exodeui 6.3.31 → 6.3.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +33 -33
- package/dist/index.mjs +2471 -2295
- package/dist/src/engine.d.ts +2 -0
- package/dist/src/types.d.ts +5 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
(function(Xt
|
|
2
|
-
`||
|
|
3
|
-
`||T[P]==="\r")&&(
|
|
4
|
-
`&&P++);
|
|
1
|
+
(function(Dt,Xt){typeof exports=="object"&&typeof module<"u"?Xt(exports,require("react/jsx-runtime"),require("react"),require("@chenglou/pretext"),require("@dimforge/rapier2d-compat"),require("lz-string")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","@chenglou/pretext","@dimforge/rapier2d-compat","lz-string"],Xt):(Dt=typeof globalThis<"u"?globalThis:Dt||self,Xt(Dt.ExodeUIReact={},Dt.jsxRuntime,Dt.React,Dt.pretext,Dt.Rapier,Dt.LZString))})(this,(function(Dt,Xt,Et,Xe,Zt,bs){"use strict";var li=Object.defineProperty;var ci=(Dt,Xt,Et)=>Xt in Dt?li(Dt,Xt,{enumerable:!0,configurable:!0,writable:!0,value:Et}):Dt[Xt]=Et;var lt=(Dt,Xt,Et)=>ci(Dt,typeof Xt!="symbol"?Xt+"":Xt,Et);function vs(g){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(g){for(const i in g)if(i!=="default"){const o=Object.getOwnPropertyDescriptor(g,i);Object.defineProperty(t,i,o.get?o:{enumerable:!0,get:()=>g[i]})}}return t.default=g,Object.freeze(t)}const Ss=vs(bs);var U=(g=>(g.Proximity="Proximity",g.Magnetic="Magnetic",g.Repel="Repel",g.Orbit="Orbit",g.Vortex="Vortex",g.Fluid="Fluid",g.Elastic="Elastic",g.Holographic="Holographic",g.Sticky="Sticky",g.Dilation="Dilation",g.Parallax="Parallax",g.Noise="Noise",g.Float="Float",g.Pulse="Pulse",g.Draggable="Draggable",g.Scroll="Scroll",g.LookAt="LookAt",g.Glint="Glint",g.Scan="Scan",g.Ratchet="Ratchet",g.Jitter="Jitter",g.Follower="Follower",g.Wrap="Wrap",g.Typewriter="Typewriter",g.Scramble="Scramble",g.Wave="Wave",g.Bounce="Bounce",g.TextTrail="TextTrail",g.Reveal3D="Reveal3D",g.RevealSlide="RevealSlide",g.RevealBlur="RevealBlur",g.TextLiquid="TextLiquid",g.TextVortex="TextVortex",g.TextExplosion="TextExplosion",g.TextRain="TextRain",g.TextGravity="TextGravity",g.TextMatrix="TextMatrix",g.TextNeon="TextNeon",g.TextDissolve="TextDissolve",g.TextOrganic="TextOrganic",g.TextBreathe="TextBreathe",g.TextSpin="TextSpin",g.TextMagnet="TextMagnet",g.TextPerspective="TextPerspective",g.TextMirror="TextMirror",g.TextFloral="TextFloral",g.TextSmoke="TextSmoke",g.TextVariable="TextVariable",g.TextZing="TextZing",g.TextElastic="TextElastic",g.TextGlitch3D="TextGlitch3D",g.GlitchText="GlitchText",g.TextCounter="TextCounter",g.Squash="Squash",g.Spotlight="Spotlight",g.Lens="Lens",g.Gravity="Gravity",g.Velocity="Velocity",g.Shear="Shear",g.LayoutAnimation="LayoutAnimation",g.SpringChain="SpringChain",g.ParticleEmitter="ParticleEmitter",g.StateReactive="StateReactive",g.Fold="Fold",g.Crumple="Crumple",g))(U||{}),jt=(g=>(g.Scale="Scale",g.Opacity="Opacity",g.RotateZ="RotateZ",g.RotateX="RotateX",g.RotateY="RotateY",g.PositionX="PositionX",g.PositionY="PositionY",g.SkewX="SkewX",g.Blur="Blur",g.Exposure="Exposure",g.HueShift="HueShift",g.Negative="Negative",g.CornerRadius="CornerRadius",g.StrokeWidth="StrokeWidth",g.BoxShadow="BoxShadow",g.FontSize="FontSize",g.LetterSpacing="LetterSpacing",g))(jt||{}),Qe=(g=>(g.Equal="Equal",g.NotEqual="NotEqual",g.GreaterThan="GreaterThan",g.LessThan="LessThan",g.GreaterEqual="GreaterEqual",g.LessEqual="LessEqual",g.IsTrue="IsTrue",g.IsFalse="IsFalse",g))(Qe||{}),wt=(g=>(g.AND="AND",g.OR="OR",g.NOT="NOT",g.XOR="XOR",g.OBJECT="OBJECT",g.PROPERTY="PROPERTY",g.GET_PROPERTY="GET_PROPERTY",g.SET_PROPERTY="SET_PROPERTY",g.ADD="ADD",g.SUB="SUB",g.MUL="MUL",g.DIV="DIV",g.MOD="MOD",g.POW="POW",g.ABS="ABS",g.ROUND="ROUND",g.FLOOR="FLOOR",g.CEIL="CEIL",g.SIN="SIN",g.COS="COS",g.TAN="TAN",g.CLAMP="CLAMP",g.REMAP="REMAP",g.EQ="EQ",g.NEQ="NEQ",g.GT="GT",g.LT="LT",g.GTE="GTE",g.LTE="LTE",g.IF_ELSE="IF_ELSE",g.VALUE="VALUE",g.INPUT="INPUT",g.LOG="LOG",g.SCROLL_X="SCROLL_X",g.SCROLL_Y="SCROLL_Y",g.MOUSE_X="MOUSE_X",g.MOUSE_Y="MOUSE_Y",g.IS_MOUSE_DOWN="IS_MOUSE_DOWN",g.EFFECTOR="EFFECTOR",g.MONITOR="MONITOR",g.DELAY="DELAY",g.SPRING_PULL="SPRING_PULL",g.SPRING_SETTLE="SPRING_SETTLE",g.EMIT="EMIT",g))(wt||{});function Cs(g){if(g.length<5)return g;const t=new Set("aeiouyAEIOUY".split(""));if(/[\u4E00-\u9FFF\u3400-\u4DBF]/.test(g))return g;let o="";for(let e=0;e<g.length;e++){if(o+=g[e],e>=g.length-2)continue;const s=t.has(g[e]),n=t.has(g[e+1]),a=t.has(g[e+2]);s&&!n&&a&&(o+=""),s&&!n&&!a&&e>=1&&(o+="")}return o}function ws(g){return g.replace(/\b([a-zA-Z]{4,})\b/g,(t,i)=>Cs(i))}function Ms(g,t,i){return g}function Is(g,t,i){return g}const Re=new Map;function Ze(g){var I;const{text:t,fontFamily:i="Inter",fontSize:o=16,fontWeight:e=400,fontStyle:s="normal",lineHeight:n=1.2,width:a=200,letterSpacing:l=0,paragraphSpacing:c=0,paragraphIndent:h=0,textCase:r="none",segments:u=[],enableSegments:f=!1}=g;let d=String(t||"");r==="uppercase"?d=d.toUpperCase():r==="lowercase"?d=d.toLowerCase():r==="capitalize"&&(d=d.replace(/\b\w/g,k=>k.toUpperCase())),g.hyphenation===!0&&(d=ws(d));const p=`${s} ${e} ${o}px "${i}", sans-serif`,m=`${d}|${p}|${l}|${c}|${h}|${f}|${JSON.stringify(u)}|hyp:${!!g.hyphenation}|comp:${g.composer}|bal:${!!g.balanceRaggedLines}`;let y=Re.get(m);const b=typeof CanvasRenderingContext2D<"u"?CanvasRenderingContext2D.prototype.measureText:null,v=function(k){if(!b)return{width:0,fontBoundingBoxAscent:0,fontBoundingBoxDescent:0};const T=b.call(this,k);return l!==0&&k&&k.length>0?{...T,width:T.width+(k.length-1)*l}:T};if(!y){try{if(l!==0&&typeof CanvasRenderingContext2D<"u"&&(CanvasRenderingContext2D.prototype.measureText=v),f&&u&&u.length>0){const k=u.map(T=>{let O=T.text||"";const P=T.textCase||r||"none";return P==="uppercase"?O.toUpperCase():P==="lowercase"?O.toLowerCase():P==="capitalize"?O.replace(/\b\w/g,_=>_.toUpperCase()):O}).join("");if(y=Xe.prepareWithSegments(k,p),y){let T=0,O=o;for(const P of u){let _=P.text||"";if(!_)continue;const A=P.textCase||r||"none";A==="uppercase"?_=_.toUpperCase():A==="lowercase"?_=_.toLowerCase():A==="capitalize"&&(_=_.replace(/\b\w/g,B=>B.toUpperCase()));const x=P.fontSize||o;x>O&&(O=x);const W=`${P.fontStyle||s} ${P.fontWeight||e} ${x}px "${P.fontFamily||i}", sans-serif`,Y=Xe.prepareWithSegments(_,W);if(Y&&Y.widths)for(let B=0;B<Y.widths.length;B++){const X=T+B;if(X<y.widths.length){y.widths[X]=Y.widths[B];const q=Y.kinds[B];if(q===2){const j=_[B];j===`
|
|
2
|
+
`||j==="\r"?y.kinds[X]=2:y.kinds[X]=0}else y.kinds[X]=q}}T+=_.length}y.fullText=k,y.maxFontSize=O}}else y=Xe.prepareWithSegments(d,p);y&&Re.set(m,y)}catch(k){return console.error("[ExodeUI] Pretext prepare failed:",k),{width:a,height:0,lineCount:0,lines:[]}}finally{l!==0&&typeof CanvasRenderingContext2D<"u"&&b&&(CanvasRenderingContext2D.prototype.measureText=b)}if(Re.size>500){const k=Re.keys().next().value;k&&Re.delete(k)}}if(h>0&&y&&y.widths&&!y.indentApplied){const k=[...y.widths],T=y.fullText||d;let O=!0;for(let P=0;P<T.length;P++)O&&k[P]!==void 0&&(k[P]+=h,O=!1),(T[P]===`
|
|
3
|
+
`||T[P]==="\r")&&(O=!0,T[P]==="\r"&&T[P+1]===`
|
|
4
|
+
`&&P++);y={...y,widths:k,indentApplied:!0}}if(!y)return{width:a,height:0,lineCount:0,lines:[]};let S=n;typeof S=="string"&&(S=parseFloat(S)),S>5&&o>0&&(S=S/o),l!==0&&(CanvasRenderingContext2D.prototype.measureText=v);let C;try{const k=y.maxFontSize||o;if(a>=1e5){const T=d.split(/\r\n|\r|\n/);C={lines:T.map(O=>({text:O,width:0})),height:T.length*(S*k),lineCount:T.length}}else C=Xe.layoutWithLines(y,a,S*k)}finally{l!==0&&b&&(CanvasRenderingContext2D.prototype.measureText=b)}let w=(C==null?void 0:C.height)!==void 0&&C.height>0?C.height:(((I=C==null?void 0:C.lines)==null?void 0:I.length)||0)*S*o;if(c>0&&C&&C.lines&&C.lines.length>1){let k=0;const T=y.fullText||t;for(let O=0;O<C.lines.length-1;O++)k+=C.lines[O].text.length,(T[k]===`
|
|
5
5
|
`||T[k]==="\r")&&(w+=c,k++,T[k-1]==="\r"&&T[k]===`
|
|
6
|
-
`&&k++)}let M=(C==null?void 0:C.lines)||[];return g.composer==="every-line"&&M.length>1&&(M=Ms(M)),g.balanceRaggedLines===!0&&M.length>1&&(M=Is(M)),{width:a,height:w,lineCount:M.length,lines:M}}function je(g,t,i){let o=String(g||"").trim();if(o&&!isNaN(Number(o))&&!o.includes(" ")&&!o.endsWith("fr")&&!o.endsWith("px")&&!o.endsWith("%")){const r=Math.max(1,parseInt(o));o=new Array(r).fill("1fr").join(" ")}const e=o.split(/\s+/).filter(Boolean),s=new Array(e.length).fill(0);let n=t-(e.length-1)*i,a=0;if(e.forEach((r,c)=>{if(r.endsWith("px")){const l=parseFloat(r);s[c]=l,n-=l}else r.endsWith("fr")?a+=parseFloat(r):r==="auto"&&(s[c]=100,n-=100)}),a>0&&n>0){const r=n/a;e.forEach((c,l)=>{c.endsWith("fr")&&(s[l]=r*parseFloat(c))})}return s}function ts(g,t,i){try{const o=g.autoLayout;return!o||!o.enabled?{childUpdates:[]}:(o.mode||"linear")==="grid"?Ts(g,t,i):ks(g,t,i)}catch(o){return console.error("Layout Engine Error:",o),{childUpdates:[]}}}function ks(g,t,i){var E,L;const o=g.autoLayout,{direction:e,spacing:s,padding:n,align:a,wrap:r}=o,c=e==="vertical",l=t.map(O=>{const W=i(O.id),B=O.geometry;let $=(W==null?void 0:W.width)??B.width??100,Y=(W==null?void 0:W.height)??B.height??100;if(B.type==="Ellipse"||B.type==="Polygon"||B.type==="Star"){const H=(W==null?void 0:W.radius)??B.radius??(W==null?void 0:W.outer_radius)??B.outer_radius??50;$=H*2,Y=H*2}else if(B.type==="Text"){const H=Ze({text:(W==null?void 0:W.text)??B.text??"",fontFamily:B.fontFamily,fontSize:B.fontSize,fontWeight:B.fontWeight,fontStyle:B.fontStyle,lineHeight:B.lineHeight,width:B.width||200,letterSpacing:B.letterSpacing,paragraphSpacing:B.paragraphSpacing,paragraphIndent:B.paragraphIndent,textCase:B.textCase,segments:B.segments,enableSegments:B.enableSegments});Y=H.height,B.width||($=H.width)}return $*=O.transform.scale_x||1,Y*=O.transform.scale_y||1,{id:O.id,w:$,h:Y,original:O}});let h=g.width,u=g.height;const f=((E=g.layoutProps)==null?void 0:E.width)==="hug",d=((L=g.layoutProps)==null?void 0:L.height)==="hug",p=[];let y=[],m=0,b=0;const v=h-n.left-n.right,S=u-n.top-n.bottom;l.forEach(O=>{r&&y.length>0&&(c?b+s+O.h>S:m+s+O.w>v)?(p.push({children:y,width:m,height:b}),y=[O],m=O.w,b=O.h):(y.push(O),c?(m=Math.max(m,O.w),b+=(y.length>1?s:0)+O.h):(m+=(y.length>1?s:0)+O.w,b=Math.max(b,O.h)))}),y.length>0&&p.push({children:y,width:m,height:b}),f&&!c&&(h=Math.max(...p.map(O=>O.width),0)+n.left+n.right),d&&c&&(u=Math.max(...p.map(O=>O.height),0)+n.top+n.bottom);const C=[];let w=n.left,M=n.top;const I=a.toLowerCase(),k=I==="center"||I.endsWith("-center"),T=I.endsWith("-right"),x=I==="center"||I.startsWith("center-"),P=I.startsWith("bottom-");return p.forEach(O=>{let W=w,B=M;c?x?B=n.top+(u-n.top-n.bottom-O.height)/2:P&&(B=u-n.bottom-O.height):k?W=n.left+(h-n.left-n.right-O.width)/2:T&&(W=h-n.right-O.width),O.children.forEach($=>{var _,R;let Y=W,H=B;c?k?Y+=(O.width-$.w)/2:T&&(Y+=O.width-$.w):x?H+=(O.height-$.h)/2:P&&(H+=O.height-$.h);const K=((_=$.original.layoutProps)==null?void 0:_.width)==="fill",A=((R=$.original.layoutProps)==null?void 0:R.height)==="fill";C.push({id:$.id,x:Y+$.w/2-h/2,y:H+$.h/2-u/2,width:K&&c?O.width:void 0,height:A?c?void 0:O.height:void 0}),c?B+=$.h+s:W+=$.w+s}),c?w+=O.width+s:M+=O.height+s}),{frameWidth:f?h:void 0,frameHeight:d?u:void 0,childUpdates:C}}function Ts(g,t,i){const o=g.autoLayout;if(!o)return{childUpdates:[]};const{gridColumns:e,gridRows:s,columnGap:n=0,rowGap:a=0,padding:r,align:c}=o;let l=g.width,h=g.height;const u=l-r.left-r.right,f=h-r.top-r.bottom,d=je(e||"1fr",u,n),p=je(s||"auto",f,a),y=d.length>0?d.reduce((T,x)=>T+x,0)+(d.length-1)*n:0,m=p.length>0?p.reduce((T,x)=>T+x,0)+(p.length-1)*a:0,b=c.toLowerCase(),v=b==="center"||b.endsWith("-center"),S=b.endsWith("-right"),C=b==="center"||b.startsWith("center-"),w=b.startsWith("bottom-");let M=0,I=0;v?M=(u-y)/2:S&&(M=u-y),C?I=(f-m)/2:w&&(I=f-m);const k=[];return t.forEach((T,x)=>{var R,X;const P=x%d.length||0,E=Math.floor(x/d.length)||0;E>=p.length&&p.push(100);const L=d[P],O=p[E];let W=r.left+M+d.slice(0,P).reduce((N,it)=>N+it+n,0),B=r.top+I+p.slice(0,E).reduce((N,it)=>N+it+a,0);const $=i(T.id),Y=T.geometry;let H=($==null?void 0:$.width)??Y.width??100,K=($==null?void 0:$.height)??Y.height??100;if(Y.type==="Ellipse"||Y.type==="Polygon"||Y.type==="Star"){const N=($==null?void 0:$.radius)??Y.radius??($==null?void 0:$.outer_radius)??Y.outer_radius??50;H=N*2,K=N*2}H*=T.transform.scale_x||1,K*=T.transform.scale_y||1;let A=W,_=B;v?A+=(L-H)/2:S&&(A+=L-H),C?_+=(O-K)/2:w&&(_+=O-K),k.push({id:T.id,x:A+H/2-l/2,y:_+K/2-h/2,width:((R=T.layoutProps)==null?void 0:R.width)==="fill"?L:void 0,height:((X=T.layoutProps)==null?void 0:X.height)==="fill"?O:void 0})}),{childUpdates:k}}class es{constructor(){ot(this,"world",null);ot(this,"bodies",new Map);ot(this,"colliders",new Map);ot(this,"joints",new Map);ot(this,"initialized",!1);ot(this,"bodyIdByCollider",new Map);ot(this,"onCollisionCB",null);ot(this,"eventQueue",null)}setCollisionCallback(t){this.onCollisionCB=t}async init(t){this.initialized||(await Zt.init(),this.world=new Zt.World(new Zt.Vector2(t.x*100,t.y*100)),this.eventQueue=new Zt.EventQueue(!0),this.initialized=!0)}destroy(){this.bodies.clear(),this.colliders.clear(),this.joints.clear(),this.world&&(this.world.free(),this.world=null),this.initialized=!1}setGravity(t){this.world&&(this.world.gravity=new Zt.Vector2(t.x*100,t.y*100))}createBody(t){if(!this.world){console.warn("[RapierPhysics] World not initialized");return}this.bodies.has(t.id)&&this.removeBody(t.id);const i=t.isStatic?Zt.RigidBodyDesc.fixed():Zt.RigidBodyDesc.dynamic();i.setTranslation(t.x,t.y),t.rotation!==void 0&&i.setRotation(t.rotation);const o=this.world.createRigidBody(i);let e;switch(t.type){case"Rectangle":e=Zt.ColliderDesc.cuboid(t.width/2,t.height/2);break;case"Ellipse":e=Zt.ColliderDesc.ball(Math.max(t.width,t.height)/2);break;case"Triangle":case"Star":case"Polygon":e=Zt.ColliderDesc.cuboid(t.width/2,t.height/2);break;default:e=Zt.ColliderDesc.cuboid(t.width/2,t.height/2)}if(t.friction!==void 0&&e.setFriction(t.friction),t.restitution!==void 0&&e.setRestitution(t.restitution),t.density!==void 0)e.setDensity(t.density);else if(t.mass!==void 0&&!t.isStatic){const n=t.width*t.height;e.setDensity(t.mass/n)}t.isSensor&&e.setSensor(!0);const s=this.world.createCollider(e,o);this.bodyIdByCollider.set(s.handle,t.id),t.frictionAir!==void 0&&o.setLinearDamping(t.frictionAir*10),this.bodies.set(t.id,o),this.colliders.set(t.id,s)}removeBody(t){const i=this.bodies.get(t),o=this.colliders.get(t);o&&this.bodyIdByCollider.delete(o.handle),i&&this.world&&(this.world.removeRigidBody(i),this.bodies.delete(t),this.colliders.delete(t))}step(t){if(!this.world)return;this.world.step(this.eventQueue);const i=this.onCollisionCB,o=this.eventQueue;i&&o&&o.drainContactEvents((e,s,n)=>{const a=this.bodyIdByCollider.get(e),r=this.bodyIdByCollider.get(s);a&&r&&i(a,r,n)})}getPosition(t){const i=this.bodies.get(t);if(!i)return null;const o=i.translation();return{x:o.x,y:o.y}}getRotation(t){const i=this.bodies.get(t);return i?i.rotation():null}getVelocity(t){const i=this.bodies.get(t);if(!i)return null;const o=i.linvel();return{x:o.x,y:o.y}}setPosition(t,i,o){const e=this.bodies.get(t);e&&e.setTranslation(new Zt.Vector2(i,o),!0)}setRotation(t,i){const o=this.bodies.get(t);o&&o.setRotation(i,!0)}setVelocity(t,i,o){const e=this.bodies.get(t);e&&e.setLinvel(new Zt.Vector2(i,o),!0)}setAngularVelocity(t,i){const o=this.bodies.get(t);o&&o.setAngvel(i,!0)}applyForce(t,i,o){const e=this.bodies.get(t);e&&e.addForce(new Zt.Vector2(i,o),!0)}applyImpulse(t,i,o){const e=this.bodies.get(t);e&&e.applyImpulse(new Zt.Vector2(i,o),!0)}createJoint(t){if(!this.world){console.warn("[RapierPhysics] World not initialized");return}this.joints.has(t.id)&&this.removeJoint(t.id);const i=this.bodies.get(t.bodyA),o=this.bodies.get(t.bodyB);if(!i||!o){console.warn(`[RapierPhysics] Cannot create joint ${t.id}: bodyA (${t.bodyA}) or bodyB (${t.bodyB}) not found`);return}const e=new Zt.Vector2(t.anchorA.x,t.anchorA.y),s=new Zt.Vector2(t.anchorB.x,t.anchorB.y);let n;if(t.type==="Distance"){const a=t.length??100,r=t.stiffness??100,c=t.damping??10;n=Zt.JointData.spring(a,r,c,e,s)}else n=Zt.JointData.revolute(e,s);try{const a=this.world.createImpulseJoint(n,i,o,!0);this.joints.set(t.id,a)}catch(a){console.error(`[RapierPhysics] Failed to create joint ${t.id}:`,a)}}removeJoint(t){const i=this.joints.get(t);if(i&&this.world){try{this.world.removeImpulseJoint(i,!0)}catch(o){console.error(`[RapierPhysics] Failed to remove joint ${t}:`,o)}this.joints.delete(t)}}}const ss=g=>g,_s=g=>g>0?1:0,Ps=g=>g<1?0:1,is=g=>g*g,ns=g=>g*(2-g),os=g=>g<.5?2*g*g:-1+(4-2*g)*g,Es=g=>g*g*g,As=g=>--g*g*g+1,Os=g=>g<.5?4*g*g*g:(g-1)*(2*g-2)*(2*g-2)+1,xs=g=>g*g*g*g,Ls=g=>1- --g*g*g*g,Rs=g=>g<.5?8*g*g*g*g:1-8*--g*g*g*g,Fs=g=>g*g*g*g*g,$s=g=>1+--g*g*g*g*g,Ws=g=>g<.5?16*g*g*g*g*g:1+16*--g*g*g*g*g,Bs=g=>1-Math.cos(g*Math.PI/2),Ys=g=>Math.sin(g*Math.PI/2),Xs=g=>-(Math.cos(Math.PI*g)-1)/2,Gs=g=>g===0?0:Math.pow(2,10*(g-1)),Ds=g=>g===1?1:1-Math.pow(2,-10*g),zs=g=>g===0?0:g===1?1:g<.5?Math.pow(2,20*g-10)/2:(2-Math.pow(2,-20*g+10))/2,Vs=g=>1-Math.sqrt(1-g*g),Ns=g=>Math.sqrt(1- --g*g),Hs=g=>g<.5?(1-Math.sqrt(1-4*g*g))/2:(Math.sqrt(1-(-2*g+2)*(-2*g+2))+1)/2,Ge=1.70158,De=Ge*1.525,as=Ge+1,Us=g=>as*g*g*g-Ge*g*g,qs=g=>1+as*Math.pow(g-1,3)+Ge*Math.pow(g-1,2),Js=g=>g<.5?Math.pow(2*g,2)*((De+1)*2*g-De)/2:(Math.pow(2*g-2,2)*((De+1)*(g*2-2)+De)+2)/2,rs=2*Math.PI/3,ls=2*Math.PI/4.5,Qs=g=>g===0?0:g===1?1:-Math.pow(2,10*g-10)*Math.sin((g*10-10.75)*rs),Ks=g=>g===0?0:g===1?1:Math.pow(2,-10*g)*Math.sin((g*10-.75)*rs)+1,Zs=g=>g===0?0:g===1?1:g<.5?-(Math.pow(2,20*g-10)*Math.sin((20*g-11.125)*ls))/2:Math.pow(2,-20*g+10)*Math.sin((20*g-11.125)*ls)/2+1,ze=g=>g<1/2.75?7.5625*g*g:g<2/2.75?7.5625*(g-=1.5/2.75)*g+.75:g<2.5/2.75?7.5625*(g-=2.25/2.75)*g+.9375:7.5625*(g-=2.625/2.75)*g+.984375,js=g=>1-ze(1-g),ti=ze,ei=g=>g<.5?(1-ze(1-2*g))/2:(1+ze(2*g-1))/2,Qe=new Map,$e=(g,t,i,o)=>{const e=`${g},${t},${i},${o}`;if(Qe.has(e))return Qe.get(e);const s=l=>(1-3*i+3*g)*l*l*l+(3*i-6*g)*l*l+3*g*l,n=l=>(1-3*o+3*t)*l*l*l+(3*o-6*t)*l*l+3*t*l,a=l=>3*(1-3*i+3*g)*l*l+2*(3*i-6*g)*l+3*g,r=l=>{let h=l;for(let u=0;u<8;u++){const f=s(h)-l;if(Math.abs(f)<1e-6)return h;const d=a(h);if(Math.abs(d)<1e-6)break;h=h-f/d}return h},c=l=>l===0?0:l===1?1:n(r(l));return Qe.set(e,c),c},cs=g=>{const t=g.match(/cubic-bezier\s*\(\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*\)/);if(!t)return null;const[,i,o,e,s]=t.map(Number);return $e(i,o,e,s)},fs={ease:$e(.25,.1,.25,1),"ease-in":$e(.42,0,1,1),"ease-out":$e(0,0,.58,1),"ease-in-out":$e(.42,0,.58,1)},Ve={Linear:ss,EaseInQuad:is,EaseOutQuad:ns,EaseInOutQuad:os,EaseInCubic:Es,EaseOutCubic:As,EaseInOutCubic:Os,EaseInQuart:xs,EaseOutQuart:Ls,EaseInOutQuart:Rs,EaseInQuint:Fs,EaseOutQuint:$s,EaseInOutQuint:Ws,EaseInSine:Bs,EaseOutSine:Ys,EaseInOutSine:Xs,EaseInExpo:Gs,EaseOutExpo:Ds,EaseInOutExpo:zs,EaseInCirc:Vs,EaseOutCirc:Ns,EaseInOutCirc:Hs,EaseInBack:Us,EaseOutBack:qs,EaseInOutBack:Js,EaseInElastic:Qs,EaseOutElastic:Ks,EaseInOutElastic:Zs,EaseInBounce:js,EaseOutBounce:ti,EaseInOutBounce:ei,EaseIn:is,EaseOut:ns,EaseInOut:os,StepStart:_s,StepEnd:Ps},si=g=>{const t=g.trim(),i=t.toLowerCase();if(Ve[t])return Ve[t];const o=Object.keys(Ve).find(s=>s.toLowerCase()===i);if(o)return Ve[o];const e=Object.keys(hs).find(s=>s.toLowerCase()===i);if(e){const s=cs(hs[e].value);if(s)return s}if(fs[i])return fs[i];if(i.startsWith("cubic-bezier")){const s=cs(t);if(s)return s}return ss},hs={Snappy:{label:"Snappy",description:"High energy, quick arrival.",value:"cubic-bezier(0.2, 1, 0.2, 1)"},Bouncy:{label:"Bouncy",description:"Springy with an overshoot.",value:"cubic-bezier(0.2, 0.9, 0.4, 1.3)"},Gentle:{label:"Gentle",description:"Smooth and organic flow.",value:"cubic-bezier(0.4, 0, 0.6, 1)"},Stiff:{label:"Stiff",description:"Solid and reliable movement.",value:"cubic-bezier(0.3, 1, 0.7, 1)"},Floating:{label:"Floating",description:"Weightless and airy transition.",value:"cubic-bezier(0.5, 0, 0.5, 1)"},Sudden:{label:"Sudden",description:"Instant, direct movement.",value:"cubic-bezier(1, 0, 1, 1)"},Elastic:{label:"Elastic",description:"Extreme overshoot and spring.",value:"cubic-bezier(0.5, 1.5, 0.5, 1.5)"},Sharp:{label:"Sharp",description:"Fast start, very hard stop.",value:"cubic-bezier(0.1, 0.9, 0.1, 1)"},Fluid:{label:"Fluid",description:"Natural high-end flow.",value:"cubic-bezier(0.4, 0, 0.2, 1)"},Heavy:{label:"Heavy",description:"Slow start, massive impact.",value:"cubic-bezier(0.6, 0, 1, 1)"}},ii=(g,t,i,o,e)=>{if(!g||!t||!i)return g;const s=o.scale_x??1,n=o.scale_y??1,a=(r,c,l)=>{let h=0,u=0;const f=o.rotation*Math.PI/180,d=Math.cos(f),p=Math.sin(f),y=r*s*d-c*n*p+o.x,m=r*s*p+c*n*d+o.y;l.forEach(I=>{const k=e(I.boneId);if(!k)return;const T={x:k.x,y:k.y,rotation:k.rotation,scaleX:k.scale_x??1,scaleY:k.scale_y??1},x=i[I.boneId]||[1,0,0,1,0,0],P=y*x[0]+m*x[2]+x[4],E=y*x[1]+m*x[3]+x[5],L=T.rotation*Math.PI/180,O=Math.cos(L),W=Math.sin(L),B=P*T.scaleX*O-E*T.scaleY*W+T.x,$=P*T.scaleX*W+E*T.scaleY*O+T.y;h+=B*I.amount,u+=$*I.amount});const b=[...l].sort((I,k)=>k.amount-I.amount);if(b.length>=2&&b[0].amount>0&&b[1].amount>0){const I=e(b[0].boneId),k=e(b[1].boneId);if(I&&k&&I.length!==void 0&&k.length!==void 0){const T=I.length*(I.scale_y??1),x=I.rotation*Math.PI/180,P=I.x-T*Math.sin(x),E=I.y+T*Math.cos(x),L=k.length*(k.scale_y??1),O=k.rotation*Math.PI/180,W=k.x-L*Math.sin(O),B=k.y+L*Math.cos(O);let $=null,Y=null,H=!1;const K=1;if(Math.hypot(I.x-k.x,I.y-k.y)<K||Math.hypot(I.x-W,I.y-B)<K?($=I.x,Y=I.y):(Math.hypot(P-k.x,E-k.y)<K||Math.hypot(P-W,E-B)<K)&&($=P,Y=E,H=!0),$!==null&&Y!==null){const A=i[b[0].boneId]||[1,0,0,1,0,0],_=A[0]*A[3]-A[1]*A[2];let R=0,X=0;if(_!==0){const N=(A[2]*A[5]-A[3]*A[4])/_,it=(A[1]*A[4]-A[0]*A[5])/_,lt=Math.atan2(-A[1],A[3]);if(!H)R=N,X=it;else{const ft=-A[2]/_,wt=A[0]/_,It=Math.hypot(ft,wt),Mt=I.length*It;R=N-Mt*Math.sin(lt),X=it+Mt*Math.cos(lt)}const nt=Math.hypot(y-R,m-X),bt=Math.hypot(h-$,u-Y);if(bt>0&&nt>0){const ft=Math.max(bt,.01),wt=Math.min(nt/ft,3),It=$+(h-$)*wt,Mt=Y+(u-Y)*wt,xt=b[0].amount,At=b[1].amount,Tt=Math.min(xt,At)*2,Nt=1-Math.pow(1-Tt,4);h=h*(1-Nt)+It*Nt,u=u*(1-Nt)+Mt*Nt}}}}}const v=o.rotation*Math.PI/180,S=Math.cos(v),C=Math.sin(v),w=h-o.x,M=u-o.y;return{x:(w*S+M*C)/s,y:(-w*C+M*S)/n}};return g.map((r,c)=>{const l=t[c];if(!l||l.length===0)return{...r};const h={...r,...a(r.x,r.y,l)};if(r.in_x!==void 0&&r.in_y!==void 0){const u=a(r.in_x,r.in_y,l);h.in_x=u.x,h.in_y=u.y}if(r.out_x!==void 0&&r.out_y!==void 0){const u=a(r.out_x,r.out_y,l);h.out_x=u.x,h.out_y=u.y}return h})},ds={default:{label:"Default",colors:["#6366f1","#f59e0b"],cardBackground:"rgba(255,255,255,0.04)",cardBorderColor:"rgba(255,255,255,0.08)",gridColor:"rgba(255,255,255,0.06)",axisLabelColor:"rgba(255,255,255,0.5)",legendColor:"rgba(255,255,255,0.7)",barGradient:!0},neon:{label:"Neon",colors:["#00f5ff","#ff00e5"],cardBackground:"rgba(0,0,0,0.5)",cardBorderColor:"rgba(0,245,255,0.2)",gridColor:"rgba(0,245,255,0.08)",axisLabelColor:"rgba(0,245,255,0.6)",legendColor:"rgba(0,245,255,0.8)",barGradient:!0},pastel:{label:"Pastel",colors:["#a5b4fc","#fcd34d"],cardBackground:"rgba(255,255,255,0.06)",cardBorderColor:"rgba(255,255,255,0.12)",gridColor:"rgba(255,255,255,0.08)",axisLabelColor:"rgba(255,255,255,0.45)",legendColor:"rgba(255,255,255,0.65)",barGradient:!1},warm:{label:"Warm",colors:["#f97316","#ef4444"],cardBackground:"rgba(30,10,0,0.4)",cardBorderColor:"rgba(249,115,22,0.2)",gridColor:"rgba(249,115,22,0.08)",axisLabelColor:"rgba(253,186,116,0.7)",legendColor:"rgba(253,186,116,0.85)",barGradient:!0},ocean:{label:"Ocean",colors:["#06b6d4","#0ea5e9"],cardBackground:"rgba(0,20,40,0.5)",cardBorderColor:"rgba(6,182,212,0.2)",gridColor:"rgba(6,182,212,0.06)",axisLabelColor:"rgba(125,211,252,0.6)",legendColor:"rgba(125,211,252,0.8)",barGradient:!0},mono:{label:"Mono",colors:["rgba(255,255,255,0.9)","rgba(255,255,255,0.4)"],cardBackground:"rgba(255,255,255,0.03)",cardBorderColor:"rgba(255,255,255,0.1)",gridColor:"rgba(255,255,255,0.05)",axisLabelColor:"rgba(255,255,255,0.4)",legendColor:"rgba(255,255,255,0.6)",barGradient:!1}},us={default:{label:"Default",colors:["#6366f1","#22d3ee","#f59e0b","#ec4899","#34d399"],cardBackground:"rgba(255,255,255,0.04)",cardBorderColor:"rgba(255,255,255,0.08)",legendColor:"rgba(255,255,255,0.65)",labelColor:"#ffffff",centerTextColor:"#ffffff",centerLabelColor:"rgba(255,255,255,0.4)"},neon:{label:"Neon",colors:["#00f5ff","#ff00e5","#00ff9f","#ff6b00","#b400ff"],cardBackground:"rgba(0,0,0,0.55)",cardBorderColor:"rgba(0,245,255,0.2)",legendColor:"rgba(0,245,255,0.75)",labelColor:"#ffffff",centerTextColor:"#00f5ff",centerLabelColor:"rgba(0,245,255,0.5)"},pastel:{label:"Pastel",colors:["#a5b4fc","#67e8f9","#fcd34d","#f9a8d4","#6ee7b7"],cardBackground:"rgba(255,255,255,0.06)",cardBorderColor:"rgba(255,255,255,0.12)",legendColor:"rgba(255,255,255,0.6)",labelColor:"#1a1a2e",centerTextColor:"#ffffff",centerLabelColor:"rgba(255,255,255,0.45)"},warm:{label:"Warm",colors:["#f97316","#ef4444","#f59e0b","#dc2626","#fb923c"],cardBackground:"rgba(30,10,0,0.45)",cardBorderColor:"rgba(249,115,22,0.2)",legendColor:"rgba(253,186,116,0.8)",labelColor:"#ffffff",centerTextColor:"#fb923c",centerLabelColor:"rgba(253,186,116,0.5)"},ocean:{label:"Ocean",colors:["#06b6d4","#0ea5e9","#38bdf8","#7dd3fc","#0284c7"],cardBackground:"rgba(0,20,40,0.5)",cardBorderColor:"rgba(6,182,212,0.2)",legendColor:"rgba(125,211,252,0.75)",labelColor:"#ffffff",centerTextColor:"#38bdf8",centerLabelColor:"rgba(125,211,252,0.5)"},mono:{label:"Mono",colors:["rgba(255,255,255,0.9)","rgba(255,255,255,0.65)","rgba(255,255,255,0.45)","rgba(255,255,255,0.28)","rgba(255,255,255,0.15)"],cardBackground:"rgba(255,255,255,0.03)",cardBorderColor:"rgba(255,255,255,0.1)",legendColor:"rgba(255,255,255,0.55)",labelColor:"#000000",centerTextColor:"#ffffff",centerLabelColor:"rgba(255,255,255,0.4)"}};class ps{constructor(){ot(this,"artboard",null);ot(this,"objectStates",new Map);ot(this,"physicsEngine",null);ot(this,"activeStateMachine",null);ot(this,"inputs",new Map);ot(this,"inputNameMap",new Map);ot(this,"layerStates",new Map);ot(this,"pretextCache",new Map);ot(this,"pointerHistory",[]);ot(this,"MAX_HISTORY",200);ot(this,"imageCache",new Map);ot(this,"lastValidSvgImgMap",new Map);ot(this,"maskBuffer",null);ot(this,"maskCtx",null);ot(this,"lumaBuffer",null);ot(this,"lumaCtx",null);ot(this,"_noiseTileCanvas",null);ot(this,"layout",{fit:"Contain",alignment:"Center"});ot(this,"onTrigger");ot(this,"onInputUpdate");ot(this,"onComponentChange");ot(this,"onToggle");ot(this,"onInputChange");ot(this,"onInputFocus");ot(this,"onInputBlur");ot(this,"onLog");ot(this,"onButtonClick");ot(this,"onGraphPointClick");ot(this,"justFiredTriggers",new Set);ot(this,"rootTransform",null);ot(this,"canvasWidth",0);ot(this,"canvasHeight",0);ot(this,"lastHoveredObjectId",null);ot(this,"_lastPointerPos",null);ot(this,"_prevPointerPos",null);ot(this,"focusedId",null);ot(this,"draggingSliderId",null);ot(this,"draggingJoystickId",null);ot(this,"activeDropdownId",null);ot(this,"activeObjectId",null);ot(this,"draggingListViewId",null);ot(this,"scrollOffset",{x:0,y:0});ot(this,"_totalScroll",{x:0,y:0});ot(this,"draggingBehaviors",new Set);ot(this,"isMouseDown",!1);ot(this,"activeKeys",new Set);ot(this,"_layoutAnimCache",new Map);ot(this,"_springChainState",new Map);ot(this,"_emitterPools",new Map);ot(this,"objectVelocities",new Map);ot(this,"currentTime",0);ot(this,"frameCount",0);ot(this,"fontLeadingFactors",{Inter:.35,Roboto:.45,Montserrat:.4,Outfit:.35,"Open Sans":.4,Poppins:.45,"Playfair Display":.35,Lora:.4,Lato:.35,"Bebas Neue":.45,Oswald:.4});ot(this,"onLogicUpdate");ot(this,"logicNodeValues",new Map);ot(this,"logicNodeState",new Map);ot(this,"pointerDownTimes",new Map);ot(this,"activeHoverIds",new Set);ot(this,"onNavigation");ot(this,"periodicTriggerTimes",new Map);ot(this,"wasInView",new Set);ot(this,"scrollProgressLastValue",new Map);ot(this,"debug_objectsRendered",0);ot(this,"debug_objectsTotal",0);ot(this,"lastRenderTime",0);ot(this,"debugMode",!1);ot(this,"activeTriggers",new Map);console.info("%c[ExodeUI Engine] Pixel-Perfect Parity Active (v6.3.10) - SVG Fill & Gradient Parity Active","color: #3b82f6; font-weight: bold; padding: 2px 4px; border-radius: 4px; background: rgba(59, 130, 246, 0.1)")}setTriggerCallback(t){this.onTrigger=t}setInputUpdateCallback(t){this.onInputUpdate=t}setComponentChangeCallback(t){this.onComponentChange=t}setToggleCallback(t){this.onToggle=t}setLogicUpdateCallback(t){this.onLogicUpdate=t}setInputChangeCallback(t){this.onInputChange=t}setButtonClickCallback(t){this.onButtonClick=t}setGraphPointClickCallback(t){this.onGraphPointClick=t}setNavigationCallback(t){this.onNavigation=t}ensurePathPoints(t){if(!t||t.type!=="Path"&&t.type!=="Subtract"&&t.type!=="Union"&&t.type!=="Intersect"&&t.type!=="Exclude"&&t.type!=="BooleanOperation")return;if(t.points&&t.points.length>0){if(t.is_closed===void 0&&t.isClosed===void 0&&t.data){const{isClosed:e}=this.svgPathToPoints(t.data);t.is_closed=e}return}if(!t.data)return;const{points:i,isClosed:o}=this.svgPathToPoints(t.data);t.points=i,t.is_closed===void 0&&(t.is_closed=o)}svgPathToPoints(t){const i=/([MLHVCSQTAZmlhvcsqtaz])([^MLHVCSQTAZmlhvcsqtaz]*)/g,o=/[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/g,e=[];let s=!1,n=0,a=0,r=0,c=0,l=0,h=0,u;for(;(u=i.exec(t))!==null;){const f=u[1],d=(u[2].match(o)||[]).map(parseFloat),p=f===f.toLowerCase(),y=f.toUpperCase();let m=0;const b=S=>{let C=d[m++];return p&&(C+=S?n:a),C},v=()=>({x:b(!0),y:b(!1)});switch(y){case"M":{const S=v();for(l=n=S.x,h=a=S.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a,moveTo:!0});m<d.length;){const C=v();n=C.x,a=C.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}case"L":for(;m<d.length;){const S=v();n=S.x,a=S.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break;case"H":for(;m<d.length;)n=b(!0),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"V":for(;m<d.length;)a=b(!1),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"C":for(;m<d.length;){const S=v(),C=v(),w=v();if(e.length>0){const M=e[e.length-1];M.out_x=S.x,M.out_y=S.y}n=w.x,a=w.y,e.push({x:n,y:a,in_x:C.x,in_y:C.y,out_x:n,out_y:a}),r=C.x,c=C.y}break;case"S":for(;m<d.length;){const S={x:2*n-r,y:2*a-c},C=v(),w=v();if(e.length>0){const M=e[e.length-1];M.out_x=S.x,M.out_y=S.y}n=w.x,a=w.y,e.push({x:n,y:a,in_x:C.x,in_y:C.y,out_x:n,out_y:a}),r=C.x,c=C.y}break;case"Q":for(;m<d.length;){const S=v(),C=v();if(e.length>0){const w=e[e.length-1];w.out_x=w.x+2/3*(S.x-w.x),w.out_y=w.y+2/3*(S.y-w.y)}n=C.x,a=C.y,e.push({x:n,y:a,in_x:n+2/3*(S.x-n),in_y:a+2/3*(S.y-a),out_x:n,out_y:a}),r=S.x,c=S.y}break;case"T":for(;m<d.length;){const S={x:2*n-r,y:2*a-c},C=v();if(e.length>0){const w=e[e.length-1];w.out_x=w.x+2/3*(S.x-w.x),w.out_y=w.y+2/3*(S.y-w.y)}n=C.x,a=C.y,e.push({x:n,y:a,in_x:n+2/3*(S.x-n),in_y:a+2/3*(S.y-a),out_x:n,out_y:a}),r=S.x,c=S.y}break;case"Z":if(s=!0,e.length>0){const S=e[e.length-1];S.closePath=!0;const C=[...e].reverse().find(w=>w.moveTo)||e[0];C&&Math.hypot(C.x-S.x,C.y-S.y)<.1&&(C.in_x=S.in_x,C.in_y=S.in_y,e.pop(),e.length>0&&(e[e.length-1].closePath=!0))}n=l,a=h;break;default:if(d.length>=2){const S=v();n=S.x,a=S.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}}return{points:e,isClosed:s}}setOnLogCallback(t){this.onLog=t}debugLog(t){this.onLog&&this.onLog(t)}setInputFocusCallback(t){this.onInputFocus=t}setInputBlurCallback(t){this.onInputBlur=t}updateConstraint(t,i,o){var s;const e=(s=this.artboard)==null?void 0:s.objects.find(n=>n.id===t);e&&e.constraints&&e.constraints[i]&&(e.constraints[i]={...e.constraints[i],...o},o.useSpring===!1&&this.objectVelocities.delete(t))}log(...t){this.debugMode&&console.log(...t)}warn(...t){this.debugMode&&console.warn(...t)}setInternalInput(t,i){this.inputs.set(t,i),this.onInputUpdate&&this.onInputUpdate(t,i)}setLayout(t,i){this.layout={fit:t,alignment:i}}getActiveStateIds(t="Base Layer"){const i=this.layerStates.get(t);return i?i.currentStateIds:[]}getObjectState(t){return this.objectStates.get(t)}updateObjectOptions(t,i){const o=this.objectStates.get(t);o&&(o.options={...o.options,...i})}updateGraphData(t,i){var e,s;if(!this.artboard)return;const o=this.artboard.objects.find(n=>n.id===t||n.name===t);if(o&&((e=o.geometry)==null?void 0:e.type)==="LineGraph"){const n=o.geometry;!n.datasets||n.datasets.length===0?n.datasets=[{id:"default",label:"Runtime Data",data:i,lineColor:"#3b82f6",lineWidth:2,showArea:!1}]:n.datasets[0].data=i;const a=this.objectStates.get(o.id);a&&((s=a.geometry)==null?void 0:s.type)==="LineGraph"&&(!a.geometry.datasets||a.geometry.datasets.length===0?a.geometry.datasets=JSON.parse(JSON.stringify(n.datasets)):a.geometry.datasets[0].data=[...i]),n.datasets[0].inputId&&this.updateInput(n.datasets[0].inputId,i)}else this.updateInput(t,i)}load(t){var n,a;if(!t)return;let i=this.decompressStrings(t);const o=[],e=new Set,s=r=>{r&&r.forEach(c=>{if(e.has(c.id))return;const l={...c},h=l.childrenObjects||[];e.add(l.id),o.push(l),s(h)})};if(s(i.objects||[]),o.length>(i.objects||[]).length&&this.log(`[Engine] Flattened artboard from ${(i.objects||[]).length} to ${o.length} objects.`),i.objects=o,this.artboard=i,this.currentTime=0,this.objectStates.clear(),this.log(`[ExodeUIEngine] Loading artboard: "${(n=this.artboard)==null?void 0:n.name}" with ${(a=this.artboard)==null?void 0:a.objects.length} objects`),this.artboard&&this.artboard.objects){const r=new Map;this.artboard.objects.forEach(c=>{r.set(c.id,c),c.children||(c.children=[])}),this.artboard.objects.forEach(c=>{if(c.parentId){const l=r.get(c.parentId);l&&(l.children||(l.children=[]),l.children.includes(c.id)||l.children.push(c.id))}})}this.loadFonts(),this.preloadImages(this.artboard),this.reset(),this.advance(0)}preloadImages(t){if(!t||!t.objects)return;const i=o=>{if(!o||this.imageCache.has(o))return;const e=new Image;e.onload=()=>{this.log(`[ExodeUI Preload] loaded ${e.naturalWidth}x${e.naturalHeight}`)},e.onerror=s=>{console.error("[ExodeUI Preload] failed:",s,`Src: ${o.substring(0,80)}...`)},e.src=o,this.imageCache.set(o,e)};t.objects.forEach(o=>{var e,s,n;(e=o.geometry)!=null&&e.src&&i(o.geometry.src),(n=(s=o.style)==null?void 0:s.fill)!=null&&n.src&&i(o.style.fill.src)})}decompressStrings(t){if(t&&typeof t=="object"&&!Array.isArray(t)){if(t._compressed&&t._data)try{const o=Ss.decompressFromBase64(t._data);if(o)return o}catch(o){return console.error("[ExodeUI] Failed to decompress string:",o),t._data}const i={};for(const[o,e]of Object.entries(t))i[o]=this.decompressStrings(e);return i}return Array.isArray(t)?t.map(i=>this.decompressStrings(i)):t}reset(){if(!this.artboard)return;if(this.objectStates.clear(),this.objectVelocities.clear(),this.currentTime=0,this.inputs.clear(),this.inputNameMap.clear(),this.layerStates.clear(),this.logicNodeValues.clear(),this.justFiredTriggers.clear(),this.inputs.set("mouseX",0),this.inputs.set("mouseY",0),this.inputs.set("scrollX",0),this.inputs.set("scrollY",0),this.inputs.set("isMouseDown",!1),this.physicsEngine&&(this.physicsEngine.destroy(),this.physicsEngine=null),this._layoutAnimCache.clear(),this._springChainState.clear(),this._emitterPools.clear(),this.artboard.objects.forEach(i=>{var n,a,r,c,l,h,u;const o=i.width??((n=i.geometry)==null?void 0:n.width)??0,e=i.height??((a=i.geometry)==null?void 0:a.height)??0,s=i.cornerRadius??i.corner_radius??((r=i.geometry)==null?void 0:r.corner_radius)??((c=i.geometry)==null?void 0:c.cornerRadius)??0;this.objectStates.set(i.id,{...i.transform||{},x:((l=i.transform)==null?void 0:l.x)??i.x??0,y:((h=i.transform)==null?void 0:h.y)??i.y??0,width:o,height:e,cornerRadius:s,corner_radius:s,clipContent:i.clipContent??!1,autoLayout:i.autoLayout?JSON.parse(JSON.stringify(i.autoLayout)):void 0,layoutProps:i.layoutProps?JSON.parse(JSON.stringify(i.layoutProps)):void 0,opacity:((u=i.transform)==null?void 0:u.opacity)!==void 0?i.transform.opacity:i.opacity!==void 0?i.opacity:100,visible:i.visible!==void 0?i.visible:i.isVisible!==void 0?i.isVisible:!0,blendMode:i.blendMode||"Normal",style:JSON.parse(JSON.stringify(i.style||{})),geometry:JSON.parse(JSON.stringify(i.geometry||{})),options:i.options?JSON.parse(JSON.stringify(i.options)):{},masks:i.masks?JSON.parse(JSON.stringify(i.masks)):[],zIndex:i.zIndex!==void 0?i.zIndex:void 0})}),this.artboard.objects.some(i=>{var o;return(o=i.physics)==null?void 0:o.enabled})){this.physicsEngine=new es;const i=this.artboard.physics?{x:this.artboard.physics.gravity.x,y:this.artboard.physics.gravity.y}:{x:0,y:1};this.physicsEngine.init(i).then(()=>{var o;this.physicsEngine&&((o=this.artboard)==null||o.objects.forEach(e=>{var s,n;if((s=e.physics)!=null&&s.enabled&&e.type==="Shape"){const a=this.objectStates.get(e.id);if(!a)return;const r=e.geometry.width||100,c=e.geometry.height||100;this.physicsEngine.createBody({id:e.id,type:((n=e.geometry)==null?void 0:n.type)||"Rectangle",x:a.x,y:a.y,width:r,height:c,rotation:a.rotation*(Math.PI/180),isStatic:e.physics.bodyType==="Static",mass:e.physics.mass,friction:e.physics.friction,restitution:e.physics.restitution,frictionAir:e.physics.frictionAir,density:e.physics.density,isSensor:e.physics.isSensor})}}))})}this.artboard.stateVariables&&this.artboard.stateVariables.forEach(i=>{this.inputs.set(i.id,i.value);const o=this.inputNameMap.get(i.name)||[];o.includes(i.id)||o.push(i.id),this.inputNameMap.set(i.name,o)}),this.artboard.stateMachine&&(this.activeStateMachine=this.artboard.stateMachine,this.activeStateMachine.inputs.forEach(i=>{this.inputs.set(i.id,i.value.value);const o=this.inputNameMap.get(i.name)||[];o.push(i.id),this.inputNameMap.set(i.name,o)}),this.activeStateMachine.layers.forEach(i=>{let o=i.states.find(e=>e.id===i.entryStateId);!o&&i.states.length>0&&(console.warn(`[ExodeUI] Invalid entryStateId "${i.entryStateId}" in layer "${i.name}". Falling back to first state.`),o=i.states[0]),o&&this.enterStates(i.name,[o.id])}),this.evaluateTransitions()),this.initGlobalAnimationTriggers(),this.updateAutoLayout(!0),this.loadFonts()}updateAutoLayout(t=!1){var s;if(!this.artboard)return;const i=new Map;this.artboard.objects.forEach(n=>i.set(n.id,n));const o=.15,e=n=>{n.forEach(a=>{const r=this.objectStates.get(a.id);if(r){const c=Math.abs(r.x-a.x),l=Math.abs(r.y-a.y);!t&&(c>20||l>20)?(r.x+=(a.x-r.x)*o,r.y+=(a.y-r.y)*o):(r.x=a.x,r.y=a.y),a.width!==void 0&&(r.width=a.width),a.height!==void 0&&(r.height=a.height)}})};if((s=this.artboard.autoLayout)!=null&&s.enabled){const n=this.artboard.objects.filter(r=>!r.parentId),a=ts(this.artboard,n,r=>this.objectStates.get(r));e(a.childUpdates)}this.artboard.objects.forEach(n=>{var a;if(n.type==="Frame"&&((a=n.autoLayout)!=null&&a.enabled)&&n.children&&n.children.length>0){const r=n.children.map(h=>i.get(h)).filter(h=>!!h),c=this.objectStates.get(n.id);if(!c)return;const l=ts(c,r,h=>this.objectStates.get(h));l.frameWidth!==void 0&&(c.width=l.frameWidth),l.frameHeight!==void 0&&(c.height=l.frameHeight),e(l.childUpdates)}})}loadFonts(){if(!this.artboard)return;const t=new Set;if(this.artboard.objects.forEach(n=>{n.geometry&&n.geometry.type==="Text"&&n.geometry.fontFamily&&t.add(n.geometry.fontFamily)}),this.artboard.animations.forEach(n=>{n.tracks.forEach(a=>{(a.property==="geometry.fontFamily"||a.property==="fontFamily")&&a.keyframes.forEach(r=>{r.value&&typeof r.value=="string"&&t.add(r.value)})})}),t.size===0)return;let i="";t.forEach(n=>{const a=n.replace(/ /g,"+");i+=`&family=${a}:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900`});const o="exodeui-google-fonts",e="exodeui-fontshare-fonts";if(i.length>0){const n=`https://fonts.googleapis.com/css2?display=swap${i}`;let a=document.getElementById(o);a||(a=document.createElement("link"),a.id=o,a.rel="stylesheet",document.head.appendChild(a)),a.href!==n&&(a.href=n)}const s=[];if(t.forEach(n=>{n.toLowerCase().includes("clash display")&&s.push("clash-display@200,300,400,500,600,700")}),s.length>0){const n=`https://api.fontshare.com/v2/css?f[]=${s.join("&f[]=")}&display=swap`;let a=document.getElementById(e);a||(a=document.createElement("link"),a.id=e,a.rel="stylesheet",document.head.appendChild(a)),a.href!==n&&(a.href=n)}document.fonts&&document.fonts.ready&&document.fonts.ready.then(()=>{this.pretextCache.clear(),this.advance(0)})}enterStates(t,i){var n;if(i.length===0)return;const o=this.layerStates.get(t);if(o&&o.currentStateIds.length===i.length&&i.every(r=>o.currentStateIds.includes(r))&&this.justFiredTriggers.size===0)return;const e=[];let s=0;if(this.artboard&&this.activeStateMachine){const a=this.activeStateMachine.layers.find(r=>r.name===t);if(a)for(const r of i){const c=a.states.find(l=>l.id===r);if(c)if(c.isBlendState&&c.blendAnimations&&c.blendAnimations.length>0)e.push({animation:null,state:c}),c.blendAnimations.forEach(l=>{const h=this.artboard.animations.find(u=>u.id===l.animationId);h&&(s=Math.max(s,h.duration))});else{let l=null;c.animationId&&(l=this.artboard.animations.find(h=>h.id===c.animationId)||null),l||(l=this.artboard.animations.find(h=>{var u,f;return h.name===c.name||h.id===c.name||(c.name==="Entry"||c.id==="entry")&&(((u=h.name)==null?void 0:u.toLowerCase())==="onload"||((f=h.name)==null?void 0:f.toLowerCase())==="intro")})||null),l&&((n=this.artboard.animationFlow)!=null&&n.some(u=>(u.trigger==="on_load"||u.trigger==="after_delay")&&u.targetAnimationId===(l==null?void 0:l.id))||(e.push({animation:l,state:c}),s=Math.max(s,l.duration)))}}}this.layerStates.set(t,{currentStateIds:i,animations:e,time:0,duration:s})}setInputBool(t,i){this.updateInput(t,i)}setInputNumber(t,i){this.updateInput(t,i)}fireTrigger(t){this.updateInput(t,!0)}setInputText(t,i){this.updateInput(t,i)}setInputNumberArray(t,i){this.updateInput(t,i)}setInputStringArray(t,i){this.updateInput(t,i)}updateObjectProperty(t,i,o){const e=this.objectStates.get(t);if(e)if(i.includes(".")){const s=i.split(".");let n=e;for(let a=0;a<s.length-1;a++)n[s[a]]||(n[s[a]]={}),n=n[s[a]];n[s[s.length-1]]=o}else e[i]=o}updateInput(t,i){var n,a,r;let o;if(this.inputs.has(t)){const c=(n=this.activeStateMachine)==null?void 0:n.inputs.find(l=>l.id===t);c&&typeof c.value=="object"&&(o=c.value.type)}else{const c=this.inputNameMap.get(t);if(c&&c.length>0){const l=(a=this.activeStateMachine)==null?void 0:a.inputs.find(h=>h.id===c[0]);l&&typeof l.value=="object"&&(o=l.value.type)}}let e=i;o==="Trigger"&&(i===1?e=!0:i===0&&(e=!1)),this.inputs.has(t)&&this.setInternalInput(t,e);const s=this.inputNameMap.get(t);s&&s.forEach(c=>this.setInternalInput(c,e)),o==="Trigger"&&e===!0&&(this.justFiredTriggers.add(t),s&&s.forEach(c=>this.justFiredTriggers.add(c))),Array.isArray(e)&&((r=this.artboard)==null||r.objects.forEach(c=>{if(c.inputId===t||c.name===t){const l=this.objectStates.get(c.id);l&&l.options&&(c.type==="ListView"||c.variant==="listview"?l.options.items=e:(c.type==="Dropdown"||c.variant==="dropdown")&&(l.options.optionsList=e))}})),this.evaluateTransitions(),this.evaluateVariableTriggers(t,e)}evaluateVariableTriggers(t,i){if(!this.artboard)return;const o=this.artboard.animationFlow||[],e=this.inputNameMap.get(t);o.forEach(s=>{if(s.trigger==="variable"&&s.conditionVariableId&&s.targetAnimationId&&(s.conditionVariableId===t||e&&e.includes(s.conditionVariableId))){const a=s.conditionOperator||"IsTrue",r=s.conditionValue;let c=!1;switch(a){case"Equal":case"==":c=i==r;break;case"NotEqual":case"!=":c=i!=r;break;case"GreaterThan":case">":c=i>r;break;case"LessThan":case"<":c=i<r;break;case"GreaterEqual":case">=":c=i>=r;break;case"LessEqual":case"<=":c=i<=r;break;case"IsTrue":c=!!i;break;case"IsFalse":c=!i;break}if(c){const l=s.delay||0;l<=0?this.triggerGlobalAnimation(s.targetAnimationId,s.subAnimationIds,s.loop,s.id):setTimeout(()=>this.triggerGlobalAnimation(s.targetAnimationId,s.subAnimationIds,s.loop,s.id),l)}}})}evaluateTransitions(){this.activeStateMachine&&(this.activeStateMachine.layers.forEach(t=>{const i=this.layerStates.get(t.name);if(!i||i.currentStateIds.length===0)return;const o=[];let e=!1;for(const s of i.currentStateIds){const n=t.states.find(r=>r.id===s);if(!n)continue;let a=!1;for(const r of n.transitions||[])this.checkConditions(r.conditions)&&(o.push(r.targetStateId),a=!0,e=!0);a||o.push(s)}if(!e){const s=this.findGlobalTransition(t,i.currentStateIds);s&&(o.length=0,o.push(s.targetStateId),e=!0,s.conditions&&(s.conditions||[]).forEach(n=>{var r;const a=(r=this.activeStateMachine)==null?void 0:r.inputs.find(c=>c.id===n.inputId);a&&typeof a.value=="object"&&a.value.type==="Trigger"&&this.setInternalInput(n.inputId,!1)}))}if(e){const s=Array.from(new Set(o));this.enterStates(t.name,s)}}),this.justFiredTriggers.size>0&&(this.justFiredTriggers.forEach(t=>{var o,e;this.setInternalInput(t,!1);const i=(o=this.activeStateMachine)==null?void 0:o.inputs.find(s=>s.id===t);i&&this.inputNameMap.has(i.name)&&((e=this.inputNameMap.get(i.name))==null||e.forEach(s=>this.setInternalInput(s,!1)))}),this.justFiredTriggers.clear()))}findGlobalTransition(t,i){for(const o of t.states)if(!(i.includes(o.id)&&this.justFiredTriggers.size===0)){for(const s of o.transitions||[])if(!(i.includes(s.targetStateId)&&this.justFiredTriggers.size===0)&&this.checkConditions(s.conditions))return s}return null}checkConditions(t){return!t||t.length===0?!0:t.every(i=>{const o=i.inputId,e=i.op,s=i.value,n=this.evaluateLogicTree(o);if(n===void 0)return this.log(`[Engine] Condition Check Failed: Input ${o} is undefined`),!1;let a=!1;switch(e){case"Equal":case"==":a=n==s;break;case"NotEqual":case"!=":a=n!=s;break;case"GreaterThan":case">":a=n>s;break;case"LessThan":case"<":a=n<s;break;case"GreaterEqual":case">=":a=n>=s;break;case"LessEqual":case"<=":a=n<=s;break;case"IsTrue":a=!!n;break;case"IsFalse":a=!n;break;default:a=!1}return a||this.justFiredTriggers.has(o),a})}evaluateLogicTree(t,i=null,o=new Set){var a,r,c,l,h,u;if(o.has(t))return this.inputs.get(t)??this.logicNodeValues.get(t)??0;o.add(t);const e=(r=(a=this.activeStateMachine)==null?void 0:a.logicNodes)==null?void 0:r.find(f=>f.id===t);if(e){const f=(p,y)=>{const m=e.inputs.find(b=>b.id===p);return m?m.sourceId?this.evaluateLogicTree(m.sourceId,m.sourceHandleId,o):m.value!==void 0?m.value:y:y};let d=0;switch(e.op){case vt.AND:d=f("a",!1)&&f("b",!1);break;case vt.OR:d=f("a",!1)||f("b",!1);break;case vt.NOT:d=!f("in",!1);break;case vt.XOR:d=!!f("a",!1)!=!!f("b",!1);break;case vt.OBJECT:d=e.name;break;case vt.PROPERTY:case vt.GET_PROPERTY:{const p=f("id","");if(!p){d=0;break}const y=e.name;if(!y||y==="GET_PROPERTY"||y==="PROPERTY"){d=0;break}const m=this.objectStates.get(p);if(!m){d=0;break}y in m?d=m[y]:d=this.resolvePath(m,y);break}case vt.SET_PROPERTY:{const p=f("id",""),y=f("value",void 0);if(!p||y===void 0){d=0;break}const m=e.name;if(!m||m==="SET_PROPERTY"){d=0;break}const b=this.objectStates.get(p);if(!b){d=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(m))b[m]=y,d=y;else{const S=m.split(".");let C=b;for(let M=0;M<S.length-1;M++){const I=S[M];C[I]===void 0&&(C[I]={}),C=C[I]}const w=S[S.length-1];C[w]=y,d=y}break}case vt.ADD:d=f("a",0)+f("b",0);break;case vt.SUB:d=f("a",0)-f("b",0);break;case vt.MUL:d=f("a",0)*f("b",0);break;case vt.DIV:{const p=f("b",1);d=p===0?0:f("a",0)/p;break}case vt.MOD:d=f("a",0)%f("b",1);break;case vt.POW:d=Math.pow(f("a",0),f("b",1));break;case vt.ABS:d=Math.abs(f("in",0));break;case vt.ROUND:d=Math.round(f("in",0));break;case vt.FLOOR:d=Math.floor(f("in",0));break;case vt.CEIL:d=Math.ceil(f("in",0));break;case vt.SIN:d=Math.sin(f("in",0));break;case vt.COS:d=Math.cos(f("in",0));break;case vt.TAN:d=Math.tan(f("in",0));break;case vt.CLAMP:{const p=f("in",0),y=f("min",0),m=f("max",1);d=Math.max(y,Math.min(m,p));break}case vt.REMAP:{const p=f("in",0),y=f("inMin",0),m=f("inMax",100),b=f("outMin",0),v=f("outMax",1);d=m===y?b:b+(p-y)*(v-b)/(m-y);break}case vt.EQ:d=f("a",0)==f("b",0);break;case vt.NEQ:d=f("a",0)!=f("b",0);break;case vt.GT:d=f("a",0)>f("b",0);break;case vt.LT:d=f("a",0)<f("b",0);break;case vt.GTE:d=f("a",0)>=f("b",0);break;case vt.LTE:d=f("a",0)<=f("b",0);break;case vt.IF_ELSE:d=f("cond",!1)?f("then",0):f("else",0);break;case vt.VALUE:d=e.value!==void 0?e.value:0;break;case vt.INPUT:d=this.inputs.get(e.name)??0;break;case vt.LOG:{const p=f("in","");this.debugLog(`[User Logic] ${p}`),d=p;break}case vt.SCROLL_X:d=this.inputs.get("scrollX")??0;break;case vt.SCROLL_Y:d=this.inputs.get("scrollY")??0;break;case vt.MOUSE_X:d=this.inputs.get("mouseX")??0;break;case vt.MOUSE_Y:d=this.inputs.get("mouseY")??0;break;case vt.IS_MOUSE_DOWN:d=this.inputs.get("isMouseDown")??!1;break;case vt.EFFECTOR:{const p=f("id",""),y=f("intensity",1),m=f("trigger",!0);if(!p||!m){d=0;break}const b=e.name;if(!b){d=0;break}const v=this.objectStates.get(p);if(!v){d=0;break}if(["glitch","halftone","pixelate","noise","acid_gradient","acid_rave","shimmer"].includes(b))v.style||(v.style={}),v.style.artEffect={enabled:!0,type:b,intensity:y},d=1;else{v.behaviors||(v.behaviors=[]);let C=v.behaviors.find(w=>w.type===b);C?(C.enabled=!0,C.settings||(C.settings={}),C.settings.intensity=y):(C={id:`eff_${Date.now()}_${b}`,type:b,enabled:!0,sensors:[],settings:{intensity:y}},v.behaviors.push(C)),d=1}break}case vt.MONITOR:{d=f("in",0);break}case vt.SPRING_PULL:{const p=f("objectId",""),y=f("forceX",0),m=f("forceY",0);p&&((c=this.artboard)==null||c.objects.forEach(b=>{b.behaviors&&b.behaviors.forEach(v=>{var S;if(v.type===V.SpringChain&&((S=v.settings)!=null&&S.connections)&&(v.settings.connections.some(w=>w.targetId===p)||b.id===p)){this._springChainState.has(b.id)||this._springChainState.set(b.id,new Map);const w=this._springChainState.get(b.id);if(!w.has(p)){const I=this.objectStates.get(p);w.set(p,{x:(I==null?void 0:I.x)??0,y:(I==null?void 0:I.y)??0,vx:0,vy:0})}const M=w.get(p);M&&(M.vx+=y,M.vy+=m)}})})),d=1;break}case vt.SPRING_SETTLE:{const p=f("objectId","");let y=!0;if(p){const m=f("threshold",1);this._springChainState.forEach(b=>{const v=b.get(p);v&&(Math.abs(v.vx)>m||Math.abs(v.vy)>m)&&(y=!1)})}d=y;break}case vt.EMIT:{const p=f("objectId",""),y=f("count",20);p&&((l=this.artboard)==null||l.objects.forEach(m=>{m.behaviors&&m.behaviors.forEach(b=>{b.type===V.ParticleEmitter&&m.id===p&&(b._pendingBurst=(b._pendingBurst||0)+y)})})),d=1;break}default:d=0;break}if(this.logicNodeValues.set(t,d),e.op===vt.DELAY){const p=f("delay",0),y=f("in",0);let m=this.logicNodeState.get(t);for(m||(m={queue:[]},this.logicNodeState.set(t,m)),m.queue.push({time:this.currentTime+p,value:y});m.queue.length>0&&m.queue[0].time<=this.currentTime;)m.lastValue=m.queue.shift().value;d=m.lastValue??0}return d}const s=(h=this.activeStateMachine)==null?void 0:h.inputs.find(f=>f.id===t||f.name===t);if(s&&s.sourceId&&!o.has(s.sourceId)){const f=this.evaluateLogicTree(s.sourceId,s.sourceHandleId,o);return this.inputs.set(s.id,f),f}let n=this.inputs.get(t)??(s?this.inputs.get(s.id):void 0);if((this.justFiredTriggers.has(t)||s&&this.justFiredTriggers.has(s.id))&&(n=!0),i&&n!==void 0){const f=(u=this.activeStateMachine)==null?void 0:u.inputs.find(d=>d.id===t);if(f&&f.value.type==="Number"&&typeof n=="number"){const d=f.value.defaultValue??f.value.value;if(i==="source-greater")return n>d;if(i==="source-less")return n<d;if(i==="source-equal")return n===d}if(i==="source-true")return n===!0;if(i==="source-false")return n===!1;if(i==="source-fire")return this.justFiredTriggers.has(t)}return n!==void 0?n:0}runLogicNodes(){!this.activeStateMachine||!this.activeStateMachine.logicNodes||this.activeStateMachine.logicNodes.forEach(t=>{(t.op===vt.SET_PROPERTY||t.op===vt.EFFECTOR)&&this.evaluateLogicTree(t.id)})}resolvePath(t,i){const o=i.split(".");let e=t;for(const s of o)if(e&&typeof e=="object"&&s in e)e=e[s];else return;return e}seek(t){this.artboard&&(this.currentTime=t,this.layerStates.forEach(i=>{i.time=t,i.time>(i.duration||0)&&(i.animations.some(e=>{var s;return((s=e.state)==null?void 0:s.loop)===!0})?i.time%=i.duration||1:i.time=i.duration)}),this.advance(0))}advance(t){if(!this.artboard)return;this.currentTime+=t,this.isMouseDown&&this.pointerDownTimes.forEach((o,e)=>{e&&this.currentTime-o>=.5&&(this.log(`[Engine] onHold detected for ${e}`),this.fireEventForObject(e,"onHold"),this.pointerDownTimes.delete(e))}),this.frameCount++,this.physicsEngine&&(this.physicsEngine.step(t),this.artboard.objects.forEach(o=>{var e;if((e=o.physics)!=null&&e.enabled){const s=this.physicsEngine.getPosition(o.id),n=this.physicsEngine.getRotation(o.id),a=this.objectStates.get(o.id);a&&s!==null&&n!==null&&(a.x=s.x,a.y=s.y,a.rotation=n*(180/Math.PI))}})),this.activeStateMachine&&(this.runLogicNodes(),this.evaluateTransitions());const i=[];this.layerStates.forEach((o,e)=>{if(o.animations.length>0){if(o.time+=t,this.frameCount%240===0&&this.debugLog(`Advancing Layer time: ${o.time.toFixed(3)} / ${o.duration.toFixed(3)}`),o.time>o.duration)if(o.animations.some(n=>{var a;return((a=n.state)==null?void 0:a.loop)===!0}))o.time%=o.duration;else{const n=o.time<o.duration+.1;o.time=o.duration,n&&(o.currentStateIds.length>0&&this.handleAnimationFinished(o.currentStateIds[0],o.ruleId),e.startsWith("global_")&&i.push(e))}o.animations.forEach(s=>{var n;(n=s.state)!=null&&n.isBlendState&&s.state.blendAnimations?this.applyBlendState(s.state,o.time):s.animation&&this.applyAnimation(s.animation,o.time,s.filterObjectIds)})}}),i.forEach(o=>{this.layerStates.delete(o),this.debugLog(`[Engine] Cleaned up completed global layer: ${o}`)}),this.solveConstraints(t),this.solveBehaviors(t),this.activeTriggers.forEach((o,e)=>{var s,n,a,r,c,l,h;if(o.phase==="entry")o.time+=t,o.time>=o.animation.duration&&((a=(n=(s=this.artboard)==null?void 0:s.objects.find(u=>u.id===e))==null?void 0:n.triggers)==null||a.find(u=>u.id===o.triggerId),o.phase="hold",o.elapsedHold=0,o.time=o.animation.duration),this.applyAnimation(o.animation,o.time,o.filterObjectIds||o.filterObjectId||void 0);else if(o.phase==="hold"){const u=(l=(c=(r=this.artboard)==null?void 0:r.objects.find(p=>p.id===e))==null?void 0:c.triggers)==null?void 0:l.find(p=>p.id===o.triggerId),f=(u==null?void 0:u.duration)||0;o.elapsedHold+=t*1e3;let d=o.elapsedHold>=f;if((u==null?void 0:u.eventType)==="hover"&&!this.activeHoverIds.has(e)&&(d=!0),((u==null?void 0:u.eventType)==="onHold"||(u==null?void 0:u.eventType)==="pointerDown")&&!this.isMouseDown&&(d=!0),d)if(u!=null&&u.exitAnimationId){const p=(h=this.artboard)==null?void 0:h.animations.find(y=>y.id===u.exitAnimationId);p?(o.phase="exit",o.animation=p,o.time=0):this.activeTriggers.delete(e)}else this.activeTriggers.delete(e)}else o.phase==="exit"&&(o.time+=t,o.time>=o.animation.duration?this.activeTriggers.delete(e):this.applyAnimation(o.animation,o.time,o.filterObjectIds||o.filterObjectId||void 0))}),this.evaluateContinuousInteractions(t),this.processJoysticks(t),this.activeStateMachine&&this.onLogicUpdate&&this.logicNodeValues.size>0&&this.onLogicUpdate(Object.fromEntries(this.logicNodeValues))}evaluateContinuousInteractions(t){this.artboard&&(this.artboard.objects.forEach(i=>{var e,s,n;const o=(e=i.style)==null?void 0:e.analytics;if(o&&o.isEnabled&&o.triggerType==="visible"){const a=this.objectStates.get(i.id);if(a&&a.visible!==!1){const r=this.getGlobalTransform(i.id),c=(((s=i.geometry)==null?void 0:s.width)||100)*(r.scale_x||1),l=(((n=i.geometry)==null?void 0:n.height)||100)*(r.scale_y||1),h=50,u=r.x+c/2>=-this.canvasWidth/2-h&&r.x-c/2<=this.canvasWidth/2+h&&r.y+l/2>=-this.canvasHeight/2-h&&r.y-l/2<=this.canvasHeight/2+h,f=`analytics_${i.id}`,d=this.wasInView.has(f);u&&!d&&this.fireAnalyticsEvent(i.id,"visible"),u?this.wasInView.add(f):this.wasInView.delete(f)}}}),this.artboard.objects.forEach(i=>{const o=i.interactions||[];o.length!==0&&o.forEach(e=>{const s=e.triggers||[e.event||e.trigger];s&&s.forEach(n=>{var r,c,l;const a=n.toLowerCase();if(a==="on interval"||a==="oninterval"){const h=e.intervalValue||2e3,u=this.periodicTriggerTimes.get(e.id)||0;this.currentTime*1e3-u>=h&&(!e.conditions||this.checkConditions(e.conditions))&&(this.fireEventForObject(i.id,"On Interval"),this.periodicTriggerTimes.set(e.id,this.currentTime*1e3))}if(a==="on delay"||a==="ondelay"){const h=e.delayValue||1e3;!this.periodicTriggerTimes.has(e.id)&&this.currentTime*1e3>=h&&(!e.conditions||this.checkConditions(e.conditions))&&(this.fireEventForObject(i.id,"On Delay"),this.periodicTriggerTimes.set(e.id,this.currentTime*1e3))}if(a==="scroll into view"||a==="scrollintoview"){const h=this.objectStates.get(i.id);if(h&&h.visible!==!1){const u=this.getGlobalTransform(i.id),f=(((r=i.geometry)==null?void 0:r.width)||100)*(u.scale_x||1),d=(((c=i.geometry)==null?void 0:c.height)||100)*(u.scale_y||1),p=50,y=u.x+f/2>=-this.canvasWidth/2-p&&u.x-f/2<=this.canvasWidth/2+p&&u.y+d/2>=-this.canvasHeight/2-p&&u.y-d/2<=this.canvasHeight/2+p,m=this.wasInView.has(i.id);y&&!m&&(!e.conditions||this.checkConditions(e.conditions))&&this.fireEventForObject(i.id,"Scroll Into View"),y?this.wasInView.add(i.id):this.wasInView.delete(i.id)}}if(a==="scroll progress"||a==="scrollprogress"){const h=Math.abs(this.scrollOffset.y)/(((l=this.artboard)==null?void 0:l.height)||1e3),u=this.scrollProgressLastValue.get(e.id)||0;Math.abs(h-u)>.001&&(this.scrollProgressLastValue.set(e.id,h),(e.action==="Set Input"||e.action==="setInput")&&this.updateInput(e.targetInputId,h))}})})}))}solveConstraints(t){this.artboard&&this.artboard.objects.forEach(i=>{if(!i.constraints||i.constraints.length===0)return;const o=this.objectStates.get(i.id);if(!o)return;const e=this.getGlobalTransform(i.id);if(i.constraints.forEach((s,n)=>{var l,h,u,f,d,p,y,m,b;const a=((l=o.constraints)==null?void 0:l[n])||{},r={...s,...a},c=r.strength??1;if(r.type==="Translation"){const v=this.getGlobalTransform(r.targetId);if(v){const S=r.offsetX||0,C=r.offsetY||0,w=v.x+S,M=v.y+C,I=r.useSpring;if(I){const T=this.objectVelocities.get(i.id)||{vx:0,vy:0},{x,y:P,vx:E,vy:L}=this.computeSpring(e.x,e.y,T.vx,T.vy,w,M,r,t);r.copyX&&(e.x=e.x+(x-e.x)*c),r.copyY&&(e.y=e.y+(P-e.y)*c),this.objectVelocities.set(i.id,{vx:E,vy:L})}else r.copyX&&(e.x=e.x+(w-e.x)*c),r.copyY&&(e.y=e.y+(M-e.y)*c);let k=!1;if((h=r.limitX)!=null&&h.enabled){const T=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==T&&(k=!0)}if((u=r.limitY)!=null&&u.enabled){const T=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==T&&(k=!0)}k&&I&&this.objectVelocities.set(i.id,{vx:0,vy:0})}}else if(r.type==="Rotation"){const v=this.getGlobalTransform(r.targetId);if(v){let C=(v.rotation+(r.offset||0)-e.rotation)%360;C>180&&(C-=360),C<-180&&(C+=360),e.rotation=e.rotation+C*c}}else if(r.type==="Scale"){const v=this.getGlobalTransform(r.targetId);v&&(r.copyX&&(e.scale_x=e.scale_x+(v.scale_x-e.scale_x)*c),r.copyY&&(e.scale_y=e.scale_y+(v.scale_y-e.scale_y)*c))}else if(r.type==="Transform"){const v=this.getGlobalTransform(r.targetId);if(v){e.x=e.x+(v.x-e.x)*c,e.y=e.y+(v.y-e.y)*c;let S=(v.rotation-e.rotation)%360;S>180&&(S-=360),S<-180&&(S+=360),e.rotation=e.rotation+S*c,e.scale_x=e.scale_x+(v.scale_x-e.scale_x)*c,e.scale_y=e.scale_y+(v.scale_y-e.scale_y)*c}}else if(r.type==="FollowPointer"){const v=((f=this._lastPointerPos)==null?void 0:f.x)??e.x,S=((d=this._lastPointerPos)==null?void 0:d.y)??e.y,C=r.useSpring;if(C){const M=this.objectVelocities.get(i.id)||{vx:0,vy:0},{x:I,y:k,vx:T,vy:x}=this.computeSpring(e.x,e.y,M.vx,M.vy,v,S,r,t);e.x=I,e.y=k,this.objectVelocities.set(i.id,{vx:T,vy:x})}else e.x=e.x+(v-e.x)*c,e.y=e.y+(S-e.y)*c;let w=!1;if((p=r.limitX)!=null&&p.enabled){const M=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==M&&(w=!0)}if((y=r.limitY)!=null&&y.enabled){const M=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==M&&(w=!0)}w&&C&&this.objectVelocities.set(i.id,{vx:0,vy:0})}else if(r.type==="Distance"){const v=this.getGlobalTransform(r.targetId);if(v){const S=e.x-v.x,C=e.y-v.y,w=Math.sqrt(S*S+C*C),M=r.distance||0;let I=w;switch(r.mode){case"exact":I=M;break;case"minimum":I=Math.max(M,w);break;case"maximum":I=Math.min(M,w);break;case"clamped":I=Math.max(0,Math.min(M,w));break}if(w>0){const k=e.x===v.x&&e.y===v.y?1:I/w;e.x=e.x+(v.x+S*k-e.x)*c,e.y=e.y+(v.y+C*k-e.y)*c}}}else if(r.type==="FollowPath"){const v=(m=this.artboard)==null?void 0:m.objects.find(S=>S.id===r.targetId);if(v){const S=this.getGlobalTransform(v.id);if(S){let C=v.geometry;if(v.type==="Frame"||v.type==="Group"||!C||C.type!=="Path"&&C.type!=="Ellipse"&&C.type!=="Rectangle"){const _=(b=this.artboard)==null?void 0:b.objects.find(R=>R.parentId===v.id&&R.type==="Shape"&&R.geometry&&(R.geometry.type==="Path"||R.geometry.type==="Ellipse"||R.geometry.type==="Rectangle"));_&&(C=_.geometry)}if(!C)return;const w=(r.distance||0)/100,M=S.width||C.width||0,I=S.height||C.height||0,k=this.getPointOnPath(C,M,I,w),T=S.rotation*Math.PI/180,x=Math.cos(T),P=Math.sin(T),E=k.x*S.scale_x*x-k.y*S.scale_y*P,L=k.x*S.scale_x*P+k.y*S.scale_y*x;let O=S.rotation+(r.offsetRotation||0);if(r.orient){const _=Math.cos(k.angle),R=Math.sin(k.angle),X=_*S.scale_x*x-R*S.scale_y*P,N=_*S.scale_x*P+R*S.scale_y*x;O=Math.atan2(N,X)*180/Math.PI+(r.offsetRotation||0)}const W=O*Math.PI/180,B=Math.cos(W),$=Math.sin(W),Y=(r.offsetX||0)*B-(r.offsetY||0)*$,H=(r.offsetX||0)*$+(r.offsetY||0)*B,K=S.x+E+Y,A=S.y+L+H;if(e.x=e.x+(K-e.x)*c,e.y=e.y+(A-e.y)*c,r.orient){let _=(O-e.rotation)%360;_>180&&(_-=360),_<-180&&(_+=360),e.rotation=e.rotation+_*c}}}}else if(r.type==="IK"){const v=this.getGlobalTransform(r.targetId);v&&this.solveIK(i,v,r.boneCount||2,c)}}),i.constraints.some(s=>s.type!=="IK")){const s=this.globalToLocal(i.parentId,e);o.x=s.x,o.y=s.y,o.rotation=s.rotation,o.flip_x=s.scale_x<0,o.scale_x=Math.abs(s.scale_x),o.flip_y=s.scale_y<0,o.scale_y=Math.abs(s.scale_y)}})}getGlobalTransform(t){var h,u;const i=this.objectStates.get(t);if(!i)return{x:0,y:0,rotation:0,scale_x:1,scale_y:1};const o=(h=this.artboard)==null?void 0:h.objects.find(f=>f.id===t),e=(o==null?void 0:o.type)==="Bone"?(u=o.geometry)==null?void 0:u.length:void 0;if(!o||!o.parentId)return{x:i.x,y:i.y,rotation:i.rotation,scale_x:(i.scale_x??1)*(i.flip_x?-1:1),scale_y:(i.scale_y??1)*(i.flip_y?-1:1),length:e};const s=this.getGlobalTransform(o.parentId),n=s.rotation*Math.PI/180,a=Math.cos(n),r=Math.sin(n),c=s.x+(i.x*s.scale_x*a-i.y*s.scale_y*r),l=s.y+(i.x*s.scale_x*r+i.y*s.scale_y*a);return{x:c,y:l,rotation:s.rotation+i.rotation,scale_x:s.scale_x*(i.scale_x??1)*(i.flip_x?-1:1),scale_y:s.scale_y*(i.scale_y??1)*(i.flip_y?-1:1),length:e}}globalToLocal(t,i){if(!t)return i;const o=this.getGlobalTransform(t),e=o.scale_x===0?0:1/o.scale_x,s=o.scale_y===0?0:1/o.scale_y,n=-o.rotation*Math.PI/180,a=Math.cos(n),r=Math.sin(n),c=i.x-o.x,l=i.y-o.y,h=(c*a-l*r)*e,u=(c*r+l*a)*s;return{x:h,y:u,rotation:i.rotation-o.rotation,scale_x:i.scale_x/(o.scale_x||1),scale_y:i.scale_y/(o.scale_y||1)}}solveIK(t,i,o,e){var c;const s=[];let n=t.id;for(let l=0;l<o&&n;l++){const h=(c=this.artboard)==null?void 0:c.objects.find(u=>u.id===n);if(!h)break;s.push({id:n,local:this.objectStates.get(n),global:this.getGlobalTransform(n)}),n=h.parentId}if(s.length<2)return;const a=s.reverse(),r=5;for(let l=0;l<r;l++){const h=this.getGlobalTransform(t.id);for(let u=a.length-2;u>=0;u--){const f=a[u],d=this.getGlobalTransform(f.id),p=h.x-d.x,y=h.y-d.y,m=i.x-d.x,b=i.y-d.y,v=Math.sqrt(p*p+y*y),S=Math.sqrt(m*m+b*b);if(v>.001&&S>.001){const C=Math.atan2(y,p);let M=(Math.atan2(b,m)-C)*180/Math.PI;M*=e;const I=this.objectStates.get(f.id);I&&(I.rotation+=M)}}}}computeSpring(t,i,o,e,s,n,a,r){const c=a.stiffness??100,l=a.damping??10,h=a.mass??1,u=-c*(t-s),f=-c*(i-n),d=-l*o,p=-l*e,y=(u+d)/h,m=(f+p)/h,b=o+y*r,v=e+m*r,S=t+b*r,C=i+v*r;return{x:S,y:C,vx:b,vy:v}}handlePointerInput(t,i,o,e,s){if(!this.artboard)return;const n=this.calculateTransform(e,s,this.artboard.width,this.artboard.height,this.layout.fit,this.layout.alignment),a=(i-n.tx)/n.scaleX,r=(o-n.ty)/n.scaleY;this._prevPointerPos=this._lastPointerPos,this._lastPointerPos={x:a,y:r},this.updateInput("mouseX",a),this.updateInput("mouseY",r),this.handlePointerEvent(t,a,r)}handleScroll(t,i){const o=this.scrollOffset.x,e=this.scrollOffset.y;this.scrollOffset={x:t,y:i},this._totalScroll.x+=t-o,this._totalScroll.y+=i-e,this.updateInput("scrollX",this._totalScroll.x),this.updateInput("scrollY",this._totalScroll.y)}handleWheel(t,i){this._totalScroll.x+=t,this._totalScroll.y+=i,this.scrollOffset={x:this._totalScroll.x,y:this._totalScroll.y},this.updateInput("scrollX",this._totalScroll.x),this.updateInput("scrollY",this._totalScroll.y)}handlePointerEvent(t,i,o){var r,c,l,h,u;if(!this.artboard)return;t==="down"?(this.isMouseDown=!0,this.updateInput("isMouseDown",!0)):(t==="up"||t==="blur")&&(this.isMouseDown=!1,this.updateInput("isMouseDown",!1));let e=null;const s=(f,d)=>{var S;let p=d;d==="click"?p="onClick":d==="down"?p="onPointerDown":d==="up"?p="onPointerUp":d==="blur"&&(p="onPointerLeave");const y=new Set([p]);d==="move"&&y.add("onPointerEnter").add("hover").add("onPointerLeave").add("blur"),p==="onClick"&&y.add("click"),p==="onPointerDown"&&y.add("pointerDown"),p==="onPointerUp"&&y.add("pointerUp");const m=["button","toggle","toggle_button","dropdown","listview","inputbox","slider","checkbox","radiogroup","joystick"];return!!(f.type==="Component"&&m.includes(f.variant)||f.type==="Joystick"||m.includes((S=f.type)==null?void 0:S.toLowerCase())||(f.interactions||[]).some(C=>y.has(C.event))||(f.triggers||[]).some(C=>y.has(C.eventType)))};let n=null;for(let f=this.artboard.objects.length-1;f>=0;f--){const d=this.artboard.objects[f],p=this.objectStates.get(d.id);if(p&&p.visible!==!1&&p.opacity>0&&this.hitTest(d,i,o)&&(n||(n=d),s(d,t))){e=d;break}}!e&&n&&(e=n),this.pointerHistory.push({x:i,y:o,time:Date.now()}),this.pointerHistory.length>this.MAX_HISTORY&&this.pointerHistory.shift();const a=(e==null?void 0:e.id)||null;if(t==="move"){if(this.draggingSliderId){const f=this.artboard.objects.find(d=>d.id===this.draggingSliderId);f&&this.updateSliderValueFromPointer(f,i,o);return}if(this.draggingJoystickId){const f=this.artboard.objects.find(d=>d.id===this.draggingJoystickId);f&&this.updateJoystickValueFromPointer(f,i,o);return}if(this.draggingListViewId){const f=this.artboard.objects.find(d=>d.id===this.draggingListViewId);f&&this.updateListViewScrollFromPointer(f);return}e&&(e.type==="ListView"||e.type==="Component"&&e.variant==="listview")&&this.updateListViewHoverFromPointer(e,i,o),this.isMouseDown&&a&&this.fireEventForObject(a,"Drag"),a!==this.lastHoveredObjectId&&(this.log(`[Engine] HOVER CHANGE: ${this.lastHoveredObjectId} -> ${a}`),this.lastHoveredObjectId&&this.fireEventForObject(this.lastHoveredObjectId,"onPointerLeave"),a&&this.fireEventForObject(a,"onPointerEnter"),this.lastHoveredObjectId=a);return}if((t==="up"||t==="blur")&&(this.draggingSliderId=null,this.draggingJoystickId=null,this.draggingListViewId=null,this.draggingBehaviors.clear(),this.pointerDownTimes.delete(a),this.activeObjectId=null),t==="down"&&(this.pointerDownTimes.set(a,this.currentTime),this.activeObjectId=a,e&&((r=e.behaviors)!=null&&r.some(f=>f.type===V.Draggable))&&this.draggingBehaviors.add(a)),t==="move"?(a&&!this.activeHoverIds.has(a)&&this.activeHoverIds.add(a),this.activeHoverIds.forEach(f=>{f!==a&&this.activeHoverIds.delete(f)})):t==="blur"&&this.activeHoverIds.clear(),this.activeDropdownId&&t==="down"){const f=this.artboard.objects.find(d=>d.id===this.activeDropdownId);if(f&&(f.type==="Dropdown"||f.variant==="dropdown")){const d=this.objectStates.get(f.id),p=(d==null?void 0:d.options)||f.options||{},y=f.geometry||{},m=y.width??f.width??200,b=y.height??f.height??40,v=p.optionsList||[],S=p.itemHeight||32,C=p.listPadding??4,w=v.length*S+C*2,M=this.getWorldTransform(f.id),I=m*Math.abs(M.scaleX),k=b*Math.abs(M.scaleY),T=M.y+k/2+4,x=Math.abs(i-M.x)<=I/2,P=o>=T&&o<=T+w*Math.abs(M.scaleY);if(x&&P){const E=Math.abs(M.scaleY),L=o-(T+C*E),O=Math.floor(L/(S*E));if(O>=0&&O<v.length){const W=v[O];p.selectedOption=W,p.isOpen=!1,this.activeDropdownId=null,f.inputId&&this.setInternalInput(f.inputId,W),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"dropdown",property:"selectedOption",value:W})}return}else a!==this.activeDropdownId&&(p.isOpen=!1,this.activeDropdownId=null)}}if(e){let f=e,d=e;for(;d&&d.parentId;){const y=this.artboard.objects.find(m=>m.id===d.parentId);if(y&&y.type==="Component"){f=y;break}d=y}let p=t;if(t==="click"?p="onClick":t==="down"?p="onPointerDown":t==="up"?p="onPointerUp":t==="blur"&&(p="onPointerLeave"),this.fireEventForObject(e.id,p),f!==e&&this.fireEventForObject(f.id,p),f.type==="Component"&&f.variant==="toggle_button"&&t==="down"){const y=this.objectStates.get(f.id),m=(y==null?void 0:y.options)||f.options||{};m.checked=!m.checked,f.inputId&&this.setInternalInput(f.inputId,m.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"toggle_button",property:"checked",value:m.checked}),this.fireEventForObject(f.id,"Toggle"),this.fireEventForObject(f.id,m.checked?"Toggle True":"Toggle False")}if(f.type==="Component"&&f.variant==="toggle"&&t==="down"){const y=this.objectStates.get(f.id),m=(y==null?void 0:y.options)||f.options||{};m.checked=!m.checked,f.inputId&&this.setInternalInput(f.inputId,m.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"toggle",property:"checked",value:m.checked}),this.onToggle&&this.onToggle(f.name,m.checked),this.fireEventForObject(f.id,"Toggle"),this.fireEventForObject(f.id,m.checked?"Toggle True":"Toggle False")}if(f.type==="Component"&&f.variant==="dropdown"&&t==="down"){const y=this.objectStates.get(f.id),m=(y==null?void 0:y.options)||f.options||{},b=!m.isOpen;if(b&&this.activeDropdownId&&this.activeDropdownId!==f.id){const v=this.artboard.objects.find(S=>S.id===this.activeDropdownId);v&&v.options&&(v.options.isOpen=!1)}m.isOpen=b,this.activeDropdownId=b?f.id:null}if(f.type==="Component"&&f.variant==="button"&&t==="down"&&(this.onButtonClick&&this.onButtonClick(f.name,f.id),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"button",property:"click",value:!0})),(f.type==="ListView"||f.type==="Component"&&f.variant==="listview")&&t==="down"){this.draggingListViewId=f.id;const y=this.getListViewItemIndexAtPointer(f,i,o);if(y!==null){const m=f.options||{};m.activeItemIndex=y;const b=this.objectStates.get(f.id);b&&b.options&&(b.options.activeItemIndex=y);const v=(m.items||[])[y],S=typeof v=="string"?v:v.label||v.value||y;b&&b.options&&(b.options.selectedValue=S),f.inputId&&this.setInternalInput(f.inputId,S),this.onComponentChange&&(this.onComponentChange({objectId:f.id,componentName:f.name,variant:"listview",property:"activeItemIndex",value:y}),this.onComponentChange({objectId:f.id,componentName:f.name,variant:"listview",property:"selected",value:S}))}}if(f.type==="Component"&&f.variant==="slider"&&t==="down"&&(this.draggingSliderId=f.id,this.updateSliderValueFromPointer(f,i,o)),f.type==="Joystick"||f.type==="Component"&&f.variant==="joystick"){if(t==="down")this.draggingJoystickId=f.id,this.updateJoystickValueFromPointer(f,i,o);else if(t==="up"||t==="blur"){const y=this.objectStates.get(f.id);y&&f.isSpringReturn!==!1&&(y.handleX=0,y.handleY=0),f.isSpringReturn!==!1&&(f.handleX=0,f.handleY=0)}}if(f.type==="Component"&&f.variant==="checkbox"&&t==="down"){const y=this.objectStates.get(f.id),m=(y==null?void 0:y.options)||f.options||{};m.checked=!m.checked,f.inputId&&this.setInternalInput(f.inputId,m.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"checkbox",property:"checked",value:m.checked}),this.fireEventForObject(f.id,"Click"),this.fireEventForObject(f.id,m.checked?"Checked":"Unchecked")}if(f.type==="Component"&&f.variant==="radiogroup"&&t==="down"){const y=this.objectStates.get(f.id),m=(y==null?void 0:y.options)||f.options||{},b=m.optionsList||[],v=this.getRadioGroupItemIndexAtPointer(f,i,o);if(v!==null&&v>=0&&v<b.length){const S=b[v];m.selectedValue=S,f.inputId&&this.setInternalInput(f.inputId,S),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"radiogroup",property:"selectedValue",value:S}),this.fireEventForObject(f.id,"Click"),this.fireEventForObject(f.id,`Selected: ${S}`)}}if(f.type==="LineGraph"&&(t==="down"||t==="click")){const y=f.geometry,m=(y==null?void 0:y.datasets)||[],b=this.objectStates.get(f.id),v=(b==null?void 0:b.width)||(y==null?void 0:y.width)||200,S=(b==null?void 0:b.height)||(y==null?void 0:y.height)||150,C=this.getWorldTransform(f.id),w=30,M=20,I=v-w,k=S-M;let T=1;m.forEach(E=>{const L=Math.max(...E.data||[0]);L>T&&(T=L)});let x=1/0,P=null;m.forEach((E,L)=>{const O=E.data||[],W=I/Math.max(O.length-1,1);O.forEach((B,$)=>{const Y=C.x-v/2+w+$*W,H=C.y+S/2-M-B/T*k,K=Math.sqrt((i-Y)**2+(o-H)**2);K<x&&(x=K,P={dIdx:L,pIdx:$,val:B,label:E.label||`Dataset ${L+1}`})})}),P&&x<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:f.id,componentName:f.name,datasetIndex:P.dIdx,pointIndex:P.pIdx,value:P.val,label:P.label}),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"linegraph",property:"click",value:(P==null?void 0:P.val)??null})}if(t==="click"){const y=(c=this.artboard)==null?void 0:c.objects.find(v=>v.id===e.id),m=this.focusedId,b=(y==null?void 0:y.type)==="InputBox"||(y==null?void 0:y.type)==="Component"&&y.variant==="inputbox";if(y&&b){if(this.focusedId=e.id,this.log(`[Engine] Focus set to: ${e.id}`),m!==this.focusedId){if(m){const v=(l=this.artboard)==null?void 0:l.objects.find(S=>S.id===m);v&&this.onInputBlur&&this.onInputBlur(v.name)}this.onInputFocus&&this.onInputFocus(y.name)}}else if(this.focusedId=null,m){const v=(h=this.artboard)==null?void 0:h.objects.find(S=>S.id===m);v&&this.onInputBlur&&this.onInputBlur(v.name)}}}else if(t==="click"){const f=this.focusedId;if(this.focusedId=null,f){const d=(u=this.artboard)==null?void 0:u.objects.find(p=>p.id===f);d&&this.onInputBlur&&this.onInputBlur(d.name)}}}handleKeyDown(t){if(!this.artboard||(this.activeKeys.add(t.key.toLowerCase()),this.activeKeys.add(t.code),!this.focusedId))return;const i=this.artboard.objects.find(a=>a.id===this.focusedId),o=(i==null?void 0:i.type)==="InputBox"||(i==null?void 0:i.type)==="Component"&&i.variant==="inputbox";if(!i||!o)return;const e=i.options||{};let s=e.text||"";if(t.key==="Backspace")s=s.slice(0,-1);else if(t.key==="Enter")if(e.multiline)s+=`
|
|
7
|
-
`;else{this.focusedId=null;return}else if(t.key.length===1)s+=t.key;else return;e.text=s;const n=i.geometry;n.textInputId&&this.updateInput(n.textInputId,s),this.onComponentChange&&this.onComponentChange({objectId:i.id,componentName:i.name,variant:"inputbox",property:"text",value:s}),this.onInputChange&&this.onInputChange(i.name,s),this.onInputUpdate&&this.onInputUpdate(this.focusedId,s)}handleKeyUp(t){this.artboard&&(this.activeKeys.delete(t.key.toLowerCase()),this.activeKeys.delete(t.code))}fireEventForObject(t,i){var l,h,u,f,d;const o=(l=this.artboard)==null?void 0:l.objects.find(p=>p.id===t);if(!o)return;const e=new Set([i,i.toLowerCase()]),s=i.toLowerCase();s==="onclick"||s==="click"||s==="onpointerdown"||s==="pointerdown"?this.fireAnalyticsEvent(t,"click"):(s==="onpointerenter"||s==="hover"||s==="move")&&this.fireAnalyticsEvent(t,"hover"),s==="onclick"||s==="click"?(e.add("click"),e.add("onclick")):s==="onpointerdown"||s==="pointerdown"?(e.add("pointerdown"),e.add("onpointerdown")):s==="onpointerup"||s==="pointerup"?(e.add("pointerup"),e.add("onpointerup")):s==="onpointerenter"||s==="hover"||s==="move"?(e.add("hover"),e.add("onpointerenter")):s==="onpointerleave"||s==="blur"?(e.add("onpointerleave"),e.add("blur")):s==="drag"||s==="ondrag"?(e.add("drag"),e.add("ondrag")):s==="toggle"||s==="ontoggle"?(e.add("toggle"),e.add("ontoggle")):s==="toggle true"||s==="toggle_true"||s==="toggletrue"?(e.add("toggle true"),e.add("toggle_true"),e.add("toggletrue")):(s==="toggle false"||s==="toggle_false"||s==="togglefalse")&&(e.add("toggle false"),e.add("toggle_false"),e.add("togglefalse"));const a=(o.interactions||[]).find(p=>{const y=p.triggers||[p.event||p.trigger||"click"];return((p.triggerLogic||"OR")==="AND"?y.every(v=>e.has(v.toLowerCase())):y.some(v=>e.has(v.toLowerCase())))?p.conditions&&p.conditions.length>0?this.checkConditions(p.conditions):!0:!1});if(a){if(this.log(`[Engine] Interaction matched: ${i} -> Action: ${a.action}`),a.action==="setInput"||a.action==="Set Input"){let p=a.value||a.inputValue;p==="toggle"&&(p=!this.inputs.get(a.targetInputId)),this.updateInput(a.targetInputId,p)}else if(a.action==="Toggle Boolean"){const p=this.inputs.get(a.targetInputId);this.updateInput(a.targetInputId,!p)}else if(a.action==="fireTrigger")this.updateInput(a.targetInputId,!0);else if(a.action==="setProperty"){const p=a.targetObjectId||o.id,y=a.targetProperty;y&&this.updateObjectProperty(p,y,a.value)}else if(a.action==="Navigate Artboard"||a.action==="navigate")this.onNavigation&&this.onNavigation({type:"artboard",value:a.targetArtboard||a.value});else if(a.action==="Navigate URL")this.onNavigation&&this.onNavigation({type:"url",value:a.navigateUrl});else if(a.action==="Play Animation"){const p=a.targetAnimationId,y=!a.playMode||a.playMode==="all"?void 0:a.subAnimationIds;p==="__all__"?(u=(h=this.artboard)==null?void 0:h.animations)==null||u.forEach(m=>{this.triggerGlobalAnimation(m.id,y)}):p&&this.triggerGlobalAnimation(p,y)}else if(a.action==="setState"||a.action==="Set State"){const p=a.targetObjectId||o.id,m={...this.objectStates.get(p)||{},...a.value||{}};this.objectStates.set(p,m),this.log(`[Engine] State updated for ${p}:`,m)}else if(a.action==="Stop Animation"||a.action==="Pause Animation"){const p=a.targetAnimationId;p==="__all__"?this.layerStates.forEach((y,m)=>{m.startsWith("global_")&&this.layerStates.delete(m)}):p&&this.layerStates.forEach((y,m)=>{m.startsWith(`global_${p}_`)&&this.layerStates.delete(m)})}else if(a.action==="Switch to State"&&this.activeStateMachine){const p=a.targetState,y=this.activeStateMachine.layers.find(m=>m.states.some(b=>b.id===p||b.name===p));y&&(this.log(`[Engine] Switching Layer ${y.name} to State ${p}`),this.enterStates(y.name,[p]))}this.onTrigger&&this.onTrigger(i,a.action)}const c=(o.triggers||[]).find(p=>{const y=p.eventType.toLowerCase();let m=!1;return(e.has(y)||y==="click"&&e.has("onclick")||y==="hover"&&(e.has("onpointerenter")||e.has("hover"))||y==="pointerdown"&&e.has("onpointerdown")||y==="pointerup"&&e.has("onpointerup"))&&(m=!0),m&&p.conditions&&p.conditions.length>0?this.checkConditions(p.conditions):m});if(c&&c.entryAnimationId){this.log(`[Engine] Trigger matched: ${i} (as ${c.eventType}) -> Animation ${c.entryAnimationId}`);const p=(d=(f=this.artboard)==null?void 0:f.animations)==null?void 0:d.find(y=>y.id===c.entryAnimationId);p&&(this.activeTriggers.set(o.id,{triggerId:c.id,animation:p,time:0,phase:"entry",elapsedHold:0,filterObjectId:c.targetObjectId}),this.onTrigger&&this.onTrigger(c.name,p.name))}}fireAnalyticsEvent(t,i){var r,c;const o=(r=this.artboard)==null?void 0:r.objects.find(l=>l.id===t);if(!o)return;const e=(c=o.style)==null?void 0:c.analytics;if(!e||!e.isEnabled||e.triggerType!==i)return;const s=e.eventName||`${o.name.toLowerCase().replace(/\s+/g,"_")}_interacted`,n={};e.parameters&&Array.isArray(e.parameters)&&e.parameters.forEach(l=>{if(l.type==="literal")n[l.key]=l.value;else if(l.type==="variable"){const h=this.inputs.get(l.value);n[l.key]=h!==void 0?h:""}}),this.log(`[ExodeUI Analytics] Dispatching event "${s}" via ${i} trigger:`,n);const a=e.platforms||{ga4:!0,meta:!0,mixpanel:!1};if(a.ga4){const l=window;typeof l.gtag=="function"?(l.gtag("event",s,n),this.log(`[ExodeUI Analytics] GA4: Event "${s}" sent successfully.`)):this.warn(`[ExodeUI Analytics] GA4: window.gtag is not a function. Event "${s}" skipped.`)}if(a.meta){const l=window;typeof l.fbq=="function"?(l.fbq("track",s,n),this.log(`[ExodeUI Analytics] Meta Pixel: Event "${s}" sent successfully.`)):this.warn(`[ExodeUI Analytics] Meta Pixel: window.fbq is not a function. Event "${s}" skipped.`)}if(a.mixpanel){const l=window;l.mixpanel&&typeof l.mixpanel.track=="function"?(l.mixpanel.track(s,n),this.log(`[ExodeUI Analytics] Mixpanel: Event "${s}" sent successfully.`)):this.warn(`[ExodeUI Analytics] Mixpanel: window.mixpanel.track is not a function. Event "${s}" skipped.`)}}initGlobalAnimationTriggers(){if(!this.artboard)return;const t=this.artboard.animationFlow||[];let i=!1;t.forEach(o=>{if((o.trigger==="on_load"||o.trigger==="after_delay")&&o.targetAnimationId){i=!0;const e=o.delay||0;e<=0?this.triggerGlobalAnimation(o.targetAnimationId,o.subAnimationIds,o.loop,o.id):setTimeout(()=>this.triggerGlobalAnimation(o.targetAnimationId,o.subAnimationIds,o.loop,o.id),e)}}),!i&&this.artboard.startupAnimationId&&this.triggerGlobalAnimation(this.artboard.startupAnimationId,this.artboard.startupSubAnimationIds)}triggerGlobalAnimation(t,i,o=!1,e){if(!this.artboard)return;const s=this.artboard.animations.find(a=>a.id===t);if(!s)return;const n=`global_${t}_${Math.random().toString(36).substr(2,5)}`;this.layerStates.set(n,{currentStateIds:[t],animations:[{animation:s,state:{loop:o},filterObjectIds:i}],time:0,duration:s.duration,ruleId:e}),this.debugLog(`[Engine] Triggered global animation: ${s.name} (Loop: ${o}, Sub-Anims: ${(i==null?void 0:i.length)||"All"})`)}handleAnimationFinished(t,i){if(!this.artboard)return;(this.artboard.animationFlow||[]).forEach(e=>{if(e.trigger==="after_anim"&&e.targetAnimationId&&(e.afterAnim===t||i&&e.afterAnim===i)){const n=e.delay||0;n<=0?this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id):setTimeout(()=>this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id),n)}})}getWorldTransform(t){var u;const i=this.objectStates.get(t);if(!i)return{x:0,y:0,scaleX:1,scaleY:1,rotation:0};const o=(u=this.artboard)==null?void 0:u.objects.find(f=>f.id===t);if(!o||!o.parentId)return{x:i.x,y:i.y,scaleX:i.scale_x??1,scaleY:i.scale_y??1,rotation:i.rotation??0};const e=this.getWorldTransform(o.parentId),s=e.rotation*(Math.PI/180),n=Math.cos(s),a=Math.sin(s),r=i.x*e.scaleX,c=i.y*e.scaleY,l=e.x+(r*n-c*a),h=e.y+(r*a+c*n);return{x:l,y:h,scaleX:(i.scale_x??1)*e.scaleX,scaleY:(i.scale_y??1)*e.scaleY,rotation:e.rotation+(i.rotation??0)}}hitTest(t,i,o){var v,S;if(!this.objectStates.get(t.id))return!1;const s=((v=t.geometry)==null?void 0:v.width)??t.width??100,n=((S=t.geometry)==null?void 0:S.height)??t.height??100,a=this.getWorldTransform(t.id),r=i-a.x,c=o-a.y,l=-a.rotation*(Math.PI/180),h=Math.cos(l),u=Math.sin(l),f=r*h-c*u,d=r*u+c*h,p=a.scaleX,y=a.scaleY,m=s*Math.abs(p),b=n*Math.abs(y);return Math.abs(f)<=m/2&&Math.abs(d)<=b/2}updateSliderValueFromPointer(t,i,o){var M;const e=this.objectStates.get(t.id);if(!e)return;const s=t.options||{},n=((M=t.geometry)==null?void 0:M.width)??t.width??200,a=this.getWorldTransform(t.id),r=i-a.x,c=o-a.y,l=-a.rotation*(Math.PI/180),h=Math.cos(l),u=Math.sin(l),f=r*h-c*u,d=s.thumbWidth??16,p=n-d;let m=(f+p/2)/p;m=Math.max(0,Math.min(1,m));const b=s.min??0,v=s.max??100,S=s.step||1;let C=b+m*(v-b);S>0&&(C=Math.round(C/S)*S),C=Math.max(b,Math.min(v,C));const w=e.options||{};w.value!==C&&(e.options={...w,value:C},t.inputId&&this.setInternalInput(t.inputId,C),this.onComponentChange&&this.onComponentChange({objectId:t.id,componentName:t.name,variant:"slider",property:"value",value:C}))}updateJoystickValueFromPointer(t,i,o){var M,I;const e=this.objectStates.get(t.id);if(!e)return;const s=(e==null?void 0:e.width)!==void 0?e.width:((M=t.geometry)==null?void 0:M.width)??t.width??100,n=(e==null?void 0:e.height)!==void 0?e.height:((I=t.geometry)==null?void 0:I.height)??t.height??100,a=this.getWorldTransform(t.id),r=i-a.x,c=o-a.y,l=-a.rotation*(Math.PI/180),h=Math.cos(l),u=Math.sin(l);let f=(r*h-c*u)/Math.max(.001,Math.abs(a.scaleX||1)),d=(r*u+c*h)/Math.max(.001,Math.abs(a.scaleY||1));t.handleOrigin==="top-left"?(f-=s/2,d-=n/2):t.handleOrigin==="bottom-right"&&(f+=s/2,d+=n/2);const p=Math.min(s,n)*.45,y=Math.min(s,n)*.15,m=p-y;let b=f/m,v=d/m;const S=Math.sqrt(b*b+v*v);t.boundsShape==="square"?(b=Math.max(-1,Math.min(1,b)),v=Math.max(-1,Math.min(1,v))):S>1&&(b/=S,v/=S),t.deadzone!==void 0&&S<t.deadzone?(b=0,v=0):(t.stepX!==void 0&&t.stepX>0&&(b=Math.round(b/t.stepX)*t.stepX),t.stepY!==void 0&&t.stepY>0&&(v=Math.round(v/t.stepY)*t.stepY)),t.joystickType==="1D_X"?v=0:t.joystickType==="1D_Y"&&(b=0);const C=e.handleX,w=e.handleY;(C!==b||w!==v)&&(e.handleX=b,e.handleY=v,t.handleX=b,t.handleY=v)}processJoysticks(t){this.artboard&&this.artboard.objects.forEach(i=>{var a;if(i.type!=="Joystick"&&!(i.type==="Component"&&i.variant==="joystick"))return;const o=i,e=this.objectStates.get(o.id);if(!e)return;let s=e.handleX??o.handleX??0,n=e.handleY??o.handleY??0;if(((a=o.inputBinding)==null?void 0:a.type)==="keyboard"&&o.inputBinding.keyboardConfig){const r=o.inputBinding.keyboardConfig;let c=s,l=n;const u=(r.speed||5)*t;let f=!1;this.activeKeys.has(r.upKey.toLowerCase())&&(l-=u,f=!0),this.activeKeys.has(r.downKey.toLowerCase())&&(l+=u,f=!0),this.activeKeys.has(r.leftKey.toLowerCase())&&(c-=u,f=!0),this.activeKeys.has(r.rightKey.toLowerCase())&&(c+=u,f=!0),o.joystickType==="1D_X"&&(l=0),o.joystickType==="1D_Y"&&(c=0);const d=Math.sqrt(c*c+l*l);d>1&&(c/=d,l/=d),!f&&o.isSpringReturn!==!1&&(c+=(0-c)*(10*t),l+=(0-l)*(10*t),Math.abs(c)<.01&&(c=0),Math.abs(l)<.01&&(l=0)),s=c,n=l}if(e.handleX=s,e.handleY=n,o.handleX=s,o.handleY=n,o.bindings&&o.bindings.length>0){const r=Math.sqrt(s*s+n*n);let c=Math.atan2(n,s)*(180/Math.PI);c<0&&(c+=360),o.bindings.forEach(l=>{var f,d;let h=0;l.sourceAxis==="x"?h=o.invertX?-s:s:l.sourceAxis==="y"?h=o.invertY?-n:n:l.sourceAxis==="distance"?h=r:l.sourceAxis==="angle"&&(h=c);const u=(f=this.artboard)==null?void 0:f.objects.find(p=>p.id===l.targetObjectId);if(u){if(l.actionType==="bind"&&l.targetProperty&&l.isContinuous!==!1){const p=l.sourceMin??-1,y=l.sourceMax??1,m=l.targetMin??0,b=l.targetMax??100,v=(h-p)/(y-p),S=Math.max(0,Math.min(1,v));let C=m+S*(b-m);l.step&&l.step>0&&(C=Math.round(C/l.step)*l.step);const w=this.objectStates.get(u.id);if(w){const M=l.isRelative!==!1,I=M?u.x??0:0,k=M?u.y??0:0,T=M?u.rotation??0:0,x=M?u.scale_x??1:0,P=M?u.scale_y??1:0,E=M?u.opacity??100:0;l.targetProperty==="x"||l.targetProperty==="transform.x"?w.x=I+C:l.targetProperty==="y"||l.targetProperty==="transform.y"?w.y=k+C:l.targetProperty==="rotation"||l.targetProperty==="r"||l.targetProperty==="transform.rotation"?w.rotation=T+C:l.targetProperty==="scaleX"||l.targetProperty==="transform.scale_x"?w.scale_x=x+C:l.targetProperty==="scaleY"||l.targetProperty==="transform.scale_y"?w.scale_y=P+C:(l.targetProperty==="opacity"||l.targetProperty==="transform.opacity")&&(w.opacity=E+C)}(d=u.physics)!=null&&d.enabled&&this.physicsEngine&&(l.targetProperty==="x"||l.targetProperty==="transform.x"||l.targetProperty==="y"||l.targetProperty==="transform.y")&&(l.targetProperty==="x"||l.targetProperty==="transform.x"?this.physicsEngine.applyForce(u.id,(C-((w==null?void 0:w.x)||0))*10,0):(l.targetProperty==="y"||l.targetProperty==="transform.y")&&this.physicsEngine.applyForce(u.id,0,(C-((w==null?void 0:w.y)||0))*10))}else if(l.actionType==="playAnimation"||l.actionType==="stopAnimation"||l.actionType==="pauseAnimation"){let p=!1;const y=l.threshold??0;l.condition==="always"?p=!0:l.condition===">"?p=h>y:l.condition==="<"?p=h<y:l.condition==="=="&&(p=Math.abs(h-y)<.01);const m=e[`_prev_src_${l.id}`]??h;let b=!1;l.condition==="always"?b=!0:l.condition===">"?b=m>y:l.condition==="<"?b=m<y:l.condition==="=="&&(b=Math.abs(m-y)<.01),e[`_prev_src_${l.id}`]=h,p&&!b&&l.targetAnimationId&&(l.actionType==="playAnimation"||l.actionType)}}})}})}applyBlendState(t,i){var c,l,h,u,f,d,p,y;if(!t.blendAnimations||t.blendAnimations.length===0)return;let o=0,e=0;t.blendInputX&&(o=this.inputs.get(t.blendInputX)??0),t.blendInputY&&(e=this.inputs.get(t.blendInputY)??0);const s=[];let n=0;if(t.blendType==="1D"){const m=[...t.blendAnimations].sort((b,v)=>b.position[0]-v.position[0]);if(m.length===1){const b=(l=(c=this.artboard)==null?void 0:c.animations)==null?void 0:l.find(v=>v.id===m[0].animationId);b&&(s.push({anim:b,weight:1}),n=1)}else{let b=0;for(;b<m.length-1&&m[b+1].position[0]<o;)b++;if(b===m.length-1&&o>m[b].position[0]){const v=(u=(h=this.artboard)==null?void 0:h.animations)==null?void 0:u.find(S=>S.id===m[b].animationId);v&&(s.push({anim:v,weight:1}),n=1)}else{const v=m[b].position[0],S=m[b+1].position[0],C=(d=(f=this.artboard)==null?void 0:f.animations)==null?void 0:d.find(T=>T.id===m[b].animationId),w=(y=(p=this.artboard)==null?void 0:p.animations)==null?void 0:y.find(T=>T.id===m[b+1].animationId),M=Math.max(.001,S-v);let I=(o-v)/M;I=Math.max(0,Math.min(1,I));const k=1-I;C&&(s.push({anim:C,weight:k}),n+=k),w&&(s.push({anim:w,weight:I}),n+=I)}}}else t.blendAnimations.forEach(m=>{var w,M;const b=(M=(w=this.artboard)==null?void 0:w.animations)==null?void 0:M.find(I=>I.id===m.animationId);if(!b)return;const v=m.position[0]-o,S=m.position[1]-e,C=v*v+S*S;if(C<1e-4)s.push({anim:b,weight:1e4}),n+=1e4;else{const I=1/C;s.push({anim:b,weight:I}),n+=I}});if(n===0)return;s.forEach(m=>m.weight/=n);const a=new Map,r=m=>{let b=m.startsWith("#")?m.substring(1):m;return b.length===3&&(b=[b[0],b[0],b[1],b[1],b[2],b[2]].join("")),b="0x"+b,{r:b>>16&255,g:b>>8&255,b:b&255,a:1}};s.forEach(({anim:m,weight:b})=>{m.tracks&&m.tracks.forEach(v=>{var x,P;const S=v.object_id||v.objectId,C=v.property,w=(x=this.artboard)==null?void 0:x.objects.find(E=>E.id===S);if(((P=w==null?void 0:w.physics)==null?void 0:P.enabled)&&w.physics.bodyType!=="Static"&&(C==="x"||C==="y"||C==="rotation"))return;const I=this.interpolate(v.keyframes,i);if(I===void 0)return;let k=a.get(S);k||(k=new Map,a.set(S,k));let T=k.get(C);if(!T){if(typeof I=="number")T={type:"number",value:0};else if(typeof I=="string"&&I.startsWith("#"))T={type:"color",value:I,colorAcc:{r:0,g:0,b:0,a:0}};else if(T={type:"number",value:I},b<.5)return;k.set(C,T)}if(T.type==="number"&&typeof I=="number")T.value+=I*b;else if(T.type==="color"&&typeof I=="string"&&T.colorAcc){const E=r(I);E&&(T.colorAcc.r+=E.r*b,T.colorAcc.g+=E.g*b,T.colorAcc.b+=E.b*b,T.colorAcc.a+=E.a*b)}else b>.5&&(T.value=I)})}),a.forEach((m,b)=>{var C;const v=this.objectStates.get(b),S=(C=this.artboard)==null?void 0:C.objects.find(w=>w.id===b);!v||!S||m.forEach((w,M)=>{let I=w.value;if(w.type==="color"&&w.colorAcc){const k=Math.round(w.colorAcc.r).toString(16).padStart(2,"0"),T=Math.round(w.colorAcc.g).toString(16).padStart(2,"0"),x=Math.round(w.colorAcc.b).toString(16).padStart(2,"0");I=`#${k}${T}${x}`}if(M.includes(".")){const k=(M||"").split(".");let T=v;for(let x=0;x<k.length-1;x++){if(typeof T[k[x]]!="object"||T[k[x]]===null){let P=S;for(let E=0;E<=x;E++)P=P?P[k[E]]:null;if(k[x]==="corner_radius"||k[x]==="cornerRadius"){const E=typeof T[k[x]]=="number"?T[k[x]]:typeof P=="number"?P:0;T[k[x]]={tl:E,tr:E,bl:E,br:E}}else T[k[x]]=P?JSON.parse(JSON.stringify(P)):{}}T=T[k[x]]}T[k[k.length-1]]=I,k[k.length-1]==="color"&&(k[k.length-2]==="fill"||k[k.length-2]==="stroke")&&(T.type="Solid")}else M==="fill"?(v.style||(v.style={}),v.style.fill=I):M==="stroke"?(v.style||(v.style={}),v.style.stroke=I):v[M]=I})})}applyAnimation(t,i,o){!t||!t.tracks||t.tracks.forEach(e=>{var h,u,f;const s=e.object_id||e.objectId;if(o){if(Array.isArray(o)){if(!o.includes(s))return}else if(s!==o)return}const n=(h=this.artboard)==null?void 0:h.objects.find(d=>d.id===s),a=((u=n==null?void 0:n.physics)==null?void 0:u.enabled)&&n.physics.bodyType!=="Static";let r=e.property;if(a&&(r==="x"||r==="y"||r==="rotation"))return;const c=this.objectStates.get(s);if(!c){this.frameCount%600===0&&this.debugLog(`Skipping track: Object ${s} not found in state`);return}const l=this.interpolate(e.keyframes,i);if(l!==void 0){if(this.frameCount%240===0){const d=(n==null?void 0:n.name)||s,p=typeof l=="object"?JSON.stringify(l).slice(0,50):l;this.debugLog(`[Anim] Applying ${r} = ${p} to ${d}`)}if(r.includes(".")){const d=(r||"").split(".");let p=c;for(let y=0;y<d.length-1;y++){if(typeof p[d[y]]!="object"||p[d[y]]===null){let m=n;for(let b=0;b<=y;b++)m=m?m[d[b]]:null;if(d[y]==="corner_radius"||d[y]==="cornerRadius"){const b=typeof p[d[y]]=="number"?p[d[y]]:typeof m=="number"?m:0;p[d[y]]={tl:b,tr:b,bl:b,br:b}}else p[d[y]]=m?JSON.parse(JSON.stringify(m)):{}}p=p[d[y]]}p[d[d.length-1]]=l,d[d.length-1]==="color"&&(d[d.length-2]==="fill"||d[d.length-2]==="stroke")&&(p.type="Solid")}else r==="fill"?(c.style||(c.style={}),c.style.fill=l):r==="stroke"?(c.style||(c.style={}),c.style.stroke=l):c[r]=l;if(this.physicsEngine&&((f=n==null?void 0:n.physics)!=null&&f.enabled)&&n.physics.bodyType==="Static")if(r==="x"){const d=this.physicsEngine.getPosition(s);d&&this.physicsEngine.setPosition(s,l,d.y)}else if(r==="y"){const d=this.physicsEngine.getPosition(s);d&&this.physicsEngine.setPosition(s,d.x,l)}else r==="rotation"&&this.physicsEngine.setRotation(s,l*(Math.PI/180))}})}interpolate(t,i){if(t.length===0)return;let o=t[0],e=t[t.length-1];if(i<=o.time)return o.value;if(i>=e.time)return e.value;for(let a=0;a<t.length-1;a++)if(i>=t[a].time&&i<t[a+1].time){o=t[a],e=t[a+1];break}const s=e.time-o.time;let n=(i-o.time)/s;if(o.easing&&(n=si(o.easing)(n)),typeof o.value=="string"){if(o.value.startsWith("#"))return this.interpolateColor(o.value,e.value,n);const a=parseFloat(o.value),r=parseFloat(e.value);return!isNaN(a)&&!isNaN(r)?Math.round(a+(r-a)*n).toString():o.value}if(Array.isArray(o.value)&&Array.isArray(e.value))return o.value.length===e.value.length?o.value.map((a,r)=>{const c=e.value[r];return typeof a=="number"&&typeof c=="number"?a+(c-a)*n:n<.5?a:c}):n<.5?o.value:e.value;if(typeof o.value=="object"&&typeof e.value=="object"&&o.value!==null&&e.value!==null){if(o.value.width!==void 0&&o.value.color!==void 0)return this.interpolateStroke(o.value,e.value,n);if(o.value.type&&e.value.type)return this.interpolateFill(o.value,e.value,n);const a={};return new Set([...Object.keys(o.value),...Object.keys(e.value)]).forEach(c=>{const l=o.value[c],h=e.value[c];typeof l=="number"&&typeof h=="number"?a[c]=l+(h-l)*n:l===void 0?a[c]=h:h===void 0?a[c]=l:a[c]=n<.5?l:h}),a}return typeof o.value=="number"&&typeof e.value=="number"?o.value+(e.value-o.value)*n:n<.5?o.value:e.value}interpolateColor(t,i,o){var d,p;const e=((p=(d=this.artboard)==null?void 0:d.tokens)==null?void 0:p.colors)||{},s=e[t]||t,n=e[i]||i,a=y=>{if(!y)return{r:0,g:0,b:0};const m=y.startsWith("#")?y.replace("#",""):"000000";return m.length===3?{r:parseInt(m[0]+m[0],16),g:parseInt(m[1]+m[1],16),b:parseInt(m[2]+m[2],16)}:{r:parseInt(m.substring(0,2),16),g:parseInt(m.substring(2,4),16),b:parseInt(m.substring(4,6),16)}},r=a(s),c=a(n),l=Math.round(r.r+(c.r-r.r)*o),h=Math.round(r.g+(c.g-r.g)*o),u=Math.round(r.b+(c.b-r.b)*o),f=y=>{const m=Math.max(0,Math.min(255,y)).toString(16);return m.length===1?"0"+m:m};return`#${f(l)}${f(h)}${f(u)}`}interpolateStops(t,i,o){return!t||!i||t.length!==i.length?o<.5?t:i:t.map((e,s)=>{const n=i[s];return{offset:e.offset+(n.offset-e.offset)*o,color:this.interpolateColor(e.color,n.color,o),opacity:(e.opacity??1)+((n.opacity??1)-(e.opacity??1))*o}})}interpolateFill(t,i,o){if(!t||!i||t.type!==i.type)return o<.5?t:i;const e={...t,opacity:(t.opacity??1)+((i.opacity??1)-(t.opacity??1))*o};return t.type==="Solid"?e.color=this.interpolateColor(t.color,i.color,o):(t.type==="LinearGradient"||t.type==="RadialGradient")&&(t.start&&i.start&&(e.start=[t.start[0]+(i.start[0]-t.start[0])*o,t.start[1]+(i.start[1]-t.start[1])*o]),t.end&&i.end&&(e.end=[t.end[0]+(i.end[0]-t.end[0])*o,t.end[1]+(i.end[1]-t.end[1])*o]),t.center&&i.center&&(e.center=[t.center[0]+(i.center[0]-t.center[0])*o,t.center[1]+(i.center[1]-t.center[1])*o]),t.radius!==void 0&&i.radius!==void 0&&(e.radius=t.radius+(i.radius-t.radius)*o),e.stops=this.interpolateStops(t.stops,i.stops,o)),e}interpolateStroke(t,i,o){if(!t||!i)return o<.5?t:i;const e={...t};return e.width=(t.width??0)+((i.width??0)-(t.width??0))*o,e.opacity=(t.opacity??1)+((i.opacity??1)-(t.opacity??1))*o,t.fill&&i.fill?e.fill=this.interpolateFill(t.fill,i.fill,o):t.color&&i.color&&t.color.startsWith("#")&&i.color.startsWith("#")&&(e.color=this.interpolateColor(t.color,i.color,o)),e.trimStart=(t.trimStart??0)+((i.trimStart??0)-(t.trimStart??0))*o,e.trimEnd=(t.trimEnd??1)+((i.trimEnd??1)-(t.trimEnd??1))*o,e.trimOffset=(t.trimOffset??0)+((i.trimOffset??0)-(t.trimOffset??0))*o,e.dashOffset=(t.dashOffset??0)+((i.dashOffset??0)-(t.dashOffset??0))*o,e}render(t,i,o){var h;this.debug_objectsTotal=((h=this.artboard)==null?void 0:h.objects.length)||0,this.debug_objectsRendered=0;const e=performance.now();if(this.canvasWidth=i,this.canvasHeight=o,!this.artboard)return;t.clearRect(0,0,i,o);const s=this.artboard.width,n=this.artboard.height,a=this.calculateTransform(i,o,s,n,this.layout.fit,this.layout.alignment);if(t.save(),t.translate(Math.round(a.tx),Math.round(a.ty)),t.scale(a.scaleX,a.scaleY),this.rootTransform=t.getTransform(),this.artboard.backgroundVisible!==!1&&(t.fillStyle=this.artboard.backgroundColor||"#000000",t.fillRect(0,0,s,n)),this.artboard.backgroundImage){const u=this.artboard.backgroundImage;let f=this.imageCache.get(u);if(f||(f=new Image,f.src=u,this.imageCache.set(u,f)),f.complete&&f.naturalWidth>0){t.save(),t.globalAlpha=this.normalizeOpacity(this.artboard.backgroundOpacity??100);const d=f.naturalWidth/f.naturalHeight,p=s/n;let y,m,b,v;p>d?(y=s,m=s/d):(m=n,y=n*d),b=(s-y)/2,v=(n-m)/2,t.drawImage(f,b,v,y,m),t.restore()}}(this.artboard.clipContent===!0||this.artboard.clip_content===!0)&&(t.beginPath(),t.rect(0,0,s,n),t.clip());const c=new Map;this.artboard.objects.forEach(u=>c.set(u.id,u)),this.artboard.objects.filter(u=>!u.parentId).map((u,f)=>{const d=this.objectStates.get(u.id),p=(d==null?void 0:d.zIndex)??f;return{obj:u,zIndex:p}}).sort((u,f)=>u.zIndex-f.zIndex).forEach(({obj:u})=>{this.renderObject(t,u,c)}),this._emitterPools.forEach((u,f)=>{if(!(u.length===0||!c.get(f)))for(const p of u)t.save(),t.globalAlpha=p.opacity,t.fillStyle=p.color,t.beginPath(),t.arc(p.x,p.y,Math.max(1,p.size*p.opacity),0,Math.PI*2),t.fill(),t.restore()}),this.lastRenderTime=performance.now()-e,this.debugMode&&this.frameCount%60===0&&this.log(`[Engine Debug] Rendered ${this.debug_objectsRendered}/${this.debug_objectsTotal} objects in ${this.lastRenderTime.toFixed(2)}ms`),t.restore()}isObjectInView(t,i,o,e,s,n=0){const a=t.getTransform(),r=i*a.a+o*a.c+a.e,c=i*a.b+o*a.d+a.f,l=Math.sqrt(a.a*a.a+a.b*a.b),h=Math.sqrt(a.c*a.c+a.d*a.d),u=(e/2+n)*l,f=(s/2+n)*h;return r+u>=0&&r-u<=this.canvasWidth&&c+f>=0&&c-f<=this.canvasHeight}calculateTransform(t,i,o,e,s,n){let a=1,r=1,c=1;const l=o/e,h=t/i;switch(s){case"Contain":h>l?c=i/e:c=t/o,a=r=c;break;case"Cover":h>l?c=t/o:c=i/e,a=r=c;break;case"Fill":a=t/o,r=i/e;break;case"FitWidth":c=t/o,a=r=c;break;case"FitHeight":c=i/e,a=r=c;break;case"None":a=r=1;break;case"ScaleDown":c=Math.min(t/o,i/e),c>1&&(c=1),a=r=c;break;default:a=r=1;break}const u=o*a,f=e*r;let d=0,p=0;return n.includes("Left")?d=0:n.includes("Right")?d=t-u:d=(t-u)/2,n.includes("Top")?p=0:n.includes("Bottom")?p=i-f:p=(i-f)/2,{scaleX:a,scaleY:r,tx:d,ty:p}}mapFontWeight(t){const i=t.toLowerCase();return i==="thin"||i==="100"?"100":i==="extralight"||i==="200"?"200":i==="light"||i==="300"?"300":i==="regular"||i==="normal"||i==="400"?"400":i==="medium"||i==="500"?"500":i==="semibold"||i==="600"?"600":i==="bold"||i==="700"?"700":i==="extrabold"||i==="800"?"800":i==="black"||i==="900"?"900":t}drawTextDecoration(t,i,o,e,s,n){t.beginPath();const a=Math.max(1,n/14);let r=e;i==="underline"?r=e+n*.12:i==="line-through"&&(r=e-n*.3),t.lineWidth=a,t.strokeStyle=t.fillStyle,t.moveTo(o-s/2,r),t.lineTo(o+s/2,r),t.stroke()}renderObject(t,i,o){var p,y,m,b,v,S,C,w,M,I,k,T,x,P,E,L,O,W,B,$,Y,H,K,A,_;const e=this.objectStates.get(i.id);if(!e){this.warn("No state for object:",i.id);return}this.frameCount%60,t.roundRect||(t.roundRect=(R,X,N,it,lt)=>(this.drawRoundRect(t,R,X,N,it,lt),t));const s=e.geometry?this.deepMerge(i.geometry,e.geometry):i.geometry,n=e.style?this.deepMerge(i.style,e.style):i.style;let a=(s==null?void 0:s.width)||((p=i.geometry)==null?void 0:p.width)||i.width||0,r=(s==null?void 0:s.height)||((y=i.geometry)==null?void 0:y.height)||i.height||0;if((a===0||r===0)&&(s!=null&&s.points)&&Array.isArray(s.points)&&s.points.length>0){let R=1/0,X=-1/0,N=1/0,it=-1/0;s.points.forEach(lt=>{R=Math.min(R,lt.x),X=Math.max(X,lt.x),N=Math.min(N,lt.y),it=Math.max(it,lt.y)}),a===0&&(a=X-R),r===0&&(r=it-N)}const c=R=>{if(R)return R.corner_radius??R.cornerRadius},l=c(e)??c(n)??c(s)??c(i.style)??c(i.geometry)??0;let h={...s,width:a,height:r};if(delete h.cornerRadius,h.corner_radius=l,h.type==="Path"&&i.weights&&i.bindMatrices&&h.points){const R=this.getGlobalTransform(i.id);if(R){const X=ii(h.points,i.weights,i.bindMatrices,R,N=>this.getGlobalTransform(N));h={...h,points:X}}}if(e.visible===!1)return;const u=i.repeaterConfig,f=u&&u.isEnabled&&u.count>1,d=f?u.count:1;for(let R=0;R<d;R++){let X=e.x!==void 0?e.x:((m=e.transform)==null?void 0:m.x)??0,N=e.y!==void 0?e.y:((b=e.transform)==null?void 0:b.y)??0,it=e.rotation!==void 0?e.rotation:((v=e.transform)==null?void 0:v.rotation)??0,lt=e.scale_x!==void 0?e.scale_x:((S=e.transform)==null?void 0:S.scale_x)??1,nt=e.scale_y!==void 0?e.scale_y:((C=e.transform)==null?void 0:C.scale_y)??1;if(f&&R>0){if(u.type==="Linear"){const at=u.offsetX||0,gt=u.offsetY||0,j=u.rotation||0,z=u.scale!==void 0?u.scale:1;X+=R*at,N+=R*gt,it+=R*j,lt*=Math.pow(z,R),nt*=Math.pow(z,R)}else if(u.type==="Grid"){const at=u.cols||Math.ceil(Math.sqrt(u.count)),gt=u.gapX||0,j=u.gapY||0,z=Math.floor(R/at),D=R%at,et=a+gt,mt=r+j;X+=D*et,N+=z*mt}else if(u.type==="Radial"){const at=u.radius||100,gt=u.startAngle||0,z=(u.endAngle||360)-gt,D=u.count>1?z/(z===360?u.count:u.count-1):0,et=gt+R*D,mt=et*Math.PI/180;X=e.x+at*Math.cos(mt),N=e.y+at*Math.sin(mt),it+=et}}const bt=i.type==="Group"||i.type==="Frame"||i.type==="Component",ft=a>0&&r>0;if(!bt&&ft){const at=(((w=n.shadow)==null?void 0:w.isEnabled)!==!1?(((M=n.shadow)==null?void 0:M.blur)||0)+10:0)+(((I=n.blur)==null?void 0:I.isEnabled)!==!1&&((k=n.blur)==null?void 0:k.radius)||0)+20;if(!this.isObjectInView(t,X,N,a,r,at))continue}this.debug_objectsRendered++,t.save();const wt=[],It=n.blur||((T=i.style)==null?void 0:T.blur);It&&It.amount>0&&wt.push(`blur(${It.amount}px)`);const Mt=n.effect||((x=i.style)==null?void 0:x.effect),xt=(Mt==null?void 0:Mt.isEnabled)===!0,At=Mt==null?void 0:Mt.type,Tt=(Mt==null?void 0:Mt.radius)??10;xt&&At==="LayerBlur"&&wt.push(`blur(${Tt}px)`);const Nt=((P=s==null?void 0:s.type)==null?void 0:P.toLowerCase().includes("image"))||((E=i.type)==null?void 0:E.toLowerCase().includes("image")),Z=n.adjustments&&Object.keys(n.adjustments).length>0?n.adjustments:null,pt=s!=null&&s.adjustments&&Object.keys(s.adjustments).length>0?s.adjustments:null,Et=Nt?pt||Z:Z||pt,ut=Nt&&!Et?{exposure:0,contrast:0,saturation:100,temperature:0,tint:0,highlights:0,shadows:0,blur:0,negative:0,hue:0}:Et;if(e&&ut&&(e.geometry=e.geometry||{},e.geometry.adjustments={...ut}),ut){const at=(ut.exposure||0)/100,gt=ut.contrast||0,j=1+(ut.saturation||0)/100,z=(ut.temperature||0)/200,D=(ut.tint||0)/200,et=(ut.highlights||0)/500,mt=(ut.shadows||0)/500;let Pt="",Ct="SourceGraphic";if(at!==0&&(Pt+=`
|
|
8
|
-
<feComponentTransfer in="${
|
|
9
|
-
<feFuncR type="linear" slope="1" intercept="${
|
|
10
|
-
<feFuncG type="linear" slope="1" intercept="${
|
|
11
|
-
<feFuncB type="linear" slope="1" intercept="${
|
|
12
|
-
</feComponentTransfer>`,
|
|
13
|
-
<feComponentTransfer in="${
|
|
14
|
-
<feFuncR type="linear" slope="${
|
|
15
|
-
<feFuncG type="linear" slope="${
|
|
16
|
-
<feFuncB type="linear" slope="${
|
|
17
|
-
</feComponentTransfer>`,
|
|
18
|
-
<feColorMatrix in="${
|
|
19
|
-
values="${
|
|
20
|
-
0 ${
|
|
21
|
-
0 0 ${
|
|
22
|
-
0 0 0 1 0"/>`,Ct="invert"}if(z!==0||D!==0||et!==0||mt!==0){const yt=1+et+mt,F=yt*(1+z-D/2),Ft=yt*(1+D),se=yt*(1-z-D/2),Ht=ut.shadows*.1/255,de=[F,0,0,0,Ht,0,Ft,0,0,Ht,0,0,se,0,Ht,0,0,0,1,0].join(" ");Pt+=`<feColorMatrix in="${Ct}" type="matrix" values="${de}" result="advanced"/>`,Ct="advanced"}if(ut.blur&&(Pt+=`<feGaussianBlur in="${Ct}" stdDeviation="${ut.blur}" result="blur"/>`,Ct="blur"),Pt){const yt=`<svg xmlns="http://www.w3.org/2000/svg"><filter id="f" color-interpolation-filters="sRGB">${Pt}</filter></svg>`,F=btoa(yt);wt.push(`url('data:image/svg+xml;base64,${F}#f')`)}}wt.length>0?t.filter=wt.join(" "):t.filter="none",t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";const St=t.globalAlpha,Rt=this.normalizeOpacity(e.opacity!==void 0?e.opacity:100);t.globalAlpha=St*Rt;const Dt=e.compositeOperation||e.blendMode;if(Dt&&Dt!=="Normal"){const at=Dt.toLowerCase();["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity","source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","copy","xor","multiply","screen"].includes(at)&&(t.globalCompositeOperation=at)}const Yt=t,Vt=e.masks||(i.maskedBy?[{maskId:i.maskedBy,inverted:i.maskInverted===!0,type:i.maskType||"alpha",opacity:i.maskOpacity!==void 0?i.maskOpacity/100:1,feather:i.maskFeather||0,isVisible:!0}]:[]);let Jt=!1;const ie=Vt.filter(at=>at.isVisible!==!1&&o.has(at.maskId));if(ie.length>0){const at=ie[0],gt=o.get(at.maskId),j=this.objectStates.get(gt.id);j&&j.visible!==!1&&(Jt=!0,(!this.maskBuffer||this.maskBuffer.width!==this.canvasWidth||this.maskBuffer.height!==this.canvasHeight)&&(this.maskBuffer=document.createElement("canvas"),this.maskBuffer.width=this.canvasWidth,this.maskBuffer.height=this.canvasHeight,this.maskCtx=this.maskBuffer.getContext("2d",{willReadFrequently:!0}),this.maskCtx&&(this.maskCtx.imageSmoothingEnabled=!0,this.maskCtx.imageSmoothingQuality="high")),this.maskCtx.setTransform(1,0,0,1,0,0),this.maskCtx.globalCompositeOperation="source-over",this.maskCtx.globalAlpha=1,this.maskCtx.filter="none",this.maskCtx.clearRect(0,0,this.maskBuffer.width,this.maskBuffer.height),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),i.parentId&&this.applyAbsoluteTransform(this.maskCtx,i.parentId,o),this.maskCtx.save(),this.maskCtx.globalAlpha=1,t=this.maskCtx,t.filter=Yt.filter)}t.translate(Math.round(X),Math.round(N)),t.rotate(it*Math.PI/180);const me=e.skew_x||0,ye=e.skew_y||0;if(me!==0||ye!==0){const at=Math.tan(me*Math.PI/180),gt=Math.tan(ye*Math.PI/180);t.transform(1+at*gt,gt,at,1,0,0)}const te=e.rotate_x!==void 0?e.rotate_x:((L=e.transform)==null?void 0:L.rotate_x)??0,ve=e.rotate_y!==void 0?e.rotate_y:((O=e.transform)==null?void 0:O.rotate_y)??0,Se=1+(e.translate_z!==void 0?e.translate_z:((W=e.transform)==null?void 0:W.translate_z)??0)/1e3,we=(e.flip_x===!0?-1:1)*Math.cos(ve*Math.PI/180)*Se,_e=(e.flip_y===!0?-1:1)*Math.cos(te*Math.PI/180)*Se;t.scale(lt*we,nt*_e),n.shadow&&n.shadow.isEnabled!==!0&&((n.shadow.blur||0)>0||Math.abs(n.shadow.offsetX||0)>0||Math.abs(n.shadow.offsetY||0)>0)&&(n.shadow.isEnabled=!0);const ce=n.shadow;if(ce&&ce.isEnabled!==!1){let at=ce.color||"#000000";($=(B=this.artboard)==null?void 0:B.tokens)!=null&&$.colors&&this.artboard.tokens.colors[at]&&(at=this.artboard.tokens.colors[at]);const gt=this.normalizeOpacity(ce.opacity??100),j=ce.spread||0,D=(ce.blur||0)+j*1.5;let et=at;if(at.startsWith("#")){const Ct=at.replace("#",""),Bt=parseInt(Ct.substring(0,2),16),yt=parseInt(Ct.substring(2,4),16),F=parseInt(Ct.substring(4,6),16);et=`rgba(${Bt}, ${yt}, ${F}, ${gt})`}else if(at.startsWith("rgba")){const Ct=at.match(/[\d.]+/g);if(Ct&&Ct.length>=4){const Bt=Ct[0],yt=Ct[1],F=Ct[2],Ft=Ct[3];et=`rgba(${Bt}, ${yt}, ${F}, ${parseFloat(Ft)*gt})`}}const mt=t.getTransform(),Pt=Math.sqrt(mt.a*mt.a+mt.b*mt.b)||1;t.shadowColor=et,t.shadowBlur=D*Pt,t.shadowOffsetX=(ce.offsetX||0)*Pt,t.shadowOffsetY=(ce.offsetY||0)*Pt}const ne=i.liquidFill||((Y=i.style)==null?void 0:Y.liquidFill);if(ne&&ne.enabled){t.save();const at=ne.fillLevel??.5;t.beginPath();const gt=r/2-r*at;t.rect(-a/2,gt,a,r*at),t.clip(),t.fillStyle=ne.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(ne.opacity??1)}if((s==null?void 0:s.type)==="Text")this._renderText(t,i,h,n,e,a,r);else if((s==null?void 0:s.type)==="Image"){const at=s.originalSrc||s.src;if(at){let gt=this.imageCache.get(at);gt||(gt=new Image,gt.onload=()=>{this.log(`[ExodeUI] Image loaded successfully, size: ${gt.naturalWidth}x${gt.naturalHeight}`)},gt.onerror=D=>{console.error("[ExodeUI] Image load failed:",D,`Src preview: ${at.substring(0,100)}...`)},gt.src=at,this.imageCache.set(at,gt));const j=n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1,z=(((H=n.stroke)==null?void 0:H.alignment)||"center").toLowerCase();if(j&&(z==="outside"||z==="center")&&this.applyStrokeAlignment(t,n,h,a,r,l),n.fill&&n.fill.type!=="None"){t.save();const D=t.globalAlpha,et=this.createCanvasFill(t,n.fill,a,r);t.fillStyle=et||n.fill.color||"transparent",t.globalAlpha=D*this.normalizeOpacity(n.fill.opacity??100),l!==0?(this.drawRoundRect(t,-a/2,-r/2,a,r,l),t.fill()):t.fillRect(-a/2,-r/2,a,r),t.globalAlpha=D,t.restore()}gt.complete&>.naturalWidth>0?(l!==0?(t.save(),this.drawRoundRect(t,-a/2,-r/2,a,r,l),t.clip(),t.drawImage(gt,-a/2,-r/2,a,r),t.restore()):t.drawImage(gt,-a/2,-r/2,a,r),j&&z==="inside"&&this.applyStrokeAlignment(t,n,h,a,r,l)):j&&z==="inside"&&this.applyStrokeAlignment(t,n,h,a,r,l)}}else if(s.type==="SVG"){const at=s.svgContent;if(at){const gt=n.palette||[],j=n.fill,z=n.stroke,D=j?this.normalizeOpacity(j.opacity??100):1,et=(j==null?void 0:j.type)==="Solid"&&(!z||z.isEnabled===!1||z.type==="Solid"&&z.color===j.color),mt=j&&j.type!=="None"?et?"monochrome":j.type==="Solid"?(j.color||"")+"|opacity:"+D:JSON.stringify(j.stops||[])+"|opacity:"+D:"",Pt=z&&z.isEnabled!==!1&&(z.width||0)>0?et?["monochrome",z.width||0,z.trimStart??0,z.trimEnd??1,z.trimOffset??0,z.dashOffset??0].join("|"):[z.width||0,z.fill?z.fill.type==="Solid"?z.fill.color||"":JSON.stringify(z.fill.stops||[]):z.color||"",z.opacity??1,z.lineCap||"",z.lineJoin||"",(z.dashArray||[]).join(","),z.trimStart??0,z.trimEnd??1,z.trimOffset??0,z.dashOffset??0].join("|"):"nostroke",Ct=[i.id,gt.join("_"),mt,Pt,e.opacity??100,e.visible!==!1?"v":"h"].join("_");let Bt=this.imageCache.get(Ct);if(!Bt){Bt=new Image,Bt.crossOrigin="anonymous";let F=at;F.match(/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i)||(F=F.replace(/<svg([^>]*)>/i,(tt,dt)=>`<svg xmlns="http://www.w3.org/2000/svg"${dt}>`));let Ft=s.width||a||100,se=s.height||r||100;const Ht=F.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(Ht&&(Ft=parseFloat(Ht[1]),se=parseFloat(Ht[2])),F=F.replace(/<svg([^>]*)>/i,(tt,dt)=>{let G=dt.replace(/\b(?:width|height)=["'][^"']*["']/gi," ");return G.match(/\bviewBox=/i)||(G+=` viewBox="0 0 ${Ft} ${se}"`),G.match(/\bpreserveAspectRatio=/i)||(G+=' preserveAspectRatio="none"'),G+=' width="100%" height="100%"',`<svg${G}>`}),s.colors&&s.colors.length>0&>.length>0&&s.colors.forEach((tt,dt)=>{if(gt[dt]){const G=tt.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),st=new RegExp(G,"gi");F=F.replace(st,gt[dt])}}),j&&j.type&&j.type!=="None"){if(j.type==="Solid"&&j.color){const tt=et?"#FFFFFF":j.color,dt=et?1:this.normalizeOpacity(j.opacity??100);F=F.replace(/\bfill\s*=\s*["'][^"']*["']/gi,G=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(G)?G:`fill="${tt}"`),F=F.replace(/fill\s*:\s*[^;"')]+/gi,G=>/fill\s*:\s*(none|transparent)/i.test(G)?G:`fill:${tt}`),dt<1&&(F=F.replace(/\bfill-opacity\s*=\s*["'][^"']*["']/gi,`fill-opacity="${dt}"`),F=F.replace(/fill-opacity\s*:\s*[^;"')]+/gi,`fill-opacity:${dt}`),F.match(/\bfill-opacity\s*=/i)||(F=F.replace(/(<svg[^>]*>)/i,`$1<g fill-opacity="${dt}">`),F=F.replace(/<\/svg>/i,"</g></svg>")))}else if(j.type==="LinearGradient"||j.type==="RadialGradient"||j.type==="Linear"||j.type==="Radial"){const tt="exode-fill",dt=this.normalizeOpacity(j.opacity??100),G=(j.stops||[]).map(J=>{const $t=J.offset!==void 0?J.offset:J.pos??0,Qt=this.normalizeOpacity(J.opacity??100)*dt;return`<stop offset="${$t*100}%" stop-color="${J.color||"#000"}" stop-opacity="${Qt}"/>`}).join("");let st="";if(j.type==="LinearGradient"||j.type==="Linear"){const J=(Kt,Ut)=>Array.isArray(Kt)?Kt[Ut]??(Ut===0?0:1):Kt&&typeof Kt=="object"?Kt[Ut===0?"x":"y"]??(Ut===0?0:1):Ut===0?0:1,$t=J(j.start,0)*100,Qt=J(j.start,1)*100,oe=J(j.end,0)*100,Gt=J(j.end,1)*100;st=`<linearGradient id="${tt}" x1="${$t}%" y1="${Qt}%" x2="${oe}%" y2="${Gt}%" gradientUnits="objectBoundingBox">${G}</linearGradient>`}else{const J=(Gt,Kt)=>Array.isArray(Gt)?Gt[Kt]??.5:Gt&&typeof Gt=="object"?Gt[Kt===0?"x":"y"]??.5:.5,$t=J(j.center,0)*100,Qt=J(j.center,1)*100,oe=(j.radius??.5)*100;st=`<radialGradient id="${tt}" cx="${$t}%" cy="${Qt}%" r="${oe}%" gradientUnits="objectBoundingBox">${G}</radialGradient>`}/<defs>/i.test(F)?F=F.replace(/<defs>/i,`<defs>${st}`):F=F.replace(/<svg([^>]*)>/i,`<svg$1><defs>${st}</defs>`),F=F.replace(/\bfill\s*=\s*["'][^"']*["']/gi,J=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(J)?J:`fill="url(#${tt})"`),F=F.replace(/fill\s*:\s*[^;"')]+/gi,J=>/fill\s*:\s*(none|transparent)/i.test(J)?J:`fill:url(#${tt})`)}}const de=(tt,dt,G=1)=>{const st=(tt.stops||[]).map(Gt=>{const Kt=Gt.offset!==void 0?Gt.offset:Gt.pos??0,Ut=this.normalizeOpacity(Gt.opacity??100)*G;return`<stop offset="${Kt*100}%" stop-color="${Gt.color||"#000"}" stop-opacity="${Ut}"/>`}).join(""),J=(Gt,Kt,Ut=.5)=>Array.isArray(Gt)?Gt[Kt]??Ut:Gt&&typeof Gt=="object"?Gt[Kt===0?"x":"y"]??Ut:Ut;if(tt.type==="LinearGradient"||tt.type==="Linear"){const Gt=J(tt.start,0,0)*100,Kt=J(tt.start,1,0)*100,Ut=J(tt.end,0,1)*100,Me=J(tt.end,1,1)*100;return`<linearGradient id="${dt}" x1="${Gt}%" y1="${Kt}%" x2="${Ut}%" y2="${Me}%" gradientUnits="objectBoundingBox">${st}</linearGradient>`}const $t=J(tt.center,0,.5)*100,Qt=J(tt.center,1,.5)*100,oe=(tt.radius??.5)*100;return`<radialGradient id="${dt}" cx="${$t}%" cy="${Qt}%" r="${oe}%" gradientUnits="objectBoundingBox">${st}</radialGradient>`},Lt=(tt,dt)=>/<defs>/i.test(tt)?tt.replace(/<defs>/i,`<defs>${dt}`):tt.replace(/(<svg[^>]*>)/i,`$1<defs>${dt}</defs>`);if(z&&z.isEnabled!==!1&&(z.width||0)>0){const tt=et?1:this.normalizeOpacity(z.opacity??100),dt=et?"#FFFFFF":z.color||(j==null?void 0:j.color)||"#000000";let G="";const st=z.fill;if(st&&st.type){if(st.type==="Solid")G=st.color||z.color||"#000000";else if(st.type==="LinearGradient"||st.type==="RadialGradient"||st.type==="Linear"||st.type==="Radial"){const zt="exode-stroke";F=Lt(F,de(st,zt,tt)),G=`url(#${zt})`}}G||(G=dt),F.match(/\bstroke\s*=\s*["']/i)?F=F.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,zt=>/stroke\s*=\s*["']\s*(none|transparent)\s*["']/i.test(zt)?zt:`stroke="${G}"`):F=F.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke="${G}"`),F=F.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),`stroke:${G}`);let J=s.width||a||100,$t=s.height||r||100;const Qt=at.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(Qt){const zt=parseFloat(Qt[1]),ae=parseFloat(Qt[2]);!isNaN(zt)&&!isNaN(ae)&&(J=zt,$t=ae)}const oe=Math.max(.001,a/J),Gt=Math.max(.001,r/$t),Kt=(oe+Gt)/2,Ut=(z.width||1)/Kt;F.match(/\bstroke-width\s*=\s*["']/i)?F=F.replace(/\bstroke-width\s*=\s*["'][^"']*["']/gi,`stroke-width="${Ut}"`):F=F.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-width="${Ut}"`),F=F.replace(/stroke-width\s*:\s*[^;"')]+/gi,`stroke-width:${Ut}`),F.match(/\bstroke-opacity\s*=\s*["']/i)?F=F.replace(/\bstroke-opacity\s*=\s*["'][^"']*["']/gi,`stroke-opacity="${tt}"`):F=F.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-opacity="${tt}"`),F=F.replace(/stroke-opacity\s*:\s*[^;"')]+/gi,`stroke-opacity:${tt}`);const Me=z.lineCap||"round";F.match(/\bstroke-linecap\s*=\s*["']/i)?F=F.replace(/\bstroke-linecap\s*=\s*["'][^"']*["']/gi,`stroke-linecap="${Me}"`):F=F.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linecap="${Me}"`),F=F.replace(/stroke-linecap\s*:\s*[^;"')]+/gi,`stroke-linecap:${Me}`);const Pe=z.lineJoin||"round";F.match(/\bstroke-linejoin\s*=\s*["']/i)?F=F.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${Pe}"`):F=F.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linejoin="${Pe}"`),F=F.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${Pe}`);const Ee=z.trimStart??0,Ae=z.trimEnd??1,Oe=z.trimOffset??0,xe=z.dashOffset??0,We=Ee!==0||Ae!==1||Oe!==0||xe!==0;if(We){const zt=Math.max(0,Math.min(1,Ee)),ae=Math.max(0,Math.min(1,Ae));this.frameCount%600===0&&this.debugLog(`SVG Trim - Object: ${i.name||i.id}, Start: ${zt}, End: ${ae}`);const Ce=(J+$t)*2,Le=(Oe%1+1)%1,Re=(xe%1+1)%1;let ue="",fe=0;if(zt>=ae)ue=`0 ${Ce}`,fe=0;else{const he=Ce*(ae-zt),Ie=Ce-he;fe=-(Ce*(zt+Le+Re)),ue=`${he} ${Ie}`}F.match(/\bstroke-dasharray\s*=/i)?F=F.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${ue}"`):F=F.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dasharray="${ue}"`),F=F.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${ue}`),F.match(/\bstroke-dashoffset\s*=/i)?F=F.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${fe}"`):F=F.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dashoffset="${fe}"`),F=F.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${fe}`)}else if(z.dashArray&&z.dashArray.length>0){const zt=z.dashArray.join(" ");F=F.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${zt}"`),F=F.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${zt}`),z.dashOffset&&(F=F.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${z.dashOffset}"`),F=F.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${z.dashOffset}`))}if(!/\bstroke\s*=\s*["']/i.test(at)&&!new RegExp("(?<![a-z-])stroke\\s*:","i").test(at)){let zt="",ae="";if(We){const ue=s.width||a||100,fe=s.height||r||100,he=(ue+fe)*2,Ie=Math.max(0,Math.min(1,Ee)),Be=Math.max(0,Math.min(1,Ae)),Ne=(Oe%1+1)%1,He=(xe%1+1)%1;if(Ie>=Be)zt=` stroke-dasharray="0 ${he}"`,ae=' stroke-dashoffset="0"';else{const Ye=he*(Be-Ie),Ue=he-Ye,qe=-(he*(Ie+Ne+He));zt=` stroke-dasharray="${Ye} ${Ue}"`,ae=` stroke-dashoffset="${qe}"`}}else(K=z.dashArray)!=null&&K.length&&(zt=` stroke-dasharray="${z.dashArray.join(" ")}"`,z.dashOffset&&(ae=` stroke-dashoffset="${z.dashOffset}"`));const Ce=` stroke-linecap="${z.lineCap||"round"}"`,Le=` stroke-linejoin="${z.lineJoin||"round"}"`,Re=`stroke="${G}" stroke-width="${Ut}" stroke-opacity="${tt}"${Ce}${Le}${zt}${ae}`;F=F.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(ue,fe,he)=>`${fe}${he}<g ${Re}>`),F=F.replace(/<\/svg>/i,"</g></svg>")}}else z&&z.isEnabled===!1&&(F=F.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,'stroke="none"'),F=F.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),"stroke:none"));const ht=new Blob([F],{type:"image/svg+xml"}),ct=URL.createObjectURL(ht);Bt.onload=()=>{if(URL.revokeObjectURL(ct),this.frameCount%900===0){const tt=this.imageCache.get(Ct);tt&&this.debugLog(`SVG Payload Ready: ${i.name||i.id} (${tt.naturalWidth}x${tt.naturalHeight})`)}},Bt.onerror=()=>{URL.revokeObjectURL(ct),this.debugLog(`SVG Error: Failed to load payload for ${i.name||i.id}`)},Bt.src=ct,this.imageCache.set(Ct,Bt)}let yt=null;if(Bt.complete&&Bt.naturalWidth>0?(yt=Bt,this.lastValidSvgImgMap.set(i.id,Bt)):yt=this.lastValidSvgImgMap.get(i.id)||null,yt&&yt.complete&&yt.naturalWidth>0){const F=Math.max(1,a),Ft=Math.max(1,r);if(et&&(j==null?void 0:j.type)==="Solid"){this.maskBuffer||(this.maskBuffer=document.createElement("canvas"),this.maskCtx=this.maskBuffer.getContext("2d")),this.maskBuffer.width=F,this.maskBuffer.height=Ft,this.maskCtx.setTransform(1,0,0,1,0,0),this.maskCtx.globalCompositeOperation="source-over",this.maskCtx.globalAlpha=1,this.maskCtx.filter="none",this.maskCtx.clearRect(0,0,F,Ft),this.maskCtx.drawImage(yt,0,0,F,Ft),this.maskCtx.globalCompositeOperation="source-in";const se=j.color||"#000000",Ht=this.normalizeOpacity(j.opacity??100);this.maskCtx.fillStyle=se,this.maskCtx.globalAlpha=Ht,this.maskCtx.fillRect(0,0,F,Ft),t.drawImage(this.maskBuffer,-F/2,-Ft/2,F,Ft)}else l!==0?(t.save(),this.drawRoundRect(t,-F/2,-Ft/2,F,Ft,l),t.clip(),t.drawImage(yt,-F/2,-Ft/2,F,Ft),t.restore()):t.drawImage(yt,-F/2,-Ft/2,F,Ft)}}}else if(h.type==="LineGraph")this.renderLineGraph(t,h,a,r);else if(i.type==="Shape"){if(this.applyPath(t,h,a,r,l),t.save(),n.blur&&n.blur.amount>0&&(t.filter=`blur(${n.blur.amount}px)`),n.fill){const at=t.globalAlpha;if(((A=n.fill)==null?void 0:A.type)==="Image"&&(n.fill.originalSrc||n.fill.src)){const gt=n.fill.originalSrc||n.fill.src;let j=this.imageCache.get(gt);j||(j=new Image,j.src=gt,this.imageCache.set(gt,j)),j.complete&&j.naturalWidth>0&&(t.save(),this.applyPath(t,h,a,r,l),t.clip(),this.renderFittedImage(t,j,-a/2,-r/2,a,r,n.fill.fillMode),t.restore())}else{const gt=this.createCanvasFill(t,n.fill,a,r);t.fillStyle=gt||(typeof n.fill=="string"?n.fill:n.fill.color||"transparent"),t.globalAlpha=at*this.normalizeOpacity(n.fill.opacity??100),this.applyPath(t,h,a,r,l),t.fill()}t.globalAlpha=at}t.restore(),n.stroke&&n.stroke.width>0&&this.applyStrokeAlignment(t,n,h,a,r,l)}else if(i.type==="Frame"||i.type==="Group"&&!i.isStructuralGroup){const at=e.width??s.width??i.width??a,gt=e.height??s.height??i.height??r,j=l;if(t.save(),t.beginPath(),this.drawRoundRect(t,-at/2,-gt/2,at,gt,j),n.fill&&n.fill.type!=="None"){const z=t.globalAlpha,D=this.createCanvasFill(t,n.fill,at,gt);t.fillStyle=D||n.fill.color||"transparent",t.globalAlpha=z*this.normalizeOpacity(n.fill.opacity??100),t.fill(),t.globalAlpha=z}if(t.restore(),n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1){const z={type:"Rectangle"};this.applyStrokeAlignment(t,n,z,at,gt,j)}}else i.type==="Group"&&i.isStructuralGroup||(i.type==="Component"&&i.variant==="inputbox"?this.renderInputBox(t,i):i.type==="Component"&&i.variant==="button"?this.renderButton(t,i):i.type==="Component"&&i.variant==="toggle_button"?this.renderToggleButton(t,i):i.type==="Toggle"||i.type==="Component"&&i.variant==="toggle"?this.renderToggle(t,i):i.type==="Slider"||i.type==="Component"&&i.variant==="slider"?this.renderSlider(t,i):i.type==="Dropdown"||i.type==="Component"&&i.variant==="dropdown"?this.renderDropdown(t,i):i.type==="ListView"||i.type==="Component"&&i.variant==="listview"?this.renderListView(t,i):i.type==="Checkbox"||i.type==="Component"&&i.variant==="checkbox"?this.renderCheckbox(t,i):i.type==="RadioGroup"||i.type==="Component"&&i.variant==="radiogroup"?this.renderRadioGroup(t,i):i.type==="BarChart"||i.type==="Component"&&i.variant==="barchart"?this.renderBarChart(t,i):i.type==="PieChart"||i.type==="Component"&&i.variant==="piechart"?this.renderPieChart(t,i):i.type==="Joystick"||i.type==="Component"&&i.variant==="joystick"?this.renderJoystick(t,i):this.frameCount%300===0&&this.warn("[Engine] Unhandled object type in renderObject:",i.type,"Geo:",(_=i.geometry)==null?void 0:_.type));if(this.applyArtEffectOverlay(t,i,h,a,r,l),xt&&At==="BackgroundBlur"&&this.applyBackgroundBlurGlass(t,h,a,r,l,Mt),ne&&ne.enabled&&t.restore(),i.children&&i.children.length>0){const gt=i.type==="Frame",j=i.clipsContent!==void 0?i.clipsContent:i.clipContent!==void 0?i.clipContent:gt;if(t.save(),j){t.beginPath();const D=e.width??(s==null?void 0:s.width)??i.width??0,et=e.height??(s==null?void 0:s.height)??i.height??0,mt=e.cornerRadius??(s==null?void 0:s.corner_radius)??i.cornerRadius??0;this.drawRoundRect(t,-D/2,-et/2,D,et,mt),t.clip()}let z=0;for(i.children.forEach(D=>{const et=o.get(D);if(!et)return;const mt=this.objectStates.get(D),Pt=(mt==null?void 0:mt.geometry)||et.geometry;if(Pt&&Pt.isMask&&(mt==null?void 0:mt.visible)!==!1){const Ct=Pt.width||0,Bt=Pt.height||0;this.applyObjectTransform(t,D);const yt=(mt==null?void 0:mt.corner_radius)??(Pt==null?void 0:Pt.corner_radius)??0;this.applyPath(t,Pt,Ct,Bt,yt),t.clip(),z++}else this.renderObject(t,et,o)});z>0;)t.restore(),z--;t.restore()}if(Jt){this.maskCtx.restore(),(e.masks||(i.maskedBy?[{maskId:i.maskedBy,inverted:i.maskInverted===!0,type:i.maskType||"alpha",opacity:i.maskOpacity!==void 0?i.maskOpacity/100:1,feather:i.maskFeather||0,isVisible:!0}]:[])).filter(z=>z.isVisible!==!1&&o.has(z.maskId)).forEach(z=>{var yt,F,Ft,se,Ht,de;const D=o.get(z.maskId),et=this.objectStates.get(D.id),mt=z.feather||0,Pt=z.inverted===!0,Ct=z.opacity!==void 0?typeof z.opacity=="number"?z.opacity:z.opacity/100:1;if((z.type||"alpha")==="luma"){(!this.lumaBuffer||this.lumaBuffer.width!==this.maskBuffer.width||this.lumaBuffer.height!==this.maskBuffer.height)&&(this.lumaBuffer=document.createElement("canvas"),this.lumaBuffer.width=this.maskBuffer.width,this.lumaBuffer.height=this.maskBuffer.height,this.lumaCtx=this.lumaBuffer.getContext("2d",{willReadFrequently:!0}),this.lumaCtx&&(this.lumaCtx.imageSmoothingEnabled=!0,this.lumaCtx.imageSmoothingQuality="high")),this.lumaCtx.setTransform(1,0,0,1,0,0),this.lumaCtx.globalCompositeOperation="source-over",this.lumaCtx.globalAlpha=1,this.lumaCtx.filter="none",this.lumaCtx.clearRect(0,0,this.lumaBuffer.width,this.lumaBuffer.height),this.lumaCtx.save(),this.rootTransform&&this.lumaCtx.setTransform(this.rootTransform),this.applyAbsoluteTransform(this.lumaCtx,D.id,o),mt>0&&(this.lumaCtx.filter=`blur(${mt}px)`),this.lumaCtx.globalAlpha=Ct;const Lt=(et==null?void 0:et.width)||D.geometry.width||0,ht=(et==null?void 0:et.height)||D.geometry.height||0,ct=(et==null?void 0:et.corner_radius)??D.corner_radius??0;if(((yt=D.geometry)==null?void 0:yt.type)==="Text"){const st=et!=null&&et.geometry?this.deepMerge(D.geometry,et.geometry):D.geometry,J=et!=null&&et.style?this.deepMerge(D.style,et.style):D.style;this._renderText(this.lumaCtx,D,{...st,width:Lt,height:ht,corner_radius:ct},J,et,Lt,ht,!0)}else if(((F=D.geometry)==null?void 0:F.type)==="Image"){const st=D.geometry.src;if(st){let J=this.imageCache.get(st);J||(J=new Image,J.src=st,this.imageCache.set(st,J)),J.complete&&J.naturalWidth>0?this.lumaCtx.drawImage(J,-Lt/2,-ht/2,Lt,ht):(this.applyPath(this.lumaCtx,D.geometry,Lt,ht,ct),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else if(((Ft=D.geometry)==null?void 0:Ft.type)==="SVG"){const st=D.geometry.svgContent;if(st){const J=`__lumamask_${D.id}`;let $t=this.imageCache.get(J);if(!$t){$t=new Image;const Qt=new Blob([st],{type:"image/svg+xml"});$t.src=URL.createObjectURL(Qt),$t.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(J,$t)}$t.complete&&$t.naturalWidth>0?this.lumaCtx.drawImage($t,-Lt/2,-ht/2,Lt,ht):(this.applyPath(this.lumaCtx,D.geometry,Lt,ht,ct),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else this.applyPath(this.lumaCtx,D.geometry,Lt,ht,ct),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill();this.lumaCtx.restore();const tt=this.maskCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight),dt=this.lumaCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight).data,G=tt.data;for(let st=0;st<G.length;st+=4){const J=dt[st],$t=dt[st+1],Qt=dt[st+2];let oe=(.299*J+.587*$t+.114*Qt)/255;Pt&&(oe=1-oe),G[st+3]*=oe}this.maskCtx.putImageData(tt,0,0)}else{this.maskCtx.save(),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),this.maskCtx.globalCompositeOperation=Pt?"destination-out":"destination-in",mt>0&&(this.maskCtx.filter=`blur(${mt}px)`),this.maskCtx.globalAlpha=Ct,this.applyAbsoluteTransform(this.maskCtx,D.id,o);const Lt=(et==null?void 0:et.width)||D.geometry.width||0,ht=(et==null?void 0:et.height)||D.geometry.height||0,ct=(et==null?void 0:et.corner_radius)??D.corner_radius??0;if(((se=D.geometry)==null?void 0:se.type)==="Text"){const tt=et!=null&&et.geometry?this.deepMerge(D.geometry,et.geometry):D.geometry,dt=et!=null&&et.style?this.deepMerge(D.style,et.style):D.style;this._renderText(this.maskCtx,D,{...tt,width:Lt,height:ht,corner_radius:ct},dt,et,Lt,ht,!0)}else if(((Ht=D.geometry)==null?void 0:Ht.type)==="Image"){const tt=D.geometry.src;if(tt){let dt=this.imageCache.get(tt);dt||(dt=new Image,dt.src=tt,this.imageCache.set(tt,dt)),dt.complete&&dt.naturalWidth>0?this.maskCtx.drawImage(dt,-Lt/2,-ht/2,Lt,ht):(this.applyPath(this.maskCtx,D.geometry,Lt,ht,ct),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else if(((de=D.geometry)==null?void 0:de.type)==="SVG"){const tt=D.geometry.svgContent;if(tt){const dt=`__alphamask_${D.id}`;let G=this.imageCache.get(dt);if(!G){G=new Image;const st=new Blob([tt],{type:"image/svg+xml"});G.src=URL.createObjectURL(st),G.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(dt,G)}G.complete&&G.naturalWidth>0?this.maskCtx.drawImage(G,-Lt/2,-ht/2,Lt,ht):(this.applyPath(this.maskCtx,D.geometry,Lt,ht,ct),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else this.applyPath(this.maskCtx,D.geometry,Lt,ht,ct),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill();this.maskCtx.restore()}}),Yt.save(),Yt.setTransform(1,0,0,1,0,0);const j=i.maskBlendMode||i.blendMode;j&&j!=="Normal"&&(Yt.globalCompositeOperation=j.toLowerCase()),Yt.drawImage(this.maskBuffer,0,0),Yt.restore(),Yt.restore()}else t.restore()}}_renderText(t,i,o,e,s,n,a,r=!1,c=!1){var bt,ft,wt,It,Mt,xt,At,Tt,Nt;let l=o.text||"";if(o.textInputId&&!r){const Z=this.inputs.get(o.textInputId);Z!==void 0&&(l=String(Z),s.geometry&&s.geometry.type==="Text"&&(s.geometry.text=l))}if(o.svgPath){const Z=o.svgPath;t.save();const pt=((bt=e==null?void 0:e.fill)==null?void 0:bt.color)||"#000000",Et=((ft=e==null?void 0:e.fill)==null?void 0:ft.opacity)!==void 0?(wt=e==null?void 0:e.fill)==null?void 0:wt.opacity:1;t.fillStyle=pt,t.globalAlpha*=Et;const ut=new Path2D(Z);t.fill(ut),t.restore();return}let h=l||"";o.enableSegments===!0&&o.segments&&Array.isArray(o.segments)&&(h=o.segments.map(Z=>Z&&Z.text?Z.text:"").join(""));const u=o.textCase||"none";u==="uppercase"?h=h.toUpperCase():u==="lowercase"?h=h.toLowerCase():u==="capitalize"&&(h=h.replace(/\b\w/g,Z=>Z.toUpperCase()));let f=((It=o.fontWeight)==null?void 0:It.toString())||"400",d=o.fontStyle||"normal";f.toLowerCase().includes("italic")&&(d="italic",f=f.replace(/italic/gi,"").trim()||"400");const p=this.mapFontWeight(f),y=Math.max(1,o.fontSize||32);let m=o.fontFamily||"Inter";const b=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];b.forEach(Z=>{const pt=new RegExp(`[\\s-]${Z}$`,"i");pt.test(m)&&(m=m.replace(pt,"").trim())});const C=`${o.smallCaps===!0?"small-caps ":""}${d} ${p} ${y}px "${m}", sans-serif`;t.font=C;const w=o.textVerticalAlign||"top";t.textBaseline="top";const M=o.textAlign||"left";t.textAlign=M;let I=0;if(typeof o.letterSpacing=="number")I=o.letterSpacing;else if(typeof o.letterSpacing=="object"&&o.letterSpacing.value!==void 0){const Z=o.letterSpacing;I=Z.unit==="PERCENT"?Z.value/100*y:Z.value}t.letterSpacing!==void 0&&(t.letterSpacing=`${I}px`);const k=o.kerning||"auto",T=o.kerningValue||0;k==="manual"&&T!==0&&(t.letterSpacing=`${I+T}px`);const x=o.paragraphSpacing||0;let P=o.lineHeight??1.2;typeof P=="string"&&(P=parseFloat(P)),P>5&&y>0&&(P=P/y);const E=(P||1.2)*y,L=o.isPointText===!0||!o.width||o.width<=0,O=((Mt=o.padding)==null?void 0:Mt.left)||((xt=o.padding)==null?void 0:xt.right)||0,W=L?1e5:o.width&&o.width>0?Math.ceil(o.width)-O*2:1e5;o.autoHeight;const B=Ze({text:h,fontFamily:m,fontSize:y,fontWeight:p,fontStyle:d,lineHeight:P,width:W,letterSpacing:I,paragraphSpacing:x,paragraphIndent:o.paragraphIndent||0,segments:o.segments,enableSegments:o.enableSegments,textCase:u,hyphenation:o.hyphenation,composer:o.composer,balanceRaggedLines:o.balanceRaggedLines}),$=B.lines||[],Y=B.maxFontSize||y,H=this.fontLeadingFactors[m]??.5,K=(E-y)*H;let A=B.height,_=n,R=a;if(_===0||R===0||_>=1e5){let Z=0,pt=0;const Et=B.fullText||h;($||[]).forEach(ut=>{const St=ut.text||"",Rt=t.measureText(St).width+(St.length>0?(St.length-1)*I:0);Rt>Z&&(Z=Rt),pt+=St.length,pt<Et.length&&(Et[pt]===`
|
|
23
|
-
`||
|
|
24
|
-
`&&
|
|
25
|
-
`||
|
|
26
|
-
`||
|
|
27
|
-
`||
|
|
28
|
-
`&&
|
|
29
|
-
`||
|
|
30
|
-
`&&
|
|
31
|
-
`||
|
|
32
|
-
`||
|
|
33
|
-
`&&ut++)}),t.globalAlpha=pt}}}applyStrokeAlignment(t,i,o,e,s,n){if(!i.stroke||i.stroke.width<=0||i.stroke.isEnabled===!1)return;const a=i.stroke,r=a.width,c=(a.alignment||"center").toLowerCase();if(t.save(),i.fill&&i.fill.type!=="None"&&i.fill.isEnabled!==!1&&i.fill.opacity!==0&&i.fill.color!=="transparent"&&i.fill.color!=="rgba(0,0,0,0)"&&(t.shadowColor="transparent",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),a.fill){const m=this.createCanvasFill(t,a.fill,e,s);m?t.strokeStyle=m:t.strokeStyle=a.color||"#000000"}else t.strokeStyle=a.color||"#000000";const h=t.globalAlpha;t.globalAlpha=h*this.normalizeOpacity(a.opacity??100),t.lineWidth=r,t.lineCap=a.lineCap||"round",t.lineJoin=a.lineJoin||"round",a.miterLimit!==void 0&&(t.miterLimit=a.miterLimit);const u=a.trimStart??0,f=a.trimEnd??1,d=a.trimOffset??0,p=a.dashOffset??0,y=a.dashArray||[];if(u!==0||f!==1||d!==0){const m=this.getPerimeter(o,e,s);if(m>0){const b=Math.max(0,Math.min(1,u)),v=Math.max(0,Math.min(1,f));if(b<v){const S=m*(v-b),C=m-S,w=-(m*(b+d%1));t.setLineDash([S,C]),t.lineDashOffset=w+p*m}else if(b===v)t.setLineDash([0,m]);else{const S=m*(1-b+v),C=m-S,w=-(m*b);t.setLineDash([S,C]),t.lineDashOffset=w+p*m}}}else y.length>0&&(t.setLineDash(y),t.lineDashOffset=p);(o==null?void 0:o.type)==="Line"||e===0||s===0?(this.applyPath(t,o,e,s,n),t.stroke()):c==="inside"?(t.lineWidth=r*2,t.save(),this.applyPath(t,o,e,s,n),t.clip(),t.stroke(),t.restore()):c==="outside"?(t.lineWidth=r*2,this.applyPath(t,o,e,s,n),t.stroke(),t.save(),t.globalCompositeOperation="destination-out",this.applyPath(t,o,e,s,n),t.fill(),t.restore()):(t.lineWidth=r,this.applyPath(t,o,e,s,n),t.stroke()),t.restore()}getPerimeter(t,i,o){switch(this.ensurePathPoints(t),t==null?void 0:t.type){case"Rectangle":return(i+o)*2;case"Ellipse":{const e=Math.abs(i)/2,s=Math.abs(o)/2,n=Math.abs(t.sweepAngle??360),a=t.ratio||0,r=Math.PI*(3*(e+s)-Math.sqrt((3*e+s)*(e+3*s)));if(n>=360&&a<=0)return r;let c=n/360*r;if(a>0){const l=Math.PI*(3*(e*a+s*a)-Math.sqrt((3*e*a+s*a)*(e*a+3*s*a)));c+=n/360*l,n<360&&(c+=2*Math.sqrt((e-e*a)**2+(s-s*a)**2))}else n<360&&(c+=2*Math.max(e,s));return isNaN(c)?0:c}case"Line":return t.length||Math.sqrt(i*i+o*o);case"Triangle":return i+Math.sqrt((i/2)**2+o**2)*2;case"Polygon":{const e=t.sides||3,s=t.radius||Math.min(i,o)/2;return 2*e*s*Math.sin(Math.PI/e)}case"Star":{const e=t.points||5,s=t.outer_radius||Math.min(i,o)/2,n=t.inner_radius||s/2,a=Math.PI/e;return Math.sqrt(s*s+n*n-2*s*n*Math.cos(a))*e*2}case"Path":{const e=t.points||[];if(e.length<2)return t.length||0;let s=0,n=e[0].x,a=e[0].y;for(let r=1;r<e.length;r++){const c=e[r];if(c.moveTo){n=c.x,a=c.y;continue}const l=n,h=a,u=e[r-1].out_x,f=e[r-1].out_y;if(u!==void 0||c.in_x!==void 0?s+=this.getBezierLength(l,h,u??l,f??h,c.in_x??c.x,c.in_y??c.y,c.x,c.y):s+=Math.sqrt((c.x-l)**2+(c.y-h)**2),n=c.x,a=c.y,c.closePath||r===e.length-1&&(t.is_closed||t.isClosed)){const d=n,p=a,y=[...e.slice(0,r+1)].reverse().find(M=>M.moveTo)||e[0],m=y.x,b=y.y,v=e[r].out_x,S=e[r].out_y,C=y.in_x,w=y.in_y;v!==void 0||C!==void 0?s+=this.getBezierLength(d,p,v??d,S??p,C??m,w??b,m,b):s+=Math.sqrt((m-d)**2+(b-p)**2)}}return s}default:return(i+o)*2}}getBezierLength(t,i,o,e,s,n,a,r,c=10){let l=0,h=t,u=i;for(let f=1;f<=c;f++){const d=f/c,p=1-d,y=d*d,m=p*p,b=m*p,v=y*d,S=b*t+3*m*d*o+3*p*y*s+v*a,C=b*i+3*m*d*e+3*p*y*n+v*r,w=S-h,M=C-u;l+=Math.sqrt(w*w+M*M),h=S,u=C}return l}getBezierTAtLength(t,i,o,e,s,n,a,r,c,l=20){if(t<=0)return 0;let h=0,u=i,f=o;for(let d=1;d<=l;d++){const p=d/l,y=1-p,m=p*p,b=y*y,v=b*y,S=m*p,C=v*i+3*b*p*e+3*y*m*n+S*r,w=v*o+3*b*p*s+3*y*m*a+S*c,M=C-u,I=w-f,k=Math.sqrt(M*M+I*I);if(h+k>=t){const T=t-h,x=k===0?0:T/k;return(d-1+x)/l}h+=k,u=C,f=w}return 1}getPointOnPath(t,i,o,e){if(this.ensurePathPoints(t),(t==null?void 0:t.type)==="Path"){const s=t.points||[];if(s.length<2)return{x:0,y:0,angle:0};let n=1/0,a=-1/0,r=1/0,c=-1/0;s.forEach(b=>{typeof b.x=="number"&&typeof b.y=="number"&&(n=Math.min(n,b.x),a=Math.max(a,b.x),r=Math.min(r,b.y),c=Math.max(c,b.y),b.out_x!==void 0&&(n=Math.min(n,b.out_x),a=Math.max(a,b.out_x)),b.out_y!==void 0&&(r=Math.min(r,b.out_y),c=Math.max(c,b.out_y)),b.in_x!==void 0&&(n=Math.min(n,b.in_x),a=Math.max(a,b.in_x)),b.in_y!==void 0&&(r=Math.min(r,b.in_y),c=Math.max(c,b.in_y)))});const l=(n+a)/2,h=(r+c)/2,f=this.getPerimeter(t,i,o)*e;let d=0;const p=[];let y=s[0],m=s[0];for(let b=1;b<s.length;b++){const v=s[b];if(v.moveTo){y=v,m=v;continue}p.push({p0:y,p1:v}),(v.closePath||b===s.length-1&&(t.is_closed||t.isClosed))&&p.push({p0:v,p1:m}),y=v}for(const b of p){const v=b.p0,S=b.p1;let C=0;const w=v.out_x!==void 0||S.in_x!==void 0;if(w?C=this.getBezierLength(v.x,v.y,v.out_x??v.x,v.out_y??v.y,S.in_x??S.x,S.in_y??S.y,S.x,S.y):C=Math.sqrt((S.x-v.x)**2+(S.y-v.y)**2),d+C>=f||b===p[p.length-1]){let M=0;if(w)return M=this.getBezierTAtLength(f-d,v.x,v.y,v.out_x??v.x,v.out_y??v.y,S.in_x??S.x,S.in_y??S.y,S.x,S.y,20),this.getBezierPointAndAngle(M,v,S,l,h);{M=C===0?0:(f-d)/C;const I=v.x+(S.x-v.x)*M-l,k=v.y+(S.y-v.y)*M-h,T=Math.atan2(S.y-v.y,S.x-v.x);return{x:I,y:k,angle:T}}}d+=C}}else if(t.type==="Ellipse"){const s=Math.abs(i)/2,n=Math.abs(o)/2,a=t.sweepAngle??360,c=((t.startAngle??0)+a*e)*Math.PI/180,l=s*Math.cos(c),h=n*Math.sin(c),u=-s*Math.sin(c),f=n*Math.cos(c),d=Math.atan2(f,u);return{x:l,y:h,angle:d}}else if((t==null?void 0:t.type)==="Rectangle"){const s=Math.abs(i),n=Math.abs(o),r=(s+n)*2*e;let c=0,l=0,h=0;return r<s?(c=-s/2+r,l=-n/2,h=0):r<s+n?(c=s/2,l=-n/2+(r-s),h=Math.PI/2):r<2*s+n?(c=s/2-(r-(s+n)),l=n/2,h=Math.PI):(c=-s/2,l=n/2-(r-(2*s+n)),h=-Math.PI/2),{x:c,y:l,angle:h}}return{x:0,y:0,angle:0}}getBezierPointAndAngle(t,i,o,e,s){const n=i.x,a=i.y,r=i.out_x??i.x,c=i.out_y??i.y,l=o.in_x??o.x,h=o.in_y??o.y,u=o.x,f=o.y,d=1-t,p=t*t,y=d*d,m=y*d,b=p*t,v=m*n+3*y*t*r+3*d*p*l+b*u-e,S=m*a+3*y*t*c+3*d*p*h+b*f-s,C=3*y*(r-n)+6*d*t*(l-r)+3*p*(u-l),w=3*y*(c-a)+6*d*t*(h-c)+3*p*(f-h),M=Math.atan2(w,C);return{x:v,y:S,angle:M}}applyAbsoluteTransform(t,i,o){if(!o.get(i))return;const s=[];let n=i;for(;n;){s.unshift(n);const a=o.get(n);n=a==null?void 0:a.parentId}s.forEach(a=>{this.applyObjectTransform(t,a)})}applyObjectTransform(t,i){const o=this.objectStates.get(i);if(!o)return;t.translate(o.x,o.y),t.rotate(o.rotation*Math.PI/180);const e=(o.scale_x??1)*(o.flip_x===!0?-1:1),s=(o.scale_y??1)*(o.flip_y===!0?-1:1);t.scale(e,s)}applyArtEffectOverlay(t,i,o,e,s,n){var f,d,p,y,m;const a=this.objectStates.get(i.id),r=((f=a==null?void 0:a.style)==null?void 0:f.artEffect)||i.artEffect||((d=i.style)==null?void 0:d.artEffect);if(!r||!r.enabled)return;const c=r.type,l=r.intensity??.5,h=r.speed??1,u=r.scale??10;if(c==="acid_gradient"||c==="acid_rave"||c==="shimmer"||c==="glint_overlay"||c==="halftone"||c==="noise"||c==="scanlines"||c==="chromatic_aberration"||c==="pixelate"||c==="glitch"||c==="fold_overlay"||c==="crumple_overlay"){if(t.save(),this.applyPath(t,o,e,s,n),t.clip(),c==="shimmer"){const v=this.currentTime*h%2/2,S=t.createLinearGradient(-e,-s,e,s);S.addColorStop(Math.max(0,v-.2),"rgba(255,255,255,0)"),S.addColorStop(v,`rgba(255,255,255,${l*.8})`),S.addColorStop(Math.min(1,v+.2),"rgba(255,255,255,0)"),t.fillStyle=S,t.globalCompositeOperation="screen",t.fillRect(-e/2,-s/2,e,s),t.globalCompositeOperation="source-over"}else if(c==="glint_overlay"){let S=((this._lastPointerPos||{x:0}).x-(((p=i.transform)==null?void 0:p.x)??0)+300)/600;S=Math.max(-.2,Math.min(1.2,S));const C=t.createLinearGradient(-e,-s,e,s);C.addColorStop(Math.max(0,S-.15),"rgba(255,255,255,0)"),C.addColorStop(Math.max(0,Math.min(1,S)),`rgba(255,255,255,${l})`),C.addColorStop(Math.min(1,S+.15),"rgba(255,255,255,0)"),t.fillStyle=C,t.globalCompositeOperation="screen",t.fillRect(-e/2,-s/2,e,s),t.globalCompositeOperation="source-over"}else if(c==="fold_overlay"){const b=this._lastPointerPos||{x:0,y:0},v=b.x-(((y=i.transform)==null?void 0:y.x)??0),S=b.y-(((m=i.transform)==null?void 0:m.y)??0),C=t.createLinearGradient(v>0?-e/2:e/2,S>0?-s/2:s/2,v>0?e/2:-e/2,S>0?s/2:-s/2);C.addColorStop(0,`rgba(0,0,0,${l*.6})`),C.addColorStop(.4,"rgba(0,0,0,0)"),C.addColorStop(.5,`rgba(255,255,255,${l*.4})`),C.addColorStop(1,`rgba(0,0,0,${l*.2})`),t.fillStyle=C,t.globalCompositeOperation="overlay",t.fillRect(-e/2,-s/2,e,s),t.globalCompositeOperation="source-over",t.beginPath(),v>0&&S>0?(t.moveTo(e/2-40,s/2),t.lineTo(e/2,s/2-40),t.lineTo(e/2-40,s/2-40)):v<0&&S>0?(t.moveTo(-e/2+40,s/2),t.lineTo(-e/2,s/2-40),t.lineTo(-e/2+40,s/2-40)):v>0&&S<0?(t.moveTo(e/2-40,-s/2),t.lineTo(e/2,-s/2+40),t.lineTo(e/2-40,-s/2+40)):(t.moveTo(-e/2+40,-s/2),t.lineTo(-e/2,-s/2+40),t.lineTo(-e/2+40,-s/2+40)),t.closePath(),t.fillStyle="#ffffff",t.shadowColor="rgba(0,0,0,0.5)",t.shadowBlur=10,t.shadowOffsetX=v>0?-2:2,t.shadowOffsetY=S>0?-2:2,t.fill()}else if(c==="crumple_overlay"){const b=Math.floor(e/u),v=document.createElement("canvas");v.width=b,v.height=Math.floor(s/u);const S=v.getContext("2d"),C=S.createImageData(v.width,v.height);for(let w=0;w<C.data.length;w+=4){const M=Math.random()>.95?150:255;C.data[w]=M,C.data[w+1]=M,C.data[w+2]=M,C.data[w+3]=255*l}S.putImageData(C,0,0),t.globalCompositeOperation="multiply",t.imageSmoothingEnabled=!1,t.drawImage(v,-e/2,-s/2,e,s)}else if(c==="acid_gradient"||c==="acid_rave"){const b=this.currentTime*h,v=r.color1,S=r.color2,C=t.createLinearGradient(-e/2,-s/2,e/2,s/2);if(v&&S){const w=b*60%360;C.addColorStop(0,this._shiftHue(v,w,l*.7)),C.addColorStop(1,this._shiftHue(S,(w+180)%360,l*.7))}else{const w=b*100%360,M=(w+180)%360;C.addColorStop(0,`hsla(${w}, 80%, 50%, ${l*.5})`),C.addColorStop(1,`hsla(${M}, 80%, 50%, ${l*.5})`)}t.fillStyle=C,t.globalCompositeOperation="screen",t.fillRect(-e/2,-s/2,e,s)}else if(c==="halftone"){const b=Math.max(2,u*(1-l*.8)),v=document.createElement("canvas");v.width=b,v.height=b;const S=v.getContext("2d");if(S){S.fillStyle="black",S.beginPath(),S.arc(b/2,b/2,b/2*l,0,Math.PI*2),S.fill();const C=t.createPattern(v,"repeat");C&&(t.globalAlpha=.3*l,t.fillStyle=C,t.fillRect(-e/2,-s/2,e,s))}}else if(c==="noise"){const b=Math.floor(e*s*l*.02);t.globalAlpha=.4*l;for(let v=0;v<b;v++){const S=Math.random()>.5?255:0;t.fillStyle=`rgba(${S}, ${S}, ${S}, ${.5+Math.random()*.5})`,t.fillRect(-e/2+Math.random()*e,-s/2+Math.random()*s,2,2)}}else if(c==="scanlines"){t.globalAlpha=.2*l,t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1;for(let b=-s/2;b<s/2;b+=4)t.beginPath(),t.moveTo(-e/2,b),t.lineTo(e/2,b),t.stroke()}else if(c==="chromatic_aberration"){const b=5*l;t.globalCompositeOperation="screen",t.globalAlpha=.5,t.fillStyle="cyan",t.fillRect(-e/2-b,-s/2,e,s),t.fillStyle="magenta",t.fillRect(-e/2+b,-s/2,e,s)}else if(c==="pixelate"){const b=Math.max(2,Math.round(u*(1-l*.5))),v=document.createElement("canvas"),S=Math.max(1,Math.ceil(e/b)),C=Math.max(1,Math.ceil(s/b));v.width=S,v.height=C;const w=v.getContext("2d");if(w){w.imageSmoothingEnabled=!1;const M=t.getTransform(),I=M.e-e/2,k=M.f-s/2;w.drawImage(t.canvas,I,k,e,s,0,0,S,C),t.imageSmoothingEnabled=!1,t.drawImage(v,0,0,S,C,-e/2,-s/2,e,s),t.imageSmoothingEnabled=!0}}else if(c==="glitch"){const b=this.currentTime*h,v=r.chaosAmount??.2,S=Math.max(3,Math.floor(8*l)),C=l*e*.15;t.globalCompositeOperation="screen",t.globalAlpha=l*.4;const w=C*.3;t.fillStyle="rgba(255, 0, 0, 0.4)",t.fillRect(-e/2+w,-s/2,e,s),t.fillStyle="rgba(0, 255, 255, 0.4)",t.fillRect(-e/2-w,-s/2,e,s),t.globalCompositeOperation="source-over",t.globalAlpha=1;const M=s/S;for(let I=0;I<S;I++){const k=Math.sin(I*127.1+b*311.7*h)*43758.5,T=k-Math.floor(k);if(T>1-v){const x=(T-(1-v))/v*C*(Math.random()>.5?1:-1),P=-s/2+I*M,E=t.getTransform(),L=E.e-e/2+x,O=E.f+P;t.save(),t.beginPath(),t.rect(-e/2,P,e,M),t.clip(),t.globalAlpha=.8,t.drawImage(t.canvas,L,O,e,M,-e/2+x,P,e,M),t.restore()}}}t.restore()}}_shiftHue(t,i,o){let e=0,s=0,n=0;if(t.startsWith("#")){const f=t.replace("#","");e=parseInt(f.substring(0,2),16)/255,s=parseInt(f.substring(2,4),16)/255,n=parseInt(f.substring(4,6),16)/255}const a=Math.max(e,s,n),r=Math.min(e,s,n);let c=0,l=0,h=(a+r)/2;if(a!==r){const f=a-r;switch(l=h>.5?f/(2-a-r):f/(a+r),a){case e:c=((s-n)/f+(s<n?6:0))/6;break;case s:c=((n-e)/f+2)/6;break;case n:c=((e-s)/f+4)/6;break}}return`hsla(${(((c*360+i)%360+360)%360).toFixed(0)}, ${(l*100).toFixed(0)}%, ${(h*100).toFixed(0)}%, ${o})`}applyBackgroundBlurGlass(t,i,o,e,s,n){const a=n.radius??10,r=n.color??"rgba(255,255,255,0.2)",c=n.opacity??.5,l=n.noise??0;t.save(),this.applyPath(t,i,o,e,s),t.clip();const h=t.getTransform(),u=h.e-o/2,f=h.f-e/2;try{const p=document.createElement("canvas");p.width=Math.max(1,Math.ceil(o)),p.height=Math.max(1,Math.ceil(e));const y=p.getContext("2d");if(y){y.drawImage(t.canvas,u,f,o,e,0,0,o,e),y.filter=`blur(${a}px)`;const m=document.createElement("canvas");m.width=p.width,m.height=p.height;const b=m.getContext("2d");b.filter=`blur(${a}px)`,b.drawImage(p,0,0),t.globalCompositeOperation="source-over",t.globalAlpha=1,t.drawImage(m,-o/2,-e/2,o,e)}}catch{}t.globalCompositeOperation="source-over",t.globalAlpha=c,t.fillStyle=r,t.fillRect(-o/2,-e/2,o,e),t.globalAlpha=1,t.globalCompositeOperation="source-atop";const d=t.createLinearGradient(-o/2,-e/2,o/2,e/2);if(d.addColorStop(0,"rgba(255,255,255,0.12)"),d.addColorStop(.3,"rgba(255,255,255,0.04)"),d.addColorStop(.5,"rgba(255,255,255,0.0)"),d.addColorStop(1,"rgba(255,255,255,0.0)"),t.fillStyle=d,t.fillRect(-o/2,-e/2,o,e),l>0){if(t.globalAlpha=l/100,!this._noiseTileCanvas){const y=document.createElement("canvas");y.width=64,y.height=64;const m=y.getContext("2d"),b=m.createImageData(64,64),v=b.data;for(let S=0;S<v.length;S+=4){const C=Math.floor(Math.random()*255);v[S]=C,v[S+1]=C,v[S+2]=C,v[S+3]=18}m.putImageData(b,0,0),this._noiseTileCanvas=y}const p=t.createPattern(this._noiseTileCanvas,"repeat");p&&(t.fillStyle=p,t.fillRect(-o/2,-e/2,o,e))}t.restore(),t.save(),t.globalAlpha=1,t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1.5,this.applyPath(t,i,o,e,s),t.stroke(),t.restore()}applyPath(t,i,o,e,s){i!=null&&i.data&&(i.type==="Path"||i.type==="Subtract"||i.type==="Union"||i.type==="Intersect"||i.type==="Exclude"||i.type),t.beginPath(),this._tracePath(t,i,o,e,s)}_tracePath(t,i,o,e,s){if(i){if(this.ensurePathPoints(i),(i==null?void 0:i.type)==="Rectangle"||i.type==="Image"){const n=s!==void 0?s:i.corner_radius??0;this.drawRoundRect(t,-o/2,-e/2,o,e,n)}else if(i.type==="Line")t.moveTo(-o/2,0),t.lineTo(o/2,0);else if(i.type==="Ellipse"){const{startAngle:n=0,sweepAngle:a=360,ratio:r=0}=i,c=o/2,l=e/2,h=n*Math.PI/180,u=a*Math.PI/180,f=h+u;a>=360&&r<=0?t.ellipse(0,0,c,l,0,0,Math.PI*2):(t.ellipse(0,0,c,l,0,h,f,!1),r>0?t.ellipse(0,0,c*r,l*r,0,f,h,!0):t.lineTo(0,0),t.closePath())}else if(i.type==="Triangle")t.moveTo(0,-e/2),t.lineTo(o/2,e/2),t.lineTo(-o/2,e/2),t.closePath();else if(i.type==="Polygon"){const n=i.sides||3,a=i.radius||Math.min(o,e)/2;for(let r=0;r<n;r++){const c=r*2*Math.PI/n-Math.PI/2,l=a*Math.cos(c),h=a*Math.sin(c);r===0?t.moveTo(l,h):t.lineTo(l,h)}t.closePath()}else if(i.type==="Star"){const n=i.points||5,a=i.outer_radius||Math.min(o,e)/2;let r=i.inner_radius;r==null?r=a*.382:r<=1&&(r=a*r);for(let c=0;c<n*2;c++){const l=c*Math.PI/n-Math.PI/2,h=c%2===0?a:r,u=h*Math.cos(l),f=h*Math.sin(l);c===0?t.moveTo(u,f):t.lineTo(u,f)}t.closePath()}else if(((i==null?void 0:i.type)==="Path"||i.type==="Subtract"||i.type==="Union"||i.type==="Intersect"||i.type==="Exclude"||i.type==="BooleanOperation")&&i.points){this.frameCount%300===0&&this.log("[Engine] Tracing Path:",i.points.length,"points");let n=1/0,a=-1/0,r=1/0,c=-1/0;if(i.points.forEach(u=>{typeof u.x=="number"&&typeof u.y=="number"&&(n=Math.min(n,u.x),a=Math.max(a,u.x),r=Math.min(r,u.y),c=Math.max(c,u.y),u.out_x!==void 0&&(n=Math.min(n,u.out_x),a=Math.max(a,u.out_x)),u.out_y!==void 0&&(r=Math.min(r,u.out_y),c=Math.max(c,u.out_y)),u.in_x!==void 0&&(n=Math.min(n,u.in_x),a=Math.max(a,u.in_x)),u.in_y!==void 0&&(r=Math.min(r,u.in_y),c=Math.max(c,u.in_y)))}),n===1/0)return;const l=(n+a)/2,h=(r+c)/2;if(isNaN(l)||isNaN(h)){this.warn("[Engine] Invalid path center:",l,h);return}i.points.forEach((u,f)=>{if(f===0||u.moveTo)t.moveTo(u.x-l,u.y-h);else{const d=i.points[f-1];if(!d)return;const p=(d.out_x??d.x)-l,y=(d.out_y??d.y)-h,m=(u.in_x??u.x)-l,b=(u.in_y??u.y)-h;isNaN(p)||isNaN(m)||isNaN(u.x)?t.lineTo(u.x-l,u.y-h):t.bezierCurveTo(p,y,m,b,u.x-l,u.y-h)}if(u.closePath||f===i.points.length-1&&(i.is_closed||i.isClosed)){const d=[...i.points.slice(0,f+1)].reverse().find(p=>p.moveTo)||i.points[0];d&&(u.out_x!==void 0||d.in_x!==void 0)&&t.bezierCurveTo((u.out_x??u.x)-l,(u.out_y??u.y)-h,(d.in_x??d.x)-l,(d.in_y??d.y)-h,d.x-l,d.y-h),t.closePath()}})}else if(i.points&&Array.isArray(i.points)){let n=1/0,a=-1/0,r=1/0,c=-1/0;i.points.forEach(u=>{n=Math.min(n,u.x),a=Math.max(a,u.x),r=Math.min(r,u.y),c=Math.max(c,u.y)});const l=(n+a)/2,h=(r+c)/2;i.points.forEach((u,f)=>{if(f===0)t.moveTo(u.x-l,u.y-h);else{const d=i.points[f-1];d.out_x!==void 0||u.in_x!==void 0?t.bezierCurveTo((d.out_x??d.x)-l,(d.out_y??d.y)-h,(u.in_x??u.x)-l,(u.in_y??u.y)-h,u.x-l,u.y-h):t.lineTo(u.x-l,u.y-h)}(u.closePath||f===i.points.length-1&&(i.is_closed||i.isClosed))&&t.closePath()})}}}renderInputBox(t,i){var it,lt;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=((it=i.geometry)==null?void 0:it.width)||250,n=((lt=i.geometry)==null?void 0:lt.height)||45,a=this.focusedId===i.id,r=this.lastHoveredObjectId===i.id,c=e.previewState||"default",l=c!=="default"?c:a?"focused":r?"hovered":"default",h=e.label||{visible:!0,text:"Label"},u=e.helperText||{visible:!1,text:"Helper text"},f=e.leftIcon||{visible:!1},d=e.rightIcon||{visible:!1},p=e.multiline===!0,y=e.corner_radius??8,m=e.corners||{tl:y,tr:y,bl:y,br:y},b=[m.tl,m.tr,m.br,m.bl];let v=e.backgroundColor||"rgba(31, 41, 55, 1)",S=e.borderColor||"rgba(55, 65, 81, 1)",C=e.borderWidth??1.5,w=e.color||"#ffffff",M=e.placeholderColor||"rgba(156, 163, 175, 1)",I=e.fontSize||14;const k=`${l}Style`,T=e[k];T?(T.backgroundColor!==void 0&&(v=T.backgroundColor),T.borderColor!==void 0&&(S=T.borderColor),T.borderWidth!==void 0&&(C=T.borderWidth),T.color!==void 0&&(w=T.color),T.placeholderColor!==void 0&&(M=T.placeholderColor),T.fontSize!==void 0&&(I=T.fontSize)):l==="focused"?(S=e.focusBorderColor||"rgba(59, 130, 246, 1)",C=Math.max(C,2)):l==="hovered"||l==="hover"?(S=e.hoverBorderColor||S,v=e.hoverBackgroundColor||v):l==="disabled"?(v=e.disabledBackgroundColor||"rgba(31, 41, 55, 0.6)",S=e.disabledBorderColor||"rgba(55, 65, 81, 0.4)"):l==="error"&&(S="rgba(239, 68, 68, 1)",C=Math.max(C,2)),t.beginPath(),this.drawRoundRect(t,-s/2,-n/2,s,n,b);const x=this.createCanvasFill(t,v,s,n);if(x&&(t.fillStyle=x,t.fill()),C>0){const nt=this.createCanvasFill(t,S,s,n);if(nt&&(t.strokeStyle=nt,t.lineWidth=C,t.stroke()),l==="focused"||l==="focus"){t.save(),t.beginPath();const bt=b.map(ft=>ft+2);this.drawRoundRect(t,-s/2-2,-n/2-2,s+4,n+4,bt),t.strokeStyle="rgba(59, 130, 246, 0.3)",t.lineWidth=2,t.stroke(),t.restore()}}const P=(nt,bt)=>{if(!nt.visible||!nt.svgPath)return;const ft=nt.size||14,wt=nt.offset??16,It=nt.color||"#ffffff",Mt=bt?-(s/2)+wt:s/2-wt,xt=nt.svgPath;if(t.save(),t.translate(Mt,0),!xt.startsWith("<svg")){const At=new Path2D(xt),Tt=ft/24;t.scale(Tt,Tt),t.translate(-12,-12),t.fillStyle=It,t.fill(At)}t.restore()};P(f,!0),P(d,!1);const E=e.text||"",L=e.placeholder||"Enter text...",O=!E,W=E||L,B=O?M:w,$=I,Y=e.fontFamily||"Inter",H=e.fontWeight||400;t.font=`${H} ${$}px "${Y}", sans-serif`,t.fillStyle=B,t.textAlign="left",t.textBaseline=p?"top":"middle";const K=e.inputPadding??16,A=f.visible?(f.offset??16)+(f.size||14)/2+8:K,_=d.visible?(d.offset??16)+(d.size||14)/2+8:K,R=-(s/2)+A,X=s-A-_,N=e.inputType==="password"?"•".repeat(W.length):W;if(t.save(),t.beginPath(),t.rect(R-2,-n/2+4,X+4,n-8),t.clip(),p){const nt=N.split(`
|
|
34
|
-
`);let bt=-n/2+K;const ft=$*1.2;let wt=0;nt.forEach((It,Mt)=>{const xt=It.split(" ");let At="";for(let Tt=0;Tt<xt.length;Tt++){const Nt=At+xt[Tt]+" ";t.measureText(Nt).width>X&&Tt>0?(t.fillText(At,R,bt),At=xt[Tt]+" ",bt+=ft):At=Nt}t.fillText(At,R,bt),wt=t.measureText(At).width,Mt<nt.length-1&&(bt+=ft,wt=0)}),a&&!O&&Math.floor(performance.now()/500)%2===0&&t.fillRect(R+wt,bt,1.5,$)}else{const bt=t.measureText(N).width;let ft=0;if(bt>X&&(ft=bt-X),t.fillText(N,R-ft,0),a&&!O&&Math.floor(performance.now()/500)%2===0){const It=R+bt-ft;t.fillRect(It,-($/2),1.5,$)}}if(t.restore(),h.visible!==!1){const nt=h.text||"Label",bt=h.fontSize||12,ft=h.color||"rgba(156, 163, 175, 1)",wt=h.offset??8;t.font=`600 ${bt}px "${Y}", sans-serif`,t.fillStyle=ft,t.textAlign="left",t.textBaseline="bottom";const It=-(s/2),Mt=-(n/2)-wt;t.fillText(nt,It,Mt)}if(u.visible===!0){const nt=u.text||"Helper text",bt=u.fontSize||11,ft=l==="error"?"rgba(239, 68, 68, 1)":u.color||"rgba(156, 163, 175, 1)",wt=u.offset??6;t.font=`400 ${bt}px "${Y}", sans-serif`,t.fillStyle=ft,t.textAlign="left",t.textBaseline="top";const It=-(s/2),Mt=n/2+wt;t.fillText(nt,It,Mt)}}renderSlider(t,i){const o=this.objectStates.get(i.id),e=(o==null?void 0:o.geometry)||i.geometry,s=(o==null?void 0:o.options)||i.options||{},n=e.width||200,a=s.value??50,r=s.min??0,l=(s.max??100)-r,h=l===0?0:(a-r)/l,u=s.trackHeight||4,f=s.trackRoundedness??2,d=s.trackShape??"Rectangle",p=s.trackPath||"",y=s.accentColor||"#3b82f6",m=s.inactiveColor||"#374151",b=s.thumbShape||"Ellipse",v=s.thumbWidth??16,S=s.thumbHeight??16,C=s.thumbRoundedness??0,w=s.thumbColor||"#ffffff",M=s.thumbPath||"",I=s.thumbIcon||"",k=s.showValueTooltip??!1,T=s.tooltipBgColor||"#333333",x=s.tooltipColor||"#ffffff",P=s.tooltipOffsetX??0,E=s.tooltipOffsetY??-25,L=(X,N,it,lt,nt,bt,ft)=>{if((X==="Custom"||X==="Icon")&&ft)try{const wt=new Path2D(ft);if(t.save(),t.translate(N,it),X==="Icon"){const It=Math.min(lt,nt)/24;t.scale(It,It),t.translate(-12,-12)}t.fill(wt),t.restore();return}catch(wt){console.error("Error drawing slider shape in engine:",wt)}if(t.beginPath(),X==="Ellipse")t.ellipse(N,it,lt/2,nt/2,0,0,Math.PI*2);else if(X==="Rectangle")this.drawRoundRect(t,N-lt/2,it-nt/2,lt,nt,bt);else if(X==="Triangle")t.moveTo(N,it-nt/2),t.lineTo(N+lt/2,it+nt/2),t.lineTo(N-lt/2,it+nt/2),t.closePath();else if(X==="Diamond")t.moveTo(N,it-nt/2),t.lineTo(N+lt/2,it),t.lineTo(N,it+nt/2),t.lineTo(N-lt/2,it),t.closePath();else if(X==="Polygon"){const wt=i.geometry.sides||3,It=i.geometry.radius||Math.min(lt,nt)/2;for(let Mt=0;Mt<wt;Mt++){const xt=Mt*2*Math.PI/wt-Math.PI/2,At=N+It*Math.cos(xt),Tt=it+It*Math.sin(xt);Mt===0?t.moveTo(At,Tt):t.lineTo(At,Tt)}t.closePath()}else if(X==="Star"){const It=Math.min(lt,nt)/2,Mt=It/2;for(let xt=0;xt<10;xt++){const At=xt%2===0?It:Mt,Tt=xt*Math.PI/5-Math.PI/2;t.lineTo(N+At*Math.cos(Tt),it+At*Math.sin(Tt))}t.closePath()}else X==="Line"&&(t.moveTo(N-lt/2,it),t.lineTo(N+lt/2,it));t.fill()},O=this.createCanvasFill(t,m,n,u);O&&(t.fillStyle=O,t.strokeStyle=O),d==="Line"?(t.lineWidth=u,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(n/2,0),t.stroke()):L(d,0,0,n,u,f,p);const W=n-v,B=-n/2+v/2+h*W,$=B- -n/2;if($>0){const X=this.createCanvasFill(t,y,n,u);X&&(t.fillStyle=X,t.strokeStyle=X),d==="Line"?(t.lineWidth=u,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(B,0),t.stroke()):d==="Rectangle"&&(t.beginPath(),this.drawRoundRect(t,-n/2,-u/2,$,u,f),t.fill())}t.save(),t.translate(B,0);const Y=t.getTransform(),H=Math.sqrt(Y.a*Y.a+Y.b*Y.b)||1;t.shadowColor="rgba(0,0,0,0.2)",t.shadowBlur=4*H,t.shadowOffsetY=1*H;const K=this.createCanvasFill(t,w,v,S);if(K&&(t.fillStyle=K),L(b,0,0,v,S,C,b==="Icon"?I:M),t.restore(),k){t.save(),t.translate(B+P,E);const X=Math.round(a).toString();t.font="10px Inter, sans-serif";const N=t.measureText(X),it=6,lt=4,nt=N.width+it*2,bt=14+lt;t.beginPath(),this.drawRoundRect(t,-nt/2,-bt/2,nt,bt,4),t.fillStyle=T,t.fill(),t.fillStyle=x,t.textAlign="center",t.textBaseline="middle",t.fillText(X,0,0),t.restore()}const A=s.label||{},_=s.helperText||{},R=s.fontFamily||"Inter";if(A.visible!==!1){const X=A.text||"Label",N=A.fontSize||12,it=A.color||"rgba(156, 163, 175, 1)",lt=A.offset??8;t.font=`600 ${N}px "${R}", sans-serif`,t.fillStyle=it,t.textAlign="left",t.textBaseline="bottom";const nt=-(n/2),bt=-(u/2)-lt;t.fillText(X,nt,bt)}if(_.visible===!0){const X=_.text||"Helper text",N=_.fontSize||11,it=_.color||"rgba(156, 163, 175, 1)",lt=_.offset??6;t.font=`400 ${N}px "${R}", sans-serif`,t.fillStyle=it,t.textAlign="left",t.textBaseline="top";const nt=-(n/2),bt=u/2+lt;t.fillText(X,nt,bt)}}renderDropdown(t,i){var E;const o=this.objectStates.get(i.id);if(!o)return;const e=o.options||i.options||{},s=i.geometry.width||160,n=i.geometry.height||40,a=-s/2,r=-n/2,c=e.corner_radius??6,l=e.disabled||e.previewState==="disabled",h=this.lastHoveredObjectId===i.id||e.previewState==="hover",u=(e.isOpen||e.previewState==="active")&&!l;let f=e.backgroundColor,d=e.borderColor,p=e.color||"#333333";l?(f=e.disabledBackgroundColor||"#f3f4f6",d=e.disabledBorderColor||"#e5e7eb",p=e.disabledColor||"#9ca3af"):u?(f=e.activeBackgroundColor||f,d=e.activeBorderColor||d,p=e.activeColor||p):h&&(f=e.hoverBackgroundColor||f,d=e.hoverBorderColor||d,p=e.hoverColor||p),f||(f="#ffffff"),d||(d="#e5e7eb");const y=t.globalAlpha;t.globalAlpha=y*(e.opacity??1),this.drawRoundRect(t,a,r,s,n,c),t.fillStyle=this.createCanvasFill(t,typeof f=="string"?{type:"Solid",color:f}:f,s,n)||"#ffffff",t.fill();const m=e.borderWidth??1;m>0&&(t.strokeStyle=this.createCanvasFill(t,typeof d=="string"?{type:"Solid",color:d}:d,s,n)||"#e5e7eb",t.lineWidth=m,t.stroke());const b=12,v=e.chevronType||"chevron",S=e.chevronSize||16,C=(u?e.openIconColor:e.closedIconColor)||e.chevronColor||"#6b7280";if(v!=="none"){const L=a+s-b-S/2;t.save(),t.translate(L,0);const O=u?e.openIconAngle??180:e.closedIconAngle??0;if(t.rotate(O*Math.PI/180),t.strokeStyle=C,t.fillStyle=C,t.lineWidth=1.5,t.lineCap="round",t.lineJoin="round",v==="chevron")t.beginPath(),t.moveTo(-S/2,-S*.2),t.lineTo(0,S*.2),t.lineTo(S/2,-S*.2),t.stroke();else if(v==="custom"||v==="path"){const W=u&&e.openIconPath||e.closedIconPath;if(W){const B=new Path2D(W);t.save();const $=S/24;t.scale($,$),t.translate(-12,-12),t.fill(B),t.restore()}}t.restore()}const w=e.selectedOption||e.placeholder||"Select...",M=e.fontSize||14,I=e.fontWeight||400,k=e.fontFamily||"Inter, sans-serif";t.font=`${I} ${M}px ${k}`;const T=l?e.disabledColor||"#9ca3af":!e.selectedOption&&e.placeholder?"#9ca3af":p;t.fillStyle=this.createCanvasFill(t,typeof T=="string"?{type:"Solid",color:T}:T,s,n)||"#333333",t.textAlign="left",t.textBaseline="middle";const x=v==="none"?0:S+8,P=s-b*2-x;if(t.save(),t.beginPath(),t.rect(a+b,r,P,n),t.clip(),t.fillText(w,a+b,0),t.restore(),u&&!l){const L=r+n+4,O=e.optionsList||[],W=e.itemHeight||32,B=e.listPadding??4,$=O.length*W+B*2,Y=e.listCornerRadius??c;t.save();const H=e.listShadow||{},K=t.getTransform(),A=Math.sqrt(K.a*K.a+K.b*K.b)||1;t.shadowColor=typeof H.color=="string"?H.color:((E=H.color)==null?void 0:E.color)||"rgba(0,0,0,0.15)",t.shadowBlur=(H.blur??12)*A,t.shadowOffsetY=(H.offsetY??6)*A,t.shadowOffsetX=(H.offsetX??0)*A,t.beginPath(),this.drawRoundRect(t,a,L,s,$,Y),t.fillStyle=this.createCanvasFill(t,typeof e.listBackgroundColor=="string"?{type:"Solid",color:e.listBackgroundColor}:e.listBackgroundColor||{type:"Solid",color:"#ffffff"},s,$)||"#ffffff",t.fill();const _=e.listBorderWidth??1;_>0&&(t.shadowColor="transparent",t.strokeStyle=this.createCanvasFill(t,typeof e.listBorderColor=="string"?{type:"Solid",color:e.listBorderColor}:e.listBorderColor||{type:"Solid",color:d},s,$)||"#e5e7eb",t.lineWidth=_,t.stroke()),t.restore();const R=e.itemFontSize||M,X=e.itemFontFamily||k;t.font=`${I} ${R}px ${X}`,O.forEach((N,it)=>{const lt=L+B+it*W;if(N===e.selectedOption)t.fillStyle=this.createCanvasFill(t,typeof e.itemSelectedBackgroundColor=="string"?{type:"Solid",color:e.itemSelectedBackgroundColor}:e.itemSelectedBackgroundColor||{type:"Solid",color:"#f3f4f6"},s,W)||"#f3f4f6",t.fillRect(a+_,lt,s-_*2,W),t.fillStyle=e.itemSelectedColor||e.accentColor||p||"#374151";else if(t.fillStyle=e.listTextColor||p||"#333333",this.activeDropdownId===i.id&&this._lastPointerPos){const bt=this._lastPointerPos.y-(L+B),ft=Math.floor(bt/W);it===ft&&(t.fillStyle=this.createCanvasFill(t,typeof e.itemHoverBackgroundColor=="string"?{type:"Solid",color:e.itemHoverBackgroundColor}:e.itemHoverBackgroundColor||{type:"Solid",color:"#f9fafb"},s,W)||"#f9fafb",t.fillRect(a+_,lt,s-_*2,W),t.fillStyle=e.itemHoverColor||p)}t.fillText(N,a+b,lt+W/2)})}t.globalAlpha=y}renderButton(t,i){if(i.children&&i.children.length>0)return;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=i.geometry||{},n=s.width||120,a=s.height||40,r=this.lastHoveredObjectId===i.id,c=this.activeObjectId===i.id,l=e.label||{},h=e.hoverStyle||{},u=e.activeStyle||{},f=e.icon||{enabled:!1};let d=e.backgroundColor||"#3b82f6",p=l.color||"#ffffff",y=l.text||"Button",m=s.cornerRadius??8,b=e.borderColor||"transparent",v=e.borderWidth||0,S=1;c&&u?(d=u.backgroundColor||d,p=u.color||p,y=u.text||y,S=u.scale??.95,m=u.cornerRadius??m):r&&h&&(d=h.backgroundColor||d,p=h.color||p,y=h.text||y,S=h.scale??1,m=h.cornerRadius??m,b=h.borderColor||b);const C=-n/2,w=-a/2;t.save(),t.scale(S,S),t.beginPath(),this.drawRoundRect(t,C,w,n,a,m);const M=this.createCanvasFill(t,d,n,a);M&&(t.fillStyle=M,t.fill()),(v>0||r&&h.borderColor)&&(t.strokeStyle=b,t.lineWidth=v||(r?1:0),t.stroke());const I=l.fontSize||14,k=l.fontFamily||"Inter",T=l.fontWeight||600;t.font=`${T} ${I}px "${k}", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle=p,t.textAlign="center",t.textBaseline="middle";let x=0;if(f.enabled&&f.svgPath){const P=I*1.1,E=f.gap||8,L=t.measureText(y),W=-(L.width+P+E)/2,B=f.position==="left"?W+P/2:W+L.width+E+P/2;x=f.position==="left"?W+P+E+L.width/2:W+L.width/2,t.save(),t.translate(B,0);const $=new Path2D(f.svgPath),Y=P/24;t.scale(Y,Y),t.translate(-12,-12),t.fillStyle=p,t.fill($),t.restore()}t.fillText(y,x,0),t.restore()}renderToggleButton(t,i){var y,m;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=e.checked??!1,n=((y=i.geometry)==null?void 0:y.width)||120,a=((m=i.geometry)==null?void 0:m.height)||40,r=-n/2,c=-a/2,l=e.corner_radius??8,h=e.label||{},u=s?e.accentColor||"#3b82f6":e.inactiveColor||"#374151",f=s?e.activeTextColor||"#ffffff":e.inactiveTextColor||"#9ca3af";t.save(),t.beginPath(),this.drawRoundRect(t,r,c,n,a,l),t.fillStyle=u,t.fill();const d=h.fontSize||14,p=h.fontFamily||"Inter";t.font=`${h.fontWeight||600} ${d}px "${p}", sans-serif`,t.fillStyle=f,t.textAlign="center",t.textBaseline="middle",t.fillText(h.text||"Toggle",0,0),t.restore()}renderToggle(t,i){var Y,H,K,A,_,R,X,N,it,lt,nt,bt;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=((Y=i.geometry)==null?void 0:Y.width)||52,n=((H=i.geometry)==null?void 0:H.height)||30,a=-s/2,r=-n/2,c=e.checked??!1,l=e.cornerRadius??e.corner_radius??n/2,h=e.toggleStyle||{},u=h.backgroundColor||e.activeColor||"#10b981",f=h.borderColor||e.borderColor||"transparent",d=h.borderWidth??e.borderWidth??0,p=h.knobColor||e.knobColor||"#ffffff",y=c?u:e.inactiveColor||"#374151",m=c?f:e.borderColor||"transparent",b=c?d:e.borderWidth??0,v=c?p:e.knobColor||"#ffffff";e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,s,n,l);const S=this.createCanvasFill(t,y,s,n);if(S&&(t.fillStyle=S,t.fill()),b>0){t.lineWidth=b;const ft=this.createCanvasFill(t,m,s,n);ft&&(t.strokeStyle=ft,t.stroke())}const C=2,w=n-C*2,M=w/2,I=a+C,k=a+s-C-w,T=c?k:I,x=r+C;t.beginPath(),t.arc(T+M,x+M,M,0,Math.PI*2);const P=this.createCanvasFill(t,v,w,w);P&&(t.fillStyle=P,t.fill()),e.disabled&&(t.globalAlpha*=2);let E=!1,L=!1;const O=(c?(K=h.leftLabel)==null?void 0:K.text:null)||((A=e.leftLabel)==null?void 0:A.text)||"",W=(c?(_=h.leftLabel)==null?void 0:_.color:null)||((R=e.leftLabel)==null?void 0:R.color)||"#f3f4f6";if((X=e.leftLabel)!=null&&X.enabled&&O){const ft=e.leftLabel;t.font=`${ft.fontWeight||400} ${ft.fontSize||12}px "${ft.fontFamily||"Inter"}", sans-serif`,t.fillStyle=W,t.textBaseline="middle",t.textAlign="right",t.fillText(O,a-(ft.gap||8),0),E=!0}const B=(c?(N=h.rightLabel)==null?void 0:N.text:null)||((it=e.rightLabel)==null?void 0:it.text)||"",$=(c?(lt=h.rightLabel)==null?void 0:lt.color:null)||((nt=e.rightLabel)==null?void 0:nt.color)||"#f3f4f6";if((bt=e.rightLabel)!=null&&bt.enabled&&B){const ft=e.rightLabel;t.font=`${ft.fontWeight||400} ${ft.fontSize||12}px "${ft.fontFamily||"Inter"}", sans-serif`,t.fillStyle=$,t.textBaseline="middle",t.textAlign="left",t.fillText(B,a+s+(ft.gap||8),0),L=!0}if(!E&&!L&&e.label&&e.label.text){const ft=e.label,wt=ft.fontSize||14,It=ft.fontWeight||400,Mt=ft.fontFamily||"Inter";t.font=`${It} ${wt}px "${Mt}", sans-serif`,t.fillStyle=ft.color||"#f3f4f6",t.textBaseline="middle";const xt=ft.gap||10;let At=0,Tt=0;ft.position==="left"?(t.textAlign="right",At=a-xt,Tt=0):ft.position==="right"?(t.textAlign="left",At=a+s+xt,Tt=0):ft.position==="top"?(t.textAlign="center",At=0,Tt=r-xt,t.textBaseline="bottom"):ft.position==="bottom"?(t.textAlign="center",At=0,Tt=r+n+xt,t.textBaseline="top"):(t.textAlign="left",At=a+s+xt,Tt=0),t.fillText(ft.text,At,Tt)}}renderCheckbox(t,i){var S,C;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=((S=i.geometry)==null?void 0:S.width)||20,n=((C=i.geometry)==null?void 0:C.height)||20,a=-s/2,r=-n/2,c=e.cornerRadius??4,l=e.checked??!1,h=e.activeColor||"#3b82f6",u=e.inactiveColor||"transparent",f=e.checkColor||"#ffffff",d=e.borderColor||"#4b5563",p=e.borderWidth??2,y=l?h:u,m=l?"transparent":d,b=l?0:p;e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,s,n,c);const v=this.createCanvasFill(t,y,s,n);if(v&&(t.fillStyle=v,t.fill()),b>0){t.lineWidth=b;const w=this.createCanvasFill(t,m,s,n);w&&(t.strokeStyle=w,t.stroke())}else if(l){t.lineWidth=1;const w=this.createCanvasFill(t,h,s,n);w&&(t.strokeStyle=w,t.stroke())}if(l){t.save(),t.beginPath();const w=this.createCanvasFill(t,f,s,n);t.strokeStyle=w||f,t.lineWidth=Math.max(2,s*.12),t.lineCap="round",t.lineJoin="round";const M=a+s*.25,I=r+n*.5,k=a+s*.45,T=r+n*.7,x=a+s*.75,P=r+n*.25;t.moveTo(M,I),t.lineTo(k,T),t.lineTo(x,P),t.stroke(),t.restore()}if(e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const w=e.label;t.save(),t.font=`${w.fontWeight||400} ${w.fontSize||14}px "${w.fontFamily||"Inter"}", sans-serif`,t.fillStyle=w.color||"#f3f4f6",t.textBaseline="middle";const M=w.gap||8;let I=0,k=0;w.position==="left"?(t.textAlign="right",I=a-M,k=0):w.position==="right"?(t.textAlign="left",I=a+s+M,k=0):w.position==="top"?(t.textAlign="center",I=0,k=r-M,t.textBaseline="bottom"):w.position==="bottom"&&(t.textAlign="center",I=0,k=r+n+M,t.textBaseline="top"),t.fillText(w.text,I,k),t.restore()}}renderRadioGroup(t,i){var C,w;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=((C=i.geometry)==null?void 0:C.width)||180,n=((w=i.geometry)==null?void 0:w.height)||100,a=-s/2,r=-n/2,c=e.selectedValue,l=e.optionsList||["Option 1","Option 2","Option 3"],h=e.orientation||"vertical",u=e.itemGap!==void 0?e.itemGap:16,f=e.activeColor||"#3b82f6",d=e.inactiveColor||"#4b5563",p=e.textColor||"#ffffff",y=e.fontSize||14,m=e.fontFamily||"Inter",b=e.fontWeight||400;e.disabled&&(t.globalAlpha*=.5);const v=8,S=v*2;if(t.save(),t.font=`${b} ${y}px "${m}", sans-serif`,t.textBaseline="middle",t.textAlign="left",h==="vertical"){const M=Math.max(S,y)+u;l.forEach((I,k)=>{const T=r+k*M+v;t.beginPath(),t.arc(a+v,T,v,0,Math.PI*2);const x=c===I,P=this.createCanvasFill(t,f,S,S),E=this.createCanvasFill(t,d,S,S);x?(t.strokeStyle=P||f,t.lineWidth=2,t.stroke(),t.beginPath(),t.arc(a+v,T,v/2,0,Math.PI*2),t.fillStyle=P||f,t.fill()):(t.strokeStyle=E||d,t.lineWidth=1.5,t.stroke()),t.fillStyle=p,t.fillText(I,a+S+8,T)})}else{let M=a;l.forEach(I=>{const k=c===I,T=t.measureText(I).width;t.beginPath(),t.arc(M+v,0,v,0,Math.PI*2);const x=this.createCanvasFill(t,f,S,S),P=this.createCanvasFill(t,d,S,S);k?(t.strokeStyle=x||f,t.lineWidth=2,t.stroke(),t.beginPath(),t.arc(M+v,0,v/2,0,Math.PI*2),t.fillStyle=x||f,t.fill()):(t.strokeStyle=P||d,t.lineWidth=1.5,t.stroke()),t.fillStyle=p,t.fillText(I,M+S+6,0),M+=S+6+T+u})}if(t.restore(),e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const M=e.label;t.save(),t.font=`${M.fontWeight||400} ${M.fontSize||14}px "${M.fontFamily||"Inter"}", sans-serif`,t.fillStyle=M.color||"#9ca3af",t.textBaseline="middle";const I=M.gap||8;let k=0,T=0;M.position==="left"?(t.textAlign="right",k=a-I,T=0):M.position==="right"?(t.textAlign="left",k=a+s+I,T=0):M.position==="top"?(t.textAlign="center",k=0,T=r-I,t.textBaseline="bottom"):M.position==="bottom"&&(t.textAlign="center",k=0,T=r+n+I,t.textBaseline="top"),t.fillText(M.text,k,T),t.restore()}}renderBarChart(t,i){var T,x;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s={width:((T=i.geometry)==null?void 0:T.width)||300,height:((x=i.geometry)==null?void 0:x.height)||180,chartType:e.chartType||"grouped",stylePreset:e.stylePreset||"default",datasets:e.datasets||[{id:"ds-1",label:"Revenue",data:[42,67,31,55,78,48],color:"#6366f1"}],categories:e.categories||["Jan","Feb","Mar","Apr","May","Jun"],orientation:e.orientation||"vertical",barWidth:e.barWidth!==void 0?e.barWidth:14,barGap:e.barGap!==void 0?e.barGap:4,barCornerRadius:e.barCornerRadius!==void 0?e.barCornerRadius:5,showXAxis:!!e.showXAxis,showYAxis:!!e.showYAxis,xAxisColor:e.xAxisColor||"rgba(255,255,255,0.12)",yAxisColor:e.yAxisColor||"rgba(255,255,255,0.12)",showXLabels:e.showXLabels!==void 0?!!e.showXLabels:!0,showYLabels:!!e.showYLabels,axisLabelColor:e.axisLabelColor||"rgba(255,255,255,0.5)",axisLabelFontSize:e.axisLabelFontSize||9,showLegend:e.showLegend!==void 0?!!e.showLegend:!0,legendColor:e.legendColor||"rgba(255,255,255,0.7)",legendFontSize:e.legendFontSize||9,showGridLines:e.showGridLines!==void 0?!!e.showGridLines:!0,gridColor:e.gridColor||"rgba(255,255,255,0.06)",cardBackground:e.cardBackground||"rgba(255,255,255,0.04)",cardBorderColor:e.cardBorderColor||"rgba(255,255,255,0.08)",barGradient:e.barGradient!==void 0?!!e.barGradient:!0,showValueOnTop:!!e.showValueOnTop,chartBackground:e.chartBackground||"transparent",barStyle:e.barStyle||"solid",barBorderWidth:e.barBorderWidth!==void 0?e.barBorderWidth:1,barBorderColor:e.barBorderColor||"auto",enableShadows:!!e.enableShadows,shadowColor:e.shadowColor||"rgba(0,0,0,0.5)",shadowBlur:e.shadowBlur!==void 0?e.shadowBlur:4,shadowOffsetY:e.shadowOffsetY!==void 0?e.shadowOffsetY:2,valueFontSize:e.valueFontSize||10,valueColor:e.valueColor||"auto",valueFontWeight:e.valueFontWeight||"bold",xAxisLineWidth:e.xAxisLineWidth!==void 0?e.xAxisLineWidth:1,yAxisLineWidth:e.yAxisLineWidth!==void 0?e.yAxisLineWidth:1,gridLineWidth:e.gridLineWidth!==void 0?e.gridLineWidth:1,gridLineDash:e.gridLineDash||[3,4],_getPreset:function(){return ds[this.stylePreset]||ds.default},_resolveColor:function(P,E){const L=this._getPreset();return["#6366f1","#f59e0b","#10b981","#3b82f6","#a855f7"].includes(P)?L.colors[E%L.colors.length]:typeof P=="string"?P:L.colors[E%L.colors.length]},_makeGradient:function(P,E,L,O,W,B){if(!this._getPreset().barGradient&&!this.barGradient)return E;const Y=P.createLinearGradient(L,O,W,B);return Y.addColorStop(0,E),Y.addColorStop(1,E+"44"),Y},_drawRoundedBar:function(P,E,L,O,W,B,$){if(B=Math.min(B,Math.min(Math.abs(O),Math.abs(W))/2),B<=0||O===0||W===0){P.rect(E,L,O,W);return}P.beginPath(),$?(P.moveTo(E,L+W),P.lineTo(E,L+B),P.quadraticCurveTo(E,L,E+B,L),P.lineTo(E+O-B,L),P.quadraticCurveTo(E+O,L,E+O,L+B),P.lineTo(E+O,L+W),P.lineTo(E,L+W)):(P.moveTo(E,L),P.lineTo(E+O-B,L),P.quadraticCurveTo(E+O,L,E+O,L+B),P.lineTo(E+O,L+W-B),P.quadraticCurveTo(E+O,L+W,E+O-B,L+W),P.lineTo(E,L+W),P.lineTo(E,L)),P.closePath()}},n=s.width,a=s.height,r=-n/2,c=-a/2;if(!s.datasets||s.datasets.length===0||s.categories.length===0){t.save(),t.fillStyle="rgba(99,102,241,0.7)",t.font="bold 11px Inter, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("NO CHART DATA",0,0),t.restore();return}const l=s._getPreset();let h=-1/0,u=1/0;const f=s.categories.length,d=s.datasets.length;if(s.chartType==="stacked")for(let P=0;P<f;P++){let E=0,L=0;s.datasets.forEach(O=>{const W=O.data[P]??0;W>=0?E+=W:L+=W}),E>h&&(h=E),L<u&&(u=L)}else s.datasets.forEach(P=>{P.data&&P.data.forEach(E=>{E>h&&(h=E),E<u&&(u=E)})});isFinite(h)||(h=10),isFinite(u)||(u=0),h=Math.max(h,0),u=Math.min(u,0);const p=h-u||10;t.save(),s.enableShadows&&(t.shadowColor=s.shadowColor,t.shadowBlur=s.shadowBlur,t.shadowOffsetY=s.shadowOffsetY),t.font=s.axisLabelFontSize+"px Inter, sans-serif";const y=s.showYLabels?t.measureText(h.toFixed(0)).width+14:10,m=s.showXLabels?s.axisLabelFontSize+12:8,v=(s.showLegend&&d>0?s.legendFontSize+10:0)+8,S=10,C=r+y,w=c+v,M=n-y-S,I=a-v-m;if(s.enableShadows&&(t.shadowColor="transparent"),t.beginPath(),t.roundRect(r,c,n,a,10),t.fillStyle=l.cardBackground,t.fill(),t.strokeStyle=l.cardBorderColor,t.lineWidth=1,t.stroke(),s.chartBackground&&s.chartBackground!=="transparent"&&(t.beginPath(),t.rect(C,w,M,I),t.fillStyle=s.chartBackground,t.fill()),s.showLegend&&d>0){t.font=s.legendFontSize+"px Inter, sans-serif",t.textBaseline="middle";const P=c+12;let E=C;s.datasets.forEach((L,O)=>{const W=s._resolveColor(L.color,O),B=L.label||"Series "+(O+1),$=7;t.beginPath(),t.roundRect(E,P-$/2,$,$,2),t.fillStyle=W,t.fill(),t.fillStyle=l.legendColor,t.textAlign="left",t.fillText(B,E+$+4,P),E+=t.measureText(B).width+$+16})}const k=4;if(s.showGridLines){t.setLineDash(s.gridLineDash||[]),t.lineWidth=s.gridLineWidth||1,t.strokeStyle=l.gridColor;for(let P=0;P<=k;P++)if(s.orientation==="horizontal"){const E=C+P/k*M;t.beginPath(),t.moveTo(E,w),t.lineTo(E,w+I),t.stroke()}else{const E=w+P/k*I;t.beginPath(),t.moveTo(C,E),t.lineTo(C+M,E),t.stroke()}t.setLineDash([])}if(s.showYLabels){t.font=s.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=l.axisLabelColor;for(let P=0;P<=k;P++)if(s.orientation==="horizontal"){const E=u+P/k*p,L=C+P/k*M;t.textAlign="center",t.fillText(E.toFixed(0),L,w+I+s.axisLabelFontSize)}else{const E=h-P/k*p,L=w+P/k*I;t.textAlign="right",t.fillText(E.toFixed(0),C-6,L)}}if(t.setLineDash([]),s.showXAxis&&(t.lineWidth=s.xAxisLineWidth||1,t.strokeStyle=s.xAxisColor,t.beginPath(),t.moveTo(C,w+I),t.lineTo(C+M,w+I),t.stroke()),s.showYAxis&&(t.lineWidth=s.yAxisLineWidth||1,t.strokeStyle=s.yAxisColor,t.beginPath(),t.moveTo(C,w),t.lineTo(C,w+I),t.stroke()),s.enableShadows&&(t.shadowColor=s.shadowColor),s.chartType==="stacked")if(s.orientation==="horizontal"){const P=I/f;for(let E=0;E<f;E++){const L=w+E*P+P/2;s.showXLabels&&(t.font=s.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=l.axisLabelColor,t.shadowColor="transparent",t.fillText(s.categories[E]||"",C-5,L),s.enableShadows&&(t.shadowColor=s.shadowColor));let O=C;s.datasets.forEach((W,B)=>{const $=W.data[E]??0;if($===0)return;const Y=$/p*M,H=Math.min(s.barWidth*d+s.barGap,P-8),K=L-H/2,A=O;O+=Y;const _=s._resolveColor(W.color,B);t.beginPath(),t.fillStyle=s._makeGradient(t,_,A,K,A+Y,K),s._drawRoundedBar(t,A,K,Y,H,B===d-1?s.barCornerRadius:0,!1),s.barStyle==="outline"||s.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=s.barBorderColor==="auto"?_:s.barBorderColor,t.lineWidth=s.barBorderWidth,s.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill()})}}else{const P=M/f;for(let E=0;E<f;E++){const L=C+E*P+P/2;s.showXLabels&&(t.font=s.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillStyle=l.axisLabelColor,t.shadowColor="transparent",t.fillText(s.categories[E]||"",L,w+I+5),s.enableShadows&&(t.shadowColor=s.shadowColor));let O=w+I;s.datasets.forEach((W,B)=>{const $=W.data[E]??0;if($===0)return;const Y=$/p*I,H=Math.min(s.barWidth*d+s.barGap,P-8),K=L-H/2,A=O-Y;O-=Y;const _=s._resolveColor(W.color,B);t.beginPath(),t.fillStyle=s._makeGradient(t,_,K,A,K,A+Y),s._drawRoundedBar(t,K,A,H,Y,B===d-1?s.barCornerRadius:0,!0),s.barStyle==="outline"||s.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=s.barBorderColor==="auto"?_:s.barBorderColor,t.lineWidth=s.barBorderWidth,s.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill()})}}else if(s.orientation==="horizontal"){const P=I/f,E=d*s.barWidth+Math.max(0,(d-1)*s.barGap),L=C+(0-u)/p*M;for(let O=0;O<f;O++){const W=w+O*P+P/2;s.showXLabels&&(t.font=s.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=l.axisLabelColor,t.shadowColor="transparent",t.fillText(s.categories[O]||"",C-5,W),s.enableShadows&&(t.shadowColor=s.shadowColor));const B=W-E/2;s.datasets.forEach(($,Y)=>{const H=$.data[O]??0,K=Math.abs(H/p*M);if(K<1)return;const A=B+Y*(s.barWidth+s.barGap),_=H>=0?L:L-K,R=s._resolveColor($.color,Y);t.beginPath(),t.fillStyle=s._makeGradient(t,R,_,A,_+K,A),s._drawRoundedBar(t,_,A,K,s.barWidth,s.barCornerRadius,!1),s.barStyle==="outline"||s.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=s.barBorderColor==="auto"?R:s.barBorderColor,t.lineWidth=s.barBorderWidth,s.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),s.showValueOnTop&&H!==0&&(t.font=(s.valueFontWeight||"bold")+" "+(s.valueFontSize||10)+"px Inter, sans-serif",t.textAlign=H>=0?"left":"right",t.textBaseline="middle",t.fillStyle=s.valueColor==="auto"?R:s.valueColor||"#fff",t.shadowColor="transparent",t.fillText(H.toString(),H>=0?_+K+4:_-4,A+s.barWidth/2),s.enableShadows&&(t.shadowColor=s.shadowColor))})}}else{const P=M/f,E=d*s.barWidth+Math.max(0,(d-1)*s.barGap),L=w+I-(0-u)/p*I;for(let O=0;O<f;O++){const W=C+O*P+P/2;s.showXLabels&&(t.font=s.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillStyle=l.axisLabelColor,t.shadowColor="transparent",t.fillText(s.categories[O]||"",W,w+I+5),s.enableShadows&&(t.shadowColor=s.shadowColor));const B=W-E/2;s.datasets.forEach(($,Y)=>{const H=$.data[O]??0,K=Math.abs(H/p*I);if(K<1)return;const A=B+Y*(s.barWidth+s.barGap),_=H>=0?L-K:L,R=s._resolveColor($.color,Y);t.beginPath(),t.fillStyle=s._makeGradient(t,R,A,_,A,_+K),s._drawRoundedBar(t,A,_,s.barWidth,K,s.barCornerRadius,!0),s.barStyle==="outline"||s.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=s.barBorderColor==="auto"?R:s.barBorderColor,t.lineWidth=s.barBorderWidth,s.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),s.showValueOnTop&&H!==0&&(t.font=(s.valueFontWeight||"bold")+" "+(s.valueFontSize||10)+"px Inter, sans-serif",t.textAlign="center",t.textBaseline=H>=0?"bottom":"top",t.fillStyle=s.valueColor==="auto"?R:s.valueColor||"#fff",t.shadowColor="transparent",t.fillText(H.toString(),A+s.barWidth/2,H>=0?_-4:_+K+4),s.enableShadows&&(t.shadowColor=s.shadowColor))})}}t.restore()}renderPieChart(t,i){var y,m;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s={width:((y=i.geometry)==null?void 0:y.width)||180,height:((m=i.geometry)==null?void 0:m.height)||180,chartType:e.chartType||"donut",stylePreset:e.stylePreset||"default",slices:e.slices||[{id:"slice-1",label:"Item 1",value:45,color:"#6366f1"}],innerRadius:e.innerRadius!==void 0?e.innerRadius:.55,sliceGap:e.sliceGap!==void 0?e.sliceGap:3,showLabels:!!e.showLabels,labelColor:e.labelColor||"#ffffff",labelFontSize:e.labelFontSize||10,showLegend:e.showLegend!==void 0?!!e.showLegend:!0,legendColor:e.legendColor||"rgba(255,255,255,0.65)",legendFontSize:e.legendFontSize||9,showCenterText:e.showCenterText!==void 0?!!e.showCenterText:!0,centerLabel:e.centerLabel||"Total",centerTextColor:e.centerTextColor||"#ffffff",centerLabelColor:e.centerLabelColor||"rgba(255,255,255,0.4)",_getPreset:function(){return us[this.stylePreset]||us.default},_resolveSliceColor:function(b,v){const S=b.color,C=v,w=this._getPreset();return["#6366f1","#22d3ee","#f59e0b","#ec4899","#34d399","#a855f7","#f87171"].includes(S)?w.colors[C%w.colors.length]:typeof S=="string"?S:w.colors[C%w.colors.length]}},n=s.width,a=s.height;if(!s.slices||s.slices.length===0){t.save(),t.fillStyle="rgba(99,102,241,0.8)",t.font="bold 11px Inter, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("NO PIE DATA",0,0),t.restore();return}const r=s.slices.reduce((b,v)=>b+(v.value||0),0);if(r<=0){t.save(),t.fillStyle="rgba(99,102,241,0.8)",t.font="bold 11px Inter, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("EMPTY DATA",0,0),t.restore();return}const c=s._getPreset();t.save(),t.beginPath(),t.roundRect(-n/2,-a/2,n,a,10),t.fillStyle=c.cardBackground,t.fill(),t.strokeStyle=c.cardBorderColor,t.lineWidth=1,t.stroke();const l=s.showLegend?Math.ceil(s.slices.length/2):0,h=l>0?l*(s.legendFontSize+8)+10:0,u=a-h-16,f=Math.min(n-24,u)/2,d=0,p=-h/2;if(s.chartType==="rose"){const b=Math.max(...s.slices.map(C=>C.value||0)),v=Math.PI*2/s.slices.length,S=f>0?s.sliceGap/f:0;s.slices.forEach((C,w)=>{const M=C.value||0;if(M===0)return;const I=M/b*f,k=-Math.PI/2+w*v+S/2,T=k+v-S,x=s._resolveSliceColor(C,w);if(t.beginPath(),t.moveTo(d,p),t.arc(d,p,I,k,T),t.closePath(),t.fillStyle=x+"cc",t.fill(),t.strokeStyle=x,t.lineWidth=1.5,t.stroke(),s.showLabels){const P=k+(T-k)/2,E=d+I*.65*Math.cos(P),L=p+I*.65*Math.sin(P),O=Math.round(M/r*100);t.save(),t.font=`bold ${s.labelFontSize}px Inter, sans-serif`,t.fillStyle=c.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${O}%`,E,L),t.restore()}})}else{const b=s.chartType==="pie"?0:s.innerRadius,v=f*Math.max(0,b),S=f>0?s.sliceGap/f:0;let C=-Math.PI/2;if(s.slices.forEach((w,M)=>{const I=w.value||0;if(I===0){C+=I/r*Math.PI*2;return}const k=I/r*Math.PI*2,T=C+S/2,x=C+k-S/2;if(x<=T){C+=k;return}const P=s._resolveSliceColor(w,M);if(t.beginPath(),t.fillStyle=P,v<=0?(t.moveTo(d,p),t.arc(d,p,f,T,x),t.lineTo(d,p)):(t.moveTo(d+f*Math.cos(T),p+f*Math.sin(T)),t.arc(d,p,f,T,x),t.arc(d,p,v,x,T,!0),t.closePath()),t.fill(),s.showLabels){const E=T+(x-T)/2,L=v+(f-v)/2,O=d+L*Math.cos(E),W=p+L*Math.sin(E),B=Math.round(I/r*100);t.save(),t.font=`bold ${s.labelFontSize}px Inter, sans-serif`,t.fillStyle=c.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${B}%`,O,W),t.restore()}C+=k}),s.chartType==="donut"&&s.showCenterText&&v>14){const w=Math.round(r),M=Math.min(Math.floor(v*.52),20),I=Math.min(Math.floor(v*.26),10);t.textAlign="center",t.textBaseline="middle",t.font=`bold ${M}px Inter, sans-serif`,t.fillStyle=c.centerTextColor,t.fillText(w.toString(),d,p-I*.5),s.centerLabel&&(t.font=`${I}px Inter, sans-serif`,t.fillStyle=c.centerLabelColor,t.fillText(s.centerLabel,d,p+M*.6))}}if(s.showLegend&&s.slices.length>0){t.font=`${s.legendFontSize}px Inter, sans-serif`;const b=2,v=n/b,S=s.legendFontSize+8,C=a/2-h+10,w=-n/2+10;s.slices.forEach((M,I)=>{const k=I%b,T=Math.floor(I/b),x=w+k*v,P=C+T*S,E=s._resolveSliceColor(M,I),L=7;t.beginPath(),t.roundRect(x,P-L/2,L,L,2),t.fillStyle=E,t.fill(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=c.legendColor;const O=Math.round((M.value||0)/r*100),W=`${M.label||"Item"} ${O}%`,B=v-L-20;let $=W;for(;t.measureText($).width>B&&$.length>4;)$=$.slice(0,-4)+"…";t.fillText($,x+L+4,P)})}t.restore()}renderJoystick(t,i){var p,y,m,b,v;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.width)!==void 0?o.width:((p=i.geometry)==null?void 0:p.width)??i.width??100,s=(o==null?void 0:o.height)!==void 0?o.height:((y=i.geometry)==null?void 0:y.height)??i.height??100,n=Math.min(e,s)*.45,a=Math.min(e,s)*.15;let r=i.handleX||0,c=i.handleY||0;o&&o.handleX!==void 0&&(r=o.handleX),o&&o.handleY!==void 0&&(c=o.handleY),t.save();let l=0,h=0;i.handleOrigin==="top-left"?(l=e/2,h=s/2):i.handleOrigin==="bottom-right"&&(l=-e/2,h=-s/2),t.translate(l,h),t.beginPath(),i.boundsShape==="square"?t.rect(-n,-n,n*2,n*2):t.arc(0,0,n,0,Math.PI*2),t.fillStyle="rgba(0,0,0,0.2)",(m=i.style)!=null&&m.fill&&typeof i.style.fill=="string"?t.fillStyle=i.style.fill:(b=i.style)!=null&&b.fill&&i.style.fill.type==="solid"&&(t.fillStyle=i.style.fill.color),t.fill(),(v=i.style)!=null&&v.stroke&&i.style.stroke.isEnabled!==!1&&(t.lineWidth=i.style.stroke.width||1,t.strokeStyle=i.style.stroke.color||"#000",t.stroke());const u=n-a;let f=0,d=0;i.joystickType==="2D"?(f=r*u,d=c*u):i.joystickType==="1D_X"?(f=r*u,d=0):i.joystickType==="1D_Y"&&(f=0,d=c*u),t.beginPath(),t.arc(f,d,a,0,Math.PI*2),t.fillStyle="#fff",t.fill(),t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1,t.stroke(),t.restore()}getRadioGroupItemIndexAtPointer(t,i,o){var I,k;const e=t.options||{},s=this.objectStates.get(t.id)||{},n=e.optionsList||[];if(n.length===0)return null;const a=s.width!==void 0?s.width:((I=t.geometry)==null?void 0:I.width)||180,r=s.height!==void 0?s.height:((k=t.geometry)==null?void 0:k.height)||100,c=e.orientation||"vertical",l=e.itemGap!==void 0?e.itemGap:16,h=e.fontSize||14,u=this.getWorldTransform(t.id),f=i-u.x,d=o-u.y,p=-u.rotation*(Math.PI/180),y=Math.cos(p),m=Math.sin(p),b=f*y-d*m,v=f*m+d*y,C=8*2,w=-a/2,M=-r/2;if(c==="vertical"){const T=Math.max(C,h)+l;for(let x=0;x<n.length;x++){const P=M+x*T;if(b>=w&&b<=w+a&&v>=P&&v<=P+T)return x}}else{let T=w;for(let x=0;x<n.length;x++){const E=n[x].length*8,L=C+6+E+l;if(b>=T&&b<=T+L&&v>=M&&v<=M+r)return x;T+=L}}return null}renderLineGraph(t,i,o,e){let s=i.datasets||[];if((!s||s.length===0)&&(i.data||i.graphData)&&(s=[{id:"line-1",label:"Series 1",data:i.data||i.graphData||[],lineColor:i.lineColor||"#3b82f6",lineWidth:i.lineWidth||2,showArea:i.showArea||!1,areaColor:i.areaColor||"rgba(139, 92, 246, 0.3)",smoothing:i.smoothing||!1,showPoints:i.showPoints!==void 0?i.showPoints:!0,pointSize:i.pointSize||6,pointFill:i.pointFill||"#ffffff",pointStrokeColor:i.pointStrokeColor||i.lineColor||"#3b82f6",pointStrokeWidth:i.pointStrokeWidth||2}]),!s||s.length===0||!s.some(p=>p.data&&p.data.length>=2)){t.save(),t.fillStyle="#6366f1",t.font="12px Inter, system-ui, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("NO DATA",0,0),t.restore();return}let n=1/0,a=-1/0,r=0;if(s.forEach(p=>{let y=p.data;if(p.isVarEnabled&&p.inputId){let m=this.inputs.get(p.inputId);if(m===void 0){const b=this.inputNameMap.get(p.inputId);b&&b.length>0&&(m=this.inputs.get(b[0]))}m&&Array.isArray(m)&&(y=m)}if(y&&y.length>0){const m=y.filter(b=>typeof b=="number"&&!isNaN(b));m.length>0&&(n=Math.min(n,...m),a=Math.max(a,...m),r=Math.max(r,y.length))}p._resolvedData=y}),r<2)return;const c=a-n,l=o/(r-1),h=p=>{const y=c===0?.5:(p-n)/c;return e/2-y*e},u=p=>p*l-o/2,f=i.axisColor||"#333333";if(i.showXAxis&&(t.beginPath(),t.strokeStyle=i.xAxisColor||f,t.lineWidth=1,t.moveTo(-o/2,e/2),t.lineTo(o/2,e/2),t.stroke()),i.showYAxis&&(t.beginPath(),t.strokeStyle=i.yAxisColor||f,t.lineWidth=1,t.moveTo(-o/2,-e/2),t.lineTo(-o/2,e/2),t.stroke()),t.fillStyle=i.axisLabelColor||"#333333",t.font=`${i.axisLabelFontSize||10}px Inter, sans-serif`,i.showXLabels){t.textAlign="center",t.textBaseline="top";for(let p=0;p<r;p++){const y=u(p);t.fillText(`${p+1}`,y,e/2+5)}}if(i.showYLabels){t.textAlign="right",t.textBaseline="middle";const p=-o/2-5,y=(a+n)/2;t.fillText(a.toFixed(1),p,h(a)),t.fillText(y.toFixed(1),p,h(y)),t.fillText(n.toFixed(1),p,h(n))}const d=10;if(s.forEach(p=>{const y=p._resolvedData;if(!(!y||y.length<2)){if(p.showArea){if(t.beginPath(),t.moveTo(u(0),e/2),t.lineTo(u(0),h(y[0])),p.smoothing&&y.length>2)for(let b=0;b<y.length-1;b++){const v=y[b===0?b:b-1],S=y[b],C=y[b+1],w=y[b+1===y.length-1?b+1:b+2];for(let M=1;M<=d;M++){const I=M/d,k=this._catmullRom(v,S,C,w,I);t.lineTo(u(b+I),h(k))}}else for(let b=1;b<y.length;b++)t.lineTo(u(b),h(y[b]));t.lineTo(u(y.length-1),e/2),t.closePath();const m=t.globalAlpha;t.globalAlpha=m*(i.areaOpacity??.3),t.fillStyle=p.areaColor||"rgba(139, 92, 246, 0.2)",t.fill(),t.globalAlpha=m}if(t.beginPath(),t.strokeStyle=p.lineColor||"#3b82f6",t.lineWidth=p.lineWidth||2,t.lineJoin="round",t.lineCap="round",t.moveTo(u(0),h(y[0])),p.smoothing&&y.length>2)for(let m=0;m<y.length-1;m++){const b=y[m===0?m:m-1],v=y[m],S=y[m+1],C=y[m+1===y.length-1?m+1:m+2];for(let w=1;w<=d;w++){const M=w/d,I=this._catmullRom(b,v,S,C,M);t.lineTo(u(m+M),h(I))}}else for(let m=1;m<y.length;m++)t.lineTo(u(m),h(y[m]));t.stroke(),p.showPoints&&y.forEach((m,b)=>{const v=u(b),S=h(m);t.beginPath(),t.arc(v,S,(p.pointSize||6)/2,0,Math.PI*2),t.fillStyle=p.pointFill||"#ffffff",t.fill(),t.strokeStyle=p.pointStrokeColor||p.lineColor||"#3b82f6",t.lineWidth=p.pointStrokeWidth||1,t.stroke()})}}),i.showLegend&&s.length>0){const p=o/2-10;let y=-e/2+15;const m=i.legendFontSize||10,b=m+5;t.font=`${m}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="alphabetic",s.forEach(v=>{const C=v.label||"Series",w=t.measureText(C).width;t.beginPath(),t.rect(p-w-8-5,y-(8/2+2),8,8),t.fillStyle=v.lineColor||"#3b82f6",t.fill(),t.fillStyle=i.legendColor||"#333333",t.fillText(C,p,y),y+=b})}}_catmullRom(t,i,o,e,s){const n=(o-t)*.5,a=(e-i)*.5,r=s*s,c=s*r;return(2*i-2*o+n+a)*c+(-3*i+3*o-2*n-a)*r+n*s+i}normalizeOpacity(t){const i=typeof t=="number"?t:parseFloat(String(t));return isNaN(i)?1:i>1?Math.min(1,i/100):Math.max(0,Math.min(1,i))}createCanvasFill(t,i,o,e){var s,n,a;if(!i||i.type==="None")return null;if(typeof i=="string")return i;if(i.type==="Solid"&&i.color){const r=i.color,l=(((n=(s=this.artboard)==null?void 0:s.tokens)==null?void 0:n.colors)||{})[r]||r;return t.fillStyle=l,l}if((i.type==="LinearGradient"||i.type==="RadialGradient"||i.type==="AngularGradient"||i.type==="DiamondGradient")&&i.stops){const r=(c,l=100)=>{var S,C;const u=(((C=(S=this.artboard)==null?void 0:S.tokens)==null?void 0:C.colors)||{})[c]||c,f=this.normalizeOpacity(i.opacity??100),p=this.normalizeOpacity(l)*f;if(p>=1&&u.startsWith("#"))return u;const y=u.startsWith("#")?u.replace("#",""):"ffffff",m=parseInt(y.substring(0,2),16),b=parseInt(y.substring(2,4),16),v=parseInt(y.substring(4,6),16);return`rgba(${m}, ${b}, ${v}, ${p})`};if(i.type==="LinearGradient"){const c=(p,y,m)=>Array.isArray(p)?p[y]??(y===0?0:1):p&&typeof p=="object"?p[m]??(y===0?0:1):y===0?0:1,l=c(i.start,0,"x")*o-o/2,h=c(i.start,1,"y")*e-e/2,u=c(i.end,0,"x")*o-o/2,f=c(i.end,1,"y")*e-e/2,d=t.createLinearGradient(l,h,u,f);if(i.stops.forEach(p=>{const y=p.offset!==void 0?p.offset:p.pos!==void 0?p.pos:p.position!==void 0?p.position:0,m=r(p.color||"#000000",p.opacity??100);d.addColorStop(Math.max(0,Math.min(1,y)),m)}),i.gradientTransform&&d.setTransform){const[p,y,m,b,v,S]=i.gradientTransform;d.setTransform({a:p,b:y,c:m,d:b,e:v,f:S})}return d}else if(i.type==="RadialGradient"){const c=(d,p,y)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[y]??.5:.5,l=c(i.center,0,"x")*o-o/2,h=c(i.center,1,"y")*e-e/2,u=(i.radius??.5)*Math.max(o,e),f=t.createRadialGradient(l,h,0,l,h,u);if(i.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,y=r(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),y)}),i.gradientTransform&&f.setTransform){const[d,p,y,m,b,v]=i.gradientTransform;f.setTransform({a:d,b:p,c:y,d:m,e:b,f:v})}return f}else if(i.type==="AngularGradient"){const c=(d,p,y)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[y]??.5:.5,l=c(i.center||[.5,.5],0,"x")*o-o/2,h=c(i.center||[.5,.5],1,"y")*e-e/2,u=(i.degree||i.angle||0)*(Math.PI/180),f=(a=t.createConicGradient)==null?void 0:a.call(t,u,l,h);if(f){if(i.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,y=r(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),y)}),i.gradientTransform&&f.setTransform){const[d,p,y,m,b,v]=i.gradientTransform;f.setTransform({a:d,b:p,c:y,d:m,e:b,f:v})}return f}}else if(i.type==="DiamondGradient"){const c=(d,p,y)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[y]??.5:.5,l=c(i.center||[.5,.5],0,"x")*o-o/2,h=c(i.center||[.5,.5],1,"y")*e-e/2,u=(i.radius??.5)*Math.max(o,e);t.save(),t.translate(l,h),t.rotate(Math.PI/4);const f=t.createRadialGradient(0,0,0,0,0,u);if(i.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,y=r(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),y)}),i.gradientTransform&&f.setTransform){const[d,p,y,m,b,v]=i.gradientTransform;f.setTransform({a:d,b:p,c:y,d:m,e:b,f:v})}return t.scale(1/Math.SQRT2,1/Math.SQRT2),t.fillStyle=f,t.restore(),f}}if(i.type==="Pattern"&&i.url){let r=this.imageCache.get(i.url);if(r||(r=new Image,r.src=i.url,this.imageCache.set(i.url,r)),r.complete&&r.naturalWidth>0){const c=t.createPattern(r,"repeat");if(c&&(i.scaleX!==void 0||i.offsetX!==void 0)){const l=new DOMMatrix,h=i.scaleX??1,u=i.scaleY??1,f=i.offsetX??0,d=i.offsetY??0,p=i.rotation??0;l.translateSelf(f,d),l.rotateSelf(p),l.scaleSelf(h,u),c.setTransform(l)}return c}}return i.color||null}drawRoundRect(t,i,o,e,s,n){if(n===0||n===void 0||n===null){t.rect(i,o,e,s);return}let a=n;if(typeof a=="string")try{a=JSON.parse(a)}catch{a=parseFloat(a)||0}let r=0,c=0,l=0,h=0;typeof a=="number"?r=c=l=h=a:Array.isArray(a)?a.length===1?r=c=l=h=a[0]:a.length===2?(r=l=a[0],c=h=a[1]):a.length===3?(r=a[0],c=h=a[1],l=a[2]):a.length>=4&&(r=a[0],c=a[1],l=a[2],h=a[3]):a&&typeof a=="object"&&(r=a.tl??a.corner_radius??a.cornerRadius??0,c=a.tr??a.corner_radius??a.cornerRadius??0,l=a.br??a.corner_radius??a.cornerRadius??0,h=a.bl??a.corner_radius??a.cornerRadius??0);const u=Math.min(Math.abs(e)/2,Math.abs(s)/2);if(r=Math.min(Math.max(0,r),u),c=Math.min(Math.max(0,c),u),l=Math.min(Math.max(0,l),u),h=Math.min(Math.max(0,h),u),t.roundRect){t.roundRect(i,o,e,s,[r,c,l,h]);return}t.moveTo(i+r,o),t.lineTo(i+e-c,o),t.arcTo(i+e,o,i+e,o+c,c),t.lineTo(i+e,o+s-l),t.arcTo(i+e,o+s,i+e-l,o+s,l),t.lineTo(i+h,o+s),t.arcTo(i,o+s,i,o+s-h,h),t.lineTo(i,o+r),t.arcTo(i,o,i+r,o,r),t.closePath()}renderListView(t,i){var O,W,B,$;const o=this.objectStates.get(i.id)||{},e=o.options||i.options||{},s=o.width!==void 0?o.width:((O=i.geometry)==null?void 0:O.width)||200,n=o.height!==void 0?o.height:((W=i.geometry)==null?void 0:W.height)||300,a=-s/2,r=-n/2,c=o.corner_radius!==void 0?o.corner_radius:e.corner_radius??0,l=e.orientation||"vertical",h=e.items||[],u=e.itemGap??10,f=e.itemHeight??50,d=e.itemWidth??200,p=e.scrollOffset??0,y=e.padding??0,m=e.glassEffect!==!1,b=e.accentColor||"#3b82f6",v=e.itemTextColor||"#333333",S=e.itemBackgroundColor||"#ffffff",C=e.hoveredIndex??null,w=e.activeItemIndex??null,M=e.glowIntensity??0,I=e.glowColor||"#3b82f6",k=typeof I=="string"?I:I.color||(($=(B=I.stops)==null?void 0:B[0])==null?void 0:$.color)||"#3b82f6",T=e.opacity!==void 0?e.opacity:i.opacity!==void 0?i.opacity:1;if(t.save(),t.globalAlpha*=T,M>0){const Y=t.getTransform(),H=Math.sqrt(Y.a*Y.a+Y.b*Y.b)||1;t.shadowColor=k,t.shadowBlur=M*2*H,t.shadowOffsetX=0,t.shadowOffsetY=0}if(m){const Y=e.listBackgroundColor||"rgba(31, 41, 55, 0.4)",H=this.createCanvasFill(t,Y,s,n);t.fillStyle=H||"rgba(31, 41, 55, 0.4)",t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,s,n,c)||t.fill();const A=t.createLinearGradient(a,r,a+s,r+n);A.addColorStop(0,"rgba(255, 255, 255, 0.15)"),A.addColorStop(.5,"rgba(255, 255, 255, 0.08)"),A.addColorStop(1,"rgba(255, 255, 255, 0.03)"),t.fillStyle=A,t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,s,n,c)||t.fill(),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1,t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,s,n,c)||t.stroke()}else{const Y=e.backgroundColor||e.listBackgroundColor||"transparent",H=this.createCanvasFill(t,Y,s,n);if(H){t.fillStyle=H,t.beginPath();const A=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,s,n,c);t.fill()}const K=e.borderWidth??0;if(K>0){t.strokeStyle=e.borderColor||"#cccccc",t.lineWidth=K,t.beginPath();const A=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,s,n,c);t.stroke()}}t.shadowBlur=0,t.save(),t.beginPath();const x=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,s,n,c);if(e.listLayout!=="circular")if(x&&e.containerShape==="custom")try{const Y=new Path2D(e.containerPath);t.translate(a,r),t.scale(s/100,n/100),t.clip(Y),t.scale(100/s,100/n),t.translate(-a,-r)}catch{}else t.clip();const P=typeof y=="number"?y:l==="vertical"?y[0]:y[3];let E=(l==="vertical"?r:a)+p+P;if(t.textBaseline="middle",h.forEach((Y,H)=>{const K=e.listLayout||"linear",A=K==="circular"?d:l==="vertical"?s:d,_=K==="circular"||l==="vertical"?f:n;let R=0,X=0,N=0;if(K==="circular"){const Tt=h.length||1,Nt=Math.PI*2/Tt,Z=e.circularStartAngle||0,pt=e.circularRadius||100,Et=p*.01+Z*Math.PI/180,ut=H*Nt+Et,St=a+s/2,Rt=r+n/2;R=St+Math.cos(ut)*pt-A/2,X=Rt+Math.sin(ut)*pt-_/2,N=ut+(e.itemRotation||0)*Math.PI/180}else R=l==="vertical"?a:E,X=l==="vertical"?E:r,N=(e.itemRotation||0)*Math.PI/180;const it=C===H,lt=w===H,nt=lt&&e.activeItemShape?e.activeItemShape:e.itemShape||"rectangle",bt=lt&&e.activeItemShape?e.activeItemPath:e.itemPath||"",ft=e.itemCornerRadius||0;if(t.save(),N!==0&&(t.translate(R+A/2,X+_/2),t.rotate(N),t.translate(-(R+A/2),-(X+_/2))),lt){const Tt=this.createCanvasFill(t,b,A,_);t.fillStyle=Tt||b;const Nt=t.globalAlpha;t.globalAlpha=Nt*.8,t.beginPath(),this.drawCustomShape(t,nt,bt,R,X,A,_,ft)||(t.rect(R,X,A,_),t.fill()),t.globalAlpha=Nt}else if(it)t.fillStyle=m?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",t.beginPath(),this.drawCustomShape(t,nt,bt,R,X,A,_,ft)||(t.rect(R,X,A,_),t.fill());else if(S!=="transparent"){const Tt=this.createCanvasFill(t,S,A,_);t.fillStyle=Tt||S,t.beginPath(),this.drawCustomShape(t,nt,bt,R,X,A,_,ft)||(t.rect(R,X,A,_),t.fill())}if(lt||it){const Tt=this.createCanvasFill(t,b,l==="vertical"?3:A,l==="vertical"?_:3);t.fillStyle=Tt||b,l==="vertical"?t.fillRect(R,X,3,_):t.fillRect(R,X+_-3,A,3)}const wt=lt?"#ffffff":m?"rgba(255, 255, 255, 0.9)":v;t.fillStyle=wt,t.font=lt||it?"600 14px Inter, sans-serif":"400 14px Inter, sans-serif";const It=typeof Y=="string"?Y:(Y==null?void 0:Y.label)||`Item ${H+1}`,Mt=R+(l==="vertical"?16:A/2),xt=X+_/2;l==="horizontal"||K==="circular"?t.textAlign="center":t.textAlign="left";const At=K==="circular"?R+A/2:Mt;t.fillText(It,At,xt),t.restore(),E+=(l==="vertical"?f:d)+u}),t.restore(),e.showScrollbar!==!1){const Y=(h.length||0)*(l==="vertical"?f:d)+((h.length||0)-1)*u,H=l==="vertical"?n:s,K=e.listLayout||"linear",A=e.containerShape==="circle"||K==="circular";if(Y>H||K==="circular"&&h.length>0){const _=e.scrollbarColor||"rgba(255,255,255,0.3)",R=e.scrollbarWidth||4;if(A){const X=Math.min(s,n)/2-R/2-2,N=a+s/2,it=r+n/2;if(t.strokeStyle=_,t.lineWidth=R,t.lineCap="round",t.beginPath(),K==="circular"){const lt=Math.PI/4,nt=-(p*.01)-Math.PI/2;t.arc(N,it,X,nt,nt+lt)}else{const lt=Math.PI/2,nt=H/Y,bt=lt*nt,ft=-p/Y*lt,It=-Math.PI/4+ft;t.arc(N,it,X,It,It+bt)}t.stroke()}else{const X=H/Y,N=H*X,it=-p/Y*H;t.fillStyle=_,l==="vertical"?t.fillRect(a+s-R-2,r+it,R,N):t.fillRect(a+it,r+n-R-2,N,R)}}}t.restore()}drawCustomShape(t,i,o,e,s,n,a,r){if(i==="circle"){const c=Math.min(n,a)/2;return t.arc(e+n/2,s+a/2,c,0,Math.PI*2),!1}else if(i==="pill"){const c=Math.min(n,a)/2;return this.drawListViewRect(t,e,s,n,a,c),!1}else if(i==="custom"&&o)try{const c=new Path2D(o);return t.save(),t.translate(e,s),t.scale(n/100,a/100),t.fill(c),t.restore(),!0}catch{return this.drawListViewRect(t,e,s,n,a,r),!1}return this.drawListViewRect(t,e,s,n,a,r),!1}updateListViewScrollFromPointer(t){var m,b;if(!this._lastPointerPos||!this._prevPointerPos)return;const i=t.options||{},o=i.orientation||"vertical",e=this._lastPointerPos.x-this._prevPointerPos.x,s=this._lastPointerPos.y-this._prevPointerPos.y;o==="vertical"?i.scrollOffset=(i.scrollOffset||0)+s:i.scrollOffset=(i.scrollOffset||0)+e;const n=i.listLayout||"linear",a=this.objectStates.get(t.id)||{},r=i.items||[],c=i.itemGap??10,l=i.itemHeight??50,h=i.itemWidth??200,u=a.width!==void 0?a.width:((m=t.geometry)==null?void 0:m.width)||200,f=a.height!==void 0?a.height:((b=t.geometry)==null?void 0:b.height)||300;if(n==="circular")return;const d=(r.length||0)*(o==="vertical"?l:h)+((r.length||0)-1)*c,y=Math.max(0,d-(o==="vertical"?f:u)+(i.padding*2||0));i.scrollOffset>0&&(i.scrollOffset=0),i.scrollOffset<-y&&(i.scrollOffset=-y)}updateListViewHoverFromPointer(t,i,o){const e=this.getListViewItemIndexAtPointer(t,i,o),s=t.options||{};s.hoveredIndex!==e&&(s.hoveredIndex=e)}getListViewItemIndexAtPointer(t,i,o){var B,$;const e=t.options||{},s=this.objectStates.get(t.id)||{},n=e.items||[];if(n.length===0)return null;const a=s.width!==void 0?s.width:((B=t.geometry)==null?void 0:B.width)||200,r=s.height!==void 0?s.height:(($=t.geometry)==null?void 0:$.height)||300,c=e.orientation||"vertical",l=e.itemGap??10,h=e.itemHeight??50,u=e.itemWidth??200,f=e.scrollOffset??0,d=e.padding??0,p=this.getWorldTransform(t.id),y=i-p.x,m=o-p.y,b=-p.rotation*(Math.PI/180),v=Math.cos(b),S=Math.sin(b),C=y*v-m*S,w=y*S+m*v,M=-a/2,I=-r/2,k=typeof d=="number"?d:c==="vertical"?d[0]:d[3];let T=(c==="vertical"?I:M)+f+k;const x=e.listLayout||"linear",P=n.length||1,E=Math.PI*2/P,L=e.circularStartAngle||0,O=e.circularRadius||100,W=f*.01+L*Math.PI/180;for(let Y=0;Y<n.length;Y++){const H=x==="circular"?u:c==="vertical"?a:u,K=x==="circular"||c==="vertical"?h:r;let A=0,_=0,R=0;if(x==="circular"){const X=Y*E+W,N=M+a/2,it=I+r/2;A=N+Math.cos(X)*O-H/2,_=it+Math.sin(X)*O-K/2,R=X+(e.itemRotation||0)*Math.PI/180}else A=c==="vertical"?M:T,_=c==="vertical"?T:I,R=(e.itemRotation||0)*Math.PI/180;if(R!==0){const X=A+H/2,N=_+K/2,it=C-X,lt=w-N,nt=-R,bt=it*Math.cos(nt)-lt*Math.sin(nt)+X,ft=it*Math.sin(nt)+lt*Math.cos(nt)+N;if(bt>=A&&bt<=A+H&&ft>=_&&ft<=_+K)return Y}else if(C>=A&&C<=A+H&&w>=_&&w<=_+K)return Y;T+=(c==="vertical"?h:u)+l}return null}drawListViewRect(t,i,o,e,s,n){t.beginPath(),this.drawRoundRect(t,i,o,e,s,n),t.fill()}solveBehaviors(t){if(!this.artboard)return;if(!this._lastPointerPos){this.frameCount%60;return}const{x:i,y:o}=this._lastPointerPos;this.artboard.objects.forEach(e=>{if(!e.behaviors||e.behaviors.length===0)return;const s=this.objectStates.get(e.id);s&&e.behaviors.forEach(n=>{var u,f,d,p,y,m,b,v,S,C,w,M,I,k,T,x,P,E,L,O,W,B,$,Y,H,K,A,_,R,X,N,it,lt,nt,bt,ft,wt,It,Mt,xt,At,Tt,Nt,Z,pt,Et,ut,St,Rt,Dt,Yt,Vt,Jt,ie,me,ye,te,ve,Te,Se,we,_e,ce,ne,at,gt,j,z,D,et,mt,Pt,Ct,Bt,yt,F,Ft,se,Ht,de,Lt,ht,ct,tt,dt,G,st,J,$t,Qt,oe,Gt,Kt,Ut,Me,Pe,Ee,Ae,Oe,xe,We,zt,ae,Ce,Le,Re,ue,fe,he,Ie,Be,Ne,He,Ye,Ue,qe,gs,ms;if(!n.enabled)return;const a=n.startTime||0,r=n.endTime||1/0;if(this.currentTime<a||this.currentTime>r)return;const c=s.x-i,l=s.y-o,h=Math.sqrt(c*c+l*l);if(this.frameCount%240===0&&Math.random()<.1&&this.log(`[ExodeUI] Executing ${n.type} on ${e.name}`),n.type===V.Proximity){const U=((u=n.settings)==null?void 0:u.radius)||300,Q=((f=n.settings)==null?void 0:f.falloff)||"smooth";let q=0;h<U&&(Q==="linear"?q=1-h/U:q=Math.pow(1-h/U,2)),n.sensors.forEach(rt=>{this.applyBehaviorSensor(s,rt,q,t,n.settings,e,c,l,h)})}else if(n.type===V.Magnetic){const U=((d=n.settings)==null?void 0:d.radius)||400,Q=((p=n.settings)==null?void 0:p.strength)||.5;if(h<U&&h>5){const q=1-h/U,rt=c*q*Q,kt=l*q*Q;s.x-=rt*t*10,s.y-=kt*t*10}}else if(n.type===V.Repel){const U=((y=n.settings)==null?void 0:y.radius)||300,Q=((m=n.settings)==null?void 0:m.strength)||1;if(h<U){const q=Math.pow(1-h/U,2);s.x+=c/(h||1)*q*60*Q*t*5,s.y+=l/(h||1)*q*60*Q*t*5}}else if(n.type===V.Orbit){const U=((b=n.settings)==null?void 0:b.speed)||1,Q=((v=n.settings)==null?void 0:v.radius)||30,q=this.currentTime*U*Math.PI*2;s.x+=Math.cos(q)*Q*t*5,s.y+=Math.sin(q)*Q*t*5,s.rotation+=2*t*5}else if(n.type===V.Vortex){const U=((S=n.settings)==null?void 0:S.radius)||400,Q=((C=n.settings)==null?void 0:C.speed)||2,q=((w=n.settings)==null?void 0:w.strength)||1;if(h<U){const rt=Math.pow(1-h/U,1.5),kt=this.currentTime*Q*Math.PI*2,_t=Math.cos(kt)*30-c*.4,Wt=Math.sin(kt)*30-l*.4;s.x+=_t*rt*q*t*5,s.y+=Wt*rt*q*t*5,s.rotation+=5*rt*q*t*5,s.scale_x*=1-rt*.1*q*t,s.scale_y*=1-rt*.1*q*t}}else if(n.type===V.Fluid){const U=((M=n.settings)==null?void 0:M.radius)||300,Q=((I=n.settings)==null?void 0:I.strength)||1;if(h<U){const q=Math.pow(1-h/U,1.2),rt=c/(h||1)*q*1.2*Q,kt=l/(h||1)*q*1.2*Q;s.x+=rt*10*t*5,s.y+=kt*10*t*5,s.scale_x*=1+q*.3*Q*t,s.scale_y*=1+q*.3*Q*t}}else if(n.type===V.Elastic){const U=((k=n.settings)==null?void 0:k.radius)||300,Q=((T=n.settings)==null?void 0:T.strength)||1;if(h<U){const q=1-h/U;s.scale_x*=1+q*.4*Q*t,s.scale_y*=1+q*.4*Q*t}}else if(n.type===V.Holographic){const U=s.x-this.canvasWidth/2,Q=s.y-this.canvasHeight/2,q=((x=n.settings)==null?void 0:x.factor)||25;if(s.x-=U/1e3*q*t*5,s.y-=Q/1e3*q*t*5,s.style){const rt=1-Math.min(1,h/400);s.style.exposure=(s.style.exposure||1)+rt*.5*t}}else if(n.type===V.Sticky){const U=((P=n.settings)==null?void 0:P.radius)||80,Q=((E=n.settings)==null?void 0:E.strength)||1;if(h<U){const q=Math.pow(1-h/U,2);s.x-=c*q*Q*t*10,s.y-=l*q*Q*t*10,s.scale_x*=1-q*.1*Q*t,s.scale_y*=1-q*.1*Q*t}}else if(n.type===V.Dilation){const U=((L=n.settings)==null?void 0:L.size)||120,Q=((O=n.settings)==null?void 0:O.strength)||1;if(h<U){const q=1-h/U;s.scale_x*=1+q*.5*Q*t,s.scale_y*=1+q*.5*Q*t}}else if(n.type===V.Parallax){const U=((W=n.settings)==null?void 0:W.factor)||15,Q=((B=n.settings)==null?void 0:B.strength)||1,q=this.canvasWidth/2,rt=this.canvasHeight/2,kt=this._lastPointerPos||{x:q,y:rt},_t=(kt.x-q)/q,Wt=(kt.y-rt)/rt,ee=((($=e.transform)==null?void 0:$.x)??0)+_t*U*Q,pe=(((Y=e.transform)==null?void 0:Y.y)??0)+Wt*U*Q,ke=(((H=e.transform)==null?void 0:H.rotate_x)??0)-Wt*U*1.5*Q,re=(((K=e.transform)==null?void 0:K.rotate_y)??0)+_t*U*1.5*Q,be=Math.min(1,10*t);s.x=this.lerp(s.x??((A=e.transform)==null?void 0:A.x)??0,ee,be),s.y=this.lerp(s.y??((_=e.transform)==null?void 0:_.y)??0,pe,be),s.rotate_x=this.lerp(s.rotate_x??((R=e.transform)==null?void 0:R.rotate_x)??0,ke,be),s.rotate_y=this.lerp(s.rotate_y??((X=e.transform)==null?void 0:X.rotate_y)??0,re,be)}else if(n.type===V.Fold){if(h<300){const U=1-h/300,Q=(c>0?-1:1)*U*10,q=1-U*.1,rt=l/300*U*20,kt=-(c/300)*U*20,_t=Math.min(1,10*t);s.skew_x=this.lerp(s.skew_x??((N=e.transform)==null?void 0:N.skew_x)??0,Q,_t),s.scale_y=this.lerp(s.scale_y??((it=e.transform)==null?void 0:it.scale_y)??1,(((lt=e.transform)==null?void 0:lt.scale_y)??1)*q,_t),s.rotate_x=this.lerp(s.rotate_x??((nt=e.transform)==null?void 0:nt.rotate_x)??0,rt,_t),s.rotate_y=this.lerp(s.rotate_y??((bt=e.transform)==null?void 0:bt.rotate_y)??0,kt,_t),s.style=s.style||{...e.style},s.style.artEffect={enabled:!0,type:"fold_overlay",intensity:((ft=n.settings)==null?void 0:ft.opacity)??.5}}}else if(n.type===V.Crumple){if(h<300){const U=1-h/300,Q=U*(Math.random()-.5)*5,q=U*(Math.random()-.5)*.05,rt=Math.min(1,15*t);s.skew_x=this.lerp(s.skew_x??((wt=e.transform)==null?void 0:wt.skew_x)??0,Q,rt),s.scale_x=this.lerp(s.scale_x??((It=e.transform)==null?void 0:It.scale_x)??1,(((Mt=e.transform)==null?void 0:Mt.scale_x)??1)*(1+q),rt),s.scale_y=this.lerp(s.scale_y??((xt=e.transform)==null?void 0:xt.scale_y)??1,(((At=e.transform)==null?void 0:At.scale_y)??1)*(1+q),rt),s.style=s.style||{...e.style},s.style.artEffect={enabled:!0,type:"crumple_overlay",intensity:((Tt=n.settings)==null?void 0:Tt.intensity)??1,scale:((Nt=n.settings)==null?void 0:Nt.scale)??2}}}else if(n.type===V.Squash){const U=((Z=n.settings)==null?void 0:Z.strength)||.8;h<(e.width||100)&&this.isMouseDown?(s.scale_y=this.lerp(s.scale_y??1,(((pt=e.transform)==null?void 0:pt.scale_y)??1)*U,.3),s.scale_x=this.lerp(s.scale_x??1,(((Et=e.transform)==null?void 0:Et.scale_x)??1)*(1+(1-U)*.4),.3)):(s.scale_y=this.lerp(s.scale_y??1,((ut=e.transform)==null?void 0:ut.scale_y)??1,.2),s.scale_x=this.lerp(s.scale_x??1,((St=e.transform)==null?void 0:St.scale_x)??1,.2))}else if(n.type===V.TextCounter){const U=((Rt=n.settings)==null?void 0:Rt.duration)||2,Q=((Dt=n.settings)==null?void 0:Dt.from)||0,q=((Yt=n.settings)==null?void 0:Yt.to)||100;n._runtimeStart===void 0&&(n._runtimeStart=this.currentTime);const rt=this.currentTime-n._runtimeStart,kt=Math.min(1,rt/U),_t=Math.floor(Q+(q-Q)*kt);if(((Vt=e.geometry)==null?void 0:Vt.type)==="Text"){const Wt=((Jt=n.settings)==null?void 0:Jt.prefix)||"",ee=((ie=n.settings)==null?void 0:ie.suffix)||"";s.geometry||(s.geometry={...e.geometry}),s.geometry.text=`${Wt}${_t}${ee}`}}else if(n.type===V.Spotlight){const U=((me=n.settings)==null?void 0:me.radius)||250,Q=((ye=n.settings)==null?void 0:ye.strength)||1.5;if(h<U){const q=Math.pow(1-h/U,2);s.style||(s.style={...e.style}),s.style.adjustments||(s.style.adjustments={...(te=e.style)==null?void 0:te.adjustments}),s.style.adjustments.exposure=(((Te=(ve=e.style)==null?void 0:ve.adjustments)==null?void 0:Te.exposure)||0)+q*Q*50}else(Se=s.style)!=null&&Se.adjustments&&(s.style.adjustments.exposure=this.lerp(s.style.adjustments.exposure||0,((_e=(we=e.style)==null?void 0:we.adjustments)==null?void 0:_e.exposure)||0,.1))}else if(n.type===V.Noise||n.type===V.Float){const U=(((ce=n.settings)==null?void 0:ce.frequency)||((ne=n.settings)==null?void 0:ne.speed)||1)*.002,Q=(((at=n.settings)==null?void 0:at.amplitude)||((gt=n.settings)==null?void 0:gt.range)||50)*(((j=n.settings)==null?void 0:j.strength)||1),q=Date.now();s.x+=Math.sin(q*U)*Q*t,s.y+=Math.cos(q*U*.8)*Q*t,s.rotation+=Math.sin(q*U*.5)*5*t}else if(n.type===V.Pulse){const U=(((z=n.settings)==null?void 0:z.speed)||1)*.005,Q=(((D=n.settings)==null?void 0:D.scale)||1.2)-1,q=Math.sin(Date.now()*U),rt=((et=n.settings)==null?void 0:et.strength)||1;s.scale_x*=1+q*Q*rt*t,s.scale_y*=1+q*Q*rt*t,s.style&&(s.style.exposure=(s.style.exposure||1)+Math.max(0,q)*.1*rt*t)}else if(n.type===V.Draggable){const U=((mt=n.settings)==null?void 0:mt.radius)||150,Q=this.draggingBehaviors.has(e.id);if(h<U||Q){const q=((Pt=n.settings)==null?void 0:Pt.strength)||1,rt=Q?1:Math.max(0,1-h/U);this.applyBehaviorSensor(s,jt.PositionX,rt*q,t,n.settings),this.applyBehaviorSensor(s,jt.PositionY,rt*q,t,n.settings)}}else if(n.type===V.Scroll){const U=((Ct=n.settings)==null?void 0:Ct.axis)||"vertical",Q=((Bt=n.settings)==null?void 0:Bt.factor)||.5,q=((yt=n.settings)==null?void 0:yt.strength)||1,rt=((F=n.settings)==null?void 0:F.scaleFactor)||0;(U==="vertical"||U==="both")&&(s.y+=this.scrollOffset.y*Q*q*t),(U==="horizontal"||U==="both")&&(s.x+=this.scrollOffset.x*Q*q*t),rt!==0&&(s.scale_x*=1+this.scrollOffset.y*rt*t,s.scale_y*=1+this.scrollOffset.y*rt*t)}else if(n.type===V.LookAt){const U=((Ft=n.settings)==null?void 0:Ft.factor)||1,Q=((se=n.settings)==null?void 0:se.strength)||1,q=Math.atan2(-l,-c)*(180/Math.PI),rt=s.rotation,kt=(q-rt+180)%360-180;s.rotation+=kt*U*Q*t*10}else if(n.type===V.Scan){const U=(((Ht=n.settings)==null?void 0:Ht.speed)||1)*.004,Q=((de=n.settings)==null?void 0:de.strength)||1,q=(Math.sin(Date.now()*U)+1)/2;s.style&&(s.style.exposure=(s.style.exposure||1)+q*Q*t*5),s.x+=(q-.5)*20*Q*t}else if(n.type===V.Glint)s.style=s.style||{...e.style},s.style.artEffect={enabled:!0,type:"glint_overlay",intensity:((Lt=n.settings)==null?void 0:Lt.strength)??.8};else if(n.type===V.Ratchet){const U=((ht=n.settings)==null?void 0:ht.steps)||12,Q=(((ct=n.settings)==null?void 0:ct.speed)||1)*30,q=Math.floor(s.rotation/(360/U))*(360/U);s.rotation=this.lerp(s.rotation,q+Q*t,.1)}else if(n.type===V.Jitter&&h<300){const U=((tt=n.settings)==null?void 0:tt.strength)||1,Q=(((dt=n.settings)==null?void 0:dt.intensity)||5)*U;s.x+=(Math.random()-.5)*Q*t*60,s.y+=(Math.random()-.5)*Q*t*60,s.rotation+=(Math.random()-.5)*Q*t*120}else if(n.type===V.Follower){const U=(G=n.settings)==null?void 0:G.targetId;if(U){const Q=this.objectStates.get(U);if(Q){const q=((st=n.settings)==null?void 0:st.stiffness)||.1,rt=Q.x-s.x,kt=Q.y-s.y;s.x+=rt*q*t*60,s.y+=kt*q*t*60}}}else if(n.type===V.Wrap)s.x<0?s.x=this.canvasWidth:s.x>this.canvasWidth&&(s.x=0),s.y<0?s.y=this.canvasHeight:s.y>this.canvasHeight&&(s.y=0);else if(n.type===V.Gravity){const U=((J=n.settings)==null?void 0:J.strength)||9.8;s.y+=U*t*10}else if(n.type===V.Velocity){const U=(($t=n.settings)==null?void 0:$t.vx)||0,Q=((Qt=n.settings)==null?void 0:Qt.vy)||0;s.x+=U*t*10,s.y+=Q*t*10}else if(n.type===V.Shear){const U=((oe=n.settings)==null?void 0:oe.strength)||1,Q=((Gt=n.settings)==null?void 0:Gt.radius)||300;if(h<Q){const q=1-h/Q;s.skew_x=this.lerp(s.skew_x||0,(((Kt=e.transform)==null?void 0:Kt.skew_x)||0)+q*U*30,.1)}else s.skew_x=this.lerp(s.skew_x||0,((Ut=e.transform)==null?void 0:Ut.skew_x)||0,.05)}else if(n.type===V.Lens){const U=((Me=n.settings)==null?void 0:Me.radius)||200,Q=((Pe=n.settings)==null?void 0:Pe.strength)||.5;if(h<U){const q=Math.pow(1-h/U,2);s.scale_x=this.lerp(s.scale_x??1,(((Ee=e.transform)==null?void 0:Ee.scale_x)??1)*(1+q*Q),.2),s.scale_y=this.lerp(s.scale_y??1,(((Ae=e.transform)==null?void 0:Ae.scale_y)??1)*(1+q*Q),.2)}else s.scale_x=this.lerp(s.scale_x??1,((Oe=e.transform)==null?void 0:Oe.scale_x)??1,.1),s.scale_y=this.lerp(s.scale_y??1,((xe=e.transform)==null?void 0:xe.scale_y)??1,.1)}else if(n.type===V.LayoutAnimation){const U=((We=n.settings)==null?void 0:We.watchProperties)||["x","y","scale_x","scale_y","opacity","rotation"],Q=((zt=n.settings)==null?void 0:zt.duration)||.3;this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const q=this._layoutAnimCache.get(e.id);for(const rt of U){const kt=this.getObjectProperty(s,e,rt);if(kt===void 0)continue;const _t=q.get(rt);if(!_t)q.set(rt,{from:kt,to:kt,startTime:this.currentTime,duration:0});else if(_t.to!==kt){const ee=this.getObjectProperty(s,e,rt);q.set(rt,{from:ee??_t.from,to:kt,startTime:this.currentTime,duration:((ae=n.settings)==null?void 0:ae.duration)??Q})}const Wt=q.get(rt);if(Wt.duration>0&&Wt.from!==Wt.to){const ee=this.currentTime-Wt.startTime,pe=Math.min(1,ee/Wt.duration),ke=this.applyEasing(pe,((Ce=n.settings)==null?void 0:Ce.easing)||"easeOutCubic"),re=Wt.from+(Wt.to-Wt.from)*ke;this.setObjectProperty(s,e,rt,re)}}}else if(n.type===V.StateReactive){this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const U=this._layoutAnimCache.get(e.id),Q=((Le=n.settings)==null?void 0:Le.defaultDuration)||.3,q=["x","y","scale_x","scale_y","opacity","rotation","style.fill.color","style.stroke.width","geometry.cornerRadius","style.blur.value","style.shadow.blur","style.shadow.offsetX","style.shadow.offsetY"];for(const rt of q){const kt=this.getObjectProperty(s,e,rt);if(kt===void 0||typeof kt!="number")continue;const _t=U.get(rt);if(!_t)U.set(rt,{from:kt,to:kt,startTime:this.currentTime,duration:0});else if(_t.to!==kt){const ee=this.getObjectProperty(s,e,rt);U.set(rt,{from:ee??_t.from,to:kt,startTime:this.currentTime,duration:Q})}const Wt=U.get(rt);if(Wt.duration>0&&Wt.from!==Wt.to){const ee=this.currentTime-Wt.startTime,pe=Math.min(1,ee/Wt.duration),ke=this.applyEasing(pe,((Re=n.settings)==null?void 0:Re.defaultEasing)||"easeOutCubic"),re=Wt.from+(Wt.to-Wt.from)*ke;this.setObjectProperty(s,e,rt,re)}}}else if(n.type===V.SpringChain){const U=((ue=n.settings)==null?void 0:ue.connections)||[],Q=((fe=n.settings)==null?void 0:fe.globalDamping)||.3;this._springChainState.has(e.id)||this._springChainState.set(e.id,new Map);const q=this._springChainState.get(e.id);for(const kt of U){if(!q.has(kt.targetId)){const _t=this.objectStates.get(kt.targetId);q.set(kt.targetId,{x:(_t==null?void 0:_t.x)??0,y:(_t==null?void 0:_t.y)??0,vx:0,vy:0})}q.has(e.id)||q.set(e.id,{x:s.x,y:s.y,vx:0,vy:0})}const rt=q.get(e.id);if(rt){rt.x=s.x,rt.y=s.y;for(const kt of U){const _t=q.get(kt.targetId);if(!_t)continue;const Wt=_t.x-rt.x,ee=_t.y-rt.y,pe=Math.sqrt(Wt*Wt+ee*ee)||.001,re=(pe-(kt.restLength||50))*(kt.stiffness||.8),be=Wt/pe*re,Je=ee/pe*re;rt.vx+=be*t*10,rt.vy+=Je*t*10,_t.vx-=be*t*10,_t.vy-=Je*t*10,rt.vx*=1-Q*t*10,rt.vy*=1-Q*t*10,_t.vx*=1-Q*t*10,_t.vy*=1-Q*t*10;const ge=this.objectStates.get(kt.targetId);ge&&(ge.x+=_t.vx*t,ge.y+=_t.vy*t)}s.x+=rt.vx*t,s.y+=rt.vy*t}}else if(n.type===V.ParticleEmitter){const U=((he=n.settings)==null?void 0:he.rate)||10,Q=((Ie=n.settings)==null?void 0:Ie.speed)||100,q=((Be=n.settings)==null?void 0:Be.size)||5,rt=((Ne=n.settings)==null?void 0:Ne.lifetime)||2,kt=((He=n.settings)==null?void 0:He.gravity)||0,_t=((Ye=n.settings)==null?void 0:Ye.color)||"#ffffff",Wt=((Ue=n.settings)==null?void 0:Ue.maxParticles)||200,ee=(qe=n.settings)!=null&&qe.rateInputId?this.inputs.get(n.settings.rateInputId)??U:U,pe=(gs=n.settings)!=null&&gs.gravityInputId?this.inputs.get(n.settings.gravityInputId)??kt:kt,ke=(ms=n.settings)!=null&&ms.speedInputId?this.inputs.get(n.settings.speedInputId)??Q:Q;this._emitterPools.has(e.id)||this._emitterPools.set(e.id,[]);const re=this._emitterPools.get(e.id);let be=0;n._pendingBurst&&n._pendingBurst>0&&(be=n._pendingBurst,n._pendingBurst=0);const Je=Math.floor(ee*t)+(be||0);for(let ge=0;ge<Math.min(Je,Wt-re.length);ge++){const le=Math.random()*Math.PI*2,ys=ke*(.5+Math.random()*.5);re.push({x:s.x,y:s.y,vx:Math.cos(le)*ys,vy:Math.sin(le)*ys,life:0,maxLife:rt*(.5+Math.random()*.5),size:q*(.5+Math.random()),color:_t,opacity:1})}for(let ge=re.length-1;ge>=0;ge--){const le=re[ge];le.vy+=pe*t*10,le.x+=le.vx*t,le.y+=le.vy*t,le.life+=t,le.opacity=Math.max(0,1-le.life/le.maxLife),le.life>=le.maxLife&&re.splice(ge,1)}}})})}applyBehaviorSensor(t,i,o,e,s,n,a=0,r=0,c=1){var d,p,y,m,b,v,S,C,w,M,I,k,T,x,P,E,L,O,W,B,$,Y,H,K;const l=(s==null?void 0:s.intensity)||(s==null?void 0:s.strength)||1,h=Math.min(1,15*e),u=c>0?a/c:0,f=c>0?r/c:0;switch(i){case jt.Scale:{const A=((d=n==null?void 0:n.transform)==null?void 0:d.scale_x)??1,_=((p=n==null?void 0:n.transform)==null?void 0:p.scale_y)??1,R=A*(1+o*l*.4),X=_*(1+o*l*.4);t.scale_x=(t.scale_x??A)*(1-h)+R*h,t.scale_y=(t.scale_y??_)*(1-h)+X*h;break}case jt.Opacity:{const A=((y=n==null?void 0:n.transform)==null?void 0:y.opacity)??100,_=Math.max(0,Math.min(100,A-o*l*100));t.opacity=(t.opacity??A)*(1-h)+_*h;break}case jt.RotateZ:{const A=((m=n==null?void 0:n.transform)==null?void 0:m.rotation)??0,_=A+o*l*45;t.rotation=(t.rotation??A)*(1-h)+_*h;break}case jt.RotateX:{const A=((b=n==null?void 0:n.transform)==null?void 0:b.rotate_x)??0,_=A-f*o*l*60;t.rotate_x=(t.rotate_x??A)*(1-h)+_*h;break}case jt.RotateY:{const A=((v=n==null?void 0:n.transform)==null?void 0:v.rotate_y)??0,_=A+u*o*l*60;t.rotate_y=(t.rotate_y??A)*(1-h)+_*h;break}case jt.PositionX:{const A=((S=n==null?void 0:n.transform)==null?void 0:S.x)??0,_=A-u*o*l*40;t.x=(t.x??A)*(1-h)+_*h;break}case jt.PositionY:{const A=((C=n==null?void 0:n.transform)==null?void 0:C.y)??0,_=A-f*o*l*40;t.y=(t.y??A)*(1-h)+_*h;break}case jt.SkewX:{const A=((w=n==null?void 0:n.transform)==null?void 0:w.skew_x)??0,_=A+u*o*l*45;t.skew_x=(t.skew_x??A)*(1-h)+_*h,t.skew_x>85&&(t.skew_x=85),t.skew_x<-85&&(t.skew_x=-85);break}case jt.Blur:{t.style||(t.style={...n==null?void 0:n.style}),t.style.blur||(t.style.blur={...(M=n==null?void 0:n.style)==null?void 0:M.blur});const A=((k=(I=n==null?void 0:n.style)==null?void 0:I.blur)==null?void 0:k.amount)||0,_=A+o*((s==null?void 0:s.blur)||20)*l;t.style.blur.amount=(t.style.blur.amount??A)*(1-h)+_*h;break}case jt.Exposure:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(T=n==null?void 0:n.style)==null?void 0:T.adjustments});const A=((P=(x=n==null?void 0:n.style)==null?void 0:x.adjustments)==null?void 0:P.exposure)||0,_=A+o*((s==null?void 0:s.exposure)||50)*l;t.style.adjustments.exposure=(t.style.adjustments.exposure??A)*(1-h)+_*h;break}case jt.HueShift:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(E=n==null?void 0:n.style)==null?void 0:E.adjustments});const A=((O=(L=n==null?void 0:n.style)==null?void 0:L.adjustments)==null?void 0:O.hue)||0,_=A+o*((s==null?void 0:s.hue)||180)*l;t.style.adjustments.hue=(t.style.adjustments.hue??A)*(1-h)+_*h;break}case jt.Negative:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(W=n==null?void 0:n.style)==null?void 0:W.adjustments});const A=(($=(B=n==null?void 0:n.style)==null?void 0:B.adjustments)==null?void 0:$.negative)||0,_=A+o*((s==null?void 0:s.negative)||100)*l;t.style.adjustments.negative=(t.style.adjustments.negative??A)*(1-h)+_*h;break}case jt.CornerRadius:{const A=((Y=n==null?void 0:n.transform)==null?void 0:Y.corner_radius)||0,_=A+o*l*50;t.corner_radius=(t.corner_radius??A)*(1-h)+_*h;break}case jt.StrokeWidth:{t.style||(t.style={...n==null?void 0:n.style});const A=((H=n==null?void 0:n.style)==null?void 0:H.borderWidth)||0,_=A+o*l*10;t.style.borderWidth=(t.style.borderWidth??A)*(1-h)+_*h;break}case jt.LetterSpacing:{t.geometry||(t.geometry={});const A=((K=n==null?void 0:n.geometry)==null?void 0:K.letterSpacing)||0,_=A+o*l*10;t.geometry.letterSpacing=(t.geometry.letterSpacing??A)*(1-h)+_*h;break}}}getObjectProperty(t,i,o){const e=o.split(".");let s=t;for(const n of e){if(s==null||typeof s!="object")return;if(n==="style"&&t.style===void 0){s=i.style;continue}s=s[n]}return typeof s=="number"?s:void 0}setObjectProperty(t,i,o,e){const s=o.split(".");let n=t;for(let r=0;r<s.length-1;r++){const c=s[r];if(n[c]===void 0||n[c]===null){const l=i,h=s.slice(0,r+1).reduce((u,f)=>u==null?void 0:u[f],l);n[c]=h!==void 0?{...h}:{}}n=n[c]}const a=s[s.length-1];n!=null&&(n[a]=e)}applyEasing(t,i){switch(i){case"easeOutCubic":return 1-Math.pow(1-t,3);case"easeInCubic":return t*t*t;case"easeInOutCubic":return t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2;case"easeOutQuad":return t*(2-t);case"easeInQuad":return t*t;case"easeInOutQuad":return t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2;case"easeOutExpo":return t===1?1:1-Math.pow(2,-10*t);case"easeOutBack":return 1+2.70158*Math.pow(t-1,3)+1.70158*Math.pow(t-1,2);case"easeOutElastic":{const o=2*Math.PI/3;return t===0?0:t===1?1:Math.pow(2,-10*t)*Math.sin((t*10-.75)*o)+1}case"easeOutBounce":return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375;case"linear":return t;default:return 1-Math.pow(1-t,3)}}lerp(t,i,o){return t*(1-o)+i*o}deepMerge(t,i){if(!t)return i;if(!i)return t;if(typeof t!="object"||typeof i!="object"||t===null||i===null)return i;const o={...t};for(const e in i)Object.prototype.hasOwnProperty.call(i,e)&&(i[e]&&typeof i[e]=="object"&&!Array.isArray(i[e])?o[e]=this.deepMerge(t[e],i[e]):o[e]=i[e]);return o}renderFittedImage(t,i,o,e,s,n,a="cover"){const r=i.naturalWidth,c=i.naturalHeight,l=r/c,h=s/n;let u=s,f=n,d=o,p=e;a==="cover"?l>h?(u=n*l,d=o-(u-s)/2):(f=s/l,p=e-(f-n)/2):a==="contain"&&(l>h?(f=s/l,p=e+(n-f)/2):(u=n*l,d=o+(s-u)/2)),t.drawImage(i,d,p,u,f)}}const ni=Ot.forwardRef(({artboard:g,src:t,style:i,autoPlay:o=!0,fit:e="Contain",alignment:s="Center",onReady:n,onTrigger:a,onInputUpdate:r,onComponentChange:c,onToggle:l,onInputChange:h,onInputFocus:u,onInputBlur:f,onLog:d,onLogicUpdate:p,onButtonClick:y,onGraphPointClick:m,currentTime:b,revision:v=0,scrollY:S,scrollX:C,mouseX:w,mouseY:M,isMouseDown:I,inputs:k,interactive:T=!0,onNavigation:x},P)=>{const E=Ot.useRef(null),L=Ot.useRef(null);L.current||(L.current=new ps);const O=Ot.useRef(void 0),W=Ot.useRef(0),B=Ot.useRef(null),$=Ot.useRef(v),Y=Ot.useRef(null),[,H]=Ot.useState(g||null),K=Ot.useRef(!0);Ot.useImperativeHandle(P,()=>E.current),Ot.useEffect(()=>(K.current=!0,()=>{K.current=!1,O.current&&cancelAnimationFrame(O.current)}),[]),Ot.useEffect(()=>{L.current.setLayout(e,s)},[e,s]),Ot.useEffect(()=>{const _=L.current;a&&_.setTriggerCallback(a),r&&_.setInputUpdateCallback((R,X)=>r({[R]:X})),c&&_.setComponentChangeCallback(R=>c(R)),l&&_.setToggleCallback(l),h&&_.setInputChangeCallback(h),u&&_.setInputFocusCallback(u),f&&_.setInputBlurCallback(f),d&&_.setOnLogCallback(R=>d(R,"info")),p&&_.setLogicUpdateCallback(p),y&&_.setButtonClickCallback(y),m&&_.setGraphPointClickCallback(R=>m(R.objectId,R)),x&&_.setNavigationCallback(x)},[a,r,c,l,h,u,f,d,p,y,m,x]),Ot.useEffect(()=>{(async()=>{let R=g;if(t&&!g)try{t.startsWith("{")?R=JSON.parse(t):R=await(await fetch(t)).json()}catch(X){console.error("[ExodeUI] Failed to load src:",X)}if(R){const X=L.current,N=R.id||R.name||"default";(B.current!==N||$.current!==v||Y.current!==R)&&(X.load(R),B.current=N,$.current=v,Y.current=R,H(R),W.current=0,X.advance(0)),n&&n(X)}})()},[g,t,v]),Ot.useEffect(()=>{const _=R=>{if(!L.current||!K.current)return;const X=L.current,N=E.current;if(!N)return;const it=N.getContext("2d");if(!it)return;const lt=R/1e3;W.current===0&&(W.current=lt);let nt=lt-W.current;nt>.1&&(nt=.1),W.current=lt;const bt=N.getBoundingClientRect(),ft=window.devicePixelRatio||1,wt=Math.round(bt.width*ft),It=Math.round(bt.height*ft);(N.width!==wt||N.height!==It)&&(N.width=wt,N.height=It);try{o?X.advance(nt):b!==void 0&&X.seek(b),X.render(it,N.width,N.height)}catch(Mt){console.error("[ExodeUICanvas] Error in animation loop:",Mt),d&&d(`[Error] Animation loop crashed: ${Mt}`,"error")}O.current=requestAnimationFrame(_)};return O.current=requestAnimationFrame(_),()=>{O.current&&cancelAnimationFrame(O.current)}},[o,b]),Ot.useEffect(()=>{const _=L.current;S!==void 0&&_.updateInput("scrollY",S),C!==void 0&&_.updateInput("scrollX",C),w!==void 0&&_.updateInput("mouseX",w),M!==void 0&&_.updateInput("mouseY",M),I!==void 0&&_.updateInput("isMouseDown",I),k&&Object.entries(k).forEach(([R,X])=>_.updateInput(R,X))},[S,C,w,M,I,k]);const A=(_,R)=>{if(!T||!E.current)return;_.stopPropagation(),"nativeEvent"in _&&_.nativeEvent&&typeof _.nativeEvent.stopImmediatePropagation=="function"?_.nativeEvent.stopImmediatePropagation():typeof _.stopImmediatePropagation=="function"&&_.stopImmediatePropagation();const X=E.current,N=X.getBoundingClientRect(),it=_.clientX-N.left,lt=_.clientY-N.top,nt=window.devicePixelRatio||1;(R==="click"||R==="down"||R==="up")&&d&&d(`[Canvas] Pointer ${R} at rect(${Math.round(it)},${Math.round(lt)}) mapped to buffer(${Math.round(it*nt)},${Math.round(lt*nt)})`,"info"),L.current.handlePointerInput(R,it*nt,lt*nt,X.width,X.height)};return qt.jsx("canvas",{ref:E,onPointerDown:_=>{var R;A(_,"down"),(R=E.current)==null||R.focus()},onPointerMove:_=>A(_,"move"),onPointerUp:_=>A(_,"up"),onPointerCancel:_=>A(_,"up"),onClick:_=>A(_,"click"),onWheel:_=>{L.current.handleWheel(_.deltaX,_.deltaY)},onKeyDown:_=>L.current.handleKeyDown(_.nativeEvent),onContextMenu:_=>_.preventDefault(),tabIndex:0,style:{...i,width:"100%",height:"100%",outline:"none",display:"block",touchAction:"none",pointerEvents:T?"auto":"none"}})});function oi(){const[g,t]=Ot.useState(null),i=Ot.useCallback((h,u)=>{g==null||g.setInputBool(h,u)},[g]),o=Ot.useCallback((h,u)=>{g==null||g.setInputNumber(h,u)},[g]),e=Ot.useCallback(h=>{g==null||g.fireTrigger(h)},[g]),s=Ot.useCallback((h,u)=>{g==null||g.setInputText(h,u)},[g]),n=Ot.useCallback((h,u)=>{g==null||g.setInputNumberArray(h,u)},[g]),a=Ot.useCallback((h,u)=>{g==null||g.setInputStringArray(h,u)},[g]),r=Ot.useCallback((h,u)=>{g==null||g.updateObjectOptions(h,u)},[g]),c=Ot.useCallback((h,u,f)=>{g==null||g.updateConstraint(h,u,f)},[g]),l=Ot.useCallback((h,u)=>{g==null||g.updateGraphData(h,u)},[g]);return{setEngine:t,engine:g,setInputBool:i,setInputNumber:o,fireTrigger:e,setInputText:s,setInputNumberArray:n,setInputStringArray:a,updateConstraint:c,updateGraphData:l,updateObjectOptions:r}}const ai=({artboard:g,config:t})=>{const i={...g.seo,...t},o=i.enableSmartExtraction!==!1;Ot.useEffect(()=>{const a=i.title||g.name;a&&(document.title=a);let r=i.description;if(!r&&o){const h=g.objects.filter(u=>{var f;return((f=u.geometry)==null?void 0:f.type)==="Text"}).sort((u,f)=>{var d,p;return(((d=f.geometry.text)==null?void 0:d.length)||0)-(((p=u.geometry.text)==null?void 0:p.length)||0)});h.length>0&&(r=h[0].geometry.text)}r&&(e("name","description",r),e("property","og:description",r)),i.keywords&&i.keywords.length>0&&e("name","keywords",i.keywords.join(", "));const c=i.ogImage||g.backgroundImage;c&&e("property","og:image",c),a&&e("property","og:title",a),e("property","og:type","website")},[i,g,o]);const e=(a,r,c)=>{let l=document.querySelector(`meta[${a}="${r}"]`);l||(l=document.createElement("meta"),l.setAttribute(a,r),document.head.appendChild(l)),l.setAttribute("content",c)},s=()=>{const a=[];return a.push(qt.jsx("h1",{children:i.title||g.name},"artboard-title")),g.objects.forEach((c,l)=>{var h,u;if(!(c.visible===!1||c.isVisible===!1))if(((h=c.geometry)==null?void 0:h.type)==="Text"){const f=c.geometry.text;f&&(c.geometry.fontSize>24?a.push(qt.jsx("h2",{children:f},c.id||l)):a.push(qt.jsx("p",{children:f},c.id||l)))}else if(((u=c.geometry)==null?void 0:u.type)==="Image"){const f=c.geometry.src,d=c.altText||c.name||"Illustration";a.push(qt.jsx("img",{src:f,alt:d},c.id||l))}else c.type==="Button"&&a.push(qt.jsx("button",{children:c.name||"Button"},c.id||l))}),a},n=i.jsonLd||{"@context":"https://schema.org","@type":"VisualArtwork",name:i.title||g.name,description:i.description,image:i.ogImage||g.backgroundImage,abstract:"Animated interface created with ExodeUI"};return qt.jsxs("div",{id:`exode-seo-${g.id||"default"}`,"aria-hidden":"false",style:{position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:"0",zIndex:-1},children:[s(),qt.jsx("script",{type:"application/ld+json",children:JSON.stringify(n)})]})},ri={version:"6.3.31"}.version;Xt.BehaviorSensor=jt,Xt.BehaviorType=V,Xt.ConditionOp=Ke,Xt.ExodeSEO=ai,Xt.ExodeUICanvas=ni,Xt.ExodeUIEngine=ps,Xt.LogicOp=vt,Xt.RapierPhysics=es,Xt.VERSION=ri,Xt.useExodeUI=oi,Object.defineProperty(Xt,Symbol.toStringTag,{value:"Module"})}));
|
|
6
|
+
`&&k++)}let M=(C==null?void 0:C.lines)||[];return g.composer==="every-line"&&M.length>1&&(M=Ms(M)),g.balanceRaggedLines===!0&&M.length>1&&(M=Is(M)),{width:a,height:w,lineCount:M.length,lines:M}}function je(g,t,i){let o=String(g||"").trim();if(o&&!isNaN(Number(o))&&!o.includes(" ")&&!o.endsWith("fr")&&!o.endsWith("px")&&!o.endsWith("%")){const l=Math.max(1,parseInt(o));o=new Array(l).fill("1fr").join(" ")}const e=o.split(/\s+/).filter(Boolean),s=new Array(e.length).fill(0);let n=t-(e.length-1)*i,a=0;if(e.forEach((l,c)=>{if(l.endsWith("px")){const h=parseFloat(l);s[c]=h,n-=h}else l.endsWith("fr")?a+=parseFloat(l):l==="auto"&&(s[c]=100,n-=100)}),a>0&&n>0){const l=n/a;e.forEach((c,h)=>{c.endsWith("fr")&&(s[h]=l*parseFloat(c))})}return s}function ts(g,t,i){try{const o=g.autoLayout;return!o||!o.enabled?{childUpdates:[]}:(o.mode||"linear")==="grid"?Ts(g,t,i):ks(g,t,i)}catch(o){return console.error("Layout Engine Error:",o),{childUpdates:[]}}}function ks(g,t,i){var _,A;const o=g.autoLayout,{direction:e,spacing:s,padding:n,align:a,wrap:l}=o,c=e==="vertical",h=t.map(x=>{const W=i(x.id),Y=x.geometry;let B=(W==null?void 0:W.width)??Y.width??100,X=(W==null?void 0:W.height)??Y.height??100;if(Y.type==="Ellipse"||Y.type==="Polygon"||Y.type==="Star"){const q=(W==null?void 0:W.radius)??Y.radius??(W==null?void 0:W.outer_radius)??Y.outer_radius??50;B=q*2,X=q*2}else if(Y.type==="Text"){const q=Ze({text:(W==null?void 0:W.text)??Y.text??"",fontFamily:Y.fontFamily,fontSize:Y.fontSize,fontWeight:Y.fontWeight,fontStyle:Y.fontStyle,lineHeight:Y.lineHeight,width:Y.width||200,letterSpacing:Y.letterSpacing,paragraphSpacing:Y.paragraphSpacing,paragraphIndent:Y.paragraphIndent,textCase:Y.textCase,segments:Y.segments,enableSegments:Y.enableSegments});X=q.height,Y.width||(B=q.width)}return B*=x.transform.scale_x||1,X*=x.transform.scale_y||1,{id:x.id,w:B,h:X,original:x}});let r=g.width,u=g.height;const f=((_=g.layoutProps)==null?void 0:_.width)==="hug",d=((A=g.layoutProps)==null?void 0:A.height)==="hug",p=[];let m=[],y=0,b=0;const v=r-n.left-n.right,S=u-n.top-n.bottom;h.forEach(x=>{l&&m.length>0&&(c?b+s+x.h>S:y+s+x.w>v)?(p.push({children:m,width:y,height:b}),m=[x],y=x.w,b=x.h):(m.push(x),c?(y=Math.max(y,x.w),b+=(m.length>1?s:0)+x.h):(y+=(m.length>1?s:0)+x.w,b=Math.max(b,x.h)))}),m.length>0&&p.push({children:m,width:y,height:b}),f&&!c&&(r=Math.max(...p.map(x=>x.width),0)+n.left+n.right),d&&c&&(u=Math.max(...p.map(x=>x.height),0)+n.top+n.bottom);const C=[];let w=n.left,M=n.top;const I=a.toLowerCase(),k=I==="center"||I.endsWith("-center"),T=I.endsWith("-right"),O=I==="center"||I.startsWith("center-"),P=I.startsWith("bottom-");return p.forEach(x=>{let W=w,Y=M;c?O?Y=n.top+(u-n.top-n.bottom-x.height)/2:P&&(Y=u-n.bottom-x.height):k?W=n.left+(r-n.left-n.right-x.width)/2:T&&(W=r-n.right-x.width),x.children.forEach(B=>{var L,G;let X=W,q=Y;c?k?X+=(x.width-B.w)/2:T&&(X+=x.width-B.w):O?q+=(x.height-B.h)/2:P&&(q+=x.height-B.h);const j=((L=B.original.layoutProps)==null?void 0:L.width)==="fill",E=((G=B.original.layoutProps)==null?void 0:G.height)==="fill";C.push({id:B.id,x:X+B.w/2-r/2,y:q+B.h/2-u/2,width:j&&c?x.width:void 0,height:E?c?void 0:x.height:void 0}),c?Y+=B.h+s:W+=B.w+s}),c?w+=x.width+s:M+=x.height+s}),{frameWidth:f?r:void 0,frameHeight:d?u:void 0,childUpdates:C}}function Ts(g,t,i){const o=g.autoLayout;if(!o)return{childUpdates:[]};const{gridColumns:e,gridRows:s,columnGap:n=0,rowGap:a=0,padding:l,align:c}=o;let h=g.width,r=g.height;const u=h-l.left-l.right,f=r-l.top-l.bottom,d=je(e||"1fr",u,n),p=je(s||"auto",f,a),m=d.length>0?d.reduce((T,O)=>T+O,0)+(d.length-1)*n:0,y=p.length>0?p.reduce((T,O)=>T+O,0)+(p.length-1)*a:0,b=c.toLowerCase(),v=b==="center"||b.endsWith("-center"),S=b.endsWith("-right"),C=b==="center"||b.startsWith("center-"),w=b.startsWith("bottom-");let M=0,I=0;v?M=(u-m)/2:S&&(M=u-m),C?I=(f-y)/2:w&&(I=f-y);const k=[];return t.forEach((T,O)=>{var G,z;const P=O%d.length||0,_=Math.floor(O/d.length)||0;_>=p.length&&p.push(100);const A=d[P],x=p[_];let W=l.left+M+d.slice(0,P).reduce((it,F)=>it+F+n,0),Y=l.top+I+p.slice(0,_).reduce((it,F)=>it+F+a,0);const B=i(T.id),X=T.geometry;let q=(B==null?void 0:B.width)??X.width??100,j=(B==null?void 0:B.height)??X.height??100;if(X.type==="Ellipse"||X.type==="Polygon"||X.type==="Star"){const it=(B==null?void 0:B.radius)??X.radius??(B==null?void 0:B.outer_radius)??X.outer_radius??50;q=it*2,j=it*2}q*=T.transform.scale_x||1,j*=T.transform.scale_y||1;let E=W,L=Y;v?E+=(A-q)/2:S&&(E+=A-q),C?L+=(x-j)/2:w&&(L+=x-j),k.push({id:T.id,x:E+q/2-h/2,y:L+j/2-r/2,width:((G=T.layoutProps)==null?void 0:G.width)==="fill"?A:void 0,height:((z=T.layoutProps)==null?void 0:z.height)==="fill"?x:void 0})}),{childUpdates:k}}class es{constructor(){lt(this,"world",null);lt(this,"bodies",new Map);lt(this,"colliders",new Map);lt(this,"joints",new Map);lt(this,"initialized",!1);lt(this,"bodyIdByCollider",new Map);lt(this,"onCollisionCB",null);lt(this,"eventQueue",null)}setCollisionCallback(t){this.onCollisionCB=t}async init(t){this.initialized||(await Zt.init(),this.world=new Zt.World(new Zt.Vector2(t.x*100,t.y*100)),this.eventQueue=new Zt.EventQueue(!0),this.initialized=!0)}destroy(){this.bodies.clear(),this.colliders.clear(),this.joints.clear(),this.world&&(this.world.free(),this.world=null),this.initialized=!1}setGravity(t){this.world&&(this.world.gravity=new Zt.Vector2(t.x*100,t.y*100))}createBody(t){if(!this.world){console.warn("[RapierPhysics] World not initialized");return}this.bodies.has(t.id)&&this.removeBody(t.id);const i=t.isStatic?Zt.RigidBodyDesc.fixed():Zt.RigidBodyDesc.dynamic();i.setTranslation(t.x,t.y),t.rotation!==void 0&&i.setRotation(t.rotation);const o=this.world.createRigidBody(i);let e;switch(t.type){case"Rectangle":e=Zt.ColliderDesc.cuboid(t.width/2,t.height/2);break;case"Ellipse":e=Zt.ColliderDesc.ball(Math.max(t.width,t.height)/2);break;case"Triangle":case"Star":case"Polygon":e=Zt.ColliderDesc.cuboid(t.width/2,t.height/2);break;default:e=Zt.ColliderDesc.cuboid(t.width/2,t.height/2)}if(t.friction!==void 0&&e.setFriction(t.friction),t.restitution!==void 0&&e.setRestitution(t.restitution),t.density!==void 0)e.setDensity(t.density);else if(t.mass!==void 0&&!t.isStatic){const n=t.width*t.height;e.setDensity(t.mass/n)}t.isSensor&&e.setSensor(!0);const s=this.world.createCollider(e,o);this.bodyIdByCollider.set(s.handle,t.id),t.frictionAir!==void 0&&o.setLinearDamping(t.frictionAir*10),this.bodies.set(t.id,o),this.colliders.set(t.id,s)}removeBody(t){const i=this.bodies.get(t),o=this.colliders.get(t);o&&this.bodyIdByCollider.delete(o.handle),i&&this.world&&(this.world.removeRigidBody(i),this.bodies.delete(t),this.colliders.delete(t))}step(t){if(!this.world)return;this.world.step(this.eventQueue);const i=this.onCollisionCB,o=this.eventQueue;i&&o&&o.drainContactEvents((e,s,n)=>{const a=this.bodyIdByCollider.get(e),l=this.bodyIdByCollider.get(s);a&&l&&i(a,l,n)})}getPosition(t){const i=this.bodies.get(t);if(!i)return null;const o=i.translation();return{x:o.x,y:o.y}}getRotation(t){const i=this.bodies.get(t);return i?i.rotation():null}getVelocity(t){const i=this.bodies.get(t);if(!i)return null;const o=i.linvel();return{x:o.x,y:o.y}}setPosition(t,i,o){const e=this.bodies.get(t);e&&e.setTranslation(new Zt.Vector2(i,o),!0)}setRotation(t,i){const o=this.bodies.get(t);o&&o.setRotation(i,!0)}setVelocity(t,i,o){const e=this.bodies.get(t);e&&e.setLinvel(new Zt.Vector2(i,o),!0)}setAngularVelocity(t,i){const o=this.bodies.get(t);o&&o.setAngvel(i,!0)}applyForce(t,i,o){const e=this.bodies.get(t);e&&e.addForce(new Zt.Vector2(i,o),!0)}applyImpulse(t,i,o){const e=this.bodies.get(t);e&&e.applyImpulse(new Zt.Vector2(i,o),!0)}createJoint(t){if(!this.world){console.warn("[RapierPhysics] World not initialized");return}this.joints.has(t.id)&&this.removeJoint(t.id);const i=this.bodies.get(t.bodyA),o=this.bodies.get(t.bodyB);if(!i||!o){console.warn(`[RapierPhysics] Cannot create joint ${t.id}: bodyA (${t.bodyA}) or bodyB (${t.bodyB}) not found`);return}const e=new Zt.Vector2(t.anchorA.x,t.anchorA.y),s=new Zt.Vector2(t.anchorB.x,t.anchorB.y);let n;if(t.type==="Distance"){const a=t.length??100,l=t.stiffness??100,c=t.damping??10;n=Zt.JointData.spring(a,l,c,e,s)}else n=Zt.JointData.revolute(e,s);try{const a=this.world.createImpulseJoint(n,i,o,!0);this.joints.set(t.id,a)}catch(a){console.error(`[RapierPhysics] Failed to create joint ${t.id}:`,a)}}removeJoint(t){const i=this.joints.get(t);if(i&&this.world){try{this.world.removeImpulseJoint(i,!0)}catch(o){console.error(`[RapierPhysics] Failed to remove joint ${t}:`,o)}this.joints.delete(t)}}}const ss=g=>g,_s=g=>g>0?1:0,Ps=g=>g<1?0:1,is=g=>g*g,ns=g=>g*(2-g),os=g=>g<.5?2*g*g:-1+(4-2*g)*g,Es=g=>g*g*g,As=g=>--g*g*g+1,xs=g=>g<.5?4*g*g*g:(g-1)*(2*g-2)*(2*g-2)+1,Os=g=>g*g*g*g,Ls=g=>1- --g*g*g*g,Fs=g=>g<.5?8*g*g*g*g:1-8*--g*g*g*g,Rs=g=>g*g*g*g*g,$s=g=>1+--g*g*g*g*g,Bs=g=>g<.5?16*g*g*g*g*g:1+16*--g*g*g*g*g,Ws=g=>1-Math.cos(g*Math.PI/2),Ys=g=>Math.sin(g*Math.PI/2),Xs=g=>-(Math.cos(Math.PI*g)-1)/2,Ds=g=>g===0?0:Math.pow(2,10*(g-1)),Gs=g=>g===1?1:1-Math.pow(2,-10*g),zs=g=>g===0?0:g===1?1:g<.5?Math.pow(2,20*g-10)/2:(2-Math.pow(2,-20*g+10))/2,Vs=g=>1-Math.sqrt(1-g*g),Ns=g=>Math.sqrt(1- --g*g),Hs=g=>g<.5?(1-Math.sqrt(1-4*g*g))/2:(Math.sqrt(1-(-2*g+2)*(-2*g+2))+1)/2,De=1.70158,Ge=De*1.525,as=De+1,Us=g=>as*g*g*g-De*g*g,qs=g=>1+as*Math.pow(g-1,3)+De*Math.pow(g-1,2),Ks=g=>g<.5?Math.pow(2*g,2)*((Ge+1)*2*g-Ge)/2:(Math.pow(2*g-2,2)*((Ge+1)*(g*2-2)+Ge)+2)/2,rs=2*Math.PI/3,ls=2*Math.PI/4.5,Js=g=>g===0?0:g===1?1:-Math.pow(2,10*g-10)*Math.sin((g*10-10.75)*rs),Qs=g=>g===0?0:g===1?1:Math.pow(2,-10*g)*Math.sin((g*10-.75)*rs)+1,Zs=g=>g===0?0:g===1?1:g<.5?-(Math.pow(2,20*g-10)*Math.sin((20*g-11.125)*ls))/2:Math.pow(2,-20*g+10)*Math.sin((20*g-11.125)*ls)/2+1,ze=g=>g<1/2.75?7.5625*g*g:g<2/2.75?7.5625*(g-=1.5/2.75)*g+.75:g<2.5/2.75?7.5625*(g-=2.25/2.75)*g+.9375:7.5625*(g-=2.625/2.75)*g+.984375,js=g=>1-ze(1-g),ti=ze,ei=g=>g<.5?(1-ze(1-2*g))/2:(1+ze(2*g-1))/2,Je=new Map,$e=(g,t,i,o)=>{const e=`${g},${t},${i},${o}`;if(Je.has(e))return Je.get(e);const s=h=>(1-3*i+3*g)*h*h*h+(3*i-6*g)*h*h+3*g*h,n=h=>(1-3*o+3*t)*h*h*h+(3*o-6*t)*h*h+3*t*h,a=h=>3*(1-3*i+3*g)*h*h+2*(3*i-6*g)*h+3*g,l=h=>{let r=h;for(let u=0;u<8;u++){const f=s(r)-h;if(Math.abs(f)<1e-6)return r;const d=a(r);if(Math.abs(d)<1e-6)break;r=r-f/d}return r},c=h=>h===0?0:h===1?1:n(l(h));return Je.set(e,c),c},cs=g=>{const t=g.match(/cubic-bezier\s*\(\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*\)/);if(!t)return null;const[,i,o,e,s]=t.map(Number);return $e(i,o,e,s)},fs={ease:$e(.25,.1,.25,1),"ease-in":$e(.42,0,1,1),"ease-out":$e(0,0,.58,1),"ease-in-out":$e(.42,0,.58,1)},Ve={Linear:ss,EaseInQuad:is,EaseOutQuad:ns,EaseInOutQuad:os,EaseInCubic:Es,EaseOutCubic:As,EaseInOutCubic:xs,EaseInQuart:Os,EaseOutQuart:Ls,EaseInOutQuart:Fs,EaseInQuint:Rs,EaseOutQuint:$s,EaseInOutQuint:Bs,EaseInSine:Ws,EaseOutSine:Ys,EaseInOutSine:Xs,EaseInExpo:Ds,EaseOutExpo:Gs,EaseInOutExpo:zs,EaseInCirc:Vs,EaseOutCirc:Ns,EaseInOutCirc:Hs,EaseInBack:Us,EaseOutBack:qs,EaseInOutBack:Ks,EaseInElastic:Js,EaseOutElastic:Qs,EaseInOutElastic:Zs,EaseInBounce:js,EaseOutBounce:ti,EaseInOutBounce:ei,EaseIn:is,EaseOut:ns,EaseInOut:os,StepStart:_s,StepEnd:Ps},si=g=>{const t=g.trim(),i=t.toLowerCase();if(Ve[t])return Ve[t];const o=Object.keys(Ve).find(s=>s.toLowerCase()===i);if(o)return Ve[o];const e=Object.keys(hs).find(s=>s.toLowerCase()===i);if(e){const s=cs(hs[e].value);if(s)return s}if(fs[i])return fs[i];if(i.startsWith("cubic-bezier")){const s=cs(t);if(s)return s}return ss},hs={Snappy:{label:"Snappy",description:"High energy, quick arrival.",value:"cubic-bezier(0.2, 1, 0.2, 1)"},Bouncy:{label:"Bouncy",description:"Springy with an overshoot.",value:"cubic-bezier(0.2, 0.9, 0.4, 1.3)"},Gentle:{label:"Gentle",description:"Smooth and organic flow.",value:"cubic-bezier(0.4, 0, 0.6, 1)"},Stiff:{label:"Stiff",description:"Solid and reliable movement.",value:"cubic-bezier(0.3, 1, 0.7, 1)"},Floating:{label:"Floating",description:"Weightless and airy transition.",value:"cubic-bezier(0.5, 0, 0.5, 1)"},Sudden:{label:"Sudden",description:"Instant, direct movement.",value:"cubic-bezier(1, 0, 1, 1)"},Elastic:{label:"Elastic",description:"Extreme overshoot and spring.",value:"cubic-bezier(0.5, 1.5, 0.5, 1.5)"},Sharp:{label:"Sharp",description:"Fast start, very hard stop.",value:"cubic-bezier(0.1, 0.9, 0.1, 1)"},Fluid:{label:"Fluid",description:"Natural high-end flow.",value:"cubic-bezier(0.4, 0, 0.2, 1)"},Heavy:{label:"Heavy",description:"Slow start, massive impact.",value:"cubic-bezier(0.6, 0, 1, 1)"}},ii=(g,t,i,o,e)=>{if(!g||!t||!i)return g;const s=o.scale_x??1,n=o.scale_y??1,a=(l,c,h)=>{let r=0,u=0;const f=o.rotation*Math.PI/180,d=Math.cos(f),p=Math.sin(f),m=l*s*d-c*n*p+o.x,y=l*s*p+c*n*d+o.y;h.forEach(I=>{const k=e(I.boneId);if(!k)return;const T={x:k.x,y:k.y,rotation:k.rotation,scaleX:k.scale_x??1,scaleY:k.scale_y??1},O=i[I.boneId]||[1,0,0,1,0,0],P=m*O[0]+y*O[2]+O[4],_=m*O[1]+y*O[3]+O[5],A=T.rotation*Math.PI/180,x=Math.cos(A),W=Math.sin(A),Y=P*T.scaleX*x-_*T.scaleY*W+T.x,B=P*T.scaleX*W+_*T.scaleY*x+T.y;r+=Y*I.amount,u+=B*I.amount});const b=[...h].sort((I,k)=>k.amount-I.amount);if(b.length>=2&&b[0].amount>0&&b[1].amount>0){const I=e(b[0].boneId),k=e(b[1].boneId);if(I&&k&&I.length!==void 0&&k.length!==void 0){const T=I.length*(I.scale_y??1),O=I.rotation*Math.PI/180,P=I.x-T*Math.sin(O),_=I.y+T*Math.cos(O),A=k.length*(k.scale_y??1),x=k.rotation*Math.PI/180,W=k.x-A*Math.sin(x),Y=k.y+A*Math.cos(x);let B=null,X=null,q=!1;const j=1;if(Math.hypot(I.x-k.x,I.y-k.y)<j||Math.hypot(I.x-W,I.y-Y)<j?(B=I.x,X=I.y):(Math.hypot(P-k.x,_-k.y)<j||Math.hypot(P-W,_-Y)<j)&&(B=P,X=_,q=!0),B!==null&&X!==null){const E=i[b[0].boneId]||[1,0,0,1,0,0],L=E[0]*E[3]-E[1]*E[2];let G=0,z=0;if(L!==0){const it=(E[2]*E[5]-E[3]*E[4])/L,F=(E[1]*E[4]-E[0]*E[5])/L,$=Math.atan2(-E[1],E[3]);if(!q)G=it,z=F;else{const rt=-E[2]/L,mt=E[0]/L,Ct=Math.hypot(rt,mt),ct=I.length*Ct;G=it-ct*Math.sin($),z=F+ct*Math.cos($)}const V=Math.hypot(m-G,y-z),tt=Math.hypot(r-B,u-X);if(tt>0&&V>0){const rt=Math.max(tt,.01),mt=Math.min(V/rt,3),Ct=B+(r-B)*mt,ct=X+(u-X)*mt,Pt=b[0].amount,kt=b[1].amount,Tt=Math.min(Pt,kt)*2,zt=1-Math.pow(1-Tt,4);r=r*(1-zt)+Ct*zt,u=u*(1-zt)+ct*zt}}}}}const v=o.rotation*Math.PI/180,S=Math.cos(v),C=Math.sin(v),w=r-o.x,M=u-o.y;return{x:(w*S+M*C)/s,y:(-w*C+M*S)/n}};return g.map((l,c)=>{const h=t[c];if(!h||h.length===0)return{...l};const r={...l,...a(l.x,l.y,h)};if(l.in_x!==void 0&&l.in_y!==void 0){const u=a(l.in_x,l.in_y,h);r.in_x=u.x,r.in_y=u.y}if(l.out_x!==void 0&&l.out_y!==void 0){const u=a(l.out_x,l.out_y,h);r.out_x=u.x,r.out_y=u.y}return r})},ds={default:{label:"Default",colors:["#6366f1","#f59e0b"],cardBackground:"rgba(255,255,255,0.04)",cardBorderColor:"rgba(255,255,255,0.08)",gridColor:"rgba(255,255,255,0.06)",axisLabelColor:"rgba(255,255,255,0.5)",legendColor:"rgba(255,255,255,0.7)",barGradient:!0},neon:{label:"Neon",colors:["#00f5ff","#ff00e5"],cardBackground:"rgba(0,0,0,0.5)",cardBorderColor:"rgba(0,245,255,0.2)",gridColor:"rgba(0,245,255,0.08)",axisLabelColor:"rgba(0,245,255,0.6)",legendColor:"rgba(0,245,255,0.8)",barGradient:!0},pastel:{label:"Pastel",colors:["#a5b4fc","#fcd34d"],cardBackground:"rgba(255,255,255,0.06)",cardBorderColor:"rgba(255,255,255,0.12)",gridColor:"rgba(255,255,255,0.08)",axisLabelColor:"rgba(255,255,255,0.45)",legendColor:"rgba(255,255,255,0.65)",barGradient:!1},warm:{label:"Warm",colors:["#f97316","#ef4444"],cardBackground:"rgba(30,10,0,0.4)",cardBorderColor:"rgba(249,115,22,0.2)",gridColor:"rgba(249,115,22,0.08)",axisLabelColor:"rgba(253,186,116,0.7)",legendColor:"rgba(253,186,116,0.85)",barGradient:!0},ocean:{label:"Ocean",colors:["#06b6d4","#0ea5e9"],cardBackground:"rgba(0,20,40,0.5)",cardBorderColor:"rgba(6,182,212,0.2)",gridColor:"rgba(6,182,212,0.06)",axisLabelColor:"rgba(125,211,252,0.6)",legendColor:"rgba(125,211,252,0.8)",barGradient:!0},mono:{label:"Mono",colors:["rgba(255,255,255,0.9)","rgba(255,255,255,0.4)"],cardBackground:"rgba(255,255,255,0.03)",cardBorderColor:"rgba(255,255,255,0.1)",gridColor:"rgba(255,255,255,0.05)",axisLabelColor:"rgba(255,255,255,0.4)",legendColor:"rgba(255,255,255,0.6)",barGradient:!1}},us={default:{label:"Default",colors:["#6366f1","#22d3ee","#f59e0b","#ec4899","#34d399"],cardBackground:"rgba(255,255,255,0.04)",cardBorderColor:"rgba(255,255,255,0.08)",legendColor:"rgba(255,255,255,0.65)",labelColor:"#ffffff",centerTextColor:"#ffffff",centerLabelColor:"rgba(255,255,255,0.4)"},neon:{label:"Neon",colors:["#00f5ff","#ff00e5","#00ff9f","#ff6b00","#b400ff"],cardBackground:"rgba(0,0,0,0.55)",cardBorderColor:"rgba(0,245,255,0.2)",legendColor:"rgba(0,245,255,0.75)",labelColor:"#ffffff",centerTextColor:"#00f5ff",centerLabelColor:"rgba(0,245,255,0.5)"},pastel:{label:"Pastel",colors:["#a5b4fc","#67e8f9","#fcd34d","#f9a8d4","#6ee7b7"],cardBackground:"rgba(255,255,255,0.06)",cardBorderColor:"rgba(255,255,255,0.12)",legendColor:"rgba(255,255,255,0.6)",labelColor:"#1a1a2e",centerTextColor:"#ffffff",centerLabelColor:"rgba(255,255,255,0.45)"},warm:{label:"Warm",colors:["#f97316","#ef4444","#f59e0b","#dc2626","#fb923c"],cardBackground:"rgba(30,10,0,0.45)",cardBorderColor:"rgba(249,115,22,0.2)",legendColor:"rgba(253,186,116,0.8)",labelColor:"#ffffff",centerTextColor:"#fb923c",centerLabelColor:"rgba(253,186,116,0.5)"},ocean:{label:"Ocean",colors:["#06b6d4","#0ea5e9","#38bdf8","#7dd3fc","#0284c7"],cardBackground:"rgba(0,20,40,0.5)",cardBorderColor:"rgba(6,182,212,0.2)",legendColor:"rgba(125,211,252,0.75)",labelColor:"#ffffff",centerTextColor:"#38bdf8",centerLabelColor:"rgba(125,211,252,0.5)"},mono:{label:"Mono",colors:["rgba(255,255,255,0.9)","rgba(255,255,255,0.65)","rgba(255,255,255,0.45)","rgba(255,255,255,0.28)","rgba(255,255,255,0.15)"],cardBackground:"rgba(255,255,255,0.03)",cardBorderColor:"rgba(255,255,255,0.1)",legendColor:"rgba(255,255,255,0.55)",labelColor:"#000000",centerTextColor:"#ffffff",centerLabelColor:"rgba(255,255,255,0.4)"}};class ps{constructor(){lt(this,"artboard",null);lt(this,"objectStates",new Map);lt(this,"physicsEngine",null);lt(this,"activeStateMachine",null);lt(this,"inputs",new Map);lt(this,"inputNameMap",new Map);lt(this,"layerStates",new Map);lt(this,"pretextCache",new Map);lt(this,"pointerHistory",[]);lt(this,"MAX_HISTORY",200);lt(this,"imageCache",new Map);lt(this,"lastValidSvgImgMap",new Map);lt(this,"maskBuffer",null);lt(this,"maskCtx",null);lt(this,"lumaBuffer",null);lt(this,"lumaCtx",null);lt(this,"_noiseTileCanvas",null);lt(this,"layout",{fit:"Contain",alignment:"Center"});lt(this,"onTrigger");lt(this,"onInputUpdate");lt(this,"onComponentChange");lt(this,"onToggle");lt(this,"onInputChange");lt(this,"onInputFocus");lt(this,"onInputBlur");lt(this,"onLog");lt(this,"onButtonClick");lt(this,"onGraphPointClick");lt(this,"justFiredTriggers",new Set);lt(this,"rootTransform",null);lt(this,"canvasWidth",0);lt(this,"canvasHeight",0);lt(this,"lastHoveredObjectId",null);lt(this,"_lastPointerPos",null);lt(this,"_prevPointerPos",null);lt(this,"_mouseDelta",{dx:0,dy:0});lt(this,"focusedId",null);lt(this,"draggingSliderId",null);lt(this,"draggingJoystickId",null);lt(this,"activeDropdownId",null);lt(this,"activeObjectId",null);lt(this,"draggingListViewId",null);lt(this,"scrollOffset",{x:0,y:0});lt(this,"_totalScroll",{x:0,y:0});lt(this,"draggingBehaviors",new Set);lt(this,"isMouseDown",!1);lt(this,"activeKeys",new Set);lt(this,"_layoutAnimCache",new Map);lt(this,"_springChainState",new Map);lt(this,"_emitterPools",new Map);lt(this,"objectVelocities",new Map);lt(this,"currentTime",0);lt(this,"frameCount",0);lt(this,"fontLeadingFactors",{Inter:.35,Roboto:.45,Montserrat:.4,Outfit:.35,"Open Sans":.4,Poppins:.45,"Playfair Display":.35,Lora:.4,Lato:.35,"Bebas Neue":.45,Oswald:.4});lt(this,"onLogicUpdate");lt(this,"logicNodeValues",new Map);lt(this,"logicNodeState",new Map);lt(this,"pointerDownTimes",new Map);lt(this,"activeHoverIds",new Set);lt(this,"onNavigation");lt(this,"periodicTriggerTimes",new Map);lt(this,"wasInView",new Set);lt(this,"scrollProgressLastValue",new Map);lt(this,"debug_objectsRendered",0);lt(this,"debug_objectsTotal",0);lt(this,"lastRenderTime",0);lt(this,"debugMode",!1);lt(this,"activeTriggers",new Map);console.info("%c[ExodeUI Engine] Pixel-Perfect Parity Active (v6.3.10) - SVG Fill & Gradient Parity Active","color: #3b82f6; font-weight: bold; padding: 2px 4px; border-radius: 4px; background: rgba(59, 130, 246, 0.1)")}getInputValue(t){return this.inputs.get(t)}setTriggerCallback(t){this.onTrigger=t}setInputUpdateCallback(t){this.onInputUpdate=t}setComponentChangeCallback(t){this.onComponentChange=t}setToggleCallback(t){this.onToggle=t}setLogicUpdateCallback(t){this.onLogicUpdate=t}setInputChangeCallback(t){this.onInputChange=t}setButtonClickCallback(t){this.onButtonClick=t}setGraphPointClickCallback(t){this.onGraphPointClick=t}setNavigationCallback(t){this.onNavigation=t}ensurePathPoints(t){if(!t||t.type!=="Path"&&t.type!=="Subtract"&&t.type!=="Union"&&t.type!=="Intersect"&&t.type!=="Exclude"&&t.type!=="BooleanOperation")return;if(t.points&&t.points.length>0){if(t.is_closed===void 0&&t.isClosed===void 0&&t.data){const{isClosed:e}=this.svgPathToPoints(t.data);t.is_closed=e}return}if(!t.data)return;const{points:i,isClosed:o}=this.svgPathToPoints(t.data);t.points=i,t.is_closed===void 0&&(t.is_closed=o)}svgPathToPoints(t){const i=/([MLHVCSQTAZmlhvcsqtaz])([^MLHVCSQTAZmlhvcsqtaz]*)/g,o=/[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/g,e=[];let s=!1,n=0,a=0,l=0,c=0,h=0,r=0,u;for(;(u=i.exec(t))!==null;){const f=u[1],d=(u[2].match(o)||[]).map(parseFloat),p=f===f.toLowerCase(),m=f.toUpperCase();let y=0;const b=S=>{let C=d[y++];return p&&(C+=S?n:a),C},v=()=>({x:b(!0),y:b(!1)});switch(m){case"M":{const S=v();for(h=n=S.x,r=a=S.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a,moveTo:!0});y<d.length;){const C=v();n=C.x,a=C.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}case"L":for(;y<d.length;){const S=v();n=S.x,a=S.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break;case"H":for(;y<d.length;)n=b(!0),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"V":for(;y<d.length;)a=b(!1),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"C":for(;y<d.length;){const S=v(),C=v(),w=v();if(e.length>0){const M=e[e.length-1];M.out_x=S.x,M.out_y=S.y}n=w.x,a=w.y,e.push({x:n,y:a,in_x:C.x,in_y:C.y,out_x:n,out_y:a}),l=C.x,c=C.y}break;case"S":for(;y<d.length;){const S={x:2*n-l,y:2*a-c},C=v(),w=v();if(e.length>0){const M=e[e.length-1];M.out_x=S.x,M.out_y=S.y}n=w.x,a=w.y,e.push({x:n,y:a,in_x:C.x,in_y:C.y,out_x:n,out_y:a}),l=C.x,c=C.y}break;case"Q":for(;y<d.length;){const S=v(),C=v();if(e.length>0){const w=e[e.length-1];w.out_x=w.x+2/3*(S.x-w.x),w.out_y=w.y+2/3*(S.y-w.y)}n=C.x,a=C.y,e.push({x:n,y:a,in_x:n+2/3*(S.x-n),in_y:a+2/3*(S.y-a),out_x:n,out_y:a}),l=S.x,c=S.y}break;case"T":for(;y<d.length;){const S={x:2*n-l,y:2*a-c},C=v();if(e.length>0){const w=e[e.length-1];w.out_x=w.x+2/3*(S.x-w.x),w.out_y=w.y+2/3*(S.y-w.y)}n=C.x,a=C.y,e.push({x:n,y:a,in_x:n+2/3*(S.x-n),in_y:a+2/3*(S.y-a),out_x:n,out_y:a}),l=S.x,c=S.y}break;case"Z":if(s=!0,e.length>0){const S=e[e.length-1];S.closePath=!0;const C=[...e].reverse().find(w=>w.moveTo)||e[0];C&&Math.hypot(C.x-S.x,C.y-S.y)<.1&&(C.in_x=S.in_x,C.in_y=S.in_y,e.pop(),e.length>0&&(e[e.length-1].closePath=!0))}n=h,a=r;break;default:if(d.length>=2){const S=v();n=S.x,a=S.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}}return{points:e,isClosed:s}}setOnLogCallback(t){this.onLog=t}debugLog(t){this.onLog&&this.onLog(t)}setInputFocusCallback(t){this.onInputFocus=t}setInputBlurCallback(t){this.onInputBlur=t}updateConstraint(t,i,o){var s;const e=(s=this.artboard)==null?void 0:s.objects.find(n=>n.id===t);e&&e.constraints&&e.constraints[i]&&(e.constraints[i]={...e.constraints[i],...o},o.useSpring===!1&&this.objectVelocities.delete(t))}log(...t){this.debugMode&&console.log(...t)}warn(...t){this.debugMode&&console.warn(...t)}setInternalInput(t,i){this.inputs.set(t,i),this.onInputUpdate&&this.onInputUpdate(t,i)}setLayout(t,i){this.layout={fit:t,alignment:i}}getActiveStateIds(t="Base Layer"){const i=this.layerStates.get(t);return i?i.currentStateIds:[]}getObjectState(t){return this.objectStates.get(t)}updateObjectOptions(t,i){const o=this.objectStates.get(t);o&&(o.options={...o.options,...i})}updateGraphData(t,i){var e,s;if(!this.artboard)return;const o=this.artboard.objects.find(n=>n.id===t||n.name===t);if(o&&((e=o.geometry)==null?void 0:e.type)==="LineGraph"){const n=o.geometry;!n.datasets||n.datasets.length===0?n.datasets=[{id:"default",label:"Runtime Data",data:i,lineColor:"#3b82f6",lineWidth:2,showArea:!1}]:n.datasets[0].data=i;const a=this.objectStates.get(o.id);a&&((s=a.geometry)==null?void 0:s.type)==="LineGraph"&&(!a.geometry.datasets||a.geometry.datasets.length===0?a.geometry.datasets=JSON.parse(JSON.stringify(n.datasets)):a.geometry.datasets[0].data=[...i]),n.datasets[0].inputId&&this.updateInput(n.datasets[0].inputId,i)}else this.updateInput(t,i)}load(t){var n,a;if(!t)return;let i=this.decompressStrings(t);const o=[],e=new Set,s=l=>{l&&l.forEach(c=>{if(e.has(c.id))return;const h={...c},r=h.childrenObjects||[];e.add(h.id),o.push(h),s(r)})};if(s(i.objects||[]),o.length>(i.objects||[]).length&&this.log(`[Engine] Flattened artboard from ${(i.objects||[]).length} to ${o.length} objects.`),i.objects=o,this.artboard=i,this.currentTime=0,this.objectStates.clear(),this.log(`[ExodeUIEngine] Loading artboard: "${(n=this.artboard)==null?void 0:n.name}" with ${(a=this.artboard)==null?void 0:a.objects.length} objects`),this.artboard&&this.artboard.objects){const l=new Map;this.artboard.objects.forEach(c=>{l.set(c.id,c),c.children||(c.children=[])}),this.artboard.objects.forEach(c=>{if(c.parentId){const h=l.get(c.parentId);h&&(h.children||(h.children=[]),h.children.includes(c.id)||h.children.push(c.id))}})}this.loadFonts(),this.preloadImages(this.artboard),this.reset(),this.advance(0)}preloadImages(t){if(!t||!t.objects)return;const i=o=>{if(!o||this.imageCache.has(o))return;const e=new Image;e.onload=()=>{this.log(`[ExodeUI Preload] loaded ${e.naturalWidth}x${e.naturalHeight}`)},e.onerror=s=>{console.error("[ExodeUI Preload] failed:",s,`Src: ${o.substring(0,80)}...`)},e.src=o,this.imageCache.set(o,e)};t.objects.forEach(o=>{var e,s,n;(e=o.geometry)!=null&&e.src&&i(o.geometry.src),(n=(s=o.style)==null?void 0:s.fill)!=null&&n.src&&i(o.style.fill.src)})}decompressStrings(t){if(t&&typeof t=="object"&&!Array.isArray(t)){if(t._compressed&&t._data)try{const o=Ss.decompressFromBase64(t._data);if(o)return o}catch(o){return console.error("[ExodeUI] Failed to decompress string:",o),t._data}const i={};for(const[o,e]of Object.entries(t))i[o]=this.decompressStrings(e);return i}return Array.isArray(t)?t.map(i=>this.decompressStrings(i)):t}reset(){if(!this.artboard)return;if(this.objectStates.clear(),this.objectVelocities.clear(),this.currentTime=0,this.inputs.clear(),this.inputNameMap.clear(),this.layerStates.clear(),this.logicNodeValues.clear(),this.justFiredTriggers.clear(),this.inputs.set("mouseX",0),this.inputs.set("mouseY",0),this.inputs.set("scrollX",0),this.inputs.set("scrollY",0),this.inputs.set("isMouseDown",!1),this.physicsEngine&&(this.physicsEngine.destroy(),this.physicsEngine=null),this._layoutAnimCache.clear(),this._springChainState.clear(),this._emitterPools.clear(),this.artboard.objects.forEach(i=>{var n,a,l,c,h,r,u;const o=i.width??((n=i.geometry)==null?void 0:n.width)??0,e=i.height??((a=i.geometry)==null?void 0:a.height)??0,s=i.cornerRadius??i.corner_radius??((l=i.geometry)==null?void 0:l.corner_radius)??((c=i.geometry)==null?void 0:c.cornerRadius)??0;this.objectStates.set(i.id,{...i.transform||{},x:((h=i.transform)==null?void 0:h.x)??i.x??0,y:((r=i.transform)==null?void 0:r.y)??i.y??0,width:o,height:e,cornerRadius:s,corner_radius:s,clipContent:i.clipContent??!1,autoLayout:i.autoLayout?JSON.parse(JSON.stringify(i.autoLayout)):void 0,layoutProps:i.layoutProps?JSON.parse(JSON.stringify(i.layoutProps)):void 0,opacity:((u=i.transform)==null?void 0:u.opacity)!==void 0?i.transform.opacity:i.opacity!==void 0?i.opacity:100,visible:i.visible!==void 0?i.visible:i.isVisible!==void 0?i.isVisible:!0,blendMode:i.blendMode||"Normal",style:JSON.parse(JSON.stringify(i.style||{})),geometry:JSON.parse(JSON.stringify(i.geometry||{})),options:i.options?JSON.parse(JSON.stringify(i.options)):{},masks:i.masks?JSON.parse(JSON.stringify(i.masks)):[],zIndex:i.zIndex!==void 0?i.zIndex:void 0})}),this.artboard.objects.some(i=>{var o;return(o=i.physics)==null?void 0:o.enabled})){this.physicsEngine=new es;const i=this.artboard.physics?{x:this.artboard.physics.gravity.x,y:this.artboard.physics.gravity.y}:{x:0,y:1};this.physicsEngine.init(i).then(()=>{var o;this.physicsEngine&&((o=this.artboard)==null||o.objects.forEach(e=>{var s,n;if((s=e.physics)!=null&&s.enabled&&e.type==="Shape"){const a=this.objectStates.get(e.id);if(!a)return;const l=e.geometry.width||100,c=e.geometry.height||100;this.physicsEngine.createBody({id:e.id,type:((n=e.geometry)==null?void 0:n.type)||"Rectangle",x:a.x,y:a.y,width:l,height:c,rotation:a.rotation*(Math.PI/180),isStatic:e.physics.bodyType==="Static",mass:e.physics.mass,friction:e.physics.friction,restitution:e.physics.restitution,frictionAir:e.physics.frictionAir,density:e.physics.density,isSensor:e.physics.isSensor})}}))})}this.artboard.stateVariables&&this.artboard.stateVariables.forEach(i=>{this.inputs.set(i.id,i.value);const o=this.inputNameMap.get(i.name)||[];o.includes(i.id)||o.push(i.id),this.inputNameMap.set(i.name,o)}),this.artboard.stateMachine&&(this.activeStateMachine=this.artboard.stateMachine,this.activeStateMachine.inputs.forEach(i=>{this.inputs.set(i.id,i.value.value);const o=this.inputNameMap.get(i.name)||[];o.push(i.id),this.inputNameMap.set(i.name,o)}),this.activeStateMachine.layers.forEach(i=>{let o=i.states.find(e=>e.id===i.entryStateId);!o&&i.states.length>0&&(console.warn(`[ExodeUI] Invalid entryStateId "${i.entryStateId}" in layer "${i.name}". Falling back to first state.`),o=i.states[0]),o&&this.enterStates(i.name,[o.id])}),this.evaluateTransitions()),this.initGlobalAnimationTriggers(),this.updateAutoLayout(!0),this.loadFonts()}updateAutoLayout(t=!1){var s;if(!this.artboard)return;const i=new Map;this.artboard.objects.forEach(n=>i.set(n.id,n));const o=.15,e=n=>{n.forEach(a=>{const l=this.objectStates.get(a.id);if(l){const c=Math.abs(l.x-a.x),h=Math.abs(l.y-a.y);!t&&(c>20||h>20)?(l.x+=(a.x-l.x)*o,l.y+=(a.y-l.y)*o):(l.x=a.x,l.y=a.y),a.width!==void 0&&(l.width=a.width),a.height!==void 0&&(l.height=a.height)}})};if((s=this.artboard.autoLayout)!=null&&s.enabled){const n=this.artboard.objects.filter(l=>!l.parentId),a=ts(this.artboard,n,l=>this.objectStates.get(l));e(a.childUpdates)}this.artboard.objects.forEach(n=>{var a;if(n.type==="Frame"&&((a=n.autoLayout)!=null&&a.enabled)&&n.children&&n.children.length>0){const l=n.children.map(r=>i.get(r)).filter(r=>!!r),c=this.objectStates.get(n.id);if(!c)return;const h=ts(c,l,r=>this.objectStates.get(r));h.frameWidth!==void 0&&(c.width=h.frameWidth),h.frameHeight!==void 0&&(c.height=h.frameHeight),e(h.childUpdates)}})}loadFonts(){if(!this.artboard)return;const t=new Set;if(this.artboard.objects.forEach(n=>{n.geometry&&n.geometry.type==="Text"&&n.geometry.fontFamily&&t.add(n.geometry.fontFamily)}),this.artboard.animations.forEach(n=>{n.tracks.forEach(a=>{(a.property==="geometry.fontFamily"||a.property==="fontFamily")&&a.keyframes.forEach(l=>{l.value&&typeof l.value=="string"&&t.add(l.value)})})}),t.size===0)return;let i="";t.forEach(n=>{const a=n.replace(/ /g,"+");i+=`&family=${a}:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900`});const o="exodeui-google-fonts",e="exodeui-fontshare-fonts";if(i.length>0){const n=`https://fonts.googleapis.com/css2?display=swap${i}`;let a=document.getElementById(o);a||(a=document.createElement("link"),a.id=o,a.rel="stylesheet",document.head.appendChild(a)),a.href!==n&&(a.href=n)}const s=[];if(t.forEach(n=>{n.toLowerCase().includes("clash display")&&s.push("clash-display@200,300,400,500,600,700")}),s.length>0){const n=`https://api.fontshare.com/v2/css?f[]=${s.join("&f[]=")}&display=swap`;let a=document.getElementById(e);a||(a=document.createElement("link"),a.id=e,a.rel="stylesheet",document.head.appendChild(a)),a.href!==n&&(a.href=n)}document.fonts&&document.fonts.ready&&document.fonts.ready.then(()=>{this.pretextCache.clear(),this.advance(0)})}enterStates(t,i){var n;if(i.length===0)return;const o=this.layerStates.get(t);if(o&&o.currentStateIds.length===i.length&&i.every(l=>o.currentStateIds.includes(l))&&this.justFiredTriggers.size===0)return;const e=[];let s=0;if(this.artboard&&this.activeStateMachine){const a=this.activeStateMachine.layers.find(l=>l.name===t);if(a)for(const l of i){const c=a.states.find(h=>h.id===l);if(c)if(c.isBlendState&&c.blendAnimations&&c.blendAnimations.length>0)e.push({animation:null,state:c}),c.blendAnimations.forEach(h=>{const r=this.artboard.animations.find(u=>u.id===h.animationId);r&&(s=Math.max(s,r.duration))});else{let h=null;c.animationId&&(h=this.artboard.animations.find(r=>r.id===c.animationId)||null),h||(h=this.artboard.animations.find(r=>{var u,f;return r.name===c.name||r.id===c.name||(c.name==="Entry"||c.id==="entry")&&(((u=r.name)==null?void 0:u.toLowerCase())==="onload"||((f=r.name)==null?void 0:f.toLowerCase())==="intro")})||null),h&&((n=this.artboard.animationFlow)!=null&&n.some(u=>(u.trigger==="on_load"||u.trigger==="after_delay")&&u.targetAnimationId===(h==null?void 0:h.id))||(e.push({animation:h,state:c}),s=Math.max(s,h.duration)))}}}this.layerStates.set(t,{currentStateIds:i,animations:e,time:0,duration:s})}setInputBool(t,i){this.updateInput(t,i)}setInputNumber(t,i){this.updateInput(t,i)}fireTrigger(t){this.updateInput(t,!0)}setInputText(t,i){this.updateInput(t,i)}setInputNumberArray(t,i){this.updateInput(t,i)}setInputStringArray(t,i){this.updateInput(t,i)}updateObjectProperty(t,i,o){const e=this.objectStates.get(t);if(e)if(i.includes(".")){const s=i.split(".");let n=e;for(let a=0;a<s.length-1;a++)n[s[a]]||(n[s[a]]={}),n=n[s[a]];n[s[s.length-1]]=o}else e[i]=o}updateInput(t,i){var n,a,l;let o;if(this.inputs.has(t)){const c=(n=this.activeStateMachine)==null?void 0:n.inputs.find(h=>h.id===t);c&&typeof c.value=="object"&&(o=c.value.type)}else{const c=this.inputNameMap.get(t);if(c&&c.length>0){const h=(a=this.activeStateMachine)==null?void 0:a.inputs.find(r=>r.id===c[0]);h&&typeof h.value=="object"&&(o=h.value.type)}}let e=i;o==="Trigger"&&(i===1?e=!0:i===0&&(e=!1)),this.inputs.has(t)&&this.setInternalInput(t,e);const s=this.inputNameMap.get(t);s&&s.forEach(c=>this.setInternalInput(c,e)),o==="Trigger"&&e===!0&&(this.justFiredTriggers.add(t),s&&s.forEach(c=>this.justFiredTriggers.add(c))),Array.isArray(e)&&((l=this.artboard)==null||l.objects.forEach(c=>{if(c.inputId===t||c.name===t){const h=this.objectStates.get(c.id);h&&h.options&&(c.type==="ListView"||c.variant==="listview"?h.options.items=e:(c.type==="Dropdown"||c.variant==="dropdown")&&(h.options.optionsList=e))}})),this.evaluateTransitions(),this.evaluateVariableTriggers(t,e)}evaluateVariableTriggers(t,i){if(!this.artboard)return;const o=this.artboard.animationFlow||[],e=this.inputNameMap.get(t);o.forEach(s=>{if(s.trigger==="variable"&&s.conditionVariableId&&s.targetAnimationId&&(s.conditionVariableId===t||e&&e.includes(s.conditionVariableId))){const a=s.conditionOperator||"IsTrue",l=s.conditionValue;let c=!1;switch(a){case"Equal":case"==":c=i==l;break;case"NotEqual":case"!=":c=i!=l;break;case"GreaterThan":case">":c=i>l;break;case"LessThan":case"<":c=i<l;break;case"GreaterEqual":case">=":c=i>=l;break;case"LessEqual":case"<=":c=i<=l;break;case"IsTrue":c=!!i;break;case"IsFalse":c=!i;break}if(c){const h=s.delay||0;h<=0?this.triggerGlobalAnimation(s.targetAnimationId,s.subAnimationIds,s.loop,s.id):setTimeout(()=>this.triggerGlobalAnimation(s.targetAnimationId,s.subAnimationIds,s.loop,s.id),h)}}})}evaluateTransitions(){this.activeStateMachine&&(this.activeStateMachine.layers.forEach(t=>{const i=this.layerStates.get(t.name);if(!i||i.currentStateIds.length===0)return;const o=[];let e=!1;for(const s of i.currentStateIds){const n=t.states.find(l=>l.id===s);if(!n)continue;let a=!1;for(const l of n.transitions||[])this.checkConditions(l.conditions)&&(o.push(l.targetStateId),a=!0,e=!0);a||o.push(s)}if(!e){const s=this.findGlobalTransition(t,i.currentStateIds);s&&(o.length=0,o.push(s.targetStateId),e=!0,s.conditions&&(s.conditions||[]).forEach(n=>{var l;const a=(l=this.activeStateMachine)==null?void 0:l.inputs.find(c=>c.id===n.inputId);a&&typeof a.value=="object"&&a.value.type==="Trigger"&&this.setInternalInput(n.inputId,!1)}))}if(e){const s=Array.from(new Set(o));this.enterStates(t.name,s)}}),this.justFiredTriggers.size>0&&(this.justFiredTriggers.forEach(t=>{var o,e;this.setInternalInput(t,!1);const i=(o=this.activeStateMachine)==null?void 0:o.inputs.find(s=>s.id===t);i&&this.inputNameMap.has(i.name)&&((e=this.inputNameMap.get(i.name))==null||e.forEach(s=>this.setInternalInput(s,!1)))}),this.justFiredTriggers.clear()))}findGlobalTransition(t,i){for(const o of t.states)if(!(i.includes(o.id)&&this.justFiredTriggers.size===0)){for(const s of o.transitions||[])if(!(i.includes(s.targetStateId)&&this.justFiredTriggers.size===0)&&this.checkConditions(s.conditions))return s}return null}checkConditions(t){return!t||t.length===0?!0:t.every(i=>{const o=i.inputId,e=i.op,s=i.value,n=this.evaluateLogicTree(o);if(n===void 0)return this.log(`[Engine] Condition Check Failed: Input ${o} is undefined`),!1;let a=!1;switch(e){case"Equal":case"==":a=n==s;break;case"NotEqual":case"!=":a=n!=s;break;case"GreaterThan":case">":a=n>s;break;case"LessThan":case"<":a=n<s;break;case"GreaterEqual":case">=":a=n>=s;break;case"LessEqual":case"<=":a=n<=s;break;case"IsTrue":a=!!n;break;case"IsFalse":a=!n;break;default:a=!1}return a||this.justFiredTriggers.has(o),a})}evaluateLogicTree(t,i=null,o=new Set){var a,l,c,h,r,u;if(o.has(t))return this.inputs.get(t)??this.logicNodeValues.get(t)??0;o.add(t);const e=(l=(a=this.activeStateMachine)==null?void 0:a.logicNodes)==null?void 0:l.find(f=>f.id===t);if(e){const f=(p,m)=>{const y=e.inputs.find(b=>b.id===p);return y?y.sourceId?this.evaluateLogicTree(y.sourceId,y.sourceHandleId,o):y.value!==void 0?y.value:m:m};let d=0;switch(e.op){case wt.AND:d=f("a",!1)&&f("b",!1);break;case wt.OR:d=f("a",!1)||f("b",!1);break;case wt.NOT:d=!f("in",!1);break;case wt.XOR:d=!!f("a",!1)!=!!f("b",!1);break;case wt.OBJECT:d=e.name;break;case wt.PROPERTY:case wt.GET_PROPERTY:{const p=f("id","");if(!p){d=0;break}const m=e.name;if(!m||m==="GET_PROPERTY"||m==="PROPERTY"){d=0;break}const y=this.objectStates.get(p);if(!y){d=0;break}m in y?d=y[m]:d=this.resolvePath(y,m);break}case wt.SET_PROPERTY:{const p=f("id",""),m=f("value",void 0);if(!p||m===void 0){d=0;break}const y=e.name;if(!y||y==="SET_PROPERTY"){d=0;break}const b=this.objectStates.get(p);if(!b){d=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(y))b[y]=m,d=m;else{const S=y.split(".");let C=b;for(let M=0;M<S.length-1;M++){const I=S[M];C[I]===void 0&&(C[I]={}),C=C[I]}const w=S[S.length-1];C[w]=m,d=m}break}case wt.ADD:d=f("a",0)+f("b",0);break;case wt.SUB:d=f("a",0)-f("b",0);break;case wt.MUL:d=f("a",0)*f("b",0);break;case wt.DIV:{const p=f("b",1);d=p===0?0:f("a",0)/p;break}case wt.MOD:d=f("a",0)%f("b",1);break;case wt.POW:d=Math.pow(f("a",0),f("b",1));break;case wt.ABS:d=Math.abs(f("in",0));break;case wt.ROUND:d=Math.round(f("in",0));break;case wt.FLOOR:d=Math.floor(f("in",0));break;case wt.CEIL:d=Math.ceil(f("in",0));break;case wt.SIN:d=Math.sin(f("in",0));break;case wt.COS:d=Math.cos(f("in",0));break;case wt.TAN:d=Math.tan(f("in",0));break;case wt.CLAMP:{const p=f("in",0),m=f("min",0),y=f("max",1);d=Math.max(m,Math.min(y,p));break}case wt.REMAP:{const p=f("in",0),m=f("inMin",0),y=f("inMax",100),b=f("outMin",0),v=f("outMax",1);d=y===m?b:b+(p-m)*(v-b)/(y-m);break}case wt.EQ:d=f("a",0)==f("b",0);break;case wt.NEQ:d=f("a",0)!=f("b",0);break;case wt.GT:d=f("a",0)>f("b",0);break;case wt.LT:d=f("a",0)<f("b",0);break;case wt.GTE:d=f("a",0)>=f("b",0);break;case wt.LTE:d=f("a",0)<=f("b",0);break;case wt.IF_ELSE:d=f("cond",!1)?f("then",0):f("else",0);break;case wt.VALUE:d=e.value!==void 0?e.value:0;break;case wt.INPUT:d=this.inputs.get(e.name)??0;break;case wt.LOG:{const p=f("in","");this.debugLog(`[User Logic] ${p}`),d=p;break}case wt.SCROLL_X:d=this.inputs.get("scrollX")??0;break;case wt.SCROLL_Y:d=this.inputs.get("scrollY")??0;break;case wt.MOUSE_X:d=this.inputs.get("mouseX")??0;break;case wt.MOUSE_Y:d=this.inputs.get("mouseY")??0;break;case wt.IS_MOUSE_DOWN:d=this.inputs.get("isMouseDown")??!1;break;case wt.EFFECTOR:{const p=f("id",""),m=f("intensity",1),y=f("trigger",!0);if(!p||!y){d=0;break}const b=e.name;if(!b){d=0;break}const v=this.objectStates.get(p);if(!v){d=0;break}if(["glitch","halftone","pixelate","noise","acid_gradient","acid_rave","shimmer"].includes(b))v.style||(v.style={}),v.style.artEffect={enabled:!0,type:b,intensity:m},d=1;else{v.behaviors||(v.behaviors=[]);let C=v.behaviors.find(w=>w.type===b);C?(C.enabled=!0,C.settings||(C.settings={}),C.settings.intensity=m):(C={id:`eff_${Date.now()}_${b}`,type:b,enabled:!0,sensors:[],settings:{intensity:m}},v.behaviors.push(C)),d=1}break}case wt.MONITOR:{d=f("in",0);break}case wt.SPRING_PULL:{const p=f("objectId",""),m=f("forceX",0),y=f("forceY",0);p&&((c=this.artboard)==null||c.objects.forEach(b=>{b.behaviors&&b.behaviors.forEach(v=>{var S;if(v.type===U.SpringChain&&((S=v.settings)!=null&&S.connections)&&(v.settings.connections.some(w=>w.targetId===p)||b.id===p)){this._springChainState.has(b.id)||this._springChainState.set(b.id,new Map);const w=this._springChainState.get(b.id);if(!w.has(p)){const I=this.objectStates.get(p);w.set(p,{x:(I==null?void 0:I.x)??0,y:(I==null?void 0:I.y)??0,vx:0,vy:0})}const M=w.get(p);M&&(M.vx+=m,M.vy+=y)}})})),d=1;break}case wt.SPRING_SETTLE:{const p=f("objectId","");let m=!0;if(p){const y=f("threshold",1);this._springChainState.forEach(b=>{const v=b.get(p);v&&(Math.abs(v.vx)>y||Math.abs(v.vy)>y)&&(m=!1)})}d=m;break}case wt.EMIT:{const p=f("objectId",""),m=f("count",20);p&&((h=this.artboard)==null||h.objects.forEach(y=>{y.behaviors&&y.behaviors.forEach(b=>{b.type===U.ParticleEmitter&&y.id===p&&(b._pendingBurst=(b._pendingBurst||0)+m)})})),d=1;break}default:d=0;break}if(this.logicNodeValues.set(t,d),e.op===wt.DELAY){const p=f("delay",0),m=f("in",0);let y=this.logicNodeState.get(t);for(y||(y={queue:[]},this.logicNodeState.set(t,y)),y.queue.push({time:this.currentTime+p,value:m});y.queue.length>0&&y.queue[0].time<=this.currentTime;)y.lastValue=y.queue.shift().value;d=y.lastValue??0}return d}const s=(r=this.activeStateMachine)==null?void 0:r.inputs.find(f=>f.id===t||f.name===t);if(s&&s.sourceId&&!o.has(s.sourceId)){const f=this.evaluateLogicTree(s.sourceId,s.sourceHandleId,o);return this.inputs.set(s.id,f),f}let n=this.inputs.get(t)??(s?this.inputs.get(s.id):void 0);if((this.justFiredTriggers.has(t)||s&&this.justFiredTriggers.has(s.id))&&(n=!0),i&&n!==void 0){const f=(u=this.activeStateMachine)==null?void 0:u.inputs.find(d=>d.id===t);if(f&&f.value.type==="Number"&&typeof n=="number"){const d=f.value.defaultValue??f.value.value;if(i==="source-greater")return n>d;if(i==="source-less")return n<d;if(i==="source-equal")return n===d}if(i==="source-true")return n===!0;if(i==="source-false")return n===!1;if(i==="source-fire")return this.justFiredTriggers.has(t)}return n!==void 0?n:0}runLogicNodes(){!this.activeStateMachine||!this.activeStateMachine.logicNodes||this.activeStateMachine.logicNodes.forEach(t=>{(t.op===wt.SET_PROPERTY||t.op===wt.EFFECTOR)&&this.evaluateLogicTree(t.id)})}resolvePath(t,i){const o=i.split(".");let e=t;for(const s of o)if(e&&typeof e=="object"&&s in e)e=e[s];else return;return e}seek(t){this.artboard&&(this.currentTime=t,this.layerStates.forEach(i=>{i.time=t,i.time>(i.duration||0)&&(i.animations.some(e=>{var s;return((s=e.state)==null?void 0:s.loop)===!0})?i.time%=i.duration||1:i.time=i.duration)}),this.advance(0))}advance(t){if(!this.artboard)return;this.currentTime+=t,this.isMouseDown&&this.pointerDownTimes.forEach((o,e)=>{e&&this.currentTime-o>=.5&&(this.log(`[Engine] onHold detected for ${e}`),this.fireEventForObject(e,"onHold"),this.pointerDownTimes.delete(e))}),this.frameCount++,this.physicsEngine&&(this.physicsEngine.step(t),this.artboard.objects.forEach(o=>{var e;if((e=o.physics)!=null&&e.enabled){const s=this.physicsEngine.getPosition(o.id),n=this.physicsEngine.getRotation(o.id),a=this.objectStates.get(o.id);a&&s!==null&&n!==null&&(a.x=s.x,a.y=s.y,a.rotation=n*(180/Math.PI))}})),this.activeStateMachine&&(this.runLogicNodes(),this.evaluateTransitions());const i=[];this.layerStates.forEach((o,e)=>{if(o.animations.length>0){if(o.time+=t,this.frameCount%240===0&&this.debugLog(`Advancing Layer time: ${o.time.toFixed(3)} / ${o.duration.toFixed(3)}`),o.time>o.duration)if(o.animations.some(n=>{var a;return((a=n.state)==null?void 0:a.loop)===!0}))o.time%=o.duration;else{const n=o.time<o.duration+.1;o.time=o.duration,n&&(o.currentStateIds.length>0&&this.handleAnimationFinished(o.currentStateIds[0],o.ruleId),e.startsWith("global_")&&i.push(e))}o.animations.forEach(s=>{var n;(n=s.state)!=null&&n.isBlendState&&s.state.blendAnimations?this.applyBlendState(s.state,o.time):s.animation&&this.applyAnimation(s.animation,o.time,s.filterObjectIds)})}}),i.forEach(o=>{this.layerStates.delete(o),this.debugLog(`[Engine] Cleaned up completed global layer: ${o}`)}),this.solveConstraints(t),this.solveBehaviors(t),this.activeTriggers.forEach((o,e)=>{var s,n,a,l,c,h,r;if(o.phase==="entry")o.time+=t,o.time>=o.animation.duration&&((a=(n=(s=this.artboard)==null?void 0:s.objects.find(u=>u.id===e))==null?void 0:n.triggers)==null||a.find(u=>u.id===o.triggerId),o.phase="hold",o.elapsedHold=0,o.time=o.animation.duration),this.applyAnimation(o.animation,o.time,o.filterObjectIds||o.filterObjectId||void 0);else if(o.phase==="hold"){const u=(h=(c=(l=this.artboard)==null?void 0:l.objects.find(p=>p.id===e))==null?void 0:c.triggers)==null?void 0:h.find(p=>p.id===o.triggerId),f=(u==null?void 0:u.duration)||0;o.elapsedHold+=t*1e3;let d=o.elapsedHold>=f;if((u==null?void 0:u.eventType)==="hover"&&!this.activeHoverIds.has(e)&&(d=!0),((u==null?void 0:u.eventType)==="onHold"||(u==null?void 0:u.eventType)==="pointerDown")&&!this.isMouseDown&&(d=!0),d)if(u!=null&&u.exitAnimationId){const p=(r=this.artboard)==null?void 0:r.animations.find(m=>m.id===u.exitAnimationId);p?(o.phase="exit",o.animation=p,o.time=0):this.activeTriggers.delete(e)}else this.activeTriggers.delete(e)}else o.phase==="exit"&&(o.time+=t,o.time>=o.animation.duration?this.activeTriggers.delete(e):this.applyAnimation(o.animation,o.time,o.filterObjectIds||o.filterObjectId||void 0))}),this.evaluateContinuousInteractions(t),this.processJoysticks(t),this.activeStateMachine&&this.onLogicUpdate&&this.logicNodeValues.size>0&&this.onLogicUpdate(Object.fromEntries(this.logicNodeValues))}evaluateContinuousInteractions(t){this.artboard&&(this.artboard.objects.forEach(i=>{var e,s,n;const o=(e=i.style)==null?void 0:e.analytics;if(o&&o.isEnabled&&o.triggerType==="visible"){const a=this.objectStates.get(i.id);if(a&&a.visible!==!1){const l=this.getGlobalTransform(i.id),c=(((s=i.geometry)==null?void 0:s.width)||100)*(l.scale_x||1),h=(((n=i.geometry)==null?void 0:n.height)||100)*(l.scale_y||1),r=50,u=l.x+c/2>=-this.canvasWidth/2-r&&l.x-c/2<=this.canvasWidth/2+r&&l.y+h/2>=-this.canvasHeight/2-r&&l.y-h/2<=this.canvasHeight/2+r,f=`analytics_${i.id}`,d=this.wasInView.has(f);u&&!d&&this.fireAnalyticsEvent(i.id,"visible"),u?this.wasInView.add(f):this.wasInView.delete(f)}}}),this.artboard.objects.forEach(i=>{const o=i.interactions||[];o.length!==0&&o.forEach(e=>{const s=e.triggers||[e.event||e.trigger];s&&s.forEach(n=>{var l,c,h;const a=n.toLowerCase();if(a==="on interval"||a==="oninterval"){const r=e.intervalValue||2e3,u=this.periodicTriggerTimes.get(e.id)||0;this.currentTime*1e3-u>=r&&(!e.conditions||this.checkConditions(e.conditions))&&(this.fireEventForObject(i.id,"On Interval"),this.periodicTriggerTimes.set(e.id,this.currentTime*1e3))}if(a==="on delay"||a==="ondelay"){const r=e.delayValue||1e3;!this.periodicTriggerTimes.has(e.id)&&this.currentTime*1e3>=r&&(!e.conditions||this.checkConditions(e.conditions))&&(this.fireEventForObject(i.id,"On Delay"),this.periodicTriggerTimes.set(e.id,this.currentTime*1e3))}if(a==="scroll into view"||a==="scrollintoview"){const r=this.objectStates.get(i.id);if(r&&r.visible!==!1){const u=this.getGlobalTransform(i.id),f=(((l=i.geometry)==null?void 0:l.width)||100)*(u.scale_x||1),d=(((c=i.geometry)==null?void 0:c.height)||100)*(u.scale_y||1),p=50,m=u.x+f/2>=-this.canvasWidth/2-p&&u.x-f/2<=this.canvasWidth/2+p&&u.y+d/2>=-this.canvasHeight/2-p&&u.y-d/2<=this.canvasHeight/2+p,y=this.wasInView.has(i.id);m&&!y&&(!e.conditions||this.checkConditions(e.conditions))&&this.fireEventForObject(i.id,"Scroll Into View"),m?this.wasInView.add(i.id):this.wasInView.delete(i.id)}}if(a==="scroll progress"||a==="scrollprogress"){const r=Math.abs(this.scrollOffset.y)/(((h=this.artboard)==null?void 0:h.height)||1e3),u=this.scrollProgressLastValue.get(e.id)||0;Math.abs(r-u)>.001&&(this.scrollProgressLastValue.set(e.id,r),(e.action==="Set Input"||e.action==="setInput")&&this.updateInput(e.targetInputId,r))}})})}))}solveConstraints(t){this.artboard&&this.artboard.objects.forEach(i=>{if(!i.constraints||i.constraints.length===0)return;const o=this.objectStates.get(i.id);if(!o)return;const e=this.getGlobalTransform(i.id);if(i.constraints.forEach((s,n)=>{var h,r,u,f,d,p,m,y,b;const a=((h=o.constraints)==null?void 0:h[n])||{},l={...s,...a},c=l.strength??1;if(l.type==="Translation"){const v=this.getGlobalTransform(l.targetId);if(v){const S=l.offsetX||0,C=l.offsetY||0,w=v.x+S,M=v.y+C,I=l.useSpring;if(I){const T=this.objectVelocities.get(i.id)||{vx:0,vy:0},{x:O,y:P,vx:_,vy:A}=this.computeSpring(e.x,e.y,T.vx,T.vy,w,M,l,t);l.copyX&&(e.x=e.x+(O-e.x)*c),l.copyY&&(e.y=e.y+(P-e.y)*c),this.objectVelocities.set(i.id,{vx:_,vy:A})}else l.copyX&&(e.x=e.x+(w-e.x)*c),l.copyY&&(e.y=e.y+(M-e.y)*c);let k=!1;if((r=l.limitX)!=null&&r.enabled){const T=e.x;e.x=Math.max(l.limitX.min,Math.min(l.limitX.max,e.x)),e.x!==T&&(k=!0)}if((u=l.limitY)!=null&&u.enabled){const T=e.y;e.y=Math.max(l.limitY.min,Math.min(l.limitY.max,e.y)),e.y!==T&&(k=!0)}k&&I&&this.objectVelocities.set(i.id,{vx:0,vy:0})}}else if(l.type==="Rotation"){const v=this.getGlobalTransform(l.targetId);if(v){let C=(v.rotation+(l.offset||0)-e.rotation)%360;C>180&&(C-=360),C<-180&&(C+=360),e.rotation=e.rotation+C*c}}else if(l.type==="Scale"){const v=this.getGlobalTransform(l.targetId);v&&(l.copyX&&(e.scale_x=e.scale_x+(v.scale_x-e.scale_x)*c),l.copyY&&(e.scale_y=e.scale_y+(v.scale_y-e.scale_y)*c))}else if(l.type==="Transform"){const v=this.getGlobalTransform(l.targetId);if(v){e.x=e.x+(v.x-e.x)*c,e.y=e.y+(v.y-e.y)*c;let S=(v.rotation-e.rotation)%360;S>180&&(S-=360),S<-180&&(S+=360),e.rotation=e.rotation+S*c,e.scale_x=e.scale_x+(v.scale_x-e.scale_x)*c,e.scale_y=e.scale_y+(v.scale_y-e.scale_y)*c}}else if(l.type==="FollowPointer"){const v=((f=this._lastPointerPos)==null?void 0:f.x)??e.x,S=((d=this._lastPointerPos)==null?void 0:d.y)??e.y,C=l.useSpring;if(C){const M=this.objectVelocities.get(i.id)||{vx:0,vy:0},{x:I,y:k,vx:T,vy:O}=this.computeSpring(e.x,e.y,M.vx,M.vy,v,S,l,t);e.x=I,e.y=k,this.objectVelocities.set(i.id,{vx:T,vy:O})}else e.x=e.x+(v-e.x)*c,e.y=e.y+(S-e.y)*c;let w=!1;if((p=l.limitX)!=null&&p.enabled){const M=e.x;e.x=Math.max(l.limitX.min,Math.min(l.limitX.max,e.x)),e.x!==M&&(w=!0)}if((m=l.limitY)!=null&&m.enabled){const M=e.y;e.y=Math.max(l.limitY.min,Math.min(l.limitY.max,e.y)),e.y!==M&&(w=!0)}w&&C&&this.objectVelocities.set(i.id,{vx:0,vy:0})}else if(l.type==="Distance"){const v=this.getGlobalTransform(l.targetId);if(v){const S=e.x-v.x,C=e.y-v.y,w=Math.sqrt(S*S+C*C),M=l.distance||0;let I=w;switch(l.mode){case"exact":I=M;break;case"minimum":I=Math.max(M,w);break;case"maximum":I=Math.min(M,w);break;case"clamped":I=Math.max(0,Math.min(M,w));break}if(w>0){const k=e.x===v.x&&e.y===v.y?1:I/w;e.x=e.x+(v.x+S*k-e.x)*c,e.y=e.y+(v.y+C*k-e.y)*c}}}else if(l.type==="FollowPath"){const v=(y=this.artboard)==null?void 0:y.objects.find(S=>S.id===l.targetId);if(v){const S=this.getGlobalTransform(v.id);if(S){let C=v.geometry;if(v.type==="Frame"||v.type==="Group"||!C||C.type!=="Path"&&C.type!=="Ellipse"&&C.type!=="Rectangle"){const L=(b=this.artboard)==null?void 0:b.objects.find(G=>G.parentId===v.id&&G.type==="Shape"&&G.geometry&&(G.geometry.type==="Path"||G.geometry.type==="Ellipse"||G.geometry.type==="Rectangle"));L&&(C=L.geometry)}if(!C)return;const w=(l.distance||0)/100,M=S.width||C.width||0,I=S.height||C.height||0,k=this.getPointOnPath(C,M,I,w),T=S.rotation*Math.PI/180,O=Math.cos(T),P=Math.sin(T),_=k.x*S.scale_x*O-k.y*S.scale_y*P,A=k.x*S.scale_x*P+k.y*S.scale_y*O;let x=S.rotation+(l.offsetRotation||0);if(l.orient){const L=Math.cos(k.angle),G=Math.sin(k.angle),z=L*S.scale_x*O-G*S.scale_y*P,it=L*S.scale_x*P+G*S.scale_y*O;x=Math.atan2(it,z)*180/Math.PI+(l.offsetRotation||0)}const W=x*Math.PI/180,Y=Math.cos(W),B=Math.sin(W),X=(l.offsetX||0)*Y-(l.offsetY||0)*B,q=(l.offsetX||0)*B+(l.offsetY||0)*Y,j=S.x+_+X,E=S.y+A+q;if(e.x=e.x+(j-e.x)*c,e.y=e.y+(E-e.y)*c,l.orient){let L=(x-e.rotation)%360;L>180&&(L-=360),L<-180&&(L+=360),e.rotation=e.rotation+L*c}}}}else if(l.type==="IK"){const v=this.getGlobalTransform(l.targetId);v&&this.solveIK(i,v,l.boneCount||2,c)}}),i.constraints.some(s=>s.type!=="IK")){const s=this.globalToLocal(i.parentId,e);o.x=s.x,o.y=s.y,o.rotation=s.rotation,o.flip_x=s.scale_x<0,o.scale_x=Math.abs(s.scale_x),o.flip_y=s.scale_y<0,o.scale_y=Math.abs(s.scale_y)}})}getGlobalTransform(t){var r,u;const i=this.objectStates.get(t);if(!i)return{x:0,y:0,rotation:0,scale_x:1,scale_y:1};const o=(r=this.artboard)==null?void 0:r.objects.find(f=>f.id===t),e=(o==null?void 0:o.type)==="Bone"?(u=o.geometry)==null?void 0:u.length:void 0;if(!o||!o.parentId)return{x:i.x,y:i.y,rotation:i.rotation,scale_x:(i.scale_x??1)*(i.flip_x?-1:1),scale_y:(i.scale_y??1)*(i.flip_y?-1:1),length:e};const s=this.getGlobalTransform(o.parentId),n=s.rotation*Math.PI/180,a=Math.cos(n),l=Math.sin(n),c=s.x+(i.x*s.scale_x*a-i.y*s.scale_y*l),h=s.y+(i.x*s.scale_x*l+i.y*s.scale_y*a);return{x:c,y:h,rotation:s.rotation+i.rotation,scale_x:s.scale_x*(i.scale_x??1)*(i.flip_x?-1:1),scale_y:s.scale_y*(i.scale_y??1)*(i.flip_y?-1:1),length:e}}globalToLocal(t,i){if(!t)return i;const o=this.getGlobalTransform(t),e=o.scale_x===0?0:1/o.scale_x,s=o.scale_y===0?0:1/o.scale_y,n=-o.rotation*Math.PI/180,a=Math.cos(n),l=Math.sin(n),c=i.x-o.x,h=i.y-o.y,r=(c*a-h*l)*e,u=(c*l+h*a)*s;return{x:r,y:u,rotation:i.rotation-o.rotation,scale_x:i.scale_x/(o.scale_x||1),scale_y:i.scale_y/(o.scale_y||1)}}solveIK(t,i,o,e){var c;const s=[];let n=t.id;for(let h=0;h<o&&n;h++){const r=(c=this.artboard)==null?void 0:c.objects.find(u=>u.id===n);if(!r)break;s.push({id:n,local:this.objectStates.get(n),global:this.getGlobalTransform(n)}),n=r.parentId}if(s.length<2)return;const a=s.reverse(),l=5;for(let h=0;h<l;h++){const r=this.getGlobalTransform(t.id);for(let u=a.length-2;u>=0;u--){const f=a[u],d=this.getGlobalTransform(f.id),p=r.x-d.x,m=r.y-d.y,y=i.x-d.x,b=i.y-d.y,v=Math.sqrt(p*p+m*m),S=Math.sqrt(y*y+b*b);if(v>.001&&S>.001){const C=Math.atan2(m,p);let M=(Math.atan2(b,y)-C)*180/Math.PI;M*=e;const I=this.objectStates.get(f.id);I&&(I.rotation+=M)}}}}computeSpring(t,i,o,e,s,n,a,l){const c=a.stiffness??100,h=a.damping??10,r=a.mass??1,u=-c*(t-s),f=-c*(i-n),d=-h*o,p=-h*e,m=(u+d)/r,y=(f+p)/r,b=o+m*l,v=e+y*l,S=t+b*l,C=i+v*l;return{x:S,y:C,vx:b,vy:v}}handlePointerInput(t,i,o,e,s){if(!this.artboard)return;const n=this.calculateTransform(e,s,this.artboard.width,this.artboard.height,this.layout.fit,this.layout.alignment),a=(i-n.tx)/n.scaleX,l=(o-n.ty)/n.scaleY;this._prevPointerPos=this._lastPointerPos,this._lastPointerPos={x:a,y:l},this._prevPointerPos&&(this._mouseDelta.dx+=a-this._prevPointerPos.x,this._mouseDelta.dy+=l-this._prevPointerPos.y),this.updateInput("mouseX",a),this.updateInput("mouseY",l),this.handlePointerEvent(t,a,l)}handleScroll(t,i){const o=this.scrollOffset.x,e=this.scrollOffset.y;this.scrollOffset={x:t,y:i},this._totalScroll.x+=t-o,this._totalScroll.y+=i-e,this.updateInput("scrollX",this._totalScroll.x),this.updateInput("scrollY",this._totalScroll.y)}handleWheel(t,i){this._totalScroll.x+=t,this._totalScroll.y+=i,this.scrollOffset={x:this._totalScroll.x,y:this._totalScroll.y},this.updateInput("scrollX",this._totalScroll.x),this.updateInput("scrollY",this._totalScroll.y)}handlePointerEvent(t,i,o){var l,c,h,r,u;if(!this.artboard)return;t==="down"?(this.isMouseDown=!0,this.updateInput("isMouseDown",!0)):(t==="up"||t==="blur")&&(this.isMouseDown=!1,this.updateInput("isMouseDown",!1));let e=null;const s=(f,d)=>{var S;let p=d;d==="click"?p="onClick":d==="down"?p="onPointerDown":d==="up"?p="onPointerUp":d==="blur"&&(p="onPointerLeave");const m=new Set([p]);d==="move"&&m.add("onPointerEnter").add("hover").add("onPointerLeave").add("blur"),p==="onClick"&&m.add("click"),p==="onPointerDown"&&m.add("pointerDown"),p==="onPointerUp"&&m.add("pointerUp");const y=["button","toggle","toggle_button","dropdown","listview","inputbox","slider","checkbox","radiogroup","joystick"];return!!(f.type==="Component"&&y.includes(f.variant)||f.type==="Joystick"||y.includes((S=f.type)==null?void 0:S.toLowerCase())||(f.interactions||[]).some(C=>m.has(C.event))||(f.triggers||[]).some(C=>m.has(C.eventType)))};let n=null;for(let f=this.artboard.objects.length-1;f>=0;f--){const d=this.artboard.objects[f],p=this.objectStates.get(d.id);if(p&&p.visible!==!1&&p.opacity>0&&this.hitTest(d,i,o)&&(n||(n=d),s(d,t))){e=d;break}}!e&&n&&(e=n),this.pointerHistory.push({x:i,y:o,time:Date.now()}),this.pointerHistory.length>this.MAX_HISTORY&&this.pointerHistory.shift();const a=(e==null?void 0:e.id)||null;if(t==="move"){if(this.draggingSliderId){const f=this.artboard.objects.find(d=>d.id===this.draggingSliderId);f&&this.updateSliderValueFromPointer(f,i,o);return}if(this.draggingJoystickId){const f=this.artboard.objects.find(d=>d.id===this.draggingJoystickId);f&&this.updateJoystickValueFromPointer(f,i,o);return}if(this.draggingListViewId){const f=this.artboard.objects.find(d=>d.id===this.draggingListViewId);f&&this.updateListViewScrollFromPointer(f);return}e&&(e.type==="ListView"||e.type==="Component"&&e.variant==="listview")&&this.updateListViewHoverFromPointer(e,i,o),this.isMouseDown&&a&&this.fireEventForObject(a,"Drag"),a!==this.lastHoveredObjectId&&(this.log(`[Engine] HOVER CHANGE: ${this.lastHoveredObjectId} -> ${a}`),this.lastHoveredObjectId&&this.fireEventForObject(this.lastHoveredObjectId,"onPointerLeave"),a&&this.fireEventForObject(a,"onPointerEnter"),this.lastHoveredObjectId=a);return}if((t==="up"||t==="blur")&&(this.draggingSliderId=null,this.draggingJoystickId=null,this.draggingListViewId=null,this.draggingBehaviors.clear(),this.pointerDownTimes.delete(a),this.activeObjectId=null),t==="down"&&(this.pointerDownTimes.set(a,this.currentTime),this.activeObjectId=a,e&&((l=e.behaviors)!=null&&l.some(f=>f.type===U.Draggable))&&this.draggingBehaviors.add(a)),t==="move"?(a&&!this.activeHoverIds.has(a)&&this.activeHoverIds.add(a),this.activeHoverIds.forEach(f=>{f!==a&&this.activeHoverIds.delete(f)})):t==="blur"&&this.activeHoverIds.clear(),this.activeDropdownId&&t==="down"){const f=this.artboard.objects.find(d=>d.id===this.activeDropdownId);if(f&&(f.type==="Dropdown"||f.variant==="dropdown")){const d=this.objectStates.get(f.id),p=(d==null?void 0:d.options)||f.options||{},m=f.geometry||{},y=m.width??f.width??200,b=m.height??f.height??40,v=p.optionsList||[],S=p.itemHeight||32,C=p.listPadding??4,w=v.length*S+C*2,M=this.getWorldTransform(f.id),I=y*Math.abs(M.scaleX),k=b*Math.abs(M.scaleY),T=M.y+k/2+4,O=Math.abs(i-M.x)<=I/2,P=o>=T&&o<=T+w*Math.abs(M.scaleY);if(O&&P){const _=Math.abs(M.scaleY),A=o-(T+C*_),x=Math.floor(A/(S*_));if(x>=0&&x<v.length){const W=v[x];p.selectedOption=W,p.isOpen=!1,this.activeDropdownId=null,f.inputId&&this.setInternalInput(f.inputId,W),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"dropdown",property:"selectedOption",value:W})}return}else a!==this.activeDropdownId&&(p.isOpen=!1,this.activeDropdownId=null)}}if(e){let f=e,d=e;for(;d&&d.parentId;){const m=this.artboard.objects.find(y=>y.id===d.parentId);if(m&&m.type==="Component"){f=m;break}d=m}let p=t;if(t==="click"?p="onClick":t==="down"?p="onPointerDown":t==="up"?p="onPointerUp":t==="blur"&&(p="onPointerLeave"),this.fireEventForObject(e.id,p),f!==e&&this.fireEventForObject(f.id,p),f.type==="Component"&&f.variant==="toggle_button"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{};y.checked=!y.checked,f.inputId&&this.setInternalInput(f.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"toggle_button",property:"checked",value:y.checked}),this.fireEventForObject(f.id,"Toggle"),this.fireEventForObject(f.id,y.checked?"Toggle True":"Toggle False")}if(f.type==="Component"&&f.variant==="toggle"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{};y.checked=!y.checked,f.inputId&&this.setInternalInput(f.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"toggle",property:"checked",value:y.checked}),this.onToggle&&this.onToggle(f.name,y.checked),this.fireEventForObject(f.id,"Toggle"),this.fireEventForObject(f.id,y.checked?"Toggle True":"Toggle False")}if(f.type==="Component"&&f.variant==="dropdown"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{},b=!y.isOpen;if(b&&this.activeDropdownId&&this.activeDropdownId!==f.id){const v=this.artboard.objects.find(S=>S.id===this.activeDropdownId);v&&v.options&&(v.options.isOpen=!1)}y.isOpen=b,this.activeDropdownId=b?f.id:null}if(f.type==="Component"&&f.variant==="button"&&t==="down"&&(this.onButtonClick&&this.onButtonClick(f.name,f.id),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"button",property:"click",value:!0})),(f.type==="ListView"||f.type==="Component"&&f.variant==="listview")&&t==="down"){this.draggingListViewId=f.id;const m=this.getListViewItemIndexAtPointer(f,i,o);if(m!==null){const y=f.options||{};y.activeItemIndex=m;const b=this.objectStates.get(f.id);b&&b.options&&(b.options.activeItemIndex=m);const v=(y.items||[])[m],S=typeof v=="string"?v:v.label||v.value||m;b&&b.options&&(b.options.selectedValue=S),f.inputId&&this.setInternalInput(f.inputId,S),this.onComponentChange&&(this.onComponentChange({objectId:f.id,componentName:f.name,variant:"listview",property:"activeItemIndex",value:m}),this.onComponentChange({objectId:f.id,componentName:f.name,variant:"listview",property:"selected",value:S}))}}if(f.type==="Component"&&f.variant==="slider"&&t==="down"&&(this.draggingSliderId=f.id,this.updateSliderValueFromPointer(f,i,o)),f.type==="Joystick"||f.type==="Component"&&f.variant==="joystick"){if(t==="down")this.draggingJoystickId=f.id,this.updateJoystickValueFromPointer(f,i,o);else if(t==="up"||t==="blur"){const m=this.objectStates.get(f.id);m&&f.isSpringReturn!==!1&&(m.handleX=0,m.handleY=0),f.isSpringReturn!==!1&&(f.handleX=0,f.handleY=0)}}if(f.type==="Component"&&f.variant==="checkbox"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{};y.checked=!y.checked,f.inputId&&this.setInternalInput(f.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"checkbox",property:"checked",value:y.checked}),this.fireEventForObject(f.id,"Click"),this.fireEventForObject(f.id,y.checked?"Checked":"Unchecked")}if(f.type==="Component"&&f.variant==="radiogroup"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{},b=y.optionsList||[],v=this.getRadioGroupItemIndexAtPointer(f,i,o);if(v!==null&&v>=0&&v<b.length){const S=b[v];y.selectedValue=S,f.inputId&&this.setInternalInput(f.inputId,S),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"radiogroup",property:"selectedValue",value:S}),this.fireEventForObject(f.id,"Click"),this.fireEventForObject(f.id,`Selected: ${S}`)}}if(f.type==="LineGraph"&&(t==="down"||t==="click")){const m=f.geometry,y=(m==null?void 0:m.datasets)||[],b=this.objectStates.get(f.id),v=(b==null?void 0:b.width)||(m==null?void 0:m.width)||200,S=(b==null?void 0:b.height)||(m==null?void 0:m.height)||150,C=this.getWorldTransform(f.id),w=30,M=20,I=v-w,k=S-M;let T=1;y.forEach(_=>{const A=Math.max(..._.data||[0]);A>T&&(T=A)});let O=1/0,P=null;y.forEach((_,A)=>{const x=_.data||[],W=I/Math.max(x.length-1,1);x.forEach((Y,B)=>{const X=C.x-v/2+w+B*W,q=C.y+S/2-M-Y/T*k,j=Math.sqrt((i-X)**2+(o-q)**2);j<O&&(O=j,P={dIdx:A,pIdx:B,val:Y,label:_.label||`Dataset ${A+1}`})})}),P&&O<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:f.id,componentName:f.name,datasetIndex:P.dIdx,pointIndex:P.pIdx,value:P.val,label:P.label}),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"linegraph",property:"click",value:(P==null?void 0:P.val)??null})}if(t==="click"){const m=(c=this.artboard)==null?void 0:c.objects.find(v=>v.id===e.id),y=this.focusedId,b=(m==null?void 0:m.type)==="InputBox"||(m==null?void 0:m.type)==="Component"&&m.variant==="inputbox";if(m&&b){if(this.focusedId=e.id,this.log(`[Engine] Focus set to: ${e.id}`),y!==this.focusedId){if(y){const v=(h=this.artboard)==null?void 0:h.objects.find(S=>S.id===y);v&&this.onInputBlur&&this.onInputBlur(v.name)}this.onInputFocus&&this.onInputFocus(m.name)}}else if(this.focusedId=null,y){const v=(r=this.artboard)==null?void 0:r.objects.find(S=>S.id===y);v&&this.onInputBlur&&this.onInputBlur(v.name)}}}else if(t==="click"){const f=this.focusedId;if(this.focusedId=null,f){const d=(u=this.artboard)==null?void 0:u.objects.find(p=>p.id===f);d&&this.onInputBlur&&this.onInputBlur(d.name)}}}handleKeyDown(t){if(!this.artboard||(this.activeKeys.add(t.key.toLowerCase()),this.activeKeys.add(t.code),!this.focusedId))return;const i=this.artboard.objects.find(a=>a.id===this.focusedId),o=(i==null?void 0:i.type)==="InputBox"||(i==null?void 0:i.type)==="Component"&&i.variant==="inputbox";if(!i||!o)return;const e=i.options||{};let s=e.text||"";if(t.key==="Backspace")s=s.slice(0,-1);else if(t.key==="Enter")if(e.multiline)s+=`
|
|
7
|
+
`;else{this.focusedId=null;return}else if(t.key.length===1)s+=t.key;else return;e.text=s;const n=i.geometry;n.textInputId&&this.updateInput(n.textInputId,s),this.onComponentChange&&this.onComponentChange({objectId:i.id,componentName:i.name,variant:"inputbox",property:"text",value:s}),this.onInputChange&&this.onInputChange(i.name,s),this.onInputUpdate&&this.onInputUpdate(this.focusedId,s)}handleKeyUp(t){this.artboard&&(this.activeKeys.delete(t.key.toLowerCase()),this.activeKeys.delete(t.code))}fireEventForObject(t,i){var h,r,u,f,d;const o=(h=this.artboard)==null?void 0:h.objects.find(p=>p.id===t);if(!o)return;const e=new Set([i,i.toLowerCase()]),s=i.toLowerCase();s==="onclick"||s==="click"||s==="onpointerdown"||s==="pointerdown"?this.fireAnalyticsEvent(t,"click"):(s==="onpointerenter"||s==="hover"||s==="move")&&this.fireAnalyticsEvent(t,"hover"),s==="onclick"||s==="click"?(e.add("click"),e.add("onclick")):s==="onpointerdown"||s==="pointerdown"?(e.add("pointerdown"),e.add("onpointerdown")):s==="onpointerup"||s==="pointerup"?(e.add("pointerup"),e.add("onpointerup")):s==="onpointerenter"||s==="hover"||s==="move"?(e.add("hover"),e.add("onpointerenter")):s==="onpointerleave"||s==="blur"?(e.add("onpointerleave"),e.add("blur")):s==="drag"||s==="ondrag"?(e.add("drag"),e.add("ondrag")):s==="toggle"||s==="ontoggle"?(e.add("toggle"),e.add("ontoggle")):s==="toggle true"||s==="toggle_true"||s==="toggletrue"?(e.add("toggle true"),e.add("toggle_true"),e.add("toggletrue")):(s==="toggle false"||s==="toggle_false"||s==="togglefalse")&&(e.add("toggle false"),e.add("toggle_false"),e.add("togglefalse"));const a=(o.interactions||[]).find(p=>{const m=p.triggers||[p.event||p.trigger||"click"];return((p.triggerLogic||"OR")==="AND"?m.every(v=>e.has(v.toLowerCase())):m.some(v=>e.has(v.toLowerCase())))?p.conditions&&p.conditions.length>0?this.checkConditions(p.conditions):!0:!1});if(a){if(this.log(`[Engine] Interaction matched: ${i} -> Action: ${a.action}`),a.action==="setInput"||a.action==="Set Input"){let p=a.value||a.inputValue;p==="toggle"&&(p=!this.inputs.get(a.targetInputId)),this.updateInput(a.targetInputId,p)}else if(a.action==="Toggle Boolean"){const p=this.inputs.get(a.targetInputId);this.updateInput(a.targetInputId,!p)}else if(a.action==="fireTrigger")this.updateInput(a.targetInputId,!0);else if(a.action==="setProperty"){const p=a.targetObjectId||o.id,m=a.targetProperty;m&&this.updateObjectProperty(p,m,a.value)}else if(a.action==="Navigate Artboard"||a.action==="navigate")this.onNavigation&&this.onNavigation({type:"artboard",value:a.targetArtboard||a.value});else if(a.action==="Navigate URL")this.onNavigation&&this.onNavigation({type:"url",value:a.navigateUrl});else if(a.action==="Play Animation"){const p=a.targetAnimationId,m=!a.playMode||a.playMode==="all"?void 0:a.subAnimationIds;p==="__all__"?(u=(r=this.artboard)==null?void 0:r.animations)==null||u.forEach(y=>{this.triggerGlobalAnimation(y.id,m)}):p&&this.triggerGlobalAnimation(p,m)}else if(a.action==="setState"||a.action==="Set State"){const p=a.targetObjectId||o.id,y={...this.objectStates.get(p)||{},...a.value||{}};this.objectStates.set(p,y),this.log(`[Engine] State updated for ${p}:`,y)}else if(a.action==="Stop Animation"||a.action==="Pause Animation"){const p=a.targetAnimationId;p==="__all__"?this.layerStates.forEach((m,y)=>{y.startsWith("global_")&&this.layerStates.delete(y)}):p&&this.layerStates.forEach((m,y)=>{y.startsWith(`global_${p}_`)&&this.layerStates.delete(y)})}else if(a.action==="Switch to State"&&this.activeStateMachine){const p=a.targetState,m=this.activeStateMachine.layers.find(y=>y.states.some(b=>b.id===p||b.name===p));m&&(this.log(`[Engine] Switching Layer ${m.name} to State ${p}`),this.enterStates(m.name,[p]))}this.onTrigger&&this.onTrigger(i,a.action)}const c=(o.triggers||[]).find(p=>{const m=p.eventType.toLowerCase();let y=!1;return(e.has(m)||m==="click"&&e.has("onclick")||m==="hover"&&(e.has("onpointerenter")||e.has("hover"))||m==="pointerdown"&&e.has("onpointerdown")||m==="pointerup"&&e.has("onpointerup"))&&(y=!0),y&&p.conditions&&p.conditions.length>0?this.checkConditions(p.conditions):y});if(c&&c.entryAnimationId){this.log(`[Engine] Trigger matched: ${i} (as ${c.eventType}) -> Animation ${c.entryAnimationId}`);const p=(d=(f=this.artboard)==null?void 0:f.animations)==null?void 0:d.find(m=>m.id===c.entryAnimationId);p&&(this.activeTriggers.set(o.id,{triggerId:c.id,animation:p,time:0,phase:"entry",elapsedHold:0,filterObjectId:c.targetObjectId}),this.onTrigger&&this.onTrigger(c.name,p.name))}}fireAnalyticsEvent(t,i){var l,c;const o=(l=this.artboard)==null?void 0:l.objects.find(h=>h.id===t);if(!o)return;const e=(c=o.style)==null?void 0:c.analytics;if(!e||!e.isEnabled||e.triggerType!==i)return;const s=e.eventName||`${o.name.toLowerCase().replace(/\s+/g,"_")}_interacted`,n={};e.parameters&&Array.isArray(e.parameters)&&e.parameters.forEach(h=>{if(h.type==="literal")n[h.key]=h.value;else if(h.type==="variable"){const r=this.inputs.get(h.value);n[h.key]=r!==void 0?r:""}}),this.log(`[ExodeUI Analytics] Dispatching event "${s}" via ${i} trigger:`,n);const a=e.platforms||{ga4:!0,meta:!0,mixpanel:!1};if(a.ga4){const h=window;typeof h.gtag=="function"?(h.gtag("event",s,n),this.log(`[ExodeUI Analytics] GA4: Event "${s}" sent successfully.`)):this.warn(`[ExodeUI Analytics] GA4: window.gtag is not a function. Event "${s}" skipped.`)}if(a.meta){const h=window;typeof h.fbq=="function"?(h.fbq("track",s,n),this.log(`[ExodeUI Analytics] Meta Pixel: Event "${s}" sent successfully.`)):this.warn(`[ExodeUI Analytics] Meta Pixel: window.fbq is not a function. Event "${s}" skipped.`)}if(a.mixpanel){const h=window;h.mixpanel&&typeof h.mixpanel.track=="function"?(h.mixpanel.track(s,n),this.log(`[ExodeUI Analytics] Mixpanel: Event "${s}" sent successfully.`)):this.warn(`[ExodeUI Analytics] Mixpanel: window.mixpanel.track is not a function. Event "${s}" skipped.`)}}initGlobalAnimationTriggers(){if(!this.artboard)return;const t=this.artboard.animationFlow||[];let i=!1;t.forEach(o=>{if((o.trigger==="on_load"||o.trigger==="after_delay")&&o.targetAnimationId){i=!0;const e=o.delay||0;e<=0?this.triggerGlobalAnimation(o.targetAnimationId,o.subAnimationIds,o.loop,o.id):setTimeout(()=>this.triggerGlobalAnimation(o.targetAnimationId,o.subAnimationIds,o.loop,o.id),e)}}),!i&&this.artboard.startupAnimationId&&this.triggerGlobalAnimation(this.artboard.startupAnimationId,this.artboard.startupSubAnimationIds)}triggerGlobalAnimation(t,i,o=!1,e){if(!this.artboard)return;const s=this.artboard.animations.find(a=>a.id===t);if(!s)return;const n=`global_${t}_${Math.random().toString(36).substr(2,5)}`;this.layerStates.set(n,{currentStateIds:[t],animations:[{animation:s,state:{loop:o},filterObjectIds:i}],time:0,duration:s.duration,ruleId:e}),this.debugLog(`[Engine] Triggered global animation: ${s.name} (Loop: ${o}, Sub-Anims: ${(i==null?void 0:i.length)||"All"})`)}handleAnimationFinished(t,i){if(!this.artboard)return;(this.artboard.animationFlow||[]).forEach(e=>{if(e.trigger==="after_anim"&&e.targetAnimationId&&(e.afterAnim===t||i&&e.afterAnim===i)){const n=e.delay||0;n<=0?this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id):setTimeout(()=>this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id),n)}})}getWorldTransform(t){var u;const i=this.objectStates.get(t);if(!i)return{x:0,y:0,scaleX:1,scaleY:1,rotation:0};const o=(u=this.artboard)==null?void 0:u.objects.find(f=>f.id===t);if(!o||!o.parentId)return{x:i.x,y:i.y,scaleX:i.scale_x??1,scaleY:i.scale_y??1,rotation:i.rotation??0};const e=this.getWorldTransform(o.parentId),s=e.rotation*(Math.PI/180),n=Math.cos(s),a=Math.sin(s),l=i.x*e.scaleX,c=i.y*e.scaleY,h=e.x+(l*n-c*a),r=e.y+(l*a+c*n);return{x:h,y:r,scaleX:(i.scale_x??1)*e.scaleX,scaleY:(i.scale_y??1)*e.scaleY,rotation:e.rotation+(i.rotation??0)}}hitTest(t,i,o){var v,S;if(!this.objectStates.get(t.id))return!1;const s=((v=t.geometry)==null?void 0:v.width)??t.width??100,n=((S=t.geometry)==null?void 0:S.height)??t.height??100,a=this.getWorldTransform(t.id),l=i-a.x,c=o-a.y,h=-a.rotation*(Math.PI/180),r=Math.cos(h),u=Math.sin(h),f=l*r-c*u,d=l*u+c*r,p=a.scaleX,m=a.scaleY,y=s*Math.abs(p),b=n*Math.abs(m);return Math.abs(f)<=y/2&&Math.abs(d)<=b/2}updateSliderValueFromPointer(t,i,o){var M;const e=this.objectStates.get(t.id);if(!e)return;const s=t.options||{},n=((M=t.geometry)==null?void 0:M.width)??t.width??200,a=this.getWorldTransform(t.id),l=i-a.x,c=o-a.y,h=-a.rotation*(Math.PI/180),r=Math.cos(h),u=Math.sin(h),f=l*r-c*u,d=s.thumbWidth??16,p=n-d;let y=(f+p/2)/p;y=Math.max(0,Math.min(1,y));const b=s.min??0,v=s.max??100,S=s.step||1;let C=b+y*(v-b);S>0&&(C=Math.round(C/S)*S),C=Math.max(b,Math.min(v,C));const w=e.options||{};w.value!==C&&(e.options={...w,value:C},t.inputId&&this.setInternalInput(t.inputId,C),this.onComponentChange&&this.onComponentChange({objectId:t.id,componentName:t.name,variant:"slider",property:"value",value:C}))}updateJoystickValueFromPointer(t,i,o){var M,I;const e=this.objectStates.get(t.id);if(!e)return;const s=(e==null?void 0:e.width)!==void 0?e.width:((M=t.geometry)==null?void 0:M.width)??t.width??100,n=(e==null?void 0:e.height)!==void 0?e.height:((I=t.geometry)==null?void 0:I.height)??t.height??100,a=this.getWorldTransform(t.id),l=i-a.x,c=o-a.y,h=-a.rotation*(Math.PI/180),r=Math.cos(h),u=Math.sin(h);let f=(l*r-c*u)/Math.max(.001,Math.abs(a.scaleX||1)),d=(l*u+c*r)/Math.max(.001,Math.abs(a.scaleY||1));t.handleOrigin==="top-left"?(f-=s/2,d-=n/2):t.handleOrigin==="bottom-right"&&(f+=s/2,d+=n/2);const p=Math.min(s,n)*.45,m=Math.min(s,n)*.15,y=p-m;let b=f/y,v=d/y;const S=Math.sqrt(b*b+v*v);t.boundsShape==="square"?(b=Math.max(-1,Math.min(1,b)),v=Math.max(-1,Math.min(1,v))):S>1&&(b/=S,v/=S),t.deadzone!==void 0&&S<t.deadzone?(b=0,v=0):(t.stepX!==void 0&&t.stepX>0&&(b=Math.round(b/t.stepX)*t.stepX),t.stepY!==void 0&&t.stepY>0&&(v=Math.round(v/t.stepY)*t.stepY)),t.joystickType==="1D_X"?v=0:t.joystickType==="1D_Y"&&(b=0);const C=e.handleX,w=e.handleY;(C!==b||w!==v)&&(e.handleX=b,e.handleY=v,t.handleX=b,t.handleY=v)}processJoysticks(t){this.artboard&&(this.artboard.objects.forEach(i=>{var a,l;if(i.type!=="Joystick"&&!(i.type==="Component"&&i.variant==="joystick"))return;const o=i,e=this.objectStates.get(o.id);if(!e)return;let s=e.handleX??o.handleX??0,n=e.handleY??o.handleY??0;if(((a=o.inputBinding)==null?void 0:a.type)==="keyboard"&&o.inputBinding.keyboardConfig){const c=o.inputBinding.keyboardConfig;let h=s,r=n;const f=(c.speed||5)*t;let d=!1;this.activeKeys.has(c.upKey.toLowerCase())&&(r-=f,d=!0),this.activeKeys.has(c.downKey.toLowerCase())&&(r+=f,d=!0),this.activeKeys.has(c.leftKey.toLowerCase())&&(h-=f,d=!0),this.activeKeys.has(c.rightKey.toLowerCase())&&(h+=f,d=!0),o.joystickType==="1D_X"&&(r=0),o.joystickType==="1D_Y"&&(h=0);const p=Math.sqrt(h*h+r*r);p>1&&(h/=p,r/=p),!d&&o.isSpringReturn!==!1&&(h+=(0-h)*(10*t),r+=(0-r)*(10*t),Math.abs(h)<.01&&(h=0),Math.abs(r)<.01&&(r=0)),s=h,n=r}else if(((l=o.inputBinding)==null?void 0:l.type)==="mouse"&&o.inputBinding.mouseConfig){const c=o.inputBinding.mouseConfig;let h=s,r=n;const u=c.sensitivity||.01,f=Math.abs(this._mouseDelta.dx)>0||Math.abs(this._mouseDelta.dy)>0;c.axisX&&(h+=this._mouseDelta.dx*u),c.axisY&&(r+=this._mouseDelta.dy*u),o.joystickType==="1D_X"&&(r=0),o.joystickType==="1D_Y"&&(h=0);const d=Math.sqrt(h*h+r*r);d>1&&(h/=d,r/=d),!f&&o.isSpringReturn!==!1&&(h+=(0-h)*(10*t),r+=(0-r)*(10*t),Math.abs(h)<.01&&(h=0),Math.abs(r)<.01&&(r=0)),s=h,n=r}if(e.handleX=s,e.handleY=n,o.handleX=s,o.handleY=n,o.bindings&&o.bindings.length>0){const c=Math.sqrt(s*s+n*n);let h=Math.atan2(n,s)*(180/Math.PI);h<0&&(h+=360),o.bindings.forEach(r=>{var d,p,m,y,b,v,S,C;let u=0;r.sourceAxis==="x"?u=o.invertX?-s:s:r.sourceAxis==="y"?u=o.invertY?-n:n:r.sourceAxis==="distance"?u=c:r.sourceAxis==="angle"&&(u=h);const f=(d=this.artboard)==null?void 0:d.objects.find(w=>w.id===r.targetObjectId);if(f){if(r.actionType==="bind"&&r.targetProperty&&r.isContinuous!==!1){const w=r.sourceMin??-1,M=r.sourceMax??1,I=r.targetMin??0,k=r.targetMax??100;let T=!!r.isContinuous,O=0,P=0;if(T){if((r.sourceAxis==="x"||r.sourceAxis==="y")&&I>=0){const A=Math.max(Math.abs(w),Math.abs(M))||1;P=u/A*k}else{let A=(u-w)/(M-w);A=Math.max(0,Math.min(1,A)),P=I+A*(k-I)}Math.abs(u)<.05&&(P=0)}else{const A=(u-w)/(M-w),x=Math.max(0,Math.min(1,A));O=I+x*(k-I),r.step&&r.step>0&&(O=Math.round(O/r.step)*r.step)}const _=this.objectStates.get(f.id);if(_){const A=r.isRelative!==!1,x=A?((p=f.transform)==null?void 0:p.x)??0:0,W=A?((m=f.transform)==null?void 0:m.y)??0:0,Y=A?((y=f.transform)==null?void 0:y.rotation)??0:0,B=A?((b=f.transform)==null?void 0:b.scale_x)??1:0,X=A?((v=f.transform)==null?void 0:v.scale_y)??1:0,q=A?((S=f.style)==null?void 0:S.opacity)??100:0,j=t*60,E=(L,G)=>{let z=O;if(T){const it=`_internal_${L}_${r.id}`;let F=_[it];F===void 0&&(F=_[L]??G),z=F+P*j,_[it]=z,r.step&&r.step>0&&(z=Math.round(z/r.step)*r.step)}else z=G+O;_[L]=z};r.targetProperty==="x"||r.targetProperty==="transform.x"?E("x",x):r.targetProperty==="y"||r.targetProperty==="transform.y"?E("y",W):r.targetProperty==="rotation"||r.targetProperty==="r"||r.targetProperty==="transform.rotation"?E("rotation",Y):r.targetProperty==="scaleX"||r.targetProperty==="transform.scale_x"?E("scale_x",B):r.targetProperty==="scaleY"||r.targetProperty==="transform.scale_y"?E("scale_y",X):(r.targetProperty==="opacity"||r.targetProperty==="transform.opacity")&&E("opacity",q)}(C=f.physics)!=null&&C.enabled&&this.physicsEngine&&(r.targetProperty==="x"||r.targetProperty==="transform.x"||r.targetProperty==="y"||r.targetProperty==="transform.y")&&(r.targetProperty==="x"||r.targetProperty==="transform.x"?this.physicsEngine.applyForce(f.id,(O-((_==null?void 0:_.x)||0))*10,0):(r.targetProperty==="y"||r.targetProperty==="transform.y")&&this.physicsEngine.applyForce(f.id,0,(O-((_==null?void 0:_.y)||0))*10))}else if(r.actionType==="playAnimation"||r.actionType==="stopAnimation"||r.actionType==="pauseAnimation"){let w=!1;const M=r.threshold??0;r.condition==="always"?w=!0:r.condition===">"?w=u>M:r.condition==="<"?w=u<M:r.condition==="=="&&(w=Math.abs(u-M)<.01);const I=e[`_prev_src_${r.id}`]??u;let k=!1;r.condition==="always"?k=!0:r.condition===">"?k=I>M:r.condition==="<"?k=I<M:r.condition==="=="&&(k=Math.abs(I-M)<.01),e[`_prev_src_${r.id}`]=u,w&&!k&&r.targetAnimationId&&(r.actionType==="playAnimation"||r.actionType)}}})}}),this._mouseDelta.dx=0,this._mouseDelta.dy=0)}applyBlendState(t,i){var c,h,r,u,f,d,p,m;if(!t.blendAnimations||t.blendAnimations.length===0)return;let o=0,e=0;t.blendInputX&&(o=this.inputs.get(t.blendInputX)??0),t.blendInputY&&(e=this.inputs.get(t.blendInputY)??0);const s=[];let n=0;if(t.blendType==="1D"){const y=[...t.blendAnimations].sort((b,v)=>b.position[0]-v.position[0]);if(y.length===1){const b=(h=(c=this.artboard)==null?void 0:c.animations)==null?void 0:h.find(v=>v.id===y[0].animationId);b&&(s.push({anim:b,weight:1}),n=1)}else{let b=0;for(;b<y.length-1&&y[b+1].position[0]<o;)b++;if(b===y.length-1&&o>y[b].position[0]){const v=(u=(r=this.artboard)==null?void 0:r.animations)==null?void 0:u.find(S=>S.id===y[b].animationId);v&&(s.push({anim:v,weight:1}),n=1)}else{const v=y[b].position[0],S=y[b+1].position[0],C=(d=(f=this.artboard)==null?void 0:f.animations)==null?void 0:d.find(T=>T.id===y[b].animationId),w=(m=(p=this.artboard)==null?void 0:p.animations)==null?void 0:m.find(T=>T.id===y[b+1].animationId),M=Math.max(.001,S-v);let I=(o-v)/M;I=Math.max(0,Math.min(1,I));const k=1-I;C&&(s.push({anim:C,weight:k}),n+=k),w&&(s.push({anim:w,weight:I}),n+=I)}}}else t.blendAnimations.forEach(y=>{var w,M;const b=(M=(w=this.artboard)==null?void 0:w.animations)==null?void 0:M.find(I=>I.id===y.animationId);if(!b)return;const v=y.position[0]-o,S=y.position[1]-e,C=v*v+S*S;if(C<1e-4)s.push({anim:b,weight:1e4}),n+=1e4;else{const I=1/C;s.push({anim:b,weight:I}),n+=I}});if(n===0)return;s.forEach(y=>y.weight/=n);const a=new Map,l=y=>{let b=y.startsWith("#")?y.substring(1):y;return b.length===3&&(b=[b[0],b[0],b[1],b[1],b[2],b[2]].join("")),b="0x"+b,{r:b>>16&255,g:b>>8&255,b:b&255,a:1}};s.forEach(({anim:y,weight:b})=>{y.tracks&&y.tracks.forEach(v=>{var O,P;const S=v.object_id||v.objectId,C=v.property,w=(O=this.artboard)==null?void 0:O.objects.find(_=>_.id===S);if(((P=w==null?void 0:w.physics)==null?void 0:P.enabled)&&w.physics.bodyType!=="Static"&&(C==="x"||C==="y"||C==="rotation"))return;const I=this.interpolate(v.keyframes,i);if(I===void 0)return;let k=a.get(S);k||(k=new Map,a.set(S,k));let T=k.get(C);if(!T){if(typeof I=="number")T={type:"number",value:0};else if(typeof I=="string"&&I.startsWith("#"))T={type:"color",value:I,colorAcc:{r:0,g:0,b:0,a:0}};else if(T={type:"number",value:I},b<.5)return;k.set(C,T)}if(T.type==="number"&&typeof I=="number")T.value+=I*b;else if(T.type==="color"&&typeof I=="string"&&T.colorAcc){const _=l(I);_&&(T.colorAcc.r+=_.r*b,T.colorAcc.g+=_.g*b,T.colorAcc.b+=_.b*b,T.colorAcc.a+=_.a*b)}else b>.5&&(T.value=I)})}),a.forEach((y,b)=>{var C;const v=this.objectStates.get(b),S=(C=this.artboard)==null?void 0:C.objects.find(w=>w.id===b);!v||!S||y.forEach((w,M)=>{let I=w.value;if(w.type==="color"&&w.colorAcc){const k=Math.round(w.colorAcc.r).toString(16).padStart(2,"0"),T=Math.round(w.colorAcc.g).toString(16).padStart(2,"0"),O=Math.round(w.colorAcc.b).toString(16).padStart(2,"0");I=`#${k}${T}${O}`}if(M.includes(".")){const k=(M||"").split(".");let T=v;for(let O=0;O<k.length-1;O++){if(typeof T[k[O]]!="object"||T[k[O]]===null){let P=S;for(let _=0;_<=O;_++)P=P?P[k[_]]:null;if(k[O]==="corner_radius"||k[O]==="cornerRadius"){const _=typeof T[k[O]]=="number"?T[k[O]]:typeof P=="number"?P:0;T[k[O]]={tl:_,tr:_,bl:_,br:_}}else T[k[O]]=P?JSON.parse(JSON.stringify(P)):{}}T=T[k[O]]}T[k[k.length-1]]=I,k[k.length-1]==="color"&&(k[k.length-2]==="fill"||k[k.length-2]==="stroke")&&(T.type="Solid")}else M==="fill"?(v.style||(v.style={}),v.style.fill=I):M==="stroke"?(v.style||(v.style={}),v.style.stroke=I):v[M]=I})})}applyAnimation(t,i,o){!t||!t.tracks||t.tracks.forEach(e=>{var r,u,f;const s=e.object_id||e.objectId;if(o){if(Array.isArray(o)){if(!o.includes(s))return}else if(s!==o)return}const n=(r=this.artboard)==null?void 0:r.objects.find(d=>d.id===s),a=((u=n==null?void 0:n.physics)==null?void 0:u.enabled)&&n.physics.bodyType!=="Static";let l=e.property;if(a&&(l==="x"||l==="y"||l==="rotation"))return;const c=this.objectStates.get(s);if(!c){this.frameCount%600===0&&this.debugLog(`Skipping track: Object ${s} not found in state`);return}const h=this.interpolate(e.keyframes,i);if(h!==void 0){if(this.frameCount%240===0){const d=(n==null?void 0:n.name)||s,p=typeof h=="object"?JSON.stringify(h).slice(0,50):h;this.debugLog(`[Anim] Applying ${l} = ${p} to ${d}`)}if(l.includes(".")){const d=(l||"").split(".");let p=c;for(let m=0;m<d.length-1;m++){if(typeof p[d[m]]!="object"||p[d[m]]===null){let y=n;for(let b=0;b<=m;b++)y=y?y[d[b]]:null;if(d[m]==="corner_radius"||d[m]==="cornerRadius"){const b=typeof p[d[m]]=="number"?p[d[m]]:typeof y=="number"?y:0;p[d[m]]={tl:b,tr:b,bl:b,br:b}}else p[d[m]]=y?JSON.parse(JSON.stringify(y)):{}}p=p[d[m]]}p[d[d.length-1]]=h,d[d.length-1]==="color"&&(d[d.length-2]==="fill"||d[d.length-2]==="stroke")&&(p.type="Solid")}else l==="fill"?(c.style||(c.style={}),c.style.fill=h):l==="stroke"?(c.style||(c.style={}),c.style.stroke=h):c[l]=h;if(this.physicsEngine&&((f=n==null?void 0:n.physics)!=null&&f.enabled)&&n.physics.bodyType==="Static")if(l==="x"){const d=this.physicsEngine.getPosition(s);d&&this.physicsEngine.setPosition(s,h,d.y)}else if(l==="y"){const d=this.physicsEngine.getPosition(s);d&&this.physicsEngine.setPosition(s,d.x,h)}else l==="rotation"&&this.physicsEngine.setRotation(s,h*(Math.PI/180))}})}interpolate(t,i){if(t.length===0)return;let o=t[0],e=t[t.length-1];if(i<=o.time)return o.value;if(i>=e.time)return e.value;for(let a=0;a<t.length-1;a++)if(i>=t[a].time&&i<t[a+1].time){o=t[a],e=t[a+1];break}const s=e.time-o.time;let n=(i-o.time)/s;if(o.easing&&(n=si(o.easing)(n)),typeof o.value=="string"){if(o.value.startsWith("#"))return this.interpolateColor(o.value,e.value,n);const a=parseFloat(o.value),l=parseFloat(e.value);return!isNaN(a)&&!isNaN(l)?Math.round(a+(l-a)*n).toString():o.value}if(Array.isArray(o.value)&&Array.isArray(e.value))return o.value.length===e.value.length?o.value.map((a,l)=>{const c=e.value[l];return typeof a=="number"&&typeof c=="number"?a+(c-a)*n:n<.5?a:c}):n<.5?o.value:e.value;if(typeof o.value=="object"&&typeof e.value=="object"&&o.value!==null&&e.value!==null){if(o.value.width!==void 0&&o.value.color!==void 0)return this.interpolateStroke(o.value,e.value,n);if(o.value.type&&e.value.type)return this.interpolateFill(o.value,e.value,n);const a={};return new Set([...Object.keys(o.value),...Object.keys(e.value)]).forEach(c=>{const h=o.value[c],r=e.value[c];typeof h=="number"&&typeof r=="number"?a[c]=h+(r-h)*n:h===void 0?a[c]=r:r===void 0?a[c]=h:a[c]=n<.5?h:r}),a}return typeof o.value=="number"&&typeof e.value=="number"?o.value+(e.value-o.value)*n:n<.5?o.value:e.value}interpolateColor(t,i,o){var d,p;const e=((p=(d=this.artboard)==null?void 0:d.tokens)==null?void 0:p.colors)||{},s=e[t]||t,n=e[i]||i,a=m=>{if(!m)return{r:0,g:0,b:0};const y=m.startsWith("#")?m.replace("#",""):"000000";return y.length===3?{r:parseInt(y[0]+y[0],16),g:parseInt(y[1]+y[1],16),b:parseInt(y[2]+y[2],16)}:{r:parseInt(y.substring(0,2),16),g:parseInt(y.substring(2,4),16),b:parseInt(y.substring(4,6),16)}},l=a(s),c=a(n),h=Math.round(l.r+(c.r-l.r)*o),r=Math.round(l.g+(c.g-l.g)*o),u=Math.round(l.b+(c.b-l.b)*o),f=m=>{const y=Math.max(0,Math.min(255,m)).toString(16);return y.length===1?"0"+y:y};return`#${f(h)}${f(r)}${f(u)}`}interpolateStops(t,i,o){return!t||!i||t.length!==i.length?o<.5?t:i:t.map((e,s)=>{const n=i[s];return{offset:e.offset+(n.offset-e.offset)*o,color:this.interpolateColor(e.color,n.color,o),opacity:(e.opacity??1)+((n.opacity??1)-(e.opacity??1))*o}})}interpolateFill(t,i,o){if(!t||!i||t.type!==i.type)return o<.5?t:i;const e={...t,opacity:(t.opacity??1)+((i.opacity??1)-(t.opacity??1))*o};return t.type==="Solid"?e.color=this.interpolateColor(t.color,i.color,o):(t.type==="LinearGradient"||t.type==="RadialGradient")&&(t.start&&i.start&&(e.start=[t.start[0]+(i.start[0]-t.start[0])*o,t.start[1]+(i.start[1]-t.start[1])*o]),t.end&&i.end&&(e.end=[t.end[0]+(i.end[0]-t.end[0])*o,t.end[1]+(i.end[1]-t.end[1])*o]),t.center&&i.center&&(e.center=[t.center[0]+(i.center[0]-t.center[0])*o,t.center[1]+(i.center[1]-t.center[1])*o]),t.radius!==void 0&&i.radius!==void 0&&(e.radius=t.radius+(i.radius-t.radius)*o),e.stops=this.interpolateStops(t.stops,i.stops,o)),e}interpolateStroke(t,i,o){if(!t||!i)return o<.5?t:i;const e={...t};return e.width=(t.width??0)+((i.width??0)-(t.width??0))*o,e.opacity=(t.opacity??1)+((i.opacity??1)-(t.opacity??1))*o,t.fill&&i.fill?e.fill=this.interpolateFill(t.fill,i.fill,o):t.color&&i.color&&t.color.startsWith("#")&&i.color.startsWith("#")&&(e.color=this.interpolateColor(t.color,i.color,o)),e.trimStart=(t.trimStart??0)+((i.trimStart??0)-(t.trimStart??0))*o,e.trimEnd=(t.trimEnd??1)+((i.trimEnd??1)-(t.trimEnd??1))*o,e.trimOffset=(t.trimOffset??0)+((i.trimOffset??0)-(t.trimOffset??0))*o,e.dashOffset=(t.dashOffset??0)+((i.dashOffset??0)-(t.dashOffset??0))*o,e}render(t,i,o){var r;this.debug_objectsTotal=((r=this.artboard)==null?void 0:r.objects.length)||0,this.debug_objectsRendered=0;const e=performance.now();if(this.canvasWidth=i,this.canvasHeight=o,!this.artboard)return;t.clearRect(0,0,i,o);const s=this.artboard.width,n=this.artboard.height,a=this.calculateTransform(i,o,s,n,this.layout.fit,this.layout.alignment);if(t.save(),t.translate(Math.round(a.tx),Math.round(a.ty)),t.scale(a.scaleX,a.scaleY),this.rootTransform=t.getTransform(),this.artboard.backgroundVisible!==!1&&(t.fillStyle=this.artboard.backgroundColor||"#000000",t.fillRect(0,0,s,n)),this.artboard.backgroundImage){const u=this.artboard.backgroundImage;let f=this.imageCache.get(u);if(f||(f=new Image,f.src=u,this.imageCache.set(u,f)),f.complete&&f.naturalWidth>0){t.save(),t.globalAlpha=this.normalizeOpacity(this.artboard.backgroundOpacity??100);const d=f.naturalWidth/f.naturalHeight,p=s/n;let m,y,b,v;p>d?(m=s,y=s/d):(y=n,m=n*d),b=(s-m)/2,v=(n-y)/2,t.drawImage(f,b,v,m,y),t.restore()}}(this.artboard.clipContent===!0||this.artboard.clip_content===!0)&&(t.beginPath(),t.rect(0,0,s,n),t.clip());const c=new Map;this.artboard.objects.forEach(u=>c.set(u.id,u)),this.artboard.objects.filter(u=>!u.parentId).map((u,f)=>{const d=this.objectStates.get(u.id),p=(d==null?void 0:d.zIndex)??f;return{obj:u,zIndex:p}}).sort((u,f)=>u.zIndex-f.zIndex).forEach(({obj:u})=>{this.renderObject(t,u,c)}),this._emitterPools.forEach((u,f)=>{if(!(u.length===0||!c.get(f)))for(const p of u)t.save(),t.globalAlpha=p.opacity,t.fillStyle=p.color,t.beginPath(),t.arc(p.x,p.y,Math.max(1,p.size*p.opacity),0,Math.PI*2),t.fill(),t.restore()}),this.lastRenderTime=performance.now()-e,this.debugMode&&this.frameCount%60===0&&this.log(`[Engine Debug] Rendered ${this.debug_objectsRendered}/${this.debug_objectsTotal} objects in ${this.lastRenderTime.toFixed(2)}ms`),t.restore()}isObjectInView(t,i,o,e,s,n=0){const a=t.getTransform(),l=i*a.a+o*a.c+a.e,c=i*a.b+o*a.d+a.f,h=Math.sqrt(a.a*a.a+a.b*a.b),r=Math.sqrt(a.c*a.c+a.d*a.d),u=(e/2+n)*h,f=(s/2+n)*r;return l+u>=0&&l-u<=this.canvasWidth&&c+f>=0&&c-f<=this.canvasHeight}calculateTransform(t,i,o,e,s,n){let a=1,l=1,c=1;const h=o/e,r=t/i;switch(s){case"Contain":r>h?c=i/e:c=t/o,a=l=c;break;case"Cover":r>h?c=t/o:c=i/e,a=l=c;break;case"Fill":a=t/o,l=i/e;break;case"FitWidth":c=t/o,a=l=c;break;case"FitHeight":c=i/e,a=l=c;break;case"None":a=l=1;break;case"ScaleDown":c=Math.min(t/o,i/e),c>1&&(c=1),a=l=c;break;default:a=l=1;break}const u=o*a,f=e*l;let d=0,p=0;return n.includes("Left")?d=0:n.includes("Right")?d=t-u:d=(t-u)/2,n.includes("Top")?p=0:n.includes("Bottom")?p=i-f:p=(i-f)/2,{scaleX:a,scaleY:l,tx:d,ty:p}}mapFontWeight(t){const i=t.toLowerCase();return i==="thin"||i==="100"?"100":i==="extralight"||i==="200"?"200":i==="light"||i==="300"?"300":i==="regular"||i==="normal"||i==="400"?"400":i==="medium"||i==="500"?"500":i==="semibold"||i==="600"?"600":i==="bold"||i==="700"?"700":i==="extrabold"||i==="800"?"800":i==="black"||i==="900"?"900":t}drawTextDecoration(t,i,o,e,s,n){t.beginPath();const a=Math.max(1,n/14);let l=e;i==="underline"?l=e+n*.12:i==="line-through"&&(l=e-n*.3),t.lineWidth=a,t.strokeStyle=t.fillStyle,t.moveTo(o-s/2,l),t.lineTo(o+s/2,l),t.stroke()}renderObject(t,i,o){var p,m,y,b,v,S,C,w,M,I,k,T,O,P,_,A,x,W,Y,B,X,q,j,E,L;const e=this.objectStates.get(i.id);if(!e){this.warn("No state for object:",i.id);return}this.frameCount%60,t.roundRect||(t.roundRect=(G,z,it,F,$)=>(this.drawRoundRect(t,G,z,it,F,$),t));const s=e.geometry?this.deepMerge(i.geometry,e.geometry):i.geometry,n=e.style?this.deepMerge(i.style,e.style):i.style;let a=(s==null?void 0:s.width)||((p=i.geometry)==null?void 0:p.width)||i.width||0,l=(s==null?void 0:s.height)||((m=i.geometry)==null?void 0:m.height)||i.height||0;if((a===0||l===0)&&(s!=null&&s.points)&&Array.isArray(s.points)&&s.points.length>0){let G=1/0,z=-1/0,it=1/0,F=-1/0;s.points.forEach($=>{G=Math.min(G,$.x),z=Math.max(z,$.x),it=Math.min(it,$.y),F=Math.max(F,$.y)}),a===0&&(a=z-G),l===0&&(l=F-it)}const c=G=>{if(G)return G.corner_radius??G.cornerRadius},h=c(e)??c(n)??c(s)??c(i.style)??c(i.geometry)??0;let r={...s,width:a,height:l};if(delete r.cornerRadius,r.corner_radius=h,r.type==="Path"&&i.weights&&i.bindMatrices&&r.points){const G=this.getGlobalTransform(i.id);if(G){const z=ii(r.points,i.weights,i.bindMatrices,G,it=>this.getGlobalTransform(it));r={...r,points:z}}}if(e.visible===!1)return;const u=i.repeaterConfig,f=u&&u.isEnabled&&u.count>1,d=f?u.count:1;for(let G=0;G<d;G++){let z=e.x!==void 0?e.x:((y=e.transform)==null?void 0:y.x)??0,it=e.y!==void 0?e.y:((b=e.transform)==null?void 0:b.y)??0,F=e.rotation!==void 0?e.rotation:((v=e.transform)==null?void 0:v.rotation)??0,$=e.scale_x!==void 0?e.scale_x:((S=e.transform)==null?void 0:S.scale_x)??1,V=e.scale_y!==void 0?e.scale_y:((C=e.transform)==null?void 0:C.scale_y)??1;if(f&&G>0){if(u.type==="Linear"){const ft=u.offsetX||0,bt=u.offsetY||0,st=u.rotation||0,H=u.scale!==void 0?u.scale:1;z+=G*ft,it+=G*bt,F+=G*st,$*=Math.pow(H,G),V*=Math.pow(H,G)}else if(u.type==="Grid"){const ft=u.cols||Math.ceil(Math.sqrt(u.count)),bt=u.gapX||0,st=u.gapY||0,H=Math.floor(G/ft),N=G%ft,ot=a+bt,vt=l+st;z+=N*ot,it+=H*vt}else if(u.type==="Radial"){const ft=u.radius||100,bt=u.startAngle||0,H=(u.endAngle||360)-bt,N=u.count>1?H/(H===360?u.count:u.count-1):0,ot=bt+G*N,vt=ot*Math.PI/180;z=e.x+ft*Math.cos(vt),it=e.y+ft*Math.sin(vt),F+=ot}}const tt=i.type==="Group"||i.type==="Frame"||i.type==="Component",rt=a>0&&l>0;if(!tt&&rt){const ft=(((w=n.shadow)==null?void 0:w.isEnabled)!==!1?(((M=n.shadow)==null?void 0:M.blur)||0)+10:0)+(((I=n.blur)==null?void 0:I.isEnabled)!==!1&&((k=n.blur)==null?void 0:k.radius)||0)+20;if(!this.isObjectInView(t,z,it,a,l,ft))continue}this.debug_objectsRendered++,t.save();const mt=[],Ct=n.blur||((T=i.style)==null?void 0:T.blur);Ct&&Ct.amount>0&&mt.push(`blur(${Ct.amount}px)`);const ct=n.effect||((O=i.style)==null?void 0:O.effect),Pt=(ct==null?void 0:ct.isEnabled)===!0,kt=ct==null?void 0:ct.type,Tt=(ct==null?void 0:ct.radius)??10;Pt&&kt==="LayerBlur"&&mt.push(`blur(${Tt}px)`);const zt=((P=s==null?void 0:s.type)==null?void 0:P.toLowerCase().includes("image"))||((_=i.type)==null?void 0:_.toLowerCase().includes("image")),et=n.adjustments&&Object.keys(n.adjustments).length>0?n.adjustments:null,yt=s!=null&&s.adjustments&&Object.keys(s.adjustments).length>0?s.adjustments:null,Ot=zt?yt||et:et||yt,gt=zt&&!Ot?{exposure:0,contrast:0,saturation:100,temperature:0,tint:0,highlights:0,shadows:0,blur:0,negative:0,hue:0}:Ot;if(e&>&&(e.geometry=e.geometry||{},e.geometry.adjustments={...gt}),gt){const ft=(gt.exposure||0)/100,bt=gt.contrast||0,st=1+(gt.saturation||0)/100,H=(gt.temperature||0)/200,N=(gt.tint||0)/200,ot=(gt.highlights||0)/500,vt=(gt.shadows||0)/500;let xt="",It="SourceGraphic";if(ft!==0&&(xt+=`
|
|
8
|
+
<feComponentTransfer in="${It}" result="exposure">
|
|
9
|
+
<feFuncR type="linear" slope="1" intercept="${ft}"/>
|
|
10
|
+
<feFuncG type="linear" slope="1" intercept="${ft}"/>
|
|
11
|
+
<feFuncB type="linear" slope="1" intercept="${ft}"/>
|
|
12
|
+
</feComponentTransfer>`,It="exposure"),bt!==0){const St=(bt+100)/100,R=.5*(1-St);xt+=`
|
|
13
|
+
<feComponentTransfer in="${It}" result="contrast">
|
|
14
|
+
<feFuncR type="linear" slope="${St}" intercept="${R}"/>
|
|
15
|
+
<feFuncG type="linear" slope="${St}" intercept="${R}"/>
|
|
16
|
+
<feFuncB type="linear" slope="${St}" intercept="${R}"/>
|
|
17
|
+
</feComponentTransfer>`,It="contrast"}if(st!==1&&(xt+=`<feColorMatrix in="${It}" type="saturate" values="${st}" result="saturate"/>`,It="saturate"),gt.hue&&(xt+=`<feColorMatrix in="${It}" type="hueRotate" values="${gt.hue}" result="hue"/>`,It="hue"),gt.negative){const St=1-gt.negative/50;xt+=`
|
|
18
|
+
<feColorMatrix in="${It}" type="matrix" result="invert"
|
|
19
|
+
values="${St} 0 0 0 ${1-St}
|
|
20
|
+
0 ${St} 0 0 ${1-St}
|
|
21
|
+
0 0 ${St} 0 ${1-St}
|
|
22
|
+
0 0 0 1 0"/>`,It="invert"}if(H!==0||N!==0||ot!==0||vt!==0){const St=1+ot+vt,R=St*(1+H-N/2),Rt=St*(1+N),se=St*(1-H-N/2),Ut=gt.shadows*.1/255,de=[R,0,0,0,Ut,0,Rt,0,0,Ut,0,0,se,0,Ut,0,0,0,1,0].join(" ");xt+=`<feColorMatrix in="${It}" type="matrix" values="${de}" result="advanced"/>`,It="advanced"}if(gt.blur&&(xt+=`<feGaussianBlur in="${It}" stdDeviation="${gt.blur}" result="blur"/>`,It="blur"),xt){const St=`<svg xmlns="http://www.w3.org/2000/svg"><filter id="f" color-interpolation-filters="sRGB">${xt}</filter></svg>`,R=btoa(St);mt.push(`url('data:image/svg+xml;base64,${R}#f')`)}}mt.length>0?t.filter=mt.join(" "):t.filter="none",t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";const Mt=t.globalAlpha,Ft=this.normalizeOpacity(e.opacity!==void 0?e.opacity:100);t.globalAlpha=Mt*Ft;const Vt=e.compositeOperation||e.blendMode;if(Vt&&Vt!=="Normal"){const ft=Vt.toLowerCase();["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity","source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","copy","xor","multiply","screen"].includes(ft)&&(t.globalCompositeOperation=ft)}const Yt=t,Ht=e.masks||(i.maskedBy?[{maskId:i.maskedBy,inverted:i.maskInverted===!0,type:i.maskType||"alpha",opacity:i.maskOpacity!==void 0?i.maskOpacity/100:1,feather:i.maskFeather||0,isVisible:!0}]:[]);let Kt=!1;const ie=Ht.filter(ft=>ft.isVisible!==!1&&o.has(ft.maskId));if(ie.length>0){const ft=ie[0],bt=o.get(ft.maskId),st=this.objectStates.get(bt.id);st&&st.visible!==!1&&(Kt=!0,(!this.maskBuffer||this.maskBuffer.width!==this.canvasWidth||this.maskBuffer.height!==this.canvasHeight)&&(this.maskBuffer=document.createElement("canvas"),this.maskBuffer.width=this.canvasWidth,this.maskBuffer.height=this.canvasHeight,this.maskCtx=this.maskBuffer.getContext("2d",{willReadFrequently:!0}),this.maskCtx&&(this.maskCtx.imageSmoothingEnabled=!0,this.maskCtx.imageSmoothingQuality="high")),this.maskCtx.setTransform(1,0,0,1,0,0),this.maskCtx.globalCompositeOperation="source-over",this.maskCtx.globalAlpha=1,this.maskCtx.filter="none",this.maskCtx.clearRect(0,0,this.maskBuffer.width,this.maskBuffer.height),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),i.parentId&&this.applyAbsoluteTransform(this.maskCtx,i.parentId,o),this.maskCtx.save(),this.maskCtx.globalAlpha=1,t=this.maskCtx,t.filter=Yt.filter)}t.translate(Math.round(z),Math.round(it)),t.rotate(F*Math.PI/180);const ye=e.skew_x||0,me=e.skew_y||0;if(ye!==0||me!==0){const ft=Math.tan(ye*Math.PI/180),bt=Math.tan(me*Math.PI/180);t.transform(1+ft*bt,bt,ft,1,0,0)}const te=e.rotate_x!==void 0?e.rotate_x:((A=e.transform)==null?void 0:A.rotate_x)??0,ve=e.rotate_y!==void 0?e.rotate_y:((x=e.transform)==null?void 0:x.rotate_y)??0,Se=1+(e.translate_z!==void 0?e.translate_z:((W=e.transform)==null?void 0:W.translate_z)??0)/1e3,we=(e.flip_x===!0?-1:1)*Math.cos(ve*Math.PI/180)*Se,_e=(e.flip_y===!0?-1:1)*Math.cos(te*Math.PI/180)*Se;t.scale($*we,V*_e),n.shadow&&n.shadow.isEnabled!==!0&&((n.shadow.blur||0)>0||Math.abs(n.shadow.offsetX||0)>0||Math.abs(n.shadow.offsetY||0)>0)&&(n.shadow.isEnabled=!0);const ce=n.shadow;if(ce&&ce.isEnabled!==!1){let ft=ce.color||"#000000";(B=(Y=this.artboard)==null?void 0:Y.tokens)!=null&&B.colors&&this.artboard.tokens.colors[ft]&&(ft=this.artboard.tokens.colors[ft]);const bt=this.normalizeOpacity(ce.opacity??100),st=ce.spread||0,N=(ce.blur||0)+st*1.5;let ot=ft;if(ft.startsWith("#")){const It=ft.replace("#",""),Wt=parseInt(It.substring(0,2),16),St=parseInt(It.substring(2,4),16),R=parseInt(It.substring(4,6),16);ot=`rgba(${Wt}, ${St}, ${R}, ${bt})`}else if(ft.startsWith("rgba")){const It=ft.match(/[\d.]+/g);if(It&&It.length>=4){const Wt=It[0],St=It[1],R=It[2],Rt=It[3];ot=`rgba(${Wt}, ${St}, ${R}, ${parseFloat(Rt)*bt})`}}const vt=t.getTransform(),xt=Math.sqrt(vt.a*vt.a+vt.b*vt.b)||1;t.shadowColor=ot,t.shadowBlur=N*xt,t.shadowOffsetX=(ce.offsetX||0)*xt,t.shadowOffsetY=(ce.offsetY||0)*xt}const ne=i.liquidFill||((X=i.style)==null?void 0:X.liquidFill);if(ne&&ne.enabled){t.save();const ft=ne.fillLevel??.5;t.beginPath();const bt=l/2-l*ft;t.rect(-a/2,bt,a,l*ft),t.clip(),t.fillStyle=ne.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(ne.opacity??1)}if((s==null?void 0:s.type)==="Text")this._renderText(t,i,r,n,e,a,l);else if((s==null?void 0:s.type)==="Image"){const ft=s.originalSrc||s.src;if(ft){let bt=this.imageCache.get(ft);bt||(bt=new Image,bt.onload=()=>{this.log(`[ExodeUI] Image loaded successfully, size: ${bt.naturalWidth}x${bt.naturalHeight}`)},bt.onerror=N=>{console.error("[ExodeUI] Image load failed:",N,`Src preview: ${ft.substring(0,100)}...`)},bt.src=ft,this.imageCache.set(ft,bt));const st=n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1,H=(((q=n.stroke)==null?void 0:q.alignment)||"center").toLowerCase();if(st&&(H==="outside"||H==="center")&&this.applyStrokeAlignment(t,n,r,a,l,h),n.fill&&n.fill.type!=="None"){t.save();const N=t.globalAlpha,ot=this.createCanvasFill(t,n.fill,a,l);t.fillStyle=ot||n.fill.color||"transparent",t.globalAlpha=N*this.normalizeOpacity(n.fill.opacity??100),h!==0?(this.drawRoundRect(t,-a/2,-l/2,a,l,h),t.fill()):t.fillRect(-a/2,-l/2,a,l),t.globalAlpha=N,t.restore()}bt.complete&&bt.naturalWidth>0?(h!==0?(t.save(),this.drawRoundRect(t,-a/2,-l/2,a,l,h),t.clip(),t.drawImage(bt,-a/2,-l/2,a,l),t.restore()):t.drawImage(bt,-a/2,-l/2,a,l),st&&H==="inside"&&this.applyStrokeAlignment(t,n,r,a,l,h)):st&&H==="inside"&&this.applyStrokeAlignment(t,n,r,a,l,h)}}else if(s.type==="SVG"){const ft=s.svgContent;if(ft){const bt=n.palette||[],st=n.fill,H=n.stroke,N=st?this.normalizeOpacity(st.opacity??100):1,ot=(st==null?void 0:st.type)==="Solid"&&(!H||H.isEnabled===!1||H.type==="Solid"&&H.color===st.color),vt=st&&st.type!=="None"?ot?"monochrome":st.type==="Solid"?(st.color||"")+"|opacity:"+N:JSON.stringify(st.stops||[])+"|opacity:"+N:"",xt=H&&H.isEnabled!==!1&&(H.width||0)>0?ot?["monochrome",H.width||0,H.trimStart??0,H.trimEnd??1,H.trimOffset??0,H.dashOffset??0].join("|"):[H.width||0,H.fill?H.fill.type==="Solid"?H.fill.color||"":JSON.stringify(H.fill.stops||[]):H.color||"",H.opacity??1,H.lineCap||"",H.lineJoin||"",(H.dashArray||[]).join(","),H.trimStart??0,H.trimEnd??1,H.trimOffset??0,H.dashOffset??0].join("|"):"nostroke",It=[i.id,bt.join("_"),vt,xt,e.opacity??100,e.visible!==!1?"v":"h"].join("_");let Wt=this.imageCache.get(It);if(!Wt){Wt=new Image,Wt.crossOrigin="anonymous";let R=ft;R.match(/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i)||(R=R.replace(/<svg([^>]*)>/i,(nt,pt)=>`<svg xmlns="http://www.w3.org/2000/svg"${pt}>`));let Rt=s.width||a||100,se=s.height||l||100;const Ut=R.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(Ut&&(Rt=parseFloat(Ut[1]),se=parseFloat(Ut[2])),R=R.replace(/<svg([^>]*)>/i,(nt,pt)=>{let D=pt.replace(/\b(?:width|height)=["'][^"']*["']/gi," ");return D.match(/\bviewBox=/i)||(D+=` viewBox="0 0 ${Rt} ${se}"`),D.match(/\bpreserveAspectRatio=/i)||(D+=' preserveAspectRatio="none"'),D+=' width="100%" height="100%"',`<svg${D}>`}),s.colors&&s.colors.length>0&&bt.length>0&&s.colors.forEach((nt,pt)=>{if(bt[pt]){const D=nt.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),at=new RegExp(D,"gi");R=R.replace(at,bt[pt])}}),st&&st.type&&st.type!=="None"){if(st.type==="Solid"&&st.color){const nt=ot?"#FFFFFF":st.color,pt=ot?1:this.normalizeOpacity(st.opacity??100);R=R.replace(/\bfill\s*=\s*["'][^"']*["']/gi,D=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(D)?D:`fill="${nt}"`),R=R.replace(/fill\s*:\s*[^;"')]+/gi,D=>/fill\s*:\s*(none|transparent)/i.test(D)?D:`fill:${nt}`),pt<1&&(R=R.replace(/\bfill-opacity\s*=\s*["'][^"']*["']/gi,`fill-opacity="${pt}"`),R=R.replace(/fill-opacity\s*:\s*[^;"')]+/gi,`fill-opacity:${pt}`),R.match(/\bfill-opacity\s*=/i)||(R=R.replace(/(<svg[^>]*>)/i,`$1<g fill-opacity="${pt}">`),R=R.replace(/<\/svg>/i,"</g></svg>")))}else if(st.type==="LinearGradient"||st.type==="RadialGradient"||st.type==="Linear"||st.type==="Radial"){const nt="exode-fill",pt=this.normalizeOpacity(st.opacity??100),D=(st.stops||[]).map(Q=>{const $t=Q.offset!==void 0?Q.offset:Q.pos??0,Jt=this.normalizeOpacity(Q.opacity??100)*pt;return`<stop offset="${$t*100}%" stop-color="${Q.color||"#000"}" stop-opacity="${Jt}"/>`}).join("");let at="";if(st.type==="LinearGradient"||st.type==="Linear"){const Q=(Qt,qt)=>Array.isArray(Qt)?Qt[qt]??(qt===0?0:1):Qt&&typeof Qt=="object"?Qt[qt===0?"x":"y"]??(qt===0?0:1):qt===0?0:1,$t=Q(st.start,0)*100,Jt=Q(st.start,1)*100,oe=Q(st.end,0)*100,Gt=Q(st.end,1)*100;at=`<linearGradient id="${nt}" x1="${$t}%" y1="${Jt}%" x2="${oe}%" y2="${Gt}%" gradientUnits="objectBoundingBox">${D}</linearGradient>`}else{const Q=(Gt,Qt)=>Array.isArray(Gt)?Gt[Qt]??.5:Gt&&typeof Gt=="object"?Gt[Qt===0?"x":"y"]??.5:.5,$t=Q(st.center,0)*100,Jt=Q(st.center,1)*100,oe=(st.radius??.5)*100;at=`<radialGradient id="${nt}" cx="${$t}%" cy="${Jt}%" r="${oe}%" gradientUnits="objectBoundingBox">${D}</radialGradient>`}/<defs>/i.test(R)?R=R.replace(/<defs>/i,`<defs>${at}`):R=R.replace(/<svg([^>]*)>/i,`<svg$1><defs>${at}</defs>`),R=R.replace(/\bfill\s*=\s*["'][^"']*["']/gi,Q=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Q)?Q:`fill="url(#${nt})"`),R=R.replace(/fill\s*:\s*[^;"')]+/gi,Q=>/fill\s*:\s*(none|transparent)/i.test(Q)?Q:`fill:url(#${nt})`)}}const de=(nt,pt,D=1)=>{const at=(nt.stops||[]).map(Gt=>{const Qt=Gt.offset!==void 0?Gt.offset:Gt.pos??0,qt=this.normalizeOpacity(Gt.opacity??100)*D;return`<stop offset="${Qt*100}%" stop-color="${Gt.color||"#000"}" stop-opacity="${qt}"/>`}).join(""),Q=(Gt,Qt,qt=.5)=>Array.isArray(Gt)?Gt[Qt]??qt:Gt&&typeof Gt=="object"?Gt[Qt===0?"x":"y"]??qt:qt;if(nt.type==="LinearGradient"||nt.type==="Linear"){const Gt=Q(nt.start,0,0)*100,Qt=Q(nt.start,1,0)*100,qt=Q(nt.end,0,1)*100,Me=Q(nt.end,1,1)*100;return`<linearGradient id="${pt}" x1="${Gt}%" y1="${Qt}%" x2="${qt}%" y2="${Me}%" gradientUnits="objectBoundingBox">${at}</linearGradient>`}const $t=Q(nt.center,0,.5)*100,Jt=Q(nt.center,1,.5)*100,oe=(nt.radius??.5)*100;return`<radialGradient id="${pt}" cx="${$t}%" cy="${Jt}%" r="${oe}%" gradientUnits="objectBoundingBox">${at}</radialGradient>`},Lt=(nt,pt)=>/<defs>/i.test(nt)?nt.replace(/<defs>/i,`<defs>${pt}`):nt.replace(/(<svg[^>]*>)/i,`$1<defs>${pt}</defs>`);if(H&&H.isEnabled!==!1&&(H.width||0)>0){const nt=ot?1:this.normalizeOpacity(H.opacity??100),pt=ot?"#FFFFFF":H.color||(st==null?void 0:st.color)||"#000000";let D="";const at=H.fill;if(at&&at.type){if(at.type==="Solid")D=at.color||H.color||"#000000";else if(at.type==="LinearGradient"||at.type==="RadialGradient"||at.type==="Linear"||at.type==="Radial"){const Nt="exode-stroke";R=Lt(R,de(at,Nt,nt)),D=`url(#${Nt})`}}D||(D=pt),R.match(/\bstroke\s*=\s*["']/i)?R=R.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,Nt=>/stroke\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Nt)?Nt:`stroke="${D}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke="${D}"`),R=R.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),`stroke:${D}`);let Q=s.width||a||100,$t=s.height||l||100;const Jt=ft.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(Jt){const Nt=parseFloat(Jt[1]),ae=parseFloat(Jt[2]);!isNaN(Nt)&&!isNaN(ae)&&(Q=Nt,$t=ae)}const oe=Math.max(.001,a/Q),Gt=Math.max(.001,l/$t),Qt=(oe+Gt)/2,qt=(H.width||1)/Qt;R.match(/\bstroke-width\s*=\s*["']/i)?R=R.replace(/\bstroke-width\s*=\s*["'][^"']*["']/gi,`stroke-width="${qt}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-width="${qt}"`),R=R.replace(/stroke-width\s*:\s*[^;"')]+/gi,`stroke-width:${qt}`),R.match(/\bstroke-opacity\s*=\s*["']/i)?R=R.replace(/\bstroke-opacity\s*=\s*["'][^"']*["']/gi,`stroke-opacity="${nt}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-opacity="${nt}"`),R=R.replace(/stroke-opacity\s*:\s*[^;"')]+/gi,`stroke-opacity:${nt}`);const Me=H.lineCap||"round";R.match(/\bstroke-linecap\s*=\s*["']/i)?R=R.replace(/\bstroke-linecap\s*=\s*["'][^"']*["']/gi,`stroke-linecap="${Me}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linecap="${Me}"`),R=R.replace(/stroke-linecap\s*:\s*[^;"')]+/gi,`stroke-linecap:${Me}`);const Pe=H.lineJoin||"round";R.match(/\bstroke-linejoin\s*=\s*["']/i)?R=R.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${Pe}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linejoin="${Pe}"`),R=R.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${Pe}`);const Ee=H.trimStart??0,Ae=H.trimEnd??1,xe=H.trimOffset??0,Oe=H.dashOffset??0,Be=Ee!==0||Ae!==1||xe!==0||Oe!==0;if(Be){const Nt=Math.max(0,Math.min(1,Ee)),ae=Math.max(0,Math.min(1,Ae));this.frameCount%600===0&&this.debugLog(`SVG Trim - Object: ${i.name||i.id}, Start: ${Nt}, End: ${ae}`);const Ce=(Q+$t)*2,Le=(xe%1+1)%1,Fe=(Oe%1+1)%1;let ue="",fe=0;if(Nt>=ae)ue=`0 ${Ce}`,fe=0;else{const he=Ce*(ae-Nt),Ie=Ce-he;fe=-(Ce*(Nt+Le+Fe)),ue=`${he} ${Ie}`}R.match(/\bstroke-dasharray\s*=/i)?R=R.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${ue}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dasharray="${ue}"`),R=R.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${ue}`),R.match(/\bstroke-dashoffset\s*=/i)?R=R.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${fe}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dashoffset="${fe}"`),R=R.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${fe}`)}else if(H.dashArray&&H.dashArray.length>0){const Nt=H.dashArray.join(" ");R=R.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${Nt}"`),R=R.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${Nt}`),H.dashOffset&&(R=R.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${H.dashOffset}"`),R=R.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${H.dashOffset}`))}if(!/\bstroke\s*=\s*["']/i.test(ft)&&!new RegExp("(?<![a-z-])stroke\\s*:","i").test(ft)){let Nt="",ae="";if(Be){const ue=s.width||a||100,fe=s.height||l||100,he=(ue+fe)*2,Ie=Math.max(0,Math.min(1,Ee)),We=Math.max(0,Math.min(1,Ae)),Ne=(xe%1+1)%1,He=(Oe%1+1)%1;if(Ie>=We)Nt=` stroke-dasharray="0 ${he}"`,ae=' stroke-dashoffset="0"';else{const Ye=he*(We-Ie),Ue=he-Ye,qe=-(he*(Ie+Ne+He));Nt=` stroke-dasharray="${Ye} ${Ue}"`,ae=` stroke-dashoffset="${qe}"`}}else(j=H.dashArray)!=null&&j.length&&(Nt=` stroke-dasharray="${H.dashArray.join(" ")}"`,H.dashOffset&&(ae=` stroke-dashoffset="${H.dashOffset}"`));const Ce=` stroke-linecap="${H.lineCap||"round"}"`,Le=` stroke-linejoin="${H.lineJoin||"round"}"`,Fe=`stroke="${D}" stroke-width="${qt}" stroke-opacity="${nt}"${Ce}${Le}${Nt}${ae}`;R=R.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(ue,fe,he)=>`${fe}${he}<g ${Fe}>`),R=R.replace(/<\/svg>/i,"</g></svg>")}}else H&&H.isEnabled===!1&&(R=R.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,'stroke="none"'),R=R.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),"stroke:none"));const ut=new Blob([R],{type:"image/svg+xml"}),dt=URL.createObjectURL(ut);Wt.onload=()=>{if(URL.revokeObjectURL(dt),this.frameCount%900===0){const nt=this.imageCache.get(It);nt&&this.debugLog(`SVG Payload Ready: ${i.name||i.id} (${nt.naturalWidth}x${nt.naturalHeight})`)}},Wt.onerror=()=>{URL.revokeObjectURL(dt),this.debugLog(`SVG Error: Failed to load payload for ${i.name||i.id}`)},Wt.src=dt,this.imageCache.set(It,Wt)}let St=null;if(Wt.complete&&Wt.naturalWidth>0?(St=Wt,this.lastValidSvgImgMap.set(i.id,Wt)):St=this.lastValidSvgImgMap.get(i.id)||null,St&&St.complete&&St.naturalWidth>0){const R=Math.max(1,a),Rt=Math.max(1,l);if(ot&&(st==null?void 0:st.type)==="Solid"){this.maskBuffer||(this.maskBuffer=document.createElement("canvas"),this.maskCtx=this.maskBuffer.getContext("2d")),this.maskBuffer.width=R,this.maskBuffer.height=Rt,this.maskCtx.setTransform(1,0,0,1,0,0),this.maskCtx.globalCompositeOperation="source-over",this.maskCtx.globalAlpha=1,this.maskCtx.filter="none",this.maskCtx.clearRect(0,0,R,Rt),this.maskCtx.drawImage(St,0,0,R,Rt),this.maskCtx.globalCompositeOperation="source-in";const se=st.color||"#000000",Ut=this.normalizeOpacity(st.opacity??100);this.maskCtx.fillStyle=se,this.maskCtx.globalAlpha=Ut,this.maskCtx.fillRect(0,0,R,Rt),t.drawImage(this.maskBuffer,-R/2,-Rt/2,R,Rt)}else h!==0?(t.save(),this.drawRoundRect(t,-R/2,-Rt/2,R,Rt,h),t.clip(),t.drawImage(St,-R/2,-Rt/2,R,Rt),t.restore()):t.drawImage(St,-R/2,-Rt/2,R,Rt)}}}else if(r.type==="LineGraph")this.renderLineGraph(t,r,a,l);else if(i.type==="Shape"){if(this.applyPath(t,r,a,l,h),t.save(),n.blur&&n.blur.amount>0&&(t.filter=`blur(${n.blur.amount}px)`),n.fill){const ft=t.globalAlpha;if(((E=n.fill)==null?void 0:E.type)==="Image"&&(n.fill.originalSrc||n.fill.src)){const bt=n.fill.originalSrc||n.fill.src;let st=this.imageCache.get(bt);st||(st=new Image,st.src=bt,this.imageCache.set(bt,st)),st.complete&&st.naturalWidth>0&&(t.save(),this.applyPath(t,r,a,l,h),t.clip(),this.renderFittedImage(t,st,-a/2,-l/2,a,l,n.fill.fillMode),t.restore())}else{const bt=this.createCanvasFill(t,n.fill,a,l);t.fillStyle=bt||(typeof n.fill=="string"?n.fill:n.fill.color||"transparent"),t.globalAlpha=ft*this.normalizeOpacity(n.fill.opacity??100),this.applyPath(t,r,a,l,h),t.fill()}t.globalAlpha=ft}t.restore(),n.stroke&&n.stroke.width>0&&this.applyStrokeAlignment(t,n,r,a,l,h)}else if(i.type==="Frame"||i.type==="Group"&&!i.isStructuralGroup){const ft=e.width??s.width??i.width??a,bt=e.height??s.height??i.height??l,st=h;if(t.save(),t.beginPath(),this.drawRoundRect(t,-ft/2,-bt/2,ft,bt,st),n.fill&&n.fill.type!=="None"){const H=t.globalAlpha,N=this.createCanvasFill(t,n.fill,ft,bt);t.fillStyle=N||n.fill.color||"transparent",t.globalAlpha=H*this.normalizeOpacity(n.fill.opacity??100),t.fill(),t.globalAlpha=H}if(t.restore(),n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1){const H={type:"Rectangle"};this.applyStrokeAlignment(t,n,H,ft,bt,st)}}else i.type==="Group"&&i.isStructuralGroup||(i.type==="Component"&&i.variant==="inputbox"?this.renderInputBox(t,i):i.type==="Component"&&i.variant==="button"?this.renderButton(t,i):i.type==="Component"&&i.variant==="toggle_button"?this.renderToggleButton(t,i):i.type==="Toggle"||i.type==="Component"&&i.variant==="toggle"?this.renderToggle(t,i):i.type==="Slider"||i.type==="Component"&&i.variant==="slider"?this.renderSlider(t,i):i.type==="Dropdown"||i.type==="Component"&&i.variant==="dropdown"?this.renderDropdown(t,i):i.type==="ListView"||i.type==="Component"&&i.variant==="listview"?this.renderListView(t,i):i.type==="Checkbox"||i.type==="Component"&&i.variant==="checkbox"?this.renderCheckbox(t,i):i.type==="RadioGroup"||i.type==="Component"&&i.variant==="radiogroup"?this.renderRadioGroup(t,i):i.type==="BarChart"||i.type==="Component"&&i.variant==="barchart"?this.renderBarChart(t,i):i.type==="PieChart"||i.type==="Component"&&i.variant==="piechart"?this.renderPieChart(t,i):i.type==="Joystick"||i.type==="Component"&&i.variant==="joystick"?this.renderJoystick(t,i):this.frameCount%300===0&&this.warn("[Engine] Unhandled object type in renderObject:",i.type,"Geo:",(L=i.geometry)==null?void 0:L.type));if(this.applyArtEffectOverlay(t,i,r,a,l,h),Pt&&kt==="BackgroundBlur"&&this.applyBackgroundBlurGlass(t,r,a,l,h,ct),ne&&ne.enabled&&t.restore(),i.children&&i.children.length>0){const bt=i.type==="Frame",st=i.clipsContent!==void 0?i.clipsContent:i.clipContent!==void 0?i.clipContent:bt;if(t.save(),st){t.beginPath();const N=e.width??(s==null?void 0:s.width)??i.width??0,ot=e.height??(s==null?void 0:s.height)??i.height??0,vt=e.cornerRadius??(s==null?void 0:s.corner_radius)??i.cornerRadius??0;this.drawRoundRect(t,-N/2,-ot/2,N,ot,vt),t.clip()}let H=0;for(i.children.forEach(N=>{const ot=o.get(N);if(!ot)return;const vt=this.objectStates.get(N),xt=(vt==null?void 0:vt.geometry)||ot.geometry;if(xt&&xt.isMask&&(vt==null?void 0:vt.visible)!==!1){const It=xt.width||0,Wt=xt.height||0;this.applyObjectTransform(t,N);const St=(vt==null?void 0:vt.corner_radius)??(xt==null?void 0:xt.corner_radius)??0;this.applyPath(t,xt,It,Wt,St),t.clip(),H++}else this.renderObject(t,ot,o)});H>0;)t.restore(),H--;t.restore()}if(Kt){this.maskCtx.restore(),(e.masks||(i.maskedBy?[{maskId:i.maskedBy,inverted:i.maskInverted===!0,type:i.maskType||"alpha",opacity:i.maskOpacity!==void 0?i.maskOpacity/100:1,feather:i.maskFeather||0,isVisible:!0}]:[])).filter(H=>H.isVisible!==!1&&o.has(H.maskId)).forEach(H=>{var St,R,Rt,se,Ut,de;const N=o.get(H.maskId),ot=this.objectStates.get(N.id),vt=H.feather||0,xt=H.inverted===!0,It=H.opacity!==void 0?typeof H.opacity=="number"?H.opacity:H.opacity/100:1;if((H.type||"alpha")==="luma"){(!this.lumaBuffer||this.lumaBuffer.width!==this.maskBuffer.width||this.lumaBuffer.height!==this.maskBuffer.height)&&(this.lumaBuffer=document.createElement("canvas"),this.lumaBuffer.width=this.maskBuffer.width,this.lumaBuffer.height=this.maskBuffer.height,this.lumaCtx=this.lumaBuffer.getContext("2d",{willReadFrequently:!0}),this.lumaCtx&&(this.lumaCtx.imageSmoothingEnabled=!0,this.lumaCtx.imageSmoothingQuality="high")),this.lumaCtx.setTransform(1,0,0,1,0,0),this.lumaCtx.globalCompositeOperation="source-over",this.lumaCtx.globalAlpha=1,this.lumaCtx.filter="none",this.lumaCtx.clearRect(0,0,this.lumaBuffer.width,this.lumaBuffer.height),this.lumaCtx.save(),this.rootTransform&&this.lumaCtx.setTransform(this.rootTransform),this.applyAbsoluteTransform(this.lumaCtx,N.id,o),vt>0&&(this.lumaCtx.filter=`blur(${vt}px)`),this.lumaCtx.globalAlpha=It;const Lt=(ot==null?void 0:ot.width)||N.geometry.width||0,ut=(ot==null?void 0:ot.height)||N.geometry.height||0,dt=(ot==null?void 0:ot.corner_radius)??N.corner_radius??0;if(((St=N.geometry)==null?void 0:St.type)==="Text"){const at=ot!=null&&ot.geometry?this.deepMerge(N.geometry,ot.geometry):N.geometry,Q=ot!=null&&ot.style?this.deepMerge(N.style,ot.style):N.style;this._renderText(this.lumaCtx,N,{...at,width:Lt,height:ut,corner_radius:dt},Q,ot,Lt,ut,!0)}else if(((R=N.geometry)==null?void 0:R.type)==="Image"){const at=N.geometry.src;if(at){let Q=this.imageCache.get(at);Q||(Q=new Image,Q.src=at,this.imageCache.set(at,Q)),Q.complete&&Q.naturalWidth>0?this.lumaCtx.drawImage(Q,-Lt/2,-ut/2,Lt,ut):(this.applyPath(this.lumaCtx,N.geometry,Lt,ut,dt),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else if(((Rt=N.geometry)==null?void 0:Rt.type)==="SVG"){const at=N.geometry.svgContent;if(at){const Q=`__lumamask_${N.id}`;let $t=this.imageCache.get(Q);if(!$t){$t=new Image;const Jt=new Blob([at],{type:"image/svg+xml"});$t.src=URL.createObjectURL(Jt),$t.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(Q,$t)}$t.complete&&$t.naturalWidth>0?this.lumaCtx.drawImage($t,-Lt/2,-ut/2,Lt,ut):(this.applyPath(this.lumaCtx,N.geometry,Lt,ut,dt),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else this.applyPath(this.lumaCtx,N.geometry,Lt,ut,dt),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill();this.lumaCtx.restore();const nt=this.maskCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight),pt=this.lumaCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight).data,D=nt.data;for(let at=0;at<D.length;at+=4){const Q=pt[at],$t=pt[at+1],Jt=pt[at+2];let oe=(.299*Q+.587*$t+.114*Jt)/255;xt&&(oe=1-oe),D[at+3]*=oe}this.maskCtx.putImageData(nt,0,0)}else{this.maskCtx.save(),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),this.maskCtx.globalCompositeOperation=xt?"destination-out":"destination-in",vt>0&&(this.maskCtx.filter=`blur(${vt}px)`),this.maskCtx.globalAlpha=It,this.applyAbsoluteTransform(this.maskCtx,N.id,o);const Lt=(ot==null?void 0:ot.width)||N.geometry.width||0,ut=(ot==null?void 0:ot.height)||N.geometry.height||0,dt=(ot==null?void 0:ot.corner_radius)??N.corner_radius??0;if(((se=N.geometry)==null?void 0:se.type)==="Text"){const nt=ot!=null&&ot.geometry?this.deepMerge(N.geometry,ot.geometry):N.geometry,pt=ot!=null&&ot.style?this.deepMerge(N.style,ot.style):N.style;this._renderText(this.maskCtx,N,{...nt,width:Lt,height:ut,corner_radius:dt},pt,ot,Lt,ut,!0)}else if(((Ut=N.geometry)==null?void 0:Ut.type)==="Image"){const nt=N.geometry.src;if(nt){let pt=this.imageCache.get(nt);pt||(pt=new Image,pt.src=nt,this.imageCache.set(nt,pt)),pt.complete&&pt.naturalWidth>0?this.maskCtx.drawImage(pt,-Lt/2,-ut/2,Lt,ut):(this.applyPath(this.maskCtx,N.geometry,Lt,ut,dt),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else if(((de=N.geometry)==null?void 0:de.type)==="SVG"){const nt=N.geometry.svgContent;if(nt){const pt=`__alphamask_${N.id}`;let D=this.imageCache.get(pt);if(!D){D=new Image;const at=new Blob([nt],{type:"image/svg+xml"});D.src=URL.createObjectURL(at),D.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(pt,D)}D.complete&&D.naturalWidth>0?this.maskCtx.drawImage(D,-Lt/2,-ut/2,Lt,ut):(this.applyPath(this.maskCtx,N.geometry,Lt,ut,dt),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else this.applyPath(this.maskCtx,N.geometry,Lt,ut,dt),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill();this.maskCtx.restore()}}),Yt.save(),Yt.setTransform(1,0,0,1,0,0);const st=i.maskBlendMode||i.blendMode;st&&st!=="Normal"&&(Yt.globalCompositeOperation=st.toLowerCase()),Yt.drawImage(this.maskBuffer,0,0),Yt.restore(),Yt.restore()}else t.restore()}}_renderText(t,i,o,e,s,n,a,l=!1,c=!1){var tt,rt,mt,Ct,ct,Pt,kt,Tt,zt;let h=o.text||"";if(o.textInputId&&!l){const et=this.inputs.get(o.textInputId);et!==void 0&&(h=String(et),s.geometry&&s.geometry.type==="Text"&&(s.geometry.text=h))}if(o.svgPath){const et=o.svgPath;t.save();const yt=((tt=e==null?void 0:e.fill)==null?void 0:tt.color)||"#000000",Ot=((rt=e==null?void 0:e.fill)==null?void 0:rt.opacity)!==void 0?(mt=e==null?void 0:e.fill)==null?void 0:mt.opacity:1;t.fillStyle=yt,t.globalAlpha*=Ot;const gt=new Path2D(et);t.fill(gt),t.restore();return}let r=h||"";o.enableSegments===!0&&o.segments&&Array.isArray(o.segments)&&(r=o.segments.map(et=>et&&et.text?et.text:"").join(""));const u=o.textCase||"none";u==="uppercase"?r=r.toUpperCase():u==="lowercase"?r=r.toLowerCase():u==="capitalize"&&(r=r.replace(/\b\w/g,et=>et.toUpperCase()));let f=((Ct=o.fontWeight)==null?void 0:Ct.toString())||"400",d=o.fontStyle||"normal";f.toLowerCase().includes("italic")&&(d="italic",f=f.replace(/italic/gi,"").trim()||"400");const p=this.mapFontWeight(f),m=Math.max(1,o.fontSize||32);let y=o.fontFamily||"Inter";const b=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];b.forEach(et=>{const yt=new RegExp(`[\\s-]${et}$`,"i");yt.test(y)&&(y=y.replace(yt,"").trim())});const C=`${o.smallCaps===!0?"small-caps ":""}${d} ${p} ${m}px "${y}", sans-serif`;t.font=C;const w=o.textVerticalAlign||"top";t.textBaseline="top";const M=o.textAlign||"left";t.textAlign=M;let I=0;if(typeof o.letterSpacing=="number")I=o.letterSpacing;else if(typeof o.letterSpacing=="object"&&o.letterSpacing.value!==void 0){const et=o.letterSpacing;I=et.unit==="PERCENT"?et.value/100*m:et.value}t.letterSpacing!==void 0&&(t.letterSpacing=`${I}px`);const k=o.kerning||"auto",T=o.kerningValue||0;k==="manual"&&T!==0&&(t.letterSpacing=`${I+T}px`);const O=o.paragraphSpacing||0;let P=o.lineHeight??1.2;typeof P=="string"&&(P=parseFloat(P)),P>5&&m>0&&(P=P/m);const _=(P||1.2)*m,A=o.isPointText===!0||!o.width||o.width<=0,x=((ct=o.padding)==null?void 0:ct.left)||((Pt=o.padding)==null?void 0:Pt.right)||0,W=A?1e5:o.width&&o.width>0?Math.ceil(o.width)-x*2:1e5;o.autoHeight;const Y=Ze({text:r,fontFamily:y,fontSize:m,fontWeight:p,fontStyle:d,lineHeight:P,width:W,letterSpacing:I,paragraphSpacing:O,paragraphIndent:o.paragraphIndent||0,segments:o.segments,enableSegments:o.enableSegments,textCase:u,hyphenation:o.hyphenation,composer:o.composer,balanceRaggedLines:o.balanceRaggedLines}),B=Y.lines||[],X=Y.maxFontSize||m,q=this.fontLeadingFactors[y]??.5,j=(_-m)*q;let E=Y.height,L=n,G=a;if(L===0||G===0||L>=1e5){let et=0,yt=0;const Ot=Y.fullText||r;(B||[]).forEach(gt=>{const Mt=gt.text||"",Ft=t.measureText(Mt).width+(Mt.length>0?(Mt.length-1)*I:0);Ft>et&&(et=Ft),yt+=Mt.length,yt<Ot.length&&(Ot[yt]===`
|
|
23
|
+
`||Ot[yt]==="\r")&&(yt++,Ot[yt-1]==="\r"&&Ot[yt]===`
|
|
24
|
+
`&&yt++)}),(L===0||L>=1e5)&&(L=et),G===0&&(G=E||0)}let z=-E/2;a>0&&a>E&&(w==="top"?z=-a/2:w==="middle"||w==="center"?z=-E/2:w==="bottom"&&(z=a/2-E)),z+=j;let it=null,F=0;if(o.pathId&&this.artboard){const et=this.artboard.objects.find(yt=>yt.id===o.pathId);if(et&&et.type==="Shape"&&((kt=et.geometry)==null?void 0:kt.type)==="Path"){const yt=this.objectStates.get(et.id),Ot=yt!=null&&yt.geometry?this.deepMerge(et.geometry,yt.geometry):et.geometry,gt=(yt==null?void 0:yt.scale_x)!==void 0?(et.width||0)*yt.scale_x:et.width||0,Mt=(yt==null?void 0:yt.scale_y)!==void 0?(et.height||0)*yt.scale_y:et.height||0;it={geo:Ot,obj:et,w:gt,h:Mt},F=this.getPerimeter(Ot,gt,Mt)}}const $=(et,yt)=>{var gt,Mt;if(I===0&&(!o.enableSegments||!((gt=o.segments)!=null&>.length)))return t.measureText(et).width;let Ot=0;for(let Ft=0;Ft<et.length;Ft++){const Vt=yt+Ft;let Yt=0;if(o.enableSegments===!0&&((Mt=o.segments)==null?void 0:Mt.length)>0){let Ht=0,Kt=null;for(const ie of o.segments){if(Vt<Ht+(ie.text||"").length){Kt=ie;break}Ht+=(ie.text||"").length}if(Kt){t.save();let ie=Kt.fontFamily||o.fontFamily||"Inter";const ye=this.mapFontWeight((Kt.fontWeight||o.fontWeight||"400").toString()),me=Kt.fontStyle||d,te=Kt.fontSize||m;t.font=`${me} ${ye} ${te}px "${ie}", sans-serif`,Yt=t.measureText(et[Ft]).width,t.restore()}else Yt=t.measureText(et[Ft]).width}else Yt=t.measureText(et[Ft]).width;Ot+=Yt+I}return Ot-(et.length>0?I:0)},V=(et,yt,Ot,gt,Mt)=>{var ye,me;const Vt=(Mt===0||r[Mt-1]===`
|
|
25
|
+
`||r[Mt-1]==="\r")&&o.paragraphIndent?o.paragraphIndent:0,Yt=(!l||c)&&(i.behaviors||[]).some(te=>te.enabled&&(te.type.toString().includes("Text")||["Typewriter","Scramble","Wave","Bounce","GlitchText","Reveal3D","RevealSlide","RevealBlur"].includes(te.type))),Ht=!o.pathId&&!Yt&&(o.enableSegments!==!0||!o.segments||o.segments.length===0),Kt=o.baselineShift||0,ie=Ot+Kt;if(Ht)t.font=C,gt?t.strokeText(et,yt+Vt,ie):t.fillText(et,yt+Vt,ie);else{const te=$(et,Mt);let ve=yt+Vt;M==="center"?ve-=te/2:M==="right"&&(ve-=te);const Te=Mt+et.length>=r.length||r[Mt+et.length]===`
|
|
26
|
+
`||r[Mt+et.length]==="\r";let Se=0,we=0;const _e=o.justifyMinWordSpacing,ce=o.justifyMaxWordSpacing;if(M==="justify"&&!Te&&te>0&&!o.pathId){const st=A?te:W-x*2+0,H=Math.max(0,st-te);for(let N=0;N<et.length;N++)et[N]===" "&&we++;if(we>0){const N=t.measureText(" ").width;let ot=_e||N*.5,vt=ce||N*2.5;Se=Math.max(0,Math.min(H/we,vt-ot))}}let ne=o.pathOffset||0;o.pathId&&F>0&&it&&(M==="center"?ne+=F/2-te/2:M==="right"&&(ne+=F-te));let ft=ve;const bt=l&&!c?[]:((ye=i.behaviors)==null?void 0:ye.filter(st=>[U.Typewriter,U.Scramble,U.Wave,U.Bounce,U.GlitchText,U.TextTrail,U.Reveal3D,U.RevealSlide,U.RevealBlur,U.TextLiquid,U.TextVortex,U.TextExplosion,U.TextRain,U.TextGravity,U.TextElastic,U.TextMatrix,U.TextNeon,U.TextGlitch3D,U.TextDissolve,U.TextOrganic,U.TextBreathe,U.TextFloral,U.TextSmoke,U.TextVariable,U.TextMagnet,U.TextSpin,U.TextZing,U.TextPerspective,U.TextMirror].includes(st.type)&&st.enabled))||[];for(let st=0;st<et.length;st++){let H=et[st];const N=Mt+st;let ot=0,vt=0,xt=1,It=1,Wt=0,St=1,R=H;bt.forEach(ut=>{const dt=ut.settings||{},nt=dt.strength||1,pt=Date.now();if(ut.type===U.Typewriter)this.currentTime*(dt.speed||1)-N*(dt.stagger||.05)<0&&(St=0);else if(ut.type===U.Scramble)Math.max(0,Math.min(1,this.currentTime/(dt.duration||1.5))-N*.02)<1&&Math.random()<.3&&(R="$%#@!*&"[Math.floor(Math.random()*7)]);else if(ut.type===U.Wave)vt+=Math.sin(this.currentTime*5*(dt.speed||1)+N*(dt.frequency||1))*(dt.amplitude||20)*nt;else if(ut.type===U.Bounce){const D=Math.max(0,this.currentTime%2-N*(dt.stagger||.1));D<1&&(vt-=Math.abs(Math.sin(D*Math.PI))*(dt.height||50)*nt)}else if(ut.type===U.TextTrail){const D=this.pointerHistory[Math.max(0,this.pointerHistory.length-1-N*(dt.delay||5))];D&&(ot+=(D.x-(s.x+ft))*nt*.2,vt+=(D.y-(s.y+Ot+vt))*nt*.2)}else if(ut.type===U.Reveal3D){const D=Math.max(0,Math.min(1,this.currentTime*(dt.speed||1)-N*(dt.stagger||.1)));xt*=D,It*=D,St=D}else if(ut.type===U.RevealSlide){const D=Math.max(0,Math.min(1,this.currentTime*1.5-N*.05)),at=(1-D)*(dt.distance||40)*nt,Q=dt.direction||"up";Q==="up"?vt-=at:Q==="down"?vt+=at:Q==="left"?ot-=at:Q==="right"&&(ot+=at),St=D}else if(ut.type===U.RevealBlur){const D=Math.max(0,Math.min(1,this.currentTime*1.2-N*.1));St=D,ot+=(1-D)*5}else if(ut.type===U.TextLiquid){const D=Math.max(0,Math.sin(pt*.001*(dt.speed||1)+N*.5));vt+=D*(dt.amplitude||10)*nt,It*=1+D*.2}else if(ut.type===U.TextVortex){const D=pt*.002*(dt.speed||1)+N*.2,at=(1-(Math.sin(pt*.001)*.5+.5))*(dt.radius||50);ot+=Math.cos(D)*at*nt,vt+=Math.sin(D)*at*nt}else if(ut.type===U.TextExplosion){const D=dt.force||1,at=this.currentTime%2;if(at<1){const Q=(N/et.length-.5)*Math.PI*2,$t=at*100*D;ot+=Math.cos(Q)*$t*nt,vt+=Math.sin(Q)*$t*nt,St=1-at}}else if(ut.type===U.TextRain){const D=dt.speed||1,at=dt.height||100,Q=(pt*.001*D+N*.1)%1;vt-=(1-Q)*at*nt,St=Q>.1?1:Q*10}else if(ut.type===U.TextGravity){const D=dt.gravity||9.8,at=this.currentTime%3/3,Q=.5*D*Math.pow(at*10,2);Q<100?vt+=Q*nt:vt+=100*nt}else if(ut.type===U.TextMatrix){const D=dt.speed||1;if(Math.random()<.1*D){const Q="0123456789ABCDEF!@#$%^&*";R=Q[Math.floor(Math.random()*Q.length)]}St=.3+(Math.sin(pt*.01*D+N)+1)/2*.7}else if(ut.type===U.TextNeon){const D=Math.random()>.95?.5:1;St=(.7+(Math.sin(pt*.005)+1)/2*.3)*D}else if(ut.type===U.TextDissolve)Math.sin(N*1.5+pt*.002*(dt.speed||1))>.5&&(St=0);else if(ut.type===U.TextOrganic){const D=dt.speed||1,at=dt.amplitude||10;ot+=Math.sin(pt*.002*D+N)*at*nt,vt+=Math.cos(pt*.0015*D+N*.7)*at*nt}else if(ut.type===U.TextBreathe){const at=1+(Math.sin(pt*.003+N*.2)+1)/2*.2*nt;xt*=at,It*=at}else if(ut.type===U.TextSpin){const D=dt.speed||1;Wt+=pt*.01*D+N}else if(ut.type===U.TextMagnet){const D=this.pointerHistory[this.pointerHistory.length-1];if(D){const at=D.x-(s.x+ft),Q=D.y-(s.y+Ot);Wt=Math.atan2(Q,at)}}else if(ut.type===U.TextPerspective){const D=et.length/2,at=(N-D)/D,Q=1-Math.abs(at)*.3*nt;xt*=Q,It*=Q,ot+=at*20*nt}else if(ut.type===U.TextMirror)St*=.8;else if(ut.type===U.TextFloral){const D=dt.speed||1,at=dt.stagger||.1,Q=(pt*.001*D+N*at)%2;Q<1&&(xt*=Q,It*=Q,Wt+=Q*Math.PI)}else if(ut.type===U.TextSmoke){const D=dt.speed||1,at=dt.height||50,Q=(pt*5e-4*D+N*.2)%1;vt-=Q*at*nt,ot+=Math.sin(pt*.002+N)*5*nt,St=1-Q}else if(ut.type===U.TextVariable){const D=dt.speed||1,at=dt.intensity||1.5,Q=(Math.sin(pt*.004*D+N*.3)+1)/2;xt*=1+Q*(at-1)*nt}else if(ut.type===U.TextZing){const D=dt.speed||2,at=dt.distance||100,Q=(pt*.002*D+N*.05)%1;ot+=(1-Q)*at*nt,St=Q}else if(ut.type===U.TextElastic){const D=dt.stiffness||.2,at=dt.damping||.1,Q=Math.sin(pt*.01)*Math.exp(-pt*.001*at);It*=1+Q*D*nt}else if(ut.type===U.TextGlitch3D){const D=dt.intensity||5;Math.random()<.2&&(ot+=(Math.random()-.5)*D,vt+=(Math.random()-.5)*D,St=.8)}else if(ut.type===U.GlitchText){const D=dt.intensity||5;Math.random()<.1&&(ot+=(Math.random()-.5)*D,vt+=(Math.random()-.5)*D,Math.random()<.05&&(St=.5))}});let Rt=null,se=o.textDecoration||"none",Ut=m;if(o.enableSegments===!0&&((me=o.segments)==null?void 0:me.length)>0){let ut=0,dt=null;for(const nt of o.segments){if(N<ut+(nt.text||"").length){dt=nt;break}ut+=(nt.text||"").length}if(dt){let nt=dt.fontFamily||o.fontFamily||"Inter";b.forEach(at=>{const Q=new RegExp(`[\\s-]${at}$`,"i");Q.test(nt)&&(nt=nt.replace(Q,"").trim())});const pt=this.mapFontWeight((dt.fontWeight||o.fontWeight||"400").toString()),D=dt.fontStyle||d;Ut=dt.fontSize||m,t.font=`${D} ${pt} ${Ut}px "${nt}", sans-serif`,dt.fill&&(Rt=dt.fill),dt.textDecoration&&(se=dt.textDecoration),Ut<X&&(vt+=(X-Ut)*.85)}}else t.font=C;const de=t.globalAlpha;t.globalAlpha*=St,t.save();const Lt=t.measureText(R).width;if(it&&F>0){const ut=ft-ve+Lt/2,nt=(ne+ut)/F,pt=this.getPointOnPath(it.geo,it.w,it.h,Math.abs(nt%1)),D=pt.angle,at=Ot+vt+(o.pathOffsetY||0),Q=o.pathSide==="right"?-1:1,$t=Math.cos(D+Math.PI/2)*at*Q,Jt=Math.sin(D+Math.PI/2)*at*Q;t.translate(pt.x+$t+ot,pt.y+Jt),t.rotate(D+Wt+(Q===-1?Math.PI:0))}else t.translate(ft+ot+Lt/2,Ot+vt),Wt!==0&&t.rotate(Wt);if(t.scale(xt,It),Rt&&!l&&!c){const ut=this.createCanvasFill(t,Rt,L,G);t.fillStyle=ut||Rt.color||"#000000"}else if(!l&&!c){const ut=this.createCanvasFill(t,e.fill,L,G);t.fillStyle=ut||e.fill.color||"#000000"}if(St>0)if(l||c){const ut=c?"#000000":this.createCanvasFill(t,e.fill,L,G);t.fillStyle=ut||e.fill.color||"#ffffff",t.fillText(R,-Lt/2,0)}else gt?t.strokeText(R,-Lt/2,0):t.fillText(R,-Lt/2,0);se!=="none"&&!l&&this.drawTextDecoration(t,se,0,0,Lt,Ut),t.restore(),t.globalAlpha=de,M==="justify"&&Se>0&&R===" "&&!Te?ft+=Lt+I+Se:ft+=Lt+I}}};if(l){let et=0,yt=z;(B||[]).forEach(Ot=>{const gt=Ot.text||"",Mt=r.indexOf(gt,et);Mt!==-1&&(et=Mt);let Ft=-L/2;M==="center"?Ft=0:M==="right"&&(Ft=L/2),V(gt,Ft,yt,!1,et),et+=gt.length,yt+=_})}else if(c){let et=0,yt=z;(B||[]).forEach(Ot=>{const gt=Ot.text||"";let Mt=-L/2;M==="center"?Mt=0:M==="right"&&(Mt=L/2),V(gt,Mt,yt,!1,et),et+=gt.length,et<r.length&&(r[et]===`
|
|
27
|
+
`||r[et]==="\r")&&(et++,r[et-1]==="\r"&&r[et]===`
|
|
28
|
+
`&&et++),yt+=_})}else{if(e.fill){const yt=t.globalAlpha,Ot=this.createCanvasFill(t,e.fill,L,G);t.fillStyle=Ot||e.fill.color||"#000000",t.globalAlpha=yt*this.normalizeOpacity(e.fill.opacity??100);const gt=Y.fullText||(o.enableSegments?(o.segments||[]).map(Vt=>{let Yt=Vt.text||"";const Ht=Vt.textCase||o.textCase||"none";return Ht==="uppercase"?Yt.toUpperCase():Ht==="lowercase"?Yt.toLowerCase():Ht==="capitalize"?Yt.replace(/\b\w/g,Kt=>Kt.toUpperCase()):Yt}).join(""):r);let Mt=0,Ft=z;(B||[]).forEach(Vt=>{const Yt=Vt.text||"";let Ht=-L/2;M==="center"?Ht=0:M==="right"&&(Ht=L/2),V(Yt,Ht,Ft,!1,Mt),Mt+=Yt.length,Ft+=_,Mt<gt.length&&(gt[Mt]===`
|
|
29
|
+
`||gt[Mt]==="\r")&&(O>0&&(Ft+=O),Mt++,gt[Mt-1]==="\r"&>[Mt]===`
|
|
30
|
+
`&&Mt++)}),t.globalAlpha=yt}const et=o.paragraphRule;if(et&&(((Tt=et.top)==null?void 0:Tt.width)>0||((zt=et.bottom)==null?void 0:zt.width)>0)){let yt=0;(B||[]).forEach((Ot,gt)=>{var Vt,Yt;const Ft=yt===0||yt<r.length&&(r[yt]===`
|
|
31
|
+
`||r[yt]==="\r");if(Ft&>>0&&yt++,Ft){if(((Vt=et.top)==null?void 0:Vt.width)>0){const Ht=z+gt*_-et.top.offset;t.strokeStyle=et.top.color||"#000000",t.lineWidth=et.top.width,t.beginPath();const Kt=-n/2+_*.2;t.moveTo(Kt,Ht),t.lineTo(n/2-_*.2,Ht),t.stroke()}if(((Yt=et.bottom)==null?void 0:Yt.width)>0){const Ht=z+(gt+1)*_-et.bottom.offset;t.strokeStyle=et.bottom.color||"#000000",t.lineWidth=et.bottom.width,t.beginPath();const Kt=-n/2+_*.2;t.moveTo(Kt,Ht),t.lineTo(n/2-_*.2,Ht),t.stroke()}}yt+=(Ot.text||"").length})}if(e.stroke&&e.stroke.width>0){const yt=t.globalAlpha;e.fill&&e.fill.type!=="None"&&e.fill.isEnabled!==!1&&e.fill.opacity!==0&&e.fill.color!=="transparent"&&e.fill.color!=="rgba(0,0,0,0)"&&(t.shadowColor="transparent",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),t.strokeStyle=e.stroke.color,t.lineWidth=e.stroke.width,t.globalAlpha=yt*this.normalizeOpacity(e.stroke.opacity??100);let gt=0,Mt=z;(B||[]).forEach(Ft=>{let Vt=-L/2;M==="center"?Vt=0:M==="right"&&(Vt=L/2),V(Ft.text,Vt,Mt,!0,gt),gt+=(Ft.text||"").length,Mt+=_,gt<r.length&&(r[gt]===`
|
|
32
|
+
`||r[gt]==="\r")&&(O>0&&(Mt+=O),gt++,r[gt-1]==="\r"&&r[gt]===`
|
|
33
|
+
`&>++)}),t.globalAlpha=yt}}}applyStrokeAlignment(t,i,o,e,s,n){if(!i.stroke||i.stroke.width<=0||i.stroke.isEnabled===!1)return;const a=i.stroke,l=a.width,c=(a.alignment||"center").toLowerCase();if(t.save(),i.fill&&i.fill.type!=="None"&&i.fill.isEnabled!==!1&&i.fill.opacity!==0&&i.fill.color!=="transparent"&&i.fill.color!=="rgba(0,0,0,0)"&&(t.shadowColor="transparent",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),a.fill){const y=this.createCanvasFill(t,a.fill,e,s);y?t.strokeStyle=y:t.strokeStyle=a.color||"#000000"}else t.strokeStyle=a.color||"#000000";const r=t.globalAlpha;t.globalAlpha=r*this.normalizeOpacity(a.opacity??100),t.lineWidth=l,t.lineCap=a.lineCap||"round",t.lineJoin=a.lineJoin||"round",a.miterLimit!==void 0&&(t.miterLimit=a.miterLimit);const u=a.trimStart??0,f=a.trimEnd??1,d=a.trimOffset??0,p=a.dashOffset??0,m=a.dashArray||[];if(u!==0||f!==1||d!==0){const y=this.getPerimeter(o,e,s);if(y>0){const b=Math.max(0,Math.min(1,u)),v=Math.max(0,Math.min(1,f));if(b<v){const S=y*(v-b),C=y-S,w=-(y*(b+d%1));t.setLineDash([S,C]),t.lineDashOffset=w+p*y}else if(b===v)t.setLineDash([0,y]);else{const S=y*(1-b+v),C=y-S,w=-(y*b);t.setLineDash([S,C]),t.lineDashOffset=w+p*y}}}else m.length>0&&(t.setLineDash(m),t.lineDashOffset=p);(o==null?void 0:o.type)==="Line"||e===0||s===0?(this.applyPath(t,o,e,s,n),t.stroke()):c==="inside"?(t.lineWidth=l*2,t.save(),this.applyPath(t,o,e,s,n),t.clip(),t.stroke(),t.restore()):c==="outside"?(t.lineWidth=l*2,this.applyPath(t,o,e,s,n),t.stroke(),t.save(),t.globalCompositeOperation="destination-out",this.applyPath(t,o,e,s,n),t.fill(),t.restore()):(t.lineWidth=l,this.applyPath(t,o,e,s,n),t.stroke()),t.restore()}getPerimeter(t,i,o){switch(this.ensurePathPoints(t),t==null?void 0:t.type){case"Rectangle":return(i+o)*2;case"Ellipse":{const e=Math.abs(i)/2,s=Math.abs(o)/2,n=Math.abs(t.sweepAngle??360),a=t.ratio||0,l=Math.PI*(3*(e+s)-Math.sqrt((3*e+s)*(e+3*s)));if(n>=360&&a<=0)return l;let c=n/360*l;if(a>0){const h=Math.PI*(3*(e*a+s*a)-Math.sqrt((3*e*a+s*a)*(e*a+3*s*a)));c+=n/360*h,n<360&&(c+=2*Math.sqrt((e-e*a)**2+(s-s*a)**2))}else n<360&&(c+=2*Math.max(e,s));return isNaN(c)?0:c}case"Line":return t.length||Math.sqrt(i*i+o*o);case"Triangle":return i+Math.sqrt((i/2)**2+o**2)*2;case"Polygon":{const e=t.sides||3,s=t.radius||Math.min(i,o)/2;return 2*e*s*Math.sin(Math.PI/e)}case"Star":{const e=t.points||5,s=t.outer_radius||Math.min(i,o)/2,n=t.inner_radius||s/2,a=Math.PI/e;return Math.sqrt(s*s+n*n-2*s*n*Math.cos(a))*e*2}case"Path":{const e=t.points||[];if(e.length<2)return t.length||0;let s=0,n=e[0].x,a=e[0].y;for(let l=1;l<e.length;l++){const c=e[l];if(c.moveTo){n=c.x,a=c.y;continue}const h=n,r=a,u=e[l-1].out_x,f=e[l-1].out_y;if(u!==void 0||c.in_x!==void 0?s+=this.getBezierLength(h,r,u??h,f??r,c.in_x??c.x,c.in_y??c.y,c.x,c.y):s+=Math.sqrt((c.x-h)**2+(c.y-r)**2),n=c.x,a=c.y,c.closePath||l===e.length-1&&(t.is_closed||t.isClosed)){const d=n,p=a,m=[...e.slice(0,l+1)].reverse().find(M=>M.moveTo)||e[0],y=m.x,b=m.y,v=e[l].out_x,S=e[l].out_y,C=m.in_x,w=m.in_y;v!==void 0||C!==void 0?s+=this.getBezierLength(d,p,v??d,S??p,C??y,w??b,y,b):s+=Math.sqrt((y-d)**2+(b-p)**2)}}return s}default:return(i+o)*2}}getBezierLength(t,i,o,e,s,n,a,l,c=10){let h=0,r=t,u=i;for(let f=1;f<=c;f++){const d=f/c,p=1-d,m=d*d,y=p*p,b=y*p,v=m*d,S=b*t+3*y*d*o+3*p*m*s+v*a,C=b*i+3*y*d*e+3*p*m*n+v*l,w=S-r,M=C-u;h+=Math.sqrt(w*w+M*M),r=S,u=C}return h}getBezierTAtLength(t,i,o,e,s,n,a,l,c,h=20){if(t<=0)return 0;let r=0,u=i,f=o;for(let d=1;d<=h;d++){const p=d/h,m=1-p,y=p*p,b=m*m,v=b*m,S=y*p,C=v*i+3*b*p*e+3*m*y*n+S*l,w=v*o+3*b*p*s+3*m*y*a+S*c,M=C-u,I=w-f,k=Math.sqrt(M*M+I*I);if(r+k>=t){const T=t-r,O=k===0?0:T/k;return(d-1+O)/h}r+=k,u=C,f=w}return 1}getPointOnPath(t,i,o,e){if(this.ensurePathPoints(t),(t==null?void 0:t.type)==="Path"){const s=t.points||[];if(s.length<2)return{x:0,y:0,angle:0};let n=1/0,a=-1/0,l=1/0,c=-1/0;s.forEach(b=>{typeof b.x=="number"&&typeof b.y=="number"&&(n=Math.min(n,b.x),a=Math.max(a,b.x),l=Math.min(l,b.y),c=Math.max(c,b.y),b.out_x!==void 0&&(n=Math.min(n,b.out_x),a=Math.max(a,b.out_x)),b.out_y!==void 0&&(l=Math.min(l,b.out_y),c=Math.max(c,b.out_y)),b.in_x!==void 0&&(n=Math.min(n,b.in_x),a=Math.max(a,b.in_x)),b.in_y!==void 0&&(l=Math.min(l,b.in_y),c=Math.max(c,b.in_y)))});const h=(n+a)/2,r=(l+c)/2,f=this.getPerimeter(t,i,o)*e;let d=0;const p=[];let m=s[0],y=s[0];for(let b=1;b<s.length;b++){const v=s[b];if(v.moveTo){m=v,y=v;continue}p.push({p0:m,p1:v}),(v.closePath||b===s.length-1&&(t.is_closed||t.isClosed))&&p.push({p0:v,p1:y}),m=v}for(const b of p){const v=b.p0,S=b.p1;let C=0;const w=v.out_x!==void 0||S.in_x!==void 0;if(w?C=this.getBezierLength(v.x,v.y,v.out_x??v.x,v.out_y??v.y,S.in_x??S.x,S.in_y??S.y,S.x,S.y):C=Math.sqrt((S.x-v.x)**2+(S.y-v.y)**2),d+C>=f||b===p[p.length-1]){let M=0;if(w)return M=this.getBezierTAtLength(f-d,v.x,v.y,v.out_x??v.x,v.out_y??v.y,S.in_x??S.x,S.in_y??S.y,S.x,S.y,20),this.getBezierPointAndAngle(M,v,S,h,r);{M=C===0?0:(f-d)/C;const I=v.x+(S.x-v.x)*M-h,k=v.y+(S.y-v.y)*M-r,T=Math.atan2(S.y-v.y,S.x-v.x);return{x:I,y:k,angle:T}}}d+=C}}else if(t.type==="Ellipse"){const s=Math.abs(i)/2,n=Math.abs(o)/2,a=t.sweepAngle??360,c=((t.startAngle??0)+a*e)*Math.PI/180,h=s*Math.cos(c),r=n*Math.sin(c),u=-s*Math.sin(c),f=n*Math.cos(c),d=Math.atan2(f,u);return{x:h,y:r,angle:d}}else if((t==null?void 0:t.type)==="Rectangle"){const s=Math.abs(i),n=Math.abs(o),l=(s+n)*2*e;let c=0,h=0,r=0;return l<s?(c=-s/2+l,h=-n/2,r=0):l<s+n?(c=s/2,h=-n/2+(l-s),r=Math.PI/2):l<2*s+n?(c=s/2-(l-(s+n)),h=n/2,r=Math.PI):(c=-s/2,h=n/2-(l-(2*s+n)),r=-Math.PI/2),{x:c,y:h,angle:r}}return{x:0,y:0,angle:0}}getBezierPointAndAngle(t,i,o,e,s){const n=i.x,a=i.y,l=i.out_x??i.x,c=i.out_y??i.y,h=o.in_x??o.x,r=o.in_y??o.y,u=o.x,f=o.y,d=1-t,p=t*t,m=d*d,y=m*d,b=p*t,v=y*n+3*m*t*l+3*d*p*h+b*u-e,S=y*a+3*m*t*c+3*d*p*r+b*f-s,C=3*m*(l-n)+6*d*t*(h-l)+3*p*(u-h),w=3*m*(c-a)+6*d*t*(r-c)+3*p*(f-r),M=Math.atan2(w,C);return{x:v,y:S,angle:M}}applyAbsoluteTransform(t,i,o){if(!o.get(i))return;const s=[];let n=i;for(;n;){s.unshift(n);const a=o.get(n);n=a==null?void 0:a.parentId}s.forEach(a=>{this.applyObjectTransform(t,a)})}applyObjectTransform(t,i){const o=this.objectStates.get(i);if(!o)return;t.translate(o.x,o.y),t.rotate(o.rotation*Math.PI/180);const e=(o.scale_x??1)*(o.flip_x===!0?-1:1),s=(o.scale_y??1)*(o.flip_y===!0?-1:1);t.scale(e,s)}applyArtEffectOverlay(t,i,o,e,s,n){var f,d,p,m,y;const a=this.objectStates.get(i.id),l=((f=a==null?void 0:a.style)==null?void 0:f.artEffect)||i.artEffect||((d=i.style)==null?void 0:d.artEffect);if(!l||!l.enabled)return;const c=l.type,h=l.intensity??.5,r=l.speed??1,u=l.scale??10;if(c==="acid_gradient"||c==="acid_rave"||c==="shimmer"||c==="glint_overlay"||c==="halftone"||c==="noise"||c==="scanlines"||c==="chromatic_aberration"||c==="pixelate"||c==="glitch"||c==="fold_overlay"||c==="crumple_overlay"){if(t.save(),this.applyPath(t,o,e,s,n),t.clip(),c==="shimmer"){const v=this.currentTime*r%2/2,S=t.createLinearGradient(-e,-s,e,s);S.addColorStop(Math.max(0,v-.2),"rgba(255,255,255,0)"),S.addColorStop(v,`rgba(255,255,255,${h*.8})`),S.addColorStop(Math.min(1,v+.2),"rgba(255,255,255,0)"),t.fillStyle=S,t.globalCompositeOperation="screen",t.fillRect(-e/2,-s/2,e,s),t.globalCompositeOperation="source-over"}else if(c==="glint_overlay"){let S=((this._lastPointerPos||{x:0}).x-(((p=i.transform)==null?void 0:p.x)??0)+300)/600;S=Math.max(-.2,Math.min(1.2,S));const C=t.createLinearGradient(-e,-s,e,s);C.addColorStop(Math.max(0,S-.15),"rgba(255,255,255,0)"),C.addColorStop(Math.max(0,Math.min(1,S)),`rgba(255,255,255,${h})`),C.addColorStop(Math.min(1,S+.15),"rgba(255,255,255,0)"),t.fillStyle=C,t.globalCompositeOperation="screen",t.fillRect(-e/2,-s/2,e,s),t.globalCompositeOperation="source-over"}else if(c==="fold_overlay"){const b=this._lastPointerPos||{x:0,y:0},v=b.x-(((m=i.transform)==null?void 0:m.x)??0),S=b.y-(((y=i.transform)==null?void 0:y.y)??0),C=t.createLinearGradient(v>0?-e/2:e/2,S>0?-s/2:s/2,v>0?e/2:-e/2,S>0?s/2:-s/2);C.addColorStop(0,`rgba(0,0,0,${h*.6})`),C.addColorStop(.4,"rgba(0,0,0,0)"),C.addColorStop(.5,`rgba(255,255,255,${h*.4})`),C.addColorStop(1,`rgba(0,0,0,${h*.2})`),t.fillStyle=C,t.globalCompositeOperation="overlay",t.fillRect(-e/2,-s/2,e,s),t.globalCompositeOperation="source-over",t.beginPath(),v>0&&S>0?(t.moveTo(e/2-40,s/2),t.lineTo(e/2,s/2-40),t.lineTo(e/2-40,s/2-40)):v<0&&S>0?(t.moveTo(-e/2+40,s/2),t.lineTo(-e/2,s/2-40),t.lineTo(-e/2+40,s/2-40)):v>0&&S<0?(t.moveTo(e/2-40,-s/2),t.lineTo(e/2,-s/2+40),t.lineTo(e/2-40,-s/2+40)):(t.moveTo(-e/2+40,-s/2),t.lineTo(-e/2,-s/2+40),t.lineTo(-e/2+40,-s/2+40)),t.closePath(),t.fillStyle="#ffffff",t.shadowColor="rgba(0,0,0,0.5)",t.shadowBlur=10,t.shadowOffsetX=v>0?-2:2,t.shadowOffsetY=S>0?-2:2,t.fill()}else if(c==="crumple_overlay"){const b=Math.floor(e/u),v=document.createElement("canvas");v.width=b,v.height=Math.floor(s/u);const S=v.getContext("2d"),C=S.createImageData(v.width,v.height);for(let w=0;w<C.data.length;w+=4){const M=Math.random()>.95?150:255;C.data[w]=M,C.data[w+1]=M,C.data[w+2]=M,C.data[w+3]=255*h}S.putImageData(C,0,0),t.globalCompositeOperation="multiply",t.imageSmoothingEnabled=!1,t.drawImage(v,-e/2,-s/2,e,s)}else if(c==="acid_gradient"||c==="acid_rave"){const b=this.currentTime*r,v=l.color1,S=l.color2,C=t.createLinearGradient(-e/2,-s/2,e/2,s/2);if(v&&S){const w=b*60%360;C.addColorStop(0,this._shiftHue(v,w,h*.7)),C.addColorStop(1,this._shiftHue(S,(w+180)%360,h*.7))}else{const w=b*100%360,M=(w+180)%360;C.addColorStop(0,`hsla(${w}, 80%, 50%, ${h*.5})`),C.addColorStop(1,`hsla(${M}, 80%, 50%, ${h*.5})`)}t.fillStyle=C,t.globalCompositeOperation="screen",t.fillRect(-e/2,-s/2,e,s)}else if(c==="halftone"){const b=Math.max(2,u*(1-h*.8)),v=document.createElement("canvas");v.width=b,v.height=b;const S=v.getContext("2d");if(S){S.fillStyle="black",S.beginPath(),S.arc(b/2,b/2,b/2*h,0,Math.PI*2),S.fill();const C=t.createPattern(v,"repeat");C&&(t.globalAlpha=.3*h,t.fillStyle=C,t.fillRect(-e/2,-s/2,e,s))}}else if(c==="noise"){const b=Math.floor(e*s*h*.02);t.globalAlpha=.4*h;for(let v=0;v<b;v++){const S=Math.random()>.5?255:0;t.fillStyle=`rgba(${S}, ${S}, ${S}, ${.5+Math.random()*.5})`,t.fillRect(-e/2+Math.random()*e,-s/2+Math.random()*s,2,2)}}else if(c==="scanlines"){t.globalAlpha=.2*h,t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1;for(let b=-s/2;b<s/2;b+=4)t.beginPath(),t.moveTo(-e/2,b),t.lineTo(e/2,b),t.stroke()}else if(c==="chromatic_aberration"){const b=5*h;t.globalCompositeOperation="screen",t.globalAlpha=.5,t.fillStyle="cyan",t.fillRect(-e/2-b,-s/2,e,s),t.fillStyle="magenta",t.fillRect(-e/2+b,-s/2,e,s)}else if(c==="pixelate"){const b=Math.max(2,Math.round(u*(1-h*.5))),v=document.createElement("canvas"),S=Math.max(1,Math.ceil(e/b)),C=Math.max(1,Math.ceil(s/b));v.width=S,v.height=C;const w=v.getContext("2d");if(w){w.imageSmoothingEnabled=!1;const M=t.getTransform(),I=M.e-e/2,k=M.f-s/2;w.drawImage(t.canvas,I,k,e,s,0,0,S,C),t.imageSmoothingEnabled=!1,t.drawImage(v,0,0,S,C,-e/2,-s/2,e,s),t.imageSmoothingEnabled=!0}}else if(c==="glitch"){const b=this.currentTime*r,v=l.chaosAmount??.2,S=Math.max(3,Math.floor(8*h)),C=h*e*.15;t.globalCompositeOperation="screen",t.globalAlpha=h*.4;const w=C*.3;t.fillStyle="rgba(255, 0, 0, 0.4)",t.fillRect(-e/2+w,-s/2,e,s),t.fillStyle="rgba(0, 255, 255, 0.4)",t.fillRect(-e/2-w,-s/2,e,s),t.globalCompositeOperation="source-over",t.globalAlpha=1;const M=s/S;for(let I=0;I<S;I++){const k=Math.sin(I*127.1+b*311.7*r)*43758.5,T=k-Math.floor(k);if(T>1-v){const O=(T-(1-v))/v*C*(Math.random()>.5?1:-1),P=-s/2+I*M,_=t.getTransform(),A=_.e-e/2+O,x=_.f+P;t.save(),t.beginPath(),t.rect(-e/2,P,e,M),t.clip(),t.globalAlpha=.8,t.drawImage(t.canvas,A,x,e,M,-e/2+O,P,e,M),t.restore()}}}t.restore()}}_shiftHue(t,i,o){let e=0,s=0,n=0;if(t.startsWith("#")){const f=t.replace("#","");e=parseInt(f.substring(0,2),16)/255,s=parseInt(f.substring(2,4),16)/255,n=parseInt(f.substring(4,6),16)/255}const a=Math.max(e,s,n),l=Math.min(e,s,n);let c=0,h=0,r=(a+l)/2;if(a!==l){const f=a-l;switch(h=r>.5?f/(2-a-l):f/(a+l),a){case e:c=((s-n)/f+(s<n?6:0))/6;break;case s:c=((n-e)/f+2)/6;break;case n:c=((e-s)/f+4)/6;break}}return`hsla(${(((c*360+i)%360+360)%360).toFixed(0)}, ${(h*100).toFixed(0)}%, ${(r*100).toFixed(0)}%, ${o})`}applyBackgroundBlurGlass(t,i,o,e,s,n){const a=n.radius??10,l=n.color??"rgba(255,255,255,0.2)",c=n.opacity??.5,h=n.noise??0;t.save(),this.applyPath(t,i,o,e,s),t.clip();const r=t.getTransform(),u=r.e-o/2,f=r.f-e/2;try{const p=document.createElement("canvas");p.width=Math.max(1,Math.ceil(o)),p.height=Math.max(1,Math.ceil(e));const m=p.getContext("2d");if(m){m.drawImage(t.canvas,u,f,o,e,0,0,o,e),m.filter=`blur(${a}px)`;const y=document.createElement("canvas");y.width=p.width,y.height=p.height;const b=y.getContext("2d");b.filter=`blur(${a}px)`,b.drawImage(p,0,0),t.globalCompositeOperation="source-over",t.globalAlpha=1,t.drawImage(y,-o/2,-e/2,o,e)}}catch{}t.globalCompositeOperation="source-over",t.globalAlpha=c,t.fillStyle=l,t.fillRect(-o/2,-e/2,o,e),t.globalAlpha=1,t.globalCompositeOperation="source-atop";const d=t.createLinearGradient(-o/2,-e/2,o/2,e/2);if(d.addColorStop(0,"rgba(255,255,255,0.12)"),d.addColorStop(.3,"rgba(255,255,255,0.04)"),d.addColorStop(.5,"rgba(255,255,255,0.0)"),d.addColorStop(1,"rgba(255,255,255,0.0)"),t.fillStyle=d,t.fillRect(-o/2,-e/2,o,e),h>0){if(t.globalAlpha=h/100,!this._noiseTileCanvas){const m=document.createElement("canvas");m.width=64,m.height=64;const y=m.getContext("2d"),b=y.createImageData(64,64),v=b.data;for(let S=0;S<v.length;S+=4){const C=Math.floor(Math.random()*255);v[S]=C,v[S+1]=C,v[S+2]=C,v[S+3]=18}y.putImageData(b,0,0),this._noiseTileCanvas=m}const p=t.createPattern(this._noiseTileCanvas,"repeat");p&&(t.fillStyle=p,t.fillRect(-o/2,-e/2,o,e))}t.restore(),t.save(),t.globalAlpha=1,t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1.5,this.applyPath(t,i,o,e,s),t.stroke(),t.restore()}applyPath(t,i,o,e,s){i!=null&&i.data&&(i.type==="Path"||i.type==="Subtract"||i.type==="Union"||i.type==="Intersect"||i.type==="Exclude"||i.type),t.beginPath(),this._tracePath(t,i,o,e,s)}_tracePath(t,i,o,e,s){if(i){if(this.ensurePathPoints(i),(i==null?void 0:i.type)==="Rectangle"||i.type==="Image"){const n=s!==void 0?s:i.corner_radius??0;this.drawRoundRect(t,-o/2,-e/2,o,e,n)}else if(i.type==="Line")t.moveTo(-o/2,0),t.lineTo(o/2,0);else if(i.type==="Ellipse"){const{startAngle:n=0,sweepAngle:a=360,ratio:l=0}=i,c=o/2,h=e/2,r=n*Math.PI/180,u=a*Math.PI/180,f=r+u;a>=360&&l<=0?t.ellipse(0,0,c,h,0,0,Math.PI*2):(t.ellipse(0,0,c,h,0,r,f,!1),l>0?t.ellipse(0,0,c*l,h*l,0,f,r,!0):t.lineTo(0,0),t.closePath())}else if(i.type==="Triangle")t.moveTo(0,-e/2),t.lineTo(o/2,e/2),t.lineTo(-o/2,e/2),t.closePath();else if(i.type==="Polygon"){const n=i.sides||3,a=i.radius||Math.min(o,e)/2;for(let l=0;l<n;l++){const c=l*2*Math.PI/n-Math.PI/2,h=a*Math.cos(c),r=a*Math.sin(c);l===0?t.moveTo(h,r):t.lineTo(h,r)}t.closePath()}else if(i.type==="Star"){const n=i.points||5,a=i.outer_radius||Math.min(o,e)/2;let l=i.inner_radius;l==null?l=a*.382:l<=1&&(l=a*l);for(let c=0;c<n*2;c++){const h=c*Math.PI/n-Math.PI/2,r=c%2===0?a:l,u=r*Math.cos(h),f=r*Math.sin(h);c===0?t.moveTo(u,f):t.lineTo(u,f)}t.closePath()}else if(((i==null?void 0:i.type)==="Path"||i.type==="Subtract"||i.type==="Union"||i.type==="Intersect"||i.type==="Exclude"||i.type==="BooleanOperation")&&i.points){this.frameCount%300===0&&this.log("[Engine] Tracing Path:",i.points.length,"points");let n=1/0,a=-1/0,l=1/0,c=-1/0;if(i.points.forEach(u=>{typeof u.x=="number"&&typeof u.y=="number"&&(n=Math.min(n,u.x),a=Math.max(a,u.x),l=Math.min(l,u.y),c=Math.max(c,u.y),u.out_x!==void 0&&(n=Math.min(n,u.out_x),a=Math.max(a,u.out_x)),u.out_y!==void 0&&(l=Math.min(l,u.out_y),c=Math.max(c,u.out_y)),u.in_x!==void 0&&(n=Math.min(n,u.in_x),a=Math.max(a,u.in_x)),u.in_y!==void 0&&(l=Math.min(l,u.in_y),c=Math.max(c,u.in_y)))}),n===1/0)return;const h=(n+a)/2,r=(l+c)/2;if(isNaN(h)||isNaN(r)){this.warn("[Engine] Invalid path center:",h,r);return}i.points.forEach((u,f)=>{if(f===0||u.moveTo)t.moveTo(u.x-h,u.y-r);else{const d=i.points[f-1];if(!d)return;const p=(d.out_x??d.x)-h,m=(d.out_y??d.y)-r,y=(u.in_x??u.x)-h,b=(u.in_y??u.y)-r;isNaN(p)||isNaN(y)||isNaN(u.x)?t.lineTo(u.x-h,u.y-r):t.bezierCurveTo(p,m,y,b,u.x-h,u.y-r)}if(u.closePath||f===i.points.length-1&&(i.is_closed||i.isClosed)){const d=[...i.points.slice(0,f+1)].reverse().find(p=>p.moveTo)||i.points[0];d&&(u.out_x!==void 0||d.in_x!==void 0)&&t.bezierCurveTo((u.out_x??u.x)-h,(u.out_y??u.y)-r,(d.in_x??d.x)-h,(d.in_y??d.y)-r,d.x-h,d.y-r),t.closePath()}})}else if(i.points&&Array.isArray(i.points)){let n=1/0,a=-1/0,l=1/0,c=-1/0;i.points.forEach(u=>{n=Math.min(n,u.x),a=Math.max(a,u.x),l=Math.min(l,u.y),c=Math.max(c,u.y)});const h=(n+a)/2,r=(l+c)/2;i.points.forEach((u,f)=>{if(f===0)t.moveTo(u.x-h,u.y-r);else{const d=i.points[f-1];d.out_x!==void 0||u.in_x!==void 0?t.bezierCurveTo((d.out_x??d.x)-h,(d.out_y??d.y)-r,(u.in_x??u.x)-h,(u.in_y??u.y)-r,u.x-h,u.y-r):t.lineTo(u.x-h,u.y-r)}(u.closePath||f===i.points.length-1&&(i.is_closed||i.isClosed))&&t.closePath()})}}}renderInputBox(t,i){var F,$;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=((F=i.geometry)==null?void 0:F.width)||250,n=(($=i.geometry)==null?void 0:$.height)||45,a=this.focusedId===i.id,l=this.lastHoveredObjectId===i.id,c=e.previewState||"default",h=c!=="default"?c:a?"focused":l?"hovered":"default",r=e.label||{visible:!0,text:"Label"},u=e.helperText||{visible:!1,text:"Helper text"},f=e.leftIcon||{visible:!1},d=e.rightIcon||{visible:!1},p=e.multiline===!0,m=e.corner_radius??8,y=e.corners||{tl:m,tr:m,bl:m,br:m},b=[y.tl,y.tr,y.br,y.bl];let v=e.backgroundColor||"rgba(31, 41, 55, 1)",S=e.borderColor||"rgba(55, 65, 81, 1)",C=e.borderWidth??1.5,w=e.color||"#ffffff",M=e.placeholderColor||"rgba(156, 163, 175, 1)",I=e.fontSize||14;const k=`${h}Style`,T=e[k];T?(T.backgroundColor!==void 0&&(v=T.backgroundColor),T.borderColor!==void 0&&(S=T.borderColor),T.borderWidth!==void 0&&(C=T.borderWidth),T.color!==void 0&&(w=T.color),T.placeholderColor!==void 0&&(M=T.placeholderColor),T.fontSize!==void 0&&(I=T.fontSize)):h==="focused"?(S=e.focusBorderColor||"rgba(59, 130, 246, 1)",C=Math.max(C,2)):h==="hovered"||h==="hover"?(S=e.hoverBorderColor||S,v=e.hoverBackgroundColor||v):h==="disabled"?(v=e.disabledBackgroundColor||"rgba(31, 41, 55, 0.6)",S=e.disabledBorderColor||"rgba(55, 65, 81, 0.4)"):h==="error"&&(S="rgba(239, 68, 68, 1)",C=Math.max(C,2)),t.beginPath(),this.drawRoundRect(t,-s/2,-n/2,s,n,b);const O=this.createCanvasFill(t,v,s,n);if(O&&(t.fillStyle=O,t.fill()),C>0){const V=this.createCanvasFill(t,S,s,n);if(V&&(t.strokeStyle=V,t.lineWidth=C,t.stroke()),h==="focused"||h==="focus"){t.save(),t.beginPath();const tt=b.map(rt=>rt+2);this.drawRoundRect(t,-s/2-2,-n/2-2,s+4,n+4,tt),t.strokeStyle="rgba(59, 130, 246, 0.3)",t.lineWidth=2,t.stroke(),t.restore()}}const P=(V,tt)=>{if(!V.visible||!V.svgPath)return;const rt=V.size||14,mt=V.offset??16,Ct=V.color||"#ffffff",ct=tt?-(s/2)+mt:s/2-mt,Pt=V.svgPath;if(t.save(),t.translate(ct,0),!Pt.startsWith("<svg")){const kt=new Path2D(Pt),Tt=rt/24;t.scale(Tt,Tt),t.translate(-12,-12),t.fillStyle=Ct,t.fill(kt)}t.restore()};P(f,!0),P(d,!1);const _=e.text||"",A=e.placeholder||"Enter text...",x=!_,W=_||A,Y=x?M:w,B=I,X=e.fontFamily||"Inter",q=e.fontWeight||400;t.font=`${q} ${B}px "${X}", sans-serif`,t.fillStyle=Y,t.textAlign="left",t.textBaseline=p?"top":"middle";const j=e.inputPadding??16,E=f.visible?(f.offset??16)+(f.size||14)/2+8:j,L=d.visible?(d.offset??16)+(d.size||14)/2+8:j,G=-(s/2)+E,z=s-E-L,it=e.inputType==="password"?"•".repeat(W.length):W;if(t.save(),t.beginPath(),t.rect(G-2,-n/2+4,z+4,n-8),t.clip(),p){const V=it.split(`
|
|
34
|
+
`);let tt=-n/2+j;const rt=B*1.2;let mt=0;V.forEach((Ct,ct)=>{const Pt=Ct.split(" ");let kt="";for(let Tt=0;Tt<Pt.length;Tt++){const zt=kt+Pt[Tt]+" ";t.measureText(zt).width>z&&Tt>0?(t.fillText(kt,G,tt),kt=Pt[Tt]+" ",tt+=rt):kt=zt}t.fillText(kt,G,tt),mt=t.measureText(kt).width,ct<V.length-1&&(tt+=rt,mt=0)}),a&&!x&&Math.floor(performance.now()/500)%2===0&&t.fillRect(G+mt,tt,1.5,B)}else{const tt=t.measureText(it).width;let rt=0;if(tt>z&&(rt=tt-z),t.fillText(it,G-rt,0),a&&!x&&Math.floor(performance.now()/500)%2===0){const Ct=G+tt-rt;t.fillRect(Ct,-(B/2),1.5,B)}}if(t.restore(),r.visible!==!1){const V=r.text||"Label",tt=r.fontSize||12,rt=r.color||"rgba(156, 163, 175, 1)",mt=r.offset??8;t.font=`600 ${tt}px "${X}", sans-serif`,t.fillStyle=rt,t.textAlign="left",t.textBaseline="bottom";const Ct=-(s/2),ct=-(n/2)-mt;t.fillText(V,Ct,ct)}if(u.visible===!0){const V=u.text||"Helper text",tt=u.fontSize||11,rt=h==="error"?"rgba(239, 68, 68, 1)":u.color||"rgba(156, 163, 175, 1)",mt=u.offset??6;t.font=`400 ${tt}px "${X}", sans-serif`,t.fillStyle=rt,t.textAlign="left",t.textBaseline="top";const Ct=-(s/2),ct=n/2+mt;t.fillText(V,Ct,ct)}}renderSlider(t,i){const o=this.objectStates.get(i.id),e=(o==null?void 0:o.geometry)||i.geometry,s=(o==null?void 0:o.options)||i.options||{},n=e.width||200,a=s.value??50,l=s.min??0,h=(s.max??100)-l,r=h===0?0:(a-l)/h,u=s.trackHeight||4,f=s.trackRoundedness??2,d=s.trackShape??"Rectangle",p=s.trackPath||"",m=s.accentColor||"#3b82f6",y=s.inactiveColor||"#374151",b=s.thumbShape||"Ellipse",v=s.thumbWidth??16,S=s.thumbHeight??16,C=s.thumbRoundedness??0,w=s.thumbColor||"#ffffff",M=s.thumbPath||"",I=s.thumbIcon||"",k=s.showValueTooltip??!1,T=s.tooltipBgColor||"#333333",O=s.tooltipColor||"#ffffff",P=s.tooltipOffsetX??0,_=s.tooltipOffsetY??-25,A=(z,it,F,$,V,tt,rt)=>{if((z==="Custom"||z==="Icon")&&rt)try{const mt=new Path2D(rt);if(t.save(),t.translate(it,F),z==="Icon"){const Ct=Math.min($,V)/24;t.scale(Ct,Ct),t.translate(-12,-12)}t.fill(mt),t.restore();return}catch(mt){console.error("Error drawing slider shape in engine:",mt)}if(t.beginPath(),z==="Ellipse")t.ellipse(it,F,$/2,V/2,0,0,Math.PI*2);else if(z==="Rectangle")this.drawRoundRect(t,it-$/2,F-V/2,$,V,tt);else if(z==="Triangle")t.moveTo(it,F-V/2),t.lineTo(it+$/2,F+V/2),t.lineTo(it-$/2,F+V/2),t.closePath();else if(z==="Diamond")t.moveTo(it,F-V/2),t.lineTo(it+$/2,F),t.lineTo(it,F+V/2),t.lineTo(it-$/2,F),t.closePath();else if(z==="Polygon"){const mt=i.geometry.sides||3,Ct=i.geometry.radius||Math.min($,V)/2;for(let ct=0;ct<mt;ct++){const Pt=ct*2*Math.PI/mt-Math.PI/2,kt=it+Ct*Math.cos(Pt),Tt=F+Ct*Math.sin(Pt);ct===0?t.moveTo(kt,Tt):t.lineTo(kt,Tt)}t.closePath()}else if(z==="Star"){const Ct=Math.min($,V)/2,ct=Ct/2;for(let Pt=0;Pt<10;Pt++){const kt=Pt%2===0?Ct:ct,Tt=Pt*Math.PI/5-Math.PI/2;t.lineTo(it+kt*Math.cos(Tt),F+kt*Math.sin(Tt))}t.closePath()}else z==="Line"&&(t.moveTo(it-$/2,F),t.lineTo(it+$/2,F));t.fill()},x=this.createCanvasFill(t,y,n,u);x&&(t.fillStyle=x,t.strokeStyle=x),d==="Line"?(t.lineWidth=u,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(n/2,0),t.stroke()):A(d,0,0,n,u,f,p);const W=n-v,Y=-n/2+v/2+r*W,B=Y- -n/2;if(B>0){const z=this.createCanvasFill(t,m,n,u);z&&(t.fillStyle=z,t.strokeStyle=z),d==="Line"?(t.lineWidth=u,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(Y,0),t.stroke()):d==="Rectangle"&&(t.beginPath(),this.drawRoundRect(t,-n/2,-u/2,B,u,f),t.fill())}t.save(),t.translate(Y,0);const X=t.getTransform(),q=Math.sqrt(X.a*X.a+X.b*X.b)||1;t.shadowColor="rgba(0,0,0,0.2)",t.shadowBlur=4*q,t.shadowOffsetY=1*q;const j=this.createCanvasFill(t,w,v,S);if(j&&(t.fillStyle=j),A(b,0,0,v,S,C,b==="Icon"?I:M),t.restore(),k){t.save(),t.translate(Y+P,_);const z=Math.round(a).toString();t.font="10px Inter, sans-serif";const it=t.measureText(z),F=6,$=4,V=it.width+F*2,tt=14+$;t.beginPath(),this.drawRoundRect(t,-V/2,-tt/2,V,tt,4),t.fillStyle=T,t.fill(),t.fillStyle=O,t.textAlign="center",t.textBaseline="middle",t.fillText(z,0,0),t.restore()}const E=s.label||{},L=s.helperText||{},G=s.fontFamily||"Inter";if(E.visible!==!1){const z=E.text||"Label",it=E.fontSize||12,F=E.color||"rgba(156, 163, 175, 1)",$=E.offset??8;t.font=`600 ${it}px "${G}", sans-serif`,t.fillStyle=F,t.textAlign="left",t.textBaseline="bottom";const V=-(n/2),tt=-(u/2)-$;t.fillText(z,V,tt)}if(L.visible===!0){const z=L.text||"Helper text",it=L.fontSize||11,F=L.color||"rgba(156, 163, 175, 1)",$=L.offset??6;t.font=`400 ${it}px "${G}", sans-serif`,t.fillStyle=F,t.textAlign="left",t.textBaseline="top";const V=-(n/2),tt=u/2+$;t.fillText(z,V,tt)}}renderDropdown(t,i){var _;const o=this.objectStates.get(i.id);if(!o)return;const e=o.options||i.options||{},s=i.geometry.width||160,n=i.geometry.height||40,a=-s/2,l=-n/2,c=e.corner_radius??6,h=e.disabled||e.previewState==="disabled",r=this.lastHoveredObjectId===i.id||e.previewState==="hover",u=(e.isOpen||e.previewState==="active")&&!h;let f=e.backgroundColor,d=e.borderColor,p=e.color||"#333333";h?(f=e.disabledBackgroundColor||"#f3f4f6",d=e.disabledBorderColor||"#e5e7eb",p=e.disabledColor||"#9ca3af"):u?(f=e.activeBackgroundColor||f,d=e.activeBorderColor||d,p=e.activeColor||p):r&&(f=e.hoverBackgroundColor||f,d=e.hoverBorderColor||d,p=e.hoverColor||p),f||(f="#ffffff"),d||(d="#e5e7eb");const m=t.globalAlpha;t.globalAlpha=m*(e.opacity??1),this.drawRoundRect(t,a,l,s,n,c),t.fillStyle=this.createCanvasFill(t,typeof f=="string"?{type:"Solid",color:f}:f,s,n)||"#ffffff",t.fill();const y=e.borderWidth??1;y>0&&(t.strokeStyle=this.createCanvasFill(t,typeof d=="string"?{type:"Solid",color:d}:d,s,n)||"#e5e7eb",t.lineWidth=y,t.stroke());const b=12,v=e.chevronType||"chevron",S=e.chevronSize||16,C=(u?e.openIconColor:e.closedIconColor)||e.chevronColor||"#6b7280";if(v!=="none"){const A=a+s-b-S/2;t.save(),t.translate(A,0);const x=u?e.openIconAngle??180:e.closedIconAngle??0;if(t.rotate(x*Math.PI/180),t.strokeStyle=C,t.fillStyle=C,t.lineWidth=1.5,t.lineCap="round",t.lineJoin="round",v==="chevron")t.beginPath(),t.moveTo(-S/2,-S*.2),t.lineTo(0,S*.2),t.lineTo(S/2,-S*.2),t.stroke();else if(v==="custom"||v==="path"){const W=u&&e.openIconPath||e.closedIconPath;if(W){const Y=new Path2D(W);t.save();const B=S/24;t.scale(B,B),t.translate(-12,-12),t.fill(Y),t.restore()}}t.restore()}const w=e.selectedOption||e.placeholder||"Select...",M=e.fontSize||14,I=e.fontWeight||400,k=e.fontFamily||"Inter, sans-serif";t.font=`${I} ${M}px ${k}`;const T=h?e.disabledColor||"#9ca3af":!e.selectedOption&&e.placeholder?"#9ca3af":p;t.fillStyle=this.createCanvasFill(t,typeof T=="string"?{type:"Solid",color:T}:T,s,n)||"#333333",t.textAlign="left",t.textBaseline="middle";const O=v==="none"?0:S+8,P=s-b*2-O;if(t.save(),t.beginPath(),t.rect(a+b,l,P,n),t.clip(),t.fillText(w,a+b,0),t.restore(),u&&!h){const A=l+n+4,x=e.optionsList||[],W=e.itemHeight||32,Y=e.listPadding??4,B=x.length*W+Y*2,X=e.listCornerRadius??c;t.save();const q=e.listShadow||{},j=t.getTransform(),E=Math.sqrt(j.a*j.a+j.b*j.b)||1;t.shadowColor=typeof q.color=="string"?q.color:((_=q.color)==null?void 0:_.color)||"rgba(0,0,0,0.15)",t.shadowBlur=(q.blur??12)*E,t.shadowOffsetY=(q.offsetY??6)*E,t.shadowOffsetX=(q.offsetX??0)*E,t.beginPath(),this.drawRoundRect(t,a,A,s,B,X),t.fillStyle=this.createCanvasFill(t,typeof e.listBackgroundColor=="string"?{type:"Solid",color:e.listBackgroundColor}:e.listBackgroundColor||{type:"Solid",color:"#ffffff"},s,B)||"#ffffff",t.fill();const L=e.listBorderWidth??1;L>0&&(t.shadowColor="transparent",t.strokeStyle=this.createCanvasFill(t,typeof e.listBorderColor=="string"?{type:"Solid",color:e.listBorderColor}:e.listBorderColor||{type:"Solid",color:d},s,B)||"#e5e7eb",t.lineWidth=L,t.stroke()),t.restore();const G=e.itemFontSize||M,z=e.itemFontFamily||k;t.font=`${I} ${G}px ${z}`,x.forEach((it,F)=>{const $=A+Y+F*W;if(it===e.selectedOption)t.fillStyle=this.createCanvasFill(t,typeof e.itemSelectedBackgroundColor=="string"?{type:"Solid",color:e.itemSelectedBackgroundColor}:e.itemSelectedBackgroundColor||{type:"Solid",color:"#f3f4f6"},s,W)||"#f3f4f6",t.fillRect(a+L,$,s-L*2,W),t.fillStyle=e.itemSelectedColor||e.accentColor||p||"#374151";else if(t.fillStyle=e.listTextColor||p||"#333333",this.activeDropdownId===i.id&&this._lastPointerPos){const tt=this._lastPointerPos.y-(A+Y),rt=Math.floor(tt/W);F===rt&&(t.fillStyle=this.createCanvasFill(t,typeof e.itemHoverBackgroundColor=="string"?{type:"Solid",color:e.itemHoverBackgroundColor}:e.itemHoverBackgroundColor||{type:"Solid",color:"#f9fafb"},s,W)||"#f9fafb",t.fillRect(a+L,$,s-L*2,W),t.fillStyle=e.itemHoverColor||p)}t.fillText(it,a+b,$+W/2)})}t.globalAlpha=m}renderButton(t,i){if(i.children&&i.children.length>0)return;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=i.geometry||{},n=s.width||120,a=s.height||40,l=this.lastHoveredObjectId===i.id,c=this.activeObjectId===i.id,h=e.label||{},r=e.hoverStyle||{},u=e.activeStyle||{},f=e.icon||{enabled:!1};let d=e.backgroundColor||"#3b82f6",p=h.color||"#ffffff",m=h.text||"Button",y=s.cornerRadius??8,b=e.borderColor||"transparent",v=e.borderWidth||0,S=1;c&&u?(d=u.backgroundColor||d,p=u.color||p,m=u.text||m,S=u.scale??.95,y=u.cornerRadius??y):l&&r&&(d=r.backgroundColor||d,p=r.color||p,m=r.text||m,S=r.scale??1,y=r.cornerRadius??y,b=r.borderColor||b);const C=-n/2,w=-a/2;t.save(),t.scale(S,S),t.beginPath(),this.drawRoundRect(t,C,w,n,a,y);const M=this.createCanvasFill(t,d,n,a);M&&(t.fillStyle=M,t.fill()),(v>0||l&&r.borderColor)&&(t.strokeStyle=b,t.lineWidth=v||(l?1:0),t.stroke());const I=h.fontSize||14,k=h.fontFamily||"Inter",T=h.fontWeight||600;t.font=`${T} ${I}px "${k}", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle=p,t.textAlign="center",t.textBaseline="middle";let O=0;if(f.enabled&&f.svgPath){const P=I*1.1,_=f.gap||8,A=t.measureText(m),W=-(A.width+P+_)/2,Y=f.position==="left"?W+P/2:W+A.width+_+P/2;O=f.position==="left"?W+P+_+A.width/2:W+A.width/2,t.save(),t.translate(Y,0);const B=new Path2D(f.svgPath),X=P/24;t.scale(X,X),t.translate(-12,-12),t.fillStyle=p,t.fill(B),t.restore()}t.fillText(m,O,0),t.restore()}renderToggleButton(t,i){var m,y;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=e.checked??!1,n=((m=i.geometry)==null?void 0:m.width)||120,a=((y=i.geometry)==null?void 0:y.height)||40,l=-n/2,c=-a/2,h=e.corner_radius??8,r=e.label||{},u=s?e.accentColor||"#3b82f6":e.inactiveColor||"#374151",f=s?e.activeTextColor||"#ffffff":e.inactiveTextColor||"#9ca3af";t.save(),t.beginPath(),this.drawRoundRect(t,l,c,n,a,h),t.fillStyle=u,t.fill();const d=r.fontSize||14,p=r.fontFamily||"Inter";t.font=`${r.fontWeight||600} ${d}px "${p}", sans-serif`,t.fillStyle=f,t.textAlign="center",t.textBaseline="middle",t.fillText(r.text||"Toggle",0,0),t.restore()}renderToggle(t,i){var X,q,j,E,L,G,z,it,F,$,V,tt;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=((X=i.geometry)==null?void 0:X.width)||52,n=((q=i.geometry)==null?void 0:q.height)||30,a=-s/2,l=-n/2,c=e.checked??!1,h=e.cornerRadius??e.corner_radius??n/2,r=e.toggleStyle||{},u=r.backgroundColor||e.activeColor||"#10b981",f=r.borderColor||e.borderColor||"transparent",d=r.borderWidth??e.borderWidth??0,p=r.knobColor||e.knobColor||"#ffffff",m=c?u:e.inactiveColor||"#374151",y=c?f:e.borderColor||"transparent",b=c?d:e.borderWidth??0,v=c?p:e.knobColor||"#ffffff";e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,l,s,n,h);const S=this.createCanvasFill(t,m,s,n);if(S&&(t.fillStyle=S,t.fill()),b>0){t.lineWidth=b;const rt=this.createCanvasFill(t,y,s,n);rt&&(t.strokeStyle=rt,t.stroke())}const C=2,w=n-C*2,M=w/2,I=a+C,k=a+s-C-w,T=c?k:I,O=l+C;t.beginPath(),t.arc(T+M,O+M,M,0,Math.PI*2);const P=this.createCanvasFill(t,v,w,w);P&&(t.fillStyle=P,t.fill()),e.disabled&&(t.globalAlpha*=2);let _=!1,A=!1;const x=(c?(j=r.leftLabel)==null?void 0:j.text:null)||((E=e.leftLabel)==null?void 0:E.text)||"",W=(c?(L=r.leftLabel)==null?void 0:L.color:null)||((G=e.leftLabel)==null?void 0:G.color)||"#f3f4f6";if((z=e.leftLabel)!=null&&z.enabled&&x){const rt=e.leftLabel;t.font=`${rt.fontWeight||400} ${rt.fontSize||12}px "${rt.fontFamily||"Inter"}", sans-serif`,t.fillStyle=W,t.textBaseline="middle",t.textAlign="right",t.fillText(x,a-(rt.gap||8),0),_=!0}const Y=(c?(it=r.rightLabel)==null?void 0:it.text:null)||((F=e.rightLabel)==null?void 0:F.text)||"",B=(c?($=r.rightLabel)==null?void 0:$.color:null)||((V=e.rightLabel)==null?void 0:V.color)||"#f3f4f6";if((tt=e.rightLabel)!=null&&tt.enabled&&Y){const rt=e.rightLabel;t.font=`${rt.fontWeight||400} ${rt.fontSize||12}px "${rt.fontFamily||"Inter"}", sans-serif`,t.fillStyle=B,t.textBaseline="middle",t.textAlign="left",t.fillText(Y,a+s+(rt.gap||8),0),A=!0}if(!_&&!A&&e.label&&e.label.text){const rt=e.label,mt=rt.fontSize||14,Ct=rt.fontWeight||400,ct=rt.fontFamily||"Inter";t.font=`${Ct} ${mt}px "${ct}", sans-serif`,t.fillStyle=rt.color||"#f3f4f6",t.textBaseline="middle";const Pt=rt.gap||10;let kt=0,Tt=0;rt.position==="left"?(t.textAlign="right",kt=a-Pt,Tt=0):rt.position==="right"?(t.textAlign="left",kt=a+s+Pt,Tt=0):rt.position==="top"?(t.textAlign="center",kt=0,Tt=l-Pt,t.textBaseline="bottom"):rt.position==="bottom"?(t.textAlign="center",kt=0,Tt=l+n+Pt,t.textBaseline="top"):(t.textAlign="left",kt=a+s+Pt,Tt=0),t.fillText(rt.text,kt,Tt)}}renderCheckbox(t,i){var S,C;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=((S=i.geometry)==null?void 0:S.width)||20,n=((C=i.geometry)==null?void 0:C.height)||20,a=-s/2,l=-n/2,c=e.cornerRadius??4,h=e.checked??!1,r=e.activeColor||"#3b82f6",u=e.inactiveColor||"transparent",f=e.checkColor||"#ffffff",d=e.borderColor||"#4b5563",p=e.borderWidth??2,m=h?r:u,y=h?"transparent":d,b=h?0:p;e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,l,s,n,c);const v=this.createCanvasFill(t,m,s,n);if(v&&(t.fillStyle=v,t.fill()),b>0){t.lineWidth=b;const w=this.createCanvasFill(t,y,s,n);w&&(t.strokeStyle=w,t.stroke())}else if(h){t.lineWidth=1;const w=this.createCanvasFill(t,r,s,n);w&&(t.strokeStyle=w,t.stroke())}if(h){t.save(),t.beginPath();const w=this.createCanvasFill(t,f,s,n);t.strokeStyle=w||f,t.lineWidth=Math.max(2,s*.12),t.lineCap="round",t.lineJoin="round";const M=a+s*.25,I=l+n*.5,k=a+s*.45,T=l+n*.7,O=a+s*.75,P=l+n*.25;t.moveTo(M,I),t.lineTo(k,T),t.lineTo(O,P),t.stroke(),t.restore()}if(e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const w=e.label;t.save(),t.font=`${w.fontWeight||400} ${w.fontSize||14}px "${w.fontFamily||"Inter"}", sans-serif`,t.fillStyle=w.color||"#f3f4f6",t.textBaseline="middle";const M=w.gap||8;let I=0,k=0;w.position==="left"?(t.textAlign="right",I=a-M,k=0):w.position==="right"?(t.textAlign="left",I=a+s+M,k=0):w.position==="top"?(t.textAlign="center",I=0,k=l-M,t.textBaseline="bottom"):w.position==="bottom"&&(t.textAlign="center",I=0,k=l+n+M,t.textBaseline="top"),t.fillText(w.text,I,k),t.restore()}}renderRadioGroup(t,i){var C,w;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s=((C=i.geometry)==null?void 0:C.width)||180,n=((w=i.geometry)==null?void 0:w.height)||100,a=-s/2,l=-n/2,c=e.selectedValue,h=e.optionsList||["Option 1","Option 2","Option 3"],r=e.orientation||"vertical",u=e.itemGap!==void 0?e.itemGap:16,f=e.activeColor||"#3b82f6",d=e.inactiveColor||"#4b5563",p=e.textColor||"#ffffff",m=e.fontSize||14,y=e.fontFamily||"Inter",b=e.fontWeight||400;e.disabled&&(t.globalAlpha*=.5);const v=8,S=v*2;if(t.save(),t.font=`${b} ${m}px "${y}", sans-serif`,t.textBaseline="middle",t.textAlign="left",r==="vertical"){const M=Math.max(S,m)+u;h.forEach((I,k)=>{const T=l+k*M+v;t.beginPath(),t.arc(a+v,T,v,0,Math.PI*2);const O=c===I,P=this.createCanvasFill(t,f,S,S),_=this.createCanvasFill(t,d,S,S);O?(t.strokeStyle=P||f,t.lineWidth=2,t.stroke(),t.beginPath(),t.arc(a+v,T,v/2,0,Math.PI*2),t.fillStyle=P||f,t.fill()):(t.strokeStyle=_||d,t.lineWidth=1.5,t.stroke()),t.fillStyle=p,t.fillText(I,a+S+8,T)})}else{let M=a;h.forEach(I=>{const k=c===I,T=t.measureText(I).width;t.beginPath(),t.arc(M+v,0,v,0,Math.PI*2);const O=this.createCanvasFill(t,f,S,S),P=this.createCanvasFill(t,d,S,S);k?(t.strokeStyle=O||f,t.lineWidth=2,t.stroke(),t.beginPath(),t.arc(M+v,0,v/2,0,Math.PI*2),t.fillStyle=O||f,t.fill()):(t.strokeStyle=P||d,t.lineWidth=1.5,t.stroke()),t.fillStyle=p,t.fillText(I,M+S+6,0),M+=S+6+T+u})}if(t.restore(),e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const M=e.label;t.save(),t.font=`${M.fontWeight||400} ${M.fontSize||14}px "${M.fontFamily||"Inter"}", sans-serif`,t.fillStyle=M.color||"#9ca3af",t.textBaseline="middle";const I=M.gap||8;let k=0,T=0;M.position==="left"?(t.textAlign="right",k=a-I,T=0):M.position==="right"?(t.textAlign="left",k=a+s+I,T=0):M.position==="top"?(t.textAlign="center",k=0,T=l-I,t.textBaseline="bottom"):M.position==="bottom"&&(t.textAlign="center",k=0,T=l+n+I,t.textBaseline="top"),t.fillText(M.text,k,T),t.restore()}}renderBarChart(t,i){var T,O;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s={width:((T=i.geometry)==null?void 0:T.width)||300,height:((O=i.geometry)==null?void 0:O.height)||180,chartType:e.chartType||"grouped",stylePreset:e.stylePreset||"default",datasets:e.datasets||[{id:"ds-1",label:"Revenue",data:[42,67,31,55,78,48],color:"#6366f1"}],categories:e.categories||["Jan","Feb","Mar","Apr","May","Jun"],orientation:e.orientation||"vertical",barWidth:e.barWidth!==void 0?e.barWidth:14,barGap:e.barGap!==void 0?e.barGap:4,barCornerRadius:e.barCornerRadius!==void 0?e.barCornerRadius:5,showXAxis:!!e.showXAxis,showYAxis:!!e.showYAxis,xAxisColor:e.xAxisColor||"rgba(255,255,255,0.12)",yAxisColor:e.yAxisColor||"rgba(255,255,255,0.12)",showXLabels:e.showXLabels!==void 0?!!e.showXLabels:!0,showYLabels:!!e.showYLabels,axisLabelColor:e.axisLabelColor||"rgba(255,255,255,0.5)",axisLabelFontSize:e.axisLabelFontSize||9,showLegend:e.showLegend!==void 0?!!e.showLegend:!0,legendColor:e.legendColor||"rgba(255,255,255,0.7)",legendFontSize:e.legendFontSize||9,showGridLines:e.showGridLines!==void 0?!!e.showGridLines:!0,gridColor:e.gridColor||"rgba(255,255,255,0.06)",cardBackground:e.cardBackground||"rgba(255,255,255,0.04)",cardBorderColor:e.cardBorderColor||"rgba(255,255,255,0.08)",barGradient:e.barGradient!==void 0?!!e.barGradient:!0,showValueOnTop:!!e.showValueOnTop,chartBackground:e.chartBackground||"transparent",barStyle:e.barStyle||"solid",barBorderWidth:e.barBorderWidth!==void 0?e.barBorderWidth:1,barBorderColor:e.barBorderColor||"auto",enableShadows:!!e.enableShadows,shadowColor:e.shadowColor||"rgba(0,0,0,0.5)",shadowBlur:e.shadowBlur!==void 0?e.shadowBlur:4,shadowOffsetY:e.shadowOffsetY!==void 0?e.shadowOffsetY:2,valueFontSize:e.valueFontSize||10,valueColor:e.valueColor||"auto",valueFontWeight:e.valueFontWeight||"bold",xAxisLineWidth:e.xAxisLineWidth!==void 0?e.xAxisLineWidth:1,yAxisLineWidth:e.yAxisLineWidth!==void 0?e.yAxisLineWidth:1,gridLineWidth:e.gridLineWidth!==void 0?e.gridLineWidth:1,gridLineDash:e.gridLineDash||[3,4],_getPreset:function(){return ds[this.stylePreset]||ds.default},_resolveColor:function(P,_){const A=this._getPreset();return["#6366f1","#f59e0b","#10b981","#3b82f6","#a855f7"].includes(P)?A.colors[_%A.colors.length]:typeof P=="string"?P:A.colors[_%A.colors.length]},_makeGradient:function(P,_,A,x,W,Y){if(!this._getPreset().barGradient&&!this.barGradient)return _;const X=P.createLinearGradient(A,x,W,Y);return X.addColorStop(0,_),X.addColorStop(1,_+"44"),X},_drawRoundedBar:function(P,_,A,x,W,Y,B){if(Y=Math.min(Y,Math.min(Math.abs(x),Math.abs(W))/2),Y<=0||x===0||W===0){P.rect(_,A,x,W);return}P.beginPath(),B?(P.moveTo(_,A+W),P.lineTo(_,A+Y),P.quadraticCurveTo(_,A,_+Y,A),P.lineTo(_+x-Y,A),P.quadraticCurveTo(_+x,A,_+x,A+Y),P.lineTo(_+x,A+W),P.lineTo(_,A+W)):(P.moveTo(_,A),P.lineTo(_+x-Y,A),P.quadraticCurveTo(_+x,A,_+x,A+Y),P.lineTo(_+x,A+W-Y),P.quadraticCurveTo(_+x,A+W,_+x-Y,A+W),P.lineTo(_,A+W),P.lineTo(_,A)),P.closePath()}},n=s.width,a=s.height,l=-n/2,c=-a/2;if(!s.datasets||s.datasets.length===0||s.categories.length===0){t.save(),t.fillStyle="rgba(99,102,241,0.7)",t.font="bold 11px Inter, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("NO CHART DATA",0,0),t.restore();return}const h=s._getPreset();let r=-1/0,u=1/0;const f=s.categories.length,d=s.datasets.length;if(s.chartType==="stacked")for(let P=0;P<f;P++){let _=0,A=0;s.datasets.forEach(x=>{const W=x.data[P]??0;W>=0?_+=W:A+=W}),_>r&&(r=_),A<u&&(u=A)}else s.datasets.forEach(P=>{P.data&&P.data.forEach(_=>{_>r&&(r=_),_<u&&(u=_)})});isFinite(r)||(r=10),isFinite(u)||(u=0),r=Math.max(r,0),u=Math.min(u,0);const p=r-u||10;t.save(),s.enableShadows&&(t.shadowColor=s.shadowColor,t.shadowBlur=s.shadowBlur,t.shadowOffsetY=s.shadowOffsetY),t.font=s.axisLabelFontSize+"px Inter, sans-serif";const m=s.showYLabels?t.measureText(r.toFixed(0)).width+14:10,y=s.showXLabels?s.axisLabelFontSize+12:8,v=(s.showLegend&&d>0?s.legendFontSize+10:0)+8,S=10,C=l+m,w=c+v,M=n-m-S,I=a-v-y;if(s.enableShadows&&(t.shadowColor="transparent"),t.beginPath(),t.roundRect(l,c,n,a,10),t.fillStyle=h.cardBackground,t.fill(),t.strokeStyle=h.cardBorderColor,t.lineWidth=1,t.stroke(),s.chartBackground&&s.chartBackground!=="transparent"&&(t.beginPath(),t.rect(C,w,M,I),t.fillStyle=s.chartBackground,t.fill()),s.showLegend&&d>0){t.font=s.legendFontSize+"px Inter, sans-serif",t.textBaseline="middle";const P=c+12;let _=C;s.datasets.forEach((A,x)=>{const W=s._resolveColor(A.color,x),Y=A.label||"Series "+(x+1),B=7;t.beginPath(),t.roundRect(_,P-B/2,B,B,2),t.fillStyle=W,t.fill(),t.fillStyle=h.legendColor,t.textAlign="left",t.fillText(Y,_+B+4,P),_+=t.measureText(Y).width+B+16})}const k=4;if(s.showGridLines){t.setLineDash(s.gridLineDash||[]),t.lineWidth=s.gridLineWidth||1,t.strokeStyle=h.gridColor;for(let P=0;P<=k;P++)if(s.orientation==="horizontal"){const _=C+P/k*M;t.beginPath(),t.moveTo(_,w),t.lineTo(_,w+I),t.stroke()}else{const _=w+P/k*I;t.beginPath(),t.moveTo(C,_),t.lineTo(C+M,_),t.stroke()}t.setLineDash([])}if(s.showYLabels){t.font=s.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=h.axisLabelColor;for(let P=0;P<=k;P++)if(s.orientation==="horizontal"){const _=u+P/k*p,A=C+P/k*M;t.textAlign="center",t.fillText(_.toFixed(0),A,w+I+s.axisLabelFontSize)}else{const _=r-P/k*p,A=w+P/k*I;t.textAlign="right",t.fillText(_.toFixed(0),C-6,A)}}if(t.setLineDash([]),s.showXAxis&&(t.lineWidth=s.xAxisLineWidth||1,t.strokeStyle=s.xAxisColor,t.beginPath(),t.moveTo(C,w+I),t.lineTo(C+M,w+I),t.stroke()),s.showYAxis&&(t.lineWidth=s.yAxisLineWidth||1,t.strokeStyle=s.yAxisColor,t.beginPath(),t.moveTo(C,w),t.lineTo(C,w+I),t.stroke()),s.enableShadows&&(t.shadowColor=s.shadowColor),s.chartType==="stacked")if(s.orientation==="horizontal"){const P=I/f;for(let _=0;_<f;_++){const A=w+_*P+P/2;s.showXLabels&&(t.font=s.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=h.axisLabelColor,t.shadowColor="transparent",t.fillText(s.categories[_]||"",C-5,A),s.enableShadows&&(t.shadowColor=s.shadowColor));let x=C;s.datasets.forEach((W,Y)=>{const B=W.data[_]??0;if(B===0)return;const X=B/p*M,q=Math.min(s.barWidth*d+s.barGap,P-8),j=A-q/2,E=x;x+=X;const L=s._resolveColor(W.color,Y);t.beginPath(),t.fillStyle=s._makeGradient(t,L,E,j,E+X,j),s._drawRoundedBar(t,E,j,X,q,Y===d-1?s.barCornerRadius:0,!1),s.barStyle==="outline"||s.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=s.barBorderColor==="auto"?L:s.barBorderColor,t.lineWidth=s.barBorderWidth,s.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill()})}}else{const P=M/f;for(let _=0;_<f;_++){const A=C+_*P+P/2;s.showXLabels&&(t.font=s.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillStyle=h.axisLabelColor,t.shadowColor="transparent",t.fillText(s.categories[_]||"",A,w+I+5),s.enableShadows&&(t.shadowColor=s.shadowColor));let x=w+I;s.datasets.forEach((W,Y)=>{const B=W.data[_]??0;if(B===0)return;const X=B/p*I,q=Math.min(s.barWidth*d+s.barGap,P-8),j=A-q/2,E=x-X;x-=X;const L=s._resolveColor(W.color,Y);t.beginPath(),t.fillStyle=s._makeGradient(t,L,j,E,j,E+X),s._drawRoundedBar(t,j,E,q,X,Y===d-1?s.barCornerRadius:0,!0),s.barStyle==="outline"||s.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=s.barBorderColor==="auto"?L:s.barBorderColor,t.lineWidth=s.barBorderWidth,s.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill()})}}else if(s.orientation==="horizontal"){const P=I/f,_=d*s.barWidth+Math.max(0,(d-1)*s.barGap),A=C+(0-u)/p*M;for(let x=0;x<f;x++){const W=w+x*P+P/2;s.showXLabels&&(t.font=s.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=h.axisLabelColor,t.shadowColor="transparent",t.fillText(s.categories[x]||"",C-5,W),s.enableShadows&&(t.shadowColor=s.shadowColor));const Y=W-_/2;s.datasets.forEach((B,X)=>{const q=B.data[x]??0,j=Math.abs(q/p*M);if(j<1)return;const E=Y+X*(s.barWidth+s.barGap),L=q>=0?A:A-j,G=s._resolveColor(B.color,X);t.beginPath(),t.fillStyle=s._makeGradient(t,G,L,E,L+j,E),s._drawRoundedBar(t,L,E,j,s.barWidth,s.barCornerRadius,!1),s.barStyle==="outline"||s.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=s.barBorderColor==="auto"?G:s.barBorderColor,t.lineWidth=s.barBorderWidth,s.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),s.showValueOnTop&&q!==0&&(t.font=(s.valueFontWeight||"bold")+" "+(s.valueFontSize||10)+"px Inter, sans-serif",t.textAlign=q>=0?"left":"right",t.textBaseline="middle",t.fillStyle=s.valueColor==="auto"?G:s.valueColor||"#fff",t.shadowColor="transparent",t.fillText(q.toString(),q>=0?L+j+4:L-4,E+s.barWidth/2),s.enableShadows&&(t.shadowColor=s.shadowColor))})}}else{const P=M/f,_=d*s.barWidth+Math.max(0,(d-1)*s.barGap),A=w+I-(0-u)/p*I;for(let x=0;x<f;x++){const W=C+x*P+P/2;s.showXLabels&&(t.font=s.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillStyle=h.axisLabelColor,t.shadowColor="transparent",t.fillText(s.categories[x]||"",W,w+I+5),s.enableShadows&&(t.shadowColor=s.shadowColor));const Y=W-_/2;s.datasets.forEach((B,X)=>{const q=B.data[x]??0,j=Math.abs(q/p*I);if(j<1)return;const E=Y+X*(s.barWidth+s.barGap),L=q>=0?A-j:A,G=s._resolveColor(B.color,X);t.beginPath(),t.fillStyle=s._makeGradient(t,G,E,L,E,L+j),s._drawRoundedBar(t,E,L,s.barWidth,j,s.barCornerRadius,!0),s.barStyle==="outline"||s.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=s.barBorderColor==="auto"?G:s.barBorderColor,t.lineWidth=s.barBorderWidth,s.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),s.showValueOnTop&&q!==0&&(t.font=(s.valueFontWeight||"bold")+" "+(s.valueFontSize||10)+"px Inter, sans-serif",t.textAlign="center",t.textBaseline=q>=0?"bottom":"top",t.fillStyle=s.valueColor==="auto"?G:s.valueColor||"#fff",t.shadowColor="transparent",t.fillText(q.toString(),E+s.barWidth/2,q>=0?L-4:L+j+4),s.enableShadows&&(t.shadowColor=s.shadowColor))})}}t.restore()}renderPieChart(t,i){var m,y;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.options)||i.options||{},s={width:((m=i.geometry)==null?void 0:m.width)||180,height:((y=i.geometry)==null?void 0:y.height)||180,chartType:e.chartType||"donut",stylePreset:e.stylePreset||"default",slices:e.slices||[{id:"slice-1",label:"Item 1",value:45,color:"#6366f1"}],innerRadius:e.innerRadius!==void 0?e.innerRadius:.55,sliceGap:e.sliceGap!==void 0?e.sliceGap:3,showLabels:!!e.showLabels,labelColor:e.labelColor||"#ffffff",labelFontSize:e.labelFontSize||10,showLegend:e.showLegend!==void 0?!!e.showLegend:!0,legendColor:e.legendColor||"rgba(255,255,255,0.65)",legendFontSize:e.legendFontSize||9,showCenterText:e.showCenterText!==void 0?!!e.showCenterText:!0,centerLabel:e.centerLabel||"Total",centerTextColor:e.centerTextColor||"#ffffff",centerLabelColor:e.centerLabelColor||"rgba(255,255,255,0.4)",_getPreset:function(){return us[this.stylePreset]||us.default},_resolveSliceColor:function(b,v){const S=b.color,C=v,w=this._getPreset();return["#6366f1","#22d3ee","#f59e0b","#ec4899","#34d399","#a855f7","#f87171"].includes(S)?w.colors[C%w.colors.length]:typeof S=="string"?S:w.colors[C%w.colors.length]}},n=s.width,a=s.height;if(!s.slices||s.slices.length===0){t.save(),t.fillStyle="rgba(99,102,241,0.8)",t.font="bold 11px Inter, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("NO PIE DATA",0,0),t.restore();return}const l=s.slices.reduce((b,v)=>b+(v.value||0),0);if(l<=0){t.save(),t.fillStyle="rgba(99,102,241,0.8)",t.font="bold 11px Inter, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("EMPTY DATA",0,0),t.restore();return}const c=s._getPreset();t.save(),t.beginPath(),t.roundRect(-n/2,-a/2,n,a,10),t.fillStyle=c.cardBackground,t.fill(),t.strokeStyle=c.cardBorderColor,t.lineWidth=1,t.stroke();const h=s.showLegend?Math.ceil(s.slices.length/2):0,r=h>0?h*(s.legendFontSize+8)+10:0,u=a-r-16,f=Math.min(n-24,u)/2,d=0,p=-r/2;if(s.chartType==="rose"){const b=Math.max(...s.slices.map(C=>C.value||0)),v=Math.PI*2/s.slices.length,S=f>0?s.sliceGap/f:0;s.slices.forEach((C,w)=>{const M=C.value||0;if(M===0)return;const I=M/b*f,k=-Math.PI/2+w*v+S/2,T=k+v-S,O=s._resolveSliceColor(C,w);if(t.beginPath(),t.moveTo(d,p),t.arc(d,p,I,k,T),t.closePath(),t.fillStyle=O+"cc",t.fill(),t.strokeStyle=O,t.lineWidth=1.5,t.stroke(),s.showLabels){const P=k+(T-k)/2,_=d+I*.65*Math.cos(P),A=p+I*.65*Math.sin(P),x=Math.round(M/l*100);t.save(),t.font=`bold ${s.labelFontSize}px Inter, sans-serif`,t.fillStyle=c.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${x}%`,_,A),t.restore()}})}else{const b=s.chartType==="pie"?0:s.innerRadius,v=f*Math.max(0,b),S=f>0?s.sliceGap/f:0;let C=-Math.PI/2;if(s.slices.forEach((w,M)=>{const I=w.value||0;if(I===0){C+=I/l*Math.PI*2;return}const k=I/l*Math.PI*2,T=C+S/2,O=C+k-S/2;if(O<=T){C+=k;return}const P=s._resolveSliceColor(w,M);if(t.beginPath(),t.fillStyle=P,v<=0?(t.moveTo(d,p),t.arc(d,p,f,T,O),t.lineTo(d,p)):(t.moveTo(d+f*Math.cos(T),p+f*Math.sin(T)),t.arc(d,p,f,T,O),t.arc(d,p,v,O,T,!0),t.closePath()),t.fill(),s.showLabels){const _=T+(O-T)/2,A=v+(f-v)/2,x=d+A*Math.cos(_),W=p+A*Math.sin(_),Y=Math.round(I/l*100);t.save(),t.font=`bold ${s.labelFontSize}px Inter, sans-serif`,t.fillStyle=c.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${Y}%`,x,W),t.restore()}C+=k}),s.chartType==="donut"&&s.showCenterText&&v>14){const w=Math.round(l),M=Math.min(Math.floor(v*.52),20),I=Math.min(Math.floor(v*.26),10);t.textAlign="center",t.textBaseline="middle",t.font=`bold ${M}px Inter, sans-serif`,t.fillStyle=c.centerTextColor,t.fillText(w.toString(),d,p-I*.5),s.centerLabel&&(t.font=`${I}px Inter, sans-serif`,t.fillStyle=c.centerLabelColor,t.fillText(s.centerLabel,d,p+M*.6))}}if(s.showLegend&&s.slices.length>0){t.font=`${s.legendFontSize}px Inter, sans-serif`;const b=2,v=n/b,S=s.legendFontSize+8,C=a/2-r+10,w=-n/2+10;s.slices.forEach((M,I)=>{const k=I%b,T=Math.floor(I/b),O=w+k*v,P=C+T*S,_=s._resolveSliceColor(M,I),A=7;t.beginPath(),t.roundRect(O,P-A/2,A,A,2),t.fillStyle=_,t.fill(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=c.legendColor;const x=Math.round((M.value||0)/l*100),W=`${M.label||"Item"} ${x}%`,Y=v-A-20;let B=W;for(;t.measureText(B).width>Y&&B.length>4;)B=B.slice(0,-4)+"…";t.fillText(B,O+A+4,P)})}t.restore()}renderJoystick(t,i){var p,m,y,b,v;const o=this.objectStates.get(i.id),e=(o==null?void 0:o.width)!==void 0?o.width:((p=i.geometry)==null?void 0:p.width)??i.width??100,s=(o==null?void 0:o.height)!==void 0?o.height:((m=i.geometry)==null?void 0:m.height)??i.height??100,n=Math.min(e,s)*.45,a=Math.min(e,s)*.15;let l=i.handleX||0,c=i.handleY||0;o&&o.handleX!==void 0&&(l=o.handleX),o&&o.handleY!==void 0&&(c=o.handleY),t.save();let h=0,r=0;i.handleOrigin==="top-left"?(h=e/2,r=s/2):i.handleOrigin==="bottom-right"&&(h=-e/2,r=-s/2),t.translate(h,r),t.beginPath(),i.boundsShape==="square"?t.rect(-n,-n,n*2,n*2):t.arc(0,0,n,0,Math.PI*2),t.fillStyle="rgba(0,0,0,0.2)",(y=i.style)!=null&&y.fill&&typeof i.style.fill=="string"?t.fillStyle=i.style.fill:(b=i.style)!=null&&b.fill&&i.style.fill.type==="solid"&&(t.fillStyle=i.style.fill.color),t.fill(),(v=i.style)!=null&&v.stroke&&i.style.stroke.isEnabled!==!1&&(t.lineWidth=i.style.stroke.width||1,t.strokeStyle=i.style.stroke.color||"#000",t.stroke());const u=n-a;let f=0,d=0;i.joystickType==="2D"?(f=l*u,d=c*u):i.joystickType==="1D_X"?(f=l*u,d=0):i.joystickType==="1D_Y"&&(f=0,d=c*u),t.beginPath(),t.arc(f,d,a,0,Math.PI*2),t.fillStyle="#fff",t.fill(),t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1,t.stroke(),t.restore()}getRadioGroupItemIndexAtPointer(t,i,o){var I,k;const e=t.options||{},s=this.objectStates.get(t.id)||{},n=e.optionsList||[];if(n.length===0)return null;const a=s.width!==void 0?s.width:((I=t.geometry)==null?void 0:I.width)||180,l=s.height!==void 0?s.height:((k=t.geometry)==null?void 0:k.height)||100,c=e.orientation||"vertical",h=e.itemGap!==void 0?e.itemGap:16,r=e.fontSize||14,u=this.getWorldTransform(t.id),f=i-u.x,d=o-u.y,p=-u.rotation*(Math.PI/180),m=Math.cos(p),y=Math.sin(p),b=f*m-d*y,v=f*y+d*m,C=8*2,w=-a/2,M=-l/2;if(c==="vertical"){const T=Math.max(C,r)+h;for(let O=0;O<n.length;O++){const P=M+O*T;if(b>=w&&b<=w+a&&v>=P&&v<=P+T)return O}}else{let T=w;for(let O=0;O<n.length;O++){const _=n[O].length*8,A=C+6+_+h;if(b>=T&&b<=T+A&&v>=M&&v<=M+l)return O;T+=A}}return null}renderLineGraph(t,i,o,e){let s=i.datasets||[];if((!s||s.length===0)&&(i.data||i.graphData)&&(s=[{id:"line-1",label:"Series 1",data:i.data||i.graphData||[],lineColor:i.lineColor||"#3b82f6",lineWidth:i.lineWidth||2,showArea:i.showArea||!1,areaColor:i.areaColor||"rgba(139, 92, 246, 0.3)",smoothing:i.smoothing||!1,showPoints:i.showPoints!==void 0?i.showPoints:!0,pointSize:i.pointSize||6,pointFill:i.pointFill||"#ffffff",pointStrokeColor:i.pointStrokeColor||i.lineColor||"#3b82f6",pointStrokeWidth:i.pointStrokeWidth||2}]),!s||s.length===0||!s.some(p=>p.data&&p.data.length>=2)){t.save(),t.fillStyle="#6366f1",t.font="12px Inter, system-ui, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("NO DATA",0,0),t.restore();return}let n=1/0,a=-1/0,l=0;if(s.forEach(p=>{let m=p.data;if(p.isVarEnabled&&p.inputId){let y=this.inputs.get(p.inputId);if(y===void 0){const b=this.inputNameMap.get(p.inputId);b&&b.length>0&&(y=this.inputs.get(b[0]))}y&&Array.isArray(y)&&(m=y)}if(m&&m.length>0){const y=m.filter(b=>typeof b=="number"&&!isNaN(b));y.length>0&&(n=Math.min(n,...y),a=Math.max(a,...y),l=Math.max(l,m.length))}p._resolvedData=m}),l<2)return;const c=a-n,h=o/(l-1),r=p=>{const m=c===0?.5:(p-n)/c;return e/2-m*e},u=p=>p*h-o/2,f=i.axisColor||"#333333";if(i.showXAxis&&(t.beginPath(),t.strokeStyle=i.xAxisColor||f,t.lineWidth=1,t.moveTo(-o/2,e/2),t.lineTo(o/2,e/2),t.stroke()),i.showYAxis&&(t.beginPath(),t.strokeStyle=i.yAxisColor||f,t.lineWidth=1,t.moveTo(-o/2,-e/2),t.lineTo(-o/2,e/2),t.stroke()),t.fillStyle=i.axisLabelColor||"#333333",t.font=`${i.axisLabelFontSize||10}px Inter, sans-serif`,i.showXLabels){t.textAlign="center",t.textBaseline="top";for(let p=0;p<l;p++){const m=u(p);t.fillText(`${p+1}`,m,e/2+5)}}if(i.showYLabels){t.textAlign="right",t.textBaseline="middle";const p=-o/2-5,m=(a+n)/2;t.fillText(a.toFixed(1),p,r(a)),t.fillText(m.toFixed(1),p,r(m)),t.fillText(n.toFixed(1),p,r(n))}const d=10;if(s.forEach(p=>{const m=p._resolvedData;if(!(!m||m.length<2)){if(p.showArea){if(t.beginPath(),t.moveTo(u(0),e/2),t.lineTo(u(0),r(m[0])),p.smoothing&&m.length>2)for(let b=0;b<m.length-1;b++){const v=m[b===0?b:b-1],S=m[b],C=m[b+1],w=m[b+1===m.length-1?b+1:b+2];for(let M=1;M<=d;M++){const I=M/d,k=this._catmullRom(v,S,C,w,I);t.lineTo(u(b+I),r(k))}}else for(let b=1;b<m.length;b++)t.lineTo(u(b),r(m[b]));t.lineTo(u(m.length-1),e/2),t.closePath();const y=t.globalAlpha;t.globalAlpha=y*(i.areaOpacity??.3),t.fillStyle=p.areaColor||"rgba(139, 92, 246, 0.2)",t.fill(),t.globalAlpha=y}if(t.beginPath(),t.strokeStyle=p.lineColor||"#3b82f6",t.lineWidth=p.lineWidth||2,t.lineJoin="round",t.lineCap="round",t.moveTo(u(0),r(m[0])),p.smoothing&&m.length>2)for(let y=0;y<m.length-1;y++){const b=m[y===0?y:y-1],v=m[y],S=m[y+1],C=m[y+1===m.length-1?y+1:y+2];for(let w=1;w<=d;w++){const M=w/d,I=this._catmullRom(b,v,S,C,M);t.lineTo(u(y+M),r(I))}}else for(let y=1;y<m.length;y++)t.lineTo(u(y),r(m[y]));t.stroke(),p.showPoints&&m.forEach((y,b)=>{const v=u(b),S=r(y);t.beginPath(),t.arc(v,S,(p.pointSize||6)/2,0,Math.PI*2),t.fillStyle=p.pointFill||"#ffffff",t.fill(),t.strokeStyle=p.pointStrokeColor||p.lineColor||"#3b82f6",t.lineWidth=p.pointStrokeWidth||1,t.stroke()})}}),i.showLegend&&s.length>0){const p=o/2-10;let m=-e/2+15;const y=i.legendFontSize||10,b=y+5;t.font=`${y}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="alphabetic",s.forEach(v=>{const C=v.label||"Series",w=t.measureText(C).width;t.beginPath(),t.rect(p-w-8-5,m-(8/2+2),8,8),t.fillStyle=v.lineColor||"#3b82f6",t.fill(),t.fillStyle=i.legendColor||"#333333",t.fillText(C,p,m),m+=b})}}_catmullRom(t,i,o,e,s){const n=(o-t)*.5,a=(e-i)*.5,l=s*s,c=s*l;return(2*i-2*o+n+a)*c+(-3*i+3*o-2*n-a)*l+n*s+i}normalizeOpacity(t){const i=typeof t=="number"?t:parseFloat(String(t));return isNaN(i)?1:i>1?Math.min(1,i/100):Math.max(0,Math.min(1,i))}createCanvasFill(t,i,o,e){var s,n,a;if(!i||i.type==="None")return null;if(typeof i=="string")return i;if(i.type==="Solid"&&i.color){const l=i.color,h=(((n=(s=this.artboard)==null?void 0:s.tokens)==null?void 0:n.colors)||{})[l]||l;return t.fillStyle=h,h}if((i.type==="LinearGradient"||i.type==="RadialGradient"||i.type==="AngularGradient"||i.type==="DiamondGradient")&&i.stops){const l=(c,h=100)=>{var S,C;const u=(((C=(S=this.artboard)==null?void 0:S.tokens)==null?void 0:C.colors)||{})[c]||c,f=this.normalizeOpacity(i.opacity??100),p=this.normalizeOpacity(h)*f;if(p>=1&&u.startsWith("#"))return u;const m=u.startsWith("#")?u.replace("#",""):"ffffff",y=parseInt(m.substring(0,2),16),b=parseInt(m.substring(2,4),16),v=parseInt(m.substring(4,6),16);return`rgba(${y}, ${b}, ${v}, ${p})`};if(i.type==="LinearGradient"){const c=(p,m,y)=>Array.isArray(p)?p[m]??(m===0?0:1):p&&typeof p=="object"?p[y]??(m===0?0:1):m===0?0:1,h=c(i.start,0,"x")*o-o/2,r=c(i.start,1,"y")*e-e/2,u=c(i.end,0,"x")*o-o/2,f=c(i.end,1,"y")*e-e/2,d=t.createLinearGradient(h,r,u,f);if(i.stops.forEach(p=>{const m=p.offset!==void 0?p.offset:p.pos!==void 0?p.pos:p.position!==void 0?p.position:0,y=l(p.color||"#000000",p.opacity??100);d.addColorStop(Math.max(0,Math.min(1,m)),y)}),i.gradientTransform&&d.setTransform){const[p,m,y,b,v,S]=i.gradientTransform;d.setTransform({a:p,b:m,c:y,d:b,e:v,f:S})}return d}else if(i.type==="RadialGradient"){const c=(d,p,m)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[m]??.5:.5,h=c(i.center,0,"x")*o-o/2,r=c(i.center,1,"y")*e-e/2,u=(i.radius??.5)*Math.max(o,e),f=t.createRadialGradient(h,r,0,h,r,u);if(i.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,m=l(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),m)}),i.gradientTransform&&f.setTransform){const[d,p,m,y,b,v]=i.gradientTransform;f.setTransform({a:d,b:p,c:m,d:y,e:b,f:v})}return f}else if(i.type==="AngularGradient"){const c=(d,p,m)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[m]??.5:.5,h=c(i.center||[.5,.5],0,"x")*o-o/2,r=c(i.center||[.5,.5],1,"y")*e-e/2,u=(i.degree||i.angle||0)*(Math.PI/180),f=(a=t.createConicGradient)==null?void 0:a.call(t,u,h,r);if(f){if(i.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,m=l(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),m)}),i.gradientTransform&&f.setTransform){const[d,p,m,y,b,v]=i.gradientTransform;f.setTransform({a:d,b:p,c:m,d:y,e:b,f:v})}return f}}else if(i.type==="DiamondGradient"){const c=(d,p,m)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[m]??.5:.5,h=c(i.center||[.5,.5],0,"x")*o-o/2,r=c(i.center||[.5,.5],1,"y")*e-e/2,u=(i.radius??.5)*Math.max(o,e);t.save(),t.translate(h,r),t.rotate(Math.PI/4);const f=t.createRadialGradient(0,0,0,0,0,u);if(i.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,m=l(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),m)}),i.gradientTransform&&f.setTransform){const[d,p,m,y,b,v]=i.gradientTransform;f.setTransform({a:d,b:p,c:m,d:y,e:b,f:v})}return t.scale(1/Math.SQRT2,1/Math.SQRT2),t.fillStyle=f,t.restore(),f}}if(i.type==="Pattern"&&i.url){let l=this.imageCache.get(i.url);if(l||(l=new Image,l.src=i.url,this.imageCache.set(i.url,l)),l.complete&&l.naturalWidth>0){const c=t.createPattern(l,"repeat");if(c&&(i.scaleX!==void 0||i.offsetX!==void 0)){const h=new DOMMatrix,r=i.scaleX??1,u=i.scaleY??1,f=i.offsetX??0,d=i.offsetY??0,p=i.rotation??0;h.translateSelf(f,d),h.rotateSelf(p),h.scaleSelf(r,u),c.setTransform(h)}return c}}return i.color||null}drawRoundRect(t,i,o,e,s,n){if(n===0||n===void 0||n===null){t.rect(i,o,e,s);return}let a=n;if(typeof a=="string")try{a=JSON.parse(a)}catch{a=parseFloat(a)||0}let l=0,c=0,h=0,r=0;typeof a=="number"?l=c=h=r=a:Array.isArray(a)?a.length===1?l=c=h=r=a[0]:a.length===2?(l=h=a[0],c=r=a[1]):a.length===3?(l=a[0],c=r=a[1],h=a[2]):a.length>=4&&(l=a[0],c=a[1],h=a[2],r=a[3]):a&&typeof a=="object"&&(l=a.tl??a.corner_radius??a.cornerRadius??0,c=a.tr??a.corner_radius??a.cornerRadius??0,h=a.br??a.corner_radius??a.cornerRadius??0,r=a.bl??a.corner_radius??a.cornerRadius??0);const u=Math.min(Math.abs(e)/2,Math.abs(s)/2);if(l=Math.min(Math.max(0,l),u),c=Math.min(Math.max(0,c),u),h=Math.min(Math.max(0,h),u),r=Math.min(Math.max(0,r),u),t.roundRect){t.roundRect(i,o,e,s,[l,c,h,r]);return}t.moveTo(i+l,o),t.lineTo(i+e-c,o),t.arcTo(i+e,o,i+e,o+c,c),t.lineTo(i+e,o+s-h),t.arcTo(i+e,o+s,i+e-h,o+s,h),t.lineTo(i+r,o+s),t.arcTo(i,o+s,i,o+s-r,r),t.lineTo(i,o+l),t.arcTo(i,o,i+l,o,l),t.closePath()}renderListView(t,i){var x,W,Y,B;const o=this.objectStates.get(i.id)||{},e=o.options||i.options||{},s=o.width!==void 0?o.width:((x=i.geometry)==null?void 0:x.width)||200,n=o.height!==void 0?o.height:((W=i.geometry)==null?void 0:W.height)||300,a=-s/2,l=-n/2,c=o.corner_radius!==void 0?o.corner_radius:e.corner_radius??0,h=e.orientation||"vertical",r=e.items||[],u=e.itemGap??10,f=e.itemHeight??50,d=e.itemWidth??200,p=e.scrollOffset??0,m=e.padding??0,y=e.glassEffect!==!1,b=e.accentColor||"#3b82f6",v=e.itemTextColor||"#333333",S=e.itemBackgroundColor||"#ffffff",C=e.hoveredIndex??null,w=e.activeItemIndex??null,M=e.glowIntensity??0,I=e.glowColor||"#3b82f6",k=typeof I=="string"?I:I.color||((B=(Y=I.stops)==null?void 0:Y[0])==null?void 0:B.color)||"#3b82f6",T=e.opacity!==void 0?e.opacity:i.opacity!==void 0?i.opacity:1;if(t.save(),t.globalAlpha*=T,M>0){const X=t.getTransform(),q=Math.sqrt(X.a*X.a+X.b*X.b)||1;t.shadowColor=k,t.shadowBlur=M*2*q,t.shadowOffsetX=0,t.shadowOffsetY=0}if(y){const X=e.listBackgroundColor||"rgba(31, 41, 55, 0.4)",q=this.createCanvasFill(t,X,s,n);t.fillStyle=q||"rgba(31, 41, 55, 0.4)",t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,l,s,n,c)||t.fill();const E=t.createLinearGradient(a,l,a+s,l+n);E.addColorStop(0,"rgba(255, 255, 255, 0.15)"),E.addColorStop(.5,"rgba(255, 255, 255, 0.08)"),E.addColorStop(1,"rgba(255, 255, 255, 0.03)"),t.fillStyle=E,t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,l,s,n,c)||t.fill(),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1,t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,l,s,n,c)||t.stroke()}else{const X=e.backgroundColor||e.listBackgroundColor||"transparent",q=this.createCanvasFill(t,X,s,n);if(q){t.fillStyle=q,t.beginPath();const E=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,l,s,n,c);t.fill()}const j=e.borderWidth??0;if(j>0){t.strokeStyle=e.borderColor||"#cccccc",t.lineWidth=j,t.beginPath();const E=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,l,s,n,c);t.stroke()}}t.shadowBlur=0,t.save(),t.beginPath();const O=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,l,s,n,c);if(e.listLayout!=="circular")if(O&&e.containerShape==="custom")try{const X=new Path2D(e.containerPath);t.translate(a,l),t.scale(s/100,n/100),t.clip(X),t.scale(100/s,100/n),t.translate(-a,-l)}catch{}else t.clip();const P=typeof m=="number"?m:h==="vertical"?m[0]:m[3];let _=(h==="vertical"?l:a)+p+P;if(t.textBaseline="middle",r.forEach((X,q)=>{const j=e.listLayout||"linear",E=j==="circular"?d:h==="vertical"?s:d,L=j==="circular"||h==="vertical"?f:n;let G=0,z=0,it=0;if(j==="circular"){const Tt=r.length||1,zt=Math.PI*2/Tt,et=e.circularStartAngle||0,yt=e.circularRadius||100,Ot=p*.01+et*Math.PI/180,gt=q*zt+Ot,Mt=a+s/2,Ft=l+n/2;G=Mt+Math.cos(gt)*yt-E/2,z=Ft+Math.sin(gt)*yt-L/2,it=gt+(e.itemRotation||0)*Math.PI/180}else G=h==="vertical"?a:_,z=h==="vertical"?_:l,it=(e.itemRotation||0)*Math.PI/180;const F=C===q,$=w===q,V=$&&e.activeItemShape?e.activeItemShape:e.itemShape||"rectangle",tt=$&&e.activeItemShape?e.activeItemPath:e.itemPath||"",rt=e.itemCornerRadius||0;if(t.save(),it!==0&&(t.translate(G+E/2,z+L/2),t.rotate(it),t.translate(-(G+E/2),-(z+L/2))),$){const Tt=this.createCanvasFill(t,b,E,L);t.fillStyle=Tt||b;const zt=t.globalAlpha;t.globalAlpha=zt*.8,t.beginPath(),this.drawCustomShape(t,V,tt,G,z,E,L,rt)||(t.rect(G,z,E,L),t.fill()),t.globalAlpha=zt}else if(F)t.fillStyle=y?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",t.beginPath(),this.drawCustomShape(t,V,tt,G,z,E,L,rt)||(t.rect(G,z,E,L),t.fill());else if(S!=="transparent"){const Tt=this.createCanvasFill(t,S,E,L);t.fillStyle=Tt||S,t.beginPath(),this.drawCustomShape(t,V,tt,G,z,E,L,rt)||(t.rect(G,z,E,L),t.fill())}if($||F){const Tt=this.createCanvasFill(t,b,h==="vertical"?3:E,h==="vertical"?L:3);t.fillStyle=Tt||b,h==="vertical"?t.fillRect(G,z,3,L):t.fillRect(G,z+L-3,E,3)}const mt=$?"#ffffff":y?"rgba(255, 255, 255, 0.9)":v;t.fillStyle=mt,t.font=$||F?"600 14px Inter, sans-serif":"400 14px Inter, sans-serif";const Ct=typeof X=="string"?X:(X==null?void 0:X.label)||`Item ${q+1}`,ct=G+(h==="vertical"?16:E/2),Pt=z+L/2;h==="horizontal"||j==="circular"?t.textAlign="center":t.textAlign="left";const kt=j==="circular"?G+E/2:ct;t.fillText(Ct,kt,Pt),t.restore(),_+=(h==="vertical"?f:d)+u}),t.restore(),e.showScrollbar!==!1){const X=(r.length||0)*(h==="vertical"?f:d)+((r.length||0)-1)*u,q=h==="vertical"?n:s,j=e.listLayout||"linear",E=e.containerShape==="circle"||j==="circular";if(X>q||j==="circular"&&r.length>0){const L=e.scrollbarColor||"rgba(255,255,255,0.3)",G=e.scrollbarWidth||4;if(E){const z=Math.min(s,n)/2-G/2-2,it=a+s/2,F=l+n/2;if(t.strokeStyle=L,t.lineWidth=G,t.lineCap="round",t.beginPath(),j==="circular"){const $=Math.PI/4,V=-(p*.01)-Math.PI/2;t.arc(it,F,z,V,V+$)}else{const $=Math.PI/2,V=q/X,tt=$*V,rt=-p/X*$,Ct=-Math.PI/4+rt;t.arc(it,F,z,Ct,Ct+tt)}t.stroke()}else{const z=q/X,it=q*z,F=-p/X*q;t.fillStyle=L,h==="vertical"?t.fillRect(a+s-G-2,l+F,G,it):t.fillRect(a+F,l+n-G-2,it,G)}}}t.restore()}drawCustomShape(t,i,o,e,s,n,a,l){if(i==="circle"){const c=Math.min(n,a)/2;return t.arc(e+n/2,s+a/2,c,0,Math.PI*2),!1}else if(i==="pill"){const c=Math.min(n,a)/2;return this.drawListViewRect(t,e,s,n,a,c),!1}else if(i==="custom"&&o)try{const c=new Path2D(o);return t.save(),t.translate(e,s),t.scale(n/100,a/100),t.fill(c),t.restore(),!0}catch{return this.drawListViewRect(t,e,s,n,a,l),!1}return this.drawListViewRect(t,e,s,n,a,l),!1}updateListViewScrollFromPointer(t){var y,b;if(!this._lastPointerPos||!this._prevPointerPos)return;const i=t.options||{},o=i.orientation||"vertical",e=this._lastPointerPos.x-this._prevPointerPos.x,s=this._lastPointerPos.y-this._prevPointerPos.y;o==="vertical"?i.scrollOffset=(i.scrollOffset||0)+s:i.scrollOffset=(i.scrollOffset||0)+e;const n=i.listLayout||"linear",a=this.objectStates.get(t.id)||{},l=i.items||[],c=i.itemGap??10,h=i.itemHeight??50,r=i.itemWidth??200,u=a.width!==void 0?a.width:((y=t.geometry)==null?void 0:y.width)||200,f=a.height!==void 0?a.height:((b=t.geometry)==null?void 0:b.height)||300;if(n==="circular")return;const d=(l.length||0)*(o==="vertical"?h:r)+((l.length||0)-1)*c,m=Math.max(0,d-(o==="vertical"?f:u)+(i.padding*2||0));i.scrollOffset>0&&(i.scrollOffset=0),i.scrollOffset<-m&&(i.scrollOffset=-m)}updateListViewHoverFromPointer(t,i,o){const e=this.getListViewItemIndexAtPointer(t,i,o),s=t.options||{};s.hoveredIndex!==e&&(s.hoveredIndex=e)}getListViewItemIndexAtPointer(t,i,o){var Y,B;const e=t.options||{},s=this.objectStates.get(t.id)||{},n=e.items||[];if(n.length===0)return null;const a=s.width!==void 0?s.width:((Y=t.geometry)==null?void 0:Y.width)||200,l=s.height!==void 0?s.height:((B=t.geometry)==null?void 0:B.height)||300,c=e.orientation||"vertical",h=e.itemGap??10,r=e.itemHeight??50,u=e.itemWidth??200,f=e.scrollOffset??0,d=e.padding??0,p=this.getWorldTransform(t.id),m=i-p.x,y=o-p.y,b=-p.rotation*(Math.PI/180),v=Math.cos(b),S=Math.sin(b),C=m*v-y*S,w=m*S+y*v,M=-a/2,I=-l/2,k=typeof d=="number"?d:c==="vertical"?d[0]:d[3];let T=(c==="vertical"?I:M)+f+k;const O=e.listLayout||"linear",P=n.length||1,_=Math.PI*2/P,A=e.circularStartAngle||0,x=e.circularRadius||100,W=f*.01+A*Math.PI/180;for(let X=0;X<n.length;X++){const q=O==="circular"?u:c==="vertical"?a:u,j=O==="circular"||c==="vertical"?r:l;let E=0,L=0,G=0;if(O==="circular"){const z=X*_+W,it=M+a/2,F=I+l/2;E=it+Math.cos(z)*x-q/2,L=F+Math.sin(z)*x-j/2,G=z+(e.itemRotation||0)*Math.PI/180}else E=c==="vertical"?M:T,L=c==="vertical"?T:I,G=(e.itemRotation||0)*Math.PI/180;if(G!==0){const z=E+q/2,it=L+j/2,F=C-z,$=w-it,V=-G,tt=F*Math.cos(V)-$*Math.sin(V)+z,rt=F*Math.sin(V)+$*Math.cos(V)+it;if(tt>=E&&tt<=E+q&&rt>=L&&rt<=L+j)return X}else if(C>=E&&C<=E+q&&w>=L&&w<=L+j)return X;T+=(c==="vertical"?r:u)+h}return null}drawListViewRect(t,i,o,e,s,n){t.beginPath(),this.drawRoundRect(t,i,o,e,s,n),t.fill()}solveBehaviors(t){if(!this.artboard)return;if(!this._lastPointerPos){this.frameCount%60;return}const{x:i,y:o}=this._lastPointerPos;this.artboard.objects.forEach(e=>{if(!e.behaviors||e.behaviors.length===0)return;const s=this.objectStates.get(e.id);s&&e.behaviors.forEach(n=>{var u,f,d,p,m,y,b,v,S,C,w,M,I,k,T,O,P,_,A,x,W,Y,B,X,q,j,E,L,G,z,it,F,$,V,tt,rt,mt,Ct,ct,Pt,kt,Tt,zt,et,yt,Ot,gt,Mt,Ft,Vt,Yt,Ht,Kt,ie,ye,me,te,ve,Te,Se,we,_e,ce,ne,ft,bt,st,H,N,ot,vt,xt,It,Wt,St,R,Rt,se,Ut,de,Lt,ut,dt,nt,pt,D,at,Q,$t,Jt,oe,Gt,Qt,qt,Me,Pe,Ee,Ae,xe,Oe,Be,Nt,ae,Ce,Le,Fe,ue,fe,he,Ie,We,Ne,He,Ye,Ue,qe,gs,ys;if(!n.enabled)return;const a=n.startTime||0,l=n.endTime||1/0;if(this.currentTime<a||this.currentTime>l)return;const c=s.x-i,h=s.y-o,r=Math.sqrt(c*c+h*h);if(this.frameCount%240===0&&Math.random()<.1&&this.log(`[ExodeUI] Executing ${n.type} on ${e.name}`),n.type===U.Proximity){const K=((u=n.settings)==null?void 0:u.radius)||300,Z=((f=n.settings)==null?void 0:f.falloff)||"smooth";let J=0;r<K&&(Z==="linear"?J=1-r/K:J=Math.pow(1-r/K,2)),n.sensors.forEach(ht=>{this.applyBehaviorSensor(s,ht,J,t,n.settings,e,c,h,r)})}else if(n.type===U.Magnetic){const K=((d=n.settings)==null?void 0:d.radius)||400,Z=((p=n.settings)==null?void 0:p.strength)||.5;if(r<K&&r>5){const J=1-r/K,ht=c*J*Z,_t=h*J*Z;s.x-=ht*t*10,s.y-=_t*t*10}}else if(n.type===U.Repel){const K=((m=n.settings)==null?void 0:m.radius)||300,Z=((y=n.settings)==null?void 0:y.strength)||1;if(r<K){const J=Math.pow(1-r/K,2);s.x+=c/(r||1)*J*60*Z*t*5,s.y+=h/(r||1)*J*60*Z*t*5}}else if(n.type===U.Orbit){const K=((b=n.settings)==null?void 0:b.speed)||1,Z=((v=n.settings)==null?void 0:v.radius)||30,J=this.currentTime*K*Math.PI*2;s.x+=Math.cos(J)*Z*t*5,s.y+=Math.sin(J)*Z*t*5,s.rotation+=2*t*5}else if(n.type===U.Vortex){const K=((S=n.settings)==null?void 0:S.radius)||400,Z=((C=n.settings)==null?void 0:C.speed)||2,J=((w=n.settings)==null?void 0:w.strength)||1;if(r<K){const ht=Math.pow(1-r/K,1.5),_t=this.currentTime*Z*Math.PI*2,At=Math.cos(_t)*30-c*.4,Bt=Math.sin(_t)*30-h*.4;s.x+=At*ht*J*t*5,s.y+=Bt*ht*J*t*5,s.rotation+=5*ht*J*t*5,s.scale_x*=1-ht*.1*J*t,s.scale_y*=1-ht*.1*J*t}}else if(n.type===U.Fluid){const K=((M=n.settings)==null?void 0:M.radius)||300,Z=((I=n.settings)==null?void 0:I.strength)||1;if(r<K){const J=Math.pow(1-r/K,1.2),ht=c/(r||1)*J*1.2*Z,_t=h/(r||1)*J*1.2*Z;s.x+=ht*10*t*5,s.y+=_t*10*t*5,s.scale_x*=1+J*.3*Z*t,s.scale_y*=1+J*.3*Z*t}}else if(n.type===U.Elastic){const K=((k=n.settings)==null?void 0:k.radius)||300,Z=((T=n.settings)==null?void 0:T.strength)||1;if(r<K){const J=1-r/K;s.scale_x*=1+J*.4*Z*t,s.scale_y*=1+J*.4*Z*t}}else if(n.type===U.Holographic){const K=s.x-this.canvasWidth/2,Z=s.y-this.canvasHeight/2,J=((O=n.settings)==null?void 0:O.factor)||25;if(s.x-=K/1e3*J*t*5,s.y-=Z/1e3*J*t*5,s.style){const ht=1-Math.min(1,r/400);s.style.exposure=(s.style.exposure||1)+ht*.5*t}}else if(n.type===U.Sticky){const K=((P=n.settings)==null?void 0:P.radius)||80,Z=((_=n.settings)==null?void 0:_.strength)||1;if(r<K){const J=Math.pow(1-r/K,2);s.x-=c*J*Z*t*10,s.y-=h*J*Z*t*10,s.scale_x*=1-J*.1*Z*t,s.scale_y*=1-J*.1*Z*t}}else if(n.type===U.Dilation){const K=((A=n.settings)==null?void 0:A.size)||120,Z=((x=n.settings)==null?void 0:x.strength)||1;if(r<K){const J=1-r/K;s.scale_x*=1+J*.5*Z*t,s.scale_y*=1+J*.5*Z*t}}else if(n.type===U.Parallax){const K=((W=n.settings)==null?void 0:W.factor)||15,Z=((Y=n.settings)==null?void 0:Y.strength)||1,J=this.canvasWidth/2,ht=this.canvasHeight/2,_t=this._lastPointerPos||{x:J,y:ht},At=(_t.x-J)/J,Bt=(_t.y-ht)/ht,ee=(((B=e.transform)==null?void 0:B.x)??0)+At*K*Z,pe=(((X=e.transform)==null?void 0:X.y)??0)+Bt*K*Z,ke=(((q=e.transform)==null?void 0:q.rotate_x)??0)-Bt*K*1.5*Z,re=(((j=e.transform)==null?void 0:j.rotate_y)??0)+At*K*1.5*Z,be=Math.min(1,10*t);s.x=this.lerp(s.x??((E=e.transform)==null?void 0:E.x)??0,ee,be),s.y=this.lerp(s.y??((L=e.transform)==null?void 0:L.y)??0,pe,be),s.rotate_x=this.lerp(s.rotate_x??((G=e.transform)==null?void 0:G.rotate_x)??0,ke,be),s.rotate_y=this.lerp(s.rotate_y??((z=e.transform)==null?void 0:z.rotate_y)??0,re,be)}else if(n.type===U.Fold){if(r<300){const K=1-r/300,Z=(c>0?-1:1)*K*10,J=1-K*.1,ht=h/300*K*20,_t=-(c/300)*K*20,At=Math.min(1,10*t);s.skew_x=this.lerp(s.skew_x??((it=e.transform)==null?void 0:it.skew_x)??0,Z,At),s.scale_y=this.lerp(s.scale_y??((F=e.transform)==null?void 0:F.scale_y)??1,((($=e.transform)==null?void 0:$.scale_y)??1)*J,At),s.rotate_x=this.lerp(s.rotate_x??((V=e.transform)==null?void 0:V.rotate_x)??0,ht,At),s.rotate_y=this.lerp(s.rotate_y??((tt=e.transform)==null?void 0:tt.rotate_y)??0,_t,At),s.style=s.style||{...e.style},s.style.artEffect={enabled:!0,type:"fold_overlay",intensity:((rt=n.settings)==null?void 0:rt.opacity)??.5}}}else if(n.type===U.Crumple){if(r<300){const K=1-r/300,Z=K*(Math.random()-.5)*5,J=K*(Math.random()-.5)*.05,ht=Math.min(1,15*t);s.skew_x=this.lerp(s.skew_x??((mt=e.transform)==null?void 0:mt.skew_x)??0,Z,ht),s.scale_x=this.lerp(s.scale_x??((Ct=e.transform)==null?void 0:Ct.scale_x)??1,(((ct=e.transform)==null?void 0:ct.scale_x)??1)*(1+J),ht),s.scale_y=this.lerp(s.scale_y??((Pt=e.transform)==null?void 0:Pt.scale_y)??1,(((kt=e.transform)==null?void 0:kt.scale_y)??1)*(1+J),ht),s.style=s.style||{...e.style},s.style.artEffect={enabled:!0,type:"crumple_overlay",intensity:((Tt=n.settings)==null?void 0:Tt.intensity)??1,scale:((zt=n.settings)==null?void 0:zt.scale)??2}}}else if(n.type===U.Squash){const K=((et=n.settings)==null?void 0:et.strength)||.8;r<(e.width||100)&&this.isMouseDown?(s.scale_y=this.lerp(s.scale_y??1,(((yt=e.transform)==null?void 0:yt.scale_y)??1)*K,.3),s.scale_x=this.lerp(s.scale_x??1,(((Ot=e.transform)==null?void 0:Ot.scale_x)??1)*(1+(1-K)*.4),.3)):(s.scale_y=this.lerp(s.scale_y??1,((gt=e.transform)==null?void 0:gt.scale_y)??1,.2),s.scale_x=this.lerp(s.scale_x??1,((Mt=e.transform)==null?void 0:Mt.scale_x)??1,.2))}else if(n.type===U.TextCounter){const K=((Ft=n.settings)==null?void 0:Ft.duration)||2,Z=((Vt=n.settings)==null?void 0:Vt.from)||0,J=((Yt=n.settings)==null?void 0:Yt.to)||100;n._runtimeStart===void 0&&(n._runtimeStart=this.currentTime);const ht=this.currentTime-n._runtimeStart,_t=Math.min(1,ht/K),At=Math.floor(Z+(J-Z)*_t);if(((Ht=e.geometry)==null?void 0:Ht.type)==="Text"){const Bt=((Kt=n.settings)==null?void 0:Kt.prefix)||"",ee=((ie=n.settings)==null?void 0:ie.suffix)||"";s.geometry||(s.geometry={...e.geometry}),s.geometry.text=`${Bt}${At}${ee}`}}else if(n.type===U.Spotlight){const K=((ye=n.settings)==null?void 0:ye.radius)||250,Z=((me=n.settings)==null?void 0:me.strength)||1.5;if(r<K){const J=Math.pow(1-r/K,2);s.style||(s.style={...e.style}),s.style.adjustments||(s.style.adjustments={...(te=e.style)==null?void 0:te.adjustments}),s.style.adjustments.exposure=(((Te=(ve=e.style)==null?void 0:ve.adjustments)==null?void 0:Te.exposure)||0)+J*Z*50}else(Se=s.style)!=null&&Se.adjustments&&(s.style.adjustments.exposure=this.lerp(s.style.adjustments.exposure||0,((_e=(we=e.style)==null?void 0:we.adjustments)==null?void 0:_e.exposure)||0,.1))}else if(n.type===U.Noise||n.type===U.Float){const K=(((ce=n.settings)==null?void 0:ce.frequency)||((ne=n.settings)==null?void 0:ne.speed)||1)*.002,Z=(((ft=n.settings)==null?void 0:ft.amplitude)||((bt=n.settings)==null?void 0:bt.range)||50)*(((st=n.settings)==null?void 0:st.strength)||1),J=Date.now();s.x+=Math.sin(J*K)*Z*t,s.y+=Math.cos(J*K*.8)*Z*t,s.rotation+=Math.sin(J*K*.5)*5*t}else if(n.type===U.Pulse){const K=(((H=n.settings)==null?void 0:H.speed)||1)*.005,Z=(((N=n.settings)==null?void 0:N.scale)||1.2)-1,J=Math.sin(Date.now()*K),ht=((ot=n.settings)==null?void 0:ot.strength)||1;s.scale_x*=1+J*Z*ht*t,s.scale_y*=1+J*Z*ht*t,s.style&&(s.style.exposure=(s.style.exposure||1)+Math.max(0,J)*.1*ht*t)}else if(n.type===U.Draggable){const K=((vt=n.settings)==null?void 0:vt.radius)||150,Z=this.draggingBehaviors.has(e.id);if(r<K||Z){const J=((xt=n.settings)==null?void 0:xt.strength)||1,ht=Z?1:Math.max(0,1-r/K);this.applyBehaviorSensor(s,jt.PositionX,ht*J,t,n.settings),this.applyBehaviorSensor(s,jt.PositionY,ht*J,t,n.settings)}}else if(n.type===U.Scroll){const K=((It=n.settings)==null?void 0:It.axis)||"vertical",Z=((Wt=n.settings)==null?void 0:Wt.factor)||.5,J=((St=n.settings)==null?void 0:St.strength)||1,ht=((R=n.settings)==null?void 0:R.scaleFactor)||0;(K==="vertical"||K==="both")&&(s.y+=this.scrollOffset.y*Z*J*t),(K==="horizontal"||K==="both")&&(s.x+=this.scrollOffset.x*Z*J*t),ht!==0&&(s.scale_x*=1+this.scrollOffset.y*ht*t,s.scale_y*=1+this.scrollOffset.y*ht*t)}else if(n.type===U.LookAt){const K=((Rt=n.settings)==null?void 0:Rt.factor)||1,Z=((se=n.settings)==null?void 0:se.strength)||1,J=Math.atan2(-h,-c)*(180/Math.PI),ht=s.rotation,_t=(J-ht+180)%360-180;s.rotation+=_t*K*Z*t*10}else if(n.type===U.Scan){const K=(((Ut=n.settings)==null?void 0:Ut.speed)||1)*.004,Z=((de=n.settings)==null?void 0:de.strength)||1,J=(Math.sin(Date.now()*K)+1)/2;s.style&&(s.style.exposure=(s.style.exposure||1)+J*Z*t*5),s.x+=(J-.5)*20*Z*t}else if(n.type===U.Glint)s.style=s.style||{...e.style},s.style.artEffect={enabled:!0,type:"glint_overlay",intensity:((Lt=n.settings)==null?void 0:Lt.strength)??.8};else if(n.type===U.Ratchet){const K=((ut=n.settings)==null?void 0:ut.steps)||12,Z=(((dt=n.settings)==null?void 0:dt.speed)||1)*30,J=Math.floor(s.rotation/(360/K))*(360/K);s.rotation=this.lerp(s.rotation,J+Z*t,.1)}else if(n.type===U.Jitter&&r<300){const K=((nt=n.settings)==null?void 0:nt.strength)||1,Z=(((pt=n.settings)==null?void 0:pt.intensity)||5)*K;s.x+=(Math.random()-.5)*Z*t*60,s.y+=(Math.random()-.5)*Z*t*60,s.rotation+=(Math.random()-.5)*Z*t*120}else if(n.type===U.Follower){const K=(D=n.settings)==null?void 0:D.targetId;if(K){const Z=this.objectStates.get(K);if(Z){const J=((at=n.settings)==null?void 0:at.stiffness)||.1,ht=Z.x-s.x,_t=Z.y-s.y;s.x+=ht*J*t*60,s.y+=_t*J*t*60}}}else if(n.type===U.Wrap)s.x<0?s.x=this.canvasWidth:s.x>this.canvasWidth&&(s.x=0),s.y<0?s.y=this.canvasHeight:s.y>this.canvasHeight&&(s.y=0);else if(n.type===U.Gravity){const K=((Q=n.settings)==null?void 0:Q.strength)||9.8;s.y+=K*t*10}else if(n.type===U.Velocity){const K=(($t=n.settings)==null?void 0:$t.vx)||0,Z=((Jt=n.settings)==null?void 0:Jt.vy)||0;s.x+=K*t*10,s.y+=Z*t*10}else if(n.type===U.Shear){const K=((oe=n.settings)==null?void 0:oe.strength)||1,Z=((Gt=n.settings)==null?void 0:Gt.radius)||300;if(r<Z){const J=1-r/Z;s.skew_x=this.lerp(s.skew_x||0,(((Qt=e.transform)==null?void 0:Qt.skew_x)||0)+J*K*30,.1)}else s.skew_x=this.lerp(s.skew_x||0,((qt=e.transform)==null?void 0:qt.skew_x)||0,.05)}else if(n.type===U.Lens){const K=((Me=n.settings)==null?void 0:Me.radius)||200,Z=((Pe=n.settings)==null?void 0:Pe.strength)||.5;if(r<K){const J=Math.pow(1-r/K,2);s.scale_x=this.lerp(s.scale_x??1,(((Ee=e.transform)==null?void 0:Ee.scale_x)??1)*(1+J*Z),.2),s.scale_y=this.lerp(s.scale_y??1,(((Ae=e.transform)==null?void 0:Ae.scale_y)??1)*(1+J*Z),.2)}else s.scale_x=this.lerp(s.scale_x??1,((xe=e.transform)==null?void 0:xe.scale_x)??1,.1),s.scale_y=this.lerp(s.scale_y??1,((Oe=e.transform)==null?void 0:Oe.scale_y)??1,.1)}else if(n.type===U.LayoutAnimation){const K=((Be=n.settings)==null?void 0:Be.watchProperties)||["x","y","scale_x","scale_y","opacity","rotation"],Z=((Nt=n.settings)==null?void 0:Nt.duration)||.3;this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const J=this._layoutAnimCache.get(e.id);for(const ht of K){const _t=this.getObjectProperty(s,e,ht);if(_t===void 0)continue;const At=J.get(ht);if(!At)J.set(ht,{from:_t,to:_t,startTime:this.currentTime,duration:0});else if(At.to!==_t){const ee=this.getObjectProperty(s,e,ht);J.set(ht,{from:ee??At.from,to:_t,startTime:this.currentTime,duration:((ae=n.settings)==null?void 0:ae.duration)??Z})}const Bt=J.get(ht);if(Bt.duration>0&&Bt.from!==Bt.to){const ee=this.currentTime-Bt.startTime,pe=Math.min(1,ee/Bt.duration),ke=this.applyEasing(pe,((Ce=n.settings)==null?void 0:Ce.easing)||"easeOutCubic"),re=Bt.from+(Bt.to-Bt.from)*ke;this.setObjectProperty(s,e,ht,re)}}}else if(n.type===U.StateReactive){this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const K=this._layoutAnimCache.get(e.id),Z=((Le=n.settings)==null?void 0:Le.defaultDuration)||.3,J=["x","y","scale_x","scale_y","opacity","rotation","style.fill.color","style.stroke.width","geometry.cornerRadius","style.blur.value","style.shadow.blur","style.shadow.offsetX","style.shadow.offsetY"];for(const ht of J){const _t=this.getObjectProperty(s,e,ht);if(_t===void 0||typeof _t!="number")continue;const At=K.get(ht);if(!At)K.set(ht,{from:_t,to:_t,startTime:this.currentTime,duration:0});else if(At.to!==_t){const ee=this.getObjectProperty(s,e,ht);K.set(ht,{from:ee??At.from,to:_t,startTime:this.currentTime,duration:Z})}const Bt=K.get(ht);if(Bt.duration>0&&Bt.from!==Bt.to){const ee=this.currentTime-Bt.startTime,pe=Math.min(1,ee/Bt.duration),ke=this.applyEasing(pe,((Fe=n.settings)==null?void 0:Fe.defaultEasing)||"easeOutCubic"),re=Bt.from+(Bt.to-Bt.from)*ke;this.setObjectProperty(s,e,ht,re)}}}else if(n.type===U.SpringChain){const K=((ue=n.settings)==null?void 0:ue.connections)||[],Z=((fe=n.settings)==null?void 0:fe.globalDamping)||.3;this._springChainState.has(e.id)||this._springChainState.set(e.id,new Map);const J=this._springChainState.get(e.id);for(const _t of K){if(!J.has(_t.targetId)){const At=this.objectStates.get(_t.targetId);J.set(_t.targetId,{x:(At==null?void 0:At.x)??0,y:(At==null?void 0:At.y)??0,vx:0,vy:0})}J.has(e.id)||J.set(e.id,{x:s.x,y:s.y,vx:0,vy:0})}const ht=J.get(e.id);if(ht){ht.x=s.x,ht.y=s.y;for(const _t of K){const At=J.get(_t.targetId);if(!At)continue;const Bt=At.x-ht.x,ee=At.y-ht.y,pe=Math.sqrt(Bt*Bt+ee*ee)||.001,re=(pe-(_t.restLength||50))*(_t.stiffness||.8),be=Bt/pe*re,Ke=ee/pe*re;ht.vx+=be*t*10,ht.vy+=Ke*t*10,At.vx-=be*t*10,At.vy-=Ke*t*10,ht.vx*=1-Z*t*10,ht.vy*=1-Z*t*10,At.vx*=1-Z*t*10,At.vy*=1-Z*t*10;const ge=this.objectStates.get(_t.targetId);ge&&(ge.x+=At.vx*t,ge.y+=At.vy*t)}s.x+=ht.vx*t,s.y+=ht.vy*t}}else if(n.type===U.ParticleEmitter){const K=((he=n.settings)==null?void 0:he.rate)||10,Z=((Ie=n.settings)==null?void 0:Ie.speed)||100,J=((We=n.settings)==null?void 0:We.size)||5,ht=((Ne=n.settings)==null?void 0:Ne.lifetime)||2,_t=((He=n.settings)==null?void 0:He.gravity)||0,At=((Ye=n.settings)==null?void 0:Ye.color)||"#ffffff",Bt=((Ue=n.settings)==null?void 0:Ue.maxParticles)||200,ee=(qe=n.settings)!=null&&qe.rateInputId?this.inputs.get(n.settings.rateInputId)??K:K,pe=(gs=n.settings)!=null&&gs.gravityInputId?this.inputs.get(n.settings.gravityInputId)??_t:_t,ke=(ys=n.settings)!=null&&ys.speedInputId?this.inputs.get(n.settings.speedInputId)??Z:Z;this._emitterPools.has(e.id)||this._emitterPools.set(e.id,[]);const re=this._emitterPools.get(e.id);let be=0;n._pendingBurst&&n._pendingBurst>0&&(be=n._pendingBurst,n._pendingBurst=0);const Ke=Math.floor(ee*t)+(be||0);for(let ge=0;ge<Math.min(Ke,Bt-re.length);ge++){const le=Math.random()*Math.PI*2,ms=ke*(.5+Math.random()*.5);re.push({x:s.x,y:s.y,vx:Math.cos(le)*ms,vy:Math.sin(le)*ms,life:0,maxLife:ht*(.5+Math.random()*.5),size:J*(.5+Math.random()),color:At,opacity:1})}for(let ge=re.length-1;ge>=0;ge--){const le=re[ge];le.vy+=pe*t*10,le.x+=le.vx*t,le.y+=le.vy*t,le.life+=t,le.opacity=Math.max(0,1-le.life/le.maxLife),le.life>=le.maxLife&&re.splice(ge,1)}}})})}applyBehaviorSensor(t,i,o,e,s,n,a=0,l=0,c=1){var d,p,m,y,b,v,S,C,w,M,I,k,T,O,P,_,A,x,W,Y,B,X,q,j;const h=(s==null?void 0:s.intensity)||(s==null?void 0:s.strength)||1,r=Math.min(1,15*e),u=c>0?a/c:0,f=c>0?l/c:0;switch(i){case jt.Scale:{const E=((d=n==null?void 0:n.transform)==null?void 0:d.scale_x)??1,L=((p=n==null?void 0:n.transform)==null?void 0:p.scale_y)??1,G=E*(1+o*h*.4),z=L*(1+o*h*.4);t.scale_x=(t.scale_x??E)*(1-r)+G*r,t.scale_y=(t.scale_y??L)*(1-r)+z*r;break}case jt.Opacity:{const E=((m=n==null?void 0:n.transform)==null?void 0:m.opacity)??100,L=Math.max(0,Math.min(100,E-o*h*100));t.opacity=(t.opacity??E)*(1-r)+L*r;break}case jt.RotateZ:{const E=((y=n==null?void 0:n.transform)==null?void 0:y.rotation)??0,L=E+o*h*45;t.rotation=(t.rotation??E)*(1-r)+L*r;break}case jt.RotateX:{const E=((b=n==null?void 0:n.transform)==null?void 0:b.rotate_x)??0,L=E-f*o*h*60;t.rotate_x=(t.rotate_x??E)*(1-r)+L*r;break}case jt.RotateY:{const E=((v=n==null?void 0:n.transform)==null?void 0:v.rotate_y)??0,L=E+u*o*h*60;t.rotate_y=(t.rotate_y??E)*(1-r)+L*r;break}case jt.PositionX:{const E=((S=n==null?void 0:n.transform)==null?void 0:S.x)??0,L=E-u*o*h*40;t.x=(t.x??E)*(1-r)+L*r;break}case jt.PositionY:{const E=((C=n==null?void 0:n.transform)==null?void 0:C.y)??0,L=E-f*o*h*40;t.y=(t.y??E)*(1-r)+L*r;break}case jt.SkewX:{const E=((w=n==null?void 0:n.transform)==null?void 0:w.skew_x)??0,L=E+u*o*h*45;t.skew_x=(t.skew_x??E)*(1-r)+L*r,t.skew_x>85&&(t.skew_x=85),t.skew_x<-85&&(t.skew_x=-85);break}case jt.Blur:{t.style||(t.style={...n==null?void 0:n.style}),t.style.blur||(t.style.blur={...(M=n==null?void 0:n.style)==null?void 0:M.blur});const E=((k=(I=n==null?void 0:n.style)==null?void 0:I.blur)==null?void 0:k.amount)||0,L=E+o*((s==null?void 0:s.blur)||20)*h;t.style.blur.amount=(t.style.blur.amount??E)*(1-r)+L*r;break}case jt.Exposure:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(T=n==null?void 0:n.style)==null?void 0:T.adjustments});const E=((P=(O=n==null?void 0:n.style)==null?void 0:O.adjustments)==null?void 0:P.exposure)||0,L=E+o*((s==null?void 0:s.exposure)||50)*h;t.style.adjustments.exposure=(t.style.adjustments.exposure??E)*(1-r)+L*r;break}case jt.HueShift:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(_=n==null?void 0:n.style)==null?void 0:_.adjustments});const E=((x=(A=n==null?void 0:n.style)==null?void 0:A.adjustments)==null?void 0:x.hue)||0,L=E+o*((s==null?void 0:s.hue)||180)*h;t.style.adjustments.hue=(t.style.adjustments.hue??E)*(1-r)+L*r;break}case jt.Negative:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(W=n==null?void 0:n.style)==null?void 0:W.adjustments});const E=((B=(Y=n==null?void 0:n.style)==null?void 0:Y.adjustments)==null?void 0:B.negative)||0,L=E+o*((s==null?void 0:s.negative)||100)*h;t.style.adjustments.negative=(t.style.adjustments.negative??E)*(1-r)+L*r;break}case jt.CornerRadius:{const E=((X=n==null?void 0:n.transform)==null?void 0:X.corner_radius)||0,L=E+o*h*50;t.corner_radius=(t.corner_radius??E)*(1-r)+L*r;break}case jt.StrokeWidth:{t.style||(t.style={...n==null?void 0:n.style});const E=((q=n==null?void 0:n.style)==null?void 0:q.borderWidth)||0,L=E+o*h*10;t.style.borderWidth=(t.style.borderWidth??E)*(1-r)+L*r;break}case jt.LetterSpacing:{t.geometry||(t.geometry={});const E=((j=n==null?void 0:n.geometry)==null?void 0:j.letterSpacing)||0,L=E+o*h*10;t.geometry.letterSpacing=(t.geometry.letterSpacing??E)*(1-r)+L*r;break}}}getObjectProperty(t,i,o){const e=o.split(".");let s=t;for(const n of e){if(s==null||typeof s!="object")return;if(n==="style"&&t.style===void 0){s=i.style;continue}s=s[n]}return typeof s=="number"?s:void 0}setObjectProperty(t,i,o,e){const s=o.split(".");let n=t;for(let l=0;l<s.length-1;l++){const c=s[l];if(n[c]===void 0||n[c]===null){const h=i,r=s.slice(0,l+1).reduce((u,f)=>u==null?void 0:u[f],h);n[c]=r!==void 0?{...r}:{}}n=n[c]}const a=s[s.length-1];n!=null&&(n[a]=e)}applyEasing(t,i){switch(i){case"easeOutCubic":return 1-Math.pow(1-t,3);case"easeInCubic":return t*t*t;case"easeInOutCubic":return t<.5?4*t*t*t:1-Math.pow(-2*t+2,3)/2;case"easeOutQuad":return t*(2-t);case"easeInQuad":return t*t;case"easeInOutQuad":return t<.5?2*t*t:1-Math.pow(-2*t+2,2)/2;case"easeOutExpo":return t===1?1:1-Math.pow(2,-10*t);case"easeOutBack":return 1+2.70158*Math.pow(t-1,3)+1.70158*Math.pow(t-1,2);case"easeOutElastic":{const o=2*Math.PI/3;return t===0?0:t===1?1:Math.pow(2,-10*t)*Math.sin((t*10-.75)*o)+1}case"easeOutBounce":return t<1/2.75?7.5625*t*t:t<2/2.75?7.5625*(t-=1.5/2.75)*t+.75:t<2.5/2.75?7.5625*(t-=2.25/2.75)*t+.9375:7.5625*(t-=2.625/2.75)*t+.984375;case"linear":return t;default:return 1-Math.pow(1-t,3)}}lerp(t,i,o){return t*(1-o)+i*o}deepMerge(t,i){if(!t)return i;if(!i)return t;if(typeof t!="object"||typeof i!="object"||t===null||i===null)return i;const o={...t};for(const e in i)Object.prototype.hasOwnProperty.call(i,e)&&(i[e]&&typeof i[e]=="object"&&!Array.isArray(i[e])?o[e]=this.deepMerge(t[e],i[e]):o[e]=i[e]);return o}renderFittedImage(t,i,o,e,s,n,a="cover"){const l=i.naturalWidth,c=i.naturalHeight,h=l/c,r=s/n;let u=s,f=n,d=o,p=e;a==="cover"?h>r?(u=n*h,d=o-(u-s)/2):(f=s/h,p=e-(f-n)/2):a==="contain"&&(h>r?(f=s/h,p=e+(n-f)/2):(u=n*h,d=o+(s-u)/2)),t.drawImage(i,d,p,u,f)}}const ni=Et.forwardRef(({artboard:g,src:t,style:i,autoPlay:o=!0,fit:e="Contain",alignment:s="Center",onReady:n,onTrigger:a,onInputUpdate:l,onComponentChange:c,onToggle:h,onInputChange:r,onInputFocus:u,onInputBlur:f,onLog:d,onLogicUpdate:p,onButtonClick:m,onGraphPointClick:y,currentTime:b,revision:v=0,scrollY:S,scrollX:C,mouseX:w,mouseY:M,isMouseDown:I,inputs:k,interactive:T=!0,onNavigation:O},P)=>{const _=Et.useRef(null),A=Et.useRef(null);A.current||(A.current=new ps);const x=Et.useRef(void 0),W=Et.useRef(0),Y=Et.useRef(null),B=Et.useRef(v),X=Et.useRef(null),[,q]=Et.useState(g||null),j=Et.useRef(!0);Et.useImperativeHandle(P,()=>_.current),Et.useEffect(()=>(j.current=!0,()=>{j.current=!1,x.current&&cancelAnimationFrame(x.current)}),[]),Et.useEffect(()=>{A.current.setLayout(e,s)},[e,s]),Et.useEffect(()=>{const F=A.current;a&&F.setTriggerCallback(a),l&&F.setInputUpdateCallback(($,V)=>l({[$]:V})),c&&F.setComponentChangeCallback($=>c($)),h&&F.setToggleCallback(h),r&&F.setInputChangeCallback(r),u&&F.setInputFocusCallback(u),f&&F.setInputBlurCallback(f),d&&F.setOnLogCallback($=>d($,"info")),p&&F.setLogicUpdateCallback(p),m&&F.setButtonClickCallback(m),y&&F.setGraphPointClickCallback($=>y($.objectId,$)),O&&F.setNavigationCallback(O)},[a,l,c,h,r,u,f,d,p,m,y,O]),Et.useEffect(()=>{(async()=>{let $=g;if(t&&!g)try{t.startsWith("{")?$=JSON.parse(t):$=await(await fetch(t)).json()}catch(V){console.error("[ExodeUI] Failed to load src:",V)}if($){const V=A.current,tt=$.id||$.name||"default";(Y.current!==tt||B.current!==v||X.current!==$)&&(V.load($),Y.current=tt,B.current=v,X.current=$,q($),W.current=0,V.advance(0)),n&&n(V)}})()},[g,t,v]),Et.useEffect(()=>{const F=$=>{if(!A.current||!j.current)return;const V=A.current,tt=_.current;if(!tt)return;const rt=tt.getContext("2d");if(!rt)return;const mt=$/1e3;W.current===0&&(W.current=mt);let Ct=mt-W.current;Ct>.1&&(Ct=.1),W.current=mt;const ct=tt.getBoundingClientRect(),Pt=window.devicePixelRatio||1,kt=Math.round(ct.width*Pt),Tt=Math.round(ct.height*Pt);(tt.width!==kt||tt.height!==Tt)&&(tt.width=kt,tt.height=Tt);try{o?V.advance(Ct):b!==void 0&&V.seek(b),V.render(rt,tt.width,tt.height)}catch(zt){console.error("[ExodeUICanvas] Error in animation loop:",zt),d&&d(`[Error] Animation loop crashed: ${zt}`,"error")}x.current=requestAnimationFrame(F)};return x.current=requestAnimationFrame(F),()=>{x.current&&cancelAnimationFrame(x.current)}},[o,b]),Et.useEffect(()=>{const F=A.current;S!==void 0&&F.updateInput("scrollY",S),C!==void 0&&F.updateInput("scrollX",C),w!==void 0&&F.updateInput("mouseX",w),M!==void 0&&F.updateInput("mouseY",M),I!==void 0&&F.updateInput("isMouseDown",I),k&&Object.entries(k).forEach(([$,V])=>F.updateInput($,V))},[S,C,w,M,I,k]);const E=(F,$)=>{if(!T||!_.current)return;F.stopPropagation(),"nativeEvent"in F&&F.nativeEvent&&typeof F.nativeEvent.stopImmediatePropagation=="function"?F.nativeEvent.stopImmediatePropagation():typeof F.stopImmediatePropagation=="function"&&F.stopImmediatePropagation();const V=_.current,tt=V.getBoundingClientRect(),rt=F.clientX-tt.left,mt=F.clientY-tt.top,Ct=window.devicePixelRatio||1;($==="click"||$==="down"||$==="up")&&d&&d(`[Canvas] Pointer ${$} at rect(${Math.round(rt)},${Math.round(mt)}) mapped to buffer(${Math.round(rt*Ct)},${Math.round(mt*Ct)})`,"info"),A.current.handlePointerInput($,rt*Ct,mt*Ct,V.width,V.height)};Et.useEffect(()=>{if(!T)return;const F=V=>{var tt,rt,mt;((tt=document.activeElement)==null?void 0:tt.tagName)==="INPUT"||((rt=document.activeElement)==null?void 0:rt.tagName)==="TEXTAREA"||(mt=A.current)==null||mt.handleKeyDown(V)},$=V=>{var tt,rt,mt;((tt=document.activeElement)==null?void 0:tt.tagName)==="INPUT"||((rt=document.activeElement)==null?void 0:rt.tagName)==="TEXTAREA"||(mt=A.current)==null||mt.handleKeyUp(V)};return window.addEventListener("keydown",F),window.addEventListener("keyup",$),()=>{window.removeEventListener("keydown",F),window.removeEventListener("keyup",$)}},[T]);const[L,G]=Et.useState([]);Et.useEffect(()=>{if(g&&g.objects){const F=g.objects.filter($=>{var V,tt;return $.type==="Joystick"&&((V=$.inputBinding)==null?void 0:V.type)==="keyboard"&&((tt=$.inputBinding.keyboardConfig)==null?void 0:tt.showVirtualKeyboard)});G(F)}},[g]);const[,z]=Et.useState(0);Et.useEffect(()=>{if(L.length===0)return;let F;const $=()=>{z(V=>V+1),F=requestAnimationFrame($)};return F=requestAnimationFrame($),()=>cancelAnimationFrame(F)},[L.length]);const it=()=>L.map(F=>{const $=F.inputBinding.keyboardConfig,V=ct=>{var kt;const Pt={key:ct,code:ct,preventDefault:()=>{}};(kt=A.current)==null||kt.handleKeyDown(Pt)},tt=ct=>{var kt;const Pt={key:ct,code:ct,preventDefault:()=>{}};(kt=A.current)==null||kt.handleKeyUp(Pt)},rt=A.current,mt=ct=>rt&&rt.activeKeys?rt.activeKeys.has(ct.toLowerCase()):!1,Ct=ct=>({width:"50px",height:"50px",background:ct?"rgba(255, 255, 255, 0.4)":"rgba(0, 0, 0, 0.4)",border:"1px solid rgba(255, 255, 255, 0.2)",borderRadius:"12px",display:"flex",alignItems:"center",justifyContent:"center",color:"white",fontWeight:"bold",fontSize:"18px",userSelect:"none",cursor:"pointer",backdropFilter:"blur(8px)",transition:"background 0.1s",boxShadow:ct?"none":"0 4px 6px rgba(0,0,0,0.1)"});return Xt.jsxs("div",{style:{position:"absolute",bottom:"40px",right:"40px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",pointerEvents:"auto",zIndex:100},children:[Xt.jsx("div",{style:Ct(mt($.upKey)),onMouseDown:()=>V($.upKey),onMouseUp:()=>tt($.upKey),onMouseLeave:()=>tt($.upKey),onTouchStart:ct=>{ct.preventDefault(),V($.upKey)},onTouchEnd:ct=>{ct.preventDefault(),tt($.upKey)},children:$.upKey.toUpperCase()}),Xt.jsxs("div",{style:{display:"flex",gap:"8px"},children:[Xt.jsx("div",{style:Ct(mt($.leftKey)),onMouseDown:()=>V($.leftKey),onMouseUp:()=>tt($.leftKey),onMouseLeave:()=>tt($.leftKey),onTouchStart:ct=>{ct.preventDefault(),V($.leftKey)},onTouchEnd:ct=>{ct.preventDefault(),tt($.leftKey)},children:$.leftKey.toUpperCase()}),Xt.jsx("div",{style:Ct(mt($.downKey)),onMouseDown:()=>V($.downKey),onMouseUp:()=>tt($.downKey),onMouseLeave:()=>tt($.downKey),onTouchStart:ct=>{ct.preventDefault(),V($.downKey)},onTouchEnd:ct=>{ct.preventDefault(),tt($.downKey)},children:$.downKey.toUpperCase()}),Xt.jsx("div",{style:Ct(mt($.rightKey)),onMouseDown:()=>V($.rightKey),onMouseUp:()=>tt($.rightKey),onMouseLeave:()=>tt($.rightKey),onTouchStart:ct=>{ct.preventDefault(),V($.rightKey)},onTouchEnd:ct=>{ct.preventDefault(),tt($.rightKey)},children:$.rightKey.toUpperCase()})]})]},F.id)});return Xt.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[Xt.jsx("canvas",{ref:_,onPointerDown:F=>{var $;E(F,"down"),($=_.current)==null||$.focus()},onPointerMove:F=>E(F,"move"),onPointerUp:F=>E(F,"up"),onPointerCancel:F=>E(F,"up"),onClick:F=>E(F,"click"),onWheel:F=>{A.current.handleWheel(F.deltaX,F.deltaY)},onKeyDown:F=>A.current.handleKeyDown(F.nativeEvent),onKeyUp:F=>A.current.handleKeyUp(F.nativeEvent),onContextMenu:F=>F.preventDefault(),tabIndex:0,style:{...i,width:"100%",height:"100%",outline:"none",display:"block",touchAction:"none",pointerEvents:T?"auto":"none"}}),it()]})});function oi(){const[g,t]=Et.useState(null),i=Et.useCallback((r,u)=>{g==null||g.setInputBool(r,u)},[g]),o=Et.useCallback((r,u)=>{g==null||g.setInputNumber(r,u)},[g]),e=Et.useCallback(r=>{g==null||g.fireTrigger(r)},[g]),s=Et.useCallback((r,u)=>{g==null||g.setInputText(r,u)},[g]),n=Et.useCallback((r,u)=>{g==null||g.setInputNumberArray(r,u)},[g]),a=Et.useCallback((r,u)=>{g==null||g.setInputStringArray(r,u)},[g]),l=Et.useCallback((r,u)=>{g==null||g.updateObjectOptions(r,u)},[g]),c=Et.useCallback((r,u,f)=>{g==null||g.updateConstraint(r,u,f)},[g]),h=Et.useCallback((r,u)=>{g==null||g.updateGraphData(r,u)},[g]);return{setEngine:t,engine:g,setInputBool:i,setInputNumber:o,fireTrigger:e,setInputText:s,setInputNumberArray:n,setInputStringArray:a,updateConstraint:c,updateGraphData:h,updateObjectOptions:l}}const ai=({artboard:g,config:t})=>{const i={...g.seo,...t},o=i.enableSmartExtraction!==!1;Et.useEffect(()=>{const a=i.title||g.name;a&&(document.title=a);let l=i.description;if(!l&&o){const r=g.objects.filter(u=>{var f;return((f=u.geometry)==null?void 0:f.type)==="Text"}).sort((u,f)=>{var d,p;return(((d=f.geometry.text)==null?void 0:d.length)||0)-(((p=u.geometry.text)==null?void 0:p.length)||0)});r.length>0&&(l=r[0].geometry.text)}l&&(e("name","description",l),e("property","og:description",l)),i.keywords&&i.keywords.length>0&&e("name","keywords",i.keywords.join(", "));const c=i.ogImage||g.backgroundImage;c&&e("property","og:image",c),a&&e("property","og:title",a),e("property","og:type","website")},[i,g,o]);const e=(a,l,c)=>{let h=document.querySelector(`meta[${a}="${l}"]`);h||(h=document.createElement("meta"),h.setAttribute(a,l),document.head.appendChild(h)),h.setAttribute("content",c)},s=()=>{const a=[];return a.push(Xt.jsx("h1",{children:i.title||g.name},"artboard-title")),g.objects.forEach((c,h)=>{var r,u;if(!(c.visible===!1||c.isVisible===!1))if(((r=c.geometry)==null?void 0:r.type)==="Text"){const f=c.geometry.text;f&&(c.geometry.fontSize>24?a.push(Xt.jsx("h2",{children:f},c.id||h)):a.push(Xt.jsx("p",{children:f},c.id||h)))}else if(((u=c.geometry)==null?void 0:u.type)==="Image"){const f=c.geometry.src,d=c.altText||c.name||"Illustration";a.push(Xt.jsx("img",{src:f,alt:d},c.id||h))}else c.type==="Button"&&a.push(Xt.jsx("button",{children:c.name||"Button"},c.id||h))}),a},n=i.jsonLd||{"@context":"https://schema.org","@type":"VisualArtwork",name:i.title||g.name,description:i.description,image:i.ogImage||g.backgroundImage,abstract:"Animated interface created with ExodeUI"};return Xt.jsxs("div",{id:`exode-seo-${g.id||"default"}`,"aria-hidden":"false",style:{position:"absolute",width:"1px",height:"1px",padding:"0",margin:"-1px",overflow:"hidden",clip:"rect(0, 0, 0, 0)",whiteSpace:"nowrap",border:"0",zIndex:-1},children:[s(),Xt.jsx("script",{type:"application/ld+json",children:JSON.stringify(n)})]})},ri={version:"6.3.33"}.version;Dt.BehaviorSensor=jt,Dt.BehaviorType=U,Dt.ConditionOp=Qe,Dt.ExodeSEO=ai,Dt.ExodeUICanvas=ni,Dt.ExodeUIEngine=ps,Dt.LogicOp=wt,Dt.RapierPhysics=es,Dt.VERSION=ri,Dt.useExodeUI=oi,Object.defineProperty(Dt,Symbol.toStringTag,{value:"Module"})}));
|