beyond-simulator-web 0.3.2 → 0.3.4

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/server.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{spawn as pu}from"node:child_process";import{createServer as mu}from"node:http";import{readFileSync as gu,realpathSync as $a}from"node:fs";import{extname as yu,resolve as Ga}from"node:path";import{fileURLToPath as za}from"node:url";import{createHash as bu,timingSafeEqual as vu}from"node:crypto";import{statSync as au}from"node:fs";var gn={name:"beyond-simulator-web",version:"0.3.2",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 se=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"}}),li="pc-16-9",pe=2,yt=Object.freeze({KEYBOARD:"pc-16-9",TOUCHSCREEN:"mobile-16-9",CONTROLLER_CONSOLE:"pc-16-9",CONTROLLER_MOBILE:"mobile-16-9"}),bt=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"}),ci=Object.freeze(["server-container","container","textbox","cursor","reference","grid","image","button","textwindow","keyhint","animation","fullscreen"]),yn=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}),vt=Object.freeze({100001:"rect",100002:"circle",100003:"triangle",100004:"fourstar",100005:"fivestar",100006:"ring"}),bn=50888,Dt=Object.freeze({font:4294967295,bg:16777215,outline:858993459,image:4294967295});import{Worker as Zc}from"node:worker_threads";import{existsSync as Qc,mkdirSync as eu,readFileSync as un,writeFileSync as tu}from"node:fs";import{basename as iu,dirname as ru}from"node:path";import{existsSync as ii,readFileSync as Ql}from"node:fs";import{randomUUID as ec}from"node:crypto";import{isAbsolute as vn,win32 as Sn}from"node:path";function ui(e,t=!1){let i=String(e??"").trim().replaceAll("\\","/");if(t&&(!i||i==="."))return"";if(!i||vn(i)||Sn.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 Gt(e){if(e==null)return null;if(e.version!==1)throw new Error("unsupported scriptSync version");let t=String(e.clientImportRoot||"").trim();if(!vn(t)&&!Sn.isAbsolute(t))throw new Error("\u5B9E\u673A\u5BFC\u5165\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");return{version:1,workspaceDir:ui(e.workspaceDir,!0),clientImportRoot:t,clientSubdir:ui(e.clientSubdir,!0)}}import{basename as Pt,dirname as tc,isAbsolute as ic,join as aa,resolve as sa}from"node:path";function St(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)=>St(r,`${t}[${n}]`,i));else for(let[r,n]of Object.entries(e))St(n,`${t}.${r}`,i);i.delete(e)}}function G(e){return St(e),JSON.parse(JSON.stringify(e))}function wn(e,t="$"){St(e,t)}function Cn(e){return X[e]||X[li]}function zt(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 ls(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 cs(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 Te(e){let t=e||fi();return{scale:ls(t.scale),rotation:cs(t.rotation),anchorMin:zt(t.anchorMin??t.anchor_min,.5,.5),anchorMax:zt(t.anchorMax??t.anchor_max,.5,.5),offset:zt(t.offset,0,0),size:zt(t.size,0,0),pivot:zt(t.pivot,.5,.5)}}function me(e,t=0){let i=Number(e);return Number.isFinite(i)?i:t}function $e(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},f=t.pivot||{x:t.pivotX,y:t.pivotY},p=me(a?.x,.5)*i,h=me(a?.y,.5)*r,m=me(s?.x,.5)*i,y=me(s?.y,.5)*r,v=me(l?.x),x=me(l?.y),I=me(f?.x,.5),A=me(f?.y,.5),O=m-p+v,F=y-h+x,U=n+p+me(c?.x)-v*I,ee=o+h+me(c?.y)-x*A;return{left:U,bottom:ee,width:O,height:F,right:U+O,top:ee+F,centerX:U+O/2,centerY:ee+F/2}}function wt(){return{a:1,b:0,c:0,d:1,tx:0,ty:0}}function us(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 Qe(e,t,i){return{x:e.a*t+e.c*i+e.tx,y:e.b*t+e.d*i+e.ty}}function di(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 Zi(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=me(i?.z)*Math.PI/180,a=Math.cos(o),s=Math.sin(o),c=me(r?.x,1),l=me(r?.y,1),f=e.left+e.width*me(n?.x,.5),p=e.bottom+e.height*me(n?.y,.5),h=a*c,m=s*c,y=-s*l,v=a*l;return{a:h,b:m,c:y,d:v,tx:f-h*f-y*p,ty:p-m*f-v*p}}function Vt(e,t,i){return us(e||wt(),Zi(t,i))}function In(e,t){let i=Qe(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 ge(e){let t=typeof e=="string"?Cn(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 Qi(e){return{posX:e.centerX,posY:e.centerY,width:e.width,height:e.height}}function et(e,t,i){let r=Te(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,f=Number(i.width),p=Number(i.height),h=Number(i.posX),m=Number(i.posY),y=h-f/2,v=m-p/2;return r.size={x:f-(c-a),y:p-(l-s)},r.offset={x:y-e.left-a+r.size.x*r.pivot.x,y:v-e.bottom-s+r.size.y*r.pivot.y},r}function kn(e,t){let i=Te(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 En(e){let t=Te(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 tt(e){return Cn(e).platform}function xn(e){let t={};for(let i of se)t[i]=e(i);return t}var fs={scale:["x","y","z"],rotation:["x","y","z"],anchorMin:["x","y"],anchorMax:["x","y"],offset:["x","y"],size:["x","y"],pivot:["x","y"]};function An(e,t){for(let[i,r]of Object.entries(fs))for(let n of r)if(!Number.isFinite(e?.[i]?.[n]))throw new Error(`${t}.${i}.${n} must be a finite number`)}function Le(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(!se.includes(i))throw new Error(`${t}: unknown platform ${i}`);for(let i of se)An(e[i],`${t}.${i}`)}function it(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`);Le(e.transformByPlatform,`${e.name||e.id||"\u63A7\u4EF6"}.transformByPlatform`)}function rt(e,t){if(!se.includes(t))throw new Error(`unknown platform ${t}`);return An(e?.[t],`transformByPlatform.${t}`),Te(e[t])}var ds=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"}]),hs=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 Pn(e){return[...ds,...hs[e]||[]]}function _n(e,t){return Pn(e).find(i=>i.key===t)||null}function er(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 Rn(e,t={}){let i={};for(let r of Pn(e)){let n=Object.hasOwn(t||{},r.key)?t[r.key]:r.defaultValue;i[r.key]=er(r,n)}return i}function ke(e){let t=Number(e);return Number.isSafeInteger(t)&&t>0&&t<=2147483647}function tr(e,t){if(e){t(e);for(let i of e.children||[])tr(i,t)}}function Ct(e,t=new Set,{skipServerContainer:i=!1}={}){return tr(e,r=>{i&&r.kind==="server-container"||ke(r.guid)&&t.add(Number(r.guid))}),t}function Be(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 Tn(e,t=new Set,{skipServerContainer:i=!1}={}){let r=[];tr(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=Be(t);n.guid=o,t.add(o)}return t}var ir=1;function rr(e="n"){let t=`${e}${ir}`;return ir+=1,t}function hi(e=1){ir=e}function nr(e,{isRootContainer:t=!1}={}){if(e==="server-container"||e==="fullscreen"||e==="container"&&t)return fi({layout:"stretch"});let i=yn[e]||[80,80];return fi({layout:"center",size:i})}function ps(e,t){return xn(()=>nr(e,t))}function ms(e){Le(e);let t={};for(let i of se)t[i]=rt(e,i);return t}function W(e,t={}){if(!bt[e])throw new Error(`unknown kind: ${e}`);Object.hasOwn(t,"transformByCanvas")&&it(t);let i=t.isRootContainer===!0,r=t.id||rr(e==="server-container"?"sc":"n"),n=Object.hasOwn(t,"transformByPlatform")?ms(t.transformByPlatform):ps(e,{isRootContainer:i}),o={id:r,kind:e,name:t.name||bt[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:Rn(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??Dt.font,o.bgColor=t.bgColor??Dt.bg,o.enableOutline=t.enableOutline!==!1,o.outlineColor=t.outlineColor??Dt.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??Dt.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??bn,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 nt(){hi(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}),f=W("animation",{id:"n10",name:"\u754C\u9762\u52A8\u6548"}),p=W("fullscreen",{id:"n11",name:"\u5168\u5C4F\u52A8\u6548"}),h=(m,y,v)=>{for(let x of Object.values(m.transformByPlatform))x.offset={x:y,y:v}};return h(i,-300,250),h(r,-300,140),h(n,-300,30),h(o,-300,-100),h(a,0,0),h(s,300,250),h(c,300,140),h(l,300,30),h(f,300,-100),t.children.push(i,r,n,o,a,s,c,l,f,p),e.children.push(t),hi(12),Tn(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 It(){hi(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,f)=>{for(let p of Object.values(c.transformByPlatform))p.offset={x:l,y:f}};return((c,l,f)=>{for(let p of Object.values(c.transformByPlatform))p.size={x:l,y:f}})(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),hi(6),{version:1,layoutSchemaVersion:pe,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 q(e,t,i=null){t(e,i);for(let r of e.children||[])q(r,t,e)}function ue(e,t){let i=null;return q(e,r=>{r.id===t&&(i=r)}),i}function or(e,t="n"){let i=rr(t);for(;ue(e,i);)i=rr(t);return i}function Ye(e,t){let i=null;return q(e,(r,n)=>{r.id===t&&(i=n)}),i}function ar(e){let t=e.root||e;return t.kind==="container"?t:(t.children||[]).find(i=>i.kind==="container")||(t.children||[])[0]||t}function Lt(e){if(e.meta?.assetType!=="client-control-template")return ar(e);let t=ue(e.root,e.selectedId);if(!t||t.kind==="server-container")return e.root.children?.[0]||e.root;let i=Ye(e.root,t.id);for(;i&&i.kind!=="server-container";)t=i,i=Ye(e.root,t.id);return t}function sr(e){it(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"&&gs(e.transformByPlatform);let i=W(e.kind,t);return i.children=(e.children||[]).map(r=>sr(r)),i}function gs(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 Mn(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 Nn(e,t){if(e.id===t)throw new Error("cannot remove root");let i=Ye(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 Fn=1e-4;function ys(e,t){return Math.abs(e.anchorMax[t]-e.anchorMin[t])>Fn&&Math.abs(e.size[t])<=Fn}function bs(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=$e(t,e),n=(r.centerX-t.left)/t.width,o=(r.centerY-t.bottom)/t.height,a=et(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"])ys(e,s)&&(a.offset[s]=e.offset[s],a.size[s]=e.size[s]);return a}function On({transformByPlatform:e,source:t,canvasId:i,syncAllDevices:r,sourceParentBox:n=ge(i),targetParentBoxByPlatform:o={}}){Le(e);let a=tt(i),s={};for(let c of se)c===a?s[c]=Te(t):r!==!1?s[c]=bs(t,n,o[c]||ge(yt[c])):s[c]=rt(e,c);return Le(s),s}function Ue(e,t){return rt(e,tt(t))}function $n(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 He(e,t,i=tt(t)){let r=ge(t),n={};function o(a,s,c){let l=rt(a.transformByPlatform,i),f=$e(s,l),p=a.kind==="server-container"?c:Vt(c,f,l),h=In(f,p);n[a.id]={...f,...Qi(f),id:a.id,kind:a.kind,name:a.name,visible:a.visible!==!1,active:a.active!==!1,rotationZ:l.rotation.z,renderLeft:h.left,renderBottom:h.bottom,renderWidth:h.width,renderHeight:h.height,renderRotationZ:h.rotationZ,renderMatrix:p,primitive:a.kind==="image"?vt[a.imageId]||"missing":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 m=a.kind==="server-container"?s:f;for(let y of a.children||[])o(y,m,p)}return o(e,r,wt()),{canvas:r,boxes:n}}function lr(e,t){let i=[];function r(n,o,a=null,s=[],c=0,l=1,f=e.id){i.push({id:n.id,guid:t?.get(n.id)??(n.guid||0),kind:n.kind,name:n.name,label:bt[n.kind]||n.kind,depth:o,parentId:a,ancestorIds:s,siblingIndex:c,siblingCount:l,templateId:f,childCount:(n.children||[]).length,incomplete:!ci.includes(n.kind)});let p=n.children||[];for(let h=0;h<p.length;h+=1)r(p[h],o+1,n.id,[...s,n.id],h,p.length,f)}return r(e,0),i}function _(e,t,i,r,n={}){return{key:e,label:t,type:i,value:r,...n}}function Dn(e,t,i,r){if(!e)return null;let n=Ue(e.transformByPlatform,t),o=Qi(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",En(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==="grid"&&a.push(_("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??"")),ci.includes(e.kind)||a.push(_("incomplete","\u5B8C\u6574\u5EA6","note","\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:bt[e.kind]||e.kind,incomplete:!ci.includes(e.kind),fields:a}}function Gn(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&&di(o.renderMatrix),s=a&&Qe(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 vs from"protobufjs";var Ss=String.raw`
2
+ import{spawn as xu}from"node:child_process";import{createServer as Au}from"node:http";import{readFileSync as _u,realpathSync as Ua}from"node:fs";import{extname as Pu,resolve as Xa}from"node:path";import{fileURLToPath as Ka}from"node:url";import{createHash as Ru,timingSafeEqual as Tu}from"node:crypto";import{statSync as vu}from"node:fs";var Sn={name:"beyond-simulator-web",version:"0.3.4",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 le=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"}}),di="pc-16-9",me=2,yt=Object.freeze({KEYBOARD:"pc-16-9",TOUCHSCREEN:"mobile-16-9",CONTROLLER_CONSOLE:"pc-16-9",CONTROLLER_MOBILE:"mobile-16-9"}),vt=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"}),hi=Object.freeze(["server-container","container","textbox","cursor","reference","grid","image","button","textwindow","keyhint","animation","fullscreen"]),wn=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}),bt=Object.freeze({100001:"rect",100002:"circle",100003:"triangle",100004:"fourstar",100005:"fivestar",100006:"ring"}),Cn=50888,zt=Object.freeze({font:4294967295,bg:16777215,outline:858993459,image:4294967295});import{Worker as uu}from"node:worker_threads";import{existsSync as fu,mkdirSync as du,readFileSync as pn,writeFileSync as hu}from"node:fs";import{basename as pu,dirname as mu}from"node:path";import{existsSync as ai,readFileSync as fc}from"node:fs";import{randomUUID as dc}from"node:crypto";import{isAbsolute as In,win32 as kn}from"node:path";function pi(e,t=!1){let i=String(e??"").trim().replaceAll("\\","/");if(t&&(!i||i==="."))return"";if(!i||In(i)||kn.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 Vt(e){if(e==null)return null;if(e.version!==1)throw new Error("unsupported scriptSync version");let t=String(e.clientImportRoot||"").trim();if(!In(t)&&!kn.isAbsolute(t))throw new Error("\u5B9E\u673A\u5BFC\u5165\u6839\u76EE\u5F55\u5FC5\u987B\u662F\u7EDD\u5BF9\u8DEF\u5F84");return{version:1,workspaceDir:pi(e.workspaceDir,!0),clientImportRoot:t,clientSubdir:pi(e.clientSubdir,!0)}}import{basename as Rt,dirname as hc,isAbsolute as pc,join as pa,resolve as ma}from"node:path";function St(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)=>St(r,`${t}[${n}]`,i));else for(let[r,n]of Object.entries(e))St(n,`${t}.${r}`,i);i.delete(e)}}function G(e){return St(e),JSON.parse(JSON.stringify(e))}function En(e,t="$"){St(e,t)}function xn(e){return K[e]||K[di]}function Yt(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 gs(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 ys(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 mi({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 Me(e){let t=e||mi();return{scale:gs(t.scale),rotation:ys(t.rotation),anchorMin:Yt(t.anchorMin??t.anchor_min,.5,.5),anchorMax:Yt(t.anchorMax??t.anchor_max,.5,.5),offset:Yt(t.offset,0,0),size:Yt(t.size,0,0),pivot:Yt(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},f=t.pivot||{x:t.pivotX,y:t.pivotY},p=ge(a?.x,.5)*i,d=ge(a?.y,.5)*r,m=ge(s?.x,.5)*i,y=ge(s?.y,.5)*r,v=ge(l?.x),x=ge(l?.y),I=ge(f?.x,.5),A=ge(f?.y,.5),O=m-p+v,F=y-d+x,U=n+p+ge(c?.x)-v*I,te=o+d+ge(c?.y)-x*A;return{left:U,bottom:te,width:O,height:F,right:U+O,top:te+F,centerX:U+O/2,centerY:te+F/2}}function wt(){return{a:1,b:0,c:0,d:1,tx:0,ty:0}}function vs(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 Qe(e,t,i){return{x:e.a*t+e.c*i+e.tx,y:e.b*t+e.d*i+e.ty}}function gi(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 er(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),f=e.left+e.width*ge(n?.x,.5),p=e.bottom+e.height*ge(n?.y,.5),d=a*c,m=s*c,y=-s*l,v=a*l;return{a:d,b:m,c:y,d:v,tx:f-d*f-y*p,ty:p-m*f-v*p}}function Bt(e,t,i){return vs(e||wt(),er(t,i))}function An(e,t){let i=Qe(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"?xn(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 tr(e){return{posX:e.centerX,posY:e.centerY,width:e.width,height:e.height}}function et(e,t,i){let r=Me(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,f=Number(i.width),p=Number(i.height),d=Number(i.posX),m=Number(i.posY),y=d-f/2,v=m-p/2;return r.size={x:f-(c-a),y:p-(l-s)},r.offset={x:y-e.left-a+r.size.x*r.pivot.x,y:v-e.bottom-s+r.size.y*r.pivot.y},r}function _n(e,t){let i=Me(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 Pn(e){let t=Me(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 tt(e){return xn(e).platform}function Rn(e){let t={};for(let i of le)t[i]=e(i);return t}var bs={scale:["x","y","z"],rotation:["x","y","z"],anchorMin:["x","y"],anchorMax:["x","y"],offset:["x","y"],size:["x","y"],pivot:["x","y"]};function Tn(e,t){for(let[i,r]of Object.entries(bs))for(let n of r)if(!Number.isFinite(e?.[i]?.[n]))throw new Error(`${t}.${i}.${n} must be a finite number`)}function Be(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)Tn(e[i],`${t}.${i}`)}function it(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`);Be(e.transformByPlatform,`${e.name||e.id||"\u63A7\u4EF6"}.transformByPlatform`)}function rt(e,t){if(!le.includes(t))throw new Error(`unknown platform ${t}`);return Tn(e?.[t],`transformByPlatform.${t}`),Me(e[t])}var Ss=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"}]),ws=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 Mn(e){return[...Ss,...ws[e]||[]]}function Nn(e,t){return Mn(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 Fn(e,t={}){let i={};for(let r of Mn(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 rr(e,t){if(e){t(e);for(let i of e.children||[])rr(i,t)}}function Ct(e,t=new Set,{skipServerContainer:i=!1}={}){return rr(e,r=>{i&&r.kind==="server-container"||ke(r.guid)&&t.add(Number(r.guid))}),t}function Le(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 On(e,t=new Set,{skipServerContainer:i=!1}={}){let r=[];rr(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=Le(t);n.guid=o,t.add(o)}return t}var nr=1;function or(e="n"){let t=`${e}${nr}`;return nr+=1,t}function yi(e=1){nr=e}function ar(e,{isRootContainer:t=!1}={}){if(e==="server-container"||e==="fullscreen"||e==="container"&&t)return mi({layout:"stretch"});let i=wn[e]||[80,80];return mi({layout:"center",size:i})}function Cs(e,t){return Rn(()=>ar(e,t))}function Is(e){Be(e);let t={};for(let i of le)t[i]=rt(e,i);return t}function W(e,t={}){if(!vt[e])throw new Error(`unknown kind: ${e}`);Object.hasOwn(t,"transformByCanvas")&&it(t);let i=t.isRootContainer===!0,r=t.id||or(e==="server-container"?"sc":"n"),n=Object.hasOwn(t,"transformByPlatform")?Is(t.transformByPlatform):Cs(e,{isRootContainer:i}),o={id:r,kind:e,name:t.name||vt[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:Fn(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??zt.font,o.bgColor=t.bgColor??zt.bg,o.enableOutline=t.enableOutline!==!1,o.outlineColor=t.outlineColor??zt.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??zt.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??Cn,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 nt(){yi(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}),f=W("animation",{id:"n10",name:"\u754C\u9762\u52A8\u6548"}),p=W("fullscreen",{id:"n11",name:"\u5168\u5C4F\u52A8\u6548"}),d=(m,y,v)=>{for(let x of Object.values(m.transformByPlatform))x.offset={x:y,y:v}};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(f,300,-100),t.children.push(i,r,n,o,a,s,c,l,f,p),e.children.push(t),yi(12),On(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 It(){yi(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,f)=>{for(let p of Object.values(c.transformByPlatform))p.offset={x:l,y:f}};return((c,l,f)=>{for(let p of Object.values(c.transformByPlatform))p.size={x:l,y:f}})(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),yi(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 sr(e,t="n"){let i=or(t);for(;ue(e,i);)i=or(t);return i}function Ue(e,t){let i=null;return J(e,(r,n)=>{r.id===t&&(i=n)}),i}function lr(e){let t=e.root||e;return t.kind==="container"?t:(t.children||[]).find(i=>i.kind==="container")||(t.children||[])[0]||t}function Lt(e){if(e.meta?.assetType!=="client-control-template")return lr(e);let t=ue(e.root,e.selectedId);if(!t||t.kind==="server-container")return e.root.children?.[0]||e.root;let i=Ue(e.root,t.id);for(;i&&i.kind!=="server-container";)t=i,i=Ue(e.root,t.id);return t}function cr(e){it(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"&&ks(e.transformByPlatform);let i=W(e.kind,t);return i.children=(e.children||[]).map(r=>cr(r)),i}function ks(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 Dn(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 $n(e,t){if(e.id===t)throw new Error("cannot remove root");let i=Ue(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 Gn=1e-4;function Es(e,t){return Math.abs(e.anchorMax[t]-e.anchorMin[t])>Gn&&Math.abs(e.size[t])<=Gn}function xs(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=et(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"])Es(e,s)&&(a.offset[s]=e.offset[s],a.size[s]=e.size[s]);return a}function zn({transformByPlatform:e,source:t,canvasId:i,syncAllDevices:r,sourceParentBox:n=ye(i),targetParentBoxByPlatform:o={}}){Be(e);let a=tt(i),s={};for(let c of le)c===a?s[c]=Me(t):r!==!1?s[c]=xs(t,n,o[c]||ye(yt[c])):s[c]=rt(e,c);return Be(s),s}function He(e,t){return rt(e,tt(t))}function Vn(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 Xe(e,t,i=tt(t)){let r=ye(t),n={};function o(a,s,c){let l=rt(a.transformByPlatform,i),f=De(s,l),p=a.kind==="server-container"?c:Bt(c,f,l),d=An(f,p);n[a.id]={...f,...tr(f),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:p,primitive:a.kind==="image"?bt[a.imageId]||"missing":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 m=a.kind==="server-container"?s:f;for(let y of a.children||[])o(y,m,p)}return o(e,r,wt()),{canvas:r,boxes:n}}function ur(e,t){let i=[];function r(n,o,a=null,s=[],c=0,l=1,f=e.id){i.push({id:n.id,guid:t?.get(n.id)??(n.guid||0),kind:n.kind,name:n.name,label:vt[n.kind]||n.kind,depth:o,parentId:a,ancestorIds:s,siblingIndex:c,siblingCount:l,templateId:f,childCount:(n.children||[]).length,incomplete:!hi.includes(n.kind)});let p=n.children||[];for(let d=0;d<p.length;d+=1)r(p[d],o+1,n.id,[...s,n.id],d,p.length,f)}return r(e,0),i}function R(e,t,i,r,n={}){return{key:e,label:t,type:i,value:r,...n}}function Yn(e,t,i,r){if(!e)return null;let n=He(e.transformByPlatform,t),o=tr(i),a=[R("name","\u540D\u79F0","string",e.name),R("active","\u521D\u59CB\u6FC0\u6D3B","bool",e.active!==!1),R("visible","\u521D\u59CB\u53EF\u89C1\u6027","bool",e.visible!==!1),R("canControllerFocus","\u53EF\u88AB\u624B\u67C4\u6447\u6746\u5BFC\u822A\u9009\u4E2D","bool",e.canControllerFocus===!0),R("posX","\u4F4D\u7F6E X","number",o.posX,{computed:!0}),R("posY","\u4F4D\u7F6E Y","number",o.posY,{computed:!0}),R("width","\u5927\u5C0F W","number",o.width,{computed:!0}),R("height","\u5927\u5C0F H","number",o.height,{computed:!0}),R("rotationZ","\u65CB\u8F6C Z","number",n.rotation.z),R("syncAllDevices","\u540C\u6B65\u4FE1\u606F\u81F3\u6240\u6709\u8BBE\u5907","bool",e.syncAllDevices!==!1),R("anchorType","\u951A\u70B9\u7C7B\u578B","enum",Pn(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"}]}),R("anchorMinX","\u951A\u70B9 Min X","number",n.anchorMin.x),R("anchorMinY","\u951A\u70B9 Min Y","number",n.anchorMin.y),R("anchorMaxX","\u951A\u70B9 Max X","number",n.anchorMax.x),R("anchorMaxY","\u951A\u70B9 Max Y","number",n.anchorMax.y),R("pivotX","\u4E2D\u5FC3 X","number",n.pivot.x),R("pivotY","\u4E2D\u5FC3 Y","number",n.pivot.y)];if(e.kind==="container"&&a.push(R("isolateNavigation","\u9694\u79BB\u624B\u67C4\u5BFC\u822A","bool",e.isolateNavigation===!0),R("disableKeyEventPassthrough","\u5C4F\u853D\u6309\u952E\u4E8B\u4EF6\u7A7F\u900F","bool",e.disableKeyEventPassthrough===!0),R("disableCursorEventPassthrough","\u5C4F\u853D\u533A\u57DF\u5185\u70B9\u51FB\u4E8B\u4EF6\u7A7F\u900F","bool",e.disableCursorEventPassthrough===!0),R("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(R("fontSize","\u5B57\u53F7","number",e.fontSize),R("adaptiveFontSize","\u5B57\u53F7\u81EA\u9002\u5E94","bool",e.adaptiveFontSize===!0),R("minimumFontSize","\u6700\u5C0F\u5B57\u53F7","number",e.minimumFontSize),R("fontColor","\u6587\u672C\u8272","color",e.fontColor),R("bgColor","\u80CC\u666F\u8272","color",e.bgColor),R("enableOutline","\u542F\u7528\u63CF\u8FB9","bool",e.enableOutline!==!1),R("outlineColor","\u63CF\u8FB9\u8272","color",e.outlineColor),R("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"}]}),R("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"}]}),R("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(R("imageSource","\u56FE\u7247\u6E90","enum",e.imageSource,{readonly:!0,evidence:"W",options:[{value:"StaticReference",label:"\u9759\u6001\u5F15\u7528"}]}),R("imageId","imageId","number",e.imageId??0),R("imageColor","\u586B\u5145\u8272","color",e.imageColor),R("enableMask","\u5F00\u542F\u906E\u7F69","bool",e.enableMask===!0),R("enableSoftEdge","\u8FB9\u7F18\u7FBD\u5316","bool",e.enableSoftEdge===!0,{gia:"W"}),R("softEdgeMode","\u7FBD\u5316\u6A21\u5F0F","enum",e.softEdgeMode,{options:[{value:"Percentage",label:"\u767E\u5206\u6BD4"},{value:"Pixel",label:"\u50CF\u7D20"}]}),R("softEdgeWidthX","\u7FBD\u5316\u5BBD\u5EA6 X","number",e.softEdgeWidthX),R("softEdgeWidthY","\u7FBD\u5316\u5BBD\u5EA6 Y","number",e.softEdgeWidthY),R("horizontalSoftRange","\u6C34\u5E73\u7FBD\u5316\u8303\u56F4","number",e.horizontalSoftRange),R("verticalSoftRange","\u5782\u76F4\u7FBD\u5316\u8303\u56F4","number",e.verticalSoftRange),R("enableFill","\u6309\u8FDB\u5EA6\u586B\u5145","bool",e.enableFill===!0,{gia:"W"}),R("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"}]}),R("fillHorizontalType","\u65B9\u5411","enum",e.fillHorizontalType,{options:[{value:"Left",label:"\u4ECE\u5DE6\u81F3\u53F3"},{value:"Right",label:"\u4ECE\u53F3\u81F3\u5DE6"}]}),R("fillVerticalType","\u65B9\u5411","enum",e.fillVerticalType,{options:[{value:"Bottom",label:"\u4ECE\u4E0B\u81F3\u4E0A"},{value:"Top",label:"\u4ECE\u4E0A\u81F3\u4E0B"}]}),R("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"}]}),R("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"}]}),R("fillAmount","\u8FDB\u5EA6","percent",e.fillAmount),R("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(R("raycastTarget","\u53EF\u88AB\u5149\u6807\u5C04\u7EBF\u68C0\u6D4B","bool",e.raycastTarget!==!1),R("interactable","\u6309\u94AE\u662F\u5426\u53EF\u7528","bool",e.interactable!==!1),R("unavailableChildId","\u4E0D\u53EF\u7528\u72B6\u6001\u8282\u70B9","node",e.unavailableChildId,{options:s,gia:"W"}),R("hoverChildId","\u60AC\u505C\u72B6\u6001\u8282\u70B9","node",e.hoverChildId,{options:s,gia:"W"}),R("pressedChildId","\u6309\u4E0B\u72B6\u6001\u8282\u70B9","node",e.pressedChildId,{options:s,gia:"W"}),R("selectedChildId","\u9009\u4E2D\u72B6\u6001\u8282\u70B9","node",e.selectedChildId,{options:s,gia:"W"}),R("clickAudioId","\u70B9\u51FB\u97F3\u6548","number",e.clickAudioId))}return e.kind==="reference"&&a.push(R("referencedPrefabId","\u5F15\u7528\u63A7\u4EF6\u6A21\u677F\u7D22\u5F15","string",e.referencedPrefabId??"")),e.kind==="grid"&&a.push(R("cellSizeX","\u5217\u8868\u9879\u5927\u5C0F W","number",e.cellSizeX,{evidence:"W"}),R("cellSizeY","\u5217\u8868\u9879\u5927\u5C0F H","number",e.cellSizeY,{evidence:"W"}),R("spacingX","\u5217\u8868\u9879\u95F4\u9694 X","number",e.spacingX,{evidence:"W"}),R("spacingY","\u5217\u8868\u9879\u95F4\u9694 Y","number",e.spacingY,{evidence:"W"}),R("padding1X","\u8FB9\u8DDD\u5411\u91CF 1 X","number",e.padding1X,{evidence:"W"}),R("padding1Y","\u8FB9\u8DDD\u5411\u91CF 1 Y","number",e.padding1Y,{evidence:"W"}),R("padding2X","\u8FB9\u8DDD\u5411\u91CF 2 X","number",e.padding2X,{evidence:"W"}),R("padding2Y","\u8FB9\u8DDD\u5411\u91CF 2 Y","number",e.padding2Y,{evidence:"W"}),R("previewCount","\u9884\u89C8\u6570\u91CF","number",e.previewCount)),e.kind==="keyhint"&&a.push(R("keyboardKeyCode","\u952E\u9F20\u6309\u952E","number",e.keyboardKeyCode??e.giaRaw?.keyHintField502??1,{gia:"W"}),R("controllerKeyCode","\u624B\u67C4\u6309\u952E","number",e.controllerKeyCode??e.giaRaw?.keyHintField501??1)),(e.kind==="animation"||e.kind==="fullscreen")&&a.push(R("animationId",e.kind==="animation"?"\u52A8\u6548\u7D22\u5F15":"\u5168\u5C4F\u52A8\u6548\u7D22\u5F15","string",e.animationId??"")),hi.includes(e.kind)||a.push(R("incomplete","\u5B8C\u6574\u5EA6","note","\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:vt[e.kind]||e.kind,incomplete:!hi.includes(e.kind),fields:a}}function Bn(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&&gi(o.renderMatrix),s=a&&Qe(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 As from"protobufjs";var _s=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
@@ -100,19 +100,19 @@ message ImageConfig {
100
100
  message SliceVector { float field501 = 501; float field502 = 502; }
101
101
  }
102
102
  message FooterSlot { int32 field505 = 505; }
103
- `,{root:ws}=vs.parse(Ss,{keepCase:!1}),Ee=ws.lookupType("Root"),Ke=20,cr=4,Vn=806,Ln=1657,Bt={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},Bn={"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},Yn={KEYBOARD:0,TOUCHSCREEN:1,CONTROLLER_CONSOLE:2,CONTROLLER_MOBILE:3},Cs="server-control-template",mi="client-control-template";function pi(e,t){let i=Number(e);return Number.isFinite(i)?i:t}var Is=Object.fromEntries(Object.entries(Yn).map(([e,t])=>[t,e])),Un=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"]]}),Hn=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}),ks=Object.freeze([["2/15","name",null],["4/23","field14","field14"],["1/12","transform","transform"],["62/82","empty72","rootChildRef"]]);function ur(e){return{class:1,type:8,id:e}}function Yt(e,t,i,r){return{...r,field501:t,field502:i,field503:1,nodeRef:ur(e)}}function Es(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 Ut(e,t=new Set){let i=new Map,r=[];for(let n of Es(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=Be(t);t.add(o),n.guid=o,i.set(n.id,o)}return i}function xs(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 As(e,t){let r={multiPlatform:{platforms:se.map(n=>({platformType:Yn[n],transform:xs(e.transformByPlatform[n])})),field502:Bt[e.kind]||25,...e.syncAllDevices===!1?{}:{field504:1}},type:2};return{transform:{multiPlatform:{},type:2},field501:1,field502:12,details:Yt(t,4,12,{transform:r})}}function Ps(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:Yt(t,5,i?23:86,{field14:n})},As(e,t)]}function _s(e,t,i,r){let n=(l,f,p,h,m)=>({[p]:"",field501:l,field502:f,details:Yt(t,l+2,f,{[h]:m})}),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,f=Number.isFinite(o.textAlign)?Math.trunc(o.textAlign):l,p={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}:{},...f?{align:f}:{},verticalAlign:o.textVerticalAlign??{Top:0,Middle:1,Bottom:2}[e.verticalAlignment]??0};return e.kind==="textwindow"?(p.field511=o.textField511??1,p.viewFlags={field502:o.textViewField502??1,field503:o.textViewField503??1},[s,{empty81:"",field501:71,field502:94,details:Yt(t,66,94,{textConfig:p})},c]):[s,n(64,84,"empty74","textConfig",p),c]}if(e.kind==="image"){let l={Horizontal:1,Vertical:2,Radial90:3,Radial180:4,Radial360:5}[e.fillType],f=Number.isFinite(o.imageFillType)?Math.trunc(o.imageFillType):l||1;e.enableFill&&!f&&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 p={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:pi(e.softEdgeWidthX,8),field502:pi(e.softEdgeWidthY,8)},field512:pi(e.horizontalSoftRange,85),field513:pi(e.verticalSoftRange,85),fillType:f,...e.enableMask?{enableMask:1}:{},...e.enableSoftEdge?{enableSoftEdge:1}:{},...e.softEdgeMode==="Pixel"?{softEdgePixel:1}:{},...e.enableFill&&f?{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",p),c]}if(e.kind==="button"){let l=(y,v)=>{let x=e[y];return x?(e.children||[]).some(I=>I.id===x)?i.get(x)||0:(r.push(`${e.name}: ${v}\u72B6\u6001\u8282\u70B9\u4E0D\u662F\u6309\u94AE\u7684\u76F4\u63A5\u5B50\u63A7\u4EF6\uFF0CGIA \u672A\u5199\u5165\u8BE5\u72B6\u6001\u3002`),0):0},f=l("unavailableChildId","\u4E0D\u53EF\u7528"),p=l("hoverChildId","\u60AC\u505C"),h=l("pressedChildId","\u6309\u4E0B"),m=l("selectedChildId","\u9009\u4E2D");return[s,n(70,93,"empty80","buttonPreset",{clickAudioId:Math.trunc(e.clickAudioId),...f?{disabledChild:f}:{},...p?{hoverChild:p}:{},...h?{pressedChild:h}:{},...m?{selectedChild:m}:{},...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"?[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 Rs(e,t){return t?1:Number.isSafeInteger(Number(e.giaInfoIndex))&&Number(e.giaInfoIndex)>0?Number(e.giaInfoIndex):Bn[e.kind]||2}function Ts(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 fr(e,t){let i=String(e.meta?.giaFilePath||"").trim();if(/^\d+-\d+-\d+-\\.+\.gia$/iu.test(i))return i;let r=(l,f)=>Number.isSafeInteger(Number(l))&&Number(l)>0?Number(l):f,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 gi(e,t,i,r,n,o=!1,a=!1,s=a,c=!1){let l=i.get(e.id),p=(c?[...e.children||[]].reverse():e.children||[]).map(y=>i.get(y.id)),h=o?r:p,m=Ps(e,l,o);if(o){let y=e.children?.[0];y&&m.push({empty72:"",field501:62,field502:82,details:Yt(l,64,82,{rootChildRef:{guid:i.get(y.id)}})})}else m.push(..._s(e,l,i,n));return{id:ur(l),relatedIds:h.map(y=>ur(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:Rs(e,o)},field501:2,field502:6}]:[],...o||a?[{related:{value:Ts(e,n,o?"\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F")},field501:4,field502:4}]:[]],children:o?[]:p,parent:t&&t.kind!=="server-container"?i.get(t.id):0,data:m}}}}function Kn(e){let t=[];return q(e.root,(i,r)=>{i.kind!=="server-container"&&t.push({node:i,parent:r})}),t}function Ms(e,t){let i=new Map;for(let r of e||[]){if(!r.controlId||!(t===mi?r.controlAsset===mi:r.controlAsset!==mi))continue;let o=i.get(r.controlId)||[];o.push(r.guid),i.set(r.controlId,o)}return i}function Xn(e,t,i,r){let n=Ms(t,i),o=new Map;q(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 dr(e){let t=Number(e.meta?.giaModeFlag);return Number.isSafeInteger(t)&&t>=0?{modeFlag:t}:{}}function Wn(e,t,i,r,n=[]){let o=Kn(e),a=o.filter(({parent:f})=>f?.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:f})=>f.id)),c=o.filter(({node:f})=>!s.has(f.id)),l=o.map(({node:f})=>t.get(f.id));return Xn(e,n,mi,()=>({graph:a.map(({node:f,parent:p})=>gi(f,p,t,l,i,!1,!0)),accessories:c.map(({node:f,parent:p})=>gi(f,p,t,l,i,!1,!1,!0)),filePath:r||fr(e,!0),gameVersion:e.meta?.gameVersion||"7.0.50",...dr(e)}))}function jn(e,t,i,r,n){let o=Kn(e),a=[o[0],...o.slice(1).reverse()],s=a.map(({node:c})=>t.get(c.id));return Xn(e,i.scripts,Cs,()=>({graph:[gi(e.root,null,t,s,r,!0,!1,!1,!0),...i.units||[]],accessories:a.map(({node:c,parent:l})=>gi(c,l,t,s,r,!1,!1,!1,!0)),filePath:n||fr(e,!1),gameVersion:e.meta?.gameVersion||"7.0.50",...dr(e)}))}function qn(e,t){let i=to(e),r=t(i);if(!r.valid)throw new Error(`GIA compatibility validation failed:
103
+ `,{root:Ps}=As.parse(_s,{keepCase:!1}),Ee=Ps.lookupType("Root"),Ke=20,fr=4,Un=806,Hn=1657,Ut={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},Xn={"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},Kn={KEYBOARD:0,TOUCHSCREEN:1,CONTROLLER_CONSOLE:2,CONTROLLER_MOBILE:3},Rs="server-control-template",bi="client-control-template";function vi(e,t){let i=Number(e);return Number.isFinite(i)?i:t}var Ts=Object.fromEntries(Object.entries(Kn).map(([e,t])=>[t,e])),Wn=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"]]}),jn=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}),Ms=Object.freeze([["2/15","name",null],["4/23","field14","field14"],["1/12","transform","transform"],["62/82","empty72","rootChildRef"]]);function dr(e){return{class:1,type:8,id:e}}function Ht(e,t,i,r){return{...r,field501:t,field502:i,field503:1,nodeRef:dr(e)}}function Ns(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 Xt(e,t=new Set){let i=new Map,r=[];for(let n of Ns(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=Le(t);t.add(o),n.guid=o,i.set(n.id,o)}return i}function Fs(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 Os(e,t){let r={multiPlatform:{platforms:le.map(n=>({platformType:Kn[n],transform:Fs(e.transformByPlatform[n])})),field502:Ut[e.kind]||25,...e.syncAllDevices===!1?{}:{field504:1}},type:2};return{transform:{multiPlatform:{},type:2},field501:1,field502:12,details:Ht(t,4,12,{transform:r})}}function Ds(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:Ht(t,5,i?23:86,{field14:n})},Os(e,t)]}function $s(e,t,i,r){let n=(l,f,p,d,m)=>({[p]:"",field501:l,field502:f,details:Ht(t,l+2,f,{[d]:m})}),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,f=Number.isFinite(o.textAlign)?Math.trunc(o.textAlign):l,p={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}:{},...f?{align:f}:{},verticalAlign:o.textVerticalAlign??{Top:0,Middle:1,Bottom:2}[e.verticalAlignment]??0};return e.kind==="textwindow"?(p.field511=o.textField511??1,p.viewFlags={field502:o.textViewField502??1,field503:o.textViewField503??1},[s,{empty81:"",field501:71,field502:94,details:Ht(t,66,94,{textConfig:p})},c]):[s,n(64,84,"empty74","textConfig",p),c]}if(e.kind==="image"){let l={Horizontal:1,Vertical:2,Radial90:3,Radial180:4,Radial360:5}[e.fillType],f=Number.isFinite(o.imageFillType)?Math.trunc(o.imageFillType):l||1;e.enableFill&&!f&&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 p={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:vi(e.softEdgeWidthX,8),field502:vi(e.softEdgeWidthY,8)},field512:vi(e.horizontalSoftRange,85),field513:vi(e.verticalSoftRange,85),fillType:f,...e.enableMask?{enableMask:1}:{},...e.enableSoftEdge?{enableSoftEdge:1}:{},...e.softEdgeMode==="Pixel"?{softEdgePixel:1}:{},...e.enableFill&&f?{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",p),c]}if(e.kind==="button"){let l=(y,v)=>{let x=e[y];return x?(e.children||[]).some(I=>I.id===x)?i.get(x)||0:(r.push(`${e.name}: ${v}\u72B6\u6001\u8282\u70B9\u4E0D\u662F\u6309\u94AE\u7684\u76F4\u63A5\u5B50\u63A7\u4EF6\uFF0CGIA \u672A\u5199\u5165\u8BE5\u72B6\u6001\u3002`),0):0},f=l("unavailableChildId","\u4E0D\u53EF\u7528"),p=l("hoverChildId","\u60AC\u505C"),d=l("pressedChildId","\u6309\u4E0B"),m=l("selectedChildId","\u9009\u4E2D");return[s,n(70,93,"empty80","buttonPreset",{clickAudioId:Math.trunc(e.clickAudioId),...f?{disabledChild:f}:{},...p?{hoverChild:p}:{},...d?{pressedChild:d}:{},...m?{selectedChild:m}:{},...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"?[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 Gs(e,t){return t?1:Number.isSafeInteger(Number(e.giaInfoIndex))&&Number(e.giaInfoIndex)>0?Number(e.giaInfoIndex):Xn[e.kind]||2}function zs(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 hr(e,t){let i=String(e.meta?.giaFilePath||"").trim();if(/^\d+-\d+-\d+-\\.+\.gia$/iu.test(i))return i;let r=(l,f)=>Number.isSafeInteger(Number(l))&&Number(l)>0?Number(l):f,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 Si(e,t,i,r,n,o=!1,a=!1,s=a,c=!1){let l=i.get(e.id),p=(c?[...e.children||[]].reverse():e.children||[]).map(y=>i.get(y.id)),d=o?r:p,m=Ds(e,l,o);if(o){let y=e.children?.[0];y&&m.push({empty72:"",field501:62,field502:82,details:Ht(l,64,82,{rootChildRef:{guid:i.get(y.id)}})})}else m.push(...$s(e,l,i,n));return{id:dr(l),relatedIds:d.map(y=>dr(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:Gs(e,o)},field501:2,field502:6}]:[],...o||a?[{related:{value:zs(e,n,o?"\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F")},field501:4,field502:4}]:[]],children:o?[]:p,parent:t&&t.kind!=="server-container"?i.get(t.id):0,data:m}}}}function qn(e){let t=[];return J(e.root,(i,r)=>{i.kind!=="server-container"&&t.push({node:i,parent:r})}),t}function Vs(e,t){let i=new Map;for(let r of e||[]){if(!r.controlId||!(t===bi?r.controlAsset===bi:r.controlAsset!==bi))continue;let o=i.get(r.controlId)||[];o.push(r.guid),i.set(r.controlId,o)}return i}function Jn(e,t,i,r){let n=Vs(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 pr(e){let t=Number(e.meta?.giaModeFlag);return Number.isSafeInteger(t)&&t>=0?{modeFlag:t}:{}}function Zn(e,t,i,r,n=[]){let o=qn(e),a=o.filter(({parent:f})=>f?.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:f})=>f.id)),c=o.filter(({node:f})=>!s.has(f.id)),l=o.map(({node:f})=>t.get(f.id));return Jn(e,n,bi,()=>({graph:a.map(({node:f,parent:p})=>Si(f,p,t,l,i,!1,!0)),accessories:c.map(({node:f,parent:p})=>Si(f,p,t,l,i,!1,!1,!0)),filePath:r||hr(e,!0),gameVersion:e.meta?.gameVersion||"7.0.50",...pr(e)}))}function Qn(e,t,i,r,n){let o=qn(e),a=[o[0],...o.slice(1).reverse()],s=a.map(({node:c})=>t.get(c.id));return Jn(e,i.scripts,Rs,()=>({graph:[Si(e.root,null,t,s,r,!0,!1,!1,!0),...i.units||[]],accessories:a.map(({node:c,parent:l})=>Si(c,l,t,s,r,!1,!1,!1,!0)),filePath:n||hr(e,!1),gameVersion:e.meta?.gameVersion||"7.0.50",...pr(e)}))}function eo(e,t){let i=oo(e),r=t(i);if(!r.valid)throw new Error(`GIA compatibility validation failed:
104
104
  ${r.errors.join(`
105
- `)}`);return i}function Jn(e,t={}){q(e.root,it);let i=Ut(G(e)),r=[],n=e.meta?.assetType==="client-control-template",o;if(n)o=Wn(e,i,r,void 0,t.scripts||[]);else{let s=hr(t.scripts||[],new Set(i.values()));r.push(...s.warnings),o=jn(e,i,s,r)}return{buffer:qn(o,n?so:mr),warnings:[...new Set(r)]}}function Zn(e,t,i={}){q(e.root,it),t&&q(t.root,it);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"],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 o=new Set,a=G(e),s=t?G(t):null,c=Ut(a,o),l=hr(i.scripts||[],o);r.push(...l.warnings.filter(x=>x!==eo));let f=String(i.fileName||`${a.meta?.name||"\u6574\u5408\u5305"} \xB7 \u6574\u5408\u5305.gia`),p=fr({...a,meta:{...a.meta,giaFileName:f}},!1),h=jn(a,c,l,r,p),m={graph:[],accessories:[]};if(n.length&&s){let x=Ut({...s,meta:{...s.meta,assetType:"client-control-template"}},o);m=Wn(s,x,r,p,l.scripts)}let y={graph:[...h.graph,...m.graph],accessories:[...h.accessories,...m.accessories],filePath:p,gameVersion:e.meta?.gameVersion||t?.meta?.gameVersion||"7.0.50",...dr(e)};return{buffer:qn(y,mr),warnings:[...new Set(r)]}}var kt=69,Qn=30,eo="\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 Ns(e){return(String(e.path||"").replace(/\\/g,"/").split("/").pop()||"").replace(/\.lua$/iu,"")||`\u811A\u672C${e.id||""}`}function to(e){let t=Ee.verify(e);if(t)throw new Error(`GIA encode validation failed: ${t}`);let i=Ee.encode(Ee.create(e)).finish(),r=Buffer.alloc(Ke+i.length+cr);return r.writeUInt32BE(r.length-4,0),r.writeUInt32BE(1,4),r.writeUInt32BE(Vn,8),r.writeUInt32BE(3,12),r.writeUInt32BE(i.length,16),Buffer.from(i).copy(r,Ke),r.writeUInt32BE(Ln,Ke+i.length),r}function hr(e,t=new Set){let i=(e||[]).filter(a=>a.path||a.source).map(a=>({...a})),r=[];for(let a of i){let s=Number(a.guid);ke(s)&&!t.has(s)?(t.add(s),a.guid=s):r.push(a)}for(let a of r){let s=Be(t);t.add(s),a.guid=s}let n=[];return(e||[]).some(a=>a.controlId)&&n.push(eo),{units:i.map(a=>{let s=Ns(a),c=String(a.path||"").replace(/\\/g,"/"),l=/\.lua$/iu.test(c)?c:`${c||s}.lua`,f={id:a.guid,name:s,filePath:l};return String(a.source||"")&&(f.source=String(a.source)),{id:{class:Qn,id:a.guid},name:s,which:kt,script:{mapping:f}}}),warnings:n,scripts:i}}function io(e){let t=hr(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=to(i),n=Fs(r);if(!n.valid)throw new Error(`GIA compatibility validation failed:
105
+ `)}`);return i}function to(e,t={}){J(e.root,it);let i=Xt(G(e)),r=[],n=e.meta?.assetType==="client-control-template",o;if(n)o=Zn(e,i,r,void 0,t.scripts||[]);else{let s=mr(t.scripts||[],new Set(i.values()));r.push(...s.warnings),o=Qn(e,i,s,r)}return{buffer:eo(o,n?fo:yr),warnings:[...new Set(r)]}}function io(e,t,i={}){J(e.root,it),t&&J(t.root,it);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"],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 o=new Set,a=G(e),s=t?G(t):null,c=Xt(a,o),l=mr(i.scripts||[],o);r.push(...l.warnings.filter(x=>x!==no));let f=String(i.fileName||`${a.meta?.name||"\u6574\u5408\u5305"} \xB7 \u6574\u5408\u5305.gia`),p=hr({...a,meta:{...a.meta,giaFileName:f}},!1),d=Qn(a,c,l,r,p),m={graph:[],accessories:[]};if(n.length&&s){let x=Xt({...s,meta:{...s.meta,assetType:"client-control-template"}},o);m=Zn(s,x,r,p,l.scripts)}let y={graph:[...d.graph,...m.graph],accessories:[...d.accessories,...m.accessories],filePath:p,gameVersion:e.meta?.gameVersion||t?.meta?.gameVersion||"7.0.50",...pr(e)};return{buffer:eo(y,yr),warnings:[...new Set(r)]}}var kt=69,ro=30,no="\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 Ys(e){return(String(e.path||"").replace(/\\/g,"/").split("/").pop()||"").replace(/\.lua$/iu,"")||`\u811A\u672C${e.id||""}`}function oo(e){let t=Ee.verify(e);if(t)throw new Error(`GIA encode validation failed: ${t}`);let i=Ee.encode(Ee.create(e)).finish(),r=Buffer.alloc(Ke+i.length+fr);return r.writeUInt32BE(r.length-4,0),r.writeUInt32BE(1,4),r.writeUInt32BE(Un,8),r.writeUInt32BE(3,12),r.writeUInt32BE(i.length,16),Buffer.from(i).copy(r,Ke),r.writeUInt32BE(Hn,Ke+i.length),r}function mr(e,t=new Set){let i=(e||[]).filter(a=>a.path||a.source).map(a=>({...a})),r=[];for(let a of i){let s=Number(a.guid);ke(s)&&!t.has(s)?(t.add(s),a.guid=s):r.push(a)}for(let a of r){let s=Le(t);t.add(s),a.guid=s}let n=[];return(e||[]).some(a=>a.controlId)&&n.push(no),{units:i.map(a=>{let s=Ys(a),c=String(a.path||"").replace(/\\/g,"/"),l=/\.lua$/iu.test(c)?c:`${c||s}.lua`,f={id:a.guid,name:s,filePath:l};return String(a.source||"")&&(f.source=String(a.source)),{id:{class:ro,id:a.guid},name:s,which:kt,script:{mapping:f}}}),warnings:n,scripts:i}}function ao(e){let t=mr(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=oo(i),n=Bs(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 pr(e){return Ee.toObject(Ee.decode(bi(e)),{longs:Number,enums:Number,bytes:Buffer,defaults:!1,arrays:!0,objects:!0})}function ro(e){try{let i=pr(e).graph||[];return i.length>0&&i.every(r=>Number(r.which)===kt)}catch{return!1}}function no(e){let t=(e.graph||[]).filter(n=>Number(n.which)===kt),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 oo(e){let t=pr(e),i=no(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 Fs(e){let t=[],i;try{i=pr(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)!==kt&&t.push(`${a}: which \u5E94\u4E3A 69\uFF0C\u5B9E\u9645 ${n.which}`),Number(n.id?.class)!==Qn&&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 bi(e){let t=Buffer.isBuffer(e)?e:Buffer.from(e);if(t.length<Ke+cr)throw new Error("GIA \u6587\u4EF6\u8FC7\u77ED");if(t.readUInt32BE(4)!==1||t.readUInt32BE(8)!==Vn||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-cr)throw new Error("GIA payload \u957F\u5EA6\u4E0D\u4E00\u81F4");if(t.readUInt32BE(Ke+i)!==Ln)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 Os(e){let t=fe(e,"transform")?.multiPlatform,i={};for(let n of t?.platforms||[]){let o=Is[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 se)i[n]||(i[n]=structuredClone(r));return i}function yi(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 zn(e,{reverseSiblings:t=!1,idOffset:i=0}={}){if(!e.length)return{nodes:new Map,rootCandidates:[],warnings:[]};let r=new Map(e.map((l,f)=>[l.id?.id,`n${i+f+1}`])),n=new Map,o=new Map,a=[];for(let l of e){let f=yi(l),p=fe(l,"textConfig"),h=fe(l,"imageSlot"),m=fe(l,"image"),y=fe(l,"buttonPreset"),v=fe(l,"gridView"),x=fe(l,"genericSlot"),I=fe(l,"footerSlot"),A=fe(l,"cursorConfig"),O=fe(l,"keyHint"),F=fe(l,"containerNodeSlot"),U=fe(l,"templateRefSlot"),ee=fe(l,"effectSlot"),Z=fe(l,"fullscreenEffectSlot"),D=W(f,{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||f,visible:fe(l,"field14")?.field17?.initiallyHidden!==!0,active:fe(l,"field14")?.initiallyInactive!==!0,canControllerFocus:I?.field505===1,scriptMappingIds:(x?.field502||[]).map(b=>Number(b?.field1?.id)).filter(b=>Number.isSafeInteger(b)&&b>0),transformByPlatform:Os(l),syncAllDevices:fe(l,"transform")?.multiPlatform?.field504===1,giaRaw:{genericField501:x?.field501??0,footerField505:I?.field505??0,...f==="textbox"||f==="textwindow"?{textField501:p?.field501??20,textField503:p?.field503??12,textAlign:p?.align??0,...[void 0,0,1,2].includes(p?.verticalAlign)?{}:{textVerticalAlign:p.verticalAlign},...f==="textwindow"?{textField511:p?.field511??1,textViewField502:p?.viewFlags?.field502??1,textViewField503:p?.viewFlags?.field503??1}:{}}:{},...f==="cursor"?{cursorField501:A?.field501??0}:{},...f==="reference"?{templateRefSlot:U??""}:{},...f==="grid"?{gridField501:v?.field501??1,gridField507:v?.field507??1,gridField508:v?.field508??1,gridField509:v?.field509??1,gridField511:v?.field511??5,gridField512:v?.field512??1}:{},...f==="keyhint"?{keyHintField501:O?.field501??1,keyHintField502:O?.field502??1}:{},...f==="image"?{imageField502:m?.field502??1,imageField504:m?.field504??1,imageField505:m?.field505??1,imageField507:m?.field507??2,imageFillType:m?.fillType??1}:{},...f==="animation"?{effectSlot:ee??""}:{},...f==="fullscreen"?{fullscreenEffectSlot:Z??""}:{}},...f==="container"?{isolateNavigation:F?.isolateNavigation===!0,disableKeyEventPassthrough:F?.disableKeyEventPassthrough===!0,disableCursorEventPassthrough:F?.disableCursorEventPassthrough===!0,showCursor:F?.showCursor===!0}:{},...f==="cursor"?{raycastTarget:A?.field501===1}:{},...f==="textbox"||f==="textwindow"?{text:p?.text?.value??"",fontSize:p?.fontSize??20,minimumFontSize:p?.minimumFontSize??20,adaptiveFontSize:p?.adaptive===1,fontColor:p?.color??4294967295,bgColor:p?.color2??0,enableOutline:p?.outlineOff!==1,outlineColor:p?.color3??858993459,horizontalAlignment:p?.align===1?"Middle":p?.align===2?"Right":"Left",verticalAlignment:{0:"Top",1:"Middle",2:"Bottom"}[p?.verticalAlign??0]||"Top",...f==="textwindow"?{interactable:!0,showScrollBar:!0}:{}}:{},...f==="image"?{imageSource:"StaticReference",imageId:h?.assetId??0,imageColor:Number.isFinite(h?.field502)?h.field502>>>0:4294967295,enableMask:m?.enableMask===1,enableSoftEdge:m?.enableSoftEdge===1,enableFill:m?.enableFill===1,softEdgeMode:m?.softEdgePixel===1?"Pixel":"Percentage",softEdgeWidthX:m?.border?.field501??8,softEdgeWidthY:m?.border?.field502??8,horizontalSoftRange:m?.field512??85,verticalSoftRange:m?.field513??85,fillType:{1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[m?.fillType]||"Horizontal",fillAmount:Number.isFinite(m?.field508)?Math.max(0,Math.min(1,m.field508/100)):m?.enableFill===1?0:1,reverseMaskArea:m?.reverseMask===1}:{},...f==="button"?{interactable:y?.interactable===1,raycastTarget:y?.raycastTarget===1,clickAudioId:y?.clickAudioId??50888}:{},...f==="grid"?{cellSizeX:v?.cellSize?.field501??50,cellSizeY:v?.cellSize?.field502??50,spacingX:v?.gap?.field501??8,spacingY:v?.gap?.field502??8,padding1X:v?.padding1?.field501??20,padding1Y:v?.padding1?.field502??20,padding2X:v?.padding2?.field501??20,padding2Y:v?.padding2?.field502??20,previewCount:v?.field511??5}:{},...f==="reference"?{referencedPrefabId:U??""}:{},...f==="keyhint"?{keyboardKeyCode:O?.field502??null,controllerKeyCode:O?.field501??null}:{},...f==="animation"?{animationId:ee??""}:{},...f==="fullscreen"?{animationId:Z??""}:{}});n.set(l.id?.id,D),(f==="textbox"||f==="textwindow")&&![void 0,0,1,2].includes(p?.align)&&a.push(`${D.name}: \u6C34\u5E73\u5BF9\u9F50\u679A\u4E3E ${p.align} \u7684\u542B\u4E49\u672A\u77E5\uFF0C\u5DF2\u539F\u6837\u4FDD\u7559\u3002`),(f==="textbox"||f==="textwindow")&&![void 0,0,1,2].includes(p?.verticalAlign)&&a.push(`${D.name}: \u5782\u76F4\u5BF9\u9F50\u679A\u4E3E ${p.verticalAlign} \u7684\u542B\u4E49\u672A\u77E5\uFF0C\u5DF2\u539F\u6837\u4FDD\u7559\u3002`),f==="image"&&![void 0,0,1,2,3,4,5].includes(m?.fillType)&&a.push(`${D.name}: \u586B\u5145\u5F62\u72B6\u679A\u4E3E ${m.fillType} \u672A\u8BC6\u522B\uFF0C\u5DF2\u4FDD\u7559\u539F\u503C\u3002`),f==="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 f=n.get(l.id?.id),p=(l.ui?.content?.children||[]).map(h=>n.get(h)).filter(Boolean);if(p.length){f.children=t?p.slice().reverse():p;for(let h of p)c.add(h.id)}}for(let l of e){let f=n.get(l.id?.id),p=l.ui?.content?.parent||0,h=n.get(p);h?c.has(f.id)||(t?h.children.unshift(f):h.children.push(f)):s.push(f)}for(let[l,f]of o){let p=[...n.values()].find(h=>h.id===l);for(let[h,m]of Object.entries(f))p[h]=r.get(m)||null}return{nodes:n,rootCandidates:s,warnings:a}}function ao(e){let t=bi(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 f=["GIA \u5BFC\u5165\u4E3A\u5DF2\u9A8C\u8BC1 UI \u5B57\u6BB5\u7684\u8BED\u4E49\u5BFC\u5165\uFF1B\u672A\u77E5 protobuf \u5B57\u6BB5\u4E0D\u4F1A\u8FDB\u5165 Authoring JSON\u3002"],p=no(i);f.push(...p.warnings);let h=null,m=null;if(c.length){let y=zn(c,{reverseSiblings:!0,idOffset:0});f.push(...y.warnings);let v=y.rootCandidates.find(I=>I.kind==="container")||y.rootCandidates[0];if(!v)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6839\u63A7\u4EF6");let x=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||[]});x.children=[v],y.rootCandidates.length>1&&f.push(`\u68C0\u6D4B\u5230 ${y.rootCandidates.length} \u4E2A\u65E0\u7236\u8282\u70B9\u63A7\u4EF6\uFF0C\u4EC5\u5BFC\u5165\u4EE5\u201C${v.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:v.id,script:{controlId:v.id,path:"",source:""},root:x}}if(l.length){let y=zn(l,{reverseSiblings:!1,idOffset:1e3});if(f.push(...y.warnings),!y.rootCandidates.length)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6A21\u677F");let v=W("server-container",{id:"sc1",guid:0,name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"});v.children=y.rootCandidates,m={version:1,layoutSchemaVersion:pe,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:v},h||(h=m)}return{project:h,clientProject:m&&h!==m?m:void 0,scripts:p.scripts,warnings:f,metadata:{gameVersion:i.gameVersion||"",filePath:i.filePath||"",...Number.isSafeInteger(Number(i.modeFlag))?{modeFlag:Number(i.modeFlag)}:{},combined:!!(n&&o.length)}}}function so(e){let t=bi(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=(h,m)=>h!=null&&Object.prototype.hasOwnProperty.call(h,m),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(h=>h.which===70).map(h=>{let m=yi(h),y=h.ui?.content?.info||[],v=y.find(O=>O.field501===2&&O.field502===6)?.index?.value,x=Bn[m],I=y.find(O=>O.field501===4&&O.field502===4),A=I?.related?.value||[];return(!Number.isSafeInteger(v)||v<=0)&&o.push(`${h.name}: Info.index=${v??"<missing>"}\uFF0C\u5FC5\u987B\u662F\u6B63\u6574\u6570`),I||o.push(`${h.name}: \u9876\u5C42 UIControlTemplate \u7F3A\u5C11 Info.related \u8BB0\u5F55`),{id:h.id?.id||0,name:h.name||"",kind:m,actualIndex:v,expectedIndex:x,relatedPresent:!!I,relatedGuids:A}});l.length||o.push("Root.graph \u4E0D\u542B UIControlTemplate(70)");let f=0,p=0;for(let h of[...r,...n]){if(!h.ui?.content)continue;let m=h.id?.id||0,y=h.ui.content,v=yi(h),x=r.includes(h)&&h.which===70,I=`${h.name||"<unnamed>"}(${m||"<missing-guid>"})`;!Number.isSafeInteger(m)||m<=0||m>2147483647?o.push(`${I}: GraphUnit GUID \u975E\u6CD5`):s.has(m)?o.push(`${I}: GUID \u4E0E ${s.get(m).name||"<unnamed>"} \u91CD\u590D`):s.set(m,h),(h.id?.class!==1||h.id?.type!==8)&&o.push(`${I}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),y.guid!==m&&o.push(`${I}: content.guid=${y.guid??"<missing>"} \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`),x&&h.which!==70&&o.push(`${I}: \u6A21\u677F\u6839 which \u5FC5\u987B\u4E3A UIControlTemplate(70)`),!x&&h.which!==15&&o.push(`${I}: \u9644\u4EF6\u63A7\u4EF6 which \u5FC5\u987B\u4E3A UIControl(15)`);let A=y.info||[],O=A.find(w=>w.field501===1&&w.field502===5),F=A.find(w=>w.field501===2&&w.field502===6);O?.guid?.value!==m&&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 U=A.find(w=>w.field501===4&&w.field502===4);x&&!U&&o.push(`${I}: \u9876\u5C42\u6A21\u677F\u7F3A\u5C11 Info.related \u8BB0\u5F55`),!x&&U&&o.push(`${I}: \u9644\u4EF6\u63A7\u4EF6\u4E0D\u5E94\u5199 Info.related`);let ee=Un[v],Z=y.data||[],D=Z.map(w=>`${w.field501}/${w.field502}`),b=ee?.map(([w])=>w)||[];ee?JSON.stringify(D)!==JSON.stringify(b)&&o.push(`${I}: Data \u69FD\u4F4D\u987A\u5E8F ${D.join(",")}\uFF0C\u5E94\u4E3A ${b.join(",")}`):o.push(`${I}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${v}`);for(let w=0;w<Math.min(Z.length,ee?.length||0);w+=1){let M=Z[w],[z,Y,ae]=ee[w];if(a(M,Y)||o.push(`${I}: Data ${z} \u7F3A\u5C11 ${Y} \u5206\u652F`),!ae)continue;a(M.details,ae)||o.push(`${I}: Details ${z} \u7F3A\u5C11 ${ae} \u5206\u652F`);let K=Hn[z];(M.details?.field501!==K||M.details?.field502!==M.field502||M.details?.field503!==1)&&o.push(`${I}: Details ${z} \u6807\u8BB0\u5E94\u4E3A ${K}/${M.field502}/1`);let de=M.details?.nodeRef;(de?.class!==1||de?.type!==8||de?.id!==m)&&o.push(`${I}: Details ${z} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let E=(h.ui.content.data||[]).find(w=>w.field501===4&&w.field502===86);E&&(a(E.field14,"field17")?f+=1:o.push(`${I}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`),a(E.details?.field14,"field17")?f+=1:o.push(`${I}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`));let S=(h.ui.content.data||[]).find(w=>w.details?.transform)?.details?.transform?.multiPlatform?.platforms||[];S.length!==4&&o.push(`${I}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${S.length}\uFF0C\u5E94\u4E3A 4`);let k=S.map(w=>w.platformType||0);JSON.stringify(k)!==JSON.stringify([0,1,2,3])&&o.push(`${I}: \u5E73\u53F0\u987A\u5E8F ${k.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let $=(h.ui.content.data||[]).find(w=>w.details?.transform)?.details?.transform;$?.multiPlatform?.field502!==Bt[v]&&o.push(`${I}: \u53D8\u6362 preset=${$?.multiPlatform?.field502??"<missing>"}\uFF0C${v} \u5E94\u4E3A ${Bt[v]}`);for(let w of S)a(w.transform,"field508")?p+=1:o.push(`${I}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);c.push({id:m,name:h.name||"",kind:v,template:x,parent:y.parent||0,children:[...y.children||[]],relatedIds:(h.relatedIds||[]).map(w=>w.id||0),dataSignatures:D})}for(let h of c){let m=`${h.name||"<unnamed>"}(${h.id})`;if(JSON.stringify(h.relatedIds)!==JSON.stringify(h.children)&&o.push(`${m}: GraphUnit.relatedIds \u4E0E content.children \u4E0D\u4E00\u81F4`),h.template&&h.parent&&o.push(`${m}: \u9876\u5C42\u6A21\u677F\u4E0D\u5E94\u6709 parent`),!h.template){let y=s.get(h.parent);y?(y.ui?.content?.children||[]).includes(h.id)||o.push(`${m}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):o.push(`${m}: parent=${h.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let y of h.children){let v=s.get(y);v?(v.ui?.content?.parent||0)!==h.id&&o.push(`${m}: child=${y} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):o.push(`${m}: 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:f,rectField508:p}}}function mr(e){let t=bi(e),i=Ee.toObject(Ee.decode(t),{longs:Number,enums:Number,defaults:!1,arrays:!0,objects:!0}),r=(i.graph||[]).filter(w=>w.ui?.content&&Number(w.which)===21),n=(i.graph||[]).filter(w=>Number(w.which)===70),o=(i.graph||[]).filter(w=>Number(w.which)===kt),a=(i.accessories||[]).filter(w=>w.ui?.content),s=[],c=(w,M)=>w!=null&&Object.prototype.hasOwnProperty.call(w,M);/^\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(w=>{let M=Number(w.which);return M===kt||M===70||M===21?!1:!w.ui?.content});l.length&&s.push(`Root.graph \u542B ${l.length} \u4E2A\u65E0\u6CD5\u8BC6\u522B\u7684\u975E\u63A7\u4EF6/\u975E\u811A\u672C\u5355\u5143`);let f=r[0];if(!f)return{valid:!1,errors:s,filePath:i.filePath||"",gameVersion:i.gameVersion||"",accessoryCount:a.length,controls:[],scriptCount:o.length,explicitEmpty:{field17:0,rectField508:0}};let p=[f,...a],h=new Map;for(let w of p){let M=w.id?.id||0,z=`${w.name||"<unnamed>"}(${M||"<missing-guid>"})`;!Number.isSafeInteger(M)||M<=0||M>2147483647?s.push(`${z}: GraphUnit GUID \u975E\u6CD5`):h.has(M)?s.push(`${z}: GUID \u91CD\u590D`):h.set(M,w),(w.id?.class!==1||w.id?.type!==8)&&s.push(`${z}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),w.ui?.content?.guid!==M&&s.push(`${z}: content.guid \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`)}let m=f.id?.id||0,y=f.ui.content,v=`${f.name||"<unnamed>"}(${m})`;f.which!==21&&s.push(`${v}: which \u5FC5\u987B\u4E3A UIControlGroup(21)`);let x=y.info||[];x.find(w=>w.field501===1&&w.field502===5)?.guid?.value!==m&&s.push(`${v}: Info.self GUID \u7F3A\u5931\u6216\u4E0D\u4E00\u81F4`),x.find(w=>w.field501===2&&w.field502===6)?.index?.value!==1&&s.push(`${v}: Info.index \u5FC5\u987B\u4E3A 1`);let I=x.find(w=>w.field501===4&&w.field502===4);I||s.push(`${v}: \u7F3A\u5C11\u663E\u5F0F Info.related \u8BB0\u5F55`);let A=0,O=0,F=(w,M,z,Y=!1)=>{let ae=w.id?.id||0,K=`${w.name||"<unnamed>"}(${ae})`,de=w.ui.content.data||[],Je=de.map(ie=>`${ie.field501}/${ie.field502}`),gt=z.map(([ie])=>ie);JSON.stringify(Je)!==JSON.stringify(gt)&&s.push(`${K}: Data \u69FD\u4F4D\u987A\u5E8F ${Je.join(",")}\uFF0C\u5E94\u4E3A ${gt.join(",")}`);for(let ie=0;ie<Math.min(de.length,z.length);ie+=1){let Pe=de[ie],[Oe,Mt,Nt]=z[ie];if(c(Pe,Mt)||s.push(`${K}: Data ${Oe} \u7F3A\u5C11 ${Mt} \u5206\u652F`),!Nt)continue;c(Pe.details,Nt)||s.push(`${K}: Details ${Oe} \u7F3A\u5C11 ${Nt} \u5206\u652F`);let Ve=Hn[Oe];(Pe.details?.field501!==Ve||Pe.details?.field502!==Pe.field502||Pe.details?.field503!==1)&&s.push(`${K}: Details ${Oe} \u6807\u8BB0\u5E94\u4E3A ${Ve}/${Pe.field502}/1`);let Ft=Pe.details?.nodeRef;(Ft?.class!==1||Ft?.type!==8||Ft?.id!==ae)&&s.push(`${K}: Details ${Oe} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let Tt=de.find(ie=>ie.field501===4&&ie.field502===(Y?23:86)),te=Y?"empty15":"field17";c(Tt?.field14,te)?Y||(A+=1):s.push(`${K}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.${te} \u7A7A\u4E32`),c(Tt?.details?.field14,te)?Y||(A+=1):s.push(`${K}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.${te} \u7A7A\u4E32`);let Ae=de.find(ie=>ie.details?.transform)?.details?.transform,Ze=Ae?.multiPlatform?.platforms||[];Ze.length!==4&&s.push(`${K}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${Ze.length}\uFF0C\u5E94\u4E3A 4`);let ai=Ze.map(ie=>ie.platformType||0);JSON.stringify(ai)!==JSON.stringify([0,1,2,3])&&s.push(`${K}: \u5E73\u53F0\u987A\u5E8F ${ai.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let si=Y?Bt["server-container"]:Bt[M];Ae?.multiPlatform?.field502!==si&&s.push(`${K}: \u53D8\u6362 preset=${Ae?.multiPlatform?.field502??"<missing>"}\uFF0C\u5E94\u4E3A ${si}`);for(let ie of Ze)c(ie.transform,"field508")?O+=1:s.push(`${K}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);return Je};F(f,"server-container",ks,!0);let U=(f.relatedIds||[]).map(w=>w.id||0),ee=new Set(U),Z=a.filter(w=>ee.has(w.id?.id||0)),D=Z.map(w=>w.id?.id||0);JSON.stringify(U)!==JSON.stringify(D)&&s.push(`${v}: \u4E3B\u56FE relatedIds \u5FC5\u987B\u6309\u987A\u5E8F\u8986\u76D6\u672C\u7EC4 accessories`);let b=y.data?.find(w=>w.details?.rootChildRef)?.details?.rootChildRef?.guid||0,E=h.get(b);(!E||!Z.includes(E))&&s.push(`${v}: 62/82 \u6839\u8282\u70B9\u5F15\u7528\u4E0D\u5B58\u5728`),D[0]!==b&&s.push(`${v}: \u6839\u5BB9\u5668\u8282\u70B9\u5FC5\u987B\u662F\u672C\u7EC4 accessories[0]`);let S=[];for(let w of Z){let M=w.id?.id||0,z=w.ui.content,Y=`${w.name||"<unnamed>"}(${M})`,ae=yi(w);w.which!==15&&s.push(`${Y}: which \u5FC5\u987B\u4E3A UIControl(15)`);let K=z.info||[];(K.length!==1||K[0]?.field501!==1||K[0]?.field502!==5||K[0]?.guid?.value!==M)&&s.push(`${Y}: \u670D\u52A1\u7AEF\u5BB9\u5668\u5185\u63A7\u4EF6 Info \u5FC5\u987B\u53EA\u542B\u81EA\u8EAB GUID`);let de=Un[ae];de||s.push(`${Y}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${ae}`);let Je=de?F(w,ae,de):[];S.push({id:M,name:w.name||"",kind:ae,parent:z.parent||0,children:[...z.children||[]],relatedIds:(w.relatedIds||[]).map(gt=>gt.id||0),dataSignatures:Je})}let k=S.find(w=>w.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 $=new Map(S.map(w=>[w.id,w]));for(let w of S){let M=`${w.name}(${w.id})`;if(JSON.stringify(w.relatedIds)!==JSON.stringify(w.children)&&s.push(`${M}: relatedIds \u5FC5\u987B\u4E0E\u76F4\u63A5 children \u4E00\u81F4`),w.id!==b){let z=$.get(w.parent);z?z.children.includes(w.id)||s.push(`${M}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):s.push(`${M}: parent=${w.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let z of w.children){let Y=$.get(z);Y?Y.parent!==w.id&&s.push(`${M}: child=${z} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):s.push(`${M}: child=${z} \u4E0D\u5B58\u5728`)}}return{valid:s.length===0,errors:s,filePath:i.filePath||"",gameVersion:i.gameVersion||"",graph:{id:m,name:f.name||"",relatedGuids:I?.related?.value||[],rootGuid:b},accessoryCount:a.length,controls:S,scriptCount:o.length,explicitEmpty:{field17:A,rectField508:O}}}function lo(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 o=n.transformByPlatform||{},a=n.transformByCanvas||{},s=n.name||n.id;for(let l of Object.keys(o))if(!se.includes(l))throw new Error(`${s}: unknown platform ${l}`);let c={};for(let l of se){let f=yt[l],p=X[f].platform,h=Object.keys(X).filter(x=>X[x].platform===p&&a[x]),m=a[f]?f:h[0],y=l==="CONTROLLER_CONSOLE"?c.KEYBOARD:l==="CONTROLLER_MOBILE"?c.TOUCHSCREEN:null,v=o[l]??y??(m?a[m]:null);if(c[l]=v?Te(v):nr(n.kind),v||t.push(`${s}: ${l} \u65E0\u65E7\u5E03\u5C40\uFF0C\u5DF2\u4F7F\u7528\u63A7\u4EF6\u9ED8\u8BA4\u503C`),!o[l]&&!y&&m&&m!==f&&t.push(`${s}: \u7F3A\u5C11 ${f}\uFF0C\u5DF2\u91C7\u7528 ${m} \u7684\u951A\u70B9\u548C\u5C3A\u5BF8\u53C2\u6570`),!y)for(let x of h)JSON.stringify(c[l])!==JSON.stringify(Te(a[x]))&&t.push(`${s}: ${x} \u4E0E ${l} \u5E03\u5C40\u51B2\u7A81\uFF0C\u4FDD\u7559${o[l]?"\u5DF2\u6709\u5E73\u53F0":m}\u53C2\u6570`)}Le(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 gr(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 br(e,t,i,r=e.canvasId){let n=Ye(e.root,t);return!n||n.kind==="server-container"?ge(r):i[n.id]||ge(r)}function Xe(e,{warnings:t=[]}={}){if(!e)return nt();if(e=lo(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"?It():nt(),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(Number(e.meta?.giaModeFlag))&&Number(e.meta.giaModeFlag)>=0?{giaModeFlag:Number(e.meta.giaModeFlag)}:{}},canvasId:e.canvasId&&X[e.canvasId]?e.canvasId:li,selectedId:e.selectedId||r.selectedId,root:sr(e.root||r.root)};return po(n),n}function po(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=ar(e.root).id)}function co(e){return Be(Ct(e))}function $s(e,t){let i=!1;return q(e,r=>{r.id===t&&(i=!0)}),i}function Ds(e,t,i,r){let o=He(e.root,e.canvasId).boxes[t.id],a=i.children.findIndex(p=>p.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=He(e.root,e.canvasId),c=r.kind==="server-container"?ge(e.canvasId):s.boxes[r.id]||ge(e.canvasId),l=Ue(t.transformByPlatform,e.canvasId),f=et(c,l,{posX:o.centerX,posY:o.centerY,width:o.width,height:o.height});Et(e,t,f)}function Gs(e,t){return e.meta.assetType!=="client-control-template"?lr(e.root,t):(e.root.children||[]).flatMap(i=>lr(i,t))}function mo(e,t){let i=$n(e.root,t);if(e.meta.assetType!=="client-control-template")return i;let r=Lt(e),n=new Set;return r&&r.kind!=="server-container"&&q(r,o=>n.add(o.id)),i.filter(o=>n.has(o.id))}function go(e){let{canvas:t,boxes:i}=He(e.root,e.canvasId),r=Ut(e),n=ue(e.root,e.selectedId),o=n?i[n.id]:null;return G({layoutSchemaVersion:pe,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"&&Lt(e)?.id||""},tree:Gs(e,r),boxes:mo(e,i),inspector:Dn(n,e.canvasId,o||t,r),root:e.root})}function Et(e,t,i){let r=He(e.root,e.canvasId),n=br(e,t.id,r.boxes),o={};if(t.syncAllDevices!==!1)for(let a of se){if(a===tt(e.canvasId))continue;let s=yt[a],c=He(e.root,s,a);o[a]=br(e,t.id,c.boxes,s)}t.transformByPlatform=On({transformByPlatform:t.transformByPlatform,source:i,canvasId:e.canvasId,syncAllDevices:t.syncAllDevices!==!1,sourceParentBox:n,targetParentBoxByPlatform:o})}var zs=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"]),Vs=new Set(["posX","posY","width","height"]),Ls=new Set(["anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]);function Bs(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 De(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 Ys=new Set(["fontSize","minimumFontSize","imageId","clickAudioId","softEdgeWidthX","softEdgeWidthY","horizontalSoftRange","verticalSoftRange","fillAmount","cellSizeX","cellSizeY","spacingX","spacingY","padding1X","padding1Y","padding2X","padding2Y","previewCount","keyboardKeyCode","controllerKeyCode"]),Us=new Set(["active","visible","canControllerFocus","isolateNavigation","disableKeyEventPassthrough","disableCursorEventPassthrough","showCursor","adaptiveFontSize","enableOutline","enableMask","enableSoftEdge","enableFill","reverseMaskArea","raycastTarget","interactable","showScrollBar"]),Hs=new Set(["name","horizontalAlignment","verticalAlignment","text","softEdgeMode","fillType","fillHorizontalType","fillVerticalType","fillRadial90Type","fillRadialType","scrollDirection","layoutConstraint","referencedPrefabId","animationId"]),fo=new Set(["unavailableChildId","hoverChildId","pressedChildId","selectedChildId"]),ho={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 Ks(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}=He(e.root,e.canvasId),n=mo(e,r),o=Gn(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"?It():nt();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:or(e.root),guid:co(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=Mn(r,t.kind,{id:or(e.root),guid:co(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?Ye(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||$s(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 Ds(e,r,n,o),e.selectedId=r.id,e}if(i==="moveSibling"){let r=ue(e.root,t.id||e.selectedId),n=r?Ye(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=Ye(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 Nn(e.root,r)&&(q(e.root,o=>{if(o.kind==="button")for(let a of fo)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 f=_n(r.kind,l);if(!f)throw new Error(`unknown raw GIA field for ${r.kind}: ${l}`);if(r.giaRaw||={},r.giaRaw[l]=er(f,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 p={0:"Left",1:"Middle",2:"Right"}[r.giaRaw[l]];p&&(r.horizontalAlignment=p)}if(r.kind==="image"&&l==="imageFillType"){let p={1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[r.giaRaw[l]];p&&(r.fillType=p)}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=Ue(r.transformByPlatform,e.canvasId);Et(e,r,l)}return e}if(zs.has(n)){if(n.endsWith("Color")&&(o=Bs(o)),Ys.has(n)){if(o=De(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(Us.has(n)&&(o=uo(o)),Hs.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(ho[n]&&!ho[n].includes(o))throw new Error(`invalid ${n}`);if(fo.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(f=>f.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}=He(e.root,e.canvasId),s=br(e,r.id,a),c=Ue(r.transformByPlatform,e.canvasId);if(n==="anchorType"){let l=yr(a[r.id]),f=kn(c,o);return f=et(s,f,l),Et(e,r,f),e}if(n==="rotationZ"){let l={...c,rotation:{...c.rotation,z:De(o,n)}};return Et(e,r,l),e}if(Ls.has(n)){let l=yr(a[r.id]),f={...c,anchorMin:{...c.anchorMin},anchorMax:{...c.anchorMax},pivot:{...c.pivot}};return n==="anchorMinX"&&(f.anchorMin.x=De(o,n)),n==="anchorMinY"&&(f.anchorMin.y=De(o,n)),n==="anchorMaxX"&&(f.anchorMax.x=De(o,n)),n==="anchorMaxY"&&(f.anchorMax.y=De(o,n)),n==="pivotX"&&(f.pivot.x=De(o,n)),n==="pivotY"&&(f.pivot.y=De(o,n)),Et(e,r,et(s,f,l)),e}if(Vs.has(n)){let l=yr(a[r.id]),f=De(o,n);if((n==="width"||n==="height")&&f<0)throw new Error(`${n} must not be negative`);return l[n]=f,Et(e,r,et(s,c,l)),e}throw new Error(`set: unknown key ${n}`)}if(i==="replace"){let r=Xe(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 vr(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 Ks(r,t),po(r),r.version=i+1,Object.keys(e).forEach(n=>{delete e[n]}),Object.assign(e,r),e}function yr(e){return e?{posX:e.centerX,posY:e.centerY,width:e.width,height:e.height}:{posX:0,posY:0,width:0,height:0}}import Xs from"fengari";var{lua:u,lauxlib:oe,lualib:yo,to_luastring:vi,to_jsstring:Ws}=Xs,js=u.LUA_TNIL,qs=u.LUA_TBOOLEAN,Js=u.LUA_TNUMBER,Zs=u.LUA_TSTRING,bo=u.LUA_TTABLE,Qs=u.LUA_TFUNCTION,Sr=u.LUA_TUSERDATA,Me=u.LUA_OK,vo=new WeakMap,wr=Symbol("luaTableEntries"),Cr={__scriptHostKey:!0};function R(e){return vi(String(e))}function ot(e,t){vo.set(e,t)}function Ce(e){return vo.get(e)}function le(e,t,i){if(i==null){u.lua_pushnil(e);return}let r=typeof i;if(r==="boolean"){u.lua_pushboolean(e,i);return}if(r==="number"){Number.isInteger(i)&&Math.abs(i)<=2147483647?u.lua_pushinteger(e,i):u.lua_pushnumber(e,i);return}if(r==="string"){u.lua_pushstring(e,R(i));return}if(r==="function"){il(e,t,i);return}if(i&&i[wr]){let n=i[wr];u.lua_createtable(e,Array.isArray(i)?i.length:0,n.length);for(let[o,a]of n)le(e,t,o),le(e,t,a),u.lua_settable(e,-3);return}if(Array.isArray(i)){u.lua_createtable(e,i.length,0);for(let n=0;n<i.length;n++)le(e,t,i[n]),u.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.SetEase){t.pushTween(e,i);return}if(r==="object"){u.lua_createtable(e,0,Object.keys(i).length);for(let[n,o]of Object.entries(i))le(e,t,o),u.lua_setfield(e,-2,R(n));return}u.lua_pushnil(e)}function J(e,t){if(u.lua_isnil(e,t)||u.lua_type(e,t)===u.LUA_TNONE)return"";if(!u.lua_isstring(e,t)&&u.lua_type(e,t)!==u.LUA_TNUMBER)return`lua_type=${u.lua_type(e,t)}`;let i=u.lua_tostring(e,t);return i==null?"":Ws(i)}function We(e,t){t=u.lua_absindex(e,t);let i=u.lua_type(e,t);if(i===Sr)return Ce(u.lua_touserdata(e,t));if(i===bo){u.lua_pushlightuserdata(e,Cr),u.lua_rawget(e,t);let r=u.lua_type(e,-1)===Sr?u.lua_touserdata(e,-1):null;return u.lua_pop(e,1),r?Ce(r):null}return null}function ye(e,t,i){i=u.lua_absindex(e,i);let r=u.lua_type(e,i);if(r===js)return null;if(r===qs)return!!u.lua_toboolean(e,i);if(r===Js)return u.lua_isinteger(e,i)?u.lua_tointeger(e,i):u.lua_tonumber(e,i);if(r===Zs)return J(e,i);if(r===Sr){let n=u.lua_touserdata(e,i);return Ce(n)??n}if(r===Qs)return el(e,t,i);if(r===bo){let n=We(e,i);if(n)return n;let o=[];for(u.lua_pushnil(e);u.lua_next(e,i)!==0;){let l=ye(e,t,-2),f=ye(e,t,-1);o.push([l,f]),u.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,f]of o)Array.isArray(c)&&Number.isInteger(l)&&l>=1?c[l-1]=f:(typeof l=="string"||typeof l=="number")&&(c[l]=f);return Object.defineProperty(c,wr,{value:o}),c}return null}function el(e,t,i){t.luaFunctions||(t.luaFunctions=new Map);let r=typeof u.lua_topointer=="function"?u.lua_topointer(e,i):null;if(r!=null&&t.luaFunctions.has(r))return t.luaFunctions.get(r);u.lua_pushvalue(e,i);let n=oe.luaL_ref(e,u.LUA_REGISTRYINDEX),o=tl(e,t,n);return r!=null&&t.luaFunctions.set(r,o),o}function tl(e,t,i){let r=(...n)=>{let o=u.lua_gettop(e);u.lua_rawgeti(e,u.LUA_REGISTRYINDEX,i);for(let l of n)le(e,t,l);if(u.lua_pcall(e,n.length,u.LUA_MULTRET,0)!==Me){let l=J(e,-1);throw u.lua_settop(e,o),new Error(l)}let s=u.lua_gettop(e)-o,c=[];for(let l=1;l<=s;l++)c.push(ye(e,t,o+l));if(u.lua_settop(e,o),c.length!==0)return c.length===1?c[0]:c};return r.__luaRef=i,r.__luaState=e,r}function So(e,t){if(!t||t.__luaRef==null||!t.__luaState)return;let i=t.__luaState;if((!e?.luaStates||e.luaStates.has(i))&&oe.luaL_unref(i,u.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 il(e,t,i){u.lua_pushlightuserdata(e,i),u.lua_pushlightuserdata(e,t),u.lua_pushcclosure(e,function(n){let o=u.lua_touserdata(n,u.lua_upvalueindex(1)),a=u.lua_touserdata(n,u.lua_upvalueindex(2)),s=u.lua_gettop(n),c=[];for(let l=1;l<=s;l++)c.push(ye(n,a,l));try{let l=o(...c);if(Array.isArray(l)&&l.__multi){for(let f of l)le(n,a,f);return l.length}return l===void 0?0:(le(n,a,l),1)}catch(l){return u.lua_pushstring(n,R(String(l&&l.message?l.message:l))),u.lua_error(n)}},2)}function wo(e){!e||typeof u.lua_close!="function"||u.lua_close(e)}function Co(e){if(oe.luaL_loadstring(e,R(["local nativeGetMetatable = getmetatable","getmetatable = function(value)",' if type(value) == "string" then return nil end'," return nativeGetMetatable(value)","end"].join(`
108
- `)))===Me&&u.lua_pcall(e,0,0,0),u.lua_settop(e,0),u.lua_pushnil(e),u.lua_setglobal(e,R("_VERSION")),u.lua_getglobal(e,R("string")),!u.lua_isnil(e,-1))for(let i of["dump","pack","unpack"])u.lua_pushnil(e),u.lua_setfield(e,-2,R(i));if(u.lua_pop(e,1),u.lua_pushnil(e),u.lua_setglobal(e,R("io")),u.lua_getglobal(e,R("os")),!u.lua_isnil(e,-1))for(let i of Object.keys({execute:1,getenv:1,remove:1,rename:1,tmpname:1,setlocale:1,exit:1}))u.lua_pushnil(e),u.lua_setfield(e,-2,R(i));u.lua_pop(e,1),u.lua_getglobal(e,R("debug")),u.lua_isnil(e,-1)?u.lua_pop(e,1):(u.lua_getfield(e,-1,R("traceback")),u.lua_newtable(e),u.lua_pushvalue(e,-2),u.lua_setfield(e,-2,R("traceback")),u.lua_setglobal(e,R("debug")),u.lua_pop(e,2)),u.lua_getglobal(e,R("math")),u.lua_isnil(e,-1)||(u.lua_pushcfunction(e,i=>{let r=u.lua_tonumber(i,1);return u.lua_pushboolean(i,Number.isNaN(r)),1}),u.lua_setfield(e,-2,R("isnan")),u.lua_pushcfunction(e,i=>{let r=u.lua_tonumber(i,1);return u.lua_pushboolean(i,r===1/0||r===-1/0),1}),u.lua_setfield(e,-2,R("isinf"))),u.lua_pop(e,1),u.lua_pushnil(e),u.lua_setglobal(e,R("package")),u.lua_pushnil(e),u.lua_setglobal(e,R("load")),u.lua_pushnil(e),u.lua_setglobal(e,R("loadfile")),u.lua_pushnil(e),u.lua_setglobal(e,R("dofile")),u.lua_pushnil(e),u.lua_setglobal(e,R("collectgarbage")),u.lua_pushnil(e),u.lua_setglobal(e,R("coroutine")),u.lua_pushnil(e),u.lua_setglobal(e,R("fengari"))}var Io={container:"ClientUIContainerControl",textbox:"ClientUITextBoxControl",textwindow:"ClientUITextWindowControl",image:"ClientUIImageControl",button:"ClientUIPresetButtonControl",cursor:"ClientUICursorEventAreaControl",grid:"ClientUIGridScrollerControl",keyhint:"ClientUIKeyHintControl",animation:"ClientUIAnimationControl",fullscreen:"ClientUIFullscreenAnimationControl",reference:"ClientUIReferenceControl"},rl=["alive","Id","prefabIndex","active","activeInHierarchy","visible"],Si=new Set(["active","visible","parent","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]),nl=["name","parent","anchoredPositionX","anchoredPositionY","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY","localScaleX","localScaleY","localScaleZ","localRotationX","localRotationY","localRotationZ","canControllerFocus"],ol={image:["imageSource","imageId"],grid:["itemCount","scrollDirection","layoutConstraint","layoutConstraintFixedCount"],reference:["referencedPrefabIndex"]},al={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"]},sl=["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"],ko=["AddCursorEventListener","RemoveCursorEventListener","RemoveCursorEventListeners","RemoveAllCursorEventListeners","SimulateCursorClick"],ll={image:["SetImage","SetSoftEdgeWidth","SetFillUnused","SetFillHorizontal","SetFillVertical","SetFillRadial90","SetFillRadial180","SetFillRadial360"],button:ko,cursor:ko,animation:["PlayAnimation","StopAnimation"],grid:["RefreshItems","GetItemIndex","GetItemSize","GetItemSpacing","GetPadding","ScrollToItemAt","GetContentLength"]};function Ir(e,t){return rl.includes(t)||(ol[e.kind]||[]).includes(t)?"ro":nl.includes(t)||(al[e.kind]||[]).includes(t)?"rw":null}function Eo(e,t){return sl.includes(t)||(ll[e.kind]||[]).includes(t)}var cl={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=Io[this.kind]||Io.container,this.alive=!0,this.Id=i.Id??t.nextControlId(),this.authoringId=i.authoringId??null,this.prefabIndex=i.prefabIndex??0,this.name=i.name??"",this.active=i.active===!0,this.visible=i.visible!==!1,this._parent=null,this.children=[],this.scripts=[],this.cursorListeners=new Map,this.keyListeners=new Map,this.navListeners=new Map,this.navConfig=new Map,this.anchoredPositionX=i.anchoredPositionX??0,this.anchoredPositionY=i.anchoredPositionY??0,this.sizeDeltaX=i.sizeDeltaX??0,this.sizeDeltaY=i.sizeDeltaY??0,this.anchorMinX=i.anchorMinX??.5,this.anchorMinY=i.anchorMinY??.5,this.anchorMaxX=i.anchorMaxX??.5,this.anchorMaxY=i.anchorMaxY??.5,this.pivotX=i.pivotX??.5,this.pivotY=i.pivotY??.5,this.localScaleX=i.localScaleX??1,this.localScaleY=i.localScaleY??1,this.localScaleZ=i.localScaleZ??1,this.localRotationX=i.localRotationX??0,this.localRotationY=i.localRotationY??0,this.localRotationZ=i.localRotationZ??0,this.canControllerFocus=i.canControllerFocus??!1,this._playDirty=!0,this._playDeepDirty=!0,this._playChildDirty=!1;let r=cl[this.kind]||{};for(let[n,o]of Object.entries(r))this[n]===void 0&&(this[n]=i[n]!==void 0?i[n]:o);if(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}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[this.localRotationX,this.localRotationY,this.localRotationZ]}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)}_removeListener(t,i,r){let n=t.get(i);n&&(t.set(i,n.filter(o=>o!==r)),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(){throw new Error("ClientUIGridScrollerControl:RefreshItems not implemented")}GetItemIndex(){throw new Error("ClientUIGridScrollerControl:GetItemIndex not implemented")}GetItemSize(){throw new Error("ClientUIGridScrollerControl:GetItemSize not implemented")}GetItemSpacing(){throw new Error("ClientUIGridScrollerControl:GetItemSpacing not implemented")}GetPadding(){throw new Error("ClientUIGridScrollerControl:GetPadding not implemented")}ScrollToItemAt(){throw new Error("ClientUIGridScrollerControl:ScrollToItemAt not implemented")}GetContentLength(){throw new Error("ClientUIGridScrollerControl:GetContentLength not implemented")}};function Ne(e,t){t(e);for(let i of e.children)Ne(i,t)}function kr(e,t=[],i=""){t.push(`${i}${e.name||"(unnamed)"} [${e.typeofName}] Id=${e.Id}`);for(let r of e.children)kr(r,t,i+" ");return t}function wi(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 xo={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-wi(1-e),OutBounce:wi,InOutBounce:e=>e<.5?(1-wi(1-2*e))/2:(1+wi(2*e-1))/2};function Ao(e,t){let i=xo[e]||xo.Linear;return t<=0?0:t>=1?1:i(t)}function xt(e,t,i,r=255){let n=Ci(e),o=Ci(t),a=Ci(i);return((r==null?255:Ci(r))<<24|n<<16|o<<8|a)>>>0}function Ht(e){let t=e>>>0;return[t>>>16&255,t>>>8&255,t&255,t>>>24&255]}function Ci(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(255,Math.trunc(t))):0}function Po(e,t,i){let r=Ht(e),n=Ht(t);return xt(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 ul=new Set(["fontColor","bgColor","outlineColor","imageColor"]),Ii=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}capture(){this.from={},this.to={};for(let[t,i]of Object.entries(this.data)){let r=this.object[t];this.from[t]=r,this.to[t]=this.relative?Number(r)+Number(i):i}}restoreInitial(){this.initialFrom?(this.from={...this.initialFrom},this.to={...this.initialTo}):this.capture()}SetEase(t){return this.easeName=typeof t=="string"?t:t?.Name||"Linear",this}SetRelative(t){return this.relative=!!t,this}Play(){return this._start(!1)}_start(t){return this.playing=!0,this.paused=!1,this.elapsed=0,this.loopIndex=0,this.killed=!1,t&&this.initialFrom?this.restoreInitial():(this.capture(),this.initialFrom={...this.from},this.initialTo={...this.to}),this.runtime.tweens.add(this),this.duration===0&&this.Complete(),this}Pause(){this.paused=!0}Resume(){this.paused=!1}Restart(){return this._start(!0)}Complete(){this.apply(1),this.finish(!0)}Kill(t){t?this.Complete():this.finish(!1)}SetOnComplete(t){return this.onComplete=t,this}SetOnStepComplete(t){return this.onStepComplete=t,this}SetLoops(t){return this.loops=t,this}apply(t){let i=Ao(this.easeName,t),r=!1,n=!1;for(let o of Object.keys(this.to)){let a=this.from[o],s=this.to[o];ul.has(o)&&typeof a=="number"&&typeof s=="number"?this.object[o]=Po(a,s,i):typeof a=="number"&&typeof s=="number"?this.object[o]=a+(s-a)*i:this.object[o]=i>=1?s:a,r=!0,Si.has(o)&&(n=!0)}r&&typeof this.object?.markPlayDirty=="function"&&this.object.markPlayDirty(n)}step(t){if(!this.playing||this.paused||this.killed)return;this.elapsed+=t;let i=this.duration<=0?1:Math.min(1,this.elapsed/this.duration);if(this.apply(i),i>=1){this.onStepComplete&&this.runtime.safeCall(this.onStepComplete);let r=this.loops<0;if(this.loopIndex++,r||this.loopIndex<this.loops){this.elapsed=Math.max(0,this.elapsed-this.duration),this.relative?this.capture():this.restoreInitial();let n=this.duration<=0?1:Math.min(1,this.elapsed/this.duration);this.apply(n)}else this.finish(!0)}}finish(t){this.playing=!1,this.killed=!0,this.runtime.tweens.delete(this),t&&this.onComplete&&this.runtime.safeCall(this.onComplete)}},ki=class{constructor(t){this.runtime=t,this.steps=[],this.playing=!1,this.paused=!1,this.killed=!1,this.elapsed=0,this.loops=1,this.loopIndex=0,this.onComplete=null,this.onStepComplete=null,this._built=[]}Append(t){return this.steps.push({kind:"tween",tween:t,parallel:!1}),this}AppendInterval(t){return this.steps.push({kind:"interval",duration:t}),this}AppendCallback(t){return this.steps.push({kind:"callback",fn:t}),this}Join(t){return this.steps.push({kind:"tween",tween:t,parallel:!0}),this}Insert(t,i){return this.steps.push({kind:"insert",time:t,tween:i}),this}InsertCallback(t,i){return this.steps.push({kind:"insertCb",time:t,fn:i}),this}Play(){return this.playing=!0,this.paused=!1,this.killed=!1,this.elapsed=0,this.loopIndex=0,this._schedule(),this._activateDueEntries(),this.runtime.sequences.add(this),this}_schedule(){let t=0,i=0,r=!1;this._built=[];for(let n of this.steps)if(n.kind==="tween"&&n.parallel){let o=r?i:t;this._built.push({at:o,tween:n.tween}),t=Math.max(t,o+n.tween.duration)}else n.kind==="tween"?(this._built.push({at:t,tween:n.tween}),i=t,r=!0,t+=n.tween.duration):n.kind==="interval"?(i=t,r=!0,t+=n.duration):n.kind==="callback"?this._built.push({at:t,fn:n.fn}):n.kind==="insert"?(this._built.push({at:n.time,tween:n.tween}),t=Math.max(t,n.time+n.tween.duration)):n.kind==="insertCb"&&(this._built.push({at:n.time,fn:n.fn}),t=Math.max(t,n.time));this._end=t,this._fired=new Set}Pause(){this.paused=!0;for(let t of this._built)t.tween&&this._fired.has(t)&&t.tween.Pause()}Resume(){this.paused=!1;for(let t of this._built)t.tween&&this._fired.has(t)&&t.tween.Resume()}Restart(){this.Play()}Complete(){for(let t of this._built)t.tween&&(this._fired.has(t)||t.tween.Play(),t.tween.Complete()),t.fn&&!this._fired.has(t)&&this.runtime.safeCall(t.fn),this._fired.add(t);this.finish(!0)}Kill(t){if(t)this.Complete();else{for(let i of this._built)i.tween&&this._fired.has(i)&&i.tween.Kill(!1);this.finish(!1)}}SetOnComplete(t){return this.onComplete=t,this}SetOnStepComplete(t){return this.onStepComplete=t,this}SetLoops(t){return this.loops=t,this}_activateDueEntries(){for(let t of this._built)this._fired.has(t)||this.elapsed+1e-9<t.at||(this._fired.add(t),t.tween&&t.tween.Play(),t.fn&&this.runtime.safeCall(t.fn))}step(t){!this.playing||this.paused||this.killed||(this.elapsed+=t,this._activateDueEntries(),this.elapsed>=this._end&&(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.loopIndex++,this.loops<0||this.loopIndex<this.loops?(this.elapsed=0,this._schedule()):this.finish(!0)))}finish(t){this.playing=!1,this.killed=!0,this.runtime.sequences.delete(this),t&&this.onComplete&&this.runtime.safeCall(this.onComplete)}};var Ei={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"]},fl=[...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"],dl=[...Array.from({length:14},(e,t)=>`CraftspersonKey${t+1}`),"SprintKey","JumpKey","InteractKey","NormalAttackKey","CharacterSkill1Key","CharacterSkill2Key","CharacterSkill3Key","CharacterSkill4Key","MenuConfirmKey","MenuBackKey","None"];function hl(){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}Ei.KeyboardKeyCode=fl;Ei.ControllerKeyCode=dl;Ei.KeyEventType=hl();var _o=new Map;function at(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 Er(e,t){return t==null?t:t.__kind==="EnumItem"?at(t.EnumType||e,t.Name):typeof t=="string"&&t?at(e,t):t}function xr(){let e={};for(let[t,i]of Object.entries(Ei)){let r={};for(let n of i)r[n]=at(t,n);e[t]=r}return e}var Ro={horizontalAlignment:"TextHorizontalAlignment",verticalAlignment:"TextVerticalAlignment",imageSource:"ImageSource",fillType:"ImageFillType",fillHorizontalType:"ImageFillHorizontalType",fillVerticalType:"ImageFillVerticalType",fillRadial90Type:"ImageFillRadial90Type",fillRadialType:"ImageFillRadialType",softEdgeMode:"ImageMaskSoftEdgeMode",layer:"UIAnimationLayer",scrollDirection:"ScrollDirection",layoutConstraint:"ScrollLayoutConstraint"},st=u.LUA_REGISTRYINDEX,pl=u.LUA_MULTRET,ml=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 xi=class{constructor(t={}){this.canvasWidth=t.canvasWidth??1600,this.canvasHeight=t.canvasHeight??900,this.device=t.device??"KeyboardAndMouse",this.language=t.language??"LanguageChs",this.stageMode=t.stageMode??"Classic",this.testPlay=t.testPlay!==!1,this.clock={time:0,levelTime:0,paused:!1,frame:0},this.logs=[],this.mountErrors=[],this.tweens=new Set,this.sequences=new Set,this.audios=new Map,this.nextAudioId=1,this._nextControlId=1,this._playRemoved=[],this._nextScriptMappingId=1,this.lifecyclePhase="idle",this.controlsById=new Map,this.roots=[],this.templates=new Map,this.scriptFiles=new Map,this.requireAliases=new Map,this.requireCache=new Map,this.moduleBaseEnvironments=new Map,this.luaFunctions=new Map,this.mountedScripts=[],this.serverVars={Level:Object.create(null),PlayerSelf:Object.create(null),AvatarSelf:Object.create(null)},this.serverBridge=null,this.varHandlers=[],this.signalHandlers=[],this.cursor={x:0,y:0},this.focus=null,this.stick={left:[0,0],right:[0,0]},this.enumTree=xr(),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?u.lua_pushinteger(t,r):u.lua_pushnumber(t,r)}unrefLuaCallback(t){So(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),Ne(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(f){let p=f&&f.message?f.message:String(f);this.mountErrors.push(p),this.log("lua-error",p)}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;u.lua_pushcfunction(t,r=>{let n=u.lua_gettop(r),o=[];for(let a=1;a<=n;a++)o.push(ye(r,i,a));return i.log("info",...o),0}),u.lua_setglobal(t,R("print")),u.lua_pushcfunction(t,r=>{let n=u.lua_gettop(r),o=[];for(let a=1;a<=n;a++)o.push(ye(r,i,a));return i.log("error",...o),0}),u.lua_setglobal(t,R("printerr")),u.lua_pushcfunction(t,r=>{if(u.lua_type(r,1)===u.LUA_TTABLE&&!We(r,1))return u.lua_pushstring(r,R("table")),1;let n=ye(r,i,1);return u.lua_pushstring(r,R(i.typeofOf(n))),1}),u.lua_setglobal(t,R("typeof")),this.pushColorLib(t),this.pushEnumLib(t),this.pushGameLib(t),u.lua_pushcfunction(t,r=>i.luaRequire(r)),u.lua_setglobal(t,R("require"))}typeofOf(t){return t==null?"nil":t.__kind==="Script"?"Script":t.__kind==="EnumItem"?"EnumItem":t.__kind==="CursorEventData"?"CursorEventData":t.typeofName?t.typeofName:typeof t=="number"?"number":typeof t=="string"?"string":typeof t=="boolean"?"boolean":typeof t}pushColorLib(t){u.lua_newtable(t),u.lua_pushcfunction(t,i=>(this.pushPackedColor(i,xt(u.lua_tonumber(i,1),u.lua_tonumber(i,2),u.lua_tonumber(i,3),255)),1)),u.lua_setfield(t,-2,R("FromRGB")),u.lua_pushcfunction(t,i=>{let r=u.lua_isnoneornil(i,4)?255:u.lua_tonumber(i,4);return this.pushPackedColor(i,xt(u.lua_tonumber(i,1),u.lua_tonumber(i,2),u.lua_tonumber(i,3),r)),1}),u.lua_setfield(t,-2,R("FromRGBA")),u.lua_pushcfunction(t,i=>{let r=u.lua_tonumber(i,1)>>>0,[n,o,a,s]=Ht(r);return u.lua_pushnumber(i,n),u.lua_pushnumber(i,o),u.lua_pushnumber(i,a),u.lua_pushnumber(i,s),4}),u.lua_setfield(t,-2,R("ToRGBA")),u.lua_newtable(t),u.lua_pushcfunction(t,i=>{let r=u.lua_tonumber(i,2),n=u.lua_tonumber(i,3),o=u.lua_tonumber(i,4),a=u.lua_isnoneornil(i,5)?255:u.lua_tonumber(i,5);return this.pushPackedColor(i,xt(r,n,o,a)),1}),u.lua_setfield(t,-2,R("__call")),u.lua_setmetatable(t,-2),u.lua_setglobal(t,R("Color"))}pushEnumLib(t){u.lua_newtable(t);for(let[i,r]of Object.entries(this.enumTree)){u.lua_newtable(t);for(let[n,o]of Object.entries(r))this.pushEnumItem(t,o),u.lua_setfield(t,-2,R(n));u.lua_setfield(t,-2,R(i))}u.lua_setglobal(t,R("Enum"))}pushEnumItem(t,i){let r=u.lua_newuserdata(t,0);ot(r,i),oe.luaL_setmetatable(t,R("EnumItem"))}pushControl(t,i){let r=u.lua_newuserdata(t,0);ot(r,i),oe.luaL_setmetatable(t,R("Control"))}pushScript(t,i){u.lua_newtable(t),u.lua_pushlightuserdata(t,Cr);let r=u.lua_newuserdata(t,0);ot(r,i),u.lua_rawset(t,-3),oe.luaL_getmetatable(t,R("Script")),u.lua_setmetatable(t,-2)}pushTween(t,i){let r=u.lua_newuserdata(t,0);ot(r,i);let n=i.Append?"TweenSequence":"Tween";oe.luaL_setmetatable(t,R(n))}pushCursor(t,i){let r=u.lua_newuserdata(t,0);ot(r,i),oe.luaL_setmetatable(t,R("CursorEventData"))}pushGameLib(t){let i=this;u.lua_newtable(t);let r={InstantiateClientUIControl:n=>{let o=u.lua_tointeger(n,1),a=Ce(u.lua_touserdata(n,2)),s=i.instantiate(o,a,i.lifecyclePhase);return s?(i.pushControl(n,s),1):(u.lua_pushnil(n),1)},DestroyClientUIControl:n=>{let o=Ce(u.lua_touserdata(n,1));return o&&i.destroyControl(o),0},GetClientUIControl:n=>{let o=u.lua_tointeger(n,1),a=i.controlsById.get(o);return a?i.pushControl(n,a):u.lua_pushnil(n),1},FindClientUIRoot:n=>{let o=J(n,1),a=i.roots.find(s=>s.name===o);return a?i.pushControl(n,a):u.lua_pushnil(n),1},GetClientUIRoots:n=>(u.lua_createtable(n,i.roots.length,0),i.roots.forEach((o,a)=>{i.pushControl(n,o),u.lua_rawseti(n,-2,a+1)}),1),GetUICanvasSize:n=>(u.lua_pushnumber(n,i.canvasWidth),u.lua_pushnumber(n,i.canvasHeight),2),GetCursorUIPos:n=>(u.lua_pushnumber(n,i.cursor.x),u.lua_pushnumber(n,i.cursor.y),2),GetDevice:n=>(i.pushEnumItem(n,at("Device",i.device)),1),SetControllerFocus:n=>(i.focus=Ce(u.lua_touserdata(n,1)),0),GetControllerFocus:n=>(i.focus?i.pushControl(n,i.focus):u.lua_pushnil(n),1),GetControllerLeftStickAxis:n=>(u.lua_pushnumber(n,i.stick.left[0]),u.lua_pushnumber(n,i.stick.left[1]),2),GetControllerRightStickAxis:n=>(u.lua_pushnumber(n,i.stick.right[0]),u.lua_pushnumber(n,i.stick.right[1]),2),Tween:n=>{let o=Ce(u.lua_touserdata(n,1))||ye(n,i,1),a=ye(n,i,2)||{},s=u.lua_tonumber(n,3),c=new Ii(i,o,a,s);return i.pushTween(n,c),1},TweenSequence:n=>(i.pushTween(n,new ki(i)),1),ServerSignal:n=>{let o=J(n,1),a=i.makeServerSignal(o),s=u.lua_newuserdata(n,0);return ot(s,a),oe.luaL_setmetatable(n,R("ServerSignal")),1},GetGlobalCustomVariableValue:n=>{let o=be(ye(n,i,1)),a=J(n,2);return le(n,i,i.getVar(o,a)),1},PauseLevelTime:n=>(i.clock.paused=!!u.lua_toboolean(n,1),0),IsLevelTimePaused:n=>(u.lua_pushboolean(n,i.clock.paused),1),PlayAudio2D:n=>{let o=i.nextAudioId++;return i.audios.set(o,{audioId:u.lua_tointeger(n,1),alive:!0}),u.lua_pushinteger(n,o),1},StopAudio:n=>{let o=u.lua_tointeger(n,1),a=i.audios.get(o);return a&&(a.alive=!1),0},IsAudioAlive:n=>{let o=i.audios.get(u.lua_tointeger(n,1));return u.lua_pushboolean(n,!!(o&&o.alive)),1},GetLanguageType:n=>(i.pushEnumItem(n,at("LanguageType",i.language)),1),GetStageMode:n=>(i.pushEnumItem(n,at("StageMode",i.stageMode)),1),IsTestPlay:n=>(u.lua_pushboolean(n,i.testPlay),1),GetText:n=>{let o=J(n,1);return u.lua_pushstring(n,R(o)),1},PrintClientUITree:n=>{for(let o of i.roots)i.log("info",kr(o).join(`
109
- `));return 0}};for(let[n,o]of Object.entries(r)){let a=ml[n];if(a===void 0)throw new Error(`missing game arity for ${n}`);u.lua_pushcfunction(t,s=>{let c=u.lua_gettop(s);return c!==a?oe.luaL_error(s,R(`bad argument count to '${n}' (${a} expected, got ${c})`)):o(s)}),u.lua_setfield(t,-2,R(n))}u.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)}}}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),Ne(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}`);Ne(t,i=>{i._destroying=!0}),this._destroyControlTree(t)}}_destroyControlTree(t){this.releaseControlListeners(t);for(let i of t.scripts.slice())this.unmountScript(i);for(let i of t.children.slice())this._destroyControlTree(i);if(t.alive=!1,this._playRemoved.push(t.Id),t.parent){let i=t.parent,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=[];Ne(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),u.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){oe.luaL_newmetatable(t,R(i)),u.lua_pushcfunction(t,s=>{let c=We(s,1)||Ce(u.lua_touserdata(s,1)),l=J(s,2);if(o[l]&&(!a||a(c,l)))return u.lua_pushcfunction(s,o[l]),1;let f=r(c,l);return f===void 0?(u.lua_pushnil(s),1):(le(s,this,f),1)}),u.lua_setfield(t,-2,R("__index")),u.lua_pushcfunction(t,s=>{try{let c=We(s,1)||Ce(u.lua_touserdata(s,1)),l=J(s,2),f=ye(s,this,3);return n(c,l,f),0}catch(c){return u.lua_pushstring(s,R(String(c.message||c))),u.lua_error(s)}}),u.lua_setfield(t,-2,R("__newindex")),u.lua_pushcfunction(t,s=>{let c=We(s,1)||Ce(u.lua_touserdata(s,1)),l=We(s,2)||Ce(u.lua_touserdata(s,2));return u.lua_pushboolean(s,c===l),1}),u.lua_setfield(t,-2,R("__eq")),u.lua_pop(t,1)}method(t){let i=this;return r=>{let n=We(r,1)||Ce(u.lua_touserdata(r,1)),o=u.lua_gettop(r),a=[];for(let s=2;s<=o;s++)a.push(ye(r,i,s));try{let s=t(n,...a);if(s===n)return u.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 u.lua_createtable(r,s.length,0),s.forEach((c,l)=>{i.pushControl(r,c),u.lua_rawseti(r,-2,l+1)}),1;if(s.__scripts)return u.lua_createtable(r,s.length,0),s.forEach((c,l)=>{i.pushScript(r,c),u.lua_rawseti(r,-2,l+1)}),1;if(typeof s[0]=="number"&&s.length<=4){for(let c of s)u.lua_pushnumber(r,c);return s.length}}return le(r,i,s),1}catch(s){return u.lua_pushstring(r,R(String(s.message||s))),u.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=>r.RefreshItems()),GetItemIndex:this.method(r=>r.GetItemIndex()),GetItemSize:this.method(r=>r.GetItemSize()),GetItemSpacing:this.method(r=>r.GetItemSpacing()),GetPadding:this.method(r=>r.GetPadding()),ScrollToItemAt:this.method(r=>r.ScrollToItemAt()),GetContentLength:this.method(r=>r.GetContentLength())};this.mtIndexNewindex(t,"Control",(r,n)=>{if(!Ir(r,n))return;let o=r[n],a=Ro[n];return a?Er(a,o):o},(r,n,o)=>{if(Ir(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=Ro[n];r[n]=s?Er(s,o):o,typeof r.markPlayDirty=="function"&&r.markPlayDirty(Si.has(n));return}throw new Error(`cannot set ${n}, no such field`)},i,Eo)}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:this.method((n,o,...a)=>n.invoke(o,a)),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=J(t,1),r=this.normalizeRequirePath(i),n=this.requireAliases.get(r)||r;u.lua_rawgeti(t,st,u.LUA_RIDX_MAINTHREAD);let o=u.lua_tothread(t,-1);u.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 u.lua_pushstring(t,R(`failed to load script '${r}': cyclic require`)),u.lua_error(t);if(s&&s.ref!=null)return u.lua_rawgeti(t,st,s.ref),1;let c=this.scriptFiles.get(n);if(c==null)return u.lua_pushstring(t,R(`failed to load script '${r}'`)),u.lua_error(t);let l=u.lua_gettop(t);a.set(n,{loading:!0});try{this.loadModule(t,o,n,c),u.lua_pushvalue(t,-1);let f=oe.luaL_ref(t,st);return a.set(n,{ref:f}),1}catch(f){return a.delete(n),u.lua_settop(t,l),u.lua_pushstring(t,R(`failed to load script '${r}': ${f.message||f}`)),u.lua_error(t)}}newLuaThread(){let t=oe.luaL_newstate();return yo.luaL_openlibs(t),Co(t),this.installMetatables(t),this.installGlobals(t),this.luaStates.add(t),u.lua_pushglobaltable(t),this.copyLuaEnvironment(t,-1),u.lua_remove(t,-2),this.moduleBaseEnvironments.set(t,oe.luaL_ref(t,st)),t}copyLuaEnvironment(t,i){let r=u.lua_absindex(t,i);u.lua_newtable(t);let n=u.lua_absindex(t,-1);for(u.lua_pushnil(t);u.lua_next(t,r)!==0;)u.lua_pushvalue(t,-2),u.lua_pushvalue(t,-2),u.lua_rawset(t,n),u.lua_pop(t,1);u.lua_pushvalue(t,n),u.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&&oe.luaL_unref(t,st,r.ref);this.requireCache.delete(t);let i=this.moduleBaseEnvironments.get(t);if(i!=null&&oe.luaL_unref(t,st,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);wo(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=vi(a);if(oe.luaL_loadbuffer(t,s,s.length,R(`@${r}`))!==Me)throw new Error(J(t,-1));let l=u.lua_absindex(t,-1);if(u.lua_rawgeti(t,st,this.moduleBaseEnvironments.get(i)),this.copyLuaEnvironment(t,-1),u.lua_remove(t,-2),this.pushScript(t,o),u.lua_setfield(t,-2,R("script")),u.lua_setupvalue(t,l,1),u.lua_pcall(t,0,1,0)!==Me)throw new Error(J(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,f)=>this.invokeOn(a,l,f),r&&r.scripts.push(s),this.mountedScripts.push(s),this.pushScript(a,s),u.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 f=this.callGlobal(a,"OnEnable");f&&this.mountErrors.push(f),this.lifecyclePhase="OnStart",s.lifecyclePhase="OnStart";let p=this.callGlobal(a,"OnStart");return p&&this.mountErrors.push(p),this.lifecyclePhase="running",s.lifecyclePhase="running",s}catch(l){throw s.alive=!1,s.lifecyclePhase="failed",this.mountedScripts=this.mountedScripts.filter(f=>f!==s),r&&(r.scripts=r.scripts.filter(f=>f!==s)),this.varHandlers=this.varHandlers.filter(f=>f.script!==s),this.signalHandlers=this.signalHandlers.filter(f=>f.script!==s),this.lifecyclePhase=c,a&&a!==this.L&&this.closeTrackedLuaState(a),s.env=null,l}}runChunk(t,i,r){let n=String(i).replace(/^\uFEFF/,""),o=vi(n),a=oe.luaL_loadbuffer(t,o,o.length,R(`@${r}`));if(a!==Me){let c=J(t,-1)||`luaL_loadbuffer status ${a}`;throw u.lua_pop(t,1),new Error(c)}let s=u.lua_pcall(t,0,0,0);if(s!==Me){let c=J(t,-1)||`lua_pcall status ${s}`;throw u.lua_pop(t,1),new Error(c)}}callGlobal(t,i){if(u.lua_getglobal(t,R(i)),u.lua_isfunction(t,-1)){if(u.lua_pcall(t,0,0,0)!==Me){let n=J(t,-1);u.lua_pop(t,1);let o=`${i}: ${n}`;return this.log("lua-error",o),o}}else u.lua_pop(t,1);return null}callGlobalDt(t,i,r){if(u.lua_getglobal(t,R(i)),u.lua_isfunction(t,-1)){if(u.lua_pushnumber(t,r),u.lua_pcall(t,1,0,0)!==Me){let o=J(t,-1);u.lua_pop(t,1),this.log("lua-error",`${i}: ${o}`)}}else u.lua_pop(t,1)}invokeOn(t,i,r){let n=u.lua_gettop(t);if(u.lua_getglobal(t,R(i)),!u.lua_isfunction(t,-1)){u.lua_settop(t,n);return}for(let c of r)le(t,this,c);if(u.lua_pcall(t,r.length,pl,0)!==Me){let c=J(t,-1);throw u.lua_settop(t,n),new Error(c)}let a=u.lua_gettop(t)-n;if(a<=0){u.lua_settop(t,n);return}if(a===1){let c=ye(t,this,-1);return u.lua_settop(t,n),c}let s=[];for(let c=1;c<=a;c++)s.push(ye(t,this,n+c));return u.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),u.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;let i=!this.clock.paused;for(let r of[...this.tweens])r.step(t);for(let r of[...this.sequences])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;u.lua_createtable(r,0,5);let n=(o,a)=>{u.lua_pushcfunction(r,a),u.lua_setfield(r,-2,R(o))};return n("var",o=>(le(o,this,i.var(J(o,1),J(o,2))),1)),n("logContains",o=>(u.lua_pushboolean(o,i.logContains(J(o,1))),1)),n("control",o=>(le(o,this,i.control(J(o,1))),1)),n("logs",o=>(le(o,this,i.logs()),1)),n("signals",o=>(le(o,this,i.signals(J(o,1))),1)),n("serverLogs",o=>(le(o,this,i.serverLogs?i.serverLogs():[]),1)),n("serverLogContains",o=>{let a=i.serverLogContains;return u.lua_pushboolean(o,a?!!a(J(o,1)):!1),1}),u.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}};function Kt(e){let t=new xi(e);return t.boot(),t}var ct=Object.freeze(Array.from({length:8},(e,t)=>`Player${t+1}`)),_r=Object.freeze(Array.from({length:8},(e,t)=>`Avatar${t+1}`)),Go=Object.freeze(["Level","PlayerSelf","AvatarSelf"]);var Ar=Object.freeze([...Go,...ct,..._r]),zo=Object.freeze(["PlayerSelf","AllPlayers",...ct]),gl=Object.freeze(["Level","PlayerSelf",...ct]),To=Object.freeze(["Int","Float","String","Bool","Vector3","Entity","Guid","PrefabId","ConfigId","IntList","FloatList","StringList","BoolList","Vector3List","EntityList","GuidList","PrefabIdList","ConfigIdList","Dict","Struct"]),yl=-2147483648,bl=2147483647,vl=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 Xt(e){return`Player${Number(e)}`}function Ai(e){return`Avatar${Number(e)}`}function Mo(e){let t=String(e||"").match(/^(?:Player|Avatar)([1-8])$/);return t?Number(t[1]):0}function lt(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 Ge(e,t=8){let i=lt(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 ct)e[t]=Object.create(null);for(let t of _r)e[t]=Object.create(null);return e}function Vo(e){let t=String(e||"");if(!Ar.includes(t))throw new Error(`unknown CustomVariableEntityType: ${e}`);return t}function Sl(e,t){let i=Vo(e);if(!gl.includes(i))throw new Error(`${t}.entityType must be Level, PlayerSelf, or Player1-8`);return i}function Wt(e){let t=String(e??"");if(!t)throw new Error("custom variable name is required");return t}function Pi(e){let t=String(e??"");if(!t)throw new Error("signal name is required");return t}function Pr(e){let t=String(e||"PlayerSelf");if(!zo.includes(t))throw new Error(`unsupported client signal target: ${e}. use PlayerSelf, AllPlayers, or Player1-8`);return t}function jt(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=jt(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 Fo(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 Oo(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:jt(t),value:t}):[]}function wl(e){return String(e?.kind||e?.type||e?.name||e?.id||"")}function _i(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function Lo(e,t){if(!_i(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 $o(e,t){return Lo(e,t)||Se(e)}function Cl(e,t,i){if(!_i(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=Sl(e.entityType,n);if(!Object.prototype.hasOwnProperty.call(e,"value"))throw new Error(`${n}.value is required`);return{kind:r,entityType:o,name:Wt(e.name),value:$o(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:Pr(e.target),signalName:Pi(e.signalName),params:e.params.map((o,a)=>$o(o,`${n}.params[${a}]`))}}throw new Error(`${n}.kind must be setCustomVariable or sendClientScriptSignal`)}function qt(e){if(e==null)return{version:1,rules:[]};if(!_i(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(!_i(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:Pi(i.signalName),actions:i.actions.map((n,o)=>Cl(n,r,o))}})}}function Do(e,t,{typed:i=!1}={}){let r=Lo(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 Il(e){return e==="Level"?"Level":ct.includes(e)?"PlayerSelf":_r.includes(e)?"AvatarSelf":e}function Bo(e={}){let t=No(),i=No(),r=[],n=[],o=[],a=[],s=Array.from({length:9},()=>null),c=1,l=0,f=Number(e.onlineLatencyMs||0);(!Number.isFinite(f)||f<0)&&(f=0);let p=qt(e.logic),h=lt(e.playerCount),m=Ge(e.viewPlayerIndex,h);function y(b,E){a.push({source:"server",level:String(b||"engine"),text:String(E),time:l})}function v(b){let E=s[b||m],S=Number(E?.clock?.time);Number.isFinite(S)&&(l=S)}function x(b,E,S,k){t[b][E]=S,i[b][E]={type:k||jt(S)||i[b][E]?.type||""}}function I(b,E,S){return typeof S!="number"||!Number.isInteger(S)?{ok:!0,value:S}:S>=yl&&S<=bl?{ok:!0,value:S}:(y("engine",`Int custom variable ${b}.${E} out of range ${S}; keeping previous legal value`),{ok:!1,value:t[b][E]})}function A(b,E){let S=Vo(b),k=E||m;return S==="PlayerSelf"?Xt(k):S==="AvatarSelf"?Ai(k):S}function O(b,E){let S=Il(b);if(b==="Level"){for(let w=1;w<=h;w+=1){let M=s[w];M&&typeof M.notifyVarHandlers=="function"&&M.notifyVarHandlers("Level",E)}return}let k=Mo(b);if(!k)return;let $=s[k];$&&typeof $.notifyVarHandlers=="function"&&$.notifyVarHandlers(S,E)}function F(b,E){let S=Pr(b);return S==="AllPlayers"?Array.from({length:h},(k,$)=>$+1):S==="PlayerSelf"?[E||m]:[Mo(S)]}function U(b){for(let E of p.rules)if(E.signalName===b.name)for(let S of E.actions){if(S.kind==="setCustomVariable"){let k=Do(S.value,b);D.setVar(S.entityType,S.name,k,{type:S.variableType,playerIndex:b.playerIndex}),y("info",`logic ${E.id}: set ${S.entityType}.${S.name}`);continue}if(S.kind==="sendClientScriptSignal"){let k=S.params.map($=>Do($,b,{typed:!0}));D.sendToClient(S.signalName,k,{target:S.target,playerIndex:b.playerIndex}),y("info",`logic ${E.id}: sent ${S.signalName} to ${S.target}`)}}}function ee(b,E){b&&(b.serverBridge={getVar:(S,k)=>D.getVar(S,k,{playerIndex:E}),setVar:(S,k,$)=>D.setVar(S,k,$,{playerIndex:E}),receiveFromClient:(S,k)=>D.receiveFromClient(S,k,{playerIndex:E})})}function Z(b){b&&(b.serverBridge=null)}let D={ENTITY_TYPES:Go,ALL_ENTITY_TYPES:Ar,CLIENT_SIGNAL_TARGETS:zo,get clock(){return l},get playerCount(){return h},get viewPlayerIndex(){return m},setClock(b){l=Number(b)||0},setPlayerCount(b){return h=lt(b),m>h&&(m=h),h},setViewPlayerIndex(b){return m=Ge(b,h),m},log(b,E){y(b,E)},defineVar(b,E,S={},{playerIndex:k}={}){let $=A(b,k),w=Wt(E);if(Object.prototype.hasOwnProperty.call(t[$],w))throw new Error(`custom variable already exists: ${$}.${w}`);let M=S.type?String(S.type):jt(S.value??S.defaultValue);if(M&&!To.includes(M))throw new Error(`unsupported custom variable type: ${M}`);let z=S.value!==void 0?S.value:S.defaultValue!==void 0?S.defaultValue:null;return x($,w,z,M),D.getVar($,w)},getVar(b,E,{playerIndex:S}={}){let k=A(b,S),$=Wt(E);if(!Object.prototype.hasOwnProperty.call(t[k],$)){y("engine",`GetGlobalCustomVariableValue missing ${k}.${$}; returning nil (simulator policy)`);return}return t[k][$]},setVar(b,E,S,{notify:k=!0,type:$,playerIndex:w}={}){let M=A(b,w),z=Wt(E),Y=$||i[M][z]?.type||jt(S);if(Y&&!To.includes(Y)&&Y!=="")throw new Error(`unsupported custom variable type: ${Y}`);let ae=S;if(!((Y==="Int"||Y===""&&typeof S=="number"&&Number.isInteger(S))&&(ae=I(M,z,S).value,ae===void 0)))return x(M,z,ae,Y),k&&O(M,z),ae},listVars(b){let E=b?[A(b)]:["Level",...Array.from({length:h},(k,$)=>Xt($+1)),...Array.from({length:h},(k,$)=>Ai($+1))],S=[];for(let k of E)for(let $ of Object.keys(t[k]))S.push({entityType:k,name:$,type:i[k][$]?.type||"",value:Se(t[k][$])});return S},receiveFromClient(b,E=[],{playerIndex:S}={}){let k=Ge(S||m,h);v(k);let $=Pi(b),w={id:c++,direction:"inbound",name:$,params:Oo(E),values:Fo(E),time:l,playerIndex:k,from:Xt(k)};return r.push(w),U(w),w},sendToClient(b,E=[],{target:S="PlayerSelf",playerIndex:k}={}){let $=Pi(b),w=Pr(S),z=F(w,k||m),Y={id:c++,direction:"outbound",name:$,params:Oo(E),values:Fo(E),time:l,target:w,players:z,deliverAt:l+f/1e3,delivered:!1};return n.push(Y),f===0?D.deliver(Y):o.push(Y),Y},getLogic(){return Se(p)},setLogic(b){return p=qt(b),D.getLogic()},deliver(b){if(!b||b.delivered)return;b.delivered=!0;let E=Array.isArray(b.players)&&b.players.length?b.players:F(b.target);for(let S of E){let k=s[S];k&&typeof k.sendClientSignal=="function"&&k.sendClientSignal(b.name,b.values)}},flush(b){b!==void 0&&(l=Number(b)||0);let E=[];for(let S=o.length-1;S>=0;S-=1)o[S].deliverAt<=l&&E.push(o.splice(S,1)[0]);E.sort((S,k)=>S.id-k.id);for(let S of E)D.deliver(S);return E},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 E of b.nodes||[]){let S=wl(E);if(!vl.has(S))throw new Error(`unsupported server node: ${S||JSON.stringify(E)}. v1 only supports custom variables and signals`)}if(b.onlineLatencyMs!==void 0){let E=Number(b.onlineLatencyMs);if(!Number.isFinite(E)||E<0)throw new Error("onlineLatencyMs must be a non-negative finite number");f=E}b.playerCount!==void 0&&D.setPlayerCount(b.playerCount),b.viewPlayerIndex!==void 0&&D.setViewPlayerIndex(b.viewPlayerIndex),(b.logic!==void 0||b.serverLogic!==void 0)&&D.setLogic(b.logic??b.serverLogic);for(let E of b.vars||[]){let S=A(E.entityType),k=Wt(E.name);Object.prototype.hasOwnProperty.call(t[S],k)?D.setVar(S,k,E.value??E.defaultValue,{notify:!1,type:E.type}):D.defineVar(S,k,E)}}},attachRuntime(b,{playerIndex:E=1}={}){let S=Ge(E,8);return s[S]&&s[S]!==b&&Z(s[S]),s[S]=b||null,ee(s[S],S),D},attachRuntimes(b){D.detachRuntime();let E=Array.isArray(b)?b:[];for(let S=0;S<E.length&&S<8;S+=1)s[S+1]=E[S]||null,ee(s[S+1],S+1);return D},detachRuntime(){for(let b=1;b<=8;b+=1)Z(s[b]),s[b]=null},snapshot(){let b=Xt(m),E=Ai(m),S={Level:{},PlayerSelf:{},AvatarSelf:{}};for(let k of Object.keys(t.Level))S.Level[k]={type:i.Level[k]?.type||"",value:Se(t.Level[k])};for(let k of Object.keys(t[b]))S.PlayerSelf[k]={type:i[b][k]?.type||"",value:Se(t[b][k])};for(let k of Object.keys(t[E]))S.AvatarSelf[k]={type:i[E][k]?.type||"",value:Se(t[E][k])};for(let k=1;k<=h;k+=1){let $=Xt(k),w=Ai(k);S[$]={},S[w]={};for(let M of Object.keys(t[$]))S[$][M]={type:i[$][M]?.type||"",value:Se(t[$][M])};for(let M of Object.keys(t[w]))S[w][M]={type:i[w][M]?.type||"",value:Se(t[w][M])}}return{clock:l,onlineLatencyMs:f,playerCount:h,viewPlayerIndex:m,logic:D.getLogic(),vars:S,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:a.map(k=>({source:"server",level:k.level,text:k.text,time:k.time}))}},reset(){for(let b of Ar){for(let E of Object.keys(t[b]))delete t[b][E];for(let E of Object.keys(i[b]))delete i[b][E]}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 b of e.vars||[])D.defineVar(b.entityType,b.name,b);return D}var kl={container:"container",textbox:"textbox",image:"image",button:"button",cursor:"cursor",grid:"grid",reference:"reference",textwindow:"textwindow",keyhint:"keyhint",animation:"animation",fullscreen:"fullscreen"};function Rr(e,t,i=null){let r=Ue(e.transformByPlatform,t),n={authoringId:e.id,kind:kl[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=>Rr(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 Tr(e,t=[],i=""){let r=i&&X[i]?i:e.canvasId,n=X[r],o=Lt(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=>Rr(c,r,a)):[];return{canvasId:r,platform:n.platform,device:n.luaDevice,canvasWidth:n.width,canvasHeight:n.height,root:Rr(o,r,a),templates:s}}var Ri="qxqy-autotest";var ut=.03333333333333333,El=new Set(["pointer","key","click","pause","resume","serverSet","serverSend","view"]),xl=new Set(["log","control","var","signal","tree","lua"]);function Jt(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function Mr(e){return JSON.parse(JSON.stringify(e??null))}function Ti(e,t){if(!e||typeof e!="object")throw new Error(`events[${t}] must be an object`);let i=String(e.kind||e.do||"");if(!El.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=Jt(r.x,"pointer.x"),r.y=Jt(r.y,"pointer.y"),r.type=String(r.type||"click");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:Jt(e.t??0,"event.t"),source:String(e.source||"user"),kind:i,payload:r}}function Nr(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(!xl.has(i))throw new Error(`unsupported assert kind: ${i||"(empty)"}`);let r={kind:i};if(e.at!==void 0&&(r.at=Jt(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=Mr(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=Mr(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=Mr(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 Yo(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+=Jt(n.dt??ut,"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(Ti({...n,kind:n.do,t},i.length));continue}if(n.assert||n.check||n.kind){r.push(Nr({...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:ut}}function Zt(e){if(Array.isArray(e)){let r=Yo(e);return{format:Ri,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=Yo(e.queue||e.steps);return{format:Ri,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)=>Ti(r,n)),i=(e.asserts||[]).map((r,n)=>Nr(r,n));return t.sort((r,n)=>r.t-n.t||0),{format:Ri,version:1,name:String(e.name||""),dt:Number(e.dt)>0?Number(e.dt):ut,playerCount:Number(e.playerCount)>0?Number(e.playerCount):1,events:t,asserts:i}}function Uo(e,t={}){let i=(e||[]).map((r,n)=>Ti(r,n));return{format:Ri,version:1,name:String(t.name||""),dt:Number(t.dt)>0?Number(t.dt):ut,playerCount:Number(t.playerCount)>0?Number(t.playerCount):1,events:i,asserts:(t.asserts||[]).map((r,n)=>Nr(r,n))}}function Ho(e,t,i){if(!e)return null;let r=Ti({...t,t:t.t??i??0},e.events.length);return e.events.push(r),r}var Al=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 Dr(e){let t=ge({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),i=new Map;function r(n,o,a){let s=$e(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 Pl(e,t=Dr(e)){let i=new Map;function r(n,o){let a=t.get(n.Id);if(!a)return;let s=Vt(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,wt());return i}function Xo(e,t){let i=t.get(e.Id);return{id:e.Id,prefabId:e.prefabIndex,authoringId:e.authoringId,name:e.name,kind:e.kind,typeofName:e.typeofName,instantiated:!e.authoringId,active:!!e.active,visible:!!e.visible,activeInHierarchy:!!i?.activeInHierarchy,raycastTarget:e.raycastTarget!==!1,interactable:e.interactable!==!1,pressed:e.pressed===!0,anchoredPositionX:e.anchoredPositionX,anchoredPositionY:e.anchoredPositionY,sizeDeltaX:e.sizeDeltaX,sizeDeltaY:e.sizeDeltaY,localScaleX:e.localScaleX,localScaleY:e.localScaleY,localScaleZ:e.localScaleZ,localRotationZ:e.localRotationZ,text:e.kind==="textbox"||e.kind==="textwindow"?e.text??"":null,fontSize:e.kind==="textbox"||e.kind==="textwindow"?e.fontSize:null,fontColor:e.kind==="textbox"||e.kind==="textwindow"?e.fontColor:null,bgColor:e.kind==="textbox"||e.kind==="textwindow"?e.bgColor:null,enableOutline:e.kind==="textbox"||e.kind==="textwindow"?e.enableOutline===!0:null,outlineColor:e.kind==="textbox"||e.kind==="textwindow"?e.outlineColor:null,imageId:e.kind==="image"?e.imageId??0:null,primitive:e.kind==="image"?vt[e.imageId]||"missing":null,imageColor:e.kind==="image"?e.imageColor:null,enableMask:e.kind==="image"?e.enableMask===!0:null,enableSoftEdge:e.kind==="image"?e.enableSoftEdge===!0:null,softEdgeMode:e.kind==="image"?e.softEdgeMode:null,softEdgeWidthX:e.kind==="image"?e.softEdgeWidthX:null,softEdgeWidthY:e.kind==="image"?e.softEdgeWidthY:null,horizontalSoftRange:e.kind==="image"?e.horizontalSoftRange:null,verticalSoftRange:e.kind==="image"?e.verticalSoftRange:null,enableFill:e.kind==="image"?e.enableFill===!0:null,fillType:e.kind==="image"?e.fillType:null,fillHorizontalType:e.kind==="image"?e.fillHorizontalType:null,fillVerticalType:e.kind==="image"?e.fillVerticalType:null,fillRadial90Type:e.kind==="image"?e.fillRadial90Type:null,fillRadialType:e.kind==="image"?e.fillRadialType:null,reverseMaskArea:e.kind==="image"?e.reverseMaskArea===!0:null,fillAmount:e.kind==="image"?e.fillAmount:null,box:i?{left:i.left,bottom:i.bottom,width:i.width,height:i.height}:null,children:e.children.map(r=>Xo(r,t))}}function _l(){return{pointerDownControl:null,pointerDownPosition:null,pointerLastPosition:null,pointerDragging:!1,pointerHoverControl:null,hoveredControl:null,selectedControl:null,stateRestores:new Map,viewCache:null}}function Rl(e,t,i,r){let n=Kt({canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight,device:e.device,...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 Tl=["pointerDownControl","pointerDownPosition","pointerLastPosition","pointerDragging","pointerHoverControl","hoveredControl","selectedControl","stateRestores","viewCache"];function Ml(e){Object.defineProperty(e,"runtime",{configurable:!0,enumerable:!0,get(){return e.runtimes[e.viewPlayerIndex-1]}});for(let t of Tl)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 Wo(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 f=r||i,p=n||i,h=Tr(e,f,a),m=t?Tr(t,p,a):null,y=lt(s),v=Ge(c,y),x=Bo({playerCount:y,viewPlayerIndex:v});o&&x.loadConfig({...o,playerCount:y,viewPlayerIndex:v});let I=[];for(let F=0;F<y;F+=1)I.push(Rl(h,m,i,l));x.attachRuntimes(I);for(let F of I)F.addRoot(h.root);let A={runtimes:I,views:I.map(()=>_l()),playerCount:y,viewPlayerIndex:v,server:x,compiled:h,mountError:I.find(F=>F.mountErrors[0])?.mountErrors[0]||null,debugPaused:!1,history:{events:[]},recording:!0};Ml(A);let O=A.viewPlayerIndex;for(let F=1;F<=y;F+=1)A.viewPlayerIndex=F,Ul(A);return A.viewPlayerIndex=O,A}function Gr(e,t){if(!e)throw new Error("play session has not started");let i=Ge(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||Ho(e.history,{...t,source:t.source||"user"},e.runtime.clock.time)}function Nl(e){return e?.history?.events||[]}var zr=new Set(["image","textbox","textwindow","button"]);function Fl(e,t){let i=Qe(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 ft(e){return typeof e=="string"?e:e?.Name}function jo(e){return{fillType:ft(e.fillType),fillHorizontalType:ft(e.fillHorizontalType),fillVerticalType:ft(e.fillVerticalType),fillAmount:e.fillAmount}}function Ol(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};return e.kind==="image"&&(o.primitive=vt[e.imageId]||"missing",o.imageColor=e.imageColor,o.imageId=e.imageId,Object.assign(o,jo(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=ft(e.horizontalAlignment),o.verticalAlignment=ft(e.verticalAlignment)),o}function $l(e,t=Dr(e)){let i=[],r=Pl(e,t);function n(o){let a=t.get(o.Id);if(!a||o.visible===!1||!a.activeInHierarchy)return;let s=r.get(o.Id);if(!s)return;let c=Fl(a,s);zr.has(o.kind)&&i.push(Ol(o,a,c));let l=o.children||[];for(let f=l.length-1;f>=0;f-=1)n(l[f])}for(let o of e.runtime.roots)n(o);return i}function Dl(e,t){let i={kind:e.kind,name:e.name,sourceWidth:t.width,sourceHeight:t.height,pressed:e.pressed===!0};return e.kind==="image"&&(i.primitive=vt[e.imageId]||"missing",i.imageColor=e.imageColor,i.imageId=e.imageId,Object.assign(i,jo(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=ft(e.horizontalAlignment),i.verticalAlignment=ft(e.verticalAlignment)),i}function Gl(e,t,i){let r=Zi(e,t),n=Qe(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 qo(e){let t=e.matrix;return[e.parent,e.z,e.group?1:0,t.a,t.b,t.c,t.d,t.tx,t.ty,e.kind,e.name,e.sourceWidth,e.sourceHeight,e.pressed,e.primitive,e.imageColor,e.imageId,e.fillType,e.fillHorizontalType,e.fillVerticalType,e.fillAmount,e.text,e.fontSize,e.fontColor,e.bgColor,e.enableOutline,e.outlineColor,e.horizontalAlignment,e.verticalAlignment].join(" ")}function Jo(e,t,i,r,n,o){return{id:e.Id,parent:t,z:n,group:o>=16,matrix:Gl(r,e,i),...Dl(e,r)}}function zl(e){let t=ge({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),i=new Set,r=new Map,n=new Map;function o(c,l,f){let p=$e(l,c);if(p.activeInHierarchy=f&&c.active!==!1,n.set(c.Id,p),c.visible===!1||!p.activeInHierarchy)return!1;let h=c.children||[],m=zr.has(c.kind),y=0;for(let v=0;v<h.length;v+=1)o(h[v],p,p.activeInHierarchy)&&(m=!0,y+=1);return m?(i.add(c.Id),r.set(c.Id,y),!0):!1}function a(c,l,f,p){if(!i.has(c.Id))return;let h=n.get(c.Id);s.push(Jo(c,l,f,h,p,r.get(c.Id)||0));let m=c.children||[];for(let y=0;y<m.length;y+=1)a(m[y],c.Id,h,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 $r(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)$r(i[r])}function Vl(e,t){let i=ge({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 f=a[l];t.fingerprints.has(f)&&(n.push(f),t.fingerprints.delete(f),t.childCounts.delete(f),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 f=l.children;for(let p=0;p<f.length;p+=1)s(f[p])}function c(l,f,p,h,m,y){let v=y||l._playDeepDirty===!0,x=v||l._playDirty===!0,I=v||l._playChildDirty===!0;if(!x&&!I)return;if(!(m&&l.active!==!1)||l.visible===!1){s(l);return}let O=$e(f,l),F=t.childCounts.get(l.Id)||0;if(I){F=0;let E=l.children;for(let S=0;S<E.length;S+=1)c(E[S],O,l.Id,S,!0,v),t.fingerprints.has(E[S].Id)&&(F+=1)}if(!(zr.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 ee=t.childCounts.get(l.Id);t.childCounts.set(l.Id,F);let Z=F>=16!=(ee||0)>=16;if(!x&&!Z&&t.fingerprints.has(l.Id))return;let D=Jo(l,p,f===i?null:f,O,h,F),b=qo(D);t.fingerprints.get(D.id)!==b&&(t.fingerprints.has(D.id)||(o+=1),t.fingerprints.set(D.id,b),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 Ll(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}=zl(e);i.rev+=1,i.fingerprints=new Map(c.map(f=>[f.id,qo(f)])),i.childCounts=l,i.count=c.length;for(let f of e.runtime.roots)$r(f);return{format:"tree-v1",revision:i.rev,reset:!0,count:c.length,nodes:c}}let{changed:o,removed:a,count:s}=Vl(e,i);i.rev+=1;for(let c of e.runtime.roots)$r(c);return{format:"tree-v1",revision:i.rev,reset:!1,count:s,changed:o,removed:a}}function Vr(e,{inspect:t=!1,view:i=!1,paint:r=!1,sceneRev:n,compact:o=!1}={}){let a=e.runtime,s=e.compiled,[c,l]=[a.canvasWidth,a.canvasHeight];e.server&&e.server.setClock(a.clock.time);let f=o?a.logs.slice(-100):a.logs,p=Nl(e),h=e.server?e.server.snapshot():{vars:{},inbound:[],outbound:[],logs:[]};o&&(h.inbound=h.inbound.slice(-100),h.outbound=h.outbound.slice(-100),h.logs=h.logs.slice(-100));let m={canvasId:s.canvasId,platform:s.platform,device:a.device,canvasWidth:c,canvasHeight:l,canvasPresets:Al,playerCount:e.playerCount||1,viewPlayerIndex:e.viewPlayerIndex||1,players:Array.from({length:e.playerCount||1},(y,v)=>({index:v+1,label:`\u73A9\u5BB6${v+1}`,entityType:`Player${v+1}`})),time:a.clock.time,frame:a.clock.frame,paused:!!e.debugPaused,levelTimePaused:!!a.clock.paused,mountError:e.mountError||a.mountErrors[0]||null,logs:f.map(y=>({source:"client",level:y.level,text:y.text,time:y.time})),tree:[],paint:[],scene:null,server:h,history:(o?p.slice(-100):p).map(y=>({t:y.t,source:y.source||"user",kind:y.kind,payload:y.payload||{}}))};if(t||r){let y=Dr(e);t&&(m.tree=a.roots.map(v=>Xo(v,y))),r&&(m.paint=$l(e,y))}return i&&(m.scene=Ll(e,n)),St(m),m}function Mi(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 Lr(e,t){qe(e,{kind:"key",payload:{typeName:String(t)}}),e.runtime.injectKey(t)}function Bl(e,t){let i=null;for(let r of e.runtime.roots)Ne(r,n=>{!i&&n.name===t&&(i=n)});return i}function Br(e,t){qe(e,{kind:"click",payload:{name:String(t)}});let i=Bl(e,t);i&&Yr(i)&&(i.kind==="button"||i.kind==="cursor")&&i.SimulateCursorClick()}function Yl(e,t){return!e||!t?null:e.children.find(i=>i.authoringId===t||i.Id===t)||null}var Zo={unavailable:"unavailableChildId",hover:"hoverChildId",pressed:"pressedChildId",selected:"selectedChildId"};function Qo(e,t){let i=[];for(let[r,n]of Object.entries(Zo)){let o=t[n]?Yl(t,t[n]):null;o&&i.push({state:r,child:o})}return i}function Ul(e){for(let t of e.runtime.roots)Ne(t,i=>{if(i.kind==="button"){for(let{child:r}of Qo(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);ei(e,i)}})}function ei(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 Qo(e,t))r.child.active=!0,r.child.visible=r.state===i,typeof r.child.markPlayDirty=="function"&&r.child.markPlayDirty(!0)}function Fr(e){if(!e)return null;let t=e.parent;return t?.kind==="button"&&Object.values(Zo).map(r=>t[r]).filter(Boolean).includes(e.authoringId)?t:e}function Yr(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 ea(e){return e.kind==="container"||e.kind==="grid"||e.kind==="textwindow"||e.kind==="reference"||e.kind==="button"}function ta(e,t){let i=e.Id,r=t.get(i);if(r!==void 0)return r;let n=Yr(e);if(!n&&ea(e)){let o=e.children;for(let a=0;a<o.length;a+=1)if(ta(o[a],t)){n=!0;break}}return t.set(i,n),n}function Or(e,t,i){let r=ge({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),n=new Map;function o(s,c,l,f){if(!f||s.active===!1||s.visible===!1||!ta(s,n))return null;let p=$e(c,s),h=Vt(l,p,s),m=di(h);if(!m)return null;let y=Qe(m,t,i);if(y.x<p.left||y.x>p.right||y.y<p.bottom||y.y>p.top)return null;if(ea(s))for(let v=0;v<s.children.length;v+=1){let x=o(s.children[v],p,h,!0);if(x)return x}return Yr(s)?s:null}let a=wt();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 Qt(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 Ko(e,t,i){t.pressed=i,typeof t.markPlayDirty=="function"&&t.markPlayDirty(),ei(e,t)}function ti(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");if(e.runtime.cursor.x=o,e.runtime.cursor.y=a,n.silent||qe(e,{kind:"pointer",payload:{type:t,x:o,y:a}}),t==="move"){let s=e.pointerLastPosition||{x:o,y:a},c=e.pointerHoverControl,l=Fr(Or(e,o,a)),f=Qt(e,o,a,{previous:s});c&&c!==l&&e.runtime.injectCursor(c,"CursorExit",f),l&&c!==l&&e.runtime.injectCursor(l,"CursorEnter",f),e.pointerHoverControl=l;let p=e.hoveredControl;e.hoveredControl=l?.kind==="button"?l:null,p&&p!==e.hoveredControl&&ei(e,p),e.hoveredControl&&ei(e,e.hoveredControl);let h=e.pointerDownControl;if(h){let m=e.pointerDownPosition||s,y=o!==s.x||a!==s.y;!e.pointerDragging&&y&&(e.runtime.injectCursor(h,"CursorBeginDrag",Qt(e,o,a,{press:m,previous:s,dragging:!1})),e.pointerDragging=!0),e.pointerDragging&&e.runtime.injectCursor(h,"CursorDrag",Qt(e,o,a,{press:m,previous:s,dragging:!0}))}return e.pointerLastPosition={x:o,y:a},l}if(t==="down"){let s=Fr(Or(e,o,a));return e.pointerDownControl=s,e.pointerDownPosition={x:o,y:a},e.pointerLastPosition={x:o,y:a},e.pointerDragging=!1,s&&(Ko(e,s,!0),e.runtime.injectCursor(s,"CursorDown",Qt(e,o,a))),s}if(t==="up"){let s=e.pointerDownControl,c=Fr(Or(e,o,a));if(s){let l=Qt(e,o,a,{press:e.pointerDownPosition,previous:e.pointerLastPosition,dragging:e.pointerDragging});if(e.runtime.injectCursor(s,"CursorUp",l),e.pointerDragging)e.runtime.injectCursor(s,"CursorEndDrag",l);else if(c===s){e.runtime.injectCursor(s,"CursorClick",l);let f=e.selectedControl;e.selectedControl=s.kind==="button"?s:null,f&&f!==e.selectedControl&&ei(e,f)}Ko(e,s,!1)}return e.pointerDownControl=null,e.pointerDownPosition=null,e.pointerLastPosition={x:o,y:a},e.pointerDragging=!1,c}if(t==="click")return ti(e,"down",o,a,{silent:!0}),ti(e,"up",o,a,{silent:!0});throw new Error(`unknown pointer type ${t}`)}function Ur(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 ia(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 Hr(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 Ni(e){return{snapshot:t=>Vr(e,t),step:t=>Mi(e,t),pointer:(t,i,r)=>ti(e,t,i,r),key:t=>Lr(e,t),click:t=>Br(e,t),view:t=>Gr(e,t),pause:()=>{qe(e,{kind:"pause",payload:{}}),e.debugPaused=!0},resume:()=>{qe(e,{kind:"resume",payload:{}}),e.debugPaused=!1},serverSet:(t,i,r)=>Ur(e,t,i,r),serverSend:(t,i,r)=>Hr(e,t,i,r)}}function Kr(e){e?.server&&e.server.destroy();let t=e?.runtimes||(e?.runtime?[e.runtime]:[]);for(let i of t)i.destroy()}function Xr(e,t){return JSON.stringify(e)===JSON.stringify(t)}function ra(e,t){for(let i of e||[])t(i),i.children?.length&&ra(i.children,t)}function Wr(e,{id:t,name:i}){let r=null;return ra(e,n=>{r||(t&&String(n.id)===String(t)||!t&&i&&n.name===i)&&(r=n)}),r}function Hl(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 Kl(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=Wr(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 Xl(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=Wr(t.tree,e);if(!i)return{ok:!1,actual:null,expected:e.equals,message:`control not found: ${e.id||e.name}`};let r=Hl(i,e.field);return Xr(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 Xr(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||Xr(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=!!Wr(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 Wl(e,t){let i=Kt();try{return i.evalQueryScript(e,Kl(t)),{ok:!0,actual:!0}}catch(r){return{ok:!1,message:r?.message||String(r)}}finally{i.destroy()}}function na(e,t){return e.kind==="lua"?Wl(e.source,t):Xl(e,t)}function jl(e,t){let i=t>0?t:ut;return Math.round((e+i)*1e9)/1e9}function ql(e,t){let i=t.payload||{};if(t.kind==="pointer")e.pointer(i.type,i.x,i.y);else if(t.kind==="key")e.key(i.typeName);else if(t.kind==="click")e.click(i.name);else if(t.kind==="pause")e.pause();else if(t.kind==="resume")e.resume();else if(t.kind==="serverSet")e.serverSet(i.entityType,i.name,i.value);else if(t.kind==="serverSend")e.serverSend(i.name,i.params,i.target);else if(t.kind==="view")e.view(i.playerIndex);else throw new Error(`unsupported event kind: ${t.kind}`)}function Jl(e,t){let i=na(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 oa(e,t){let i=Zt(t),r=i.events.slice().sort((I,A)=>I.t-A.t),n=i.asserts.slice(),o=i.dt||ut,a=r.reduce((I,A)=>Math.max(I,A.t),0),s=n.reduce((I,A)=>Math.max(I,Number(A.at||0)),0),c=Math.max(a,s),l=0,f=[],p=0,h=n.some(I=>I.kind==="control"||I.kind==="tree"||I.kind==="lua"),m=e.snapshot({inspect:h}),y=()=>{for(;l<r.length&&r[l].t<=p+1e-9;)ql(e,r[l]),l+=1,m=e.snapshot({inspect:h})},v=()=>{for(let I of n)if(!I._done&&Number(I.at||0)<=p+1e-9){let A=Jl(I,m);if(f.push(A),I._done=!0,!A.ok)return{passed:!1,failedAt:p,frame:m.frame||0,results:f,snapshot:m}}return null};y();let x=v();if(x)return jr(i,x);for(;p+1e-9<c;){e.step(o),p=jl(p,o),m=e.snapshot({inspect:h}),y();let I=v();if(I)return jr(i,I)}return jr(i,{passed:f.every(I=>I.ok),failedAt:null,frame:m.frame||0,results:f,snapshot:m})}function jr(e,t){return G({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 qr(e){return Array.isArray(e)?e.slice():[]}var rc={Level:"\u5173\u5361",PlayerSelf:"\u5F53\u524D\u73A9\u5BB6",AvatarSelf:"\u5F53\u524D\u89D2\u8272",...Object.fromEntries(ct.map((e,t)=>[e,`\u73A9\u5BB6${t+1}`])),...Object.fromEntries(Array.from({length:8},(e,t)=>[`Avatar${t+1}`,`\u89D2\u8272${t+1}`]))};function nc(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(G({entityType:s,entityLabel:rc[s]||s,name:l,type:c[l]?.type||"",value:c[l]?.value??null}))}return r}var ht="qxqy-simulator-save",oc="qxqy-simulator-scripts",ne="server-control-template",B="client-control-template",Jr={[ne]:"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F",[B]:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"};function dt(e){return e===B?"client":"server"}function Fi(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 Zr(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)||![ne,B].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:Fi(i.oldGuid),newGuid:Fi(i.newGuid)}})}function ac(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 Oi(e){let t=String(e?.controlAsset||""),i=ac(e);return{id:String(i||e?.id||""),guid:i,path:String(e?.path||""),source:String(e?.source||""),controlId:String(e?.controlId||""),controlAsset:t===B||t==="client"?B:t===ne||t==="server"?ne:""}}function sc(e){let t=[],i=(r,n="")=>{if(r&&(r.path||r.source)){let o=Oi(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(Oi(r));return t}if(i(e?.assets?.server?.script,ne),i(e?.assets?.client?.script,B),e&&e.format!==ht){i(e?.script);for(let r of e?.scripts||[])i(r)}return t}function Qr(e){return Xe(e===B?It():nt())}var lc="\u672A\u7ED1\u5B9A",At="\u672A\u547D\u540D\u5B58\u6863",cc="\u672A\u547D\u540D\u754C\u9762";function uc(e){let t=e;for(let i=0;i<8;i++){if(ii(aa(t,"simulator","studio"))&&ii(aa(t,"lua")))return t;let r=tc(t);if(r===t)break;t=r}return e}function fc(e){return e?{name:Pt(e),path:e,bound:!0}:{name:lc,path:"",bound:!1}}function dc(e,t=process.cwd()){if(ic(e)&&ii(e))return e;let i=t||process.cwd(),r=uc(i),n=sa(r,e);if(ii(n))return n;let o=sa(i,e);if(ii(o))return o;throw new Error("script file not found: "+e)}function en(e,t={}){e?.format===ht&&gr(e.version);let i=[],r=typeof t.workspacePath=="string"&&t.workspacePath?t.workspacePath:"",n=e?.format===ht&&e.assets,o=Zr(e?.controlGuidChanges),a=Gt(e?.scriptSync),s=n?null:Xe(e,{warnings:i}),c={server:n&&e.assets.server?Xe(e.assets.server,{warnings:i}):Qr(ne),client:n&&e.assets.client?Xe(e.assets.client,{warnings:i}):Qr(B)};s&&(c[dt(s.meta.assetType)]=s);let l=n&&e.activeAssetType===B?B:s?.meta.assetType||ne,f=n&&e.meta?.name?String(e.meta.name):"",p=()=>f||At;!e?.meta?.name&&c.server.meta.name==="\u672A\u547D\u540D\u754C\u9762\u63A7\u4EF6\u7EC4"&&(c.server.meta.name=cc);let h=[],m=new Set;function y(){m.clear(),Ct(c.server.root,m),Ct(c.client.root,m,{skipServerContainer:!0});for(let d of h)ke(d.guid)&&m.add(Number(d.guid))}function v(d=0){y();let g=ke(d)&&!m.has(Number(d))?Number(d):Be(m);return m.add(g),g}function x(d){let g=Oi(d),C=v(g.guid);return{...g,guid:C,id:String(C)}}Ve(sc(e));let I=qt(e?.serverLogic),A=null,O="",F=1,U=1;function ee(d){let g=String(d||"").trim();if(!g)return"";if(!X[g])throw new Error(`unknown canvas preset: ${g} (available: ${Object.keys(X).join(", ")})`);return g}let Z=()=>c[dt(l)];function D(d){if(!d)return null;for(let[g,C]of[["server",c.server],["client",c.client]]){let P=ue(C.root,d);if(P&&P.kind!=="server-container")return{key:g,node:P}}return null}function b(d){if(!d.controlId)return null;let g=d.controlAsset===B?"client":d.controlAsset===ne?"server":null;if(g){let C=ue(c[g].root,d.controlId);return C&&C.kind!=="server-container"?{key:g,node:C}:null}return D(d.controlId)}function E(){for(let d of h)d.controlId&&!b(d)&&(d.controlId="",d.controlAsset="")}function S(d){if(!ke(d))return null;for(let[g,C]of[[ne,c.server],[B,c.client]]){let P="";if(q(C.root,T=>{!P&&(T.scriptMappingIds||[]).includes(Number(d))&&(P=T.id)}),P)return{controlId:P,controlAsset:g}}return null}function k(d,g,C){let P=c[dt(d.controlAsset)],T=P&&ue(P.root,d.controlId);T&&(T.scriptMappingIds=(T.scriptMappingIds||[]).map(N=>Number(N)===Number(g)?Number(C):N))}E();function $(){return h.map(d=>{let g=b(d),C=g?g.key==="client"?B:ne:"";return G({id:d.id,guid:d.guid||0,path:d.path||"",source:d.source||"",controlId:d.controlId||"",controlAsset:d.controlAsset||C,controlName:g?.node.name||"",assetType:C,assetLabel:g?Jr[C]:"",mounted:!!g})})}function w(){let d=[],g=(C,P)=>{q(C.root,T=>{T.kind!=="server-container"&&d.push(G({id:T.id,name:T.name,kind:T.kind,assetType:P,assetLabel:Jr[P]}))})};return g(c.server,ne),g(c.client,B),d}function M(d){let g=[];return q(d.root,C=>{C.kind!=="server-container"&&g.push(JSON.stringify({kind:C.kind,guid:C.guid,name:C.name,text:C.text??null,imageId:C.imageId??null,fontSize:C.fontSize??null,fontColor:C.fontColor??null,bgColor:C.bgColor??null,imageColor:C.imageColor??null,fillType:C.fillType??null,fillAmount:C.fillAmount??null,syncAllDevices:C.syncAllDevices!==!1,transformByPlatform:C.transformByPlatform||null}))}),g.join("/")}let z=M(It()),Y=M(nt());function ae(d){let g=M(d);return d.meta?.assetType===B?g===z:g===Y}function K(d,g){return String(d||"").replace(/[\\/:*?"<>|]/g,"-").trim()||g}function de(d){let g=K(p(),At),C=d.meta?.assetType===B?"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F";return`${g} \xB7 ${C}`}function Je(){if(!((c.server.root.children||[]).find(g=>g.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 Zn(c.server,c.client,{scripts:h,fileName:`${K(p(),At)} \xB7 \u6574\u5408\u5305.gia`})}function gt(){let d=g=>({type:g.meta.assetType,name:g.meta.name,sourceFile:g.meta.sourceFile||""});return{format:ht,name:p(),activeAssetType:l,assets:{server:d(c.server),client:d(c.client),scripts:$()}}}function Tt(){return G({format:ht,version:4,meta:{name:p()},activeAssetType:l,serverLogic:I,controlGuidChanges:o,scriptSync:a,assets:{server:c.server,client:c.client,scripts:h.map(d=>G({id:d.id,guid:d.guid||0,path:d.path||"",source:d.source||"",controlId:d.controlId||"",controlAsset:d.controlAsset||""}))}})}function te(){let d=Z(),g=go(d);return g.workspace=fc(r),g.save=gt(),g.scripts=$(),g.mountTargets=w(),g.serverLogic=I,g.migrationWarnings=[...i],g.controlGuidChanges=G(o),g.scriptSync=G(a),wn(g),g}function Ae(d){let g=Z();if(d.expectedRevision!==void 0&&Number(d.expectedRevision)!==g.version)throw new Error(`revision conflict: expected ${d.expectedRevision}, current ${g.version}`);return g}function Ze(d,g,C=""){let P=String(g||"");if(P){let T=C===B?B:C===ne?ne:"";if(!b({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");d.controlAsset=T}else d.controlAsset="";d.controlId=P}function ai(d){let g=Ae(d);if(d.op==="addScript"){let C=x({path:String(d.path||""),source:String(d.source||""),controlId:"",controlAsset:""});d.controlId!==void 0&&d.controlId!==""&&Ze(C,d.controlId,d.controlAsset),h.push(C)}else if(d.op==="updateScript"){let C=h.find(P=>P.id===d.id);if(!C)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${d.id}`);d.controlId!==void 0&&Ze(C,d.controlId,d.controlAsset),d.path!==void 0&&(C.path=String(d.path)),d.source!==void 0&&(C.source=String(d.source))}else if(d.op==="removeScript"){let C=h.length;if(h=h.filter(P=>P.id!==d.id),h.length===C)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${d.id}`)}return g.version+=1,te()}function si(d){let g=Ae(d),C=ue(g.root,d.id??g.selectedId);if(!C||C.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=Fi(d.guid),T=Fi(C.guid);if(P===T)return te();let N=[];for(let L of Object.values(c))q(L.root,re=>{L===c.client&&re.kind==="server-container"||N.push({node:re,project:L})});if(N.some(L=>L.node!==C&&Number(L.node.guid)===P)||h.some(L=>Number(L.guid)===P))throw new Error(`\u63A7\u4EF6\u7D22\u5F15 ${P} \u5DF2\u88AB\u5176\u4ED6\u63A7\u4EF6\u6216\u811A\u672C\u5360\u7528`);let V=[],j=(L,re,Re)=>{let Q=L?.[re];(typeof Q=="number"||typeof Q=="string"&&/^\d+$/.test(Q.trim()))&&Number(Q)===T&&V.push({owner:L,key:re,project:Re.project})};for(let L of N)j(L.node,"referencedPrefabId",L),j(L.node,"itemPrefabId",L),j(L.node.giaRaw,"templateRefSlot",L);if(V.length&&N.filter(L=>Number(L.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 _e={id:ec(),controlAsset:l,controlId:C.id,controlName:C.name,oldGuid:T,newGuid:P};C.guid=P;let he=new Set([g]);for(let{owner:L,key:re,project:Re}of V)L[re]=typeof L[re]=="string"?String(P):P,he.add(Re);o.push(_e);for(let L of he)L.version+=1;return te()}function ie(d){let g=Ae(d);if(!Array.isArray(d.changeIds)||!d.changeIds.length||d.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 C=new Set(d.changeIds);return o=o.filter(P=>!C.has(P.id)),g.version+=1,te()}function Pe(d){if(!d||typeof d!="object")throw new Error("patch requires op");if(d.op==="setScriptSync"){let g=Ae(d);return a=Gt(d.config),g.version+=1,te()}if(d.op==="setControlGuid")return si(d);if(d.op==="acknowledgeControlGuidChanges")return ie(d);if(d.op==="setServerLogic"){let g=Ae(d);return I=qt(d.logic),g.version+=1,te()}if(d.op==="addScript"||d.op==="updateScript"||d.op==="removeScript")return ai(d);if(d.op==="selectAsset")return l=d.assetType===B?B:ne,te();if(d.op==="renameSave"){let g=String(d.name||"").trim();if(!g)throw new Error("\u5B58\u6863\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");return f=g,te()}if(d.op==="newAsset"){let g=Ae(d);l=d.assetType===B?B:ne;let C=Qr(l);return C.version=g.version+1,c[dt(l)]=C,o=o.filter(P=>P.controlAsset!==l),E(),te()}return vr(Z(),d),E(),te()}function Oe(d){return h.filter(g=>{let C=b(g);return!!(C&&C.key==="client"==(d===B))})}function Mt(d="json",g=""){let C=Nt(d,g);if(o.length&&!["save","archive"].includes(String(d).toLowerCase())){let P=o.map(T=>`\u63A7\u4EF6\u7D22\u5F15\u5F85\u6838\u5BF9 Lua \u5F15\u7528\uFF1A${Jr[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`);C.warnings=[...new Set([...C.warnings||[],...P])]}return C}function Nt(d="json",g=""){let C=String(d).toLowerCase();if(C==="save"||C==="archive"){let N=Buffer.from(JSON.stringify(Tt(),null,2),"utf8");return G({filename:`${p().replace(/[\\/:*?"<>|]/g,"-")} \xB7 \u8D44\u4EA7\u5305.json`,mimeType:"application/json",encoding:"base64",data:N.toString("base64"),warnings:[]})}if(C==="save-gia"||C==="archive-gia"){let N=[],V=[],j=(he,L="")=>{let re=Mt(he,L);N.push(G({filename:re.filename,mimeType:re.mimeType,encoding:re.encoding,data:re.data,warnings:re.warnings||[]})),V.push(...re.warnings||[])},_e=(he,L)=>{let re=c[dt(he)],Re=he===l,Q=h.some(ve=>ve.controlAsset===he&&ve.controlId);if(!Re&&ae(re)&&!Q){V.push(L);return}j("gia",he)};if(_e(ne,"\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"),_e(B,"\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(he=>he.path||he.source)&&j("scripts-gia"),!N.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 G({format:"qxqy-gia-package",files:N,warnings:[...new Set(V)]})}if(C==="gia-combined"||C==="combined-gia"||C==="combined"){let N=Je();return G({filename:`${K(p(),At)} \xB7 \u6574\u5408\u5305.gia`,mimeType:"application/octet-stream",encoding:"base64",data:N.buffer.toString("base64"),warnings:[...new Set(N.warnings||[])]})}if(C==="scripts"){let N=G({format:oc,version:1,scripts:h.map(j=>G({id:j.id,guid:j.guid||0,path:j.path||"",source:j.source||"",controlId:j.controlId||"",controlAsset:j.controlAsset||""}))}),V=Buffer.from(JSON.stringify(N,null,2),"utf8");return G({filename:`${K(p(),At)} \xB7 \u811A\u672C.json`,mimeType:"application/json",encoding:"base64",data:V.toString("base64"),warnings:[]})}if(C==="scripts-gia"||C==="scriptsgia"){let N=io(h);return G({filename:`${K(p(),At)} \xB7 \u811A\u672C.gia`,mimeType:"application/octet-stream",encoding:"base64",data:N.buffer.toString("base64"),warnings:N.warnings})}if(C==="lua"){let N=h.find(j=>j.id===g)||h.find(j=>j.path===g);if(!N)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=Pt(N.path||"")||`qxqy-script-${N.id}`;return G({filename:/\.lua$/i.test(V)?V:`${V}.lua`,mimeType:"text/x-lua",encoding:"base64",data:Buffer.from(N.source||"","utf8").toString("base64"),warnings:[]})}let P=g?c[dt(g)]:Z(),T=de(P);if(C==="json"){let N=G({...P,scripts:Oe(P.meta.assetType),controlGuidChanges:o.filter(j=>j.controlAsset===P.meta.assetType)}),V=Buffer.from(JSON.stringify(N,null,2),"utf8");return G({filename:`${T}.json`,mimeType:"application/json",encoding:"base64",data:V.toString("base64"),warnings:[]})}if(C==="gia"){let N=Jn(P,P.meta.assetType===B?{scripts:Oe(B)}:{}),V=P.meta.assetType===B?[]:Oe(ne);return V.length&&N.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`),G({filename:`${T}.gia`,mimeType:"application/octet-stream",encoding:"base64",data:N.buffer.toString("base64"),warnings:N.warnings})}throw new Error(`unsupported export format: ${d}`)}function Ve(d){for(let g of d){let C=Oi(g);if(!C.path&&!C.source)continue;let P=C.controlId?null:S(C.guid),T=x(P?{...C,...P}:C);P&&T.guid!==C.guid&&k(P,C.guid,T.guid),T.controlId&&!b(T)&&(T.controlId="",T.controlAsset=""),h.push(T)}}function Ft(d,g,C=""){let P=String(d||"").toLowerCase();if(typeof g!="string"||!g)throw new Error("import data is required");let T=Buffer.from(g,"base64"),N,V=[],j={};if(P==="json"){try{N=JSON.parse(T.toString("utf8"))}catch{throw new Error("JSON \u6587\u4EF6\u65E0\u6548")}if(N?.project&&(N=N.project),N?.format===ht&&N?.assets){gr(N.version);let Q=en(N);V.push(...Q.get().migrationWarnings);let ve=Q.archiveData();return c.server=ve.assets.server,c.client=ve.assets.client,i=[...V],l=N.activeAssetType===B?B:ne,f=String(N.meta?.name||Pt(C).replace(/\.json$/i,"")||f),I=ve.serverLogic,h=ve.assets.scripts,o=ve.controlGuidChanges,a=ve.scriptSync,m.clear(),G({snapshot:te(),warnings:V,metadata:{format:ht}})}}else{if(P==="lua")return h.push(x({path:Pt(C||"imported.lua"),source:T.toString("utf8"),controlId:""})),G({snapshot:te(),warnings:V,metadata:{assetType:"lua-script"}});if(P==="gia"){if(ro(T)){let we=oo(T);return Ve(we.scripts),G({snapshot:te(),warnings:we.warnings,metadata:we.metadata})}let Q=ao(T);N=Q.project,V=Q.warnings,j=Q.metadata,Q.clientProject&&(c.client=Xe(Q.clientProject),o=o.filter(we=>we.controlAsset!==B),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,hn=(we,as)=>{we&&q(we.root,pn=>{for(let Ji of pn.scriptMappingIds||[]){let mn=ve.get(Number(Ji));if(mn){V.push(`\u811A\u672C GUID ${Ji} \u540C\u65F6\u6302\u8F7D\u5230\u591A\u4E2A\u63A7\u4EF6\uFF0C\u5DF2\u4FDD\u7559\u201C${mn.controlAsset===ne?"\u670D\u52A1\u7AEF":"\u5BA2\u6237\u7AEF"}\u201D\u76EE\u6807\u3002`);continue}ve.set(Number(Ji),{controlId:pn.id,controlAsset:as})}})};hn(Q.project,ne),hn(Q.clientProject,B),Ve((Q.scripts||[]).map(we=>ve.has(Number(we.guid))?{...we,...ve.get(Number(we.guid))}:we))}else throw new Error(`unsupported import format: ${d}`)}let _e=Xe(N,{warnings:V}),he=Zr(N?.controlGuidChanges);if(he.some(Q=>Q.controlAsset!==_e.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 L=Zr([...o.filter(Q=>Q.controlAsset!==_e.meta.assetType),...he]);i=[...V];let re=dt(_e.meta.assetType);c[re]=_e,o=L,l=_e.meta.assetType;let Re=c[re];return C&&(Re.meta.name=Pt(C).replace(/\.(json|gia)$/i,"")||Re.meta.name,Re.meta.sourceFile=Pt(C),Re.meta.sourceFormat=P),Ve(N?.scripts||[]),N?.script&&(N.script.path||N.script.source)&&Ve([N.script]),G({snapshot:te(),warnings:V,metadata:j})}function Va(d,g){return vr(Z(),{op:"pick",x:d,y:g}),te()}function La(d){let g=typeof d=="string"&&d?d:"";!g||g===r||(r=g)}function Ba(d){let g=d.source||"";if(!g.trim()&&d.path.trim())try{g=Ql(dc(d.path,r),"utf8")}catch(C){throw new Error(`\u811A\u672C ${d.path} \u8BFB\u53D6\u5931\u8D25: ${C?.message||C}`)}return g}function Ot(d={}){let g=ee(d.canvasId);g&&(O=g),d.playerCount!==void 0&&d.playerCount!==null&&d.playerCount!==""&&(F=lt(d.playerCount),U>F&&(U=1)),d.viewPlayerIndex!==void 0&&d.viewPlayerIndex!==null&&d.viewPlayerIndex!==""&&(U=Ge(d.viewPlayerIndex,F)),A&&Kr(A);let C=h.map(T=>{try{return{id:T.id,guid:T.guid||0,path:T.path||T.id,source:Ba(T),controlId:T.controlId||"",controlAsset:T.controlAsset||""}}catch(N){return{id:T.id,guid:T.guid||0,path:T.path||T.id,source:`error([==[ ${String(N.message).replace(/]=+]/g,"] =]")} ])`,controlId:T.controlId||"",controlAsset:T.controlAsset||""}}}),P=T=>C.filter(N=>{let V={controlId:N.controlId,controlAsset:N.controlAsset},j=N.controlId?b(V):null;return!!(j&&j.key===T)});return A=Wo(c.server,{templatesProject:c.client,scripts:C,sceneScripts:P("server"),templateScripts:P("client"),serverConfig:{logic:I},canvasId:O,playerCount:F,viewPlayerIndex:U,language:d.language||""}),ce(d)}function Ya(d,g={}){let C=ee(d);if(!C)throw new Error("playSetCanvas requires canvasId");return Ot({...g,canvasId:C})}function ce(d={}){if(!A)return G({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]});let g=Vr(A,d);return g.running=!0,g.logs=qr(g.logs),g.serverLogs=qr(g.server?.logs||[]),g.serverVars=nc(g.server,g.playerCount||1),g}function Ua(d,g={}){return A||Ot(),Mi(A,d),g.observe===!1?G({running:!0,time:A.runtime.clock.time,frame:A.runtime.clock.frame,paused:!!A.debugPaused,levelTimePaused:!!A.runtime.clock.paused,playerCount:A.playerCount||1,viewPlayerIndex:A.viewPlayerIndex||1}):ce(g)}function Ha(d=0){Ot();let g=Math.max(0,Number(d)||0);for(let C=0;C<g;C++)Mi(A,1/30);return ce()}function Ka(){return A&&Kr(A),A=null,O="",F=1,U=1,G({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]})}function Xa(d,g={}){let C=$t();return U=Gr(C,d),g.observe===!1?null:ce(g)}function Wa(d,g={}){if(!A)throw new Error("play session has not started");return Lr(A,d),g.observe===!1?null:ce(g)}function ja(d,g={}){if(!A)throw new Error("play session has not started");return Br(A,d),g.observe===!1?null:ce(g)}function qa(d,g,C,P={}){if(!A)throw new Error("play session has not started");return ti(A,d,g,C),P.observe===!1?null:ce(P)}function Ja(d={}){return A&&Ni(A).pause(),d.observe===!1?null:ce(d)}function Za(d={}){return A&&Ni(A).resume(),d.observe===!1?null:ce(d)}function $t(){if(!A)throw new Error("play session has not started");return A}function Qa(d,g){let C=$t();if(!d&&!g){let P=ce();return G({vars:P.serverVars||[]})}return G({entityType:String(d||""),name:String(g||""),value:ia(C,d,g)})}function es(d,g,C){let P=$t();return Ur(P,d,g,C),ce()}function ts(d,g=[],C="PlayerSelf"){let P=$t();return Hr(P,d,g,C),ce()}function is(){let d=ce();return G({events:d.history||[],case:Uo(d.history||[],{playerCount:d.playerCount||1})})}function rs(d={}){let g=ce(),C=Zt({name:d.name||"",dt:d.dt,playerCount:d.playerCount||g.playerCount||1,events:d.events||g.history||[],asserts:d.asserts||[]});return G(C)}function ns(d,g={}){let C=Zt(d);Ot({...g,playerCount:g.playerCount||C.playerCount||1});let P=$t();P.recording=!1;try{return oa(Ni(P),d)}finally{P.recording=!0}}function os(){if(!A)return{running:!1,paused:!1,time:0,frame:0,playerCount:1,viewPlayerIndex:1};let d=A.runtime.clock;return{running:!0,paused:!!A.debugPaused,levelTimePaused:!!d.paused,time:d.time,frame:d.frame,playerCount:A.playerCount||1,viewPlayerIndex:A.viewPlayerIndex||1}}let dn={get:te,patch:Pe,setWorkspace:La,exportData:Mt,importData:Ft,pick:Va,playStart:Ot,playSetCanvas:Ya,playSetView:Xa,playGet:ce,playStatus:os,playStep:Ua,playRun:Ha,playStop:Ka,playKey:Wa,playClick:ja,playPointer:qa,playPause:Ja,playResume:Za,playServerGet:Qa,playServerSet:es,playServerSend:ts,playHistory:is,playSaveCase:rs,playRunCase:ns,archiveData:Tt};return Object.defineProperty(dn,"_project",{enumerable:!1,get:Z}),dn}import{createRequire as hc}from"node:module";function la(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}}var pc=hc(import.meta.url),mc=[0,-.5,.5,.5,-.5,.5],gc=[0,-.5,.12,-.12,.5,0,.12,.12,0,.5,-.12,.12,-.5,0,-.12,-.12],yc=[0,-.5,.11,-.15,.48,-.15,.18,.07,.29,.41,0,.2,-.29,.41,-.18,.07,-.48,-.15,-.11,-.15],tn=Buffer.from([137,80,78,71,13,10,26,10]),bc=new Set(["image","textbox","textwindow","button"]),$i={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"},Di=null;function ua(){if(Di)return Di;try{Di=pc("@napi-rs/canvas")}catch(e){let t=e?.message||String(e);throw new Error(`Host screenshot renderer requires @napi-rs/canvas (${t})`)}return Di}function H(e,t=0){let i=Number(e);return Number.isFinite(i)?i:t}function zi(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 pt(e,t=1){return`rgba(${e.r},${e.g},${e.b},${Math.max(0,Math.min(1,e.a*t))})`}function fa(e,t,i=1){let r=Math.max(1,Math.round(H(e,1))),n=Math.max(1,Math.round(H(t,1))),o=Math.max(1,Math.min(2,H(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 da(e){let t=Buffer.from(e.toBuffer("image/png"));if(t.length<tn.length||!t.subarray(0,tn.length).equals(tn))throw new Error("Host screenshot renderer did not produce a PNG");return t}function vc(e){return e==="triangle"?mc:e==="fourstar"?gc:yc}function Sc(e,t,i,r,n){let o=vc(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=pt(n),e.fill()}function wc(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,f,p]=n;e.transform(a*o,-s*o,-c*o,l*o,f,i-p);return}e.translate(H(t.left)+H(t.width)/2,i-H(t.bottom)-H(t.height)/2),e.rotate(-H(t.rotationZ)*Math.PI/180),e.scale(o,o)}function Cc(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 ha(e,t,i,r){let n=zi(t.bgColor,16777215);e.fillStyle=pt(n),e.fillRect(-i/2,-r/2,i,r);let o=Math.max(8,H(t.fontSize,12)),a=zi(t.fontColor,4294967295),s=t.horizontalAlignment==="Right"?1:t.horizontalAlignment==="Middle"?.5:0,c=t.verticalAlignment==="Bottom"?1:t.verticalAlignment==="Middle"?.5:0;if(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=pt(a),e.textAlign=s===1?"right":s===.5?"center":"left",e.textBaseline=c===1?"bottom":c===.5?"middle":"top",t.enableOutline){let y=zi(t.outlineColor,4278190080);e.strokeStyle=pt(y),e.lineWidth=Math.max(2,o*.12),e.lineJoin="round"}let l=s===0?-i/2+2:s===1?i/2-2:0,f=c===0?-r/2:c===1?r/2:0,p=String(t.text||"").split(`
110
- `),h=o*1.2,m=c===.5?f-(p.length-1)*h/2:c===1?f-(p.length-1)*h:f;for(let y=0;y<p.length;y+=1){let v=m+y*h;t.enableOutline&&e.strokeText(p[y],l,v),e.fillText(p[y],l,v)}e.restore()}function pa(e,t,i,r){e.beginPath(),Cc(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 ma(e,t,i,r){let n=zi(t.imageColor,4294967295);if(t.primitive==="missing"){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=pt(n),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=pt(n),e.lineWidth=7,e.stroke();return}if(t.primitive==="triangle"||t.primitive==="fourstar"||t.primitive==="fivestar"){Sc(e,t.primitive,i,r,n);return}e.fillStyle=pt(n),e.fillRect(-i/2,-r/2,i,r)}function Ic(e,t,i){let r=Math.max(0,H(t.sourceWidth,H(t.width))),n=Math.max(0,H(t.sourceHeight,H(t.height)));if(e.save(),wc(e,t,i),t.kind==="textbox"||t.kind==="textwindow")ha(e,t,r,n);else if(t.kind==="button")pa(e,t,r,n);else{let o=la(t,r,n);o&&(e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip()),ma(e,t,r,n)}e.restore()}function ga(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 kc(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 ca(e){let t=e?.matrix;return!t||typeof t!="object"?{a:1,b:0,c:0,d:1,tx:0,ty:0}:{a:H(t.a,1),b:H(t.b),c:H(t.c),d:H(t.d,1),tx:H(t.tx),ty:H(t.ty)}}function Ec(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)=>H(s.z)-H(c.z));let r=[];function n(a,s){if(!bc.has(a.kind))return;let c=Math.abs(H(a.sourceWidth)*Math.hypot(s.a,s.b)),l=Math.abs(H(a.sourceHeight)*Math.hypot(s.c,s.d));r.push({...a,left:s.tx-c/2,bottom:s.ty-l/2,width:c,height:l,rotationZ:Math.atan2(s.b,s.a)*180/Math.PI,matrix:{a:s.a,b:s.b,c:s.c,d:s.d,tx:s.tx,ty:s.ty}})}function o(a,s){let c=i.get(a)||[];for(let l=c.length-1;l>=0;l-=1){let f=c[l],p=s?kc(s,ca(f)):ca(f);n(f,p),o(String(f.id),p)}}return o("",null),r}function ya(e,t,i,r={}){return xc(Ec(e),t,i,r)}function xc(e,t,i,r={}){let{createCanvas:n}=ua(),o=fa(t,i,r.scale),a=n(o.pixelWidth,o.pixelHeight),s=a.getContext("2d");s.scale(o.pixelRatio,o.pixelRatio),ga(s,o.width,o.height);let c=Array.isArray(e)?e:[];for(let l of c)!l||l.id===void 0||l.id===null||Ic(s,l,o.height);return{data:da(a),width:o.width,height:o.height,pixelWidth:o.pixelWidth,pixelHeight:o.pixelHeight}}function Ac(e){return{kind:e.kind,left:H(e.renderLeft,e.left),bottom:H(e.renderBottom,e.bottom),width:Math.max(0,H(e.renderWidth,e.width)),height:Math.max(0,H(e.renderHeight,e.height)),rotationZ:H(e.renderRotationZ,e.rotationZ)}}function Gi(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 Pc(e,t,i,r){let n=Ac(t);if(n.width<=0||n.height<=0)return;e.save(),e.translate(n.left+n.width/2,i-n.bottom-n.height/2),e.rotate(-n.rotationZ*Math.PI/180);let o=-n.width/2,a=-n.height/2;if(t.kind==="image")ma(e,t,n.width,n.height);else if(t.kind==="textbox"||t.kind==="textwindow")ha(e,t,n.width,n.height);else if(t.kind==="button")pa(e,t,n.width,n.height),Gi(e,t.name||$i.button,n.width);else if(t.kind==="cursor")e.setLineDash([6,4]),e.strokeStyle="rgba(74,142,181,0.7)",e.fillStyle="rgba(74,142,181,0.1)",e.fillRect(o,a,n.width,n.height),e.strokeRect(o,a,n.width,n.height),Gi(e,t.name||$i.cursor,n.width);else if(t.kind==="grid"){e.strokeStyle="rgba(106,146,189,0.55)",e.strokeRect(o,a,n.width,n.height),e.beginPath();for(let s=20;s<n.width;s+=20)e.moveTo(o+s,a),e.lineTo(o+s,a+n.height);for(let s=20;s<n.height;s+=20)e.moveTo(o,a+s),e.lineTo(o+n.width,a+s);e.stroke(),Gi(e,t.name||$i.grid,n.width)}else t.kind!=="container"&&t.kind!=="server-container"?(e.setLineDash(t.kind==="reference"||t.kind==="animation"||t.kind==="fullscreen"?[4,4]:[]),e.strokeStyle="rgba(203,218,237,0.55)",e.strokeRect(o,a,n.width,n.height),Gi(e,t.name||$i[t.kind]||t.kind,n.width)):(e.strokeStyle="rgba(78,165,230,0.42)",e.strokeRect(o,a,n.width,n.height));t.id===r&&t.kind!=="container"&&t.kind!=="server-container"&&(e.setLineDash([]),e.strokeStyle="#61b9ff",e.lineWidth=2,e.strokeRect(o,a,n.width,n.height)),e.restore()}function ba(e,t={}){let{createCanvas:i}=ua(),r=e?.canvas||{},n=fa(r.width||1600,r.height||900,t.scale),o=i(n.pixelWidth,n.pixelHeight),a=o.getContext("2d");a.scale(n.pixelRatio,n.pixelRatio),ga(a,n.width,n.height,{checker:!0});let s=Array.isArray(e?.boxes)?e.boxes:[],c=e?.selectedId;for(let l of s)!l||l.kind==="server-container"||l.visible===!1||Pc(a,l,n.height,c);return{data:da(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 _c,existsSync as Vi,openSync as Rc,opendirSync as Tc,readSync as Mc,realpathSync as _t,statSync as Sa}from"node:fs";import{basename as Nc,dirname as va,isAbsolute as an,join as Fc,relative as wa,resolve as oi}from"node:path";var Oc="qxqy-simulator-save",Ca=new Set(["node_modules",".git","dist",".dsh","coverage"]),ri=50,Ia=4096,rn=1e4,nn=1e3,on=8;function mt(e=""){let t=oi(String(e||process.cwd()));if(!Vi(t))throw new Error(`workspace does not exist: ${t}`);if(!Sa(t).isDirectory())throw new Error(`workspace is not a directory: ${t}`);return _t(t)}function ni(e,t,i=!1){let r=wa(e,t);if(!i&&!r||r.startsWith("..")||an(r))throw new Error("path must stay inside the configured workspace");return r}function Fe(e,t){let i=String(t||"").trim();if(!i||an(i))throw new Error("path must be a non-empty workspace-relative path");let r=_t(oi(e)),n=oi(r,i);if(ni(r,n),!Vi(n))throw new Error(`file does not exist: ${i}`);let o=_t(n);return ni(r,o),o}function xe(e,t){let i=String(t||"").trim();if(!i||an(i))throw new Error("path must be a non-empty workspace-relative path");let r=_t(oi(e)),n=oi(r,i);ni(r,n);let o=va(n);for(;!Vi(o);){let a=va(o);if(a===o)throw new Error("unable to resolve output directory");o=a}return ni(r,_t(o),!0),Vi(n)&&ni(r,_t(n)),n}function $c(e,t=Ia){let i=Buffer.alloc(t),r=Rc(e,"r");try{let n=Mc(r,i,0,t,0);return i.subarray(0,n).toString("utf8")}finally{_c(r)}}function ka(e,t,i,r,n){if(r>on){n.depthLimitedDirectories+=1;return}if(n.scannedDirectories>=nn){n.directoryLimitReached=!0;return}let o;try{n.scannedDirectories+=1,o=Tc(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()&&Ca.has(a.name)){n.skippedEntries+=1,a.isDirectory()&&(n.skippedDirectories+=1);continue}let s=Fc(e,a.name);if(a.isDirectory()){if(ka(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=Sa(s),l=$c(s);if(!l.includes(Oc))continue;let f=l.match(/"name"\s*:\s*("(?:\\.|[^"\\])*")/)?.[1],p=Nc(a.name,".json");if(f)try{p=JSON.parse(f)||p}catch{}i.push({path:wa(t,s).replaceAll("\\","/"),name:p,bytes:c.size,mtime:c.mtimeMs})}catch{n.unreadableEntries+=1}}}}catch{n.unreadableEntries+=1}finally{try{o.closeSync()}catch{n.unreadableEntries+=1}}}function Li(e){let t=mt(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:ri,entries:rn,directories:nn,depth:on,headBytes:Ia},policy:{excludedDirectories:[...Ca],hiddenEntries:!1,symlinks:!1,validatesJson:!1}};return ka(t,t,i,0,r),i.sort((n,o)=>o.mtime-n.mtime||n.path.localeCompare(o.path)),r.matchedArchives=i.length,i.length>ri&&r.warnings.push(`\u53D1\u73B0 ${i.length} \u4E2A\u5B58\u6863\uFF0C\u4EC5\u663E\u793A\u4FEE\u6539\u65F6\u95F4\u6700\u65B0\u7684 ${ri} \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 / ${nn} \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 ${on} \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>ri||r.entryLimitReached||r.directoryLimitReached||r.depthLimitedDirectories>0,{bound:!0,workspace:t,archives:i.slice(0,ri),discovery:r}}import{readFileSync as Dc}from"node:fs";import{homedir as Gc}from"node:os";import{join as zc}from"node:path";var Vc={"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 Lc(e){let i=[...String(e||"").matchAll(/Request to set language:([A-Za-z0-9_-]+)/g)].at(-1)?.[1]?.toLowerCase();return Vc[i]||null}function Bc(){return zc(Gc(),"AppData","LocalLow","miHoYo","\u539F\u795E","output_log.txt")}function Ea(e=Bc()){try{return Lc(Dc(e,"utf8"))}catch{return null}}import{existsSync as cn,lstatSync as Yc,mkdirSync as xa,readFileSync as Bi,readdirSync as Uc,realpathSync as Aa,renameSync as Hc,rmSync as Kc,statSync as Hi,writeFileSync as Pa}from"node:fs";import{createHash as Xc,randomUUID as _a}from"node:crypto";import{homedir as Wc}from"node:os";import{basename as jc,dirname as Yi,isAbsolute as qc,join as Ui,relative as Jc}from"node:path";var ze=e=>Xc("sha256").update(e).digest("hex"),sn=e=>cn(e)?ze(Bi(e)):null,ln=(e,t)=>{let i=Jc(e,t);return!qc(i)&&i!==".."&&!i.startsWith(`..${process.platform==="win32"?"\\":"/"}`)};function Ra(e,t){let i=xe(e,t),r=i;for(;r!==e;){try{if(Yc(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=Yi(r)}if(cn(i)&&!Hi(i).isFile())throw new Error("\u5B9E\u673A\u76EE\u6807\u4E0D\u662F\u666E\u901A\u6587\u4EF6");return i}function Ta(e=Ui(Wc(),"AppData","LocalLow","miHoYo","\u539F\u795E","BeyondLocal")){let t=r=>{try{return Uc(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=Ui(e,r,"Beyond_Local_Save_Level");for(let o of t(n)){let a=Ui(n,o,"external_lua_file","default_import_file");cn(a)&&Hi(a).isDirectory()&&i.push({uid:r,editorId:o,path:a})}}return{candidates:i}}var Ki=class{constructor(t){this.controller=t,this.plan=null,this.lastResult=null}preview(){let t=this.controller,i=t.studio.archiveData(),r=Gt(i.scriptSync);if(!r)throw new Error("\u8BF7\u5148\u914D\u7F6E\u5B9E\u673A\u811A\u672C\u76EE\u5F55");let n=Aa(t.activeWorkspacePath()),o=Aa(r.clientImportRoot);if(!Hi(o).isDirectory())throw new Error("\u5B9E\u673A\u5BFC\u5165\u6839\u76EE\u5F55\u4E0D\u5B58\u5728");let a=r.workspaceDir?Fe(n,r.workspaceDir):n;if(!Hi(a).isDirectory())throw new Error("\u5DE5\u4F5C\u533A\u811A\u672C\u76EE\u5F55\u4E0D\u5B58\u5728");if(ln(a,o)||ln(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(f=>{let p={id:f.id,path:f.path,sourceKind:f.source.trim()?"\u5B58\u6863\u6E90\u7801":"\u5DE5\u4F5C\u533A\u6587\u4EF6"};try{let h=ui(f.path);if(!/\.lua$/i.test(h))throw new Error("\u811A\u672C\u8DEF\u5F84\u5FC5\u987B\u4EE5 .lua \u7ED3\u5C3E");let m=r.workspaceDir?`${r.workspaceDir}/`:"";if(!h.startsWith(m))throw new Error("\u811A\u672C\u4E0D\u5728\u6240\u914D\u7F6E\u7684\u5DE5\u4F5C\u533A\u811A\u672C\u76EE\u5F55\u4E2D");let y=[r.clientSubdir,h.slice(m.length)].filter(Boolean).join("/"),v=Ra(o,y),x=v.toLowerCase();s.set(x,(s.get(x)||0)+1);let I=null,A="";try{I=Bi(Fe(n,h),"utf8")}catch(U){A=U.message}if(!f.source.trim()&&I===null)throw new Error(A);let O=f.source.trim()?f.source:I,F=sn(v);return{...p,target:v,targetRelative:y,source:O,diskSource:I,diskError:A,sourceMismatch:!!(f.source.trim()&&I!==null&&f.source!==I),beforeSource:F===null?"":Bi(v,"utf8"),beforeHash:F,sourceHash:ze(O),status:F===null?"\u65B0\u589E":F===ze(O)?"\u672A\u53D8\u5316":"\u8986\u76D6"}}catch(h){return{...p,status:"\u9519\u8BEF",error:h.message}}});for(let f of c)f.target&&s.get(f.target.toLowerCase())>1&&(f.status="\u9519\u8BEF",f.error="\u591A\u4E2A\u811A\u672C\u6620\u5C04\u5230\u540C\u4E00\u76EE\u6807\u6587\u4EF6");let l=ze(JSON.stringify({archive:i,workspace:n,root:o,rows:c}));return this.plan={id:_a(),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(f=>{let p=n.rows.find(h=>h.id===f);if(!p||p.error||p.status==="\u672A\u53D8\u5316")throw new Error("\u6240\u9009\u811A\u672C\u4E0D\u80FD\u590D\u5236\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");return p});this.controller.assertSavedArchive();let s=`.qxqy-script-sync-backups/${n.id}`,c=xe(n.workspace,s);if(ln(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 f of a){let p="";try{let h=Ra(n.root,f.targetRelative);if(sn(h)!==f.beforeHash)throw new Error("\u76EE\u6807\u6587\u4EF6\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");if(f.beforeHash!==null){let m=xe(n.workspace,`${s}/${f.targetRelative}`);xa(Yi(m),{recursive:!0}),Pa(m,Bi(h),{flag:"wx"})}if(xa(Yi(h),{recursive:!0}),p=Ui(Yi(h),`.${jc(h)}.${_a()}.tmp`),Pa(p,f.source,{flag:"wx"}),sn(h)!==f.beforeHash)throw new Error("\u76EE\u6807\u6587\u4EF6\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");Hc(p,h),l.push({id:f.id,target:h,status:"\u6210\u529F"})}catch(h){l.push({id:f.id,target:f.target,status:"\u5931\u8D25",error:h.message})}finally{p&&Kc(p,{force:!0})}}return this.lastResult={completed:l.every(f=>f.status==="\u6210\u529F"),at:new Date().toISOString(),backupRoot:c,results:l},this.lastResult}};var nu=Math.max(1e3,Number(process.env.QXQY_PLAY_TIMEOUT_MS)||8e3),ou=8e3;function Ma(){let e=new Error("operation aborted");return e.name="AbortError",e}var Rt=class{constructor(t=""){this.workspacePath=t?mt(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 Ki(this)}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 Ta();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=Fe(this.activeWorkspacePath(),this.archivePath);if(ze(un(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=xe(this.activeWorkspacePath(),t);if(Qc(r)){let n=this.archivePath?xe(this.activeWorkspacePath(),this.archivePath):"";if(r!==n||ze(un(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 Li(this.workspacePath)}loadArchive(t){let i=this.activeWorkspacePath();if(!i)throw new Error("workspace is not bound");let r=Fe(i,t),n=un(r),o=this.studio.importData("json",n.toString("base64"),iu(r));return this.archivePath=String(t).trim().replaceAll("\\","/"),this.archiveStamp=ze(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=xe(r,i);eu(ru(n),{recursive:!0});let o=Buffer.from(JSON.stringify(this.studio.archiveData(),null,2)+`
111
- `,"utf8");return tu(n,o),this.archivePath=i.replaceAll("\\","/"),this.archiveStamp=ze(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 Zc(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=nu){let o=this.worker||this.createWorker(),a=this.sequence++;return new Promise((s,c)=>{let l=!1,f=(m,y)=>{l||(l=!0,clearTimeout(h),r?.removeEventListener("abort",p),m(y))},p=()=>{this.pending.delete(a),f(c,Ma()),this.terminateWorker(Ma())},h=setTimeout(()=>{this.pending.delete(a);let m=new Error(`play worker timed out after ${n}ms`);f(c,m),this.terminateWorker(m)},n);if(this.pending.set(a,{resolve:m=>f(s,m),reject:m=>f(c,m)}),r?.aborted)return p();r?.addEventListener("abort",p,{once:!0}),o.postMessage({id:a,action:t,args:i})})}async play(t,i={},r){if((t==="start"||t==="device")&&!i.language){let n=Ea();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,ou),r=ya(i.scene,i.canvasWidth,i.canvasHeight);return{data:r.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:r.width,height:r.height,pixelWidth:r.pixelWidth,pixelHeight:r.pixelHeight}}uiScreenshot(){let t=ba(this.studio.get());return{data:t.data,page:t.page,width:t.width,height:t.height,pixelWidth:t.pixelWidth,pixelHeight:t.pixelHeight}}async dispose(){await this.terminateWorker()}};var su=new Set(["server-control-template","client-control-template"]),lu=new Set(["start","device","view","get","step","pointer","key","click","pause","resume","stop","serverGet","serverSet","serverSend","history","saveCase","runCase"]);function Na(e){return String(e||"").trim().replaceAll("\\","/")}function Fa(e,t){let i=au(Fe(e,t));return`${i.size}:${i.mtimeMs}`}function cu(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 Oa(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 Xi=class{constructor({workspace:t,initialPath:i="",watchIntervalMs:r=700,discoveryIntervalMs:n=5e3}={}){this.workspace=mt(t),this.controller=new Rt(this.workspace),this.initialPath=Na(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=Li(this.workspace),this.archiveCacheTime=Date.now()),this.archiveCache}previewStatus(){let t=this.controller.get();return{service:"beyond-simulator-web",version:gn.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:cu(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=Na(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=Oa(this.playState,{running:!1,logs:[]},"stop");let o=Fa(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 Fa(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&&!su.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(!lu.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=Oa(this.playState,n,t),this.emit({type:"play",action:t,frame:this.playState.frame}),n}async currentState(t){return this.state()}editorScreenshot(){return this.controller.uiScreenshot()}playScreenshot(t){return this.controller.exclusive(()=>this.controller.playScreenshot(t))}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let i of this.listeners)i(t)}async dispose(){this.disposed=!0,this.timer&&clearInterval(this.timer),this.timer=null,this.listeners.clear(),await this.controller.exclusive(()=>this.controller.dispose())}};import{existsSync as uu,readFileSync as fu}from"node:fs";import{createHash as du}from"node:crypto";var hu=new Set(["get","patch","import","export","archives","load-archive","save","play","script-sync","script-sync-apply"]),fn=e=>du("sha256").update(fu(e)).digest("hex"),Wi=class{constructor(t,{initialPath:i="",maxSessions:r=8}={}){this.workspace=t,this.initialPath=i,this.maxSessions=r,this.sessions=new Map}getSession(t){if(typeof t!="string"||!/^[a-zA-Z0-9_-]{1,100}$/.test(t))throw new Error("Invalid editor sessionId");if(!this.sessions.has(t)){if(this.sessions.size>=this.maxSessions)throw new Error("Editor session limit reached; save your work and restart the server");let r={controller:new Rt(this.workspace),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=Fe(this.workspace,i),n=t.controller.loadArchive(i);return t.path=String(i).replaceAll("\\","/"),t.fileStamp=fn(r),{...n,snapshot:this.snapshot(t)}}async call(t,i,r){if(!hu.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==="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=xe(this.workspace,i.path);if(uu(a)){let c=n.path?xe(this.workspace,n.path):"";if(a!==c||fn(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=fn(a),s}})}async dispose(){await Promise.all([...this.sessions.values()].map(t=>t.controller.exclusive(()=>t.controller.dispose()))),this.sessions.clear()}};var Su=za(new URL(".",import.meta.url)),wu=Ga(Su,"public"),Da=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"]]),Cu={".html":"text/html; charset=utf-8",".js":"text/javascript; charset=utf-8",".css":"text/css; charset=utf-8"};function Iu(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 qi(e){return{"cache-control":"no-store","content-type":e,"content-security-policy":"default-src 'self'; img-src 'self' data:; connect-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; object-src 'none'; frame-ancestors 'none'","x-content-type-options":"nosniff"}}function Ie(e,t,i){e.writeHead(t,qi("application/json; charset=utf-8")),e.end(JSON.stringify(i))}function ku(e,t){e.writeHead(200,{...qi("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 ji(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 Eu(e){let t=process.platform==="win32"?"cmd.exe":process.platform==="darwin"?"open":"xdg-open",i=process.platform==="win32"?["/c","start","",e]:[e];pu(t,i,{detached:!0,stdio:"ignore",windowsHide:!0}).unref()}async function xu(e={}){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=v=>bu("sha256").update(v).digest(),o=n(i),a=new Xi(e);await a.initialize();let s=new Wi(a.workspace,e),c=new Set,l=a.subscribe(v=>{let x=`event: state
107
+ `)}`);return{buffer:r,warnings:[...new Set(t.warnings)]}}function gr(e){return Ee.toObject(Ee.decode(Ci(e)),{longs:Number,enums:Number,bytes:Buffer,defaults:!1,arrays:!0,objects:!0})}function so(e){try{let i=gr(e).graph||[];return i.length>0&&i.every(r=>Number(r.which)===kt)}catch{return!1}}function lo(e){let t=(e.graph||[]).filter(n=>Number(n.which)===kt),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 co(e){let t=gr(e),i=lo(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 Bs(e){let t=[],i;try{i=gr(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)!==kt&&t.push(`${a}: which \u5E94\u4E3A 69\uFF0C\u5B9E\u9645 ${n.which}`),Number(n.id?.class)!==ro&&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 Ci(e){let t=Buffer.isBuffer(e)?e:Buffer.from(e);if(t.length<Ke+fr)throw new Error("GIA \u6587\u4EF6\u8FC7\u77ED");if(t.readUInt32BE(4)!==1||t.readUInt32BE(8)!==Un||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-fr)throw new Error("GIA payload \u957F\u5EA6\u4E0D\u4E00\u81F4");if(t.readUInt32BE(Ke+i)!==Hn)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 Ls(e){let t=fe(e,"transform")?.multiPlatform,i={};for(let n of t?.platforms||[]){let o=Ts[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 wi(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 Ln(e,{reverseSiblings:t=!1,idOffset:i=0}={}){if(!e.length)return{nodes:new Map,rootCandidates:[],warnings:[]};let r=new Map(e.map((l,f)=>[l.id?.id,`n${i+f+1}`])),n=new Map,o=new Map,a=[];for(let l of e){let f=wi(l),p=fe(l,"textConfig"),d=fe(l,"imageSlot"),m=fe(l,"image"),y=fe(l,"buttonPreset"),v=fe(l,"gridView"),x=fe(l,"genericSlot"),I=fe(l,"footerSlot"),A=fe(l,"cursorConfig"),O=fe(l,"keyHint"),F=fe(l,"containerNodeSlot"),U=fe(l,"templateRefSlot"),te=fe(l,"effectSlot"),Z=fe(l,"fullscreenEffectSlot"),$=W(f,{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||f,visible:fe(l,"field14")?.field17?.initiallyHidden!==!0,active:fe(l,"field14")?.initiallyInactive!==!0,canControllerFocus:I?.field505===1,scriptMappingIds:(x?.field502||[]).map(b=>Number(b?.field1?.id)).filter(b=>Number.isSafeInteger(b)&&b>0),transformByPlatform:Ls(l),syncAllDevices:fe(l,"transform")?.multiPlatform?.field504===1,giaRaw:{genericField501:x?.field501??0,footerField505:I?.field505??0,...f==="textbox"||f==="textwindow"?{textField501:p?.field501??20,textField503:p?.field503??12,textAlign:p?.align??0,...[void 0,0,1,2].includes(p?.verticalAlign)?{}:{textVerticalAlign:p.verticalAlign},...f==="textwindow"?{textField511:p?.field511??1,textViewField502:p?.viewFlags?.field502??1,textViewField503:p?.viewFlags?.field503??1}:{}}:{},...f==="cursor"?{cursorField501:A?.field501??0}:{},...f==="reference"?{templateRefSlot:U??""}:{},...f==="grid"?{gridField501:v?.field501??1,gridField507:v?.field507??1,gridField508:v?.field508??1,gridField509:v?.field509??1,gridField511:v?.field511??5,gridField512:v?.field512??1}:{},...f==="keyhint"?{keyHintField501:O?.field501??1,keyHintField502:O?.field502??1}:{},...f==="image"?{imageField502:m?.field502??1,imageField504:m?.field504??1,imageField505:m?.field505??1,imageField507:m?.field507??2,imageFillType:m?.fillType??1}:{},...f==="animation"?{effectSlot:te??""}:{},...f==="fullscreen"?{fullscreenEffectSlot:Z??""}:{}},...f==="container"?{isolateNavigation:F?.isolateNavigation===!0,disableKeyEventPassthrough:F?.disableKeyEventPassthrough===!0,disableCursorEventPassthrough:F?.disableCursorEventPassthrough===!0,showCursor:F?.showCursor===!0}:{},...f==="cursor"?{raycastTarget:A?.field501===1}:{},...f==="textbox"||f==="textwindow"?{text:p?.text?.value??"",fontSize:p?.fontSize??20,minimumFontSize:p?.minimumFontSize??20,adaptiveFontSize:p?.adaptive===1,fontColor:p?.color??4294967295,bgColor:p?.color2??0,enableOutline:p?.outlineOff!==1,outlineColor:p?.color3??858993459,horizontalAlignment:p?.align===1?"Middle":p?.align===2?"Right":"Left",verticalAlignment:{0:"Top",1:"Middle",2:"Bottom"}[p?.verticalAlign??0]||"Top",...f==="textwindow"?{interactable:!0,showScrollBar:!0}:{}}:{},...f==="image"?{imageSource:"StaticReference",imageId:d?.assetId??0,imageColor:Number.isFinite(d?.field502)?d.field502>>>0:4294967295,enableMask:m?.enableMask===1,enableSoftEdge:m?.enableSoftEdge===1,enableFill:m?.enableFill===1,softEdgeMode:m?.softEdgePixel===1?"Pixel":"Percentage",softEdgeWidthX:m?.border?.field501??8,softEdgeWidthY:m?.border?.field502??8,horizontalSoftRange:m?.field512??85,verticalSoftRange:m?.field513??85,fillType:{1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[m?.fillType]||"Horizontal",fillAmount:Number.isFinite(m?.field508)?Math.max(0,Math.min(1,m.field508/100)):m?.enableFill===1?0:1,reverseMaskArea:m?.reverseMask===1}:{},...f==="button"?{interactable:y?.interactable===1,raycastTarget:y?.raycastTarget===1,clickAudioId:y?.clickAudioId??50888}:{},...f==="grid"?{cellSizeX:v?.cellSize?.field501??50,cellSizeY:v?.cellSize?.field502??50,spacingX:v?.gap?.field501??8,spacingY:v?.gap?.field502??8,padding1X:v?.padding1?.field501??20,padding1Y:v?.padding1?.field502??20,padding2X:v?.padding2?.field501??20,padding2Y:v?.padding2?.field502??20,previewCount:v?.field511??5}:{},...f==="reference"?{referencedPrefabId:U??""}:{},...f==="keyhint"?{keyboardKeyCode:O?.field502??null,controllerKeyCode:O?.field501??null}:{},...f==="animation"?{animationId:te??""}:{},...f==="fullscreen"?{animationId:Z??""}:{}});n.set(l.id?.id,$),(f==="textbox"||f==="textwindow")&&![void 0,0,1,2].includes(p?.align)&&a.push(`${$.name}: \u6C34\u5E73\u5BF9\u9F50\u679A\u4E3E ${p.align} \u7684\u542B\u4E49\u672A\u77E5\uFF0C\u5DF2\u539F\u6837\u4FDD\u7559\u3002`),(f==="textbox"||f==="textwindow")&&![void 0,0,1,2].includes(p?.verticalAlign)&&a.push(`${$.name}: \u5782\u76F4\u5BF9\u9F50\u679A\u4E3E ${p.verticalAlign} \u7684\u542B\u4E49\u672A\u77E5\uFF0C\u5DF2\u539F\u6837\u4FDD\u7559\u3002`),f==="image"&&![void 0,0,1,2,3,4,5].includes(m?.fillType)&&a.push(`${$.name}: \u586B\u5145\u5F62\u72B6\u679A\u4E3E ${m.fillType} \u672A\u8BC6\u522B\uFF0C\u5DF2\u4FDD\u7559\u539F\u503C\u3002`),f==="button"&&o.set($.id,{unavailableChildId:y?.disabledChild,hoverChildId:y?.hoverChild,pressedChildId:y?.pressedChild,selectedChildId:y?.selectedChild})}let s=[],c=new Set;for(let l of e){let f=n.get(l.id?.id),p=(l.ui?.content?.children||[]).map(d=>n.get(d)).filter(Boolean);if(p.length){f.children=t?p.slice().reverse():p;for(let d of p)c.add(d.id)}}for(let l of e){let f=n.get(l.id?.id),p=l.ui?.content?.parent||0,d=n.get(p);d?c.has(f.id)||(t?d.children.unshift(f):d.children.push(f)):s.push(f)}for(let[l,f]of o){let p=[...n.values()].find(d=>d.id===l);for(let[d,m]of Object.entries(f))p[d]=r.get(m)||null}return{nodes:n,rootCandidates:s,warnings:a}}function uo(e){let t=Ci(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 f=["GIA \u5BFC\u5165\u4E3A\u5DF2\u9A8C\u8BC1 UI \u5B57\u6BB5\u7684\u8BED\u4E49\u5BFC\u5165\uFF1B\u672A\u77E5 protobuf \u5B57\u6BB5\u4E0D\u4F1A\u8FDB\u5165 Authoring JSON\u3002"],p=lo(i);f.push(...p.warnings);let d=null,m=null;if(c.length){let y=Ln(c,{reverseSiblings:!0,idOffset:0});f.push(...y.warnings);let v=y.rootCandidates.find(I=>I.kind==="container")||y.rootCandidates[0];if(!v)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6839\u63A7\u4EF6");let x=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||[]});x.children=[v],y.rootCandidates.length>1&&f.push(`\u68C0\u6D4B\u5230 ${y.rootCandidates.length} \u4E2A\u65E0\u7236\u8282\u70B9\u63A7\u4EF6\uFF0C\u4EC5\u5BFC\u5165\u4EE5\u201C${v.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:v.id,script:{controlId:v.id,path:"",source:""},root:x}}if(l.length){let y=Ln(l,{reverseSiblings:!1,idOffset:1e3});if(f.push(...y.warnings),!y.rootCandidates.length)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6A21\u677F");let v=W("server-container",{id:"sc1",guid:0,name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"});v.children=y.rootCandidates,m={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:v},d||(d=m)}return{project:d,clientProject:m&&d!==m?m:void 0,scripts:p.scripts,warnings:f,metadata:{gameVersion:i.gameVersion||"",filePath:i.filePath||"",...Number.isSafeInteger(Number(i.modeFlag))?{modeFlag:Number(i.modeFlag)}:{},combined:!!(n&&o.length)}}}function fo(e){let t=Ci(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,m)=>d!=null&&Object.prototype.hasOwnProperty.call(d,m),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 m=wi(d),y=d.ui?.content?.info||[],v=y.find(O=>O.field501===2&&O.field502===6)?.index?.value,x=Xn[m],I=y.find(O=>O.field501===4&&O.field502===4),A=I?.related?.value||[];return(!Number.isSafeInteger(v)||v<=0)&&o.push(`${d.name}: Info.index=${v??"<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:m,actualIndex:v,expectedIndex:x,relatedPresent:!!I,relatedGuids:A}});l.length||o.push("Root.graph \u4E0D\u542B UIControlTemplate(70)");let f=0,p=0;for(let d of[...r,...n]){if(!d.ui?.content)continue;let m=d.id?.id||0,y=d.ui.content,v=wi(d),x=r.includes(d)&&d.which===70,I=`${d.name||"<unnamed>"}(${m||"<missing-guid>"})`;!Number.isSafeInteger(m)||m<=0||m>2147483647?o.push(`${I}: GraphUnit GUID \u975E\u6CD5`):s.has(m)?o.push(`${I}: GUID \u4E0E ${s.get(m).name||"<unnamed>"} \u91CD\u590D`):s.set(m,d),(d.id?.class!==1||d.id?.type!==8)&&o.push(`${I}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),y.guid!==m&&o.push(`${I}: content.guid=${y.guid??"<missing>"} \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`),x&&d.which!==70&&o.push(`${I}: \u6A21\u677F\u6839 which \u5FC5\u987B\u4E3A UIControlTemplate(70)`),!x&&d.which!==15&&o.push(`${I}: \u9644\u4EF6\u63A7\u4EF6 which \u5FC5\u987B\u4E3A UIControl(15)`);let A=y.info||[],O=A.find(w=>w.field501===1&&w.field502===5),F=A.find(w=>w.field501===2&&w.field502===6);O?.guid?.value!==m&&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 U=A.find(w=>w.field501===4&&w.field502===4);x&&!U&&o.push(`${I}: \u9876\u5C42\u6A21\u677F\u7F3A\u5C11 Info.related \u8BB0\u5F55`),!x&&U&&o.push(`${I}: \u9644\u4EF6\u63A7\u4EF6\u4E0D\u5E94\u5199 Info.related`);let te=Wn[v],Z=y.data||[],$=Z.map(w=>`${w.field501}/${w.field502}`),b=te?.map(([w])=>w)||[];te?JSON.stringify($)!==JSON.stringify(b)&&o.push(`${I}: Data \u69FD\u4F4D\u987A\u5E8F ${$.join(",")}\uFF0C\u5E94\u4E3A ${b.join(",")}`):o.push(`${I}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${v}`);for(let w=0;w<Math.min(Z.length,te?.length||0);w+=1){let M=Z[w],[z,L,se]=te[w];if(a(M,L)||o.push(`${I}: Data ${z} \u7F3A\u5C11 ${L} \u5206\u652F`),!se)continue;a(M.details,se)||o.push(`${I}: Details ${z} \u7F3A\u5C11 ${se} \u5206\u652F`);let X=jn[z];(M.details?.field501!==X||M.details?.field502!==M.field502||M.details?.field503!==1)&&o.push(`${I}: Details ${z} \u6807\u8BB0\u5E94\u4E3A ${X}/${M.field502}/1`);let he=M.details?.nodeRef;(he?.class!==1||he?.type!==8||he?.id!==m)&&o.push(`${I}: Details ${z} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let E=(d.ui.content.data||[]).find(w=>w.field501===4&&w.field502===86);E&&(a(E.field14,"field17")?f+=1:o.push(`${I}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`),a(E.details?.field14,"field17")?f+=1:o.push(`${I}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`));let S=(d.ui.content.data||[]).find(w=>w.details?.transform)?.details?.transform?.multiPlatform?.platforms||[];S.length!==4&&o.push(`${I}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${S.length}\uFF0C\u5E94\u4E3A 4`);let k=S.map(w=>w.platformType||0);JSON.stringify(k)!==JSON.stringify([0,1,2,3])&&o.push(`${I}: \u5E73\u53F0\u987A\u5E8F ${k.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let D=(d.ui.content.data||[]).find(w=>w.details?.transform)?.details?.transform;D?.multiPlatform?.field502!==Ut[v]&&o.push(`${I}: \u53D8\u6362 preset=${D?.multiPlatform?.field502??"<missing>"}\uFF0C${v} \u5E94\u4E3A ${Ut[v]}`);for(let w of S)a(w.transform,"field508")?p+=1:o.push(`${I}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);c.push({id:m,name:d.name||"",kind:v,template:x,parent:y.parent||0,children:[...y.children||[]],relatedIds:(d.relatedIds||[]).map(w=>w.id||0),dataSignatures:$})}for(let d of c){let m=`${d.name||"<unnamed>"}(${d.id})`;if(JSON.stringify(d.relatedIds)!==JSON.stringify(d.children)&&o.push(`${m}: GraphUnit.relatedIds \u4E0E content.children \u4E0D\u4E00\u81F4`),d.template&&d.parent&&o.push(`${m}: \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(`${m}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):o.push(`${m}: parent=${d.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let y of d.children){let v=s.get(y);v?(v.ui?.content?.parent||0)!==d.id&&o.push(`${m}: child=${y} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):o.push(`${m}: 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:f,rectField508:p}}}function yr(e){let t=Ci(e),i=Ee.toObject(Ee.decode(t),{longs:Number,enums:Number,defaults:!1,arrays:!0,objects:!0}),r=(i.graph||[]).filter(w=>w.ui?.content&&Number(w.which)===21),n=(i.graph||[]).filter(w=>Number(w.which)===70),o=(i.graph||[]).filter(w=>Number(w.which)===kt),a=(i.accessories||[]).filter(w=>w.ui?.content),s=[],c=(w,M)=>w!=null&&Object.prototype.hasOwnProperty.call(w,M);/^\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(w=>{let M=Number(w.which);return M===kt||M===70||M===21?!1:!w.ui?.content});l.length&&s.push(`Root.graph \u542B ${l.length} \u4E2A\u65E0\u6CD5\u8BC6\u522B\u7684\u975E\u63A7\u4EF6/\u975E\u811A\u672C\u5355\u5143`);let f=r[0];if(!f)return{valid:!1,errors:s,filePath:i.filePath||"",gameVersion:i.gameVersion||"",accessoryCount:a.length,controls:[],scriptCount:o.length,explicitEmpty:{field17:0,rectField508:0}};let p=[f,...a],d=new Map;for(let w of p){let M=w.id?.id||0,z=`${w.name||"<unnamed>"}(${M||"<missing-guid>"})`;!Number.isSafeInteger(M)||M<=0||M>2147483647?s.push(`${z}: GraphUnit GUID \u975E\u6CD5`):d.has(M)?s.push(`${z}: GUID \u91CD\u590D`):d.set(M,w),(w.id?.class!==1||w.id?.type!==8)&&s.push(`${z}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),w.ui?.content?.guid!==M&&s.push(`${z}: content.guid \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`)}let m=f.id?.id||0,y=f.ui.content,v=`${f.name||"<unnamed>"}(${m})`;f.which!==21&&s.push(`${v}: which \u5FC5\u987B\u4E3A UIControlGroup(21)`);let x=y.info||[];x.find(w=>w.field501===1&&w.field502===5)?.guid?.value!==m&&s.push(`${v}: Info.self GUID \u7F3A\u5931\u6216\u4E0D\u4E00\u81F4`),x.find(w=>w.field501===2&&w.field502===6)?.index?.value!==1&&s.push(`${v}: Info.index \u5FC5\u987B\u4E3A 1`);let I=x.find(w=>w.field501===4&&w.field502===4);I||s.push(`${v}: \u7F3A\u5C11\u663E\u5F0F Info.related \u8BB0\u5F55`);let A=0,O=0,F=(w,M,z,L=!1)=>{let se=w.id?.id||0,X=`${w.name||"<unnamed>"}(${se})`,he=w.ui.content.data||[],Je=he.map(re=>`${re.field501}/${re.field502}`),gt=z.map(([re])=>re);JSON.stringify(Je)!==JSON.stringify(gt)&&s.push(`${X}: Data \u69FD\u4F4D\u987A\u5E8F ${Je.join(",")}\uFF0C\u5E94\u4E3A ${gt.join(",")}`);for(let re=0;re<Math.min(he.length,z.length);re+=1){let Pe=he[re],[Oe,Ft,Ot]=z[re];if(c(Pe,Ft)||s.push(`${X}: Data ${Oe} \u7F3A\u5C11 ${Ft} \u5206\u652F`),!Ot)continue;c(Pe.details,Ot)||s.push(`${X}: Details ${Oe} \u7F3A\u5C11 ${Ot} \u5206\u652F`);let Ye=jn[Oe];(Pe.details?.field501!==Ye||Pe.details?.field502!==Pe.field502||Pe.details?.field503!==1)&&s.push(`${X}: Details ${Oe} \u6807\u8BB0\u5E94\u4E3A ${Ye}/${Pe.field502}/1`);let Dt=Pe.details?.nodeRef;(Dt?.class!==1||Dt?.type!==8||Dt?.id!==se)&&s.push(`${X}: Details ${Oe} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let Nt=he.find(re=>re.field501===4&&re.field502===(L?23:86)),ie=L?"empty15":"field17";c(Nt?.field14,ie)?L||(A+=1):s.push(`${X}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.${ie} \u7A7A\u4E32`),c(Nt?.details?.field14,ie)?L||(A+=1):s.push(`${X}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.${ie} \u7A7A\u4E32`);let _e=he.find(re=>re.details?.transform)?.details?.transform,Ze=_e?.multiPlatform?.platforms||[];Ze.length!==4&&s.push(`${X}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${Ze.length}\uFF0C\u5E94\u4E3A 4`);let ui=Ze.map(re=>re.platformType||0);JSON.stringify(ui)!==JSON.stringify([0,1,2,3])&&s.push(`${X}: \u5E73\u53F0\u987A\u5E8F ${ui.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let fi=L?Ut["server-container"]:Ut[M];_e?.multiPlatform?.field502!==fi&&s.push(`${X}: \u53D8\u6362 preset=${_e?.multiPlatform?.field502??"<missing>"}\uFF0C\u5E94\u4E3A ${fi}`);for(let re of Ze)c(re.transform,"field508")?O+=1:s.push(`${X}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);return Je};F(f,"server-container",Ms,!0);let U=(f.relatedIds||[]).map(w=>w.id||0),te=new Set(U),Z=a.filter(w=>te.has(w.id?.id||0)),$=Z.map(w=>w.id?.id||0);JSON.stringify(U)!==JSON.stringify($)&&s.push(`${v}: \u4E3B\u56FE relatedIds \u5FC5\u987B\u6309\u987A\u5E8F\u8986\u76D6\u672C\u7EC4 accessories`);let b=y.data?.find(w=>w.details?.rootChildRef)?.details?.rootChildRef?.guid||0,E=d.get(b);(!E||!Z.includes(E))&&s.push(`${v}: 62/82 \u6839\u8282\u70B9\u5F15\u7528\u4E0D\u5B58\u5728`),$[0]!==b&&s.push(`${v}: \u6839\u5BB9\u5668\u8282\u70B9\u5FC5\u987B\u662F\u672C\u7EC4 accessories[0]`);let S=[];for(let w of Z){let M=w.id?.id||0,z=w.ui.content,L=`${w.name||"<unnamed>"}(${M})`,se=wi(w);w.which!==15&&s.push(`${L}: which \u5FC5\u987B\u4E3A UIControl(15)`);let X=z.info||[];(X.length!==1||X[0]?.field501!==1||X[0]?.field502!==5||X[0]?.guid?.value!==M)&&s.push(`${L}: \u670D\u52A1\u7AEF\u5BB9\u5668\u5185\u63A7\u4EF6 Info \u5FC5\u987B\u53EA\u542B\u81EA\u8EAB GUID`);let he=Wn[se];he||s.push(`${L}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${se}`);let Je=he?F(w,se,he):[];S.push({id:M,name:w.name||"",kind:se,parent:z.parent||0,children:[...z.children||[]],relatedIds:(w.relatedIds||[]).map(gt=>gt.id||0),dataSignatures:Je})}let k=S.find(w=>w.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 D=new Map(S.map(w=>[w.id,w]));for(let w of S){let M=`${w.name}(${w.id})`;if(JSON.stringify(w.relatedIds)!==JSON.stringify(w.children)&&s.push(`${M}: relatedIds \u5FC5\u987B\u4E0E\u76F4\u63A5 children \u4E00\u81F4`),w.id!==b){let z=D.get(w.parent);z?z.children.includes(w.id)||s.push(`${M}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):s.push(`${M}: parent=${w.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let z of w.children){let L=D.get(z);L?L.parent!==w.id&&s.push(`${M}: child=${z} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):s.push(`${M}: child=${z} \u4E0D\u5B58\u5728`)}}return{valid:s.length===0,errors:s,filePath:i.filePath||"",gameVersion:i.gameVersion||"",graph:{id:m,name:f.name||"",relatedGuids:I?.related?.value||[],rootGuid:b},accessoryCount:a.length,controls:S,scriptCount:o.length,explicitEmpty:{field17:A,rectField508:O}}}function ho(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 f=yt[l],p=K[f].platform,d=Object.keys(K).filter(x=>K[x].platform===p&&a[x]),m=a[f]?f:d[0],y=l==="CONTROLLER_CONSOLE"?c.KEYBOARD:l==="CONTROLLER_MOBILE"?c.TOUCHSCREEN:null,v=o[l]??y??(m?a[m]:null);if(c[l]=v?Me(v):ar(n.kind),v||t.push(`${s}: ${l} \u65E0\u65E7\u5E03\u5C40\uFF0C\u5DF2\u4F7F\u7528\u63A7\u4EF6\u9ED8\u8BA4\u503C`),!o[l]&&!y&&m&&m!==f&&t.push(`${s}: \u7F3A\u5C11 ${f}\uFF0C\u5DF2\u91C7\u7528 ${m} \u7684\u951A\u70B9\u548C\u5C3A\u5BF8\u53C2\u6570`),!y)for(let x of d)JSON.stringify(c[l])!==JSON.stringify(Me(a[x]))&&t.push(`${s}: ${x} \u4E0E ${l} \u5E03\u5C40\u51B2\u7A81\uFF0C\u4FDD\u7559${o[l]?"\u5DF2\u6709\u5E73\u53F0":m}\u53C2\u6570`)}Be(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 vr(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 Sr(e,t,i,r=e.canvasId){let n=Ue(e.root,t);return!n||n.kind==="server-container"?ye(r):i[n.id]||ye(r)}function We(e,{warnings:t=[]}={}){if(!e)return nt();if(e=ho(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"?It():nt(),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&&K[e.canvasId]?e.canvasId:di,selectedId:e.selectedId||r.selectedId,root:cr(e.root||r.root)};return vo(n),n}function vo(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=lr(e.root).id)}function po(e){return Le(Ct(e))}function Us(e,t){let i=!1;return J(e,r=>{r.id===t&&(i=!0)}),i}function Hs(e,t,i,r){let o=Xe(e.root,e.canvasId).boxes[t.id],a=i.children.findIndex(p=>p.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=Xe(e.root,e.canvasId),c=r.kind==="server-container"?ye(e.canvasId):s.boxes[r.id]||ye(e.canvasId),l=He(t.transformByPlatform,e.canvasId),f=et(c,l,{posX:o.centerX,posY:o.centerY,width:o.width,height:o.height});Et(e,t,f)}function Xs(e,t){return e.meta.assetType!=="client-control-template"?ur(e.root,t):(e.root.children||[]).flatMap(i=>ur(i,t))}function bo(e,t){let i=Vn(e.root,t);if(e.meta.assetType!=="client-control-template")return i;let r=Lt(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 So(e){let{canvas:t,boxes:i}=Xe(e.root,e.canvasId),r=Xt(e),n=ue(e.root,e.selectedId),o=n?i[n.id]:null;return G({layoutSchemaVersion:me,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(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"&&Lt(e)?.id||""},tree:Xs(e,r),boxes:bo(e,i),inspector:Yn(n,e.canvasId,o||t,r),root:e.root})}function Et(e,t,i){let r=Xe(e.root,e.canvasId),n=Sr(e,t.id,r.boxes),o={};if(t.syncAllDevices!==!1)for(let a of le){if(a===tt(e.canvasId))continue;let s=yt[a],c=Xe(e.root,s,a);o[a]=Sr(e,t.id,c.boxes,s)}t.transformByPlatform=zn({transformByPlatform:t.transformByPlatform,source:i,canvasId:e.canvasId,syncAllDevices:t.syncAllDevices!==!1,sourceParentBox:n,targetParentBoxByPlatform:o})}var Ks=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"]),Ws=new Set(["posX","posY","width","height"]),js=new Set(["anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]);function qs(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 $e(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function mo(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 Js=new Set(["fontSize","minimumFontSize","imageId","clickAudioId","softEdgeWidthX","softEdgeWidthY","horizontalSoftRange","verticalSoftRange","fillAmount","cellSizeX","cellSizeY","spacingX","spacingY","padding1X","padding1Y","padding2X","padding2Y","previewCount","keyboardKeyCode","controllerKeyCode"]),Zs=new Set(["active","visible","canControllerFocus","isolateNavigation","disableKeyEventPassthrough","disableCursorEventPassthrough","showCursor","adaptiveFontSize","enableOutline","enableMask","enableSoftEdge","enableFill","reverseMaskArea","raycastTarget","interactable","showScrollBar"]),Qs=new Set(["name","horizontalAlignment","verticalAlignment","text","softEdgeMode","fillType","fillHorizontalType","fillVerticalType","fillRadial90Type","fillRadialType","scrollDirection","layoutConstraint","referencedPrefabId","animationId"]),go=new Set(["unavailableChildId","hoverChildId","pressedChildId","selectedChildId"]),yo={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 el(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}=Xe(e.root,e.canvasId),n=bo(e,r),o=Bn(n,Number(t.x),Number(t.y));return o&&(e.selectedId=o),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"?It():nt();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:sr(e.root),guid:po(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=Dn(r,t.kind,{id:sr(e.root),guid:po(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?Ue(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||Us(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 Hs(e,r,n,o),e.selectedId=r.id,e}if(i==="moveSibling"){let r=ue(e.root,t.id||e.selectedId),n=r?Ue(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=Ue(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 $n(e.root,r)&&(J(e.root,o=>{if(o.kind==="button")for(let a of go)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 f=Nn(r.kind,l);if(!f)throw new Error(`unknown raw GIA field for ${r.kind}: ${l}`);if(r.giaRaw||={},r.giaRaw[l]=ir(f,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 p={0:"Left",1:"Middle",2:"Right"}[r.giaRaw[l]];p&&(r.horizontalAlignment=p)}if(r.kind==="image"&&l==="imageFillType"){let p={1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[r.giaRaw[l]];p&&(r.fillType=p)}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=mo(o),r.syncAllDevices){let l=He(r.transformByPlatform,e.canvasId);Et(e,r,l)}return e}if(Ks.has(n)){if(n.endsWith("Color")&&(o=qs(o)),Js.has(n)){if(o=$e(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(Zs.has(n)&&(o=mo(o)),Qs.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(yo[n]&&!yo[n].includes(o))throw new Error(`invalid ${n}`);if(go.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(f=>f.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}=Xe(e.root,e.canvasId),s=Sr(e,r.id,a),c=He(r.transformByPlatform,e.canvasId);if(n==="anchorType"){let l=br(a[r.id]),f=_n(c,o);return f=et(s,f,l),Et(e,r,f),e}if(n==="rotationZ"){let l={...c,rotation:{...c.rotation,z:$e(o,n)}};return Et(e,r,l),e}if(js.has(n)){let l=br(a[r.id]),f={...c,anchorMin:{...c.anchorMin},anchorMax:{...c.anchorMax},pivot:{...c.pivot}};return n==="anchorMinX"&&(f.anchorMin.x=$e(o,n)),n==="anchorMinY"&&(f.anchorMin.y=$e(o,n)),n==="anchorMaxX"&&(f.anchorMax.x=$e(o,n)),n==="anchorMaxY"&&(f.anchorMax.y=$e(o,n)),n==="pivotX"&&(f.pivot.x=$e(o,n)),n==="pivotY"&&(f.pivot.y=$e(o,n)),Et(e,r,et(s,f,l)),e}if(Ws.has(n)){let l=br(a[r.id]),f=$e(o,n);if((n==="width"||n==="height")&&f<0)throw new Error(`${n} must not be negative`);return l[n]=f,Et(e,r,et(s,c,l)),e}throw new Error(`set: unknown key ${n}`)}if(i==="replace"){let r=We(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 wr(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 el(r,t),vo(r),r.version=i+1,Object.keys(e).forEach(n=>{delete e[n]}),Object.assign(e,r),e}function br(e){return e?{posX:e.centerX,posY:e.centerY,width:e.width,height:e.height}:{posX:0,posY:0,width:0,height:0}}import tl from"fengari";var{lua:u,lauxlib:ee,lualib:wo,to_luastring:Ii,to_jsstring:il}=tl,rl=u.LUA_TNIL,nl=u.LUA_TBOOLEAN,ol=u.LUA_TNUMBER,al=u.LUA_TSTRING,Co=u.LUA_TTABLE,sl=u.LUA_TFUNCTION,Cr=u.LUA_TUSERDATA,xe=u.LUA_OK,Io=new WeakMap,Ir=Symbol("luaTableEntries"),kr={__scriptHostKey:!0};function P(e){return Ii(String(e))}function ot(e,t){Io.set(e,t)}function Ce(e){return Io.get(e)}var Kt=class{constructor(t){this.value=t}};function ae(e,t,i){if(i instanceof Kt){u.lua_pushnumber(e,i.value);return}if(i==null){u.lua_pushnil(e);return}let r=typeof i;if(r==="boolean"){u.lua_pushboolean(e,i);return}if(r==="number"){Number.isInteger(i)&&Math.abs(i)<=2147483647?u.lua_pushinteger(e,i):u.lua_pushnumber(e,i);return}if(r==="string"){u.lua_pushstring(e,P(i));return}if(r==="function"){ul(e,t,i);return}if(i&&i[Ir]){let n=i[Ir];u.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),u.lua_settable(e,-3);return}if(Array.isArray(i)){u.lua_createtable(e,i.length,0);for(let n=0;n<i.length;n++)ae(e,t,i[n]),u.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"){u.lua_createtable(e,0,Object.keys(i).length);for(let[n,o]of Object.entries(i))ae(e,t,o),u.lua_setfield(e,-2,P(n));return}u.lua_pushnil(e)}function q(e,t){if(u.lua_isnil(e,t)||u.lua_type(e,t)===u.LUA_TNONE)return"";if(!u.lua_isstring(e,t)&&u.lua_type(e,t)!==u.LUA_TNUMBER)return`lua_type=${u.lua_type(e,t)}`;let i=u.lua_tostring(e,t);return i==null?"":il(i)}function Ge(e,t){t=u.lua_absindex(e,t);let i=u.lua_type(e,t);if(i===Cr)return Ce(u.lua_touserdata(e,t));if(i===Co){u.lua_pushlightuserdata(e,kr),u.lua_rawget(e,t);let r=u.lua_type(e,-1)===Cr?u.lua_touserdata(e,-1):null;return u.lua_pop(e,1),r?Ce(r):null}return null}function de(e,t,i){i=u.lua_absindex(e,i);let r=u.lua_type(e,i);if(r===rl)return null;if(r===nl)return!!u.lua_toboolean(e,i);if(r===ol)return u.lua_isinteger(e,i)?u.lua_tointeger(e,i):u.lua_tonumber(e,i);if(r===al)return q(e,i);if(r===Cr){let n=u.lua_touserdata(e,i);return Ce(n)??n}if(r===sl)return ll(e,t,i);if(r===Co){let n=Ge(e,i);if(n)return n;let o=[];for(u.lua_pushnil(e);u.lua_next(e,i)!==0;){let l=de(e,t,-2),f=de(e,t,-1);o.push([l,f]),u.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,f]of o)Array.isArray(c)&&Number.isInteger(l)&&l>=1?c[l-1]=f:(typeof l=="string"||typeof l=="number")&&(c[l]=f);return Object.defineProperty(c,Ir,{value:o}),c}return null}function ll(e,t,i){t.luaFunctions||(t.luaFunctions=new Map);let r=typeof u.lua_topointer=="function"?u.lua_topointer(e,i):null;if(r!=null&&t.luaFunctions.has(r))return t.luaFunctions.get(r);u.lua_pushvalue(e,i);let n=ee.luaL_ref(e,u.LUA_REGISTRYINDEX),o=cl(e,t,n);return r!=null&&t.luaFunctions.set(r,o),o}function cl(e,t,i){let r=(...n)=>{if(r.__luaRef==null)throw new Error("attempt to call a released Lua callback");let o=u.lua_gettop(e);u.lua_rawgeti(e,u.LUA_REGISTRYINDEX,r.__luaRef);for(let l of n)ae(e,t,l);if(u.lua_pcall(e,n.length,u.LUA_MULTRET,0)!==xe){let l=q(e,-1);throw u.lua_settop(e,o),new Error(l)}let s=u.lua_gettop(e)-o,c=[];for(let l=1;l<=s;l++)c.push(de(e,t,o+l));if(u.lua_settop(e,o),c.length!==0)return c.length===1?c[0]:c};return r.__luaRef=i,r.__luaState=e,r}function ko(e){e?.__luaRef!=null&&(e.__luaHolds=(e.__luaHolds||0)+1)}function Eo(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,u.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 ul(e,t,i){u.lua_pushlightuserdata(e,i),u.lua_pushlightuserdata(e,t),u.lua_pushcclosure(e,function(n){let o=u.lua_touserdata(n,u.lua_upvalueindex(1)),a=u.lua_touserdata(n,u.lua_upvalueindex(2)),s=u.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 f of l)ae(n,a,f);return l.length}return l===void 0?0:(ae(n,a,l),1)}catch(l){return u.lua_pushstring(n,P(String(l&&l.message?l.message:l))),u.lua_error(n)}},2)}function xo(e){!e||typeof u.lua_close!="function"||u.lua_close(e)}function Ao(e){if(ee.luaL_loadstring(e,P(["local nativeGetMetatable = getmetatable","getmetatable = function(value)",' if type(value) == "string" then return nil end'," return nativeGetMetatable(value)","end"].join(`
108
+ `)))===xe&&u.lua_pcall(e,0,0,0),u.lua_settop(e,0),u.lua_pushnil(e),u.lua_setglobal(e,P("_VERSION")),u.lua_getglobal(e,P("string")),!u.lua_isnil(e,-1))for(let i of["dump","pack","unpack"])u.lua_pushnil(e),u.lua_setfield(e,-2,P(i));if(u.lua_pop(e,1),u.lua_pushnil(e),u.lua_setglobal(e,P("io")),u.lua_getglobal(e,P("os")),!u.lua_isnil(e,-1))for(let i of Object.keys({execute:1,getenv:1,remove:1,rename:1,tmpname:1,setlocale:1,exit:1}))u.lua_pushnil(e),u.lua_setfield(e,-2,P(i));u.lua_pop(e,1),u.lua_getglobal(e,P("debug")),u.lua_isnil(e,-1)?u.lua_pop(e,1):(u.lua_getfield(e,-1,P("traceback")),u.lua_newtable(e),u.lua_pushvalue(e,-2),u.lua_setfield(e,-2,P("traceback")),u.lua_setglobal(e,P("debug")),u.lua_pop(e,2)),u.lua_getglobal(e,P("math")),u.lua_isnil(e,-1)||(u.lua_pushcfunction(e,i=>{let r=u.lua_tonumber(i,1);return u.lua_pushboolean(i,Number.isNaN(r)),1}),u.lua_setfield(e,-2,P("isnan")),u.lua_pushcfunction(e,i=>{let r=u.lua_tonumber(i,1);return u.lua_pushboolean(i,r===1/0||r===-1/0),1}),u.lua_setfield(e,-2,P("isinf"))),u.lua_pop(e,1),u.lua_pushnil(e),u.lua_setglobal(e,P("package")),u.lua_pushnil(e),u.lua_setglobal(e,P("load")),u.lua_pushnil(e),u.lua_setglobal(e,P("loadfile")),u.lua_pushnil(e),u.lua_setglobal(e,P("dofile")),u.lua_pushnil(e),u.lua_setglobal(e,P("collectgarbage")),u.lua_pushnil(e),u.lua_setglobal(e,P("coroutine")),u.lua_pushnil(e),u.lua_setglobal(e,P("fengari"))}var _o={container:"ClientUIContainerControl",textbox:"ClientUITextBoxControl",textwindow:"ClientUITextWindowControl",image:"ClientUIImageControl",button:"ClientUIPresetButtonControl",cursor:"ClientUICursorEventAreaControl",grid:"ClientUIGridScrollerControl",keyhint:"ClientUIKeyHintControl",animation:"ClientUIAnimationControl",fullscreen:"ClientUIFullscreenAnimationControl",reference:"ClientUIReferenceControl"},fl=["alive","Id","prefabIndex","active","activeInHierarchy","visible"],ki=new Set(["active","visible","parent","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]),dl=["name","parent","anchoredPositionX","anchoredPositionY","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY","localScaleX","localScaleY","localScaleZ","localRotationX","localRotationY","localRotationZ","canControllerFocus"],hl={image:["imageSource","imageId"],grid:["itemCount","scrollDirection","layoutConstraint","layoutConstraintFixedCount"],reference:["referencedPrefabIndex"]},pl={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"]},ml=["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"],Po=["AddCursorEventListener","RemoveCursorEventListener","RemoveCursorEventListeners","RemoveAllCursorEventListeners","SimulateCursorClick"],gl={image:["SetImage","SetSoftEdgeWidth","SetFillUnused","SetFillHorizontal","SetFillVertical","SetFillRadial90","SetFillRadial180","SetFillRadial360"],button:Po,cursor:Po,animation:["PlayAnimation","StopAnimation"],grid:["RefreshItems","GetItemIndex","GetItemSize","GetItemSpacing","GetPadding","ScrollToItemAt","GetContentLength"]};function xr(e,t){return fl.includes(t)||(hl[e.kind]||[]).includes(t)?"ro":dl.includes(t)||(pl[e.kind]||[]).includes(t)?"rw":null}var yl=["localRotationX","localRotationY","localRotationZ"],xt=Math.PI/180;function Ro(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 Er(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 To(e,t,i){let r=A=>[Math.sin(A*xt/2),Math.cos(A*xt/2)],[n,o]=r(e),[a,s]=r(t),[c,l]=r(i),[f,p,d,m]=Ro(Ro([0,a,0,s],[n,0,0,o]),[0,0,c,l]),y=Math.max(-1,Math.min(1,-2*(p*d-m*f))),v,x,I;return Math.abs(y)>.999999?(v=Math.sign(y)*90,x=2*Math.atan2(p,m)/xt,I=0):(v=Math.asin(y)/xt,x=Math.atan2(2*(m*p+f*d),1-2*(f*f+p*p))/xt,I=Math.atan2(2*(m*d+f*p),1-2*(f*f+d*d))/xt),[Er(v),Er(x),Er(I)]}function Mo(e,t){return ml.includes(t)||(gl[e.kind]||[]).includes(t)}var vl={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=_o[this.kind]||_o.container,this.alive=!0,this.Id=i.Id??t.nextControlId(),this.authoringId=i.authoringId??null,this.prefabIndex=i.prefabIndex??0,this.name=i.name??"",this.active=i.active===!0,this.visible=i.visible!==!1,this._parent=null,this.children=[],this.scripts=[],this.cursorListeners=new Map,this.keyListeners=new Map,this.navListeners=new Map,this.navConfig=new Map,this.anchoredPositionX=i.anchoredPositionX??0,this.anchoredPositionY=i.anchoredPositionY??0,this.sizeDeltaX=i.sizeDeltaX??0,this.sizeDeltaY=i.sizeDeltaY??0,this.anchorMinX=i.anchorMinX??.5,this.anchorMinY=i.anchorMinY??.5,this.anchorMaxX=i.anchorMaxX??.5,this.anchorMaxY=i.anchorMaxY??.5,this.pivotX=i.pivotX??.5,this.pivotY=i.pivotY??.5,this.localScaleX=i.localScaleX??1,this.localScaleY=i.localScaleY??1,this.localScaleZ=i.localScaleZ??1,this.localRotationX=i.localRotationX??0,this.localRotationY=i.localRotationY??0,this.localRotationZ=i.localRotationZ??0,this.canControllerFocus=i.canControllerFocus??!1,this._playDirty=!0,this._playDeepDirty=!0,this._playChildDirty=!1;let r=vl[this.kind]||{};for(let[n,o]of Object.entries(r))this[n]===void 0&&(this[n]=i[n]!==void 0?i[n]:o);if(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}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 To(this.localRotationX,this.localRotationY,this.localRotationZ)}luaFieldValue(t){let i=yl.indexOf(t);return i<0?this[t]:To(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(){throw new Error("ClientUIGridScrollerControl:RefreshItems not implemented")}GetItemIndex(){throw new Error("ClientUIGridScrollerControl:GetItemIndex not implemented")}GetItemSize(){throw new Error("ClientUIGridScrollerControl:GetItemSize not implemented")}GetItemSpacing(){throw new Error("ClientUIGridScrollerControl:GetItemSpacing not implemented")}GetPadding(){throw new Error("ClientUIGridScrollerControl:GetPadding not implemented")}ScrollToItemAt(){throw new Error("ClientUIGridScrollerControl:ScrollToItemAt not implemented")}GetContentLength(){throw new Error("ClientUIGridScrollerControl:GetContentLength not implemented")}};function Ne(e,t){t(e);for(let i of e.children)Ne(i,t)}function Ar(e,t=[],i=""){t.push(`${i}${e.name||"(unnamed)"} [${e.typeofName}] Id=${e.Id}`);for(let r of e.children)Ar(r,t,i+" ");return t}function Ei(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 No={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-Ei(1-e),OutBounce:Ei,InOutBounce:e=>e<.5?(1-Ei(1-2*e))/2:(1+Ei(2*e-1))/2};function Fo(e,t){let i=No[e]||No.Linear;return t<=0?0:t>=1?1:i(t)}function At(e,t,i,r=255){let n=xi(e),o=xi(t),a=xi(i);return((r==null?255:xi(r))<<24|n<<16|o<<8|a)>>>0}function Wt(e){let t=e>>>0;return[t>>>16&255,t>>>8&255,t&255,t>>>24&255]}function xi(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(255,Math.trunc(t))):0}function Oo(e,t,i){let r=Wt(e),n=Wt(t);return At(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 bl=new Set(["fontColor","bgColor","outlineColor","imageColor"]),Sl=new Set(["fontSize","minimumFontSize"]),_r=1e-9;function wl(e,t){return typeof e?.luaFieldValue=="function"?e.luaFieldValue(t):e[t]}var jt=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=wl(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=Fo(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(bl.has(o)&&typeof a=="number"&&typeof s=="number")this.object[o]=Oo(a,s,i);else if(typeof a=="number"&&typeof s=="number"){let c=a+(s-a)*i;this.object[o]=Sl.has(o)?Math.trunc(c):c}else this.object[o]=i>=1?s:a;r=!0,ki.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)}},_t=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+_r&&n.push({at:a.at,rank:a.fn?1:2,entry:a}),a.tween&&!a.done&&a.end<=t+_r&&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+_r<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 Ai={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"]},Cl=[...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"],Il=[...Array.from({length:14},(e,t)=>`CraftspersonKey${t+1}`),"SprintKey","JumpKey","InteractKey","NormalAttackKey","CharacterSkill1Key","CharacterSkill2Key","CharacterSkill3Key","CharacterSkill4Key","MenuConfirmKey","MenuBackKey","None"];function kl(){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}Ai.KeyboardKeyCode=Cl;Ai.ControllerKeyCode=Il;Ai.KeyEventType=kl();var Do=new Map;function at(e,t){let i=`${e}\0${t}`,r=Do.get(i);return r||(r={__kind:"EnumItem",Name:t,FullName:`Enum.${e}.${t}`,EnumType:e},Do.set(i,r)),r}function Pr(e,t){return t==null?t:t.__kind==="EnumItem"?at(t.EnumType||e,t.Name):typeof t=="string"&&t?at(e,t):t}function Rr(){let e={};for(let[t,i]of Object.entries(Ai)){let r={};for(let n of i)r[n]=at(t,n);e[t]=r}return e}var El=new Set(["Id","prefabIndex","imageId","fontSize","minimumFontSize","clickAudioId","itemCount","itemPrefabIndex","animationId","referencedPrefabIndex"]),xl=new Set(["imageColor","fontColor","bgColor","outlineColor"]),$o={horizontalAlignment:"TextHorizontalAlignment",verticalAlignment:"TextVerticalAlignment",imageSource:"ImageSource",fillType:"ImageFillType",fillHorizontalType:"ImageFillHorizontalType",fillVerticalType:"ImageFillVerticalType",fillRadial90Type:"ImageFillRadial90Type",fillRadialType:"ImageFillRadialType",softEdgeMode:"ImageMaskSoftEdgeMode",layer:"UIAnimationLayer",scrollDirection:"ScrollDirection",layoutConstraint:"ScrollLayoutConstraint"},st=u.LUA_REGISTRYINDEX,Go=u.LUA_MULTRET,Al=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 ve(e){return e==null?"":typeof e=="string"?e:e.Name||e.FullName||String(e)}var _i=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._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=Rr(),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?u.lua_pushinteger(t,r):u.lua_pushnumber(t,r)}retainLuaCallback(t){ko(t)}unrefLuaCallback(t){Eo(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),Ne(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(f){let p=f&&f.message?f.message:String(f);this.mountErrors.push(p),this.log("lua-error",p)}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;u.lua_pushcfunction(t,r=>{let n=u.lua_gettop(r),o=[];for(let a=1;a<=n;a++)o.push(de(r,i,a));return i.log("info",...o),0}),u.lua_setglobal(t,P("print")),u.lua_pushcfunction(t,r=>{let n=u.lua_gettop(r),o=[];for(let a=1;a<=n;a++)o.push(de(r,i,a));return i.log("error",...o),0}),u.lua_setglobal(t,P("printerr")),u.lua_pushcfunction(t,r=>{if(u.lua_type(r,1)===u.LUA_TTABLE&&!Ge(r,1))return u.lua_pushstring(r,P("table")),1;let n=de(r,i,1);return u.lua_pushstring(r,P(i.typeofOf(n))),1}),u.lua_setglobal(t,P("typeof")),this.pushColorLib(t),this.pushEnumLib(t),this.pushGameLib(t),u.lua_pushcfunction(t,r=>i.luaRequire(r)),u.lua_setglobal(t,P("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 _t?"TweenSequence":t instanceof jt?"Tween":t.typeofName?t.typeofName:typeof t=="number"?"number":typeof t=="string"?"string":typeof t=="boolean"?"boolean":typeof t}pushColorLib(t){u.lua_newtable(t),u.lua_pushcfunction(t,i=>(this.pushPackedColor(i,At(u.lua_tonumber(i,1),u.lua_tonumber(i,2),u.lua_tonumber(i,3),255)),1)),u.lua_setfield(t,-2,P("FromRGB")),u.lua_pushcfunction(t,i=>{let r=u.lua_isnoneornil(i,4)?255:u.lua_tonumber(i,4);return this.pushPackedColor(i,At(u.lua_tonumber(i,1),u.lua_tonumber(i,2),u.lua_tonumber(i,3),r)),1}),u.lua_setfield(t,-2,P("FromRGBA")),u.lua_pushcfunction(t,i=>{let r=u.lua_tonumber(i,1)>>>0;for(let n of Wt(r))u.lua_pushinteger(i,n);return 4}),u.lua_setfield(t,-2,P("ToRGBA")),u.lua_newtable(t),u.lua_pushcfunction(t,i=>{let r=u.lua_tonumber(i,2),n=u.lua_tonumber(i,3),o=u.lua_tonumber(i,4),a=u.lua_isnoneornil(i,5)?255:u.lua_tonumber(i,5);return this.pushPackedColor(i,At(r,n,o,a)),1}),u.lua_setfield(t,-2,P("__call")),u.lua_setmetatable(t,-2),u.lua_setglobal(t,P("Color"))}pushEnumLib(t){u.lua_newtable(t);for(let[i,r]of Object.entries(this.enumTree)){u.lua_newtable(t);for(let[n,o]of Object.entries(r))this.pushEnumItem(t,o),u.lua_setfield(t,-2,P(n));u.lua_setfield(t,-2,P(i))}u.lua_setglobal(t,P("Enum"))}pushEnumItem(t,i){let r=u.lua_newuserdata(t,0);ot(r,i),ee.luaL_setmetatable(t,P("EnumItem"))}pushControl(t,i){let r=u.lua_newuserdata(t,0);ot(r,i),ee.luaL_setmetatable(t,P("Control"))}pushScript(t,i){u.lua_newtable(t),u.lua_pushlightuserdata(t,kr);let r=u.lua_newuserdata(t,0);ot(r,i),u.lua_rawset(t,-3),ee.luaL_getmetatable(t,P("Script")),u.lua_setmetatable(t,-2)}pushTween(t,i){let r=u.lua_newuserdata(t,0);ot(r,i);let n=i instanceof _t?"TweenSequence":"Tween";ee.luaL_setmetatable(t,P(n))}pushSignal(t,i){let r=u.lua_newuserdata(t,0);ot(r,i),ee.luaL_setmetatable(t,P("ServerSignal"))}pushCursor(t,i){let r=u.lua_newuserdata(t,0);ot(r,i),ee.luaL_setmetatable(t,P("CursorEventData"))}pushGameLib(t){let i=this;u.lua_newtable(t);let r={InstantiateClientUIControl:n=>{let o=u.lua_tointeger(n,1),a=Ce(u.lua_touserdata(n,2)),s=i.instantiate(o,a,i.lifecyclePhase);return s?(i.pushControl(n,s),1):(u.lua_pushnil(n),1)},DestroyClientUIControl:n=>{let o=Ce(u.lua_touserdata(n,1));return o&&i.destroyControl(o),0},GetClientUIControl:n=>{let o=u.lua_tointeger(n,1),a=i.controlsById.get(o);return a?i.pushControl(n,a):u.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):u.lua_pushnil(n),1},GetClientUIRoots:n=>(u.lua_createtable(n,i.roots.length,0),i.roots.forEach((o,a)=>{i.pushControl(n,o),u.lua_rawseti(n,-2,a+1)}),1),GetUICanvasSize:n=>(u.lua_pushnumber(n,i.canvasWidth),u.lua_pushnumber(n,i.canvasHeight),2),GetCursorUIPos:n=>(u.lua_pushnumber(n,i.cursor.x),u.lua_pushnumber(n,i.cursor.y),2),GetDevice:n=>(i.pushEnumItem(n,at("Device",i.device)),1),SetControllerFocus:n=>(i.focus=Ce(u.lua_touserdata(n,1)),0),GetControllerFocus:n=>(i.focus?i.pushControl(n,i.focus):u.lua_pushnil(n),1),GetControllerLeftStickAxis:n=>(u.lua_pushnumber(n,i.stick.left[0]),u.lua_pushnumber(n,i.stick.left[1]),2),GetControllerRightStickAxis:n=>(u.lua_pushnumber(n,i.stick.right[0]),u.lua_pushnumber(n,i.stick.right[1]),2),Tween:n=>{let o=Ce(u.lua_touserdata(n,1))||de(n,i,1),a=de(n,i,2)||{},s=u.lua_tonumber(n,3),c=new jt(i,o,a,s);return i.pushTween(n,c),1},TweenSequence:n=>(i.pushTween(n,new _t(i)),1),ServerSignal:n=>{let o=q(n,1);return i.pushSignal(n,i.makeServerSignal(o)),1},GetGlobalCustomVariableValue:n=>{let o=ve(de(n,i,1)),a=q(n,2);return ae(n,i,i.getVar(o,a)),1},PauseLevelTime:n=>(i.clock.paused=!!u.lua_toboolean(n,1),0),IsLevelTimePaused:n=>(u.lua_pushboolean(n,i.clock.paused),1),PlayAudio2D:n=>{let o=i.nextAudioId++;return i.audios.set(o,{audioId:u.lua_tointeger(n,1),alive:!0}),u.lua_pushinteger(n,o),1},StopAudio:n=>{let o=u.lua_tointeger(n,1),a=i.audios.get(o);return a&&(a.alive=!1),0},IsAudioAlive:n=>{let o=i.audios.get(u.lua_tointeger(n,1));return u.lua_pushboolean(n,!!(o&&o.alive)),1},GetLanguageType:n=>(i.pushEnumItem(n,at("LanguageType",i.language)),1),GetStageMode:n=>(i.pushEnumItem(n,at("StageMode",i.stageMode)),1),IsTestPlay:n=>(u.lua_pushboolean(n,i.testPlay),1),GetText:n=>{let o=q(n,1);return u.lua_pushstring(n,P(o)),1},PrintClientUITree:n=>{for(let o of i.roots)i.log("info",Ar(o).join(`
109
+ `));return 0}};for(let[n,o]of Object.entries(r)){let a=Al[n];if(a===void 0)throw new Error(`missing game arity for ${n}`);u.lua_pushcfunction(t,s=>{let c=u.lua_gettop(s);return c!==a?ee.luaL_error(s,P(`bad argument count to '${n}' (${a} expected, got ${c})`)):o(s)}),u.lua_setfield(t,-2,P(n))}u.lua_setglobal(t,P("game"))}makeServerSignal(t){let i=[],r=this;return{__kind:"ServerSignal",name:t,AddParam(n,o){i.push({type:ve(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)}}}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(),Ne(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}`);Ne(t,i=>{i._destroying=!0}),this._destroyControlTree(t)}}_destroyControlTree(t){this.releaseControlListeners(t);for(let i of t.scripts.slice())this.unmountScript(i);for(let i of t.children.slice())this._destroyControlTree(i);if(t.alive=!1,this._playRemoved.push(t.Id),t.parent){let i=t.parent,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=[];Ne(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),u.lua_setglobal(i,P("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){ee.luaL_newmetatable(t,P(i)),u.lua_pushcfunction(t,s=>{let c=Ge(s,1)||Ce(u.lua_touserdata(s,1)),l=q(s,2);if(o[l]&&(!a||a(c,l)))return u.lua_pushcfunction(s,o[l]),1;let f;try{f=r(c,l)}catch(p){return ee.luaL_error(s,P(String(p.message||p)))}return f===void 0?(u.lua_pushnil(s),1):(ae(s,this,f),1)}),u.lua_setfield(t,-2,P("__index")),u.lua_pushcfunction(t,s=>{try{let c=Ge(s,1)||Ce(u.lua_touserdata(s,1)),l=q(s,2),f=de(s,this,3);return n(c,l,f),0}catch(c){return u.lua_pushstring(s,P(String(c.message||c))),u.lua_error(s)}}),u.lua_setfield(t,-2,P("__newindex")),u.lua_pushcfunction(t,s=>{let c=Ge(s,1)||Ce(u.lua_touserdata(s,1)),l=Ge(s,2)||Ce(u.lua_touserdata(s,2));return u.lua_pushboolean(s,c===l),1}),u.lua_setfield(t,-2,P("__eq")),u.lua_pop(t,1)}method(t){let i=this;return r=>{let n=Ge(r,1)||Ce(u.lua_touserdata(r,1)),o=u.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 u.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 u.lua_createtable(r,s.length,0),s.forEach((c,l)=>{i.pushControl(r,c),u.lua_rawseti(r,-2,l+1)}),1;if(s.__scripts)return u.lua_createtable(r,s.length,0),s.forEach((c,l)=>{i.pushScript(r,c),u.lua_rawseti(r,-2,l+1)}),1;if(typeof s[0]=="number"&&s.length<=4){for(let c of s)u.lua_pushnumber(r,c);return s.length}}return ae(r,i,s),1}catch(s){return u.lua_pushstring(r,P(String(s.message||s))),u.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(ve(n),o)),RemoveCursorEventListener:this.method((r,n,o)=>r.RemoveCursorEventListener(ve(n),o)),RemoveCursorEventListeners:this.method((r,n)=>r.RemoveCursorEventListeners(ve(n))),RemoveAllCursorEventListeners:this.method(r=>r.RemoveAllCursorEventListeners()),SimulateCursorClick:this.method(r=>r.SimulateCursorClick()),AddKeyEventListener:this.method((r,n,o)=>r.AddKeyEventListener(ve(n),o)),RemoveKeyEventListener:this.method((r,n,o)=>r.RemoveKeyEventListener(ve(n),o)),RemoveKeyEventListeners:this.method((r,n)=>r.RemoveKeyEventListeners(ve(n))),RemoveAllKeyEventListeners:this.method(r=>r.RemoveAllKeyEventListeners()),AddNavigationEventListener:this.method((r,n,o)=>r.AddNavigationEventListener(ve(n),o)),RemoveNavigationEventListener:this.method((r,n,o)=>r.RemoveNavigationEventListener(ve(n),o)),RemoveNavigationEventListeners:this.method((r,n)=>r.RemoveNavigationEventListeners(ve(n))),RemoveAllNavigationEventListeners:this.method(r=>r.RemoveAllNavigationEventListeners()),SetControllerNavigation:this.method((r,n,o,a)=>r.SetControllerNavigation(ve(n),o,a)),GetControllerNavigation:this.method((r,n)=>r.GetControllerNavigation(ve(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=>r.RefreshItems()),GetItemIndex:this.method(r=>r.GetItemIndex()),GetItemSize:this.method(r=>r.GetItemSize()),GetItemSpacing:this.method(r=>r.GetItemSpacing()),GetPadding:this.method(r=>r.GetPadding()),ScrollToItemAt:this.method(r=>r.ScrollToItemAt()),GetContentLength:this.method(r=>r.GetContentLength())};this.mtIndexNewindex(t,"Control",(r,n)=>{if(!xr(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=$o[n];return a?Pr(a,o):typeof o=="number"&&!El.has(n)&&!xl.has(n)?new Kt(o):o},(r,n,o)=>{if(xr(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=$o[n];r[n]=s?Pr(s,o):o,typeof r.markPlayDirty=="function"&&r.markPlayDirty(ki.has(n));return}throw new Error(`cannot set ${n}, no such field`)},i,Mo)}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:ve(o),name:a,fn:s})}),UnregisterCustomVariableChangedHandler:this.method((n,o,a)=>{let s=ve(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;u.lua_rawgeti(t,st,u.LUA_RIDX_MAINTHREAD);let o=u.lua_tothread(t,-1);u.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 u.lua_pushstring(t,P(`failed to load script '${r}': cyclic require`)),u.lua_error(t);if(s&&s.ref!=null)return u.lua_rawgeti(t,st,s.ref),1;let c=this.scriptFiles.get(n);if(c==null)return u.lua_pushstring(t,P(`failed to load script '${r}'`)),u.lua_error(t);let l=u.lua_gettop(t);a.set(n,{loading:!0});try{this.loadModule(t,o,n,c),u.lua_pushvalue(t,-1);let f=ee.luaL_ref(t,st);return a.set(n,{ref:f}),1}catch(f){return a.delete(n),u.lua_settop(t,l),u.lua_pushstring(t,P(`failed to load script '${r}': ${f.message||f}`)),u.lua_error(t)}}newLuaThread(){let t=ee.luaL_newstate();return wo.luaL_openlibs(t),Ao(t),this.installMetatables(t),this.installGlobals(t),this.luaStates.add(t),u.lua_pushglobaltable(t),this.copyLuaEnvironment(t,-1),u.lua_remove(t,-2),this.moduleBaseEnvironments.set(t,ee.luaL_ref(t,st)),t}copyLuaEnvironment(t,i){let r=u.lua_absindex(t,i);u.lua_newtable(t);let n=u.lua_absindex(t,-1);for(u.lua_pushnil(t);u.lua_next(t,r)!==0;)u.lua_pushvalue(t,-2),u.lua_pushvalue(t,-2),u.lua_rawset(t,n),u.lua_pop(t,1);u.lua_pushvalue(t,n),u.lua_setfield(t,n,P("_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,st,r.ref);this.requireCache.delete(t);let i=this.moduleBaseEnvironments.get(t);if(i!=null&&ee.luaL_unref(t,st,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);xo(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=Ii(a);if(ee.luaL_loadbuffer(t,s,s.length,P(`@${r}`))!==xe)throw new Error(q(t,-1));let l=u.lua_absindex(t,-1);if(u.lua_rawgeti(t,st,this.moduleBaseEnvironments.get(i)),this.copyLuaEnvironment(t,-1),u.lua_remove(t,-2),this.pushScript(t,o),u.lua_setfield(t,-2,P("script")),u.lua_setupvalue(t,l,1),u.lua_pcall(t,0,1,0)!==xe)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,f)=>this.invokeOn(a,l,f),r&&r.scripts.push(s),this.mountedScripts.push(s),this.pushScript(a,s),u.lua_setglobal(a,P("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 f=this.callGlobal(a,"OnEnable");f&&this.mountErrors.push(f),this.lifecyclePhase="OnStart",s.lifecyclePhase="OnStart";let p=this.callGlobal(a,"OnStart");return p&&this.mountErrors.push(p),this.lifecyclePhase="running",s.lifecyclePhase="running",s}catch(l){throw s.alive=!1,s.lifecyclePhase="failed",this.mountedScripts=this.mountedScripts.filter(f=>f!==s),r&&(r.scripts=r.scripts.filter(f=>f!==s)),this.varHandlers=this.varHandlers.filter(f=>f.script!==s),this.signalHandlers=this.signalHandlers.filter(f=>f.script!==s),this.lifecyclePhase=c,a&&a!==this.L&&this.closeTrackedLuaState(a),s.env=null,l}}runChunk(t,i,r){let n=String(i).replace(/^\uFEFF/,""),o=Ii(n),a=ee.luaL_loadbuffer(t,o,o.length,P(`@${r}`));if(a!==xe){let c=q(t,-1)||`luaL_loadbuffer status ${a}`;throw u.lua_pop(t,1),new Error(c)}let s=u.lua_pcall(t,0,0,0);if(s!==xe){let c=q(t,-1)||`lua_pcall status ${s}`;throw u.lua_pop(t,1),new Error(c)}}callGlobal(t,i){if(u.lua_getglobal(t,P(i)),u.lua_isfunction(t,-1)){if(u.lua_pcall(t,0,0,0)!==xe){let n=q(t,-1);u.lua_pop(t,1);let o=`${i}: ${n}`;return this.log("lua-error",o),o}}else u.lua_pop(t,1);return null}callGlobalDt(t,i,r){if(u.lua_getglobal(t,P(i)),u.lua_isfunction(t,-1)){if(u.lua_pushnumber(t,r),u.lua_pcall(t,1,0,0)!==xe){let o=q(t,-1);u.lua_pop(t,1),this.log("lua-error",`${i}: ${o}`)}}else u.lua_pop(t,1)}luaInvoke(t){let i=Ge(t,1);if(!i||i.__kind!=="Script")return ee.luaL_error(t,P("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 p=3;p<=u.lua_gettop(t);p++)c.push(de(t,this,p));let l;try{l=i.invoke(r,c)}catch(p){return ee.luaL_error(t,P(String(p.message||p)))}if(l===void 0)return 0;let f=Array.isArray(l)&&l.__multi?l:[l];for(let p of f)ae(t,this,p);return f.length}let o=2;if(u.lua_getglobal(t,P(r)),!u.lua_isfunction(t,-1))return 0;u.lua_replace(t,o),u.lua_remove(t,1);let a=u.lua_gettop(t)-1;return u.lua_pcall(t,a,Go,0)!==xe?u.lua_error(t):u.lua_gettop(t)}invokeOn(t,i,r){let n=u.lua_gettop(t);if(u.lua_getglobal(t,P(i)),!u.lua_isfunction(t,-1)){u.lua_settop(t,n);return}for(let c of r)ae(t,this,c);if(u.lua_pcall(t,r.length,Go,0)!==xe){let c=q(t,-1);throw u.lua_settop(t,n),new Error(c)}let a=u.lua_gettop(t)-n;if(a<=0){u.lua_settop(t,n);return}if(a===1){let c=de(t,this,-1);return u.lua_settop(t,n),c}let s=[];for(let c=1;c<=a;c++)s.push(de(t,this,n+c));return u.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),u.lua_setglobal(n,P("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;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;u.lua_createtable(r,0,5);let n=(o,a)=>{u.lua_pushcfunction(r,a),u.lua_setfield(r,-2,P(o))};return n("var",o=>(ae(o,this,i.var(q(o,1),q(o,2))),1)),n("logContains",o=>(u.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 u.lua_pushboolean(o,a?!!a(q(o,1)):!1),1}),u.lua_setglobal(r,P("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}};function qt(e){let t=new _i(e);return t.boot(),t}var ct=Object.freeze(Array.from({length:8},(e,t)=>`Player${t+1}`)),Nr=Object.freeze(Array.from({length:8},(e,t)=>`Avatar${t+1}`)),Xo=Object.freeze(["Level","PlayerSelf","AvatarSelf"]);var Tr=Object.freeze([...Xo,...ct,...Nr]),Ko=Object.freeze(["PlayerSelf","AllPlayers",...ct]),_l=Object.freeze(["Level","PlayerSelf",...ct]),zo=Object.freeze(["Int","Float","String","Bool","Vector3","Entity","Guid","PrefabId","ConfigId","IntList","FloatList","StringList","BoolList","Vector3List","EntityList","GuidList","PrefabIdList","ConfigIdList","Dict","Struct"]),Pl=-2147483648,Rl=2147483647,Tl=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 Jt(e){return`Player${Number(e)}`}function Pi(e){return`Avatar${Number(e)}`}function Vo(e){let t=String(e||"").match(/^(?:Player|Avatar)([1-8])$/);return t?Number(t[1]):0}function lt(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 ze(e,t=8){let i=lt(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 Yo(){let e={Level:Object.create(null),PlayerSelf:Object.create(null),AvatarSelf:Object.create(null)};for(let t of ct)e[t]=Object.create(null);for(let t of Nr)e[t]=Object.create(null);return e}function Wo(e){let t=String(e||"");if(!Tr.includes(t))throw new Error(`unknown CustomVariableEntityType: ${e}`);return t}function Ml(e,t){let i=Wo(e);if(!_l.includes(i))throw new Error(`${t}.entityType must be Level, PlayerSelf, or Player1-8`);return i}function Zt(e){let t=String(e??"");if(!t)throw new Error("custom variable name is required");return t}function Ri(e){let t=String(e??"");if(!t)throw new Error("signal name is required");return t}function Mr(e){let t=String(e||"PlayerSelf");if(!Ko.includes(t))throw new Error(`unsupported client signal target: ${e}. use PlayerSelf, AllPlayers, or Player1-8`);return t}function Qt(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=Qt(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 Bo(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 Lo(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:Qt(t),value:t}):[]}function Nl(e){return String(e?.kind||e?.type||e?.name||e?.id||"")}function Ti(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function jo(e,t){if(!Ti(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 Uo(e,t){return jo(e,t)||Se(e)}function Fl(e,t,i){if(!Ti(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=Ml(e.entityType,n);if(!Object.prototype.hasOwnProperty.call(e,"value"))throw new Error(`${n}.value is required`);return{kind:r,entityType:o,name:Zt(e.name),value:Uo(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:Mr(e.target),signalName:Ri(e.signalName),params:e.params.map((o,a)=>Uo(o,`${n}.params[${a}]`))}}throw new Error(`${n}.kind must be setCustomVariable or sendClientScriptSignal`)}function ei(e){if(e==null)return{version:1,rules:[]};if(!Ti(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(!Ti(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:Ri(i.signalName),actions:i.actions.map((n,o)=>Fl(n,r,o))}})}}function Ho(e,t,{typed:i=!1}={}){let r=jo(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 Ol(e){return e==="Level"?"Level":ct.includes(e)?"PlayerSelf":Nr.includes(e)?"AvatarSelf":e}function qo(e={}){let t=Yo(),i=Yo(),r=[],n=[],o=[],a=[],s=Array.from({length:9},()=>null),c=1,l=0,f=Number(e.onlineLatencyMs||0);(!Number.isFinite(f)||f<0)&&(f=0);let p=ei(e.logic),d=lt(e.playerCount),m=ze(e.viewPlayerIndex,d);function y(b,E){a.push({source:"server",level:String(b||"engine"),text:String(E),time:l})}function v(b){let E=s[b||m],S=Number(E?.clock?.time);Number.isFinite(S)&&(l=S)}function x(b,E,S,k){t[b][E]=S,i[b][E]={type:k||Qt(S)||i[b][E]?.type||""}}function I(b,E,S){return typeof S!="number"||!Number.isInteger(S)?{ok:!0,value:S}:S>=Pl&&S<=Rl?{ok:!0,value:S}:(y("engine",`Int custom variable ${b}.${E} out of range ${S}; keeping previous legal value`),{ok:!1,value:t[b][E]})}function A(b,E){let S=Wo(b),k=E||m;return S==="PlayerSelf"?Jt(k):S==="AvatarSelf"?Pi(k):S}function O(b,E){let S=Ol(b);if(b==="Level"){for(let w=1;w<=d;w+=1){let M=s[w];M&&typeof M.notifyVarHandlers=="function"&&M.notifyVarHandlers("Level",E)}return}let k=Vo(b);if(!k)return;let D=s[k];D&&typeof D.notifyVarHandlers=="function"&&D.notifyVarHandlers(S,E)}function F(b,E){let S=Mr(b);return S==="AllPlayers"?Array.from({length:d},(k,D)=>D+1):S==="PlayerSelf"?[E||m]:[Vo(S)]}function U(b){for(let E of p.rules)if(E.signalName===b.name)for(let S of E.actions){if(S.kind==="setCustomVariable"){let k=Ho(S.value,b);$.setVar(S.entityType,S.name,k,{type:S.variableType,playerIndex:b.playerIndex}),y("info",`logic ${E.id}: set ${S.entityType}.${S.name}`);continue}if(S.kind==="sendClientScriptSignal"){let k=S.params.map(D=>Ho(D,b,{typed:!0}));$.sendToClient(S.signalName,k,{target:S.target,playerIndex:b.playerIndex}),y("info",`logic ${E.id}: sent ${S.signalName} to ${S.target}`)}}}function te(b,E){b&&(b.serverBridge={getVar:(S,k)=>$.getVar(S,k,{playerIndex:E}),setVar:(S,k,D)=>$.setVar(S,k,D,{playerIndex:E}),receiveFromClient:(S,k)=>$.receiveFromClient(S,k,{playerIndex:E})})}function Z(b){b&&(b.serverBridge=null)}let $={ENTITY_TYPES:Xo,ALL_ENTITY_TYPES:Tr,CLIENT_SIGNAL_TARGETS:Ko,get clock(){return l},get playerCount(){return d},get viewPlayerIndex(){return m},setClock(b){l=Number(b)||0},setPlayerCount(b){return d=lt(b),m>d&&(m=d),d},setViewPlayerIndex(b){return m=ze(b,d),m},log(b,E){y(b,E)},defineVar(b,E,S={},{playerIndex:k}={}){let D=A(b,k),w=Zt(E);if(Object.prototype.hasOwnProperty.call(t[D],w))throw new Error(`custom variable already exists: ${D}.${w}`);let M=S.type?String(S.type):Qt(S.value??S.defaultValue);if(M&&!zo.includes(M))throw new Error(`unsupported custom variable type: ${M}`);let z=S.value!==void 0?S.value:S.defaultValue!==void 0?S.defaultValue:null;return x(D,w,z,M),$.getVar(D,w)},getVar(b,E,{playerIndex:S}={}){let k=A(b,S),D=Zt(E);if(!Object.prototype.hasOwnProperty.call(t[k],D)){y("engine",`GetGlobalCustomVariableValue missing ${k}.${D}; returning nil (simulator policy)`);return}return t[k][D]},setVar(b,E,S,{notify:k=!0,type:D,playerIndex:w}={}){let M=A(b,w),z=Zt(E),L=D||i[M][z]?.type||Qt(S);if(L&&!zo.includes(L)&&L!=="")throw new Error(`unsupported custom variable type: ${L}`);let se=S;if(!((L==="Int"||L===""&&typeof S=="number"&&Number.isInteger(S))&&(se=I(M,z,S).value,se===void 0)))return x(M,z,se,L),k&&O(M,z),se},listVars(b){let E=b?[A(b)]:["Level",...Array.from({length:d},(k,D)=>Jt(D+1)),...Array.from({length:d},(k,D)=>Pi(D+1))],S=[];for(let k of E)for(let D of Object.keys(t[k]))S.push({entityType:k,name:D,type:i[k][D]?.type||"",value:Se(t[k][D])});return S},receiveFromClient(b,E=[],{playerIndex:S}={}){let k=ze(S||m,d);v(k);let D=Ri(b),w={id:c++,direction:"inbound",name:D,params:Lo(E),values:Bo(E),time:l,playerIndex:k,from:Jt(k)};return r.push(w),U(w),w},sendToClient(b,E=[],{target:S="PlayerSelf",playerIndex:k}={}){let D=Ri(b),w=Mr(S),z=F(w,k||m),L={id:c++,direction:"outbound",name:D,params:Lo(E),values:Bo(E),time:l,target:w,players:z,deliverAt:l+f/1e3,delivered:!1};return n.push(L),f===0?$.deliver(L):o.push(L),L},getLogic(){return Se(p)},setLogic(b){return p=ei(b),$.getLogic()},deliver(b){if(!b||b.delivered)return;b.delivered=!0;let E=Array.isArray(b.players)&&b.players.length?b.players:F(b.target);for(let S of E){let k=s[S];k&&typeof k.sendClientSignal=="function"&&k.sendClientSignal(b.name,b.values)}},flush(b){b!==void 0&&(l=Number(b)||0);let E=[];for(let S=o.length-1;S>=0;S-=1)o[S].deliverAt<=l&&E.push(o.splice(S,1)[0]);E.sort((S,k)=>S.id-k.id);for(let S of E)$.deliver(S);return E},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 E of b.nodes||[]){let S=Nl(E);if(!Tl.has(S))throw new Error(`unsupported server node: ${S||JSON.stringify(E)}. v1 only supports custom variables and signals`)}if(b.onlineLatencyMs!==void 0){let E=Number(b.onlineLatencyMs);if(!Number.isFinite(E)||E<0)throw new Error("onlineLatencyMs must be a non-negative finite number");f=E}b.playerCount!==void 0&&$.setPlayerCount(b.playerCount),b.viewPlayerIndex!==void 0&&$.setViewPlayerIndex(b.viewPlayerIndex),(b.logic!==void 0||b.serverLogic!==void 0)&&$.setLogic(b.logic??b.serverLogic);for(let E of b.vars||[]){let S=A(E.entityType),k=Zt(E.name);Object.prototype.hasOwnProperty.call(t[S],k)?$.setVar(S,k,E.value??E.defaultValue,{notify:!1,type:E.type}):$.defineVar(S,k,E)}}},attachRuntime(b,{playerIndex:E=1}={}){let S=ze(E,8);return s[S]&&s[S]!==b&&Z(s[S]),s[S]=b||null,te(s[S],S),$},attachRuntimes(b){$.detachRuntime();let E=Array.isArray(b)?b:[];for(let S=0;S<E.length&&S<8;S+=1)s[S+1]=E[S]||null,te(s[S+1],S+1);return $},detachRuntime(){for(let b=1;b<=8;b+=1)Z(s[b]),s[b]=null},snapshot(){let b=Jt(m),E=Pi(m),S={Level:{},PlayerSelf:{},AvatarSelf:{}};for(let k of Object.keys(t.Level))S.Level[k]={type:i.Level[k]?.type||"",value:Se(t.Level[k])};for(let k of Object.keys(t[b]))S.PlayerSelf[k]={type:i[b][k]?.type||"",value:Se(t[b][k])};for(let k of Object.keys(t[E]))S.AvatarSelf[k]={type:i[E][k]?.type||"",value:Se(t[E][k])};for(let k=1;k<=d;k+=1){let D=Jt(k),w=Pi(k);S[D]={},S[w]={};for(let M of Object.keys(t[D]))S[D][M]={type:i[D][M]?.type||"",value:Se(t[D][M])};for(let M of Object.keys(t[w]))S[w][M]={type:i[w][M]?.type||"",value:Se(t[w][M])}}return{clock:l,onlineLatencyMs:f,playerCount:d,viewPlayerIndex:m,logic:$.getLogic(),vars:S,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:a.map(k=>({source:"server",level:k.level,text:k.text,time:k.time}))}},reset(){for(let b of Tr){for(let E of Object.keys(t[b]))delete t[b][E];for(let E of Object.keys(i[b]))delete i[b][E]}r.length=0,n.length=0,o.length=0,a.length=0,c=1,l=0},destroy(){$.detachRuntime(),$.reset()}};e.config&&$.loadConfig(e.config);for(let b of e.vars||[])$.defineVar(b.entityType,b.name,b);return $}var Dl={container:"container",textbox:"textbox",image:"image",button:"button",cursor:"cursor",grid:"grid",reference:"reference",textwindow:"textwindow",keyhint:"keyhint",animation:"animation",fullscreen:"fullscreen"};function Fr(e,t,i=null){let r=He(e.transformByPlatform,t),n={authoringId:e.id,kind:Dl[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=>Fr(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 Or(e,t=[],i=""){let r=i&&K[i]?i:e.canvasId,n=K[r],o=Lt(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=>Fr(c,r,a)):[];return{canvasId:r,platform:n.platform,device:n.luaDevice,canvasWidth:n.width,canvasHeight:n.height,root:Fr(o,r,a),templates:s}}var Mi="qxqy-autotest";var ut=.03333333333333333,$l=new Set(["pointer","key","click","pause","resume","serverSet","serverSend","view"]),Gl=new Set(["log","control","var","signal","tree","lua"]);function ti(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function Dr(e){return JSON.parse(JSON.stringify(e??null))}function Ni(e,t){if(!e||typeof e!="object")throw new Error(`events[${t}] must be an object`);let i=String(e.kind||e.do||"");if(!$l.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=ti(r.x,"pointer.x"),r.y=ti(r.y,"pointer.y"),r.type=String(r.type||"click");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:ti(e.t??0,"event.t"),source:String(e.source||"user"),kind:i,payload:r}}function $r(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(!Gl.has(i))throw new Error(`unsupported assert kind: ${i||"(empty)"}`);let r={kind:i};if(e.at!==void 0&&(r.at=ti(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=Dr(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=Dr(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=Dr(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+=ti(n.dt??ut,"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(Ni({...n,kind:n.do,t},i.length));continue}if(n.assert||n.check||n.kind){r.push($r({...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:ut}}function ii(e){if(Array.isArray(e)){let r=Jo(e);return{format:Mi,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:Mi,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)=>Ni(r,n)),i=(e.asserts||[]).map((r,n)=>$r(r,n));return t.sort((r,n)=>r.t-n.t||0),{format:Mi,version:1,name:String(e.name||""),dt:Number(e.dt)>0?Number(e.dt):ut,playerCount:Number(e.playerCount)>0?Number(e.playerCount):1,events:t,asserts:i}}function Zo(e,t={}){let i=(e||[]).map((r,n)=>Ni(r,n));return{format:Mi,version:1,name:String(t.name||""),dt:Number(t.dt)>0?Number(t.dt):ut,playerCount:Number(t.playerCount)>0?Number(t.playerCount):1,events:i,asserts:(t.asserts||[]).map((r,n)=>$r(r,n))}}function Qo(e,t,i){if(!e)return null;let r=Ni({...t,t:t.t??i??0},e.events.length);return e.events.push(r),r}var zl=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 Yr(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 Vl(e,t=Yr(e)){let i=new Map;function r(n,o){let a=t.get(n.Id);if(!a)return;let s=Bt(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,wt());return i}function ta(e,t){let i=t.get(e.Id);return{id:e.Id,prefabId:e.prefabIndex,authoringId:e.authoringId,name:e.name,kind:e.kind,typeofName:e.typeofName,instantiated:!e.authoringId,active:!!e.active,visible:!!e.visible,activeInHierarchy:!!i?.activeInHierarchy,raycastTarget:e.raycastTarget!==!1,interactable:e.interactable!==!1,pressed:e.pressed===!0,anchoredPositionX:e.anchoredPositionX,anchoredPositionY:e.anchoredPositionY,sizeDeltaX:e.sizeDeltaX,sizeDeltaY:e.sizeDeltaY,localScaleX:e.localScaleX,localScaleY:e.localScaleY,localScaleZ:e.localScaleZ,localRotationZ:e.localRotationZ,text:e.kind==="textbox"||e.kind==="textwindow"?e.text??"":null,fontSize:e.kind==="textbox"||e.kind==="textwindow"?e.fontSize:null,fontColor:e.kind==="textbox"||e.kind==="textwindow"?e.fontColor:null,bgColor:e.kind==="textbox"||e.kind==="textwindow"?e.bgColor:null,enableOutline:e.kind==="textbox"||e.kind==="textwindow"?e.enableOutline===!0:null,outlineColor:e.kind==="textbox"||e.kind==="textwindow"?e.outlineColor:null,imageId:e.kind==="image"?e.imageId??0:null,primitive:e.kind==="image"?bt[e.imageId]||"missing":null,imageColor:e.kind==="image"?e.imageColor:null,enableMask:e.kind==="image"?e.enableMask===!0:null,enableSoftEdge:e.kind==="image"?e.enableSoftEdge===!0:null,softEdgeMode:e.kind==="image"?e.softEdgeMode:null,softEdgeWidthX:e.kind==="image"?e.softEdgeWidthX:null,softEdgeWidthY:e.kind==="image"?e.softEdgeWidthY:null,horizontalSoftRange:e.kind==="image"?e.horizontalSoftRange:null,verticalSoftRange:e.kind==="image"?e.verticalSoftRange:null,enableFill:e.kind==="image"?e.enableFill===!0:null,fillType:e.kind==="image"?e.fillType:null,fillHorizontalType:e.kind==="image"?e.fillHorizontalType:null,fillVerticalType:e.kind==="image"?e.fillVerticalType:null,fillRadial90Type:e.kind==="image"?e.fillRadial90Type:null,fillRadialType:e.kind==="image"?e.fillRadialType:null,reverseMaskArea:e.kind==="image"?e.reverseMaskArea===!0:null,fillAmount:e.kind==="image"?e.fillAmount:null,box:i?{left:i.left,bottom:i.bottom,width:i.width,height:i.height}:null,children:e.children.map(r=>ta(r,t))}}function Yl(){return{pointerDownControl:null,pointerDownPosition:null,pointerLastPosition:null,pointerDragging:!1,pointerHoverControl:null,hoveredControl:null,selectedControl:null,stateRestores:new Map,viewCache:null}}function Bl(e,t,i,r){let n=qt({canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight,device:e.device,...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 Ll=["pointerDownControl","pointerDownPosition","pointerLastPosition","pointerDragging","pointerHoverControl","hoveredControl","selectedControl","stateRestores","viewCache"];function Ul(e){Object.defineProperty(e,"runtime",{configurable:!0,enumerable:!0,get(){return e.runtimes[e.viewPlayerIndex-1]}});for(let t of Ll)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 ia(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 f=r||i,p=n||i,d=Or(e,f,a),m=t?Or(t,p,a):null,y=lt(s),v=ze(c,y),x=qo({playerCount:y,viewPlayerIndex:v});o&&x.loadConfig({...o,playerCount:y,viewPlayerIndex:v});let I=[];for(let F=0;F<y;F+=1)I.push(Bl(d,m,i,l));x.attachRuntimes(I);for(let F of I)F.addRoot(d.root);let A={runtimes:I,views:I.map(()=>Yl()),playerCount:y,viewPlayerIndex:v,server:x,compiled:d,mountError:I.find(F=>F.mountErrors[0])?.mountErrors[0]||null,debugPaused:!1,history:{events:[]},recording:!0};Ul(A);let O=A.viewPlayerIndex;for(let F=1;F<=y;F+=1)A.viewPlayerIndex=F,ic(A);return A.viewPlayerIndex=O,A}function Br(e,t){if(!e)throw new Error("play session has not started");let i=ze(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||Qo(e.history,{...t,source:t.source||"user"},e.runtime.clock.time)}function Hl(e){return e?.history?.events||[]}var Lr=new Set(["image","textbox","textwindow","button"]);function Xl(e,t){let i=Qe(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 ft(e){return typeof e=="string"?e:e?.Name}function ra(e){return{fillType:ft(e.fillType),fillHorizontalType:ft(e.fillHorizontalType),fillVerticalType:ft(e.fillVerticalType),fillAmount:e.fillAmount}}function Kl(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};return e.kind==="image"&&(o.primitive=bt[e.imageId]||"missing",o.imageColor=e.imageColor,o.imageId=e.imageId,Object.assign(o,ra(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=ft(e.horizontalAlignment),o.verticalAlignment=ft(e.verticalAlignment)),o}function Wl(e,t=Yr(e)){let i=[],r=Vl(e,t);function n(o){let a=t.get(o.Id);if(!a||o.visible===!1||!a.activeInHierarchy)return;let s=r.get(o.Id);if(!s)return;let c=Xl(a,s);Lr.has(o.kind)&&i.push(Kl(o,a,c));let l=o.children||[];for(let f=l.length-1;f>=0;f-=1)n(l[f])}for(let o of e.runtime.roots)n(o);return i}function jl(e,t){let i={kind:e.kind,name:e.name,sourceWidth:t.width,sourceHeight:t.height,pressed:e.pressed===!0};return e.kind==="image"&&(i.primitive=bt[e.imageId]||"missing",i.imageColor=e.imageColor,i.imageId=e.imageId,Object.assign(i,ra(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=ft(e.horizontalAlignment),i.verticalAlignment=ft(e.verticalAlignment)),i}function ql(e,t,i){let r=er(e,t),n=Qe(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 na(e){let t=e.matrix;return[e.parent,e.z,e.group?1:0,t.a,t.b,t.c,t.d,t.tx,t.ty,e.kind,e.name,e.sourceWidth,e.sourceHeight,e.pressed,e.primitive,e.imageColor,e.imageId,e.fillType,e.fillHorizontalType,e.fillVerticalType,e.fillAmount,e.text,e.fontSize,e.fontColor,e.bgColor,e.enableOutline,e.outlineColor,e.horizontalAlignment,e.verticalAlignment].join(" ")}function oa(e,t,i,r,n,o){return{id:e.Id,parent:t,z:n,group:o>=16,matrix:ql(r,e,i),...jl(e,r)}}function Jl(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,f){let p=De(l,c);if(p.activeInHierarchy=f&&c.active!==!1,n.set(c.Id,p),c.visible===!1||!p.activeInHierarchy)return!1;let d=c.children||[],m=Lr.has(c.kind),y=0;for(let v=0;v<d.length;v+=1)o(d[v],p,p.activeInHierarchy)&&(m=!0,y+=1);return m?(i.add(c.Id),r.set(c.Id,y),!0):!1}function a(c,l,f,p){if(!i.has(c.Id))return;let d=n.get(c.Id);s.push(oa(c,l,f,d,p,r.get(c.Id)||0));let m=c.children||[];for(let y=0;y<m.length;y+=1)a(m[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 Vr(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)Vr(i[r])}function Zl(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 f=a[l];t.fingerprints.has(f)&&(n.push(f),t.fingerprints.delete(f),t.childCounts.delete(f),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 f=l.children;for(let p=0;p<f.length;p+=1)s(f[p])}function c(l,f,p,d,m,y){let v=y||l._playDeepDirty===!0,x=v||l._playDirty===!0,I=v||l._playChildDirty===!0;if(!x&&!I)return;if(!(m&&l.active!==!1)||l.visible===!1){s(l);return}let O=De(f,l),F=t.childCounts.get(l.Id)||0;if(I){F=0;let E=l.children;for(let S=0;S<E.length;S+=1)c(E[S],O,l.Id,S,!0,v),t.fingerprints.has(E[S].Id)&&(F+=1)}if(!(Lr.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(!x&&!Z&&t.fingerprints.has(l.Id))return;let $=oa(l,p,f===i?null:f,O,d,F),b=na($);t.fingerprints.get($.id)!==b&&(t.fingerprints.has($.id)||(o+=1),t.fingerprints.set($.id,b),r.push($))}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 Ql(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}=Jl(e);i.rev+=1,i.fingerprints=new Map(c.map(f=>[f.id,na(f)])),i.childCounts=l,i.count=c.length;for(let f of e.runtime.roots)Vr(f);return{format:"tree-v1",revision:i.rev,reset:!0,count:c.length,nodes:c}}let{changed:o,removed:a,count:s}=Zl(e,i);i.rev+=1;for(let c of e.runtime.roots)Vr(c);return{format:"tree-v1",revision:i.rev,reset:!1,count:s,changed:o,removed:a}}function Ur(e,{inspect:t=!1,view:i=!1,paint:r=!1,sceneRev:n,compact:o=!1}={}){let a=e.runtime,s=e.compiled,[c,l]=[a.canvasWidth,a.canvasHeight];e.server&&e.server.setClock(a.clock.time);let f=o?a.logs.slice(-100):a.logs,p=Hl(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 m={canvasId:s.canvasId,platform:s.platform,device:a.device,canvasWidth:c,canvasHeight:l,canvasPresets:zl,playerCount:e.playerCount||1,viewPlayerIndex:e.viewPlayerIndex||1,players:Array.from({length:e.playerCount||1},(y,v)=>({index:v+1,label:`\u73A9\u5BB6${v+1}`,entityType:`Player${v+1}`})),time:a.clock.time,frame:a.clock.frame,paused:!!e.debugPaused,levelTimePaused:!!a.clock.paused,mountError:e.mountError||a.mountErrors[0]||null,logs:f.map(y=>({source:"client",level:y.level,text:y.text,time:y.time})),tree:[],paint:[],scene:null,server:d,history:(o?p.slice(-100):p).map(y=>({t:y.t,source:y.source||"user",kind:y.kind,payload:y.payload||{}}))};if(t||r){let y=Yr(e);t&&(m.tree=a.roots.map(v=>ta(v,y))),r&&(m.paint=Wl(e,y))}return i&&(m.scene=Ql(e,n)),St(m),m}function Fi(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 Hr(e,t){qe(e,{kind:"key",payload:{typeName:String(t)}}),e.runtime.injectKey(t)}function ec(e,t){let i=null;for(let r of e.runtime.roots)Ne(r,n=>{!i&&n.name===t&&(i=n)});return i}function Xr(e,t){qe(e,{kind:"click",payload:{name:String(t)}});let i=ec(e,t);i&&Kr(i)&&(i.kind==="button"||i.kind==="cursor")&&i.SimulateCursorClick()}function tc(e,t){return!e||!t?null:e.children.find(i=>i.authoringId===t||i.Id===t)||null}var aa={unavailable:"unavailableChildId",hover:"hoverChildId",pressed:"pressedChildId",selected:"selectedChildId"};function sa(e,t){let i=[];for(let[r,n]of Object.entries(aa)){let o=t[n]?tc(t,t[n]):null;o&&i.push({state:r,child:o})}return i}function ic(e){for(let t of e.runtime.roots)Ne(t,i=>{if(i.kind==="button"){for(let{child:r}of sa(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);ni(e,i)}})}function ni(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 sa(e,t))r.child.active=!0,r.child.visible=r.state===i,typeof r.child.markPlayDirty=="function"&&r.child.markPlayDirty(!0)}function Gr(e){if(!e)return null;let t=e.parent;return t?.kind==="button"&&Object.values(aa).map(r=>t[r]).filter(Boolean).includes(e.authoringId)?t:e}function Kr(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 la(e){return e.kind==="container"||e.kind==="grid"||e.kind==="textwindow"||e.kind==="reference"||e.kind==="button"}function ca(e,t){let i=e.Id,r=t.get(i);if(r!==void 0)return r;let n=Kr(e);if(!n&&la(e)){let o=e.children;for(let a=0;a<o.length;a+=1)if(ca(o[a],t)){n=!0;break}}return t.set(i,n),n}function zr(e,t,i){let r=ye({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),n=new Map;function o(s,c,l,f){if(!f||s.active===!1||s.visible===!1||!ca(s,n))return null;let p=De(c,s),d=Bt(l,p,s),m=gi(d);if(!m)return null;let y=Qe(m,t,i);if(y.x<p.left||y.x>p.right||y.y<p.bottom||y.y>p.top)return null;if(la(s))for(let v=0;v<s.children.length;v+=1){let x=o(s.children[v],p,d,!0);if(x)return x}return Kr(s)?s:null}let a=wt();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 ri(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 ea(e,t,i){t.pressed=i,typeof t.markPlayDirty=="function"&&t.markPlayDirty(),ni(e,t)}function oi(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");if(e.runtime.cursor.x=o,e.runtime.cursor.y=a,n.silent||qe(e,{kind:"pointer",payload:{type:t,x:o,y:a}}),t==="move"){let s=e.pointerLastPosition||{x:o,y:a},c=e.pointerHoverControl,l=Gr(zr(e,o,a)),f=ri(e,o,a,{previous:s});c&&c!==l&&e.runtime.injectCursor(c,"CursorExit",f),l&&c!==l&&e.runtime.injectCursor(l,"CursorEnter",f),e.pointerHoverControl=l;let p=e.hoveredControl;e.hoveredControl=l?.kind==="button"?l:null,p&&p!==e.hoveredControl&&ni(e,p),e.hoveredControl&&ni(e,e.hoveredControl);let d=e.pointerDownControl;if(d){let m=e.pointerDownPosition||s,y=o!==s.x||a!==s.y;!e.pointerDragging&&y&&(e.runtime.injectCursor(d,"CursorBeginDrag",ri(e,o,a,{press:m,previous:s,dragging:!1})),e.pointerDragging=!0),e.pointerDragging&&e.runtime.injectCursor(d,"CursorDrag",ri(e,o,a,{press:m,previous:s,dragging:!0}))}return e.pointerLastPosition={x:o,y:a},l}if(t==="down"){let s=Gr(zr(e,o,a));return e.pointerDownControl=s,e.pointerDownPosition={x:o,y:a},e.pointerLastPosition={x:o,y:a},e.pointerDragging=!1,s&&(ea(e,s,!0),e.runtime.injectCursor(s,"CursorDown",ri(e,o,a))),s}if(t==="up"){let s=e.pointerDownControl,c=Gr(zr(e,o,a));if(s){let l=ri(e,o,a,{press:e.pointerDownPosition,previous:e.pointerLastPosition,dragging:e.pointerDragging});if(e.runtime.injectCursor(s,"CursorUp",l),e.pointerDragging)e.runtime.injectCursor(s,"CursorEndDrag",l);else if(c===s){e.runtime.injectCursor(s,"CursorClick",l);let f=e.selectedControl;e.selectedControl=s.kind==="button"?s:null,f&&f!==e.selectedControl&&ni(e,f)}ea(e,s,!1)}return e.pointerDownControl=null,e.pointerDownPosition=null,e.pointerLastPosition={x:o,y:a},e.pointerDragging=!1,c}if(t==="click")return oi(e,"down",o,a,{silent:!0}),oi(e,"up",o,a,{silent:!0});throw new Error(`unknown pointer type ${t}`)}function Wr(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 ua(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 jr(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 Oi(e){return{snapshot:t=>Ur(e,t),step:t=>Fi(e,t),pointer:(t,i,r)=>oi(e,t,i,r),key:t=>Hr(e,t),click:t=>Xr(e,t),view:t=>Br(e,t),pause:()=>{qe(e,{kind:"pause",payload:{}}),e.debugPaused=!0},resume:()=>{qe(e,{kind:"resume",payload:{}}),e.debugPaused=!1},serverSet:(t,i,r)=>Wr(e,t,i,r),serverSend:(t,i,r)=>jr(e,t,i,r)}}function qr(e){e?.server&&e.server.destroy();let t=e?.runtimes||(e?.runtime?[e.runtime]:[]);for(let i of t)i.destroy()}function Jr(e,t){return JSON.stringify(e)===JSON.stringify(t)}function fa(e,t){for(let i of e||[])t(i),i.children?.length&&fa(i.children,t)}function Zr(e,{id:t,name:i}){let r=null;return fa(e,n=>{r||(t&&String(n.id)===String(t)||!t&&i&&n.name===i)&&(r=n)}),r}function rc(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 nc(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=Zr(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 oc(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=Zr(t.tree,e);if(!i)return{ok:!1,actual:null,expected:e.equals,message:`control not found: ${e.id||e.name}`};let r=rc(i,e.field);return Jr(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 Jr(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||Jr(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=!!Zr(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 ac(e,t){let i=qt();try{return i.evalQueryScript(e,nc(t)),{ok:!0,actual:!0}}catch(r){return{ok:!1,message:r?.message||String(r)}}finally{i.destroy()}}function da(e,t){return e.kind==="lua"?ac(e.source,t):oc(e,t)}function sc(e,t){let i=t>0?t:ut;return Math.round((e+i)*1e9)/1e9}function lc(e,t){let i=t.payload||{};if(t.kind==="pointer")e.pointer(i.type,i.x,i.y);else if(t.kind==="key")e.key(i.typeName);else if(t.kind==="click")e.click(i.name);else if(t.kind==="pause")e.pause();else if(t.kind==="resume")e.resume();else if(t.kind==="serverSet")e.serverSet(i.entityType,i.name,i.value);else if(t.kind==="serverSend")e.serverSend(i.name,i.params,i.target);else if(t.kind==="view")e.view(i.playerIndex);else throw new Error(`unsupported event kind: ${t.kind}`)}function cc(e,t){let i=da(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 ha(e,t){let i=ii(t),r=i.events.slice().sort((I,A)=>I.t-A.t),n=i.asserts.slice(),o=i.dt||ut,a=r.reduce((I,A)=>Math.max(I,A.t),0),s=n.reduce((I,A)=>Math.max(I,Number(A.at||0)),0),c=Math.max(a,s),l=0,f=[],p=0,d=n.some(I=>I.kind==="control"||I.kind==="tree"||I.kind==="lua"),m=e.snapshot({inspect:d}),y=()=>{for(;l<r.length&&r[l].t<=p+1e-9;)lc(e,r[l]),l+=1,m=e.snapshot({inspect:d})},v=()=>{for(let I of n)if(!I._done&&Number(I.at||0)<=p+1e-9){let A=cc(I,m);if(f.push(A),I._done=!0,!A.ok)return{passed:!1,failedAt:p,frame:m.frame||0,results:f,snapshot:m}}return null};y();let x=v();if(x)return Qr(i,x);for(;p+1e-9<c;){e.step(o),p=sc(p,o),m=e.snapshot({inspect:d}),y();let I=v();if(I)return Qr(i,I)}return Qr(i,{passed:f.every(I=>I.ok),failedAt:null,frame:m.frame||0,results:f,snapshot:m})}function Qr(e,t){return G({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 en(e){return Array.isArray(e)?e.slice():[]}var mc={Level:"\u5173\u5361",PlayerSelf:"\u5F53\u524D\u73A9\u5BB6",AvatarSelf:"\u5F53\u524D\u89D2\u8272",...Object.fromEntries(ct.map((e,t)=>[e,`\u73A9\u5BB6${t+1}`])),...Object.fromEntries(Array.from({length:8},(e,t)=>[`Avatar${t+1}`,`\u89D2\u8272${t+1}`]))};function gc(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(G({entityType:s,entityLabel:mc[s]||s,name:l,type:c[l]?.type||"",value:c[l]?.value??null}))}return r}var ht="qxqy-simulator-save",yc="qxqy-simulator-scripts",oe="server-control-template",B="client-control-template",tn={[oe]:"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F",[B]:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"};function dt(e){return e===B?"client":"server"}function Di(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 rn(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,B].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:Di(i.oldGuid),newGuid:Di(i.newGuid)}})}function vc(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 $i(e){let t=String(e?.controlAsset||""),i=vc(e);return{id:String(i||e?.id||""),guid:i,path:String(e?.path||""),source:String(e?.source||""),controlId:String(e?.controlId||""),controlAsset:t===B||t==="client"?B:t===oe||t==="server"?oe:""}}function bc(e){let t=[],i=(r,n="")=>{if(r&&(r.path||r.source)){let o=$i(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($i(r));return t}if(i(e?.assets?.server?.script,oe),i(e?.assets?.client?.script,B),e&&e.format!==ht){i(e?.script);for(let r of e?.scripts||[])i(r)}return t}function nn(e){return We(e===B?It():nt())}var Sc="\u672A\u7ED1\u5B9A",Pt="\u672A\u547D\u540D\u5B58\u6863",wc="\u672A\u547D\u540D\u754C\u9762";function Cc(e){let t=e;for(let i=0;i<8;i++){if(ai(pa(t,"simulator","studio"))&&ai(pa(t,"lua")))return t;let r=hc(t);if(r===t)break;t=r}return e}function Ic(e){return e?{name:Rt(e),path:e,bound:!0}:{name:Sc,path:"",bound:!1}}function kc(e,t=process.cwd()){if(pc(e)&&ai(e))return e;let i=t||process.cwd(),r=Cc(i),n=ma(r,e);if(ai(n))return n;let o=ma(i,e);if(ai(o))return o;throw new Error("script file not found: "+e)}function on(e,t={}){e?.format===ht&&vr(e.version);let i=[],r=typeof t.workspacePath=="string"&&t.workspacePath?t.workspacePath:"",n=e?.format===ht&&e.assets,o=rn(e?.controlGuidChanges),a=Vt(e?.scriptSync),s=n?null:We(e,{warnings:i}),c={server:n&&e.assets.server?We(e.assets.server,{warnings:i}):nn(oe),client:n&&e.assets.client?We(e.assets.client,{warnings:i}):nn(B)};s&&(c[dt(s.meta.assetType)]=s);let l=n&&e.activeAssetType===B?B:s?.meta.assetType||oe,f=n&&e.meta?.name?String(e.meta.name):"",p=()=>f||Pt;!e?.meta?.name&&c.server.meta.name==="\u672A\u547D\u540D\u754C\u9762\u63A7\u4EF6\u7EC4"&&(c.server.meta.name=wc);let d=[],m=new Set;function y(){m.clear(),Ct(c.server.root,m),Ct(c.client.root,m,{skipServerContainer:!0});for(let h of d)ke(h.guid)&&m.add(Number(h.guid))}function v(h=0){y();let g=ke(h)&&!m.has(Number(h))?Number(h):Le(m);return m.add(g),g}function x(h){let g=$i(h),C=v(g.guid);return{...g,guid:C,id:String(C)}}Ye(bc(e));let I=ei(e?.serverLogic),A=null,O="",F=1,U=1;function te(h){let g=String(h||"").trim();if(!g)return"";if(!K[g])throw new Error(`unknown canvas preset: ${g} (available: ${Object.keys(K).join(", ")})`);return g}let Z=()=>c[dt(l)];function $(h){if(!h)return null;for(let[g,C]of[["server",c.server],["client",c.client]]){let _=ue(C.root,h);if(_&&_.kind!=="server-container")return{key:g,node:_}}return null}function b(h){if(!h.controlId)return null;let g=h.controlAsset===B?"client":h.controlAsset===oe?"server":null;if(g){let C=ue(c[g].root,h.controlId);return C&&C.kind!=="server-container"?{key:g,node:C}:null}return $(h.controlId)}function E(){for(let h of d)h.controlId&&!b(h)&&(h.controlId="",h.controlAsset="")}function S(h){if(!ke(h))return null;for(let[g,C]of[[oe,c.server],[B,c.client]]){let _="";if(J(C.root,T=>{!_&&(T.scriptMappingIds||[]).includes(Number(h))&&(_=T.id)}),_)return{controlId:_,controlAsset:g}}return null}function k(h,g,C){let _=c[dt(h.controlAsset)],T=_&&ue(_.root,h.controlId);T&&(T.scriptMappingIds=(T.scriptMappingIds||[]).map(N=>Number(N)===Number(g)?Number(C):N))}E();function D(){return d.map(h=>{let g=b(h),C=g?g.key==="client"?B:oe:"";return G({id:h.id,guid:h.guid||0,path:h.path||"",source:h.source||"",controlId:h.controlId||"",controlAsset:h.controlAsset||C,controlName:g?.node.name||"",assetType:C,assetLabel:g?tn[C]:"",mounted:!!g})})}function w(){let h=[],g=(C,_)=>{J(C.root,T=>{T.kind!=="server-container"&&h.push(G({id:T.id,name:T.name,kind:T.kind,assetType:_,assetLabel:tn[_]}))})};return g(c.server,oe),g(c.client,B),h}function M(h){let g=[];return J(h.root,C=>{C.kind!=="server-container"&&g.push(JSON.stringify({kind:C.kind,guid:C.guid,name:C.name,text:C.text??null,imageId:C.imageId??null,fontSize:C.fontSize??null,fontColor:C.fontColor??null,bgColor:C.bgColor??null,imageColor:C.imageColor??null,fillType:C.fillType??null,fillAmount:C.fillAmount??null,syncAllDevices:C.syncAllDevices!==!1,transformByPlatform:C.transformByPlatform||null}))}),g.join("/")}let z=M(It()),L=M(nt());function se(h){let g=M(h);return h.meta?.assetType===B?g===z:g===L}function X(h,g){return String(h||"").replace(/[\\/:*?"<>|]/g,"-").trim()||g}function he(h){let g=X(p(),Pt),C=h.meta?.assetType===B?"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F";return`${g} \xB7 ${C}`}function Je(){if(!((c.server.root.children||[]).find(g=>g.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 io(c.server,c.client,{scripts:d,fileName:`${X(p(),Pt)} \xB7 \u6574\u5408\u5305.gia`})}function gt(){let h=g=>({type:g.meta.assetType,name:g.meta.name,sourceFile:g.meta.sourceFile||""});return{format:ht,name:p(),activeAssetType:l,assets:{server:h(c.server),client:h(c.client),scripts:D()}}}function Nt(){return G({format:ht,version:4,meta:{name:p()},activeAssetType:l,serverLogic:I,controlGuidChanges:o,scriptSync:a,assets:{server:c.server,client:c.client,scripts:d.map(h=>G({id:h.id,guid:h.guid||0,path:h.path||"",source:h.source||"",controlId:h.controlId||"",controlAsset:h.controlAsset||""}))}})}function ie(){let h=Z(),g=So(h);return g.workspace=Ic(r),g.save=gt(),g.scripts=D(),g.mountTargets=w(),g.serverLogic=I,g.migrationWarnings=[...i],g.controlGuidChanges=G(o),g.scriptSync=G(a),En(g),g}function _e(h){let g=Z();if(h.expectedRevision!==void 0&&Number(h.expectedRevision)!==g.version)throw new Error(`revision conflict: expected ${h.expectedRevision}, current ${g.version}`);return g}function Ze(h,g,C=""){let _=String(g||"");if(_){let T=C===B?B:C===oe?oe:"";if(!b({controlId:_,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");h.controlAsset=T}else h.controlAsset="";h.controlId=_}function ui(h){let g=_e(h);if(h.op==="addScript"){let C=x({path:String(h.path||""),source:String(h.source||""),controlId:"",controlAsset:""});h.controlId!==void 0&&h.controlId!==""&&Ze(C,h.controlId,h.controlAsset),d.push(C)}else if(h.op==="updateScript"){let C=d.find(_=>_.id===h.id);if(!C)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${h.id}`);h.controlId!==void 0&&Ze(C,h.controlId,h.controlAsset),h.path!==void 0&&(C.path=String(h.path)),h.source!==void 0&&(C.source=String(h.source))}else if(h.op==="removeScript"){let C=d.length;if(d=d.filter(_=>_.id!==h.id),d.length===C)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${h.id}`)}return g.version+=1,ie()}function fi(h){let g=_e(h),C=ue(g.root,h.id??g.selectedId);if(!C||C.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 _=Di(h.guid),T=Di(C.guid);if(_===T)return ie();let N=[];for(let Y of Object.values(c))J(Y.root,ne=>{Y===c.client&&ne.kind==="server-container"||N.push({node:ne,project:Y})});if(N.some(Y=>Y.node!==C&&Number(Y.node.guid)===_)||d.some(Y=>Number(Y.guid)===_))throw new Error(`\u63A7\u4EF6\u7D22\u5F15 ${_} \u5DF2\u88AB\u5176\u4ED6\u63A7\u4EF6\u6216\u811A\u672C\u5360\u7528`);let V=[],j=(Y,ne,Te)=>{let Q=Y?.[ne];(typeof Q=="number"||typeof Q=="string"&&/^\d+$/.test(Q.trim()))&&Number(Q)===T&&V.push({owner:Y,key:ne,project:Te.project})};for(let Y of N)j(Y.node,"referencedPrefabId",Y),j(Y.node,"itemPrefabId",Y),j(Y.node.giaRaw,"templateRefSlot",Y);if(V.length&&N.filter(Y=>Number(Y.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 Re={id:dc(),controlAsset:l,controlId:C.id,controlName:C.name,oldGuid:T,newGuid:_};C.guid=_;let pe=new Set([g]);for(let{owner:Y,key:ne,project:Te}of V)Y[ne]=typeof Y[ne]=="string"?String(_):_,pe.add(Te);o.push(Re);for(let Y of pe)Y.version+=1;return ie()}function re(h){let g=_e(h);if(!Array.isArray(h.changeIds)||!h.changeIds.length||h.changeIds.some(_=>typeof _!="string"||!o.some(T=>T.id===_)))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 C=new Set(h.changeIds);return o=o.filter(_=>!C.has(_.id)),g.version+=1,ie()}function Pe(h){if(!h||typeof h!="object")throw new Error("patch requires op");if(h.op==="setScriptSync"){let g=_e(h);return a=Vt(h.config),g.version+=1,ie()}if(h.op==="setControlGuid")return fi(h);if(h.op==="acknowledgeControlGuidChanges")return re(h);if(h.op==="setServerLogic"){let g=_e(h);return I=ei(h.logic),g.version+=1,ie()}if(h.op==="addScript"||h.op==="updateScript"||h.op==="removeScript")return ui(h);if(h.op==="selectAsset")return l=h.assetType===B?B:oe,ie();if(h.op==="renameSave"){let g=String(h.name||"").trim();if(!g)throw new Error("\u5B58\u6863\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");return f=g,ie()}if(h.op==="newAsset"){let g=_e(h);l=h.assetType===B?B:oe;let C=nn(l);return C.version=g.version+1,c[dt(l)]=C,o=o.filter(_=>_.controlAsset!==l),E(),ie()}return wr(Z(),h),E(),ie()}function Oe(h){return d.filter(g=>{let C=b(g);return!!(C&&C.key==="client"==(h===B))})}function Ft(h="json",g=""){let C=Ot(h,g);if(o.length&&!["save","archive"].includes(String(h).toLowerCase())){let _=o.map(T=>`\u63A7\u4EF6\u7D22\u5F15\u5F85\u6838\u5BF9 Lua \u5F15\u7528\uFF1A${tn[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`);C.warnings=[...new Set([...C.warnings||[],..._])]}return C}function Ot(h="json",g=""){let C=String(h).toLowerCase();if(C==="save"||C==="archive"){let N=Buffer.from(JSON.stringify(Nt(),null,2),"utf8");return G({filename:`${p().replace(/[\\/:*?"<>|]/g,"-")} \xB7 \u8D44\u4EA7\u5305.json`,mimeType:"application/json",encoding:"base64",data:N.toString("base64"),warnings:[]})}if(C==="save-gia"||C==="archive-gia"){let N=[],V=[],j=(pe,Y="")=>{let ne=Ft(pe,Y);N.push(G({filename:ne.filename,mimeType:ne.mimeType,encoding:ne.encoding,data:ne.data,warnings:ne.warnings||[]})),V.push(...ne.warnings||[])},Re=(pe,Y)=>{let ne=c[dt(pe)],Te=pe===l,Q=d.some(be=>be.controlAsset===pe&&be.controlId);if(!Te&&se(ne)&&!Q){V.push(Y);return}j("gia",pe)};if(Re(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"),Re(B,"\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)&&j("scripts-gia"),!N.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 G({format:"qxqy-gia-package",files:N,warnings:[...new Set(V)]})}if(C==="gia-combined"||C==="combined-gia"||C==="combined"){let N=Je();return G({filename:`${X(p(),Pt)} \xB7 \u6574\u5408\u5305.gia`,mimeType:"application/octet-stream",encoding:"base64",data:N.buffer.toString("base64"),warnings:[...new Set(N.warnings||[])]})}if(C==="scripts"){let N=G({format:yc,version:1,scripts:d.map(j=>G({id:j.id,guid:j.guid||0,path:j.path||"",source:j.source||"",controlId:j.controlId||"",controlAsset:j.controlAsset||""}))}),V=Buffer.from(JSON.stringify(N,null,2),"utf8");return G({filename:`${X(p(),Pt)} \xB7 \u811A\u672C.json`,mimeType:"application/json",encoding:"base64",data:V.toString("base64"),warnings:[]})}if(C==="scripts-gia"||C==="scriptsgia"){let N=ao(d);return G({filename:`${X(p(),Pt)} \xB7 \u811A\u672C.gia`,mimeType:"application/octet-stream",encoding:"base64",data:N.buffer.toString("base64"),warnings:N.warnings})}if(C==="lua"){let N=d.find(j=>j.id===g)||d.find(j=>j.path===g);if(!N)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=Rt(N.path||"")||`qxqy-script-${N.id}`;return G({filename:/\.lua$/i.test(V)?V:`${V}.lua`,mimeType:"text/x-lua",encoding:"base64",data:Buffer.from(N.source||"","utf8").toString("base64"),warnings:[]})}let _=g?c[dt(g)]:Z(),T=he(_);if(C==="json"){let N=G({..._,scripts:Oe(_.meta.assetType),controlGuidChanges:o.filter(j=>j.controlAsset===_.meta.assetType)}),V=Buffer.from(JSON.stringify(N,null,2),"utf8");return G({filename:`${T}.json`,mimeType:"application/json",encoding:"base64",data:V.toString("base64"),warnings:[]})}if(C==="gia"){let N=to(_,_.meta.assetType===B?{scripts:Oe(B)}:{}),V=_.meta.assetType===B?[]:Oe(oe);return V.length&&N.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`),G({filename:`${T}.gia`,mimeType:"application/octet-stream",encoding:"base64",data:N.buffer.toString("base64"),warnings:N.warnings})}throw new Error(`unsupported export format: ${h}`)}function Ye(h){for(let g of h){let C=$i(g);if(!C.path&&!C.source)continue;let _=C.controlId?null:S(C.guid),T=x(_?{...C,..._}:C);_&&T.guid!==C.guid&&k(_,C.guid,T.guid),T.controlId&&!b(T)&&(T.controlId="",T.controlAsset=""),d.push(T)}}function Dt(h,g,C=""){let _=String(h||"").toLowerCase();if(typeof g!="string"||!g)throw new Error("import data is required");let T=Buffer.from(g,"base64"),N,V=[],j={};if(_==="json"){try{N=JSON.parse(T.toString("utf8"))}catch{throw new Error("JSON \u6587\u4EF6\u65E0\u6548")}if(N?.project&&(N=N.project),N?.format===ht&&N?.assets){vr(N.version);let Q=on(N);V.push(...Q.get().migrationWarnings);let be=Q.archiveData();return c.server=be.assets.server,c.client=be.assets.client,i=[...V],l=N.activeAssetType===B?B:oe,f=String(N.meta?.name||Rt(C).replace(/\.json$/i,"")||f),I=be.serverLogic,d=be.assets.scripts,o=be.controlGuidChanges,a=be.scriptSync,m.clear(),G({snapshot:ie(),warnings:V,metadata:{format:ht}})}}else{if(_==="lua")return d.push(x({path:Rt(C||"imported.lua"),source:T.toString("utf8"),controlId:""})),G({snapshot:ie(),warnings:V,metadata:{assetType:"lua-script"}});if(_==="gia"){if(so(T)){let we=co(T);return Ye(we.scripts),G({snapshot:ie(),warnings:we.warnings,metadata:we.metadata})}let Q=uo(T);N=Q.project,V=Q.warnings,j=Q.metadata,Q.clientProject&&(c.client=We(Q.clientProject),o=o.filter(we=>we.controlAsset!==B),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 be=new Map,yn=(we,ps)=>{we&&J(we.root,vn=>{for(let Qi of vn.scriptMappingIds||[]){let bn=be.get(Number(Qi));if(bn){V.push(`\u811A\u672C GUID ${Qi} \u540C\u65F6\u6302\u8F7D\u5230\u591A\u4E2A\u63A7\u4EF6\uFF0C\u5DF2\u4FDD\u7559\u201C${bn.controlAsset===oe?"\u670D\u52A1\u7AEF":"\u5BA2\u6237\u7AEF"}\u201D\u76EE\u6807\u3002`);continue}be.set(Number(Qi),{controlId:vn.id,controlAsset:ps})}})};yn(Q.project,oe),yn(Q.clientProject,B),Ye((Q.scripts||[]).map(we=>be.has(Number(we.guid))?{...we,...be.get(Number(we.guid))}:we))}else throw new Error(`unsupported import format: ${h}`)}let Re=We(N,{warnings:V}),pe=rn(N?.controlGuidChanges);if(pe.some(Q=>Q.controlAsset!==Re.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 Y=rn([...o.filter(Q=>Q.controlAsset!==Re.meta.assetType),...pe]);i=[...V];let ne=dt(Re.meta.assetType);c[ne]=Re,o=Y,l=Re.meta.assetType;let Te=c[ne];return C&&(Te.meta.name=Rt(C).replace(/\.(json|gia)$/i,"")||Te.meta.name,Te.meta.sourceFile=Rt(C),Te.meta.sourceFormat=_),Ye(N?.scripts||[]),N?.script&&(N.script.path||N.script.source)&&Ye([N.script]),G({snapshot:ie(),warnings:V,metadata:j})}function Wa(h,g){return wr(Z(),{op:"pick",x:h,y:g}),ie()}function ja(h){let g=typeof h=="string"&&h?h:"";!g||g===r||(r=g)}function qa(h){let g=h.source||"";if(!g.trim()&&h.path.trim())try{g=fc(kc(h.path,r),"utf8")}catch(C){throw new Error(`\u811A\u672C ${h.path} \u8BFB\u53D6\u5931\u8D25: ${C?.message||C}`)}return g}function $t(h={}){let g=te(h.canvasId);g&&(O=g),h.playerCount!==void 0&&h.playerCount!==null&&h.playerCount!==""&&(F=lt(h.playerCount),U>F&&(U=1)),h.viewPlayerIndex!==void 0&&h.viewPlayerIndex!==null&&h.viewPlayerIndex!==""&&(U=ze(h.viewPlayerIndex,F)),A&&qr(A);let C=d.map(T=>{try{return{id:T.id,guid:T.guid||0,path:T.path||T.id,source:qa(T),controlId:T.controlId||"",controlAsset:T.controlAsset||""}}catch(N){return{id:T.id,guid:T.guid||0,path:T.path||T.id,source:`error([==[ ${String(N.message).replace(/]=+]/g,"] =]")} ])`,controlId:T.controlId||"",controlAsset:T.controlAsset||""}}}),_=T=>C.filter(N=>{let V={controlId:N.controlId,controlAsset:N.controlAsset},j=N.controlId?b(V):null;return!!(j&&j.key===T)});return A=ia(c.server,{templatesProject:c.client,scripts:C,sceneScripts:_("server"),templateScripts:_("client"),serverConfig:{logic:I},canvasId:O,playerCount:F,viewPlayerIndex:U,language:h.language||""}),ce(h)}function Ja(h,g={}){let C=te(h);if(!C)throw new Error("playSetCanvas requires canvasId");return $t({...g,canvasId:C})}function ce(h={}){if(!A)return G({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]});let g=Ur(A,h);return g.running=!0,g.logs=en(g.logs),g.serverLogs=en(g.server?.logs||[]),g.serverVars=gc(g.server,g.playerCount||1),g}function Za(h,g={}){return A||$t(),Fi(A,h),g.observe===!1?G({running:!0,time:A.runtime.clock.time,frame:A.runtime.clock.frame,paused:!!A.debugPaused,levelTimePaused:!!A.runtime.clock.paused,playerCount:A.playerCount||1,viewPlayerIndex:A.viewPlayerIndex||1}):ce(g)}function Qa(h=0){$t();let g=Math.max(0,Number(h)||0);for(let C=0;C<g;C++)Fi(A,1/30);return ce()}function es(){return A&&qr(A),A=null,O="",F=1,U=1,G({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]})}function ts(h,g={}){let C=Gt();return U=Br(C,h),g.observe===!1?null:ce(g)}function is(h,g={}){if(!A)throw new Error("play session has not started");return Hr(A,h),g.observe===!1?null:ce(g)}function rs(h,g={}){if(!A)throw new Error("play session has not started");return Xr(A,h),g.observe===!1?null:ce(g)}function ns(h,g,C,_={}){if(!A)throw new Error("play session has not started");return oi(A,h,g,C),_.observe===!1?null:ce(_)}function os(h={}){return A&&Oi(A).pause(),h.observe===!1?null:ce(h)}function as(h={}){return A&&Oi(A).resume(),h.observe===!1?null:ce(h)}function Gt(){if(!A)throw new Error("play session has not started");return A}function ss(h,g){let C=Gt();if(!h&&!g){let _=ce();return G({vars:_.serverVars||[]})}return G({entityType:String(h||""),name:String(g||""),value:ua(C,h,g)})}function ls(h,g,C){let _=Gt();return Wr(_,h,g,C),ce()}function cs(h,g=[],C="PlayerSelf"){let _=Gt();return jr(_,h,g,C),ce()}function us(){let h=ce();return G({events:h.history||[],case:Zo(h.history||[],{playerCount:h.playerCount||1})})}function fs(h={}){let g=ce(),C=ii({name:h.name||"",dt:h.dt,playerCount:h.playerCount||g.playerCount||1,events:h.events||g.history||[],asserts:h.asserts||[]});return G(C)}function ds(h,g={}){let C=ii(h);$t({...g,playerCount:g.playerCount||C.playerCount||1});let _=Gt();_.recording=!1;try{return ha(Oi(_),h)}finally{_.recording=!0}}function hs(){if(!A)return{running:!1,paused:!1,time:0,frame:0,playerCount:1,viewPlayerIndex:1};let h=A.runtime.clock;return{running:!0,paused:!!A.debugPaused,levelTimePaused:!!h.paused,time:h.time,frame:h.frame,playerCount:A.playerCount||1,viewPlayerIndex:A.viewPlayerIndex||1}}let gn={get:ie,patch:Pe,setWorkspace:ja,exportData:Ft,importData:Dt,pick:Wa,playStart:$t,playSetCanvas:Ja,playSetView:ts,playGet:ce,playStatus:hs,playStep:Za,playRun:Qa,playStop:es,playKey:is,playClick:rs,playPointer:ns,playPause:os,playResume:as,playServerGet:ss,playServerSet:ls,playServerSend:cs,playHistory:us,playSaveCase:fs,playRunCase:ds,archiveData:Nt};return Object.defineProperty(gn,"_project",{enumerable:!1,get:Z}),gn}import{createRequire as Ec}from"node:module";function ga(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}}var xc=Ec(import.meta.url),Ac=[0,-.5,.5,.5,-.5,.5],_c=[0,-.5,.12,-.12,.5,0,.12,.12,0,.5,-.12,.12,-.5,0,-.12,-.12],Pc=[0,-.5,.11,-.15,.48,-.15,.18,.07,.29,.41,0,.2,-.29,.41,-.18,.07,-.48,-.15,-.11,-.15],an=Buffer.from([137,80,78,71,13,10,26,10]),Rc=new Set(["image","textbox","textwindow","button"]),Gi={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"},zi=null;function va(){if(zi)return zi;try{zi=xc("@napi-rs/canvas")}catch(e){let t=e?.message||String(e);throw new Error(`Host screenshot renderer requires @napi-rs/canvas (${t})`)}return zi}function H(e,t=0){let i=Number(e);return Number.isFinite(i)?i:t}function Yi(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 pt(e,t=1){return`rgba(${e.r},${e.g},${e.b},${Math.max(0,Math.min(1,e.a*t))})`}function ba(e,t,i=1){let r=Math.max(1,Math.round(H(e,1))),n=Math.max(1,Math.round(H(t,1))),o=Math.max(1,Math.min(2,H(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 Sa(e){let t=Buffer.from(e.toBuffer("image/png"));if(t.length<an.length||!t.subarray(0,an.length).equals(an))throw new Error("Host screenshot renderer did not produce a PNG");return t}function Tc(e){return e==="triangle"?Ac:e==="fourstar"?_c:Pc}function Mc(e,t,i,r,n){let o=Tc(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=pt(n),e.fill()}function Nc(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,f,p]=n;e.transform(a*o,-s*o,-c*o,l*o,f,i-p);return}e.translate(H(t.left)+H(t.width)/2,i-H(t.bottom)-H(t.height)/2),e.rotate(-H(t.rotationZ)*Math.PI/180),e.scale(o,o)}function Fc(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 wa(e,t,i,r){let n=Yi(t.bgColor,16777215);e.fillStyle=pt(n),e.fillRect(-i/2,-r/2,i,r);let o=Math.max(8,H(t.fontSize,12)),a=Yi(t.fontColor,4294967295),s=t.horizontalAlignment==="Right"?1:t.horizontalAlignment==="Middle"?.5:0,c=t.verticalAlignment==="Bottom"?1:t.verticalAlignment==="Middle"?.5:0;if(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=pt(a),e.textAlign=s===1?"right":s===.5?"center":"left",e.textBaseline=c===1?"bottom":c===.5?"middle":"top",t.enableOutline){let y=Yi(t.outlineColor,4278190080);e.strokeStyle=pt(y),e.lineWidth=Math.max(2,o*.12),e.lineJoin="round"}let l=s===0?-i/2+2:s===1?i/2-2:0,f=c===0?-r/2:c===1?r/2:0,p=String(t.text||"").split(`
110
+ `),d=o*1.2,m=c===.5?f-(p.length-1)*d/2:c===1?f-(p.length-1)*d:f;for(let y=0;y<p.length;y+=1){let v=m+y*d;t.enableOutline&&e.strokeText(p[y],l,v),e.fillText(p[y],l,v)}e.restore()}function Ca(e,t,i,r){e.beginPath(),Fc(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 Ia(e,t,i,r){let n=Yi(t.imageColor,4294967295);if(t.primitive==="missing"){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=pt(n),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=pt(n),e.lineWidth=7,e.stroke();return}if(t.primitive==="triangle"||t.primitive==="fourstar"||t.primitive==="fivestar"){Mc(e,t.primitive,i,r,n);return}e.fillStyle=pt(n),e.fillRect(-i/2,-r/2,i,r)}function Oc(e,t,i){let r=Math.max(0,H(t.sourceWidth,H(t.width))),n=Math.max(0,H(t.sourceHeight,H(t.height)));if(e.save(),Nc(e,t,i),t.kind==="textbox"||t.kind==="textwindow")wa(e,t,r,n);else if(t.kind==="button")Ca(e,t,r,n);else{let o=ga(t,r,n);o&&(e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip()),Ia(e,t,r,n)}e.restore()}function ka(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 Dc(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 ya(e){let t=e?.matrix;return!t||typeof t!="object"?{a:1,b:0,c:0,d:1,tx:0,ty:0}:{a:H(t.a,1),b:H(t.b),c:H(t.c),d:H(t.d,1),tx:H(t.tx),ty:H(t.ty)}}function $c(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)=>H(s.z)-H(c.z));let r=[];function n(a,s){if(!Rc.has(a.kind))return;let c=Math.abs(H(a.sourceWidth)*Math.hypot(s.a,s.b)),l=Math.abs(H(a.sourceHeight)*Math.hypot(s.c,s.d));r.push({...a,left:s.tx-c/2,bottom:s.ty-l/2,width:c,height:l,rotationZ:Math.atan2(s.b,s.a)*180/Math.PI,matrix:{a:s.a,b:s.b,c:s.c,d:s.d,tx:s.tx,ty:s.ty}})}function o(a,s){let c=i.get(a)||[];for(let l=c.length-1;l>=0;l-=1){let f=c[l],p=s?Dc(s,ya(f)):ya(f);n(f,p),o(String(f.id),p)}}return o("",null),r}function Ea(e,t,i,r={}){return Gc($c(e),t,i,r)}function Gc(e,t,i,r={}){let{createCanvas:n}=va(),o=ba(t,i,r.scale),a=n(o.pixelWidth,o.pixelHeight),s=a.getContext("2d");s.scale(o.pixelRatio,o.pixelRatio),ka(s,o.width,o.height);let c=Array.isArray(e)?e:[];for(let l of c)!l||l.id===void 0||l.id===null||Oc(s,l,o.height);return{data:Sa(a),width:o.width,height:o.height,pixelWidth:o.pixelWidth,pixelHeight:o.pixelHeight}}function zc(e){return{kind:e.kind,left:H(e.renderLeft,e.left),bottom:H(e.renderBottom,e.bottom),width:Math.max(0,H(e.renderWidth,e.width)),height:Math.max(0,H(e.renderHeight,e.height)),rotationZ:H(e.renderRotationZ,e.rotationZ)}}function Vi(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 Vc(e,t,i,r){let n=zc(t);if(n.width<=0||n.height<=0)return;e.save(),e.translate(n.left+n.width/2,i-n.bottom-n.height/2),e.rotate(-n.rotationZ*Math.PI/180);let o=-n.width/2,a=-n.height/2;if(t.kind==="image")Ia(e,t,n.width,n.height);else if(t.kind==="textbox"||t.kind==="textwindow")wa(e,t,n.width,n.height);else if(t.kind==="button")Ca(e,t,n.width,n.height),Vi(e,t.name||Gi.button,n.width);else if(t.kind==="cursor")e.setLineDash([6,4]),e.strokeStyle="rgba(74,142,181,0.7)",e.fillStyle="rgba(74,142,181,0.1)",e.fillRect(o,a,n.width,n.height),e.strokeRect(o,a,n.width,n.height),Vi(e,t.name||Gi.cursor,n.width);else if(t.kind==="grid"){e.strokeStyle="rgba(106,146,189,0.55)",e.strokeRect(o,a,n.width,n.height),e.beginPath();for(let s=20;s<n.width;s+=20)e.moveTo(o+s,a),e.lineTo(o+s,a+n.height);for(let s=20;s<n.height;s+=20)e.moveTo(o,a+s),e.lineTo(o+n.width,a+s);e.stroke(),Vi(e,t.name||Gi.grid,n.width)}else t.kind!=="container"&&t.kind!=="server-container"?(e.setLineDash(t.kind==="reference"||t.kind==="animation"||t.kind==="fullscreen"?[4,4]:[]),e.strokeStyle="rgba(203,218,237,0.55)",e.strokeRect(o,a,n.width,n.height),Vi(e,t.name||Gi[t.kind]||t.kind,n.width)):(e.strokeStyle="rgba(78,165,230,0.42)",e.strokeRect(o,a,n.width,n.height));t.id===r&&t.kind!=="container"&&t.kind!=="server-container"&&(e.setLineDash([]),e.strokeStyle="#61b9ff",e.lineWidth=2,e.strokeRect(o,a,n.width,n.height)),e.restore()}function xa(e,t={}){let{createCanvas:i}=va(),r=e?.canvas||{},n=ba(r.width||1600,r.height||900,t.scale),o=i(n.pixelWidth,n.pixelHeight),a=o.getContext("2d");a.scale(n.pixelRatio,n.pixelRatio),ka(a,n.width,n.height,{checker:!0});let s=Array.isArray(e?.boxes)?e.boxes:[],c=e?.selectedId;for(let l of s)!l||l.kind==="server-container"||l.visible===!1||Vc(a,l,n.height,c);return{data:Sa(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 Yc,existsSync as Bi,openSync as Bc,opendirSync as Lc,readSync as Uc,realpathSync as Tt,statSync as _a}from"node:fs";import{basename as Hc,dirname as Aa,isAbsolute as un,join as Xc,relative as Pa,resolve as ci}from"node:path";var Kc="qxqy-simulator-save",Ra=new Set(["node_modules",".git","dist",".dsh","coverage"]),si=50,Ta=4096,sn=1e4,ln=1e3,cn=8;function mt(e=""){let t=ci(String(e||process.cwd()));if(!Bi(t))throw new Error(`workspace does not exist: ${t}`);if(!_a(t).isDirectory())throw new Error(`workspace is not a directory: ${t}`);return Tt(t)}function li(e,t,i=!1){let r=Pa(e,t);if(!i&&!r||r.startsWith("..")||un(r))throw new Error("path must stay inside the configured workspace");return r}function Fe(e,t){let i=String(t||"").trim();if(!i||un(i))throw new Error("path must be a non-empty workspace-relative path");let r=Tt(ci(e)),n=ci(r,i);if(li(r,n),!Bi(n))throw new Error(`file does not exist: ${i}`);let o=Tt(n);return li(r,o),o}function Ae(e,t){let i=String(t||"").trim();if(!i||un(i))throw new Error("path must be a non-empty workspace-relative path");let r=Tt(ci(e)),n=ci(r,i);li(r,n);let o=Aa(n);for(;!Bi(o);){let a=Aa(o);if(a===o)throw new Error("unable to resolve output directory");o=a}return li(r,Tt(o),!0),Bi(n)&&li(r,Tt(n)),n}function Wc(e,t=Ta){let i=Buffer.alloc(t),r=Bc(e,"r");try{let n=Uc(r,i,0,t,0);return i.subarray(0,n).toString("utf8")}finally{Yc(r)}}function Ma(e,t,i,r,n){if(r>cn){n.depthLimitedDirectories+=1;return}if(n.scannedDirectories>=ln){n.directoryLimitReached=!0;return}let o;try{n.scannedDirectories+=1,o=Lc(e)}catch{n.unreadableEntries+=1;return}try{let a;for(;a=o.readSync();){if(n.scannedEntries>=sn){n.entryLimitReached=!0;return}if(n.scannedEntries+=1,a.name.startsWith(".")||a.isDirectory()&&Ra.has(a.name)){n.skippedEntries+=1,a.isDirectory()&&(n.skippedDirectories+=1);continue}let s=Xc(e,a.name);if(a.isDirectory()){if(Ma(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=_a(s),l=Wc(s);if(!l.includes(Kc))continue;let f=l.match(/"name"\s*:\s*("(?:\\.|[^"\\])*")/)?.[1],p=Hc(a.name,".json");if(f)try{p=JSON.parse(f)||p}catch{}i.push({path:Pa(t,s).replaceAll("\\","/"),name:p,bytes:c.size,mtime:c.mtimeMs})}catch{n.unreadableEntries+=1}}}}catch{n.unreadableEntries+=1}finally{try{o.closeSync()}catch{n.unreadableEntries+=1}}}function Li(e){let t=mt(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:si,entries:sn,directories:ln,depth:cn,headBytes:Ta},policy:{excludedDirectories:[...Ra],hiddenEntries:!1,symlinks:!1,validatesJson:!1}};return Ma(t,t,i,0,r),i.sort((n,o)=>o.mtime-n.mtime||n.path.localeCompare(o.path)),r.matchedArchives=i.length,i.length>si&&r.warnings.push(`\u53D1\u73B0 ${i.length} \u4E2A\u5B58\u6863\uFF0C\u4EC5\u663E\u793A\u4FEE\u6539\u65F6\u95F4\u6700\u65B0\u7684 ${si} \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${sn} \u9879 / ${ln} \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 ${cn} \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>si||r.entryLimitReached||r.directoryLimitReached||r.depthLimitedDirectories>0,{bound:!0,workspace:t,archives:i.slice(0,si),discovery:r}}import{readFileSync as jc}from"node:fs";import{homedir as qc}from"node:os";import{join as Jc}from"node:path";var Zc={"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 Qc(e){let i=[...String(e||"").matchAll(/Request to set language:([A-Za-z0-9_-]+)/g)].at(-1)?.[1]?.toLowerCase();return Zc[i]||null}function eu(){return Jc(qc(),"AppData","LocalLow","miHoYo","\u539F\u795E","output_log.txt")}function Na(e=eu()){try{return Qc(jc(e,"utf8"))}catch{return null}}import{existsSync as hn,lstatSync as tu,mkdirSync as Fa,readFileSync as Ui,readdirSync as iu,realpathSync as Oa,renameSync as ru,rmSync as nu,statSync as Ki,writeFileSync as Da}from"node:fs";import{createHash as ou,randomUUID as $a}from"node:crypto";import{homedir as au}from"node:os";import{basename as su,dirname as Hi,isAbsolute as lu,join as Xi,relative as cu}from"node:path";var Ve=e=>ou("sha256").update(e).digest("hex"),fn=e=>hn(e)?Ve(Ui(e)):null,dn=(e,t)=>{let i=cu(e,t);return!lu(i)&&i!==".."&&!i.startsWith(`..${process.platform==="win32"?"\\":"/"}`)};function Ga(e,t){let i=Ae(e,t),r=i;for(;r!==e;){try{if(tu(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=Hi(r)}if(hn(i)&&!Ki(i).isFile())throw new Error("\u5B9E\u673A\u76EE\u6807\u4E0D\u662F\u666E\u901A\u6587\u4EF6");return i}function za(e=Xi(au(),"AppData","LocalLow","miHoYo","\u539F\u795E","BeyondLocal")){let t=r=>{try{return iu(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=Xi(e,r,"Beyond_Local_Save_Level");for(let o of t(n)){let a=Xi(n,o,"external_lua_file","default_import_file");hn(a)&&Ki(a).isDirectory()&&i.push({uid:r,editorId:o,path:a})}}return{candidates:i}}var Wi=class{constructor(t){this.controller=t,this.plan=null,this.lastResult=null}preview(){let t=this.controller,i=t.studio.archiveData(),r=Vt(i.scriptSync);if(!r)throw new Error("\u8BF7\u5148\u914D\u7F6E\u5B9E\u673A\u811A\u672C\u76EE\u5F55");let n=Oa(t.activeWorkspacePath()),o=Oa(r.clientImportRoot);if(!Ki(o).isDirectory())throw new Error("\u5B9E\u673A\u5BFC\u5165\u6839\u76EE\u5F55\u4E0D\u5B58\u5728");let a=r.workspaceDir?Fe(n,r.workspaceDir):n;if(!Ki(a).isDirectory())throw new Error("\u5DE5\u4F5C\u533A\u811A\u672C\u76EE\u5F55\u4E0D\u5B58\u5728");if(dn(a,o)||dn(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(f=>{let p={id:f.id,path:f.path,sourceKind:f.source.trim()?"\u5B58\u6863\u6E90\u7801":"\u5DE5\u4F5C\u533A\u6587\u4EF6"};try{let d=pi(f.path);if(!/\.lua$/i.test(d))throw new Error("\u811A\u672C\u8DEF\u5F84\u5FC5\u987B\u4EE5 .lua \u7ED3\u5C3E");let m=r.workspaceDir?`${r.workspaceDir}/`:"";if(!d.startsWith(m))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(m.length)].filter(Boolean).join("/"),v=Ga(o,y),x=v.toLowerCase();s.set(x,(s.get(x)||0)+1);let I=null,A="";try{I=Ui(Fe(n,d),"utf8")}catch(U){A=U.message}if(!f.source.trim()&&I===null)throw new Error(A);let O=f.source.trim()?f.source:I,F=fn(v);return{...p,target:v,targetRelative:y,source:O,diskSource:I,diskError:A,sourceMismatch:!!(f.source.trim()&&I!==null&&f.source!==I),beforeSource:F===null?"":Ui(v,"utf8"),beforeHash:F,sourceHash:Ve(O),status:F===null?"\u65B0\u589E":F===Ve(O)?"\u672A\u53D8\u5316":"\u8986\u76D6"}}catch(d){return{...p,status:"\u9519\u8BEF",error:d.message}}});for(let f of c)f.target&&s.get(f.target.toLowerCase())>1&&(f.status="\u9519\u8BEF",f.error="\u591A\u4E2A\u811A\u672C\u6620\u5C04\u5230\u540C\u4E00\u76EE\u6807\u6587\u4EF6");let l=Ve(JSON.stringify({archive:i,workspace:n,root:o,rows:c}));return this.plan={id:$a(),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(f=>{let p=n.rows.find(d=>d.id===f);if(!p||p.error||p.status==="\u672A\u53D8\u5316")throw new Error("\u6240\u9009\u811A\u672C\u4E0D\u80FD\u590D\u5236\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");return p});this.controller.assertSavedArchive();let s=`.qxqy-script-sync-backups/${n.id}`,c=Ae(n.workspace,s);if(dn(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 f of a){let p="";try{let d=Ga(n.root,f.targetRelative);if(fn(d)!==f.beforeHash)throw new Error("\u76EE\u6807\u6587\u4EF6\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");if(f.beforeHash!==null){let m=Ae(n.workspace,`${s}/${f.targetRelative}`);Fa(Hi(m),{recursive:!0}),Da(m,Ui(d),{flag:"wx"})}if(Fa(Hi(d),{recursive:!0}),p=Xi(Hi(d),`.${su(d)}.${$a()}.tmp`),Da(p,f.source,{flag:"wx"}),fn(d)!==f.beforeHash)throw new Error("\u76EE\u6807\u6587\u4EF6\u5DF2\u53D8\u5316\uFF0C\u8BF7\u91CD\u65B0\u68C0\u67E5");ru(p,d),l.push({id:f.id,target:d,status:"\u6210\u529F"})}catch(d){l.push({id:f.id,target:f.target,status:"\u5931\u8D25",error:d.message})}finally{p&&nu(p,{force:!0})}}return this.lastResult={completed:l.every(f=>f.status==="\u6210\u529F"),at:new Date().toISOString(),backupRoot:c,results:l},this.lastResult}};var gu=Math.max(1e3,Number(process.env.QXQY_PLAY_TIMEOUT_MS)||8e3),yu=8e3;function Va(){let e=new Error("operation aborted");return e.name="AbortError",e}var Mt=class{constructor(t=""){this.workspacePath=t?mt(t):"",this.studio=on(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 Wi(this)}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 za();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=Fe(this.activeWorkspacePath(),this.archivePath);if(Ve(pn(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=Ae(this.activeWorkspacePath(),t);if(fu(r)){let n=this.archivePath?Ae(this.activeWorkspacePath(),this.archivePath):"";if(r!==n||Ve(pn(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 Li(this.workspacePath)}loadArchive(t){let i=this.activeWorkspacePath();if(!i)throw new Error("workspace is not bound");let r=Fe(i,t),n=pn(r),o=this.studio.importData("json",n.toString("base64"),pu(r));return this.archivePath=String(t).trim().replaceAll("\\","/"),this.archiveStamp=Ve(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=Ae(r,i);du(mu(n),{recursive:!0});let o=Buffer.from(JSON.stringify(this.studio.archiveData(),null,2)+`
111
+ `,"utf8");return hu(n,o),this.archivePath=i.replaceAll("\\","/"),this.archiveStamp=Ve(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 uu(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=gu){let o=this.worker||this.createWorker(),a=this.sequence++;return new Promise((s,c)=>{let l=!1,f=(m,y)=>{l||(l=!0,clearTimeout(d),r?.removeEventListener("abort",p),m(y))},p=()=>{this.pending.delete(a),f(c,Va()),this.terminateWorker(Va())},d=setTimeout(()=>{this.pending.delete(a);let m=new Error(`play worker timed out after ${n}ms`);f(c,m),this.terminateWorker(m)},n);if(this.pending.set(a,{resolve:m=>f(s,m),reject:m=>f(c,m)}),r?.aborted)return p();r?.addEventListener("abort",p,{once:!0}),o.postMessage({id:a,action:t,args:i})})}async play(t,i={},r){if((t==="start"||t==="device")&&!i.language){let n=Na();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(!K[n])throw new Error(`unknown canvas preset: ${n||"(empty)"} (available: ${Object.keys(K).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,yu),r=Ea(i.scene,i.canvasWidth,i.canvasHeight);return{data:r.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:r.width,height:r.height,pixelWidth:r.pixelWidth,pixelHeight:r.pixelHeight}}uiScreenshot(){let t=xa(this.studio.get());return{data:t.data,page:t.page,width:t.width,height:t.height,pixelWidth:t.pixelWidth,pixelHeight:t.pixelHeight}}async dispose(){await this.terminateWorker()}};var bu=new Set(["server-control-template","client-control-template"]),Su=new Set(["start","device","view","get","step","pointer","key","click","pause","resume","stop","serverGet","serverSet","serverSend","history","saveCase","runCase"]);function Ya(e){return String(e||"").trim().replaceAll("\\","/")}function Ba(e,t){let i=vu(Fe(e,t));return`${i.size}:${i.mtimeMs}`}function wu(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 La(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 ji=class{constructor({workspace:t,initialPath:i="",watchIntervalMs:r=700,discoveryIntervalMs:n=5e3}={}){this.workspace=mt(t),this.controller=new Mt(this.workspace),this.initialPath=Ya(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=Li(this.workspace),this.archiveCacheTime=Date.now()),this.archiveCache}previewStatus(){let t=this.controller.get();return{service:"beyond-simulator-web",version:Sn.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:wu(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=Ya(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=La(this.playState,{running:!1,logs:[]},"stop");let o=Ba(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 Ba(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&&!bu.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(!Su.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=La(this.playState,n,t),this.emit({type:"play",action:t,frame:this.playState.frame}),n}async currentState(t){return this.state()}editorScreenshot(){return this.controller.uiScreenshot()}playScreenshot(t){return this.controller.exclusive(()=>this.controller.playScreenshot(t))}subscribe(t){return this.listeners.add(t),()=>this.listeners.delete(t)}emit(t){for(let i of this.listeners)i(t)}async dispose(){this.disposed=!0,this.timer&&clearInterval(this.timer),this.timer=null,this.listeners.clear(),await this.controller.exclusive(()=>this.controller.dispose())}};import{existsSync as Cu,readFileSync as Iu}from"node:fs";import{createHash as ku}from"node:crypto";var Eu=new Set(["get","patch","import","export","archives","load-archive","save","play","script-sync","script-sync-apply"]),mn=e=>ku("sha256").update(Iu(e)).digest("hex"),qi=class{constructor(t,{initialPath:i="",maxSessions:r=8}={}){this.workspace=t,this.initialPath=i,this.maxSessions=r,this.sessions=new Map}getSession(t){if(typeof t!="string"||!/^[a-zA-Z0-9_-]{1,100}$/.test(t))throw new Error("Invalid editor sessionId");if(!this.sessions.has(t)){if(this.sessions.size>=this.maxSessions)throw new Error("Editor session limit reached; save your work and restart the server");let r={controller:new Mt(this.workspace),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=Fe(this.workspace,i),n=t.controller.loadArchive(i);return t.path=String(i).replaceAll("\\","/"),t.fileStamp=mn(r),{...n,snapshot:this.snapshot(t)}}async call(t,i,r){if(!Eu.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==="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=Ae(this.workspace,i.path);if(Cu(a)){let c=n.path?Ae(this.workspace,n.path):"";if(a!==c||mn(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=mn(a),s}})}async dispose(){await Promise.all([...this.sessions.values()].map(t=>t.controller.exclusive(()=>t.controller.dispose()))),this.sessions.clear()}};var Mu=Ka(new URL(".",import.meta.url)),Nu=Xa(Mu,"public"),Ha=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"]]),Fu={".html":"text/html; charset=utf-8",".js":"text/javascript; charset=utf-8",".css":"text/css; charset=utf-8"};function Ou(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 Zi(e){return{"cache-control":"no-store","content-type":e,"content-security-policy":"default-src 'self'; img-src 'self' data:; connect-src 'self'; style-src 'self' 'unsafe-inline'; script-src 'self'; object-src 'none'; frame-ancestors 'none'","x-content-type-options":"nosniff"}}function Ie(e,t,i){e.writeHead(t,Zi("application/json; charset=utf-8")),e.end(JSON.stringify(i))}function Du(e,t){e.writeHead(200,{...Zi("image/png"),"content-length":t.data.length,"x-qxqy-width":String(t.width||0),"x-qxqy-height":String(t.height||0)}),e.end(t.data)}async function Ji(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 $u(e){let t=process.platform==="win32"?"cmd.exe":process.platform==="darwin"?"open":"xdg-open",i=process.platform==="win32"?["/c","start","",e]:[e];xu(t,i,{detached:!0,stdio:"ignore",windowsHide:!0}).unref()}async function Gu(e={}){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=v=>Ru("sha256").update(v).digest(),o=n(i),a=new ji(e);await a.initialize();let s=new qi(a.workspace,e),c=new Set,l=a.subscribe(v=>{let x=`event: state
112
112
  data: ${JSON.stringify(v)}
113
113
 
114
- `;for(let I of c)I.write(x)}),f=mu(async(v,x)=>{let I=new URL(v.url||"/","http://localhost"),A=new AbortController;v.once("aborted",()=>A.abort());try{if(v.method==="GET"&&I.pathname==="/health"){Ie(x,200,{status:"ok"});return}if(i){let O=String(v.headers.authorization||""),F=O.startsWith("Basic ")?Buffer.from(O.slice(6),"base64").toString("utf8"):"";if(!(F.startsWith("simulator:")&&vu(n(F.slice(10)),o))){x.setHeader("www-authenticate",'Basic realm="QXQY Simulator", charset="UTF-8"'),Ie(x,401,{ok:!1,error:"Authentication required"});return}}if(!i&&r){let O=new URL(`http://${v.headers.host}`).hostname;if(!["127.0.0.1","localhost","[::1]"].includes(O)){Ie(x,403,{ok:!1,error:"Local Host required"});return}}if(v.method==="POST"){if(!/^application\/json(?:;|$)/i.test(v.headers["content-type"]||"")){Ie(x,415,{ok:!1,error:"application/json required"});return}if(v.headers.origin&&new URL(v.headers.origin).host!==v.headers.host){Ie(x,403,{ok:!1,error:"Cross-origin requests are not allowed"});return}}if(v.method==="GET"&&Da.has(I.pathname)){let O=Da.get(I.pathname),F=gu(Ga(wu,O));x.writeHead(200,qi(Cu[yu(O)]||"application/octet-stream")),x.end(F);return}if(v.method==="GET"&&I.pathname==="/api/state"){I.searchParams.get("refresh")==="1"&&a.archives(!0),Ie(x,200,{ok:!0,value:await a.currentState(A.signal)});return}if(v.method==="GET"&&I.pathname==="/api/preview"){Ie(x,200,{ok:!0,value:a.previewStatus()});return}if(v.method==="GET"&&I.pathname==="/api/editor.png"){ku(x,a.editorScreenshot());return}if(v.method==="GET"&&I.pathname==="/api/events"){x.writeHead(200,{...qi("text/event-stream; charset=utf-8"),connection:"keep-alive"}),x.write(`: connected
114
+ `;for(let I of c)I.write(x)}),f=Au(async(v,x)=>{let I=new URL(v.url||"/","http://localhost"),A=new AbortController;v.once("aborted",()=>A.abort());try{if(v.method==="GET"&&I.pathname==="/health"){Ie(x,200,{status:"ok"});return}if(i){let O=String(v.headers.authorization||""),F=O.startsWith("Basic ")?Buffer.from(O.slice(6),"base64").toString("utf8"):"";if(!(F.startsWith("simulator:")&&Tu(n(F.slice(10)),o))){x.setHeader("www-authenticate",'Basic realm="QXQY Simulator", charset="UTF-8"'),Ie(x,401,{ok:!1,error:"Authentication required"});return}}if(!i&&r){let O=new URL(`http://${v.headers.host}`).hostname;if(!["127.0.0.1","localhost","[::1]"].includes(O)){Ie(x,403,{ok:!1,error:"Local Host required"});return}}if(v.method==="POST"){if(!/^application\/json(?:;|$)/i.test(v.headers["content-type"]||"")){Ie(x,415,{ok:!1,error:"application/json required"});return}if(v.headers.origin&&new URL(v.headers.origin).host!==v.headers.host){Ie(x,403,{ok:!1,error:"Cross-origin requests are not allowed"});return}}if(v.method==="GET"&&Ha.has(I.pathname)){let O=Ha.get(I.pathname),F=_u(Xa(Nu,O));x.writeHead(200,Zi(Fu[Pu(O)]||"application/octet-stream")),x.end(F);return}if(v.method==="GET"&&I.pathname==="/api/state"){I.searchParams.get("refresh")==="1"&&a.archives(!0),Ie(x,200,{ok:!0,value:await a.currentState(A.signal)});return}if(v.method==="GET"&&I.pathname==="/api/preview"){Ie(x,200,{ok:!0,value:a.previewStatus()});return}if(v.method==="GET"&&I.pathname==="/api/editor.png"){Du(x,a.editorScreenshot());return}if(v.method==="GET"&&I.pathname==="/api/events"){x.writeHead(200,{...Zi("text/event-stream; charset=utf-8"),connection:"keep-alive"}),x.write(`: connected
115
115
 
116
- `),c.add(x),v.once("close",()=>c.delete(x));return}if(v.method==="POST"&&I.pathname==="/api/open"){let O=await ji(v);if(O.expectedWorkspace!==void 0){let F=mt(O.expectedWorkspace);if(!(process.platform==="win32"?F.toLowerCase()===a.workspace.toLowerCase():F===a.workspace))throw new Error(`Web workspace mismatch: ${a.workspace}`)}Ie(x,200,{ok:!0,value:await a.open(O.path,O.expectedWorkspace===void 0?"manual":"mcp-preview")});return}if(v.method==="POST"&&I.pathname.startsWith("/editor/api/")){let O=await ji(v,8388608),F=I.pathname.slice(12),U=await s.call(F,O,A.signal);Ie(x,200,{ok:!0,value:U});return}if(v.method==="POST"&&I.pathname==="/api/view"){Ie(x,200,{ok:!0,value:await a.setView(await ji(v))});return}if(v.method==="POST"&&I.pathname==="/api/play"){let O=await ji(v);Ie(x,200,{ok:!0,value:await a.play(O.action,O.args||{},A.signal)});return}Ie(x,404,{ok:!1,error:"not found"})}catch(O){Ie(x,400,{ok:!1,error:O?.message||String(O)})}}),p=Number.isFinite(Number(e.port))?Number(e.port):4173;try{await new Promise((v,x)=>{f.once("error",x),f.listen(p,t,v)})}catch(v){throw l(),await a.dispose(),await s.dispose(),v}let h=f.address(),m=typeof h=="object"&&h?h.port:p;return{url:`http://${t.includes(":")?`[${t}]`:t}:${m}`,session:a,server:f,async close(){l();for(let v of c)v.end();c.clear(),await a.dispose(),await s.dispose(),await new Promise(v=>f.close(v))}}}async function Au(){let e=Iu(),t=await xu(e);process.stdout.write(`QXQY Simulator Web: ${t.url}
117
- `),e.open&&Eu(t.url);let i=()=>{t.close().finally(()=>process.exit(0))};process.once("SIGINT",i),process.once("SIGTERM",i)}function Pu(){if(!process.argv[1])return!1;try{return $a(process.argv[1])===$a(za(import.meta.url))}catch{return!1}}Pu()&&Au().catch(e=>{process.stderr.write(`${e?.stack||e}
118
- `),process.exitCode=1});export{xu as createWebServer};
116
+ `),c.add(x),v.once("close",()=>c.delete(x));return}if(v.method==="POST"&&I.pathname==="/api/open"){let O=await Ji(v);if(O.expectedWorkspace!==void 0){let F=mt(O.expectedWorkspace);if(!(process.platform==="win32"?F.toLowerCase()===a.workspace.toLowerCase():F===a.workspace))throw new Error(`Web workspace mismatch: ${a.workspace}`)}Ie(x,200,{ok:!0,value:await a.open(O.path,O.expectedWorkspace===void 0?"manual":"mcp-preview")});return}if(v.method==="POST"&&I.pathname.startsWith("/editor/api/")){let O=await Ji(v,8388608),F=I.pathname.slice(12),U=await s.call(F,O,A.signal);Ie(x,200,{ok:!0,value:U});return}if(v.method==="POST"&&I.pathname==="/api/view"){Ie(x,200,{ok:!0,value:await a.setView(await Ji(v))});return}if(v.method==="POST"&&I.pathname==="/api/play"){let O=await Ji(v);Ie(x,200,{ok:!0,value:await a.play(O.action,O.args||{},A.signal)});return}Ie(x,404,{ok:!1,error:"not found"})}catch(O){Ie(x,400,{ok:!1,error:O?.message||String(O)})}}),p=Number.isFinite(Number(e.port))?Number(e.port):4173;try{await new Promise((v,x)=>{f.once("error",x),f.listen(p,t,v)})}catch(v){throw l(),await a.dispose(),await s.dispose(),v}let d=f.address(),m=typeof d=="object"&&d?d.port:p;return{url:`http://${t.includes(":")?`[${t}]`:t}:${m}`,session:a,server:f,async close(){l();for(let v of c)v.end();c.clear(),await a.dispose(),await s.dispose(),await new Promise(v=>f.close(v))}}}async function zu(){let e=Ou(),t=await Gu(e);process.stdout.write(`QXQY Simulator Web: ${t.url}
117
+ `),e.open&&$u(t.url);let i=()=>{t.close().finally(()=>process.exit(0))};process.once("SIGINT",i),process.once("SIGTERM",i)}function Vu(){if(!process.argv[1])return!1;try{return Ua(process.argv[1])===Ua(Ka(import.meta.url))}catch{return!1}}Vu()&&zu().catch(e=>{process.stderr.write(`${e?.stack||e}
118
+ `),process.exitCode=1});export{Gu as createWebServer};