beyond-simulator-web 0.3.6 → 0.4.0
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/editor.js +12 -11
- package/dist/public/play-renderer.js +72 -72
- package/dist/server.js +16 -16
- package/dist/worker.js +9 -9
- package/package.json +1 -1
package/dist/server.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import{spawn as Vf}from"node:child_process";import{createServer as jf}from"node:http";import{readFileSync as Yf,realpathSync as Os}from"node:fs";import{extname as Bf,resolve as Ds}from"node:path";import{fileURLToPath as $s}from"node:url";import{createHash as Hf,timingSafeEqual as Uf}from"node:crypto";import{statSync as Rf}from"node:fs";var Kn={name:"beyond-simulator-web",version:"0.3.6",description:"Self-hosted editor, preview and play surface for Qianxing simulator saves",type:"module",main:"dist/server.js",bin:{"beyond-simulator-web":"dist/server.js"},files:["dist","README.md"],scripts:{build:"node ../scripts/build.mjs web",pretest:"node ../scripts/build.mjs web",prepack:"node ../scripts/build.mjs web",start:"node dist/server.js",dev:"node ../scripts/build.mjs web && node server.js",test:"node --test test/*.test.mjs"},engines:{node:">=20"},dependencies:{"@napi-rs/canvas":"0.1.100",fengari:"0.1.5",protobufjs:"8.7.2"},devDependencies:{react:"19.1.1","react-dom":"19.1.1","qxqy-editor-ui":"workspace:*","qxqy-studio":"workspace:*"},license:"GPL-3.0-only",repository:{type:"git",url:"git+https://github.com/1475505/miliastra-beyond-simulator.git",directory:"web"}};var qn="https://oss.070077.xyz/images/",vr="sprite-v1",Ii="/qxqy-assets/",sl=[[100001,100006],[100101,100213],[101001,101018],[101020,101028],[101030,101046],[101048,101048],[101050,101054],[101056,101080],[102001,102052],[103001,103148],[104001,104010],[105001,105140],[105142,105219],[105221,105317],[106001,106047],[106049,106096],[107001,107007],[107010,107020],[107031,107092],[107094,107180],[107183,107201],[107203,107205],[107207,107228],[107231,107278],[107280,107402],[108001,108017],[108019,108020],[109001,109031],[109033,109034],[109036,109075],[110001,110053],[111001,111139],[112001,112042]];function Lt(e){return Number.isSafeInteger(e)&&e>100006&&sl.some(([t,i])=>e>=t&&e<=i)}var le=Object.freeze(["KEYBOARD","TOUCHSCREEN","CONTROLLER_CONSOLE","CONTROLLER_MOBILE"]),X=Object.freeze({"pc-16-9":{id:"pc-16-9",device:"pc",platform:"KEYBOARD",width:1600,height:900,ratio:"16:9",luaDevice:"KeyboardAndMouse",label:"PC 1600\xD7900"},"pc-21-9":{id:"pc-21-9",device:"pc",platform:"KEYBOARD",width:2100,height:900,ratio:"21:9",luaDevice:"KeyboardAndMouse",label:"PC 2100\xD7900"},"mobile-16-9":{id:"mobile-16-9",device:"mobile",platform:"TOUCHSCREEN",width:1280,height:720,ratio:"16:9",luaDevice:"Mobile",label:"\u624B\u673A 1280\xD7720"},"mobile-19.5-9":{id:"mobile-19.5-9",device:"mobile",platform:"TOUCHSCREEN",width:1560,height:720,ratio:"19.5:9",luaDevice:"Mobile",label:"\u624B\u673A 1560\xD7720"},"mobile-4-3":{id:"mobile-4-3",device:"mobile",platform:"TOUCHSCREEN",width:1280,height:960,ratio:"4:3",luaDevice:"Mobile",label:"\u624B\u673A 1280\xD7960"}}),Ci="pc-16-9",me=2,vt=Object.freeze({KEYBOARD:"pc-16-9",TOUCHSCREEN:"mobile-16-9",CONTROLLER_CONSOLE:"pc-16-9",CONTROLLER_MOBILE:"mobile-16-9"}),wt=Object.freeze({"server-container":"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668",container:"\u5BB9\u5668\u8282\u70B9",textbox:"\u6587\u672C\u6846",image:"\u56FE\u7247",button:"\u9884\u8BBE\u6309\u94AE",cursor:"\u5149\u6807\u68C0\u6D4B\u533A\u57DF",grid:"\u7F51\u683C\u89C6\u7A97",reference:"\u6A21\u677F\u5F15\u7528\u63A7\u4EF6",textwindow:"\u6587\u672C\u89C6\u7A97",keyhint:"\u6309\u952E\u63D0\u793A",animation:"\u754C\u9762\u52A8\u6548",fullscreen:"\u5168\u5C4F\u52A8\u6548"}),xi=Object.freeze(["server-container","container","textbox","cursor","reference","grid","image","button","textwindow","keyhint","animation","fullscreen"]),Jn=Object.freeze({"server-container":null,container:[150,150],textbox:[100,40],image:[80,80],button:[150,50],cursor:[150,50],grid:[80,80],reference:[80,80],textwindow:[100,40],keyhint:[40,40],animation:[100,100],fullscreen:null}),ll=Object.freeze({100001:"rect",100002:"circle",100003:"triangle",100004:"fourstar",100005:"fivestar",100006:"ring"});function St(e){return ll[e]||(Lt(e)?"sprite":"missing")}var Qn=50888,Xt=Object.freeze({font:4294967295,bg:16777215,outline:858993459,image:4294967295});import{Worker as If}from"node:worker_threads";import{existsSync as Cf,mkdirSync as xf,readFileSync as jn,writeFileSync as kf}from"node:fs";import{basename as Ef,dirname as Af}from"node:path";import{existsSync as mi,readFileSync as au}from"node:fs";import{randomUUID as su}from"node:crypto";import{isAbsolute as Zn,win32 as eo}from"node:path";function ki(e,t=!1){let i=String(e??"").trim().replaceAll("\\","/");if(t&&(!i||i==="."))return"";if(!i||Zn(i)||eo.isAbsolute(i)||i.split("/").some(r=>!r||r==="."||r===".."||/[<>:"|?*\x00-\x1f]/.test(r)||/[. ]$/.test(r)||/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(r)))throw new Error("\u811A\u672C\u76EE\u5F55/\u8DEF\u5F84\u5FC5\u987B\u662F\u6709\u6548\u7684\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u4E0D\u80FD\u5305\u542B .. \u6216 Windows \u7279\u6B8A\u6587\u4EF6\u540D");return i}function Wt(e){if(e==null)return null;if(e.version!==1)throw new Error("unsupported scriptSync version");let t=String(e.clientImportRoot||"").trim();if(!Zn(t)&&!eo.isAbsolute(t))throw new Error("\u5B9E\u673A\u5BFC\u5165\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");return{version:1,workspaceDir:ki(e.workspaceDir,!0),clientImportRoot:t,clientSubdir:ki(e.clientSubdir,!0)}}import{basename as Ot,dirname as lu,isAbsolute as cu,join as Za,resolve as es}from"node:path";function It(e,t="$",i=new Set){if(e===void 0)throw new Error(`undefined at ${t}`);if(typeof e=="number"&&!Number.isFinite(e))throw new Error(`non-finite number at ${t}`);if(typeof e=="bigint"||typeof e=="function"||typeof e=="symbol")throw new Error(`non-JSON value at ${t}`);if(!(e===null||typeof e!="object")){if(i.has(e))throw new Error(`circular value at ${t}`);if(i.add(e),Array.isArray(e))e.forEach((r,n)=>It(r,`${t}[${n}]`,i));else for(let[r,n]of Object.entries(e))It(n,`${t}.${r}`,i);i.delete(e)}}function $(e){return It(e),JSON.parse(JSON.stringify(e))}function to(e,t="$"){It(e,t)}function io(e){return X[e]||X[Ci]}function Kt(e,t=0,i=0){return!e||typeof e!="object"?{x:t,y:i}:{x:Number(e.x??t),y:Number(e.y??i)}}function cl(e){return!e||typeof e!="object"?{x:1,y:1,z:1}:{x:Number(e.x??1),y:Number(e.y??1),z:Number(e.z??1)}}function ul(e){return!e||typeof e!="object"?{x:0,y:0,z:0}:{x:Number(e.x??0),y:Number(e.y??0),z:Number(e.z??0)}}function Ei({layout:e="center",size:t=[100,40],offset:i=[0,0]}={}){return e==="stretch"?{scale:{x:1,y:1,z:1},rotation:{x:0,y:0,z:0},anchorMin:{x:0,y:0},anchorMax:{x:1,y:1},offset:{x:0,y:0},size:{x:0,y:0},pivot:{x:.5,y:.5}}:{scale:{x:1,y:1,z:1},rotation:{x:0,y:0,z:0},anchorMin:{x:.5,y:.5},anchorMax:{x:.5,y:.5},offset:{x:Number(i[0]??0),y:Number(i[1]??0)},size:{x:Number(t[0]??0),y:Number(t[1]??0)},pivot:{x:.5,y:.5}}}function Ne(e){let t=e||Ei();return{scale:cl(t.scale),rotation:ul(t.rotation),anchorMin:Kt(t.anchorMin??t.anchor_min,.5,.5),anchorMax:Kt(t.anchorMax??t.anchor_max,.5,.5),offset:Kt(t.offset,0,0),size:Kt(t.size,0,0),pivot:Kt(t.pivot,.5,.5)}}function ge(e,t=0){let i=Number(e);return Number.isFinite(i)?i:t}function De(e,t){let i=e.width,r=e.height,n=e.left,o=e.bottom,a=t.anchorMin||{x:t.anchorMinX,y:t.anchorMinY},s=t.anchorMax||{x:t.anchorMaxX,y:t.anchorMaxY},c=t.offset||{x:t.anchoredPositionX,y:t.anchoredPositionY},l=t.size||{x:t.sizeDeltaX,y:t.sizeDeltaY},u=t.pivot||{x:t.pivotX,y:t.pivotY},h=ge(a?.x,.5)*i,d=ge(a?.y,.5)*r,g=ge(s?.x,.5)*i,y=ge(s?.y,.5)*r,m=ge(l?.x),S=ge(l?.y),I=ge(u?.x,.5),E=ge(u?.y,.5),M=g-h+m,F=y-d+S,H=n+h+ge(c?.x)-m*I,te=o+d+ge(c?.y)-S*E;return{left:H,bottom:te,width:M,height:F,right:H+M,top:te+F,centerX:H+M/2,centerY:te+F/2}}function Ct(){return{a:1,b:0,c:0,d:1,tx:0,ty:0}}function fl(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 $e(e,t,i){return{x:e.a*t+e.c*i+e.tx,y:e.b*t+e.d*i+e.ty}}function qt(e){let t=e.a*e.d-e.b*e.c;return!Number.isFinite(t)||Math.abs(t)<1e-8?null:{a:e.d/t,b:-e.b/t,c:-e.c/t,d:e.a/t,tx:(e.c*e.ty-e.d*e.tx)/t,ty:(e.b*e.tx-e.a*e.ty)/t}}function wr(e,t){let i=t.rotation||{z:t.localRotationZ},r=t.scale||{x:t.localScaleX,y:t.localScaleY},n=t.pivot||{x:t.pivotX,y:t.pivotY},o=ge(i?.z)*Math.PI/180,a=Math.cos(o),s=Math.sin(o),c=ge(r?.x,1),l=ge(r?.y,1),u=e.left+e.width*ge(n?.x,.5),h=e.bottom+e.height*ge(n?.y,.5),d=a*c,g=s*c,y=-s*l,m=a*l;return{a:d,b:g,c:y,d:m,tx:u-d*u-y*h,ty:h-g*u-m*h}}function Jt(e,t,i){return fl(e||Ct(),wr(t,i))}function ro(e,t){let i=$e(t,e.centerX,e.centerY),r=Math.abs(e.width*Math.hypot(t.a,t.b)),n=Math.abs(e.height*Math.hypot(t.c,t.d));return{left:i.x-r/2,bottom:i.y-n/2,width:r,height:n,centerX:i.x,centerY:i.y,rotationZ:Math.atan2(t.b,t.a)*180/Math.PI}}function ye(e){let t=typeof e=="string"?io(e):e;return{left:0,bottom:0,width:t.width,height:t.height,right:t.width,top:t.height,centerX:t.width/2,centerY:t.height/2}}function Sr(e){return{posX:e.centerX,posY:e.centerY,width:e.width,height:e.height}}function tt(e,t,i){let r=Ne(t),n=e.width,o=e.height,a=r.anchorMin.x*n,s=r.anchorMin.y*o,c=r.anchorMax.x*n,l=r.anchorMax.y*o,u=Number(i.width),h=Number(i.height),d=Number(i.posX),g=Number(i.posY),y=d-u/2,m=g-h/2;return r.size={x:u-(c-a),y:h-(l-s)},r.offset={x:y-e.left-a+r.size.x*r.pivot.x,y:m-e.bottom-s+r.size.y*r.pivot.y},r}function no(e,t){let i=Ne(e),n={"bottom-left":[[0,0],[0,0],[0,0]],bottom:[[.5,0],[.5,0],[.5,0]],"bottom-right":[[1,0],[1,0],[1,0]],left:[[0,.5],[0,.5],[0,.5]],center:[[.5,.5],[.5,.5],[.5,.5]],right:[[1,.5],[1,.5],[1,.5]],"top-left":[[0,1],[0,1],[0,1]],top:[[.5,1],[.5,1],[.5,1]],"top-right":[[1,1],[1,1],[1,1]],stretch:[[0,0],[1,1],[.5,.5]],"stretch-horizontal":[[0,.5],[1,.5],[.5,.5]],"stretch-vertical":[[.5,0],[.5,1],[.5,.5]]}[t];return n&&(i.anchorMin={x:n[0][0],y:n[0][1]},i.anchorMax={x:n[1][0],y:n[1][1]},i.pivot={x:n[2][0],y:n[2][1]}),i}function oo(e){let t=Ne(e),i=(r,n)=>Math.abs(r-n)<1e-4;if(i(t.anchorMin.x,0)&&i(t.anchorMin.y,0)&&i(t.anchorMax.x,1)&&i(t.anchorMax.y,1))return"stretch";if(i(t.anchorMin.x,t.anchorMax.x)&&i(t.anchorMin.y,t.anchorMax.y)){let r=t.anchorMin.x,n=t.anchorMin.y,o=[[0,0,"bottom-left"],[.5,0,"bottom"],[1,0,"bottom-right"],[0,.5,"left"],[.5,.5,"center"],[1,.5,"right"],[0,1,"top-left"],[.5,1,"top"],[1,1,"top-right"]];for(let a of o)if(i(r,a[0])&&i(n,a[1]))return a[2]}return"custom"}function it(e){return io(e).platform}function ao(e){let t={};for(let i of le)t[i]=e(i);return t}var dl={scale:["x","y","z"],rotation:["x","y","z"],anchorMin:["x","y"],anchorMax:["x","y"],offset:["x","y"],size:["x","y"],pivot:["x","y"]};function so(e,t){for(let[i,r]of Object.entries(dl))for(let n of r)if(!Number.isFinite(e?.[i]?.[n]))throw new Error(`${t}.${i}.${n} must be a finite number`)}function He(e,t="transformByPlatform"){if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`${t}: \u9700\u8981\u5B8C\u6574\u7684\u56DB\u5E73\u53F0\u5E03\u5C40`);for(let i of Object.keys(e))if(!le.includes(i))throw new Error(`${t}: unknown platform ${i}`);for(let i of le)so(e[i],`${t}.${i}`)}function rt(e){if(Object.hasOwn(e,"transformByCanvas"))throw new Error(`${e.name||e.id||"\u63A7\u4EF6"}: \u4E0D\u518D\u652F\u6301 transformByCanvas\uFF1B\u8BF7\u4F7F\u7528\u56DB\u5E73\u53F0 transformByPlatform \u5E03\u5C40`);He(e.transformByPlatform,`${e.name||e.id||"\u63A7\u4EF6"}.transformByPlatform`)}function nt(e,t){if(!le.includes(t))throw new Error(`unknown platform ${t}`);return so(e?.[t],`transformByPlatform.${t}`),Ne(e[t])}var hl=Object.freeze([{key:"genericField501",label:"\u901A\u7528\u69FD field501",type:"number",defaultValue:0,wire:"GenericSlot.field501"},{key:"footerField505",label:"\u5C3E\u90E8\u69FD field505",type:"number",defaultValue:0,wire:"FooterSlot.field505"}]),pl=Object.freeze({container:[],textbox:[{key:"textField501",label:"\u6587\u672C\u914D\u7F6E field501",type:"number",defaultValue:20,wire:"TextConfig.field501"},{key:"textField503",label:"\u6587\u672C\u914D\u7F6E field503",type:"number",defaultValue:12,wire:"TextConfig.field503"},{key:"textAlign",label:"\u6C34\u5E73\u5BF9\u9F50\u679A\u4E3E\u539F\u59CB\u503C",type:"enum",defaultValue:0,wire:"TextConfig.align",options:[{value:0,label:"0 \xB7 \u5DE6\u5BF9\u9F50"},{value:1,label:"1 \xB7 \u5C45\u4E2D"},{value:2,label:"2 \xB7 \u53F3\u5BF9\u9F50"}]}],textwindow:[{key:"textField501",label:"\u6587\u672C\u914D\u7F6E field501",type:"number",defaultValue:20,wire:"TextConfig.field501"},{key:"textField503",label:"\u6587\u672C\u914D\u7F6E field503",type:"number",defaultValue:12,wire:"TextConfig.field503"},{key:"textAlign",label:"\u6C34\u5E73\u5BF9\u9F50\u679A\u4E3E\u539F\u59CB\u503C",type:"enum",defaultValue:0,wire:"TextConfig.align",options:[{value:0,label:"0 \xB7 \u5DE6\u5BF9\u9F50"},{value:1,label:"1 \xB7 \u5C45\u4E2D"},{value:2,label:"2 \xB7 \u53F3\u5BF9\u9F50"}]},{key:"textField511",label:"\u6587\u672C\u89C6\u7A97 field511",type:"number",defaultValue:1,wire:"TextConfig.field511"},{key:"textViewField502",label:"\u89C6\u7A97\u6807\u8BB0 field502",type:"number",defaultValue:1,wire:"TextConfig.viewFlags.field502"},{key:"textViewField503",label:"\u89C6\u7A97\u6807\u8BB0 field503",type:"number",defaultValue:1,wire:"TextConfig.viewFlags.field503"}],cursor:[{key:"cursorField501",label:"\u5149\u6807\u68C0\u6D4B field501",type:"number",defaultValue:1,wire:"CursorConfig.field501"}],reference:[{key:"templateRefSlot",label:"\u6A21\u677F\u5F15\u7528\u69FD\u539F\u59CB\u503C",type:"string",defaultValue:"",wire:"Details.templateRefSlot"}],grid:[{key:"gridField501",label:"\u7F51\u683C\u6807\u8BB0 field501",type:"number",defaultValue:1,wire:"GridViewConfig.field501"},{key:"gridField507",label:"\u7F51\u683C\u6807\u8BB0 field507",type:"number",defaultValue:1,wire:"GridViewConfig.field507"},{key:"gridField508",label:"\u7F51\u683C\u6807\u8BB0 field508",type:"number",defaultValue:1,wire:"GridViewConfig.field508"},{key:"gridField509",label:"\u7F51\u683C\u6807\u8BB0 field509",type:"number",defaultValue:1,wire:"GridViewConfig.field509"},{key:"gridField511",label:"\u7F51\u683C\u6807\u8BB0 field511",type:"number",defaultValue:5,wire:"GridViewConfig.field511"},{key:"gridField512",label:"\u7F51\u683C\u6807\u8BB0 field512",type:"number",defaultValue:1,wire:"GridViewConfig.field512"}],keyhint:[{key:"keyHintField501",label:"\u6309\u952E\u63D0\u793A field501",type:"number",defaultValue:1,wire:"KeyHintConfig.field501"},{key:"keyHintField502",label:"\u952E\u9F20\u952E\u4F4D\u539F\u59CB\u503C",type:"number",defaultValue:1,wire:"KeyHintConfig.field502"}],image:[{key:"imageField502",label:"\u56FE\u7247\u6807\u8BB0 field502",type:"number",defaultValue:1,wire:"ImageConfig.field502"},{key:"imageField504",label:"\u56FE\u7247\u6807\u8BB0 field504",type:"number",defaultValue:1,wire:"ImageConfig.field504"},{key:"imageField505",label:"\u56FE\u7247\u6807\u8BB0 field505",type:"number",defaultValue:1,wire:"ImageConfig.field505"},{key:"imageField507",label:"\u56FE\u7247\u6807\u8BB0 field507",type:"number",defaultValue:2,wire:"ImageConfig.field507"},{key:"imageFillType",label:"\u586B\u5145\u5F62\u72B6\u679A\u4E3E\u539F\u59CB\u503C",type:"enum",defaultValue:1,wire:"ImageConfig.fillType",options:[{value:1,label:"1 \xB7 \u6A2A\u5411"},{value:2,label:"2 \xB7 \u7EB5\u5411"},{value:3,label:"3 \xB7 90\u5EA6\u73AF\u7ED5"},{value:4,label:"4 \xB7 180\u5EA6\u73AF\u7ED5"},{value:5,label:"5 \xB7 360\u5EA6\u73AF\u7ED5"}]}],animation:[{key:"effectSlot",label:"\u754C\u9762\u52A8\u6548\u69FD\u539F\u59CB\u503C",type:"string",defaultValue:"",wire:"Details.effectSlot"}],fullscreen:[{key:"fullscreenEffectSlot",label:"\u5168\u5C4F\u52A8\u6548\u69FD\u539F\u59CB\u503C",type:"string",defaultValue:"",wire:"Details.fullscreenEffectSlot"}]});function lo(e){return[...hl,...pl[e]||[]]}function co(e,t){return lo(e).find(i=>i.key===t)||null}function Ir(e,t){if(!e)throw new Error("unknown raw GIA field");if(e.type==="string")return String(t??"");let i=Number(t);if(!Number.isFinite(i))throw new Error(`${e.wire} must be a finite number`);return Math.trunc(i)}function uo(e,t={}){let i={};for(let r of lo(e)){let n=Object.hasOwn(t||{},r.key)?t[r.key]:r.defaultValue;i[r.key]=Ir(r,n)}return i}function ke(e){let t=Number(e);return Number.isSafeInteger(t)&&t>0&&t<=2147483647}function Cr(e,t){if(e){t(e);for(let i of e.children||[])Cr(i,t)}}function xt(e,t=new Set,{skipServerContainer:i=!1}={}){return Cr(e,r=>{i&&r.kind==="server-container"||ke(r.guid)&&t.add(Number(r.guid))}),t}function Ue(e,t=1073741850){let i=Number.isSafeInteger(t)&&t>0?t:1073741850;i<1073741850&&(i=1073741850);for(let r of e)ke(r)&&r>=i&&(i=Number(r)+1);for(;e.has(i);)i+=1;if(i>2147483647)throw new Error("GUID space exhausted");return i}function fo(e,t=new Set,{skipServerContainer:i=!1}={}){let r=[];Cr(e,n=>{if(i&&n.kind==="server-container")return;let o=Number(n.guid);if(ke(o)&&!t.has(o)){t.add(o),n.guid=o;return}r.push(n)});for(let n of r){let o=Ue(t);n.guid=o,t.add(o)}return t}var xr=1;function kr(e="n"){let t=`${e}${xr}`;return xr+=1,t}function Ai(e=1){xr=e}function Er(e,{isRootContainer:t=!1}={}){if(e==="server-container"||e==="fullscreen"||e==="container"&&t)return Ei({layout:"stretch"});let i=Jn[e]||[80,80];return Ei({layout:"center",size:i})}function ml(e,t){return ao(()=>Er(e,t))}function gl(e){He(e);let t={};for(let i of le)t[i]=nt(e,i);return t}function W(e,t={}){if(!wt[e])throw new Error(`unknown kind: ${e}`);Object.hasOwn(t,"transformByCanvas")&&rt(t);let i=t.isRootContainer===!0,r=t.id||kr(e==="server-container"?"sc":"n"),n=Object.hasOwn(t,"transformByPlatform")?gl(t.transformByPlatform):ml(e,{isRootContainer:i}),o={id:r,kind:e,name:t.name||wt[e],guid:t.guid??0,giaRelatedGuids:Array.isArray(t.giaRelatedGuids)?t.giaRelatedGuids.filter(a=>Number.isSafeInteger(Number(a))&&Number(a)>0).map(Number):[],...Number.isSafeInteger(Number(t.giaInfoIndex))&&Number(t.giaInfoIndex)>0?{giaInfoIndex:Number(t.giaInfoIndex)}:{},active:t.active!==!1,visible:t.visible!==!1,canControllerFocus:t.canControllerFocus??t.giaRaw?.footerField505===1,syncAllDevices:t.syncAllDevices!==!1,giaRaw:uo(e,t.giaRaw),transformByPlatform:n,children:[],scriptMappingIds:Array.isArray(t.scriptMappingIds)?t.scriptMappingIds.filter(a=>Number.isSafeInteger(Number(a))&&Number(a)>0).map(Number):[]};if(e==="container"&&(o.isolateNavigation=t.isolateNavigation===!0,o.disableKeyEventPassthrough=t.disableKeyEventPassthrough===!0,o.disableCursorEventPassthrough=t.disableCursorEventPassthrough===!0,o.showCursor=t.showCursor===!0),(e==="textbox"||e==="textwindow")&&(o.fontSize=t.fontSize??20,o.adaptiveFontSize=t.adaptiveFontSize===!0,o.minimumFontSize=t.minimumFontSize??20,o.fontColor=t.fontColor??Xt.font,o.bgColor=t.bgColor??Xt.bg,o.enableOutline=t.enableOutline!==!1,o.outlineColor=t.outlineColor??Xt.outline,o.horizontalAlignment=t.horizontalAlignment||"Left",o.verticalAlignment=t.verticalAlignment||"Top",Number.isInteger(t.giaRaw?.textVerticalAlign)&&![0,1,2].includes(t.giaRaw.textVerticalAlign)&&(o.giaRaw.textVerticalAlign=t.giaRaw.textVerticalAlign),o.text=t.text??"",Object.hasOwn(t.giaRaw||{},"textAlign")||(o.giaRaw.textAlign={Left:0,Middle:1,Right:2}[o.horizontalAlignment]??o.giaRaw.textAlign),e==="textwindow"&&(o.interactable=t.interactable!==!1,o.showScrollBar=t.showScrollBar!==!1)),e==="image"&&(o.imageSource=t.imageSource||"StaticReference",o.imageId=t.imageId??100001,o.imageColor=t.imageColor??Xt.image,o.enableMask=t.enableMask===!0,o.enableSoftEdge=t.enableSoftEdge===!0,o.softEdgeMode=t.softEdgeMode||"Percentage",o.softEdgeWidthX=t.softEdgeWidthX??8,o.softEdgeWidthY=t.softEdgeWidthY??8,o.horizontalSoftRange=t.horizontalSoftRange??85,o.verticalSoftRange=t.verticalSoftRange??85,o.enableFill=t.enableFill===!0,o.fillType=t.fillType||"Horizontal",o.fillHorizontalType=t.fillHorizontalType||"Left",o.fillVerticalType=t.fillVerticalType||"Bottom",o.fillRadial90Type=t.fillRadial90Type||"BottomLeft",o.fillRadialType=t.fillRadialType||"Bottom",o.fillAmount=t.fillAmount??1,o.reverseMaskArea=t.reverseMaskArea===!0||t.reverseMask===!0,Object.hasOwn(t.giaRaw||{},"imageFillType")||(o.giaRaw.imageFillType={Horizontal:1,Vertical:2,Radial90:3,Radial180:4,Radial360:5}[o.fillType]??o.giaRaw.imageFillType)),e==="button"&&(o.raycastTarget=t.raycastTarget!==!1,o.interactable=t.interactable!==!1,o.clickAudioId=t.clickAudioId??Qn,o.unavailableChildId=t.unavailableChildId??null,o.hoverChildId=t.hoverChildId??null,o.pressedChildId=t.pressedChildId??null,o.selectedChildId=t.selectedChildId??null),e==="cursor"&&(o.raycastTarget=t.raycastTarget??t.giaRaw?.cursorField501!==0),e==="reference"&&(o.referencedPrefabId=t.referencedPrefabId??t.giaRaw?.templateRefSlot??null,Object.hasOwn(t.giaRaw||{},"templateRefSlot")||(o.giaRaw.templateRefSlot=String(o.referencedPrefabId??""))),e==="grid"&&(o.itemPrefabId=t.itemPrefabId??null,o.raycastTarget=t.raycastTarget!==!1,o.interactable=t.interactable!==!1,o.showScrollBar=t.showScrollBar!==!1,o.scrollDirection=t.scrollDirection||"Vertical",o.layoutConstraint=t.layoutConstraint||"AutoWrap",o.layoutConstraintFixedCount=t.layoutConstraintFixedCount??null,o.cellSizeX=t.cellSizeX??50,o.cellSizeY=t.cellSizeY??50,o.spacingX=t.spacingX??8,o.spacingY=t.spacingY??8,o.padding1X=t.padding1X??20,o.padding1Y=t.padding1Y??20,o.padding2X=t.padding2X??20,o.padding2Y=t.padding2Y??20,o.previewCount=t.previewCount??t.giaRaw?.gridField511??5,Object.hasOwn(t.giaRaw||{},"gridField511")||(o.giaRaw.gridField511=Math.trunc(o.previewCount))),e==="keyhint"&&(o.keyboardKeyCode=t.keyboardKeyCode??t.giaRaw?.keyHintField502??null,o.controllerKeyCode=t.controllerKeyCode??t.giaRaw?.keyHintField501??null,Object.hasOwn(t.giaRaw||{},"keyHintField502")||(o.giaRaw.keyHintField502=Math.trunc(o.keyboardKeyCode??1)),Object.hasOwn(t.giaRaw||{},"keyHintField501")||(o.giaRaw.keyHintField501=Math.trunc(o.controllerKeyCode??1))),e==="animation"||e==="fullscreen"){let a=e==="animation"?t.giaRaw?.effectSlot:t.giaRaw?.fullscreenEffectSlot;o.animationId=t.animationId??a??null,o.playSoundEffect=t.playSoundEffect??null,e==="animation"&&(o.layer=t.layer??null);let s=e==="animation"?"effectSlot":"fullscreenEffectSlot";Object.hasOwn(t.giaRaw||{},s)||(o.giaRaw[s]=String(o.animationId??""))}if(t.children)for(let a of t.children)o.children.push(a);return o}function ot(){Ai(1);let e=W("server-container",{id:"sc1",name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668"}),t=W("container",{id:"n1",name:"\u5BB9\u5668\u8282\u70B9",isRootContainer:!0}),i=W("textbox",{id:"n2",name:"\u6587\u672C\u6846",text:"\u6587\u672C"}),r=W("cursor",{id:"n3",name:"\u5149\u6807\u68C0\u6D4B\u533A\u57DF"}),n=W("reference",{id:"n4",name:"\u6A21\u677F\u5F15\u7528\u63A7\u4EF6"}),o=W("grid",{id:"n5",name:"\u7F51\u683C\u89C6\u7A97"}),a=W("button",{id:"n6",name:"\u9884\u8BBE\u6309\u94AE"}),s=W("textwindow",{id:"n7",name:"\u6587\u672C\u89C6\u7A97"}),c=W("keyhint",{id:"n8",name:"\u6309\u952E\u63D0\u793A"}),l=W("image",{id:"n9",name:"\u56FE\u7247",imageId:100005}),u=W("animation",{id:"n10",name:"\u754C\u9762\u52A8\u6548"}),h=W("fullscreen",{id:"n11",name:"\u5168\u5C4F\u52A8\u6548"}),d=(g,y,m)=>{for(let S of Object.values(g.transformByPlatform))S.offset={x:y,y:m}};return d(i,-300,250),d(r,-300,140),d(n,-300,30),d(o,-300,-100),d(a,0,0),d(s,300,250),d(c,300,140),d(l,300,30),d(u,300,-100),t.children.push(i,r,n,o,a,s,c,l,u,h),e.children.push(t),Ai(12),fo(e),{version:1,layoutSchemaVersion:me,meta:{name:"\u672A\u547D\u540D\u754C\u9762\u63A7\u4EF6\u7EC4",assetType:"server-control-template",sourceFormat:"authoring",sourceFile:""},canvasId:"pc-16-9",selectedId:"n2",root:e}}function kt(){Ai(1);let e=W("server-container",{id:"sc1",name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"}),t=W("container",{id:"n1",guid:1073742100,name:"Lua\u5B9E\u4F8B\u5316\u9762\u677F"}),i=W("textbox",{id:"n2",guid:1073742101,name:"\u6A21\u677F\u6807\u9898",text:"\u5BA2\u6237\u7AEF\u6A21\u677F\u5DF2\u5B9E\u4F8B\u5316",fontSize:28,horizontalAlignment:"Middle"}),r=W("image",{id:"n3",guid:1073742102,name:"\u6A21\u677F\u56FE\u6807",imageId:100005}),n=W("button",{id:"n4",guid:1073742103,name:"\u786E\u8BA4\u6309\u94AE"}),o=W("textbox",{id:"n5",guid:1073742104,name:"\u6309\u94AE\u6587\u5B57",text:"\u786E\u8BA4",horizontalAlignment:"Middle",verticalAlignment:"Top"}),a=(c,l,u)=>{for(let h of Object.values(c.transformByPlatform))h.offset={x:l,y:u}};return((c,l,u)=>{for(let h of Object.values(c.transformByPlatform))h.size={x:l,y:u}})(t,520,320),a(i,0,110),a(r,0,0),a(n,0,-110),n.children.push(o),t.children.push(i,r,n),e.children.push(t),Ai(6),{version:1,layoutSchemaVersion:me,meta:{name:"Lua\u5B9E\u4F8B\u5316\u9762\u677F",assetType:"client-control-template",sourceFormat:"authoring",sourceFile:"",gameVersion:"7.0.50",giaOwnerUid:114514,giaFileId:1073741829,giaFileName:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868.gia"},canvasId:"pc-16-9",selectedId:"n1",root:e}}function J(e,t,i=null){t(e,i);for(let r of e.children||[])J(r,t,e)}function ue(e,t){let i=null;return J(e,r=>{r.id===t&&(i=r)}),i}function Ar(e,t="n"){let i=kr(t);for(;ue(e,i);)i=kr(t);return i}function Le(e,t){let i=null;return J(e,(r,n)=>{r.id===t&&(i=n)}),i}function _r(e){let t=e.root||e;return t.kind==="container"?t:(t.children||[]).find(i=>i.kind==="container")||(t.children||[])[0]||t}function Qt(e){if(e.meta?.assetType!=="client-control-template")return _r(e);let t=ue(e.root,e.selectedId);if(!t||t.kind==="server-container")return e.root.children?.[0]||e.root;let i=Le(e.root,t.id);for(;i&&i.kind!=="server-container";)t=i,i=Le(e.root,t.id);return t}function Pr(e){rt(e);let t={id:e.id,name:e.name,guid:e.guid,giaRelatedGuids:e.giaRelatedGuids,giaInfoIndex:e.giaInfoIndex,scriptMappingIds:e.scriptMappingIds,giaRaw:e.giaRaw,active:e.active,visible:e.visible,canControllerFocus:e.canControllerFocus,syncAllDevices:e.syncAllDevices,transformByPlatform:e.transformByPlatform};e.kind==="container"&&(t.isolateNavigation=e.isolateNavigation,t.disableKeyEventPassthrough=e.disableKeyEventPassthrough,t.disableCursorEventPassthrough=e.disableCursorEventPassthrough,t.showCursor=e.showCursor),(e.kind==="textbox"||e.kind==="textwindow")&&(t.fontSize=e.fontSize,t.adaptiveFontSize=e.adaptiveFontSize,t.minimumFontSize=e.minimumFontSize,t.fontColor=e.fontColor,t.bgColor=e.bgColor,t.enableOutline=e.enableOutline,t.outlineColor=e.outlineColor,t.horizontalAlignment=e.horizontalAlignment,t.verticalAlignment=e.verticalAlignment,t.text=e.text??"",e.kind==="textwindow"&&(t.interactable=e.interactable,t.showScrollBar=e.showScrollBar)),e.kind==="image"&&(t.imageSource=e.imageSource,t.imageId=e.imageId,t.imageColor=e.imageColor,t.enableMask=e.enableMask,t.enableSoftEdge=e.enableSoftEdge,t.softEdgeMode=e.softEdgeMode,t.softEdgeWidthX=e.softEdgeWidthX,t.softEdgeWidthY=e.softEdgeWidthY,t.horizontalSoftRange=e.horizontalSoftRange,t.verticalSoftRange=e.verticalSoftRange,t.enableFill=e.enableFill,t.fillType=e.fillType,t.fillHorizontalType=e.fillHorizontalType,t.fillVerticalType=e.fillVerticalType,t.fillRadial90Type=e.fillRadial90Type,t.fillRadialType=e.fillRadialType,t.fillAmount=e.fillAmount,t.reverseMaskArea=e.reverseMaskArea??e.reverseMask),e.kind==="button"&&(t.raycastTarget=e.raycastTarget,t.interactable=e.interactable,t.clickAudioId=e.clickAudioId,t.unavailableChildId=e.unavailableChildId??null,t.hoverChildId=e.hoverChildId??null,t.pressedChildId=e.pressedChildId??null,t.selectedChildId=e.selectedChildId??null),e.kind==="cursor"&&(t.raycastTarget=e.raycastTarget),e.kind==="reference"&&(t.referencedPrefabId=e.referencedPrefabId??null),e.kind==="grid"&&(t.itemPrefabId=e.itemPrefabId??null,t.raycastTarget=e.raycastTarget,t.interactable=e.interactable,t.showScrollBar=e.showScrollBar,t.scrollDirection=e.scrollDirection,t.layoutConstraint=e.layoutConstraint,t.layoutConstraintFixedCount=e.layoutConstraintFixedCount??null,t.cellSizeX=e.cellSizeX,t.cellSizeY=e.cellSizeY,t.spacingX=e.spacingX,t.spacingY=e.spacingY,t.padding1X=e.padding1X,t.padding1Y=e.padding1Y,t.padding2X=e.padding2X,t.padding2Y=e.padding2Y,t.previewCount=e.previewCount),e.kind==="keyhint"&&(t.keyboardKeyCode=e.keyboardKeyCode??null,t.controllerKeyCode=e.controllerKeyCode??null),(e.kind==="animation"||e.kind==="fullscreen")&&(t.animationId=e.animationId??null,t.playSoundEffect=e.playSoundEffect??null,e.kind==="animation"&&(t.layer=e.layer??null)),t.isRootContainer=e.kind==="container"&&yl(e.transformByPlatform);let i=W(e.kind,t);return i.children=(e.children||[]).map(r=>Pr(r)),i}function yl(e){let t=e&&(e.KEYBOARD||Object.values(e)[0]);return t?Math.abs(t.anchorMin?.x??.5)<1e-4&&Math.abs(t.anchorMin?.y??.5)<1e-4&&Math.abs((t.anchorMax?.x??.5)-1)<1e-4&&Math.abs((t.anchorMax?.y??.5)-1)<1e-4:!1}function ho(e,t,i={}){if(e.kind==="server-container"&&t!=="container")throw new Error("server container only accepts container nodes");let r=W(t,i);return e.children.push(r),r}function po(e,t){if(e.id===t)throw new Error("cannot remove root");let i=Le(e,t);if(!i)return!1;let r=i.children.findIndex(n=>n.id===t);return r<0?!1:(i.children.splice(r,1),!0)}var mo=1e-4;function bl(e,t){return Math.abs(e.anchorMax[t]-e.anchorMin[t])>mo&&Math.abs(e.size[t])<=mo}function vl(e,t,i){if(!(t.width>0)||!(t.height>0))throw new Error("source parent must have positive size");if(!(i.width>0)||!(i.height>0))throw new Error("target parent must have positive size");let r=De(t,e),n=(r.centerX-t.left)/t.width,o=(r.centerY-t.bottom)/t.height,a=tt(i,e,{posX:i.left+n*i.width,posY:i.bottom+o*i.height,width:r.width,height:r.height});for(let s of["x","y"])bl(e,s)&&(a.offset[s]=e.offset[s],a.size[s]=e.size[s]);return a}function go({transformByPlatform:e,source:t,canvasId:i,syncAllDevices:r,sourceParentBox:n=ye(i),targetParentBoxByPlatform:o={}}){He(e);let a=it(i),s={};for(let c of le)c===a?s[c]=Ne(t):r!==!1?s[c]=vl(t,n,o[c]||ye(vt[c])):s[c]=nt(e,c);return He(s),s}function Xe(e,t){return nt(e,it(t))}function yo(e,t){let i=[];function r(n){t[n.id]&&i.push(t[n.id]);let o=n.children||[];for(let a=o.length-1;a>=0;a-=1)r(o[a])}return r(e),i}function We(e,t,i=it(t)){let r=ye(t),n={};function o(a,s,c){let l=nt(a.transformByPlatform,i),u=De(s,l),h=a.kind==="server-container"?c:Jt(c,u,l),d=ro(u,h);n[a.id]={...u,...Sr(u),id:a.id,kind:a.kind,name:a.name,visible:a.visible!==!1,active:a.active!==!1,rotationZ:l.rotation.z,renderLeft:d.left,renderBottom:d.bottom,renderWidth:d.width,renderHeight:d.height,renderRotationZ:d.rotationZ,renderMatrix:h,primitive:a.kind==="image"?St(a.imageId):null,...a.kind==="textbox"||a.kind==="textwindow"?{text:a.text??"",fontSize:a.fontSize,fontColor:a.fontColor,bgColor:a.bgColor,enableOutline:a.enableOutline!==!1,outlineColor:a.outlineColor,horizontalAlignment:a.horizontalAlignment,verticalAlignment:a.verticalAlignment}:{},...a.kind==="image"?{imageSource:a.imageSource,imageId:a.imageId,imageColor:a.imageColor,enableMask:a.enableMask===!0,enableSoftEdge:a.enableSoftEdge===!0,softEdgeMode:a.softEdgeMode,softEdgeWidthX:a.softEdgeWidthX,softEdgeWidthY:a.softEdgeWidthY,horizontalSoftRange:a.horizontalSoftRange,verticalSoftRange:a.verticalSoftRange,enableFill:a.enableFill===!0,fillType:a.fillType,fillHorizontalType:a.fillHorizontalType,fillVerticalType:a.fillVerticalType,fillRadial90Type:a.fillRadial90Type,fillRadialType:a.fillRadialType,fillAmount:a.fillAmount,reverseMaskArea:a.reverseMaskArea===!0}:{},...a.kind==="button"?{raycastTarget:a.raycastTarget!==!1,interactable:a.interactable!==!1,clickAudioId:a.clickAudioId,unavailableChildId:a.unavailableChildId??null,hoverChildId:a.hoverChildId??null,pressedChildId:a.pressedChildId??null,selectedChildId:a.selectedChildId??null}:{}};let g=a.kind==="server-container"?s:u;for(let y of a.children||[])o(y,g,h)}return o(e,r,Ct()),{canvas:r,boxes:n}}function Rr(e,t){let i=[];function r(n,o,a=null,s=[],c=0,l=1,u=e.id){i.push({id:n.id,guid:t?.get(n.id)??(n.guid||0),kind:n.kind,name:n.name,label:wt[n.kind]||n.kind,depth:o,parentId:a,ancestorIds:s,siblingIndex:c,siblingCount:l,templateId:u,childCount:(n.children||[]).length,incomplete:!xi.includes(n.kind)});let h=n.children||[];for(let d=0;d<h.length;d+=1)r(h[d],o+1,n.id,[...s,n.id],d,h.length,u)}return r(e,0),i}function _(e,t,i,r,n={}){return{key:e,label:t,type:i,value:r,...n}}function bo(e,t,i,r){if(!e)return null;let n=Xe(e.transformByPlatform,t),o=Sr(i),a=[_("name","\u540D\u79F0","string",e.name),_("active","\u521D\u59CB\u6FC0\u6D3B","bool",e.active!==!1),_("visible","\u521D\u59CB\u53EF\u89C1\u6027","bool",e.visible!==!1),_("canControllerFocus","\u53EF\u88AB\u624B\u67C4\u6447\u6746\u5BFC\u822A\u9009\u4E2D","bool",e.canControllerFocus===!0),_("posX","\u4F4D\u7F6E X","number",o.posX,{computed:!0}),_("posY","\u4F4D\u7F6E Y","number",o.posY,{computed:!0}),_("width","\u5927\u5C0F W","number",o.width,{computed:!0}),_("height","\u5927\u5C0F H","number",o.height,{computed:!0}),_("rotationZ","\u65CB\u8F6C Z","number",n.rotation.z),_("syncAllDevices","\u540C\u6B65\u4FE1\u606F\u81F3\u6240\u6709\u8BBE\u5907","bool",e.syncAllDevices!==!1),_("anchorType","\u951A\u70B9\u7C7B\u578B","enum",oo(n),{options:[{value:"center",label:"\u5C45\u4E2D"},{value:"top-left",label:"\u5DE6\u4E0A"},{value:"top",label:"\u4E0A\u65B9"},{value:"top-right",label:"\u53F3\u4E0A"},{value:"left",label:"\u5DE6\u4FA7"},{value:"right",label:"\u53F3\u4FA7"},{value:"bottom-left",label:"\u5DE6\u4E0B"},{value:"bottom",label:"\u4E0B\u65B9"},{value:"bottom-right",label:"\u53F3\u4E0B"},{value:"stretch",label:"\u53CC\u5411\u62C9\u4F38"},{value:"stretch-horizontal",label:"\u6C34\u5E73\u62C9\u4F38"},{value:"stretch-vertical",label:"\u5782\u76F4\u62C9\u4F38"},{value:"custom",label:"\u81EA\u5B9A\u4E49"}]}),_("anchorMinX","\u951A\u70B9 Min X","number",n.anchorMin.x),_("anchorMinY","\u951A\u70B9 Min Y","number",n.anchorMin.y),_("anchorMaxX","\u951A\u70B9 Max X","number",n.anchorMax.x),_("anchorMaxY","\u951A\u70B9 Max Y","number",n.anchorMax.y),_("pivotX","\u4E2D\u5FC3 X","number",n.pivot.x),_("pivotY","\u4E2D\u5FC3 Y","number",n.pivot.y)];if(e.kind==="container"&&a.push(_("isolateNavigation","\u9694\u79BB\u624B\u67C4\u5BFC\u822A","bool",e.isolateNavigation===!0),_("disableKeyEventPassthrough","\u5C4F\u853D\u6309\u952E\u4E8B\u4EF6\u7A7F\u900F","bool",e.disableKeyEventPassthrough===!0),_("disableCursorEventPassthrough","\u5C4F\u853D\u533A\u57DF\u5185\u70B9\u51FB\u4E8B\u4EF6\u7A7F\u900F","bool",e.disableCursorEventPassthrough===!0),_("showCursor","\u663E\u793A\u5E38\u9A7B\u5149\u6807","bool",e.showCursor===!0)),e.kind==="textbox"||e.kind==="textwindow"){let s=e.giaRaw?.textAlign,c=[0,1,2].includes(s)?e.horizontalAlignment||"Left":`__unrecognized:${s}`;a.push(_("fontSize","\u5B57\u53F7","number",e.fontSize),_("adaptiveFontSize","\u5B57\u53F7\u81EA\u9002\u5E94","bool",e.adaptiveFontSize===!0),_("minimumFontSize","\u6700\u5C0F\u5B57\u53F7","number",e.minimumFontSize),_("fontColor","\u6587\u672C\u8272","color",e.fontColor),_("bgColor","\u80CC\u666F\u8272","color",e.bgColor),_("enableOutline","\u542F\u7528\u63CF\u8FB9","bool",e.enableOutline!==!1),_("outlineColor","\u63CF\u8FB9\u8272","color",e.outlineColor),_("horizontalAlignment","\u6C34\u5E73\u5BF9\u9F50","enum",c,{...[0,1,2].includes(s)?{}:{unknownValue:s},options:[{value:"Left",label:"\u5DE6\u5BF9\u9F50"},{value:"Middle",label:"\u5C45\u4E2D"},{value:"Right",label:"\u53F3\u5BF9\u9F50"}]}),_("verticalAlignment","\u5782\u76F4\u5BF9\u9F50","enum",e.verticalAlignment||"Top",{options:[{value:"Top",label:"\u9876\u90E8"},{value:"Middle",label:"\u5C45\u4E2D"},{value:"Bottom",label:"\u5E95\u90E8"}]}),_("text","\u6587\u672C","text",e.text??""))}if(e.kind==="image"){let s=e.giaRaw?.imageFillType,c=[1,2,3,4,5].includes(s)?e.fillType:`__unrecognized:${s}`;a.push(_("imageSource","\u56FE\u7247\u6E90","enum",e.imageSource,{readonly:!0,evidence:"W",options:[{value:"StaticReference",label:"\u9759\u6001\u5F15\u7528"}]}),_("imageId","imageId","number",e.imageId??0),_("imageColor","\u586B\u5145\u8272","color",e.imageColor),_("enableMask","\u5F00\u542F\u906E\u7F69","bool",e.enableMask===!0),_("enableSoftEdge","\u8FB9\u7F18\u7FBD\u5316","bool",e.enableSoftEdge===!0,{gia:"W"}),_("softEdgeMode","\u7FBD\u5316\u6A21\u5F0F","enum",e.softEdgeMode,{options:[{value:"Percentage",label:"\u767E\u5206\u6BD4"},{value:"Pixel",label:"\u50CF\u7D20"}]}),_("softEdgeWidthX","\u7FBD\u5316\u5BBD\u5EA6 X","number",e.softEdgeWidthX),_("softEdgeWidthY","\u7FBD\u5316\u5BBD\u5EA6 Y","number",e.softEdgeWidthY),_("horizontalSoftRange","\u6C34\u5E73\u7FBD\u5316\u8303\u56F4","number",e.horizontalSoftRange),_("verticalSoftRange","\u5782\u76F4\u7FBD\u5316\u8303\u56F4","number",e.verticalSoftRange),_("enableFill","\u6309\u8FDB\u5EA6\u586B\u5145","bool",e.enableFill===!0,{gia:"W"}),_("fillType","\u5F62\u72B6","enum",c,{...[1,2,3,4,5].includes(s)?{}:{unknownValue:s},options:[{value:"Horizontal",label:"\u6A2A\u5411"},{value:"Vertical",label:"\u7EB5\u5411"},{value:"Radial90",label:"90\u5EA6\u73AF\u7ED5"},{value:"Radial180",label:"180\u5EA6\u73AF\u7ED5"},{value:"Radial360",label:"360\u5EA6\u73AF\u7ED5"}]}),_("fillHorizontalType","\u65B9\u5411","enum",e.fillHorizontalType,{options:[{value:"Left",label:"\u4ECE\u5DE6\u81F3\u53F3"},{value:"Right",label:"\u4ECE\u53F3\u81F3\u5DE6"}]}),_("fillVerticalType","\u65B9\u5411","enum",e.fillVerticalType,{options:[{value:"Bottom",label:"\u4ECE\u4E0B\u81F3\u4E0A"},{value:"Top",label:"\u4ECE\u4E0A\u81F3\u4E0B"}]}),_("fillRadial90Type","\u8D77\u70B9","enum",e.fillRadial90Type,{options:[{value:"BottomLeft",label:"\u5DE6\u4E0B"},{value:"TopLeft",label:"\u5DE6\u4E0A"},{value:"TopRight",label:"\u53F3\u4E0A"},{value:"BottomRight",label:"\u53F3\u4E0B"}]}),_("fillRadialType","\u8D77\u70B9","enum",e.fillRadialType,{options:[{value:"Bottom",label:"\u4E0B\u65B9"},{value:"Left",label:"\u5DE6\u4FA7"},{value:"Top",label:"\u4E0A\u65B9"},{value:"Right",label:"\u53F3\u4FA7"}]}),_("fillAmount","\u8FDB\u5EA6","percent",e.fillAmount),_("reverseMaskArea","\u906E\u7F69\u533A\u57DF\u53CD\u8F6C","bool",e.reverseMaskArea===!0,{gia:"W"}))}if(e.kind==="button"){let s=[{value:"",label:"\u672A\u8BBE\u7F6E"},...(e.children||[]).map(c=>({value:c.id,label:`${c.name} \xB7 ${c.id}`}))];a.push(_("raycastTarget","\u53EF\u88AB\u5149\u6807\u5C04\u7EBF\u68C0\u6D4B","bool",e.raycastTarget!==!1),_("interactable","\u6309\u94AE\u662F\u5426\u53EF\u7528","bool",e.interactable!==!1),_("unavailableChildId","\u4E0D\u53EF\u7528\u72B6\u6001\u8282\u70B9","node",e.unavailableChildId,{options:s,gia:"W"}),_("hoverChildId","\u60AC\u505C\u72B6\u6001\u8282\u70B9","node",e.hoverChildId,{options:s,gia:"W"}),_("pressedChildId","\u6309\u4E0B\u72B6\u6001\u8282\u70B9","node",e.pressedChildId,{options:s,gia:"W"}),_("selectedChildId","\u9009\u4E2D\u72B6\u6001\u8282\u70B9","node",e.selectedChildId,{options:s,gia:"W"}),_("clickAudioId","\u70B9\u51FB\u97F3\u6548","number",e.clickAudioId))}return e.kind==="reference"&&a.push(_("referencedPrefabId","\u5F15\u7528\u63A7\u4EF6\u6A21\u677F\u7D22\u5F15","string",e.referencedPrefabId??"")),(e.kind==="textwindow"||e.kind==="grid")&&a.push(_("interactable","\u5141\u8BB8\u6EDA\u52A8\u4EA4\u4E92","bool",e.interactable!==!1),_("showScrollBar","\u663E\u793A\u6EDA\u52A8\u6761","bool",e.showScrollBar!==!1)),e.kind==="grid"&&a.push(_("itemPrefabId","\u5217\u8868\u9879\u6A21\u677F\u7D22\u5F15","number",e.itemPrefabId??0),_("raycastTarget","\u53EF\u88AB\u5149\u6807\u5C04\u7EBF\u68C0\u6D4B","bool",e.raycastTarget!==!1),_("scrollDirection","\u6EDA\u52A8\u65B9\u5411","enum",e.scrollDirection,{options:[{value:"Vertical",label:"\u7EB5\u5411"},{value:"Horizontal",label:"\u6A2A\u5411"}]}),_("layoutConstraint","\u6392\u5217\u9650\u5236","enum",e.layoutConstraint,{options:[{value:"AutoWrap",label:"\u81EA\u52A8\u6362\u884C"},{value:"Fixed",label:"\u56FA\u5B9A\u884C\u5217\u6570"}]}),_("layoutConstraintFixedCount","\u6BCF\u884C\u6216\u6BCF\u5217\u6570\u91CF","number",e.layoutConstraintFixedCount??1),_("cellSizeX","\u5217\u8868\u9879\u5927\u5C0F W","number",e.cellSizeX,{evidence:"W"}),_("cellSizeY","\u5217\u8868\u9879\u5927\u5C0F H","number",e.cellSizeY,{evidence:"W"}),_("spacingX","\u5217\u8868\u9879\u95F4\u9694 X","number",e.spacingX,{evidence:"W"}),_("spacingY","\u5217\u8868\u9879\u95F4\u9694 Y","number",e.spacingY,{evidence:"W"}),_("padding1X","\u8FB9\u8DDD\u5411\u91CF 1 X","number",e.padding1X,{evidence:"W"}),_("padding1Y","\u8FB9\u8DDD\u5411\u91CF 1 Y","number",e.padding1Y,{evidence:"W"}),_("padding2X","\u8FB9\u8DDD\u5411\u91CF 2 X","number",e.padding2X,{evidence:"W"}),_("padding2Y","\u8FB9\u8DDD\u5411\u91CF 2 Y","number",e.padding2Y,{evidence:"W"}),_("previewCount","\u9884\u89C8\u6570\u91CF","number",e.previewCount)),e.kind==="keyhint"&&a.push(_("keyboardKeyCode","\u952E\u9F20\u6309\u952E","number",e.keyboardKeyCode??e.giaRaw?.keyHintField502??1,{gia:"W"}),_("controllerKeyCode","\u624B\u67C4\u6309\u952E","number",e.controllerKeyCode??e.giaRaw?.keyHintField501??1)),(e.kind==="animation"||e.kind==="fullscreen")&&a.push(_("animationId",e.kind==="animation"?"\u52A8\u6548\u7D22\u5F15":"\u5168\u5C4F\u52A8\u6548\u7D22\u5F15","string",e.animationId??"")),(!xi.includes(e.kind)||e.kind==="textwindow"||e.kind==="grid")&&a.push(_("incomplete","\u5B8C\u6574\u5EA6","note",e.kind==="textwindow"||e.kind==="grid"?"\u8BD5\u73A9\u652F\u6301\u57FA\u7840\u6EDA\u52A8\uFF1B\u6EDA\u52A8\u4EA4\u4E92\u3001\u6EDA\u52A8\u6761\u53CA\u5217\u8868\u914D\u7F6E\u4EE5 JSON/Lua \u4E3A\u51C6\uFF0C\u76F8\u5173 GIA \u5F00\u5173\u6620\u5C04\u5C1A\u672A\u6838\u5B9E\u3002":"\u672C\u9636\u6BB5\u4EC5\u516C\u5171\u53D8\u6362\uFF0C\u4E1A\u52A1\u69FD\u4E0D\u5B8C\u6574")),{id:e.id,guid:r?.get(e.id)??(e.guid||0),kind:e.kind,label:wt[e.kind]||e.kind,incomplete:!xi.includes(e.kind),fields:a}}function vo(e,t,i){let r=(Array.isArray(e)?e:Object.values(e)).filter(n=>n.kind!=="server-container");for(let n=r.length-1;n>=0;n-=1){let o=r[n];if(!o.visible||!o.active)continue;let a=o.renderMatrix&&qt(o.renderMatrix),s=a&&$e(a,t,i);if(s&&s.x>=o.left&&s.x<=o.right&&s.y>=o.bottom&&s.y<=o.top)return o.id}return null}import wl from"protobufjs";var Sl=String.raw`
|
|
2
|
+
import{spawn as hd}from"node:child_process";import{createServer as md}from"node:http";import{readFileSync as pd,realpathSync as nl}from"node:fs";import{extname as gd,resolve as ol}from"node:path";import{fileURLToPath as sl}from"node:url";import{createHash as yd,timingSafeEqual as bd}from"node:crypto";import{statSync as rd}from"node:fs";var da={name:"beyond-simulator-web",version:"0.4.0",description:"Self-hosted editor, preview and play surface for Qianxing simulator saves",type:"module",main:"dist/server.js",bin:{"beyond-simulator-web":"dist/server.js"},files:["dist","README.md"],scripts:{build:"node ../scripts/build.mjs web",pretest:"node ../scripts/build.mjs web",prepack:"node ../scripts/build.mjs web",start:"node dist/server.js",dev:"node ../scripts/build.mjs web && node server.js",test:"node --test test/*.test.mjs"},engines:{node:">=20"},dependencies:{"@napi-rs/canvas":"0.1.100",fengari:"0.1.5",protobufjs:"8.7.2"},devDependencies:{react:"19.1.1","react-dom":"19.1.1","qxqy-editor-ui":"workspace:*","qxqy-studio":"workspace:*"},license:"GPL-3.0-only",repository:{type:"git",url:"git+https://github.com/1475505/miliastra-beyond-simulator.git",directory:"web"}};var ha="https://oss.070077.xyz/prefabs/",Jt="prefab-v1",Tl=[[10003004,10003004],[10005001,10005142],[10006001,10006002],[10007002,10007002],[10008001,10008001],[10009001,10009011],[20001001,20001074],[20001076,20001121],[20001123,20001156],[20001158,20001302],[20001304,20001568],[20001570,20001999],[20002001,20002755],[20002757,20002999],[20003001,20003455],[30001001,30001016],[30002001,30002017],[30003001,30003011],[30004001,30004001],[30005001,30005020],[30006001,30006026],[30007001,30007013],[30008001,30008011]];function Ai(e){return!Number.isSafeInteger(e)||!Tl.some(([t,i])=>e>=t&&e<=i)?null:e===10003004||e===10008001?128:256}var _i="https://oss.070077.xyz/images/",Rr="sprite-v1",Pi="/qxqy-assets/",Rl=[[100001,100006],[100101,100213],[101001,101018],[101020,101028],[101030,101046],[101048,101048],[101050,101054],[101056,101080],[102001,102052],[103001,103148],[104001,104010],[105001,105140],[105142,105219],[105221,105317],[106001,106047],[106049,106096],[107001,107007],[107010,107020],[107031,107092],[107094,107180],[107183,107201],[107203,107205],[107207,107228],[107231,107278],[107280,107402],[108001,108017],[108019,108020],[109001,109031],[109033,109034],[109036,109075],[110001,110053],[111001,111139],[112001,112042]];function Ie(e){return e==null||e===""?"StaticReference":typeof e=="string"?e:typeof e.Name=="string"?e.Name:"Unknown"}function Ti(e,t){return`${Ie(t)}:${e}`}function ma(e,t){return Ie(t)==="StaticReference"&&qe(e,t)}function qe(e,t){let i=Ie(t);return i==="Prefab"?Ai(e)!==null:i==="StaticReference"&&Number.isSafeInteger(e)&&e>100006&&Rl.some(([r,n])=>e>=r&&e<=n)}var Ri="7.1.0",ce=Object.freeze(["KEYBOARD","TOUCHSCREEN","CONTROLLER_CONSOLE","CONTROLLER_MOBILE"]),K=Object.freeze({"pc-16-9":{id:"pc-16-9",device:"pc",platform:"KEYBOARD",width:1600,height:900,ratio:"16:9",luaDevice:"KeyboardAndMouse",label:"PC 1600\xD7900"},"pc-21-9":{id:"pc-21-9",device:"pc",platform:"KEYBOARD",width:2100,height:900,ratio:"21:9",luaDevice:"KeyboardAndMouse",label:"PC 2100\xD7900"},"mobile-16-9":{id:"mobile-16-9",device:"mobile",platform:"TOUCHSCREEN",width:1280,height:720,ratio:"16:9",luaDevice:"Mobile",label:"\u624B\u673A 1280\xD7720"},"mobile-19.5-9":{id:"mobile-19.5-9",device:"mobile",platform:"TOUCHSCREEN",width:1560,height:720,ratio:"19.5:9",luaDevice:"Mobile",label:"\u624B\u673A 1560\xD7720"},"mobile-4-3":{id:"mobile-4-3",device:"mobile",platform:"TOUCHSCREEN",width:1280,height:960,ratio:"4:3",luaDevice:"Mobile",label:"\u624B\u673A 1280\xD7960"}}),Mi="pc-16-9",pe=2,kt=Object.freeze({KEYBOARD:"pc-16-9",TOUCHSCREEN:"mobile-16-9",CONTROLLER_CONSOLE:"pc-16-9",CONTROLLER_MOBILE:"mobile-16-9"}),Et=Object.freeze({"server-container":"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668",container:"\u5BB9\u5668\u8282\u70B9",textbox:"\u6587\u672C\u6846",image:"\u56FE\u7247",button:"\u9884\u8BBE\u6309\u94AE",cursor:"\u5149\u6807\u68C0\u6D4B\u533A\u57DF",grid:"\u7F51\u683C\u89C6\u7A97",reference:"\u6A21\u677F\u5F15\u7528\u63A7\u4EF6",textwindow:"\u6587\u672C\u89C6\u7A97",keyhint:"\u6309\u952E\u63D0\u793A",animation:"\u754C\u9762\u52A8\u6548",fullscreen:"\u5168\u5C4F\u52A8\u6548"}),Ni=Object.freeze(["server-container","container","textbox","cursor","reference","grid","image","button","textwindow","keyhint","animation","fullscreen"]),pa=Object.freeze({"server-container":null,container:[150,150],textbox:[100,40],image:[80,80],button:[150,50],cursor:[150,50],grid:[80,80],reference:[80,80],textwindow:[100,40],keyhint:[40,40],animation:[100,100],fullscreen:null}),Ml=Object.freeze({100001:"rect",100002:"circle",100003:"triangle",100004:"fourstar",100005:"fivestar",100006:"ring"});function At(e,t){return Ie(t)==="StaticReference"&&Ml[e]||(qe(e,t)?"sprite":"missing")}var ga=50888,Zt=Object.freeze({font:4294967295,bg:16777215,outline:858993459,image:4294967295});import{Worker as Kf}from"node:worker_threads";import{existsSync as qf,mkdirSync as Jf,readFileSync as ra,writeFileSync as Zf}from"node:fs";import{basename as Qf,dirname as ed}from"node:path";import{existsSync as vi,readFileSync as Pu}from"node:fs";import{randomUUID as Tu}from"node:crypto";import{isAbsolute as ya,win32 as ba}from"node:path";function Oi(e,t=!1){let i=String(e??"").trim().replaceAll("\\","/");if(t&&(!i||i==="."))return"";if(!i||ya(i)||ba.isAbsolute(i)||i.split("/").some(r=>!r||r==="."||r===".."||/[<>:"|?*\x00-\x1f]/.test(r)||/[. ]$/.test(r)||/^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(r)))throw new Error("\u811A\u672C\u76EE\u5F55/\u8DEF\u5F84\u5FC5\u987B\u662F\u6709\u6548\u7684\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u4E0D\u80FD\u5305\u542B .. \u6216 Windows \u7279\u6B8A\u6587\u4EF6\u540D");return i}function Qt(e){if(e==null)return null;if(e.version!==1)throw new Error("unsupported scriptSync version");let t=String(e.clientImportRoot||"").trim();if(!ya(t)&&!ba.isAbsolute(t))throw new Error("\u5B9E\u673A\u5BFC\u5165\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");return{version:1,workspaceDir:Oi(e.workspaceDir,!0),clientImportRoot:t,clientSubdir:Oi(e.clientSubdir,!0)}}import{basename as Yt,dirname as Ru,isAbsolute as Mu,join as bs,resolve as vs}from"node:path";function _t(e,t="$",i=new Set){if(e===void 0)throw new Error(`undefined at ${t}`);if(typeof e=="number"&&!Number.isFinite(e))throw new Error(`non-finite number at ${t}`);if(typeof e=="bigint"||typeof e=="function"||typeof e=="symbol")throw new Error(`non-JSON value at ${t}`);if(!(e===null||typeof e!="object")){if(i.has(e))throw new Error(`circular value at ${t}`);if(i.add(e),Array.isArray(e))e.forEach((r,n)=>_t(r,`${t}[${n}]`,i));else for(let[r,n]of Object.entries(e))_t(n,`${t}.${r}`,i);i.delete(e)}}function V(e){return _t(e),JSON.parse(JSON.stringify(e))}function va(e,t="$"){_t(e,t)}function Sa(e){return K[e]||K[Mi]}function ei(e,t=0,i=0){return!e||typeof e!="object"?{x:t,y:i}:{x:Number(e.x??t),y:Number(e.y??i)}}function Nl(e){return!e||typeof e!="object"?{x:1,y:1,z:1}:{x:Number(e.x??1),y:Number(e.y??1),z:Number(e.z??1)}}function Ol(e){return!e||typeof e!="object"?{x:0,y:0,z:0}:{x:Number(e.x??0),y:Number(e.y??0),z:Number(e.z??0)}}function Fi({layout:e="center",size:t=[100,40],offset:i=[0,0]}={}){return e==="stretch"?{scale:{x:1,y:1,z:1},rotation:{x:0,y:0,z:0},anchorMin:{x:0,y:0},anchorMax:{x:1,y:1},offset:{x:0,y:0},size:{x:0,y:0},pivot:{x:.5,y:.5}}:{scale:{x:1,y:1,z:1},rotation:{x:0,y:0,z:0},anchorMin:{x:.5,y:.5},anchorMax:{x:.5,y:.5},offset:{x:Number(i[0]??0),y:Number(i[1]??0)},size:{x:Number(t[0]??0),y:Number(t[1]??0)},pivot:{x:.5,y:.5}}}function $e(e){let t=e||Fi();return{scale:Nl(t.scale),rotation:Ol(t.rotation),anchorMin:ei(t.anchorMin??t.anchor_min,.5,.5),anchorMax:ei(t.anchorMax??t.anchor_max,.5,.5),offset:ei(t.offset,0,0),size:ei(t.size,0,0),pivot:ei(t.pivot,.5,.5)}}function ge(e,t=0){let i=Number(e);return Number.isFinite(i)?i:t}function Be(e,t){let i=e.width,r=e.height,n=e.left,a=e.bottom,o=t.anchorMin||{x:t.anchorMinX,y:t.anchorMinY},s=t.anchorMax||{x:t.anchorMaxX,y:t.anchorMaxY},c=t.offset||{x:t.anchoredPositionX,y:t.anchoredPositionY},l=t.size||{x:t.sizeDeltaX,y:t.sizeDeltaY},u=t.pivot||{x:t.pivotX,y:t.pivotY},d=ge(o?.x,.5)*i,h=ge(o?.y,.5)*r,p=ge(s?.x,.5)*i,m=ge(s?.y,.5)*r,g=ge(l?.x),S=ge(l?.y),C=ge(u?.x,.5),I=ge(u?.y,.5),P=p-d+g,N=m-h+S,G=n+d+ge(c?.x)-g*C,j=a+h+ge(c?.y)-S*I;return{left:G,bottom:j,width:P,height:N,right:G+P,top:j+N,centerX:G+P/2,centerY:j+N/2}}function Pt(){return{a:1,b:0,c:0,d:1,tx:0,ty:0}}function Fl(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 xe(e,t,i){return{x:e.a*t+e.c*i+e.tx,y:e.b*t+e.d*i+e.ty}}function je(e){let t=e.a*e.d-e.b*e.c;return!Number.isFinite(t)||Math.abs(t)<1e-8?null:{a:e.d/t,b:-e.b/t,c:-e.c/t,d:e.a/t,tx:(e.c*e.ty-e.d*e.tx)/t,ty:(e.b*e.tx-e.a*e.ty)/t}}function Mr(e,t){let i=t.rotation||{z:t.localRotationZ},r=t.scale||{x:t.localScaleX,y:t.localScaleY},n=t.pivot||{x:t.pivotX,y:t.pivotY},a=ge(i?.z)*Math.PI/180,o=Math.cos(a),s=Math.sin(a),c=ge(r?.x,1),l=ge(r?.y,1),u=e.left+e.width*ge(n?.x,.5),d=e.bottom+e.height*ge(n?.y,.5),h=o*c,p=s*c,m=-s*l,g=o*l;return{a:h,b:p,c:m,d:g,tx:u-h*u-m*d,ty:d-p*u-g*d}}function ti(e,t,i){return Fl(e||Pt(),Mr(t,i))}function wa(e,t){let i=xe(t,e.centerX,e.centerY),r=Math.abs(e.width*Math.hypot(t.a,t.b)),n=Math.abs(e.height*Math.hypot(t.c,t.d));return{left:i.x-r/2,bottom:i.y-n/2,width:r,height:n,centerX:i.x,centerY:i.y,rotationZ:Math.atan2(t.b,t.a)*180/Math.PI}}function ye(e){let t=typeof e=="string"?Sa(e):e;return{left:0,bottom:0,width:t.width,height:t.height,right:t.width,top:t.height,centerX:t.width/2,centerY:t.height/2}}function Nr(e){return{posX:e.centerX,posY:e.centerY,width:e.width,height:e.height}}function lt(e,t,i){let r=$e(t),n=e.width,a=e.height,o=r.anchorMin.x*n,s=r.anchorMin.y*a,c=r.anchorMax.x*n,l=r.anchorMax.y*a,u=Number(i.width),d=Number(i.height),h=Number(i.posX),p=Number(i.posY),m=h-u/2,g=p-d/2;return r.size={x:u-(c-o),y:d-(l-s)},r.offset={x:m-e.left-o+r.size.x*r.pivot.x,y:g-e.bottom-s+r.size.y*r.pivot.y},r}function Ia(e,t){let i=$e(e),n={"bottom-left":[[0,0],[0,0],[0,0]],bottom:[[.5,0],[.5,0],[.5,0]],"bottom-right":[[1,0],[1,0],[1,0]],left:[[0,.5],[0,.5],[0,.5]],center:[[.5,.5],[.5,.5],[.5,.5]],right:[[1,.5],[1,.5],[1,.5]],"top-left":[[0,1],[0,1],[0,1]],top:[[.5,1],[.5,1],[.5,1]],"top-right":[[1,1],[1,1],[1,1]],stretch:[[0,0],[1,1],[.5,.5]],"stretch-horizontal":[[0,.5],[1,.5],[.5,.5]],"stretch-vertical":[[.5,0],[.5,1],[.5,.5]]}[t];return n&&(i.anchorMin={x:n[0][0],y:n[0][1]},i.anchorMax={x:n[1][0],y:n[1][1]},i.pivot={x:n[2][0],y:n[2][1]}),i}function xa(e){let t=$e(e),i=(r,n)=>Math.abs(r-n)<1e-4;if(i(t.anchorMin.x,0)&&i(t.anchorMin.y,0)&&i(t.anchorMax.x,1)&&i(t.anchorMax.y,1))return"stretch";if(i(t.anchorMin.x,t.anchorMax.x)&&i(t.anchorMin.y,t.anchorMax.y)){let r=t.anchorMin.x,n=t.anchorMin.y,a=[[0,0,"bottom-left"],[.5,0,"bottom"],[1,0,"bottom-right"],[0,.5,"left"],[.5,.5,"center"],[1,.5,"right"],[0,1,"top-left"],[.5,1,"top"],[1,1,"top-right"]];for(let o of a)if(i(r,o[0])&&i(n,o[1]))return o[2]}return"custom"}function ct(e){return Sa(e).platform}function Ca(e){let t={};for(let i of ce)t[i]=e(i);return t}var Dl={scale:["x","y","z"],rotation:["x","y","z"],anchorMin:["x","y"],anchorMax:["x","y"],offset:["x","y"],size:["x","y"],pivot:["x","y"]};function ka(e,t){for(let[i,r]of Object.entries(Dl))for(let n of r)if(!Number.isFinite(e?.[i]?.[n]))throw new Error(`${t}.${i}.${n} must be a finite number`)}function Je(e,t="transformByPlatform"){if(!e||typeof e!="object"||Array.isArray(e))throw new Error(`${t}: \u9700\u8981\u5B8C\u6574\u7684\u56DB\u5E73\u53F0\u5E03\u5C40`);for(let i of Object.keys(e))if(!ce.includes(i))throw new Error(`${t}: unknown platform ${i}`);for(let i of ce)ka(e[i],`${t}.${i}`)}function ut(e){if(Object.hasOwn(e,"transformByCanvas"))throw new Error(`${e.name||e.id||"\u63A7\u4EF6"}: \u4E0D\u518D\u652F\u6301 transformByCanvas\uFF1B\u8BF7\u4F7F\u7528\u56DB\u5E73\u53F0 transformByPlatform \u5E03\u5C40`);Je(e.transformByPlatform,`${e.name||e.id||"\u63A7\u4EF6"}.transformByPlatform`)}function ft(e,t){if(!ce.includes(t))throw new Error(`unknown platform ${t}`);return ka(e?.[t],`transformByPlatform.${t}`),$e(e[t])}var zl=Object.freeze([{key:"genericField501",label:"\u901A\u7528\u69FD field501",type:"number",defaultValue:0,wire:"GenericSlot.field501"},{key:"footerField505",label:"\u5C3E\u90E8\u69FD field505",type:"number",defaultValue:0,wire:"FooterSlot.field505"}]),$l=Object.freeze({container:[],textbox:[{key:"textField501",label:"\u6587\u672C\u914D\u7F6E field501",type:"number",defaultValue:20,wire:"TextConfig.field501"},{key:"textField503",label:"\u6587\u672C\u914D\u7F6E field503",type:"number",defaultValue:12,wire:"TextConfig.field503"},{key:"textAlign",label:"\u6C34\u5E73\u5BF9\u9F50\u679A\u4E3E\u539F\u59CB\u503C",type:"enum",defaultValue:0,wire:"TextConfig.align",options:[{value:0,label:"0 \xB7 \u5DE6\u5BF9\u9F50"},{value:1,label:"1 \xB7 \u5C45\u4E2D"},{value:2,label:"2 \xB7 \u53F3\u5BF9\u9F50"}]}],textwindow:[{key:"textField501",label:"\u6587\u672C\u914D\u7F6E field501",type:"number",defaultValue:20,wire:"TextConfig.field501"},{key:"textField503",label:"\u6587\u672C\u914D\u7F6E field503",type:"number",defaultValue:12,wire:"TextConfig.field503"},{key:"textAlign",label:"\u6C34\u5E73\u5BF9\u9F50\u679A\u4E3E\u539F\u59CB\u503C",type:"enum",defaultValue:0,wire:"TextConfig.align",options:[{value:0,label:"0 \xB7 \u5DE6\u5BF9\u9F50"},{value:1,label:"1 \xB7 \u5C45\u4E2D"},{value:2,label:"2 \xB7 \u53F3\u5BF9\u9F50"}]},{key:"textField511",label:"\u6587\u672C\u89C6\u7A97 field511",type:"number",defaultValue:1,wire:"TextConfig.field511"},{key:"textViewField502",label:"\u89C6\u7A97\u6807\u8BB0 field502",type:"number",defaultValue:1,wire:"TextConfig.viewFlags.field502"},{key:"textViewField503",label:"\u89C6\u7A97\u6807\u8BB0 field503",type:"number",defaultValue:1,wire:"TextConfig.viewFlags.field503"}],cursor:[{key:"cursorField501",label:"\u5149\u6807\u68C0\u6D4B field501",type:"number",defaultValue:1,wire:"CursorConfig.field501"}],reference:[{key:"templateRefSlot",label:"\u6A21\u677F\u5F15\u7528\u69FD\u539F\u59CB\u503C",type:"string",defaultValue:"",wire:"Details.templateRefSlot"}],grid:[{key:"gridField501",label:"\u7F51\u683C\u6807\u8BB0 field501",type:"number",defaultValue:1,wire:"GridViewConfig.field501"},{key:"gridField507",label:"\u7F51\u683C\u6807\u8BB0 field507",type:"number",defaultValue:1,wire:"GridViewConfig.field507"},{key:"gridField508",label:"\u7F51\u683C\u6807\u8BB0 field508",type:"number",defaultValue:1,wire:"GridViewConfig.field508"},{key:"gridField509",label:"\u7F51\u683C\u6807\u8BB0 field509",type:"number",defaultValue:1,wire:"GridViewConfig.field509"},{key:"gridField511",label:"\u7F51\u683C\u6807\u8BB0 field511",type:"number",defaultValue:5,wire:"GridViewConfig.field511"},{key:"gridField512",label:"\u7F51\u683C\u6807\u8BB0 field512",type:"number",defaultValue:1,wire:"GridViewConfig.field512"}],keyhint:[{key:"keyHintField501",label:"\u6309\u952E\u63D0\u793A field501",type:"number",defaultValue:1,wire:"KeyHintConfig.field501"},{key:"keyHintField502",label:"\u952E\u9F20\u952E\u4F4D\u539F\u59CB\u503C",type:"number",defaultValue:1,wire:"KeyHintConfig.field502"}],image:[{key:"imageSlotType",label:"\u56FE\u7247\u7C7B\u578B\u539F\u59CB\u503C",type:"number",defaultValue:0,wire:"ImageSlotConfig.imageType"},{key:"imageField502",label:"\u56FE\u7247\u6807\u8BB0 field502",type:"number",defaultValue:1,wire:"ImageConfig.field502"},{key:"imageField504",label:"\u56FE\u7247\u6807\u8BB0 field504",type:"number",defaultValue:1,wire:"ImageConfig.field504"},{key:"imageField505",label:"\u56FE\u7247\u6807\u8BB0 field505",type:"number",defaultValue:1,wire:"ImageConfig.field505"},{key:"imageField507",label:"\u56FE\u7247\u6807\u8BB0 field507",type:"number",defaultValue:2,wire:"ImageConfig.field507"},{key:"imageFillType",label:"\u586B\u5145\u5F62\u72B6\u679A\u4E3E\u539F\u59CB\u503C",type:"enum",defaultValue:1,wire:"ImageConfig.fillType",options:[{value:1,label:"1 \xB7 \u6A2A\u5411"},{value:2,label:"2 \xB7 \u7EB5\u5411"},{value:3,label:"3 \xB7 90\u5EA6\u73AF\u7ED5"},{value:4,label:"4 \xB7 180\u5EA6\u73AF\u7ED5"},{value:5,label:"5 \xB7 360\u5EA6\u73AF\u7ED5"}]}],animation:[{key:"effectSlot",label:"\u754C\u9762\u52A8\u6548\u69FD\u539F\u59CB\u503C",type:"string",defaultValue:"",wire:"Details.effectSlot"}],fullscreen:[{key:"fullscreenEffectSlot",label:"\u5168\u5C4F\u52A8\u6548\u69FD\u539F\u59CB\u503C",type:"string",defaultValue:"",wire:"Details.fullscreenEffectSlot"}]});function Ea(e){return[...zl,...$l[e]||[]]}function Aa(e,t){return Ea(e).find(i=>i.key===t)||null}function Or(e,t){if(!e)throw new Error("unknown raw GIA field");if(e.type==="string")return String(t??"");let i=Number(t);if(!Number.isFinite(i))throw new Error(`${e.wire} must be a finite number`);return Math.trunc(i)}function _a(e,t={}){let i={};for(let r of Ea(e)){let n=Object.hasOwn(t||{},r.key)?t[r.key]:r.defaultValue;i[r.key]=Or(r,n)}return i}function Pe(e){let t=Number(e);return Number.isSafeInteger(t)&&t>0&&t<=2147483647}function Fr(e,t){if(e){t(e);for(let i of e.children||[])Fr(i,t)}}function Tt(e,t=new Set,{skipServerContainer:i=!1}={}){return Fr(e,r=>{i&&r.kind==="server-container"||Pe(r.guid)&&t.add(Number(r.guid))}),t}function Ze(e,t=1073741850){let i=Number.isSafeInteger(t)&&t>0?t:1073741850;i<1073741850&&(i=1073741850);for(let r of e)Pe(r)&&r>=i&&(i=Number(r)+1);for(;e.has(i);)i+=1;if(i>2147483647)throw new Error("GUID space exhausted");return i}function Pa(e,t=new Set,{skipServerContainer:i=!1}={}){let r=[];Fr(e,n=>{if(i&&n.kind==="server-container")return;let a=Number(n.guid);if(Pe(a)&&!t.has(a)){t.add(a),n.guid=a;return}r.push(n)});for(let n of r){let a=Ze(t);n.guid=a,t.add(a)}return t}function Ee(e){return Number.isSafeInteger(e)&&e>0&&e<=2147483647}function He(e,{warnings:t=[]}={}){if(e.meta?.assetType!=="client-control-template")return;if(e.meta.giaAssetIndexSchemaVersion>1)throw new Error(`\u4E0D\u652F\u6301\u5BA2\u6237\u7AEF\u8D44\u4EA7\u7F16\u53F7\u7248\u672C ${e.meta.giaAssetIndexSchemaVersion}`);let i=[],r=m=>{m.kind!=="server-container"&&i.push(m);for(let g of m.children||[])r(g)};r(e.root);let n=new Map,a=new Map;for(let m of i){if(!Ee(m.giaInfoIndex))continue;let g=n.get(m.giaInfoIndex)||[];g.push(m),n.set(m.giaInfoIndex,g);let S=a.get(m.kind)||new Set;S.add(m.giaInfoIndex),a.set(m.kind,S)}let o=(e.root.children||[]).filter(m=>m.kind!=="server-container"),s=new Set(o),c=o.some((m,g)=>Ee(m.giaInfoIndex)&&o.slice(0,g).some(S=>S.giaInfoIndex===m.giaInfoIndex)),l=!e.meta.giaAssetIndexSchemaVersion&&c&&i.every(m=>m.giaInfoIndexSource!=="authoring")&&[...a.values()].every(m=>m.size===1)&&[...n.values()].every(m=>m.every(g=>g.kind===m[0].kind)),u=new Set;if(l)for(let m of n.values()){let g=m.find(S=>s.has(S))||m[0];for(let S of m)S!==g&&u.add(S)}let d=new Map,h=Number.isSafeInteger(e.meta.giaNextAssetIndex)&&e.meta.giaNextAssetIndex>=2?e.meta.giaNextAssetIndex:2;for(let m of i){if(!Ee(m.giaInfoIndex)||(h=Math.max(h,m.giaInfoIndex+1),u.has(m)))continue;let g=d.get(m.giaInfoIndex);if(g&&(g.giaInfoIndexSource==="authoring"||m.giaInfoIndexSource==="authoring"))throw new Error(`\u65B0\u5EFA\u8D44\u4EA7\u7F16\u53F7 ${m.giaInfoIndex} \u91CD\u590D\uFF1A${g.name} / ${m.name}`);d.set(m.giaInfoIndex,m)}l&&(h=Math.max(h,13));let p=l?[...o,...i.filter(m=>!s.has(m))].filter(m=>u.has(m)||!Ee(m.giaInfoIndex)):i.filter(m=>!Ee(m.giaInfoIndex));if(p.length&&h+p.length-1>2147483647)throw new Error("\u5BA2\u6237\u7AEF\u8D44\u4EA7\u7F16\u53F7\u7A7A\u95F4\u5DF2\u8017\u5C3D");for(let m of p)m.giaInfoIndex=h++,m.giaInfoIndexSource="authoring";e.meta.giaNextAssetIndex=h,e.meta.giaAssetIndexSchemaVersion=1,u.size&&t.push(`\u65E7\u5BA2\u6237\u7AEF\u8D44\u4EA7\u7F16\u53F7\u81EA\u52A8\u8FC1\u79FB\uFF1A\u4FEE\u590D ${u.size} \u6761\u6309\u63A7\u4EF6\u7C7B\u578B\u590D\u7528\u7684\u7F16\u53F7\uFF1BGUID\u3001Lua \u5F15\u7528\u548C\u63A7\u4EF6\u5C5E\u6027\u4FDD\u6301\u4E0D\u53D8\u3002`)}var Dr=1;function zr(e="n"){let t=`${e}${Dr}`;return Dr+=1,t}function Di(e=1){Dr=e}function $r(e,{isRootContainer:t=!1}={}){if(e==="server-container"||e==="fullscreen"||e==="container"&&t)return Fi({layout:"stretch"});let i=pa[e]||[80,80];return Fi({layout:"center",size:i})}function Gl(e,t){return Ca(()=>$r(e,t))}function Vl(e){Je(e);let t={};for(let i of ce)t[i]=ft(e,i);return t}function q(e,t={}){if(!Et[e])throw new Error(`unknown kind: ${e}`);Object.hasOwn(t,"transformByCanvas")&&ut(t);let i=t.isRootContainer===!0,r=t.id||zr(e==="server-container"?"sc":"n"),n=Object.hasOwn(t,"transformByPlatform")?Vl(t.transformByPlatform):Gl(e,{isRootContainer:i}),a={id:r,kind:e,name:t.name||Et[e],guid:t.guid??0,giaRelatedGuids:Array.isArray(t.giaRelatedGuids)?t.giaRelatedGuids.filter(o=>Number.isSafeInteger(Number(o))&&Number(o)>0).map(Number):[],...Ee(Number(t.giaInfoIndex))?{giaInfoIndex:Number(t.giaInfoIndex),giaInfoIndexSource:t.giaInfoIndexSource==="authoring"?"authoring":"imported"}:{},active:t.active!==!1,visible:t.visible!==!1,canControllerFocus:t.canControllerFocus??t.giaRaw?.footerField505===1,syncAllDevices:t.syncAllDevices!==!1,giaRaw:_a(e,t.giaRaw),transformByPlatform:n,children:[],scriptMappingIds:Array.isArray(t.scriptMappingIds)?t.scriptMappingIds.filter(o=>Number.isSafeInteger(Number(o))&&Number(o)>0).map(Number):[]};if(e==="container"&&(a.isolateNavigation=t.isolateNavigation===!0,a.disableKeyEventPassthrough=t.disableKeyEventPassthrough===!0,a.disableCursorEventPassthrough=t.disableCursorEventPassthrough===!0,a.showCursor=t.showCursor===!0),(e==="textbox"||e==="textwindow")&&(a.fontSize=t.fontSize??20,a.adaptiveFontSize=t.adaptiveFontSize===!0,a.minimumFontSize=t.minimumFontSize??20,a.fontColor=t.fontColor??Zt.font,a.bgColor=t.bgColor??Zt.bg,a.enableOutline=t.enableOutline!==!1,a.outlineColor=t.outlineColor??Zt.outline,a.horizontalAlignment=t.horizontalAlignment||"Left",a.verticalAlignment=t.verticalAlignment||"Top",Number.isInteger(t.giaRaw?.textVerticalAlign)&&![0,1,2].includes(t.giaRaw.textVerticalAlign)&&(a.giaRaw.textVerticalAlign=t.giaRaw.textVerticalAlign),a.text=t.text??"",Object.hasOwn(t.giaRaw||{},"textAlign")||(a.giaRaw.textAlign={Left:0,Middle:1,Right:2}[a.horizontalAlignment]??a.giaRaw.textAlign),e==="textwindow"&&(a.interactable=t.interactable!==!1,a.showScrollBar=t.showScrollBar!==!1)),e==="image"&&(a.imageSource=t.imageSource||"StaticReference",a.imageType=["Basic","Stretch"].includes(t.imageType)?t.imageType:null,a.imageId=t.imageId??100001,a.imageColor=t.imageColor??Zt.image,a.enableMask=t.enableMask===!0,a.enableSoftEdge=t.enableSoftEdge===!0,a.softEdgeMode=t.softEdgeMode||"Percentage",a.softEdgeWidthX=t.softEdgeWidthX??8,a.softEdgeWidthY=t.softEdgeWidthY??8,a.horizontalSoftRange=t.horizontalSoftRange??85,a.verticalSoftRange=t.verticalSoftRange??85,a.enableFill=t.enableFill===!0,a.fillType=t.fillType||"Horizontal",a.fillHorizontalType=t.fillHorizontalType||"Left",a.fillVerticalType=t.fillVerticalType||"Bottom",a.fillRadial90Type=t.fillRadial90Type||"BottomLeft",a.fillRadialType=t.fillRadialType||"Bottom",a.fillAmount=t.fillAmount??1,a.reverseMaskArea=t.reverseMaskArea===!0||t.reverseMask===!0,Object.hasOwn(t.giaRaw||{},"imageFillType")||(a.giaRaw.imageFillType={Horizontal:1,Vertical:2,Radial90:3,Radial180:4,Radial360:5}[a.fillType]??a.giaRaw.imageFillType)),e==="button"&&(a.raycastTarget=t.raycastTarget!==!1,a.interactable=t.interactable!==!1,a.clickAudioId=t.clickAudioId??ga,a.unavailableChildId=t.unavailableChildId??null,a.hoverChildId=t.hoverChildId??null,a.pressedChildId=t.pressedChildId??null,a.selectedChildId=t.selectedChildId??null),e==="cursor"&&(a.raycastTarget=t.raycastTarget??t.giaRaw?.cursorField501!==0),e==="reference"&&(a.referencedPrefabId=t.referencedPrefabId??t.giaRaw?.templateRefSlot??null,Object.hasOwn(t.giaRaw||{},"templateRefSlot")||(a.giaRaw.templateRefSlot=String(a.referencedPrefabId??""))),e==="grid"&&(a.itemPrefabId=t.itemPrefabId??null,a.raycastTarget=t.raycastTarget!==!1,a.interactable=t.interactable!==!1,a.showScrollBar=t.showScrollBar!==!1,a.scrollDirection=t.scrollDirection||"Vertical",a.layoutConstraint=t.layoutConstraint||"AutoWrap",a.layoutConstraintFixedCount=t.layoutConstraintFixedCount??null,a.cellSizeX=t.cellSizeX??50,a.cellSizeY=t.cellSizeY??50,a.spacingX=t.spacingX??8,a.spacingY=t.spacingY??8,a.padding1X=t.padding1X??20,a.padding1Y=t.padding1Y??20,a.padding2X=t.padding2X??20,a.padding2Y=t.padding2Y??20,a.previewCount=t.previewCount??t.giaRaw?.gridField511??5,Object.hasOwn(t.giaRaw||{},"gridField511")||(a.giaRaw.gridField511=Math.trunc(a.previewCount))),e==="keyhint"&&(a.keyboardKeyCode=t.keyboardKeyCode??t.giaRaw?.keyHintField502??null,a.controllerKeyCode=t.controllerKeyCode??t.giaRaw?.keyHintField501??null,Object.hasOwn(t.giaRaw||{},"keyHintField502")||(a.giaRaw.keyHintField502=Math.trunc(a.keyboardKeyCode??1)),Object.hasOwn(t.giaRaw||{},"keyHintField501")||(a.giaRaw.keyHintField501=Math.trunc(a.controllerKeyCode??1))),e==="animation"||e==="fullscreen"){let o=e==="animation"?t.giaRaw?.effectSlot:t.giaRaw?.fullscreenEffectSlot;a.animationId=t.animationId??o??null,a.playSoundEffect=t.playSoundEffect??null,e==="animation"&&(a.layer=t.layer??null);let s=e==="animation"?"effectSlot":"fullscreenEffectSlot";Object.hasOwn(t.giaRaw||{},s)||(a.giaRaw[s]=String(a.animationId??""))}if(t.children)for(let o of t.children)a.children.push(o);return a}function dt(){Di(1);let e=q("server-container",{id:"sc1",name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668"}),t=q("container",{id:"n1",name:"\u5BB9\u5668\u8282\u70B9",isRootContainer:!0}),i=q("textbox",{id:"n2",name:"\u6587\u672C\u6846",text:"\u6587\u672C"}),r=q("cursor",{id:"n3",name:"\u5149\u6807\u68C0\u6D4B\u533A\u57DF"}),n=q("reference",{id:"n4",name:"\u6A21\u677F\u5F15\u7528\u63A7\u4EF6"}),a=q("grid",{id:"n5",name:"\u7F51\u683C\u89C6\u7A97"}),o=q("button",{id:"n6",name:"\u9884\u8BBE\u6309\u94AE"}),s=q("textwindow",{id:"n7",name:"\u6587\u672C\u89C6\u7A97"}),c=q("keyhint",{id:"n8",name:"\u6309\u952E\u63D0\u793A"}),l=q("image",{id:"n9",name:"\u56FE\u7247",imageId:100005}),u=q("animation",{id:"n10",name:"\u754C\u9762\u52A8\u6548"}),d=q("fullscreen",{id:"n11",name:"\u5168\u5C4F\u52A8\u6548"}),h=(p,m,g)=>{for(let S of Object.values(p.transformByPlatform))S.offset={x:m,y:g}};return h(i,-300,250),h(r,-300,140),h(n,-300,30),h(a,-300,-100),h(o,0,0),h(s,300,250),h(c,300,140),h(l,300,30),h(u,300,-100),t.children.push(i,r,n,a,o,s,c,l,u,d),e.children.push(t),Di(12),Pa(e),{version:1,layoutSchemaVersion:pe,meta:{name:"\u672A\u547D\u540D\u754C\u9762\u63A7\u4EF6\u7EC4",assetType:"server-control-template",sourceFormat:"authoring",sourceFile:""},canvasId:"pc-16-9",selectedId:"n2",root:e}}function Rt(){Di(1);let e=q("server-container",{id:"sc1",name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"}),t=q("container",{id:"n1",guid:1073742100,name:"Lua\u5B9E\u4F8B\u5316\u9762\u677F"}),i=q("textbox",{id:"n2",guid:1073742101,name:"\u6A21\u677F\u6807\u9898",text:"\u5BA2\u6237\u7AEF\u6A21\u677F\u5DF2\u5B9E\u4F8B\u5316",fontSize:28,horizontalAlignment:"Middle"}),r=q("image",{id:"n3",guid:1073742102,name:"\u6A21\u677F\u56FE\u6807",imageId:100005}),n=q("button",{id:"n4",guid:1073742103,name:"\u786E\u8BA4\u6309\u94AE"}),a=q("textbox",{id:"n5",guid:1073742104,name:"\u6309\u94AE\u6587\u5B57",text:"\u786E\u8BA4",horizontalAlignment:"Middle",verticalAlignment:"Top"}),o=(l,u,d)=>{for(let h of Object.values(l.transformByPlatform))h.offset={x:u,y:d}};((l,u,d)=>{for(let h of Object.values(l.transformByPlatform))h.size={x:u,y:d}})(t,520,320),o(i,0,110),o(r,0,0),o(n,0,-110),n.children.push(a),t.children.push(i,r,n),e.children.push(t),Di(6);let c={version:1,layoutSchemaVersion:pe,meta:{name:"Lua\u5B9E\u4F8B\u5316\u9762\u677F",assetType:"client-control-template",sourceFormat:"authoring",sourceFile:"",gameVersion:Ri,giaOwnerUid:114514,giaFileId:1073741829,giaFileName:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868.gia"},canvasId:"pc-16-9",selectedId:"n1",root:e};return He(c),c}function Q(e,t,i=null){t(e,i);for(let r of e.children||[])Q(r,t,e)}function fe(e,t){let i=null;return Q(e,r=>{r.id===t&&(i=r)}),i}function Gr(e,t="n"){let i=zr(t);for(;fe(e,i);)i=zr(t);return i}function Qe(e,t){let i=null;return Q(e,(r,n)=>{r.id===t&&(i=n)}),i}function Vr(e){let t=e.root||e;return t.kind==="container"?t:(t.children||[]).find(i=>i.kind==="container")||(t.children||[])[0]||t}function ii(e){if(e.meta?.assetType!=="client-control-template")return Vr(e);let t=fe(e.root,e.selectedId);if(!t||t.kind==="server-container")return e.root.children?.[0]||e.root;let i=Qe(e.root,t.id);for(;i&&i.kind!=="server-container";)t=i,i=Qe(e.root,t.id);return t}function Yr(e){ut(e);let t={id:e.id,name:e.name,guid:e.guid,giaRelatedGuids:e.giaRelatedGuids,giaInfoIndex:e.giaInfoIndex,giaInfoIndexSource:e.giaInfoIndexSource,scriptMappingIds:e.scriptMappingIds,giaRaw:e.giaRaw,active:e.active,visible:e.visible,canControllerFocus:e.canControllerFocus,syncAllDevices:e.syncAllDevices,transformByPlatform:e.transformByPlatform};e.kind==="container"&&(t.isolateNavigation=e.isolateNavigation,t.disableKeyEventPassthrough=e.disableKeyEventPassthrough,t.disableCursorEventPassthrough=e.disableCursorEventPassthrough,t.showCursor=e.showCursor),(e.kind==="textbox"||e.kind==="textwindow")&&(t.fontSize=e.fontSize,t.adaptiveFontSize=e.adaptiveFontSize,t.minimumFontSize=e.minimumFontSize,t.fontColor=e.fontColor,t.bgColor=e.bgColor,t.enableOutline=e.enableOutline,t.outlineColor=e.outlineColor,t.horizontalAlignment=e.horizontalAlignment,t.verticalAlignment=e.verticalAlignment,t.text=e.text??"",e.kind==="textwindow"&&(t.interactable=e.interactable,t.showScrollBar=e.showScrollBar)),e.kind==="image"&&(t.imageSource=e.imageSource,t.imageType=e.imageType,t.imageId=e.imageId,t.imageColor=e.imageColor,t.enableMask=e.enableMask,t.enableSoftEdge=e.enableSoftEdge,t.softEdgeMode=e.softEdgeMode,t.softEdgeWidthX=e.softEdgeWidthX,t.softEdgeWidthY=e.softEdgeWidthY,t.horizontalSoftRange=e.horizontalSoftRange,t.verticalSoftRange=e.verticalSoftRange,t.enableFill=e.enableFill,t.fillType=e.fillType,t.fillHorizontalType=e.fillHorizontalType,t.fillVerticalType=e.fillVerticalType,t.fillRadial90Type=e.fillRadial90Type,t.fillRadialType=e.fillRadialType,t.fillAmount=e.fillAmount,t.reverseMaskArea=e.reverseMaskArea??e.reverseMask),e.kind==="button"&&(t.raycastTarget=e.raycastTarget,t.interactable=e.interactable,t.clickAudioId=e.clickAudioId,t.unavailableChildId=e.unavailableChildId??null,t.hoverChildId=e.hoverChildId??null,t.pressedChildId=e.pressedChildId??null,t.selectedChildId=e.selectedChildId??null),e.kind==="cursor"&&(t.raycastTarget=e.raycastTarget),e.kind==="reference"&&(t.referencedPrefabId=e.referencedPrefabId??null),e.kind==="grid"&&(t.itemPrefabId=e.itemPrefabId??null,t.raycastTarget=e.raycastTarget,t.interactable=e.interactable,t.showScrollBar=e.showScrollBar,t.scrollDirection=e.scrollDirection,t.layoutConstraint=e.layoutConstraint,t.layoutConstraintFixedCount=e.layoutConstraintFixedCount??null,t.cellSizeX=e.cellSizeX,t.cellSizeY=e.cellSizeY,t.spacingX=e.spacingX,t.spacingY=e.spacingY,t.padding1X=e.padding1X,t.padding1Y=e.padding1Y,t.padding2X=e.padding2X,t.padding2Y=e.padding2Y,t.previewCount=e.previewCount),e.kind==="keyhint"&&(t.keyboardKeyCode=e.keyboardKeyCode??null,t.controllerKeyCode=e.controllerKeyCode??null),(e.kind==="animation"||e.kind==="fullscreen")&&(t.animationId=e.animationId??null,t.playSoundEffect=e.playSoundEffect??null,e.kind==="animation"&&(t.layer=e.layer??null)),t.isRootContainer=e.kind==="container"&&Yl(e.transformByPlatform);let i=q(e.kind,t);return i.children=(e.children||[]).map(r=>Yr(r)),i}function Yl(e){let t=e&&(e.KEYBOARD||Object.values(e)[0]);return t?Math.abs(t.anchorMin?.x??.5)<1e-4&&Math.abs(t.anchorMin?.y??.5)<1e-4&&Math.abs((t.anchorMax?.x??.5)-1)<1e-4&&Math.abs((t.anchorMax?.y??.5)-1)<1e-4:!1}function Ta(e,t,i={}){if(e.kind==="server-container"&&t!=="container")throw new Error("server container only accepts container nodes");let r=q(t,i);return e.children.push(r),r}function Ra(e,t){if(e.id===t)throw new Error("cannot remove root");let i=Qe(e,t);if(!i)return!1;let r=i.children.findIndex(n=>n.id===t);return r<0?!1:(i.children.splice(r,1),!0)}var Ma=1e-4;function Bl(e,t){return Math.abs(e.anchorMax[t]-e.anchorMin[t])>Ma&&Math.abs(e.size[t])<=Ma}function jl(e,t,i){if(!(t.width>0)||!(t.height>0))throw new Error("source parent must have positive size");if(!(i.width>0)||!(i.height>0))throw new Error("target parent must have positive size");let r=Be(t,e),n=(r.centerX-t.left)/t.width,a=(r.centerY-t.bottom)/t.height,o=lt(i,e,{posX:i.left+n*i.width,posY:i.bottom+a*i.height,width:r.width,height:r.height});for(let s of["x","y"])Bl(e,s)&&(o.offset[s]=e.offset[s],o.size[s]=e.size[s]);return o}function Na({transformByPlatform:e,source:t,canvasId:i,syncAllDevices:r,sourceParentBox:n=ye(i),targetParentBoxByPlatform:a={}}){Je(e);let o=ct(i),s={};for(let c of ce)c===o?s[c]=$e(t):r!==!1?s[c]=jl(t,n,a[c]||ye(kt[c])):s[c]=ft(e,c);return Je(s),s}function et(e,t){return ft(e,ct(t))}function Oa(e,t){let i=[];function r(n){t[n.id]&&i.push(t[n.id]);let a=n.children||[];for(let o=a.length-1;o>=0;o-=1)r(a[o])}return r(e),i}function tt(e,t,i=ct(t)){let r=ye(t),n={};function a(o,s,c){let l=ft(o.transformByPlatform,i),u=Be(s,l),d=o.kind==="server-container"?c:ti(c,u,l),h=wa(u,d);n[o.id]={...u,...Nr(u),id:o.id,kind:o.kind,name:o.name,visible:o.visible!==!1,active:o.active!==!1,rotationZ:l.rotation.z,renderLeft:h.left,renderBottom:h.bottom,renderWidth:h.width,renderHeight:h.height,renderRotationZ:h.rotationZ,renderMatrix:d,primitive:o.kind==="image"?At(o.imageId,o.imageSource):null,...o.kind==="textbox"||o.kind==="textwindow"?{text:o.text??"",fontSize:o.fontSize,fontColor:o.fontColor,bgColor:o.bgColor,enableOutline:o.enableOutline!==!1,outlineColor:o.outlineColor,horizontalAlignment:o.horizontalAlignment,verticalAlignment:o.verticalAlignment}:{},...o.kind==="image"?{imageSource:o.imageSource,imageType:o.imageType??null,imageId:o.imageId,imageColor:o.imageColor,enableMask:o.enableMask===!0,enableSoftEdge:o.enableSoftEdge===!0,softEdgeMode:o.softEdgeMode,softEdgeWidthX:o.softEdgeWidthX,softEdgeWidthY:o.softEdgeWidthY,horizontalSoftRange:o.horizontalSoftRange,verticalSoftRange:o.verticalSoftRange,enableFill:o.enableFill===!0,fillType:o.fillType,fillHorizontalType:o.fillHorizontalType,fillVerticalType:o.fillVerticalType,fillRadial90Type:o.fillRadial90Type,fillRadialType:o.fillRadialType,fillAmount:o.fillAmount,reverseMaskArea:o.reverseMaskArea===!0}:{},...o.kind==="button"?{raycastTarget:o.raycastTarget!==!1,interactable:o.interactable!==!1,clickAudioId:o.clickAudioId,unavailableChildId:o.unavailableChildId??null,hoverChildId:o.hoverChildId??null,pressedChildId:o.pressedChildId??null,selectedChildId:o.selectedChildId??null}:{}};let p=o.kind==="server-container"?s:u;for(let m of o.children||[])a(m,p,d)}return a(e,r,Pt()),{canvas:r,boxes:n}}function Br(e,t){let i=[];function r(n,a,o=null,s=[],c=0,l=1,u=e.id){i.push({id:n.id,guid:t?.get(n.id)??(n.guid||0),kind:n.kind,name:n.name,label:Et[n.kind]||n.kind,depth:a,parentId:o,ancestorIds:s,siblingIndex:c,siblingCount:l,templateId:u,childCount:(n.children||[]).length,incomplete:!Ni.includes(n.kind)});let d=n.children||[];for(let h=0;h<d.length;h+=1)r(d[h],a+1,n.id,[...s,n.id],h,d.length,u)}return r(e,0),i}function T(e,t,i,r,n={}){return{key:e,label:t,type:i,value:r,...n}}function Fa(e,t,i,r){if(!e)return null;let n=et(e.transformByPlatform,t),a=Nr(i),o=[T("name","\u540D\u79F0","string",e.name),T("active","\u521D\u59CB\u6FC0\u6D3B","bool",e.active!==!1),T("visible","\u521D\u59CB\u53EF\u89C1\u6027","bool",e.visible!==!1),T("canControllerFocus","\u53EF\u88AB\u624B\u67C4\u6447\u6746\u5BFC\u822A\u9009\u4E2D","bool",e.canControllerFocus===!0),T("posX","\u4F4D\u7F6E X","number",a.posX,{computed:!0}),T("posY","\u4F4D\u7F6E Y","number",a.posY,{computed:!0}),T("width","\u5927\u5C0F W","number",a.width,{computed:!0}),T("height","\u5927\u5C0F H","number",a.height,{computed:!0}),T("rotationZ","\u65CB\u8F6C Z","number",n.rotation.z),T("syncAllDevices","\u540C\u6B65\u4FE1\u606F\u81F3\u6240\u6709\u8BBE\u5907","bool",e.syncAllDevices!==!1),T("anchorType","\u951A\u70B9\u7C7B\u578B","enum",xa(n),{options:[{value:"center",label:"\u5C45\u4E2D"},{value:"top-left",label:"\u5DE6\u4E0A"},{value:"top",label:"\u4E0A\u65B9"},{value:"top-right",label:"\u53F3\u4E0A"},{value:"left",label:"\u5DE6\u4FA7"},{value:"right",label:"\u53F3\u4FA7"},{value:"bottom-left",label:"\u5DE6\u4E0B"},{value:"bottom",label:"\u4E0B\u65B9"},{value:"bottom-right",label:"\u53F3\u4E0B"},{value:"stretch",label:"\u53CC\u5411\u62C9\u4F38"},{value:"stretch-horizontal",label:"\u6C34\u5E73\u62C9\u4F38"},{value:"stretch-vertical",label:"\u5782\u76F4\u62C9\u4F38"},{value:"custom",label:"\u81EA\u5B9A\u4E49"}]}),T("anchorMinX","\u951A\u70B9 Min X","number",n.anchorMin.x),T("anchorMinY","\u951A\u70B9 Min Y","number",n.anchorMin.y),T("anchorMaxX","\u951A\u70B9 Max X","number",n.anchorMax.x),T("anchorMaxY","\u951A\u70B9 Max Y","number",n.anchorMax.y),T("pivotX","\u4E2D\u5FC3 X","number",n.pivot.x),T("pivotY","\u4E2D\u5FC3 Y","number",n.pivot.y)];if(e.kind==="container"&&o.push(T("isolateNavigation","\u9694\u79BB\u624B\u67C4\u5BFC\u822A","bool",e.isolateNavigation===!0),T("disableKeyEventPassthrough","\u5C4F\u853D\u6309\u952E\u4E8B\u4EF6\u7A7F\u900F","bool",e.disableKeyEventPassthrough===!0),T("disableCursorEventPassthrough","\u5C4F\u853D\u533A\u57DF\u5185\u70B9\u51FB\u4E8B\u4EF6\u7A7F\u900F","bool",e.disableCursorEventPassthrough===!0),T("showCursor","\u663E\u793A\u5E38\u9A7B\u5149\u6807","bool",e.showCursor===!0)),e.kind==="textbox"||e.kind==="textwindow"){let s=e.giaRaw?.textAlign,c=[0,1,2].includes(s)?e.horizontalAlignment||"Left":`__unrecognized:${s}`;o.push(T("fontSize","\u5B57\u53F7","number",e.fontSize),T("adaptiveFontSize","\u5B57\u53F7\u81EA\u9002\u5E94","bool",e.adaptiveFontSize===!0),T("minimumFontSize","\u6700\u5C0F\u5B57\u53F7","number",e.minimumFontSize),T("fontColor","\u6587\u672C\u8272","color",e.fontColor),T("bgColor","\u80CC\u666F\u8272","color",e.bgColor),T("enableOutline","\u542F\u7528\u63CF\u8FB9","bool",e.enableOutline!==!1),T("outlineColor","\u63CF\u8FB9\u8272","color",e.outlineColor),T("horizontalAlignment","\u6C34\u5E73\u5BF9\u9F50","enum",c,{...[0,1,2].includes(s)?{}:{unknownValue:s},options:[{value:"Left",label:"\u5DE6\u5BF9\u9F50"},{value:"Middle",label:"\u5C45\u4E2D"},{value:"Right",label:"\u53F3\u5BF9\u9F50"}]}),T("verticalAlignment","\u5782\u76F4\u5BF9\u9F50","enum",e.verticalAlignment||"Top",{options:[{value:"Top",label:"\u9876\u90E8"},{value:"Middle",label:"\u5C45\u4E2D"},{value:"Bottom",label:"\u5E95\u90E8"}]}),T("text","\u6587\u672C","text",e.text??""))}if(e.kind==="image"){let s=e.giaRaw?.imageFillType,c=[1,2,3,4,5].includes(s)?e.fillType:`__unrecognized:${s}`;o.push(T("imageSource","\u56FE\u7247\u6E90","enum",e.imageSource,{options:[{value:"StaticReference",label:"\u9759\u6001\u5F15\u7528"},{value:"Prefab",label:"\u5143\u4EF6"}]}),T("imageId","imageId","number",e.imageId??0),T("imageType","\u56FE\u7247\u7C7B\u578B","enum",e.imageType??null,{options:[{value:"Basic",label:"\u57FA\u7840"},{value:"Stretch",label:"\u62C9\u4F38"}]}),T("imageColor","\u586B\u5145\u8272","color",e.imageColor),T("enableMask","\u5F00\u542F\u906E\u7F69","bool",e.enableMask===!0),T("enableSoftEdge","\u8FB9\u7F18\u7FBD\u5316","bool",e.enableSoftEdge===!0,{gia:"W"}),T("softEdgeMode","\u7FBD\u5316\u6A21\u5F0F","enum",e.softEdgeMode,{options:[{value:"Percentage",label:"\u767E\u5206\u6BD4"},{value:"Pixel",label:"\u50CF\u7D20"}]}),T("softEdgeWidthX","\u7FBD\u5316\u5BBD\u5EA6 X","number",e.softEdgeWidthX),T("softEdgeWidthY","\u7FBD\u5316\u5BBD\u5EA6 Y","number",e.softEdgeWidthY),T("horizontalSoftRange","\u6C34\u5E73\u7FBD\u5316\u8303\u56F4","number",e.horizontalSoftRange),T("verticalSoftRange","\u5782\u76F4\u7FBD\u5316\u8303\u56F4","number",e.verticalSoftRange),T("enableFill","\u6309\u8FDB\u5EA6\u586B\u5145","bool",e.enableFill===!0,{gia:"W"}),T("fillType","\u5F62\u72B6","enum",c,{...[1,2,3,4,5].includes(s)?{}:{unknownValue:s},options:[{value:"Horizontal",label:"\u6A2A\u5411"},{value:"Vertical",label:"\u7EB5\u5411"},{value:"Radial90",label:"90\u5EA6\u73AF\u7ED5"},{value:"Radial180",label:"180\u5EA6\u73AF\u7ED5"},{value:"Radial360",label:"360\u5EA6\u73AF\u7ED5"}]}),T("fillHorizontalType","\u65B9\u5411","enum",e.fillHorizontalType,{options:[{value:"Left",label:"\u4ECE\u5DE6\u81F3\u53F3"},{value:"Right",label:"\u4ECE\u53F3\u81F3\u5DE6"}]}),T("fillVerticalType","\u65B9\u5411","enum",e.fillVerticalType,{options:[{value:"Bottom",label:"\u4ECE\u4E0B\u81F3\u4E0A"},{value:"Top",label:"\u4ECE\u4E0A\u81F3\u4E0B"}]}),T("fillRadial90Type","\u8D77\u70B9","enum",e.fillRadial90Type,{options:[{value:"BottomLeft",label:"\u5DE6\u4E0B"},{value:"TopLeft",label:"\u5DE6\u4E0A"},{value:"TopRight",label:"\u53F3\u4E0A"},{value:"BottomRight",label:"\u53F3\u4E0B"}]}),T("fillRadialType","\u8D77\u70B9","enum",e.fillRadialType,{options:[{value:"Bottom",label:"\u4E0B\u65B9"},{value:"Left",label:"\u5DE6\u4FA7"},{value:"Top",label:"\u4E0A\u65B9"},{value:"Right",label:"\u53F3\u4FA7"}]}),T("fillAmount","\u8FDB\u5EA6","percent",e.fillAmount),T("reverseMaskArea","\u906E\u7F69\u533A\u57DF\u53CD\u8F6C","bool",e.reverseMaskArea===!0,{gia:"W"}))}if(e.kind==="button"){let s=[{value:"",label:"\u672A\u8BBE\u7F6E"},...(e.children||[]).map(c=>({value:c.id,label:`${c.name} \xB7 ${c.id}`}))];o.push(T("raycastTarget","\u53EF\u88AB\u5149\u6807\u5C04\u7EBF\u68C0\u6D4B","bool",e.raycastTarget!==!1),T("interactable","\u6309\u94AE\u662F\u5426\u53EF\u7528","bool",e.interactable!==!1),T("unavailableChildId","\u4E0D\u53EF\u7528\u72B6\u6001\u8282\u70B9","node",e.unavailableChildId,{options:s,gia:"W"}),T("hoverChildId","\u60AC\u505C\u72B6\u6001\u8282\u70B9","node",e.hoverChildId,{options:s,gia:"W"}),T("pressedChildId","\u6309\u4E0B\u72B6\u6001\u8282\u70B9","node",e.pressedChildId,{options:s,gia:"W"}),T("selectedChildId","\u9009\u4E2D\u72B6\u6001\u8282\u70B9","node",e.selectedChildId,{options:s,gia:"W"}),T("clickAudioId","\u70B9\u51FB\u97F3\u6548","number",e.clickAudioId))}return e.kind==="reference"&&o.push(T("referencedPrefabId","\u5F15\u7528\u63A7\u4EF6\u6A21\u677F\u7D22\u5F15","string",e.referencedPrefabId??"")),(e.kind==="textwindow"||e.kind==="grid")&&o.push(T("interactable","\u5141\u8BB8\u6EDA\u52A8\u4EA4\u4E92","bool",e.interactable!==!1),T("showScrollBar","\u663E\u793A\u6EDA\u52A8\u6761","bool",e.showScrollBar!==!1)),e.kind==="grid"&&o.push(T("itemPrefabId","\u5217\u8868\u9879\u6A21\u677F\u7D22\u5F15","number",e.itemPrefabId??0),T("raycastTarget","\u53EF\u88AB\u5149\u6807\u5C04\u7EBF\u68C0\u6D4B","bool",e.raycastTarget!==!1),T("scrollDirection","\u6EDA\u52A8\u65B9\u5411","enum",e.scrollDirection,{options:[{value:"Vertical",label:"\u7EB5\u5411"},{value:"Horizontal",label:"\u6A2A\u5411"}]}),T("layoutConstraint","\u6392\u5217\u9650\u5236","enum",e.layoutConstraint,{options:[{value:"AutoWrap",label:"\u81EA\u52A8\u6362\u884C"},{value:"Fixed",label:"\u56FA\u5B9A\u884C\u5217\u6570"}]}),T("layoutConstraintFixedCount","\u6BCF\u884C\u6216\u6BCF\u5217\u6570\u91CF","number",e.layoutConstraintFixedCount??1),T("cellSizeX","\u5217\u8868\u9879\u5927\u5C0F W","number",e.cellSizeX,{evidence:"W"}),T("cellSizeY","\u5217\u8868\u9879\u5927\u5C0F H","number",e.cellSizeY,{evidence:"W"}),T("spacingX","\u5217\u8868\u9879\u95F4\u9694 X","number",e.spacingX,{evidence:"W"}),T("spacingY","\u5217\u8868\u9879\u95F4\u9694 Y","number",e.spacingY,{evidence:"W"}),T("padding1X","\u8FB9\u8DDD\u5411\u91CF 1 X","number",e.padding1X,{evidence:"W"}),T("padding1Y","\u8FB9\u8DDD\u5411\u91CF 1 Y","number",e.padding1Y,{evidence:"W"}),T("padding2X","\u8FB9\u8DDD\u5411\u91CF 2 X","number",e.padding2X,{evidence:"W"}),T("padding2Y","\u8FB9\u8DDD\u5411\u91CF 2 Y","number",e.padding2Y,{evidence:"W"}),T("previewCount","\u9884\u89C8\u6570\u91CF","number",e.previewCount)),e.kind==="keyhint"&&o.push(T("keyboardKeyCode","\u952E\u9F20\u6309\u952E","number",e.keyboardKeyCode??e.giaRaw?.keyHintField502??1,{gia:"W"}),T("controllerKeyCode","\u624B\u67C4\u6309\u952E","number",e.controllerKeyCode??e.giaRaw?.keyHintField501??1)),(e.kind==="animation"||e.kind==="fullscreen")&&o.push(T("animationId",e.kind==="animation"?"\u52A8\u6548\u7D22\u5F15":"\u5168\u5C4F\u52A8\u6548\u7D22\u5F15","string",e.animationId??"")),(!Ni.includes(e.kind)||e.kind==="textwindow"||e.kind==="grid")&&o.push(T("incomplete","\u5B8C\u6574\u5EA6","note",e.kind==="textwindow"||e.kind==="grid"?"\u8BD5\u73A9\u652F\u6301\u57FA\u7840\u6EDA\u52A8\uFF1B\u6EDA\u52A8\u4EA4\u4E92\u3001\u6EDA\u52A8\u6761\u53CA\u5217\u8868\u914D\u7F6E\u4EE5 JSON/Lua \u4E3A\u51C6\uFF0C\u76F8\u5173 GIA \u5F00\u5173\u6620\u5C04\u5C1A\u672A\u6838\u5B9E\u3002":"\u672C\u9636\u6BB5\u4EC5\u516C\u5171\u53D8\u6362\uFF0C\u4E1A\u52A1\u69FD\u4E0D\u5B8C\u6574")),{id:e.id,guid:r?.get(e.id)??(e.guid||0),kind:e.kind,label:Et[e.kind]||e.kind,incomplete:!Ni.includes(e.kind),fields:o}}function Da(e,t,i){let r=(Array.isArray(e)?e:Object.values(e)).filter(n=>n.kind!=="server-container");for(let n=r.length-1;n>=0;n-=1){let a=r[n];if(!a.visible||!a.active)continue;let o=a.renderMatrix&&je(a.renderMatrix),s=o&&xe(o,t,i);if(s&&s.x>=a.left&&s.x<=a.right&&s.y>=a.bottom&&s.y<=a.top)return a.id}return null}import Hl from"protobufjs";var Ul=String.raw`
|
|
3
3
|
syntax = "proto3";
|
|
4
4
|
// Root.graph is singular in the game's canonical schema, but template-list
|
|
5
5
|
// assets legally emit field 1 more than once. Model it as repeated here so
|
|
@@ -91,7 +91,7 @@ message ButtonPresetConfig {
|
|
|
91
91
|
int32 raycastTarget = 507;
|
|
92
92
|
}
|
|
93
93
|
message KeyHintConfig { int32 field501 = 501; int32 field502 = 502; }
|
|
94
|
-
message ImageSlotConfig { uint32 field502 = 502; uint32 assetId = 503; }
|
|
94
|
+
message ImageSlotConfig { uint32 field502 = 502; uint32 assetId = 503; int32 imageType = 504; }
|
|
95
95
|
message ImageConfig {
|
|
96
96
|
int32 enableMask = 501; int32 field502 = 502; int32 field504 = 504; int32 field505 = 505;
|
|
97
97
|
int32 field507 = 507; int32 field508 = 508; int32 enableSoftEdge = 509; int32 softEdgePixel = 510;
|
|
@@ -100,21 +100,21 @@ message ImageConfig {
|
|
|
100
100
|
message SliceVector { float field501 = 501; float field502 = 502; }
|
|
101
101
|
}
|
|
102
102
|
message FooterSlot { int32 field505 = 505; }
|
|
103
|
-
`,{root:Il}=wl.parse(Sl,{keepCase:!1}),Ee=Il.lookupType("Root"),Ke=20,Tr=4,So=806,Io=1657,Zt={image:23,"server-container":24,container:25,grid:26,reference:27,button:28,animation:29,fullscreen:30,textbox:31,textwindow:32,cursor:33,keyhint:34},Co={"server-container":1,container:2,textbox:3,cursor:4,reference:5,grid:6,button:7,textwindow:8,keyhint:9,image:10,animation:11,fullscreen:12},xo={KEYBOARD:0,TOUCHSCREEN:1,CONTROLLER_CONSOLE:2,CONTROLLER_MOBILE:3},Cl="server-control-template",Pi="client-control-template";function _i(e,t){let i=Number(e);return Number.isFinite(i)?i:t}var xl=Object.fromEntries(Object.entries(xo).map(([e,t])=>[t,e])),ko=Object.freeze({container:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["68/91","empty78","containerNodeSlot"],["67/90","empty77","footerSlot"]],textbox:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["64/84","empty74","textConfig"],["67/90","empty77","footerSlot"]],cursor:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["65/85","empty75","cursorConfig"],["67/90","empty77","footerSlot"]],reference:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["66/89","empty76","templateRefSlot"],["67/90","empty77","footerSlot"]],grid:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["69/92","empty79","gridView"],["67/90","empty77","footerSlot"]],button:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["70/93","empty80","buttonPreset"],["67/90","empty77","footerSlot"]],textwindow:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["71/94","empty81","textConfig"],["67/90","empty77","footerSlot"]],keyhint:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["72/95","empty82","keyHint"],["67/90","empty77","footerSlot"]],image:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["73/96","empty83","imageSlot"],["74/97","empty84","image"],["67/90","empty77","footerSlot"]],animation:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["75/98","empty85","effectSlot"],["67/90","empty77","footerSlot"]],fullscreen:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["76/99","empty86","fullscreenEffectSlot"],["67/90","empty77","footerSlot"]]}),Eo=Object.freeze({"4/23":5,"4/86":5,"1/12":4,"62/82":64,"63/83":65,"64/84":66,"65/85":67,"66/89":68,"67/90":69,"68/91":70,"69/92":71,"70/93":72,"71/94":66,"72/95":74,"73/96":75,"74/97":76,"75/98":77,"76/99":78}),kl=Object.freeze([["2/15","name",null],["4/23","field14","field14"],["1/12","transform","transform"],["62/82","empty72","rootChildRef"]]);function Mr(e){return{class:1,type:8,id:e}}function ei(e,t,i,r){return{...r,field501:t,field502:i,field503:1,nodeRef:Mr(e)}}function El(e){let t=[],i=e.meta?.assetType==="client-control-template";return J(e.root,r=>{i&&r.kind==="server-container"||t.push(r)}),t}function ti(e,t=new Set){let i=new Map,r=[];for(let n of El(e)){let o=Number(n.guid);ke(o)&&!t.has(o)?(t.add(o),n.guid=o,i.set(n.id,o)):r.push(n)}for(let n of r){let o=Ue(t);t.add(o),n.guid=o,i.set(n.id,o)}return i}function Al(e){return{scale:{x:e.scale.x,y:e.scale.y,z:e.scale.z},anchorMin:{x:e.anchorMin.x,y:e.anchorMin.y},anchorMax:{x:e.anchorMax.x,y:e.anchorMax.y},offset:{x:e.offset.x,y:e.offset.y},size:{x:e.size.x,y:e.size.y},pivot:{x:e.pivot.x,y:e.pivot.y},field508:e.rotation.z?{z:e.rotation.z}:{}}}function _l(e,t){let r={multiPlatform:{platforms:le.map(n=>({platformType:xo[n],transform:Al(e.transformByPlatform[n])})),field502:Zt[e.kind]||25,...e.syncAllDevices===!1?{}:{field504:1}},type:2};return{transform:{multiPlatform:{},type:2},field501:1,field502:12,details:ei(t,4,12,{transform:r})}}function Pl(e,t,i){let r=i?{empty15:"",field501:5}:{field17:{},field501:7},n=i?r:{...r,...e.visible===!1?{field17:{initiallyHidden:!0}}:{},...e.active===!1?{initiallyInactive:!0}:{}};return[{name:{value:e.name},field501:2,field502:15},{field14:r,field501:4,field502:i?23:86,details:ei(t,5,i?23:86,{field14:n})},_l(e,t)]}function Rl(e,t,i,r){let n=(l,u,h,d,g)=>({[h]:"",field501:l,field502:u,details:ei(t,l+2,u,{[d]:g})}),o=e.giaRaw||{},a=Array.isArray(e.scriptMappingIds)&&e.scriptMappingIds.length?{field501:o.genericField501||1,field502:e.scriptMappingIds.map(l=>({field1:{id:Number(l)}}))}:{field501:o.genericField501??0},s=n(63,83,"empty73","genericSlot",a),c=n(67,90,"empty77","footerSlot",{field505:[void 0,0,1].includes(o.footerField505)?e.canControllerFocus?1:0:o.footerField505});if(e.kind==="container")return[s,n(68,91,"empty78","containerNodeSlot",{...e.isolateNavigation?{isolateNavigation:!0}:{},...e.disableKeyEventPassthrough?{disableKeyEventPassthrough:!0}:{},...e.disableCursorEventPassthrough?{disableCursorEventPassthrough:!0}:{},...e.showCursor?{showCursor:!0}:{}}),c];if(e.kind==="textbox"||e.kind==="textwindow"){e.verticalAlignment==="Middle"&&r.push(`${e.name}: \u5782\u76F4\u5C45\u4E2D\u6309\u63A8\u5B9A\u503C\u5BFC\u51FA\uFF0C\u5C1A\u5F85\u5B9E\u673A\u786E\u8BA4\u3002`);let l={Left:0,Middle:1,Right:2}[e.horizontalAlignment]??0,u=Number.isFinite(o.textAlign)?Math.trunc(o.textAlign):l,h={field501:o.textField501??20,field503:o.textField503??12,color:e.fontColor>>>0,color2:e.bgColor>>>0,color3:e.outlineColor>>>0,text:{value:e.text||""},fontSize:Math.trunc(e.fontSize),minimumFontSize:Math.trunc(e.minimumFontSize),...e.adaptiveFontSize?{adaptive:1}:{},...e.enableOutline===!1?{outlineOff:1}:{},...u?{align:u}:{},verticalAlign:o.textVerticalAlign??{Top:0,Middle:1,Bottom:2}[e.verticalAlignment]??0};return e.kind==="textwindow"?((e.interactable===!1||e.showScrollBar===!1)&&r.push(`${e.name}: \u6587\u672C\u89C6\u7A97\u4EA4\u4E92/\u6EDA\u52A8\u6761\u5F00\u5173\u4EC5\u4FDD\u5B58\u5728 JSON\uFF0CGIA \u672A\u6620\u5C04\u8FD9\u4E9B\u6539\u52A8\u3002`),h.field511=o.textField511??1,h.viewFlags={field502:o.textViewField502??1,field503:o.textViewField503??1},[s,{empty81:"",field501:71,field502:94,details:ei(t,66,94,{textConfig:h})},c]):[s,n(64,84,"empty74","textConfig",h),c]}if(e.kind==="image"){let l={Horizontal:1,Vertical:2,Radial90:3,Radial180:4,Radial360:5}[e.fillType],u=Number.isFinite(o.imageFillType)?Math.trunc(o.imageFillType):l||1;e.enableFill&&!u&&r.push(`${e.name}: \u586B\u5145\u5F62\u72B6\u539F\u59CB\u679A\u4E3E\u4E3A 0\uFF0C\u5DF2\u5173\u95ED\u5BFC\u51FA\u6587\u4EF6\u4E2D\u7684\u8FDB\u5EA6\u586B\u5145\u3002`),e.fillType==="Horizontal"&&e.fillHorizontalType!=="Left"&&r.push(`${e.name}: \u5F53\u524D\u6A2A\u5411\u586B\u5145\u65B9\u5411\u6682\u4E0D\u652F\u6301\u5199\u5165 GIA\u3002`),e.fillType==="Radial180"&&e.fillRadialType!=="Bottom"&&r.push(`${e.name}: \u5F53\u524D 180 \u5EA6\u586B\u5145\u8D77\u70B9\u6682\u4E0D\u652F\u6301\u5199\u5165 GIA\u3002`);let h={field502:o.imageField502??1,field504:o.imageField504??1,field505:o.imageField505??1,field507:o.imageField507??2,field508:Math.round(Math.max(0,Math.min(1,Number(e.fillAmount)||0))*100),border:{field501:_i(e.softEdgeWidthX,8),field502:_i(e.softEdgeWidthY,8)},field512:_i(e.horizontalSoftRange,85),field513:_i(e.verticalSoftRange,85),fillType:u,...e.enableMask?{enableMask:1}:{},...e.enableSoftEdge?{enableSoftEdge:1}:{},...e.softEdgeMode==="Pixel"?{softEdgePixel:1}:{},...e.enableFill&&u?{enableFill:1}:{},...e.reverseMaskArea?{reverseMask:1}:{}};return[s,n(73,96,"empty83","imageSlot",{field502:Number.isFinite(e.imageColor)?e.imageColor>>>0:4294967295,assetId:e.imageId>>>0}),n(74,97,"empty84","image",h),c]}if(e.kind==="button"){let l=(y,m)=>{let S=e[y];return S?(e.children||[]).some(I=>I.id===S)?i.get(S)||0:(r.push(`${e.name}: ${m}\u72B6\u6001\u8282\u70B9\u4E0D\u662F\u6309\u94AE\u7684\u76F4\u63A5\u5B50\u63A7\u4EF6\uFF0CGIA \u672A\u5199\u5165\u8BE5\u72B6\u6001\u3002`),0):0},u=l("unavailableChildId","\u4E0D\u53EF\u7528"),h=l("hoverChildId","\u60AC\u505C"),d=l("pressedChildId","\u6309\u4E0B"),g=l("selectedChildId","\u9009\u4E2D");return[s,n(70,93,"empty80","buttonPreset",{clickAudioId:Math.trunc(e.clickAudioId),...u?{disabledChild:u}:{},...h?{hoverChild:h}:{},...d?{pressedChild:d}:{},...g?{selectedChild:g}:{},...e.interactable?{interactable:1}:{},...e.raycastTarget?{raycastTarget:1}:{}}),c]}return e.kind==="cursor"?[s,n(65,85,"empty75","cursorConfig",{field501:[void 0,0,1].includes(o.cursorField501)?e.raycastTarget!==!1?1:0:o.cursorField501}),c]:e.kind==="reference"?[s,n(66,89,"empty76","templateRefSlot",o.templateRefSlot??""),c]:e.kind==="grid"?((e.itemPrefabId||e.interactable===!1||e.showScrollBar===!1||e.raycastTarget===!1||e.scrollDirection!=="Vertical"||e.layoutConstraint!=="AutoWrap")&&r.push(`${e.name}: \u7F51\u683C\u5217\u8868\u9879\u6A21\u677F\u3001\u4EA4\u4E92/\u6EDA\u52A8\u6761\u5F00\u5173\u3001\u6EDA\u52A8\u65B9\u5411\u53CA\u6392\u5217\u9650\u5236\u4EC5\u4FDD\u5B58\u5728 JSON\uFF0CGIA \u672A\u6620\u5C04\u8FD9\u4E9B\u6539\u52A8\u3002`),[s,n(69,92,"empty79","gridView",{field501:o.gridField501??1,cellSize:{field501:e.cellSizeX,field502:e.cellSizeY},gap:{field501:e.spacingX,field502:e.spacingY},padding1:{field501:e.padding1X,field502:e.padding1Y},padding2:{field501:e.padding2X,field502:e.padding2Y},field507:o.gridField507??1,field508:o.gridField508??1,field509:o.gridField509??1,field511:o.gridField511??5,field512:o.gridField512??1}),c]):e.kind==="keyhint"?[s,n(72,95,"empty82","keyHint",{field501:Number.isFinite(o.keyHintField501)?Math.trunc(o.keyHintField501):e.controllerKeyCode??1,field502:Number.isFinite(o.keyHintField502)?Math.trunc(o.keyHintField502):e.keyboardKeyCode??1}),c]:e.kind==="animation"?[s,n(75,98,"empty85","effectSlot",o.effectSlot??""),c]:e.kind==="fullscreen"?[s,n(76,99,"empty86","fullscreenEffectSlot",o.fullscreenEffectSlot??""),c]:(r.push(`${e.name}: ${e.kind} \u4E0D\u662F\u5DF2\u77E5 GIA \u63A7\u4EF6\u7C7B\u578B\uFF0C\u5DF2\u4EC5\u5199\u516C\u5171\u53D8\u6362\u3002`),[s,c])}function Tl(e,t){return t?1:Number.isSafeInteger(Number(e.giaInfoIndex))&&Number(e.giaInfoIndex)>0?Number(e.giaInfoIndex):Co[e.kind]||2}function Ml(e,t,i){let r=Array.isArray(e.giaRelatedGuids)?e.giaRelatedGuids.filter(n=>Number.isSafeInteger(n)&&n>0&&n<=2147483647):[];return r.length?r:(t.push(`${e.name}: \u65B0${i}\u5199\u5165\u663E\u5F0F\u7A7A Info.related\uFF0C\u907F\u514D\u8DE8\u6C99\u7BB1\u590D\u7528\u4F34\u751F\u8D44\u6E90 GUID \u4EA7\u751F\u65E0\u6CD5\u52A0\u8F7D\u7684\u7D22\u5F15\u3002`),[])}function Nr(e,t){let i=String(e.meta?.giaFilePath||"").trim();if(/^\d+-\d+-\d+-\\.+\.gia$/iu.test(i))return i;let r=(l,u)=>Number.isSafeInteger(Number(l))&&Number(l)>0?Number(l):u,n=r(e.meta?.giaOwnerUid,114514),o=r(e.meta?.giaTimestamp,Math.floor(Date.now()/1e3)),a=r(e.meta?.giaFileId,t?1073741829:1073741830),s=t?"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868.gia":"\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F-\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668.gia",c=String(e.meta?.giaFileName||s).replace(/[\\/:*?"<>|]/gu,"-").replace(/\.gia$/iu,"").trim()||s.replace(/\.gia$/iu,"");return`${n}-${o}-${a}-\\${c}.gia`}function Ri(e,t,i,r,n,o=!1,a=!1,s=a,c=!1){let l=i.get(e.id),h=(c?[...e.children||[]].reverse():e.children||[]).map(y=>i.get(y.id)),d=o?r:h,g=Pl(e,l,o);if(o){let y=e.children?.[0];y&&g.push({empty72:"",field501:62,field502:82,details:ei(l,64,82,{rootChildRef:{guid:i.get(y.id)}})})}else g.push(...Rl(e,l,i,n));return{id:Mr(l),relatedIds:d.map(y=>Mr(y)),name:e.name,which:o?21:a?70:15,ui:{content:{guid:l,info:[{guid:{value:l},field501:1,field502:5},...o||s?[{index:{value:Tl(e,o)},field501:2,field502:6}]:[],...o||a?[{related:{value:Ml(e,n,o?"\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F")},field501:4,field502:4}]:[]],children:o?[]:h,parent:t&&t.kind!=="server-container"?i.get(t.id):0,data:g}}}}function Ao(e){let t=[];return J(e.root,(i,r)=>{i.kind!=="server-container"&&t.push({node:i,parent:r})}),t}function Nl(e,t){let i=new Map;for(let r of e||[]){if(!r.controlId||!(t===Pi?r.controlAsset===Pi:r.controlAsset!==Pi))continue;let o=i.get(r.controlId)||[];o.push(r.guid),i.set(r.controlId,o)}return i}function _o(e,t,i,r){let n=Nl(t,i),o=new Map;J(e.root,a=>{n.has(a.id)&&(o.set(a,a.scriptMappingIds),a.scriptMappingIds=n.get(a.id))});try{return r()}finally{for(let[a,s]of o)s===void 0?delete a.scriptMappingIds:a.scriptMappingIds=s}}function Fr(e){let t=Number(e.meta?.giaModeFlag);return Number.isSafeInteger(t)&&t>=0?{modeFlag:t}:{}}function Po(e,t,i,r,n=[]){let o=Ao(e),a=o.filter(({parent:u})=>u?.kind==="server-container");if(!a.length)throw new Error("\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868\u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u6A21\u677F");let s=new Set(a.map(({node:u})=>u.id)),c=o.filter(({node:u})=>!s.has(u.id)),l=o.map(({node:u})=>t.get(u.id));return _o(e,n,Pi,()=>({graph:a.map(({node:u,parent:h})=>Ri(u,h,t,l,i,!1,!0)),accessories:c.map(({node:u,parent:h})=>Ri(u,h,t,l,i,!1,!1,!0)),filePath:r||Nr(e,!0),gameVersion:e.meta?.gameVersion||"7.0.50",...Fr(e)}))}function Ro(e,t,i,r,n){let o=Ao(e),a=[o[0],...o.slice(1).reverse()],s=a.map(({node:c})=>t.get(c.id));return _o(e,i.scripts,Cl,()=>({graph:[Ri(e.root,null,t,s,r,!0,!1,!1,!0),...i.units||[]],accessories:a.map(({node:c,parent:l})=>Ri(c,l,t,s,r,!1,!1,!1,!0)),filePath:n||Nr(e,!1),gameVersion:e.meta?.gameVersion||"7.0.50",...Fr(e)}))}function To(e,t){let i=zo(e),r=t(i);if(!r.valid)throw new Error(`GIA compatibility validation failed:
|
|
103
|
+
`,{root:Ll}=Hl.parse(Ul,{keepCase:!1}),Te=Ll.lookupType("Root"),it=20,jr=4,$a=806,Ga=1657,ri={image:23,"server-container":24,container:25,grid:26,reference:27,button:28,animation:29,fullscreen:30,textbox:31,textwindow:32,cursor:33,keyhint:34},Va={KEYBOARD:0,TOUCHSCREEN:1,CONTROLLER_CONSOLE:2,CONTROLLER_MOBILE:3},Xl="server-control-template",$i="client-control-template";function zi(e,t){let i=Number(e);return Number.isFinite(i)?i:t}var Wl=Object.fromEntries(Object.entries(Va).map(([e,t])=>[t,e])),Ya=Object.freeze({container:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["68/91","empty78","containerNodeSlot"],["67/90","empty77","footerSlot"]],textbox:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["64/84","empty74","textConfig"],["67/90","empty77","footerSlot"]],cursor:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["65/85","empty75","cursorConfig"],["67/90","empty77","footerSlot"]],reference:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["66/89","empty76","templateRefSlot"],["67/90","empty77","footerSlot"]],grid:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["69/92","empty79","gridView"],["67/90","empty77","footerSlot"]],button:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["70/93","empty80","buttonPreset"],["67/90","empty77","footerSlot"]],textwindow:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["71/94","empty81","textConfig"],["67/90","empty77","footerSlot"]],keyhint:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["72/95","empty82","keyHint"],["67/90","empty77","footerSlot"]],image:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["73/96","empty83","imageSlot"],["74/97","empty84","image"],["67/90","empty77","footerSlot"]],animation:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["75/98","empty85","effectSlot"],["67/90","empty77","footerSlot"]],fullscreen:[["2/15","name",null],["4/86","field14","field14"],["1/12","transform","transform"],["63/83","empty73","genericSlot"],["76/99","empty86","fullscreenEffectSlot"],["67/90","empty77","footerSlot"]]}),Ba=Object.freeze({"4/23":5,"4/86":5,"1/12":4,"62/82":64,"63/83":65,"64/84":66,"65/85":67,"66/89":68,"67/90":69,"68/91":70,"69/92":71,"70/93":72,"71/94":66,"72/95":74,"73/96":75,"74/97":76,"75/98":77,"76/99":78}),Kl=Object.freeze([["2/15","name",null],["4/23","field14","field14"],["1/12","transform","transform"],["62/82","empty72","rootChildRef"]]);function Hr(e){return{class:1,type:8,id:e}}function ni(e,t,i,r){return{...r,field501:t,field502:i,field503:1,nodeRef:Hr(e)}}function ql(e){let t=[],i=e.meta?.assetType==="client-control-template";return Q(e.root,r=>{i&&r.kind==="server-container"||t.push(r)}),t}function ai(e,t=new Set){let i=new Map,r=[];for(let n of ql(e)){let a=Number(n.guid);Pe(a)&&!t.has(a)?(t.add(a),n.guid=a,i.set(n.id,a)):r.push(n)}for(let n of r){let a=Ze(t);t.add(a),n.guid=a,i.set(n.id,a)}return i}function Jl(e){return{scale:{x:e.scale.x,y:e.scale.y,z:e.scale.z},anchorMin:{x:e.anchorMin.x,y:e.anchorMin.y},anchorMax:{x:e.anchorMax.x,y:e.anchorMax.y},offset:{x:e.offset.x,y:e.offset.y},size:{x:e.size.x,y:e.size.y},pivot:{x:e.pivot.x,y:e.pivot.y},field508:e.rotation.z?{z:e.rotation.z}:{}}}function Zl(e,t){let r={multiPlatform:{platforms:ce.map(n=>({platformType:Va[n],transform:Jl(e.transformByPlatform[n])})),field502:ri[e.kind]||25,...e.syncAllDevices===!1?{}:{field504:1}},type:2};return{transform:{multiPlatform:{},type:2},field501:1,field502:12,details:ni(t,4,12,{transform:r})}}function Ql(e,t,i){let r=i?{empty15:"",field501:5}:{field17:{},field501:7},n=i?r:{...r,...e.visible===!1?{field17:{initiallyHidden:!0}}:{},...e.active===!1?{initiallyInactive:!0}:{}};return[{name:{value:e.name},field501:2,field502:15},{field14:r,field501:4,field502:i?23:86,details:ni(t,5,i?23:86,{field14:n})},Zl(e,t)]}function ec(e,t,i,r){let n=(l,u,d,h,p)=>({[d]:"",field501:l,field502:u,details:ni(t,l+2,u,{[h]:p})}),a=e.giaRaw||{},o=Array.isArray(e.scriptMappingIds)&&e.scriptMappingIds.length?{field501:a.genericField501||1,field502:e.scriptMappingIds.map(l=>({field1:{id:Number(l)}}))}:{field501:a.genericField501??0},s=n(63,83,"empty73","genericSlot",o),c=n(67,90,"empty77","footerSlot",{field505:[void 0,0,1].includes(a.footerField505)?e.canControllerFocus?1:0:a.footerField505});if(e.kind==="container")return[s,n(68,91,"empty78","containerNodeSlot",{...e.isolateNavigation?{isolateNavigation:!0}:{},...e.disableKeyEventPassthrough?{disableKeyEventPassthrough:!0}:{},...e.disableCursorEventPassthrough?{disableCursorEventPassthrough:!0}:{},...e.showCursor?{showCursor:!0}:{}}),c];if(e.kind==="textbox"||e.kind==="textwindow"){e.verticalAlignment==="Middle"&&r.push(`${e.name}: \u5782\u76F4\u5C45\u4E2D\u6309\u63A8\u5B9A\u503C\u5BFC\u51FA\uFF0C\u5C1A\u5F85\u5B9E\u673A\u786E\u8BA4\u3002`);let l={Left:0,Middle:1,Right:2}[e.horizontalAlignment]??0,u=Number.isFinite(a.textAlign)?Math.trunc(a.textAlign):l,d={field501:a.textField501??20,field503:a.textField503??12,color:e.fontColor>>>0,color2:e.bgColor>>>0,color3:e.outlineColor>>>0,text:{value:e.text||""},fontSize:Math.trunc(e.fontSize),minimumFontSize:Math.trunc(e.minimumFontSize),...e.adaptiveFontSize?{adaptive:1}:{},...e.enableOutline===!1?{outlineOff:1}:{},...u?{align:u}:{},verticalAlign:a.textVerticalAlign??{Top:0,Middle:1,Bottom:2}[e.verticalAlignment]??0};return e.kind==="textwindow"?((e.interactable===!1||e.showScrollBar===!1)&&r.push(`${e.name}: \u6587\u672C\u89C6\u7A97\u4EA4\u4E92/\u6EDA\u52A8\u6761\u5F00\u5173\u4EC5\u4FDD\u5B58\u5728 JSON\uFF0CGIA \u672A\u6620\u5C04\u8FD9\u4E9B\u6539\u52A8\u3002`),d.field511=a.textField511??1,d.viewFlags={field502:a.textViewField502??1,field503:a.textViewField503??1},[s,{empty81:"",field501:71,field502:94,details:ni(t,66,94,{textConfig:d})},c]):[s,n(64,84,"empty74","textConfig",d),c]}if(e.kind==="image"){let l=[0,1].includes(a.imageSlotType??0)?e.imageType==="Stretch"?1:0:a.imageSlotType;e.imageType==null&&e.imageSource==="StaticReference"&&e.imageId>100006&&r.push(`${e.name}: \u56FE\u7247\u7C7B\u578B\u968F\u7D20\u6750\u8FB9\u754C\u81EA\u52A8\u9009\u62E9\uFF0CGIA \u6309\u57FA\u7840\u5BFC\u51FA\uFF1B\u9700\u8981\u62C9\u4F38\u8BF7\u5148\u660E\u786E\u9009\u62E9\u6216\u5728 Lua \u8BBE\u7F6E imageType\u3002`),e.imageSource&&e.imageSource!=="StaticReference"&&r.push(`${e.name}: \u56FE\u7247\u6765\u6E90 ${e.imageSource} \u4EC5\u4FDD\u5B58\u5728 JSON\uFF0C\u5C1A\u672A\u6620\u5C04\u5230 GIA\uFF1B\u8BF7\u5728 Lua \u4E2D\u7528 SetImage(Enum.ImageSource.${e.imageSource}, ${e.imageId}) \u8BBE\u7F6E\u3002`);let u={Horizontal:1,Vertical:2,Radial90:3,Radial180:4,Radial360:5}[e.fillType],d=Number.isFinite(a.imageFillType)?Math.trunc(a.imageFillType):u||1;e.enableFill&&!d&&r.push(`${e.name}: \u586B\u5145\u5F62\u72B6\u539F\u59CB\u679A\u4E3E\u4E3A 0\uFF0C\u5DF2\u5173\u95ED\u5BFC\u51FA\u6587\u4EF6\u4E2D\u7684\u8FDB\u5EA6\u586B\u5145\u3002`),e.fillType==="Horizontal"&&e.fillHorizontalType!=="Left"&&r.push(`${e.name}: \u5F53\u524D\u6A2A\u5411\u586B\u5145\u65B9\u5411\u6682\u4E0D\u652F\u6301\u5199\u5165 GIA\u3002`),e.fillType==="Radial180"&&e.fillRadialType!=="Bottom"&&r.push(`${e.name}: \u5F53\u524D 180 \u5EA6\u586B\u5145\u8D77\u70B9\u6682\u4E0D\u652F\u6301\u5199\u5165 GIA\u3002`);let h={field502:a.imageField502??1,field504:a.imageField504??1,field505:a.imageField505??1,field507:a.imageField507??2,field508:Math.round(Math.max(0,Math.min(1,Number(e.fillAmount)||0))*100),border:{field501:zi(e.softEdgeWidthX,8),field502:zi(e.softEdgeWidthY,8)},field512:zi(e.horizontalSoftRange,85),field513:zi(e.verticalSoftRange,85),fillType:d,...e.enableMask?{enableMask:1}:{},...e.enableSoftEdge?{enableSoftEdge:1}:{},...e.softEdgeMode==="Pixel"?{softEdgePixel:1}:{},...e.enableFill&&d?{enableFill:1}:{},...e.reverseMaskArea?{reverseMask:1}:{}};return[s,n(73,96,"empty83","imageSlot",{field502:Number.isFinite(e.imageColor)?e.imageColor>>>0:4294967295,assetId:e.imageId>>>0,...l?{imageType:l}:{}}),n(74,97,"empty84","image",h),c]}if(e.kind==="button"){let l=(m,g)=>{let S=e[m];return S?(e.children||[]).some(C=>C.id===S)?i.get(S)||0:(r.push(`${e.name}: ${g}\u72B6\u6001\u8282\u70B9\u4E0D\u662F\u6309\u94AE\u7684\u76F4\u63A5\u5B50\u63A7\u4EF6\uFF0CGIA \u672A\u5199\u5165\u8BE5\u72B6\u6001\u3002`),0):0},u=l("unavailableChildId","\u4E0D\u53EF\u7528"),d=l("hoverChildId","\u60AC\u505C"),h=l("pressedChildId","\u6309\u4E0B"),p=l("selectedChildId","\u9009\u4E2D");return[s,n(70,93,"empty80","buttonPreset",{clickAudioId:Math.trunc(e.clickAudioId),...u?{disabledChild:u}:{},...d?{hoverChild:d}:{},...h?{pressedChild:h}:{},...p?{selectedChild:p}:{},...e.interactable?{interactable:1}:{},...e.raycastTarget?{raycastTarget:1}:{}}),c]}return e.kind==="cursor"?[s,n(65,85,"empty75","cursorConfig",{field501:[void 0,0,1].includes(a.cursorField501)?e.raycastTarget!==!1?1:0:a.cursorField501}),c]:e.kind==="reference"?[s,n(66,89,"empty76","templateRefSlot",a.templateRefSlot??""),c]:e.kind==="grid"?((e.itemPrefabId||e.interactable===!1||e.showScrollBar===!1||e.raycastTarget===!1||e.scrollDirection!=="Vertical"||e.layoutConstraint!=="AutoWrap")&&r.push(`${e.name}: \u7F51\u683C\u5217\u8868\u9879\u6A21\u677F\u3001\u4EA4\u4E92/\u6EDA\u52A8\u6761\u5F00\u5173\u3001\u6EDA\u52A8\u65B9\u5411\u53CA\u6392\u5217\u9650\u5236\u4EC5\u4FDD\u5B58\u5728 JSON\uFF0CGIA \u672A\u6620\u5C04\u8FD9\u4E9B\u6539\u52A8\u3002`),[s,n(69,92,"empty79","gridView",{field501:a.gridField501??1,cellSize:{field501:e.cellSizeX,field502:e.cellSizeY},gap:{field501:e.spacingX,field502:e.spacingY},padding1:{field501:e.padding1X,field502:e.padding1Y},padding2:{field501:e.padding2X,field502:e.padding2Y},field507:a.gridField507??1,field508:a.gridField508??1,field509:a.gridField509??1,field511:a.gridField511??5,field512:a.gridField512??1}),c]):e.kind==="keyhint"?[s,n(72,95,"empty82","keyHint",{field501:Number.isFinite(a.keyHintField501)?Math.trunc(a.keyHintField501):e.controllerKeyCode??1,field502:Number.isFinite(a.keyHintField502)?Math.trunc(a.keyHintField502):e.keyboardKeyCode??1}),c]:e.kind==="animation"?[s,n(75,98,"empty85","effectSlot",a.effectSlot??""),c]:e.kind==="fullscreen"?[s,n(76,99,"empty86","fullscreenEffectSlot",a.fullscreenEffectSlot??""),c]:(r.push(`${e.name}: ${e.kind} \u4E0D\u662F\u5DF2\u77E5 GIA \u63A7\u4EF6\u7C7B\u578B\uFF0C\u5DF2\u4EC5\u5199\u516C\u5171\u53D8\u6362\u3002`),[s,c])}function tc(e,t){if(t)return 1;if(!Ee(e.giaInfoIndex))throw new Error(`${e.name}: \u7F3A\u5C11\u5408\u6CD5\u7684\u5BA2\u6237\u7AEF\u8D44\u4EA7\u7F16\u53F7`);return e.giaInfoIndex}function ic(e,t,i){let r=Array.isArray(e.giaRelatedGuids)?e.giaRelatedGuids.filter(n=>Number.isSafeInteger(n)&&n>0&&n<=2147483647):[];return r.length?r:(t.push(`${e.name}: \u65B0${i}\u5199\u5165\u663E\u5F0F\u7A7A Info.related\uFF0C\u907F\u514D\u8DE8\u6C99\u7BB1\u590D\u7528\u4F34\u751F\u8D44\u6E90 GUID \u4EA7\u751F\u65E0\u6CD5\u52A0\u8F7D\u7684\u7D22\u5F15\u3002`),[])}function Ur(e,t){let i=String(e.meta?.giaFilePath||"").trim();if(/^\d+-\d+-\d+-\\.+\.gia$/iu.test(i))return i;let r=(l,u)=>Number.isSafeInteger(Number(l))&&Number(l)>0?Number(l):u,n=r(e.meta?.giaOwnerUid,114514),a=r(e.meta?.giaTimestamp,Math.floor(Date.now()/1e3)),o=r(e.meta?.giaFileId,t?1073741829:1073741830),s=t?"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868.gia":"\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F-\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668.gia",c=String(e.meta?.giaFileName||s).replace(/[\\/:*?"<>|]/gu,"-").replace(/\.gia$/iu,"").trim()||s.replace(/\.gia$/iu,"");return`${n}-${a}-${o}-\\${c}.gia`}function Gi(e,t,i,r,n,a=!1,o=!1,s=o,c=!1){let l=i.get(e.id),d=(c?[...e.children||[]].reverse():e.children||[]).map(m=>i.get(m.id)),h=a?r:d,p=Ql(e,l,a);if(a){let m=e.children?.[0];m&&p.push({empty72:"",field501:62,field502:82,details:ni(l,64,82,{rootChildRef:{guid:i.get(m.id)}})})}else p.push(...ec(e,l,i,n));return{id:Hr(l),relatedIds:h.map(m=>Hr(m)),name:e.name,which:a?21:o?70:15,ui:{content:{guid:l,info:[{guid:{value:l},field501:1,field502:5},...a||s?[{index:{value:tc(e,a)},field501:2,field502:6}]:[],...a||o?[{related:{value:ic(e,n,a?"\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F")},field501:4,field502:4}]:[]],children:a?[]:d,parent:t&&t.kind!=="server-container"?i.get(t.id):0,data:p}}}}function ja(e){let t=[];return Q(e.root,(i,r)=>{i.kind!=="server-container"&&t.push({node:i,parent:r})}),t}function rc(e,t){let i=new Map;for(let r of e||[]){if(!r.controlId||!(t===$i?r.controlAsset===$i:r.controlAsset!==$i))continue;let a=i.get(r.controlId)||[];a.push(r.guid),i.set(r.controlId,a)}return i}function Ha(e,t,i,r){let n=rc(t,i),a=new Map;Q(e.root,o=>{n.has(o.id)&&(a.set(o,o.scriptMappingIds),o.scriptMappingIds=n.get(o.id))});try{return r()}finally{for(let[o,s]of a)s===void 0?delete o.scriptMappingIds:o.scriptMappingIds=s}}function Lr(e){let t=Number(e.meta?.giaModeFlag);return Number.isSafeInteger(t)&&t>=0?{modeFlag:t}:{}}function Xr(e){let t=e.meta?.gameVersion;return!t||t==="7.0.50"?Ri:t}function Ua(e,t,i,r,n=[]){let a=ja(e),o=a.filter(({parent:u})=>u?.kind==="server-container");if(!o.length)throw new Error("\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868\u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u6A21\u677F");let s=new Set(o.map(({node:u})=>u.id)),c=a.filter(({node:u})=>!s.has(u.id)),l=a.map(({node:u})=>t.get(u.id));return Ha(e,n,$i,()=>({graph:o.map(({node:u,parent:d})=>Gi(u,d,t,l,i,!1,!0)),accessories:c.map(({node:u,parent:d})=>Gi(u,d,t,l,i,!1,!1,!0)),filePath:r||Ur(e,!0),gameVersion:Xr(e),...Lr(e)}))}function La(e,t,i,r,n){let a=ja(e),o=[a[0],...a.slice(1).reverse()],s=o.map(({node:c})=>t.get(c.id));return Ha(e,i.scripts,Xl,()=>({graph:[Gi(e.root,null,t,s,r,!0,!1,!1,!0),...i.units||[]],accessories:o.map(({node:c,parent:l})=>Gi(c,l,t,s,r,!1,!1,!1,!0)),filePath:n||Ur(e,!1),gameVersion:Xr(e),...Lr(e)}))}function Xa(e,t){let i=Wr(e),r=t(i);if(!r.valid)throw new Error(`GIA compatibility validation failed:
|
|
104
104
|
${r.errors.join(`
|
|
105
|
-
`)}`);return i}function
|
|
105
|
+
`)}`);return i}function Wa(e,t={}){Q(e.root,ut);let i=[];He(e,{warnings:i});let r=ai(V(e)),n=e.meta?.assetType==="client-control-template",a;if(n)a=Ua(e,r,i,void 0,t.scripts||[]);else{let s=Kr(t.scripts||[],new Set(r.values()));i.push(...s.warnings),a=La(e,r,s,i)}return{buffer:Xa(a,n?Jr:Zr),warnings:[...new Set(i)]}}function Ka(e,t,i={}){Q(e.root,ut),t&&Q(t.root,ut);let r=["\u6574\u5408\u5305\u628A\u670D\u52A1\u7AEF UIControlGroup \u4E0E\u5BA2\u6237\u7AEF UIControlTemplate \u5E76\u6392\u5199\u5165\u540C\u4E00 GIA \u7684 Root.graph\uFF1B\u5BFC\u5165\u65F6\u62C6\u56DE\u4E24\u7C7B\u8D44\u4EA7\uFF0C\u6A21\u677F\u8FB9\u754C\u3001\u811A\u672C\u6620\u5C04\u4E0E\u63A7\u4EF6\u6302\u8F7D\u5173\u7CFB\u4F1A\u4FDD\u7559\u3002"];t&&He(t,{warnings:r});let n=t?.root?.children||[];n.length||r.push("\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u4E3A\u7A7A\uFF0C\u6574\u5408\u5305\u53EA\u5305\u542B\u670D\u52A1\u7AEF\u63A7\u4EF6\u4E0E\u811A\u672C\u3002");let a=new Set,o=V(e),s=t?V(t):null,c=ai(o,a),l=Kr(i.scripts||[],a);r.push(...l.warnings.filter(S=>S!==Ja));let u=String(i.fileName||`${o.meta?.name||"\u6574\u5408\u5305"} \xB7 \u6574\u5408\u5305.gia`),d=Ur({...o,meta:{...o.meta,giaFileName:u}},!1),h=La(o,c,l,r,d),p={graph:[],accessories:[]};if(n.length&&s){let S=ai({...s,meta:{...s.meta,assetType:"client-control-template"}},a);p=Ua(s,S,r,d,l.scripts)}let m={graph:[...h.graph,...p.graph],accessories:[...h.accessories,...p.accessories],filePath:d,gameVersion:Xr({meta:{gameVersion:e.meta?.gameVersion||t?.meta?.gameVersion}}),...Lr(e)};return{buffer:Xa(m,Zr),warnings:[...new Set(r)]}}var Mt=69,qa=30,Ja="\u811A\u672C\u6302\u8F7D\u5173\u7CFB\u4E0D\u8FDB\u5165 GIA\uFF1A\u5B98\u65B9 script.gia \u53EA\u542B\u6620\u5C04\uFF08ID/\u540D\u79F0/\u8DEF\u5F84/\u6E90\u7801\uFF09\uFF0C\u5BFC\u5165\u540E\u9700\u91CD\u65B0\u6302\u8F7D\u3002";function nc(e){return(String(e.path||"").replace(/\\/g,"/").split("/").pop()||"").replace(/\.lua$/iu,"")||`\u811A\u672C${e.id||""}`}function Wr(e){let t=Te.verify(e);if(t)throw new Error(`GIA encode validation failed: ${t}`);let i=Te.encode(Te.create(e)).finish(),r=Buffer.alloc(it+i.length+jr);return r.writeUInt32BE(r.length-4,0),r.writeUInt32BE(1,4),r.writeUInt32BE($a,8),r.writeUInt32BE(3,12),r.writeUInt32BE(i.length,16),Buffer.from(i).copy(r,it),r.writeUInt32BE(Ga,it+i.length),r}function Kr(e,t=new Set){let i=(e||[]).filter(o=>o.path||o.source).map(o=>({...o})),r=[];for(let o of i){let s=Number(o.guid);Pe(s)&&!t.has(s)?(t.add(s),o.guid=s):r.push(o)}for(let o of r){let s=Ze(t);t.add(s),o.guid=s}let n=[];return(e||[]).some(o=>o.controlId)&&n.push(Ja),{units:i.map(o=>{let s=nc(o),c=String(o.path||"").replace(/\\/g,"/"),l=/\.lua$/iu.test(c)?c:`${c||s}.lua`,u={id:o.guid,name:s,filePath:l};return String(o.source||"")&&(u.source=String(o.source)),{id:{class:qa,id:o.guid},name:s,which:Mt,script:{mapping:u}}}),warnings:n,scripts:i}}function Za(e){let t=Kr(e);if(!t.units.length)throw new Error("\u6CA1\u6709\u53EF\u5BFC\u51FA\u7684 Lua \u811A\u672C\uFF0C\u8BF7\u5148\u5728\u201CLua \u811A\u672C\u201D\u9875\u521B\u5EFA");let i={graph:t.units,filePath:`114514-${Math.floor(Date.now()/1e3)}-1073741832-\\script.gia`,gameVersion:"7.0.51"},r=Wr(i),n=ac(r);if(!n.valid)throw new Error(`GIA compatibility validation failed:
|
|
106
106
|
${n.errors.join(`
|
|
107
|
-
`)}`);return{buffer:r,warnings:[...new Set(t.warnings)]}}function zr(e){return Ee.toObject(Ee.decode(Mi(e)),{longs:Number,enums:Number,bytes:Buffer,defaults:!1,arrays:!0,objects:!0})}function $o(e){try{let i=zr(e).graph||[];return i.length>0&&i.every(r=>Number(r.which)===Et)}catch{return!1}}function Go(e){let t=(e.graph||[]).filter(n=>Number(n.which)===Et),i=[],r=t.map((n,o)=>{let a=n.script?.mapping||{},s=Number(n.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 c=Number(a.id)||0;return c&&c!==s&&i.push(`\u7B2C ${o+1} \u6761\u811A\u672C\u6620\u5C04 id(${c}) \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[n,o]of r.entries())o.path&&!/\.lua$/iu.test(o.path)&&i.push(`\u7B2C ${n+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:r,warnings:i}}function Vo(e){let t=zr(e),i=Go(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 Ol(e){let t=[],i;try{i=zr(e)}catch(n){return{valid:!1,errors:[n?.message||String(n)],scriptCount:0}}let r=i.graph||[];return r.length||t.push("Root.graph \u4E3A\u7A7A"),(i.accessories||[]).length&&t.push("script.gia \u4E0D\u5E94\u5305\u542B accessories"),r.forEach((n,o)=>{let a=`\u5355\u5143 ${o+1}`;Number(n.which)!==Et&&t.push(`${a}: which \u5E94\u4E3A 69\uFF0C\u5B9E\u9645 ${n.which}`),Number(n.id?.class)!==Fo&&t.push(`${a}: id.class \u5E94\u4E3A 30\uFF0C\u5B9E\u9645 ${n.id?.class}`),Number(n.id?.type??0)!==0&&t.push(`${a}: id.type \u5E94\u7F3A\u7701`);let s=n.script?.mapping;if(!s){t.push(`${a}: \u7F3A\u5C11 field35 ScriptMappingWrapper`);return}Number(n.id?.id)<=0&&t.push(`${a}: GraphUnit.id.id \u975E\u6CD5`),Number(s.id)!==Number(n.id?.id)&&t.push(`${a}: mapping.id \u5E94\u7B49\u4E8E GraphUnit.id.id`),String(s.name||"")!==String(n.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:r.length}}function Mi(e){let t=Buffer.isBuffer(e)?e:Buffer.from(e);if(t.length<Ke+Tr)throw new Error("GIA \u6587\u4EF6\u8FC7\u77ED");if(t.readUInt32BE(4)!==1||t.readUInt32BE(8)!==So||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-Ke-Tr)throw new Error("GIA payload \u957F\u5EA6\u4E0D\u4E00\u81F4");if(t.readUInt32BE(Ke+i)!==Io)throw new Error("GIA \u5C3E\u6807\u8BB0\u65E0\u6548");return t.subarray(Ke,Ke+i)}function fe(e,t){return e.ui?.content?.data?.find(i=>i.details?.[t])?.details?.[t]||null}function zl(e){let t=fe(e,"transform")?.multiPlatform,i={};for(let n of t?.platforms||[]){let o=xl[n.platformType||0],a=n.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:a.field508?.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 r=i.KEYBOARD||i[Object.keys(i)[0]];if(!r)throw new Error(`GIA \u63A7\u4EF6 ${e.name||e.id?.id} \u7F3A\u5C11\u591A\u5E73\u53F0\u53D8\u6362`);for(let n of le)i[n]||(i[n]=structuredClone(r));return i}function Ti(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 wo(e,{reverseSiblings:t=!1,idOffset:i=0}={}){if(!e.length)return{nodes:new Map,rootCandidates:[],warnings:[]};let r=new Map(e.map((l,u)=>[l.id?.id,`n${i+u+1}`])),n=new Map,o=new Map,a=[];for(let l of e){let u=Ti(l),h=fe(l,"textConfig"),d=fe(l,"imageSlot"),g=fe(l,"image"),y=fe(l,"buttonPreset"),m=fe(l,"gridView"),S=fe(l,"genericSlot"),I=fe(l,"footerSlot"),E=fe(l,"cursorConfig"),M=fe(l,"keyHint"),F=fe(l,"containerNodeSlot"),H=fe(l,"templateRefSlot"),te=fe(l,"effectSlot"),Z=fe(l,"fullscreenEffectSlot"),D=W(u,{id:r.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||u,visible:fe(l,"field14")?.field17?.initiallyHidden!==!0,active:fe(l,"field14")?.initiallyInactive!==!0,canControllerFocus:I?.field505===1,scriptMappingIds:(S?.field502||[]).map(v=>Number(v?.field1?.id)).filter(v=>Number.isSafeInteger(v)&&v>0),transformByPlatform:zl(l),syncAllDevices:fe(l,"transform")?.multiPlatform?.field504===1,giaRaw:{genericField501:S?.field501??0,footerField505:I?.field505??0,...u==="textbox"||u==="textwindow"?{textField501:h?.field501??20,textField503:h?.field503??12,textAlign:h?.align??0,...[void 0,0,1,2].includes(h?.verticalAlign)?{}:{textVerticalAlign:h.verticalAlign},...u==="textwindow"?{textField511:h?.field511??1,textViewField502:h?.viewFlags?.field502??1,textViewField503:h?.viewFlags?.field503??1}:{}}:{},...u==="cursor"?{cursorField501:E?.field501??0}:{},...u==="reference"?{templateRefSlot:H??""}:{},...u==="grid"?{gridField501:m?.field501??1,gridField507:m?.field507??1,gridField508:m?.field508??1,gridField509:m?.field509??1,gridField511:m?.field511??5,gridField512:m?.field512??1}:{},...u==="keyhint"?{keyHintField501:M?.field501??1,keyHintField502:M?.field502??1}:{},...u==="image"?{imageField502:g?.field502??1,imageField504:g?.field504??1,imageField505:g?.field505??1,imageField507:g?.field507??2,imageFillType:g?.fillType??1}:{},...u==="animation"?{effectSlot:te??""}:{},...u==="fullscreen"?{fullscreenEffectSlot:Z??""}:{}},...u==="container"?{isolateNavigation:F?.isolateNavigation===!0,disableKeyEventPassthrough:F?.disableKeyEventPassthrough===!0,disableCursorEventPassthrough:F?.disableCursorEventPassthrough===!0,showCursor:F?.showCursor===!0}:{},...u==="cursor"?{raycastTarget:E?.field501===1}:{},...u==="textbox"||u==="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:{0:"Top",1:"Middle",2:"Bottom"}[h?.verticalAlign??0]||"Top",...u==="textwindow"?{interactable:!0,showScrollBar:!0}:{}}:{},...u==="image"?{imageSource:"StaticReference",imageId:d?.assetId??0,imageColor:Number.isFinite(d?.field502)?d.field502>>>0:4294967295,enableMask:g?.enableMask===1,enableSoftEdge:g?.enableSoftEdge===1,enableFill:g?.enableFill===1,softEdgeMode:g?.softEdgePixel===1?"Pixel":"Percentage",softEdgeWidthX:g?.border?.field501??8,softEdgeWidthY:g?.border?.field502??8,horizontalSoftRange:g?.field512??85,verticalSoftRange:g?.field513??85,fillType:{1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[g?.fillType]||"Horizontal",fillAmount:Number.isFinite(g?.field508)?Math.max(0,Math.min(1,g.field508/100)):g?.enableFill===1?0:1,reverseMaskArea:g?.reverseMask===1}:{},...u==="button"?{interactable:y?.interactable===1,raycastTarget:y?.raycastTarget===1,clickAudioId:y?.clickAudioId??50888}:{},...u==="grid"?{cellSizeX:m?.cellSize?.field501??50,cellSizeY:m?.cellSize?.field502??50,spacingX:m?.gap?.field501??8,spacingY:m?.gap?.field502??8,padding1X:m?.padding1?.field501??20,padding1Y:m?.padding1?.field502??20,padding2X:m?.padding2?.field501??20,padding2Y:m?.padding2?.field502??20,previewCount:m?.field511??5}:{},...u==="reference"?{referencedPrefabId:H??""}:{},...u==="keyhint"?{keyboardKeyCode:M?.field502??null,controllerKeyCode:M?.field501??null}:{},...u==="animation"?{animationId:te??""}:{},...u==="fullscreen"?{animationId:Z??""}:{}});n.set(l.id?.id,D),(u==="textbox"||u==="textwindow")&&![void 0,0,1,2].includes(h?.align)&&a.push(`${D.name}: \u6C34\u5E73\u5BF9\u9F50\u679A\u4E3E ${h.align} \u7684\u542B\u4E49\u672A\u77E5\uFF0C\u5DF2\u539F\u6837\u4FDD\u7559\u3002`),(u==="textbox"||u==="textwindow")&&![void 0,0,1,2].includes(h?.verticalAlign)&&a.push(`${D.name}: \u5782\u76F4\u5BF9\u9F50\u679A\u4E3E ${h.verticalAlign} \u7684\u542B\u4E49\u672A\u77E5\uFF0C\u5DF2\u539F\u6837\u4FDD\u7559\u3002`),u==="image"&&![void 0,0,1,2,3,4,5].includes(g?.fillType)&&a.push(`${D.name}: \u586B\u5145\u5F62\u72B6\u679A\u4E3E ${g.fillType} \u672A\u8BC6\u522B\uFF0C\u5DF2\u4FDD\u7559\u539F\u503C\u3002`),u==="button"&&o.set(D.id,{unavailableChildId:y?.disabledChild,hoverChildId:y?.hoverChild,pressedChildId:y?.pressedChild,selectedChildId:y?.selectedChild})}let s=[],c=new Set;for(let l of e){let u=n.get(l.id?.id),h=(l.ui?.content?.children||[]).map(d=>n.get(d)).filter(Boolean);if(h.length){u.children=t?h.slice().reverse():h;for(let d of h)c.add(d.id)}}for(let l of e){let u=n.get(l.id?.id),h=l.ui?.content?.parent||0,d=n.get(h);d?c.has(u.id)||(t?d.children.unshift(u):d.children.push(u)):s.push(u)}for(let[l,u]of o){let h=[...n.values()].find(d=>d.id===l);for(let[d,g]of Object.entries(u))h[d]=r.get(g)||null}return{nodes:n,rootCandidates:s,warnings:a}}function jo(e){let t=Mi(e),i=Ee.toObject(Ee.decode(t),{longs:Number,enums:Number,bytes:Buffer,defaults:!1,arrays:!0,objects:!0}),r=i.graph||[];if(!r.some(y=>y.ui?.content))throw new Error("GIA \u4E0D\u542B\u53EF\u8BC6\u522B\u7684 UIControlGroup \u4E3B\u56FE");let n=r.find(y=>y.which===21)||null,o=r.filter(y=>Number(y.which)===70),a=i.accessories||[],s=new Set((n?.relatedIds||[]).map(y=>y.id||0)),c=n?s.size?a.filter(y=>s.has(y.id?.id||0)):a:[],l=o.length?[...o,...a.filter(y=>!s.has(y.id?.id||0))]:n?[]:[...r,...a];if(!c.length&&!l.length)throw new Error("GIA \u4E0D\u542B\u5BA2\u6237\u7AEF\u63A7\u4EF6");let u=["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=Go(i);u.push(...h.warnings);let d=null,g=null;if(c.length){let y=wo(c,{reverseSiblings:!0,idOffset:0});u.push(...y.warnings);let m=y.rootCandidates.find(I=>I.kind==="container")||y.rootCandidates[0];if(!m)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6839\u63A7\u4EF6");let S=W("server-container",{id:"sc1",guid:n?.id?.id||0,name:n?.name||"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668",giaRelatedGuids:(n?.ui?.content?.info||[]).find(I=>I.field501===4&&I.field502===4)?.related?.value||[]});S.children=[m],y.rootCandidates.length>1&&u.push(`\u68C0\u6D4B\u5230 ${y.rootCandidates.length} \u4E2A\u65E0\u7236\u8282\u70B9\u63A7\u4EF6\uFF0C\u4EC5\u5BFC\u5165\u4EE5\u201C${m.name}\u201D\u4E3A\u6839\u7684\u6811\u3002`),d={version:1,layoutSchemaVersion:me,meta:{name:n?.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:m.id,script:{controlId:m.id,path:"",source:""},root:S}}if(l.length){let y=wo(l,{reverseSiblings:!1,idOffset:1e3});if(u.push(...y.warnings),!y.rootCandidates.length)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6A21\u677F");let m=W("server-container",{id:"sc1",guid:0,name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"});m.children=y.rootCandidates,g={version:1,layoutSchemaVersion:me,meta:{name:y.rootCandidates.length===1?y.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:y.rootCandidates[0].id,script:{controlId:y.rootCandidates[0].id,path:"",source:""},root:m},d||(d=g)}return{project:d,clientProject:g&&d!==g?g:void 0,scripts:h.scripts,warnings:u,metadata:{gameVersion:i.gameVersion||"",filePath:i.filePath||"",...Number.isSafeInteger(Number(i.modeFlag))?{modeFlag:Number(i.modeFlag)}:{},combined:!!(n&&o.length)}}}function Yo(e){let t=Mi(e),i=Ee.toObject(Ee.decode(t),{longs:Number,enums:Number,defaults:!1,arrays:!0,objects:!0}),r=i.graph||[],n=i.accessories||[],o=[],a=(d,g)=>d!=null&&Object.prototype.hasOwnProperty.call(d,g),s=new Map,c=[];/^\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=r.filter(d=>d.which===70).map(d=>{let g=Ti(d),y=d.ui?.content?.info||[],m=y.find(M=>M.field501===2&&M.field502===6)?.index?.value,S=Co[g],I=y.find(M=>M.field501===4&&M.field502===4),E=I?.related?.value||[];return(!Number.isSafeInteger(m)||m<=0)&&o.push(`${d.name}: Info.index=${m??"<missing>"}\uFF0C\u5FC5\u987B\u662F\u6B63\u6574\u6570`),I||o.push(`${d.name}: \u9876\u5C42 UIControlTemplate \u7F3A\u5C11 Info.related \u8BB0\u5F55`),{id:d.id?.id||0,name:d.name||"",kind:g,actualIndex:m,expectedIndex:S,relatedPresent:!!I,relatedGuids:E}});l.length||o.push("Root.graph \u4E0D\u542B UIControlTemplate(70)");let u=0,h=0;for(let d of[...r,...n]){if(!d.ui?.content)continue;let g=d.id?.id||0,y=d.ui.content,m=Ti(d),S=r.includes(d)&&d.which===70,I=`${d.name||"<unnamed>"}(${g||"<missing-guid>"})`;!Number.isSafeInteger(g)||g<=0||g>2147483647?o.push(`${I}: GraphUnit GUID \u975E\u6CD5`):s.has(g)?o.push(`${I}: GUID \u4E0E ${s.get(g).name||"<unnamed>"} \u91CD\u590D`):s.set(g,d),(d.id?.class!==1||d.id?.type!==8)&&o.push(`${I}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),y.guid!==g&&o.push(`${I}: content.guid=${y.guid??"<missing>"} \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`),S&&d.which!==70&&o.push(`${I}: \u6A21\u677F\u6839 which \u5FC5\u987B\u4E3A UIControlTemplate(70)`),!S&&d.which!==15&&o.push(`${I}: \u9644\u4EF6\u63A7\u4EF6 which \u5FC5\u987B\u4E3A UIControl(15)`);let E=y.info||[],M=E.find(C=>C.field501===1&&C.field502===5),F=E.find(C=>C.field501===2&&C.field502===6);M?.guid?.value!==g&&o.push(`${I}: Info.self GUID \u7F3A\u5931\u6216\u4E0E\u81EA\u8EAB\u4E0D\u4E00\u81F4`),(!Number.isSafeInteger(F?.index?.value)||F.index.value<=0)&&o.push(`${I}: Info.index=${F?.index?.value??"<missing>"}\uFF0C\u5FC5\u987B\u662F\u6B63\u6574\u6570`);let H=E.find(C=>C.field501===4&&C.field502===4);S&&!H&&o.push(`${I}: \u9876\u5C42\u6A21\u677F\u7F3A\u5C11 Info.related \u8BB0\u5F55`),!S&&H&&o.push(`${I}: \u9644\u4EF6\u63A7\u4EF6\u4E0D\u5E94\u5199 Info.related`);let te=ko[m],Z=y.data||[],D=Z.map(C=>`${C.field501}/${C.field502}`),v=te?.map(([C])=>C)||[];te?JSON.stringify(D)!==JSON.stringify(v)&&o.push(`${I}: Data \u69FD\u4F4D\u987A\u5E8F ${D.join(",")}\uFF0C\u5E94\u4E3A ${v.join(",")}`):o.push(`${I}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${m}`);for(let C=0;C<Math.min(Z.length,te?.length||0);C+=1){let N=Z[C],[G,B,se]=te[C];if(a(N,B)||o.push(`${I}: Data ${G} \u7F3A\u5C11 ${B} \u5206\u652F`),!se)continue;a(N.details,se)||o.push(`${I}: Details ${G} \u7F3A\u5C11 ${se} \u5206\u652F`);let L=Eo[G];(N.details?.field501!==L||N.details?.field502!==N.field502||N.details?.field503!==1)&&o.push(`${I}: Details ${G} \u6807\u8BB0\u5E94\u4E3A ${L}/${N.field502}/1`);let he=N.details?.nodeRef;(he?.class!==1||he?.type!==8||he?.id!==g)&&o.push(`${I}: Details ${G} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let A=(d.ui.content.data||[]).find(C=>C.field501===4&&C.field502===86);A&&(a(A.field14,"field17")?u+=1:o.push(`${I}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`),a(A.details?.field14,"field17")?u+=1:o.push(`${I}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`));let w=(d.ui.content.data||[]).find(C=>C.details?.transform)?.details?.transform?.multiPlatform?.platforms||[];w.length!==4&&o.push(`${I}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${w.length}\uFF0C\u5E94\u4E3A 4`);let k=w.map(C=>C.platformType||0);JSON.stringify(k)!==JSON.stringify([0,1,2,3])&&o.push(`${I}: \u5E73\u53F0\u987A\u5E8F ${k.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let z=(d.ui.content.data||[]).find(C=>C.details?.transform)?.details?.transform;z?.multiPlatform?.field502!==Zt[m]&&o.push(`${I}: \u53D8\u6362 preset=${z?.multiPlatform?.field502??"<missing>"}\uFF0C${m} \u5E94\u4E3A ${Zt[m]}`);for(let C of w)a(C.transform,"field508")?h+=1:o.push(`${I}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);c.push({id:g,name:d.name||"",kind:m,template:S,parent:y.parent||0,children:[...y.children||[]],relatedIds:(d.relatedIds||[]).map(C=>C.id||0),dataSignatures:D})}for(let d of c){let g=`${d.name||"<unnamed>"}(${d.id})`;if(JSON.stringify(d.relatedIds)!==JSON.stringify(d.children)&&o.push(`${g}: GraphUnit.relatedIds \u4E0E content.children \u4E0D\u4E00\u81F4`),d.template&&d.parent&&o.push(`${g}: \u9876\u5C42\u6A21\u677F\u4E0D\u5E94\u6709 parent`),!d.template){let y=s.get(d.parent);y?(y.ui?.content?.children||[]).includes(d.id)||o.push(`${g}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):o.push(`${g}: parent=${d.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let y of d.children){let m=s.get(y);m?(m.ui?.content?.parent||0)!==d.id&&o.push(`${g}: child=${y} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):o.push(`${g}: child=${y} \u4E0D\u5B58\u5728`)}}return{valid:o.length===0,errors:o,filePath:i.filePath||"",gameVersion:i.gameVersion||"",templateCount:l.length,accessoryCount:n.length,templates:l,units:c,explicitEmpty:{field17:u,rectField508:h}}}function Dr(e){let t=Mi(e),i=Ee.toObject(Ee.decode(t),{longs:Number,enums:Number,defaults:!1,arrays:!0,objects:!0}),r=(i.graph||[]).filter(C=>C.ui?.content&&Number(C.which)===21),n=(i.graph||[]).filter(C=>Number(C.which)===70),o=(i.graph||[]).filter(C=>Number(C.which)===Et),a=(i.accessories||[]).filter(C=>C.ui?.content),s=[],c=(C,N)=>C!=null&&Object.prototype.hasOwnProperty.call(C,N);/^\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>"}`),r.length!==1&&s.push(`\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F UIControlGroup \u6570\u91CF=${r.length}\uFF0C\u5E94\u4E3A 1`);let l=(i.graph||[]).filter(C=>{let N=Number(C.which);return N===Et||N===70||N===21?!1:!C.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 u=r[0];if(!u)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=[u,...a],d=new Map;for(let C of h){let N=C.id?.id||0,G=`${C.name||"<unnamed>"}(${N||"<missing-guid>"})`;!Number.isSafeInteger(N)||N<=0||N>2147483647?s.push(`${G}: GraphUnit GUID \u975E\u6CD5`):d.has(N)?s.push(`${G}: GUID \u91CD\u590D`):d.set(N,C),(C.id?.class!==1||C.id?.type!==8)&&s.push(`${G}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),C.ui?.content?.guid!==N&&s.push(`${G}: content.guid \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`)}let g=u.id?.id||0,y=u.ui.content,m=`${u.name||"<unnamed>"}(${g})`;u.which!==21&&s.push(`${m}: which \u5FC5\u987B\u4E3A UIControlGroup(21)`);let S=y.info||[];S.find(C=>C.field501===1&&C.field502===5)?.guid?.value!==g&&s.push(`${m}: Info.self GUID \u7F3A\u5931\u6216\u4E0D\u4E00\u81F4`),S.find(C=>C.field501===2&&C.field502===6)?.index?.value!==1&&s.push(`${m}: Info.index \u5FC5\u987B\u4E3A 1`);let I=S.find(C=>C.field501===4&&C.field502===4);I||s.push(`${m}: \u7F3A\u5C11\u663E\u5F0F Info.related \u8BB0\u5F55`);let E=0,M=0,F=(C,N,G,B=!1)=>{let se=C.id?.id||0,L=`${C.name||"<unnamed>"}(${se})`,he=C.ui.content.data||[],Ze=he.map(re=>`${re.field501}/${re.field502}`),bt=G.map(([re])=>re);JSON.stringify(Ze)!==JSON.stringify(bt)&&s.push(`${L}: Data \u69FD\u4F4D\u987A\u5E8F ${Ze.join(",")}\uFF0C\u5E94\u4E3A ${bt.join(",")}`);for(let re=0;re<Math.min(he.length,G.length);re+=1){let Re=he[re],[ze,jt,Yt]=G[re];if(c(Re,jt)||s.push(`${L}: Data ${ze} \u7F3A\u5C11 ${jt} \u5206\u652F`),!Yt)continue;c(Re.details,Yt)||s.push(`${L}: Details ${ze} \u7F3A\u5C11 ${Yt} \u5206\u652F`);let Be=Eo[ze];(Re.details?.field501!==Be||Re.details?.field502!==Re.field502||Re.details?.field503!==1)&&s.push(`${L}: Details ${ze} \u6807\u8BB0\u5E94\u4E3A ${Be}/${Re.field502}/1`);let Bt=Re.details?.nodeRef;(Bt?.class!==1||Bt?.type!==8||Bt?.id!==se)&&s.push(`${L}: Details ${ze} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let Vt=he.find(re=>re.field501===4&&re.field502===(B?23:86)),ie=B?"empty15":"field17";c(Vt?.field14,ie)?B||(E+=1):s.push(`${L}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.${ie} \u7A7A\u4E32`),c(Vt?.details?.field14,ie)?B||(E+=1):s.push(`${L}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.${ie} \u7A7A\u4E32`);let Pe=he.find(re=>re.details?.transform)?.details?.transform,et=Pe?.multiPlatform?.platforms||[];et.length!==4&&s.push(`${L}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${et.length}\uFF0C\u5E94\u4E3A 4`);let wi=et.map(re=>re.platformType||0);JSON.stringify(wi)!==JSON.stringify([0,1,2,3])&&s.push(`${L}: \u5E73\u53F0\u987A\u5E8F ${wi.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let Si=B?Zt["server-container"]:Zt[N];Pe?.multiPlatform?.field502!==Si&&s.push(`${L}: \u53D8\u6362 preset=${Pe?.multiPlatform?.field502??"<missing>"}\uFF0C\u5E94\u4E3A ${Si}`);for(let re of et)c(re.transform,"field508")?M+=1:s.push(`${L}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);return Ze};F(u,"server-container",kl,!0);let H=(u.relatedIds||[]).map(C=>C.id||0),te=new Set(H),Z=a.filter(C=>te.has(C.id?.id||0)),D=Z.map(C=>C.id?.id||0);JSON.stringify(H)!==JSON.stringify(D)&&s.push(`${m}: \u4E3B\u56FE relatedIds \u5FC5\u987B\u6309\u987A\u5E8F\u8986\u76D6\u672C\u7EC4 accessories`);let v=y.data?.find(C=>C.details?.rootChildRef)?.details?.rootChildRef?.guid||0,A=d.get(v);(!A||!Z.includes(A))&&s.push(`${m}: 62/82 \u6839\u8282\u70B9\u5F15\u7528\u4E0D\u5B58\u5728`),D[0]!==v&&s.push(`${m}: \u6839\u5BB9\u5668\u8282\u70B9\u5FC5\u987B\u662F\u672C\u7EC4 accessories[0]`);let w=[];for(let C of Z){let N=C.id?.id||0,G=C.ui.content,B=`${C.name||"<unnamed>"}(${N})`,se=Ti(C);C.which!==15&&s.push(`${B}: which \u5FC5\u987B\u4E3A UIControl(15)`);let L=G.info||[];(L.length!==1||L[0]?.field501!==1||L[0]?.field502!==5||L[0]?.guid?.value!==N)&&s.push(`${B}: \u670D\u52A1\u7AEF\u5BB9\u5668\u5185\u63A7\u4EF6 Info \u5FC5\u987B\u53EA\u542B\u81EA\u8EAB GUID`);let he=ko[se];he||s.push(`${B}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${se}`);let Ze=he?F(C,se,he):[];w.push({id:N,name:C.name||"",kind:se,parent:G.parent||0,children:[...G.children||[]],relatedIds:(C.relatedIds||[]).map(bt=>bt.id||0),dataSignatures:Ze})}let k=w.find(C=>C.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 z=new Map(w.map(C=>[C.id,C]));for(let C of w){let N=`${C.name}(${C.id})`;if(JSON.stringify(C.relatedIds)!==JSON.stringify(C.children)&&s.push(`${N}: relatedIds \u5FC5\u987B\u4E0E\u76F4\u63A5 children \u4E00\u81F4`),C.id!==v){let G=z.get(C.parent);G?G.children.includes(C.id)||s.push(`${N}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):s.push(`${N}: parent=${C.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let G of C.children){let B=z.get(G);B?B.parent!==C.id&&s.push(`${N}: child=${G} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):s.push(`${N}: child=${G} \u4E0D\u5B58\u5728`)}}return{valid:s.length===0,errors:s,filePath:i.filePath||"",gameVersion:i.gameVersion||"",graph:{id:g,name:u.name||"",relatedGuids:I?.related?.value||[],rootGuid:v},accessoryCount:a.length,controls:w,scriptCount:o.length,explicitEmpty:{field17:E,rectField508:M}}}function Bo(e,t=[]){if(!e||e.layoutSchemaVersion===me)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:me};let i=structuredClone(e),r=0;return J(i.root,n=>{let o=n.transformByPlatform||{},a=n.transformByCanvas||{},s=n.name||n.id;for(let l of Object.keys(o))if(!le.includes(l))throw new Error(`${s}: unknown platform ${l}`);let c={};for(let l of le){let u=vt[l],h=X[u].platform,d=Object.keys(X).filter(S=>X[S].platform===h&&a[S]),g=a[u]?u:d[0],y=l==="CONTROLLER_CONSOLE"?c.KEYBOARD:l==="CONTROLLER_MOBILE"?c.TOUCHSCREEN:null,m=o[l]??y??(g?a[g]:null);if(c[l]=m?Ne(m):Er(n.kind),m||t.push(`${s}: ${l} \u65E0\u65E7\u5E03\u5C40\uFF0C\u5DF2\u4F7F\u7528\u63A7\u4EF6\u9ED8\u8BA4\u503C`),!o[l]&&!y&&g&&g!==u&&t.push(`${s}: \u7F3A\u5C11 ${u}\uFF0C\u5DF2\u91C7\u7528 ${g} \u7684\u951A\u70B9\u548C\u5C3A\u5BF8\u53C2\u6570`),!y)for(let S of d)JSON.stringify(c[l])!==JSON.stringify(Ne(a[S]))&&t.push(`${s}: ${S} \u4E0E ${l} \u5E03\u5C40\u51B2\u7A81\uFF0C\u4FDD\u7559${o[l]?"\u5DF2\u6709\u5E73\u53F0":g}\u53C2\u6570`)}He(c,`${s}.transformByPlatform`),n.transformByPlatform=c,delete n.transformByCanvas,r++}),i.layoutSchemaVersion=me,t.unshift(`\u5DF2\u81EA\u52A8\u8FC1\u79FB\u65E7\u5E03\u5C40\uFF1A${r} \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 $r(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 Vr(e,t,i,r=e.canvasId){let n=Le(e.root,t);return!n||n.kind==="server-container"?ye(r):i[n.id]||ye(r)}function qe(e,{warnings:t=[]}={}){if(!e)return ot();if(e=Bo(e,t),(e.root||e.layoutSchemaVersion!==void 0)&&e.layoutSchemaVersion!==me)throw new Error(`\u4EC5\u652F\u6301 layoutSchemaVersion=${me} \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",r=i==="client-control-template"?kt():ot(),n={layoutSchemaVersion:me,version:Number.isSafeInteger(e.version)&&e.version>0?e.version:1,meta:{name:String(e.meta?.name||r.meta.name),assetType:i,sourceFormat:String(e.meta?.sourceFormat||r.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&&X[e.canvasId]?e.canvasId:Ci,selectedId:e.selectedId||r.selectedId,root:Pr(e.root||r.root)};return Wo(n),n}function Wo(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=_r(e.root).id)}function Ho(e){return Ue(xt(e))}function Dl(e,t){let i=!1;return J(e,r=>{r.id===t&&(i=!0)}),i}function $l(e,t,i,r){let o=We(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),r.children.push(t),!o)return;let s=We(e.root,e.canvasId),c=r.kind==="server-container"?ye(e.canvasId):s.boxes[r.id]||ye(e.canvasId),l=Xe(t.transformByPlatform,e.canvasId),u=tt(c,l,{posX:o.centerX,posY:o.centerY,width:o.width,height:o.height});At(e,t,u)}function Gl(e,t){return e.meta.assetType!=="client-control-template"?Rr(e.root,t):(e.root.children||[]).flatMap(i=>Rr(i,t))}function Ko(e,t){let i=yo(e.root,t);if(e.meta.assetType!=="client-control-template")return i;let r=Qt(e),n=new Set;return r&&r.kind!=="server-container"&&J(r,o=>n.add(o.id)),i.filter(o=>n.has(o.id))}function qo(e){let{canvas:t,boxes:i}=We(e.root,e.canvasId),r=ti(e),n=ue(e.root,e.selectedId),o=n?i[n.id]:null;return $({layoutSchemaVersion:me,version:e.version,meta:{...e.meta},canvasId:e.canvasId,canvas:{id:e.canvasId,width:t.width,height:t.height,platform:X[e.canvasId].platform,label:X[e.canvasId].label,presets:Object.values(X).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"&&Qt(e)?.id||""},tree:Gl(e,r),boxes:Ko(e,i),inspector:bo(n,e.canvasId,o||t,r),root:e.root})}function At(e,t,i){let r=We(e.root,e.canvasId),n=Vr(e,t.id,r.boxes),o={};if(t.syncAllDevices!==!1)for(let a of le){if(a===it(e.canvasId))continue;let s=vt[a],c=We(e.root,s,a);o[a]=Vr(e,t.id,c.boxes,s)}t.transformByPlatform=go({transformByPlatform:t.transformByPlatform,source:i,canvasId:e.canvasId,syncAllDevices:t.syncAllDevices!==!1,sourceParentBox:n,targetParentBoxByPlatform:o})}var Vl=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","itemPrefabId","layoutConstraintFixedCount"]),jl=new Set(["posX","posY","width","height"]),Yl=new Set(["anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]);function Bl(e){if(typeof e=="number"&&Number.isFinite(e))return e>>>0;if(typeof e=="string"){let t=e.trim();if(t.startsWith("#")){let r=t.slice(1);if(r.length===6)return(4278190080|parseInt(r,16))>>>0;if(r.length===8)return parseInt(r,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 Ge(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function Uo(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 Hl=new Set(["fontSize","minimumFontSize","imageId","clickAudioId","softEdgeWidthX","softEdgeWidthY","horizontalSoftRange","verticalSoftRange","fillAmount","cellSizeX","cellSizeY","spacingX","spacingY","padding1X","padding1Y","padding2X","padding2Y","previewCount","keyboardKeyCode","controllerKeyCode","itemPrefabId","layoutConstraintFixedCount"]),Ul=new Set(["active","visible","canControllerFocus","isolateNavigation","disableKeyEventPassthrough","disableCursorEventPassthrough","showCursor","adaptiveFontSize","enableOutline","enableMask","enableSoftEdge","enableFill","reverseMaskArea","raycastTarget","interactable","showScrollBar"]),Ll=new Set(["name","horizontalAlignment","verticalAlignment","text","softEdgeMode","fillType","fillHorizontalType","fillVerticalType","fillRadial90Type","fillRadialType","scrollDirection","layoutConstraint","referencedPrefabId","animationId"]),Lo=new Set(["unavailableChildId","hoverChildId","pressedChildId","selectedChildId"]),Xo={scrollDirection:["Horizontal","Vertical"],layoutConstraint:["AutoWrap","Fixed"],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 Xl(e,t){if(!t||typeof t!="object")throw new Error("patch requires op");let i=t.op;if(i==="select")return t.id&&ue(e.root,t.id)&&(e.selectedId=t.id),e;if(i==="pick"){let{boxes:r}=We(e.root,e.canvasId),n=Ko(e,r),o=vo(n,Number(t.x),Number(t.y));return o&&(e.selectedId=o),e}if(i==="setCanvas")return t.canvasId&&X[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 r=t.assetType==="client-control-template"?kt():ot();return e.version=r.version,e.meta=r.meta,e.canvasId=r.canvasId,e.selectedId=r.selectedId,e.root=r.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 r=W(t.kind,{id:Ar(e.root),guid:Ho(e.root),name:t.name||`\u65B0${t.kind==="container"?"\u5BB9\u5668\u8282\u70B9":t.kind}\u6A21\u677F`});return e.root.children.push(r),e.selectedId=r.id,e}if(i==="add"){let r=ue(e.root,t.parentId||e.selectedId);if(!r)throw new Error("add: parent not found");let n=ho(r,t.kind,{id:Ar(e.root),guid:Ho(e.root),name:t.name});return e.selectedId=n.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 r=ue(e.root,t.id||e.selectedId),n=r?Le(e.root,r.id):null,o=ue(e.root,t.parentId);if(!r||r.kind==="server-container"||!n)throw new Error("reparent: node not found");if(!o)throw new Error("reparent: parent not found");if(o.id===r.id||Dl(r,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"&&n.kind==="server-container")return e;if(n.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 $l(e,r,n,o),e.selectedId=r.id,e}if(i==="moveSibling"){let r=ue(e.root,t.id||e.selectedId),n=r?Le(e.root,r.id):null;if(!r||!n)throw new Error("moveSibling: node not found");let o=n.children.findIndex(c=>c.id===r.id),a=t.direction==="up"?-1:t.direction==="down"?1:0,s=o+a;return!a||s<0||s>=n.children.length||(n.children.splice(o,1),n.children.splice(s,0,r),e.selectedId=r.id),e}if(i==="remove"){let r=t.id||e.selectedId,n=Le(e.root,r);if(n?.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 po(e.root,r)&&(J(e.root,o=>{if(o.kind==="button")for(let a of Lo)o[a]&&!ue(e.root,o[a])&&(o[a]=null)}),e.selectedId=n?n.id:e.root.id),e}if(i==="set"){let r=ue(e.root,t.id||e.selectedId);if(!r)throw new Error("set: node not found");let n=t.key;n==="reverseMask"&&(n="reverseMaskArea");let o=t.value;if(n.startsWith("giaRaw.")){let l=n.slice(7);if(!l||l.includes("."))throw new Error("invalid raw GIA field path");let u=co(r.kind,l);if(!u)throw new Error(`unknown raw GIA field for ${r.kind}: ${l}`);if(r.giaRaw||={},r.giaRaw[l]=Ir(u,o),l==="footerField505"&&[0,1].includes(r.giaRaw[l])&&(r.canControllerFocus=r.giaRaw[l]===1),r.kind==="cursor"&&l==="cursorField501"&&[0,1].includes(r.giaRaw[l])&&(r.raycastTarget=r.giaRaw[l]===1),(r.kind==="textbox"||r.kind==="textwindow")&&l==="textAlign"){let h={0:"Left",1:"Middle",2:"Right"}[r.giaRaw[l]];h&&(r.horizontalAlignment=h)}if(r.kind==="image"&&l==="imageFillType"){let h={1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[r.giaRaw[l]];h&&(r.fillType=h)}return r.kind==="keyhint"&&l==="keyHintField502"&&(r.keyboardKeyCode=r.giaRaw[l]),r.kind==="keyhint"&&l==="keyHintField501"&&(r.controllerKeyCode=r.giaRaw[l]),e}if(n==="syncAllDevices"){if(r.syncAllDevices=Uo(o),r.syncAllDevices){let l=Xe(r.transformByPlatform,e.canvasId);At(e,r,l)}return e}if(Vl.has(n)){if(n.endsWith("Color")&&(o=Bl(o)),Hl.has(n)){if(o=Ge(o,n),o<0)throw new Error(`${n} must not be negative`);if((n==="imageId"||n==="clickAudioId"||n==="keyboardKeyCode"||n==="controllerKeyCode")&&(o=Math.trunc(o)),n==="fillAmount"&&o>1)throw new Error("fillAmount must be between 0 and 1")}if(Ul.has(n)&&(o=Uo(o)),Ll.has(n)&&(o=String(o??"")),n==="horizontalAlignment"&&!["Left","Middle","Right"].includes(o))throw new Error("invalid horizontalAlignment");if(n==="verticalAlignment"&&!["Top","Middle","Bottom"].includes(o))throw new Error("invalid verticalAlignment");if(Xo[n]&&!Xo[n].includes(o))throw new Error(`invalid ${n}`);if(Lo.has(n))if(o===""||o===void 0||o===null)o=null;else{o=String(o);let l=ue(e.root,o);if(!l||l===r||l.kind==="server-container"||!(r.children||[]).some(u=>u.id===o))throw new Error(`${n} must reference a direct child of this button`)}if(r[n]=o,n==="canControllerFocus"&&(r.giaRaw.footerField505=o?1:0),r.kind==="cursor"&&n==="raycastTarget"&&(r.giaRaw.cursorField501=o?1:0),(r.kind==="textbox"||r.kind==="textwindow")&&n==="horizontalAlignment"&&(r.giaRaw.textAlign={Left:0,Middle:1,Right:2}[o]),(r.kind==="textbox"||r.kind==="textwindow")&&n==="verticalAlignment"&&delete r.giaRaw.textVerticalAlign,r.kind==="image"&&n==="fillType"){let l={Horizontal:1,Vertical:2,Radial90:3,Radial180:4,Radial360:5}[o];l&&(r.giaRaw.imageFillType=l)}return r.kind==="reference"&&n==="referencedPrefabId"&&(r.giaRaw.templateRefSlot=o),r.kind==="grid"&&n==="previewCount"&&(r.giaRaw.gridField511=Math.trunc(o)),r.kind==="keyhint"&&n==="keyboardKeyCode"&&(r.giaRaw.keyHintField502=Math.trunc(o)),r.kind==="keyhint"&&n==="controllerKeyCode"&&(r.giaRaw.keyHintField501=Math.trunc(o)),(r.kind==="animation"||r.kind==="fullscreen")&&n==="animationId"&&(r.giaRaw[r.kind==="animation"?"effectSlot":"fullscreenEffectSlot"]=o),e}let{boxes:a}=We(e.root,e.canvasId),s=Vr(e,r.id,a),c=Xe(r.transformByPlatform,e.canvasId);if(n==="anchorType"){let l=Gr(a[r.id]),u=no(c,o);return u=tt(s,u,l),At(e,r,u),e}if(n==="rotationZ"){let l={...c,rotation:{...c.rotation,z:Ge(o,n)}};return At(e,r,l),e}if(Yl.has(n)){let l=Gr(a[r.id]),u={...c,anchorMin:{...c.anchorMin},anchorMax:{...c.anchorMax},pivot:{...c.pivot}};return n==="anchorMinX"&&(u.anchorMin.x=Ge(o,n)),n==="anchorMinY"&&(u.anchorMin.y=Ge(o,n)),n==="anchorMaxX"&&(u.anchorMax.x=Ge(o,n)),n==="anchorMaxY"&&(u.anchorMax.y=Ge(o,n)),n==="pivotX"&&(u.pivot.x=Ge(o,n)),n==="pivotY"&&(u.pivot.y=Ge(o,n)),At(e,r,tt(s,u,l)),e}if(jl.has(n)){let l=Gr(a[r.id]),u=Ge(o,n);if((n==="width"||n==="height")&&u<0)throw new Error(`${n} must not be negative`);return l[n]=u,At(e,r,tt(s,c,l)),e}throw new Error(`set: unknown key ${n}`)}if(i==="replace"){let r=qe(t.project);return e.version=r.version,e.meta=r.meta,e.canvasId=r.canvasId,e.selectedId=r.selectedId,e.root=r.root,e}throw new Error(`unknown op ${i}`)}function jr(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,r=JSON.parse(JSON.stringify(e));return Xl(r,t),Wo(r),r.version=i+1,Object.keys(e).forEach(n=>{delete e[n]}),Object.assign(e,r),e}function Gr(e){return e?{posX:e.centerX,posY:e.centerY,width:e.width,height:e.height}:{posX:0,posY:0,width:0,height:0}}import Wl from"fengari";var{lua:f,lauxlib:Q,lualib:Jo,to_luastring:Ni,to_jsstring:Kl}=Wl,ql=f.LUA_TNIL,Jl=f.LUA_TBOOLEAN,Ql=f.LUA_TNUMBER,Zl=f.LUA_TSTRING,Qo=f.LUA_TTABLE,ec=f.LUA_TFUNCTION,Yr=f.LUA_TUSERDATA,Ae=f.LUA_OK,Zo=new WeakMap,Br=Symbol("luaTableEntries"),Hr={__scriptHostKey:!0};function R(e){return Ni(String(e))}function at(e,t){Zo.set(e,t)}function Ie(e){return Zo.get(e)}var ii=class{constructor(t){this.value=t}};function ae(e,t,i){if(i instanceof ii){f.lua_pushnumber(e,i.value);return}if(i==null){f.lua_pushnil(e);return}let r=typeof i;if(r==="boolean"){f.lua_pushboolean(e,i);return}if(r==="number"){Number.isInteger(i)&&Math.abs(i)<=2147483647?f.lua_pushinteger(e,i):f.lua_pushnumber(e,i);return}if(r==="string"){f.lua_pushstring(e,R(i));return}if(r==="function"){rc(e,t,i);return}if(i&&i[Br]){let n=i[Br];f.lua_createtable(e,Array.isArray(i)?i.length:0,n.length);for(let[o,a]of n)ae(e,t,o),ae(e,t,a),f.lua_settable(e,-3);return}if(Array.isArray(i)){f.lua_createtable(e,i.length,0);for(let n=0;n<i.length;n++)ae(e,t,i[n]),f.lua_rawseti(e,-2,n+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.__kind==="ServerSignal"){t.pushSignal(e,i);return}if(i&&(i.SetEase||i.Append)){t.pushTween(e,i);return}if(r==="object"){f.lua_createtable(e,0,Object.keys(i).length);for(let[n,o]of Object.entries(i))ae(e,t,o),f.lua_setfield(e,-2,R(n));return}f.lua_pushnil(e)}function q(e,t){if(f.lua_isnil(e,t)||f.lua_type(e,t)===f.LUA_TNONE)return"";if(!f.lua_isstring(e,t)&&f.lua_type(e,t)!==f.LUA_TNUMBER)return`lua_type=${f.lua_type(e,t)}`;let i=f.lua_tostring(e,t);return i==null?"":Kl(i)}function Ve(e,t){t=f.lua_absindex(e,t);let i=f.lua_type(e,t);if(i===Yr)return Ie(f.lua_touserdata(e,t));if(i===Qo){f.lua_pushlightuserdata(e,Hr),f.lua_rawget(e,t);let r=f.lua_type(e,-1)===Yr?f.lua_touserdata(e,-1):null;return f.lua_pop(e,1),r?Ie(r):null}return null}function de(e,t,i){i=f.lua_absindex(e,i);let r=f.lua_type(e,i);if(r===ql)return null;if(r===Jl)return!!f.lua_toboolean(e,i);if(r===Ql)return f.lua_isinteger(e,i)?f.lua_tointeger(e,i):f.lua_tonumber(e,i);if(r===Zl)return q(e,i);if(r===Yr){let n=f.lua_touserdata(e,i);return Ie(n)??n}if(r===ec)return tc(e,t,i);if(r===Qo){let n=Ve(e,i);if(n)return n;let o=[];for(f.lua_pushnil(e);f.lua_next(e,i)!==0;){let l=de(e,t,-2),u=de(e,t,-1);o.push([l,u]),f.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 c=s>0?[]:{};for(let[l,u]of o)Array.isArray(c)&&Number.isInteger(l)&&l>=1?c[l-1]=u:(typeof l=="string"||typeof l=="number")&&(c[l]=u);return Object.defineProperty(c,Br,{value:o}),c}return null}function tc(e,t,i){t.luaFunctions||(t.luaFunctions=new Map);let r=typeof f.lua_topointer=="function"?f.lua_topointer(e,i):null;if(r!=null&&t.luaFunctions.has(r))return t.luaFunctions.get(r);f.lua_pushvalue(e,i);let n=Q.luaL_ref(e,f.LUA_REGISTRYINDEX),o=ic(e,t,n);return r!=null&&t.luaFunctions.set(r,o),o}function ic(e,t,i){let r=(...n)=>{if(r.__luaRef==null)throw new Error("attempt to call a released Lua callback");let o=f.lua_gettop(e);f.lua_rawgeti(e,f.LUA_REGISTRYINDEX,r.__luaRef);for(let l of n)ae(e,t,l);if(f.lua_pcall(e,n.length,f.LUA_MULTRET,0)!==Ae){let l=q(e,-1);throw f.lua_settop(e,o),new Error(l)}let s=f.lua_gettop(e)-o,c=[];for(let l=1;l<=s;l++)c.push(de(e,t,o+l));if(f.lua_settop(e,o),c.length!==0)return c.length===1?c[0]:c};return r.__luaRef=i,r.__luaState=e,r}function ea(e){e?.__luaRef!=null&&(e.__luaHolds=(e.__luaHolds||0)+1)}function ta(e,t){if(!t||t.__luaRef==null||!t.__luaState)return;if(t.__luaHolds>1){t.__luaHolds-=1;return}let i=t.__luaState;if((!e?.luaStates||e.luaStates.has(i))&&Q.luaL_unref(i,f.LUA_REGISTRYINDEX,t.__luaRef),t.__luaRef=null,t.__luaState=null,e?.luaFunctions)for(let[r,n]of e.luaFunctions)n===t&&e.luaFunctions.delete(r)}function rc(e,t,i){f.lua_pushlightuserdata(e,i),f.lua_pushlightuserdata(e,t),f.lua_pushcclosure(e,function(n){let o=f.lua_touserdata(n,f.lua_upvalueindex(1)),a=f.lua_touserdata(n,f.lua_upvalueindex(2)),s=f.lua_gettop(n),c=[];for(let l=1;l<=s;l++)c.push(de(n,a,l));try{let l=o(...c);if(Array.isArray(l)&&l.__multi){for(let u of l)ae(n,a,u);return l.length}return l===void 0?0:(ae(n,a,l),1)}catch(l){return f.lua_pushstring(n,R(String(l&&l.message?l.message:l))),f.lua_error(n)}},2)}function ia(e){!e||typeof f.lua_close!="function"||f.lua_close(e)}function ra(e){if(Q.luaL_loadstring(e,R(["local nativeGetMetatable = getmetatable","getmetatable = function(value)",' if type(value) == "string" then return nil end'," return nativeGetMetatable(value)","end"].join(`
|
|
108
|
-
`)))===Ae&&f.lua_pcall(e,0,0,0),f.lua_settop(e,0),f.lua_pushnil(e),f.lua_setglobal(e,R("_VERSION")),f.lua_getglobal(e,R("string")),!f.lua_isnil(e,-1))for(let i of["dump","pack","unpack"])f.lua_pushnil(e),f.lua_setfield(e,-2,R(i));if(f.lua_pop(e,1),f.lua_pushnil(e),f.lua_setglobal(e,R("io")),f.lua_getglobal(e,R("os")),!f.lua_isnil(e,-1))for(let i of Object.keys({execute:1,getenv:1,remove:1,rename:1,tmpname:1,setlocale:1,exit:1}))f.lua_pushnil(e),f.lua_setfield(e,-2,R(i));f.lua_pop(e,1),f.lua_getglobal(e,R("debug")),f.lua_isnil(e,-1)?f.lua_pop(e,1):(f.lua_getfield(e,-1,R("traceback")),f.lua_newtable(e),f.lua_pushvalue(e,-2),f.lua_setfield(e,-2,R("traceback")),f.lua_setglobal(e,R("debug")),f.lua_pop(e,2)),f.lua_getglobal(e,R("math")),f.lua_isnil(e,-1)||(f.lua_pushcfunction(e,i=>{let r=f.lua_tonumber(i,1);return f.lua_pushboolean(i,Number.isNaN(r)),1}),f.lua_setfield(e,-2,R("isnan")),f.lua_pushcfunction(e,i=>{let r=f.lua_tonumber(i,1);return f.lua_pushboolean(i,r===1/0||r===-1/0),1}),f.lua_setfield(e,-2,R("isinf"))),f.lua_pop(e,1),f.lua_pushnil(e),f.lua_setglobal(e,R("package")),f.lua_pushnil(e),f.lua_setglobal(e,R("load")),f.lua_pushnil(e),f.lua_setglobal(e,R("loadfile")),f.lua_pushnil(e),f.lua_setglobal(e,R("dofile")),f.lua_pushnil(e),f.lua_setglobal(e,R("collectgarbage")),f.lua_pushnil(e),f.lua_setglobal(e,R("coroutine")),f.lua_pushnil(e),f.lua_setglobal(e,R("fengari"))}var xe=(e,t=0)=>Number.isFinite(Number(e))?Number(e):t,na=e=>e?.Name||e,Fi=e=>Math.max(0,Math.min(1,xe(e)));function ri(e){let t=e.parent?ri(e.parent):[e.runtime.canvasWidth,e.runtime.canvasHeight];return[Math.max(0,(e.anchorMaxX-e.anchorMinX)*t[0]+xe(e.sizeDeltaX)),Math.max(0,(e.anchorMaxY-e.anchorMinY)*t[1]+xe(e.sizeDeltaY))]}function ni(e){let[t,i]=ri(e),r=na(e.scrollDirection)==="Horizontal",n=Math.max(1,xe(e.cellSizeX,50)),o=Math.max(1,xe(e.cellSizeY,50)),a=Math.max(0,xe(e.spacingX)),s=Math.max(0,xe(e.spacingY)),c=Math.max(0,xe(e.padding1X)),l=Math.max(0,xe(e.padding1Y)),u=Math.max(0,xe(e.padding2X)),h=Math.max(0,xe(e.padding2Y)),d=r?i-l-h:t-c-u,g=r?o:n,y=r?s:a,m=na(e.layoutConstraint)==="Fixed"?Math.max(1,Math.floor(xe(e.layoutConstraintFixedCount,1))):Math.max(1,Math.floor((d+y)/(g+y))),S=Math.ceil(e.itemCount/m),I=S?r?c+u+S*n+(S-1)*a:l+h+S*o+(S-1)*s:0,E=r?t:i,M=Math.max(0,I-E);return{width:t,height:i,horizontal:r,cellW:n,cellH:o,gapX:a,gapY:s,left:c,top:l,right:u,bottom:h,lanes:m,length:I,viewport:E,max:M,offset:Fi(e.scrollProgress)*M}}function _t(e){let t=ni(e);for(let i=0;i<(e._gridItems?.length||0);i+=1){let r=e._gridItems[i];if(!r.alive||r.parent!==e)continue;let n=Math.floor(i/t.lanes),o=i%t.lanes,a=t.horizontal?n:o,s=t.horizontal?o:n,c=t.left+a*(t.cellW+t.gapX)+t.cellW/2-(t.horizontal?t.offset:0),l=-t.top-s*(t.cellH+t.gapY)-t.cellH/2+(t.horizontal?0:t.offset),u={anchorMinX:0,anchorMaxX:0,anchorMinY:1,anchorMaxY:1,pivotX:.5,pivotY:.5,sizeDeltaX:t.cellW,sizeDeltaY:t.cellH,anchoredPositionX:c,anchoredPositionY:l};Object.entries(u).some(([h,d])=>r[h]!==d)&&(Object.assign(r,u),r.markPlayDirty(!0))}return t}var oa={container:"ClientUIContainerControl",textbox:"ClientUITextBoxControl",textwindow:"ClientUITextWindowControl",image:"ClientUIImageControl",button:"ClientUIPresetButtonControl",cursor:"ClientUICursorEventAreaControl",grid:"ClientUIGridScrollerControl",keyhint:"ClientUIKeyHintControl",animation:"ClientUIAnimationControl",fullscreen:"ClientUIFullscreenAnimationControl",reference:"ClientUIReferenceControl"},nc=["alive","Id","prefabIndex","active","activeInHierarchy","visible"],Oi=new Set(["active","visible","parent","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]),oc=["name","parent","anchoredPositionX","anchoredPositionY","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY","localScaleX","localScaleY","localScaleZ","localRotationX","localRotationY","localRotationZ","canControllerFocus"],ac={image:["imageSource","imageId"],grid:["itemCount","scrollDirection","layoutConstraint","layoutConstraintFixedCount"],reference:["referencedPrefabIndex"]},sc={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"]},lc=["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"],aa=["AddCursorEventListener","RemoveCursorEventListener","RemoveCursorEventListeners","RemoveAllCursorEventListeners","SimulateCursorClick"],cc={image:["SetImage","SetSoftEdgeWidth","SetFillUnused","SetFillHorizontal","SetFillVertical","SetFillRadial90","SetFillRadial180","SetFillRadial360"],button:aa,cursor:aa,animation:["PlayAnimation","StopAnimation"],grid:["RefreshItems","GetItemIndex","GetItemSize","GetItemSpacing","GetPadding","ScrollToItemAt","GetContentLength"]};function Lr(e,t){return nc.includes(t)||(ac[e.kind]||[]).includes(t)?"ro":oc.includes(t)||(sc[e.kind]||[]).includes(t)?"rw":null}var uc=["localRotationX","localRotationY","localRotationZ"],Pt=Math.PI/180;function sa(e,t){return[e[3]*t[0]+e[0]*t[3]+e[1]*t[2]-e[2]*t[1],e[3]*t[1]-e[0]*t[2]+e[1]*t[3]+e[2]*t[0],e[3]*t[2]+e[0]*t[1]-e[1]*t[0]+e[2]*t[3],e[3]*t[3]-e[0]*t[0]-e[1]*t[1]-e[2]*t[2]]}function Ur(e){if(Object.is(e,-0))return e;let t=(e%360+360)%360,i=Math.round(t*1e6)/1e6;return i>=360?0:i}function la(e,t,i){let r=E=>[Math.sin(E*Pt/2),Math.cos(E*Pt/2)],[n,o]=r(e),[a,s]=r(t),[c,l]=r(i),[u,h,d,g]=sa(sa([0,a,0,s],[n,0,0,o]),[0,0,c,l]),y=Math.max(-1,Math.min(1,-2*(h*d-g*u))),m,S,I;return Math.abs(y)>.999999?(m=Math.sign(y)*90,S=2*Math.atan2(h,g)/Pt,I=0):(m=Math.asin(y)/Pt,S=Math.atan2(2*(g*h+u*d),1-2*(u*u+h*h))/Pt,I=Math.atan2(2*(g*d+u*h),1-2*(u*u+d*d))/Pt),[Ur(m),Ur(S),Ur(I)]}function ca(e,t){return lc.includes(t)||(cc[e.kind]||[]).includes(t)}var fc={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}},Je=class e{constructor(t,i){this.runtime=t,this.kind=i.kind||"container",this.typeofName=oa[this.kind]||oa.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,(this.kind==="grid"||this.kind==="textwindow")&&(this.runtime.scrollControls||=new Set,this.runtime.scrollControls.add(this));let r=fc[this.kind]||{};for(let[n,o]of Object.entries(r))this[n]===void 0&&(this[n]=i[n]!==void 0?i[n]:o);if(this.kind==="grid"&&(this.scrollProgress=i.scrollProgress??0),i.children)for(let n of i.children){let o=n instanceof e?n:new e(t,n);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 r=t;r;r=r._parent)if(r===this)throw new Error("cannot parent a control to itself or its descendant");let i=this._parent;if(i){let r=i.children.indexOf(this);r>=0&&i.children.splice(r,1),i.markPlayDirty(!0)}else{let r=this.runtime.roots.indexOf(this);r>=0&&this.runtime.roots.splice(r,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}get scrollProgress(){return this._scrollProgress??0}set scrollProgress(t){if(typeof t!="number"||!Number.isFinite(t))throw new Error("scrollProgress must be a finite number");this._scrollProgress=Fi(t),this.markPlayDirty()}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),r=this;for(let n of i)if(r=r.GetChild(n),!r)return null;return r}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,r=i.indexOf(this);if(r<0)return!1;let n=i.length-1;return!Number.isInteger(t)||t<0||t>n?!1:(i.splice(r,1),i.splice(n-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,r){this.localScaleX=t,this.localScaleY=i,this.localScaleZ=r,this.markPlayDirty()}GetLocalRotation(){return la(this.localRotationX,this.localRotationY,this.localRotationZ)}luaFieldValue(t){let i=uc.indexOf(t);return i<0?this[t]:la(this.localRotationX,this.localRotationY,this.localRotationZ)[i]}SetLocalRotation(t,i,r){this.localRotationX=t,this.localRotationY=i,this.localRotationZ=r,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,r){let n=t.get(i)||[];n.push(r),t.set(i,n),this.runtime.retainLuaCallback?.(r)}_removeListener(t,i,r){let n=t.get(i);if(!n)return;let o=n.filter(a=>a!==r);t.set(i,o);for(let a=o.length;a<n.length;a++)this.runtime.unrefLuaCallback?.(r)}_removeListeners(t,i){let r=t.get(i)||[];for(let n of r)this.runtime.unrefLuaCallback?.(n);t.delete(i)}_removeAllListeners(t){for(let i of t.values())for(let r of i)this.runtime.unrefLuaCallback?.(r);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 r=this.cursorListeners.get(t)||[];for(let n of r)n(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 r of i)if(r()===!0)return!0;return!1}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,r){this.navConfig.set(t,{mode:i,target:r})}GetControllerNavigation(t){let i=this.navConfig.get(t),r=i?[i.mode,i.target]:[null,null];return r.__multi=!0,r}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(t,i){if(!Number.isInteger(t)||t<0||t>2e3)throw new Error("RefreshItems: simulator supports 0..2000 items");if(typeof i!="function")throw new Error("RefreshItems: callback must be a function");if(!this.alive||this._refreshingGrid)throw new Error("RefreshItems: destroyed control or recursive refresh");if(t&&!this.runtime.templates.has(Number(this.itemPrefabIndex)))throw new Error("RefreshItems: item template not found");if(t&&["OnInit","OnDestroy"].includes(this.runtime.lifecyclePhase))throw new Error("RefreshItems: items cannot be created during OnInit/OnDestroy");this._refreshingGrid=!0;try{this._gridItems||=[];let r=[];for(let n of this._gridItems)n.alive&&n.parent===this&&n.prefabIndex===Number(this.itemPrefabIndex)&&r.length<t?r.push(n):n.alive&&n.parent===this&&this.runtime.destroyControl(n);for(this._gridItems=r;r.length<t;){let n=this.runtime.instantiate(this.itemPrefabIndex,this,this.runtime.lifecyclePhase);if(!n)throw new Error("RefreshItems: could not instantiate item");r.push(n),n.SetActive(!0)}this.itemCount=t,_t(this),this.markPlayDirty(!0);for(let n=0;n<r.length&&this.alive;n+=1)i(r[n],n)}finally{this._refreshingGrid=!1}}GetItemIndex(t){return t?.alive&&t.parent===this?this._gridItems?.indexOf(t)??-1:-1}GetItemSize(){return[this.cellSizeX,this.cellSizeY]}GetItemSpacing(){return[this.spacingX,this.spacingY]}GetPadding(){return[this.padding1Y,this.padding2Y,this.padding1X,this.padding2X]}ScrollToItemAt(t,i){if(!Number.isInteger(t)||t<0||t>=this.itemCount)throw new Error("ScrollToItemAt: item index out of range");let r=ni(this),n=r.horizontal?r.cellW:r.cellH,o=r.horizontal?r.gapX:r.gapY,a=(r.horizontal?r.left:r.top)+Math.floor(t/r.lanes)*(n+o),s=i?.Name||i;if(!["Top","Center","Bottom"].includes(s))throw new Error("ScrollToItemAt: invalid alignment");let c=a-(s==="Center"?(r.viewport-n)/2:s==="Bottom"?r.viewport-n:0);this.scrollProgress=r.max?Fi(c/r.max):0,_t(this),this.markPlayDirty(!0)}GetContentLength(){return ni(this).length}};function Fe(e,t){t(e);for(let i of e.children)Fe(i,t)}function Xr(e,t=[],i=""){t.push(`${i}${e.name||"(unnamed)"} [${e.typeofName}] Id=${e.Id}`);for(let r of e.children)Xr(r,t,i+" ");return t}function zi(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 ua={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-zi(1-e),OutBounce:zi,InOutBounce:e=>e<.5?(1-zi(1-2*e))/2:(1+zi(2*e-1))/2};function fa(e,t){let i=ua[e]||ua.Linear;return t<=0?0:t>=1?1:i(t)}function Rt(e,t,i,r=255){let n=Di(e),o=Di(t),a=Di(i);return((r==null?255:Di(r))<<24|n<<16|o<<8|a)>>>0}function oi(e){let t=e>>>0;return[t>>>16&255,t>>>8&255,t&255,t>>>24&255]}function Di(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(255,Math.trunc(t))):0}function da(e,t,i){let r=oi(e),n=oi(t);return Rt(r[0]+(n[0]-r[0])*i,r[1]+(n[1]-r[1])*i,r[2]+(n[2]-r[2])*i,r[3]+(n[3]-r[3])*i)}var dc=new Set(["fontColor","bgColor","outlineColor","imageColor"]),hc=new Set(["fontSize","minimumFontSize"]),Wr=1e-9;function pc(e,t){return typeof e?.luaFieldValue=="function"?e.luaFieldValue(t):e[t]}var ai=class{constructor(t,i,r,n){this.runtime=t,this.object=i,this.data={...r},this.duration=Math.max(0,Number(n)||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,this.dead=!1,this.completed=!1}capture(){this.from={},this.to={};for(let[t,i]of Object.entries(this.data)){let r=pc(this.object,t);this.from[t]=r,this.to[t]=this.relative?Number(r)+Number(i):i}}restoreInitial(){this.from={...this.initialFrom},this.to={...this.initialTo}}SetEase(t){return this.easeName=typeof t=="string"?t:t?.Name||"Linear",this}SetRelative(t){return this.relative=!!t,this}Play(){return this.dead?this:this.playing?(this.paused=!1,this):this._start(!1)}_begin(t){this.playing=!0,this.paused=!1,this.elapsed=0,this.loopIndex=0,this.killed=!1,this.completed=!1,t&&this.initialFrom?this.restoreInitial():(this.capture(),this.initialFrom={...this.from},this.initialTo={...this.to})}_start(t){return this._begin(t),this.runtime.tweens.add(this),this.runtime.animations.add(this),this}get loopCount(){return this.loops>0?this.loops:1}Pause(){this.paused=!0}Resume(){this.paused=!1}Restart(){return this.dead?this:this._start(!0)}Complete(){this.dead||this.completed||(this.initialFrom||this._begin(!1),this.apply(1),this.finish(!0))}Kill(t){t?this.Complete():this.finish(!1),this.dead=!0}SetOnComplete(t){return this.onComplete=t,this}SetOnStepComplete(t){return this.onStepComplete=t,this}SetLoops(t){return this.loops=t,this}apply(t){if(this.object?.alive===!1)return;let i=fa(this.easeName,t),r=!1,n=!1;for(let o of Object.keys(this.to)){let a=this.from[o],s=this.to[o];if(dc.has(o)&&typeof a=="number"&&typeof s=="number")this.object[o]=da(a,s,i);else if(typeof a=="number"&&typeof s=="number"){let c=a+(s-a)*i;this.object[o]=hc.has(o)?Math.trunc(c):c}else this.object[o]=i>=1?s:a;r=!0,Oi.has(o)&&(n=!0)}r&&typeof this.object?.markPlayDirty=="function"&&this.object.markPlayDirty(n)}_advance(t,i){this.elapsed+=t;let r=this.duration<=0?1:Math.min(1,this.elapsed/this.duration);return this.apply(r),r<1?!1:i>=0&&this.loopIndex+1>=i?!0:(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.loopIndex++,this.elapsed=0,this.restoreInitial(),!1)}step(t){!this.playing||this.paused||this.killed||this._advance(t,this.loops<0?-1:this.loopCount)&&(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.finish(!0))}finish(t){this.playing=!1,this.killed=!0,t&&(this.completed=!0),this.runtime.tweens.delete(this),this.runtime.animations.delete(this),t&&this.onComplete&&this.runtime.safeCall(this.onComplete)}},Tt=class{constructor(t){this.runtime=t,this.steps=[],this.playing=!1,this.paused=!1,this.killed=!1,this.dead=!1,this.completed=!1,this.elapsed=0,this.loops=1,this.loopIndex=0,this.onComplete=null,this.onStepComplete=null,this._entries=null}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.dead?this:this.playing?(this.paused=!1,this):this._play()}_play(){return this.playing=!0,this.paused=!1,this.killed=!1,this.completed=!1,this.elapsed=0,this.loopIndex=0,this._schedule(),this.runtime.sequences.add(this),this.runtime.animations.add(this),this}_schedule(){let t=0,i=0,r=!1,n=[],o=a=>a.duration*a.loopCount;for(let a of this.steps)if(a.kind==="tween"&&a.parallel){let s=r?i:t;n.push({at:s,tween:a.tween}),t=Math.max(t,s+o(a.tween))}else a.kind==="tween"?(n.push({at:t,tween:a.tween}),i=t,r=!0,t+=o(a.tween)):a.kind==="interval"?(i=t,r=!0,t+=a.duration):a.kind==="callback"?n.push({at:t,fn:a.fn}):a.kind==="insert"?(n.push({at:a.time,tween:a.tween}),t=Math.max(t,a.time+o(a.tween))):a.kind==="insertCb"&&(n.push({at:a.time,fn:a.fn}),t=Math.max(t,a.time));this._entries=n.map((a,s)=>({...a,index:s,end:a.tween?a.at+o(a.tween):a.at})),this._end=t,this._resetEntries()}_resetEntries(){for(let t of this._entries)t.started=!1,t.done=!1}_startChild(t){t.started=!0,t.tween._begin(!!t.tween.initialFrom)}_finishChild(t){t.done=!0,t.tween.apply(1),t.tween.onStepComplete&&this.runtime.safeCall(t.tween.onStepComplete),t.tween.finish(!0)}_advanceTo(t,i){let r=this._entries,n=[];for(let a of r)!a.started&&a.at<=t+Wr&&n.push({at:a.at,rank:a.fn?1:2,entry:a}),a.tween&&!a.done&&a.end<=t+Wr&&n.push({at:a.end,rank:0,entry:a});n.sort((a,s)=>a.at-s.at||a.rank-s.rank||a.entry.index-s.entry.index);let o=new Set;for(let{rank:a,entry:s}of n)if(a===1){if(s.started=!0,this.runtime.safeCall(s.fn),!this.playing||this.killed||this._entries!==r)return!1}else s.started||(this._startChild(s),o.add(s)),a===0&&!s.done&&this._finishChild(s);for(let a of r)!a.tween||!a.started||a.done||(o.has(a)?a.tween._advance(t-a.at,a.tween.loopCount):a.tween._advance(i,a.tween.loopCount));return!0}step(t){!this.playing||this.paused||this.killed||(this.elapsed+=t,this._advanceTo(this.elapsed,t)&&(this.elapsed+Wr<this._end||(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.loopIndex++,this.loops<0||this.loopIndex<this.loops?(this.elapsed=0,this._resetEntries()):this.finish(!0))))}Pause(){this.paused=!0}Resume(){this.paused=!1}Restart(){this.dead||this._play()}Complete(){this.dead||this.completed||(this._entries||this._schedule(),this.playing=!0,this.killed=!1,this._advanceTo(1/0,0)&&(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.finish(!0)))}Kill(t){t?this.Complete():this.finish(!1),this.dead=!0}SetOnComplete(t){return this.onComplete=t,this}SetOnStepComplete(t){return this.onStepComplete=t,this}SetLoops(t){return this.loops=t,this}finish(t){this.playing=!1,this.killed=!0,t&&(this.completed=!0),this.runtime.sequences.delete(this),this.runtime.animations.delete(this),t&&this.onComplete&&this.runtime.safeCall(this.onComplete)}};var $i={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"]},mc=[...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"],gc=[...Array.from({length:14},(e,t)=>`CraftspersonKey${t+1}`),"SprintKey","JumpKey","InteractKey","NormalAttackKey","CharacterSkill1Key","CharacterSkill2Key","CharacterSkill3Key","CharacterSkill4Key","MenuConfirmKey","MenuBackKey","None"];function yc(){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}$i.KeyboardKeyCode=mc;$i.ControllerKeyCode=gc;$i.KeyEventType=yc();var ha=new Map;function st(e,t){let i=`${e}\0${t}`,r=ha.get(i);return r||(r={__kind:"EnumItem",Name:t,FullName:`Enum.${e}.${t}`,EnumType:e},ha.set(i,r)),r}function Kr(e,t){return t==null?t:t.__kind==="EnumItem"?st(t.EnumType||e,t.Name):typeof t=="string"&&t?st(e,t):t}function qr(){let e={};for(let[t,i]of Object.entries($i)){let r={};for(let n of i)r[n]=st(t,n);e[t]=r}return e}var bc=new Set(["Id","prefabIndex","imageId","fontSize","minimumFontSize","clickAudioId","itemCount","itemPrefabIndex","animationId","referencedPrefabIndex"]),vc=new Set(["imageColor","fontColor","bgColor","outlineColor"]),pa={horizontalAlignment:"TextHorizontalAlignment",verticalAlignment:"TextVerticalAlignment",imageSource:"ImageSource",fillType:"ImageFillType",fillHorizontalType:"ImageFillHorizontalType",fillVerticalType:"ImageFillVerticalType",fillRadial90Type:"ImageFillRadial90Type",fillRadialType:"ImageFillRadialType",softEdgeMode:"ImageMaskSoftEdgeMode",layer:"UIAnimationLayer",scrollDirection:"ScrollDirection",layoutConstraint:"ScrollLayoutConstraint"},lt=f.LUA_REGISTRYINDEX,ma=f.LUA_MULTRET,wc=Object.freeze({InstantiateClientUIControl:2,DestroyClientUIControl:1,GetClientUIControl:1,FindClientUIRoot:1,GetClientUIRoots:0,GetUICanvasSize:0,GetCursorUIPos:0,GetDevice:0,SetControllerFocus:1,GetControllerFocus:0,GetControllerLeftStickAxis:0,GetControllerRightStickAxis:0,Tween:3,TweenSequence:0,ServerSignal:1,GetGlobalCustomVariableValue:2,PauseLevelTime:1,IsLevelTimePaused:0,PlayAudio2D:1,StopAudio:1,IsAudioAlive:1,GetLanguageType:0,GetStageMode:0,IsTestPlay:0,GetText:1,PrintClientUITree:0});function be(e){return e==null?"":typeof e=="string"?e:e.Name||e.FullName||String(e)}var Gi=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.animations=new Set,this.audios=new Map,this.nextAudioId=1,this.audioDuration=t.audioDuration||(()=>null),this.audioHistory=[],this.audioWarnings=new Set,this.audioRevision=0,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=qr(),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 r=this._nextScriptMappingId;return this._nextScriptMappingId+=1,r}pushPackedColor(t,i){let r=i>>>0;(r|0)===r?f.lua_pushinteger(t,r):f.lua_pushnumber(t,r)}retainLuaCallback(t){ea(t)}unrefLuaCallback(t){ta(this,t)}log(t,...i){let r=i.map(n=>n==null?"nil":typeof n=="object"&&n!==null&&n.__kind==="EnumItem"?n.Name:String(n)).join(" ");this.logs.push({level:t,text:r,time:this.clock.time})}safeCall(t,...i){try{return t(...i)}catch(r){this.log("lua-error",r&&r.message?r.message:String(r))}}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 r=this.normalizeRequirePath(t);this.scriptFiles.set(r,i),r.startsWith("default_import_file/")||this.requireAliases.set(`default_import_file/${r}`,r)}normalizeRequirePath(t){let i=String(t).replace(/\\/g,"/");return i.endsWith(".lua")&&(i=i.slice(0,-4)),i}addRoot(t){let i=t instanceof Je?t:new Je(this,t);return this.roots.push(i),Fe(i,r=>this.controlsById.set(r.Id,r)),this.mountSpecScripts(t,i),i}mountSpecScripts(t,i){if(t instanceof Je)return;let r=o=>(o.scripts?.length||0)>0||(o.children||[]).some(r);if(!t||!r(t))return;let n=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(u){let h=u&&u.message?u.message:String(u);this.mountErrors.push(h),this.log("lua-error",h)}let c=a.children||[];for(let l=0;l<c.length;l+=1)o(c[l],s?.children?.[l])};o(t,i)}finally{this.lifecyclePhase=n}}makeCursorEventData({x:t=0,y:i=0,pressX:r=t,pressY:n=i,deltaX:o=t-r,deltaY:a=i-n,dragging:s=!1,touchId:c=-1}={}){let l=this;return{__kind:"CursorEventData",typeofName:"CursorEventData",dragging:s,touchId:c,x:t,y:i,pressX:r,pressY:n,GetUIPos(){return[t,i]},GetPressUIPos(){return[r,n]},GetUIPosDelta(){return[o,a]}}}boot(){let t=this.newLuaThread();this.L=t}installGlobals(t){let i=this;f.lua_pushcfunction(t,r=>{let n=f.lua_gettop(r),o=[];for(let a=1;a<=n;a++)o.push(de(r,i,a));return i.log("info",...o),0}),f.lua_setglobal(t,R("print")),f.lua_pushcfunction(t,r=>{let n=f.lua_gettop(r),o=[];for(let a=1;a<=n;a++)o.push(de(r,i,a));return i.log("error",...o),0}),f.lua_setglobal(t,R("printerr")),f.lua_pushcfunction(t,r=>{if(f.lua_type(r,1)===f.LUA_TTABLE&&!Ve(r,1))return f.lua_pushstring(r,R("table")),1;let n=de(r,i,1);return f.lua_pushstring(r,R(i.typeofOf(n))),1}),f.lua_setglobal(t,R("typeof")),this.pushColorLib(t),this.pushEnumLib(t),this.pushGameLib(t),f.lua_pushcfunction(t,r=>i.luaRequire(r)),f.lua_setglobal(t,R("require"))}typeofOf(t){return t==null?"nil":t.__kind==="Script"?"Script":t.__kind==="EnumItem"?"EnumItem":t.__kind==="CursorEventData"?"CursorEventData":t.__kind==="ServerSignal"?"ServerSignal":t instanceof Tt?"TweenSequence":t instanceof ai?"Tween":t.typeofName?t.typeofName:typeof t=="number"?"number":typeof t=="string"?"string":typeof t=="boolean"?"boolean":typeof t}pushColorLib(t){f.lua_newtable(t),f.lua_pushcfunction(t,i=>(this.pushPackedColor(i,Rt(f.lua_tonumber(i,1),f.lua_tonumber(i,2),f.lua_tonumber(i,3),255)),1)),f.lua_setfield(t,-2,R("FromRGB")),f.lua_pushcfunction(t,i=>{let r=f.lua_isnoneornil(i,4)?255:f.lua_tonumber(i,4);return this.pushPackedColor(i,Rt(f.lua_tonumber(i,1),f.lua_tonumber(i,2),f.lua_tonumber(i,3),r)),1}),f.lua_setfield(t,-2,R("FromRGBA")),f.lua_pushcfunction(t,i=>{let r=f.lua_tonumber(i,1)>>>0;for(let n of oi(r))f.lua_pushinteger(i,n);return 4}),f.lua_setfield(t,-2,R("ToRGBA")),f.lua_newtable(t),f.lua_pushcfunction(t,i=>{let r=f.lua_tonumber(i,2),n=f.lua_tonumber(i,3),o=f.lua_tonumber(i,4),a=f.lua_isnoneornil(i,5)?255:f.lua_tonumber(i,5);return this.pushPackedColor(i,Rt(r,n,o,a)),1}),f.lua_setfield(t,-2,R("__call")),f.lua_setmetatable(t,-2),f.lua_setglobal(t,R("Color"))}pushEnumLib(t){f.lua_newtable(t);for(let[i,r]of Object.entries(this.enumTree)){f.lua_newtable(t);for(let[n,o]of Object.entries(r))this.pushEnumItem(t,o),f.lua_setfield(t,-2,R(n));f.lua_setfield(t,-2,R(i))}f.lua_setglobal(t,R("Enum"))}pushEnumItem(t,i){let r=f.lua_newuserdata(t,0);at(r,i),Q.luaL_setmetatable(t,R("EnumItem"))}pushControl(t,i){let r=f.lua_newuserdata(t,0);at(r,i),Q.luaL_setmetatable(t,R("Control"))}pushScript(t,i){f.lua_newtable(t),f.lua_pushlightuserdata(t,Hr);let r=f.lua_newuserdata(t,0);at(r,i),f.lua_rawset(t,-3),Q.luaL_getmetatable(t,R("Script")),f.lua_setmetatable(t,-2)}pushTween(t,i){let r=f.lua_newuserdata(t,0);at(r,i);let n=i instanceof Tt?"TweenSequence":"Tween";Q.luaL_setmetatable(t,R(n))}pushSignal(t,i){let r=f.lua_newuserdata(t,0);at(r,i),Q.luaL_setmetatable(t,R("ServerSignal"))}pushCursor(t,i){let r=f.lua_newuserdata(t,0);at(r,i),Q.luaL_setmetatable(t,R("CursorEventData"))}pushGameLib(t){let i=this;f.lua_newtable(t);let r={InstantiateClientUIControl:n=>{let o=f.lua_tointeger(n,1),a=Ie(f.lua_touserdata(n,2)),s=i.instantiate(o,a,i.lifecyclePhase);return s?(i.pushControl(n,s),1):(f.lua_pushnil(n),1)},DestroyClientUIControl:n=>{let o=Ie(f.lua_touserdata(n,1));return o&&i.destroyControl(o),0},GetClientUIControl:n=>{let o=f.lua_tointeger(n,1),a=i.controlsById.get(o);return a?i.pushControl(n,a):f.lua_pushnil(n),1},FindClientUIRoot:n=>{let o=q(n,1),a=i.roots.find(s=>s.name===o);return a?i.pushControl(n,a):f.lua_pushnil(n),1},GetClientUIRoots:n=>(f.lua_createtable(n,i.roots.length,0),i.roots.forEach((o,a)=>{i.pushControl(n,o),f.lua_rawseti(n,-2,a+1)}),1),GetUICanvasSize:n=>(f.lua_pushnumber(n,i.canvasWidth),f.lua_pushnumber(n,i.canvasHeight),2),GetCursorUIPos:n=>(f.lua_pushnumber(n,i.cursor.x),f.lua_pushnumber(n,i.cursor.y),2),GetDevice:n=>(i.pushEnumItem(n,st("Device",i.device)),1),SetControllerFocus:n=>(i.focus=Ie(f.lua_touserdata(n,1)),0),GetControllerFocus:n=>(i.focus?i.pushControl(n,i.focus):f.lua_pushnil(n),1),GetControllerLeftStickAxis:n=>(f.lua_pushnumber(n,i.stick.left[0]),f.lua_pushnumber(n,i.stick.left[1]),2),GetControllerRightStickAxis:n=>(f.lua_pushnumber(n,i.stick.right[0]),f.lua_pushnumber(n,i.stick.right[1]),2),Tween:n=>{let o=Ie(f.lua_touserdata(n,1))||de(n,i,1),a=de(n,i,2)||{},s=f.lua_tonumber(n,3),c=new ai(i,o,a,s);return i.pushTween(n,c),1},TweenSequence:n=>(i.pushTween(n,new Tt(i)),1),ServerSignal:n=>{let o=q(n,1);return i.pushSignal(n,i.makeServerSignal(o)),1},GetGlobalCustomVariableValue:n=>{let o=be(de(n,i,1)),a=q(n,2);return ae(n,i,i.getVar(o,a)),1},PauseLevelTime:n=>(i.clock.paused=!!f.lua_toboolean(n,1),0),IsLevelTimePaused:n=>(f.lua_pushboolean(n,i.clock.paused),1),PlayAudio2D:n=>{let o=i.playAudio(i.audioInteger(n));return f.lua_pushinteger(n,o),1},StopAudio:n=>(i.stopAudio(i.audioInteger(n)),0),IsAudioAlive:n=>{let o=i.audios.get(i.audioInteger(n));return f.lua_pushboolean(n,!!(o&&o.alive)),1},GetLanguageType:n=>(i.pushEnumItem(n,st("LanguageType",i.language)),1),GetStageMode:n=>(i.pushEnumItem(n,st("StageMode",i.stageMode)),1),IsTestPlay:n=>(f.lua_pushboolean(n,i.testPlay),1),GetText:n=>{let o=q(n,1);return f.lua_pushstring(n,R(o)),1},PrintClientUITree:n=>{for(let o of i.roots)i.log("info",Xr(o).join(`
|
|
109
|
-
`));return 0}};for(let[n,o]of Object.entries(r)){let a=wc[n];if(a===void 0)throw new Error(`missing game arity for ${n}`);f.lua_pushcfunction(t,s=>{let c=f.lua_gettop(s);return c!==a?Q.luaL_error(s,R(`bad argument count to '${n}' (${a} expected, got ${c})`)):o(s)}),f.lua_setfield(t,-2,R(n))}f.lua_setglobal(t,R("game"))}makeServerSignal(t){let i=[],r=this;return{__kind:"ServerSignal",name:t,AddParam(n,o){i.push({type:be(n),value:o})},AddInt(n){i.push({type:"Int",value:n})},AddIntList(n){i.push({type:"IntList",value:n})},AddFloat(n){i.push({type:"Float",value:n})},AddFloatList(n){i.push({type:"FloatList",value:n})},AddString(n){i.push({type:"String",value:n})},AddStringList(n){i.push({type:"StringList",value:n})},AddVector3(n){i.push({type:"Vector3",value:n})},AddVector3List(n){i.push({type:"Vector3List",value:n})},AddBool(n){i.push({type:"Bool",value:n})},AddBoolList(n){i.push({type:"BoolList",value:n})},AddGuid(n){i.push({type:"Guid",value:n})},AddGuidList(n){i.push({type:"GuidList",value:n})},AddEntity(n){i.push({type:"Entity",value:n})},AddEntityList(n){i.push({type:"EntityList",value:n})},AddPrefabId(n){i.push({type:"PrefabId",value:n})},AddPrefabIdList(n){i.push({type:"PrefabIdList",value:n})},AddConfigId(n){i.push({type:"ConfigId",value:n})},AddConfigIdList(n){i.push({type:"ConfigIdList",value:n})},SendSignal(){let n=i.slice();r.serverBridge&&typeof r.serverBridge.receiveFromClient=="function"&&r.serverBridge.receiveFromClient(t,n)}}}audioInteger(t){let i=f.lua_tonumber(t,1);return f.lua_type(t,1)!==f.LUA_TNUMBER||!Number.isSafeInteger(i)?Q.luaL_error(t,R("audio argument must be an integer")):i}playAudio(t){this.audioRevision++;let i=this.nextAudioId++,r=this.audioDuration(t),n=Number.isFinite(r)&&r>0,o={instanceId:i,audioId:t,startedAt:this.clock.time,duration:n?r:0,alive:n,stopped:!1};return this.audioHistory.push(o),this.audioHistory.length>128&&this.audioHistory.shift(),n?(this.audios.size>=128&&this.stopAudio(this.audios.keys().next().value),this.audios.set(i,o)):this.audioWarnings.has(t)||(this.audioWarnings.size>=128&&this.audioWarnings.delete(this.audioWarnings.values().next().value),this.audioWarnings.add(t),this.log("warn",`\u97F3\u6548 ${t} \u672A\u5217\u5165\u6A21\u62DF\u5668\u97F3\u9891\u767D\u540D\u5355`)),i}stopAudio(t){let i=this.audios.get(t)||this.audioHistory.find(r=>r.instanceId===t);i&&!i.stopped&&(i.alive=!1,i.stopped=!0,this.audioRevision++),this.audios.delete(t)}audioSnapshot(){return{sequence:this.nextAudioId-1,revision:this.audioRevision,active:[...this.audios.values()].map(t=>({...t})),recent:this.audioHistory.map(t=>({...t}))}}instantiate(t,i,r){if(r==="OnInit"||r==="OnDestroy")return null;let n=this.templates.get(Number(t));if(!n||!i)return null;let o=new Je(this,{...n,Id:this.nextControlId(),authoringId:null,prefabIndex:Number(t)});return i.addChild(o),o.SetAsLastSibling(),Fe(o,a=>this.controlsById.set(a.Id,a)),this.mountSpecScripts(n,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}`);Fe(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.scrollControls?.delete(t),this._playRemoved.push(t.Id),t.parent){let i=t.parent,r=i.children.indexOf(t);r>=0&&i.children.splice(r,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 r of i)this.unrefLuaCallback(r);for(let i of t.keyListeners.values())for(let r of i)this.unrefLuaCallback(r);for(let i of t.navListeners.values())for(let r of i)this.unrefLuaCallback(r);t.cursorListeners.clear(),t.keyListeners.clear(),t.navListeners.clear(),t.navConfig.clear()}onControlActiveChanging(t,i){let r=[];Fe(t,n=>r.push({control:n,was:n.activeInHierarchy})),t.active=!!i,t.markPlayDirty(!0);for(let n of r){let o=n.control.activeInHierarchy;if(n.was!==o)for(let a of n.control.scripts.slice())o?this.enableScript(a):this.disableScript(a)}}bindScriptEnv(t){let i=t.env;return i?(this.pushScript(i,t),f.lua_setglobal(i,R("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,r=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=r,this.mountedScripts=this.mountedScripts.filter(n=>n!==t),t.object&&(t.object.scripts=t.object.scripts.filter(n=>n!==t)),this.varHandlers=this.varHandlers.filter(n=>n.script!==t),this.signalHandlers=this.signalHandlers.filter(n=>n.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,r,n,o,a){Q.luaL_newmetatable(t,R(i)),f.lua_pushcfunction(t,s=>{let c=Ve(s,1)||Ie(f.lua_touserdata(s,1)),l=q(s,2);if(o[l]&&(!a||a(c,l)))return f.lua_pushcfunction(s,o[l]),1;let u;try{u=r(c,l)}catch(h){return Q.luaL_error(s,R(String(h.message||h)))}return u===void 0?(f.lua_pushnil(s),1):(ae(s,this,u),1)}),f.lua_setfield(t,-2,R("__index")),f.lua_pushcfunction(t,s=>{try{let c=Ve(s,1)||Ie(f.lua_touserdata(s,1)),l=q(s,2),u=de(s,this,3);return n(c,l,u),0}catch(c){return f.lua_pushstring(s,R(String(c.message||c))),f.lua_error(s)}}),f.lua_setfield(t,-2,R("__newindex")),f.lua_pushcfunction(t,s=>{let c=Ve(s,1)||Ie(f.lua_touserdata(s,1)),l=Ve(s,2)||Ie(f.lua_touserdata(s,2));return f.lua_pushboolean(s,c===l),1}),f.lua_setfield(t,-2,R("__eq")),f.lua_pop(t,1)}method(t){let i=this;return r=>{let n=Ve(r,1)||Ie(f.lua_touserdata(r,1)),o=f.lua_gettop(r),a=[];for(let s=2;s<=o;s++)a.push(de(r,i,s));try{let s=t(n,...a);if(s===n)return f.lua_pushvalue(r,1),1;if(s===void 0)return 0;if(Array.isArray(s)&&s.__multi){for(let c of s)ae(r,i,c);return s.length}if(Array.isArray(s)&&!(s.length&&typeof s[0]=="object"&&s[0]?.typeofName)){if(s.__controls)return f.lua_createtable(r,s.length,0),s.forEach((c,l)=>{i.pushControl(r,c),f.lua_rawseti(r,-2,l+1)}),1;if(s.__scripts)return f.lua_createtable(r,s.length,0),s.forEach((c,l)=>{i.pushScript(r,c),f.lua_rawseti(r,-2,l+1)}),1;if(typeof s[0]=="number"&&s.length<=4){for(let c of s)f.lua_pushnumber(r,c);return s.length}}return ae(r,i,s),1}catch(s){return f.lua_pushstring(r,R(String(s.message||s))),f.lua_error(r)}}}mtEnum(t){let i=new Set(["Name","FullName","EnumType"]);this.mtIndexNewindex(t,"EnumItem",(r,n)=>i.has(n)?r[n]:void 0,(r,n)=>{throw new Error(`cannot set ${n}, no such field`)},{})}mtCursor(t){let i=new Set(["dragging","touchId"]);this.mtIndexNewindex(t,"CursorEventData",(r,n)=>i.has(n)?r[n]:void 0,(r,n)=>{throw new Error(`cannot set ${n}, no such field`)},{GetUIPos:this.method(r=>r.GetUIPos()),GetPressUIPos:this.method(r=>r.GetPressUIPos()),GetUIPosDelta:this.method(r=>r.GetUIPosDelta())})}mtControl(t){let i={GetChildren:this.method(r=>{let n=r.GetChildren();return n.__controls=!0,n}),GetChild:this.method((r,n)=>r.GetChild(n)),FindChild:this.method((r,n)=>r.FindChild(n)),SetActive:this.method((r,n)=>r.SetActive(n)),SetVisible:this.method((r,n)=>r.SetVisible(n)),GetSiblingIndex:this.method(r=>r.GetSiblingIndex()),SetSiblingIndex:this.method((r,n)=>r.SetSiblingIndex(n)),SetAsFirstSibling:this.method(r=>r.SetAsFirstSibling()),SetAsLastSibling:this.method(r=>r.SetAsLastSibling()),GetAnchoredPosition:this.method(r=>r.GetAnchoredPosition()),SetAnchoredPosition:this.method((r,n,o)=>r.SetAnchoredPosition(n,o)),GetSizeDelta:this.method(r=>r.GetSizeDelta()),SetSizeDelta:this.method((r,n,o)=>r.SetSizeDelta(n,o)),GetAnchorMin:this.method(r=>r.GetAnchorMin()),SetAnchorMin:this.method((r,n,o)=>r.SetAnchorMin(n,o)),GetAnchorMax:this.method(r=>r.GetAnchorMax()),SetAnchorMax:this.method((r,n,o)=>r.SetAnchorMax(n,o)),GetPivot:this.method(r=>r.GetPivot()),SetPivot:this.method((r,n,o)=>r.SetPivot(n,o)),GetLocalScale:this.method(r=>r.GetLocalScale()),SetLocalScale:this.method((r,n,o,a)=>r.SetLocalScale(n,o,a)),GetLocalRotation:this.method(r=>r.GetLocalRotation()),SetLocalRotation:this.method((r,n,o,a)=>r.SetLocalRotation(n,o,a)),GetScriptByPath:this.method((r,n)=>r.GetScriptByPath(n)),GetScript:this.method((r,n)=>r.GetScript(n)),GetScripts:this.method(r=>{let n=r.GetScripts();return n.__scripts=!0,n}),AddCursorEventListener:this.method((r,n,o)=>r.AddCursorEventListener(be(n),o)),RemoveCursorEventListener:this.method((r,n,o)=>r.RemoveCursorEventListener(be(n),o)),RemoveCursorEventListeners:this.method((r,n)=>r.RemoveCursorEventListeners(be(n))),RemoveAllCursorEventListeners:this.method(r=>r.RemoveAllCursorEventListeners()),SimulateCursorClick:this.method(r=>r.SimulateCursorClick()),AddKeyEventListener:this.method((r,n,o)=>r.AddKeyEventListener(be(n),o)),RemoveKeyEventListener:this.method((r,n,o)=>r.RemoveKeyEventListener(be(n),o)),RemoveKeyEventListeners:this.method((r,n)=>r.RemoveKeyEventListeners(be(n))),RemoveAllKeyEventListeners:this.method(r=>r.RemoveAllKeyEventListeners()),AddNavigationEventListener:this.method((r,n,o)=>r.AddNavigationEventListener(be(n),o)),RemoveNavigationEventListener:this.method((r,n,o)=>r.RemoveNavigationEventListener(be(n),o)),RemoveNavigationEventListeners:this.method((r,n)=>r.RemoveNavigationEventListeners(be(n))),RemoveAllNavigationEventListeners:this.method(r=>r.RemoveAllNavigationEventListeners()),SetControllerNavigation:this.method((r,n,o,a)=>r.SetControllerNavigation(be(n),o,a)),GetControllerNavigation:this.method((r,n)=>r.GetControllerNavigation(be(n))),SetImage:this.method((r,n,o)=>r.SetImage(n,o)),SetSoftEdgeWidth:this.method((r,n,o)=>r.SetSoftEdgeWidth(n,o)),SetFillUnused:this.method(r=>r.SetFillUnused()),SetFillHorizontal:this.method((r,n,o)=>r.SetFillHorizontal(n,o)),SetFillVertical:this.method((r,n,o)=>r.SetFillVertical(n,o)),SetFillRadial90:this.method((r,n,o)=>r.SetFillRadial90(n,o)),SetFillRadial180:this.method((r,n,o)=>r.SetFillRadial180(n,o)),SetFillRadial360:this.method((r,n,o)=>r.SetFillRadial360(n,o)),PlayAnimation:this.method(r=>r.PlayAnimation()),StopAnimation:this.method(r=>r.StopAnimation()),RefreshItems:this.method((r,n,o)=>{this.retainLuaCallback(o);try{r.RefreshItems(n,o)}finally{this.unrefLuaCallback(o)}}),GetItemIndex:this.method((r,n)=>r.GetItemIndex(n)),GetItemSize:this.method(r=>r.GetItemSize()),GetItemSpacing:this.method(r=>r.GetItemSpacing()),GetPadding:this.method(r=>r.GetPadding()),ScrollToItemAt:this.method((r,n,o)=>r.ScrollToItemAt(n,o)),GetContentLength:this.method(r=>r.GetContentLength())};this.mtIndexNewindex(t,"Control",(r,n)=>{if(!Lr(r,n))return;if(!r.alive&&n!=="alive")throw new Error(`attempt to read '${n}' of a destroyed control`);let o=r.luaFieldValue(n),a=pa[n];return a?Kr(a,o):typeof o=="number"&&!bc.has(n)&&!vc.has(n)?new ii(o):o},(r,n,o)=>{if(Lr(r,n)==="rw"){if((n==="fontSize"||n==="minimumFontSize")&&!Number.isInteger(o)){let c=o===null?"nil":typeof o;throw new Error(`bad argument #2 to '${n}' (integer expected, got ${c})`)}let s=pa[n];r[n]=s?Kr(s,o):o,typeof r.markPlayDirty=="function"&&r.markPlayDirty(Oi.has(n));return}throw new Error(`cannot set ${n}, no such field`)},i,ca)}mtScript(t){let i=this,r=new Set(["alive","scriptMappingId","object","path","enabled"]);this.mtIndexNewindex(t,"Script",(n,o)=>r.has(o)?n[o]:void 0,(n,o,a)=>{if(o==="enabled"){n.enabled=!!a;return}throw new Error(`cannot set ${o}, no such field`)},{GetParam:this.method((n,o)=>Object.prototype.hasOwnProperty.call(n.params,o)?n.params[o]:null),Invoke:n=>i.luaInvoke(n),EnableUpdate:this.method((n,o)=>{n.updateEnabled=!!o}),RegisterServerSignalHandler:this.method((n,o,a)=>{i.signalHandlers.push({script:n,name:o,fn:a})}),UnregisterServerSignalHandler:this.method((n,o)=>{i.signalHandlers=i.signalHandlers.filter(a=>!(a.script===n&&a.name===o))}),RegisterCustomVariableChangedHandler:this.method((n,o,a,s)=>{i.varHandlers.push({script:n,entityType:be(o),name:a,fn:s})}),UnregisterCustomVariableChangedHandler:this.method((n,o,a)=>{let s=be(o);i.varHandlers=i.varHandlers.filter(c=>!(c.script===n&&c.entityType===s&&c.name===a))})})}mtTween(t){this.mtIndexNewindex(t,"Tween",()=>{},()=>{},{SetEase:this.method((i,r)=>i.SetEase(r)),SetRelative:this.method((i,r)=>i.SetRelative(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,r)=>i.Kill(r)),SetOnComplete:this.method((i,r)=>i.SetOnComplete(r)),SetOnStepComplete:this.method((i,r)=>i.SetOnStepComplete(r)),SetLoops:this.method((i,r)=>i.SetLoops(r))})}mtSeq(t){this.mtIndexNewindex(t,"TweenSequence",()=>{},()=>{},{Append:this.method((i,r)=>i.Append(r)),AppendInterval:this.method((i,r)=>i.AppendInterval(r)),AppendCallback:this.method((i,r)=>i.AppendCallback(r)),Join:this.method((i,r)=>i.Join(r)),Insert:this.method((i,r,n)=>i.Insert(r,n)),InsertCallback:this.method((i,r,n)=>i.InsertCallback(r,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,r)=>i.Kill(r)),SetOnComplete:this.method((i,r)=>i.SetOnComplete(r)),SetOnStepComplete:this.method((i,r)=>i.SetOnStepComplete(r)),SetLoops:this.method((i,r)=>i.SetLoops(r))})}mtSignal(t){this.mtIndexNewindex(t,"ServerSignal",()=>{},()=>{},{AddParam:this.method((i,r,n)=>i.AddParam(r,n)),SendSignal:this.method(i=>i.SendSignal()),AddInt:this.method((i,r)=>i.AddInt(r)),AddIntList:this.method((i,r)=>i.AddIntList(r)),AddFloat:this.method((i,r)=>i.AddFloat(r)),AddFloatList:this.method((i,r)=>i.AddFloatList(r)),AddString:this.method((i,r)=>i.AddString(r)),AddStringList:this.method((i,r)=>i.AddStringList(r)),AddVector3:this.method((i,r)=>i.AddVector3(r)),AddVector3List:this.method((i,r)=>i.AddVector3List(r)),AddBool:this.method((i,r)=>i.AddBool(r)),AddBoolList:this.method((i,r)=>i.AddBoolList(r)),AddGuid:this.method((i,r)=>i.AddGuid(r)),AddGuidList:this.method((i,r)=>i.AddGuidList(r)),AddEntity:this.method((i,r)=>i.AddEntity(r)),AddEntityList:this.method((i,r)=>i.AddEntityList(r)),AddPrefabId:this.method((i,r)=>i.AddPrefabId(r)),AddPrefabIdList:this.method((i,r)=>i.AddPrefabIdList(r)),AddConfigId:this.method((i,r)=>i.AddConfigId(r)),AddConfigIdList:this.method((i,r)=>i.AddConfigIdList(r))})}luaRequire(t){let i=q(t,1),r=this.normalizeRequirePath(i),n=this.requireAliases.get(r)||r;f.lua_rawgeti(t,lt,f.LUA_RIDX_MAINTHREAD);let o=f.lua_tothread(t,-1);f.lua_pop(t,1);let a=this.requireCache.get(o);a||(a=new Map,this.requireCache.set(o,a));let s=a.get(n);if(s?.loading)return f.lua_pushstring(t,R(`failed to load script '${r}': cyclic require`)),f.lua_error(t);if(s&&s.ref!=null)return f.lua_rawgeti(t,lt,s.ref),1;let c=this.scriptFiles.get(n);if(c==null)return f.lua_pushstring(t,R(`failed to load script '${r}'`)),f.lua_error(t);let l=f.lua_gettop(t);a.set(n,{loading:!0});try{this.loadModule(t,o,n,c),f.lua_pushvalue(t,-1);let u=Q.luaL_ref(t,lt);return a.set(n,{ref:u}),1}catch(u){return a.delete(n),f.lua_settop(t,l),f.lua_pushstring(t,R(`failed to load script '${r}': ${u.message||u}`)),f.lua_error(t)}}newLuaThread(){let t=Q.luaL_newstate();return Jo.luaL_openlibs(t),ra(t),this.installMetatables(t),this.installGlobals(t),this.luaStates.add(t),f.lua_pushglobaltable(t),this.copyLuaEnvironment(t,-1),f.lua_remove(t,-2),this.moduleBaseEnvironments.set(t,Q.luaL_ref(t,lt)),t}copyLuaEnvironment(t,i){let r=f.lua_absindex(t,i);f.lua_newtable(t);let n=f.lua_absindex(t,-1);for(f.lua_pushnil(t);f.lua_next(t,r)!==0;)f.lua_pushvalue(t,-2),f.lua_pushvalue(t,-2),f.lua_rawset(t,n),f.lua_pop(t,1);f.lua_pushvalue(t,n),f.lua_setfield(t,n,R("_G"))}closeTrackedLuaState(t){if(!t||!this.luaStates.has(t))return;for(let r of this.requireCache.get(t)?.values()||[])r.ref!=null&&Q.luaL_unref(t,lt,r.ref);this.requireCache.delete(t);let i=this.moduleBaseEnvironments.get(t);if(i!=null&&Q.luaL_unref(t,lt,i),this.moduleBaseEnvironments.delete(t),this.luaStates.delete(t),this.luaFunctions)for(let[r,n]of this.luaFunctions)n.__luaState===t&&this.luaFunctions.delete(r);ia(t)}loadModule(t,i,r,n){let o={__kind:"Script",alive:!0,scriptMappingId:this.resolveScriptMappingId(),object:null,path:r,enabled:!0,updateEnabled:!1,params:{},env:t,invoke(){}},a=String(n).replace(/^\uFEFF/,""),s=Ni(a);if(Q.luaL_loadbuffer(t,s,s.length,R(`@${r}`))!==Ae)throw new Error(q(t,-1));let l=f.lua_absindex(t,-1);if(f.lua_rawgeti(t,lt,this.moduleBaseEnvironments.get(i)),this.copyLuaEnvironment(t,-1),f.lua_remove(t,-2),this.pushScript(t,o),f.lua_setfield(t,-2,R("script")),f.lua_setupvalue(t,l,1),f.lua_pcall(t,0,1,0)!==Ae)throw new Error(q(t,-1))}mountScript({path:t,source:i,control:r,params:n={},scriptMappingId:o=void 0}){this.L||this.boot();let a=this.newLuaThread(),s={__kind:"Script",alive:!0,scriptMappingId:this.resolveScriptMappingId(o),object:r,path:this.normalizeRequirePath(t),enabled:!0,updateEnabled:!1,params:n,env:a,lifecyclePhase:"idle"};s.invoke=(l,u)=>this.invokeOn(a,l,u),r&&r.scripts.push(s),this.mountedScripts.push(s),this.pushScript(a,s),f.lua_setglobal(a,R("script"));let c=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 u=this.callGlobal(a,"OnEnable");u&&this.mountErrors.push(u),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(u=>u!==s),r&&(r.scripts=r.scripts.filter(u=>u!==s)),this.varHandlers=this.varHandlers.filter(u=>u.script!==s),this.signalHandlers=this.signalHandlers.filter(u=>u.script!==s),this.lifecyclePhase=c,a&&a!==this.L&&this.closeTrackedLuaState(a),s.env=null,l}}runChunk(t,i,r){let n=String(i).replace(/^\uFEFF/,""),o=Ni(n),a=Q.luaL_loadbuffer(t,o,o.length,R(`@${r}`));if(a!==Ae){let c=q(t,-1)||`luaL_loadbuffer status ${a}`;throw f.lua_pop(t,1),new Error(c)}let s=f.lua_pcall(t,0,0,0);if(s!==Ae){let c=q(t,-1)||`lua_pcall status ${s}`;throw f.lua_pop(t,1),new Error(c)}}callGlobal(t,i){if(f.lua_getglobal(t,R(i)),f.lua_isfunction(t,-1)){if(f.lua_pcall(t,0,0,0)!==Ae){let n=q(t,-1);f.lua_pop(t,1);let o=`${i}: ${n}`;return this.log("lua-error",o),o}}else f.lua_pop(t,1);return null}callGlobalDt(t,i,r){if(f.lua_getglobal(t,R(i)),f.lua_isfunction(t,-1)){if(f.lua_pushnumber(t,r),f.lua_pcall(t,1,0,0)!==Ae){let o=q(t,-1);f.lua_pop(t,1),this.log("lua-error",`${i}: ${o}`)}}else f.lua_pop(t,1)}luaInvoke(t){let i=Ve(t,1);if(!i||i.__kind!=="Script")return Q.luaL_error(t,R("bad self to 'Invoke' (Script expected)"));let r=q(t,2),n=i.env;if(!n||n.l_G!==t.l_G){let c=[];for(let h=3;h<=f.lua_gettop(t);h++)c.push(de(t,this,h));let l;try{l=i.invoke(r,c)}catch(h){return Q.luaL_error(t,R(String(h.message||h)))}if(l===void 0)return 0;let u=Array.isArray(l)&&l.__multi?l:[l];for(let h of u)ae(t,this,h);return u.length}let o=2;if(f.lua_getglobal(t,R(r)),!f.lua_isfunction(t,-1))return 0;f.lua_replace(t,o),f.lua_remove(t,1);let a=f.lua_gettop(t)-1;return f.lua_pcall(t,a,ma,0)!==Ae?f.lua_error(t):f.lua_gettop(t)}invokeOn(t,i,r){let n=f.lua_gettop(t);if(f.lua_getglobal(t,R(i)),!f.lua_isfunction(t,-1)){f.lua_settop(t,n);return}for(let c of r)ae(t,this,c);if(f.lua_pcall(t,r.length,ma,0)!==Ae){let c=q(t,-1);throw f.lua_settop(t,n),new Error(c)}let a=f.lua_gettop(t)-n;if(a<=0){f.lua_settop(t,n);return}if(a===1){let c=de(t,this,-1);return f.lua_settop(t,n),c}let s=[];for(let c=1;c<=a;c++)s.push(de(t,this,n+c));return f.lua_settop(t,n),s.__multi=!0,s}runScriptPhase(t,i){for(let r of this.mountedScripts){if(!this.scriptCanRun(r))continue;let n=r.env;n&&(this.pushScript(n,r),f.lua_setglobal(n,R("script")),!(t==="OnUpdate"&&!r.updateEnabled)&&this.callGlobalDt(n,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;for(let[r,n]of this.audios)this.clock.time+1e-9>=n.startedAt+n.duration&&(n.alive=!1,this.audios.delete(r),this.audioRevision++);let i=!this.clock.paused;for(let r of[...this.animations])r.step(t);this.runScriptPhase("OnUpdate",t),i&&(this.clock.levelTime+=t,this.runScriptPhase("OnLevelUpdate",t))}injectKey(t){let i=r=>{if(!r.alive||!r.activeInHierarchy)return!1;if(r.keyListeners.has(t)&&r.emitKey(t))return!0;for(let n of[...r.children])if(i(n))return!0;return!1};for(let r of[...this.roots])i(r)}injectCursor(t,i,r){let n=r||this.makeCursorEventData({});Number.isFinite(n.x)&&Number.isFinite(n.y)&&(this.cursor.x=n.x,this.cursor.y=n.y),t.emitCursor(i,n)}getVar(t,i){if(this.serverBridge&&typeof this.serverBridge.getVar=="function")return this.serverBridge.getVar(t,i);let r=this.serverVars[t];return r?r[i]:void 0}notifyVarHandlers(t,i){for(let r of this.varHandlers)this.scriptCanRun(r.script)&&r.entityType===t&&r.name===i&&this.safeCall(r.fn,this.enumTree.CustomVariableEntityType[t],i)}setVar(t,i,r){if(this.serverBridge&&typeof this.serverBridge.setVar=="function"){this.serverBridge.setVar(t,i,r);return}let n=this.serverVars[t]||(this.serverVars[t]=Object.create(null));n[i]=r,this.notifyVarHandlers(t,i)}sendClientSignal(t,i){for(let r of this.signalHandlers)this.scriptCanRun(r.script)&&r.name===t&&this.safeCall(r.fn,t,i)}evalQueryScript(t,i){this.L||this.boot();let r=this.L;f.lua_createtable(r,0,5);let n=(o,a)=>{f.lua_pushcfunction(r,a),f.lua_setfield(r,-2,R(o))};return n("var",o=>(ae(o,this,i.var(q(o,1),q(o,2))),1)),n("logContains",o=>(f.lua_pushboolean(o,i.logContains(q(o,1))),1)),n("control",o=>(ae(o,this,i.control(q(o,1))),1)),n("logs",o=>(ae(o,this,i.logs()),1)),n("signals",o=>(ae(o,this,i.signals(q(o,1))),1)),n("serverLogs",o=>(ae(o,this,i.serverLogs?i.serverLogs():[]),1)),n("serverLogContains",o=>{let a=i.serverLogContains;return f.lua_pushboolean(o,a?!!a(q(o,1)):!1),1}),f.lua_setglobal(r,R("query")),this.runChunk(r,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,this.audios.clear(),this.audioHistory.length=0,this.audioWarnings.clear()}};function si(e){let t=new Gi(e);return t.boot(),t}var ut=Object.freeze(Array.from({length:8},(e,t)=>`Player${t+1}`)),Zr=Object.freeze(Array.from({length:8},(e,t)=>`Avatar${t+1}`)),Ca=Object.freeze(["Level","PlayerSelf","AvatarSelf"]);var Jr=Object.freeze([...Ca,...ut,...Zr]),xa=Object.freeze(["PlayerSelf","AllPlayers",...ut]),Sc=Object.freeze(["Level","PlayerSelf",...ut]),ga=Object.freeze(["Int","Float","String","Bool","Vector3","Entity","Guid","PrefabId","ConfigId","IntList","FloatList","StringList","BoolList","Vector3List","EntityList","GuidList","PrefabIdList","ConfigIdList","Dict","Struct"]),Ic=-2147483648,Cc=2147483647,xc=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 li(e){return`Player${Number(e)}`}function Vi(e){return`Avatar${Number(e)}`}function ya(e){let t=String(e||"").match(/^(?:Player|Avatar)([1-8])$/);return t?Number(t[1]):0}function ct(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 je(e,t=8){let i=ct(t);if(e==null||e==="")return 1;let r=Number(e);if(!Number.isInteger(r)||r<1||r>i)throw new Error(`playerIndex must be an integer 1-${i}`);return r}function ba(){let e={Level:Object.create(null),PlayerSelf:Object.create(null),AvatarSelf:Object.create(null)};for(let t of ut)e[t]=Object.create(null);for(let t of Zr)e[t]=Object.create(null);return e}function ka(e){let t=String(e||"");if(!Jr.includes(t))throw new Error(`unknown CustomVariableEntityType: ${e}`);return t}function kc(e,t){let i=ka(e);if(!Sc.includes(i))throw new Error(`${t}.entityType must be Level, PlayerSelf, or Player1-8`);return i}function ci(e){let t=String(e??"");if(!t)throw new Error("custom variable name is required");return t}function ji(e){let t=String(e??"");if(!t)throw new Error("signal name is required");return t}function Qr(e){let t=String(e||"PlayerSelf");if(!xa.includes(t))throw new Error(`unsupported client signal target: ${e}. use PlayerSelf, AllPlayers, or Player1-8`);return t}function ui(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=ui(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 we(e){return e===void 0?null:JSON.parse(JSON.stringify(e))}function va(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 wa(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:ui(t),value:t}):[]}function Ec(e){return String(e?.kind||e?.type||e?.name||e?.id||"")}function Yi(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Ea(e,t){if(!Yi(e)||!Object.prototype.hasOwnProperty.call(e,"fromSignalParam"))return null;if(Object.keys(e).some(r=>r!=="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 Sa(e,t){return Ea(e,t)||we(e)}function Ac(e,t,i){if(!Yi(e))throw new Error(`serverLogic.rules[${t}].actions[${i}] must be an object`);let r=String(e.kind||e.type||""),n=`serverLogic.rules[${t}].actions[${i}]`;if(r==="setCustomVariable"){let o=kc(e.entityType,n);if(!Object.prototype.hasOwnProperty.call(e,"value"))throw new Error(`${n}.value is required`);return{kind:r,entityType:o,name:ci(e.name),value:Sa(e.value,`${n}.value`),...e.variableType?{variableType:String(e.variableType)}:{}}}if(r==="sendClientScriptSignal"){if(!Array.isArray(e.params))throw new Error(`${n}.params must be an array`);return{kind:r,target:Qr(e.target),signalName:ji(e.signalName),params:e.params.map((o,a)=>Sa(o,`${n}.params[${a}]`))}}throw new Error(`${n}.kind must be setCustomVariable or sendClientScriptSignal`)}function fi(e){if(e==null)return{version:1,rules:[]};if(!Yi(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,r)=>{if(!Yi(i))throw new Error(`serverLogic.rules[${r}] must be an object`);if(!Array.isArray(i.actions)||i.actions.length===0)throw new Error(`serverLogic.rules[${r}].actions must be a non-empty array`);return{id:String(i.id||`signal-${r+1}`),signalName:ji(i.signalName),actions:i.actions.map((n,o)=>Ac(n,r,o))}})}}function Ia(e,t,{typed:i=!1}={}){let r=Ea(e,"server logic value");if(r){let n=i?t.params:t.values;if(r.fromSignalParam>=n.length)throw new Error(`signal ${t.name} has no parameter at index ${r.fromSignalParam}`);return we(n[r.fromSignalParam])}return we(e)}function _c(e){return e==="Level"?"Level":ut.includes(e)?"PlayerSelf":Zr.includes(e)?"AvatarSelf":e}function Aa(e={}){let t=ba(),i=ba(),r=[],n=[],o=[],a=[],s=Array.from({length:9},()=>null),c=1,l=0,u=Number(e.onlineLatencyMs||0);(!Number.isFinite(u)||u<0)&&(u=0);let h=fi(e.logic),d=ct(e.playerCount),g=je(e.viewPlayerIndex,d);function y(v,A){a.push({source:"server",level:String(v||"engine"),text:String(A),time:l})}function m(v){let A=s[v||g],w=Number(A?.clock?.time);Number.isFinite(w)&&(l=w)}function S(v,A,w,k){t[v][A]=w,i[v][A]={type:k||ui(w)||i[v][A]?.type||""}}function I(v,A,w){return typeof w!="number"||!Number.isInteger(w)?{ok:!0,value:w}:w>=Ic&&w<=Cc?{ok:!0,value:w}:(y("engine",`Int custom variable ${v}.${A} out of range ${w}; keeping previous legal value`),{ok:!1,value:t[v][A]})}function E(v,A){let w=ka(v),k=A||g;return w==="PlayerSelf"?li(k):w==="AvatarSelf"?Vi(k):w}function M(v,A){let w=_c(v);if(v==="Level"){for(let C=1;C<=d;C+=1){let N=s[C];N&&typeof N.notifyVarHandlers=="function"&&N.notifyVarHandlers("Level",A)}return}let k=ya(v);if(!k)return;let z=s[k];z&&typeof z.notifyVarHandlers=="function"&&z.notifyVarHandlers(w,A)}function F(v,A){let w=Qr(v);return w==="AllPlayers"?Array.from({length:d},(k,z)=>z+1):w==="PlayerSelf"?[A||g]:[ya(w)]}function H(v){for(let A of h.rules)if(A.signalName===v.name)for(let w of A.actions){if(w.kind==="setCustomVariable"){let k=Ia(w.value,v);D.setVar(w.entityType,w.name,k,{type:w.variableType,playerIndex:v.playerIndex}),y("info",`logic ${A.id}: set ${w.entityType}.${w.name}`);continue}if(w.kind==="sendClientScriptSignal"){let k=w.params.map(z=>Ia(z,v,{typed:!0}));D.sendToClient(w.signalName,k,{target:w.target,playerIndex:v.playerIndex}),y("info",`logic ${A.id}: sent ${w.signalName} to ${w.target}`)}}}function te(v,A){v&&(v.serverBridge={getVar:(w,k)=>D.getVar(w,k,{playerIndex:A}),setVar:(w,k,z)=>D.setVar(w,k,z,{playerIndex:A}),receiveFromClient:(w,k)=>D.receiveFromClient(w,k,{playerIndex:A})})}function Z(v){v&&(v.serverBridge=null)}let D={ENTITY_TYPES:Ca,ALL_ENTITY_TYPES:Jr,CLIENT_SIGNAL_TARGETS:xa,get clock(){return l},get playerCount(){return d},get viewPlayerIndex(){return g},setClock(v){l=Number(v)||0},setPlayerCount(v){return d=ct(v),g>d&&(g=d),d},setViewPlayerIndex(v){return g=je(v,d),g},log(v,A){y(v,A)},defineVar(v,A,w={},{playerIndex:k}={}){let z=E(v,k),C=ci(A);if(Object.prototype.hasOwnProperty.call(t[z],C))throw new Error(`custom variable already exists: ${z}.${C}`);let N=w.type?String(w.type):ui(w.value??w.defaultValue);if(N&&!ga.includes(N))throw new Error(`unsupported custom variable type: ${N}`);let G=w.value!==void 0?w.value:w.defaultValue!==void 0?w.defaultValue:null;return S(z,C,G,N),D.getVar(z,C)},getVar(v,A,{playerIndex:w}={}){let k=E(v,w),z=ci(A);if(!Object.prototype.hasOwnProperty.call(t[k],z)){y("engine",`GetGlobalCustomVariableValue missing ${k}.${z}; returning nil (simulator policy)`);return}return t[k][z]},setVar(v,A,w,{notify:k=!0,type:z,playerIndex:C}={}){let N=E(v,C),G=ci(A),B=z||i[N][G]?.type||ui(w);if(B&&!ga.includes(B)&&B!=="")throw new Error(`unsupported custom variable type: ${B}`);let se=w;if(!((B==="Int"||B===""&&typeof w=="number"&&Number.isInteger(w))&&(se=I(N,G,w).value,se===void 0)))return S(N,G,se,B),k&&M(N,G),se},listVars(v){let A=v?[E(v)]:["Level",...Array.from({length:d},(k,z)=>li(z+1)),...Array.from({length:d},(k,z)=>Vi(z+1))],w=[];for(let k of A)for(let z of Object.keys(t[k]))w.push({entityType:k,name:z,type:i[k][z]?.type||"",value:we(t[k][z])});return w},receiveFromClient(v,A=[],{playerIndex:w}={}){let k=je(w||g,d);m(k);let z=ji(v),C={id:c++,direction:"inbound",name:z,params:wa(A),values:va(A),time:l,playerIndex:k,from:li(k)};return r.push(C),H(C),C},sendToClient(v,A=[],{target:w="PlayerSelf",playerIndex:k}={}){let z=ji(v),C=Qr(w),G=F(C,k||g),B={id:c++,direction:"outbound",name:z,params:wa(A),values:va(A),time:l,target:C,players:G,deliverAt:l+u/1e3,delivered:!1};return n.push(B),u===0?D.deliver(B):o.push(B),B},getLogic(){return we(h)},setLogic(v){return h=fi(v),D.getLogic()},deliver(v){if(!v||v.delivered)return;v.delivered=!0;let A=Array.isArray(v.players)&&v.players.length?v.players:F(v.target);for(let w of A){let k=s[w];k&&typeof k.sendClientSignal=="function"&&k.sendClientSignal(v.name,v.values)}},flush(v){v!==void 0&&(l=Number(v)||0);let A=[];for(let w=o.length-1;w>=0;w-=1)o[w].deliverAt<=l&&A.push(o.splice(w,1)[0]);A.sort((w,k)=>w.id-k.id);for(let w of A)D.deliver(w);return A},inbound(){return r.slice()},outbound(){return n.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 A of v.nodes||[]){let w=Ec(A);if(!xc.has(w))throw new Error(`unsupported server node: ${w||JSON.stringify(A)}. v1 only supports custom variables and signals`)}if(v.onlineLatencyMs!==void 0){let A=Number(v.onlineLatencyMs);if(!Number.isFinite(A)||A<0)throw new Error("onlineLatencyMs must be a non-negative finite number");u=A}v.playerCount!==void 0&&D.setPlayerCount(v.playerCount),v.viewPlayerIndex!==void 0&&D.setViewPlayerIndex(v.viewPlayerIndex),(v.logic!==void 0||v.serverLogic!==void 0)&&D.setLogic(v.logic??v.serverLogic);for(let A of v.vars||[]){let w=E(A.entityType),k=ci(A.name);Object.prototype.hasOwnProperty.call(t[w],k)?D.setVar(w,k,A.value??A.defaultValue,{notify:!1,type:A.type}):D.defineVar(w,k,A)}}},attachRuntime(v,{playerIndex:A=1}={}){let w=je(A,8);return s[w]&&s[w]!==v&&Z(s[w]),s[w]=v||null,te(s[w],w),D},attachRuntimes(v){D.detachRuntime();let A=Array.isArray(v)?v:[];for(let w=0;w<A.length&&w<8;w+=1)s[w+1]=A[w]||null,te(s[w+1],w+1);return D},detachRuntime(){for(let v=1;v<=8;v+=1)Z(s[v]),s[v]=null},snapshot(){let v=li(g),A=Vi(g),w={Level:{},PlayerSelf:{},AvatarSelf:{}};for(let k of Object.keys(t.Level))w.Level[k]={type:i.Level[k]?.type||"",value:we(t.Level[k])};for(let k of Object.keys(t[v]))w.PlayerSelf[k]={type:i[v][k]?.type||"",value:we(t[v][k])};for(let k of Object.keys(t[A]))w.AvatarSelf[k]={type:i[A][k]?.type||"",value:we(t[A][k])};for(let k=1;k<=d;k+=1){let z=li(k),C=Vi(k);w[z]={},w[C]={};for(let N of Object.keys(t[z]))w[z][N]={type:i[z][N]?.type||"",value:we(t[z][N])};for(let N of Object.keys(t[C]))w[C][N]={type:i[C][N]?.type||"",value:we(t[C][N])}}return{clock:l,onlineLatencyMs:u,playerCount:d,viewPlayerIndex:g,logic:D.getLogic(),vars:w,inbound:r.map(k=>({id:k.id,name:k.name,params:we(k.params),values:we(k.values),time:k.time,playerIndex:k.playerIndex,from:k.from})),outbound:n.map(k=>({id:k.id,name:k.name,params:we(k.params),values:we(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 Jr){for(let A of Object.keys(t[v]))delete t[v][A];for(let A of Object.keys(i[v]))delete i[v][A]}r.length=0,n.length=0,o.length=0,a.length=0,c=1,l=0},destroy(){D.detachRuntime(),D.reset()}};e.config&&D.loadConfig(e.config);for(let v of e.vars||[])D.defineVar(v.entityType,v.name,v);return D}var Pc={container:"container",textbox:"textbox",image:"image",button:"button",cursor:"cursor",grid:"grid",reference:"reference",textwindow:"textwindow",keyhint:"keyhint",animation:"animation",fullscreen:"fullscreen"};function en(e,t,i=null){let r=Xe(e.transformByPlatform,t),n={authoringId:e.id,kind:Pc[e.kind]||"container",name:e.name,prefabIndex:e.guid||0,active:e.active!==!1,visible:e.visible!==!1,canControllerFocus:e.canControllerFocus===!0,anchoredPositionX:r.offset.x,anchoredPositionY:r.offset.y,sizeDeltaX:r.size.x,sizeDeltaY:r.size.y,anchorMinX:r.anchorMin.x,anchorMinY:r.anchorMin.y,anchorMaxX:r.anchorMax.x,anchorMaxY:r.anchorMax.y,pivotX:r.pivot.x,pivotY:r.pivot.y,localScaleX:r.scale.x,localScaleY:r.scale.y,localScaleZ:r.scale.z,localRotationX:r.rotation.x,localRotationY:r.rotation.y,localRotationZ:r.rotation.z,children:(e.children||[]).map(a=>en(a,t,i))},o=i?.get(e.id);return o?.length&&(n.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"&&(n.isolateNavigation=e.isolateNavigation===!0,n.disableKeyEventPassthrough=e.disableKeyEventPassthrough===!0,n.disableCursorEventPassthrough=e.disableCursorEventPassthrough===!0,n.showCursor=e.showCursor===!0),(e.kind==="textbox"||e.kind==="textwindow")&&(n.text=e.text??"",n.fontSize=e.fontSize,n.adaptiveFontSize=e.adaptiveFontSize===!0,n.minimumFontSize=e.minimumFontSize,n.fontColor=e.fontColor,n.bgColor=e.bgColor,n.enableOutline=e.enableOutline!==!1,n.outlineColor=e.outlineColor,n.horizontalAlignment=e.horizontalAlignment||"Left",n.verticalAlignment=e.verticalAlignment||"Top",e.kind==="textwindow"&&(n.interactable=e.interactable!==!1,n.showScrollBar=e.showScrollBar!==!1)),e.kind==="image"&&(n.imageSource=e.imageSource,n.imageId=e.imageId??0,n.imageColor=e.imageColor,n.raycastTarget=e.raycastTarget===!0,n.enableMask=e.enableMask===!0,n.enableSoftEdge=e.enableSoftEdge===!0,n.softEdgeMode=e.softEdgeMode,n.softEdgeWidthX=e.softEdgeWidthX,n.softEdgeWidthY=e.softEdgeWidthY,n.horizontalSoftRange=e.horizontalSoftRange,n.verticalSoftRange=e.verticalSoftRange,n.enableFill=e.enableFill===!0,n.fillType=e.enableFill?e.fillType:"Unused",n.fillHorizontalType=e.fillHorizontalType,n.fillVerticalType=e.fillVerticalType,n.fillRadial90Type=e.fillRadial90Type,n.fillRadialType=e.fillRadialType,n.fillAmount=e.fillAmount,n.reverseMaskArea=e.reverseMaskArea===!0),e.kind==="button"&&(n.raycastTarget=e.raycastTarget!==!1,n.interactable=e.interactable!==!1,n.clickAudioId=e.clickAudioId,n.unavailableChildId=e.unavailableChildId??null,n.hoverChildId=e.hoverChildId??null,n.pressedChildId=e.pressedChildId??null,n.selectedChildId=e.selectedChildId??null),e.kind==="cursor"&&(n.raycastTarget=e.raycastTarget!==!1),e.kind==="reference"&&(n.referencedPrefabIndex=e.referencedPrefabId),e.kind==="grid"&&(n.itemPrefabIndex=e.itemPrefabId,n.raycastTarget=e.raycastTarget!==!1,n.interactable=e.interactable!==!1,n.showScrollBar=e.showScrollBar!==!1,n.scrollDirection=e.scrollDirection,n.layoutConstraint=e.layoutConstraint,n.layoutConstraintFixedCount=e.layoutConstraintFixedCount,n.cellSizeX=e.cellSizeX,n.cellSizeY=e.cellSizeY,n.spacingX=e.spacingX,n.spacingY=e.spacingY,n.padding1X=e.padding1X,n.padding1Y=e.padding1Y,n.padding2X=e.padding2X,n.padding2Y=e.padding2Y,n.previewCount=e.previewCount),e.kind==="keyhint"&&(n.keyboardKeyCode=e.keyboardKeyCode,n.controllerKeyCode=e.controllerKeyCode),(e.kind==="animation"||e.kind==="fullscreen")&&(n.raycastTarget=!1,n.animationId=e.animationId,n.playSoundEffect=e.playSoundEffect,e.kind==="animation"&&(n.layer=e.layer)),n}function tn(e,t=[],i=""){let r=i&&X[i]?i:e.canvasId,n=X[r],o=Qt(e),a=new Map;for(let c of t){if(!c.controlId)continue;let l=a.get(c.controlId)||[];l.push(c),a.set(c.controlId,l)}let s=e.meta?.assetType==="client-control-template"?(e.root.children||[]).map(c=>en(c,r,a)):[];return{canvasId:r,platform:n.platform,device:n.luaDevice,canvasWidth:n.width,canvasHeight:n.height,root:en(o,r,a),templates:s}}var Bi="qxqy-autotest";var dt=.03333333333333333,Rc=new Set(["pointer","key","click","pause","resume","serverSet","serverSend","view"]),Tc=new Set(["log","control","var","signal","tree","lua"]);function ft(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function rn(e){return JSON.parse(JSON.stringify(e??null))}function Hi(e,t){if(!e||typeof e!="object")throw new Error(`events[${t}] must be an object`);let i=String(e.kind||e.do||"");if(!Rc.has(i))throw new Error(`unsupported event kind: ${i||"(empty)"}`);let r=e.payload&&typeof e.payload=="object"?{...e.payload}:{};if(i==="pointer")!r.type&&e.type&&(r.type=e.type),r.x===void 0&&(r.x=e.x),r.y===void 0&&(r.y=e.y),r.x=ft(r.x,"pointer.x"),r.y=ft(r.y,"pointer.y"),r.type=String(r.type||"click"),r.type==="wheel"&&(r.deltaX=ft(r.deltaX??e.deltaX??0,"pointer.deltaX"),r.deltaY=ft(r.deltaY??e.deltaY??0,"pointer.deltaY"));else if(i==="key"){if(r.typeName=String(r.typeName||r.key||e.typeName||e.key||""),!r.typeName)throw new Error("key event requires typeName")}else if(i==="click"){if(r.name=String(r.name||e.name||""),!r.name)throw new Error("click event requires control name")}else if(i==="serverSet"){if(r.entityType=String(r.entityType||e.entityType||""),r.name=String(r.name||e.name||""),r.value===void 0&&(r.value=e.value),r.value===void 0&&(r.value=null),!r.entityType||!r.name)throw new Error("serverSet requires entityType and name")}else if(i==="serverSend"){if(r.name=String(r.name||e.name||""),r.params=Array.isArray(r.params)?r.params:Array.isArray(e.params)?e.params:[],r.target=String(r.target||e.target||"PlayerSelf"),!r.name)throw new Error("serverSend requires signal name")}else if(i==="view"&&(r.playerIndex=Number(r.playerIndex||r.viewPlayerIndex||e.playerIndex||e.viewPlayerIndex||0),!Number.isInteger(r.playerIndex)||r.playerIndex<1))throw new Error("view event requires playerIndex 1-8");return{t:ft(e.t??0,"event.t"),source:String(e.source||"user"),kind:i,payload:r}}function nn(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(!Tc.has(i))throw new Error(`unsupported assert kind: ${i||"(empty)"}`);let r={kind:i};if(e.at!==void 0&&(r.at=ft(e.at,"assert.at")),i==="log"){if(r.contains=String(e.contains||e.check||e.text||""),r.source=e.source==="server"?"server":"client",e.level&&(r.level=String(e.level)),!r.contains)throw new Error("log assert requires contains")}else if(i==="control"){if(r.id=e.id?String(e.id):"",r.name=e.name?String(e.name):"",r.field=String(e.field||""),!r.field)throw new Error("control assert requires field");if(!r.id&&!r.name)throw new Error("control assert requires id or name");if(!Object.prototype.hasOwnProperty.call(e,"equals"))throw new Error("control assert requires equals");r.equals=rn(e.equals)}else if(i==="var"){if(r.entityType=String(e.entityType||""),r.name=String(e.name||""),!r.entityType||!r.name)throw new Error("var assert requires entityType and name");if(!Object.prototype.hasOwnProperty.call(e,"equals"))throw new Error("var assert requires equals");r.equals=rn(e.equals)}else if(i==="signal"){if(r.direction=e.direction==="outbound"?"outbound":"inbound",r.name=String(e.name||""),!r.name)throw new Error("signal assert requires name");e.values!==void 0&&(r.values=rn(e.values))}else if(i==="tree"){if(r.name=String(e.name||""),r.exists=e.exists!==!1,!r.name)throw new Error("tree assert requires name")}else if(i==="lua"&&(r.source=String(e.source||""),!r.source.trim()))throw new Error("lua assert requires source");return r}function _a(e){let t=0,i=[],r=[];for(let n of e){if(!n||typeof n!="object")throw new Error("queue step must be an object");if(n.do!=="start"){if(n.do==="step"){t+=ft(n.dt??dt,"step.dt");continue}if(n.do==="pointer"||n.do==="key"||n.do==="click"||n.do==="pause"||n.do==="resume"||n.do==="serverSet"||n.do==="serverSend"||n.do==="view"){i.push(Hi({...n,kind:n.do,t},i.length));continue}if(n.assert||n.check||n.kind){r.push(nn({...n.assert||n,at:n.at??t},r.length));continue}throw new Error(`unsupported queue step: ${JSON.stringify(n)}`)}}return{events:i,asserts:r,dt}}function di(e){if(Array.isArray(e)){let r=_a(e);return{format:Bi,version:1,name:"",dt:r.dt,events:r.events,asserts:r.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 r=_a(e.queue||e.steps);return{format:Bi,version:1,name:String(e.name||""),dt:Number(e.dt)>0?Number(e.dt):r.dt,events:r.events,asserts:r.asserts}}let t=(e.events||[]).map((r,n)=>Hi(r,n)),i=(e.asserts||[]).map((r,n)=>nn(r,n));return t.sort((r,n)=>r.t-n.t||0),{format:Bi,version:1,name:String(e.name||""),dt:Number(e.dt)>0?Number(e.dt):dt,playerCount:Number(e.playerCount)>0?Number(e.playerCount):1,events:t,asserts:i}}function Pa(e,t={}){let i=(e||[]).map((r,n)=>Hi(r,n));return{format:Bi,version:1,name:String(t.name||""),dt:Number(t.dt)>0?Number(t.dt):dt,playerCount:Number(t.playerCount)>0?Number(t.playerCount):1,events:i,asserts:(t.asserts||[]).map((r,n)=>nn(r,n))}}function Ra(e,t,i){if(!e)return null;let r=Hi({...t,t:t.t??i??0},e.events.length);return e.events.push(r),r}import{createCanvas as Mc}from"@napi-rs/canvas";var Ta=Mc(1,1).getContext("2d"),Nc='"Microsoft YaHei UI","Microsoft YaHei",sans-serif',Ui=(e,t)=>Math.max(0,Math.min(t,Number.isFinite(e)?e:0));function Ma(e,t,i){let r=Math.max(8,Number(e.fontSize)||12),n=String(e.text??"").replace(/\r\n?/g,`
|
|
110
|
-
`),
|
|
111
|
-
`)){let S="";for(let I of m)S&&Ta.measureText(S+I).width>g&&(y.push(S),S=""),S+=I;y.push(S)}return y},u=l(Math.max(1,t-4)),h=e.showScrollBar!==!1&&u.length*r*1.2>i,d=Math.max(1,t-4-(h?12:0));h&&(u=l(d)),a=e._textWindowLayout={key:o,lines:u,font:r,textWidth:d,lineHeight:r*1.2,length:u.length*r*1.2}}let s=Math.max(0,a.length-i),c=Ui(e._scrollOffset||0,s);return e._scrollOffset=c,{...a,max:s,offset:c,viewport:i,horizontal:!1,width:t,height:i}}function Mt(e,t,i){if(!e?.showBar||e.max<=0||t<=0||i<=0)return null;let r=e.horizontal===!0,n=r?t:i,o=Math.max(0,n-4),a=Math.min(o,Math.max(18,o*n/(n+e.max))),s=o-a,c=s*e.offset/e.max,l=Math.min(8,r?i:t),u=r?{x:-t/2+2,y:i/2-l-2,width:o,height:l}:{x:t/2-l-2,y:-i/2+2,width:l,height:o},h=r?{...u,x:u.x+c,width:a}:{...u,y:u.y+c,height:a};return{track:u,thumb:h,travel:s}}var Na="https://oss.070077.xyz/",on="mp3-v1",Li="/qxqy-audio/",Fc=[[10001,"ura.1ht4.2ag9.1hh5.jbb.k02.jcw.2tv.2wn.2xk.2r3.d5s.94l.ebv.kcr.b40.77k.9gp.97w.1hb5.jag.btu.jc9.hp5.bmj.blq.blq.ff9.ffk.o74.1owl.rp.mg.l3.lf.lh.qy.1a3z.2xk.2xk.2xk.2xk.2xk.17dc.1f2b.2bc.2bc.2bc.2bc.2bc.ffo.ffo.126.1fk.4mo.4mo.15e.1h2.237.2ba.2kd.2bc.4mo.4mo.4mo.4mo.1mc.1n6.2cu.1ud.2b1.2ee.1tj.1tk"],[20001,"o6.fh.kb.cr.og.sm.6x.8c.87.o7.vz.kt.qo.lg.ob.9w.mg.1kz.zc.1ex.1d5.ps.uu.su.qs.ys.zp.10k.15a.xc.uk.mx.1ax.nt.tu.19m.uj.1ku.tt.100.ie.d3.fp.ie.ie.d3.fp.ie.8p.7k.fw.h0.qc.ot.uc.ot.rk.gb.1c2.ff.cl.9v.wg.1ir.1lr.1b8.1ri.1p0.104.10n.mw.j6.jb.f1.dv.84.a0.cp.bx.1ko.1au.1ia.rs.rt.rs.t7.x6.wi.zc.16f.1i6.2jh.28d.qh.k8.1gz.1ko.2iv.1xp.1l4.1gk.10j.yo.1jk.1jk.xv.104.15o.1xg.1xg.1xi.25i.p1.t1.yh.1ak.1i6.1y2.xt.32u.3g6.1bz.2mn.14l.14c.1e1.op.s8.p2.v5.2ix.1a0.ry.16m.17n.13c.134.ys.yu.xr.sl.sr.sd.yh.z5.gd.gl.hx.h2.g8.fj.iy.hz.jj.th.12n.16r.d3.j9.dg.lj.fl.a7.f9.iw.el.27f.1dh.1rh.2ph.yd.w5.x5.tr.pq.zf.16h.1a5.17t.wy.vn.y8.wl.yv.2ye.2qt.1ah.163.19t.uf.119.2vv.1bm.13h.14p.1so.c3.as.9z.19w.1l4.1nl.rj.we"],[30001,"jo.my.ss.dw.c1.b4.hl.hl.hl.cz.dw.dw.b4.dw.fr.kd.qv.px.px.74.6u.8h.60.8q.8b.eo.eo.eo.8k.a5.99.12v.13y.lg.m4.qr.dw.ex.g0.ef.cd.br.11n.17h.1b8.1c9.9p.ag.9z.l9.m8.m8.lw.m8.cz.99.b4.8c.63.7f.6h.99.re.pp.pi.cq.c9.cp.ck.c6.b0.bd.al.f6.gl.ed.fs.lc.k6.kh.i6.cx.j1.hk.gb.d7.h7.g2.em.kj.kn.k4.j5.rh.t0.qt.mj.i7.ih.i2.hd.3r.8d.6u.6z.by.de.dg.cr.1a5.1ab.16c.18g.n2.ly.no.nt.f9.de.lr.fe.f0.fj.el.fo.t1.g9.ly.h3.g6.de.2ak.2f3.wf.kg.qn.11p.rg.uj.u6.11c.22o.2cs.3dp.3dq.3d5.3d6.1zx.18v"],[40001,"19x.215.2zt.1ex.2pj.7hy.1ur.1gn.1g7.1b1.u9.1tw.108.1ew.rs.1qu.w9.lk.244.qi.b6.tk.jg.jg.jg.y4.c1.b4.iv.hi.r4.n7.gy.ev.qe.12z.18n.dw.1l6.ou.wz.1un.19t.18k.yy.1hs.sl.dw.1vl.100.14k.1q8.209.1jk.1xr.ua.1j2.pr.26h.1gs.s9.px.15v.pf.1jk.xc.1hb.111.172.ut.285.1oh.149.zj.22r.2l9.14a.ok.23y.1eh.xe.1j0.1rp.1cz.wf.1mh.22k.334.1z2.1xo.1br.4ji.5nq.5nf.2za.18r.h3.eo.ia.1kn.dc.ss.s0.1bl.1oc.is.km.177.1ec.1ao.h4.hp.dx.l9.iw.i3.12w.n1.yq.12w.1ju.yx.14s.18b.22t.u3.my.2rb.36w.13u.z8.20r.18g.19r.2x9.w4.q2.1d2.wo.13a.v6.17w.ur.288.1b6.14m.1fi.1xx.1ee.kj.121.j2.1d2.2ad.1ri.2lc.1vk.138.12r.xj.1h5.1c5.2qx.1gj.t2.lv.rf.18q.1kz.dw.2aq.ia.1i9.k5.199.f4.10y.18a.xf.rk.1g9.1q3.10h.sj.15o.e3.dz.sv.135.w9.yg.aw.2a2.19m.22w.1c8.272.13o.104.1sr.rs.1pb.d5.df.kp.jq.1a7.s8.1ao.ba.rb.in.pz.q8.140.ij.1e7.jl.yk.117.10i.1tn.1oj.1sv.sj.1e3.2so.1c7.1gv.178.107.10n.1dx.1qi.1wp.2bc.218.16r.105.xc.z6.11w.1mc.1y9.17p.1cs.2ij.18c.1ie.nn.16c.1ce.xb.1ei.3j0.ve.14x.1sx.285.1b8.1at.v4.rv.rs.10z.xq.11o.15k.xq.u1.i2.pu.i4.l3.9u.oh.mc.nm.pw.1i3.1h4.pj.111.l4.lb.qq.qf.u0.h4.nk.yf.6h.ij.ds.oy.re.m8.1gl.cz.16z.a1.1f8.1x6.vp.dz.gp.g6.fr.vl.fr.gg.qc.aj.99.go.ij.fz.11a.x5.mo.1u9.h0.m8.10m.1an.2bc.3uw.2gk.124.xb.1uk.1b6.2xj.1os.11a.vs.1i9.1lr.2gv.265.668.1xg.45j.404.2x1.1io.3om.4q2.4mo.1d4.2bp.1pr.166.2y6.2bv.361.2nc.2bc.3g0.7g4.334.2bc.2xo.3uw.6ic.4ig.3uw.23v.1la.2zr.1jt.1cq.27a.1n1.19x.1qg.1jn.1ca.26y.2d6.4v4.4mo.4mo.7ps.1jk.153.1fo.1dm.1s2.1w1.oe.1lb.319.2eg.58p.4mo.3dw.2y2.2xm.1u8.1ko.12n.1e0.2sd.1md.2cl.1q2.372.4mo.48s.b14.3fu.334.334.34i.4nf.4ji.5eg.3uw.2u8.1g1.110.37x.2jo.su.334.3aj.3uw.63f.2bc.2bc.8v4.1ts.ax5.5du.34d.3oc.34j.4si.174.rt.1rp.2b0.37d.1ta.2gh.28a.22z.1nc.1a5.1pa.4dd.3ha.2cs.5mv.4mq.5c2.3uw.1gf.4md.113.10x.21o.2hj.1b3.1cx.1ol.3ar.1fv.17t.1a7.2uj.2we.1jk"],[50001,"1o8.1k1.mo.1wu.2c9.22d.1kb.23n.1b8.1ic.24c.2wz.1mq.1mu.1jx.1z1.o3.190.vp.1h7.th.4mo.1rp.4mo.4mo.7ps.zz.143.21v.1nf.34s.1s3.r9.18t.s1.r9.21w.277.ls.25k.5v1.2bc.1kh.wt.14i.1eq.15o.668.sh.rl.3wi.3vc.43c.3yn.17c.f5.xu.jg.176.19v.1xy.23m.18x.30c.10l.13k.v8.vp.17t.qj.17m.1wr.1la.8t.s7.18d.1l2.152.mx.1c8.1l4.1f5.1xe.rz.2hz.1et.13t.xb.14r.15o.z0.1zo.ur.257.1gb.li.12d.15a.132.1m1.3vu.296.1mg.11m.z0.159.mp.hd.x4.1go.ns.xh.2a7.tt.2vb.1bx.1kh.u3.11i.1y1.24e.2hp.2mn.1w6.3zm.166.14g.1mo.2v9.2rg.2f9.1r0.139.m1.k3.ys.1dy.29k.1mm.22m.3zx.4dr.2h7.22o.tv.rm.1et.2wv.2ar.1t7.ku.12s.10b.1v9.1gu.12m.1b3.tv.1c8.tk.10s.ul.1tt.ka.oi.qb.13f.13f.13k.17h.1uh.ez.en.2x7.2ln.2h8.3h8.ig.n9.27o.18b.hl.nm.uk.11a.1ta.1k4.1eh.wv.1go.1gg.sc.18u.1dz.2aq.vt.2l7.25h.1l5.1kn.1vc.1b4.28i.17t.1d6.1k2.18z.jy.jw.dh.1mx.fr.vp.35w.34z.35w.34z.4so.vf.yx.1bg.1d3.2yc.1tg.8q3.99g.am.2du.rm.rg.xa.2cw.xc.1j6.1if.18z.13a.yz.142.1z5.262.1bj.1y8.ur.u5.16j.1pf.1bi.l8.1il.3vz.2dr.jo.ls.18s.16l.18c.141.219.1yz.1fc.24t.27e.481.1vp.25h.1yq.1zn.1uw.11u.1jp.1pz.39o.t6.1mj.1u5.11l.1vd.1dk.1zb.1ic.3ql.14p.1wq.25x.267.zn.zn.1pf.13z.1j7.r9.1hb.4yp.1lt.1cw.1z4.19z.1og.1j4.1cl.1eg.u8.16s.1en.zu.1hr.1js.19g.303.22j.2oa.180.1v7.2ud.2d7.21s.3g9.vh.v1.284.3lg.3lg.17q.1h3.4mo.1cm.1rv.22i.2mc.2j3.27o.333.1q8.237.2ll.23b.2sp.2ll.2ox.2cf.2f8.2hz.1uo.y4.s9.w6.2dg.2q9.up.1m1.1vz.2n8.192.1eb.z7.2em.2q3.1sd.1gj.348.3vf.2iu.29x.1dc.7oj.4pq.5vb.4mx.5me.5sf.5yf.7ps.yj.q0.10w.13p.18b.2wd.11q.2vx.dd.iv.12p.jh.u9.1uy.w0.3f0.3bj.126.qo.1gj.11k.pu.22h.1z6.rp.y4.y0.xl.1d0.11s.wa.1a6.127.10m.12r.1nh.1fy.yo.1js.162.n4.174.1aj.y4.o8.qz.rh.qa.18s.mr.j3.ii.sr.sx.1jk.17l.mj.zr.uy.wa.19t.2bt.xe.1od.hs.xr.5b.12c.1ab.we.gz.mz.4y.sf.11s.e0.1l7.ew.h6.jz.l0.e8.1cx.p6.17u.bw.1ah.10r.10e.o9.1bc.uv.lq.tl.zb.100.jy.b8.bj.336.10n.na.sq.14r.yr.nm.123.tf.l1.zp.1xc.1vk.31l.zl.2bj.2b9.2fv.17p.y0.so.1ln.29c.1eh.nh.xn.131.qc.186.ff.fc.xq.1bm.la.l8.14f.243.111.xi.qw.1qn.11v.1ur.1jx.1ks.s9.nz.269.1zj.2zd.1pv.18n.2vk.p3.1fh.13v.1lf.1lu.2db.1sr.1k3.26o.1dl.1f3.187.2lh.166.v9.xh.1e3.119.s2.mt.1iu.1k6.1o2.12s.u4.2br.1q3.qv.1e4.1zu.1v4.1vk.1t3.3p7.1ob.14d.1ns.1ef.1e4.12w.2kk.1ba.2jx.1e0.1s5.12w.17r.14s.wz.1qp.183.3fb.188.1gr.2ot.168.1u7.w8.28o.1zd.32z.230.w7.vq.x8.1qh.19f.14o.2r9.qg.1ey.1qr.1p6.3a3.1ov.13d.tz.wk.22v.1qa.2l9.yw.yf.nw.p6.1ly.1jk.1nh.x9.q0.17r.17h.ux.uw.12y.p7.g7.kt.14c.ze.1kh.1eo.18a.1d8.26j.15k.19f.1ym.1j5.1c6.11k.1sd.1jp.1ws.13s.1o5.214.sx.px.20x.14h.1ja.s6.1q8.w8.1ks.so.ub.121.202.1ej.1g1.1s8.2bc.4t1.bih.3uw.3pb.avp.6c7.bko.5eg.79c.6wh.3wd.4pn.55j.4a5.3gg.bko.5ei.52p.578.bcv.6gr.2bc.4j9.5y7.9d2.2bb.2bc.668.73z.5pg.50f.5m7.788.267.642.8h2.8h2.49s.64g.5e8.5e8.2bb.3ih.5ur.6bk.578.4ck.3sg.5fe.23i.e9w.2b8.5oj.6bw.2al.2rk.2rk.5pj.n6e.350.6v9.70t.639.3uw.3uw.2bg.639.2bb.2bd.6gj.2bh.660.578.3bk.65e.359.3o0.44i.4tn.1zq.5ee.4a5.3zu.rs.639.33q.5eg.1k1.15o.dw.3uw.b7p.7qd.898.4l4.5uu.5uu.b4g.2yh.2yh.3uw.51a.51a.5kk.66f.iq9.3n7.4nb.46a.1wb.20p.bih.8xa.7ps.70t.70t.4rv.5p1.6aq.ts.63z.668.5v2.5nu.563.55s.55s.5p3.2ga.32x.42x.5cr.4c2.71b.5zp.5c2.66t.4c8.2bc.2bc.2gn.3ea.2kp.fz6.8hz.3e8.4an.bko.j7e.jag.7sr.2bc.3zx.7qd.5ut.5jp.2wk.5q7.3uw.334.4i3.3uw.4bd.5eu.46h.4i2.6t4.446.5s7.5cg.4bk.5nd.7bf.4rt.23b.2bc.2bc.2bc.2bc.2ba.4mo.4dv.3wn.2bc.1we.4he.2bc.4gz.3wn.3km.4xy.4hi.4mr.2bc.247.3yj.2c6.2bc.3aj.446.4ub.3uw.51.e0.86.is.i1.hg.mn.m4.2c.7h.sg.e3.jb.7r.eq.nf.u0.60.4o.ke.47.47.47.47.b8.4x.dr.dy.rw.rw.59.8j.5z.a5.l3.c0.ik.f7.li.lr.7x.dv.du.dd.5e.91.1b.ce.cc.59.bh.e6.8m.9n.cl.lt.7ip.4mr.4si.4kf.vo.we.13e.17n.1iw.2pi.lp.r6.gw.7x.xz.qt.bq.ls.q1.eh.bx.cr.3c.j7.b8.fz.4k.8p.bg.5w.iy.j3.12o.rs.cz.dp.yz.jk.63.63.7ps.7ps.7ps.40g.3jp.4tw.89k.88a.7s0.83d.668.7ps.2fw.2ev.2fp.7ps.2jb.2dh.2ud.25i.24c.2bt.1pa.17r.1a7.7ps.7pt.5rg.4nl.3vv.7qo.31a.2p0.2k0.49a.3v4.3nl.1ug.1ug.1l6.7s1.7ps.2cp.2f8.2i7.7ps.28q.2be.275.1ma.1oz.1q7.16s.1iq.1e0.78m.7ps.2bc.2bc.2bc.bko.2wu.2wu.2wu.3b4.38f.3uw.3uw.3uw.3uw.7ps.7qa.32n.2gg.2wk.7rv.1v3.1qq.1rb.1zk.1my.1zp.1yn.1oh.1uh.7st.9q.9q.9q.9q.9q.kk.kk.kk.kk.kk.dw.dp.dw.rs.rs.rs.rs.s4.sd.54j.5n8.2n6.21r.1nu.1o5.14u.t6.3f7.2j0.32c.304.189.1gf.18w.18j.1st.1vq.116.kw.3uw.3uw.vr.zx.xc.tc.7d.7r.9d.9w.8s.9p.3b.3b"]].map(([e,t])=>[e,t.split(".").map(i=>parseInt(i,36)/1e3)]);function Xi(e){if(!Number.isSafeInteger(e))return null;for(let[t,i]of Fc)if(e>=t&&e<t+i.length)return i[e-t];return null}import{randomUUID as Da}from"node:crypto";function qi(e){for(let t of e.runtime.scrollControls||[]){let[i,r]=ri(t),n=t.kind==="grid"?_t(t):Ma(t,i,r),o={offset:n.offset,max:n.max,horizontal:n.horizontal,showBar:t.showScrollBar!==!1,textWidth:n.textWidth??0,lines:n.lines||[],lineHeight:n.lineHeight||0,contentLength:n.length},a=JSON.stringify(o);t._scrollKey!==a&&(t._scrollKey=a,t._scroll=o,t.markPlayDirty())}}function $a(e){return{...e._scroll?{scroll:e._scroll}:{},...e.parent?._gridItems?.includes(e)?{clipToParent:!0}:{}}}function an(e,t){let i=e._scroll?.max||0;e.kind==="grid"?e.scrollProgress=i?Ui(t,i)/i:0:e._scrollOffset=Ui(t,i),e.markPlayDirty()}var Oc=Object.freeze(Object.values(X).map(e=>Object.freeze({id:e.id,label:e.label,platform:e.platform,width:e.width,height:e.height})));function Ji(e){qi(e);let t=ye({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),i=new Map;function r(n,o,a){let s=De(o,n);s.activeInHierarchy=a&&n.active!==!1,i.set(n.Id,s);let c=s.activeInHierarchy;for(let l of n.children)r(l,s,c)}for(let n of e.runtime.roots)r(n,t,!0);return i}function Ga(e,t=Ji(e)){let i=new Map;function r(n,o){let a=t.get(n.Id);if(!a)return;let s=Jt(o,a,n);i.set(n.Id,s);for(let c of n.children)r(c,s)}for(let n of e.runtime.roots)r(n,Ct());return i}function Va(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,...e._scroll?{scrollOffset:e._scroll.offset,scrollMax:e._scroll.max}:{},...e.kind==="grid"?{itemCount:e.itemCount,scrollProgress:e.scrollProgress}:{},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"?St(e.imageId):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(r=>Va(r,t))}}function zc(){return{pointerDownControl:null,pointerDownPosition:null,pointerLastPosition:null,pointerDragging:!1,pointerHoverControl:null,pointerScroll:null,hoveredControl:null,selectedControl:null,stateRestores:new Map,viewCache:null}}function Dc(e,t,i,r){let n=si({canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight,device:e.device,audioDuration:Xi,...r?{language:r}:{}});for(let o of[...e.templates||[],...t?.templates||[]])Number.isSafeInteger(o.prefabIndex)&&o.prefabIndex>0&&n.registerTemplate(o.prefabIndex,o);for(let o of i){let a=o.path||o.id,s=o.source||"";a&&s&&n.registerScriptFile(a,s)}return n}var $c=["pointerDownControl","pointerDownPosition","pointerLastPosition","pointerDragging","pointerHoverControl","pointerScroll","hoveredControl","selectedControl","stateRestores","viewCache"];function Gc(e){Object.defineProperty(e,"runtime",{configurable:!0,enumerable:!0,get(){return e.runtimes[e.viewPlayerIndex-1]}});for(let t of $c)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 ja(e,{templatesProject:t=null,scripts:i=[],sceneScripts:r=null,templateScripts:n=null,serverConfig:o=null,canvasId:a="",playerCount:s=1,viewPlayerIndex:c=1,language:l=""}={}){let u=r||i,h=n||i,d=tn(e,u,a),g=t?tn(t,h,a):null,y=ct(s),m=je(c,y),S=Aa({playerCount:y,viewPlayerIndex:m});o&&S.loadConfig({...o,playerCount:y,viewPlayerIndex:m});let I=[];for(let F=0;F<y;F+=1)I.push(Dc(d,g,i,l));S.attachRuntimes(I);for(let F of I)F.addRoot(d.root);let E={audioSessionId:Da(),runtimes:I,views:I.map(()=>zc()),playerCount:y,viewPlayerIndex:m,server:S,compiled:d,mountError:I.find(F=>F.mountErrors[0])?.mountErrors[0]||null,debugPaused:!1,history:{events:[]},recording:!0};Gc(E);let M=E.viewPlayerIndex;for(let F=1;F<=y;F+=1)E.viewPlayerIndex=F,Jc(E);return E.viewPlayerIndex=M,E}function un(e,t){if(!e)throw new Error("play session has not started");let i=je(t,e.playerCount);return i===e.viewPlayerIndex||(Qe(e,{kind:"view",payload:{playerIndex:i}}),e.viewPlayerIndex=i,e.viewCache=null,e.server&&e.server.setViewPlayerIndex(i)),i}function Qe(e,t){!e?.recording||!e.history||Ra(e.history,{...t,source:t.source||"user"},e.runtime.clock.time)}function Vc(e){return e?.history?.events||[]}var fn=new Set(["image","textbox","textwindow","button","grid"]);function jc(e,t){let i=$e(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 ht(e){return typeof e=="string"?e:e?.Name}function Ya(e){return{fillType:ht(e.fillType),fillHorizontalType:ht(e.fillHorizontalType),fillVerticalType:ht(e.fillVerticalType),fillAmount:e.fillAmount}}function Yc(e,t,i){let r=Math.abs(t.width*i.scaleX),n=Math.abs(t.height*i.scaleY),o={id:e.Id,kind:e.kind,name:e.name,left:i.centerX-r/2,bottom:i.centerY-n/2,width:r,height:n,sourceWidth:t.width,sourceHeight:t.height,rotationZ:i.rotationZ,matrix:i.matrix,pressed:e.pressed===!0,...$a(e)};return e.kind==="image"&&(o.primitive=St(e.imageId),o.imageColor=e.imageColor,o.imageId=e.imageId,Object.assign(o,Ya(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=ht(e.horizontalAlignment),o.verticalAlignment=ht(e.verticalAlignment)),o}function Bc(e,t=Ji(e)){let i=[],r=Ga(e,t);function n(o,a=[]){let s=t.get(o.Id);if(!s||o.visible===!1||!s.activeInHierarchy)return;let c=r.get(o.Id);if(!c)return;let l=jc(s,c),u=()=>i.push({...Yc(o,s,l),...a.length?{clipPolygons:a}:{}});fn.has(o.kind)&&o.kind!=="grid"&&u();let h=o.children||[];for(let d=h.length-1;d>=0;d-=1){let g=o._gridItems?.includes(h[d])?[...a,[[s.left,s.bottom],[s.right,s.bottom],[s.right,s.top],[s.left,s.top]].map(([y,m])=>$e(c,y,m))]:a;n(h[d],g)}o.kind==="grid"&&u()}for(let o of e.runtime.roots)n(o);return i}function Hc(e,t){let i={kind:e.kind,name:e.name,sourceWidth:t.width,sourceHeight:t.height,pressed:e.pressed===!0,...$a(e)};return e.kind==="image"&&(i.primitive=St(e.imageId),i.imageColor=e.imageColor,i.imageId=e.imageId,Object.assign(i,Ya(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=ht(e.horizontalAlignment),i.verticalAlignment=ht(e.verticalAlignment)),i}function Uc(e,t,i){let r=wr(e,t),n=$e(r,e.centerX,e.centerY);return{a:r.a,b:r.b,c:r.c,d:r.d,tx:n.x-(i?i.centerX:0),ty:n.y-(i?i.centerY:0)}}function Ba(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,JSON.stringify(e.scroll),e.clipToParent].join(" ")}function Ha(e,t,i,r,n,o){return{id:e.Id,parent:t,z:n,group:o>=16,matrix:Uc(r,e,i),...Hc(e,r)}}function Lc(e){let t=ye({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),i=new Set,r=new Map,n=new Map;function o(c,l,u){let h=De(l,c);if(h.activeInHierarchy=u&&c.active!==!1,n.set(c.Id,h),c.visible===!1||!h.activeInHierarchy)return!1;let d=c.children||[],g=fn.has(c.kind),y=0;for(let m=0;m<d.length;m+=1)o(d[m],h,h.activeInHierarchy)&&(g=!0,y+=1);return g?(i.add(c.Id),r.set(c.Id,y),!0):!1}function a(c,l,u,h){if(!i.has(c.Id))return;let d=n.get(c.Id);s.push(Ha(c,l,u,d,h,r.get(c.Id)||0));let g=c.children||[];for(let y=0;y<g.length;y+=1)a(g[y],c.Id,d,y)}let s=[];for(let c=0;c<e.runtime.roots.length;c+=1)o(e.runtime.roots[c],t,!0),a(e.runtime.roots[c],null,null,c);return{nodes:s,childCounts:r}}function ln(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 r=0;r<i.length;r+=1)ln(i[r])}function Xc(e,t){let i=ye({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),r=[],n=[],o=t.count,a=e.runtime._playRemoved||[];for(let l=0;l<a.length;l+=1){let u=a[l];t.fingerprints.has(u)&&(n.push(u),t.fingerprints.delete(u),t.childCounts.delete(u),o-=1)}e.runtime._playRemoved=[];function s(l){t.fingerprints.has(l.Id)&&(n.push(l.Id),t.fingerprints.delete(l.Id),t.childCounts.delete(l.Id),o-=1);let u=l.children;for(let h=0;h<u.length;h+=1)s(u[h])}function c(l,u,h,d,g,y){let m=y||l._playDeepDirty===!0,S=m||l._playDirty===!0,I=m||l._playChildDirty===!0;if(!S&&!I)return;if(!(g&&l.active!==!1)||l.visible===!1){s(l);return}let M=De(u,l),F=t.childCounts.get(l.Id)||0;if(I){F=0;let A=l.children;for(let w=0;w<A.length;w+=1)c(A[w],M,l.Id,w,!0,m),t.fingerprints.has(A[w].Id)&&(F+=1)}if(!(fn.has(l.kind)||F>0)){t.fingerprints.has(l.Id)&&(n.push(l.Id),t.fingerprints.delete(l.Id),t.childCounts.delete(l.Id),o-=1);return}let te=t.childCounts.get(l.Id);t.childCounts.set(l.Id,F);let Z=F>=16!=(te||0)>=16;if(!S&&!Z&&t.fingerprints.has(l.Id))return;let D=Ha(l,h,u===i?null:u,M,d,F),v=Ba(D);t.fingerprints.get(D.id)!==v&&(t.fingerprints.has(D.id)||(o+=1),t.fingerprints.set(D.id,v),r.push(D))}for(let l=0;l<e.runtime.roots.length;l+=1)c(e.runtime.roots[l],i,null,l,!0,!1);return t.count=o,{changed:r,removed:n,count:o}}function Wc(e,t){let i=e.viewCache||(e.viewCache={rev:0,fingerprints:new Map,childCounts:new Map,count:0}),r=Number(t);if(!(Number.isFinite(r)&&r===i.rev&&i.fingerprints.size>0)){let{nodes:c,childCounts:l}=Lc(e);i.rev+=1,i.fingerprints=new Map(c.map(u=>[u.id,Ba(u)])),i.childCounts=l,i.count=c.length;for(let u of e.runtime.roots)ln(u);return{format:"tree-v1",revision:i.rev,reset:!0,count:c.length,nodes:c}}let{changed:o,removed:a,count:s}=Xc(e,i);i.rev+=1;for(let c of e.runtime.roots)ln(c);return{format:"tree-v1",revision:i.rev,reset:!1,count:s,changed:o,removed:a}}function dn(e,{inspect:t=!1,view:i=!1,paint:r=!1,sceneRev:n,compact:o=!1}={}){qi(e),e.audioSessionId||=Da();let a=e.runtime,s=e.compiled,[c,l]=[a.canvasWidth,a.canvasHeight];e.server&&e.server.setClock(a.clock.time);let u=o?a.logs.slice(-100):a.logs,h=Vc(e),d=e.server?e.server.snapshot():{vars:{},inbound:[],outbound:[],logs:[]};o&&(d.inbound=d.inbound.slice(-100),d.outbound=d.outbound.slice(-100),d.logs=d.logs.slice(-100));let g={canvasId:s.canvasId,platform:s.platform,device:a.device,canvasWidth:c,canvasHeight:l,canvasPresets:Oc,playerCount:e.playerCount||1,viewPlayerIndex:e.viewPlayerIndex||1,players:Array.from({length:e.playerCount||1},(y,m)=>({index:m+1,label:`\u73A9\u5BB6${m+1}`,entityType:`Player${m+1}`})),time:a.clock.time,frame:a.clock.frame,paused:!!e.debugPaused,levelTimePaused:!!a.clock.paused,audio:{sessionId:e.audioSessionId,playerIndex:e.viewPlayerIndex||1,...a.audioSnapshot()},mountError:e.mountError||a.mountErrors[0]||null,logs:u.map(y=>({source:"client",level:y.level,text:y.text,time:y.time})),tree:[],paint:[],scene:null,server:d,history:(o?h.slice(-100):h).map(y=>({t:y.t,source:y.source||"user",kind:y.kind,payload:y.payload||{}}))};if(t||r){let y=Ji(e);t&&(g.tree=a.roots.map(m=>Va(m,y))),r&&(g.paint=Bc(e,y))}return i&&(g.scene=Wc(e,n)),It(g),g}function Qi(e,t=1/30){let i=e.runtimes||(e.runtime?[e.runtime]:[]);for(let r of i)r.step(t);e.server&&(e.server.setClock(e.runtime.clock.time),e.server.flush())}function hn(e,t){Qe(e,{kind:"key",payload:{typeName:String(t)}}),e.runtime.injectKey(t)}function Kc(e,t){let i=null;for(let r of e.runtime.roots)Fe(r,n=>{!i&&n.name===t&&(i=n)});return i}function pn(e,t){Qe(e,{kind:"click",payload:{name:String(t)}});let i=Kc(e,t);i&&mn(i)&&(i.kind==="button"||i.kind==="cursor")&&i.SimulateCursorClick()}function qc(e,t){return!e||!t?null:e.children.find(i=>i.authoringId===t||i.Id===t)||null}var Ua={unavailable:"unavailableChildId",hover:"hoverChildId",pressed:"pressedChildId",selected:"selectedChildId"};function La(e,t){let i=[];for(let[r,n]of Object.entries(Ua)){let o=t[n]?qc(t,t[n]):null;o&&i.push({state:r,child:o})}return i}function Jc(e){for(let t of e.runtime.roots)Fe(t,i=>{if(i.kind==="button"){for(let{child:r}of La(e,i))e.stateRestores.has(r.Id)||e.stateRestores.set(r.Id,{child:r,active:r.active,visible:r.visible}),r.active=!0,r.visible=!1,typeof r.markPlayDirty=="function"&&r.markPlayDirty(!0);hi(e,i)}})}function hi(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 r of La(e,t))r.child.active=!0,r.child.visible=r.state===i,typeof r.child.markPlayDirty=="function"&&r.child.markPlayDirty(!0)}function sn(e){if(!e)return null;let t=e.parent;return t?.kind==="button"&&Object.values(Ua).map(r=>t[r]).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 Xa(e){return e.kind==="container"||e.kind==="grid"||e.kind==="textwindow"||e.kind==="reference"||e.kind==="button"}function Wa(e,t){let i=e.Id,r=t.get(i);if(r!==void 0)return r;let n=mn(e);if(!n&&Xa(e)){let o=e.children;for(let a=0;a<o.length;a+=1)if(Wa(o[a],t)){n=!0;break}}return t.set(i,n),n}function Wi(e,t,i){qi(e);let r=ye({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),n=new Map;function o(s,c,l,u){if(!u||s.active===!1||s.visible===!1||!Wa(s,n))return null;let h=De(c,s),d=Jt(l,h,s),g=qt(d);if(!g)return null;let y=$e(g,t,i);if(y.x<h.left||y.x>h.right||y.y<h.bottom||y.y>h.top)return null;if(Ki(s)){let m=Mt(s._scroll,h.width,h.height)?.track,S=y.x-h.centerX,I=h.centerY-y.y;if(m&&S>=m.x&&S<=m.x+m.width&&I>=m.y&&I<=m.y+m.height)return s}if(Xa(s))for(let m=0;m<s.children.length;m+=1){let S=o(s.children[m],h,d,!0);if(S)return S}return mn(s)?s:null}let a=Ct();for(let s=e.runtime.roots.length-1;s>=0;s-=1){let c=o(e.runtime.roots[s],r,a,!0);if(c)return c}return null}function Nt(e,t,i,{dragging:r=!1,press:n=null,previous:o=null}={}){let a=n||{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:r})}function cn(e,t,i){t.kind==="grid"||t.kind==="textwindow"||(t.pressed=i,typeof t.markPlayDirty=="function"&&t.markPlayDirty(),hi(e,t))}function Ki(e){if(!e?.alive||!e.activeInHierarchy||e.interactable===!1||e.raycastTarget===!1)return!1;for(let t=e;t;t=t.parent)if(t.visible===!1)return!1;return e._scroll?.max>0}function Fa(e){for(let t=e;t;t=t.parent)if(Ki(t))return t;return null}function Oa(e,t,i,r){let n=Ji(e),o=n.get(t.Id),a=Ga(e,n).get(t.Id),s=a&&qt(a);if(!o||!s)return null;let c=$e(s,i,r);return{x:c.x-o.centerX,y:o.centerY-c.y,width:o.width,height:o.height}}function za(e,t,i){let r=e.pointerDownControl;if(r?.alive){let n=Nt(e,t,i,{dragging:e.pointerDragging,press:e.pointerDownPosition,previous:e.pointerLastPosition});e.runtime.injectCursor(r,"CursorUp",n),e.pointerDragging&&!e.pointerScroll&&e.runtime.injectCursor(r,"CursorEndDrag",n),cn(e,r,!1)}e.pointerDownControl=null,e.pointerScroll=null,e.pointerDownPosition=null,e.pointerDragging=!1,e.pointerLastPosition={x:t,y:i}}function pi(e,t,i,r,n={}){let o=Number(i),a=Number(r);if(!Number.isFinite(o)||!Number.isFinite(a))throw new Error("pointer coordinates must be finite");e.runtime.cursor.x=o,e.runtime.cursor.y=a;let s=Number(n.deltaX??0),c=Number(n.deltaY??0);if(t==="wheel"&&(!Number.isFinite(s)||!Number.isFinite(c)))throw new Error("wheel deltas must be finite");if(n.silent||Qe(e,{kind:"pointer",payload:{type:t,x:o,y:a,...t==="wheel"?{deltaX:s,deltaY:c}:{}}}),t==="wheel"){let l=Wi(e,o,a),u=Fa(l);if(u){let h=u._scroll.horizontal&&s||c;an(u,u._scroll.offset+h)}return l}if(t==="cancel")return za(e,o,a),null;if((t==="move"||t==="up")&&e.pointerScroll&&!Ki(e.pointerScroll.control)&&za(e,o,a),t==="move"){let l=e.pointerLastPosition||{x:o,y:a},u=e.pointerHoverControl,h=sn(Wi(e,o,a)),d=Nt(e,o,a,{previous:l});u&&u!==h&&e.runtime.injectCursor(u,"CursorExit",d),h&&u!==h&&e.runtime.injectCursor(h,"CursorEnter",d),e.pointerHoverControl=h;let g=e.hoveredControl;e.hoveredControl=h?.kind==="button"?h:null,g&&g!==e.hoveredControl&&hi(e,g),e.hoveredControl&&hi(e,e.hoveredControl);let y=e.pointerDownControl,m=e.pointerScroll;if(m)if(!Ki(m.control))e.pointerScroll=null;else{let S=Oa(e,m.control,o,a);if(S){let I=m.control._scroll,E=I.horizontal?S.x-m.start.x:S.y-m.start.y,M=Mt(I,S.width,S.height)?.travel||0,F=m.bar?M?E*I.max/M:0:-E;an(m.control,m.offset+F)}}if(y?.alive){let S=e.pointerDownPosition||l,I=o!==l.x||a!==l.y;!e.pointerDragging&&I&&(m||e.runtime.injectCursor(y,"CursorBeginDrag",Nt(e,o,a,{press:S,previous:l,dragging:!1})),e.pointerDragging=!0),e.pointerDragging&&!m&&e.runtime.injectCursor(y,"CursorDrag",Nt(e,o,a,{press:S,previous:l,dragging:!0}))}return e.pointerLastPosition={x:o,y:a},h}if(t==="down"){let l=sn(Wi(e,o,a));e.pointerDownControl=l,e.pointerDownPosition={x:o,y:a},e.pointerLastPosition={x:o,y:a},e.pointerDragging=!1,e.pointerScroll=null;let u=Fa(l);if(u){let h=Oa(e,u,o,a),d=h&&Mt(u._scroll,h.width,h.height),g=m=>h.x>=m.x&&h.x<=m.x+m.width&&h.y>=m.y&&h.y<=m.y+m.height,y=d&&g(d.track);if(y&&!g(d.thumb)){let m=u._scroll.horizontal?h.x-d.track.x-d.thumb.width/2:h.y-d.track.y-d.thumb.height/2;an(u,d.travel?m/d.travel*u._scroll.max:0),qi(e)}h&&(e.pointerScroll={control:u,start:h,offset:u._scroll.offset,bar:!!y})}return l&&(cn(e,l,!0),e.runtime.injectCursor(l,"CursorDown",Nt(e,o,a))),l}if(t==="up"){let l=e.pointerDownControl,u=sn(Wi(e,o,a));if(l?.alive){let h=Nt(e,o,a,{press:e.pointerDownPosition,previous:e.pointerLastPosition,dragging:e.pointerDragging});if(e.runtime.injectCursor(l,"CursorUp",h),e.pointerDragging)e.pointerScroll||e.runtime.injectCursor(l,"CursorEndDrag",h);else if(u===l&&!e.pointerScroll?.bar){e.runtime.injectCursor(l,"CursorClick",h);let d=e.selectedControl;e.selectedControl=l.kind==="button"?l:null,d&&d!==e.selectedControl&&hi(e,d)}cn(e,l,!1)}return e.pointerDownControl=null,e.pointerDownPosition=null,e.pointerLastPosition={x:o,y:a},e.pointerDragging=!1,e.pointerScroll=null,u}if(t==="click")return pi(e,"down",o,a,{silent:!0}),pi(e,"up",o,a,{silent:!0});throw new Error(`unknown pointer type ${t}`)}function gn(e,t,i,r){if(!e?.server)throw new Error("play session has no server");return Qe(e,{kind:"serverSet",payload:{entityType:t,name:i,value:r,playerIndex:e.viewPlayerIndex}}),e.server.setVar(t,i,r,{playerIndex:e.viewPlayerIndex})}function Ka(e,t,i){if(!e?.server)throw new Error("play session has no server");let r=e.server.getVar(t,i,{playerIndex:e.viewPlayerIndex});return r===void 0?null:r}function yn(e,t,i=[],r="PlayerSelf"){if(!e?.server)throw new Error("play session has no server");return Qe(e,{kind:"serverSend",payload:{name:t,params:i,target:r,playerIndex:e.viewPlayerIndex}}),e.server.sendToClient(t,i,{target:r,playerIndex:e.viewPlayerIndex})}function Zi(e){return{snapshot:t=>dn(e,t),step:t=>Qi(e,t),pointer:(t,i,r,n)=>pi(e,t,i,r,n),key:t=>hn(e,t),click:t=>pn(e,t),view:t=>un(e,t),pause:()=>{Qe(e,{kind:"pause",payload:{}}),e.debugPaused=!0},resume:()=>{Qe(e,{kind:"resume",payload:{}}),e.debugPaused=!1},serverSet:(t,i,r)=>gn(e,t,i,r),serverSend:(t,i,r)=>yn(e,t,i,r)}}function bn(e){e?.server&&e.server.destroy();let t=e?.runtimes||(e?.runtime?[e.runtime]:[]);for(let i of t)i.destroy()}function vn(e,t){return JSON.stringify(e)===JSON.stringify(t)}function qa(e,t){for(let i of e||[])t(i),i.children?.length&&qa(i.children,t)}function wn(e,{id:t,name:i}){let r=null;return qa(e,n=>{r||(t&&String(n.id)===String(t)||!t&&i&&n.name===i)&&(r=n)}),r}function Qc(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 Zc(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=wn(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(r=>({name:r.name,values:r.values}))}}}function eu(e,t){if(e.kind==="log"){let i=e.source==="server"?t.server?.logs||t.serverLogs||[]:t.logs||[];return i.some(n=>e.level&&n.level!==e.level?!1:String(n.text||"").includes(e.contains))?{ok:!0,actual:e.contains}:{ok:!1,actual:i.map(n=>n.text).slice(-8),expected:e.contains}}if(e.kind==="control"){let i=wn(t.tree,e);if(!i)return{ok:!1,actual:null,expected:e.equals,message:`control not found: ${e.id||e.name}`};let r=Qc(i,e.field);return vn(r,e.equals)?{ok:!0,actual:r}:{ok:!1,actual:r,expected:e.equals}}if(e.kind==="var"){let i=t.server?.vars?.[e.entityType],n=!i||!Object.prototype.hasOwnProperty.call(i,e.name)?null:i[e.name].value;return vn(n,e.equals)?{ok:!0,actual:n}:{ok:!1,actual:n,expected:e.equals}}if(e.kind==="signal"){let i=e.direction==="outbound"?t.server?.outbound||[]:t.server?.inbound||[],r=i.find(n=>n.name===e.name&&(e.values===void 0||vn(n.values,e.values)));return r?{ok:!0,actual:r.values}:{ok:!1,actual:i.map(n=>({name:n.name,values:n.values})),expected:{name:e.name,values:e.values??null}}}if(e.kind==="tree"){let i=!!wn(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 tu(e,t){let i=si();try{return i.evalQueryScript(e,Zc(t)),{ok:!0,actual:!0}}catch(r){return{ok:!1,message:r?.message||String(r)}}finally{i.destroy()}}function Ja(e,t){return e.kind==="lua"?tu(e.source,t):eu(e,t)}function iu(e,t){let i=t>0?t:dt;return Math.round((e+i)*1e9)/1e9}function ru(e,t){let i=t.payload||{};if(t.kind==="pointer")e.pointer(i.type,i.x,i.y,i);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 nu(e,t){let i=Ja(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 Qa(e,t){let i=di(t),r=i.events.slice().sort((I,E)=>I.t-E.t),n=i.asserts.slice(),o=i.dt||dt,a=r.reduce((I,E)=>Math.max(I,E.t),0),s=n.reduce((I,E)=>Math.max(I,Number(E.at||0)),0),c=Math.max(a,s),l=0,u=[],h=0,d=n.some(I=>I.kind==="control"||I.kind==="tree"||I.kind==="lua"),g=e.snapshot({inspect:d}),y=()=>{for(;l<r.length&&r[l].t<=h+1e-9;)ru(e,r[l]),l+=1,g=e.snapshot({inspect:d})},m=()=>{for(let I of n)if(!I._done&&Number(I.at||0)<=h+1e-9){let E=nu(I,g);if(u.push(E),I._done=!0,!E.ok)return{passed:!1,failedAt:h,frame:g.frame||0,results:u,snapshot:g}}return null};y();let S=m();if(S)return Sn(i,S);for(;h+1e-9<c;){e.step(o),h=iu(h,o),g=e.snapshot({inspect:d}),y();let I=m();if(I)return Sn(i,I)}return Sn(i,{passed:u.every(I=>I.ok),failedAt:null,frame:g.frame||0,results:u,snapshot:g})}function Sn(e,t){return $({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 In(e){return Array.isArray(e)?e.slice():[]}var uu={Level:"\u5173\u5361",PlayerSelf:"\u5F53\u524D\u73A9\u5BB6",AvatarSelf:"\u5F53\u524D\u89D2\u8272",...Object.fromEntries(ut.map((e,t)=>[e,`\u73A9\u5BB6${t+1}`])),...Object.fromEntries(Array.from({length:8},(e,t)=>[`Avatar${t+1}`,`\u89D2\u8272${t+1}`]))};function fu(e,t=1){let i=e?.vars||{},r=[],n=Number(t)>0?Number(t):1,o=["Level","PlayerSelf","AvatarSelf"];if(n>1)for(let s=1;s<=n;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 c=i[s]||{};for(let l of Object.keys(c))r.push($({entityType:s,entityLabel:uu[s]||s,name:l,type:c[l]?.type||"",value:c[l]?.value??null}))}return r}var mt="qxqy-simulator-save",du="qxqy-simulator-scripts",oe="server-control-template",Y="client-control-template",Cn={[oe]:"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F",[Y]:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"};function pt(e){return e===Y?"client":"server"}function er(e){if(!(typeof e=="number"||typeof e=="string"&&/^\d+$/.test(e.trim()))||!ke(e))throw new Error("\u63A7\u4EF6\u7D22\u5F15\u5FC5\u987B\u662F 1\u20132147483647 \u8303\u56F4\u5185\u7684\u6574\u6570");return Number(e)}function xn(e=[]){if(!Array.isArray(e))throw new Error("controlGuidChanges \u5FC5\u987B\u662F\u6570\u7EC4");let t=new Set;return e.map(i=>{if(!i||typeof i.id!="string"||!i.id||t.has(i.id)||![oe,Y].includes(i.controlAsset)||typeof i.controlId!="string"||!i.controlId||typeof i.controlName!="string")throw new Error("controlGuidChanges \u5305\u542B\u65E0\u6548\u6216\u91CD\u590D\u7684\u53D8\u66F4\u8BB0\u5F55");return t.add(i.id),{id:i.id,controlAsset:i.controlAsset,controlId:i.controlId,controlName:i.controlName,oldGuid:er(i.oldGuid),newGuid:er(i.newGuid)}})}function hu(e){let t=[e?.guid,e?.id];for(let i of t){let r=Number(i);if(Number.isSafeInteger(r)&&r>0&&r<=2147483647)return r}return 0}function tr(e){let t=String(e?.controlAsset||""),i=hu(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 pu(e){let t=[],i=(r,n="")=>{if(r&&(r.path||r.source)){let o=tr(r);t.push(n?{...o,controlAsset:n}:o)}};if(Array.isArray(e?.assets?.scripts)){for(let r of e.assets.scripts)r&&(r.path||r.source)&&t.push(tr(r));return t}if(i(e?.assets?.server?.script,oe),i(e?.assets?.client?.script,Y),e&&e.format!==mt){i(e?.script);for(let r of e?.scripts||[])i(r)}return t}function kn(e){return qe(e===Y?kt():ot())}var mu="\u672A\u7ED1\u5B9A",Ft="\u672A\u547D\u540D\u5B58\u6863",gu="\u672A\u547D\u540D\u754C\u9762";function yu(e){let t=e;for(let i=0;i<8;i++){if(mi(Za(t,"simulator","studio"))&&mi(Za(t,"lua")))return t;let r=lu(t);if(r===t)break;t=r}return e}function bu(e){return e?{name:Ot(e),path:e,bound:!0}:{name:mu,path:"",bound:!1}}function vu(e,t=process.cwd()){if(cu(e)&&mi(e))return e;let i=t||process.cwd(),r=yu(i),n=es(r,e);if(mi(n))return n;let o=es(i,e);if(mi(o))return o;throw new Error("script file not found: "+e)}function En(e,t={}){e?.format===mt&&$r(e.version);let i=[],r=typeof t.workspacePath=="string"&&t.workspacePath?t.workspacePath:"",n=e?.format===mt&&e.assets,o=xn(e?.controlGuidChanges),a=Wt(e?.scriptSync),s=n?null:qe(e,{warnings:i}),c={server:n&&e.assets.server?qe(e.assets.server,{warnings:i}):kn(oe),client:n&&e.assets.client?qe(e.assets.client,{warnings:i}):kn(Y)};s&&(c[pt(s.meta.assetType)]=s);let l=n&&e.activeAssetType===Y?Y:s?.meta.assetType||oe,u=n&&e.meta?.name?String(e.meta.name):"",h=()=>u||Ft;!e?.meta?.name&&c.server.meta.name==="\u672A\u547D\u540D\u754C\u9762\u63A7\u4EF6\u7EC4"&&(c.server.meta.name=gu);let d=[],g=new Set;function y(){g.clear(),xt(c.server.root,g),xt(c.client.root,g,{skipServerContainer:!0});for(let p of d)ke(p.guid)&&g.add(Number(p.guid))}function m(p=0){y();let b=ke(p)&&!g.has(Number(p))?Number(p):Ue(g);return g.add(b),b}function S(p){let b=tr(p),x=m(b.guid);return{...b,guid:x,id:String(x)}}Be(pu(e));let I=fi(e?.serverLogic),E=null,M="",F=1,H=1;function te(p){let b=String(p||"").trim();if(!b)return"";if(!X[b])throw new Error(`unknown canvas preset: ${b} (available: ${Object.keys(X).join(", ")})`);return b}let Z=()=>c[pt(l)];function D(p){if(!p)return null;for(let[b,x]of[["server",c.server],["client",c.client]]){let P=ue(x.root,p);if(P&&P.kind!=="server-container")return{key:b,node:P}}return null}function v(p){if(!p.controlId)return null;let b=p.controlAsset===Y?"client":p.controlAsset===oe?"server":null;if(b){let x=ue(c[b].root,p.controlId);return x&&x.kind!=="server-container"?{key:b,node:x}:null}return D(p.controlId)}function A(){for(let p of d)p.controlId&&!v(p)&&(p.controlId="",p.controlAsset="")}function w(p){if(!ke(p))return null;for(let[b,x]of[[oe,c.server],[Y,c.client]]){let P="";if(J(x.root,T=>{!P&&(T.scriptMappingIds||[]).includes(Number(p))&&(P=T.id)}),P)return{controlId:P,controlAsset:b}}return null}function k(p,b,x){let P=c[pt(p.controlAsset)],T=P&&ue(P.root,p.controlId);T&&(T.scriptMappingIds=(T.scriptMappingIds||[]).map(O=>Number(O)===Number(b)?Number(x):O))}A();function z(){return d.map(p=>{let b=v(p),x=b?b.key==="client"?Y:oe:"";return $({id:p.id,guid:p.guid||0,path:p.path||"",source:p.source||"",controlId:p.controlId||"",controlAsset:p.controlAsset||x,controlName:b?.node.name||"",assetType:x,assetLabel:b?Cn[x]:"",mounted:!!b})})}function C(){let p=[],b=(x,P)=>{J(x.root,T=>{T.kind!=="server-container"&&p.push($({id:T.id,name:T.name,kind:T.kind,assetType:P,assetLabel:Cn[P]}))})};return b(c.server,oe),b(c.client,Y),p}function N(p){let b=[];return J(p.root,x=>{x.kind!=="server-container"&&b.push(JSON.stringify({kind:x.kind,guid:x.guid,name:x.name,text:x.text??null,imageId:x.imageId??null,fontSize:x.fontSize??null,fontColor:x.fontColor??null,bgColor:x.bgColor??null,imageColor:x.imageColor??null,fillType:x.fillType??null,fillAmount:x.fillAmount??null,syncAllDevices:x.syncAllDevices!==!1,transformByPlatform:x.transformByPlatform||null}))}),b.join("/")}let G=N(kt()),B=N(ot());function se(p){let b=N(p);return p.meta?.assetType===Y?b===G:b===B}function L(p,b){return String(p||"").replace(/[\\/:*?"<>|]/g,"-").trim()||b}function he(p){let b=L(h(),Ft),x=p.meta?.assetType===Y?"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F";return`${b} \xB7 ${x}`}function Ze(){if(!((c.server.root.children||[]).find(b=>b.kind==="container")||c.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 No(c.server,c.client,{scripts:d,fileName:`${L(h(),Ft)} \xB7 \u6574\u5408\u5305.gia`})}function bt(){let p=b=>({type:b.meta.assetType,name:b.meta.name,sourceFile:b.meta.sourceFile||""});return{format:mt,name:h(),activeAssetType:l,assets:{server:p(c.server),client:p(c.client),scripts:z()}}}function Vt(){return $({format:mt,version:4,meta:{name:h()},activeAssetType:l,serverLogic:I,controlGuidChanges:o,scriptSync:a,assets:{server:c.server,client:c.client,scripts:d.map(p=>$({id:p.id,guid:p.guid||0,path:p.path||"",source:p.source||"",controlId:p.controlId||"",controlAsset:p.controlAsset||""}))}})}function ie(){let p=Z(),b=qo(p);return b.workspace=bu(r),b.save=bt(),b.scripts=z(),b.mountTargets=C(),b.serverLogic=I,b.migrationWarnings=[...i],b.controlGuidChanges=$(o),b.scriptSync=$(a),to(b),b}function Pe(p){let b=Z();if(p.expectedRevision!==void 0&&Number(p.expectedRevision)!==b.version)throw new Error(`revision conflict: expected ${p.expectedRevision}, current ${b.version}`);return b}function et(p,b,x=""){let P=String(b||"");if(P){let T=x===Y?Y:x===oe?oe:"";if(!v({controlId:P,controlAsset:T}))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");p.controlAsset=T}else p.controlAsset="";p.controlId=P}function wi(p){let b=Pe(p);if(p.op==="addScript"){let x=S({path:String(p.path||""),source:String(p.source||""),controlId:"",controlAsset:""});p.controlId!==void 0&&p.controlId!==""&&et(x,p.controlId,p.controlAsset),d.push(x)}else if(p.op==="updateScript"){let x=d.find(P=>P.id===p.id);if(!x)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${p.id}`);p.controlId!==void 0&&et(x,p.controlId,p.controlAsset),p.path!==void 0&&(x.path=String(p.path)),p.source!==void 0&&(x.source=String(p.source))}else if(p.op==="removeScript"){let x=d.length;if(d=d.filter(P=>P.id!==p.id),d.length===x)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${p.id}`)}return b.version+=1,ie()}function Si(p){let b=Pe(p),x=ue(b.root,p.id??b.selectedId);if(!x||x.kind==="server-container")throw new Error("\u4EC5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6216\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5141\u8BB8\u4FEE\u6539\u7D22\u5F15");let P=er(p.guid),T=er(x.guid);if(P===T)return ie();let O=[];for(let j of Object.values(c))J(j.root,ne=>{j===c.client&&ne.kind==="server-container"||O.push({node:ne,project:j})});if(O.some(j=>j.node!==x&&Number(j.node.guid)===P)||d.some(j=>Number(j.guid)===P))throw new Error(`\u63A7\u4EF6\u7D22\u5F15 ${P} \u5DF2\u88AB\u5176\u4ED6\u63A7\u4EF6\u6216\u811A\u672C\u5360\u7528`);let V=[],K=(j,ne,Me)=>{let ee=j?.[ne];(typeof ee=="number"||typeof ee=="string"&&/^\d+$/.test(ee.trim()))&&Number(ee)===T&&V.push({owner:j,key:ne,project:Me.project})};for(let j of O)K(j.node,"referencedPrefabId",j),K(j.node,"itemPrefabId",j),K(j.node.giaRaw,"templateRefSlot",j);if(V.length&&O.filter(j=>Number(j.node.guid)===T).length!==1)throw new Error(`\u65E7\u7D22\u5F15 ${T} \u5728\u591A\u68F5\u8D44\u4EA7\u6811\u4E2D\u91CD\u590D\uFF0C\u65E0\u6CD5\u786E\u5B9A\u6A21\u677F\u5F15\u7528\u5F52\u5C5E\uFF1B\u8BF7\u5148\u6D88\u9664\u6B67\u4E49\u540E\u4FEE\u6539`);let Te={id:su(),controlAsset:l,controlId:x.id,controlName:x.name,oldGuid:T,newGuid:P};x.guid=P;let pe=new Set([b]);for(let{owner:j,key:ne,project:Me}of V)j[ne]=typeof j[ne]=="string"?String(P):P,pe.add(Me);o.push(Te);for(let j of pe)j.version+=1;return ie()}function re(p){let b=Pe(p);if(!Array.isArray(p.changeIds)||!p.changeIds.length||p.changeIds.some(P=>typeof P!="string"||!o.some(T=>T.id===P)))throw new Error("\u8BF7\u660E\u786E\u6307\u5B9A\u5DF2\u6838\u5BF9 Lua \u5F15\u7528\u7684\u6709\u6548\u7D22\u5F15\u53D8\u66F4\u8BB0\u5F55 changeIds");let x=new Set(p.changeIds);return o=o.filter(P=>!x.has(P.id)),b.version+=1,ie()}function Re(p){if(!p||typeof p!="object")throw new Error("patch requires op");if(p.op==="setScriptSync"){let b=Pe(p);return a=Wt(p.config),b.version+=1,ie()}if(p.op==="setControlGuid")return Si(p);if(p.op==="acknowledgeControlGuidChanges")return re(p);if(p.op==="setServerLogic"){let b=Pe(p);return I=fi(p.logic),b.version+=1,ie()}if(p.op==="addScript"||p.op==="updateScript"||p.op==="removeScript")return wi(p);if(p.op==="selectAsset")return l=p.assetType===Y?Y:oe,ie();if(p.op==="renameSave"){let b=String(p.name||"").trim();if(!b)throw new Error("\u5B58\u6863\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");return u=b,ie()}if(p.op==="newAsset"){let b=Pe(p);l=p.assetType===Y?Y:oe;let x=kn(l);return x.version=b.version+1,c[pt(l)]=x,o=o.filter(P=>P.controlAsset!==l),A(),ie()}return jr(Z(),p),A(),ie()}function ze(p){return d.filter(b=>{let x=v(b);return!!(x&&x.key==="client"==(p===Y))})}function jt(p="json",b=""){let x=Yt(p,b);if(o.length&&!["save","archive"].includes(String(p).toLowerCase())){let P=o.map(T=>`\u63A7\u4EF6\u7D22\u5F15\u5F85\u6838\u5BF9 Lua \u5F15\u7528\uFF1A${Cn[T.controlAsset]} / ${T.controlName} (${T.controlId})\uFF1A${T.oldGuid} \u2192 ${T.newGuid}\u3002\u8BF7\u6309\u8BED\u4E49\u66F4\u65B0\u811A\u672C\u4E2D\u7684\u63A7\u4EF6\u7D22\u5F15\u5F15\u7528\uFF0C\u6838\u5BF9\u540E\u786E\u8BA4\u53D8\u66F4\u8BB0\u5F55 ${T.id}\uFF1B\u4E0D\u8981\u5168\u5C40\u66FF\u6362\u540C\u503C\u6570\u5B57\u3002`);x.warnings=[...new Set([...x.warnings||[],...P])]}return x}function Yt(p="json",b=""){let x=String(p).toLowerCase();if(x==="save"||x==="archive"){let O=Buffer.from(JSON.stringify(Vt(),null,2),"utf8");return $({filename:`${h().replace(/[\\/:*?"<>|]/g,"-")} \xB7 \u8D44\u4EA7\u5305.json`,mimeType:"application/json",encoding:"base64",data:O.toString("base64"),warnings:[]})}if(x==="save-gia"||x==="archive-gia"){let O=[],V=[],K=(pe,j="")=>{let ne=jt(pe,j);O.push($({filename:ne.filename,mimeType:ne.mimeType,encoding:ne.encoding,data:ne.data,warnings:ne.warnings||[]})),V.push(...ne.warnings||[])},Te=(pe,j)=>{let ne=c[pt(pe)],Me=pe===l,ee=d.some(ve=>ve.controlAsset===pe&&ve.controlId);if(!Me&&se(ne)&&!ee){V.push(j);return}K("gia",pe)};if(Te(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"),Te(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"),d.some(pe=>pe.path||pe.source)&&K("scripts-gia"),!O.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 $({format:"qxqy-gia-package",files:O,warnings:[...new Set(V)]})}if(x==="gia-combined"||x==="combined-gia"||x==="combined"){let O=Ze();return $({filename:`${L(h(),Ft)} \xB7 \u6574\u5408\u5305.gia`,mimeType:"application/octet-stream",encoding:"base64",data:O.buffer.toString("base64"),warnings:[...new Set(O.warnings||[])]})}if(x==="scripts"){let O=$({format:du,version:1,scripts:d.map(K=>$({id:K.id,guid:K.guid||0,path:K.path||"",source:K.source||"",controlId:K.controlId||"",controlAsset:K.controlAsset||""}))}),V=Buffer.from(JSON.stringify(O,null,2),"utf8");return $({filename:`${L(h(),Ft)} \xB7 \u811A\u672C.json`,mimeType:"application/json",encoding:"base64",data:V.toString("base64"),warnings:[]})}if(x==="scripts-gia"||x==="scriptsgia"){let O=Do(d);return $({filename:`${L(h(),Ft)} \xB7 \u811A\u672C.gia`,mimeType:"application/octet-stream",encoding:"base64",data:O.buffer.toString("base64"),warnings:O.warnings})}if(x==="lua"){let O=d.find(K=>K.id===b)||d.find(K=>K.path===b);if(!O)throw new Error("\u6CA1\u6709\u53EF\u5BFC\u51FA\u7684 Lua \u811A\u672C\uFF0C\u8BF7\u5148\u5728\u201CLua \u811A\u672C\u201D\u9875\u521B\u5EFA");let V=Ot(O.path||"")||`qxqy-script-${O.id}`;return $({filename:/\.lua$/i.test(V)?V:`${V}.lua`,mimeType:"text/x-lua",encoding:"base64",data:Buffer.from(O.source||"","utf8").toString("base64"),warnings:[]})}let P=b?c[pt(b)]:Z(),T=he(P);if(x==="json"){let O=$({...P,scripts:ze(P.meta.assetType),controlGuidChanges:o.filter(K=>K.controlAsset===P.meta.assetType)}),V=Buffer.from(JSON.stringify(O,null,2),"utf8");return $({filename:`${T}.json`,mimeType:"application/json",encoding:"base64",data:V.toString("base64"),warnings:[]})}if(x==="gia"){let O=Mo(P,P.meta.assetType===Y?{scripts:ze(Y)}:{}),V=P.meta.assetType===Y?[]:ze(oe);return V.length&&O.warnings.unshift(`\u5F53\u524D\u670D\u52A1\u5668\u63A7\u4EF6 GIA \u4E0D\u5305\u542B ${V.length} \u4E2A Lua \u811A\u672C\u7684\u6E90\u7801\uFF1B\u8BF7\u4F7F\u7528\u300C\u8D44\u4EA7\u5305 GIA \u6574\u5408\u5305\u300D\uFF0C\u6216\u53E6\u884C\u5BFC\u5165\u811A\u672C\u5305\u5E76\u6838\u5BF9\u6302\u8F7D\u3002`),$({filename:`${T}.gia`,mimeType:"application/octet-stream",encoding:"base64",data:O.buffer.toString("base64"),warnings:O.warnings})}throw new Error(`unsupported export format: ${p}`)}function Be(p){for(let b of p){let x=tr(b);if(!x.path&&!x.source)continue;let P=x.controlId?null:w(x.guid),T=S(P?{...x,...P}:x);P&&T.guid!==x.guid&&k(P,x.guid,T.guid),T.controlId&&!v(T)&&(T.controlId="",T.controlAsset=""),d.push(T)}}function Bt(p,b,x=""){let P=String(p||"").toLowerCase();if(typeof b!="string"||!b)throw new Error("import data is required");let T=Buffer.from(b,"base64"),O,V=[],K={};if(P==="json"){try{O=JSON.parse(T.toString("utf8"))}catch{throw new Error("JSON \u6587\u4EF6\u65E0\u6548")}if(O?.project&&(O=O.project),O?.format===mt&&O?.assets){$r(O.version);let ee=En(O);V.push(...ee.get().migrationWarnings);let ve=ee.archiveData();return c.server=ve.assets.server,c.client=ve.assets.client,i=[...V],l=O.activeAssetType===Y?Y:oe,u=String(O.meta?.name||Ot(x).replace(/\.json$/i,"")||u),I=ve.serverLogic,d=ve.assets.scripts,o=ve.controlGuidChanges,a=ve.scriptSync,g.clear(),$({snapshot:ie(),warnings:V,metadata:{format:mt}})}}else{if(P==="lua")return d.push(S({path:Ot(x||"imported.lua"),source:T.toString("utf8"),controlId:""})),$({snapshot:ie(),warnings:V,metadata:{assetType:"lua-script"}});if(P==="gia"){if($o(T)){let Se=Vo(T);return Be(Se.scripts),$({snapshot:ie(),warnings:Se.warnings,metadata:Se.metadata})}let ee=jo(T);O=ee.project,V=ee.warnings,K=ee.metadata,ee.clientProject&&(c.client=qe(ee.clientProject),o=o.filter(Se=>Se.controlAsset!==Y),V.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 ve=new Map,Ln=(Se,ol)=>{Se&&J(Se.root,Xn=>{for(let br of Xn.scriptMappingIds||[]){let Wn=ve.get(Number(br));if(Wn){V.push(`\u811A\u672C GUID ${br} \u540C\u65F6\u6302\u8F7D\u5230\u591A\u4E2A\u63A7\u4EF6\uFF0C\u5DF2\u4FDD\u7559\u201C${Wn.controlAsset===oe?"\u670D\u52A1\u7AEF":"\u5BA2\u6237\u7AEF"}\u201D\u76EE\u6807\u3002`);continue}ve.set(Number(br),{controlId:Xn.id,controlAsset:ol})}})};Ln(ee.project,oe),Ln(ee.clientProject,Y),Be((ee.scripts||[]).map(Se=>ve.has(Number(Se.guid))?{...Se,...ve.get(Number(Se.guid))}:Se))}else throw new Error(`unsupported import format: ${p}`)}let Te=qe(O,{warnings:V}),pe=xn(O?.controlGuidChanges);if(pe.some(ee=>ee.controlAsset!==Te.meta.assetType))throw new Error("\u5355\u8D44\u4EA7 JSON \u7684\u7D22\u5F15\u53D8\u66F4\u8BB0\u5F55\u5FC5\u987B\u5C5E\u4E8E\u5F53\u524D\u5BFC\u5165\u8D44\u4EA7");let j=xn([...o.filter(ee=>ee.controlAsset!==Te.meta.assetType),...pe]);i=[...V];let ne=pt(Te.meta.assetType);c[ne]=Te,o=j,l=Te.meta.assetType;let Me=c[ne];return x&&(Me.meta.name=Ot(x).replace(/\.(json|gia)$/i,"")||Me.meta.name,Me.meta.sourceFile=Ot(x),Me.meta.sourceFormat=P),Be(O?.scripts||[]),O?.script&&(O.script.path||O.script.source)&&Be([O.script]),$({snapshot:ie(),warnings:V,metadata:K})}function Gs(p,b){return jr(Z(),{op:"pick",x:p,y:b}),ie()}function Vs(p){let b=typeof p=="string"&&p?p:"";!b||b===r||(r=b)}function js(p){let b=p.source||"";if(!b.trim()&&p.path.trim())try{b=au(vu(p.path,r),"utf8")}catch(x){throw new Error(`\u811A\u672C ${p.path} \u8BFB\u53D6\u5931\u8D25: ${x?.message||x}`)}return b}function Ht(p={}){let b=te(p.canvasId);b&&(M=b),p.playerCount!==void 0&&p.playerCount!==null&&p.playerCount!==""&&(F=ct(p.playerCount),H>F&&(H=1)),p.viewPlayerIndex!==void 0&&p.viewPlayerIndex!==null&&p.viewPlayerIndex!==""&&(H=je(p.viewPlayerIndex,F)),E&&bn(E);let x=d.map(T=>{try{return{id:T.id,guid:T.guid||0,path:T.path||T.id,source:js(T),controlId:T.controlId||"",controlAsset:T.controlAsset||""}}catch(O){return{id:T.id,guid:T.guid||0,path:T.path||T.id,source:`error([==[ ${String(O.message).replace(/]=+]/g,"] =]")} ])`,controlId:T.controlId||"",controlAsset:T.controlAsset||""}}}),P=T=>x.filter(O=>{let V={controlId:O.controlId,controlAsset:O.controlAsset},K=O.controlId?v(V):null;return!!(K&&K.key===T)});return E=ja(c.server,{templatesProject:c.client,scripts:x,sceneScripts:P("server"),templateScripts:P("client"),serverConfig:{logic:I},canvasId:M,playerCount:F,viewPlayerIndex:H,language:p.language||""}),ce(p)}function Ys(p,b={}){let x=te(p);if(!x)throw new Error("playSetCanvas requires canvasId");return Ht({...b,canvasId:x})}function ce(p={}){if(!E)return $({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]});let b=dn(E,p);return b.running=!0,b.logs=In(b.logs),b.serverLogs=In(b.server?.logs||[]),b.serverVars=fu(b.server,b.playerCount||1),b}function Bs(p,b={}){return E||Ht(),Qi(E,p),b.observe===!1?$({running:!0,time:E.runtime.clock.time,frame:E.runtime.clock.frame,paused:!!E.debugPaused,levelTimePaused:!!E.runtime.clock.paused,playerCount:E.playerCount||1,viewPlayerIndex:E.viewPlayerIndex||1}):ce(b)}function Hs(p=0){Ht();let b=Math.max(0,Number(p)||0);for(let x=0;x<b;x++)Qi(E,1/30);return ce()}function Us(){return E&&bn(E),E=null,M="",F=1,H=1,$({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]})}function Ls(p,b={}){let x=Ut();return H=un(x,p),b.observe===!1?null:ce(b)}function Xs(p,b={}){if(!E)throw new Error("play session has not started");return hn(E,p),b.observe===!1?null:ce(b)}function Ws(p,b={}){if(!E)throw new Error("play session has not started");return pn(E,p),b.observe===!1?null:ce(b)}function Ks(p,b,x,P={}){if(!E)throw new Error("play session has not started");return pi(E,p,b,x,P),P.observe===!1?null:ce(P)}function qs(p={}){return E&&Zi(E).pause(),p.observe===!1?null:ce(p)}function Js(p={}){return E&&Zi(E).resume(),p.observe===!1?null:ce(p)}function Ut(){if(!E)throw new Error("play session has not started");return E}function Qs(p,b){let x=Ut();if(!p&&!b){let P=ce();return $({vars:P.serverVars||[]})}return $({entityType:String(p||""),name:String(b||""),value:Ka(x,p,b)})}function Zs(p,b,x){let P=Ut();return gn(P,p,b,x),ce()}function el(p,b=[],x="PlayerSelf"){let P=Ut();return yn(P,p,b,x),ce()}function tl(){let p=ce();return $({events:p.history||[],case:Pa(p.history||[],{playerCount:p.playerCount||1})})}function il(p={}){let b=ce(),x=di({name:p.name||"",dt:p.dt,playerCount:p.playerCount||b.playerCount||1,events:p.events||b.history||[],asserts:p.asserts||[]});return $(x)}function rl(p,b={}){let x=di(p);Ht({...b,playerCount:b.playerCount||x.playerCount||1});let P=Ut();P.recording=!1;try{return Qa(Zi(P),p)}finally{P.recording=!0}}function nl(){if(!E)return{running:!1,paused:!1,time:0,frame:0,playerCount:1,viewPlayerIndex:1};let p=E.runtime.clock;return{running:!0,paused:!!E.debugPaused,levelTimePaused:!!p.paused,time:p.time,frame:p.frame,playerCount:E.playerCount||1,viewPlayerIndex:E.viewPlayerIndex||1}}let Un={get:ie,patch:Re,setWorkspace:Vs,exportData:jt,importData:Bt,pick:Gs,playStart:Ht,playSetCanvas:Ys,playSetView:Ls,playGet:ce,playStatus:nl,playStep:Bs,playRun:Hs,playStop:Us,playKey:Xs,playClick:Ws,playPointer:Ks,playPause:qs,playResume:Js,playServerGet:Qs,playServerSet:Zs,playServerSend:el,playHistory:tl,playSaveCase:il,playRunCase:rl,archiveData:Vt};return Object.defineProperty(Un,"_project",{enumerable:!1,get:Z}),Un}import{createRequire as wu}from"node:module";function An(e,t,i){if(e.fillType!=="Horizontal"&&e.fillType!=="Vertical")return null;let r=Number(e.fillAmount??1),n=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1;if(e.fillType==="Horizontal"){let a=t*n;return{x:e.fillHorizontalType==="Right"?t/2-a:-t/2,y:-i/2,width:a,height:i}}let o=i*n;return{x:-t/2,y:e.fillVerticalType==="Top"?-i/2:i/2-o,width:t,height:o}}function ts(e,t,i){let r=t?.m_Rect,n=t?.m_RD?.textureRectOffset,o=t?.m_RD?.textureRect,a=Math.round(Number(r?.width)),s=Math.round(Number(r?.height)),c=Math.round(Number(n?.X)),l=Math.round(Number(n?.Y)),u=Math.round(Number(o?.width)),h=Math.round(Number(o?.height)),d=t?.m_RD?.settingsRaw?.packingRotation;if(![a,s,u,h].every(m=>Number.isInteger(m)&&m>0&&m<=8192)||a*s>16777216||!Number.isFinite(c)||!Number.isFinite(l)||c<0||l<0||c+u>a||l+h>s)throw new Error("Invalid sprite dimensions or trim offset");if(d&&d!=="None")throw new Error(`Unsupported sprite packing rotation: ${d}`);let g=i(a,s),y=g.getContext("2d");if(e.width===a&&e.height===s)y.drawImage(e,0,0);else{if(e.width!==u||e.height!==h)throw new Error("Sprite PNG does not match its trim metadata");y.drawImage(e,c,s-l-h)}return g}function is(e,t,i){let r=Number(t??4294967295)>>>0;if((r&16777215)===16777215)return e;let n=i(e.width,e.height),o=n.getContext("2d");o.drawImage(e,0,0);let a=o.getImageData(0,0,n.width,n.height),s=r>>>16&255,c=r>>>8&255,l=r&255;for(let u=0;u<a.data.length;u+=4)a.data[u]=Math.round(a.data[u]*s/255),a.data[u+1]=Math.round(a.data[u+1]*c/255),a.data[u+2]=Math.round(a.data[u+2]*l/255);return o.putImageData(a,0,0),n}var Su=wu(import.meta.url),Iu=[0,-.5,.5,.5,-.5,.5],Cu=[0,-.5,.12,-.12,.5,0,.12,.12,0,.5,-.12,.12,-.5,0,-.12,-.12],xu=[0,-.5,.11,-.15,.48,-.15,.18,.07,.29,.41,0,.2,-.29,.41,-.18,.07,-.48,-.15,-.11,-.15],_n=Buffer.from([137,80,78,71,13,10,26,10]),ku=new Set(["image","textbox","textwindow","button","grid"]),ir={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"},rr=null;function Pn(){if(rr)return rr;try{rr=Su("@napi-rs/canvas")}catch(e){let t=e?.message||String(e);throw new Error(`Host screenshot renderer requires @napi-rs/canvas (${t})`)}return rr}function U(e,t=0){let i=Number(e);return Number.isFinite(i)?i:t}function or(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 gt(e,t=1){return`rgba(${e.r},${e.g},${e.b},${Math.max(0,Math.min(1,e.a*t))})`}function ns(e,t,i=1){let r=Math.max(1,Math.round(U(e,1))),n=Math.max(1,Math.round(U(t,1))),o=Math.max(1,Math.min(2,U(i,1)));return{width:r,height:n,pixelWidth:Math.max(1,Math.round(r*o)),pixelHeight:Math.max(1,Math.round(n*o)),pixelRatio:o}}function os(e){let t=Buffer.from(e.toBuffer("image/png"));if(t.length<_n.length||!t.subarray(0,_n.length).equals(_n))throw new Error("Host screenshot renderer did not produce a PNG");return t}function Eu(e){return e==="triangle"?Iu:e==="fourstar"?Cu:xu}function Au(e,t,i,r,n){let o=Eu(t);e.beginPath();for(let a=0;a<o.length;a+=2){let s=o[a]*i,c=o[a+1]*r;a===0?e.moveTo(s,c):e.lineTo(s,c)}e.closePath(),e.fillStyle=gt(n),e.fill()}function _u(e,t,i){let r=t?.matrix,n=r&&typeof r=="object"?[r.a,r.b,r.c,r.d,r.tx,r.ty].map(Number):null,o=t?.pressed?.98:1;if(n&&n.every(Number.isFinite)){let[a,s,c,l,u,h]=n;e.transform(a*o,-s*o,-c*o,l*o,u,i-h);return}e.translate(U(t.left)+U(t.width)/2,i-U(t.bottom)-U(t.height)/2),e.rotate(-U(t.rotationZ)*Math.PI/180),e.scale(o,o)}function Pu(e,t,i,r,n,o){if(typeof e.roundRect=="function"){e.roundRect(t,i,r,n,o);return}let a=Math.max(0,Math.min(o,r/2,n/2));e.moveTo(t+a,i),e.arcTo(t+r,i,t+r,i+n,a),e.arcTo(t+r,i+n,t,i+n,a),e.arcTo(t,i+n,t,i,a),e.arcTo(t,i,t+r,i,a),e.closePath()}function as(e,t,i,r){let n=or(t.bgColor,16777215);e.fillStyle=gt(n),e.fillRect(-i/2,-r/2,i,r);let o=Math.max(8,U(t.fontSize,12)),a=or(t.fontColor,4294967295),s=t.horizontalAlignment==="Right"?1:t.horizontalAlignment==="Middle"?.5:0,c=t.verticalAlignment==="Bottom"?1:t.verticalAlignment==="Middle"?.5:0;e.save(),e.beginPath(),e.rect(-i/2,-r/2,i,r),e.clip(),e.font=`${o}px "Microsoft YaHei UI","Microsoft YaHei",sans-serif`,e.fillStyle=gt(a),e.textAlign=s===1?"right":s===.5?"center":"left";let l=t.kind==="textwindow"?t.scroll:null;if(e.textBaseline=l?"top":c===1?"bottom":c===.5?"middle":"top",t.enableOutline){let m=or(t.outlineColor,4278190080);e.strokeStyle=gt(m),e.lineWidth=Math.max(2,o*.12),e.lineJoin="round"}let u=l?-i/2+2+s*l.textWidth:s===0?-i/2+2:s===1?i/2-2:0,h=c===0?-r/2:c===1?r/2:0,d=l?.lines||String(t.text||"").split(`
|
|
112
|
-
`),g=l?.lineHeight||o*1.2,y=l?-r/2-l.offset+(l.max>0?0:c*(r-l.contentLength)):c===.5?h-(d.length-1)*g/2:c===1?h-(d.length-1)*g:h;for(let m=0;m<d.length;m+=1){let S=y+m*g;l&&(S+g<-r/2||S>r/2)||(t.enableOutline&&e.strokeText(d[m],u,S),e.fillText(d[m],u,S))}e.restore()}function Ru(e,t,i,r){let n=Mt(t.scroll,i,r);if(n)for(let[o,a]of[[n.track,"#263447"],[n.thumb,"#90aecb"]])e.fillStyle=a,e.fillRect(o.x,o.y,o.width,o.height)}function ss(e,t,i,r){e.beginPath(),Pu(e,-i/2,-r/2,i,r,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 ls(e,t,i,r,n){let o=or(t.imageColor,4294967295),a=n?.images?.get(t.imageId);if(t.primitive==="sprite"&&a){let s=`${t.imageId}:${Number(t.imageColor??4294967295)&16777215}`,c=n.tints.get(s);c||(c=is(a,t.imageColor,Pn().createCanvas),n.tints.set(s,c)),e.globalAlpha*=o.a,e.drawImage(c,-i/2,-r/2,i,r);return}if(t.primitive==="missing"||t.primitive==="sprite"){e.fillStyle="rgba(72,34,40,0.36)",e.fillRect(-i/2,-r/2,i,r),e.strokeStyle="#ff7481",e.lineWidth=1,e.strokeRect(-i/2+.5,-r/2+.5,Math.max(0,i-1),Math.max(0,r-1));return}if(t.primitive==="circle"){e.beginPath(),e.ellipse(0,0,i/2,r/2,0,0,Math.PI*2),e.fillStyle=gt(o),e.fill();return}if(t.primitive==="ring"){e.beginPath(),e.ellipse(0,0,Math.max(1,i/2-3.5),Math.max(1,r/2-3.5),0,0,Math.PI*2),e.strokeStyle=gt(o),e.lineWidth=7,e.stroke();return}if(t.primitive==="triangle"||t.primitive==="fourstar"||t.primitive==="fivestar"){Au(e,t.primitive,i,r,o);return}e.fillStyle=gt(o),e.fillRect(-i/2,-r/2,i,r)}function Tu(e,t,i,r){let n=Math.max(0,U(t.sourceWidth,U(t.width))),o=Math.max(0,U(t.sourceHeight,U(t.height)));e.save();for(let a of t.clipPolygons||[])e.beginPath(),a.forEach((s,c)=>c?e.lineTo(s.x,i-s.y):e.moveTo(s.x,i-s.y)),e.closePath(),e.clip();if(_u(e,t,i),t.kind==="textbox"||t.kind==="textwindow")as(e,t,n,o);else if(t.kind==="button")ss(e,t,n,o);else if(t.kind!=="grid"){let a=An(t,n,o);a&&(e.beginPath(),e.rect(a.x,a.y,a.width,a.height),e.clip()),ls(e,t,n,o,r)}Ru(e,t,n,o),e.restore()}function cs(e,t,i,{checker:r=!1}={}){if(r){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 n=e.createRadialGradient(t/2,i*.45,8,t/2,i/2,Math.max(t,i)*.72);n.addColorStop(0,"#123a6b"),n.addColorStop(.72,"#061934"),n.addColorStop(1,"#071426"),e.fillStyle=n,e.fillRect(0,0,t,i)}function Mu(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 rs(e){let t=e?.matrix;return!t||typeof t!="object"?{a:1,b:0,c:0,d:1,tx:0,ty:0}:{a:U(t.a,1),b:U(t.b),c:U(t.c),d:U(t.d,1),tx:U(t.tx),ty:U(t.ty)}}function Nu(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),c=i.get(s);c?c.push(a):i.set(s,[a])}for(let a of i.values())a.sort((s,c)=>U(s.z)-U(c.z));let r=[];function n(a,s,c){if(!ku.has(a.kind))return;let l=Math.abs(U(a.sourceWidth)*Math.hypot(s.a,s.b)),u=Math.abs(U(a.sourceHeight)*Math.hypot(s.c,s.d));r.push({...a,left:s.tx-l/2,bottom:s.ty-u/2,width:l,height:u,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},...c.length?{clipPolygons:c}:{}})}function o(a,s,c=null,l=[]){let u=i.get(a)||[];for(let h=u.length-1;h>=0;h-=1){let d=u[h],g=s?Mu(s,rs(d)):rs(d),y=l;if(d.clipToParent&&s&&c){let m=c.sourceWidth/2,S=c.sourceHeight/2;y=[...l,[[-m,-S],[m,-S],[m,S],[-m,S]].map(([I,E])=>({x:s.a*I+s.c*E+s.tx,y:s.b*I+s.d*E+s.ty}))]}d.kind!=="grid"&&n(d,g,y),o(String(d.id),g,d,y),d.kind==="grid"&&n(d,g,y)}}return o("",null),r}function us(e,t,i,r={}){return Fu(Nu(e),t,i,r)}function Fu(e,t,i,r={}){let{createCanvas:n}=Pn(),o=ns(t,i,r.scale),a=n(o.pixelWidth,o.pixelHeight),s=a.getContext("2d");s.scale(o.pixelRatio,o.pixelRatio),cs(s,o.width,o.height);let c=Array.isArray(e)?e:[],l={images:r.images,tints:new Map};for(let u of c)!u||u.id===void 0||u.id===null||Tu(s,u,o.height,l);return{data:os(a),width:o.width,height:o.height,pixelWidth:o.pixelWidth,pixelHeight:o.pixelHeight}}function Ou(e){return{kind:e.kind,left:U(e.renderLeft,e.left),bottom:U(e.renderBottom,e.bottom),width:Math.max(0,U(e.renderWidth,e.width)),height:Math.max(0,U(e.renderHeight,e.height)),rotationZ:U(e.renderRotationZ,e.rotationZ)}}function nr(e,t,i){let r=String(t||"");if(!r)return;e.font='10px "Microsoft YaHei UI","Microsoft YaHei",sans-serif',e.textAlign="center",e.textBaseline="middle";let n=e.measureText(r),o=Math.min(i-4,Math.max(24,n.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(r,0,0)}function zu(e,t,i,r,n){let o=Ou(t);if(o.width<=0||o.height<=0)return;e.save(),e.translate(o.left+o.width/2,i-o.bottom-o.height/2),e.rotate(-o.rotationZ*Math.PI/180);let a=-o.width/2,s=-o.height/2;if(t.kind==="image"){e.save();let c=t.enableFill?An(t,o.width,o.height):null;c&&(e.beginPath(),e.rect(c.x,c.y,c.width,c.height),e.clip()),ls(e,t,o.width,o.height,n),e.restore()}else if(t.kind==="textbox"||t.kind==="textwindow")as(e,t,o.width,o.height);else if(t.kind==="button")ss(e,t,o.width,o.height),nr(e,t.name||ir.button,o.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(a,s,o.width,o.height),e.strokeRect(a,s,o.width,o.height),nr(e,t.name||ir.cursor,o.width);else if(t.kind==="grid"){e.strokeStyle="rgba(106,146,189,0.55)",e.strokeRect(a,s,o.width,o.height),e.beginPath();for(let c=20;c<o.width;c+=20)e.moveTo(a+c,s),e.lineTo(a+c,s+o.height);for(let c=20;c<o.height;c+=20)e.moveTo(a,s+c),e.lineTo(a+o.width,s+c);e.stroke(),nr(e,t.name||ir.grid,o.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(a,s,o.width,o.height),nr(e,t.name||ir[t.kind]||t.kind,o.width)):(e.strokeStyle="rgba(78,165,230,0.42)",e.strokeRect(a,s,o.width,o.height));t.id===r&&t.kind!=="container"&&t.kind!=="server-container"&&(e.setLineDash([]),e.strokeStyle="#61b9ff",e.lineWidth=2,e.strokeRect(a,s,o.width,o.height)),e.restore()}function fs(e,t={}){let{createCanvas:i}=Pn(),r=e?.canvas||{},n=ns(r.width||1600,r.height||900,t.scale),o=i(n.pixelWidth,n.pixelHeight),a=o.getContext("2d");a.scale(n.pixelRatio,n.pixelRatio),cs(a,n.width,n.height,{checker:!0});let s=Array.isArray(e?.boxes)?e.boxes:[],c=e?.selectedId,l={images:t.images,tints:new Map};for(let u of s)!u||u.kind==="server-container"||u.visible===!1||zu(a,u,n.height,c,l);return{data:os(o),page:e?.asset?.type==="client-control-template"?"UI\u63A7\u4EF6-\u5BA2\u6237\u7AEF":"UI \u7F16\u8F91",width:n.width,height:n.height,pixelWidth:n.pixelWidth,pixelHeight:n.pixelHeight}}import{closeSync as Du,existsSync as ar,openSync as $u,opendirSync as Gu,readSync as Vu,realpathSync as zt,statSync as hs}from"node:fs";import{basename as ju,dirname as ds,isAbsolute as Nn,join as Yu,relative as ps,resolve as bi}from"node:path";var Bu="qxqy-simulator-save",ms=new Set(["node_modules",".git","dist",".dsh","coverage"]),gi=50,gs=4096,Rn=1e4,Tn=1e3,Mn=8;function yt(e=""){let t=bi(String(e||process.cwd()));if(!ar(t))throw new Error(`workspace does not exist: ${t}`);if(!hs(t).isDirectory())throw new Error(`workspace is not a directory: ${t}`);return zt(t)}function yi(e,t,i=!1){let r=ps(e,t);if(!i&&!r||r.startsWith("..")||Nn(r))throw new Error("path must stay inside the configured workspace");return r}function Oe(e,t){let i=String(t||"").trim();if(!i||Nn(i))throw new Error("path must be a non-empty workspace-relative path");let r=zt(bi(e)),n=bi(r,i);if(yi(r,n),!ar(n))throw new Error(`file does not exist: ${i}`);let o=zt(n);return yi(r,o),o}function _e(e,t){let i=String(t||"").trim();if(!i||Nn(i))throw new Error("path must be a non-empty workspace-relative path");let r=zt(bi(e)),n=bi(r,i);yi(r,n);let o=ds(n);for(;!ar(o);){let a=ds(o);if(a===o)throw new Error("unable to resolve output directory");o=a}return yi(r,zt(o),!0),ar(n)&&yi(r,zt(n)),n}function Hu(e,t=gs){let i=Buffer.alloc(t),r=$u(e,"r");try{let n=Vu(r,i,0,t,0);return i.subarray(0,n).toString("utf8")}finally{Du(r)}}function ys(e,t,i,r,n){if(r>Mn){n.depthLimitedDirectories+=1;return}if(n.scannedDirectories>=Tn){n.directoryLimitReached=!0;return}let o;try{n.scannedDirectories+=1,o=Gu(e)}catch{n.unreadableEntries+=1;return}try{let a;for(;a=o.readSync();){if(n.scannedEntries>=Rn){n.entryLimitReached=!0;return}if(n.scannedEntries+=1,a.name.startsWith(".")||a.isDirectory()&&ms.has(a.name)){n.skippedEntries+=1,a.isDirectory()&&(n.skippedDirectories+=1);continue}let s=Yu(e,a.name);if(a.isDirectory()){if(ys(s,t,i,r+1,n),n.entryLimitReached||n.directoryLimitReached)return;continue}if(!(!a.isFile()||!/\.json$/i.test(a.name))){n.scannedJsonFiles+=1;try{let c=hs(s),l=Hu(s);if(!l.includes(Bu))continue;let u=l.match(/"name"\s*:\s*("(?:\\.|[^"\\])*")/)?.[1],h=ju(a.name,".json");if(u)try{h=JSON.parse(u)||h}catch{}i.push({path:ps(t,s).replaceAll("\\","/"),name:h,bytes:c.size,mtime:c.mtimeMs})}catch{n.unreadableEntries+=1}}}}catch{n.unreadableEntries+=1}finally{try{o.closeSync()}catch{n.unreadableEntries+=1}}}function sr(e){let t=yt(e),i=[],r={truncated:!1,warnings:[],scannedDirectories:0,scannedEntries:0,scannedJsonFiles:0,matchedArchives:0,skippedDirectories:0,skippedEntries:0,unreadableEntries:0,depthLimitedDirectories:0,entryLimitReached:!1,directoryLimitReached:!1,limits:{archives:gi,entries:Rn,directories:Tn,depth:Mn,headBytes:gs},policy:{excludedDirectories:[...ms],hiddenEntries:!1,symlinks:!1,validatesJson:!1}};return ys(t,t,i,0,r),i.sort((n,o)=>o.mtime-n.mtime||n.path.localeCompare(o.path)),r.matchedArchives=i.length,i.length>gi&&r.warnings.push(`\u53D1\u73B0 ${i.length} \u4E2A\u5B58\u6863\uFF0C\u4EC5\u663E\u793A\u4FEE\u6539\u65F6\u95F4\u6700\u65B0\u7684 ${gi} \u4E2A\uFF1B\u5176\u4ED6\u5B58\u6863\u53EF\u901A\u8FC7\u6307\u5B9A\u8DEF\u5F84\u6253\u5F00\u3002`),(r.entryLimitReached||r.directoryLimitReached)&&r.warnings.push(`\u81EA\u52A8\u53D1\u73B0\u8FBE\u5230\u626B\u63CF\u4E0A\u9650\uFF08${Rn} \u9879 / ${Tn} \u4E2A\u76EE\u5F55\uFF09\uFF0C\u5217\u8868\u53EF\u80FD\u4E0D\u5B8C\u6574\uFF1B\u53EF\u901A\u8FC7\u6307\u5B9A\u8DEF\u5F84\u6253\u5F00\u5B58\u6863\u3002`),r.depthLimitedDirectories&&r.warnings.push(`\u81EA\u52A8\u53D1\u73B0\u8DF3\u8FC7 ${r.depthLimitedDirectories} \u4E2A\u8D85\u8FC7 ${Mn} \u5C42\u7684\u76EE\u5F55\uFF1B\u53EF\u901A\u8FC7\u6307\u5B9A\u8DEF\u5F84\u6253\u5F00\u5176\u4E2D\u7684\u5B58\u6863\u3002`),r.skippedEntries&&r.warnings.push("\u81EA\u52A8\u53D1\u73B0\u8DF3\u8FC7\u9690\u85CF\u9879\u53CA\u751F\u6210\u76EE\u5F55\uFF08\u5982 node_modules\u3001dist\uFF09\uFF1B\u53EF\u901A\u8FC7\u6307\u5B9A\u8DEF\u5F84\u6253\u5F00\u5176\u4E2D\u7684\u5B58\u6863\u3002"),r.unreadableEntries&&r.warnings.push(`\u81EA\u52A8\u53D1\u73B0\u65E0\u6CD5\u8BFB\u53D6 ${r.unreadableEntries} \u4E2A\u6587\u4EF6\u6216\u76EE\u5F55\uFF1B\u8BF7\u68C0\u67E5\u8BBF\u95EE\u6743\u9650\uFF0C\u6216\u901A\u8FC7\u6307\u5B9A\u8DEF\u5F84\u67E5\u770B\u5177\u4F53\u9519\u8BEF\u3002`),r.truncated=i.length>gi||r.entryLimitReached||r.directoryLimitReached||r.depthLimitedDirectories>0,{bound:!0,workspace:t,archives:i.slice(0,gi),discovery:r}}import{readFileSync as Uu}from"node:fs";import{homedir as Lu}from"node:os";import{join as Xu}from"node:path";var Wu={"zh-cn":"LanguageChs",chs:"LanguageChs","zh-tw":"LanguageCht",cht:"LanguageCht",en:"LanguageEng","en-us":"LanguageEng",eng:"LanguageEng",ja:"LanguageJpn","ja-jp":"LanguageJpn",jp:"LanguageJpn",ko:"LanguageKor","ko-kr":"LanguageKor",kr:"LanguageKor",fr:"LanguageFra",fra:"LanguageFra",de:"LanguageDeu",deu:"LanguageDeu",es:"LanguageSpa",spa:"LanguageSpa",pt:"LanguagePor",por:"LanguagePor",ru:"LanguageRus",rus:"LanguageRus",th:"LanguageTha",tha:"LanguageTha",vi:"LanguageVie",vie:"LanguageVie",id:"LanguageInd",ind:"LanguageInd",tr:"LanguageTur",tur:"LanguageTur",it:"LanguageIta",ita:"LanguageIta"};function Ku(e){let i=[...String(e||"").matchAll(/Request to set language:([A-Za-z0-9_-]+)/g)].at(-1)?.[1]?.toLowerCase();return Wu[i]||null}function qu(){return Xu(Lu(),"AppData","LocalLow","miHoYo","\u539F\u795E","output_log.txt")}function bs(e=qu()){try{return Ku(Uu(e,"utf8"))}catch{return null}}import{existsSync as zn,lstatSync as Ju,mkdirSync as vs,readFileSync as lr,readdirSync as Qu,realpathSync as ws,renameSync as Zu,rmSync as ef,statSync as fr,writeFileSync as Ss}from"node:fs";import{createHash as tf,randomUUID as Is}from"node:crypto";import{homedir as rf}from"node:os";import{basename as nf,dirname as cr,isAbsolute as of,join as ur,relative as af}from"node:path";var Ye=e=>tf("sha256").update(e).digest("hex"),Fn=e=>zn(e)?Ye(lr(e)):null,On=(e,t)=>{let i=af(e,t);return!of(i)&&i!==".."&&!i.startsWith(`..${process.platform==="win32"?"\\":"/"}`)};function Cs(e,t){let i=_e(e,t),r=i;for(;r!==e;){try{if(Ju(r).isSymbolicLink())throw new Error("\u5B9E\u673A\u76EE\u6807\u4E0D\u80FD\u5305\u542B\u7B26\u53F7\u94FE\u63A5\u6216\u76EE\u5F55\u8054\u63A5")}catch(n){if(n.code!=="ENOENT")throw n}r=cr(r)}if(zn(i)&&!fr(i).isFile())throw new Error("\u5B9E\u673A\u76EE\u6807\u4E0D\u662F\u666E\u901A\u6587\u4EF6");return i}function xs(e=ur(rf(),"AppData","LocalLow","miHoYo","\u539F\u795E","BeyondLocal")){let t=r=>{try{return Qu(r,{withFileTypes:!0}).filter(n=>n.isDirectory()&&/^\d+$/.test(n.name)).map(n=>n.name)}catch{return[]}},i=[];for(let r of t(e)){let n=ur(e,r,"Beyond_Local_Save_Level");for(let o of t(n)){let a=ur(n,o,"external_lua_file","default_import_file");zn(a)&&fr(a).isDirectory()&&i.push({uid:r,editorId:o,path:a})}}return{candidates:i}}var dr=class{constructor(t){this.controller=t,this.plan=null,this.lastResult=null}preview(){let t=this.controller,i=t.studio.archiveData(),r=Wt(i.scriptSync);if(!r)throw new Error("\u8BF7\u5148\u914D\u7F6E\u5B9E\u673A\u811A\u672C\u76EE\u5F55");let n=ws(t.activeWorkspacePath()),o=ws(r.clientImportRoot);if(!fr(o).isDirectory())throw new Error("\u5B9E\u673A\u5BFC\u5165\u6839\u76EE\u5F55\u4E0D\u5B58\u5728");let a=r.workspaceDir?Oe(n,r.workspaceDir):n;if(!fr(a).isDirectory())throw new Error("\u5DE5\u4F5C\u533A\u811A\u672C\u76EE\u5F55\u4E0D\u5B58\u5728");if(On(a,o)||On(o,a))throw new Error("\u5DE5\u4F5C\u533A\u811A\u672C\u76EE\u5F55\u4E0E\u5B9E\u673A\u76EE\u5F55\u4E0D\u80FD\u91CD\u53E0");let s=new Map,c=i.assets.scripts.map(u=>{let h={id:u.id,path:u.path,sourceKind:u.source.trim()?"\u5B58\u6863\u6E90\u7801":"\u5DE5\u4F5C\u533A\u6587\u4EF6"};try{let d=ki(u.path);if(!/\.lua$/i.test(d))throw new Error("\u811A\u672C\u8DEF\u5F84\u5FC5\u987B\u4EE5 .lua \u7ED3\u5C3E");let g=r.workspaceDir?`${r.workspaceDir}/`:"";if(!d.startsWith(g))throw new Error("\u811A\u672C\u4E0D\u5728\u6240\u914D\u7F6E\u7684\u5DE5\u4F5C\u533A\u811A\u672C\u76EE\u5F55\u4E2D");let y=[r.clientSubdir,d.slice(g.length)].filter(Boolean).join("/"),m=Cs(o,y),S=m.toLowerCase();s.set(S,(s.get(S)||0)+1);let I=null,E="";try{I=lr(Oe(n,d),"utf8")}catch(H){E=H.message}if(!u.source.trim()&&I===null)throw new Error(E);let M=u.source.trim()?u.source:I,F=Fn(m);return{...h,target:m,targetRelative:y,source:M,diskSource:I,diskError:E,sourceMismatch:!!(u.source.trim()&&I!==null&&u.source!==I),beforeSource:F===null?"":lr(m,"utf8"),beforeHash:F,sourceHash:Ye(M),status:F===null?"\u65B0\u589E":F===Ye(M)?"\u672A\u53D8\u5316":"\u8986\u76D6"}}catch(d){return{...h,status:"\u9519\u8BEF",error:d.message}}});for(let u of c)u.target&&s.get(u.target.toLowerCase())>1&&(u.status="\u9519\u8BEF",u.error="\u591A\u4E2A\u811A\u672C\u6620\u5C04\u5230\u540C\u4E00\u76EE\u6807\u6587\u4EF6");let l=Ye(JSON.stringify({archive:i,workspace:n,root:o,rows:c}));return this.plan={id:Is(),fingerprint:l,root:o,workspace:n,rows:c,pendingGuidChanges:i.controlGuidChanges.length,createdAt:new Date().toISOString()},this.plan}apply({planId:t,scriptIds:i,confirmed:r}){let n=this.plan;if(r!==!0||!n||n.id!==t)throw new Error("\u8BF7\u5148\u68C0\u67E5\u5DEE\u5F02\u5E76\u786E\u8BA4\u672C\u6B21\u590D\u5236");let o=this.preview();if(this.plan=null,o.fingerprint!==n.fingerprint)throw new Error("\u5185\u5BB9\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");if(n.pendingGuidChanges)throw new Error("\u8BF7\u5148\u6838\u5BF9\u5E76\u786E\u8BA4\u63A7\u4EF6\u7D22\u5F15\u7684 Lua \u5F15\u7528\u53D8\u66F4");if(!Array.isArray(i)||!i.length||new Set(i).size!==i.length)throw new Error("\u8BF7\u9009\u62E9\u8981\u590D\u5236\u7684\u811A\u672C");let a=i.map(u=>{let h=n.rows.find(d=>d.id===u);if(!h||h.error||h.status==="\u672A\u53D8\u5316")throw new Error("\u6240\u9009\u811A\u672C\u4E0D\u80FD\u590D\u5236\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");return h});this.controller.assertSavedArchive();let s=`.qxqy-script-sync-backups/${n.id}`,c=_e(n.workspace,s);if(On(n.root,c))throw new Error("\u5907\u4EFD\u76EE\u5F55\u4E0D\u80FD\u4F4D\u4E8E\u5B9E\u673A\u811A\u672C\u76EE\u5F55\u4E2D");let l=[];for(let u of a){let h="";try{let d=Cs(n.root,u.targetRelative);if(Fn(d)!==u.beforeHash)throw new Error("\u76EE\u6807\u6587\u4EF6\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");if(u.beforeHash!==null){let g=_e(n.workspace,`${s}/${u.targetRelative}`);vs(cr(g),{recursive:!0}),Ss(g,lr(d),{flag:"wx"})}if(vs(cr(d),{recursive:!0}),h=ur(cr(d),`.${nf(d)}.${Is()}.tmp`),Ss(h,u.source,{flag:"wx"}),Fn(d)!==u.beforeHash)throw new Error("\u76EE\u6807\u6587\u4EF6\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");Zu(h,d),l.push({id:u.id,target:d,status:"\u6210\u529F"})}catch(d){l.push({id:u.id,target:u.target,status:"\u5931\u8D25",error:d.message})}finally{h&&ef(h,{force:!0})}}return this.lastResult={completed:l.every(u=>u.status==="\u6210\u529F"),at:new Date().toISOString(),backupRoot:c,results:l},this.lastResult}};import{createHash as sf,randomUUID as lf}from"node:crypto";import{mkdir as cf,open as uf,readFile as ff,rename as df,rm as Dn,stat as hf,writeFile as pf}from"node:fs/promises";import{homedir as $n}from"node:os";import{join as Dt,resolve as mf}from"node:path";import{setTimeout as gf}from"node:timers/promises";var Gn=e=>sf("sha256").update(e).digest("hex");function hr(e){return Dt(process.platform==="win32"?process.env.LOCALAPPDATA||Dt($n(),"AppData","Local"):process.platform==="darwin"?Dt($n(),"Library","Caches"):process.env.XDG_CACHE_HOME||Dt($n(),".cache"),"beyond-simulator",e)}var $t=class{constructor({cacheDir:t,source:i,version:r,extension:n,accepts:o,fetch:a=globalThis.fetch,timeout:s=12e3}){this.directory=Dt(mf(t),r,Gn(i).slice(0,12)),Object.assign(this,{source:i,extension:n,accepts:o,fetcher:a,timeout:s}),this.pending=new Map,this.failures=new Map,this.active=0,this.waiters=[]}async limited(t){this.active>=4?await new Promise(i=>this.waiters.push(i)):this.active++;try{return await t()}finally{let i=this.waiters.shift();i?i():this.active--}}async download(t,i,r,n){let o=await this.fetcher(new URL(t,this.source),{signal:r,redirect:"error",cache:n?"no-cache":"default"});if(!o.ok)throw new Error(`Asset source returned HTTP ${o.status}`);if(Number(o.headers.get("content-length"))>i)throw new Error("Asset response too large");let a=[],s=0;for await(let c of o.body){if(s+=c.length,s>i)throw new Error("Asset response too large");a.push(c)}return Buffer.concat(a)}async cached(t){try{let i=await ff(t);return{data:i,...await this.decode(i),etag:`"${Gn(i)}"`}}catch(i){if(i.code==="ENOENT")return null;if(i.code==="EACCES"||i.code==="EPERM")throw i;return null}}async load(t,i=!1){let r=Dt(this.directory,`${t}.${this.extension}`),n=!i&&await this.cached(r);if(n)return n;await cf(this.directory,{recursive:!0});let o=`${r}.lock`,a=Date.now()+3e4,s;for(;!s;)try{s=await uf(o,"wx")}catch(l){if(l.code!=="EEXIST")throw l;let u=!i&&await this.cached(r);if(u)return u;try{Date.now()-(await hf(o)).mtimeMs>6e4&&await Dn(o,{force:!0})}catch(h){if(h.code!=="ENOENT")throw h}if(Date.now()>a)throw new Error("Timed out waiting for asset cache writer");await gf(80)}let c=`${r}.${lf()}.tmp`;try{let l=!i&&await this.cached(r);if(l)return l;let u=new AbortController,h=setTimeout(()=>u.abort(),this.timeout),d;try{d=await this.produce(t,u.signal,i)}finally{clearTimeout(h),u.abort()}let g=await this.decode(d);return await pf(c,d,{flag:"wx"}),await df(c,r),{data:d,...g,etag:`"${Gn(d)}"`}}finally{try{await Dn(c,{force:!0})}finally{await s.close(),await Dn(o,{force:!0})}}}get(t,{refresh:i=!1}={}){if(!this.accepts(t))return Promise.reject(Object.assign(new Error("Asset ID is not in the preview allowlist"),{status:404}));if(this.pending.has(t))return this.pending.get(t);let r=this.failures.get(t);if(!i&&r&&r.until>Date.now())return Promise.reject(r.error);let n=this.limited(()=>this.load(t,i)).then(o=>(this.failures.delete(t),o),o=>{throw i||this.failures.set(t,{until:Date.now()+6e4,error:o}),o}).finally(()=>this.pending.delete(t));return this.pending.set(t,n),n}async refresh(t){if(!this.accepts(t))throw Object.assign(new Error("Asset ID is not in the preview allowlist"),{status:404});return await this.pending.get(t)?.catch(()=>{}),this.failures.delete(t),this.get(t,{refresh:!0})}};import{createCanvas as yf,loadImage as ks}from"@napi-rs/canvas";var As=20*1024*1024,bf=Buffer.from("89504e470d0a1a0a","hex");function vf(e,t){return t.throwIfAborted(),new Promise((i,r)=>{let n=()=>r(t.reason);t.addEventListener("abort",n,{once:!0}),e.then(i,r).finally(()=>t.removeEventListener("abort",n))})}function wf(){return process.env.QXQY_IMAGE_CACHE_DIR||hr("images")}function Es(e){if(e.length<24||e.length>As||!e.subarray(0,8).equals(bf))throw new Error("Invalid sprite PNG");let t=e.readUInt32BE(16),i=e.readUInt32BE(20);if(!t||!i||t>8192||i>8192||t*i>16777216)throw new Error("Sprite PNG exceeds pixel limit")}var Vn=class extends $t{constructor({cacheDir:t=wf(),fetch:i=globalThis.fetch,source:r=qn}={}){super({cacheDir:t,fetch:i,source:r,version:vr,extension:"png",accepts:Lt})}async decode(t){return Es(t),{image:await ks(t)}}async produce(t,i,r){let[n,o]=await Promise.all([this.download(`sprite/${t}.png`,As,i,r),this.download(`border/${t}.json`,131072,i,r)]);Es(n);let a=await ks(n),s=ts(a,JSON.parse(o.toString("utf8")),yf);return Buffer.from(s.toBuffer("image/png"))}async prepare(t,i){let r=new Map,n=[],o=[...new Set((t||[]).filter(l=>l.kind==="image"&&l.visible!==!1&&Lt(l.imageId)).map(l=>l.imageId))];i?.throwIfAborted();let a=AbortSignal.timeout(45e3),s=i?AbortSignal.any([i,a]):a,c=0;await Promise.all(Array.from({length:Math.min(4,o.length)},async()=>{for(;c<o.length&&!s.aborted;){let l=o[c++];try{r.set(l,(await vf(this.get(l),s)).image)}catch(u){n.push({imageId:l,error:u.message})}}}));for(let l of o.slice(c))n.push({imageId:l,error:"Image preparation timed out"});return i?.throwIfAborted(),{images:r,warnings:n}}},Sf;function vi(){return Sf||=new Vn}async function _s(e,t,i=vi()){let r=new URL(e.url,"http://localhost");if(r.pathname!==Ii.slice(0,-1)&&!r.pathname.startsWith(Ii))return!1;try{if(!["GET","HEAD"].includes(e.method))throw Object.assign(new Error("GET or HEAD required"),{status:405});let n=r.pathname.match(new RegExp(`^${Ii}${vr}/([0-9]+)\\.png$`));if(!n)throw Object.assign(new Error("Unknown image resource"),{status:404});let o=await i.get(Number(n[1])),a={"content-type":"image/png","cache-control":"private, max-age=43200",etag:o.etag,"x-content-type-options":"nosniff"};e.headers["if-none-match"]===o.etag?(t.writeHead(304,a),t.end()):(t.writeHead(200,{...a,"content-length":o.data.length}),t.end(e.method==="HEAD"?void 0:o.data))}catch(n){t.writeHead(n.status||502,{"content-type":"text/plain; charset=utf-8","cache-control":"no-store","x-content-type-options":"nosniff"}),t.end(e.method==="HEAD"?void 0:n.message)}return!0}var _f=Math.max(1e3,Number(process.env.QXQY_PLAY_TIMEOUT_MS)||8e3),Pf=8e3;function Ps(){let e=new Error("operation aborted");return e.name="AbortError",e}var Gt=class{constructor(t="",{imageAssets:i=vi()}={}){this.workspacePath=t?yt(t):"",this.studio=En(void 0,this.workspacePath?{workspacePath:this.workspacePath}:void 0),this.worker=null,this.pending=new Map,this.sequence=1,this.lock=Promise.resolve(),this.archivePath="",this.archiveStamp="",this.savedArchive="",this.scriptSync=new dr(this),this.imageAssets=i}async exclusive(t){let i=this.lock,r;this.lock=new Promise(n=>{r=n}),await i;try{return await t()}finally{r()}}get(){return{...this.studio.get(),storage:{path:this.archivePath}}}scriptSyncAction(t,i={}){if(t==="discover")return xs();if(t==="status")return{config:this.get().scriptSync,lastResult:this.scriptSync.lastResult};if(t==="configure"){if(!Number.isInteger(i.expectedRevision))throw new Error("expectedRevision is required");return this.patch({op:"setScriptSync",config:i.config,expectedRevision:i.expectedRevision})}if(t==="preview")return this.scriptSync.preview();throw new Error("unknown script sync action (AI \u53EF\u914D\u7F6E\u548C\u9884\u89C8\uFF1B\u590D\u5236\u9700\u5728\u7F16\u8F91\u5668\u4E2D\u786E\u8BA4)")}assertSavedArchive(){if(!this.archivePath||this.savedArchive!==JSON.stringify(this.studio.archiveData()))throw new Error("\u8BF7\u5148\u4FDD\u5B58\u5F53\u524D\u5B8C\u6574\u5B58\u6863\uFF0C\u518D\u786E\u8BA4\u590D\u5236");let t=Oe(this.activeWorkspacePath(),this.archivePath);if(Ye(jn(t))!==this.archiveStamp)throw new Error("\u5B58\u6863\u6587\u4EF6\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u52A0\u8F7D\u5E76\u68C0\u67E5")}saveForScriptSync(t,i){if(i!==this.get().version)throw new Error("revision conflict: reload before saving");let r=_e(this.activeWorkspacePath(),t);if(Cf(r)){let n=this.archivePath?_e(this.activeWorkspacePath(),this.archivePath):"";if(r!==n||Ye(jn(r))!==this.archiveStamp)throw new Error("File changed or already exists; load it again or save under a new path")}return this.saveArchive(t)}patch(t){return{...this.studio.patch(t),storage:{path:this.archivePath}}}listArchives(){return sr(this.workspacePath)}loadArchive(t){let i=this.activeWorkspacePath();if(!i)throw new Error("workspace is not bound");let r=Oe(i,t),n=jn(r),o=this.studio.importData("json",n.toString("base64"),Ef(r));return this.archivePath=String(t).trim().replaceAll("\\","/"),this.archiveStamp=Ye(n),this.savedArchive=JSON.stringify(this.studio.archiveData()),o}saveArchive(t=this.archivePath||"qxqy-simulator.save.json"){let i=String(t).trim(),r=this.activeWorkspacePath();if(!r)throw new Error("workspace is not bound");let n=_e(r,i);xf(Af(n),{recursive:!0});let o=Buffer.from(JSON.stringify(this.studio.archiveData(),null,2)+`
|
|
113
|
-
`,"utf8");return kf(n,o),this.archivePath=i.replaceAll("\\","/"),this.archiveStamp=Ye(o),this.savedArchive=JSON.stringify(this.studio.archiveData()),{path:this.archivePath,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 If(new URL("./worker.js",import.meta.url),{type:"module"});return t.on("message",i=>{let r=this.pending.get(i?.id);r&&(this.pending.delete(i.id),i.ok?r.resolve(i.value):r.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,r,n=_f){let o=this.worker||this.createWorker(),a=this.sequence++;return new Promise((s,c)=>{let l=!1,u=(g,y)=>{l||(l=!0,clearTimeout(d),r?.removeEventListener("abort",h),g(y))},h=()=>{this.pending.delete(a),u(c,Ps()),this.terminateWorker(Ps())},d=setTimeout(()=>{this.pending.delete(a);let g=new Error(`play worker timed out after ${n}ms`);u(c,g),this.terminateWorker(g)},n);if(this.pending.set(a,{resolve:g=>u(s,g),reject:g=>u(c,g)}),r?.aborted)return h();r?.addEventListener("abort",h,{once:!0}),o.postMessage({id:a,action:t,args:i})})}async play(t,i={},r){if((t==="start"||t==="device")&&!i.language){let n=bs();n&&(i={...i,language:n})}if(t==="start")return await this.terminateWorker(),this.request("start",{archive:this.studio.archiveData(),workspacePath:this.activeWorkspacePath(),...i},r);if(t==="device"){let n=String(i.canvasId||"").trim();if(!X[n])throw new Error(`unknown canvas preset: ${n||"(empty)"} (available: ${Object.keys(X).join(", ")})`);return await this.terminateWorker(),this.request("start",{archive:this.studio.archiveData(),workspacePath:this.activeWorkspacePath(),...i,canvasId:n},r)}if(t==="stop"){if(!this.worker)return{running:!1,tree:[],logs:[]};try{return await this.request("stop",i,r)}finally{await this.terminateWorker()}}if(!this.worker)throw new Error("play session has not started");return this.request(t,i,r)}async playScreenshot(t){if(!this.worker)throw new Error("play session has not started");let i=await this.request("get",{view:!0},t,Pf),r=await this.imageAssets.prepare(i.scene?.nodes,t),n=us(i.scene,i.canvasWidth,i.canvasHeight,r);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,assetWarnings:r.warnings}}async uiScreenshot(t){let i=this.studio.get(),r=await this.imageAssets.prepare(i.boxes,t),n=fs(i,r);return{data:n.data,page:n.page,width:n.width,height:n.height,pixelWidth:n.pixelWidth,pixelHeight:n.pixelHeight,assetWarnings:r.warnings}}async dispose(){await this.terminateWorker()}};var Tf=new Set(["server-control-template","client-control-template"]),Mf=new Set(["start","device","view","get","step","pointer","key","click","pause","resume","stop","serverGet","serverSet","serverSend","history","saveCase","runCase"]);function Rs(e){return String(e||"").trim().replaceAll("\\","/")}function Ts(e,t){let i=Rf(Oe(e,t));return`${i.size}:${i.mtimeMs}`}function Nf(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 Ms(e,t,i){let r=i==="stop"||t?.running===!1,n=Array.isArray(t?.logs)?t.logs.slice(-100):e.logs;return{running:!r,paused:r?!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:n}}var pr=class{constructor({workspace:t,initialPath:i="",watchIntervalMs:r=700,discoveryIntervalMs:n=5e3,imageAssets:o}={}){this.workspace=yt(t),this.controller=new Gt(this.workspace,{imageAssets:o}),this.initialPath=Rs(i),this.watchIntervalMs=Math.max(100,Number(r)||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,this.discoveryIntervalMs=Math.max(100,Number(n)||5e3),this.archiveCache=null,this.archiveCacheTime=0,this.openGeneration=0,this.disposed=!1}async initialize(){let t=this.archives().archives,i=this.initialPath||t[0]?.path||"";if(i)try{await this.open(i,"startup")}catch{}return this.timer=setInterval(()=>{this.refreshFromDisk()},this.watchIntervalMs),this.state()}archives(t=!1){return(t||!this.archiveCache||Date.now()-this.archiveCacheTime>=this.discoveryIntervalMs)&&(this.archiveCache=sr(this.workspace),this.archiveCacheTime=Date.now()),this.archiveCache}previewStatus(){let t=this.controller.get();return{service:"beyond-simulator-web",version:Kn.version,workspace:this.workspace,activePath:this.activePath,lastLoadedAt:this.lastLoadedAt,lastError:this.lastError,revision:this.activePath?t.version:null,name:this.activePath&&t.save?.name||""}}state(){let t=this.archives();return{...this.previewStatus(),archives:t.archives,discovery:t.discovery,snapshot:Nf(this.controller.get()),play:this.playState}}recordError(t){let i=t?.message||String(t),r=i!==this.lastError;this.lastError=i,r&&this.emit({type:"error",error:i})}async open(t,i="manual",r=this.openGeneration){let n=Rs(t);if(!n)throw new Error("path is required");return this.controller.exclusive(async()=>{if(this.disposed||i==="external-change"&&r!==this.openGeneration)return this.state();try{await this.controller.play("stop"),this.playState=Ms(this.playState,{running:!1,logs:[]},"stop");let o=Ts(this.workspace,n),a=this.controller.loadArchive(n);return this.activePath=n,this.activeStamp=o,this.initialPath="",this.openGeneration++,this.lastLoadedAt=new Date().toISOString(),this.lastError="",this.archiveCache=null,this.emit({type:"archive",reason:i,path:n,revision:a.version}),this.state()}catch(o){throw this.recordError(o),o}})}async refreshFromDisk(){if(this.refreshing||this.disposed)return!1;this.refreshing=!0;try{if(!this.activePath){let i=this.initialPath||this.archives().archives[0]?.path||"";return i?(await this.open(i,"external-change"),!0):!1}return Ts(this.workspace,this.activePath)===this.activeStamp&&!this.lastError?!1:(await this.open(this.activePath,"external-change"),!0)}catch(t){return this.recordError(t),!1}finally{this.refreshing=!1}}async setView({assetType:t,canvasId:i}={}){if(t&&!Tf.has(t))throw new Error(`unknown asset type: ${t}`);if(i&&!X[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 r=this.controller.get().version;this.controller.patch({op:"setCanvas",canvasId:i,expectedRevision:r})}}),this.emit({type:"view"}),this.state()}async play(t,i={},r){if(!Mf.has(t))throw new Error(`unknown play action: ${t||"(empty)"}`);let n=await this.controller.exclusive(()=>this.controller.play(t,i,r));return this.playState=Ms(this.playState,n,t),this.emit({type:"play",action:t,frame:this.playState.frame}),n}async currentState(t){return this.state()}editorScreenshot(t){return this.controller.uiScreenshot(t)}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.disposed=!0,this.timer&&clearInterval(this.timer),this.timer=null,this.listeners.clear(),await this.controller.exclusive(()=>this.controller.dispose())}};import{existsSync as Ff,readFileSync as Of}from"node:fs";import{createHash as zf}from"node:crypto";var Df=new Set(["get","patch","import","export","archives","load-archive","save","play","script-sync","script-sync-apply","image-refresh"]),Yn=e=>zf("sha256").update(Of(e)).digest("hex"),mr=class{constructor(t,{initialPath:i="",maxSessions:r=8,imageAssets:n}={}){this.workspace=t,this.initialPath=i,this.maxSessions=r,this.sessions=new Map,this.imageAssets=n}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 r={controller:new Gt(this.workspace,{imageAssets:this.imageAssets}),path:"",fileStamp:""};this.initialPath&&this.load(r,this.initialPath),this.sessions.set(t,r)}return this.sessions.get(t)}snapshot(t){return{...t.controller.get(),storage:{path:t.path}}}load(t,i){let r=Oe(this.workspace,i),n=t.controller.loadArchive(i);return t.path=String(i).replaceAll("\\","/"),t.fileStamp=Yn(r),{...n,snapshot:this.snapshot(t)}}async call(t,i,r){if(!Df.has(t))throw new Error("Unknown editor action");let n=this.getSession(i.sessionId),o=n.controller;return o.exclusive(async()=>{if(t==="get")return this.snapshot(n);if(t==="image-refresh")return await o.imageAssets.refresh(i.imageId),{imageId:i.imageId,refreshed:!0};if(t==="script-sync")return o.scriptSyncAction(i.action,i.args||{});if(t==="script-sync-apply")return o.scriptSync.apply(i);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(n)}if(t==="export")return o.studio.exportData(i.format,i.assetType);if(t==="play")return o.play(i.action,i.args||{},r);if(t==="load-archive"||t==="import"){if(await o.play("stop"),t==="load-archive")return this.load(n,i.path);let a=o.studio.importData(i.format,i.data,i.filename);return n.path="",n.fileStamp="",{...a,snapshot:this.snapshot(n)}}if(t==="save"){if(i.expectedRevision!==o.get().version)throw new Error("revision conflict: reload before saving");let a=_e(this.workspace,i.path);if(Ff(a)){let c=n.path?_e(this.workspace,n.path):"";if(a!==c||Yn(a)!==n.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 n.path=s.path,n.fileStamp=Yn(a),s}})}async dispose(){await Promise.all([...this.sessions.values()].map(t=>t.controller.exclusive(()=>t.controller.dispose()))),this.sessions.clear()}};var Ns=32*1024*1024;function $f(e){if(e.length<8||e.length>Ns)throw new Error("Invalid MP3 size");let t=0,i=0;if(e.subarray(0,3).toString()==="ID3"){if(e.length<10||e[3]<2||e[3]>4||e.subarray(6,10).some(r=>r>127))throw new Error("Invalid MP3 ID3 header");t=10+(e[6]<<21|e[7]<<14|e[8]<<7|e[9])+(e[5]&16&&e[3]===4?10:0)}for(;t+4<=e.length;){if(e.length-t===128&&e.subarray(t,t+3).toString()==="TAG"){t=e.length;break}let r=e[t+1],n=e[t+2],o=r>>3&3,a=n>>2&3,s=n>>4;if(e[t]!==255||(r&224)!==224||(r&6)!==2||o===1||a===3||s===0||s===15)throw new Error("Invalid MP3 frame");let c=(o===3?[0,32,40,48,56,64,80,96,112,128,160,192,224,256,320]:[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160])[s],l=[44100,48e3,32e3][a]/(o===3?1:o===2?2:4),u=Math.floor((o===3?144e3:72e3)*c/l)+(n>>1&1);t+=u,i++}if(i<2||t!==e.length)throw new Error("Truncated or invalid MP3")}var Bn=class extends $t{constructor({cacheDir:t=process.env.QXQY_AUDIO_CACHE_DIR||hr("audio"),fetch:i=globalThis.fetch,source:r=Na}={}){super({cacheDir:t,fetch:i,source:r,version:on,extension:"mp3",accepts:n=>Xi(n)!==null,timeout:2e4})}decode(t){return $f(t),{}}produce(t,i,r){return this.download(`audio/${t}.mp3`,Ns,i,r)}},Gf;function Hn(){return Gf||=new Bn}async function Fs(e,t,i=Hn()){let r=new URL(e.url,"http://localhost");if(r.pathname!==Li.slice(0,-1)&&!r.pathname.startsWith(Li))return!1;try{if(!["GET","HEAD"].includes(e.method))throw Object.assign(new Error("GET or HEAD required"),{status:405});let n=r.pathname.match(new RegExp(`^${Li}${on}/([0-9]+)\\.mp3$`));if(!n)throw Object.assign(new Error("Unknown audio resource"),{status:404});let o=await i.get(Number(n[1])),a=o.data.length,s={"content-type":"audio/mpeg","cache-control":"private, max-age=43200",etag:o.etag,"accept-ranges":"bytes","x-content-type-options":"nosniff"};if(e.headers["if-none-match"]===o.etag)return t.writeHead(304,s),t.end(),!0;let c=e.headers.range,l=0,u=a-1,h=200;if(c&&(!e.headers["if-range"]||e.headers["if-range"]===o.etag)){let d=c.match(/^bytes=(\d*)-(\d*)$/);if(!d||!d[1]&&!d[2])throw Object.assign(new Error("Invalid byte range"),{status:416,size:a});if(d[1]?(l=Number(d[1]),u=d[2]?Math.min(a-1,Number(d[2])):u):l=Math.max(0,a-Number(d[2])),!Number.isSafeInteger(l)||!Number.isSafeInteger(u)||l>=a||u<l)throw Object.assign(new Error("Unsatisfiable byte range"),{status:416,size:a});h=206,s["content-range"]=`bytes ${l}-${u}/${a}`}t.writeHead(h,{...s,"content-length":u-l+1}),t.end(e.method==="HEAD"?void 0:o.data.subarray(l,u+1))}catch(n){t.writeHead(n.status||502,{"content-type":"text/plain; charset=utf-8","cache-control":"no-store",...n.status===416?{"content-range":`bytes */${n.size}`}:{}}),t.end(e.method==="HEAD"?void 0:n.message)}return!0}var Lf=$s(new URL(".",import.meta.url)),Xf=Ds(Lf,"public"),zs=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"]]),Wf={".html":"text/html; charset=utf-8",".js":"text/javascript; charset=utf-8",".css":"text/css; charset=utf-8"};function Kf(e=process.argv.slice(2)){let t=(i,r="")=>{let n=e.indexOf(i);return n>=0&&e[n+1]?e[n+1]:r};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 yr(e,t="'none'"){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 ${t}`,"x-content-type-options":"nosniff"}}function Ce(e,t,i){e.writeHead(t,yr("application/json; charset=utf-8")),e.end(JSON.stringify(i))}function qf(e,t){e.writeHead(200,{...yr("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 gr(e,t=1024*1024){let i=[],r=0;for await(let n of e){if(r+=n.length,r>t)throw new Error("request body is too large");i.push(n)}return i.length?JSON.parse(Buffer.concat(i).toString("utf8")):{}}function Jf(e){let t=process.platform==="win32"?"cmd.exe":process.platform==="darwin"?"open":"xdg-open",i=process.platform==="win32"?["/c","start","",e]:[e];Vf(t,i,{detached:!0,stdio:"ignore",windowsHide:!0}).unref()}async function Qf(e={}){e={...e,imageAssets:e.imageAssets||vi(),audioAssets:e.audioAssets||Hn()};let t=e.host||"127.0.0.1",i=e.password??process.env.QXQY_WEB_PASSWORD??"",r=["127.0.0.1","localhost","::1"].includes(t);if(!r&&!i)throw new Error("QXQY_WEB_PASSWORD is required when listening outside loopback");let n=m=>Hf("sha256").update(m).digest(),o=n(i),a=new pr(e);await a.initialize();let s=new mr(a.workspace,e),c=new Set,l=a.subscribe(m=>{let S=`event: state
|
|
114
|
-
data: ${JSON.stringify(
|
|
107
|
+
`)}`);return{buffer:r,warnings:[...new Set(t.warnings)]}}function qr(e){return Te.toObject(Te.decode(Yi(e)),{longs:Number,enums:Number,bytes:Buffer,defaults:!1,arrays:!0,objects:!0})}function Qa(e){try{let i=qr(e).graph||[];return i.length>0&&i.every(r=>Number(r.which)===Mt)}catch{return!1}}function eo(e){let t=(e.graph||[]).filter(n=>Number(n.which)===Mt),i=[],r=t.map((n,a)=>{let o=n.script?.mapping||{},s=Number(n.id?.id)||0;s<=0&&i.push(`\u7B2C ${a+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 c=Number(o.id)||0;return c&&c!==s&&i.push(`\u7B2C ${a+1} \u6761\u811A\u672C\u6620\u5C04 id(${c}) \u4E0E\u5355\u5143 id(${s}) \u4E0D\u4E00\u81F4\uFF0C\u4EE5\u5355\u5143 id \u4E3A\u51C6\u3002`),{guid:s,path:String(o.filePath||""),source:String(o.source||"")}});for(let[n,a]of r.entries())a.path&&!/\.lua$/iu.test(a.path)&&i.push(`\u7B2C ${n+1} \u6761\u811A\u672C\u6620\u5C04 file_path \u7F3A\u5C11 .lua \u540E\u7F00\uFF08${a.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:r,warnings:i}}function to(e){let t=qr(e),i=eo(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 ac(e){let t=[],i;try{i=qr(e)}catch(n){return{valid:!1,errors:[n?.message||String(n)],scriptCount:0}}let r=i.graph||[];return r.length||t.push("Root.graph \u4E3A\u7A7A"),(i.accessories||[]).length&&t.push("script.gia \u4E0D\u5E94\u5305\u542B accessories"),r.forEach((n,a)=>{let o=`\u5355\u5143 ${a+1}`;Number(n.which)!==Mt&&t.push(`${o}: which \u5E94\u4E3A 69\uFF0C\u5B9E\u9645 ${n.which}`),Number(n.id?.class)!==qa&&t.push(`${o}: id.class \u5E94\u4E3A 30\uFF0C\u5B9E\u9645 ${n.id?.class}`),Number(n.id?.type??0)!==0&&t.push(`${o}: id.type \u5E94\u7F3A\u7701`);let s=n.script?.mapping;if(!s){t.push(`${o}: \u7F3A\u5C11 field35 ScriptMappingWrapper`);return}Number(n.id?.id)<=0&&t.push(`${o}: GraphUnit.id.id \u975E\u6CD5`),Number(s.id)!==Number(n.id?.id)&&t.push(`${o}: mapping.id \u5E94\u7B49\u4E8E GraphUnit.id.id`),String(s.name||"")!==String(n.name||"")&&t.push(`${o}: mapping.name \u5E94\u7B49\u4E8E GraphUnit.name`),String(s.filePath||"").trim()?/\.lua$/iu.test(String(s.filePath))||t.push(`${o}: 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(`${o}: file_path \u4E3A\u7A7A`)}),{valid:t.length===0,errors:t,scriptCount:r.length}}function Yi(e){let t=Buffer.isBuffer(e)?e:Buffer.from(e);if(t.length<it+jr)throw new Error("GIA \u6587\u4EF6\u8FC7\u77ED");if(t.readUInt32BE(4)!==1||t.readUInt32BE(8)!==$a||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-it-jr)throw new Error("GIA payload \u957F\u5EA6\u4E0D\u4E00\u81F4");if(t.readUInt32BE(it+i)!==Ga)throw new Error("GIA \u5C3E\u6807\u8BB0\u65E0\u6548");return t.subarray(it,it+i)}function de(e,t){return e.ui?.content?.data?.find(i=>i.details?.[t])?.details?.[t]||null}function oc(e){let t=de(e,"transform")?.multiPlatform,i={};for(let n of t?.platforms||[]){let a=Wl[n.platformType||0],o=n.transform||{};i[a]={scale:o.scale?{x:o.scale.x??0,y:o.scale.y??0,z:o.scale.z??0}:{x:1,y:1,z:1},rotation:{x:0,y:0,z:o.field508?.z??0},anchorMin:{x:o.anchorMin?.x??0,y:o.anchorMin?.y??0},anchorMax:{x:o.anchorMax?.x??0,y:o.anchorMax?.y??0},offset:{x:o.offset?.x??0,y:o.offset?.y??0},size:{x:o.size?.x??0,y:o.size?.y??0},pivot:o.pivot?{x:o.pivot.x??0,y:o.pivot.y??0}:{x:.5,y:.5}}}let r=i.KEYBOARD||i[Object.keys(i)[0]];if(!r)throw new Error(`GIA \u63A7\u4EF6 ${e.name||e.id?.id} \u7F3A\u5C11\u591A\u5E73\u53F0\u53D8\u6362`);for(let n of ce)i[n]||(i[n]=structuredClone(r));return i}function Vi(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 za(e,{reverseSiblings:t=!1,idOffset:i=0}={}){if(!e.length)return{nodes:new Map,rootCandidates:[],warnings:[]};let r=new Map(e.map((l,u)=>[l.id?.id,`n${i+u+1}`])),n=new Map,a=new Map,o=[];for(let l of e){let u=Vi(l),d=de(l,"textConfig"),h=de(l,"imageSlot"),p=de(l,"image"),m=de(l,"buttonPreset"),g=de(l,"gridView"),S=de(l,"genericSlot"),C=de(l,"footerSlot"),I=de(l,"cursorConfig"),P=de(l,"keyHint"),N=de(l,"containerNodeSlot"),G=de(l,"templateRefSlot"),j=de(l,"effectSlot"),B=de(l,"fullscreenEffectSlot"),z=q(u,{id:r.get(l.id?.id),guid:l.id?.id||0,giaInfoIndex:(l.ui?.content?.info||[]).find(b=>b.field501===2&&b.field502===6)?.index?.value,giaRelatedGuids:(l.ui?.content?.info||[]).find(b=>b.field501===4&&b.field502===4)?.related?.value||[],name:l.name||u,visible:de(l,"field14")?.field17?.initiallyHidden!==!0,active:de(l,"field14")?.initiallyInactive!==!0,canControllerFocus:C?.field505===1,scriptMappingIds:(S?.field502||[]).map(b=>Number(b?.field1?.id)).filter(b=>Number.isSafeInteger(b)&&b>0),transformByPlatform:oc(l),syncAllDevices:de(l,"transform")?.multiPlatform?.field504===1,giaRaw:{genericField501:S?.field501??0,footerField505:C?.field505??0,...u==="textbox"||u==="textwindow"?{textField501:d?.field501??20,textField503:d?.field503??12,textAlign:d?.align??0,...[void 0,0,1,2].includes(d?.verticalAlign)?{}:{textVerticalAlign:d.verticalAlign},...u==="textwindow"?{textField511:d?.field511??1,textViewField502:d?.viewFlags?.field502??1,textViewField503:d?.viewFlags?.field503??1}:{}}:{},...u==="cursor"?{cursorField501:I?.field501??0}:{},...u==="reference"?{templateRefSlot:G??""}:{},...u==="grid"?{gridField501:g?.field501??1,gridField507:g?.field507??1,gridField508:g?.field508??1,gridField509:g?.field509??1,gridField511:g?.field511??5,gridField512:g?.field512??1}:{},...u==="keyhint"?{keyHintField501:P?.field501??1,keyHintField502:P?.field502??1}:{},...u==="image"?{imageSlotType:h?.imageType??0,imageField502:p?.field502??1,imageField504:p?.field504??1,imageField505:p?.field505??1,imageField507:p?.field507??2,imageFillType:p?.fillType??1}:{},...u==="animation"?{effectSlot:j??""}:{},...u==="fullscreen"?{fullscreenEffectSlot:B??""}:{}},...u==="container"?{isolateNavigation:N?.isolateNavigation===!0,disableKeyEventPassthrough:N?.disableKeyEventPassthrough===!0,disableCursorEventPassthrough:N?.disableCursorEventPassthrough===!0,showCursor:N?.showCursor===!0}:{},...u==="cursor"?{raycastTarget:I?.field501===1}:{},...u==="textbox"||u==="textwindow"?{text:d?.text?.value??"",fontSize:d?.fontSize??20,minimumFontSize:d?.minimumFontSize??20,adaptiveFontSize:d?.adaptive===1,fontColor:d?.color??4294967295,bgColor:d?.color2??0,enableOutline:d?.outlineOff!==1,outlineColor:d?.color3??858993459,horizontalAlignment:d?.align===1?"Middle":d?.align===2?"Right":"Left",verticalAlignment:{0:"Top",1:"Middle",2:"Bottom"}[d?.verticalAlign??0]||"Top",...u==="textwindow"?{interactable:!0,showScrollBar:!0}:{}}:{},...u==="image"?{imageSource:"StaticReference",imageId:h?.assetId??0,imageType:h?.imageType===1?"Stretch":"Basic",imageColor:Number.isFinite(h?.field502)?h.field502>>>0:4294967295,enableMask:p?.enableMask===1,enableSoftEdge:p?.enableSoftEdge===1,enableFill:p?.enableFill===1,softEdgeMode:p?.softEdgePixel===1?"Pixel":"Percentage",softEdgeWidthX:p?.border?.field501??8,softEdgeWidthY:p?.border?.field502??8,horizontalSoftRange:p?.field512??85,verticalSoftRange:p?.field513??85,fillType:{1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[p?.fillType]||"Horizontal",fillAmount:Number.isFinite(p?.field508)?Math.max(0,Math.min(1,p.field508/100)):p?.enableFill===1?0:1,reverseMaskArea:p?.reverseMask===1}:{},...u==="button"?{interactable:m?.interactable===1,raycastTarget:m?.raycastTarget===1,clickAudioId:m?.clickAudioId??50888}:{},...u==="grid"?{cellSizeX:g?.cellSize?.field501??50,cellSizeY:g?.cellSize?.field502??50,spacingX:g?.gap?.field501??8,spacingY:g?.gap?.field502??8,padding1X:g?.padding1?.field501??20,padding1Y:g?.padding1?.field502??20,padding2X:g?.padding2?.field501??20,padding2Y:g?.padding2?.field502??20,previewCount:g?.field511??5}:{},...u==="reference"?{referencedPrefabId:G??""}:{},...u==="keyhint"?{keyboardKeyCode:P?.field502??null,controllerKeyCode:P?.field501??null}:{},...u==="animation"?{animationId:j??""}:{},...u==="fullscreen"?{animationId:B??""}:{}});n.set(l.id?.id,z),(u==="textbox"||u==="textwindow")&&![void 0,0,1,2].includes(d?.align)&&o.push(`${z.name}: \u6C34\u5E73\u5BF9\u9F50\u679A\u4E3E ${d.align} \u7684\u542B\u4E49\u672A\u77E5\uFF0C\u5DF2\u539F\u6837\u4FDD\u7559\u3002`),(u==="textbox"||u==="textwindow")&&![void 0,0,1,2].includes(d?.verticalAlign)&&o.push(`${z.name}: \u5782\u76F4\u5BF9\u9F50\u679A\u4E3E ${d.verticalAlign} \u7684\u542B\u4E49\u672A\u77E5\uFF0C\u5DF2\u539F\u6837\u4FDD\u7559\u3002`),u==="image"&&![void 0,0,1,2,3,4,5].includes(p?.fillType)&&o.push(`${z.name}: \u586B\u5145\u5F62\u72B6\u679A\u4E3E ${p.fillType} \u672A\u8BC6\u522B\uFF0C\u5DF2\u4FDD\u7559\u539F\u503C\u3002`),u==="button"&&a.set(z.id,{unavailableChildId:m?.disabledChild,hoverChildId:m?.hoverChild,pressedChildId:m?.pressedChild,selectedChildId:m?.selectedChild})}let s=[],c=new Set;for(let l of e){let u=n.get(l.id?.id),d=(l.ui?.content?.children||[]).map(h=>n.get(h)).filter(Boolean);if(d.length){u.children=t?d.slice().reverse():d;for(let h of d)c.add(h.id)}}for(let l of e){let u=n.get(l.id?.id),d=l.ui?.content?.parent||0,h=n.get(d);h?c.has(u.id)||(t?h.children.unshift(u):h.children.push(u)):s.push(u)}for(let[l,u]of a){let d=[...n.values()].find(h=>h.id===l);for(let[h,p]of Object.entries(u))d[h]=r.get(p)||null}return{nodes:n,rootCandidates:s,warnings:o}}function io(e){let t=Yi(e),i=Te.toObject(Te.decode(t),{longs:Number,enums:Number,bytes:Buffer,defaults:!1,arrays:!0,objects:!0}),r=i.graph||[];if(!r.some(m=>m.ui?.content))throw new Error("GIA \u4E0D\u542B\u53EF\u8BC6\u522B\u7684 UIControlGroup \u4E3B\u56FE");let n=r.find(m=>m.which===21)||null,a=r.filter(m=>Number(m.which)===70),o=i.accessories||[],s=new Set((n?.relatedIds||[]).map(m=>m.id||0)),c=n?s.size?o.filter(m=>s.has(m.id?.id||0)):o:[],l=a.length?[...a,...o.filter(m=>!s.has(m.id?.id||0))]:n?[]:[...r,...o];if(!c.length&&!l.length)throw new Error("GIA \u4E0D\u542B\u5BA2\u6237\u7AEF\u63A7\u4EF6");let u=["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"],d=eo(i);u.push(...d.warnings);let h=null,p=null;if(c.length){let m=za(c,{reverseSiblings:!0,idOffset:0});u.push(...m.warnings);let g=m.rootCandidates.find(C=>C.kind==="container")||m.rootCandidates[0];if(!g)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6839\u63A7\u4EF6");let S=q("server-container",{id:"sc1",guid:n?.id?.id||0,name:n?.name||"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668",giaRelatedGuids:(n?.ui?.content?.info||[]).find(C=>C.field501===4&&C.field502===4)?.related?.value||[]});S.children=[g],m.rootCandidates.length>1&&u.push(`\u68C0\u6D4B\u5230 ${m.rootCandidates.length} \u4E2A\u65E0\u7236\u8282\u70B9\u63A7\u4EF6\uFF0C\u4EC5\u5BFC\u5165\u4EE5\u201C${g.name}\u201D\u4E3A\u6839\u7684\u6811\u3002`),h={version:1,layoutSchemaVersion:pe,meta:{name:n?.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:g.id,script:{controlId:g.id,path:"",source:""},root:S}}if(l.length){let m=za(l,{reverseSiblings:!1,idOffset:1e3});if(u.push(...m.warnings),!m.rootCandidates.length)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6A21\u677F");let g=q("server-container",{id:"sc1",guid:0,name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"});g.children=m.rootCandidates,p={version:1,layoutSchemaVersion:pe,meta:{name:m.rootCandidates.length===1?m.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:m.rootCandidates[0].id,script:{controlId:m.rootCandidates[0].id,path:"",source:""},root:g},He(p,{warnings:u}),h||(h=p)}return{project:h,clientProject:p&&h!==p?p:void 0,scripts:d.scripts,warnings:u,metadata:{gameVersion:i.gameVersion||"",filePath:i.filePath||"",...Number.isSafeInteger(Number(i.modeFlag))?{modeFlag:Number(i.modeFlag)}:{},combined:!!(n&&a.length)}}}function Jr(e){let t=Yi(e),i=Te.toObject(Te.decode(t),{longs:Number,enums:Number,defaults:!1,arrays:!0,objects:!0}),r=i.graph||[],n=i.accessories||[],a=[],o=(p,m)=>p!=null&&Object.prototype.hasOwnProperty.call(p,m),s=new Map,c=[];/^\d+-\d+-\d+-\\.+\.gia$/iu.test(i.filePath||"")||a.push(`Root.filePath \u4E0D\u662F UID-TIME-ID-\\\u6587\u4EF6\u540D.gia\uFF1A${i.filePath||"<missing>"}`);let l=r.filter(p=>p.which===70).map(p=>{let m=Vi(p),g=p.ui?.content?.info||[],S=g.find(P=>P.field501===2&&P.field502===6)?.index?.value,C=g.find(P=>P.field501===4&&P.field502===4),I=C?.related?.value||[];return Ee(S)||a.push(`${p.name}: Info.index=${S??"<missing>"}\uFF0C\u5FC5\u987B\u662F\u6B63\u6574\u6570`),C||a.push(`${p.name}: \u9876\u5C42 UIControlTemplate \u7F3A\u5C11 Info.related \u8BB0\u5F55`),{id:p.id?.id||0,name:p.name||"",kind:m,actualIndex:S,relatedPresent:!!C,relatedGuids:I}}),u=new Map;for(let p of l){if(!Ee(p.actualIndex))continue;let m=u.get(p.actualIndex);m?a.push(`${p.name}: \u72EC\u7ACB\u6A21\u677F\u8D44\u4EA7\u7F16\u53F7 ${p.actualIndex} \u4E0E ${m.name} \u91CD\u590D`):u.set(p.actualIndex,p)}l.length||a.push("Root.graph \u4E0D\u542B UIControlTemplate(70)");let d=0,h=0;for(let p of[...r,...n]){if(!p.ui?.content)continue;let m=p.id?.id||0,g=p.ui.content,S=Vi(p),C=r.includes(p)&&p.which===70,I=`${p.name||"<unnamed>"}(${m||"<missing-guid>"})`;!Number.isSafeInteger(m)||m<=0||m>2147483647?a.push(`${I}: GraphUnit GUID \u975E\u6CD5`):s.has(m)?a.push(`${I}: GUID \u4E0E ${s.get(m).name||"<unnamed>"} \u91CD\u590D`):s.set(m,p),(p.id?.class!==1||p.id?.type!==8)&&a.push(`${I}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),g.guid!==m&&a.push(`${I}: content.guid=${g.guid??"<missing>"} \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`),C&&p.which!==70&&a.push(`${I}: \u6A21\u677F\u6839 which \u5FC5\u987B\u4E3A UIControlTemplate(70)`),!C&&p.which!==15&&a.push(`${I}: \u9644\u4EF6\u63A7\u4EF6 which \u5FC5\u987B\u4E3A UIControl(15)`);let P=g.info||[],N=P.find(_=>_.field501===1&&_.field502===5),G=P.find(_=>_.field501===2&&_.field502===6);N?.guid?.value!==m&&a.push(`${I}: Info.self GUID \u7F3A\u5931\u6216\u4E0E\u81EA\u8EAB\u4E0D\u4E00\u81F4`),Ee(G?.index?.value)||a.push(`${I}: Info.index=${G?.index?.value??"<missing>"}\uFF0C\u5FC5\u987B\u662F\u6B63\u6574\u6570`);let j=P.find(_=>_.field501===4&&_.field502===4);C&&!j&&a.push(`${I}: \u9876\u5C42\u6A21\u677F\u7F3A\u5C11 Info.related \u8BB0\u5F55`),!C&&j&&a.push(`${I}: \u9644\u4EF6\u63A7\u4EF6\u4E0D\u5E94\u5199 Info.related`);let B=Ya[S],z=g.data||[],b=z.map(_=>`${_.field501}/${_.field502}`),A=B?.map(([_])=>_)||[];B?JSON.stringify(b)!==JSON.stringify(A)&&a.push(`${I}: Data \u69FD\u4F4D\u987A\u5E8F ${b.join(",")}\uFF0C\u5E94\u4E3A ${A.join(",")}`):a.push(`${I}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${S}`);for(let _=0;_<Math.min(z.length,B?.length||0);_+=1){let $=z[_],[Y,re,X]=B[_];if(o($,re)||a.push(`${I}: Data ${Y} \u7F3A\u5C11 ${re} \u5206\u652F`),!X)continue;o($.details,X)||a.push(`${I}: Details ${Y} \u7F3A\u5C11 ${X} \u5206\u652F`);let te=Ba[Y];($.details?.field501!==te||$.details?.field502!==$.field502||$.details?.field503!==1)&&a.push(`${I}: Details ${Y} \u6807\u8BB0\u5E94\u4E3A ${te}/${$.field502}/1`);let _e=$.details?.nodeRef;(_e?.class!==1||_e?.type!==8||_e?.id!==m)&&a.push(`${I}: Details ${Y} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let w=(p.ui.content.data||[]).find(_=>_.field501===4&&_.field502===86);w&&(o(w.field14,"field17")?d+=1:a.push(`${I}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`),o(w.details?.field14,"field17")?d+=1:a.push(`${I}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`));let k=(p.ui.content.data||[]).find(_=>_.details?.transform)?.details?.transform?.multiPlatform?.platforms||[];k.length!==4&&a.push(`${I}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${k.length}\uFF0C\u5E94\u4E3A 4`);let F=k.map(_=>_.platformType||0);JSON.stringify(F)!==JSON.stringify([0,1,2,3])&&a.push(`${I}: \u5E73\u53F0\u987A\u5E8F ${F.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let E=(p.ui.content.data||[]).find(_=>_.details?.transform)?.details?.transform;E?.multiPlatform?.field502!==ri[S]&&a.push(`${I}: \u53D8\u6362 preset=${E?.multiPlatform?.field502??"<missing>"}\uFF0C${S} \u5E94\u4E3A ${ri[S]}`);for(let _ of k)o(_.transform,"field508")?h+=1:a.push(`${I}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);c.push({id:m,name:p.name||"",kind:S,template:C,parent:g.parent||0,children:[...g.children||[]],relatedIds:(p.relatedIds||[]).map(_=>_.id||0),dataSignatures:b})}for(let p of c){let m=`${p.name||"<unnamed>"}(${p.id})`;if(JSON.stringify(p.relatedIds)!==JSON.stringify(p.children)&&a.push(`${m}: GraphUnit.relatedIds \u4E0E content.children \u4E0D\u4E00\u81F4`),p.template&&p.parent&&a.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)||a.push(`${m}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):a.push(`${m}: parent=${p.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let g of p.children){let S=s.get(g);S?(S.ui?.content?.parent||0)!==p.id&&a.push(`${m}: child=${g} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):a.push(`${m}: child=${g} \u4E0D\u5B58\u5728`)}}return{valid:a.length===0,errors:a,filePath:i.filePath||"",gameVersion:i.gameVersion||"",templateCount:l.length,accessoryCount:n.length,templates:l,units:c,explicitEmpty:{field17:d,rectField508:h}}}function Zr(e){let t=Yi(e),i=Te.toObject(Te.decode(t),{longs:Number,enums:Number,defaults:!1,arrays:!0,objects:!0}),r=(i.graph||[]).filter(E=>E.ui?.content&&Number(E.which)===21),n=(i.graph||[]).filter(E=>Number(E.which)===70),a=(i.graph||[]).filter(E=>Number(E.which)===Mt),o=(i.accessories||[]).filter(E=>E.ui?.content),s=[],c=(E,_)=>E!=null&&Object.prototype.hasOwnProperty.call(E,_);/^\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>"}`),r.length!==1&&s.push(`\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F UIControlGroup \u6570\u91CF=${r.length}\uFF0C\u5E94\u4E3A 1`);let l=(i.graph||[]).filter(E=>{let _=Number(E.which);return _===Mt||_===70||_===21?!1:!E.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 u=r[0];if(!u)return{valid:!1,errors:s,filePath:i.filePath||"",gameVersion:i.gameVersion||"",accessoryCount:o.length,controls:[],scriptCount:a.length,explicitEmpty:{field17:0,rectField508:0}};let d=[u,...n,...o],h=new Map;for(let E of d){let _=E.id?.id||0,$=`${E.name||"<unnamed>"}(${_||"<missing-guid>"})`;!Number.isSafeInteger(_)||_<=0||_>2147483647?s.push(`${$}: GraphUnit GUID \u975E\u6CD5`):h.has(_)?s.push(`${$}: GUID \u91CD\u590D`):h.set(_,E),(E.id?.class!==1||E.id?.type!==8)&&s.push(`${$}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),E.ui?.content?.guid!==_&&s.push(`${$}: content.guid \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`)}let p=u.id?.id||0,m=u.ui.content,g=`${u.name||"<unnamed>"}(${p})`;u.which!==21&&s.push(`${g}: which \u5FC5\u987B\u4E3A UIControlGroup(21)`);let S=m.info||[];S.find(E=>E.field501===1&&E.field502===5)?.guid?.value!==p&&s.push(`${g}: Info.self GUID \u7F3A\u5931\u6216\u4E0D\u4E00\u81F4`),S.find(E=>E.field501===2&&E.field502===6)?.index?.value!==1&&s.push(`${g}: Info.index \u5FC5\u987B\u4E3A 1`);let C=S.find(E=>E.field501===4&&E.field502===4);C||s.push(`${g}: \u7F3A\u5C11\u663E\u5F0F Info.related \u8BB0\u5F55`);let I=0,P=0,N=(E,_,$,Y=!1)=>{let re=E.id?.id||0,X=`${E.name||"<unnamed>"}(${re})`,te=E.ui.content.data||[],_e=te.map(ae=>`${ae.field501}/${ae.field502}`),Ct=$.map(([ae])=>ae);JSON.stringify(_e)!==JSON.stringify(Ct)&&s.push(`${X}: Data \u69FD\u4F4D\u987A\u5E8F ${_e.join(",")}\uFF0C\u5E94\u4E3A ${Ct.join(",")}`);for(let ae=0;ae<Math.min(te.length,$.length);ae+=1){let Fe=te[ae],[Ye,Lt,Xt]=$[ae];if(c(Fe,Lt)||s.push(`${X}: Data ${Ye} \u7F3A\u5C11 ${Lt} \u5206\u652F`),!Xt)continue;c(Fe.details,Xt)||s.push(`${X}: Details ${Ye} \u7F3A\u5C11 ${Xt} \u5206\u652F`);let Ke=Ba[Ye];(Fe.details?.field501!==Ke||Fe.details?.field502!==Fe.field502||Fe.details?.field503!==1)&&s.push(`${X}: Details ${Ye} \u6807\u8BB0\u5E94\u4E3A ${Ke}/${Fe.field502}/1`);let Wt=Fe.details?.nodeRef;(Wt?.class!==1||Wt?.type!==8||Wt?.id!==re)&&s.push(`${X}: Details ${Ye} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let Ut=te.find(ae=>ae.field501===4&&ae.field502===(Y?23:86)),ne=Y?"empty15":"field17";c(Ut?.field14,ne)?Y||(I+=1):s.push(`${X}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.${ne} \u7A7A\u4E32`),c(Ut?.details?.field14,ne)?Y||(I+=1):s.push(`${X}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.${ne} \u7A7A\u4E32`);let Oe=te.find(ae=>ae.details?.transform)?.details?.transform,st=Oe?.multiPlatform?.platforms||[];st.length!==4&&s.push(`${X}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${st.length}\uFF0C\u5E94\u4E3A 4`);let ki=st.map(ae=>ae.platformType||0);JSON.stringify(ki)!==JSON.stringify([0,1,2,3])&&s.push(`${X}: \u5E73\u53F0\u987A\u5E8F ${ki.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let Ei=Y?ri["server-container"]:ri[_];Oe?.multiPlatform?.field502!==Ei&&s.push(`${X}: \u53D8\u6362 preset=${Oe?.multiPlatform?.field502??"<missing>"}\uFF0C\u5E94\u4E3A ${Ei}`);for(let ae of st)c(ae.transform,"field508")?P+=1:s.push(`${X}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);return _e};N(u,"server-container",Kl,!0);let G=(u.relatedIds||[]).map(E=>E.id||0),j=new Set(G),B=o.filter(E=>j.has(E.id?.id||0)),z=B.map(E=>E.id?.id||0);JSON.stringify(G)!==JSON.stringify(z)&&s.push(`${g}: \u4E3B\u56FE relatedIds \u5FC5\u987B\u6309\u987A\u5E8F\u8986\u76D6\u672C\u7EC4 accessories`);let b=m.data?.find(E=>E.details?.rootChildRef)?.details?.rootChildRef?.guid||0,A=h.get(b);(!A||!B.includes(A))&&s.push(`${g}: 62/82 \u6839\u8282\u70B9\u5F15\u7528\u4E0D\u5B58\u5728`),z[0]!==b&&s.push(`${g}: \u6839\u5BB9\u5668\u8282\u70B9\u5FC5\u987B\u662F\u672C\u7EC4 accessories[0]`);let w=[];for(let E of B){let _=E.id?.id||0,$=E.ui.content,Y=`${E.name||"<unnamed>"}(${_})`,re=Vi(E);E.which!==15&&s.push(`${Y}: which \u5FC5\u987B\u4E3A UIControl(15)`);let X=$.info||[];(X.length!==1||X[0]?.field501!==1||X[0]?.field502!==5||X[0]?.guid?.value!==_)&&s.push(`${Y}: \u670D\u52A1\u7AEF\u5BB9\u5668\u5185\u63A7\u4EF6 Info \u5FC5\u987B\u53EA\u542B\u81EA\u8EAB GUID`);let te=Ya[re];te||s.push(`${Y}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${re}`);let _e=te?N(E,re,te):[];w.push({id:_,name:E.name||"",kind:re,parent:$.parent||0,children:[...$.children||[]],relatedIds:(E.relatedIds||[]).map(Ct=>Ct.id||0),dataSignatures:_e})}let k=w.find(E=>E.id===b);k&&(k.kind!=="container"&&s.push(`${k.name}(${b}): \u6839\u63A7\u4EF6\u5FC5\u987B\u4E3A\u5BB9\u5668\u8282\u70B9`),k.parent&&s.push(`${k.name}(${b}): \u6839\u63A7\u4EF6\u4E0D\u5E94\u6709 parent`));let F=new Map(w.map(E=>[E.id,E]));for(let E of w){let _=`${E.name}(${E.id})`;if(JSON.stringify(E.relatedIds)!==JSON.stringify(E.children)&&s.push(`${_}: relatedIds \u5FC5\u987B\u4E0E\u76F4\u63A5 children \u4E00\u81F4`),E.id!==b){let $=F.get(E.parent);$?$.children.includes(E.id)||s.push(`${_}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):s.push(`${_}: parent=${E.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let $ of E.children){let Y=F.get($);Y?Y.parent!==E.id&&s.push(`${_}: child=${$} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):s.push(`${_}: child=${$} \u4E0D\u5B58\u5728`)}}if(n.length){let E=Jr(Wr({...i,graph:n,accessories:o.filter(_=>!j.has(_.id?.id||0))}));s.push(...E.errors.map(_=>`\u5BA2\u6237\u7AEF\u6A21\u677F: ${_}`))}return{valid:s.length===0,errors:s,filePath:i.filePath||"",gameVersion:i.gameVersion||"",graph:{id:p,name:u.name||"",relatedGuids:C?.related?.value||[],rootGuid:b},accessoryCount:o.length,controls:w,scriptCount:a.length,explicitEmpty:{field17:I,rectField508:P}}}function ro(e,t=[]){if(!e||e.layoutSchemaVersion===pe)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:pe};let i=structuredClone(e),r=0;return Q(i.root,n=>{let a=n.transformByPlatform||{},o=n.transformByCanvas||{},s=n.name||n.id;for(let l of Object.keys(a))if(!ce.includes(l))throw new Error(`${s}: unknown platform ${l}`);let c={};for(let l of ce){let u=kt[l],d=K[u].platform,h=Object.keys(K).filter(S=>K[S].platform===d&&o[S]),p=o[u]?u:h[0],m=l==="CONTROLLER_CONSOLE"?c.KEYBOARD:l==="CONTROLLER_MOBILE"?c.TOUCHSCREEN:null,g=a[l]??m??(p?o[p]:null);if(c[l]=g?$e(g):$r(n.kind),g||t.push(`${s}: ${l} \u65E0\u65E7\u5E03\u5C40\uFF0C\u5DF2\u4F7F\u7528\u63A7\u4EF6\u9ED8\u8BA4\u503C`),!a[l]&&!m&&p&&p!==u&&t.push(`${s}: \u7F3A\u5C11 ${u}\uFF0C\u5DF2\u91C7\u7528 ${p} \u7684\u951A\u70B9\u548C\u5C3A\u5BF8\u53C2\u6570`),!m)for(let S of h)JSON.stringify(c[l])!==JSON.stringify($e(o[S]))&&t.push(`${s}: ${S} \u4E0E ${l} \u5E03\u5C40\u51B2\u7A81\uFF0C\u4FDD\u7559${a[l]?"\u5DF2\u6709\u5E73\u53F0":p}\u53C2\u6570`)}Je(c,`${s}.transformByPlatform`),n.transformByPlatform=c,delete n.transformByCanvas,r++}),i.layoutSchemaVersion=pe,t.unshift(`\u5DF2\u81EA\u52A8\u8FC1\u79FB\u65E7\u5E03\u5C40\uFF1A${r} \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 Qr(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 tn(e,t,i,r=e.canvasId){let n=Qe(e.root,t);return!n||n.kind==="server-container"?ye(r):i[n.id]||ye(r)}function rt(e,{warnings:t=[]}={}){if(!e)return dt();if(e=ro(e,t),(e.root||e.layoutSchemaVersion!==void 0)&&e.layoutSchemaVersion!==pe)throw new Error(`\u4EC5\u652F\u6301 layoutSchemaVersion=${pe} \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",r=i==="client-control-template"?Rt():dt(),n={layoutSchemaVersion:pe,version:Number.isSafeInteger(e.version)&&e.version>0?e.version:1,meta:{name:String(e.meta?.name||r.meta.name),assetType:i,sourceFormat:String(e.meta?.sourceFormat||r.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(e.meta?.giaNextAssetIndex)&&e.meta.giaNextAssetIndex>=2?{giaNextAssetIndex:e.meta.giaNextAssetIndex}:{},...Number.isSafeInteger(e.meta?.giaAssetIndexSchemaVersion)&&e.meta.giaAssetIndexSchemaVersion>0?{giaAssetIndexSchemaVersion:e.meta.giaAssetIndexSchemaVersion}:{},...Number.isSafeInteger(Number(e.meta?.giaModeFlag))&&Number(e.meta.giaModeFlag)>=0?{giaModeFlag:Number(e.meta.giaModeFlag)}:{}},canvasId:e.canvasId&&K[e.canvasId]?e.canvasId:Mi,selectedId:e.selectedId||r.selectedId,root:Yr(e.root||r.root)};return lo(n),He(n,{warnings:t}),n}function lo(e){let t=new Set;Q(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=Vr(e.root).id)}function no(e){return Ze(Tt(e))}function sc(e,t){let i=!1;return Q(e,r=>{r.id===t&&(i=!0)}),i}function lc(e,t,i,r){let a=tt(e.root,e.canvasId).boxes[t.id],o=i.children.findIndex(d=>d.id===t.id);if(o<0)throw new Error("reparent: source node is not attached");if(i.children.splice(o,1),r.children.push(t),!a)return;let s=tt(e.root,e.canvasId),c=r.kind==="server-container"?ye(e.canvasId):s.boxes[r.id]||ye(e.canvasId),l=et(t.transformByPlatform,e.canvasId),u=lt(c,l,{posX:a.centerX,posY:a.centerY,width:a.width,height:a.height});Nt(e,t,u)}function cc(e,t){return e.meta.assetType!=="client-control-template"?Br(e.root,t):(e.root.children||[]).flatMap(i=>Br(i,t))}function co(e,t){let i=Oa(e.root,t);if(e.meta.assetType!=="client-control-template")return i;let r=ii(e),n=new Set;return r&&r.kind!=="server-container"&&Q(r,a=>n.add(a.id)),i.filter(a=>n.has(a.id))}function uo(e){let{canvas:t,boxes:i}=tt(e.root,e.canvasId),r=ai(e),n=fe(e.root,e.selectedId),a=n?i[n.id]:null;return V({layoutSchemaVersion:pe,version:e.version,meta:{...e.meta},canvasId:e.canvasId,canvas:{id:e.canvasId,width:t.width,height:t.height,platform:K[e.canvasId].platform,label:K[e.canvasId].label,presets:Object.values(K).map(o=>({id:o.id,label:o.label,width:o.width,height:o.height,platform:o.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"&&ii(e)?.id||""},tree:cc(e,r),boxes:co(e,i),inspector:Fa(n,e.canvasId,a||t,r),root:e.root})}function Nt(e,t,i){let r=tt(e.root,e.canvasId),n=tn(e,t.id,r.boxes),a={};if(t.syncAllDevices!==!1)for(let o of ce){if(o===ct(e.canvasId))continue;let s=kt[o],c=tt(e.root,s,o);a[o]=tn(e,t.id,c.boxes,s)}t.transformByPlatform=Na({transformByPlatform:t.transformByPlatform,source:i,canvasId:e.canvasId,syncAllDevices:t.syncAllDevices!==!1,sourceParentBox:n,targetParentBoxByPlatform:a})}var uc=new Set(["name","active","visible","canControllerFocus","isolateNavigation","disableKeyEventPassthrough","disableCursorEventPassthrough","showCursor","fontSize","adaptiveFontSize","minimumFontSize","fontColor","bgColor","enableOutline","outlineColor","horizontalAlignment","verticalAlignment","text","imageSource","imageType","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","itemPrefabId","layoutConstraintFixedCount"]),fc=new Set(["posX","posY","width","height"]),dc=new Set(["anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]);function hc(e){if(typeof e=="number"&&Number.isFinite(e))return e>>>0;if(typeof e=="string"){let t=e.trim();if(t.startsWith("#")){let r=t.slice(1);if(r.length===6)return(4278190080|parseInt(r,16))>>>0;if(r.length===8)return parseInt(r,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 Ue(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function ao(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 mc=new Set(["fontSize","minimumFontSize","imageId","clickAudioId","softEdgeWidthX","softEdgeWidthY","horizontalSoftRange","verticalSoftRange","fillAmount","cellSizeX","cellSizeY","spacingX","spacingY","padding1X","padding1Y","padding2X","padding2Y","previewCount","keyboardKeyCode","controllerKeyCode","itemPrefabId","layoutConstraintFixedCount"]),pc=new Set(["active","visible","canControllerFocus","isolateNavigation","disableKeyEventPassthrough","disableCursorEventPassthrough","showCursor","adaptiveFontSize","enableOutline","enableMask","enableSoftEdge","enableFill","reverseMaskArea","raycastTarget","interactable","showScrollBar"]),gc=new Set(["name","imageSource","horizontalAlignment","verticalAlignment","text","softEdgeMode","fillType","fillHorizontalType","fillVerticalType","fillRadial90Type","fillRadialType","scrollDirection","layoutConstraint","referencedPrefabId","animationId"]),oo=new Set(["unavailableChildId","hoverChildId","pressedChildId","selectedChildId"]),so={imageSource:["StaticReference","Prefab"],imageType:["Basic","Stretch",null],scrollDirection:["Horizontal","Vertical"],layoutConstraint:["AutoWrap","Fixed"],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 yc(e,t){if(!t||typeof t!="object")throw new Error("patch requires op");let i=t.op;if(i==="select")return t.id&&fe(e.root,t.id)&&(e.selectedId=t.id),e;if(i==="pick"){let{boxes:r}=tt(e.root,e.canvasId),n=co(e,r),a=Da(n,Number(t.x),Number(t.y));return a&&(e.selectedId=a),e}if(i==="setCanvas")return t.canvasId&&K[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 r=t.assetType==="client-control-template"?Rt():dt();return e.version=r.version,e.meta=r.meta,e.canvasId=r.canvasId,e.selectedId=r.selectedId,e.root=r.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 r=q(t.kind,{id:Gr(e.root),guid:no(e.root),name:t.name||`\u65B0${t.kind==="container"?"\u5BB9\u5668\u8282\u70B9":t.kind}\u6A21\u677F`});return e.root.children.push(r),e.selectedId=r.id,e}if(i==="add"){let r=fe(e.root,t.parentId||e.selectedId);if(!r)throw new Error("add: parent not found");let n=Ta(r,t.kind,{id:Gr(e.root),guid:no(e.root),name:t.name});return e.selectedId=n.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 r=fe(e.root,t.id||e.selectedId),n=r?Qe(e.root,r.id):null,a=fe(e.root,t.parentId);if(!r||r.kind==="server-container"||!n)throw new Error("reparent: node not found");if(!a)throw new Error("reparent: parent not found");if(a.id===r.id||sc(r,a.id))throw new Error("\u63A7\u4EF6\u4E0D\u80FD\u79FB\u52A8\u5230\u81EA\u8EAB\u6216\u5176\u540E\u4EE3\u4E0B\u9762");if(a.kind==="server-container"&&n.kind==="server-container")return e;if(n.kind==="server-container"&&a.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 lc(e,r,n,a),e.selectedId=r.id,e}if(i==="moveSibling"){let r=fe(e.root,t.id||e.selectedId),n=r?Qe(e.root,r.id):null;if(!r||!n)throw new Error("moveSibling: node not found");let a=n.children.findIndex(c=>c.id===r.id),o=t.direction==="up"?-1:t.direction==="down"?1:0,s=a+o;return!o||s<0||s>=n.children.length||(n.children.splice(a,1),n.children.splice(s,0,r),e.selectedId=r.id),e}if(i==="remove"){let r=t.id||e.selectedId,n=Qe(e.root,r);if(n?.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 Ra(e.root,r)&&(Q(e.root,a=>{if(a.kind==="button")for(let o of oo)a[o]&&!fe(e.root,a[o])&&(a[o]=null)}),e.selectedId=n?n.id:e.root.id),e}if(i==="set"){let r=fe(e.root,t.id||e.selectedId);if(!r)throw new Error("set: node not found");let n=t.key;n==="reverseMask"&&(n="reverseMaskArea");let a=t.value;if(n.startsWith("giaRaw.")){let l=n.slice(7);if(!l||l.includes("."))throw new Error("invalid raw GIA field path");let u=Aa(r.kind,l);if(!u)throw new Error(`unknown raw GIA field for ${r.kind}: ${l}`);if(r.giaRaw||={},r.giaRaw[l]=Or(u,a),l==="footerField505"&&[0,1].includes(r.giaRaw[l])&&(r.canControllerFocus=r.giaRaw[l]===1),r.kind==="cursor"&&l==="cursorField501"&&[0,1].includes(r.giaRaw[l])&&(r.raycastTarget=r.giaRaw[l]===1),(r.kind==="textbox"||r.kind==="textwindow")&&l==="textAlign"){let d={0:"Left",1:"Middle",2:"Right"}[r.giaRaw[l]];d&&(r.horizontalAlignment=d)}if(r.kind==="image"&&l==="imageFillType"){let d={1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[r.giaRaw[l]];d&&(r.fillType=d)}return r.kind==="keyhint"&&l==="keyHintField502"&&(r.keyboardKeyCode=r.giaRaw[l]),r.kind==="keyhint"&&l==="keyHintField501"&&(r.controllerKeyCode=r.giaRaw[l]),e}if(n==="syncAllDevices"){if(r.syncAllDevices=ao(a),r.syncAllDevices){let l=et(r.transformByPlatform,e.canvasId);Nt(e,r,l)}return e}if(uc.has(n)){if(n.endsWith("Color")&&(a=hc(a)),mc.has(n)){if(a=Ue(a,n),a<0)throw new Error(`${n} must not be negative`);if((n==="imageId"||n==="clickAudioId"||n==="keyboardKeyCode"||n==="controllerKeyCode")&&(a=Math.trunc(a)),n==="fillAmount"&&a>1)throw new Error("fillAmount must be between 0 and 1")}if(pc.has(n)&&(a=ao(a)),gc.has(n)&&(a=String(a??"")),n==="horizontalAlignment"&&!["Left","Middle","Right"].includes(a))throw new Error("invalid horizontalAlignment");if(n==="verticalAlignment"&&!["Top","Middle","Bottom"].includes(a))throw new Error("invalid verticalAlignment");if(so[n]&&!so[n].includes(a))throw new Error(`invalid ${n}`);if(oo.has(n))if(a===""||a===void 0||a===null)a=null;else{a=String(a);let l=fe(e.root,a);if(!l||l===r||l.kind==="server-container"||!(r.children||[]).some(u=>u.id===a))throw new Error(`${n} must reference a direct child of this button`)}if(r.kind==="image"&&(n==="imageSource"||n==="imageId")&&r[n]!==a&&(r.imageType=null,r.giaRaw.imageSlotType=0),r[n]=a,r.kind==="image"&&n==="imageType"&&(r.giaRaw.imageSlotType=a==="Stretch"?1:0),n==="canControllerFocus"&&(r.giaRaw.footerField505=a?1:0),r.kind==="cursor"&&n==="raycastTarget"&&(r.giaRaw.cursorField501=a?1:0),(r.kind==="textbox"||r.kind==="textwindow")&&n==="horizontalAlignment"&&(r.giaRaw.textAlign={Left:0,Middle:1,Right:2}[a]),(r.kind==="textbox"||r.kind==="textwindow")&&n==="verticalAlignment"&&delete r.giaRaw.textVerticalAlign,r.kind==="image"&&n==="fillType"){let l={Horizontal:1,Vertical:2,Radial90:3,Radial180:4,Radial360:5}[a];l&&(r.giaRaw.imageFillType=l)}return r.kind==="reference"&&n==="referencedPrefabId"&&(r.giaRaw.templateRefSlot=a),r.kind==="grid"&&n==="previewCount"&&(r.giaRaw.gridField511=Math.trunc(a)),r.kind==="keyhint"&&n==="keyboardKeyCode"&&(r.giaRaw.keyHintField502=Math.trunc(a)),r.kind==="keyhint"&&n==="controllerKeyCode"&&(r.giaRaw.keyHintField501=Math.trunc(a)),(r.kind==="animation"||r.kind==="fullscreen")&&n==="animationId"&&(r.giaRaw[r.kind==="animation"?"effectSlot":"fullscreenEffectSlot"]=a),e}let{boxes:o}=tt(e.root,e.canvasId),s=tn(e,r.id,o),c=et(r.transformByPlatform,e.canvasId);if(n==="anchorType"){let l=en(o[r.id]),u=Ia(c,a);return u=lt(s,u,l),Nt(e,r,u),e}if(n==="rotationZ"){let l={...c,rotation:{...c.rotation,z:Ue(a,n)}};return Nt(e,r,l),e}if(dc.has(n)){let l=en(o[r.id]),u={...c,anchorMin:{...c.anchorMin},anchorMax:{...c.anchorMax},pivot:{...c.pivot}};return n==="anchorMinX"&&(u.anchorMin.x=Ue(a,n)),n==="anchorMinY"&&(u.anchorMin.y=Ue(a,n)),n==="anchorMaxX"&&(u.anchorMax.x=Ue(a,n)),n==="anchorMaxY"&&(u.anchorMax.y=Ue(a,n)),n==="pivotX"&&(u.pivot.x=Ue(a,n)),n==="pivotY"&&(u.pivot.y=Ue(a,n)),Nt(e,r,lt(s,u,l)),e}if(fc.has(n)){let l=en(o[r.id]),u=Ue(a,n);if((n==="width"||n==="height")&&u<0)throw new Error(`${n} must not be negative`);return l[n]=u,Nt(e,r,lt(s,c,l)),e}throw new Error(`set: unknown key ${n}`)}if(i==="replace"){let r=rt(t.project);return e.version=r.version,e.meta=r.meta,e.canvasId=r.canvasId,e.selectedId=r.selectedId,e.root=r.root,e}throw new Error(`unknown op ${i}`)}function rn(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,r=JSON.parse(JSON.stringify(e));return yc(r,t),lo(r),He(r),r.version=i+1,Object.keys(e).forEach(n=>{delete e[n]}),Object.assign(e,r),e}function en(e){return e?{posX:e.centerX,posY:e.centerY,width:e.width,height:e.height}:{posX:0,posY:0,width:0,height:0}}import bc from"fengari";var{lua:f,lauxlib:ee,lualib:fo,to_luastring:Bi,to_jsstring:vc}=bc,Sc=f.LUA_TNIL,wc=f.LUA_TBOOLEAN,Ic=f.LUA_TNUMBER,xc=f.LUA_TSTRING,ho=f.LUA_TTABLE,Cc=f.LUA_TFUNCTION,nn=f.LUA_TUSERDATA,Re=f.LUA_OK,mo=new WeakMap,an=Symbol("luaTableEntries"),on={__scriptHostKey:!0};function M(e){return Bi(String(e))}function ht(e,t){mo.set(e,t)}function Ce(e){return mo.get(e)}var oi=class{constructor(t){this.value=t}};function le(e,t,i){if(i instanceof oi){f.lua_pushnumber(e,i.value);return}if(i==null){f.lua_pushnil(e);return}let r=typeof i;if(r==="boolean"){f.lua_pushboolean(e,i);return}if(r==="number"){Number.isInteger(i)&&Math.abs(i)<=2147483647?f.lua_pushinteger(e,i):f.lua_pushnumber(e,i);return}if(r==="string"){f.lua_pushstring(e,M(i));return}if(r==="function"){Ac(e,t,i);return}if(i&&i[an]){let n=i[an];f.lua_createtable(e,Array.isArray(i)?i.length:0,n.length);for(let[a,o]of n)le(e,t,a),le(e,t,o),f.lua_settable(e,-3);return}if(Array.isArray(i)){f.lua_createtable(e,i.length,0);for(let n=0;n<i.length;n++)le(e,t,i[n]),f.lua_rawseti(e,-2,n+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.__kind==="ServerSignal"){t.pushSignal(e,i);return}if(i&&(i.SetEase||i.Append)){t.pushTween(e,i);return}if(r==="object"){f.lua_createtable(e,0,Object.keys(i).length);for(let[n,a]of Object.entries(i))le(e,t,a),f.lua_setfield(e,-2,M(n));return}f.lua_pushnil(e)}function Z(e,t){if(f.lua_isnil(e,t)||f.lua_type(e,t)===f.LUA_TNONE)return"";if(!f.lua_isstring(e,t)&&f.lua_type(e,t)!==f.LUA_TNUMBER)return`lua_type=${f.lua_type(e,t)}`;let i=f.lua_tostring(e,t);return i==null?"":vc(i)}function Le(e,t){t=f.lua_absindex(e,t);let i=f.lua_type(e,t);if(i===nn)return Ce(f.lua_touserdata(e,t));if(i===ho){f.lua_pushlightuserdata(e,on),f.lua_rawget(e,t);let r=f.lua_type(e,-1)===nn?f.lua_touserdata(e,-1):null;return f.lua_pop(e,1),r?Ce(r):null}return null}function he(e,t,i){i=f.lua_absindex(e,i);let r=f.lua_type(e,i);if(r===Sc)return null;if(r===wc)return!!f.lua_toboolean(e,i);if(r===Ic)return f.lua_isinteger(e,i)?f.lua_tointeger(e,i):f.lua_tonumber(e,i);if(r===xc)return Z(e,i);if(r===nn){let n=f.lua_touserdata(e,i);return Ce(n)??n}if(r===Cc)return kc(e,t,i);if(r===ho){let n=Le(e,i);if(n)return n;let a=[];for(f.lua_pushnil(e);f.lua_next(e,i)!==0;){let l=he(e,t,-2),u=he(e,t,-1);a.push([l,u]),f.lua_pop(e,1)}let o=new Map(a.filter(([l])=>Number.isInteger(l)&&l>=1)),s=0;for(;o.has(s+1);)s+=1;let c=s>0?[]:{};for(let[l,u]of a)Array.isArray(c)&&Number.isInteger(l)&&l>=1?c[l-1]=u:(typeof l=="string"||typeof l=="number")&&(c[l]=u);return Object.defineProperty(c,an,{value:a}),c}return null}function kc(e,t,i){t.luaFunctions||(t.luaFunctions=new Map);let r=typeof f.lua_topointer=="function"?f.lua_topointer(e,i):null;if(r!=null&&t.luaFunctions.has(r))return t.luaFunctions.get(r);f.lua_pushvalue(e,i);let n=ee.luaL_ref(e,f.LUA_REGISTRYINDEX),a=Ec(e,t,n);return r!=null&&t.luaFunctions.set(r,a),a}function Ec(e,t,i){let r=(...n)=>{if(r.__luaRef==null)throw new Error("attempt to call a released Lua callback");let a=f.lua_gettop(e);f.lua_rawgeti(e,f.LUA_REGISTRYINDEX,r.__luaRef);for(let l of n)le(e,t,l);if(f.lua_pcall(e,n.length,f.LUA_MULTRET,0)!==Re){let l=Z(e,-1);throw f.lua_settop(e,a),new Error(l)}let s=f.lua_gettop(e)-a,c=[];for(let l=1;l<=s;l++)c.push(he(e,t,a+l));if(f.lua_settop(e,a),c.length!==0)return c.length===1?c[0]:c};return r.__luaRef=i,r.__luaState=e,r}function po(e){e?.__luaRef!=null&&(e.__luaHolds=(e.__luaHolds||0)+1)}function go(e,t){if(!t||t.__luaRef==null||!t.__luaState)return;if(t.__luaHolds>1){t.__luaHolds-=1;return}let i=t.__luaState;if((!e?.luaStates||e.luaStates.has(i))&&ee.luaL_unref(i,f.LUA_REGISTRYINDEX,t.__luaRef),t.__luaRef=null,t.__luaState=null,e?.luaFunctions)for(let[r,n]of e.luaFunctions)n===t&&e.luaFunctions.delete(r)}function Ac(e,t,i){f.lua_pushlightuserdata(e,i),f.lua_pushlightuserdata(e,t),f.lua_pushcclosure(e,function(n){let a=f.lua_touserdata(n,f.lua_upvalueindex(1)),o=f.lua_touserdata(n,f.lua_upvalueindex(2)),s=f.lua_gettop(n),c=[];for(let l=1;l<=s;l++)c.push(he(n,o,l));try{let l=a(...c);if(Array.isArray(l)&&l.__multi){for(let u of l)le(n,o,u);return l.length}return l===void 0?0:(le(n,o,l),1)}catch(l){return f.lua_pushstring(n,M(String(l&&l.message?l.message:l))),f.lua_error(n)}},2)}function yo(e){!e||typeof f.lua_close!="function"||f.lua_close(e)}function bo(e){if(ee.luaL_loadstring(e,M(["local nativeGetMetatable = getmetatable","getmetatable = function(value)",' if type(value) == "string" then return nil end'," return nativeGetMetatable(value)","end"].join(`
|
|
108
|
+
`)))===Re&&f.lua_pcall(e,0,0,0),f.lua_settop(e,0),f.lua_pushnil(e),f.lua_setglobal(e,M("_VERSION")),f.lua_getglobal(e,M("string")),!f.lua_isnil(e,-1))for(let i of["dump","pack","unpack"])f.lua_pushnil(e),f.lua_setfield(e,-2,M(i));if(f.lua_pop(e,1),f.lua_pushnil(e),f.lua_setglobal(e,M("io")),f.lua_getglobal(e,M("os")),!f.lua_isnil(e,-1))for(let i of Object.keys({execute:1,getenv:1,remove:1,rename:1,tmpname:1,setlocale:1,exit:1}))f.lua_pushnil(e),f.lua_setfield(e,-2,M(i));f.lua_pop(e,1),f.lua_getglobal(e,M("debug")),f.lua_isnil(e,-1)?f.lua_pop(e,1):(f.lua_getfield(e,-1,M("traceback")),f.lua_newtable(e),f.lua_pushvalue(e,-2),f.lua_setfield(e,-2,M("traceback")),f.lua_setglobal(e,M("debug")),f.lua_pop(e,2)),f.lua_getglobal(e,M("math")),f.lua_isnil(e,-1)||(f.lua_pushcfunction(e,i=>{let r=f.lua_tonumber(i,1);return f.lua_pushboolean(i,Number.isNaN(r)),1}),f.lua_setfield(e,-2,M("isnan")),f.lua_pushcfunction(e,i=>{let r=f.lua_tonumber(i,1);return f.lua_pushboolean(i,r===1/0||r===-1/0),1}),f.lua_setfield(e,-2,M("isinf"))),f.lua_pop(e,1),f.lua_pushnil(e),f.lua_setglobal(e,M("package")),f.lua_pushnil(e),f.lua_setglobal(e,M("load")),f.lua_pushnil(e),f.lua_setglobal(e,M("loadfile")),f.lua_pushnil(e),f.lua_setglobal(e,M("dofile")),f.lua_pushnil(e),f.lua_setglobal(e,M("collectgarbage")),f.lua_pushnil(e),f.lua_setglobal(e,M("coroutine")),f.lua_pushnil(e),f.lua_setglobal(e,M("fengari"))}var Ae=(e,t=0)=>Number.isFinite(Number(e))?Number(e):t,vo=e=>e?.Name||e,ji=e=>Math.max(0,Math.min(1,Ae(e)));function si(e){let t=e.parent?si(e.parent):[e.runtime.canvasWidth,e.runtime.canvasHeight];return[Math.max(0,(e.anchorMaxX-e.anchorMinX)*t[0]+Ae(e.sizeDeltaX)),Math.max(0,(e.anchorMaxY-e.anchorMinY)*t[1]+Ae(e.sizeDeltaY))]}function li(e){let[t,i]=si(e),r=vo(e.scrollDirection)==="Horizontal",n=Math.max(1,Ae(e.cellSizeX,50)),a=Math.max(1,Ae(e.cellSizeY,50)),o=Math.max(0,Ae(e.spacingX)),s=Math.max(0,Ae(e.spacingY)),c=Math.max(0,Ae(e.padding1X)),l=Math.max(0,Ae(e.padding1Y)),u=Math.max(0,Ae(e.padding2X)),d=Math.max(0,Ae(e.padding2Y)),h=r?i-l-d:t-c-u,p=r?a:n,m=r?s:o,g=vo(e.layoutConstraint)==="Fixed"?Math.max(1,Math.floor(Ae(e.layoutConstraintFixedCount,1))):Math.max(1,Math.floor((h+m)/(p+m))),S=Math.ceil(e.itemCount/g),C=S?r?c+u+S*n+(S-1)*o:l+d+S*a+(S-1)*s:0,I=r?t:i,P=Math.max(0,C-I);return{width:t,height:i,horizontal:r,cellW:n,cellH:a,gapX:o,gapY:s,left:c,top:l,right:u,bottom:d,lanes:g,length:C,viewport:I,max:P,offset:ji(e.scrollProgress)*P}}function Ot(e){let t=li(e);for(let i=0;i<(e._gridItems?.length||0);i+=1){let r=e._gridItems[i];if(!r.alive||r.parent!==e)continue;let n=Math.floor(i/t.lanes),a=i%t.lanes,o=t.horizontal?n:a,s=t.horizontal?a:n,c=t.left+o*(t.cellW+t.gapX)+t.cellW/2-(t.horizontal?t.offset:0),l=-t.top-s*(t.cellH+t.gapY)-t.cellH/2+(t.horizontal?0:t.offset),u={anchorMinX:0,anchorMaxX:0,anchorMinY:1,anchorMaxY:1,pivotX:.5,pivotY:.5,sizeDeltaX:t.cellW,sizeDeltaY:t.cellH,anchoredPositionX:c,anchoredPositionY:l};Object.entries(u).some(([d,h])=>r[d]!==h)&&(Object.assign(r,u),r.markPlayDirty(!0))}return t}var So={container:"ClientUIContainerControl",textbox:"ClientUITextBoxControl",textwindow:"ClientUITextWindowControl",image:"ClientUIImageControl",button:"ClientUIPresetButtonControl",cursor:"ClientUICursorEventAreaControl",grid:"ClientUIGridScrollerControl",keyhint:"ClientUIKeyHintControl",animation:"ClientUIAnimationControl",fullscreen:"ClientUIFullscreenAnimationControl",reference:"ClientUIReferenceControl"},_c=["alive","Id","prefabIndex","active","activeInHierarchy","visible"],Hi=new Set(["active","visible","parent","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]),Pc=["name","parent","anchoredPositionX","anchoredPositionY","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY","localScaleX","localScaleY","localScaleZ","localRotationX","localRotationY","localRotationZ","canControllerFocus"],Tc={image:["imageSource","imageId"],grid:["itemCount","scrollDirection","layoutConstraint","layoutConstraintFixedCount"],reference:["referencedPrefabIndex"]},Rc={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"]},Mc=["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"],wo=["AddCursorEventListener","RemoveCursorEventListener","RemoveCursorEventListeners","RemoveAllCursorEventListeners","SimulateCursorClick"],Nc={image:["SetImage","SetSoftEdgeWidth","SetFillUnused","SetFillHorizontal","SetFillVertical","SetFillRadial90","SetFillRadial180","SetFillRadial360"],button:wo,cursor:wo,animation:["PlayAnimation","StopAnimation"],grid:["RefreshItems","GetItemIndex","GetItemSize","GetItemSpacing","GetPadding","ScrollToItemAt","GetContentLength"]};function ln(e,t){return e.kind==="image"&&t==="imageType"&&e.runtime.canSelectImageType(e.imageId,e.imageSource)?"rw":_c.includes(t)||(Tc[e.kind]||[]).includes(t)?"ro":Pc.includes(t)||(Rc[e.kind]||[]).includes(t)?"rw":null}var Oc=["localRotationX","localRotationY","localRotationZ"],Ft=Math.PI/180;function Io(e,t){return[e[3]*t[0]+e[0]*t[3]+e[1]*t[2]-e[2]*t[1],e[3]*t[1]-e[0]*t[2]+e[1]*t[3]+e[2]*t[0],e[3]*t[2]+e[0]*t[1]-e[1]*t[0]+e[2]*t[3],e[3]*t[3]-e[0]*t[0]-e[1]*t[1]-e[2]*t[2]]}function sn(e){if(Object.is(e,-0))return e;let t=(e%360+360)%360,i=Math.round(t*1e6)/1e6;return i>=360?0:i}function xo(e,t,i){let r=I=>[Math.sin(I*Ft/2),Math.cos(I*Ft/2)],[n,a]=r(e),[o,s]=r(t),[c,l]=r(i),[u,d,h,p]=Io(Io([0,o,0,s],[n,0,0,a]),[0,0,c,l]),m=Math.max(-1,Math.min(1,-2*(d*h-p*u))),g,S,C;return Math.abs(m)>.999999?(g=Math.sign(m)*90,S=2*Math.atan2(d,p)/Ft,C=0):(g=Math.asin(m)/Ft,S=Math.atan2(2*(p*d+u*h),1-2*(u*u+d*d))/Ft,C=Math.atan2(2*(p*h+u*d),1-2*(u*u+h*h))/Ft),[sn(g),sn(S),sn(C)]}function Co(e,t){return Mc.includes(t)||(Nc[e.kind]||[]).includes(t)}var Fc={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}},nt=class e{constructor(t,i){this.runtime=t,this.kind=i.kind||"container",this.typeofName=So[this.kind]||So.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,(this.kind==="grid"||this.kind==="textwindow")&&(this.runtime.scrollControls||=new Set,this.runtime.scrollControls.add(this));let r=Fc[this.kind]||{};for(let[n,a]of Object.entries(r))this[n]===void 0&&(this[n]=i[n]!==void 0?i[n]:a);if(this.kind==="grid"&&(this.scrollProgress=i.scrollProgress??0),i.children)for(let n of i.children){let a=n instanceof e?n:new e(t,n);this.addChild(a)}}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 r=t;r;r=r._parent)if(r===this)throw new Error("cannot parent a control to itself or its descendant");let i=this._parent;if(i){let r=i.children.indexOf(this);r>=0&&i.children.splice(r,1),i.markPlayDirty(!0)}else{let r=this.runtime.roots.indexOf(this);r>=0&&this.runtime.roots.splice(r,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}get scrollProgress(){return this._scrollProgress??0}set scrollProgress(t){if(typeof t!="number"||!Number.isFinite(t))throw new Error("scrollProgress must be a finite number");this._scrollProgress=ji(t),this.markPlayDirty()}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),r=this;for(let n of i)if(r=r.GetChild(n),!r)return null;return r}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,r=i.indexOf(this);if(r<0)return!1;let n=i.length-1;return!Number.isInteger(t)||t<0||t>n?!1:(i.splice(r,1),i.splice(n-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,r){this.localScaleX=t,this.localScaleY=i,this.localScaleZ=r,this.markPlayDirty()}GetLocalRotation(){return xo(this.localRotationX,this.localRotationY,this.localRotationZ)}luaFieldValue(t){if(t==="imageType")return this.imageType??"Stretch";let i=Oc.indexOf(t);return i<0?this[t]:xo(this.localRotationX,this.localRotationY,this.localRotationZ)[i]}SetLocalRotation(t,i,r){this.localRotationX=t,this.localRotationY=i,this.localRotationZ=r,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,r){let n=t.get(i)||[];n.push(r),t.set(i,n),this.runtime.retainLuaCallback?.(r)}_removeListener(t,i,r){let n=t.get(i);if(!n)return;let a=n.filter(o=>o!==r);t.set(i,a);for(let o=a.length;o<n.length;o++)this.runtime.unrefLuaCallback?.(r)}_removeListeners(t,i){let r=t.get(i)||[];for(let n of r)this.runtime.unrefLuaCallback?.(n);t.delete(i)}_removeAllListeners(t){for(let i of t.values())for(let r of i)this.runtime.unrefLuaCallback?.(r);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 r=this.cursorListeners.get(t)||[];for(let n of r)n(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 r of i)if(r()===!0)return!0;return!1}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,r){this.navConfig.set(t,{mode:i,target:r})}GetControllerNavigation(t){let i=this.navConfig.get(t),r=i?[i.mode,i.target]:[null,null];return r.__multi=!0,r}SetImage(t,i){let r=this.imageSource?.Name||this.imageSource,n=t?.Name||t;(i!==this.imageId||r!==n)&&(this.imageType=null),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(t,i){if(!Number.isInteger(t)||t<0||t>2e3)throw new Error("RefreshItems: simulator supports 0..2000 items");if(typeof i!="function")throw new Error("RefreshItems: callback must be a function");if(!this.alive||this._refreshingGrid)throw new Error("RefreshItems: destroyed control or recursive refresh");if(t&&!this.runtime.templates.has(Number(this.itemPrefabIndex)))throw new Error("RefreshItems: item template not found");if(t&&["OnInit","OnDestroy"].includes(this.runtime.lifecyclePhase))throw new Error("RefreshItems: items cannot be created during OnInit/OnDestroy");this._refreshingGrid=!0;try{this._gridItems||=[];let r=[];for(let n of this._gridItems)n.alive&&n.parent===this&&n.prefabIndex===Number(this.itemPrefabIndex)&&r.length<t?r.push(n):n.alive&&n.parent===this&&this.runtime.destroyControl(n);for(this._gridItems=r;r.length<t;){let n=this.runtime.instantiate(this.itemPrefabIndex,this,this.runtime.lifecyclePhase);if(!n)throw new Error("RefreshItems: could not instantiate item");r.push(n),n.SetActive(!0)}this.itemCount=t,Ot(this),this.markPlayDirty(!0);for(let n=0;n<r.length&&this.alive;n+=1)i(r[n],n)}finally{this._refreshingGrid=!1}}GetItemIndex(t){return t?.alive&&t.parent===this?this._gridItems?.indexOf(t)??-1:-1}GetItemSize(){return[this.cellSizeX,this.cellSizeY]}GetItemSpacing(){return[this.spacingX,this.spacingY]}GetPadding(){return[this.padding1Y,this.padding2Y,this.padding1X,this.padding2X]}ScrollToItemAt(t,i){if(!Number.isInteger(t)||t<0||t>=this.itemCount)throw new Error("ScrollToItemAt: item index out of range");let r=li(this),n=r.horizontal?r.cellW:r.cellH,a=r.horizontal?r.gapX:r.gapY,o=(r.horizontal?r.left:r.top)+Math.floor(t/r.lanes)*(n+a),s=i?.Name||i;if(!["Top","Center","Bottom"].includes(s))throw new Error("ScrollToItemAt: invalid alignment");let c=o-(s==="Center"?(r.viewport-n)/2:s==="Bottom"?r.viewport-n:0);this.scrollProgress=r.max?ji(c/r.max):0,Ot(this),this.markPlayDirty(!0)}GetContentLength(){return li(this).length}};function Ge(e,t){t(e);for(let i of e.children)Ge(i,t)}function cn(e,t=[],i=""){t.push(`${i}${e.name||"(unnamed)"} [${e.typeofName}] Id=${e.Id}`);for(let r of e.children)cn(r,t,i+" ");return t}function Ui(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 ko={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-Ui(1-e),OutBounce:Ui,InOutBounce:e=>e<.5?(1-Ui(1-2*e))/2:(1+Ui(2*e-1))/2};function Eo(e,t){let i=ko[e]||ko.Linear;return t<=0?0:t>=1?1:i(t)}function Dt(e,t,i,r=255){let n=Li(e),a=Li(t),o=Li(i);return((r==null?255:Li(r))<<24|n<<16|a<<8|o)>>>0}function ci(e){let t=e>>>0;return[t>>>16&255,t>>>8&255,t&255,t>>>24&255]}function Li(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(255,Math.trunc(t))):0}function Ao(e,t,i){let r=ci(e),n=ci(t);return Dt(r[0]+(n[0]-r[0])*i,r[1]+(n[1]-r[1])*i,r[2]+(n[2]-r[2])*i,r[3]+(n[3]-r[3])*i)}var Dc=new Set(["fontColor","bgColor","outlineColor","imageColor"]),zc=new Set(["fontSize","minimumFontSize"]),un=1e-9;function $c(e,t){return typeof e?.luaFieldValue=="function"?e.luaFieldValue(t):e[t]}var ui=class{constructor(t,i,r,n){this.runtime=t,this.object=i,this.data={...r},this.duration=Math.max(0,Number(n)||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,this.dead=!1,this.completed=!1}capture(){this.from={},this.to={};for(let[t,i]of Object.entries(this.data)){let r=$c(this.object,t);this.from[t]=r,this.to[t]=this.relative?Number(r)+Number(i):i}}restoreInitial(){this.from={...this.initialFrom},this.to={...this.initialTo}}SetEase(t){return this.easeName=typeof t=="string"?t:t?.Name||"Linear",this}SetRelative(t){return this.relative=!!t,this}Play(){return this.dead?this:this.playing?(this.paused=!1,this):this._start(!1)}_begin(t){this.playing=!0,this.paused=!1,this.elapsed=0,this.loopIndex=0,this.killed=!1,this.completed=!1,t&&this.initialFrom?this.restoreInitial():(this.capture(),this.initialFrom={...this.from},this.initialTo={...this.to})}_start(t){return this._begin(t),this.runtime.tweens.add(this),this.runtime.animations.add(this),this}get loopCount(){return this.loops>0?this.loops:1}Pause(){this.paused=!0}Resume(){this.paused=!1}Restart(){return this.dead?this:this._start(!0)}Complete(){this.dead||this.completed||(this.initialFrom||this._begin(!1),this.apply(1),this.finish(!0))}Kill(t){t?this.Complete():this.finish(!1),this.dead=!0}SetOnComplete(t){return this.onComplete=t,this}SetOnStepComplete(t){return this.onStepComplete=t,this}SetLoops(t){return this.loops=t,this}apply(t){if(this.object?.alive===!1)return;let i=Eo(this.easeName,t),r=!1,n=!1;for(let a of Object.keys(this.to)){let o=this.from[a],s=this.to[a];if(Dc.has(a)&&typeof o=="number"&&typeof s=="number")this.object[a]=Ao(o,s,i);else if(typeof o=="number"&&typeof s=="number"){let c=o+(s-o)*i;this.object[a]=zc.has(a)?Math.trunc(c):c}else this.object[a]=i>=1?s:o;r=!0,Hi.has(a)&&(n=!0)}r&&typeof this.object?.markPlayDirty=="function"&&this.object.markPlayDirty(n)}_advance(t,i){this.elapsed+=t;let r=this.duration<=0?1:Math.min(1,this.elapsed/this.duration);return this.apply(r),r<1?!1:i>=0&&this.loopIndex+1>=i?!0:(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.loopIndex++,this.elapsed=0,this.restoreInitial(),!1)}step(t){!this.playing||this.paused||this.killed||this._advance(t,this.loops<0?-1:this.loopCount)&&(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.finish(!0))}finish(t){this.playing=!1,this.killed=!0,t&&(this.completed=!0),this.runtime.tweens.delete(this),this.runtime.animations.delete(this),t&&this.onComplete&&this.runtime.safeCall(this.onComplete)}},zt=class{constructor(t){this.runtime=t,this.steps=[],this.playing=!1,this.paused=!1,this.killed=!1,this.dead=!1,this.completed=!1,this.elapsed=0,this.loops=1,this.loopIndex=0,this.onComplete=null,this.onStepComplete=null,this._entries=null}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.dead?this:this.playing?(this.paused=!1,this):this._play()}_play(){return this.playing=!0,this.paused=!1,this.killed=!1,this.completed=!1,this.elapsed=0,this.loopIndex=0,this._schedule(),this.runtime.sequences.add(this),this.runtime.animations.add(this),this}_schedule(){let t=0,i=0,r=!1,n=[],a=o=>o.duration*o.loopCount;for(let o of this.steps)if(o.kind==="tween"&&o.parallel){let s=r?i:t;n.push({at:s,tween:o.tween}),t=Math.max(t,s+a(o.tween))}else o.kind==="tween"?(n.push({at:t,tween:o.tween}),i=t,r=!0,t+=a(o.tween)):o.kind==="interval"?(i=t,r=!0,t+=o.duration):o.kind==="callback"?n.push({at:t,fn:o.fn}):o.kind==="insert"?(n.push({at:o.time,tween:o.tween}),t=Math.max(t,o.time+a(o.tween))):o.kind==="insertCb"&&(n.push({at:o.time,fn:o.fn}),t=Math.max(t,o.time));this._entries=n.map((o,s)=>({...o,index:s,end:o.tween?o.at+a(o.tween):o.at})),this._end=t,this._resetEntries()}_resetEntries(){for(let t of this._entries)t.started=!1,t.done=!1}_startChild(t){t.started=!0,t.tween._begin(!!t.tween.initialFrom)}_finishChild(t){t.done=!0,t.tween.apply(1),t.tween.onStepComplete&&this.runtime.safeCall(t.tween.onStepComplete),t.tween.finish(!0)}_advanceTo(t,i){let r=this._entries,n=[];for(let o of r)!o.started&&o.at<=t+un&&n.push({at:o.at,rank:o.fn?1:2,entry:o}),o.tween&&!o.done&&o.end<=t+un&&n.push({at:o.end,rank:0,entry:o});n.sort((o,s)=>o.at-s.at||o.rank-s.rank||o.entry.index-s.entry.index);let a=new Set;for(let{rank:o,entry:s}of n)if(o===1){if(s.started=!0,this.runtime.safeCall(s.fn),!this.playing||this.killed||this._entries!==r)return!1}else s.started||(this._startChild(s),a.add(s)),o===0&&!s.done&&this._finishChild(s);for(let o of r)!o.tween||!o.started||o.done||(a.has(o)?o.tween._advance(t-o.at,o.tween.loopCount):o.tween._advance(i,o.tween.loopCount));return!0}step(t){!this.playing||this.paused||this.killed||(this.elapsed+=t,this._advanceTo(this.elapsed,t)&&(this.elapsed+un<this._end||(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.loopIndex++,this.loops<0||this.loopIndex<this.loops?(this.elapsed=0,this._resetEntries()):this.finish(!0))))}Pause(){this.paused=!0}Resume(){this.paused=!1}Restart(){this.dead||this._play()}Complete(){this.dead||this.completed||(this._entries||this._schedule(),this.playing=!0,this.killed=!1,this._advanceTo(1/0,0)&&(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.finish(!0)))}Kill(t){t?this.Complete():this.finish(!1),this.dead=!0}SetOnComplete(t){return this.onComplete=t,this}SetOnStepComplete(t){return this.onStepComplete=t,this}SetLoops(t){return this.loops=t,this}finish(t){this.playing=!1,this.killed=!0,t&&(this.completed=!0),this.runtime.sequences.delete(this),this.runtime.animations.delete(this),t&&this.onComplete&&this.runtime.safeCall(this.onComplete)}};var Xi={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"]},Gc=[...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"],Vc=[...Array.from({length:14},(e,t)=>`CraftspersonKey${t+1}`),"SprintKey","JumpKey","InteractKey","NormalAttackKey","CharacterSkill1Key","CharacterSkill2Key","CharacterSkill3Key","CharacterSkill4Key","MenuConfirmKey","MenuBackKey","None"];function Yc(){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}Xi.KeyboardKeyCode=Gc;Xi.ControllerKeyCode=Vc;Xi.KeyEventType=Yc();var _o=new Map;function mt(e,t){let i=`${e}\0${t}`,r=_o.get(i);return r||(r={__kind:"EnumItem",Name:t,FullName:`Enum.${e}.${t}`,EnumType:e},_o.set(i,r)),r}function fn(e,t){return t==null?t:t.__kind==="EnumItem"?mt(t.EnumType||e,t.Name):typeof t=="string"&&t?mt(e,t):t}function dn(){let e={};for(let[t,i]of Object.entries(Xi)){let r={};for(let n of i)r[n]=mt(t,n);e[t]=r}return e}var Bc=new Set(["Id","prefabIndex","imageId","fontSize","minimumFontSize","clickAudioId","itemCount","itemPrefabIndex","animationId","referencedPrefabIndex"]),jc=new Set(["imageColor","fontColor","bgColor","outlineColor"]),Po={horizontalAlignment:"TextHorizontalAlignment",verticalAlignment:"TextVerticalAlignment",imageSource:"ImageSource",imageType:"ImageType",fillType:"ImageFillType",fillHorizontalType:"ImageFillHorizontalType",fillVerticalType:"ImageFillVerticalType",fillRadial90Type:"ImageFillRadial90Type",fillRadialType:"ImageFillRadialType",softEdgeMode:"ImageMaskSoftEdgeMode",layer:"UIAnimationLayer",scrollDirection:"ScrollDirection",layoutConstraint:"ScrollLayoutConstraint"},pt=f.LUA_REGISTRYINDEX,To=f.LUA_MULTRET,Hc=Object.freeze({InstantiateClientUIControl:2,DestroyClientUIControl:1,GetClientUIControl:1,FindClientUIRoot:1,GetClientUIRoots:0,GetUICanvasSize:0,GetCursorUIPos:0,GetDevice:0,SetControllerFocus:1,GetControllerFocus:0,GetControllerLeftStickAxis:0,GetControllerRightStickAxis:0,Tween:3,TweenSequence:0,ServerSignal:1,GetGlobalCustomVariableValue:2,PauseLevelTime:1,IsLevelTimePaused:0,PlayAudio2D:1,StopAudio:1,IsAudioAlive:1,GetLanguageType:0,GetStageMode:0,IsTestPlay:0,GetText:1,PrintClientUITree:0});function be(e){return e==null?"":typeof e=="string"?e:e.Name||e.FullName||String(e)}var Wi=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.canSelectImageType=t.canSelectImageType||(()=>!1),this.clock={time:0,levelTime:0,paused:!1,frame:0},this.logs=[],this.mountErrors=[],this.tweens=new Set,this.sequences=new Set,this.animations=new Set,this.audios=new Map,this.nextAudioId=1,this.audioDuration=t.audioDuration||(()=>null),this.audioHistory=[],this.audioWarnings=new Set,this.audioRevision=0,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=dn(),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 r=this._nextScriptMappingId;return this._nextScriptMappingId+=1,r}pushPackedColor(t,i){let r=i>>>0;(r|0)===r?f.lua_pushinteger(t,r):f.lua_pushnumber(t,r)}retainLuaCallback(t){po(t)}unrefLuaCallback(t){go(this,t)}log(t,...i){let r=i.map(n=>n==null?"nil":typeof n=="object"&&n!==null&&n.__kind==="EnumItem"?n.Name:String(n)).join(" ");this.logs.push({level:t,text:r,time:this.clock.time})}safeCall(t,...i){try{return t(...i)}catch(r){this.log("lua-error",r&&r.message?r.message:String(r))}}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 r=this.normalizeRequirePath(t);this.scriptFiles.set(r,i),r.startsWith("default_import_file/")||this.requireAliases.set(`default_import_file/${r}`,r)}normalizeRequirePath(t){let i=String(t).replace(/\\/g,"/");return i.endsWith(".lua")&&(i=i.slice(0,-4)),i}addRoot(t){let i=t instanceof nt?t:new nt(this,t);return this.roots.push(i),Ge(i,r=>this.controlsById.set(r.Id,r)),this.mountSpecScripts(t,i),i}mountSpecScripts(t,i){if(t instanceof nt)return;let r=a=>(a.scripts?.length||0)>0||(a.children||[]).some(r);if(!t||!r(t))return;let n=this.lifecyclePhase;try{let a=(o,s)=>{for(let l of o.scripts||[])try{this.mountScript({path:l.path,source:l.source,control:s,scriptMappingId:l.scriptMappingId})}catch(u){let d=u&&u.message?u.message:String(u);this.mountErrors.push(d),this.log("lua-error",d)}let c=o.children||[];for(let l=0;l<c.length;l+=1)a(c[l],s?.children?.[l])};a(t,i)}finally{this.lifecyclePhase=n}}makeCursorEventData({x:t=0,y:i=0,pressX:r=t,pressY:n=i,deltaX:a=t-r,deltaY:o=i-n,dragging:s=!1,touchId:c=-1}={}){let l=this;return{__kind:"CursorEventData",typeofName:"CursorEventData",dragging:s,touchId:c,x:t,y:i,pressX:r,pressY:n,GetUIPos(){return[t,i]},GetPressUIPos(){return[r,n]},GetUIPosDelta(){return[a,o]}}}boot(){let t=this.newLuaThread();this.L=t}installGlobals(t){let i=this;f.lua_pushcfunction(t,r=>{let n=f.lua_gettop(r),a=[];for(let o=1;o<=n;o++)a.push(he(r,i,o));return i.log("info",...a),0}),f.lua_setglobal(t,M("print")),f.lua_pushcfunction(t,r=>{let n=f.lua_gettop(r),a=[];for(let o=1;o<=n;o++)a.push(he(r,i,o));return i.log("error",...a),0}),f.lua_setglobal(t,M("printerr")),f.lua_pushcfunction(t,r=>{if(f.lua_type(r,1)===f.LUA_TTABLE&&!Le(r,1))return f.lua_pushstring(r,M("table")),1;let n=he(r,i,1);return f.lua_pushstring(r,M(i.typeofOf(n))),1}),f.lua_setglobal(t,M("typeof")),this.pushColorLib(t),this.pushEnumLib(t),this.pushGameLib(t),f.lua_pushcfunction(t,r=>i.luaRequire(r)),f.lua_setglobal(t,M("require"))}typeofOf(t){return t==null?"nil":t.__kind==="Script"?"Script":t.__kind==="EnumItem"?"EnumItem":t.__kind==="CursorEventData"?"CursorEventData":t.__kind==="ServerSignal"?"ServerSignal":t instanceof zt?"TweenSequence":t instanceof ui?"Tween":t.typeofName?t.typeofName:typeof t=="number"?"number":typeof t=="string"?"string":typeof t=="boolean"?"boolean":typeof t}pushColorLib(t){f.lua_newtable(t),f.lua_pushcfunction(t,i=>(this.pushPackedColor(i,Dt(f.lua_tonumber(i,1),f.lua_tonumber(i,2),f.lua_tonumber(i,3),255)),1)),f.lua_setfield(t,-2,M("FromRGB")),f.lua_pushcfunction(t,i=>{let r=f.lua_isnoneornil(i,4)?255:f.lua_tonumber(i,4);return this.pushPackedColor(i,Dt(f.lua_tonumber(i,1),f.lua_tonumber(i,2),f.lua_tonumber(i,3),r)),1}),f.lua_setfield(t,-2,M("FromRGBA")),f.lua_pushcfunction(t,i=>{let r=f.lua_tonumber(i,1)>>>0;for(let n of ci(r))f.lua_pushinteger(i,n);return 4}),f.lua_setfield(t,-2,M("ToRGBA")),f.lua_newtable(t),f.lua_pushcfunction(t,i=>{let r=f.lua_tonumber(i,2),n=f.lua_tonumber(i,3),a=f.lua_tonumber(i,4),o=f.lua_isnoneornil(i,5)?255:f.lua_tonumber(i,5);return this.pushPackedColor(i,Dt(r,n,a,o)),1}),f.lua_setfield(t,-2,M("__call")),f.lua_setmetatable(t,-2),f.lua_setglobal(t,M("Color"))}pushEnumLib(t){f.lua_newtable(t);for(let[i,r]of Object.entries(this.enumTree)){f.lua_newtable(t);for(let[n,a]of Object.entries(r))this.pushEnumItem(t,a),f.lua_setfield(t,-2,M(n));f.lua_setfield(t,-2,M(i))}f.lua_setglobal(t,M("Enum"))}pushEnumItem(t,i){let r=f.lua_newuserdata(t,0);ht(r,i),ee.luaL_setmetatable(t,M("EnumItem"))}pushControl(t,i){let r=f.lua_newuserdata(t,0);ht(r,i),ee.luaL_setmetatable(t,M("Control"))}pushScript(t,i){f.lua_newtable(t),f.lua_pushlightuserdata(t,on);let r=f.lua_newuserdata(t,0);ht(r,i),f.lua_rawset(t,-3),ee.luaL_getmetatable(t,M("Script")),f.lua_setmetatable(t,-2)}pushTween(t,i){let r=f.lua_newuserdata(t,0);ht(r,i);let n=i instanceof zt?"TweenSequence":"Tween";ee.luaL_setmetatable(t,M(n))}pushSignal(t,i){let r=f.lua_newuserdata(t,0);ht(r,i),ee.luaL_setmetatable(t,M("ServerSignal"))}pushCursor(t,i){let r=f.lua_newuserdata(t,0);ht(r,i),ee.luaL_setmetatable(t,M("CursorEventData"))}pushGameLib(t){let i=this;f.lua_newtable(t);let r={InstantiateClientUIControl:n=>{let a=f.lua_tointeger(n,1),o=Ce(f.lua_touserdata(n,2)),s=i.instantiate(a,o,i.lifecyclePhase);return s?(i.pushControl(n,s),1):(f.lua_pushnil(n),1)},DestroyClientUIControl:n=>{let a=Ce(f.lua_touserdata(n,1));return a&&i.destroyControl(a),0},GetClientUIControl:n=>{let a=f.lua_tointeger(n,1),o=i.controlsById.get(a);return o?i.pushControl(n,o):f.lua_pushnil(n),1},FindClientUIRoot:n=>{let a=Z(n,1),o=i.roots.find(s=>s.name===a);return o?i.pushControl(n,o):f.lua_pushnil(n),1},GetClientUIRoots:n=>(f.lua_createtable(n,i.roots.length,0),i.roots.forEach((a,o)=>{i.pushControl(n,a),f.lua_rawseti(n,-2,o+1)}),1),GetUICanvasSize:n=>(f.lua_pushnumber(n,i.canvasWidth),f.lua_pushnumber(n,i.canvasHeight),2),GetCursorUIPos:n=>(f.lua_pushnumber(n,i.cursor.x),f.lua_pushnumber(n,i.cursor.y),2),GetDevice:n=>(i.pushEnumItem(n,mt("Device",i.device)),1),SetControllerFocus:n=>(i.focus=Ce(f.lua_touserdata(n,1)),0),GetControllerFocus:n=>(i.focus?i.pushControl(n,i.focus):f.lua_pushnil(n),1),GetControllerLeftStickAxis:n=>(f.lua_pushnumber(n,i.stick.left[0]),f.lua_pushnumber(n,i.stick.left[1]),2),GetControllerRightStickAxis:n=>(f.lua_pushnumber(n,i.stick.right[0]),f.lua_pushnumber(n,i.stick.right[1]),2),Tween:n=>{let a=Ce(f.lua_touserdata(n,1))||he(n,i,1),o=he(n,i,2)||{},s=f.lua_tonumber(n,3),c=new ui(i,a,o,s);return i.pushTween(n,c),1},TweenSequence:n=>(i.pushTween(n,new zt(i)),1),ServerSignal:n=>{let a=Z(n,1);return i.pushSignal(n,i.makeServerSignal(a)),1},GetGlobalCustomVariableValue:n=>{let a=be(he(n,i,1)),o=Z(n,2);return le(n,i,i.getVar(a,o)),1},PauseLevelTime:n=>(i.clock.paused=!!f.lua_toboolean(n,1),0),IsLevelTimePaused:n=>(f.lua_pushboolean(n,i.clock.paused),1),PlayAudio2D:n=>{let a=i.playAudio(i.audioInteger(n));return f.lua_pushinteger(n,a),1},StopAudio:n=>(i.stopAudio(i.audioInteger(n)),0),IsAudioAlive:n=>{let a=i.audios.get(i.audioInteger(n));return f.lua_pushboolean(n,!!(a&&a.alive)),1},GetLanguageType:n=>(i.pushEnumItem(n,mt("LanguageType",i.language)),1),GetStageMode:n=>(i.pushEnumItem(n,mt("StageMode",i.stageMode)),1),IsTestPlay:n=>(f.lua_pushboolean(n,i.testPlay),1),GetText:n=>{let a=Z(n,1);return f.lua_pushstring(n,M(a)),1},PrintClientUITree:n=>{for(let a of i.roots)i.log("info",cn(a).join(`
|
|
109
|
+
`));return 0}};for(let[n,a]of Object.entries(r)){let o=Hc[n];if(o===void 0)throw new Error(`missing game arity for ${n}`);f.lua_pushcfunction(t,s=>{let c=f.lua_gettop(s);return c!==o?ee.luaL_error(s,M(`bad argument count to '${n}' (${o} expected, got ${c})`)):a(s)}),f.lua_setfield(t,-2,M(n))}f.lua_setglobal(t,M("game"))}makeServerSignal(t){let i=[],r=this;return{__kind:"ServerSignal",name:t,AddParam(n,a){i.push({type:be(n),value:a})},AddInt(n){i.push({type:"Int",value:n})},AddIntList(n){i.push({type:"IntList",value:n})},AddFloat(n){i.push({type:"Float",value:n})},AddFloatList(n){i.push({type:"FloatList",value:n})},AddString(n){i.push({type:"String",value:n})},AddStringList(n){i.push({type:"StringList",value:n})},AddVector3(n){i.push({type:"Vector3",value:n})},AddVector3List(n){i.push({type:"Vector3List",value:n})},AddBool(n){i.push({type:"Bool",value:n})},AddBoolList(n){i.push({type:"BoolList",value:n})},AddGuid(n){i.push({type:"Guid",value:n})},AddGuidList(n){i.push({type:"GuidList",value:n})},AddEntity(n){i.push({type:"Entity",value:n})},AddEntityList(n){i.push({type:"EntityList",value:n})},AddPrefabId(n){i.push({type:"PrefabId",value:n})},AddPrefabIdList(n){i.push({type:"PrefabIdList",value:n})},AddConfigId(n){i.push({type:"ConfigId",value:n})},AddConfigIdList(n){i.push({type:"ConfigIdList",value:n})},SendSignal(){let n=i.slice();r.serverBridge&&typeof r.serverBridge.receiveFromClient=="function"&&r.serverBridge.receiveFromClient(t,n)}}}audioInteger(t){let i=f.lua_tonumber(t,1);return f.lua_type(t,1)!==f.LUA_TNUMBER||!Number.isSafeInteger(i)?ee.luaL_error(t,M("audio argument must be an integer")):i}playAudio(t){this.audioRevision++;let i=this.nextAudioId++,r=this.audioDuration(t),n=Number.isFinite(r)&&r>0,a={instanceId:i,audioId:t,startedAt:this.clock.time,duration:n?r:0,alive:n,stopped:!1};return this.audioHistory.push(a),this.audioHistory.length>128&&this.audioHistory.shift(),n?(this.audios.size>=128&&this.stopAudio(this.audios.keys().next().value),this.audios.set(i,a)):this.audioWarnings.has(t)||(this.audioWarnings.size>=128&&this.audioWarnings.delete(this.audioWarnings.values().next().value),this.audioWarnings.add(t),this.log("warn",`\u97F3\u6548 ${t} \u672A\u5217\u5165\u6A21\u62DF\u5668\u97F3\u9891\u767D\u540D\u5355`)),i}stopAudio(t){let i=this.audios.get(t)||this.audioHistory.find(r=>r.instanceId===t);i&&!i.stopped&&(i.alive=!1,i.stopped=!0,this.audioRevision++),this.audios.delete(t)}audioSnapshot(){return{sequence:this.nextAudioId-1,revision:this.audioRevision,active:[...this.audios.values()].map(t=>({...t})),recent:this.audioHistory.map(t=>({...t}))}}instantiate(t,i,r){if(r==="OnInit"||r==="OnDestroy")return null;let n=this.templates.get(Number(t));if(!n||!i)return null;let a=new nt(this,{...n,Id:this.nextControlId(),authoringId:null,prefabIndex:Number(t)});return i.addChild(a),a.SetAsLastSibling(),Ge(a,o=>this.controlsById.set(o.Id,o)),this.mountSpecScripts(n,a),a}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}`);Ge(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.scrollControls?.delete(t),this._playRemoved.push(t.Id),t.parent){let i=t.parent,r=i.children.indexOf(t);r>=0&&i.children.splice(r,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 r of i)this.unrefLuaCallback(r);for(let i of t.keyListeners.values())for(let r of i)this.unrefLuaCallback(r);for(let i of t.navListeners.values())for(let r of i)this.unrefLuaCallback(r);t.cursorListeners.clear(),t.keyListeners.clear(),t.navListeners.clear(),t.navConfig.clear()}onControlActiveChanging(t,i){let r=[];Ge(t,n=>r.push({control:n,was:n.activeInHierarchy})),t.active=!!i,t.markPlayDirty(!0);for(let n of r){let a=n.control.activeInHierarchy;if(n.was!==a)for(let o of n.control.scripts.slice())a?this.enableScript(o):this.disableScript(o)}}bindScriptEnv(t){let i=t.env;return i?(this.pushScript(i,t),f.lua_setglobal(i,M("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,r=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=r,this.mountedScripts=this.mountedScripts.filter(n=>n!==t),t.object&&(t.object.scripts=t.object.scripts.filter(n=>n!==t)),this.varHandlers=this.varHandlers.filter(n=>n.script!==t),this.signalHandlers=this.signalHandlers.filter(n=>n.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,r,n,a,o){ee.luaL_newmetatable(t,M(i)),f.lua_pushcfunction(t,s=>{let c=Le(s,1)||Ce(f.lua_touserdata(s,1)),l=Z(s,2);if(a[l]&&(!o||o(c,l)))return f.lua_pushcfunction(s,a[l]),1;let u;try{u=r(c,l)}catch(d){return ee.luaL_error(s,M(String(d.message||d)))}return u===void 0?(f.lua_pushnil(s),1):(le(s,this,u),1)}),f.lua_setfield(t,-2,M("__index")),f.lua_pushcfunction(t,s=>{try{let c=Le(s,1)||Ce(f.lua_touserdata(s,1)),l=Z(s,2),u=he(s,this,3);return n(c,l,u),0}catch(c){return f.lua_pushstring(s,M(String(c.message||c))),f.lua_error(s)}}),f.lua_setfield(t,-2,M("__newindex")),f.lua_pushcfunction(t,s=>{let c=Le(s,1)||Ce(f.lua_touserdata(s,1)),l=Le(s,2)||Ce(f.lua_touserdata(s,2));return f.lua_pushboolean(s,c===l),1}),f.lua_setfield(t,-2,M("__eq")),f.lua_pop(t,1)}method(t){let i=this;return r=>{let n=Le(r,1)||Ce(f.lua_touserdata(r,1)),a=f.lua_gettop(r),o=[];for(let s=2;s<=a;s++)o.push(he(r,i,s));try{let s=t(n,...o);if(s===n)return f.lua_pushvalue(r,1),1;if(s===void 0)return 0;if(Array.isArray(s)&&s.__multi){for(let c of s)le(r,i,c);return s.length}if(Array.isArray(s)&&!(s.length&&typeof s[0]=="object"&&s[0]?.typeofName)){if(s.__controls)return f.lua_createtable(r,s.length,0),s.forEach((c,l)=>{i.pushControl(r,c),f.lua_rawseti(r,-2,l+1)}),1;if(s.__scripts)return f.lua_createtable(r,s.length,0),s.forEach((c,l)=>{i.pushScript(r,c),f.lua_rawseti(r,-2,l+1)}),1;if(typeof s[0]=="number"&&s.length<=4){for(let c of s)f.lua_pushnumber(r,c);return s.length}}return le(r,i,s),1}catch(s){return f.lua_pushstring(r,M(String(s.message||s))),f.lua_error(r)}}}mtEnum(t){let i=new Set(["Name","FullName","EnumType"]);this.mtIndexNewindex(t,"EnumItem",(r,n)=>i.has(n)?r[n]:void 0,(r,n)=>{throw new Error(`cannot set ${n}, no such field`)},{})}mtCursor(t){let i=new Set(["dragging","touchId"]);this.mtIndexNewindex(t,"CursorEventData",(r,n)=>i.has(n)?r[n]:void 0,(r,n)=>{throw new Error(`cannot set ${n}, no such field`)},{GetUIPos:this.method(r=>r.GetUIPos()),GetPressUIPos:this.method(r=>r.GetPressUIPos()),GetUIPosDelta:this.method(r=>r.GetUIPosDelta())})}mtControl(t){let i={GetChildren:this.method(r=>{let n=r.GetChildren();return n.__controls=!0,n}),GetChild:this.method((r,n)=>r.GetChild(n)),FindChild:this.method((r,n)=>r.FindChild(n)),SetActive:this.method((r,n)=>r.SetActive(n)),SetVisible:this.method((r,n)=>r.SetVisible(n)),GetSiblingIndex:this.method(r=>r.GetSiblingIndex()),SetSiblingIndex:this.method((r,n)=>r.SetSiblingIndex(n)),SetAsFirstSibling:this.method(r=>r.SetAsFirstSibling()),SetAsLastSibling:this.method(r=>r.SetAsLastSibling()),GetAnchoredPosition:this.method(r=>r.GetAnchoredPosition()),SetAnchoredPosition:this.method((r,n,a)=>r.SetAnchoredPosition(n,a)),GetSizeDelta:this.method(r=>r.GetSizeDelta()),SetSizeDelta:this.method((r,n,a)=>r.SetSizeDelta(n,a)),GetAnchorMin:this.method(r=>r.GetAnchorMin()),SetAnchorMin:this.method((r,n,a)=>r.SetAnchorMin(n,a)),GetAnchorMax:this.method(r=>r.GetAnchorMax()),SetAnchorMax:this.method((r,n,a)=>r.SetAnchorMax(n,a)),GetPivot:this.method(r=>r.GetPivot()),SetPivot:this.method((r,n,a)=>r.SetPivot(n,a)),GetLocalScale:this.method(r=>r.GetLocalScale()),SetLocalScale:this.method((r,n,a,o)=>r.SetLocalScale(n,a,o)),GetLocalRotation:this.method(r=>r.GetLocalRotation()),SetLocalRotation:this.method((r,n,a,o)=>r.SetLocalRotation(n,a,o)),GetScriptByPath:this.method((r,n)=>r.GetScriptByPath(n)),GetScript:this.method((r,n)=>r.GetScript(n)),GetScripts:this.method(r=>{let n=r.GetScripts();return n.__scripts=!0,n}),AddCursorEventListener:this.method((r,n,a)=>r.AddCursorEventListener(be(n),a)),RemoveCursorEventListener:this.method((r,n,a)=>r.RemoveCursorEventListener(be(n),a)),RemoveCursorEventListeners:this.method((r,n)=>r.RemoveCursorEventListeners(be(n))),RemoveAllCursorEventListeners:this.method(r=>r.RemoveAllCursorEventListeners()),SimulateCursorClick:this.method(r=>r.SimulateCursorClick()),AddKeyEventListener:this.method((r,n,a)=>r.AddKeyEventListener(be(n),a)),RemoveKeyEventListener:this.method((r,n,a)=>r.RemoveKeyEventListener(be(n),a)),RemoveKeyEventListeners:this.method((r,n)=>r.RemoveKeyEventListeners(be(n))),RemoveAllKeyEventListeners:this.method(r=>r.RemoveAllKeyEventListeners()),AddNavigationEventListener:this.method((r,n,a)=>r.AddNavigationEventListener(be(n),a)),RemoveNavigationEventListener:this.method((r,n,a)=>r.RemoveNavigationEventListener(be(n),a)),RemoveNavigationEventListeners:this.method((r,n)=>r.RemoveNavigationEventListeners(be(n))),RemoveAllNavigationEventListeners:this.method(r=>r.RemoveAllNavigationEventListeners()),SetControllerNavigation:this.method((r,n,a,o)=>r.SetControllerNavigation(be(n),a,o)),GetControllerNavigation:this.method((r,n)=>r.GetControllerNavigation(be(n))),SetImage:this.method((r,n,a)=>r.SetImage(n,a)),SetSoftEdgeWidth:this.method((r,n,a)=>r.SetSoftEdgeWidth(n,a)),SetFillUnused:this.method(r=>r.SetFillUnused()),SetFillHorizontal:this.method((r,n,a)=>r.SetFillHorizontal(n,a)),SetFillVertical:this.method((r,n,a)=>r.SetFillVertical(n,a)),SetFillRadial90:this.method((r,n,a)=>r.SetFillRadial90(n,a)),SetFillRadial180:this.method((r,n,a)=>r.SetFillRadial180(n,a)),SetFillRadial360:this.method((r,n,a)=>r.SetFillRadial360(n,a)),PlayAnimation:this.method(r=>r.PlayAnimation()),StopAnimation:this.method(r=>r.StopAnimation()),RefreshItems:this.method((r,n,a)=>{this.retainLuaCallback(a);try{r.RefreshItems(n,a)}finally{this.unrefLuaCallback(a)}}),GetItemIndex:this.method((r,n)=>r.GetItemIndex(n)),GetItemSize:this.method(r=>r.GetItemSize()),GetItemSpacing:this.method(r=>r.GetItemSpacing()),GetPadding:this.method(r=>r.GetPadding()),ScrollToItemAt:this.method((r,n,a)=>r.ScrollToItemAt(n,a)),GetContentLength:this.method(r=>r.GetContentLength())};this.mtIndexNewindex(t,"Control",(r,n)=>{if(!ln(r,n))return;if(!r.alive&&n!=="alive")throw new Error(`attempt to read '${n}' of a destroyed control`);let a=r.luaFieldValue(n),o=Po[n];return o?fn(o,a):typeof a=="number"&&!Bc.has(n)&&!jc.has(n)?new oi(a):a},(r,n,a)=>{if(ln(r,n)==="rw"){if((n==="fontSize"||n==="minimumFontSize")&&!Number.isInteger(a)){let c=a===null?"nil":typeof a;throw new Error(`bad argument #2 to '${n}' (integer expected, got ${c})`)}let s=Po[n];if(n==="imageType"&&(a?.EnumType!=="ImageType"||!["Basic","Stretch"].includes(a.Name)))throw new Error("imageType requires Enum.ImageType.Basic or Stretch");r[n]=s?fn(s,a):a,typeof r.markPlayDirty=="function"&&r.markPlayDirty(Hi.has(n));return}throw new Error(`cannot set ${n}, no such field`)},i,Co)}mtScript(t){let i=this,r=new Set(["alive","scriptMappingId","object","path","enabled"]);this.mtIndexNewindex(t,"Script",(n,a)=>r.has(a)?n[a]:void 0,(n,a,o)=>{if(a==="enabled"){n.enabled=!!o;return}throw new Error(`cannot set ${a}, no such field`)},{GetParam:this.method((n,a)=>Object.prototype.hasOwnProperty.call(n.params,a)?n.params[a]:null),Invoke:n=>i.luaInvoke(n),EnableUpdate:this.method((n,a)=>{n.updateEnabled=!!a}),RegisterServerSignalHandler:this.method((n,a,o)=>{i.signalHandlers.push({script:n,name:a,fn:o})}),UnregisterServerSignalHandler:this.method((n,a)=>{i.signalHandlers=i.signalHandlers.filter(o=>!(o.script===n&&o.name===a))}),RegisterCustomVariableChangedHandler:this.method((n,a,o,s)=>{i.varHandlers.push({script:n,entityType:be(a),name:o,fn:s})}),UnregisterCustomVariableChangedHandler:this.method((n,a,o)=>{let s=be(a);i.varHandlers=i.varHandlers.filter(c=>!(c.script===n&&c.entityType===s&&c.name===o))})})}mtTween(t){this.mtIndexNewindex(t,"Tween",()=>{},()=>{},{SetEase:this.method((i,r)=>i.SetEase(r)),SetRelative:this.method((i,r)=>i.SetRelative(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,r)=>i.Kill(r)),SetOnComplete:this.method((i,r)=>i.SetOnComplete(r)),SetOnStepComplete:this.method((i,r)=>i.SetOnStepComplete(r)),SetLoops:this.method((i,r)=>i.SetLoops(r))})}mtSeq(t){this.mtIndexNewindex(t,"TweenSequence",()=>{},()=>{},{Append:this.method((i,r)=>i.Append(r)),AppendInterval:this.method((i,r)=>i.AppendInterval(r)),AppendCallback:this.method((i,r)=>i.AppendCallback(r)),Join:this.method((i,r)=>i.Join(r)),Insert:this.method((i,r,n)=>i.Insert(r,n)),InsertCallback:this.method((i,r,n)=>i.InsertCallback(r,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,r)=>i.Kill(r)),SetOnComplete:this.method((i,r)=>i.SetOnComplete(r)),SetOnStepComplete:this.method((i,r)=>i.SetOnStepComplete(r)),SetLoops:this.method((i,r)=>i.SetLoops(r))})}mtSignal(t){this.mtIndexNewindex(t,"ServerSignal",()=>{},()=>{},{AddParam:this.method((i,r,n)=>i.AddParam(r,n)),SendSignal:this.method(i=>i.SendSignal()),AddInt:this.method((i,r)=>i.AddInt(r)),AddIntList:this.method((i,r)=>i.AddIntList(r)),AddFloat:this.method((i,r)=>i.AddFloat(r)),AddFloatList:this.method((i,r)=>i.AddFloatList(r)),AddString:this.method((i,r)=>i.AddString(r)),AddStringList:this.method((i,r)=>i.AddStringList(r)),AddVector3:this.method((i,r)=>i.AddVector3(r)),AddVector3List:this.method((i,r)=>i.AddVector3List(r)),AddBool:this.method((i,r)=>i.AddBool(r)),AddBoolList:this.method((i,r)=>i.AddBoolList(r)),AddGuid:this.method((i,r)=>i.AddGuid(r)),AddGuidList:this.method((i,r)=>i.AddGuidList(r)),AddEntity:this.method((i,r)=>i.AddEntity(r)),AddEntityList:this.method((i,r)=>i.AddEntityList(r)),AddPrefabId:this.method((i,r)=>i.AddPrefabId(r)),AddPrefabIdList:this.method((i,r)=>i.AddPrefabIdList(r)),AddConfigId:this.method((i,r)=>i.AddConfigId(r)),AddConfigIdList:this.method((i,r)=>i.AddConfigIdList(r))})}luaRequire(t){let i=Z(t,1),r=this.normalizeRequirePath(i),n=this.requireAliases.get(r)||r;f.lua_rawgeti(t,pt,f.LUA_RIDX_MAINTHREAD);let a=f.lua_tothread(t,-1);f.lua_pop(t,1);let o=this.requireCache.get(a);o||(o=new Map,this.requireCache.set(a,o));let s=o.get(n);if(s?.loading)return f.lua_pushstring(t,M(`failed to load script '${r}': cyclic require`)),f.lua_error(t);if(s&&s.ref!=null)return f.lua_rawgeti(t,pt,s.ref),1;let c=this.scriptFiles.get(n);if(c==null)return f.lua_pushstring(t,M(`failed to load script '${r}'`)),f.lua_error(t);let l=f.lua_gettop(t);o.set(n,{loading:!0});try{this.loadModule(t,a,n,c),f.lua_pushvalue(t,-1);let u=ee.luaL_ref(t,pt);return o.set(n,{ref:u}),1}catch(u){return o.delete(n),f.lua_settop(t,l),f.lua_pushstring(t,M(`failed to load script '${r}': ${u.message||u}`)),f.lua_error(t)}}newLuaThread(){let t=ee.luaL_newstate();return fo.luaL_openlibs(t),bo(t),this.installMetatables(t),this.installGlobals(t),this.luaStates.add(t),f.lua_pushglobaltable(t),this.copyLuaEnvironment(t,-1),f.lua_remove(t,-2),this.moduleBaseEnvironments.set(t,ee.luaL_ref(t,pt)),t}copyLuaEnvironment(t,i){let r=f.lua_absindex(t,i);f.lua_newtable(t);let n=f.lua_absindex(t,-1);for(f.lua_pushnil(t);f.lua_next(t,r)!==0;)f.lua_pushvalue(t,-2),f.lua_pushvalue(t,-2),f.lua_rawset(t,n),f.lua_pop(t,1);f.lua_pushvalue(t,n),f.lua_setfield(t,n,M("_G"))}closeTrackedLuaState(t){if(!t||!this.luaStates.has(t))return;for(let r of this.requireCache.get(t)?.values()||[])r.ref!=null&&ee.luaL_unref(t,pt,r.ref);this.requireCache.delete(t);let i=this.moduleBaseEnvironments.get(t);if(i!=null&&ee.luaL_unref(t,pt,i),this.moduleBaseEnvironments.delete(t),this.luaStates.delete(t),this.luaFunctions)for(let[r,n]of this.luaFunctions)n.__luaState===t&&this.luaFunctions.delete(r);yo(t)}loadModule(t,i,r,n){let a={__kind:"Script",alive:!0,scriptMappingId:this.resolveScriptMappingId(),object:null,path:r,enabled:!0,updateEnabled:!1,params:{},env:t,invoke(){}},o=String(n).replace(/^\uFEFF/,""),s=Bi(o);if(ee.luaL_loadbuffer(t,s,s.length,M(`@${r}`))!==Re)throw new Error(Z(t,-1));let l=f.lua_absindex(t,-1);if(f.lua_rawgeti(t,pt,this.moduleBaseEnvironments.get(i)),this.copyLuaEnvironment(t,-1),f.lua_remove(t,-2),this.pushScript(t,a),f.lua_setfield(t,-2,M("script")),f.lua_setupvalue(t,l,1),f.lua_pcall(t,0,1,0)!==Re)throw new Error(Z(t,-1))}mountScript({path:t,source:i,control:r,params:n={},scriptMappingId:a=void 0}){this.L||this.boot();let o=this.newLuaThread(),s={__kind:"Script",alive:!0,scriptMappingId:this.resolveScriptMappingId(a),object:r,path:this.normalizeRequirePath(t),enabled:!0,updateEnabled:!1,params:n,env:o,lifecyclePhase:"idle"};s.invoke=(l,u)=>this.invokeOn(o,l,u),r&&r.scripts.push(s),this.mountedScripts.push(s),this.pushScript(o,s),f.lua_setglobal(o,M("script"));let c=this.lifecyclePhase;try{this.lifecyclePhase="OnInit",s.lifecyclePhase="OnInit",this.runChunk(o,i,t);let l=this.callGlobal(o,"OnInit");l&&this.mountErrors.push(l),this.lifecyclePhase="OnEnable",s.lifecyclePhase="OnEnable";let u=this.callGlobal(o,"OnEnable");u&&this.mountErrors.push(u),this.lifecyclePhase="OnStart",s.lifecyclePhase="OnStart";let d=this.callGlobal(o,"OnStart");return d&&this.mountErrors.push(d),this.lifecyclePhase="running",s.lifecyclePhase="running",s}catch(l){throw s.alive=!1,s.lifecyclePhase="failed",this.mountedScripts=this.mountedScripts.filter(u=>u!==s),r&&(r.scripts=r.scripts.filter(u=>u!==s)),this.varHandlers=this.varHandlers.filter(u=>u.script!==s),this.signalHandlers=this.signalHandlers.filter(u=>u.script!==s),this.lifecyclePhase=c,o&&o!==this.L&&this.closeTrackedLuaState(o),s.env=null,l}}runChunk(t,i,r){let n=String(i).replace(/^\uFEFF/,""),a=Bi(n),o=ee.luaL_loadbuffer(t,a,a.length,M(`@${r}`));if(o!==Re){let c=Z(t,-1)||`luaL_loadbuffer status ${o}`;throw f.lua_pop(t,1),new Error(c)}let s=f.lua_pcall(t,0,0,0);if(s!==Re){let c=Z(t,-1)||`lua_pcall status ${s}`;throw f.lua_pop(t,1),new Error(c)}}callGlobal(t,i){if(f.lua_getglobal(t,M(i)),f.lua_isfunction(t,-1)){if(f.lua_pcall(t,0,0,0)!==Re){let n=Z(t,-1);f.lua_pop(t,1);let a=`${i}: ${n}`;return this.log("lua-error",a),a}}else f.lua_pop(t,1);return null}callGlobalDt(t,i,r){if(f.lua_getglobal(t,M(i)),f.lua_isfunction(t,-1)){if(f.lua_pushnumber(t,r),f.lua_pcall(t,1,0,0)!==Re){let a=Z(t,-1);f.lua_pop(t,1),this.log("lua-error",`${i}: ${a}`)}}else f.lua_pop(t,1)}luaInvoke(t){let i=Le(t,1);if(!i||i.__kind!=="Script")return ee.luaL_error(t,M("bad self to 'Invoke' (Script expected)"));let r=Z(t,2),n=i.env;if(!n||n.l_G!==t.l_G){let c=[];for(let d=3;d<=f.lua_gettop(t);d++)c.push(he(t,this,d));let l;try{l=i.invoke(r,c)}catch(d){return ee.luaL_error(t,M(String(d.message||d)))}if(l===void 0)return 0;let u=Array.isArray(l)&&l.__multi?l:[l];for(let d of u)le(t,this,d);return u.length}let a=2;if(f.lua_getglobal(t,M(r)),!f.lua_isfunction(t,-1))return 0;f.lua_replace(t,a),f.lua_remove(t,1);let o=f.lua_gettop(t)-1;return f.lua_pcall(t,o,To,0)!==Re?f.lua_error(t):f.lua_gettop(t)}invokeOn(t,i,r){let n=f.lua_gettop(t);if(f.lua_getglobal(t,M(i)),!f.lua_isfunction(t,-1)){f.lua_settop(t,n);return}for(let c of r)le(t,this,c);if(f.lua_pcall(t,r.length,To,0)!==Re){let c=Z(t,-1);throw f.lua_settop(t,n),new Error(c)}let o=f.lua_gettop(t)-n;if(o<=0){f.lua_settop(t,n);return}if(o===1){let c=he(t,this,-1);return f.lua_settop(t,n),c}let s=[];for(let c=1;c<=o;c++)s.push(he(t,this,n+c));return f.lua_settop(t,n),s.__multi=!0,s}runScriptPhase(t,i){for(let r of this.mountedScripts){if(!this.scriptCanRun(r))continue;let n=r.env;n&&(this.pushScript(n,r),f.lua_setglobal(n,M("script")),!(t==="OnUpdate"&&!r.updateEnabled)&&this.callGlobalDt(n,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;for(let[r,n]of this.audios)this.clock.time+1e-9>=n.startedAt+n.duration&&(n.alive=!1,this.audios.delete(r),this.audioRevision++);let i=!this.clock.paused;for(let r of[...this.animations])r.step(t);this.runScriptPhase("OnUpdate",t),i&&(this.clock.levelTime+=t,this.runScriptPhase("OnLevelUpdate",t))}injectKey(t){let i=r=>{if(!r.alive||!r.activeInHierarchy)return!1;if(r.keyListeners.has(t)&&r.emitKey(t))return!0;for(let n of[...r.children])if(i(n))return!0;return!1};for(let r of[...this.roots])i(r)}injectCursor(t,i,r){let n=r||this.makeCursorEventData({});Number.isFinite(n.x)&&Number.isFinite(n.y)&&(this.cursor.x=n.x,this.cursor.y=n.y),t.emitCursor(i,n)}getVar(t,i){if(this.serverBridge&&typeof this.serverBridge.getVar=="function")return this.serverBridge.getVar(t,i);let r=this.serverVars[t];return r?r[i]:void 0}notifyVarHandlers(t,i){for(let r of this.varHandlers)this.scriptCanRun(r.script)&&r.entityType===t&&r.name===i&&this.safeCall(r.fn,this.enumTree.CustomVariableEntityType[t],i)}setVar(t,i,r){if(this.serverBridge&&typeof this.serverBridge.setVar=="function"){this.serverBridge.setVar(t,i,r);return}let n=this.serverVars[t]||(this.serverVars[t]=Object.create(null));n[i]=r,this.notifyVarHandlers(t,i)}sendClientSignal(t,i){for(let r of this.signalHandlers)this.scriptCanRun(r.script)&&r.name===t&&this.safeCall(r.fn,t,i)}evalQueryScript(t,i){this.L||this.boot();let r=this.L;f.lua_createtable(r,0,5);let n=(a,o)=>{f.lua_pushcfunction(r,o),f.lua_setfield(r,-2,M(a))};return n("var",a=>(le(a,this,i.var(Z(a,1),Z(a,2))),1)),n("logContains",a=>(f.lua_pushboolean(a,i.logContains(Z(a,1))),1)),n("control",a=>(le(a,this,i.control(Z(a,1))),1)),n("logs",a=>(le(a,this,i.logs()),1)),n("signals",a=>(le(a,this,i.signals(Z(a,1))),1)),n("serverLogs",a=>(le(a,this,i.serverLogs?i.serverLogs():[]),1)),n("serverLogContains",a=>{let o=i.serverLogContains;return f.lua_pushboolean(a,o?!!o(Z(a,1)):!1),1}),f.lua_setglobal(r,M("query")),this.runChunk(r,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,this.audios.clear(),this.audioHistory.length=0,this.audioWarnings.clear()}};function fi(e){let t=new Wi(e);return t.boot(),t}var yt=Object.freeze(Array.from({length:8},(e,t)=>`Player${t+1}`)),pn=Object.freeze(Array.from({length:8},(e,t)=>`Avatar${t+1}`)),$o=Object.freeze(["Level","PlayerSelf","AvatarSelf"]);var hn=Object.freeze([...$o,...yt,...pn]),Go=Object.freeze(["PlayerSelf","AllPlayers",...yt]),Uc=Object.freeze(["Level","PlayerSelf",...yt]),Ro=Object.freeze(["Int","Float","String","Bool","Vector3","Entity","Guid","PrefabId","ConfigId","IntList","FloatList","StringList","BoolList","Vector3List","EntityList","GuidList","PrefabIdList","ConfigIdList","Dict","Struct"]),Lc=-2147483648,Xc=2147483647,Wc=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 di(e){return`Player${Number(e)}`}function Ki(e){return`Avatar${Number(e)}`}function Mo(e){let t=String(e||"").match(/^(?:Player|Avatar)([1-8])$/);return t?Number(t[1]):0}function gt(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 Xe(e,t=8){let i=gt(t);if(e==null||e==="")return 1;let r=Number(e);if(!Number.isInteger(r)||r<1||r>i)throw new Error(`playerIndex must be an integer 1-${i}`);return r}function No(){let e={Level:Object.create(null),PlayerSelf:Object.create(null),AvatarSelf:Object.create(null)};for(let t of yt)e[t]=Object.create(null);for(let t of pn)e[t]=Object.create(null);return e}function Vo(e){let t=String(e||"");if(!hn.includes(t))throw new Error(`unknown CustomVariableEntityType: ${e}`);return t}function Kc(e,t){let i=Vo(e);if(!Uc.includes(i))throw new Error(`${t}.entityType must be Level, PlayerSelf, or Player1-8`);return i}function hi(e){let t=String(e??"");if(!t)throw new Error("custom variable name is required");return t}function qi(e){let t=String(e??"");if(!t)throw new Error("signal name is required");return t}function mn(e){let t=String(e||"PlayerSelf");if(!Go.includes(t))throw new Error(`unsupported client signal target: ${e}. use PlayerSelf, AllPlayers, or Player1-8`);return t}function mi(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=mi(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 Se(e){return e===void 0?null:JSON.parse(JSON.stringify(e))}function Oo(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 Fo(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:mi(t),value:t}):[]}function qc(e){return String(e?.kind||e?.type||e?.name||e?.id||"")}function Ji(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Yo(e,t){if(!Ji(e)||!Object.prototype.hasOwnProperty.call(e,"fromSignalParam"))return null;if(Object.keys(e).some(r=>r!=="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 Do(e,t){return Yo(e,t)||Se(e)}function Jc(e,t,i){if(!Ji(e))throw new Error(`serverLogic.rules[${t}].actions[${i}] must be an object`);let r=String(e.kind||e.type||""),n=`serverLogic.rules[${t}].actions[${i}]`;if(r==="setCustomVariable"){let a=Kc(e.entityType,n);if(!Object.prototype.hasOwnProperty.call(e,"value"))throw new Error(`${n}.value is required`);return{kind:r,entityType:a,name:hi(e.name),value:Do(e.value,`${n}.value`),...e.variableType?{variableType:String(e.variableType)}:{}}}if(r==="sendClientScriptSignal"){if(!Array.isArray(e.params))throw new Error(`${n}.params must be an array`);return{kind:r,target:mn(e.target),signalName:qi(e.signalName),params:e.params.map((a,o)=>Do(a,`${n}.params[${o}]`))}}throw new Error(`${n}.kind must be setCustomVariable or sendClientScriptSignal`)}function pi(e){if(e==null)return{version:1,rules:[]};if(!Ji(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,r)=>{if(!Ji(i))throw new Error(`serverLogic.rules[${r}] must be an object`);if(!Array.isArray(i.actions)||i.actions.length===0)throw new Error(`serverLogic.rules[${r}].actions must be a non-empty array`);return{id:String(i.id||`signal-${r+1}`),signalName:qi(i.signalName),actions:i.actions.map((n,a)=>Jc(n,r,a))}})}}function zo(e,t,{typed:i=!1}={}){let r=Yo(e,"server logic value");if(r){let n=i?t.params:t.values;if(r.fromSignalParam>=n.length)throw new Error(`signal ${t.name} has no parameter at index ${r.fromSignalParam}`);return Se(n[r.fromSignalParam])}return Se(e)}function Zc(e){return e==="Level"?"Level":yt.includes(e)?"PlayerSelf":pn.includes(e)?"AvatarSelf":e}function Bo(e={}){let t=No(),i=No(),r=[],n=[],a=[],o=[],s=Array.from({length:9},()=>null),c=1,l=0,u=Number(e.onlineLatencyMs||0);(!Number.isFinite(u)||u<0)&&(u=0);let d=pi(e.logic),h=gt(e.playerCount),p=Xe(e.viewPlayerIndex,h);function m(b,A){o.push({source:"server",level:String(b||"engine"),text:String(A),time:l})}function g(b){let A=s[b||p],w=Number(A?.clock?.time);Number.isFinite(w)&&(l=w)}function S(b,A,w,k){t[b][A]=w,i[b][A]={type:k||mi(w)||i[b][A]?.type||""}}function C(b,A,w){return typeof w!="number"||!Number.isInteger(w)?{ok:!0,value:w}:w>=Lc&&w<=Xc?{ok:!0,value:w}:(m("engine",`Int custom variable ${b}.${A} out of range ${w}; keeping previous legal value`),{ok:!1,value:t[b][A]})}function I(b,A){let w=Vo(b),k=A||p;return w==="PlayerSelf"?di(k):w==="AvatarSelf"?Ki(k):w}function P(b,A){let w=Zc(b);if(b==="Level"){for(let E=1;E<=h;E+=1){let _=s[E];_&&typeof _.notifyVarHandlers=="function"&&_.notifyVarHandlers("Level",A)}return}let k=Mo(b);if(!k)return;let F=s[k];F&&typeof F.notifyVarHandlers=="function"&&F.notifyVarHandlers(w,A)}function N(b,A){let w=mn(b);return w==="AllPlayers"?Array.from({length:h},(k,F)=>F+1):w==="PlayerSelf"?[A||p]:[Mo(w)]}function G(b){for(let A of d.rules)if(A.signalName===b.name)for(let w of A.actions){if(w.kind==="setCustomVariable"){let k=zo(w.value,b);z.setVar(w.entityType,w.name,k,{type:w.variableType,playerIndex:b.playerIndex}),m("info",`logic ${A.id}: set ${w.entityType}.${w.name}`);continue}if(w.kind==="sendClientScriptSignal"){let k=w.params.map(F=>zo(F,b,{typed:!0}));z.sendToClient(w.signalName,k,{target:w.target,playerIndex:b.playerIndex}),m("info",`logic ${A.id}: sent ${w.signalName} to ${w.target}`)}}}function j(b,A){b&&(b.serverBridge={getVar:(w,k)=>z.getVar(w,k,{playerIndex:A}),setVar:(w,k,F)=>z.setVar(w,k,F,{playerIndex:A}),receiveFromClient:(w,k)=>z.receiveFromClient(w,k,{playerIndex:A})})}function B(b){b&&(b.serverBridge=null)}let z={ENTITY_TYPES:$o,ALL_ENTITY_TYPES:hn,CLIENT_SIGNAL_TARGETS:Go,get clock(){return l},get playerCount(){return h},get viewPlayerIndex(){return p},setClock(b){l=Number(b)||0},setPlayerCount(b){return h=gt(b),p>h&&(p=h),h},setViewPlayerIndex(b){return p=Xe(b,h),p},log(b,A){m(b,A)},defineVar(b,A,w={},{playerIndex:k}={}){let F=I(b,k),E=hi(A);if(Object.prototype.hasOwnProperty.call(t[F],E))throw new Error(`custom variable already exists: ${F}.${E}`);let _=w.type?String(w.type):mi(w.value??w.defaultValue);if(_&&!Ro.includes(_))throw new Error(`unsupported custom variable type: ${_}`);let $=w.value!==void 0?w.value:w.defaultValue!==void 0?w.defaultValue:null;return S(F,E,$,_),z.getVar(F,E)},getVar(b,A,{playerIndex:w}={}){let k=I(b,w),F=hi(A);if(!Object.prototype.hasOwnProperty.call(t[k],F)){m("engine",`GetGlobalCustomVariableValue missing ${k}.${F}; returning nil (simulator policy)`);return}return t[k][F]},setVar(b,A,w,{notify:k=!0,type:F,playerIndex:E}={}){let _=I(b,E),$=hi(A),Y=F||i[_][$]?.type||mi(w);if(Y&&!Ro.includes(Y)&&Y!=="")throw new Error(`unsupported custom variable type: ${Y}`);let re=w;if(!((Y==="Int"||Y===""&&typeof w=="number"&&Number.isInteger(w))&&(re=C(_,$,w).value,re===void 0)))return S(_,$,re,Y),k&&P(_,$),re},listVars(b){let A=b?[I(b)]:["Level",...Array.from({length:h},(k,F)=>di(F+1)),...Array.from({length:h},(k,F)=>Ki(F+1))],w=[];for(let k of A)for(let F of Object.keys(t[k]))w.push({entityType:k,name:F,type:i[k][F]?.type||"",value:Se(t[k][F])});return w},receiveFromClient(b,A=[],{playerIndex:w}={}){let k=Xe(w||p,h);g(k);let F=qi(b),E={id:c++,direction:"inbound",name:F,params:Fo(A),values:Oo(A),time:l,playerIndex:k,from:di(k)};return r.push(E),G(E),E},sendToClient(b,A=[],{target:w="PlayerSelf",playerIndex:k}={}){let F=qi(b),E=mn(w),$=N(E,k||p),Y={id:c++,direction:"outbound",name:F,params:Fo(A),values:Oo(A),time:l,target:E,players:$,deliverAt:l+u/1e3,delivered:!1};return n.push(Y),u===0?z.deliver(Y):a.push(Y),Y},getLogic(){return Se(d)},setLogic(b){return d=pi(b),z.getLogic()},deliver(b){if(!b||b.delivered)return;b.delivered=!0;let A=Array.isArray(b.players)&&b.players.length?b.players:N(b.target);for(let w of A){let k=s[w];k&&typeof k.sendClientSignal=="function"&&k.sendClientSignal(b.name,b.values)}},flush(b){b!==void 0&&(l=Number(b)||0);let A=[];for(let w=a.length-1;w>=0;w-=1)a[w].deliverAt<=l&&A.push(a.splice(w,1)[0]);A.sort((w,k)=>w.id-k.id);for(let w of A)z.deliver(w);return A},inbound(){return r.slice()},outbound(){return n.slice()},loadConfig(b){if(b!=null){if(typeof b!="object")throw new Error("server config must be an object");if(b.graph&&!Array.isArray(b.nodes))throw new Error("unsupported server node graph: v1 only accepts custom variables and signals");for(let A of b.nodes||[]){let w=qc(A);if(!Wc.has(w))throw new Error(`unsupported server node: ${w||JSON.stringify(A)}. v1 only supports custom variables and signals`)}if(b.onlineLatencyMs!==void 0){let A=Number(b.onlineLatencyMs);if(!Number.isFinite(A)||A<0)throw new Error("onlineLatencyMs must be a non-negative finite number");u=A}b.playerCount!==void 0&&z.setPlayerCount(b.playerCount),b.viewPlayerIndex!==void 0&&z.setViewPlayerIndex(b.viewPlayerIndex),(b.logic!==void 0||b.serverLogic!==void 0)&&z.setLogic(b.logic??b.serverLogic);for(let A of b.vars||[]){let w=I(A.entityType),k=hi(A.name);Object.prototype.hasOwnProperty.call(t[w],k)?z.setVar(w,k,A.value??A.defaultValue,{notify:!1,type:A.type}):z.defineVar(w,k,A)}}},attachRuntime(b,{playerIndex:A=1}={}){let w=Xe(A,8);return s[w]&&s[w]!==b&&B(s[w]),s[w]=b||null,j(s[w],w),z},attachRuntimes(b){z.detachRuntime();let A=Array.isArray(b)?b:[];for(let w=0;w<A.length&&w<8;w+=1)s[w+1]=A[w]||null,j(s[w+1],w+1);return z},detachRuntime(){for(let b=1;b<=8;b+=1)B(s[b]),s[b]=null},snapshot(){let b=di(p),A=Ki(p),w={Level:{},PlayerSelf:{},AvatarSelf:{}};for(let k of Object.keys(t.Level))w.Level[k]={type:i.Level[k]?.type||"",value:Se(t.Level[k])};for(let k of Object.keys(t[b]))w.PlayerSelf[k]={type:i[b][k]?.type||"",value:Se(t[b][k])};for(let k of Object.keys(t[A]))w.AvatarSelf[k]={type:i[A][k]?.type||"",value:Se(t[A][k])};for(let k=1;k<=h;k+=1){let F=di(k),E=Ki(k);w[F]={},w[E]={};for(let _ of Object.keys(t[F]))w[F][_]={type:i[F][_]?.type||"",value:Se(t[F][_])};for(let _ of Object.keys(t[E]))w[E][_]={type:i[E][_]?.type||"",value:Se(t[E][_])}}return{clock:l,onlineLatencyMs:u,playerCount:h,viewPlayerIndex:p,logic:z.getLogic(),vars:w,inbound:r.map(k=>({id:k.id,name:k.name,params:Se(k.params),values:Se(k.values),time:k.time,playerIndex:k.playerIndex,from:k.from})),outbound:n.map(k=>({id:k.id,name:k.name,params:Se(k.params),values:Se(k.values),time:k.time,target:k.target,players:Array.isArray(k.players)?k.players.slice():[],deliverAt:k.deliverAt,delivered:!!k.delivered})),logs:o.map(k=>({source:"server",level:k.level,text:k.text,time:k.time}))}},reset(){for(let b of hn){for(let A of Object.keys(t[b]))delete t[b][A];for(let A of Object.keys(i[b]))delete i[b][A]}r.length=0,n.length=0,a.length=0,o.length=0,c=1,l=0},destroy(){z.detachRuntime(),z.reset()}};e.config&&z.loadConfig(e.config);for(let b of e.vars||[])z.defineVar(b.entityType,b.name,b);return z}var Qc={container:"container",textbox:"textbox",image:"image",button:"button",cursor:"cursor",grid:"grid",reference:"reference",textwindow:"textwindow",keyhint:"keyhint",animation:"animation",fullscreen:"fullscreen"};function gn(e,t,i=null){let r=et(e.transformByPlatform,t),n={authoringId:e.id,kind:Qc[e.kind]||"container",name:e.name,prefabIndex:e.guid||0,active:e.active!==!1,visible:e.visible!==!1,canControllerFocus:e.canControllerFocus===!0,anchoredPositionX:r.offset.x,anchoredPositionY:r.offset.y,sizeDeltaX:r.size.x,sizeDeltaY:r.size.y,anchorMinX:r.anchorMin.x,anchorMinY:r.anchorMin.y,anchorMaxX:r.anchorMax.x,anchorMaxY:r.anchorMax.y,pivotX:r.pivot.x,pivotY:r.pivot.y,localScaleX:r.scale.x,localScaleY:r.scale.y,localScaleZ:r.scale.z,localRotationX:r.rotation.x,localRotationY:r.rotation.y,localRotationZ:r.rotation.z,children:(e.children||[]).map(o=>gn(o,t,i))},a=i?.get(e.id);return a?.length&&(n.scripts=a.map(o=>{let s=Number(o.guid);return{path:o.path||o.id,source:o.source||"",...Number.isSafeInteger(s)&&s>0?{scriptMappingId:s}:{}}})),e.kind==="container"&&(n.isolateNavigation=e.isolateNavigation===!0,n.disableKeyEventPassthrough=e.disableKeyEventPassthrough===!0,n.disableCursorEventPassthrough=e.disableCursorEventPassthrough===!0,n.showCursor=e.showCursor===!0),(e.kind==="textbox"||e.kind==="textwindow")&&(n.text=e.text??"",n.fontSize=e.fontSize,n.adaptiveFontSize=e.adaptiveFontSize===!0,n.minimumFontSize=e.minimumFontSize,n.fontColor=e.fontColor,n.bgColor=e.bgColor,n.enableOutline=e.enableOutline!==!1,n.outlineColor=e.outlineColor,n.horizontalAlignment=e.horizontalAlignment||"Left",n.verticalAlignment=e.verticalAlignment||"Top",e.kind==="textwindow"&&(n.interactable=e.interactable!==!1,n.showScrollBar=e.showScrollBar!==!1)),e.kind==="image"&&(n.imageSource=e.imageSource,n.imageType=e.imageType??null,n.imageId=e.imageId??0,n.imageColor=e.imageColor,n.raycastTarget=e.raycastTarget===!0,n.enableMask=e.enableMask===!0,n.enableSoftEdge=e.enableSoftEdge===!0,n.softEdgeMode=e.softEdgeMode,n.softEdgeWidthX=e.softEdgeWidthX,n.softEdgeWidthY=e.softEdgeWidthY,n.horizontalSoftRange=e.horizontalSoftRange,n.verticalSoftRange=e.verticalSoftRange,n.enableFill=e.enableFill===!0,n.fillType=e.enableFill?e.fillType:"Unused",n.fillHorizontalType=e.fillHorizontalType,n.fillVerticalType=e.fillVerticalType,n.fillRadial90Type=e.fillRadial90Type,n.fillRadialType=e.fillRadialType,n.fillAmount=e.fillAmount,n.reverseMaskArea=e.reverseMaskArea===!0),e.kind==="button"&&(n.raycastTarget=e.raycastTarget!==!1,n.interactable=e.interactable!==!1,n.clickAudioId=e.clickAudioId,n.unavailableChildId=e.unavailableChildId??null,n.hoverChildId=e.hoverChildId??null,n.pressedChildId=e.pressedChildId??null,n.selectedChildId=e.selectedChildId??null),e.kind==="cursor"&&(n.raycastTarget=e.raycastTarget!==!1),e.kind==="reference"&&(n.referencedPrefabIndex=e.referencedPrefabId),e.kind==="grid"&&(n.itemPrefabIndex=e.itemPrefabId,n.raycastTarget=e.raycastTarget!==!1,n.interactable=e.interactable!==!1,n.showScrollBar=e.showScrollBar!==!1,n.scrollDirection=e.scrollDirection,n.layoutConstraint=e.layoutConstraint,n.layoutConstraintFixedCount=e.layoutConstraintFixedCount,n.cellSizeX=e.cellSizeX,n.cellSizeY=e.cellSizeY,n.spacingX=e.spacingX,n.spacingY=e.spacingY,n.padding1X=e.padding1X,n.padding1Y=e.padding1Y,n.padding2X=e.padding2X,n.padding2Y=e.padding2Y,n.previewCount=e.previewCount),e.kind==="keyhint"&&(n.keyboardKeyCode=e.keyboardKeyCode,n.controllerKeyCode=e.controllerKeyCode),(e.kind==="animation"||e.kind==="fullscreen")&&(n.raycastTarget=!1,n.animationId=e.animationId,n.playSoundEffect=e.playSoundEffect,e.kind==="animation"&&(n.layer=e.layer)),n}function yn(e,t=[],i=""){let r=i&&K[i]?i:e.canvasId,n=K[r],a=ii(e),o=new Map;for(let c of t){if(!c.controlId)continue;let l=o.get(c.controlId)||[];l.push(c),o.set(c.controlId,l)}let s=e.meta?.assetType==="client-control-template"?(e.root.children||[]).map(c=>gn(c,r,o)):[];return{canvasId:r,platform:n.platform,device:n.luaDevice,canvasWidth:n.width,canvasHeight:n.height,root:gn(a,r,o),templates:s}}var Zi="qxqy-autotest";var vt=.03333333333333333,eu=new Set(["pointer","key","click","pause","resume","serverSet","serverSend","view"]),tu=new Set(["log","control","var","signal","tree","lua"]);function bt(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function bn(e){return JSON.parse(JSON.stringify(e??null))}function Qi(e,t){if(!e||typeof e!="object")throw new Error(`events[${t}] must be an object`);let i=String(e.kind||e.do||"");if(!eu.has(i))throw new Error(`unsupported event kind: ${i||"(empty)"}`);let r=e.payload&&typeof e.payload=="object"?{...e.payload}:{};if(i==="pointer")!r.type&&e.type&&(r.type=e.type),r.x===void 0&&(r.x=e.x),r.y===void 0&&(r.y=e.y),r.x=bt(r.x,"pointer.x"),r.y=bt(r.y,"pointer.y"),r.type=String(r.type||"click"),r.type==="wheel"&&(r.deltaX=bt(r.deltaX??e.deltaX??0,"pointer.deltaX"),r.deltaY=bt(r.deltaY??e.deltaY??0,"pointer.deltaY"));else if(i==="key"){if(r.typeName=String(r.typeName||r.key||e.typeName||e.key||""),!r.typeName)throw new Error("key event requires typeName")}else if(i==="click"){if(r.name=String(r.name||e.name||""),!r.name)throw new Error("click event requires control name")}else if(i==="serverSet"){if(r.entityType=String(r.entityType||e.entityType||""),r.name=String(r.name||e.name||""),r.value===void 0&&(r.value=e.value),r.value===void 0&&(r.value=null),!r.entityType||!r.name)throw new Error("serverSet requires entityType and name")}else if(i==="serverSend"){if(r.name=String(r.name||e.name||""),r.params=Array.isArray(r.params)?r.params:Array.isArray(e.params)?e.params:[],r.target=String(r.target||e.target||"PlayerSelf"),!r.name)throw new Error("serverSend requires signal name")}else if(i==="view"&&(r.playerIndex=Number(r.playerIndex||r.viewPlayerIndex||e.playerIndex||e.viewPlayerIndex||0),!Number.isInteger(r.playerIndex)||r.playerIndex<1))throw new Error("view event requires playerIndex 1-8");return{t:bt(e.t??0,"event.t"),source:String(e.source||"user"),kind:i,payload:r}}function vn(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(!tu.has(i))throw new Error(`unsupported assert kind: ${i||"(empty)"}`);let r={kind:i};if(e.at!==void 0&&(r.at=bt(e.at,"assert.at")),i==="log"){if(r.contains=String(e.contains||e.check||e.text||""),r.source=e.source==="server"?"server":"client",e.level&&(r.level=String(e.level)),!r.contains)throw new Error("log assert requires contains")}else if(i==="control"){if(r.id=e.id?String(e.id):"",r.name=e.name?String(e.name):"",r.field=String(e.field||""),!r.field)throw new Error("control assert requires field");if(!r.id&&!r.name)throw new Error("control assert requires id or name");if(!Object.prototype.hasOwnProperty.call(e,"equals"))throw new Error("control assert requires equals");r.equals=bn(e.equals)}else if(i==="var"){if(r.entityType=String(e.entityType||""),r.name=String(e.name||""),!r.entityType||!r.name)throw new Error("var assert requires entityType and name");if(!Object.prototype.hasOwnProperty.call(e,"equals"))throw new Error("var assert requires equals");r.equals=bn(e.equals)}else if(i==="signal"){if(r.direction=e.direction==="outbound"?"outbound":"inbound",r.name=String(e.name||""),!r.name)throw new Error("signal assert requires name");e.values!==void 0&&(r.values=bn(e.values))}else if(i==="tree"){if(r.name=String(e.name||""),r.exists=e.exists!==!1,!r.name)throw new Error("tree assert requires name")}else if(i==="lua"&&(r.source=String(e.source||""),!r.source.trim()))throw new Error("lua assert requires source");return r}function jo(e){let t=0,i=[],r=[];for(let n of e){if(!n||typeof n!="object")throw new Error("queue step must be an object");if(n.do!=="start"){if(n.do==="step"){t+=bt(n.dt??vt,"step.dt");continue}if(n.do==="pointer"||n.do==="key"||n.do==="click"||n.do==="pause"||n.do==="resume"||n.do==="serverSet"||n.do==="serverSend"||n.do==="view"){i.push(Qi({...n,kind:n.do,t},i.length));continue}if(n.assert||n.check||n.kind){r.push(vn({...n.assert||n,at:n.at??t},r.length));continue}throw new Error(`unsupported queue step: ${JSON.stringify(n)}`)}}return{events:i,asserts:r,dt:vt}}function gi(e){if(Array.isArray(e)){let r=jo(e);return{format:Zi,version:1,name:"",dt:r.dt,events:r.events,asserts:r.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 r=jo(e.queue||e.steps);return{format:Zi,version:1,name:String(e.name||""),dt:Number(e.dt)>0?Number(e.dt):r.dt,events:r.events,asserts:r.asserts}}let t=(e.events||[]).map((r,n)=>Qi(r,n)),i=(e.asserts||[]).map((r,n)=>vn(r,n));return t.sort((r,n)=>r.t-n.t||0),{format:Zi,version:1,name:String(e.name||""),dt:Number(e.dt)>0?Number(e.dt):vt,playerCount:Number(e.playerCount)>0?Number(e.playerCount):1,events:t,asserts:i}}function Ho(e,t={}){let i=(e||[]).map((r,n)=>Qi(r,n));return{format:Zi,version:1,name:String(t.name||""),dt:Number(t.dt)>0?Number(t.dt):vt,playerCount:Number(t.playerCount)>0?Number(t.playerCount):1,events:i,asserts:(t.asserts||[]).map((r,n)=>vn(r,n))}}function Uo(e,t,i){if(!e)return null;let r=Qi({...t,t:t.t??i??0},e.events.length);return e.events.push(r),r}import{createCanvas as iu}from"@napi-rs/canvas";var Lo=iu(1,1).getContext("2d"),ru='"Microsoft YaHei UI","Microsoft YaHei",sans-serif',er=(e,t)=>Math.max(0,Math.min(t,Number.isFinite(e)?e:0));function Xo(e,t,i){let r=Math.max(8,Number(e.fontSize)||12),n=String(e.text??"").replace(/\r\n?/g,`
|
|
110
|
+
`),a=JSON.stringify([n,t,i,r,e.showScrollBar]),o=e._textWindowLayout;if(o?.key!==a){Lo.font=`${r}px ${ru}`;let l=p=>{let m=[];for(let g of n.split(`
|
|
111
|
+
`)){let S="";for(let C of g)S&&Lo.measureText(S+C).width>p&&(m.push(S),S=""),S+=C;m.push(S)}return m},u=l(Math.max(1,t-4)),d=e.showScrollBar!==!1&&u.length*r*1.2>i,h=Math.max(1,t-4-(d?12:0));d&&(u=l(h)),o=e._textWindowLayout={key:a,lines:u,font:r,textWidth:h,lineHeight:r*1.2,length:u.length*r*1.2}}let s=Math.max(0,o.length-i),c=er(e._scrollOffset||0,s);return e._scrollOffset=c,{...o,max:s,offset:c,viewport:i,horizontal:!1,width:t,height:i}}function $t(e,t,i){if(!e?.showBar||e.max<=0||t<=0||i<=0)return null;let r=e.horizontal===!0,n=r?t:i,a=Math.max(0,n-4),o=Math.min(a,Math.max(18,a*n/(n+e.max))),s=a-o,c=s*e.offset/e.max,l=Math.min(8,r?i:t),u=r?{x:-t/2+2,y:i/2-l-2,width:a,height:l}:{x:t/2-l-2,y:-i/2+2,width:l,height:a},d=r?{...u,x:u.x+c,width:o}:{...u,y:u.y+c,height:o};return{track:u,thumb:d,travel:s}}var Wo="https://oss.070077.xyz/",Sn="mp3-v1",tr="/qxqy-audio/",nu=[[10001,"ura.1ht4.2ag9.1hh5.jbb.k02.jcw.2tv.2wn.2xk.2r3.d5s.94l.ebv.kcr.b40.77k.9gp.97w.1hb5.jag.btu.jc9.hp5.bmj.blq.blq.ff9.ffk.o74.1owl.rp.mg.l3.lf.lh.qy.1a3z.2xk.2xk.2xk.2xk.2xk.17dc.1f2b.2bc.2bc.2bc.2bc.2bc.ffo.ffo.126.1fk.4mo.4mo.15e.1h2.237.2ba.2kd.2bc.4mo.4mo.4mo.4mo.1mc.1n6.2cu.1ud.2b1.2ee.1tj.1tk"],[20001,"o6.fh.kb.cr.og.sm.6x.8c.87.o7.vz.kt.qo.lg.ob.9w.mg.1kz.zc.1ex.1d5.ps.uu.su.qs.ys.zp.10k.15a.xc.uk.mx.1ax.nt.tu.19m.uj.1ku.tt.100.ie.d3.fp.ie.ie.d3.fp.ie.8p.7k.fw.h0.qc.ot.uc.ot.rk.gb.1c2.ff.cl.9v.wg.1ir.1lr.1b8.1ri.1p0.104.10n.mw.j6.jb.f1.dv.84.a0.cp.bx.1ko.1au.1ia.rs.rt.rs.t7.x6.wi.zc.16f.1i6.2jh.28d.qh.k8.1gz.1ko.2iv.1xp.1l4.1gk.10j.yo.1jk.1jk.xv.104.15o.1xg.1xg.1xi.25i.p1.t1.yh.1ak.1i6.1y2.xt.32u.3g6.1bz.2mn.14l.14c.1e1.op.s8.p2.v5.2ix.1a0.ry.16m.17n.13c.134.ys.yu.xr.sl.sr.sd.yh.z5.gd.gl.hx.h2.g8.fj.iy.hz.jj.th.12n.16r.d3.j9.dg.lj.fl.a7.f9.iw.el.27f.1dh.1rh.2ph.yd.w5.x5.tr.pq.zf.16h.1a5.17t.wy.vn.y8.wl.yv.2ye.2qt.1ah.163.19t.uf.119.2vv.1bm.13h.14p.1so.c3.as.9z.19w.1l4.1nl.rj.we"],[30001,"jo.my.ss.dw.c1.b4.hl.hl.hl.cz.dw.dw.b4.dw.fr.kd.qv.px.px.74.6u.8h.60.8q.8b.eo.eo.eo.8k.a5.99.12v.13y.lg.m4.qr.dw.ex.g0.ef.cd.br.11n.17h.1b8.1c9.9p.ag.9z.l9.m8.m8.lw.m8.cz.99.b4.8c.63.7f.6h.99.re.pp.pi.cq.c9.cp.ck.c6.b0.bd.al.f6.gl.ed.fs.lc.k6.kh.i6.cx.j1.hk.gb.d7.h7.g2.em.kj.kn.k4.j5.rh.t0.qt.mj.i7.ih.i2.hd.3r.8d.6u.6z.by.de.dg.cr.1a5.1ab.16c.18g.n2.ly.no.nt.f9.de.lr.fe.f0.fj.el.fo.t1.g9.ly.h3.g6.de.2ak.2f3.wf.kg.qn.11p.rg.uj.u6.11c.22o.2cs.3dp.3dq.3d5.3d6.1zx.18v"],[40001,"19x.215.2zt.1ex.2pj.7hy.1ur.1gn.1g7.1b1.u9.1tw.108.1ew.rs.1qu.w9.lk.244.qi.b6.tk.jg.jg.jg.y4.c1.b4.iv.hi.r4.n7.gy.ev.qe.12z.18n.dw.1l6.ou.wz.1un.19t.18k.yy.1hs.sl.dw.1vl.100.14k.1q8.209.1jk.1xr.ua.1j2.pr.26h.1gs.s9.px.15v.pf.1jk.xc.1hb.111.172.ut.285.1oh.149.zj.22r.2l9.14a.ok.23y.1eh.xe.1j0.1rp.1cz.wf.1mh.22k.334.1z2.1xo.1br.4ji.5nq.5nf.2za.18r.h3.eo.ia.1kn.dc.ss.s0.1bl.1oc.is.km.177.1ec.1ao.h4.hp.dx.l9.iw.i3.12w.n1.yq.12w.1ju.yx.14s.18b.22t.u3.my.2rb.36w.13u.z8.20r.18g.19r.2x9.w4.q2.1d2.wo.13a.v6.17w.ur.288.1b6.14m.1fi.1xx.1ee.kj.121.j2.1d2.2ad.1ri.2lc.1vk.138.12r.xj.1h5.1c5.2qx.1gj.t2.lv.rf.18q.1kz.dw.2aq.ia.1i9.k5.199.f4.10y.18a.xf.rk.1g9.1q3.10h.sj.15o.e3.dz.sv.135.w9.yg.aw.2a2.19m.22w.1c8.272.13o.104.1sr.rs.1pb.d5.df.kp.jq.1a7.s8.1ao.ba.rb.in.pz.q8.140.ij.1e7.jl.yk.117.10i.1tn.1oj.1sv.sj.1e3.2so.1c7.1gv.178.107.10n.1dx.1qi.1wp.2bc.218.16r.105.xc.z6.11w.1mc.1y9.17p.1cs.2ij.18c.1ie.nn.16c.1ce.xb.1ei.3j0.ve.14x.1sx.285.1b8.1at.v4.rv.rs.10z.xq.11o.15k.xq.u1.i2.pu.i4.l3.9u.oh.mc.nm.pw.1i3.1h4.pj.111.l4.lb.qq.qf.u0.h4.nk.yf.6h.ij.ds.oy.re.m8.1gl.cz.16z.a1.1f8.1x6.vp.dz.gp.g6.fr.vl.fr.gg.qc.aj.99.go.ij.fz.11a.x5.mo.1u9.h0.m8.10m.1an.2bc.3uw.2gk.124.xb.1uk.1b6.2xj.1os.11a.vs.1i9.1lr.2gv.265.668.1xg.45j.404.2x1.1io.3om.4q2.4mo.1d4.2bp.1pr.166.2y6.2bv.361.2nc.2bc.3g0.7g4.334.2bc.2xo.3uw.6ic.4ig.3uw.23v.1la.2zr.1jt.1cq.27a.1n1.19x.1qg.1jn.1ca.26y.2d6.4v4.4mo.4mo.7ps.1jk.153.1fo.1dm.1s2.1w1.oe.1lb.319.2eg.58p.4mo.3dw.2y2.2xm.1u8.1ko.12n.1e0.2sd.1md.2cl.1q2.372.4mo.48s.b14.3fu.334.334.34i.4nf.4ji.5eg.3uw.2u8.1g1.110.37x.2jo.su.334.3aj.3uw.63f.2bc.2bc.8v4.1ts.ax5.5du.34d.3oc.34j.4si.174.rt.1rp.2b0.37d.1ta.2gh.28a.22z.1nc.1a5.1pa.4dd.3ha.2cs.5mv.4mq.5c2.3uw.1gf.4md.113.10x.21o.2hj.1b3.1cx.1ol.3ar.1fv.17t.1a7.2uj.2we.1jk"],[50001,"1o8.1k1.mo.1wu.2c9.22d.1kb.23n.1b8.1ic.24c.2wz.1mq.1mu.1jx.1z1.o3.190.vp.1h7.th.4mo.1rp.4mo.4mo.7ps.zz.143.21v.1nf.34s.1s3.r9.18t.s1.r9.21w.277.ls.25k.5v1.2bc.1kh.wt.14i.1eq.15o.668.sh.rl.3wi.3vc.43c.3yn.17c.f5.xu.jg.176.19v.1xy.23m.18x.30c.10l.13k.v8.vp.17t.qj.17m.1wr.1la.8t.s7.18d.1l2.152.mx.1c8.1l4.1f5.1xe.rz.2hz.1et.13t.xb.14r.15o.z0.1zo.ur.257.1gb.li.12d.15a.132.1m1.3vu.296.1mg.11m.z0.159.mp.hd.x4.1go.ns.xh.2a7.tt.2vb.1bx.1kh.u3.11i.1y1.24e.2hp.2mn.1w6.3zm.166.14g.1mo.2v9.2rg.2f9.1r0.139.m1.k3.ys.1dy.29k.1mm.22m.3zx.4dr.2h7.22o.tv.rm.1et.2wv.2ar.1t7.ku.12s.10b.1v9.1gu.12m.1b3.tv.1c8.tk.10s.ul.1tt.ka.oi.qb.13f.13f.13k.17h.1uh.ez.en.2x7.2ln.2h8.3h8.ig.n9.27o.18b.hl.nm.uk.11a.1ta.1k4.1eh.wv.1go.1gg.sc.18u.1dz.2aq.vt.2l7.25h.1l5.1kn.1vc.1b4.28i.17t.1d6.1k2.18z.jy.jw.dh.1mx.fr.vp.35w.34z.35w.34z.4so.vf.yx.1bg.1d3.2yc.1tg.8q3.99g.am.2du.rm.rg.xa.2cw.xc.1j6.1if.18z.13a.yz.142.1z5.262.1bj.1y8.ur.u5.16j.1pf.1bi.l8.1il.3vz.2dr.jo.ls.18s.16l.18c.141.219.1yz.1fc.24t.27e.481.1vp.25h.1yq.1zn.1uw.11u.1jp.1pz.39o.t6.1mj.1u5.11l.1vd.1dk.1zb.1ic.3ql.14p.1wq.25x.267.zn.zn.1pf.13z.1j7.r9.1hb.4yp.1lt.1cw.1z4.19z.1og.1j4.1cl.1eg.u8.16s.1en.zu.1hr.1js.19g.303.22j.2oa.180.1v7.2ud.2d7.21s.3g9.vh.v1.284.3lg.3lg.17q.1h3.4mo.1cm.1rv.22i.2mc.2j3.27o.333.1q8.237.2ll.23b.2sp.2ll.2ox.2cf.2f8.2hz.1uo.y4.s9.w6.2dg.2q9.up.1m1.1vz.2n8.192.1eb.z7.2em.2q3.1sd.1gj.348.3vf.2iu.29x.1dc.7oj.4pq.5vb.4mx.5me.5sf.5yf.7ps.yj.q0.10w.13p.18b.2wd.11q.2vx.dd.iv.12p.jh.u9.1uy.w0.3f0.3bj.126.qo.1gj.11k.pu.22h.1z6.rp.y4.y0.xl.1d0.11s.wa.1a6.127.10m.12r.1nh.1fy.yo.1js.162.n4.174.1aj.y4.o8.qz.rh.qa.18s.mr.j3.ii.sr.sx.1jk.17l.mj.zr.uy.wa.19t.2bt.xe.1od.hs.xr.5b.12c.1ab.we.gz.mz.4y.sf.11s.e0.1l7.ew.h6.jz.l0.e8.1cx.p6.17u.bw.1ah.10r.10e.o9.1bc.uv.lq.tl.zb.100.jy.b8.bj.336.10n.na.sq.14r.yr.nm.123.tf.l1.zp.1xc.1vk.31l.zl.2bj.2b9.2fv.17p.y0.so.1ln.29c.1eh.nh.xn.131.qc.186.ff.fc.xq.1bm.la.l8.14f.243.111.xi.qw.1qn.11v.1ur.1jx.1ks.s9.nz.269.1zj.2zd.1pv.18n.2vk.p3.1fh.13v.1lf.1lu.2db.1sr.1k3.26o.1dl.1f3.187.2lh.166.v9.xh.1e3.119.s2.mt.1iu.1k6.1o2.12s.u4.2br.1q3.qv.1e4.1zu.1v4.1vk.1t3.3p7.1ob.14d.1ns.1ef.1e4.12w.2kk.1ba.2jx.1e0.1s5.12w.17r.14s.wz.1qp.183.3fb.188.1gr.2ot.168.1u7.w8.28o.1zd.32z.230.w7.vq.x8.1qh.19f.14o.2r9.qg.1ey.1qr.1p6.3a3.1ov.13d.tz.wk.22v.1qa.2l9.yw.yf.nw.p6.1ly.1jk.1nh.x9.q0.17r.17h.ux.uw.12y.p7.g7.kt.14c.ze.1kh.1eo.18a.1d8.26j.15k.19f.1ym.1j5.1c6.11k.1sd.1jp.1ws.13s.1o5.214.sx.px.20x.14h.1ja.s6.1q8.w8.1ks.so.ub.121.202.1ej.1g1.1s8.2bc.4t1.bih.3uw.3pb.avp.6c7.bko.5eg.79c.6wh.3wd.4pn.55j.4a5.3gg.bko.5ei.52p.578.bcv.6gr.2bc.4j9.5y7.9d2.2bb.2bc.668.73z.5pg.50f.5m7.788.267.642.8h2.8h2.49s.64g.5e8.5e8.2bb.3ih.5ur.6bk.578.4ck.3sg.5fe.23i.e9w.2b8.5oj.6bw.2al.2rk.2rk.5pj.n6e.350.6v9.70t.639.3uw.3uw.2bg.639.2bb.2bd.6gj.2bh.660.578.3bk.65e.359.3o0.44i.4tn.1zq.5ee.4a5.3zu.rs.639.33q.5eg.1k1.15o.dw.3uw.b7p.7qd.898.4l4.5uu.5uu.b4g.2yh.2yh.3uw.51a.51a.5kk.66f.iq9.3n7.4nb.46a.1wb.20p.bih.8xa.7ps.70t.70t.4rv.5p1.6aq.ts.63z.668.5v2.5nu.563.55s.55s.5p3.2ga.32x.42x.5cr.4c2.71b.5zp.5c2.66t.4c8.2bc.2bc.2gn.3ea.2kp.fz6.8hz.3e8.4an.bko.j7e.jag.7sr.2bc.3zx.7qd.5ut.5jp.2wk.5q7.3uw.334.4i3.3uw.4bd.5eu.46h.4i2.6t4.446.5s7.5cg.4bk.5nd.7bf.4rt.23b.2bc.2bc.2bc.2bc.2ba.4mo.4dv.3wn.2bc.1we.4he.2bc.4gz.3wn.3km.4xy.4hi.4mr.2bc.247.3yj.2c6.2bc.3aj.446.4ub.3uw.51.e0.86.is.i1.hg.mn.m4.2c.7h.sg.e3.jb.7r.eq.nf.u0.60.4o.ke.47.47.47.47.b8.4x.dr.dy.rw.rw.59.8j.5z.a5.l3.c0.ik.f7.li.lr.7x.dv.du.dd.5e.91.1b.ce.cc.59.bh.e6.8m.9n.cl.lt.7ip.4mr.4si.4kf.vo.we.13e.17n.1iw.2pi.lp.r6.gw.7x.xz.qt.bq.ls.q1.eh.bx.cr.3c.j7.b8.fz.4k.8p.bg.5w.iy.j3.12o.rs.cz.dp.yz.jk.63.63.7ps.7ps.7ps.40g.3jp.4tw.89k.88a.7s0.83d.668.7ps.2fw.2ev.2fp.7ps.2jb.2dh.2ud.25i.24c.2bt.1pa.17r.1a7.7ps.7pt.5rg.4nl.3vv.7qo.31a.2p0.2k0.49a.3v4.3nl.1ug.1ug.1l6.7s1.7ps.2cp.2f8.2i7.7ps.28q.2be.275.1ma.1oz.1q7.16s.1iq.1e0.78m.7ps.2bc.2bc.2bc.bko.2wu.2wu.2wu.3b4.38f.3uw.3uw.3uw.3uw.7ps.7qa.32n.2gg.2wk.7rv.1v3.1qq.1rb.1zk.1my.1zp.1yn.1oh.1uh.7st.9q.9q.9q.9q.9q.kk.kk.kk.kk.kk.dw.dp.dw.rs.rs.rs.rs.s4.sd.54j.5n8.2n6.21r.1nu.1o5.14u.t6.3f7.2j0.32c.304.189.1gf.18w.18j.1st.1vq.116.kw.3uw.3uw.vr.zx.xc.tc.7d.7r.9d.9w.8s.9p.3b.3b"]].map(([e,t])=>[e,t.split(".").map(i=>parseInt(i,36)/1e3)]);function ir(e){if(!Number.isSafeInteger(e))return null;for(let[t,i]of nu)if(e>=t&&e<t+i.length)return i[e-t];return null}var rr=e=>Number.isFinite(Number(e))?Math.max(0,Number(e)):0;function nr(e,t){if(!e||e.kind!=="image"||e.enableMask!==!0||!t)return null;let i=rr(e.sourceWidth??e.width),r=rr(e.sourceHeight??e.height),n=e.enableSoftEdge===!0,a=e.softEdgeMode!=="Pixel",o=n?rr(e.softEdgeWidthX):0,s=n?rr(e.softEdgeWidthY):0;return{id:e.id,matrix:t,width:i,height:r,featherX:a?i*o/100:o,featherY:a?r*s/100:s}}function Ko(e,t,i){let r=xe(e,t,i);return{a:e.a,b:e.b,c:e.c,d:e.d,tx:r.x,ty:r.y}}function qo(e,t,i){let r=(n,a)=>n<=0?0:!(a>0)||n>=a?1:n/a;return Math.min(r(e+i.width/2,i.featherX),r(i.width/2-e,i.featherX),r(t+i.height/2,i.featherY),r(i.height/2-t,i.featherY))}function Jo(e){let t={children:[]},i=[t],r=[];for(let n of e||[]){if(!n||n.id==null)continue;let a=n.masks||[],o=a.map(c=>JSON.stringify([c.id,c.matrix,c.width,c.height,c.featherX,c.featherY])),s=0;for(;s<r.length&&s<o.length&&r[s]===o[s];)s++;i.length=s+1;for(let c=s;c<a.length;c++){let l={mask:a[c],children:[]};i.at(-1).children.push(l),i.push(l)}i.at(-1).children.push({item:n}),r=o}return t.children}import{randomUUID as ts}from"node:crypto";function sr(e){for(let t of e.runtime.scrollControls||[]){let[i,r]=si(t),n=t.kind==="grid"?Ot(t):Xo(t,i,r),a={offset:n.offset,max:n.max,horizontal:n.horizontal,showBar:t.showScrollBar!==!1,textWidth:n.textWidth??0,lines:n.lines||[],lineHeight:n.lineHeight||0,contentLength:n.length},o=JSON.stringify(a);t._scrollKey!==o&&(t._scrollKey=o,t._scroll=a,t.markPlayDirty())}}function is(e){return{...e._scroll?{scroll:e._scroll}:{},...e.parent?._gridItems?.includes(e)?{clipToParent:!0}:{}}}function wn(e,t){let i=e._scroll?.max||0;e.kind==="grid"?e.scrollProgress=i?er(t,i)/i:0:e._scrollOffset=er(t,i),e.markPlayDirty()}var au=Object.freeze(Object.values(K).map(e=>Object.freeze({id:e.id,label:e.label,platform:e.platform,width:e.width,height:e.height})));function lr(e){sr(e);let t=ye({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),i=new Map;function r(n,a,o){let s=Be(a,n);s.activeInHierarchy=o&&n.active!==!1,i.set(n.Id,s);let c=s.activeInHierarchy;for(let l of n.children)r(l,s,c)}for(let n of e.runtime.roots)r(n,t,!0);return i}function rs(e,t=lr(e)){let i=new Map;function r(n,a){let o=t.get(n.Id);if(!o)return;let s=ti(a,o,n);i.set(n.Id,s);for(let c of n.children)r(c,s)}for(let n of e.runtime.roots)r(n,Pt());return i}function ns(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,...e._scroll?{scrollOffset:e._scroll.offset,scrollMax:e._scroll.max}:{},...e.kind==="grid"?{itemCount:e.itemCount,scrollProgress:e.scrollProgress}:{},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,imageSource:e.kind==="image"?Ie(e.imageSource):null,imageType:e.kind==="image"?e.imageType==null?null:Me(e.imageType):null,primitive:e.kind==="image"?At(e.imageId,e.imageSource):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(r=>ns(r,t))}}function ou(){return{pointerDownControl:null,pointerDownPosition:null,pointerLastPosition:null,pointerDragging:!1,pointerHoverControl:null,pointerScroll:null,hoveredControl:null,selectedControl:null,stateRestores:new Map,viewCache:null}}function su(e,t,i,r){let n=fi({canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight,device:e.device,audioDuration:ir,canSelectImageType:ma,...r?{language:r}:{}});for(let a of[...e.templates||[],...t?.templates||[]])Number.isSafeInteger(a.prefabIndex)&&a.prefabIndex>0&&n.registerTemplate(a.prefabIndex,a);for(let a of i){let o=a.path||a.id,s=a.source||"";o&&s&&n.registerScriptFile(o,s)}return n}var lu=["pointerDownControl","pointerDownPosition","pointerLastPosition","pointerDragging","pointerHoverControl","pointerScroll","hoveredControl","selectedControl","stateRestores","viewCache"];function cu(e){Object.defineProperty(e,"runtime",{configurable:!0,enumerable:!0,get(){return e.runtimes[e.viewPlayerIndex-1]}});for(let t of lu)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 as(e,{templatesProject:t=null,scripts:i=[],sceneScripts:r=null,templateScripts:n=null,serverConfig:a=null,canvasId:o="",playerCount:s=1,viewPlayerIndex:c=1,language:l=""}={}){let u=r||i,d=n||i,h=yn(e,u,o),p=t?yn(t,d,o):null,m=gt(s),g=Xe(c,m),S=Bo({playerCount:m,viewPlayerIndex:g});a&&S.loadConfig({...a,playerCount:m,viewPlayerIndex:g});let C=[];for(let N=0;N<m;N+=1)C.push(su(h,p,i,l));S.attachRuntimes(C);for(let N of C)N.addRoot(h.root);let I={audioSessionId:ts(),runtimes:C,views:C.map(()=>ou()),playerCount:m,viewPlayerIndex:g,server:S,compiled:h,mountError:C.find(N=>N.mountErrors[0])?.mountErrors[0]||null,debugPaused:!1,history:{events:[]},recording:!0};cu(I);let P=I.viewPlayerIndex;for(let N=1;N<=m;N+=1)I.viewPlayerIndex=N,Su(I);return I.viewPlayerIndex=P,I}function kn(e,t){if(!e)throw new Error("play session has not started");let i=Xe(t,e.playerCount);return i===e.viewPlayerIndex||(at(e,{kind:"view",payload:{playerIndex:i}}),e.viewPlayerIndex=i,e.viewCache=null,e.server&&e.server.setViewPlayerIndex(i)),i}function at(e,t){!e?.recording||!e.history||Uo(e.history,{...t,source:t.source||"user"},e.runtime.clock.time)}function uu(e){return e?.history?.events||[]}var En=new Set(["image","textbox","textwindow","button","grid"]);function fu(e,t){let i=xe(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 Me(e){return typeof e=="string"?e:e?.Name}function os(e){return{fillType:Me(e.fillType),fillHorizontalType:Me(e.fillHorizontalType),fillVerticalType:Me(e.fillVerticalType),fillAmount:e.fillAmount}}function du(e,t,i){let r=Math.abs(t.width*i.scaleX),n=Math.abs(t.height*i.scaleY),a={id:e.Id,kind:e.kind,name:e.name,left:i.centerX-r/2,bottom:i.centerY-n/2,width:r,height:n,sourceWidth:t.width,sourceHeight:t.height,rotationZ:i.rotationZ,matrix:i.matrix,pressed:e.pressed===!0,...is(e)};return e.kind==="image"&&(a.imageSource=Ie(e.imageSource),a.imageType=e.imageType==null?null:Me(e.imageType),a.primitive=At(e.imageId,a.imageSource),a.imageColor=e.imageColor,a.imageId=e.imageId,Object.assign(a,os(e))),(e.kind==="textbox"||e.kind==="textwindow")&&(a.text=e.text??"",a.fontSize=e.fontSize,a.fontColor=e.fontColor,a.bgColor=e.bgColor,a.enableOutline=e.enableOutline===!0,a.outlineColor=e.outlineColor,a.horizontalAlignment=Me(e.horizontalAlignment),a.verticalAlignment=Me(e.verticalAlignment)),a}function hu(e,t=lr(e)){let i=[],r=rs(e,t);function n(a,o=[],s=[]){let c=t.get(a.Id);if(!c||a.visible===!1||!c.activeInHierarchy)return;let l=r.get(a.Id);if(!l)return;let u=fu(c,l),d=a.kind==="image"&&a.enableMask===!0?nr({...ss(a,c),id:a.Id},Ko(l,c.centerX,c.centerY)):null,h=d?[...s,d]:s,p=()=>i.push({...du(a,c,u),...o.length?{clipPolygons:o}:{},...h.length?{masks:h}:{}});En.has(a.kind)&&a.kind!=="grid"&&p();let m=a.children||[];for(let g=m.length-1;g>=0;g-=1){let S=a._gridItems?.includes(m[g])?[...o,[[c.left,c.bottom],[c.right,c.bottom],[c.right,c.top],[c.left,c.top]].map(([C,I])=>xe(l,C,I))]:o;n(m[g],S,h)}a.kind==="grid"&&p()}for(let a of e.runtime.roots)n(a);return i}function ss(e,t){let i={kind:e.kind,name:e.name,sourceWidth:t.width,sourceHeight:t.height,pressed:e.pressed===!0,...is(e)};return e.kind==="image"&&(i.imageSource=Ie(e.imageSource),i.imageType=e.imageType==null?null:Me(e.imageType),i.primitive=At(e.imageId,i.imageSource),i.imageColor=e.imageColor,i.imageId=e.imageId,Object.assign(i,os(e),{enableMask:e.enableMask===!0,enableSoftEdge:e.enableSoftEdge===!0,softEdgeMode:Me(e.softEdgeMode)||"Percentage",softEdgeWidthX:e.softEdgeWidthX,softEdgeWidthY:e.softEdgeWidthY})),(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=Me(e.horizontalAlignment),i.verticalAlignment=Me(e.verticalAlignment)),i}function mu(e,t,i){let r=Mr(e,t),n=xe(r,e.centerX,e.centerY);return{a:r.a,b:r.b,c:r.c,d:r.d,tx:n.x-(i?i.centerX:0),ty:n.y-(i?i.centerY:0)}}function ls(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.imageSource,e.imageType,e.fillType,e.fillHorizontalType,e.fillVerticalType,e.fillAmount,e.enableMask,e.enableSoftEdge,e.softEdgeMode,e.softEdgeWidthX,e.softEdgeWidthY,e.text,e.fontSize,e.fontColor,e.bgColor,e.enableOutline,e.outlineColor,e.horizontalAlignment,e.verticalAlignment,JSON.stringify(e.scroll),e.clipToParent].join(" ")}function cs(e,t,i,r,n,a){return{id:e.Id,parent:t,z:n,group:a>=16,matrix:mu(r,e,i),...ss(e,r)}}function pu(e){let t=ye({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),i=new Set,r=new Map,n=new Map;function a(c,l,u){let d=Be(l,c);if(d.activeInHierarchy=u&&c.active!==!1,n.set(c.Id,d),c.visible===!1||!d.activeInHierarchy)return!1;let h=c.children||[],p=En.has(c.kind),m=0;for(let g=0;g<h.length;g+=1)a(h[g],d,d.activeInHierarchy)&&(p=!0,m+=1);return p?(i.add(c.Id),r.set(c.Id,m),!0):!1}function o(c,l,u,d){if(!i.has(c.Id))return;let h=n.get(c.Id);s.push(cs(c,l,u,h,d,r.get(c.Id)||0));let p=c.children||[];for(let m=0;m<p.length;m+=1)o(p[m],c.Id,h,m)}let s=[];for(let c=0;c<e.runtime.roots.length;c+=1)a(e.runtime.roots[c],t,!0),o(e.runtime.roots[c],null,null,c);return{nodes:s,childCounts:r}}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 r=0;r<i.length;r+=1)xn(i[r])}function gu(e,t){let i=ye({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),r=[],n=[],a=t.count,o=e.runtime._playRemoved||[];for(let l=0;l<o.length;l+=1){let u=o[l];t.fingerprints.has(u)&&(n.push(u),t.fingerprints.delete(u),t.childCounts.delete(u),a-=1)}e.runtime._playRemoved=[];function s(l){t.fingerprints.has(l.Id)&&(n.push(l.Id),t.fingerprints.delete(l.Id),t.childCounts.delete(l.Id),a-=1);let u=l.children;for(let d=0;d<u.length;d+=1)s(u[d])}function c(l,u,d,h,p,m){let g=m||l._playDeepDirty===!0,S=g||l._playDirty===!0,C=g||l._playChildDirty===!0;if(!S&&!C)return;if(!(p&&l.active!==!1)||l.visible===!1){s(l);return}let P=Be(u,l),N=t.childCounts.get(l.Id)||0;if(C){N=0;let A=l.children;for(let w=0;w<A.length;w+=1)c(A[w],P,l.Id,w,!0,g),t.fingerprints.has(A[w].Id)&&(N+=1)}if(!(En.has(l.kind)||N>0)){t.fingerprints.has(l.Id)&&(n.push(l.Id),t.fingerprints.delete(l.Id),t.childCounts.delete(l.Id),a-=1);return}let j=t.childCounts.get(l.Id);t.childCounts.set(l.Id,N);let B=N>=16!=(j||0)>=16;if(!S&&!B&&t.fingerprints.has(l.Id))return;let z=cs(l,d,u===i?null:u,P,h,N),b=ls(z);t.fingerprints.get(z.id)!==b&&(t.fingerprints.has(z.id)||(a+=1),t.fingerprints.set(z.id,b),r.push(z))}for(let l=0;l<e.runtime.roots.length;l+=1)c(e.runtime.roots[l],i,null,l,!0,!1);return t.count=a,{changed:r,removed:n,count:a}}function yu(e,t){let i=e.viewCache||(e.viewCache={rev:0,fingerprints:new Map,childCounts:new Map,count:0}),r=Number(t);if(!(Number.isFinite(r)&&r===i.rev&&i.fingerprints.size>0)){let{nodes:c,childCounts:l}=pu(e);i.rev+=1,i.fingerprints=new Map(c.map(u=>[u.id,ls(u)])),i.childCounts=l,i.count=c.length;for(let u of e.runtime.roots)xn(u);return{format:"tree-v1",revision:i.rev,reset:!0,count:c.length,nodes:c}}let{changed:a,removed:o,count:s}=gu(e,i);i.rev+=1;for(let c of e.runtime.roots)xn(c);return{format:"tree-v1",revision:i.rev,reset:!1,count:s,changed:a,removed:o}}function An(e,{inspect:t=!1,view:i=!1,paint:r=!1,sceneRev:n,compact:a=!1}={}){sr(e),e.audioSessionId||=ts();let o=e.runtime,s=e.compiled,[c,l]=[o.canvasWidth,o.canvasHeight];e.server&&e.server.setClock(o.clock.time);let u=a?o.logs.slice(-100):o.logs,d=uu(e),h=e.server?e.server.snapshot():{vars:{},inbound:[],outbound:[],logs:[]};a&&(h.inbound=h.inbound.slice(-100),h.outbound=h.outbound.slice(-100),h.logs=h.logs.slice(-100));let p={canvasId:s.canvasId,platform:s.platform,device:o.device,canvasWidth:c,canvasHeight:l,canvasPresets:au,playerCount:e.playerCount||1,viewPlayerIndex:e.viewPlayerIndex||1,players:Array.from({length:e.playerCount||1},(m,g)=>({index:g+1,label:`\u73A9\u5BB6${g+1}`,entityType:`Player${g+1}`})),time:o.clock.time,frame:o.clock.frame,paused:!!e.debugPaused,levelTimePaused:!!o.clock.paused,audio:{sessionId:e.audioSessionId,playerIndex:e.viewPlayerIndex||1,...o.audioSnapshot()},mountError:e.mountError||o.mountErrors[0]||null,logs:u.map(m=>({source:"client",level:m.level,text:m.text,time:m.time})),tree:[],paint:[],scene:null,server:h,history:(a?d.slice(-100):d).map(m=>({t:m.t,source:m.source||"user",kind:m.kind,payload:m.payload||{}}))};if(t||r){let m=lr(e);t&&(p.tree=o.roots.map(g=>ns(g,m))),r&&(p.paint=hu(e,m))}return i&&(p.scene=yu(e,n)),_t(p),p}function cr(e,t=1/30){let i=e.runtimes||(e.runtime?[e.runtime]:[]);for(let r of i)r.step(t);e.server&&(e.server.setClock(e.runtime.clock.time),e.server.flush())}function _n(e,t){at(e,{kind:"key",payload:{typeName:String(t)}}),e.runtime.injectKey(t)}function bu(e,t){let i=null;for(let r of e.runtime.roots)Ge(r,n=>{!i&&n.name===t&&(i=n)});return i}function Pn(e,t){at(e,{kind:"click",payload:{name:String(t)}});let i=bu(e,t);i&&Tn(i)&&(i.kind==="button"||i.kind==="cursor")&&i.SimulateCursorClick()}function vu(e,t){return!e||!t?null:e.children.find(i=>i.authoringId===t||i.Id===t)||null}var us={unavailable:"unavailableChildId",hover:"hoverChildId",pressed:"pressedChildId",selected:"selectedChildId"};function fs(e,t){let i=[];for(let[r,n]of Object.entries(us)){let a=t[n]?vu(t,t[n]):null;a&&i.push({state:r,child:a})}return i}function Su(e){for(let t of e.runtime.roots)Ge(t,i=>{if(i.kind==="button"){for(let{child:r}of fs(e,i))e.stateRestores.has(r.Id)||e.stateRestores.set(r.Id,{child:r,active:r.active,visible:r.visible}),r.active=!0,r.visible=!1,typeof r.markPlayDirty=="function"&&r.markPlayDirty(!0);yi(e,i)}})}function yi(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 r of fs(e,t))r.child.active=!0,r.child.visible=r.state===i,typeof r.child.markPlayDirty=="function"&&r.child.markPlayDirty(!0)}function In(e){if(!e)return null;let t=e.parent;return t?.kind==="button"&&Object.values(us).map(r=>t[r]).filter(Boolean).includes(e.authoringId)?t:e}function Tn(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 ds(e){return e.kind==="container"||e.kind==="grid"||e.kind==="textwindow"||e.kind==="reference"||e.kind==="button"}function hs(e,t){let i=e.Id,r=t.get(i);if(r!==void 0)return r;let n=Tn(e);if(!n&&ds(e)){let a=e.children;for(let o=0;o<a.length;o+=1)if(hs(a[o],t)){n=!0;break}}return t.set(i,n),n}function ar(e,t,i){sr(e);let r=ye({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),n=new Map;function a(s,c,l,u){if(!u||s.active===!1||s.visible===!1||!hs(s,n))return null;let d=Be(c,s),h=ti(l,d,s),p=je(h);if(!p)return null;let m=xe(p,t,i);if(m.x<d.left||m.x>d.right||m.y<d.bottom||m.y>d.top)return null;if(or(s)){let g=$t(s._scroll,d.width,d.height)?.track,S=m.x-d.centerX,C=d.centerY-m.y;if(g&&S>=g.x&&S<=g.x+g.width&&C>=g.y&&C<=g.y+g.height)return s}if(ds(s))for(let g=0;g<s.children.length;g+=1){let S=a(s.children[g],d,h,!0);if(S)return S}return Tn(s)?s:null}let o=Pt();for(let s=e.runtime.roots.length-1;s>=0;s-=1){let c=a(e.runtime.roots[s],r,o,!0);if(c)return c}return null}function Gt(e,t,i,{dragging:r=!1,press:n=null,previous:a=null}={}){let o=n||{x:t,y:i},s=a||{x:t,y:i};return e.runtime.makeCursorEventData({x:t,y:i,pressX:o.x,pressY:o.y,deltaX:t-s.x,deltaY:i-s.y,dragging:r})}function Cn(e,t,i){t.kind==="grid"||t.kind==="textwindow"||(t.pressed=i,typeof t.markPlayDirty=="function"&&t.markPlayDirty(),yi(e,t))}function or(e){if(!e?.alive||!e.activeInHierarchy||e.interactable===!1||e.raycastTarget===!1)return!1;for(let t=e;t;t=t.parent)if(t.visible===!1)return!1;return e._scroll?.max>0}function Zo(e){for(let t=e;t;t=t.parent)if(or(t))return t;return null}function Qo(e,t,i,r){let n=lr(e),a=n.get(t.Id),o=rs(e,n).get(t.Id),s=o&&je(o);if(!a||!s)return null;let c=xe(s,i,r);return{x:c.x-a.centerX,y:a.centerY-c.y,width:a.width,height:a.height}}function es(e,t,i){let r=e.pointerDownControl;if(r?.alive){let n=Gt(e,t,i,{dragging:e.pointerDragging,press:e.pointerDownPosition,previous:e.pointerLastPosition});e.runtime.injectCursor(r,"CursorUp",n),e.pointerDragging&&!e.pointerScroll&&e.runtime.injectCursor(r,"CursorEndDrag",n),Cn(e,r,!1)}e.pointerDownControl=null,e.pointerScroll=null,e.pointerDownPosition=null,e.pointerDragging=!1,e.pointerLastPosition={x:t,y:i}}function bi(e,t,i,r,n={}){let a=Number(i),o=Number(r);if(!Number.isFinite(a)||!Number.isFinite(o))throw new Error("pointer coordinates must be finite");e.runtime.cursor.x=a,e.runtime.cursor.y=o;let s=Number(n.deltaX??0),c=Number(n.deltaY??0);if(t==="wheel"&&(!Number.isFinite(s)||!Number.isFinite(c)))throw new Error("wheel deltas must be finite");if(n.silent||at(e,{kind:"pointer",payload:{type:t,x:a,y:o,...t==="wheel"?{deltaX:s,deltaY:c}:{}}}),t==="wheel"){let l=ar(e,a,o),u=Zo(l);if(u){let d=u._scroll.horizontal&&s||c;wn(u,u._scroll.offset+d)}return l}if(t==="cancel")return es(e,a,o),null;if((t==="move"||t==="up")&&e.pointerScroll&&!or(e.pointerScroll.control)&&es(e,a,o),t==="move"){let l=e.pointerLastPosition||{x:a,y:o},u=e.pointerHoverControl,d=In(ar(e,a,o)),h=Gt(e,a,o,{previous:l});u&&u!==d&&e.runtime.injectCursor(u,"CursorExit",h),d&&u!==d&&e.runtime.injectCursor(d,"CursorEnter",h),e.pointerHoverControl=d;let p=e.hoveredControl;e.hoveredControl=d?.kind==="button"?d:null,p&&p!==e.hoveredControl&&yi(e,p),e.hoveredControl&&yi(e,e.hoveredControl);let m=e.pointerDownControl,g=e.pointerScroll;if(g)if(!or(g.control))e.pointerScroll=null;else{let S=Qo(e,g.control,a,o);if(S){let C=g.control._scroll,I=C.horizontal?S.x-g.start.x:S.y-g.start.y,P=$t(C,S.width,S.height)?.travel||0,N=g.bar?P?I*C.max/P:0:-I;wn(g.control,g.offset+N)}}if(m?.alive){let S=e.pointerDownPosition||l,C=a!==l.x||o!==l.y;!e.pointerDragging&&C&&(g||e.runtime.injectCursor(m,"CursorBeginDrag",Gt(e,a,o,{press:S,previous:l,dragging:!1})),e.pointerDragging=!0),e.pointerDragging&&!g&&e.runtime.injectCursor(m,"CursorDrag",Gt(e,a,o,{press:S,previous:l,dragging:!0}))}return e.pointerLastPosition={x:a,y:o},d}if(t==="down"){let l=In(ar(e,a,o));e.pointerDownControl=l,e.pointerDownPosition={x:a,y:o},e.pointerLastPosition={x:a,y:o},e.pointerDragging=!1,e.pointerScroll=null;let u=Zo(l);if(u){let d=Qo(e,u,a,o),h=d&&$t(u._scroll,d.width,d.height),p=g=>d.x>=g.x&&d.x<=g.x+g.width&&d.y>=g.y&&d.y<=g.y+g.height,m=h&&p(h.track);if(m&&!p(h.thumb)){let g=u._scroll.horizontal?d.x-h.track.x-h.thumb.width/2:d.y-h.track.y-h.thumb.height/2;wn(u,h.travel?g/h.travel*u._scroll.max:0),sr(e)}d&&(e.pointerScroll={control:u,start:d,offset:u._scroll.offset,bar:!!m})}return l&&(Cn(e,l,!0),e.runtime.injectCursor(l,"CursorDown",Gt(e,a,o))),l}if(t==="up"){let l=e.pointerDownControl,u=In(ar(e,a,o));if(l?.alive){let d=Gt(e,a,o,{press:e.pointerDownPosition,previous:e.pointerLastPosition,dragging:e.pointerDragging});if(e.runtime.injectCursor(l,"CursorUp",d),e.pointerDragging)e.pointerScroll||e.runtime.injectCursor(l,"CursorEndDrag",d);else if(u===l&&!e.pointerScroll?.bar){e.runtime.injectCursor(l,"CursorClick",d);let h=e.selectedControl;e.selectedControl=l.kind==="button"?l:null,h&&h!==e.selectedControl&&yi(e,h)}Cn(e,l,!1)}return e.pointerDownControl=null,e.pointerDownPosition=null,e.pointerLastPosition={x:a,y:o},e.pointerDragging=!1,e.pointerScroll=null,u}if(t==="click")return bi(e,"down",a,o,{silent:!0}),bi(e,"up",a,o,{silent:!0});throw new Error(`unknown pointer type ${t}`)}function Rn(e,t,i,r){if(!e?.server)throw new Error("play session has no server");return at(e,{kind:"serverSet",payload:{entityType:t,name:i,value:r,playerIndex:e.viewPlayerIndex}}),e.server.setVar(t,i,r,{playerIndex:e.viewPlayerIndex})}function ms(e,t,i){if(!e?.server)throw new Error("play session has no server");let r=e.server.getVar(t,i,{playerIndex:e.viewPlayerIndex});return r===void 0?null:r}function Mn(e,t,i=[],r="PlayerSelf"){if(!e?.server)throw new Error("play session has no server");return at(e,{kind:"serverSend",payload:{name:t,params:i,target:r,playerIndex:e.viewPlayerIndex}}),e.server.sendToClient(t,i,{target:r,playerIndex:e.viewPlayerIndex})}function ur(e){return{snapshot:t=>An(e,t),step:t=>cr(e,t),pointer:(t,i,r,n)=>bi(e,t,i,r,n),key:t=>_n(e,t),click:t=>Pn(e,t),view:t=>kn(e,t),pause:()=>{at(e,{kind:"pause",payload:{}}),e.debugPaused=!0},resume:()=>{at(e,{kind:"resume",payload:{}}),e.debugPaused=!1},serverSet:(t,i,r)=>Rn(e,t,i,r),serverSend:(t,i,r)=>Mn(e,t,i,r)}}function Nn(e){e?.server&&e.server.destroy();let t=e?.runtimes||(e?.runtime?[e.runtime]:[]);for(let i of t)i.destroy()}function On(e,t){return JSON.stringify(e)===JSON.stringify(t)}function ps(e,t){for(let i of e||[])t(i),i.children?.length&&ps(i.children,t)}function Fn(e,{id:t,name:i}){let r=null;return ps(e,n=>{r||(t&&String(n.id)===String(t)||!t&&i&&n.name===i)&&(r=n)}),r}function wu(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 Iu(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=Fn(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(r=>({name:r.name,values:r.values}))}}}function xu(e,t){if(e.kind==="log"){let i=e.source==="server"?t.server?.logs||t.serverLogs||[]:t.logs||[];return i.some(n=>e.level&&n.level!==e.level?!1:String(n.text||"").includes(e.contains))?{ok:!0,actual:e.contains}:{ok:!1,actual:i.map(n=>n.text).slice(-8),expected:e.contains}}if(e.kind==="control"){let i=Fn(t.tree,e);if(!i)return{ok:!1,actual:null,expected:e.equals,message:`control not found: ${e.id||e.name}`};let r=wu(i,e.field);return On(r,e.equals)?{ok:!0,actual:r}:{ok:!1,actual:r,expected:e.equals}}if(e.kind==="var"){let i=t.server?.vars?.[e.entityType],n=!i||!Object.prototype.hasOwnProperty.call(i,e.name)?null:i[e.name].value;return On(n,e.equals)?{ok:!0,actual:n}:{ok:!1,actual:n,expected:e.equals}}if(e.kind==="signal"){let i=e.direction==="outbound"?t.server?.outbound||[]:t.server?.inbound||[],r=i.find(n=>n.name===e.name&&(e.values===void 0||On(n.values,e.values)));return r?{ok:!0,actual:r.values}:{ok:!1,actual:i.map(n=>({name:n.name,values:n.values})),expected:{name:e.name,values:e.values??null}}}if(e.kind==="tree"){let i=!!Fn(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 Cu(e,t){let i=fi();try{return i.evalQueryScript(e,Iu(t)),{ok:!0,actual:!0}}catch(r){return{ok:!1,message:r?.message||String(r)}}finally{i.destroy()}}function gs(e,t){return e.kind==="lua"?Cu(e.source,t):xu(e,t)}function ku(e,t){let i=t>0?t:vt;return Math.round((e+i)*1e9)/1e9}function Eu(e,t){let i=t.payload||{};if(t.kind==="pointer")e.pointer(i.type,i.x,i.y,i);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 Au(e,t){let i=gs(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 ys(e,t){let i=gi(t),r=i.events.slice().sort((C,I)=>C.t-I.t),n=i.asserts.slice(),a=i.dt||vt,o=r.reduce((C,I)=>Math.max(C,I.t),0),s=n.reduce((C,I)=>Math.max(C,Number(I.at||0)),0),c=Math.max(o,s),l=0,u=[],d=0,h=n.some(C=>C.kind==="control"||C.kind==="tree"||C.kind==="lua"),p=e.snapshot({inspect:h}),m=()=>{for(;l<r.length&&r[l].t<=d+1e-9;)Eu(e,r[l]),l+=1,p=e.snapshot({inspect:h})},g=()=>{for(let C of n)if(!C._done&&Number(C.at||0)<=d+1e-9){let I=Au(C,p);if(u.push(I),C._done=!0,!I.ok)return{passed:!1,failedAt:d,frame:p.frame||0,results:u,snapshot:p}}return null};m();let S=g();if(S)return Dn(i,S);for(;d+1e-9<c;){e.step(a),d=ku(d,a),p=e.snapshot({inspect:h}),m();let C=g();if(C)return Dn(i,C)}return Dn(i,{passed:u.every(C=>C.ok),failedAt:null,frame:p.frame||0,results:u,snapshot:p})}function Dn(e,t){return V({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 zn(e){return Array.isArray(e)?e.slice():[]}var Nu={Level:"\u5173\u5361",PlayerSelf:"\u5F53\u524D\u73A9\u5BB6",AvatarSelf:"\u5F53\u524D\u89D2\u8272",...Object.fromEntries(yt.map((e,t)=>[e,`\u73A9\u5BB6${t+1}`])),...Object.fromEntries(Array.from({length:8},(e,t)=>[`Avatar${t+1}`,`\u89D2\u8272${t+1}`]))};function Ou(e,t=1){let i=e?.vars||{},r=[],n=Number(t)>0?Number(t):1,a=["Level","PlayerSelf","AvatarSelf"];if(n>1)for(let s=1;s<=n;s+=1)a.push(`Player${s}`,`Avatar${s}`);let o=new Set;for(let s of a){if(o.has(s)||!i[s])continue;o.add(s);let c=i[s]||{};for(let l of Object.keys(c))r.push(V({entityType:s,entityLabel:Nu[s]||s,name:l,type:c[l]?.type||"",value:c[l]?.value??null}))}return r}var wt="qxqy-simulator-save",Fu="qxqy-simulator-scripts",se="server-control-template",L="client-control-template",$n={[se]:"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F",[L]:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"};function St(e){return e===L?"client":"server"}function fr(e){if(!(typeof e=="number"||typeof e=="string"&&/^\d+$/.test(e.trim()))||!Pe(e))throw new Error("\u63A7\u4EF6\u7D22\u5F15\u5FC5\u987B\u662F 1\u20132147483647 \u8303\u56F4\u5185\u7684\u6574\u6570");return Number(e)}function Gn(e=[]){if(!Array.isArray(e))throw new Error("controlGuidChanges \u5FC5\u987B\u662F\u6570\u7EC4");let t=new Set;return e.map(i=>{if(!i||typeof i.id!="string"||!i.id||t.has(i.id)||![se,L].includes(i.controlAsset)||typeof i.controlId!="string"||!i.controlId||typeof i.controlName!="string")throw new Error("controlGuidChanges \u5305\u542B\u65E0\u6548\u6216\u91CD\u590D\u7684\u53D8\u66F4\u8BB0\u5F55");return t.add(i.id),{id:i.id,controlAsset:i.controlAsset,controlId:i.controlId,controlName:i.controlName,oldGuid:fr(i.oldGuid),newGuid:fr(i.newGuid)}})}function Du(e){let t=[e?.guid,e?.id];for(let i of t){let r=Number(i);if(Number.isSafeInteger(r)&&r>0&&r<=2147483647)return r}return 0}function dr(e){let t=String(e?.controlAsset||""),i=Du(e);return{id:String(i||e?.id||""),guid:i,path:String(e?.path||""),source:String(e?.source||""),controlId:String(e?.controlId||""),controlAsset:t===L||t==="client"?L:t===se||t==="server"?se:""}}function zu(e){let t=[],i=(r,n="")=>{if(r&&(r.path||r.source)){let a=dr(r);t.push(n?{...a,controlAsset:n}:a)}};if(Array.isArray(e?.assets?.scripts)){for(let r of e.assets.scripts)r&&(r.path||r.source)&&t.push(dr(r));return t}if(i(e?.assets?.server?.script,se),i(e?.assets?.client?.script,L),e&&e.format!==wt){i(e?.script);for(let r of e?.scripts||[])i(r)}return t}function Vn(e){return rt(e===L?Rt():dt())}var $u="\u672A\u7ED1\u5B9A",Vt="\u672A\u547D\u540D\u5B58\u6863",Gu="\u672A\u547D\u540D\u754C\u9762";function Vu(e){let t=e;for(let i=0;i<8;i++){if(vi(bs(t,"simulator","studio"))&&vi(bs(t,"lua")))return t;let r=Ru(t);if(r===t)break;t=r}return e}function Yu(e){return e?{name:Yt(e),path:e,bound:!0}:{name:$u,path:"",bound:!1}}function Bu(e,t=process.cwd()){if(Mu(e)&&vi(e))return e;let i=t||process.cwd(),r=Vu(i),n=vs(r,e);if(vi(n))return n;let a=vs(i,e);if(vi(a))return a;throw new Error("script file not found: "+e)}function Yn(e,t={}){e?.format===wt&&Qr(e.version);let i=[],r=typeof t.workspacePath=="string"&&t.workspacePath?t.workspacePath:"",n=e?.format===wt&&e.assets,a=Gn(e?.controlGuidChanges),o=Qt(e?.scriptSync),s=n?null:rt(e,{warnings:i}),c={server:n&&e.assets.server?rt(e.assets.server,{warnings:i}):Vn(se),client:n&&e.assets.client?rt(e.assets.client,{warnings:i}):Vn(L)};s&&(c[St(s.meta.assetType)]=s);let l=n&&e.activeAssetType===L?L:s?.meta.assetType||se,u=n&&e.meta?.name?String(e.meta.name):"",d=()=>u||Vt;!e?.meta?.name&&c.server.meta.name==="\u672A\u547D\u540D\u754C\u9762\u63A7\u4EF6\u7EC4"&&(c.server.meta.name=Gu);let h=[],p=new Set;function m(){p.clear(),Tt(c.server.root,p),Tt(c.client.root,p,{skipServerContainer:!0});for(let y of h)Pe(y.guid)&&p.add(Number(y.guid))}function g(y=0){m();let v=Pe(y)&&!p.has(Number(y))?Number(y):Ze(p);return p.add(v),v}function S(y){let v=dr(y),x=g(v.guid);return{...v,guid:x,id:String(x)}}Ke(zu(e));let C=pi(e?.serverLogic),I=null,P="",N=1,G=1;function j(y){let v=String(y||"").trim();if(!v)return"";if(!K[v])throw new Error(`unknown canvas preset: ${v} (available: ${Object.keys(K).join(", ")})`);return v}let B=()=>c[St(l)];function z(y){if(!y)return null;for(let[v,x]of[["server",c.server],["client",c.client]]){let R=fe(x.root,y);if(R&&R.kind!=="server-container")return{key:v,node:R}}return null}function b(y){if(!y.controlId)return null;let v=y.controlAsset===L?"client":y.controlAsset===se?"server":null;if(v){let x=fe(c[v].root,y.controlId);return x&&x.kind!=="server-container"?{key:v,node:x}:null}return z(y.controlId)}function A(){for(let y of h)y.controlId&&!b(y)&&(y.controlId="",y.controlAsset="")}function w(y){if(!Pe(y))return null;for(let[v,x]of[[se,c.server],[L,c.client]]){let R="";if(Q(x.root,O=>{!R&&(O.scriptMappingIds||[]).includes(Number(y))&&(R=O.id)}),R)return{controlId:R,controlAsset:v}}return null}function k(y,v,x){let R=c[St(y.controlAsset)],O=R&&fe(R.root,y.controlId);O&&(O.scriptMappingIds=(O.scriptMappingIds||[]).map(D=>Number(D)===Number(v)?Number(x):D))}A();function F(){return h.map(y=>{let v=b(y),x=v?v.key==="client"?L:se:"";return V({id:y.id,guid:y.guid||0,path:y.path||"",source:y.source||"",controlId:y.controlId||"",controlAsset:y.controlAsset||x,controlName:v?.node.name||"",assetType:x,assetLabel:v?$n[x]:"",mounted:!!v})})}function E(){let y=[],v=(x,R)=>{Q(x.root,O=>{O.kind!=="server-container"&&y.push(V({id:O.id,name:O.name,kind:O.kind,assetType:R,assetLabel:$n[R]}))})};return v(c.server,se),v(c.client,L),y}function _(y){let v=[];return Q(y.root,x=>{x.kind!=="server-container"&&v.push(JSON.stringify({kind:x.kind,guid:x.guid,name:x.name,text:x.text??null,imageId:x.imageId??null,imageSource:x.imageSource??null,imageType:x.imageType??null,fontSize:x.fontSize??null,fontColor:x.fontColor??null,bgColor:x.bgColor??null,imageColor:x.imageColor??null,fillType:x.fillType??null,fillAmount:x.fillAmount??null,syncAllDevices:x.syncAllDevices!==!1,transformByPlatform:x.transformByPlatform||null}))}),v.join("/")}let $=_(Rt()),Y=_(dt());function re(y){let v=_(y);return y.meta?.assetType===L?v===$:v===Y}function X(y,v){return String(y||"").replace(/[\\/:*?"<>|]/g,"-").trim()||v}function te(y){let v=X(d(),Vt),x=y.meta?.assetType===L?"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F";return`${v} \xB7 ${x}`}function _e(){if(!((c.server.root.children||[]).find(v=>v.kind==="container")||c.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 Ka(c.server,c.client,{scripts:h,fileName:`${X(d(),Vt)} \xB7 \u6574\u5408\u5305.gia`})}function Ct(){let y=v=>({type:v.meta.assetType,name:v.meta.name,sourceFile:v.meta.sourceFile||""});return{format:wt,name:d(),activeAssetType:l,assets:{server:y(c.server),client:y(c.client),scripts:F()}}}function Ut(){return V({format:wt,version:4,meta:{name:d()},activeAssetType:l,serverLogic:C,controlGuidChanges:a,scriptSync:o,assets:{server:c.server,client:c.client,scripts:h.map(y=>V({id:y.id,guid:y.guid||0,path:y.path||"",source:y.source||"",controlId:y.controlId||"",controlAsset:y.controlAsset||""}))}})}function ne(){let y=B(),v=uo(y);return v.workspace=Yu(r),v.save=Ct(),v.scripts=F(),v.mountTargets=E(),v.serverLogic=C,v.migrationWarnings=[...i],v.controlGuidChanges=V(a),v.scriptSync=V(o),va(v),v}function Oe(y){let v=B();if(y.expectedRevision!==void 0&&Number(y.expectedRevision)!==v.version)throw new Error(`revision conflict: expected ${y.expectedRevision}, current ${v.version}`);return v}function st(y,v,x=""){let R=String(v||"");if(R){let O=x===L?L:x===se?se:"";if(!b({controlId:R,controlAsset:O}))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");y.controlAsset=O}else y.controlAsset="";y.controlId=R}function ki(y){let v=Oe(y);if(y.op==="addScript"){let x=S({path:String(y.path||""),source:String(y.source||""),controlId:"",controlAsset:""});y.controlId!==void 0&&y.controlId!==""&&st(x,y.controlId,y.controlAsset),h.push(x)}else if(y.op==="updateScript"){let x=h.find(R=>R.id===y.id);if(!x)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${y.id}`);y.controlId!==void 0&&st(x,y.controlId,y.controlAsset),y.path!==void 0&&(x.path=String(y.path)),y.source!==void 0&&(x.source=String(y.source))}else if(y.op==="removeScript"){let x=h.length;if(h=h.filter(R=>R.id!==y.id),h.length===x)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${y.id}`)}return v.version+=1,ne()}function Ei(y){let v=Oe(y),x=fe(v.root,y.id??v.selectedId);if(!x||x.kind==="server-container")throw new Error("\u4EC5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6216\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5141\u8BB8\u4FEE\u6539\u7D22\u5F15");let R=fr(y.guid),O=fr(x.guid);if(R===O)return ne();let D=[];for(let U of Object.values(c))Q(U.root,oe=>{U===c.client&&oe.kind==="server-container"||D.push({node:oe,project:U})});if(D.some(U=>U.node!==x&&Number(U.node.guid)===R)||h.some(U=>Number(U.guid)===R))throw new Error(`\u63A7\u4EF6\u7D22\u5F15 ${R} \u5DF2\u88AB\u5176\u4ED6\u63A7\u4EF6\u6216\u811A\u672C\u5360\u7528`);let H=[],J=(U,oe,ze)=>{let ie=U?.[oe];(typeof ie=="number"||typeof ie=="string"&&/^\d+$/.test(ie.trim()))&&Number(ie)===O&&H.push({owner:U,key:oe,project:ze.project})};for(let U of D)J(U.node,"referencedPrefabId",U),J(U.node,"itemPrefabId",U),J(U.node.giaRaw,"templateRefSlot",U);if(H.length&&D.filter(U=>Number(U.node.guid)===O).length!==1)throw new Error(`\u65E7\u7D22\u5F15 ${O} \u5728\u591A\u68F5\u8D44\u4EA7\u6811\u4E2D\u91CD\u590D\uFF0C\u65E0\u6CD5\u786E\u5B9A\u6A21\u677F\u5F15\u7528\u5F52\u5C5E\uFF1B\u8BF7\u5148\u6D88\u9664\u6B67\u4E49\u540E\u4FEE\u6539`);let De={id:Tu(),controlAsset:l,controlId:x.id,controlName:x.name,oldGuid:O,newGuid:R};x.guid=R;let me=new Set([v]);for(let{owner:U,key:oe,project:ze}of H)U[oe]=typeof U[oe]=="string"?String(R):R,me.add(ze);a.push(De);for(let U of me)U.version+=1;return ne()}function ae(y){let v=Oe(y);if(!Array.isArray(y.changeIds)||!y.changeIds.length||y.changeIds.some(R=>typeof R!="string"||!a.some(O=>O.id===R)))throw new Error("\u8BF7\u660E\u786E\u6307\u5B9A\u5DF2\u6838\u5BF9 Lua \u5F15\u7528\u7684\u6709\u6548\u7D22\u5F15\u53D8\u66F4\u8BB0\u5F55 changeIds");let x=new Set(y.changeIds);return a=a.filter(R=>!x.has(R.id)),v.version+=1,ne()}function Fe(y){if(!y||typeof y!="object")throw new Error("patch requires op");if(y.op==="setScriptSync"){let v=Oe(y);return o=Qt(y.config),v.version+=1,ne()}if(y.op==="setControlGuid")return Ei(y);if(y.op==="acknowledgeControlGuidChanges")return ae(y);if(y.op==="setServerLogic"){let v=Oe(y);return C=pi(y.logic),v.version+=1,ne()}if(y.op==="addScript"||y.op==="updateScript"||y.op==="removeScript")return ki(y);if(y.op==="selectAsset")return l=y.assetType===L?L:se,ne();if(y.op==="renameSave"){let v=String(y.name||"").trim();if(!v)throw new Error("\u5B58\u6863\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");return u=v,ne()}if(y.op==="newAsset"){let v=Oe(y);l=y.assetType===L?L:se;let x=Vn(l);return x.version=v.version+1,c[St(l)]=x,a=a.filter(R=>R.controlAsset!==l),A(),ne()}return rn(B(),y),A(),ne()}function Ye(y){return h.filter(v=>{let x=b(v);return!!(x&&x.key==="client"==(y===L))})}function Lt(y="json",v=""){let x=Xt(y,v);if(a.length&&!["save","archive"].includes(String(y).toLowerCase())){let R=a.map(O=>`\u63A7\u4EF6\u7D22\u5F15\u5F85\u6838\u5BF9 Lua \u5F15\u7528\uFF1A${$n[O.controlAsset]} / ${O.controlName} (${O.controlId})\uFF1A${O.oldGuid} \u2192 ${O.newGuid}\u3002\u8BF7\u6309\u8BED\u4E49\u66F4\u65B0\u811A\u672C\u4E2D\u7684\u63A7\u4EF6\u7D22\u5F15\u5F15\u7528\uFF0C\u6838\u5BF9\u540E\u786E\u8BA4\u53D8\u66F4\u8BB0\u5F55 ${O.id}\uFF1B\u4E0D\u8981\u5168\u5C40\u66FF\u6362\u540C\u503C\u6570\u5B57\u3002`);x.warnings=[...new Set([...x.warnings||[],...R])]}return x}function Xt(y="json",v=""){let x=String(y).toLowerCase();if(x==="save"||x==="archive"){let D=Buffer.from(JSON.stringify(Ut(),null,2),"utf8");return V({filename:`${d().replace(/[\\/:*?"<>|]/g,"-")} \xB7 \u8D44\u4EA7\u5305.json`,mimeType:"application/json",encoding:"base64",data:D.toString("base64"),warnings:[]})}if(x==="save-gia"||x==="archive-gia"){let D=[],H=[],J=(me,U="")=>{let oe=Lt(me,U);D.push(V({filename:oe.filename,mimeType:oe.mimeType,encoding:oe.encoding,data:oe.data,warnings:oe.warnings||[]})),H.push(...oe.warnings||[])},De=(me,U)=>{let oe=c[St(me)],ze=me===l,ie=h.some(ve=>ve.controlAsset===me&&ve.controlId);if(!ze&&re(oe)&&!ie){H.push(U);return}J("gia",me)};if(De(se,"\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"),De(L,"\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"),h.some(me=>me.path||me.source)&&J("scripts-gia"),!D.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 V({format:"qxqy-gia-package",files:D,warnings:[...new Set(H)]})}if(x==="gia-combined"||x==="combined-gia"||x==="combined"){let D=_e();return V({filename:`${X(d(),Vt)} \xB7 \u6574\u5408\u5305.gia`,mimeType:"application/octet-stream",encoding:"base64",data:D.buffer.toString("base64"),warnings:[...new Set(D.warnings||[])]})}if(x==="scripts"){let D=V({format:Fu,version:1,scripts:h.map(J=>V({id:J.id,guid:J.guid||0,path:J.path||"",source:J.source||"",controlId:J.controlId||"",controlAsset:J.controlAsset||""}))}),H=Buffer.from(JSON.stringify(D,null,2),"utf8");return V({filename:`${X(d(),Vt)} \xB7 \u811A\u672C.json`,mimeType:"application/json",encoding:"base64",data:H.toString("base64"),warnings:[]})}if(x==="scripts-gia"||x==="scriptsgia"){let D=Za(h);return V({filename:`${X(d(),Vt)} \xB7 \u811A\u672C.gia`,mimeType:"application/octet-stream",encoding:"base64",data:D.buffer.toString("base64"),warnings:D.warnings})}if(x==="lua"){let D=h.find(J=>J.id===v)||h.find(J=>J.path===v);if(!D)throw new Error("\u6CA1\u6709\u53EF\u5BFC\u51FA\u7684 Lua \u811A\u672C\uFF0C\u8BF7\u5148\u5728\u201CLua \u811A\u672C\u201D\u9875\u521B\u5EFA");let H=Yt(D.path||"")||`qxqy-script-${D.id}`;return V({filename:/\.lua$/i.test(H)?H:`${H}.lua`,mimeType:"text/x-lua",encoding:"base64",data:Buffer.from(D.source||"","utf8").toString("base64"),warnings:[]})}let R=v?c[St(v)]:B(),O=te(R);if(x==="json"){let D=V({...R,scripts:Ye(R.meta.assetType),controlGuidChanges:a.filter(J=>J.controlAsset===R.meta.assetType)}),H=Buffer.from(JSON.stringify(D,null,2),"utf8");return V({filename:`${O}.json`,mimeType:"application/json",encoding:"base64",data:H.toString("base64"),warnings:[]})}if(x==="gia"){let D=Wa(R,R.meta.assetType===L?{scripts:Ye(L)}:{}),H=R.meta.assetType===L?[]:Ye(se);return H.length&&D.warnings.unshift(`\u5F53\u524D\u670D\u52A1\u5668\u63A7\u4EF6 GIA \u4E0D\u5305\u542B ${H.length} \u4E2A Lua \u811A\u672C\u7684\u6E90\u7801\uFF1B\u8BF7\u4F7F\u7528\u300C\u8D44\u4EA7\u5305 GIA \u6574\u5408\u5305\u300D\uFF0C\u6216\u53E6\u884C\u5BFC\u5165\u811A\u672C\u5305\u5E76\u6838\u5BF9\u6302\u8F7D\u3002`),V({filename:`${O}.gia`,mimeType:"application/octet-stream",encoding:"base64",data:D.buffer.toString("base64"),warnings:D.warnings})}throw new Error(`unsupported export format: ${y}`)}function Ke(y){for(let v of y){let x=dr(v);if(!x.path&&!x.source)continue;let R=x.controlId?null:w(x.guid),O=S(R?{...x,...R}:x);R&&O.guid!==x.guid&&k(R,x.guid,O.guid),O.controlId&&!b(O)&&(O.controlId="",O.controlAsset=""),h.push(O)}}function Wt(y,v,x=""){let R=String(y||"").toLowerCase();if(typeof v!="string"||!v)throw new Error("import data is required");let O=Buffer.from(v,"base64"),D,H=[],J={};if(R==="json"){try{D=JSON.parse(O.toString("utf8"))}catch{throw new Error("JSON \u6587\u4EF6\u65E0\u6548")}if(D?.project&&(D=D.project),D?.format===wt&&D?.assets){Qr(D.version);let ie=Yn(D);H.push(...ie.get().migrationWarnings);let ve=ie.archiveData();return c.server=ve.assets.server,c.client=ve.assets.client,i=[...H],l=D.activeAssetType===L?L:se,u=String(D.meta?.name||Yt(x).replace(/\.json$/i,"")||u),C=ve.serverLogic,h=ve.assets.scripts,a=ve.controlGuidChanges,o=ve.scriptSync,p.clear(),V({snapshot:ne(),warnings:H,metadata:{format:wt}})}}else{if(R==="lua")return h.push(S({path:Yt(x||"imported.lua"),source:O.toString("utf8"),controlId:""})),V({snapshot:ne(),warnings:H,metadata:{assetType:"lua-script"}});if(R==="gia"){if(Qa(O)){let we=to(O);return Ke(we.scripts),V({snapshot:ne(),warnings:we.warnings,metadata:we.metadata})}let ie=io(O);D=ie.project,H=ie.warnings,J=ie.metadata,ie.clientProject&&(c.client=rt(ie.clientProject),a=a.filter(we=>we.controlAsset!==L),H.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 ve=new Map,ca=(we,_l)=>{we&&Q(we.root,ua=>{for(let Tr of ua.scriptMappingIds||[]){let fa=ve.get(Number(Tr));if(fa){H.push(`\u811A\u672C GUID ${Tr} \u540C\u65F6\u6302\u8F7D\u5230\u591A\u4E2A\u63A7\u4EF6\uFF0C\u5DF2\u4FDD\u7559\u201C${fa.controlAsset===se?"\u670D\u52A1\u7AEF":"\u5BA2\u6237\u7AEF"}\u201D\u76EE\u6807\u3002`);continue}ve.set(Number(Tr),{controlId:ua.id,controlAsset:_l})}})};ca(ie.project,se),ca(ie.clientProject,L),Ke((ie.scripts||[]).map(we=>ve.has(Number(we.guid))?{...we,...ve.get(Number(we.guid))}:we))}else throw new Error(`unsupported import format: ${y}`)}let De=rt(D,{warnings:H}),me=Gn(D?.controlGuidChanges);if(me.some(ie=>ie.controlAsset!==De.meta.assetType))throw new Error("\u5355\u8D44\u4EA7 JSON \u7684\u7D22\u5F15\u53D8\u66F4\u8BB0\u5F55\u5FC5\u987B\u5C5E\u4E8E\u5F53\u524D\u5BFC\u5165\u8D44\u4EA7");let U=Gn([...a.filter(ie=>ie.controlAsset!==De.meta.assetType),...me]);i=[...H];let oe=St(De.meta.assetType);c[oe]=De,a=U,l=De.meta.assetType;let ze=c[oe];return x&&(ze.meta.name=Yt(x).replace(/\.(json|gia)$/i,"")||ze.meta.name,ze.meta.sourceFile=Yt(x),ze.meta.sourceFormat=R),Ke(D?.scripts||[]),D?.script&&(D.script.path||D.script.source)&&Ke([D.script]),V({snapshot:ne(),warnings:H,metadata:J})}function ll(y,v){return rn(B(),{op:"pick",x:y,y:v}),ne()}function cl(y){let v=typeof y=="string"&&y?y:"";!v||v===r||(r=v)}function ul(y){let v=y.source||"";if(!v.trim()&&y.path.trim())try{v=Pu(Bu(y.path,r),"utf8")}catch(x){throw new Error(`\u811A\u672C ${y.path} \u8BFB\u53D6\u5931\u8D25: ${x?.message||x}`)}return v}function Kt(y={}){let v=j(y.canvasId);v&&(P=v),y.playerCount!==void 0&&y.playerCount!==null&&y.playerCount!==""&&(N=gt(y.playerCount),G>N&&(G=1)),y.viewPlayerIndex!==void 0&&y.viewPlayerIndex!==null&&y.viewPlayerIndex!==""&&(G=Xe(y.viewPlayerIndex,N)),I&&Nn(I);let x=h.map(O=>{try{return{id:O.id,guid:O.guid||0,path:O.path||O.id,source:ul(O),controlId:O.controlId||"",controlAsset:O.controlAsset||""}}catch(D){return{id:O.id,guid:O.guid||0,path:O.path||O.id,source:`error([==[ ${String(D.message).replace(/]=+]/g,"] =]")} ])`,controlId:O.controlId||"",controlAsset:O.controlAsset||""}}}),R=O=>x.filter(D=>{let H={controlId:D.controlId,controlAsset:D.controlAsset},J=D.controlId?b(H):null;return!!(J&&J.key===O)});return I=as(c.server,{templatesProject:c.client,scripts:x,sceneScripts:R("server"),templateScripts:R("client"),serverConfig:{logic:C},canvasId:P,playerCount:N,viewPlayerIndex:G,language:y.language||""}),ue(y)}function fl(y,v={}){let x=j(y);if(!x)throw new Error("playSetCanvas requires canvasId");return Kt({...v,canvasId:x})}function ue(y={}){if(!I)return V({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]});let v=An(I,y);return v.running=!0,v.logs=zn(v.logs),v.serverLogs=zn(v.server?.logs||[]),v.serverVars=Ou(v.server,v.playerCount||1),v}function dl(y,v={}){return I||Kt(),cr(I,y),v.observe===!1?V({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}):ue(v)}function hl(y=0){Kt();let v=Math.max(0,Number(y)||0);for(let x=0;x<v;x++)cr(I,1/30);return ue()}function ml(){return I&&Nn(I),I=null,P="",N=1,G=1,V({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]})}function pl(y,v={}){let x=qt();return G=kn(x,y),v.observe===!1?null:ue(v)}function gl(y,v={}){if(!I)throw new Error("play session has not started");return _n(I,y),v.observe===!1?null:ue(v)}function yl(y,v={}){if(!I)throw new Error("play session has not started");return Pn(I,y),v.observe===!1?null:ue(v)}function bl(y,v,x,R={}){if(!I)throw new Error("play session has not started");return bi(I,y,v,x,R),R.observe===!1?null:ue(R)}function vl(y={}){return I&&ur(I).pause(),y.observe===!1?null:ue(y)}function Sl(y={}){return I&&ur(I).resume(),y.observe===!1?null:ue(y)}function qt(){if(!I)throw new Error("play session has not started");return I}function wl(y,v){let x=qt();if(!y&&!v){let R=ue();return V({vars:R.serverVars||[]})}return V({entityType:String(y||""),name:String(v||""),value:ms(x,y,v)})}function Il(y,v,x){let R=qt();return Rn(R,y,v,x),ue()}function xl(y,v=[],x="PlayerSelf"){let R=qt();return Mn(R,y,v,x),ue()}function Cl(){let y=ue();return V({events:y.history||[],case:Ho(y.history||[],{playerCount:y.playerCount||1})})}function kl(y={}){let v=ue(),x=gi({name:y.name||"",dt:y.dt,playerCount:y.playerCount||v.playerCount||1,events:y.events||v.history||[],asserts:y.asserts||[]});return V(x)}function El(y,v={}){let x=gi(y);Kt({...v,playerCount:v.playerCount||x.playerCount||1});let R=qt();R.recording=!1;try{return ys(ur(R),y)}finally{R.recording=!0}}function Al(){if(!I)return{running:!1,paused:!1,time:0,frame:0,playerCount:1,viewPlayerIndex:1};let y=I.runtime.clock;return{running:!0,paused:!!I.debugPaused,levelTimePaused:!!y.paused,time:y.time,frame:y.frame,playerCount:I.playerCount||1,viewPlayerIndex:I.viewPlayerIndex||1}}let la={get:ne,patch:Fe,setWorkspace:cl,exportData:Lt,importData:Wt,pick:ll,playStart:Kt,playSetCanvas:fl,playSetView:pl,playGet:ue,playStatus:Al,playStep:dl,playRun:hl,playStop:ml,playKey:gl,playClick:yl,playPointer:bl,playPause:vl,playResume:Sl,playServerGet:wl,playServerSet:Il,playServerSend:xl,playHistory:Cl,playSaveCase:kl,playRunCase:El,archiveData:Ut};return Object.defineProperty(la,"_project",{enumerable:!1,get:B}),la}import{createRequire as Uu}from"node:module";function Bn(e,t,i){if(e.fillType!=="Horizontal"&&e.fillType!=="Vertical")return null;let r=Number(e.fillAmount??1),n=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1;if(e.fillType==="Horizontal"){let o=t*n;return{x:e.fillHorizontalType==="Right"?t/2-o:-t/2,y:-i/2,width:o,height:i}}let a=i*n;return{x:-t/2,y:e.fillVerticalType==="Top"?-i/2:i/2-a,width:t,height:a}}function Ss(e,t,i){let r=t?.m_Rect,n=t?.m_RD?.textureRectOffset,a=t?.m_RD?.textureRect,o=Math.round(Number(r?.width)),s=Math.round(Number(r?.height)),c=Math.round(Number(n?.X)),l=Math.round(Number(n?.Y)),u=Math.round(Number(a?.width)),d=Math.round(Number(a?.height)),h=t?.m_RD?.settingsRaw?.packingRotation;if(![o,s,u,d].every(g=>Number.isInteger(g)&&g>0&&g<=8192)||o*s>16777216||!Number.isFinite(c)||!Number.isFinite(l)||c<0||l<0||c+u>o||l+d>s)throw new Error("Invalid sprite dimensions or trim offset");if(h&&h!=="None")throw new Error(`Unsupported sprite packing rotation: ${h}`);let p=i(o,s),m=p.getContext("2d");if(e.width===o&&e.height===s)m.drawImage(e,0,0);else{if(e.width!==u||e.height!==d)throw new Error("Sprite PNG does not match its trim metadata");m.drawImage(e,c,s-l-d)}return p}function ws(e,t,i){let r=Number(t??4294967295)>>>0;if((r&16777215)===16777215)return e;let n=i(e.width,e.height),a=n.getContext("2d");a.drawImage(e,0,0);let o=a.getImageData(0,0,n.width,n.height),s=r>>>16&255,c=r>>>8&255,l=r&255;for(let u=0;u<o.data.length;u+=4)o.data[u]=Math.round(o.data[u]*s/255),o.data[u+1]=Math.round(o.data[u+1]*c/255),o.data[u+2]=Math.round(o.data[u+2]*l/255);return a.putImageData(o,0,0),n}function ju(e){return!!e?.border&&Object.values(e.border).some(t=>Number.isFinite(t)&&t>0)}function xs(e,t){let i=typeof t=="object"?t?.Name:t;return ju(e)&&i!=="Basic"?"Stretch":"Basic"}function Cs(e){if(!e)return null;let t=Number(e.m_Rect?.width),i=Number(e.m_Rect?.height);if(![t,i].every(n=>Number.isFinite(n)&&n>0&&n<=8192)||t*i>16777216)throw new Error("Invalid image metadata dimensions");let r={};for(let[n,a]of[["left","X"],["bottom","Y"],["right","Z"],["top","W"]]){let o=Number(e.m_Border?.[a]??0);if(!Number.isFinite(o))throw new Error("Invalid image border");r[n]=Math.max(0,o)}return{width:t,height:i,border:r}}function Hu(e,t,i,r){t=Number.isFinite(t)?Math.max(0,t):0,i=Number.isFinite(i)?Math.max(0,i):0;let n=Math.min(1,e/(t+i||1));t*=n,i*=n;let a=Math.min(1,r/(t+i||1));return{source:[0,t,e-i,e],target:[0,t*a,r-i*a,r]}}var Is=new WeakMap;function ks(e,t,i,r,n){let a=Math.max(0,i),o=Math.max(0,r),s=Math.min(1,4096/Math.max(1,a),4096/Math.max(1,o)),c=Math.max(1,Math.round(a*s)),l=Math.max(1,Math.round(o*s)),u=n(c,l),d=u.getContext("2d");if(!a||!o)return u;let h=Is.get(e);if(!h){let I=n(e.width,e.height),P=I.getContext("2d");P.drawImage(e,0,0),h=P.getImageData(0,0,e.width,e.height),Is.set(e,h)}let p=d.createImageData(c,l),m=h.data,g=(I,P,N,G,j,B)=>{let{source:z,target:b}=Hu(P,N,G,j);return Array.from({length:B},(A,w)=>{let k=(w+.5)*j/B,F=k<b[1]?0:k<b[2]?1:2,E=b[F+1]>b[F]?(k-b[F])/(b[F+1]-b[F]):0,_=Math.max(0,Math.min(I-1,(z[F]+E*(z[F+1]-z[F]))*I/P-.5)),$=Math.floor(_);return[$,Math.min(I-1,$+1),_-$]})},S=g(e.width,t.width,t.border.left,t.border.right,a,c),C=g(e.height,t.height,t.border.top,t.border.bottom,o,l);for(let I=0;I<l;I++)for(let P=0;P<c;P++){let[N,G,j]=S[P],[B,z,b]=C[I],A=(B*e.width+N)*4,w=(B*e.width+G)*4,k=(z*e.width+N)*4,F=(z*e.width+G)*4,E=m[A+3]*(1-j)*(1-b),_=m[w+3]*j*(1-b),$=m[k+3]*(1-j)*b,Y=m[F+3]*j*b,re=E+_+$+Y,X=(I*c+P)*4;p.data[X+3]=Math.round(re);for(let te=0;te<3;te++)p.data[X+te]=re?Math.round((m[A+te]*E+m[w+te]*_+m[k+te]*$+m[F+te]*Y)/re):0}return d.putImageData(p,0,0),u}var Lu=Uu(import.meta.url),Xu=[0,-.5,.5,.5,-.5,.5],Wu=[0,-.5,.12,-.12,.5,0,.12,.12,0,.5,-.12,.12,-.5,0,-.12,-.12],Ku=[0,-.5,.11,-.15,.48,-.15,.18,.07,.29,.41,0,.2,-.29,.41,-.18,.07,-.48,-.15,-.11,-.15],jn=Buffer.from([137,80,78,71,13,10,26,10]),qu=new Set(["image","textbox","textwindow","button","grid"]),hr={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"},mr=null;function Si(){if(mr)return mr;try{mr=Lu("@napi-rs/canvas")}catch(e){let t=e?.message||String(e);throw new Error(`Host screenshot renderer requires @napi-rs/canvas (${t})`)}return mr}function W(e,t=0){let i=Number(e);return Number.isFinite(i)?i:t}function gr(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 It(e,t=1){return`rgba(${e.r},${e.g},${e.b},${Math.max(0,Math.min(1,e.a*t))})`}function As(e,t,i=1){let r=Math.max(1,Math.round(W(e,1))),n=Math.max(1,Math.round(W(t,1))),a=Math.max(1,Math.min(2,W(i,1)));return{width:r,height:n,pixelWidth:Math.max(1,Math.round(r*a)),pixelHeight:Math.max(1,Math.round(n*a)),pixelRatio:a}}function _s(e){let t=Buffer.from(e.toBuffer("image/png"));if(t.length<jn.length||!t.subarray(0,jn.length).equals(jn))throw new Error("Host screenshot renderer did not produce a PNG");return t}function Ju(e){return e==="triangle"?Xu:e==="fourstar"?Wu:Ku}function Zu(e,t,i,r,n){let a=Ju(t);e.beginPath();for(let o=0;o<a.length;o+=2){let s=a[o]*i,c=a[o+1]*r;o===0?e.moveTo(s,c):e.lineTo(s,c)}e.closePath(),e.fillStyle=It(n),e.fill()}function Qu(e,t,i){let r=t?.matrix,n=r&&typeof r=="object"?[r.a,r.b,r.c,r.d,r.tx,r.ty].map(Number):null,a=t?.pressed?.98:1;if(n&&n.every(Number.isFinite)){let[o,s,c,l,u,d]=n;e.transform(o*a,-s*a,-c*a,l*a,u,i-d);return}e.translate(W(t.left)+W(t.width)/2,i-W(t.bottom)-W(t.height)/2),e.rotate(-W(t.rotationZ)*Math.PI/180),e.scale(a,a)}function ef(e,t,i,r,n,a){if(typeof e.roundRect=="function"){e.roundRect(t,i,r,n,a);return}let o=Math.max(0,Math.min(a,r/2,n/2));e.moveTo(t+o,i),e.arcTo(t+r,i,t+r,i+n,o),e.arcTo(t+r,i+n,t,i+n,o),e.arcTo(t,i+n,t,i,o),e.arcTo(t,i,t+r,i,o),e.closePath()}function Ps(e,t,i,r){let n=gr(t.bgColor,16777215);e.fillStyle=It(n),e.fillRect(-i/2,-r/2,i,r);let a=Math.max(8,W(t.fontSize,12)),o=gr(t.fontColor,4294967295),s=t.horizontalAlignment==="Right"?1:t.horizontalAlignment==="Middle"?.5:0,c=t.verticalAlignment==="Bottom"?1:t.verticalAlignment==="Middle"?.5:0;e.save(),e.beginPath(),e.rect(-i/2,-r/2,i,r),e.clip(),e.font=`${a}px "Microsoft YaHei UI","Microsoft YaHei",sans-serif`,e.fillStyle=It(o),e.textAlign=s===1?"right":s===.5?"center":"left";let l=t.kind==="textwindow"?t.scroll:null;if(e.textBaseline=l?"top":c===1?"bottom":c===.5?"middle":"top",t.enableOutline){let g=gr(t.outlineColor,4278190080);e.strokeStyle=It(g),e.lineWidth=Math.max(2,a*.12),e.lineJoin="round"}let u=l?-i/2+2+s*l.textWidth:s===0?-i/2+2:s===1?i/2-2:0,d=c===0?-r/2:c===1?r/2:0,h=l?.lines||String(t.text||"").split(`
|
|
112
|
+
`),p=l?.lineHeight||a*1.2,m=l?-r/2-l.offset+(l.max>0?0:c*(r-l.contentLength)):c===.5?d-(h.length-1)*p/2:c===1?d-(h.length-1)*p:d;for(let g=0;g<h.length;g+=1){let S=m+g*p;l&&(S+p<-r/2||S>r/2)||(t.enableOutline&&e.strokeText(h[g],u,S),e.fillText(h[g],u,S))}e.restore()}function tf(e,t,i,r){let n=$t(t.scroll,i,r);if(n)for(let[a,o]of[[n.track,"#263447"],[n.thumb,"#90aecb"]])e.fillStyle=o,e.fillRect(a.x,a.y,a.width,a.height)}function Ts(e,t,i,r){e.beginPath(),ef(e,-i/2,-r/2,i,r,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 Rs(e,t,i,r,n){let a=gr(t.imageColor,4294967295),o=Ti(t.imageId,t.imageSource),s=n?.images?.get(o);if(t.primitive==="sprite"&&s){let c=n.imageMetadata?.get(o),l=xs(c,t.imageType),u=`${o}:${Number(t.imageColor??4294967295)&16777215}:${l}:${l==="Stretch"?`${i}:${r}`:""}`,d=n.tints.get(u);if(!d){let h=l==="Stretch"?ks(s,c,i,r,Si().createCanvas):s;d=ws(h,t.imageColor,Si().createCanvas),n.tints.set(u,d)}e.globalAlpha*=a.a,e.drawImage(d,-i/2,-r/2,i,r);return}if(t.primitive==="missing"||t.primitive==="sprite"){e.fillStyle="rgba(72,34,40,0.36)",e.fillRect(-i/2,-r/2,i,r),e.strokeStyle="#ff7481",e.lineWidth=1,e.strokeRect(-i/2+.5,-r/2+.5,Math.max(0,i-1),Math.max(0,r-1));return}if(t.primitive==="circle"){e.beginPath(),e.ellipse(0,0,i/2,r/2,0,0,Math.PI*2),e.fillStyle=It(a),e.fill();return}if(t.primitive==="ring"){e.beginPath(),e.ellipse(0,0,Math.max(1,i/2-3.5),Math.max(1,r/2-3.5),0,0,Math.PI*2),e.strokeStyle=It(a),e.lineWidth=7,e.stroke();return}if(t.primitive==="triangle"||t.primitive==="fourstar"||t.primitive==="fivestar"){Zu(e,t.primitive,i,r,a);return}e.fillStyle=It(a),e.fillRect(-i/2,-r/2,i,r)}function rf(e,t,i,r){let n=Math.max(0,W(t.sourceWidth,W(t.width))),a=Math.max(0,W(t.sourceHeight,W(t.height)));e.save();for(let o of t.clipPolygons||[])e.beginPath(),o.forEach((s,c)=>c?e.lineTo(s.x,i-s.y):e.moveTo(s.x,i-s.y)),e.closePath(),e.clip();if(Qu(e,t,i),t.kind==="textbox"||t.kind==="textwindow")Ps(e,t,n,a);else if(t.kind==="button")Ts(e,t,n,a);else if(t.kind!=="grid"){let o=Bn(t,n,a);o&&(e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip()),Rs(e,t,n,a,r)}tf(e,t,n,a),e.restore()}function Ms(e,t,i,{checker:r=!1}={}){if(r){e.fillStyle="#28313e",e.fillRect(0,0,t,i);let a=16;for(let o=0;o<i;o+=a)for(let s=0;s<t;s+=a)(s/a+o/a)%2===0&&(e.fillStyle="rgba(255,255,255,0.04)",e.fillRect(s,o,a,a));e.strokeStyle="#40b8cf",e.lineWidth=1,e.strokeRect(.5,.5,t-1,i-1);return}let n=e.createRadialGradient(t/2,i*.45,8,t/2,i/2,Math.max(t,i)*.72);n.addColorStop(0,"#123a6b"),n.addColorStop(.72,"#061934"),n.addColorStop(1,"#071426"),e.fillStyle=n,e.fillRect(0,0,t,i)}function nf(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 Es(e){let t=e?.matrix;return!t||typeof t!="object"?{a:1,b:0,c:0,d:1,tx:0,ty:0}:{a:W(t.a,1),b:W(t.b),c:W(t.c),d:W(t.d,1),tx:W(t.tx),ty:W(t.ty)}}function af(e){let t=Array.isArray(e?.nodes)?e.nodes:[],i=new Map;for(let o of t){if(!o||o.id===void 0||o.id===null)continue;let s=o.parent==null?"":String(o.parent),c=i.get(s);c?c.push(o):i.set(s,[o])}for(let o of i.values())o.sort((s,c)=>W(s.z)-W(c.z));let r=[];function n(o,s,c,l){if(!qu.has(o.kind))return;let u=Math.abs(W(o.sourceWidth)*Math.hypot(s.a,s.b)),d=Math.abs(W(o.sourceHeight)*Math.hypot(s.c,s.d));r.push({...o,left:s.tx-u/2,bottom:s.ty-d/2,width:u,height:d,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},...c.length?{clipPolygons:c}:{},...l.length?{masks:l}:{}})}function a(o,s,c=null,l=[],u=[]){let d=i.get(o)||[];for(let h=d.length-1;h>=0;h-=1){let p=d[h],m=s?nf(s,Es(p)):Es(p),g=l;if(p.clipToParent&&s&&c){let I=c.sourceWidth/2,P=c.sourceHeight/2;g=[...l,[[-I,-P],[I,-P],[I,P],[-I,P]].map(([N,G])=>({x:s.a*N+s.c*G+s.tx,y:s.b*N+s.d*G+s.ty}))]}let S=nr(p,m),C=S?[...u,S]:u;p.kind!=="grid"&&n(p,m,g,C),a(String(p.id),m,p,g,C),p.kind==="grid"&&n(p,m,g,C)}}return a("",null),r}function Ns(e,t,i,r={}){return lf(af(e),t,i,r)}function of(e,t,i){if(!(e.width>0&&e.height>0)||!je(e.matrix))return null;let r=[[-1,-1],[1,-1],[1,1],[-1,1]].map(([c,l])=>{let u=xe(e.matrix,c*e.width/2,l*e.height/2);return{x:u.x*i.pixelRatio,y:(i.height-u.y)*i.pixelRatio}}),n=Math.max(t.x,Math.floor(Math.min(...r.map(c=>c.x)))),a=Math.max(t.y,Math.floor(Math.min(...r.map(c=>c.y)))),o=Math.min(t.x+t.canvas.width,Math.ceil(Math.max(...r.map(c=>c.x)))),s=Math.min(t.y+t.canvas.height,Math.ceil(Math.max(...r.map(c=>c.y))));return o>n&&s>a?{x:n,y:a,width:o-n,height:s-a}:null}function sf(e,t,i,r){let n=t.canvas.width,a=t.canvas.height,o=t.ctx.getImageData(0,0,n,a).data,s=t.x-e.x,c=t.y-e.y,l=e.ctx.getImageData(s,c,n,a),u=l.data,d=je(i.matrix);for(let h=0;h<a;h++){let p=r.height-(t.y+h+.5)/r.pixelRatio;for(let m=0;m<n;m++){let g=(h*n+m)*4;if(!o[g+3])continue;let S=(t.x+m+.5)/r.pixelRatio,C=d.a*S+d.c*p+d.tx,I=d.b*S+d.d*p+d.ty,P=qo(C,I,i),N=Math.round(o[g+3]*P)/255;if(!N)continue;let G=u[g+3]/255,j=N+G*(1-N);for(let B=0;B<3;B++)u[g+B]=Math.round((o[g+B]*N+u[g+B]*G*(1-N))/j);u[g+3]=Math.round(j*255)}}e.ctx.save(),e.ctx.setTransform(1,0,0,1,0,0),e.ctx.putImageData(l,s,c),e.ctx.restore()}function Os(e,t,i,r){for(let n of t){if(n.item){rf(e.ctx,n.item,i.height,r);continue}let a=of(n.mask,e,i);if(!a)continue;let o=Si().createCanvas(a.width,a.height),s=o.getContext("2d");s.setTransform(i.pixelRatio,0,0,i.pixelRatio,-a.x,-a.y);let c={canvas:o,ctx:s,x:a.x,y:a.y};Os(c,n.children,i,r),sf(e,c,n.mask,i)}}function lf(e,t,i,r={}){let{createCanvas:n}=Si(),a=As(t,i,r.scale),o=n(a.pixelWidth,a.pixelHeight),s=o.getContext("2d");s.scale(a.pixelRatio,a.pixelRatio),r.background!=="transparent"&&Ms(s,a.width,a.height);let c=Array.isArray(e)?e:[],l={images:r.images,imageMetadata:r.imageMetadata,tints:new Map};return Os({canvas:o,ctx:s,x:0,y:0},Jo(c),a,l),{data:_s(o),width:a.width,height:a.height,pixelWidth:a.pixelWidth,pixelHeight:a.pixelHeight}}function cf(e){return{kind:e.kind,left:W(e.renderLeft,e.left),bottom:W(e.renderBottom,e.bottom),width:Math.max(0,W(e.renderWidth,e.width)),height:Math.max(0,W(e.renderHeight,e.height)),rotationZ:W(e.renderRotationZ,e.rotationZ)}}function pr(e,t,i){let r=String(t||"");if(!r)return;e.font='10px "Microsoft YaHei UI","Microsoft YaHei",sans-serif',e.textAlign="center",e.textBaseline="middle";let n=e.measureText(r),a=Math.min(i-4,Math.max(24,n.width+8)),o=16;e.fillStyle="rgba(17,25,37,0.66)",e.fillRect(-a/2,-o/2,a,o),e.fillStyle="#e7edf5",e.fillText(r,0,0)}function uf(e,t,i,r,n){let a=cf(t);if(a.width<=0||a.height<=0)return;e.save(),e.translate(a.left+a.width/2,i-a.bottom-a.height/2),e.rotate(-a.rotationZ*Math.PI/180);let o=-a.width/2,s=-a.height/2;if(t.kind==="image"){e.save();let c=Math.max(0,W(t.width,a.width)),l=Math.max(0,W(t.height,a.height));e.scale(c?a.width/c:1,l?a.height/l:1);let u=t.enableFill?Bn(t,c,l):null;u&&(e.beginPath(),e.rect(u.x,u.y,u.width,u.height),e.clip()),Rs(e,t,c,l,n),e.restore()}else if(t.kind==="textbox"||t.kind==="textwindow")Ps(e,t,a.width,a.height);else if(t.kind==="button")Ts(e,t,a.width,a.height),pr(e,t.name||hr.button,a.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,s,a.width,a.height),e.strokeRect(o,s,a.width,a.height),pr(e,t.name||hr.cursor,a.width);else if(t.kind==="grid"){e.strokeStyle="rgba(106,146,189,0.55)",e.strokeRect(o,s,a.width,a.height),e.beginPath();for(let c=20;c<a.width;c+=20)e.moveTo(o+c,s),e.lineTo(o+c,s+a.height);for(let c=20;c<a.height;c+=20)e.moveTo(o,s+c),e.lineTo(o+a.width,s+c);e.stroke(),pr(e,t.name||hr.grid,a.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,s,a.width,a.height),pr(e,t.name||hr[t.kind]||t.kind,a.width)):(e.strokeStyle="rgba(78,165,230,0.42)",e.strokeRect(o,s,a.width,a.height));t.id===r&&t.kind!=="container"&&t.kind!=="server-container"&&(e.setLineDash([]),e.strokeStyle="#61b9ff",e.lineWidth=2,e.strokeRect(o,s,a.width,a.height)),e.restore()}function Fs(e,t={}){let{createCanvas:i}=Si(),r=e?.canvas||{},n=As(r.width||1600,r.height||900,t.scale),a=i(n.pixelWidth,n.pixelHeight),o=a.getContext("2d");o.scale(n.pixelRatio,n.pixelRatio),Ms(o,n.width,n.height,{checker:!0});let s=Array.isArray(e?.boxes)?e.boxes:[],c=e?.selectedId,l={images:t.images,imageMetadata:t.imageMetadata,tints:new Map};for(let u of s)!u||u.kind==="server-container"||u.visible===!1||uf(o,u,n.height,c,l);return{data:_s(a),page:e?.asset?.type==="client-control-template"?"UI\u63A7\u4EF6-\u5BA2\u6237\u7AEF":"UI \u7F16\u8F91",width:n.width,height:n.height,pixelWidth:n.pixelWidth,pixelHeight:n.pixelHeight}}import{closeSync as ff,existsSync as yr,openSync as df,opendirSync as hf,readSync as mf,realpathSync as Bt,statSync as zs}from"node:fs";import{basename as pf,dirname as Ds,isAbsolute as Xn,join as gf,relative as $s,resolve as xi}from"node:path";var yf="qxqy-simulator-save",Gs=new Set(["node_modules",".git","dist",".dsh","coverage"]),wi=50,Vs=4096,Hn=1e4,Un=1e3,Ln=8;function xt(e=""){let t=xi(String(e||process.cwd()));if(!yr(t))throw new Error(`workspace does not exist: ${t}`);if(!zs(t).isDirectory())throw new Error(`workspace is not a directory: ${t}`);return Bt(t)}function Ii(e,t,i=!1){let r=$s(e,t);if(!i&&!r||r.startsWith("..")||Xn(r))throw new Error("path must stay inside the configured workspace");return r}function Ve(e,t){let i=String(t||"").trim();if(!i||Xn(i))throw new Error("path must be a non-empty workspace-relative path");let r=Bt(xi(e)),n=xi(r,i);if(Ii(r,n),!yr(n))throw new Error(`file does not exist: ${i}`);let a=Bt(n);return Ii(r,a),a}function Ne(e,t){let i=String(t||"").trim();if(!i||Xn(i))throw new Error("path must be a non-empty workspace-relative path");let r=Bt(xi(e)),n=xi(r,i);Ii(r,n);let a=Ds(n);for(;!yr(a);){let o=Ds(a);if(o===a)throw new Error("unable to resolve output directory");a=o}return Ii(r,Bt(a),!0),yr(n)&&Ii(r,Bt(n)),n}function bf(e,t=Vs){let i=Buffer.alloc(t),r=df(e,"r");try{let n=mf(r,i,0,t,0);return i.subarray(0,n).toString("utf8")}finally{ff(r)}}function Ys(e,t,i,r,n){if(r>Ln){n.depthLimitedDirectories+=1;return}if(n.scannedDirectories>=Un){n.directoryLimitReached=!0;return}let a;try{n.scannedDirectories+=1,a=hf(e)}catch{n.unreadableEntries+=1;return}try{let o;for(;o=a.readSync();){if(n.scannedEntries>=Hn){n.entryLimitReached=!0;return}if(n.scannedEntries+=1,o.name.startsWith(".")||o.isDirectory()&&Gs.has(o.name)){n.skippedEntries+=1,o.isDirectory()&&(n.skippedDirectories+=1);continue}let s=gf(e,o.name);if(o.isDirectory()){if(Ys(s,t,i,r+1,n),n.entryLimitReached||n.directoryLimitReached)return;continue}if(!(!o.isFile()||!/\.json$/i.test(o.name))){n.scannedJsonFiles+=1;try{let c=zs(s),l=bf(s);if(!l.includes(yf))continue;let u=l.match(/"name"\s*:\s*("(?:\\.|[^"\\])*")/)?.[1],d=pf(o.name,".json");if(u)try{d=JSON.parse(u)||d}catch{}i.push({path:$s(t,s).replaceAll("\\","/"),name:d,bytes:c.size,mtime:c.mtimeMs})}catch{n.unreadableEntries+=1}}}}catch{n.unreadableEntries+=1}finally{try{a.closeSync()}catch{n.unreadableEntries+=1}}}function br(e){let t=xt(e),i=[],r={truncated:!1,warnings:[],scannedDirectories:0,scannedEntries:0,scannedJsonFiles:0,matchedArchives:0,skippedDirectories:0,skippedEntries:0,unreadableEntries:0,depthLimitedDirectories:0,entryLimitReached:!1,directoryLimitReached:!1,limits:{archives:wi,entries:Hn,directories:Un,depth:Ln,headBytes:Vs},policy:{excludedDirectories:[...Gs],hiddenEntries:!1,symlinks:!1,validatesJson:!1}};return Ys(t,t,i,0,r),i.sort((n,a)=>a.mtime-n.mtime||n.path.localeCompare(a.path)),r.matchedArchives=i.length,i.length>wi&&r.warnings.push(`\u53D1\u73B0 ${i.length} \u4E2A\u5B58\u6863\uFF0C\u4EC5\u663E\u793A\u4FEE\u6539\u65F6\u95F4\u6700\u65B0\u7684 ${wi} \u4E2A\uFF1B\u5176\u4ED6\u5B58\u6863\u53EF\u901A\u8FC7\u6307\u5B9A\u8DEF\u5F84\u6253\u5F00\u3002`),(r.entryLimitReached||r.directoryLimitReached)&&r.warnings.push(`\u81EA\u52A8\u53D1\u73B0\u8FBE\u5230\u626B\u63CF\u4E0A\u9650\uFF08${Hn} \u9879 / ${Un} \u4E2A\u76EE\u5F55\uFF09\uFF0C\u5217\u8868\u53EF\u80FD\u4E0D\u5B8C\u6574\uFF1B\u53EF\u901A\u8FC7\u6307\u5B9A\u8DEF\u5F84\u6253\u5F00\u5B58\u6863\u3002`),r.depthLimitedDirectories&&r.warnings.push(`\u81EA\u52A8\u53D1\u73B0\u8DF3\u8FC7 ${r.depthLimitedDirectories} \u4E2A\u8D85\u8FC7 ${Ln} \u5C42\u7684\u76EE\u5F55\uFF1B\u53EF\u901A\u8FC7\u6307\u5B9A\u8DEF\u5F84\u6253\u5F00\u5176\u4E2D\u7684\u5B58\u6863\u3002`),r.skippedEntries&&r.warnings.push("\u81EA\u52A8\u53D1\u73B0\u8DF3\u8FC7\u9690\u85CF\u9879\u53CA\u751F\u6210\u76EE\u5F55\uFF08\u5982 node_modules\u3001dist\uFF09\uFF1B\u53EF\u901A\u8FC7\u6307\u5B9A\u8DEF\u5F84\u6253\u5F00\u5176\u4E2D\u7684\u5B58\u6863\u3002"),r.unreadableEntries&&r.warnings.push(`\u81EA\u52A8\u53D1\u73B0\u65E0\u6CD5\u8BFB\u53D6 ${r.unreadableEntries} \u4E2A\u6587\u4EF6\u6216\u76EE\u5F55\uFF1B\u8BF7\u68C0\u67E5\u8BBF\u95EE\u6743\u9650\uFF0C\u6216\u901A\u8FC7\u6307\u5B9A\u8DEF\u5F84\u67E5\u770B\u5177\u4F53\u9519\u8BEF\u3002`),r.truncated=i.length>wi||r.entryLimitReached||r.directoryLimitReached||r.depthLimitedDirectories>0,{bound:!0,workspace:t,archives:i.slice(0,wi),discovery:r}}import{readFileSync as vf}from"node:fs";import{homedir as Sf}from"node:os";import{join as wf}from"node:path";var If={"zh-cn":"LanguageChs",chs:"LanguageChs","zh-tw":"LanguageCht",cht:"LanguageCht",en:"LanguageEng","en-us":"LanguageEng",eng:"LanguageEng",ja:"LanguageJpn","ja-jp":"LanguageJpn",jp:"LanguageJpn",ko:"LanguageKor","ko-kr":"LanguageKor",kr:"LanguageKor",fr:"LanguageFra",fra:"LanguageFra",de:"LanguageDeu",deu:"LanguageDeu",es:"LanguageSpa",spa:"LanguageSpa",pt:"LanguagePor",por:"LanguagePor",ru:"LanguageRus",rus:"LanguageRus",th:"LanguageTha",tha:"LanguageTha",vi:"LanguageVie",vie:"LanguageVie",id:"LanguageInd",ind:"LanguageInd",tr:"LanguageTur",tur:"LanguageTur",it:"LanguageIta",ita:"LanguageIta"};function xf(e){let i=[...String(e||"").matchAll(/Request to set language:([A-Za-z0-9_-]+)/g)].at(-1)?.[1]?.toLowerCase();return If[i]||null}function Cf(){return wf(Sf(),"AppData","LocalLow","miHoYo","\u539F\u795E","output_log.txt")}function Bs(e=Cf()){try{return xf(vf(e,"utf8"))}catch{return null}}import{existsSync as qn,lstatSync as kf,mkdirSync as js,readFileSync as vr,readdirSync as Ef,realpathSync as Hs,renameSync as Af,rmSync as _f,statSync as Ir,writeFileSync as Us}from"node:fs";import{createHash as Pf,randomUUID as Ls}from"node:crypto";import{homedir as Tf}from"node:os";import{basename as Rf,dirname as Sr,isAbsolute as Mf,join as wr,relative as Nf}from"node:path";var We=e=>Pf("sha256").update(e).digest("hex"),Wn=e=>qn(e)?We(vr(e)):null,Kn=(e,t)=>{let i=Nf(e,t);return!Mf(i)&&i!==".."&&!i.startsWith(`..${process.platform==="win32"?"\\":"/"}`)};function Xs(e,t){let i=Ne(e,t),r=i;for(;r!==e;){try{if(kf(r).isSymbolicLink())throw new Error("\u5B9E\u673A\u76EE\u6807\u4E0D\u80FD\u5305\u542B\u7B26\u53F7\u94FE\u63A5\u6216\u76EE\u5F55\u8054\u63A5")}catch(n){if(n.code!=="ENOENT")throw n}r=Sr(r)}if(qn(i)&&!Ir(i).isFile())throw new Error("\u5B9E\u673A\u76EE\u6807\u4E0D\u662F\u666E\u901A\u6587\u4EF6");return i}function Ws(e=wr(Tf(),"AppData","LocalLow","miHoYo","\u539F\u795E","BeyondLocal")){let t=r=>{try{return Ef(r,{withFileTypes:!0}).filter(n=>n.isDirectory()&&/^\d+$/.test(n.name)).map(n=>n.name)}catch{return[]}},i=[];for(let r of t(e)){let n=wr(e,r,"Beyond_Local_Save_Level");for(let a of t(n)){let o=wr(n,a,"external_lua_file","default_import_file");qn(o)&&Ir(o).isDirectory()&&i.push({uid:r,editorId:a,path:o})}}return{candidates:i}}var xr=class{constructor(t){this.controller=t,this.plan=null,this.lastResult=null}preview(){let t=this.controller,i=t.studio.archiveData(),r=Qt(i.scriptSync);if(!r)throw new Error("\u8BF7\u5148\u914D\u7F6E\u5B9E\u673A\u811A\u672C\u76EE\u5F55");let n=Hs(t.activeWorkspacePath()),a=Hs(r.clientImportRoot);if(!Ir(a).isDirectory())throw new Error("\u5B9E\u673A\u5BFC\u5165\u6839\u76EE\u5F55\u4E0D\u5B58\u5728");let o=r.workspaceDir?Ve(n,r.workspaceDir):n;if(!Ir(o).isDirectory())throw new Error("\u5DE5\u4F5C\u533A\u811A\u672C\u76EE\u5F55\u4E0D\u5B58\u5728");if(Kn(o,a)||Kn(a,o))throw new Error("\u5DE5\u4F5C\u533A\u811A\u672C\u76EE\u5F55\u4E0E\u5B9E\u673A\u76EE\u5F55\u4E0D\u80FD\u91CD\u53E0");let s=new Map,c=i.assets.scripts.map(u=>{let d={id:u.id,path:u.path,sourceKind:u.source.trim()?"\u5B58\u6863\u6E90\u7801":"\u5DE5\u4F5C\u533A\u6587\u4EF6"};try{let h=Oi(u.path);if(!/\.lua$/i.test(h))throw new Error("\u811A\u672C\u8DEF\u5F84\u5FC5\u987B\u4EE5 .lua \u7ED3\u5C3E");let p=r.workspaceDir?`${r.workspaceDir}/`:"";if(!h.startsWith(p))throw new Error("\u811A\u672C\u4E0D\u5728\u6240\u914D\u7F6E\u7684\u5DE5\u4F5C\u533A\u811A\u672C\u76EE\u5F55\u4E2D");let m=[r.clientSubdir,h.slice(p.length)].filter(Boolean).join("/"),g=Xs(a,m),S=g.toLowerCase();s.set(S,(s.get(S)||0)+1);let C=null,I="";try{C=vr(Ve(n,h),"utf8")}catch(G){I=G.message}if(!u.source.trim()&&C===null)throw new Error(I);let P=u.source.trim()?u.source:C,N=Wn(g);return{...d,target:g,targetRelative:m,source:P,diskSource:C,diskError:I,sourceMismatch:!!(u.source.trim()&&C!==null&&u.source!==C),beforeSource:N===null?"":vr(g,"utf8"),beforeHash:N,sourceHash:We(P),status:N===null?"\u65B0\u589E":N===We(P)?"\u672A\u53D8\u5316":"\u8986\u76D6"}}catch(h){return{...d,status:"\u9519\u8BEF",error:h.message}}});for(let u of c)u.target&&s.get(u.target.toLowerCase())>1&&(u.status="\u9519\u8BEF",u.error="\u591A\u4E2A\u811A\u672C\u6620\u5C04\u5230\u540C\u4E00\u76EE\u6807\u6587\u4EF6");let l=We(JSON.stringify({archive:i,workspace:n,root:a,rows:c}));return this.plan={id:Ls(),fingerprint:l,root:a,workspace:n,rows:c,pendingGuidChanges:i.controlGuidChanges.length,createdAt:new Date().toISOString()},this.plan}apply({planId:t,scriptIds:i,confirmed:r}){let n=this.plan;if(r!==!0||!n||n.id!==t)throw new Error("\u8BF7\u5148\u68C0\u67E5\u5DEE\u5F02\u5E76\u786E\u8BA4\u672C\u6B21\u590D\u5236");let a=this.preview();if(this.plan=null,a.fingerprint!==n.fingerprint)throw new Error("\u5185\u5BB9\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");if(n.pendingGuidChanges)throw new Error("\u8BF7\u5148\u6838\u5BF9\u5E76\u786E\u8BA4\u63A7\u4EF6\u7D22\u5F15\u7684 Lua \u5F15\u7528\u53D8\u66F4");if(!Array.isArray(i)||!i.length||new Set(i).size!==i.length)throw new Error("\u8BF7\u9009\u62E9\u8981\u590D\u5236\u7684\u811A\u672C");let o=i.map(u=>{let d=n.rows.find(h=>h.id===u);if(!d||d.error||d.status==="\u672A\u53D8\u5316")throw new Error("\u6240\u9009\u811A\u672C\u4E0D\u80FD\u590D\u5236\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");return d});this.controller.assertSavedArchive();let s=`.qxqy-script-sync-backups/${n.id}`,c=Ne(n.workspace,s);if(Kn(n.root,c))throw new Error("\u5907\u4EFD\u76EE\u5F55\u4E0D\u80FD\u4F4D\u4E8E\u5B9E\u673A\u811A\u672C\u76EE\u5F55\u4E2D");let l=[];for(let u of o){let d="";try{let h=Xs(n.root,u.targetRelative);if(Wn(h)!==u.beforeHash)throw new Error("\u76EE\u6807\u6587\u4EF6\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");if(u.beforeHash!==null){let p=Ne(n.workspace,`${s}/${u.targetRelative}`);js(Sr(p),{recursive:!0}),Us(p,vr(h),{flag:"wx"})}if(js(Sr(h),{recursive:!0}),d=wr(Sr(h),`.${Rf(h)}.${Ls()}.tmp`),Us(d,u.source,{flag:"wx"}),Wn(h)!==u.beforeHash)throw new Error("\u76EE\u6807\u6587\u4EF6\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");Af(d,h),l.push({id:u.id,target:h,status:"\u6210\u529F"})}catch(h){l.push({id:u.id,target:u.target,status:"\u5931\u8D25",error:h.message})}finally{d&&_f(d,{force:!0})}}return this.lastResult={completed:l.every(u=>u.status==="\u6210\u529F"),at:new Date().toISOString(),backupRoot:c,results:l},this.lastResult}};import{createHash as Of,randomUUID as Ff}from"node:crypto";import{mkdir as Df,open as zf,readFile as $f,rename as Gf,rm as Jn,stat as Vf,writeFile as Yf}from"node:fs/promises";import{homedir as Zn}from"node:os";import{join as jt,resolve as Bf}from"node:path";import{setTimeout as jf}from"node:timers/promises";var Qn=e=>Of("sha256").update(e).digest("hex");function Cr(e){return jt(process.platform==="win32"?process.env.LOCALAPPDATA||jt(Zn(),"AppData","Local"):process.platform==="darwin"?jt(Zn(),"Library","Caches"):process.env.XDG_CACHE_HOME||jt(Zn(),".cache"),"beyond-simulator",e)}var ot=class{constructor({cacheDir:t,source:i,version:r,extension:n,accepts:a,fetch:o=globalThis.fetch,timeout:s=12e3}){this.directory=jt(Bf(t),r,Qn(i).slice(0,12)),Object.assign(this,{source:i,extension:n,accepts:a,fetcher:o,timeout:s}),this.pending=new Map,this.failures=new Map,this.active=0,this.waiters=[]}async limited(t){this.active>=4?await new Promise(i=>this.waiters.push(i)):this.active++;try{return await t()}finally{let i=this.waiters.shift();i?i():this.active--}}async download(t,i,r,n){let a=await this.fetcher(new URL(t,this.source),{signal:r,redirect:"error",cache:n?"no-cache":"default"});if(!a.ok)throw Object.assign(new Error(`Asset source returned HTTP ${a.status}`),{status:a.status});if(Number(a.headers.get("content-length"))>i)throw new Error("Asset response too large");let o=[],s=0;for await(let c of a.body){if(s+=c.length,s>i)throw new Error("Asset response too large");o.push(c)}return Buffer.concat(o)}async cached(t){try{let i=await $f(t);return{data:i,...await this.decode(i),etag:`"${Qn(i)}"`}}catch(i){if(i.code==="ENOENT")return null;if(i.code==="EACCES"||i.code==="EPERM")throw i;return null}}async load(t,i=!1){let r=jt(this.directory,`${t}.${this.extension}`),n=!i&&await this.cached(r);if(n)return n;await Df(this.directory,{recursive:!0});let a=`${r}.lock`,o=Date.now()+3e4,s;for(;!s;)try{s=await zf(a,"wx")}catch(l){if(l.code!=="EEXIST")throw l;let u=!i&&await this.cached(r);if(u)return u;try{Date.now()-(await Vf(a)).mtimeMs>6e4&&await Jn(a,{force:!0})}catch(d){if(d.code!=="ENOENT")throw d}if(Date.now()>o)throw new Error("Timed out waiting for asset cache writer");await jf(80)}let c=`${r}.${Ff()}.tmp`;try{let l=!i&&await this.cached(r);if(l)return l;let u=new AbortController,d=setTimeout(()=>u.abort(),this.timeout),h;try{h=await this.produce(t,u.signal,i)}finally{clearTimeout(d),u.abort()}let p=await this.decode(h);return await Yf(c,h,{flag:"wx"}),await Gf(c,r),{data:h,...p,etag:`"${Qn(h)}"`}}finally{try{await Jn(c,{force:!0})}finally{await s.close(),await Jn(a,{force:!0})}}}get(t,{refresh:i=!1}={}){if(!this.accepts(t))return Promise.reject(Object.assign(new Error("Asset ID is not in the preview allowlist"),{status:404}));if(this.pending.has(t))return this.pending.get(t);let r=this.failures.get(t);if(!i&&r&&r.until>Date.now())return Promise.reject(r.error);let n=this.limited(()=>this.load(t,i)).then(a=>(this.failures.delete(t),a),a=>{throw i||this.failures.set(t,{until:Date.now()+6e4,error:a}),a}).finally(()=>this.pending.delete(t));return this.pending.set(t,n),n}async refresh(t){if(!this.accepts(t))throw Object.assign(new Error("Asset ID is not in the preview allowlist"),{status:404});return await this.pending.get(t)?.catch(()=>{}),this.failures.delete(t),this.get(t,{refresh:!0})}};import{createHash as Hf}from"node:crypto";import{createCanvas as Uf,loadImage as Ks}from"@napi-rs/canvas";var kr=class extends ot{constructor({cacheDir:t,source:i=_i,fetch:r=globalThis.fetch}){super({cacheDir:t,source:i,fetch:r,version:"border-v1",extension:"json",accepts:n=>qe(n)})}decode(t){let i=JSON.parse(t.toString("utf8"));if(i!==null&&(typeof i!="object"||Array.isArray(i)))throw new Error("Invalid image metadata");let r=Cs(i);return{raw:i,meta:r}}async produce(t,i,r){try{return await this.download(`border/${t}.json`,128*1024,i,r)}catch(n){if(n.status===404)return Buffer.from("null");throw n}}};var ta=20*1024*1024,Lf=Buffer.from("89504e470d0a1a0a","hex");function qs(e,t){return t.throwIfAborted(),new Promise((i,r)=>{let n=()=>r(t.reason);t.addEventListener("abort",n,{once:!0}),e.then(i,r).finally(()=>t.removeEventListener("abort",n))})}function Xf(){return process.env.QXQY_IMAGE_CACHE_DIR||Cr("images")}function ea(e){if(e.length<24||e.length>ta||!e.subarray(0,8).equals(Lf))throw new Error("Invalid sprite PNG");let t=e.readUInt32BE(16),i=e.readUInt32BE(20);if(!t||!i||t>8192||i>8192||t*i>16777216)throw new Error("Sprite PNG exceeds pixel limit")}var ia=class e extends ot{constructor({cacheDir:t=Xf(),fetch:i=globalThis.fetch,source:r,imageSource:n="StaticReference"}={}){let a=Ie(n);if(!["StaticReference","Prefab"].includes(a))throw new Error(`Unsupported image source: ${a}`);super({cacheDir:t,fetch:i,source:r||(a==="Prefab"?ha:_i),version:a==="Prefab"?Jt:Rr,extension:"png",accepts:o=>qe(o,a)}),this.imageSource=a,this.cacheDir=t,this.prefabStore=null,this.metadataStore=null}forSource(t){let i=Ie(t);if(i===this.imageSource)return this;if(i==="Prefab"&&this.imageSource==="StaticReference")return this.prefabStore||=new e({cacheDir:this.cacheDir,imageSource:"Prefab",fetch:(...r)=>this.fetcher(...r)});throw Object.assign(new Error(`Unsupported image source: ${i}`),{status:404})}get(t,{imageSource:i=this.imageSource,...r}={}){try{let n=this.forSource(i);return n===this?super.get(t,r):n.get(t,r)}catch(n){return Promise.reject(n)}}refresh(t,{imageSource:i=this.imageSource}={}){try{let r=this.forSource(i);return r===this?super.refresh(t):r.refresh(t)}catch(r){return Promise.reject(r)}}async decode(t){return ea(t),{image:await Ks(t)}}metadata(t,{imageSource:i=this.imageSource,refresh:r=!1}={}){try{let n=this.forSource(i);if(n!==this)return n.metadata(t,{refresh:r});if(!this.accepts(t))throw Object.assign(new Error("Image ID is not in the preview allowlist"),{status:404});return this.imageSource==="Prefab"?Promise.resolve({meta:null,raw:null}):(this.metadataStore||=new kr({cacheDir:this.cacheDir,source:this.source,fetch:(...a)=>this.fetcher(...a)}),r?this.metadataStore.refresh(t):this.metadataStore.get(t))}catch(n){return Promise.reject(n)}}async produce(t,i,r){if(this.imageSource==="Prefab"){let c=await this.download(`sprite/${t}.png`,ta,i,r);ea(c);let l=Ai(t);if(c.readUInt32BE(16)!==l||c.readUInt32BE(20)!==l)throw new Error("Prefab PNG does not match catalog dimensions");return c}let[n,a]=await Promise.all([this.download(`sprite/${t}.png`,ta,i,r),this.metadata(t,{refresh:r})]);ea(n);let o=await Ks(n),s=a.raw?Ss(o,a.raw,Uf):o;return a.raw?Buffer.from(s.toBuffer("image/png")):n}async prepare(t,i){let r=new Map,n=new Map,a=[],o=[...new Map((t||[]).filter(u=>u.kind==="image"&&u.visible!==!1&&qe(u.imageId,u.imageSource)).map(u=>[Ti(u.imageId,u.imageSource),{imageId:u.imageId,imageSource:Ie(u.imageSource)}])).entries()];i?.throwIfAborted();let s=AbortSignal.timeout(45e3),c=i?AbortSignal.any([i,s]):s,l=0;await Promise.all(Array.from({length:Math.min(4,o.length)},async()=>{for(;l<o.length&&!c.aborted;){let[u,d]=o[l++];try{let h=await qs(this.get(d.imageId,d),c);r.set(u,h.image);let p=await qs(this.metadata(d.imageId,d),c);n.set(u,p.meta)}catch(h){a.push({...d,error:h.message})}}}));for(let[,u]of o.slice(l))a.push({...u,error:"Image preparation timed out"});return i?.throwIfAborted(),{images:r,imageMetadata:n,warnings:a}}},Wf;function Ci(){return Wf||=new ia}async function Js(e,t,i=Ci()){let r=new URL(e.url,"http://localhost");if(r.pathname!==Pi.slice(0,-1)&&!r.pathname.startsWith(Pi))return!1;try{if(!["GET","HEAD"].includes(e.method))throw Object.assign(new Error("GET or HEAD required"),{status:405});let n=r.pathname.match(new RegExp(`^${Pi}(${Rr}|${Jt})/([0-9]+)\\.(png|json)$`));if(!n)throw Object.assign(new Error("Unknown image resource"),{status:404});let a={imageSource:n[1]===Jt?"Prefab":"StaticReference"};if(n[3]==="json"){let{meta:c}=await i.metadata(Number(n[2]),a),l=JSON.stringify(c),u=`"${Hf("sha256").update(l).digest("hex")}"`,d={"content-type":"application/json; charset=utf-8","cache-control":"private, max-age=43200",etag:u,"x-content-type-options":"nosniff"};return e.headers["if-none-match"]===u?(t.writeHead(304,d),t.end()):(t.writeHead(200,d),t.end(e.method==="HEAD"?void 0:l)),!0}let o=await i.get(Number(n[2]),a),s={"content-type":"image/png","cache-control":"private, max-age=43200",etag:o.etag,"x-content-type-options":"nosniff"};e.headers["if-none-match"]===o.etag?(t.writeHead(304,s),t.end()):(t.writeHead(200,{...s,"content-length":o.data.length}),t.end(e.method==="HEAD"?void 0:o.data))}catch(n){t.writeHead(n.status||502,{"content-type":"text/plain; charset=utf-8","cache-control":"no-store","x-content-type-options":"nosniff"}),t.end(e.method==="HEAD"?void 0:n.message)}return!0}var td=Math.max(1e3,Number(process.env.QXQY_PLAY_TIMEOUT_MS)||8e3),id=8e3;function Zs(){let e=new Error("operation aborted");return e.name="AbortError",e}function na(e){if(e!=="manual"&&e!=="realtime")throw new Error("clockMode must be manual or realtime");return e}var Ht=class{constructor(t="",{imageAssets:i=Ci(),clockMode:r="realtime"}={}){this.workspacePath=t?xt(t):"",this.studio=Yn(void 0,this.workspacePath?{workspacePath:this.workspacePath}:void 0),this.worker=null,this.pending=new Map,this.sequence=1,this.lock=Promise.resolve(),this.archivePath="",this.archiveStamp="",this.savedArchive="",this.scriptSync=new xr(this),this.imageAssets=i,this.defaultClockMode=na(r),this.playClockMode=this.defaultClockMode}async exclusive(t){let i=this.lock,r;this.lock=new Promise(n=>{r=n}),await i;try{return await t()}finally{r()}}get(){return{...this.studio.get(),storage:{path:this.archivePath}}}scriptSyncAction(t,i={}){if(t==="discover")return Ws();if(t==="status")return{config:this.get().scriptSync,lastResult:this.scriptSync.lastResult};if(t==="configure"){if(!Number.isInteger(i.expectedRevision))throw new Error("expectedRevision is required");return this.patch({op:"setScriptSync",config:i.config,expectedRevision:i.expectedRevision})}if(t==="preview")return this.scriptSync.preview();throw new Error("unknown script sync action (AI \u53EF\u914D\u7F6E\u548C\u9884\u89C8\uFF1B\u590D\u5236\u9700\u5728\u7F16\u8F91\u5668\u4E2D\u786E\u8BA4)")}assertSavedArchive(){if(!this.archivePath||this.savedArchive!==JSON.stringify(this.studio.archiveData()))throw new Error("\u8BF7\u5148\u4FDD\u5B58\u5F53\u524D\u5B8C\u6574\u5B58\u6863\uFF0C\u518D\u786E\u8BA4\u590D\u5236");let t=Ve(this.activeWorkspacePath(),this.archivePath);if(We(ra(t))!==this.archiveStamp)throw new Error("\u5B58\u6863\u6587\u4EF6\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u52A0\u8F7D\u5E76\u68C0\u67E5")}saveForScriptSync(t,i){if(i!==this.get().version)throw new Error("revision conflict: reload before saving");let r=Ne(this.activeWorkspacePath(),t);if(qf(r)){let n=this.archivePath?Ne(this.activeWorkspacePath(),this.archivePath):"";if(r!==n||We(ra(r))!==this.archiveStamp)throw new Error("File changed or already exists; load it again or save under a new path")}return this.saveArchive(t)}patch(t){return{...this.studio.patch(t),storage:{path:this.archivePath}}}listArchives(){return br(this.workspacePath)}loadArchive(t){let i=this.activeWorkspacePath();if(!i)throw new Error("workspace is not bound");let r=Ve(i,t),n=ra(r),a=this.studio.importData("json",n.toString("base64"),Qf(r));return this.archivePath=String(t).trim().replaceAll("\\","/"),this.archiveStamp=We(n),this.savedArchive=JSON.stringify(this.studio.archiveData()),a}saveArchive(t=this.archivePath||"qxqy-simulator.save.json"){let i=String(t).trim(),r=this.activeWorkspacePath();if(!r)throw new Error("workspace is not bound");let n=Ne(r,i);Jf(ed(n),{recursive:!0});let a=Buffer.from(JSON.stringify(this.studio.archiveData(),null,2)+`
|
|
113
|
+
`,"utf8");return Zf(n,a),this.archivePath=i.replaceAll("\\","/"),this.archiveStamp=We(a),this.savedArchive=JSON.stringify(this.studio.archiveData()),{path:this.archivePath,bytes:a.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 Kf(new URL("./worker.js",import.meta.url),{type:"module"});return t.on("message",i=>{let r=this.pending.get(i?.id);r&&(this.pending.delete(i.id),i.ok?r.resolve(i.value):r.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,r,n=td){let a=this.worker||this.createWorker(),o=this.sequence++;return new Promise((s,c)=>{let l=!1,u=(p,m)=>{l||(l=!0,clearTimeout(h),r?.removeEventListener("abort",d),p(m))},d=()=>{this.pending.delete(o),u(c,Zs()),this.terminateWorker(Zs())},h=setTimeout(()=>{this.pending.delete(o);let p=new Error(`play worker timed out after ${n}ms`);u(c,p),this.terminateWorker(p)},n);if(this.pending.set(o,{resolve:p=>u(s,p),reject:p=>u(c,p)}),r?.aborted)return d();r?.addEventListener("abort",d,{once:!0}),a.postMessage({id:o,action:t,args:i})})}async play(t,i={},r){if((t==="start"||t==="device")&&!i.language){let n=Bs();n&&(i={...i,language:n})}if(t==="start"){let n=na(i.clockMode??this.defaultClockMode);return await this.terminateWorker(),this.playClockMode=n,this.request("start",{archive:this.studio.archiveData(),workspacePath:this.activeWorkspacePath(),...i,clockMode:n},r)}if(t==="device"){let n=String(i.canvasId||"").trim();if(!K[n])throw new Error(`unknown canvas preset: ${n||"(empty)"} (available: ${Object.keys(K).join(", ")})`);let a=na(i.clockMode??this.playClockMode);return await this.terminateWorker(),this.playClockMode=a,this.request("start",{archive:this.studio.archiveData(),workspacePath:this.activeWorkspacePath(),...i,canvasId:n,clockMode:a},r)}if(t==="stop"){if(!this.worker)return{running:!1,tree:[],logs:[]};try{return await this.request("stop",i,r)}finally{await this.terminateWorker()}}if(!this.worker)throw new Error("play session has not started");return this.request(t,i,r)}async playScreenshot(t){if(!this.worker)throw new Error("play session has not started");let i=await this.request("get",{view:!0},t,id),r=await this.imageAssets.prepare(i.scene?.nodes,t),n=Ns(i.scene,i.canvasWidth,i.canvasHeight,r);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,clockMode:i.clockMode,width:n.width,height:n.height,pixelWidth:n.pixelWidth,pixelHeight:n.pixelHeight,assetWarnings:r.warnings}}async uiScreenshot(t){let i=this.studio.get(),r=await this.imageAssets.prepare(i.boxes,t),n=Fs(i,r);return{data:n.data,page:n.page,width:n.width,height:n.height,pixelWidth:n.pixelWidth,pixelHeight:n.pixelHeight,assetWarnings:r.warnings}}async dispose(){await this.terminateWorker()}};var nd=new Set(["server-control-template","client-control-template"]),ad=new Set(["start","device","view","get","step","pointer","key","click","pause","resume","stop","serverGet","serverSet","serverSend","history","saveCase","runCase"]);function Qs(e){return String(e||"").trim().replaceAll("\\","/")}function el(e,t){let i=rd(Ve(e,t));return`${i.size}:${i.mtimeMs}`}function od(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 tl(e,t,i){let r=i==="stop"||t?.running===!1,n=Array.isArray(t?.logs)?t.logs.slice(-100):e.logs;return{running:!r,paused:r?!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:n}}var Er=class{constructor({workspace:t,initialPath:i="",watchIntervalMs:r=700,discoveryIntervalMs:n=5e3,imageAssets:a}={}){this.workspace=xt(t),this.controller=new Ht(this.workspace,{imageAssets:a}),this.initialPath=Qs(i),this.watchIntervalMs=Math.max(100,Number(r)||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,this.discoveryIntervalMs=Math.max(100,Number(n)||5e3),this.archiveCache=null,this.archiveCacheTime=0,this.openGeneration=0,this.disposed=!1}async initialize(){let t=this.archives().archives,i=this.initialPath||t[0]?.path||"";if(i)try{await this.open(i,"startup")}catch{}return this.timer=setInterval(()=>{this.refreshFromDisk()},this.watchIntervalMs),this.state()}archives(t=!1){return(t||!this.archiveCache||Date.now()-this.archiveCacheTime>=this.discoveryIntervalMs)&&(this.archiveCache=br(this.workspace),this.archiveCacheTime=Date.now()),this.archiveCache}previewStatus(){let t=this.controller.get();return{service:"beyond-simulator-web",version:da.version,workspace:this.workspace,activePath:this.activePath,lastLoadedAt:this.lastLoadedAt,lastError:this.lastError,revision:this.activePath?t.version:null,name:this.activePath&&t.save?.name||""}}state(){let t=this.archives();return{...this.previewStatus(),archives:t.archives,discovery:t.discovery,snapshot:od(this.controller.get()),play:this.playState}}recordError(t){let i=t?.message||String(t),r=i!==this.lastError;this.lastError=i,r&&this.emit({type:"error",error:i})}async open(t,i="manual",r=this.openGeneration){let n=Qs(t);if(!n)throw new Error("path is required");return this.controller.exclusive(async()=>{if(this.disposed||i==="external-change"&&r!==this.openGeneration)return this.state();try{await this.controller.play("stop"),this.playState=tl(this.playState,{running:!1,logs:[]},"stop");let a=el(this.workspace,n),o=this.controller.loadArchive(n);return this.activePath=n,this.activeStamp=a,this.initialPath="",this.openGeneration++,this.lastLoadedAt=new Date().toISOString(),this.lastError="",this.archiveCache=null,this.emit({type:"archive",reason:i,path:n,revision:o.version}),this.state()}catch(a){throw this.recordError(a),a}})}async refreshFromDisk(){if(this.refreshing||this.disposed)return!1;this.refreshing=!0;try{if(!this.activePath){let i=this.initialPath||this.archives().archives[0]?.path||"";return i?(await this.open(i,"external-change"),!0):!1}return el(this.workspace,this.activePath)===this.activeStamp&&!this.lastError?!1:(await this.open(this.activePath,"external-change"),!0)}catch(t){return this.recordError(t),!1}finally{this.refreshing=!1}}async setView({assetType:t,canvasId:i}={}){if(t&&!nd.has(t))throw new Error(`unknown asset type: ${t}`);if(i&&!K[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 r=this.controller.get().version;this.controller.patch({op:"setCanvas",canvasId:i,expectedRevision:r})}}),this.emit({type:"view"}),this.state()}async play(t,i={},r){if(!ad.has(t))throw new Error(`unknown play action: ${t||"(empty)"}`);let n=await this.controller.exclusive(()=>this.controller.play(t,i,r));return this.playState=tl(this.playState,n,t),this.emit({type:"play",action:t,frame:this.playState.frame}),n}async currentState(t){return this.state()}editorScreenshot(t){return this.controller.uiScreenshot(t)}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.disposed=!0,this.timer&&clearInterval(this.timer),this.timer=null,this.listeners.clear(),await this.controller.exclusive(()=>this.controller.dispose())}};import{existsSync as sd,readFileSync as ld}from"node:fs";import{createHash as cd}from"node:crypto";var ud=new Set(["get","patch","import","export","archives","load-archive","save","play","script-sync","script-sync-apply","image-refresh"]),aa=e=>cd("sha256").update(ld(e)).digest("hex"),Ar=class{constructor(t,{initialPath:i="",maxSessions:r=8,imageAssets:n}={}){this.workspace=t,this.initialPath=i,this.maxSessions=r,this.sessions=new Map,this.imageAssets=n}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 r={controller:new Ht(this.workspace,{imageAssets:this.imageAssets}),path:"",fileStamp:""};this.initialPath&&this.load(r,this.initialPath),this.sessions.set(t,r)}return this.sessions.get(t)}snapshot(t){return{...t.controller.get(),storage:{path:t.path}}}load(t,i){let r=Ve(this.workspace,i),n=t.controller.loadArchive(i);return t.path=String(i).replaceAll("\\","/"),t.fileStamp=aa(r),{...n,snapshot:this.snapshot(t)}}async call(t,i,r){if(!ud.has(t))throw new Error("Unknown editor action");let n=this.getSession(i.sessionId),a=n.controller;return a.exclusive(async()=>{if(t==="get")return this.snapshot(n);if(t==="image-refresh")return await a.imageAssets.refresh(i.imageId,{imageSource:i.imageSource}),{imageId:i.imageId,imageSource:i.imageSource||"StaticReference",refreshed:!0};if(t==="script-sync")return a.scriptSyncAction(i.action,i.args||{});if(t==="script-sync-apply")return a.scriptSync.apply(i);if(t==="archives")return a.listArchives();if(t==="patch"){if(!Number.isInteger(i.op?.expectedRevision))throw new Error("expectedRevision is required");return a.patch(i.op),this.snapshot(n)}if(t==="export")return a.studio.exportData(i.format,i.assetType);if(t==="play")return a.play(i.action,i.args||{},r);if(t==="load-archive"||t==="import"){if(await a.play("stop"),t==="load-archive")return this.load(n,i.path);let o=a.studio.importData(i.format,i.data,i.filename);return n.path="",n.fileStamp="",{...o,snapshot:this.snapshot(n)}}if(t==="save"){if(i.expectedRevision!==a.get().version)throw new Error("revision conflict: reload before saving");let o=Ne(this.workspace,i.path);if(sd(o)){let c=n.path?Ne(this.workspace,n.path):"";if(o!==c||aa(o)!==n.fileStamp)throw new Error("File changed or already exists; load it again or save under a new path")}let s=a.saveArchive(i.path);return n.path=s.path,n.fileStamp=aa(o),s}})}async dispose(){await Promise.all([...this.sessions.values()].map(t=>t.controller.exclusive(()=>t.controller.dispose()))),this.sessions.clear()}};var il=32*1024*1024;function fd(e){if(e.length<8||e.length>il)throw new Error("Invalid MP3 size");let t=0,i=0;if(e.subarray(0,3).toString()==="ID3"){if(e.length<10||e[3]<2||e[3]>4||e.subarray(6,10).some(r=>r>127))throw new Error("Invalid MP3 ID3 header");t=10+(e[6]<<21|e[7]<<14|e[8]<<7|e[9])+(e[5]&16&&e[3]===4?10:0)}for(;t+4<=e.length;){if(e.length-t===128&&e.subarray(t,t+3).toString()==="TAG"){t=e.length;break}let r=e[t+1],n=e[t+2],a=r>>3&3,o=n>>2&3,s=n>>4;if(e[t]!==255||(r&224)!==224||(r&6)!==2||a===1||o===3||s===0||s===15)throw new Error("Invalid MP3 frame");let c=(a===3?[0,32,40,48,56,64,80,96,112,128,160,192,224,256,320]:[0,8,16,24,32,40,48,56,64,80,96,112,128,144,160])[s],l=[44100,48e3,32e3][o]/(a===3?1:a===2?2:4),u=Math.floor((a===3?144e3:72e3)*c/l)+(n>>1&1);t+=u,i++}if(i<2||t!==e.length)throw new Error("Truncated or invalid MP3")}var oa=class extends ot{constructor({cacheDir:t=process.env.QXQY_AUDIO_CACHE_DIR||Cr("audio"),fetch:i=globalThis.fetch,source:r=Wo}={}){super({cacheDir:t,fetch:i,source:r,version:Sn,extension:"mp3",accepts:n=>ir(n)!==null,timeout:2e4})}decode(t){return fd(t),{}}produce(t,i,r){return this.download(`audio/${t}.mp3`,il,i,r)}},dd;function sa(){return dd||=new oa}async function rl(e,t,i=sa()){let r=new URL(e.url,"http://localhost");if(r.pathname!==tr.slice(0,-1)&&!r.pathname.startsWith(tr))return!1;try{if(!["GET","HEAD"].includes(e.method))throw Object.assign(new Error("GET or HEAD required"),{status:405});let n=r.pathname.match(new RegExp(`^${tr}${Sn}/([0-9]+)\\.mp3$`));if(!n)throw Object.assign(new Error("Unknown audio resource"),{status:404});let a=await i.get(Number(n[1])),o=a.data.length,s={"content-type":"audio/mpeg","cache-control":"private, max-age=43200",etag:a.etag,"accept-ranges":"bytes","x-content-type-options":"nosniff"};if(e.headers["if-none-match"]===a.etag)return t.writeHead(304,s),t.end(),!0;let c=e.headers.range,l=0,u=o-1,d=200;if(c&&(!e.headers["if-range"]||e.headers["if-range"]===a.etag)){let h=c.match(/^bytes=(\d*)-(\d*)$/);if(!h||!h[1]&&!h[2])throw Object.assign(new Error("Invalid byte range"),{status:416,size:o});if(h[1]?(l=Number(h[1]),u=h[2]?Math.min(o-1,Number(h[2])):u):l=Math.max(0,o-Number(h[2])),!Number.isSafeInteger(l)||!Number.isSafeInteger(u)||l>=o||u<l)throw Object.assign(new Error("Unsatisfiable byte range"),{status:416,size:o});d=206,s["content-range"]=`bytes ${l}-${u}/${o}`}t.writeHead(d,{...s,"content-length":u-l+1}),t.end(e.method==="HEAD"?void 0:a.data.subarray(l,u+1))}catch(n){t.writeHead(n.status||502,{"content-type":"text/plain; charset=utf-8","cache-control":"no-store",...n.status===416?{"content-range":`bytes */${n.size}`}:{}}),t.end(e.method==="HEAD"?void 0:n.message)}return!0}var vd=sl(new URL(".",import.meta.url)),Sd=ol(vd,"public"),al=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"]]),wd={".html":"text/html; charset=utf-8",".js":"text/javascript; charset=utf-8",".css":"text/css; charset=utf-8"};function Id(e=process.argv.slice(2)){let t=(i,r="")=>{let n=e.indexOf(i);return n>=0&&e[n+1]?e[n+1]:r};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 Pr(e,t="'none'"){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 ${t}`,"x-content-type-options":"nosniff"}}function ke(e,t,i){e.writeHead(t,Pr("application/json; charset=utf-8")),e.end(JSON.stringify(i))}function xd(e,t){e.writeHead(200,{...Pr("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 _r(e,t=1024*1024){let i=[],r=0;for await(let n of e){if(r+=n.length,r>t)throw new Error("request body is too large");i.push(n)}return i.length?JSON.parse(Buffer.concat(i).toString("utf8")):{}}function Cd(e){let t=process.platform==="win32"?"cmd.exe":process.platform==="darwin"?"open":"xdg-open",i=process.platform==="win32"?["/c","start","",e]:[e];hd(t,i,{detached:!0,stdio:"ignore",windowsHide:!0}).unref()}async function kd(e={}){e={...e,imageAssets:e.imageAssets||Ci(),audioAssets:e.audioAssets||sa()};let t=e.host||"127.0.0.1",i=e.password??process.env.QXQY_WEB_PASSWORD??"",r=["127.0.0.1","localhost","::1"].includes(t);if(!r&&!i)throw new Error("QXQY_WEB_PASSWORD is required when listening outside loopback");let n=g=>yd("sha256").update(g).digest(),a=n(i),o=new Er(e);await o.initialize();let s=new Ar(o.workspace,e),c=new Set,l=o.subscribe(g=>{let S=`event: state
|
|
114
|
+
data: ${JSON.stringify(g)}
|
|
115
115
|
|
|
116
|
-
`;for(let
|
|
116
|
+
`;for(let C of c)C.write(S)}),u=md(async(g,S)=>{let C=new URL(g.url||"/","http://localhost"),I=new AbortController;g.once("aborted",()=>I.abort());try{if(g.method==="GET"&&C.pathname==="/health"){ke(S,200,{status:"ok"});return}if(i){let P=String(g.headers.authorization||""),N=P.startsWith("Basic ")?Buffer.from(P.slice(6),"base64").toString("utf8"):"";if(!(N.startsWith("simulator:")&&bd(n(N.slice(10)),a))){S.setHeader("www-authenticate",'Basic realm="QXQY Simulator", charset="UTF-8"'),ke(S,401,{ok:!1,error:"Authentication required"});return}}if(!i&&r){let P=new URL(`http://${g.headers.host}`).hostname;if(!["127.0.0.1","localhost","[::1]"].includes(P)){ke(S,403,{ok:!1,error:"Local Host required"});return}}if(g.method==="POST"){if(!/^application\/json(?:;|$)/i.test(g.headers["content-type"]||"")){ke(S,415,{ok:!1,error:"application/json required"});return}if(g.headers.origin&&new URL(g.headers.origin).host!==g.headers.host){ke(S,403,{ok:!1,error:"Cross-origin requests are not allowed"});return}}if(await Js(g,S,e.imageAssets)||await rl(g,S,e.audioAssets))return;if(g.method==="GET"&&al.has(C.pathname)){let P=al.get(C.pathname),N=pd(ol(Sd,P));S.writeHead(200,Pr(wd[gd(P)]||"application/octet-stream",C.pathname==="/editor/play"?"'self'":"'none'")),S.end(N);return}if(g.method==="GET"&&C.pathname==="/api/state"){C.searchParams.get("refresh")==="1"&&o.archives(!0),ke(S,200,{ok:!0,value:await o.currentState(I.signal)});return}if(g.method==="GET"&&C.pathname==="/api/preview"){ke(S,200,{ok:!0,value:o.previewStatus()});return}if(g.method==="GET"&&C.pathname==="/api/editor.png"){xd(S,await o.editorScreenshot(I.signal));return}if(g.method==="GET"&&C.pathname==="/api/events"){S.writeHead(200,{...Pr("text/event-stream; charset=utf-8"),connection:"keep-alive"}),S.write(`: connected
|
|
117
117
|
|
|
118
|
-
`),c.add(S),
|
|
119
|
-
`),e.open&&
|
|
120
|
-
`),process.exitCode=1});export{
|
|
118
|
+
`),c.add(S),g.once("close",()=>c.delete(S));return}if(g.method==="POST"&&C.pathname==="/api/open"){let P=await _r(g);if(P.expectedWorkspace!==void 0){let N=xt(P.expectedWorkspace);if(!(process.platform==="win32"?N.toLowerCase()===o.workspace.toLowerCase():N===o.workspace))throw new Error(`Web workspace mismatch: ${o.workspace}`)}ke(S,200,{ok:!0,value:await o.open(P.path,P.expectedWorkspace===void 0?"manual":"mcp-preview")});return}if(g.method==="POST"&&C.pathname.startsWith("/editor/api/")){let P=await _r(g,8388608),N=C.pathname.slice(12),G=await s.call(N,P,I.signal);ke(S,200,{ok:!0,value:G});return}if(g.method==="POST"&&C.pathname==="/api/view"){ke(S,200,{ok:!0,value:await o.setView(await _r(g))});return}if(g.method==="POST"&&C.pathname==="/api/play"){let P=await _r(g);ke(S,200,{ok:!0,value:await o.play(P.action,P.args||{},I.signal)});return}ke(S,404,{ok:!1,error:"not found"})}catch(P){ke(S,400,{ok:!1,error:P?.message||String(P)})}}),d=Number.isFinite(Number(e.port))?Number(e.port):4173;try{await new Promise((g,S)=>{u.once("error",S),u.listen(d,t,g)})}catch(g){throw l(),await o.dispose(),await s.dispose(),g}let h=u.address(),p=typeof h=="object"&&h?h.port:d;return{url:`http://${t.includes(":")?`[${t}]`:t}:${p}`,session:o,server:u,async close(){l();for(let g of c)g.end();c.clear(),await o.dispose(),await s.dispose(),await new Promise(g=>u.close(g))}}}async function Ed(){let e=Id(),t=await kd(e);process.stdout.write(`QXQY Simulator Web: ${t.url}
|
|
119
|
+
`),e.open&&Cd(t.url);let i=()=>{t.close().finally(()=>process.exit(0))};process.once("SIGINT",i),process.once("SIGTERM",i)}function Ad(){if(!process.argv[1])return!1;try{return nl(process.argv[1])===nl(sl(import.meta.url))}catch{return!1}}Ad()&&Ed().catch(e=>{process.stderr.write(`${e?.stack||e}
|
|
120
|
+
`),process.exitCode=1});export{kd as createWebServer};
|