beyond-simulator-web 0.2.0 → 0.2.1
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/dist/public/play-renderer.js +1 -1
- package/dist/server.js +1 -1
- package/package.json +1 -1
|
@@ -922,7 +922,7 @@ fn mainFragment(
|
|
|
922
922
|
`),e.unshift(`
|
|
923
923
|
var stride = ${r};
|
|
924
924
|
`);let s=e.join(`
|
|
925
|
-
`);return new Function("ps","f32v","u32v",s)}var Ja=class{constructor(t){this._size=0,this._generateParticleUpdateCache={};let e=this._size=t.size??1e3,r=t.properties,s=0,n=0;for(let h in r){let u=r[h],d=Wt(u.format);u.dynamic?n+=d.stride:s+=d.stride}this._dynamicStride=n/4,this._staticStride=s/4,this.staticAttributeBuffer=new Ge(e*4*s),this.dynamicAttributeBuffer=new Ge(e*4*n),this.indexBuffer=Xu(e);let o=new Be,a=0,l=0;this._staticBuffer=new Ft({data:new Float32Array(1),label:"static-particle-buffer",shrinkToFit:!1,usage:it.VERTEX|it.COPY_DST}),this._dynamicBuffer=new Ft({data:new Float32Array(1),label:"dynamic-particle-buffer",shrinkToFit:!1,usage:it.VERTEX|it.COPY_DST});for(let h in r){let u=r[h],d=Wt(u.format);u.dynamic?(o.addAttribute(u.attributeName,{buffer:this._dynamicBuffer,stride:this._dynamicStride*4,offset:a*4,format:u.format}),a+=d.size):(o.addAttribute(u.attributeName,{buffer:this._staticBuffer,stride:this._staticStride*4,offset:l*4,format:u.format}),l+=d.size)}o.addIndex(this.indexBuffer);let c=this.getParticleUpdate(r);this._dynamicUpload=c.dynamicUpdate,this._staticUpload=c.staticUpdate,this.geometry=o}getParticleUpdate(t){let e=NE(t);return this._generateParticleUpdateCache[e]?this._generateParticleUpdateCache[e]:(this._generateParticleUpdateCache[e]=this.generateParticleUpdate(t),this._generateParticleUpdateCache[e])}generateParticleUpdate(t){return Y0(t)}update(t,e){t.length>this._size&&(e=!0,this._size=Math.max(t.length,this._size*1.5|0),this.staticAttributeBuffer=new Ge(this._size*this._staticStride*4*4),this.dynamicAttributeBuffer=new Ge(this._size*this._dynamicStride*4*4),this.indexBuffer=Xu(this._size),this.geometry.indexBuffer.setDataWithSize(this.indexBuffer,this.indexBuffer.byteLength,!0));let r=this.dynamicAttributeBuffer;if(this._dynamicUpload(t,r.float32View,r.uint32View),this._dynamicBuffer.setDataWithSize(this.dynamicAttributeBuffer.float32View,t.length*this._dynamicStride*4,!0),e){let s=this.staticAttributeBuffer;this._staticUpload(t,s.float32View,s.uint32View),this._staticBuffer.setDataWithSize(s.float32View,t.length*this._staticStride*4,!0)}}destroy(){this._staticBuffer.destroy(),this._dynamicBuffer.destroy(),this.geometry.destroy()}};function NE(i){let t=[];for(let e in i){let r=i[e];t.push(e,r.code,r.dynamic?"d":"s")}return t.join("_")}dt();et();rr();mt();rc();xe();Iu();fo();Za();Gt();H.add(_m,bm);function j0(i,t,e){if(i.fillType!=="Horizontal"&&i.fillType!=="Vertical")return null;let r=Number(i.fillAmount??1),s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1;if(i.fillType==="Horizontal"){let o=t*s;return{x:i.fillHorizontalType==="Right"?t/2-o:-t/2,y:-e/2,width:o,height:e}}let n=e*s;return{x:-t/2,y:i.fillVerticalType==="Top"?-e/2:e/2-n,width:t,height:n}}Nh();jh();$h();Mh();ca();kr();sr();var $0={aVertex:(i,t,e,r,s)=>{let n=0,o=0,a=0,l=0;for(let c=0;c<i.length;++c){let h=i[c],u=h.texture,d=h.scaleX,f=h.scaleY,m=h.anchorX,g=h.anchorY,y=u.trim,x=u.orig;y?(o=y.x-m*x.width,n=o+y.width,l=y.y-g*x.height,a=l+y.height):(n=x.width*(1-m),o=x.width*-m,a=x.height*(1-g),l=x.height*-g),t[r]=o*d,t[r+1]=l*f,t[r+s]=n*d,t[r+s+1]=l*f,t[r+s*2]=n*d,t[r+s*2+1]=a*f,t[r+s*3]=o*d,t[r+s*3+1]=a*f,r+=s*4}},aPosition:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n],a=o.x,l=o.y;t[r]=a,t[r+1]=l,t[r+s]=a,t[r+s+1]=l,t[r+s*2]=a,t[r+s*2+1]=l,t[r+s*3]=a,t[r+s*3+1]=l,r+=s*4}},aRotation:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].rotation;t[r]=o,t[r+s]=o,t[r+s*2]=o,t[r+s*3]=o,r+=s*4}},aUV:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].texture.uvs;t[r]=o.x0,t[r+1]=o.y0,t[r+s]=o.x1,t[r+s+1]=o.y1,t[r+s*2]=o.x2,t[r+s*2+1]=o.y2,t[r+s*3]=o.x3,t[r+s*3+1]=o.y3,r+=s*4}},aColor:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].color;e[r]=o,e[r+s]=o,e[r+s*2]=o,e[r+s*3]=o,r+=s*4}}};function q0(i){let t=Object.values(i),e=t.filter(s=>s.dynamic),r=t.filter(s=>!s.dynamic);return{dynamicUpdate:K0(e),staticUpdate:K0(r)}}function K0(i){let t=0,e=[];for(let r=0;r<i.length;r++){let s=i[r],n=Wt(s.format).stride/4;t+=n,e.push({stride:n,updateFunction:s.updateFunction||$0[s.attributeName]})}return(r,s,n)=>{let o=0;for(let a=0;a<e.length;a++){let l=e[a];l.updateFunction(r,s,n,o,t),o+=l.stride}}}Js();ce();Ot();xr();Hh();function Z0(){return HE}function HE(i,t,e){let r=i.gl,s=i.shader,n=s._getProgramData(t.glProgram);for(let o in t.groups){let a=t.groups[o];for(let l in a.resources){let c=a.resources[l];if(c instanceof St)c.ubo?s.bindUniformBlock(c,t._uniformBindMap[o][l],e.blockIndex++):s.updateUniformGroup(c);else if(c instanceof ke)s.bindUniformBlock(c,t._uniformBindMap[o][l],e.blockIndex++);else if(c instanceof J||c instanceof Gi){i.texture.bind(c,e.textureCount);let h=t._uniformBindMap[o][l],u=n.uniformData[h];u&&(u.value!==e.textureCount&&r.uniform1i(u.location,e.textureCount),e.textureCount++)}else c instanceof Qt}}}va();ha();Qs();var Q0=[(i,t,e,r,s)=>{let n=r[i].toArray(!0);t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+4]=n[3],t[e+5]=n[4],t[e+6]=n[5],t[e+8]=n[6],t[e+9]=n[7],t[e+10]=n[8]},(i,t,e,r,s)=>{s=r[i],t[e]=s.x,t[e+1]=s.y,t[e+2]=s.width,t[e+3]=s.height},(i,t,e,r,s)=>{s=r[i],t[e]=s.x,t[e+1]=s.y},(i,t,e,r,s)=>{s=r[i],t[e]=s.red,t[e+1]=s.green,t[e+2]=s.blue,t[e+3]=s.alpha},(i,t,e,r,s)=>{s=r[i],t[e]=s.red,t[e+1]=s.green,t[e+2]=s.blue}],J0={f32:(i,t,e,r,s)=>{t[e]=s},i32:(i,t,e,r,s)=>{t[e]=s},"vec2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1]},"vec3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2]},"vec4<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat2x2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat3x3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+4]=s[3],t[e+5]=s[4],t[e+6]=s[5],t[e+8]=s[6],t[e+9]=s[7],t[e+10]=s[8]},"mat4x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<16;n++)t[e+n]=s[n]},"mat3x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/3|0)*4+n%3]=s[n]},"mat4x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat4x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat3x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/3|0)*4+n%3]=s[n]}},tv={f32:(i,t,e,r,s)=>{t[e]=s},i32:(i,t,e,r,s)=>{t[e]=s},"vec2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1]},"vec3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2]},"vec4<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat2x2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+4]=s[2],t[e+5]=s[3]},"mat3x3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+4]=s[3],t[e+5]=s[4],t[e+6]=s[5],t[e+8]=s[6],t[e+9]=s[7],t[e+10]=s[8]},"mat4x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<16;n++)t[e+n]=s[n]},"mat3x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/3|0)*4+n%3]=s[n]},"mat4x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat4x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat3x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/3|0)*4+n%3]=s[n]}};function ev(i){return iv(i,tv,t=>{let e=Math.max(_n[t.data.type]/16,1),r=t.data.value.length/t.data.size,s=(4-r%4)%4;return(n,o,a,l,c)=>{let h=0;for(let u=0;u<t.data.size*e;u++){for(let d=0;d<r;d++)o[a++]=c[h++];a+=s}}})}function rv(i){return iv(i,J0,t=>{let{size:e,align:r}=Nr[t.data.type],s=(e-r)/4;return(n,o,a,l,c)=>{let h=0;for(let u=0;u<t.data.size*(e/4);u++){for(let d=0;d<e/4;d++)o[a++]=c[h++];a+=s}}})}function iv(i,t,e){let r={};for(let s in i){let n=i[s],o=n.data,a=!1;r[o.name]={offset:n.offset/4,func:null};for(let l=0;l<Jt.length;l++){let c=Jt[l];if(o.type===c.type&&c.test(o)){r[o.name].func=Q0[l],a=!0;break}}a||(o.size===1?r[o.name].func=t[o.type]:r[o.name].func=e(n))}return(s,n,o)=>{for(let a in r)r[a].func(a,n,o+r[a].offset,s,s[a])}}Qs();var sv={f32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1f(s[i].location,r))},"vec2<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2f(s[i].location,r[0],r[1]))},"vec3<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3f(s[i].location,r[0],r[1],r[2]))},"vec4<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4f(s[i].location,r[0],r[1],r[2],r[3]))},i32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1i(s[i].location,r))},"vec2<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2i(s[i].location,r[0],r[1]))},"vec3<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3i(s[i].location,r[0],r[1],r[2]))},"vec4<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4i(s[i].location,r[0],r[1],r[2],r[3]))},u32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1ui(s[i].location,r))},"vec2<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2ui(s[i].location,r[0],r[1]))},"vec3<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3ui(s[i].location,r[0],r[1],r[2]))},"vec4<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4ui(s[i].location,r[0],r[1],r[2],r[3]))},bool(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1i(s[i].location,r))},"vec2<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2i(s[i].location,r[0],r[1]))},"vec3<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3i(s[i].location,r[0],r[1],r[2]))},"vec4<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4i(s[i].location,r[0],r[1],r[2],r[3]))},"mat2x2<f32>"(i,t,e,r,s,n,o){o.uniformMatrix2fv(s[i].location,!1,r)},"mat3x3<f32>"(i,t,e,r,s,n,o){o.uniformMatrix3fv(s[i].location,!1,r)},"mat4x4<f32>"(i,t,e,r,s,n,o){o.uniformMatrix4fv(s[i].location,!1,r)}},nv={f32(i,t,e,r,s,n,o){o.uniform1fv(s[i].location,r)},"vec2<f32>"(i,t,e,r,s,n,o){o.uniform2fv(s[i].location,r)},"vec3<f32>"(i,t,e,r,s,n,o){o.uniform3fv(s[i].location,r)},"vec4<f32>"(i,t,e,r,s,n,o){o.uniform4fv(s[i].location,r)},"mat2x2<f32>"(i,t,e,r,s,n,o){o.uniformMatrix2fv(s[i].location,!1,r)},"mat3x3<f32>"(i,t,e,r,s,n,o){o.uniformMatrix3fv(s[i].location,!1,r)},"mat4x4<f32>"(i,t,e,r,s,n,o){o.uniformMatrix4fv(s[i].location,!1,r)},i32(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<i32>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<i32>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<i32>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)},u32(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<u32>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<u32>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<u32>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)},bool(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<bool>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<bool>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<bool>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)}},ov=[(i,t,e,r,s,n,o)=>{o.uniformMatrix3fv(s[i].location,!1,n[i].toArray(!0))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.x||e[1]!==r.y||e[2]!==r.width||e[3]!==r.height)&&(e[0]=r.x,e[1]=r.y,e[2]=r.width,e[3]=r.height,o.uniform4f(s[i].location,r.x,r.y,r.width,r.height))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.x||e[1]!==r.y)&&(e[0]=r.x,e[1]=r.y,o.uniform2f(s[i].location,r.x,r.y))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.red||e[1]!==r.green||e[2]!==r.blue||e[3]!==r.alpha)&&(e[0]=r.red,e[1]=r.green,e[2]=r.blue,e[3]=r.alpha,o.uniform4f(s[i].location,r.red,r.green,r.blue,r.alpha))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.red||e[1]!==r.green||e[2]!==r.blue)&&(e[0]=r.red,e[1]=r.green,e[2]=r.blue,o.uniform3f(s[i].location,r.red,r.green,r.blue))}];function av(i,t){let e={};for(let r in i.uniformStructures){if(!t[r])continue;let s=i.uniformStructures[r],n=!1;for(let o=0;o<Jt.length;o++){let a=Jt[o];if(s.type===a.type&&a.test(s)){e[r]=ov[o],n=!0;break}}if(!n){let o=s.size===1?sv:nv;e[r]=o[s.type]}}return(r,s,n)=>{let o=n.gl;for(let a in e){let l=s[a],c=r[a],h=r[a].value;e[a](a,c,h,l,r,s,o)}}}function WE(){Object.assign(ue.prototype,{_unsafeEvalCheck(){}}),Object.assign(cr.prototype,{_systemCheck(){}}),Object.assign(zr.prototype,{_generateUniformsSync:av}),Object.assign(Wr.prototype,{_generateUboSync:ev}),Object.assign(Hr.prototype,{_generateUboSync:rv}),Object.assign(Vr.prototype,{_generateShaderSync:Z0}),Object.assign(Ja.prototype,{generateParticleUpdate:q0})}WE();var VE=33,zE=60;function Yu(i,t){let e=i.code&&String(i.code).startsWith("Digit")?String(i.code).slice(5):"";return e&&Number(e)>=1&&Number(e)<=9?`KeyboardCraftspersonKey${e}${t}`:""}function lv(i,t,e,r){return{x:(i.clientX-t.left)*e/t.width,y:(t.bottom-i.clientY)*r/t.height}}function XE({renderer:i,api:t,onSnapshot:e,onStatus:r,onError:s,isActive:n}={}){let o=null,a=!1,l=!1,c=null,h=null,u=0,d=null,f=null,m=[];function g(F){s&&s(F)}async function y(F){o=F,a=F?.running!==!1,F?.scene&&F.scene.format==="tree-v1"?(F.scene.reset&&(u=0),await i.applyScene(F.scene,F.canvasWidth,F.canvasHeight),u=F.scene.revision||u):Array.isArray(F?.paint)&&await i.render(F.paint,F.canvasWidth,F.canvasHeight),e&&await e(F)}async function x(){if(!(!a||l)&&!(n&&!n())){l=!0;try{await y(await t("get",{view:!0,sceneRev:u,compact:!0}))}catch(F){a=!1,v(),g(F)}finally{l=!1}}}function b(){c||(c=setInterval(()=>{x()},33))}function v(){c&&clearInterval(c),c=null,h&&clearTimeout(h),h=null}function T(F=30){h||(h=setTimeout(()=>{h=null,x()},F))}function S(){a=!1,u=0,v()}async function E(F,A){if(n&&!n())return null;try{let k=await t(F,{light:!0,...A||{}});return k&&typeof k=="object"&&k.frame!==void 0&&r&&r(k),T(30),k}catch(k){return g(k),null}}async function w(F={}){u=0;let A=await t("start",{view:!0,compact:!0,...F});return await y({...A,running:!0}),a=!0,v(),b(),A}async function I(){u=0,v();let F=await t("get",{view:!0,compact:!0,sceneRev:0});return await y(F),a&&b(),F}async function G(F={}){u=0,v();let A=await t("device",{view:!0,compact:!0,...F});return await y({...A,running:!0}),a=!0,b(),A}async function M(F={}){u=0;let A=await t("view",{view:!0,compact:!0,...F});return await y({...A,running:!0}),A}async function C(){return S(),t("stop")}function R(F,A){return lv(F,A.getBoundingClientRect(),o.canvasWidth,o.canvasHeight)}function L(F,{keysOn:A}={}){let k=A||F,X=z=>{!o||!a||n&&!n()||(F.setPointerCapture?.(z.pointerId),E("pointer",{type:"down",...R(z,F)}))},D=z=>{!o||!a||n&&!n()||E("pointer",{type:"up",...R(z,F)})},Z=z=>{!o||!a||n&&!n()||(f=R(z,F),!d&&(d=setTimeout(()=>{d=null,f&&E("pointer",{type:"move",...f})},60)))},ht=()=>{o&&a&&(!n||n())&&E("pointer",{type:"move",x:-1,y:-1})},xt=z=>{if(!o||!a||n&&!n())return;let Dt=Yu(z,"Down");Dt&&(z.preventDefault(),E("key",{key:Dt}))},st=z=>{if(!o||!a||n&&!n())return;let Dt=Yu(z,"Up");Dt&&(z.preventDefault(),E("key",{key:Dt}))};F.addEventListener("pointerdown",X),F.addEventListener("pointerup",D),F.addEventListener("pointermove",Z),F.addEventListener("pointerleave",ht),k.addEventListener("keydown",xt),k.addEventListener("keyup",st);let at=()=>{F.removeEventListener("pointerdown",X),F.removeEventListener("pointerup",D),F.removeEventListener("pointermove",Z),F.removeEventListener("pointerleave",ht),k.removeEventListener("keydown",xt),k.removeEventListener("keyup",st),d&&clearTimeout(d),d=null};return m.push(at),at}function V(){for(S();m.length;)m.pop()();i?.destroy?.()}return{get snapshot(){return o},get running(){return a},get sceneRev(){return u},applyScene:y,poll:x,pollSoon:T,startPolling:b,stopPolling:v,reset:S,act:E,start:w,attach:I,device:G,view:M,stop:C,bindInput:L,destroy:V}}var YE=[0,-.5,.5,.5,-.5,.5],jE=[0,-.5,.12,-.12,.5,0,.12,.12,0,.5,-.12,.12,-.5,0,-.12,-.12],$E=[0,-.5,.11,-.15,.48,-.15,.18,.07,.29,.41,0,.2,-.29,.41,-.18,.07,-.48,-.15,-.11,-.15],KE=new Set(["image","textbox","textwindow","button"]);function Ln(i,t=4294967295){let e=Number(i??t)>>>0;return{color:e&16777215,alpha:(e>>>24&255)/255}}function Zt(i,t=0){let e=Number(i);return Number.isFinite(e)?e:t}function qE(i){let t=i?.matrix;if(!t||typeof t!="object")return null;let e=[t.a,t.b,t.c,t.d,t.tx,t.ty].map(Number);return e.every(Number.isFinite)?e:null}function ZE(i){let t=i.horizontalAlignment==="Right"?1:i.horizontalAlignment==="Middle"?.5:0,e=i.verticalAlignment==="Bottom"?1:i.verticalAlignment==="Middle"?.5:0;return{x:t,y:e}}function QE(i,t,e){let r=i.primitive==="triangle"?YE:i.primitive==="fourstar"?jE:$E,s=[];for(let n=0;n<r.length;n+=2)s.push(r[n]*t,r[n+1]*e);return s}function JE(i,t,e){return hv(i)?[i.kind,i.primitive,i.imageId,"sprite"].join(" "):[i.kind,i.primitive,t,e,i.imageColor,i.imageId,i.fillType,i.fillHorizontalType,i.fillVerticalType,i.fillAmount,i.text,i.fontSize,i.fontColor,i.bgColor,i.enableOutline,i.outlineColor,i.horizontalAlignment,i.verticalAlignment,i.pressed].join(" ")}function hv(i){return i.kind==="image"&&i.primitive==="circle"&&(!i.fillType||i.fillType==="Unused")}function tC(i){let t=W.get().createCanvas(i,i);t.width=t.height=i;let e=t.getContext("2d");return e.fillStyle="#ffffff",e.beginPath(),e.arc(i/2,i/2,i/2,0,Math.PI*2),e.fill(),new U({source:new vt({resource:t,width:i,height:i,resolution:1})})}var cv=class{constructor(t){this.canvas=t,this.app=null,this.nodes=new Map,this.circleTextures=new Map,this.canvasWidth=0,this.canvasHeight=0,this.scratch=new B,this.ready=this.initialize()}async initialize(){let t=new za;await t.init({canvas:this.canvas,width:1,height:1,autoStart:!1,autoDensity:!1,resolution:Math.min(2,window.devicePixelRatio||1),antialias:!0,backgroundAlpha:0,preference:"webgl",powerPreference:"high-performance"}),t.ticker.stop(),t.stage.eventMode="none",t.stage.sortableChildren=!0,this.app=t}resize(t,e){let r=Math.max(1,Math.round(Zt(t,1))),s=Math.max(1,Math.round(Zt(e,1)));r===this.canvasWidth&&s===this.canvasHeight||(this.canvasWidth=r,this.canvasHeight=s,this.app.renderer.resize(r,s))}createNode(t,{group:e=!1}={}){let r=new ut({isRenderGroup:!!e});return r.label=`runtime:${t.id}`,r.eventMode="none",r.sortableChildren=!0,r.__runtimeId=t.id,r.__group=!!e,this.nodes.set(t.id,r),this.app.stage.addChild(r),r}clearVisual(t){t.__visual&&(t.removeChild(t.__visual),t.__visual.destroy({children:!0,context:!0}),t.__visual=null,t.__visualKey="")}circleTexture(t){let e=this.app?.renderer.resolution||2,r=Math.min(4096,Math.max(256,2**Math.ceil(Math.log2(Math.max(1,t*e)))));this.circleTextures||=new Map;let s=this.circleTextures.get(r);return s||(s=tC(r),this.circleTextures.set(r,s)),s}replaceVisual(t,e,r,s){if(this.clearVisual(t),!KE.has(e.kind))return;let n=new ut;if(n.eventMode="none",n.label=`visual:${e.id}`,e.kind==="textbox"||e.kind==="textwindow"){let o=new Se,a=Ln(e.bgColor,16777215);o.rect(-r/2,-s/2,r,s).fill(a),n.addChild(o);let l=Math.max(8,Zt(e.fontSize,12)),c=ZE(e),h=new On({text:String(e.text||""),style:new qe({fontFamily:'Inter, "Microsoft YaHei UI", "Microsoft YaHei", sans-serif',fontSize:l,fill:Ln(e.fontColor,4294967295),stroke:e.enableOutline?{color:Ln(e.outlineColor,4278190080).color,width:Math.max(2,l*.12),join:"round"}:void 0,wordWrap:!0,wordWrapWidth:Math.max(4,r-4),breakWords:!0,align:c.x===1?"right":c.x===.5?"center":"left",lineHeight:l*1.2})});h.anchor.set(c.x,c.y),h.x=c.x===0?-r/2+2:c.x===1?r/2-2:0,h.y=c.y===0?-s/2:c.y===1?s/2:0;let u=new Se().rect(-r/2,-s/2,r,s).fill({color:16777215,alpha:1});h.mask=u,n.addChild(u,h)}else if(e.kind==="button"){let o=new Se;o.roundRect(-r/2,-s/2,r,s,6).fill({color:3303631,alpha:1}),o.roundRect(-r/2,-s/2,r,s,6).stroke({color:7381247,alpha:.8,width:1}),e.pressed&&o.roundRect(-r/2,-s/2,r,s,6).fill({color:0,alpha:.28}),n.addChild(o)}else if(hv(e)){let o=new Me({texture:this.circleTexture(Math.min(r,s)),anchor:.5});n.__circle=o,n.addChild(o)}else{let o=new Se,a=Ln(e.imageColor,4294967295);e.primitive==="missing"?(o.rect(-r/2,-s/2,r,s).fill({color:4727336,alpha:.36}),o.rect(-r/2+.5,-s/2+.5,Math.max(0,r-1),Math.max(0,s-1)).stroke({color:16741505,alpha:1,width:1})):e.primitive==="circle"?o.circle(0,0,Math.min(r,s)/2).fill(a):e.primitive==="ring"?o.circle(0,0,Math.max(1,Math.min(r,s)/2-3.5)).stroke({...a,width:7}):e.primitive==="triangle"||e.primitive==="fourstar"||e.primitive==="fivestar"?o.poly(QE(e,r,s)).fill(a):o.rect(-r/2,-s/2,r,s).fill(a);let l=j0(e,r,s);if(l&&(o.visible=l.width>0&&l.height>0,o.visible)){let c=new Se().rect(l.x,l.y,l.width,l.height).fill({color:16777215,alpha:1});o.mask=c,n.addChild(c)}n.addChild(o)}n.scale.set(e.pressed?.98:1),t.addChildAt(n,0),t.__visual=n}applyMatrix(t,e,r){let s=qE(e);if(!s){let u=Math.max(0,Zt(e.sourceWidth,Zt(e.width))),d=Math.max(0,Zt(e.sourceHeight,Zt(e.height)));t.x=Zt(e.left)+u/2,t.y=this.canvasHeight-Zt(e.bottom)-d/2,t.rotation=-Zt(e.rotationZ)*Math.PI/180,t.scale.set(1);return}let[n,o,a,l,c,h]=s;this.scratch.set(n,-o,-a,l,c,r?-h:this.canvasHeight-h),t.setFromMatrix(this.scratch)}updateNode(t,e,{nested:r=!1}={}){let s=Math.max(0,Zt(e.sourceWidth,Zt(e.width))),n=Math.max(0,Zt(e.sourceHeight,Zt(e.height))),o=JE(e,s,n);t.__visualKey!==o&&(this.replaceVisual(t,e,s,n),t.__visualKey=o),t.__visual&&t.__visual.scale.set(e.pressed?.98:1);let a=t.__visual?.__circle;if(a){let l=Math.min(s,n),c=Ln(e.imageColor,4294967295);a.texture=this.circleTexture(l),a.width=a.height=l,a.tint=c.color,a.alpha=c.alpha,a.visible=l>0}this.applyMatrix(t,e,r)}attachNode(t,e){let r=e.parent,n=(r==null?this.app.stage:this.nodes.get(r))||this.app.stage;t.parent!==n&&n.addChild(t),n.sortableChildren=!0,t.zIndex=-Zt(e.z)}upsertSceneNode(t){if(!t||t.id===void 0||t.id===null)return;let e=t.group===!0,r=this.nodes.get(t.id);r?r.__group!==e&&(e?r.enableRenderGroup?.():r.disableRenderGroup?.(),r.__group=e):r=this.createNode(t,{group:e}),this.updateNode(r,t,{nested:t.parent!=null}),this.attachNode(r,t)}removeNode(t){let e=this.nodes.get(t);if(e){for(let r of[...e.children])r.__runtimeId!=null&&e.removeChild(r);e.parent?.removeChild(e),this.clearVisual(e),e.destroy({children:!1}),this.nodes.delete(t)}}clearNodes(){for(let t of[...this.nodes.keys()])this.removeNode(t)}async applyScene(t,e,r){if(await this.ready,this.resize(e,r),!t||t.format!=="tree-v1"){this.app.render();return}t.reset&&this.clearNodes();for(let n of t.removed||[])this.removeNode(n);let s=t.reset?t.nodes:t.changed;for(let n=0;n<(s||[]).length;n+=1){let o=s[n];!o||o.id===void 0||o.id===null||this.nodes.has(o.id)||this.createNode(o,{group:o.group===!0})}for(let n=0;n<(s||[]).length;n+=1)this.upsertSceneNode(s[n]);this.app.render()}async render(t,e,r){await this.ready,this.resize(e,r);let s=new Set,n=Array.isArray(t)?t:[];for(let o=0;o<n.length;o+=1){let a=n[o];if(!a||a.id===void 0||a.id===null)continue;s.add(a.id);let l=this.nodes.get(a.id)||this.createNode(a);this.updateNode(l,a),l.zIndex=o,l.parent!==this.app.stage&&this.app.stage.addChild(l)}for(let[o]of this.nodes)s.has(o)||this.removeNode(o);this.app.render()}destroy(){this.clearNodes();for(let t of this.circleTextures.values())t.destroy(!0);this.circleTextures.clear(),this.app?.destroy({removeView:!1},{children:!0,texture:!0,textureSource:!0}),this.app=null}};export{zE as PLAY_MOVE_THROTTLE_MS,VE as PLAY_POLL_INTERVAL_MS,cv as PixiPlayRenderer,tC as createCircleTexture,XE as createPlaySession,Yu as keyEventName,lv as stagePoint};
|
|
925
|
+
`);return new Function("ps","f32v","u32v",s)}var Ja=class{constructor(t){this._size=0,this._generateParticleUpdateCache={};let e=this._size=t.size??1e3,r=t.properties,s=0,n=0;for(let h in r){let u=r[h],d=Wt(u.format);u.dynamic?n+=d.stride:s+=d.stride}this._dynamicStride=n/4,this._staticStride=s/4,this.staticAttributeBuffer=new Ge(e*4*s),this.dynamicAttributeBuffer=new Ge(e*4*n),this.indexBuffer=Xu(e);let o=new Be,a=0,l=0;this._staticBuffer=new Ft({data:new Float32Array(1),label:"static-particle-buffer",shrinkToFit:!1,usage:it.VERTEX|it.COPY_DST}),this._dynamicBuffer=new Ft({data:new Float32Array(1),label:"dynamic-particle-buffer",shrinkToFit:!1,usage:it.VERTEX|it.COPY_DST});for(let h in r){let u=r[h],d=Wt(u.format);u.dynamic?(o.addAttribute(u.attributeName,{buffer:this._dynamicBuffer,stride:this._dynamicStride*4,offset:a*4,format:u.format}),a+=d.size):(o.addAttribute(u.attributeName,{buffer:this._staticBuffer,stride:this._staticStride*4,offset:l*4,format:u.format}),l+=d.size)}o.addIndex(this.indexBuffer);let c=this.getParticleUpdate(r);this._dynamicUpload=c.dynamicUpdate,this._staticUpload=c.staticUpdate,this.geometry=o}getParticleUpdate(t){let e=NE(t);return this._generateParticleUpdateCache[e]?this._generateParticleUpdateCache[e]:(this._generateParticleUpdateCache[e]=this.generateParticleUpdate(t),this._generateParticleUpdateCache[e])}generateParticleUpdate(t){return Y0(t)}update(t,e){t.length>this._size&&(e=!0,this._size=Math.max(t.length,this._size*1.5|0),this.staticAttributeBuffer=new Ge(this._size*this._staticStride*4*4),this.dynamicAttributeBuffer=new Ge(this._size*this._dynamicStride*4*4),this.indexBuffer=Xu(this._size),this.geometry.indexBuffer.setDataWithSize(this.indexBuffer,this.indexBuffer.byteLength,!0));let r=this.dynamicAttributeBuffer;if(this._dynamicUpload(t,r.float32View,r.uint32View),this._dynamicBuffer.setDataWithSize(this.dynamicAttributeBuffer.float32View,t.length*this._dynamicStride*4,!0),e){let s=this.staticAttributeBuffer;this._staticUpload(t,s.float32View,s.uint32View),this._staticBuffer.setDataWithSize(s.float32View,t.length*this._staticStride*4,!0)}}destroy(){this._staticBuffer.destroy(),this._dynamicBuffer.destroy(),this.geometry.destroy()}};function NE(i){let t=[];for(let e in i){let r=i[e];t.push(e,r.code,r.dynamic?"d":"s")}return t.join("_")}dt();et();rr();mt();rc();xe();Iu();fo();Za();Gt();H.add(_m,bm);function j0(i,t,e){if(i.fillType!=="Horizontal"&&i.fillType!=="Vertical")return null;let r=Number(i.fillAmount??1),s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1;if(i.fillType==="Horizontal"){let o=t*s;return{x:i.fillHorizontalType==="Right"?t/2-o:-t/2,y:-e/2,width:o,height:e}}let n=e*s;return{x:-t/2,y:i.fillVerticalType==="Top"?-e/2:e/2-n,width:t,height:n}}Nh();jh();$h();Mh();ca();kr();sr();var $0={aVertex:(i,t,e,r,s)=>{let n=0,o=0,a=0,l=0;for(let c=0;c<i.length;++c){let h=i[c],u=h.texture,d=h.scaleX,f=h.scaleY,m=h.anchorX,g=h.anchorY,y=u.trim,x=u.orig;y?(o=y.x-m*x.width,n=o+y.width,l=y.y-g*x.height,a=l+y.height):(n=x.width*(1-m),o=x.width*-m,a=x.height*(1-g),l=x.height*-g),t[r]=o*d,t[r+1]=l*f,t[r+s]=n*d,t[r+s+1]=l*f,t[r+s*2]=n*d,t[r+s*2+1]=a*f,t[r+s*3]=o*d,t[r+s*3+1]=a*f,r+=s*4}},aPosition:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n],a=o.x,l=o.y;t[r]=a,t[r+1]=l,t[r+s]=a,t[r+s+1]=l,t[r+s*2]=a,t[r+s*2+1]=l,t[r+s*3]=a,t[r+s*3+1]=l,r+=s*4}},aRotation:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].rotation;t[r]=o,t[r+s]=o,t[r+s*2]=o,t[r+s*3]=o,r+=s*4}},aUV:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].texture.uvs;t[r]=o.x0,t[r+1]=o.y0,t[r+s]=o.x1,t[r+s+1]=o.y1,t[r+s*2]=o.x2,t[r+s*2+1]=o.y2,t[r+s*3]=o.x3,t[r+s*3+1]=o.y3,r+=s*4}},aColor:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].color;e[r]=o,e[r+s]=o,e[r+s*2]=o,e[r+s*3]=o,r+=s*4}}};function q0(i){let t=Object.values(i),e=t.filter(s=>s.dynamic),r=t.filter(s=>!s.dynamic);return{dynamicUpdate:K0(e),staticUpdate:K0(r)}}function K0(i){let t=0,e=[];for(let r=0;r<i.length;r++){let s=i[r],n=Wt(s.format).stride/4;t+=n,e.push({stride:n,updateFunction:s.updateFunction||$0[s.attributeName]})}return(r,s,n)=>{let o=0;for(let a=0;a<e.length;a++){let l=e[a];l.updateFunction(r,s,n,o,t),o+=l.stride}}}Js();ce();Ot();xr();Hh();function Z0(){return HE}function HE(i,t,e){let r=i.gl,s=i.shader,n=s._getProgramData(t.glProgram);for(let o in t.groups){let a=t.groups[o];for(let l in a.resources){let c=a.resources[l];if(c instanceof St)c.ubo?s.bindUniformBlock(c,t._uniformBindMap[o][l],e.blockIndex++):s.updateUniformGroup(c);else if(c instanceof ke)s.bindUniformBlock(c,t._uniformBindMap[o][l],e.blockIndex++);else if(c instanceof J||c instanceof Gi){i.texture.bind(c,e.textureCount);let h=t._uniformBindMap[o][l],u=n.uniformData[h];u&&(u.value!==e.textureCount&&r.uniform1i(u.location,e.textureCount),e.textureCount++)}else c instanceof Qt}}}va();ha();Qs();var Q0=[(i,t,e,r,s)=>{let n=r[i].toArray(!0);t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+4]=n[3],t[e+5]=n[4],t[e+6]=n[5],t[e+8]=n[6],t[e+9]=n[7],t[e+10]=n[8]},(i,t,e,r,s)=>{s=r[i],t[e]=s.x,t[e+1]=s.y,t[e+2]=s.width,t[e+3]=s.height},(i,t,e,r,s)=>{s=r[i],t[e]=s.x,t[e+1]=s.y},(i,t,e,r,s)=>{s=r[i],t[e]=s.red,t[e+1]=s.green,t[e+2]=s.blue,t[e+3]=s.alpha},(i,t,e,r,s)=>{s=r[i],t[e]=s.red,t[e+1]=s.green,t[e+2]=s.blue}],J0={f32:(i,t,e,r,s)=>{t[e]=s},i32:(i,t,e,r,s)=>{t[e]=s},"vec2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1]},"vec3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2]},"vec4<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat2x2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat3x3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+4]=s[3],t[e+5]=s[4],t[e+6]=s[5],t[e+8]=s[6],t[e+9]=s[7],t[e+10]=s[8]},"mat4x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<16;n++)t[e+n]=s[n]},"mat3x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/3|0)*4+n%3]=s[n]},"mat4x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat4x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat3x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/3|0)*4+n%3]=s[n]}},tv={f32:(i,t,e,r,s)=>{t[e]=s},i32:(i,t,e,r,s)=>{t[e]=s},"vec2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1]},"vec3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2]},"vec4<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat2x2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+4]=s[2],t[e+5]=s[3]},"mat3x3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+4]=s[3],t[e+5]=s[4],t[e+6]=s[5],t[e+8]=s[6],t[e+9]=s[7],t[e+10]=s[8]},"mat4x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<16;n++)t[e+n]=s[n]},"mat3x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/3|0)*4+n%3]=s[n]},"mat4x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat4x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat3x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/3|0)*4+n%3]=s[n]}};function ev(i){return iv(i,tv,t=>{let e=Math.max(_n[t.data.type]/16,1),r=t.data.value.length/t.data.size,s=(4-r%4)%4;return(n,o,a,l,c)=>{let h=0;for(let u=0;u<t.data.size*e;u++){for(let d=0;d<r;d++)o[a++]=c[h++];a+=s}}})}function rv(i){return iv(i,J0,t=>{let{size:e,align:r}=Nr[t.data.type],s=(e-r)/4;return(n,o,a,l,c)=>{let h=0;for(let u=0;u<t.data.size*(e/4);u++){for(let d=0;d<e/4;d++)o[a++]=c[h++];a+=s}}})}function iv(i,t,e){let r={};for(let s in i){let n=i[s],o=n.data,a=!1;r[o.name]={offset:n.offset/4,func:null};for(let l=0;l<Jt.length;l++){let c=Jt[l];if(o.type===c.type&&c.test(o)){r[o.name].func=Q0[l],a=!0;break}}a||(o.size===1?r[o.name].func=t[o.type]:r[o.name].func=e(n))}return(s,n,o)=>{for(let a in r)r[a].func(a,n,o+r[a].offset,s,s[a])}}Qs();var sv={f32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1f(s[i].location,r))},"vec2<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2f(s[i].location,r[0],r[1]))},"vec3<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3f(s[i].location,r[0],r[1],r[2]))},"vec4<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4f(s[i].location,r[0],r[1],r[2],r[3]))},i32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1i(s[i].location,r))},"vec2<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2i(s[i].location,r[0],r[1]))},"vec3<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3i(s[i].location,r[0],r[1],r[2]))},"vec4<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4i(s[i].location,r[0],r[1],r[2],r[3]))},u32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1ui(s[i].location,r))},"vec2<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2ui(s[i].location,r[0],r[1]))},"vec3<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3ui(s[i].location,r[0],r[1],r[2]))},"vec4<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4ui(s[i].location,r[0],r[1],r[2],r[3]))},bool(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1i(s[i].location,r))},"vec2<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2i(s[i].location,r[0],r[1]))},"vec3<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3i(s[i].location,r[0],r[1],r[2]))},"vec4<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4i(s[i].location,r[0],r[1],r[2],r[3]))},"mat2x2<f32>"(i,t,e,r,s,n,o){o.uniformMatrix2fv(s[i].location,!1,r)},"mat3x3<f32>"(i,t,e,r,s,n,o){o.uniformMatrix3fv(s[i].location,!1,r)},"mat4x4<f32>"(i,t,e,r,s,n,o){o.uniformMatrix4fv(s[i].location,!1,r)}},nv={f32(i,t,e,r,s,n,o){o.uniform1fv(s[i].location,r)},"vec2<f32>"(i,t,e,r,s,n,o){o.uniform2fv(s[i].location,r)},"vec3<f32>"(i,t,e,r,s,n,o){o.uniform3fv(s[i].location,r)},"vec4<f32>"(i,t,e,r,s,n,o){o.uniform4fv(s[i].location,r)},"mat2x2<f32>"(i,t,e,r,s,n,o){o.uniformMatrix2fv(s[i].location,!1,r)},"mat3x3<f32>"(i,t,e,r,s,n,o){o.uniformMatrix3fv(s[i].location,!1,r)},"mat4x4<f32>"(i,t,e,r,s,n,o){o.uniformMatrix4fv(s[i].location,!1,r)},i32(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<i32>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<i32>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<i32>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)},u32(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<u32>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<u32>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<u32>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)},bool(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<bool>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<bool>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<bool>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)}},ov=[(i,t,e,r,s,n,o)=>{o.uniformMatrix3fv(s[i].location,!1,n[i].toArray(!0))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.x||e[1]!==r.y||e[2]!==r.width||e[3]!==r.height)&&(e[0]=r.x,e[1]=r.y,e[2]=r.width,e[3]=r.height,o.uniform4f(s[i].location,r.x,r.y,r.width,r.height))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.x||e[1]!==r.y)&&(e[0]=r.x,e[1]=r.y,o.uniform2f(s[i].location,r.x,r.y))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.red||e[1]!==r.green||e[2]!==r.blue||e[3]!==r.alpha)&&(e[0]=r.red,e[1]=r.green,e[2]=r.blue,e[3]=r.alpha,o.uniform4f(s[i].location,r.red,r.green,r.blue,r.alpha))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.red||e[1]!==r.green||e[2]!==r.blue)&&(e[0]=r.red,e[1]=r.green,e[2]=r.blue,o.uniform3f(s[i].location,r.red,r.green,r.blue))}];function av(i,t){let e={};for(let r in i.uniformStructures){if(!t[r])continue;let s=i.uniformStructures[r],n=!1;for(let o=0;o<Jt.length;o++){let a=Jt[o];if(s.type===a.type&&a.test(s)){e[r]=ov[o],n=!0;break}}if(!n){let o=s.size===1?sv:nv;e[r]=o[s.type]}}return(r,s,n)=>{let o=n.gl;for(let a in e){let l=s[a],c=r[a],h=r[a].value;e[a](a,c,h,l,r,s,o)}}}function WE(){Object.assign(ue.prototype,{_unsafeEvalCheck(){}}),Object.assign(cr.prototype,{_systemCheck(){}}),Object.assign(zr.prototype,{_generateUniformsSync:av}),Object.assign(Wr.prototype,{_generateUboSync:ev}),Object.assign(Hr.prototype,{_generateUboSync:rv}),Object.assign(Vr.prototype,{_generateShaderSync:Z0}),Object.assign(Ja.prototype,{generateParticleUpdate:q0})}WE();var VE=33,zE=60;function Yu(i,t){let e=i.code&&String(i.code).startsWith("Digit")?String(i.code).slice(5):"";return e&&Number(e)>=1&&Number(e)<=9?`KeyboardCraftspersonKey${e}${t}`:""}function lv(i,t,e,r){return{x:(i.clientX-t.left)*e/t.width,y:(t.bottom-i.clientY)*r/t.height}}function XE({renderer:i,api:t,onSnapshot:e,onStatus:r,onError:s,isActive:n}={}){let o=null,a=!1,l=!1,c=null,h=null,u=0,d=null,f=null,m=[];function g(F){s&&s(F)}async function y(F){o=F,a=F?.running!==!1,F?.scene&&F.scene.format==="tree-v1"?(F.scene.reset&&(u=0),await i.applyScene(F.scene,F.canvasWidth,F.canvasHeight),u=F.scene.revision||u):Array.isArray(F?.paint)&&await i.render(F.paint,F.canvasWidth,F.canvasHeight),e&&await e(F)}async function x(){if(!(!a||l)&&!(n&&!n())){l=!0;try{await y(await t("get",{view:!0,sceneRev:u,compact:!0}))}catch(F){a=!1,v(),g(F)}finally{l=!1}}}function b(){c||(c=setInterval(()=>{x()},33))}function v(){c&&clearInterval(c),c=null,h&&clearTimeout(h),h=null}function T(F=30){h||(h=setTimeout(()=>{h=null,x()},F))}function S(){a=!1,u=0,v()}async function E(F,A){if(n&&!n())return null;try{let k=await t(F,{light:!0,...A||{}});return k&&typeof k=="object"&&k.frame!==void 0&&r&&r(k),T(30),k}catch(k){return g(k),null}}async function w(F={}){u=0;let A=await t("start",{view:!0,compact:!0,...F});return await y({...A,running:!0}),a=!0,v(),b(),A}async function I(){u=0,v();let F=await t("get",{view:!0,compact:!0,sceneRev:0});return await y(F),a&&b(),F}async function G(F={}){u=0,v();let A=await t("device",{view:!0,compact:!0,...F});return await y({...A,running:!0}),a=!0,b(),A}async function M(F={}){u=0;let A=await t("view",{view:!0,compact:!0,...F});return await y({...A,running:!0}),A}async function C(){return S(),t("stop")}function R(F,A){return lv(F,A.getBoundingClientRect(),o.canvasWidth,o.canvasHeight)}function L(F,{keysOn:A}={}){let k=A||F,X=z=>{!o||!a||n&&!n()||(F.setPointerCapture?.(z.pointerId),E("pointer",{type:"down",...R(z,F)}))},D=z=>{!o||!a||n&&!n()||E("pointer",{type:"up",...R(z,F)})},Z=z=>{!o||!a||n&&!n()||(f=R(z,F),!d&&(d=setTimeout(()=>{d=null,f&&E("pointer",{type:"move",...f})},60)))},ht=()=>{o&&a&&(!n||n())&&E("pointer",{type:"move",x:-1,y:-1})},xt=z=>{if(!o||!a||n&&!n())return;let Dt=Yu(z,"Down");Dt&&(z.preventDefault(),E("key",{key:Dt}))},st=z=>{if(!o||!a||n&&!n())return;let Dt=Yu(z,"Up");Dt&&(z.preventDefault(),E("key",{key:Dt}))};F.addEventListener("pointerdown",X),F.addEventListener("pointerup",D),F.addEventListener("pointermove",Z),F.addEventListener("pointerleave",ht),k.addEventListener("keydown",xt),k.addEventListener("keyup",st);let at=()=>{F.removeEventListener("pointerdown",X),F.removeEventListener("pointerup",D),F.removeEventListener("pointermove",Z),F.removeEventListener("pointerleave",ht),k.removeEventListener("keydown",xt),k.removeEventListener("keyup",st),d&&clearTimeout(d),d=null};return m.push(at),at}function V(){for(S();m.length;)m.pop()();i?.destroy?.()}return{get snapshot(){return o},get running(){return a},get sceneRev(){return u},applyScene:y,poll:x,pollSoon:T,startPolling:b,stopPolling:v,reset:S,act:E,start:w,attach:I,device:G,view:M,stop:C,bindInput:L,destroy:V}}var YE=[0,-.5,.5,.5,-.5,.5],jE=[0,-.5,.12,-.12,.5,0,.12,.12,0,.5,-.12,.12,-.5,0,-.12,-.12],$E=[0,-.5,.11,-.15,.48,-.15,.18,.07,.29,.41,0,.2,-.29,.41,-.18,.07,-.48,-.15,-.11,-.15],KE=new Set(["image","textbox","textwindow","button"]);function Ln(i,t=4294967295){let e=Number(i??t)>>>0;return{color:e&16777215,alpha:(e>>>24&255)/255}}function Zt(i,t=0){let e=Number(i);return Number.isFinite(e)?e:t}function qE(i){let t=i?.matrix;if(!t||typeof t!="object")return null;let e=[t.a,t.b,t.c,t.d,t.tx,t.ty].map(Number);return e.every(Number.isFinite)?e:null}function ZE(i){let t=i.horizontalAlignment==="Right"?1:i.horizontalAlignment==="Middle"?.5:0,e=i.verticalAlignment==="Bottom"?1:i.verticalAlignment==="Middle"?.5:0;return{x:t,y:e}}function QE(i,t,e){let r=i.primitive==="triangle"?YE:i.primitive==="fourstar"?jE:$E,s=[];for(let n=0;n<r.length;n+=2)s.push(r[n]*t,r[n+1]*e);return s}function JE(i,t,e){return hv(i)?[i.kind,i.primitive,i.imageId,"sprite"].join(" "):[i.kind,i.primitive,t,e,i.imageColor,i.imageId,i.fillType,i.fillHorizontalType,i.fillVerticalType,i.fillAmount,i.text,i.fontSize,i.fontColor,i.bgColor,i.enableOutline,i.outlineColor,i.horizontalAlignment,i.verticalAlignment,i.pressed].join(" ")}function hv(i){return i.kind==="image"&&i.primitive==="circle"&&(!i.fillType||i.fillType==="Unused")}function tC(i){let t=W.get().createCanvas(i,i);t.width=t.height=i;let e=t.getContext("2d");return e.fillStyle="#ffffff",e.beginPath(),e.arc(i/2,i/2,i/2,0,Math.PI*2),e.fill(),new U({source:new vt({resource:t,width:i,height:i,resolution:1})})}var cv=class{constructor(t){this.canvas=t,this.app=null,this.nodes=new Map,this.circleTextures=new Map,this.canvasWidth=0,this.canvasHeight=0,this.scratch=new B,this.ready=this.initialize()}async initialize(){let t=new za;await t.init({canvas:this.canvas,width:1,height:1,autoStart:!1,autoDensity:!1,resolution:Math.min(2,window.devicePixelRatio||1),antialias:!0,backgroundAlpha:0,preference:"webgl",powerPreference:"high-performance"}),t.ticker.stop(),t.stage.eventMode="none",t.stage.sortableChildren=!0,this.app=t}resize(t,e){let r=Math.max(1,Math.round(Zt(t,1))),s=Math.max(1,Math.round(Zt(e,1)));r===this.canvasWidth&&s===this.canvasHeight||(this.canvasWidth=r,this.canvasHeight=s,this.app.renderer.resize(r,s))}createNode(t,{group:e=!1}={}){let r=new ut({isRenderGroup:!!e});return r.label=`runtime:${t.id}`,r.eventMode="none",r.sortableChildren=!0,r.__runtimeId=t.id,r.__group=!!e,this.nodes.set(t.id,r),this.app.stage.addChild(r),r}clearVisual(t){t.__visual&&(t.removeChild(t.__visual),t.__visual.destroy({children:!0,context:!0}),t.__visual=null,t.__visualKey="")}circleTexture(t){let e=this.app?.renderer.resolution||2,r=Math.min(4096,Math.max(256,2**Math.ceil(Math.log2(Math.max(1,t*e)))));this.circleTextures||=new Map;let s=this.circleTextures.get(r);return s||(s=tC(r),this.circleTextures.set(r,s)),s}replaceVisual(t,e,r,s){if(this.clearVisual(t),!KE.has(e.kind))return;let n=new ut;if(n.eventMode="none",n.label=`visual:${e.id}`,e.kind==="textbox"||e.kind==="textwindow"){let o=new Se,a=Ln(e.bgColor,16777215);o.rect(-r/2,-s/2,r,s).fill(a),n.addChild(o);let l=Math.max(8,Zt(e.fontSize,12)),c=ZE(e),h=new On({text:String(e.text||""),style:new qe({fontFamily:'Inter, "Microsoft YaHei UI", "Microsoft YaHei", sans-serif',fontSize:l,fill:Ln(e.fontColor,4294967295),stroke:e.enableOutline?{color:Ln(e.outlineColor,4278190080).color,width:Math.max(2,l*.12),join:"round"}:void 0,wordWrap:!0,wordWrapWidth:Math.max(4,r-4),breakWords:!0,align:c.x===1?"right":c.x===.5?"center":"left",lineHeight:l*1.2})});h.anchor.set(c.x,c.y),h.x=c.x===0?-r/2+2:c.x===1?r/2-2:0,h.y=c.y===0?-s/2:c.y===1?s/2:0;let u=new Se().rect(-r/2,-s/2,r,s).fill({color:16777215,alpha:1});h.mask=u,n.addChild(u,h)}else if(e.kind==="button"){let o=new Se;o.roundRect(-r/2,-s/2,r,s,6).fill({color:3303631,alpha:1}),o.roundRect(-r/2,-s/2,r,s,6).stroke({color:7381247,alpha:.8,width:1}),e.pressed&&o.roundRect(-r/2,-s/2,r,s,6).fill({color:0,alpha:.28}),n.addChild(o)}else if(hv(e)){let o=new Me({texture:this.circleTexture(Math.max(r,s)),anchor:.5});n.__circle=o,n.addChild(o)}else{let o=new Se,a=Ln(e.imageColor,4294967295);e.primitive==="missing"?(o.rect(-r/2,-s/2,r,s).fill({color:4727336,alpha:.36}),o.rect(-r/2+.5,-s/2+.5,Math.max(0,r-1),Math.max(0,s-1)).stroke({color:16741505,alpha:1,width:1})):e.primitive==="circle"?o.ellipse(0,0,r/2,s/2).fill(a):e.primitive==="ring"?o.ellipse(0,0,Math.max(1,r/2-3.5),Math.max(1,s/2-3.5)).stroke({...a,width:7}):e.primitive==="triangle"||e.primitive==="fourstar"||e.primitive==="fivestar"?o.poly(QE(e,r,s)).fill(a):o.rect(-r/2,-s/2,r,s).fill(a);let l=j0(e,r,s);if(l&&(o.visible=l.width>0&&l.height>0,o.visible)){let c=new Se().rect(l.x,l.y,l.width,l.height).fill({color:16777215,alpha:1});o.mask=c,n.addChild(c)}n.addChild(o)}n.scale.set(e.pressed?.98:1),t.addChildAt(n,0),t.__visual=n}applyMatrix(t,e,r){let s=qE(e);if(!s){let u=Math.max(0,Zt(e.sourceWidth,Zt(e.width))),d=Math.max(0,Zt(e.sourceHeight,Zt(e.height)));t.x=Zt(e.left)+u/2,t.y=this.canvasHeight-Zt(e.bottom)-d/2,t.rotation=-Zt(e.rotationZ)*Math.PI/180,t.scale.set(1);return}let[n,o,a,l,c,h]=s;this.scratch.set(n,-o,-a,l,c,r?-h:this.canvasHeight-h),t.setFromMatrix(this.scratch)}updateNode(t,e,{nested:r=!1}={}){let s=Math.max(0,Zt(e.sourceWidth,Zt(e.width))),n=Math.max(0,Zt(e.sourceHeight,Zt(e.height))),o=JE(e,s,n);t.__visualKey!==o&&(this.replaceVisual(t,e,s,n),t.__visualKey=o),t.__visual&&t.__visual.scale.set(e.pressed?.98:1);let a=t.__visual?.__circle;if(a){let l=Math.max(s,n),c=Ln(e.imageColor,4294967295);a.texture=this.circleTexture(l),a.width=s,a.height=n,a.tint=c.color,a.alpha=c.alpha,a.visible=s>0&&n>0}this.applyMatrix(t,e,r)}attachNode(t,e){let r=e.parent,n=(r==null?this.app.stage:this.nodes.get(r))||this.app.stage;t.parent!==n&&n.addChild(t),n.sortableChildren=!0,t.zIndex=-Zt(e.z)}upsertSceneNode(t){if(!t||t.id===void 0||t.id===null)return;let e=t.group===!0,r=this.nodes.get(t.id);r?r.__group!==e&&(e?r.enableRenderGroup?.():r.disableRenderGroup?.(),r.__group=e):r=this.createNode(t,{group:e}),this.updateNode(r,t,{nested:t.parent!=null}),this.attachNode(r,t)}removeNode(t){let e=this.nodes.get(t);if(e){for(let r of[...e.children])r.__runtimeId!=null&&e.removeChild(r);e.parent?.removeChild(e),this.clearVisual(e),e.destroy({children:!1}),this.nodes.delete(t)}}clearNodes(){for(let t of[...this.nodes.keys()])this.removeNode(t)}async applyScene(t,e,r){if(await this.ready,this.resize(e,r),!t||t.format!=="tree-v1"){this.app.render();return}t.reset&&this.clearNodes();for(let n of t.removed||[])this.removeNode(n);let s=t.reset?t.nodes:t.changed;for(let n=0;n<(s||[]).length;n+=1){let o=s[n];!o||o.id===void 0||o.id===null||this.nodes.has(o.id)||this.createNode(o,{group:o.group===!0})}for(let n=0;n<(s||[]).length;n+=1)this.upsertSceneNode(s[n]);this.app.render()}async render(t,e,r){await this.ready,this.resize(e,r);let s=new Set,n=Array.isArray(t)?t:[];for(let o=0;o<n.length;o+=1){let a=n[o];if(!a||a.id===void 0||a.id===null)continue;s.add(a.id);let l=this.nodes.get(a.id)||this.createNode(a);this.updateNode(l,a),l.zIndex=o,l.parent!==this.app.stage&&this.app.stage.addChild(l)}for(let[o]of this.nodes)s.has(o)||this.removeNode(o);this.app.render()}destroy(){this.clearNodes();for(let t of this.circleTextures.values())t.destroy(!0);this.circleTextures.clear(),this.app?.destroy({removeView:!1},{children:!0,texture:!0,textureSource:!0}),this.app=null}};export{zE as PLAY_MOVE_THROTTLE_MS,VE as PLAY_POLL_INTERVAL_MS,cv as PixiPlayRenderer,tC as createCircleTexture,XE as createPlaySession,Yu as keyEventName,lv as stagePoint};
|
|
926
926
|
/*! Bundled license information:
|
|
927
927
|
|
|
928
928
|
tiny-lru/dist/tiny-lru.js:
|
package/dist/server.js
CHANGED
|
@@ -105,7 +105,7 @@ ${r.errors.join(`
|
|
|
105
105
|
`)}`);return{buffer:n,warnings:[...new Set(t.warnings)]}}function nn(e){return we.toObject(we.decode(di(e)),{longs:Number,enums:Number,bytes:Buffer,defaults:!1,arrays:!0,objects:!0})}function Nr(e){try{let i=nn(e).graph||[];return i.length>0&&i.every(n=>Number(n.which)===vt)}catch{return!1}}function Fr(e){let t=(e.graph||[]).filter(r=>Number(r.which)===vt),i=[],n=t.map((r,o)=>{let a=r.script?.mapping||{},s=Number(r.id?.id)||0;s<=0&&i.push(`\u7B2C ${o+1} \u6761\u811A\u672C\u6620\u5C04\u7F3A\u5C11 GraphUnit.id.id\uFF0C\u5DF2\u6309 0 \u5904\u7406\uFF08\u5BFC\u51FA\u65F6\u4F1A\u91CD\u65B0\u5206\u914D\uFF09\u3002`);let u=Number(a.id)||0;return u&&u!==s&&i.push(`\u7B2C ${o+1} \u6761\u811A\u672C\u6620\u5C04 id(${u}) \u4E0E\u5355\u5143 id(${s}) \u4E0D\u4E00\u81F4\uFF0C\u4EE5\u5355\u5143 id \u4E3A\u51C6\u3002`),{guid:s,path:String(a.filePath||""),source:String(a.source||"")}});for(let[r,o]of n.entries())o.path&&!/\.lua$/iu.test(o.path)&&i.push(`\u7B2C ${r+1} \u6761\u811A\u672C\u6620\u5C04 file_path \u7F3A\u5C11 .lua \u540E\u7F00\uFF08${o.path}\uFF09\uFF0C\u771F\u673A\u53EF\u80FD\u62D2\u7EDD\u5BFC\u5165\uFF1B\u6A21\u62DF\u5668\u5185\u6309\u5F52\u4E00\u5316\u8DEF\u5F84\u7167\u5E38 require\u3002`);return{scripts:n,warnings:i}}function Or(e){let t=nn(e),i=Fr(t);if(!i.scripts.length)throw new Error("GIA \u5185\u6CA1\u6709\u811A\u672C\u6620\u5C04\u5355\u5143\uFF08which=69\uFF09");return{scripts:i.scripts,warnings:i.warnings,metadata:{assetType:"lua-script"}}}function Za(e){let t=[],i;try{i=nn(e)}catch(r){return{valid:!1,errors:[r?.message||String(r)],scriptCount:0}}let n=i.graph||[];return n.length||t.push("Root.graph \u4E3A\u7A7A"),(i.accessories||[]).length&&t.push("script.gia \u4E0D\u5E94\u5305\u542B accessories"),n.forEach((r,o)=>{let a=`\u5355\u5143 ${o+1}`;Number(r.which)!==vt&&t.push(`${a}: which \u5E94\u4E3A 69\uFF0C\u5B9E\u9645 ${r.which}`),Number(r.id?.class)!==Pr&&t.push(`${a}: id.class \u5E94\u4E3A 30\uFF0C\u5B9E\u9645 ${r.id?.class}`),Number(r.id?.type??0)!==0&&t.push(`${a}: id.type \u5E94\u7F3A\u7701`);let s=r.script?.mapping;if(!s){t.push(`${a}: \u7F3A\u5C11 field35 ScriptMappingWrapper`);return}Number(r.id?.id)<=0&&t.push(`${a}: GraphUnit.id.id \u975E\u6CD5`),Number(s.id)!==Number(r.id?.id)&&t.push(`${a}: mapping.id \u5E94\u7B49\u4E8E GraphUnit.id.id`),String(s.name||"")!==String(r.name||"")&&t.push(`${a}: mapping.name \u5E94\u7B49\u4E8E GraphUnit.name`),String(s.filePath||"").trim()?/\.lua$/iu.test(String(s.filePath))||t.push(`${a}: file_path \u5E94\u4EE5 .lua \u7ED3\u5C3E\uFF08\u5B98\u65B9 script.gia \u6837\u672C\u5747\u4E3A \u540D\u79F0.lua\uFF0C\u771F\u673A require \u65F6\u624D\u53BB\u6269\u5C55\u540D\uFF09`):t.push(`${a}: file_path \u4E3A\u7A7A`)}),{valid:t.length===0,errors:t,scriptCount:n.length}}function di(e){let t=Buffer.isBuffer(e)?e:Buffer.from(e);if(t.length<Ye+Ji)throw new Error("GIA \u6587\u4EF6\u8FC7\u77ED");if(t.readUInt32BE(4)!==1||t.readUInt32BE(8)!==mr||t.readUInt32BE(12)!==3)throw new Error("\u4E0D\u662F\u53D7\u652F\u6301\u7684 GIA v1 \u6587\u4EF6");let i=t.readUInt32BE(16);if(i!==t.length-Ye-Ji)throw new Error("GIA payload \u957F\u5EA6\u4E0D\u4E00\u81F4");if(t.readUInt32BE(Ye+i)!==gr)throw new Error("GIA \u5C3E\u6807\u8BB0\u65E0\u6548");return t.subarray(Ye,Ye+i)}function he(e,t){return e.ui?.content?.data?.find(i=>i.details?.[t])?.details?.[t]||null}function Qa(e){let t=he(e,"transform")?.multiPlatform,i={};for(let r of t?.platforms||[]){let o=Ya[r.platformType||0],a=r.transform||{};i[o]={scale:a.scale?{x:a.scale.x??0,y:a.scale.y??0,z:a.scale.z??0}:{x:1,y:1,z:1},rotation:{x:0,y:0,z:0},anchorMin:{x:a.anchorMin?.x??0,y:a.anchorMin?.y??0},anchorMax:{x:a.anchorMax?.x??0,y:a.anchorMax?.y??0},offset:{x:a.offset?.x??0,y:a.offset?.y??0},size:{x:a.size?.x??0,y:a.size?.y??0},pivot:a.pivot?{x:a.pivot.x??0,y:a.pivot.y??0}:{x:.5,y:.5}}}let n=i.KEYBOARD||i[Object.keys(i)[0]];if(!n)throw new Error(`GIA \u63A7\u4EF6 ${e.name||e.id?.id} \u7F3A\u5C11\u591A\u5E73\u53F0\u53D8\u6362`);for(let r of te)i[r]||(i[r]=structuredClone(n));return i}function fi(e){let t=e.ui?.content?.data||[];return t.some(i=>i.details?.textConfig)?t.some(i=>i.field501===71)?"textwindow":"textbox":t.some(i=>i.details?.cursorConfig)?"cursor":t.some(i=>Object.hasOwn(i.details||{},"templateRefSlot"))?"reference":t.some(i=>i.details?.gridView)?"grid":t.some(i=>i.details?.buttonPreset)?"button":t.some(i=>i.details?.keyHint)?"keyhint":t.some(i=>i.details?.image||i.details?.imageSlot)?"image":t.some(i=>Object.hasOwn(i.details||{},"effectSlot"))?"animation":t.some(i=>Object.hasOwn(i.details||{},"fullscreenEffectSlot"))?"fullscreen":(t.some(i=>Object.hasOwn(i.details||{},"containerNodeSlot")),"container")}function pr(e,{reverseSiblings:t=!1,idOffset:i=0}={}){if(!e.length)return{nodes:new Map,rootCandidates:[],warnings:[]};let n=new Map(e.map((l,f)=>[l.id?.id,`n${i+f+1}`])),r=new Map,o=new Map,a=[];for(let l of e){let f=fi(l),h=he(l,"textConfig"),p=he(l,"imageSlot"),m=he(l,"image"),g=he(l,"buttonPreset"),b=he(l,"gridView"),I=he(l,"genericSlot"),x=he(l,"footerSlot"),$=he(l,"cursorConfig"),P=he(l,"keyHint"),V=he(l,"containerNodeSlot"),X=he(l,"templateRefSlot"),Z=he(l,"effectSlot"),j=he(l,"fullscreenEffectSlot"),O=H(f,{id:n.get(l.id?.id),guid:l.id?.id||0,giaInfoIndex:(l.ui?.content?.info||[]).find(v=>v.field501===2&&v.field502===6)?.index?.value,giaRelatedGuids:(l.ui?.content?.info||[]).find(v=>v.field501===4&&v.field502===4)?.related?.value||[],name:l.name||f,scriptMappingIds:(I?.field502||[]).map(v=>Number(v?.field1?.id)).filter(v=>Number.isSafeInteger(v)&&v>0),transformByPlatform:Qa(l),syncAllDevices:he(l,"transform")?.multiPlatform?.field504===1,giaRaw:{genericField501:I?.field501??0,footerField505:x?.field505??0,...f==="container"?{containerNodeSlot:V??""}:{},...f==="textbox"||f==="textwindow"?{textField501:h?.field501??20,textField503:h?.field503??12,textAlign:h?.align??0,...f==="textwindow"?{textField511:h?.field511??1,textViewField502:h?.viewFlags?.field502??1,textViewField503:h?.viewFlags?.field503??1}:{}}:{},...f==="cursor"?{cursorField501:$?.field501??1}:{},...f==="reference"?{templateRefSlot:X??""}:{},...f==="grid"?{gridField501:b?.field501??1,gridField507:b?.field507??1,gridField508:b?.field508??1,gridField509:b?.field509??1,gridField511:b?.field511??5,gridField512:b?.field512??1}:{},...f==="keyhint"?{keyHintField501:P?.field501??1,keyHintField502:P?.field502??1}:{},...f==="image"?{imageField502:m?.field502??1,imageField504:m?.field504??1,imageField505:m?.field505??1,imageField507:m?.field507??2,imageFillType:m?.fillType??1}:{},...f==="animation"?{effectSlot:Z??""}:{},...f==="fullscreen"?{fullscreenEffectSlot:j??""}:{}},...f==="textbox"||f==="textwindow"?{text:h?.text?.value??"",fontSize:h?.fontSize??20,minimumFontSize:h?.minimumFontSize??20,adaptiveFontSize:h?.adaptive===1,fontColor:h?.color??4294967295,bgColor:h?.color2??0,enableOutline:h?.outlineOff!==1,outlineColor:h?.color3??858993459,horizontalAlignment:h?.align===1?"Middle":h?.align===2?"Right":"Left",verticalAlignment:"Top",...f==="textwindow"?{interactable:!0,showScrollBar:!0}:{}}:{},...f==="image"?{imageSource:"StaticReference",imageId:p?.assetId??0,imageColor:Number.isFinite(p?.field502)?p.field502>>>0:4294967295,enableMask:m?.enableMask===1,enableSoftEdge:m?.enableSoftEdge===1,enableFill:m?.enableFill===1,softEdgeMode:m?.softEdgePixel===1?"Pixel":"Percentage",softEdgeWidthX:m?.border?.field501??8,softEdgeWidthY:m?.border?.field502??8,horizontalSoftRange:m?.field512??85,verticalSoftRange:m?.field513??85,fillType:{1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[m?.fillType]||"Horizontal",fillAmount:Number.isFinite(m?.field508)?Math.max(0,Math.min(1,m.field508/100)):m?.enableFill===1?0:1,reverseMaskArea:m?.reverseMask===1}:{},...f==="button"?{interactable:g?.interactable===1,raycastTarget:g?.raycastTarget===1,clickAudioId:g?.clickAudioId??50888}:{},...f==="grid"?{cellSizeX:b?.cellSize?.field501??50,cellSizeY:b?.cellSize?.field502??50,spacingX:b?.gap?.field501??8,spacingY:b?.gap?.field502??8,padding1X:b?.padding1?.field501??20,padding1Y:b?.padding1?.field502??20,padding2X:b?.padding2?.field501??20,padding2Y:b?.padding2?.field502??20,previewCount:b?.field511??5}:{},...f==="reference"?{referencedPrefabId:X??""}:{},...f==="keyhint"?{keyboardKeyCode:P?.field502??null,controllerKeyCode:P?.field501??null}:{},...f==="animation"?{animationId:Z??""}:{},...f==="fullscreen"?{animationId:j??""}:{}});r.set(l.id?.id,O),(f==="textbox"||f==="textwindow")&&![void 0,0,1,2].includes(h?.align)&&a.push(`${O.name}: \u6C34\u5E73\u5BF9\u9F50\u679A\u4E3E ${h.align} \u7684\u542B\u4E49\u672A\u77E5\uFF0C\u5DF2\u539F\u6837\u4FDD\u7559\u3002`),f==="image"&&![void 0,0,1,2,3,4,5].includes(m?.fillType)&&a.push(`${O.name}: \u586B\u5145\u5F62\u72B6\u679A\u4E3E ${m.fillType} \u672A\u8BC6\u522B\uFF0C\u5DF2\u4FDD\u7559\u539F\u503C\u3002`),f==="button"&&o.set(O.id,{unavailableChildId:g?.disabledChild,hoverChildId:g?.hoverChild,pressedChildId:g?.pressedChild,selectedChildId:g?.selectedChild})}let s=[],u=new Set;for(let l of e){let f=r.get(l.id?.id),h=(l.ui?.content?.children||[]).map(p=>r.get(p)).filter(Boolean);if(h.length){f.children=t?h.slice().reverse():h;for(let p of h)u.add(p.id)}}for(let l of e){let f=r.get(l.id?.id),h=l.ui?.content?.parent||0,p=r.get(h);p?u.has(f.id)||(t?p.children.unshift(f):p.children.push(f)):s.push(f)}for(let[l,f]of o){let h=[...r.values()].find(p=>p.id===l);for(let[p,m]of Object.entries(f))h[p]=n.get(m)||null}return{nodes:r,rootCandidates:s,warnings:a}}function $r(e){let t=di(e),i=we.toObject(we.decode(t),{longs:Number,enums:Number,bytes:Buffer,defaults:!1,arrays:!0,objects:!0}),n=i.graph||[];if(!n.some(g=>g.ui?.content))throw new Error("GIA \u4E0D\u542B\u53EF\u8BC6\u522B\u7684 UIControlGroup \u4E3B\u56FE");let r=n.find(g=>g.which===21)||null,o=n.filter(g=>Number(g.which)===70),a=i.accessories||[],s=new Set((r?.relatedIds||[]).map(g=>g.id||0)),u=r?s.size?a.filter(g=>s.has(g.id?.id||0)):a:[],l=o.length?[...o,...a.filter(g=>!s.has(g.id?.id||0))]:r?[]:[...n,...a];if(!u.length&&!l.length)throw new Error("GIA \u4E0D\u542B\u5BA2\u6237\u7AEF\u63A7\u4EF6");let f=["GIA \u5BFC\u5165\u4E3A\u5DF2\u9A8C\u8BC1 UI \u5B57\u6BB5\u7684\u8BED\u4E49\u5BFC\u5165\uFF1B\u672A\u77E5 protobuf \u5B57\u6BB5\u4E0D\u4F1A\u8FDB\u5165 Authoring JSON\u3002"],h=Fr(i);f.push(...h.warnings);let p=null,m=null;if(u.length){let g=pr(u,{reverseSiblings:!0,idOffset:0});f.push(...g.warnings);let b=g.rootCandidates.find(x=>x.kind==="container")||g.rootCandidates[0];if(!b)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6839\u63A7\u4EF6");let I=H("server-container",{id:"sc1",guid:r?.id?.id||0,name:r?.name||"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668",giaRelatedGuids:(r?.ui?.content?.info||[]).find(x=>x.field501===4&&x.field502===4)?.related?.value||[]});I.children=[b],g.rootCandidates.length>1&&f.push(`\u68C0\u6D4B\u5230 ${g.rootCandidates.length} \u4E2A\u65E0\u7236\u8282\u70B9\u63A7\u4EF6\uFF0C\u4EC5\u5BFC\u5165\u4EE5\u201C${b.name}\u201D\u4E3A\u6839\u7684\u6811\u3002`),p={version:1,layoutSchemaVersion:ue,meta:{name:r?.name||"\u5BFC\u5165\u7684\u754C\u9762\u63A7\u4EF6\u7EC4",assetType:"server-control-template",sourceFormat:"gia",sourceFile:"",gameVersion:i.gameVersion||"",giaFilePath:i.filePath||"",...Number.isSafeInteger(Number(i.modeFlag))?{giaModeFlag:Number(i.modeFlag)}:{}},canvasId:"pc-16-9",selectedId:b.id,script:{controlId:b.id,path:"",source:""},root:I}}if(l.length){let g=pr(l,{reverseSiblings:!1,idOffset:1e3});if(f.push(...g.warnings),!g.rootCandidates.length)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6A21\u677F");let b=H("server-container",{id:"sc1",guid:0,name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"});b.children=g.rootCandidates,m={version:1,layoutSchemaVersion:ue,meta:{name:g.rootCandidates.length===1?g.rootCandidates[0].name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868",assetType:"client-control-template",sourceFormat:"gia",sourceFile:"",gameVersion:i.gameVersion||"",giaFilePath:i.filePath||"",...Number.isSafeInteger(Number(i.modeFlag))?{giaModeFlag:Number(i.modeFlag)}:{}},canvasId:"pc-16-9",selectedId:g.rootCandidates[0].id,script:{controlId:g.rootCandidates[0].id,path:"",source:""},root:b},p||(p=m)}return{project:p,clientProject:m&&p!==m?m:void 0,scripts:h.scripts,warnings:f,metadata:{gameVersion:i.gameVersion||"",filePath:i.filePath||"",...Number.isSafeInteger(Number(i.modeFlag))?{modeFlag:Number(i.modeFlag)}:{},combined:!!(r&&o.length)}}}function Dr(e){let t=di(e),i=we.toObject(we.decode(t),{longs:Number,enums:Number,defaults:!1,arrays:!0,objects:!0}),n=i.graph||[],r=i.accessories||[],o=[],a=(p,m)=>p!=null&&Object.prototype.hasOwnProperty.call(p,m),s=new Map,u=[];/^\d+-\d+-\d+-\\.+\.gia$/iu.test(i.filePath||"")||o.push(`Root.filePath \u4E0D\u662F UID-TIME-ID-\\\u6587\u4EF6\u540D.gia\uFF1A${i.filePath||"<missing>"}`);let l=n.filter(p=>p.which===70).map(p=>{let m=fi(p),g=p.ui?.content?.info||[],b=g.find(P=>P.field501===2&&P.field502===6)?.index?.value,I=yr[m],x=g.find(P=>P.field501===4&&P.field502===4),$=x?.related?.value||[];return(!Number.isSafeInteger(b)||b<=0)&&o.push(`${p.name}: Info.index=${b??"<missing>"}\uFF0C\u5FC5\u987B\u662F\u6B63\u6574\u6570`),x||o.push(`${p.name}: \u9876\u5C42 UIControlTemplate \u7F3A\u5C11 Info.related \u8BB0\u5F55`),{id:p.id?.id||0,name:p.name||"",kind:m,actualIndex:b,expectedIndex:I,relatedPresent:!!x,relatedGuids:$}});l.length||o.push("Root.graph \u4E0D\u542B UIControlTemplate(70)");let f=0,h=0;for(let p of[...n,...r]){if(!p.ui?.content)continue;let m=p.id?.id||0,g=p.ui.content,b=fi(p),I=n.includes(p)&&p.which===70,x=`${p.name||"<unnamed>"}(${m||"<missing-guid>"})`;!Number.isSafeInteger(m)||m<=0||m>2147483647?o.push(`${x}: GraphUnit GUID \u975E\u6CD5`):s.has(m)?o.push(`${x}: GUID \u4E0E ${s.get(m).name||"<unnamed>"} \u91CD\u590D`):s.set(m,p),(p.id?.class!==1||p.id?.type!==8)&&o.push(`${x}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),g.guid!==m&&o.push(`${x}: content.guid=${g.guid??"<missing>"} \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`),I&&p.which!==70&&o.push(`${x}: \u6A21\u677F\u6839 which \u5FC5\u987B\u4E3A UIControlTemplate(70)`),!I&&p.which!==15&&o.push(`${x}: \u9644\u4EF6\u63A7\u4EF6 which \u5FC5\u987B\u4E3A UIControl(15)`);let $=g.info||[],P=$.find(w=>w.field501===1&&w.field502===5),V=$.find(w=>w.field501===2&&w.field502===6);P?.guid?.value!==m&&o.push(`${x}: Info.self GUID \u7F3A\u5931\u6216\u4E0E\u81EA\u8EAB\u4E0D\u4E00\u81F4`),(!Number.isSafeInteger(V?.index?.value)||V.index.value<=0)&&o.push(`${x}: Info.index=${V?.index?.value??"<missing>"}\uFF0C\u5FC5\u987B\u662F\u6B63\u6574\u6570`);let X=$.find(w=>w.field501===4&&w.field502===4);I&&!X&&o.push(`${x}: \u9876\u5C42\u6A21\u677F\u7F3A\u5C11 Info.related \u8BB0\u5F55`),!I&&X&&o.push(`${x}: \u9644\u4EF6\u63A7\u4EF6\u4E0D\u5E94\u5199 Info.related`);let Z=vr[b],j=g.data||[],O=j.map(w=>`${w.field501}/${w.field502}`),v=Z?.map(([w])=>w)||[];Z?JSON.stringify(O)!==JSON.stringify(v)&&o.push(`${x}: Data \u69FD\u4F4D\u987A\u5E8F ${O.join(",")}\uFF0C\u5E94\u4E3A ${v.join(",")}`):o.push(`${x}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${b}`);for(let w=0;w<Math.min(j.length,Z?.length||0);w+=1){let T=j[w],[z,G,ie]=Z[w];if(a(T,G)||o.push(`${x}: Data ${z} \u7F3A\u5C11 ${G} \u5206\u652F`),!ie)continue;a(T.details,ie)||o.push(`${x}: Details ${z} \u7F3A\u5C11 ${ie} \u5206\u652F`);let q=Sr[z];(T.details?.field501!==q||T.details?.field502!==T.field502||T.details?.field503!==1)&&o.push(`${x}: Details ${z} \u6807\u8BB0\u5E94\u4E3A ${q}/${T.field502}/1`);let ce=T.details?.nodeRef;(ce?.class!==1||ce?.type!==8||ce?.id!==m)&&o.push(`${x}: Details ${z} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let E=(p.ui.content.data||[]).find(w=>w.field501===4&&w.field502===86);E&&(a(E.field14,"field17")?f+=1:o.push(`${x}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`),a(E.details?.field14,"field17")?f+=1:o.push(`${x}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`));let S=(p.ui.content.data||[]).find(w=>w.details?.transform)?.details?.transform?.multiPlatform?.platforms||[];S.length!==4&&o.push(`${x}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${S.length}\uFF0C\u5E94\u4E3A 4`);let k=S.map(w=>w.platformType||0);JSON.stringify(k)!==JSON.stringify([0,1,2,3])&&o.push(`${x}: \u5E73\u53F0\u987A\u5E8F ${k.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let N=(p.ui.content.data||[]).find(w=>w.details?.transform)?.details?.transform;N?.multiPlatform?.field502!==zt[b]&&o.push(`${x}: \u53D8\u6362 preset=${N?.multiPlatform?.field502??"<missing>"}\uFF0C${b} \u5E94\u4E3A ${zt[b]}`);for(let w of S)a(w.transform,"field508")?h+=1:o.push(`${x}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);u.push({id:m,name:p.name||"",kind:b,template:I,parent:g.parent||0,children:[...g.children||[]],relatedIds:(p.relatedIds||[]).map(w=>w.id||0),dataSignatures:O})}for(let p of u){let m=`${p.name||"<unnamed>"}(${p.id})`;if(JSON.stringify(p.relatedIds)!==JSON.stringify(p.children)&&o.push(`${m}: GraphUnit.relatedIds \u4E0E content.children \u4E0D\u4E00\u81F4`),p.template&&p.parent&&o.push(`${m}: \u9876\u5C42\u6A21\u677F\u4E0D\u5E94\u6709 parent`),!p.template){let g=s.get(p.parent);g?(g.ui?.content?.children||[]).includes(p.id)||o.push(`${m}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):o.push(`${m}: parent=${p.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let g of p.children){let b=s.get(g);b?(b.ui?.content?.parent||0)!==p.id&&o.push(`${m}: child=${g} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):o.push(`${m}: child=${g} \u4E0D\u5B58\u5728`)}}return{valid:o.length===0,errors:o,filePath:i.filePath||"",gameVersion:i.gameVersion||"",templateCount:l.length,accessoryCount:r.length,templates:l,units:u,explicitEmpty:{field17:f,rectField508:h}}}function rn(e){let t=di(e),i=we.toObject(we.decode(t),{longs:Number,enums:Number,defaults:!1,arrays:!0,objects:!0}),n=(i.graph||[]).filter(w=>w.ui?.content&&Number(w.which)===21),r=(i.graph||[]).filter(w=>Number(w.which)===70),o=(i.graph||[]).filter(w=>Number(w.which)===vt),a=(i.accessories||[]).filter(w=>w.ui?.content),s=[],u=(w,T)=>w!=null&&Object.prototype.hasOwnProperty.call(w,T);/^\d+-\d+-\d+-\\.+\.gia$/iu.test(i.filePath||"")||s.push(`Root.filePath \u4E0D\u662F UID-TIME-ID-\\\u6587\u4EF6\u540D.gia\uFF1A${i.filePath||"<missing>"}`),n.length!==1&&s.push(`\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F UIControlGroup \u6570\u91CF=${n.length}\uFF0C\u5E94\u4E3A 1`);let l=(i.graph||[]).filter(w=>{let T=Number(w.which);return T===vt||T===70||T===21?!1:!w.ui?.content});l.length&&s.push(`Root.graph \u542B ${l.length} \u4E2A\u65E0\u6CD5\u8BC6\u522B\u7684\u975E\u63A7\u4EF6/\u975E\u811A\u672C\u5355\u5143`);let f=n[0];if(!f)return{valid:!1,errors:s,filePath:i.filePath||"",gameVersion:i.gameVersion||"",accessoryCount:a.length,controls:[],scriptCount:o.length,explicitEmpty:{field17:0,rectField508:0}};let h=[f,...a],p=new Map;for(let w of h){let T=w.id?.id||0,z=`${w.name||"<unnamed>"}(${T||"<missing-guid>"})`;!Number.isSafeInteger(T)||T<=0||T>2147483647?s.push(`${z}: GraphUnit GUID \u975E\u6CD5`):p.has(T)?s.push(`${z}: GUID \u91CD\u590D`):p.set(T,w),(w.id?.class!==1||w.id?.type!==8)&&s.push(`${z}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),w.ui?.content?.guid!==T&&s.push(`${z}: content.guid \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`)}let m=f.id?.id||0,g=f.ui.content,b=`${f.name||"<unnamed>"}(${m})`;f.which!==21&&s.push(`${b}: which \u5FC5\u987B\u4E3A UIControlGroup(21)`);let I=g.info||[];I.find(w=>w.field501===1&&w.field502===5)?.guid?.value!==m&&s.push(`${b}: Info.self GUID \u7F3A\u5931\u6216\u4E0D\u4E00\u81F4`),I.find(w=>w.field501===2&&w.field502===6)?.index?.value!==1&&s.push(`${b}: Info.index \u5FC5\u987B\u4E3A 1`);let x=I.find(w=>w.field501===4&&w.field502===4);x||s.push(`${b}: \u7F3A\u5C11\u663E\u5F0F Info.related \u8BB0\u5F55`);let $=0,P=0,V=(w,T,z,G=!1)=>{let ie=w.id?.id||0,q=`${w.name||"<unnamed>"}(${ie})`,ce=w.ui.content.data||[],Re=ce.map(L=>`${L.field501}/${L.field502}`),ae=z.map(([L])=>L);JSON.stringify(Re)!==JSON.stringify(ae)&&s.push(`${q}: Data \u69FD\u4F4D\u987A\u5E8F ${Re.join(",")}\uFF0C\u5E94\u4E3A ${ae.join(",")}`);for(let L=0;L<Math.min(ce.length,z.length);L+=1){let Ce=ce[L],[Ke,ii,Rt]=z[L];if(u(Ce,ii)||s.push(`${q}: Data ${Ke} \u7F3A\u5C11 ${ii} \u5206\u652F`),!Rt)continue;u(Ce.details,Rt)||s.push(`${q}: Details ${Ke} \u7F3A\u5C11 ${Rt} \u5206\u652F`);let Me=Sr[Ke];(Ce.details?.field501!==Me||Ce.details?.field502!==Ce.field502||Ce.details?.field503!==1)&&s.push(`${q}: Details ${Ke} \u6807\u8BB0\u5E94\u4E3A ${Me}/${Ce.field502}/1`);let Mt=Ce.details?.nodeRef;(Mt?.class!==1||Mt?.type!==8||Mt?.id!==ie)&&s.push(`${q}: Details ${Ke} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let ct=ce.find(L=>L.field501===4&&L.field502===(G?23:86)),Xe=G?"empty15":"field17";u(ct?.field14,Xe)?G||($+=1):s.push(`${q}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.${Xe} \u7A7A\u4E32`),u(ct?.details?.field14,Xe)?G||($+=1):s.push(`${q}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.${Xe} \u7A7A\u4E32`);let _t=ce.find(L=>L.details?.transform)?.details?.transform,ut=_t?.multiPlatform?.platforms||[];ut.length!==4&&s.push(`${q}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${ut.length}\uFF0C\u5E94\u4E3A 4`);let Pt=ut.map(L=>L.platformType||0);JSON.stringify(Pt)!==JSON.stringify([0,1,2,3])&&s.push(`${q}: \u5E73\u53F0\u987A\u5E8F ${Pt.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let Tt=G?zt["server-container"]:zt[T];_t?.multiPlatform?.field502!==Tt&&s.push(`${q}: \u53D8\u6362 preset=${_t?.multiPlatform?.field502??"<missing>"}\uFF0C\u5E94\u4E3A ${Tt}`);for(let L of ut)u(L.transform,"field508")?P+=1:s.push(`${q}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);return Re};V(f,"server-container",Ba,!0);let X=(f.relatedIds||[]).map(w=>w.id||0),Z=new Set(X),j=a.filter(w=>Z.has(w.id?.id||0)),O=j.map(w=>w.id?.id||0);JSON.stringify(X)!==JSON.stringify(O)&&s.push(`${b}: \u4E3B\u56FE relatedIds \u5FC5\u987B\u6309\u987A\u5E8F\u8986\u76D6\u672C\u7EC4 accessories`);let v=g.data?.find(w=>w.details?.rootChildRef)?.details?.rootChildRef?.guid||0,E=p.get(v);(!E||!j.includes(E))&&s.push(`${b}: 62/82 \u6839\u8282\u70B9\u5F15\u7528\u4E0D\u5B58\u5728`),O[0]!==v&&s.push(`${b}: \u6839\u5BB9\u5668\u8282\u70B9\u5FC5\u987B\u662F\u672C\u7EC4 accessories[0]`);let S=[];for(let w of j){let T=w.id?.id||0,z=w.ui.content,G=`${w.name||"<unnamed>"}(${T})`,ie=fi(w);w.which!==15&&s.push(`${G}: which \u5FC5\u987B\u4E3A UIControl(15)`);let q=z.info||[];(q.length!==1||q[0]?.field501!==1||q[0]?.field502!==5||q[0]?.guid?.value!==T)&&s.push(`${G}: \u670D\u52A1\u7AEF\u5BB9\u5668\u5185\u63A7\u4EF6 Info \u5FC5\u987B\u53EA\u542B\u81EA\u8EAB GUID`);let ce=vr[ie];ce||s.push(`${G}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${ie}`);let Re=ce?V(w,ie,ce):[];S.push({id:T,name:w.name||"",kind:ie,parent:z.parent||0,children:[...z.children||[]],relatedIds:(w.relatedIds||[]).map(ae=>ae.id||0),dataSignatures:Re})}let k=S.find(w=>w.id===v);k&&(k.kind!=="container"&&s.push(`${k.name}(${v}): \u6839\u63A7\u4EF6\u5FC5\u987B\u4E3A\u5BB9\u5668\u8282\u70B9`),k.parent&&s.push(`${k.name}(${v}): \u6839\u63A7\u4EF6\u4E0D\u5E94\u6709 parent`));let N=new Map(S.map(w=>[w.id,w]));for(let w of S){let T=`${w.name}(${w.id})`;if(JSON.stringify(w.relatedIds)!==JSON.stringify(w.children)&&s.push(`${T}: relatedIds \u5FC5\u987B\u4E0E\u76F4\u63A5 children \u4E00\u81F4`),w.id!==v){let z=N.get(w.parent);z?z.children.includes(w.id)||s.push(`${T}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):s.push(`${T}: parent=${w.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let z of w.children){let G=N.get(z);G?G.parent!==w.id&&s.push(`${T}: child=${z} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):s.push(`${T}: child=${z} \u4E0D\u5B58\u5728`)}}return{valid:s.length===0,errors:s,filePath:i.filePath||"",gameVersion:i.gameVersion||"",graph:{id:m,name:f.name||"",relatedGuids:x?.related?.value||[],rootGuid:v},accessoryCount:a.length,controls:S,scriptCount:o.length,explicitEmpty:{field17:$,rectField508:P}}}function zr(e,t=[]){if(!e||e.layoutSchemaVersion===ue)return e;if(e.layoutSchemaVersion!==void 0&&e.layoutSchemaVersion!==1)throw new Error(`\u4EC5\u652F\u6301 layoutSchemaVersion=2 \u6216\u53EF\u8FC1\u79FB\u7684\u65E7\u5E03\u5C40\uFF0C\u6536\u5230 ${e.layoutSchemaVersion}`);if(!e.root)return{...e,layoutSchemaVersion:ue};let i=structuredClone(e),n=0;return J(i.root,r=>{let o=r.transformByPlatform||{},a=r.transformByCanvas||{},s=r.name||r.id;for(let l of Object.keys(o))if(!te.includes(l))throw new Error(`${s}: unknown platform ${l}`);let u={};for(let l of te){let f=ht[l],h=U[f].platform,p=Object.keys(U).filter(I=>U[I].platform===h&&a[I]),m=a[f]?f:p[0],g=l==="CONTROLLER_CONSOLE"?u.KEYBOARD:l==="CONTROLLER_MOBILE"?u.TOUCHSCREEN:null,b=o[l]??g??(m?a[m]:null);if(u[l]=b?ke(b):Ki(r.kind),b||t.push(`${s}: ${l} \u65E0\u65E7\u5E03\u5C40\uFF0C\u5DF2\u4F7F\u7528\u63A7\u4EF6\u9ED8\u8BA4\u503C`),!o[l]&&!g&&m&&m!==f&&t.push(`${s}: \u7F3A\u5C11 ${f}\uFF0C\u5DF2\u91C7\u7528 ${m} \u7684\u951A\u70B9\u548C\u5C3A\u5BF8\u53C2\u6570`),!g)for(let I of p)JSON.stringify(u[l])!==JSON.stringify(ke(a[I]))&&t.push(`${s}: ${I} \u4E0E ${l} \u5E03\u5C40\u51B2\u7A81\uFF0C\u4FDD\u7559${o[l]?"\u5DF2\u6709\u5E73\u53F0":m}\u53C2\u6570`)}Oe(u,`${s}.transformByPlatform`),r.transformByPlatform=u,delete r.transformByCanvas,n++}),i.layoutSchemaVersion=ue,t.unshift(`\u5DF2\u81EA\u52A8\u8FC1\u79FB\u65E7\u5E03\u5C40\uFF1A${n} \u4E2A\u63A7\u4EF6\u8F6C\u6362\u4E3A\u56DB\u5E73\u53F0\u53C2\u6570\uFF1B\u518D\u6B21\u4FDD\u5B58\u5C06\u4F7F\u7528\u65B0\u7248\u683C\u5F0F`),i}function on(e){if(![1,2,3,4].includes(e))throw new Error(`\u4EC5\u652F\u6301 version=1\u20134 \u7684\u5B58\u6863\uFF0C\u6536\u5230 ${e}`)}function sn(e,t,i,n=e.canvasId){let r=De(e.root,t);return!r||r.kind==="server-container"?de(n):i[r.id]||de(n)}function Ee(e,{warnings:t=[]}={}){if(!e)return ze();if(e=zr(e,t),(e.root||e.layoutSchemaVersion!==void 0)&&e.layoutSchemaVersion!==ue)throw new Error(`\u4EC5\u652F\u6301 layoutSchemaVersion=${ue} \u7684\u56DB\u5E73\u53F0\u5E03\u5C40\uFF0C\u4E0D\u652F\u6301\u65E7\u753B\u5E03\u5E03\u5C40\u6216\u5176\u4ED6\u7248\u672C`);let i=e.meta?.assetType==="client-control-template"?"client-control-template":"server-control-template",n=i==="client-control-template"?Ze():ze(),r={layoutSchemaVersion:ue,version:Number.isSafeInteger(e.version)&&e.version>0?e.version:1,meta:{name:String(e.meta?.name||n.meta.name),assetType:i,sourceFormat:String(e.meta?.sourceFormat||n.meta.sourceFormat),sourceFile:String(e.meta?.sourceFile||""),...e.meta?.gameVersion?{gameVersion:String(e.meta.gameVersion)}:{},...e.meta?.giaFilePath?{giaFilePath:String(e.meta.giaFilePath)}:{},...Number.isSafeInteger(Number(e.meta?.giaOwnerUid))?{giaOwnerUid:Number(e.meta.giaOwnerUid)}:{},...Number.isSafeInteger(Number(e.meta?.giaTimestamp))?{giaTimestamp:Number(e.meta.giaTimestamp)}:{},...Number.isSafeInteger(Number(e.meta?.giaFileId))?{giaFileId:Number(e.meta.giaFileId)}:{},...e.meta?.giaFileName?{giaFileName:String(e.meta.giaFileName)}:{},...Number.isSafeInteger(Number(e.meta?.giaModeFlag))&&Number(e.meta.giaModeFlag)>=0?{giaModeFlag:Number(e.meta.giaModeFlag)}:{}},canvasId:e.canvasId&&U[e.canvasId]?e.canvasId:ni,selectedId:e.selectedId||n.selectedId,root:ji(e.root||n.root)};return Ur(r),r}function Ur(e){let t=new Set;J(e.root,i=>{if(typeof i.id!="string"||!i.id)throw new Error("node id must be a non-empty string");if(t.has(i.id))throw new Error(`duplicate node id: ${i.id}`);t.add(i.id)}),t.has(e.selectedId)||(e.selectedId=Wi(e.root).id)}function Gr(e){return $e(bt(e))}function es(e,t){let i=!1;return J(e,n=>{n.id===t&&(i=!0)}),i}function ts(e,t,i,n){let o=Ve(e.root,e.canvasId).boxes[t.id],a=i.children.findIndex(h=>h.id===t.id);if(a<0)throw new Error("reparent: source node is not attached");if(i.children.splice(a,1),n.children.push(t),!o)return;let s=Ve(e.root,e.canvasId),u=n.kind==="server-container"?de(e.canvasId):s.boxes[n.id]||de(e.canvasId),l=Ge(t.transformByPlatform,e.canvasId),f=We(u,l,{posX:o.centerX,posY:o.centerY,width:o.width,height:o.height});St(e,t,f)}function is(e,t){return e.meta.assetType!=="client-control-template"?qi(e.root,t):(e.root.children||[]).flatMap(i=>qi(i,t))}function Hr(e,t){let i=fr(e.root,t);if(e.meta.assetType!=="client-control-template")return i;let n=Dt(e),r=new Set;return n&&n.kind!=="server-container"&&J(n,o=>r.add(o.id)),i.filter(o=>r.has(o.id))}function Xr(e){let{canvas:t,boxes:i}=Ve(e.root,e.canvasId),n=Vt(e),r=le(e.root,e.selectedId),o=r?i[r.id]:null;return D({layoutSchemaVersion:ue,version:e.version,meta:{...e.meta},canvasId:e.canvasId,canvas:{id:e.canvasId,width:t.width,height:t.height,platform:U[e.canvasId].platform,label:U[e.canvasId].label,presets:Object.values(U).map(a=>({id:a.id,label:a.label,width:a.width,height:a.height,platform:a.platform}))},selectedId:e.selectedId,asset:{type:e.meta.assetType,label:e.meta.assetType==="client-control-template"?"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F",templateCount:e.meta.assetType==="client-control-template"?e.root.children.length:1,currentTemplateId:e.meta.assetType==="client-control-template"&&Dt(e)?.id||""},tree:is(e,n),boxes:Hr(e,i),inspector:dr(r,e.canvasId,o||t,n),root:e.root})}function St(e,t,i){let n=Ve(e.root,e.canvasId),r=sn(e,t.id,n.boxes),o={};if(t.syncAllDevices!==!1)for(let a of te){if(a===je(e.canvasId))continue;let s=ht[a],u=Ve(e.root,s,a);o[a]=sn(e,t.id,u.boxes,s)}t.transformByPlatform=ur({transformByPlatform:t.transformByPlatform,source:i,canvasId:e.canvasId,syncAllDevices:t.syncAllDevices!==!1,sourceParentBox:r,targetParentBoxByPlatform:o})}var ns=new Set(["name","active","visible","canControllerFocus","isolateNavigation","disableKeyEventPassthrough","disableCursorEventPassthrough","showCursor","fontSize","adaptiveFontSize","minimumFontSize","fontColor","bgColor","enableOutline","outlineColor","horizontalAlignment","verticalAlignment","text","imageId","imageColor","enableMask","enableSoftEdge","softEdgeMode","softEdgeWidthX","softEdgeWidthY","horizontalSoftRange","verticalSoftRange","enableFill","fillType","fillHorizontalType","fillVerticalType","fillRadial90Type","fillRadialType","fillAmount","reverseMaskArea","raycastTarget","interactable","clickAudioId","unavailableChildId","hoverChildId","pressedChildId","selectedChildId","showScrollBar","cellSizeX","cellSizeY","spacingX","spacingY","padding1X","padding1Y","padding2X","padding2Y","previewCount","scrollDirection","layoutConstraint","referencedPrefabId","animationId","keyboardKeyCode","controllerKeyCode"]),rs=new Set(["posX","posY","width","height"]),os=new Set(["anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]);function as(e){if(typeof e=="number"&&Number.isFinite(e))return e>>>0;if(typeof e=="string"){let t=e.trim();if(t.startsWith("#")){let n=t.slice(1);if(n.length===6)return(4278190080|parseInt(n,16))>>>0;if(n.length===8)return parseInt(n,16)>>>0}let i=Number(t);if(Number.isFinite(i))return i>>>0}throw new Error("color must be an ARGB integer or #RRGGBB/#AARRGGBB string")}function Pe(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function Vr(e){if(e===!0||e===1||e==="1"||e==="true")return!0;if(e===!1||e===0||e==="0"||e==="false")return!1;throw new Error("boolean field requires true or false")}var ss=new Set(["fontSize","minimumFontSize","imageId","clickAudioId","softEdgeWidthX","softEdgeWidthY","horizontalSoftRange","verticalSoftRange","fillAmount","cellSizeX","cellSizeY","spacingX","spacingY","padding1X","padding1Y","padding2X","padding2Y","previewCount","keyboardKeyCode","controllerKeyCode"]),ls=new Set(["active","visible","canControllerFocus","isolateNavigation","disableKeyEventPassthrough","disableCursorEventPassthrough","showCursor","adaptiveFontSize","enableOutline","enableMask","enableSoftEdge","enableFill","reverseMaskArea","raycastTarget","interactable","showScrollBar"]),cs=new Set(["name","horizontalAlignment","verticalAlignment","text","softEdgeMode","fillType","fillHorizontalType","fillVerticalType","fillRadial90Type","fillRadialType","scrollDirection","layoutConstraint","referencedPrefabId","animationId"]),Yr=new Set(["unavailableChildId","hoverChildId","pressedChildId","selectedChildId"]),Br={softEdgeMode:["Percentage","Pixel"],fillType:["Horizontal","Vertical","Radial90","Radial180","Radial360"],fillHorizontalType:["Left","Right"],fillVerticalType:["Bottom","Top"],fillRadial90Type:["BottomLeft","TopLeft","TopRight","BottomRight"],fillRadialType:["Bottom","Left","Top","Right"]};function us(e,t){if(!t||typeof t!="object")throw new Error("patch requires op");let i=t.op;if(i==="select")return t.id&&le(e.root,t.id)&&(e.selectedId=t.id),e;if(i==="pick"){let{boxes:n}=Ve(e.root,e.canvasId),r=Hr(e,n),o=hr(r,Number(t.x),Number(t.y));return o&&(e.selectedId=o),e}if(i==="setCanvas")return t.canvasId&&U[t.canvasId]&&(e.canvasId=t.canvasId),e;if(i==="setScript")throw new Error("\u811A\u672C\u7531\u5B58\u6863\u7EDF\u4E00\u7BA1\u7406\uFF0C\u8BF7\u4F7F\u7528 addScript / updateScript / removeScript \u64CD\u4F5C");if(i==="newAsset"){let n=t.assetType==="client-control-template"?Ze():ze();return e.version=n.version,e.meta=n.meta,e.canvasId=n.canvasId,e.selectedId=n.selectedId,e.root=n.root,e}if(i==="addTemplate"){if(e.meta.assetType!=="client-control-template")throw new Error("\u53EA\u6709\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5DE5\u7A0B\u53EF\u4EE5\u65B0\u589E\u6A21\u677F");let n=H(t.kind,{id:Li(e.root),guid:Gr(e.root),name:t.name||`\u65B0${t.kind==="container"?"\u5BB9\u5668\u8282\u70B9":t.kind}\u6A21\u677F`});return e.root.children.push(n),e.selectedId=n.id,e}if(i==="add"){let n=le(e.root,t.parentId||e.selectedId);if(!n)throw new Error("add: parent not found");let r=sr(n,t.kind,{id:Li(e.root),guid:Gr(e.root),name:t.name});return e.selectedId=r.id,e}if(i==="reparent"){if(e.meta.assetType!=="client-control-template")throw new Error("\u5C42\u7EA7\u8C03\u6574\u4EC5\u9002\u7528\u4E8E\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5DE5\u7A0B");let n=le(e.root,t.id||e.selectedId),r=n?De(e.root,n.id):null,o=le(e.root,t.parentId);if(!n||n.kind==="server-container"||!r)throw new Error("reparent: node not found");if(!o)throw new Error("reparent: parent not found");if(o.id===n.id||es(n,o.id))throw new Error("\u63A7\u4EF6\u4E0D\u80FD\u79FB\u52A8\u5230\u81EA\u8EAB\u6216\u5176\u540E\u4EE3\u4E0B\u9762");if(o.kind==="server-container"&&r.kind==="server-container")return e;if(r.kind==="server-container"&&o.kind!=="server-container"&&e.root.children.length<=1)throw new Error("\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868\u81F3\u5C11\u4FDD\u7559\u4E00\u4E2A\u9876\u5C42\u6A21\u677F");return ts(e,n,r,o),e.selectedId=n.id,e}if(i==="moveSibling"){let n=le(e.root,t.id||e.selectedId),r=n?De(e.root,n.id):null;if(!n||!r)throw new Error("moveSibling: node not found");let o=r.children.findIndex(u=>u.id===n.id),a=t.direction==="up"?-1:t.direction==="down"?1:0,s=o+a;return!a||s<0||s>=r.children.length||(r.children.splice(o,1),r.children.splice(s,0,n),e.selectedId=n.id),e}if(i==="remove"){let n=t.id||e.selectedId,r=De(e.root,n);if(r?.kind==="server-container"){if(e.meta.assetType!=="client-control-template")throw new Error("\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F\u7684\u5BA2\u6237\u7AEF\u6839\u8282\u70B9\u4E0D\u80FD\u5220\u9664");if((e.root.children||[]).length<=1)throw new Error("\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868\u81F3\u5C11\u4FDD\u7559\u4E00\u4E2A\u6A21\u677F")}return lr(e.root,n)&&(J(e.root,o=>{if(o.kind==="button")for(let a of Yr)o[a]&&!le(e.root,o[a])&&(o[a]=null)}),e.selectedId=r?r.id:e.root.id),e}if(i==="set"){let n=le(e.root,t.id||e.selectedId);if(!n)throw new Error("set: node not found");let r=t.key;r==="reverseMask"&&(r="reverseMaskArea");let o=t.value;if(r.startsWith("giaRaw.")){let l=r.slice(7);if(!l||l.includes("."))throw new Error("invalid raw GIA field path");let f=rr(n.kind,l);if(!f)throw new Error(`unknown raw GIA field for ${n.kind}: ${l}`);if(n.giaRaw||={},n.giaRaw[l]=Bi(f,o),(n.kind==="textbox"||n.kind==="textwindow")&&l==="textAlign"){let h={0:"Left",1:"Middle",2:"Right"}[n.giaRaw[l]];h&&(n.horizontalAlignment=h)}if(n.kind==="image"&&l==="imageFillType"){let h={1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[n.giaRaw[l]];h&&(n.fillType=h)}return n.kind==="keyhint"&&l==="keyHintField502"&&(n.keyboardKeyCode=n.giaRaw[l]),n.kind==="keyhint"&&l==="keyHintField501"&&(n.controllerKeyCode=n.giaRaw[l]),e}if(r==="syncAllDevices"){if(n.syncAllDevices=Vr(o),n.syncAllDevices){let l=Ge(n.transformByPlatform,e.canvasId);St(e,n,l)}return e}if(ns.has(r)){if(r.endsWith("Color")&&(o=as(o)),ss.has(r)){if(o=Pe(o,r),o<0)throw new Error(`${r} must not be negative`);if((r==="imageId"||r==="clickAudioId"||r==="keyboardKeyCode"||r==="controllerKeyCode")&&(o=Math.trunc(o)),r==="fillAmount"&&o>1)throw new Error("fillAmount must be between 0 and 1")}if(ls.has(r)&&(o=Vr(o)),cs.has(r)&&(o=String(o??"")),r==="horizontalAlignment"&&!["Left","Middle","Right"].includes(o))throw new Error("invalid horizontalAlignment");if(r==="verticalAlignment"&&!["Top","Middle","Bottom"].includes(o))throw new Error("invalid verticalAlignment");if(Br[r]&&!Br[r].includes(o))throw new Error(`invalid ${r}`);if(Yr.has(r))if(o===""||o===void 0||o===null)o=null;else{o=String(o);let l=le(e.root,o);if(!l||l===n||l.kind==="server-container"||!(n.children||[]).some(f=>f.id===o))throw new Error(`${r} must reference a direct child of this button`)}if(n[r]=o,(n.kind==="textbox"||n.kind==="textwindow")&&r==="horizontalAlignment"&&(n.giaRaw.textAlign={Left:0,Middle:1,Right:2}[o]),n.kind==="image"&&r==="fillType"){let l={Horizontal:1,Vertical:2,Radial90:3,Radial180:4,Radial360:5}[o];l&&(n.giaRaw.imageFillType=l)}return n.kind==="reference"&&r==="referencedPrefabId"&&(n.giaRaw.templateRefSlot=o),n.kind==="grid"&&r==="previewCount"&&(n.giaRaw.gridField511=Math.trunc(o)),n.kind==="keyhint"&&r==="keyboardKeyCode"&&(n.giaRaw.keyHintField502=Math.trunc(o)),n.kind==="keyhint"&&r==="controllerKeyCode"&&(n.giaRaw.keyHintField501=Math.trunc(o)),(n.kind==="animation"||n.kind==="fullscreen")&&r==="animationId"&&(n.giaRaw[n.kind==="animation"?"effectSlot":"fullscreenEffectSlot"]=o),e}let{boxes:a}=Ve(e.root,e.canvasId),s=sn(e,n.id,a),u=Ge(n.transformByPlatform,e.canvasId);if(r==="anchorType"){let l=an(a[n.id]),f=Qn(u,o);return f=We(s,f,l),St(e,n,f),e}if(r==="rotationZ"){let l={...u,rotation:{...u.rotation,z:Pe(o,r)}};return St(e,n,l),e}if(os.has(r)){let l=an(a[n.id]),f={...u,anchorMin:{...u.anchorMin},anchorMax:{...u.anchorMax},pivot:{...u.pivot}};return r==="anchorMinX"&&(f.anchorMin.x=Pe(o,r)),r==="anchorMinY"&&(f.anchorMin.y=Pe(o,r)),r==="anchorMaxX"&&(f.anchorMax.x=Pe(o,r)),r==="anchorMaxY"&&(f.anchorMax.y=Pe(o,r)),r==="pivotX"&&(f.pivot.x=Pe(o,r)),r==="pivotY"&&(f.pivot.y=Pe(o,r)),St(e,n,We(s,f,l)),e}if(rs.has(r)){let l=an(a[n.id]),f=Pe(o,r);if((r==="width"||r==="height")&&f<0)throw new Error(`${r} must not be negative`);return l[r]=f,St(e,n,We(s,u,l)),e}throw new Error(`set: unknown key ${r}`)}if(i==="replace"){let n=Ee(t.project);return e.version=n.version,e.meta=n.meta,e.canvasId=n.canvasId,e.selectedId=n.selectedId,e.root=n.root,e}throw new Error(`unknown op ${i}`)}function ln(e,t){if(!t||typeof t!="object")throw new Error("patch requires op");if(t.expectedRevision!==void 0&&Number(t.expectedRevision)!==e.version)throw new Error(`revision conflict: expected ${t.expectedRevision}, current ${e.version}`);let i=e.version,n=JSON.parse(JSON.stringify(e));return us(n,t),Ur(n),n.version=i+1,Object.keys(e).forEach(r=>{delete e[r]}),Object.assign(e,n),e}function an(e){return e?{posX:e.centerX,posY:e.centerY,width:e.width,height:e.height}:{posX:0,posY:0,width:0,height:0}}import fs from"fengari";var{lua:c,lauxlib:re,lualib:Kr,to_luastring:hi,to_jsstring:ds}=fs,hs=c.LUA_TNIL,ps=c.LUA_TBOOLEAN,ms=c.LUA_TNUMBER,gs=c.LUA_TSTRING,Lr=c.LUA_TTABLE,ys=c.LUA_TFUNCTION,cn=c.LUA_TUSERDATA,Ae=c.LUA_OK,Wr=new WeakMap,un=Symbol("luaTableEntries"),fn={__scriptHostKey:!0};function _(e){return hi(String(e))}function Qe(e,t){Wr.set(e,t)}function be(e){return Wr.get(e)}function ne(e,t,i){if(i==null){c.lua_pushnil(e);return}let n=typeof i;if(n==="boolean"){c.lua_pushboolean(e,i);return}if(n==="number"){Number.isInteger(i)&&Math.abs(i)<=2147483647?c.lua_pushinteger(e,i):c.lua_pushnumber(e,i);return}if(n==="string"){c.lua_pushstring(e,_(i));return}if(n==="function"){Ss(e,t,i);return}if(i&&i[un]){let r=i[un];c.lua_createtable(e,Array.isArray(i)?i.length:0,r.length);for(let[o,a]of r)ne(e,t,o),ne(e,t,a),c.lua_settable(e,-3);return}if(Array.isArray(i)){c.lua_createtable(e,i.length,0);for(let r=0;r<i.length;r++)ne(e,t,i[r]),c.lua_rawseti(e,-2,r+1);return}if(i&&i.__kind==="EnumItem"){t.pushEnumItem(e,i);return}if(i&&i.__kind==="CursorEventData"){t.pushCursor(e,i);return}if(i&&i.__kind==="Script"){t.pushScript(e,i);return}if(i&&i.typeofName){t.pushControl(e,i);return}if(i&&i.SetEase){t.pushTween(e,i);return}if(n==="object"){c.lua_createtable(e,0,Object.keys(i).length);for(let[r,o]of Object.entries(i))ne(e,t,o),c.lua_setfield(e,-2,_(r));return}c.lua_pushnil(e)}function W(e,t){if(c.lua_isnil(e,t)||c.lua_type(e,t)===c.LUA_TNONE)return"";if(!c.lua_isstring(e,t)&&c.lua_type(e,t)!==c.LUA_TNUMBER)return`lua_type=${c.lua_type(e,t)}`;let i=c.lua_tostring(e,t);return i==null?"":ds(i)}function Be(e,t){t=c.lua_absindex(e,t);let i=c.lua_type(e,t);if(i===cn)return be(c.lua_touserdata(e,t));if(i===Lr){c.lua_pushlightuserdata(e,fn),c.lua_rawget(e,t);let n=c.lua_type(e,-1)===cn?c.lua_touserdata(e,-1):null;return c.lua_pop(e,1),n?be(n):null}return null}function pe(e,t,i){i=c.lua_absindex(e,i);let n=c.lua_type(e,i);if(n===hs)return null;if(n===ps)return!!c.lua_toboolean(e,i);if(n===ms)return c.lua_isinteger(e,i)?c.lua_tointeger(e,i):c.lua_tonumber(e,i);if(n===gs)return W(e,i);if(n===cn){let r=c.lua_touserdata(e,i);return be(r)??r}if(n===ys)return bs(e,t,i);if(n===Lr){let r=Be(e,i);if(r)return r;let o=[];for(c.lua_pushnil(e);c.lua_next(e,i)!==0;){let l=pe(e,t,-2),f=pe(e,t,-1);o.push([l,f]),c.lua_pop(e,1)}let a=new Map(o.filter(([l])=>Number.isInteger(l)&&l>=1)),s=0;for(;a.has(s+1);)s+=1;let u=s>0?[]:{};for(let[l,f]of o)Array.isArray(u)&&Number.isInteger(l)&&l>=1?u[l-1]=f:(typeof l=="string"||typeof l=="number")&&(u[l]=f);return Object.defineProperty(u,un,{value:o}),u}return null}function bs(e,t,i){t.luaFunctions||(t.luaFunctions=new Map);let n=typeof c.lua_topointer=="function"?c.lua_topointer(e,i):null;if(n!=null&&t.luaFunctions.has(n))return t.luaFunctions.get(n);c.lua_pushvalue(e,i);let r=re.luaL_ref(e,c.LUA_REGISTRYINDEX),o=vs(e,t,r);return n!=null&&t.luaFunctions.set(n,o),o}function vs(e,t,i){let n=(...r)=>{let o=c.lua_gettop(e);c.lua_rawgeti(e,c.LUA_REGISTRYINDEX,i);for(let l of r)ne(e,t,l);if(c.lua_pcall(e,r.length,c.LUA_MULTRET,0)!==Ae){let l=W(e,-1);throw c.lua_settop(e,o),new Error(l)}let s=c.lua_gettop(e)-o,u=[];for(let l=1;l<=s;l++)u.push(pe(e,t,o+l));if(c.lua_settop(e,o),u.length!==0)return u.length===1?u[0]:u};return n.__luaRef=i,n.__luaState=e,n}function jr(e,t){if(!t||t.__luaRef==null||!t.__luaState)return;let i=t.__luaState;if((!e?.luaStates||e.luaStates.has(i))&&re.luaL_unref(i,c.LUA_REGISTRYINDEX,t.__luaRef),t.__luaRef=null,t.__luaState=null,e?.luaFunctions)for(let[n,r]of e.luaFunctions)r===t&&e.luaFunctions.delete(n)}function Ss(e,t,i){c.lua_pushlightuserdata(e,i),c.lua_pushlightuserdata(e,t),c.lua_pushcclosure(e,function(r){let o=c.lua_touserdata(r,c.lua_upvalueindex(1)),a=c.lua_touserdata(r,c.lua_upvalueindex(2)),s=c.lua_gettop(r),u=[];for(let l=1;l<=s;l++)u.push(pe(r,a,l));try{let l=o(...u);if(Array.isArray(l)&&l.__multi){for(let f of l)ne(r,a,f);return l.length}return l===void 0?0:(ne(r,a,l),1)}catch(l){return c.lua_pushstring(r,_(String(l&&l.message?l.message:l))),c.lua_error(r)}},2)}function qr(e){!e||typeof c.lua_close!="function"||c.lua_close(e)}function Jr(e){if(re.luaL_loadstring(e,_(["local nativeGetMetatable = getmetatable","getmetatable = function(value)",' if type(value) == "string" then return nil end'," return nativeGetMetatable(value)","end"].join(`
|
|
106
106
|
`)))===Ae&&c.lua_pcall(e,0,0,0),c.lua_settop(e,0),c.lua_pushnil(e),c.lua_setglobal(e,_("_VERSION")),c.lua_getglobal(e,_("string")),!c.lua_isnil(e,-1))for(let i of["dump","pack","unpack"])c.lua_pushnil(e),c.lua_setfield(e,-2,_(i));if(c.lua_pop(e,1),c.lua_pushnil(e),c.lua_setglobal(e,_("io")),c.lua_getglobal(e,_("os")),!c.lua_isnil(e,-1))for(let i of Object.keys({execute:1,getenv:1,remove:1,rename:1,tmpname:1,setlocale:1,exit:1}))c.lua_pushnil(e),c.lua_setfield(e,-2,_(i));c.lua_pop(e,1),c.lua_getglobal(e,_("debug")),c.lua_isnil(e,-1)?c.lua_pop(e,1):(c.lua_getfield(e,-1,_("traceback")),c.lua_newtable(e),c.lua_pushvalue(e,-2),c.lua_setfield(e,-2,_("traceback")),c.lua_setglobal(e,_("debug")),c.lua_pop(e,2)),c.lua_getglobal(e,_("math")),c.lua_isnil(e,-1)||(c.lua_pushcfunction(e,i=>{let n=c.lua_tonumber(i,1);return c.lua_pushboolean(i,Number.isNaN(n)),1}),c.lua_setfield(e,-2,_("isnan")),c.lua_pushcfunction(e,i=>{let n=c.lua_tonumber(i,1);return c.lua_pushboolean(i,n===1/0||n===-1/0),1}),c.lua_setfield(e,-2,_("isinf"))),c.lua_pop(e,1),c.lua_pushnil(e),c.lua_setglobal(e,_("package")),c.lua_pushnil(e),c.lua_setglobal(e,_("load")),c.lua_pushnil(e),c.lua_setglobal(e,_("loadfile")),c.lua_pushnil(e),c.lua_setglobal(e,_("dofile")),c.lua_pushnil(e),c.lua_setglobal(e,_("collectgarbage")),c.lua_pushnil(e),c.lua_setglobal(e,_("coroutine")),c.lua_pushnil(e),c.lua_setglobal(e,_("fengari"))}var Zr={container:"ClientUIContainerControl",textbox:"ClientUITextBoxControl",textwindow:"ClientUITextWindowControl",image:"ClientUIImageControl",button:"ClientUIPresetButtonControl",cursor:"ClientUICursorEventAreaControl",grid:"ClientUIGridScrollerControl",keyhint:"ClientUIKeyHintControl",animation:"ClientUIAnimationControl",fullscreen:"ClientUIFullscreenAnimationControl",reference:"ClientUIReferenceControl"},ws=["alive","Id","prefabIndex","active","activeInHierarchy","visible"],pi=new Set(["active","visible","parent","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]),Is=["name","parent","anchoredPositionX","anchoredPositionY","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY","localScaleX","localScaleY","localScaleZ","localRotationX","localRotationY","localRotationZ","canControllerFocus"],Cs={image:["imageSource","imageId"],grid:["itemCount","scrollDirection","layoutConstraint","layoutConstraintFixedCount"],reference:["referencedPrefabIndex"]},ks={container:["isolateNavigation","disableKeyEventPassthrough","disableCursorEventPassthrough","showCursor"],textbox:["text","fontSize","fontColor","bgColor","enableOutline","outlineColor","horizontalAlignment","verticalAlignment","adaptiveFontSize","minimumFontSize"],textwindow:["interactable","showScrollBar","text","fontSize","fontColor","bgColor","enableOutline","outlineColor","horizontalAlignment","verticalAlignment","adaptiveFontSize","minimumFontSize"],image:["imageColor","enableMask","enableSoftEdge","softEdgeMode","softEdgeWidthX","softEdgeWidthY","horizontalSoftRange","verticalSoftRange","reverseMaskArea","fillType","fillHorizontalType","fillVerticalType","fillRadial90Type","fillRadialType","fillAmount"],button:["interactable","clickAudioId","raycastTarget"],cursor:["raycastTarget"],grid:["itemPrefabIndex","raycastTarget","showScrollBar","interactable","scrollProgress"],keyhint:["keyboardKeyCode","controllerKeyCode"],animation:["animationId","playSoundEffect","layer"],fullscreen:["animationId","playSoundEffect"]},xs=["GetChildren","GetChild","FindChild","SetActive","SetVisible","GetSiblingIndex","SetSiblingIndex","SetAsFirstSibling","SetAsLastSibling","GetAnchoredPosition","SetAnchoredPosition","GetSizeDelta","SetSizeDelta","GetAnchorMin","SetAnchorMin","GetAnchorMax","SetAnchorMax","GetPivot","SetPivot","GetLocalScale","SetLocalScale","GetLocalRotation","SetLocalRotation","GetScriptByPath","GetScript","GetScripts","AddKeyEventListener","RemoveKeyEventListener","RemoveKeyEventListeners","RemoveAllKeyEventListeners","AddNavigationEventListener","RemoveNavigationEventListener","RemoveNavigationEventListeners","RemoveAllNavigationEventListeners","SetControllerNavigation","GetControllerNavigation"],Qr=["AddCursorEventListener","RemoveCursorEventListener","RemoveCursorEventListeners","RemoveAllCursorEventListeners","SimulateCursorClick"],Es={image:["SetImage","SetSoftEdgeWidth","SetFillUnused","SetFillHorizontal","SetFillVertical","SetFillRadial90","SetFillRadial180","SetFillRadial360"],button:Qr,cursor:Qr,animation:["PlayAnimation","StopAnimation"],grid:["RefreshItems","GetItemIndex","GetItemSize","GetItemSpacing","GetPadding","ScrollToItemAt","GetContentLength"]};function dn(e,t){return ws.includes(t)||(Cs[e.kind]||[]).includes(t)?"ro":Is.includes(t)||(ks[e.kind]||[]).includes(t)?"rw":null}function eo(e,t){return xs.includes(t)||(Es[e.kind]||[]).includes(t)}var As={container:{isolateNavigation:!1,disableKeyEventPassthrough:!1,disableCursorEventPassthrough:!1,showCursor:!1},textbox:{text:"",fontSize:20,fontColor:4294967295,bgColor:0,enableOutline:!1,outlineColor:0,horizontalAlignment:null,verticalAlignment:null,adaptiveFontSize:!1,minimumFontSize:10},textwindow:{interactable:!0,showScrollBar:!0,text:"",fontSize:20,fontColor:4294967295,bgColor:0,enableOutline:!1,outlineColor:0,horizontalAlignment:null,verticalAlignment:null,adaptiveFontSize:!1,minimumFontSize:10},image:{imageSource:null,imageId:0,imageColor:4294967295,imageType:null,enableMask:!1,enableSoftEdge:!1,softEdgeMode:"Percentage",softEdgeWidthX:8,softEdgeWidthY:8,horizontalSoftRange:85,verticalSoftRange:85,enableFill:!1,fillType:"Unused",fillHorizontalType:"Left",fillVerticalType:"Bottom",fillRadial90Type:"BottomLeft",fillRadialType:"Bottom",reverseMaskArea:!1,fillAmount:1},button:{interactable:!0,clickAudioId:0,raycastTarget:!0,unavailableChildId:null,hoverChildId:null,pressedChildId:null,selectedChildId:null,pressed:!1},cursor:{raycastTarget:!0},grid:{itemCount:0,itemPrefabIndex:null,raycastTarget:!0,interactable:!0,showScrollBar:!0,scrollDirection:"Vertical",layoutConstraint:"AutoWrap",layoutConstraintFixedCount:null,scrollProgress:0,cellSizeX:50,cellSizeY:50,spacingX:8,spacingY:8,padding1X:20,padding1Y:20,padding2X:20,padding2Y:20,previewCount:5},keyhint:{keyboardKeyCode:null,controllerKeyCode:null},animation:{animationId:null,playSoundEffect:null,layer:null,raycastTarget:!1},fullscreen:{animationId:null,playSoundEffect:null,raycastTarget:!1},reference:{referencedPrefabIndex:null}},Ue=class e{constructor(t,i){this.runtime=t,this.kind=i.kind||"container",this.typeofName=Zr[this.kind]||Zr.container,this.alive=!0,this.Id=i.Id??t.nextControlId(),this.authoringId=i.authoringId??null,this.prefabIndex=i.prefabIndex??0,this.name=i.name??"",this.active=i.active===!0,this.visible=i.visible!==!1,this._parent=null,this.children=[],this.scripts=[],this.cursorListeners=new Map,this.keyListeners=new Map,this.navListeners=new Map,this.navConfig=new Map,this.anchoredPositionX=i.anchoredPositionX??0,this.anchoredPositionY=i.anchoredPositionY??0,this.sizeDeltaX=i.sizeDeltaX??0,this.sizeDeltaY=i.sizeDeltaY??0,this.anchorMinX=i.anchorMinX??.5,this.anchorMinY=i.anchorMinY??.5,this.anchorMaxX=i.anchorMaxX??.5,this.anchorMaxY=i.anchorMaxY??.5,this.pivotX=i.pivotX??.5,this.pivotY=i.pivotY??.5,this.localScaleX=i.localScaleX??1,this.localScaleY=i.localScaleY??1,this.localScaleZ=i.localScaleZ??1,this.localRotationX=i.localRotationX??0,this.localRotationY=i.localRotationY??0,this.localRotationZ=i.localRotationZ??0,this.canControllerFocus=i.canControllerFocus??!1,this._playDirty=!0,this._playDeepDirty=!0,this._playChildDirty=!1;let n=As[this.kind]||{};for(let[r,o]of Object.entries(n))this[r]===void 0&&(this[r]=i[r]!==void 0?i[r]:o);if(i.children)for(let r of i.children){let o=r instanceof e?r:new e(t,r);this.addChild(o)}}get parent(){return this._parent}set parent(t){if(this._parent===t)return;if(t!==null&&!(t instanceof e))throw new Error("parent must be a Control or nil");if(t&&t.runtime!==this.runtime)throw new Error("parent must belong to the same runtime");if(t===this)throw new Error("cannot parent a control to itself or its descendant");for(let n=t;n;n=n._parent)if(n===this)throw new Error("cannot parent a control to itself or its descendant");let i=this._parent;if(i){let n=i.children.indexOf(this);n>=0&&i.children.splice(n,1),i.markPlayDirty(!0)}else{let n=this.runtime.roots.indexOf(this);n>=0&&this.runtime.roots.splice(n,1)}this._parent=t,this.markPlayDirty(!0),t&&!t.children.includes(this)?(t.children.push(this),t.markPlayDirty(!0)):!t&&this.alive&&!this.runtime.roots.includes(this)&&this.runtime.roots.push(this)}markPlayDirty(t=!1){this._playDirty=!0,t&&(this._playDeepDirty=!0);for(let i=this._parent;i&&!i._playChildDirty;i=i._parent)i._playChildDirty=!0}get activeInHierarchy(){return this.active?this._parent?this._parent.activeInHierarchy:!0:!1}addChild(t){return t.parent=this,t}GetChildren(){return this.children.slice()}GetChild(t){return this.children.find(i=>i.name===t)||null}FindChild(t){if(!t)return null;if(!t.includes("/"))return this.GetChild(t);let i=t.split("/").filter(Boolean),n=this;for(let r of i)if(n=n.GetChild(r),!n)return null;return n}SetActive(t){let i=!!t;if(this.active!==i){if(typeof this.runtime?.onControlActiveChanging=="function"){this.runtime.onControlActiveChanging(this,i);return}this.active=i,this.markPlayDirty(!0)}}SetVisible(t){this.visible=!!t,this.markPlayDirty(!0)}GetSiblingIndex(){if(!this._parent)return-1;let t=this._parent.children,i=t.indexOf(this);return i<0?-1:t.length-1-i}SetSiblingIndex(t){if(!this._parent)return!1;let i=this._parent.children,n=i.indexOf(this);if(n<0)return!1;let r=i.length-1;return!Number.isInteger(t)||t<0||t>r?!1:(i.splice(n,1),i.splice(r-t,0,this),this._parent.markPlayDirty(!0),this.markPlayDirty(),!0)}SetAsFirstSibling(){return this.SetSiblingIndex(0)}SetAsLastSibling(){return this._parent?this.SetSiblingIndex(this._parent.children.length-1):!1}GetAnchoredPosition(){return[this.anchoredPositionX,this.anchoredPositionY]}SetAnchoredPosition(t,i){this.anchoredPositionX=t,this.anchoredPositionY=i,this.markPlayDirty()}GetSizeDelta(){return[this.sizeDeltaX,this.sizeDeltaY]}SetSizeDelta(t,i){this.sizeDeltaX=t,this.sizeDeltaY=i,this.markPlayDirty(!0)}GetAnchorMin(){return[this.anchorMinX,this.anchorMinY]}SetAnchorMin(t,i){this.anchorMinX=t,this.anchorMinY=i,this.markPlayDirty(!0)}GetAnchorMax(){return[this.anchorMaxX,this.anchorMaxY]}SetAnchorMax(t,i){this.anchorMaxX=t,this.anchorMaxY=i,this.markPlayDirty(!0)}GetPivot(){return[this.pivotX,this.pivotY]}SetPivot(t,i){this.pivotX=t,this.pivotY=i,this.markPlayDirty(!0)}GetLocalScale(){return[this.localScaleX,this.localScaleY,this.localScaleZ]}SetLocalScale(t,i,n){this.localScaleX=t,this.localScaleY=i,this.localScaleZ=n,this.markPlayDirty()}GetLocalRotation(){return[this.localRotationX,this.localRotationY,this.localRotationZ]}SetLocalRotation(t,i,n){this.localRotationX=t,this.localRotationY=i,this.localRotationZ=n,this.markPlayDirty()}GetScriptByPath(t){return this.scripts.find(i=>i.path===t)||null}GetScript(t){return this.scripts.find(i=>i.scriptMappingId===t)||null}GetScripts(){return this.scripts.slice()}_addListener(t,i,n){let r=t.get(i)||[];r.push(n),t.set(i,r)}_removeListener(t,i,n){let r=t.get(i);r&&(t.set(i,r.filter(o=>o!==n)),this.runtime.unrefLuaCallback?.(n))}_removeListeners(t,i){let n=t.get(i)||[];for(let r of n)this.runtime.unrefLuaCallback?.(r);t.delete(i)}_removeAllListeners(t){for(let i of t.values())for(let n of i)this.runtime.unrefLuaCallback?.(n);t.clear()}AddCursorEventListener(t,i){this._addListener(this.cursorListeners,t,i)}RemoveCursorEventListener(t,i){this._removeListener(this.cursorListeners,t,i)}RemoveCursorEventListeners(t){this._removeListeners(this.cursorListeners,t)}RemoveAllCursorEventListeners(){this._removeAllListeners(this.cursorListeners)}SimulateCursorClick(){let t=this.runtime.makeCursorEventData({x:0,y:0,pressX:0,pressY:0});this.emitCursor("CursorDown",t),this.emitCursor("CursorUp",t),this.emitCursor("CursorClick",t)}emitCursor(t,i){if(!this.runtime.cursorEventsEnabled(this))return;let n=this.cursorListeners.get(t)||[];for(let r of n)r(i)}AddKeyEventListener(t,i){this._addListener(this.keyListeners,t,i)}RemoveKeyEventListener(t,i){this._removeListener(this.keyListeners,t,i)}RemoveKeyEventListeners(t){this._removeListeners(this.keyListeners,t)}RemoveAllKeyEventListeners(){this._removeAllListeners(this.keyListeners)}emitKey(t){let i=this.keyListeners.get(t)||[];for(let n of i)if(n()===!0)break}AddNavigationEventListener(t,i){this._addListener(this.navListeners,t,i)}RemoveNavigationEventListener(t,i){this._removeListener(this.navListeners,t,i)}RemoveNavigationEventListeners(t){this._removeListeners(this.navListeners,t)}RemoveAllNavigationEventListeners(){this._removeAllListeners(this.navListeners)}SetControllerNavigation(t,i,n){this.navConfig.set(t,{mode:i,target:n})}GetControllerNavigation(t){let i=this.navConfig.get(t),n=i?[i.mode,i.target]:[null,null];return n.__multi=!0,n}SetImage(t,i){this.imageSource=t,this.imageId=i,this.markPlayDirty()}SetSoftEdgeWidth(t,i){this.softEdgeWidthX=t,this.softEdgeWidthY=i,this.markPlayDirty()}SetFillUnused(){this.fillType="Unused",this.markPlayDirty()}SetFillHorizontal(t,i){this.fillType="Horizontal",this.fillHorizontalType=t,this.fillAmount=i,this.markPlayDirty()}SetFillVertical(t,i){this.fillType="Vertical",this.fillVerticalType=t,this.fillAmount=i,this.markPlayDirty()}SetFillRadial90(t,i){this.fillType="Radial90",this.fillRadial90Type=t,this.fillAmount=i,this.markPlayDirty()}SetFillRadial180(t,i){this.fillType="Radial180",this.fillRadialType=t,this.fillAmount=i,this.markPlayDirty()}SetFillRadial360(t,i){this.fillType="Radial360",this.fillRadialType=t,this.fillAmount=i,this.markPlayDirty()}PlayAnimation(){}StopAnimation(){}RefreshItems(){throw new Error("ClientUIGridScrollerControl:RefreshItems not implemented")}GetItemIndex(){throw new Error("ClientUIGridScrollerControl:GetItemIndex not implemented")}GetItemSize(){throw new Error("ClientUIGridScrollerControl:GetItemSize not implemented")}GetItemSpacing(){throw new Error("ClientUIGridScrollerControl:GetItemSpacing not implemented")}GetPadding(){throw new Error("ClientUIGridScrollerControl:GetPadding not implemented")}ScrollToItemAt(){throw new Error("ClientUIGridScrollerControl:ScrollToItemAt not implemented")}GetContentLength(){throw new Error("ClientUIGridScrollerControl:GetContentLength not implemented")}};function Ie(e,t){t(e);for(let i of e.children)Ie(i,t)}function hn(e,t=[],i=""){t.push(`${i}${e.name||"(unnamed)"} [${e.typeofName}] Id=${e.Id}`);for(let n of e.children)hn(n,t,i+" ");return t}function mi(e){return e<1/2.75?7.5625*e*e:e<2/2.75?7.5625*(e-=1.5/2.75)*e+.75:e<2.5/2.75?7.5625*(e-=2.25/2.75)*e+.9375:7.5625*(e-=2.625/2.75)*e+.984375}var to={Linear:e=>e,InSine:e=>1-Math.cos(e*Math.PI/2),OutSine:e=>Math.sin(e*Math.PI/2),InOutSine:e=>-(Math.cos(Math.PI*e)-1)/2,InQuad:e=>e*e,OutQuad:e=>1-(1-e)*(1-e),InOutQuad:e=>e<.5?2*e*e:1-(-2*e+2)**2/2,InCubic:e=>e*e*e,OutCubic:e=>1-(1-e)**3,InOutCubic:e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,InQuart:e=>e**4,OutQuart:e=>1-(1-e)**4,InOutQuart:e=>e<.5?8*e**4:1-(-2*e+2)**4/2,InQuint:e=>e**5,OutQuint:e=>1-(1-e)**5,InOutQuint:e=>e<.5?16*e**5:1-(-2*e+2)**5/2,InExpo:e=>e===0?0:2**(10*e-10),OutExpo:e=>e===1?1:1-2**(-10*e),InOutExpo:e=>e===0||e===1?e:e<.5?2**(20*e-10)/2:(2-2**(-20*e+10))/2,InCirc:e=>1-Math.sqrt(1-e**2),OutCirc:e=>Math.sqrt(1-(e-1)**2),InOutCirc:e=>e<.5?(1-Math.sqrt(1-(2*e)**2))/2:(Math.sqrt(1-(-2*e+2)**2)+1)/2,InBack:e=>(1.70158+1)*e*e*e-1.70158*e*e,OutBack:e=>1+2.70158*(e-1)**3+1.70158*(e-1)**2,InOutBack:e=>{let i=2.5949095;return e<.5?(2*e)**2*((i+1)*2*e-i)/2:((2*e-2)**2*((i+1)*(e*2-2)+i)+2)/2},InElastic:e=>e===0||e===1?e:-(2**(10*e-10))*Math.sin((e*10-10.75)*(2*Math.PI/3)),OutElastic:e=>e===0||e===1?e:2**(-10*e)*Math.sin((e*10-.75)*(2*Math.PI/3))+1,InOutElastic:e=>{if(e===0||e===1)return e;let t=2*Math.PI/4.5;return e<.5?-(2**(20*e-10)*Math.sin((20*e-11.125)*t))/2:2**(-20*e+10)*Math.sin((20*e-11.125)*t)/2+1},InBounce:e=>1-mi(1-e),OutBounce:mi,InOutBounce:e=>e<.5?(1-mi(1-2*e))/2:(1+mi(2*e-1))/2};function io(e,t){let i=to[e]||to.Linear;return t<=0?0:t>=1?1:i(t)}function wt(e,t,i,n=255){let r=gi(e),o=gi(t),a=gi(i);return((n==null?255:gi(n))<<24|r<<16|o<<8|a)>>>0}function Yt(e){let t=e>>>0;return[t>>>16&255,t>>>8&255,t&255,t>>>24&255]}function gi(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(255,Math.trunc(t))):0}function no(e,t,i){let n=Yt(e),r=Yt(t);return wt(n[0]+(r[0]-n[0])*i,n[1]+(r[1]-n[1])*i,n[2]+(r[2]-n[2])*i,n[3]+(r[3]-n[3])*i)}var _s=new Set(["fontColor","bgColor","outlineColor","imageColor"]),yi=class{constructor(t,i,n,r){this.runtime=t,this.object=i,this.data={...n},this.duration=Math.max(0,Number(r)||0),this.easeName="Linear",this.relative=!1,this.playing=!1,this.paused=!1,this.elapsed=0,this.loops=1,this.loopIndex=0,this.from={},this.to={},this.initialFrom=null,this.initialTo=null,this.onComplete=null,this.onStepComplete=null,this.killed=!1}capture(){this.from={},this.to={};for(let[t,i]of Object.entries(this.data)){let n=this.object[t];this.from[t]=n,this.to[t]=this.relative?Number(n)+Number(i):i}}restoreInitial(){this.initialFrom?(this.from={...this.initialFrom},this.to={...this.initialTo}):this.capture()}SetEase(t){return this.easeName=typeof t=="string"?t:t?.Name||"Linear",this}SetRelative(t){return this.relative=!!t,this}Play(){return this._start(!1)}_start(t){return this.playing=!0,this.paused=!1,this.elapsed=0,this.loopIndex=0,this.killed=!1,t&&this.initialFrom?this.restoreInitial():(this.capture(),this.initialFrom={...this.from},this.initialTo={...this.to}),this.runtime.tweens.add(this),this.duration===0&&this.Complete(),this}Pause(){this.paused=!0}Resume(){this.paused=!1}Restart(){return this._start(!0)}Complete(){this.apply(1),this.finish(!0)}Kill(t){t?this.Complete():this.finish(!1)}SetOnComplete(t){return this.onComplete=t,this}SetOnStepComplete(t){return this.onStepComplete=t,this}SetLoops(t){return this.loops=t,this}apply(t){let i=io(this.easeName,t),n=!1,r=!1;for(let o of Object.keys(this.to)){let a=this.from[o],s=this.to[o];_s.has(o)&&typeof a=="number"&&typeof s=="number"?this.object[o]=no(a,s,i):typeof a=="number"&&typeof s=="number"?this.object[o]=a+(s-a)*i:this.object[o]=i>=1?s:a,n=!0,pi.has(o)&&(r=!0)}n&&typeof this.object?.markPlayDirty=="function"&&this.object.markPlayDirty(r)}step(t){if(!this.playing||this.paused||this.killed)return;this.elapsed+=t;let i=this.duration<=0?1:Math.min(1,this.elapsed/this.duration);if(this.apply(i),i>=1){this.onStepComplete&&this.runtime.safeCall(this.onStepComplete);let n=this.loops<0;if(this.loopIndex++,n||this.loopIndex<this.loops){this.elapsed=Math.max(0,this.elapsed-this.duration),this.relative?this.capture():this.restoreInitial();let r=this.duration<=0?1:Math.min(1,this.elapsed/this.duration);this.apply(r)}else this.finish(!0)}}finish(t){this.playing=!1,this.killed=!0,this.runtime.tweens.delete(this),t&&this.onComplete&&this.runtime.safeCall(this.onComplete)}},bi=class{constructor(t){this.runtime=t,this.steps=[],this.playing=!1,this.paused=!1,this.killed=!1,this.elapsed=0,this.loops=1,this.loopIndex=0,this.onComplete=null,this.onStepComplete=null,this._built=[]}Append(t){return this.steps.push({kind:"tween",tween:t,parallel:!1}),this}AppendInterval(t){return this.steps.push({kind:"interval",duration:t}),this}AppendCallback(t){return this.steps.push({kind:"callback",fn:t}),this}Join(t){return this.steps.push({kind:"tween",tween:t,parallel:!0}),this}Insert(t,i){return this.steps.push({kind:"insert",time:t,tween:i}),this}InsertCallback(t,i){return this.steps.push({kind:"insertCb",time:t,fn:i}),this}Play(){return this.playing=!0,this.paused=!1,this.killed=!1,this.elapsed=0,this.loopIndex=0,this._schedule(),this._activateDueEntries(),this.runtime.sequences.add(this),this}_schedule(){let t=0,i=0,n=!1;this._built=[];for(let r of this.steps)if(r.kind==="tween"&&r.parallel){let o=n?i:t;this._built.push({at:o,tween:r.tween}),t=Math.max(t,o+r.tween.duration)}else r.kind==="tween"?(this._built.push({at:t,tween:r.tween}),i=t,n=!0,t+=r.tween.duration):r.kind==="interval"?(i=t,n=!0,t+=r.duration):r.kind==="callback"?this._built.push({at:t,fn:r.fn}):r.kind==="insert"?(this._built.push({at:r.time,tween:r.tween}),t=Math.max(t,r.time+r.tween.duration)):r.kind==="insertCb"&&(this._built.push({at:r.time,fn:r.fn}),t=Math.max(t,r.time));this._end=t,this._fired=new Set}Pause(){this.paused=!0;for(let t of this._built)t.tween&&this._fired.has(t)&&t.tween.Pause()}Resume(){this.paused=!1;for(let t of this._built)t.tween&&this._fired.has(t)&&t.tween.Resume()}Restart(){this.Play()}Complete(){for(let t of this._built)t.tween&&(this._fired.has(t)||t.tween.Play(),t.tween.Complete()),t.fn&&!this._fired.has(t)&&this.runtime.safeCall(t.fn),this._fired.add(t);this.finish(!0)}Kill(t){if(t)this.Complete();else{for(let i of this._built)i.tween&&this._fired.has(i)&&i.tween.Kill(!1);this.finish(!1)}}SetOnComplete(t){return this.onComplete=t,this}SetOnStepComplete(t){return this.onStepComplete=t,this}SetLoops(t){return this.loops=t,this}_activateDueEntries(){for(let t of this._built)this._fired.has(t)||this.elapsed+1e-9<t.at||(this._fired.add(t),t.tween&&t.tween.Play(),t.fn&&this.runtime.safeCall(t.fn))}step(t){!this.playing||this.paused||this.killed||(this.elapsed+=t,this._activateDueEntries(),this.elapsed>=this._end&&(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.loopIndex++,this.loops<0||this.loopIndex<this.loops?(this.elapsed=0,this._schedule()):this.finish(!0)))}finish(t){this.playing=!1,this.killed=!0,this.runtime.sequences.delete(this),t&&this.onComplete&&this.runtime.safeCall(this.onComplete)}};var vi={EaseType:["Linear","InSine","OutSine","InOutSine","InQuad","OutQuad","InOutQuad","InCubic","OutCubic","InOutCubic","InQuart","OutQuart","InOutQuart","InQuint","OutQuint","InOutQuint","InExpo","OutExpo","InOutExpo","InCirc","OutCirc","InOutCirc","InBack","OutBack","InOutBack","InElastic","OutElastic","InOutElastic","InBounce","OutBounce","InOutBounce"],CustomVariableEntityType:["Level","PlayerSelf","AvatarSelf"],Device:["KeyboardAndMouse","Mobile","Controller","MobileController"],StageMode:["Beyond","Classic"],LanguageType:["LanguageNone","LanguageEng","LanguageChs","LanguageCht","LanguageFra","LanguageDeu","LanguageSpa","LanguagePor","LanguageRus","LanguageJpn","LanguageKor","LanguageTha","LanguageVie","LanguageInd","LanguageTur","LanguageIta"],ParamType:["Entity","EntityList","Int","IntList","Bool","BoolList","Float","FloatList","String","StringList","Vector3","Vector3List","Guid","GuidList","ConfigId","PrefabId","ConfigIdList","PrefabIdList"],CursorEventType:["CursorDown","CursorUp","CursorEnter","CursorExit","CursorDrag","CursorBeginDrag","CursorEndDrag","CursorClick"],ScrollDirection:["Horizontal","Vertical"],ScrollLayoutConstraint:["AutoWrap","Fixed"],ScrollAlignType:["Bottom","Center","Top"],ControllerNavigationDir:["Up","Down","Left","Right"],ControllerNavigationEventType:["Confirm","Cancel","Focus","LostFocus","RightStickUp","RightStickDown","RightStickRight","RightStickLeft","LeftStickUp","LeftStickDown","LeftStickRight","LeftStickLeft"],ControllerNavigationMode:["None","NearestControl","Specified"],TextHorizontalAlignment:["Left","Middle","Right"],TextVerticalAlignment:["Top","Middle","Bottom"],ImageType:["Basic","Stretch"],ImageSource:["StaticReference","Item","Equipment","Skill","UnitStatus","Faction","Currency","Prefab"],ImageFillType:["Unused","Horizontal","Vertical","Radial90","Radial180","Radial360"],ImageFillHorizontalType:["Left","Right"],ImageFillVerticalType:["Bottom","Top"],ImageFillRadial90Type:["BottomLeft","TopLeft","TopRight","BottomRight"],ImageFillRadialType:["Bottom","Left","Top","Right"],ImageMaskSoftEdgeMode:["Percentage","Pixel"],UIAnimationLayer:["AboveAllControls","BelowAllControls"]},Ps=[...Array.from({length:43},(e,t)=>`CraftspersonKey${t+1}`),"MoveForwardKey","MoveBackwardKey","MoveLeftKey","MoveRightKey","SwitchToWalkOrRunKey","SprintKey","JumpKey","DropKey","OpenShortcutWheelKey","InteractKey","NormalAttackKey","CharacterSkill1Key","CharacterSkill2Key","CharacterSkill3Key","CharacterSkill4Key","None"],Ts=[...Array.from({length:14},(e,t)=>`CraftspersonKey${t+1}`),"SprintKey","JumpKey","InteractKey","NormalAttackKey","CharacterSkill1Key","CharacterSkill2Key","CharacterSkill3Key","CharacterSkill4Key","MenuConfirmKey","MenuBackKey","None"];function Rs(){let e=[];for(let t of["Down","Up"]){for(let i=1;i<=43;i++)e.push(`KeyboardCraftspersonKey${i}${t}`);for(let i of["MoveForwardKey","MoveBackwardKey","MoveLeftKey","MoveRightKey","SwitchToWalkOrRunKey","SprintKey","JumpKey","DropKey","OpenShortcutWheelKey","InteractKey","NormalAttackKey","CharacterSkill1Key","CharacterSkill2Key","CharacterSkill3Key","CharacterSkill4Key"])e.push(`Keyboard${i}${t}`);for(let i=1;i<=14;i++)e.push(`ControllerCraftspersonKey${i}${t}`);for(let i of["SprintKey","JumpKey","InteractKey","NormalAttackKey","CharacterSkill1Key","CharacterSkill2Key","CharacterSkill3Key","CharacterSkill4Key","MenuConfirmKey","MenuBackKey"])e.push(`Controller${i}${t}`)}return e}vi.KeyboardKeyCode=Ps;vi.ControllerKeyCode=Ts;vi.KeyEventType=Rs();var ro=new Map;function et(e,t){let i=`${e}\0${t}`,n=ro.get(i);return n||(n={__kind:"EnumItem",Name:t,FullName:`Enum.${e}.${t}`,EnumType:e},ro.set(i,n)),n}function pn(e,t){return t==null?t:t.__kind==="EnumItem"?et(t.EnumType||e,t.Name):typeof t=="string"&&t?et(e,t):t}function mn(){let e={};for(let[t,i]of Object.entries(vi)){let n={};for(let r of i)n[r]=et(t,r);e[t]=n}return e}var oo={horizontalAlignment:"TextHorizontalAlignment",verticalAlignment:"TextVerticalAlignment",imageSource:"ImageSource",fillType:"ImageFillType",fillHorizontalType:"ImageFillHorizontalType",fillVerticalType:"ImageFillVerticalType",fillRadial90Type:"ImageFillRadial90Type",fillRadialType:"ImageFillRadialType",softEdgeMode:"ImageMaskSoftEdgeMode",layer:"UIAnimationLayer",scrollDirection:"ScrollDirection",layoutConstraint:"ScrollLayoutConstraint"},tt=c.LUA_REGISTRYINDEX,Ms=c.LUA_MULTRET;function me(e){return e==null?"":typeof e=="string"?e:e.Name||e.FullName||String(e)}function Ns(e){let t=String(e).replace(/\\/g,"/").replace(/\.lua$/i,"");return t.split("/").pop()||t}var Si=class{constructor(t={}){this.canvasWidth=t.canvasWidth??1600,this.canvasHeight=t.canvasHeight??900,this.device=t.device??"KeyboardAndMouse",this.language=t.language??"LanguageChs",this.stageMode=t.stageMode??"Classic",this.testPlay=t.testPlay!==!1,this.clock={time:0,levelTime:0,paused:!1,frame:0},this.logs=[],this.mountErrors=[],this.tweens=new Set,this.sequences=new Set,this.audios=new Map,this.nextAudioId=1,this._nextControlId=1,this._playRemoved=[],this._nextScriptMappingId=1,this.lifecyclePhase="idle",this.controlsById=new Map,this.roots=[],this.templates=new Map,this.scriptFiles=new Map,this.requireAliases=new Map,this.requireCache=new Map,this.moduleBaseEnvironments=new Map,this.luaFunctions=new Map,this.mountedScripts=[],this.serverVars={Level:Object.create(null),PlayerSelf:Object.create(null),AvatarSelf:Object.create(null)},this.serverBridge=null,this.varHandlers=[],this.signalHandlers=[],this.cursor={x:0,y:0},this.focus=null,this.stick={left:[0,0],right:[0,0]},this.enumTree=mn(),this.luaStates=new Set,this.L=null}nextControlId(){let t=this._nextControlId;return this._nextControlId+=1,t}resolveScriptMappingId(t){let i=Number(t);if(Number.isSafeInteger(i)&&i>0)return this._nextScriptMappingId=Math.max(this._nextScriptMappingId,i+1),i;let n=this._nextScriptMappingId;return this._nextScriptMappingId+=1,n}pushPackedColor(t,i){let n=i>>>0;(n|0)===n?c.lua_pushinteger(t,n):c.lua_pushnumber(t,n)}unrefLuaCallback(t){jr(this,t)}log(t,...i){let n=i.map(r=>r==null?"nil":typeof r=="object"&&r!==null&&r.__kind==="EnumItem"?r.Name:String(r)).join(" ");this.logs.push({level:t,text:n,time:this.clock.time})}safeCall(t,...i){try{return t(...i)}catch(n){this.log("lua-error",n&&n.message?n.message:String(n))}}scriptCanRun(t){if(!t?.alive||!t.enabled)return!1;let i=t.object;return!i||i.alive&&i.activeInHierarchy}cursorEventsEnabled(t){for(let i=t;i;i=i.parent)if(i.kind==="container"&&i.showCursor===!0)return!0;return!1}registerTemplate(t,i){this.templates.set(Number(t),i)}registerScriptFile(t,i){let n=this.normalizeRequirePath(t);this.scriptFiles.set(n,i),n.startsWith("default_import_file/")||this.requireAliases.set(`default_import_file/${n}`,n)}normalizeRequirePath(t){let i=String(t).replace(/\\/g,"/");return i.endsWith(".lua")&&(i=i.slice(0,-4)),i}addRoot(t){let i=t instanceof Ue?t:new Ue(this,t);return this.roots.push(i),Ie(i,n=>this.controlsById.set(n.Id,n)),this.mountSpecScripts(t,i),i}mountSpecScripts(t,i){if(t instanceof Ue)return;let n=o=>(o.scripts?.length||0)>0||(o.children||[]).some(n);if(!t||!n(t))return;let r=this.lifecyclePhase;try{let o=(a,s)=>{for(let l of a.scripts||[])try{this.mountScript({path:l.path,source:l.source,control:s,scriptMappingId:l.scriptMappingId})}catch(f){let h=f&&f.message?f.message:String(f);this.mountErrors.push(h),this.log("lua-error",h)}let u=a.children||[];for(let l=0;l<u.length;l+=1)o(u[l],s?.children?.[l])};o(t,i)}finally{this.lifecyclePhase=r}}makeCursorEventData({x:t=0,y:i=0,pressX:n=t,pressY:r=i,deltaX:o=t-n,deltaY:a=i-r,dragging:s=!1,touchId:u=-1}={}){let l=this;return{__kind:"CursorEventData",typeofName:"CursorEventData",dragging:s,touchId:u,x:t,y:i,pressX:n,pressY:r,GetUIPos(){return[t,i]},GetPressUIPos(){return[n,r]},GetUIPosDelta(){return[o,a]}}}boot(){let t=this.newLuaThread();this.L=t}installGlobals(t){let i=this;c.lua_pushcfunction(t,n=>{let r=c.lua_gettop(n),o=[];for(let a=1;a<=r;a++)o.push(pe(n,i,a));return i.log("info",...o),0}),c.lua_setglobal(t,_("print")),c.lua_pushcfunction(t,n=>{let r=c.lua_gettop(n),o=[];for(let a=1;a<=r;a++)o.push(pe(n,i,a));return i.log("error",...o),0}),c.lua_setglobal(t,_("printerr")),c.lua_pushcfunction(t,n=>{if(c.lua_type(n,1)===c.LUA_TTABLE&&!Be(n,1))return c.lua_pushstring(n,_("table")),1;let r=pe(n,i,1);return c.lua_pushstring(n,_(i.typeofOf(r))),1}),c.lua_setglobal(t,_("typeof")),this.pushColorLib(t),this.pushEnumLib(t),this.pushGameLib(t),c.lua_pushcfunction(t,n=>i.luaRequire(n)),c.lua_setglobal(t,_("require"))}typeofOf(t){return t==null?"nil":t.__kind==="Script"?"Script":t.__kind==="EnumItem"?"EnumItem":t.__kind==="CursorEventData"?"CursorEventData":t.typeofName?t.typeofName:typeof t=="number"?"number":typeof t=="string"?"string":typeof t=="boolean"?"boolean":typeof t}pushColorLib(t){c.lua_newtable(t),c.lua_pushcfunction(t,i=>(this.pushPackedColor(i,wt(c.lua_tonumber(i,1),c.lua_tonumber(i,2),c.lua_tonumber(i,3),255)),1)),c.lua_setfield(t,-2,_("FromRGB")),c.lua_pushcfunction(t,i=>{let n=c.lua_isnoneornil(i,4)?255:c.lua_tonumber(i,4);return this.pushPackedColor(i,wt(c.lua_tonumber(i,1),c.lua_tonumber(i,2),c.lua_tonumber(i,3),n)),1}),c.lua_setfield(t,-2,_("FromRGBA")),c.lua_pushcfunction(t,i=>{let n=c.lua_tonumber(i,1)>>>0,[r,o,a,s]=Yt(n);return c.lua_pushnumber(i,r),c.lua_pushnumber(i,o),c.lua_pushnumber(i,a),c.lua_pushnumber(i,s),4}),c.lua_setfield(t,-2,_("ToRGBA")),c.lua_newtable(t),c.lua_pushcfunction(t,i=>{let n=c.lua_tonumber(i,2),r=c.lua_tonumber(i,3),o=c.lua_tonumber(i,4),a=c.lua_isnoneornil(i,5)?255:c.lua_tonumber(i,5);return this.pushPackedColor(i,wt(n,r,o,a)),1}),c.lua_setfield(t,-2,_("__call")),c.lua_setmetatable(t,-2),c.lua_setglobal(t,_("Color"))}pushEnumLib(t){c.lua_newtable(t);for(let[i,n]of Object.entries(this.enumTree)){c.lua_newtable(t);for(let[r,o]of Object.entries(n))this.pushEnumItem(t,o),c.lua_setfield(t,-2,_(r));c.lua_setfield(t,-2,_(i))}c.lua_setglobal(t,_("Enum"))}pushEnumItem(t,i){let n=c.lua_newuserdata(t,0);Qe(n,i),re.luaL_setmetatable(t,_("EnumItem"))}pushControl(t,i){let n=c.lua_newuserdata(t,0);Qe(n,i),re.luaL_setmetatable(t,_("Control"))}pushScript(t,i){c.lua_newtable(t),c.lua_pushlightuserdata(t,fn);let n=c.lua_newuserdata(t,0);Qe(n,i),c.lua_rawset(t,-3),re.luaL_getmetatable(t,_("Script")),c.lua_setmetatable(t,-2)}pushTween(t,i){let n=c.lua_newuserdata(t,0);Qe(n,i);let r=i.Append?"TweenSequence":"Tween";re.luaL_setmetatable(t,_(r))}pushCursor(t,i){let n=c.lua_newuserdata(t,0);Qe(n,i),re.luaL_setmetatable(t,_("CursorEventData"))}pushGameLib(t){let i=this;c.lua_newtable(t);let n={InstantiateClientUIControl:r=>{let o=c.lua_tointeger(r,1),a=be(c.lua_touserdata(r,2)),s=i.instantiate(o,a,i.lifecyclePhase);return s?(i.pushControl(r,s),1):(c.lua_pushnil(r),1)},DestroyClientUIControl:r=>{let o=be(c.lua_touserdata(r,1));return o&&i.destroyControl(o),0},GetClientUIControl:r=>{let o=c.lua_tointeger(r,1),a=i.controlsById.get(o);return a?i.pushControl(r,a):c.lua_pushnil(r),1},FindClientUIRoot:r=>{let o=W(r,1),a=i.roots.find(s=>s.name===o);return a?i.pushControl(r,a):c.lua_pushnil(r),1},GetClientUIRoots:r=>(c.lua_createtable(r,i.roots.length,0),i.roots.forEach((o,a)=>{i.pushControl(r,o),c.lua_rawseti(r,-2,a+1)}),1),GetUICanvasSize:r=>(c.lua_pushnumber(r,i.canvasWidth),c.lua_pushnumber(r,i.canvasHeight),2),GetCursorUIPos:r=>(c.lua_pushnumber(r,i.cursor.x),c.lua_pushnumber(r,i.cursor.y),2),GetDevice:r=>(i.pushEnumItem(r,et("Device",i.device)),1),SetControllerFocus:r=>(i.focus=be(c.lua_touserdata(r,1)),0),GetControllerFocus:r=>(i.focus?i.pushControl(r,i.focus):c.lua_pushnil(r),1),GetControllerLeftStickAxis:r=>(c.lua_pushnumber(r,i.stick.left[0]),c.lua_pushnumber(r,i.stick.left[1]),2),GetControllerRightStickAxis:r=>(c.lua_pushnumber(r,i.stick.right[0]),c.lua_pushnumber(r,i.stick.right[1]),2),Tween:r=>{let o=be(c.lua_touserdata(r,1))||pe(r,i,1),a=pe(r,i,2)||{},s=c.lua_tonumber(r,3),u=new yi(i,o,a,s);return i.pushTween(r,u),1},TweenSequence:r=>(i.pushTween(r,new bi(i)),1),ServerSignal:r=>{let o=W(r,1),a=i.makeServerSignal(o),s=c.lua_newuserdata(r,0);return Qe(s,a),re.luaL_setmetatable(r,_("ServerSignal")),1},GetGlobalCustomVariableValue:r=>{let o=me(pe(r,i,1)),a=W(r,2);return ne(r,i,i.getVar(o,a)),1},PauseLevelTime:r=>(i.clock.paused=!!c.lua_toboolean(r,1),0),IsLevelTimePaused:r=>(c.lua_pushboolean(r,i.clock.paused),1),PlayAudio2D:r=>{let o=i.nextAudioId++;return i.audios.set(o,{audioId:c.lua_tointeger(r,1),alive:!0}),c.lua_pushinteger(r,o),1},StopAudio:r=>{let o=c.lua_tointeger(r,1),a=i.audios.get(o);return a&&(a.alive=!1),0},IsAudioAlive:r=>{let o=i.audios.get(c.lua_tointeger(r,1));return c.lua_pushboolean(r,!!(o&&o.alive)),1},GetLanguageType:r=>(i.pushEnumItem(r,et("LanguageType",i.language)),1),GetStageMode:r=>(i.pushEnumItem(r,et("StageMode",i.stageMode)),1),IsTestPlay:r=>(c.lua_pushboolean(r,i.testPlay),1),GetText:r=>{let o=W(r,1);return c.lua_pushstring(r,_(o)),1},PrintClientUITree:r=>{for(let o of i.roots)i.log("info",hn(o).join(`
|
|
107
107
|
`));return 0}};for(let[r,o]of Object.entries(n))c.lua_pushcfunction(t,o),c.lua_setfield(t,-2,_(r));c.lua_setglobal(t,_("game"))}makeServerSignal(t){let i=[],n=this;return{__kind:"ServerSignal",name:t,AddParam(r,o){i.push({type:me(r),value:o})},AddInt(r){i.push({type:"Int",value:r})},AddIntList(r){i.push({type:"IntList",value:r})},AddFloat(r){i.push({type:"Float",value:r})},AddFloatList(r){i.push({type:"FloatList",value:r})},AddString(r){i.push({type:"String",value:r})},AddStringList(r){i.push({type:"StringList",value:r})},AddVector3(r){i.push({type:"Vector3",value:r})},AddVector3List(r){i.push({type:"Vector3List",value:r})},AddBool(r){i.push({type:"Bool",value:r})},AddBoolList(r){i.push({type:"BoolList",value:r})},AddGuid(r){i.push({type:"Guid",value:r})},AddGuidList(r){i.push({type:"GuidList",value:r})},AddEntity(r){i.push({type:"Entity",value:r})},AddEntityList(r){i.push({type:"EntityList",value:r})},AddPrefabId(r){i.push({type:"PrefabId",value:r})},AddPrefabIdList(r){i.push({type:"PrefabIdList",value:r})},AddConfigId(r){i.push({type:"ConfigId",value:r})},AddConfigIdList(r){i.push({type:"ConfigIdList",value:r})},SendSignal(){let r=i.slice();n.serverBridge&&typeof n.serverBridge.receiveFromClient=="function"&&n.serverBridge.receiveFromClient(t,r)}}}instantiate(t,i,n){if(n==="OnInit"||n==="OnDestroy")return null;let r=this.templates.get(Number(t));if(!r||!i)return null;let o=new Ue(this,{...r,Id:this.nextControlId(),authoringId:null,prefabIndex:Number(t)});return i.addChild(o),Ie(o,a=>this.controlsById.set(a.Id,a)),this.mountSpecScripts(r,o),o}destroyControl(t){if(!(!t||!t.alive)){if(t._destroying)throw new Error(`\u5BA2\u6237\u7AEF\u63A7\u4EF6\u751F\u547D\u5468\u671F\u5904\u4E8E\u521B\u5EFA\u6216\u9500\u6BC1\u65F6\uFF0C\u65E0\u6CD5\u8C03\u7528DestroyClientUIControl, ID:${t.name}`);Ie(t,i=>{i._destroying=!0}),this._destroyControlTree(t)}}_destroyControlTree(t){this.releaseControlListeners(t);for(let i of t.scripts.slice())this.unmountScript(i);for(let i of t.children.slice())this._destroyControlTree(i);if(t.alive=!1,this._playRemoved.push(t.Id),t.parent){let i=t.parent,n=i.children.indexOf(t);n>=0&&i.children.splice(n,1),t._parent=null,i.markPlayDirty(!0)}else{let i=this.roots.indexOf(t);i>=0&&this.roots.splice(i,1)}this.controlsById.delete(t.Id),this.focus===t&&(this.focus=null);for(let i of[...this.tweens])i.object===t&&i.Kill(!1)}releaseControlListeners(t){for(let i of t.cursorListeners.values())for(let n of i)this.unrefLuaCallback(n);for(let i of t.keyListeners.values())for(let n of i)this.unrefLuaCallback(n);for(let i of t.navListeners.values())for(let n of i)this.unrefLuaCallback(n);t.cursorListeners.clear(),t.keyListeners.clear(),t.navListeners.clear(),t.navConfig.clear()}onControlActiveChanging(t,i){let n=[];Ie(t,r=>n.push({control:r,was:r.activeInHierarchy})),t.active=!!i,t.markPlayDirty(!0);for(let r of n){let o=r.control.activeInHierarchy;if(r.was!==o)for(let a of r.control.scripts.slice())o?this.enableScript(a):this.disableScript(a)}}bindScriptEnv(t){let i=t.env;return i?(this.pushScript(i,t),c.lua_setglobal(i,_("script")),i):null}disableScript(t){if(!t?.alive||!t.env||t.lifecyclePhase!=="running")return;let i=this.lifecyclePhase;this.lifecyclePhase="OnDisable",t.lifecyclePhase="OnDisable",this.bindScriptEnv(t),this.callGlobal(t.env,"OnDisable"),t.lifecyclePhase="disabled",this.lifecyclePhase=i}enableScript(t){if(!t?.alive||!t.env||t.lifecyclePhase!=="disabled")return;let i=this.lifecyclePhase;this.lifecyclePhase="OnEnable",t.lifecyclePhase="OnEnable",this.bindScriptEnv(t),this.callGlobal(t.env,"OnEnable"),t.lifecyclePhase="running",this.lifecyclePhase=i}unmountScript(t){if(!t||!t.alive)return;let i=t.env,n=this.lifecyclePhase;i&&(t.lifecyclePhase==="running"&&(this.lifecyclePhase="OnDisable",t.lifecyclePhase="OnDisable",this.bindScriptEnv(t),this.callGlobal(i,"OnDisable")),this.lifecyclePhase="OnDestroy",t.lifecyclePhase="OnDestroy",this.bindScriptEnv(t),this.callGlobal(i,"OnDestroy")),t.alive=!1,t.lifecyclePhase="destroyed",this.lifecyclePhase=n,this.mountedScripts=this.mountedScripts.filter(r=>r!==t),t.object&&(t.object.scripts=t.object.scripts.filter(r=>r!==t)),this.varHandlers=this.varHandlers.filter(r=>r.script!==t),this.signalHandlers=this.signalHandlers.filter(r=>r.script!==t),i&&i!==this.L&&this.closeTrackedLuaState(i),t.env=null}installMetatables(t){this.mtEnum(t),this.mtControl(t),this.mtScript(t),this.mtTween(t),this.mtSeq(t),this.mtSignal(t),this.mtCursor(t)}mtIndexNewindex(t,i,n,r,o,a){re.luaL_newmetatable(t,_(i)),c.lua_pushcfunction(t,s=>{let u=Be(s,1)||be(c.lua_touserdata(s,1)),l=W(s,2);if(o[l]&&(!a||a(u,l)))return c.lua_pushcfunction(s,o[l]),1;let f=n(u,l);return f===void 0?(c.lua_pushnil(s),1):(ne(s,this,f),1)}),c.lua_setfield(t,-2,_("__index")),c.lua_pushcfunction(t,s=>{try{let u=Be(s,1)||be(c.lua_touserdata(s,1)),l=W(s,2),f=pe(s,this,3);return r(u,l,f),0}catch(u){return c.lua_pushstring(s,_(String(u.message||u))),c.lua_error(s)}}),c.lua_setfield(t,-2,_("__newindex")),c.lua_pushcfunction(t,s=>{let u=Be(s,1)||be(c.lua_touserdata(s,1)),l=Be(s,2)||be(c.lua_touserdata(s,2));return c.lua_pushboolean(s,u===l),1}),c.lua_setfield(t,-2,_("__eq")),c.lua_pop(t,1)}method(t){let i=this;return n=>{let r=Be(n,1)||be(c.lua_touserdata(n,1)),o=c.lua_gettop(n),a=[];for(let s=2;s<=o;s++)a.push(pe(n,i,s));try{let s=t(r,...a);if(s===r)return c.lua_pushvalue(n,1),1;if(s===void 0)return 0;if(Array.isArray(s)&&s.__multi){for(let u of s)ne(n,i,u);return s.length}if(Array.isArray(s)&&!(s.length&&typeof s[0]=="object"&&s[0]?.typeofName)){if(s.__controls)return c.lua_createtable(n,s.length,0),s.forEach((u,l)=>{i.pushControl(n,u),c.lua_rawseti(n,-2,l+1)}),1;if(s.__scripts)return c.lua_createtable(n,s.length,0),s.forEach((u,l)=>{i.pushScript(n,u),c.lua_rawseti(n,-2,l+1)}),1;if(typeof s[0]=="number"&&s.length<=4){for(let u of s)c.lua_pushnumber(n,u);return s.length}}return ne(n,i,s),1}catch(s){return c.lua_pushstring(n,_(String(s.message||s))),c.lua_error(n)}}}mtEnum(t){let i=new Set(["Name","FullName","EnumType"]);this.mtIndexNewindex(t,"EnumItem",(n,r)=>i.has(r)?n[r]:void 0,(n,r)=>{throw new Error(`cannot set ${r}, no such field`)},{})}mtCursor(t){let i=new Set(["dragging","touchId"]);this.mtIndexNewindex(t,"CursorEventData",(n,r)=>i.has(r)?n[r]:void 0,(n,r)=>{throw new Error(`cannot set ${r}, no such field`)},{GetUIPos:this.method(n=>n.GetUIPos()),GetPressUIPos:this.method(n=>n.GetPressUIPos()),GetUIPosDelta:this.method(n=>n.GetUIPosDelta())})}mtControl(t){let i={GetChildren:this.method(n=>{let r=n.GetChildren();return r.__controls=!0,r}),GetChild:this.method((n,r)=>n.GetChild(r)),FindChild:this.method((n,r)=>n.FindChild(r)),SetActive:this.method((n,r)=>n.SetActive(r)),SetVisible:this.method((n,r)=>n.SetVisible(r)),GetSiblingIndex:this.method(n=>n.GetSiblingIndex()),SetSiblingIndex:this.method((n,r)=>n.SetSiblingIndex(r)),SetAsFirstSibling:this.method(n=>n.SetAsFirstSibling()),SetAsLastSibling:this.method(n=>n.SetAsLastSibling()),GetAnchoredPosition:this.method(n=>n.GetAnchoredPosition()),SetAnchoredPosition:this.method((n,r,o)=>n.SetAnchoredPosition(r,o)),GetSizeDelta:this.method(n=>n.GetSizeDelta()),SetSizeDelta:this.method((n,r,o)=>n.SetSizeDelta(r,o)),GetAnchorMin:this.method(n=>n.GetAnchorMin()),SetAnchorMin:this.method((n,r,o)=>n.SetAnchorMin(r,o)),GetAnchorMax:this.method(n=>n.GetAnchorMax()),SetAnchorMax:this.method((n,r,o)=>n.SetAnchorMax(r,o)),GetPivot:this.method(n=>n.GetPivot()),SetPivot:this.method((n,r,o)=>n.SetPivot(r,o)),GetLocalScale:this.method(n=>n.GetLocalScale()),SetLocalScale:this.method((n,r,o,a)=>n.SetLocalScale(r,o,a)),GetLocalRotation:this.method(n=>n.GetLocalRotation()),SetLocalRotation:this.method((n,r,o,a)=>n.SetLocalRotation(r,o,a)),GetScriptByPath:this.method((n,r)=>n.GetScriptByPath(r)),GetScript:this.method((n,r)=>n.GetScript(r)),GetScripts:this.method(n=>{let r=n.GetScripts();return r.__scripts=!0,r}),AddCursorEventListener:this.method((n,r,o)=>n.AddCursorEventListener(me(r),o)),RemoveCursorEventListener:this.method((n,r,o)=>n.RemoveCursorEventListener(me(r),o)),RemoveCursorEventListeners:this.method((n,r)=>n.RemoveCursorEventListeners(me(r))),RemoveAllCursorEventListeners:this.method(n=>n.RemoveAllCursorEventListeners()),SimulateCursorClick:this.method(n=>n.SimulateCursorClick()),AddKeyEventListener:this.method((n,r,o)=>n.AddKeyEventListener(me(r),o)),RemoveKeyEventListener:this.method((n,r,o)=>n.RemoveKeyEventListener(me(r),o)),RemoveKeyEventListeners:this.method((n,r)=>n.RemoveKeyEventListeners(me(r))),RemoveAllKeyEventListeners:this.method(n=>n.RemoveAllKeyEventListeners()),AddNavigationEventListener:this.method((n,r,o)=>n.AddNavigationEventListener(me(r),o)),RemoveNavigationEventListener:this.method((n,r,o)=>n.RemoveNavigationEventListener(me(r),o)),RemoveNavigationEventListeners:this.method((n,r)=>n.RemoveNavigationEventListeners(me(r))),RemoveAllNavigationEventListeners:this.method(n=>n.RemoveAllNavigationEventListeners()),SetControllerNavigation:this.method((n,r,o,a)=>n.SetControllerNavigation(me(r),o,a)),GetControllerNavigation:this.method((n,r)=>n.GetControllerNavigation(me(r))),SetImage:this.method((n,r,o)=>n.SetImage(r,o)),SetSoftEdgeWidth:this.method((n,r,o)=>n.SetSoftEdgeWidth(r,o)),SetFillUnused:this.method(n=>n.SetFillUnused()),SetFillHorizontal:this.method((n,r,o)=>n.SetFillHorizontal(r,o)),SetFillVertical:this.method((n,r,o)=>n.SetFillVertical(r,o)),SetFillRadial90:this.method((n,r,o)=>n.SetFillRadial90(r,o)),SetFillRadial180:this.method((n,r,o)=>n.SetFillRadial180(r,o)),SetFillRadial360:this.method((n,r,o)=>n.SetFillRadial360(r,o)),PlayAnimation:this.method(n=>n.PlayAnimation()),StopAnimation:this.method(n=>n.StopAnimation()),RefreshItems:this.method(n=>n.RefreshItems()),GetItemIndex:this.method(n=>n.GetItemIndex()),GetItemSize:this.method(n=>n.GetItemSize()),GetItemSpacing:this.method(n=>n.GetItemSpacing()),GetPadding:this.method(n=>n.GetPadding()),ScrollToItemAt:this.method(n=>n.ScrollToItemAt()),GetContentLength:this.method(n=>n.GetContentLength())};this.mtIndexNewindex(t,"Control",(n,r)=>{if(!dn(n,r))return;let o=n[r],a=oo[r];return a?pn(a,o):o},(n,r,o)=>{if(dn(n,r)==="rw"){let s=oo[r];n[r]=s?pn(s,o):o,typeof n.markPlayDirty=="function"&&n.markPlayDirty(pi.has(r));return}throw new Error(`cannot set ${r}, no such field`)},i,eo)}mtScript(t){let i=this,n=new Set(["alive","scriptMappingId","object","path","enabled"]);this.mtIndexNewindex(t,"Script",(r,o)=>n.has(o)?r[o]:void 0,(r,o,a)=>{if(o==="enabled"){r.enabled=!!a;return}throw new Error(`cannot set ${o}, no such field`)},{GetParam:this.method((r,o)=>Object.prototype.hasOwnProperty.call(r.params,o)?r.params[o]:null),Invoke:this.method((r,o,...a)=>r.invoke(o,a)),EnableUpdate:this.method((r,o)=>{r.updateEnabled=!!o}),RegisterServerSignalHandler:this.method((r,o,a)=>{i.signalHandlers.push({script:r,name:o,fn:a})}),UnregisterServerSignalHandler:this.method((r,o)=>{i.signalHandlers=i.signalHandlers.filter(a=>!(a.script===r&&a.name===o))}),RegisterCustomVariableChangedHandler:this.method((r,o,a,s)=>{i.varHandlers.push({script:r,entityType:me(o),name:a,fn:s})}),UnregisterCustomVariableChangedHandler:this.method((r,o,a)=>{let s=me(o);i.varHandlers=i.varHandlers.filter(u=>!(u.script===r&&u.entityType===s&&u.name===a))})})}mtTween(t){this.mtIndexNewindex(t,"Tween",()=>{},()=>{},{SetEase:this.method((i,n)=>i.SetEase(n)),SetRelative:this.method((i,n)=>i.SetRelative(n)),Play:this.method(i=>i.Play()),Pause:this.method(i=>i.Pause()),Resume:this.method(i=>i.Resume()),Restart:this.method(i=>i.Restart()),Complete:this.method(i=>i.Complete()),Kill:this.method((i,n)=>i.Kill(n)),SetOnComplete:this.method((i,n)=>i.SetOnComplete(n)),SetOnStepComplete:this.method((i,n)=>i.SetOnStepComplete(n)),SetLoops:this.method((i,n)=>i.SetLoops(n))})}mtSeq(t){this.mtIndexNewindex(t,"TweenSequence",()=>{},()=>{},{Append:this.method((i,n)=>i.Append(n)),AppendInterval:this.method((i,n)=>i.AppendInterval(n)),AppendCallback:this.method((i,n)=>i.AppendCallback(n)),Join:this.method((i,n)=>i.Join(n)),Insert:this.method((i,n,r)=>i.Insert(n,r)),InsertCallback:this.method((i,n,r)=>i.InsertCallback(n,r)),Play:this.method(i=>i.Play()),Pause:this.method(i=>i.Pause()),Resume:this.method(i=>i.Resume()),Restart:this.method(i=>i.Restart()),Complete:this.method(i=>i.Complete()),Kill:this.method((i,n)=>i.Kill(n)),SetOnComplete:this.method((i,n)=>i.SetOnComplete(n)),SetOnStepComplete:this.method((i,n)=>i.SetOnStepComplete(n)),SetLoops:this.method((i,n)=>i.SetLoops(n))})}mtSignal(t){this.mtIndexNewindex(t,"ServerSignal",()=>{},()=>{},{AddParam:this.method((i,n,r)=>i.AddParam(n,r)),SendSignal:this.method(i=>i.SendSignal()),AddInt:this.method((i,n)=>i.AddInt(n)),AddIntList:this.method((i,n)=>i.AddIntList(n)),AddFloat:this.method((i,n)=>i.AddFloat(n)),AddFloatList:this.method((i,n)=>i.AddFloatList(n)),AddString:this.method((i,n)=>i.AddString(n)),AddStringList:this.method((i,n)=>i.AddStringList(n)),AddVector3:this.method((i,n)=>i.AddVector3(n)),AddVector3List:this.method((i,n)=>i.AddVector3List(n)),AddBool:this.method((i,n)=>i.AddBool(n)),AddBoolList:this.method((i,n)=>i.AddBoolList(n)),AddGuid:this.method((i,n)=>i.AddGuid(n)),AddGuidList:this.method((i,n)=>i.AddGuidList(n)),AddEntity:this.method((i,n)=>i.AddEntity(n)),AddEntityList:this.method((i,n)=>i.AddEntityList(n)),AddPrefabId:this.method((i,n)=>i.AddPrefabId(n)),AddPrefabIdList:this.method((i,n)=>i.AddPrefabIdList(n)),AddConfigId:this.method((i,n)=>i.AddConfigId(n)),AddConfigIdList:this.method((i,n)=>i.AddConfigIdList(n))})}luaRequire(t){let i=W(t,1),n=this.normalizeRequirePath(i),r=this.requireAliases.get(n)||n;c.lua_rawgeti(t,tt,c.LUA_RIDX_MAINTHREAD);let o=c.lua_tothread(t,-1);c.lua_pop(t,1);let a=this.requireCache.get(o);a||(a=new Map,this.requireCache.set(o,a));let s=a.get(r);if(s?.loading)return c.lua_pushstring(t,_(`failed to load script '${n}': cyclic require`)),c.lua_error(t);if(s&&s.ref!=null)return c.lua_rawgeti(t,tt,s.ref),1;let u=this.scriptFiles.get(r);if(u==null)return c.lua_pushstring(t,_(`failed to load script '${n}'`)),c.lua_error(t);let l=c.lua_gettop(t);a.set(r,{loading:!0});try{this.loadModule(t,o,r,u),c.lua_pushvalue(t,-1);let f=re.luaL_ref(t,tt);return a.set(r,{ref:f}),1}catch(f){return a.delete(r),c.lua_settop(t,l),c.lua_pushstring(t,_(`failed to load script '${n}': ${f.message||f}`)),c.lua_error(t)}}newLuaThread(){let t=re.luaL_newstate();return Kr.luaL_openlibs(t),Jr(t),this.installMetatables(t),this.installGlobals(t),this.luaStates.add(t),c.lua_pushglobaltable(t),this.copyLuaEnvironment(t,-1),c.lua_remove(t,-2),this.moduleBaseEnvironments.set(t,re.luaL_ref(t,tt)),t}copyLuaEnvironment(t,i){let n=c.lua_absindex(t,i);c.lua_newtable(t);let r=c.lua_absindex(t,-1);for(c.lua_pushnil(t);c.lua_next(t,n)!==0;)c.lua_pushvalue(t,-2),c.lua_pushvalue(t,-2),c.lua_rawset(t,r),c.lua_pop(t,1);c.lua_pushvalue(t,r),c.lua_setfield(t,r,_("_G"))}closeTrackedLuaState(t){if(!t||!this.luaStates.has(t))return;for(let n of this.requireCache.get(t)?.values()||[])n.ref!=null&&re.luaL_unref(t,tt,n.ref);this.requireCache.delete(t);let i=this.moduleBaseEnvironments.get(t);if(i!=null&&re.luaL_unref(t,tt,i),this.moduleBaseEnvironments.delete(t),this.luaStates.delete(t),this.luaFunctions)for(let[n,r]of this.luaFunctions)r.__luaState===t&&this.luaFunctions.delete(n);qr(t)}loadModule(t,i,n,r){let o={__kind:"Script",alive:!0,scriptMappingId:this.resolveScriptMappingId(),object:null,path:n,enabled:!0,updateEnabled:!1,params:{},env:t,invoke(){}},a=String(r).replace(/^\uFEFF/,""),s=hi(a);if(re.luaL_loadbuffer(t,s,s.length,_(`@${n}`))!==Ae)throw new Error(W(t,-1));let l=c.lua_absindex(t,-1);if(c.lua_rawgeti(t,tt,this.moduleBaseEnvironments.get(i)),this.copyLuaEnvironment(t,-1),c.lua_remove(t,-2),this.pushScript(t,o),c.lua_setfield(t,-2,_("script")),c.lua_setupvalue(t,l,1),c.lua_pcall(t,0,1,0)!==Ae)throw new Error(W(t,-1))}mountScript({path:t,source:i,control:n,params:r={},scriptMappingId:o=void 0}){this.L||this.boot();let a=this.newLuaThread(),s={__kind:"Script",alive:!0,scriptMappingId:this.resolveScriptMappingId(o),object:n,path:Ns(t),enabled:!0,updateEnabled:!1,params:r,env:a,lifecyclePhase:"idle"};s.invoke=(l,f)=>this.invokeOn(a,l,f),n&&n.scripts.push(s),this.mountedScripts.push(s),this.pushScript(a,s),c.lua_setglobal(a,_("script"));let u=this.lifecyclePhase;try{this.lifecyclePhase="OnInit",s.lifecyclePhase="OnInit",this.runChunk(a,i,t);let l=this.callGlobal(a,"OnInit");l&&this.mountErrors.push(l),this.lifecyclePhase="OnEnable",s.lifecyclePhase="OnEnable";let f=this.callGlobal(a,"OnEnable");f&&this.mountErrors.push(f),this.lifecyclePhase="OnStart",s.lifecyclePhase="OnStart";let h=this.callGlobal(a,"OnStart");return h&&this.mountErrors.push(h),this.lifecyclePhase="running",s.lifecyclePhase="running",s}catch(l){throw s.alive=!1,s.lifecyclePhase="failed",this.mountedScripts=this.mountedScripts.filter(f=>f!==s),n&&(n.scripts=n.scripts.filter(f=>f!==s)),this.varHandlers=this.varHandlers.filter(f=>f.script!==s),this.signalHandlers=this.signalHandlers.filter(f=>f.script!==s),this.lifecyclePhase=u,a&&a!==this.L&&this.closeTrackedLuaState(a),s.env=null,l}}runChunk(t,i,n){let r=String(i).replace(/^\uFEFF/,""),o=hi(r),a=re.luaL_loadbuffer(t,o,o.length,_(`@${n}`));if(a!==Ae){let u=W(t,-1)||`luaL_loadbuffer status ${a}`;throw c.lua_pop(t,1),new Error(u)}let s=c.lua_pcall(t,0,0,0);if(s!==Ae){let u=W(t,-1)||`lua_pcall status ${s}`;throw c.lua_pop(t,1),new Error(u)}}callGlobal(t,i){if(c.lua_getglobal(t,_(i)),c.lua_isfunction(t,-1)){if(c.lua_pcall(t,0,0,0)!==Ae){let r=W(t,-1);c.lua_pop(t,1);let o=`${i}: ${r}`;return this.log("lua-error",o),o}}else c.lua_pop(t,1);return null}callGlobalDt(t,i,n){if(c.lua_getglobal(t,_(i)),c.lua_isfunction(t,-1)){if(c.lua_pushnumber(t,n),c.lua_pcall(t,1,0,0)!==Ae){let o=W(t,-1);c.lua_pop(t,1),this.log("lua-error",`${i}: ${o}`)}}else c.lua_pop(t,1)}invokeOn(t,i,n){let r=c.lua_gettop(t);if(c.lua_getglobal(t,_(i)),!c.lua_isfunction(t,-1)){c.lua_settop(t,r);return}for(let u of n)ne(t,this,u);if(c.lua_pcall(t,n.length,Ms,0)!==Ae){let u=W(t,-1);throw c.lua_settop(t,r),new Error(u)}let a=c.lua_gettop(t)-r;if(a<=0){c.lua_settop(t,r);return}if(a===1){let u=pe(t,this,-1);return c.lua_settop(t,r),u}let s=[];for(let u=1;u<=a;u++)s.push(pe(t,this,r+u));return c.lua_settop(t,r),s.__multi=!0,s}runScriptPhase(t,i){for(let n of this.mountedScripts){if(!this.scriptCanRun(n))continue;let r=n.env;r&&(this.pushScript(r,n),c.lua_setglobal(r,_("script")),!(t==="OnUpdate"&&!n.updateEnabled)&&this.callGlobalDt(r,t,i))}}step(t=1/30){if(typeof t!="number"||!Number.isFinite(t)||t<0)throw new TypeError("dt must be a finite non-negative number");this.clock.frame++,this.clock.time+=t;let i=!this.clock.paused;for(let n of[...this.tweens])n.step(t);for(let n of[...this.sequences])n.step(t);this.runScriptPhase("OnUpdate",t),i&&(this.clock.levelTime+=t,this.runScriptPhase("OnLevelUpdate",t))}injectKey(t){for(let i of this.roots)Ie(i,n=>{n.alive&&n.activeInHierarchy&&n.keyListeners.has(t)&&n.emitKey(t)})}injectCursor(t,i,n){let r=n||this.makeCursorEventData({});Number.isFinite(r.x)&&Number.isFinite(r.y)&&(this.cursor.x=r.x,this.cursor.y=r.y),t.emitCursor(i,r)}getVar(t,i){if(this.serverBridge&&typeof this.serverBridge.getVar=="function")return this.serverBridge.getVar(t,i);let n=this.serverVars[t];return n?n[i]:void 0}notifyVarHandlers(t,i){for(let n of this.varHandlers)this.scriptCanRun(n.script)&&n.entityType===t&&n.name===i&&this.safeCall(n.fn,this.enumTree.CustomVariableEntityType[t],i)}setVar(t,i,n){if(this.serverBridge&&typeof this.serverBridge.setVar=="function"){this.serverBridge.setVar(t,i,n);return}let r=this.serverVars[t]||(this.serverVars[t]=Object.create(null));r[i]=n,this.notifyVarHandlers(t,i)}sendClientSignal(t,i){for(let n of this.signalHandlers)this.scriptCanRun(n.script)&&n.name===t&&this.safeCall(n.fn,t,i)}evalQueryScript(t,i){this.L||this.boot();let n=this.L;c.lua_createtable(n,0,5);let r=(o,a)=>{c.lua_pushcfunction(n,a),c.lua_setfield(n,-2,_(o))};return r("var",o=>(ne(o,this,i.var(W(o,1),W(o,2))),1)),r("logContains",o=>(c.lua_pushboolean(o,i.logContains(W(o,1))),1)),r("control",o=>(ne(o,this,i.control(W(o,1))),1)),r("logs",o=>(ne(o,this,i.logs()),1)),r("signals",o=>(ne(o,this,i.signals(W(o,1))),1)),r("serverLogs",o=>(ne(o,this,i.serverLogs?i.serverLogs():[]),1)),r("serverLogContains",o=>{let a=i.serverLogContains;return c.lua_pushboolean(o,a?!!a(W(o,1)):!1),1}),c.lua_setglobal(n,_("query")),this.runChunk(n,t,"autotest-assert"),!0}destroy(){for(let t of this.roots.slice())this.destroyControl(t);for(let t of this.mountedScripts.slice())this.unmountScript(t);this.lifecyclePhase="idle",this.mountedScripts=[],this.luaFunctions.clear();for(let t of[...this.luaStates])this.closeTrackedLuaState(t);this.L=null}};function Bt(e){let t=new Si(e);return t.boot(),t}var nt=Object.freeze(Array.from({length:8},(e,t)=>`Player${t+1}`)),bn=Object.freeze(Array.from({length:8},(e,t)=>`Avatar${t+1}`)),po=Object.freeze(["Level","PlayerSelf","AvatarSelf"]);var gn=Object.freeze([...po,...nt,...bn]),mo=Object.freeze(["PlayerSelf","AllPlayers",...nt]),Fs=Object.freeze(["Level","PlayerSelf",...nt]),ao=Object.freeze(["Int","Float","String","Bool","Vector3","Entity","Guid","PrefabId","ConfigId","IntList","FloatList","StringList","BoolList","Vector3List","EntityList","GuidList","PrefabIdList","ConfigIdList","Dict","Struct"]),Os=-2147483648,$s=2147483647,Ds=new Set(["set-custom-variable","get-custom-variable","custom-variable-changed","\u8BBE\u7F6E\u81EA\u5B9A\u4E49\u53D8\u91CF","\u83B7\u53D6\u81EA\u5B9A\u4E49\u53D8\u91CF","\u81EA\u5B9A\u4E49\u53D8\u91CF\u53D8\u5316\u65F6","send-signal","listen-signal","send-client-script-signal","\u53D1\u9001\u4FE1\u53F7","\u76D1\u542C\u4FE1\u53F7","\u53D1\u9001\u5BA2\u6237\u7AEF\u811A\u672C\u4FE1\u53F7","setVar","getVar","signal","var"]);function Ut(e){return`Player${Number(e)}`}function wi(e){return`Avatar${Number(e)}`}function so(e){let t=String(e||"").match(/^(?:Player|Avatar)([1-8])$/);return t?Number(t[1]):0}function it(e){if(e==null||e==="")return 1;let t=Number(e);if(!Number.isInteger(t)||t<1||t>8)throw new Error("playerCount must be an integer 1-8");return t}function Te(e,t=8){let i=it(t);if(e==null||e==="")return 1;let n=Number(e);if(!Number.isInteger(n)||n<1||n>i)throw new Error(`playerIndex must be an integer 1-${i}`);return n}function lo(){let e={Level:Object.create(null),PlayerSelf:Object.create(null),AvatarSelf:Object.create(null)};for(let t of nt)e[t]=Object.create(null);for(let t of bn)e[t]=Object.create(null);return e}function go(e){let t=String(e||"");if(!gn.includes(t))throw new Error(`unknown CustomVariableEntityType: ${e}`);return t}function zs(e,t){let i=go(e);if(!Fs.includes(i))throw new Error(`${t}.entityType must be Level, PlayerSelf, or Player1-8`);return i}function Ht(e){let t=String(e??"");if(!t)throw new Error("custom variable name is required");return t}function Ii(e){let t=String(e??"");if(!t)throw new Error("signal name is required");return t}function yn(e){let t=String(e||"PlayerSelf");if(!mo.includes(t))throw new Error(`unsupported client signal target: ${e}. use PlayerSelf, AllPlayers, or Player1-8`);return t}function Xt(e){if(e==null)return"";if(typeof e=="boolean")return"Bool";if(typeof e=="string")return"String";if(typeof e=="number")return Number.isInteger(e)?"Int":"Float";if(Array.isArray(e)){if(e.length===0)return"IntList";let t=Xt(e[0]);return t&&!t.endsWith("List")&&t!=="Dict"&&t!=="Struct"?`${t}List`:"IntList"}return e&&typeof e=="object"?"x"in e||"y"in e||"z"in e?"Vector3":"Dict":""}function ye(e){return e===void 0?null:JSON.parse(JSON.stringify(e))}function co(e){return Array.isArray(e)?e.map(t=>t&&typeof t=="object"&&Object.prototype.hasOwnProperty.call(t,"value")&&"type"in t?t.value:t):[]}function uo(e){return Array.isArray(e)?e.map(t=>t&&typeof t=="object"&&Object.prototype.hasOwnProperty.call(t,"value")&&"type"in t?{type:String(t.type||""),value:t.value}:{type:Xt(t),value:t}):[]}function Gs(e){return String(e?.kind||e?.type||e?.name||e?.id||"")}function Ci(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function yo(e,t){if(!Ci(e)||!Object.prototype.hasOwnProperty.call(e,"fromSignalParam"))return null;if(Object.keys(e).some(n=>n!=="fromSignalParam"))throw new Error(`${t}.fromSignalParam cannot be combined with literal fields`);let i=Number(e.fromSignalParam);if(!Number.isSafeInteger(i)||i<0)throw new Error(`${t}.fromSignalParam must be a non-negative integer`);return{fromSignalParam:i}}function fo(e,t){return yo(e,t)||ye(e)}function Vs(e,t,i){if(!Ci(e))throw new Error(`serverLogic.rules[${t}].actions[${i}] must be an object`);let n=String(e.kind||e.type||""),r=`serverLogic.rules[${t}].actions[${i}]`;if(n==="setCustomVariable"){let o=zs(e.entityType,r);if(!Object.prototype.hasOwnProperty.call(e,"value"))throw new Error(`${r}.value is required`);return{kind:n,entityType:o,name:Ht(e.name),value:fo(e.value,`${r}.value`),...e.variableType?{variableType:String(e.variableType)}:{}}}if(n==="sendClientScriptSignal"){if(!Array.isArray(e.params))throw new Error(`${r}.params must be an array`);return{kind:n,target:yn(e.target),signalName:Ii(e.signalName),params:e.params.map((o,a)=>fo(o,`${r}.params[${a}]`))}}throw new Error(`${r}.kind must be setCustomVariable or sendClientScriptSignal`)}function It(e){if(e==null)return{version:1,rules:[]};if(!Ci(e))throw new Error("serverLogic must be an object");let t=e.rules===void 0?[]:e.rules;if(!Array.isArray(t))throw new Error("serverLogic.rules must be an array");return{version:1,rules:t.map((i,n)=>{if(!Ci(i))throw new Error(`serverLogic.rules[${n}] must be an object`);if(!Array.isArray(i.actions)||i.actions.length===0)throw new Error(`serverLogic.rules[${n}].actions must be a non-empty array`);return{id:String(i.id||`signal-${n+1}`),signalName:Ii(i.signalName),actions:i.actions.map((r,o)=>Vs(r,n,o))}})}}function ho(e,t,{typed:i=!1}={}){let n=yo(e,"server logic value");if(n){let r=i?t.params:t.values;if(n.fromSignalParam>=r.length)throw new Error(`signal ${t.name} has no parameter at index ${n.fromSignalParam}`);return ye(r[n.fromSignalParam])}return ye(e)}function Ys(e){return e==="Level"?"Level":nt.includes(e)?"PlayerSelf":bn.includes(e)?"AvatarSelf":e}function bo(e={}){let t=lo(),i=lo(),n=[],r=[],o=[],a=[],s=Array.from({length:9},()=>null),u=1,l=0,f=Number(e.onlineLatencyMs||0);(!Number.isFinite(f)||f<0)&&(f=0);let h=It(e.logic),p=it(e.playerCount),m=Te(e.viewPlayerIndex,p);function g(v,E){a.push({source:"server",level:String(v||"engine"),text:String(E),time:l})}function b(v){let E=s[v||m],S=Number(E?.clock?.time);Number.isFinite(S)&&(l=S)}function I(v,E,S,k){t[v][E]=S,i[v][E]={type:k||Xt(S)||i[v][E]?.type||""}}function x(v,E,S){return typeof S!="number"||!Number.isInteger(S)?{ok:!0,value:S}:S>=Os&&S<=$s?{ok:!0,value:S}:(g("engine",`Int custom variable ${v}.${E} out of range ${S}; keeping previous legal value`),{ok:!1,value:t[v][E]})}function $(v,E){let S=go(v),k=E||m;return S==="PlayerSelf"?Ut(k):S==="AvatarSelf"?wi(k):S}function P(v,E){let S=Ys(v);if(v==="Level"){for(let w=1;w<=p;w+=1){let T=s[w];T&&typeof T.notifyVarHandlers=="function"&&T.notifyVarHandlers("Level",E)}return}let k=so(v);if(!k)return;let N=s[k];N&&typeof N.notifyVarHandlers=="function"&&N.notifyVarHandlers(S,E)}function V(v,E){let S=yn(v);return S==="AllPlayers"?Array.from({length:p},(k,N)=>N+1):S==="PlayerSelf"?[E||m]:[so(S)]}function X(v){for(let E of h.rules)if(E.signalName===v.name)for(let S of E.actions){if(S.kind==="setCustomVariable"){let k=ho(S.value,v);O.setVar(S.entityType,S.name,k,{type:S.variableType,playerIndex:v.playerIndex}),g("info",`logic ${E.id}: set ${S.entityType}.${S.name}`);continue}if(S.kind==="sendClientScriptSignal"){let k=S.params.map(N=>ho(N,v,{typed:!0}));O.sendToClient(S.signalName,k,{target:S.target,playerIndex:v.playerIndex}),g("info",`logic ${E.id}: sent ${S.signalName} to ${S.target}`)}}}function Z(v,E){v&&(v.serverBridge={getVar:(S,k)=>O.getVar(S,k,{playerIndex:E}),setVar:(S,k,N)=>O.setVar(S,k,N,{playerIndex:E}),receiveFromClient:(S,k)=>O.receiveFromClient(S,k,{playerIndex:E})})}function j(v){v&&(v.serverBridge=null)}let O={ENTITY_TYPES:po,ALL_ENTITY_TYPES:gn,CLIENT_SIGNAL_TARGETS:mo,get clock(){return l},get playerCount(){return p},get viewPlayerIndex(){return m},setClock(v){l=Number(v)||0},setPlayerCount(v){return p=it(v),m>p&&(m=p),p},setViewPlayerIndex(v){return m=Te(v,p),m},log(v,E){g(v,E)},defineVar(v,E,S={},{playerIndex:k}={}){let N=$(v,k),w=Ht(E);if(Object.prototype.hasOwnProperty.call(t[N],w))throw new Error(`custom variable already exists: ${N}.${w}`);let T=S.type?String(S.type):Xt(S.value??S.defaultValue);if(T&&!ao.includes(T))throw new Error(`unsupported custom variable type: ${T}`);let z=S.value!==void 0?S.value:S.defaultValue!==void 0?S.defaultValue:null;return I(N,w,z,T),O.getVar(N,w)},getVar(v,E,{playerIndex:S}={}){let k=$(v,S),N=Ht(E);if(!Object.prototype.hasOwnProperty.call(t[k],N)){g("engine",`GetGlobalCustomVariableValue missing ${k}.${N}; returning nil (simulator policy)`);return}return t[k][N]},setVar(v,E,S,{notify:k=!0,type:N,playerIndex:w}={}){let T=$(v,w),z=Ht(E),G=N||i[T][z]?.type||Xt(S);if(G&&!ao.includes(G)&&G!=="")throw new Error(`unsupported custom variable type: ${G}`);let ie=S;if(!((G==="Int"||G===""&&typeof S=="number"&&Number.isInteger(S))&&(ie=x(T,z,S).value,ie===void 0)))return I(T,z,ie,G),k&&P(T,z),ie},listVars(v){let E=v?[$(v)]:["Level",...Array.from({length:p},(k,N)=>Ut(N+1)),...Array.from({length:p},(k,N)=>wi(N+1))],S=[];for(let k of E)for(let N of Object.keys(t[k]))S.push({entityType:k,name:N,type:i[k][N]?.type||"",value:ye(t[k][N])});return S},receiveFromClient(v,E=[],{playerIndex:S}={}){let k=Te(S||m,p);b(k);let N=Ii(v),w={id:u++,direction:"inbound",name:N,params:uo(E),values:co(E),time:l,playerIndex:k,from:Ut(k)};return n.push(w),X(w),w},sendToClient(v,E=[],{target:S="PlayerSelf",playerIndex:k}={}){let N=Ii(v),w=yn(S),z=V(w,k||m),G={id:u++,direction:"outbound",name:N,params:uo(E),values:co(E),time:l,target:w,players:z,deliverAt:l+f/1e3,delivered:!1};return r.push(G),f===0?O.deliver(G):o.push(G),G},getLogic(){return ye(h)},setLogic(v){return h=It(v),O.getLogic()},deliver(v){if(!v||v.delivered)return;v.delivered=!0;let E=Array.isArray(v.players)&&v.players.length?v.players:V(v.target);for(let S of E){let k=s[S];k&&typeof k.sendClientSignal=="function"&&k.sendClientSignal(v.name,v.values)}},flush(v){v!==void 0&&(l=Number(v)||0);let E=[];for(let S=o.length-1;S>=0;S-=1)o[S].deliverAt<=l&&E.push(o.splice(S,1)[0]);E.sort((S,k)=>S.id-k.id);for(let S of E)O.deliver(S);return E},inbound(){return n.slice()},outbound(){return r.slice()},loadConfig(v){if(v!=null){if(typeof v!="object")throw new Error("server config must be an object");if(v.graph&&!Array.isArray(v.nodes))throw new Error("unsupported server node graph: v1 only accepts custom variables and signals");for(let E of v.nodes||[]){let S=Gs(E);if(!Ds.has(S))throw new Error(`unsupported server node: ${S||JSON.stringify(E)}. v1 only supports custom variables and signals`)}if(v.onlineLatencyMs!==void 0){let E=Number(v.onlineLatencyMs);if(!Number.isFinite(E)||E<0)throw new Error("onlineLatencyMs must be a non-negative finite number");f=E}v.playerCount!==void 0&&O.setPlayerCount(v.playerCount),v.viewPlayerIndex!==void 0&&O.setViewPlayerIndex(v.viewPlayerIndex),(v.logic!==void 0||v.serverLogic!==void 0)&&O.setLogic(v.logic??v.serverLogic);for(let E of v.vars||[]){let S=$(E.entityType),k=Ht(E.name);Object.prototype.hasOwnProperty.call(t[S],k)?O.setVar(S,k,E.value??E.defaultValue,{notify:!1,type:E.type}):O.defineVar(S,k,E)}}},attachRuntime(v,{playerIndex:E=1}={}){let S=Te(E,8);return s[S]&&s[S]!==v&&j(s[S]),s[S]=v||null,Z(s[S],S),O},attachRuntimes(v){O.detachRuntime();let E=Array.isArray(v)?v:[];for(let S=0;S<E.length&&S<8;S+=1)s[S+1]=E[S]||null,Z(s[S+1],S+1);return O},detachRuntime(){for(let v=1;v<=8;v+=1)j(s[v]),s[v]=null},snapshot(){let v=Ut(m),E=wi(m),S={Level:{},PlayerSelf:{},AvatarSelf:{}};for(let k of Object.keys(t.Level))S.Level[k]={type:i.Level[k]?.type||"",value:ye(t.Level[k])};for(let k of Object.keys(t[v]))S.PlayerSelf[k]={type:i[v][k]?.type||"",value:ye(t[v][k])};for(let k of Object.keys(t[E]))S.AvatarSelf[k]={type:i[E][k]?.type||"",value:ye(t[E][k])};for(let k=1;k<=p;k+=1){let N=Ut(k),w=wi(k);S[N]={},S[w]={};for(let T of Object.keys(t[N]))S[N][T]={type:i[N][T]?.type||"",value:ye(t[N][T])};for(let T of Object.keys(t[w]))S[w][T]={type:i[w][T]?.type||"",value:ye(t[w][T])}}return{clock:l,onlineLatencyMs:f,playerCount:p,viewPlayerIndex:m,logic:O.getLogic(),vars:S,inbound:n.map(k=>({id:k.id,name:k.name,params:ye(k.params),values:ye(k.values),time:k.time,playerIndex:k.playerIndex,from:k.from})),outbound:r.map(k=>({id:k.id,name:k.name,params:ye(k.params),values:ye(k.values),time:k.time,target:k.target,players:Array.isArray(k.players)?k.players.slice():[],deliverAt:k.deliverAt,delivered:!!k.delivered})),logs:a.map(k=>({source:"server",level:k.level,text:k.text,time:k.time}))}},reset(){for(let v of gn){for(let E of Object.keys(t[v]))delete t[v][E];for(let E of Object.keys(i[v]))delete i[v][E]}n.length=0,r.length=0,o.length=0,a.length=0,u=1,l=0},destroy(){O.detachRuntime(),O.reset()}};e.config&&O.loadConfig(e.config);for(let v of e.vars||[])O.defineVar(v.entityType,v.name,v);return O}var Bs={container:"container",textbox:"textbox",image:"image",button:"button",cursor:"cursor",grid:"grid",reference:"reference",textwindow:"textwindow",keyhint:"keyhint",animation:"animation",fullscreen:"fullscreen"};function vn(e,t,i=null){let n=Ge(e.transformByPlatform,t),r={authoringId:e.id,kind:Bs[e.kind]||"container",name:e.name,prefabIndex:e.guid||0,active:e.active!==!1,visible:e.visible!==!1,canControllerFocus:e.canControllerFocus===!0,anchoredPositionX:n.offset.x,anchoredPositionY:n.offset.y,sizeDeltaX:n.size.x,sizeDeltaY:n.size.y,anchorMinX:n.anchorMin.x,anchorMinY:n.anchorMin.y,anchorMaxX:n.anchorMax.x,anchorMaxY:n.anchorMax.y,pivotX:n.pivot.x,pivotY:n.pivot.y,localScaleX:n.scale.x,localScaleY:n.scale.y,localScaleZ:n.scale.z,localRotationX:n.rotation.x,localRotationY:n.rotation.y,localRotationZ:n.rotation.z,children:(e.children||[]).map(a=>vn(a,t,i))},o=i?.get(e.id);return o?.length&&(r.scripts=o.map(a=>{let s=Number(a.guid);return{path:a.path||a.id,source:a.source||"",...Number.isSafeInteger(s)&&s>0?{scriptMappingId:s}:{}}})),e.kind==="container"&&(r.isolateNavigation=e.isolateNavigation===!0,r.disableKeyEventPassthrough=e.disableKeyEventPassthrough===!0,r.disableCursorEventPassthrough=e.disableCursorEventPassthrough===!0,r.showCursor=e.showCursor===!0),(e.kind==="textbox"||e.kind==="textwindow")&&(r.text=e.text??"",r.fontSize=e.fontSize,r.adaptiveFontSize=e.adaptiveFontSize===!0,r.minimumFontSize=e.minimumFontSize,r.fontColor=e.fontColor,r.bgColor=e.bgColor,r.enableOutline=e.enableOutline!==!1,r.outlineColor=e.outlineColor,r.horizontalAlignment=e.horizontalAlignment||"Left",r.verticalAlignment=e.verticalAlignment||"Top",e.kind==="textwindow"&&(r.interactable=e.interactable!==!1,r.showScrollBar=e.showScrollBar!==!1)),e.kind==="image"&&(r.imageSource=e.imageSource,r.imageId=e.imageId??0,r.imageColor=e.imageColor,r.raycastTarget=e.raycastTarget===!0,r.enableMask=e.enableMask===!0,r.enableSoftEdge=e.enableSoftEdge===!0,r.softEdgeMode=e.softEdgeMode,r.softEdgeWidthX=e.softEdgeWidthX,r.softEdgeWidthY=e.softEdgeWidthY,r.horizontalSoftRange=e.horizontalSoftRange,r.verticalSoftRange=e.verticalSoftRange,r.enableFill=e.enableFill===!0,r.fillType=e.enableFill?e.fillType:"Unused",r.fillHorizontalType=e.fillHorizontalType,r.fillVerticalType=e.fillVerticalType,r.fillRadial90Type=e.fillRadial90Type,r.fillRadialType=e.fillRadialType,r.fillAmount=e.fillAmount,r.reverseMaskArea=e.reverseMaskArea===!0),e.kind==="button"&&(r.raycastTarget=e.raycastTarget!==!1,r.interactable=e.interactable!==!1,r.clickAudioId=e.clickAudioId,r.unavailableChildId=e.unavailableChildId??null,r.hoverChildId=e.hoverChildId??null,r.pressedChildId=e.pressedChildId??null,r.selectedChildId=e.selectedChildId??null),e.kind==="cursor"&&(r.raycastTarget=e.raycastTarget!==!1),e.kind==="reference"&&(r.referencedPrefabIndex=e.referencedPrefabId),e.kind==="grid"&&(r.itemPrefabIndex=e.itemPrefabId,r.raycastTarget=e.raycastTarget!==!1,r.interactable=e.interactable!==!1,r.showScrollBar=e.showScrollBar!==!1,r.scrollDirection=e.scrollDirection,r.layoutConstraint=e.layoutConstraint,r.layoutConstraintFixedCount=e.layoutConstraintFixedCount,r.cellSizeX=e.cellSizeX,r.cellSizeY=e.cellSizeY,r.spacingX=e.spacingX,r.spacingY=e.spacingY,r.padding1X=e.padding1X,r.padding1Y=e.padding1Y,r.padding2X=e.padding2X,r.padding2Y=e.padding2Y,r.previewCount=e.previewCount),e.kind==="keyhint"&&(r.keyboardKeyCode=e.keyboardKeyCode,r.controllerKeyCode=e.controllerKeyCode),(e.kind==="animation"||e.kind==="fullscreen")&&(r.raycastTarget=!1,r.animationId=e.animationId,r.playSoundEffect=e.playSoundEffect,e.kind==="animation"&&(r.layer=e.layer)),r}function Sn(e,t=[],i=""){let n=i&&U[i]?i:e.canvasId,r=U[n],o=Dt(e),a=new Map;for(let u of t){if(!u.controlId)continue;let l=a.get(u.controlId)||[];l.push(u),a.set(u.controlId,l)}let s=e.meta?.assetType==="client-control-template"?(e.root.children||[]).map(u=>vn(u,n,a)):[];return{canvasId:n,platform:r.platform,device:r.luaDevice,canvasWidth:r.width,canvasHeight:r.height,root:vn(o,n,a),templates:s}}var ki="qxqy-autotest";var rt=.03333333333333333,Us=new Set(["pointer","key","click","pause","resume","serverSet","serverSend","view"]),Hs=new Set(["log","control","var","signal","tree","lua"]);function Kt(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function wn(e){return JSON.parse(JSON.stringify(e??null))}function xi(e,t){if(!e||typeof e!="object")throw new Error(`events[${t}] must be an object`);let i=String(e.kind||e.do||"");if(!Us.has(i))throw new Error(`unsupported event kind: ${i||"(empty)"}`);let n=e.payload&&typeof e.payload=="object"?{...e.payload}:{};if(i==="pointer")!n.type&&e.type&&(n.type=e.type),n.x===void 0&&(n.x=e.x),n.y===void 0&&(n.y=e.y),n.x=Kt(n.x,"pointer.x"),n.y=Kt(n.y,"pointer.y"),n.type=String(n.type||"click");else if(i==="key"){if(n.typeName=String(n.typeName||n.key||e.typeName||e.key||""),!n.typeName)throw new Error("key event requires typeName")}else if(i==="click"){if(n.name=String(n.name||e.name||""),!n.name)throw new Error("click event requires control name")}else if(i==="serverSet"){if(n.entityType=String(n.entityType||e.entityType||""),n.name=String(n.name||e.name||""),n.value===void 0&&(n.value=e.value),n.value===void 0&&(n.value=null),!n.entityType||!n.name)throw new Error("serverSet requires entityType and name")}else if(i==="serverSend"){if(n.name=String(n.name||e.name||""),n.params=Array.isArray(n.params)?n.params:Array.isArray(e.params)?e.params:[],n.target=String(n.target||e.target||"PlayerSelf"),!n.name)throw new Error("serverSend requires signal name")}else if(i==="view"&&(n.playerIndex=Number(n.playerIndex||n.viewPlayerIndex||e.playerIndex||e.viewPlayerIndex||0),!Number.isInteger(n.playerIndex)||n.playerIndex<1))throw new Error("view event requires playerIndex 1-8");return{t:Kt(e.t??0,"event.t"),source:String(e.source||"user"),kind:i,payload:n}}function In(e,t){if(!e||typeof e!="object")throw new Error(`asserts[${t}] must be an object`);let i=String(e.kind||(e.check?"log":""));if(!Hs.has(i))throw new Error(`unsupported assert kind: ${i||"(empty)"}`);let n={kind:i};if(e.at!==void 0&&(n.at=Kt(e.at,"assert.at")),i==="log"){if(n.contains=String(e.contains||e.check||e.text||""),n.source=e.source==="server"?"server":"client",e.level&&(n.level=String(e.level)),!n.contains)throw new Error("log assert requires contains")}else if(i==="control"){if(n.id=e.id?String(e.id):"",n.name=e.name?String(e.name):"",n.field=String(e.field||""),!n.field)throw new Error("control assert requires field");if(!n.id&&!n.name)throw new Error("control assert requires id or name");if(!Object.prototype.hasOwnProperty.call(e,"equals"))throw new Error("control assert requires equals");n.equals=wn(e.equals)}else if(i==="var"){if(n.entityType=String(e.entityType||""),n.name=String(e.name||""),!n.entityType||!n.name)throw new Error("var assert requires entityType and name");if(!Object.prototype.hasOwnProperty.call(e,"equals"))throw new Error("var assert requires equals");n.equals=wn(e.equals)}else if(i==="signal"){if(n.direction=e.direction==="outbound"?"outbound":"inbound",n.name=String(e.name||""),!n.name)throw new Error("signal assert requires name");e.values!==void 0&&(n.values=wn(e.values))}else if(i==="tree"){if(n.name=String(e.name||""),n.exists=e.exists!==!1,!n.name)throw new Error("tree assert requires name")}else if(i==="lua"&&(n.source=String(e.source||""),!n.source.trim()))throw new Error("lua assert requires source");return n}function vo(e){let t=0,i=[],n=[];for(let r of e){if(!r||typeof r!="object")throw new Error("queue step must be an object");if(r.do!=="start"){if(r.do==="step"){t+=Kt(r.dt??rt,"step.dt");continue}if(r.do==="pointer"||r.do==="key"||r.do==="click"||r.do==="pause"||r.do==="resume"||r.do==="serverSet"||r.do==="serverSend"||r.do==="view"){i.push(xi({...r,kind:r.do,t},i.length));continue}if(r.assert||r.check||r.kind){n.push(In({...r.assert||r,at:r.at??t},n.length));continue}throw new Error(`unsupported queue step: ${JSON.stringify(r)}`)}}return{events:i,asserts:n,dt:rt}}function Lt(e){if(Array.isArray(e)){let n=vo(e);return{format:ki,version:1,name:"",dt:n.dt,events:n.events,asserts:n.asserts}}if(!e||typeof e!="object")throw new Error("autotest case must be an object or step array");if(Array.isArray(e.queue)||Array.isArray(e.steps)){let n=vo(e.queue||e.steps);return{format:ki,version:1,name:String(e.name||""),dt:Number(e.dt)>0?Number(e.dt):n.dt,events:n.events,asserts:n.asserts}}let t=(e.events||[]).map((n,r)=>xi(n,r)),i=(e.asserts||[]).map((n,r)=>In(n,r));return t.sort((n,r)=>n.t-r.t||0),{format:ki,version:1,name:String(e.name||""),dt:Number(e.dt)>0?Number(e.dt):rt,playerCount:Number(e.playerCount)>0?Number(e.playerCount):1,events:t,asserts:i}}function So(e,t={}){let i=(e||[]).map((n,r)=>xi(n,r));return{format:ki,version:1,name:String(t.name||""),dt:Number(t.dt)>0?Number(t.dt):rt,playerCount:Number(t.playerCount)>0?Number(t.playerCount):1,events:i,asserts:(t.asserts||[]).map((n,r)=>In(n,r))}}function wo(e,t,i){if(!e)return null;let n=xi({...t,t:t.t??i??0},e.events.length);return e.events.push(n),n}var Xs=Object.freeze(Object.values(U).map(e=>Object.freeze({id:e.id,label:e.label,platform:e.platform,width:e.width,height:e.height})));function En(e){let t=de({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),i=new Map;function n(r,o,a){let s=_e(o,r);s.activeInHierarchy=a&&r.active!==!1,i.set(r.Id,s);let u=s.activeInHierarchy;for(let l of r.children)n(l,s,u)}for(let r of e.runtime.roots)n(r,t,!0);return i}function Ks(e,t=En(e)){let i=new Map;function n(r,o){let a=t.get(r.Id);if(!a)return;let s=$t(o,a,r);i.set(r.Id,s);for(let u of r.children)n(u,s)}for(let r of e.runtime.roots)n(r,yt());return i}function Co(e,t){let i=t.get(e.Id);return{id:e.Id,prefabId:e.prefabIndex,authoringId:e.authoringId,name:e.name,kind:e.kind,typeofName:e.typeofName,instantiated:!e.authoringId,active:!!e.active,visible:!!e.visible,activeInHierarchy:!!i?.activeInHierarchy,raycastTarget:e.raycastTarget!==!1,interactable:e.interactable!==!1,pressed:e.pressed===!0,anchoredPositionX:e.anchoredPositionX,anchoredPositionY:e.anchoredPositionY,sizeDeltaX:e.sizeDeltaX,sizeDeltaY:e.sizeDeltaY,localScaleX:e.localScaleX,localScaleY:e.localScaleY,localScaleZ:e.localScaleZ,localRotationZ:e.localRotationZ,text:e.kind==="textbox"||e.kind==="textwindow"?e.text??"":null,fontSize:e.kind==="textbox"||e.kind==="textwindow"?e.fontSize:null,fontColor:e.kind==="textbox"||e.kind==="textwindow"?e.fontColor:null,bgColor:e.kind==="textbox"||e.kind==="textwindow"?e.bgColor:null,enableOutline:e.kind==="textbox"||e.kind==="textwindow"?e.enableOutline===!0:null,outlineColor:e.kind==="textbox"||e.kind==="textwindow"?e.outlineColor:null,imageId:e.kind==="image"?e.imageId??0:null,primitive:e.kind==="image"?mt[e.imageId]||"missing":null,imageColor:e.kind==="image"?e.imageColor:null,enableMask:e.kind==="image"?e.enableMask===!0:null,enableSoftEdge:e.kind==="image"?e.enableSoftEdge===!0:null,softEdgeMode:e.kind==="image"?e.softEdgeMode:null,softEdgeWidthX:e.kind==="image"?e.softEdgeWidthX:null,softEdgeWidthY:e.kind==="image"?e.softEdgeWidthY:null,horizontalSoftRange:e.kind==="image"?e.horizontalSoftRange:null,verticalSoftRange:e.kind==="image"?e.verticalSoftRange:null,enableFill:e.kind==="image"?e.enableFill===!0:null,fillType:e.kind==="image"?e.fillType:null,fillHorizontalType:e.kind==="image"?e.fillHorizontalType:null,fillVerticalType:e.kind==="image"?e.fillVerticalType:null,fillRadial90Type:e.kind==="image"?e.fillRadial90Type:null,fillRadialType:e.kind==="image"?e.fillRadialType:null,reverseMaskArea:e.kind==="image"?e.reverseMaskArea===!0:null,fillAmount:e.kind==="image"?e.fillAmount:null,box:i?{left:i.left,bottom:i.bottom,width:i.width,height:i.height}:null,children:e.children.map(n=>Co(n,t))}}function Ls(){return{pointerDownControl:null,pointerDownPosition:null,pointerLastPosition:null,pointerDragging:!1,pointerHoverControl:null,hoveredControl:null,selectedControl:null,stateRestores:new Map,viewCache:null}}function Ws(e,t,i){let n=Bt({canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight,device:e.device});for(let r of[...e.templates||[],...t?.templates||[]])Number.isSafeInteger(r.prefabIndex)&&r.prefabIndex>0&&n.registerTemplate(r.prefabIndex,r);for(let r of i){let o=r.path||r.id,a=r.source||"";o&&a&&n.registerScriptFile(o,a)}return n}var js=["pointerDownControl","pointerDownPosition","pointerLastPosition","pointerDragging","pointerHoverControl","hoveredControl","selectedControl","stateRestores","viewCache"];function qs(e){Object.defineProperty(e,"runtime",{configurable:!0,enumerable:!0,get(){return e.runtimes[e.viewPlayerIndex-1]}});for(let t of js)Object.defineProperty(e,t,{configurable:!0,enumerable:!0,get(){return e.views[e.viewPlayerIndex-1][t]},set(i){e.views[e.viewPlayerIndex-1][t]=i}})}function ko(e,{templatesProject:t=null,scripts:i=[],sceneScripts:n=null,templateScripts:r=null,serverConfig:o=null,canvasId:a="",playerCount:s=1,viewPlayerIndex:u=1}={}){let l=n||i,f=r||i,h=Sn(e,l,a),p=t?Sn(t,f,a):null,m=it(s),g=Te(u,m),b=bo({playerCount:m,viewPlayerIndex:g});o&&b.loadConfig({...o,playerCount:m,viewPlayerIndex:g});let I=[];for(let P=0;P<m;P+=1)I.push(Ws(h,p,i));b.attachRuntimes(I);for(let P of I)P.addRoot(h.root);let x={runtimes:I,views:I.map(()=>Ls()),playerCount:m,viewPlayerIndex:g,server:b,compiled:h,mountError:I.find(P=>P.mountErrors[0])?.mountErrors[0]||null,debugPaused:!1,history:{events:[]},recording:!0};qs(x);let $=x.viewPlayerIndex;for(let P=1;P<=m;P+=1)x.viewPlayerIndex=P,ll(x);return x.viewPlayerIndex=$,x}function An(e,t){if(!e)throw new Error("play session has not started");let i=Te(t,e.playerCount);return i===e.viewPlayerIndex||(He(e,{kind:"view",payload:{playerIndex:i}}),e.viewPlayerIndex=i,e.viewCache=null,e.server&&e.server.setViewPlayerIndex(i)),i}function He(e,t){!e?.recording||!e.history||wo(e.history,{...t,source:t.source||"user"},e.runtime.clock.time)}function Js(e){return e?.history?.events||[]}var _n=new Set(["image","textbox","textwindow","button"]);function Zs(e,t){let i=Le(t,e.centerX,e.centerY);return{centerX:i.x,centerY:i.y,scaleX:Math.hypot(t.a,t.b),scaleY:Math.hypot(t.c,t.d),rotationZ:Math.atan2(t.b,t.a)*180/Math.PI,matrix:{a:t.a,b:t.b,c:t.c,d:t.d,tx:i.x,ty:i.y}}}function ot(e){return typeof e=="string"?e:e?.Name}function xo(e){return{fillType:ot(e.fillType),fillHorizontalType:ot(e.fillHorizontalType),fillVerticalType:ot(e.fillVerticalType),fillAmount:e.fillAmount}}function Qs(e,t,i){let n=Math.abs(t.width*i.scaleX),r=Math.abs(t.height*i.scaleY),o={id:e.Id,kind:e.kind,name:e.name,left:i.centerX-n/2,bottom:i.centerY-r/2,width:n,height:r,sourceWidth:t.width,sourceHeight:t.height,rotationZ:i.rotationZ,matrix:i.matrix,pressed:e.pressed===!0};return e.kind==="image"&&(o.primitive=mt[e.imageId]||"missing",o.imageColor=e.imageColor,o.imageId=e.imageId,Object.assign(o,xo(e))),(e.kind==="textbox"||e.kind==="textwindow")&&(o.text=e.text??"",o.fontSize=e.fontSize,o.fontColor=e.fontColor,o.bgColor=e.bgColor,o.enableOutline=e.enableOutline===!0,o.outlineColor=e.outlineColor,o.horizontalAlignment=ot(e.horizontalAlignment),o.verticalAlignment=ot(e.verticalAlignment)),o}function el(e,t=En(e)){let i=[],n=Ks(e,t);function r(o){let a=t.get(o.Id);if(!a||o.visible===!1||!a.activeInHierarchy)return;let s=n.get(o.Id);if(!s)return;let u=Zs(a,s);_n.has(o.kind)&&i.push(Qs(o,a,u));let l=o.children||[];for(let f=l.length-1;f>=0;f-=1)r(l[f])}for(let o of e.runtime.roots)r(o);return i}function tl(e,t){let i={kind:e.kind,name:e.name,sourceWidth:t.width,sourceHeight:t.height,pressed:e.pressed===!0};return e.kind==="image"&&(i.primitive=mt[e.imageId]||"missing",i.imageColor=e.imageColor,i.imageId=e.imageId,Object.assign(i,xo(e))),(e.kind==="textbox"||e.kind==="textwindow")&&(i.text=e.text??"",i.fontSize=e.fontSize,i.fontColor=e.fontColor,i.bgColor=e.bgColor,i.enableOutline=e.enableOutline===!0,i.outlineColor=e.outlineColor,i.horizontalAlignment=ot(e.horizontalAlignment),i.verticalAlignment=ot(e.verticalAlignment)),i}function il(e,t,i){let n=Vi(e,t),r=Le(n,e.centerX,e.centerY);return{a:n.a,b:n.b,c:n.c,d:n.d,tx:r.x-(i?i.centerX:0),ty:r.y-(i?i.centerY:0)}}function Eo(e){let t=e.matrix;return[e.parent,e.z,e.group?1:0,t.a,t.b,t.c,t.d,t.tx,t.ty,e.kind,e.name,e.sourceWidth,e.sourceHeight,e.pressed,e.primitive,e.imageColor,e.imageId,e.fillType,e.fillHorizontalType,e.fillVerticalType,e.fillAmount,e.text,e.fontSize,e.fontColor,e.bgColor,e.enableOutline,e.outlineColor,e.horizontalAlignment,e.verticalAlignment].join(" ")}function Ao(e,t,i,n,r,o){return{id:e.Id,parent:t,z:r,group:o>=16,matrix:il(n,e,i),...tl(e,n)}}function nl(e){let t=de({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),i=new Set,n=new Map,r=new Map;function o(u,l,f){let h=_e(l,u);if(h.activeInHierarchy=f&&u.active!==!1,r.set(u.Id,h),u.visible===!1||!h.activeInHierarchy)return!1;let p=u.children||[],m=_n.has(u.kind),g=0;for(let b=0;b<p.length;b+=1)o(p[b],h,h.activeInHierarchy)&&(m=!0,g+=1);return m?(i.add(u.Id),n.set(u.Id,g),!0):!1}function a(u,l,f,h){if(!i.has(u.Id))return;let p=r.get(u.Id);s.push(Ao(u,l,f,p,h,n.get(u.Id)||0));let m=u.children||[];for(let g=0;g<m.length;g+=1)a(m[g],u.Id,p,g)}let s=[];for(let u=0;u<e.runtime.roots.length;u+=1)o(e.runtime.roots[u],t,!0),a(e.runtime.roots[u],null,null,u);return{nodes:s,childCounts:n}}function xn(e){let t=e._playChildDirty===!0||e._playDeepDirty===!0;if(e._playDirty=!1,e._playChildDirty=!1,e._playDeepDirty=!1,!t)return;let i=e.children;for(let n=0;n<i.length;n+=1)xn(i[n])}function rl(e,t){let i=de({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),n=[],r=[],o=t.count,a=e.runtime._playRemoved||[];for(let l=0;l<a.length;l+=1){let f=a[l];t.fingerprints.has(f)&&(r.push(f),t.fingerprints.delete(f),t.childCounts.delete(f),o-=1)}e.runtime._playRemoved=[];function s(l){t.fingerprints.has(l.Id)&&(r.push(l.Id),t.fingerprints.delete(l.Id),t.childCounts.delete(l.Id),o-=1);let f=l.children;for(let h=0;h<f.length;h+=1)s(f[h])}function u(l,f,h,p,m,g){let b=g||l._playDeepDirty===!0,I=b||l._playDirty===!0,x=b||l._playChildDirty===!0;if(!I&&!x)return;if(!(m&&l.active!==!1)||l.visible===!1){s(l);return}let P=_e(f,l),V=t.childCounts.get(l.Id)||0;if(x){V=0;let E=l.children;for(let S=0;S<E.length;S+=1)u(E[S],P,l.Id,S,!0,b),t.fingerprints.has(E[S].Id)&&(V+=1)}if(!(_n.has(l.kind)||V>0)){t.fingerprints.has(l.Id)&&(r.push(l.Id),t.fingerprints.delete(l.Id),t.childCounts.delete(l.Id),o-=1);return}let Z=t.childCounts.get(l.Id);t.childCounts.set(l.Id,V);let j=V>=16!=(Z||0)>=16;if(!I&&!j&&t.fingerprints.has(l.Id))return;let O=Ao(l,h,f===i?null:f,P,p,V),v=Eo(O);t.fingerprints.get(O.id)!==v&&(t.fingerprints.has(O.id)||(o+=1),t.fingerprints.set(O.id,v),n.push(O))}for(let l=0;l<e.runtime.roots.length;l+=1)u(e.runtime.roots[l],i,null,l,!0,!1);return t.count=o,{changed:n,removed:r,count:o}}function ol(e,t){let i=e.viewCache||(e.viewCache={rev:0,fingerprints:new Map,childCounts:new Map,count:0}),n=Number(t);if(!(Number.isFinite(n)&&n===i.rev&&i.fingerprints.size>0)){let{nodes:u,childCounts:l}=nl(e);i.rev+=1,i.fingerprints=new Map(u.map(f=>[f.id,Eo(f)])),i.childCounts=l,i.count=u.length;for(let f of e.runtime.roots)xn(f);return{format:"tree-v1",revision:i.rev,reset:!0,count:u.length,nodes:u}}let{changed:o,removed:a,count:s}=rl(e,i);i.rev+=1;for(let u of e.runtime.roots)xn(u);return{format:"tree-v1",revision:i.rev,reset:!1,count:s,changed:o,removed:a}}function Pn(e,{inspect:t=!1,view:i=!1,paint:n=!1,sceneRev:r,compact:o=!1}={}){let a=e.runtime,s=e.compiled,[u,l]=[a.canvasWidth,a.canvasHeight];e.server&&e.server.setClock(a.clock.time);let f=o?a.logs.slice(-100):a.logs,h=Js(e),p=e.server?e.server.snapshot():{vars:{},inbound:[],outbound:[],logs:[]};o&&(p.inbound=p.inbound.slice(-100),p.outbound=p.outbound.slice(-100),p.logs=p.logs.slice(-100));let m={canvasId:s.canvasId,platform:s.platform,device:a.device,canvasWidth:u,canvasHeight:l,canvasPresets:Xs,playerCount:e.playerCount||1,viewPlayerIndex:e.viewPlayerIndex||1,players:Array.from({length:e.playerCount||1},(g,b)=>({index:b+1,label:`\u73A9\u5BB6${b+1}`,entityType:`Player${b+1}`})),time:a.clock.time,frame:a.clock.frame,paused:!!e.debugPaused,levelTimePaused:!!a.clock.paused,mountError:e.mountError||a.mountErrors[0]||null,logs:f.map(g=>({source:"client",level:g.level,text:g.text,time:g.time})),tree:[],paint:[],scene:null,server:p,history:(o?h.slice(-100):h).map(g=>({t:g.t,source:g.source||"user",kind:g.kind,payload:g.payload||{}}))};if(t||n){let g=En(e);t&&(m.tree=a.roots.map(b=>Co(b,g))),n&&(m.paint=el(e,g))}return i&&(m.scene=ol(e,r)),gt(m),m}function Ei(e,t=1/30){let i=e.runtimes||(e.runtime?[e.runtime]:[]);for(let n of i)n.step(t);e.server&&(e.server.setClock(e.runtime.clock.time),e.server.flush())}function Tn(e,t){He(e,{kind:"key",payload:{typeName:String(t)}}),e.runtime.injectKey(t)}function al(e,t){let i=null;for(let n of e.runtime.roots)Ie(n,r=>{!i&&r.name===t&&(i=r)});return i}function Rn(e,t){He(e,{kind:"click",payload:{name:String(t)}});let i=al(e,t);i&&Mn(i)&&(i.kind==="button"||i.kind==="cursor")&&i.SimulateCursorClick()}function sl(e,t){return!e||!t?null:e.children.find(i=>i.authoringId===t||i.Id===t)||null}var _o={unavailable:"unavailableChildId",hover:"hoverChildId",pressed:"pressedChildId",selected:"selectedChildId"};function Po(e,t){let i=[];for(let[n,r]of Object.entries(_o)){let o=t[r]?sl(t,t[r]):null;o&&i.push({state:n,child:o})}return i}function ll(e){for(let t of e.runtime.roots)Ie(t,i=>{if(i.kind==="button"){for(let{child:n}of Po(e,i))e.stateRestores.has(n.Id)||e.stateRestores.set(n.Id,{child:n,active:n.active,visible:n.visible}),n.active=!0,n.visible=!1,typeof n.markPlayDirty=="function"&&n.markPlayDirty(!0);jt(e,i)}})}function jt(e,t){if(!t||t.kind!=="button")return;let i=null;t.interactable===!1?i="unavailable":t.pressed===!0?i="pressed":e.hoveredControl===t?i="hover":e.selectedControl===t&&(i="selected");for(let n of Po(e,t))n.child.active=!0,n.child.visible=n.state===i,typeof n.child.markPlayDirty=="function"&&n.child.markPlayDirty(!0)}function Cn(e){if(!e)return null;let t=e.parent;return t?.kind==="button"&&Object.values(_o).map(n=>t[n]).filter(Boolean).includes(e.authoringId)?t:e}function Mn(e){return e.kind==="button"?e.raycastTarget!==!1&&e.interactable!==!1:e.kind==="cursor"||e.kind==="grid"?e.raycastTarget!==!1:e.kind==="textwindow"?e.interactable!==!1:e.raycastTarget===!0}function To(e){return e.kind==="container"||e.kind==="grid"||e.kind==="textwindow"||e.kind==="reference"||e.kind==="button"}function Ro(e,t){let i=e.Id,n=t.get(i);if(n!==void 0)return n;let r=Mn(e);if(!r&&To(e)){let o=e.children;for(let a=0;a<o.length;a+=1)if(Ro(o[a],t)){r=!0;break}}return t.set(i,r),r}function kn(e,t,i){let n=de({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),r=new Map;function o(s,u,l,f){if(!f||s.active===!1||s.visible===!1||!Ro(s,r))return null;let h=_e(u,s),p=$t(l,h,s),m=ai(p);if(!m)return null;let g=Le(m,t,i);if(g.x<h.left||g.x>h.right||g.y<h.bottom||g.y>h.top)return null;if(To(s))for(let b=0;b<s.children.length;b+=1){let I=o(s.children[b],h,p,!0);if(I)return I}return Mn(s)?s:null}let a=yt();for(let s=e.runtime.roots.length-1;s>=0;s-=1){let u=o(e.runtime.roots[s],n,a,!0);if(u)return u}return null}function Wt(e,t,i,{dragging:n=!1,press:r=null,previous:o=null}={}){let a=r||{x:t,y:i},s=o||{x:t,y:i};return e.runtime.makeCursorEventData({x:t,y:i,pressX:a.x,pressY:a.y,deltaX:t-s.x,deltaY:i-s.y,dragging:n})}function Io(e,t,i){t.pressed=i,typeof t.markPlayDirty=="function"&&t.markPlayDirty(),jt(e,t)}function qt(e,t,i,n,r={}){let o=Number(i),a=Number(n);if(!Number.isFinite(o)||!Number.isFinite(a))throw new Error("pointer coordinates must be finite");if(e.runtime.cursor.x=o,e.runtime.cursor.y=a,r.silent||He(e,{kind:"pointer",payload:{type:t,x:o,y:a}}),t==="move"){let s=e.pointerLastPosition||{x:o,y:a},u=e.pointerHoverControl,l=Cn(kn(e,o,a)),f=Wt(e,o,a,{previous:s});u&&u!==l&&e.runtime.injectCursor(u,"CursorExit",f),l&&u!==l&&e.runtime.injectCursor(l,"CursorEnter",f),e.pointerHoverControl=l;let h=e.hoveredControl;e.hoveredControl=l?.kind==="button"?l:null,h&&h!==e.hoveredControl&&jt(e,h),e.hoveredControl&&jt(e,e.hoveredControl);let p=e.pointerDownControl;if(p){let m=e.pointerDownPosition||s,g=o!==s.x||a!==s.y;!e.pointerDragging&&g&&(e.runtime.injectCursor(p,"CursorBeginDrag",Wt(e,o,a,{press:m,previous:s,dragging:!1})),e.pointerDragging=!0),e.pointerDragging&&e.runtime.injectCursor(p,"CursorDrag",Wt(e,o,a,{press:m,previous:s,dragging:!0}))}return e.pointerLastPosition={x:o,y:a},l}if(t==="down"){let s=Cn(kn(e,o,a));return e.pointerDownControl=s,e.pointerDownPosition={x:o,y:a},e.pointerLastPosition={x:o,y:a},e.pointerDragging=!1,s&&(Io(e,s,!0),e.runtime.injectCursor(s,"CursorDown",Wt(e,o,a))),s}if(t==="up"){let s=e.pointerDownControl,u=Cn(kn(e,o,a));if(s){let l=Wt(e,o,a,{press:e.pointerDownPosition,previous:e.pointerLastPosition,dragging:e.pointerDragging});if(e.runtime.injectCursor(s,"CursorUp",l),e.pointerDragging)e.runtime.injectCursor(s,"CursorEndDrag",l);else if(u===s){e.runtime.injectCursor(s,"CursorClick",l);let f=e.selectedControl;e.selectedControl=s.kind==="button"?s:null,f&&f!==e.selectedControl&&jt(e,f)}Io(e,s,!1)}return e.pointerDownControl=null,e.pointerDownPosition=null,e.pointerLastPosition={x:o,y:a},e.pointerDragging=!1,u}if(t==="click")return qt(e,"down",o,a,{silent:!0}),qt(e,"up",o,a,{silent:!0});throw new Error(`unknown pointer type ${t}`)}function Nn(e,t,i,n){if(!e?.server)throw new Error("play session has no server");return He(e,{kind:"serverSet",payload:{entityType:t,name:i,value:n,playerIndex:e.viewPlayerIndex}}),e.server.setVar(t,i,n,{playerIndex:e.viewPlayerIndex})}function Mo(e,t,i){if(!e?.server)throw new Error("play session has no server");let n=e.server.getVar(t,i,{playerIndex:e.viewPlayerIndex});return n===void 0?null:n}function Fn(e,t,i=[],n="PlayerSelf"){if(!e?.server)throw new Error("play session has no server");return He(e,{kind:"serverSend",payload:{name:t,params:i,target:n,playerIndex:e.viewPlayerIndex}}),e.server.sendToClient(t,i,{target:n,playerIndex:e.viewPlayerIndex})}function Ai(e){return{snapshot:t=>Pn(e,t),step:t=>Ei(e,t),pointer:(t,i,n)=>qt(e,t,i,n),key:t=>Tn(e,t),click:t=>Rn(e,t),view:t=>An(e,t),pause:()=>{He(e,{kind:"pause",payload:{}}),e.debugPaused=!0},resume:()=>{He(e,{kind:"resume",payload:{}}),e.debugPaused=!1},serverSet:(t,i,n)=>Nn(e,t,i,n),serverSend:(t,i,n)=>Fn(e,t,i,n)}}function On(e){e?.server&&e.server.destroy();let t=e?.runtimes||(e?.runtime?[e.runtime]:[]);for(let i of t)i.destroy()}function $n(e,t){return JSON.stringify(e)===JSON.stringify(t)}function No(e,t){for(let i of e||[])t(i),i.children?.length&&No(i.children,t)}function Dn(e,{id:t,name:i}){let n=null;return No(e,r=>{n||(t&&String(r.id)===String(t)||!t&&i&&r.name===i)&&(n=r)}),n}function cl(e,t){if(e){if(Object.prototype.hasOwnProperty.call(e,t))return e[t];if(e.box&&Object.prototype.hasOwnProperty.call(e.box,t))return e.box[t]}}function ul(e){return{var(t,i){return e.server?.vars?.[t]?.[i]?.value??null},logs(){return(e.logs||[]).map(t=>t.text)},logContains(t){return(e.logs||[]).some(i=>String(i.text||"").includes(String(t)))},serverLogs(){return(e.server?.logs||e.serverLogs||[]).map(t=>t.text)},serverLogContains(t){return(e.server?.logs||e.serverLogs||[]).some(i=>String(i.text||"").includes(String(t)))},control(t){let i=Dn(e.tree,{name:String(t)});return i?{id:i.id,name:i.name,kind:i.kind,active:i.active,visible:i.visible,pressed:i.pressed,text:i.text,interactable:i.interactable}:null},signals(t){let i=t==="outbound"?"outbound":"inbound";return(e.server?.[i]||[]).map(n=>({name:n.name,values:n.values}))}}}function fl(e,t){if(e.kind==="log"){let i=e.source==="server"?t.server?.logs||t.serverLogs||[]:t.logs||[];return i.some(r=>e.level&&r.level!==e.level?!1:String(r.text||"").includes(e.contains))?{ok:!0,actual:e.contains}:{ok:!1,actual:i.map(r=>r.text).slice(-8),expected:e.contains}}if(e.kind==="control"){let i=Dn(t.tree,e);if(!i)return{ok:!1,actual:null,expected:e.equals,message:`control not found: ${e.id||e.name}`};let n=cl(i,e.field);return $n(n,e.equals)?{ok:!0,actual:n}:{ok:!1,actual:n,expected:e.equals}}if(e.kind==="var"){let i=t.server?.vars?.[e.entityType],r=!i||!Object.prototype.hasOwnProperty.call(i,e.name)?null:i[e.name].value;return $n(r,e.equals)?{ok:!0,actual:r}:{ok:!1,actual:r,expected:e.equals}}if(e.kind==="signal"){let i=e.direction==="outbound"?t.server?.outbound||[]:t.server?.inbound||[],n=i.find(r=>r.name===e.name&&(e.values===void 0||$n(r.values,e.values)));return n?{ok:!0,actual:n.values}:{ok:!1,actual:i.map(r=>({name:r.name,values:r.values})),expected:{name:e.name,values:e.values??null}}}if(e.kind==="tree"){let i=!!Dn(t.tree,{name:e.name});return i===e.exists?{ok:!0,actual:i}:{ok:!1,actual:i,expected:e.exists}}return{ok:!1,message:`unsupported assert kind ${e.kind}`}}function dl(e,t){let i=Bt();try{return i.evalQueryScript(e,ul(t)),{ok:!0,actual:!0}}catch(n){return{ok:!1,message:n?.message||String(n)}}finally{i.destroy()}}function Fo(e,t){return e.kind==="lua"?dl(e.source,t):fl(e,t)}function hl(e,t){let i=t>0?t:rt;return Math.round((e+i)*1e9)/1e9}function pl(e,t){let i=t.payload||{};if(t.kind==="pointer")e.pointer(i.type,i.x,i.y);else if(t.kind==="key")e.key(i.typeName);else if(t.kind==="click")e.click(i.name);else if(t.kind==="pause")e.pause();else if(t.kind==="resume")e.resume();else if(t.kind==="serverSet")e.serverSet(i.entityType,i.name,i.value);else if(t.kind==="serverSend")e.serverSend(i.name,i.params,i.target);else if(t.kind==="view")e.view(i.playerIndex);else throw new Error(`unsupported event kind: ${t.kind}`)}function ml(e,t){let i=Fo(e,t);return{kind:e.kind,at:Number(e.at||0),ok:!!i.ok,actual:i.actual??null,expected:i.expected??null,message:i.message||""}}function Oo(e,t){let i=Lt(t),n=i.events.slice().sort((x,$)=>x.t-$.t),r=i.asserts.slice(),o=i.dt||rt,a=n.reduce((x,$)=>Math.max(x,$.t),0),s=r.reduce((x,$)=>Math.max(x,Number($.at||0)),0),u=Math.max(a,s),l=0,f=[],h=0,p=r.some(x=>x.kind==="control"||x.kind==="tree"||x.kind==="lua"),m=e.snapshot({inspect:p}),g=()=>{for(;l<n.length&&n[l].t<=h+1e-9;)pl(e,n[l]),l+=1,m=e.snapshot({inspect:p})},b=()=>{for(let x of r)if(!x._done&&Number(x.at||0)<=h+1e-9){let $=ml(x,m);if(f.push($),x._done=!0,!$.ok)return{passed:!1,failedAt:h,frame:m.frame||0,results:f,snapshot:m}}return null};g();let I=b();if(I)return zn(i,I);for(;h+1e-9<u;){e.step(o),h=hl(h,o),m=e.snapshot({inspect:p}),g();let x=b();if(x)return zn(i,x)}return zn(i,{passed:f.every(x=>x.ok),failedAt:null,frame:m.frame||0,results:f,snapshot:m})}function zn(e,t){return D({format:e.format,name:e.name,passed:t.passed,failedAt:t.failedAt,frame:t.frame,results:t.results,snapshot:{time:t.snapshot?.time??0,frame:t.snapshot?.frame??0,logs:t.snapshot?.logs||[],serverLogs:t.snapshot?.serverLogs||t.snapshot?.server?.logs||[],server:t.snapshot?.server||{vars:{},inbound:[],outbound:[],logs:[]}}})}function Gn(e){return Array.isArray(e)?e.slice():[]}var Sl={Level:"\u5173\u5361",PlayerSelf:"\u5F53\u524D\u73A9\u5BB6",AvatarSelf:"\u5F53\u524D\u89D2\u8272",...Object.fromEntries(nt.map((e,t)=>[e,`\u73A9\u5BB6${t+1}`])),...Object.fromEntries(Array.from({length:8},(e,t)=>[`Avatar${t+1}`,`\u89D2\u8272${t+1}`]))};function wl(e,t=1){let i=e?.vars||{},n=[],r=Number(t)>0?Number(t):1,o=["Level","PlayerSelf","AvatarSelf"];if(r>1)for(let s=1;s<=r;s+=1)o.push(`Player${s}`,`Avatar${s}`);let a=new Set;for(let s of o){if(a.has(s)||!i[s])continue;a.add(s);let u=i[s]||{};for(let l of Object.keys(u))n.push(D({entityType:s,entityLabel:Sl[s]||s,name:l,type:u[l]?.type||"",value:u[l]?.value??null}))}return n}var st="qxqy-simulator-save",Il="qxqy-simulator-scripts",oe="server-control-template",Y="client-control-template",zo={[oe]:"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F",[Y]:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"};function at(e){return e===Y?"client":"server"}function Cl(e){let t=[e?.guid,e?.id];for(let i of t){let n=Number(i);if(Number.isSafeInteger(n)&&n>0&&n<=2147483647)return n}return 0}function _i(e){let t=String(e?.controlAsset||""),i=Cl(e);return{id:String(i||e?.id||""),guid:i,path:String(e?.path||""),source:String(e?.source||""),controlId:String(e?.controlId||""),controlAsset:t===Y||t==="client"?Y:t===oe||t==="server"?oe:""}}function Go(e){let t=[],i=(n,r="")=>{if(n&&(n.path||n.source)){let o=_i(n);t.push(r?{...o,controlAsset:r}:o)}};if(Array.isArray(e?.assets?.scripts)){for(let n of e.assets.scripts)n&&(n.path||n.source)&&t.push(_i(n));return t}if(i(e?.assets?.server?.script,oe),i(e?.assets?.client?.script,Y),e&&e.format!==st){i(e?.script);for(let n of e?.scripts||[])i(n)}return t}function Vn(e){return Ee(e===Y?Ze():ze())}var kl="\u672A\u7ED1\u5B9A",Ct="\u672A\u547D\u540D\u5B58\u6863",xl="\u672A\u547D\u540D\u754C\u9762";function El(e){let t=e;for(let i=0;i<8;i++){if(Jt($o(t,"simulator","studio"))&&Jt($o(t,"lua")))return t;let n=bl(t);if(n===t)break;t=n}return e}function Al(e){return e?{name:kt(e),path:e,bound:!0}:{name:kl,path:"",bound:!1}}function _l(e,t=process.cwd()){if(vl(e)&&Jt(e))return e;let i=t||process.cwd(),n=El(i),r=Do(n,e);if(Jt(r))return r;let o=Do(i,e);if(Jt(o))return o;throw new Error("script file not found: "+e)}function Vo(e,t={}){e?.format===st&&on(e.version);let i=[],n=typeof t.workspacePath=="string"&&t.workspacePath?t.workspacePath:"",r=e?.format===st&&e.assets,o=r?null:Ee(e,{warnings:i}),a={server:r&&e.assets.server?Ee(e.assets.server,{warnings:i}):Vn(oe),client:r&&e.assets.client?Ee(e.assets.client,{warnings:i}):Vn(Y)};o&&(a[at(o.meta.assetType)]=o);let s=r&&e.activeAssetType===Y?Y:o?.meta.assetType||oe,u=r&&e.meta?.name?String(e.meta.name):"",l=()=>u||Ct;!e?.meta?.name&&a.server.meta.name==="\u672A\u547D\u540D\u754C\u9762\u63A7\u4EF6\u7EC4"&&(a.server.meta.name=xl);let f=[],h=new Set;function p(){h.clear(),bt(a.server.root,h),bt(a.client.root,h,{skipServerContainer:!0});for(let d of f)xe(d.guid)&&h.add(Number(d.guid))}function m(d=0){p();let y=xe(d)&&!h.has(Number(d))?Number(d):$e(h);return h.add(y),y}function g(d){let y=_i(d),C=m(y.guid);return{...y,guid:C,id:String(C)}}for(let d of Go(e))f.push(g(d));let b=It(e?.serverLogic),I=null,x="",$=1,P=1;function V(d){let y=String(d||"").trim();if(!y)return"";if(!U[y])throw new Error(`unknown canvas preset: ${y} (available: ${Object.keys(U).join(", ")})`);return y}let X=()=>a[at(s)];function Z(d){if(!d)return null;for(let[y,C]of[["server",a.server],["client",a.client]]){let R=le(C.root,d);if(R&&R.kind!=="server-container")return{key:y,node:R}}return null}function j(d){if(!d.controlId)return null;let y=d.controlAsset===Y?"client":d.controlAsset===oe?"server":null;if(y){let C=le(a[y].root,d.controlId);return C&&C.kind!=="server-container"?{key:y,node:C}:null}return Z(d.controlId)}function O(){for(let d of f)d.controlId&&!j(d)&&(d.controlId="",d.controlAsset="")}function v(d){if(!xe(d))return null;for(let[y,C]of[[oe,a.server],[Y,a.client]]){let R="";if(J(C.root,F=>{!R&&(F.scriptMappingIds||[]).includes(Number(d))&&(R=F.id)}),R)return{controlId:R,controlAsset:y}}return null}function E(d,y,C){let R=a[at(d.controlAsset)],F=R&&le(R.root,d.controlId);F&&(F.scriptMappingIds=(F.scriptMappingIds||[]).map(M=>Number(M)===Number(y)?Number(C):M))}O();function S(){return f.map(d=>{let y=j(d),C=y?y.key==="client"?Y:oe:"";return D({id:d.id,guid:d.guid||0,path:d.path||"",source:d.source||"",controlId:d.controlId||"",controlAsset:d.controlAsset||C,controlName:y?.node.name||"",assetType:C,assetLabel:y?zo[C]:"",mounted:!!y})})}function k(){let d=[],y=(C,R)=>{J(C.root,F=>{F.kind!=="server-container"&&d.push(D({id:F.id,name:F.name,kind:F.kind,assetType:R,assetLabel:zo[R]}))})};return y(a.server,oe),y(a.client,Y),d}function N(d){let y=[];return J(d.root,C=>{C.kind!=="server-container"&&y.push(JSON.stringify({kind:C.kind,name:C.name,text:C.text??null,imageId:C.imageId??null,fontSize:C.fontSize??null,fontColor:C.fontColor??null,bgColor:C.bgColor??null,imageColor:C.imageColor??null,fillType:C.fillType??null,fillAmount:C.fillAmount??null,syncAllDevices:C.syncAllDevices!==!1,transformByPlatform:C.transformByPlatform||null}))}),y.join("/")}let w=N(Ze()),T=N(ze());function z(d){let y=N(d);return d.meta?.assetType===Y?y===w:y===T}function G(d,y){return String(d||"").replace(/[\\/:*?"<>|]/g,"-").trim()||y}function ie(d){let y=G(l(),Ct),C=d.meta?.assetType===Y?"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F";return`${y} \xB7 ${C}`}function q(){if(!((a.server.root.children||[]).find(y=>y.kind==="container")||a.server.root.children?.[0]))throw new Error("\u6574\u5408\u5305\u9700\u8981\u670D\u52A1\u7AEF\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668\u4E0B\u81F3\u5C11\u6709\u4E00\u4E2A\u6839\u63A7\u4EF6");return _r(a.server,a.client,{scripts:f,fileName:`${G(l(),Ct)} \xB7 \u6574\u5408\u5305.gia`})}function ce(){let d=y=>({type:y.meta.assetType,name:y.meta.name,sourceFile:y.meta.sourceFile||""});return{format:st,name:l(),activeAssetType:s,assets:{server:d(a.server),client:d(a.client),scripts:S()}}}function Re(){return D({format:st,version:4,meta:{name:l()},activeAssetType:s,serverLogic:b,assets:{server:a.server,client:a.client,scripts:f.map(d=>D({id:d.id,guid:d.guid||0,path:d.path||"",source:d.source||"",controlId:d.controlId||"",controlAsset:d.controlAsset||""}))}})}function ae(){let d=X(),y=Xr(d);return y.workspace=Al(n),y.save=ce(),y.scripts=S(),y.mountTargets=k(),y.serverLogic=b,y.migrationWarnings=[...i],qn(y),y}function ct(d){let y=X();if(d.expectedRevision!==void 0&&Number(d.expectedRevision)!==y.version)throw new Error(`revision conflict: expected ${d.expectedRevision}, current ${y.version}`);return y}function Xe(d,y,C=""){let R=String(y||"");if(R){let F=C===Y?Y:C===oe?oe:"";if(!j({controlId:R,controlAsset:F}))throw new Error("\u6302\u8F7D\u76EE\u6807\u5FC5\u987B\u662F\u5B58\u6863\u5185\u7684\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6216\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F");d.controlAsset=F}else d.controlAsset="";d.controlId=R}function _t(d){let y=ct(d);if(d.op==="addScript"){let C=g({path:String(d.path||""),source:String(d.source||""),controlId:"",controlAsset:""});d.controlId!==void 0&&d.controlId!==""&&Xe(C,d.controlId,d.controlAsset),f.push(C)}else if(d.op==="updateScript"){let C=f.find(R=>R.id===d.id);if(!C)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${d.id}`);d.controlId!==void 0&&Xe(C,d.controlId,d.controlAsset),d.path!==void 0&&(C.path=String(d.path)),d.source!==void 0&&(C.source=String(d.source))}else if(d.op==="removeScript"){let C=f.length;if(f=f.filter(R=>R.id!==d.id),f.length===C)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${d.id}`)}return y.version+=1,ae()}function ut(d){if(!d||typeof d!="object")throw new Error("patch requires op");if(d.op==="setServerLogic"){let y=ct(d);return b=It(d.logic),y.version+=1,ae()}if(d.op==="addScript"||d.op==="updateScript"||d.op==="removeScript")return _t(d);if(d.op==="selectAsset")return s=d.assetType===Y?Y:oe,ae();if(d.op==="renameSave"){let y=String(d.name||"").trim();if(!y)throw new Error("\u5B58\u6863\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");return u=y,ae()}if(d.op==="newAsset"){let y=ct(d);s=d.assetType===Y?Y:oe;let C=Vn(s);return C.version=y.version+1,a[at(s)]=C,O(),ae()}return ln(X(),d),O(),ae()}function Pt(d){return f.filter(y=>{let C=j(y);return!!(C&&C.key==="client"==(d===Y))})}function Tt(d="json",y=""){let C=String(d).toLowerCase();if(C==="save"||C==="archive"){let M=Buffer.from(JSON.stringify(Re(),null,2),"utf8");return D({filename:`${l().replace(/[\\/:*?"<>|]/g,"-")} \xB7 \u8D44\u4EA7\u5305.json`,mimeType:"application/json",encoding:"base64",data:M.toString("base64"),warnings:[]})}if(C==="save-gia"||C==="archive-gia"){let M=[],K=[],Q=(ve,Ne="")=>{let ee=Tt(ve,Ne);M.push(D({filename:ee.filename,mimeType:ee.mimeType,encoding:ee.encoding,data:ee.data,warnings:ee.warnings||[]})),K.push(...ee.warnings||[])},ft=(ve,Ne)=>{let ee=a[at(ve)],Fe=ve===s,dt=f.some(ge=>ge.controlAsset===ve&&ge.controlId);if(!Fe&&z(ee)&&!dt){K.push(Ne);return}Q("gia",ve)};if(ft(oe,"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F\u4ECD\u662F\u9ED8\u8BA4\u6A71\u7A97\uFF0C\u672A\u6539\u52A8\u4E14\u5F53\u524D\u672A\u663E\u793A\uFF0C\u5DF2\u4ECE\u8D44\u4EA7\u5305 GIA \u4E2D\u7701\u7565\u3002"),ft(Y,"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u4ECD\u662F\u9ED8\u8BA4\u300CLua\u5B9E\u4F8B\u5316\u9762\u677F\u300D\uFF0C\u672A\u6539\u52A8\u4E14\u5F53\u524D\u672A\u663E\u793A\uFF0C\u5DF2\u4ECE\u8D44\u4EA7\u5305 GIA \u4E2D\u7701\u7565\u3002"),f.some(ve=>ve.path||ve.source)&&Q("scripts-gia"),!M.length)throw new Error("\u8D44\u4EA7\u5305 GIA \u6CA1\u6709\u53EF\u5BFC\u51FA\u7684\u5DF2\u6539\u52A8\u9879\uFF1B\u8BF7\u5148\u7F16\u8F91\u5F53\u524D\u754C\u9762\uFF0C\u6216\u6539\u7528\u300C\u5F53\u524D\u754C\u9762 GIA\u300D\u3002");return D({format:"qxqy-gia-package",files:M,warnings:[...new Set(K)]})}if(C==="gia-combined"||C==="combined-gia"||C==="combined"){let M=q();return D({filename:`${G(l(),Ct)} \xB7 \u6574\u5408\u5305.gia`,mimeType:"application/octet-stream",encoding:"base64",data:M.buffer.toString("base64"),warnings:[...new Set(M.warnings||[])]})}if(C==="scripts"){let M=D({format:Il,version:1,scripts:f.map(Q=>D({id:Q.id,guid:Q.guid||0,path:Q.path||"",source:Q.source||"",controlId:Q.controlId||"",controlAsset:Q.controlAsset||""}))}),K=Buffer.from(JSON.stringify(M,null,2),"utf8");return D({filename:`${G(l(),Ct)} \xB7 \u811A\u672C.json`,mimeType:"application/json",encoding:"base64",data:K.toString("base64"),warnings:[]})}if(C==="scripts-gia"||C==="scriptsgia"){let M=Mr(f);return D({filename:`${G(l(),Ct)} \xB7 \u811A\u672C.gia`,mimeType:"application/octet-stream",encoding:"base64",data:M.buffer.toString("base64"),warnings:M.warnings})}if(C==="lua"){let M=f.find(Q=>Q.id===y)||f.find(Q=>Q.path===y);if(!M)throw new Error("\u6CA1\u6709\u53EF\u5BFC\u51FA\u7684 Lua \u811A\u672C\uFF0C\u8BF7\u5148\u5728\u201CLua \u811A\u672C\u201D\u9875\u521B\u5EFA");let K=kt(M.path||"")||`qxqy-script-${M.id}`;return D({filename:/\.lua$/i.test(K)?K:`${K}.lua`,mimeType:"text/x-lua",encoding:"base64",data:Buffer.from(M.source||"","utf8").toString("base64"),warnings:[]})}let R=y?a[at(y)]:X(),F=ie(R);if(C==="json"){let M=D({...R,scripts:Pt(R.meta.assetType)}),K=Buffer.from(JSON.stringify(M,null,2),"utf8");return D({filename:`${F}.json`,mimeType:"application/json",encoding:"base64",data:K.toString("base64"),warnings:[]})}if(C==="gia"){let M=Ar(R,R.meta.assetType===Y?{scripts:Pt(Y)}:{});return D({filename:`${F}.gia`,mimeType:"application/octet-stream",encoding:"base64",data:M.buffer.toString("base64"),warnings:M.warnings})}throw new Error(`unsupported export format: ${d}`)}function L(d){for(let y of d){let C=_i(y);if(!C.path&&!C.source)continue;let R=C.controlId?null:v(C.guid),F=g(R?{...C,...R}:C);R&&F.guid!==C.guid&&E(R,C.guid,F.guid),F.controlId&&!j(F)&&(F.controlId="",F.controlAsset=""),f.push(F)}}function Ce(d,y,C=""){let R=String(d||"").toLowerCase();if(typeof y!="string"||!y)throw new Error("import data is required");let F=Buffer.from(y,"base64"),M,K=[],Q={};if(R==="json"){try{M=JSON.parse(F.toString("utf8"))}catch{throw new Error("JSON \u6587\u4EF6\u65E0\u6548")}if(M?.project&&(M=M.project),M?.format===st&&M?.assets){on(M.version);let ee=Ee(M.assets.server||ze(),{warnings:K}),Fe=Ee(M.assets.client||Ze(),{warnings:K}),dt=It(M.serverLogic);return a.server=ee,a.client=Fe,i=[...K],s=M.activeAssetType===Y?Y:oe,u=String(M.meta?.name||kt(C).replace(/\.json$/i,"")||u),b=dt,f=[],h.clear(),L(Go(M)),O(),D({snapshot:ae(),warnings:K,metadata:{format:st}})}}else{if(R==="lua")return f.push(g({path:kt(C||"imported.lua"),source:F.toString("utf8"),controlId:""})),D({snapshot:ae(),warnings:K,metadata:{assetType:"lua-script"}});if(R==="gia"){if(Nr(F)){let ge=Or(F);return L(ge.scripts),D({snapshot:ae(),warnings:ge.warnings,metadata:ge.metadata})}let ee=$r(F);M=ee.project,K=ee.warnings,Q=ee.metadata,ee.clientProject&&(a.client=Ee(ee.clientProject),K.push("\u6574\u5408\u5305\u5DF2\u62C6\u56DE\u300CUI\u63A7\u4EF6-\u670D\u52A1\u7AEF\u300D\u4E0E\u300CUI\u63A7\u4EF6-\u5BA2\u6237\u7AEF\u300D\uFF1B\u5BA2\u6237\u7AEF\u6A21\u677F\u8FB9\u754C\u5DF2\u4FDD\u7559\u3002"));let Fe=new Map,dt=(ge,xa)=>{ge&&J(ge.root,Kn=>{for(let Gi of Kn.scriptMappingIds||[]){let Ln=Fe.get(Number(Gi));if(Ln){K.push(`\u811A\u672C GUID ${Gi} \u540C\u65F6\u6302\u8F7D\u5230\u591A\u4E2A\u63A7\u4EF6\uFF0C\u5DF2\u4FDD\u7559\u201C${Ln.controlAsset===oe?"\u670D\u52A1\u7AEF":"\u5BA2\u6237\u7AEF"}\u201D\u76EE\u6807\u3002`);continue}Fe.set(Number(Gi),{controlId:Kn.id,controlAsset:xa})}})};dt(ee.project,oe),dt(ee.clientProject,Y),L((ee.scripts||[]).map(ge=>Fe.has(Number(ge.guid))?{...ge,...Fe.get(Number(ge.guid))}:ge))}else throw new Error(`unsupported import format: ${d}`)}let ft=Ee(M,{warnings:K});i=[...K];let ve=at(ft.meta.assetType);a[ve]=ft,s=ft.meta.assetType;let Ne=a[ve];return C&&(Ne.meta.name=kt(C).replace(/\.(json|gia)$/i,"")||Ne.meta.name,Ne.meta.sourceFile=kt(C),Ne.meta.sourceFormat=R),L(M?.scripts||[]),M?.script&&(M.script.path||M.script.source)&&L([M.script]),D({snapshot:ae(),warnings:K,metadata:Q})}function Ke(d,y){return ln(X(),{op:"pick",x:d,y}),ae()}function ii(d){let y=typeof d=="string"&&d?d:"";!y||y===n||(n=y)}function Rt(d){let y=d.source||"";if(!y.trim()&&d.path.trim())try{y=yl(_l(d.path,n),"utf8")}catch(C){throw new Error(`\u811A\u672C ${d.path} \u8BFB\u53D6\u5931\u8D25: ${C?.message||C}`)}return y}function Me(d={}){let y=V(d.canvasId);y&&(x=y),d.playerCount!==void 0&&d.playerCount!==null&&d.playerCount!==""&&($=it(d.playerCount),P>$&&(P=1)),d.viewPlayerIndex!==void 0&&d.viewPlayerIndex!==null&&d.viewPlayerIndex!==""&&(P=Te(d.viewPlayerIndex,$)),I&&On(I);let C=f.map(F=>{try{return{id:F.id,guid:F.guid||0,path:F.path||F.id,source:Rt(F),controlId:F.controlId||"",controlAsset:F.controlAsset||""}}catch(M){return{id:F.id,guid:F.guid||0,path:F.path||F.id,source:`error([==[ ${String(M.message).replace(/]=+]/g,"] =]")} ])`,controlId:F.controlId||"",controlAsset:F.controlAsset||""}}}),R=F=>C.filter(M=>{let K={controlId:M.controlId,controlAsset:M.controlAsset},Q=M.controlId?j(K):null;return!!(Q&&Q.key===F)});return I=ko(a.server,{templatesProject:a.client,scripts:C,sceneScripts:R("server"),templateScripts:R("client"),serverConfig:{logic:b},canvasId:x,playerCount:$,viewPlayerIndex:P}),se(d)}function Mt(d,y={}){let C=V(d);if(!C)throw new Error("playSetCanvas requires canvasId");return Me({...y,canvasId:C})}function se(d={}){if(!I)return D({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]});let y=Pn(I,d);return y.running=!0,y.logs=Gn(y.logs),y.serverLogs=Gn(y.server?.logs||[]),y.serverVars=wl(y.server,y.playerCount||1),y}function ca(d,y={}){return I||Me(),Ei(I,d),y.observe===!1?D({running:!0,time:I.runtime.clock.time,frame:I.runtime.clock.frame,paused:!!I.debugPaused,levelTimePaused:!!I.runtime.clock.paused,playerCount:I.playerCount||1,viewPlayerIndex:I.viewPlayerIndex||1}):se(y)}function ua(d=0){Me();let y=Math.max(0,Number(d)||0);for(let C=0;C<y;C++)Ei(I,1/30);return se()}function fa(){return I&&On(I),I=null,x="",$=1,P=1,D({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]})}function da(d,y={}){let C=Nt();return P=An(C,d),y.observe===!1?null:se(y)}function ha(d,y={}){if(!I)throw new Error("play session has not started");return Tn(I,d),y.observe===!1?null:se(y)}function pa(d,y={}){if(!I)throw new Error("play session has not started");return Rn(I,d),y.observe===!1?null:se(y)}function ma(d,y,C,R={}){if(!I)throw new Error("play session has not started");return qt(I,d,y,C),R.observe===!1?null:se(R)}function ga(d={}){return I&&Ai(I).pause(),d.observe===!1?null:se(d)}function ya(d={}){return I&&Ai(I).resume(),d.observe===!1?null:se(d)}function Nt(){if(!I)throw new Error("play session has not started");return I}function ba(d,y){let C=Nt();if(!d&&!y){let R=se();return D({vars:R.serverVars||[]})}return D({entityType:String(d||""),name:String(y||""),value:Mo(C,d,y)})}function va(d,y,C){let R=Nt();return Nn(R,d,y,C),se()}function Sa(d,y=[],C="PlayerSelf"){let R=Nt();return Fn(R,d,y,C),se()}function wa(){let d=se();return D({events:d.history||[],case:So(d.history||[],{playerCount:d.playerCount||1})})}function Ia(d={}){let y=se(),C=Lt({name:d.name||"",dt:d.dt,playerCount:d.playerCount||y.playerCount||1,events:d.events||y.history||[],asserts:d.asserts||[]});return D(C)}function Ca(d,y={}){let C=Lt(d);Me({...y,playerCount:y.playerCount||C.playerCount||1});let R=Nt();R.recording=!1;try{return Oo(Ai(R),d)}finally{R.recording=!0}}function ka(){if(!I)return{running:!1,paused:!1,time:0,frame:0,playerCount:1,viewPlayerIndex:1};let d=I.runtime.clock;return{running:!0,paused:!!I.debugPaused,levelTimePaused:!!d.paused,time:d.time,frame:d.frame,playerCount:I.playerCount||1,viewPlayerIndex:I.viewPlayerIndex||1}}let Xn={get:ae,patch:ut,setWorkspace:ii,exportData:Tt,importData:Ce,pick:Ke,playStart:Me,playSetCanvas:Mt,playSetView:da,playGet:se,playStatus:ka,playStep:ca,playRun:ua,playStop:fa,playKey:ha,playClick:pa,playPointer:ma,playPause:ga,playResume:ya,playServerGet:ba,playServerSet:va,playServerSend:Sa,playHistory:wa,playSaveCase:Ia,playRunCase:Ca,archiveData:Re};return Object.defineProperty(Xn,"_project",{enumerable:!1,get:X}),Xn}import{createRequire as Pl}from"node:module";function Yo(e,t,i){if(e.fillType!=="Horizontal"&&e.fillType!=="Vertical")return null;let n=Number(e.fillAmount??1),r=Number.isFinite(n)?Math.max(0,Math.min(1,n)):1;if(e.fillType==="Horizontal"){let a=t*r;return{x:e.fillHorizontalType==="Right"?t/2-a:-t/2,y:-i/2,width:a,height:i}}let o=i*r;return{x:-t/2,y:e.fillVerticalType==="Top"?-i/2:i/2-o,width:t,height:o}}var Tl=Pl(import.meta.url),Rl=[0,-.5,.5,.5,-.5,.5],Ml=[0,-.5,.12,-.12,.5,0,.12,.12,0,.5,-.12,.12,-.5,0,-.12,-.12],Nl=[0,-.5,.11,-.15,.48,-.15,.18,.07,.29,.41,0,.2,-.29,.41,-.18,.07,-.48,-.15,-.11,-.15],Yn=Buffer.from([137,80,78,71,13,10,26,10]),Fl=new Set(["image","textbox","textwindow","button"]),Pi={cursor:"\u5149\u6807\u68C0\u6D4B\u533A\u57DF",reference:"\u6A21\u677F\u5F15\u7528\u63A7\u4EF6",grid:"\u7F51\u683C\u89C6\u7A97",button:"\u9884\u8BBE\u6309\u94AE",keyhint:"\u6309\u952E\u63D0\u793A",animation:"\u754C\u9762\u52A8\u6548",fullscreen:"\u5168\u5C4F\u52A8\u6548"},Ti=null;function Uo(){if(Ti)return Ti;try{Ti=Tl("@napi-rs/canvas")}catch(e){let t=e?.message||String(e);throw new Error(`Host screenshot renderer requires @napi-rs/canvas (${t})`)}return Ti}function B(e,t=0){let i=Number(e);return Number.isFinite(i)?i:t}function Mi(e,t=4294967295){let i=Number(e??t)>>>0;return{r:i>>>16&255,g:i>>>8&255,b:i&255,a:(i>>>24&255)/255}}function lt(e,t=1){return`rgba(${e.r},${e.g},${e.b},${Math.max(0,Math.min(1,e.a*t))})`}function Ho(e,t,i=1){let n=Math.max(1,Math.round(B(e,1))),r=Math.max(1,Math.round(B(t,1))),o=Math.max(1,Math.min(2,B(i,1)));return{width:n,height:r,pixelWidth:Math.max(1,Math.round(n*o)),pixelHeight:Math.max(1,Math.round(r*o)),pixelRatio:o}}function Xo(e){let t=Buffer.from(e.toBuffer("image/png"));if(t.length<Yn.length||!t.subarray(0,Yn.length).equals(Yn))throw new Error("Host screenshot renderer did not produce a PNG");return t}function Ol(e){return e==="triangle"?Rl:e==="fourstar"?Ml:Nl}function $l(e,t,i,n,r){let o=Ol(t);e.beginPath();for(let a=0;a<o.length;a+=2){let s=o[a]*i,u=o[a+1]*n;a===0?e.moveTo(s,u):e.lineTo(s,u)}e.closePath(),e.fillStyle=lt(r),e.fill()}function Dl(e,t,i){let n=t?.matrix,r=n&&typeof n=="object"?[n.a,n.b,n.c,n.d,n.tx,n.ty].map(Number):null,o=t?.pressed?.98:1;if(r&&r.every(Number.isFinite)){let[a,s,u,l,f,h]=r;e.transform(a*o,-s*o,-u*o,l*o,f,i-h);return}e.translate(B(t.left)+B(t.width)/2,i-B(t.bottom)-B(t.height)/2),e.rotate(-B(t.rotationZ)*Math.PI/180),e.scale(o,o)}function zl(e,t,i,n,r,o){if(typeof e.roundRect=="function"){e.roundRect(t,i,n,r,o);return}let a=Math.max(0,Math.min(o,n/2,r/2));e.moveTo(t+a,i),e.arcTo(t+n,i,t+n,i+r,a),e.arcTo(t+n,i+r,t,i+r,a),e.arcTo(t,i+r,t,i,a),e.arcTo(t,i,t+n,i,a),e.closePath()}function Ko(e,t,i,n){let r=Mi(t.bgColor,16777215);e.fillStyle=lt(r),e.fillRect(-i/2,-n/2,i,n);let o=Math.max(8,B(t.fontSize,12)),a=Mi(t.fontColor,4294967295),s=t.horizontalAlignment==="Right"?1:t.horizontalAlignment==="Middle"?.5:0,u=t.verticalAlignment==="Bottom"?1:t.verticalAlignment==="Middle"?.5:0;if(e.save(),e.beginPath(),e.rect(-i/2,-n/2,i,n),e.clip(),e.font=`${o}px "Microsoft YaHei UI","Microsoft YaHei",sans-serif`,e.fillStyle=lt(a),e.textAlign=s===1?"right":s===.5?"center":"left",e.textBaseline=u===1?"bottom":u===.5?"middle":"top",t.enableOutline){let g=Mi(t.outlineColor,4278190080);e.strokeStyle=lt(g),e.lineWidth=Math.max(2,o*.12),e.lineJoin="round"}let l=s===0?-i/2+2:s===1?i/2-2:0,f=u===0?-n/2:u===1?n/2:0,h=String(t.text||"").split(`
|
|
108
|
-
`),p=o*1.2,m=u===.5?f-(h.length-1)*p/2:u===1?f-(h.length-1)*p:f;for(let g=0;g<h.length;g+=1){let b=m+g*p;t.enableOutline&&e.strokeText(h[g],l,b),e.fillText(h[g],l,b)}e.restore()}function Lo(e,t,i,n){e.beginPath(),zl(e,-i/2,-n/2,i,n,6),e.fillStyle="#3268cf",e.fill(),e.strokeStyle="rgba(112,160,255,0.8)",e.lineWidth=1,e.stroke(),t.pressed&&(e.fillStyle="rgba(0,0,0,0.28)",e.fill())}function Wo(e,t,i,n){let r=Mi(t.imageColor,4294967295);if(t.primitive==="missing"){e.fillStyle="rgba(72,34,40,0.36)",e.fillRect(-i/2,-n/2,i,n),e.strokeStyle="#ff7481",e.lineWidth=1,e.strokeRect(-i/2+.5,-n/2+.5,Math.max(0,i-1),Math.max(0,n-1));return}if(t.primitive==="circle"){e.beginPath(),e.
|
|
108
|
+
`),p=o*1.2,m=u===.5?f-(h.length-1)*p/2:u===1?f-(h.length-1)*p:f;for(let g=0;g<h.length;g+=1){let b=m+g*p;t.enableOutline&&e.strokeText(h[g],l,b),e.fillText(h[g],l,b)}e.restore()}function Lo(e,t,i,n){e.beginPath(),zl(e,-i/2,-n/2,i,n,6),e.fillStyle="#3268cf",e.fill(),e.strokeStyle="rgba(112,160,255,0.8)",e.lineWidth=1,e.stroke(),t.pressed&&(e.fillStyle="rgba(0,0,0,0.28)",e.fill())}function Wo(e,t,i,n){let r=Mi(t.imageColor,4294967295);if(t.primitive==="missing"){e.fillStyle="rgba(72,34,40,0.36)",e.fillRect(-i/2,-n/2,i,n),e.strokeStyle="#ff7481",e.lineWidth=1,e.strokeRect(-i/2+.5,-n/2+.5,Math.max(0,i-1),Math.max(0,n-1));return}if(t.primitive==="circle"){e.beginPath(),e.ellipse(0,0,i/2,n/2,0,0,Math.PI*2),e.fillStyle=lt(r),e.fill();return}if(t.primitive==="ring"){e.beginPath(),e.ellipse(0,0,Math.max(1,i/2-3.5),Math.max(1,n/2-3.5),0,0,Math.PI*2),e.strokeStyle=lt(r),e.lineWidth=7,e.stroke();return}if(t.primitive==="triangle"||t.primitive==="fourstar"||t.primitive==="fivestar"){$l(e,t.primitive,i,n,r);return}e.fillStyle=lt(r),e.fillRect(-i/2,-n/2,i,n)}function Gl(e,t,i){let n=Math.max(0,B(t.sourceWidth,B(t.width))),r=Math.max(0,B(t.sourceHeight,B(t.height)));if(e.save(),Dl(e,t,i),t.kind==="textbox"||t.kind==="textwindow")Ko(e,t,n,r);else if(t.kind==="button")Lo(e,t,n,r);else{let o=Yo(t,n,r);o&&(e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip()),Wo(e,t,n,r)}e.restore()}function jo(e,t,i,{checker:n=!1}={}){if(n){e.fillStyle="#28313e",e.fillRect(0,0,t,i);let o=16;for(let a=0;a<i;a+=o)for(let s=0;s<t;s+=o)(s/o+a/o)%2===0&&(e.fillStyle="rgba(255,255,255,0.04)",e.fillRect(s,a,o,o));e.strokeStyle="#40b8cf",e.lineWidth=1,e.strokeRect(.5,.5,t-1,i-1);return}let r=e.createRadialGradient(t/2,i*.45,8,t/2,i/2,Math.max(t,i)*.72);r.addColorStop(0,"#123a6b"),r.addColorStop(.72,"#061934"),r.addColorStop(1,"#071426"),e.fillStyle=r,e.fillRect(0,0,t,i)}function Vl(e,t){return{a:e.a*t.a+e.c*t.b,b:e.b*t.a+e.d*t.b,c:e.a*t.c+e.c*t.d,d:e.b*t.c+e.d*t.d,tx:e.a*t.tx+e.c*t.ty+e.tx,ty:e.b*t.tx+e.d*t.ty+e.ty}}function Bo(e){let t=e?.matrix;return!t||typeof t!="object"?{a:1,b:0,c:0,d:1,tx:0,ty:0}:{a:B(t.a,1),b:B(t.b),c:B(t.c),d:B(t.d,1),tx:B(t.tx),ty:B(t.ty)}}function Yl(e){let t=Array.isArray(e?.nodes)?e.nodes:[],i=new Map;for(let a of t){if(!a||a.id===void 0||a.id===null)continue;let s=a.parent==null?"":String(a.parent),u=i.get(s);u?u.push(a):i.set(s,[a])}for(let a of i.values())a.sort((s,u)=>B(s.z)-B(u.z));let n=[];function r(a,s){if(!Fl.has(a.kind))return;let u=Math.abs(B(a.sourceWidth)*Math.hypot(s.a,s.b)),l=Math.abs(B(a.sourceHeight)*Math.hypot(s.c,s.d));n.push({...a,left:s.tx-u/2,bottom:s.ty-l/2,width:u,height:l,rotationZ:Math.atan2(s.b,s.a)*180/Math.PI,matrix:{a:s.a,b:s.b,c:s.c,d:s.d,tx:s.tx,ty:s.ty}})}function o(a,s){let u=i.get(a)||[];for(let l=u.length-1;l>=0;l-=1){let f=u[l],h=s?Vl(s,Bo(f)):Bo(f);r(f,h),o(String(f.id),h)}}return o("",null),n}function qo(e,t,i,n={}){return Bl(Yl(e),t,i,n)}function Bl(e,t,i,n={}){let{createCanvas:r}=Uo(),o=Ho(t,i,n.scale),a=r(o.pixelWidth,o.pixelHeight),s=a.getContext("2d");s.scale(o.pixelRatio,o.pixelRatio),jo(s,o.width,o.height);let u=Array.isArray(e)?e:[];for(let l of u)!l||l.id===void 0||l.id===null||Gl(s,l,o.height);return{data:Xo(a),width:o.width,height:o.height,pixelWidth:o.pixelWidth,pixelHeight:o.pixelHeight}}function Ul(e){return{kind:e.kind,left:B(e.renderLeft,e.left),bottom:B(e.renderBottom,e.bottom),width:Math.max(0,B(e.renderWidth,e.width)),height:Math.max(0,B(e.renderHeight,e.height)),rotationZ:B(e.renderRotationZ,e.rotationZ)}}function Ri(e,t,i){let n=String(t||"");if(!n)return;e.font='10px "Microsoft YaHei UI","Microsoft YaHei",sans-serif',e.textAlign="center",e.textBaseline="middle";let r=e.measureText(n),o=Math.min(i-4,Math.max(24,r.width+8)),a=16;e.fillStyle="rgba(17,25,37,0.66)",e.fillRect(-o/2,-a/2,o,a),e.fillStyle="#e7edf5",e.fillText(n,0,0)}function Hl(e,t,i,n){let r=Ul(t);if(r.width<=0||r.height<=0)return;e.save(),e.translate(r.left+r.width/2,i-r.bottom-r.height/2),e.rotate(-r.rotationZ*Math.PI/180);let o=-r.width/2,a=-r.height/2;if(t.kind==="image")Wo(e,t,r.width,r.height);else if(t.kind==="textbox"||t.kind==="textwindow")Ko(e,t,r.width,r.height);else if(t.kind==="button")Lo(e,t,r.width,r.height),Ri(e,t.name||Pi.button,r.width);else if(t.kind==="cursor")e.setLineDash([6,4]),e.strokeStyle="rgba(74,142,181,0.7)",e.fillStyle="rgba(74,142,181,0.1)",e.fillRect(o,a,r.width,r.height),e.strokeRect(o,a,r.width,r.height),Ri(e,t.name||Pi.cursor,r.width);else if(t.kind==="grid"){e.strokeStyle="rgba(106,146,189,0.55)",e.strokeRect(o,a,r.width,r.height),e.beginPath();for(let s=20;s<r.width;s+=20)e.moveTo(o+s,a),e.lineTo(o+s,a+r.height);for(let s=20;s<r.height;s+=20)e.moveTo(o,a+s),e.lineTo(o+r.width,a+s);e.stroke(),Ri(e,t.name||Pi.grid,r.width)}else t.kind!=="container"&&t.kind!=="server-container"?(e.setLineDash(t.kind==="reference"||t.kind==="animation"||t.kind==="fullscreen"?[4,4]:[]),e.strokeStyle="rgba(203,218,237,0.55)",e.strokeRect(o,a,r.width,r.height),Ri(e,t.name||Pi[t.kind]||t.kind,r.width)):(e.strokeStyle="rgba(78,165,230,0.42)",e.strokeRect(o,a,r.width,r.height));t.id===n&&t.kind!=="container"&&t.kind!=="server-container"&&(e.setLineDash([]),e.strokeStyle="#61b9ff",e.lineWidth=2,e.strokeRect(o,a,r.width,r.height)),e.restore()}function Jo(e,t={}){let{createCanvas:i}=Uo(),n=e?.canvas||{},r=Ho(n.width||1600,n.height||900,t.scale),o=i(r.pixelWidth,r.pixelHeight),a=o.getContext("2d");a.scale(r.pixelRatio,r.pixelRatio),jo(a,r.width,r.height,{checker:!0});let s=Array.isArray(e?.boxes)?e.boxes:[],u=e?.selectedId;for(let l of s)!l||l.kind==="server-container"||l.visible===!1||Hl(a,l,r.height,u);return{data:Xo(o),page:e?.asset?.type==="client-control-template"?"UI\u63A7\u4EF6-\u5BA2\u6237\u7AEF":"UI \u7F16\u8F91",width:r.width,height:r.height,pixelWidth:r.pixelWidth,pixelHeight:r.pixelHeight}}import{closeSync as Xl,existsSync as Ni,openSync as Kl,readdirSync as Ll,readSync as Wl,realpathSync as xt,statSync as ea}from"node:fs";import{basename as jl,dirname as Zo,isAbsolute as Bn,join as ql,relative as ta,resolve as Qt}from"node:path";var Jl="qxqy-simulator-save",Zl=new Set(["node_modules",".git","dist",".dsh","coverage"]),Qo=50,Ql=8*1024*1024,ec=8;function ei(e=""){let t=Qt(String(e||process.cwd()));if(!Ni(t))throw new Error(`workspace does not exist: ${t}`);if(!ea(t).isDirectory())throw new Error(`workspace is not a directory: ${t}`);return xt(t)}function Zt(e,t,i=!1){let n=ta(e,t);if(!i&&!n||n.startsWith("..")||Bn(n))throw new Error("path must stay inside the configured workspace");return n}function Et(e,t){let i=String(t||"").trim();if(!i||Bn(i))throw new Error("path must be a non-empty workspace-relative path");let n=xt(Qt(e)),r=Qt(n,i);if(Zt(n,r),!Ni(r))throw new Error(`file does not exist: ${i}`);let o=xt(r);return Zt(n,o),o}function ti(e,t){let i=String(t||"").trim();if(!i||Bn(i))throw new Error("path must be a non-empty workspace-relative path");let n=xt(Qt(e)),r=Qt(n,i);Zt(n,r);let o=Zo(r);for(;!Ni(o);){let a=Zo(o);if(a===o)throw new Error("unable to resolve output directory");o=a}return Zt(n,xt(o),!0),Ni(r)&&Zt(n,xt(r)),r}function tc(e,t=4096){let i=Buffer.alloc(t),n=Kl(e,"r");try{let r=Wl(n,i,0,t,0);return i.subarray(0,r).toString("utf8")}finally{Xl(n)}}function ia(e,t,i,n){if(i.length>=Qo||n>ec)return;let r;try{r=Ll(e,{withFileTypes:!0})}catch{return}for(let o of r){if(i.length>=Qo)return;if(o.name.startsWith(".")||Zl.has(o.name))continue;let a=ql(e,o.name);if(o.isDirectory()){ia(a,t,i,n+1);continue}if(!(!o.isFile()||!/\.json$/i.test(o.name)))try{let s=ea(a);if(s.size<20||s.size>Ql)continue;let u=tc(a);if(!u.includes(Jl))continue;let l=u.match(/"name"\s*:\s*"([^"]+)"/)?.[1]||jl(o.name,".json");i.push({path:ta(t,a).replaceAll("\\","/"),name:l,bytes:s.size,mtime:s.mtimeMs})}catch{}}}function Fi(e){let t=ei(e),i=[];return ia(t,t,i,0),i.sort((n,r)=>r.mtime-n.mtime),{bound:!0,workspace:t,archives:i}}var lc=Math.max(1e3,Number(process.env.QXQY_PLAY_TIMEOUT_MS)||8e3),cc=8e3;function na(){let e=new Error("operation aborted");return e.name="AbortError",e}var At=class{constructor(t=""){this.workspacePath=t?ei(t):"",this.studio=Vo(void 0,this.workspacePath?{workspacePath:this.workspacePath}:void 0),this.worker=null,this.pending=new Map,this.sequence=1,this.lock=Promise.resolve()}async exclusive(t){let i=this.lock,n;this.lock=new Promise(r=>{n=r}),await i;try{return await t()}finally{n()}}get(){return this.studio.get()}patch(t){return this.studio.patch(t)}listArchives(){return Fi(this.workspacePath)}loadArchive(t){let i=this.activeWorkspacePath();if(!i)throw new Error("workspace is not bound");let n=Et(i,t),r=rc(n);return this.studio.importData("json",r.toString("base64"),ac(n))}saveArchive(t="qxqy-simulator.save.json"){let i=String(t),n=this.activeWorkspacePath();if(!n)throw new Error("workspace is not bound");let r=ti(n,i);nc(sc(r),{recursive:!0});let o=Buffer.from(JSON.stringify(this.studio.archiveData(),null,2)+`
|
|
109
109
|
`,"utf8");return oc(r,o),{path:i.replaceAll("\\","/"),bytes:o.length,revision:this.studio.get().version,name:this.studio.get().save?.name||""}}activeWorkspacePath(){let t=this.studio.get().workspace;return t?.bound&&t.path?String(t.path):this.workspacePath}createWorker(){let t=new ic(new URL("./worker.js",import.meta.url),{type:"module"});return t.on("message",i=>{let n=this.pending.get(i?.id);n&&(this.pending.delete(i.id),i.ok?n.resolve(i.value):n.reject(new Error(i.error||"play worker failed")))}),t.on("error",i=>{this.worker===t&&(this.worker=null),this.rejectPending(i)}),t.on("exit",i=>{this.worker===t&&(this.worker=null),i!==0&&this.rejectPending(new Error(`play worker exited with code ${i}`))}),this.worker=t,t}rejectPending(t){for(let i of this.pending.values())i.reject(t);this.pending.clear()}async terminateWorker(t=new Error("play worker terminated")){let i=this.worker;this.worker=null,this.rejectPending(t),i&&await i.terminate().catch(()=>{})}request(t,i,n,r=lc){let o=this.worker||this.createWorker(),a=this.sequence++;return new Promise((s,u)=>{let l=!1,f=(m,g)=>{l||(l=!0,clearTimeout(p),n?.removeEventListener("abort",h),m(g))},h=()=>{this.pending.delete(a),f(u,na()),this.terminateWorker(na())},p=setTimeout(()=>{this.pending.delete(a);let m=new Error(`play worker timed out after ${r}ms`);f(u,m),this.terminateWorker(m)},r);if(this.pending.set(a,{resolve:m=>f(s,m),reject:m=>f(u,m)}),n?.aborted)return h();n?.addEventListener("abort",h,{once:!0}),o.postMessage({id:a,action:t,args:i})})}async play(t,i={},n){if(t==="start")return await this.terminateWorker(),this.request("start",{archive:this.studio.archiveData(),workspacePath:this.activeWorkspacePath(),...i},n);if(t==="device"){let r=String(i.canvasId||"").trim();if(!U[r])throw new Error(`unknown canvas preset: ${r||"(empty)"} (available: ${Object.keys(U).join(", ")})`);return await this.terminateWorker(),this.request("start",{archive:this.studio.archiveData(),workspacePath:this.activeWorkspacePath(),...i,canvasId:r},n)}if(t==="stop"){if(!this.worker)return{running:!1,tree:[],logs:[]};try{return await this.request("stop",i,n)}finally{await this.terminateWorker()}}if(!this.worker)throw new Error("play session has not started");return this.request(t,i,n)}async playScreenshot(t){if(!this.worker)throw new Error("play session has not started");let i=await this.request("get",{view:!0},t,cc),n=qo(i.scene,i.canvasWidth,i.canvasHeight);return{data:n.data,canvasId:String(i.canvasId||""),frame:Number.isFinite(Number(i.frame))?Number(i.frame):0,time:Number.isFinite(Number(i.time))?Number(i.time):0,width:n.width,height:n.height,pixelWidth:n.pixelWidth,pixelHeight:n.pixelHeight}}uiScreenshot(){let t=Jo(this.studio.get());return{data:t.data,page:t.page,width:t.width,height:t.height,pixelWidth:t.pixelWidth,pixelHeight:t.pixelHeight}}async dispose(){await this.terminateWorker()}};var fc=new Set(["server-control-template","client-control-template"]),dc=new Set(["start","device","view","get","step","pointer","key","click","pause","resume","stop","serverGet","serverSet","serverSend","history","saveCase","runCase"]);function ra(e){return String(e||"").trim().replaceAll("\\","/")}function oa(e,t){let i=uc(Et(e,t));return`${i.size}:${i.mtimeMs}`}function hc(e){return{version:e.version,selectedId:e.selectedId,save:e.save,asset:e.asset,canvas:e.canvas,tree:e.tree,workspace:e.workspace,scriptCount:Array.isArray(e.scripts)?e.scripts.length:0}}function aa(e,t,i){let n=i==="stop"||t?.running===!1,r=Array.isArray(t?.logs)?t.logs.slice(-100):e.logs;return{running:!n,paused:n?!1:!!t?.paused,canvasId:String(t?.canvasId||e.canvasId||""),width:Number(t?.canvasWidth||e.width||0),height:Number(t?.canvasHeight||e.height||0),frame:Number(t?.frame||0),time:Number(t?.time||0),logs:r}}var Oi=class{constructor({workspace:t,initialPath:i="",watchIntervalMs:n=700}={}){this.workspace=ei(t),this.controller=new At(this.workspace),this.initialPath=ra(i),this.watchIntervalMs=Math.max(100,Number(n)||700),this.activePath="",this.activeStamp="",this.lastLoadedAt="",this.lastError="",this.listeners=new Set,this.playState={running:!1,paused:!1,canvasId:"",width:0,height:0,frame:0,time:0,logs:[]},this.timer=null,this.refreshing=!1}async initialize(){let t=this.archives().archives,i=this.initialPath||t[0]?.path||"";return i&&await this.open(i,"startup"),this.timer=setInterval(()=>{this.refreshFromDisk()},this.watchIntervalMs),this.state()}archives(){return Fi(this.workspace)}state(){return{workspace:this.workspace,activePath:this.activePath,lastLoadedAt:this.lastLoadedAt,lastError:this.lastError,archives:this.archives().archives,snapshot:hc(this.controller.get()),play:this.playState}}async open(t,i="manual"){let n=ra(t);if(!n)throw new Error("path is required");this.playState={...this.playState,running:!1,paused:!1};let r=await this.controller.exclusive(async()=>(await this.controller.play("stop"),this.controller.loadArchive(n)));return this.activePath=n,this.activeStamp=oa(this.workspace,n),this.lastLoadedAt=new Date().toISOString(),this.lastError="",this.playState=aa(this.playState,{running:!1,logs:[]},"stop"),this.emit({type:"archive",reason:i,path:n,revision:r.version}),this.state()}async refreshFromDisk(){if(!this.activePath||this.refreshing)return!1;this.refreshing=!0;try{return oa(this.workspace,this.activePath)===this.activeStamp?!1:(await this.open(this.activePath,"external-change"),!0)}catch(t){let i=t?.message||String(t);return i!==this.lastError&&this.emit({type:"error",error:i}),this.lastError=i,!1}finally{this.refreshing=!1}}async setView({assetType:t,canvasId:i}={}){if(t&&!fc.has(t))throw new Error(`unknown asset type: ${t}`);if(i&&!U[i])throw new Error(`unknown canvas preset: ${i}`);return await this.controller.exclusive(async()=>{if(t&&this.controller.patch({op:"selectAsset",assetType:t}),i){let n=this.controller.get().version;this.controller.patch({op:"setCanvas",canvasId:i,expectedRevision:n})}}),this.emit({type:"view"}),this.state()}async play(t,i={},n){if(!dc.has(t))throw new Error(`unknown play action: ${t||"(empty)"}`);let r=await this.controller.exclusive(()=>this.controller.play(t,i,n));return this.playState=aa(this.playState,r,t),this.lastError="",this.emit({type:"play",action:t,frame:this.playState.frame}),r}async currentState(t){return this.state()}editorScreenshot(){return this.controller.uiScreenshot()}playScreenshot(t){return this.controller.exclusive(()=>this.controller.playScreenshot(t))}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let i of this.listeners)i(t)}async dispose(){this.timer&&clearInterval(this.timer),this.timer=null,this.listeners.clear(),await this.controller.dispose()}};import{existsSync as pc,readFileSync as mc}from"node:fs";import{createHash as gc}from"node:crypto";var yc=new Set(["get","patch","import","export","archives","load-archive","save","play"]),Un=e=>gc("sha256").update(mc(e)).digest("hex"),$i=class{constructor(t,{initialPath:i="",maxSessions:n=8}={}){this.workspace=t,this.initialPath=i,this.maxSessions=n,this.sessions=new Map}getSession(t){if(typeof t!="string"||!/^[a-zA-Z0-9_-]{1,100}$/.test(t))throw new Error("Invalid editor sessionId");if(!this.sessions.has(t)){if(this.sessions.size>=this.maxSessions)throw new Error("Editor session limit reached; save your work and restart the server");let n={controller:new At(this.workspace),path:"",fileStamp:""};this.initialPath&&this.load(n,this.initialPath),this.sessions.set(t,n)}return this.sessions.get(t)}snapshot(t){return{...t.controller.get(),storage:{path:t.path}}}load(t,i){let n=Et(this.workspace,i),r=t.controller.loadArchive(i);return t.path=String(i).replaceAll("\\","/"),t.fileStamp=Un(n),{...r,snapshot:this.snapshot(t)}}async call(t,i,n){if(!yc.has(t))throw new Error("Unknown editor action");let r=this.getSession(i.sessionId),o=r.controller;return o.exclusive(async()=>{if(t==="get")return this.snapshot(r);if(t==="archives")return o.listArchives();if(t==="patch"){if(!Number.isInteger(i.op?.expectedRevision))throw new Error("expectedRevision is required");return o.patch(i.op),this.snapshot(r)}if(t==="export")return o.studio.exportData(i.format,i.assetType);if(t==="play")return o.play(i.action,i.args||{},n);if(t==="load-archive"||t==="import"){if(await o.play("stop"),t==="load-archive")return this.load(r,i.path);let a=o.studio.importData(i.format,i.data,i.filename);return r.path="",r.fileStamp="",{...a,snapshot:this.snapshot(r)}}if(t==="save"){if(i.expectedRevision!==o.get().version)throw new Error("revision conflict: reload before saving");let a=ti(this.workspace,i.path);if(pc(a)){let u=r.path?ti(this.workspace,r.path):"";if(a!==u||Un(a)!==r.fileStamp)throw new Error("File changed or already exists; load it again or save under a new path")}let s=o.saveArchive(i.path);return r.path=s.path,r.fileStamp=Un(a),s}})}async dispose(){await Promise.all([...this.sessions.values()].map(t=>t.controller.exclusive(()=>t.controller.dispose()))),this.sessions.clear()}};var kc=la(new URL(".",import.meta.url)),xc=Hn(kc,"public"),sa=new Map([["/","index.html"],["/index.html","index.html"],["/app.js","app.js"],["/play-renderer.js","play-renderer.js"],["/styles.css","styles.css"],["/editor","editor.html"],["/editor/","editor.html"],["/editor.js","editor.js"],["/editor.css","editor.css"],["/editor/play","play.html"],["/editor/play.js","play.js"],["/editor/play.css","play.css"],["/editor/play-renderer.js","play-renderer.js"]]),Ec={".html":"text/html; charset=utf-8",".js":"text/javascript; charset=utf-8",".css":"text/css; charset=utf-8"};function Ac(e=process.argv.slice(2)){let t=(i,n="")=>{let r=e.indexOf(i);return r>=0&&e[r+1]?e[r+1]:n};return{workspace:t("--workspace",process.env.QXQY_WORKSPACE||process.cwd()),initialPath:t("--file"),host:t("--host","127.0.0.1"),port:Number(t("--port","4173")),open:e.includes("--open")}}function zi(e){return{"cache-control":"no-store","content-type":e,"content-security-policy":"default-src 'self'; img-src 'self' data:; connect-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; object-src 'none'; frame-ancestors 'none'","x-content-type-options":"nosniff"}}function Se(e,t,i){e.writeHead(t,zi("application/json; charset=utf-8")),e.end(JSON.stringify(i))}function _c(e,t){e.writeHead(200,{...zi("image/png"),"content-length":t.data.length,"x-qxqy-width":String(t.width||0),"x-qxqy-height":String(t.height||0)}),e.end(t.data)}async function Di(e,t=1024*1024){let i=[],n=0;for await(let r of e){if(n+=r.length,n>t)throw new Error("request body is too large");i.push(r)}return i.length?JSON.parse(Buffer.concat(i).toString("utf8")):{}}function Pc(e){let t=process.platform==="win32"?"cmd.exe":process.platform==="darwin"?"open":"xdg-open",i=process.platform==="win32"?["/c","start","",e]:[e];bc(t,i,{detached:!0,stdio:"ignore",windowsHide:!0}).unref()}async function Tc(e={}){let t=e.host||"127.0.0.1",i=e.password??process.env.QXQY_WEB_PASSWORD??"",n=["127.0.0.1","localhost","::1"].includes(t);if(!n&&!i)throw new Error("QXQY_WEB_PASSWORD is required when listening outside loopback");let r=b=>Ic("sha256").update(b).digest(),o=r(i),a=new Oi(e);await a.initialize();let s=new $i(a.workspace,e),u=new Set,l=a.subscribe(b=>{let I=`event: state
|
|
110
110
|
data: ${JSON.stringify(b)}
|
|
111
111
|
|