dsh-plugin-beyond-simulator 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dsh-plugin/dist/index.js
CHANGED
|
@@ -104,5 +104,5 @@ ${r.errors.join(`
|
|
|
104
104
|
`)}`);return{buffer:n,warnings:[...new Set(t.warnings)]}}function Qi(e){return Se.toObject(Se.decode(ci(e)),{longs:Number,enums:Number,bytes:Buffer,defaults:!1,arrays:!0,objects:!0})}function $r(e){try{let i=Qi(e).graph||[];return i.length>0&&i.every(n=>Number(n.which)===bt)}catch{return!1}}function Dr(e){let t=(e.graph||[]).filter(r=>Number(r.which)===bt),i=[],n=t.map((r,o)=>{let a=r.script?.mapping||{},s=Number(r.id?.id)||0;s<=0&&i.push(`\u7B2C ${o+1} \u6761\u811A\u672C\u6620\u5C04\u7F3A\u5C11 GraphUnit.id.id\uFF0C\u5DF2\u6309 0 \u5904\u7406\uFF08\u5BFC\u51FA\u65F6\u4F1A\u91CD\u65B0\u5206\u914D\uFF09\u3002`);let 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[r,o]of n.entries())o.path&&!/\.lua$/iu.test(o.path)&&i.push(`\u7B2C ${r+1} \u6761\u811A\u672C\u6620\u5C04 file_path \u7F3A\u5C11 .lua \u540E\u7F00\uFF08${o.path}\uFF09\uFF0C\u771F\u673A\u53EF\u80FD\u62D2\u7EDD\u5BFC\u5165\uFF1B\u6A21\u62DF\u5668\u5185\u6309\u5F52\u4E00\u5316\u8DEF\u5F84\u7167\u5E38 require\u3002`);return{scripts:n,warnings:i}}function zr(e){let t=Qi(e),i=Dr(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 cs(e){let t=[],i;try{i=Qi(e)}catch(r){return{valid:!1,errors:[r?.message||String(r)],scriptCount:0}}let n=i.graph||[];return n.length||t.push("Root.graph \u4E3A\u7A7A"),(i.accessories||[]).length&&t.push("script.gia \u4E0D\u5E94\u5305\u542B accessories"),n.forEach((r,o)=>{let a=`\u5355\u5143 ${o+1}`;Number(r.which)!==bt&&t.push(`${a}: which \u5E94\u4E3A 69\uFF0C\u5B9E\u9645 ${r.which}`),Number(r.id?.class)!==Mr&&t.push(`${a}: id.class \u5E94\u4E3A 30\uFF0C\u5B9E\u9645 ${r.id?.class}`),Number(r.id?.type??0)!==0&&t.push(`${a}: id.type \u5E94\u7F3A\u7701`);let s=r.script?.mapping;if(!s){t.push(`${a}: \u7F3A\u5C11 field35 ScriptMappingWrapper`);return}Number(r.id?.id)<=0&&t.push(`${a}: GraphUnit.id.id \u975E\u6CD5`),Number(s.id)!==Number(r.id?.id)&&t.push(`${a}: mapping.id \u5E94\u7B49\u4E8E GraphUnit.id.id`),String(s.name||"")!==String(r.name||"")&&t.push(`${a}: mapping.name \u5E94\u7B49\u4E8E GraphUnit.name`),String(s.filePath||"").trim()?/\.lua$/iu.test(String(s.filePath))||t.push(`${a}: file_path \u5E94\u4EE5 .lua \u7ED3\u5C3E\uFF08\u5B98\u65B9 script.gia \u6837\u672C\u5747\u4E3A \u540D\u79F0.lua\uFF0C\u771F\u673A require \u65F6\u624D\u53BB\u6269\u5C55\u540D\uFF09`):t.push(`${a}: file_path \u4E3A\u7A7A`)}),{valid:t.length===0,errors:t,scriptCount:n.length}}function ci(e){let t=Buffer.isBuffer(e)?e:Buffer.from(e);if(t.length<Ve+Wi)throw new Error("GIA \u6587\u4EF6\u8FC7\u77ED");if(t.readUInt32BE(4)!==1||t.readUInt32BE(8)!==br||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-Ve-Wi)throw new Error("GIA payload \u957F\u5EA6\u4E0D\u4E00\u81F4");if(t.readUInt32BE(Ve+i)!==vr)throw new Error("GIA \u5C3E\u6807\u8BB0\u65E0\u6548");return t.subarray(Ve,Ve+i)}function he(e,t){return e.ui?.content?.data?.find(i=>i.details?.[t])?.details?.[t]||null}function fs(e){let t=he(e,"transform")?.multiPlatform,i={};for(let r of t?.platforms||[]){let o=Qa[r.platformType||0],a=r.transform||{};i[o]={scale:a.scale?{x:a.scale.x??0,y:a.scale.y??0,z:a.scale.z??0}:{x:1,y:1,z:1},rotation:{x:0,y:0,z:0},anchorMin:{x:a.anchorMin?.x??0,y:a.anchorMin?.y??0},anchorMax:{x:a.anchorMax?.x??0,y:a.anchorMax?.y??0},offset:{x:a.offset?.x??0,y:a.offset?.y??0},size:{x:a.size?.x??0,y:a.size?.y??0},pivot:a.pivot?{x:a.pivot.x??0,y:a.pivot.y??0}:{x:.5,y:.5}}}let n=i.KEYBOARD||i[Object.keys(i)[0]];if(!n)throw new Error(`GIA \u63A7\u4EF6 ${e.name||e.id?.id} \u7F3A\u5C11\u591A\u5E73\u53F0\u53D8\u6362`);for(let r of te)i[r]||(i[r]=structuredClone(n));return i}function ui(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 yr(e,{reverseSiblings:t=!1,idOffset:i=0}={}){if(!e.length)return{nodes:new Map,rootCandidates:[],warnings:[]};let n=new Map(e.map((l,f)=>[l.id?.id,`n${i+f+1}`])),r=new Map,o=new Map,a=[];for(let l of e){let f=ui(l),h=he(l,"textConfig"),p=he(l,"imageSlot"),m=he(l,"image"),g=he(l,"buttonPreset"),I=he(l,"gridView"),k=he(l,"genericSlot"),E=he(l,"footerSlot"),$=he(l,"cursorConfig"),F=he(l,"keyHint"),U=he(l,"containerNodeSlot"),W=he(l,"templateRefSlot"),Z=he(l,"effectSlot"),q=he(l,"fullscreenEffectSlot"),O=B(f,{id:n.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,scriptMappingIds:(k?.field502||[]).map(b=>Number(b?.field1?.id)).filter(b=>Number.isSafeInteger(b)&&b>0),transformByPlatform:fs(l),syncAllDevices:he(l,"transform")?.multiPlatform?.field504===1,giaRaw:{genericField501:k?.field501??0,footerField505:E?.field505??0,...f==="container"?{containerNodeSlot:U??""}:{},...f==="textbox"||f==="textwindow"?{textField501:h?.field501??20,textField503:h?.field503??12,textAlign:h?.align??0,...f==="textwindow"?{textField511:h?.field511??1,textViewField502:h?.viewFlags?.field502??1,textViewField503:h?.viewFlags?.field503??1}:{}}:{},...f==="cursor"?{cursorField501:$?.field501??1}:{},...f==="reference"?{templateRefSlot:W??""}:{},...f==="grid"?{gridField501:I?.field501??1,gridField507:I?.field507??1,gridField508:I?.field508??1,gridField509:I?.field509??1,gridField511:I?.field511??5,gridField512:I?.field512??1}:{},...f==="keyhint"?{keyHintField501:F?.field501??1,keyHintField502:F?.field502??1}:{},...f==="image"?{imageField502:m?.field502??1,imageField504:m?.field504??1,imageField505:m?.field505??1,imageField507:m?.field507??2,imageFillType:m?.fillType??1}:{},...f==="animation"?{effectSlot:Z??""}:{},...f==="fullscreen"?{fullscreenEffectSlot:q??""}:{}},...f==="textbox"||f==="textwindow"?{text:h?.text?.value??"",fontSize:h?.fontSize??20,minimumFontSize:h?.minimumFontSize??20,adaptiveFontSize:h?.adaptive===1,fontColor:h?.color??4294967295,bgColor:h?.color2??0,enableOutline:h?.outlineOff!==1,outlineColor:h?.color3??858993459,horizontalAlignment:h?.align===1?"Middle":h?.align===2?"Right":"Left",verticalAlignment:"Top",...f==="textwindow"?{interactable:!0,showScrollBar:!0}:{}}:{},...f==="image"?{imageSource:"StaticReference",imageId:p?.assetId??0,imageColor:Number.isFinite(p?.field502)?p.field502>>>0:4294967295,enableMask:m?.enableMask===1,enableSoftEdge:m?.enableSoftEdge===1,enableFill:m?.enableFill===1,softEdgeMode:m?.softEdgePixel===1?"Pixel":"Percentage",softEdgeWidthX:m?.border?.field501??8,softEdgeWidthY:m?.border?.field502??8,horizontalSoftRange:m?.field512??85,verticalSoftRange:m?.field513??85,fillType:{1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[m?.fillType]||"Horizontal",fillAmount:Number.isFinite(m?.field508)?Math.max(0,Math.min(1,m.field508/100)):m?.enableFill===1?0:1,reverseMaskArea:m?.reverseMask===1}:{},...f==="button"?{interactable:g?.interactable===1,raycastTarget:g?.raycastTarget===1,clickAudioId:g?.clickAudioId??50888}:{},...f==="grid"?{cellSizeX:I?.cellSize?.field501??50,cellSizeY:I?.cellSize?.field502??50,spacingX:I?.gap?.field501??8,spacingY:I?.gap?.field502??8,padding1X:I?.padding1?.field501??20,padding1Y:I?.padding1?.field502??20,padding2X:I?.padding2?.field501??20,padding2Y:I?.padding2?.field502??20,previewCount:I?.field511??5}:{},...f==="reference"?{referencedPrefabId:W??""}:{},...f==="keyhint"?{keyboardKeyCode:F?.field502??null,controllerKeyCode:F?.field501??null}:{},...f==="animation"?{animationId:Z??""}:{},...f==="fullscreen"?{animationId:q??""}:{}});r.set(l.id?.id,O),(f==="textbox"||f==="textwindow")&&![void 0,0,1,2].includes(h?.align)&&a.push(`${O.name}: \u6C34\u5E73\u5BF9\u9F50\u679A\u4E3E ${h.align} \u7684\u542B\u4E49\u672A\u77E5\uFF0C\u5DF2\u539F\u6837\u4FDD\u7559\u3002`),f==="image"&&![void 0,0,1,2,3,4,5].includes(m?.fillType)&&a.push(`${O.name}: \u586B\u5145\u5F62\u72B6\u679A\u4E3E ${m.fillType} \u672A\u8BC6\u522B\uFF0C\u5DF2\u4FDD\u7559\u539F\u503C\u3002`),f==="button"&&o.set(O.id,{unavailableChildId:g?.disabledChild,hoverChildId:g?.hoverChild,pressedChildId:g?.pressedChild,selectedChildId:g?.selectedChild})}let s=[],c=new Set;for(let l of e){let f=r.get(l.id?.id),h=(l.ui?.content?.children||[]).map(p=>r.get(p)).filter(Boolean);if(h.length){f.children=t?h.slice().reverse():h;for(let p of h)c.add(p.id)}}for(let l of e){let f=r.get(l.id?.id),h=l.ui?.content?.parent||0,p=r.get(h);p?c.has(f.id)||(t?p.children.unshift(f):p.children.push(f)):s.push(f)}for(let[l,f]of o){let h=[...r.values()].find(p=>p.id===l);for(let[p,m]of Object.entries(f))h[p]=n.get(m)||null}return{nodes:r,rootCandidates:s,warnings:a}}function Gr(e){let t=ci(e),i=Se.toObject(Se.decode(t),{longs:Number,enums:Number,bytes:Buffer,defaults:!1,arrays:!0,objects:!0}),n=i.graph||[];if(!n.some(g=>g.ui?.content))throw new Error("GIA \u4E0D\u542B\u53EF\u8BC6\u522B\u7684 UIControlGroup \u4E3B\u56FE");let r=n.find(g=>g.which===21)||null,o=n.filter(g=>Number(g.which)===70),a=i.accessories||[],s=new Set((r?.relatedIds||[]).map(g=>g.id||0)),c=r?s.size?a.filter(g=>s.has(g.id?.id||0)):a:[],l=o.length?[...o,...a.filter(g=>!s.has(g.id?.id||0))]:r?[]:[...n,...a];if(!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"],h=Dr(i);f.push(...h.warnings);let p=null,m=null;if(c.length){let g=yr(c,{reverseSiblings:!0,idOffset:0});f.push(...g.warnings);let I=g.rootCandidates.find(E=>E.kind==="container")||g.rootCandidates[0];if(!I)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6839\u63A7\u4EF6");let k=B("server-container",{id:"sc1",guid:r?.id?.id||0,name:r?.name||"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668",giaRelatedGuids:(r?.ui?.content?.info||[]).find(E=>E.field501===4&&E.field502===4)?.related?.value||[]});k.children=[I],g.rootCandidates.length>1&&f.push(`\u68C0\u6D4B\u5230 ${g.rootCandidates.length} \u4E2A\u65E0\u7236\u8282\u70B9\u63A7\u4EF6\uFF0C\u4EC5\u5BFC\u5165\u4EE5\u201C${I.name}\u201D\u4E3A\u6839\u7684\u6811\u3002`),p={version:1,layoutSchemaVersion:ce,meta:{name:r?.name||"\u5BFC\u5165\u7684\u754C\u9762\u63A7\u4EF6\u7EC4",assetType:"server-control-template",sourceFormat:"gia",sourceFile:"",gameVersion:i.gameVersion||"",giaFilePath:i.filePath||"",...Number.isSafeInteger(Number(i.modeFlag))?{giaModeFlag:Number(i.modeFlag)}:{}},canvasId:"pc-16-9",selectedId:I.id,script:{controlId:I.id,path:"",source:""},root:k}}if(l.length){let g=yr(l,{reverseSiblings:!1,idOffset:1e3});if(f.push(...g.warnings),!g.rootCandidates.length)throw new Error("GIA \u672A\u627E\u5230\u5BA2\u6237\u7AEF\u6A21\u677F");let I=B("server-container",{id:"sc1",guid:0,name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"});I.children=g.rootCandidates,m={version:1,layoutSchemaVersion:ce,meta:{name:g.rootCandidates.length===1?g.rootCandidates[0].name:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868",assetType:"client-control-template",sourceFormat:"gia",sourceFile:"",gameVersion:i.gameVersion||"",giaFilePath:i.filePath||"",...Number.isSafeInteger(Number(i.modeFlag))?{giaModeFlag:Number(i.modeFlag)}:{}},canvasId:"pc-16-9",selectedId:g.rootCandidates[0].id,script:{controlId:g.rootCandidates[0].id,path:"",source:""},root:I},p||(p=m)}return{project:p,clientProject:m&&p!==m?m:void 0,scripts:h.scripts,warnings:f,metadata:{gameVersion:i.gameVersion||"",filePath:i.filePath||"",...Number.isSafeInteger(Number(i.modeFlag))?{modeFlag:Number(i.modeFlag)}:{},combined:!!(r&&o.length)}}}function Vr(e){let t=ci(e),i=Se.toObject(Se.decode(t),{longs:Number,enums:Number,defaults:!1,arrays:!0,objects:!0}),n=i.graph||[],r=i.accessories||[],o=[],a=(p,m)=>p!=null&&Object.prototype.hasOwnProperty.call(p,m),s=new Map,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=n.filter(p=>p.which===70).map(p=>{let m=ui(p),g=p.ui?.content?.info||[],I=g.find(F=>F.field501===2&&F.field502===6)?.index?.value,k=Sr[m],E=g.find(F=>F.field501===4&&F.field502===4),$=E?.related?.value||[];return(!Number.isSafeInteger(I)||I<=0)&&o.push(`${p.name}: Info.index=${I??"<missing>"}\uFF0C\u5FC5\u987B\u662F\u6B63\u6574\u6570`),E||o.push(`${p.name}: \u9876\u5C42 UIControlTemplate \u7F3A\u5C11 Info.related \u8BB0\u5F55`),{id:p.id?.id||0,name:p.name||"",kind:m,actualIndex:I,expectedIndex:k,relatedPresent:!!E,relatedGuids:$}});l.length||o.push("Root.graph \u4E0D\u542B UIControlTemplate(70)");let f=0,h=0;for(let p of[...n,...r]){if(!p.ui?.content)continue;let m=p.id?.id||0,g=p.ui.content,I=ui(p),k=n.includes(p)&&p.which===70,E=`${p.name||"<unnamed>"}(${m||"<missing-guid>"})`;!Number.isSafeInteger(m)||m<=0||m>2147483647?o.push(`${E}: GraphUnit GUID \u975E\u6CD5`):s.has(m)?o.push(`${E}: GUID \u4E0E ${s.get(m).name||"<unnamed>"} \u91CD\u590D`):s.set(m,p),(p.id?.class!==1||p.id?.type!==8)&&o.push(`${E}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),g.guid!==m&&o.push(`${E}: content.guid=${g.guid??"<missing>"} \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`),k&&p.which!==70&&o.push(`${E}: \u6A21\u677F\u6839 which \u5FC5\u987B\u4E3A UIControlTemplate(70)`),!k&&p.which!==15&&o.push(`${E}: \u9644\u4EF6\u63A7\u4EF6 which \u5FC5\u987B\u4E3A UIControl(15)`);let $=g.info||[],F=$.find(S=>S.field501===1&&S.field502===5),U=$.find(S=>S.field501===2&&S.field502===6);F?.guid?.value!==m&&o.push(`${E}: Info.self GUID \u7F3A\u5931\u6216\u4E0E\u81EA\u8EAB\u4E0D\u4E00\u81F4`),(!Number.isSafeInteger(U?.index?.value)||U.index.value<=0)&&o.push(`${E}: Info.index=${U?.index?.value??"<missing>"}\uFF0C\u5FC5\u987B\u662F\u6B63\u6574\u6570`);let W=$.find(S=>S.field501===4&&S.field502===4);k&&!W&&o.push(`${E}: \u9876\u5C42\u6A21\u677F\u7F3A\u5C11 Info.related \u8BB0\u5F55`),!k&&W&&o.push(`${E}: \u9644\u4EF6\u63A7\u4EF6\u4E0D\u5E94\u5199 Info.related`);let Z=Ir[I],q=g.data||[],O=q.map(S=>`${S.field501}/${S.field502}`),b=Z?.map(([S])=>S)||[];Z?JSON.stringify(O)!==JSON.stringify(b)&&o.push(`${E}: Data \u69FD\u4F4D\u987A\u5E8F ${O.join(",")}\uFF0C\u5E94\u4E3A ${b.join(",")}`):o.push(`${E}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${I}`);for(let S=0;S<Math.min(q.length,Z?.length||0);S+=1){let P=q[S],[z,G,ie]=Z[S];if(a(P,G)||o.push(`${E}: Data ${z} \u7F3A\u5C11 ${G} \u5206\u652F`),!ie)continue;a(P.details,ie)||o.push(`${E}: Details ${z} \u7F3A\u5C11 ${ie} \u5206\u652F`);let j=Cr[z];(P.details?.field501!==j||P.details?.field502!==P.field502||P.details?.field503!==1)&&o.push(`${E}: Details ${z} \u6807\u8BB0\u5E94\u4E3A ${j}/${P.field502}/1`);let ue=P.details?.nodeRef;(ue?.class!==1||ue?.type!==8||ue?.id!==m)&&o.push(`${E}: Details ${z} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let x=(p.ui.content.data||[]).find(S=>S.field501===4&&S.field502===86);x&&(a(x.field14,"field17")?f+=1:o.push(`${E}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`),a(x.details?.field14,"field17")?f+=1:o.push(`${E}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.field17 \u7A7A\u4E32`));let v=(p.ui.content.data||[]).find(S=>S.details?.transform)?.details?.transform?.multiPlatform?.platforms||[];v.length!==4&&o.push(`${E}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${v.length}\uFF0C\u5E94\u4E3A 4`);let C=v.map(S=>S.platformType||0);JSON.stringify(C)!==JSON.stringify([0,1,2,3])&&o.push(`${E}: \u5E73\u53F0\u987A\u5E8F ${C.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let M=(p.ui.content.data||[]).find(S=>S.details?.transform)?.details?.transform;M?.multiPlatform?.field502!==zt[I]&&o.push(`${E}: \u53D8\u6362 preset=${M?.multiPlatform?.field502??"<missing>"}\uFF0C${I} \u5E94\u4E3A ${zt[I]}`);for(let S of v)a(S.transform,"field508")?h+=1:o.push(`${E}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);c.push({id:m,name:p.name||"",kind:I,template:k,parent:g.parent||0,children:[...g.children||[]],relatedIds:(p.relatedIds||[]).map(S=>S.id||0),dataSignatures:O})}for(let p of c){let m=`${p.name||"<unnamed>"}(${p.id})`;if(JSON.stringify(p.relatedIds)!==JSON.stringify(p.children)&&o.push(`${m}: GraphUnit.relatedIds \u4E0E content.children \u4E0D\u4E00\u81F4`),p.template&&p.parent&&o.push(`${m}: \u9876\u5C42\u6A21\u677F\u4E0D\u5E94\u6709 parent`),!p.template){let g=s.get(p.parent);g?(g.ui?.content?.children||[]).includes(p.id)||o.push(`${m}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):o.push(`${m}: parent=${p.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let g of p.children){let I=s.get(g);I?(I.ui?.content?.parent||0)!==p.id&&o.push(`${m}: child=${g} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):o.push(`${m}: child=${g} \u4E0D\u5B58\u5728`)}}return{valid:o.length===0,errors:o,filePath:i.filePath||"",gameVersion:i.gameVersion||"",templateCount:l.length,accessoryCount:r.length,templates:l,units:c,explicitEmpty:{field17:f,rectField508:h}}}function en(e){let t=ci(e),i=Se.toObject(Se.decode(t),{longs:Number,enums:Number,defaults:!1,arrays:!0,objects:!0}),n=(i.graph||[]).filter(S=>S.ui?.content&&Number(S.which)===21),r=(i.graph||[]).filter(S=>Number(S.which)===70),o=(i.graph||[]).filter(S=>Number(S.which)===bt),a=(i.accessories||[]).filter(S=>S.ui?.content),s=[],c=(S,P)=>S!=null&&Object.prototype.hasOwnProperty.call(S,P);/^\d+-\d+-\d+-\\.+\.gia$/iu.test(i.filePath||"")||s.push(`Root.filePath \u4E0D\u662F UID-TIME-ID-\\\u6587\u4EF6\u540D.gia\uFF1A${i.filePath||"<missing>"}`),n.length!==1&&s.push(`\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F UIControlGroup \u6570\u91CF=${n.length}\uFF0C\u5E94\u4E3A 1`);let l=(i.graph||[]).filter(S=>{let P=Number(S.which);return P===bt||P===70||P===21?!1:!S.ui?.content});l.length&&s.push(`Root.graph \u542B ${l.length} \u4E2A\u65E0\u6CD5\u8BC6\u522B\u7684\u975E\u63A7\u4EF6/\u975E\u811A\u672C\u5355\u5143`);let f=n[0];if(!f)return{valid:!1,errors:s,filePath:i.filePath||"",gameVersion:i.gameVersion||"",accessoryCount:a.length,controls:[],scriptCount:o.length,explicitEmpty:{field17:0,rectField508:0}};let h=[f,...a],p=new Map;for(let S of h){let P=S.id?.id||0,z=`${S.name||"<unnamed>"}(${P||"<missing-guid>"})`;!Number.isSafeInteger(P)||P<=0||P>2147483647?s.push(`${z}: GraphUnit GUID \u975E\u6CD5`):p.has(P)?s.push(`${z}: GUID \u91CD\u590D`):p.set(P,S),(S.id?.class!==1||S.id?.type!==8)&&s.push(`${z}: GraphUnit.id \u5FC5\u987B\u4E3A class=1,type=8`),S.ui?.content?.guid!==P&&s.push(`${z}: content.guid \u4E0E GraphUnit.id.id \u4E0D\u4E00\u81F4`)}let m=f.id?.id||0,g=f.ui.content,I=`${f.name||"<unnamed>"}(${m})`;f.which!==21&&s.push(`${I}: which \u5FC5\u987B\u4E3A UIControlGroup(21)`);let k=g.info||[];k.find(S=>S.field501===1&&S.field502===5)?.guid?.value!==m&&s.push(`${I}: Info.self GUID \u7F3A\u5931\u6216\u4E0D\u4E00\u81F4`),k.find(S=>S.field501===2&&S.field502===6)?.index?.value!==1&&s.push(`${I}: Info.index \u5FC5\u987B\u4E3A 1`);let E=k.find(S=>S.field501===4&&S.field502===4);E||s.push(`${I}: \u7F3A\u5C11\u663E\u5F0F Info.related \u8BB0\u5F55`);let $=0,F=0,U=(S,P,z,G=!1)=>{let ie=S.id?.id||0,j=`${S.name||"<unnamed>"}(${ie})`,ue=S.ui.content.data||[],Te=ue.map(X=>`${X.field501}/${X.field502}`),ae=z.map(([X])=>X);JSON.stringify(Te)!==JSON.stringify(ae)&&s.push(`${j}: Data \u69FD\u4F4D\u987A\u5E8F ${Te.join(",")}\uFF0C\u5E94\u4E3A ${ae.join(",")}`);for(let X=0;X<Math.min(ue.length,z.length);X+=1){let Ie=ue[X],[Xe,ei,Rt]=z[X];if(c(Ie,ei)||s.push(`${j}: Data ${Xe} \u7F3A\u5C11 ${ei} \u5206\u652F`),!Rt)continue;c(Ie.details,Rt)||s.push(`${j}: Details ${Xe} \u7F3A\u5C11 ${Rt} \u5206\u652F`);let Re=Cr[Xe];(Ie.details?.field501!==Re||Ie.details?.field502!==Ie.field502||Ie.details?.field503!==1)&&s.push(`${j}: Details ${Xe} \u6807\u8BB0\u5E94\u4E3A ${Re}/${Ie.field502}/1`);let Mt=Ie.details?.nodeRef;(Mt?.class!==1||Mt?.type!==8||Mt?.id!==ie)&&s.push(`${j}: Details ${Xe} node_ref \u672A\u6307\u5411\u81EA\u8EAB`)}let lt=ue.find(X=>X.field501===4&&X.field502===(G?23:86)),He=G?"empty15":"field17";c(lt?.field14,He)?G||($+=1):s.push(`${j}: \u7C7B\u578B Data \u7F3A\u5C11\u663E\u5F0F Field14.${He} \u7A7A\u4E32`),c(lt?.details?.field14,He)?G||($+=1):s.push(`${j}: \u7C7B\u578B Details \u7F3A\u5C11\u663E\u5F0F Field14.${He} \u7A7A\u4E32`);let _t=ue.find(X=>X.details?.transform)?.details?.transform,ut=_t?.multiPlatform?.platforms||[];ut.length!==4&&s.push(`${j}: \u591A\u5E73\u53F0\u53D8\u6362\u6570\u91CF=${ut.length}\uFF0C\u5E94\u4E3A 4`);let Pt=ut.map(X=>X.platformType||0);JSON.stringify(Pt)!==JSON.stringify([0,1,2,3])&&s.push(`${j}: \u5E73\u53F0\u987A\u5E8F ${Pt.join(",")}\uFF0C\u5E94\u4E3A 0,1,2,3`);let Tt=G?zt["server-container"]:zt[P];_t?.multiPlatform?.field502!==Tt&&s.push(`${j}: \u53D8\u6362 preset=${_t?.multiPlatform?.field502??"<missing>"}\uFF0C\u5E94\u4E3A ${Tt}`);for(let X of ut)c(X.transform,"field508")?F+=1:s.push(`${j}: RectTransform \u7F3A\u5C11\u663E\u5F0F field508 \u7A7A\u4E32`);return Te};U(f,"server-container",es,!0);let W=(f.relatedIds||[]).map(S=>S.id||0),Z=new Set(W),q=a.filter(S=>Z.has(S.id?.id||0)),O=q.map(S=>S.id?.id||0);JSON.stringify(W)!==JSON.stringify(O)&&s.push(`${I}: \u4E3B\u56FE relatedIds \u5FC5\u987B\u6309\u987A\u5E8F\u8986\u76D6\u672C\u7EC4 accessories`);let b=g.data?.find(S=>S.details?.rootChildRef)?.details?.rootChildRef?.guid||0,x=p.get(b);(!x||!q.includes(x))&&s.push(`${I}: 62/82 \u6839\u8282\u70B9\u5F15\u7528\u4E0D\u5B58\u5728`),O[0]!==b&&s.push(`${I}: \u6839\u5BB9\u5668\u8282\u70B9\u5FC5\u987B\u662F\u672C\u7EC4 accessories[0]`);let v=[];for(let S of q){let P=S.id?.id||0,z=S.ui.content,G=`${S.name||"<unnamed>"}(${P})`,ie=ui(S);S.which!==15&&s.push(`${G}: which \u5FC5\u987B\u4E3A UIControl(15)`);let j=z.info||[];(j.length!==1||j[0]?.field501!==1||j[0]?.field502!==5||j[0]?.guid?.value!==P)&&s.push(`${G}: \u670D\u52A1\u7AEF\u5BB9\u5668\u5185\u63A7\u4EF6 Info \u5FC5\u987B\u53EA\u542B\u81EA\u8EAB GUID`);let ue=Ir[ie];ue||s.push(`${G}: \u672A\u77E5\u5BA2\u6237\u7AEF\u63A7\u4EF6\u7C7B\u578B ${ie}`);let Te=ue?U(S,ie,ue):[];v.push({id:P,name:S.name||"",kind:ie,parent:z.parent||0,children:[...z.children||[]],relatedIds:(S.relatedIds||[]).map(ae=>ae.id||0),dataSignatures:Te})}let C=v.find(S=>S.id===b);C&&(C.kind!=="container"&&s.push(`${C.name}(${b}): \u6839\u63A7\u4EF6\u5FC5\u987B\u4E3A\u5BB9\u5668\u8282\u70B9`),C.parent&&s.push(`${C.name}(${b}): \u6839\u63A7\u4EF6\u4E0D\u5E94\u6709 parent`));let M=new Map(v.map(S=>[S.id,S]));for(let S of v){let P=`${S.name}(${S.id})`;if(JSON.stringify(S.relatedIds)!==JSON.stringify(S.children)&&s.push(`${P}: relatedIds \u5FC5\u987B\u4E0E\u76F4\u63A5 children \u4E00\u81F4`),S.id!==b){let z=M.get(S.parent);z?z.children.includes(S.id)||s.push(`${P}: \u7236\u63A7\u4EF6 children \u672A\u53CD\u5411\u5305\u542B\u81EA\u8EAB`):s.push(`${P}: parent=${S.parent||"<missing>"} \u4E0D\u5B58\u5728`)}for(let z of S.children){let G=M.get(z);G?G.parent!==S.id&&s.push(`${P}: child=${z} \u7684 parent \u672A\u6307\u56DE\u81EA\u8EAB`):s.push(`${P}: 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:E?.related?.value||[],rootGuid:b},accessoryCount:a.length,controls:v,scriptCount:o.length,explicitEmpty:{field17:$,rectField508:F}}}function Yr(e,t=[]){if(!e||e.layoutSchemaVersion===ce)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:ce};let i=structuredClone(e),n=0;return J(i.root,r=>{let o=r.transformByPlatform||{},a=r.transformByCanvas||{},s=r.name||r.id;for(let l of Object.keys(o))if(!te.includes(l))throw new Error(`${s}: unknown platform ${l}`);let c={};for(let l of te){let f=dt[l],h=K[f].platform,p=Object.keys(K).filter(k=>K[k].platform===h&&a[k]),m=a[f]?f:p[0],g=l==="CONTROLLER_CONSOLE"?c.KEYBOARD:l==="CONTROLLER_MOBILE"?c.TOUCHSCREEN:null,I=o[l]??g??(m?a[m]:null);if(c[l]=I?Ce(I):Ui(r.kind),I||t.push(`${s}: ${l} \u65E0\u65E7\u5E03\u5C40\uFF0C\u5DF2\u4F7F\u7528\u63A7\u4EF6\u9ED8\u8BA4\u503C`),!o[l]&&!g&&m&&m!==f&&t.push(`${s}: \u7F3A\u5C11 ${f}\uFF0C\u5DF2\u91C7\u7528 ${m} \u7684\u951A\u70B9\u548C\u5C3A\u5BF8\u53C2\u6570`),!g)for(let k of p)JSON.stringify(c[l])!==JSON.stringify(Ce(a[k]))&&t.push(`${s}: ${k} \u4E0E ${l} \u5E03\u5C40\u51B2\u7A81\uFF0C\u4FDD\u7559${o[l]?"\u5DF2\u6709\u5E73\u53F0":m}\u53C2\u6570`)}Oe(c,`${s}.transformByPlatform`),r.transformByPlatform=c,delete r.transformByCanvas,n++}),i.layoutSchemaVersion=ce,t.unshift(`\u5DF2\u81EA\u52A8\u8FC1\u79FB\u65E7\u5E03\u5C40\uFF1A${n} \u4E2A\u63A7\u4EF6\u8F6C\u6362\u4E3A\u56DB\u5E73\u53F0\u53C2\u6570\uFF1B\u518D\u6B21\u4FDD\u5B58\u5C06\u4F7F\u7528\u65B0\u7248\u683C\u5F0F`),i}function tn(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 rn(e,t,i,n=e.canvasId){let r=$e(e.root,t);return!r||r.kind==="server-container"?de(n):i[r.id]||de(n)}function xe(e,{warnings:t=[]}={}){if(!e)return De();if(e=Yr(e,t),(e.root||e.layoutSchemaVersion!==void 0)&&e.layoutSchemaVersion!==ce)throw new Error(`\u4EC5\u652F\u6301 layoutSchemaVersion=${ce} \u7684\u56DB\u5E73\u53F0\u5E03\u5C40\uFF0C\u4E0D\u652F\u6301\u65E7\u753B\u5E03\u5E03\u5C40\u6216\u5176\u4ED6\u7248\u672C`);let i=e.meta?.assetType==="client-control-template"?"client-control-template":"server-control-template",n=i==="client-control-template"?Je():De(),r={layoutSchemaVersion:ce,version:Number.isSafeInteger(e.version)&&e.version>0?e.version:1,meta:{name:String(e.meta?.name||n.meta.name),assetType:i,sourceFormat:String(e.meta?.sourceFormat||n.meta.sourceFormat),sourceFile:String(e.meta?.sourceFile||""),...e.meta?.gameVersion?{gameVersion:String(e.meta.gameVersion)}:{},...e.meta?.giaFilePath?{giaFilePath:String(e.meta.giaFilePath)}:{},...Number.isSafeInteger(Number(e.meta?.giaOwnerUid))?{giaOwnerUid:Number(e.meta.giaOwnerUid)}:{},...Number.isSafeInteger(Number(e.meta?.giaTimestamp))?{giaTimestamp:Number(e.meta.giaTimestamp)}:{},...Number.isSafeInteger(Number(e.meta?.giaFileId))?{giaFileId:Number(e.meta.giaFileId)}:{},...e.meta?.giaFileName?{giaFileName:String(e.meta.giaFileName)}:{},...Number.isSafeInteger(Number(e.meta?.giaModeFlag))&&Number(e.meta.giaModeFlag)>=0?{giaModeFlag:Number(e.meta.giaModeFlag)}:{}},canvasId:e.canvasId&&K[e.canvasId]?e.canvasId:ti,selectedId:e.selectedId||n.selectedId,root:Ki(e.root||n.root)};return Kr(r),r}function Kr(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=Xi(e.root).id)}function Br(e){return Fe(yt(e))}function ds(e,t){let i=!1;return J(e,n=>{n.id===t&&(i=!0)}),i}function hs(e,t,i,n){let o=Ge(e.root,e.canvasId).boxes[t.id],a=i.children.findIndex(h=>h.id===t.id);if(a<0)throw new Error("reparent: source node is not attached");if(i.children.splice(a,1),n.children.push(t),!o)return;let s=Ge(e.root,e.canvasId),c=n.kind==="server-container"?de(e.canvasId):s.boxes[n.id]||de(e.canvasId),l=ze(t.transformByPlatform,e.canvasId),f=Le(c,l,{posX:o.centerX,posY:o.centerY,width:o.width,height:o.height});vt(e,t,f)}function ps(e,t){return e.meta.assetType!=="client-control-template"?Li(e.root,t):(e.root.children||[]).flatMap(i=>Li(i,t))}function Lr(e,t){let i=pr(e.root,t);if(e.meta.assetType!=="client-control-template")return i;let n=Dt(e),r=new Set;return n&&n.kind!=="server-container"&&J(n,o=>r.add(o.id)),i.filter(o=>r.has(o.id))}function Wr(e){let{canvas:t,boxes:i}=Ge(e.root,e.canvasId),n=Vt(e),r=le(e.root,e.selectedId),o=r?i[r.id]:null;return D({layoutSchemaVersion:ce,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"&&Dt(e)?.id||""},tree:ps(e,n),boxes:Lr(e,i),inspector:mr(r,e.canvasId,o||t,n),root:e.root})}function vt(e,t,i){let n=Ge(e.root,e.canvasId),r=rn(e,t.id,n.boxes),o={};if(t.syncAllDevices!==!1)for(let a of te){if(a===We(e.canvasId))continue;let s=dt[a],c=Ge(e.root,s,a);o[a]=rn(e,t.id,c.boxes,s)}t.transformByPlatform=hr({transformByPlatform:t.transformByPlatform,source:i,canvasId:e.canvasId,syncAllDevices:t.syncAllDevices!==!1,sourceParentBox:r,targetParentBoxByPlatform:o})}var ms=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"]),gs=new Set(["posX","posY","width","height"]),ys=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 n=t.slice(1);if(n.length===6)return(4278190080|parseInt(n,16))>>>0;if(n.length===8)return parseInt(n,16)>>>0}let i=Number(t);if(Number.isFinite(i))return i>>>0}throw new Error("color must be an ARGB integer or #RRGGBB/#AARRGGBB string")}function _e(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function Ur(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 vs=new Set(["fontSize","minimumFontSize","imageId","clickAudioId","softEdgeWidthX","softEdgeWidthY","horizontalSoftRange","verticalSoftRange","fillAmount","cellSizeX","cellSizeY","spacingX","spacingY","padding1X","padding1Y","padding2X","padding2Y","previewCount","keyboardKeyCode","controllerKeyCode"]),Ss=new Set(["active","visible","canControllerFocus","isolateNavigation","disableKeyEventPassthrough","disableCursorEventPassthrough","showCursor","adaptiveFontSize","enableOutline","enableMask","enableSoftEdge","enableFill","reverseMaskArea","raycastTarget","interactable","showScrollBar"]),ws=new Set(["name","horizontalAlignment","verticalAlignment","text","softEdgeMode","fillType","fillHorizontalType","fillVerticalType","fillRadial90Type","fillRadialType","scrollDirection","layoutConstraint","referencedPrefabId","animationId"]),Hr=new Set(["unavailableChildId","hoverChildId","pressedChildId","selectedChildId"]),Xr={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 Is(e,t){if(!t||typeof t!="object")throw new Error("patch requires op");let i=t.op;if(i==="select")return t.id&&le(e.root,t.id)&&(e.selectedId=t.id),e;if(i==="pick"){let{boxes:n}=Ge(e.root,e.canvasId),r=Lr(e,n),o=gr(r,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 n=t.assetType==="client-control-template"?Je():De();return e.version=n.version,e.meta=n.meta,e.canvasId=n.canvasId,e.selectedId=n.selectedId,e.root=n.root,e}if(i==="addTemplate"){if(e.meta.assetType!=="client-control-template")throw new Error("\u53EA\u6709\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5DE5\u7A0B\u53EF\u4EE5\u65B0\u589E\u6A21\u677F");let n=B(t.kind,{id:Hi(e.root),guid:Br(e.root),name:t.name||`\u65B0${t.kind==="container"?"\u5BB9\u5668\u8282\u70B9":t.kind}\u6A21\u677F`});return e.root.children.push(n),e.selectedId=n.id,e}if(i==="add"){let n=le(e.root,t.parentId||e.selectedId);if(!n)throw new Error("add: parent not found");let r=cr(n,t.kind,{id:Hi(e.root),guid:Br(e.root),name:t.name});return e.selectedId=r.id,e}if(i==="reparent"){if(e.meta.assetType!=="client-control-template")throw new Error("\u5C42\u7EA7\u8C03\u6574\u4EC5\u9002\u7528\u4E8E\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5DE5\u7A0B");let n=le(e.root,t.id||e.selectedId),r=n?$e(e.root,n.id):null,o=le(e.root,t.parentId);if(!n||n.kind==="server-container"||!r)throw new Error("reparent: node not found");if(!o)throw new Error("reparent: parent not found");if(o.id===n.id||ds(n,o.id))throw new Error("\u63A7\u4EF6\u4E0D\u80FD\u79FB\u52A8\u5230\u81EA\u8EAB\u6216\u5176\u540E\u4EE3\u4E0B\u9762");if(o.kind==="server-container"&&r.kind==="server-container")return e;if(r.kind==="server-container"&&o.kind!=="server-container"&&e.root.children.length<=1)throw new Error("\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868\u81F3\u5C11\u4FDD\u7559\u4E00\u4E2A\u9876\u5C42\u6A21\u677F");return hs(e,n,r,o),e.selectedId=n.id,e}if(i==="moveSibling"){let n=le(e.root,t.id||e.selectedId),r=n?$e(e.root,n.id):null;if(!n||!r)throw new Error("moveSibling: node not found");let o=r.children.findIndex(c=>c.id===n.id),a=t.direction==="up"?-1:t.direction==="down"?1:0,s=o+a;return!a||s<0||s>=r.children.length||(r.children.splice(o,1),r.children.splice(s,0,n),e.selectedId=n.id),e}if(i==="remove"){let n=t.id||e.selectedId,r=$e(e.root,n);if(r?.kind==="server-container"){if(e.meta.assetType!=="client-control-template")throw new Error("\u670D\u52A1\u7AEF\u63A7\u4EF6\u6A21\u677F\u7684\u5BA2\u6237\u7AEF\u6839\u8282\u70B9\u4E0D\u80FD\u5220\u9664");if((e.root.children||[]).length<=1)throw new Error("\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u5217\u8868\u81F3\u5C11\u4FDD\u7559\u4E00\u4E2A\u6A21\u677F")}return fr(e.root,n)&&(J(e.root,o=>{if(o.kind==="button")for(let a of Hr)o[a]&&!le(e.root,o[a])&&(o[a]=null)}),e.selectedId=r?r.id:e.root.id),e}if(i==="set"){let n=le(e.root,t.id||e.selectedId);if(!n)throw new Error("set: node not found");let r=t.key;r==="reverseMask"&&(r="reverseMaskArea");let o=t.value;if(r.startsWith("giaRaw.")){let l=r.slice(7);if(!l||l.includes("."))throw new Error("invalid raw GIA field path");let f=sr(n.kind,l);if(!f)throw new Error(`unknown raw GIA field for ${n.kind}: ${l}`);if(n.giaRaw||={},n.giaRaw[l]=Gi(f,o),(n.kind==="textbox"||n.kind==="textwindow")&&l==="textAlign"){let h={0:"Left",1:"Middle",2:"Right"}[n.giaRaw[l]];h&&(n.horizontalAlignment=h)}if(n.kind==="image"&&l==="imageFillType"){let h={1:"Horizontal",2:"Vertical",3:"Radial90",4:"Radial180",5:"Radial360"}[n.giaRaw[l]];h&&(n.fillType=h)}return n.kind==="keyhint"&&l==="keyHintField502"&&(n.keyboardKeyCode=n.giaRaw[l]),n.kind==="keyhint"&&l==="keyHintField501"&&(n.controllerKeyCode=n.giaRaw[l]),e}if(r==="syncAllDevices"){if(n.syncAllDevices=Ur(o),n.syncAllDevices){let l=ze(n.transformByPlatform,e.canvasId);vt(e,n,l)}return e}if(ms.has(r)){if(r.endsWith("Color")&&(o=bs(o)),vs.has(r)){if(o=_e(o,r),o<0)throw new Error(`${r} must not be negative`);if((r==="imageId"||r==="clickAudioId"||r==="keyboardKeyCode"||r==="controllerKeyCode")&&(o=Math.trunc(o)),r==="fillAmount"&&o>1)throw new Error("fillAmount must be between 0 and 1")}if(Ss.has(r)&&(o=Ur(o)),ws.has(r)&&(o=String(o??"")),r==="horizontalAlignment"&&!["Left","Middle","Right"].includes(o))throw new Error("invalid horizontalAlignment");if(r==="verticalAlignment"&&!["Top","Middle","Bottom"].includes(o))throw new Error("invalid verticalAlignment");if(Xr[r]&&!Xr[r].includes(o))throw new Error(`invalid ${r}`);if(Hr.has(r))if(o===""||o===void 0||o===null)o=null;else{o=String(o);let l=le(e.root,o);if(!l||l===n||l.kind==="server-container"||!(n.children||[]).some(f=>f.id===o))throw new Error(`${r} must reference a direct child of this button`)}if(n[r]=o,(n.kind==="textbox"||n.kind==="textwindow")&&r==="horizontalAlignment"&&(n.giaRaw.textAlign={Left:0,Middle:1,Right:2}[o]),n.kind==="image"&&r==="fillType"){let l={Horizontal:1,Vertical:2,Radial90:3,Radial180:4,Radial360:5}[o];l&&(n.giaRaw.imageFillType=l)}return n.kind==="reference"&&r==="referencedPrefabId"&&(n.giaRaw.templateRefSlot=o),n.kind==="grid"&&r==="previewCount"&&(n.giaRaw.gridField511=Math.trunc(o)),n.kind==="keyhint"&&r==="keyboardKeyCode"&&(n.giaRaw.keyHintField502=Math.trunc(o)),n.kind==="keyhint"&&r==="controllerKeyCode"&&(n.giaRaw.keyHintField501=Math.trunc(o)),(n.kind==="animation"||n.kind==="fullscreen")&&r==="animationId"&&(n.giaRaw[n.kind==="animation"?"effectSlot":"fullscreenEffectSlot"]=o),e}let{boxes:a}=Ge(e.root,e.canvasId),s=rn(e,n.id,a),c=ze(n.transformByPlatform,e.canvasId);if(r==="anchorType"){let l=nn(a[n.id]),f=ir(c,o);return f=Le(s,f,l),vt(e,n,f),e}if(r==="rotationZ"){let l={...c,rotation:{...c.rotation,z:_e(o,r)}};return vt(e,n,l),e}if(ys.has(r)){let l=nn(a[n.id]),f={...c,anchorMin:{...c.anchorMin},anchorMax:{...c.anchorMax},pivot:{...c.pivot}};return r==="anchorMinX"&&(f.anchorMin.x=_e(o,r)),r==="anchorMinY"&&(f.anchorMin.y=_e(o,r)),r==="anchorMaxX"&&(f.anchorMax.x=_e(o,r)),r==="anchorMaxY"&&(f.anchorMax.y=_e(o,r)),r==="pivotX"&&(f.pivot.x=_e(o,r)),r==="pivotY"&&(f.pivot.y=_e(o,r)),vt(e,n,Le(s,f,l)),e}if(gs.has(r)){let l=nn(a[n.id]),f=_e(o,r);if((r==="width"||r==="height")&&f<0)throw new Error(`${r} must not be negative`);return l[r]=f,vt(e,n,Le(s,c,l)),e}throw new Error(`set: unknown key ${r}`)}if(i==="replace"){let n=xe(t.project);return e.version=n.version,e.meta=n.meta,e.canvasId=n.canvasId,e.selectedId=n.selectedId,e.root=n.root,e}throw new Error(`unknown op ${i}`)}function on(e,t){if(!t||typeof t!="object")throw new Error("patch requires op");if(t.expectedRevision!==void 0&&Number(t.expectedRevision)!==e.version)throw new Error(`revision conflict: expected ${t.expectedRevision}, current ${e.version}`);let i=e.version,n=JSON.parse(JSON.stringify(e));return Is(n,t),Kr(n),n.version=i+1,Object.keys(e).forEach(r=>{delete e[r]}),Object.assign(e,n),e}function nn(e){return e?{posX:e.centerX,posY:e.centerY,width:e.width,height:e.height}:{posX:0,posY:0,width:0,height:0}}import Cs from"fengari";var{lua:u,lauxlib:re,lualib:qr,to_luastring:fi,to_jsstring:ks}=Cs,xs=u.LUA_TNIL,Es=u.LUA_TBOOLEAN,As=u.LUA_TNUMBER,_s=u.LUA_TSTRING,jr=u.LUA_TTABLE,Ps=u.LUA_TFUNCTION,an=u.LUA_TUSERDATA,Ee=u.LUA_OK,Jr=new WeakMap,sn=Symbol("luaTableEntries"),ln={__scriptHostKey:!0};function _(e){return fi(String(e))}function Ze(e,t){Jr.set(e,t)}function be(e){return Jr.get(e)}function ne(e,t,i){if(i==null){u.lua_pushnil(e);return}let n=typeof i;if(n==="boolean"){u.lua_pushboolean(e,i);return}if(n==="number"){Number.isInteger(i)&&Math.abs(i)<=2147483647?u.lua_pushinteger(e,i):u.lua_pushnumber(e,i);return}if(n==="string"){u.lua_pushstring(e,_(i));return}if(n==="function"){Ms(e,t,i);return}if(i&&i[sn]){let r=i[sn];u.lua_createtable(e,Array.isArray(i)?i.length:0,r.length);for(let[o,a]of r)ne(e,t,o),ne(e,t,a),u.lua_settable(e,-3);return}if(Array.isArray(i)){u.lua_createtable(e,i.length,0);for(let r=0;r<i.length;r++)ne(e,t,i[r]),u.lua_rawseti(e,-2,r+1);return}if(i&&i.__kind==="EnumItem"){t.pushEnumItem(e,i);return}if(i&&i.__kind==="CursorEventData"){t.pushCursor(e,i);return}if(i&&i.__kind==="Script"){t.pushScript(e,i);return}if(i&&i.typeofName){t.pushControl(e,i);return}if(i&&i.SetEase){t.pushTween(e,i);return}if(n==="object"){u.lua_createtable(e,0,Object.keys(i).length);for(let[r,o]of Object.entries(i))ne(e,t,o),u.lua_setfield(e,-2,_(r));return}u.lua_pushnil(e)}function L(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?"":ks(i)}function Ye(e,t){t=u.lua_absindex(e,t);let i=u.lua_type(e,t);if(i===an)return be(u.lua_touserdata(e,t));if(i===jr){u.lua_pushlightuserdata(e,ln),u.lua_rawget(e,t);let n=u.lua_type(e,-1)===an?u.lua_touserdata(e,-1):null;return u.lua_pop(e,1),n?be(n):null}return null}function pe(e,t,i){i=u.lua_absindex(e,i);let n=u.lua_type(e,i);if(n===xs)return null;if(n===Es)return!!u.lua_toboolean(e,i);if(n===As)return u.lua_isinteger(e,i)?u.lua_tointeger(e,i):u.lua_tonumber(e,i);if(n===_s)return L(e,i);if(n===an){let r=u.lua_touserdata(e,i);return be(r)??r}if(n===Ps)return Ts(e,t,i);if(n===jr){let r=Ye(e,i);if(r)return r;let o=[];for(u.lua_pushnil(e);u.lua_next(e,i)!==0;){let l=pe(e,t,-2),f=pe(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,sn,{value:o}),c}return null}function Ts(e,t,i){t.luaFunctions||(t.luaFunctions=new Map);let n=typeof u.lua_topointer=="function"?u.lua_topointer(e,i):null;if(n!=null&&t.luaFunctions.has(n))return t.luaFunctions.get(n);u.lua_pushvalue(e,i);let r=re.luaL_ref(e,u.LUA_REGISTRYINDEX),o=Rs(e,t,r);return n!=null&&t.luaFunctions.set(n,o),o}function Rs(e,t,i){let n=(...r)=>{let o=u.lua_gettop(e);u.lua_rawgeti(e,u.LUA_REGISTRYINDEX,i);for(let l of r)ne(e,t,l);if(u.lua_pcall(e,r.length,u.LUA_MULTRET,0)!==Ee){let l=L(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(pe(e,t,o+l));if(u.lua_settop(e,o),c.length!==0)return c.length===1?c[0]:c};return n.__luaRef=i,n.__luaState=e,n}function Zr(e,t){if(!t||t.__luaRef==null||!t.__luaState)return;let i=t.__luaState;if((!e?.luaStates||e.luaStates.has(i))&&re.luaL_unref(i,u.LUA_REGISTRYINDEX,t.__luaRef),t.__luaRef=null,t.__luaState=null,e?.luaFunctions)for(let[n,r]of e.luaFunctions)r===t&&e.luaFunctions.delete(n)}function Ms(e,t,i){u.lua_pushlightuserdata(e,i),u.lua_pushlightuserdata(e,t),u.lua_pushcclosure(e,function(r){let o=u.lua_touserdata(r,u.lua_upvalueindex(1)),a=u.lua_touserdata(r,u.lua_upvalueindex(2)),s=u.lua_gettop(r),c=[];for(let l=1;l<=s;l++)c.push(pe(r,a,l));try{let l=o(...c);if(Array.isArray(l)&&l.__multi){for(let f of l)ne(r,a,f);return l.length}return l===void 0?0:(ne(r,a,l),1)}catch(l){return u.lua_pushstring(r,_(String(l&&l.message?l.message:l))),u.lua_error(r)}},2)}function Qr(e){!e||typeof u.lua_close!="function"||u.lua_close(e)}function eo(e){if(re.luaL_loadstring(e,_(["local nativeGetMetatable = getmetatable","getmetatable = function(value)",' if type(value) == "string" then return nil end'," return nativeGetMetatable(value)","end"].join(`
|
|
105
105
|
`)))===Ee&&u.lua_pcall(e,0,0,0),u.lua_settop(e,0),u.lua_pushnil(e),u.lua_setglobal(e,_("_VERSION")),u.lua_getglobal(e,_("string")),!u.lua_isnil(e,-1))for(let i of["dump","pack","unpack"])u.lua_pushnil(e),u.lua_setfield(e,-2,_(i));if(u.lua_pop(e,1),u.lua_pushnil(e),u.lua_setglobal(e,_("io")),u.lua_getglobal(e,_("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,_(i));u.lua_pop(e,1),u.lua_getglobal(e,_("debug")),u.lua_isnil(e,-1)?u.lua_pop(e,1):(u.lua_getfield(e,-1,_("traceback")),u.lua_newtable(e),u.lua_pushvalue(e,-2),u.lua_setfield(e,-2,_("traceback")),u.lua_setglobal(e,_("debug")),u.lua_pop(e,2)),u.lua_getglobal(e,_("math")),u.lua_isnil(e,-1)||(u.lua_pushcfunction(e,i=>{let n=u.lua_tonumber(i,1);return u.lua_pushboolean(i,Number.isNaN(n)),1}),u.lua_setfield(e,-2,_("isnan")),u.lua_pushcfunction(e,i=>{let n=u.lua_tonumber(i,1);return u.lua_pushboolean(i,n===1/0||n===-1/0),1}),u.lua_setfield(e,-2,_("isinf"))),u.lua_pop(e,1),u.lua_pushnil(e),u.lua_setglobal(e,_("package")),u.lua_pushnil(e),u.lua_setglobal(e,_("load")),u.lua_pushnil(e),u.lua_setglobal(e,_("loadfile")),u.lua_pushnil(e),u.lua_setglobal(e,_("dofile")),u.lua_pushnil(e),u.lua_setglobal(e,_("collectgarbage")),u.lua_pushnil(e),u.lua_setglobal(e,_("coroutine")),u.lua_pushnil(e),u.lua_setglobal(e,_("fengari"))}var to={container:"ClientUIContainerControl",textbox:"ClientUITextBoxControl",textwindow:"ClientUITextWindowControl",image:"ClientUIImageControl",button:"ClientUIPresetButtonControl",cursor:"ClientUICursorEventAreaControl",grid:"ClientUIGridScrollerControl",keyhint:"ClientUIKeyHintControl",animation:"ClientUIAnimationControl",fullscreen:"ClientUIFullscreenAnimationControl",reference:"ClientUIReferenceControl"},Ns=["alive","Id","prefabIndex","active","activeInHierarchy","visible"],di=new Set(["active","visible","parent","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY"]),Os=["name","parent","anchoredPositionX","anchoredPositionY","sizeDeltaX","sizeDeltaY","anchorMinX","anchorMinY","anchorMaxX","anchorMaxY","pivotX","pivotY","localScaleX","localScaleY","localScaleZ","localRotationX","localRotationY","localRotationZ","canControllerFocus"],Fs={image:["imageSource","imageId"],grid:["itemCount","scrollDirection","layoutConstraint","layoutConstraintFixedCount"],reference:["referencedPrefabIndex"]},$s={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"]},Ds=["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"],io=["AddCursorEventListener","RemoveCursorEventListener","RemoveCursorEventListeners","RemoveAllCursorEventListeners","SimulateCursorClick"],zs={image:["SetImage","SetSoftEdgeWidth","SetFillUnused","SetFillHorizontal","SetFillVertical","SetFillRadial90","SetFillRadial180","SetFillRadial360"],button:io,cursor:io,animation:["PlayAnimation","StopAnimation"],grid:["RefreshItems","GetItemIndex","GetItemSize","GetItemSpacing","GetPadding","ScrollToItemAt","GetContentLength"]};function un(e,t){return Ns.includes(t)||(Fs[e.kind]||[]).includes(t)?"ro":Os.includes(t)||($s[e.kind]||[]).includes(t)?"rw":null}function no(e,t){return Ds.includes(t)||(zs[e.kind]||[]).includes(t)}var Gs={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}},Be=class e{constructor(t,i){this.runtime=t,this.kind=i.kind||"container",this.typeofName=to[this.kind]||to.container,this.alive=!0,this.Id=i.Id??t.nextControlId(),this.authoringId=i.authoringId??null,this.prefabIndex=i.prefabIndex??0,this.name=i.name??"",this.active=i.active===!0,this.visible=i.visible!==!1,this._parent=null,this.children=[],this.scripts=[],this.cursorListeners=new Map,this.keyListeners=new Map,this.navListeners=new Map,this.navConfig=new Map,this.anchoredPositionX=i.anchoredPositionX??0,this.anchoredPositionY=i.anchoredPositionY??0,this.sizeDeltaX=i.sizeDeltaX??0,this.sizeDeltaY=i.sizeDeltaY??0,this.anchorMinX=i.anchorMinX??.5,this.anchorMinY=i.anchorMinY??.5,this.anchorMaxX=i.anchorMaxX??.5,this.anchorMaxY=i.anchorMaxY??.5,this.pivotX=i.pivotX??.5,this.pivotY=i.pivotY??.5,this.localScaleX=i.localScaleX??1,this.localScaleY=i.localScaleY??1,this.localScaleZ=i.localScaleZ??1,this.localRotationX=i.localRotationX??0,this.localRotationY=i.localRotationY??0,this.localRotationZ=i.localRotationZ??0,this.canControllerFocus=i.canControllerFocus??!1,this._playDirty=!0,this._playDeepDirty=!0,this._playChildDirty=!1;let n=Gs[this.kind]||{};for(let[r,o]of Object.entries(n))this[r]===void 0&&(this[r]=i[r]!==void 0?i[r]:o);if(i.children)for(let r of i.children){let o=r instanceof e?r:new e(t,r);this.addChild(o)}}get parent(){return this._parent}set parent(t){if(this._parent===t)return;if(t!==null&&!(t instanceof e))throw new Error("parent must be a Control or nil");if(t&&t.runtime!==this.runtime)throw new Error("parent must belong to the same runtime");if(t===this)throw new Error("cannot parent a control to itself or its descendant");for(let n=t;n;n=n._parent)if(n===this)throw new Error("cannot parent a control to itself or its descendant");let i=this._parent;if(i){let n=i.children.indexOf(this);n>=0&&i.children.splice(n,1),i.markPlayDirty(!0)}else{let n=this.runtime.roots.indexOf(this);n>=0&&this.runtime.roots.splice(n,1)}this._parent=t,this.markPlayDirty(!0),t&&!t.children.includes(this)?(t.children.push(this),t.markPlayDirty(!0)):!t&&this.alive&&!this.runtime.roots.includes(this)&&this.runtime.roots.push(this)}markPlayDirty(t=!1){this._playDirty=!0,t&&(this._playDeepDirty=!0);for(let i=this._parent;i&&!i._playChildDirty;i=i._parent)i._playChildDirty=!0}get activeInHierarchy(){return this.active?this._parent?this._parent.activeInHierarchy:!0:!1}addChild(t){return t.parent=this,t}GetChildren(){return this.children.slice()}GetChild(t){return this.children.find(i=>i.name===t)||null}FindChild(t){if(!t)return null;if(!t.includes("/"))return this.GetChild(t);let i=t.split("/").filter(Boolean),n=this;for(let r of i)if(n=n.GetChild(r),!n)return null;return n}SetActive(t){let i=!!t;if(this.active!==i){if(typeof this.runtime?.onControlActiveChanging=="function"){this.runtime.onControlActiveChanging(this,i);return}this.active=i,this.markPlayDirty(!0)}}SetVisible(t){this.visible=!!t,this.markPlayDirty(!0)}GetSiblingIndex(){if(!this._parent)return-1;let t=this._parent.children,i=t.indexOf(this);return i<0?-1:t.length-1-i}SetSiblingIndex(t){if(!this._parent)return!1;let i=this._parent.children,n=i.indexOf(this);if(n<0)return!1;let r=i.length-1;return!Number.isInteger(t)||t<0||t>r?!1:(i.splice(n,1),i.splice(r-t,0,this),this._parent.markPlayDirty(!0),this.markPlayDirty(),!0)}SetAsFirstSibling(){return this.SetSiblingIndex(0)}SetAsLastSibling(){return this._parent?this.SetSiblingIndex(this._parent.children.length-1):!1}GetAnchoredPosition(){return[this.anchoredPositionX,this.anchoredPositionY]}SetAnchoredPosition(t,i){this.anchoredPositionX=t,this.anchoredPositionY=i,this.markPlayDirty()}GetSizeDelta(){return[this.sizeDeltaX,this.sizeDeltaY]}SetSizeDelta(t,i){this.sizeDeltaX=t,this.sizeDeltaY=i,this.markPlayDirty(!0)}GetAnchorMin(){return[this.anchorMinX,this.anchorMinY]}SetAnchorMin(t,i){this.anchorMinX=t,this.anchorMinY=i,this.markPlayDirty(!0)}GetAnchorMax(){return[this.anchorMaxX,this.anchorMaxY]}SetAnchorMax(t,i){this.anchorMaxX=t,this.anchorMaxY=i,this.markPlayDirty(!0)}GetPivot(){return[this.pivotX,this.pivotY]}SetPivot(t,i){this.pivotX=t,this.pivotY=i,this.markPlayDirty(!0)}GetLocalScale(){return[this.localScaleX,this.localScaleY,this.localScaleZ]}SetLocalScale(t,i,n){this.localScaleX=t,this.localScaleY=i,this.localScaleZ=n,this.markPlayDirty()}GetLocalRotation(){return[this.localRotationX,this.localRotationY,this.localRotationZ]}SetLocalRotation(t,i,n){this.localRotationX=t,this.localRotationY=i,this.localRotationZ=n,this.markPlayDirty()}GetScriptByPath(t){return this.scripts.find(i=>i.path===t)||null}GetScript(t){return this.scripts.find(i=>i.scriptMappingId===t)||null}GetScripts(){return this.scripts.slice()}_addListener(t,i,n){let r=t.get(i)||[];r.push(n),t.set(i,r)}_removeListener(t,i,n){let r=t.get(i);r&&(t.set(i,r.filter(o=>o!==n)),this.runtime.unrefLuaCallback?.(n))}_removeListeners(t,i){let n=t.get(i)||[];for(let r of n)this.runtime.unrefLuaCallback?.(r);t.delete(i)}_removeAllListeners(t){for(let i of t.values())for(let n of i)this.runtime.unrefLuaCallback?.(n);t.clear()}AddCursorEventListener(t,i){this._addListener(this.cursorListeners,t,i)}RemoveCursorEventListener(t,i){this._removeListener(this.cursorListeners,t,i)}RemoveCursorEventListeners(t){this._removeListeners(this.cursorListeners,t)}RemoveAllCursorEventListeners(){this._removeAllListeners(this.cursorListeners)}SimulateCursorClick(){let t=this.runtime.makeCursorEventData({x:0,y:0,pressX:0,pressY:0});this.emitCursor("CursorDown",t),this.emitCursor("CursorUp",t),this.emitCursor("CursorClick",t)}emitCursor(t,i){if(!this.runtime.cursorEventsEnabled(this))return;let n=this.cursorListeners.get(t)||[];for(let r of n)r(i)}AddKeyEventListener(t,i){this._addListener(this.keyListeners,t,i)}RemoveKeyEventListener(t,i){this._removeListener(this.keyListeners,t,i)}RemoveKeyEventListeners(t){this._removeListeners(this.keyListeners,t)}RemoveAllKeyEventListeners(){this._removeAllListeners(this.keyListeners)}emitKey(t){let i=this.keyListeners.get(t)||[];for(let n of i)if(n()===!0)break}AddNavigationEventListener(t,i){this._addListener(this.navListeners,t,i)}RemoveNavigationEventListener(t,i){this._removeListener(this.navListeners,t,i)}RemoveNavigationEventListeners(t){this._removeListeners(this.navListeners,t)}RemoveAllNavigationEventListeners(){this._removeAllListeners(this.navListeners)}SetControllerNavigation(t,i,n){this.navConfig.set(t,{mode:i,target:n})}GetControllerNavigation(t){let i=this.navConfig.get(t),n=i?[i.mode,i.target]:[null,null];return n.__multi=!0,n}SetImage(t,i){this.imageSource=t,this.imageId=i,this.markPlayDirty()}SetSoftEdgeWidth(t,i){this.softEdgeWidthX=t,this.softEdgeWidthY=i,this.markPlayDirty()}SetFillUnused(){this.fillType="Unused",this.markPlayDirty()}SetFillHorizontal(t,i){this.fillType="Horizontal",this.fillHorizontalType=t,this.fillAmount=i,this.markPlayDirty()}SetFillVertical(t,i){this.fillType="Vertical",this.fillVerticalType=t,this.fillAmount=i,this.markPlayDirty()}SetFillRadial90(t,i){this.fillType="Radial90",this.fillRadial90Type=t,this.fillAmount=i,this.markPlayDirty()}SetFillRadial180(t,i){this.fillType="Radial180",this.fillRadialType=t,this.fillAmount=i,this.markPlayDirty()}SetFillRadial360(t,i){this.fillType="Radial360",this.fillRadialType=t,this.fillAmount=i,this.markPlayDirty()}PlayAnimation(){}StopAnimation(){}RefreshItems(){throw new Error("ClientUIGridScrollerControl:RefreshItems not implemented")}GetItemIndex(){throw new Error("ClientUIGridScrollerControl:GetItemIndex not implemented")}GetItemSize(){throw new Error("ClientUIGridScrollerControl:GetItemSize not implemented")}GetItemSpacing(){throw new Error("ClientUIGridScrollerControl:GetItemSpacing not implemented")}GetPadding(){throw new Error("ClientUIGridScrollerControl:GetPadding not implemented")}ScrollToItemAt(){throw new Error("ClientUIGridScrollerControl:ScrollToItemAt not implemented")}GetContentLength(){throw new Error("ClientUIGridScrollerControl:GetContentLength not implemented")}};function we(e,t){t(e);for(let i of e.children)we(i,t)}function cn(e,t=[],i=""){t.push(`${i}${e.name||"(unnamed)"} [${e.typeofName}] Id=${e.Id}`);for(let n of e.children)cn(n,t,i+" ");return t}function hi(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 ro={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-hi(1-e),OutBounce:hi,InOutBounce:e=>e<.5?(1-hi(1-2*e))/2:(1+hi(2*e-1))/2};function oo(e,t){let i=ro[e]||ro.Linear;return t<=0?0:t>=1?1:i(t)}function St(e,t,i,n=255){let r=pi(e),o=pi(t),a=pi(i);return((n==null?255:pi(n))<<24|r<<16|o<<8|a)>>>0}function Yt(e){let t=e>>>0;return[t>>>16&255,t>>>8&255,t&255,t>>>24&255]}function pi(e){let t=Number(e);return Number.isFinite(t)?Math.max(0,Math.min(255,Math.trunc(t))):0}function ao(e,t,i){let n=Yt(e),r=Yt(t);return St(n[0]+(r[0]-n[0])*i,n[1]+(r[1]-n[1])*i,n[2]+(r[2]-n[2])*i,n[3]+(r[3]-n[3])*i)}var Vs=new Set(["fontColor","bgColor","outlineColor","imageColor"]),mi=class{constructor(t,i,n,r){this.runtime=t,this.object=i,this.data={...n},this.duration=Math.max(0,Number(r)||0),this.easeName="Linear",this.relative=!1,this.playing=!1,this.paused=!1,this.elapsed=0,this.loops=1,this.loopIndex=0,this.from={},this.to={},this.initialFrom=null,this.initialTo=null,this.onComplete=null,this.onStepComplete=null,this.killed=!1}capture(){this.from={},this.to={};for(let[t,i]of Object.entries(this.data)){let n=this.object[t];this.from[t]=n,this.to[t]=this.relative?Number(n)+Number(i):i}}restoreInitial(){this.initialFrom?(this.from={...this.initialFrom},this.to={...this.initialTo}):this.capture()}SetEase(t){return this.easeName=typeof t=="string"?t:t?.Name||"Linear",this}SetRelative(t){return this.relative=!!t,this}Play(){return this._start(!1)}_start(t){return this.playing=!0,this.paused=!1,this.elapsed=0,this.loopIndex=0,this.killed=!1,t&&this.initialFrom?this.restoreInitial():(this.capture(),this.initialFrom={...this.from},this.initialTo={...this.to}),this.runtime.tweens.add(this),this.duration===0&&this.Complete(),this}Pause(){this.paused=!0}Resume(){this.paused=!1}Restart(){return this._start(!0)}Complete(){this.apply(1),this.finish(!0)}Kill(t){t?this.Complete():this.finish(!1)}SetOnComplete(t){return this.onComplete=t,this}SetOnStepComplete(t){return this.onStepComplete=t,this}SetLoops(t){return this.loops=t,this}apply(t){let i=oo(this.easeName,t),n=!1,r=!1;for(let o of Object.keys(this.to)){let a=this.from[o],s=this.to[o];Vs.has(o)&&typeof a=="number"&&typeof s=="number"?this.object[o]=ao(a,s,i):typeof a=="number"&&typeof s=="number"?this.object[o]=a+(s-a)*i:this.object[o]=i>=1?s:a,n=!0,di.has(o)&&(r=!0)}n&&typeof this.object?.markPlayDirty=="function"&&this.object.markPlayDirty(r)}step(t){if(!this.playing||this.paused||this.killed)return;this.elapsed+=t;let i=this.duration<=0?1:Math.min(1,this.elapsed/this.duration);if(this.apply(i),i>=1){this.onStepComplete&&this.runtime.safeCall(this.onStepComplete);let n=this.loops<0;if(this.loopIndex++,n||this.loopIndex<this.loops){this.elapsed=Math.max(0,this.elapsed-this.duration),this.relative?this.capture():this.restoreInitial();let r=this.duration<=0?1:Math.min(1,this.elapsed/this.duration);this.apply(r)}else this.finish(!0)}}finish(t){this.playing=!1,this.killed=!0,this.runtime.tweens.delete(this),t&&this.onComplete&&this.runtime.safeCall(this.onComplete)}},gi=class{constructor(t){this.runtime=t,this.steps=[],this.playing=!1,this.paused=!1,this.killed=!1,this.elapsed=0,this.loops=1,this.loopIndex=0,this.onComplete=null,this.onStepComplete=null,this._built=[]}Append(t){return this.steps.push({kind:"tween",tween:t,parallel:!1}),this}AppendInterval(t){return this.steps.push({kind:"interval",duration:t}),this}AppendCallback(t){return this.steps.push({kind:"callback",fn:t}),this}Join(t){return this.steps.push({kind:"tween",tween:t,parallel:!0}),this}Insert(t,i){return this.steps.push({kind:"insert",time:t,tween:i}),this}InsertCallback(t,i){return this.steps.push({kind:"insertCb",time:t,fn:i}),this}Play(){return this.playing=!0,this.paused=!1,this.killed=!1,this.elapsed=0,this.loopIndex=0,this._schedule(),this._activateDueEntries(),this.runtime.sequences.add(this),this}_schedule(){let t=0,i=0,n=!1;this._built=[];for(let r of this.steps)if(r.kind==="tween"&&r.parallel){let o=n?i:t;this._built.push({at:o,tween:r.tween}),t=Math.max(t,o+r.tween.duration)}else r.kind==="tween"?(this._built.push({at:t,tween:r.tween}),i=t,n=!0,t+=r.tween.duration):r.kind==="interval"?(i=t,n=!0,t+=r.duration):r.kind==="callback"?this._built.push({at:t,fn:r.fn}):r.kind==="insert"?(this._built.push({at:r.time,tween:r.tween}),t=Math.max(t,r.time+r.tween.duration)):r.kind==="insertCb"&&(this._built.push({at:r.time,fn:r.fn}),t=Math.max(t,r.time));this._end=t,this._fired=new Set}Pause(){this.paused=!0;for(let t of this._built)t.tween&&this._fired.has(t)&&t.tween.Pause()}Resume(){this.paused=!1;for(let t of this._built)t.tween&&this._fired.has(t)&&t.tween.Resume()}Restart(){this.Play()}Complete(){for(let t of this._built)t.tween&&(this._fired.has(t)||t.tween.Play(),t.tween.Complete()),t.fn&&!this._fired.has(t)&&this.runtime.safeCall(t.fn),this._fired.add(t);this.finish(!0)}Kill(t){if(t)this.Complete();else{for(let i of this._built)i.tween&&this._fired.has(i)&&i.tween.Kill(!1);this.finish(!1)}}SetOnComplete(t){return this.onComplete=t,this}SetOnStepComplete(t){return this.onStepComplete=t,this}SetLoops(t){return this.loops=t,this}_activateDueEntries(){for(let t of this._built)this._fired.has(t)||this.elapsed+1e-9<t.at||(this._fired.add(t),t.tween&&t.tween.Play(),t.fn&&this.runtime.safeCall(t.fn))}step(t){!this.playing||this.paused||this.killed||(this.elapsed+=t,this._activateDueEntries(),this.elapsed>=this._end&&(this.onStepComplete&&this.runtime.safeCall(this.onStepComplete),this.loopIndex++,this.loops<0||this.loopIndex<this.loops?(this.elapsed=0,this._schedule()):this.finish(!0)))}finish(t){this.playing=!1,this.killed=!0,this.runtime.sequences.delete(this),t&&this.onComplete&&this.runtime.safeCall(this.onComplete)}};var yi={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"]},Ys=[...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"],Bs=[...Array.from({length:14},(e,t)=>`CraftspersonKey${t+1}`),"SprintKey","JumpKey","InteractKey","NormalAttackKey","CharacterSkill1Key","CharacterSkill2Key","CharacterSkill3Key","CharacterSkill4Key","MenuConfirmKey","MenuBackKey","None"];function Us(){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}yi.KeyboardKeyCode=Ys;yi.ControllerKeyCode=Bs;yi.KeyEventType=Us();var so=new Map;function Qe(e,t){let i=`${e}\0${t}`,n=so.get(i);return n||(n={__kind:"EnumItem",Name:t,FullName:`Enum.${e}.${t}`,EnumType:e},so.set(i,n)),n}function fn(e,t){return t==null?t:t.__kind==="EnumItem"?Qe(t.EnumType||e,t.Name):typeof t=="string"&&t?Qe(e,t):t}function dn(){let e={};for(let[t,i]of Object.entries(yi)){let n={};for(let r of i)n[r]=Qe(t,r);e[t]=n}return e}var lo={horizontalAlignment:"TextHorizontalAlignment",verticalAlignment:"TextVerticalAlignment",imageSource:"ImageSource",fillType:"ImageFillType",fillHorizontalType:"ImageFillHorizontalType",fillVerticalType:"ImageFillVerticalType",fillRadial90Type:"ImageFillRadial90Type",fillRadialType:"ImageFillRadialType",softEdgeMode:"ImageMaskSoftEdgeMode",layer:"UIAnimationLayer",scrollDirection:"ScrollDirection",layoutConstraint:"ScrollLayoutConstraint"},et=u.LUA_REGISTRYINDEX,Hs=u.LUA_MULTRET;function me(e){return e==null?"":typeof e=="string"?e:e.Name||e.FullName||String(e)}function Xs(e){let t=String(e).replace(/\\/g,"/").replace(/\.lua$/i,"");return t.split("/").pop()||t}var bi=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=dn(),this.luaStates=new Set,this.L=null}nextControlId(){let t=this._nextControlId;return this._nextControlId+=1,t}resolveScriptMappingId(t){let i=Number(t);if(Number.isSafeInteger(i)&&i>0)return this._nextScriptMappingId=Math.max(this._nextScriptMappingId,i+1),i;let n=this._nextScriptMappingId;return this._nextScriptMappingId+=1,n}pushPackedColor(t,i){let n=i>>>0;(n|0)===n?u.lua_pushinteger(t,n):u.lua_pushnumber(t,n)}unrefLuaCallback(t){Zr(this,t)}log(t,...i){let n=i.map(r=>r==null?"nil":typeof r=="object"&&r!==null&&r.__kind==="EnumItem"?r.Name:String(r)).join(" ");this.logs.push({level:t,text:n,time:this.clock.time})}safeCall(t,...i){try{return t(...i)}catch(n){this.log("lua-error",n&&n.message?n.message:String(n))}}scriptCanRun(t){if(!t?.alive||!t.enabled)return!1;let i=t.object;return!i||i.alive&&i.activeInHierarchy}cursorEventsEnabled(t){for(let i=t;i;i=i.parent)if(i.kind==="container"&&i.showCursor===!0)return!0;return!1}registerTemplate(t,i){this.templates.set(Number(t),i)}registerScriptFile(t,i){let n=this.normalizeRequirePath(t);this.scriptFiles.set(n,i),n.startsWith("default_import_file/")||this.requireAliases.set(`default_import_file/${n}`,n)}normalizeRequirePath(t){let i=String(t).replace(/\\/g,"/");return i.endsWith(".lua")&&(i=i.slice(0,-4)),i}addRoot(t){let i=t instanceof Be?t:new Be(this,t);return this.roots.push(i),we(i,n=>this.controlsById.set(n.Id,n)),this.mountSpecScripts(t,i),i}mountSpecScripts(t,i){if(t instanceof Be)return;let n=o=>(o.scripts?.length||0)>0||(o.children||[]).some(n);if(!t||!n(t))return;let r=this.lifecyclePhase;try{let o=(a,s)=>{for(let l of a.scripts||[])try{this.mountScript({path:l.path,source:l.source,control:s,scriptMappingId:l.scriptMappingId})}catch(f){let h=f&&f.message?f.message:String(f);this.mountErrors.push(h),this.log("lua-error",h)}let c=a.children||[];for(let l=0;l<c.length;l+=1)o(c[l],s?.children?.[l])};o(t,i)}finally{this.lifecyclePhase=r}}makeCursorEventData({x:t=0,y:i=0,pressX:n=t,pressY:r=i,deltaX:o=t-n,deltaY:a=i-r,dragging:s=!1,touchId:c=-1}={}){let l=this;return{__kind:"CursorEventData",typeofName:"CursorEventData",dragging:s,touchId:c,x:t,y:i,pressX:n,pressY:r,GetUIPos(){return[t,i]},GetPressUIPos(){return[n,r]},GetUIPosDelta(){return[o,a]}}}boot(){let t=this.newLuaThread();this.L=t}installGlobals(t){let i=this;u.lua_pushcfunction(t,n=>{let r=u.lua_gettop(n),o=[];for(let a=1;a<=r;a++)o.push(pe(n,i,a));return i.log("info",...o),0}),u.lua_setglobal(t,_("print")),u.lua_pushcfunction(t,n=>{let r=u.lua_gettop(n),o=[];for(let a=1;a<=r;a++)o.push(pe(n,i,a));return i.log("error",...o),0}),u.lua_setglobal(t,_("printerr")),u.lua_pushcfunction(t,n=>{if(u.lua_type(n,1)===u.LUA_TTABLE&&!Ye(n,1))return u.lua_pushstring(n,_("table")),1;let r=pe(n,i,1);return u.lua_pushstring(n,_(i.typeofOf(r))),1}),u.lua_setglobal(t,_("typeof")),this.pushColorLib(t),this.pushEnumLib(t),this.pushGameLib(t),u.lua_pushcfunction(t,n=>i.luaRequire(n)),u.lua_setglobal(t,_("require"))}typeofOf(t){return t==null?"nil":t.__kind==="Script"?"Script":t.__kind==="EnumItem"?"EnumItem":t.__kind==="CursorEventData"?"CursorEventData":t.typeofName?t.typeofName:typeof t=="number"?"number":typeof t=="string"?"string":typeof t=="boolean"?"boolean":typeof t}pushColorLib(t){u.lua_newtable(t),u.lua_pushcfunction(t,i=>(this.pushPackedColor(i,St(u.lua_tonumber(i,1),u.lua_tonumber(i,2),u.lua_tonumber(i,3),255)),1)),u.lua_setfield(t,-2,_("FromRGB")),u.lua_pushcfunction(t,i=>{let n=u.lua_isnoneornil(i,4)?255:u.lua_tonumber(i,4);return this.pushPackedColor(i,St(u.lua_tonumber(i,1),u.lua_tonumber(i,2),u.lua_tonumber(i,3),n)),1}),u.lua_setfield(t,-2,_("FromRGBA")),u.lua_pushcfunction(t,i=>{let n=u.lua_tonumber(i,1)>>>0,[r,o,a,s]=Yt(n);return u.lua_pushnumber(i,r),u.lua_pushnumber(i,o),u.lua_pushnumber(i,a),u.lua_pushnumber(i,s),4}),u.lua_setfield(t,-2,_("ToRGBA")),u.lua_newtable(t),u.lua_pushcfunction(t,i=>{let n=u.lua_tonumber(i,2),r=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,St(n,r,o,a)),1}),u.lua_setfield(t,-2,_("__call")),u.lua_setmetatable(t,-2),u.lua_setglobal(t,_("Color"))}pushEnumLib(t){u.lua_newtable(t);for(let[i,n]of Object.entries(this.enumTree)){u.lua_newtable(t);for(let[r,o]of Object.entries(n))this.pushEnumItem(t,o),u.lua_setfield(t,-2,_(r));u.lua_setfield(t,-2,_(i))}u.lua_setglobal(t,_("Enum"))}pushEnumItem(t,i){let n=u.lua_newuserdata(t,0);Ze(n,i),re.luaL_setmetatable(t,_("EnumItem"))}pushControl(t,i){let n=u.lua_newuserdata(t,0);Ze(n,i),re.luaL_setmetatable(t,_("Control"))}pushScript(t,i){u.lua_newtable(t),u.lua_pushlightuserdata(t,ln);let n=u.lua_newuserdata(t,0);Ze(n,i),u.lua_rawset(t,-3),re.luaL_getmetatable(t,_("Script")),u.lua_setmetatable(t,-2)}pushTween(t,i){let n=u.lua_newuserdata(t,0);Ze(n,i);let r=i.Append?"TweenSequence":"Tween";re.luaL_setmetatable(t,_(r))}pushCursor(t,i){let n=u.lua_newuserdata(t,0);Ze(n,i),re.luaL_setmetatable(t,_("CursorEventData"))}pushGameLib(t){let i=this;u.lua_newtable(t);let n={InstantiateClientUIControl:r=>{let o=u.lua_tointeger(r,1),a=be(u.lua_touserdata(r,2)),s=i.instantiate(o,a,i.lifecyclePhase);return s?(i.pushControl(r,s),1):(u.lua_pushnil(r),1)},DestroyClientUIControl:r=>{let o=be(u.lua_touserdata(r,1));return o&&i.destroyControl(o),0},GetClientUIControl:r=>{let o=u.lua_tointeger(r,1),a=i.controlsById.get(o);return a?i.pushControl(r,a):u.lua_pushnil(r),1},FindClientUIRoot:r=>{let o=L(r,1),a=i.roots.find(s=>s.name===o);return a?i.pushControl(r,a):u.lua_pushnil(r),1},GetClientUIRoots:r=>(u.lua_createtable(r,i.roots.length,0),i.roots.forEach((o,a)=>{i.pushControl(r,o),u.lua_rawseti(r,-2,a+1)}),1),GetUICanvasSize:r=>(u.lua_pushnumber(r,i.canvasWidth),u.lua_pushnumber(r,i.canvasHeight),2),GetCursorUIPos:r=>(u.lua_pushnumber(r,i.cursor.x),u.lua_pushnumber(r,i.cursor.y),2),GetDevice:r=>(i.pushEnumItem(r,Qe("Device",i.device)),1),SetControllerFocus:r=>(i.focus=be(u.lua_touserdata(r,1)),0),GetControllerFocus:r=>(i.focus?i.pushControl(r,i.focus):u.lua_pushnil(r),1),GetControllerLeftStickAxis:r=>(u.lua_pushnumber(r,i.stick.left[0]),u.lua_pushnumber(r,i.stick.left[1]),2),GetControllerRightStickAxis:r=>(u.lua_pushnumber(r,i.stick.right[0]),u.lua_pushnumber(r,i.stick.right[1]),2),Tween:r=>{let o=be(u.lua_touserdata(r,1))||pe(r,i,1),a=pe(r,i,2)||{},s=u.lua_tonumber(r,3),c=new mi(i,o,a,s);return i.pushTween(r,c),1},TweenSequence:r=>(i.pushTween(r,new gi(i)),1),ServerSignal:r=>{let o=L(r,1),a=i.makeServerSignal(o),s=u.lua_newuserdata(r,0);return Ze(s,a),re.luaL_setmetatable(r,_("ServerSignal")),1},GetGlobalCustomVariableValue:r=>{let o=me(pe(r,i,1)),a=L(r,2);return ne(r,i,i.getVar(o,a)),1},PauseLevelTime:r=>(i.clock.paused=!!u.lua_toboolean(r,1),0),IsLevelTimePaused:r=>(u.lua_pushboolean(r,i.clock.paused),1),PlayAudio2D:r=>{let o=i.nextAudioId++;return i.audios.set(o,{audioId:u.lua_tointeger(r,1),alive:!0}),u.lua_pushinteger(r,o),1},StopAudio:r=>{let o=u.lua_tointeger(r,1),a=i.audios.get(o);return a&&(a.alive=!1),0},IsAudioAlive:r=>{let o=i.audios.get(u.lua_tointeger(r,1));return u.lua_pushboolean(r,!!(o&&o.alive)),1},GetLanguageType:r=>(i.pushEnumItem(r,Qe("LanguageType",i.language)),1),GetStageMode:r=>(i.pushEnumItem(r,Qe("StageMode",i.stageMode)),1),IsTestPlay:r=>(u.lua_pushboolean(r,i.testPlay),1),GetText:r=>{let o=L(r,1);return u.lua_pushstring(r,_(o)),1},PrintClientUITree:r=>{for(let o of i.roots)i.log("info",cn(o).join(`
|
|
106
106
|
`));return 0}};for(let[r,o]of Object.entries(n))u.lua_pushcfunction(t,o),u.lua_setfield(t,-2,_(r));u.lua_setglobal(t,_("game"))}makeServerSignal(t){let i=[],n=this;return{__kind:"ServerSignal",name:t,AddParam(r,o){i.push({type:me(r),value:o})},AddInt(r){i.push({type:"Int",value:r})},AddIntList(r){i.push({type:"IntList",value:r})},AddFloat(r){i.push({type:"Float",value:r})},AddFloatList(r){i.push({type:"FloatList",value:r})},AddString(r){i.push({type:"String",value:r})},AddStringList(r){i.push({type:"StringList",value:r})},AddVector3(r){i.push({type:"Vector3",value:r})},AddVector3List(r){i.push({type:"Vector3List",value:r})},AddBool(r){i.push({type:"Bool",value:r})},AddBoolList(r){i.push({type:"BoolList",value:r})},AddGuid(r){i.push({type:"Guid",value:r})},AddGuidList(r){i.push({type:"GuidList",value:r})},AddEntity(r){i.push({type:"Entity",value:r})},AddEntityList(r){i.push({type:"EntityList",value:r})},AddPrefabId(r){i.push({type:"PrefabId",value:r})},AddPrefabIdList(r){i.push({type:"PrefabIdList",value:r})},AddConfigId(r){i.push({type:"ConfigId",value:r})},AddConfigIdList(r){i.push({type:"ConfigIdList",value:r})},SendSignal(){let r=i.slice();n.serverBridge&&typeof n.serverBridge.receiveFromClient=="function"&&n.serverBridge.receiveFromClient(t,r)}}}instantiate(t,i,n){if(n==="OnInit"||n==="OnDestroy")return null;let r=this.templates.get(Number(t));if(!r||!i)return null;let o=new Be(this,{...r,Id:this.nextControlId(),authoringId:null,prefabIndex:Number(t)});return i.addChild(o),we(o,a=>this.controlsById.set(a.Id,a)),this.mountSpecScripts(r,o),o}destroyControl(t){if(!(!t||!t.alive)){if(t._destroying)throw new Error(`\u5BA2\u6237\u7AEF\u63A7\u4EF6\u751F\u547D\u5468\u671F\u5904\u4E8E\u521B\u5EFA\u6216\u9500\u6BC1\u65F6\uFF0C\u65E0\u6CD5\u8C03\u7528DestroyClientUIControl, ID:${t.name}`);we(t,i=>{i._destroying=!0}),this._destroyControlTree(t)}}_destroyControlTree(t){this.releaseControlListeners(t);for(let i of t.scripts.slice())this.unmountScript(i);for(let i of t.children.slice())this._destroyControlTree(i);if(t.alive=!1,this._playRemoved.push(t.Id),t.parent){let i=t.parent,n=i.children.indexOf(t);n>=0&&i.children.splice(n,1),t._parent=null,i.markPlayDirty(!0)}else{let i=this.roots.indexOf(t);i>=0&&this.roots.splice(i,1)}this.controlsById.delete(t.Id),this.focus===t&&(this.focus=null);for(let i of[...this.tweens])i.object===t&&i.Kill(!1)}releaseControlListeners(t){for(let i of t.cursorListeners.values())for(let n of i)this.unrefLuaCallback(n);for(let i of t.keyListeners.values())for(let n of i)this.unrefLuaCallback(n);for(let i of t.navListeners.values())for(let n of i)this.unrefLuaCallback(n);t.cursorListeners.clear(),t.keyListeners.clear(),t.navListeners.clear(),t.navConfig.clear()}onControlActiveChanging(t,i){let n=[];we(t,r=>n.push({control:r,was:r.activeInHierarchy})),t.active=!!i,t.markPlayDirty(!0);for(let r of n){let o=r.control.activeInHierarchy;if(r.was!==o)for(let a of r.control.scripts.slice())o?this.enableScript(a):this.disableScript(a)}}bindScriptEnv(t){let i=t.env;return i?(this.pushScript(i,t),u.lua_setglobal(i,_("script")),i):null}disableScript(t){if(!t?.alive||!t.env||t.lifecyclePhase!=="running")return;let i=this.lifecyclePhase;this.lifecyclePhase="OnDisable",t.lifecyclePhase="OnDisable",this.bindScriptEnv(t),this.callGlobal(t.env,"OnDisable"),t.lifecyclePhase="disabled",this.lifecyclePhase=i}enableScript(t){if(!t?.alive||!t.env||t.lifecyclePhase!=="disabled")return;let i=this.lifecyclePhase;this.lifecyclePhase="OnEnable",t.lifecyclePhase="OnEnable",this.bindScriptEnv(t),this.callGlobal(t.env,"OnEnable"),t.lifecyclePhase="running",this.lifecyclePhase=i}unmountScript(t){if(!t||!t.alive)return;let i=t.env,n=this.lifecyclePhase;i&&(t.lifecyclePhase==="running"&&(this.lifecyclePhase="OnDisable",t.lifecyclePhase="OnDisable",this.bindScriptEnv(t),this.callGlobal(i,"OnDisable")),this.lifecyclePhase="OnDestroy",t.lifecyclePhase="OnDestroy",this.bindScriptEnv(t),this.callGlobal(i,"OnDestroy")),t.alive=!1,t.lifecyclePhase="destroyed",this.lifecyclePhase=n,this.mountedScripts=this.mountedScripts.filter(r=>r!==t),t.object&&(t.object.scripts=t.object.scripts.filter(r=>r!==t)),this.varHandlers=this.varHandlers.filter(r=>r.script!==t),this.signalHandlers=this.signalHandlers.filter(r=>r.script!==t),i&&i!==this.L&&this.closeTrackedLuaState(i),t.env=null}installMetatables(t){this.mtEnum(t),this.mtControl(t),this.mtScript(t),this.mtTween(t),this.mtSeq(t),this.mtSignal(t),this.mtCursor(t)}mtIndexNewindex(t,i,n,r,o,a){re.luaL_newmetatable(t,_(i)),u.lua_pushcfunction(t,s=>{let c=Ye(s,1)||be(u.lua_touserdata(s,1)),l=L(s,2);if(o[l]&&(!a||a(c,l)))return u.lua_pushcfunction(s,o[l]),1;let f=n(c,l);return f===void 0?(u.lua_pushnil(s),1):(ne(s,this,f),1)}),u.lua_setfield(t,-2,_("__index")),u.lua_pushcfunction(t,s=>{try{let c=Ye(s,1)||be(u.lua_touserdata(s,1)),l=L(s,2),f=pe(s,this,3);return r(c,l,f),0}catch(c){return u.lua_pushstring(s,_(String(c.message||c))),u.lua_error(s)}}),u.lua_setfield(t,-2,_("__newindex")),u.lua_pushcfunction(t,s=>{let c=Ye(s,1)||be(u.lua_touserdata(s,1)),l=Ye(s,2)||be(u.lua_touserdata(s,2));return u.lua_pushboolean(s,c===l),1}),u.lua_setfield(t,-2,_("__eq")),u.lua_pop(t,1)}method(t){let i=this;return n=>{let r=Ye(n,1)||be(u.lua_touserdata(n,1)),o=u.lua_gettop(n),a=[];for(let s=2;s<=o;s++)a.push(pe(n,i,s));try{let s=t(r,...a);if(s===r)return u.lua_pushvalue(n,1),1;if(s===void 0)return 0;if(Array.isArray(s)&&s.__multi){for(let c of s)ne(n,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(n,s.length,0),s.forEach((c,l)=>{i.pushControl(n,c),u.lua_rawseti(n,-2,l+1)}),1;if(s.__scripts)return u.lua_createtable(n,s.length,0),s.forEach((c,l)=>{i.pushScript(n,c),u.lua_rawseti(n,-2,l+1)}),1;if(typeof s[0]=="number"&&s.length<=4){for(let c of s)u.lua_pushnumber(n,c);return s.length}}return ne(n,i,s),1}catch(s){return u.lua_pushstring(n,_(String(s.message||s))),u.lua_error(n)}}}mtEnum(t){let i=new Set(["Name","FullName","EnumType"]);this.mtIndexNewindex(t,"EnumItem",(n,r)=>i.has(r)?n[r]:void 0,(n,r)=>{throw new Error(`cannot set ${r}, no such field`)},{})}mtCursor(t){let i=new Set(["dragging","touchId"]);this.mtIndexNewindex(t,"CursorEventData",(n,r)=>i.has(r)?n[r]:void 0,(n,r)=>{throw new Error(`cannot set ${r}, no such field`)},{GetUIPos:this.method(n=>n.GetUIPos()),GetPressUIPos:this.method(n=>n.GetPressUIPos()),GetUIPosDelta:this.method(n=>n.GetUIPosDelta())})}mtControl(t){let i={GetChildren:this.method(n=>{let r=n.GetChildren();return r.__controls=!0,r}),GetChild:this.method((n,r)=>n.GetChild(r)),FindChild:this.method((n,r)=>n.FindChild(r)),SetActive:this.method((n,r)=>n.SetActive(r)),SetVisible:this.method((n,r)=>n.SetVisible(r)),GetSiblingIndex:this.method(n=>n.GetSiblingIndex()),SetSiblingIndex:this.method((n,r)=>n.SetSiblingIndex(r)),SetAsFirstSibling:this.method(n=>n.SetAsFirstSibling()),SetAsLastSibling:this.method(n=>n.SetAsLastSibling()),GetAnchoredPosition:this.method(n=>n.GetAnchoredPosition()),SetAnchoredPosition:this.method((n,r,o)=>n.SetAnchoredPosition(r,o)),GetSizeDelta:this.method(n=>n.GetSizeDelta()),SetSizeDelta:this.method((n,r,o)=>n.SetSizeDelta(r,o)),GetAnchorMin:this.method(n=>n.GetAnchorMin()),SetAnchorMin:this.method((n,r,o)=>n.SetAnchorMin(r,o)),GetAnchorMax:this.method(n=>n.GetAnchorMax()),SetAnchorMax:this.method((n,r,o)=>n.SetAnchorMax(r,o)),GetPivot:this.method(n=>n.GetPivot()),SetPivot:this.method((n,r,o)=>n.SetPivot(r,o)),GetLocalScale:this.method(n=>n.GetLocalScale()),SetLocalScale:this.method((n,r,o,a)=>n.SetLocalScale(r,o,a)),GetLocalRotation:this.method(n=>n.GetLocalRotation()),SetLocalRotation:this.method((n,r,o,a)=>n.SetLocalRotation(r,o,a)),GetScriptByPath:this.method((n,r)=>n.GetScriptByPath(r)),GetScript:this.method((n,r)=>n.GetScript(r)),GetScripts:this.method(n=>{let r=n.GetScripts();return r.__scripts=!0,r}),AddCursorEventListener:this.method((n,r,o)=>n.AddCursorEventListener(me(r),o)),RemoveCursorEventListener:this.method((n,r,o)=>n.RemoveCursorEventListener(me(r),o)),RemoveCursorEventListeners:this.method((n,r)=>n.RemoveCursorEventListeners(me(r))),RemoveAllCursorEventListeners:this.method(n=>n.RemoveAllCursorEventListeners()),SimulateCursorClick:this.method(n=>n.SimulateCursorClick()),AddKeyEventListener:this.method((n,r,o)=>n.AddKeyEventListener(me(r),o)),RemoveKeyEventListener:this.method((n,r,o)=>n.RemoveKeyEventListener(me(r),o)),RemoveKeyEventListeners:this.method((n,r)=>n.RemoveKeyEventListeners(me(r))),RemoveAllKeyEventListeners:this.method(n=>n.RemoveAllKeyEventListeners()),AddNavigationEventListener:this.method((n,r,o)=>n.AddNavigationEventListener(me(r),o)),RemoveNavigationEventListener:this.method((n,r,o)=>n.RemoveNavigationEventListener(me(r),o)),RemoveNavigationEventListeners:this.method((n,r)=>n.RemoveNavigationEventListeners(me(r))),RemoveAllNavigationEventListeners:this.method(n=>n.RemoveAllNavigationEventListeners()),SetControllerNavigation:this.method((n,r,o,a)=>n.SetControllerNavigation(me(r),o,a)),GetControllerNavigation:this.method((n,r)=>n.GetControllerNavigation(me(r))),SetImage:this.method((n,r,o)=>n.SetImage(r,o)),SetSoftEdgeWidth:this.method((n,r,o)=>n.SetSoftEdgeWidth(r,o)),SetFillUnused:this.method(n=>n.SetFillUnused()),SetFillHorizontal:this.method((n,r,o)=>n.SetFillHorizontal(r,o)),SetFillVertical:this.method((n,r,o)=>n.SetFillVertical(r,o)),SetFillRadial90:this.method((n,r,o)=>n.SetFillRadial90(r,o)),SetFillRadial180:this.method((n,r,o)=>n.SetFillRadial180(r,o)),SetFillRadial360:this.method((n,r,o)=>n.SetFillRadial360(r,o)),PlayAnimation:this.method(n=>n.PlayAnimation()),StopAnimation:this.method(n=>n.StopAnimation()),RefreshItems:this.method(n=>n.RefreshItems()),GetItemIndex:this.method(n=>n.GetItemIndex()),GetItemSize:this.method(n=>n.GetItemSize()),GetItemSpacing:this.method(n=>n.GetItemSpacing()),GetPadding:this.method(n=>n.GetPadding()),ScrollToItemAt:this.method(n=>n.ScrollToItemAt()),GetContentLength:this.method(n=>n.GetContentLength())};this.mtIndexNewindex(t,"Control",(n,r)=>{if(!un(n,r))return;let o=n[r],a=lo[r];return a?fn(a,o):o},(n,r,o)=>{if(un(n,r)==="rw"){let s=lo[r];n[r]=s?fn(s,o):o,typeof n.markPlayDirty=="function"&&n.markPlayDirty(di.has(r));return}throw new Error(`cannot set ${r}, no such field`)},i,no)}mtScript(t){let i=this,n=new Set(["alive","scriptMappingId","object","path","enabled"]);this.mtIndexNewindex(t,"Script",(r,o)=>n.has(o)?r[o]:void 0,(r,o,a)=>{if(o==="enabled"){r.enabled=!!a;return}throw new Error(`cannot set ${o}, no such field`)},{GetParam:this.method((r,o)=>Object.prototype.hasOwnProperty.call(r.params,o)?r.params[o]:null),Invoke:this.method((r,o,...a)=>r.invoke(o,a)),EnableUpdate:this.method((r,o)=>{r.updateEnabled=!!o}),RegisterServerSignalHandler:this.method((r,o,a)=>{i.signalHandlers.push({script:r,name:o,fn:a})}),UnregisterServerSignalHandler:this.method((r,o)=>{i.signalHandlers=i.signalHandlers.filter(a=>!(a.script===r&&a.name===o))}),RegisterCustomVariableChangedHandler:this.method((r,o,a,s)=>{i.varHandlers.push({script:r,entityType:me(o),name:a,fn:s})}),UnregisterCustomVariableChangedHandler:this.method((r,o,a)=>{let s=me(o);i.varHandlers=i.varHandlers.filter(c=>!(c.script===r&&c.entityType===s&&c.name===a))})})}mtTween(t){this.mtIndexNewindex(t,"Tween",()=>{},()=>{},{SetEase:this.method((i,n)=>i.SetEase(n)),SetRelative:this.method((i,n)=>i.SetRelative(n)),Play:this.method(i=>i.Play()),Pause:this.method(i=>i.Pause()),Resume:this.method(i=>i.Resume()),Restart:this.method(i=>i.Restart()),Complete:this.method(i=>i.Complete()),Kill:this.method((i,n)=>i.Kill(n)),SetOnComplete:this.method((i,n)=>i.SetOnComplete(n)),SetOnStepComplete:this.method((i,n)=>i.SetOnStepComplete(n)),SetLoops:this.method((i,n)=>i.SetLoops(n))})}mtSeq(t){this.mtIndexNewindex(t,"TweenSequence",()=>{},()=>{},{Append:this.method((i,n)=>i.Append(n)),AppendInterval:this.method((i,n)=>i.AppendInterval(n)),AppendCallback:this.method((i,n)=>i.AppendCallback(n)),Join:this.method((i,n)=>i.Join(n)),Insert:this.method((i,n,r)=>i.Insert(n,r)),InsertCallback:this.method((i,n,r)=>i.InsertCallback(n,r)),Play:this.method(i=>i.Play()),Pause:this.method(i=>i.Pause()),Resume:this.method(i=>i.Resume()),Restart:this.method(i=>i.Restart()),Complete:this.method(i=>i.Complete()),Kill:this.method((i,n)=>i.Kill(n)),SetOnComplete:this.method((i,n)=>i.SetOnComplete(n)),SetOnStepComplete:this.method((i,n)=>i.SetOnStepComplete(n)),SetLoops:this.method((i,n)=>i.SetLoops(n))})}mtSignal(t){this.mtIndexNewindex(t,"ServerSignal",()=>{},()=>{},{AddParam:this.method((i,n,r)=>i.AddParam(n,r)),SendSignal:this.method(i=>i.SendSignal()),AddInt:this.method((i,n)=>i.AddInt(n)),AddIntList:this.method((i,n)=>i.AddIntList(n)),AddFloat:this.method((i,n)=>i.AddFloat(n)),AddFloatList:this.method((i,n)=>i.AddFloatList(n)),AddString:this.method((i,n)=>i.AddString(n)),AddStringList:this.method((i,n)=>i.AddStringList(n)),AddVector3:this.method((i,n)=>i.AddVector3(n)),AddVector3List:this.method((i,n)=>i.AddVector3List(n)),AddBool:this.method((i,n)=>i.AddBool(n)),AddBoolList:this.method((i,n)=>i.AddBoolList(n)),AddGuid:this.method((i,n)=>i.AddGuid(n)),AddGuidList:this.method((i,n)=>i.AddGuidList(n)),AddEntity:this.method((i,n)=>i.AddEntity(n)),AddEntityList:this.method((i,n)=>i.AddEntityList(n)),AddPrefabId:this.method((i,n)=>i.AddPrefabId(n)),AddPrefabIdList:this.method((i,n)=>i.AddPrefabIdList(n)),AddConfigId:this.method((i,n)=>i.AddConfigId(n)),AddConfigIdList:this.method((i,n)=>i.AddConfigIdList(n))})}luaRequire(t){let i=L(t,1),n=this.normalizeRequirePath(i),r=this.requireAliases.get(n)||n;u.lua_rawgeti(t,et,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(r);if(s?.loading)return u.lua_pushstring(t,_(`failed to load script '${n}': cyclic require`)),u.lua_error(t);if(s&&s.ref!=null)return u.lua_rawgeti(t,et,s.ref),1;let c=this.scriptFiles.get(r);if(c==null)return u.lua_pushstring(t,_(`failed to load script '${n}'`)),u.lua_error(t);let l=u.lua_gettop(t);a.set(r,{loading:!0});try{this.loadModule(t,o,r,c),u.lua_pushvalue(t,-1);let f=re.luaL_ref(t,et);return a.set(r,{ref:f}),1}catch(f){return a.delete(r),u.lua_settop(t,l),u.lua_pushstring(t,_(`failed to load script '${n}': ${f.message||f}`)),u.lua_error(t)}}newLuaThread(){let t=re.luaL_newstate();return qr.luaL_openlibs(t),eo(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,re.luaL_ref(t,et)),t}copyLuaEnvironment(t,i){let n=u.lua_absindex(t,i);u.lua_newtable(t);let r=u.lua_absindex(t,-1);for(u.lua_pushnil(t);u.lua_next(t,n)!==0;)u.lua_pushvalue(t,-2),u.lua_pushvalue(t,-2),u.lua_rawset(t,r),u.lua_pop(t,1);u.lua_pushvalue(t,r),u.lua_setfield(t,r,_("_G"))}closeTrackedLuaState(t){if(!t||!this.luaStates.has(t))return;for(let n of this.requireCache.get(t)?.values()||[])n.ref!=null&&re.luaL_unref(t,et,n.ref);this.requireCache.delete(t);let i=this.moduleBaseEnvironments.get(t);if(i!=null&&re.luaL_unref(t,et,i),this.moduleBaseEnvironments.delete(t),this.luaStates.delete(t),this.luaFunctions)for(let[n,r]of this.luaFunctions)r.__luaState===t&&this.luaFunctions.delete(n);Qr(t)}loadModule(t,i,n,r){let o={__kind:"Script",alive:!0,scriptMappingId:this.resolveScriptMappingId(),object:null,path:n,enabled:!0,updateEnabled:!1,params:{},env:t,invoke(){}},a=String(r).replace(/^\uFEFF/,""),s=fi(a);if(re.luaL_loadbuffer(t,s,s.length,_(`@${n}`))!==Ee)throw new Error(L(t,-1));let l=u.lua_absindex(t,-1);if(u.lua_rawgeti(t,et,this.moduleBaseEnvironments.get(i)),this.copyLuaEnvironment(t,-1),u.lua_remove(t,-2),this.pushScript(t,o),u.lua_setfield(t,-2,_("script")),u.lua_setupvalue(t,l,1),u.lua_pcall(t,0,1,0)!==Ee)throw new Error(L(t,-1))}mountScript({path:t,source:i,control:n,params:r={},scriptMappingId:o=void 0}){this.L||this.boot();let a=this.newLuaThread(),s={__kind:"Script",alive:!0,scriptMappingId:this.resolveScriptMappingId(o),object:n,path:Xs(t),enabled:!0,updateEnabled:!1,params:r,env:a,lifecyclePhase:"idle"};s.invoke=(l,f)=>this.invokeOn(a,l,f),n&&n.scripts.push(s),this.mountedScripts.push(s),this.pushScript(a,s),u.lua_setglobal(a,_("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 h=this.callGlobal(a,"OnStart");return h&&this.mountErrors.push(h),this.lifecyclePhase="running",s.lifecyclePhase="running",s}catch(l){throw s.alive=!1,s.lifecyclePhase="failed",this.mountedScripts=this.mountedScripts.filter(f=>f!==s),n&&(n.scripts=n.scripts.filter(f=>f!==s)),this.varHandlers=this.varHandlers.filter(f=>f.script!==s),this.signalHandlers=this.signalHandlers.filter(f=>f.script!==s),this.lifecyclePhase=c,a&&a!==this.L&&this.closeTrackedLuaState(a),s.env=null,l}}runChunk(t,i,n){let r=String(i).replace(/^\uFEFF/,""),o=fi(r),a=re.luaL_loadbuffer(t,o,o.length,_(`@${n}`));if(a!==Ee){let c=L(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!==Ee){let c=L(t,-1)||`lua_pcall status ${s}`;throw u.lua_pop(t,1),new Error(c)}}callGlobal(t,i){if(u.lua_getglobal(t,_(i)),u.lua_isfunction(t,-1)){if(u.lua_pcall(t,0,0,0)!==Ee){let r=L(t,-1);u.lua_pop(t,1);let o=`${i}: ${r}`;return this.log("lua-error",o),o}}else u.lua_pop(t,1);return null}callGlobalDt(t,i,n){if(u.lua_getglobal(t,_(i)),u.lua_isfunction(t,-1)){if(u.lua_pushnumber(t,n),u.lua_pcall(t,1,0,0)!==Ee){let o=L(t,-1);u.lua_pop(t,1),this.log("lua-error",`${i}: ${o}`)}}else u.lua_pop(t,1)}invokeOn(t,i,n){let r=u.lua_gettop(t);if(u.lua_getglobal(t,_(i)),!u.lua_isfunction(t,-1)){u.lua_settop(t,r);return}for(let c of n)ne(t,this,c);if(u.lua_pcall(t,n.length,Hs,0)!==Ee){let c=L(t,-1);throw u.lua_settop(t,r),new Error(c)}let a=u.lua_gettop(t)-r;if(a<=0){u.lua_settop(t,r);return}if(a===1){let c=pe(t,this,-1);return u.lua_settop(t,r),c}let s=[];for(let c=1;c<=a;c++)s.push(pe(t,this,r+c));return u.lua_settop(t,r),s.__multi=!0,s}runScriptPhase(t,i){for(let n of this.mountedScripts){if(!this.scriptCanRun(n))continue;let r=n.env;r&&(this.pushScript(r,n),u.lua_setglobal(r,_("script")),!(t==="OnUpdate"&&!n.updateEnabled)&&this.callGlobalDt(r,t,i))}}step(t=1/30){if(typeof t!="number"||!Number.isFinite(t)||t<0)throw new TypeError("dt must be a finite non-negative number");this.clock.frame++,this.clock.time+=t;let i=!this.clock.paused;for(let n of[...this.tweens])n.step(t);for(let n of[...this.sequences])n.step(t);this.runScriptPhase("OnUpdate",t),i&&(this.clock.levelTime+=t,this.runScriptPhase("OnLevelUpdate",t))}injectKey(t){for(let i of this.roots)we(i,n=>{n.alive&&n.activeInHierarchy&&n.keyListeners.has(t)&&n.emitKey(t)})}injectCursor(t,i,n){let r=n||this.makeCursorEventData({});Number.isFinite(r.x)&&Number.isFinite(r.y)&&(this.cursor.x=r.x,this.cursor.y=r.y),t.emitCursor(i,r)}getVar(t,i){if(this.serverBridge&&typeof this.serverBridge.getVar=="function")return this.serverBridge.getVar(t,i);let n=this.serverVars[t];return n?n[i]:void 0}notifyVarHandlers(t,i){for(let n of this.varHandlers)this.scriptCanRun(n.script)&&n.entityType===t&&n.name===i&&this.safeCall(n.fn,this.enumTree.CustomVariableEntityType[t],i)}setVar(t,i,n){if(this.serverBridge&&typeof this.serverBridge.setVar=="function"){this.serverBridge.setVar(t,i,n);return}let r=this.serverVars[t]||(this.serverVars[t]=Object.create(null));r[i]=n,this.notifyVarHandlers(t,i)}sendClientSignal(t,i){for(let n of this.signalHandlers)this.scriptCanRun(n.script)&&n.name===t&&this.safeCall(n.fn,t,i)}evalQueryScript(t,i){this.L||this.boot();let n=this.L;u.lua_createtable(n,0,5);let r=(o,a)=>{u.lua_pushcfunction(n,a),u.lua_setfield(n,-2,_(o))};return r("var",o=>(ne(o,this,i.var(L(o,1),L(o,2))),1)),r("logContains",o=>(u.lua_pushboolean(o,i.logContains(L(o,1))),1)),r("control",o=>(ne(o,this,i.control(L(o,1))),1)),r("logs",o=>(ne(o,this,i.logs()),1)),r("signals",o=>(ne(o,this,i.signals(L(o,1))),1)),r("serverLogs",o=>(ne(o,this,i.serverLogs?i.serverLogs():[]),1)),r("serverLogContains",o=>{let a=i.serverLogContains;return u.lua_pushboolean(o,a?!!a(L(o,1)):!1),1}),u.lua_setglobal(n,_("query")),this.runChunk(n,t,"autotest-assert"),!0}destroy(){for(let t of this.roots.slice())this.destroyControl(t);for(let t of this.mountedScripts.slice())this.unmountScript(t);this.lifecyclePhase="idle",this.mountedScripts=[],this.luaFunctions.clear();for(let t of[...this.luaStates])this.closeTrackedLuaState(t);this.L=null}};function Bt(e){let t=new bi(e);return t.boot(),t}var it=Object.freeze(Array.from({length:8},(e,t)=>`Player${t+1}`)),mn=Object.freeze(Array.from({length:8},(e,t)=>`Avatar${t+1}`)),yo=Object.freeze(["Level","PlayerSelf","AvatarSelf"]);var hn=Object.freeze([...yo,...it,...mn]),bo=Object.freeze(["PlayerSelf","AllPlayers",...it]),Ks=Object.freeze(["Level","PlayerSelf",...it]),uo=Object.freeze(["Int","Float","String","Bool","Vector3","Entity","Guid","PrefabId","ConfigId","IntList","FloatList","StringList","BoolList","Vector3List","EntityList","GuidList","PrefabIdList","ConfigIdList","Dict","Struct"]),Ls=-2147483648,Ws=2147483647,qs=new Set(["set-custom-variable","get-custom-variable","custom-variable-changed","\u8BBE\u7F6E\u81EA\u5B9A\u4E49\u53D8\u91CF","\u83B7\u53D6\u81EA\u5B9A\u4E49\u53D8\u91CF","\u81EA\u5B9A\u4E49\u53D8\u91CF\u53D8\u5316\u65F6","send-signal","listen-signal","send-client-script-signal","\u53D1\u9001\u4FE1\u53F7","\u76D1\u542C\u4FE1\u53F7","\u53D1\u9001\u5BA2\u6237\u7AEF\u811A\u672C\u4FE1\u53F7","setVar","getVar","signal","var"]);function Ut(e){return`Player${Number(e)}`}function vi(e){return`Avatar${Number(e)}`}function co(e){let t=String(e||"").match(/^(?:Player|Avatar)([1-8])$/);return t?Number(t[1]):0}function tt(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 Pe(e,t=8){let i=tt(t);if(e==null||e==="")return 1;let n=Number(e);if(!Number.isInteger(n)||n<1||n>i)throw new Error(`playerIndex must be an integer 1-${i}`);return n}function fo(){let e={Level:Object.create(null),PlayerSelf:Object.create(null),AvatarSelf:Object.create(null)};for(let t of it)e[t]=Object.create(null);for(let t of mn)e[t]=Object.create(null);return e}function vo(e){let t=String(e||"");if(!hn.includes(t))throw new Error(`unknown CustomVariableEntityType: ${e}`);return t}function js(e,t){let i=vo(e);if(!Ks.includes(i))throw new Error(`${t}.entityType must be Level, PlayerSelf, or Player1-8`);return i}function Ht(e){let t=String(e??"");if(!t)throw new Error("custom variable name is required");return t}function Si(e){let t=String(e??"");if(!t)throw new Error("signal name is required");return t}function pn(e){let t=String(e||"PlayerSelf");if(!bo.includes(t))throw new Error(`unsupported client signal target: ${e}. use PlayerSelf, AllPlayers, or Player1-8`);return t}function Xt(e){if(e==null)return"";if(typeof e=="boolean")return"Bool";if(typeof e=="string")return"String";if(typeof e=="number")return Number.isInteger(e)?"Int":"Float";if(Array.isArray(e)){if(e.length===0)return"IntList";let t=Xt(e[0]);return t&&!t.endsWith("List")&&t!=="Dict"&&t!=="Struct"?`${t}List`:"IntList"}return e&&typeof e=="object"?"x"in e||"y"in e||"z"in e?"Vector3":"Dict":""}function ye(e){return e===void 0?null:JSON.parse(JSON.stringify(e))}function ho(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 po(e){return Array.isArray(e)?e.map(t=>t&&typeof t=="object"&&Object.prototype.hasOwnProperty.call(t,"value")&&"type"in t?{type:String(t.type||""),value:t.value}:{type:Xt(t),value:t}):[]}function Js(e){return String(e?.kind||e?.type||e?.name||e?.id||"")}function wi(e){return e!==null&&typeof e=="object"&&!Array.isArray(e)}function So(e,t){if(!wi(e)||!Object.prototype.hasOwnProperty.call(e,"fromSignalParam"))return null;if(Object.keys(e).some(n=>n!=="fromSignalParam"))throw new Error(`${t}.fromSignalParam cannot be combined with literal fields`);let i=Number(e.fromSignalParam);if(!Number.isSafeInteger(i)||i<0)throw new Error(`${t}.fromSignalParam must be a non-negative integer`);return{fromSignalParam:i}}function mo(e,t){return So(e,t)||ye(e)}function Zs(e,t,i){if(!wi(e))throw new Error(`serverLogic.rules[${t}].actions[${i}] must be an object`);let n=String(e.kind||e.type||""),r=`serverLogic.rules[${t}].actions[${i}]`;if(n==="setCustomVariable"){let o=js(e.entityType,r);if(!Object.prototype.hasOwnProperty.call(e,"value"))throw new Error(`${r}.value is required`);return{kind:n,entityType:o,name:Ht(e.name),value:mo(e.value,`${r}.value`),...e.variableType?{variableType:String(e.variableType)}:{}}}if(n==="sendClientScriptSignal"){if(!Array.isArray(e.params))throw new Error(`${r}.params must be an array`);return{kind:n,target:pn(e.target),signalName:Si(e.signalName),params:e.params.map((o,a)=>mo(o,`${r}.params[${a}]`))}}throw new Error(`${r}.kind must be setCustomVariable or sendClientScriptSignal`)}function wt(e){if(e==null)return{version:1,rules:[]};if(!wi(e))throw new Error("serverLogic must be an object");let t=e.rules===void 0?[]:e.rules;if(!Array.isArray(t))throw new Error("serverLogic.rules must be an array");return{version:1,rules:t.map((i,n)=>{if(!wi(i))throw new Error(`serverLogic.rules[${n}] must be an object`);if(!Array.isArray(i.actions)||i.actions.length===0)throw new Error(`serverLogic.rules[${n}].actions must be a non-empty array`);return{id:String(i.id||`signal-${n+1}`),signalName:Si(i.signalName),actions:i.actions.map((r,o)=>Zs(r,n,o))}})}}function go(e,t,{typed:i=!1}={}){let n=So(e,"server logic value");if(n){let r=i?t.params:t.values;if(n.fromSignalParam>=r.length)throw new Error(`signal ${t.name} has no parameter at index ${n.fromSignalParam}`);return ye(r[n.fromSignalParam])}return ye(e)}function Qs(e){return e==="Level"?"Level":it.includes(e)?"PlayerSelf":mn.includes(e)?"AvatarSelf":e}function wo(e={}){let t=fo(),i=fo(),n=[],r=[],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 h=wt(e.logic),p=tt(e.playerCount),m=Pe(e.viewPlayerIndex,p);function g(b,x){a.push({source:"server",level:String(b||"engine"),text:String(x),time:l})}function I(b){let x=s[b||m],v=Number(x?.clock?.time);Number.isFinite(v)&&(l=v)}function k(b,x,v,C){t[b][x]=v,i[b][x]={type:C||Xt(v)||i[b][x]?.type||""}}function E(b,x,v){return typeof v!="number"||!Number.isInteger(v)?{ok:!0,value:v}:v>=Ls&&v<=Ws?{ok:!0,value:v}:(g("engine",`Int custom variable ${b}.${x} out of range ${v}; keeping previous legal value`),{ok:!1,value:t[b][x]})}function $(b,x){let v=vo(b),C=x||m;return v==="PlayerSelf"?Ut(C):v==="AvatarSelf"?vi(C):v}function F(b,x){let v=Qs(b);if(b==="Level"){for(let S=1;S<=p;S+=1){let P=s[S];P&&typeof P.notifyVarHandlers=="function"&&P.notifyVarHandlers("Level",x)}return}let C=co(b);if(!C)return;let M=s[C];M&&typeof M.notifyVarHandlers=="function"&&M.notifyVarHandlers(v,x)}function U(b,x){let v=pn(b);return v==="AllPlayers"?Array.from({length:p},(C,M)=>M+1):v==="PlayerSelf"?[x||m]:[co(v)]}function W(b){for(let x of h.rules)if(x.signalName===b.name)for(let v of x.actions){if(v.kind==="setCustomVariable"){let C=go(v.value,b);O.setVar(v.entityType,v.name,C,{type:v.variableType,playerIndex:b.playerIndex}),g("info",`logic ${x.id}: set ${v.entityType}.${v.name}`);continue}if(v.kind==="sendClientScriptSignal"){let C=v.params.map(M=>go(M,b,{typed:!0}));O.sendToClient(v.signalName,C,{target:v.target,playerIndex:b.playerIndex}),g("info",`logic ${x.id}: sent ${v.signalName} to ${v.target}`)}}}function Z(b,x){b&&(b.serverBridge={getVar:(v,C)=>O.getVar(v,C,{playerIndex:x}),setVar:(v,C,M)=>O.setVar(v,C,M,{playerIndex:x}),receiveFromClient:(v,C)=>O.receiveFromClient(v,C,{playerIndex:x})})}function q(b){b&&(b.serverBridge=null)}let O={ENTITY_TYPES:yo,ALL_ENTITY_TYPES:hn,CLIENT_SIGNAL_TARGETS:bo,get clock(){return l},get playerCount(){return p},get viewPlayerIndex(){return m},setClock(b){l=Number(b)||0},setPlayerCount(b){return p=tt(b),m>p&&(m=p),p},setViewPlayerIndex(b){return m=Pe(b,p),m},log(b,x){g(b,x)},defineVar(b,x,v={},{playerIndex:C}={}){let M=$(b,C),S=Ht(x);if(Object.prototype.hasOwnProperty.call(t[M],S))throw new Error(`custom variable already exists: ${M}.${S}`);let P=v.type?String(v.type):Xt(v.value??v.defaultValue);if(P&&!uo.includes(P))throw new Error(`unsupported custom variable type: ${P}`);let z=v.value!==void 0?v.value:v.defaultValue!==void 0?v.defaultValue:null;return k(M,S,z,P),O.getVar(M,S)},getVar(b,x,{playerIndex:v}={}){let C=$(b,v),M=Ht(x);if(!Object.prototype.hasOwnProperty.call(t[C],M)){g("engine",`GetGlobalCustomVariableValue missing ${C}.${M}; returning nil (simulator policy)`);return}return t[C][M]},setVar(b,x,v,{notify:C=!0,type:M,playerIndex:S}={}){let P=$(b,S),z=Ht(x),G=M||i[P][z]?.type||Xt(v);if(G&&!uo.includes(G)&&G!=="")throw new Error(`unsupported custom variable type: ${G}`);let ie=v;if(!((G==="Int"||G===""&&typeof v=="number"&&Number.isInteger(v))&&(ie=E(P,z,v).value,ie===void 0)))return k(P,z,ie,G),C&&F(P,z),ie},listVars(b){let x=b?[$(b)]:["Level",...Array.from({length:p},(C,M)=>Ut(M+1)),...Array.from({length:p},(C,M)=>vi(M+1))],v=[];for(let C of x)for(let M of Object.keys(t[C]))v.push({entityType:C,name:M,type:i[C][M]?.type||"",value:ye(t[C][M])});return v},receiveFromClient(b,x=[],{playerIndex:v}={}){let C=Pe(v||m,p);I(C);let M=Si(b),S={id:c++,direction:"inbound",name:M,params:po(x),values:ho(x),time:l,playerIndex:C,from:Ut(C)};return n.push(S),W(S),S},sendToClient(b,x=[],{target:v="PlayerSelf",playerIndex:C}={}){let M=Si(b),S=pn(v),z=U(S,C||m),G={id:c++,direction:"outbound",name:M,params:po(x),values:ho(x),time:l,target:S,players:z,deliverAt:l+f/1e3,delivered:!1};return r.push(G),f===0?O.deliver(G):o.push(G),G},getLogic(){return ye(h)},setLogic(b){return h=wt(b),O.getLogic()},deliver(b){if(!b||b.delivered)return;b.delivered=!0;let x=Array.isArray(b.players)&&b.players.length?b.players:U(b.target);for(let v of x){let C=s[v];C&&typeof C.sendClientSignal=="function"&&C.sendClientSignal(b.name,b.values)}},flush(b){b!==void 0&&(l=Number(b)||0);let x=[];for(let v=o.length-1;v>=0;v-=1)o[v].deliverAt<=l&&x.push(o.splice(v,1)[0]);x.sort((v,C)=>v.id-C.id);for(let v of x)O.deliver(v);return x},inbound(){return n.slice()},outbound(){return r.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 x of b.nodes||[]){let v=Js(x);if(!qs.has(v))throw new Error(`unsupported server node: ${v||JSON.stringify(x)}. v1 only supports custom variables and signals`)}if(b.onlineLatencyMs!==void 0){let x=Number(b.onlineLatencyMs);if(!Number.isFinite(x)||x<0)throw new Error("onlineLatencyMs must be a non-negative finite number");f=x}b.playerCount!==void 0&&O.setPlayerCount(b.playerCount),b.viewPlayerIndex!==void 0&&O.setViewPlayerIndex(b.viewPlayerIndex),(b.logic!==void 0||b.serverLogic!==void 0)&&O.setLogic(b.logic??b.serverLogic);for(let x of b.vars||[]){let v=$(x.entityType),C=Ht(x.name);Object.prototype.hasOwnProperty.call(t[v],C)?O.setVar(v,C,x.value??x.defaultValue,{notify:!1,type:x.type}):O.defineVar(v,C,x)}}},attachRuntime(b,{playerIndex:x=1}={}){let v=Pe(x,8);return s[v]&&s[v]!==b&&q(s[v]),s[v]=b||null,Z(s[v],v),O},attachRuntimes(b){O.detachRuntime();let x=Array.isArray(b)?b:[];for(let v=0;v<x.length&&v<8;v+=1)s[v+1]=x[v]||null,Z(s[v+1],v+1);return O},detachRuntime(){for(let b=1;b<=8;b+=1)q(s[b]),s[b]=null},snapshot(){let b=Ut(m),x=vi(m),v={Level:{},PlayerSelf:{},AvatarSelf:{}};for(let C of Object.keys(t.Level))v.Level[C]={type:i.Level[C]?.type||"",value:ye(t.Level[C])};for(let C of Object.keys(t[b]))v.PlayerSelf[C]={type:i[b][C]?.type||"",value:ye(t[b][C])};for(let C of Object.keys(t[x]))v.AvatarSelf[C]={type:i[x][C]?.type||"",value:ye(t[x][C])};for(let C=1;C<=p;C+=1){let M=Ut(C),S=vi(C);v[M]={},v[S]={};for(let P of Object.keys(t[M]))v[M][P]={type:i[M][P]?.type||"",value:ye(t[M][P])};for(let P of Object.keys(t[S]))v[S][P]={type:i[S][P]?.type||"",value:ye(t[S][P])}}return{clock:l,onlineLatencyMs:f,playerCount:p,viewPlayerIndex:m,logic:O.getLogic(),vars:v,inbound:n.map(C=>({id:C.id,name:C.name,params:ye(C.params),values:ye(C.values),time:C.time,playerIndex:C.playerIndex,from:C.from})),outbound:r.map(C=>({id:C.id,name:C.name,params:ye(C.params),values:ye(C.values),time:C.time,target:C.target,players:Array.isArray(C.players)?C.players.slice():[],deliverAt:C.deliverAt,delivered:!!C.delivered})),logs:a.map(C=>({source:"server",level:C.level,text:C.text,time:C.time}))}},reset(){for(let b of hn){for(let x of Object.keys(t[b]))delete t[b][x];for(let x of Object.keys(i[b]))delete i[b][x]}n.length=0,r.length=0,o.length=0,a.length=0,c=1,l=0},destroy(){O.detachRuntime(),O.reset()}};e.config&&O.loadConfig(e.config);for(let b of e.vars||[])O.defineVar(b.entityType,b.name,b);return O}var el={container:"container",textbox:"textbox",image:"image",button:"button",cursor:"cursor",grid:"grid",reference:"reference",textwindow:"textwindow",keyhint:"keyhint",animation:"animation",fullscreen:"fullscreen"};function gn(e,t,i=null){let n=ze(e.transformByPlatform,t),r={authoringId:e.id,kind:el[e.kind]||"container",name:e.name,prefabIndex:e.guid||0,active:e.active!==!1,visible:e.visible!==!1,canControllerFocus:e.canControllerFocus===!0,anchoredPositionX:n.offset.x,anchoredPositionY:n.offset.y,sizeDeltaX:n.size.x,sizeDeltaY:n.size.y,anchorMinX:n.anchorMin.x,anchorMinY:n.anchorMin.y,anchorMaxX:n.anchorMax.x,anchorMaxY:n.anchorMax.y,pivotX:n.pivot.x,pivotY:n.pivot.y,localScaleX:n.scale.x,localScaleY:n.scale.y,localScaleZ:n.scale.z,localRotationX:n.rotation.x,localRotationY:n.rotation.y,localRotationZ:n.rotation.z,children:(e.children||[]).map(a=>gn(a,t,i))},o=i?.get(e.id);return o?.length&&(r.scripts=o.map(a=>{let s=Number(a.guid);return{path:a.path||a.id,source:a.source||"",...Number.isSafeInteger(s)&&s>0?{scriptMappingId:s}:{}}})),e.kind==="container"&&(r.isolateNavigation=e.isolateNavigation===!0,r.disableKeyEventPassthrough=e.disableKeyEventPassthrough===!0,r.disableCursorEventPassthrough=e.disableCursorEventPassthrough===!0,r.showCursor=e.showCursor===!0),(e.kind==="textbox"||e.kind==="textwindow")&&(r.text=e.text??"",r.fontSize=e.fontSize,r.adaptiveFontSize=e.adaptiveFontSize===!0,r.minimumFontSize=e.minimumFontSize,r.fontColor=e.fontColor,r.bgColor=e.bgColor,r.enableOutline=e.enableOutline!==!1,r.outlineColor=e.outlineColor,r.horizontalAlignment=e.horizontalAlignment||"Left",r.verticalAlignment=e.verticalAlignment||"Top",e.kind==="textwindow"&&(r.interactable=e.interactable!==!1,r.showScrollBar=e.showScrollBar!==!1)),e.kind==="image"&&(r.imageSource=e.imageSource,r.imageId=e.imageId??0,r.imageColor=e.imageColor,r.raycastTarget=e.raycastTarget===!0,r.enableMask=e.enableMask===!0,r.enableSoftEdge=e.enableSoftEdge===!0,r.softEdgeMode=e.softEdgeMode,r.softEdgeWidthX=e.softEdgeWidthX,r.softEdgeWidthY=e.softEdgeWidthY,r.horizontalSoftRange=e.horizontalSoftRange,r.verticalSoftRange=e.verticalSoftRange,r.enableFill=e.enableFill===!0,r.fillType=e.enableFill?e.fillType:"Unused",r.fillHorizontalType=e.fillHorizontalType,r.fillVerticalType=e.fillVerticalType,r.fillRadial90Type=e.fillRadial90Type,r.fillRadialType=e.fillRadialType,r.fillAmount=e.fillAmount,r.reverseMaskArea=e.reverseMaskArea===!0),e.kind==="button"&&(r.raycastTarget=e.raycastTarget!==!1,r.interactable=e.interactable!==!1,r.clickAudioId=e.clickAudioId,r.unavailableChildId=e.unavailableChildId??null,r.hoverChildId=e.hoverChildId??null,r.pressedChildId=e.pressedChildId??null,r.selectedChildId=e.selectedChildId??null),e.kind==="cursor"&&(r.raycastTarget=e.raycastTarget!==!1),e.kind==="reference"&&(r.referencedPrefabIndex=e.referencedPrefabId),e.kind==="grid"&&(r.itemPrefabIndex=e.itemPrefabId,r.raycastTarget=e.raycastTarget!==!1,r.interactable=e.interactable!==!1,r.showScrollBar=e.showScrollBar!==!1,r.scrollDirection=e.scrollDirection,r.layoutConstraint=e.layoutConstraint,r.layoutConstraintFixedCount=e.layoutConstraintFixedCount,r.cellSizeX=e.cellSizeX,r.cellSizeY=e.cellSizeY,r.spacingX=e.spacingX,r.spacingY=e.spacingY,r.padding1X=e.padding1X,r.padding1Y=e.padding1Y,r.padding2X=e.padding2X,r.padding2Y=e.padding2Y,r.previewCount=e.previewCount),e.kind==="keyhint"&&(r.keyboardKeyCode=e.keyboardKeyCode,r.controllerKeyCode=e.controllerKeyCode),(e.kind==="animation"||e.kind==="fullscreen")&&(r.raycastTarget=!1,r.animationId=e.animationId,r.playSoundEffect=e.playSoundEffect,e.kind==="animation"&&(r.layer=e.layer)),r}function yn(e,t=[],i=""){let n=i&&K[i]?i:e.canvasId,r=K[n],o=Dt(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=>gn(c,n,a)):[];return{canvasId:n,platform:r.platform,device:r.luaDevice,canvasWidth:r.width,canvasHeight:r.height,root:gn(o,n,a),templates:s}}var Ii="qxqy-autotest";var nt=.03333333333333333,tl=new Set(["pointer","key","click","pause","resume","serverSet","serverSend","view"]),il=new Set(["log","control","var","signal","tree","lua"]);function Kt(e,t){let i=Number(e);if(!Number.isFinite(i))throw new Error(`${t} must be a finite number`);return i}function bn(e){return JSON.parse(JSON.stringify(e??null))}function Ci(e,t){if(!e||typeof e!="object")throw new Error(`events[${t}] must be an object`);let i=String(e.kind||e.do||"");if(!tl.has(i))throw new Error(`unsupported event kind: ${i||"(empty)"}`);let n=e.payload&&typeof e.payload=="object"?{...e.payload}:{};if(i==="pointer")!n.type&&e.type&&(n.type=e.type),n.x===void 0&&(n.x=e.x),n.y===void 0&&(n.y=e.y),n.x=Kt(n.x,"pointer.x"),n.y=Kt(n.y,"pointer.y"),n.type=String(n.type||"click");else if(i==="key"){if(n.typeName=String(n.typeName||n.key||e.typeName||e.key||""),!n.typeName)throw new Error("key event requires typeName")}else if(i==="click"){if(n.name=String(n.name||e.name||""),!n.name)throw new Error("click event requires control name")}else if(i==="serverSet"){if(n.entityType=String(n.entityType||e.entityType||""),n.name=String(n.name||e.name||""),n.value===void 0&&(n.value=e.value),n.value===void 0&&(n.value=null),!n.entityType||!n.name)throw new Error("serverSet requires entityType and name")}else if(i==="serverSend"){if(n.name=String(n.name||e.name||""),n.params=Array.isArray(n.params)?n.params:Array.isArray(e.params)?e.params:[],n.target=String(n.target||e.target||"PlayerSelf"),!n.name)throw new Error("serverSend requires signal name")}else if(i==="view"&&(n.playerIndex=Number(n.playerIndex||n.viewPlayerIndex||e.playerIndex||e.viewPlayerIndex||0),!Number.isInteger(n.playerIndex)||n.playerIndex<1))throw new Error("view event requires playerIndex 1-8");return{t:Kt(e.t??0,"event.t"),source:String(e.source||"user"),kind:i,payload:n}}function vn(e,t){if(!e||typeof e!="object")throw new Error(`asserts[${t}] must be an object`);let i=String(e.kind||(e.check?"log":""));if(!il.has(i))throw new Error(`unsupported assert kind: ${i||"(empty)"}`);let n={kind:i};if(e.at!==void 0&&(n.at=Kt(e.at,"assert.at")),i==="log"){if(n.contains=String(e.contains||e.check||e.text||""),n.source=e.source==="server"?"server":"client",e.level&&(n.level=String(e.level)),!n.contains)throw new Error("log assert requires contains")}else if(i==="control"){if(n.id=e.id?String(e.id):"",n.name=e.name?String(e.name):"",n.field=String(e.field||""),!n.field)throw new Error("control assert requires field");if(!n.id&&!n.name)throw new Error("control assert requires id or name");if(!Object.prototype.hasOwnProperty.call(e,"equals"))throw new Error("control assert requires equals");n.equals=bn(e.equals)}else if(i==="var"){if(n.entityType=String(e.entityType||""),n.name=String(e.name||""),!n.entityType||!n.name)throw new Error("var assert requires entityType and name");if(!Object.prototype.hasOwnProperty.call(e,"equals"))throw new Error("var assert requires equals");n.equals=bn(e.equals)}else if(i==="signal"){if(n.direction=e.direction==="outbound"?"outbound":"inbound",n.name=String(e.name||""),!n.name)throw new Error("signal assert requires name");e.values!==void 0&&(n.values=bn(e.values))}else if(i==="tree"){if(n.name=String(e.name||""),n.exists=e.exists!==!1,!n.name)throw new Error("tree assert requires name")}else if(i==="lua"&&(n.source=String(e.source||""),!n.source.trim()))throw new Error("lua assert requires source");return n}function Io(e){let t=0,i=[],n=[];for(let r of e){if(!r||typeof r!="object")throw new Error("queue step must be an object");if(r.do!=="start"){if(r.do==="step"){t+=Kt(r.dt??nt,"step.dt");continue}if(r.do==="pointer"||r.do==="key"||r.do==="click"||r.do==="pause"||r.do==="resume"||r.do==="serverSet"||r.do==="serverSend"||r.do==="view"){i.push(Ci({...r,kind:r.do,t},i.length));continue}if(r.assert||r.check||r.kind){n.push(vn({...r.assert||r,at:r.at??t},n.length));continue}throw new Error(`unsupported queue step: ${JSON.stringify(r)}`)}}return{events:i,asserts:n,dt:nt}}function Lt(e){if(Array.isArray(e)){let n=Io(e);return{format:Ii,version:1,name:"",dt:n.dt,events:n.events,asserts:n.asserts}}if(!e||typeof e!="object")throw new Error("autotest case must be an object or step array");if(Array.isArray(e.queue)||Array.isArray(e.steps)){let n=Io(e.queue||e.steps);return{format:Ii,version:1,name:String(e.name||""),dt:Number(e.dt)>0?Number(e.dt):n.dt,events:n.events,asserts:n.asserts}}let t=(e.events||[]).map((n,r)=>Ci(n,r)),i=(e.asserts||[]).map((n,r)=>vn(n,r));return t.sort((n,r)=>n.t-r.t||0),{format:Ii,version:1,name:String(e.name||""),dt:Number(e.dt)>0?Number(e.dt):nt,playerCount:Number(e.playerCount)>0?Number(e.playerCount):1,events:t,asserts:i}}function Co(e,t={}){let i=(e||[]).map((n,r)=>Ci(n,r));return{format:Ii,version:1,name:String(t.name||""),dt:Number(t.dt)>0?Number(t.dt):nt,playerCount:Number(t.playerCount)>0?Number(t.playerCount):1,events:i,asserts:(t.asserts||[]).map((n,r)=>vn(n,r))}}function ko(e,t,i){if(!e)return null;let n=Ci({...t,t:t.t??i??0},e.events.length);return e.events.push(n),n}var nl=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 Cn(e){let t=de({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),i=new Map;function n(r,o,a){let s=Ae(o,r);s.activeInHierarchy=a&&r.active!==!1,i.set(r.Id,s);let c=s.activeInHierarchy;for(let l of r.children)n(l,s,c)}for(let r of e.runtime.roots)n(r,t,!0);return i}function rl(e,t=Cn(e)){let i=new Map;function n(r,o){let a=t.get(r.Id);if(!a)return;let s=$t(o,a,r);i.set(r.Id,s);for(let c of r.children)n(c,s)}for(let r of e.runtime.roots)n(r,gt());return i}function Eo(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"?pt[e.imageId]||"missing":null,imageColor:e.kind==="image"?e.imageColor:null,enableMask:e.kind==="image"?e.enableMask===!0:null,enableSoftEdge:e.kind==="image"?e.enableSoftEdge===!0:null,softEdgeMode:e.kind==="image"?e.softEdgeMode:null,softEdgeWidthX:e.kind==="image"?e.softEdgeWidthX:null,softEdgeWidthY:e.kind==="image"?e.softEdgeWidthY:null,horizontalSoftRange:e.kind==="image"?e.horizontalSoftRange:null,verticalSoftRange:e.kind==="image"?e.verticalSoftRange:null,enableFill:e.kind==="image"?e.enableFill===!0:null,fillType:e.kind==="image"?e.fillType:null,fillHorizontalType:e.kind==="image"?e.fillHorizontalType:null,fillVerticalType:e.kind==="image"?e.fillVerticalType:null,fillRadial90Type:e.kind==="image"?e.fillRadial90Type:null,fillRadialType:e.kind==="image"?e.fillRadialType:null,reverseMaskArea:e.kind==="image"?e.reverseMaskArea===!0:null,fillAmount:e.kind==="image"?e.fillAmount:null,box:i?{left:i.left,bottom:i.bottom,width:i.width,height:i.height}:null,children:e.children.map(n=>Eo(n,t))}}function ol(){return{pointerDownControl:null,pointerDownPosition:null,pointerLastPosition:null,pointerDragging:!1,pointerHoverControl:null,hoveredControl:null,selectedControl:null,stateRestores:new Map,viewCache:null}}function al(e,t,i){let n=Bt({canvasWidth:e.canvasWidth,canvasHeight:e.canvasHeight,device:e.device});for(let r of[...e.templates||[],...t?.templates||[]])Number.isSafeInteger(r.prefabIndex)&&r.prefabIndex>0&&n.registerTemplate(r.prefabIndex,r);for(let r of i){let o=r.path||r.id,a=r.source||"";o&&a&&n.registerScriptFile(o,a)}return n}var sl=["pointerDownControl","pointerDownPosition","pointerLastPosition","pointerDragging","pointerHoverControl","hoveredControl","selectedControl","stateRestores","viewCache"];function ll(e){Object.defineProperty(e,"runtime",{configurable:!0,enumerable:!0,get(){return e.runtimes[e.viewPlayerIndex-1]}});for(let t of sl)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 Ao(e,{templatesProject:t=null,scripts:i=[],sceneScripts:n=null,templateScripts:r=null,serverConfig:o=null,canvasId:a="",playerCount:s=1,viewPlayerIndex:c=1}={}){let l=n||i,f=r||i,h=yn(e,l,a),p=t?yn(t,f,a):null,m=tt(s),g=Pe(c,m),I=wo({playerCount:m,viewPlayerIndex:g});o&&I.loadConfig({...o,playerCount:m,viewPlayerIndex:g});let k=[];for(let F=0;F<m;F+=1)k.push(al(h,p,i));I.attachRuntimes(k);for(let F of k)F.addRoot(h.root);let E={runtimes:k,views:k.map(()=>ol()),playerCount:m,viewPlayerIndex:g,server:I,compiled:h,mountError:k.find(F=>F.mountErrors[0])?.mountErrors[0]||null,debugPaused:!1,history:{events:[]},recording:!0};ll(E);let $=E.viewPlayerIndex;for(let F=1;F<=m;F+=1)E.viewPlayerIndex=F,Sl(E);return E.viewPlayerIndex=$,E}function kn(e,t){if(!e)throw new Error("play session has not started");let i=Pe(t,e.playerCount);return i===e.viewPlayerIndex||(Ue(e,{kind:"view",payload:{playerIndex:i}}),e.viewPlayerIndex=i,e.viewCache=null,e.server&&e.server.setViewPlayerIndex(i)),i}function Ue(e,t){!e?.recording||!e.history||ko(e.history,{...t,source:t.source||"user"},e.runtime.clock.time)}function ul(e){return e?.history?.events||[]}var xn=new Set(["image","textbox","textwindow","button"]);function cl(e,t){let i=Ke(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 rt(e){return typeof e=="string"?e:e?.Name}function _o(e){return{fillType:rt(e.fillType),fillHorizontalType:rt(e.fillHorizontalType),fillVerticalType:rt(e.fillVerticalType),fillAmount:e.fillAmount}}function fl(e,t,i){let n=Math.abs(t.width*i.scaleX),r=Math.abs(t.height*i.scaleY),o={id:e.Id,kind:e.kind,name:e.name,left:i.centerX-n/2,bottom:i.centerY-r/2,width:n,height:r,sourceWidth:t.width,sourceHeight:t.height,rotationZ:i.rotationZ,matrix:i.matrix,pressed:e.pressed===!0};return e.kind==="image"&&(o.primitive=pt[e.imageId]||"missing",o.imageColor=e.imageColor,o.imageId=e.imageId,Object.assign(o,_o(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=rt(e.horizontalAlignment),o.verticalAlignment=rt(e.verticalAlignment)),o}function dl(e,t=Cn(e)){let i=[],n=rl(e,t);function r(o){let a=t.get(o.Id);if(!a||o.visible===!1||!a.activeInHierarchy)return;let s=n.get(o.Id);if(!s)return;let c=cl(a,s);xn.has(o.kind)&&i.push(fl(o,a,c));let l=o.children||[];for(let f=l.length-1;f>=0;f-=1)r(l[f])}for(let o of e.runtime.roots)r(o);return i}function hl(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=pt[e.imageId]||"missing",i.imageColor=e.imageColor,i.imageId=e.imageId,Object.assign(i,_o(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=rt(e.horizontalAlignment),i.verticalAlignment=rt(e.verticalAlignment)),i}function pl(e,t,i){let n=Di(e,t),r=Ke(n,e.centerX,e.centerY);return{a:n.a,b:n.b,c:n.c,d:n.d,tx:r.x-(i?i.centerX:0),ty:r.y-(i?i.centerY:0)}}function Po(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 To(e,t,i,n,r,o){return{id:e.Id,parent:t,z:r,group:o>=16,matrix:pl(n,e,i),...hl(e,n)}}function ml(e){let t=de({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),i=new Set,n=new Map,r=new Map;function o(c,l,f){let h=Ae(l,c);if(h.activeInHierarchy=f&&c.active!==!1,r.set(c.Id,h),c.visible===!1||!h.activeInHierarchy)return!1;let p=c.children||[],m=xn.has(c.kind),g=0;for(let I=0;I<p.length;I+=1)o(p[I],h,h.activeInHierarchy)&&(m=!0,g+=1);return m?(i.add(c.Id),n.set(c.Id,g),!0):!1}function a(c,l,f,h){if(!i.has(c.Id))return;let p=r.get(c.Id);s.push(To(c,l,f,p,h,n.get(c.Id)||0));let m=c.children||[];for(let g=0;g<m.length;g+=1)a(m[g],c.Id,p,g)}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:n}}function In(e){let t=e._playChildDirty===!0||e._playDeepDirty===!0;if(e._playDirty=!1,e._playChildDirty=!1,e._playDeepDirty=!1,!t)return;let i=e.children;for(let n=0;n<i.length;n+=1)In(i[n])}function gl(e,t){let i=de({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),n=[],r=[],o=t.count,a=e.runtime._playRemoved||[];for(let l=0;l<a.length;l+=1){let f=a[l];t.fingerprints.has(f)&&(r.push(f),t.fingerprints.delete(f),t.childCounts.delete(f),o-=1)}e.runtime._playRemoved=[];function s(l){t.fingerprints.has(l.Id)&&(r.push(l.Id),t.fingerprints.delete(l.Id),t.childCounts.delete(l.Id),o-=1);let f=l.children;for(let h=0;h<f.length;h+=1)s(f[h])}function c(l,f,h,p,m,g){let I=g||l._playDeepDirty===!0,k=I||l._playDirty===!0,E=I||l._playChildDirty===!0;if(!k&&!E)return;if(!(m&&l.active!==!1)||l.visible===!1){s(l);return}let F=Ae(f,l),U=t.childCounts.get(l.Id)||0;if(E){U=0;let x=l.children;for(let v=0;v<x.length;v+=1)c(x[v],F,l.Id,v,!0,I),t.fingerprints.has(x[v].Id)&&(U+=1)}if(!(xn.has(l.kind)||U>0)){t.fingerprints.has(l.Id)&&(r.push(l.Id),t.fingerprints.delete(l.Id),t.childCounts.delete(l.Id),o-=1);return}let Z=t.childCounts.get(l.Id);t.childCounts.set(l.Id,U);let q=U>=16!=(Z||0)>=16;if(!k&&!q&&t.fingerprints.has(l.Id))return;let O=To(l,h,f===i?null:f,F,p,U),b=Po(O);t.fingerprints.get(O.id)!==b&&(t.fingerprints.has(O.id)||(o+=1),t.fingerprints.set(O.id,b),n.push(O))}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:n,removed:r,count:o}}function yl(e,t){let i=e.viewCache||(e.viewCache={rev:0,fingerprints:new Map,childCounts:new Map,count:0}),n=Number(t);if(!(Number.isFinite(n)&&n===i.rev&&i.fingerprints.size>0)){let{nodes:c,childCounts:l}=ml(e);i.rev+=1,i.fingerprints=new Map(c.map(f=>[f.id,Po(f)])),i.childCounts=l,i.count=c.length;for(let f of e.runtime.roots)In(f);return{format:"tree-v1",revision:i.rev,reset:!0,count:c.length,nodes:c}}let{changed:o,removed:a,count:s}=gl(e,i);i.rev+=1;for(let c of e.runtime.roots)In(c);return{format:"tree-v1",revision:i.rev,reset:!1,count:s,changed:o,removed:a}}function En(e,{inspect:t=!1,view:i=!1,paint:n=!1,sceneRev:r,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,h=ul(e),p=e.server?e.server.snapshot():{vars:{},inbound:[],outbound:[],logs:[]};o&&(p.inbound=p.inbound.slice(-100),p.outbound=p.outbound.slice(-100),p.logs=p.logs.slice(-100));let m={canvasId:s.canvasId,platform:s.platform,device:a.device,canvasWidth:c,canvasHeight:l,canvasPresets:nl,playerCount:e.playerCount||1,viewPlayerIndex:e.viewPlayerIndex||1,players:Array.from({length:e.playerCount||1},(g,I)=>({index:I+1,label:`\u73A9\u5BB6${I+1}`,entityType:`Player${I+1}`})),time:a.clock.time,frame:a.clock.frame,paused:!!e.debugPaused,levelTimePaused:!!a.clock.paused,mountError:e.mountError||a.mountErrors[0]||null,logs:f.map(g=>({source:"client",level:g.level,text:g.text,time:g.time})),tree:[],paint:[],scene:null,server:p,history:(o?h.slice(-100):h).map(g=>({t:g.t,source:g.source||"user",kind:g.kind,payload:g.payload||{}}))};if(t||n){let g=Cn(e);t&&(m.tree=a.roots.map(I=>Eo(I,g))),n&&(m.paint=dl(e,g))}return i&&(m.scene=yl(e,r)),mt(m),m}function ki(e,t=1/30){let i=e.runtimes||(e.runtime?[e.runtime]:[]);for(let n of i)n.step(t);e.server&&(e.server.setClock(e.runtime.clock.time),e.server.flush())}function An(e,t){Ue(e,{kind:"key",payload:{typeName:String(t)}}),e.runtime.injectKey(t)}function bl(e,t){let i=null;for(let n of e.runtime.roots)we(n,r=>{!i&&r.name===t&&(i=r)});return i}function _n(e,t){Ue(e,{kind:"click",payload:{name:String(t)}});let i=bl(e,t);i&&Pn(i)&&(i.kind==="button"||i.kind==="cursor")&&i.SimulateCursorClick()}function vl(e,t){return!e||!t?null:e.children.find(i=>i.authoringId===t||i.Id===t)||null}var Ro={unavailable:"unavailableChildId",hover:"hoverChildId",pressed:"pressedChildId",selected:"selectedChildId"};function Mo(e,t){let i=[];for(let[n,r]of Object.entries(Ro)){let o=t[r]?vl(t,t[r]):null;o&&i.push({state:n,child:o})}return i}function Sl(e){for(let t of e.runtime.roots)we(t,i=>{if(i.kind==="button"){for(let{child:n}of Mo(e,i))e.stateRestores.has(n.Id)||e.stateRestores.set(n.Id,{child:n,active:n.active,visible:n.visible}),n.active=!0,n.visible=!1,typeof n.markPlayDirty=="function"&&n.markPlayDirty(!0);qt(e,i)}})}function qt(e,t){if(!t||t.kind!=="button")return;let i=null;t.interactable===!1?i="unavailable":t.pressed===!0?i="pressed":e.hoveredControl===t?i="hover":e.selectedControl===t&&(i="selected");for(let n of Mo(e,t))n.child.active=!0,n.child.visible=n.state===i,typeof n.child.markPlayDirty=="function"&&n.child.markPlayDirty(!0)}function Sn(e){if(!e)return null;let t=e.parent;return t?.kind==="button"&&Object.values(Ro).map(n=>t[n]).filter(Boolean).includes(e.authoringId)?t:e}function Pn(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 No(e){return e.kind==="container"||e.kind==="grid"||e.kind==="textwindow"||e.kind==="reference"||e.kind==="button"}function Oo(e,t){let i=e.Id,n=t.get(i);if(n!==void 0)return n;let r=Pn(e);if(!r&&No(e)){let o=e.children;for(let a=0;a<o.length;a+=1)if(Oo(o[a],t)){r=!0;break}}return t.set(i,r),r}function wn(e,t,i){let n=de({width:e.runtime.canvasWidth,height:e.runtime.canvasHeight}),r=new Map;function o(s,c,l,f){if(!f||s.active===!1||s.visible===!1||!Oo(s,r))return null;let h=Ae(c,s),p=$t(l,h,s),m=ri(p);if(!m)return null;let g=Ke(m,t,i);if(g.x<h.left||g.x>h.right||g.y<h.bottom||g.y>h.top)return null;if(No(s))for(let I=0;I<s.children.length;I+=1){let k=o(s.children[I],h,p,!0);if(k)return k}return Pn(s)?s:null}let a=gt();for(let s=e.runtime.roots.length-1;s>=0;s-=1){let c=o(e.runtime.roots[s],n,a,!0);if(c)return c}return null}function Wt(e,t,i,{dragging:n=!1,press:r=null,previous:o=null}={}){let a=r||{x:t,y:i},s=o||{x:t,y:i};return e.runtime.makeCursorEventData({x:t,y:i,pressX:a.x,pressY:a.y,deltaX:t-s.x,deltaY:i-s.y,dragging:n})}function xo(e,t,i){t.pressed=i,typeof t.markPlayDirty=="function"&&t.markPlayDirty(),qt(e,t)}function jt(e,t,i,n,r={}){let o=Number(i),a=Number(n);if(!Number.isFinite(o)||!Number.isFinite(a))throw new Error("pointer coordinates must be finite");if(e.runtime.cursor.x=o,e.runtime.cursor.y=a,r.silent||Ue(e,{kind:"pointer",payload:{type:t,x:o,y:a}}),t==="move"){let s=e.pointerLastPosition||{x:o,y:a},c=e.pointerHoverControl,l=Sn(wn(e,o,a)),f=Wt(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 h=e.hoveredControl;e.hoveredControl=l?.kind==="button"?l:null,h&&h!==e.hoveredControl&&qt(e,h),e.hoveredControl&&qt(e,e.hoveredControl);let p=e.pointerDownControl;if(p){let m=e.pointerDownPosition||s,g=o!==s.x||a!==s.y;!e.pointerDragging&&g&&(e.runtime.injectCursor(p,"CursorBeginDrag",Wt(e,o,a,{press:m,previous:s,dragging:!1})),e.pointerDragging=!0),e.pointerDragging&&e.runtime.injectCursor(p,"CursorDrag",Wt(e,o,a,{press:m,previous:s,dragging:!0}))}return e.pointerLastPosition={x:o,y:a},l}if(t==="down"){let s=Sn(wn(e,o,a));return e.pointerDownControl=s,e.pointerDownPosition={x:o,y:a},e.pointerLastPosition={x:o,y:a},e.pointerDragging=!1,s&&(xo(e,s,!0),e.runtime.injectCursor(s,"CursorDown",Wt(e,o,a))),s}if(t==="up"){let s=e.pointerDownControl,c=Sn(wn(e,o,a));if(s){let l=Wt(e,o,a,{press:e.pointerDownPosition,previous:e.pointerLastPosition,dragging:e.pointerDragging});if(e.runtime.injectCursor(s,"CursorUp",l),e.pointerDragging)e.runtime.injectCursor(s,"CursorEndDrag",l);else if(c===s){e.runtime.injectCursor(s,"CursorClick",l);let f=e.selectedControl;e.selectedControl=s.kind==="button"?s:null,f&&f!==e.selectedControl&&qt(e,f)}xo(e,s,!1)}return e.pointerDownControl=null,e.pointerDownPosition=null,e.pointerLastPosition={x:o,y:a},e.pointerDragging=!1,c}if(t==="click")return jt(e,"down",o,a,{silent:!0}),jt(e,"up",o,a,{silent:!0});throw new Error(`unknown pointer type ${t}`)}function Tn(e,t,i,n){if(!e?.server)throw new Error("play session has no server");return Ue(e,{kind:"serverSet",payload:{entityType:t,name:i,value:n,playerIndex:e.viewPlayerIndex}}),e.server.setVar(t,i,n,{playerIndex:e.viewPlayerIndex})}function Fo(e,t,i){if(!e?.server)throw new Error("play session has no server");let n=e.server.getVar(t,i,{playerIndex:e.viewPlayerIndex});return n===void 0?null:n}function Rn(e,t,i=[],n="PlayerSelf"){if(!e?.server)throw new Error("play session has no server");return Ue(e,{kind:"serverSend",payload:{name:t,params:i,target:n,playerIndex:e.viewPlayerIndex}}),e.server.sendToClient(t,i,{target:n,playerIndex:e.viewPlayerIndex})}function xi(e){return{snapshot:t=>En(e,t),step:t=>ki(e,t),pointer:(t,i,n)=>jt(e,t,i,n),key:t=>An(e,t),click:t=>_n(e,t),view:t=>kn(e,t),pause:()=>{Ue(e,{kind:"pause",payload:{}}),e.debugPaused=!0},resume:()=>{Ue(e,{kind:"resume",payload:{}}),e.debugPaused=!1},serverSet:(t,i,n)=>Tn(e,t,i,n),serverSend:(t,i,n)=>Rn(e,t,i,n)}}function Mn(e){e?.server&&e.server.destroy();let t=e?.runtimes||(e?.runtime?[e.runtime]:[]);for(let i of t)i.destroy()}function Nn(e,t){return JSON.stringify(e)===JSON.stringify(t)}function $o(e,t){for(let i of e||[])t(i),i.children?.length&&$o(i.children,t)}function On(e,{id:t,name:i}){let n=null;return $o(e,r=>{n||(t&&String(r.id)===String(t)||!t&&i&&r.name===i)&&(n=r)}),n}function wl(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 Il(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=On(e.tree,{name:String(t)});return i?{id:i.id,name:i.name,kind:i.kind,active:i.active,visible:i.visible,pressed:i.pressed,text:i.text,interactable:i.interactable}:null},signals(t){let i=t==="outbound"?"outbound":"inbound";return(e.server?.[i]||[]).map(n=>({name:n.name,values:n.values}))}}}function Cl(e,t){if(e.kind==="log"){let i=e.source==="server"?t.server?.logs||t.serverLogs||[]:t.logs||[];return i.some(r=>e.level&&r.level!==e.level?!1:String(r.text||"").includes(e.contains))?{ok:!0,actual:e.contains}:{ok:!1,actual:i.map(r=>r.text).slice(-8),expected:e.contains}}if(e.kind==="control"){let i=On(t.tree,e);if(!i)return{ok:!1,actual:null,expected:e.equals,message:`control not found: ${e.id||e.name}`};let n=wl(i,e.field);return Nn(n,e.equals)?{ok:!0,actual:n}:{ok:!1,actual:n,expected:e.equals}}if(e.kind==="var"){let i=t.server?.vars?.[e.entityType],r=!i||!Object.prototype.hasOwnProperty.call(i,e.name)?null:i[e.name].value;return Nn(r,e.equals)?{ok:!0,actual:r}:{ok:!1,actual:r,expected:e.equals}}if(e.kind==="signal"){let i=e.direction==="outbound"?t.server?.outbound||[]:t.server?.inbound||[],n=i.find(r=>r.name===e.name&&(e.values===void 0||Nn(r.values,e.values)));return n?{ok:!0,actual:n.values}:{ok:!1,actual:i.map(r=>({name:r.name,values:r.values})),expected:{name:e.name,values:e.values??null}}}if(e.kind==="tree"){let i=!!On(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 kl(e,t){let i=Bt();try{return i.evalQueryScript(e,Il(t)),{ok:!0,actual:!0}}catch(n){return{ok:!1,message:n?.message||String(n)}}finally{i.destroy()}}function Do(e,t){return e.kind==="lua"?kl(e.source,t):Cl(e,t)}function xl(e,t){let i=t>0?t:nt;return Math.round((e+i)*1e9)/1e9}function El(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 Al(e,t){let i=Do(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 zo(e,t){let i=Lt(t),n=i.events.slice().sort((E,$)=>E.t-$.t),r=i.asserts.slice(),o=i.dt||nt,a=n.reduce((E,$)=>Math.max(E,$.t),0),s=r.reduce((E,$)=>Math.max(E,Number($.at||0)),0),c=Math.max(a,s),l=0,f=[],h=0,p=r.some(E=>E.kind==="control"||E.kind==="tree"||E.kind==="lua"),m=e.snapshot({inspect:p}),g=()=>{for(;l<n.length&&n[l].t<=h+1e-9;)El(e,n[l]),l+=1,m=e.snapshot({inspect:p})},I=()=>{for(let E of r)if(!E._done&&Number(E.at||0)<=h+1e-9){let $=Al(E,m);if(f.push($),E._done=!0,!$.ok)return{passed:!1,failedAt:h,frame:m.frame||0,results:f,snapshot:m}}return null};g();let k=I();if(k)return Fn(i,k);for(;h+1e-9<c;){e.step(o),h=xl(h,o),m=e.snapshot({inspect:p}),g();let E=I();if(E)return Fn(i,E)}return Fn(i,{passed:f.every(E=>E.ok),failedAt:null,frame:m.frame||0,results:f,snapshot:m})}function Fn(e,t){return D({format:e.format,name:e.name,passed:t.passed,failedAt:t.failedAt,frame:t.frame,results:t.results,snapshot:{time:t.snapshot?.time??0,frame:t.snapshot?.frame??0,logs:t.snapshot?.logs||[],serverLogs:t.snapshot?.serverLogs||t.snapshot?.server?.logs||[],server:t.snapshot?.server||{vars:{},inbound:[],outbound:[],logs:[]}}})}function $n(e){return Array.isArray(e)?e.slice():[]}var Ml={Level:"\u5173\u5361",PlayerSelf:"\u5F53\u524D\u73A9\u5BB6",AvatarSelf:"\u5F53\u524D\u89D2\u8272",...Object.fromEntries(it.map((e,t)=>[e,`\u73A9\u5BB6${t+1}`])),...Object.fromEntries(Array.from({length:8},(e,t)=>[`Avatar${t+1}`,`\u89D2\u8272${t+1}`]))};function Nl(e,t=1){let i=e?.vars||{},n=[],r=Number(t)>0?Number(t):1,o=["Level","PlayerSelf","AvatarSelf"];if(r>1)for(let s=1;s<=r;s+=1)o.push(`Player${s}`,`Avatar${s}`);let a=new Set;for(let s of o){if(a.has(s)||!i[s])continue;a.add(s);let c=i[s]||{};for(let l of Object.keys(c))n.push(D({entityType:s,entityLabel:Ml[s]||s,name:l,type:c[l]?.type||"",value:c[l]?.value??null}))}return n}var at="qxqy-simulator-save",Ol="qxqy-simulator-scripts",oe="server-control-template",V="client-control-template",Yo={[oe]:"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F",[V]:"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F"};function ot(e){return e===V?"client":"server"}function Fl(e){let t=[e?.guid,e?.id];for(let i of t){let n=Number(i);if(Number.isSafeInteger(n)&&n>0&&n<=2147483647)return n}return 0}function Ei(e){let t=String(e?.controlAsset||""),i=Fl(e);return{id:String(i||e?.id||""),guid:i,path:String(e?.path||""),source:String(e?.source||""),controlId:String(e?.controlId||""),controlAsset:t===V||t==="client"?V:t===oe||t==="server"?oe:""}}function Bo(e){let t=[],i=(n,r="")=>{if(n&&(n.path||n.source)){let o=Ei(n);t.push(r?{...o,controlAsset:r}:o)}};if(Array.isArray(e?.assets?.scripts)){for(let n of e.assets.scripts)n&&(n.path||n.source)&&t.push(Ei(n));return t}if(i(e?.assets?.server?.script,oe),i(e?.assets?.client?.script,V),e&&e.format!==at){i(e?.script);for(let n of e?.scripts||[])i(n)}return t}function Dn(e){return xe(e===V?Je():De())}var $l="\u672A\u7ED1\u5B9A",It="\u672A\u547D\u540D\u5B58\u6863",Dl="\u672A\u547D\u540D\u754C\u9762";function zl(e){let t=e;for(let i=0;i<8;i++){if(Jt(Go(t,"simulator","studio"))&&Jt(Go(t,"lua")))return t;let n=Tl(t);if(n===t)break;t=n}return e}function Gl(e){return e?{name:Ct(e),path:e,bound:!0}:{name:$l,path:"",bound:!1}}function Vl(e,t=process.cwd()){if(Rl(e)&&Jt(e))return e;let i=t||process.cwd(),n=zl(i),r=Vo(n,e);if(Jt(r))return r;let o=Vo(i,e);if(Jt(o))return o;throw new Error("script file not found: "+e)}function Uo(e,t={}){e?.format===at&&tn(e.version);let i=[],n=typeof t.workspacePath=="string"&&t.workspacePath?t.workspacePath:"",r=e?.format===at&&e.assets,o=r?null:xe(e,{warnings:i}),a={server:r&&e.assets.server?xe(e.assets.server,{warnings:i}):Dn(oe),client:r&&e.assets.client?xe(e.assets.client,{warnings:i}):Dn(V)};o&&(a[ot(o.meta.assetType)]=o);let s=r&&e.activeAssetType===V?V:o?.meta.assetType||oe,c=r&&e.meta?.name?String(e.meta.name):"",l=()=>c||It;!e?.meta?.name&&a.server.meta.name==="\u672A\u547D\u540D\u754C\u9762\u63A7\u4EF6\u7EC4"&&(a.server.meta.name=Dl);let f=[],h=new Set;function p(){h.clear(),yt(a.server.root,h),yt(a.client.root,h,{skipServerContainer:!0});for(let d of f)ke(d.guid)&&h.add(Number(d.guid))}function m(d=0){p();let y=ke(d)&&!h.has(Number(d))?Number(d):Fe(h);return h.add(y),y}function g(d){let y=Ei(d),w=m(y.guid);return{...y,guid:w,id:String(w)}}for(let d of Bo(e))f.push(g(d));let I=wt(e?.serverLogic),k=null,E="",$=1,F=1;function U(d){let y=String(d||"").trim();if(!y)return"";if(!K[y])throw new Error(`unknown canvas preset: ${y} (available: ${Object.keys(K).join(", ")})`);return y}let W=()=>a[ot(s)];function Z(d){if(!d)return null;for(let[y,w]of[["server",a.server],["client",a.client]]){let T=le(w.root,d);if(T&&T.kind!=="server-container")return{key:y,node:T}}return null}function q(d){if(!d.controlId)return null;let y=d.controlAsset===V?"client":d.controlAsset===oe?"server":null;if(y){let w=le(a[y].root,d.controlId);return w&&w.kind!=="server-container"?{key:y,node:w}:null}return Z(d.controlId)}function O(){for(let d of f)d.controlId&&!q(d)&&(d.controlId="",d.controlAsset="")}function b(d){if(!ke(d))return null;for(let[y,w]of[[oe,a.server],[V,a.client]]){let T="";if(J(w.root,N=>{!T&&(N.scriptMappingIds||[]).includes(Number(d))&&(T=N.id)}),T)return{controlId:T,controlAsset:y}}return null}function x(d,y,w){let T=a[ot(d.controlAsset)],N=T&&le(T.root,d.controlId);N&&(N.scriptMappingIds=(N.scriptMappingIds||[]).map(R=>Number(R)===Number(y)?Number(w):R))}O();function v(){return f.map(d=>{let y=q(d),w=y?y.key==="client"?V:oe:"";return D({id:d.id,guid:d.guid||0,path:d.path||"",source:d.source||"",controlId:d.controlId||"",controlAsset:d.controlAsset||w,controlName:y?.node.name||"",assetType:w,assetLabel:y?Yo[w]:"",mounted:!!y})})}function C(){let d=[],y=(w,T)=>{J(w.root,N=>{N.kind!=="server-container"&&d.push(D({id:N.id,name:N.name,kind:N.kind,assetType:T,assetLabel:Yo[T]}))})};return y(a.server,oe),y(a.client,V),d}function M(d){let y=[];return J(d.root,w=>{w.kind!=="server-container"&&y.push(JSON.stringify({kind:w.kind,name:w.name,text:w.text??null,imageId:w.imageId??null,fontSize:w.fontSize??null,fontColor:w.fontColor??null,bgColor:w.bgColor??null,imageColor:w.imageColor??null,fillType:w.fillType??null,fillAmount:w.fillAmount??null,syncAllDevices:w.syncAllDevices!==!1,transformByPlatform:w.transformByPlatform||null}))}),y.join("/")}let S=M(Je()),P=M(De());function z(d){let y=M(d);return d.meta?.assetType===V?y===S:y===P}function G(d,y){return String(d||"").replace(/[\\/:*?"<>|]/g,"-").trim()||y}function ie(d){let y=G(l(),It),w=d.meta?.assetType===V?"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F":"\u670D\u52A1\u5668\u63A7\u4EF6\u6A21\u677F";return`${y} \xB7 ${w}`}function j(){if(!((a.server.root.children||[]).find(y=>y.kind==="container")||a.server.root.children?.[0]))throw new Error("\u6574\u5408\u5305\u9700\u8981\u670D\u52A1\u7AEF\u5BA2\u6237\u7AEF\u63A7\u4EF6\u5BB9\u5668\u4E0B\u81F3\u5C11\u6709\u4E00\u4E2A\u6839\u63A7\u4EF6");return Rr(a.server,a.client,{scripts:f,fileName:`${G(l(),It)} \xB7 \u6574\u5408\u5305.gia`})}function ue(){let d=y=>({type:y.meta.assetType,name:y.meta.name,sourceFile:y.meta.sourceFile||""});return{format:at,name:l(),activeAssetType:s,assets:{server:d(a.server),client:d(a.client),scripts:v()}}}function Te(){return D({format:at,version:4,meta:{name:l()},activeAssetType:s,serverLogic:I,assets:{server:a.server,client:a.client,scripts:f.map(d=>D({id:d.id,guid:d.guid||0,path:d.path||"",source:d.source||"",controlId:d.controlId||"",controlAsset:d.controlAsset||""}))}})}function ae(){let d=W(),y=Wr(d);return y.workspace=Gl(n),y.save=ue(),y.scripts=v(),y.mountTargets=C(),y.serverLogic=I,y.migrationWarnings=[...i],Qn(y),y}function lt(d){let y=W();if(d.expectedRevision!==void 0&&Number(d.expectedRevision)!==y.version)throw new Error(`revision conflict: expected ${d.expectedRevision}, current ${y.version}`);return y}function He(d,y,w=""){let T=String(y||"");if(T){let N=w===V?V:w===oe?oe:"";if(!q({controlId:T,controlAsset:N}))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=N}else d.controlAsset="";d.controlId=T}function _t(d){let y=lt(d);if(d.op==="addScript"){let w=g({path:String(d.path||""),source:String(d.source||""),controlId:"",controlAsset:""});d.controlId!==void 0&&d.controlId!==""&&He(w,d.controlId,d.controlAsset),f.push(w)}else if(d.op==="updateScript"){let w=f.find(T=>T.id===d.id);if(!w)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${d.id}`);d.controlId!==void 0&&He(w,d.controlId,d.controlAsset),d.path!==void 0&&(w.path=String(d.path)),d.source!==void 0&&(w.source=String(d.source))}else if(d.op==="removeScript"){let w=f.length;if(f=f.filter(T=>T.id!==d.id),f.length===w)throw new Error(`\u811A\u672C\u4E0D\u5B58\u5728: ${d.id}`)}return y.version+=1,ae()}function ut(d){if(!d||typeof d!="object")throw new Error("patch requires op");if(d.op==="setServerLogic"){let y=lt(d);return I=wt(d.logic),y.version+=1,ae()}if(d.op==="addScript"||d.op==="updateScript"||d.op==="removeScript")return _t(d);if(d.op==="selectAsset")return s=d.assetType===V?V:oe,ae();if(d.op==="renameSave"){let y=String(d.name||"").trim();if(!y)throw new Error("\u5B58\u6863\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");return c=y,ae()}if(d.op==="newAsset"){let y=lt(d);s=d.assetType===V?V:oe;let w=Dn(s);return w.version=y.version+1,a[ot(s)]=w,O(),ae()}return on(W(),d),O(),ae()}function Pt(d){return f.filter(y=>{let w=q(y);return!!(w&&w.key==="client"==(d===V))})}function Tt(d="json",y=""){let w=String(d).toLowerCase();if(w==="save"||w==="archive"){let R=Buffer.from(JSON.stringify(Te(),null,2),"utf8");return D({filename:`${l().replace(/[\\/:*?"<>|]/g,"-")} \xB7 \u8D44\u4EA7\u5305.json`,mimeType:"application/json",encoding:"base64",data:R.toString("base64"),warnings:[]})}if(w==="save-gia"||w==="archive-gia"){let R=[],H=[],Q=(ve,Me="")=>{let ee=Tt(ve,Me);R.push(D({filename:ee.filename,mimeType:ee.mimeType,encoding:ee.encoding,data:ee.data,warnings:ee.warnings||[]})),H.push(...ee.warnings||[])},ct=(ve,Me)=>{let ee=a[ot(ve)],Ne=ve===s,ft=f.some(ge=>ge.controlAsset===ve&&ge.controlId);if(!Ne&&z(ee)&&!ft){H.push(Me);return}Q("gia",ve)};if(ct(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"),ct(V,"\u5BA2\u6237\u7AEF\u63A7\u4EF6\u6A21\u677F\u4ECD\u662F\u9ED8\u8BA4\u300CLua\u5B9E\u4F8B\u5316\u9762\u677F\u300D\uFF0C\u672A\u6539\u52A8\u4E14\u5F53\u524D\u672A\u663E\u793A\uFF0C\u5DF2\u4ECE\u8D44\u4EA7\u5305 GIA \u4E2D\u7701\u7565\u3002"),f.some(ve=>ve.path||ve.source)&&Q("scripts-gia"),!R.length)throw new Error("\u8D44\u4EA7\u5305 GIA \u6CA1\u6709\u53EF\u5BFC\u51FA\u7684\u5DF2\u6539\u52A8\u9879\uFF1B\u8BF7\u5148\u7F16\u8F91\u5F53\u524D\u754C\u9762\uFF0C\u6216\u6539\u7528\u300C\u5F53\u524D\u754C\u9762 GIA\u300D\u3002");return D({format:"qxqy-gia-package",files:R,warnings:[...new Set(H)]})}if(w==="gia-combined"||w==="combined-gia"||w==="combined"){let R=j();return D({filename:`${G(l(),It)} \xB7 \u6574\u5408\u5305.gia`,mimeType:"application/octet-stream",encoding:"base64",data:R.buffer.toString("base64"),warnings:[...new Set(R.warnings||[])]})}if(w==="scripts"){let R=D({format:Ol,version:1,scripts:f.map(Q=>D({id:Q.id,guid:Q.guid||0,path:Q.path||"",source:Q.source||"",controlId:Q.controlId||"",controlAsset:Q.controlAsset||""}))}),H=Buffer.from(JSON.stringify(R,null,2),"utf8");return D({filename:`${G(l(),It)} \xB7 \u811A\u672C.json`,mimeType:"application/json",encoding:"base64",data:H.toString("base64"),warnings:[]})}if(w==="scripts-gia"||w==="scriptsgia"){let R=Fr(f);return D({filename:`${G(l(),It)} \xB7 \u811A\u672C.gia`,mimeType:"application/octet-stream",encoding:"base64",data:R.buffer.toString("base64"),warnings:R.warnings})}if(w==="lua"){let R=f.find(Q=>Q.id===y)||f.find(Q=>Q.path===y);if(!R)throw new Error("\u6CA1\u6709\u53EF\u5BFC\u51FA\u7684 Lua \u811A\u672C\uFF0C\u8BF7\u5148\u5728\u201CLua \u811A\u672C\u201D\u9875\u521B\u5EFA");let H=Ct(R.path||"")||`qxqy-script-${R.id}`;return D({filename:/\.lua$/i.test(H)?H:`${H}.lua`,mimeType:"text/x-lua",encoding:"base64",data:Buffer.from(R.source||"","utf8").toString("base64"),warnings:[]})}let T=y?a[ot(y)]:W(),N=ie(T);if(w==="json"){let R=D({...T,scripts:Pt(T.meta.assetType)}),H=Buffer.from(JSON.stringify(R,null,2),"utf8");return D({filename:`${N}.json`,mimeType:"application/json",encoding:"base64",data:H.toString("base64"),warnings:[]})}if(w==="gia"){let R=Tr(T,T.meta.assetType===V?{scripts:Pt(V)}:{});return D({filename:`${N}.gia`,mimeType:"application/octet-stream",encoding:"base64",data:R.buffer.toString("base64"),warnings:R.warnings})}throw new Error(`unsupported export format: ${d}`)}function X(d){for(let y of d){let w=Ei(y);if(!w.path&&!w.source)continue;let T=w.controlId?null:b(w.guid),N=g(T?{...w,...T}:w);T&&N.guid!==w.guid&&x(T,w.guid,N.guid),N.controlId&&!q(N)&&(N.controlId="",N.controlAsset=""),f.push(N)}}function Ie(d,y,w=""){let T=String(d||"").toLowerCase();if(typeof y!="string"||!y)throw new Error("import data is required");let N=Buffer.from(y,"base64"),R,H=[],Q={};if(T==="json"){try{R=JSON.parse(N.toString("utf8"))}catch{throw new Error("JSON \u6587\u4EF6\u65E0\u6548")}if(R?.project&&(R=R.project),R?.format===at&&R?.assets){tn(R.version);let ee=xe(R.assets.server||De(),{warnings:H}),Ne=xe(R.assets.client||Je(),{warnings:H}),ft=wt(R.serverLogic);return a.server=ee,a.client=Ne,i=[...H],s=R.activeAssetType===V?V:oe,c=String(R.meta?.name||Ct(w).replace(/\.json$/i,"")||c),I=ft,f=[],h.clear(),X(Bo(R)),O(),D({snapshot:ae(),warnings:H,metadata:{format:at}})}}else{if(T==="lua")return f.push(g({path:Ct(w||"imported.lua"),source:N.toString("utf8"),controlId:""})),D({snapshot:ae(),warnings:H,metadata:{assetType:"lua-script"}});if(T==="gia"){if($r(N)){let ge=zr(N);return X(ge.scripts),D({snapshot:ae(),warnings:ge.warnings,metadata:ge.metadata})}let ee=Gr(N);R=ee.project,H=ee.warnings,Q=ee.metadata,ee.clientProject&&(a.client=xe(ee.clientProject),H.push("\u6574\u5408\u5305\u5DF2\u62C6\u56DE\u300CUI\u63A7\u4EF6-\u670D\u52A1\u7AEF\u300D\u4E0E\u300CUI\u63A7\u4EF6-\u5BA2\u6237\u7AEF\u300D\uFF1B\u5BA2\u6237\u7AEF\u6A21\u677F\u8FB9\u754C\u5DF2\u4FDD\u7559\u3002"));let Ne=new Map,ft=(ge,Da)=>{ge&&J(ge.root,qn=>{for(let $i of qn.scriptMappingIds||[]){let jn=Ne.get(Number($i));if(jn){H.push(`\u811A\u672C GUID ${$i} \u540C\u65F6\u6302\u8F7D\u5230\u591A\u4E2A\u63A7\u4EF6\uFF0C\u5DF2\u4FDD\u7559\u201C${jn.controlAsset===oe?"\u670D\u52A1\u7AEF":"\u5BA2\u6237\u7AEF"}\u201D\u76EE\u6807\u3002`);continue}Ne.set(Number($i),{controlId:qn.id,controlAsset:Da})}})};ft(ee.project,oe),ft(ee.clientProject,V),X((ee.scripts||[]).map(ge=>Ne.has(Number(ge.guid))?{...ge,...Ne.get(Number(ge.guid))}:ge))}else throw new Error(`unsupported import format: ${d}`)}let ct=xe(R,{warnings:H});i=[...H];let ve=ot(ct.meta.assetType);a[ve]=ct,s=ct.meta.assetType;let Me=a[ve];return w&&(Me.meta.name=Ct(w).replace(/\.(json|gia)$/i,"")||Me.meta.name,Me.meta.sourceFile=Ct(w),Me.meta.sourceFormat=T),X(R?.scripts||[]),R?.script&&(R.script.path||R.script.source)&&X([R.script]),D({snapshot:ae(),warnings:H,metadata:Q})}function Xe(d,y){return on(W(),{op:"pick",x:d,y}),ae()}function ei(d){let y=typeof d=="string"&&d?d:"";!y||y===n||(n=y)}function Rt(d){let y=d.source||"";if(!y.trim()&&d.path.trim())try{y=Pl(Vl(d.path,n),"utf8")}catch(w){throw new Error(`\u811A\u672C ${d.path} \u8BFB\u53D6\u5931\u8D25: ${w?.message||w}`)}return y}function Re(d={}){let y=U(d.canvasId);y&&(E=y),d.playerCount!==void 0&&d.playerCount!==null&&d.playerCount!==""&&($=tt(d.playerCount),F>$&&(F=1)),d.viewPlayerIndex!==void 0&&d.viewPlayerIndex!==null&&d.viewPlayerIndex!==""&&(F=Pe(d.viewPlayerIndex,$)),k&&Mn(k);let w=f.map(N=>{try{return{id:N.id,guid:N.guid||0,path:N.path||N.id,source:Rt(N),controlId:N.controlId||"",controlAsset:N.controlAsset||""}}catch(R){return{id:N.id,guid:N.guid||0,path:N.path||N.id,source:`error([==[ ${String(R.message).replace(/]=+]/g,"] =]")} ])`,controlId:N.controlId||"",controlAsset:N.controlAsset||""}}}),T=N=>w.filter(R=>{let H={controlId:R.controlId,controlAsset:R.controlAsset},Q=R.controlId?q(H):null;return!!(Q&&Q.key===N)});return k=Ao(a.server,{templatesProject:a.client,scripts:w,sceneScripts:T("server"),templateScripts:T("client"),serverConfig:{logic:I},canvasId:E,playerCount:$,viewPlayerIndex:F}),se(d)}function Mt(d,y={}){let w=U(d);if(!w)throw new Error("playSetCanvas requires canvasId");return Re({...y,canvasId:w})}function se(d={}){if(!k)return D({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]});let y=En(k,d);return y.running=!0,y.logs=$n(y.logs),y.serverLogs=$n(y.server?.logs||[]),y.serverVars=Nl(y.server,y.playerCount||1),y}function wa(d,y={}){return k||Re(),ki(k,d),y.observe===!1?D({running:!0,time:k.runtime.clock.time,frame:k.runtime.clock.frame,paused:!!k.debugPaused,levelTimePaused:!!k.runtime.clock.paused,playerCount:k.playerCount||1,viewPlayerIndex:k.viewPlayerIndex||1}):se(y)}function Ia(d=0){Re();let y=Math.max(0,Number(d)||0);for(let w=0;w<y;w++)ki(k,1/30);return se()}function Ca(){return k&&Mn(k),k=null,E="",$=1,F=1,D({running:!1,tree:[],logs:[],serverLogs:[],serverVars:[]})}function ka(d,y={}){let w=Nt();return F=kn(w,d),y.observe===!1?null:se(y)}function xa(d,y={}){if(!k)throw new Error("play session has not started");return An(k,d),y.observe===!1?null:se(y)}function Ea(d,y={}){if(!k)throw new Error("play session has not started");return _n(k,d),y.observe===!1?null:se(y)}function Aa(d,y,w,T={}){if(!k)throw new Error("play session has not started");return jt(k,d,y,w),T.observe===!1?null:se(T)}function _a(d={}){return k&&xi(k).pause(),d.observe===!1?null:se(d)}function Pa(d={}){return k&&xi(k).resume(),d.observe===!1?null:se(d)}function Nt(){if(!k)throw new Error("play session has not started");return k}function Ta(d,y){let w=Nt();if(!d&&!y){let T=se();return D({vars:T.serverVars||[]})}return D({entityType:String(d||""),name:String(y||""),value:Fo(w,d,y)})}function Ra(d,y,w){let T=Nt();return Tn(T,d,y,w),se()}function Ma(d,y=[],w="PlayerSelf"){let T=Nt();return Rn(T,d,y,w),se()}function Na(){let d=se();return D({events:d.history||[],case:Co(d.history||[],{playerCount:d.playerCount||1})})}function Oa(d={}){let y=se(),w=Lt({name:d.name||"",dt:d.dt,playerCount:d.playerCount||y.playerCount||1,events:d.events||y.history||[],asserts:d.asserts||[]});return D(w)}function Fa(d,y={}){let w=Lt(d);Re({...y,playerCount:y.playerCount||w.playerCount||1});let T=Nt();T.recording=!1;try{return zo(xi(T),d)}finally{T.recording=!0}}function $a(){if(!k)return{running:!1,paused:!1,time:0,frame:0,playerCount:1,viewPlayerIndex:1};let d=k.runtime.clock;return{running:!0,paused:!!k.debugPaused,levelTimePaused:!!d.paused,time:d.time,frame:d.frame,playerCount:k.playerCount||1,viewPlayerIndex:k.viewPlayerIndex||1}}let Wn={get:ae,patch:ut,setWorkspace:ei,exportData:Tt,importData:Ie,pick:Xe,playStart:Re,playSetCanvas:Mt,playSetView:ka,playGet:se,playStatus:$a,playStep:wa,playRun:Ia,playStop:Ca,playKey:xa,playClick:Ea,playPointer:Aa,playPause:_a,playResume:Pa,playServerGet:Ta,playServerSet:Ra,playServerSend:Ma,playHistory:Na,playSaveCase:Oa,playRunCase:Fa,archiveData:Te};return Object.defineProperty(Wn,"_project",{enumerable:!1,get:W}),Wn}import{createRequire as Yl}from"node:module";function Ho(e,t,i){if(e.fillType!=="Horizontal"&&e.fillType!=="Vertical")return null;let n=Number(e.fillAmount??1),r=Number.isFinite(n)?Math.max(0,Math.min(1,n)):1;if(e.fillType==="Horizontal"){let a=t*r;return{x:e.fillHorizontalType==="Right"?t/2-a:-t/2,y:-i/2,width:a,height:i}}let o=i*r;return{x:-t/2,y:e.fillVerticalType==="Top"?-i/2:i/2-o,width:t,height:o}}var Bl=Yl(import.meta.url),Ul=[0,-.5,.5,.5,-.5,.5],Hl=[0,-.5,.12,-.12,.5,0,.12,.12,0,.5,-.12,.12,-.5,0,-.12,-.12],Xl=[0,-.5,.11,-.15,.48,-.15,.18,.07,.29,.41,0,.2,-.29,.41,-.18,.07,-.48,-.15,-.11,-.15],zn=Buffer.from([137,80,78,71,13,10,26,10]),Kl=new Set(["image","textbox","textwindow","button"]),Ai={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"},_i=null;function Ko(){if(_i)return _i;try{_i=Bl("@napi-rs/canvas")}catch(e){let t=e?.message||String(e);throw new Error(`Host screenshot renderer requires @napi-rs/canvas (${t})`)}return _i}function Y(e,t=0){let i=Number(e);return Number.isFinite(i)?i:t}function Ti(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 st(e,t=1){return`rgba(${e.r},${e.g},${e.b},${Math.max(0,Math.min(1,e.a*t))})`}function Lo(e,t,i=1){let n=Math.max(1,Math.round(Y(e,1))),r=Math.max(1,Math.round(Y(t,1))),o=Math.max(1,Math.min(2,Y(i,1)));return{width:n,height:r,pixelWidth:Math.max(1,Math.round(n*o)),pixelHeight:Math.max(1,Math.round(r*o)),pixelRatio:o}}function Wo(e){let t=Buffer.from(e.toBuffer("image/png"));if(t.length<zn.length||!t.subarray(0,zn.length).equals(zn))throw new Error("Host screenshot renderer did not produce a PNG");return t}function Ll(e){return e==="triangle"?Ul:e==="fourstar"?Hl:Xl}function Wl(e,t,i,n,r){let o=Ll(t);e.beginPath();for(let a=0;a<o.length;a+=2){let s=o[a]*i,c=o[a+1]*n;a===0?e.moveTo(s,c):e.lineTo(s,c)}e.closePath(),e.fillStyle=st(r),e.fill()}function ql(e,t,i){let n=t?.matrix,r=n&&typeof n=="object"?[n.a,n.b,n.c,n.d,n.tx,n.ty].map(Number):null,o=t?.pressed?.98:1;if(r&&r.every(Number.isFinite)){let[a,s,c,l,f,h]=r;e.transform(a*o,-s*o,-c*o,l*o,f,i-h);return}e.translate(Y(t.left)+Y(t.width)/2,i-Y(t.bottom)-Y(t.height)/2),e.rotate(-Y(t.rotationZ)*Math.PI/180),e.scale(o,o)}function jl(e,t,i,n,r,o){if(typeof e.roundRect=="function"){e.roundRect(t,i,n,r,o);return}let a=Math.max(0,Math.min(o,n/2,r/2));e.moveTo(t+a,i),e.arcTo(t+n,i,t+n,i+r,a),e.arcTo(t+n,i+r,t,i+r,a),e.arcTo(t,i+r,t,i,a),e.arcTo(t,i,t+n,i,a),e.closePath()}function qo(e,t,i,n){let r=Ti(t.bgColor,16777215);e.fillStyle=st(r),e.fillRect(-i/2,-n/2,i,n);let o=Math.max(8,Y(t.fontSize,12)),a=Ti(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,-n/2,i,n),e.clip(),e.font=`${o}px "Microsoft YaHei UI","Microsoft YaHei",sans-serif`,e.fillStyle=st(a),e.textAlign=s===1?"right":s===.5?"center":"left",e.textBaseline=c===1?"bottom":c===.5?"middle":"top",t.enableOutline){let g=Ti(t.outlineColor,4278190080);e.strokeStyle=st(g),e.lineWidth=Math.max(2,o*.12),e.lineJoin="round"}let l=s===0?-i/2+2:s===1?i/2-2:0,f=c===0?-n/2:c===1?n/2:0,h=String(t.text||"").split(`
|
|
107
|
-
`),p=o*1.2,m=c===.5?f-(h.length-1)*p/2:c===1?f-(h.length-1)*p:f;for(let g=0;g<h.length;g+=1){let I=m+g*p;t.enableOutline&&e.strokeText(h[g],l,I),e.fillText(h[g],l,I)}e.restore()}function jo(e,t,i,n){e.beginPath(),jl(e,-i/2,-n/2,i,n,6),e.fillStyle="#3268cf",e.fill(),e.strokeStyle="rgba(112,160,255,0.8)",e.lineWidth=1,e.stroke(),t.pressed&&(e.fillStyle="rgba(0,0,0,0.28)",e.fill())}function Jo(e,t,i,n){let r=Ti(t.imageColor,4294967295);if(t.primitive==="missing"){e.fillStyle="rgba(72,34,40,0.36)",e.fillRect(-i/2,-n/2,i,n),e.strokeStyle="#ff7481",e.lineWidth=1,e.strokeRect(-i/2+.5,-n/2+.5,Math.max(0,i-1),Math.max(0,n-1));return}if(t.primitive==="circle"){e.beginPath(),e.
|
|
107
|
+
`),p=o*1.2,m=c===.5?f-(h.length-1)*p/2:c===1?f-(h.length-1)*p:f;for(let g=0;g<h.length;g+=1){let I=m+g*p;t.enableOutline&&e.strokeText(h[g],l,I),e.fillText(h[g],l,I)}e.restore()}function jo(e,t,i,n){e.beginPath(),jl(e,-i/2,-n/2,i,n,6),e.fillStyle="#3268cf",e.fill(),e.strokeStyle="rgba(112,160,255,0.8)",e.lineWidth=1,e.stroke(),t.pressed&&(e.fillStyle="rgba(0,0,0,0.28)",e.fill())}function Jo(e,t,i,n){let r=Ti(t.imageColor,4294967295);if(t.primitive==="missing"){e.fillStyle="rgba(72,34,40,0.36)",e.fillRect(-i/2,-n/2,i,n),e.strokeStyle="#ff7481",e.lineWidth=1,e.strokeRect(-i/2+.5,-n/2+.5,Math.max(0,i-1),Math.max(0,n-1));return}if(t.primitive==="circle"){e.beginPath(),e.ellipse(0,0,i/2,n/2,0,0,Math.PI*2),e.fillStyle=st(r),e.fill();return}if(t.primitive==="ring"){e.beginPath(),e.ellipse(0,0,Math.max(1,i/2-3.5),Math.max(1,n/2-3.5),0,0,Math.PI*2),e.strokeStyle=st(r),e.lineWidth=7,e.stroke();return}if(t.primitive==="triangle"||t.primitive==="fourstar"||t.primitive==="fivestar"){Wl(e,t.primitive,i,n,r);return}e.fillStyle=st(r),e.fillRect(-i/2,-n/2,i,n)}function Jl(e,t,i){let n=Math.max(0,Y(t.sourceWidth,Y(t.width))),r=Math.max(0,Y(t.sourceHeight,Y(t.height)));if(e.save(),ql(e,t,i),t.kind==="textbox"||t.kind==="textwindow")qo(e,t,n,r);else if(t.kind==="button")jo(e,t,n,r);else{let o=Ho(t,n,r);o&&(e.beginPath(),e.rect(o.x,o.y,o.width,o.height),e.clip()),Jo(e,t,n,r)}e.restore()}function Zo(e,t,i,{checker:n=!1}={}){if(n){e.fillStyle="#28313e",e.fillRect(0,0,t,i);let o=16;for(let a=0;a<i;a+=o)for(let s=0;s<t;s+=o)(s/o+a/o)%2===0&&(e.fillStyle="rgba(255,255,255,0.04)",e.fillRect(s,a,o,o));e.strokeStyle="#40b8cf",e.lineWidth=1,e.strokeRect(.5,.5,t-1,i-1);return}let r=e.createRadialGradient(t/2,i*.45,8,t/2,i/2,Math.max(t,i)*.72);r.addColorStop(0,"#123a6b"),r.addColorStop(.72,"#061934"),r.addColorStop(1,"#071426"),e.fillStyle=r,e.fillRect(0,0,t,i)}function Zl(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 Xo(e){let t=e?.matrix;return!t||typeof t!="object"?{a:1,b:0,c:0,d:1,tx:0,ty:0}:{a:Y(t.a,1),b:Y(t.b),c:Y(t.c),d:Y(t.d,1),tx:Y(t.tx),ty:Y(t.ty)}}function Ql(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)=>Y(s.z)-Y(c.z));let n=[];function r(a,s){if(!Kl.has(a.kind))return;let c=Math.abs(Y(a.sourceWidth)*Math.hypot(s.a,s.b)),l=Math.abs(Y(a.sourceHeight)*Math.hypot(s.c,s.d));n.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],h=s?Zl(s,Xo(f)):Xo(f);r(f,h),o(String(f.id),h)}}return o("",null),n}function Qo(e,t,i,n={}){return eu(Ql(e),t,i,n)}function eu(e,t,i,n={}){let{createCanvas:r}=Ko(),o=Lo(t,i,n.scale),a=r(o.pixelWidth,o.pixelHeight),s=a.getContext("2d");s.scale(o.pixelRatio,o.pixelRatio),Zo(s,o.width,o.height);let c=Array.isArray(e)?e:[];for(let l of c)!l||l.id===void 0||l.id===null||Jl(s,l,o.height);return{data:Wo(a),width:o.width,height:o.height,pixelWidth:o.pixelWidth,pixelHeight:o.pixelHeight}}function tu(e){return{kind:e.kind,left:Y(e.renderLeft,e.left),bottom:Y(e.renderBottom,e.bottom),width:Math.max(0,Y(e.renderWidth,e.width)),height:Math.max(0,Y(e.renderHeight,e.height)),rotationZ:Y(e.renderRotationZ,e.rotationZ)}}function Pi(e,t,i){let n=String(t||"");if(!n)return;e.font='10px "Microsoft YaHei UI","Microsoft YaHei",sans-serif',e.textAlign="center",e.textBaseline="middle";let r=e.measureText(n),o=Math.min(i-4,Math.max(24,r.width+8)),a=16;e.fillStyle="rgba(17,25,37,0.66)",e.fillRect(-o/2,-a/2,o,a),e.fillStyle="#e7edf5",e.fillText(n,0,0)}function iu(e,t,i,n){let r=tu(t);if(r.width<=0||r.height<=0)return;e.save(),e.translate(r.left+r.width/2,i-r.bottom-r.height/2),e.rotate(-r.rotationZ*Math.PI/180);let o=-r.width/2,a=-r.height/2;if(t.kind==="image")Jo(e,t,r.width,r.height);else if(t.kind==="textbox"||t.kind==="textwindow")qo(e,t,r.width,r.height);else if(t.kind==="button")jo(e,t,r.width,r.height),Pi(e,t.name||Ai.button,r.width);else if(t.kind==="cursor")e.setLineDash([6,4]),e.strokeStyle="rgba(74,142,181,0.7)",e.fillStyle="rgba(74,142,181,0.1)",e.fillRect(o,a,r.width,r.height),e.strokeRect(o,a,r.width,r.height),Pi(e,t.name||Ai.cursor,r.width);else if(t.kind==="grid"){e.strokeStyle="rgba(106,146,189,0.55)",e.strokeRect(o,a,r.width,r.height),e.beginPath();for(let s=20;s<r.width;s+=20)e.moveTo(o+s,a),e.lineTo(o+s,a+r.height);for(let s=20;s<r.height;s+=20)e.moveTo(o,a+s),e.lineTo(o+r.width,a+s);e.stroke(),Pi(e,t.name||Ai.grid,r.width)}else t.kind!=="container"&&t.kind!=="server-container"?(e.setLineDash(t.kind==="reference"||t.kind==="animation"||t.kind==="fullscreen"?[4,4]:[]),e.strokeStyle="rgba(203,218,237,0.55)",e.strokeRect(o,a,r.width,r.height),Pi(e,t.name||Ai[t.kind]||t.kind,r.width)):(e.strokeStyle="rgba(78,165,230,0.42)",e.strokeRect(o,a,r.width,r.height));t.id===n&&t.kind!=="container"&&t.kind!=="server-container"&&(e.setLineDash([]),e.strokeStyle="#61b9ff",e.lineWidth=2,e.strokeRect(o,a,r.width,r.height)),e.restore()}function ea(e,t={}){let{createCanvas:i}=Ko(),n=e?.canvas||{},r=Lo(n.width||1600,n.height||900,t.scale),o=i(r.pixelWidth,r.pixelHeight),a=o.getContext("2d");a.scale(r.pixelRatio,r.pixelRatio),Zo(a,r.width,r.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||iu(a,l,r.height,c);return{data:Wo(o),page:e?.asset?.type==="client-control-template"?"UI\u63A7\u4EF6-\u5BA2\u6237\u7AEF":"UI \u7F16\u8F91",width:r.width,height:r.height,pixelWidth:r.pixelWidth,pixelHeight:r.pixelHeight}}import{closeSync as nu,existsSync as Ri,openSync as ru,readdirSync as ou,readSync as au,realpathSync as kt,statSync as na}from"node:fs";import{basename as su,dirname as ta,isAbsolute as Gn,join as lu,relative as ra,resolve as Qt}from"node:path";var uu="qxqy-simulator-save",cu=new Set(["node_modules",".git","dist",".dsh","coverage"]),ia=50,fu=8*1024*1024,du=8;function Vn(e=""){let t=Qt(String(e||process.cwd()));if(!Ri(t))throw new Error(`workspace does not exist: ${t}`);if(!na(t).isDirectory())throw new Error(`workspace is not a directory: ${t}`);return kt(t)}function Zt(e,t,i=!1){let n=ra(e,t);if(!i&&!n||n.startsWith("..")||Gn(n))throw new Error("path must stay inside the configured workspace");return n}function oa(e,t){let i=String(t||"").trim();if(!i||Gn(i))throw new Error("path must be a non-empty workspace-relative path");let n=kt(Qt(e)),r=Qt(n,i);if(Zt(n,r),!Ri(r))throw new Error(`file does not exist: ${i}`);let o=kt(r);return Zt(n,o),o}function aa(e,t){let i=String(t||"").trim();if(!i||Gn(i))throw new Error("path must be a non-empty workspace-relative path");let n=kt(Qt(e)),r=Qt(n,i);Zt(n,r);let o=ta(r);for(;!Ri(o);){let a=ta(o);if(a===o)throw new Error("unable to resolve output directory");o=a}return Zt(n,kt(o),!0),Ri(r)&&Zt(n,kt(r)),r}function hu(e,t=4096){let i=Buffer.alloc(t),n=ru(e,"r");try{let r=au(n,i,0,t,0);return i.subarray(0,r).toString("utf8")}finally{nu(n)}}function sa(e,t,i,n){if(i.length>=ia||n>du)return;let r;try{r=ou(e,{withFileTypes:!0})}catch{return}for(let o of r){if(i.length>=ia)return;if(o.name.startsWith(".")||cu.has(o.name))continue;let a=lu(e,o.name);if(o.isDirectory()){sa(a,t,i,n+1);continue}if(!(!o.isFile()||!/\.json$/i.test(o.name)))try{let s=na(a);if(s.size<20||s.size>fu)continue;let c=hu(a);if(!c.includes(uu))continue;let l=c.match(/"name"\s*:\s*"([^"]+)"/)?.[1]||su(o.name,".json");i.push({path:ra(t,a).replaceAll("\\","/"),name:l,bytes:s.size,mtime:s.mtimeMs})}catch{}}}function la(e){let t=Vn(e),i=[];return sa(t,t,i,0),i.sort((n,r)=>r.mtime-n.mtime),{bound:!0,workspace:t,archives:i}}var Su=Math.max(1e3,Number(process.env.QXQY_PLAY_TIMEOUT_MS)||8e3),wu=8e3;function ua(){let e=new Error("operation aborted");return e.name="AbortError",e}var Mi=class{constructor(t=""){this.workspacePath=t?Vn(t):"",this.studio=Uo(void 0,this.workspacePath?{workspacePath:this.workspacePath}:void 0),this.worker=null,this.pending=new Map,this.sequence=1,this.lock=Promise.resolve()}async exclusive(t){let i=this.lock,n;this.lock=new Promise(r=>{n=r}),await i;try{return await t()}finally{n()}}get(){return this.studio.get()}patch(t){return this.studio.patch(t)}listArchives(){return la(this.workspacePath)}loadArchive(t){let i=this.activeWorkspacePath();if(!i)throw new Error("workspace is not bound");let n=oa(i,t),r=gu(n);return this.studio.importData("json",r.toString("base64"),bu(n))}saveArchive(t="qxqy-simulator.save.json"){let i=String(t),n=this.activeWorkspacePath();if(!n)throw new Error("workspace is not bound");let r=aa(n,i);mu(vu(r),{recursive:!0});let o=Buffer.from(JSON.stringify(this.studio.archiveData(),null,2)+`
|
|
108
108
|
`,"utf8");return yu(r,o),{path:i.replaceAll("\\","/"),bytes:o.length,revision:this.studio.get().version,name:this.studio.get().save?.name||""}}activeWorkspacePath(){let t=this.studio.get().workspace;return t?.bound&&t.path?String(t.path):this.workspacePath}createWorker(){let t=new pu(new URL("./worker.js",import.meta.url),{type:"module"});return t.on("message",i=>{let n=this.pending.get(i?.id);n&&(this.pending.delete(i.id),i.ok?n.resolve(i.value):n.reject(new Error(i.error||"play worker failed")))}),t.on("error",i=>{this.worker===t&&(this.worker=null),this.rejectPending(i)}),t.on("exit",i=>{this.worker===t&&(this.worker=null),i!==0&&this.rejectPending(new Error(`play worker exited with code ${i}`))}),this.worker=t,t}rejectPending(t){for(let i of this.pending.values())i.reject(t);this.pending.clear()}async terminateWorker(t=new Error("play worker terminated")){let i=this.worker;this.worker=null,this.rejectPending(t),i&&await i.terminate().catch(()=>{})}request(t,i,n,r=Su){let o=this.worker||this.createWorker(),a=this.sequence++;return new Promise((s,c)=>{let l=!1,f=(m,g)=>{l||(l=!0,clearTimeout(p),n?.removeEventListener("abort",h),m(g))},h=()=>{this.pending.delete(a),f(c,ua()),this.terminateWorker(ua())},p=setTimeout(()=>{this.pending.delete(a);let m=new Error(`play worker timed out after ${r}ms`);f(c,m),this.terminateWorker(m)},r);if(this.pending.set(a,{resolve:m=>f(s,m),reject:m=>f(c,m)}),n?.aborted)return h();n?.addEventListener("abort",h,{once:!0}),o.postMessage({id:a,action:t,args:i})})}async play(t,i={},n){if(t==="start")return await this.terminateWorker(),this.request("start",{archive:this.studio.archiveData(),workspacePath:this.activeWorkspacePath(),...i},n);if(t==="device"){let r=String(i.canvasId||"").trim();if(!K[r])throw new Error(`unknown canvas preset: ${r||"(empty)"} (available: ${Object.keys(K).join(", ")})`);return await this.terminateWorker(),this.request("start",{archive:this.studio.archiveData(),workspacePath:this.activeWorkspacePath(),...i,canvasId:r},n)}if(t==="stop"){if(!this.worker)return{running:!1,tree:[],logs:[]};try{return await this.request("stop",i,n)}finally{await this.terminateWorker()}}if(!this.worker)throw new Error("play session has not started");return this.request(t,i,n)}async playScreenshot(t){if(!this.worker)throw new Error("play session has not started");let i=await this.request("get",{view:!0},t,wu),n=Qo(i.scene,i.canvasWidth,i.canvasHeight);return{data:n.data,canvasId:String(i.canvasId||""),frame:Number.isFinite(Number(i.frame))?Number(i.frame):0,time:Number.isFinite(Number(i.time))?Number(i.time):0,width:n.width,height:n.height,pixelWidth:n.pixelWidth,pixelHeight:n.pixelHeight}}uiScreenshot(){let t=ea(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()}};import{defineTool as xt}from"@deepseek-ai/dsh-tools";import{closeSync as Iu,existsSync as da,openSync as Cu,readdirSync as ku,readSync as xu,realpathSync as ca,statSync as Eu}from"node:fs";import{basename as Au,isAbsolute as Yn,join as _u,relative as Bn,resolve as Ni}from"node:path";var Pu="qxqy-simulator-save",Tu=new Set(["node_modules",".git","dist",".dsh","coverage"]),fa=50,Ru=8*1024*1024,Mu=8;function ha(e,t){if(!e)throw new Error("\u5DE5\u4F5C\u533A\u672A\u7ED1\u5B9A\uFF0C\u65E0\u6CD5\u4ECE\u78C1\u76D8\u62C9\u53D6\u5B58\u6863");let i=String(t||"").trim();if(!i)throw new Error("path is required");let n=ca(Ni(e)),r=Yn(i)?Ni(i):Ni(n,i),o=Bn(n,r);if(!o||o.startsWith("..")||Yn(o))throw new Error("\u5B58\u6863\u8DEF\u5F84\u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D\u5DE5\u4F5C\u533A\u5185");if(!da(r))throw new Error(`\u5B58\u6863\u4E0D\u5B58\u5728: ${i}`);let a=ca(r),s=Bn(n,a);if(!s||s.startsWith("..")||Yn(s))throw new Error("\u5B58\u6863\u8DEF\u5F84\u5FC5\u987B\u4F4D\u4E8E\u5F53\u524D\u5DE5\u4F5C\u533A\u5185");return a}function Nu(e,t=4096){let i=Buffer.alloc(t),n=Cu(e,"r");try{let r=xu(n,i,0,t,0);return i.subarray(0,r).toString("utf8")}finally{Iu(n)}}function pa(e,t,i,n){if(i.length>=fa||n>Mu)return;let r;try{r=ku(e,{withFileTypes:!0})}catch{return}for(let o of r){if(i.length>=fa)return;if(o.name.startsWith(".")||Tu.has(o.name))continue;let a=_u(e,o.name);if(o.isDirectory()){pa(a,t,i,n+1);continue}if(!(!o.isFile()||!/\.json$/i.test(o.name)))try{let s=Eu(a);if(s.size<20||s.size>Ru)continue;let c=Nu(a);if(!c.includes(Pu))continue;let l=c.match(/"name"\s*:\s*"([^"]+)"/)?.[1]||Au(o.name,".json");i.push({path:Bn(t,a).replaceAll("\\","/"),name:l,bytes:s.size,mtime:s.mtimeMs})}catch{}}}function ma(e){if(!e)return{bound:!1,archives:[]};let t=Ni(e);if(!da(t))return{bound:!1,archives:[]};let i=[];return pa(t,t,i,0),i.sort((n,r)=>r.mtime-n.mtime),{bound:!0,workspace:t,archives:i}}var vd="qxqy-simulator",Sd=["tools","webServer"],ga="/qxqy-simulator/api",ya="/qxqy-simulator/play",Fu="/qxqy-simulator/play-renderer.js",$u=8*1024*1024,Du=32,ba=8e3,Xn=class extends Mi{constructor(t=""){super(t),this.touchedAt=Date.now()}touch(){this.touchedAt=Date.now()}get(){return this.touch(),super.get()}patch(t){return this.touch(),super.patch(Fi(t))}exportData(t,i){return this.touch(),this.studio.exportData(t,i)}importData(t,i,n){return this.touch(),this.studio.importData(t,i,n)}listArchives(){return this.touch(),ma(this.studio.get().workspace?.path||"")}loadArchive(t){this.touch();let i=this.studio.get().workspace?.path||"",n=ha(i,t),r=Ln(n);return this.studio.importData("json",r.toString("base64"),Ou(n))}async play(t,i={},n){return this.touch(),super.play(t,Fi(i)||{},n)}async requestScreenshot(t){return{...await super.playScreenshot(t),capturedAt:new Date().toISOString()}}requestUiScreenshot(){return this.touch(),{...super.uiScreenshot(),capturedAt:new Date().toISOString()}}async dispose(){await this.terminateWorker()}};function Sa(e){let t=String(e||"").trim();if(!t||t.length>256)throw new Error("sessionId is required");return t}function Fi(e){if(e!=null){if(typeof e!="string")return e;try{let t=JSON.parse(e);return t&&typeof t=="object"?t:void 0}catch{return}}}function Et(e){return Sa(e?.agent?.id)}function Kn(e){let t=e?.cwd;return typeof t=="string"&&t?t:""}function At(e){return Kn(e?.agent?.session?.header)}async function zu(e,t={}){let i=t.sessions?.get?.(e),n=Kn(i?.header);if(n)return n;let r=t.sessionPersistence?.inspect;if(typeof r!="function")return"";try{let o=await r.call(t.sessionPersistence,e);return Kn(o?.meta)}catch{return""}}function Gu(){let e=new Map;function t(){if(e.size<Du)return;let i=[...e.entries()].sort((n,r)=>n[1].touchedAt-r[1].touchedAt)[0];i&&(e.delete(i[0]),i[1].dispose())}return{get(i,n=""){let r=Sa(i),o=e.get(r);return o?n&&o.studio.setWorkspace(n):(t(),o=new Xn(n),e.set(r,o)),o.touch(),o},async dispose(){await Promise.all([...e.values()].map(i=>i.dispose())),e.clear()}}}function Oi(e,t,i){let n=JSON.stringify(i);e.statusCode=t,e.setHeader("content-type","application/json; charset=utf-8"),e.setHeader("cache-control","no-store"),e.end(n)}function Vu(){if(!Un){let t=[new URL("./play.html",import.meta.url),new URL("../lib/play.html",import.meta.url)].find(i=>va(i));if(!t)throw new Error("standalone play page is missing");Un=Ln(t,"utf8")}return Un}var Un=null;function Yu(){if(!Hn){let t=[new URL("../dist/play-renderer.js",import.meta.url),new URL("./play-renderer.js",import.meta.url)].find(i=>va(i));if(!t)throw new Error("standalone play renderer bundle is missing; run npm run build");Hn=Ln(t,"utf8")}return Hn}var Hn=null;function Bu(e){e.webServer.register({kind:"prefix",path:ya,handler(t,i){let n=new URL(t.url,"http://localhost").pathname.replace(/\/$/,"");if(t.method!=="GET"||n!==ya){i.statusCode=t.method==="GET"?404:405,i.setHeader("content-type","text/plain; charset=utf-8"),i.end(t.method==="GET"?"not found":"GET required");return}i.statusCode=200,i.setHeader("content-type","text/html; charset=utf-8"),i.setHeader("cache-control","no-store"),i.setHeader("x-content-type-options","nosniff"),i.end(Vu())}})}function Uu(e){e.webServer.register({kind:"exact",path:Fu,handler(t,i){if(t.method!=="GET"){i.statusCode=405,i.setHeader("content-type","text/plain; charset=utf-8"),i.end("GET required");return}try{i.statusCode=200,i.setHeader("content-type","text/javascript; charset=utf-8"),i.setHeader("cache-control","no-store"),i.setHeader("x-content-type-options","nosniff"),i.end(Yu())}catch(n){i.statusCode=500,i.setHeader("content-type","text/plain; charset=utf-8"),i.end(n?.message||String(n))}}})}function Hu(e){return new Promise((t,i)=>{let n=0,r=[];e.on("data",o=>{if(n+=o.length,n>$u){i(new Error("request body is too large")),e.destroy();return}r.push(o)}),e.on("end",()=>{try{let o=Buffer.concat(r).toString("utf8");t(o?JSON.parse(o):{})}catch{i(new Error("invalid JSON body"))}}),e.on("error",i)})}function Xu(e,t){e.tools.register(xt({name:"qxqy_studio_get",description:"\u8BFB\u53D6\u5F53\u524D DeepSeek Harness \u4F1A\u8BDD\u7684\u5343\u661F UI \u7F16\u8F91\u5668\u65E0\u635F JSON \u5FEB\u7167\u3002",parameters:{},output:{schema:{type:"json"},render:(i,n)=>[{type:"text",text:JSON.stringify(n,null,2)}]},timeoutMs:5e3,isConcurrencySafe:()=>!0,async execute(i,n){return t.get(Et(n),At(n)).get()}})),e.tools.register(xt({name:"qxqy_studio_play_screenshot",description:"\u83B7\u53D6\u5F53\u524D\u8BD5\u73A9 Runtime \u753B\u9762\u7684 PNG\u3002Host \u4E0E\u72EC\u7ACB\u8BD5\u73A9\u9875\u5171\u7528 Runtime scene \u6811\uFF08\u540C\u7EA7\u5148\u51FA\u73B0\u7684\u5B50\u8282\u70B9\u5728\u4E0A\uFF09\u518D\u753B\u6210 PNG\uFF0C\u4E0D\u9700\u8981\u6253\u5F00\u8BD5\u73A9\u9875\u6216\u5207\u6362\u6807\u7B7E\u3002\u4EC5\u5728\u9700\u8981\u89C2\u5BDF\u8FD0\u884C\u65F6\u753B\u9762\u3001\u52A8\u753B\u6216\u4EA4\u4E92\u7ED3\u679C\u65F6\u8C03\u7528\uFF1B\u82E5\u8981\u770B\u7F16\u8F91\u5668\u821E\u53F0\uFF0C\u8BF7\u6539\u7528 qxqy_studio_ui_screenshot\u3002\u4E0D\u4F1A\u6B65\u8FDB\u65F6\u95F4\uFF0C\u4E5F\u4E0D\u66FF\u4EE3 get {inspect:true} \u7684\u7ED3\u6784\u5316\u65AD\u8A00\u3002",parameters:{},output:{schema:{type:"json"},render:(i,n)=>{let o=[{type:"text",text:`\u8BD5\u73A9\u622A\u56FE\uFF1A${n.canvasId||"unknown"}\uFF0CFrame ${n.frame??0}\uFF0C${n.width||0}\xD7${n.height||0}`}];return n.image&&o.push({type:"image",attachment:n.image}),o}},timeoutMs:ba+1e3,isConcurrencySafe:()=>!1,async execute(i,n){let o=await t.get(Et(n),At(n)).requestScreenshot(n.signal),a=e.get?.("attachments");if(!a?.saveImage)throw new Error("Harness attachment service is unavailable; cannot return screenshot to AI");let s=await a.saveImage({data:o.data,mediaType:"image/png",name:`qxqy-play-${o.canvasId||"canvas"}-f${o.frame}.png`}),{data:c,...l}=o;return{...l,image:{attachmentId:s.attachmentId,mediaType:s.mediaType,bytes:s.bytes,width:s.width,height:s.height,...s.name===void 0?{}:{name:s.name}}}}})),e.tools.register(xt({name:"qxqy_studio_ui_screenshot",description:"\u83B7\u53D6\u5F53\u524D\u7F16\u8F91\u5668\u821E\u53F0\u7684 PNG\u3002Host \u6839\u636E boxes \u5728\u8FDB\u7A0B\u5185\u6E32\u67D3\uFF0C\u4E0D\u9700\u8981\u6253\u5F00\u6216\u4FDD\u6301\u201C\u6A21\u62DF\u5668\u201D\u6807\u7B7E\u3002\u7528\u4E8E\u68C0\u67E5\u9759\u6001 UI \u5E03\u5C40\u3001\u9009\u4E2D\u9879\u548C\u63A7\u4EF6\u56FE\u5143\uFF1B\u4E0D\u542B\u5B8C\u6574 Chrome DOM \u5DE5\u5177\u680F/\u68C0\u89C6\u5668\u3002\u82E5\u8981\u770B Lua Runtime \u8BD5\u73A9\u753B\u9762\uFF0C\u8BF7\u6539\u7528 qxqy_studio_play_screenshot\u3002",parameters:{},output:{schema:{type:"json"},render:(i,n)=>{let a=[{type:"text",text:`\u7F16\u8F91\u5668\u622A\u56FE\uFF1A${n.page||"\u6A21\u62DF\u5668"}\uFF0C${n.width||0}\xD7${n.height||0}`}];return n.image&&a.push({type:"image",attachment:n.image}),a}},timeoutMs:ba+1e3,isConcurrencySafe:()=>!1,async execute(i,n){let o=t.get(Et(n),At(n)).requestUiScreenshot(),a=e.get?.("attachments");if(!a?.saveImage)throw new Error("Harness attachment service is unavailable; cannot return screenshot to AI");let s=await a.saveImage({data:o.data,mediaType:"image/png",name:`qxqy-ui-${o.page||"editor"}.png`}),{data:c,...l}=o;return{...l,image:{attachmentId:s.attachmentId,mediaType:s.mediaType,bytes:s.bytes,width:s.width,height:s.height,...s.name===void 0?{}:{name:s.name}}}}})),e.tools.register(xt({name:"qxqy_studio_patch",description:"\u4FEE\u6539\u5F53\u524D\u4F1A\u8BDD\u7684\u5343\u661F UI \u5DE5\u7A0B\u3002op \u5FC5\u987B\u643A\u5E26 expectedRevision \u4EE5\u9632\u6B62\u9648\u65E7\u5199\u5165\u3002",parameters:{op:{type:"json",required:!0,description:"\u7F16\u8F91\u5668 patch \u5BF9\u8C61\u3002"}},output:{schema:{type:"json"},render:(i,n)=>[{type:"text",text:JSON.stringify(n,null,2)}]},timeoutMs:5e3,isConcurrencySafe:()=>!1,async execute(i,n){let r=Fi(i.op);if(!r)throw new Error("patch requires op");return t.get(Et(n),At(n)).patch(r)}})),e.tools.register(xt({name:"qxqy_studio_play",description:"\u63A7\u5236\u5F53\u524D\u4F1A\u8BDD\u7684\u5343\u661F UI \u8BD5\u73A9 Worker\uFF1A\u542F\u52A8\u3001\u6B65\u8FDB\u3001\u8F93\u5165\u3001\u6682\u505C\u3001\u505C\u6B62\u3001\u591A\u8BBE\u5907\u753B\u5E03\u5207\u6362\u3001\u591A\u4EBA\u89C6\u89D2\u3001\u670D\u52A1\u7AEF\u53D8\u91CF/\u4FE1\u53F7\uFF0C\u4EE5\u53CA\u5F55\u5236\u56DE\u653E\u7528\u4F8B\u3002",parameters:{action:{type:"string",enum:["start","device","view","get","step","pointer","key","click","pause","resume","stop","serverGet","serverSet","serverSend","history","saveCase","runCase"],required:!0},args:{type:"json",description:"\u52A8\u4F5C\u53C2\u6570\uFF1Bpointer \u4F7F\u7528 type/x/y\uFF0Cstep \u4F7F\u7528 dt\uFF1Bget/start \u53EF\u7528 inspect:true \u62C9\u8FD0\u884C\u6811\uFF1Bstart/device \u7528 canvasId \u5207\u6362\u8BBE\u5907\u753B\u5E03\uFF08\u5982 pc-16-9 / mobile-19.5-9\uFF09\uFF1Bstart \u53EF\u7528 playerCount(1-8)\uFF1Bview \u7528 playerIndex \u5207\u6362\u5F53\u524D\u73A9\u5BB6\u89C6\u89D2\uFF1BrunCase \u53EF\u5E26 canvasId/playerCount\uFF1BserverSet \u4F7F\u7528 entityType/name/value\uFF1BrunCase \u4F7F\u7528 case\u3002"}},output:{schema:{type:"json"},render:(i,n)=>[{type:"text",text:JSON.stringify(n,null,2)}]},timeoutMs:1e4,isConcurrencySafe:()=>!1,async execute(i,n){let r=Fi(i.args)||{};return t.get(Et(n),At(n)).play(i.action,r,n.signal)}})),e.tools.register(xt({name:"qxqy_studio_load",description:"\u4ECE\u5F53\u524D\u4F1A\u8BDD\u5DE5\u4F5C\u533A\u62C9\u53D6\u5343\u661F\u6A21\u62DF\u5668\u5B58\u6863\u3002\u4E0D\u4F20 path \u65F6\u5217\u51FA\u5DE5\u4F5C\u533A\u5185\u7684 qxqy-simulator-save\uFF1B\u4F20\u5165\u76F8\u5BF9\u8DEF\u5F84\u5219\u52A0\u8F7D\u8BE5\u5B58\u6863\u3002",parameters:{path:{type:"string",description:"\u5DE5\u4F5C\u533A\u5185\u76F8\u5BF9\u8DEF\u5F84\uFF0C\u4F8B\u5982 workspace/flappy-fish/flappy-fish.save.json\u3002\u7701\u7565\u5219\u53EA\u5217\u51FA\u53EF\u62C9\u53D6\u5B58\u6863\u3002"}},output:{schema:{type:"json"},render:(i,n)=>[{type:"text",text:JSON.stringify(n,null,2)}]},timeoutMs:8e3,isConcurrencySafe:()=>!1,async execute(i,n){let r=t.get(Et(n),At(n));return i.path?r.loadArchive(i.path):r.listArchives()}}))}function Ku(e,t){e.webServer.register({kind:"prefix",path:ga,async handler(i,n){if(i.method!=="POST"){Oi(n,405,{ok:!1,value:null,error:"POST required"});return}let o=new URL(i.url,"http://localhost").pathname.slice(ga.length).replace(/^\/+/,"");if(o==="health"){Oi(n,200,{ok:!0,value:{status:"ok"},error:null});return}let a=new AbortController;i.once("aborted",()=>a.abort());try{let s=await Hu(i),c=await zu(s.sessionId,{sessions:e.get?.("sessions"),sessionPersistence:e.get?.("sessionPersistence")}),l=t.get(s.sessionId,c),f;if(o==="get")f=l.get();else if(o==="patch")f=l.patch(s.op);else if(o==="export")f=l.exportData(s.format,s.assetType);else if(o==="import")f=l.importData(s.format,s.data,s.filename);else if(o==="archives")f=l.listArchives();else if(o==="load-archive")f=l.loadArchive(s.path);else if(o==="play")f=await l.play(s.action,s.args||{},a.signal);else throw new Error("unknown API action");Oi(n,200,{ok:!0,value:f,error:null})}catch(s){Oi(n,400,{ok:!1,value:null,error:s?.message||String(s)})}}})}function wd(e){let t=Gu();Xu(e,t),Ku(e,t),Bu(e),Uu(e),e.effect(()=>()=>{t.dispose()},"qxqy-simulator: dispose sessions")}export{Xn as SimulatorController,wd as apply,Kn as headerWorkspace,Sd as inject,Fi as jsonParam,zu as lookupSessionWorkspace,vd as name,At as sessionWorkspace};
|
|
@@ -922,7 +922,7 @@ fn mainFragment(
|
|
|
922
922
|
`),e.unshift(`
|
|
923
923
|
var stride = ${r};
|
|
924
924
|
`);let s=e.join(`
|
|
925
|
-
`);return new Function("ps","f32v","u32v",s)}var Ja=class{constructor(t){this._size=0,this._generateParticleUpdateCache={};let e=this._size=t.size??1e3,r=t.properties,s=0,n=0;for(let h in r){let u=r[h],d=Wt(u.format);u.dynamic?n+=d.stride:s+=d.stride}this._dynamicStride=n/4,this._staticStride=s/4,this.staticAttributeBuffer=new Ge(e*4*s),this.dynamicAttributeBuffer=new Ge(e*4*n),this.indexBuffer=Xu(e);let o=new Be,a=0,l=0;this._staticBuffer=new Ft({data:new Float32Array(1),label:"static-particle-buffer",shrinkToFit:!1,usage:it.VERTEX|it.COPY_DST}),this._dynamicBuffer=new Ft({data:new Float32Array(1),label:"dynamic-particle-buffer",shrinkToFit:!1,usage:it.VERTEX|it.COPY_DST});for(let h in r){let u=r[h],d=Wt(u.format);u.dynamic?(o.addAttribute(u.attributeName,{buffer:this._dynamicBuffer,stride:this._dynamicStride*4,offset:a*4,format:u.format}),a+=d.size):(o.addAttribute(u.attributeName,{buffer:this._staticBuffer,stride:this._staticStride*4,offset:l*4,format:u.format}),l+=d.size)}o.addIndex(this.indexBuffer);let c=this.getParticleUpdate(r);this._dynamicUpload=c.dynamicUpdate,this._staticUpload=c.staticUpdate,this.geometry=o}getParticleUpdate(t){let e=WE(t);return this._generateParticleUpdateCache[e]?this._generateParticleUpdateCache[e]:(this._generateParticleUpdateCache[e]=this.generateParticleUpdate(t),this._generateParticleUpdateCache[e])}generateParticleUpdate(t){return j0(t)}update(t,e){t.length>this._size&&(e=!0,this._size=Math.max(t.length,this._size*1.5|0),this.staticAttributeBuffer=new Ge(this._size*this._staticStride*4*4),this.dynamicAttributeBuffer=new Ge(this._size*this._dynamicStride*4*4),this.indexBuffer=Xu(this._size),this.geometry.indexBuffer.setDataWithSize(this.indexBuffer,this.indexBuffer.byteLength,!0));let r=this.dynamicAttributeBuffer;if(this._dynamicUpload(t,r.float32View,r.uint32View),this._dynamicBuffer.setDataWithSize(this.dynamicAttributeBuffer.float32View,t.length*this._dynamicStride*4,!0),e){let s=this.staticAttributeBuffer;this._staticUpload(t,s.float32View,s.uint32View),this._staticBuffer.setDataWithSize(s.float32View,t.length*this._staticStride*4,!0)}}destroy(){this._staticBuffer.destroy(),this._dynamicBuffer.destroy(),this.geometry.destroy()}};function WE(i){let t=[];for(let e in i){let r=i[e];t.push(e,r.code,r.dynamic?"d":"s")}return t.join("_")}dt();et();rr();mt();rc();xe();Iu();fo();Za();Gt();H.add(ym,vm);function $0(i,t,e){if(i.fillType!=="Horizontal"&&i.fillType!=="Vertical")return null;let r=Number(i.fillAmount??1),s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1;if(i.fillType==="Horizontal"){let o=t*s;return{x:i.fillHorizontalType==="Right"?t/2-o:-t/2,y:-e/2,width:o,height:e}}let n=e*s;return{x:-t/2,y:i.fillVerticalType==="Top"?-e/2:e/2-n,width:t,height:n}}Nh();jh();$h();Mh();ca();kr();sr();var K0={aVertex:(i,t,e,r,s)=>{let n=0,o=0,a=0,l=0;for(let c=0;c<i.length;++c){let h=i[c],u=h.texture,d=h.scaleX,f=h.scaleY,m=h.anchorX,g=h.anchorY,y=u.trim,x=u.orig;y?(o=y.x-m*x.width,n=o+y.width,l=y.y-g*x.height,a=l+y.height):(n=x.width*(1-m),o=x.width*-m,a=x.height*(1-g),l=x.height*-g),t[r]=o*d,t[r+1]=l*f,t[r+s]=n*d,t[r+s+1]=l*f,t[r+s*2]=n*d,t[r+s*2+1]=a*f,t[r+s*3]=o*d,t[r+s*3+1]=a*f,r+=s*4}},aPosition:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n],a=o.x,l=o.y;t[r]=a,t[r+1]=l,t[r+s]=a,t[r+s+1]=l,t[r+s*2]=a,t[r+s*2+1]=l,t[r+s*3]=a,t[r+s*3+1]=l,r+=s*4}},aRotation:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].rotation;t[r]=o,t[r+s]=o,t[r+s*2]=o,t[r+s*3]=o,r+=s*4}},aUV:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].texture.uvs;t[r]=o.x0,t[r+1]=o.y0,t[r+s]=o.x1,t[r+s+1]=o.y1,t[r+s*2]=o.x2,t[r+s*2+1]=o.y2,t[r+s*3]=o.x3,t[r+s*3+1]=o.y3,r+=s*4}},aColor:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].color;e[r]=o,e[r+s]=o,e[r+s*2]=o,e[r+s*3]=o,r+=s*4}}};function Z0(i){let t=Object.values(i),e=t.filter(s=>s.dynamic),r=t.filter(s=>!s.dynamic);return{dynamicUpdate:q0(e),staticUpdate:q0(r)}}function q0(i){let t=0,e=[];for(let r=0;r<i.length;r++){let s=i[r],n=Wt(s.format).stride/4;t+=n,e.push({stride:n,updateFunction:s.updateFunction||K0[s.attributeName]})}return(r,s,n)=>{let o=0;for(let a=0;a<e.length;a++){let l=e[a];l.updateFunction(r,s,n,o,t),o+=l.stride}}}Js();ce();Ot();xr();Hh();function Q0(){return VE}function VE(i,t,e){let r=i.gl,s=i.shader,n=s._getProgramData(t.glProgram);for(let o in t.groups){let a=t.groups[o];for(let l in a.resources){let c=a.resources[l];if(c instanceof St)c.ubo?s.bindUniformBlock(c,t._uniformBindMap[o][l],e.blockIndex++):s.updateUniformGroup(c);else if(c instanceof ke)s.bindUniformBlock(c,t._uniformBindMap[o][l],e.blockIndex++);else if(c instanceof J||c instanceof Gi){i.texture.bind(c,e.textureCount);let h=t._uniformBindMap[o][l],u=n.uniformData[h];u&&(u.value!==e.textureCount&&r.uniform1i(u.location,e.textureCount),e.textureCount++)}else c instanceof Qt}}}va();ha();Qs();var J0=[(i,t,e,r,s)=>{let n=r[i].toArray(!0);t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+4]=n[3],t[e+5]=n[4],t[e+6]=n[5],t[e+8]=n[6],t[e+9]=n[7],t[e+10]=n[8]},(i,t,e,r,s)=>{s=r[i],t[e]=s.x,t[e+1]=s.y,t[e+2]=s.width,t[e+3]=s.height},(i,t,e,r,s)=>{s=r[i],t[e]=s.x,t[e+1]=s.y},(i,t,e,r,s)=>{s=r[i],t[e]=s.red,t[e+1]=s.green,t[e+2]=s.blue,t[e+3]=s.alpha},(i,t,e,r,s)=>{s=r[i],t[e]=s.red,t[e+1]=s.green,t[e+2]=s.blue}],tv={f32:(i,t,e,r,s)=>{t[e]=s},i32:(i,t,e,r,s)=>{t[e]=s},"vec2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1]},"vec3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2]},"vec4<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat2x2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat3x3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+4]=s[3],t[e+5]=s[4],t[e+6]=s[5],t[e+8]=s[6],t[e+9]=s[7],t[e+10]=s[8]},"mat4x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<16;n++)t[e+n]=s[n]},"mat3x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/3|0)*4+n%3]=s[n]},"mat4x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat4x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat3x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/3|0)*4+n%3]=s[n]}},ev={f32:(i,t,e,r,s)=>{t[e]=s},i32:(i,t,e,r,s)=>{t[e]=s},"vec2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1]},"vec3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2]},"vec4<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat2x2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+4]=s[2],t[e+5]=s[3]},"mat3x3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+4]=s[3],t[e+5]=s[4],t[e+6]=s[5],t[e+8]=s[6],t[e+9]=s[7],t[e+10]=s[8]},"mat4x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<16;n++)t[e+n]=s[n]},"mat3x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/3|0)*4+n%3]=s[n]},"mat4x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat4x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat3x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/3|0)*4+n%3]=s[n]}};function rv(i){return sv(i,ev,t=>{let e=Math.max(_n[t.data.type]/16,1),r=t.data.value.length/t.data.size,s=(4-r%4)%4;return(n,o,a,l,c)=>{let h=0;for(let u=0;u<t.data.size*e;u++){for(let d=0;d<r;d++)o[a++]=c[h++];a+=s}}})}function iv(i){return sv(i,tv,t=>{let{size:e,align:r}=Nr[t.data.type],s=(e-r)/4;return(n,o,a,l,c)=>{let h=0;for(let u=0;u<t.data.size*(e/4);u++){for(let d=0;d<e/4;d++)o[a++]=c[h++];a+=s}}})}function sv(i,t,e){let r={};for(let s in i){let n=i[s],o=n.data,a=!1;r[o.name]={offset:n.offset/4,func:null};for(let l=0;l<Jt.length;l++){let c=Jt[l];if(o.type===c.type&&c.test(o)){r[o.name].func=J0[l],a=!0;break}}a||(o.size===1?r[o.name].func=t[o.type]:r[o.name].func=e(n))}return(s,n,o)=>{for(let a in r)r[a].func(a,n,o+r[a].offset,s,s[a])}}Qs();var nv={f32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1f(s[i].location,r))},"vec2<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2f(s[i].location,r[0],r[1]))},"vec3<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3f(s[i].location,r[0],r[1],r[2]))},"vec4<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4f(s[i].location,r[0],r[1],r[2],r[3]))},i32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1i(s[i].location,r))},"vec2<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2i(s[i].location,r[0],r[1]))},"vec3<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3i(s[i].location,r[0],r[1],r[2]))},"vec4<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4i(s[i].location,r[0],r[1],r[2],r[3]))},u32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1ui(s[i].location,r))},"vec2<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2ui(s[i].location,r[0],r[1]))},"vec3<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3ui(s[i].location,r[0],r[1],r[2]))},"vec4<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4ui(s[i].location,r[0],r[1],r[2],r[3]))},bool(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1i(s[i].location,r))},"vec2<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2i(s[i].location,r[0],r[1]))},"vec3<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3i(s[i].location,r[0],r[1],r[2]))},"vec4<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4i(s[i].location,r[0],r[1],r[2],r[3]))},"mat2x2<f32>"(i,t,e,r,s,n,o){o.uniformMatrix2fv(s[i].location,!1,r)},"mat3x3<f32>"(i,t,e,r,s,n,o){o.uniformMatrix3fv(s[i].location,!1,r)},"mat4x4<f32>"(i,t,e,r,s,n,o){o.uniformMatrix4fv(s[i].location,!1,r)}},ov={f32(i,t,e,r,s,n,o){o.uniform1fv(s[i].location,r)},"vec2<f32>"(i,t,e,r,s,n,o){o.uniform2fv(s[i].location,r)},"vec3<f32>"(i,t,e,r,s,n,o){o.uniform3fv(s[i].location,r)},"vec4<f32>"(i,t,e,r,s,n,o){o.uniform4fv(s[i].location,r)},"mat2x2<f32>"(i,t,e,r,s,n,o){o.uniformMatrix2fv(s[i].location,!1,r)},"mat3x3<f32>"(i,t,e,r,s,n,o){o.uniformMatrix3fv(s[i].location,!1,r)},"mat4x4<f32>"(i,t,e,r,s,n,o){o.uniformMatrix4fv(s[i].location,!1,r)},i32(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<i32>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<i32>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<i32>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)},u32(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<u32>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<u32>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<u32>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)},bool(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<bool>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<bool>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<bool>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)}},av=[(i,t,e,r,s,n,o)=>{o.uniformMatrix3fv(s[i].location,!1,n[i].toArray(!0))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.x||e[1]!==r.y||e[2]!==r.width||e[3]!==r.height)&&(e[0]=r.x,e[1]=r.y,e[2]=r.width,e[3]=r.height,o.uniform4f(s[i].location,r.x,r.y,r.width,r.height))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.x||e[1]!==r.y)&&(e[0]=r.x,e[1]=r.y,o.uniform2f(s[i].location,r.x,r.y))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.red||e[1]!==r.green||e[2]!==r.blue||e[3]!==r.alpha)&&(e[0]=r.red,e[1]=r.green,e[2]=r.blue,e[3]=r.alpha,o.uniform4f(s[i].location,r.red,r.green,r.blue,r.alpha))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.red||e[1]!==r.green||e[2]!==r.blue)&&(e[0]=r.red,e[1]=r.green,e[2]=r.blue,o.uniform3f(s[i].location,r.red,r.green,r.blue))}];function lv(i,t){let e={};for(let r in i.uniformStructures){if(!t[r])continue;let s=i.uniformStructures[r],n=!1;for(let o=0;o<Jt.length;o++){let a=Jt[o];if(s.type===a.type&&a.test(s)){e[r]=av[o],n=!0;break}}if(!n){let o=s.size===1?nv:ov;e[r]=o[s.type]}}return(r,s,n)=>{let o=n.gl;for(let a in e){let l=s[a],c=r[a],h=r[a].value;e[a](a,c,h,l,r,s,o)}}}function zE(){Object.assign(ue.prototype,{_unsafeEvalCheck(){}}),Object.assign(cr.prototype,{_systemCheck(){}}),Object.assign(zr.prototype,{_generateUniformsSync:lv}),Object.assign(Wr.prototype,{_generateUboSync:rv}),Object.assign(Hr.prototype,{_generateUboSync:iv}),Object.assign(Vr.prototype,{_generateShaderSync:Q0}),Object.assign(Ja.prototype,{generateParticleUpdate:Z0})}zE();var cv=33;function Yu(i,t){let e=i.code&&String(i.code).startsWith("Digit")?String(i.code).slice(5):"";return e&&Number(e)>=1&&Number(e)<=9?`KeyboardCraftspersonKey${e}${t}`:""}function hv(i,t,e,r){return{x:(i.clientX-t.left)*e/t.width,y:(t.bottom-i.clientY)*r/t.height}}function uv({renderer:i,api:t,onSnapshot:e,onStatus:r,onError:s,isActive:n}={}){let o=null,a=!1,l=!1,c=null,h=null,u=0,d=null,f=null,m=[];function g(F){s&&s(F)}async function y(F){o=F,a=F?.running!==!1,F?.scene&&F.scene.format==="tree-v1"?(F.scene.reset&&(u=0),await i.applyScene(F.scene,F.canvasWidth,F.canvasHeight),u=F.scene.revision||u):Array.isArray(F?.paint)&&await i.render(F.paint,F.canvasWidth,F.canvasHeight),e&&await e(F)}async function x(){if(!(!a||l)&&!(n&&!n())){l=!0;try{await y(await t("get",{view:!0,sceneRev:u,compact:!0}))}catch(F){a=!1,v(),g(F)}finally{l=!1}}}function b(){c||(c=setInterval(()=>{x()},33))}function v(){c&&clearInterval(c),c=null,h&&clearTimeout(h),h=null}function T(F=30){h||(h=setTimeout(()=>{h=null,x()},F))}function S(){a=!1,u=0,v()}async function E(F,A){if(n&&!n())return null;try{let k=await t(F,{light:!0,...A||{}});return k&&typeof k=="object"&&k.frame!==void 0&&r&&r(k),T(30),k}catch(k){return g(k),null}}async function w(F={}){u=0;let A=await t("start",{view:!0,compact:!0,...F});return await y({...A,running:!0}),a=!0,v(),b(),A}async function I(){u=0,v();let F=await t("get",{view:!0,compact:!0,sceneRev:0});return await y(F),a&&b(),F}async function G(F={}){u=0,v();let A=await t("device",{view:!0,compact:!0,...F});return await y({...A,running:!0}),a=!0,b(),A}async function M(F={}){u=0;let A=await t("view",{view:!0,compact:!0,...F});return await y({...A,running:!0}),A}async function C(){return S(),t("stop")}function R(F,A){return hv(F,A.getBoundingClientRect(),o.canvasWidth,o.canvasHeight)}function L(F,{keysOn:A}={}){let k=A||F,X=z=>{!o||!a||n&&!n()||(F.setPointerCapture?.(z.pointerId),E("pointer",{type:"down",...R(z,F)}))},D=z=>{!o||!a||n&&!n()||E("pointer",{type:"up",...R(z,F)})},Z=z=>{!o||!a||n&&!n()||(f=R(z,F),!d&&(d=setTimeout(()=>{d=null,f&&E("pointer",{type:"move",...f})},60)))},ht=()=>{o&&a&&(!n||n())&&E("pointer",{type:"move",x:-1,y:-1})},xt=z=>{if(!o||!a||n&&!n())return;let Dt=Yu(z,"Down");Dt&&(z.preventDefault(),E("key",{key:Dt}))},st=z=>{if(!o||!a||n&&!n())return;let Dt=Yu(z,"Up");Dt&&(z.preventDefault(),E("key",{key:Dt}))};F.addEventListener("pointerdown",X),F.addEventListener("pointerup",D),F.addEventListener("pointermove",Z),F.addEventListener("pointerleave",ht),k.addEventListener("keydown",xt),k.addEventListener("keyup",st);let at=()=>{F.removeEventListener("pointerdown",X),F.removeEventListener("pointerup",D),F.removeEventListener("pointermove",Z),F.removeEventListener("pointerleave",ht),k.removeEventListener("keydown",xt),k.removeEventListener("keyup",st),d&&clearTimeout(d),d=null};return m.push(at),at}function V(){for(S();m.length;)m.pop()();i?.destroy?.()}return{get snapshot(){return o},get running(){return a},get sceneRev(){return u},applyScene:y,poll:x,pollSoon:T,startPolling:b,stopPolling:v,reset:S,act:E,start:w,attach:I,device:G,view:M,stop:C,bindInput:L,destroy:V}}var XE=[0,-.5,.5,.5,-.5,.5],YE=[0,-.5,.12,-.12,.5,0,.12,.12,0,.5,-.12,.12,-.5,0,-.12,-.12],jE=[0,-.5,.11,-.15,.48,-.15,.18,.07,.29,.41,0,.2,-.29,.41,-.18,.07,-.48,-.15,-.11,-.15],$E=new Set(["image","textbox","textwindow","button"]);function Ln(i,t=4294967295){let e=Number(i??t)>>>0;return{color:e&16777215,alpha:(e>>>24&255)/255}}function Zt(i,t=0){let e=Number(i);return Number.isFinite(e)?e:t}function KE(i){let t=i?.matrix;if(!t||typeof t!="object")return null;let e=[t.a,t.b,t.c,t.d,t.tx,t.ty].map(Number);return e.every(Number.isFinite)?e:null}function qE(i){let t=i.horizontalAlignment==="Right"?1:i.horizontalAlignment==="Middle"?.5:0,e=i.verticalAlignment==="Bottom"?1:i.verticalAlignment==="Middle"?.5:0;return{x:t,y:e}}function ZE(i,t,e){let r=i.primitive==="triangle"?XE:i.primitive==="fourstar"?YE:jE,s=[];for(let n=0;n<r.length;n+=2)s.push(r[n]*t,r[n+1]*e);return s}function QE(i,t,e){return dv(i)?[i.kind,i.primitive,i.imageId,"sprite"].join(" "):[i.kind,i.primitive,t,e,i.imageColor,i.imageId,i.fillType,i.fillHorizontalType,i.fillVerticalType,i.fillAmount,i.text,i.fontSize,i.fontColor,i.bgColor,i.enableOutline,i.outlineColor,i.horizontalAlignment,i.verticalAlignment,i.pressed].join(" ")}function dv(i){return i.kind==="image"&&i.primitive==="circle"&&(!i.fillType||i.fillType==="Unused")}function JE(i){let t=W.get().createCanvas(i,i);t.width=t.height=i;let e=t.getContext("2d");return e.fillStyle="#ffffff",e.beginPath(),e.arc(i/2,i/2,i/2,0,Math.PI*2),e.fill(),new U({source:new vt({resource:t,width:i,height:i,resolution:1})})}var ju=class{constructor(t){this.canvas=t,this.app=null,this.nodes=new Map,this.circleTextures=new Map,this.canvasWidth=0,this.canvasHeight=0,this.scratch=new B,this.ready=this.initialize()}async initialize(){let t=new za;await t.init({canvas:this.canvas,width:1,height:1,autoStart:!1,autoDensity:!1,resolution:Math.min(2,window.devicePixelRatio||1),antialias:!0,backgroundAlpha:0,preference:"webgl",powerPreference:"high-performance"}),t.ticker.stop(),t.stage.eventMode="none",t.stage.sortableChildren=!0,this.app=t}resize(t,e){let r=Math.max(1,Math.round(Zt(t,1))),s=Math.max(1,Math.round(Zt(e,1)));r===this.canvasWidth&&s===this.canvasHeight||(this.canvasWidth=r,this.canvasHeight=s,this.app.renderer.resize(r,s))}createNode(t,{group:e=!1}={}){let r=new ut({isRenderGroup:!!e});return r.label=`runtime:${t.id}`,r.eventMode="none",r.sortableChildren=!0,r.__runtimeId=t.id,r.__group=!!e,this.nodes.set(t.id,r),this.app.stage.addChild(r),r}clearVisual(t){t.__visual&&(t.removeChild(t.__visual),t.__visual.destroy({children:!0,context:!0}),t.__visual=null,t.__visualKey="")}circleTexture(t){let e=this.app?.renderer.resolution||2,r=Math.min(4096,Math.max(256,2**Math.ceil(Math.log2(Math.max(1,t*e)))));this.circleTextures||=new Map;let s=this.circleTextures.get(r);return s||(s=JE(r),this.circleTextures.set(r,s)),s}replaceVisual(t,e,r,s){if(this.clearVisual(t),!$E.has(e.kind))return;let n=new ut;if(n.eventMode="none",n.label=`visual:${e.id}`,e.kind==="textbox"||e.kind==="textwindow"){let o=new Se,a=Ln(e.bgColor,16777215);o.rect(-r/2,-s/2,r,s).fill(a),n.addChild(o);let l=Math.max(8,Zt(e.fontSize,12)),c=qE(e),h=new On({text:String(e.text||""),style:new qe({fontFamily:'Inter, "Microsoft YaHei UI", "Microsoft YaHei", sans-serif',fontSize:l,fill:Ln(e.fontColor,4294967295),stroke:e.enableOutline?{color:Ln(e.outlineColor,4278190080).color,width:Math.max(2,l*.12),join:"round"}:void 0,wordWrap:!0,wordWrapWidth:Math.max(4,r-4),breakWords:!0,align:c.x===1?"right":c.x===.5?"center":"left",lineHeight:l*1.2})});h.anchor.set(c.x,c.y),h.x=c.x===0?-r/2+2:c.x===1?r/2-2:0,h.y=c.y===0?-s/2:c.y===1?s/2:0;let u=new Se().rect(-r/2,-s/2,r,s).fill({color:16777215,alpha:1});h.mask=u,n.addChild(u,h)}else if(e.kind==="button"){let o=new Se;o.roundRect(-r/2,-s/2,r,s,6).fill({color:3303631,alpha:1}),o.roundRect(-r/2,-s/2,r,s,6).stroke({color:7381247,alpha:.8,width:1}),e.pressed&&o.roundRect(-r/2,-s/2,r,s,6).fill({color:0,alpha:.28}),n.addChild(o)}else if(dv(e)){let o=new Me({texture:this.circleTexture(Math.min(r,s)),anchor:.5});n.__circle=o,n.addChild(o)}else{let o=new Se,a=Ln(e.imageColor,4294967295);e.primitive==="missing"?(o.rect(-r/2,-s/2,r,s).fill({color:4727336,alpha:.36}),o.rect(-r/2+.5,-s/2+.5,Math.max(0,r-1),Math.max(0,s-1)).stroke({color:16741505,alpha:1,width:1})):e.primitive==="circle"?o.circle(0,0,Math.min(r,s)/2).fill(a):e.primitive==="ring"?o.circle(0,0,Math.max(1,Math.min(r,s)/2-3.5)).stroke({...a,width:7}):e.primitive==="triangle"||e.primitive==="fourstar"||e.primitive==="fivestar"?o.poly(ZE(e,r,s)).fill(a):o.rect(-r/2,-s/2,r,s).fill(a);let l=$0(e,r,s);if(l&&(o.visible=l.width>0&&l.height>0,o.visible)){let c=new Se().rect(l.x,l.y,l.width,l.height).fill({color:16777215,alpha:1});o.mask=c,n.addChild(c)}n.addChild(o)}n.scale.set(e.pressed?.98:1),t.addChildAt(n,0),t.__visual=n}applyMatrix(t,e,r){let s=KE(e);if(!s){let u=Math.max(0,Zt(e.sourceWidth,Zt(e.width))),d=Math.max(0,Zt(e.sourceHeight,Zt(e.height)));t.x=Zt(e.left)+u/2,t.y=this.canvasHeight-Zt(e.bottom)-d/2,t.rotation=-Zt(e.rotationZ)*Math.PI/180,t.scale.set(1);return}let[n,o,a,l,c,h]=s;this.scratch.set(n,-o,-a,l,c,r?-h:this.canvasHeight-h),t.setFromMatrix(this.scratch)}updateNode(t,e,{nested:r=!1}={}){let s=Math.max(0,Zt(e.sourceWidth,Zt(e.width))),n=Math.max(0,Zt(e.sourceHeight,Zt(e.height))),o=QE(e,s,n);t.__visualKey!==o&&(this.replaceVisual(t,e,s,n),t.__visualKey=o),t.__visual&&t.__visual.scale.set(e.pressed?.98:1);let a=t.__visual?.__circle;if(a){let l=Math.min(s,n),c=Ln(e.imageColor,4294967295);a.texture=this.circleTexture(l),a.width=a.height=l,a.tint=c.color,a.alpha=c.alpha,a.visible=l>0}this.applyMatrix(t,e,r)}attachNode(t,e){let r=e.parent,n=(r==null?this.app.stage:this.nodes.get(r))||this.app.stage;t.parent!==n&&n.addChild(t),n.sortableChildren=!0,t.zIndex=-Zt(e.z)}upsertSceneNode(t){if(!t||t.id===void 0||t.id===null)return;let e=t.group===!0,r=this.nodes.get(t.id);r?r.__group!==e&&(e?r.enableRenderGroup?.():r.disableRenderGroup?.(),r.__group=e):r=this.createNode(t,{group:e}),this.updateNode(r,t,{nested:t.parent!=null}),this.attachNode(r,t)}removeNode(t){let e=this.nodes.get(t);if(e){for(let r of[...e.children])r.__runtimeId!=null&&e.removeChild(r);e.parent?.removeChild(e),this.clearVisual(e),e.destroy({children:!1}),this.nodes.delete(t)}}clearNodes(){for(let t of[...this.nodes.keys()])this.removeNode(t)}async applyScene(t,e,r){if(await this.ready,this.resize(e,r),!t||t.format!=="tree-v1"){this.app.render();return}t.reset&&this.clearNodes();for(let n of t.removed||[])this.removeNode(n);let s=t.reset?t.nodes:t.changed;for(let n=0;n<(s||[]).length;n+=1){let o=s[n];!o||o.id===void 0||o.id===null||this.nodes.has(o.id)||this.createNode(o,{group:o.group===!0})}for(let n=0;n<(s||[]).length;n+=1)this.upsertSceneNode(s[n]);this.app.render()}async render(t,e,r){await this.ready,this.resize(e,r);let s=new Set,n=Array.isArray(t)?t:[];for(let o=0;o<n.length;o+=1){let a=n[o];if(!a||a.id===void 0||a.id===null)continue;s.add(a.id);let l=this.nodes.get(a.id)||this.createNode(a);this.updateNode(l,a),l.zIndex=o,l.parent!==this.app.stage&&this.app.stage.addChild(l)}for(let[o]of this.nodes)s.has(o)||this.removeNode(o);this.app.render()}destroy(){this.clearNodes();for(let t of this.circleTextures.values())t.destroy(!0);this.circleTextures.clear(),this.app?.destroy({removeView:!1},{children:!0,texture:!0,textureSource:!0}),this.app=null}};export{cv as PLAY_POLL_INTERVAL_MS,ju as PixiPlayRenderer,uv as createPlaySession};
|
|
925
|
+
`);return new Function("ps","f32v","u32v",s)}var Ja=class{constructor(t){this._size=0,this._generateParticleUpdateCache={};let e=this._size=t.size??1e3,r=t.properties,s=0,n=0;for(let h in r){let u=r[h],d=Wt(u.format);u.dynamic?n+=d.stride:s+=d.stride}this._dynamicStride=n/4,this._staticStride=s/4,this.staticAttributeBuffer=new Ge(e*4*s),this.dynamicAttributeBuffer=new Ge(e*4*n),this.indexBuffer=Xu(e);let o=new Be,a=0,l=0;this._staticBuffer=new Ft({data:new Float32Array(1),label:"static-particle-buffer",shrinkToFit:!1,usage:it.VERTEX|it.COPY_DST}),this._dynamicBuffer=new Ft({data:new Float32Array(1),label:"dynamic-particle-buffer",shrinkToFit:!1,usage:it.VERTEX|it.COPY_DST});for(let h in r){let u=r[h],d=Wt(u.format);u.dynamic?(o.addAttribute(u.attributeName,{buffer:this._dynamicBuffer,stride:this._dynamicStride*4,offset:a*4,format:u.format}),a+=d.size):(o.addAttribute(u.attributeName,{buffer:this._staticBuffer,stride:this._staticStride*4,offset:l*4,format:u.format}),l+=d.size)}o.addIndex(this.indexBuffer);let c=this.getParticleUpdate(r);this._dynamicUpload=c.dynamicUpdate,this._staticUpload=c.staticUpdate,this.geometry=o}getParticleUpdate(t){let e=WE(t);return this._generateParticleUpdateCache[e]?this._generateParticleUpdateCache[e]:(this._generateParticleUpdateCache[e]=this.generateParticleUpdate(t),this._generateParticleUpdateCache[e])}generateParticleUpdate(t){return j0(t)}update(t,e){t.length>this._size&&(e=!0,this._size=Math.max(t.length,this._size*1.5|0),this.staticAttributeBuffer=new Ge(this._size*this._staticStride*4*4),this.dynamicAttributeBuffer=new Ge(this._size*this._dynamicStride*4*4),this.indexBuffer=Xu(this._size),this.geometry.indexBuffer.setDataWithSize(this.indexBuffer,this.indexBuffer.byteLength,!0));let r=this.dynamicAttributeBuffer;if(this._dynamicUpload(t,r.float32View,r.uint32View),this._dynamicBuffer.setDataWithSize(this.dynamicAttributeBuffer.float32View,t.length*this._dynamicStride*4,!0),e){let s=this.staticAttributeBuffer;this._staticUpload(t,s.float32View,s.uint32View),this._staticBuffer.setDataWithSize(s.float32View,t.length*this._staticStride*4,!0)}}destroy(){this._staticBuffer.destroy(),this._dynamicBuffer.destroy(),this.geometry.destroy()}};function WE(i){let t=[];for(let e in i){let r=i[e];t.push(e,r.code,r.dynamic?"d":"s")}return t.join("_")}dt();et();rr();mt();rc();xe();Iu();fo();Za();Gt();H.add(ym,vm);function $0(i,t,e){if(i.fillType!=="Horizontal"&&i.fillType!=="Vertical")return null;let r=Number(i.fillAmount??1),s=Number.isFinite(r)?Math.max(0,Math.min(1,r)):1;if(i.fillType==="Horizontal"){let o=t*s;return{x:i.fillHorizontalType==="Right"?t/2-o:-t/2,y:-e/2,width:o,height:e}}let n=e*s;return{x:-t/2,y:i.fillVerticalType==="Top"?-e/2:e/2-n,width:t,height:n}}Nh();jh();$h();Mh();ca();kr();sr();var K0={aVertex:(i,t,e,r,s)=>{let n=0,o=0,a=0,l=0;for(let c=0;c<i.length;++c){let h=i[c],u=h.texture,d=h.scaleX,f=h.scaleY,m=h.anchorX,g=h.anchorY,y=u.trim,x=u.orig;y?(o=y.x-m*x.width,n=o+y.width,l=y.y-g*x.height,a=l+y.height):(n=x.width*(1-m),o=x.width*-m,a=x.height*(1-g),l=x.height*-g),t[r]=o*d,t[r+1]=l*f,t[r+s]=n*d,t[r+s+1]=l*f,t[r+s*2]=n*d,t[r+s*2+1]=a*f,t[r+s*3]=o*d,t[r+s*3+1]=a*f,r+=s*4}},aPosition:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n],a=o.x,l=o.y;t[r]=a,t[r+1]=l,t[r+s]=a,t[r+s+1]=l,t[r+s*2]=a,t[r+s*2+1]=l,t[r+s*3]=a,t[r+s*3+1]=l,r+=s*4}},aRotation:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].rotation;t[r]=o,t[r+s]=o,t[r+s*2]=o,t[r+s*3]=o,r+=s*4}},aUV:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].texture.uvs;t[r]=o.x0,t[r+1]=o.y0,t[r+s]=o.x1,t[r+s+1]=o.y1,t[r+s*2]=o.x2,t[r+s*2+1]=o.y2,t[r+s*3]=o.x3,t[r+s*3+1]=o.y3,r+=s*4}},aColor:(i,t,e,r,s)=>{for(let n=0;n<i.length;++n){let o=i[n].color;e[r]=o,e[r+s]=o,e[r+s*2]=o,e[r+s*3]=o,r+=s*4}}};function Z0(i){let t=Object.values(i),e=t.filter(s=>s.dynamic),r=t.filter(s=>!s.dynamic);return{dynamicUpdate:q0(e),staticUpdate:q0(r)}}function q0(i){let t=0,e=[];for(let r=0;r<i.length;r++){let s=i[r],n=Wt(s.format).stride/4;t+=n,e.push({stride:n,updateFunction:s.updateFunction||K0[s.attributeName]})}return(r,s,n)=>{let o=0;for(let a=0;a<e.length;a++){let l=e[a];l.updateFunction(r,s,n,o,t),o+=l.stride}}}Js();ce();Ot();xr();Hh();function Q0(){return VE}function VE(i,t,e){let r=i.gl,s=i.shader,n=s._getProgramData(t.glProgram);for(let o in t.groups){let a=t.groups[o];for(let l in a.resources){let c=a.resources[l];if(c instanceof St)c.ubo?s.bindUniformBlock(c,t._uniformBindMap[o][l],e.blockIndex++):s.updateUniformGroup(c);else if(c instanceof ke)s.bindUniformBlock(c,t._uniformBindMap[o][l],e.blockIndex++);else if(c instanceof J||c instanceof Gi){i.texture.bind(c,e.textureCount);let h=t._uniformBindMap[o][l],u=n.uniformData[h];u&&(u.value!==e.textureCount&&r.uniform1i(u.location,e.textureCount),e.textureCount++)}else c instanceof Qt}}}va();ha();Qs();var J0=[(i,t,e,r,s)=>{let n=r[i].toArray(!0);t[e]=n[0],t[e+1]=n[1],t[e+2]=n[2],t[e+4]=n[3],t[e+5]=n[4],t[e+6]=n[5],t[e+8]=n[6],t[e+9]=n[7],t[e+10]=n[8]},(i,t,e,r,s)=>{s=r[i],t[e]=s.x,t[e+1]=s.y,t[e+2]=s.width,t[e+3]=s.height},(i,t,e,r,s)=>{s=r[i],t[e]=s.x,t[e+1]=s.y},(i,t,e,r,s)=>{s=r[i],t[e]=s.red,t[e+1]=s.green,t[e+2]=s.blue,t[e+3]=s.alpha},(i,t,e,r,s)=>{s=r[i],t[e]=s.red,t[e+1]=s.green,t[e+2]=s.blue}],tv={f32:(i,t,e,r,s)=>{t[e]=s},i32:(i,t,e,r,s)=>{t[e]=s},"vec2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1]},"vec3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2]},"vec4<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat2x2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat3x3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+4]=s[3],t[e+5]=s[4],t[e+6]=s[5],t[e+8]=s[6],t[e+9]=s[7],t[e+10]=s[8]},"mat4x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<16;n++)t[e+n]=s[n]},"mat3x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/3|0)*4+n%3]=s[n]},"mat4x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat4x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat3x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/3|0)*4+n%3]=s[n]}},ev={f32:(i,t,e,r,s)=>{t[e]=s},i32:(i,t,e,r,s)=>{t[e]=s},"vec2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1]},"vec3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2]},"vec4<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+3]=s[3]},"mat2x2<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+4]=s[2],t[e+5]=s[3]},"mat3x3<f32>":(i,t,e,r,s)=>{t[e]=s[0],t[e+1]=s[1],t[e+2]=s[2],t[e+4]=s[3],t[e+5]=s[4],t[e+6]=s[5],t[e+8]=s[6],t[e+9]=s[7],t[e+10]=s[8]},"mat4x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<16;n++)t[e+n]=s[n]},"mat3x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/3|0)*4+n%3]=s[n]},"mat4x2<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<6;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat4x3<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/4|0)*4+n%4]=s[n]},"mat2x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<8;n++)t[e+(n/2|0)*4+n%2]=s[n]},"mat3x4<f32>":(i,t,e,r,s)=>{for(let n=0;n<12;n++)t[e+(n/3|0)*4+n%3]=s[n]}};function rv(i){return sv(i,ev,t=>{let e=Math.max(_n[t.data.type]/16,1),r=t.data.value.length/t.data.size,s=(4-r%4)%4;return(n,o,a,l,c)=>{let h=0;for(let u=0;u<t.data.size*e;u++){for(let d=0;d<r;d++)o[a++]=c[h++];a+=s}}})}function iv(i){return sv(i,tv,t=>{let{size:e,align:r}=Nr[t.data.type],s=(e-r)/4;return(n,o,a,l,c)=>{let h=0;for(let u=0;u<t.data.size*(e/4);u++){for(let d=0;d<e/4;d++)o[a++]=c[h++];a+=s}}})}function sv(i,t,e){let r={};for(let s in i){let n=i[s],o=n.data,a=!1;r[o.name]={offset:n.offset/4,func:null};for(let l=0;l<Jt.length;l++){let c=Jt[l];if(o.type===c.type&&c.test(o)){r[o.name].func=J0[l],a=!0;break}}a||(o.size===1?r[o.name].func=t[o.type]:r[o.name].func=e(n))}return(s,n,o)=>{for(let a in r)r[a].func(a,n,o+r[a].offset,s,s[a])}}Qs();var nv={f32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1f(s[i].location,r))},"vec2<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2f(s[i].location,r[0],r[1]))},"vec3<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3f(s[i].location,r[0],r[1],r[2]))},"vec4<f32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4f(s[i].location,r[0],r[1],r[2],r[3]))},i32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1i(s[i].location,r))},"vec2<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2i(s[i].location,r[0],r[1]))},"vec3<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3i(s[i].location,r[0],r[1],r[2]))},"vec4<i32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4i(s[i].location,r[0],r[1],r[2],r[3]))},u32(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1ui(s[i].location,r))},"vec2<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2ui(s[i].location,r[0],r[1]))},"vec3<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3ui(s[i].location,r[0],r[1],r[2]))},"vec4<u32>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4ui(s[i].location,r[0],r[1],r[2],r[3]))},bool(i,t,e,r,s,n,o){e!==r&&(t.value=r,o.uniform1i(s[i].location,r))},"vec2<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1])&&(e[0]=r[0],e[1]=r[1],o.uniform2i(s[i].location,r[0],r[1]))},"vec3<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],o.uniform3i(s[i].location,r[0],r[1],r[2]))},"vec4<bool>"(i,t,e,r,s,n,o){(e[0]!==r[0]||e[1]!==r[1]||e[2]!==r[2]||e[3]!==r[3])&&(e[0]=r[0],e[1]=r[1],e[2]=r[2],e[3]=r[3],o.uniform4i(s[i].location,r[0],r[1],r[2],r[3]))},"mat2x2<f32>"(i,t,e,r,s,n,o){o.uniformMatrix2fv(s[i].location,!1,r)},"mat3x3<f32>"(i,t,e,r,s,n,o){o.uniformMatrix3fv(s[i].location,!1,r)},"mat4x4<f32>"(i,t,e,r,s,n,o){o.uniformMatrix4fv(s[i].location,!1,r)}},ov={f32(i,t,e,r,s,n,o){o.uniform1fv(s[i].location,r)},"vec2<f32>"(i,t,e,r,s,n,o){o.uniform2fv(s[i].location,r)},"vec3<f32>"(i,t,e,r,s,n,o){o.uniform3fv(s[i].location,r)},"vec4<f32>"(i,t,e,r,s,n,o){o.uniform4fv(s[i].location,r)},"mat2x2<f32>"(i,t,e,r,s,n,o){o.uniformMatrix2fv(s[i].location,!1,r)},"mat3x3<f32>"(i,t,e,r,s,n,o){o.uniformMatrix3fv(s[i].location,!1,r)},"mat4x4<f32>"(i,t,e,r,s,n,o){o.uniformMatrix4fv(s[i].location,!1,r)},i32(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<i32>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<i32>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<i32>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)},u32(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<u32>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<u32>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<u32>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)},bool(i,t,e,r,s,n,o){o.uniform1iv(s[i].location,r)},"vec2<bool>"(i,t,e,r,s,n,o){o.uniform2iv(s[i].location,r)},"vec3<bool>"(i,t,e,r,s,n,o){o.uniform3iv(s[i].location,r)},"vec4<bool>"(i,t,e,r,s,n,o){o.uniform4iv(s[i].location,r)}},av=[(i,t,e,r,s,n,o)=>{o.uniformMatrix3fv(s[i].location,!1,n[i].toArray(!0))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.x||e[1]!==r.y||e[2]!==r.width||e[3]!==r.height)&&(e[0]=r.x,e[1]=r.y,e[2]=r.width,e[3]=r.height,o.uniform4f(s[i].location,r.x,r.y,r.width,r.height))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.x||e[1]!==r.y)&&(e[0]=r.x,e[1]=r.y,o.uniform2f(s[i].location,r.x,r.y))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.red||e[1]!==r.green||e[2]!==r.blue||e[3]!==r.alpha)&&(e[0]=r.red,e[1]=r.green,e[2]=r.blue,e[3]=r.alpha,o.uniform4f(s[i].location,r.red,r.green,r.blue,r.alpha))},(i,t,e,r,s,n,o)=>{e=s[i].value,r=n[i],(e[0]!==r.red||e[1]!==r.green||e[2]!==r.blue)&&(e[0]=r.red,e[1]=r.green,e[2]=r.blue,o.uniform3f(s[i].location,r.red,r.green,r.blue))}];function lv(i,t){let e={};for(let r in i.uniformStructures){if(!t[r])continue;let s=i.uniformStructures[r],n=!1;for(let o=0;o<Jt.length;o++){let a=Jt[o];if(s.type===a.type&&a.test(s)){e[r]=av[o],n=!0;break}}if(!n){let o=s.size===1?nv:ov;e[r]=o[s.type]}}return(r,s,n)=>{let o=n.gl;for(let a in e){let l=s[a],c=r[a],h=r[a].value;e[a](a,c,h,l,r,s,o)}}}function zE(){Object.assign(ue.prototype,{_unsafeEvalCheck(){}}),Object.assign(cr.prototype,{_systemCheck(){}}),Object.assign(zr.prototype,{_generateUniformsSync:lv}),Object.assign(Wr.prototype,{_generateUboSync:rv}),Object.assign(Hr.prototype,{_generateUboSync:iv}),Object.assign(Vr.prototype,{_generateShaderSync:Q0}),Object.assign(Ja.prototype,{generateParticleUpdate:Z0})}zE();var cv=33;function Yu(i,t){let e=i.code&&String(i.code).startsWith("Digit")?String(i.code).slice(5):"";return e&&Number(e)>=1&&Number(e)<=9?`KeyboardCraftspersonKey${e}${t}`:""}function hv(i,t,e,r){return{x:(i.clientX-t.left)*e/t.width,y:(t.bottom-i.clientY)*r/t.height}}function uv({renderer:i,api:t,onSnapshot:e,onStatus:r,onError:s,isActive:n}={}){let o=null,a=!1,l=!1,c=null,h=null,u=0,d=null,f=null,m=[];function g(F){s&&s(F)}async function y(F){o=F,a=F?.running!==!1,F?.scene&&F.scene.format==="tree-v1"?(F.scene.reset&&(u=0),await i.applyScene(F.scene,F.canvasWidth,F.canvasHeight),u=F.scene.revision||u):Array.isArray(F?.paint)&&await i.render(F.paint,F.canvasWidth,F.canvasHeight),e&&await e(F)}async function x(){if(!(!a||l)&&!(n&&!n())){l=!0;try{await y(await t("get",{view:!0,sceneRev:u,compact:!0}))}catch(F){a=!1,v(),g(F)}finally{l=!1}}}function b(){c||(c=setInterval(()=>{x()},33))}function v(){c&&clearInterval(c),c=null,h&&clearTimeout(h),h=null}function T(F=30){h||(h=setTimeout(()=>{h=null,x()},F))}function S(){a=!1,u=0,v()}async function E(F,A){if(n&&!n())return null;try{let k=await t(F,{light:!0,...A||{}});return k&&typeof k=="object"&&k.frame!==void 0&&r&&r(k),T(30),k}catch(k){return g(k),null}}async function w(F={}){u=0;let A=await t("start",{view:!0,compact:!0,...F});return await y({...A,running:!0}),a=!0,v(),b(),A}async function I(){u=0,v();let F=await t("get",{view:!0,compact:!0,sceneRev:0});return await y(F),a&&b(),F}async function G(F={}){u=0,v();let A=await t("device",{view:!0,compact:!0,...F});return await y({...A,running:!0}),a=!0,b(),A}async function M(F={}){u=0;let A=await t("view",{view:!0,compact:!0,...F});return await y({...A,running:!0}),A}async function C(){return S(),t("stop")}function R(F,A){return hv(F,A.getBoundingClientRect(),o.canvasWidth,o.canvasHeight)}function L(F,{keysOn:A}={}){let k=A||F,X=z=>{!o||!a||n&&!n()||(F.setPointerCapture?.(z.pointerId),E("pointer",{type:"down",...R(z,F)}))},D=z=>{!o||!a||n&&!n()||E("pointer",{type:"up",...R(z,F)})},Z=z=>{!o||!a||n&&!n()||(f=R(z,F),!d&&(d=setTimeout(()=>{d=null,f&&E("pointer",{type:"move",...f})},60)))},ht=()=>{o&&a&&(!n||n())&&E("pointer",{type:"move",x:-1,y:-1})},xt=z=>{if(!o||!a||n&&!n())return;let Dt=Yu(z,"Down");Dt&&(z.preventDefault(),E("key",{key:Dt}))},st=z=>{if(!o||!a||n&&!n())return;let Dt=Yu(z,"Up");Dt&&(z.preventDefault(),E("key",{key:Dt}))};F.addEventListener("pointerdown",X),F.addEventListener("pointerup",D),F.addEventListener("pointermove",Z),F.addEventListener("pointerleave",ht),k.addEventListener("keydown",xt),k.addEventListener("keyup",st);let at=()=>{F.removeEventListener("pointerdown",X),F.removeEventListener("pointerup",D),F.removeEventListener("pointermove",Z),F.removeEventListener("pointerleave",ht),k.removeEventListener("keydown",xt),k.removeEventListener("keyup",st),d&&clearTimeout(d),d=null};return m.push(at),at}function V(){for(S();m.length;)m.pop()();i?.destroy?.()}return{get snapshot(){return o},get running(){return a},get sceneRev(){return u},applyScene:y,poll:x,pollSoon:T,startPolling:b,stopPolling:v,reset:S,act:E,start:w,attach:I,device:G,view:M,stop:C,bindInput:L,destroy:V}}var XE=[0,-.5,.5,.5,-.5,.5],YE=[0,-.5,.12,-.12,.5,0,.12,.12,0,.5,-.12,.12,-.5,0,-.12,-.12],jE=[0,-.5,.11,-.15,.48,-.15,.18,.07,.29,.41,0,.2,-.29,.41,-.18,.07,-.48,-.15,-.11,-.15],$E=new Set(["image","textbox","textwindow","button"]);function Ln(i,t=4294967295){let e=Number(i??t)>>>0;return{color:e&16777215,alpha:(e>>>24&255)/255}}function Zt(i,t=0){let e=Number(i);return Number.isFinite(e)?e:t}function KE(i){let t=i?.matrix;if(!t||typeof t!="object")return null;let e=[t.a,t.b,t.c,t.d,t.tx,t.ty].map(Number);return e.every(Number.isFinite)?e:null}function qE(i){let t=i.horizontalAlignment==="Right"?1:i.horizontalAlignment==="Middle"?.5:0,e=i.verticalAlignment==="Bottom"?1:i.verticalAlignment==="Middle"?.5:0;return{x:t,y:e}}function ZE(i,t,e){let r=i.primitive==="triangle"?XE:i.primitive==="fourstar"?YE:jE,s=[];for(let n=0;n<r.length;n+=2)s.push(r[n]*t,r[n+1]*e);return s}function QE(i,t,e){return dv(i)?[i.kind,i.primitive,i.imageId,"sprite"].join(" "):[i.kind,i.primitive,t,e,i.imageColor,i.imageId,i.fillType,i.fillHorizontalType,i.fillVerticalType,i.fillAmount,i.text,i.fontSize,i.fontColor,i.bgColor,i.enableOutline,i.outlineColor,i.horizontalAlignment,i.verticalAlignment,i.pressed].join(" ")}function dv(i){return i.kind==="image"&&i.primitive==="circle"&&(!i.fillType||i.fillType==="Unused")}function JE(i){let t=W.get().createCanvas(i,i);t.width=t.height=i;let e=t.getContext("2d");return e.fillStyle="#ffffff",e.beginPath(),e.arc(i/2,i/2,i/2,0,Math.PI*2),e.fill(),new U({source:new vt({resource:t,width:i,height:i,resolution:1})})}var ju=class{constructor(t){this.canvas=t,this.app=null,this.nodes=new Map,this.circleTextures=new Map,this.canvasWidth=0,this.canvasHeight=0,this.scratch=new B,this.ready=this.initialize()}async initialize(){let t=new za;await t.init({canvas:this.canvas,width:1,height:1,autoStart:!1,autoDensity:!1,resolution:Math.min(2,window.devicePixelRatio||1),antialias:!0,backgroundAlpha:0,preference:"webgl",powerPreference:"high-performance"}),t.ticker.stop(),t.stage.eventMode="none",t.stage.sortableChildren=!0,this.app=t}resize(t,e){let r=Math.max(1,Math.round(Zt(t,1))),s=Math.max(1,Math.round(Zt(e,1)));r===this.canvasWidth&&s===this.canvasHeight||(this.canvasWidth=r,this.canvasHeight=s,this.app.renderer.resize(r,s))}createNode(t,{group:e=!1}={}){let r=new ut({isRenderGroup:!!e});return r.label=`runtime:${t.id}`,r.eventMode="none",r.sortableChildren=!0,r.__runtimeId=t.id,r.__group=!!e,this.nodes.set(t.id,r),this.app.stage.addChild(r),r}clearVisual(t){t.__visual&&(t.removeChild(t.__visual),t.__visual.destroy({children:!0,context:!0}),t.__visual=null,t.__visualKey="")}circleTexture(t){let e=this.app?.renderer.resolution||2,r=Math.min(4096,Math.max(256,2**Math.ceil(Math.log2(Math.max(1,t*e)))));this.circleTextures||=new Map;let s=this.circleTextures.get(r);return s||(s=JE(r),this.circleTextures.set(r,s)),s}replaceVisual(t,e,r,s){if(this.clearVisual(t),!$E.has(e.kind))return;let n=new ut;if(n.eventMode="none",n.label=`visual:${e.id}`,e.kind==="textbox"||e.kind==="textwindow"){let o=new Se,a=Ln(e.bgColor,16777215);o.rect(-r/2,-s/2,r,s).fill(a),n.addChild(o);let l=Math.max(8,Zt(e.fontSize,12)),c=qE(e),h=new On({text:String(e.text||""),style:new qe({fontFamily:'Inter, "Microsoft YaHei UI", "Microsoft YaHei", sans-serif',fontSize:l,fill:Ln(e.fontColor,4294967295),stroke:e.enableOutline?{color:Ln(e.outlineColor,4278190080).color,width:Math.max(2,l*.12),join:"round"}:void 0,wordWrap:!0,wordWrapWidth:Math.max(4,r-4),breakWords:!0,align:c.x===1?"right":c.x===.5?"center":"left",lineHeight:l*1.2})});h.anchor.set(c.x,c.y),h.x=c.x===0?-r/2+2:c.x===1?r/2-2:0,h.y=c.y===0?-s/2:c.y===1?s/2:0;let u=new Se().rect(-r/2,-s/2,r,s).fill({color:16777215,alpha:1});h.mask=u,n.addChild(u,h)}else if(e.kind==="button"){let o=new Se;o.roundRect(-r/2,-s/2,r,s,6).fill({color:3303631,alpha:1}),o.roundRect(-r/2,-s/2,r,s,6).stroke({color:7381247,alpha:.8,width:1}),e.pressed&&o.roundRect(-r/2,-s/2,r,s,6).fill({color:0,alpha:.28}),n.addChild(o)}else if(dv(e)){let o=new Me({texture:this.circleTexture(Math.max(r,s)),anchor:.5});n.__circle=o,n.addChild(o)}else{let o=new Se,a=Ln(e.imageColor,4294967295);e.primitive==="missing"?(o.rect(-r/2,-s/2,r,s).fill({color:4727336,alpha:.36}),o.rect(-r/2+.5,-s/2+.5,Math.max(0,r-1),Math.max(0,s-1)).stroke({color:16741505,alpha:1,width:1})):e.primitive==="circle"?o.ellipse(0,0,r/2,s/2).fill(a):e.primitive==="ring"?o.ellipse(0,0,Math.max(1,r/2-3.5),Math.max(1,s/2-3.5)).stroke({...a,width:7}):e.primitive==="triangle"||e.primitive==="fourstar"||e.primitive==="fivestar"?o.poly(ZE(e,r,s)).fill(a):o.rect(-r/2,-s/2,r,s).fill(a);let l=$0(e,r,s);if(l&&(o.visible=l.width>0&&l.height>0,o.visible)){let c=new Se().rect(l.x,l.y,l.width,l.height).fill({color:16777215,alpha:1});o.mask=c,n.addChild(c)}n.addChild(o)}n.scale.set(e.pressed?.98:1),t.addChildAt(n,0),t.__visual=n}applyMatrix(t,e,r){let s=KE(e);if(!s){let u=Math.max(0,Zt(e.sourceWidth,Zt(e.width))),d=Math.max(0,Zt(e.sourceHeight,Zt(e.height)));t.x=Zt(e.left)+u/2,t.y=this.canvasHeight-Zt(e.bottom)-d/2,t.rotation=-Zt(e.rotationZ)*Math.PI/180,t.scale.set(1);return}let[n,o,a,l,c,h]=s;this.scratch.set(n,-o,-a,l,c,r?-h:this.canvasHeight-h),t.setFromMatrix(this.scratch)}updateNode(t,e,{nested:r=!1}={}){let s=Math.max(0,Zt(e.sourceWidth,Zt(e.width))),n=Math.max(0,Zt(e.sourceHeight,Zt(e.height))),o=QE(e,s,n);t.__visualKey!==o&&(this.replaceVisual(t,e,s,n),t.__visualKey=o),t.__visual&&t.__visual.scale.set(e.pressed?.98:1);let a=t.__visual?.__circle;if(a){let l=Math.max(s,n),c=Ln(e.imageColor,4294967295);a.texture=this.circleTexture(l),a.width=s,a.height=n,a.tint=c.color,a.alpha=c.alpha,a.visible=s>0&&n>0}this.applyMatrix(t,e,r)}attachNode(t,e){let r=e.parent,n=(r==null?this.app.stage:this.nodes.get(r))||this.app.stage;t.parent!==n&&n.addChild(t),n.sortableChildren=!0,t.zIndex=-Zt(e.z)}upsertSceneNode(t){if(!t||t.id===void 0||t.id===null)return;let e=t.group===!0,r=this.nodes.get(t.id);r?r.__group!==e&&(e?r.enableRenderGroup?.():r.disableRenderGroup?.(),r.__group=e):r=this.createNode(t,{group:e}),this.updateNode(r,t,{nested:t.parent!=null}),this.attachNode(r,t)}removeNode(t){let e=this.nodes.get(t);if(e){for(let r of[...e.children])r.__runtimeId!=null&&e.removeChild(r);e.parent?.removeChild(e),this.clearVisual(e),e.destroy({children:!1}),this.nodes.delete(t)}}clearNodes(){for(let t of[...this.nodes.keys()])this.removeNode(t)}async applyScene(t,e,r){if(await this.ready,this.resize(e,r),!t||t.format!=="tree-v1"){this.app.render();return}t.reset&&this.clearNodes();for(let n of t.removed||[])this.removeNode(n);let s=t.reset?t.nodes:t.changed;for(let n=0;n<(s||[]).length;n+=1){let o=s[n];!o||o.id===void 0||o.id===null||this.nodes.has(o.id)||this.createNode(o,{group:o.group===!0})}for(let n=0;n<(s||[]).length;n+=1)this.upsertSceneNode(s[n]);this.app.render()}async render(t,e,r){await this.ready,this.resize(e,r);let s=new Set,n=Array.isArray(t)?t:[];for(let o=0;o<n.length;o+=1){let a=n[o];if(!a||a.id===void 0||a.id===null)continue;s.add(a.id);let l=this.nodes.get(a.id)||this.createNode(a);this.updateNode(l,a),l.zIndex=o,l.parent!==this.app.stage&&this.app.stage.addChild(l)}for(let[o]of this.nodes)s.has(o)||this.removeNode(o);this.app.render()}destroy(){this.clearNodes();for(let t of this.circleTextures.values())t.destroy(!0);this.circleTextures.clear(),this.app?.destroy({removeView:!1},{children:!0,texture:!0,textureSource:!0}),this.app=null}};export{cv as PLAY_POLL_INTERVAL_MS,ju as PixiPlayRenderer,uv as createPlaySession};
|
|
926
926
|
/*! Bundled license information:
|
|
927
927
|
|
|
928
928
|
tiny-lru/dist/tiny-lru.js:
|