@minecraft/creator-tools
Version:
Minecraft Creator Tools command line and libraries.
2 lines • 20.1 MB
JavaScript
/*! For license information please see web.js.LICENSE.txt */
(()=>{var e,t,i,n,r,o,s={104:(e,t,i)=>{"use strict";i.d(t,{W5:()=>p,dr:()=>c,hB:()=>u,lt:()=>l,wC:()=>h});var n=i(16844),r=i(82862),o=i(15365),s=i(28061),a=i(66055);class l{constructor(e,t,i,n){this.searchString=e,this.isRegex=t,this.matchCase=i,this.wordSeparators=n}parseSearchRequest(){if(""===this.searchString)return null;let e;e=this.isRegex?function(e){if(!e||0===e.length)return!1;for(let t=0,i=e.length;t<i;t++){const n=e.charCodeAt(t);if(10===n)return!0;if(92===n){if(t++,t>=i)break;const n=e.charCodeAt(t);if(110===n||114===n||87===n)return!0}}return!1}(this.searchString):this.searchString.indexOf("\n")>=0;let t=null;try{t=n.OS(this.searchString,this.isRegex,{matchCase:this.matchCase,wholeWord:!1,multiline:e,global:!0,unicode:!0})}catch(e){return null}if(!t)return null;let i=!this.isRegex&&!e;return i&&this.searchString.toLowerCase()!==this.searchString.toUpperCase()&&(i=this.matchCase),new a.L5(t,this.wordSeparators?(0,r.i)(this.wordSeparators,[]):null,i?this.searchString:null)}}function c(e,t,i){if(!i)return new a.Dg(e,null);const n=[];for(let e=0,i=t.length;e<i;e++)n[e]=t[e];return new a.Dg(e,n)}class d{constructor(e){const t=[];let i=0;for(let n=0,r=e.length;n<r;n++)10===e.charCodeAt(n)&&(t[i++]=n);this._lineFeedsOffsets=t}findLineFeedCountBeforeOffset(e){const t=this._lineFeedsOffsets;let i=0,n=t.length-1;if(-1===n)return 0;if(e<=t[0])return 0;for(;i<n;){const r=i+((n-i)/2|0);t[r]>=e?n=r-1:t[r+1]>=e?(i=r,n=r):i=r+1}return i+1}}class u{static findMatches(e,t,i,n,r){const o=t.parseSearchRequest();return o?o.regex.multiline?this._doFindMatchesMultiline(e,i,new p(o.wordSeparators,o.regex),n,r):this._doFindMatchesLineByLine(e,i,o,n,r):[]}static _getMultilineMatchRange(e,t,i,n,r,o){let a,l,c=0;if(n?(c=n.findLineFeedCountBeforeOffset(r),a=t+r+c):a=t+r,n){const e=n.findLineFeedCountBeforeOffset(r+o.length)-c;l=a+o.length+e}else l=a+o.length;const d=e.getPositionAt(a),u=e.getPositionAt(l);return new s.Q(d.lineNumber,d.column,u.lineNumber,u.column)}static _doFindMatchesMultiline(e,t,i,n,r){const o=e.getOffsetAt(t.getStartPosition()),s=e.getValueInRange(t,1),a="\r\n"===e.getEOL()?new d(s):null,l=[];let u,h=0;for(i.reset(0);u=i.next(s);)if(l[h++]=c(this._getMultilineMatchRange(e,o,s,a,u.index,u[0]),u,n),h>=r)return l;return l}static _doFindMatchesLineByLine(e,t,i,n,r){const o=[];let s=0;if(t.startLineNumber===t.endLineNumber){const a=e.getLineContent(t.startLineNumber).substring(t.startColumn-1,t.endColumn-1);return s=this._findMatchesInLine(i,a,t.startLineNumber,t.startColumn-1,s,o,n,r),o}const a=e.getLineContent(t.startLineNumber).substring(t.startColumn-1);s=this._findMatchesInLine(i,a,t.startLineNumber,t.startColumn-1,s,o,n,r);for(let a=t.startLineNumber+1;a<t.endLineNumber&&s<r;a++)s=this._findMatchesInLine(i,e.getLineContent(a),a,0,s,o,n,r);if(s<r){const a=e.getLineContent(t.endLineNumber).substring(0,t.endColumn-1);s=this._findMatchesInLine(i,a,t.endLineNumber,0,s,o,n,r)}return o}static _findMatchesInLine(e,t,i,n,r,o,l,d){const u=e.wordSeparators;if(!l&&e.simpleSearch){const l=e.simpleSearch,c=l.length,p=t.length;let f=-c;for(;-1!==(f=t.indexOf(l,f+c));)if((!u||h(u,t,p,f,c))&&(o[r++]=new a.Dg(new s.Q(i,f+1+n,i,f+1+c+n),null),r>=d))return r;return r}const f=new p(e.wordSeparators,e.regex);let m;f.reset(0);do{if(m=f.next(t),m&&(o[r++]=c(new s.Q(i,m.index+1+n,i,m.index+1+m[0].length+n),m,l),r>=d))return r}while(m);return r}static findNextMatch(e,t,i,n){const r=t.parseSearchRequest();if(!r)return null;const o=new p(r.wordSeparators,r.regex);return r.regex.multiline?this._doFindNextMatchMultiline(e,i,o,n):this._doFindNextMatchLineByLine(e,i,o,n)}static _doFindNextMatchMultiline(e,t,i,n){const r=new o.y(t.lineNumber,1),a=e.getOffsetAt(r),l=e.getLineCount(),u=e.getValueInRange(new s.Q(r.lineNumber,r.column,l,e.getLineMaxColumn(l)),1),h="\r\n"===e.getEOL()?new d(u):null;i.reset(t.column-1);const p=i.next(u);return p?c(this._getMultilineMatchRange(e,a,u,h,p.index,p[0]),p,n):1!==t.lineNumber||1!==t.column?this._doFindNextMatchMultiline(e,new o.y(1,1),i,n):null}static _doFindNextMatchLineByLine(e,t,i,n){const r=e.getLineCount(),o=t.lineNumber,s=e.getLineContent(o),a=this._findFirstMatchInLine(i,s,o,t.column,n);if(a)return a;for(let t=1;t<=r;t++){const s=(o+t-1)%r,a=e.getLineContent(s+1),l=this._findFirstMatchInLine(i,a,s+1,1,n);if(l)return l}return null}static _findFirstMatchInLine(e,t,i,n,r){e.reset(n-1);const o=e.next(t);return o?c(new s.Q(i,o.index+1,i,o.index+1+o[0].length),o,r):null}static findPreviousMatch(e,t,i,n){const r=t.parseSearchRequest();if(!r)return null;const o=new p(r.wordSeparators,r.regex);return r.regex.multiline?this._doFindPreviousMatchMultiline(e,i,o,n):this._doFindPreviousMatchLineByLine(e,i,o,n)}static _doFindPreviousMatchMultiline(e,t,i,n){const r=this._doFindMatchesMultiline(e,new s.Q(1,1,t.lineNumber,t.column),i,n,9990);if(r.length>0)return r[r.length-1];const a=e.getLineCount();return t.lineNumber!==a||t.column!==e.getLineMaxColumn(a)?this._doFindPreviousMatchMultiline(e,new o.y(a,e.getLineMaxColumn(a)),i,n):null}static _doFindPreviousMatchLineByLine(e,t,i,n){const r=e.getLineCount(),o=t.lineNumber,s=e.getLineContent(o).substring(0,t.column-1),a=this._findLastMatchInLine(i,s,o,n);if(a)return a;for(let t=1;t<=r;t++){const s=(r+o-t-1)%r,a=e.getLineContent(s+1),l=this._findLastMatchInLine(i,a,s+1,n);if(l)return l}return null}static _findLastMatchInLine(e,t,i,n){let r,o=null;for(e.reset(0);r=e.next(t);)o=c(new s.Q(i,r.index+1,i,r.index+1+r[0].length),r,n);return o}}function h(e,t,i,n,r){return function(e,t,i,n,r){if(0===n)return!0;const o=t.charCodeAt(n-1);if(0!==e.get(o))return!0;if(13===o||10===o)return!0;if(r>0){const i=t.charCodeAt(n);if(0!==e.get(i))return!0}return!1}(e,t,0,n,r)&&function(e,t,i,n,r){if(n+r===i)return!0;const o=t.charCodeAt(n+r);if(0!==e.get(o))return!0;if(13===o||10===o)return!0;if(r>0){const i=t.charCodeAt(n+r-1);if(0!==e.get(i))return!0}return!1}(e,t,i,n,r)}class p{constructor(e,t){this._wordSeparators=e,this._searchRegex=t,this._prevMatchStartIndex=-1,this._prevMatchLength=0}reset(e){this._searchRegex.lastIndex=e,this._prevMatchStartIndex=-1,this._prevMatchLength=0}next(e){const t=e.length;let i;do{if(this._prevMatchStartIndex+this._prevMatchLength===t)return null;if(i=this._searchRegex.exec(e),!i)return null;const r=i.index,o=i[0].length;if(r===this._prevMatchStartIndex&&o===this._prevMatchLength){if(0===o){n.Z5(e,t,this._searchRegex.lastIndex)>65535?this._searchRegex.lastIndex+=2:this._searchRegex.lastIndex+=1;continue}return null}if(this._prevMatchStartIndex=r,this._prevMatchLength=o,!this._wordSeparators||h(this._wordSeparators,e,t,r,o))return i}while(i);return null}}},194:(e,t,i)=>{"use strict";var n=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(e[n]=i[n])}return e},r=d(i(5556)),o=d(i(41537)),s=d(i(46641)),a=i(96540),l=d(a),c=d(i(41853));function d(e){return e&&e.__esModule?e:{default:e}}var u={bgColor:r.default.oneOfType([r.default.object,r.default.string]),fgColor:r.default.oneOfType([r.default.object,r.default.string]),level:r.default.string,size:r.default.number,value:r.default.string.isRequired},h=(0,a.forwardRef)(function(e,t){var i=e.bgColor,r=void 0===i?"#FFFFFF":i,a=e.fgColor,d=void 0===a?"#000000":a,u=e.level,h=void 0===u?"L":u,p=e.size,f=void 0===p?256:p,m=e.value,g=function(e,t){var i={};for(var n in e)t.indexOf(n)>=0||Object.prototype.hasOwnProperty.call(e,n)&&(i[n]=e[n]);return i}(e,["bgColor","fgColor","level","size","value"]),_=new s.default(-1,o.default[h]);_.addData(m),_.make();var v=_.modules;return l.default.createElement(c.default,n({},g,{bgColor:r,bgD:v.map(function(e,t){return e.map(function(e,i){return e?"":"M "+i+" "+t+" l 1 0 0 1 -1 0 Z"}).join(" ")}).join(" "),fgColor:d,fgD:v.map(function(e,t){return e.map(function(e,i){return e?"M "+i+" "+t+" l 1 0 0 1 -1 0 Z":""}).join(" ")}).join(" "),ref:t,size:f,viewBoxSize:v.length}))});h.displayName="QRCode",h.propTypes=u,t.Ay=h},251:(e,t)=>{t.read=function(e,t,i,n,r){var o,s,a=8*r-n-1,l=(1<<a)-1,c=l>>1,d=-7,u=i?r-1:0,h=i?-1:1,p=e[t+u];for(u+=h,o=p&(1<<-d)-1,p>>=-d,d+=a;d>0;o=256*o+e[t+u],u+=h,d-=8);for(s=o&(1<<-d)-1,o>>=-d,d+=n;d>0;s=256*s+e[t+u],u+=h,d-=8);if(0===o)o=1-c;else{if(o===l)return s?NaN:1/0*(p?-1:1);s+=Math.pow(2,n),o-=c}return(p?-1:1)*s*Math.pow(2,o-n)},t.write=function(e,t,i,n,r,o){var s,a,l,c=8*o-r-1,d=(1<<c)-1,u=d>>1,h=23===r?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:o-1,f=n?1:-1,m=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(a=isNaN(t)?1:0,s=d):(s=Math.floor(Math.log(t)/Math.LN2),t*(l=Math.pow(2,-s))<1&&(s--,l*=2),(t+=s+u>=1?h/l:h*Math.pow(2,1-u))*l>=2&&(s++,l/=2),s+u>=d?(a=0,s=d):s+u>=1?(a=(t*l-1)*Math.pow(2,r),s+=u):(a=t*Math.pow(2,u-1)*Math.pow(2,r),s=0));r>=8;e[i+p]=255&a,p+=f,a/=256,r-=8);for(s=s<<r|a,c+=r;c>0;e[i+p]=255&s,p+=f,s/=256,c-=8);e[i+p-f]|=128*m}},378:(e,t,i)=>{"use strict";i.d(t,{Ay:()=>w,Jl:()=>E,M7:()=>S,fR:()=>y,h6:()=>x,lw:()=>C,qK:()=>T,sw:()=>b});var n=i(67687),r=i(72327),o=i(70263),s=i(60825),a=i(59327),l=i(51044),c=i(40538),d=i(66207),u=i(93149),h=i(60889),p=i(83748),f=i(59701),m=i(98906),g=i(37386),_=i(55757),v=i(75236);const y=7;var b,x,S,C;function T(e,t){return e===x.singleFileRaw||e===x.validationWithJson||e===x.diff||e!==x.singleFileEditorForced&&t===v.nQ.raw}function E(e){switch(e){case n.bD.entityTypeBehavior:case n.bD.blockTypeBehavior:case n.bD.itemTypeBehavior:case n.bD.recipeBehavior:case n.bD.actionSet:case n.bD.modelGeometryJson:case n.bD.worldTest:case n.bD.scriptTypesJson:case n.bD.packageJson:case n.bD.behaviorPackManifestJson:case n.bD.spawnRuleBehavior:case n.bD.tradingBehaviorJson:case n.bD.lootTableBehavior:case n.bD.entityTypeResource:case n.bD.attachableResourceJson:case n.bD.biomeBehavior:case n.bD.biomeResource:case n.bD.featureBehavior:case n.bD.featureRuleBehavior:case n.bD.voxelShapeBehavior:case n.bD.commandSetDefinitionJson:case n.bD.contentIndexJson:case n.bD.contentReportJson:case n.bD.dataForm:return!0;default:return!1}}!function(e){e[e.downloadBlockbenchModel=0]="downloadBlockbenchModel",e[e.deleteItem=1]="deleteItem",e[e.renameItem=2]="renameItem",e[e.viewAsJson=3]="viewAsJson",e[e.viewInEditor=4]="viewInEditor",e[e.viewOnMap=5]="viewOnMap",e[e.download=6]="download",e[e.focus=7]="focus",e[e.unfocus=8]="unfocus",e[e.viewIssues=9]="viewIssues"}(b||(b={})),function(e){e[e.singleFileEditor=0]="singleFileEditor",e[e.diff=1]="diff",e[e.singleFileRaw=2]="singleFileRaw",e[e.map=3]="map",e[e.validationWithJson=4]="validationWithJson",e[e.singleFileEditorForced=5]="singleFileEditorForced"}(x||(x={})),function(e){e[e.properties=0]="properties",e[e.inspector=1]="inspector",e[e.minecraftToolSettings=2]="minecraftToolSettings",e[e.activeItem=3]="activeItem",e[e.cartoSettings=4]="cartoSettings",e[e.minecraft=5]="minecraft",e[e.actions=6]="actions",e[e.map=7]="map"}(S||(S={})),function(e){e[e.worldPropertiesDialog=0]="worldPropertiesDialog",e[e.projectListUp=1]="projectListUp",e[e.projectListDown=2]="projectListDown",e[e.projectListCommit=3]="projectListCommit"}(C||(C={}));class w{static convertStoragePathToBrowserSafe(e){return e.replace(/#/gi,"|")}static convertStoragePathFromBrowserSafe(e){return e=e.replace(/\|/gi,"#"),decodeURI(e)}static getProjectEditorModeString(e){switch(e){case S.activeItem:return"activeitem";case S.properties:return"properties";case S.inspector:return"inspector";case S.actions:return"actions";case S.cartoSettings:return"appsettings";case S.minecraft:return"minecraft";case S.minecraftToolSettings:return"minecrafttoolsettings";case S.map:return"map"}}static getProjectEditorFromString(e){switch(e.toLowerCase().trim()){case"activeitem":return S.activeItem;case"properties":return S.properties;case"inspector":return S.inspector;case"actions":return S.actions;case"appsettings":return S.cartoSettings;case"minecraft":return S.minecraft;case"minecrafttoolsettings":return S.minecraftToolSettings;default:return}}static getItemMenuItems(e,t,i,r,o=!0,s=!0){let a="";null!==e.projectPath&&void 0!==e.projectPath&&(a=e.projectPath);const l=[];return o&&(l.push({key:"focusMenu|"+a,content:t===e.projectPath?"Clear focus":"Focus on this item",tag:{path:e.projectPath,action:t===e.projectPath?b.unfocus:b.focus}}),l.push({key:"nav-divider|"+a,kind:"divider"})),l.push({key:"download|"+a,content:"Download",tag:{path:e.projectPath,action:b.download}},{key:"rename|"+a,content:"Rename",tag:{path:e.projectPath,action:b.renameItem}}),void 0!==i&&i>0&&l.unshift({key:"viewIssues|"+a,content:"View Issues ("+i+")",tag:{path:e.projectPath,action:b.viewIssues}}),e.itemType===n.bD.modelGeometryJson&&l.push({key:"downloadBbmodel|"+a,content:"Download Blockbench Model",tag:{path:e.projectPath,action:b.downloadBlockbenchModel}}),"json"===f.Ay.getTypeFromName(a)&&(r?l.push({key:"viewInEditor|"+a,content:"Open in Visual Editor",tag:{path:e.projectPath,action:b.viewInEditor}}):l.push({key:"viewAsJson|"+a,content:"Open in Text Editor",tag:{path:e.projectPath,action:b.viewAsJson}})),s&&l.push({key:"viewAsMap|"+a,content:"View on map",tag:{path:e.projectPath,action:b.viewOnMap}}),l.push({key:"delete-divider|"+a,kind:"divider"}),l.push({key:"delete|"+a,content:"Delete",tag:{path:e.projectPath,action:b.deleteItem},destructive:!0}),l}static getIsLinkShareable(e){if(!(e.gitHubOwner&&e.gitHubRepoName||void 0!==e.originalGitHubOwner&&void 0!==e.originalGitHubRepoName))return!1;if(e.projectCabinetFile)return!1;for(let t of e.items)if(t.isFileContainerStorageItem)return!1;return!0}static async launchFlatWorldWithPacksDownload(e,t){const i=await e.notifyOperationStarted("Starting export of flat world with packs."),n=await t.loc.getTokenValue(t.name),r=l.A.getFileFriendlySummarySeconds(new Date)+"-"+n,s=r+" Flat",a=r+"-flatpack.mcworld";await e.notifyStatusUpdate("Packing "+a);const c=await o.default.generateFlatBetaApisWorldWithPacksZipBytes(e,t,s);c?(await e.notifyStatusUpdate("Now downloading "+a),void 0!==c&&saveAs(new Blob([c],{type:"application/octet-stream"}),a),await e.notifyOperationEnded(i,"Done with save "+a)):await e.notifyOperationEnded(i)}static async launchWorldWithPacksDownload(e,t){const i=l.A.getFileFriendlySummarySeconds(new Date)+"-"+t.name+".mcworld",n=await o.default.generateWorldWithPacks(e,t,t.ensureWorldSettings());if(void 0===n)return;const r=await n.getBytes();void 0!==r&&saveAs(new Blob([r],{type:"application/octet-stream"}),i),await e.notifyStatusUpdate("Downloading mcworld with packs embedded '"+t.name+"'.")}static async extractZipContentsToProject(e,t){if(!e.projectFolder)return;if(!f.Ay.isContainerFile(t.name))return;const i=await e.creatorTools.notifyOperationStarted("Extracting '"+t.name+"' contents to project"),n=await t.arrayBuffer(),r=new m.A;await r.loadFromUint8Array(new Uint8Array(n),t.name),await f.Ay.syncFolderTo(r.rootFolder,e.projectFolder,!0,!0,!1),await e.inferProjectItemsFromFilesRootFolder(!0),await e.creatorTools.notifyOperationEnded(i,"'"+t.name+"' contents extracted to project")}static getIntegrateBrowserFileDefaultActionDescription(e,t,i,n){if(!e.projectFolder)return;const r=i.name.toLowerCase(),o=f.Ay.getTypeFromName(i.name);if("level.dat"===r||"db"===o||"current"===r||r.startsWith("manifest-")||"level.dat_old"===r||"levelname.txt"===r||r.startsWith("world_"))return"Add as new world";if("snbt"===o)return"Add '"+i.name+"' as new structure";if("mcworld"===o)return"Extract '"+i.name+"' contents to project";if("mcproject"===o)return"Extract '"+i.name+"' contents to project";if("mctemplate"===o)return"Extract '"+i.name+"' contents to project";if("mcaddon"===o)return"Extract '"+i.name+"' contents to project";if("zip"===o)return"Extract '"+i.name+"' contents to project";if("mcpack"===o)return"Extract '"+i.name+"' contents to project";if("ogg"===o||"mp3"===o||"wav"===o)return"Add '"+i.name+"' as new sound";if("mcstructure"===o)return"Add '"+i.name+"' as new structure";if("bbmodel"===o){let e="Integrate '"+i.name+"' as a model ";if(n&&"string"==typeof n){const t=c.A.ensureFromContent(n);if(t.id&&(e+="("+t.id+")"),t.data?.animations&&(e+=", animations ",t.data&&t.data.animations)&&(e+="("+u.Ay.removeSubTypeExtensionFromName(t.data.name)+".animation.json",e+=") "),e+="and textures",t.data&&t.data.textures){e+=" (";let i=!0;for(const n of t.data.textures)i||(e+=", "),e+=n.name,i=!1;e+=")"}}else e+="and textures";return e}if("json"===o){if(n&&"string"==typeof n){const e=s.Ay.inferTypeFromJsonContent(n,r);let t=e.packType;void 0===t&&(t=h.E.behavior);const o=s.Ay.getDescriptionForType(e.itemType);return"Add '"+i.name+"' as new "+o}return"Add '"+i.name+"' as new data file"}}static async integrateBrowserFileDefaultAction(e,t,i){if(!e.projectFolder)return;const o=t.toLowerCase(),l=i.name.toLowerCase(),u=f.Ay.getTypeFromName(i.name);if("level.dat"===l||"db"===u||"current"===l||l.startsWith("manifest-")||"level.dat_old"===l||"levelname.txt"===l||l.startsWith("world_")){t.length<2&&(t="/default"),o.indexOf("worlds")<0&&(t=f.Ay.joinPath("worlds",t)),t=f.Ay.ensureEndsWithDelimiter(f.Ay.absolutize(t));const s=await e.projectFolder.ensureFolderFromRelativePath(t);"level.dat"===l&&e.ensureItemByProjectPath(t,n.K5.folder,s.name,n.bD.worldFolder,r.S.world,void 0,n.E9.normal);const a=await i.arrayBuffer(),c=s.ensureFile(i.name);c.setContentIfSemanticallyDifferent(new Uint8Array(a))&&await c.saveContent()}else if("snbt"===u){const t=await e.creatorTools.notifyOperationStarted("Saving new SNBT structure file '"+i.name+"'"),o=await i.text(),s=e.projectFolder.ensureFolder("packs").ensureFile(i.name);s.setContentIfSemanticallyDifferent(o)&&await s.saveContent();const a=s.getFolderRelativePath(e.projectFolder);void 0!==a&&e.ensureItemByProjectPath(a,n.K5.singleFile,i.name,n.bD.structure,r.S.behaviorPack,void 0,n.E9.normal),await e.creatorTools.notifyOperationEnded(t,"New SNBT structure file '"+i.name+"' added")}else if("mcworld"===u){const t=await e.creatorTools.notifyOperationStarted("Saving new MCWorld file '"+i.name+"'"),o=await i.arrayBuffer(),s=e.projectFolder.ensureFolder("worlds").ensureFile(i.name);s.setContent(new Uint8Array(o)),s.saveContent();const a=s.getFolderRelativePath(e.projectFolder);void 0!==a&&(e.ensureItemByProjectPath(a,n.K5.singleFile,i.name,n.bD.MCWorld,r.S.world,void 0,n.E9.normal),await e.inferProjectItemsFromZipFile(a,s,!1)),await e.creatorTools.notifyOperationEnded(t,"New MCWorld file '"+i.name+"' added")}else if("mcproject"===u){const t=await e.creatorTools.notifyOperationStarted("Saving new MCProject file '"+i.name+"'"),o=await i.arrayBuffer(),s=e.projectFolder.ensureFolder("editorworlds").ensureFile(i.name);s.setContent(new Uint8Array(o)),s.saveContent();const a=s.getFolderRelativePath(e.projectFolder);void 0!==a&&(e.ensureItemByProjectPath(a,n.K5.singleFile,i.name,n.bD.MCProject,r.S.world,void 0,n.E9.normal),await e.inferProjectItemsFromZipFile(a,s,!1)),await e.creatorTools.notifyOperationEnded(t,"New MCProject file '"+i.name+"' added")}else if("mctemplate"===u){const t=await e.creatorTools.notifyOperationStarted("Saving new MCTemplate file '"+i.name+"'"),o=await i.arrayBuffer(),s=e.projectFolder.ensureFolder("templates").ensureFile(i.name);s.setContent(new Uint8Array(o)),s.saveContent();const a=s.getFolderRelativePath(e.projectFolder);void 0!==a&&(e.ensureItemByProjectPath(a,n.K5.singleFile,i.name,n.bD.MCTemplate,r.S.world,void 0,n.E9.normal),await e.inferProjectItemsFromZipFile(a,s,!1)),await e.creatorTools.notifyOperationEnded(t,"New MCTemplate file '"+i.name+"' added")}else if("mcaddon"===u){const t=await e.creatorTools.notifyOperationStarted("Saving new MCAddon file '"+i.name+"'"),o=await i.arrayBuffer(),s=e.projectFolder.ensureFolder("addons").ensureFile(i.name);s.setContent(new Uint8Array(o)),s.saveContent();const a=s.getFolderRelativePath(e.projectFolder);void 0!==a&&(e.ensureItemByProjectPath(a,n.K5.singleFile,i.name,n.bD.MCAddon,r.S.unknown,void 0,n.E9.normal),await e.inferProjectItemsFromZipFile(a,s,!1)),await e.creatorTools.notifyOperationEnded(t,"New MCAddon file '"+i.name+"' added")}else if("zip"===u){const t=await e.creatorTools.notifyOperationStarted("Saving new zip file '"+i.name+"'"),o=await i.arrayBuffer(),s=e.projectFolder.ensureFolder("zips").ensureFile(i.name);s.setContent(new Uint8Array(o)),s.saveContent();const a=s.getFolderRelativePath(e.projectFolder);void 0!==a&&(e.ensureItemByProjectPath(a,n.K5.singleFile,i.name,n.bD.zip,r.S.unknown,void 0,n.E9.normal),await e.inferProjectItemsFromZipFile(a,s,!1)),await e.creatorTools.notifyOperationEnded(t,"New zip file '"+i.name+"' added")}else if("mcpack"===u){const t=await e.creatorTools.notifyOperationStarted("Saving new MCPack file '"+i.name+"'"),o=await i.arrayBuffer(),s=e.projectFolder.ensureFolder("packs").ensureFile(i.name);s.setContent(new Uint8Array(o)),s.saveContent();const a=s.getFolderRelativePath(e.projectFolder);void 0!==a&&(e.ensureItemByProjectPath(a,n.K5.singleFile,i.name,n.bD.MCPack,r.S.unknown,void 0,n.E9.normal),await e.inferProjectItemsFromZipFile(a,s,!1)),await e.creatorTools.notifyOperationEnded(t,"New MCPack file '"+i.name+"' added")}else if("mcstructure"===u){const t=await e.creatorTools.notifyOperationStarted("Saving new structure file '"+i.name+"'"),o=await i.arrayBuffer(),s=(await e.ensureDefaultBehaviorPackFolder()).ensureFolder("structures").ensureFile(i.name);s.setContent(new Uint8Array(o)),s.saveContent();const a=s.getFolderRelativePath(e.projectFolder);void 0!==a&&e.ensureItemByProjectPath(a,n.K5.singleFile,i.name,n.bD.structure,r.S.behaviorPack,void 0,n.E9.normal),await e.creatorTools.notifyOperationEnded(t,"New structure file '"+i.name+"' added")}else if("mp3"===u||"ogg"===u||"flac"===u||"wav"===u){const t=await e.creatorTools.notifyOperationStarted("Saving new audio file '"+i.name+"'"),o=await i.arrayBuffer(),s=(await e.ensureDefaultResourcePackFolder()).ensureFolder("sounds").ensureFile(i.name);s.setContent(new Uint8Array(o)),s.saveContent();const a=s.getFolderRelativePath(e.projectFolder);if(void 0!==a){const t=e.ensureItemByProjectPath(a,n.K5.singleFile,i.name,n.bD.audio,r.S.resourcePack,void 0,n.E9.normal);await d.A.ensureFoundationalDependencies(t)}await e.creatorTools.notifyOperationEnded(t,"New audio file '"+i.name+"' added")}else if("json"===u){const t=await e.creatorTools.notifyOperationStarted("Saving new JSON file '"+i.name+"'"),n=await i.text(),r=await a.Ay.ensureJsonItem(e,n,l);let o="";r&&(o=" as "+s.Ay.getDescriptionForType(r.itemType)+" to "+r.projectPath),await e.creatorTools.notifyOperationEnded(t,"New JSON file '"+i.name+"' added"+o)}else if("bbmodel"===u){const t=await e.creatorTools.notifyOperationStarted("Integrating bbmodel file '"+i.name+"'"),n=await i.text();c.A.ensureFromContent(n).integrateIntoProject(e),await e.creatorTools.notifyOperationEnded(t,"Integrated bbmodel '"+i.name+"'.")}else if("png"===u||"jpg"===u||"jpeg"===u||"tga"===u){const o=await e.creatorTools.notifyOperationStarted("Saving new texture file '"+i.name+"'"),s=await i.arrayBuffer(),a=await e.ensureDefaultResourcePackFolder();let l,c=i.name;if(t&&t.length>1&&t.includes("/textures/")){let e=f.Ay.ensureStartsWithDelimiter(t);e=e.replace(/^\/(resource_pack|behavior_pack)\//i,"/");const i=f.Ay.getFolderPath(e);c=f.Ay.getLeafName(e),l=await a.ensureFolderFromRelativePath(i)}else l=a.ensureFolder("textures");const d=l.ensureFile(c);d.setContent(new Uint8Array(s)),await d.saveContent();const u=d.getFolderRelativePath(e.projectFolder);void 0!==u&&e.ensureItemByProjectPath(u,n.K5.singleFile,c,n.bD.texture,r.S.resourcePack,void 0,n.E9.normal),await e.creatorTools.notifyOperationEnded(o,"New texture file '"+c+"' added"+(t&&t.length>1?" at "+t:""))}}static async launchEditorWorldWithPacksDownload(e,t){const i=l.A.getFileFriendlySummarySeconds(new Date)+"-"+t.name+".mcproject",n=await o.default.generateWorldWithPacks(e,t,t.ensureEditorWorldSettings());if(void 0===n)return;const r=await n.getBytes();if(void 0!==r){saveAs(new Blob([r],{type:"application/octet-stream"}),i);const e={},t=(n.worldBehaviorPacks?.length||0)+(n.worldResourcePacks?.length||0);e[_.tA.ADDITIONAL_PACKS_ADDED]=t>0?t:void 0;const o=n.worldBehaviorPacks?.map(e=>e.pack_id).join(";");e[_.tA.BEHAVIOR_PACKS]=o&&o.length>0?o:void 0;const s=n.worldResourcePacks?.map(e=>e.pack_id).join(";");e[_.tA.RESOURCE_PACKS]=s&&s.length>0?s:void 0,g.A.trackEvent({name:_.bZ.EDITOR_PROJECT_DOWNLOADED,properties:e})}await e.notifyStatusUpdate("Downloading mcworld with packs embedded '"+t.name+"'.")}static async launchLocalExport(e,t){if(null===t||null===t.projectFolder)return;let i;try{const n=await window.showDirectoryPicker({mode:"readwrite"});if(n){const r=new p.A(n);i=await e.notifyOperationStarted("Exporting project to '"+n.name+"'");const o=await r.rootFolder.getFirstUnsafeError();o?await e.notifyOperationEnded(i,"Could not export to a folder on your device: "+o,void 0,!0):(await f.Ay.syncFolderTo(t.projectFolder,r.rootFolder,!0,!0,!1,[],void 0,async t=>{await e.notifyStatusUpdate(t)},!0),await e.notifyStatusUpdate("Saving all files to '"+n.name+"'."),await r.rootFolder.saveAll(),await e.notifyOperationEnded(i,"Export completed."),g.A.trackEvent({name:_.bZ.PROJECT_EXPORTED,properties:{[_.tA.EXPORT_FORMAT]:"folder"}}))}}catch(t){if(t instanceof DOMException&&"AbortError"===t.name)return;const n=t instanceof Error?t.message:String(t);void 0!==i?await e.notifyOperationEnded(i,"Export to folder failed: "+n,void 0,!0):await e.notifyStatusUpdate("Export to folder failed: "+n)}}static async launchZipExport(e,t){if(null==t)return;const i=await t.loc.getTokenValue(t.name),n=await e.notifyOperationStarted("Exporting '"+i+"' as zip.");try{const r=new m.A,o=await t.ensureLoadedProjectFolder();await f.Ay.syncFolderTo(o,r.rootFolder,!0,!0,!1),await r.rootFolder.saveAll();const s=await r.generateBlobAsync();await e.notifyOperationEnded(n,"Export zip of '"+i+"' created; downloading."),saveAs(s,i+".zip"),g.A.trackEvent({name:_.bZ.PROJECT_EXPORTED,properties:{[_.tA.EXPORT_FORMAT]:"zip"}})}catch(t){const i=t instanceof Error?t.message:String(t);throw await e.notifyOperationEnded(n,"Export zip failed: "+i,void 0,!0),t}}}},428:(e,t,i)=>{"use strict";i.d(t,{A:()=>d});var n=i(14466),r=i(46882),o=i(59701),s=i(67687),a=i(51044),l=i(40267),c=i(77452);class d{_data;_file;_isLoaded=!1;_loadedWithComments=!1;_onLoaded=new r.Qe;get isLoaded(){return this._isLoaded}get file(){return this._file}get data(){return this._data}get onLoaded(){return this._onLoaded.asEvent()}set file(e){this._file=e}get textureData(){if(this._data)return void 0===this._data.texture_data&&(this._data.texture_data={}),this._data.texture_data}getCanonicalizedTexturePathList(){if(!this._data||!this._data.texture_data)return;const e=[];for(const t in this._data.texture_data){const i=this._data.texture_data[t];if(i&&i.textures)if("string"==typeof i.textures){const t=c.A.canonicalizeTexturePath(i.textures);t&&e.push(t)}else if(Array.isArray(i.textures))for(const t of i.textures)if("string"==typeof t){const i=c.A.canonicalizeTexturePath(t);i&&e.push(i)}else if(t){let i=t.path;"string"==typeof i&&(i=c.A.canonicalizeTexturePath(i),i&&e.push(i))}}return e}getTexturePathList(){if(!this._data||!this._data.texture_data)return;const e=[];for(const t in this._data.texture_data){const i=this._data.texture_data[t];if(i&&i.textures)if("string"==typeof i.textures)e.push(i.textures);else if(Array.isArray(i.textures))for(const t of i.textures)if("string"==typeof t){const i=c.A.canonicalizeTexturePath(t);i&&e.push(i)}else if(t){let i=t.path;"string"==typeof i&&(i=c.A.canonicalizeTexturePath(i),i&&e.push(i))}}return e}get texturesIdList(){if(!this._data||!this._data.texture_data)return;const e=[];for(const t in this._data.texture_data)e.push(t);return e}static async ensureOnFile(e,t){let i;return void 0===e.manager&&(i=new d,i.file=e,e.manager=i),void 0!==e.manager&&e.manager instanceof d&&(i=e.manager,i.isLoaded||(t&&i.onLoaded.subscribe(t),await i.load())),i}persist(){return void 0!==this._file&&!!this._data&&this._file.setObjectContentIfSemanticallyDifferent(this._data)}getPackRootFolder(){let e;if(this.file&&this.file.parentFolder){let t=this.file.parentFolder;e=o.Ay.getParentOfParentFolderNamed("textures",t)}return e}getTextureReferences(){const e=[];if(this.data?.texture_data)for(const t in this.data.texture_data){const i=this.data.texture_data[t];i&&i.textures&&(e.includes(t)||e.push(t))}return e}async addChildItems(e,t){const i=e.getItemsByType(s.bD.texture);let n=this.getPackRootFolder(),r=this.getCanonicalizedTexturePathList();for(const e of i)if(n&&r&&(e.isContentLoaded||await e.loadContent(),e.primaryFile)){let i=c.A.canonicalizeTexturePath(o.Ay.getBaseRelativePath(e.primaryFile,n));i&&r&&r.includes(i)&&(t.addChildItem(e),r=a.A.removeItemInArray(i,r))}if(r)for(const e of r)t.addUnfulfilledRelationship(e,s.bD.texture,await l.A.isVanillaToken(e))}async load(e=!1){if(this._isLoaded&&this._loadedWithComments)return;if(this._isLoaded&&!e)return;if(void 0===this._file)return void n.Ay.unexpectedUndefined("ITCDF");if(this._file.isContentLoaded||await this._file.loadContent(),!this._file.content||this._file.content instanceof Uint8Array)return this._isLoaded=!0,this._loadedWithComments=e,void this._onLoaded.dispatch(this,this);let t={},i=e?o.Ay.getJsonObjectWithComments(this._file):o.Ay.getJsonObject(this._file);i&&(t=i),this._data=t,this._isLoaded=!0,this._loadedWithComments=e,this._onLoaded.dispatch(this,this)}}},542:(e,t,i)=>{"use strict";i.d(t,{Z:()=>n,A:()=>$});var n,r=i(74848),o=i(96540),s=i(7897),a=i(20982),l=i(66188),c=i(67687),d=i(58280);!function(e){e[e.explorer=0]="explorer",e[e.folderPicker=1]="folderPicker"}(n||(n={}));const u={project:void 0,theme:{bodyFontFamily:"",mc0:"",mc1:"",mc2:"",mc3:"",mc4:"",mc5:"",mcc1:"",background:"",background1:"",background2:"",background3:"",background4:"",background5:"",background6:"",foreground:"",foreground1:"",foreground2:"",foreground3:"",foreground4:"",foreground5:"",foreground6:"",foregroundHover:"",foregroundHover1:"",foregroundHover2:"",foregroundHover3:"",backgroundHover:"",backgroundHover1:"",backgroundHover2:"",backgroundHover3:"",foregroundActive:"",foregroundActive1:"",backgroundActive:"",backgroundActive1:"",backgroundPressed:""},selectedItem:void 0,mode:n.explorer,readOnly:!0,onFileSelected:void 0,onFolderSelected:void 0,onFileDelete:void 0,onFileRename:void 0,onFileOpenAsRaw:void 0},h=(0,o.createContext)(u),p=h.Provider;var f=i(22275);class m extends o.Component{static contextType=h;constructor(e){super(e),this.state={cachedDominantGroup:void 0,cachedForFolderPath:void 0},this._handleToggleExpandedClick=this._handleToggleExpandedClick.bind(this),this._handleFolderClick=this._handleFolderClick.bind(this),this._handleExpandClick=this._handleExpandClick.bind(this),this._handleCollapseClick=this._handleCollapseClick.bind(this)}_handleFolderClick(){this.context.onFolderSelected&&this.context.onFolderSelected(this.props.folder)}_handleToggleExpandedClick(){this.props.onExpandedSet&&this.props.onExpandedSet(!this.props.isExpanded)}_handleCollapseClick(){this.props.onExpandedSet&&this.props.onExpandedSet(!1)}_handleExpandClick(){this.props.onExpandedSet&&this.props.onExpandedSet(!0)}getDominantItemTypeGroup(){const e=this.context.project;if(!e)return;const t=this.props.folder.extendedPath;if(this.state.cachedForFolderPath===t&&void 0!==this.state.cachedDominantGroup)return null===this.state.cachedDominantGroup?void 0:this.state.cachedDominantGroup;const i=this.props.folder;let n,r=!1;for(const o in i.files){const s=i.files[o];if(s){const i=e.getItemByExtendedOrProjectPath(s.extendedPath);if(i&&i.itemType!==c.bD.unknown){r=!0;const e=(0,d.cA)(i.itemType);if(void 0===n)n=e;else if(n!==e)return void setTimeout(()=>{this.setState({cachedDominantGroup:null,cachedForFolderPath:t})},0)}}}const o=r?n:void 0;return setTimeout(()=>{this.setState({cachedDominantGroup:void 0===o?null:o,cachedForFolderPath:t})},0),o}getFolderLabelColor(){const e=this.getDominantItemTypeGroup();if(e){const t=d.uY[e];if(t)return`rgb(${t.red}, ${t.green}, ${t.blue})`}}render(){const{theme:e,selectedItem:t,mode:i}=this.context;let o,c="fexfod-area";if(t&&t===this.props.folder&&(o=(0,f.kt)().background3),this.props.itemAnnotations)for(const e in this.props.itemAnnotations)if(this.props.itemAnnotations[e].length>0){c+=" fexfod-containsAnnotatedItems";break}let d=(0,r.jsx)(r.Fragment,{});return(this.props.folder.folderCount>0||i!==n.folderPicker&&this.props.folder.fileCount>0)&&(d=(0,r.jsx)("div",{className:"fexfod-expander",onClick:this._handleToggleExpandedClick,onKeyDown:e=>{"Enter"!==e.key&&" "!==e.key||(this._handleToggleExpandedClick(),e.preventDefault(),e.stopPropagation())},tabIndex:0,role:"button","aria-expanded":this.props.isExpanded,"aria-label":(this.props.isExpanded?"Collapse":"Expand")+" "+this.props.folder.name,title:(this.props.isExpanded?"Collapse":"Expand")+" "+this.props.folder.name,children:this.props.isExpanded?(0,r.jsx)(a.g,{icon:l.xBV,className:"fa-lg"}):(0,r.jsx)(a.g,{icon:l.fU5,className:"fa-lg"})})),(0,r.jsxs)("div",{className:c,style:{backgroundColor:o},onKeyDown:e=>{"Space"===e.key?this._handleToggleExpandedClick():"ArrowLeft"===e.key?this._handleCollapseClick():"ArrowRight"===e.key?this._handleExpandClick():"Enter"===e.key&&this._handleFolderClick()},children:[d,(0,r.jsxs)("div",{"aria-selected":!!t&&t===this.props.folder,className:"fexfod-summary",role:"treeitem","aria-expanded":this.props.isExpanded,tabIndex:0,onClick:this._handleFolderClick,onKeyDown:e=>{"Space"===e.key?(this._handleToggleExpandedClick(),e.preventDefault(),e.stopPropagation()):"ArrowLeft"===e.key?(this._handleCollapseClick(),e.preventDefault(),e.stopPropagation()):"ArrowRight"===e.key?(this._handleExpandClick(),e.preventDefault(),e.stopPropagation()):"Enter"===e.key&&(this._handleFolderClick(),e.preventDefault(),e.stopPropagation())},title:"Select "+this.props.folder.name,"aria-label":"Folder: "+this.props.folder.name,children:[(0,r.jsx)("div",{className:"fexfod-icon",children:(0,r.jsx)(a.g,{icon:s.ao0,className:"fa-lg"})}),(0,r.jsx)("div",{className:"fexfod-label",style:{color:this.getFolderLabelColor()},children:this.props.folder.name})]})]})}}var g=i(96997),_=i(3234),v=i(16572),y=i(79791),b=i(19741),x=i(73896),S=i(11641),C=i(58031),T=i(46831),E=i(22477),w=i(69890),A=i(25239),P=i(36632),I=i(58763),R=i(54855),D=i(17064);function M(e){if(!e)return{base:"",extension:""};const t=e.lastIndexOf(".");return t<=0?{base:e,extension:""}:{base:e.substring(0,t),extension:e.substring(t)}}const k=/[<>:"/\\|?*]/;function O(e,t){return e&&e.trim()?k.test(e)?'Name cannot contain: < > : " / \\ | ? *':k.test(t)?'Extension cannot contain: < > : " / \\ | ? *':null:"File name cannot be empty."}class N extends o.Component{static contextType=h;constructor(e){super(e),this._handleCloseClick=this._handleCloseClick.bind(this),this._handleToggleExpanderClick=this._handleToggleExpanderClick.bind(this),this._handleExpandClick=this._handleExpandClick.bind(this),this._handleCollapseClick=this._handleCollapseClick.bind(this),this._handleFileClick=this._handleFileClick.bind(this),this._handleMenuClick=this._handleMenuClick.bind(this),this._handleRenameDialogCancel=this._handleRenameDialogCancel.bind(this),this._handleRenameDialogConfirm=this._handleRenameDialogConfirm.bind(this),this._handleRenameBaseChange=this._handleRenameBaseChange.bind(this),this._handleRenameExtensionChange=this._handleRenameExtensionChange.bind(this),this._handleToggleExtensionLock=this._handleToggleExtensionLock.bind(this),this._handleConfirmExtensionChange=this._handleConfirmExtensionChange.bind(this),this._handleMenuButtonClick=this._handleMenuButtonClick.bind(this),this._handleMenuClose=this._handleMenuClose.bind(this),this._handleContextMenuClose=this._handleContextMenuClose.bind(this);const t=M(e.file.name);this.state={showRenameDialog:!1,renameBaseValue:t.base,renameExtensionValue:t.extension,renameError:null,extensionUnlocked:!1,extensionChangeConfirmed:!1,menuAnchorEl:null,contextMenuPosition:null,toastMessage:null}}_handleFileClick(){this.context.onFileSelected&&this.context.onFileSelected(this.props.file)}_handleCloseClick(){this.props.onRemove&&this.props.onRemove()}_handleCollapseClick(){this.props.onExpandedSet&&this.props.onExpandedSet(!1)}_handleExpandClick(){this.props.onExpandedSet&&this.props.onExpandedSet(!0)}_handleToggleExpanderClick(){this.props.onExpandedSet&&this.props.onExpandedSet(!this.props.isExpanded)}_handleMenuClick(e){if("Delete"===e){const e=this.props.file.name;window.confirm(`Delete ${e}?\n\nThis will permanently remove the file from your project.`)&&this.context.onFileDelete&&this.context.onFileDelete(this.props.file)}else if("Rename"===e){const e=M(this.props.file.name);this.setState({showRenameDialog:!0,renameBaseValue:e.base,renameExtensionValue:e.extension,renameError:null,extensionUnlocked:!1,extensionChangeConfirmed:!1})}else"Copy path"===e?this._copyFilePath():"Duplicate"===e?this._duplicateFile():"Reveal in folder"===e?this._revealInFolder():"Open as Raw"===e&&this.context.onFileOpenAsRaw&&this.context.onFileOpenAsRaw(this.props.file);this.setState({menuAnchorEl:null,contextMenuPosition:null})}async _revealInFolder(){try{const e=this.props.file,t=e.parentFolder?.fullPath||e.fullPath;if(!t)return void this.setState({toastMessage:"No folder path available for this file"});_.A.hasAppService?await _.A.sendAsync(_.$.shellOpenFolderInExplorer,t):this.setState({toastMessage:"Reveal in folder is only available in the desktop app"})}catch(e){this.setState({toastMessage:"Could not reveal file in folder"})}}async _copyFilePath(){const e=this.props.file.storageRelativePath||this.props.file.name;try{navigator.clipboard&&navigator.clipboard.writeText?(await navigator.clipboard.writeText(e),this.setState({toastMessage:"Path copied to clipboard"})):this.setState({toastMessage:"Clipboard not available: "+e})}catch(e){this.setState({toastMessage:"Could not copy path"})}}async _duplicateFile(){const e=this.props.file,t=e.parentFolder;if(t)try{const i=M(e.name);let n=`${i.base} copy${i.extension}`,r=2;const o=100;for(;void 0!==t.files[n];){if(r>o)return void this.setState({toastMessage:"Could not find a unique name for the duplicate"});n=`${i.base} copy ${r}${i.extension}`,r++}null!==e.content&&void 0!==e.content||await e.loadContent();const s=t.ensureFile(n);null!==e.content&&void 0!==e.content&&(s.setContent(e.content),await s.saveContent()),this.props.fileExplorer.forceUpdate(),this.setState({toastMessage:`Duplicated as ${n}`})}catch(e){this.setState({toastMessage:"Could not duplicate file"})}else this.setState({toastMessage:"Cannot duplicate: no parent folder"})}_handleMenuButtonClick(e){e.stopPropagation(),this.setState({menuAnchorEl:e.currentTarget})}_handleMenuClose(){this.setState({menuAnchorEl:null})}_handleContextMenuClose(){this.setState({contextMenuPosition:null})}_handleRenameDialogCancel(){this.setState({showRenameDialog:!1,renameError:null,extensionUnlocked:!1,extensionChangeConfirmed:!1})}_handleRenameDialogConfirm(){const e=this.state.renameBaseValue,t=this.state.renameExtensionValue,i=O(e,t);if(i)return void this.setState({renameError:i});if(!(t===M(this.props.file.name).extension||this.state.extensionUnlocked&&this.state.extensionChangeConfirmed))return;const n=e+t;this.context.onFileRename&&n&&n!==this.props.file.name&&this.context.onFileRename(this.props.file,n),this.setState({showRenameDialog:!1,renameError:null,extensionUnlocked:!1,extensionChangeConfirmed:!1})}_handleRenameBaseChange(e){const t=e.target.value,i=O(t,this.state.renameExtensionValue);this.setState({renameBaseValue:t,renameError:i})}_handleRenameExtensionChange(e){let t=e.target.value;t&&!t.startsWith(".")&&(t="."+t);const i=O(this.state.renameBaseValue,t);this.setState({renameExtensionValue:t,extensionChangeConfirmed:!1,renameError:i})}_handleToggleExtensionLock(){this.setState(e=>({extensionUnlocked:!e.extensionUnlocked,extensionChangeConfirmed:!1,renameExtensionValue:e.extensionUnlocked?M(this.props.file.name).extension:e.renameExtensionValue}))}_handleConfirmExtensionChange(){this.setState({extensionChangeConfirmed:!0})}renderIcon(){if(this.context.project){const e=this.context.project.getItemByExtendedOrProjectPath(this.props.file.extendedPath);if(e&&e.itemType!==c.bD.unknown)return(0,r.jsx)(y.A,{itemType:e.itemType,size:16})}return(0,r.jsx)(a.g,{icon:s.A4h,className:"fa-lg"})}render(){const{theme:e,selectedItem:t}=this.context;let i,n="fexfid-area",o="";if(this.props.itemAnnotations)for(const e in this.props.itemAnnotations){const t=this.props.itemAnnotations[e];for(let e=0;e<t.length;e++)o.length>0&&(o+=" "),t[e].type===v.f.error&&n.indexOf("error")<1&&(n+=" fexfid-error"),o+=t[e].message}t&&t===this.props.file&&(i=(0,f.kt)().background3,o+=" Selected");let s=(0,r.jsx)(r.Fragment,{});this.props.isExpandable&&(s=(0,r.jsx)("div",{className:"fexfid-expander",onClick:this._handleToggleExpanderClick,title:"Expand/collapse "+this.props.file.name,children:this.props.isExpanded?(0,r.jsx)(a.g,{icon:l.xBV,className:"fa-lg"}):(0,r.jsx)(a.g,{icon:l.fU5,className:"fa-lg"})}));const c=t&&t===this.props.file,d=[];this.context.readOnly||(d.push({key:"rename",content:"Rename",shortcut:"F2"}),d.push({key:"duplicate",content:"Duplicate"}),d.push({key:"copypath",content:"Copy path"}),this.context.onFileOpenAsRaw&&d.push({key:"openasraw",content:"Open as Raw"}),g.Ay.hostType!==g.RN.electronWeb&&g.Ay.hostType!==g.RN.electronNodeJs||d.push({key:"revealinfolder",content:"Reveal in folder"}),d.push({key:"delete",content:"Delete",shortcut:"Del"}));const u=(0,r.jsxs)("div",{title:o,"aria-selected":!!c,className:"fexfid-summary",role:"treeitem",tabIndex:0,onClick:this._handleFileClick,children:[(0,r.jsx)("div",{className:"fexfid-icon",children:this.renderIcon()}),(0,r.jsx)("div",{className:"fexfid-label",children:this.props.file.name})]});let h;h=!this.context.readOnly&&d.length>0?(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{onContextMenu:e=>{e.preventDefault(),this.setState({contextMenuPosition:{top:e.clientY,left:e.clientX}})},children:u}),(0,r.jsx)(b.A,{open:null!==this.state.contextMenuPosition,onClose:this._handleContextMenuClose,anchorReference:"anchorPosition",anchorPosition:null!==this.state.contextMenuPosition?{top:this.state.contextMenuPosition.top,left:this.state.contextMenuPosition.left}:void 0,children:d.map(e=>(0,r.jsxs)(x.A,{onClick:()=>this._handleMenuClick(e.content),children:[e.content,e.shortcut&&(0,r.jsx)("span",{style:{marginLeft:"auto",paddingLeft:16,opacity:.6,fontSize:"12px"},children:e.shortcut})]},e.key))})]}):u;let p=(0,r.jsx)(r.Fragment,{});!this.context.readOnly&&d.length>0&&(p=(0,r.jsxs)("div",{className:"fexfid-menuButtonWrapper",children:[(0,r.jsx)(S.A,{className:"fexfid-menuButton",title:"File actions","aria-label":"File actions",size:"small",onClick:this._handleMenuButtonClick,children:(0,r.jsx)(a.g,{icon:l.vaG,className:"fa-sm"})}),(0,r.jsx)(b.A,{anchorEl:this.state.menuAnchorEl,open:Boolean(this.state.menuAnchorEl),onClose:this._handleMenuClose,children:d.map(e=>(0,r.jsxs)(x.A,{onClick:()=>this._handleMenuClick(e.content),children:[e.content,e.shortcut&&(0,r.jsx)("span",{style:{marginLeft:"auto",paddingLeft:16,opacity:.6,fontSize:"12px"},children:e.shortcut})]},e.key))})]}));const m=M(this.props.file.name),_=this.state.renameExtensionValue!==m.extension,y=!this.state.extensionUnlocked,k=null!==this.state.renameError,O=!this.state.renameBaseValue||k||_&&(!this.state.extensionUnlocked||!this.state.extensionChangeConfirmed),N=(0,r.jsxs)(C.A,{open:this.state.showRenameDialog,onClose:this._handleRenameDialogCancel,children:[(0,r.jsx)(T.A,{children:"Rename File"}),(0,r.jsxs)(E.A,{children:[(0,r.jsxs)("div",{style:{display:"flex",gap:8,alignItems:"flex-start",marginTop:8},children:[(0,r.jsx)(w.A,{label:"Name",value:this.state.renameBaseValue,onChange:this._handleRenameBaseChange,autoFocus:!0,size:"small",variant:"outlined",sx:{flex:1},inputProps:{"aria-label":"File name (without extension)"},error:k,helperText:this.state.renameError??" "}),(0,r.jsx)(w.A,{label:"Extension",value:this.state.renameExtensionValue,onChange:this._handleRenameExtensionChange,disabled:y,size:"small",variant:"outlined",sx:{width:140},inputProps:{"aria-label":"File extension"},placeholder:".ext",InputProps:{endAdornment:(0,r.jsx)(A.A,{position:"end",children:(0,r.jsx)(S.A,{size:"small",onClick:this._handleToggleExtensionLock,"aria-label":y?"Unlock extension to change it":"Lock extension","aria-pressed":!y,title:y?"Unlock to change extension":"Lock extension",children:(0,r.jsx)(a.g,{icon:y?l.DW4:l.pNp})})})}})]}),_&&this.state.extensionUnlocked&&(0,r.jsxs)(P.A,{severity:"warning",sx:{mt:2},action:this.state.extensionChangeConfirmed?void 0:(0,r.jsx)(D.A,{variant:"wood",onClick:this._handleConfirmExtensionChange,children:"Change anyway"}),children:["This will change the file type and may make it unreadable.",this.state.extensionChangeConfirmed&&" Extension change confirmed."]})]}),(0,r.jsxs)(I.A,{children:[(0,r.jsx)(D.A,{variant:"stone",onClick:this._handleRenameDialogCancel,children:"Cancel"}),(0,r.jsx)(D.A,{variant:"green",onClick:this._handleRenameDialogConfirm,disabled:O,children:"Rename"})]})]});return(0,r.jsxs)("div",{className:n,style:{backgroundColor:i},onKeyDown:e=>{if("Space"===e.key)this._handleToggleExpanderClick();else if("ArrowLeft"===e.key)this._handleCollapseClick();else if("ArrowRight"===e.key)this._handleExpandClick();else if("Enter"===e.key||" "===e.key)this._handleFileClick()," "===e.key&&e.preventDefault();else if("Delete"!==e.key||this.context.readOnly){if("F2"===e.key&&!this.context.readOnly){const e=M(this.props.file.name);this.setState({showRenameDialog:!0,renameBaseValue:e.base,renameExtensionValue:e.extension,extensionUnlocked:!1,extensionChangeConfirmed:!1})}}else{const e=this.props.file.name;window.confirm(`Delete ${e}?\n\nThis will permanently remove the file from your project.`)&&this.context.onFileDelete&&this.context.onFileDelete(this.props.file)}},children:[s,h,p,N,(0,r.jsx)(R.A,{open:null!==this.state.toastMessage,autoHideDuration:2500,onClose:()=>this.setState({toastMessage:null}),message:this.state.toastMessage??"",anchorOrigin:{vertical:"bottom",horizontal:"center"}})]})}}var L=i(59701);function F(e,t){if(!e)return;const i={},n=t.storageRelativePath;for(const t in e)t.startsWith(n)&&(i[t]=e[t]);return i}class B extends o.Component{static contextType=h;constructor(e){super(e),this.state={isLoaded:!1,isExpanded:this.props.startExpanded},this._fileExpandToggle=this._fileExpandToggle.bind(this),this.loadCabinetFile()}async loadCabinetFile(){let e;L.Ay.isContainerFile(this.props.file.storageRelativePath)&&(await this.props.file.loadContent(!1),e=await L.Ay.getFileStorageFolder(this.props.file),"string"==typeof e)||this.setState({cabinetRootFolder:e,isLoaded:!0})}_fileExpandToggle(e){this.setState({cabinetRootFolder:this.state.cabinetRootFolder,isLoaded:this.state.isLoaded,isExpanded:e})}render(){if(!this.state||!this.state.isLoaded)return(0,r.jsx)(r.Fragment,{});const e=[];let t=(0,r.jsx)(r.Fragment,{}),i="fexcf-bin";if(this.props.displayFileDetail&&(i="fexcf-binIndent",t=(0,r.jsx)(N,{file:this.props.file,isExpandable:!0,isExpanded:this.state.isExpanded,itemAnnotations:this.props.itemAnnotations,fileExplorer:this.props.fileExplorer,onExpandedSet:this._fileExpandToggle},"rootDetail")),this.state.cabinetRootFolder)for(const t in this.state.cabinetRootFolder.files){const i=this.state.cabinetRootFolder.files[t];i&&e.push((0,r.jsx)(N,{file:i,itemAnnotations:F(this.props.itemAnnotations,i),fileExplorer:this.props.fileExplorer},"fd"+t))}let n=(0,r.jsx)(r.Fragment,{});if(this.state.isExpanded&&(n=(0,r.jsx)("div",{className:i,children:e}),this.state.cabinetRootFolder))for(const t in this.state.cabinetRootFolder.folders){const i=this.state.cabinetRootFolder.folders[t];i&&!i.canIgnore&&e.push((0,r.jsx)(j,{folder:i,startExpanded:!1,itemAnnotations:F(this.props.itemAnnotations,i),fileExplorer:this.props.fileExplorer,displayFolderDetail:!0,depth:this.props.depth+1},"fo"+i.name))}return(0,r.jsxs)("div",{className:"fexcf-area",children:[t,n]})}}class j extends o.Component{static contextType=h;constructor(e){super(e),this.state={loadedExtendedPath:void 0,isExpanded:this.props.startExpanded},this._folderExpandToggle=this._folderExpandToggle.bind(this)}componentDidMount(){this.loadFolder(),this.state.isExpanded&&this.props.onExpandedChange&&this.props.onExpandedChange(1)}componentWillUnmount(){this.state.isExpanded&&this.props.onExpandedChange&&this.props.onExpandedChange(-1)}componentDidUpdate(e,t){e.folder!==this.props.folder&&this.loadFolder(),e.collapseAllToken!==this.props.collapseAllToken&&void 0!==this.props.collapseAllToken&&this.state.isExpanded&&(this.setState({isExpanded:!1}),this.props.onExpandedChange&&this.props.onExpandedChange(-1))}_folderExpandToggle(e){const t=this.state.isExpanded;this.setState({loadedExtendedPath:this.state.loadedExtendedPath,isExpanded:e}),t!==e&&this.props.onExpandedChange&&this.props.onExpandedChange(e?1:-1)}async loadFolder(){this.props.folder.extendedPath!==this.state.loadedExtendedPath&&await this.props.folder.load(),this.setState({loadedExtendedPath:this.props.folder.extendedPath})}render(){if(!this.state||!this.state.loadedExtendedPath)return(0,r.jsx)(r.Fragment,{});const{theme:e,selectedItem:t,mode:i,onFileSelected:o,onFolderSelected:s,project:a}=this.context,l=[];let c=(0,r.jsx)(r.Fragment,{}),d="fexfo-bin";(this.props.displayFolderDetail||i===n.folderPicker)&&(d="fexfo-binIndent",c=(0,r.jsx)(m,{folder:this.props.folder,isExpanded:this.state.isExpanded,itemAnnotations:this.props.itemAnnotations,fileExplorer:this.props.fileExplorer,onExpandedSet:this._folderExpandToggle},"rootDetail")),i!==n.folderPicker&&this.props.folder.getSortedFileKeys().forEach(e=>{const t=this.props.folder.files[e];t&&!t.canIgnore&&(L.Ay.isContainerFile(e)?l.push((0,r.jsx)(B,{file:t,displayFileDetail:!0,depth:this.props.depth+1,startExpanded:!1,itemAnnotations:F(this.props.itemAnnotations,t),fileExplorer:this.props.file