@dcl-regenesislabs/web-editor 0.3.16-40597790940.commit-6020aad → 0.3.16-40609313304.commit-caa7bdd
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/editor.js +8 -8
- package/package.json +2 -2
- package/scene-compiler/sdk-snapshot.json +1 -1
- package/scene-compiler/worker.js +22 -22
package/editor.js
CHANGED
|
@@ -32664,7 +32664,7 @@ module.exports = require('./index')
|
|
|
32664
32664
|
`,$Vt="web",jXe=/^[a-z0-9][a-z0-9-]{0,63}$/,Z1r=/^[A-Za-z0-9_.]{1,64}$/,K1r="\0";function zVt(t){let n="";for(const r of new TextEncoder().encode(t))n+=String.fromCharCode(r);return btoa(n)}function VVt(t){if(!jXe.test(t))throw new Error(`Invalid preview project id "${t}"`);return`/preview/${t}`}function WVt(t){if(!Z1r.test(t))throw new Error(`Invalid preview machine id "${t}"`);return"-"+t}const BXe=(t,n=$Vt)=>"b64-"+zVt(VVt(t)+WVt(n)),exr=(t,n,r,a=$Vt)=>"b64-"+zVt(`${VVt(t)}/${n}${K1r}${r}${WVt(a)}`),hTe=t=>t;async function txr(t){const n=new Uint8Array(await crypto.subtle.digest("SHA-256",hTe(t)));return String(n.slice(0,6).reduce((r,a)=>r*256+a,0))}const nxr="https://registry.npmjs.org",vWe=1024*1024,rxr={packages:200,unpackedBytes:100*vWe,tarballBytes:20*vWe};class Bh extends Error{constructor(n,r,a){super(r),this.code=n,this.pkg=a,this.name="PackageResolveError"}}const QBe=t=>t instanceof Error?t.message:String(t);function B0e(t){const n={};if(v_(t))for(const[r,a]of Object.entries(t))typeof a=="string"&&(n[r]=a);return n}function bWe(t,n){return t<n?-1:t>n?1:0}const xve=t=>Object.entries(t).sort(([n],[r])=>bWe(n,r));function Ene(t){try{return new URL(t).origin}catch{throw new Bh("invalid",`"${t}" is not a url`)}}function YBe(t,n){let r=t,a=n.trim();if(a.startsWith("npm:")){const s=a.lastIndexOf("@");r=s>4?a.slice(4,s):a.slice(4),a=s>4?a.slice(s+1):"latest"}return/^(file|link|portal):/.test(a)?{kind:"local"}:/^[a-z+]+:/.test(a)||a.startsWith("git@")||a.includes("/")||!rae(r)?{kind:"unsupported"}:{kind:"registry",name:r,range:a===""?"*":a}}function HAt(t,n){const r=v_(n)&&v_(n.dist)?n.dist:void 0;if(!v_(n)||r===void 0||typeof r.tarball!="string")throw new Bh("invalid",`the registry has no tarball for ${t}`,t);const a=B0e(n.optionalDependencies),s=B0e(n.dependencies);for(const x of Object.keys(a))delete s[x];const l=v_(n.peerDependenciesMeta)?n.peerDependenciesMeta:{},f={};for(const[x,T]of Object.entries(B0e(n.peerDependencies))){const C=l[x];!(v_(C)&&C.optional===!0)&&s[x]===void 0&&a[x]===void 0&&(f[x]=T)}const m=n.bundleDependencies??n.bundledDependencies,_=typeof r.integrity=="string"?r.integrity.split(/\s+/).find(x=>x.startsWith("sha512-")):void 0;return{tarball:r.tarball,integrity:_==null?void 0:_.split("?")[0],shasum:typeof r.shasum=="string"?r.shasum.toLowerCase():void 0,dependencies:s,optional:a,peers:f,bundled:m===!0?"all":new Set(Array.isArray(m)?m.filter(x=>typeof x=="string"):[]),platform:n.os!==void 0||n.cpu!==void 0||n.libc!==void 0}}async function JAt(t,n){return new Uint8Array(await crypto.subtle.digest(t,hTe(n)))}function ixr(t){let n="";for(const r of t)n+=String.fromCharCode(r);return btoa(n)}const axr=t=>Array.from(t,n=>n.toString(16).padStart(2,"0")).join("");function sxr(t){const n=t.url.replace(/\/+$/,""),r=Ene(n),a=new Map;let s=0;async function l(_,x){s++;let T;try{T=await t.fetch(_,{headers:x===void 0?void 0:{Accept:x},credentials:"omit",signal:t.signal})}catch(C){throw new Bh("network",`${_}: ${QBe(C)}`)}if(T.url!==""&&Ene(T.url)!==r)throw new Bh("registry-origin",`${_} was answered by ${Ene(T.url)}, not by ${r}`);return T}async function f(_){if(t.frozen)throw new Bh("frozen",`${_} is not pinned by the lock, and the project is frozen`,_);const x=await l(`${n}/${_.replace("/","%2f")}`,"application/vnd.npm.install-v1+json");if(x.status===404)throw new Bh("not-found",`${_} is not in the registry`,_);if(!x.ok)throw new Bh("network",`${_}: the registry answered ${x.status}`,_);let T;try{T=await x.json()}catch(C){throw new Bh("network",`${_}: ${QBe(C)}`,_)}if(!v_(T)||!v_(T.versions))throw new Bh("invalid",`${_}: the registry sent no versions`,_);return{tags:B0e(T["dist-tags"]),versions:T.versions}}async function m(_,x,T){var N;const C=new Bh("limit",`${x}: the tarball is larger than ${T} bytes`,x);if(Number(_.headers.get("content-length"))>T)throw C;try{const F=(N=_.body)==null?void 0:N.getReader();if(F===void 0){const te=new Uint8Array(await _.arrayBuffer());if(te.length>T)throw C;return te}const B=[];let H=0;for(;;){const{done:te,value:pe}=await F.read();if(te)break;if(H+=pe.length,H>T)throw await F.cancel(),C;B.push(pe)}const Z=new Uint8Array(H);let K=0;for(const te of B)Z.set(te,K),K+=te.length;return Z}catch(F){throw F instanceof Bh?F:new Bh("network",`${x}: ${QBe(F)}`,x)}}return{url:n,requests:()=>s,packument(_){let x=a.get(_);return x===void 0&&a.set(_,x=f(_)),x},async tarball(_,x,T){if(t.frozen)throw new Bh("frozen",`${_} is not in the package store, and the project is frozen`,_);if(Ene(x)!==r)throw new Bh("registry-origin",`${_}: its tarball is on ${Ene(x)}, not on ${r}`,_);const C=await l(x);if(!C.ok)throw new Bh("network",`${_}: the registry answered ${C.status}`,_);return m(C,_,T)}}}const oxr=new Set("assert async_hooks buffer child_process cluster console constants crypto dgram diagnostics_channel dns domain events fs http http2 https inspector module net os path perf_hooks process punycode querystring readline repl stream string_decoder sys timers tls trace_events tty url util v8 vm wasi worker_threads zlib".split(" ")),cxr=t=>t.startsWith("node:")||oxr.has(t.split("/",1)[0]),lxr=new RegExp(`(?<![.\\w$])require\\(\\s*['"]([^'"\\n]+)['"]\\s*\\)|\\b(?:import|export)\\b[^'"\\n;]*?\\bfrom\\s*['"]([^'"\\n]+)['"]|\\bimport\\s*\\(?\\s*['"]([^'"\\n]+)['"]`,"g"),uxr=/\.(js|mjs|cjs|json)$/,dxr=2e3,fxr=1024*1024;function pxr(t){const n=t.get("package.json");if(n===void 0)return{};try{const r=JSON.parse(new TextDecoder().decode(n));return v_(r)?r:{}}catch{return{}}}function mxr(t,n){const r=new R1r,a="/node_modules/"+t;for(const[x,T]of n)uxr.test(x)&&T.length<=fxr&&r.set(`${a}/${x}`,T);const s=new V1r({vfs:r}),l=s.resolve(t,"/","import"),f=new Set,m=new Set,_=l.kind==="file"?[l.path]:[];for(let x=_.pop();x!==void 0&&m.size<dxr;x=_.pop())if(!(m.has(x)||x.endsWith(".json"))){m.add(x);for(const T of(r.text(x)??"").matchAll(lxr)){const C=T[1]??T[2]??T[3],N=s.resolve(C,Vj(x),T[1]===void 0?"import":"require");N.kind==="file"?_.push(N.path):N.kind==="missing"&&cxr(C)&&f.add(C.replace(/^node:/,"").split("/",1)[0])}}return[...f].sort()}function hxr(t,n){const r=pxr(n),a=v_(r.scripts)?r.scripts:{},s=n.has("binding.gyp")||r.gypfile===!0,l=["preinstall","install","postinstall"].filter(f=>typeof a[f]=="string");return s&&!l.includes("install")&&l.push("install"),{installScripts:l,native:s||[...n.keys()].some(f=>f.endsWith(".node")),nodeBuiltins:mxr(t,n)}}class BA extends Error{constructor(n,r){super(r),this.reason=n}}const KW=512,Oxe=new TextDecoder;async function _xr(t,n){const a=new Blob([hTe(t)]).stream().pipeThrough(new DecompressionStream("gzip")).getReader(),s=[];let l=0;try{for(;;){const{done:_,value:x}=await a.read();if(_)break;if(l+=x.length,l>n)throw await a.cancel(),new BA("too-large",`unpacks to more than ${n} bytes`);s.push(x)}}catch(_){throw _ instanceof BA?_:new BA("malformed","is not a gzip archive")}const f=new Uint8Array(l);let m=0;for(const _ of s)f.set(_,m),m+=_.length;return f}function zre(t,n,r){let a=n;for(;a<n+r&&t[a]!==0;)a++;return Oxe.decode(t.subarray(n,a))}function gxr(t){if(t[124]&128)throw new BA("too-large","holds an entry larger than 8 GB");const n=parseInt(zre(t,124,12).trim()||"0",8);if(!Number.isSafeInteger(n)||n<0)throw new BA("malformed","has an entry with no valid size");return n}function yxr(t){let n=0;for(let r=0;r<KW;r++)n+=r>=148&&r<156?32:t[r];return n===parseInt(zre(t,148,8).trim(),8)}function vxr(t){const n={};for(let r=0;r<t.length;){let a=r;for(;a<t.length&&t[a]!==32;)a++;const s=Number(Oxe.decode(t.subarray(r,a)));if(!Number.isSafeInteger(s)||s<=0)break;const l=Oxe.decode(t.subarray(a+1,r+s-1)),f=l.indexOf("=");f>0&&(n[l.slice(0,f)]=l.slice(f+1)),r+=s}return n}function bxr(t){if(t.includes("\0"))throw new BA("unsafe-path","has an entry with a NUL in its path");const n=t.split(/[\\/]/);if(t.startsWith("/")||t.startsWith("\\")||/^[A-Za-z]:/.test(t))throw new BA("unsafe-path",`has an entry with an absolute path: ${t}`);if(n.includes(".."))throw new BA("unsafe-path",`has an entry that leaves the package: ${t}`);const r=n.filter(a=>a!==""&&a!==".").slice(1);return r.length===0?void 0:r.join("/")}function xxr(t){const n=new Map,r=[];let a,s={};for(let l=0;l+KW<=t.length;){const f=t.subarray(l,l+KW);if(f.every(B=>B===0))break;if(!yxr(f))throw new BA("malformed","is not a tar archive");const m=String.fromCharCode(f[156]||48),_=s.size===void 0?gxr(f):Number(s.size),x=l+KW;if(!Number.isSafeInteger(_)||x+_>t.length)throw new BA("malformed","is cut short");const T=t.subarray(x,x+_);if(l=x+Math.ceil(_/KW)*KW,m==="x"){s=vxr(T);continue}if(m==="g")continue;if(m==="L"){a=Oxe.decode(T).replace(/\0+$/,"");continue}if(m==="K")continue;const C=zre(f,257,5)==="ustar"?zre(f,345,155):"",N=s.path??a??(C===""?"":C+"/")+zre(f,0,100);a=void 0,s={};const F=bxr(N);if(!(m==="5"||F===void 0)){if(m!=="0"&&m!=="7"){r.push(F);continue}n.set(F,T.slice())}}return{files:n,skipped:r}}const wxr=4;async function Sxr(t){var qt;const n=sxr({url:t.registry??nxr,fetch:t.fetch??((Ve,Re)=>fetch(Ve,Re)),frozen:t.frozen===!0,signal:t.signal}),r={...rxr,...t.limits},a=((qt=t.snapshot)==null?void 0:qt.provided)??{},s=t.lock!==void 0&&t.lock.registry===n.url?t.lock:void 0,l={packages:0,downloaded:0,reused:0,requests:0,tarballBytes:0,unpackedBytes:0},f=[],m=(Ve,Re,$t)=>{f.some(vt=>vt.code===Ve&&vt.message===Re)||f.push({code:Ve,message:Re,...$t===void 0?{}:{package:$t}})},_=new Map,x=new Map,T=new Map,C=[],N={};async function F(Ve){if(_.has(Ve)||x.has(Ve)||(s==null?void 0:s.packages[Ve])!==void 0)return;const Re=Mq(Ve);if(Re===void 0)throw new Bh("invalid",`"${Ve}" is not a package version`);const $t=(await n.packument(Re.name)).versions[Re.version];if($t===void 0)throw new Bh("no-version",`${Ve} is not in the registry`,Ve);x.set(Ve,HAt(Ve,$t))}async function B(Ve,Re,$t){const vt=!bve(Re),xt=Ke=>{const st=Mq(Ke);return st!==void 0&&st.name===Ve&&(vt||ZW(st.version,Re))},ut=Ke=>_.has(Ke)||(s==null?void 0:s.packages[Ke])!==void 0;if($t!==void 0&&xt($t)&&ut($t))return $t;if(!vt){const Ke=tn=>{const An=WAt([...tn].filter(xt).map(un=>un.slice(Ve.length+1)),Re);return An===void 0?void 0:`${Ve}@${An}`},st=Ke(_.keys())??Ke(Object.keys((s==null?void 0:s.packages)??{}));if(st!==void 0)return st}const Nt=await n.packument(Ve),Ut=Nt.tags.latest,Wt=vt?Nt.tags[Re]:Ut!==void 0&&ZW(Ut,Re)?Ut:WAt(Object.keys(Nt.versions),Re);if(Wt===void 0||bG(Wt)===void 0||Nt.versions[Wt]===void 0)throw new Bh("no-version",`no version of ${Ve} matches "${Re}"`,Ve);const Me=`${Ve}@${Wt}`;return!_.has(Me)&&!x.has(Me)&&x.set(Me,HAt(Me,Nt.versions[Wt])),Me}function H(Ve,Re){var xt;if(_.has(Ve))return;if(_.size>=r.packages)throw new Bh("limit",`the project needs more than ${r.packages} packages`);const $t=x.get(Ve),vt=s==null?void 0:s.packages[Ve];if($t!==void 0)_.set(Ve,{resolved:$t.tarball,integrity:$t.integrity??"",dependencies:{}});else if(vt!==void 0)_.set(Ve,{resolved:vt.resolved,integrity:vt.integrity,dependencies:{...vt.dependencies}});else throw new Bh("invalid",`${Ve} was never resolved`,Ve);T.set(Ve,Re),C.push(Ve),(xt=t.onProgress)==null||xt.call(t,{type:"resolved",package:Ve})}function Z(Ve,Re){const $t=YBe(Ve,Re);if(t.frozen===!0||a[Ve]!==void 0||$t.kind!=="registry")return;const vt=xt=>xt.startsWith($t.name+"@")&&bve($t.range)&&ZW(xt.slice($t.name.length+1),$t.range);[..._.keys(),...Object.keys((s==null?void 0:s.packages)??{})].some(vt)||n.packument($t.name).catch(()=>{})}function K(Ve,Re,$t){const vt=a[Ve];if(vt===void 0)return!1;const xt=Re.trim();return vt!==""&&bve(xt)&&!ZW(vt,xt,{includePrerelease:!0})&&(Ve==="@dcl/sdk"&&$t===void 0?m("sdk-version",`This project pins @dcl/sdk ${xt}; it is built here with ${vt}.`,Ve):m("snapshot-version",`${$t??"This project"} asks for ${Ve} ${xt}; it gets the ${vt} the SDK ships.`,$t??Ve)),!0}function te(Ve,Re){var xt,ut;const $t=T.get(Re),vt=($t===void 0||(ut=(xt=_.get($t))==null?void 0:xt.dependencies)==null?void 0:ut[Ve])??N[Ve];return vt===void 0?void 0:Wj(Ve,vt)}async function pe(Ve){var Ut;const Re=_.get(Ve);if(Re===void 0)return;const $t=Re.dependencies??(Re.dependencies={}),vt=x.get(Ve);if(vt===void 0){for(const[Wt,Me]of xve({...$t})){if(a[Wt]!==void 0){delete $t[Wt];continue}const Ke=Wj(Wt,Me);await F(Ke),H(Ke,Ve)}return}const xt=[];for(const[Wt,Me]of Object.entries(vt.dependencies))xt.push([Wt,Me,"required"]);for(const[Wt,Me]of Object.entries(vt.optional))xt.push([Wt,Me,"optional"]);for(const[Wt,Me]of Object.entries(vt.peers))xt.push([Wt,Me,"peer"]);xt.sort(([Wt],[Me])=>bWe(Wt,Me));const ut=Wt=>vt.bundled==="all"||vt.bundled.has(Wt);for(const[Wt,Me,Ke]of xt)Ke!=="peer"&&!ut(Wt)&&Z(Wt,Me);let Nt=0;for(const[Wt,Me,Ke]of xt){if(Ke!=="peer"&&ut(Wt)||K(Wt,Me,Ve))continue;const st=YBe(Wt,Me);if(st.kind!=="registry"){m("unsupported-spec",`${Ve} depends on ${Wt} as "${Me}", which is not a registry version; it was left out.`,Ve);continue}try{let tn=Ke==="peer"?te(Wt,Ve):void 0;if(tn===void 0?tn=await B(st.name,st.range,void 0):bve(st.range)&&!ZW(tn.slice(tn.lastIndexOf("@")+1),st.range)&&m("peer-unmet",`${Ve} expects ${Wt} ${st.range}; the project uses ${tn}.`,Ve),Ke==="optional"&&((Ut=x.get(tn))==null?void 0:Ut.platform)===!0&&!_.has(tn)){Nt++;continue}H(tn,Ve),$t[Wt]=qAt(Wt,tn)}catch(tn){if(!(tn instanceof Bh)||tn.code==="limit"||tn.code==="frozen"||Ke==="required")throw tn;m(Ke==="peer"?"peer-unmet":"optional-skipped",`${Ve}: ${Wt} was left out (${tn.message}).`,Ve)}}Nt>0&&m("optional-skipped",`${Ve}: ${Nt} optional packages built for one platform were left out.`,Ve)}for(const[Ve,Re]of Object.entries(t.dependencies))typeof Re=="string"&&rae(Ve)&&(s==null?void 0:s.dependencies[Ve])===void 0&&Z(Ve,Re);for(const[Ve,Re]of xve(t.dependencies)){if(typeof Re!="string"||K(Ve,Re,void 0))continue;const $t=YBe(Ve,Re);if($t.kind==="local")continue;if($t.kind==="unsupported"||!rae(Ve)){m("unsupported-spec",`${Ve}: "${Re}" is not a registry version; it was left out.`,Ve);continue}const vt=s==null?void 0:s.dependencies[Ve],xt=await B($t.name,$t.range,vt===void 0?void 0:Wj(Ve,vt));H(xt,void 0),N[Ve]=qAt(Ve,xt)}for(const[Ve,Re]of Object.entries(t.devDependencies??{}))typeof Re=="string"&&K(Ve,Re,void 0);for(let Ve=C.shift();Ve!==void 0;Ve=C.shift())await pe(Ve);const fe=(Ve,Re)=>{if(l.unpackedBytes+=Re,l.unpackedBytes>r.unpackedBytes)throw new Bh("limit",`the packages unpack to more than ${r.unpackedBytes} bytes (at ${Ve})`,Ve)};async function X(Ve,Re){var Wt,Me;const $t=await n.tarball(Ve,Re.resolved,r.tarballBytes),vt="sha512-"+ixr(await JAt("SHA-512",$t));if(Re.integrity===""){const Ke=(Wt=x.get(Ve))==null?void 0:Wt.shasum;if(Ke===void 0||axr(await JAt("SHA-1",$t))!==Ke)throw new Bh("integrity",`${Ve}: the tarball does not match the checksum the registry lists`,Ve);Re.integrity=vt,m("weak-integrity",`${Ve} was published with a SHA-1 checksum only; the lock pins what was downloaded.`,Ve)}else if(vt!==Re.integrity)throw new Bh("integrity",`${Ve}: the tarball does not match its integrity (${Re.integrity})`,Ve);(Me=t.onProgress)==null||Me.call(t,{type:"downloaded",package:Ve,bytes:$t.length});let xt;try{xt=xxr(await _xr($t,2*r.unpackedBytes+vWe))}catch(Ke){throw Ke instanceof BA?new Bh(Ke.reason==="too-large"?"limit":"unsafe-tarball",`${Ve} ${Ke.message}`,Ve):Ke}const{files:ut}=xt;ut.delete(pTe);let Nt=0;for(const Ke of ut.values())Nt+=Ke.length;fe(Ve,Nt);const Ut={integrity:Re.integrity,files:ut.size,bytes:Nt,...hxr(Ve.slice(0,Ve.lastIndexOf("@")),ut)};await t.store.remove(Ve);for(const[Ke,st]of ut)await t.store.write(Ve,Ke,st);return await M1r(t.store,Ve,Ut),xt.skipped.length>0&&m("links-skipped",`${Ve}: ${xt.skipped.length} links in the tarball were left out.`,Ve),l.downloaded++,l.tarballBytes+=$t.length,Ut}const he=[..._.keys()],Ce=new Map;let qe=0,wt=!1;const ft=async()=>{var Ve;for(;qe<he.length&&!wt;){const Re=he[qe++],$t=_.get(Re);if($t!==void 0)try{const vt=await RVt(t.store,Re),xt=vt!==void 0&&vt.integrity===$t.integrity;xt&&(fe(Re,vt.bytes),l.reused++),Ce.set(Re,xt?vt:await X(Re,$t)),(Ve=t.onProgress)==null||Ve.call(t,{type:"stored",package:Re,reused:xt,done:Ce.size,total:he.length})}catch(vt){throw wt=!0,vt}}};await Promise.all(Array.from({length:Math.min(wxr,he.length)},ft));const St=new Set(Object.entries(N).map(([Ve,Re])=>Wj(Ve,Re)));for(const Ve of he){const Re=Ce.get(Ve);Re!==void 0&&(Re.installScripts.length>0&&m("install-script",`${Ve} declares ${Re.installScripts.join(", ")} scripts; they are not run here.`,Ve),Re.native&&m("native",`${Ve} ships native code, which a scene cannot load.`,Ve),Re.nodeBuiltins.length>0&&St.has(Ve)&&m("node-builtins",`${Ve} uses Node built-ins a scene does not have: ${Re.nodeBuiltins.join(", ")}.`,Ve))}const gt=(Ve,Re)=>{const[$t,vt]=[Mq(Ve),Mq(Re)];if($t===void 0||vt===void 0||$t.name!==vt.name)return bWe(Ve,Re);const[xt,ut]=[bG($t.version),bG(vt.version)];return xt===void 0||ut===void 0?0:FXe(xt,ut)},Ue={};for(const Ve of[...he].sort(gt)){const Re=_.get(Ve);if(Re===void 0)continue;const $t=Object.fromEntries(xve(Re.dependencies??{}));Ue[Ve]={resolved:Re.resolved,integrity:Re.integrity,...Object.keys($t).length>0?{dependencies:$t}:{}}}return l.packages=he.length,l.requests=n.requests(),{lock:{lockfileVersion:1,registry:n.url,dependencies:Object.fromEntries(xve(N)),packages:Ue},warnings:f,stats:l}}var QAt={};function YAt(t){return Array.isArray(t)?t:[t]}const xWe="",XAt=" ",XBe="\\",Txr=/^\s+$/,kxr=/(?:[^\\]|^)\\$/,Exr=/^\\!/,Cxr=/^\\#/,Axr=/\r?\n/g,Oxr=/^\.*\/|^\.+$/,ZBe="/";let qVt="node-ignore";typeof Symbol<"u"&&(qVt=Symbol.for("node-ignore"));const ZAt=qVt,Pxr=(t,n,r)=>Object.defineProperty(t,n,{value:r}),Ixr=/([0-z])-([0-z])/g,GVt=()=>!1,Nxr=t=>t.replace(Ixr,(n,r,a)=>r.charCodeAt(0)<=a.charCodeAt(0)?n:xWe),Dxr=t=>{const{length:n}=t;return t.slice(0,n-n%2)},Rxr=[[/^\uFEFF/,()=>xWe],[/((?:\\\\)*?)(\\?\s+)$/,(t,n,r)=>n+(r.indexOf("\\")===0?XAt:xWe)],[/(\\+?)\s/g,(t,n)=>{const{length:r}=n;return n.slice(0,r-r%2)+XAt}],[/[\\$.|*+(){^]/g,t=>`\\${t}`],[/(?!\\)\?/g,()=>"[^/]"],[/^\//,()=>"^"],[/\//g,()=>"\\/"],[/^\^*\\\*\\\*\\\//,()=>"^(?:.*\\/)?"],[/^(?=[^^])/,function(){return/\/(?!$)/.test(this)?"^":"(?:^|\\/)"}],[/\\\/\\\*\\\*(?=\\\/|$)/g,(t,n,r)=>n+6<r.length?"(?:\\/[^\\/]+)*":"\\/.+"],[/(^|[^\\]+)(\\\*)+(?=.+)/g,(t,n,r)=>{const a=r.replace(/\\\*/g,"[^\\/]*");return n+a}],[/\\\\\\(?=[$.|*+(){^])/g,()=>XBe],[/\\\\/g,()=>XBe],[/(\\)?\[([^\]/]*?)(\\*)($|\])/g,(t,n,r,a,s)=>n===XBe?`\\[${r}${Dxr(a)}${s}`:s==="]"&&a.length%2===0?`[${Nxr(r)}${a}]`:"[]"],[/(?:[^*])$/,t=>/\/$/.test(t)?`${t}$`:`${t}(?=$|\\/$)`],[/(\^|\\\/)?\\\*$/,(t,n)=>`${n?`${n}[^/]+`:"[^/]*"}(?=$|\\/$)`]],KAt=Object.create(null),Mxr=(t,n)=>{let r=KAt[t];return r||(r=Rxr.reduce((a,[s,l])=>a.replace(s,l.bind(t)),t),KAt[t]=r),n?new RegExp(r,"i"):new RegExp(r)},UXe=t=>typeof t=="string",Lxr=t=>t&&UXe(t)&&!Txr.test(t)&&!kxr.test(t)&&t.indexOf("#")!==0,Fxr=t=>t.split(Axr);class jxr{constructor(n,r,a,s){this.origin=n,this.pattern=r,this.negative=a,this.regex=s}}const Bxr=(t,n)=>{const r=t;let a=!1;t.indexOf("!")===0&&(a=!0,t=t.substr(1)),t=t.replace(Exr,"!").replace(Cxr,"#");const s=Mxr(t,n);return new jxr(r,t,a,s)},Uxr=(t,n)=>{throw new n(t)},sR=(t,n,r)=>UXe(t)?t?sR.isNotRelative(t)?r(`path should be a \`path.relative()\`d string, but got "${n}"`,RangeError):!0:r("path must not be empty",TypeError):r(`path must be a string, but got \`${n}\``,TypeError),HVt=t=>Oxr.test(t);sR.isNotRelative=HVt;sR.convert=t=>t;class $xr{constructor({ignorecase:n=!0,ignoreCase:r=n,allowRelativePaths:a=!1}={}){Pxr(this,ZAt,!0),this._rules=[],this._ignoreCase=r,this._allowRelativePaths=a,this._initCache()}_initCache(){this._ignoreCache=Object.create(null),this._testCache=Object.create(null)}_addPattern(n){if(n&&n[ZAt]){this._rules=this._rules.concat(n._rules),this._added=!0;return}if(Lxr(n)){const r=Bxr(n,this._ignoreCase);this._added=!0,this._rules.push(r)}}add(n){return this._added=!1,YAt(UXe(n)?Fxr(n):n).forEach(this._addPattern,this),this._added&&this._initCache(),this}addPattern(n){return this.add(n)}_testOne(n,r){let a=!1,s=!1;return this._rules.forEach(l=>{const{negative:f}=l;if(s===f&&a!==s||f&&!a&&!s&&!r)return;l.regex.test(n)&&(a=!f,s=f)}),{ignored:a,unignored:s}}_test(n,r,a,s){const l=n&&sR.convert(n);return sR(l,n,this._allowRelativePaths?GVt:Uxr),this._t(l,r,a,s)}_t(n,r,a,s){if(n in r)return r[n];if(s||(s=n.split(ZBe)),s.pop(),!s.length)return r[n]=this._testOne(n,a);const l=this._t(s.join(ZBe)+ZBe,r,a,s);return r[n]=l.ignored?l:this._testOne(n,a)}ignores(n){return this._test(n,this._ignoreCache,!1).ignored}createFilter(){return n=>!this.ignores(n)}filter(n){return YAt(n).filter(this.createFilter())}test(n){return this._test(n,this._testCache,!0)}}const Pxe=t=>new $xr(t),zxr=t=>sR(t&&sR.convert(t),t,GVt);Pxe.isPathValid=zxr;Pxe.default=Pxe;var Vxr=Pxe;if(typeof process<"u"&&(QAt&&QAt.IGNORE_TEST_WIN32||process.platform==="win32")){const t=r=>/^\\\\\?\\/.test(r)||/["<>|\u0000-\u001F]+/u.test(r)?r:r.replace(/\\/g,"/");sR.convert=t;const n=/^[a-z]:\//i;sR.isNotRelative=r=>n.test(r)||HVt(r)}const Wxr=Lxe(Vxr),qxr=[".*","package.json","package-lock.json","yarn-lock.json","build.json","export","tsconfig.json","tslint.json","node_modules","dclcontext","**/*.ts","**/*.tsx","Dockerfile","thumbnails","dist","README.md","*.blend","*.fbx","*.zip","*.rar","*.map","node_modules/**","*.md"];function $Xe(t,n){const r=Wxr().add([...(n==null?void 0:n.split(`
|
|
32665
32665
|
`))??[],...qxr].filter(Boolean)),a=[...t].filter(s=>!s.split("/").some(l=>l.startsWith(".")));return r.filter(a)}function Gxr(t){const n=t.scene;if(!v_(n))throw new Error('scene.json has no "scene" section');const{base:r,parcels:a}=n;if(typeof r!="string"||!Array.isArray(a))throw new Error("scene.json needs scene.base and scene.parcels");return[...new Set([r,...a.filter(s=>typeof s=="string")])]}function Hxr(t){const n=new Set,r=t.files.map(({path:a,version:s})=>{const l=a.toLowerCase();if(n.has(l))throw new Error(`Two files deploy as "${l}"; scene file names are case-insensitive`);return n.add(l),{file:l,hash:exr(t.projectId,a,s,t.machineId)}});return{version:"v3",type:"scene",id:BXe(t.projectId,t.machineId),pointers:Gxr(t.sceneJson),timestamp:t.timestamp,content:r,metadata:t.sdkVersion===void 0?t.sceneJson:{sdkVersion:t.sdkVersion,...t.sceneJson}}}const Ixe="dcl-editor-preview-v1",Jxr="dcl-editor-storage-v1";function wWe(t,n){if(!jXe.test(n))throw new Error(`Invalid preview project id "${n}"`);return new URL(`preview/${n}/`,t).href}const SWe=t=>t+"__manifest",eOt=(t,n)=>`${t}content/contents/${n}`;async function Qxr(t){const n=new URL(t.realmUrl).href;if(n!==wWe(new URL("../../",n),t.projectId))throw new Error(`"${t.realmUrl}" is not the preview realm of project "${t.projectId}"`);const r=new Map([...t.files,...t.buildOutputs]),a=r.get(".dclignore"),s=$Xe(r.keys(),a===void 0?void 0:new TextDecoder().decode(a)),l=await Promise.all(s.map(async B=>{const H=r.get(B)??new Uint8Array;return{path:B,bytes:H,version:await txr(H)}})),f=await caches.open(Ixe),m=await f.match(SWe(n)),_=await(m==null?void 0:m.json().catch(()=>{})),x=v_(_)&&typeof _.version=="number"?_.version:0,T=Hxr({projectId:t.projectId,sceneJson:t.sceneJson,files:l,timestamp:Date.now(),sdkVersion:t.sdkVersion,machineId:t.machineId}),C=new Set;await Promise.all(T.content.map(async({hash:B},H)=>{const Z=eOt(n,B);C.add(new URL(Z).href),await f.match(Z)===void 0&&await f.put(Z,new Response(hTe(l[H].bytes),{headers:{"Content-Type":"application/octet-stream"}}))}));const N={version:x+1,entity:T};await f.put(SWe(n),new Response(JSON.stringify(N),{headers:{"Content-Type":"application/json"}}));const F=eOt(n,"");for(const B of await f.keys())B.url.startsWith(F)&&!C.has(B.url)&&await f.delete(B);return{realmUrl:n,entityId:T.id}}const Yxr="0.1.0";function Xxr(t){try{return JSON.parse(t)}catch{throw new Error("Invalid scene request.")}}function Zxr(t){const n=pXe({paths:async()=>[...t.files().keys()],read:async r=>t.files().get(r),write:(r,a,s,l)=>t.write(r,a,s,l),...t.written===void 0?{}:{written:t.written}});return async(r,a)=>{a.throwIfAborted();const{tool:s,args:l}=r;if(s==="playtest"){if(t.playtest===void 0)throw new Error("Playtesting requires an updated editor.");return JSON.stringify(await t.playtest(l,a))}if(s==="ui_layout"){if(t.uiLayout===void 0)throw new Error("Measuring the UI requires an updated editor.");return JSON.stringify(await t.uiLayout(l,a))}if(s==="asset_request"){if(t.assets===void 0)throw new Error("Asset tools require an updated editor.");return JSON.stringify(await t.assets(l,a))}if(s==="build")return JSON.stringify(await t.build(a));if(s==="view")return JSON.stringify(await t.view(ozt(l),a));if(s==="scene_request")return JSON.stringify(await t.scene(typeof l.request=="string"?Xxr(l.request):l.request,a));if(!u$t(s))throw new Error("Unknown browser tool.");return n(s,l,a)}}function Kxr(t){const n=new Set;let r=null,a=null,s=0,l=null,f=Promise.resolve(),m=null;const _=X=>{for(const he of n)he(X)},x=X=>[{id:"claude",label:"Claude",available:!1,models:[],defaultModel:"",transport:"service",reason:X}],T=X=>{(r==null?void 0:r.readyState)===WebSocket.OPEN&&r.send(JSON.stringify(X))};function C(X,he,Ce="stopped"){var wt;const qe=l;qe!==null&&(l=null,qe.controller.abort(),(wt=qe.ended)==null||wt.call(qe).catch(ft=>console.error("[assistant] ending the turn failed",ft)),he!==void 0&&_({kind:"error",turnId:qe.id,message:he}),_({kind:"done",turnId:qe.id,ok:X}),Xx(X?"prompt_completed":"prompt_failed",{project_id:qe.projectId,model:qe.model,duration_ms:Date.now()-qe.started,tool_calls:qe.calls.size,...X?{}:{error:Ce}}))}function N(X){const he=dl(X.args.request)?X.args.request:{};switch(X.tool){case"write_file":return null;case"read_file":return{tool:"Read",detail:typeof X.args.path=="string"?X.args.path:""};case"search_files":return{tool:"Search",detail:typeof X.args.query=="string"?X.args.query:""};case"edit_file":return null;case"asset_request":return{tool:"Assets",detail:String(X.args.action??"")};case"build":return{tool:"Build",detail:"Scene"};case"view":return{tool:"View",detail:X.args.target==="mobile"?"Mobile preview":X.args.target==="editor"?"Editor":"Current view"};case"playtest":return{tool:"Playtest",detail:`${String(X.args.action??"")}${X.args.platform==="mobile"?" (mobile)":""}`};case"ui_layout":return{tool:"UI layout",detail:"Screen"};case"scene_request":if(he.type==="batch"&&Array.isArray(he.requests))return{tool:"Scene",detail:`${he.requests.length} changes`};if(he.type==="sceneSettings")return{tool:"Scene",detail:"Settings"};if(he.type==="saveThumbnail")return{tool:"Thumbnail",detail:"New version"};if(he.type==="readThumbnail")return{tool:"Thumbnail",detail:"Current"};if(he.type==="useThumbnail")return{tool:"Thumbnail",detail:`Version ${String(he.version)}`};if(he.type==="attachScript")return null}return{tool:"Inspect",detail:"Project"}}function F(X,he,Ce,qe){const wt=he.label===void 0?{}:{label:he.label},ft=N(he);if(ft!==null){qe||_({kind:"tool",turnId:X,...ft,...wt});return}if(he.tool==="write_file"||he.tool==="edit_file"){const St=typeof he.args.path=="string"?he.args.path:"";_({kind:"tool",turnId:X,tool:he.tool==="write_file"&&he.args.revision===null?"Write":"Edit",detail:St,...wt})}}async function B(X){const he=l;if(he===null||he.id!==X.turnId||he.controller.signal.aborted)return;let Ce=!1,qe="",wt=!1;try{if(t.wallet()!==he.wallet||t.project().id!==he.projectId)throw new Error("The open project or account changed.");if(X.label!==void 0){const ft=N(X);ft!==null&&(_({kind:"tool",turnId:he.id,...ft,label:X.label}),wt=!0)}if(qe=await he.execute(X,he.controller.signal),qe.length>5e5)throw new Error("The tool result is too large. Ask for a smaller part of the project.");he.controller.signal.throwIfAborted(),Ce=!0,F(he.id,X,qe,wt)}catch(ft){qe=ft instanceof Error?ft.message:typeof ft=="string"&&ft!==""?ft:"The browser tool failed."}l===he&&!he.controller.signal.aborted&&T({kind:"result",turnId:he.id,callId:X.callId,ok:Ce,text:qe})}function H(X){let he;try{he=JSON.parse(X)}catch{C(!1,"Invalid assistant response.","invalid_response");return}if(!dl(he))return;if(he.kind==="failure"&&typeof he.message=="string"){C(!1,he.message,"service_failure");return}if(he.kind==="call"&&typeof he.turnId=="string"&&typeof he.callId=="string"&&hSn.test(he.callId)&&ySn.includes(String(he.tool))&&dl(he.args)){const{label:qe,...wt}=he,ft=typeof qe=="string"?{...wt,label:qe}:wt;if(l===null||l.id!==ft.turnId||l.calls.has(ft.callId))return;l.calls.add(ft.callId);const St=vSn(ft.tool,ft.args),gt=(St?Promise.resolve():f).then(()=>B(ft)).catch(Ue=>{console.error("[assistant] browser tool failed",ft.tool,Ue),(l==null?void 0:l.id)===ft.turnId&&C(!1,"The browser tool failed.","tool_failed")});St||(f=gt);return}if(he.kind!=="event"||!dl(he.event))return;const Ce=he.event;if(!(l===null||Ce.turnId!==l.id)){if(Ce.kind==="text"&&typeof Ce.text=="string"&&_({kind:"text",turnId:l.id,text:Ce.text}),Ce.kind==="error"&&typeof Ce.message=="string"){const qe=Ce.resumable===!0;qe&&(m=r),l.error=qe?"limit":"assistant_error",_({kind:"error",turnId:l.id,message:Ce.message,...qe?{resumable:qe}:{}})}Ce.kind==="done"&&typeof Ce.ok=="boolean"&&C(Ce.ok,void 0,l.error??"assistant_error")}}async function Z(){if((r==null?void 0:r.readyState)===WebSocket.OPEN)return r;if(a!==null)return a;const X=s,he=(async()=>{if(t.service===null)throw new Error("The assistant service is not configured.");const Ce=await t.fetch(`${t.service}/assistant/connect`,{method:"POST"});if(!Ce.ok)throw new Error("The assistant service is unavailable. Sign in and recheck.");const qe=await Ce.json();if(!dl(qe)||typeof qe.token!="string")throw new Error("Invalid assistant connection.");if(X!==s)throw new Error("Connection cancelled.");const wt=new URL(`${t.service}/assistant/socket`,location.href);wt.protocol=wt.protocol==="https:"?"wss:":"ws:";const ft=new WebSocket(wt,[_Sn,gSn+qe.token]);return r=ft,new Promise((St,gt)=>{let Ue=!1;const qt=setTimeout(()=>{ft.close(),gt(new Error("Assistant connection timed out."))},1e4);ft.onmessage=({data:Ve})=>{if(r===ft&&typeof Ve=="string")if(Ue)H(Ve);else{let Re;try{Re=JSON.parse(Ve)}catch{ft.close();return}if(!dl(Re)||Re.kind!=="ready")return;Ue=!0,clearTimeout(qt),St(ft)}},ft.onerror=()=>{ft.close(),gt(new Error("Could not connect to the assistant service."))},ft.onclose=()=>{clearTimeout(qt),r===ft&&(r=null,C(!1,"Assistant connection closed. Your edits are saved; the next message starts a new conversation.","connection_closed")),gt(new Error("Assistant connection closed."))}})})();a=he;try{return await he}finally{a===he&&(a=null)}}function K(){try{return t.project().id}catch{return null}}async function te(X,he){try{const Ce=await t.memory.read(X,he);if(Ce!==null)return Ce;const qe={id:ewr(crypto.getRandomValues(new Uint8Array(16))),key:twr(crypto.getRandomValues(new Uint8Array(32)))};return await t.memory.write(X,he,qe),qe}catch{return}}function pe(){s++,T({kind:"reset"}),C(!1);const X=r;return r=null,a=null,X==null||X.close(),f}return{shell:{async aiProviders(){if(t.wallet()===null)return x("Sign in to Decentraland to use the assistant.");if(t.service===null)return x("The assistant service is not configured.");try{const X=await t.fetch(`${t.service}/assistant/providers`);if(!X.ok)return x("The assistant service is unavailable. Recheck when it is running.");const he=await X.json();return Array.isArray(he)?he.filter(Ce=>dl(Ce)&&(Ce.id==="claude"||Ce.id==="codex")&&typeof Ce.label=="string"&&typeof Ce.available=="boolean"&&typeof Ce.defaultModel=="string"&&Array.isArray(Ce.models)&&Ce.models.every(qe=>typeof qe=="string")).map(Ce=>({...Ce,transport:"service"})):x("The assistant service returned an invalid provider list.")}catch{return x("Could not reach the assistant service. Recheck your connection.")}},async aiSend(X){var wt,ft;if(l!==null)throw new Error("A turn is already running.");const he=t.wallet();if(he===null)throw new Error("Sign in to use the assistant.");m=null;const Ce=t.project(),qe={id:crypto.randomUUID(),wallet:he,projectId:Ce.id,controller:new AbortController,calls:new Set,execute:Zxr(Ce.tools),ended:Ce.tools.turnEnded,started:Date.now(),model:X.model??null,error:null};l=qe,_({kind:"started",turnId:qe.id}),Xx("prompt_sent",{project_id:Ce.id,provider:X.provider,model:qe.model,prompt_length:X.text.length,images:((wt=X.images)==null?void 0:wt.length)??0});try{if(await Z(),qe.controller.signal.throwIfAborted(),t.wallet()!==he||t.project().id!==Ce.id)throw new Error("The open project or account changed.");const St=await te(Ce.id,he);qe.controller.signal.throwIfAborted();const gt=(ft=t.mobilePreview)==null?void 0:ft.call(t),Ue=gt===void 0?X.context:[X.context,`[Mobile preview] ${JSON.stringify({mode:gt.mode,ready:gt.ready})}`].filter(Boolean).join(`
|
|
32666
32666
|
|
|
32667
|
-
`);T({kind:"prompt",turnId:qe.id,projectId:Ce.id,params:{...X,context:Ue},memory:St})}catch(St){l===qe&&C(!1,St instanceof Error?St.message:"Could not start the assistant.","start_failed")}return{turnId:qe.id}},async aiStop(){l!==null&&T({kind:"stop",turnId:l.id}),await pe()},async aiReset(){await pe()},async aiForget(){const X=t.wallet(),he=(l==null?void 0:l.projectId)??K();l!==null&&T({kind:"stop",turnId:l.id}),C(!1);const Ce=X===null||he===null?null:await t.memory.read(he,X).catch(()=>null);Ce!==null&&X!==null&&he!==null&&(T({kind:"forget",id:Ce.id}),await t.memory.write(he,X,null).catch(()=>{})),await pe()},aiCanResume:()=>m!==null&&m===r&&r.readyState===WebSocket.OPEN,onAiEvent(X){return n.add(X),()=>{n.delete(X)}}},reset:pe,dispose(){pe(),n.clear()}}}function ewr(t){return Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}function twr(t){return btoa(String.fromCharCode(...t)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function gB(t){const n={"scene-compiler/worker.js":"sha384-
|
|
32667
|
+
`);T({kind:"prompt",turnId:qe.id,projectId:Ce.id,params:{...X,context:Ue},memory:St})}catch(St){l===qe&&C(!1,St instanceof Error?St.message:"Could not start the assistant.","start_failed")}return{turnId:qe.id}},async aiStop(){l!==null&&T({kind:"stop",turnId:l.id}),await pe()},async aiReset(){await pe()},async aiForget(){const X=t.wallet(),he=(l==null?void 0:l.projectId)??K();l!==null&&T({kind:"stop",turnId:l.id}),C(!1);const Ce=X===null||he===null?null:await t.memory.read(he,X).catch(()=>null);Ce!==null&&X!==null&&he!==null&&(T({kind:"forget",id:Ce.id}),await t.memory.write(he,X,null).catch(()=>{})),await pe()},aiCanResume:()=>m!==null&&m===r&&r.readyState===WebSocket.OPEN,onAiEvent(X){return n.add(X),()=>{n.delete(X)}}},reset:pe,dispose(){pe(),n.clear()}}}function ewr(t){return Array.from(t,n=>n.toString(16).padStart(2,"0")).join("")}function twr(t){return btoa(String.fromCharCode(...t)).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,"")}function gB(t){const n={"scene-compiler/worker.js":"sha384-GCCoSf3nYqyLm3kwF1wvfutA2SwiKz+wOa7yR64wlYmZG3WUWSQDohcoBi9yQy2e","scene-compiler/esbuild.wasm":"sha384-V8Ml7eHSlgGTb/TR1IYB6LtWwAW1NXLDPRjL2FjxwIfqDkSZ/hp+zmfvXDHqu8NV","scene-compiler/sdk-snapshot.json":"sha384-z1EjDWcfwcGr+O+ZEdboDWdpOFpL1uFiAcYiJnz2eZ0tw0QKKfPWZA65ibuYEGAA","three/worker.js":"sha384-fpaxQE7sJmPgdwwsCLEkPRmp3A++vppj0bqkpV7a8egKEfBEEP4o/pD2eYfsXZTp","prefabs/catalog.json":"sha384-7rYPa+NmVOozQBrgcfao3ZUO+ou6ANruPMNRsXhTydwM4lUalT9YzUEr6Xm3u8Nl","materials/T_Bark_D.jpg":"sha384-FtUe6G243wHZ8C0kbR+2lFVHp/atYXEPodY4A1qDQquYeu27euNDRDqEyFoQJ29L","materials/T_Bark_N.jpg":"sha384-EhhyT3HTQ3sy1CVvKMTX+ueIGq2+FgDntZ6lKFZW6sHOrCTCMbxnDhthwQIanVOr","materials/T_Cobblestone_D.jpg":"sha384-lSuwYcPhIyqVZvG0NuB93ESZIEqL0ffEmD7gh6iG3qN4elINxt7KQS8CN4Ay2CQ0","materials/T_Cobblestone_N.jpg":"sha384-A+Xe7cTTQGB4hwE6WPsWgD76xwIZ2/FFlxqeWZnyFk5AWaK6hDEKCEZVeVinJ3uw","materials/T_Concrete_D.jpg":"sha384-1dPzQGKxZAw2NloRUM+KhE0X9XeTLUxBrvkw4Uaa4Gm/ID65iDv+yPWUHYi59gYn","materials/T_Concrete_N.jpg":"sha384-8+TiM45B8TCGHYOHh5/510IpXfo1WgyaS5q/T1B3GOEdQrXHV+x9yXmyjkN9mWsh","materials/T_FloorTiles_D.jpg":"sha384-PwDH1P94cY4VXHyrbTQSpvDh89A5jMf+xG62xUDT9TRbItuR6uI1lXB9onxu4gaX","materials/T_FloorTiles_N.jpg":"sha384-opjmq0wL8b+pxHcujr8IGFCOQt8+pDX7EjcnmzmcKGy7F8H3dv9IgG7gxQXgkQJu","materials/T_Grass_D.jpg":"sha384-GGodYBboPnhEcv7JVlR1mSjLWux7q4qJcOxqdl7a/6bN6IWkel4A1BeHV4sieS25","materials/T_Grass_N.jpg":"sha384-zu3ig6Su3u2I3e3LX2zeaS9LtqJYl8V3siVjWBQ2Xea6iMAcMCXHp2HQyctvaEY2","materials/T_Gravel_D.jpg":"sha384-Y2EZTiFeTQbZlduNmz1Y74fZIvkmh8c2grqr6B1GqejChZbNnRb5ejC8SCqyPY77","materials/T_Gravel_N.jpg":"sha384-VWUAPWQZqvuFDmiZZvhAgqQ24DmSrByuu7ETrD2igGikpZS+U7E81hAJ3Iiv88iT","materials/T_Ice_D.jpg":"sha384-qNSYRVYvzZ6NP5Ny/MDMNajmplmSXf9036CidUKqte1DUUDzMm28FZvWcAMSnyux","materials/T_Ice_N.jpg":"sha384-LYz8XTf6DXyxCy6Jtci0y6E0/ER4b73sdH6lhCbagK8nuYPpD8ChpB8PZUTLMLkF","materials/T_Marble_D.jpg":"sha384-MfvwmuTcZs+OB9BLKNAFU849wj27KcdPxxvF3WAY9OrZGtQORoHXjDWh2YWBukWk","materials/T_Marble_N.jpg":"sha384-SU6JhDtveHoi5d1AUiQV8oVfO1uEChNA7ACvMv1OIKESECfG1lCMw6MG7TZrGhnf","materials/T_MetalPlate_D.jpg":"sha384-Qe4yIHUfUVMwOEDZTsY0u7d19xhUE/GiSyz0s3P9297mx+XXGvDCR8gKdU9hLhbo","materials/T_MetalPlate_N.jpg":"sha384-RpCdFzgg7xIUz1G+nDJEon1H0MHwsk4RHOTfi2Er2hC56AXU2TXcToTY12aqz+4R","materials/T_Metal_D.jpg":"sha384-h2Fs2s1/WPYJwUY3a6vpMqrd0rb7GDWViOvw8SlsSocO/sBqcqzzbjOwYR9uooVE","materials/T_Metal_N.jpg":"sha384-iVL98sXzJCK2z/YuoBw0pwbZyes0ZprTHsvQdFQ6tXhKP5004tHMWJnr5icUVwKp","materials/T_MossyRock_D.jpg":"sha384-5sB1xTHnLgeGIiY5kqc5kr78xBvR17BBrWJZD1IyyEuFO8mcgJ7DaAKH9ZcrV0Oj","materials/T_MossyRock_N.jpg":"sha384-z+02Z5HZoLwVk/i0R/YRm/MW/KQr3Y5h4cB0iH837QsKMrvzrO6iFMuBWXER8ZLk","materials/T_OldBrick_D.jpg":"sha384-1h+VtTgiyyfZ9N5h15snvPP5bjvvI5Mzq958DaMi0BTJKxFbtKoYjnWp9mkhDBTZ","materials/T_OldBrick_N.jpg":"sha384-mORhqcYtb2adL11dYPIpTKvrTVqiz1mqHVW/abZaSerjsKMEvRa5uxoe65nfUmzF","materials/T_Planks_D.jpg":"sha384-olCbQDlaUR5rNCiEPsJt3Z6XYD2L1McfZNZOBdCDsIo4dyKa9Y41H3mCbdY1BMqL","materials/T_Planks_N.jpg":"sha384-Qe2LOHGe2f/b8RdZmZRSrZl0KMgxMT28Q0yj/Ewr0TRsmSe4L1N9TxQscZ7jXIpz","materials/T_RedBrick_D.jpg":"sha384-z5Omhin/SbXfu6KqUuKYyVFQN5GIkfCtva/SIM3g8C09Dy/ajUgaCrQYUQv0Wi6s","materials/T_RedBrick_N.jpg":"sha384-N5Zlk1HLC7ECYSYp9JAlKc9UZk3lFIytrdyYTNCyrRAD6IMQMGM178Ns5ICXoBcY","materials/T_Rock_D.jpg":"sha384-JPbUh7M8Yt82J9u9P3cMPWNBNNDN2MOkMhb4BpWOQ1MUacVygOKoKHOAspiyAaDI","materials/T_Rock_N.jpg":"sha384-d2AXOT8FPWfSBdhZGN2U85WRbKq02qgDIFhEcp9/ZrTfzPPpb3x+1tM3pRfflGWG","materials/T_RoofTiles_D.jpg":"sha384-XyFas+mKIHi1ZJxhOpjcJ3aE7SZjOUukcY1wZqJ0kcwMjYE2SD5mv/Ft1babZiRk","materials/T_RoofTiles_N.jpg":"sha384-OtknIACV+BRu+g5+hVLWILG4Qli4fIDdqqrf3rFTuGr/VxhZIGgxC61tMM7Tr5pt","materials/T_RustyMetal_D.jpg":"sha384-vN18ZCLm3ijlv9l30lI/rUbcUpcJH0ut4hF8GueDNYPZO4WDiqxJH9EX70DGsEsh","materials/T_RustyMetal_N.jpg":"sha384-+rdn3/f1t/jU65sT0kq03mG9HtAIA3a1+bezGQmXOV9FiCM2KUCIugsOUhQAzmjO","materials/T_Sand_D.jpg":"sha384-i3zMj/gXeIpnlll08lxRRvQ9BA+j/3bLnzru+M3LzjvyhwMKgz6bmnLjhe1rPZrz","materials/T_Sand_N.jpg":"sha384-eBZtZpK8wZnUmtNfV5iCt/l4WWvoppG0bFkFeULvqw5gNkT+emO5u8AVtpRTFjxM","materials/T_Snow_D.jpg":"sha384-kOAg+1SQpFtFg/XpbSTT+Boo6hGe/+BXR3fI2pgrTyl0VJTrc2W1pUKlT38nSP6k","materials/T_Snow_N.jpg":"sha384-8ryXPS0Yprm5vNZCUadJRhKh4MQ+8gkD0q1GbjlPLez7GSjsV7QmAyM63PiIn0cK","materials/T_StoneBlocks_D.jpg":"sha384-o2TlIP/+m+uvEmypAk3zXE+9huFaU3K+VTD18p8vPEb9I3SVB1n2ez1jqZTXZNQF","materials/T_StoneBlocks_N.jpg":"sha384-eR/UR9FC3v3Pw4oBlWlOyQNmtgvb5a1mSRwSBMrQhDyXk4neOjmVlTyjBjhOTYOU","materials/T_Wood_D.jpg":"sha384-Tk9jMT15vysCDRdd22J2mFUHCBSHVMhGNa71sYFf7yqvZQkmMGdrIhiIsmi/fAm2","materials/T_Wood_N.jpg":"sha384-b1SWrWCwyf+89JAlVNPCwmwkUTrcGXUqRANI3x+grecaCQblZGLsSaJx/5CNPnPC","sounds/click.mp3":"sha384-5Nn2A2LWwXVAhOJKiwTncPtBTCtmrqOVQVAuz+xHRrAuMnScsTQ06gM0dU14yxa1","sounds/close.mp3":"sha384-JBoxn91EXhKXI4EJZ1nlDO3U735Nz6Nn1UuzpPhRjjpMaEOafABEqQL8GgfV7XTi","sounds/coin.mp3":"sha384-2RR7dy+f4rzUKdiGeSdApfQmbsENC4FzT8o4y3JXs5IX6a2udQbwU3iLhCUZ+z1a","sounds/countdown-tick.mp3":"sha384-I1gWiwXYWkrQ3dmkVDqolRCU+O/OkVqH625gdQZ8i3mntGSNBKJN1u2yPzmiPOio","sounds/door-close.mp3":"sha384-V/WOG/jNZMVo2EK2wosamkz0F/OjilfprwqVR0JwxFuLjzaIGOG6LFUxp1RB2NF6","sounds/door-open.mp3":"sha384-toZQ6Li9ckUBKJ2Ct9j0VihbOL/1cckuyURTQZoeGWNs9O37cudKQDiQZwGpY7zq","sounds/error.mp3":"sha384-/1dEHJ1qoAxzjSucYUOOSu2v1iZYjiVyKIKHvXI6YgbdXR9ekFvFcoeyGSvpOClG","sounds/explosion.mp3":"sha384-ltgcuLllD+21WOWShc9fHRcMCHja6CjvrriwZ6q+svIzA6sjbOzL7as5pD7F6cZg","sounds/fire-loop.mp3":"sha384-961Bvf7i+Y4Ij2823D68797moLbDjrru/1gSbAn3s9G5acVoQbcwrE1hqd94K/XV","sounds/gem.mp3":"sha384-R3zEhJWNA8xL6l1SGy4l81c6sRAsYweKJr1LzwbB/te+hd1PRu6vtm+z1pV8JHV/","sounds/hit.mp3":"sha384-gNRf3+uQRBdPYgenEiKF7x4nZTu0+MSc3k6g4Mzj9pERNfyzmB0eluHrvUSXIQxf","sounds/jump.mp3":"sha384-5Fq5FzFq3J7aaa65LLaRIQ2rDWdBrj6kX1YuIxizC+N5DKmz6yVrZvhOEcdHETZa","sounds/land.mp3":"sha384-FzP8V/7gNObRoNTgDtomIrCIaLPQwp45q2AoqEEmxTVHzgf2Tqs56rqNcasWD/Df","sounds/lever.mp3":"sha384-/l81+1qFlkY+VOiv9vSv80lS2V6FUoHnNNw1CHWNHkxaWbE7qXXIn5byS/0tNnwQ","sounds/lose.mp3":"sha384-Fko/fFGTQf6WOcJz9iDlgfYtldodfjcUgH0hgNGU72c+OntJLlAYQ0i8ZcRFBuoA","sounds/machine-loop.mp3":"sha384-HK+6s/ohv0LmgMNH4XCP8gYdyYNsUQ7MiBgCJSvnznGhXaviNkvZHMZZTo2+Nvkl","sounds/open.mp3":"sha384-r8PUU3VxFOwpVcmIhwYOg6BYUhYrOQnJT4CgVz4V9ooVpM0NeaAhGMPURavBdanE","sounds/point.mp3":"sha384-98vZ+QorY3iw1bm7sRNIm54Mq0LroKWsCNFrPt6aAQ3ZhHN7+I4ibwsu+TxgWf3a","sounds/power-up.mp3":"sha384-URbVyheAkb87lZdDT3iWJQAIJfyUzk8ieEwX2Hv/PFNSqnO098E9mqdhy0KeQM9m","sounds/rumble-loop.mp3":"sha384-1KsyvSyAN9bm4ZrCRF/3+bHDDVvnC560HXk48Zjr+26capvQS0IvtmvFqrdcFgs/","sounds/splat.mp3":"sha384-2aZ/C6hYBRqXPnSZq2TB9M5u3EFDOVxQjeMGOswRv43CzuL0ZAysUhX/nnHr07Hi","sounds/start.mp3":"sha384-zw5mXd2OL6pbHLz5xdyjQn9nc7AVDgLqx1MSiPYehc6yI0Odt5qTh1TyJNpqxJVC","sounds/teleport.mp3":"sha384-pkpm8x8Aknup+URiIAhz9whdPkPLRoJlhdGYRM/2FJyzzaemjIZoIveJ339G3eFU","sounds/time-up.mp3":"sha384-UeQg6KkMKoeiiRIft0T5z3MU8NM9hLZbx3Smhsz7voAqGb/u7Ndag6lpHOaxqhVY","sounds/win.mp3":"sha384-I8Pyt8U4kbyk9xAoxcimTKSgF9BTr4Nf1t63E/Olnahu2FKJ0G6oLPIVD7CotGiH","editor.css":"sha384-UtVv2Sy+fO5029No4SyC1iW7hUXbIfy4nqF1QP2S8A7M1rUOv5qoJPnxdiNzAF60"}[t];if(n===void 0)throw new Error(`${t} is not one of the editor's published files`);return n}function nwr(t){const n=r=>new URL(`scene-compiler/${r}`,t).href;return{workerUrl:n("worker.js"),wasmUrl:n("esbuild.wasm"),snapshotUrl:n("sdk-snapshot.json"),integrity:{worker:gB("scene-compiler/worker.js"),wasm:gB("scene-compiler/esbuild.wasm"),snapshot:gB("scene-compiler/sdk-snapshot.json")}}}function rwr(t){let n=null;return async()=>(n??(n=mTe(new URL("three/worker.js",t).href,gB("three/worker.js"),"three/worker.js").then(r=>r.text())),n.catch(()=>{n=null}),await n)}let TWe=null;function iwr(t){TWe=t}async function JVt(t){if(TWe===null)throw new Error("The shared library is not available here.");const n=await mTe(new URL(t,TWe).href,gB(t),t);return new Uint8Array(await n.arrayBuffer())}const awr=(t,n)=>JVt(mXe(t,n)),swr=t=>JVt(g$t(t)),kWe={".png":"image/png",".jpg":"image/jpeg",".jpeg":"image/jpeg",".gif":"image/gif",".webp":"image/webp"};function M1(t){if(t===void 0)return null;try{const n=JSON.parse(new TextDecoder().decode(t));return typeof n=="object"&&n!==null&&!Array.isArray(n)?n:null}catch{return null}}const tOt=t=>new TextEncoder().encode(JSON.stringify(t,null,2)+`
|
|
32668
32668
|
`);function QVt(t){const n=t.lastIndexOf(".");return n===-1?"":t.slice(n).toLowerCase()}function nOt(t,n){let r="";for(let a=0;a<n.length;a+=32768)r+=String.fromCharCode(...n.subarray(a,a+32768));return`data:${kWe[QVt(t)]??"image/png"};base64,${btoa(r)}`}function x3(t){return Array.isArray(t)?t.length===0?0:(Math.min(...t)+Math.max(...t))/2:typeof t=="number"?t:0}function owr(t){var n,r,a,s,l,f,m;return{title:((n=t.display)==null?void 0:n.title)??"",description:((r=t.display)==null?void 0:r.description)??"",thumbnailPath:((a=t.display)==null?void 0:a.navmapThumbnail)??null,contactName:((s=t.contact)==null?void 0:s.name)??"",contactEmail:((l=t.contact)==null?void 0:l.email)??"",parcels:Array.isArray((f=t.scene)==null?void 0:f.parcels)?[...t.scene.parcels]:[],base:((m=t.scene)==null?void 0:m.base)??"",spawnPoints:(t.spawnPoints??[]).map((_,x)=>{var T,C,N;return{name:_.name??`Spawn Point ${x+1}`,default:_.default===!0,position:{x:x3((T=_.position)==null?void 0:T.x),y:x3((C=_.position)==null?void 0:C.y),z:x3((N=_.position)==null?void 0:N.z)},..._.cameraTarget!==void 0?{cameraTarget:{x:x3(_.cameraTarget.x),y:x3(_.cameraTarget.y),z:x3(_.cameraTarget.z)}}:{}}})}}const YVt=/^-?\d+,-?\d+$/;function cwr(t){if(t.title.trim()==="")return"The scene needs a name";if(t.parcels.length===0)return"The scene needs at least one parcel";const n=t.parcels.find(r=>!YVt.test(r));if(n!==void 0)return`"${n}" is not a valid parcel — use "x,y"`;if(new Set(t.parcels).size!==t.parcels.length)return"Duplicate parcels";if(!t.parcels.includes(t.base))return"The base parcel must be one of the scene’s parcels";for(const r of t.spawnPoints){if(r.name.trim()==="")return"Every spawn point needs a name";for(const a of[r.position.x,r.position.y,r.position.z])if(!Number.isFinite(a))return`Spawn point "${r.name}" has an invalid position`;if(r.cameraTarget!==void 0){for(const a of[r.cameraTarget.x,r.cameraTarget.y,r.cameraTarget.z])if(!Number.isFinite(a))return`Spawn point "${r.name}" has an invalid camera target`}}return null}function lwr(t,n){const r=n.spawnPoints.map(a=>({name:a.name.trim(),default:a.default,position:{x:a.position.x,y:a.position.y,z:a.position.z},...a.cameraTarget!==void 0?{cameraTarget:{...a.cameraTarget}}:{}}));return{...t,display:{...t.display??{},title:n.title.trim(),description:n.description.trim(),...n.thumbnailPath!==null?{navmapThumbnail:n.thumbnailPath}:{}},contact:{...t.contact??{},name:n.contactName.trim(),email:n.contactEmail.trim()},scene:{...t.scene??{},parcels:[...n.parcels],base:n.base},spawnPoints:r}}function uwr(t){var m,_,x;const[n,r]=(((m=t.scene)==null?void 0:m.base)??"0,0").split(",").map(T=>parseInt(T,10));if(!Number.isFinite(n)||!Number.isFinite(r))return"";const a=((_=t.spawnPoints)==null?void 0:_.find(T=>T.default))??((x=t.spawnPoints)==null?void 0:x[0]);if((a==null?void 0:a.position)===void 0)return`${n*16+8},0,${r*16+8}`;const{x:s,y:l,z:f}=a.position;return`${n*16+x3(s)},${x3(l)},${r*16+x3(f)}`}const dwr=["assets/scene/main.composite","main.composite","assets/main.composite"];function fwr(t){let n;try{n=JSON.parse(t)}catch{return[]}const r=new Set;for(const a of n.components??[])if((a==null?void 0:a.name)!=="composite::root")for(const s of Object.keys((a==null?void 0:a.data)??{})){const l=Number(s);Number.isFinite(l)&&l>0&&r.add(l)}return[...r].sort((a,s)=>a-s)}const rOt=["ALLOW_TO_MOVE_PLAYER_INSIDE_SCENE","ALLOW_TO_TRIGGER_AVATAR_EMOTE","OPEN_EXTERNAL_LINK","USE_WEB3_API","USE_FETCH","USE_WEBSOCKET"],iOt=100;function pwr(t){const n=new Set(t),r=new Set([t[0]]),a=[t[0]];for(;a.length>0;){const[s,l]=a.pop().split(",").map(Number);for(const f of[`${s+1},${l}`,`${s-1},${l}`,`${s},${l+1}`,`${s},${l-1}`])n.has(f)&&!r.has(f)&&(r.add(f),a.push(f))}return r.size===n.size}function aOt(t){if(typeof t!="object"||t===null)return null;const{x:n,y:r,z:a}=t;return[n,r,a].every(s=>typeof s=="number"&&Number.isFinite(s))?{x:n,y:r,z:a}:null}function mwr(t,n){const r={...t};if(n.thumbnailPath!==void 0){if(typeof n.thumbnailPath!="string"||!/^assets\/images\/[\w-]+\.(jpg|png)$/.test(n.thumbnailPath))throw new Error("thumbnailPath must be an image under assets/images/");r.display={...t.display??{},navmapThumbnail:n.thumbnailPath}}if(n.permissions!==void 0){if(!Array.isArray(n.permissions)||n.permissions.some(s=>typeof s!="string"||!rOt.includes(s)))throw new Error(`permissions must be some of: ${rOt.join(", ")}`);const a=Array.isArray(t.requiredPermissions)?t.requiredPermissions.filter(s=>typeof s=="string"):[];r.requiredPermissions=[...new Set([...a,...n.permissions])]}if(n.parcels!==void 0||n.base!==void 0){const a=t.scene??{},s=n.parcels??a.parcels;if(!Array.isArray(s)||s.length===0||s.length>iOt||s.some(m=>typeof m!="string"||!YVt.test(m)))throw new Error(`parcels must be a list of 1–${iOt} "x,y" coordinates`);const l=s.map(m=>m.split(",").map(Number).join(","));if(new Set(l).size!==l.length)throw new Error("parcels has duplicates");if(!pwr(l))throw new Error("parcels must form one connected area: each one shares an edge with another");const f=n.base??(typeof a.base=="string"&&l.includes(a.base)?a.base:l[0]);if(typeof f!="string"||!l.includes(f))throw new Error("base must be one of the parcels");r.scene={...a,parcels:l,base:f}}if(n.spawnPoints!==void 0){if(!Array.isArray(n.spawnPoints)||n.spawnPoints.length>16)throw new Error("spawnPoints must be a list of up to 16 points");r.spawnPoints=n.spawnPoints.map((a,s)=>{const l=typeof a=="object"&&a!==null?a:{},f=aOt(l.position);if(f===null)throw new Error(`spawn point ${s+1} needs a position {x,y,z} in scene metres`);const m=l.cameraTarget===void 0?void 0:aOt(l.cameraTarget);if(m===null)throw new Error(`spawn point ${s+1} has an invalid cameraTarget`);return{name:typeof l.name=="string"&&l.name.trim()!==""?l.name.trim().slice(0,100):`Spawn Point ${s+1}`,default:l.default===!0||s===0&&!n.spawnPoints.some(_=>(_==null?void 0:_.default)===!0),position:f,...m!==void 0?{cameraTarget:m}:{}}})}return r}const hwr=new Set(["@dcl/sdk","@dcl/ecs","@dcl/ecs-math","@dcl/js-runtime","@dcl/react-ecs","@dcl/asset-packs","react","react-reconciler","scheduler","protobufjs","long","text-encoding"]),_wr=/^(@dcl\/sdk-commands|typescript|eslint|prettier)$|^@types\/|^eslint-|^@typescript-eslint\//;function XVt(t){const n=M1(t),r={};for(const a of[n==null?void 0:n.dependencies,n==null?void 0:n.devDependencies])if(!(typeof a!="object"||a===null))for(const[s,l]of Object.entries(a))typeof l=="string"&&!hwr.has(s)&&!_wr.test(s)&&(r[s]=l);return r}class KH extends Error{constructor(n,r,a=!1,s){super(r),this.reason=n,this.retryable=a,this.detail=s,this.name="PublishError"}}const sOt=t=>{const n=t/1048576;return`${n>=10?Math.round(n):Math.round(n*10)/10} MB`},oOt="Could not reach Decentraland's world server. Check your connection and try again.";function gwr(t){try{const n=JSON.parse(t);if(typeof n=="object"&&n!==null){const{message:r,error:a}=n;if(typeof r=="string"&&r!=="")return r;if(typeof a=="string")return a}}catch{}return t.trim().slice(0,500)}function ywr(t,n,r){const a=gwr(n).replace(/^(Deployment failed: )+/,""),s=(_,x,T=!1)=>new KH(_,x,T,`${t} ${a}`);if(t===409)return s("changed",`${r} changed while this scene was being published. Nothing was replaced. Publish again.`,!0);if(t===413||/multipart request is too large/i.test(a))return s("too-large","This scene is too large to upload: a publish takes 350 MB at most. Remove or shrink its largest files.");if(t===408)return s("busy","The upload took too long and was stopped. Try again on a faster connection.",!0);if(t===429||t===503)return s("busy","Decentraland's world server is busy. Try again in a minute.",!0);if(t>=500)return s("busy",`Decentraland's world server had a problem (${t}). Try again in a minute.`,!0);if(/no permission to publish|does not have permission to deploy/i.test(a))return s("permission",`This wallet can't publish to ${r}. Publish to a NAME you own, or ask the owner of ${r} to add your wallet to its deployment list.`);if(/name deny list/i.test(a))return s("permission",`${r} can't be published to: the name is on Decentraland's deny list.`);const l=/maximum total size allowed is (\d+) bytes.*tried to upload (\d+)/i.exec(a);if(l!==null)return s("too-large",`This scene is ${sOt(Number(l[2]))} and ${r} has room for ${sOt(Number(l[1]))}. Remove or shrink files (models, textures, sounds), or free space in your other worlds.`);const f=/maximum allowed is (\d+) but the deployment has (\d+)/i.exec(a);if(f!==null)return s("too-large",`This scene has ${f[2]} files and a world takes ${f[1]} at most.`);const m=/Max allowed scene dimensions is (\d+) parcels/i.exec(a);return m!==null?s("too-large",`This scene covers more parcels than ${r} allows (${m[1]}). Use fewer parcels in Scene settings.`):/secs ago/i.test(a)?s("expired","The confirmation took more than five minutes, so the signature expired. Publish again.",!0):/in the future/i.test(a)?s("expired","This device's clock is ahead of the server's. Check the date and time, then publish again."):/Invalid entity hash|doesn't match the provided content|Extra file detected|neither present in the storage|Only CIDv1/i.test(a)?s("refused","The upload did not arrive intact. Publish again.",!0):/ephemeral|signature|auth ?chain|signer/i.test(a)?s("not-signed-in","Decentraland could not verify your signature. Sign in again, then publish again."):/thumbnail/i.test(a)?s("invalid-scene","The scene thumbnail is not one of the published files. Choose it again in Scene settings."):/worldConfiguration|scene\.json|pointers|parcel|must have required property|must be|is not present in the entity/i.test(a)?s("invalid-scene",`Decentraland did not accept this scene's settings: ${a}`):s("refused",`Decentraland refused this scene: ${a===""?`status ${t}`:a}`)}const vwr=5e7,cOt=1e4,bwr=/^-?\d+,-?\d+$/,dk=t=>new KH("invalid-scene",t);function xwr(t,n){const r=new Map([...t,...n]),a=t.get(".dclignore"),s=$Xe(r.keys(),a===void 0?void 0:new TextDecoder().decode(a)),l=new Map;for(const f of s.sort()){const m=r.get(f);m!==void 0&&f!==I3&&l.set(f,m)}return l}function wwr(t){const n=new Set(t),r=[t[0]];n.delete(t[0]);for(let a=r.shift();a!==void 0;a=r.shift()){const[s,l]=a.split(",").map(Number);for(const f of[`${s+1},${l}`,`${s-1},${l}`,`${s},${l+1}`,`${s},${l-1}`])n.delete(f)&&r.push(f)}return n.size===0}function Swr(t,n){var m,_,x;const r=(m=t.scene)==null?void 0:m.parcels,a=(_=t.scene)==null?void 0:_.base;if(!Array.isArray(r)||r.length===0||typeof a!="string")throw dk("This scene has no parcels. Set them in Scene settings.");if(r.some(T=>typeof T!="string"||!bwr.test(T)))throw dk('A parcel of this scene is not written as "x,y". Fix it in Scene settings.');if(new Set(r).size!==r.length)throw dk("A parcel is listed twice in this scene. Fix it in Scene settings.");if(!r.includes(a))throw dk(`The base parcel ${a} is not one of the scene's parcels. Fix it in Scene settings.`);if(!wwr(r))throw dk("The scene's parcels are not next to each other. Fix them in Scene settings.");const s=t.main;if(typeof s!="string"||!s.endsWith(".js"))throw dk('scene.json has no "main" script to run.');if(!n.has(s))throw dk(`The build did not produce ${s}, the script scene.json names.`);const l=(x=t.display)==null?void 0:x.navmapThumbnail;if(typeof l=="string"&&l!==""&&!n.has(l))throw dk(`The scene thumbnail “${l}” is not one of the files being published. Choose it again in Scene settings.`);const f=new Map;for(const[T,C]of n){const N=f.get(T.toLowerCase());if(N!==void 0)throw dk(`“${N}” and “${T}” differ only in capitals. A scene cannot hold both: rename one.`);if(f.set(T.toLowerCase(),T),C.length>vwr)throw dk(`“${T}” is larger than 50 MB, the most one file of a scene can be.`)}return r}async function Twr(t){var N,F,B;const n=M1(t.files.get("scene.json"));if(n===null)throw dk("scene.json is missing or is not valid JSON.");if(((N=n.worldConfiguration)==null?void 0:N.name)!==t.world)throw dk(`scene.json does not name ${t.world} as its world.`);const r=xwr(t.files,t.outputs),a=Swr(n,r),{sdkVersion:s,...l}=n,f=new Map,m=[];for(const[H,Z]of r){const K=await Axe(Z);m.push({file:H,hash:K}),f.set(K,Z)}if(m.length>cOt)throw dk(`This scene has ${m.length.toLocaleString("en")} files and a World takes at most ${cOt.toLocaleString("en")}. Delete files it does not use in Assets.`);let _=0;for(const H of f.values())_+=H.length;const x={version:"v3",type:"scene",pointers:a,timestamp:t.timestamp,content:m,metadata:{sdkVersion:t.sdkVersion,...l}},T=new TextEncoder().encode(JSON.stringify(x)),C=await Axe(T);return f.set(C,T),{entityId:C,entity:x,files:f,title:((B=(F=n.display)==null?void 0:F.title)==null?void 0:B.trim())||t.world,fileCount:m.length,bytes:_}}const lOt=100,kwr=3,Ewr=1500,EWe=t=>t instanceof Error&&t.name==="AbortError",uOt=()=>new KH("cancelled","Publishing was cancelled.");function Cwr(t,n,r){const a=new FormData;a.append("entityId",t),n.forEach((s,l)=>{a.append(`authChain[${l}][type]`,s.type),a.append(`authChain[${l}][payload]`,s.payload),a.append(`authChain[${l}][signature]`,s.signature)});for(const[s,l]of r)a.append(s,new Blob([l]),s);return a}async function Awr(t,n,r){const a=new Set;try{for(let s=0;s<n.length;s+=lOt){const l=n.slice(s,s+lOt).map(_=>`cid=${_}`).join("&"),f=await fetch(`${t}/available-content?${l}`,{signal:r});if(!f.ok)return new Set;const m=await f.json();if(!Array.isArray(m))return new Set;for(const _ of m)typeof _.cid=="string"&&_.available===!0&&a.add(_.cid)}}catch(s){if(EWe(s))throw s;return new Set}return a}function Owr(t,n){if(!Array.isArray(t)||t.length<2)return!1;const r=t;return r.every(a=>typeof(a==null?void 0:a.type)=="string"&&typeof a.payload=="string"&&typeof a.signature=="string")?r[0].type==="SIGNER"&&r[r.length-1].payload===n:!1}async function Pwr(t){var s,l;const{deployment:n,server:r,signal:a}=t;try{const f=[...n.files],m=await Awr(r,[...n.files.keys()],a);let _=f.filter(([N])=>N===n.entityId||!m.has(N));const x=_.reduce((N,[,F])=>N+F.length,0),T=`${Math.ceil(x/1024)} KB`;(s=t.onProgress)==null||s.call(t,_.length===f.length?`Uploading ${f.length-1} files (${T}).`:`Uploading ${_.length-1} of ${f.length-1} files (${T}): the server already has the others.`);let C=new KH("network",oOt,!0);for(let N=1;N<=kwr;N++){if(N>1&&((l=t.onRetry)==null||l.call(t,N,C.detail??C.message),await new Promise(H=>setTimeout(H,Ewr*(N-1))),(a==null?void 0:a.aborted)===!0))throw uOt();let F;try{F=await fetch(`${r}/entities`,{method:"POST",body:Cwr(n.entityId,t.authChain,_),signal:a})}catch(H){if(EWe(H))throw H;C=new KH("network",oOt,!0,H instanceof Error?H.message:String(H));continue}const B=await F.text();if(F.ok)try{const H=JSON.parse(B).message;return typeof H=="string"?H:""}catch{return""}if(C=ywr(F.status,B,t.world),_.length<f.length&&/neither present in the storage/.test(C.detail??"")){_=f;continue}if(F.status<500&&F.status!==408&&F.status!==429)throw C}throw C}catch(f){throw EWe(f)?uOt():f}}const Lq=100,ZVt=20;function KVt(t){const n=new URL(t).hostname;return n.endsWith(".decentraland.org")?"https://peer.decentraland.org/lambdas":n.endsWith(".decentraland.zone")?"https://peer.decentraland.zone/lambdas":null}function Iwr(t,n){return KVt(t)===null?`${t}/world/${n}`:n}async function Nwr(t,n){const r=[];for(let a=1;a<=ZVt;a++){const s=await fetch(`${t}/users/${n}/names?pageSize=${Lq}&pageNum=${a}`);if(!s.ok)throw new Error(`could not list your NAMEs (${s.status})`);const l=await s.json(),f=Array.isArray(l.elements)?l.elements:[];for(const{name:m}of f)typeof m=="string"&&m!==""&&r.push(`${m.toLowerCase()}.dcl.eth`);if(f.length<Lq||typeof l.totalAmount=="number"&&r.length>=l.totalAmount)break}return r}async function Dwr(t,n){const r=[];for(let a=0;a<ZVt;a++){const s=await fetch(`${t}/worlds?authorized_deployer=${n}&limit=${Lq}&offset=${a*Lq}`);if(!s.ok)throw new Error(`could not list the worlds you can publish to (${s.status})`);const l=await s.json(),f=Array.isArray(l.worlds)?l.worlds:[];for(const m of f){if(typeof m.name!="string")continue;const _=typeof m.owner=="string"&&m.owner.toLowerCase()===n;r.push({name:m.name.toLowerCase(),role:_?"owner":"collaborator"})}if(f.length<Lq||typeof l.total=="number"&&(a+1)*Lq>=l.total)break}return r}async function Rwr(t,n){const r=t.toLowerCase(),a=KVt(n),[s,l]=await Promise.all([a===null?[]:Nwr(a,r),Dwr(n,r).catch(m=>{if(a===null)throw m;return[]})]),f=new Map;for(const m of l)f.set(m.name,m);for(const m of s)f.set(m,{name:m,role:"owner"});return[...f.values()].sort((m,_)=>m.name.localeCompare(_.name))}const dOt=t=>t instanceof Error?t.message:String(t),Mwr=t=>t<1024*1024?`${Math.ceil(t/1024)} KB`:`${(t/1024/1024).toFixed(1)} MB`,wve={ok:!1,reason:"cancelled",message:"Publishing was cancelled.",retryable:!0},fOt={ok:!1,reason:"not-signed-in",message:"Sign in to publish",retryable:!1},$W=(t,n)=>({ok:!1,reason:"failed",message:t,retryable:n});class Lwr{constructor(){this.code="unexpected"}set(n){return this.code=n.replace(/-/g,"_"),this}}function Fwr(t){const{host:n}=t,r=n.services.worldsContent.replace(/\/+$/,"");let a=null;function s(f){var _;const m=(_=f.entity.metadata.scene)==null?void 0:_.base;return typeof m=="string"?`&position=${encodeURIComponent(m)}`:""}async function l(f,m,_,x,T){const{address:C,isGuest:N}=n.identity();if(N||C===null)return fOt;await t.setWorld(f,m),_({step:"building",line:"Building the scene for publishing…"});const F=await t.files(f),B=await t.build(f,F);if(x.aborted)return wve;if(!B.ok){for(const fe of B.diagnostics.filter(X=>X.severity==="error"))_({step:"building",line:fe.file===void 0?`ERROR: ${fe.message}`:`${fe.file}:${fe.line??1}:${fe.column??0}: ERROR: ${fe.message}`});const pe=B.events.find(fe=>fe.type==="failed");return(pe==null?void 0:pe.type)==="failed"&&B.diagnostics.length===0&&_({step:"building",line:pe.message}),T.set("build"),$W("The build failed.",!1)}const H=await Twr({files:F,outputs:B.outputs,world:m,sdkVersion:B.sdkVersion,timestamp:Date.now()});_({step:"signing",line:`Waiting for your confirmation: ${H.fileCount} files, ${Mwr(H.bytes)}, as ${H.entityId}`});let Z;try{Z=await n.signDeployment({world:m,entityId:H.entityId,title:H.title,fileCount:H.fileCount,bytes:H.bytes})}catch(pe){const fe=dOt(pe);return fe==="cancelled"?wve:fe==="not-signed-in"?fOt:(T.set("sign_failed"),$W(`Decentraland could not sign this publish: ${fe}`,!0))}if(x.aborted)return wve;if(!Owr(Z,H.entityId))return T.set("no_signature"),$W("Decentraland did not return a signature for this scene.",!0);_({step:"uploading",line:`Uploading to ${m} (${r})…`});const K=await Pwr({server:r,world:m,deployment:H,authChain:Z,signal:x,onProgress:pe=>_({step:"uploading",line:pe}),onRetry:(pe,fe)=>_({step:"uploading",line:`Trying again (${pe} of 3): ${fe}`})});K!==""&&_({step:"uploading",line:K});const te={world:m,entityId:H.entityId,url:`${n.pageDir}?realm=${encodeURIComponent(Iwr(r,m))}${s(H)}`,files:H.fileCount,bytes:H.bytes,at:Date.now()};return await t.published(f,te).catch(pe=>console.warn("[editor] could not record the publish",pe)),{ok:!0,published:te}}return{async publish(f,m,_){if(a!==null)return $W("A scene is already being published.",!1);const x=new AbortController;a=x;const T=new Lwr,C=await l(f,m,_,x.signal,T).catch(N=>N instanceof KH?N.reason==="cancelled"?wve:(N.detail!==void 0&&_({step:"uploading",line:`The server answered: ${N.detail}`}),T.set(N.reason),$W(N.message,N.retryable)):$W(dOt(N),!0)).finally(()=>{a=null});return C.ok?Xx("scene_published",{project_id:f,world:m,files:C.published.files,bytes:C.published.bytes}):Xx("publish_failed",{project_id:f,world:m,error:C.reason==="failed"?T.code:C.reason.replace(/-/g,"_"),retryable:C.retryable}),C},stop(){a==null||a.abort()}}}function jwr(){return{root:()=>navigator.storage.getDirectory(),locks:{request:(t,n,r)=>navigator.locks.request(t,n,r)}}}function pI(t){return t instanceof Error&&t.name==="NotFoundError"}const pOt=t=>encodeURIComponent(t);function mOt(t){const n=t.split("/");if(t===""||n.some(r=>r===""||r==="."||r===".."))throw new Error(`Invalid package path "${t}"`);return n}async function*eWt(t,n=""){for await(const[r,a]of t.entries())a.kind==="file"?yield n+r:yield*eWt(await t.getDirectoryHandle(r),`${n}${r}/`)}const Sve=(t,n)=>{if(pI(t))return n;throw t};class Bwr{constructor(n){this.root=n}async dir(n,r=!1){return(await this.root()).getDirectoryHandle(pOt(n),{create:r})}async has(n){return this.dir(n).then(()=>!0,r=>Sve(r,!1))}async list(n){try{const r=[];for await(const a of eWt(await this.dir(n)))r.push(a);return r}catch(r){return Sve(r,[])}}async read(n,r){try{const a=mOt(r);let s=await this.dir(n);for(const f of a.slice(0,-1))s=await s.getDirectoryHandle(f);const l=await s.getFileHandle(a[a.length-1]);return new Uint8Array(await(await l.getFile()).arrayBuffer())}catch(a){return Sve(a,void 0)}}async write(n,r,a){const s=mOt(r);let l=await this.dir(n,!0);for(const m of s.slice(0,-1))l=await l.getDirectoryHandle(m,{create:!0});const f=await(await l.getFileHandle(s[s.length-1],{create:!0})).createWritable();await f.write(a),await f.close()}async remove(n){await(await this.root()).removeEntry(pOt(n),{recursive:!0}).catch(r=>Sve(r,void 0))}async keys(){const n=[];for await(const[r,a]of(await this.root()).entries())a.kind==="directory"&&n.push(decodeURIComponent(r));return n}}class Nxe extends Error{constructor(n){super(`"${n}" is open in another tab`),this.name="ProjectBusyError"}}const Uwr="dcl-editor",hOt="index.json",$wr="dcl-editor-index",_Ot=t=>`dcl-editor-project:${t}`,tWt=/[\u200e\u200f\u202a-\u202e\u2066-\u2069]/;function CWe(t){if(t===""||/[\\\0]/.test(t))return null;const n=t.split("/");return n.some(r=>r===""||r==="."||r==="..")?null:n}function eJ(t){const n=CWe(t);return n===null||tWt.test(t)||n[0]==="bin"?!1:!n.some(r=>{const a=r.toLowerCase();return a==="node_modules"||a===".git"||a.startsWith(".env")})}function zwr(t){return t.trim().toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"").slice(0,48).replace(/-$/,"")||"my-scene"}function gOt(){return Array.from(crypto.getRandomValues(new Uint8Array(4)),t=>(t%36).toString(36)).join("")}async function Tve(t){return new Uint8Array(await(await t.getFile()).arrayBuffer())}async function KBe(t,n){const r=await t.createWritable();await r.write(n),await r.close()}async function*AWe(t,n=""){for await(const[r,a]of t.entries())a.kind==="file"?yield[n+r,await t.getFileHandle(r)]:yield*AWe(await t.getDirectoryHandle(r),`${n}${r}/`)}function Vwr(t){return typeof t=="object"&&t!==null&&Array.isArray(t.projects)}class Wwr{constructor(n){this.backend=n,this.held=new Map,this.queue=Promise.resolve(),this.packages=new Bwr(async()=>(await this.base()).getDirectoryHandle("packages",{create:!0}))}async base(){return(await this.backend.root()).getDirectoryHandle(Uwr,{create:!0})}async projects(){return(await this.base()).getDirectoryHandle("projects",{create:!0})}async dir(n,r=!1){if(!jXe.test(n))throw new Error(`Invalid project id "${n}"`);return(await this.projects()).getDirectoryHandle(n,{create:r})}async records(){let n;try{n=await(await this.base()).getFileHandle(hOt)}catch(s){if(pI(s))return[];throw s}const r=await Tve(n);if(r.length===0)return[];const a=JSON.parse(new TextDecoder().decode(r));if(!Vwr(a))throw new Error("The project index is not readable");return a.projects}mutate(n){return this.backend.locks.request($wr,{},async()=>{const r=await this.records(),a=await n(r),s=await(await this.base()).getFileHandle(hOt,{create:!0});return await KBe(s,new TextEncoder().encode(JSON.stringify({version:1,projects:r}))),a})}serial(n){const r=this.queue.then(n,n);return this.queue=r.catch(()=>{}),r}locked(n,r){return this.held.has(n)?r():this.serial(()=>this.backend.locks.request(_Ot(n),{ifAvailable:!0},async a=>{if(a===null)throw new Nxe(n);return r()}))}async put(n,r,a){const s=CWe(r)??[];let l=n;for(const f of s.slice(0,-1))l=await l.getDirectoryHandle(f,{create:!0});await KBe(await l.getFileHandle(s[s.length-1],{create:!0}),a)}async file(n,r){const a=CWe(r);if(a===null)throw new Error(`Invalid project path "${r}"`);let s=await this.dir(n);for(const l of a.slice(0,-1))s=await s.getDirectoryHandle(l);return{folder:s,name:a[a.length-1]}}async list(){return(await this.records()).filter(n=>n.deletedAt===null)}async trashed(){return(await this.records()).filter(n=>n.deletedAt!==null)}create(n,r,a={}){return this.mutate(async s=>{const l=new Set([...s.map(C=>C.id),...a.taken??[]]),f=zwr(n);let m=a.id??`${f}-${gOt()}`;if(a.id!==void 0&&s.some(C=>C.id===m))throw new Error(`"${m}" already exists`);for(;a.id===void 0&&l.has(m);)m=`${f}-${gOt()}`;await this.writeJson("sync",m,null),await(await this.projects()).removeEntry(m,{recursive:!0}).catch(C=>{if(!pI(C))throw C});const _=await this.dir(m,!0);for(const[C,N]of r)eJ(C)&&await this.put(_,C,N);const x=Date.now(),T={id:m,name:n.trim(),createdAt:x,lastOpened:x,favourite:!1,deletedAt:null};return s.push(T),T})}async duplicate(n,r,a){return this.create(r,await this.readAll(n),{taken:a})}async writeJson(n,r,a){const s=await(await this.base()).getDirectoryHandle(n,{create:!0});if(a!==null){await KBe(await s.getFileHandle(`${r}.json`,{create:!0}),new TextEncoder().encode(JSON.stringify(a)));return}await s.removeEntry(`${r}.json`).catch(l=>{if(!pI(l))throw l})}async readJson(n,r){try{const a=await(await this.base()).getDirectoryHandle(n);return JSON.parse(new TextDecoder().decode(await Tve(await a.getFileHandle(`${r}.json`))))}catch(a){if(pI(a)||a instanceof SyntaxError)return null;throw a}}syncRecord(n){return this.readJson("sync",n)}transcript(n,r){return this.readJson("assistant",`${n}@${r.toLowerCase()}`)}setTranscript(n,r,a){return this.writeJson("assistant",`${n}@${r.toLowerCase()}`,a)}assistantMemory(n,r){return this.readJson("assistant",`${n}@${r.toLowerCase()}.memory`)}setAssistantMemory(n,r,a){return this.writeJson("assistant",`${n}@${r.toLowerCase()}.memory`,a)}async removeTranscripts(n){let r;try{r=await(await this.base()).getDirectoryHandle("assistant")}catch(s){if(pI(s))return;throw s}const a=[];for await(const[s]of r.entries())s.startsWith(`${n}@`)&&a.push(s);for(const s of a)await r.removeEntry(s)}setSyncRecord(n,r){return this.writeJson("sync",n,r)}patch(n,r){return this.mutate(a=>{const s=a.find(l=>l.id===n);s!==void 0&&Object.assign(s,r)})}async trash(n){if(this.held.has(n))return!1;try{return await this.locked(n,()=>this.mutate(r=>{const a=r.find(s=>s.id===n&&s.deletedAt===null);return a===void 0?!1:(a.deletedAt=Date.now(),a.favourite=!1,!0)}))}catch(r){if(r instanceof Nxe)return!1;throw r}}restore(n){return this.mutate(r=>{const a=r.find(s=>s.id===n&&s.deletedAt!==null);return a===void 0?!1:(a.deletedAt=null,!0)})}purge(n){return this.mutate(async r=>{const a=r.filter(s=>s.deletedAt!==null&&s.deletedAt<n);for(const{id:s}of a)await(await this.projects()).removeEntry(s,{recursive:!0}).catch(l=>{if(!pI(l))throw l}),await this.writeJson("sync",s,null),await this.removeTranscripts(s),r.splice(r.findIndex(l=>l.id===s),1);return a.map(({id:s,previewId:l})=>({id:s,previewId:l}))})}open(n){return this.held.has(n)?Promise.resolve(!0):this.serial(()=>new Promise((r,a)=>{this.backend.locks.request(_Ot(n),{ifAvailable:!0},s=>s===null?(r(!1),Promise.resolve()):new Promise(l=>{this.held.set(n,l),r(!0)})).catch(a)}))}close(n){var r;(r=this.held.get(n))==null||r(),this.held.delete(n)}holds(n){return this.held.has(n)}async read(n,r){const{folder:a,name:s}=await this.file(n,r);return Tve(await a.getFileHandle(s))}async paths(n){const r=[];for await(const[a]of AWe(await this.dir(n)))r.push(a);return r.sort()}async readAll(n){const r=new Map;for await(const[a,s]of AWe(await this.dir(n)))r.set(a,await Tve(s));return r}write(n,r,a){return eJ(r)?this.locked(n,async()=>this.put(await this.dir(n),r,a)):Promise.reject(new Error(`"${r}" is not kept in a project`))}remove(n,r){return this.locked(n,async()=>{try{const{folder:a,name:s}=await this.file(n,r);return await a.removeEntry(s),!0}catch(a){if(pI(a))return!1;throw a}})}}class zXe extends Error{constructor(n){super("The scene was changed on another device"),this.version=n,this.name="SyncConflictError"}}class iae extends Error{constructor(){super("The scene is in the trash on your account"),this.name="SyncDeletedError"}}class YA extends Error{constructor(n,r,a){super(a),this.status=n,this.code=r,this.name="SyncHttpError"}}function kve(t){return t instanceof YA?t.code==="missing-blobs"?"missing-content":t.status>=500||t.status===408||t.status===429?"retry":"rejected":t instanceof zXe||t instanceof iae?"rejected":t instanceof Error&&t.message==="not-signed-in"?"signed-out":"retry"}const OWe=t=>typeof t=="number"?`${Math.round(t/(1024*1024))} MB`:"the limit";function qwr(t,n,r){switch(n){case"quota-exceeded":return`Your account's scene storage is full (${OWe(r.limit)}). A scene in the trash frees its space 30 days after it was trashed. This one stays on this device.`;case"file-too-large":return`A file in this scene is larger than the ${OWe(r.limit)} an account stores per file. The scene stays on this device.`;case"too-many-files":return`This scene has more files than an account stores (${String(r.limit)}). It stays on this device.`;case"too-many-projects":return`Your account already holds ${String(r.limit)} scenes, counting the ones in its trash, which stop counting 30 days after they were trashed. This one stays on this device.`;case"invalid-path":return`"${String(r.path)}" cannot be stored on your account. The scene stays on this device.`;case"origin-not-allowed":return"Scene sync is not available from this address."}return t===401||t===403?"Your account did not accept this sign-in. Sign in again to sync your scenes.":n===""?`The project service answered ${t}`:`The project service answered ${t} (${n})`}async function U0e(t){const n=await t.json().catch(()=>null),r=typeof n=="object"&&n!==null?n:{},a=typeof r.error=="string"?r.error:"";return new YA(t.status,a,qwr(t.status,a,r))}function nWt(t,n,r=(a,s)=>fetch(a,s)){const a={"content-type":"application/json"};async function s(m,_){const x=await n(t+m,_);if(x.ok)return x;const T=await U0e(x);throw T.code==="deleted"?new iae:T}const l=m=>m instanceof YA&&m.status===404;let f=null;return{async list(){const m=await(await s("/projects")).json(),{bytes:_,limit:x}=m.usage??{};return f=typeof _=="number"&&typeof x=="number"?{bytes:_,limit:x}:null,Array.isArray(m.projects)?m.projects:[]},usage:()=>f,async manifest(m){try{return await(await s(`/projects/${m}/manifest`)).json()}catch(_){if(l(_))return null;throw _}},async uploads(m,_){if(_.length===0)return[];const T=await(await s(`/projects/${m}/uploads`,{method:"POST",headers:a,body:JSON.stringify({files:_})})).json();return Array.isArray(T.uploads)?T.uploads:[]},async putBlob(m,_){const x=await r(m.url,{method:m.method,headers:m.headers,body:_});if(!x.ok)throw await U0e(x)},async putManifest(m,_){const x=await n(`${t}/projects/${m}/manifest`,{method:"PUT",headers:a,body:JSON.stringify(_)});if(x.status===409||x.status===412){const C=await x.json().catch(()=>({}));throw C.error==="deleted"?new iae:new zXe(C.version??null)}if(!x.ok)throw await U0e(x);const{version:T}=await x.json().catch(()=>({}));if(typeof T!="number")throw new YA(502,"","The project service did not say which version it saved");return T},async blob(m,_){return new Uint8Array(await(await s(`/projects/${m}/files/${_}`)).arrayBuffer())},async remove(m){await s(`/projects/${m}`,{method:"DELETE"}).catch(_=>{if(!l(_))throw _})},async restore(m){await s(`/projects/${m}/restore`,{method:"POST"})}}}class rWt extends Error{}function Gwr(t,n){return t.code==="quota-exceeded"?new YA(t.status,t.code,`Your account's storage is full (${OWe(n.limit)}). The prefab stays in this scene.`):t.code==="too-many-prefabs"?new YA(t.status,t.code,`Your library already holds ${String(n.limit)} prefabs. Remove one to add another.`):t}function Hwr(t,n,r=(a,s)=>fetch(a,s)){const a=nWt(t,n,r),s={"content-type":"application/json"};async function l(m,_){const x=await n(t+m,_);if(x.ok)return x;const T=await x.clone().json().catch(()=>({}));throw Gwr(await U0e(x),T)}const f=m=>`/prefabs/${encodeURIComponent(m)}`;return{async list(){const m=await(await l("/prefabs")).json();return Array.isArray(m.prefabs)?m.prefabs:[]},async uploads(m,_){if(_.length===0)return[];const T=await(await l(`${f(m)}/uploads`,{method:"POST",headers:s,body:JSON.stringify({files:_})})).json();return Array.isArray(T.uploads)?T.uploads:[]},putBlob:(m,_)=>a.putBlob(m,_),async put(m,_){try{await l(`${f(m)}/manifest`,{method:"PUT",headers:s,body:JSON.stringify({files:_})})}catch(x){throw x instanceof YA&&x.code==="exists"?new rWt(m):x}},async blob(m,_){return new Uint8Array(await(await l(`${f(m)}/files/${_}`)).arrayBuffer())},async remove(m){try{return await l(f(m),{method:"DELETE"}),!0}catch(_){if(_ instanceof YA&&_.status===404)return!1;throw _}}}}class PWe extends Error{}async function iWt(t,n,r){try{return await t.read(n,r)}catch(a){if(pI(a))return null;throw a}}async function Eve(t,n,r,a,s){const l={...a};for(const f of a===null?await t.paths(r):s){const m=eJ(f)?await iWt(t,r,f):null;m===null?delete l[f]:l[f]={hash:await n(m),size:m.length}}return l}function yOt(t,n){const r=Object.keys(t);return r.length===Object.keys(n).length&&r.every(a=>{var s;return((s=n[a])==null?void 0:s.hash)===t[a].hash})}async function vOt(t,n,r,a,s,l){const f=new Set(Object.values(s).map(T=>T.hash)),m=new Map;for(const[T,C]of Object.entries(a))f.has(C.hash)||m.set(C.hash,{path:T,file:C});const _=await n.uploads(r,[...m.values()].map(T=>T.file));l(0,_.length);let x=0;for(const T of _){const C=m.get(T.hash),N=C===void 0?null:await iWt(t,r,C.path);if(N===null||N.length!==(C==null?void 0:C.file.size))throw new PWe;try{await n.putBlob(T,N)}catch(F){throw F instanceof YA&&[400,403,422].includes(F.status)?new PWe:F}l(++x,_.length)}}async function bOt(t,n,r,a){const s=new Map,l=new Map;for(const[f,m]of r){const _=s.get(m.hash)??await t.blob(n,m.hash);s.set(m.hash,_),l.set(f,_),a(l.size,r.length)}return l}async function Cve(t,n){try{return await t.manifest(n)}catch(r){if(!(r instanceof iae))throw r;return await t.restore(n),t.manifest(n)}}const e9e=2e3,xOt=2e3,wOt=6e4,Jwr=4e3,Qwr=5e3,Ywr=3,SOt=["conflict","error","offline","syncing","synced","local"],TOt=t=>t instanceof Error?t.message:String(t);function kOt(t){const n=t;return typeof n=="object"&&n!==null&&typeof n.wallet=="string"&&typeof n.baseVersion=="number"&&typeof n.base=="object"&&n.base!==null&&Array.isArray(n.pending)}function Xwr(t){const{store:n}=t,r=new Map,a=new Set;let s=new Set,l=[],f=new Set,m=0,_=!1,x=null,T=null,C=0,N=0,F=null,B=null,H=0,Z=!1,K=!1;const te=new Set;function pe(){K||Z||(K=!0,queueMicrotask(()=>{if(K=!1,Z)return;const Me=Wt.status();for(const Ke of a)Ke(Me)}))}function fe(Me){const Ke=Me.then(()=>{},()=>{});return te.add(Ke),Ke.then(()=>te.delete(Ke)),Me}function X(Me){const Ke=r.get(Me);if(Ke!==void 0)return Ke;const st={loaded:Promise.resolve(),record:null,pending:new Set,busy:0,conflict:!1,behind:!1,error:null,attempt:0,moved:0,retry:null,debounce:null,chain:Promise.resolve(),saving:Promise.resolve(),agreedAt:0};return st.loaded=he(Me,st),r.set(Me,st),st}async function he(Me,Ke){try{await Ke.saving;const st=await n.syncRecord(Me);if(Ke.record=kOt(st)?{...st,remoteDeleted:st.remoteDeleted===!0}:null,kOt(st))for(const tn of st.pending)Ke.pending.add(tn)}catch(st){console.warn(`[editor] could not read the sync record of ${Me}`,st)}}function Ce(Me,Ke){const st=Ke.saving.then(()=>n.setSyncRecord(Me,Ke.record===null?null:{...Ke.record,pending:[...Ke.pending]}));return Ke.saving=st.catch(tn=>console.warn(`[editor] could not save the sync record of ${Me}`,tn)),Ke.saving}function qe(Me,Ke){const st=X(Me),tn=st.chain.then(async()=>{await st.loaded;const An=t.session();if(!(An===null||Z)&&!(st.record!==null&&st.record.wallet!==An.wallet)){st.busy++,pe();try{return await Ke(st,An)}finally{st.busy--,st.progress=void 0,pe()}}});return st.chain=tn.catch(()=>{}),fe(tn)}function wt(Me){var st;const Ke=((st=t.session())==null?void 0:st.wallet)??null;return Me.record!==null&&Me.record.wallet!==Ke}function ft(Me){Me.debounce!==null&&clearTimeout(Me.debounce),Me.retry!==null&&clearTimeout(Me.retry),Me.debounce=null,Me.retry=null}function St(Me,Ke){const st=X(Me);st.debounce!==null&&clearTimeout(st.debounce),st.debounce=setTimeout(()=>{st.debounce=null,Ve(Me)},Ke)}function gt(Me,Ke,st,tn){if(st instanceof zXe){Ke.conflict=!0;return}if(st instanceof PWe&&++Ke.moved<Ywr){St(Me,e9e);return}const An=kve(st);if(An!=="signed-out"){if(An==="retry"){_=!0,Ke.attempt++,Ke.retry!==null&&clearTimeout(Ke.retry),Ke.retry=setTimeout(()=>{Ke.retry=null,tn()},Math.min(wOt,xOt*2**(Ke.attempt-1)));return}Ke.error=TOt(st)}}function Ue(Me){_=!1,Me.error=null,Me.attempt=0,Me.moved=0,Me.retry!==null&&clearTimeout(Me.retry),Me.retry=null}const qt=(Me,Ke)=>(st,tn)=>{Me.progress={done:st,total:tn},Ke==null||Ke(st,tn),pe()};function Ve(Me){return qe(Me,async(Ke,{api:st,wallet:tn})=>{var un,Tn,fi;if(Ke.conflict||s.has(Me)||!f.has(Me)||Ke.record!==null&&Ke.pending.size===0)return;const An=[...Ke.pending];Ke.pending.clear();try{const Tt=((un=Ke.record)==null?void 0:un.base)??{},Wi=await Eve(n,t.hash,Me,((Tn=Ke.record)==null?void 0:Tn.base)??null,An);if(Ke.record===null||!yOt(Wi,Tt)){const Er={name:await t.title(Me),files:Wi,baseVersion:((fi=Ke.record)==null?void 0:fi.baseVersion)??null},lo=async zo=>(await vOt(n,st,Me,Wi,zo,qt(Ke)),st.putManifest(Me,Er)),Ba=await lo(Tt).catch(async zo=>{if(zo instanceof iae)return await st.restore(Me),lo(Tt);if(kve(zo)==="missing-content")return lo({});throw zo});Ke.record={wallet:tn,baseVersion:Ba,base:Wi,pending:[],remoteDeleted:!1},Ke.agreedAt=++H}Ue(Ke),await Ce(Me,Ke),Ke.pending.size>0&&St(Me,e9e)}catch(Tt){for(const Wi of An)Ke.pending.add(Wi);if(Tt instanceof YA&&Tt.status===404&&Ke.record!==null){Ke.record=null,await Ce(Me,Ke),St(Me,0);return}gt(Me,Ke,Tt,()=>void Ve(Me))}}).then(()=>{})}async function Re(Me,Ke,st,tn,An,un){const Tn=Object.entries(tn.files).filter(([Tt,Wi])=>{var Er;return eJ(Tt)&&((Er=An[Tt])==null?void 0:Er.hash)!==Wi.hash}),fi=await bOt(st.api,Me,Tn,qt(Ke,un));for(const[Tt,Wi]of fi)await n.write(Me,Tt,Wi);for(const Tt of Object.keys(An))tn.files[Tt]===void 0&&await n.remove(Me,Tt);Ke.record={wallet:st.wallet,baseVersion:tn.version,base:tn.files,pending:[],remoteDeleted:!1},Ke.agreedAt=++H,Ke.pending.clear(),Ke.behind=!1,Ke.conflict=!1,Ue(Ke),await Ce(Me,Ke),m++}async function $t(Me,Ke,st,tn){var un;const An=await Eve(n,t.hash,Me,((un=Ke.record)==null?void 0:un.base)??null,[...Ke.pending]);return yOt(An,tn.files)?(Ke.record={wallet:st,baseVersion:tn.version,base:tn.files,pending:[],remoteDeleted:!1},Ke.agreedAt=++H,Ke.pending.clear(),Ke.conflict=!1,Ue(Ke),await Ce(Me,Ke),!0):!1}function vt(Me,Ke){return qe(Me,async(st,tn)=>{if(!(st.record===null||st.pending.size>0||st.conflict))try{const An=Ke??await Cve(tn.api,Me);if(An===null||An.version===st.record.baseVersion){st.behind=!1;return}await Re(Me,st,tn,An,st.record.base)}catch(An){An instanceof Nxe||gt(Me,st,An,()=>void vt(Me))}}).then(()=>{})}async function xt(Me,Ke,st,tn){await qe(Me,async(un,{api:Tn,wallet:fi})=>{const Tt=un.record;try{if(Ke){if(Tt===null||st===void 0)return;st.deletedAt!=null?Tt.remoteDeleted=!0:Tt.remoteDeleted?(await n.restore(Me),Tt.remoteDeleted=!1,m++):(await Tn.remove(Me),Tt.remoteDeleted=!0),await Ce(Me,un);return}if(st===void 0){if(Tt!==null&&un.agreedAt>tn)return;Tt!==null&&(un.record=null,await Ce(Me,un)),St(Me,0);return}if(Tt===null){un.conflict=!0;return}if(st.deletedAt!=null){if(!Tt.remoteDeleted&&un.pending.size===0&&!n.holds(Me)){await n.trash(Me)&&(Tt.remoteDeleted=!0,await Ce(Me,un),m++);return}await Tn.restore(Me),Tt.remoteDeleted=!1,await Ce(Me,un)}if(st.version!==Tt.baseVersion){if(un.pending.size===0)un.behind=!0;else{const Wi=await Cve(Tn,Me);(Wi==null?void 0:Wi.version)===Tt.baseVersion?St(Me,0):(Wi===null||!await $t(Me,un,fi,Wi))&&(un.conflict=!0)}return}un.behind=!1,un.pending.size>0&&St(Me,0)}catch(Wi){gt(Me,un,Wi,()=>void Wt.refresh(!0))}}),X(Me).behind&&!n.holds(Me)&&await vt(Me)}async function ut(){var Tn;const Me=((Tn=t.session())==null?void 0:Tn.wallet)??null;if(Me!==B){B=Me,_=!1,x=null;for(const fi of r.values())ft(fi),fi.conflict=!1,fi.behind=!1,fi.error=null,fi.attempt=0}const[Ke,st]=await Promise.all([n.list(),n.trashed()]);s=new Set(st.map(fi=>fi.id)),f=new Set([...Ke,...st].map(fi=>fi.id));for(const[fi,Tt]of r)f.has(fi)||(ft(Tt),r.delete(fi));await Promise.all([...f].map(async fi=>{const Tt=X(fi);await Tt.loaded,Tt.busy===0&&await he(fi,Tt)}));const tn=t.session();if(tn===null){l=[],pe();return}const An=++H;try{l=await tn.api.list(),_=!1,x=null,C=0,N=Date.now()}catch(fi){const Tt=kve(fi);Tt==="retry"?(_=!0,C++,T!==null&&clearTimeout(T),T=setTimeout(()=>{T=null,Wt.refresh(!0)},Math.min(wOt,xOt*2**(C-1)))):Tt==="rejected"&&(x=TOt(fi)),pe();return}m++,pe();const un=new Map(l.map(fi=>[fi.id,fi]));for(const fi of Ke)await xt(fi.id,!1,un.get(fi.id),An);for(const fi of st)await xt(fi.id,!0,un.get(fi.id),An);pe()}function Nt(Me,Ke){return Me.record!==null&&Me.record.wallet!==Ke?{state:"local",otherAccount:!0}:Me.conflict?Me.record===null?{state:"conflict",unrelated:!0}:{state:"conflict"}:Me.busy>0?{state:"syncing",progress:Me.progress}:Me.error!==null?{state:"error",message:Me.error}:Me.record!==null&&Me.pending.size===0&&!Me.behind?{state:"synced"}:{state:Me.retry!==null||_?"offline":"syncing"}}const Ut=()=>{for(const[Me,Ke]of r)Ke.retry!==null&&(clearTimeout(Ke.retry),Ke.retry=null,Ve(Me));T!==null&&Wt.refresh(!0)};typeof window<"u"&&window.addEventListener("online",Ut);const Wt={status(){var Tn,fi,Tt;const Me=t.account(),Ke=t.session(),st={};for(const Wi of f){const Er=r.get(Wi);st[Wi]=Ke===null||Er===void 0?{state:"local"}:Nt(Er,Ke.wallet)}const tn=Object.entries(st).filter(([Wi])=>!s.has(Wi));let An="synced";Ke===null?An="local":x!==null?An="error":_&&(An="offline");for(const[,Wi]of tn)Wi.state!=="local"&&SOt.indexOf(Wi.state)<SOt.indexOf(An)&&(An=Wi.state);const un=((Tn=tn.find(([,Wi])=>Wi.state==="error"))==null?void 0:Tn[1].message)??x??void 0;return{account:Me,state:An,message:un,projects:st,revision:m,usage:((Tt=Ke==null?void 0:(fi=Ke.api).usage)==null?void 0:Tt.call(fi))??void 0}},subscribe(Me){return a.add(Me),()=>a.delete(Me)},remoteOnly(){return t.session()===null?[]:l.filter(Me=>Me.deletedAt==null&&!f.has(Me.id)).map(({id:Me,name:Ke,updatedAt:st})=>({id:Me,name:Ke,updatedAt:st}))},remoteIds:()=>l.map(Me=>Me.id),async manifest(Me){var st;const Ke=X(Me);return await Ke.loaded,Eve(n,t.hash,Me,((st=Ke.record)==null?void 0:st.base)??null,[...Ke.pending])},refresh(Me=!1){return Z?Promise.resolve():F!==null?F:!Me&&Date.now()-N<Qwr?Promise.resolve():(T!==null&&clearTimeout(T),T=null,F=fe(ut()).catch(Ke=>console.warn("[editor] could not compare the scenes with the account",Ke)).finally(()=>{F=null}),F)},touched(Me,Ke){if(!eJ(Ke))return;f.add(Me);const st=X(Me);st.error=null,st.loaded.then(()=>{if(wt(st))return;const tn=!st.pending.has(Ke);st.pending.add(Ke),tn&&st.record!==null&&Ce(Me,st),pe()}),t.session()!==null&&St(Me,e9e),pe()},async flush(Me){const Ke=[...r].filter(([st,tn])=>(Me===void 0||st===Me)&&tn.debounce!==null);await Promise.all(Ke.map(([st,tn])=>(tn.debounce!==null&&clearTimeout(tn.debounce),tn.debounce=null,Ve(st))))},async prepareOpen(Me,Ke){const st=t.session();if(!f.has(Me)&&!(await n.list()).some(Tn=>Tn.id===Me)){if(st===null)throw new Error("This scene is not on this device.");let Tn,fi;try{if(Tn=await st.api.manifest(Me),Tn===null)throw new Error("This scene is no longer on your account.");fi=await bOt(st.api,Me,Object.entries(Tn.files),Ke??(()=>{}))}catch(Wi){throw Wi instanceof YA||kve(Wi)!=="retry"?Wi:new Error("This scene is on your account but not on this device yet, and you seem to be offline.")}await n.create(Tn.name,[...fi],{id:Me}),f.add(Me);const Tt=X(Me);await Tt.loaded,Tt.record={wallet:st.wallet,baseVersion:Tn.version,base:Tn.files,pending:[],remoteDeleted:!1},Tt.agreedAt=++H,await Ce(Me,Tt),m++,pe();return}if(f.add(Me),st===null)return;let tn=!1,An=!1;const un=qe(Me,async(Tn,fi)=>{if(tn||Tn.conflict)return;await he(Me,Tn);let Tt;try{Tt=await Cve(fi.api,Me)}catch{return}if(!tn){if(An=!0,Tt===null){Tn.record!==null&&(Tn.record=null,await Ce(Me,Tn)),St(Me,0);return}if(Tn.record===null||Tt.version!==Tn.record.baseVersion&&Tn.pending.size>0){(Tn.record===null||!await $t(Me,Tn,fi.wallet,Tt))&&(Tn.conflict=!0);return}if(Tt.version!==Tn.record.baseVersion)try{await Re(Me,Tn,fi,Tt,Tn.record.base,Ke)}catch(Wi){Wi instanceof Nxe||gt(Me,Tn,Wi,()=>{})}}});await Promise.race([un,new Promise(Tn=>setTimeout(()=>{An||(tn=!0,Tn())},Jwr))])},async resolve(Me,Ke){if(t.session()===null)throw new Error("Sign in to choose which version to keep.");const tn=Ke==="keep-both"?await t.duplicate(Me):null,An=await qe(Me,async(un,{api:Tn,wallet:fi})=>{const Tt=await Cve(Tn,Me),Wi=await Eve(n,t.hash,Me,null,[]);if(Ke==="keep-local"||Tt===null){await vOt(n,Tn,Me,Wi,(Tt==null?void 0:Tt.files)??{},qt(un));const Er=await Tn.putManifest(Me,{name:await t.title(Me),files:Wi,baseVersion:(Tt==null?void 0:Tt.version)??null});un.record={wallet:fi,baseVersion:Er,base:Wi,pending:[],remoteDeleted:!1},un.agreedAt=++H,un.pending.clear(),un.conflict=!1,Ue(un),await Ce(Me,un)}else await Re(Me,un,{api:Tn,wallet:fi},Tt,Wi);return!0});if(tn!==null&&(f.add(tn),St(tn,0)),An!==!0)throw new Error("Sign in to choose which version to keep.");m++,pe()},trashed(Me){s.add(Me);const Ke=X(Me);ft(Ke),Ke.loaded.then(()=>{wt(Ke)&&(Ke.record=null,Ke.pending.clear(),Ce(Me,Ke))}),qe(Me,async(st,{api:tn})=>{if(Ke.record!==null)try{await tn.remove(Me),Ke.record.remoteDeleted=!0,await Ce(Me,Ke)}catch{}})},restored(Me){s.delete(Me);const Ke=X(Me);qe(Me,async(st,{api:tn})=>{if(Ke.record===null){St(Me,0);return}try{Ke.record.remoteDeleted&&await tn.restore(Me),Ke.record.remoteDeleted=!1,await Ce(Me,Ke),Ke.pending.size>0&&St(Me,0)}catch{}})},async idle(){for(;te.size>0;)await Promise.all([...te]);await Promise.all([...r.values()].map(Me=>Me.saving))},dispose(){Z=!0;for(const Me of r.values())ft(Me);T!==null&&clearTimeout(T),typeof window<"u"&&window.removeEventListener("online",Ut),a.clear()}};return Wt}const IWe=67324752,aWt=33639248,NWe=101010256,Zwr=117853008,Kwr=2048,eSr=1,DWe=0,sWt=8,Dxe=4294967295;let Ave=null;function oWt(t){if(Ave===null){Ave=new Uint32Array(256);for(let r=0;r<256;r++){let a=r;for(let s=0;s<8;s++)a=a&1?3988292384^a>>>1:a>>>1;Ave[r]=a}}let n=Dxe;for(const r of t)n=Ave[(n^r)&255]^n>>>8;return(n^Dxe)>>>0}async function cWt(t,n,r=1/0){const s=new Blob([t]).stream().pipeThrough(n).getReader(),l=[];let f=0;for(;;){const{done:x,value:T}=await s.read();if(x)break;if(f+=T.length,f>r)throw await s.cancel(),new Error("The zip file is damaged: an entry is larger than it says");l.push(T)}const m=new Uint8Array(f);let _=0;for(const x of l)m.set(x,_),_+=x.length;return m}function tSr(t){return{time:t.getHours()<<11|t.getMinutes()<<5|t.getSeconds()>>1,day:Math.max(1980,t.getFullYear())-1980<<9|t.getMonth()+1<<5|t.getDate()}}async function nSr(t,n=new Date){const{time:r,day:a}=tSr(n),s=[],l=[];let f=0,m=0;for(const[F,B]of t){const H=new TextEncoder().encode(F),Z=await cWt(B,new CompressionStream("deflate-raw")),K=Z.length>=B.length,te=K?B:Z,pe=new DataView(new ArrayBuffer(26));pe.setUint16(0,20,!0),pe.setUint16(2,Kwr,!0),pe.setUint16(4,K?DWe:sWt,!0),pe.setUint16(6,r,!0),pe.setUint16(8,a,!0),pe.setUint32(10,oWt(B),!0),pe.setUint32(14,te.length,!0),pe.setUint32(18,B.length,!0),pe.setUint16(22,H.length,!0);const fe=new Uint8Array(30+H.length);new DataView(fe.buffer).setUint32(0,IWe,!0),fe.set(new Uint8Array(pe.buffer),4),fe.set(H,30);const X=new Uint8Array(46+H.length),he=new DataView(X.buffer);if(he.setUint32(0,aWt,!0),he.setUint16(4,788,!0),X.set(new Uint8Array(pe.buffer),6),he.setUint32(38,33188<<16>>>0,!0),he.setUint32(42,f,!0),X.set(H,46),s.push(fe,te),l.push(X),f+=fe.length+te.length,m++,f>Dxe||m>65535)throw new Error("The project is too large for a .zip file (4 GB, 65535 files)")}const _=l.reduce((F,B)=>F+B.length,0),x=new Uint8Array(22),T=new DataView(x.buffer);T.setUint32(0,NWe,!0),T.setUint16(8,m,!0),T.setUint16(10,m,!0),T.setUint32(12,_,!0),T.setUint32(16,f,!0);const C=new Uint8Array(f+_+x.length);let N=0;for(const F of[...s,...l,x])C.set(F,N),N+=F.length;return C}function rSr(t){const n=new DataView(t.buffer,t.byteOffset,t.byteLength);let r=t.length-22;for(;r>=0&&r>=t.length-22-65535&&n.getUint32(r,!0)!==NWe;)r--;if(r<0||n.getUint32(r,!0)!==NWe)throw new Error("This is not a .zip file");const a=n.getUint16(r+10,!0);let s=n.getUint32(r+16,!0);if(a===65535||s===Dxe||r>=20&&n.getUint32(r-20,!0)===Zwr)throw new Error("This .zip file is too large to import (zip64)");const l=[],f=[];for(let m=0;m<a;m++){if(s+46>t.length||n.getUint32(s,!0)!==aWt)throw new Error("The zip file is damaged");const _=n.getUint16(s+8,!0),x=n.getUint16(s+10,!0),T=n.getUint32(s+16,!0),C=n.getUint32(s+20,!0),N=n.getUint32(s+24,!0),F=n.getUint16(s+28,!0),B=n.getUint32(s+42,!0),H=new TextDecoder().decode(t.subarray(s+46,s+46+F));if(s+=46+F+n.getUint16(s+30,!0)+n.getUint16(s+32,!0),H.endsWith("/"))continue;if(B+30>t.length||n.getUint32(B,!0)!==IWe)throw new Error("The zip file is damaged");const Z=B+30+n.getUint16(B+26,!0)+n.getUint16(B+28,!0)+C;if(Z>t.length)throw new Error("The zip file is damaged");f.push([B,Z]),l.push({path:H,size:N,async read(){if(_&eSr)throw new Error(`"${H}" is encrypted`);if(x!==DWe&&x!==sWt)throw new Error(`"${H}" uses a compression this editor cannot read`);if(B+30>t.length||n.getUint32(B,!0)!==IWe)throw new Error("The zip file is damaged");const K=B+30+n.getUint16(B+26,!0)+n.getUint16(B+28,!0),te=t.subarray(K,K+C),pe=x===DWe?te.slice():await cWt(te,new DecompressionStream("deflate-raw"),N);if(pe.length!==N||oWt(pe)!==T)throw new Error(`The zip file is damaged: "${H}" does not check out`);return pe}})}f.sort(([m],[_])=>m-_);for(let m=1;m<f.length;m++)if(f[m][0]<f[m-1][1])throw new Error("The zip file is damaged: two of its files share the same bytes");return l}const cM={files:2e3,fileBytes:50*1024*1024,totalBytes:500*1024*1024},EOt=1024*1024,iSr=/(^|\/)(__MACOSX\/|\.DS_Store$|Thumbs\.db$|desktop\.ini$)/,lWt=new Set(["node_modules",".git"]),Ove=t=>t.split("/").length;async function aSr(t,n){var te,pe;const r=n.map(fe=>({entry:fe,path:fe.path.replace(/\\/g,"/").replace(/^(\.\/)+/,"")})).filter(({path:fe})=>!iSr.test(fe));if(r.some(({path:fe})=>fe==="dcl-workspace.json"))return{ok:!1,reason:"This is a workspace of several scenes. Import one scene folder at a time."};const a=r.map(({path:fe})=>fe).filter(fe=>(fe==="scene.json"||fe.endsWith("/scene.json"))&&!fe.split("/").some(X=>lWt.has(X))).sort((fe,X)=>Ove(fe)-Ove(X));if(a.length===0)return{ok:!1,reason:"There is no scene.json here, so this does not look like a Decentraland scene."};if(a.length>1&&Ove(a[0])===Ove(a[1]))return{ok:!1,reason:"There are several scenes here. Import one scene folder at a time."};const s=a[0].slice(0,-10),l=r.filter(({path:fe})=>fe.startsWith(s)).map(({entry:fe,path:X})=>({entry:fe,path:X.slice(s.length)})),f=l.filter(({path:fe})=>eJ(fe)),m=fe=>({ok:!1,reason:`This scene is too large to import: ${fe}.`}),_=fe=>m(`${fe} is larger than ${cM.fileBytes/EOt} MB`),x=()=>m(`its files add up to more than ${cM.totalBytes/EOt} MB`);if(f.length>cM.files)return m(`it has more than ${cM.files} files`);const T=f.find(({entry:fe})=>(fe.size??0)>cM.fileBytes);if(T!==void 0)return _(T.path);if(f.reduce((fe,{entry:X})=>fe+(X.size??0),0)>cM.totalBytes)return x();const C=new Map;let N=0;for(const{entry:fe,path:X}of f){const he=await fe.read();if(he.length>cM.fileBytes)return _(X);if(N+=he.length,N>cM.totalBytes)return x();C.set(X,he)}const F=l.length-f.length,B=M1(C.get("scene.json"));if(B===null)return{ok:!1,reason:"scene.json is not valid JSON."};if(typeof((te=B.scene)==null?void 0:te.base)!="string"||!Array.isArray(B.scene.parcels))return{ok:!1,reason:"scene.json does not say which parcels the scene is on (scene.base and scene.parcels)."};const H=[];B.runtimeVersion!=="7"&&H.push('This is not an SDK7 scene (scene.json has no runtimeVersion "7"). The editor builds SDK7 scenes only, so it will most likely not run.'),[...C.keys()].some(fe=>fe.startsWith("server/"))&&H.push("This project has a server/ folder. The web editor does not run or publish a scene server: the files are kept, and nothing in them runs.");const Z=XVt(C.get("package.json"));return{ok:!0,plan:{title:typeof((pe=B.display)==null?void 0:pe.title)=="string"&&B.display.title.trim()!==""?B.display.title.trim():t,files:C,skipped:F,warnings:H,needsPackages:Z}}}function sSr(t){return rSr(t)}async function uWt(t,n=""){const r=[];for await(const[a,s]of t.entries())s.kind==="file"?r.push({path:n+a,read:async()=>new Uint8Array(await(await s.getFile()).arrayBuffer())}):lWt.has(a)||r.push(...await uWt(s,`${n}${a}/`));return r}function dWt(){const t=window.showDirectoryPicker;return typeof t=="function"?t.bind(window):null}const oSr=t=>t instanceof Error?t.message:String(t);function fWt(t){return new Promise(n=>{const r=document.createElement("input");r.type="file",r.accept=t,r.onchange=()=>{var a;return n(((a=r.files)==null?void 0:a[0])??null)},r.oncancel=()=>n(null),r.click()})}const cSr=()=>dWt()!==null;async function lSr(t,n){const r=[...n].sort(([f],[m])=>f.localeCompare(m)),a=await nSr(r),s=URL.createObjectURL(new Blob([a],{type:"application/zip"})),l=document.createElement("a");l.href=s,l.download=`${t.replace(/[^\w.-]+/g,"-").replace(/^-+|-+$/g,"")||"scene"}.zip`,l.click(),setTimeout(()=>URL.revokeObjectURL(s),6e4)}async function uSr(t){if(t==="zip"){const r=await fWt(".zip,application/zip");return r===null?null:{name:r.name.replace(/\.zip$/i,""),entries:sSr(new Uint8Array(await r.arrayBuffer()))}}const n=dWt();if(n===null)throw new Error("This browser cannot open a folder. Zip the scene folder and import the .zip.");try{const r=await n({mode:"read"});return{name:r.name,entries:await uWt(r)}}catch(r){if(r instanceof Error&&r.name==="AbortError")return null;throw r}}async function dSr(t,n){try{const r=await uSr(t);if(r===null)return null;const a=await aSr(r.name,r.entries);if(!a.ok)return a;const{title:s,files:l,skipped:f,warnings:m,needsPackages:_}=a.plan;return{ok:!0,report:{id:await n(s,l),title:s,files:l.size,skipped:f,warnings:m,needsPackages:_}}}catch(r){return{ok:!1,reason:oSr(r)}}}function fSr(t,n,r){let a=null;const s=new Map,l=()=>(a??(a=r(new URL("prefabs/catalog.json",t).href,n,"prefabs/catalog.json").then(async f=>await f.json()).catch(f=>{throw a=null,f})),a);return{async folders(){return(await l()).map(f=>({name:f.name,data:f.data,files:Object.fromEntries(Object.entries(f.files).map(([m,_])=>[m,_.size]))}))},async read(f,m){var C;const _=(C=(await l()).find(N=>N.name===f.name))==null?void 0:C.files[m];if(_===void 0)throw new Error(`${f.name}/${m} is not a built-in prefab file`);const x=`prefabs/${f.name}/${m}`;let T=s.get(x);if(T===void 0){const N=new URL(x.split("/").map(encodeURIComponent).join("/"),t).href;T=r(N,_.integrity,x).then(async F=>new Uint8Array(await F.arrayBuffer())),s.set(x,T),T.catch(()=>s.delete(x))}return T}}}const pSr=`{
|
|
32669
32669
|
"version": 1,
|
|
32670
32670
|
"components": [
|
|
@@ -33121,9 +33121,9 @@ module.exports = require('./index')
|
|
|
33121
33121
|
"server-logs": "sdk-commands sdk-server-logs"
|
|
33122
33122
|
},
|
|
33123
33123
|
"devDependencies": {
|
|
33124
|
-
"@dcl/js-runtime": "7.
|
|
33125
|
-
"@dcl/sdk": "7.
|
|
33126
|
-
"@dcl/sdk-commands": "7.
|
|
33124
|
+
"@dcl/js-runtime": "7.31.1-40606969412.commit-24c05c3",
|
|
33125
|
+
"@dcl/sdk": "7.31.1-40606969412.commit-24c05c3",
|
|
33126
|
+
"@dcl/sdk-commands": "7.31.1-40606969412.commit-24c05c3"
|
|
33127
33127
|
},
|
|
33128
33128
|
"engines": {
|
|
33129
33129
|
"node": ">=22"
|
|
@@ -33693,9 +33693,9 @@ exports.setSyncEntity = function setSyncEntity() {}
|
|
|
33693
33693
|
"server-logs": "sdk-commands sdk-server-logs"
|
|
33694
33694
|
},
|
|
33695
33695
|
"devDependencies": {
|
|
33696
|
-
"@dcl/js-runtime": "7.
|
|
33697
|
-
"@dcl/sdk": "7.
|
|
33698
|
-
"@dcl/sdk-commands": "7.
|
|
33696
|
+
"@dcl/js-runtime": "7.31.1-40606969412.commit-24c05c3",
|
|
33697
|
+
"@dcl/sdk": "7.31.1-40606969412.commit-24c05c3",
|
|
33698
|
+
"@dcl/sdk-commands": "7.31.1-40606969412.commit-24c05c3"
|
|
33699
33699
|
},
|
|
33700
33700
|
"engines": {
|
|
33701
33701
|
"node": ">=22"
|
|
@@ -35764,4 +35764,4 @@ ${n}
|
|
|
35764
35764
|
${r}`));return"w"+Array.from(new Uint8Array(a).slice(0,16),s=>s.toString(16).padStart(2,"0")).join("")}function oTr(t){return`${t.file===void 0?"":`${t.file}:${t.line??1}:${t.column??0}: `}${t.severity==="error"?"ERROR":"WARNING"}: ${t.message}`}function cTr(t){return t.length<=3?t.join(", "):`${t.slice(0,3).join(", ")} and ${t.length-3} more`}function lTr(t,n){const r=M1(t.get("package.json"));for(const a of[r==null?void 0:r.devDependencies,r==null?void 0:r.dependencies]){const s=typeof a=="object"&&a!==null?a["@dcl/sdk"]:void 0;if(typeof s=="string"&&s!==n)return`⚠ This project asks for @dcl/sdk ${s}; the editor builds it with ${n}.`}return null}function uTr(t){const{emit:n,log:r}=t;let a=null,s=!1,l=null,f=Promise.resolve();const m=C=>{const N=f.then(C,C);return f=N.catch(()=>{}),N};async function _(){if(s)throw new Error("The editor was closed");a===null&&(l=null);const C=a??B1r(t.urls);a=C;try{const N=await C.ready;return{builder:C,sdkVersion:N.sdkVersion,info:N}}catch(N){throw C.dispose(),a===C&&(a=null),N}}async function x(C,N,F){const{builder:B,info:H}=await _();let Z=!1;const K=await iTr(N,t.packages,H.snapshot,pe=>{t.onPackages(C,pe),F&&!Z&&r("Downloading packages from npm…"),Z=!0});K.lockFile!==void 0&&(N.set(I3,K.lockFile),await t.saveLock(C,K.lockFile));const te=K.lock===null?"":UVt(K.lock);if(te!==l)try{await B.setPackages(K.lock,t.packages),l=te}catch(pe){F&&r(`⚠ ${POt(pe)}`),await B.setPackages(null),l=""}if(t.onPackages(C,K.status),!(!F||K.status===null)){if(K.status.state==="error")r(`✖ ${K.status.message??"The packages could not be installed"}`);else if(K.downloaded>0){const pe=Object.entries(K.status.installed).map(([fe,X])=>`${fe} ${X}`);r(`✔ Packages frozen into the scene: ${pe.join(", ")} (${K.status.total} in all)`)}for(const pe of K.status.warnings)r(`⚠ ${pe}`)}}function T(C,N,F=C){const B=wWe(t.pageDir,F),H=new Set;let Z=null,K=null,te=!0,pe=!1,fe=!1,X=null;const he=wt=>(n({type:"failed",message:wt}),r(`✖ Build failed: ${wt.split(`
|
|
35765
35765
|
`)[0]}`),!1);async function Ce(wt){const ft=performance.now();n({type:"buildStarted",changed:wt}),r(wt.length===0?"Building the scene…":`Rebuilding: ${cTr(wt)}`);try{const{builder:St,sdkVersion:gt}=await _(),Ue=wt.length===0?lTr(N,gt):null;Ue!==null&&r(Ue);const qt=wt.length===0||wt.includes("package.json")||wt.includes(I3),{snapshot:Ve,result:Re}=await m(async()=>{(qt||l!==X)&&(await x(C,N,!0),X=l);const xt=new Map(N);return{snapshot:xt,result:await St.build(xt)}});if(fe)return!1;const $t=Re.diagnostics.filter(xt=>xt.severity==="error"||xt.file===void 0||Ve.has(xt.file));n({type:"diagnostics",diagnostics:$t.map(({severity:xt,message:ut,file:Nt,line:Ut,column:Wt})=>({severity:xt,message:ut,file:Nt,line:Ut,column:Wt}))});for(const xt of $t)r(oTr(xt));if(!Re.ok){const xt=Re.events.find(ut=>ut.type==="failed");return he((xt==null?void 0:xt.type)==="failed"?xt.message:"The build produced no bundle")}const vt=M1(Ve.get("scene.json"));return vt===null?he("scene.json is missing or is not valid JSON"):(await Qxr({realmUrl:B,projectId:F,files:Ve,buildOutputs:Re.outputs,sceneJson:vt,sdkVersion:gt,machineId:await t.machineId(F)}),fe?!1:(n({type:"bundleSaved"}),r(`✔ Built in ${Math.round(performance.now()-ft)} ms`),!0))}catch(St){return fe?!1:he(POt(St))}}function qe(){return fe?Promise.resolve(!1):(K!==null||(K=(async()=>{for(;(te||H.size>0)&&!fe;){const wt=te?[]:[...H];te=!1,H.clear(),pe=await Ce(wt)}return pe&&!fe})().finally(()=>{K=null})),K)}return{id:C,files:N,start:qe,flush(){return Z!==null&&clearTimeout(Z),Z=null,qe()},async published(){const wt=await(await caches.open(Ixe)).match(SWe(B)),ft=await(wt==null?void 0:wt.json().catch(()=>{})),St=ft==null?void 0:ft.entity;return(St==null?void 0:St.id)===BXe(F,await t.machineId(F))},changed(wt){fe||(H.add(wt),Z!==null&&clearTimeout(Z),Z=setTimeout(()=>{Z=null,qe()},aTr))},stop(){fe=!0,Z!==null&&clearTimeout(Z)}}}return{realmUrl:C=>wWe(t.pageDir,C),open:T,async build(C,N,F){const{builder:B,sdkVersion:H}=await _();return m(async()=>(await x(C,N,!1),{...await B.build(N,F),sdkVersion:H}))},install:(C,N)=>m(()=>x(C,N,!1)),dispose(){s=!0,a==null||a.dispose(),a=null}}}const NOt=64*1024*1024,dTr=4*1024*1024;function fTr(t,n){return t.length>8192?!1:n==="POST"?t==="/content/entities/active":n!=="GET"&&n!=="HEAD"?!1:t==="/about"||t==="/scene.json"||/^\/content\/contents\/(?:b64-[A-Za-z0-9+/=]+|[A-Za-z0-9]+)$/.test(decodeURIComponent(t))}function pTr(t,n,r){const a=t===null?null:new URL(t).origin;let s="",l=null,f="",m="",_=new AbortController,x=0,T=0;const C=(B,H=[])=>{l!==null&&a!==null&&l.postMessage({...B,session:n,instance:s},a,H)},N=async B=>{var he;if(typeof B.requestId!="string"||B.requestId.length>128||typeof B.path!="string")return;const H=B.requestId;if(x>=64){C({type:"realm-response",requestId:H,error:"Too many preview resource requests"});return}const Z=_,K=l,te=new AbortController,pe=setTimeout(()=>te.abort(new Error("Preview resource timed out")),3e4);let fe=0,X;x++;try{const Ce=new URL(f+B.path);if(!Ce.href.startsWith(f+"/")||!fTr(B.path,B.method))throw new Error("Invalid preview resource");if(B.body!==void 0&&(!(B.body instanceof ArrayBuffer)||B.body.byteLength>1024*1024))throw new Error("Invalid preview request body");const qe=await fetch(Ce,{method:String(B.method),credentials:"omit",redirect:"error",signal:AbortSignal.any([Z.signal,te.signal]),headers:{"Content-Type":"application/json"},body:B.method==="POST"?B.body:void 0}),wt=qe.headers.get("Content-Type")??"application/octet-stream",ft=wt.includes("application/json")?dTr:NOt;if(X=(he=qe.body)==null?void 0:he.getReader(),Number(qe.headers.get("Content-Length"))>ft)throw new Error("Preview resource exceeds the memory limit");const St=[];if(X!==void 0)for(;;){const{done:Ve,value:Re}=await X.read();if(Ve)break;if(fe+=Re.byteLength,T+=Re.byteLength,fe>ft||T>NOt)throw new Error("Preview resource exceeds the memory limit");St.push(Re)}const gt=new Uint8Array(fe);let Ue=0;for(const Ve of St)gt.set(Ve,Ue),Ue+=Ve.byteLength;St.length=0;let qt=gt.buffer;if(B.method!=="HEAD"&&qt.byteLength>0&&wt.includes("application/json")){const Ve=JSON.parse(new TextDecoder().decode(qt)),Re=$t=>typeof $t=="string"?$t.startsWith(f+"/")||$t===f?m+$t.slice(f.length):$t:Array.isArray($t)?$t.map(Re):dl($t)?Object.fromEntries(Object.entries($t).map(([vt,xt])=>[vt,Re(xt)])):$t;qt=new TextEncoder().encode(JSON.stringify(Re(Ve))).buffer}!Z.signal.aborted&&K===l&&C({type:"realm-response",requestId:H,status:qe.status,headers:{"Content-Type":wt},body:qt},[qt])}catch(Ce){!Z.signal.aborted&&K===l&&C({type:"realm-response",requestId:H,error:Ce instanceof Error?Ce.message:String(Ce)})}finally{clearTimeout(pe),te.abort(),X!==void 0&&X.cancel().catch(Ce=>{Ce instanceof Error&&Ce.name==="AbortError"||console.warn("Preview stream cleanup:",Ce)}),T-=fe,x--}},F=B=>{const H=B.data;B.origin!==a||!dl(H)||H.session!==n||H.instance!==s||s===""||(H.type==="connect"&&l===null&&B.source!==null&&"postMessage"in B.source&&(l=B.source),!(B.source!==l||l===null)&&(H.type==="realm-request"?N(H):r(H)))};return window.addEventListener("message",F),{send:C,reset:(B="",H="",Z="")=>{_.abort(),_=new AbortController,l=null,s=B,f=H,m=Z},dispose:()=>{_.abort(),window.removeEventListener("message",F)}}}function mTr(t,n){return["localhost","127.0.0.1","[::1]"].includes(new URL(t).hostname)?"http://127.0.0.1:8788/mobile-preview/index.html":n===null?null:new URL("mobile-preview/index.html",n.replace(/\/$/,"")+"/").href}function hTr(t){if(t===null)return null;const n=new URL(t).hostname;return n==="decentraland.zone"||n.endsWith(".decentraland.zone")?"zone":null}function _Tr(t,n,r,a=null){const s=crypto.randomUUID(),l=pTr(t,s,fe=>pe(fe)),f=new Set,m=new Map;let _={mode:"closed",url:null,ready:!1},x=null,T="",C="",N=0,F=null,B=!1,H=null;const Z=fe=>{_=fe;for(const X of f)X()},K=()=>{C!==""&&l.send({type:"stop",session:s,instance:C}),l.reset(),H==null||H.close(),H=null,C="";for(const fe of m.values())fe.reject(new Error("The mobile preview was closed."));m.clear(),Z({mode:"closed",url:null,ready:!1})},te=()=>{N++,x=null,K()};window.addEventListener("pagehide",te);const pe=fe=>{if(!dl(fe)||fe.session!==s||fe.instance!==C||(fe.type==="ready"&&(Z({..._,ready:!0}),l.send({type:"visibility",session:s,instance:C,visible:_.mode!=="minimized"})),fe.type==="closed"&&te(),fe.type!=="capture"||typeof fe.requestId!="string"))return;const X=m.get(fe.requestId);X!==void 0&&(typeof fe.error=="string"?X.reject(new Error(fe.error)):typeof fe.image=="string"&&fe.image.length<=4e6&&typeof fe.width=="number"&&fe.width>0&&fe.width<=1024&&typeof fe.height=="number"&&fe.height>0&&fe.height<=1024?X.resolve({mimeType:"image/jpeg",image:fe.image,width:fe.width,height:fe.height}):X.reject(new Error("The mobile preview sent an invalid picture.")))};return{state:()=>_,status:()=>({mode:_.mode,ready:_.ready}),subscribe:fe=>(f.add(fe),()=>f.delete(fe)),open:async(fe,X,he="embedded")=>{if(B||t===null)return{ok:!1,reason:"unavailable"};const Ce=fe.replace(/\/$/,"");if(_.mode===he&&x===Ce)return N++,{ok:!0};if((he==="embedded"||he==="minimized")&&(_.mode==="embedded"||_.mode==="minimized")&&x===Ce){if(N++,Z({..._,mode:he}),l.send({type:"visibility",session:s,instance:C,visible:he!=="minimized"}),he==="minimized")for(const qt of m.values())qt.reject(new Error("Restore the mobile preview before taking a picture."));return{ok:!0}}if(he==="minimized")return{ok:!1,reason:"unavailable"};const qe=he==="tab"?window.open("about:blank",`dcl-phone-preview-${crypto.randomUUID()}`):null;if(he==="tab"&&qe===null)return{ok:!1,reason:"unavailable"};const wt=++N;if(!await fetch(t,{method:"HEAD",signal:AbortSignal.timeout(5e3)}).then(qt=>qt.ok,()=>!1)||wt!==N||B||qe!=null&&qe.closed)return qe==null||qe.close(),{ok:!1,reason:"unavailable"};if(K(),await new Promise(qt=>setTimeout(qt,100)),wt!==N||B||qe!=null&&qe.closed)return qe==null||qe.close(),{ok:!1,reason:"unavailable"};C=crypto.randomUUID();const St=new URL(t);St.searchParams.set("previewSession",s),St.searchParams.set("previewInstance",C),St.searchParams.set("editorOrigin",window.location.origin),he==="tab"&&St.searchParams.set("previewDetached","1"),St.searchParams.set("maxpixels",String(1600*720)),T=new URL(`realm/${s}/${C}`,t).href,l.reset(C,Ce,T);const gt=new URL("decentraland://open");gt.searchParams.set("preview",T),gt.searchParams.set("position",X);const Ue=["--local-editor-preview","--skip-lobby","--guest-profile","--fake-deeplink",gt.href];return a!==null&&Ue.push("--dclenv",a),St.searchParams.set("args",Ue.join(" ")),x=Ce,Z({mode:he,url:St.href,ready:!1}),H=qe,qe!==null&&gTr(qe,St.href),{ok:!0}},close:te,capture:async fe=>{if(fe.throwIfAborted(),_.mode==="closed"||!_.ready)throw new Error("Open the mobile preview and wait for it to load before taking a picture.");_.mode==="minimized"&&(F=N,Z({..._,mode:"embedded"}),l.send({type:"visibility",session:s,instance:C,visible:!0}));const X=crypto.randomUUID();try{return await new Promise((he,Ce)=>{const qe=()=>{clearTimeout(ft),fe.removeEventListener("abort",wt),m.delete(X)},wt=()=>{qe(),Ce(fe.reason)},ft=setTimeout(()=>{qe(),Ce(new Error("The mobile preview did not answer. Bring its tab to the foreground and retry."))},1e4);m.set(X,{resolve:St=>{qe(),he(St)},reject:St=>{qe(),Ce(St)}}),fe.addEventListener("abort",wt,{once:!0}),l.send({type:"capture",session:s,instance:C,requestId:X})})}finally{m.size===0&&(F===N&&_.mode==="embedded"&&(Z({..._,mode:"minimized"}),l.send({type:"visibility",session:s,instance:C,visible:!1})),F=null)}},built:async fe=>{if(x===null)return;const X=x,he=await n(fe),Ce=BXe(he,await r(he));!B&&X===x&&l.send({type:"scene-updated",session:s,instance:C,realm:T,entityId:Ce})},dispose:()=>{te(),B=!0,window.removeEventListener("pagehide",te),l.dispose(),f.clear()}}}function gTr(t,n){const r=t.document;r.title="Mobile scene preview",r.body.style.cssText="margin:0;background:#19191c;overflow:hidden";const a=r.createElement("iframe");a.title="Mobile scene preview",a.allow="autoplay; fullscreen; gamepad; cross-origin-isolated",a.style.cssText="width:100vw;height:100vh;border:0;display:block",a.src=n,r.body.replaceChildren(a)}const yTr=200,vTr=2e3,bTr=/^\((?:no logs|\+\d+ older entries not retained)\)$/;function xTr(t,n){for(let r=Math.min(t.length,n.length);r>0;r--){const a=t.length-r;if(n.slice(0,r).every((s,l)=>s===t[a+l]))return n.slice(r)}return[...n]}function wTr(t,n){let r=[],a=!1,s;const l=async()=>{try{const f=await t(`scene_logs ${yTr} --server`);if(a)return;const m=f.split(`
|
|
35766
35766
|
`).filter(_=>_.trim()!==""&&!bTr.test(_.trim()));for(const _ of xTr(r,m))n(_);r=m}catch{}a||(s=setTimeout(()=>void l(),vTr))};return l(),()=>{a=!0,clearTimeout(s)}}function STr(t,n,r){r.throwIfAborted();const a=nt.scene,s=[...t].sort().join(";");return new Promise((l,f)=>{const m=()=>{clearTimeout(N),T(),r.removeEventListener("abort",C)},_=F=>{m(),f(F)},x=()=>{var B;nt.scene===a||nt.status!=="ready"||!nt.frozen||((B=nt.scene)==null?void 0:B.parcels.map(H=>`${H.x},${H.y}`).sort().join(";"))!==s||(m(),l())},T=BWe(x),C=()=>_(r.reason),N=setTimeout(()=>_(new Error("The preview has not loaded the new parcels. Retry sceneSettings before building outside the current layout.")),9e4);r.addEventListener("abort",C,{once:!0});try{n(),x()}catch(F){_(F)}})}const TTr=new Set(["node_modules",".git","bin","dist"]),kTr=300*1024,ETr=56,CTr=5;function ATr(t){const n=t.origin,r=typeof n=="object"&&n!==null&&!Array.isArray(n)?n:null;return r!==null&&(r.source==="import"||r.source==="github")?r:{...r??{},source:"user"}}function OTr(t,n){const r=new Map;let a=new Map;function s(m,_){if(_.size>kTr)return t.blob(m,_.hash);let x=r.get(_.hash);return x===void 0&&(x=t.blob(m,_.hash),r.set(_.hash,x),x.catch(()=>r.delete(_.hash))),x}const l={async folders(){const m=await t.list();return a=new Map(m.map(x=>[x.name,x])),(await Promise.all(m.map(async x=>{const T=x.files["data.json"];if(T===void 0)return null;const C=await s(x.name,T).then(F=>new TextDecoder().decode(F),()=>null);if(C===null)return null;const N=Object.fromEntries(Object.entries(x.files).map(([F,B])=>[F,B.size]));return{name:x.name,data:C,files:N}}))).filter(x=>x!==null)},async read(m,_){var T;const x=(T=a.get(m.name))==null?void 0:T.files[_];if(x===void 0)throw new Error(`${m.name}/${_} is not in your library`);return s(m.name,x)}};async function f(m,_){const x={},T=new Map;for(const[N,F]of _){const B=await n(F);x[N]={hash:B,size:F.length},T.set(B,F)}const C=[...T].map(([N,F])=>({hash:N,size:F.length}));for(const N of await t.uploads(m,C)){const F=T.get(N.hash);F!==void 0&&await t.putBlob(N,F)}await t.put(m,x)}return{tree:l,async copyOut(m,_){const[x,T,C]=_.split("/");if(x!=="custom"||T===void 0||C!==void 0||!/^[A-Za-z0-9][A-Za-z0-9._-]*$/.test(T))throw new Error(`not a prefab folder: ${_}`);const N=`${_}/`,F=new Map;for(const[X,he]of m.files()){const Ce=X.slice(N.length);X.startsWith(N)&&!Ce.split("/").some(qe=>TTr.has(qe))&&F.set(Ce,he)}const B=F.get("data.json"),H=B===void 0?null:Fq(new TextDecoder().decode(B));if(H===null)throw new Error(`${_} has no readable data.json`);const Z={...H,id:typeof H.id=="string"?H.id:crypto.randomUUID(),origin:ATr(H)},K=`${JSON.stringify(Z,null,2)}
|
|
35767
|
-
`;F.set("data.json",new TextEncoder().encode(K));const te=RWe(hWt(H,T)).slice(0,ETr).replace(/_+$/,"")||"prefab",pe=new Set((await t.list()).map(X=>X.name));let fe=1;for(let X=0;X<CTr;X++){let he=te;for(;pe.has(he);)he=`${te}_${++fe}`;try{return await f(he,F),{ref:`user:${he}`,scope:"user",data:K}}catch(Ce){if(!(Ce instanceof rWt))throw Ce;pe.add(he)}}throw new Error("could not find a free name in your library — try again")},remove:m=>t.remove(m)}}const DOt=new WeakMap;function PTr(t){let n=DOt.get(t);return n===void 0&&(n=crypto.subtle.digest("SHA-256",new Uint8Array(t)).then(r=>[...new Uint8Array(r)].map(a=>a.toString(16).padStart(2,"0")).join("")),DOt.set(t,n)),n}async function ITr(t){const n=t.get(".dclignore"),r=$Xe(t.keys(),n===void 0?void 0:new TextDecoder().decode(n)).filter(l=>l!==I3),a=new Map;let s=0;for(const l of r){const f=t.get(l);f!==void 0&&(a.set(await PTr(f),f.byteLength),s++)}return{bytes:[...a.values()].reduce((l,f)=>l+f,0),files:s}}const ROt=4e3,NTr=4e6,DTr=YOt*24*60*60*1e3,RTr="assets/images",MTr=3e3,LTr=100,FTr="Sign in to keep prefabs in your own library. The built-in prefabs work without it.",jTr=t=>t instanceof Error?t.message:String(t);function t9e(t,n){var r,a,s;return{realm:n.replace(/\/$/,""),systemScene:"",position:((r=t.scene)==null?void 0:r.base)??((s=(a=t.scene)==null?void 0:a.parcels)==null?void 0:s[0])??"0,0",spawn:uwr(t),spawnPoints:JSON.stringify(Array.isArray(t.spawnPoints)?t.spawnPoints:[])}}const BTr=({host:t,sceneCompiler:n})=>{const r=new Wwr(jwr()),a=kk(t),s=a===null||a.services.projects===null?null:nWt(a.services.projects,(Qn,Lr)=>a.signedFetch(Qn,Lr)),l=()=>{const{address:Qn,isGuest:Lr}=t.identity();return Lr||Qn===null?null:Qn.toLowerCase()},f=[],m=[],_=[],x=[],T=[],C=Qn=>{f.push(Qn),f.length>ROt&&f.splice(0,f.length-ROt);for(const Lr of m)Lr(Qn)},N=_Tr(mTr(t.pageDir,(a==null?void 0:a.services.projects)??null),he,async Qn=>IOt(await Z,l()??"guest",Qn),hTr((a==null?void 0:a.services.worldsContent)??null)),F=Qn=>{for(const Lr of _)Lr(Qn);Qn.type==="bundleSaved"&&pe!==null&&N.built(pe.id).catch(Lr=>console.error("[editor] mobile preview reload failed",Lr))},B=new Map,H=new Set,Z=B3t.then(sTr),K=uTr({pageDir:t.pageDir,urls:n,machineId:async Qn=>IOt(await Z,l()??"guest",Qn),emit:F,log:C,packages:r.packages,saveLock:async(Qn,Lr)=>{await r.write(Qn,I3,Lr),xt.touched(Qn,I3),(pe==null?void 0:pe.id)===Qn&&pe.files.set(I3,Lr)},onPackages:(Qn,Lr)=>{if(Lr===null){B.delete(Qn);return}B.set(Qn,Lr);for(const ti of H)ti(Qn,Lr)}});let te=null,pe=null,fe=null,X=null;async function he(Qn){var Ga;const Lr=(Ga=(await r.list()).find(Xa=>Xa.id===Qn))==null?void 0:Ga.previewId;if(Lr!==void 0)return Lr;const ti="p"+Array.from(crypto.getRandomValues(new Uint8Array(16)),Xa=>Xa.toString(16).padStart(2,"0")).join("");return await r.patch(Qn,{previewId:ti}),ti}async function Ce(Qn){const Lr=new URL("preview/",t.pageDir).href,ti=await caches.open(Ixe);for(const Ga of await ti.keys())Ga.url.startsWith(Lr)&&(Qn===null||!Ga.url.startsWith(Qn))&&await ti.delete(Ga)}let qe=0,wt=Promise.resolve(),ft=Promise.resolve();const St=Kxr({service:(a==null?void 0:a.services.projects)??null,fetch:(Qn,Lr)=>a===null?Promise.reject(new Error("The assistant service is not configured.")):a.signedFetch(Qn,Lr),wallet:l,mobilePreview:N.status,memory:{read:async(Qn,Lr)=>{const ti=await r.assistantMemory(Qn,Lr);return dl(ti)&&typeof ti.id=="string"&&typeof ti.key=="string"?{id:ti.id,key:ti.key}:null},write:(Qn,Lr,ti)=>r.setAssistantMemory(Qn,Lr,ti)},project:()=>{const Qn=Tt();return{id:Qn.id,tools:{files:()=>Qn.files,write:(Lr,ti,Ga,Xa)=>qt(Qn.id,Lr,ti,{expected:Ga,signal:Xa}),assets:s$t({files:()=>Qn.files}),scene:(Lr,ti)=>sTe(Lr,ti,async Ga=>{var ii,yl,ja;const Xa=ss=>{var Ts,Zs;return JSON.stringify([(Ts=ss==null?void 0:ss.scene)==null?void 0:Ts.parcels,(Zs=ss==null?void 0:ss.scene)==null?void 0:Zs.base])};await KA();const Kc=Xa(M1(await Ue(Qn.id,"scene.json")));await tn(Qn.id,ss=>mwr(ss,Ga));const uu=M1(await Ue(Qn.id,"scene.json")),lr=Xa(uu)!==Kc,Pl=((ii=uu==null?void 0:uu.scene)==null?void 0:ii.parcels)??[],fm=(yl=nt.scene)==null?void 0:yl.parcels.map(ss=>`${ss.x},${ss.y}`).sort().join(";");if(lr||fm!==[...Pl].sort().join(";")){if(!await Qn.flush())throw new Error("The scene did not build. Fix the code and retry sceneSettings to load the new parcels.");ti.throwIfAborted();const ss=await he(Qn.id);te=t9e(uu??{},K.realmUrl(ss)),await STr(Pl,()=>{for(const Ts of x)Ts(te)},ti)}else if(te!==null){const ss=t9e(uu??{},te.realm);(ss.spawn!==te.spawn||ss.spawnPoints!==te.spawnPoints)&&(te={...te,spawn:ss.spawn,spawnPoints:ss.spawnPoints},lur(ss.spawn,ss.spawnPoints))}return{requiredPermissions:(uu==null?void 0:uu.requiredPermissions)??[],spawnPoints:(uu==null?void 0:uu.spawnPoints)??[],parcels:Pl,base:((ja=uu==null?void 0:uu.scene)==null?void 0:ja.base)??null,previewReady:!0}}),written:l$t,view:(Lr,ti)=>xXe(Lr,ti),playtest:azt,uiLayout:czt,turnEnded:nzt,build:async Lr=>{Lr.throwIfAborted(),await ft;const ti=await K.build(Qn.id,new Map(Qn.files));if(Lr.throwIfAborted(),!ti.ok)return{ok:!1,diagnostics:ti.diagnostics,mobilePreview:N.status()};const Ga=await a$t();return Lr.throwIfAborted(),{ok:!0,diagnostics:ti.diagnostics,run:Ga,mobilePreview:N.status()}}}}}});function gt(){St.reset(),X==null||X(),X=null,pe!==null&&(pe.stop(),r.close(pe.id),xt.flush(pe.id),pe=null,fe=null)}async function Ue(Qn,Lr){return(pe==null?void 0:pe.id)===Qn?pe.files.get(Lr):r.read(Qn,Lr).catch(ti=>{if(!pI(ti))throw ti})}function qt(Qn,Lr,ti,Ga){const Xa=ft.then(async()=>{if(Ga==null||Ga.signal.throwIfAborted(),Ga!==void 0&&((pe==null?void 0:pe.id)!==Qn||!d$t(pe.files.get(Lr),Ga.expected)))throw new Error("This file changed. Read it again before writing.");await r.write(Qn,Lr,ti),xt.touched(Qn,Lr),(pe==null?void 0:pe.id)===Qn&&(pe.files.set(Lr,ti),pe.changed(Lr))});return ft=Xa.catch(Kc=>console.error("[editor] file write failed",Kc)),Xa}function Ve(Qn,Lr){const ti=ft.then(async()=>{const Ga=await r.remove(Qn,Lr);return Ga&&xt.touched(Qn,Lr),Ga&&(pe==null?void 0:pe.id)===Qn&&pe.files.delete(Lr)&&pe.changed(Lr),Ga});return ft=ti.catch(Ga=>console.error("[editor] file removal failed",Ga)),ti}function Re(Qn){const Lr=Tt();if(Lr.id!==Qn)throw new Error("that scene is not the one open");return{files:()=>Lr.files,write:(ti,Ga)=>qt(Qn,ti,Ga),remove:async ti=>{await Ve(Qn,ti)}}}async function $t(Qn){var Ga;const Lr=M1(await Ue(Qn,"scene.json").catch(()=>{})),ti=(((Ga=Lr==null?void 0:Lr.display)==null?void 0:Ga.title)??"").replace(/[\x00-\x1f\x7f]/g,"").replace(new RegExp(tWt.source,"g"),"").trim().slice(0,LTr);return ti===""?Qn:ti}async function vt(Qn,Lr){const ti=(await r.list()).find(Xa=>Xa.id===Qn);if(ti===void 0)return null;const Ga=await r.duplicate(Qn,`${ti.name} ${Lr}`,xt.remoteIds());return await tn(Ga.id,Xa=>{var Kc;return{...Xa,display:{...Xa.display??{},title:`${((Kc=Xa.display)==null?void 0:Kc.title)||ti.name} ${Lr}`}}}),Ga.id}const xt=Xwr({store:r,session:()=>{const Qn=l();return s===null||Qn===null?null:{api:s,wallet:Qn}},account:()=>s===null?"unavailable":l()===null?"guest":"on",hash:Axe,title:$t,duplicate:async Qn=>{const Lr=await vt(Qn,QOt(new Date));if(Lr===null)throw new Error("The scene is no longer on this device");return Lr}});let ut=!1,Nt=0;async function Ut(){const Qn=++Nt,Lr=l()!==null&&(await St.shell.aiProviders()).some(ti=>ti.available);Qn!==Nt||Lr===ut||(ut=Lr,G0())}Ut();let Wt=l();const Me=setInterval(()=>{const Qn=l();Qn!==Wt&&(Wt=Qn,St.reset(),G0(),Ut(),xt.refresh(!0),Ce(fe).catch(Lr=>console.warn("[editor] could not clear the previews",Lr)))},MTr),Ke=()=>{document.visibilityState==="hidden"&&xt.flush()};document.addEventListener("visibilitychange",Ke);const st=new Set;async function tn(Qn,Lr){const ti=M1(await Ue(Qn,"scene.json"));if(ti===null)throw new Error("scene.json is missing or is not valid JSON");await qt(Qn,"scene.json",tOt(Lr(ti)))}async function An(Qn,Lr){if(Lr==null||Lr==="")return null;const ti=await Ue(Qn,Lr).catch(()=>{});return ti===void 0||ti.length>NTr?null:nOt(Lr,ti)}async function un(Qn,Lr=xt.status().projects){var Ga,Xa,Kc,uu;const ti=M1(await Ue(Qn.id,"scene.json").catch(()=>{}));return{sync:Lr[Qn.id],path:Qn.id,name:Qn.name,title:((Ga=ti==null?void 0:ti.display)==null?void 0:Ga.title)||Qn.name,world:((Xa=ti==null?void 0:ti.worldConfiguration)==null?void 0:Xa.name)||null,parcels:Array.isArray((Kc=ti==null?void 0:ti.scene)==null?void 0:Kc.parcels)?ti.scene.parcels.length:0,thumbnail:await An(Qn.id,(uu=ti==null?void 0:ti.display)==null?void 0:uu.navmapThumbnail),favourite:Qn.favourite,lastOpened:Qn.lastOpened,published:Qn.published,deletedAt:Qn.deletedAt??void 0}}async function Tn(Qn,Lr){var Ga,Xa;gt(),f.length=0,F({type:"sessionStarted"});const ti=Kc=>{if(gt(),Lr===qe){C(`✖ ${Kc}`);for(const uu of T)uu(Kc)}};try{if(await xt.prepareOpen(Qn,(ii,yl)=>C(`Downloading from your account… ${ii}/${yl}`)),Lr!==qe)return;if(!await r.open(Qn)){ti("This scene is open in another tab. Close it there to edit it here.");return}const Kc=await r.readAll(Qn).then(async ii=>{for(const[yl,ja]of W1r(ii))await qt(Qn,yl,ja),ii.set(yl,ja);return ii}).catch(ii=>{throw r.close(Qn),ii});if(Lr!==qe){r.close(Qn);return}const uu=await he(Qn);if(Lr!==qe){r.close(Qn);return}const lr=K.open(Qn,Kc,uu);pe=lr;const Pl=K.realmUrl(uu);if(fe=Pl,C(`▶ Opening ${((Xa=(Ga=M1(lr.files.get("scene.json")))==null?void 0:Ga.display)==null?void 0:Xa.title)||Qn}`),!await lr.start()&&!await lr.published()){if(Lr!==qe)return;C("✖ The scene did not build.");for(const ii of T)ii("The scene did not build.");return}if(await r.patch(Qn,{lastOpened:Date.now()}),Lr!==qe){gt();return}const fm=M1(lr.files.get("scene.json"))??{};te=t9e(fm,Pl),X=wTr(ii=>t.engineConsole(ii),C);for(const ii of x)ii(te)}catch(Kc){ti(jTr(Kc))}}function fi(Qn){N.close(),te=null;const Lr=++qe,ti=St.reset(),Ga=wt.then(async()=>{await ti,await ft,Lr===qe&&await Qn(Lr)});return wt=Ga.catch(Xa=>console.error("[editor] project transition failed",Xa)),Ga}function Tt(){if(pe===null)throw new Error("no project is open");return pe}const Wi={saveFile:async({path:Qn,content:Lr})=>qt(Tt().id,Qn,Lr),getFile:async({path:Qn})=>{const Lr=Tt().files.get(Qn)??GSr(Qn);if(Lr===void 0)throw new Error(`no such file: ${Qn}`);return{content:Lr}},removeFiles:async({filePaths:Qn})=>{const Lr=Tt(),ti=[],Ga=[];for(const Xa of Qn)(await Ve(Lr.id,Xa).catch(()=>!1)?ti:Ga).push(Xa);return{success:ti,failed:Ga}},getFilesSizes:async({path:Qn,ignore:Lr})=>{const ti=Qn===""?"":`${Qn.replace(/\/+$/,"")}/`;return{files:[...Tt().files.keys()].filter(Xa=>Xa.startsWith(ti)&&!Xa.split("/").some(Kc=>Lr.includes(Kc))).sort().map(Xa=>({path:Xa}))}}},Er={async find(Qn){return(await r.list()).some(Lr=>Lr.id===Qn)?!0:(await xt.refresh(!0),xt.remoteOnly().some(Lr=>Lr.id===Qn))},files:async Qn=>(pe==null?void 0:pe.id)===Qn?new Map(pe.files):r.readAll(Qn),manifest:Qn=>xt.manifest(Qn),build:async(Qn,Lr)=>K.build(Qn,await Er.files(Qn),Lr),dependencies:async Qn=>XVt(await Ue(Qn,"package.json")),onImported:Qn=>(st.add(Qn),()=>st.delete(Qn))},lo=a===null?null:Fwr({host:a,setWorld:async(Qn,Lr)=>{var Ga,Xa;((Xa=(Ga=M1(await Ue(Qn,"scene.json")))==null?void 0:Ga.worldConfiguration)==null?void 0:Xa.name)!==Lr&&await tn(Qn,Kc=>({...Kc,worldConfiguration:{...Kc.worldConfiguration??{},name:Lr}}))},files:Qn=>Er.files(Qn),build:(Qn,Lr)=>K.build(Qn,Lr,{production:!0}),published:(Qn,Lr)=>r.patch(Qn,{published:Lr})}),Ba=(a==null?void 0:a.services.projects)==null?null:OTr(Hwr(a.services.projects,(Qn,Lr)=>a.signedFetch(Qn,Lr)),Axe);cdr(rwr(t.editorBase)),iwr(t.editorBase),f$t({material:awr,sound:swr}),Bdr(async()=>ITr(await Er.files(Tt().id)));const zo=tTr({builtin:fSr(t.editorBase,gB("prefabs/catalog.json"),mTe),user:()=>Ba!==null&&l()!==null?Ba.tree:null}),Zc={...(a==null?void 0:a.services.projects)==null?{}:{...St.shell,aiOffered:()=>ut,aiTranscript:()=>{const Qn=Wt;if(Qn===null||pe===null)return null;const Lr=pe.id;return{owner:`${Lr}@${Qn.toLowerCase()}`,load:()=>r.transcript(Lr,Qn),save:ti=>r.setTranscript(Lr,Qn,ti)}}},pickProject:async()=>{},openProject:Qn=>fi(Lr=>Tn(Qn,Lr)),relaunchProject:Qn=>fi(Lr=>Tn(Qn,Lr)),closeProject:()=>fi(async()=>{gt(),F({type:"sessionStarted"}),C("■ Scene closed"),await Ce(null).catch(Qn=>console.warn("[editor] could not clear the previews",Qn))}),getState:async()=>{const Qn=await r.list(),Lr=xt.status().projects,ti=xt.remoteOnly().map(Ga=>({path:Ga.id,name:Ga.name,title:Ga.name,world:null,parcels:0,thumbnail:null,remoteOnly:!0}));return{recentProjects:[...Qn].sort((Ga,Xa)=>Xa.lastOpened-Ga.lastOpened).map(Ga=>Ga.id),projects:[...await Promise.all(Qn.map(Ga=>un(Ga,Lr))),...ti],logs:[...f],bevyWebDir:"",editorSceneDir:"",webPort:0,scenePort:0,editorScenePort:0,favourites:Qn.filter(Ga=>Ga.favourite).map(Ga=>Ga.id)}},onStackLog:Qn=>{m.push(Qn)},onBuildEvent:Qn=>{_.push(Qn)},onServersReady:Qn=>{x.push(Qn)},requestReady:async()=>te,phonePreview:async Qn=>te===null?{ok:!1,reason:"no-scene"}:N.open(te.realm,te.position,Qn),phonePreviewState:N.state,onPhonePreviewState:N.subscribe,closePhonePreview:N.close,capturePhonePreview:N.capture,onServersError:Qn=>{T.push(Qn)},toggleFavourite:async Qn=>{const Lr=(await r.list()).find(ti=>ti.id===Qn);Lr!==void 0&&await r.patch(Qn,{favourite:!Lr.favourite})},deleteProject:async Qn=>{const Lr=await r.trash(Qn);return Lr&&xt.trashed(Qn),Lr},trashedProjects:async()=>Promise.all((await r.trashed()).map(Qn=>un(Qn))),restoreProject:async Qn=>{const Lr=await r.restore(Qn);return Lr&&xt.restored(Qn),Lr},syncStatus:async()=>(xt.refresh(),xt.status()),onSyncStatus:Qn=>xt.subscribe(Qn),resolveSyncConflict:(Qn,Lr)=>xt.resolve(Qn,Lr),exportProject:async Qn=>lSr(await $t(Qn),await Er.files(Qn)),importProject:async Qn=>{const Lr=await dSr(Qn,async(ti,Ga)=>{const Xa=await r.create(ti,Ga,{taken:xt.remoteIds()});return xt.touched(Xa.id,"scene.json"),Xa.id});if((Lr==null?void 0:Lr.ok)===!0){const{id:ti,needsPackages:Ga}=Lr.report;Object.keys(Ga).length>0&&r.readAll(ti).then(Xa=>K.install(ti,Xa)).catch(Xa=>console.warn("[editor] could not install the packages of",ti,Xa));for(const Xa of st)Xa(Lr.report)}return Lr},projectPackages:async Qn=>B.get(Qn)??null,onProjectPackages:Qn=>(H.add(Qn),()=>H.delete(Qn)),...lo===null||a===null?{}:{publishScene:(Qn,Lr,ti)=>lo.publish(Qn,Lr,ti),publishStop:async()=>lo.stop(),publishWorlds:async()=>{const Qn=l();return Qn===null?[]:Rwr(Qn,a.services.worldsContent.replace(/\/+$/,""))}},canImportFolder:cSr(),renameProject:(Qn,Lr)=>tn(Qn,ti=>({...ti,display:{...ti.display??{},title:Lr.trim()}})),duplicateProject:Qn=>vt(Qn,"copy"),sceneTemplates:async()=>VSr(),createScene:async(Qn,Lr,ti)=>{const Ga=pWt(ti),Xa=M1(Ga.get("scene.json"));if(Xa===null)throw new Error(`template not found: ${ti}`);Ga.set("scene.json",tOt({...Xa,display:{...Xa.display??{},title:Lr.trim()}}));const Kc=await r.create(Lr,Ga,{taken:xt.remoteIds()});return xt.touched(Kc.id,"scene.json"),Kc.id},openExternal:async Qn=>{/^https?:$/.test(new URL(Qn).protocol)&&window.open(Qn,"_blank","noopener,noreferrer")},compositeEntityIds:async Qn=>{for(const Lr of dwr){const ti=await Ue(Qn,Lr);if(ti!==void 0)return fwr(new TextDecoder().decode(ti))}return[]},sceneSettings:async Qn=>{const Lr=M1(await Ue(Qn,"scene.json"));if(Lr===null)throw new Error("scene.json is missing or is not valid JSON");const ti=owr(Lr);return{...ti,thumbnail:await An(Qn,ti.thumbnailPath)}},saveSceneSettings:async(Qn,Lr)=>{const ti=cwr(Lr);return ti!==null?ti:(await tn(Qn,Ga=>lwr(Ga,Lr)),null)},pickSceneThumbnail:async Qn=>{const Lr=await fWt(Object.values(kWe).join(","));if(Lr===null)return null;const ti=QVt(Lr.name);if(kWe[ti]===void 0)throw new Error("not a supported image (png, jpg, gif, webp)");const Ga=`${RTr}/scene-thumbnail${ti}`,Xa=new Uint8Array(await Lr.arrayBuffer());return await qt(Qn,Ga,Xa),{path:Ga,dataUrl:nOt(Ga,Xa)}},appVersion:async()=>Yxr,prefabLibraryList:()=>zo.list(),prefabLibraryCopyIn:async(Qn,Lr)=>zo.copyIn(Qn,Re(Lr)),prefabLibraryUpdateCopy:async(Qn,Lr)=>zo.updateCopy(Qn,Re(Lr)),prefabUserLibrary:()=>Ba===null?"unavailable":l()===null?"guest":"on",...Ba===null?{}:{prefabLibraryCopyOut:async(Qn,Lr)=>{if(l()===null)throw new Error(FTr);return Ba.copyOut(Re(Qn),Lr)},prefabLibraryDelete:async Qn=>{const Lr=mWt(Qn);return(Lr==null?void 0:Lr.scope)==="user"&&l()!==null?Ba.remove(Lr.name):!1}}};async function Hl(){const Qn=new Set;for(const Lr of[...await r.list(),...await r.trashed()]){const ti=BVt(await Ue(Lr.id,I3).catch(()=>{}));for(const Ga of Object.keys((ti==null?void 0:ti.packages)??{}))Qn.add(Ga);for(const[Ga,Xa]of Object.entries((ti==null?void 0:ti.dependencies)??{}))Qn.add(Wj(Ga,Xa))}for(const Lr of await r.packages.keys())Qn.has(Lr)||await r.packages.remove(Lr)}return r.purge(Date.now()-DTr).then(async Qn=>{const Lr=await caches.open(Ixe),ti=Qn.map(({id:Xa,previewId:Kc})=>K.realmUrl(Kc??Xa));for(const Xa of await Lr.keys())ti.some(Kc=>Xa.url.startsWith(Kc))&&await Lr.delete(Xa);const Ga=await caches.open(Jxr);for(const Xa of ti)await Ga.delete(`${Xa}__storage`);Qn.length>0&&await Hl()}).catch(Qn=>console.warn("[editor] could not empty the trash",Qn)),{shell:Zc,projects:Er,dataLayer:Wi,dispose:()=>{N.dispose(),St.dispose(),qe++,gt(),K.dispose(),clearInterval(Me),document.removeEventListener("visibilitychange",Ke),xt.flush().finally(()=>xt.dispose())}}};let qj=null,xG=null,ere=null,MOt=!1;function UTr(){if(qj!==null)return qj;const t=window.__dclEditorHost;if(t===void 0||t.version!==0&&t.version!==1)return console.error("[editor] window.__dclEditorHost (contract v0 or v1) is missing: nothing to mount into"),null;console.log("[editor] web build 2026-10-27T22:50:46.794Z"),KOt(t),jIt(a=>t.engineConsole(a)),H3t(()=>t.identity()),SGn.needed=!1;const n=BTr({host:t,sceneCompiler:nwr(t.editorBase)});window.editorShell=$Tr(n.shell,t),pDt(n.dataLayer??null),NGe();const r=document.createElement("link");return r.rel="stylesheet",r.href=new URL("editor.css",t.editorBase).href,r.integrity=gB("editor.css"),r.crossOrigin="anonymous",r.onerror=()=>console.error("[editor] editor.css did not load or does not match the hash this editor was published with: its fonts are not applied"),document.head.appendChild(r),AE.project=null,AE.notice=null,qj={host:t,web:n,fonts:r},qj}function Mxe(){const t=xG;xG=null,t==null||t.unmount()}function $Tr(t,n){const{createScene:r,importProject:a,duplicateProject:s}=t;return{...t,...r===void 0?{}:{createScene:async(l,f,m)=>{const _=await r(l,f,m);return _!==null&&Xx("project_created",{project_id:_,source:"template",template:m}),_}},...a===void 0?{}:{importProject:async l=>{const f=await a(l);return(f==null?void 0:f.ok)===!0&&Xx("project_created",{project_id:f.report.id,source:"import",import_kind:l}),f}},...s===void 0?{}:{duplicateProject:async l=>{const f=await s(l);return f!==null&&Xx("project_created",{project_id:f,source:"duplicate",from_project_id:l}),f}},openProject:async l=>{const f=xG;Mxe(),f==null||f.api.close(),ere??(ere=qFt(n.container,O.jsx(C1r,{}))),n.setMode("edit"),AE.project=l,AE.opens++,await t.openProject(l),Xx("project_opened")}}}function zTr(t,n){var m;const r=UTr();if(r===null)return()=>{};Mxe();const a=document.createElement("div");a.style.cssText="position:relative;width:100%;height:100%",rGn(a),t.appendChild(a);const s=qFt(a,O.jsx(sGn,{}),"eui-create-root"),l={api:n,unmount:()=>{s(),a.remove()}};xG=l;const f=MOt?null:((m=kk(r.host))==null?void 0:m.openProject)??null;return MOt=!0,Xx("editor_opened",{deep_link:f!==null}),f!==null&&r.web.projects.find(f).catch(()=>!1).then(_=>{var x;xG===l&&(_?(x=window.editorShell)==null||x.openProject(f):AE.notice=`“${f}” is not on this device or on your account. Here are your scenes.`)}),()=>{xG===l&&Mxe()}}function VTr(){Mxe();const t=qj;if(t===null)return;qj=null;const n=KA();ere==null||ere(),ere=null,t.fonts.remove(),AE.project=null,delete window.editorShell,H3t(null),jIt(null),KOt(null),t.host.setMode("off"),n.finally(()=>{var r,a;(a=(r=t.web).dispose)==null||a.call(r),qj===null&&pDt(null)})}window.__dclEditor={mountHome:zTr,unmount:VTr};
|
|
35767
|
+
`;F.set("data.json",new TextEncoder().encode(K));const te=RWe(hWt(H,T)).slice(0,ETr).replace(/_+$/,"")||"prefab",pe=new Set((await t.list()).map(X=>X.name));let fe=1;for(let X=0;X<CTr;X++){let he=te;for(;pe.has(he);)he=`${te}_${++fe}`;try{return await f(he,F),{ref:`user:${he}`,scope:"user",data:K}}catch(Ce){if(!(Ce instanceof rWt))throw Ce;pe.add(he)}}throw new Error("could not find a free name in your library — try again")},remove:m=>t.remove(m)}}const DOt=new WeakMap;function PTr(t){let n=DOt.get(t);return n===void 0&&(n=crypto.subtle.digest("SHA-256",new Uint8Array(t)).then(r=>[...new Uint8Array(r)].map(a=>a.toString(16).padStart(2,"0")).join("")),DOt.set(t,n)),n}async function ITr(t){const n=t.get(".dclignore"),r=$Xe(t.keys(),n===void 0?void 0:new TextDecoder().decode(n)).filter(l=>l!==I3),a=new Map;let s=0;for(const l of r){const f=t.get(l);f!==void 0&&(a.set(await PTr(f),f.byteLength),s++)}return{bytes:[...a.values()].reduce((l,f)=>l+f,0),files:s}}const ROt=4e3,NTr=4e6,DTr=YOt*24*60*60*1e3,RTr="assets/images",MTr=3e3,LTr=100,FTr="Sign in to keep prefabs in your own library. The built-in prefabs work without it.",jTr=t=>t instanceof Error?t.message:String(t);function t9e(t,n){var r,a,s;return{realm:n.replace(/\/$/,""),systemScene:"",position:((r=t.scene)==null?void 0:r.base)??((s=(a=t.scene)==null?void 0:a.parcels)==null?void 0:s[0])??"0,0",spawn:uwr(t),spawnPoints:JSON.stringify(Array.isArray(t.spawnPoints)?t.spawnPoints:[])}}const BTr=({host:t,sceneCompiler:n})=>{const r=new Wwr(jwr()),a=kk(t),s=a===null||a.services.projects===null?null:nWt(a.services.projects,(Qn,Lr)=>a.signedFetch(Qn,Lr)),l=()=>{const{address:Qn,isGuest:Lr}=t.identity();return Lr||Qn===null?null:Qn.toLowerCase()},f=[],m=[],_=[],x=[],T=[],C=Qn=>{f.push(Qn),f.length>ROt&&f.splice(0,f.length-ROt);for(const Lr of m)Lr(Qn)},N=_Tr(mTr(t.pageDir,(a==null?void 0:a.services.projects)??null),he,async Qn=>IOt(await Z,l()??"guest",Qn),hTr((a==null?void 0:a.services.worldsContent)??null)),F=Qn=>{for(const Lr of _)Lr(Qn);Qn.type==="bundleSaved"&&pe!==null&&N.built(pe.id).catch(Lr=>console.error("[editor] mobile preview reload failed",Lr))},B=new Map,H=new Set,Z=B3t.then(sTr),K=uTr({pageDir:t.pageDir,urls:n,machineId:async Qn=>IOt(await Z,l()??"guest",Qn),emit:F,log:C,packages:r.packages,saveLock:async(Qn,Lr)=>{await r.write(Qn,I3,Lr),xt.touched(Qn,I3),(pe==null?void 0:pe.id)===Qn&&pe.files.set(I3,Lr)},onPackages:(Qn,Lr)=>{if(Lr===null){B.delete(Qn);return}B.set(Qn,Lr);for(const ti of H)ti(Qn,Lr)}});let te=null,pe=null,fe=null,X=null;async function he(Qn){var Ga;const Lr=(Ga=(await r.list()).find(Xa=>Xa.id===Qn))==null?void 0:Ga.previewId;if(Lr!==void 0)return Lr;const ti="p"+Array.from(crypto.getRandomValues(new Uint8Array(16)),Xa=>Xa.toString(16).padStart(2,"0")).join("");return await r.patch(Qn,{previewId:ti}),ti}async function Ce(Qn){const Lr=new URL("preview/",t.pageDir).href,ti=await caches.open(Ixe);for(const Ga of await ti.keys())Ga.url.startsWith(Lr)&&(Qn===null||!Ga.url.startsWith(Qn))&&await ti.delete(Ga)}let qe=0,wt=Promise.resolve(),ft=Promise.resolve();const St=Kxr({service:(a==null?void 0:a.services.projects)??null,fetch:(Qn,Lr)=>a===null?Promise.reject(new Error("The assistant service is not configured.")):a.signedFetch(Qn,Lr),wallet:l,mobilePreview:N.status,memory:{read:async(Qn,Lr)=>{const ti=await r.assistantMemory(Qn,Lr);return dl(ti)&&typeof ti.id=="string"&&typeof ti.key=="string"?{id:ti.id,key:ti.key}:null},write:(Qn,Lr,ti)=>r.setAssistantMemory(Qn,Lr,ti)},project:()=>{const Qn=Tt();return{id:Qn.id,tools:{files:()=>Qn.files,write:(Lr,ti,Ga,Xa)=>qt(Qn.id,Lr,ti,{expected:Ga,signal:Xa}),assets:s$t({files:()=>Qn.files}),scene:(Lr,ti)=>sTe(Lr,ti,async Ga=>{var ii,yl,ja;const Xa=ss=>{var Ts,Zs;return JSON.stringify([(Ts=ss==null?void 0:ss.scene)==null?void 0:Ts.parcels,(Zs=ss==null?void 0:ss.scene)==null?void 0:Zs.base])};await KA();const Kc=Xa(M1(await Ue(Qn.id,"scene.json")));await tn(Qn.id,ss=>mwr(ss,Ga));const uu=M1(await Ue(Qn.id,"scene.json")),lr=Xa(uu)!==Kc,Pl=((ii=uu==null?void 0:uu.scene)==null?void 0:ii.parcels)??[],fm=(yl=nt.scene)==null?void 0:yl.parcels.map(ss=>`${ss.x},${ss.y}`).sort().join(";");if(lr||fm!==[...Pl].sort().join(";")){if(!await Qn.flush())throw new Error("The scene did not build. Fix the code and retry sceneSettings to load the new parcels.");ti.throwIfAborted();const ss=await he(Qn.id);te=t9e(uu??{},K.realmUrl(ss)),await STr(Pl,()=>{for(const Ts of x)Ts(te)},ti)}else if(te!==null){const ss=t9e(uu??{},te.realm);(ss.spawn!==te.spawn||ss.spawnPoints!==te.spawnPoints)&&(te={...te,spawn:ss.spawn,spawnPoints:ss.spawnPoints},lur(ss.spawn,ss.spawnPoints))}return{requiredPermissions:(uu==null?void 0:uu.requiredPermissions)??[],spawnPoints:(uu==null?void 0:uu.spawnPoints)??[],parcels:Pl,base:((ja=uu==null?void 0:uu.scene)==null?void 0:ja.base)??null,previewReady:!0}}),written:l$t,view:(Lr,ti)=>xXe(Lr,ti),playtest:azt,uiLayout:czt,turnEnded:nzt,build:async Lr=>{Lr.throwIfAborted(),await ft;const ti=await K.build(Qn.id,new Map(Qn.files));if(Lr.throwIfAborted(),!ti.ok)return{ok:!1,diagnostics:ti.diagnostics,mobilePreview:N.status()};const Ga=await a$t();return Lr.throwIfAborted(),{ok:!0,diagnostics:ti.diagnostics,run:Ga,mobilePreview:N.status()}}}}}});function gt(){St.reset(),X==null||X(),X=null,pe!==null&&(pe.stop(),r.close(pe.id),xt.flush(pe.id),pe=null,fe=null)}async function Ue(Qn,Lr){return(pe==null?void 0:pe.id)===Qn?pe.files.get(Lr):r.read(Qn,Lr).catch(ti=>{if(!pI(ti))throw ti})}function qt(Qn,Lr,ti,Ga){const Xa=ft.then(async()=>{if(Ga==null||Ga.signal.throwIfAborted(),Ga!==void 0&&((pe==null?void 0:pe.id)!==Qn||!d$t(pe.files.get(Lr),Ga.expected)))throw new Error("This file changed. Read it again before writing.");await r.write(Qn,Lr,ti),xt.touched(Qn,Lr),(pe==null?void 0:pe.id)===Qn&&(pe.files.set(Lr,ti),pe.changed(Lr))});return ft=Xa.catch(Kc=>console.error("[editor] file write failed",Kc)),Xa}function Ve(Qn,Lr){const ti=ft.then(async()=>{const Ga=await r.remove(Qn,Lr);return Ga&&xt.touched(Qn,Lr),Ga&&(pe==null?void 0:pe.id)===Qn&&pe.files.delete(Lr)&&pe.changed(Lr),Ga});return ft=ti.catch(Ga=>console.error("[editor] file removal failed",Ga)),ti}function Re(Qn){const Lr=Tt();if(Lr.id!==Qn)throw new Error("that scene is not the one open");return{files:()=>Lr.files,write:(ti,Ga)=>qt(Qn,ti,Ga),remove:async ti=>{await Ve(Qn,ti)}}}async function $t(Qn){var Ga;const Lr=M1(await Ue(Qn,"scene.json").catch(()=>{})),ti=(((Ga=Lr==null?void 0:Lr.display)==null?void 0:Ga.title)??"").replace(/[\x00-\x1f\x7f]/g,"").replace(new RegExp(tWt.source,"g"),"").trim().slice(0,LTr);return ti===""?Qn:ti}async function vt(Qn,Lr){const ti=(await r.list()).find(Xa=>Xa.id===Qn);if(ti===void 0)return null;const Ga=await r.duplicate(Qn,`${ti.name} ${Lr}`,xt.remoteIds());return await tn(Ga.id,Xa=>{var Kc;return{...Xa,display:{...Xa.display??{},title:`${((Kc=Xa.display)==null?void 0:Kc.title)||ti.name} ${Lr}`}}}),Ga.id}const xt=Xwr({store:r,session:()=>{const Qn=l();return s===null||Qn===null?null:{api:s,wallet:Qn}},account:()=>s===null?"unavailable":l()===null?"guest":"on",hash:Axe,title:$t,duplicate:async Qn=>{const Lr=await vt(Qn,QOt(new Date));if(Lr===null)throw new Error("The scene is no longer on this device");return Lr}});let ut=!1,Nt=0;async function Ut(){const Qn=++Nt,Lr=l()!==null&&(await St.shell.aiProviders()).some(ti=>ti.available);Qn!==Nt||Lr===ut||(ut=Lr,G0())}Ut();let Wt=l();const Me=setInterval(()=>{const Qn=l();Qn!==Wt&&(Wt=Qn,St.reset(),G0(),Ut(),xt.refresh(!0),Ce(fe).catch(Lr=>console.warn("[editor] could not clear the previews",Lr)))},MTr),Ke=()=>{document.visibilityState==="hidden"&&xt.flush()};document.addEventListener("visibilitychange",Ke);const st=new Set;async function tn(Qn,Lr){const ti=M1(await Ue(Qn,"scene.json"));if(ti===null)throw new Error("scene.json is missing or is not valid JSON");await qt(Qn,"scene.json",tOt(Lr(ti)))}async function An(Qn,Lr){if(Lr==null||Lr==="")return null;const ti=await Ue(Qn,Lr).catch(()=>{});return ti===void 0||ti.length>NTr?null:nOt(Lr,ti)}async function un(Qn,Lr=xt.status().projects){var Ga,Xa,Kc,uu;const ti=M1(await Ue(Qn.id,"scene.json").catch(()=>{}));return{sync:Lr[Qn.id],path:Qn.id,name:Qn.name,title:((Ga=ti==null?void 0:ti.display)==null?void 0:Ga.title)||Qn.name,world:((Xa=ti==null?void 0:ti.worldConfiguration)==null?void 0:Xa.name)||null,parcels:Array.isArray((Kc=ti==null?void 0:ti.scene)==null?void 0:Kc.parcels)?ti.scene.parcels.length:0,thumbnail:await An(Qn.id,(uu=ti==null?void 0:ti.display)==null?void 0:uu.navmapThumbnail),favourite:Qn.favourite,lastOpened:Qn.lastOpened,published:Qn.published,deletedAt:Qn.deletedAt??void 0}}async function Tn(Qn,Lr){var Ga,Xa;gt(),f.length=0,F({type:"sessionStarted"});const ti=Kc=>{if(gt(),Lr===qe){C(`✖ ${Kc}`);for(const uu of T)uu(Kc)}};try{if(await xt.prepareOpen(Qn,(ii,yl)=>C(`Downloading from your account… ${ii}/${yl}`)),Lr!==qe)return;if(!await r.open(Qn)){ti("This scene is open in another tab. Close it there to edit it here.");return}const Kc=await r.readAll(Qn).then(async ii=>{for(const[yl,ja]of W1r(ii))await qt(Qn,yl,ja),ii.set(yl,ja);return ii}).catch(ii=>{throw r.close(Qn),ii});if(Lr!==qe){r.close(Qn);return}const uu=await he(Qn);if(Lr!==qe){r.close(Qn);return}const lr=K.open(Qn,Kc,uu);pe=lr;const Pl=K.realmUrl(uu);if(fe=Pl,C(`▶ Opening ${((Xa=(Ga=M1(lr.files.get("scene.json")))==null?void 0:Ga.display)==null?void 0:Xa.title)||Qn}`),!await lr.start()&&!await lr.published()){if(Lr!==qe)return;C("✖ The scene did not build.");for(const ii of T)ii("The scene did not build.");return}if(await r.patch(Qn,{lastOpened:Date.now()}),Lr!==qe){gt();return}const fm=M1(lr.files.get("scene.json"))??{};te=t9e(fm,Pl),X=wTr(ii=>t.engineConsole(ii),C);for(const ii of x)ii(te)}catch(Kc){ti(jTr(Kc))}}function fi(Qn){N.close(),te=null;const Lr=++qe,ti=St.reset(),Ga=wt.then(async()=>{await ti,await ft,Lr===qe&&await Qn(Lr)});return wt=Ga.catch(Xa=>console.error("[editor] project transition failed",Xa)),Ga}function Tt(){if(pe===null)throw new Error("no project is open");return pe}const Wi={saveFile:async({path:Qn,content:Lr})=>qt(Tt().id,Qn,Lr),getFile:async({path:Qn})=>{const Lr=Tt().files.get(Qn)??GSr(Qn);if(Lr===void 0)throw new Error(`no such file: ${Qn}`);return{content:Lr}},removeFiles:async({filePaths:Qn})=>{const Lr=Tt(),ti=[],Ga=[];for(const Xa of Qn)(await Ve(Lr.id,Xa).catch(()=>!1)?ti:Ga).push(Xa);return{success:ti,failed:Ga}},getFilesSizes:async({path:Qn,ignore:Lr})=>{const ti=Qn===""?"":`${Qn.replace(/\/+$/,"")}/`;return{files:[...Tt().files.keys()].filter(Xa=>Xa.startsWith(ti)&&!Xa.split("/").some(Kc=>Lr.includes(Kc))).sort().map(Xa=>({path:Xa}))}}},Er={async find(Qn){return(await r.list()).some(Lr=>Lr.id===Qn)?!0:(await xt.refresh(!0),xt.remoteOnly().some(Lr=>Lr.id===Qn))},files:async Qn=>(pe==null?void 0:pe.id)===Qn?new Map(pe.files):r.readAll(Qn),manifest:Qn=>xt.manifest(Qn),build:async(Qn,Lr)=>K.build(Qn,await Er.files(Qn),Lr),dependencies:async Qn=>XVt(await Ue(Qn,"package.json")),onImported:Qn=>(st.add(Qn),()=>st.delete(Qn))},lo=a===null?null:Fwr({host:a,setWorld:async(Qn,Lr)=>{var Ga,Xa;((Xa=(Ga=M1(await Ue(Qn,"scene.json")))==null?void 0:Ga.worldConfiguration)==null?void 0:Xa.name)!==Lr&&await tn(Qn,Kc=>({...Kc,worldConfiguration:{...Kc.worldConfiguration??{},name:Lr}}))},files:Qn=>Er.files(Qn),build:(Qn,Lr)=>K.build(Qn,Lr,{production:!0}),published:(Qn,Lr)=>r.patch(Qn,{published:Lr})}),Ba=(a==null?void 0:a.services.projects)==null?null:OTr(Hwr(a.services.projects,(Qn,Lr)=>a.signedFetch(Qn,Lr)),Axe);cdr(rwr(t.editorBase)),iwr(t.editorBase),f$t({material:awr,sound:swr}),Bdr(async()=>ITr(await Er.files(Tt().id)));const zo=tTr({builtin:fSr(t.editorBase,gB("prefabs/catalog.json"),mTe),user:()=>Ba!==null&&l()!==null?Ba.tree:null}),Zc={...(a==null?void 0:a.services.projects)==null?{}:{...St.shell,aiOffered:()=>ut,aiTranscript:()=>{const Qn=Wt;if(Qn===null||pe===null)return null;const Lr=pe.id;return{owner:`${Lr}@${Qn.toLowerCase()}`,load:()=>r.transcript(Lr,Qn),save:ti=>r.setTranscript(Lr,Qn,ti)}}},pickProject:async()=>{},openProject:Qn=>fi(Lr=>Tn(Qn,Lr)),relaunchProject:Qn=>fi(Lr=>Tn(Qn,Lr)),closeProject:()=>fi(async()=>{gt(),F({type:"sessionStarted"}),C("■ Scene closed"),await Ce(null).catch(Qn=>console.warn("[editor] could not clear the previews",Qn))}),getState:async()=>{const Qn=await r.list(),Lr=xt.status().projects,ti=xt.remoteOnly().map(Ga=>({path:Ga.id,name:Ga.name,title:Ga.name,world:null,parcels:0,thumbnail:null,remoteOnly:!0}));return{recentProjects:[...Qn].sort((Ga,Xa)=>Xa.lastOpened-Ga.lastOpened).map(Ga=>Ga.id),projects:[...await Promise.all(Qn.map(Ga=>un(Ga,Lr))),...ti],logs:[...f],bevyWebDir:"",editorSceneDir:"",webPort:0,scenePort:0,editorScenePort:0,favourites:Qn.filter(Ga=>Ga.favourite).map(Ga=>Ga.id)}},onStackLog:Qn=>{m.push(Qn)},onBuildEvent:Qn=>{_.push(Qn)},onServersReady:Qn=>{x.push(Qn)},requestReady:async()=>te,phonePreview:async Qn=>te===null?{ok:!1,reason:"no-scene"}:N.open(te.realm,te.position,Qn),phonePreviewState:N.state,onPhonePreviewState:N.subscribe,closePhonePreview:N.close,capturePhonePreview:N.capture,onServersError:Qn=>{T.push(Qn)},toggleFavourite:async Qn=>{const Lr=(await r.list()).find(ti=>ti.id===Qn);Lr!==void 0&&await r.patch(Qn,{favourite:!Lr.favourite})},deleteProject:async Qn=>{const Lr=await r.trash(Qn);return Lr&&xt.trashed(Qn),Lr},trashedProjects:async()=>Promise.all((await r.trashed()).map(Qn=>un(Qn))),restoreProject:async Qn=>{const Lr=await r.restore(Qn);return Lr&&xt.restored(Qn),Lr},syncStatus:async()=>(xt.refresh(),xt.status()),onSyncStatus:Qn=>xt.subscribe(Qn),resolveSyncConflict:(Qn,Lr)=>xt.resolve(Qn,Lr),exportProject:async Qn=>lSr(await $t(Qn),await Er.files(Qn)),importProject:async Qn=>{const Lr=await dSr(Qn,async(ti,Ga)=>{const Xa=await r.create(ti,Ga,{taken:xt.remoteIds()});return xt.touched(Xa.id,"scene.json"),Xa.id});if((Lr==null?void 0:Lr.ok)===!0){const{id:ti,needsPackages:Ga}=Lr.report;Object.keys(Ga).length>0&&r.readAll(ti).then(Xa=>K.install(ti,Xa)).catch(Xa=>console.warn("[editor] could not install the packages of",ti,Xa));for(const Xa of st)Xa(Lr.report)}return Lr},projectPackages:async Qn=>B.get(Qn)??null,onProjectPackages:Qn=>(H.add(Qn),()=>H.delete(Qn)),...lo===null||a===null?{}:{publishScene:(Qn,Lr,ti)=>lo.publish(Qn,Lr,ti),publishStop:async()=>lo.stop(),publishWorlds:async()=>{const Qn=l();return Qn===null?[]:Rwr(Qn,a.services.worldsContent.replace(/\/+$/,""))}},canImportFolder:cSr(),renameProject:(Qn,Lr)=>tn(Qn,ti=>({...ti,display:{...ti.display??{},title:Lr.trim()}})),duplicateProject:Qn=>vt(Qn,"copy"),sceneTemplates:async()=>VSr(),createScene:async(Qn,Lr,ti)=>{const Ga=pWt(ti),Xa=M1(Ga.get("scene.json"));if(Xa===null)throw new Error(`template not found: ${ti}`);Ga.set("scene.json",tOt({...Xa,display:{...Xa.display??{},title:Lr.trim()}}));const Kc=await r.create(Lr,Ga,{taken:xt.remoteIds()});return xt.touched(Kc.id,"scene.json"),Kc.id},openExternal:async Qn=>{/^https?:$/.test(new URL(Qn).protocol)&&window.open(Qn,"_blank","noopener,noreferrer")},compositeEntityIds:async Qn=>{for(const Lr of dwr){const ti=await Ue(Qn,Lr);if(ti!==void 0)return fwr(new TextDecoder().decode(ti))}return[]},sceneSettings:async Qn=>{const Lr=M1(await Ue(Qn,"scene.json"));if(Lr===null)throw new Error("scene.json is missing or is not valid JSON");const ti=owr(Lr);return{...ti,thumbnail:await An(Qn,ti.thumbnailPath)}},saveSceneSettings:async(Qn,Lr)=>{const ti=cwr(Lr);return ti!==null?ti:(await tn(Qn,Ga=>lwr(Ga,Lr)),null)},pickSceneThumbnail:async Qn=>{const Lr=await fWt(Object.values(kWe).join(","));if(Lr===null)return null;const ti=QVt(Lr.name);if(kWe[ti]===void 0)throw new Error("not a supported image (png, jpg, gif, webp)");const Ga=`${RTr}/scene-thumbnail${ti}`,Xa=new Uint8Array(await Lr.arrayBuffer());return await qt(Qn,Ga,Xa),{path:Ga,dataUrl:nOt(Ga,Xa)}},appVersion:async()=>Yxr,prefabLibraryList:()=>zo.list(),prefabLibraryCopyIn:async(Qn,Lr)=>zo.copyIn(Qn,Re(Lr)),prefabLibraryUpdateCopy:async(Qn,Lr)=>zo.updateCopy(Qn,Re(Lr)),prefabUserLibrary:()=>Ba===null?"unavailable":l()===null?"guest":"on",...Ba===null?{}:{prefabLibraryCopyOut:async(Qn,Lr)=>{if(l()===null)throw new Error(FTr);return Ba.copyOut(Re(Qn),Lr)},prefabLibraryDelete:async Qn=>{const Lr=mWt(Qn);return(Lr==null?void 0:Lr.scope)==="user"&&l()!==null?Ba.remove(Lr.name):!1}}};async function Hl(){const Qn=new Set;for(const Lr of[...await r.list(),...await r.trashed()]){const ti=BVt(await Ue(Lr.id,I3).catch(()=>{}));for(const Ga of Object.keys((ti==null?void 0:ti.packages)??{}))Qn.add(Ga);for(const[Ga,Xa]of Object.entries((ti==null?void 0:ti.dependencies)??{}))Qn.add(Wj(Ga,Xa))}for(const Lr of await r.packages.keys())Qn.has(Lr)||await r.packages.remove(Lr)}return r.purge(Date.now()-DTr).then(async Qn=>{const Lr=await caches.open(Ixe),ti=Qn.map(({id:Xa,previewId:Kc})=>K.realmUrl(Kc??Xa));for(const Xa of await Lr.keys())ti.some(Kc=>Xa.url.startsWith(Kc))&&await Lr.delete(Xa);const Ga=await caches.open(Jxr);for(const Xa of ti)await Ga.delete(`${Xa}__storage`);Qn.length>0&&await Hl()}).catch(Qn=>console.warn("[editor] could not empty the trash",Qn)),{shell:Zc,projects:Er,dataLayer:Wi,dispose:()=>{N.dispose(),St.dispose(),qe++,gt(),K.dispose(),clearInterval(Me),document.removeEventListener("visibilitychange",Ke),xt.flush().finally(()=>xt.dispose())}}};let qj=null,xG=null,ere=null,MOt=!1;function UTr(){if(qj!==null)return qj;const t=window.__dclEditorHost;if(t===void 0||t.version!==0&&t.version!==1)return console.error("[editor] window.__dclEditorHost (contract v0 or v1) is missing: nothing to mount into"),null;console.log("[editor] web build 2026-10-28T00:32:19.307Z"),KOt(t),jIt(a=>t.engineConsole(a)),H3t(()=>t.identity()),SGn.needed=!1;const n=BTr({host:t,sceneCompiler:nwr(t.editorBase)});window.editorShell=$Tr(n.shell,t),pDt(n.dataLayer??null),NGe();const r=document.createElement("link");return r.rel="stylesheet",r.href=new URL("editor.css",t.editorBase).href,r.integrity=gB("editor.css"),r.crossOrigin="anonymous",r.onerror=()=>console.error("[editor] editor.css did not load or does not match the hash this editor was published with: its fonts are not applied"),document.head.appendChild(r),AE.project=null,AE.notice=null,qj={host:t,web:n,fonts:r},qj}function Mxe(){const t=xG;xG=null,t==null||t.unmount()}function $Tr(t,n){const{createScene:r,importProject:a,duplicateProject:s}=t;return{...t,...r===void 0?{}:{createScene:async(l,f,m)=>{const _=await r(l,f,m);return _!==null&&Xx("project_created",{project_id:_,source:"template",template:m}),_}},...a===void 0?{}:{importProject:async l=>{const f=await a(l);return(f==null?void 0:f.ok)===!0&&Xx("project_created",{project_id:f.report.id,source:"import",import_kind:l}),f}},...s===void 0?{}:{duplicateProject:async l=>{const f=await s(l);return f!==null&&Xx("project_created",{project_id:f,source:"duplicate",from_project_id:l}),f}},openProject:async l=>{const f=xG;Mxe(),f==null||f.api.close(),ere??(ere=qFt(n.container,O.jsx(C1r,{}))),n.setMode("edit"),AE.project=l,AE.opens++,await t.openProject(l),Xx("project_opened")}}}function zTr(t,n){var m;const r=UTr();if(r===null)return()=>{};Mxe();const a=document.createElement("div");a.style.cssText="position:relative;width:100%;height:100%",rGn(a),t.appendChild(a);const s=qFt(a,O.jsx(sGn,{}),"eui-create-root"),l={api:n,unmount:()=>{s(),a.remove()}};xG=l;const f=MOt?null:((m=kk(r.host))==null?void 0:m.openProject)??null;return MOt=!0,Xx("editor_opened",{deep_link:f!==null}),f!==null&&r.web.projects.find(f).catch(()=>!1).then(_=>{var x;xG===l&&(_?(x=window.editorShell)==null||x.openProject(f):AE.notice=`“${f}” is not on this device or on your account. Here are your scenes.`)}),()=>{xG===l&&Mxe()}}function VTr(){Mxe();const t=qj;if(t===null)return;qj=null;const n=KA();ere==null||ere(),ere=null,t.fonts.remove(),AE.project=null,delete window.editorShell,H3t(null),jIt(null),KOt(null),t.host.setMode("off"),n.finally(()=>{var r,a;(a=(r=t.web).dispose)==null||a.call(r),qj===null&&pDt(null)})}window.__dclEditor={mountHome:zTr,unmount:VTr};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcl-regenesislabs/web-editor",
|
|
3
|
-
"version": "0.3.16-
|
|
3
|
+
"version": "0.3.16-40609313304.commit-caa7bdd",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "The Decentraland scene editor for the web explorer: editor.js plus the files it loads beside it. Served by version, not installed.",
|
|
6
6
|
"repository": {
|
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
"url": "git+https://github.com/dcl-regenesislabs/web-editor.git",
|
|
9
9
|
"directory": "packages/web"
|
|
10
10
|
},
|
|
11
|
-
"commit": "
|
|
11
|
+
"commit": "caa7bddfa8328742d3bb89f2540c639d2be8ec39"
|
|
12
12
|
}
|