lecodes-viewer 0.19.0 → 0.19.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.
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "f3396b0d-2026-09-04",
3
- "commit": "f3396b0d",
4
- "buildDate": "2026-09-04T07:19:33.380Z"
2
+ "version": "df3b74c2-2026-09-04",
3
+ "commit": "df3b74c2",
4
+ "buildDate": "2026-09-04T07:30:58.749Z"
5
5
  }
@@ -184,4 +184,4 @@ textarea::placeholder {
184
184
  .widget.interactive {
185
185
  pointer-events: all;
186
186
  }`;function fe(e){var A;const g=De((A=e.player)==null?void 0:A._id);return g instanceof HTMLVideoElement?g:document.createElement("video")}function Ho(e){e.style.opacity="",e.style.width="",e.style.height="",e.style.top="",e.style.left=""}function Yo(e){var g,A,t;switch(e.type){case"image":return hI(e._src)&&((g=e._style)!=null&&g.tintColor||me(e._src))||e._sourceRect?document.createElement("div"):document.createElement("img");case"video":return fe(e);case"button":{const C=document.createElement("button");return((A=e.touchStartListeners)==null?void 0:A.length)>0&&C.classList.add("interactive"),C}case"screen":{const C=document.createElement("div");return C.classList.add("screen"),e.scrollable&&C.classList.add("scrollable"),((t=e.touchStartListeners)==null?void 0:t.length)>0&&C.classList.add("interactive"),C}case"scrollable":{const C=document.createElement("div");return C.classList.add("scrollable"),C}case"pager":{const C=document.createElement("div");return C.classList.add("pager"),C}case"vlist":{const C=document.createElement("div");return C.classList.add("vlist"),C}case"spacer":{const C=document.createElement("div");return C.classList.add("spacer"),C}case"input":return document.createElement("input");case"textarea":return document.createElement("textarea");default:return document.createElement("div")}}function vI(e,g,A){if(g.tagName.toLowerCase()===A)return g;const t=document.createElement(A);t.setAttribute("style",g.getAttribute("style")??"");for(const i of["data-measured","data-using-padding","data-using-scroll","data-viewbox"])if(g.hasAttribute(i)){const E=g.getAttribute(i);t.setAttribute(i,E)}const C=e.weakMap.get(g);return e.weakMap.delete(g),e.weakMap.set(t,C),e.nodeMap.set(C,t),g.replaceWith(t),t}function xo(e,g,A){var i;const t=g._sourceRect;if(t){_o(A,g._src,t);return}const C=((i=g._style)==null?void 0:i.tintColor)??me(g._src);Jt(e,A,g._src,C)}function qo(e,g,A){const t=g instanceof HTMLDivElement?g.style.backgroundColor:"",C=me(A)??t,i=hI(A)&&!!C,E=vI(e,g,i?"div":"img");Jt(e,E,A,C),e.recalc()}function Jt(e,g,A,t){var C;if(g._canvasSurface=void 0,g instanceof HTMLImageElement){if(TQ(g),g.referrerPolicy="no-referrer",g.crossOrigin="anonymous",g.addEventListener("load",()=>{g.hasAttribute("data-measured")&&(e.module._markNodeDirty(e.weakMap.get(g)),e.recalcImmediately())},{once:!0}),hI(A)){g.src=MI(A.svg);const i=Ke(A.svg);i&&g.setAttribute("data-viewbox",i)}else if(typeof A=="object"&&"canvasSurface"in A){const i=A.canvasSurface;g._canvasSurface=i,g.removeAttribute("data-viewbox"),g.src=((C=e.canvasHost)==null?void 0:C.surfaceToDataUrl(i))??""}else g.removeAttribute("data-viewbox"),g.src=typeof A=="object"?bI(A._id):A;return}hI(A)&&t&&(qQ(g,A.svg,t),g.hasAttribute("data-measured")&&(e.module._markNodeDirty(e.weakMap.get(g)),e.recalcImmediately()))}function To(e,g,A,t,C,i){const E=e.nodeMap.get(g);if(!E)return;const r=E._sourceRect;if(E._sourceRect=[A,t,C,i],E instanceof HTMLImageElement){const w=vI(e,E,"div");w._sourceRect=[A,t,C,i],Ht(w,E.src,E)}else Ge(E);(!r||r[2]!==C||r[3]!==i)&&(e.module._markNodeDirty(g),e.recalc())}function _o(e,g,A){e._sourceRect=A;const t=typeof g=="object"?bI(g._id):g;Ht(e,t,null)}function Ht(e,g,A){if(e.style.backgroundRepeat="no-repeat",A&&A.naturalWidth>0){e._atlasSize=[A.naturalWidth,A.naturalHeight],e.style.backgroundImage=`url("${g}")`,Ge(e);return}const t=new Image;t.crossOrigin="anonymous",t.referrerPolicy="no-referrer",t.addEventListener("load",()=>{e._atlasSize=[t.naturalWidth,t.naturalHeight],e.style.backgroundImage=`url("${g}")`,Ge(e)},{once:!0}),t.src=g}function Ge(e){const g=e._sourceRect,A=e._atlasSize;if(!g||!A)return;const[t,C,i,E]=g,[r,w]=A;e.style.backgroundSize=`${r/i*100}% ${w/E*100}%`,e.style.backgroundPosition=`${r===i?0:t/(r-i)*100}% ${w===E?0:C/(w-E)*100}%`}function Wo(e,g){var t;const A=(t=e.canvasHost)==null?void 0:t.surfaceToDataUrl(g);if(A)for(const C of e.nodeMap.values())C._canvasSurface===g&&C instanceof HTMLImageElement&&(C.src=A)}function Zo(e,g,A){const t=e.nodeMap.get(g);if(!t||!(t instanceof HTMLImageElement))return;const C=t.src,i=vI(e,t,"div"),E=i.style;E.webkitMaskImage=E.maskImage=`url("${C}")`,E.webkitMaskRepeat=E.maskRepeat="no-repeat",E.webkitMaskPosition=E.maskPosition="center",E.maskSize||(E.webkitMaskSize=E.maskSize="contain"),i.style.backgroundColor=A,e.recalc()}function Vo(e,g){var i;const A=e.nodeMap.get(g);if(!A)return;const t=A.style,C=t.maskImage||t.webkitMaskImage||"";if(A instanceof HTMLDivElement&&C){const E=(i=/url\("(.*)"\)/.exec(C))==null?void 0:i[1],r=vI(e,A,"img"),w=r.style;w.webkitMaskImage=w.maskImage="",w.webkitMaskRepeat=w.maskRepeat="",w.webkitMaskPosition=w.maskPosition="",w.webkitMaskSize=w.maskSize="",r.style.backgroundColor="",E&&(r.src=E),e.recalc()}else A.style.backgroundColor=""}const Oo=256;class Qt{constructor(g,A,t,C,i,E,r,w,h){X(this,"module");X(this,"touchSystem");X(this,"applyStyle");X(this,"classLayer");X(this,"deregister");X(this,"canvasHost");X(this,"layoutPtrBytes");X(this,"layoutPtr");X(this,"paddingPtrBytes");X(this,"paddingPtr");X(this,"vlistSystem");X(this,"pagerSystem");X(this,"nativeViewSystem");X(this,"ownerDesc");X(this,"nodeMap",new Map);X(this,"weakMap",new WeakMap);X(this,"nodeOnLayoutEventsMap",new Map);X(this,"root");X(this,"rootNodePtr");X(this,"screenId");X(this,"node");X(this,"isWidget",!1);X(this,"overlayElement",null);X(this,"vlistIds",[]);X(this,"pagerIds",[]);X(this,"updateImageSrc",(g,A)=>qo(this,g,A));X(this,"tintSvgImage",(g,A)=>Zo(this,g,A));X(this,"untintSvgImage",g=>Vo(this,g));X(this,"setSourceRect",(g,A,t,C,i)=>To(this,g,A,t,C,i));X(this,"refreshCanvasSurface",g=>Wo(this,g));X(this,"screenWidth",0);X(this,"screenHeight",0);X(this,"firedScreenWidth",-1);X(this,"firedScreenHeight",-1);X(this,"pendingRecalc",!1);X(this,"scheduledRecalc",!1);X(this,"recalcImmediately",()=>{if(this.scheduledRecalc=!1,this.screenWidth===0){this.pendingRecalc=!0;return}this.isWidget?this.module._calculateWidget(this.rootNodePtr,this.screenWidth,this.screenHeight):this.module._calculate(this.rootNodePtr,this.screenWidth,this.screenHeight),this.updateSizes(this.root)});X(this,"insertNode",(g,A,t)=>{const C=this.nodeMap.get(A);C&&(C.appendChild(this.addNodeRecursive(t,A,g)),this.recalc())});X(this,"removeNode",(g,A)=>{const t=this.nodeMap.get(g);t&&(this.detachNode(t,g,A),this.recalc())});this.module=g,this.touchSystem=A,this.applyStyle=t,this.classLayer=C,this.deregister=r,this.canvasHost=w,this.layoutPtrBytes=g._malloc(16),this.layoutPtr=this.layoutPtrBytes>>2,this.paddingPtrBytes=g._malloc(16),this.paddingPtr=this.paddingPtrBytes>>2,this.vlistSystem=i,this.pagerSystem=E,this.nativeViewSystem=h}init(g,A){this.node=A,this.screenId=g,this.root=this.addNodeRecursive(A),this.rootNodePtr=A._id}addNodeRecursive(g,A=null,t=0){var r;const C=g.type==="text"||g.type==="image"||g.type==="input"||g.type==="textarea",i=A===null?this.module._createNodeRoot(this.screenId):this.module._createNode(A,t,C),E=Yo(g);E.setAttribute("data-node-id",i),E.style.position="absolute",E._lecodesNode=g,g._text&&(E.textContent=g._text,E.style.whiteSpace="pre-wrap",E.style.lineHeight="1.2em",E.style.fontSize="14px",E.toggleAttribute("data-using-padding")),(g.type==="scrollable"||g.scrollable)&&E.toggleAttribute("data-using-scroll"),g.type==="image"&&xo(this,g,E),g.type==="video"&&Ho(E),this.attachListeners(g,E),g._id=i,this.weakMap.set(E,i),this.nodeMap.set(g._id,E);for(const[w,h]of Object.entries(g._style))this.applyStyle(Oo,i,w,h);if(g._classes)for(const w of g._classes)this.module._enableNodeLayer(i,this.classLayer(i,w));if((g.type==="input"||g.type==="textarea")&&g._value&&(E.value=g._value),g.type==="vlist"&&(E.toggleAttribute("data-using-scroll"),E.toggleAttribute("data-vlist"),E.style.overflowY="auto",this.vlistSystem.register(this,g,E,i),this.vlistIds.push(i)),g.type==="native"&&(E.toggleAttribute("data-native-view"),E.style.overflow="hidden",(r=this.nativeViewSystem)==null||r.mountInto(g,E)),g.type==="pager"&&(E.toggleAttribute("data-pager"),this.pagerSystem.register(this,g,E,i),this.pagerIds.push(i)),g.ll&&this.nodeOnLayoutEventsMap.set(i,g.ll),"children"in g&&g.type!=="pager"){let w=0;for(const h of g.children)h&&(E.appendChild(this.addNodeRecursive(h,i,w)),w++)}return E}attachListeners(g,A){if((g.type==="button"||g.type==="widget"||g.type==="screen")&&(A.addEventListener("pointerdown",this.touchSystem.onUIButtonTouchStart.bind(null,g)),g.type==="button"&&A.addEventListener("pointerup",this.touchSystem.onUIButtonTouchEnd.bind(null,g))),g.type==="input"||g.type==="textarea"){A.toggleAttribute("data-using-padding");const t=A;t._lcNode=g,t.addEventListener("input",()=>{g.type==="textarea"&&(this.module._markNodeDirty(g._id),this.recalc());for(const C of g.cl)C(t.value)}),t.addEventListener("focus",()=>{this.module._setNodeFocused(g._id,!0);for(const C of g.fl)C()}),t.addEventListener("blur",()=>{this.module._setNodeFocused(g._id,!1);for(const C of g.bl)C()})}}applyLayout(g,A){g===this.screenWidth&&A===this.screenHeight&&!this.pendingRecalc||(this.pendingRecalc=!1,this.screenWidth=g,this.screenHeight=A,this.isWidget?this.module._calculateWidget(this.rootNodePtr,g,A):this.module._calculate(this.rootNodePtr,g,A),this.updateSizes(this.root))}fireLayout(g,A){const t=this.nodeOnLayoutEventsMap.get(g);if(t)for(const C of t)C(A)}updateSizes(g){if(g.style.display==="none")return;const A=this.weakMap.get(g);if(!A){console.warn("Trying to update size for element without yogaId",g);return}if(g===this.root&&!this.isWidget)(this.screenWidth!==this.firedScreenWidth||this.screenHeight!==this.firedScreenHeight)&&(this.firedScreenWidth=this.screenWidth,this.firedScreenHeight=this.screenHeight,this.fireLayout(A,{left:0,top:0,width:this.screenWidth,height:this.screenHeight}));else if(this.module._getLayoutDOMPointer(A,this.layoutPtrBytes)){const t=this.module.HEAPF32[this.layoutPtr],C=this.module.HEAPF32[this.layoutPtr+1],i=this.module.HEAPF32[this.layoutPtr+2],E=this.module.HEAPF32[this.layoutPtr+3];g.style.left=t+"px",g.style.top=C+"px",g.style.width=i+"px",g.style.height=E+"px",g.style.maxWidth="",this.fireLayout(A,{left:t,top:C,width:i,height:E})}if(g.hasAttribute("data-using-padding")){this.module._getPaddingPointer(A,this.paddingPtrBytes);const t=this.module.HEAPF32[this.paddingPtr],C=this.module.HEAPF32[this.paddingPtr+1],i=this.module.HEAPF32[this.paddingPtr+2],E=this.module.HEAPF32[this.paddingPtr+3];g.style.padding=`${C}px ${i}px ${E}px ${t}px`,g.style.boxSizing="border-box"}if(g.hasAttribute("data-using-scroll"))if(g.classList.contains("scrollable_horizontal")){const t=this.module._getContentWidth(A);g.style.setProperty("--scroll-width",t+"px"),g.style.setProperty("--scroll-height","0px")}else{const t=this.module._getContentHeight(A);g.style.setProperty("--scroll-height",t+"px"),g.style.setProperty("--scroll-width","0px")}if(g.hasAttribute("data-vlist")){this.vlistSystem.updateLayout(this.weakMap.get(g));return}if(g.hasAttribute("data-pager")){this.pagerSystem.updateLayout(this.weakMap.get(g));return}for(const t of g.children)this.updateSizes(t)}setPagersActive(g){var A;for(const t of this.pagerIds)(A=this.pagerSystem.instances.get(t))==null||A.setActive(g)}recalc(){this.scheduledRecalc||(this.scheduledRecalc=!0,queueMicrotask(this.recalcImmediately))}setContent(g,A,t){const C=this.nodeMap.get(g);if(!C)return;for(const E of A)this.detachNode(C,g,E);let i=0;for(const E of t)E&&(C.appendChild(this.addNodeRecursive(E,g,i)),i++);this.recalc()}detachNode(g,A,t){const C=this.nodeMap.get(t._id);this.nodeMap.delete(t._id),C&&g.removeChild(C),this.module._removeNode(A,t._id),this.setNodeIdNullRecursive(t)}setNodeIdNullRecursive(g){if(g._id=0,"children"in g)for(const A of g.children)A&&this.setNodeIdNullRecursive(A)}buildSubtree(g,A){return this.addNodeRecursive(g,A,0)}updateSizesFor(g){this.updateSizes(g)}releaseSubtree(g){const A=t=>{if(t._id&&this.nodeMap.delete(t._id),t._id=0,"children"in t)for(const C of t.children??[])C&&A(C)};A(g)}remove(){this.setPagersActive(!1);for(const g of this.vlistIds)this.vlistSystem.unregister(g);for(const g of this.pagerIds)this.pagerSystem.unregister(g);this.removeFromHTML(),this.setNodeIdNullRecursive(this.node),this.isWidget?this.module._freeWidget(this.rootNodePtr):this.module._freeNode(this.rootNodePtr),this.module._free(this.layoutPtrBytes),this.module._free(this.paddingPtrBytes),this.nodeMap.clear(),this.deregister(this.screenId)}removeFromHTML(){var g;this.setPagersActive(!1),this.root.remove(),(g=this.overlayElement)==null||g.remove(),this.overlayElement=null,this.screenWidth=0,this.screenHeight=0,this.firedScreenWidth=-1,this.firedScreenHeight=-1}}let Po=class{constructor(g,A){X(this,"show",!1);X(this,"stack",[]);X(this,"onScreen");X(this,"free");this.onScreen=g,this.free=A}init(g){this.stack=[g],this.onScreen(g),this.show=!0}push(g){this.stack.push(g),this.onScreen(g)}replace(g){const A=this.stack[this.stack.length-1];this.stack[this.stack.length-1]=g,this.onScreen(g),A&&this.free(A)}hide(){this.show=!1}pop(g){const A=g<0?Math.max(this.stack.length-1+g,0):Math.min(g,this.stack.length-1),t=this.stack.slice(A+1);this.stack.length=A+1,this.onScreen(this.stack[A]);for(const C of t)this.free(C)}restore(){this.show=!0,this.onScreen(this.stack[this.stack.length-1])}};const Xo=e=>{const g=new Map,A=(l,D)=>{const R=e.lengthBytesUTF8(l)+1,L=e._malloc(R);e.stringToUTF8(l,L,R);try{return D(L)}finally{e._free(L)}},t=(l,D)=>{const R=l.map(O=>{const q=e.lengthBytesUTF8(O)+1,S=e._malloc(q);return e.stringToUTF8(O,S,q),S}),L=e._malloc(Math.max(4*R.length,4));R.forEach((O,q)=>{e.HEAPU32[(L>>2)+q]=O});try{return D(L)}finally{R.forEach(O=>e._free(O)),e._free(L)}},C=(l,D)=>{const R=e._malloc(Math.max(4*l.length,4));l.forEach((L,O)=>{e.HEAPF32[(R>>2)+O]=L});try{return D(R)}finally{e._free(R)}},i=(l,D)=>{const R=[];for(let L=0;L<D;L++)R.push(e.UTF8ToString(e.HEAPU32[(l>>2)+L]));return R},E=l=>{for(const[R,L]of l.items)l.screen.updateSizesFor(L.el),L.el.style.top=A(R,O=>e._vlistOffsetOf(l.nodeId,O))+"px",L.el.style.left="0px";const D=e._getContentHeight(l.nodeId);l.el.style.setProperty("--scroll-height",D+"px"),l.el.style.setProperty("--scroll-width","0px"),l.pendingScroll!==null&&(Math.abs(l.el.scrollTop-l.pendingScroll)>=1&&(l.el.scrollTop=l.pendingScroll),l.pendingScroll=null)},r=e.addFunction((l,D,R,L,O,q)=>{const S=g.get(D);if(!S)return;const b=i(R,L),T=i(O,q);for(const Y of b){const z=S.items.get(Y);z&&(S.items.delete(Y),z.el.remove(),S.screen.releaseSubtree(z.jsSubtree),A(Y,gA=>e._vlistItemUnmounted(D,gA)))}S.jsNode._syncWindow(b,T),E(S)},"viiiiii"),w=e.addFunction((l,D,R)=>{const L=g.get(D);L&&(L.pendingScroll=R)},"viif"),h=e.addFunction((l,D,R)=>{const L=g.get(D);if(!L)return;const O=R?L.jsNode.erl??[]:L.jsNode.strl??[];for(const q of O)q()},"viii");e._setVListHandlers(r,w,h);const G=(l,D,R,L)=>{const O={nodeId:L,el:R,jsNode:D,screen:l,items:new Map,pendingScroll:null};g.set(L,O),e._vlistInit(L,D._overscan,D._inverted?1:0,D._startThreshold,D._endThreshold),D._keys.length>0&&U(L,D._keys,D._estimates),R.addEventListener("scroll",()=>{e._vlistOnScroll(L,R.scrollTop),E(O);for(const q of D.sl??[])q(R.scrollTop)})},F=l=>{const D=g.get(l);D&&(e._vlistUpdateLayout(l),E(D))},c=l=>{g.get(l)&&(e._vlistFree(l),g.delete(l))},U=(l,D,R)=>{t(D,L=>C(R,O=>e._vlistSetKeys(l,L,O,D.length)))};return{register:G,updateLayout:F,unregister:c,refresh:E,api:{vlistSetKeys:(l,D,R)=>{U(l._id,D,R)},vlistInsertKeys:(l,D,R,L)=>{t(R,O=>C(L,q=>e._vlistInsertKeys(l._id,D,O,q,R.length)))},vlistRemoveKeys:(l,D)=>{t(D,R=>e._vlistRemoveKeys(l._id,R,D.length))},vlistInvalidate:(l,D)=>{A(D,R=>e._vlistInvalidate(l._id,R))},vlistMount:(l,D,R)=>{const L=g.get(l._id);if(!L)return;const O=A(D,S=>e._vlistCreateItemRoot(l._id,S)),q=L.screen.buildSubtree(R,O);L.el.appendChild(q),L.items.set(D,{rootPtr:O,el:q,jsSubtree:R}),A(D,S=>e._vlistItemMounted(l._id,S))},command:(l,D,...R)=>{const L=g.get(l._id);if(!L)return;const O=q=>q?"smooth":"auto";switch(D){case"scrollTo":L.el.scrollTo({top:R[0],behavior:O(R[1]??!0)});break;case"scrollToKey":{const q=A(R[0],S=>e._vlistOffsetOf(L.nodeId,S));isNaN(q)||L.el.scrollTo({top:q,behavior:O(R[1]??!0)});break}case"scrollToEnd":{const q=e._getContentHeight(L.nodeId);L.el.scrollTo({top:q-L.el.clientHeight,behavior:O(R[0]??!0)});break}}}},instances:g}},ae=(e,g,A)=>Math.max(g,Math.min(A,e)),jo=(e,g)=>{const A=new Map,t=S=>{const b=(S.children??[]).filter(Boolean),T=Array.isArray(S._lens)?S._lens:[];if(T.reduce((EA,iA)=>EA+iA,0)!==b.length||T.some(EA=>EA<1))return b.map(EA=>[EA]);const z=[];let gA=0;for(const EA of T)z.push(b.slice(gA,gA+EA)),gA+=EA;return z},C=S=>ae(S.jsNode._index??0,0,Math.max(0,S.tabs.length-1)),i=(S,b)=>{const T=document.createElement("div");T.className="pager-page";const Y=g.newScreen(b);return T.appendChild(Y.root),S.width>0&&S.height>0&&Y.applyLayout(S.width,S.height),{node:b,el:T,host:Y}},E=S=>{for(const b of S.node.ol??[])b()},r=S=>{for(const b of S.node.cl??[])b()},w=(S,b)=>{var T,Y;(Y=(T=S.host).setPagersActive)==null||Y.call(T,b)},h=S=>{var T;const b=S.active&&S.laidOut?((T=S.tabs[S.currentTab])==null?void 0:T.pages[S.tabs[S.currentTab].pages.length-1])??null:null;S.openPage!==b&&(S.openPage&&(r(S.openPage),w(S.openPage,!1)),S.openPage=b,b&&(E(b),w(b,!0)))},G=S=>{var T;const b=((T=S.tabs[S.currentTab])==null?void 0:T.pages.length)??0;S.el.classList.toggle("pager_locked",S.tabs.length<=1||b>1)},F=S=>{for(let b=0;b<S.pages.length;b++)S.pages[b].el.classList.toggle("pager-page_hidden",b!==S.pages.length-1)},c=(S,b,T)=>{const Y=ae(b,0,Math.max(0,S.tabs.length-1));S.el.scrollTo({left:Y*S.width,behavior:T?"smooth":"auto"})},U=S=>{const b=S.el.clientWidth;return b>0?S.el.scrollLeft/b:0},y=(S,b)=>{var Y,z;const T=ae(b,0,Math.max(0,S.tabs.length-1));S.targetTab=T,T!==S.currentTab&&(S.currentTab=T,(z=(Y=S.jsNode)._hostDidSelect)==null||z.call(Y,T),h(S),G(S))},l=S=>{S.settleTimer!==null&&clearTimeout(S.settleTimer);const b=U(S),T=Math.round(b);Math.abs(b-T)<.005?(S.settleTimer=null,y(S,T)):S.settleTimer=setTimeout(()=>{S.settleTimer=null,y(S,Math.round(U(S)))},80)},D=S=>{const b=t(S.jsNode),T=new Map;for(const gA of S.tabs)for(const EA of gA.pages)T.set(EA.node,EA);for(;S.tabs.length<b.length;){const gA=document.createElement("div");gA.className="pager-tab",S.el.appendChild(gA),S.tabs.push({el:gA,pages:[]})}for(;S.tabs.length>b.length;)S.tabs.pop().el.remove();const Y=Math.max(0,S.tabs.length-1);S.currentTab=Math.min(S.currentTab,Y),S.targetTab=Math.min(S.targetTab,Y);const z=new Set;for(let gA=0;gA<S.tabs.length;gA++){const EA=S.tabs[gA],iA=b[gA]??[],lA=[];for(const DA of iA){let a=T.get(DA);a||(a=i(S,DA)),z.add(a),lA.push(a),EA.el.appendChild(a.el)}EA.pages=lA,F(EA)}for(const gA of T.values())z.has(gA)||(gA===S.openPage&&(r(gA),w(gA,!1),S.openPage=null),gA.host.remove(),gA.el.remove());h(S),G(S)};return{register:(S,b,T,Y)=>{const z={nodeId:Y,el:T,jsNode:b,screen:S,tabs:[],width:0,height:0,mounted:!1,laidOut:!1,active:!1,currentTab:0,targetTab:0,openPage:null,settleTimer:null,setActive(gA){this.active!==gA&&(this.active=gA,h(this))}};A.set(Y,z);for(const gA of t(b)){const EA=document.createElement("div");EA.className="pager-tab";const iA={el:EA,pages:[]};for(const lA of gA){const DA=i(z,lA);iA.pages.push(DA),EA.appendChild(DA.el)}F(iA),z.tabs.push(iA),T.appendChild(EA)}z.currentTab=C(z),z.targetTab=z.currentTab,G(z),T.addEventListener("scroll",()=>l(z))},updateLayout:S=>{const b=A.get(S);if(!b)return;const T=parseFloat(b.el.style.width)||b.el.clientWidth,Y=parseFloat(b.el.style.height)||b.el.clientHeight;if(T<=0||Y<=0)return;const z=T!==b.width||Y!==b.height;b.width=T,b.height=Y;for(const gA of b.tabs)for(const EA of gA.pages)EA.host.applyLayout(T,Y);b.mounted?z&&c(b,b.targetTab,!1):(b.mounted=!0,b.currentTab=C(b),b.targetTab=b.currentTab,c(b,b.currentTab,!1)),b.laidOut=!0,h(b),G(b)},unregister:S=>{const b=A.get(S);if(b){b.settleTimer!==null&&clearTimeout(b.settleTimer);for(const T of b.tabs){for(const Y of T.pages)Y.host.remove(),Y.el.remove();T.el.remove()}b.tabs=[],b.openPage=null,A.delete(S)}},command:(S,b,...T)=>{const Y=A.get(S._id);if(Y)switch(b){case"select":{const z=C(Y);Y.targetTab=z,z!==Y.currentTab&&(Y.currentTab=z,h(Y),G(Y)),Y.width>0&&c(Y,z,T[0]===!0&&Y.laidOut);break}case"push":case"pop":case"popToRoot":case"replace":D(Y);break;case"content":D(Y),Y.width>0&&c(Y,Y.targetTab,!1);break}},instances:A}},zo=()=>{const e=new Map,g=new Map,A=(h,G)=>{e.set(h,G)},t=h=>e.has(h),C=h=>{const G=document.createElement("div");return G.style.cssText="display:flex;align-items:center;justify-content:center;background:#333;color:#999;font:12px sans-serif",G.textContent=`NativeView("${h}") — no web factory registered`,{el:G}},i=h=>{let G=g.get(h._viewId);if(!G){const F=e.get(h.viewName);G=F?F(h.params,{emit:(c,U)=>h._emitViewEvent(c,U===void 0?void 0:JSON.stringify(U))}):C(h.viewName),g.set(h._viewId,G)}return G};return{registerView:A,isViewSupported:t,ensureInstance:i,viewCall:(h,G,F,c,U)=>{const y=g.get(h);if(!(y!=null&&y.call)){U(`NativeView call "${G}": no live instance or no call handler (viewId ${h})`);return}try{Promise.resolve(y.call(G,JSON.parse(F))).then(l=>c(l===void 0?void 0:JSON.stringify(l)),l=>U(l instanceof Error?l.message:String(l)))}catch(l){U(l instanceof Error?l.message:String(l))}},mountInto:(h,G)=>{const{el:F}=i(h);F.style.position="absolute",F.style.inset="0",G.appendChild(F)},destroy:()=>{var h;for(const G of g.values())(h=G.destroy)==null||h.call(G);g.clear()}}},ot=[.2,0,0,1],$o={none:{},fade:{duration:280,incoming:{from:{opacity:0}}},"slide-from-right":{duration:400,incoming:{from:{x:"100%"}},outgoing:{to:{x:"-30%"}}},"slide-from-left":{duration:400,incoming:{from:{x:"-100%"}},outgoing:{to:{x:"30%"}}},"slide-from-top":{duration:400,incoming:{from:{y:"-100%"}},outgoing:{to:{y:"30%"}}},"slide-from-bottom":{duration:400,incoming:{from:{y:"100%"}},outgoing:{to:{y:"-30%"}}},zoom:{duration:400,easing:[.33,1.2,.62,1],incoming:{from:{scale:.985}}},"zoom-in":{duration:400,easing:[.33,1.2,.62,1],incoming:{from:{scale:1.08,opacity:0}},onTop:"incoming"},"zoom-out":{duration:420,outgoing:{to:{scale:.92,opacity:0}},onTop:"outgoing"},push:{duration:350,easing:ot,incoming:{from:{x:"100%"}},outgoing:{to:{x:"-25%"}},dim:.3,onTop:"incoming"},pop:{duration:350,easing:ot,incoming:{from:{x:"-25%"}},outgoing:{to:{x:"100%"}},dim:.3,onTop:"outgoing"}},AE=e=>{const g=[];if(e.x!==void 0||e.y!==void 0){const A=t=>t===void 0?"0px":typeof t=="number"?t+"px":t;g.push(`translate(${A(e.x)}, ${A(e.y)})`)}return e.scale!==void 0&&g.push(`scale(${e.scale})`),g.length>0?g.join(" "):"none"},Et=e=>{const g={transform:AE(e)};return e.opacity!==void 0&&(g.opacity=e.opacity),g},rt={transform:"none",opacity:1},gE=e=>{const g=t=>t===void 0?void 0:typeof t=="number"?-t:t.startsWith("-")?t.slice(1):"-"+t,A={};return e.x!==void 0&&(A.x=g(e.x)),e.y!==void 0&&(A.y=g(e.y)),e.scale!==void 0&&(A.scale=2-e.scale),(e.opacity!==void 0||Object.keys(A).length===0)&&(A.opacity=0),A},IE=e=>{let g=null;return{play:t=>{var O,q,S,b,T;g==null||g();const C=typeof t.transition=="string"?$o[t.transition]:t.transition??void 0,i=t.incoming&&!t.incoming.static?t.incoming.el:null,E=t.outgoing&&!t.outgoing.static?t.outgoing.el:null;let r=(O=C==null?void 0:C.incoming)==null?void 0:O.from,w=(q=C==null?void 0:C.outgoing)==null?void 0:q.to;if((S=t.incoming)!=null&&S.static&&E&&(C!=null&&C.incoming||C!=null&&C.outgoing)&&((C==null?void 0:C.onTop)!=="outgoing"&&(w=r?gE(r):w??{opacity:0}),r=void 0),(b=t.outgoing)!=null&&b.static&&i&&!r&&C&&Object.keys(C).length>0&&(r={opacity:0}),!C||!(i&&r||E&&w)||typeof((T=i??E)==null?void 0:T.animate)!="function"){t.onDone();return}const G=C.duration??300,F=C.easing?`cubic-bezier(${C.easing.join(",")})`:"cubic-bezier(0.25, 0.1, 0.25, 1)",c=[],U=C.onTop??"incoming",y=U==="incoming"?i:E,l=U==="incoming"?E:i;y&&(y.style.zIndex="3"),l&&(l.style.zIndex="1");let D=null;if(C.dim&&C.dim>0){D=document.createElement("div"),D.style.cssText="position:absolute;inset:0;background:#000;pointer-events:none;z-index:2",e.appendChild(D);const[Y,z]=U==="incoming"?[0,C.dim]:[C.dim,0];c.push(D.animate([{opacity:Y},{opacity:z}],{duration:G,easing:F}))}i&&r&&c.push(i.animate([Et(r),rt],{duration:G,easing:F})),E&&w&&c.push(E.animate([rt,Et(w)],{duration:G,easing:F,fill:"forwards"}));let R=!1;const L=()=>{if(!R){R=!0,g=null;for(const Y of c)Y.cancel();y&&(y.style.zIndex=""),l&&(l.style.zIndex=""),D==null||D.remove(),t.onDone()}};g=L,Promise.all(c.map(Y=>Y.finished)).then(L,L)},finish:()=>g==null?void 0:g()}},st={portrait:[20,0,8,0],landscape:[0,8,0,20]},Yt=(e,g)=>({insets:g?e.landscape:e.portrait,bars:(g?e.landscapeBars:e.portraitBars)??[]}),nt=256,eE={top:1,right:2,bottom:4,left:8},tE=async(e,g)=>{const A=await fetch(Mt).then(N=>N.arrayBuffer()),t=await bt({wasmBinary:A}),C=document.createElement("style");C.innerHTML=Jo,e.append(C);const i=new Map;let E=0;const r=new Map;let w=1;const h=(N,j)=>{var $;return($=(N<0?r:i).get(N))==null?void 0:$.nodeMap.get(j)},G=N=>(N<0?r:i).get(N),F=N=>{N<0?r.delete(N):i.delete(N)},c=bo(h),U=t.addFunction(c.measure,"jiififi");t._setMeasureFunc(U);const y=Xo(t);let l,D=null;vo({module:t,root:e,getNode:h,getScreen:G,addStringHandler:(N,j)=>{const $=N.length+1,eA=t._malloc($);t.stringToUTF8(N,eA,$);const yA=t.addFunction(j,"viii");t._addStringHandler(eA,yA),t._free(eA)},addFloatHandler:(N,j)=>{const $=N.length+1,eA=t._malloc($);t.stringToUTF8(N,eA,$);const yA=t.addFunction(j,"viif");t._addFloatHandler(eA,yA),t._free(eA)},addUIntHandler:(N,j)=>{const $=N.length+1,eA=t._malloc($);t.stringToUTF8(N,eA,$);const yA=t.addFunction(j,"viii");t._addUIntHandler(eA,yA),t._free(eA)},addResetHandler:(N,j)=>{const $=N.length+1,eA=t._malloc($);t.stringToUTF8(N,eA,$);const yA=t.addFunction(j,"vii");t._addResetHandler(eA,yA),t._free(eA)},addMatrixHandler:N=>{const j=t.addFunction(N,"viii");t._setMatrixHandler(j)},addTransformOriginHandler:N=>{const j=t.addFunction(N,"viiffii");t._setTransformOriginHandler(j)}});const T=new Map,Y=N=>{let j=T.get(N);if(j===void 0){const $=N.length+1;j=t._malloc($),t.stringToUTF8(N,j,$),T.set(N,j)}return j},z=(N,j,$,eA)=>{const yA=Y($);if(eA===void 0){t._resetPropExt(N,j,yA);return}switch(typeof eA){case"number":t._setFloatExt(N,j,yA,eA);break;case"boolean":t._setFloatExt(N,j,yA,eA?1:0);break;case"object":if(eA===null)t._resetPropExt(N,j,yA);else if("_id"in eA)z(N,j,$,bI(eA._id));else if("svg"in eA)z(N,j,$,MI(eA.svg));else{const ag=t._getLayer(j,yA);OA.applyStyleTransition(j,eA,ag)}break;default:const UA=t.lengthBytesUTF8(eA)+1,WA=t._malloc(UA);t.stringToUTF8(eA,WA,UA),t._setStringExt(N,j,yA,WA),t._free(WA)}},gA=()=>[e.clientWidth,e.clientHeight];let EA={};const iA=N=>{EA=N},lA=zo(),DA=IE(e);let a=null;const f=N=>{const j=new Qt(t,SA,z,Fg,y,l,F,g,lA),$=E++;return i.set($,j),j.init($,N),j};l=jo(t,{newScreen:f});const u=N=>{switch(N==null?void 0:N.type){case"scene3d":case"scene2d":return{kind:N.type,desc:N};case"native":return{kind:"native",desc:N};case"videoView":return{kind:"videoView",desc:N};default:return{kind:"screen",node:N,screen:f(N)}}},m=(N,j)=>{const $=N.kind==="screen"?N.node:N.desc._p;for(const eA of($==null?void 0:$[j])??[])eA()},W=N=>a!==null&&(a.kind==="screen"?a.node===N:a.desc===N),x=()=>{for(const N of r.values()){if(N.ownerDesc===void 0)continue;const j=W(N.ownerDesc);N.root.style.display=j?"":"none",N.overlayElement&&(N.overlayElement.style.display=j?"":"none")}},IA=N=>{if(N.kind==="screen")return e.appendChild(N.screen.root),N.screen.applyLayout(cA,n),m(N,"ol"),N.screen.setPagersActive(!0),{el:N.screen.root};if(N.kind==="scene3d"||N.kind==="scene2d"){const eA=EA[N.kind];if(!eA){console.error(`[le.codes] openView: this host has no ${N.kind==="scene3d"?"3D":"2D"} engine`);return}return eA.open(N.desc.sceneId),eA.el.style.display="block",m(N,"ol"),{el:eA.el,static:!0}}if(N.kind==="native"){const eA=N.cell??(N.cell=document.createElement("div"));return eA.style.cssText="position:absolute;inset:0;overflow:hidden",lA.mountInto(N.desc._p,eA),e.appendChild(eA),m(N,"ol"),{el:eA}}const j=fe(N.desc.node);N.restore={parent:j.parentElement,next:j.nextSibling,cssText:j.style.cssText};const $=N.wrapper??(N.wrapper=document.createElement("div"));return $.style.cssText="position:absolute;inset:0;background:#000",j.style.cssText="position:absolute;inset:0;width:100%;height:100%;object-fit:contain",$.appendChild(j),e.appendChild($),m(N,"ol"),{el:$}},QA=N=>{if(N.kind==="screen")return{el:N.screen.root};if(N.kind==="scene3d"||N.kind==="scene2d"){const j=EA[N.kind];return j?{el:j.el,static:!0}:void 0}return N.kind==="native"?N.cell?{el:N.cell}:void 0:N.wrapper?{el:N.wrapper}:void 0},nA=(N,j)=>{var eA,yA;if(N.kind==="screen"){j&&!YA.stack.includes(N)?N.screen.remove():N.screen.removeFromHTML();return}if(N.kind==="scene3d"||N.kind==="scene2d"){const UA=EA[N.kind];UA&&(UA.close(),UA.el.style.display="none");return}if(N.kind==="native"){(eA=N.cell)==null||eA.remove();return}const $=fe(N.desc.node);N.restore&&($.style.cssText=N.restore.cssText,N.restore.parent?N.restore.parent.insertBefore($,N.restore.next):$.remove()),(yA=N.wrapper)==null||yA.remove()};let hA=null,sA=!1;const MA=N=>{if(N===hA){sA=!0;return}N.kind==="screen"&&N.screen.remove()},LA=(N,j,$)=>{DA.finish();const eA=a;if(eA===N)return;eA&&m(eA,"cl"),a=N,D=(N==null?void 0:N.kind)==="screen"?N.screen:null;const yA=N?IA(N):void 0;x(),eA&&(hA=eA,sA=!1,DA.play({incoming:yA,outgoing:QA(eA),transition:j,onDone:()=>{const UA=$||sA;hA=null,nA(eA,UA)}}))},bA=(N,j)=>{YA.show&&mA();const[$,eA]=gA();vA($,eA),LA(u(N),j??"none",!0)},jA=()=>{LA(null,"none",!0)},ZA=N=>bA(N,"none");let HA,zA=null;const YA=new Po(N=>{const j=zA;zA=null,LA(N,j,!1),HA==null||HA(N.kind==="screen"?N.node:N.desc)},MA),Ig=(N,j)=>{a&&(m(a,"cl"),nA(a,!YA.stack.includes(a)),a=null,D=null);for(const yA of YA.stack)MA(yA);YA.stack=[];const[$,eA]=gA();vA($,eA),HA=j,YA.init(u(N))},xg=(N,j)=>{zA=j??"push",YA.push(u(N))},ug=(N,j)=>{zA=j??"fade",YA.replace(u(N))},og=(N,j)=>{zA=j??"pop",YA.pop(N)},mA=()=>{if(YA.hide(),a&&YA.stack.includes(a)){DA.finish(),m(a,"cl");const N=a;a=null,D=null,nA(N,!1),x()}},qg=()=>{YA.restore()},Rg=N=>{const j=G(t._getScreenId(N))??D,$=j==null?void 0:j.nodeMap.get(N);return $?$.value:""},Eg=N=>{const j=G(t._getScreenId(N))??D,$=j==null?void 0:j.nodeMap.get(N);if(!$||!$.isConnected)return null;const eA=$.getBoundingClientRect();if(eA.width===0&&eA.height===0&&eA.left===0&&eA.top===0)return null;const yA=e.getBoundingClientRect(),[UA]=tA(),WA=UA>0&&yA.width>0?yA.width/UA:1;return[(eA.left-yA.left)/WA,(eA.top-yA.top)/WA,eA.width/WA,eA.height/WA]},mg=()=>jA(),rg=(N,j,$)=>{const eA=t._getScreenId(N),yA=G(eA);if(!yA)return;const UA=yA.nodeMap.get(N);if(UA)switch(j){case"text":UA.textContent=$,t._markNodeDirty(N),yA.recalc();break;case"value":UA.value=$,UA instanceof HTMLTextAreaElement&&t._nodeHasMeasure(N)&&(t._markNodeDirty(N),yA.recalc());break;case"src":yA.updateImageSrc(UA,$);break}},sg=(N,j,$,eA,yA)=>{var UA;(UA=G(t._getScreenId(N)))==null||UA.setSourceRect(N,j,$,eA,yA)},VA=N=>{for(const j of i.values())j.refreshCanvasSurface(N);for(const j of r.values())j.refreshCanvasSurface(N)},ng=[],wg=()=>{for(const N of[i,r])for(const j of N.values())for(const $ of j.nodeMap.keys())t._nodeHasMeasure($)&&t._markNodeDirty($)},eg=()=>{if(!(!cA||!n)){D==null||D.applyLayout(cA,n);for(const N of r.values())N.applyLayout(cA,n)}},_A=(N,j,$,eA,yA)=>{const UA=new FontFace(N,`url(${j})`,$);document.fonts.add(UA),ng.push(UA),UA.load().then(()=>{wg(),eg(),eA()}).catch(yA)},pA=(N,j,$)=>{var eA;z(nt,N,j,$),(eA=G(t._getScreenId(N)))==null||eA.recalc()},wA=(N,j)=>{var $;for(let[eA,yA]of Object.entries(j))z(nt,N,eA,yA);($=G(t._getScreenId(N)))==null||$.recalc()},Fg=(N,j)=>t._getLayer(N,Y("$"+j)),Tg=(N,j,$)=>{var eA;t._setNodeClass(N,Y(j),$),(eA=G(t._getScreenId(N)))==null||eA.recalc()},OA=Ko(t,C,h,z,N=>{var j;return(j=G(t._getScreenId(N)))==null?void 0:j.overlayElement}),TA=Ro(e);let kg=()=>{},cA,n,PA=st;const vA=(N,j)=>{if(N===0||j===0)return;const{insets:$,bars:eA}=Yt(PA,N>j);t._setSafeAreaBars(eA.reduce((yA,UA)=>yA|eE[UA],0)),t._setSafePaddings($[0],$[1],$[2],$[3]),t._setConditionValue(N,j),D&&(D==null||D.applyLayout(N,j));for(const yA of r.values())yA.applyLayout(N,j);cA=N,n=j,kg(N,j)},V=N=>{kg=N},tA=()=>[cA??0,n??0],rA=N=>{PA=N??st,cA&&n&&vA(cA,n)},FA=N=>{for(const $ of Object.keys(N)){const eA=$==="fontFamily"&&typeof N[$]=="string"?be(N[$]):N[$],yA=eA==null?null:typeof eA=="number"?`${eA}px`:eA,UA=$.length+1,WA=t._malloc(UA);t.stringToUTF8($,WA,UA);let ag=0;if(yA!==null){const Kg=t.lengthBytesUTF8(yA)+1;ag=t._malloc(Kg),t.stringToUTF8(yA,ag,Kg)}t._setThemeValue(WA,ag),ag&&t._free(ag),t._free(WA),yA===null?e.style.removeProperty(`--${$}`):e.style.setProperty(`--${$}`,yA)}let j=t._applyTheme();if("fontFamily"in N&&(Lo(N.fontFamily==null?null:String(N.fontFamily)),wg(),j=!0),j&&cA&&n){D==null||D.applyLayout(cA,n);for(const $ of r.values())$.applyLayout(cA,n)}},SA=ko(e);SA.onNodeStateChanged((N,j)=>{t._setNodePressed(N,j)});const P=e.style.touchAction;e.style.touchAction="pan-x pan-y";const dA=mo(e,{scroller:".scrollable,.vlist,.pager"});e.addEventListener("pointerdown",SA.onSceneTouchDown),e.addEventListener("pointerup",SA.onSceneTouchEnd),e.addEventListener("pointercancel",SA.onSceneTouchCancel);const kA=Uo(e),tg=()=>{kA(),dA(),e.style.touchAction=P,e.removeEventListener("pointerdown",SA.onSceneTouchDown),e.removeEventListener("pointerup",SA.onSceneTouchEnd),e.removeEventListener("pointercancel",SA.onSceneTouchCancel),SA._destroy(),lA.destroy();for(const N of ng)document.fonts.delete(N);ng.length=0},Ug=(N,j)=>{var UA;for(let WA of r.values())if(WA.node===N)return;const $=new Qt(t,SA,z,Fg,y,l,F,g,lA);$.isWidget=!0,$.ownerDesc=j,r.set(-w,$),$.init(-w,N),w++;const[eA,yA]=gA();$.applyLayout(eA,yA),$.root.classList.add("widget"),((UA=N.touchStartListeners)==null?void 0:UA.length)>0&&$.root.classList.add("interactive"),e.appendChild($.root),$.setPagersActive(!0),j!==void 0&&x()},iI=N=>{if(!N._id)return;const j=t._getScreenId(N._id);if(j>=0)return;const $=G(j);$==null||$.remove()},pg=(N,j,$)=>{const eA=t._getScreenId(j),yA=G(eA);yA==null||yA.insertNode(N,j,$)},QI=(N,j)=>{const $=t._getScreenId(N),eA=G($);eA==null||eA.removeNode(N,j)},Bg=(N,j,$)=>{const eA=t._getScreenId(N),yA=G(eA);yA==null||yA.setContent(N,j,$)};return{openScreen:ZA,closeScreen:mg,routerOpen:Ig,routerPush:xg,routerReplace:ug,routerPop:og,routerHide:mA,routerRestore:qg,openView:bA,closeView:jA,isViewSupported:lA.isViewSupported,viewCall:lA.viewCall,_registerView:lA.registerView,_setSceneHost:iA,updateNode:rg,setSourceRect:sg,refreshCanvasSurface:VA,updateStyle:pA,mergeStyle:wA,setClass:Tg,registerFont:_A,fontFormat:"woff2",toast:TA,registerTouchStartEvent:SA.registerTouchStartEvent,registerTouchEndEvent:SA.registerTouchEndEvent,isButtonPressed:SA.isButtonPressed,registerResizeEvent:V,getDisplaySize:tA,getTextValue:Rg,getBoundingClientRect:Eg,insertNode:pg,removeNode:QI,setContent:Bg,animateTo:OA.animateTo,animateFrom:OA.animateFrom,showWidget:Ug,hideWidget:iI,_onResize:vA,_destroy:tg,_setCreator:SA.setCreator,_setSafeAreaSpec:rA,setTheme:FA,...y.api,command:(N,j,...$)=>(N==null?void 0:N.type)==="pager"?l.command(N,j,...$):y.api.command(N,j,...$)}};class BE{constructor(g,A,t){X(this,"id");X(this,"type");X(this,"jsNode");X(this,"parent",null);X(this,"children",[]);X(this,"style",{});X(this,"layoutRect",null);X(this,"measured");X(this,"scrollOffset",0);X(this,"sourceRect");X(this,"name");X(this,"value","");X(this,"wrapCache");this.id=g,this.type=A,this.jsNode=t,this.measured=A==="text"||A==="image"||A==="input"||A==="textarea",typeof(t==null?void 0:t.name)=="string"&&t.name.length>0&&(this.name=t.name),A==="image"&&Array.isArray(t==null?void 0:t._sourceRect)&&(this.sourceRect=t._sourceRect.slice()),(A==="input"||A==="textarea")&&typeof(t==null?void 0:t._value)=="string"&&(this.value=t._value)}get text(){var g,A;return this.type==="text"?((g=this.jsNode)==null?void 0:g._text)??((A=this.jsNode)==null?void 0:A.text)??"":void 0}get imageSrcRaw(){var g,A;return this.type==="image"?((g=this.jsNode)==null?void 0:g._src)??((A=this.jsNode)==null?void 0:A.src):void 0}get scrollable(){var g;return this.type==="scrollable"||this.type==="vlist"||((g=this.jsNode)==null?void 0:g.scrollable)===!0}get editable(){return this.type==="input"||this.type==="textarea"}get scrollAxis(){return this.style.scrollAxis==="x"?"x":"y"}get interactive(){const g=this.jsNode;return g?g.type==="screen"||g.type==="widget"?Array.isArray(g.touchStartListeners)&&g.touchStartListeners.length>0:typeof g._emitClick=="function"||typeof g._emitTouchStart=="function"||Array.isArray(g.touchStartListeners)&&g.touchStartListeners.length>0:!1}}function Me(e){return typeof e=="object"&&e!==null&&"svg"in e}function xt(e){if(!Me(e))return;const g=e.tintColor;return typeof g=="string"&&g.length>0?g:void 0}function CE(e){return typeof e=="object"&&e!==null&&"_id"in e}function iE(e){return typeof e=="object"&&e!==null&&"canvasSurface"in e}const ue="lecodes-canvas://";function QE(e){return e.startsWith(ue)?Number(e.slice(ue.length)):void 0}function oE(e){return typeof File<"u"&&e instanceof File}function EE(e){let g=e.trim();/\sxmlns\s*=/.test(g)||(g=g.replace(/<svg\b/,'<svg xmlns="http://www.w3.org/2000/svg"'));const A=new TextEncoder().encode(g);let t="";for(const C of A)t+=String.fromCharCode(C);return`data:image/svg+xml;base64,${btoa(t)}`}function JI(e){return!!e&&(e.startsWith("data:image/svg+xml")||/\.svg(\?|#|$)/i.test(e))}function we(e){var i,E,r;const g=((i=e.match(/<svg\b[^>]*>/i))==null?void 0:i[0])??"",A=g.match(/viewBox\s*=\s*["']\s*[\d.+-]+\s+[\d.+-]+\s+([\d.+-]+)\s+([\d.+-]+)\s*["']/i);if(A){const w=parseFloat(A[1]),h=parseFloat(A[2]);if(w>0&&h>0)return{width:w,height:h}}const t=parseFloat(((E=g.match(/\bwidth\s*=\s*["']?([\d.]+)/i))==null?void 0:E[1])??""),C=parseFloat(((r=g.match(/\bheight\s*=\s*["']?([\d.]+)/i))==null?void 0:r[1])??"");return t>0&&C>0?{width:t,height:C}:null}function rE(e){const g=/^data:image\/svg\+xml(;[^,]*)?,([\s\S]*)$/.exec(e);if(!g)return null;const A=g[2];try{if(/;base64/i.test(g[1]??"")){const t=atob(A),C=new Uint8Array(t.length);for(let i=0;i<t.length;i++)C[i]=t.charCodeAt(i);return new TextDecoder().decode(C)}return decodeURIComponent(A)}catch{return null}}async function sE(e,g){if(!JI(e))return null;const A=rE(e);if(A)return we(A);if(!g)return null;const t=await g(e).catch(()=>null);return t?we(t):null}function qt(e={}){const g=new WeakMap;return A=>{var E,r;if(A==null)return;if(typeof A=="string")return A;if(typeof A!="object")return;const t=A,C=g.get(t);if(C!==void 0)return C;let i;return Me(t)?i=EE(t.svg):iE(t)?i=ue+t.canvasSurface:CE(t)?i=(E=e.assetUrl)==null?void 0:E.call(e,t._id):oE(t)&&(i=(r=e.fileUrl)==null?void 0:r.call(e,t)),i!==void 0&&g.set(t,i),i}}const Lg={color:255,fontSize:14,fontFamily:"Roboto",fontWeight:400,fontStyle:"normal",letterSpacing:0,textAlign:"start",textDecoration:"none"};function Fe(e){let g,A,t,C,i,E,r,w,h;for(let F=e;F;F=F.parent){const c=F.style;g??(g=c.color),A??(A=c.fontSize),t??(t=c.fontFamily),C??(C=c.fontWeight),i??(i=c.fontStyle),E??(E=c.lineHeight),r??(r=c.letterSpacing),w??(w=c.textAlign),h??(h=c.textDecoration)}const G=A??Lg.fontSize;return{color:g??Lg.color,fontSize:G,fontFamily:t??Lg.fontFamily,fontWeight:C??Lg.fontWeight,fontStyle:i??Lg.fontStyle,lineHeight:E??G*1.2,letterSpacing:r??Lg.letterSpacing,textAlign:w??Lg.textAlign,textDecoration:h??Lg.textDecoration}}function Tt(e){return{family:e.fontFamily,size:e.fontSize,weight:e.fontWeight,italic:e.fontStyle==="italic",letterSpacing:e.letterSpacing}}function yI(e,g,A){const t=[];let C=0;for(const i of e.split(`
187
- `)){if(i.length===0){t.push("");continue}let E=i;for(;E;){if(A(E)<=g){t.push(E),C=Math.max(C,A(E));break}let r=0,w=-1,h=0;for(;(h=E.indexOf(" ",h+1))!==-1&&!(A(E.substring(0,h))>g);)w=h;if(w>0)r=w;else{let F=E.indexOf(" ");F===-1&&(F=E.length);const c=E.substring(0,F);if(A(c)>g){for(let U=1;U<=c.length;U++)if(A(c.substring(0,U))>g){r=U-1;break}}else for(let U=F+1;U<=E.length;U++)if(A(E.substring(0,U))>g){r=U-1;break}}r<=0&&(r=1);const G=E.substring(0,r);t.push(G),C=Math.max(C,A(G)),E=E.substring(r+(w>0?1:0))}}return{lines:t,maxWidth:C}}const ce="…";function _t(e,g,A,t){const C=g.lineClamp??0;if(C<=0||e.length<=C)return e;const i=e.slice(0,C);return g.textOverflow==="clip"||(i[C-1]=nE(i[C-1],A,t)),i}function nE(e,g,A){if(!isFinite(g))return e+ce;const t=[...e];let C=t.length;for(;C>0&&A(t.slice(0,C).join("")+ce)>g;)C--;return t.slice(0,C).join("").trimEnd()+ce}function aE(e,g,A){const t=Fe(e),C=Tt(t),i=isNaN(A)?1/0:A,E=G=>g.measureText(G,C),r=yI(e.text??"",i,E),w=_t(r.lines,e.style,i,E);let h=r.maxWidth;if(w!==r.lines){h=0;for(const G of w)h=Math.max(h,E(G))}return{width:Math.ceil(h),height:Math.ceil(w.length*t.lineHeight)}}function cE(e,g,A){const t=e.style,C={family:t.fontFamily??"Roboto",size:t.fontSize??14,weight:t.fontWeight??400,italic:t.fontStyle==="italic",letterSpacing:t.letterSpacing??0},i=t.lineHeight??C.size*1.2,E=e.value??"";if(e.type==="input")return{width:Math.ceil(g.measureText(E,C)),height:Math.ceil(i)};const r=isNaN(A)?1/0:A,w=yI(E,r,h=>g.measureText(h,C));return{width:Math.ceil(w.maxWidth),height:Math.ceil(Math.max(1,w.lines.length)*i)}}function lE(e,g,A,t){const C=e.imageSrcRaw;let i=0,E=0,r=!1;if(e.sourceRect)i=e.sourceRect[2],E=e.sourceRect[3];else if(Me(C)){r=!0;const G=we(C.svg);if(G)i=G.width,E=G.height;else{const F=g.getImage(g.resolveSrc(C)??"");i=(F==null?void 0:F.naturalWidth)??0,E=(F==null?void 0:F.naturalHeight)??0}}else{const G=g.resolveSrc(C),F=G?g.getImage(G):void 0;i=(F==null?void 0:F.naturalWidth)??0,E=(F==null?void 0:F.naturalHeight)??0,r=JI(G)}if(i===0||E===0)return{width:0,height:0};const w=Math.min(A/i,t/E),h=isNaN(A)&&isNaN(t)?1:isNaN(A)?t/E:isNaN(t)?A/i:r?w:Math.min(w,1);return{width:i*h,height:E*h}}function hE(e,g){return Wt(e,g.rootRect.x,g.rootRect.y,!0,g)}function Wt(e,g,A,t,C){var y,l;if(e.style.display==="none")return null;let i,E,r,w;if(t)i=C.rootRect.x,E=C.rootRect.y,r=C.rootRect.width,w=C.rootRect.height;else{const D=e.layoutRect;if(!D)return null;i=g+D.x,E=A+D.y,r=D.width,w=D.height}const h={x:i,y:E,width:r,height:w},G={id:e.id,type:e.type,rect:h,style:e.style,children:[]};if(e.name&&(G.name=e.name),e.type==="text"){const D=Fe(e),R=Tt(D),L=e.text??"";G.text=L;const O=C.layout.getPadding(e.id);(O[0]||O[1]||O[2]||O[3])&&(G.padding=O);const q=r-O[0]-O[2],S=`${e.style.lineClamp??0}|${e.style.textOverflow??""}`,b=`${q}|${R.size}|${R.weight}|${R.italic?1:0}|${R.letterSpacing}|${R.family}|${S}|${L}`;if(((y=e.wrapCache)==null?void 0:y.key)===b)G.lines=e.wrapCache.lines;else{const T=z=>C.host.measureText(z,R),Y=_t(yI(L,q,T).lines,e.style,q,T);e.wrapCache={key:b,lines:Y},G.lines=Y}G.style={...e.style,color:D.color,fontSize:D.fontSize,fontFamily:D.fontFamily,fontWeight:D.fontWeight,fontStyle:D.fontStyle,lineHeight:D.lineHeight,letterSpacing:D.letterSpacing,textAlign:D.textAlign,textDecoration:D.textDecoration}}else if(e.type==="image"){const D=C.host.resolveSrc(e.imageSrcRaw),R=D?C.host.getImage(D):void 0;G.image=R??(D?{src:D,naturalWidth:0,naturalHeight:0}:void 0),e.sourceRect&&(G.sourceRect=e.sourceRect)}else if(e.editable){G.value=e.value;const D=C.layout.getPadding(e.id);(D[0]||D[1]||D[2]||D[3])&&(G.padding=D);const R=Fe(e);G.style={...e.style,color:R.color,fontSize:R.fontSize,fontFamily:R.fontFamily,fontWeight:R.fontWeight,fontStyle:R.fontStyle,lineHeight:R.lineHeight,letterSpacing:R.letterSpacing,textAlign:R.textAlign,textDecoration:R.textDecoration}}e.interactive&&(G.state={pressed:C.isPressed(e)}),e.editable&&C.isFocused(e)&&(G.state={...G.state,focused:!0});const F=(l=e.jsNode)==null?void 0:l._classes;F&&F.size>0&&(G.state={...G.state,classes:[...F]}),e.style.overflow==="hidden"&&(G.clip=!0);let c=i,U=E;if(e.scrollable){const D=e.scrollAxis,R=D==="x"?C.layout.getContentWidth(e.id):C.layout.getContentHeight(e.id);G.clip=!0,G.scroll={offset:e.scrollOffset,content:R,axis:D},D==="x"?c=i-e.scrollOffset:U=E-e.scrollOffset}for(const D of e.children){const R=Wt(D,c,U,!1,C);R&&G.children.push(R)}return G}const dE=256,yE=new Set(["duration","delay","layer","commit"]);function eI(e,g,A,t,C=dE,i){if(t===null){e.setStyle(g,A,null,C);return}const E=typeof t;if(E==="number"||E==="string"||E==="boolean"){e.setStyle(g,A,t,C);return}if(E!=="object")return;const r=t;if("_id"in r||"svg"in r||DE(r)){const h=i==null?void 0:i(r);h!=null&&e.setStyle(g,A,h,C);return}const w=e.getLayer(g,A);for(const h of Object.keys(r))yE.has(h)||eI(e,g,h,r[h],w,i)}function DE(e){return typeof File<"u"&&e instanceof File}function at(e){const g=(Array.isArray(e.children)?e.children:[]).filter(w=>!!w);if(g.length===0)return null;const A=e._lens,t=Array.isArray(A)&&A.length>0?A:g.map(()=>1),C=e._index,i=Math.min(Math.max(typeof C=="number"?C:0,0),t.length-1);let E=0;for(let w=0;w<i;w++)E+=t[w]??0;const r=E+(t[i]??1)-1;return g[Math.min(r,g.length-1)]??null}function ct(e,g,A,t,C){var r;const i=(r=e.jsNode)==null?void 0:r.ll;if(!i||i.length===0)return;const E={left:g,top:A,width:t,height:C};for(const w of i)w(E)}function fE(e,g,A){switch(g){case"screen":e.setStyle(A,"color","var(--color, #ffffffff)"),e.setStyle(A,"fontFamily","var(--fontFamily, Roboto)");break;case"vlist":e.setStyle(A,"flexDirection","column");break}}class le{constructor(g,A,t,C,i=!1,E=r=>typeof r=="string"?r:void 0){X(this,"screenId");X(this,"isWidget");X(this,"jsNode");X(this,"root");X(this,"layout");X(this,"registry");X(this,"resolveSrc");X(this,"width",0);X(this,"height",0);X(this,"dirty",!1);X(this,"cachedTree",null);X(this,"firedScreenW",-1);X(this,"firedScreenH",-1);this.screenId=g,this.jsNode=A,this.layout=t,this.registry=C,this.isWidget=i,this.resolveSrc=E}mount(){this.root=this.addNode(this.jsNode,null,0)}addNode(g,A,t){var G,F;const C=g.type,i=C==="text"||C==="image"||C==="input"||C==="textarea",E=A===null?this.layout.createRoot(this.screenId):this.layout.createChild(A.id,t,i),r=new BE(E,C,g);r.parent=A,g._id=E,this.registry.register(r),fE(this.layout,C,E),(A==null?void 0:A.type)==="pager"&&(this.setStyleValue(E,"width","100%"),this.setStyleValue(E,"height","100%"));const w=g._style??{};for(const c of Object.keys(w))this.setStyleValue(E,c,w[c]);if(C==="image"&&w.tintColor==null){const c=xt(r.imageSrcRaw);c!=null&&this.setStyleValue(E,"tintColor",c)}if(g._classes)for(const c of g._classes)this.layout.enableNodeLayer(E,this.layout.getLayer(E,"$"+c));const h=C==="pager"?[at(g)]:g.children;if(Array.isArray(h)){let c=0;for(const U of h)U&&(r.children.push(this.addNode(U,r,c)),c++)}if(C==="pager"&&r.children.length>0)for(const c of r.children[0].jsNode.ol??[])c();return(F=(G=this.registry).onNodeAdded)==null||F.call(G,r),r}pagerReconcile(g){const A=this.registry.get(g._id);if(!A)return!1;const t=at(g),C=A.children[0]??null;if(C?C.jsNode===t:t===null)return!1;if(C){for(const i of C.jsNode.cl??[])i();this.layout.removeChild(A.id,C.id),this.releaseRecursive(C.jsNode),A.children.length=0}if(t){A.children.push(this.addNode(t,A,0));for(const i of t.ol??[])i()}return this.dirty=!0,!0}setStyleValue(g,A,t){eI(this.layout,g,A,t,void 0,this.resolveSrc)}applyLayout(g,A){g===this.width&&A===this.height&&!this.dirty||(this.width=g,this.height=A,this.dirty=!1,this.layout.calculate(this.root.id,g,A,this.isWidget),this.captureLayout(this.root),this.cachedTree=null)}captureLayout(g){if(g===this.root&&!this.isWidget)(this.width!==this.firedScreenW||this.height!==this.firedScreenH)&&(this.firedScreenW=this.width,this.firedScreenH=this.height,ct(g,0,0,this.width,this.height));else{const A=this.layout.getLayout(g.id);A&&(g.layoutRect=A,ct(g,A.x,A.y,A.width,A.height))}for(const A of g.children)this.captureLayout(A)}markDirty(){this.dirty=!0,this.cachedTree=null}isDirty(){return this.dirty||this.cachedTree===null}deactivate(){this.width=0,this.height=0,this.firedScreenW=-1,this.firedScreenH=-1,this.dirty=!1,this.cachedTree=null}renderTree(g,A,t=()=>!1){if(this.dirty&&this.width>0&&(this.dirty=!1,this.layout.calculate(this.root.id,this.width,this.height,this.isWidget),this.captureLayout(this.root),this.cachedTree=null),this.cachedTree)return this.cachedTree;const C=this.isWidget?this.root.layoutRect??{x:0,y:0,width:0,height:0}:{x:0,y:0,width:this.width,height:this.height};return this.cachedTree=hE(this.root,{layout:this.layout,host:g,rootRect:C,isPressed:A,isFocused:t}),this.cachedTree}insertNode(g,A,t){const C=this.registry.get(g);if(!C)return;const i=this.addNode(t,C,A);C.children.splice(A,0,i),this.dirty=!0}removeNode(g,A){const t=this.registry.get(g);if(!t)return;const C=A._id,i=t.children.findIndex(E=>E.id===C);i>=0&&t.children.splice(i,1),this.layout.removeChild(g,C),this.releaseRecursive(A),this.dirty=!0}setContent(g,A,t){const C=this.registry.get(g);if(!C)return;for(const E of A){if(!E)continue;const r=E._id;this.layout.removeChild(g,r),this.releaseRecursive(E)}C.children.length=0;let i=0;for(const E of t)E&&(C.children.push(this.addNode(E,C,i)),i++);this.dirty=!0}releaseRecursive(g){g._id&&this.registry.unregister(g._id),g._id=0;const A=g.children;if(Array.isArray(A))for(const t of A)t&&this.releaseRecursive(t)}destroy(){this.releaseRecursive(this.jsNode),this.layout.freeTree(this.root.id,this.isWidget)}}class GE{constructor(g,A){X(this,"show",!1);X(this,"stack",[]);this.onScreen=g,this.free=A}init(g){this.stack=[g],this.onScreen(g),this.show=!0}push(g){this.stack.push(g),this.onScreen(g)}replace(g){const A=this.stack[this.stack.length-1];this.stack[this.stack.length-1]=g,this.onScreen(g),A&&this.free(A)}hide(){this.show=!1}pop(g){const A=g<0?Math.max(this.stack.length-1+g,0):Math.min(g,this.stack.length-1),t=this.stack.slice(A+1);this.stack.length=A+1,this.onScreen(this.stack[A]);for(const C of t)this.free(C)}restore(){this.show=!0,this.onScreen(this.stack[this.stack.length-1])}get current(){return this.stack[this.stack.length-1]}}class uE{constructor(g){X(this,"vlists",new Map);this.host=g}remove(g){this.vlists.delete(g)}initVlist(g){var C,i,E;const A={node:g,keys:[],items:new Map,endLatched:!1,startLatched:!1,invertedInitial:!!((C=g.jsNode)!=null&&C._inverted)};this.vlists.set(g.id,A);const t=((i=g.jsNode)==null?void 0:i._keys)??[];t.length&&this.vlistSetKeys(g.jsNode,t,((E=g.jsNode)==null?void 0:E._estimates)??[])}settle(g){for(const[A,t]of this.vlists){if(!t.invertedInitial||this.host.getScreenOf(A)!==g)continue;const C=this.host.getNode(A);C&&this.scrollVlistToEnd(C),t.invertedInitial=!1}}checkEdges(g,A,t){const C=this.vlists.get(g.id),i=g.jsNode;if(!(!C||!i)){if(Array.isArray(i.erl)&&i.erl.length){const E=t-A<=(i._endThreshold??0);if(E&&!C.endLatched){C.endLatched=!0;for(const r of i.erl)r()}else E||(C.endLatched=!1)}if(Array.isArray(i.strl)&&i.strl.length){const E=A<=(i._startThreshold??0);if(E&&!C.startLatched){C.startLatched=!0;for(const r of i.strl)r()}else E||(C.startLatched=!1)}}}vlistChildIndex(g,A){const t=g.keys.indexOf(A);let C=0;for(const i of g.items.keys())g.keys.indexOf(i)<t&&C++;return C}unmountVlistItem(g,A,t){var i;const C=g.items.get(t);C!==void 0&&((i=this.host.getScreenOf(A))==null||i.removeNode(A,C),g.items.delete(t))}vlistMount(g,A,t){const C=this.vlists.get(g._id);if(!C||t==null)return;const i=this.host.getScreenOf(g._id);i==null||i.insertNode(g._id,this.vlistChildIndex(C,A),t),this.host.preloadNew(t,i),C.items.set(A,t)}vlistSetKeys(g,A,t){var E;const C=this.vlists.get(g._id);if(!C)return;const i=[...C.keys];for(const r of i)this.unmountVlistItem(C,g._id,r);C.keys=[...A],(E=g._syncWindow)==null||E.call(g,i,A)}vlistInsertKeys(g,A,t,C){var G;const i=this.vlists.get(g._id);if(!i)return;const E=this.host.getNode(g._id),r=A<0||A>=i.keys.length,w=r?i.keys.length:Math.max(0,A),h=E?this.host.isAtScrollEnd(E):!1;i.keys.splice(w,0,...t),w===0&&E&&C&&C.length&&(E.scrollOffset+=C.reduce((F,c)=>F+(c||0),0)),(G=g._syncWindow)==null||G.call(g,[],t),r&&E&&g._inverted&&h&&this.scrollVlistToEnd(E)}vlistRemoveKeys(g,A){var i;const t=this.vlists.get(g._id);if(!t)return;const C=A.filter(E=>t.items.has(E));for(const E of A){this.unmountVlistItem(t,g._id,E);const r=t.keys.indexOf(E);r>=0&&t.keys.splice(r,1)}C.length&&((i=g._syncWindow)==null||i.call(g,C,[]))}vlistInvalidate(g,A){var C;const t=this.vlists.get(g._id);!t||!t.keys.includes(A)||(this.unmountVlistItem(t,g._id,A),(C=g._syncWindow)==null||C.call(g,[A],[A]))}command(g,A,...t){const C=this.host.getNode(g._id);if(C){if(A==="scrollTo")this.host.scrollBy(C.id,(t[0]??0)-C.scrollOffset);else if(A==="scrollToEnd")this.scrollVlistToEnd(C);else if(A==="scrollToKey"){const i=this.vlists.get(C.id),E=i==null?void 0:i.items.get(t[0]),r=E?this.host.getNode(E._id):void 0;r!=null&&r.layoutRect&&this.host.scrollBy(C.id,r.layoutRect.y-C.scrollOffset)}}}scrollVlistToEnd(g){var A;(A=this.host.getScreenOf(g.id))==null||A.applyLayout(this.host.viewport().width,this.host.layoutHeight()),this.host.scrollBy(g.id,Number.MAX_SAFE_INTEGER)}}const he=["opacity","backgroundColor","color","tintColor","overlayColor","transform"],wE=new Set(["backgroundColor","color","tintColor","overlayColor"]),lt=[1,0,0,1,0,0];function FE(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function SE(e,g){return Array.isArray(e)&&Array.isArray(g)?e.length===g.length&&e.every((A,t)=>A===g[t]):e===g}const gI=(e,g,A)=>e+(g-e)*A;function RE(e,g,A){const t=(w,h)=>w>>>h&255,C=Math.round(gI(t(e,24),t(g,24),A)),i=Math.round(gI(t(e,16),t(g,16),A)),E=Math.round(gI(t(e,8),t(g,8),A)),r=Math.round(gI(t(e,0),t(g,0),A));return(C<<24|i<<16|E<<8|r)>>>0}function kE(e,g,A,t){return e==="transform"?g.map((C,i)=>gI(C,A[i],t)):wE.has(e)?RE(g,A,t):gI(g,A,t)}function UE(e,g,A){return e==="opacity"?{from:g??1,to:A??1}:e==="transform"?{from:g??lt,to:A??lt}:g===void 0||A===void 0?null:{from:g,to:A}}function pE(e){const g=e>>>0;return{r:g>>>24&255,g:g>>>16&255,b:g>>>8&255,a:g&255}}function Xg(e){return"#"+(e>>>0).toString(16).padStart(8,"0")}function Pg(e){const{r:g,g:A,b:t,a:C}=pE(e);return`rgba(${g}, ${A}, ${t}, ${(C/255).toFixed(4)})`}function Zt(e){return e===void 0||(e>>>0&255)===0}class NE{constructor(g){X(this,"tweens",[]);this.host=g}hasActive(){return this.tweens.length>0}animateTo(g,A){const t=this.host.getNode(g);if(!t)return;const C=this.snapshot(t);this.applyAuthoring(g,A);const i=this.snapshot(t);this.startTween(g,C,i,A==null?void 0:A.duration,A==null?void 0:A.delay)}animateFrom(g,A){const t=this.host.getNode(g);if(!t)return;const C=this.snapshot(t);this.applyAuthoring(g,A);const i=this.snapshot(t);this.applyResolved(g,C),this.startTween(g,i,C,A==null?void 0:A.duration,A==null?void 0:A.delay)}tick(g){if(this.tweens.length===0)return;const A=new Set;for(const t of this.tweens){t.elapsed+=g;const C=this.host.getNode(t.nodeId);if(C){this.applyTweenFrame(t,C);const i=this.host.getScreenOf(t.nodeId);i&&A.add(i)}}this.tweens=this.tweens.filter(t=>t.elapsed<t.delay+t.duration&&this.host.getNode(t.nodeId)!==void 0);for(const t of A)t.markDirty()}snapshot(g){const A={};for(const t of he){const C=g.style[t];A[t]=Array.isArray(C)?[...C]:C}return A}applyAuthoring(g,A){var i;if(!A)return;let t=!1;for(const E of Object.keys(A))E==="duration"||E==="delay"||E==="layer"||E==="commit"||(eI(this.host.layout,g,E,A[E],void 0,this.host.resolveSrc),this.host.isMeasureAffecting(E)&&(t=!0));const C=this.host.getNode(g);(C!=null&&C.measured||t)&&this.host.layout.markDirty(g),(i=this.host.getScreenOf(g))==null||i.markDirty()}applyResolved(g,A){var t;for(const C of he){const i=A[C];i===void 0?this.host.layout.setStyle(g,C,null):C==="opacity"?this.host.layout.setStyle(g,C,i):C==="transform"?this.host.layout.setStyle(g,C,`matrix(${i.join(",")})`):this.host.layout.setStyle(g,C,Xg(i))}(t=this.host.getScreenOf(g))==null||t.markDirty()}startTween(g,A,t,C=225,i=0){var G;const E=[];for(const F of he){const c=UE(F,A[F],t[F]);!c||SE(c.from,c.to)||E.push({key:F,from:c.from,to:c.to})}if(E.length===0)return;const r=new Set(E.map(F=>F.key));for(const F of this.tweens)F.nodeId===g&&(F.props=F.props.filter(c=>!r.has(c.key)));this.tweens=this.tweens.filter(F=>F.props.length>0);const w={nodeId:g,props:E,elapsed:0,duration:Math.max(1,C),delay:Math.max(0,i)};this.tweens.push(w);const h=this.host.getNode(g);h&&this.applyTweenFrame(w,h),(G=this.host.getScreenOf(g))==null||G.markDirty()}applyTweenFrame(g,A){const t=g.elapsed<=g.delay?0:Math.min(1,(g.elapsed-g.delay)/g.duration),C=FE(t);for(const i of g.props)A.style[i.key]=kE(i.key,i.from,i.to,C)}}const mE=60270,ht=60271,KE=.32,de=new Set(["fontSize","fontFamily","fontWeight","fontStyle","lineHeight","letterSpacing","lineClamp","textOverflow"]);class LE{constructor(g,A){X(this,"nodesById",new Map);X(this,"screensById",new Map);X(this,"currentScreen",null);X(this,"widgets",[]);X(this,"nextScreenId",0);X(this,"nextWidgetId",1);X(this,"pressed",new Set);X(this,"focusedInput",null);X(this,"onKeyboard",()=>{});X(this,"router",new GE(g=>this.activateScreen(g),g=>this.freeScreen(g)));X(this,"onRouterChange",null);X(this,"tween");X(this,"vlist");X(this,"width",0);X(this,"height",0);X(this,"safeArea",null);X(this,"safeAreaBars",[]);X(this,"onResize",()=>{});X(this,"resolveSrc",g=>this.host.resolveSrc(g));X(this,"isPressed",g=>this.pressed.has(g.id));X(this,"isFocused",g=>this.focusedInput===g);this.layout=g,this.host=A,g.setStyleSink(this),g.setMeasureCallback((t,C,i,E)=>this.measure(C,i,E)),this.tween=new NE({getNode:t=>this.get(t),getScreenOf:t=>this.getScreenOf(t),layout:this.layout,resolveSrc:this.resolveSrc,isMeasureAffecting:t=>de.has(t)}),this.vlist=new uE({getNode:t=>this.get(t),getScreenOf:t=>this.getScreenOf(t),preloadNew:(t,C)=>this.preloadNew(t,C),scrollBy:(t,C)=>this.scrollBy(t,C),isAtScrollEnd:(t,C)=>this.isAtScrollEnd(t,C),viewport:()=>({width:this.width,height:this.height}),layoutHeight:()=>this.layoutHeight()})}register(g){this.nodesById.set(g.id,g)}unregister(g){var A;this.nodesById.delete(g),this.pressed.delete(g),this.vlist.remove(g),((A=this.focusedInput)==null?void 0:A.id)===g&&(this.focusedInput=null,this.onKeyboard(null))}get(g){return this.nodesById.get(g)}onNodeAdded(g){g.type==="vlist"&&this.vlist.initVlist(g)}getStyle(g,A){var t;return(t=this.nodesById.get(A))==null?void 0:t.style}measure(g,A,t){const C=this.nodesById.get(g);return C?C.type==="text"?aE(C,this.host,A):C.type==="image"?lE(C,this.host,A,t):C.editable?cE(C,this.host,A):{width:0,height:0}:{width:0,height:0}}resize(g,A){g<=0||A<=0||(this.width=g,this.height=A,this.applySafePaddings(),this.layout.setConditionValue(g,A),this.relayout(),this.onResize(g,A),this.focusedInput&&this.emitKeyboard())}layoutHeight(){return this.focusedInput?this.height-this.keyboardRect().height:this.height}relayout(){var A;if(this.width<=0||this.height<=0)return;const g=this.layoutHeight();(A=this.currentScreen)==null||A.applyLayout(this.width,g);for(const t of this.widgets)t.applyLayout(this.width,g)}safeInsets(){return this.safeArea?this.safeArea:this.width>this.height?[0,8,0,20]:[20,0,8,0]}applySafePaddings(){var i;const[g,A,t,C]=this.safeInsets();this.layout.setSafeAreaBars(this.safeAreaBars),this.layout.setSafePaddings(g,A,t,C,(i=this.currentScreen)==null?void 0:i.root.id);for(const E of this.widgets)this.layout.setSafePaddings(g,A,t,C,E.root.id)}setSafeArea(g,A=[]){var t,C;if(this.safeArea=g,this.safeAreaBars=A,!(this.width<=0||this.height<=0)){this.applySafePaddings(),(t=this.currentScreen)==null||t.markDirty(),(C=this.currentScreen)==null||C.applyLayout(this.width,this.layoutHeight());for(const i of this.widgets)i.markDirty(),i.applyLayout(this.width,this.layoutHeight())}}setTheme(g){var A;if(this.layout.setTheme(g)&&!(this.width<=0||this.height<=0)){"fontFamily"in g&&this.invalidateTextMetrics(),(A=this.currentScreen)==null||A.markDirty();for(const t of this.widgets)t.markDirty();this.relayout()}}registerResizeEvent(g){this.onResize=g}invalidateTextMetrics(){for(const g of this.nodesById.values())g.wrapCache=void 0,g.measured&&g.type!=="image"&&this.layout.markDirty(g.id)}registerFont(g,A,t={},C,i){this.host.loadFont(g,A,t).then(()=>{var E;this.invalidateTextMetrics(),(E=this.currentScreen)==null||E.markDirty();for(const r of this.widgets)r.markDirty();C==null||C()}).catch(()=>i==null?void 0:i())}openScreen(g){this.router.show?this.routerHide():this.currentScreen&&this.closeScreen();const A=new le(this.nextScreenId++,g,this.layout,this,!1,this.resolveSrc);this.screensById.set(A.screenId,A),A.mount(),this.currentScreen=A,A.applyLayout(this.width,this.layoutHeight()),this.preloadImages(A),this.vlist.settle(A);for(const t of g.ol??[])t();return A}closeScreen(){const g=this.currentScreen;if(g){for(const A of g.jsNode.cl??[])A();g.destroy(),this.screensById.delete(g.screenId),this.currentScreen=null}}newScreen(g){const A=new le(this.nextScreenId++,g,this.layout,this,!1,this.resolveSrc);return this.screensById.set(A.screenId,A),A.mount(),A}activateScreen(g){var t;const A=this.currentScreen;if(A){for(const C of A.jsNode.cl??[])C();A.deactivate()}this.currentScreen=g,g.applyLayout(this.width,this.layoutHeight()),this.preloadImages(g),this.vlist.settle(g),(t=this.onRouterChange)==null||t.call(this,g.jsNode);for(const C of g.jsNode.ol??[])C();this.focusedInput&&this.blurInput()}freeScreen(g){this.currentScreen===g&&(this.currentScreen=null),g.destroy(),this.screensById.delete(g.screenId)}routerOpen(g,A){if(this.currentScreen){if(!this.router.stack.includes(this.currentScreen)){for(const t of this.currentScreen.jsNode.cl??[])t();this.currentScreen.destroy(),this.screensById.delete(this.currentScreen.screenId)}this.currentScreen=null}for(const t of this.router.stack)t.destroy(),this.screensById.delete(t.screenId);this.router.stack=[],this.onRouterChange=A??null,this.router.init(this.newScreen(g))}routerPush(g){this.router.push(this.newScreen(g))}routerReplace(g){this.router.replace(this.newScreen(g))}routerPop(g){this.router.pop(g)}routerHide(){if(this.router.hide(),this.currentScreen&&this.router.stack.includes(this.currentScreen)){for(const g of this.currentScreen.jsNode.cl??[])g();this.currentScreen.deactivate(),this.currentScreen=null}}routerRestore(){this.router.restore()}showWidget(g){if(this.widgets.some(C=>C.jsNode===g))return;const A=-this.nextWidgetId++,t=new le(A,g,this.layout,this,!0,this.resolveSrc);this.screensById.set(A,t),t.mount(),t.applyLayout(this.width,this.layoutHeight()),this.widgets.push(t),this.preloadImages(t),this.vlist.settle(t);for(const C of g.ol??[])C()}hideWidget(g){if(!g._id)return;const A=this.layout.getScreenId(g._id);if(A>=0)return;const t=this.screensById.get(A);if(t){for(const C of t.jsNode.cl??[])C();t.destroy(),this.screensById.delete(A),this.widgets=this.widgets.filter(C=>C!==t)}}getScreenOf(g){return this.screensById.get(this.layout.getScreenId(g))}preloadSubtree(g,A){const t=C=>{if(C.type==="image"){const E=this.resolveSrc(C.imageSrcRaw);E&&!this.host.getImage(E)&&this.host.loadImage(E).then(()=>{this.layout.markDirty(C.id),A.markDirty()}).catch(()=>{})}const i=C.style.backgroundImage;i&&!this.host.getImage(i)&&this.host.loadImage(i).then(()=>A.markDirty()).catch(()=>{});for(const E of C.children)t(E)};t(g)}preloadImages(g){this.preloadSubtree(g.root,g)}preloadNew(g,A){if(!A)return;const t=g!=null&&g._id?this.nodesById.get(g._id):void 0;t&&this.preloadSubtree(t,A)}insertNode(g,A,t){const C=this.getScreenOf(A);C==null||C.insertNode(A,g,t),this.preloadNew(t,C)}removeNode(g,A){var t;(t=this.getScreenOf(g))==null||t.removeNode(g,A)}setContent(g,A,t){const C=this.getScreenOf(g);C==null||C.setContent(g,A,t);for(const i of t)i&&this.preloadNew(i,C)}updateStyle(g,A,t){var i;eI(this.layout,g,A,t,void 0,this.resolveSrc);const C=this.nodesById.get(g);(C!=null&&C.measured||de.has(A))&&this.layout.markDirty(g),(i=this.getScreenOf(g))==null||i.markDirty()}mergeStyle(g,A){var i;let t=!1;for(const E of Object.keys(A))eI(this.layout,g,E,A[E],void 0,this.resolveSrc),de.has(E)&&(t=!0);const C=this.nodesById.get(g);(C!=null&&C.measured||t)&&this.layout.markDirty(g),(i=this.getScreenOf(g))==null||i.markDirty()}updateNode(g,A,t){var i,E;const C=this.nodesById.get(g);if(C){if(A==="value")C.value=typeof t=="string"?t:String(t??""),this.layout.markDirty(g),(i=this.getScreenOf(g))==null||i.markDirty(),this.focusedInput===C&&this.emitKeyboard();else if(A==="text")this.layout.markDirty(g),(E=this.getScreenOf(g))==null||E.markDirty();else if(A==="src"){const r=t??C.imageSrcRaw,w=this.resolveSrc(r),h=this.getScreenOf(g);w&&!this.host.getImage(w)&&this.host.loadImage(w).then(()=>{this.layout.markDirty(g),h==null||h.markDirty()}).catch(()=>{});const G=xt(r);G!=null&&eI(this.layout,g,"tintColor",G,void 0,this.resolveSrc),this.layout.markDirty(g),h==null||h.markDirty()}}}setSourceRect(g,A,t,C,i){var r;const E=this.nodesById.get(g);E&&(E.sourceRect=[A,t,C,i],this.layout.markDirty(g),(r=this.getScreenOf(g))==null||r.markDirty())}getTextValue(g){var A;return((A=this.nodesById.get(g))==null?void 0:A.value)??""}focusInput(g){var t,C,i,E,r;const A=this.nodesById.get(g);if(!(!A||!A.editable||this.focusedInput===A)){this.focusedInput&&this.unfocus(),this.focusedInput=A,this.toggleLayer(g,ht,!0,(C=(t=A.jsNode)==null?void 0:t._style)==null?void 0:C.onFocused),this.toggleLayer(g,this.layout.getLayer(g,"$focused"),!0,(E=(i=A.jsNode)==null?void 0:i._style)==null?void 0:E.$focused);for(const w of((r=A.jsNode)==null?void 0:r.fl)??[])w();this.relayout(),this.emitKeyboard()}}dismissKeyboardOnTap(){var g,A,t;((t=(A=(g=this.focusedInput)==null?void 0:g.jsNode)==null?void 0:A._style)==null?void 0:t.keyboardDismiss)!==!1&&this.blurInput()}blurInput(){this.focusedInput&&(this.unfocus(),this.relayout(),this.emitKeyboard())}submitInput(){var t,C,i;const g=this.focusedInput;if(!g)return!1;const A=g.value;for(const E of((t=g.jsNode)==null?void 0:t.sl)??[])E(A);return this.focusedInput===g&&((i=(C=g.jsNode)==null?void 0:C._style)==null?void 0:i.enterKey)!=="next"&&this.blurInput(),!0}unfocus(){var A,t,C,i,E;const g=this.focusedInput;if(g){this.toggleLayer(g.id,ht,!1,(t=(A=g.jsNode)==null?void 0:A._style)==null?void 0:t.onFocused),this.toggleLayer(g.id,this.layout.getLayer(g.id,"$focused"),!1,(i=(C=g.jsNode)==null?void 0:C._style)==null?void 0:i.$focused);for(const r of((E=g.jsNode)==null?void 0:E.bl)??[])r();this.focusedInput=null}}setInputValue(g,A){var C,i;const t=this.nodesById.get(g);if(t){t.value=A;for(const E of((C=t.jsNode)==null?void 0:C.cl)??[])E(A);this.layout.markDirty(g),(i=this.getScreenOf(g))==null||i.markDirty()}}keyboard(){const g=this.focusedInput;return g?{rect:this.keyboardRect(),input:{nodeId:g.id,rect:this.findRect(g.id)??{x:0,y:0,width:0,height:0},value:g.value,type:g.style.inputType??"text"}}:null}uiTransform(){return null}registerKeyboardEvent(g){this.onKeyboard=g}keyboardRect(){const g=Math.round(this.height*KE);return{x:0,y:this.height-g,width:this.width,height:g}}emitKeyboard(){this.onKeyboard(this.keyboard())}findRect(g){const A=C=>{if(!C)return null;if(C.id===g)return C.rect;for(const i of C.children){const E=A(i);if(E)return E}return null},t=A(this.renderTree());if(t)return t;for(const C of this.widgetTrees()){const i=A(C);if(i)return i}return null}isButtonPressed(g){return this.pressed.has(g)}getBoundingClientRect(g){const A=this.findRect(g);return A?[A.x,A.y,A.width,A.height]:null}renderTree(){return this.currentScreen?this.currentScreen.renderTree(this.host,this.isPressed,this.isFocused):null}needsPaint(){var g;if(this.tween.hasActive()||(g=this.currentScreen)!=null&&g.isDirty())return!0;for(const A of this.widgets)if(A.isDirty())return!0;return!1}frame(){const g=[],A=this.renderTree();A&&g.push({tree:A});for(const t of this.widgets){const C=t.renderTree(this.host,this.isPressed,this.isFocused),i=C.style.overlayColor;g.push({tree:C,widget:!0,backdrop:i!==void 0?{color:i,jsNode:t.jsNode}:void 0})}return g}widgetTrees(){return this.widgets.map(g=>g.renderTree(this.host,this.isPressed,this.isFocused))}findAllByName(g){const A=[],t=i=>{i.name===g&&A.push(i);for(const E of i.children)t(E)},C=this.renderTree();C&&t(C);for(const i of this.widgetTrees())t(i);return A}findByName(g){return this.findAllByName(g)[0]??null}animateTo(g,A){this.tween.animateTo(g,A)}animateFrom(g,A){this.tween.animateFrom(g,A)}tick(g){this.tween.tick(g)}hasActiveAnimations(){return this.tween.hasActive()}vlistMount(g,A,t){this.vlist.vlistMount(g,A,t)}vlistSetKeys(g,A,t){this.vlist.vlistSetKeys(g,A,t)}vlistInsertKeys(g,A,t,C){this.vlist.vlistInsertKeys(g,A,t,C)}vlistRemoveKeys(g,A){this.vlist.vlistRemoveKeys(g,A)}vlistInvalidate(g,A){this.vlist.vlistInvalidate(g,A)}command(g,A,...t){if((g==null?void 0:g.type)==="pager"&&g._id){const C=this.getScreenOf(g._id);C!=null&&C.pagerReconcile(g)&&(this.preloadImages(C),this.vlist.settle(C));return}this.vlist.command(g,A,...t)}scrollViewport(g){var t,C,i;const A=g===((t=this.currentScreen)==null?void 0:t.root);return g.scrollAxis==="x"?A?this.width:((C=g.layoutRect)==null?void 0:C.width)??0:A?this.height:((i=g.layoutRect)==null?void 0:i.height)??0}scrollMax(g){const A=g.scrollAxis==="x"?this.layout.getContentWidth(g.id):this.layout.getContentHeight(g.id);return Math.max(0,A-this.scrollViewport(g))}isAtScrollEnd(g,A=1){return g.scrollOffset>=this.scrollMax(g)-A}scrollBy(g,A){var h,G,F;const t=this.nodesById.get(g);if(!t||!t.scrollable)return!1;const C=this.scrollMax(t),i=t.scrollOffset+A,E=Math.min(C,Math.max(0,i)),r=i<0?i:i>C?i-C:0;if(r!==0){const c=(h=t.jsNode)==null?void 0:h.osl;if(Array.isArray(c)&&c.length)for(const U of c)U(r)}if(E===t.scrollOffset)return!1;t.scrollOffset=E,(G=this.getScreenOf(g))==null||G.markDirty();const w=(F=t.jsNode)==null?void 0:F.sl;if(Array.isArray(w))for(const c of w)c(E);return t.type==="vlist"&&this.vlist.checkEdges(t,E,C),!0}toggleLayer(g,A,t,C){var G,F;const i=this.nodesById.get(g);if(!i)return;const E=typeof(C==null?void 0:C.duration)=="number"?C.duration:0,r=()=>{i.measured&&this.layout.markDirty(g)};if(E<=0){t?this.layout.enableNodeLayer(g,A):this.layout.disableNodeLayer(g,A),r(),(G=this.getScreenOf(g))==null||G.markDirty();return}const w=this.tween.snapshot(i);t?this.layout.enableNodeLayer(g,A):this.layout.disableNodeLayer(g,A);const h=this.tween.snapshot(i);r(),this.tween.startTween(g,w,h,E,typeof(C==null?void 0:C.delay)=="number"?C.delay:0),(F=this.getScreenOf(g))==null||F.markDirty()}setPressed(g,A){var C,i,E;A?this.pressed.add(g):this.pressed.delete(g);const t=(C=this.nodesById.get(g))==null?void 0:C.jsNode;this.toggleLayer(g,mE,A,(i=t==null?void 0:t._style)==null?void 0:i.onPressed),this.toggleLayer(g,this.layout.getLayer(g,"$pressed"),A,(E=t==null?void 0:t._style)==null?void 0:E.$pressed)}setClass(g,A,t){var E,r;const C=this.nodesById.get(g);if(!C)return;const i=this.layout.getLayer(g,"$"+A);this.toggleLayer(g,i,t,(r=(E=C.jsNode)==null?void 0:E._style)==null?void 0:r["$"+A])}hitTestNode(g){return this.nodesById.get(g)}get screen(){return this.currentScreen}get viewport(){return{width:this.width,height:this.height}}}const bE=["farthest-corner","closest-side","closest-corner","farthest-side"],ME=52;function vE(e,g,A,t){const C=[];for(let i=0;i<t;i++)C.push(JE(e,g,A+i*ME));return C}function JE(e,g,A){const t=A>>2,C=e[t],i=g[t+1],E=g[t+2],r=g[t+4],w=[];for(let h=0;h<E;h++){const G=r+h*8>>2;w.push({color:g[G]>>>0,position:e[G+1]})}if(i===1){const h=g[t+6],G={type:"radial",shape:g[t+5]===1?"circle":"ellipse",cx:e[t+7],cy:e[t+8],stops:w};return h===4?{...G,extent:"explicit",rx:e[t+9],ry:e[t+10],rxUnit:g[t+11]===1?"fraction":"px",ryUnit:g[t+12]===1?"fraction":"px"}:{...G,extent:bE[h]??"farthest-corner"}}return{type:"linear",angle:C,stops:w}}const dt={display:{channel:"string",hostReset:!1,nodes:"all"},overflow:{channel:"string",hostReset:!1,nodes:"all"},scrollDirection:{channel:"float",hostReset:!1,nodes:["scrollable"]},borderWidth:{channel:"float",hostReset:!1,nodes:"all"},borderTopWidth:{channel:"float",hostReset:!1,nodes:"all"},borderRightWidth:{channel:"float",hostReset:!1,nodes:"all"},borderBottomWidth:{channel:"float",hostReset:!1,nodes:"all"},borderLeftWidth:{channel:"float",hostReset:!1,nodes:"all"},borderHorizontalWidth:{channel:"float",hostReset:!1,nodes:"all"},borderVerticalWidth:{channel:"float",hostReset:!1,nodes:"all"},borderStartWidth:{channel:"float",hostReset:!1,nodes:"all"},borderEndWidth:{channel:"float",hostReset:!1,nodes:"all"},color:{channel:"uint",hostReset:!0,nodes:"all"},backgroundColor:{channel:"uint",hostReset:!1,nodes:"all"},borderColor:{channel:"uint",hostReset:!1,nodes:"all"},borderTopColor:{channel:"uint",hostReset:!1,nodes:"all"},borderRightColor:{channel:"uint",hostReset:!1,nodes:"all"},borderBottomColor:{channel:"uint",hostReset:!1,nodes:"all"},borderLeftColor:{channel:"uint",hostReset:!1,nodes:"all"},placeholderColor:{channel:"uint",hostReset:!0,nodes:["input"]},refreshControlColor:{channel:"uint",hostReset:!0,nodes:["scrollable"]},tintColor:{channel:"uint",hostReset:!0,nodes:["image"]},rippleColor:{channel:"uint",hostReset:!1,nodes:["button"]},overlayColor:{channel:"uint",hostReset:!0,nodes:["widget"]},backgroundImage:{channel:"string",hostReset:!1,nodes:"all"},backgroundSize:{channel:"string",hostReset:!1,nodes:"all"},backgroundGradientStr:{channel:"string",hostReset:!1,nodes:"all"},borderRadius:{channel:"float",hostReset:!1,nodes:"all"},borderTopLeftRadius:{channel:"float",hostReset:!1,nodes:"all"},borderTopRightRadius:{channel:"float",hostReset:!1,nodes:"all"},borderBottomRightRadius:{channel:"float",hostReset:!1,nodes:"all"},borderBottomLeftRadius:{channel:"float",hostReset:!1,nodes:"all"},opacity:{channel:"float",hostReset:!1,nodes:"all"},pointerEvents:{channel:"string",hostReset:!1,nodes:"all"},fontSize:{channel:"float",hostReset:!1,nodes:["text","input"]},fontWeight:{channel:"float",hostReset:!1,nodes:["text","input"]},fontStyle:{channel:"float",hostReset:!1,nodes:["text","input"]},fontFamily:{channel:"string",hostReset:!0,nodes:["text","input"]},lineHeight:{channel:"float",hostReset:!1,nodes:["text","input"]},letterSpacing:{channel:"float",hostReset:!1,nodes:["text","input"]},textAlign:{channel:"string",hostReset:!1,nodes:["text","input"]},textDecoration:{channel:"string",hostReset:!1,nodes:["text"]},lineClamp:{channel:"float",hostReset:!1,nodes:["text"]},textOverflow:{channel:"string",hostReset:!1,nodes:["text"]},objectFit:{channel:"string",hostReset:!1,nodes:["image","video"]},placeholder:{channel:"string",hostReset:!1,nodes:["input"]},type:{channel:"string",hostReset:!1,nodes:["input"]},enterKey:{channel:"string",hostReset:!1,nodes:["input"]},autocapitalize:{channel:"string",hostReset:!1,nodes:["input"]},autocorrect:{channel:"float",hostReset:!1,nodes:["input"]},maxLength:{channel:"float",hostReset:!1,nodes:["input"]},keyboardShrink:{channel:"float",hostReset:!1,nodes:["input"]},keyboardDismiss:{channel:"float",hostReset:!1,nodes:["input"]},showScrollbar:{channel:"float",hostReset:!1,nodes:["scrollable"]},overscrollMode:{channel:"string",hostReset:!1,nodes:["scrollable"]},keyboardDismissMode:{channel:"string",hostReset:!1,nodes:["scrollable","vlist"]},snap:{channel:"string",hostReset:!1,nodes:["scrollable"]},sheetDetents:{channel:"string",hostReset:!1,nodes:["widget"]},sheetDetent:{channel:"float",hostReset:!1,nodes:["widget"]},sheetDismissible:{channel:"float",hostReset:!1,nodes:["widget"]}},Vt=e=>e.toLowerCase();function NI(e,g){var A;return e.border??(e.border={}),(A=e.border)[g]??(A[g]={width:0,color:0})}function HE(e){return e.borderRadius??(e.borderRadius={tl:0,tr:0,br:0,bl:0})}const aI=e=>({set(g,A){if(e==="")for(const t of["top","right","bottom","left"])NI(g,t).width=A;else NI(g,Vt(e)).width=A}}),cI=e=>({set(g,A){if(e==="")for(const t of["top","right","bottom","left"])NI(g,t).color=A;else NI(g,Vt(e)).color=A}}),YE={TopLeft:"tl",TopRight:"tr",BottomRight:"br",BottomLeft:"bl"},FI=e=>({set(g,A){HE(g)[YE[e]]=A}}),xE={display:{set:(e,g)=>e.display=g},overflow:{set:(e,g)=>e.overflow=g},scrollDirection:{set:(e,g)=>e.scrollAxis=g===2?"x":"y"},showScrollbar:"unsupported",overscrollMode:"unsupported",keyboardDismissMode:"unsupported",snap:"unsupported",refreshControlColor:"unsupported",borderWidth:aI(""),borderTopWidth:aI("Top"),borderRightWidth:aI("Right"),borderBottomWidth:aI("Bottom"),borderLeftWidth:aI("Left"),borderHorizontalWidth:"unsupported",borderVerticalWidth:"unsupported",borderStartWidth:"unsupported",borderEndWidth:"unsupported",borderColor:cI(""),borderTopColor:cI("Top"),borderRightColor:cI("Right"),borderBottomColor:cI("Bottom"),borderLeftColor:cI("Left"),borderRadius:{set:(e,g)=>e.borderRadius={tl:g,tr:g,br:g,bl:g}},borderTopLeftRadius:FI("TopLeft"),borderTopRightRadius:FI("TopRight"),borderBottomRightRadius:FI("BottomRight"),borderBottomLeftRadius:FI("BottomLeft"),color:{set:(e,g)=>e.color=g>>>0,reset:e=>e.color=void 0},fontFamily:{set:(e,g)=>e.fontFamily=g,reset:e=>e.fontFamily=void 0},fontSize:{set:(e,g)=>e.fontSize=g},fontWeight:{set:(e,g)=>e.fontWeight=g},fontStyle:{set:(e,g)=>e.fontStyle=g===2?"italic":"normal"},lineHeight:{set:(e,g)=>e.lineHeight=g},letterSpacing:{set:(e,g)=>e.letterSpacing=g},textAlign:{set:(e,g)=>e.textAlign=TE(g)},textDecoration:{set:(e,g)=>e.textDecoration=g},lineClamp:{set:(e,g)=>e.lineClamp=g},textOverflow:{set:(e,g)=>e.textOverflow=g},backgroundColor:{set:(e,g)=>e.backgroundColor=g>>>0},backgroundImage:{set:(e,g)=>e.backgroundImage=g||void 0},backgroundSize:{set:(e,g)=>e.backgroundSize=g},backgroundGradientStr:"unsupported",rippleColor:"unsupported",opacity:{set:(e,g)=>e.opacity=g},pointerEvents:"unsupported",objectFit:{set:(e,g)=>e.objectFit=g},tintColor:{set:(e,g)=>e.tintColor=g>>>0,reset:e=>e.tintColor=void 0},placeholder:{set:(e,g)=>e.placeholder=g},placeholderColor:{set:(e,g)=>e.placeholderColor=g>>>0,reset:e=>e.placeholderColor=void 0},type:{set:(e,g)=>e.inputType=g},enterKey:"unsupported",autocapitalize:"unsupported",autocorrect:"unsupported",maxLength:"unsupported",keyboardShrink:"unsupported",keyboardDismiss:"unsupported",overlayColor:{set:(e,g)=>e.overlayColor=g>>>0,reset:e=>e.overlayColor=void 0},sheetDetents:"unsupported",sheetDetent:"unsupported",sheetDismissible:"unsupported"};function qE(e,g){const A=(r,w)=>{const h=r.length+1,G=e._malloc(h);e.stringToUTF8(r,G,h),w(G),e._free(G)},t=[];for(const r of Object.keys(dt)){const w=xE[r];if(w==="unsupported"){t.push(r);continue}const{channel:h}=dt[r];A(r,G=>{if(h==="string"){const F=e.addFunction((c,U,y)=>{const l=g.getStyle(c,U);l&&w.set(l,e.UTF8ToString(y))},"viii");e._addStringHandler(G,F)}else if(h==="uint"){const F=e.addFunction((c,U,y)=>{const l=g.getStyle(c,U);l&&w.set(l,y>>>0)},"viii");e._addUIntHandler(G,F)}else{const F=e.addFunction((c,U,y)=>{const l=g.getStyle(c,U);l&&w.set(l,y)},"viif");e._addFloatHandler(G,F)}if(w.reset){const F=e.addFunction((c,U)=>{const y=g.getStyle(c,U);y&&w.reset(y)},"vii");e._addResetHandler(G,F)}})}const C=e.addFunction((r,w,h,G)=>{const F=g.getStyle(r,w);F&&(F.backgroundGradients=h===0||G===0?void 0:vE(e.HEAPF32,e.HEAPU32,h,G))},"viiii");e._setGradientsHandler(C),A("backgroundGradient",r=>{const w=e.addFunction((h,G)=>{const F=g.getStyle(h,G);F&&(F.backgroundGradients=void 0)},"vii");e._addResetHandler(r,w)});const i=e.addFunction((r,w,h)=>{const G=g.getStyle(r,w);if(!G)return;const F=h>>2,c=e.HEAPF32,U=c[F],y=c[F+1],l=c[F+3],D=c[F+4],R=c[F+6],L=c[F+7],O=U===1&&y===0&&l===0&&D===1&&R===0&&L===0;G.transform=O?void 0:[U,y,l,D,R,L]},"viii");e._setMatrixHandler(i);const E=e.addFunction((r,w,h,G,F,c)=>{const U=g.getStyle(r,w);if(!U)return;const y=F&&c&&h===50&&G===50;U.transformOrigin=y?void 0:{x:h,y:G,xPercent:!!F,yPercent:!!c}},"viiffii");return e._setTransformOriginHandler(E),{unsupported:t}}function TE(e){return e==="center"?"center":e==="end"||e==="right"?"end":"start"}const _E=256;class HI{constructor(g){X(this,"module");X(this,"layoutPtr");X(this,"paddingPtr");X(this,"keyCache",new Map);X(this,"packView",new DataView(new ArrayBuffer(8)));X(this,"measureCb",null);this.module=g,this.layoutPtr=g._malloc(16),this.paddingPtr=g._malloc(16)}static async create(){const{loadCreatorUiNode:g}=await II(async()=>{const{loadCreatorUiNode:A}=await import("./assets/loadCreatorUiNode-UAdhjRTd.js");return{loadCreatorUiNode:A}},[],import.meta.url);return new HI(await g())}internKey(g){let A=this.keyCache.get(g);if(A===void 0){const t=g.length+1;A=this.module._malloc(t),this.module.stringToUTF8(g,A,t),this.keyCache.set(g,A)}return A}setTheme(g){for(const A of Object.keys(g)){const t=g[A],C=t==null?null:typeof t=="number"?`${t}px`:t,i=this.internKey(A);let E=0;if(C!==null){const r=this.module.lengthBytesUTF8(C)+1;E=this.module._malloc(r),this.module.stringToUTF8(C,E,r)}this.module._setThemeValue(i,E),E&&this.module._free(E)}return this.module._applyTheme()!==0}setStyleSink(g){qE(this.module,g)}setMeasureCallback(g){this.measureCb=g;const A=this.packView,t=(i,E,r,w,h,G)=>{var c;const F=((c=this.measureCb)==null?void 0:c.call(this,i,E,r,h))??{width:0,height:0};return A.setFloat32(4,F.width,!0),A.setFloat32(0,F.height,!0),A.getBigUint64(0,!0)},C=this.module.addFunction(t,"jiififi");this.module._setMeasureFunc(C)}createRoot(g){return this.module._createNodeRoot(g)}createChild(g,A,t){return this.module._createNode(g,A,t?1:0)}removeChild(g,A){this.module._removeNode(g,A)}freeTree(g,A){A?this.module._freeWidget(g):this.module._freeNode(g)}setStyle(g,A,t,C=_E){const i=this.internKey(A);if(t===null)this.module._resetPropExt(C,g,i);else if(typeof t=="number")this.module._setFloatExt(C,g,i,t);else if(typeof t=="boolean")this.module._setFloatExt(C,g,i,t?1:0);else{const E=this.module.lengthBytesUTF8(t)+1,r=this.module._malloc(E);this.module.stringToUTF8(t,r,E),this.module._setStringExt(C,g,i,r),this.module._free(r)}}markDirty(g){this.module._markNodeDirty(g)}getLayer(g,A){return this.module._getLayer(g,this.internKey(A))}enableNodeLayer(g,A){this.module._enableNodeLayer(g,A)}disableNodeLayer(g,A){this.module._disableNodeLayer(g,A)}calculate(g,A,t,C){C?this.module._calculateWidget(g,A,t):this.module._calculate(g,A,t)}getLayout(g){if(!this.module._getLayoutPointer(g,this.layoutPtr))return null;const A=this.layoutPtr>>2,t=this.module.HEAPF32;return{x:t[A],y:t[A+1],width:t[A+2],height:t[A+3]}}getPadding(g){this.module._getPaddingPointer(g,this.paddingPtr);const A=this.paddingPtr>>2,t=this.module.HEAPF32;return[t[A],t[A+1],t[A+2],t[A+3]]}getScreenId(g){return this.module._getScreenId(g)}getContentHeight(g){return this.module._getContentHeight(g)}getContentWidth(g){return this.module._getContentWidth(g)}setConditionValue(g,A){this.module._setConditionValue(g,A)}setSafePaddings(g,A,t,C,i){i!==void 0?this.module._setSafePaddings(g,A,t,C,i):this.module._setSafePaddings(g,A,t,C)}setSafeAreaBars(g){const A={top:1,right:2,bottom:4,left:8};this.module._setSafeAreaBars(g.reduce((t,C)=>t|A[C],0))}}function mI(e,g){if(!g)return;const A=QE(e);if(A===void 0)return;const t=g.getSurface(A);if(t)return{src:e,naturalWidth:t.width,naturalHeight:t.height,handle:t.canvas}}class WE{constructor(g={}){X(this,"factor");X(this,"images",new Map);X(this,"canvasSurfaces");X(this,"resolver",qt());this.factor=g.charWidthFactor??.5,this.canvasSurfaces=g.canvasSurfaces;for(const[A,t]of Object.entries(g.images??{}))this.images.set(A,{src:A,naturalWidth:t.width,naturalHeight:t.height})}setImageSize(g,A,t){this.images.set(g,{src:g,naturalWidth:A,naturalHeight:t})}measureText(g,A){return g.length===0?0:g.length*(A.size*this.factor+A.letterSpacing)}fontMetrics(g){return{ascent:g.size*.8,descent:g.size*.2}}getImage(g){return mI(g,this.canvasSurfaces)??this.images.get(g)}loadImage(g){return Promise.resolve(mI(g,this.canvasSurfaces)??this.images.get(g)??{src:g,naturalWidth:0,naturalHeight:0})}loadFont(){return Promise.resolve()}resolveSrc(g){return this.resolver(g)}}function ZE(e,g,A){const t=e.rect;return g>=t.x&&g<t.x+t.width&&A>=t.y&&A<t.y+t.height}function SI(e,g,A,t){let C=null;const i=E=>{const r=ZE(E,g,A);if(r&&t(E)&&(C=E),!(E.clip&&!r))for(const w of E.children)i(w)};return i(e),C}const VE=4,yt=e=>g=>{var A;return((A=e.get(g.id))==null?void 0:A.interactive)??!1},OE=e=>{if(!e.scroll)return!1;const g=e.scroll.axis==="x"?e.rect.width:e.rect.height;return e.scroll.content>g+.5};function PE(e,g,A){return e>=A.x&&e<A.x+A.width&&g>=A.y&&g<A.y+A.height}class XE{constructor(g){X(this,"tracks",new Map);X(this,"onTouchStart",null);X(this,"onTouchEnd",null);X(this,"creator",null);X(this,"scenePointer",null);this.renderer=g}setScenePointer(g){this.scenePointer=g}topInteractive(g,A){const t=this.renderer.frame(),C=yt(this.renderer);for(let i=t.length-1;i>=0;i--){const E=SI(t[i].tree,g,A,C);if(E)return E.id;if(t[i].backdrop)return null}return null}registerTouchStartEvent(g){this.onTouchStart=g}registerTouchEndEvent(g){this.onTouchEnd=g}setCreator(g){this.creator=g}raycast(g,A){var t,C;return((C=(t=this.creator)==null?void 0:t._raycastView)==null?void 0:C.call(t,g,A))??0}toUi(g,A){const t=this.renderer.uiTransform();return t?[(g-t.tx)/t.scale,(A-t.ty)/t.scale]:[g,A]}pointerDown(g,A,t){var G,F,c;const[C,i]=this.toUi(A,t),E=this.renderer.frame(),r=yt(this.renderer),w=U=>{var y;return((y=this.renderer.get(U.id))==null?void 0:y.editable)??!1};for(let U=E.length-1;U>=0;U--){const y=SI(E[U].tree,C,i,w);if(y)return this.renderer.focusInput(y.id),this.start(g,C,i,{handler:{},node:null,scrollId:null,backdrop:null,dismiss:!1});if(E[U].backdrop)break}for(let U=E.length-1;U>=0;U--){const y=E[U],l=SI(y.tree,C,i,r),D=SI(y.tree,C,i,OE);if(l){const R=this.renderer.get(l.id).jsNode;this.renderer.setPressed(l.id,!0);const L=((G=R._emitTouchStart)==null?void 0:G.call(R,g,C,i))??{},O=R.type!=="button";return this.start(g,C,i,{handler:L,node:R,scrollId:(D==null?void 0:D.id)??null,backdrop:null,dismiss:O})}if(D)return this.start(g,C,i,{handler:{},node:null,scrollId:D.id,backdrop:null,dismiss:!0});if(y.backdrop){const R=!PE(C,i,y.tree.rect);return this.start(g,C,i,{handler:{},node:null,scrollId:null,backdrop:R?y.backdrop.jsNode:null,dismiss:!0})}}const h=((F=this.onTouchStart)==null?void 0:F.call(this,g,C,i,this.raycast(C,i)))??{};this.start(g,C,i,{handler:h,node:null,scrollId:null,backdrop:null,dismiss:!0,scene:!0}),(c=this.scenePointer)==null||c.call(this,0,g,C,i)}start(g,A,t,C){this.tracks.set(g,{...C,lastX:A,lastY:t,acc:0,scrolling:!1})}pointerMove(g,A,t){var h,G,F,c;const C=this.tracks.get(g);if(!C)return;const[i,E]=this.toUi(A,t),r=i-C.lastX,w=E-C.lastY;if(C.lastX=i,C.lastY=E,C.acc+=Math.abs(r)+Math.abs(w),!C.scrolling&&C.scrollId!==null&&C.acc>VE&&(C.scrolling=!0,C.node&&this.renderer.setPressed(C.node._id,!1)),C.scrolling){const U=((h=this.renderer.get(C.scrollId))==null?void 0:h.scrollAxis)==="x";this.renderer.scrollBy(C.scrollId,U?-r:-w);return}(F=(G=C.handler).onMove)==null||F.call(G,{clientX:i,clientY:E,deltaX:r,deltaY:w}),C.scene&&((c=this.scenePointer)==null||c.call(this,1,g,i,E))}pointerUp(g,A,t){var h,G,F,c,U,y,l,D;const C=this.tracks.get(g);if(!C)return;const[i,E]=this.toUi(A,t);this.tracks.delete(g);const r=i-C.lastX,w=E-C.lastY;if((G=(h=C.handler).onEnd)==null||G.call(h,{clientX:i,clientY:E,deltaX:r,deltaY:w}),C.scrolling&&C.scrollId!==null){const R=(c=(F=this.renderer.get(C.scrollId))==null?void 0:F.jsNode)==null?void 0:c.srl;if(Array.isArray(R))for(const L of R)L()}if(C.dismiss&&!C.scrolling&&this.renderer.dismissKeyboardOnTap(),C.node)this.renderer.setPressed(C.node._id,!1),!C.scrolling&&this.topInteractive(i,E)===C.node._id&&((y=(U=C.node)._emitClick)==null||y.call(U,g,i,E));else if(C.backdrop){if(!C.scrolling)for(const R of C.backdrop.otl??[])R()}else C.scrolling||(l=this.onTouchEnd)==null||l.call(this,g,i,E,this.raycast(i,E));C.scene&&((D=this.scenePointer)==null||D.call(this,2,g,i,E))}}function Se(e,g){if(!e)return;const A=Math.min(g.width,g.height)/2;return{tl:Math.min(e.tl,A),tr:Math.min(e.tr,A),br:Math.min(e.br,A),bl:Math.min(e.bl,A)}}function Dt(e){return!!e&&(e.tl>0||e.tr>0||e.br>0||e.bl>0)}function jE(e,g,A,t){const C={x:0,y:0,width:e,height:g};if(t==="fill"||e===0||g===0)return{src:C,dst:A};if(t==="cover"){const w=Math.max(A.width/e,A.height/g),h=A.width/w,G=A.height/w;return{src:{x:(e-h)/2,y:(g-G)/2,width:h,height:G},dst:A}}const i=Math.min(A.width/e,A.height/g),E=e*i,r=g*i;return{src:C,dst:{x:A.x+(A.width-E)/2,y:A.y+(A.height-r)/2,width:E,height:r}}}function zE(e,g){const A=e*Math.PI/180,t=Math.sin(A),C=-Math.cos(A),i=g.x+g.width/2,E=g.y+g.height/2,r=(Math.abs(g.width*t)+Math.abs(g.height*C))/2;return{x0:i-t*r,y0:E-C*r,x1:i+t*r,y1:E+C*r}}function $E(e,g){const A=g.x+e.cx*g.width,t=g.y+e.cy*g.height;if(e.extent==="explicit"){const y=e.rxUnit==="fraction"?(e.rx??0)*g.width:e.rx??0,l=e.ryUnit==="fraction"?(e.ry??0)*g.height:e.ry??0;return{cx:A,cy:t,rx:y,ry:l}}const C=e.cx*g.width,i=(1-e.cx)*g.width,E=e.cy*g.height,r=(1-e.cy)*g.height,w=Math.min(C,i),h=Math.max(C,i),G=Math.min(E,r),F=Math.max(E,r);let c,U;if(e.shape==="circle"){let y;switch(e.extent){case"closest-side":y=Math.min(w,G);break;case"farthest-side":y=Math.max(h,F);break;case"closest-corner":y=Math.hypot(w,G);break;default:y=Math.hypot(h,F);break}c=U=y}else switch(e.extent){case"closest-side":c=w,U=G;break;case"farthest-side":c=h,U=F;break;case"closest-corner":c=w*Math.SQRT2,U=G*Math.SQRT2;break;default:c=h*Math.SQRT2,U=F*Math.SQRT2;break}return{cx:A,cy:t,rx:c,ry:U}}function Ar(e,g,A,t,C,i){g.beginFrame(t,C);const E=e.filter(r=>r.widget);for(const r of e)r.widget||Re(r.tree,g,A);for(const r of E)r.backdrop&&g.fillRoundRect({x:0,y:0,width:t,height:C},void 0,r.backdrop.color);for(const r of E)Re(r.tree,g,A);g.endFrame()}function Re(e,g,A){const{style:t,rect:C}=e;g.save();const i=t.opacity!==void 0&&t.opacity<1?t.opacity:void 0,E=i!==void 0&&e.children.length>0;if(E?g.beginGroup(i):i!==void 0&&g.setAlpha(i),t.transform){const[h,G,F,c,U,y]=t.transform,l=t.transformOrigin,D=C.x+(l?l.xPercent?C.width*l.x/100:l.x:C.width/2),R=C.y+(l?l.yPercent?C.height*l.y/100:l.y:C.height/2);g.translate(D,R),g.transform(h,G,F,c,U,y),g.translate(-D,-R)}const r=Se(t.borderRadius,C);if(Zt(t.backgroundColor)||g.fillRoundRect(C,r,t.backgroundColor),t.backgroundImage){const h=A.getImage(t.backgroundImage);h&&h.naturalWidth>0&&h.naturalHeight>0&&(g.save(),Dt(r)&&g.clipRoundRect(C,r),g.drawImage(h,null,C,{fit:gr(t.backgroundSize)}),g.restore())}if(t.backgroundGradients)for(let h=t.backgroundGradients.length-1;h>=0;h--){const G=t.backgroundGradients[h];G.stops.length>0&&g.fillGradient(C,r,G)}if(e.image&&e.image.naturalWidth>0&&e.image.naturalHeight>0){const h=e.sourceRect;g.save(),Dt(r)&&g.clipRoundRect(C,r),g.drawImage(e.image,h?{x:h[0],y:h[1],width:h[2],height:h[3]}:null,C,{fit:h?"fill":t.objectFit??"contain",tint:JI(e.image.src)?t.tintColor:void 0,radius:r}),g.restore()}e.type==="text"&&e.lines&&e.lines.length>0&&er(e,g,A),(e.type==="input"||e.type==="textarea")&&Br(e,g,A,r),e.type==="video"&&tr(e,g,A,r),e.clip&&g.clipRoundRect(C,r);for(const h of e.children)Re(h,g,A);const w=Ir(t.border);w&&g.strokeBorder(C,r,w),E&&g.endGroup(),g.restore()}function gr(e){return e==="contain"?"contain":"cover"}function Ir(e){if(!e)return null;const g={};let A=!1;for(const t of["top","right","bottom","left"]){const C=e[t];C&&C.width>0&&(C.color>>>0)%256!==0&&(g[t]=C,A=!0)}return A?g:null}const Ot=(e,g)=>{var t;const A=g??"Roboto";return((t=e.resolveFontFamily)==null?void 0:t.call(e,A))??A};function er(e,g,A){var D,R,L;const t=e.style,C={family:Ot(A,t.fontFamily),size:t.fontSize??14,weight:t.fontWeight??400,italic:t.fontStyle==="italic",letterSpacing:t.letterSpacing??0},i=t.color??255,E=t.lineHeight??C.size*1.2,r=t.textAlign??"start",w=A.fontMetrics(C),{rect:h,lines:G}=e,F=((D=e.padding)==null?void 0:D[0])??0,c=((R=e.padding)==null?void 0:R[1])??0,U=((L=e.padding)==null?void 0:L[2])??0,y=h.x+F,l=h.width-F-U;for(let O=0;O<G.length;O++){const q=G[O],b=h.y+c+O*E+(E-(w.ascent+w.descent))/2+w.ascent,T=A.measureText(q,C),Y=r==="center"?y+(l-T)/2:r==="end"?y+l-T:y;if(g.fillText(q,Y,b,C,i),t.textDecoration==="underline"||t.textDecoration==="line-through"){const z=Math.max(1,C.size/14),gA=t.textDecoration==="underline"?b+z:b-C.size*.3;g.fillRoundRect({x:Y,y:gA,width:T,height:z},void 0,i)}}}function tr(e,g,A,t){const{rect:C}=e;Zt(e.style.backgroundColor)&&g.fillRoundRect(C,t,286463999);const i=Math.min(C.width,C.height)*.3;if(i>=6){const E={family:"Roboto",size:i,weight:400,italic:!1,letterSpacing:0},r=A.fontMetrics(E),w=A.measureText("▶",E),h=C.x+(C.width-w)/2,G=C.y+(C.height-(r.ascent+r.descent))/2+r.ascent;g.fillText("▶",h,G,E,4294967244)}}function Br(e,g,A,t){var EA,iA,lA,DA,a;const C=e.style,i={family:Ot(A,C.fontFamily),size:C.fontSize??14,weight:C.fontWeight??400,italic:C.fontStyle==="italic",letterSpacing:C.letterSpacing??0},E=e.value??"",r=E.length===0,w=C.inputType==="password"&&!r,h=r?C.placeholder??"":w?"•".repeat(E.length):E,G=r?C.placeholderColor??2576980479:C.color??255,{rect:F}=e,c=((EA=e.padding)==null?void 0:EA[0])??0,U=((iA=e.padding)==null?void 0:iA[1])??0,y=((lA=e.padding)==null?void 0:lA[2])??0,l=((DA=e.padding)==null?void 0:DA[3])??0,D=F.x+c,R=F.width-c-y,L=F.y+U,O=F.height-U-l,q=A.fontMetrics(i),S=C.lineHeight??i.size*1.2,b=C.textAlign??"start",T=e.type==="textarea",Y=T?yI(h,R,f=>A.measureText(f,i)).lines:[h],z=f=>b==="center"?D+(R-f)/2:b==="end"?D+R-f:D,gA=f=>T?L+f*S+(S-(q.ascent+q.descent))/2+q.ascent:L+(O-(q.ascent+q.descent))/2+q.ascent;g.save(),g.clipRoundRect(F,t);for(let f=0;f<Y.length;f++){const u=Y[f];u.length>0&&g.fillText(u,z(A.measureText(u,i)),gA(f),i,G)}if((a=e.state)!=null&&a.focused){const f=r?[""]:T?yI(w?"•".repeat(E.length):E,R,QA=>A.measureText(QA,i)).lines:[h],u=f.length-1,m=A.measureText(f[u],i),W=r?z(0):z(m)+m,x=gA(u),IA=Math.max(1,i.size/14);g.fillRoundRect({x:W,y:x-q.ascent,width:IA,height:q.ascent+q.descent},void 0,C.color??255)}g.restore()}function Pt(e,g=[],A={}){const t=A.precision??2,C=A.includeIds??!1,i=e?ke(e,t,C):null;if(g.length===0)return i;const E=g.map(r=>ke(r,t,C));return i?(i.overlays=E,i):{type:"frame",overlays:E}}function Cr(e,g=[],A){return JSON.stringify(Pt(e,g,A),null,2)}function AI(e,g){const A=10**g;return Math.round(e*A)/A}function ke(e,g,A){var E,r;const t=e.rect,C={type:e.type};e.name&&(C.name=e.name),C.rect=[AI(t.x,g),AI(t.y,g),AI(t.width,g),AI(t.height,g)],A&&(C.id=e.id);const i=Qr(e.style);return i&&(C.style=i),e.text!==void 0&&(C.text=e.text),e.lines&&(e.lines.length!==1||e.lines[0]!==e.text)&&(C.lines=e.lines),e.value!==void 0&&e.value!==""&&(C.value=e.value),e.style.placeholder!==void 0&&(C.placeholder=e.style.placeholder),e.image&&(C.image={src:e.image.src,natural:[e.image.naturalWidth,e.image.naturalHeight]}),e.sourceRect&&(C.sourceRect=e.sourceRect),e.state&&(e.state.pressed||(E=e.state.classes)!=null&&E.length)&&(C.state={...e.state.pressed?{pressed:!0}:{},...(r=e.state.classes)!=null&&r.length?{classes:e.state.classes}:{}}),e.scroll&&(C.scroll={offset:AI(e.scroll.offset,g),content:AI(e.scroll.content,g)}),e.children.length>0&&(C.children=e.children.map(w=>ke(w,g,A))),C}function ir(e){return e.tl===e.tr&&e.tr===e.br&&e.br===e.bl?e.tl:[e.tl,e.tr,e.br,e.bl]}function Qr(e){const g={};if(e.backgroundColor!==void 0&&(g.backgroundColor=Xg(e.backgroundColor)),e.opacity!==void 0&&(g.opacity=e.opacity),e.color!==void 0&&(g.color=Xg(e.color)),e.fontSize!==void 0&&(g.fontSize=e.fontSize),e.fontFamily!==void 0&&(g.fontFamily=e.fontFamily),e.fontWeight!==void 0&&(g.fontWeight=e.fontWeight),e.fontStyle!==void 0&&e.fontStyle!=="normal"&&(g.fontStyle=e.fontStyle),e.lineHeight!==void 0&&(g.lineHeight=e.lineHeight),e.letterSpacing&&(g.letterSpacing=e.letterSpacing),e.textAlign!==void 0&&e.textAlign!=="start"&&(g.textAlign=e.textAlign),e.textDecoration!==void 0&&e.textDecoration!=="none"&&(g.textDecoration=e.textDecoration),e.lineClamp&&(g.lineClamp=e.lineClamp,e.textOverflow==="clip"&&(g.textOverflow=e.textOverflow)),e.objectFit!==void 0&&(g.objectFit=e.objectFit),e.tintColor!==void 0&&(g.tintColor=Xg(e.tintColor)),e.overlayColor!==void 0&&(g.overlayColor=Xg(e.overlayColor)),e.backgroundImage!==void 0&&(g.backgroundImage=e.backgroundImage),e.backgroundSize!==void 0&&(g.backgroundSize=e.backgroundSize),e.backgroundGradients!==void 0&&e.backgroundGradients.length>0&&(g.backgroundGradients=e.backgroundGradients.map(A=>{const t=A.stops.map(C=>({color:Xg(C.color),position:C.position}));if(A.type==="radial"){const C={type:"radial",shape:A.shape,extent:A.extent,cx:A.cx,cy:A.cy,stops:t};return A.extent==="explicit"&&(C.rx=A.rx,C.ry=A.ry,C.rxUnit=A.rxUnit,C.ryUnit=A.ryUnit),C}return{angle:A.angle,stops:t}})),e.borderRadius&&(e.borderRadius.tl||e.borderRadius.tr||e.borderRadius.br||e.borderRadius.bl)&&(g.borderRadius=ir(e.borderRadius)),e.border){const A={};for(const t of["top","right","bottom","left"]){const C=e.border[t];C&&C.width>0&&(A[t]={width:C.width,color:Xg(C.color)})}Object.keys(A).length>0&&(g.border=A)}return Object.keys(g).length>0?g:void 0}async function or(e,g){return typeof globalThis.window>"u"&&(globalThis.window=globalThis),e({wasmBinary:g,locateFile:()=>""})}const Xt=e=>e==="monospaced"?"monospace":e;function ft(e){return`${e.italic?"italic ":""}${e.weight} ${e.size}px ${Xt(e.family)}`}class Er{constructor(g={}){X(this,"ctx");X(this,"images",new Map);X(this,"pending",new Map);X(this,"resolver");X(this,"canvasSurfaces");X(this,"fontFormat","woff2");const A=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(8,8);this.ctx=A.getContext("2d"),this.canvasSurfaces=g.canvasSurfaces,this.resolver=qt({assetUrl:g.resolveAssetUrl,fileUrl:t=>URL.createObjectURL(t)})}resolveSrc(g){return this.resolver(g)}pendingImages(){return this.pending.size}resolveFontFamily(g){return Xt(g)}measureText(g,A){return this.ctx.font=ft(A),this.ctx.letterSpacing=`${A.letterSpacing}px`,this.ctx.measureText(g).width}fontMetrics(g){this.ctx.font=ft(g);const A=this.ctx.measureText("Mg"),t=A.fontBoundingBoxAscent||A.actualBoundingBoxAscent||g.size*.8,C=A.fontBoundingBoxDescent||A.actualBoundingBoxDescent||g.size*.2;return{ascent:t,descent:C}}getImage(g){return mI(g,this.canvasSurfaces)??this.images.get(g)}loadImage(g){const A=mI(g,this.canvasSurfaces);if(A)return Promise.resolve(A);const t=this.images.get(g);if(t)return Promise.resolve(t);const C=this.pending.get(g);if(C)return C;const i=(async()=>{const E=await this.decode(g);let r=E.naturalWidth,w=E.naturalHeight;if(JI(g)){const G=await sE(g,F=>fetch(F).then(c=>c.ok?c.text():null));G&&(r=G.width,w=G.height)}const h={src:g,naturalWidth:r,naturalHeight:w,handle:E};return this.images.set(g,h),this.pending.delete(g),h})();return this.pending.set(g,i),i.catch(()=>this.pending.delete(g)),i}decode(g){return new Promise((A,t)=>{const C=new Image;C.onload=()=>A(C),C.onerror=i=>t(i),C.src=g})}async loadFont(g,A,t){if(typeof globalThis.FontFace>"u")return;const C=new FontFace(g,`url(${A})`,t);document.fonts.add(C),await C.load()}}class Gt{constructor(g,A=1){X(this,"ctx");X(this,"dpr");X(this,"groups",[]);X(this,"scratch");X(this,"scratchCtx");this.ctx=g,this.dpr=A}beginGroup(g){const A=this.ctx,t=A.canvas.width,C=A.canvas.height;let i;typeof OffscreenCanvas<"u"?i=new OffscreenCanvas(t,C):(i=document.createElement("canvas"),i.width=t,i.height=C);const E=i.getContext("2d");E.setTransform(A.getTransform()),this.groups.push({parent:A,layer:i,alpha:g}),this.ctx=E}endGroup(){const g=this.groups.pop();g&&(this.ctx=g.parent,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.globalAlpha*=g.alpha,this.ctx.drawImage(g.layer,0,0),this.ctx.restore())}beginFrame(g,A){const{ctx:t,dpr:C}=this;t.setTransform(C,0,0,C,0,0),t.clearRect(0,0,g,A),t.globalAlpha=1}endFrame(){}save(){this.ctx.save()}restore(){this.ctx.restore()}setAlpha(g){this.ctx.globalAlpha*=g}translate(g,A){this.ctx.translate(g,A)}scale(g,A){this.ctx.scale(g,A)}transform(g,A,t,C,i,E){this.ctx.transform(g,A,t,C,i,E)}addRectPath(g,A){const t=this.ctx;A&&(A.tl||A.tr||A.br||A.bl)?t.roundRect(g.x,g.y,g.width,g.height,[A.tl,A.tr,A.br,A.bl]):t.rect(g.x,g.y,g.width,g.height)}path(g,A){this.ctx.beginPath(),this.addRectPath(g,A)}clipRoundRect(g,A){this.path(g,A),this.ctx.clip()}fillRoundRect(g,A,t){this.path(g,A),this.ctx.fillStyle=Pg(t),this.ctx.fill()}fillGradient(g,A,t){if(t.type==="radial"){this.fillRadial(g,A,t);return}const{x0:C,y0:i,x1:E,y1:r}=zE(t.angle,g),w=this.ctx.createLinearGradient(C,i,E,r);for(const h of t.stops)w.addColorStop(Math.max(0,Math.min(1,h.position)),Pg(h.color));this.path(g,A),this.ctx.fillStyle=w,this.ctx.fill()}fillRadial(g,A,t){const{cx:C,cy:i,rx:E,ry:r}=$E(t,g),w=this.ctx,h=E||1e-6,G=r||1e-6;w.save(),this.path(g,A),w.clip(),w.translate(C,i),w.scale(h,G);const F=w.createRadialGradient(0,0,0,0,0,1);for(const D of t.stops)F.addColorStop(Math.max(0,Math.min(1,D.position)),Pg(D.color));w.fillStyle=F;const c=(g.x-C)/h,U=(g.x+g.width-C)/h,y=(g.y-i)/G,l=(g.y+g.height-i)/G;w.fillRect(c,y,U-c,l-y),w.restore()}strokeBorder(g,A,t){const C=this.ctx,i=["top","right","bottom","left"].filter(r=>t[r]);if(i.length===4&&i.every(r=>t[r].width===t.top.width&&t[r].color===t.top.color)){const r=t.top.width,w=Se(A,g);C.beginPath(),this.addRectPath(g,w);const h={x:g.x+r,y:g.y+r,width:g.width-2*r,height:g.height-2*r};if(h.width>0&&h.height>0){const G=w&&Se({tl:Math.max(0,w.tl-r),tr:Math.max(0,w.tr-r),br:Math.max(0,w.br-r),bl:Math.max(0,w.bl-r)},h);this.addRectPath(h,G||void 0)}C.fillStyle=Pg(t.top.color),C.fill("evenodd");return}for(const r of i){const{width:w,color:h}=t[r];C.fillStyle=Pg(h),r==="top"?C.fillRect(g.x,g.y,g.width,w):r==="bottom"?C.fillRect(g.x,g.y+g.height-w,g.width,w):r==="left"?C.fillRect(g.x,g.y,w,g.height):C.fillRect(g.x+g.width-w,g.y,w,g.height)}}getScratch(g,A){return this.scratch||(this.scratch=typeof OffscreenCanvas<"u"?new OffscreenCanvas(g,A):document.createElement("canvas"),this.scratchCtx=this.scratch.getContext("2d")),(this.scratch.width<g||this.scratch.height<A)&&(this.scratch.width=Math.max(this.scratch.width,g),this.scratch.height=Math.max(this.scratch.height,A)),this.scratchCtx}drawImage(g,A,t,C){const i=g.handle;if(!i)return;const{src:E,dst:r}=A?{src:A,dst:t}:jE(g.naturalWidth,g.naturalHeight,t,C.fit),w=!A&&C.fit!=="cover";if(C.tint===void 0){w?this.ctx.drawImage(i,r.x,r.y,r.width,r.height):this.ctx.drawImage(i,E.x,E.y,E.width,E.height,r.x,r.y,r.width,r.height);return}const h=Math.max(1,Math.ceil(r.width)),G=Math.max(1,Math.ceil(r.height)),F=this.getScratch(h,G);F.clearRect(0,0,h,G),F.globalCompositeOperation="source-over",w?F.drawImage(i,0,0,h,G):F.drawImage(i,E.x,E.y,E.width,E.height,0,0,h,G),F.globalCompositeOperation="source-in",F.fillStyle=Pg(C.tint),F.fillRect(0,0,h,G),F.globalCompositeOperation="source-over",this.ctx.drawImage(F.canvas,0,0,h,G,r.x,r.y,r.width,r.height)}fillText(g,A,t,C,i){const E=this.ctx;E.font=`${C.italic?"italic ":""}${C.weight} ${C.size}px ${C.family}`,E.textBaseline="alphabetic",E.textAlign="left","letterSpacing"in E&&(E.letterSpacing=`${C.letterSpacing}px`),E.fillStyle=Pg(i),E.fillText(g,A,t)}}const ut=new Set;function rr(e){return(...g)=>{ut.has(e)||(ut.add(e),console.warn(`[canvas-ui] "${e}" is not implemented yet (deferred feature).`))}}async function sr(e={}){const g=e.host??new WE({canvasSurfaces:e.canvasSurfaces}),A=e.layout??await HI.create(),t=new LE(A,g),C=new XE(t);return{openScreen:i=>t.openScreen(i),closeScreen:()=>t.closeScreen(),insertNode:(i,E,r)=>t.insertNode(i,E,r),removeNode:(i,E)=>t.removeNode(i,E),setContent:(i,E,r)=>t.setContent(i,E,r),updateStyle:(i,E,r)=>t.updateStyle(i,E,r),mergeStyle:(i,E)=>t.mergeStyle(i,E),setClass:(i,E,r)=>t.setClass(i,E,r),setTheme:i=>t.setTheme(i),updateNode:(i,E,r)=>t.updateNode(i,E,r),registerResizeEvent:i=>t.registerResizeEvent(i),registerTouchStartEvent:i=>C.registerTouchStartEvent(i),registerTouchEndEvent:i=>C.registerTouchEndEvent(i),isButtonPressed:i=>t.isButtonPressed(i),getTextValue:i=>t.getTextValue(i),getBoundingClientRect:i=>t.getBoundingClientRect(i),routerOpen:(i,E)=>t.routerOpen(i,E),routerPush:i=>t.routerPush(i),routerReplace:i=>t.routerReplace(i),routerPop:(i=-1)=>t.routerPop(i),routerHide:()=>t.routerHide(),routerRestore:()=>t.routerRestore(),showWidget:i=>t.showWidget(i),hideWidget:i=>t.hideWidget(i),setSourceRect:(i,E,r,w,h)=>t.setSourceRect(i,E,r,w,h),registerFont:(i,E,r,w,h)=>t.registerFont(i,E,r,w,h),fontFormat:g.fontFormat,toast:rr("toast"),animateTo:(i,E)=>t.animateTo(i,E),animateFrom:(i,E)=>t.animateFrom(i,E),vlistMount:(i,E,r)=>t.vlistMount(i,E,r),vlistSetKeys:(i,E,r)=>t.vlistSetKeys(i,E,r),vlistInsertKeys:(i,E,r,w)=>t.vlistInsertKeys(i,E,r,w),vlistInvalidate:(i,E)=>t.vlistInvalidate(i,E),vlistRemoveKeys:(i,E)=>t.vlistRemoveKeys(i,E),command:(i,E,...r)=>t.command(i,E,...r),_setCreator:i=>C.setCreator(i),_setScenePointer:i=>C.setScenePointer(i),resize:(i,E)=>t.resize(i,E),setSafeArea:(i,E)=>t.setSafeArea(i,E),renderTree:()=>t.renderTree(),widgets:()=>t.widgetTrees(),find:i=>t.findByName(i),findAll:i=>t.findAllByName(i),serialize:i=>Pt(t.renderTree(),t.widgetTrees(),i),toText:i=>Cr(t.renderTree(),t.widgetTrees(),i),paint:i=>{const{width:E,height:r}=t.viewport;Ar(t.frame(),i,g,E,r)},pointerDown:(i,E,r)=>C.pointerDown(i,E,r),pointerMove:(i,E,r)=>C.pointerMove(i,E,r),pointerUp:(i,E,r)=>C.pointerUp(i,E,r),scrollBy:(i,E)=>t.scrollBy(i,E),tick:i=>t.tick(i),hasActiveAnimations:()=>t.hasActiveAnimations(),needsPaint:()=>t.needsPaint(),focusInput:i=>t.focusInput(i),submitInput:()=>t.submitInput(),blurInput:()=>t.blurInput(),setInputValue:(i,E)=>t.setInputValue(i,E),keyboard:()=>t.keyboard(),uiTransform:()=>t.uiTransform(),onKeyboardChange:i=>t.registerKeyboardEvent(i),renderer:t,host:g}}async function nr(e,g){const A=await fetch(Mt).then(iA=>iA.arrayBuffer()),t=await or(bt,A),C=new HI(t),i=await sr({host:new Er({resolveAssetUrl:iA=>bI(iA),canvasSurfaces:g}),layout:C}),E=document.createElement("canvas");E.style.position="absolute",E.style.inset="0",E.style.width="100%",E.style.height="100%",E.style.touchAction="none",e.appendChild(E);const r=E.getContext("2d"),w=()=>(window.devicePixelRatio||1)*Mg(E);let h=w(),G=new Gt(r,h);const F=ar();F.el.style.display="none",e.appendChild(F.el);const c=document.createElement("input");c.setAttribute("autocomplete","off"),c.style.cssText="position:absolute;left:0;top:0;width:1px;height:1px;opacity:0;pointer-events:none;border:0;padding:0;",e.appendChild(c);let U=0;c.addEventListener("input",()=>{U&&i.setInputValue(U,c.value)}),i.onKeyboardChange(iA=>{iA?(U=iA.input.nodeId,c.type=iA.input.type==="password"?"password":"text",c.value!==iA.input.value&&(c.value=iA.input.value),c.focus({preventScroll:!0}),F.show(iA.rect)):(U=0,c.blur(),F.el.style.display="none")});let y=0,l=0,D=!1;const R=iA=>{const lA=l===0?0:iA-l;l=iA,i.hasActiveAnimations()&&i.tick(lA),(D||i.needsPaint())&&(D=!1,i.paint(G)),y=requestAnimationFrame(R)};let L=null,O="";const q=(iA,lA)=>{const DA=L?Yt(L,iA>lA):null,a=DA?JSON.stringify(DA):"";a!==O&&(O=a,i.setSafeArea(DA?DA.insets:null,DA==null?void 0:DA.bars))};let S=0,b=0;const T=(iA,lA,DA)=>{if(iA<=0||lA<=0)return;const a=DA??w();a!==h&&(h=a,G=new Gt(r,h)),E.width=Math.round(iA*h),E.height=Math.round(lA*h),E.style.width=iA+"px",E.style.height=lA+"px",D=!0,q(iA,lA),i.resize(iA,lA),S=iA,b=lA},Y=iA=>{const lA=E.getBoundingClientRect(),DA=Mg(E);return[(iA.clientX-lA.left)/DA,(iA.clientY-lA.top)/DA]},z=iA=>{E.setPointerCapture(iA.pointerId);const[lA,DA]=Y(iA);i.pointerDown(iA.pointerId,lA,DA)},gA=iA=>{const[lA,DA]=Y(iA);i.pointerMove(iA.pointerId,lA,DA)},EA=iA=>{const[lA,DA]=Y(iA);i.pointerUp(iA.pointerId,lA,DA)};return E.addEventListener("pointerdown",z),E.addEventListener("pointermove",gA),E.addEventListener("pointerup",EA),T(e.clientWidth,e.clientHeight),y=requestAnimationFrame(R),Object.assign(i,{_onResize:T,_setSafeAreaSpec(iA){L=iA,S&&b&&q(S,b)},getDisplaySize:()=>[S,b],_destroy(){cancelAnimationFrame(y),E.removeEventListener("pointerdown",z),E.removeEventListener("pointermove",gA),E.removeEventListener("pointerup",EA),E.remove(),F.el.remove(),c.remove()}})}function ar(){const e=document.createElement("div");e.style.cssText="position:absolute;left:0;right:0;bottom:0;box-sizing:border-box;background:#caced6;display:flex;flex-direction:column;justify-content:space-evenly;align-items:stretch;padding:6px 5px;z-index:20;user-select:none;-webkit-user-select:none;touch-action:none;";const g=["10","9","7","5"];for(const A of g){const t=document.createElement("div");t.style.cssText="display:flex;justify-content:center;align-items:center;gap:6px;flex:0 0 auto;";for(let C=0;C<Number(A);C++){const i=document.createElement("div");i.style.cssText="flex:1 1 0;max-width:32px;height:40px;background:#fff;border-radius:6px;box-shadow:0 1px 0 rgba(0,0,0,0.25);",t.appendChild(i)}e.appendChild(t)}return e.addEventListener("pointerdown",A=>A.preventDefault()),{el:e,show(A){e.style.height=A.height+"px",e.style.display="flex"}}}const cr=["abstract","ios","android"],lr={abstract:void 0,ios:{portrait:[59,0,34,0],landscape:[0,59,21,59]},android:{portrait:[24,0,48,0],landscape:[24,0,48,0],portraitBars:["top","bottom"],landscapeBars:["top","bottom"]}},jt=e=>typeof e=="string"&&cr.includes(e)?e:"abstract",Hg=document.getElementById("app"),ye=document.getElementById("loader"),Yg=new URLSearchParams(location.search),ve=(()=>{const e=window.lecodesEmbedConfig;return e&&typeof e=="object"?e:{}})();for(const[e,g]of Object.entries(ve))g!=null&&typeof g!="object"&&Yg.set(e,String(g));let KI=Yg.get("lang")||"en";window.getLanguage=()=>KI;const zt=window.parent!==window?e=>window.parent.postMessage({type:"lecodes-orientation",orientation:e},"*"):void 0;let xA=null;const $t=e=>{const g=e!=null?Number(e):NaN;return Number.isFinite(g)&&g>0?g:null};let Je=$t(Yg.get("zoom"))??.75,Ue=jt(Yg.get("shell"));const AB=e=>{if(!e||typeof e!="object")return null;const g=C=>typeof C=="number"&&Number.isFinite(C)&&C>=0?Math.round(C):0,A=e,t=[g(A.top),g(A.right),g(A.bottom),g(A.left)];return{portrait:t,landscape:t}};let gB=AB(ve.safeArea);const LI=()=>gB??lr[Ue],hr=()=>Je===1,YI=e=>{Je=e,Hg.style.zoom=String(e),xA==null||xA.refreshResolution()};YI(Je);function Jg(e){ye==null||ye.classList.toggle("embed-loader--on",e)}function vg(e){const g=document.createElement("div");g.className="embed-error",g.textContent=e,Hg.appendChild(g)}const IB=e=>typeof e=="string"&&e.startsWith("/")&&!e.startsWith("//");function dr(e){const g=e.slice(0,2e3),A=new Set,t=g.match(/\/\/ preload: (.+)/);if(t)for(const w of t[1].split(";"))A.add(w);const C=g.includes("// gl: disable")||g.includes("// gl: defer"),i=!g.includes("// gl: disable"),E=g.includes("// 2d: enable");return{engine:E&&i?"dual":E?"2d":C?"defer":"gl",preloads:A,bootFonts:yo(g)}}const He=async e=>{e.zoom!==void 0&&YI(e.zoom),e.lang&&(KI=e.lang);let g=e.code;if(g===void 0){if(!e.src)throw new Error("embed.mount: pass `code` or `src`");const E=await fetch(e.src);if(!E.ok)throw new Error(`embed: ${e.src} → HTTP ${E.status}`);g=await E.text()}const{engine:A,preloads:t,bootFonts:C}=dr(g),i=await So(Hg,{engine:A,ui:e.ui==="canvas"?nr:tE,preloads:t,bootFonts:C,methods:e.methods,safeArea:e.safeArea,keyboardTargets:e.keyboardTargets,onOrientation:e.onOrientation??zt});try{i.run(g,{onError:e.onError})}catch{}return Jg(!1),{_creator:i._creator,_creator2d:i._creator2d,_creatorUI:i._creatorUI,_creatorUtils:i._creatorUtils,uiRoot:Hg,refreshResolution:()=>i.refreshResolution(),destroy:()=>i.destroy()}};let BI=null,tI=null,Qg=0;function eB(){tI?CB(tI.uuid,tI.engine):BI&&Ye(BI)}async function Ye(e){const g=++Qg;BI=e,tI=null,Jg(!0),xA==null||xA.destroy(),xA=null,Hg.replaceChildren();try{const A=await He({src:e,safeArea:LI(),onError:t=>{var i;const C=t.detail?`${t.message}: ${t.detail}`:t.message;vg((i=t.nativeFrames)!=null&&i.length?`${C} — in ${t.nativeFrames[0]}`:C)}});if(g!==Qg){A.destroy();return}xA=A}catch(A){g===Qg&&vg(String(A))}finally{g===Qg&&Jg(!1)}}function tB(e){const g=e||"en";g!==KI&&(KI=g,eB())}function BB(e){const g=jt(e);g!==Ue&&(Ue=g,eB())}const yr=()=>{if(window.parent===window)return null;const e=location.ancestorOrigins;if(e&&e.length>0)return e[0];try{return document.referrer?new URL(document.referrer).origin:null}catch{return null}},Dr=(e,g)=>{if(e.length===0)return!0;const A=document.referrer.toLowerCase();return e.some(t=>{const C=t.toLowerCase().replace(/\/+$/,"");let i;try{i=new URL(C.includes("://")?C:`https://${C}`).origin}catch{return!1}return i!==g.toLowerCase()?!1:!C.replace(/^https?:\/\//,"").includes("/")||A.startsWith(C)})},fr=async e=>{try{const g=localStorage.getItem("accessToken");return g?(await fetch(`/api/projects/${encodeURIComponent(e)}/publish`,{headers:{Authorization:`Bearer ${g}`}})).ok:!1}catch{return!1}},Gr=e=>`/code/${encodeURIComponent(e)}.js?ts=${Math.trunc(Date.now()/3e4)*3e4}`;async function CB(e,g){var G;const A=++Qg;BI=null,tI={uuid:e,engine:g},Jg(!0),xA==null||xA.destroy(),xA=null,Hg.replaceChildren();const t=ve.policy;let C;if(t&&typeof t=="object"&&t.uuid===e)C=t;else{try{const F=await fetch(`/api/publish/${encodeURIComponent(e)}`,{cache:"no-store"});if(!F.ok)throw new Error(`HTTP ${F.status}`);C=await F.json()}catch{A===Qg&&(Jg(!1),vg("This app isn’t available."));return}if(A!==Qg)return}const i=yr(),E=i===null||i===location.origin||(C.firstPartyOrigins??[]).includes(i);let r=null;if(C.published?E&&!C.web.enabled?r="This app can’t be opened in the browser — get the LeCodes app.":!E&&!C.embed.enabled?r="This app can’t be embedded on other sites.":!E&&!Dr(C.embed.referers,i)&&(r="This site isn’t allowed to embed this app."):r="This app isn’t published right now.",r&&C.published&&E&&Yg.get("preview")==="1"&&await fr(e)&&(r=null),A!==Qg)return;if(r){Jg(!1),vg(r);return}const w=(G=C.meta)!=null&&G.twoD?"full":g==="full"||g==="lite"?g:C.web.engine,h=Gr(e);BI=h;try{if(w==="lite"){const F=await fetch(h);if(!F.ok)throw new Error(`embed: ${h} → HTTP ${F.status}`);const c=await F.text();if(A!==Qg)return;const{mountCreatorLite:U}=await II(async()=>{const{mountCreatorLite:l}=await import("./assets/host-CWKB1WDd.js");return{mountCreatorLite:l}},[],import.meta.url),y=await U(Hg,c,void 0,{safeArea:LI(),onOrientation:zt,frame:!hr(),onError:l=>vg(l.detail?`${l.message}: ${l.detail}`:l.message)});if(A!==Qg){y.destroy();return}xA={_creator:y._creator,_creator2d:void 0,_creatorUI:y._creatorUI,_creatorUtils:y._creatorUtils,uiRoot:y.uiRoot??Hg,refreshResolution:()=>{},destroy:()=>y.destroy()}}else{const F=await He({src:h,safeArea:LI(),onError:c=>{var y;const U=c.detail?`${c.message}: ${c.detail}`:c.message;vg((y=c.nativeFrames)!=null&&y.length?`${U} — in ${c.nativeFrames[0]}`:U)}});if(A!==Qg){F.destroy();return}xA=F}}catch(F){A===Qg&&vg(String(F))}finally{A===Qg&&Jg(!1)}}window.lecodesEmbed={version:"f3396b0d-2026-09-04",mount:He,setLang:tB,setZoom:YI,setShell:BB,setSafeArea(e){var g,A;gB=AB(e),(A=(g=xA==null?void 0:xA._creatorUI)==null?void 0:g._setSafeAreaSpec)==null||A.call(g,LI()??null)},destroy(){xA==null||xA.destroy(),xA=null,BI=null,tI=null}};window.addEventListener("message",e=>{if(e.source!==window.parent)return;const g=e.data;if(g)if(g.type==="lecodes-run"&&IB(g.src))Ye(g.src);else if(g.type==="lecodes-lang"&&typeof g.lang=="string")tB(g.lang);else if(g.type==="lecodes-zoom"){const A=$t(g.zoom);A!==null&&YI(A)}else g.type==="lecodes-shell"&&typeof g.shell=="string"&&BB(g.shell)});const RI=Yg.get("src"),wt=Yg.get("app");wt?CB(wt,Yg.get("engine")):RI===null||RI===""||(IB(RI)?Ye(RI):(Jg(!1),vg("embed: expected ?src=/path/to/app.js (same-origin)")));export{Mg as A,Fr as B,Og as C,st as D,De as E,Ft as F,KQ as G,St as H,Sr as I,or as J,Po as R,II as _,qQ as a,Ho as b,MI as c,fe as d,Ke as e,mo as f,bI as g,Uo as h,hI as i,ko as j,Ro as k,ho as l,Do as m,ao as n,Yt as o,eo as p,yo as q,XQ as r,me as s,wo as t,tt as u,fo as v,go as w,It as x,fg as y,UI as z};
187
+ `)){if(i.length===0){t.push("");continue}let E=i;for(;E;){if(A(E)<=g){t.push(E),C=Math.max(C,A(E));break}let r=0,w=-1,h=0;for(;(h=E.indexOf(" ",h+1))!==-1&&!(A(E.substring(0,h))>g);)w=h;if(w>0)r=w;else{let F=E.indexOf(" ");F===-1&&(F=E.length);const c=E.substring(0,F);if(A(c)>g){for(let U=1;U<=c.length;U++)if(A(c.substring(0,U))>g){r=U-1;break}}else for(let U=F+1;U<=E.length;U++)if(A(E.substring(0,U))>g){r=U-1;break}}r<=0&&(r=1);const G=E.substring(0,r);t.push(G),C=Math.max(C,A(G)),E=E.substring(r+(w>0?1:0))}}return{lines:t,maxWidth:C}}const ce="…";function _t(e,g,A,t){const C=g.lineClamp??0;if(C<=0||e.length<=C)return e;const i=e.slice(0,C);return g.textOverflow==="clip"||(i[C-1]=nE(i[C-1],A,t)),i}function nE(e,g,A){if(!isFinite(g))return e+ce;const t=[...e];let C=t.length;for(;C>0&&A(t.slice(0,C).join("")+ce)>g;)C--;return t.slice(0,C).join("").trimEnd()+ce}function aE(e,g,A){const t=Fe(e),C=Tt(t),i=isNaN(A)?1/0:A,E=G=>g.measureText(G,C),r=yI(e.text??"",i,E),w=_t(r.lines,e.style,i,E);let h=r.maxWidth;if(w!==r.lines){h=0;for(const G of w)h=Math.max(h,E(G))}return{width:Math.ceil(h),height:Math.ceil(w.length*t.lineHeight)}}function cE(e,g,A){const t=e.style,C={family:t.fontFamily??"Roboto",size:t.fontSize??14,weight:t.fontWeight??400,italic:t.fontStyle==="italic",letterSpacing:t.letterSpacing??0},i=t.lineHeight??C.size*1.2,E=e.value??"";if(e.type==="input")return{width:Math.ceil(g.measureText(E,C)),height:Math.ceil(i)};const r=isNaN(A)?1/0:A,w=yI(E,r,h=>g.measureText(h,C));return{width:Math.ceil(w.maxWidth),height:Math.ceil(Math.max(1,w.lines.length)*i)}}function lE(e,g,A,t){const C=e.imageSrcRaw;let i=0,E=0,r=!1;if(e.sourceRect)i=e.sourceRect[2],E=e.sourceRect[3];else if(Me(C)){r=!0;const G=we(C.svg);if(G)i=G.width,E=G.height;else{const F=g.getImage(g.resolveSrc(C)??"");i=(F==null?void 0:F.naturalWidth)??0,E=(F==null?void 0:F.naturalHeight)??0}}else{const G=g.resolveSrc(C),F=G?g.getImage(G):void 0;i=(F==null?void 0:F.naturalWidth)??0,E=(F==null?void 0:F.naturalHeight)??0,r=JI(G)}if(i===0||E===0)return{width:0,height:0};const w=Math.min(A/i,t/E),h=isNaN(A)&&isNaN(t)?1:isNaN(A)?t/E:isNaN(t)?A/i:r?w:Math.min(w,1);return{width:i*h,height:E*h}}function hE(e,g){return Wt(e,g.rootRect.x,g.rootRect.y,!0,g)}function Wt(e,g,A,t,C){var y,l;if(e.style.display==="none")return null;let i,E,r,w;if(t)i=C.rootRect.x,E=C.rootRect.y,r=C.rootRect.width,w=C.rootRect.height;else{const D=e.layoutRect;if(!D)return null;i=g+D.x,E=A+D.y,r=D.width,w=D.height}const h={x:i,y:E,width:r,height:w},G={id:e.id,type:e.type,rect:h,style:e.style,children:[]};if(e.name&&(G.name=e.name),e.type==="text"){const D=Fe(e),R=Tt(D),L=e.text??"";G.text=L;const O=C.layout.getPadding(e.id);(O[0]||O[1]||O[2]||O[3])&&(G.padding=O);const q=r-O[0]-O[2],S=`${e.style.lineClamp??0}|${e.style.textOverflow??""}`,b=`${q}|${R.size}|${R.weight}|${R.italic?1:0}|${R.letterSpacing}|${R.family}|${S}|${L}`;if(((y=e.wrapCache)==null?void 0:y.key)===b)G.lines=e.wrapCache.lines;else{const T=z=>C.host.measureText(z,R),Y=_t(yI(L,q,T).lines,e.style,q,T);e.wrapCache={key:b,lines:Y},G.lines=Y}G.style={...e.style,color:D.color,fontSize:D.fontSize,fontFamily:D.fontFamily,fontWeight:D.fontWeight,fontStyle:D.fontStyle,lineHeight:D.lineHeight,letterSpacing:D.letterSpacing,textAlign:D.textAlign,textDecoration:D.textDecoration}}else if(e.type==="image"){const D=C.host.resolveSrc(e.imageSrcRaw),R=D?C.host.getImage(D):void 0;G.image=R??(D?{src:D,naturalWidth:0,naturalHeight:0}:void 0),e.sourceRect&&(G.sourceRect=e.sourceRect)}else if(e.editable){G.value=e.value;const D=C.layout.getPadding(e.id);(D[0]||D[1]||D[2]||D[3])&&(G.padding=D);const R=Fe(e);G.style={...e.style,color:R.color,fontSize:R.fontSize,fontFamily:R.fontFamily,fontWeight:R.fontWeight,fontStyle:R.fontStyle,lineHeight:R.lineHeight,letterSpacing:R.letterSpacing,textAlign:R.textAlign,textDecoration:R.textDecoration}}e.interactive&&(G.state={pressed:C.isPressed(e)}),e.editable&&C.isFocused(e)&&(G.state={...G.state,focused:!0});const F=(l=e.jsNode)==null?void 0:l._classes;F&&F.size>0&&(G.state={...G.state,classes:[...F]}),e.style.overflow==="hidden"&&(G.clip=!0);let c=i,U=E;if(e.scrollable){const D=e.scrollAxis,R=D==="x"?C.layout.getContentWidth(e.id):C.layout.getContentHeight(e.id);G.clip=!0,G.scroll={offset:e.scrollOffset,content:R,axis:D},D==="x"?c=i-e.scrollOffset:U=E-e.scrollOffset}for(const D of e.children){const R=Wt(D,c,U,!1,C);R&&G.children.push(R)}return G}const dE=256,yE=new Set(["duration","delay","layer","commit"]);function eI(e,g,A,t,C=dE,i){if(t===null){e.setStyle(g,A,null,C);return}const E=typeof t;if(E==="number"||E==="string"||E==="boolean"){e.setStyle(g,A,t,C);return}if(E!=="object")return;const r=t;if("_id"in r||"svg"in r||DE(r)){const h=i==null?void 0:i(r);h!=null&&e.setStyle(g,A,h,C);return}const w=e.getLayer(g,A);for(const h of Object.keys(r))yE.has(h)||eI(e,g,h,r[h],w,i)}function DE(e){return typeof File<"u"&&e instanceof File}function at(e){const g=(Array.isArray(e.children)?e.children:[]).filter(w=>!!w);if(g.length===0)return null;const A=e._lens,t=Array.isArray(A)&&A.length>0?A:g.map(()=>1),C=e._index,i=Math.min(Math.max(typeof C=="number"?C:0,0),t.length-1);let E=0;for(let w=0;w<i;w++)E+=t[w]??0;const r=E+(t[i]??1)-1;return g[Math.min(r,g.length-1)]??null}function ct(e,g,A,t,C){var r;const i=(r=e.jsNode)==null?void 0:r.ll;if(!i||i.length===0)return;const E={left:g,top:A,width:t,height:C};for(const w of i)w(E)}function fE(e,g,A){switch(g){case"screen":e.setStyle(A,"color","var(--color, #ffffffff)"),e.setStyle(A,"fontFamily","var(--fontFamily, Roboto)");break;case"vlist":e.setStyle(A,"flexDirection","column");break}}class le{constructor(g,A,t,C,i=!1,E=r=>typeof r=="string"?r:void 0){X(this,"screenId");X(this,"isWidget");X(this,"jsNode");X(this,"root");X(this,"layout");X(this,"registry");X(this,"resolveSrc");X(this,"width",0);X(this,"height",0);X(this,"dirty",!1);X(this,"cachedTree",null);X(this,"firedScreenW",-1);X(this,"firedScreenH",-1);this.screenId=g,this.jsNode=A,this.layout=t,this.registry=C,this.isWidget=i,this.resolveSrc=E}mount(){this.root=this.addNode(this.jsNode,null,0)}addNode(g,A,t){var G,F;const C=g.type,i=C==="text"||C==="image"||C==="input"||C==="textarea",E=A===null?this.layout.createRoot(this.screenId):this.layout.createChild(A.id,t,i),r=new BE(E,C,g);r.parent=A,g._id=E,this.registry.register(r),fE(this.layout,C,E),(A==null?void 0:A.type)==="pager"&&(this.setStyleValue(E,"width","100%"),this.setStyleValue(E,"height","100%"));const w=g._style??{};for(const c of Object.keys(w))this.setStyleValue(E,c,w[c]);if(C==="image"&&w.tintColor==null){const c=xt(r.imageSrcRaw);c!=null&&this.setStyleValue(E,"tintColor",c)}if(g._classes)for(const c of g._classes)this.layout.enableNodeLayer(E,this.layout.getLayer(E,"$"+c));const h=C==="pager"?[at(g)]:g.children;if(Array.isArray(h)){let c=0;for(const U of h)U&&(r.children.push(this.addNode(U,r,c)),c++)}if(C==="pager"&&r.children.length>0)for(const c of r.children[0].jsNode.ol??[])c();return(F=(G=this.registry).onNodeAdded)==null||F.call(G,r),r}pagerReconcile(g){const A=this.registry.get(g._id);if(!A)return!1;const t=at(g),C=A.children[0]??null;if(C?C.jsNode===t:t===null)return!1;if(C){for(const i of C.jsNode.cl??[])i();this.layout.removeChild(A.id,C.id),this.releaseRecursive(C.jsNode),A.children.length=0}if(t){A.children.push(this.addNode(t,A,0));for(const i of t.ol??[])i()}return this.dirty=!0,!0}setStyleValue(g,A,t){eI(this.layout,g,A,t,void 0,this.resolveSrc)}applyLayout(g,A){g===this.width&&A===this.height&&!this.dirty||(this.width=g,this.height=A,this.dirty=!1,this.layout.calculate(this.root.id,g,A,this.isWidget),this.captureLayout(this.root),this.cachedTree=null)}captureLayout(g){if(g===this.root&&!this.isWidget)(this.width!==this.firedScreenW||this.height!==this.firedScreenH)&&(this.firedScreenW=this.width,this.firedScreenH=this.height,ct(g,0,0,this.width,this.height));else{const A=this.layout.getLayout(g.id);A&&(g.layoutRect=A,ct(g,A.x,A.y,A.width,A.height))}for(const A of g.children)this.captureLayout(A)}markDirty(){this.dirty=!0,this.cachedTree=null}isDirty(){return this.dirty||this.cachedTree===null}deactivate(){this.width=0,this.height=0,this.firedScreenW=-1,this.firedScreenH=-1,this.dirty=!1,this.cachedTree=null}renderTree(g,A,t=()=>!1){if(this.dirty&&this.width>0&&(this.dirty=!1,this.layout.calculate(this.root.id,this.width,this.height,this.isWidget),this.captureLayout(this.root),this.cachedTree=null),this.cachedTree)return this.cachedTree;const C=this.isWidget?this.root.layoutRect??{x:0,y:0,width:0,height:0}:{x:0,y:0,width:this.width,height:this.height};return this.cachedTree=hE(this.root,{layout:this.layout,host:g,rootRect:C,isPressed:A,isFocused:t}),this.cachedTree}insertNode(g,A,t){const C=this.registry.get(g);if(!C)return;const i=this.addNode(t,C,A);C.children.splice(A,0,i),this.dirty=!0}removeNode(g,A){const t=this.registry.get(g);if(!t)return;const C=A._id,i=t.children.findIndex(E=>E.id===C);i>=0&&t.children.splice(i,1),this.layout.removeChild(g,C),this.releaseRecursive(A),this.dirty=!0}setContent(g,A,t){const C=this.registry.get(g);if(!C)return;for(const E of A){if(!E)continue;const r=E._id;this.layout.removeChild(g,r),this.releaseRecursive(E)}C.children.length=0;let i=0;for(const E of t)E&&(C.children.push(this.addNode(E,C,i)),i++);this.dirty=!0}releaseRecursive(g){g._id&&this.registry.unregister(g._id),g._id=0;const A=g.children;if(Array.isArray(A))for(const t of A)t&&this.releaseRecursive(t)}destroy(){this.releaseRecursive(this.jsNode),this.layout.freeTree(this.root.id,this.isWidget)}}class GE{constructor(g,A){X(this,"show",!1);X(this,"stack",[]);this.onScreen=g,this.free=A}init(g){this.stack=[g],this.onScreen(g),this.show=!0}push(g){this.stack.push(g),this.onScreen(g)}replace(g){const A=this.stack[this.stack.length-1];this.stack[this.stack.length-1]=g,this.onScreen(g),A&&this.free(A)}hide(){this.show=!1}pop(g){const A=g<0?Math.max(this.stack.length-1+g,0):Math.min(g,this.stack.length-1),t=this.stack.slice(A+1);this.stack.length=A+1,this.onScreen(this.stack[A]);for(const C of t)this.free(C)}restore(){this.show=!0,this.onScreen(this.stack[this.stack.length-1])}get current(){return this.stack[this.stack.length-1]}}class uE{constructor(g){X(this,"vlists",new Map);this.host=g}remove(g){this.vlists.delete(g)}initVlist(g){var C,i,E;const A={node:g,keys:[],items:new Map,endLatched:!1,startLatched:!1,invertedInitial:!!((C=g.jsNode)!=null&&C._inverted)};this.vlists.set(g.id,A);const t=((i=g.jsNode)==null?void 0:i._keys)??[];t.length&&this.vlistSetKeys(g.jsNode,t,((E=g.jsNode)==null?void 0:E._estimates)??[])}settle(g){for(const[A,t]of this.vlists){if(!t.invertedInitial||this.host.getScreenOf(A)!==g)continue;const C=this.host.getNode(A);C&&this.scrollVlistToEnd(C),t.invertedInitial=!1}}checkEdges(g,A,t){const C=this.vlists.get(g.id),i=g.jsNode;if(!(!C||!i)){if(Array.isArray(i.erl)&&i.erl.length){const E=t-A<=(i._endThreshold??0);if(E&&!C.endLatched){C.endLatched=!0;for(const r of i.erl)r()}else E||(C.endLatched=!1)}if(Array.isArray(i.strl)&&i.strl.length){const E=A<=(i._startThreshold??0);if(E&&!C.startLatched){C.startLatched=!0;for(const r of i.strl)r()}else E||(C.startLatched=!1)}}}vlistChildIndex(g,A){const t=g.keys.indexOf(A);let C=0;for(const i of g.items.keys())g.keys.indexOf(i)<t&&C++;return C}unmountVlistItem(g,A,t){var i;const C=g.items.get(t);C!==void 0&&((i=this.host.getScreenOf(A))==null||i.removeNode(A,C),g.items.delete(t))}vlistMount(g,A,t){const C=this.vlists.get(g._id);if(!C||t==null)return;const i=this.host.getScreenOf(g._id);i==null||i.insertNode(g._id,this.vlistChildIndex(C,A),t),this.host.preloadNew(t,i),C.items.set(A,t)}vlistSetKeys(g,A,t){var E;const C=this.vlists.get(g._id);if(!C)return;const i=[...C.keys];for(const r of i)this.unmountVlistItem(C,g._id,r);C.keys=[...A],(E=g._syncWindow)==null||E.call(g,i,A)}vlistInsertKeys(g,A,t,C){var G;const i=this.vlists.get(g._id);if(!i)return;const E=this.host.getNode(g._id),r=A<0||A>=i.keys.length,w=r?i.keys.length:Math.max(0,A),h=E?this.host.isAtScrollEnd(E):!1;i.keys.splice(w,0,...t),w===0&&E&&C&&C.length&&(E.scrollOffset+=C.reduce((F,c)=>F+(c||0),0)),(G=g._syncWindow)==null||G.call(g,[],t),r&&E&&g._inverted&&h&&this.scrollVlistToEnd(E)}vlistRemoveKeys(g,A){var i;const t=this.vlists.get(g._id);if(!t)return;const C=A.filter(E=>t.items.has(E));for(const E of A){this.unmountVlistItem(t,g._id,E);const r=t.keys.indexOf(E);r>=0&&t.keys.splice(r,1)}C.length&&((i=g._syncWindow)==null||i.call(g,C,[]))}vlistInvalidate(g,A){var C;const t=this.vlists.get(g._id);!t||!t.keys.includes(A)||(this.unmountVlistItem(t,g._id,A),(C=g._syncWindow)==null||C.call(g,[A],[A]))}command(g,A,...t){const C=this.host.getNode(g._id);if(C){if(A==="scrollTo")this.host.scrollBy(C.id,(t[0]??0)-C.scrollOffset);else if(A==="scrollToEnd")this.scrollVlistToEnd(C);else if(A==="scrollToKey"){const i=this.vlists.get(C.id),E=i==null?void 0:i.items.get(t[0]),r=E?this.host.getNode(E._id):void 0;r!=null&&r.layoutRect&&this.host.scrollBy(C.id,r.layoutRect.y-C.scrollOffset)}}}scrollVlistToEnd(g){var A;(A=this.host.getScreenOf(g.id))==null||A.applyLayout(this.host.viewport().width,this.host.layoutHeight()),this.host.scrollBy(g.id,Number.MAX_SAFE_INTEGER)}}const he=["opacity","backgroundColor","color","tintColor","overlayColor","transform"],wE=new Set(["backgroundColor","color","tintColor","overlayColor"]),lt=[1,0,0,1,0,0];function FE(e){return e<.5?4*e*e*e:1-Math.pow(-2*e+2,3)/2}function SE(e,g){return Array.isArray(e)&&Array.isArray(g)?e.length===g.length&&e.every((A,t)=>A===g[t]):e===g}const gI=(e,g,A)=>e+(g-e)*A;function RE(e,g,A){const t=(w,h)=>w>>>h&255,C=Math.round(gI(t(e,24),t(g,24),A)),i=Math.round(gI(t(e,16),t(g,16),A)),E=Math.round(gI(t(e,8),t(g,8),A)),r=Math.round(gI(t(e,0),t(g,0),A));return(C<<24|i<<16|E<<8|r)>>>0}function kE(e,g,A,t){return e==="transform"?g.map((C,i)=>gI(C,A[i],t)):wE.has(e)?RE(g,A,t):gI(g,A,t)}function UE(e,g,A){return e==="opacity"?{from:g??1,to:A??1}:e==="transform"?{from:g??lt,to:A??lt}:g===void 0||A===void 0?null:{from:g,to:A}}function pE(e){const g=e>>>0;return{r:g>>>24&255,g:g>>>16&255,b:g>>>8&255,a:g&255}}function Xg(e){return"#"+(e>>>0).toString(16).padStart(8,"0")}function Pg(e){const{r:g,g:A,b:t,a:C}=pE(e);return`rgba(${g}, ${A}, ${t}, ${(C/255).toFixed(4)})`}function Zt(e){return e===void 0||(e>>>0&255)===0}class NE{constructor(g){X(this,"tweens",[]);this.host=g}hasActive(){return this.tweens.length>0}animateTo(g,A){const t=this.host.getNode(g);if(!t)return;const C=this.snapshot(t);this.applyAuthoring(g,A);const i=this.snapshot(t);this.startTween(g,C,i,A==null?void 0:A.duration,A==null?void 0:A.delay)}animateFrom(g,A){const t=this.host.getNode(g);if(!t)return;const C=this.snapshot(t);this.applyAuthoring(g,A);const i=this.snapshot(t);this.applyResolved(g,C),this.startTween(g,i,C,A==null?void 0:A.duration,A==null?void 0:A.delay)}tick(g){if(this.tweens.length===0)return;const A=new Set;for(const t of this.tweens){t.elapsed+=g;const C=this.host.getNode(t.nodeId);if(C){this.applyTweenFrame(t,C);const i=this.host.getScreenOf(t.nodeId);i&&A.add(i)}}this.tweens=this.tweens.filter(t=>t.elapsed<t.delay+t.duration&&this.host.getNode(t.nodeId)!==void 0);for(const t of A)t.markDirty()}snapshot(g){const A={};for(const t of he){const C=g.style[t];A[t]=Array.isArray(C)?[...C]:C}return A}applyAuthoring(g,A){var i;if(!A)return;let t=!1;for(const E of Object.keys(A))E==="duration"||E==="delay"||E==="layer"||E==="commit"||(eI(this.host.layout,g,E,A[E],void 0,this.host.resolveSrc),this.host.isMeasureAffecting(E)&&(t=!0));const C=this.host.getNode(g);(C!=null&&C.measured||t)&&this.host.layout.markDirty(g),(i=this.host.getScreenOf(g))==null||i.markDirty()}applyResolved(g,A){var t;for(const C of he){const i=A[C];i===void 0?this.host.layout.setStyle(g,C,null):C==="opacity"?this.host.layout.setStyle(g,C,i):C==="transform"?this.host.layout.setStyle(g,C,`matrix(${i.join(",")})`):this.host.layout.setStyle(g,C,Xg(i))}(t=this.host.getScreenOf(g))==null||t.markDirty()}startTween(g,A,t,C=225,i=0){var G;const E=[];for(const F of he){const c=UE(F,A[F],t[F]);!c||SE(c.from,c.to)||E.push({key:F,from:c.from,to:c.to})}if(E.length===0)return;const r=new Set(E.map(F=>F.key));for(const F of this.tweens)F.nodeId===g&&(F.props=F.props.filter(c=>!r.has(c.key)));this.tweens=this.tweens.filter(F=>F.props.length>0);const w={nodeId:g,props:E,elapsed:0,duration:Math.max(1,C),delay:Math.max(0,i)};this.tweens.push(w);const h=this.host.getNode(g);h&&this.applyTweenFrame(w,h),(G=this.host.getScreenOf(g))==null||G.markDirty()}applyTweenFrame(g,A){const t=g.elapsed<=g.delay?0:Math.min(1,(g.elapsed-g.delay)/g.duration),C=FE(t);for(const i of g.props)A.style[i.key]=kE(i.key,i.from,i.to,C)}}const mE=60270,ht=60271,KE=.32,de=new Set(["fontSize","fontFamily","fontWeight","fontStyle","lineHeight","letterSpacing","lineClamp","textOverflow"]);class LE{constructor(g,A){X(this,"nodesById",new Map);X(this,"screensById",new Map);X(this,"currentScreen",null);X(this,"widgets",[]);X(this,"nextScreenId",0);X(this,"nextWidgetId",1);X(this,"pressed",new Set);X(this,"focusedInput",null);X(this,"onKeyboard",()=>{});X(this,"router",new GE(g=>this.activateScreen(g),g=>this.freeScreen(g)));X(this,"onRouterChange",null);X(this,"tween");X(this,"vlist");X(this,"width",0);X(this,"height",0);X(this,"safeArea",null);X(this,"safeAreaBars",[]);X(this,"onResize",()=>{});X(this,"resolveSrc",g=>this.host.resolveSrc(g));X(this,"isPressed",g=>this.pressed.has(g.id));X(this,"isFocused",g=>this.focusedInput===g);this.layout=g,this.host=A,g.setStyleSink(this),g.setMeasureCallback((t,C,i,E)=>this.measure(C,i,E)),this.tween=new NE({getNode:t=>this.get(t),getScreenOf:t=>this.getScreenOf(t),layout:this.layout,resolveSrc:this.resolveSrc,isMeasureAffecting:t=>de.has(t)}),this.vlist=new uE({getNode:t=>this.get(t),getScreenOf:t=>this.getScreenOf(t),preloadNew:(t,C)=>this.preloadNew(t,C),scrollBy:(t,C)=>this.scrollBy(t,C),isAtScrollEnd:(t,C)=>this.isAtScrollEnd(t,C),viewport:()=>({width:this.width,height:this.height}),layoutHeight:()=>this.layoutHeight()})}register(g){this.nodesById.set(g.id,g)}unregister(g){var A;this.nodesById.delete(g),this.pressed.delete(g),this.vlist.remove(g),((A=this.focusedInput)==null?void 0:A.id)===g&&(this.focusedInput=null,this.onKeyboard(null))}get(g){return this.nodesById.get(g)}onNodeAdded(g){g.type==="vlist"&&this.vlist.initVlist(g)}getStyle(g,A){var t;return(t=this.nodesById.get(A))==null?void 0:t.style}measure(g,A,t){const C=this.nodesById.get(g);return C?C.type==="text"?aE(C,this.host,A):C.type==="image"?lE(C,this.host,A,t):C.editable?cE(C,this.host,A):{width:0,height:0}:{width:0,height:0}}resize(g,A){g<=0||A<=0||(this.width=g,this.height=A,this.applySafePaddings(),this.layout.setConditionValue(g,A),this.relayout(),this.onResize(g,A),this.focusedInput&&this.emitKeyboard())}layoutHeight(){return this.focusedInput?this.height-this.keyboardRect().height:this.height}relayout(){var A;if(this.width<=0||this.height<=0)return;const g=this.layoutHeight();(A=this.currentScreen)==null||A.applyLayout(this.width,g);for(const t of this.widgets)t.applyLayout(this.width,g)}safeInsets(){return this.safeArea?this.safeArea:this.width>this.height?[0,8,0,20]:[20,0,8,0]}applySafePaddings(){var i;const[g,A,t,C]=this.safeInsets();this.layout.setSafeAreaBars(this.safeAreaBars),this.layout.setSafePaddings(g,A,t,C,(i=this.currentScreen)==null?void 0:i.root.id);for(const E of this.widgets)this.layout.setSafePaddings(g,A,t,C,E.root.id)}setSafeArea(g,A=[]){var t,C;if(this.safeArea=g,this.safeAreaBars=A,!(this.width<=0||this.height<=0)){this.applySafePaddings(),(t=this.currentScreen)==null||t.markDirty(),(C=this.currentScreen)==null||C.applyLayout(this.width,this.layoutHeight());for(const i of this.widgets)i.markDirty(),i.applyLayout(this.width,this.layoutHeight())}}setTheme(g){var A;if(this.layout.setTheme(g)&&!(this.width<=0||this.height<=0)){"fontFamily"in g&&this.invalidateTextMetrics(),(A=this.currentScreen)==null||A.markDirty();for(const t of this.widgets)t.markDirty();this.relayout()}}registerResizeEvent(g){this.onResize=g}invalidateTextMetrics(){for(const g of this.nodesById.values())g.wrapCache=void 0,g.measured&&g.type!=="image"&&this.layout.markDirty(g.id)}registerFont(g,A,t={},C,i){this.host.loadFont(g,A,t).then(()=>{var E;this.invalidateTextMetrics(),(E=this.currentScreen)==null||E.markDirty();for(const r of this.widgets)r.markDirty();C==null||C()}).catch(()=>i==null?void 0:i())}openScreen(g){this.router.show?this.routerHide():this.currentScreen&&this.closeScreen();const A=new le(this.nextScreenId++,g,this.layout,this,!1,this.resolveSrc);this.screensById.set(A.screenId,A),A.mount(),this.currentScreen=A,A.applyLayout(this.width,this.layoutHeight()),this.preloadImages(A),this.vlist.settle(A);for(const t of g.ol??[])t();return A}closeScreen(){const g=this.currentScreen;if(g){for(const A of g.jsNode.cl??[])A();g.destroy(),this.screensById.delete(g.screenId),this.currentScreen=null}}newScreen(g){const A=new le(this.nextScreenId++,g,this.layout,this,!1,this.resolveSrc);return this.screensById.set(A.screenId,A),A.mount(),A}activateScreen(g){var t;const A=this.currentScreen;if(A){for(const C of A.jsNode.cl??[])C();A.deactivate()}this.currentScreen=g,g.applyLayout(this.width,this.layoutHeight()),this.preloadImages(g),this.vlist.settle(g),(t=this.onRouterChange)==null||t.call(this,g.jsNode);for(const C of g.jsNode.ol??[])C();this.focusedInput&&this.blurInput()}freeScreen(g){this.currentScreen===g&&(this.currentScreen=null),g.destroy(),this.screensById.delete(g.screenId)}routerOpen(g,A){if(this.currentScreen){if(!this.router.stack.includes(this.currentScreen)){for(const t of this.currentScreen.jsNode.cl??[])t();this.currentScreen.destroy(),this.screensById.delete(this.currentScreen.screenId)}this.currentScreen=null}for(const t of this.router.stack)t.destroy(),this.screensById.delete(t.screenId);this.router.stack=[],this.onRouterChange=A??null,this.router.init(this.newScreen(g))}routerPush(g){this.router.push(this.newScreen(g))}routerReplace(g){this.router.replace(this.newScreen(g))}routerPop(g){this.router.pop(g)}routerHide(){if(this.router.hide(),this.currentScreen&&this.router.stack.includes(this.currentScreen)){for(const g of this.currentScreen.jsNode.cl??[])g();this.currentScreen.deactivate(),this.currentScreen=null}}routerRestore(){this.router.restore()}showWidget(g){if(this.widgets.some(C=>C.jsNode===g))return;const A=-this.nextWidgetId++,t=new le(A,g,this.layout,this,!0,this.resolveSrc);this.screensById.set(A,t),t.mount(),t.applyLayout(this.width,this.layoutHeight()),this.widgets.push(t),this.preloadImages(t),this.vlist.settle(t);for(const C of g.ol??[])C()}hideWidget(g){if(!g._id)return;const A=this.layout.getScreenId(g._id);if(A>=0)return;const t=this.screensById.get(A);if(t){for(const C of t.jsNode.cl??[])C();t.destroy(),this.screensById.delete(A),this.widgets=this.widgets.filter(C=>C!==t)}}getScreenOf(g){return this.screensById.get(this.layout.getScreenId(g))}preloadSubtree(g,A){const t=C=>{if(C.type==="image"){const E=this.resolveSrc(C.imageSrcRaw);E&&!this.host.getImage(E)&&this.host.loadImage(E).then(()=>{this.layout.markDirty(C.id),A.markDirty()}).catch(()=>{})}const i=C.style.backgroundImage;i&&!this.host.getImage(i)&&this.host.loadImage(i).then(()=>A.markDirty()).catch(()=>{});for(const E of C.children)t(E)};t(g)}preloadImages(g){this.preloadSubtree(g.root,g)}preloadNew(g,A){if(!A)return;const t=g!=null&&g._id?this.nodesById.get(g._id):void 0;t&&this.preloadSubtree(t,A)}insertNode(g,A,t){const C=this.getScreenOf(A);C==null||C.insertNode(A,g,t),this.preloadNew(t,C)}removeNode(g,A){var t;(t=this.getScreenOf(g))==null||t.removeNode(g,A)}setContent(g,A,t){const C=this.getScreenOf(g);C==null||C.setContent(g,A,t);for(const i of t)i&&this.preloadNew(i,C)}updateStyle(g,A,t){var i;eI(this.layout,g,A,t,void 0,this.resolveSrc);const C=this.nodesById.get(g);(C!=null&&C.measured||de.has(A))&&this.layout.markDirty(g),(i=this.getScreenOf(g))==null||i.markDirty()}mergeStyle(g,A){var i;let t=!1;for(const E of Object.keys(A))eI(this.layout,g,E,A[E],void 0,this.resolveSrc),de.has(E)&&(t=!0);const C=this.nodesById.get(g);(C!=null&&C.measured||t)&&this.layout.markDirty(g),(i=this.getScreenOf(g))==null||i.markDirty()}updateNode(g,A,t){var i,E;const C=this.nodesById.get(g);if(C){if(A==="value")C.value=typeof t=="string"?t:String(t??""),this.layout.markDirty(g),(i=this.getScreenOf(g))==null||i.markDirty(),this.focusedInput===C&&this.emitKeyboard();else if(A==="text")this.layout.markDirty(g),(E=this.getScreenOf(g))==null||E.markDirty();else if(A==="src"){const r=t??C.imageSrcRaw,w=this.resolveSrc(r),h=this.getScreenOf(g);w&&!this.host.getImage(w)&&this.host.loadImage(w).then(()=>{this.layout.markDirty(g),h==null||h.markDirty()}).catch(()=>{});const G=xt(r);G!=null&&eI(this.layout,g,"tintColor",G,void 0,this.resolveSrc),this.layout.markDirty(g),h==null||h.markDirty()}}}setSourceRect(g,A,t,C,i){var r;const E=this.nodesById.get(g);E&&(E.sourceRect=[A,t,C,i],this.layout.markDirty(g),(r=this.getScreenOf(g))==null||r.markDirty())}getTextValue(g){var A;return((A=this.nodesById.get(g))==null?void 0:A.value)??""}focusInput(g){var t,C,i,E,r;const A=this.nodesById.get(g);if(!(!A||!A.editable||this.focusedInput===A)){this.focusedInput&&this.unfocus(),this.focusedInput=A,this.toggleLayer(g,ht,!0,(C=(t=A.jsNode)==null?void 0:t._style)==null?void 0:C.onFocused),this.toggleLayer(g,this.layout.getLayer(g,"$focused"),!0,(E=(i=A.jsNode)==null?void 0:i._style)==null?void 0:E.$focused);for(const w of((r=A.jsNode)==null?void 0:r.fl)??[])w();this.relayout(),this.emitKeyboard()}}dismissKeyboardOnTap(){var g,A,t;((t=(A=(g=this.focusedInput)==null?void 0:g.jsNode)==null?void 0:A._style)==null?void 0:t.keyboardDismiss)!==!1&&this.blurInput()}blurInput(){this.focusedInput&&(this.unfocus(),this.relayout(),this.emitKeyboard())}submitInput(){var t,C,i;const g=this.focusedInput;if(!g)return!1;const A=g.value;for(const E of((t=g.jsNode)==null?void 0:t.sl)??[])E(A);return this.focusedInput===g&&((i=(C=g.jsNode)==null?void 0:C._style)==null?void 0:i.enterKey)!=="next"&&this.blurInput(),!0}unfocus(){var A,t,C,i,E;const g=this.focusedInput;if(g){this.toggleLayer(g.id,ht,!1,(t=(A=g.jsNode)==null?void 0:A._style)==null?void 0:t.onFocused),this.toggleLayer(g.id,this.layout.getLayer(g.id,"$focused"),!1,(i=(C=g.jsNode)==null?void 0:C._style)==null?void 0:i.$focused);for(const r of((E=g.jsNode)==null?void 0:E.bl)??[])r();this.focusedInput=null}}setInputValue(g,A){var C,i;const t=this.nodesById.get(g);if(t){t.value=A;for(const E of((C=t.jsNode)==null?void 0:C.cl)??[])E(A);this.layout.markDirty(g),(i=this.getScreenOf(g))==null||i.markDirty()}}keyboard(){const g=this.focusedInput;return g?{rect:this.keyboardRect(),input:{nodeId:g.id,rect:this.findRect(g.id)??{x:0,y:0,width:0,height:0},value:g.value,type:g.style.inputType??"text"}}:null}uiTransform(){return null}registerKeyboardEvent(g){this.onKeyboard=g}keyboardRect(){const g=Math.round(this.height*KE);return{x:0,y:this.height-g,width:this.width,height:g}}emitKeyboard(){this.onKeyboard(this.keyboard())}findRect(g){const A=C=>{if(!C)return null;if(C.id===g)return C.rect;for(const i of C.children){const E=A(i);if(E)return E}return null},t=A(this.renderTree());if(t)return t;for(const C of this.widgetTrees()){const i=A(C);if(i)return i}return null}isButtonPressed(g){return this.pressed.has(g)}getBoundingClientRect(g){const A=this.findRect(g);return A?[A.x,A.y,A.width,A.height]:null}renderTree(){return this.currentScreen?this.currentScreen.renderTree(this.host,this.isPressed,this.isFocused):null}needsPaint(){var g;if(this.tween.hasActive()||(g=this.currentScreen)!=null&&g.isDirty())return!0;for(const A of this.widgets)if(A.isDirty())return!0;return!1}frame(){const g=[],A=this.renderTree();A&&g.push({tree:A});for(const t of this.widgets){const C=t.renderTree(this.host,this.isPressed,this.isFocused),i=C.style.overlayColor;g.push({tree:C,widget:!0,backdrop:i!==void 0?{color:i,jsNode:t.jsNode}:void 0})}return g}widgetTrees(){return this.widgets.map(g=>g.renderTree(this.host,this.isPressed,this.isFocused))}findAllByName(g){const A=[],t=i=>{i.name===g&&A.push(i);for(const E of i.children)t(E)},C=this.renderTree();C&&t(C);for(const i of this.widgetTrees())t(i);return A}findByName(g){return this.findAllByName(g)[0]??null}animateTo(g,A){this.tween.animateTo(g,A)}animateFrom(g,A){this.tween.animateFrom(g,A)}tick(g){this.tween.tick(g)}hasActiveAnimations(){return this.tween.hasActive()}vlistMount(g,A,t){this.vlist.vlistMount(g,A,t)}vlistSetKeys(g,A,t){this.vlist.vlistSetKeys(g,A,t)}vlistInsertKeys(g,A,t,C){this.vlist.vlistInsertKeys(g,A,t,C)}vlistRemoveKeys(g,A){this.vlist.vlistRemoveKeys(g,A)}vlistInvalidate(g,A){this.vlist.vlistInvalidate(g,A)}command(g,A,...t){if((g==null?void 0:g.type)==="pager"&&g._id){const C=this.getScreenOf(g._id);C!=null&&C.pagerReconcile(g)&&(this.preloadImages(C),this.vlist.settle(C));return}this.vlist.command(g,A,...t)}scrollViewport(g){var t,C,i;const A=g===((t=this.currentScreen)==null?void 0:t.root);return g.scrollAxis==="x"?A?this.width:((C=g.layoutRect)==null?void 0:C.width)??0:A?this.height:((i=g.layoutRect)==null?void 0:i.height)??0}scrollMax(g){const A=g.scrollAxis==="x"?this.layout.getContentWidth(g.id):this.layout.getContentHeight(g.id);return Math.max(0,A-this.scrollViewport(g))}isAtScrollEnd(g,A=1){return g.scrollOffset>=this.scrollMax(g)-A}scrollBy(g,A){var h,G,F;const t=this.nodesById.get(g);if(!t||!t.scrollable)return!1;const C=this.scrollMax(t),i=t.scrollOffset+A,E=Math.min(C,Math.max(0,i)),r=i<0?i:i>C?i-C:0;if(r!==0){const c=(h=t.jsNode)==null?void 0:h.osl;if(Array.isArray(c)&&c.length)for(const U of c)U(r)}if(E===t.scrollOffset)return!1;t.scrollOffset=E,(G=this.getScreenOf(g))==null||G.markDirty();const w=(F=t.jsNode)==null?void 0:F.sl;if(Array.isArray(w))for(const c of w)c(E);return t.type==="vlist"&&this.vlist.checkEdges(t,E,C),!0}toggleLayer(g,A,t,C){var G,F;const i=this.nodesById.get(g);if(!i)return;const E=typeof(C==null?void 0:C.duration)=="number"?C.duration:0,r=()=>{i.measured&&this.layout.markDirty(g)};if(E<=0){t?this.layout.enableNodeLayer(g,A):this.layout.disableNodeLayer(g,A),r(),(G=this.getScreenOf(g))==null||G.markDirty();return}const w=this.tween.snapshot(i);t?this.layout.enableNodeLayer(g,A):this.layout.disableNodeLayer(g,A);const h=this.tween.snapshot(i);r(),this.tween.startTween(g,w,h,E,typeof(C==null?void 0:C.delay)=="number"?C.delay:0),(F=this.getScreenOf(g))==null||F.markDirty()}setPressed(g,A){var C,i,E;A?this.pressed.add(g):this.pressed.delete(g);const t=(C=this.nodesById.get(g))==null?void 0:C.jsNode;this.toggleLayer(g,mE,A,(i=t==null?void 0:t._style)==null?void 0:i.onPressed),this.toggleLayer(g,this.layout.getLayer(g,"$pressed"),A,(E=t==null?void 0:t._style)==null?void 0:E.$pressed)}setClass(g,A,t){var E,r;const C=this.nodesById.get(g);if(!C)return;const i=this.layout.getLayer(g,"$"+A);this.toggleLayer(g,i,t,(r=(E=C.jsNode)==null?void 0:E._style)==null?void 0:r["$"+A])}hitTestNode(g){return this.nodesById.get(g)}get screen(){return this.currentScreen}get viewport(){return{width:this.width,height:this.height}}}const bE=["farthest-corner","closest-side","closest-corner","farthest-side"],ME=52;function vE(e,g,A,t){const C=[];for(let i=0;i<t;i++)C.push(JE(e,g,A+i*ME));return C}function JE(e,g,A){const t=A>>2,C=e[t],i=g[t+1],E=g[t+2],r=g[t+4],w=[];for(let h=0;h<E;h++){const G=r+h*8>>2;w.push({color:g[G]>>>0,position:e[G+1]})}if(i===1){const h=g[t+6],G={type:"radial",shape:g[t+5]===1?"circle":"ellipse",cx:e[t+7],cy:e[t+8],stops:w};return h===4?{...G,extent:"explicit",rx:e[t+9],ry:e[t+10],rxUnit:g[t+11]===1?"fraction":"px",ryUnit:g[t+12]===1?"fraction":"px"}:{...G,extent:bE[h]??"farthest-corner"}}return{type:"linear",angle:C,stops:w}}const dt={display:{channel:"string",hostReset:!1,nodes:"all"},overflow:{channel:"string",hostReset:!1,nodes:"all"},scrollDirection:{channel:"float",hostReset:!1,nodes:["scrollable"]},borderWidth:{channel:"float",hostReset:!1,nodes:"all"},borderTopWidth:{channel:"float",hostReset:!1,nodes:"all"},borderRightWidth:{channel:"float",hostReset:!1,nodes:"all"},borderBottomWidth:{channel:"float",hostReset:!1,nodes:"all"},borderLeftWidth:{channel:"float",hostReset:!1,nodes:"all"},borderHorizontalWidth:{channel:"float",hostReset:!1,nodes:"all"},borderVerticalWidth:{channel:"float",hostReset:!1,nodes:"all"},borderStartWidth:{channel:"float",hostReset:!1,nodes:"all"},borderEndWidth:{channel:"float",hostReset:!1,nodes:"all"},color:{channel:"uint",hostReset:!0,nodes:"all"},backgroundColor:{channel:"uint",hostReset:!1,nodes:"all"},borderColor:{channel:"uint",hostReset:!1,nodes:"all"},borderTopColor:{channel:"uint",hostReset:!1,nodes:"all"},borderRightColor:{channel:"uint",hostReset:!1,nodes:"all"},borderBottomColor:{channel:"uint",hostReset:!1,nodes:"all"},borderLeftColor:{channel:"uint",hostReset:!1,nodes:"all"},placeholderColor:{channel:"uint",hostReset:!0,nodes:["input"]},refreshControlColor:{channel:"uint",hostReset:!0,nodes:["scrollable"]},tintColor:{channel:"uint",hostReset:!0,nodes:["image"]},rippleColor:{channel:"uint",hostReset:!1,nodes:["button"]},overlayColor:{channel:"uint",hostReset:!0,nodes:["widget"]},backgroundImage:{channel:"string",hostReset:!1,nodes:"all"},backgroundSize:{channel:"string",hostReset:!1,nodes:"all"},backgroundGradientStr:{channel:"string",hostReset:!1,nodes:"all"},borderRadius:{channel:"float",hostReset:!1,nodes:"all"},borderTopLeftRadius:{channel:"float",hostReset:!1,nodes:"all"},borderTopRightRadius:{channel:"float",hostReset:!1,nodes:"all"},borderBottomRightRadius:{channel:"float",hostReset:!1,nodes:"all"},borderBottomLeftRadius:{channel:"float",hostReset:!1,nodes:"all"},opacity:{channel:"float",hostReset:!1,nodes:"all"},pointerEvents:{channel:"string",hostReset:!1,nodes:"all"},fontSize:{channel:"float",hostReset:!1,nodes:["text","input"]},fontWeight:{channel:"float",hostReset:!1,nodes:["text","input"]},fontStyle:{channel:"float",hostReset:!1,nodes:["text","input"]},fontFamily:{channel:"string",hostReset:!0,nodes:["text","input"]},lineHeight:{channel:"float",hostReset:!1,nodes:["text","input"]},letterSpacing:{channel:"float",hostReset:!1,nodes:["text","input"]},textAlign:{channel:"string",hostReset:!1,nodes:["text","input"]},textDecoration:{channel:"string",hostReset:!1,nodes:["text"]},lineClamp:{channel:"float",hostReset:!1,nodes:["text"]},textOverflow:{channel:"string",hostReset:!1,nodes:["text"]},objectFit:{channel:"string",hostReset:!1,nodes:["image","video"]},placeholder:{channel:"string",hostReset:!1,nodes:["input"]},type:{channel:"string",hostReset:!1,nodes:["input"]},enterKey:{channel:"string",hostReset:!1,nodes:["input"]},autocapitalize:{channel:"string",hostReset:!1,nodes:["input"]},autocorrect:{channel:"float",hostReset:!1,nodes:["input"]},maxLength:{channel:"float",hostReset:!1,nodes:["input"]},keyboardShrink:{channel:"float",hostReset:!1,nodes:["input"]},keyboardDismiss:{channel:"float",hostReset:!1,nodes:["input"]},showScrollbar:{channel:"float",hostReset:!1,nodes:["scrollable"]},overscrollMode:{channel:"string",hostReset:!1,nodes:["scrollable"]},keyboardDismissMode:{channel:"string",hostReset:!1,nodes:["scrollable","vlist"]},snap:{channel:"string",hostReset:!1,nodes:["scrollable"]},sheetDetents:{channel:"string",hostReset:!1,nodes:["widget"]},sheetDetent:{channel:"float",hostReset:!1,nodes:["widget"]},sheetDismissible:{channel:"float",hostReset:!1,nodes:["widget"]}},Vt=e=>e.toLowerCase();function NI(e,g){var A;return e.border??(e.border={}),(A=e.border)[g]??(A[g]={width:0,color:0})}function HE(e){return e.borderRadius??(e.borderRadius={tl:0,tr:0,br:0,bl:0})}const aI=e=>({set(g,A){if(e==="")for(const t of["top","right","bottom","left"])NI(g,t).width=A;else NI(g,Vt(e)).width=A}}),cI=e=>({set(g,A){if(e==="")for(const t of["top","right","bottom","left"])NI(g,t).color=A;else NI(g,Vt(e)).color=A}}),YE={TopLeft:"tl",TopRight:"tr",BottomRight:"br",BottomLeft:"bl"},FI=e=>({set(g,A){HE(g)[YE[e]]=A}}),xE={display:{set:(e,g)=>e.display=g},overflow:{set:(e,g)=>e.overflow=g},scrollDirection:{set:(e,g)=>e.scrollAxis=g===2?"x":"y"},showScrollbar:"unsupported",overscrollMode:"unsupported",keyboardDismissMode:"unsupported",snap:"unsupported",refreshControlColor:"unsupported",borderWidth:aI(""),borderTopWidth:aI("Top"),borderRightWidth:aI("Right"),borderBottomWidth:aI("Bottom"),borderLeftWidth:aI("Left"),borderHorizontalWidth:"unsupported",borderVerticalWidth:"unsupported",borderStartWidth:"unsupported",borderEndWidth:"unsupported",borderColor:cI(""),borderTopColor:cI("Top"),borderRightColor:cI("Right"),borderBottomColor:cI("Bottom"),borderLeftColor:cI("Left"),borderRadius:{set:(e,g)=>e.borderRadius={tl:g,tr:g,br:g,bl:g}},borderTopLeftRadius:FI("TopLeft"),borderTopRightRadius:FI("TopRight"),borderBottomRightRadius:FI("BottomRight"),borderBottomLeftRadius:FI("BottomLeft"),color:{set:(e,g)=>e.color=g>>>0,reset:e=>e.color=void 0},fontFamily:{set:(e,g)=>e.fontFamily=g,reset:e=>e.fontFamily=void 0},fontSize:{set:(e,g)=>e.fontSize=g},fontWeight:{set:(e,g)=>e.fontWeight=g},fontStyle:{set:(e,g)=>e.fontStyle=g===2?"italic":"normal"},lineHeight:{set:(e,g)=>e.lineHeight=g},letterSpacing:{set:(e,g)=>e.letterSpacing=g},textAlign:{set:(e,g)=>e.textAlign=TE(g)},textDecoration:{set:(e,g)=>e.textDecoration=g},lineClamp:{set:(e,g)=>e.lineClamp=g},textOverflow:{set:(e,g)=>e.textOverflow=g},backgroundColor:{set:(e,g)=>e.backgroundColor=g>>>0},backgroundImage:{set:(e,g)=>e.backgroundImage=g||void 0},backgroundSize:{set:(e,g)=>e.backgroundSize=g},backgroundGradientStr:"unsupported",rippleColor:"unsupported",opacity:{set:(e,g)=>e.opacity=g},pointerEvents:"unsupported",objectFit:{set:(e,g)=>e.objectFit=g},tintColor:{set:(e,g)=>e.tintColor=g>>>0,reset:e=>e.tintColor=void 0},placeholder:{set:(e,g)=>e.placeholder=g},placeholderColor:{set:(e,g)=>e.placeholderColor=g>>>0,reset:e=>e.placeholderColor=void 0},type:{set:(e,g)=>e.inputType=g},enterKey:"unsupported",autocapitalize:"unsupported",autocorrect:"unsupported",maxLength:"unsupported",keyboardShrink:"unsupported",keyboardDismiss:"unsupported",overlayColor:{set:(e,g)=>e.overlayColor=g>>>0,reset:e=>e.overlayColor=void 0},sheetDetents:"unsupported",sheetDetent:"unsupported",sheetDismissible:"unsupported"};function qE(e,g){const A=(r,w)=>{const h=r.length+1,G=e._malloc(h);e.stringToUTF8(r,G,h),w(G),e._free(G)},t=[];for(const r of Object.keys(dt)){const w=xE[r];if(w==="unsupported"){t.push(r);continue}const{channel:h}=dt[r];A(r,G=>{if(h==="string"){const F=e.addFunction((c,U,y)=>{const l=g.getStyle(c,U);l&&w.set(l,e.UTF8ToString(y))},"viii");e._addStringHandler(G,F)}else if(h==="uint"){const F=e.addFunction((c,U,y)=>{const l=g.getStyle(c,U);l&&w.set(l,y>>>0)},"viii");e._addUIntHandler(G,F)}else{const F=e.addFunction((c,U,y)=>{const l=g.getStyle(c,U);l&&w.set(l,y)},"viif");e._addFloatHandler(G,F)}if(w.reset){const F=e.addFunction((c,U)=>{const y=g.getStyle(c,U);y&&w.reset(y)},"vii");e._addResetHandler(G,F)}})}const C=e.addFunction((r,w,h,G)=>{const F=g.getStyle(r,w);F&&(F.backgroundGradients=h===0||G===0?void 0:vE(e.HEAPF32,e.HEAPU32,h,G))},"viiii");e._setGradientsHandler(C),A("backgroundGradient",r=>{const w=e.addFunction((h,G)=>{const F=g.getStyle(h,G);F&&(F.backgroundGradients=void 0)},"vii");e._addResetHandler(r,w)});const i=e.addFunction((r,w,h)=>{const G=g.getStyle(r,w);if(!G)return;const F=h>>2,c=e.HEAPF32,U=c[F],y=c[F+1],l=c[F+3],D=c[F+4],R=c[F+6],L=c[F+7],O=U===1&&y===0&&l===0&&D===1&&R===0&&L===0;G.transform=O?void 0:[U,y,l,D,R,L]},"viii");e._setMatrixHandler(i);const E=e.addFunction((r,w,h,G,F,c)=>{const U=g.getStyle(r,w);if(!U)return;const y=F&&c&&h===50&&G===50;U.transformOrigin=y?void 0:{x:h,y:G,xPercent:!!F,yPercent:!!c}},"viiffii");return e._setTransformOriginHandler(E),{unsupported:t}}function TE(e){return e==="center"?"center":e==="end"||e==="right"?"end":"start"}const _E=256;class HI{constructor(g){X(this,"module");X(this,"layoutPtr");X(this,"paddingPtr");X(this,"keyCache",new Map);X(this,"packView",new DataView(new ArrayBuffer(8)));X(this,"measureCb",null);this.module=g,this.layoutPtr=g._malloc(16),this.paddingPtr=g._malloc(16)}static async create(){const{loadCreatorUiNode:g}=await II(async()=>{const{loadCreatorUiNode:A}=await import("./assets/loadCreatorUiNode-UAdhjRTd.js");return{loadCreatorUiNode:A}},[],import.meta.url);return new HI(await g())}internKey(g){let A=this.keyCache.get(g);if(A===void 0){const t=g.length+1;A=this.module._malloc(t),this.module.stringToUTF8(g,A,t),this.keyCache.set(g,A)}return A}setTheme(g){for(const A of Object.keys(g)){const t=g[A],C=t==null?null:typeof t=="number"?`${t}px`:t,i=this.internKey(A);let E=0;if(C!==null){const r=this.module.lengthBytesUTF8(C)+1;E=this.module._malloc(r),this.module.stringToUTF8(C,E,r)}this.module._setThemeValue(i,E),E&&this.module._free(E)}return this.module._applyTheme()!==0}setStyleSink(g){qE(this.module,g)}setMeasureCallback(g){this.measureCb=g;const A=this.packView,t=(i,E,r,w,h,G)=>{var c;const F=((c=this.measureCb)==null?void 0:c.call(this,i,E,r,h))??{width:0,height:0};return A.setFloat32(4,F.width,!0),A.setFloat32(0,F.height,!0),A.getBigUint64(0,!0)},C=this.module.addFunction(t,"jiififi");this.module._setMeasureFunc(C)}createRoot(g){return this.module._createNodeRoot(g)}createChild(g,A,t){return this.module._createNode(g,A,t?1:0)}removeChild(g,A){this.module._removeNode(g,A)}freeTree(g,A){A?this.module._freeWidget(g):this.module._freeNode(g)}setStyle(g,A,t,C=_E){const i=this.internKey(A);if(t===null)this.module._resetPropExt(C,g,i);else if(typeof t=="number")this.module._setFloatExt(C,g,i,t);else if(typeof t=="boolean")this.module._setFloatExt(C,g,i,t?1:0);else{const E=this.module.lengthBytesUTF8(t)+1,r=this.module._malloc(E);this.module.stringToUTF8(t,r,E),this.module._setStringExt(C,g,i,r),this.module._free(r)}}markDirty(g){this.module._markNodeDirty(g)}getLayer(g,A){return this.module._getLayer(g,this.internKey(A))}enableNodeLayer(g,A){this.module._enableNodeLayer(g,A)}disableNodeLayer(g,A){this.module._disableNodeLayer(g,A)}calculate(g,A,t,C){C?this.module._calculateWidget(g,A,t):this.module._calculate(g,A,t)}getLayout(g){if(!this.module._getLayoutPointer(g,this.layoutPtr))return null;const A=this.layoutPtr>>2,t=this.module.HEAPF32;return{x:t[A],y:t[A+1],width:t[A+2],height:t[A+3]}}getPadding(g){this.module._getPaddingPointer(g,this.paddingPtr);const A=this.paddingPtr>>2,t=this.module.HEAPF32;return[t[A],t[A+1],t[A+2],t[A+3]]}getScreenId(g){return this.module._getScreenId(g)}getContentHeight(g){return this.module._getContentHeight(g)}getContentWidth(g){return this.module._getContentWidth(g)}setConditionValue(g,A){this.module._setConditionValue(g,A)}setSafePaddings(g,A,t,C,i){i!==void 0?this.module._setSafePaddings(g,A,t,C,i):this.module._setSafePaddings(g,A,t,C)}setSafeAreaBars(g){const A={top:1,right:2,bottom:4,left:8};this.module._setSafeAreaBars(g.reduce((t,C)=>t|A[C],0))}}function mI(e,g){if(!g)return;const A=QE(e);if(A===void 0)return;const t=g.getSurface(A);if(t)return{src:e,naturalWidth:t.width,naturalHeight:t.height,handle:t.canvas}}class WE{constructor(g={}){X(this,"factor");X(this,"images",new Map);X(this,"canvasSurfaces");X(this,"resolver",qt());this.factor=g.charWidthFactor??.5,this.canvasSurfaces=g.canvasSurfaces;for(const[A,t]of Object.entries(g.images??{}))this.images.set(A,{src:A,naturalWidth:t.width,naturalHeight:t.height})}setImageSize(g,A,t){this.images.set(g,{src:g,naturalWidth:A,naturalHeight:t})}measureText(g,A){return g.length===0?0:g.length*(A.size*this.factor+A.letterSpacing)}fontMetrics(g){return{ascent:g.size*.8,descent:g.size*.2}}getImage(g){return mI(g,this.canvasSurfaces)??this.images.get(g)}loadImage(g){return Promise.resolve(mI(g,this.canvasSurfaces)??this.images.get(g)??{src:g,naturalWidth:0,naturalHeight:0})}loadFont(){return Promise.resolve()}resolveSrc(g){return this.resolver(g)}}function ZE(e,g,A){const t=e.rect;return g>=t.x&&g<t.x+t.width&&A>=t.y&&A<t.y+t.height}function SI(e,g,A,t){let C=null;const i=E=>{const r=ZE(E,g,A);if(r&&t(E)&&(C=E),!(E.clip&&!r))for(const w of E.children)i(w)};return i(e),C}const VE=4,yt=e=>g=>{var A;return((A=e.get(g.id))==null?void 0:A.interactive)??!1},OE=e=>{if(!e.scroll)return!1;const g=e.scroll.axis==="x"?e.rect.width:e.rect.height;return e.scroll.content>g+.5};function PE(e,g,A){return e>=A.x&&e<A.x+A.width&&g>=A.y&&g<A.y+A.height}class XE{constructor(g){X(this,"tracks",new Map);X(this,"onTouchStart",null);X(this,"onTouchEnd",null);X(this,"creator",null);X(this,"scenePointer",null);this.renderer=g}setScenePointer(g){this.scenePointer=g}topInteractive(g,A){const t=this.renderer.frame(),C=yt(this.renderer);for(let i=t.length-1;i>=0;i--){const E=SI(t[i].tree,g,A,C);if(E)return E.id;if(t[i].backdrop)return null}return null}registerTouchStartEvent(g){this.onTouchStart=g}registerTouchEndEvent(g){this.onTouchEnd=g}setCreator(g){this.creator=g}raycast(g,A){var t,C;return((C=(t=this.creator)==null?void 0:t._raycastView)==null?void 0:C.call(t,g,A))??0}toUi(g,A){const t=this.renderer.uiTransform();return t?[(g-t.tx)/t.scale,(A-t.ty)/t.scale]:[g,A]}pointerDown(g,A,t){var G,F,c;const[C,i]=this.toUi(A,t),E=this.renderer.frame(),r=yt(this.renderer),w=U=>{var y;return((y=this.renderer.get(U.id))==null?void 0:y.editable)??!1};for(let U=E.length-1;U>=0;U--){const y=SI(E[U].tree,C,i,w);if(y)return this.renderer.focusInput(y.id),this.start(g,C,i,{handler:{},node:null,scrollId:null,backdrop:null,dismiss:!1});if(E[U].backdrop)break}for(let U=E.length-1;U>=0;U--){const y=E[U],l=SI(y.tree,C,i,r),D=SI(y.tree,C,i,OE);if(l){const R=this.renderer.get(l.id).jsNode;this.renderer.setPressed(l.id,!0);const L=((G=R._emitTouchStart)==null?void 0:G.call(R,g,C,i))??{},O=R.type!=="button";return this.start(g,C,i,{handler:L,node:R,scrollId:(D==null?void 0:D.id)??null,backdrop:null,dismiss:O})}if(D)return this.start(g,C,i,{handler:{},node:null,scrollId:D.id,backdrop:null,dismiss:!0});if(y.backdrop){const R=!PE(C,i,y.tree.rect);return this.start(g,C,i,{handler:{},node:null,scrollId:null,backdrop:R?y.backdrop.jsNode:null,dismiss:!0})}}const h=((F=this.onTouchStart)==null?void 0:F.call(this,g,C,i,this.raycast(C,i)))??{};this.start(g,C,i,{handler:h,node:null,scrollId:null,backdrop:null,dismiss:!0,scene:!0}),(c=this.scenePointer)==null||c.call(this,0,g,C,i)}start(g,A,t,C){this.tracks.set(g,{...C,lastX:A,lastY:t,acc:0,scrolling:!1})}pointerMove(g,A,t){var h,G,F,c;const C=this.tracks.get(g);if(!C)return;const[i,E]=this.toUi(A,t),r=i-C.lastX,w=E-C.lastY;if(C.lastX=i,C.lastY=E,C.acc+=Math.abs(r)+Math.abs(w),!C.scrolling&&C.scrollId!==null&&C.acc>VE&&(C.scrolling=!0,C.node&&this.renderer.setPressed(C.node._id,!1)),C.scrolling){const U=((h=this.renderer.get(C.scrollId))==null?void 0:h.scrollAxis)==="x";this.renderer.scrollBy(C.scrollId,U?-r:-w);return}(F=(G=C.handler).onMove)==null||F.call(G,{clientX:i,clientY:E,deltaX:r,deltaY:w}),C.scene&&((c=this.scenePointer)==null||c.call(this,1,g,i,E))}pointerUp(g,A,t){var h,G,F,c,U,y,l,D;const C=this.tracks.get(g);if(!C)return;const[i,E]=this.toUi(A,t);this.tracks.delete(g);const r=i-C.lastX,w=E-C.lastY;if((G=(h=C.handler).onEnd)==null||G.call(h,{clientX:i,clientY:E,deltaX:r,deltaY:w}),C.scrolling&&C.scrollId!==null){const R=(c=(F=this.renderer.get(C.scrollId))==null?void 0:F.jsNode)==null?void 0:c.srl;if(Array.isArray(R))for(const L of R)L()}if(C.dismiss&&!C.scrolling&&this.renderer.dismissKeyboardOnTap(),C.node)this.renderer.setPressed(C.node._id,!1),!C.scrolling&&this.topInteractive(i,E)===C.node._id&&((y=(U=C.node)._emitClick)==null||y.call(U,g,i,E));else if(C.backdrop){if(!C.scrolling)for(const R of C.backdrop.otl??[])R()}else C.scrolling||(l=this.onTouchEnd)==null||l.call(this,g,i,E,this.raycast(i,E));C.scene&&((D=this.scenePointer)==null||D.call(this,2,g,i,E))}}function Se(e,g){if(!e)return;const A=Math.min(g.width,g.height)/2;return{tl:Math.min(e.tl,A),tr:Math.min(e.tr,A),br:Math.min(e.br,A),bl:Math.min(e.bl,A)}}function Dt(e){return!!e&&(e.tl>0||e.tr>0||e.br>0||e.bl>0)}function jE(e,g,A,t){const C={x:0,y:0,width:e,height:g};if(t==="fill"||e===0||g===0)return{src:C,dst:A};if(t==="cover"){const w=Math.max(A.width/e,A.height/g),h=A.width/w,G=A.height/w;return{src:{x:(e-h)/2,y:(g-G)/2,width:h,height:G},dst:A}}const i=Math.min(A.width/e,A.height/g),E=e*i,r=g*i;return{src:C,dst:{x:A.x+(A.width-E)/2,y:A.y+(A.height-r)/2,width:E,height:r}}}function zE(e,g){const A=e*Math.PI/180,t=Math.sin(A),C=-Math.cos(A),i=g.x+g.width/2,E=g.y+g.height/2,r=(Math.abs(g.width*t)+Math.abs(g.height*C))/2;return{x0:i-t*r,y0:E-C*r,x1:i+t*r,y1:E+C*r}}function $E(e,g){const A=g.x+e.cx*g.width,t=g.y+e.cy*g.height;if(e.extent==="explicit"){const y=e.rxUnit==="fraction"?(e.rx??0)*g.width:e.rx??0,l=e.ryUnit==="fraction"?(e.ry??0)*g.height:e.ry??0;return{cx:A,cy:t,rx:y,ry:l}}const C=e.cx*g.width,i=(1-e.cx)*g.width,E=e.cy*g.height,r=(1-e.cy)*g.height,w=Math.min(C,i),h=Math.max(C,i),G=Math.min(E,r),F=Math.max(E,r);let c,U;if(e.shape==="circle"){let y;switch(e.extent){case"closest-side":y=Math.min(w,G);break;case"farthest-side":y=Math.max(h,F);break;case"closest-corner":y=Math.hypot(w,G);break;default:y=Math.hypot(h,F);break}c=U=y}else switch(e.extent){case"closest-side":c=w,U=G;break;case"farthest-side":c=h,U=F;break;case"closest-corner":c=w*Math.SQRT2,U=G*Math.SQRT2;break;default:c=h*Math.SQRT2,U=F*Math.SQRT2;break}return{cx:A,cy:t,rx:c,ry:U}}function Ar(e,g,A,t,C,i){g.beginFrame(t,C);const E=e.filter(r=>r.widget);for(const r of e)r.widget||Re(r.tree,g,A);for(const r of E)r.backdrop&&g.fillRoundRect({x:0,y:0,width:t,height:C},void 0,r.backdrop.color);for(const r of E)Re(r.tree,g,A);g.endFrame()}function Re(e,g,A){const{style:t,rect:C}=e;g.save();const i=t.opacity!==void 0&&t.opacity<1?t.opacity:void 0,E=i!==void 0&&e.children.length>0;if(E?g.beginGroup(i):i!==void 0&&g.setAlpha(i),t.transform){const[h,G,F,c,U,y]=t.transform,l=t.transformOrigin,D=C.x+(l?l.xPercent?C.width*l.x/100:l.x:C.width/2),R=C.y+(l?l.yPercent?C.height*l.y/100:l.y:C.height/2);g.translate(D,R),g.transform(h,G,F,c,U,y),g.translate(-D,-R)}const r=Se(t.borderRadius,C);if(Zt(t.backgroundColor)||g.fillRoundRect(C,r,t.backgroundColor),t.backgroundImage){const h=A.getImage(t.backgroundImage);h&&h.naturalWidth>0&&h.naturalHeight>0&&(g.save(),Dt(r)&&g.clipRoundRect(C,r),g.drawImage(h,null,C,{fit:gr(t.backgroundSize)}),g.restore())}if(t.backgroundGradients)for(let h=t.backgroundGradients.length-1;h>=0;h--){const G=t.backgroundGradients[h];G.stops.length>0&&g.fillGradient(C,r,G)}if(e.image&&e.image.naturalWidth>0&&e.image.naturalHeight>0){const h=e.sourceRect;g.save(),Dt(r)&&g.clipRoundRect(C,r),g.drawImage(e.image,h?{x:h[0],y:h[1],width:h[2],height:h[3]}:null,C,{fit:h?"fill":t.objectFit??"contain",tint:JI(e.image.src)?t.tintColor:void 0,radius:r}),g.restore()}e.type==="text"&&e.lines&&e.lines.length>0&&er(e,g,A),(e.type==="input"||e.type==="textarea")&&Br(e,g,A,r),e.type==="video"&&tr(e,g,A,r),e.clip&&g.clipRoundRect(C,r);for(const h of e.children)Re(h,g,A);const w=Ir(t.border);w&&g.strokeBorder(C,r,w),E&&g.endGroup(),g.restore()}function gr(e){return e==="contain"?"contain":"cover"}function Ir(e){if(!e)return null;const g={};let A=!1;for(const t of["top","right","bottom","left"]){const C=e[t];C&&C.width>0&&(C.color>>>0)%256!==0&&(g[t]=C,A=!0)}return A?g:null}const Ot=(e,g)=>{var t;const A=g??"Roboto";return((t=e.resolveFontFamily)==null?void 0:t.call(e,A))??A};function er(e,g,A){var D,R,L;const t=e.style,C={family:Ot(A,t.fontFamily),size:t.fontSize??14,weight:t.fontWeight??400,italic:t.fontStyle==="italic",letterSpacing:t.letterSpacing??0},i=t.color??255,E=t.lineHeight??C.size*1.2,r=t.textAlign??"start",w=A.fontMetrics(C),{rect:h,lines:G}=e,F=((D=e.padding)==null?void 0:D[0])??0,c=((R=e.padding)==null?void 0:R[1])??0,U=((L=e.padding)==null?void 0:L[2])??0,y=h.x+F,l=h.width-F-U;for(let O=0;O<G.length;O++){const q=G[O],b=h.y+c+O*E+(E-(w.ascent+w.descent))/2+w.ascent,T=A.measureText(q,C),Y=r==="center"?y+(l-T)/2:r==="end"?y+l-T:y;if(g.fillText(q,Y,b,C,i),t.textDecoration==="underline"||t.textDecoration==="line-through"){const z=Math.max(1,C.size/14),gA=t.textDecoration==="underline"?b+z:b-C.size*.3;g.fillRoundRect({x:Y,y:gA,width:T,height:z},void 0,i)}}}function tr(e,g,A,t){const{rect:C}=e;Zt(e.style.backgroundColor)&&g.fillRoundRect(C,t,286463999);const i=Math.min(C.width,C.height)*.3;if(i>=6){const E={family:"Roboto",size:i,weight:400,italic:!1,letterSpacing:0},r=A.fontMetrics(E),w=A.measureText("▶",E),h=C.x+(C.width-w)/2,G=C.y+(C.height-(r.ascent+r.descent))/2+r.ascent;g.fillText("▶",h,G,E,4294967244)}}function Br(e,g,A,t){var EA,iA,lA,DA,a;const C=e.style,i={family:Ot(A,C.fontFamily),size:C.fontSize??14,weight:C.fontWeight??400,italic:C.fontStyle==="italic",letterSpacing:C.letterSpacing??0},E=e.value??"",r=E.length===0,w=C.inputType==="password"&&!r,h=r?C.placeholder??"":w?"•".repeat(E.length):E,G=r?C.placeholderColor??2576980479:C.color??255,{rect:F}=e,c=((EA=e.padding)==null?void 0:EA[0])??0,U=((iA=e.padding)==null?void 0:iA[1])??0,y=((lA=e.padding)==null?void 0:lA[2])??0,l=((DA=e.padding)==null?void 0:DA[3])??0,D=F.x+c,R=F.width-c-y,L=F.y+U,O=F.height-U-l,q=A.fontMetrics(i),S=C.lineHeight??i.size*1.2,b=C.textAlign??"start",T=e.type==="textarea",Y=T?yI(h,R,f=>A.measureText(f,i)).lines:[h],z=f=>b==="center"?D+(R-f)/2:b==="end"?D+R-f:D,gA=f=>T?L+f*S+(S-(q.ascent+q.descent))/2+q.ascent:L+(O-(q.ascent+q.descent))/2+q.ascent;g.save(),g.clipRoundRect(F,t);for(let f=0;f<Y.length;f++){const u=Y[f];u.length>0&&g.fillText(u,z(A.measureText(u,i)),gA(f),i,G)}if((a=e.state)!=null&&a.focused){const f=r?[""]:T?yI(w?"•".repeat(E.length):E,R,QA=>A.measureText(QA,i)).lines:[h],u=f.length-1,m=A.measureText(f[u],i),W=r?z(0):z(m)+m,x=gA(u),IA=Math.max(1,i.size/14);g.fillRoundRect({x:W,y:x-q.ascent,width:IA,height:q.ascent+q.descent},void 0,C.color??255)}g.restore()}function Pt(e,g=[],A={}){const t=A.precision??2,C=A.includeIds??!1,i=e?ke(e,t,C):null;if(g.length===0)return i;const E=g.map(r=>ke(r,t,C));return i?(i.overlays=E,i):{type:"frame",overlays:E}}function Cr(e,g=[],A){return JSON.stringify(Pt(e,g,A),null,2)}function AI(e,g){const A=10**g;return Math.round(e*A)/A}function ke(e,g,A){var E,r;const t=e.rect,C={type:e.type};e.name&&(C.name=e.name),C.rect=[AI(t.x,g),AI(t.y,g),AI(t.width,g),AI(t.height,g)],A&&(C.id=e.id);const i=Qr(e.style);return i&&(C.style=i),e.text!==void 0&&(C.text=e.text),e.lines&&(e.lines.length!==1||e.lines[0]!==e.text)&&(C.lines=e.lines),e.value!==void 0&&e.value!==""&&(C.value=e.value),e.style.placeholder!==void 0&&(C.placeholder=e.style.placeholder),e.image&&(C.image={src:e.image.src,natural:[e.image.naturalWidth,e.image.naturalHeight]}),e.sourceRect&&(C.sourceRect=e.sourceRect),e.state&&(e.state.pressed||(E=e.state.classes)!=null&&E.length)&&(C.state={...e.state.pressed?{pressed:!0}:{},...(r=e.state.classes)!=null&&r.length?{classes:e.state.classes}:{}}),e.scroll&&(C.scroll={offset:AI(e.scroll.offset,g),content:AI(e.scroll.content,g)}),e.children.length>0&&(C.children=e.children.map(w=>ke(w,g,A))),C}function ir(e){return e.tl===e.tr&&e.tr===e.br&&e.br===e.bl?e.tl:[e.tl,e.tr,e.br,e.bl]}function Qr(e){const g={};if(e.backgroundColor!==void 0&&(g.backgroundColor=Xg(e.backgroundColor)),e.opacity!==void 0&&(g.opacity=e.opacity),e.color!==void 0&&(g.color=Xg(e.color)),e.fontSize!==void 0&&(g.fontSize=e.fontSize),e.fontFamily!==void 0&&(g.fontFamily=e.fontFamily),e.fontWeight!==void 0&&(g.fontWeight=e.fontWeight),e.fontStyle!==void 0&&e.fontStyle!=="normal"&&(g.fontStyle=e.fontStyle),e.lineHeight!==void 0&&(g.lineHeight=e.lineHeight),e.letterSpacing&&(g.letterSpacing=e.letterSpacing),e.textAlign!==void 0&&e.textAlign!=="start"&&(g.textAlign=e.textAlign),e.textDecoration!==void 0&&e.textDecoration!=="none"&&(g.textDecoration=e.textDecoration),e.lineClamp&&(g.lineClamp=e.lineClamp,e.textOverflow==="clip"&&(g.textOverflow=e.textOverflow)),e.objectFit!==void 0&&(g.objectFit=e.objectFit),e.tintColor!==void 0&&(g.tintColor=Xg(e.tintColor)),e.overlayColor!==void 0&&(g.overlayColor=Xg(e.overlayColor)),e.backgroundImage!==void 0&&(g.backgroundImage=e.backgroundImage),e.backgroundSize!==void 0&&(g.backgroundSize=e.backgroundSize),e.backgroundGradients!==void 0&&e.backgroundGradients.length>0&&(g.backgroundGradients=e.backgroundGradients.map(A=>{const t=A.stops.map(C=>({color:Xg(C.color),position:C.position}));if(A.type==="radial"){const C={type:"radial",shape:A.shape,extent:A.extent,cx:A.cx,cy:A.cy,stops:t};return A.extent==="explicit"&&(C.rx=A.rx,C.ry=A.ry,C.rxUnit=A.rxUnit,C.ryUnit=A.ryUnit),C}return{angle:A.angle,stops:t}})),e.borderRadius&&(e.borderRadius.tl||e.borderRadius.tr||e.borderRadius.br||e.borderRadius.bl)&&(g.borderRadius=ir(e.borderRadius)),e.border){const A={};for(const t of["top","right","bottom","left"]){const C=e.border[t];C&&C.width>0&&(A[t]={width:C.width,color:Xg(C.color)})}Object.keys(A).length>0&&(g.border=A)}return Object.keys(g).length>0?g:void 0}async function or(e,g){return typeof globalThis.window>"u"&&(globalThis.window=globalThis),e({wasmBinary:g,locateFile:()=>""})}const Xt=e=>e==="monospaced"?"monospace":e;function ft(e){return`${e.italic?"italic ":""}${e.weight} ${e.size}px ${Xt(e.family)}`}class Er{constructor(g={}){X(this,"ctx");X(this,"images",new Map);X(this,"pending",new Map);X(this,"resolver");X(this,"canvasSurfaces");X(this,"fontFormat","woff2");const A=typeof document<"u"?document.createElement("canvas"):new OffscreenCanvas(8,8);this.ctx=A.getContext("2d"),this.canvasSurfaces=g.canvasSurfaces,this.resolver=qt({assetUrl:g.resolveAssetUrl,fileUrl:t=>URL.createObjectURL(t)})}resolveSrc(g){return this.resolver(g)}pendingImages(){return this.pending.size}resolveFontFamily(g){return Xt(g)}measureText(g,A){return this.ctx.font=ft(A),this.ctx.letterSpacing=`${A.letterSpacing}px`,this.ctx.measureText(g).width}fontMetrics(g){this.ctx.font=ft(g);const A=this.ctx.measureText("Mg"),t=A.fontBoundingBoxAscent||A.actualBoundingBoxAscent||g.size*.8,C=A.fontBoundingBoxDescent||A.actualBoundingBoxDescent||g.size*.2;return{ascent:t,descent:C}}getImage(g){return mI(g,this.canvasSurfaces)??this.images.get(g)}loadImage(g){const A=mI(g,this.canvasSurfaces);if(A)return Promise.resolve(A);const t=this.images.get(g);if(t)return Promise.resolve(t);const C=this.pending.get(g);if(C)return C;const i=(async()=>{const E=await this.decode(g);let r=E.naturalWidth,w=E.naturalHeight;if(JI(g)){const G=await sE(g,F=>fetch(F).then(c=>c.ok?c.text():null));G&&(r=G.width,w=G.height)}const h={src:g,naturalWidth:r,naturalHeight:w,handle:E};return this.images.set(g,h),this.pending.delete(g),h})();return this.pending.set(g,i),i.catch(()=>this.pending.delete(g)),i}decode(g){return new Promise((A,t)=>{const C=new Image;C.onload=()=>A(C),C.onerror=i=>t(i),C.src=g})}async loadFont(g,A,t){if(typeof globalThis.FontFace>"u")return;const C=new FontFace(g,`url(${A})`,t);document.fonts.add(C),await C.load()}}class Gt{constructor(g,A=1){X(this,"ctx");X(this,"dpr");X(this,"groups",[]);X(this,"scratch");X(this,"scratchCtx");this.ctx=g,this.dpr=A}beginGroup(g){const A=this.ctx,t=A.canvas.width,C=A.canvas.height;let i;typeof OffscreenCanvas<"u"?i=new OffscreenCanvas(t,C):(i=document.createElement("canvas"),i.width=t,i.height=C);const E=i.getContext("2d");E.setTransform(A.getTransform()),this.groups.push({parent:A,layer:i,alpha:g}),this.ctx=E}endGroup(){const g=this.groups.pop();g&&(this.ctx=g.parent,this.ctx.save(),this.ctx.setTransform(1,0,0,1,0,0),this.ctx.globalAlpha*=g.alpha,this.ctx.drawImage(g.layer,0,0),this.ctx.restore())}beginFrame(g,A){const{ctx:t,dpr:C}=this;t.setTransform(C,0,0,C,0,0),t.clearRect(0,0,g,A),t.globalAlpha=1}endFrame(){}save(){this.ctx.save()}restore(){this.ctx.restore()}setAlpha(g){this.ctx.globalAlpha*=g}translate(g,A){this.ctx.translate(g,A)}scale(g,A){this.ctx.scale(g,A)}transform(g,A,t,C,i,E){this.ctx.transform(g,A,t,C,i,E)}addRectPath(g,A){const t=this.ctx;A&&(A.tl||A.tr||A.br||A.bl)?t.roundRect(g.x,g.y,g.width,g.height,[A.tl,A.tr,A.br,A.bl]):t.rect(g.x,g.y,g.width,g.height)}path(g,A){this.ctx.beginPath(),this.addRectPath(g,A)}clipRoundRect(g,A){this.path(g,A),this.ctx.clip()}fillRoundRect(g,A,t){this.path(g,A),this.ctx.fillStyle=Pg(t),this.ctx.fill()}fillGradient(g,A,t){if(t.type==="radial"){this.fillRadial(g,A,t);return}const{x0:C,y0:i,x1:E,y1:r}=zE(t.angle,g),w=this.ctx.createLinearGradient(C,i,E,r);for(const h of t.stops)w.addColorStop(Math.max(0,Math.min(1,h.position)),Pg(h.color));this.path(g,A),this.ctx.fillStyle=w,this.ctx.fill()}fillRadial(g,A,t){const{cx:C,cy:i,rx:E,ry:r}=$E(t,g),w=this.ctx,h=E||1e-6,G=r||1e-6;w.save(),this.path(g,A),w.clip(),w.translate(C,i),w.scale(h,G);const F=w.createRadialGradient(0,0,0,0,0,1);for(const D of t.stops)F.addColorStop(Math.max(0,Math.min(1,D.position)),Pg(D.color));w.fillStyle=F;const c=(g.x-C)/h,U=(g.x+g.width-C)/h,y=(g.y-i)/G,l=(g.y+g.height-i)/G;w.fillRect(c,y,U-c,l-y),w.restore()}strokeBorder(g,A,t){const C=this.ctx,i=["top","right","bottom","left"].filter(r=>t[r]);if(i.length===4&&i.every(r=>t[r].width===t.top.width&&t[r].color===t.top.color)){const r=t.top.width,w=Se(A,g);C.beginPath(),this.addRectPath(g,w);const h={x:g.x+r,y:g.y+r,width:g.width-2*r,height:g.height-2*r};if(h.width>0&&h.height>0){const G=w&&Se({tl:Math.max(0,w.tl-r),tr:Math.max(0,w.tr-r),br:Math.max(0,w.br-r),bl:Math.max(0,w.bl-r)},h);this.addRectPath(h,G||void 0)}C.fillStyle=Pg(t.top.color),C.fill("evenodd");return}for(const r of i){const{width:w,color:h}=t[r];C.fillStyle=Pg(h),r==="top"?C.fillRect(g.x,g.y,g.width,w):r==="bottom"?C.fillRect(g.x,g.y+g.height-w,g.width,w):r==="left"?C.fillRect(g.x,g.y,w,g.height):C.fillRect(g.x+g.width-w,g.y,w,g.height)}}getScratch(g,A){return this.scratch||(this.scratch=typeof OffscreenCanvas<"u"?new OffscreenCanvas(g,A):document.createElement("canvas"),this.scratchCtx=this.scratch.getContext("2d")),(this.scratch.width<g||this.scratch.height<A)&&(this.scratch.width=Math.max(this.scratch.width,g),this.scratch.height=Math.max(this.scratch.height,A)),this.scratchCtx}drawImage(g,A,t,C){const i=g.handle;if(!i)return;const{src:E,dst:r}=A?{src:A,dst:t}:jE(g.naturalWidth,g.naturalHeight,t,C.fit),w=!A&&C.fit!=="cover";if(C.tint===void 0){w?this.ctx.drawImage(i,r.x,r.y,r.width,r.height):this.ctx.drawImage(i,E.x,E.y,E.width,E.height,r.x,r.y,r.width,r.height);return}const h=Math.max(1,Math.ceil(r.width)),G=Math.max(1,Math.ceil(r.height)),F=this.getScratch(h,G);F.clearRect(0,0,h,G),F.globalCompositeOperation="source-over",w?F.drawImage(i,0,0,h,G):F.drawImage(i,E.x,E.y,E.width,E.height,0,0,h,G),F.globalCompositeOperation="source-in",F.fillStyle=Pg(C.tint),F.fillRect(0,0,h,G),F.globalCompositeOperation="source-over",this.ctx.drawImage(F.canvas,0,0,h,G,r.x,r.y,r.width,r.height)}fillText(g,A,t,C,i){const E=this.ctx;E.font=`${C.italic?"italic ":""}${C.weight} ${C.size}px ${C.family}`,E.textBaseline="alphabetic",E.textAlign="left","letterSpacing"in E&&(E.letterSpacing=`${C.letterSpacing}px`),E.fillStyle=Pg(i),E.fillText(g,A,t)}}const ut=new Set;function rr(e){return(...g)=>{ut.has(e)||(ut.add(e),console.warn(`[canvas-ui] "${e}" is not implemented yet (deferred feature).`))}}async function sr(e={}){const g=e.host??new WE({canvasSurfaces:e.canvasSurfaces}),A=e.layout??await HI.create(),t=new LE(A,g),C=new XE(t);return{openScreen:i=>t.openScreen(i),closeScreen:()=>t.closeScreen(),insertNode:(i,E,r)=>t.insertNode(i,E,r),removeNode:(i,E)=>t.removeNode(i,E),setContent:(i,E,r)=>t.setContent(i,E,r),updateStyle:(i,E,r)=>t.updateStyle(i,E,r),mergeStyle:(i,E)=>t.mergeStyle(i,E),setClass:(i,E,r)=>t.setClass(i,E,r),setTheme:i=>t.setTheme(i),updateNode:(i,E,r)=>t.updateNode(i,E,r),registerResizeEvent:i=>t.registerResizeEvent(i),registerTouchStartEvent:i=>C.registerTouchStartEvent(i),registerTouchEndEvent:i=>C.registerTouchEndEvent(i),isButtonPressed:i=>t.isButtonPressed(i),getTextValue:i=>t.getTextValue(i),getBoundingClientRect:i=>t.getBoundingClientRect(i),routerOpen:(i,E)=>t.routerOpen(i,E),routerPush:i=>t.routerPush(i),routerReplace:i=>t.routerReplace(i),routerPop:(i=-1)=>t.routerPop(i),routerHide:()=>t.routerHide(),routerRestore:()=>t.routerRestore(),showWidget:i=>t.showWidget(i),hideWidget:i=>t.hideWidget(i),setSourceRect:(i,E,r,w,h)=>t.setSourceRect(i,E,r,w,h),registerFont:(i,E,r,w,h)=>t.registerFont(i,E,r,w,h),fontFormat:g.fontFormat,toast:rr("toast"),animateTo:(i,E)=>t.animateTo(i,E),animateFrom:(i,E)=>t.animateFrom(i,E),vlistMount:(i,E,r)=>t.vlistMount(i,E,r),vlistSetKeys:(i,E,r)=>t.vlistSetKeys(i,E,r),vlistInsertKeys:(i,E,r,w)=>t.vlistInsertKeys(i,E,r,w),vlistInvalidate:(i,E)=>t.vlistInvalidate(i,E),vlistRemoveKeys:(i,E)=>t.vlistRemoveKeys(i,E),command:(i,E,...r)=>t.command(i,E,...r),_setCreator:i=>C.setCreator(i),_setScenePointer:i=>C.setScenePointer(i),resize:(i,E)=>t.resize(i,E),setSafeArea:(i,E)=>t.setSafeArea(i,E),renderTree:()=>t.renderTree(),widgets:()=>t.widgetTrees(),find:i=>t.findByName(i),findAll:i=>t.findAllByName(i),serialize:i=>Pt(t.renderTree(),t.widgetTrees(),i),toText:i=>Cr(t.renderTree(),t.widgetTrees(),i),paint:i=>{const{width:E,height:r}=t.viewport;Ar(t.frame(),i,g,E,r)},pointerDown:(i,E,r)=>C.pointerDown(i,E,r),pointerMove:(i,E,r)=>C.pointerMove(i,E,r),pointerUp:(i,E,r)=>C.pointerUp(i,E,r),scrollBy:(i,E)=>t.scrollBy(i,E),tick:i=>t.tick(i),hasActiveAnimations:()=>t.hasActiveAnimations(),needsPaint:()=>t.needsPaint(),focusInput:i=>t.focusInput(i),submitInput:()=>t.submitInput(),blurInput:()=>t.blurInput(),setInputValue:(i,E)=>t.setInputValue(i,E),keyboard:()=>t.keyboard(),uiTransform:()=>t.uiTransform(),onKeyboardChange:i=>t.registerKeyboardEvent(i),renderer:t,host:g}}async function nr(e,g){const A=await fetch(Mt).then(iA=>iA.arrayBuffer()),t=await or(bt,A),C=new HI(t),i=await sr({host:new Er({resolveAssetUrl:iA=>bI(iA),canvasSurfaces:g}),layout:C}),E=document.createElement("canvas");E.style.position="absolute",E.style.inset="0",E.style.width="100%",E.style.height="100%",E.style.touchAction="none",e.appendChild(E);const r=E.getContext("2d"),w=()=>(window.devicePixelRatio||1)*Mg(E);let h=w(),G=new Gt(r,h);const F=ar();F.el.style.display="none",e.appendChild(F.el);const c=document.createElement("input");c.setAttribute("autocomplete","off"),c.style.cssText="position:absolute;left:0;top:0;width:1px;height:1px;opacity:0;pointer-events:none;border:0;padding:0;",e.appendChild(c);let U=0;c.addEventListener("input",()=>{U&&i.setInputValue(U,c.value)}),i.onKeyboardChange(iA=>{iA?(U=iA.input.nodeId,c.type=iA.input.type==="password"?"password":"text",c.value!==iA.input.value&&(c.value=iA.input.value),c.focus({preventScroll:!0}),F.show(iA.rect)):(U=0,c.blur(),F.el.style.display="none")});let y=0,l=0,D=!1;const R=iA=>{const lA=l===0?0:iA-l;l=iA,i.hasActiveAnimations()&&i.tick(lA),(D||i.needsPaint())&&(D=!1,i.paint(G)),y=requestAnimationFrame(R)};let L=null,O="";const q=(iA,lA)=>{const DA=L?Yt(L,iA>lA):null,a=DA?JSON.stringify(DA):"";a!==O&&(O=a,i.setSafeArea(DA?DA.insets:null,DA==null?void 0:DA.bars))};let S=0,b=0;const T=(iA,lA,DA)=>{if(iA<=0||lA<=0)return;const a=DA??w();a!==h&&(h=a,G=new Gt(r,h)),E.width=Math.round(iA*h),E.height=Math.round(lA*h),E.style.width=iA+"px",E.style.height=lA+"px",D=!0,q(iA,lA),i.resize(iA,lA),S=iA,b=lA},Y=iA=>{const lA=E.getBoundingClientRect(),DA=Mg(E);return[(iA.clientX-lA.left)/DA,(iA.clientY-lA.top)/DA]},z=iA=>{E.setPointerCapture(iA.pointerId);const[lA,DA]=Y(iA);i.pointerDown(iA.pointerId,lA,DA)},gA=iA=>{const[lA,DA]=Y(iA);i.pointerMove(iA.pointerId,lA,DA)},EA=iA=>{const[lA,DA]=Y(iA);i.pointerUp(iA.pointerId,lA,DA)};return E.addEventListener("pointerdown",z),E.addEventListener("pointermove",gA),E.addEventListener("pointerup",EA),T(e.clientWidth,e.clientHeight),y=requestAnimationFrame(R),Object.assign(i,{_onResize:T,_setSafeAreaSpec(iA){L=iA,S&&b&&q(S,b)},getDisplaySize:()=>[S,b],_destroy(){cancelAnimationFrame(y),E.removeEventListener("pointerdown",z),E.removeEventListener("pointermove",gA),E.removeEventListener("pointerup",EA),E.remove(),F.el.remove(),c.remove()}})}function ar(){const e=document.createElement("div");e.style.cssText="position:absolute;left:0;right:0;bottom:0;box-sizing:border-box;background:#caced6;display:flex;flex-direction:column;justify-content:space-evenly;align-items:stretch;padding:6px 5px;z-index:20;user-select:none;-webkit-user-select:none;touch-action:none;";const g=["10","9","7","5"];for(const A of g){const t=document.createElement("div");t.style.cssText="display:flex;justify-content:center;align-items:center;gap:6px;flex:0 0 auto;";for(let C=0;C<Number(A);C++){const i=document.createElement("div");i.style.cssText="flex:1 1 0;max-width:32px;height:40px;background:#fff;border-radius:6px;box-shadow:0 1px 0 rgba(0,0,0,0.25);",t.appendChild(i)}e.appendChild(t)}return e.addEventListener("pointerdown",A=>A.preventDefault()),{el:e,show(A){e.style.height=A.height+"px",e.style.display="flex"}}}const cr=["abstract","ios","android"],lr={abstract:void 0,ios:{portrait:[59,0,34,0],landscape:[0,59,21,59]},android:{portrait:[24,0,48,0],landscape:[24,0,48,0],portraitBars:["top","bottom"],landscapeBars:["top","bottom"]}},jt=e=>typeof e=="string"&&cr.includes(e)?e:"abstract",Hg=document.getElementById("app"),ye=document.getElementById("loader"),Yg=new URLSearchParams(location.search),ve=(()=>{const e=window.lecodesEmbedConfig;return e&&typeof e=="object"?e:{}})();for(const[e,g]of Object.entries(ve))g!=null&&typeof g!="object"&&Yg.set(e,String(g));let KI=Yg.get("lang")||"en";window.getLanguage=()=>KI;const zt=window.parent!==window?e=>window.parent.postMessage({type:"lecodes-orientation",orientation:e},"*"):void 0;let xA=null;const $t=e=>{const g=e!=null?Number(e):NaN;return Number.isFinite(g)&&g>0?g:null};let Je=$t(Yg.get("zoom"))??.75,Ue=jt(Yg.get("shell"));const AB=e=>{if(!e||typeof e!="object")return null;const g=C=>typeof C=="number"&&Number.isFinite(C)&&C>=0?Math.round(C):0,A=e,t=[g(A.top),g(A.right),g(A.bottom),g(A.left)];return{portrait:t,landscape:t}};let gB=AB(ve.safeArea);const LI=()=>gB??lr[Ue],hr=()=>Je===1,YI=e=>{Je=e,Hg.style.zoom=String(e),xA==null||xA.refreshResolution()};YI(Je);function Jg(e){ye==null||ye.classList.toggle("embed-loader--on",e)}function vg(e){const g=document.createElement("div");g.className="embed-error",g.textContent=e,Hg.appendChild(g)}const IB=e=>typeof e=="string"&&e.startsWith("/")&&!e.startsWith("//");function dr(e){const g=e.slice(0,2e3),A=new Set,t=g.match(/\/\/ preload: (.+)/);if(t)for(const w of t[1].split(";"))A.add(w);const C=g.includes("// gl: disable")||g.includes("// gl: defer"),i=!g.includes("// gl: disable"),E=g.includes("// 2d: enable");return{engine:E&&i?"dual":E?"2d":C?"defer":"gl",preloads:A,bootFonts:yo(g)}}const He=async e=>{e.zoom!==void 0&&YI(e.zoom),e.lang&&(KI=e.lang);let g=e.code;if(g===void 0){if(!e.src)throw new Error("embed.mount: pass `code` or `src`");const E=await fetch(e.src);if(!E.ok)throw new Error(`embed: ${e.src} → HTTP ${E.status}`);g=await E.text()}const{engine:A,preloads:t,bootFonts:C}=dr(g),i=await So(Hg,{engine:A,ui:e.ui==="canvas"?nr:tE,preloads:t,bootFonts:C,methods:e.methods,safeArea:e.safeArea,keyboardTargets:e.keyboardTargets,onOrientation:e.onOrientation??zt});try{i.run(g,{onError:e.onError})}catch{}return Jg(!1),{_creator:i._creator,_creator2d:i._creator2d,_creatorUI:i._creatorUI,_creatorUtils:i._creatorUtils,uiRoot:Hg,refreshResolution:()=>i.refreshResolution(),destroy:()=>i.destroy()}};let BI=null,tI=null,Qg=0;function eB(){tI?CB(tI.uuid,tI.engine):BI&&Ye(BI)}async function Ye(e){const g=++Qg;BI=e,tI=null,Jg(!0),xA==null||xA.destroy(),xA=null,Hg.replaceChildren();try{const A=await He({src:e,safeArea:LI(),onError:t=>{var i;const C=t.detail?`${t.message}: ${t.detail}`:t.message;vg((i=t.nativeFrames)!=null&&i.length?`${C} — in ${t.nativeFrames[0]}`:C)}});if(g!==Qg){A.destroy();return}xA=A}catch(A){g===Qg&&vg(String(A))}finally{g===Qg&&Jg(!1)}}function tB(e){const g=e||"en";g!==KI&&(KI=g,eB())}function BB(e){const g=jt(e);g!==Ue&&(Ue=g,eB())}const yr=()=>{if(window.parent===window)return null;const e=location.ancestorOrigins;if(e&&e.length>0)return e[0];try{return document.referrer?new URL(document.referrer).origin:null}catch{return null}},Dr=(e,g)=>{if(e.length===0)return!0;const A=document.referrer.toLowerCase();return e.some(t=>{const C=t.toLowerCase().replace(/\/+$/,"");let i;try{i=new URL(C.includes("://")?C:`https://${C}`).origin}catch{return!1}return i!==g.toLowerCase()?!1:!C.replace(/^https?:\/\//,"").includes("/")||A.startsWith(C)})},fr=async e=>{try{const g=localStorage.getItem("accessToken");return g?(await fetch(`/api/projects/${encodeURIComponent(e)}/publish`,{headers:{Authorization:`Bearer ${g}`}})).ok:!1}catch{return!1}},Gr=e=>`/code/${encodeURIComponent(e)}.js?ts=${Math.trunc(Date.now()/3e4)*3e4}`;async function CB(e,g){var G;const A=++Qg;BI=null,tI={uuid:e,engine:g},Jg(!0),xA==null||xA.destroy(),xA=null,Hg.replaceChildren();const t=ve.policy;let C;if(t&&typeof t=="object"&&t.uuid===e)C=t;else{try{const F=await fetch(`/api/publish/${encodeURIComponent(e)}`,{cache:"no-store"});if(!F.ok)throw new Error(`HTTP ${F.status}`);C=await F.json()}catch{A===Qg&&(Jg(!1),vg("This app isn’t available."));return}if(A!==Qg)return}const i=yr(),E=i===null||i===location.origin||(C.firstPartyOrigins??[]).includes(i);let r=null;if(C.published?E&&!C.web.enabled?r="This app can’t be opened in the browser — get the LeCodes app.":!E&&!C.embed.enabled?r="This app can’t be embedded on other sites.":!E&&!Dr(C.embed.referers,i)&&(r="This site isn’t allowed to embed this app."):r="This app isn’t published right now.",r&&C.published&&E&&Yg.get("preview")==="1"&&await fr(e)&&(r=null),A!==Qg)return;if(r){Jg(!1),vg(r);return}const w=(G=C.meta)!=null&&G.twoD?"full":g==="full"||g==="lite"?g:C.web.engine,h=Gr(e);BI=h;try{if(w==="lite"){const F=await fetch(h);if(!F.ok)throw new Error(`embed: ${h} → HTTP ${F.status}`);const c=await F.text();if(A!==Qg)return;const{mountCreatorLite:U}=await II(async()=>{const{mountCreatorLite:l}=await import("./assets/host-CWKB1WDd.js");return{mountCreatorLite:l}},[],import.meta.url),y=await U(Hg,c,void 0,{safeArea:LI(),onOrientation:zt,frame:!hr(),onError:l=>vg(l.detail?`${l.message}: ${l.detail}`:l.message)});if(A!==Qg){y.destroy();return}xA={_creator:y._creator,_creator2d:void 0,_creatorUI:y._creatorUI,_creatorUtils:y._creatorUtils,uiRoot:y.uiRoot??Hg,refreshResolution:()=>{},destroy:()=>y.destroy()}}else{const F=await He({src:h,safeArea:LI(),onError:c=>{var y;const U=c.detail?`${c.message}: ${c.detail}`:c.message;vg((y=c.nativeFrames)!=null&&y.length?`${U} — in ${c.nativeFrames[0]}`:U)}});if(A!==Qg){F.destroy();return}xA=F}}catch(F){A===Qg&&vg(String(F))}finally{A===Qg&&Jg(!1)}}window.lecodesEmbed={version:"df3b74c2-2026-09-04",mount:He,setLang:tB,setZoom:YI,setShell:BB,setSafeArea(e){var g,A;gB=AB(e),(A=(g=xA==null?void 0:xA._creatorUI)==null?void 0:g._setSafeAreaSpec)==null||A.call(g,LI()??null)},destroy(){xA==null||xA.destroy(),xA=null,BI=null,tI=null}};window.addEventListener("message",e=>{if(e.source!==window.parent)return;const g=e.data;if(g)if(g.type==="lecodes-run"&&IB(g.src))Ye(g.src);else if(g.type==="lecodes-lang"&&typeof g.lang=="string")tB(g.lang);else if(g.type==="lecodes-zoom"){const A=$t(g.zoom);A!==null&&YI(A)}else g.type==="lecodes-shell"&&typeof g.shell=="string"&&BB(g.shell)});const RI=Yg.get("src"),wt=Yg.get("app");wt?CB(wt,Yg.get("engine")):RI===null||RI===""||(IB(RI)?Ye(RI):(Jg(!1),vg("embed: expected ?src=/path/to/app.js (same-origin)")));export{Mg as A,Fr as B,Og as C,st as D,De as E,Ft as F,KQ as G,St as H,Sr as I,or as J,Po as R,II as _,qQ as a,Ho as b,MI as c,fe as d,Ke as e,mo as f,bI as g,Uo as h,hI as i,ko as j,Ro as k,ho as l,Do as m,ao as n,Yt as o,eo as p,yo as q,XQ as r,me as s,wo as t,tt as u,fo as v,go as w,It as x,fg as y,UI as z};
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "lecodes-viewer",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "main": "src/createViewer.ts",
5
5
  "dependencies": {
6
- "lecodes-renderer": "workspace:*",
6
+ "lecodes-renderer": "0.19.1",
7
7
  "ogl": "^1.0.11",
8
- "lecodes-viewer-lite": "workspace:*"
8
+ "lecodes-viewer-lite": "0.19.1"
9
9
  },
10
10
  "scripts": {
11
11
  "dev": "vite",