exodeui 6.4.4 → 6.4.6

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 CHANGED
@@ -1,19 +1,19 @@
1
- (function(Kt,Qt){typeof exports=="object"&&typeof module<"u"?Qt(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"],Qt):(Kt=typeof globalThis<"u"?globalThis:Kt||self,Qt(Kt.ExodeUIReact={},Kt.jsxRuntime,Kt.React,Kt.pretext,Kt.Rapier,Kt.LZString))})(this,(function(Kt,Qt,At,ze,le,ys){"use strict";var hi=Object.defineProperty;var fi=(Kt,Qt,At)=>Qt in Kt?hi(Kt,Qt,{enumerable:!0,configurable:!0,writable:!0,value:At}):Kt[Qt]=At;var ct=(Kt,Qt,At)=>fi(Kt,typeof Qt!="symbol"?Qt+"":Qt,At);function bs(m){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(m){for(const s in m)if(s!=="default"){const o=Object.getOwnPropertyDescriptor(m,s);Object.defineProperty(t,s,o.get?o:{enumerable:!0,get:()=>m[s]})}}return t.default=m,Object.freeze(t)}const vs=bs(ys);var st=(m=>(m.Proximity="Proximity",m.Magnetic="Magnetic",m.Repel="Repel",m.Orbit="Orbit",m.Vortex="Vortex",m.Fluid="Fluid",m.Elastic="Elastic",m.Holographic="Holographic",m.Sticky="Sticky",m.Dilation="Dilation",m.Parallax="Parallax",m.Noise="Noise",m.Float="Float",m.Pulse="Pulse",m.Draggable="Draggable",m.Scroll="Scroll",m.LookAt="LookAt",m.Glint="Glint",m.Scan="Scan",m.Ratchet="Ratchet",m.Jitter="Jitter",m.Follower="Follower",m.Wrap="Wrap",m.Typewriter="Typewriter",m.Scramble="Scramble",m.Wave="Wave",m.Bounce="Bounce",m.TextTrail="TextTrail",m.Reveal3D="Reveal3D",m.RevealSlide="RevealSlide",m.RevealBlur="RevealBlur",m.TextLiquid="TextLiquid",m.TextVortex="TextVortex",m.TextExplosion="TextExplosion",m.TextRain="TextRain",m.TextGravity="TextGravity",m.TextMatrix="TextMatrix",m.TextNeon="TextNeon",m.TextDissolve="TextDissolve",m.TextOrganic="TextOrganic",m.TextBreathe="TextBreathe",m.TextSpin="TextSpin",m.TextMagnet="TextMagnet",m.TextPerspective="TextPerspective",m.TextMirror="TextMirror",m.TextFloral="TextFloral",m.TextSmoke="TextSmoke",m.TextVariable="TextVariable",m.TextZing="TextZing",m.TextElastic="TextElastic",m.TextGlitch3D="TextGlitch3D",m.GlitchText="GlitchText",m.TextCounter="TextCounter",m.Squash="Squash",m.Spotlight="Spotlight",m.Lens="Lens",m.Gravity="Gravity",m.Velocity="Velocity",m.Shear="Shear",m.LayoutAnimation="LayoutAnimation",m.SpringChain="SpringChain",m.ParticleEmitter="ParticleEmitter",m.StateReactive="StateReactive",m.Fold="Fold",m.Crumple="Crumple",m))(st||{}),ce=(m=>(m.Scale="Scale",m.Opacity="Opacity",m.RotateZ="RotateZ",m.RotateX="RotateX",m.RotateY="RotateY",m.PositionX="PositionX",m.PositionY="PositionY",m.SkewX="SkewX",m.Blur="Blur",m.Exposure="Exposure",m.HueShift="HueShift",m.Negative="Negative",m.CornerRadius="CornerRadius",m.StrokeWidth="StrokeWidth",m.BoxShadow="BoxShadow",m.FontSize="FontSize",m.LetterSpacing="LetterSpacing",m))(ce||{}),je=(m=>(m.Equal="Equal",m.NotEqual="NotEqual",m.GreaterThan="GreaterThan",m.LessThan="LessThan",m.GreaterEqual="GreaterEqual",m.LessEqual="LessEqual",m.IsTrue="IsTrue",m.IsFalse="IsFalse",m))(je||{}),Lt=(m=>(m.AND="AND",m.OR="OR",m.NOT="NOT",m.XOR="XOR",m.OBJECT="OBJECT",m.PROPERTY="PROPERTY",m.GET_PROPERTY="GET_PROPERTY",m.SET_PROPERTY="SET_PROPERTY",m.ADD="ADD",m.SUB="SUB",m.MUL="MUL",m.DIV="DIV",m.MOD="MOD",m.POW="POW",m.ABS="ABS",m.ROUND="ROUND",m.FLOOR="FLOOR",m.CEIL="CEIL",m.SIN="SIN",m.COS="COS",m.TAN="TAN",m.CLAMP="CLAMP",m.REMAP="REMAP",m.EQ="EQ",m.NEQ="NEQ",m.GT="GT",m.LT="LT",m.GTE="GTE",m.LTE="LTE",m.IF_ELSE="IF_ELSE",m.VALUE="VALUE",m.INPUT="INPUT",m.LOG="LOG",m.SCROLL_X="SCROLL_X",m.SCROLL_Y="SCROLL_Y",m.MOUSE_X="MOUSE_X",m.MOUSE_Y="MOUSE_Y",m.IS_MOUSE_DOWN="IS_MOUSE_DOWN",m.EFFECTOR="EFFECTOR",m.MONITOR="MONITOR",m.DELAY="DELAY",m.SPRING_PULL="SPRING_PULL",m.SPRING_SETTLE="SPRING_SETTLE",m.EMIT="EMIT",m))(Lt||{});function Ss(m){if(m.length<5)return m;const t=new Set("aeiouyAEIOUY".split(""));if(/[\u4E00-\u9FFF\u3400-\u4DBF]/.test(m))return m;let o="";for(let e=0;e<m.length;e++){if(o+=m[e],e>=m.length-2)continue;const n=t.has(m[e]),i=t.has(m[e+1]),a=t.has(m[e+2]);n&&!i&&a&&(o+="­"),n&&!i&&!a&&e>=1&&(o+="­")}return o}function Cs(m){return m.replace(/\b([a-zA-Z]{4,})\b/g,(t,s)=>Ss(s))}function ws(m,t,s){return m}function Ms(m,t,s){return m}const Ge=new Map;function ts(m){var I;const{text:t,fontFamily:s="Inter",fontSize:o=16,fontWeight:e=400,fontStyle:n="normal",lineHeight:i=1.2,width:a=200,letterSpacing:r=0,paragraphSpacing:l=0,paragraphIndent:f=0,textCase:p="none",segments:u=[],enableSegments:g=!1}=m;let h=String(t||"");p==="uppercase"?h=h.toUpperCase():p==="lowercase"?h=h.toLowerCase():p==="capitalize"&&(h=h.replace(/\b\w/g,E=>E.toUpperCase())),m.hyphenation===!0&&(h=Cs(h));const d=`${n} ${e} ${o}px "${s}", sans-serif`,w=`${h}|${d}|${r}|${l}|${f}|${g}|${JSON.stringify(u)}|hyp:${!!m.hyphenation}|comp:${m.composer}|bal:${!!m.balanceRaggedLines}`;let y=Ge.get(w);const c=typeof CanvasRenderingContext2D<"u"?CanvasRenderingContext2D.prototype.measureText:null,v=function(E){if(!c)return{width:0,fontBoundingBoxAscent:0,fontBoundingBoxDescent:0};const _=c.call(this,E);return r!==0&&E&&E.length>0?{..._,width:_.width+(E.length-1)*r}:_};if(!y){try{if(r!==0&&typeof CanvasRenderingContext2D<"u"&&(CanvasRenderingContext2D.prototype.measureText=v),g&&u&&u.length>0){const E=u.map(_=>{let T=_.text||"";const A=_.textCase||p||"none";return A==="uppercase"?T.toUpperCase():A==="lowercase"?T.toLowerCase():A==="capitalize"?T.replace(/\b\w/g,R=>R.toUpperCase()):T}).join("");if(y=ze.prepareWithSegments(E,d),y){let _=0,T=o;for(const A of u){let R=A.text||"";if(!R)continue;const Y=A.textCase||p||"none";Y==="uppercase"?R=R.toUpperCase():Y==="lowercase"?R=R.toLowerCase():Y==="capitalize"&&(R=R.replace(/\b\w/g,k=>k.toUpperCase()));const L=A.fontSize||o;L>T&&(T=L);const D=`${A.fontStyle||n} ${A.fontWeight||e} ${L}px "${A.fontFamily||s}", sans-serif`,P=ze.prepareWithSegments(R,D);if(P&&P.widths)for(let k=0;k<P.widths.length;k++){const O=_+k;if(O<y.widths.length){y.widths[O]=P.widths[k];const $=P.kinds[k];if($===2){const X=R[k];X===`
2
- `||X==="\r"?y.kinds[O]=2:y.kinds[O]=0}else y.kinds[O]=$}}_+=R.length}y.fullText=E,y.maxFontSize=T}}else y=ze.prepareWithSegments(h,d);y&&Ge.set(w,y)}catch(E){return console.error("[ExodeUI] Pretext prepare failed:",E),{width:a,height:0,lineCount:0,lines:[]}}finally{r!==0&&typeof CanvasRenderingContext2D<"u"&&c&&(CanvasRenderingContext2D.prototype.measureText=c)}if(Ge.size>500){const E=Ge.keys().next().value;E&&Ge.delete(E)}}if(f>0&&y&&y.widths&&!y.indentApplied){const E=[...y.widths],_=y.fullText||h;let T=!0;for(let A=0;A<_.length;A++)T&&E[A]!==void 0&&(E[A]+=f,T=!1),(_[A]===`
3
- `||_[A]==="\r")&&(T=!0,_[A]==="\r"&&_[A+1]===`
4
- `&&A++);y={...y,widths:E,indentApplied:!0}}if(!y)return{width:a,height:0,lineCount:0,lines:[]};let b=i;typeof b=="string"&&(b=parseFloat(b)),b>5&&o>0&&(b=b/o),r!==0&&(CanvasRenderingContext2D.prototype.measureText=v);let S;try{const E=y.maxFontSize||o;if(a>=1e5){const _=h.split(/\r\n|\r|\n/);S={lines:_.map(T=>({text:T,width:0})),height:_.length*(b*E),lineCount:_.length}}else S=ze.layoutWithLines(y,a,b*E)}finally{r!==0&&c&&(CanvasRenderingContext2D.prototype.measureText=c)}let C=(S==null?void 0:S.height)!==void 0&&S.height>0?S.height:(((I=S==null?void 0:S.lines)==null?void 0:I.length)||0)*b*o;if(l>0&&S&&S.lines&&S.lines.length>1){let E=0;const _=y.fullText||t;for(let T=0;T<S.lines.length-1;T++)E+=S.lines[T].text.length,(_[E]===`
5
- `||_[E]==="\r")&&(C+=l,E++,_[E-1]==="\r"&&_[E]===`
6
- `&&E++)}let M=(S==null?void 0:S.lines)||[];return m.composer==="every-line"&&M.length>1&&(M=ws(M)),m.balanceRaggedLines===!0&&M.length>1&&(M=Ms(M)),{width:a,height:C,lineCount:M.length,lines:M}}function es(m,t,s){let o=String(m||"").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),n=new Array(e.length).fill(0);let i=t-(e.length-1)*s,a=0;if(e.forEach((r,l)=>{if(r.endsWith("px")){const f=parseFloat(r);n[l]=f,i-=f}else r.endsWith("fr")?a+=parseFloat(r):r==="auto"&&(n[l]=100,i-=100)}),a>0&&i>0){const r=i/a;e.forEach((l,f)=>{l.endsWith("fr")&&(n[f]=r*parseFloat(l))})}return n}function ss(m,t,s){try{const o=m.autoLayout;return!o||!o.enabled?{childUpdates:[]}:(o.mode||"linear")==="grid"?ks(m,t,s):Is(m,t,s)}catch(o){return console.error("Layout Engine Error:",o),{childUpdates:[]}}}function Is(m,t,s){var R,Y;const o=m.autoLayout,{direction:e,spacing:n,padding:i,align:a,wrap:r}=o,l=e==="vertical",f=t.map(L=>{const D=s(L.id),P=L.geometry;let k=(D==null?void 0:D.width)??P.width??100,O=(D==null?void 0:D.height)??P.height??100;if(P.type==="Ellipse"||P.type==="Polygon"||P.type==="Star"){const $=(D==null?void 0:D.radius)??P.radius??(D==null?void 0:D.outer_radius)??P.outer_radius??50;k=$*2,O=$*2}else if(P.type==="Text"){const $=ts({text:(D==null?void 0:D.text)??P.text??"",fontFamily:P.fontFamily,fontSize:P.fontSize,fontWeight:P.fontWeight,fontStyle:P.fontStyle,lineHeight:P.lineHeight,width:P.width||200,letterSpacing:P.letterSpacing,paragraphSpacing:P.paragraphSpacing,paragraphIndent:P.paragraphIndent,textCase:P.textCase,segments:P.segments,enableSegments:P.enableSegments});O=$.height,P.width||(k=$.width)}return k*=L.transform.scale_x||1,O*=L.transform.scale_y||1,{id:L.id,w:k,h:O,original:L}});let p=m.width,u=m.height;const g=((R=m.layoutProps)==null?void 0:R.width)==="hug",h=((Y=m.layoutProps)==null?void 0:Y.height)==="hug",d=[];let w=[],y=0,c=0;const v=p-i.left-i.right,b=u-i.top-i.bottom;f.forEach(L=>{r&&w.length>0&&(l?c+n+L.h>b:y+n+L.w>v)?(d.push({children:w,width:y,height:c}),w=[L],y=L.w,c=L.h):(w.push(L),l?(y=Math.max(y,L.w),c+=(w.length>1?n:0)+L.h):(y+=(w.length>1?n:0)+L.w,c=Math.max(c,L.h)))}),w.length>0&&d.push({children:w,width:y,height:c}),g&&!l&&(p=Math.max(...d.map(L=>L.width),0)+i.left+i.right),h&&l&&(u=Math.max(...d.map(L=>L.height),0)+i.top+i.bottom);const S=[];let C=i.left,M=i.top;const I=a.toLowerCase(),E=I==="center"||I.endsWith("-center"),_=I.endsWith("-right"),T=I==="center"||I.startsWith("center-"),A=I.startsWith("bottom-");return d.forEach(L=>{let D=C,P=M;l?T?P=i.top+(u-i.top-i.bottom-L.height)/2:A&&(P=u-i.bottom-L.height):E?D=i.left+(p-i.left-i.right-L.width)/2:_&&(D=p-i.right-L.width),L.children.forEach(k=>{var B,j;let O=D,$=P;l?E?O+=(L.width-k.w)/2:_&&(O+=L.width-k.w):T?$+=(L.height-k.h)/2:A&&($+=L.height-k.h);const X=((B=k.original.layoutProps)==null?void 0:B.width)==="fill",F=((j=k.original.layoutProps)==null?void 0:j.height)==="fill";S.push({id:k.id,x:O+k.w/2-p/2,y:$+k.h/2-u/2,width:X&&l?L.width:void 0,height:F?l?void 0:L.height:void 0}),l?P+=k.h+n:D+=k.w+n}),l?C+=L.width+n:M+=L.height+n}),{frameWidth:g?p:void 0,frameHeight:h?u:void 0,childUpdates:S}}function ks(m,t,s){const o=m.autoLayout;if(!o)return{childUpdates:[]};const{gridColumns:e,gridRows:n,columnGap:i=0,rowGap:a=0,padding:r,align:l}=o;let f=m.width,p=m.height;const u=f-r.left-r.right,g=p-r.top-r.bottom,h=es(e||"1fr",u,i),d=es(n||"auto",g,a),w=h.length>0?h.reduce((_,T)=>_+T,0)+(h.length-1)*i:0,y=d.length>0?d.reduce((_,T)=>_+T,0)+(d.length-1)*a:0,c=l.toLowerCase(),v=c==="center"||c.endsWith("-center"),b=c.endsWith("-right"),S=c==="center"||c.startsWith("center-"),C=c.startsWith("bottom-");let M=0,I=0;v?M=(u-w)/2:b&&(M=u-w),S?I=(g-y)/2:C&&(I=g-y);const E=[];return t.forEach((_,T)=>{var j,z;const A=T%h.length||0,R=Math.floor(T/h.length)||0;R>=d.length&&d.push(100);const Y=h[A],L=d[R];let D=r.left+M+h.slice(0,A).reduce((q,U)=>q+U+i,0),P=r.top+I+d.slice(0,R).reduce((q,U)=>q+U+a,0);const k=s(_.id),O=_.geometry;let $=(k==null?void 0:k.width)??O.width??100,X=(k==null?void 0:k.height)??O.height??100;if(O.type==="Ellipse"||O.type==="Polygon"||O.type==="Star"){const q=(k==null?void 0:k.radius)??O.radius??(k==null?void 0:k.outer_radius)??O.outer_radius??50;$=q*2,X=q*2}$*=_.transform.scale_x||1,X*=_.transform.scale_y||1;let F=D,B=P;v?F+=(Y-$)/2:b&&(F+=Y-$),S?B+=(L-X)/2:C&&(B+=L-X),E.push({id:_.id,x:F+$/2-f/2,y:B+X/2-p/2,width:((j=_.layoutProps)==null?void 0:j.width)==="fill"?Y:void 0,height:((z=_.layoutProps)==null?void 0:z.height)==="fill"?L:void 0})}),{childUpdates:E}}class is{constructor(){ct(this,"world",null);ct(this,"bodies",new Map);ct(this,"colliders",new Map);ct(this,"joints",new Map);ct(this,"initialized",!1);ct(this,"bodyIdByCollider",new Map);ct(this,"onCollisionCB",null);ct(this,"eventQueue",null)}setCollisionCallback(t){this.onCollisionCB=t}async init(t){this.initialized||(await le.init(),this.world=new le.World(new le.Vector2(t.x*100,t.y*100)),this.eventQueue=new le.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 le.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 s=t.isStatic?le.RigidBodyDesc.fixed():le.RigidBodyDesc.dynamic();s.setTranslation(t.x,t.y),t.rotation!==void 0&&s.setRotation(t.rotation);const o=this.world.createRigidBody(s);let e;switch(t.type){case"Rectangle":e=le.ColliderDesc.cuboid(t.width/2,t.height/2);break;case"Ellipse":e=le.ColliderDesc.ball(Math.max(t.width,t.height)/2);break;case"Triangle":case"Star":case"Polygon":e=le.ColliderDesc.cuboid(t.width/2,t.height/2);break;default:e=le.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 i=t.width*t.height;e.setDensity(t.mass/i)}t.isSensor&&e.setSensor(!0);const n=this.world.createCollider(e,o);this.bodyIdByCollider.set(n.handle,t.id),t.frictionAir!==void 0&&o.setLinearDamping(t.frictionAir*10),this.bodies.set(t.id,o),this.colliders.set(t.id,n)}removeBody(t){const s=this.bodies.get(t),o=this.colliders.get(t);o&&this.bodyIdByCollider.delete(o.handle),s&&this.world&&(this.world.removeRigidBody(s),this.bodies.delete(t),this.colliders.delete(t))}step(t){if(!this.world)return;this.world.step(this.eventQueue);const s=this.onCollisionCB,o=this.eventQueue;s&&o&&o.drainContactEvents((e,n,i)=>{const a=this.bodyIdByCollider.get(e),r=this.bodyIdByCollider.get(n);a&&r&&s(a,r,i)})}getPosition(t){const s=this.bodies.get(t);if(!s)return null;const o=s.translation();return{x:o.x,y:o.y}}getRotation(t){const s=this.bodies.get(t);return s?s.rotation():null}getVelocity(t){const s=this.bodies.get(t);if(!s)return null;const o=s.linvel();return{x:o.x,y:o.y}}setPosition(t,s,o){const e=this.bodies.get(t);e&&e.setTranslation(new le.Vector2(s,o),!0)}setRotation(t,s){const o=this.bodies.get(t);o&&o.setRotation(s,!0)}setVelocity(t,s,o){const e=this.bodies.get(t);e&&e.setLinvel(new le.Vector2(s,o),!0)}setAngularVelocity(t,s){const o=this.bodies.get(t);o&&o.setAngvel(s,!0)}applyForce(t,s,o){const e=this.bodies.get(t);e&&e.addForce(new le.Vector2(s,o),!0)}applyImpulse(t,s,o){const e=this.bodies.get(t);e&&e.applyImpulse(new le.Vector2(s,o),!0)}createJoint(t){if(!this.world){console.warn("[RapierPhysics] World not initialized");return}this.joints.has(t.id)&&this.removeJoint(t.id);const s=this.bodies.get(t.bodyA),o=this.bodies.get(t.bodyB);if(!s||!o){console.warn(`[RapierPhysics] Cannot create joint ${t.id}: bodyA (${t.bodyA}) or bodyB (${t.bodyB}) not found`);return}const e=new le.Vector2(t.anchorA.x,t.anchorA.y),n=new le.Vector2(t.anchorB.x,t.anchorB.y);let i;if(t.type==="Distance"){const a=t.length??100,r=t.stiffness??100,l=t.damping??10;i=le.JointData.spring(a,r,l,e,n)}else i=le.JointData.revolute(e,n);try{const a=this.world.createImpulseJoint(i,s,o,!0);this.joints.set(t.id,a)}catch(a){console.error(`[RapierPhysics] Failed to create joint ${t.id}:`,a)}}removeJoint(t){const s=this.joints.get(t);if(s&&this.world){try{this.world.removeImpulseJoint(s,!0)}catch(o){console.error(`[RapierPhysics] Failed to remove joint ${t}:`,o)}this.joints.delete(t)}}}const ns=m=>m,Ts=m=>m>0?1:0,Ps=m=>m<1?0:1,os=m=>m*m,as=m=>m*(2-m),rs=m=>m<.5?2*m*m:-1+(4-2*m)*m,_s=m=>m*m*m,Es=m=>--m*m*m+1,As=m=>m<.5?4*m*m*m:(m-1)*(2*m-2)*(2*m-2)+1,Ls=m=>m*m*m*m,Rs=m=>1- --m*m*m*m,Os=m=>m<.5?8*m*m*m*m:1-8*--m*m*m*m,$s=m=>m*m*m*m*m,Fs=m=>1+--m*m*m*m*m,Bs=m=>m<.5?16*m*m*m*m*m:1+16*--m*m*m*m*m,Ws=m=>1-Math.cos(m*Math.PI/2),xs=m=>Math.sin(m*Math.PI/2),Ys=m=>-(Math.cos(Math.PI*m)-1)/2,Ds=m=>m===0?0:Math.pow(2,10*(m-1)),Xs=m=>m===1?1:1-Math.pow(2,-10*m),Ns=m=>m===0?0:m===1?1:m<.5?Math.pow(2,20*m-10)/2:(2-Math.pow(2,-20*m+10))/2,Gs=m=>1-Math.sqrt(1-m*m),Hs=m=>Math.sqrt(1- --m*m),Vs=m=>m<.5?(1-Math.sqrt(1-4*m*m))/2:(Math.sqrt(1-(-2*m+2)*(-2*m+2))+1)/2,Ue=1.70158,qe=Ue*1.525,ls=Ue+1,zs=m=>ls*m*m*m-Ue*m*m,Us=m=>1+ls*Math.pow(m-1,3)+Ue*Math.pow(m-1,2),qs=m=>m<.5?Math.pow(2*m,2)*((qe+1)*2*m-qe)/2:(Math.pow(2*m-2,2)*((qe+1)*(m*2-2)+qe)+2)/2,cs=2*Math.PI/3,hs=2*Math.PI/4.5,Js=m=>m===0?0:m===1?1:-Math.pow(2,10*m-10)*Math.sin((m*10-10.75)*cs),Ks=m=>m===0?0:m===1?1:Math.pow(2,-10*m)*Math.sin((m*10-.75)*cs)+1,Qs=m=>m===0?0:m===1?1:m<.5?-(Math.pow(2,20*m-10)*Math.sin((20*m-11.125)*hs))/2:Math.pow(2,-20*m+10)*Math.sin((20*m-11.125)*hs)/2+1,Je=m=>m<1/2.75?7.5625*m*m:m<2/2.75?7.5625*(m-=1.5/2.75)*m+.75:m<2.5/2.75?7.5625*(m-=2.25/2.75)*m+.9375:7.5625*(m-=2.625/2.75)*m+.984375,Zs=m=>1-Je(1-m),js=Je,ti=m=>m<.5?(1-Je(1-2*m))/2:(1+Je(2*m-1))/2,Ze=new Map,He=(m,t,s,o)=>{const e=`${m},${t},${s},${o}`;if(Ze.has(e))return Ze.get(e);const n=f=>(1-3*s+3*m)*f*f*f+(3*s-6*m)*f*f+3*m*f,i=f=>(1-3*o+3*t)*f*f*f+(3*o-6*t)*f*f+3*t*f,a=f=>3*(1-3*s+3*m)*f*f+2*(3*s-6*m)*f+3*m,r=f=>{let p=f;for(let u=0;u<8;u++){const g=n(p)-f;if(Math.abs(g)<1e-6)return p;const h=a(p);if(Math.abs(h)<1e-6)break;p=p-g/h}return p},l=f=>f===0?0:f===1?1:i(r(f));return Ze.set(e,l),l},fs=m=>{const t=m.match(/cubic-bezier\s*\(\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*\)/);if(!t)return null;const[,s,o,e,n]=t.map(Number);return He(s,o,e,n)},ds={ease:He(.25,.1,.25,1),"ease-in":He(.42,0,1,1),"ease-out":He(0,0,.58,1),"ease-in-out":He(.42,0,.58,1)},Ke={Linear:ns,EaseInQuad:os,EaseOutQuad:as,EaseInOutQuad:rs,EaseInCubic:_s,EaseOutCubic:Es,EaseInOutCubic:As,EaseInQuart:Ls,EaseOutQuart:Rs,EaseInOutQuart:Os,EaseInQuint:$s,EaseOutQuint:Fs,EaseInOutQuint:Bs,EaseInSine:Ws,EaseOutSine:xs,EaseInOutSine:Ys,EaseInExpo:Ds,EaseOutExpo:Xs,EaseInOutExpo:Ns,EaseInCirc:Gs,EaseOutCirc:Hs,EaseInOutCirc:Vs,EaseInBack:zs,EaseOutBack:Us,EaseInOutBack:qs,EaseInElastic:Js,EaseOutElastic:Ks,EaseInOutElastic:Qs,EaseInBounce:Zs,EaseOutBounce:js,EaseInOutBounce:ti,EaseIn:os,EaseOut:as,EaseInOut:rs,StepStart:Ts,StepEnd:Ps},ei=m=>{const t=m.trim(),s=t.toLowerCase();if(Ke[t])return Ke[t];const o=Object.keys(Ke).find(n=>n.toLowerCase()===s);if(o)return Ke[o];const e=Object.keys(ps).find(n=>n.toLowerCase()===s);if(e){const n=fs(ps[e].value);if(n)return n}if(ds[s])return ds[s];if(s.startsWith("cubic-bezier")){const n=fs(t);if(n)return n}return ns},ps={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)"}},si=(m,t,s,o,e)=>{if(!m||!t||!s)return m;const n=o.scale_x??1,i=o.scale_y??1,a=(r,l,f)=>{let p=0,u=0;const g=o.rotation*Math.PI/180,h=Math.cos(g),d=Math.sin(g),w=r*n*h-l*i*d+o.x,y=r*n*d+l*i*h+o.y;f.forEach(I=>{const E=e(I.boneId);if(!E)return;const _={x:E.x,y:E.y,rotation:E.rotation,scaleX:E.scale_x??1,scaleY:E.scale_y??1},T=s[I.boneId]||[1,0,0,1,0,0],A=w*T[0]+y*T[2]+T[4],R=w*T[1]+y*T[3]+T[5],Y=_.rotation*Math.PI/180,L=Math.cos(Y),D=Math.sin(Y),P=A*_.scaleX*L-R*_.scaleY*D+_.x,k=A*_.scaleX*D+R*_.scaleY*L+_.y;p+=P*I.amount,u+=k*I.amount});const c=[...f].sort((I,E)=>E.amount-I.amount);if(c.length>=2&&c[0].amount>0&&c[1].amount>0){const I=e(c[0].boneId),E=e(c[1].boneId);if(I&&E&&I.length!==void 0&&E.length!==void 0){const _=I.length*(I.scale_y??1),T=I.rotation*Math.PI/180,A=I.x-_*Math.sin(T),R=I.y+_*Math.cos(T),Y=E.length*(E.scale_y??1),L=E.rotation*Math.PI/180,D=E.x-Y*Math.sin(L),P=E.y+Y*Math.cos(L);let k=null,O=null,$=!1;const X=1;if(Math.hypot(I.x-E.x,I.y-E.y)<X||Math.hypot(I.x-D,I.y-P)<X?(k=I.x,O=I.y):(Math.hypot(A-E.x,R-E.y)<X||Math.hypot(A-D,R-P)<X)&&(k=A,O=R,$=!0),k!==null&&O!==null){const F=s[c[0].boneId]||[1,0,0,1,0,0],B=F[0]*F[3]-F[1]*F[2];let j=0,z=0;if(B!==0){const q=(F[2]*F[5]-F[3]*F[4])/B,U=(F[1]*F[4]-F[0]*F[5])/B,J=Math.atan2(-F[1],F[3]);if(!$)j=q,z=U;else{const H=-F[2]/B,rt=F[0]/B,It=Math.hypot(H,rt),mt=I.length*It;j=q-mt*Math.sin(J),z=U+mt*Math.cos(J)}const W=Math.hypot(w-j,y-z),N=Math.hypot(p-k,u-O);if(N>0&&W>0){const H=Math.max(N,.01),rt=Math.min(W/H,3),It=k+(p-k)*rt,mt=O+(u-O)*rt,St=c[0].amount,pt=c[1].amount,kt=Math.min(St,pt)*2,Bt=1-Math.pow(1-kt,4);p=p*(1-Bt)+It*Bt,u=u*(1-Bt)+mt*Bt}}}}}const v=o.rotation*Math.PI/180,b=Math.cos(v),S=Math.sin(v),C=p-o.x,M=u-o.y;return{x:(C*b+M*S)/n,y:(-C*S+M*b)/i}};return m.map((r,l)=>{const f=t[l];if(!f||f.length===0)return{...r};const p={...r,...a(r.x,r.y,f)};if(r.in_x!==void 0&&r.in_y!==void 0){const u=a(r.in_x,r.in_y,f);p.in_x=u.x,p.in_y=u.y}if(r.out_x!==void 0&&r.out_y!==void 0){const u=a(r.out_x,r.out_y,f);p.out_x=u.x,p.out_y=u.y}return p})};function ii(m,t,s,o,e){const n=m*s*.01,i=t*s*.01,a=Math.sin(e*12.9898)*43758.5453%(Math.PI*2),r=Math.cos(e*78.233)*43758.5453%(Math.PI*2);return(Math.sin(n+a)*Math.cos(i+r)+.5*Math.sin(n*2.1-r)*Math.cos(i*2.3+a)+.25*Math.sin(n*4.5+a)*Math.cos(i*4.2-r))/1.75*o}function ni(m,t,s,o,e,n,i=0,a=0){const r=[];if(!m)return[];const l=m.type;if(l==="Rectangle"||l==="Image"||l==="Frame"){const h=Math.max(20,Math.floor((t+s)/10)),d=Math.max(2,Math.floor(h*(t/(t+s)))),w=Math.max(2,Math.floor(h*(s/(t+s))));for(let y=0;y<d;y++)r.push({x:-t/2+t/d*y,y:-s/2,nx:0,ny:-1});for(let y=0;y<w;y++)r.push({x:t/2,y:-s/2+s/w*y,nx:1,ny:0});for(let y=0;y<d;y++)r.push({x:t/2-t/d*y,y:s/2,nx:0,ny:1});for(let y=0;y<w;y++)r.push({x:-t/2,y:s/2-s/w*y,nx:-1,ny:0})}else if(l==="Ellipse"){const h=Math.max(60,Math.floor(Math.PI*Math.max(t,s)/5));for(let d=0;d<h;d++){const w=d/h*Math.PI*2,y=Math.cos(w),c=Math.sin(w);r.push({x:y*t/2,y:c*s/2,nx:y,ny:c})}}else if(l==="Triangle"){const h={x:0,y:-s/2},d={x:t/2,y:s/2},w={x:-t/2,y:s/2},y=20;let c=d.x-h.x,v=d.y-h.y,b=Math.hypot(c,v),S=-v/b,C=c/b;for(let M=0;M<y;M++)r.push({x:h.x+c*(M/y),y:h.y+v*(M/y),nx:S,ny:C});c=w.x-d.x,v=w.y-d.y,b=Math.hypot(c,v),S=-v/b,C=c/b;for(let M=0;M<y;M++)r.push({x:d.x+c*(M/y),y:d.y+v*(M/y),nx:S,ny:C});c=h.x-w.x,v=h.y-w.y,b=Math.hypot(c,v),S=-v/b,C=c/b;for(let M=0;M<y;M++)r.push({x:w.x+c*(M/y),y:w.y+v*(M/y),nx:S,ny:C})}else for(let d=0;d<80;d++){const w=d/80*Math.PI*2,y=Math.cos(w),c=Math.sin(w);r.push({x:y*t/2,y:c*s/2,nx:y,ny:c})}const f=i*Math.PI/180,p=Math.cos(f),u=Math.sin(f);return r.map(h=>{const d=ii(h.x,h.y,e,o,n),w=h.nx*(1-a)+p*a,y=h.ny*(1-a)+u*a;let c=Math.hypot(w,y);return c===0&&(c=1),{x:h.x+w/c*d,y:h.y+y/c*d}})}const oi={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={vibrant:["#6366f1","#22d3ee","#f59e0b","#ec4899","#34d399","#a855f7","#f87171"],pastel:["#a5b4fc","#67e8f9","#fcd34d","#f9a8d4","#6ee7b7","#c4b5fd","#fca5a5"],neon:["#00f5ff","#ff00e5","#00ff9f","#ff6b00","#b400ff","#ffe600","#00c3ff"],warm:["#f97316","#ef4444","#f59e0b","#dc2626","#fb923c","#e11d48","#ea580c"],ocean:["#06b6d4","#0ea5e9","#38bdf8","#7dd3fc","#0284c7","#0369a1","#bae6fd"]};class gs{constructor(){ct(this,"artboard",null);ct(this,"objectStates",new Map);ct(this,"physicsEngine",null);ct(this,"activeStateMachine",null);ct(this,"inputs",new Map);ct(this,"inputNameMap",new Map);ct(this,"layerStates",new Map);ct(this,"pretextCache",new Map);ct(this,"pointerHistory",[]);ct(this,"MAX_HISTORY",200);ct(this,"imageCache",new Map);ct(this,"lastValidSvgImgMap",new Map);ct(this,"maskBuffer",null);ct(this,"maskCtx",null);ct(this,"lumaBuffer",null);ct(this,"lumaCtx",null);ct(this,"_noiseTileCanvas",null);ct(this,"layout",{fit:"Contain",alignment:"Center"});ct(this,"onTrigger");ct(this,"onInputUpdate");ct(this,"onComponentChange");ct(this,"onToggle");ct(this,"onInputChange");ct(this,"onInputFocus");ct(this,"onInputBlur");ct(this,"onLog");ct(this,"onButtonClick");ct(this,"onGraphPointClick");ct(this,"justFiredTriggers",new Set);ct(this,"rootTransform",null);ct(this,"canvasWidth",0);ct(this,"canvasHeight",0);ct(this,"lastHoveredObjectId",null);ct(this,"_lastPointerPos",null);ct(this,"_prevPointerPos",null);ct(this,"_mouseDelta",{dx:0,dy:0});ct(this,"focusedId",null);ct(this,"draggingSliderId",null);ct(this,"draggingJoystickId",null);ct(this,"activeDropdownId",null);ct(this,"activeObjectId",null);ct(this,"draggingListViewId",null);ct(this,"draggingListViewIsScrollbar",!1);ct(this,"scrollOffset",{x:0,y:0});ct(this,"_totalScroll",{x:0,y:0});ct(this,"draggingBehaviors",new Set);ct(this,"dragStartPointer",null);ct(this,"dragStartPositions",new Map);ct(this,"isMouseDown",!1);ct(this,"activeKeys",new Set);ct(this,"graphHoverStates",new Map);ct(this,"barChartRenderedBars",new Map);ct(this,"pieChartRenderedSlices",new Map);ct(this,"_layoutAnimCache",new Map);ct(this,"_springChainState",new Map);ct(this,"_emitterPools",new Map);ct(this,"objectVelocities",new Map);ct(this,"currentTime",0);ct(this,"frameCount",0);ct(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});ct(this,"onLogicUpdate");ct(this,"logicNodeValues",new Map);ct(this,"logicNodeState",new Map);ct(this,"pointerDownTimes",new Map);ct(this,"activeHoverIds",new Set);ct(this,"onNavigation");ct(this,"periodicTriggerTimes",new Map);ct(this,"wasInView",new Set);ct(this,"scrollProgressLastValue",new Map);ct(this,"debug_objectsRendered",0);ct(this,"debug_objectsTotal",0);ct(this,"lastRenderTime",0);ct(this,"debugMode",!1);ct(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){if(this.inputs.has(t))return this.inputs.get(t);const s=this.inputNameMap.get(t);if(s&&s.length>0)return this.inputs.get(s[0])}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:s,isClosed:o}=this.svgPathToPoints(t.data);t.points=s,t.is_closed===void 0&&(t.is_closed=o)}svgPathToPoints(t){const s=/([MLHVCSQTAZmlhvcsqtaz])([^MLHVCSQTAZmlhvcsqtaz]*)/g,o=/[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/g,e=[];let n=!1,i=0,a=0,r=0,l=0,f=0,p=0,u;for(;(u=s.exec(t))!==null;){const g=u[1],h=(u[2].match(o)||[]).map(parseFloat),d=g===g.toLowerCase(),w=g.toUpperCase();let y=0;const c=b=>{let S=h[y++];return d&&(S+=b?i:a),S},v=()=>({x:c(!0),y:c(!1)});switch(w){case"M":{const b=v();for(f=i=b.x,p=a=b.y,e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a,moveTo:!0});y<h.length;){const S=v();i=S.x,a=S.y,e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a})}break}case"L":for(;y<h.length;){const b=v();i=b.x,a=b.y,e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a})}break;case"H":for(;y<h.length;)i=c(!0),e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a});break;case"V":for(;y<h.length;)a=c(!1),e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a});break;case"C":for(;y<h.length;){const b=v(),S=v(),C=v();if(e.length>0){const M=e[e.length-1];M.out_x=b.x,M.out_y=b.y}i=C.x,a=C.y,e.push({x:i,y:a,in_x:S.x,in_y:S.y,out_x:i,out_y:a}),r=S.x,l=S.y}break;case"S":for(;y<h.length;){const b={x:2*i-r,y:2*a-l},S=v(),C=v();if(e.length>0){const M=e[e.length-1];M.out_x=b.x,M.out_y=b.y}i=C.x,a=C.y,e.push({x:i,y:a,in_x:S.x,in_y:S.y,out_x:i,out_y:a}),r=S.x,l=S.y}break;case"Q":for(;y<h.length;){const b=v(),S=v();if(e.length>0){const C=e[e.length-1];C.out_x=C.x+2/3*(b.x-C.x),C.out_y=C.y+2/3*(b.y-C.y)}i=S.x,a=S.y,e.push({x:i,y:a,in_x:i+2/3*(b.x-i),in_y:a+2/3*(b.y-a),out_x:i,out_y:a}),r=b.x,l=b.y}break;case"T":for(;y<h.length;){const b={x:2*i-r,y:2*a-l},S=v();if(e.length>0){const C=e[e.length-1];C.out_x=C.x+2/3*(b.x-C.x),C.out_y=C.y+2/3*(b.y-C.y)}i=S.x,a=S.y,e.push({x:i,y:a,in_x:i+2/3*(b.x-i),in_y:a+2/3*(b.y-a),out_x:i,out_y:a}),r=b.x,l=b.y}break;case"Z":if(n=!0,e.length>0){const b=e[e.length-1];b.closePath=!0;const S=[...e].reverse().find(C=>C.moveTo)||e[0];S&&Math.hypot(S.x-b.x,S.y-b.y)<.1&&(S.in_x=b.in_x,S.in_y=b.in_y,e.pop(),e.length>0&&(e[e.length-1].closePath=!0))}i=f,a=p;break;default:if(h.length>=2){const b=v();i=b.x,a=b.y,e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a})}break}}return{points:e,isClosed:n}}setOnLogCallback(t){this.onLog=t}debugLog(t){this.onLog&&this.onLog(t)}setInputFocusCallback(t){this.onInputFocus=t}setInputBlurCallback(t){this.onInputBlur=t}updateConstraint(t,s,o){var n;const e=(n=this.artboard)==null?void 0:n.objects.find(i=>i.id===t);e&&e.constraints&&e.constraints[s]&&(e.constraints[s]={...e.constraints[s],...o},o.useSpring===!1&&this.objectVelocities.delete(t))}log(...t){this.debugMode&&console.log(...t)}warn(...t){this.debugMode&&console.warn(...t)}setInternalInput(t,s){this.inputs.set(t,s),this.onInputUpdate&&this.onInputUpdate(t,s)}setLayout(t,s){this.layout={fit:t,alignment:s}}getActiveStateIds(t="Base Layer"){const s=this.layerStates.get(t);return s?s.currentStateIds:[]}getObjectState(t){return this.objectStates.get(t)}updateObjectOptions(t,s){const o=this.objectStates.get(t);o&&(o.options={...o.options,...s})}updateGraphData(t,s,o){var n,i,a;if(!this.artboard)return;const e=this.artboard.objects.find(r=>r.id===t||r.name===t);if(e){const r=((n=e.geometry)==null?void 0:n.type)==="LineGraph",l=e.type==="BarChart"||e.type==="Component"&&e.variant==="barchart",f=e.type==="PieChart"||e.type==="Component"&&e.variant==="piechart";if(r){const p=e.geometry,u=Array.isArray(s[0])?s[0]:s;!p.datasets||p.datasets.length===0?p.datasets=[{id:"default",label:"Runtime Data",data:u,lineColor:"#3b82f6",lineWidth:2,showArea:!1}]:p.datasets[0].data=u;const g=this.objectStates.get(e.id);g&&((i=g.geometry)==null?void 0:i.type)==="LineGraph"&&(!g.geometry.datasets||g.geometry.datasets.length===0?g.geometry.datasets=JSON.parse(JSON.stringify(p.datasets)):g.geometry.datasets[0].data=[...u]),(a=p.datasets[0])!=null&&a.inputId&&this.updateInput(p.datasets[0].inputId,u);return}else if(l){this.updateBarChartData(e.id,Array.isArray(s[0])?s:[s],o);return}else if(f){this.updatePieChartData(e.id,Array.isArray(s[0])?s[0]:s);return}}this.updateInput(t,s)}updateBarChartData(t,s,o){if(!this.artboard)return;const e=this.artboard.objects.find(l=>l.id===t||l.name===t);if(!e){this.updateInput(t,s);return}const n=this.objectStates.get(e.id),i=(n==null?void 0:n.options)||e.options||{},a=s.map((l,f)=>{var u;const p=((u=i.datasets)==null?void 0:u[f])||{};return Array.isArray(l)?{id:p.id||`ds-${f}`,label:p.label||`Series ${f+1}`,color:p.color||"#6366f1",data:l}:{id:l.id||p.id||`ds-${f}`,label:l.label||p.label||`Series ${f+1}`,color:l.color||p.color||"#6366f1",data:l.data||[]}}),r={...i,datasets:a};o&&Array.isArray(o)&&(r.categories=o),e.options=r,n&&(n.options=r),i.datasetInputIds&&Array.isArray(i.datasetInputIds)&&i.datasetInputIds.forEach((l,f)=>{a[f]&&this.updateInput(l,a[f].data)}),o&&i.dataInputId&&this.updateInput(i.dataInputId,o)}updatePieChartData(t,s){if(!this.artboard)return;const o=this.artboard.objects.find(l=>l.id===t||l.name===t);if(!o){this.updateInput(t,s);return}const e=this.objectStates.get(o.id),n=(e==null?void 0:e.options)||o.options||{},i=n.slices||[],a=s.map((l,f)=>{const p=i[f]||{};return typeof l=="number"?{id:p.id||`slice-${f}`,label:p.label||`Item ${f+1}`,color:p.color||"",value:l}:{id:l.id||p.id||`slice-${f}`,label:l.label||p.label||`Item ${f+1}`,color:l.color||p.color||"",value:typeof l.value=="number"?l.value:parseFloat(l.value)||0}}),r={...n,slices:a};o.options=r,e&&(e.options=r),n.dataInputId&&this.updateInput(n.dataInputId,a.map(l=>l.value))}setDropdownOptions(t,s){if(!this.artboard)return;const o=this.artboard.objects.find(a=>a.id===t||a.name===t);if(!o){this.updateInput(t,s);return}const e=this.objectStates.get(o.id),n=(e==null?void 0:e.options)||o.options||{},i={...n,optionsList:s};o.options=i,e&&(e.options=i),n.dataInputId&&this.updateInput(n.dataInputId,s)}load(t){var i,a;if(!t)return;let s=this.decompressStrings(t);const o=[],e=new Set,n=r=>{r&&r.forEach(l=>{if(e.has(l.id))return;const f={...l},p=f.childrenObjects||[];e.add(f.id),o.push(f),n(p)})};if(n(s.objects||[]),o.length>(s.objects||[]).length&&this.log(`[Engine] Flattened artboard from ${(s.objects||[]).length} to ${o.length} objects.`),s.objects=o,this.artboard=s,this.currentTime=0,this.objectStates.clear(),this.log(`[ExodeUIEngine] Loading artboard: "${(i=this.artboard)==null?void 0:i.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(l=>{r.set(l.id,l),l.children||(l.children=[])}),this.artboard.objects.forEach(l=>{if(l.parentId){const f=r.get(l.parentId);f&&(f.children||(f.children=[]),f.children.includes(l.id)||f.children.push(l.id))}})}this.loadFonts(),this.preloadImages(this.artboard),this.reset(),this.advance(0)}preloadImages(t){if(!t||!t.objects)return;const s=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=n=>{console.error("[ExodeUI Preload] failed:",n,`Src: ${o.substring(0,80)}...`)},e.src=o,this.imageCache.set(o,e)};t.objects.forEach(o=>{var e,n,i;(e=o.geometry)!=null&&e.src&&s(o.geometry.src),(i=(n=o.style)==null?void 0:n.fill)!=null&&i.src&&s(o.style.fill.src)})}decompressStrings(t){if(t&&typeof t=="object"&&!Array.isArray(t)){if(t._compressed&&t._data)try{const o=vs.decompressFromBase64(t._data);if(o)return o}catch(o){return console.error("[ExodeUI] Failed to decompress string:",o),t._data}const s={};for(const[o,e]of Object.entries(t))s[o]=this.decompressStrings(e);return s}return Array.isArray(t)?t.map(s=>this.decompressStrings(s)):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(s=>{var i,a,r,l,f,p,u;const o=s.width??((i=s.geometry)==null?void 0:i.width)??0,e=s.height??((a=s.geometry)==null?void 0:a.height)??0,n=s.cornerRadius??s.corner_radius??((r=s.geometry)==null?void 0:r.corner_radius)??((l=s.geometry)==null?void 0:l.cornerRadius)??0;this.objectStates.set(s.id,{...s.transform||{},x:((f=s.transform)==null?void 0:f.x)??s.x??0,y:((p=s.transform)==null?void 0:p.y)??s.y??0,width:o,height:e,cornerRadius:n,corner_radius:n,clipContent:s.clipContent??!1,autoLayout:s.autoLayout?JSON.parse(JSON.stringify(s.autoLayout)):void 0,layoutProps:s.layoutProps?JSON.parse(JSON.stringify(s.layoutProps)):void 0,opacity:((u=s.transform)==null?void 0:u.opacity)!==void 0?s.transform.opacity:s.opacity!==void 0?s.opacity:100,visible:s.visible!==void 0?s.visible:s.isVisible!==void 0?s.isVisible:!0,blendMode:s.blendMode||"Normal",style:JSON.parse(JSON.stringify(s.style||{})),geometry:JSON.parse(JSON.stringify(s.geometry||{})),options:s.options?JSON.parse(JSON.stringify(s.options)):{},masks:s.masks?JSON.parse(JSON.stringify(s.masks)):[],zIndex:s.zIndex!==void 0?s.zIndex:void 0})}),this.artboard.objects.some(s=>{var o;return(o=s.physics)==null?void 0:o.enabled})){this.physicsEngine=new is;const s=this.artboard.physics?{x:this.artboard.physics.gravity.x,y:this.artboard.physics.gravity.y}:{x:0,y:1};this.physicsEngine.init(s).then(()=>{var o;this.physicsEngine&&((o=this.artboard)==null||o.objects.forEach(e=>{var n,i;if((n=e.physics)!=null&&n.enabled&&e.type==="Shape"){const a=this.objectStates.get(e.id);if(!a)return;const r=e.geometry.width||100,l=e.geometry.height||100;this.physicsEngine.createBody({id:e.id,type:((i=e.geometry)==null?void 0:i.type)||"Rectangle",x:a.x,y:a.y,width:r,height:l,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(s=>{var n,i;let o=s.value;if(s.type==="RandomNumber"||s.type==="random_number"||s.min!==void 0&&s.max!==void 0&&((n=s.type)!=null&&n.toLowerCase().includes("random"))){const a=s.min??0,r=s.max??100;o=Math.random()*(r-a)+a}else if(s.type==="RandomColor"||s.type==="random_color"||s.minAlpha!==void 0&&((i=s.type)!=null&&i.toLowerCase().includes("random"))){const a=Math.floor(Math.random()*256),r=Math.floor(Math.random()*256),l=Math.floor(Math.random()*256),f=s.minAlpha??0,p=s.maxAlpha??1,u=(Math.random()*(p-f)+f).toFixed(2);o=`rgba(${a}, ${r}, ${l}, ${u})`}this.inputs.set(s.id,o);const e=this.inputNameMap.get(s.name)||[];e.includes(s.id)||e.push(s.id),this.inputNameMap.set(s.name,e)}),this.artboard.stateMachine&&(this.activeStateMachine=this.artboard.stateMachine,this.activeStateMachine.inputs.forEach(s=>{this.inputs.set(s.id,s.value.value);const o=this.inputNameMap.get(s.name)||[];o.push(s.id),this.inputNameMap.set(s.name,o)}),this.activeStateMachine.layers.forEach(s=>{let o=s.states.find(e=>e.id===s.entryStateId);!o&&s.states.length>0&&(console.warn(`[ExodeUI] Invalid entryStateId "${s.entryStateId}" in layer "${s.name}". Falling back to first state.`),o=s.states[0]),o&&this.enterStates(s.name,[o.id])}),this.evaluateTransitions()),this.initGlobalAnimationTriggers(),this.updateAutoLayout(!0),this.loadFonts()}updateAutoLayout(t=!1){var n;if(!this.artboard)return;const s=new Map;this.artboard.objects.forEach(i=>s.set(i.id,i));const o=.15,e=i=>{i.forEach(a=>{const r=this.objectStates.get(a.id);if(r){const l=Math.abs(r.x-a.x),f=Math.abs(r.y-a.y);!t&&(l>20||f>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((n=this.artboard.autoLayout)!=null&&n.enabled){const i=this.artboard.objects.filter(r=>!r.parentId),a=ss(this.artboard,i,r=>this.objectStates.get(r));e(a.childUpdates)}this.artboard.objects.forEach(i=>{var a;if(i.type==="Frame"&&((a=i.autoLayout)!=null&&a.enabled)&&i.children&&i.children.length>0){const r=i.children.map(p=>s.get(p)).filter(p=>!!p),l=this.objectStates.get(i.id);if(!l)return;const f=ss(l,r,p=>this.objectStates.get(p));f.frameWidth!==void 0&&(l.width=f.frameWidth),f.frameHeight!==void 0&&(l.height=f.frameHeight),e(f.childUpdates)}})}loadFonts(){if(!this.artboard)return;const t=new Set;if(this.artboard.objects.forEach(i=>{i.geometry&&i.geometry.type==="Text"&&i.geometry.fontFamily&&t.add(i.geometry.fontFamily)}),this.artboard.animations.forEach(i=>{i.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 s="";t.forEach(i=>{const a=i.replace(/ /g,"+");s+=`&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(s.length>0){const i=`https://fonts.googleapis.com/css2?display=swap${s}`;let a=document.getElementById(o);a||(a=document.createElement("link"),a.id=o,a.rel="stylesheet",document.head.appendChild(a)),a.href!==i&&(a.href=i)}const n=[];if(t.forEach(i=>{i.toLowerCase().includes("clash display")&&n.push("clash-display@200,300,400,500,600,700")}),n.length>0){const i=`https://api.fontshare.com/v2/css?f[]=${n.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!==i&&(a.href=i)}document.fonts&&document.fonts.ready&&document.fonts.ready.then(()=>{this.pretextCache.clear(),this.advance(0)})}enterStates(t,s){var i;if(s.length===0)return;const o=this.layerStates.get(t);if(o&&o.currentStateIds.length===s.length&&s.every(r=>o.currentStateIds.includes(r))&&this.justFiredTriggers.size===0)return;const e=[];let n=0;if(this.artboard&&this.activeStateMachine){const a=this.activeStateMachine.layers.find(r=>r.name===t);if(a)for(const r of s){const l=a.states.find(f=>f.id===r);if(l)if(l.isBlendState&&l.blendAnimations&&l.blendAnimations.length>0)e.push({animation:null,state:l}),l.blendAnimations.forEach(f=>{const p=this.artboard.animations.find(u=>u.id===f.animationId);p&&(n=Math.max(n,this.getAnimationDuration(p)))});else{let f=null;l.animationId&&(f=this.artboard.animations.find(p=>p.id===l.animationId)||null),f||(f=this.artboard.animations.find(p=>{var u,g;return p.name===l.name||p.id===l.name||(l.name==="Entry"||l.id==="entry")&&(((u=p.name)==null?void 0:u.toLowerCase())==="onload"||((g=p.name)==null?void 0:g.toLowerCase())==="intro")})||null),f&&((i=this.artboard.animationFlow)!=null&&i.some(u=>(u.trigger==="on_load"||u.trigger==="after_delay")&&u.targetAnimationId===(f==null?void 0:f.id))||(e.push({animation:f,state:l}),n=Math.max(n,this.getAnimationDuration(f))))}}}this.layerStates.set(t,{currentStateIds:s,animations:e,time:0,duration:n})}setInputBool(t,s){this.updateInput(t,s)}setInputNumber(t,s){this.updateInput(t,s)}fireTrigger(t){this.updateInput(t,!0)}setInputText(t,s){this.updateInput(t,s)}setInputNumberArray(t,s){this.updateInput(t,s)}setInputStringArray(t,s){this.updateInput(t,s)}updateObjectProperty(t,s,o){const e=this.objectStates.get(t);if(e)if(s.includes(".")||s.includes("[")){const n=s.replace(/\[(\d+)\]/g,".$1").split(".");let i=e;for(let a=0;a<n.length-1;a++){if(typeof i[n[a]]!="object"||i[n[a]]===null){const r=n[a+1],l=!isNaN(Number(r));i[n[a]]=l?[]:{}}i=i[n[a]]}i[n[n.length-1]]=o}else e[s]=o}updateInput(t,s){var l,f,p,u,g;let o;if(this.inputs.has(t)){const h=(l=this.activeStateMachine)==null?void 0:l.inputs.find(d=>d.id===t);h&&typeof h.value=="object"&&(o=h.value.type)}else{const h=this.inputNameMap.get(t);if(h&&h.length>0){const d=(f=this.activeStateMachine)==null?void 0:f.inputs.find(w=>w.id===h[0]);d&&typeof d.value=="object"&&(o=d.value.type)}}let e=s;o==="Trigger"&&(s===1?e=!0:s===0&&(e=!1));const n=(u=(p=this.artboard)==null?void 0:p.stateVariables)==null?void 0:u.find(h=>h.id===t||h.name===t);if(n&&(n.type==="RandomNumber"||n.type==="RandomColor"||n.type&&String(n.type).toLowerCase().includes("random"))){if(n.type==="RandomNumber"||n.type==="random_number"||n.min!==void 0&&n.max!==void 0){const h=n.min??0,d=n.max??100;e=Math.random()*(d-h)+h}else if(n.type==="RandomColor"||n.type==="random_color"||n.minAlpha!==void 0){const h=Math.floor(Math.random()*256),d=Math.floor(Math.random()*256),w=Math.floor(Math.random()*256),y=n.minAlpha??0,c=n.maxAlpha??1,v=(Math.random()*(c-y)+y).toFixed(2);e=`rgba(${h}, ${d}, ${w}, ${v})`}}let i=!1;this.inputs.has(t)&&(this.setInternalInput(t,e),i=!0);const a=this.inputNameMap.get(t);a&&a.length>0&&(a.forEach(h=>this.setInternalInput(h,e)),i=!0),i||this.setInternalInput(t,e),o==="Trigger"&&e===!0&&(this.justFiredTriggers.add(t),a&&a.forEach(h=>this.justFiredTriggers.add(h)));let r=null;if(Array.isArray(e))r=e;else if(typeof e=="string"&&e.trim().startsWith("[")&&e.trim().endsWith("]"))try{const h=JSON.parse(e);Array.isArray(h)&&(r=h)}catch{}r&&((g=this.artboard)==null||g.objects.forEach(h=>{var y;const d=(y=h.options)==null?void 0:y.dataInputId;if(h.inputId===t||h.name===t||d===t||a&&(a.includes(h.inputId)||d&&a.includes(d))){let c=this.objectStates.get(h.id);c&&!c.options&&(c.options=JSON.parse(JSON.stringify(h.options||{}))),c&&c.options&&(this.isListViewObject(h)?c.options.items=r:(h.type==="Dropdown"||h.variant==="dropdown")&&(c.options.optionsList=r)),h.options&&(this.isListViewObject(h)?h.options.items=r:(h.type==="Dropdown"||h.variant==="dropdown")&&(h.options.optionsList=r))}})),this.evaluateTransitions(),this.evaluateVariableTriggers(t,e)}evaluateVariableTriggers(t,s){if(!this.artboard)return;const o=this.artboard.animationFlow||[],e=this.inputNameMap.get(t);o.forEach(n=>{if(n.trigger==="variable"&&n.conditionVariableId&&n.targetAnimationId&&(n.conditionVariableId===t||e&&e.includes(n.conditionVariableId))){const a=n.conditionOperator||"IsTrue",r=n.conditionValue;let l=!1;switch(a){case"Equal":case"==":l=s==r;break;case"NotEqual":case"!=":l=s!=r;break;case"GreaterThan":case">":l=s>r;break;case"LessThan":case"<":l=s<r;break;case"GreaterEqual":case">=":l=s>=r;break;case"LessEqual":case"<=":l=s<=r;break;case"IsTrue":l=!!s;break;case"IsFalse":l=!s;break}if(l){const f=n.delay||0;f<=0?this.triggerGlobalAnimation(n.targetAnimationId,n.subAnimationIds,n.loop,n.id):setTimeout(()=>this.triggerGlobalAnimation(n.targetAnimationId,n.subAnimationIds,n.loop,n.id),f)}}})}evaluateTransitions(){this.activeStateMachine&&(this.activeStateMachine.layers.forEach(t=>{const s=this.layerStates.get(t.name);if(!s||s.currentStateIds.length===0)return;const o=[];let e=!1;for(const n of s.currentStateIds){const i=t.states.find(r=>r.id===n);if(!i)continue;let a=!1;for(const r of i.transitions||[])this.checkConditions(r.conditions)&&(o.push(r.targetStateId),a=!0,e=!0);a||o.push(n)}if(!e){const n=this.findGlobalTransition(t,s.currentStateIds);n&&(o.length=0,o.push(n.targetStateId),e=!0,n.conditions&&(n.conditions||[]).forEach(i=>{var r;const a=(r=this.activeStateMachine)==null?void 0:r.inputs.find(l=>l.id===i.inputId);a&&typeof a.value=="object"&&a.value.type==="Trigger"&&this.setInternalInput(i.inputId,!1)}))}if(e){const n=Array.from(new Set(o));this.enterStates(t.name,n)}}),this.justFiredTriggers.size>0&&(this.justFiredTriggers.forEach(t=>{var o,e;this.setInternalInput(t,!1);const s=(o=this.activeStateMachine)==null?void 0:o.inputs.find(n=>n.id===t);s&&this.inputNameMap.has(s.name)&&((e=this.inputNameMap.get(s.name))==null||e.forEach(n=>this.setInternalInput(n,!1)))}),this.justFiredTriggers.clear()))}findGlobalTransition(t,s){for(const o of t.states)if(!(s.includes(o.id)&&this.justFiredTriggers.size===0)){for(const n of o.transitions||[])if(!(s.includes(n.targetStateId)&&this.justFiredTriggers.size===0)&&this.checkConditions(n.conditions))return n}return null}checkConditions(t){return!t||t.length===0?!0:t.every(s=>{const o=s.inputId,e=s.op;let n=s.value;const i=this.evaluateLogicTree(o);if(i===void 0)return this.log(`[Engine] Condition Check Failed: Input ${o} is undefined`),!1;typeof i=="boolean"?n==="true"||n==="1"||n===1?n=!0:(n==="false"||n==="0"||n===0)&&(n=!1):typeof i=="number"&&typeof n=="string"&&(n=parseFloat(n));let a=!1;switch(e){case"Equal":case"==":a=i==n;break;case"NotEqual":case"!=":a=i!=n;break;case"GreaterThan":case">":a=i>n;break;case"LessThan":case"<":a=i<n;break;case"GreaterEqual":case">=":a=i>=n;break;case"LessEqual":case"<=":a=i<=n;break;case"IsTrue":a=!!i;break;case"IsFalse":a=!i;break;default:a=!1}return a||this.justFiredTriggers.has(o),a})}evaluateLogicTree(t,s=null,o=new Set){var a,r,l,f,p,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(g=>g.id===t);if(e){const g=(d,w)=>{const y=e.inputs.find(c=>c.id===d);return y?y.sourceId?this.evaluateLogicTree(y.sourceId,y.sourceHandleId,o):y.value!==void 0?y.value:w:w};let h=0;switch(e.op){case Lt.AND:h=g("a",!1)&&g("b",!1);break;case Lt.OR:h=g("a",!1)||g("b",!1);break;case Lt.NOT:h=!g("in",!1);break;case Lt.XOR:h=!!g("a",!1)!=!!g("b",!1);break;case Lt.OBJECT:h=e.name;break;case Lt.PROPERTY:case Lt.GET_PROPERTY:{const d=g("id","");if(!d){h=0;break}const w=e.name;if(!w||w==="GET_PROPERTY"||w==="PROPERTY"){h=0;break}const y=this.objectStates.get(d);if(!y){h=0;break}w in y?h=y[w]:h=this.resolvePath(y,w);break}case Lt.SET_PROPERTY:{const d=g("id",""),w=g("value",void 0);if(!d||w===void 0){h=0;break}const y=e.name;if(!y||y==="SET_PROPERTY"){h=0;break}const c=this.objectStates.get(d);if(!c){h=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(y))c[y]=w,h=w;else{const b=y.replace(/\[(\d+)\]/g,".$1").split(".");let S=c;for(let M=0;M<b.length-1;M++){const I=b[M],E=b[M+1];S[I]===void 0&&(S[I]=isNaN(Number(E))?{}:[]),S=S[I]}const C=b[b.length-1];S[C]=w,h=w}break}case Lt.ADD:h=g("a",0)+g("b",0);break;case Lt.SUB:h=g("a",0)-g("b",0);break;case Lt.MUL:h=g("a",0)*g("b",0);break;case Lt.DIV:{const d=g("b",1);h=d===0?0:g("a",0)/d;break}case Lt.MOD:h=g("a",0)%g("b",1);break;case Lt.POW:h=Math.pow(g("a",0),g("b",1));break;case Lt.ABS:h=Math.abs(g("in",0));break;case Lt.ROUND:h=Math.round(g("in",0));break;case Lt.FLOOR:h=Math.floor(g("in",0));break;case Lt.CEIL:h=Math.ceil(g("in",0));break;case Lt.SIN:h=Math.sin(g("in",0));break;case Lt.COS:h=Math.cos(g("in",0));break;case Lt.TAN:h=Math.tan(g("in",0));break;case Lt.CLAMP:{const d=g("in",0),w=g("min",0),y=g("max",1);h=Math.max(w,Math.min(y,d));break}case Lt.REMAP:{const d=g("in",0),w=g("inMin",0),y=g("inMax",100),c=g("outMin",0),v=g("outMax",1);h=y===w?c:c+(d-w)*(v-c)/(y-w);break}case Lt.EQ:h=g("a",0)==g("b",0);break;case Lt.NEQ:h=g("a",0)!=g("b",0);break;case Lt.GT:h=g("a",0)>g("b",0);break;case Lt.LT:h=g("a",0)<g("b",0);break;case Lt.GTE:h=g("a",0)>=g("b",0);break;case Lt.LTE:h=g("a",0)<=g("b",0);break;case Lt.IF_ELSE:h=g("cond",!1)?g("then",0):g("else",0);break;case Lt.VALUE:h=e.value!==void 0?e.value:0;break;case Lt.INPUT:h=this.inputs.get(e.name)??0;break;case Lt.LOG:{const d=g("in","");this.debugLog(`[User Logic] ${d}`),h=d;break}case Lt.SCROLL_X:h=this.inputs.get("scrollX")??0;break;case Lt.SCROLL_Y:h=this.inputs.get("scrollY")??0;break;case Lt.MOUSE_X:h=this.inputs.get("mouseX")??0;break;case Lt.MOUSE_Y:h=this.inputs.get("mouseY")??0;break;case Lt.IS_MOUSE_DOWN:h=this.inputs.get("isMouseDown")??!1;break;case Lt.EFFECTOR:{const d=g("id",""),w=g("intensity",1),y=g("trigger",!0);if(!d||!y){h=0;break}const c=e.name;if(!c){h=0;break}const v=this.objectStates.get(d);if(!v){h=0;break}if(["glitch","halftone","pixelate","noise","acid_gradient","acid_rave","shimmer"].includes(c))v.style||(v.style={}),v.style.artEffect={enabled:!0,type:c,intensity:w},h=1;else{v.behaviors||(v.behaviors=[]);let S=v.behaviors.find(C=>C.type===c);S?(S.enabled=!0,S.settings||(S.settings={}),S.settings.intensity=w):(S={id:`eff_${Date.now()}_${c}`,type:c,enabled:!0,sensors:[],settings:{intensity:w}},v.behaviors.push(S)),h=1}break}case Lt.MONITOR:{h=g("in",0);break}case Lt.SPRING_PULL:{const d=g("objectId",""),w=g("forceX",0),y=g("forceY",0);d&&((l=this.artboard)==null||l.objects.forEach(c=>{c.behaviors&&c.behaviors.forEach(v=>{var b;if(v.type===st.SpringChain&&((b=v.settings)!=null&&b.connections)&&(v.settings.connections.some(C=>C.targetId===d)||c.id===d)){this._springChainState.has(c.id)||this._springChainState.set(c.id,new Map);const C=this._springChainState.get(c.id);if(!C.has(d)){const I=this.objectStates.get(d);C.set(d,{x:(I==null?void 0:I.x)??0,y:(I==null?void 0:I.y)??0,vx:0,vy:0})}const M=C.get(d);M&&(M.vx+=w,M.vy+=y)}})})),h=1;break}case Lt.SPRING_SETTLE:{const d=g("objectId","");let w=!0;if(d){const y=g("threshold",1);this._springChainState.forEach(c=>{const v=c.get(d);v&&(Math.abs(v.vx)>y||Math.abs(v.vy)>y)&&(w=!1)})}h=w;break}case Lt.EMIT:{const d=g("objectId",""),w=g("count",20);d&&((f=this.artboard)==null||f.objects.forEach(y=>{y.behaviors&&y.behaviors.forEach(c=>{c.type===st.ParticleEmitter&&y.id===d&&(c._pendingBurst=(c._pendingBurst||0)+w)})})),h=1;break}default:h=0;break}if(this.logicNodeValues.set(t,h),e.op===Lt.DELAY){const d=g("delay",0),w=g("in",0);let y=this.logicNodeState.get(t);for(y||(y={queue:[]},this.logicNodeState.set(t,y)),y.queue.push({time:this.currentTime+d,value:w});y.queue.length>0&&y.queue[0].time<=this.currentTime;)y.lastValue=y.queue.shift().value;h=y.lastValue??0}return h}const n=(p=this.activeStateMachine)==null?void 0:p.inputs.find(g=>g.id===t||g.name===t);if(n&&n.sourceId&&!o.has(n.sourceId)){const g=this.evaluateLogicTree(n.sourceId,n.sourceHandleId,o);return this.inputs.set(n.id,g),g}let i=this.inputs.get(t)??(n?this.inputs.get(n.id):void 0);if((this.justFiredTriggers.has(t)||n&&this.justFiredTriggers.has(n.id))&&(i=!0),s&&i!==void 0){const g=(u=this.activeStateMachine)==null?void 0:u.inputs.find(h=>h.id===t);if(g&&g.value.type==="Number"&&typeof i=="number"){const h=g.value.defaultValue??g.value.value;if(s==="source-greater")return i>h;if(s==="source-less")return i<h;if(s==="source-equal")return i===h}if(s==="source-true")return i===!0;if(s==="source-false")return i===!1;if(s==="source-fire")return this.justFiredTriggers.has(t)}return i!==void 0?i:0}runLogicNodes(){!this.activeStateMachine||!this.activeStateMachine.logicNodes||this.activeStateMachine.logicNodes.forEach(t=>{(t.op===Lt.SET_PROPERTY||t.op===Lt.EFFECTOR)&&this.evaluateLogicTree(t.id)})}resolvePath(t,s){const o=s.replace(/\[(\d+)\]/g,".$1").split(".");let e=t;for(const n of o)if(e&&typeof e=="object"&&n in e)e=e[n];else return;return e}processLogicProperties(){!this.artboard||!this.artboard.objects||this.artboard.objects.forEach(t=>{const s=t.logicProperties;if(s&&s.length>0){const o=this.objectStates.get(t.id);if(!o)return;s.forEach(e=>{let n;if(e.valueType==="variable"?n=this.getInputValue(e.variableId):e.valueType==="constant"&&(n=e.value),n!==void 0){const i=e.name;if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(i))o[i]=n;else{const r=i.replace(/\[(\d+)\]/g,".$1").split(".");let l=o;for(let p=0;p<r.length-1;p++){const u=r[p],g=r[p+1];l[u]===void 0&&(l[u]=isNaN(Number(g))?{}:[]),l=l[u]}const f=r[r.length-1];l[f]=n}}})}})}seek(t){this.artboard&&(this.currentTime=t,this.layerStates.forEach(s=>{s.time=t,s.time>(s.duration||0)&&(s.animations.some(e=>{var n;return((n=e.state)==null?void 0:n.loop)===!0})?s.time%=s.duration||1:s.time=s.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 n=this.physicsEngine.getPosition(o.id),i=this.physicsEngine.getRotation(o.id),a=this.objectStates.get(o.id);a&&n!==null&&i!==null&&(a.x=n.x,a.y=n.y,a.rotation=i*(180/Math.PI))}})),this.activeStateMachine&&(this.runLogicNodes(),this.evaluateTransitions()),this.processLogicProperties();const s=[];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(i=>{var a;return((a=i.state)==null?void 0:a.loop)===!0}))o.time%=o.duration;else{const i=o.time<o.duration+.1;o.time=o.duration,i&&(e.startsWith("global_")&&console.log(`[Engine] GLOBAL layer done: ${e}, duration=${o.duration}, currentStateIds=${JSON.stringify(o.currentStateIds)}, ruleId=${o.ruleId}`),o.currentStateIds.length>0&&this.handleAnimationFinished(o.currentStateIds[0],o.ruleId),e.startsWith("global_")&&s.push(e))}o.animations.forEach(n=>{var i;(i=n.state)!=null&&i.isBlendState&&n.state.blendAnimations?this.applyBlendState(n.state,o.time):n.animation&&this.applyAnimation(n.animation,o.time,n.filterObjectIds)})}}),s.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 n,i,a,r,l,f,p;if(o.phase==="entry")o.time+=t,o.time>=this.getAnimationDuration(o.animation)&&((a=(i=(n=this.artboard)==null?void 0:n.objects.find(u=>u.id===e))==null?void 0:i.triggers)==null||a.find(u=>u.id===o.triggerId),o.phase="hold",o.elapsedHold=0,o.time=this.getAnimationDuration(o.animation)),this.applyAnimation(o.animation,o.time,o.filterObjectIds||o.filterObjectId||void 0);else if(o.phase==="hold"){const u=(f=(l=(r=this.artboard)==null?void 0:r.objects.find(d=>d.id===e))==null?void 0:l.triggers)==null?void 0:f.find(d=>d.id===o.triggerId),g=(u==null?void 0:u.duration)||0;o.elapsedHold+=t*1e3;let h=o.elapsedHold>=g;if((u==null?void 0:u.eventType)==="hover"&&!this.activeHoverIds.has(e)&&(h=!0),((u==null?void 0:u.eventType)==="onHold"||(u==null?void 0:u.eventType)==="pointerDown")&&!this.isMouseDown&&(h=!0),h)if(u!=null&&u.exitAnimationId){const d=(p=this.artboard)==null?void 0:p.animations.find(w=>w.id===u.exitAnimationId);d?(o.phase="exit",o.animation=d,o.time=0):this.activeTriggers.delete(e)}else this.activeTriggers.delete(e)}else o.phase==="exit"&&(o.time+=t,o.time>=this.getAnimationDuration(o.animation)?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(s=>{var e,n,i;const o=(e=s.style)==null?void 0:e.analytics;if(o&&o.isEnabled&&o.triggerType==="visible"){const a=this.objectStates.get(s.id);if(a&&a.visible!==!1){const r=this.getGlobalTransform(s.id),l=(((n=s.geometry)==null?void 0:n.width)||100)*(r.scale_x||1),f=(((i=s.geometry)==null?void 0:i.height)||100)*(r.scale_y||1),p=50,u=r.x+l/2>=-this.canvasWidth/2-p&&r.x-l/2<=this.canvasWidth/2+p&&r.y+f/2>=-this.canvasHeight/2-p&&r.y-f/2<=this.canvasHeight/2+p,g=`analytics_${s.id}`,h=this.wasInView.has(g);u&&!h&&this.fireAnalyticsEvent(s.id,"visible"),u?this.wasInView.add(g):this.wasInView.delete(g)}}}),this.artboard.objects.forEach(s=>{const o=s.interactions||[];o.length!==0&&o.forEach(e=>{const n=e.triggers||[e.event||e.trigger];n&&n.forEach(i=>{var r,l,f;const a=i.toLowerCase();if(a==="on interval"||a==="oninterval"){const p=e.intervalValue||2e3,u=this.periodicTriggerTimes.get(e.id)||0;this.currentTime*1e3-u>=p&&(!e.conditions||this.checkConditions(e.conditions))&&(this.fireEventForObject(s.id,"On Interval"),this.periodicTriggerTimes.set(e.id,this.currentTime*1e3))}if(a==="on delay"||a==="ondelay"){const p=e.delayValue||1e3;!this.periodicTriggerTimes.has(e.id)&&this.currentTime*1e3>=p&&(!e.conditions||this.checkConditions(e.conditions))&&(this.fireEventForObject(s.id,"On Delay"),this.periodicTriggerTimes.set(e.id,this.currentTime*1e3))}if(a==="scroll into view"||a==="scrollintoview"){const p=this.objectStates.get(s.id);if(p&&p.visible!==!1){const u=this.getGlobalTransform(s.id),g=(((r=s.geometry)==null?void 0:r.width)||100)*(u.scale_x||1),h=(((l=s.geometry)==null?void 0:l.height)||100)*(u.scale_y||1),d=50,w=u.x+g/2>=-this.canvasWidth/2-d&&u.x-g/2<=this.canvasWidth/2+d&&u.y+h/2>=-this.canvasHeight/2-d&&u.y-h/2<=this.canvasHeight/2+d,y=this.wasInView.has(s.id);w&&!y&&(!e.conditions||this.checkConditions(e.conditions))&&this.fireEventForObject(s.id,"Scroll Into View"),w?this.wasInView.add(s.id):this.wasInView.delete(s.id)}}if(a==="scroll progress"||a==="scrollprogress"){const p=Math.abs(this.scrollOffset.y)/(((f=this.artboard)==null?void 0:f.height)||1e3),u=this.scrollProgressLastValue.get(e.id)||0;Math.abs(p-u)>.001&&(this.scrollProgressLastValue.set(e.id,p),(e.action==="Set Input"||e.action==="setInput")&&this.updateInput(e.targetInputId,p))}})})}))}solveConstraints(t){this.artboard&&this.artboard.objects.forEach(s=>{if(!s.constraints||s.constraints.length===0)return;const o=this.objectStates.get(s.id);if(!o)return;const e=this.getGlobalTransform(s.id);if(s.constraints.forEach((n,i)=>{var f,p,u,g,h,d,w,y,c;const a=((f=o.constraints)==null?void 0:f[i])||{},r={...n,...a},l=r.strength??1;if(r.type==="Translation"){const v=this.getGlobalTransform(r.targetId);if(v){const b=r.offsetX||0,S=r.offsetY||0,C=v.x+b,M=v.y+S,I=r.useSpring;if(I){const T=this.objectVelocities.get(s.id)||{vx:0,vy:0},A=Math.max(0,Math.min(t,.05)),R=r.copyX!==!1,Y=r.copyY!==!1,L=R?e.x+(C-e.x)*l:e.x,D=Y?e.y+(M-e.y)*l:e.y,{x:P,y:k,vx:O,vy:$}=this.computeSpring(e.x,e.y,T.vx,T.vy,L,D,r,A);R&&(e.x=P),Y&&(e.y=k),this.objectVelocities.set(s.id,{vx:R?O:0,vy:Y?$:0})}else r.copyX!==!1&&(e.x=e.x+(C-e.x)*l),r.copyY!==!1&&(e.y=e.y+(M-e.y)*l);let E=!1,_=!1;if((p=r.limitX)!=null&&p.enabled){const T=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==T&&(E=!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&&(_=!0)}if((E||_)&&I){const T=this.objectVelocities.get(s.id)||{vx:0,vy:0};this.objectVelocities.set(s.id,{vx:E?0:T.vx,vy:_?0:T.vy})}}}else if(r.type==="Rotation"){const v=this.getGlobalTransform(r.targetId);if(v){let S=(v.rotation+(r.offset||0)-e.rotation)%360;S>180&&(S-=360),S<-180&&(S+=360),e.rotation=e.rotation+S*l}}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)*l),r.copyY&&(e.scale_y=e.scale_y+(v.scale_y-e.scale_y)*l))}else if(r.type==="Transform"){const v=this.getGlobalTransform(r.targetId);if(v){e.x=e.x+(v.x-e.x)*l,e.y=e.y+(v.y-e.y)*l;let b=(v.rotation-e.rotation)%360;b>180&&(b-=360),b<-180&&(b+=360),e.rotation=e.rotation+b*l,e.scale_x=e.scale_x+(v.scale_x-e.scale_x)*l,e.scale_y=e.scale_y+(v.scale_y-e.scale_y)*l}}else if(r.type==="FollowPointer"){const v=((g=this._lastPointerPos)==null?void 0:g.x)??e.x,b=((h=this._lastPointerPos)==null?void 0:h.y)??e.y,S=r.useSpring;if(S){const M=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:I,y:E,vx:_,vy:T}=this.computeSpring(e.x,e.y,M.vx,M.vy,v,b,r,t);e.x=I,e.y=E,this.objectVelocities.set(s.id,{vx:_,vy:T})}else e.x=e.x+(v-e.x)*l,e.y=e.y+(b-e.y)*l;let C=!1;if((d=r.limitX)!=null&&d.enabled){const M=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==M&&(C=!0)}if((w=r.limitY)!=null&&w.enabled){const M=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==M&&(C=!0)}C&&S&&this.objectVelocities.set(s.id,{vx:0,vy:0})}else if(r.type==="Distance"){const v=this.getGlobalTransform(r.targetId);if(v){const b=e.x-v.x,S=e.y-v.y,C=Math.sqrt(b*b+S*S),M=r.distance||0;let I=C;switch(r.mode){case"exact":I=M;break;case"minimum":I=Math.max(M,C);break;case"maximum":I=Math.min(M,C);break;case"clamped":I=Math.max(0,Math.min(M,C));break}if(C>0){const E=e.x===v.x&&e.y===v.y?1:I/C;e.x=e.x+(v.x+b*E-e.x)*l,e.y=e.y+(v.y+S*E-e.y)*l}}}else if(r.type==="FollowPath"){const v=(y=this.artboard)==null?void 0:y.objects.find(b=>b.id===r.targetId);if(v){const b=this.getGlobalTransform(v.id);if(b){let S=v.geometry;if(v.type==="Frame"||v.type==="Group"||!S||S.type!=="Path"&&S.type!=="Ellipse"&&S.type!=="Rectangle"){const B=(c=this.artboard)==null?void 0:c.objects.find(j=>j.parentId===v.id&&j.type==="Shape"&&j.geometry&&(j.geometry.type==="Path"||j.geometry.type==="Ellipse"||j.geometry.type==="Rectangle"));B&&(S=B.geometry)}if(!S)return;const C=Math.max(0,Math.min(1,(r.distance||0)/100)),M=b.width||S.width||0,I=b.height||S.height||0,E=this.getPointOnPath(S,M,I,C),_=b.rotation*Math.PI/180,T=Math.cos(_),A=Math.sin(_),R=E.x*b.scale_x*T-E.y*b.scale_y*A,Y=E.x*b.scale_x*A+E.y*b.scale_y*T;let L=b.rotation+(r.offsetRotation||0);if(r.orient){const B=Math.cos(E.angle),j=Math.sin(E.angle),z=B*b.scale_x*T-j*b.scale_y*A,q=B*b.scale_x*A+j*b.scale_y*T;L=Math.atan2(q,z)*180/Math.PI+(r.offsetRotation||0)}const D=L*Math.PI/180,P=Math.cos(D),k=Math.sin(D),O=(r.offsetX||0)*P-(r.offsetY||0)*k,$=(r.offsetX||0)*k+(r.offsetY||0)*P,X=b.x+R+O,F=b.y+Y+$;if(e.x=e.x+(X-e.x)*l,e.y=e.y+(F-e.y)*l,r.orient){let B=(L-e.rotation)%360;B>180&&(B-=360),B<-180&&(B+=360),e.rotation=e.rotation+B*l}}}}else if(r.type==="IK"){const v=this.getGlobalTransform(r.targetId);v&&this.solveIK(s,v,r.boneCount||2,l)}}),s.constraints.some(n=>n.type!=="IK")){const n=this.globalToLocal(s.parentId,e);o.x=n.x,o.y=n.y,o.rotation=n.rotation,o.flip_x=n.scale_x<0,o.scale_x=Math.abs(n.scale_x),o.flip_y=n.scale_y<0,o.scale_y=Math.abs(n.scale_y)}})}getGlobalTransform(t){var p,u;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,rotation:0,scale_x:1,scale_y:1};const o=(p=this.artboard)==null?void 0:p.objects.find(g=>g.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:s.x,y:s.y,rotation:s.rotation,scale_x:(s.scale_x??1)*(s.flip_x?-1:1),scale_y:(s.scale_y??1)*(s.flip_y?-1:1),length:e};const n=this.getGlobalTransform(o.parentId),i=n.rotation*Math.PI/180,a=Math.cos(i),r=Math.sin(i),l=n.x+(s.x*n.scale_x*a-s.y*n.scale_y*r),f=n.y+(s.x*n.scale_x*r+s.y*n.scale_y*a);return{x:l,y:f,rotation:n.rotation+s.rotation,scale_x:n.scale_x*(s.scale_x??1)*(s.flip_x?-1:1),scale_y:n.scale_y*(s.scale_y??1)*(s.flip_y?-1:1),length:e}}globalToLocal(t,s){if(!t)return s;const o=this.getGlobalTransform(t),e=o.scale_x===0?0:1/o.scale_x,n=o.scale_y===0?0:1/o.scale_y,i=-o.rotation*Math.PI/180,a=Math.cos(i),r=Math.sin(i),l=s.x-o.x,f=s.y-o.y,p=(l*a-f*r)*e,u=(l*r+f*a)*n;return{x:p,y:u,rotation:s.rotation-o.rotation,scale_x:s.scale_x/(o.scale_x||1),scale_y:s.scale_y/(o.scale_y||1)}}solveIK(t,s,o,e){var l;const n=[];let i=t.id;for(let f=0;f<o&&i;f++){const p=(l=this.artboard)==null?void 0:l.objects.find(u=>u.id===i);if(!p)break;n.push({id:i,local:this.objectStates.get(i),global:this.getGlobalTransform(i)}),i=p.parentId}if(n.length<2)return;const a=n.reverse(),r=5;for(let f=0;f<r;f++){const p=this.getGlobalTransform(t.id);for(let u=a.length-2;u>=0;u--){const g=a[u],h=this.getGlobalTransform(g.id),d=p.x-h.x,w=p.y-h.y,y=s.x-h.x,c=s.y-h.y,v=Math.sqrt(d*d+w*w),b=Math.sqrt(y*y+c*c);if(v>.001&&b>.001){const S=Math.atan2(w,d);let M=(Math.atan2(c,y)-S)*180/Math.PI;M*=e;const I=this.objectStates.get(g.id);I&&(I.rotation+=M)}}}}computeSpring(t,s,o,e,n,i,a,r){const l=a.stiffness??100,f=a.damping??10,p=a.mass??1,u=-l*(t-n),g=-l*(s-i),h=-f*o,d=-f*e,w=(u+h)/p,y=(g+d)/p,c=o+w*r,v=e+y*r,b=t+c*r,S=s+v*r;return{x:b,y:S,vx:c,vy:v}}handlePointerInput(t,s,o,e,n){if(!this.artboard)return;const i=this.calculateTransform(e,n,this.artboard.width,this.artboard.height,this.layout.fit,this.layout.alignment),a=(s-i.tx)/i.scaleX,r=(o-i.ty)/i.scaleY;this._prevPointerPos=this._lastPointerPos,this._lastPointerPos={x:a,y:r},this._prevPointerPos&&(this._mouseDelta.dx+=a-this._prevPointerPos.x,this._mouseDelta.dy+=r-this._prevPointerPos.y),this.updateInput("mouseX",a),this.updateInput("mouseY",r),this.handlePointerEvent(t,a,r)}handleScroll(t,s){const o=this.scrollOffset.x,e=this.scrollOffset.y;this.scrollOffset={x:t,y:s},this._totalScroll.x+=t-o,this._totalScroll.y+=s-e,this.updateInput("scrollX",this._totalScroll.x),this.updateInput("scrollY",this._totalScroll.y)}isListViewObject(t){var n;if(!t)return!1;const s=(t.type||"").toLowerCase(),o=(t.variant||"").toLowerCase(),e=(((n=t.geometry)==null?void 0:n.type)||"").toLowerCase();return s==="listview"||o==="listview"||e==="listview"}isLineGraphObject(t){var i;if(!t)return!1;const s=(t.type||"").toLowerCase(),o=(t.variant||"").toLowerCase(),e=(((i=t.geometry)==null?void 0:i.type)||"").toLowerCase(),n=(t.name||"").toLowerCase();return s==="linegraph"||e==="linegraph"||o==="linegraph"||n.includes("linegraph")}isBarChartObject(t){var i;if(!t)return!1;const s=(t.type||"").toLowerCase(),o=(t.variant||"").toLowerCase(),e=(((i=t.geometry)==null?void 0:i.type)||"").toLowerCase(),n=(t.name||"").toLowerCase();return s==="barchart"||e==="barchart"||o==="barchart"||n.includes("barchart")}isPieChartObject(t){var i;if(!t)return!1;const s=(t.type||"").toLowerCase(),o=(t.variant||"").toLowerCase(),e=(((i=t.geometry)==null?void 0:i.type)||"").toLowerCase(),n=(t.name||"").toLowerCase();return s==="piechart"||e==="piechart"||o==="piechart"||n.includes("piechart")}isGraphObject(t){return this.isLineGraphObject(t)||this.isBarChartObject(t)||this.isPieChartObject(t)}clearAllGraphHover(){this.graphHoverStates.size>0&&this.graphHoverStates.clear()}getLocalCoords(t,s,o){const e=this.getWorldTransform(t),n=s-e.x,i=o-e.y,a=-(e.rotation||0)*(Math.PI/180),r=Math.cos(a),l=Math.sin(a),f=e.scaleX||1,p=e.scaleY||1;return{x:(n*r-i*l)/(f!==0?f:1),y:(n*l+i*r)/(p!==0?p:1)}}updateGraphHoverFromPointer(t,s,o){var r,l;if(!t||!this.isGraphObject(t)){this.clearAllGraphHover();return}for(const f of Array.from(this.graphHoverStates.keys()))f!==t.id&&this.graphHoverStates.delete(f);const e=this.getLocalCoords(t.id,s,o),n=this.objectStates.get(t.id),i=(n==null?void 0:n.width)??((r=t.geometry)==null?void 0:r.width)??t.width??300,a=(n==null?void 0:n.height)??((l=t.geometry)==null?void 0:l.height)??t.height??180;if(e.x<-i/2||e.x>i/2||e.y<-a/2||e.y>a/2){this.graphHoverStates.delete(t.id);return}if(this.isLineGraphObject(t)){const f=n!=null&&n.geometry?this.deepMerge(t.geometry,n.geometry):t.geometry||{};let p=f.datasets||[];(!p||p.length===0)&&(f.data||f.graphData)&&(p=[{data:f.data||f.graphData}]);let u=0;if(p.forEach(g=>{let h=g.data;if(g.isVarEnabled&&g.inputId){let d=this.inputs.get(g.inputId);if(d===void 0){const w=this.inputNameMap.get(g.inputId);w&&w.length>0&&(d=this.inputs.get(w[0]))}d&&Array.isArray(d)&&(h=d)}h&&h.length>0&&(u=Math.max(u,h.length))}),u>=2){const g=i/(u-1),h=e.x+i/2,d=Math.max(0,Math.min(u-1,Math.round(h/g)));this.graphHoverStates.set(t.id,{hoveredIndex:d,hoverPointer:{x:e.x,y:e.y}})}}else if(this.isBarChartObject(t)){const f=this.barChartRenderedBars.get(t.id)||[];let p=null;for(let u=f.length-1;u>=0;u--){const g=f[u];if(e.x>=g.x&&e.x<=g.x+g.w&&e.y>=g.y&&e.y<=g.y+g.h){p=g;break}}p?this.graphHoverStates.set(t.id,{hoveredCatIdx:p.catIdx,hoveredDsIdx:p.dsIdx,bar:p,hoverPointer:{x:e.x,y:e.y}}):this.graphHoverStates.delete(t.id)}else if(this.isPieChartObject(t)){const f=this.pieChartRenderedSlices.get(t.id)||[];let p=null;for(const u of f){const g=e.x-u.cx,h=e.y-u.cy,d=Math.hypot(g,h);if(d>=u.innerR&&d<=u.outerR){let w=Math.atan2(h,g);const y=C=>(C%(Math.PI*2)+Math.PI*2)%(Math.PI*2),c=y(w),v=y(u.startA),b=y(u.endA);if(v<=b?c>=v&&c<=b:c>=v||c<=b){p=u.index;break}}}p!==null?this.graphHoverStates.set(t.id,{hoveredSliceIndex:p,hoverPointer:{x:e.x,y:e.y}}):this.graphHoverStates.delete(t.id)}}getGraphHoverState(t){return this.graphHoverStates.get(t)}getResolvedListViewItems(t,s){const o=this.objectStates.get(t==null?void 0:t.id),e=s||(o==null?void 0:o.options)||(t==null?void 0:t.options)||{};let n=Array.isArray(e.items)?e.items:typeof e.items=="string"?e.items.split(",").map(i=>i.trim()):[];if(e.isDataVarEnabled&&e.dataInputId){let i=this.inputs.get(e.dataInputId);if(i===void 0){const a=this.inputNameMap.get(e.dataInputId);a&&a.length>0&&(i=this.inputs.get(a[0]))}if(i&&Array.isArray(i))n=i.map(a=>typeof a=="string"?a:String(a));else if(typeof i=="string")try{n=JSON.parse(i).map(a=>String(a))}catch{}}return n}getResolvedDropdownOptions(t,s){const o=this.objectStates.get(t==null?void 0:t.id),e=s||(o==null?void 0:o.options)||(t==null?void 0:t.options)||{};let n=Array.isArray(e.optionsList)?e.optionsList:typeof e.optionsList=="string"?e.optionsList.split(",").map(i=>i.trim()):[];if(e.isDataVarEnabled&&e.dataInputId){let i=this.inputs.get(e.dataInputId);if(i===void 0){const a=this.inputNameMap.get(e.dataInputId);a&&a.length>0&&(i=this.inputs.get(a[0]))}if(i&&Array.isArray(i))n=i.map(a=>typeof a=="string"?a:String(a));else if(typeof i=="string")try{const a=JSON.parse(i);Array.isArray(a)?n=a.map(String):n=i.split(",").map(r=>r.trim())}catch{n=i.split(",").map(a=>a.trim())}}return n}handleWheel(t,s,o,e,n,i){var a,r,l,f;if(o!==void 0&&e!==void 0&&n&&i&&this.artboard){const p=this.calculateTransform(n,i,this.artboard.width,this.artboard.height,this.layout.fit,this.layout.alignment),u=(o-p.tx)/p.scaleX,g=(e-p.ty)/p.scaleY;this._lastPointerPos={x:u,y:g}}if(this._lastPointerPos&&this.artboard){let p=!1;for(let u=this.artboard.objects.length-1;u>=0;u--){const g=this.artboard.objects[u];if(this.isListViewObject(g)){const h=this.objectStates.get(g.id),d=(h==null?void 0:h.options)||g.options||{},w=(h==null?void 0:h.width)??(((a=g.geometry)==null?void 0:a.width)||200),y=(h==null?void 0:h.height)??(((r=g.geometry)==null?void 0:r.height)||300),c=this.getWorldTransform(g.id),v=this._lastPointerPos.x-c.x,b=this._lastPointerPos.y-c.y,S=-c.rotation*(Math.PI/180),C=Math.cos(S),M=Math.sin(S),I=v*C-b*M,E=v*M+b*C,_=c.scaleX||1,T=c.scaleY||1,A=w*Math.abs(_),R=y*Math.abs(T);if(Math.abs(I)<=A/2&&Math.abs(E)<=R/2){const Y=d.orientation||"vertical";let L=d.scrollOffset||0;if(Y==="vertical"?L-=s:L-=Math.abs(t)>Math.abs(s)?t:s,(d.listLayout||"linear")==="circular")d.scrollOffset=L,h&&h.options&&(h.options.scrollOffset=L),g.options&&(g.options.scrollOffset=L);else{const P=this.getResolvedListViewItems(g,d),k=d.itemGap??10,O=d.itemHeight??50,$=d.itemWidth??200,X=typeof d.padding=="number"?d.padding:Y==="vertical"?((l=d.padding)==null?void 0:l[0])||0:((f=d.padding)==null?void 0:f[3])||0,B=(P.length||0)*(Y==="vertical"?O:$)+Math.max(0,(P.length||0)-1)*k+X*2,z=Math.max(0,B-(Y==="vertical"?y:w));L>0&&(L=0),L<-z&&(L=-z),d.scrollOffset=L,h&&h.options&&(h.options.scrollOffset=L),g.options&&(g.options.scrollOffset=L)}p=!0;break}}}if(p)return}this._totalScroll.x+=t,this._totalScroll.y+=s,this.scrollOffset={x:this._totalScroll.x,y:this._totalScroll.y},this.updateInput("scrollX",this._totalScroll.x),this.updateInput("scrollY",this._totalScroll.y)}handlePointerEvent(t,s,o){var r,l,f,p,u,g,h,d,w,y;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 n=(c,v)=>{var E;let b=v;v==="click"?b="onClick":v==="down"?b="onPointerDown":v==="up"?b="onPointerUp":v==="blur"&&(b="onPointerLeave");const S=new Set([b]);v==="move"&&(S.add("onPointerEnter").add("hover").add("onPointerLeave").add("blur"),S.add("Drag").add("drag").add("ondrag")),b==="onClick"&&S.add("click"),b==="onPointerDown"&&S.add("pointerDown"),b==="onPointerUp"&&S.add("pointerUp");const C=["button","toggle","toggle_button","dropdown","listview","inputbox","slider","checkbox","radiogroup","joystick","barchart","piechart","linegraph"];if(this.isListViewObject(c)||this.isGraphObject(c)||c.type==="Component"&&c.variant&&C.includes(String(c.variant).toLowerCase())||c.type==="Joystick"||C.includes((E=c.type)==null?void 0:E.toLowerCase()))return!0;const M=c.interactions||[];return!!(M.some(_=>S.has(_.event)||S.has(_.trigger))||M.some(_=>Array.isArray(_.triggers)&&_.triggers.some(T=>S.has(String(T))))||(c.triggers||[]).some(_=>S.has(_.eventType)))};let i=null;for(let c=this.artboard.objects.length-1;c>=0;c--){const v=this.artboard.objects[c],b=this.objectStates.get(v.id);if(b&&b.visible!==!1&&b.opacity>0&&this.hitTest(v,s,o)&&(i||(i=v),n(v,t))){e=v;break}}!e&&i&&(e=i),this.pointerHistory.push({x:s,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 c=this.artboard.objects.find(v=>v.id===this.draggingSliderId);c&&this.updateSliderValueFromPointer(c,s,o);return}if(this.draggingJoystickId){const c=this.artboard.objects.find(v=>v.id===this.draggingJoystickId);c&&this.updateJoystickValueFromPointer(c,s,o);return}if(this.draggingListViewId){const c=this.artboard.objects.find(v=>v.id===this.draggingListViewId);c&&this.updateListViewScrollFromPointer(c);return}if(e&&this.isListViewObject(e)&&this.updateListViewHoverFromPointer(e,s,o),this.updateGraphHoverFromPointer(e,s,o),this.isMouseDown&&this.dragStartPointer&&this.draggingBehaviors.size>0){const c=s-this.dragStartPointer.x,v=o-this.dragStartPointer.y;this.draggingBehaviors.forEach(b=>{const S=this.dragStartPositions.get(b);if(!S)return;const C=this.artboard.objects.find(I=>I.id===b);if(!C||C.parentId)return;const M=this.objectStates.get(b);M&&(M.x=S.x+c,M.y=S.y+v)})}if(this.isMouseDown){const c=this.activeObjectId&&this.artboard.objects.some(b=>b.id===this.activeObjectId)?this.activeObjectId:a,v=c?this.artboard.objects.find(b=>b.id===c):null;v&&n(v,"move")&&this.fireEventForObject(v.id,"Drag")}!this.isMouseDown&&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.draggingListViewIsScrollbar=!1,this.draggingBehaviors.clear(),this.dragStartPointer=null,this.dragStartPositions.clear(),this.pointerDownTimes.delete(a),this.activeObjectId=null,t==="blur"&&this.clearAllGraphHover()),t==="down"&&(this.pointerDownTimes.set(a,this.currentTime),this.activeObjectId=a,e&&((r=e.behaviors)!=null&&r.some(c=>c.type===st.Draggable)||this.hasDragInteraction(e)))){this.draggingBehaviors.add(a);const c=this.objectStates.get(a);c&&(this.dragStartPointer={x:s,y:o},this.dragStartPositions.set(a,{x:c.x??0,y:c.y??0}))}if(t==="move"?(a&&!this.activeHoverIds.has(a)&&this.activeHoverIds.add(a),this.activeHoverIds.forEach(c=>{c!==a&&this.activeHoverIds.delete(c)})):t==="blur"&&this.activeHoverIds.clear(),this.activeDropdownId&&t==="down"){const c=this.artboard.objects.find(v=>v.id===this.activeDropdownId);if(c&&(c.type==="Dropdown"||c.variant==="dropdown")){const v=this.objectStates.get(c.id),b=(v==null?void 0:v.options)||c.options||{},S=c.geometry||{},C=S.width??c.width??200,M=S.height??c.height??40,I=this.getResolvedDropdownOptions(c,b),E=b.itemHeight||32,_=b.listPadding??4,T=I.length*E+_*2,A=this.getWorldTransform(c.id),R=C*Math.abs(A.scaleX),Y=M*Math.abs(A.scaleY),L=A.y+Y/2+4,D=Math.abs(s-A.x)<=R/2,P=o>=L&&o<=L+T*Math.abs(A.scaleY);if(D&&P){const k=Math.abs(A.scaleY),O=o-(L+_*k),$=Math.floor(O/(E*k));if($>=0&&$<I.length){const X=I[$];b.selectedOption=X,b.isOpen=!1,this.activeDropdownId=null,c.inputId&&this.setInternalInput(c.inputId,X),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"dropdown",property:"selectedOption",value:X})}return}else a!==this.activeDropdownId&&(b.isOpen=!1,this.activeDropdownId=null)}}if(e){let c=e,v=e;for(;v&&v.parentId;){const C=this.artboard.objects.find(M=>M.id===v.parentId);if(C&&C.type==="Component"){c=C;break}v=C}let b=t;if(t==="click"?b="onClick":t==="down"?b="onPointerDown":t==="up"?b="onPointerUp":t==="blur"&&(b="onPointerLeave"),this.fireEventForObject(e.id,b),c!==e&&this.fireEventForObject(c.id,b),c.type==="Component"&&c.variant==="toggle_button"&&t==="down"){const C=this.objectStates.get(c.id),M=(C==null?void 0:C.options)||c.options||{};M.checked=!M.checked,c.inputId&&this.setInternalInput(c.inputId,M.checked),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"toggle_button",property:"checked",value:M.checked}),this.fireEventForObject(c.id,"Toggle"),this.fireEventForObject(c.id,M.checked?"Toggle True":"Toggle False")}if(c.type==="Component"&&c.variant==="toggle"&&t==="down"){const C=this.objectStates.get(c.id),M=(C==null?void 0:C.options)||c.options||{};M.checked=!M.checked,c.inputId&&this.setInternalInput(c.inputId,M.checked),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"toggle",property:"checked",value:M.checked}),this.onToggle&&this.onToggle(c.name,M.checked),this.fireEventForObject(c.id,"Toggle"),this.fireEventForObject(c.id,M.checked?"Toggle True":"Toggle False")}if(c.type==="Component"&&c.variant==="dropdown"&&t==="down"){const C=this.objectStates.get(c.id),M=(C==null?void 0:C.options)||c.options||{},I=!M.isOpen;if(I&&this.activeDropdownId&&this.activeDropdownId!==c.id){const E=this.artboard.objects.find(_=>_.id===this.activeDropdownId);E&&E.options&&(E.options.isOpen=!1)}M.isOpen=I,this.activeDropdownId=I?c.id:null}if((c.type==="Button"||c.type==="Component"&&(c.variant==="button"||(c.name||"").toLowerCase().includes("button")||(c.name||"").toLowerCase().includes("cta")))&&t==="down"&&(this.onButtonClick&&this.onButtonClick(c.name,c.id),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"button",property:"click",value:!0})),this.isListViewObject(c)&&t==="down"){this.draggingListViewId=c.id;const C=this.objectStates.get(c.id),M=(C==null?void 0:C.options)||c.options||{},I=(C==null?void 0:C.width)??(((l=c.geometry)==null?void 0:l.width)||200),E=(C==null?void 0:C.height)??(((f=c.geometry)==null?void 0:f.height)||300),_=M.orientation||"vertical",T=M.scrollbarWidth||4,A=M.showScrollbar!==!1;let R=!1;if(A&&M.listLayout!=="circular"){const L=this.getWorldTransform(c.id),D=-L.rotation*(Math.PI/180),P=Math.cos(D),k=Math.sin(D),O=s-L.x,$=o-L.y,X=O*P-$*k,F=O*k+$*P,B=L.scaleX||1,j=L.scaleY||1,z=X/B,q=F/j,U=12;_==="vertical"?z>=I/2-T-U&&z<=I/2+U&&(R=!0):q>=E/2-T-U&&q<=E/2+U&&(R=!0)}this.draggingListViewIsScrollbar=R;const Y=this.getListViewItemIndexAtPointer(c,s,o);if(Y!==null){const L=c.options||{};L.activeItemIndex=Y;const D=this.objectStates.get(c.id);D&&D.options&&(D.options.activeItemIndex=Y);const k=this.getResolvedListViewItems(c,L)[Y],O=typeof k=="string"?k:(k==null?void 0:k.label)||(k==null?void 0:k.value)||Y;D&&D.options&&(D.options.selectedValue=O),c.inputId&&this.setInternalInput(c.inputId,O),this.onComponentChange&&(this.onComponentChange({objectId:c.id,componentName:c.name,variant:"listview",property:"activeItemIndex",value:Y}),this.onComponentChange({objectId:c.id,componentName:c.name,variant:"listview",property:"selected",value:O}))}}if(c.type==="Component"&&c.variant==="slider"&&t==="down"&&(this.draggingSliderId=c.id,this.updateSliderValueFromPointer(c,s,o)),c.type==="Joystick"||c.type==="Component"&&c.variant==="joystick"){if(t==="down")this.draggingJoystickId=c.id,this.updateJoystickValueFromPointer(c,s,o);else if(t==="up"||t==="blur"){const C=this.objectStates.get(c.id);C&&c.isSpringReturn!==!1&&(C.handleX=0,C.handleY=0),c.isSpringReturn!==!1&&(c.handleX=0,c.handleY=0)}}if((c.type==="Checkbox"||c.type==="Component"&&c.variant==="checkbox")&&t==="down"){const C=this.objectStates.get(c.id),M=(C==null?void 0:C.options)||c.options||{};if(M.disabled)return;M.checked=!M.checked,M.indeterminate&&(M.indeterminate=!1),c.inputId&&this.setInternalInput(c.inputId,M.checked),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"checkbox",property:"checked",value:M.checked}),this.fireEventForObject(c.id,"Click"),this.fireEventForObject(c.id,M.checked?"Checked":"Unchecked")}if(c.type==="Component"&&c.variant==="radiogroup"&&t==="down"){const C=this.objectStates.get(c.id),M=(C==null?void 0:C.options)||c.options||{},I=M.optionsList||[],E=this.getRadioGroupItemIndexAtPointer(c,s,o);if(E!==null&&E>=0&&E<I.length){const _=I[E];M.selectedValue=_,c.inputId&&this.setInternalInput(c.inputId,_),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"radiogroup",property:"selectedValue",value:_}),this.fireEventForObject(c.id,"Click"),this.fireEventForObject(c.id,`Selected: ${_}`)}}if(c.type==="LineGraph"&&(t==="down"||t==="click")){const C=c.geometry,M=(C==null?void 0:C.datasets)||[],I=this.objectStates.get(c.id),E=(I==null?void 0:I.width)||(C==null?void 0:C.width)||200,_=(I==null?void 0:I.height)||(C==null?void 0:C.height)||150,T=this.getWorldTransform(c.id),A=30,R=20,Y=E-A,L=_-R;let D=1;M.forEach(O=>{const $=Math.max(...O.data||[0]);$>D&&(D=$)});let P=1/0,k=null;M.forEach((O,$)=>{const X=O.data||[],F=Y/Math.max(X.length-1,1);X.forEach((B,j)=>{const z=T.x-E/2+A+j*F,q=T.y+_/2-R-B/D*L,U=Math.sqrt((s-z)**2+(o-q)**2);U<P&&(P=U,k={dIdx:$,pIdx:j,val:B,label:O.label||`Dataset ${$+1}`})})}),k&&P<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:c.id,componentName:c.name,datasetIndex:k.dIdx,pointIndex:k.pIdx,value:k.val,label:k.label}),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"linegraph",property:"click",value:(k==null?void 0:k.val)??null})}if((c==null?void 0:c.type)==="InputBox"||(c==null?void 0:c.type)==="Component"&&(c.variant==="inputbox"||c.name==="InputBox")){if(t==="down"||t==="click"){const C=this.focusedId;if(this.focusedId=c.id,this.log(`[Engine] Focus set to: ${c.id}`),C!==this.focusedId){if(C){const j=(p=this.artboard)==null?void 0:p.objects.find(z=>z.id===C);j&&this.onInputBlur&&this.onInputBlur(j.name)}this.onInputFocus&&this.onInputFocus(c.name)}const M=this.objectStates.get(c.id),I=(M==null?void 0:M.options)||c.options||{},E=c.geometry||{},_=(M==null?void 0:M.width)||(E==null?void 0:E.width)||250,T=(M==null?void 0:M.height)||(E==null?void 0:E.height)||45,A=this.getWorldTransform(c.id),R=-A.rotation*(Math.PI/180),Y=Math.cos(R),L=Math.sin(R),D=s-A.x,P=o-A.y,k=(D*Y-P*L)/(A.scaleX||1),O=(D*L+P*Y)/(A.scaleY||1);if(I.inputType==="number"&&((u=I.number)==null?void 0:u.showSteppers)!==!1){const z=_/2-4,q=z-24;if(k>=q&&k<=z&&Math.abs(O)<=T/2){const U=Number(((g=I.number)==null?void 0:g.step)??1),J=((h=I.number)==null?void 0:h.min)!==void 0?Number(I.number.min):-1/0,W=((d=I.number)==null?void 0:d.max)!==void 0?Number(I.number.max):1/0;let N=parseFloat(I.text??I.value??"0");isNaN(N)&&(N=0),O<0?N=Math.min(W,N+U):N=Math.max(J,N-U);const H=String(N);I.text=H,I.value=H,c.options&&(c.options.text=H,c.options.value=H),M&&M.options&&(M.options.text=H,M.options.value=H),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"inputbox",property:"value",value:H}),this.onInputChange&&this.onInputChange(c.name,H),this.onInputUpdate&&this.onInputUpdate(c.id,H);return}}const $=I.rightIcon||{},X=I.inputType==="password",F=$.mode==="clear"||I.inputType==="search"&&(I.text||I.value),B=$.mode==="password-toggle"||X&&$.visible!==!1;if($.visible||B||F){const j=$.offset??16,z=$.size??16,q=_/2-j;if(Math.abs(k-q)<=z&&Math.abs(O)<=T/2){if(B){I.passwordVisible=!I.passwordVisible,M&&M.options&&(M.options.passwordVisible=I.passwordVisible),c.options&&(c.options.passwordVisible=I.passwordVisible);return}else if(F){I.text="",I.value="",M&&M.options&&(M.options.text="",M.options.value=""),c.options&&(c.options.text="",c.options.value=""),this.onInputChange&&this.onInputChange(c.name,""),this.onInputUpdate&&this.onInputUpdate(c.id,"");return}}}}}else if((t==="click"||t==="down")&&this.focusedId){const C=this.focusedId;this.focusedId=null;const M=(w=this.artboard)==null?void 0:w.objects.find(I=>I.id===C);M&&this.onInputBlur&&this.onInputBlur(M.name)}}else if(t==="click"||t==="down"){const c=this.focusedId;if(this.focusedId=null,c){const v=(y=this.artboard)==null?void 0:y.objects.find(b=>b.id===c);v&&this.onInputBlur&&this.onInputBlur(v.name)}}}handleKeyDown(t){var l,f,p,u;if(!this.artboard||(this.activeKeys.add(t.key.toLowerCase()),this.activeKeys.add(t.code),!this.focusedId))return;const s=this.artboard.objects.find(g=>g.id===this.focusedId),o=(s==null?void 0:s.type)==="InputBox"||(s==null?void 0:s.type)==="Component"&&(s.variant==="inputbox"||s.name==="InputBox");if(!s||!o)return;const e=this.objectStates.get(s.id),n=(e==null?void 0:e.options)||s.options||{};let i=String(n.text??n.value??"");const a=n.inputType==="textarea"||n.multiline===!0;if(t.key==="Backspace")i=i.slice(0,-1),t.preventDefault();else if(t.key==="Escape"){this.focusedId=null,this.onInputBlur&&this.onInputBlur(s.name);return}else if(t.key==="Enter")if(a)i+=`
7
- `,t.preventDefault();else{this.focusedId=null,this.onInputBlur&&this.onInputBlur(s.name);return}else if(t.key==="ArrowUp"&&n.inputType==="number"){const g=Number(((l=n.number)==null?void 0:l.step)??1),h=((f=n.number)==null?void 0:f.max)!==void 0?Number(n.number.max):1/0;let d=parseFloat(i)||0;d=Math.min(h,d+g),i=String(d),t.preventDefault()}else if(t.key==="ArrowDown"&&n.inputType==="number"){const g=Number(((p=n.number)==null?void 0:p.step)??1),h=((u=n.number)==null?void 0:u.min)!==void 0?Number(n.number.min):-1/0;let d=parseFloat(i)||0;d=Math.max(h,d-g),i=String(d),t.preventDefault()}else if(t.key.length===1&&!t.ctrlKey&&!t.metaKey&&!t.altKey){if(n.maxLength>0&&i.length>=n.maxLength||n.inputType==="number"&&(!/[\d.\-]/.test(t.key)||t.key==="-"&&i.includes("-")||t.key==="."&&i.includes(".")))return;i+=t.key,t.preventDefault()}else return;n.text=i,n.value=i,s.options&&(s.options.text=i,s.options.value=i),e&&e.options&&(e.options.text=i,e.options.value=i);const r=s.geometry;r!=null&&r.textInputId&&this.updateInput(r.textInputId,i),this.onComponentChange&&(this.onComponentChange({objectId:s.id,componentName:s.name,variant:"inputbox",property:"text",value:i}),this.onComponentChange({objectId:s.id,componentName:s.name,variant:"inputbox",property:"value",value:i})),this.onInputChange&&this.onInputChange(s.name,i),this.onInputUpdate&&this.onInputUpdate(this.focusedId,i)}handleKeyUp(t){this.artboard&&(this.activeKeys.delete(t.key.toLowerCase()),this.activeKeys.delete(t.code))}hasDragInteraction(t){return t?(t.interactions||[]).some(o=>{const e=o.triggers||[o.event||o.trigger];return Array.isArray(e)&&e.some(n=>String(n).toLowerCase()==="drag")}):!1}fireEventForObject(t,s){var f,p,u,g,h;const o=(f=this.artboard)==null?void 0:f.objects.find(d=>d.id===t);if(!o)return;const e=new Set([s,s.toLowerCase()]),n=s.toLowerCase();n==="onclick"||n==="click"||n==="onpointerdown"||n==="pointerdown"?this.fireAnalyticsEvent(t,"click"):(n==="onpointerenter"||n==="hover"||n==="move")&&this.fireAnalyticsEvent(t,"hover"),n==="onclick"||n==="click"?(e.add("click"),e.add("onclick")):n==="onpointerdown"||n==="pointerdown"?(e.add("pointerdown"),e.add("onpointerdown")):n==="onpointerup"||n==="pointerup"?(e.add("pointerup"),e.add("onpointerup")):n==="onpointerenter"||n==="hover"||n==="move"?(e.add("hover"),e.add("onpointerenter")):n==="onpointerleave"||n==="blur"?(e.add("onpointerleave"),e.add("blur")):n==="drag"||n==="ondrag"?(e.add("drag"),e.add("ondrag")):n==="toggle"||n==="ontoggle"?(e.add("toggle"),e.add("ontoggle")):n==="toggle true"||n==="toggle_true"||n==="toggletrue"?(e.add("toggle true"),e.add("toggle_true"),e.add("toggletrue")):(n==="toggle false"||n==="toggle_false"||n==="togglefalse")&&(e.add("toggle false"),e.add("toggle_false"),e.add("togglefalse"));const a=(o.interactions||[]).find(d=>{const w=d.triggers||[d.event||d.trigger||"click"];return((d.triggerLogic||"OR")==="AND"?w.every(v=>e.has(v.toLowerCase())):w.some(v=>e.has(v.toLowerCase())))?d.conditions&&d.conditions.length>0?this.checkConditions(d.conditions):!0:!1});if(a){if(this.log(`[Engine] Interaction matched: ${s} -> Action: ${a.action}`),a.action==="setInput"||a.action==="Set Input"){let d=a.value||a.inputValue;d==="toggle"&&(d=!this.inputs.get(a.targetInputId)),this.updateInput(a.targetInputId,d)}else if(a.action==="Toggle Boolean"){const d=a.targetInputId;if(d&&this.inputs.has(d)){const c=this.inputs.get(d);this.updateInput(d,!c)}const w=this.objectStates.get(o.id),y=(w==null?void 0:w.options)||o.options;y&&typeof y.checked=="boolean"&&(y.checked=!y.checked,y.indeterminate&&(y.indeterminate=!1),this.onComponentChange&&this.onComponentChange({objectId:o.id,componentName:o.name,variant:"checkbox",property:"checked",value:y.checked}))}else if(a.action==="fireTrigger")this.updateInput(a.targetInputId,!0);else if(a.action==="setProperty"){const d=a.targetObjectId||o.id,w=a.targetProperty;w&&this.updateObjectProperty(d,w,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 d=a.targetAnimationId,w=!a.playMode||a.playMode==="all"?void 0:a.subAnimationIds;d==="__all__"?(u=(p=this.artboard)==null?void 0:p.animations)==null||u.forEach(y=>{this.triggerGlobalAnimation(y.id,w)}):d&&this.triggerGlobalAnimation(d,w)}else if(a.action==="setState"||a.action==="Set State"){const d=a.targetObjectId||o.id,y={...this.objectStates.get(d)||{},...a.value||{}};this.objectStates.set(d,y),this.log(`[Engine] State updated for ${d}:`,y)}else if(a.action==="Stop Animation"||a.action==="Pause Animation"){const d=a.targetAnimationId;d==="__all__"?this.layerStates.forEach((w,y)=>{y.startsWith("global_")&&this.layerStates.delete(y)}):d&&this.layerStates.forEach((w,y)=>{y.startsWith(`global_${d}_`)&&this.layerStates.delete(y)})}else if(a.action==="Switch to State"&&this.activeStateMachine){const d=a.targetState,w=this.activeStateMachine.layers.find(y=>y.states.some(c=>c.id===d||c.name===d));w&&(this.log(`[Engine] Switching Layer ${w.name} to State ${d}`),this.enterStates(w.name,[d]))}this.onTrigger&&this.onTrigger(s,a.action)}const l=(o.triggers||[]).find(d=>{const w=d.eventType.toLowerCase();let y=!1;return(e.has(w)||w==="click"&&e.has("onclick")||w==="hover"&&(e.has("onpointerenter")||e.has("hover"))||w==="pointerdown"&&e.has("onpointerdown")||w==="pointerup"&&e.has("onpointerup"))&&(y=!0),y&&d.conditions&&d.conditions.length>0?this.checkConditions(d.conditions):y});if(l&&l.entryAnimationId){this.log(`[Engine] Trigger matched: ${s} (as ${l.eventType}) -> Animation ${l.entryAnimationId}`);const d=(h=(g=this.artboard)==null?void 0:g.animations)==null?void 0:h.find(w=>w.id===l.entryAnimationId);d&&(this.activeTriggers.set(o.id,{triggerId:l.id,animation:d,time:0,phase:"entry",elapsedHold:0,filterObjectId:l.targetObjectId}),this.onTrigger&&this.onTrigger(l.name,d.name))}}fireAnalyticsEvent(t,s){var r,l;const o=(r=this.artboard)==null?void 0:r.objects.find(f=>f.id===t);if(!o)return;const e=(l=o.style)==null?void 0:l.analytics;if(!e||!e.isEnabled||e.triggerType!==s)return;const n=e.eventName||`${o.name.toLowerCase().replace(/\s+/g,"_")}_interacted`,i={};e.parameters&&Array.isArray(e.parameters)&&e.parameters.forEach(f=>{if(f.type==="literal")i[f.key]=f.value;else if(f.type==="variable"){const p=this.inputs.get(f.value);i[f.key]=p!==void 0?p:""}}),this.log(`[ExodeUI Analytics] Dispatching event "${n}" via ${s} trigger:`,i);const a=e.platforms||{ga4:!0,meta:!0,mixpanel:!1};if(a.ga4){const f=window;typeof f.gtag=="function"?(f.gtag("event",n,i),this.log(`[ExodeUI Analytics] GA4: Event "${n}" sent successfully.`)):this.warn(`[ExodeUI Analytics] GA4: window.gtag is not a function. Event "${n}" skipped.`)}if(a.meta){const f=window;typeof f.fbq=="function"?(f.fbq("track",n,i),this.log(`[ExodeUI Analytics] Meta Pixel: Event "${n}" sent successfully.`)):this.warn(`[ExodeUI Analytics] Meta Pixel: window.fbq is not a function. Event "${n}" skipped.`)}if(a.mixpanel){const f=window;f.mixpanel&&typeof f.mixpanel.track=="function"?(f.mixpanel.track(n,i),this.log(`[ExodeUI Analytics] Mixpanel: Event "${n}" sent successfully.`)):this.warn(`[ExodeUI Analytics] Mixpanel: window.mixpanel.track is not a function. Event "${n}" skipped.`)}}getAnimationDuration(t){var o;if(!t)return 0;let s=t.duration||0;return s<=0&&((o=t.tracks)==null||o.forEach(e=>{var n;(n=e.keyframes)==null||n.forEach(i=>{i.time>s&&(s=i.time)})})),s>0?s:1}initGlobalAnimationTriggers(){if(!this.artboard)return;const t=this.artboard.animationFlow||[];let s=!1;t.forEach(o=>{if((o.trigger==="on_load"||o.trigger==="after_delay")&&o.targetAnimationId){s=!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)}}),!s&&this.artboard.startupAnimationId&&this.triggerGlobalAnimation(this.artboard.startupAnimationId,this.artboard.startupSubAnimationIds)}triggerGlobalAnimation(t,s,o=!1,e){var r;if(!this.artboard)return;const n=this.artboard.animations.find(l=>l.id===t);if(!n)return;let i=this.getAnimationDuration(n);const a=`global_${t}_${Math.random().toString(36).substr(2,5)}`;this.layerStates.set(a,{currentStateIds:[t],animations:[{animation:n,state:{loop:o},filterObjectIds:s}],time:0,duration:i,ruleId:e}),console.log(`[Engine] Triggered global animation: ${n.name} (AnimID: ${t}, RuleID: ${e}, Loop: ${o}, StoredDuration: ${i}, anim.duration: ${n.duration}, Tracks: ${((r=n.tracks)==null?void 0:r.length)||0})`),this.debugLog(`[Engine] Triggered global animation: ${n.name} (Loop: ${o}, Sub-Anims: ${(s==null?void 0:s.length)||"All"})`)}handleAnimationFinished(t,s){if(!this.artboard)return;console.log(`[Engine] Animation finished! AnimID: ${t}, RuleID: ${s}`);const o=this.artboard.animationFlow||[];o.forEach((e,n)=>{if(e.trigger==="after_anim"&&e.targetAnimationId){let i=e.afterAnim;!i&&n>0&&(i=o[n-1].id);const a=i===t||s&&i===s;if(console.log(`[Engine] Checking rule ${e.id} (Trigger: ${e.trigger}). ExpectedParent: ${i}. isMatch? ${a}`),a){const r=e.delay||0;console.log(`[Engine] Match found! Triggering target animation: ${e.targetAnimationId} after delay: ${r}`),r<=0?this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id):setTimeout(()=>this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id),r)}}})}getWorldTransform(t){var u;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,scaleX:1,scaleY:1,rotation:0};const o=(u=this.artboard)==null?void 0:u.objects.find(g=>g.id===t);if(!o||!o.parentId)return{x:s.x,y:s.y,scaleX:s.scale_x??1,scaleY:s.scale_y??1,rotation:s.rotation??0};const e=this.getWorldTransform(o.parentId),n=e.rotation*(Math.PI/180),i=Math.cos(n),a=Math.sin(n),r=s.x*e.scaleX,l=s.y*e.scaleY,f=e.x+(r*i-l*a),p=e.y+(r*a+l*i);return{x:f,y:p,scaleX:(s.scale_x??1)*e.scaleX,scaleY:(s.scale_y??1)*e.scaleY,rotation:e.rotation+(s.rotation??0)}}hitTest(t,s,o){var v,b;if(!this.objectStates.get(t.id))return!1;const n=((v=t.geometry)==null?void 0:v.width)??t.width??100,i=((b=t.geometry)==null?void 0:b.height)??t.height??100,a=this.getWorldTransform(t.id),r=s-a.x,l=o-a.y,f=-a.rotation*(Math.PI/180),p=Math.cos(f),u=Math.sin(f),g=r*p-l*u,h=r*u+l*p,d=a.scaleX,w=a.scaleY,y=n*Math.abs(d),c=i*Math.abs(w);return Math.abs(g)<=y/2&&Math.abs(h)<=c/2}updateSliderValueFromPointer(t,s,o){var M;const e=this.objectStates.get(t.id);if(!e)return;const n=t.options||{},i=((M=t.geometry)==null?void 0:M.width)??t.width??200,a=this.getWorldTransform(t.id),r=s-a.x,l=o-a.y,f=-a.rotation*(Math.PI/180),p=Math.cos(f),u=Math.sin(f),g=r*p-l*u,h=n.thumbWidth??16,d=i-h;let y=(g+d/2)/d;y=Math.max(0,Math.min(1,y));const c=n.min??0,v=n.max??100,b=n.step||1;let S=c+y*(v-c);b>0&&(S=Math.round(S/b)*b),S=Math.max(c,Math.min(v,S));const C=e.options||{};C.value!==S&&(e.options={...C,value:S},t.inputId&&this.setInternalInput(t.inputId,S),this.onComponentChange&&this.onComponentChange({objectId:t.id,componentName:t.name,variant:"slider",property:"value",value:S}))}updateJoystickValueFromPointer(t,s,o){var M,I;const e=this.objectStates.get(t.id);if(!e)return;const n=(e==null?void 0:e.width)!==void 0?e.width:((M=t.geometry)==null?void 0:M.width)??t.width??100,i=(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=s-a.x,l=o-a.y,f=-a.rotation*(Math.PI/180),p=Math.cos(f),u=Math.sin(f);let g=(r*p-l*u)/Math.max(.001,Math.abs(a.scaleX||1)),h=(r*u+l*p)/Math.max(.001,Math.abs(a.scaleY||1));t.handleOrigin==="top-left"?(g-=n/2,h-=i/2):t.handleOrigin==="bottom-right"&&(g+=n/2,h+=i/2);const d=Math.min(n,i)*.45,w=Math.min(n,i)*.15,y=d-w;let c=g/y,v=h/y;const b=Math.sqrt(c*c+v*v);t.boundsShape==="square"?(c=Math.max(-1,Math.min(1,c)),v=Math.max(-1,Math.min(1,v))):b>1&&(c/=b,v/=b),t.deadzone!==void 0&&b<t.deadzone?(c=0,v=0):(t.stepX!==void 0&&t.stepX>0&&(c=Math.round(c/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"&&(c=0);const S=e.handleX,C=e.handleY;(S!==c||C!==v)&&(e.handleX=c,e.handleY=v,t.handleX=c,t.handleY=v)}processJoysticks(t){this.artboard&&(this.artboard.objects.forEach(s=>{var l,f,p,u;if(s.type!=="Joystick"&&!(s.type==="Component"&&s.variant==="joystick"))return;const o=s,e=this.objectStates.get(o.id);if(!e)return;let n=e.handleX??o.handleX??0,i=e.handleY??o.handleY??0;const r=(o.globalInput??!1)||this.lastHoveredObjectId===o.id;if(r&&((l=o.inputBinding)==null?void 0:l.type)==="keyboard"&&o.inputBinding.keyboardConfig){const g=o.inputBinding.keyboardConfig;let h=n,d=i;const y=(g.speed||5)*t;let c=!1;this.activeKeys.has(g.upKey.toLowerCase())&&(d-=y,c=!0),this.activeKeys.has(g.downKey.toLowerCase())&&(d+=y,c=!0),this.activeKeys.has(g.leftKey.toLowerCase())&&(h-=y,c=!0),this.activeKeys.has(g.rightKey.toLowerCase())&&(h+=y,c=!0),o.joystickType==="1D_X"&&(d=0),o.joystickType==="1D_Y"&&(h=0);const v=Math.sqrt(h*h+d*d);v>1&&(h/=v,d/=v),!c&&o.isSpringReturn!==!1&&(h+=(0-h)*(10*t),d+=(0-d)*(10*t),Math.abs(h)<.01&&(h=0),Math.abs(d)<.01&&(d=0)),n=h,i=d}else if(r&&((f=o.inputBinding)==null?void 0:f.type)==="mouse"&&o.inputBinding.mouseConfig){const g=o.inputBinding.mouseConfig;let h=e._mouseTargetX??n,d=e._mouseTargetY??i;const w=g.sensitivity||.01;if(g.mode==="absolute"){const v=((p=this.artboard)==null?void 0:p.width)||window.innerWidth,b=((u=this.artboard)==null?void 0:u.height)||window.innerHeight,S=this.inputs.get("mouseX")||0,C=this.inputs.get("mouseY")||0;g.axisX&&(h=S/v*2-1),g.axisY&&(d=C/b*2-1)}else g.axisX&&(h+=this._mouseDelta.dx*w),g.axisY&&(d+=this._mouseDelta.dy*w);o.joystickType==="1D_X"&&(d=0),o.joystickType==="1D_Y"&&(h=0);const y=Math.sqrt(h*h+d*d);y>1&&(h/=y,d/=y),o.isSpringReturn!==!1&&(h+=(0-h)*(5*t),d+=(0-d)*(5*t),Math.abs(h)<.01&&(h=0),Math.abs(d)<.01&&(d=0)),e._mouseTargetX=h,e._mouseTargetY=d;const c=15*t;n+=(h-n)*Math.min(c,1),i+=(d-i)*Math.min(c,1)}if(e.handleX=n,e.handleY=i,o.handleX=n,o.handleY=i,o.bindings&&o.bindings.length>0){const g=Math.sqrt(n*n+i*i);let h=Math.atan2(i,n)*(180/Math.PI);h<0&&(h+=360),o.bindings.forEach(d=>{var c,v,b,S,C,M,I,E;let w=0;d.sourceAxis==="x"?w=o.invertX?-n:n:d.sourceAxis==="y"?w=o.invertY?-i:i:d.sourceAxis==="distance"?w=g:d.sourceAxis==="angle"&&(w=h);const y=(c=this.artboard)==null?void 0:c.objects.find(_=>_.id===d.targetObjectId);if(y){if(d.actionType==="bind"&&d.targetProperty&&d.isContinuous!==!1){const _=d.sourceMin??-1,T=d.sourceMax??1,A=d.targetMin??0,R=d.targetMax??100;let Y=!!d.isContinuous,L=0,D=0;if(Y){if((d.sourceAxis==="x"||d.sourceAxis==="y")&&A>=0){const k=Math.max(Math.abs(_),Math.abs(T))||1;D=w/k*R}else{let k=(w-_)/(T-_);k=Math.max(0,Math.min(1,k)),D=A+k*(R-A)}Math.abs(w)<.05&&(D=0)}else{const k=(w-_)/(T-_),O=Math.max(0,Math.min(1,k));L=A+O*(R-A),d.step&&d.step>0&&(L=Math.round(L/d.step)*d.step)}const P=this.objectStates.get(y.id);if(P){const k=d.isRelative!==!1,O=k?((v=y.transform)==null?void 0:v.x)??0:0,$=k?((b=y.transform)==null?void 0:b.y)??0:0,X=k?((S=y.transform)==null?void 0:S.rotation)??0:0,F=k?((C=y.transform)==null?void 0:C.scale_x)??1:0,B=k?((M=y.transform)==null?void 0:M.scale_y)??1:0,j=k?((I=y.style)==null?void 0:I.opacity)??100:0,z=Math.min(t*60,3),q=(U,J)=>{let W=L;if(Y){const N=`_internal_${U}_${d.id}`;let H=P[N];H===void 0&&(H=P[U]??J),W=H+D*z,P[N]=W,d.step&&d.step>0&&(W=Math.round(W/d.step)*d.step)}else{W=J+L;const N=`_internal_smooth_${U}_${d.id}`;let H=P[N];if(H===void 0)H=W;else{const rt=Math.min(15*t,1);H+=(W-H)*rt}P[N]=H,W=H}P[U]=W};d.targetProperty==="x"||d.targetProperty==="transform.x"?q("x",O):d.targetProperty==="y"||d.targetProperty==="transform.y"?q("y",$):d.targetProperty==="rotation"||d.targetProperty==="r"||d.targetProperty==="transform.rotation"?q("rotation",X):d.targetProperty==="scaleX"||d.targetProperty==="transform.scale_x"?q("scale_x",F):d.targetProperty==="scaleY"||d.targetProperty==="transform.scale_y"?q("scale_y",B):(d.targetProperty==="opacity"||d.targetProperty==="transform.opacity")&&q("opacity",j)}(E=y.physics)!=null&&E.enabled&&this.physicsEngine&&(d.targetProperty==="x"||d.targetProperty==="transform.x"||d.targetProperty==="y"||d.targetProperty==="transform.y")&&(d.targetProperty==="x"||d.targetProperty==="transform.x"?this.physicsEngine.applyForce(y.id,(L-((P==null?void 0:P.x)||0))*10,0):(d.targetProperty==="y"||d.targetProperty==="transform.y")&&this.physicsEngine.applyForce(y.id,0,(L-((P==null?void 0:P.y)||0))*10))}else if(d.actionType==="playAnimation"||d.actionType==="stopAnimation"||d.actionType==="pauseAnimation"){let _=!1;const T=d.threshold??0;d.condition==="always"?_=!0:d.condition===">"?_=w>T:d.condition==="<"?_=w<T:d.condition==="=="&&(_=Math.abs(w-T)<.01);const A=e[`_prev_src_${d.id}`]??w;let R=!1;d.condition==="always"?R=!0:d.condition===">"?R=A>T:d.condition==="<"?R=A<T:d.condition==="=="&&(R=Math.abs(A-T)<.01),e[`_prev_src_${d.id}`]=w,_&&!R&&d.targetAnimationId&&(d.actionType==="playAnimation"||d.actionType)}}})}}),this._mouseDelta.dx=0,this._mouseDelta.dy=0)}applyBlendState(t,s){var l,f,p,u,g,h,d,w;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 n=[];let i=0;if(t.blendType==="1D"){const y=[...t.blendAnimations].sort((c,v)=>c.position[0]-v.position[0]);if(y.length===1){const c=(f=(l=this.artboard)==null?void 0:l.animations)==null?void 0:f.find(v=>v.id===y[0].animationId);c&&(n.push({anim:c,weight:1}),i=1)}else{let c=0;for(;c<y.length-1&&y[c+1].position[0]<o;)c++;if(c===y.length-1&&o>y[c].position[0]){const v=(u=(p=this.artboard)==null?void 0:p.animations)==null?void 0:u.find(b=>b.id===y[c].animationId);v&&(n.push({anim:v,weight:1}),i=1)}else{const v=y[c].position[0],b=y[c+1].position[0],S=(h=(g=this.artboard)==null?void 0:g.animations)==null?void 0:h.find(_=>_.id===y[c].animationId),C=(w=(d=this.artboard)==null?void 0:d.animations)==null?void 0:w.find(_=>_.id===y[c+1].animationId),M=Math.max(.001,b-v);let I=(o-v)/M;I=Math.max(0,Math.min(1,I));const E=1-I;S&&(n.push({anim:S,weight:E}),i+=E),C&&(n.push({anim:C,weight:I}),i+=I)}}}else t.blendAnimations.forEach(y=>{var C,M;const c=(M=(C=this.artboard)==null?void 0:C.animations)==null?void 0:M.find(I=>I.id===y.animationId);if(!c)return;const v=y.position[0]-o,b=y.position[1]-e,S=v*v+b*b;if(S<1e-4)n.push({anim:c,weight:1e4}),i+=1e4;else{const I=1/S;n.push({anim:c,weight:I}),i+=I}});if(i===0)return;n.forEach(y=>y.weight/=i);const a=new Map,r=y=>{let c=y.startsWith("#")?y.substring(1):y;return c.length===3&&(c=[c[0],c[0],c[1],c[1],c[2],c[2]].join("")),c="0x"+c,{r:c>>16&255,g:c>>8&255,b:c&255,a:1}};n.forEach(({anim:y,weight:c})=>{y.tracks&&y.tracks.forEach(v=>{var T,A;const b=v.object_id||v.objectId,S=v.property,C=(T=this.artboard)==null?void 0:T.objects.find(R=>R.id===b);if(((A=C==null?void 0:C.physics)==null?void 0:A.enabled)&&C.physics.bodyType!=="Static"&&(S==="x"||S==="y"||S==="rotation"))return;const I=this.interpolate(v.keyframes,s);if(I===void 0)return;let E=a.get(b);E||(E=new Map,a.set(b,E));let _=E.get(S);if(!_){if(typeof I=="number")_={type:"number",value:0};else if(typeof I=="string"&&I.startsWith("#"))_={type:"color",value:I,colorAcc:{r:0,g:0,b:0,a:0}};else if(_={type:"number",value:I},c<.5)return;E.set(S,_)}if(_.type==="number"&&typeof I=="number")_.value+=I*c;else if(_.type==="color"&&typeof I=="string"&&_.colorAcc){const R=r(I);R&&(_.colorAcc.r+=R.r*c,_.colorAcc.g+=R.g*c,_.colorAcc.b+=R.b*c,_.colorAcc.a+=R.a*c)}else c>.5&&(_.value=I)})}),a.forEach((y,c)=>{var S;const v=this.objectStates.get(c),b=(S=this.artboard)==null?void 0:S.objects.find(C=>C.id===c);!v||!b||y.forEach((C,M)=>{let I=C.value;if(C.type==="color"&&C.colorAcc){const E=Math.round(C.colorAcc.r).toString(16).padStart(2,"0"),_=Math.round(C.colorAcc.g).toString(16).padStart(2,"0"),T=Math.round(C.colorAcc.b).toString(16).padStart(2,"0");I=`#${E}${_}${T}`}if(M.includes(".")||M.includes("[")){const E=(M||"").replace(/\[(\d+)\]/g,".$1").split(".");let _=v;for(let T=0;T<E.length-1;T++){if(typeof _[E[T]]!="object"||_[E[T]]===null){let A=b;for(let R=0;R<=T;R++)A=A?A[E[R]]:null;if(E[T]==="corner_radius"||E[T]==="cornerRadius"){const R=typeof _[E[T]]=="number"?_[E[T]]:typeof A=="number"?A:0;_[E[T]]={tl:R,tr:R,bl:R,br:R}}else{const R=E[T+1],Y=!isNaN(Number(R));_[E[T]]=A?JSON.parse(JSON.stringify(A)):Y?[]:{}}}_=_[E[T]]}_[E[E.length-1]]=I,E[E.length-1]==="color"&&(E[E.length-2]==="fill"||E[E.length-2]==="stroke")&&(_.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,s,o){!t||!t.tracks||t.tracks.forEach(e=>{var p,u,g;const n=e.object_id||e.objectId;if(o){if(Array.isArray(o)){if(!o.includes(n))return}else if(n!==o)return}const i=(p=this.artboard)==null?void 0:p.objects.find(h=>h.id===n),a=((u=i==null?void 0:i.physics)==null?void 0:u.enabled)&&i.physics.bodyType!=="Static";let r=e.property;if(a&&(r==="x"||r==="y"||r==="rotation"))return;const l=this.objectStates.get(n);if(!l){this.frameCount%600===0&&this.debugLog(`Skipping track: Object ${n} not found in state`);return}const f=this.interpolate(e.keyframes,s);if(f!==void 0){if(this.frameCount%240===0){const h=(i==null?void 0:i.name)||n,d=typeof f=="object"?JSON.stringify(f).slice(0,50):f;this.debugLog(`[Anim] Applying ${r} = ${d} to ${h}`)}if(r.includes(".")||r.includes("[")){const h=(r||"").replace(/\[(\d+)\]/g,".$1").split(".");let d=l;for(let w=0;w<h.length-1;w++){if(typeof d[h[w]]!="object"||d[h[w]]===null){let y=i;for(let c=0;c<=w;c++)y=y?y[h[c]]:null;if(h[w]==="corner_radius"||h[w]==="cornerRadius"){let c=0,v=0,b=0,S=0;const C=d[h[w]]??y;typeof C=="number"?c=v=b=S=C:Array.isArray(C)?C.length===1?c=v=b=S=C[0]:C.length===2?(c=b=C[0],v=S=C[1]):C.length===3?(c=C[0],v=S=C[1],b=C[2]):C.length>=4&&(c=C[0],v=C[1],b=C[2],S=C[3]):C&&typeof C=="object"&&(c=C[0]??C.tl??C.corner_radius??C.cornerRadius??0,v=C[1]??C.tr??C.corner_radius??C.cornerRadius??0,b=C[2]??C.br??C.corner_radius??C.cornerRadius??0,S=C[3]??C.bl??C.corner_radius??C.cornerRadius??0),d[h[w]]={tl:c,tr:v,bl:S,br:b,0:c,1:v,2:b,3:S}}else{const c=h[w+1],v=!isNaN(Number(c));d[h[w]]=y?JSON.parse(JSON.stringify(y)):v?[]:{}}}d=d[h[w]]}d[h[h.length-1]]=f,h[h.length-1]==="color"&&(h[h.length-2]==="fill"||h[h.length-2]==="stroke")&&(d.type="Solid")}else r==="fill"?(l.style||(l.style={}),l.style.fill=f):r==="stroke"?(l.style||(l.style={}),l.style.stroke=f):l[r]=f;if(this.physicsEngine&&((g=i==null?void 0:i.physics)!=null&&g.enabled)&&i.physics.bodyType==="Static")if(r==="x"){const h=this.physicsEngine.getPosition(n);h&&this.physicsEngine.setPosition(n,f,h.y)}else if(r==="y"){const h=this.physicsEngine.getPosition(n);h&&this.physicsEngine.setPosition(n,h.x,f)}else r==="rotation"&&this.physicsEngine.setRotation(n,f*(Math.PI/180))}})}interpolate(t,s){if(t.length===0)return;let o=t[0],e=t[t.length-1];if(s<=o.time)return o.value;if(s>=e.time)return e.value;for(let a=0;a<t.length-1;a++)if(s>=t[a].time&&s<t[a+1].time){o=t[a],e=t[a+1];break}const n=e.time-o.time;let i=(s-o.time)/n;return o.easing&&(i=ei(o.easing)(i)),this.interpolateValue(o.value,e.value,i)}interpolateValue(t,s,o){if(t===void 0)return s;if(s===void 0)return t;if(typeof t=="string"&&typeof s=="string"){if(t.startsWith("#"))return this.interpolateColor(t,s,o);const e=parseFloat(t),n=parseFloat(s);return!isNaN(e)&&!isNaN(n)?Math.round(e+(n-e)*o).toString():o<.5?t:s}if(Array.isArray(t)&&Array.isArray(s))return t.length===s.length?t.map((e,n)=>this.interpolateValue(e,s[n],o)):o<.5?t:s;if(typeof t=="object"&&typeof s=="object"&&t!==null&&s!==null){if(t.width!==void 0&&t.color!==void 0&&typeof t.width=="number")return this.interpolateStroke(t,s,o);if(t.type&&s.type&&(t.type==="Solid"||t.type==="LinearGradient"||t.type==="RadialGradient"||t.type==="Image"))return this.interpolateFill(t,s,o);const e={};return new Set([...Object.keys(t),...Object.keys(s)]).forEach(i=>{e[i]=this.interpolateValue(t[i],s[i],o)}),e}return typeof t=="number"&&typeof s=="number"?t+(s-t)*o:o<.5?t:s}interpolateColor(t,s,o){var h,d;const e=((d=(h=this.artboard)==null?void 0:h.tokens)==null?void 0:d.colors)||{},n=e[t]||t,i=e[s]||s,a=w=>{if(!w)return{r:0,g:0,b:0};const y=w.startsWith("#")?w.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)}},r=a(n),l=a(i),f=Math.round(r.r+(l.r-r.r)*o),p=Math.round(r.g+(l.g-r.g)*o),u=Math.round(r.b+(l.b-r.b)*o),g=w=>{const y=Math.max(0,Math.min(255,w)).toString(16);return y.length===1?"0"+y:y};return`#${g(f)}${g(p)}${g(u)}`}interpolateStops(t,s,o){return!t||!s||t.length!==s.length?o<.5?t:s:t.map((e,n)=>{const i=s[n];return{offset:e.offset+(i.offset-e.offset)*o,color:this.interpolateColor(e.color,i.color,o),opacity:(e.opacity??1)+((i.opacity??1)-(e.opacity??1))*o}})}interpolateFill(t,s,o){if(!t||!s||t.type!==s.type)return o<.5?t:s;const e={...t,opacity:(t.opacity??1)+((s.opacity??1)-(t.opacity??1))*o};return t.type==="Solid"?e.color=this.interpolateColor(t.color,s.color,o):(t.type==="LinearGradient"||t.type==="RadialGradient")&&(t.start&&s.start&&(e.start=[t.start[0]+(s.start[0]-t.start[0])*o,t.start[1]+(s.start[1]-t.start[1])*o]),t.end&&s.end&&(e.end=[t.end[0]+(s.end[0]-t.end[0])*o,t.end[1]+(s.end[1]-t.end[1])*o]),t.center&&s.center&&(e.center=[t.center[0]+(s.center[0]-t.center[0])*o,t.center[1]+(s.center[1]-t.center[1])*o]),t.radius!==void 0&&s.radius!==void 0&&(e.radius=t.radius+(s.radius-t.radius)*o),e.stops=this.interpolateStops(t.stops,s.stops,o)),e}interpolateStroke(t,s,o){if(!t||!s)return o<.5?t:s;const e={...t};return e.width=(t.width??0)+((s.width??0)-(t.width??0))*o,e.opacity=(t.opacity??1)+((s.opacity??1)-(t.opacity??1))*o,t.fill&&s.fill?e.fill=this.interpolateFill(t.fill,s.fill,o):t.color&&s.color&&t.color.startsWith("#")&&s.color.startsWith("#")&&(e.color=this.interpolateColor(t.color,s.color,o)),e.trimStart=(t.trimStart??0)+((s.trimStart??0)-(t.trimStart??0))*o,e.trimEnd=(t.trimEnd??1)+((s.trimEnd??1)-(t.trimEnd??1))*o,e.trimOffset=(t.trimOffset??0)+((s.trimOffset??0)-(t.trimOffset??0))*o,e.dashOffset=(t.dashOffset??0)+((s.dashOffset??0)-(t.dashOffset??0))*o,e}render(t,s,o){var p;this.debug_objectsTotal=((p=this.artboard)==null?void 0:p.objects.length)||0,this.debug_objectsRendered=0;const e=performance.now();if(this.canvasWidth=s,this.canvasHeight=o,!this.artboard)return;t.clearRect(0,0,s,o);const n=this.artboard.width,i=this.artboard.height,a=this.calculateTransform(s,o,n,i,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,n,i)),this.artboard.backgroundImage){const u=this.artboard.backgroundImage;let g=this.imageCache.get(u);if(g||(g=new Image,g.src=u,this.imageCache.set(u,g)),g.complete&&g.naturalWidth>0){t.save(),t.globalAlpha=this.normalizeOpacity(this.artboard.backgroundOpacity??100);const h=g.naturalWidth/g.naturalHeight,d=n/i;let w,y,c,v;d>h?(w=n,y=n/h):(y=i,w=i*h),c=(n-w)/2,v=(i-y)/2,t.drawImage(g,c,v,w,y),t.restore()}}this.artboard.clipContent!==!1&&this.artboard.clip_content!==!1&&(t.beginPath(),t.rect(0,0,n,i),t.clip());const l=new Map;this.artboard.objects.forEach(u=>l.set(u.id,u)),this.artboard.objects.filter(u=>!u.parentId).map((u,g)=>{const h=this.objectStates.get(u.id),d=(h==null?void 0:h.zIndex)??g;return{obj:u,zIndex:d}}).sort((u,g)=>u.zIndex-g.zIndex).forEach(({obj:u})=>{this.renderObject(t,u,l)}),this._emitterPools.forEach((u,g)=>{if(!(u.length===0||!l.get(g)))for(const d of u)t.save(),t.globalAlpha=d.opacity,t.fillStyle=d.color,t.beginPath(),t.arc(d.x,d.y,Math.max(1,d.size*d.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,s,o,e,n,i=0){const a=t.getTransform(),r=s*a.a+o*a.c+a.e,l=s*a.b+o*a.d+a.f,f=Math.sqrt(a.a*a.a+a.b*a.b),p=Math.sqrt(a.c*a.c+a.d*a.d),u=(e/2+i)*f,g=(n/2+i)*p;return r+u>=0&&r-u<=this.canvasWidth&&l+g>=0&&l-g<=this.canvasHeight}calculateTransform(t,s,o,e,n,i){let a=1,r=1,l=1;const f=o/e,p=t/s;switch(n){case"Contain":p>f?l=s/e:l=t/o,a=r=l;break;case"Cover":p>f?l=t/o:l=s/e,a=r=l;break;case"Fill":a=t/o,r=s/e;break;case"FitWidth":l=t/o,a=r=l;break;case"FitHeight":l=s/e,a=r=l;break;case"None":a=r=1;break;case"ScaleDown":l=Math.min(t/o,s/e),l>1&&(l=1),a=r=l;break;default:a=r=1;break}const u=o*a,g=e*r;let h=0,d=0;return i.includes("Left")?h=0:i.includes("Right")?h=t-u:h=(t-u)/2,i.includes("Top")?d=0:i.includes("Bottom")?d=s-g:d=(s-g)/2,{scaleX:a,scaleY:r,tx:h,ty:d}}mapFontWeight(t){const s=t.toLowerCase();return s==="thin"||s==="100"?"100":s==="extralight"||s==="200"?"200":s==="light"||s==="300"?"300":s==="regular"||s==="normal"||s==="400"?"400":s==="medium"||s==="500"?"500":s==="semibold"||s==="600"?"600":s==="bold"||s==="700"?"700":s==="extrabold"||s==="800"?"800":s==="black"||s==="900"?"900":t}drawTextDecoration(t,s,o,e,n,i){t.beginPath();const a=Math.max(1,i/14);let r=e;s==="underline"?r=e+i*.12:s==="line-through"&&(r=e-i*.3),t.lineWidth=a,t.strokeStyle=t.fillStyle,t.moveTo(o-n/2,r),t.lineTo(o+n/2,r),t.stroke()}renderObject(t,s,o,e=!1,n=!1){var v,b,S,C,M,I,E,_,T,A,R,Y,L,D,P,k,O,$,X,F,B,j,z,q,U,J,W,N,H,rt,It,mt,St,pt,kt,Bt;const i=this.objectStates.get(s.id);if(!i){this.warn("No state for object:",s.id);return}this.frameCount%60,t.roundRect||(t.roundRect=(vt,Dt,Z,ft,Tt)=>(this.drawRoundRect(t,vt,Dt,Z,ft,Tt),t));const a=i.geometry?this.deepMerge(s.geometry,i.geometry):s.geometry;let r=i.style?this.deepMerge(s.style,i.style):s.style,l=(a==null?void 0:a.width)||((v=s.geometry)==null?void 0:v.width)||s.width||0,f=(a==null?void 0:a.height)||((b=s.geometry)==null?void 0:b.height)||s.height||0;if((l===0||f===0)&&(a!=null&&a.points)&&Array.isArray(a.points)&&a.points.length>0){let vt=1/0,Dt=-1/0,Z=1/0,ft=-1/0;a.points.forEach(Tt=>{vt=Math.min(vt,Tt.x),Dt=Math.max(Dt,Tt.x),Z=Math.min(Z,Tt.y),ft=Math.max(ft,Tt.y)}),l===0&&(l=Dt-vt),f===0&&(f=ft-Z)}const p=vt=>{if(vt)return vt.corner_radius??vt.cornerRadius},u=p(a)??p(i)??p(r)??p(s.geometry)??p(s.style)??p(s)??0;let g={...a,width:l,height:f};if(delete g.cornerRadius,g.corner_radius=u,!g.type&&(s.type==="Frame"||s.type==="Component"||s.type==="Group")&&(g.type="Rectangle"),s.type==="Text"&&(g.type="Text"),g.type==="Path"&&s.weights&&s.bindMatrices&&g.points){const vt=this.getGlobalTransform(s.id);if(vt){const Dt=si(g.points,s.weights,s.bindMatrices,vt,Z=>this.getGlobalTransform(Z));g={...g,points:Dt}}}if(i.visible===!1)return;const d=(r.effects||((S=s.style)==null?void 0:S.effects)||[]).find(vt=>vt.isEnabled!==!1&&vt.type==="PathDistortion");if(d){const vt=ni(g,l,f,d.amplitude||5,d.frequency||10,d.seed||0,d.direction||0,d.directionStrength||0);g={...g,type:"Path",points:vt}}const w=s.repeaterConfig,y=w&&w.isEnabled&&w.count>1,c=y?w.count:1;for(let vt=0;vt<c;vt++){let Dt=i.x!==void 0?i.x:((C=i.transform)==null?void 0:C.x)??0,Z=i.y!==void 0?i.y:((M=i.transform)==null?void 0:M.y)??0,ft=i.rotation!==void 0?i.rotation:((I=i.transform)==null?void 0:I.rotation)??0,Tt=i.scale_x!==void 0?i.scale_x:((E=i.transform)==null?void 0:E.scale_x)??1,Ot=i.scale_y!==void 0?i.scale_y:((_=i.transform)==null?void 0:_.scale_y)??1;if(y&&vt>0){if(w.type==="Linear"){const K=w.offsetX||0,ot=w.offsetY||0,G=w.rotation||0,V=w.scale!==void 0?w.scale:1;Dt+=vt*K,Z+=vt*ot,ft+=vt*G,Tt*=Math.pow(V,vt),Ot*=Math.pow(V,vt)}else if(w.type==="Grid"){const K=w.cols||Math.ceil(Math.sqrt(w.count)),ot=w.gapX||0,G=w.gapY||0,V=Math.floor(vt/K),Q=vt%K,tt=l+ot,ht=f+G;Dt+=Q*tt,Z+=V*ht}else if(w.type==="Radial"){const K=w.radius||100,ot=w.startAngle||0,V=(w.endAngle||360)-ot,Q=w.count>1?V/(V===360?w.count:w.count-1):0,tt=ot+vt*Q,ht=tt*Math.PI/180;Dt=i.x+K*Math.cos(ht),Z=i.y+K*Math.sin(ht),ft+=tt}}const _t=s.type==="Group"||s.type==="Frame"||s.type==="Component",Rt=l>0&&f>0;if(!_t&&Rt&&!e){const K=(((T=r.shadow)==null?void 0:T.isEnabled)!==!1?(((A=r.shadow)==null?void 0:A.blur)||0)+10:0)+(((R=r.blur)==null?void 0:R.isEnabled)!==!1&&((Y=r.blur)==null?void 0:Y.radius)||0)+20;if(!this.isObjectInView(t,Dt,Z,l,f,K))continue}this.debug_objectsRendered++,t.save();const $t=[],Ht=r.blur||((L=s.style)==null?void 0:L.blur);Ht&&Ht.amount>0&&$t.push(`blur(${Ht.amount}px)`);const zt=r.effects||((D=s.style)==null?void 0:D.effects)||[];let qt=zt.find(K=>K.isEnabled!==!1&&(K.type==="BackgroundBlur"||K.type==="LayerBlur"));qt||(qt=r.effect||((P=s.style)==null?void 0:P.effect)||zt.find(K=>K.isEnabled!==!1));const Jt=qt,se=(Jt==null?void 0:Jt.isEnabled)!==!1,ie=Jt==null?void 0:Jt.type,Se=(Jt==null?void 0:Jt.radius)??10;se&&ie==="LayerBlur"?$t.push(`blur(${Se}px)`):se&&ie==="BackgroundBlur"&&(r===s.style&&(r={...r}),r.fill={type:"None"});const Pe=(g==null?void 0:g.adjustments)||(a==null?void 0:a.adjustments)||((k=s.geometry)==null?void 0:k.adjustments),me=(r==null?void 0:r.adjustments)||((O=s.style)==null?void 0:O.adjustments),_e=(($=r==null?void 0:r.fill)==null?void 0:$.adjustments)||((F=(X=s.style)==null?void 0:X.fill)==null?void 0:F.adjustments),Me=s==null?void 0:s.adjustments,Zt=Pe||me||_e||Me;if(i&&Zt&&(i.geometry=i.geometry||{},i.geometry.adjustments={...Zt}),Zt){const K=(Zt.exposure||0)/100,ot=(Zt.contrast||0)/100,G=(Zt.saturation||0)/100,V=(Zt.temperature||0)/200,Q=(Zt.tint||0)/200,tt=(Zt.highlights||0)/500,ht=(Zt.shadows||0)/500,Et=Zt.hue||0,Yt=(Zt.negative||0)/100,jt=Zt.blur||0;if(K!==0&&$t.push(`brightness(${1+K})`),ot!==0){const yt=ot>0?1+ot*2:1+ot;$t.push(`contrast(${Number(yt.toFixed(2))})`)}if(G!==0){const yt=G>0?1+G*1.5:1+G;$t.push(`saturate(${Number(yt.toFixed(2))})`)}const Xt=Et+Q*30-V*20;Xt!==0&&$t.push(`hue-rotate(${Math.round(Xt)}deg)`),V>0&&$t.push(`sepia(${Math.round(V*40)}%)`),Yt!==0&&$t.push(`invert(${Math.abs(Yt)})`),tt!==0&&$t.push(`brightness(${1+tt})`),ht!==0&&$t.push(`contrast(${1+ht})`),jt>0&&$t.push(`blur(${jt}px)`)}$t.length>0?(t.filter=$t.join(" "),(!this._lastLoggedAdjustments||this._lastLoggedAdjustments!==t.filter)&&(this._lastLoggedAdjustments=t.filter,this.log(`[ExodeUI Engine] Applied Canvas Filter for (${s.name||s.id}): "${t.filter}" (Adjustments: ${JSON.stringify(Zt)})`),console.log(`[ExodeUI Engine Log] Applied Canvas Filter for (${s.name||s.id}):`,{filter:t.filter,adjustments:Zt}))):t.filter="none",t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";const Le=t.globalAlpha,Re=this.normalizeOpacity(i.opacity!==void 0?i.opacity:100);t.globalAlpha=Le*Re;const ve=i.compositeOperation||i.blendMode;if(ve&&ve!=="Normal"){const K=ve.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(K)&&(t.globalCompositeOperation=K)}const ae=t,Oe=i.masks||(s.maskedBy?[{maskId:s.maskedBy,inverted:s.maskInverted===!0,type:s.maskType||"alpha",opacity:s.maskOpacity!==void 0?s.maskOpacity/100:1,feather:s.maskFeather||0,isVisible:!0}]:[]);let pe=!1;const bt=Oe.filter(K=>K.isVisible!==!1&&o.has(K.maskId));if(bt.length>0){const K=bt[0],ot=o.get(K.maskId),G=this.objectStates.get(ot.id);G&&G.visible!==!1&&(pe=!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),s.parentId&&this.applyAbsoluteTransform(this.maskCtx,s.parentId,o),this.maskCtx.save(),this.maskCtx.globalAlpha=1,t=this.maskCtx,t.filter=ae.filter)}if(!n){t.translate(Dt,Z),t.rotate(ft*Math.PI/180);const K=i.skew_x||0,ot=i.skew_y||0;if(K!==0||ot!==0){const Yt=Math.tan(K*Math.PI/180),jt=Math.tan(ot*Math.PI/180);t.transform(1+Yt*jt,jt,Yt,1,0,0)}const G=i.rotate_x!==void 0?i.rotate_x:((B=i.transform)==null?void 0:B.rotate_x)??0,V=i.rotate_y!==void 0?i.rotate_y:((j=i.transform)==null?void 0:j.rotate_y)??0,tt=1+(i.translate_z!==void 0?i.translate_z:((z=i.transform)==null?void 0:z.translate_z)??0)/1e3,ht=(i.flip_x===!0?-1:1)*Math.cos(V*Math.PI/180)*tt,Et=(i.flip_y===!0?-1:1)*Math.cos(G*Math.PI/180)*tt;t.scale(Tt*ht,Ot*Et)}r.shadow&&r.shadow.isEnabled===void 0&&((r.shadow.blur||0)>0||Math.abs(r.shadow.offsetX||0)>0||Math.abs(r.shadow.offsetY||0)>0)&&(r.shadow.isEnabled=!0);const at=r.shadow;if(at&&at.isEnabled!==!1&&!e){let K=at.color||"#000000";(U=(q=this.artboard)==null?void 0:q.tokens)!=null&&U.colors&&this.artboard.tokens.colors[K]&&(K=this.artboard.tokens.colors[K]);const ot=this.normalizeOpacity(at.opacity??100)*.75,G=at.spread||0,Q=(at.blur||0)+G*1.5;let tt=K;if(K.startsWith("#")){const Yt=K.replace("#",""),jt=parseInt(Yt.substring(0,2),16),Xt=parseInt(Yt.substring(2,4),16),yt=parseInt(Yt.substring(4,6),16);tt=`rgba(${jt}, ${Xt}, ${yt}, ${ot})`}else if(K.startsWith("rgba")){const Yt=K.match(/[\d.]+/g);if(Yt&&Yt.length>=4){const jt=Yt[0],Xt=Yt[1],yt=Yt[2],x=Yt[3];tt=`rgba(${jt}, ${Xt}, ${yt}, ${parseFloat(x)*ot})`}}const ht=t.getTransform(),Et=Math.sqrt(ht.a*ht.a+ht.b*ht.b)||1;t.shadowColor=tt,t.shadowBlur=Q*Et,t.shadowOffsetX=(at.offsetX||0)*Et,t.shadowOffsetY=(at.offsetY||0)*Et}const Ct=s.liquidFill||((J=s.style)==null?void 0:J.liquidFill);if(Ct&&Ct.enabled){t.save();const K=Ct.fillLevel??.5;t.beginPath();const ot=f/2-f*K;t.rect(-l/2,ot,l,f*K),t.clip(),t.fillStyle=Ct.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(Ct.opacity??1)}if(e||this.applyOuterGlowUnderlay(t,s,g,l,f,u,r,o),(a==null?void 0:a.type)==="Text"||s.type==="Text")this._renderText(t,s,g,r,i,l,f,!1,!1);else if((a==null?void 0:a.type)==="Image"||((W=r.fill)==null?void 0:W.type)==="Image"||s.type==="Image"&&(a!=null&&a.src||(N=r.fill)!=null&&N.src)){const K=(a==null?void 0:a.originalSrc)||(a==null?void 0:a.src)||((H=r.fill)==null?void 0:H.originalSrc)||((rt=r.fill)==null?void 0:rt.src)||(s==null?void 0:s.src);if(K){let ot=this.imageCache.get(K);ot||(ot=new Image,ot.onload=()=>{this.log(`[ExodeUI] Image loaded successfully, size: ${ot.naturalWidth}x${ot.naturalHeight}`)},ot.onerror=Q=>{console.error("[ExodeUI] Image load failed:",Q,`Src preview: ${K.substring(0,100)}...`)},ot.src=K,this.imageCache.set(K,ot));const G=r.stroke&&r.stroke.width>0&&r.stroke.isEnabled!==!1,V=(((It=r.stroke)==null?void 0:It.alignment)||"center").toLowerCase();if(G&&V==="outside"&&this.applyStrokeAlignment(t,r,g,l,f,u),r.fill&&r.fill.type!=="None"){t.save();const Q=t.globalAlpha,tt=this.createCanvasFill(t,r.fill,l,f);t.fillStyle=tt||r.fill.color||"transparent",t.globalAlpha=Q*this.normalizeOpacity(r.fill.opacity??100),u!==0?(this.drawRoundRect(t,-l/2,-f/2,l,f,u),t.fill()):t.fillRect(-l/2,-f/2,l,f),t.globalAlpha=Q,t.restore()}if(ot.complete&&ot.naturalWidth>0){const Q=Zt?this.processFabricAdjustmentsCanvas(ot,l,f,Zt):ot;u!==0?(t.save(),this.drawRoundRect(t,-l/2,-f/2,l,f,u),t.clip(),t.drawImage(Q,-l/2,-f/2,l,f),t.restore()):t.drawImage(Q,-l/2,-f/2,l,f),G&&(V==="inside"||V==="center")&&this.applyStrokeAlignment(t,r,g,l,f,u)}else G&&(V==="inside"||V==="center")&&this.applyStrokeAlignment(t,r,g,l,f,u)}}else if(a.type==="SVG"){const K=a.svgContent;if(K){const ot=r.palette||[],G=r.fill,V=r.stroke,Q=G?this.normalizeOpacity(G.opacity??100):1,tt=V&&V.isEnabled!==!1?this.normalizeOpacity(V.opacity??100):1,ht=(G==null?void 0:G.type)==="Solid"&&(!V||V.isEnabled===!1||V.type==="Solid"&&V.color===G.color&&tt===Q),Et=G&&G.type!=="None"?ht?"monochrome":G.type==="Solid"?(G.color||"")+"|opacity:"+Q:JSON.stringify(G.stops||[])+"|opacity:"+Q:"",Yt=V&&V.isEnabled!==!1&&(V.width||0)>0?ht?["monochrome",V.width||0,V.trimStart??0,V.trimEnd??1,V.trimOffset??0,V.dashOffset??0].join("|"):[V.width||0,V.fill?V.fill.type==="Solid"?V.fill.color||"":JSON.stringify(V.fill.stops||[]):V.color||"",V.opacity??1,V.lineCap||"",V.lineJoin||"",(V.dashArray||[]).join(","),V.trimStart??0,V.trimEnd??1,V.trimOffset??0,V.dashOffset??0].join("|"):"nostroke",jt=[s.id,ot.join("_"),Et,Yt,i.opacity??100,i.visible!==!1?"v":"h"].join("_");let Xt=this.imageCache.get(jt);if(!Xt){Xt=new Image,Xt.crossOrigin="anonymous";let x=K;x.match(/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i)||(x=x.replace(/<svg([^>]*)>/i,(Mt,Gt)=>`<svg xmlns="http://www.w3.org/2000/svg"${Gt}>`));let wt=a.width||l||100,Vt=a.height||f||100;const lt=x.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(lt&&(wt=parseFloat(lt[1]),Vt=parseFloat(lt[2])),x=x.replace(/<svg([^>]*)>/i,(Mt,Gt)=>{let Pt=Gt.replace(/\b(?:width|height)=["'][^"']*["']/gi," ");return Pt.match(/\bviewBox=/i)||(Pt+=` viewBox="0 0 ${wt} ${Vt}"`),Pt.match(/\bpreserveAspectRatio=/i)||(Pt+=' preserveAspectRatio="none"'),Pt+=' width="100%" height="100%"',`<svg${Pt}>`}),a.colors&&a.colors.length>0&&ot.length>0&&a.colors.forEach((Mt,Gt)=>{if(ot[Gt]){const Pt=Mt.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),Nt=new RegExp(Pt,"gi");x=x.replace(Nt,ot[Gt])}}),G&&G.type&&G.type!=="None"){if(G.type==="Solid"&&G.color){const Mt=ht?"#FFFFFF":G.color,Gt=ht?1:this.normalizeOpacity(G.opacity??100);x=x.replace(/\bfill\s*=\s*["'][^"']*["']/gi,Pt=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Pt)?Pt:`fill="${Mt}"`),x=x.replace(/fill\s*:\s*[^;"')]+/gi,Pt=>/fill\s*:\s*(none|transparent)/i.test(Pt)?Pt:`fill:${Mt}`),Gt<1&&(x=x.replace(/\bfill-opacity\s*=\s*["'][^"']*["']/gi,`fill-opacity="${Gt}"`),x=x.replace(/fill-opacity\s*:\s*[^;"')]+/gi,`fill-opacity:${Gt}`),x.match(/\bfill-opacity\s*=/i)||(x=x.replace(/(<svg[^>]*>)/i,`$1<g fill-opacity="${Gt}">`),x=x.replace(/<\/svg>/i,"</g></svg>")))}else if(G.type==="LinearGradient"||G.type==="RadialGradient"||G.type==="Linear"||G.type==="Radial"){const Mt="exode-fill",Gt=this.normalizeOpacity(G.opacity??100),Pt=(G.stops||[]).map(Ft=>{const fe=Ft.offset!==void 0?Ft.offset:Ft.pos??0,ue=this.normalizeOpacity(Ft.opacity??100)*Gt;return`<stop offset="${fe*100}%" stop-color="${Ft.color||"#000"}" stop-opacity="${ue}"/>`}).join("");let Nt="";if(G.type==="LinearGradient"||G.type==="Linear"){const Ft=(re,oe)=>Array.isArray(re)?re[oe]??(oe===0?0:1):re&&typeof re=="object"?re[oe===0?"x":"y"]??(oe===0?0:1):oe===0?0:1,fe=Ft(G.start,0)*100,ue=Ft(G.start,1)*100,Ee=Ft(G.end,0)*100,te=Ft(G.end,1)*100;Nt=`<linearGradient id="${Mt}" x1="${fe}%" y1="${ue}%" x2="${Ee}%" y2="${te}%" gradientUnits="objectBoundingBox">${Pt}</linearGradient>`}else{const Ft=(te,re)=>Array.isArray(te)?te[re]??.5:te&&typeof te=="object"?te[re===0?"x":"y"]??.5:.5,fe=Ft(G.center,0)*100,ue=Ft(G.center,1)*100,Ee=(G.radius??.5)*100;Nt=`<radialGradient id="${Mt}" cx="${fe}%" cy="${ue}%" r="${Ee}%" gradientUnits="objectBoundingBox">${Pt}</radialGradient>`}/<defs>/i.test(x)?x=x.replace(/<defs>/i,`<defs>${Nt}`):x=x.replace(/<svg([^>]*)>/i,`<svg$1><defs>${Nt}</defs>`),x=x.replace(/\bfill\s*=\s*["'][^"']*["']/gi,Ft=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Ft)?Ft:`fill="url(#${Mt})"`),x=x.replace(/fill\s*:\s*[^;"')]+/gi,Ft=>/fill\s*:\s*(none|transparent)/i.test(Ft)?Ft:`fill:url(#${Mt})`)}}const gt=(Mt,Gt,Pt=1)=>{const Nt=(Mt.stops||[]).map(te=>{const re=te.offset!==void 0?te.offset:te.pos??0,oe=this.normalizeOpacity(te.opacity??100)*Pt;return`<stop offset="${re*100}%" stop-color="${te.color||"#000"}" stop-opacity="${oe}"/>`}).join(""),Ft=(te,re,oe=.5)=>Array.isArray(te)?te[re]??oe:te&&typeof te=="object"?te[re===0?"x":"y"]??oe:oe;if(Mt.type==="LinearGradient"||Mt.type==="Linear"){const te=Ft(Mt.start,0,0)*100,re=Ft(Mt.start,1,0)*100,oe=Ft(Mt.end,0,1)*100,$e=Ft(Mt.end,1,1)*100;return`<linearGradient id="${Gt}" x1="${te}%" y1="${re}%" x2="${oe}%" y2="${$e}%" gradientUnits="objectBoundingBox">${Nt}</linearGradient>`}const fe=Ft(Mt.center,0,.5)*100,ue=Ft(Mt.center,1,.5)*100,Ee=(Mt.radius??.5)*100;return`<radialGradient id="${Gt}" cx="${fe}%" cy="${ue}%" r="${Ee}%" gradientUnits="objectBoundingBox">${Nt}</radialGradient>`},ut=(Mt,Gt)=>/<defs>/i.test(Mt)?Mt.replace(/<defs>/i,`<defs>${Gt}`):Mt.replace(/(<svg[^>]*>)/i,`$1<defs>${Gt}</defs>`);if(V&&V.isEnabled!==!1&&(V.width||0)>0){const Mt=ht?1:this.normalizeOpacity(V.opacity??100),Gt=ht?"#FFFFFF":V.color||(G==null?void 0:G.color)||"#000000";let Pt="";const Nt=V.fill;if(Nt&&Nt.type){if(Nt.type==="Solid")Pt=Nt.color||V.color||"#000000";else if(Nt.type==="LinearGradient"||Nt.type==="RadialGradient"||Nt.type==="Linear"||Nt.type==="Radial"){const ee="exode-stroke";x=ut(x,gt(Nt,ee,Mt)),Pt=`url(#${ee})`}}Pt||(Pt=Gt),x.match(/\bstroke\s*=\s*["']/i)?x=x.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,ee=>/stroke\s*=\s*["']\s*(none|transparent)\s*["']/i.test(ee)?ee:`stroke="${Pt}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke="${Pt}"`),x=x.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),`stroke:${Pt}`);let Ft=a.width||l||100,fe=a.height||f||100;const ue=K.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(ue){const ee=parseFloat(ue[1]),ge=parseFloat(ue[2]);!isNaN(ee)&&!isNaN(ge)&&(Ft=ee,fe=ge)}const Ee=Math.max(.001,l/Ft),te=Math.max(.001,f/fe),re=(Ee+te)/2,oe=(V.width||1)/re;x.match(/\bstroke-width\s*=\s*["']/i)?x=x.replace(/\bstroke-width\s*=\s*["'][^"']*["']/gi,`stroke-width="${oe}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-width="${oe}"`),x=x.replace(/stroke-width\s*:\s*[^;"')]+/gi,`stroke-width:${oe}`),x.match(/\bstroke-opacity\s*=\s*["']/i)?x=x.replace(/\bstroke-opacity\s*=\s*["'][^"']*["']/gi,`stroke-opacity="${Mt}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-opacity="${Mt}"`),x=x.replace(/stroke-opacity\s*:\s*[^;"')]+/gi,`stroke-opacity:${Mt}`);const $e=V.lineCap||"round";x.match(/\bstroke-linecap\s*=\s*["']/i)?x=x.replace(/\bstroke-linecap\s*=\s*["'][^"']*["']/gi,`stroke-linecap="${$e}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linecap="${$e}"`),x=x.replace(/stroke-linecap\s*:\s*[^;"')]+/gi,`stroke-linecap:${$e}`);const Be=V.lineJoin||"round";x.match(/\bstroke-linejoin\s*=\s*["']/i)?x=x.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${Be}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linejoin="${Be}"`),x=x.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${Be}`);const We=V.trimStart??0,xe=V.trimEnd??1,Ye=V.trimOffset??0,De=V.dashOffset??0,Ve=We!==0||xe!==1||Ye!==0||De!==0;if(Ve){const ee=Math.max(0,Math.min(1,We)),ge=Math.max(0,Math.min(1,xe));this.frameCount%600===0&&this.debugLog(`SVG Trim - Object: ${s.name||s.id}, Start: ${ee}, End: ${ge}`);const Ce=(Ft+fe)*2,Xe=(Ye%1+1)%1,Ne=(De%1+1)%1;let Ie="",we=0;if(ee>=ge)Ie=`0 ${Ce}`,we=0;else{const et=Ce*(ge-ee),it=Ce-et;we=-(Ce*(ee+Xe+Ne)),Ie=`${et} ${it}`}x.match(/\bstroke-dasharray\s*=/i)?x=x.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${Ie}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dasharray="${Ie}"`),x=x.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${Ie}`),x.match(/\bstroke-dashoffset\s*=/i)?x=x.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${we}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dashoffset="${we}"`),x=x.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${we}`)}else if(V.dashArray&&V.dashArray.length>0){const ee=V.dashArray.join(" ");if(x=x.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${ee}"`),x=x.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${ee}`),V.dashOffset){const ge=(Ft+fe)*2,Ce=-(V.dashOffset*ge);x=x.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${Ce}"`),x=x.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${Ce}`)}}if(!/\bstroke\s*=\s*["']/i.test(K)&&!new RegExp("(?<![a-z-])stroke\\s*:","i").test(K)){let ee="",ge="";if(Ve){const Ie=a.width||l||100,we=a.height||f||100,et=(Ie+we)*2,it=Math.max(0,Math.min(1,We)),nt=Math.max(0,Math.min(1,xe)),dt=(Ye%1+1)%1,Wt=(De%1+1)%1;if(it>=nt)ee=` stroke-dasharray="0 ${et}"`,ge=' stroke-dashoffset="0"';else{const xt=et*(nt-it),Ut=et-xt,de=-(et*(it+dt+Wt));ee=` stroke-dasharray="${xt} ${Ut}"`,ge=` stroke-dashoffset="${de}"`}}else(mt=V.dashArray)!=null&&mt.length&&(ee=` stroke-dasharray="${V.dashArray.join(" ")}"`,V.dashOffset&&(ge=` stroke-dashoffset="${V.dashOffset}"`));const Ce=` stroke-linecap="${V.lineCap||"round"}"`,Xe=` stroke-linejoin="${V.lineJoin||"round"}"`,Ne=`stroke="${Pt}" stroke-width="${oe}" stroke-opacity="${Mt}"${Ce}${Xe}${ee}${ge}`;x=x.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(Ie,we,et)=>`${we}${et}<g ${Ne}>`),x=x.replace(/<\/svg>/i,"</g></svg>")}}else V&&V.isEnabled===!1&&(x=x.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,'stroke="none"'),x=x.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),"stroke:none"));const he=new Blob([x],{type:"image/svg+xml"}),ne=URL.createObjectURL(he);Xt.onload=()=>{if(URL.revokeObjectURL(ne),this.frameCount%900===0){const Mt=this.imageCache.get(jt);Mt&&this.debugLog(`SVG Payload Ready: ${s.name||s.id} (${Mt.naturalWidth}x${Mt.naturalHeight})`)}},Xt.onerror=()=>{URL.revokeObjectURL(ne),this.debugLog(`SVG Error: Failed to load payload for ${s.name||s.id}`)},Xt.src=ne,this.imageCache.set(jt,Xt)}let yt=null;if(Xt.complete&&Xt.naturalWidth>0?(yt=Xt,this.lastValidSvgImgMap.set(s.id,Xt)):yt=this.lastValidSvgImgMap.get(s.id)||null,yt&&yt.complete&&yt.naturalWidth>0){const x=Math.max(1,l),wt=Math.max(1,f);if(ht&&(G==null?void 0:G.type)==="Solid"){this.maskBuffer||(this.maskBuffer=document.createElement("canvas"),this.maskCtx=this.maskBuffer.getContext("2d")),this.maskBuffer.width=x,this.maskBuffer.height=wt,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,x,wt),this.maskCtx.drawImage(yt,0,0,x,wt),this.maskCtx.globalCompositeOperation="source-in";const Vt=G.color||"#000000",lt=this.normalizeOpacity(G.opacity??100);this.maskCtx.fillStyle=Vt,this.maskCtx.globalAlpha=lt,this.maskCtx.fillRect(0,0,x,wt),t.drawImage(this.maskBuffer,-x/2,-wt/2,x,wt)}else u!==0?(t.save(),this.drawRoundRect(t,-x/2,-wt/2,x,wt,u),t.clip(),t.drawImage(yt,-x/2,-wt/2,x,wt),t.restore()):t.drawImage(yt,-x/2,-wt/2,x,wt)}}}else if(g.type==="LineGraph"||s.type==="LineGraph"||this.isLineGraphObject(s))this.renderLineGraph(t,s,g,l,f);else if(s.type==="Shape"){if(this.applyPath(t,g,l,f,u),t.save(),r.blur&&r.blur.amount>0&&(t.filter=`blur(${r.blur.amount}px)`),se&&ie==="BackgroundBlur")if(e)t.fillStyle="#000000",t.globalAlpha=1,this.applyPath(t,g,l,f,u),t.fill();else{if(t.shadowColor&&t.shadowColor!=="rgba(0, 0, 0, 0)"&&t.shadowColor!=="transparent"){const G=t.getTransform(),V=t.shadowOffsetX,Q=t.shadowOffsetY;t.shadowOffsetX=V+1e4*G.a,t.shadowOffsetY=Q+1e4*G.b,t.save(),t.translate(-1e4,0),this.applyPath(t,g,l,f,u),t.fillStyle="white",t.fill(),t.restore(),t.shadowOffsetX=V,t.shadowOffsetY=Q,t.shadowColor="transparent"}this.applyBackgroundBlurGlass(t,g,l,f,u,Jt,r)}else if(r.fill){const ot=t.globalAlpha;if(((St=r.fill)==null?void 0:St.type)==="Image"&&(r.fill.originalSrc||r.fill.src)){const G=r.fill.originalSrc||r.fill.src;let V=this.imageCache.get(G);V||(V=new Image,V.src=G,this.imageCache.set(G,V)),V.complete&&V.naturalWidth>0&&(t.save(),this.applyPath(t,g,l,f,u),t.clip(),this.renderFittedImage(t,V,-l/2,-f/2,l,f,r.fill.fillMode),t.restore())}else{const G=this.createCanvasFill(t,r.fill,l,f);t.fillStyle=G||(typeof r.fill=="string"?r.fill:r.fill.color||"transparent"),t.globalAlpha=ot*this.normalizeOpacity(r.fill.opacity??100),this.applyPath(t,g,l,f,u),t.fill()}t.globalAlpha=ot}t.restore(),r.stroke&&r.stroke.width>0&&(this.applyPath(t,g,l,f,u),this.applyStrokeAlignment(t,r,g,l,f,u))}else if(s.type==="Frame"||s.type==="Component"&&!s.variant||s.type==="Group"&&!s.isStructuralGroup){const K=i.width??a.width??s.width??l,ot=i.height??a.height??s.height??f,G=u;if(t.save(),t.beginPath(),this.drawRoundRect(t,-K/2,-ot/2,K,ot,G),se&&ie==="BackgroundBlur")if(e)t.fillStyle="#000000",t.globalAlpha=1,t.beginPath(),this.drawRoundRect(t,-K/2,-ot/2,K,ot,G),t.fill();else{if(t.shadowColor&&t.shadowColor!=="rgba(0, 0, 0, 0)"&&t.shadowColor!=="transparent"){const tt=t.getTransform(),ht=t.shadowOffsetX,Et=t.shadowOffsetY;t.shadowOffsetX=ht+1e4*tt.a,t.shadowOffsetY=Et+1e4*tt.b,t.save(),t.translate(-1e4,0),t.beginPath(),this.drawRoundRect(t,-K/2,-ot/2,K,ot,G),t.fillStyle="white",t.fill(),t.restore(),t.shadowOffsetX=ht,t.shadowOffsetY=Et,t.shadowColor="transparent"}this.applyBackgroundBlurGlass(t,g,K,ot,G,Jt,r)}else if(r.fill&&r.fill.type!=="None"){const Q=t.globalAlpha;if(((pt=r.fill)==null?void 0:pt.type)==="Image"&&(r.fill.originalSrc||r.fill.src)){const tt=r.fill.originalSrc||r.fill.src;let ht=this.imageCache.get(tt);ht||(ht=new Image,ht.src=tt,this.imageCache.set(tt,ht)),ht.complete&&ht.naturalWidth>0&&(t.save(),t.beginPath(),this.drawRoundRect(t,-K/2,-ot/2,K,ot,G),t.clip(),this.renderFittedImage(t,ht,-K/2,-ot/2,K,ot,r.fill.fillMode),t.restore())}else{const tt=this.createCanvasFill(t,r.fill,K,ot);t.fillStyle=tt||r.fill.color||"transparent",t.globalAlpha=Q*this.normalizeOpacity(r.fill.opacity??100),t.beginPath(),this.drawRoundRect(t,-K/2,-ot/2,K,ot,G),t.fill(),t.globalAlpha=Q}}if(t.restore(),!e&&(se&&ie==="BackgroundBlur"||r.fill&&r.fill.type!=="None")&&(t.shadowColor="transparent"),r.stroke&&r.stroke.width>0&&r.stroke.isEnabled!==!1){const Q={type:"Rectangle"};t.beginPath(),this.drawRoundRect(t,-K/2,-ot/2,K,ot,G),this.applyStrokeAlignment(t,r,Q,K,ot,G)}}else s.type==="Group"&&s.isStructuralGroup||(s.type==="Component"&&s.variant==="inputbox"?this.renderInputBox(t,s):s.type==="Button"||s.type==="Component"&&(s.variant==="button"||(s.name||"").toLowerCase().includes("button")||(s.name||"").toLowerCase().includes("cta"))?this.renderButton(t,s):s.type==="Component"&&s.variant==="toggle_button"?this.renderToggleButton(t,s):s.type==="Toggle"||s.type==="Component"&&s.variant==="toggle"?this.renderToggle(t,s):s.type==="Slider"||s.type==="Component"&&s.variant==="slider"?this.renderSlider(t,s):s.type==="Dropdown"||s.type==="Component"&&s.variant==="dropdown"?this.renderDropdown(t,s):s.type==="ListView"||s.type==="Component"&&s.variant==="listview"?this.renderListView(t,s):s.type==="Checkbox"||((kt=s.geometry)==null?void 0:kt.type)==="Checkbox"||s.type==="Component"&&s.variant==="checkbox"?this.renderCheckbox(t,s):s.type==="RadioGroup"||s.type==="Component"&&s.variant==="radiogroup"?this.renderRadioGroup(t,s):s.type==="BarChart"||s.type==="Component"&&s.variant==="barchart"?this.renderBarChart(t,s):s.type==="PieChart"||s.type==="Component"&&s.variant==="piechart"?this.renderPieChart(t,s):s.type==="Joystick"||s.type==="Component"&&s.variant==="joystick"?this.renderJoystick(t,s):this.frameCount%300===0&&this.warn("[Engine] Unhandled object type in renderObject:",s.type,"Geo:",(Bt=s.geometry)==null?void 0:Bt.type));if(e||(this.applyInnerGlowOverlay(t,s,g,l,f,u,r),this.applyArtEffectOverlay(t,s,g,l,f,u)),Ct&&Ct.enabled&&t.restore(),s.children&&s.children.length>0){const ot=s.type==="Frame",G=s.clipsContent!==void 0?s.clipsContent:s.clipContent!==void 0?s.clipContent:ot;if(t.save(),G){t.beginPath();const Q=i.width??(a==null?void 0:a.width)??s.width??0,tt=i.height??(a==null?void 0:a.height)??s.height??0,ht=i.cornerRadius??(a==null?void 0:a.corner_radius)??s.cornerRadius??0;this.drawRoundRect(t,-Q/2,-tt/2,Q,tt,ht),t.clip()}let V=0;for(s.children.forEach(Q=>{const tt=o.get(Q);if(!tt)return;const ht=this.objectStates.get(Q),Et=(ht==null?void 0:ht.geometry)||tt.geometry;if(Et&&Et.isMask&&(ht==null?void 0:ht.visible)!==!1){const Yt=Et.width||0,jt=Et.height||0;this.applyObjectTransform(t,Q);const Xt=(ht==null?void 0:ht.corner_radius)??(Et==null?void 0:Et.corner_radius)??0;this.applyPath(t,Et,Yt,jt,Xt),t.clip(),V++}else this.renderObject(t,tt,o,e)});V>0;)t.restore(),V--;t.restore()}if(pe){this.maskCtx.restore(),(i.masks||(s.maskedBy?[{maskId:s.maskedBy,inverted:s.maskInverted===!0,type:s.maskType||"alpha",opacity:s.maskOpacity!==void 0?s.maskOpacity/100:1,feather:s.maskFeather||0,isVisible:!0}]:[])).filter(V=>V.isVisible!==!1&&o.has(V.maskId)).forEach(V=>{var Xt,yt,x,wt,Vt,lt;const Q=o.get(V.maskId),tt=this.objectStates.get(Q.id),ht=V.feather||0,Et=V.inverted===!0,Yt=V.opacity!==void 0?typeof V.opacity=="number"?V.opacity:V.opacity/100:1;if((V.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,Q.id,o),ht>0&&(this.lumaCtx.filter=`blur(${ht}px)`),this.lumaCtx.globalAlpha=Yt;const gt=(tt==null?void 0:tt.width)||Q.geometry.width||0,ut=(tt==null?void 0:tt.height)||Q.geometry.height||0,he=(tt==null?void 0:tt.corner_radius)??Q.corner_radius??0;if(((Xt=Q.geometry)==null?void 0:Xt.type)==="Text"){const Pt=tt!=null&&tt.geometry?this.deepMerge(Q.geometry,tt.geometry):Q.geometry,Nt=tt!=null&&tt.style?this.deepMerge(Q.style,tt.style):Q.style;this._renderText(this.lumaCtx,Q,{...Pt,width:gt,height:ut,corner_radius:he},Nt,tt,gt,ut,!0,!1)}else if(((yt=Q.geometry)==null?void 0:yt.type)==="Image"){const Pt=Q.geometry.src;if(Pt){let Nt=this.imageCache.get(Pt);Nt||(Nt=new Image,Nt.src=Pt,this.imageCache.set(Pt,Nt)),Nt.complete&&Nt.naturalWidth>0?this.lumaCtx.drawImage(Nt,-gt/2,-ut/2,gt,ut):(this.applyPath(this.lumaCtx,Q.geometry,gt,ut,he),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else if(((x=Q.geometry)==null?void 0:x.type)==="SVG"){const Pt=Q.geometry.svgContent;if(Pt){const Nt=`__lumamask_${Q.id}`;let Ft=this.imageCache.get(Nt);if(!Ft){Ft=new Image;const fe=new Blob([Pt],{type:"image/svg+xml"});Ft.src=URL.createObjectURL(fe),Ft.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(Nt,Ft)}Ft.complete&&Ft.naturalWidth>0?this.lumaCtx.drawImage(Ft,-gt/2,-ut/2,gt,ut):(this.applyPath(this.lumaCtx,Q.geometry,gt,ut,he),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else this.applyPath(this.lumaCtx,Q.geometry,gt,ut,he),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill();this.lumaCtx.restore();const ne=this.maskCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight),Mt=this.lumaCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight).data,Gt=ne.data;for(let Pt=0;Pt<Gt.length;Pt+=4){const Nt=Mt[Pt],Ft=Mt[Pt+1],fe=Mt[Pt+2];let ue=(.299*Nt+.587*Ft+.114*fe)/255;Et&&(ue=1-ue),Gt[Pt+3]*=ue}this.maskCtx.putImageData(ne,0,0)}else{this.maskCtx.save(),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),this.maskCtx.globalCompositeOperation=Et?"destination-out":"destination-in",ht>0&&(this.maskCtx.filter=`blur(${ht}px)`),this.maskCtx.globalAlpha=Yt,this.applyAbsoluteTransform(this.maskCtx,Q.id,o);const gt=(tt==null?void 0:tt.width)||Q.geometry.width||0,ut=(tt==null?void 0:tt.height)||Q.geometry.height||0,he=(tt==null?void 0:tt.corner_radius)??Q.corner_radius??0;if(((wt=Q.geometry)==null?void 0:wt.type)==="Text"){const ne=tt!=null&&tt.geometry?this.deepMerge(Q.geometry,tt.geometry):Q.geometry,Mt=tt!=null&&tt.style?this.deepMerge(Q.style,tt.style):Q.style;this._renderText(this.maskCtx,Q,{...ne,width:gt,height:ut,corner_radius:he},Mt,tt,gt,ut,!0,!1)}else if(((Vt=Q.geometry)==null?void 0:Vt.type)==="Image"){const ne=Q.geometry.src;if(ne){let Mt=this.imageCache.get(ne);Mt||(Mt=new Image,Mt.src=ne,this.imageCache.set(ne,Mt)),Mt.complete&&Mt.naturalWidth>0?this.maskCtx.drawImage(Mt,-gt/2,-ut/2,gt,ut):(this.applyPath(this.maskCtx,Q.geometry,gt,ut,he),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else if(((lt=Q.geometry)==null?void 0:lt.type)==="SVG"){const ne=Q.geometry.svgContent;if(ne){const Mt=`__alphamask_${Q.id}`;let Gt=this.imageCache.get(Mt);if(!Gt){Gt=new Image;const Pt=new Blob([ne],{type:"image/svg+xml"});Gt.src=URL.createObjectURL(Pt),Gt.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(Mt,Gt)}Gt.complete&&Gt.naturalWidth>0?this.maskCtx.drawImage(Gt,-gt/2,-ut/2,gt,ut):(this.applyPath(this.maskCtx,Q.geometry,gt,ut,he),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else this.applyPath(this.maskCtx,Q.geometry,gt,ut,he),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill();this.maskCtx.restore()}}),ae.save(),ae.setTransform(1,0,0,1,0,0);const G=s.maskBlendMode||s.blendMode;G&&G!=="Normal"&&(ae.globalCompositeOperation=G.toLowerCase()),ae.drawImage(this.maskBuffer,0,0),ae.restore(),ae.restore()}else t.restore()}}applyOuterGlowUnderlay(t,s,o,e,n,i,a,r){var I,E,_;const l=a||s.style||{},f=l.effect,p=l.effects||(f?[f]:[]),u=p.find(T=>T.isEnabled!==!1&&T.type==="Glow"&&(T.mode==="outer"||T.mode==="Outer Glow"||!T.mode));if(!u)return;const g=u.blur||10,h=1e4;let d=u.color||"white";(E=(I=this.artboard)==null?void 0:I.tokens)!=null&&E.colors&&this.artboard.tokens.colors[d]&&(d=this.artboard.tokens.colors[d]),t.save();const w=l.fill&&l.fill.type!=="None",y=p.some(T=>T.isEnabled!==!1&&T.type==="BackgroundBlur"),c=s.type==="Text",v=s.type==="Group";!c&&!v&&(w||y)&&(t.beginPath(),t.rect(-1e6,-1e6,2e6,2e6),s.type==="Frame"||s.type==="Component"?this.drawRoundRect(t,-e/2,-n/2,e,n,i):this._tracePath(t,o,e,n,i),t.clip("evenodd"));const b=t.getTransform();t.shadowColor=d,t.shadowBlur=g,t.shadowOffsetX=h*b.a,t.shadowOffsetY=h*b.b,t.translate(-h,0);let S="black";l.fill&&l.fill.type!=="None"&&(S=this.createCanvasFill(t,l.fill,e,n)||l.fill.color||"black");let C="black";l.stroke&&l.stroke.width>0&&(C=this.createCanvasFill(t,l.stroke.fill||{type:"Solid",color:l.stroke.color},e,n)||l.stroke.color||"black"),t.fillStyle=S,t.strokeStyle=C,t.lineWidth=((_=l.stroke)==null?void 0:_.width)||0;const M=Math.min(u.intensity||1,10);for(let T=0;T<M;T++)if(r)this.renderObject(t,s,r,!0,!0);else if(o.type==="Text")l.fill&&l.fill.type!=="None"&&t.fillText(s.text||"",0,0),l.stroke&&l.stroke.width>0&&t.strokeText(s.text||"",0,0);else if(o.points&&o.type==="Path")this.applyPath(t,o,e,n,i),l.fill&&l.fill.type!=="None"&&t.fill(),l.stroke&&l.stroke.width>0&&t.stroke();else{if(t.beginPath(),o.type==="circle"||o.type==="Ellipse"){const Y=e/2,L=n/2;t.ellipse(0,0,Y,L,0,0,Math.PI*2)}else i!==0?this.drawRoundRect(t,-e/2,-n/2,e,n,i):t.rect(-e/2,-n/2,e,n);const A=l.fill&&l.fill.type!=="None",R=l.stroke&&l.stroke.width>0;(A||!A&&!R)&&t.fill(),R&&t.stroke()}t.restore()}_renderText(t,s,o,e,n,i,a,r=!1,l=!1){var rt,It,mt,St,pt,kt,Bt,vt,Dt;let f=(o==null?void 0:o.text)||(s==null?void 0:s.text)||(s==null?void 0:s.name)||"";if(o.textInputId&&!r){const Z=this.inputs.get(o.textInputId);Z!==void 0&&(f=String(Z),n.geometry&&n.geometry.type==="Text"&&(n.geometry.text=f))}if(o.svgPath){const Z=o.svgPath;t.save();const ft=((rt=e==null?void 0:e.fill)==null?void 0:rt.color)||"#000000",Tt=((It=e==null?void 0:e.fill)==null?void 0:It.opacity)!==void 0?(mt=e==null?void 0:e.fill)==null?void 0:mt.opacity:1;t.fillStyle=ft,t.globalAlpha*=Tt;const Ot=new Path2D(Z);t.fill(Ot),t.restore();return}let p=f||"";o.enableSegments===!0&&o.segments&&Array.isArray(o.segments)&&(p=o.segments.map(Z=>Z&&Z.text?Z.text:"").join(""));const u=o.textCase||"none";u==="uppercase"?p=p.toUpperCase():u==="lowercase"?p=p.toLowerCase():u==="capitalize"&&(p=p.replace(/\b\w/g,Z=>Z.toUpperCase()));let g=((St=o.fontWeight)==null?void 0:St.toString())||"400",h=o.fontStyle||"normal";g.toLowerCase().includes("italic")&&(h="italic",g=g.replace(/italic/gi,"").trim()||"400");const d=this.mapFontWeight(g),w=Math.max(1,o.fontSize||32);let y=o.fontFamily||"Inter";const c=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];c.forEach(Z=>{const ft=new RegExp(`[\\s-]${Z}$`,"i");ft.test(y)&&(y=y.replace(ft,"").trim())});const v=o.smallCaps===!0,S=`${v?"small-caps ":""}${h} ${d} ${w}px "${y}", sans-serif`;t.font=S;const C=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*w:Z.value}t.letterSpacing!==void 0&&(t.letterSpacing=`${I}px`);const E=o.kerning||"auto",_=o.kerningValue||0;E==="manual"&&_!==0&&(t.letterSpacing=`${I+_}px`);const T=o.paragraphSpacing||0;let A=o.lineHeight??1.2;typeof A=="string"&&(A=parseFloat(A)),A>5&&w>0&&(A=A/w);const R=(A||1.2)*w,Y=o.isPointText===!0||!o.width||o.width<=0,L=((pt=o.padding)==null?void 0:pt.left)||((kt=o.padding)==null?void 0:kt.right)||0,D=Y?1e5:o.width&&o.width>0?Math.ceil(o.width)-L*2:1e5;o.autoHeight;const P=ts({text:p,fontFamily:y,fontSize:w,fontWeight:d,fontStyle:h,lineHeight:A,width:D,letterSpacing:I,paragraphSpacing:T,paragraphIndent:o.paragraphIndent||0,segments:o.segments,enableSegments:o.enableSegments,textCase:u,hyphenation:o.hyphenation,composer:o.composer,balanceRaggedLines:o.balanceRaggedLines}),k=P.lines||[],O=P.maxFontSize||w,$=this.fontLeadingFactors[y]??.5,X=(R-w)*$;let F=P.height,B=i,j=a;if(B===0||j===0||B>=1e5||Y){let Z=0,ft=0;const Tt=P.fullText||p;(k||[]).forEach(Ot=>{const _t=Ot.text||"",Rt=t.measureText(_t).width+(_t.length>0?(_t.length-1)*I:0);Rt>Z&&(Z=Rt),ft+=_t.length,ft<Tt.length&&(Tt[ft]===`
8
- `||Tt[ft]==="\r")&&(ft++,Tt[ft-1]==="\r"&&Tt[ft]===`
9
- `&&ft++)}),(B===0||B>=1e5)&&(B=Z),j===0&&(j=F||0)}let z=-F/2;a>0&&a>F&&(C==="top"?z=-a/2:C==="middle"||C==="center"?z=-F/2:C==="bottom"&&(z=a/2-F));const q=C==="top"&&a>0?0:X;let U=z+q+X,J=null,W=0;if(o.pathId&&this.artboard){const Z=this.artboard.objects.find(ft=>ft.id===o.pathId);if(Z&&Z.type==="Shape"&&((Bt=Z.geometry)==null?void 0:Bt.type)==="Path"){const ft=this.objectStates.get(Z.id),Tt=ft!=null&&ft.geometry?this.deepMerge(Z.geometry,ft.geometry):Z.geometry,Ot=(ft==null?void 0:ft.scale_x)!==void 0?(Z.width||0)*ft.scale_x:Z.width||0,_t=(ft==null?void 0:ft.scale_y)!==void 0?(Z.height||0)*ft.scale_y:Z.height||0;J={geo:Tt,obj:Z,w:Ot,h:_t},W=this.getPerimeter(Tt,Ot,_t)}}const N=(Z,ft)=>{var Ot,_t;if(!I&&!v&&!r&&(!o.enableSegments||!((Ot=o.segments)!=null&&Ot.length)))return t.measureText(Z).width;let Tt=0;for(let Rt=0;Rt<Z.length;Rt++){const $t=ft+Rt;let Ht=0;if(o.enableSegments===!0&&((_t=o.segments)==null?void 0:_t.length)>0){let zt=0,qt=null;for(const Jt of o.segments){if($t<zt+(Jt.text||"").length){qt=Jt;break}zt+=(Jt.text||"").length}if(qt){t.save();let Jt=qt.fontFamily||o.fontFamily||"Inter";const se=this.mapFontWeight((qt.fontWeight||o.fontWeight||"400").toString()),ie=qt.fontStyle||h,Se=qt.fontSize||w;t.font=`${ie} ${se} ${Se}px "${Jt}", sans-serif`,Ht=t.measureText(Z[Rt]).width,t.restore()}else Ht=t.measureText(Z[Rt]).width}else Ht=t.measureText(Z[Rt]).width;Tt+=Ht+I}return Tt-(Z.length>0?I:0)},H=(Z,ft,Tt,Ot,_t)=>{var Se,Pe;const $t=(_t===0||p[_t-1]===`
10
- `||p[_t-1]==="\r")&&o.paragraphIndent?o.paragraphIndent:0,Ht=(!r||l)&&(s.behaviors||[]).some(me=>me.enabled&&(me.type.toString().includes("Text")||["Typewriter","Scramble","Wave","Bounce","GlitchText","Reveal3D","RevealSlide","RevealBlur"].includes(me.type))),zt=!o.pathId&&!Ht&&(o.enableSegments!==!0||!o.segments||o.segments.length===0),qt=o.baselineShift||0,Jt=Tt+qt,se=N(Z,_t);let ie=ft+$t;if(M==="center"?ie-=se/2:M==="right"&&(ie-=se),zt){t.font=S;const me=t.textAlign;t.textAlign="left",Ot?t.strokeText(Z,ie,Jt):t.fillText(Z,ie,Jt),t.textAlign=me}else{const me=t.textAlign;t.textAlign="left";const _e=_t+Z.length>=p.length||p[_t+Z.length]===`
11
- `||p[_t+Z.length]==="\r";let Me=0,Zt=0;const Le=o.justifyMinWordSpacing,Re=o.justifyMaxWordSpacing;if(M==="justify"&&!_e&&se>0&&!o.pathId){const pe=Y?se:D-L*2+0,bt=Math.max(0,pe-se);for(let at=0;at<Z.length;at++)Z[at]===" "&&Zt++;if(Zt>0){const at=t.measureText(" ").width;let Ct=Le||at*.5,K=Re||at*2.5;Me=Math.max(0,Math.min(bt/Zt,K-Ct))}}let ve=o.pathOffset||0;o.pathId&&W>0&&J&&(M==="center"?ve+=W/2-se/2:M==="right"&&(ve+=W-se));let ae=ie;const Oe=r&&!l?[]:((Se=s.behaviors)==null?void 0:Se.filter(pe=>[st.Typewriter,st.Scramble,st.Wave,st.Bounce,st.GlitchText,st.TextTrail,st.Reveal3D,st.RevealSlide,st.RevealBlur,st.TextLiquid,st.TextVortex,st.TextExplosion,st.TextRain,st.TextGravity,st.TextElastic,st.TextMatrix,st.TextNeon,st.TextGlitch3D,st.TextDissolve,st.TextOrganic,st.TextBreathe,st.TextFloral,st.TextSmoke,st.TextVariable,st.TextMagnet,st.TextSpin,st.TextZing,st.TextPerspective,st.TextMirror].includes(pe.type)&&pe.enabled))||[];for(let pe=0;pe<Z.length;pe++){let bt=Z[pe];const at=_t+pe;let Ct=0,K=0,ot=1,G=1,V=0,Q=1,tt=bt;Oe.forEach(yt=>{const x=yt.settings||{},wt=x.strength||1,Vt=Date.now();if(yt.type===st.Typewriter)this.currentTime*(x.speed||1)-at*(x.stagger||.05)<0&&(Q=0);else if(yt.type===st.Scramble)Math.max(0,Math.min(1,this.currentTime/(x.duration||1.5))-at*.02)<1&&Math.random()<.3&&(tt="$%#@!*&"[Math.floor(Math.random()*7)]);else if(yt.type===st.Wave)K+=Math.sin(this.currentTime*5*(x.speed||1)+at*(x.frequency||1))*(x.amplitude||20)*wt;else if(yt.type===st.Bounce){const lt=Math.max(0,this.currentTime%2-at*(x.stagger||.1));lt<1&&(K-=Math.abs(Math.sin(lt*Math.PI))*(x.height||50)*wt)}else if(yt.type===st.TextTrail){const lt=this.pointerHistory[Math.max(0,this.pointerHistory.length-1-at*(x.delay||5))];lt&&(Ct+=(lt.x-(n.x+ae))*wt*.2,K+=(lt.y-(n.y+Tt+K))*wt*.2)}else if(yt.type===st.Reveal3D){const lt=Math.max(0,Math.min(1,this.currentTime*(x.speed||1)-at*(x.stagger||.1)));ot*=lt,G*=lt,Q=lt}else if(yt.type===st.RevealSlide){const lt=Math.max(0,Math.min(1,this.currentTime*1.5-at*.05)),gt=(1-lt)*(x.distance||40)*wt,ut=x.direction||"up";ut==="up"?K-=gt:ut==="down"?K+=gt:ut==="left"?Ct-=gt:ut==="right"&&(Ct+=gt),Q=lt}else if(yt.type===st.RevealBlur){const lt=Math.max(0,Math.min(1,this.currentTime*1.2-at*.1));Q=lt,Ct+=(1-lt)*5}else if(yt.type===st.TextLiquid){const lt=Math.max(0,Math.sin(Vt*.001*(x.speed||1)+at*.5));K+=lt*(x.amplitude||10)*wt,G*=1+lt*.2}else if(yt.type===st.TextVortex){const lt=Vt*.002*(x.speed||1)+at*.2,gt=(1-(Math.sin(Vt*.001)*.5+.5))*(x.radius||50);Ct+=Math.cos(lt)*gt*wt,K+=Math.sin(lt)*gt*wt}else if(yt.type===st.TextExplosion){const lt=x.force||1,gt=this.currentTime%2;if(gt<1){const ut=(at/Z.length-.5)*Math.PI*2,he=gt*100*lt;Ct+=Math.cos(ut)*he*wt,K+=Math.sin(ut)*he*wt,Q=1-gt}}else if(yt.type===st.TextRain){const lt=x.speed||1,gt=x.height||100,ut=(Vt*.001*lt+at*.1)%1;K-=(1-ut)*gt*wt,Q=ut>.1?1:ut*10}else if(yt.type===st.TextGravity){const lt=x.gravity||9.8,gt=this.currentTime%3/3,ut=.5*lt*Math.pow(gt*10,2);ut<100?K+=ut*wt:K+=100*wt}else if(yt.type===st.TextMatrix){const lt=x.speed||1;if(Math.random()<.1*lt){const ut="0123456789ABCDEF!@#$%^&*";tt=ut[Math.floor(Math.random()*ut.length)]}Q=.3+(Math.sin(Vt*.01*lt+at)+1)/2*.7}else if(yt.type===st.TextNeon){const lt=Math.random()>.95?.5:1;Q=(.7+(Math.sin(Vt*.005)+1)/2*.3)*lt}else if(yt.type===st.TextDissolve)Math.sin(at*1.5+Vt*.002*(x.speed||1))>.5&&(Q=0);else if(yt.type===st.TextOrganic){const lt=x.speed||1,gt=x.amplitude||10;Ct+=Math.sin(Vt*.002*lt+at)*gt*wt,K+=Math.cos(Vt*.0015*lt+at*.7)*gt*wt}else if(yt.type===st.TextBreathe){const gt=1+(Math.sin(Vt*.003+at*.2)+1)/2*.2*wt;ot*=gt,G*=gt}else if(yt.type===st.TextSpin){const lt=x.speed||1;V+=Vt*.01*lt+at}else if(yt.type===st.TextMagnet){const lt=this.pointerHistory[this.pointerHistory.length-1];if(lt){const gt=lt.x-(n.x+ae),ut=lt.y-(n.y+Tt);V=Math.atan2(ut,gt)}}else if(yt.type===st.TextPerspective){const lt=Z.length/2,gt=(at-lt)/lt,ut=1-Math.abs(gt)*.3*wt;ot*=ut,G*=ut,Ct+=gt*20*wt}else if(yt.type===st.TextMirror)Q*=.8;else if(yt.type===st.TextFloral){const lt=x.speed||1,gt=x.stagger||.1,ut=(Vt*.001*lt+at*gt)%2;ut<1&&(ot*=ut,G*=ut,V+=ut*Math.PI)}else if(yt.type===st.TextSmoke){const lt=x.speed||1,gt=x.height||50,ut=(Vt*5e-4*lt+at*.2)%1;K-=ut*gt*wt,Ct+=Math.sin(Vt*.002+at)*5*wt,Q=1-ut}else if(yt.type===st.TextVariable){const lt=x.speed||1,gt=x.intensity||1.5,ut=(Math.sin(Vt*.004*lt+at*.3)+1)/2;ot*=1+ut*(gt-1)*wt}else if(yt.type===st.TextZing){const lt=x.speed||2,gt=x.distance||100,ut=(Vt*.002*lt+at*.05)%1;Ct+=(1-ut)*gt*wt,Q=ut}else if(yt.type===st.TextElastic){const lt=x.stiffness||.2,gt=x.damping||.1,ut=Math.sin(Vt*.01)*Math.exp(-Vt*.001*gt);G*=1+ut*lt*wt}else if(yt.type===st.TextGlitch3D){const lt=x.intensity||5;Math.random()<.2&&(Ct+=(Math.random()-.5)*lt,K+=(Math.random()-.5)*lt,Q=.8)}else if(yt.type===st.GlitchText){const lt=x.intensity||5;Math.random()<.1&&(Ct+=(Math.random()-.5)*lt,K+=(Math.random()-.5)*lt,Math.random()<.05&&(Q=.5))}});let ht=null,Et=o.textDecoration||"none",Yt=w;if(o.enableSegments===!0&&((Pe=o.segments)==null?void 0:Pe.length)>0){let yt=0,x=null;for(const wt of o.segments){if(at<yt+(wt.text||"").length){x=wt;break}yt+=(wt.text||"").length}if(x){let wt=x.fontFamily||o.fontFamily||"Inter";c.forEach(gt=>{const ut=new RegExp(`[\\s-]${gt}$`,"i");ut.test(wt)&&(wt=wt.replace(ut,"").trim())});const Vt=this.mapFontWeight((x.fontWeight||o.fontWeight||"400").toString()),lt=x.fontStyle||h;Yt=x.fontSize||w,t.font=`${lt} ${Vt} ${Yt}px "${wt}", sans-serif`,x.fill&&(ht=x.fill),x.textDecoration&&(Et=x.textDecoration),Yt<O&&(K+=(O-Yt)*.85)}}else t.font=S;const jt=t.globalAlpha;t.globalAlpha*=Q,t.save();const Xt=t.measureText(tt).width;if(J&&W>0){const yt=ae-ie+Xt/2,wt=(ve+yt)/W,Vt=this.getPointOnPath(J.geo,J.w,J.h,Math.abs(wt%1)),lt=Vt.angle,gt=Tt+K+(o.pathOffsetY||0),ut=o.pathSide==="right"?-1:1,he=Math.cos(lt+Math.PI/2)*gt*ut,ne=Math.sin(lt+Math.PI/2)*gt*ut;t.translate(Vt.x+he+Ct,Vt.y+ne),t.rotate(lt+V+(ut===-1?Math.PI:0))}else t.translate(ae+Ct+Xt/2,Tt+K),V!==0&&t.rotate(V);if(t.scale(ot,G),ht&&!r&&!l){const yt=this.createCanvasFill(t,ht,B,j);t.fillStyle=yt||ht.color||"#000000"}else if(!r&&!l){const yt=this.createCanvasFill(t,e.fill,B,j);t.fillStyle=yt||e.fill.color||"#000000"}if(Q>0)if(r||l){const yt=l?"#000000":this.createCanvasFill(t,e.fill,B,j);t.fillStyle=yt||e.fill.color||"#ffffff",t.fillText(tt,-Xt/2,0)}else Ot?t.strokeText(tt,-Xt/2,0):t.fillText(tt,-Xt/2,0);Et!=="none"&&!r&&this.drawTextDecoration(t,Et,0,0,Xt,Yt),t.restore(),t.globalAlpha=jt,M==="justify"&&Me>0&&tt===" "&&!_e?ae+=Xt+I+Me:ae+=Xt+I}t.textAlign=me}};if(r){let Z=0,ft=U;(k||[]).forEach(Tt=>{const Ot=Tt.text||"",_t=p.indexOf(Ot,Z);_t!==-1&&(Z=_t);let Rt=-B/2;M==="center"?Rt=0:M==="right"&&(Rt=B/2),H(Ot,Rt,ft,!1,Z),Z+=Ot.length,ft+=R})}else if(l){let Z=0,ft=U;(k||[]).forEach(Tt=>{const Ot=Tt.text||"";let _t=-B/2;M==="center"?_t=0:M==="right"&&(_t=B/2),H(Ot,_t,ft,!1,Z),Z+=Ot.length,Z<p.length&&(p[Z]===`
12
- `||p[Z]==="\r")&&(Z++,p[Z-1]==="\r"&&p[Z]===`
13
- `&&Z++),ft+=R})}else{if(e.fill){const ft=t.globalAlpha,Tt=this.createCanvasFill(t,e.fill,B,j);t.fillStyle=Tt||e.fill.color||"#000000",t.globalAlpha=ft*this.normalizeOpacity(e.fill.opacity??100);const Ot=P.fullText||(o.enableSegments?(o.segments||[]).map($t=>{let Ht=$t.text||"";const zt=$t.textCase||o.textCase||"none";return zt==="uppercase"?Ht.toUpperCase():zt==="lowercase"?Ht.toLowerCase():zt==="capitalize"?Ht.replace(/\b\w/g,qt=>qt.toUpperCase()):Ht}).join(""):p);let _t=0,Rt=U;(k||[]).forEach($t=>{const Ht=$t.text||"";let zt=-B/2;M==="center"?zt=0:M==="right"&&(zt=B/2),H(Ht,zt,Rt,!1,_t),_t+=Ht.length,Rt+=R,_t<Ot.length&&(Ot[_t]===`
14
- `||Ot[_t]==="\r")&&(T>0&&(Rt+=T),_t++,Ot[_t-1]==="\r"&&Ot[_t]===`
15
- `&&_t++)}),t.globalAlpha=ft}const Z=o.paragraphRule;if(Z&&(((vt=Z.top)==null?void 0:vt.width)>0||((Dt=Z.bottom)==null?void 0:Dt.width)>0)){let ft=0;(k||[]).forEach((Tt,Ot)=>{var $t,Ht;const Rt=ft===0||ft<p.length&&(p[ft]===`
16
- `||p[ft]==="\r");if(Rt&&Ot>0&&ft++,Rt){if((($t=Z.top)==null?void 0:$t.width)>0){const zt=U+Ot*R-Z.top.offset;t.strokeStyle=Z.top.color||"#000000",t.lineWidth=Z.top.width,t.beginPath();const qt=-i/2+R*.2;t.moveTo(qt,zt),t.lineTo(i/2-R*.2,zt),t.stroke()}if(((Ht=Z.bottom)==null?void 0:Ht.width)>0){const zt=U+(Ot+1)*R-Z.bottom.offset;t.strokeStyle=Z.bottom.color||"#000000",t.lineWidth=Z.bottom.width,t.beginPath();const qt=-i/2+R*.2;t.moveTo(qt,zt),t.lineTo(i/2-R*.2,zt),t.stroke()}}ft+=(Tt.text||"").length})}if(e.stroke&&e.stroke.width>0){const ft=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;const Ot=t.getTransform(),_t=Math.sqrt(Ot.a*Ot.a+Ot.b*Ot.b)||1,Rt=window.devicePixelRatio||1;t.lineWidth=(e.stroke.width||1)*Rt/_t,t.globalAlpha=ft*this.normalizeOpacity(e.stroke.opacity??100);let $t=0,Ht=U;(k||[]).forEach(zt=>{let qt=-B/2;M==="center"?qt=0:M==="right"&&(qt=B/2),H(zt.text,qt,Ht,!0,$t),$t+=(zt.text||"").length,Ht+=R,$t<p.length&&(p[$t]===`
17
- `||p[$t]==="\r")&&(T>0&&(Ht+=T),$t++,p[$t-1]==="\r"&&p[$t]===`
18
- `&&$t++)}),t.globalAlpha=ft}}}applyStrokeAlignment(t,s,o,e,n,i){if(!s.stroke||s.stroke.width<=0||s.stroke.isEnabled===!1)return;const a=s.stroke,r=t.getTransform(),l=Math.sqrt(r.a*r.a+r.b*r.b)||1,f=window.devicePixelRatio||1,p=(a.width||1)*f/l,u=(a.alignment||"center").toLowerCase();if(t.save(),s.fill&&s.fill.type!=="None"&&s.fill.isEnabled!==!1&&s.fill.opacity!==0&&s.fill.color!=="transparent"&&s.fill.color!=="rgba(0,0,0,0)"&&(t.shadowColor="transparent",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),a.fill){const b=this.createCanvasFill(t,a.fill,e,n);b?t.strokeStyle=b: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=p,t.lineCap=a.lineCap||"round",t.lineJoin=a.lineJoin||"round",a.miterLimit!==void 0&&(t.miterLimit=a.miterLimit);const d=a.trimStart??0,w=a.trimEnd??1,y=a.trimOffset??0,c=a.dashOffset??0,v=a.dashArray||[];if(d!==0||w!==1||y!==0){const b=this.getPerimeter(o,e,n);if(b>0){const S=Math.max(0,Math.min(1,d)),C=Math.max(0,Math.min(1,w));if(S<C){const M=b*(C-S),I=b-M,E=-(b*(S+y%1));t.setLineDash([M,I]),t.lineDashOffset=E-c*b}else if(S===C)t.setLineDash([0,b]);else{const M=b*(1-S+C),I=b-M,E=-(b*S);t.setLineDash([M,I]),t.lineDashOffset=E-c*b}}}else if(v.length>0||c!==0){v.length>0&&t.setLineDash(v);const b=this.getPerimeter(o,e,n);t.lineDashOffset=-(c*b)}if((o==null?void 0:o.type)==="Line"||e===0||n===0)this.applyPath(t,o,e,n,i),t.stroke();else if(u==="inside")t.lineWidth=p*2,t.save(),this.applyPath(t,o,e,n,i),t.clip(),t.stroke(),t.restore();else if(u==="outside"){t.save(),t.beginPath();const b=Math.max(e,n,2e4);t.rect(-b,-b,b*2,b*2),this._tracePath(t,o,e,n,i),t.clip("evenodd"),t.lineWidth=p*2,t.beginPath(),this.applyPath(t,o,e,n,i),t.stroke(),t.restore()}else t.lineWidth=p,this.applyPath(t,o,e,n,i),t.stroke();t.restore()}getPerimeter(t,s,o){switch(this.ensurePathPoints(t),t==null?void 0:t.type){case"Rectangle":return(s+o)*2;case"Ellipse":{const e=Math.abs(s)/2,n=Math.abs(o)/2,i=Math.abs(t.sweepAngle??360),a=t.ratio||0,r=Math.PI*(3*(e+n)-Math.sqrt((3*e+n)*(e+3*n)));if(i>=360&&a<=0)return r;let l=i/360*r;if(a>0){const f=Math.PI*(3*(e*a+n*a)-Math.sqrt((3*e*a+n*a)*(e*a+3*n*a)));l+=i/360*f,i<360&&(l+=2*Math.sqrt((e-e*a)**2+(n-n*a)**2))}else i<360&&(l+=2*Math.max(e,n));return isNaN(l)?0:l}case"Line":return t.length||Math.sqrt(s*s+o*o);case"Triangle":return s+Math.sqrt((s/2)**2+o**2)*2;case"Polygon":{const e=t.sides||3,n=t.radius||Math.min(s,o)/2;return 2*e*n*Math.sin(Math.PI/e)}case"Star":{const e=t.points||5,n=t.outer_radius||Math.min(s,o)/2,i=t.inner_radius||n/2,a=Math.PI/e;return Math.sqrt(n*n+i*i-2*n*i*Math.cos(a))*e*2}case"Path":{const e=t.points||[];if(e.length<2)return t.length||0;let n=0,i=e[0].x,a=e[0].y;for(let r=1;r<e.length;r++){const l=e[r];if(l.moveTo){i=l.x,a=l.y;continue}const f=i,p=a,u=e[r-1].out_x,g=e[r-1].out_y;if(u!==void 0||l.in_x!==void 0?n+=this.getBezierLength(f,p,u??f,g??p,l.in_x??l.x,l.in_y??l.y,l.x,l.y):n+=Math.sqrt((l.x-f)**2+(l.y-p)**2),i=l.x,a=l.y,l.closePath||r===e.length-1&&(t.is_closed||t.isClosed)){const h=i,d=a,w=[...e.slice(0,r+1)].reverse().find(M=>M.moveTo)||e[0],y=w.x,c=w.y,v=e[r].out_x,b=e[r].out_y,S=w.in_x,C=w.in_y;v!==void 0||S!==void 0?n+=this.getBezierLength(h,d,v??h,b??d,S??y,C??c,y,c):n+=Math.sqrt((y-h)**2+(c-d)**2)}}return n}default:return(s+o)*2}}getBezierLength(t,s,o,e,n,i,a,r,l=10){let f=0,p=t,u=s;for(let g=1;g<=l;g++){const h=g/l,d=1-h,w=h*h,y=d*d,c=y*d,v=w*h,b=c*t+3*y*h*o+3*d*w*n+v*a,S=c*s+3*y*h*e+3*d*w*i+v*r,C=b-p,M=S-u;f+=Math.sqrt(C*C+M*M),p=b,u=S}return f}getBezierTAtLength(t,s,o,e,n,i,a,r,l,f=20){if(t<=0)return 0;let p=0,u=s,g=o;for(let h=1;h<=f;h++){const d=h/f,w=1-d,y=d*d,c=w*w,v=c*w,b=y*d,S=v*s+3*c*d*e+3*w*y*i+b*r,C=v*o+3*c*d*n+3*w*y*a+b*l,M=S-u,I=C-g,E=Math.sqrt(M*M+I*I);if(p+E>=t){const _=t-p,T=E===0?0:_/E;return(h-1+T)/f}p+=E,u=S,g=C}return 1}getPointOnPath(t,s,o,e){if(this.ensurePathPoints(t),(t==null?void 0:t.type)==="Path"){const n=t.points||[];if(n.length<2)return{x:0,y:0,angle:0};let i=1/0,a=-1/0,r=1/0,l=-1/0;n.forEach(c=>{typeof c.x=="number"&&typeof c.y=="number"&&(i=Math.min(i,c.x),a=Math.max(a,c.x),r=Math.min(r,c.y),l=Math.max(l,c.y),c.out_x!==void 0&&(i=Math.min(i,c.out_x),a=Math.max(a,c.out_x)),c.out_y!==void 0&&(r=Math.min(r,c.out_y),l=Math.max(l,c.out_y)),c.in_x!==void 0&&(i=Math.min(i,c.in_x),a=Math.max(a,c.in_x)),c.in_y!==void 0&&(r=Math.min(r,c.in_y),l=Math.max(l,c.in_y)))});const f=(i+a)/2,p=(r+l)/2,g=this.getPerimeter(t,s,o)*e;let h=0;const d=[];let w=n[0],y=n[0];for(let c=1;c<n.length;c++){const v=n[c];if(v.moveTo){w=v,y=v;continue}d.push({p0:w,p1:v}),(v.closePath||c===n.length-1&&(t.is_closed||t.isClosed))&&d.push({p0:v,p1:y}),w=v}for(const c of d){const v=c.p0,b=c.p1;let S=0;const C=v.out_x!==void 0||b.in_x!==void 0;if(C?S=this.getBezierLength(v.x,v.y,v.out_x??v.x,v.out_y??v.y,b.in_x??b.x,b.in_y??b.y,b.x,b.y):S=Math.sqrt((b.x-v.x)**2+(b.y-v.y)**2),h+S>=g||c===d[d.length-1]){let M=0;if(C)return M=this.getBezierTAtLength(g-h,v.x,v.y,v.out_x??v.x,v.out_y??v.y,b.in_x??b.x,b.in_y??b.y,b.x,b.y,20),this.getBezierPointAndAngle(M,v,b,f,p);{M=S===0?0:(g-h)/S;const I=v.x+(b.x-v.x)*M-f,E=v.y+(b.y-v.y)*M-p,_=Math.atan2(b.y-v.y,b.x-v.x);return{x:I,y:E,angle:_}}}h+=S}}else if(t.type==="Ellipse"){const n=Math.abs(s)/2,i=Math.abs(o)/2,a=t.sweepAngle??360,l=((t.startAngle??0)+a*e)*Math.PI/180,f=n*Math.cos(l),p=i*Math.sin(l),u=-n*Math.sin(l),g=i*Math.cos(l),h=Math.atan2(g,u);return{x:f,y:p,angle:h}}else if((t==null?void 0:t.type)==="Rectangle"){const n=Math.abs(s),i=Math.abs(o),r=(n+i)*2*e;let l=0,f=0,p=0;return r<n?(l=-n/2+r,f=-i/2,p=0):r<n+i?(l=n/2,f=-i/2+(r-n),p=Math.PI/2):r<2*n+i?(l=n/2-(r-(n+i)),f=i/2,p=Math.PI):(l=-n/2,f=i/2-(r-(2*n+i)),p=-Math.PI/2),{x:l,y:f,angle:p}}return{x:0,y:0,angle:0}}getBezierPointAndAngle(t,s,o,e,n){const i=s.x,a=s.y,r=s.out_x??s.x,l=s.out_y??s.y,f=o.in_x??o.x,p=o.in_y??o.y,u=o.x,g=o.y,h=1-t,d=t*t,w=h*h,y=w*h,c=d*t,v=y*i+3*w*t*r+3*h*d*f+c*u-e,b=y*a+3*w*t*l+3*h*d*p+c*g-n,S=3*w*(r-i)+6*h*t*(f-r)+3*d*(u-f),C=3*w*(l-a)+6*h*t*(p-l)+3*d*(g-p),M=Math.atan2(C,S);return{x:v,y:b,angle:M}}applyAbsoluteTransform(t,s,o){if(!o.get(s))return;const n=[];let i=s;for(;i;){n.unshift(i);const a=o.get(i);i=a==null?void 0:a.parentId}n.forEach(a=>{this.applyObjectTransform(t,a)})}applyObjectTransform(t,s){var h,d,w;const o=this.objectStates.get(s);if(!o)return;t.translate(o.x,o.y),t.rotate((o.rotation??0)*Math.PI/180);const e=o.skew_x||0,n=o.skew_y||0;if(e!==0||n!==0){const y=Math.tan(e*Math.PI/180),c=Math.tan(n*Math.PI/180);t.transform(1+y*c,c,y,1,0,0)}const i=o.rotate_x!==void 0?o.rotate_x:((h=o.transform)==null?void 0:h.rotate_x)??0,a=o.rotate_y!==void 0?o.rotate_y:((d=o.transform)==null?void 0:d.rotate_y)??0,l=1+(o.translate_z!==void 0?o.translate_z:((w=o.transform)==null?void 0:w.translate_z)??0)/1e3,f=(o.flip_x===!0?-1:1)*Math.cos(a*Math.PI/180)*l,p=(o.flip_y===!0?-1:1)*Math.cos(i*Math.PI/180)*l,u=(o.scale_x??1)*f,g=(o.scale_y??1)*p;t.scale(u,g)}applyInnerGlowOverlay(t,s,o,e,n,i,a){var y,c;const r=a||s.style||{},l=r==null?void 0:r.effect,p=((r==null?void 0:r.effects)||(l?[l]:[])).find(v=>v.isEnabled!==!1&&v.type==="Glow"&&(v.mode==="inner"||v.mode==="Inner Glow"));if(!p)return;t.save(),t.beginPath(),this.applyPath(t,o,e,n,i),t.clip();const u=p.blur||10,g=1e4,h=t.getTransform();let d=p.color||"white";(c=(y=this.artboard)==null?void 0:y.tokens)!=null&&c.colors&&this.artboard.tokens.colors[d]&&(d=this.artboard.tokens.colors[d]),t.shadowColor=d,t.shadowBlur=u,t.shadowOffsetX=g*h.a,t.shadowOffsetY=g*h.b,t.translate(-g,0),t.lineWidth=u+5,t.strokeStyle=d;const w=Math.min(p.intensity||1,5);for(let v=0;v<w;v++)t.beginPath(),this.applyPath(t,o,e,n,i),t.stroke();t.restore()}applyArtEffectOverlay(t,s,o,e,n,i){var g,h,d,w,y;const a=this.objectStates.get(s.id),r=((g=a==null?void 0:a.style)==null?void 0:g.artEffect)||s.artEffect||((h=s.style)==null?void 0:h.artEffect);if(!r||!r.enabled)return;const l=r.type,f=r.intensity??.5,p=r.speed??1,u=r.scale??10;if(l==="acid_gradient"||l==="acid_rave"||l==="shimmer"||l==="glint_overlay"||l==="halftone"||l==="noise"||l==="scanlines"||l==="chromatic_aberration"||l==="pixelate"||l==="glitch"||l==="fold_overlay"||l==="crumple_overlay"){if(t.save(),this.applyPath(t,o,e,n,i),t.clip(),l==="shimmer"){const v=this.currentTime*p%2/2,b=t.createLinearGradient(-e,-n,e,n);b.addColorStop(Math.max(0,v-.2),"rgba(255,255,255,0)"),b.addColorStop(v,`rgba(255,255,255,${f*.8})`),b.addColorStop(Math.min(1,v+.2),"rgba(255,255,255,0)"),t.fillStyle=b,t.globalCompositeOperation="screen",t.fillRect(-e/2,-n/2,e,n),t.globalCompositeOperation="source-over"}else if(l==="glint_overlay"){let b=((this._lastPointerPos||{x:0}).x-(((d=s.transform)==null?void 0:d.x)??0)+300)/600;b=Math.max(-.2,Math.min(1.2,b));const S=t.createLinearGradient(-e,-n,e,n);S.addColorStop(Math.max(0,b-.15),"rgba(255,255,255,0)"),S.addColorStop(Math.max(0,Math.min(1,b)),`rgba(255,255,255,${f})`),S.addColorStop(Math.min(1,b+.15),"rgba(255,255,255,0)"),t.fillStyle=S,t.globalCompositeOperation="screen",t.fillRect(-e/2,-n/2,e,n),t.globalCompositeOperation="source-over"}else if(l==="fold_overlay"){const c=this._lastPointerPos||{x:0,y:0},v=c.x-(((w=s.transform)==null?void 0:w.x)??0),b=c.y-(((y=s.transform)==null?void 0:y.y)??0),S=t.createLinearGradient(v>0?-e/2:e/2,b>0?-n/2:n/2,v>0?e/2:-e/2,b>0?n/2:-n/2);S.addColorStop(0,`rgba(0,0,0,${f*.6})`),S.addColorStop(.4,"rgba(0,0,0,0)"),S.addColorStop(.5,`rgba(255,255,255,${f*.4})`),S.addColorStop(1,`rgba(0,0,0,${f*.2})`),t.fillStyle=S,t.globalCompositeOperation="overlay",t.fillRect(-e/2,-n/2,e,n),t.globalCompositeOperation="source-over",t.beginPath(),v>0&&b>0?(t.moveTo(e/2-40,n/2),t.lineTo(e/2,n/2-40),t.lineTo(e/2-40,n/2-40)):v<0&&b>0?(t.moveTo(-e/2+40,n/2),t.lineTo(-e/2,n/2-40),t.lineTo(-e/2+40,n/2-40)):v>0&&b<0?(t.moveTo(e/2-40,-n/2),t.lineTo(e/2,-n/2+40),t.lineTo(e/2-40,-n/2+40)):(t.moveTo(-e/2+40,-n/2),t.lineTo(-e/2,-n/2+40),t.lineTo(-e/2+40,-n/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=b>0?-2:2,t.fill()}else if(l==="crumple_overlay"){const c=Math.floor(e/u),v=document.createElement("canvas");v.width=c,v.height=Math.floor(n/u);const b=v.getContext("2d"),S=b.createImageData(v.width,v.height);for(let C=0;C<S.data.length;C+=4){const M=Math.random()>.95?150:255;S.data[C]=M,S.data[C+1]=M,S.data[C+2]=M,S.data[C+3]=255*f}b.putImageData(S,0,0),t.globalCompositeOperation="multiply",t.imageSmoothingEnabled=!1,t.drawImage(v,-e/2,-n/2,e,n)}else if(l==="acid_gradient"||l==="acid_rave"){const c=this.currentTime*p,v=r.color1,b=r.color2,S=t.createLinearGradient(-e/2,-n/2,e/2,n/2);if(v&&b){const C=c*60%360;S.addColorStop(0,this._shiftHue(v,C,f*.7)),S.addColorStop(1,this._shiftHue(b,(C+180)%360,f*.7))}else{const C=c*100%360,M=(C+180)%360;S.addColorStop(0,`hsla(${C}, 80%, 50%, ${f*.5})`),S.addColorStop(1,`hsla(${M}, 80%, 50%, ${f*.5})`)}t.fillStyle=S,t.globalCompositeOperation="screen",t.fillRect(-e/2,-n/2,e,n)}else if(l==="halftone"){const c=Math.max(2,u*(1-f*.8)),v=document.createElement("canvas");v.width=c,v.height=c;const b=v.getContext("2d");if(b){b.fillStyle="black",b.beginPath(),b.arc(c/2,c/2,c/2*f,0,Math.PI*2),b.fill();const S=t.createPattern(v,"repeat");S&&(t.globalAlpha=.3*f,t.fillStyle=S,t.fillRect(-e/2,-n/2,e,n))}}else if(l==="noise"){const c=Math.floor(e*n*f*.02);t.globalAlpha=.4*f;for(let v=0;v<c;v++){const b=Math.random()>.5?255:0;t.fillStyle=`rgba(${b}, ${b}, ${b}, ${.5+Math.random()*.5})`,t.fillRect(-e/2+Math.random()*e,-n/2+Math.random()*n,2,2)}}else if(l==="scanlines"){t.globalAlpha=.2*f,t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1;for(let c=-n/2;c<n/2;c+=4)t.beginPath(),t.moveTo(-e/2,c),t.lineTo(e/2,c),t.stroke()}else if(l==="chromatic_aberration"){const c=5*f;t.globalCompositeOperation="screen",t.globalAlpha=.5,t.fillStyle="cyan",t.fillRect(-e/2-c,-n/2,e,n),t.fillStyle="magenta",t.fillRect(-e/2+c,-n/2,e,n)}else if(l==="pixelate"){const c=Math.max(2,Math.round(u*(1-f*.5))),v=document.createElement("canvas"),b=Math.max(1,Math.ceil(e/c)),S=Math.max(1,Math.ceil(n/c));v.width=b,v.height=S;const C=v.getContext("2d");if(C){C.imageSmoothingEnabled=!1;const M=t.getTransform(),I=M.e-e/2,E=M.f-n/2;C.drawImage(t.canvas,I,E,e,n,0,0,b,S),t.imageSmoothingEnabled=!1,t.drawImage(v,0,0,b,S,-e/2,-n/2,e,n),t.imageSmoothingEnabled=!0}}else if(l==="glitch"){const c=this.currentTime*p,v=r.chaosAmount??.2,b=Math.max(3,Math.floor(8*f)),S=f*e*.15;t.globalCompositeOperation="screen",t.globalAlpha=f*.4;const C=S*.3;t.fillStyle="rgba(255, 0, 0, 0.4)",t.fillRect(-e/2+C,-n/2,e,n),t.fillStyle="rgba(0, 255, 255, 0.4)",t.fillRect(-e/2-C,-n/2,e,n),t.globalCompositeOperation="source-over",t.globalAlpha=1;const M=n/b;for(let I=0;I<b;I++){const E=Math.sin(I*127.1+c*311.7*p)*43758.5,_=E-Math.floor(E);if(_>1-v){const T=(_-(1-v))/v*S*(Math.random()>.5?1:-1),A=-n/2+I*M,R=t.getTransform(),Y=R.e-e/2+T,L=R.f+A;t.save(),t.beginPath(),t.rect(-e/2,A,e,M),t.clip(),t.globalAlpha=.8,t.drawImage(t.canvas,Y,L,e,M,-e/2+T,A,e,M),t.restore()}}}t.restore()}}_shiftHue(t,s,o){let e=0,n=0,i=0;if(t.startsWith("#")){const g=t.replace("#","");e=parseInt(g.substring(0,2),16)/255,n=parseInt(g.substring(2,4),16)/255,i=parseInt(g.substring(4,6),16)/255}const a=Math.max(e,n,i),r=Math.min(e,n,i);let l=0,f=0,p=(a+r)/2;if(a!==r){const g=a-r;switch(f=p>.5?g/(2-a-r):g/(a+r),a){case e:l=((n-i)/g+(n<i?6:0))/6;break;case n:l=((i-e)/g+2)/6;break;case i:l=((e-n)/g+4)/6;break}}return`hsla(${(((l*360+s)%360+360)%360).toFixed(0)}, ${(f*100).toFixed(0)}%, ${(p*100).toFixed(0)}%, ${o})`}applyBackgroundBlurGlass(t,s,o,e,n,i,a){const r=i.radius??10,l=i.opacity!==void 0?this.normalizeOpacity(i.opacity):.5,f=i.noise??0,p=i.color??"rgba(255,255,255,0.2)";t.save(),this.applyPath(t,s,o,e,n),t.clip();const u=t.getTransform(),g=t.canvas;try{const w=document.createElement("canvas");w.width=Math.max(1,Math.ceil(o)),w.height=Math.max(1,Math.ceil(e));const y=w.getContext("2d");if(y){y.save(),y.translate(o/2,e/2);const c=i.magnification||1;if(c!==1&&y.scale(c,c),typeof u.inverse=="function"){const S=u.inverse();y.transform(S.a,S.b,S.c,S.d,S.e,S.f)}else{const S=u.a*u.d-u.b*u.c;S!==0&&y.transform(u.d/S,-u.b/S,-u.c/S,u.a/S,(u.c*u.f-u.d*u.e)/S,(u.b*u.e-u.a*u.f)/S)}y.drawImage(g,0,0),y.restore();const v=document.createElement("canvas");v.width=w.width,v.height=w.height;const b=v.getContext("2d");b.filter=`blur(${r}px)`,b.drawImage(w,0,0),t.globalCompositeOperation="destination-out",t.fillRect(-o/2,-e/2,o,e),t.globalCompositeOperation="source-over",t.globalAlpha=1,t.drawImage(v,-o/2,-e/2,o,e)}}catch(w){console.error("Background blur failed:",w)}t.globalCompositeOperation="source-over",t.globalAlpha=l,t.fillStyle=p,t.fillRect(-o/2,-e/2,o,e),t.globalAlpha=1;const h=t.createLinearGradient(-o/2,-e/2,o/2,e/2);if(h.addColorStop(0,"rgba(255,255,255,0.12)"),h.addColorStop(.3,"rgba(255,255,255,0.04)"),h.addColorStop(.5,"rgba(255,255,255,0.0)"),h.addColorStop(1,"rgba(255,255,255,0.0)"),t.fillStyle=h,t.fillRect(-o/2,-e/2,o,e),f>0){if(t.globalAlpha=f/100,!this._noiseTileCanvas){const y=document.createElement("canvas");y.width=64,y.height=64;const c=y.getContext("2d"),v=c.createImageData(64,64),b=v.data;for(let S=0;S<b.length;S+=4){const C=Math.floor(Math.random()*255);b[S]=C,b[S+1]=C,b[S+2]=C,b[S+3]=18}c.putImageData(v,0,0),this._noiseTileCanvas=y}const w=t.createPattern(this._noiseTileCanvas,"repeat");w&&(t.fillStyle=w,t.fillRect(-o/2,-e/2,o,e))}t.restore(),t.save(),t.globalAlpha=1,(a==null?void 0:a.stroke)&&a.stroke.width>0&&a.stroke.isEnabled!==!1?(this.applyPath(t,s,o,e,n),this.applyStrokeAlignment(t,a,s,o,e,n)):(t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1.5,this.applyPath(t,s,o,e,n),t.stroke()),t.restore()}applyPath(t,s,o,e,n){s!=null&&s.data&&(s.type==="Path"||s.type==="Subtract"||s.type==="Union"||s.type==="Intersect"||s.type==="Exclude"||s.type),t.beginPath(),this._tracePath(t,s,o,e,n)}_tracePath(t,s,o,e,n){if(s){if(this.ensurePathPoints(s),(s==null?void 0:s.type)==="Rectangle"||s.type==="Image"){const i=n!==void 0?n:s.corner_radius??0;this.drawRoundRect(t,-o/2,-e/2,o,e,i)}else if(s.type==="Line")t.moveTo(-o/2,0),t.lineTo(o/2,0);else if(s.type==="Ellipse"||s.type==="circle"){const{startAngle:i=0,sweepAngle:a=360,ratio:r=0}=s,l=o/2,f=e/2,p=i*Math.PI/180,u=a*Math.PI/180,g=p+u;a>=360&&r<=0?t.ellipse(0,0,l,f,0,0,Math.PI*2):(t.ellipse(0,0,l,f,0,p,g,!1),r>0?t.ellipse(0,0,l*r,f*r,0,g,p,!0):t.lineTo(0,0),t.closePath())}else if(s.type==="Triangle")t.moveTo(0,-e/2),t.lineTo(o/2,e/2),t.lineTo(-o/2,e/2),t.closePath();else if(s.type==="Polygon"){const i=s.sides||3,a=s.radius||Math.min(o,e)/2;for(let r=0;r<i;r++){const l=r*2*Math.PI/i-Math.PI/2,f=a*Math.cos(l),p=a*Math.sin(l);r===0?t.moveTo(f,p):t.lineTo(f,p)}t.closePath()}else if(s.type==="Star"){const i=s.points||5,a=s.outer_radius||Math.min(o,e)/2;let r=s.inner_radius;r==null?r=a*.382:r<=1&&(r=a*r);for(let l=0;l<i*2;l++){const f=l*Math.PI/i-Math.PI/2,p=l%2===0?a:r,u=p*Math.cos(f),g=p*Math.sin(f);l===0?t.moveTo(u,g):t.lineTo(u,g)}t.closePath()}else if(((s==null?void 0:s.type)==="Path"||s.type==="Subtract"||s.type==="Union"||s.type==="Intersect"||s.type==="Exclude"||s.type==="BooleanOperation")&&s.points){this.frameCount%300===0&&this.log("[Engine] Tracing Path:",s.points.length,"points");let i=1/0,a=-1/0,r=1/0,l=-1/0;if(s.points.forEach(u=>{typeof u.x=="number"&&typeof u.y=="number"&&(i=Math.min(i,u.x),a=Math.max(a,u.x),r=Math.min(r,u.y),l=Math.max(l,u.y),u.out_x!==void 0&&(i=Math.min(i,u.out_x),a=Math.max(a,u.out_x)),u.out_y!==void 0&&(r=Math.min(r,u.out_y),l=Math.max(l,u.out_y)),u.in_x!==void 0&&(i=Math.min(i,u.in_x),a=Math.max(a,u.in_x)),u.in_y!==void 0&&(r=Math.min(r,u.in_y),l=Math.max(l,u.in_y)))}),i===1/0)return;let f=(i+a)/2,p=(r+l)/2;if(isNaN(f)||isNaN(p)){this.warn("[Engine] Invalid path center:",f,p);return}s.points.forEach((u,g)=>{if(g===0||u.moveTo)t.moveTo(u.x-f,u.y-p);else{const h=s.points[g-1];if(!h)return;const d=(h.out_x??h.x)-f,w=(h.out_y??h.y)-p,y=(u.in_x??u.x)-f,c=(u.in_y??u.y)-p;isNaN(d)||isNaN(y)||isNaN(u.x)?t.lineTo(u.x-f,u.y-p):t.bezierCurveTo(d,w,y,c,u.x-f,u.y-p)}if(u.closePath||g===s.points.length-1&&(s.is_closed||s.isClosed)){const h=[...s.points.slice(0,g+1)].reverse().find(d=>d.moveTo)||s.points[0];h&&(u.out_x!==void 0||h.in_x!==void 0)&&t.bezierCurveTo((u.out_x??u.x)-f,(u.out_y??u.y)-p,(h.in_x??h.x)-f,(h.in_y??h.y)-p,h.x-f,h.y-p),t.closePath()}})}else if(s.points&&Array.isArray(s.points)){let i=1/0,a=-1/0,r=1/0,l=-1/0;s.points.forEach(u=>{i=Math.min(i,u.x),a=Math.max(a,u.x),r=Math.min(r,u.y),l=Math.max(l,u.y)});const f=(i+a)/2,p=(r+l)/2;s.points.forEach((u,g)=>{if(g===0)t.moveTo(u.x-f,u.y-p);else{const h=s.points[g-1];h.out_x!==void 0||u.in_x!==void 0?t.bezierCurveTo((h.out_x??h.x)-f,(h.out_y??h.y)-p,(u.in_x??u.x)-f,(u.in_y??u.y)-p,u.x-f,u.y-p):t.lineTo(u.x-f,u.y-p)}(u.closePath||g===s.points.length-1&&(s.is_closed||s.isClosed))&&t.closePath()})}}}renderInputBox(t,s){var Ht,zt,qt,Jt,se,ie,Se,Pe,me,_e,Me,Zt,Le,Re,ve,ae,Oe,pe;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=s.geometry||{},i=s.style||{},a=n.width||250,r=n.height||45,l=this.focusedId===s.id,f=this.lastHoveredObjectId===s.id,p=e.previewState||"default",u=p!=="default"?p:l?"focused":f?"hovered":"default",g=e.label||{visible:!0,text:"Label"},h=e.helperText||{visible:!1,text:"Helper text"},d=e.leftIcon||{visible:!1},w=e.rightIcon||{visible:!1},y=e.inputType==="textarea"||e.multiline===!0,c=u==="disabled",v=u==="error",b=n.corner_radius??n.cornerRadius,S=Array.isArray(b)?{tl:b[0],tr:b[1],br:b[2],bl:b[3]}:b&&typeof b=="object"?b:void 0,C=Number(e.cornerRadius??e.corner_radius??b??e.radius??8),M=e.corners??S??{tl:C,tr:C,bl:C,br:C},I=[Number(M.tl??C),Number(M.tr??C),Number(M.br??C),Number(M.bl??C)],E=(bt,at,Ct,K,ot,G=0)=>{const V=Math.max(0,Ct-G*2),Q=Math.max(0,K-G*2);let[tt,ht,Et,Yt]=ot.map(Xt=>Math.max(0,(Number(Xt)||0)-G));const jt=Math.min(V,Q)/2;tt=Math.min(tt,jt),ht=Math.min(ht,jt),Et=Math.min(Et,jt),Yt=Math.min(Yt,jt),t.beginPath(),t.roundRect?t.roundRect(bt+G,at+G,V,Q,[tt,ht,Et,Yt]):(t.moveTo(bt+G+tt,at+G),t.lineTo(bt+G+V-ht,at+G),t.arcTo(bt+G+V,at+G,bt+G+V,at+G+ht,ht),t.lineTo(bt+G+V,at+G+Q-Et),t.arcTo(bt+G+V,at+G+Q,bt+G+V-Et,at+G+Q,Et),t.lineTo(bt+G+Yt,at+G+Q),t.arcTo(bt+G,at+G+Q,bt+G,at+G+Q-Yt,Yt),t.lineTo(bt+G+tt,at+G),t.arcTo(bt+G,at+G,bt+G+tt,at+G,tt),t.closePath())};let _=e.backgroundColor||((Ht=i.fill)==null?void 0:Ht.color)||"rgba(31, 41, 55, 1)",T=e.borderColor||((qt=(zt=i.stroke)==null?void 0:zt.fill)==null?void 0:qt.color)||((Jt=i.stroke)==null?void 0:Jt.color)||"rgba(55, 65, 81, 1)",A=Number(e.borderWidth??((se=i.stroke)==null?void 0:se.width)??1),R=e.color||((ie=i.fill)==null?void 0:ie.color)||"#ffffff",Y=e.placeholderColor||"rgba(156, 163, 175, 1)",L=e.fontSize||14,D=e.caretColor||"#3b82f6";const P=`${u}Style`,k=e[P];k?(k.backgroundColor!==void 0&&(_=k.backgroundColor),k.borderColor!==void 0&&(T=k.borderColor),k.borderWidth!==void 0&&(A=k.borderWidth),k.color!==void 0&&(R=k.color),k.placeholderColor!==void 0&&(Y=k.placeholderColor),k.fontSize!==void 0&&(L=k.fontSize),k.caretColor!==void 0&&(D=k.caretColor)):u==="focused"?(T=e.focusBorderColor||"rgba(59, 130, 246, 1)",A=Math.max(A,2)):u==="hovered"||u==="hover"?(T=e.hoverBorderColor||T,_=e.hoverBackgroundColor||_):c?(_=e.disabledBackgroundColor||"rgba(31, 41, 55, 0.6)",T=e.disabledBorderColor||"rgba(55, 65, 81, 0.4)"):v&&(T="rgba(239, 68, 68, 1)",A=Math.max(A,2));const O=A>0?A/2:0,$=this.createCanvasFill(t,_,a,r);if($&&_!=="transparent"&&(E(-a/2,-r/2,a,r,I,O),t.fillStyle=$,t.fill()),A>0){const bt=this.createCanvasFill(t,T,a,r);bt&&T!=="transparent"&&(E(-a/2,-r/2,a,r,I,O),t.strokeStyle=bt,t.lineWidth=A,t.lineCap="round",t.lineJoin="round",t.stroke())}if((u==="focused"||u==="focus")&&!c){t.save();const bt=-3,at=I.map(ot=>Math.max(0,ot+3));E(-a/2+bt,-r/2+bt,a-bt*2,r-bt*2,at);const Ct=((Se=e.activeStyle)==null?void 0:Se.borderColor)||D||"rgba(59, 130, 246, 0.4)",K=this.createCanvasFill(t,Ct,a,r)||"rgba(59, 130, 246, 0.4)";t.strokeStyle=K,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",t.stroke(),t.restore()}const X=e.fontFamily||"Inter",F=e.fontWeight||400,B=L,j=e.inputType==="number"&&((Pe=e.number)==null?void 0:Pe.showSteppers)!==!1,z=24,q=j?z+4:0,U=String(e.text??e.value??"");let J="Enter text...";if(e.inputType==="tel")J=`${((me=e.tel)==null?void 0:me.dialCode)||"+1"} (555) 000-0000`;else if(e.inputType==="number"){const bt=(_e=e.number)!=null&&_e.prefix?`${e.number.prefix} `:"",at=(Me=e.number)!=null&&Me.suffix?` ${e.number.suffix}`:"";J=`${bt}0.00${at}`}else e.inputType==="email"?J="user@example.com":e.inputType==="search"?J="Search anything...":e.inputType==="url"?J="https://example.com":e.inputType==="password"?J="••••••••":e.inputType==="textarea"&&(J="Enter text...");const W=e.placeholder||J,N=!U,H=e.inputType==="password",rt=w.mode==="password-toggle"||H&&w.visible!==!1,It=w.mode==="clear"||e.inputType==="search"&&!!U,mt=(bt,at)=>{var tt;let Ct=bt.svgPath||"";if(Ct||(at?e.inputType==="search"&&(Ct="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"):rt?Ct=e.passwordVisible?"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24M1 1l22 22":"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z M12 9a3 3 0 100 6 3 3 0 000-6z":It&&(Ct="M18 6L6 18M6 6l12 12")),!(bt.visible||!!Ct&&(!at&&(rt||It)||at&&e.inputType==="search"))||!Ct)return;const ot=bt.size||16,G=(bt.offset??16)+(at?0:q),V=typeof bt.color=="string"?bt.color:((tt=bt.color)==null?void 0:tt.color)||"#9ca3af",Q=at?-(a/2)+G:a/2-G;if(t.save(),t.translate(Q,0),!Ct.startsWith("<svg")){const ht=new Path2D(Ct),Et=ot/24;t.scale(Et,Et),t.translate(-12,-12),Ct.includes("M18 6L6 18")||Ct.includes("M1 1l22 22")||Ct.includes("M21 21")?(t.strokeStyle=V,t.lineWidth=2,t.lineCap="round",t.stroke(ht)):(t.fillStyle=V,t.fill(ht))}t.restore()};if(mt(d,!0),mt(w,!1),j){const bt=a/2-z-4;t.save(),t.strokeStyle=T||"rgba(55, 65, 81, 0.5)",t.lineWidth=1,t.beginPath(),t.moveTo(bt,-r/2+6),t.lineTo(bt,r/2-6),t.stroke(),t.beginPath(),t.moveTo(bt,0),t.lineTo(a/2-4,0),t.stroke(),t.fillStyle=R||"rgba(156, 163, 175, 0.8)",t.font=`600 8px "${X}", sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText("▲",bt+z/2,-r/4),t.fillText("▼",bt+z/2,r/4),t.restore()}const St=((Zt=e.padding)==null?void 0:Zt.left)??e.inputPadding??12,pt=((Le=e.padding)==null?void 0:Le.right)??e.inputPadding??12,kt=d.visible||e.inputType==="search",Bt=w.visible||rt||It,vt=kt?(d.offset??16)+(d.size||16)/2+8:St,Dt=Bt?(w.offset??16)+(w.size||16)/2+8+q:pt+q,Z=-(a/2)+vt,ft=Math.max(0,a-vt-Dt);let Tt=U||W;if(e.inputType==="number"&&U){const bt=(Re=e.number)!=null&&Re.prefix?`${e.number.prefix} `:"",at=(ve=e.number)!=null&&ve.suffix?` ${e.number.suffix}`:"";Tt=`${bt}${U}${at}`}const Ot=H&&U?e.passwordVisible?U:"•".repeat(U.length):Tt,_t=N?Y:R;if(t.font=`${F} ${B}px "${X}", sans-serif`,t.fillStyle=_t,t.textAlign="left",t.save(),t.beginPath(),t.rect(Z-2,-r/2+4,ft+4,r-8),t.clip(),y){t.textBaseline="top";const bt=Ot.split(`
19
- `);let at=-r/2+(((ae=e.padding)==null?void 0:ae.top)??8);const Ct=B*1.4,K=e.rows||3;let ot=0,G=0;for(const V of bt){if(ot>=K)break;const Q=V.split(" ");let tt="";for(let ht=0;ht<Q.length;ht++){const Et=tt+Q[ht]+" ";if(t.measureText(Et).width>ft&&ht>0){if(ot>=K)break;t.fillText(tt.trim(),Z,at),tt=Q[ht]+" ",at+=Ct,ot++}else tt=Et}ot<K&&(t.fillText(tt.trim(),Z,at),G=t.measureText(tt.trim()).width,at+=Ct,ot++)}if(l&&!N&&Math.floor(performance.now()/500)%2===0){const V=at-Ct;t.fillStyle=D,t.fillRect(Z+Math.min(G,ft),V,1.5,B)}}else{t.textBaseline="middle";const at=t.measureText(Ot).width;let Ct=0;if(at>ft&&(Ct=at-ft),t.fillText(Ot,Z-Ct,0),l&&Math.floor(performance.now()/500)%2===0){const K=N?Z:Z+at-Ct;t.fillStyle=D,t.fillRect(K,-(B/2),1.5,B)}}if(t.restore(),e.showCharCounter){t.save();const bt=Number(e.maxLength||0),at=bt>0?`${U.length}/${bt}`:`${U.length}`;t.font=`400 10px "${X}", sans-serif`,t.fillStyle=bt>0&&U.length>=bt?"#ef4444":"rgba(156, 163, 175, 0.6)",t.textAlign="right",t.textBaseline="top",t.fillText(at,-(a/2)+a-8,-(r/2)+r+4),t.restore()}if(g.visible!==!1){const bt=!!(g.required||(Oe=e.validation)!=null&&Oe.required),at=(g.text||"Label")+(bt?" *":""),Ct=g.fontSize||12,K=g.color||"rgba(156, 163, 175, 1)",ot=g.position||"top",G=g.gap??g.offset??6;let V=-(a/2),Q=-(r/2)-G,tt="left",ht="bottom",Et=`600 ${Ct}px "${g.fontFamily||X}", sans-serif`;ot==="left"?(V=-(a/2)-G,Q=0,tt="right",ht="middle"):ot==="bottom"?(V=-(a/2),Q=r/2+G,tt="left",ht="top"):ot==="floating"&&(!!U||l?(V=-(a/2)+12,Q=-(r/2)+4,tt="left",ht="top",Et=`600 ${Math.max(9,Ct-2)}px "${g.fontFamily||X}", sans-serif`):Et=null),Et&&(t.save(),t.font=Et,t.fillStyle=K,t.textAlign=tt,t.textBaseline=ht,t.fillText(at,V,Q),t.restore())}const Rt=(pe=e.validation)==null?void 0:pe.errorMessage;if(v&&Rt||h.visible===!0&&h.text){t.save();const bt=h.fontSize||11,at=v?"#ef4444":h.color||"rgba(156, 163, 175, 1)",Ct=h.offset??6,K=v&&Rt?Rt:h.text;t.font=`400 ${bt}px "${X}", sans-serif`,t.fillStyle=at,t.textAlign="left",t.textBaseline="top",t.fillText(K,-(a/2),r/2+Ct),t.restore()}c&&(t.save(),E(-a/2,-r/2,a,r,I),t.fillStyle="rgba(0, 0, 0, 0.3)",t.fill(),t.restore())}renderSlider(t,s){const o=this.objectStates.get(s.id),e=(o==null?void 0:o.geometry)||s.geometry,n=(o==null?void 0:o.options)||s.options||{},i=e.width||200,a=n.value??50,r=n.min??0,f=(n.max??100)-r,p=f===0?0:(a-r)/f,u=n.trackHeight||4,g=n.trackRoundedness??2,h=n.trackShape??"Rectangle",d=n.trackPath||"",w=n.accentColor||"#3b82f6",y=n.inactiveColor||"#374151",c=n.thumbShape||"Ellipse",v=n.thumbWidth??16,b=n.thumbHeight??16,S=n.thumbRoundedness??0,C=n.thumbColor||"#ffffff",M=n.thumbPath||"",I=n.thumbIcon||"",E=n.showValueTooltip??!1,_=n.tooltipBgColor||"#333333",T=n.tooltipColor||"#ffffff",A=n.tooltipOffsetX??0,R=n.tooltipOffsetY??-25,Y=(z,q,U,J,W,N,H)=>{if((z==="Custom"||z==="Icon")&&H)try{const rt=new Path2D(H);if(t.save(),t.translate(q,U),z==="Icon"){const It=Math.min(J,W)/24;t.scale(It,It),t.translate(-12,-12)}t.fill(rt),t.restore();return}catch(rt){console.error("Error drawing slider shape in engine:",rt)}if(t.beginPath(),z==="Ellipse")t.ellipse(q,U,J/2,W/2,0,0,Math.PI*2);else if(z==="Rectangle")this.drawRoundRect(t,q-J/2,U-W/2,J,W,N);else if(z==="Triangle")t.moveTo(q,U-W/2),t.lineTo(q+J/2,U+W/2),t.lineTo(q-J/2,U+W/2),t.closePath();else if(z==="Diamond")t.moveTo(q,U-W/2),t.lineTo(q+J/2,U),t.lineTo(q,U+W/2),t.lineTo(q-J/2,U),t.closePath();else if(z==="Polygon"){const rt=s.geometry.sides||3,It=s.geometry.radius||Math.min(J,W)/2;for(let mt=0;mt<rt;mt++){const St=mt*2*Math.PI/rt-Math.PI/2,pt=q+It*Math.cos(St),kt=U+It*Math.sin(St);mt===0?t.moveTo(pt,kt):t.lineTo(pt,kt)}t.closePath()}else if(z==="Star"){const It=Math.min(J,W)/2,mt=It/2;for(let St=0;St<10;St++){const pt=St%2===0?It:mt,kt=St*Math.PI/5-Math.PI/2;t.lineTo(q+pt*Math.cos(kt),U+pt*Math.sin(kt))}t.closePath()}else z==="Line"&&(t.moveTo(q-J/2,U),t.lineTo(q+J/2,U));t.fill()},L=this.createCanvasFill(t,y,i,u);L&&(t.fillStyle=L,t.strokeStyle=L),h==="Line"?(t.lineWidth=u,t.beginPath(),t.moveTo(-i/2,0),t.lineTo(i/2,0),t.stroke()):Y(h,0,0,i,u,g,d);const D=i-v,P=-i/2+v/2+p*D,k=P- -i/2;if(k>0){const z=this.createCanvasFill(t,w,i,u);z&&(t.fillStyle=z,t.strokeStyle=z),h==="Line"?(t.lineWidth=u,t.beginPath(),t.moveTo(-i/2,0),t.lineTo(P,0),t.stroke()):h==="Rectangle"&&(t.beginPath(),this.drawRoundRect(t,-i/2,-u/2,k,u,g),t.fill())}t.save(),t.translate(P,0);const O=t.getTransform(),$=Math.sqrt(O.a*O.a+O.b*O.b)||1;t.shadowColor="rgba(0,0,0,0.2)",t.shadowBlur=4*$,t.shadowOffsetY=1*$;const X=this.createCanvasFill(t,C,v,b);if(X&&(t.fillStyle=X),Y(c,0,0,v,b,S,c==="Icon"?I:M),t.restore(),E){t.save(),t.translate(P+A,R);const z=Math.round(a).toString();t.font="10px Inter, sans-serif";const q=t.measureText(z),U=6,J=4,W=q.width+U*2,N=14+J;t.beginPath(),this.drawRoundRect(t,-W/2,-N/2,W,N,4),t.fillStyle=_,t.fill(),t.fillStyle=T,t.textAlign="center",t.textBaseline="middle",t.fillText(z,0,0),t.restore()}const F=n.label||{},B=n.helperText||{},j=n.fontFamily||"Inter";if(F.visible!==!1){const z=F.text||"Label",q=F.fontSize||12,U=F.color||"rgba(156, 163, 175, 1)",J=F.offset??8;t.font=`600 ${q}px "${j}", sans-serif`,t.fillStyle=U,t.textAlign="left",t.textBaseline="bottom";const W=-(i/2),N=-(u/2)-J;t.fillText(z,W,N)}if(B.visible===!0){const z=B.text||"Helper text",q=B.fontSize||11,U=B.color||"rgba(156, 163, 175, 1)",J=B.offset??6;t.font=`400 ${q}px "${j}", sans-serif`,t.fillStyle=U,t.textAlign="left",t.textBaseline="top";const W=-(i/2),N=u/2+J;t.fillText(z,W,N)}}renderDropdown(t,s){var R;const o=this.objectStates.get(s.id);if(!o)return;const e=o.options||s.options||{},n=s.geometry.width||180,i=s.geometry.height||40,a=-n/2,r=-i/2,l=e.cornerRadius??e.corner_radius??6,f=e.disabled||e.previewState==="disabled",p=this.lastHoveredObjectId===s.id||e.previewState==="hover",u=(e.isOpen||e.previewState==="active")&&!f;let g=e.backgroundColor,h=e.borderColor,d=e.color||"#333333";f?(g=e.disabledBackgroundColor||"#f3f4f6",h=e.disabledBorderColor||"#e5e7eb",d=e.disabledColor||"#9ca3af"):u?(g=e.activeBackgroundColor||g,h=e.activeBorderColor||h,d=e.activeColor||d):p&&(g=e.hoverBackgroundColor||g,h=e.hoverBorderColor||h,d=e.hoverColor||d),g||(g="#ffffff"),h||(h="#e5e7eb"),t.save();const w=t.globalAlpha;t.globalAlpha=w*(e.opacity??1),t.beginPath(),this.drawRoundRect(t,a,r,n,i,l),t.fillStyle=this.createCanvasFill(t,typeof g=="string"?{type:"Solid",color:g}:g,n,i)||"#ffffff",t.fill();const y=e.borderWidth??1;y>0&&(t.beginPath(),this.drawRoundRect(t,a,r,n,i,l),t.strokeStyle=this.createCanvasFill(t,typeof h=="string"?{type:"Solid",color:h}:h,n,i)||"#e5e7eb",t.lineWidth=y,t.stroke());const c=12,v=e.chevronType||"chevron",b=e.chevronSize||16,S=(u?e.openIconColor:e.closedIconColor)||e.chevronColor||"#6b7280";if(v!=="none"){const Y=a+n-c-b/2;t.save(),t.translate(Y,0);const L=u?e.openIconAngle??180:e.closedIconAngle??0;if(t.rotate(L*Math.PI/180),t.strokeStyle=S,t.fillStyle=S,t.lineWidth=1.5,t.lineCap="round",t.lineJoin="round",v==="chevron")t.beginPath(),t.moveTo(-b/2,-b*.2),t.lineTo(0,b*.2),t.lineTo(b/2,-b*.2),t.stroke();else if(v==="custom"||v==="path"){const D=u&&e.openIconPath||e.closedIconPath;if(D){const P=new Path2D(D);t.save();const k=b/24;t.scale(k,k),t.translate(-12,-12),t.fill(P),t.restore()}}t.restore()}const C=e.selectedOption||e.placeholder||"Select...",M=e.fontSize||14,I=e.fontWeight||400,E=e.fontFamily||"Inter, sans-serif";t.font=`${I} ${M}px ${E}`;const _=f?e.disabledColor||"#9ca3af":!e.selectedOption&&e.placeholder?"#9ca3af":d;t.fillStyle=this.createCanvasFill(t,typeof _=="string"?{type:"Solid",color:_}:_,n,i)||"#333333",t.textAlign="left",t.textBaseline="middle";const T=v==="none"?0:b+8,A=n-c*2-T;if(t.save(),t.beginPath(),t.rect(a+c,r,A,i),t.clip(),t.fillText(C,a+c,0),t.restore(),u&&!f){const Y=r+i+4,L=this.getResolvedDropdownOptions(s,e),D=e.itemHeight||32,P=e.listPadding??4,k=L.length*D+P*2,O=e.listCornerRadius??l;t.save();const $=e.listShadow||{},X=t.getTransform(),F=Math.sqrt(X.a*X.a+X.b*X.b)||1;t.shadowColor=typeof $.color=="string"?$.color:((R=$.color)==null?void 0:R.color)||"rgba(0,0,0,0.15)",t.shadowBlur=($.blur??12)*F,t.shadowOffsetY=($.offsetY??6)*F,t.shadowOffsetX=($.offsetX??0)*F,t.beginPath(),this.drawRoundRect(t,a,Y,n,k,O),t.fillStyle=this.createCanvasFill(t,typeof e.listBackgroundColor=="string"?{type:"Solid",color:e.listBackgroundColor}:e.listBackgroundColor||{type:"Solid",color:"#ffffff"},n,k)||"#ffffff",t.fill();const B=e.listBorderWidth??1;B>0&&(t.shadowColor="transparent",t.beginPath(),this.drawRoundRect(t,a,Y,n,k,O),t.strokeStyle=this.createCanvasFill(t,typeof e.listBorderColor=="string"?{type:"Solid",color:e.listBorderColor}:e.listBorderColor||{type:"Solid",color:h},n,k)||"#e5e7eb",t.lineWidth=B,t.stroke()),t.restore();const j=e.itemFontSize||M,z=e.itemFontFamily||E;t.font=`${I} ${j}px ${z}`,L.forEach((q,U)=>{const J=Y+P+U*D;if(q===e.selectedOption)t.fillStyle=this.createCanvasFill(t,typeof e.itemSelectedBackgroundColor=="string"?{type:"Solid",color:e.itemSelectedBackgroundColor}:e.itemSelectedBackgroundColor||{type:"Solid",color:"#f3f4f6"},n,D)||"#f3f4f6",t.fillRect(a+B,J,n-B*2,D),t.fillStyle=e.itemSelectedColor||e.accentColor||d||"#374151";else if(t.fillStyle=e.listTextColor||d||"#333333",this.activeDropdownId===s.id&&this._lastPointerPos){const N=this._lastPointerPos.y-(Y+P),H=Math.floor(N/D);U===H&&(t.fillStyle=this.createCanvasFill(t,typeof e.itemHoverBackgroundColor=="string"?{type:"Solid",color:e.itemHoverBackgroundColor}:e.itemHoverBackgroundColor||{type:"Solid",color:"#f9fafb"},n,D)||"#f9fafb",t.fillRect(a+B,J,n-B*2,D),t.fillStyle=e.itemHoverColor||d)}t.fillText(q,a+c,J+D/2)})}t.restore()}renderButton(t,s){var A;if(s.children&&s.children.length>0)return;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=s.geometry||{},i=n.width||s.width||160,a=n.height||s.height||45,r=this.lastHoveredObjectId===s.id,l=this.activeObjectId===s.id,f=e.label||{},p=e.hoverStyle||{},u=e.activeStyle||{},g=e.icon||{enabled:!1};let h=e.backgroundColor||e.buttonBgColor||((A=s.style)==null?void 0:A.fill)||"#3b82f6",d=(typeof f=="object"?f.color:null)||"#ffffff",w=typeof f=="string"?f:f.text||s.text||(s.name&&!s.name.toLowerCase().includes("component")?s.name:"Button"),y=n.cornerRadius??n.corner_radius??8,c=e.borderColor||"transparent",v=e.borderWidth||0,b=1;l&&u?(h=u.backgroundColor||h,d=u.color||d,w=u.text||w,b=u.scale??.95,y=u.cornerRadius??y):r&&p&&(h=p.backgroundColor||h,d=p.color||d,w=p.text||w,b=p.scale??1,y=p.cornerRadius??y,c=p.borderColor||c);const S=-i/2,C=-a/2;t.save(),t.scale(b,b),t.beginPath(),this.drawRoundRect(t,S,C,i,a,y);const M=this.createCanvasFill(t,h,i,a);M&&(t.fillStyle=M,t.fill()),(v>0||r&&p.borderColor)&&(t.strokeStyle=c,t.lineWidth=v||(r?1:0),t.stroke());const I=f.fontSize||14,E=f.fontFamily||"Inter",_=f.fontWeight||600;t.font=`${_} ${I}px "${E}", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle=d,t.textAlign="center",t.textBaseline="middle";let T=0;if(g.enabled&&g.svgPath){const R=I*1.1,Y=g.gap||8,L=t.measureText(w),P=-(L.width+R+Y)/2,k=g.position==="left"?P+R/2:P+L.width+Y+R/2;T=g.position==="left"?P+R+Y+L.width/2:P+L.width/2,t.save(),t.translate(k,0);const O=new Path2D(g.svgPath),$=R/24;t.scale($,$),t.translate(-12,-12),t.fillStyle=d,t.fill(O),t.restore()}t.fillText(w,T,0),t.restore()}renderToggleButton(t,s){var w,y;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=e.checked??!1,i=((w=s.geometry)==null?void 0:w.width)||120,a=((y=s.geometry)==null?void 0:y.height)||40,r=-i/2,l=-a/2,f=e.corner_radius??8,p=e.label||{},u=n?e.accentColor||"#3b82f6":e.inactiveColor||"#374151",g=n?e.activeTextColor||"#ffffff":e.inactiveTextColor||"#9ca3af";t.save(),t.beginPath(),this.drawRoundRect(t,r,l,i,a,f),t.fillStyle=u,t.fill();const h=p.fontSize||14,d=p.fontFamily||"Inter";t.font=`${p.fontWeight||600} ${h}px "${d}", sans-serif`,t.fillStyle=g,t.textAlign="center",t.textBaseline="middle",t.fillText(p.text||"Toggle",0,0),t.restore()}renderToggle(t,s){var O,$,X,F,B,j,z,q,U,J,W,N;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=((O=s.geometry)==null?void 0:O.width)||52,i=(($=s.geometry)==null?void 0:$.height)||30,a=-n/2,r=-i/2,l=e.checked??!1,f=e.cornerRadius??e.corner_radius??i/2,p=e.toggleStyle||{},u=p.backgroundColor||e.activeColor||"#10b981",g=p.borderColor||e.borderColor||"transparent",h=p.borderWidth??e.borderWidth??0,d=p.knobColor||e.knobColor||"#ffffff",w=l?u:e.inactiveColor||"#374151",y=l?g:e.borderColor||"transparent",c=l?h:e.borderWidth??0,v=l?d:e.knobColor||"#ffffff";e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,n,i,f);const b=this.createCanvasFill(t,w,n,i);if(b&&(t.fillStyle=b,t.fill()),c>0){t.lineWidth=c;const H=this.createCanvasFill(t,y,n,i);H&&(t.strokeStyle=H,t.stroke())}const S=2,C=i-S*2,M=C/2,I=a+S,E=a+n-S-C,_=l?E:I,T=r+S;t.beginPath(),t.arc(_+M,T+M,M,0,Math.PI*2);const A=this.createCanvasFill(t,v,C,C);A&&(t.fillStyle=A,t.fill()),e.disabled&&(t.globalAlpha*=2);let R=!1,Y=!1;const L=(l?(X=p.leftLabel)==null?void 0:X.text:null)||((F=e.leftLabel)==null?void 0:F.text)||"",D=(l?(B=p.leftLabel)==null?void 0:B.color:null)||((j=e.leftLabel)==null?void 0:j.color)||"#f3f4f6";if((z=e.leftLabel)!=null&&z.enabled&&L){const H=e.leftLabel;t.font=`${H.fontWeight||400} ${H.fontSize||12}px "${H.fontFamily||"Inter"}", sans-serif`,t.fillStyle=D,t.textBaseline="middle",t.textAlign="right",t.fillText(L,a-(H.gap||8),0),R=!0}const P=(l?(q=p.rightLabel)==null?void 0:q.text:null)||((U=e.rightLabel)==null?void 0:U.text)||"",k=(l?(J=p.rightLabel)==null?void 0:J.color:null)||((W=e.rightLabel)==null?void 0:W.color)||"#f3f4f6";if((N=e.rightLabel)!=null&&N.enabled&&P){const H=e.rightLabel;t.font=`${H.fontWeight||400} ${H.fontSize||12}px "${H.fontFamily||"Inter"}", sans-serif`,t.fillStyle=k,t.textBaseline="middle",t.textAlign="left",t.fillText(P,a+n+(H.gap||8),0),Y=!0}if(!R&&!Y&&e.label&&e.label.text){const H=e.label,rt=H.fontSize||14,It=H.fontWeight||400,mt=H.fontFamily||"Inter";t.font=`${It} ${rt}px "${mt}", sans-serif`,t.fillStyle=H.color||"#f3f4f6",t.textBaseline="middle";const St=H.gap||10;let pt=0,kt=0;H.position==="left"?(t.textAlign="right",pt=a-St,kt=0):H.position==="right"?(t.textAlign="left",pt=a+n+St,kt=0):H.position==="top"?(t.textAlign="center",pt=0,kt=r-St,t.textBaseline="bottom"):H.position==="bottom"?(t.textAlign="center",pt=0,kt=r+i+St,t.textBaseline="top"):(t.textAlign="left",pt=a+n+St,kt=0),t.fillText(H.text,pt,kt)}}renderCheckbox(t,s){var D,P,k,O;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=((D=s.geometry)==null?void 0:D.width)||140,i=((P=s.geometry)==null?void 0:P.height)||24,a=-n/2,r=-i/2,l=Math.max(12,Math.min(e.boxSize||18,i,n)),f=Math.min(e.cornerRadius??4,l/2),p=e.checked??!1,u=!!e.indeterminate,g=e.activeColor||"#3b82f6",h=e.inactiveColor||"transparent",d=e.checkColor||"#ffffff",w=e.borderColor||"#9ca3af",y=e.borderWidth??1.5,c=!!(e.label&&e.label.text),v=((k=e.label)==null?void 0:k.gap)??8,b=((O=e.label)==null?void 0:O.position)||"right";let S=a,C=r+(i-l)/2,M=0,I=0,E="left",_="middle";c?b==="right"?(S=a,C=r+(i-l)/2,M=S+l+v,I=0,E="left",_="middle"):b==="left"?(S=a+n-l,C=r+(i-l)/2,M=S-v,I=0,E="right",_="middle"):b==="top"?(S=a+(n-l)/2,C=r+i-l,M=0,I=C-v,E="center",_="bottom"):b==="bottom"&&(S=a+(n-l)/2,C=r,M=0,I=C+l+v,E="center",_="top"):(S=a+(n-l)/2,C=r+(i-l)/2);const T=p||u,A=T?g:h,R=T?g:w,Y=T?0:y;e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,S,C,l,l,f);const L=this.createCanvasFill(t,A,l,l);if(L&&(t.fillStyle=L,t.fill()),Y>0){t.lineWidth=Y;const $=this.createCanvasFill(t,R,l,l);$&&(t.strokeStyle=$,t.stroke())}else if(T){t.lineWidth=1;const $=this.createCanvasFill(t,g,l,l);$&&(t.strokeStyle=$,t.stroke())}if(u){t.save(),t.beginPath();const $=this.createCanvasFill(t,d,l,l);t.strokeStyle=$||d,t.lineWidth=Math.max(2,l*.12),t.lineCap="round",t.moveTo(S+l*.25,C+l*.5),t.lineTo(S+l*.75,C+l*.5),t.stroke(),t.restore()}else if(p){t.save(),t.beginPath();const $=this.createCanvasFill(t,d,l,l);t.strokeStyle=$||d,t.lineWidth=Math.max(2,l*.12),t.lineCap="round",t.lineJoin="round";const X=S+l*.24,F=C+l*.5,B=S+l*.44,j=C+l*.7,z=S+l*.76,q=C+l*.28;t.moveTo(X,F),t.lineTo(B,j),t.lineTo(z,q),t.stroke(),t.restore()}if(e.disabled&&(t.globalAlpha*=2),c&&e.label&&e.label.text){const $=e.label;t.save(),t.font=`${$.fontWeight||400} ${$.fontSize||14}px "${$.fontFamily||"Inter"}", sans-serif`,t.fillStyle=$.color||"#111827",t.textAlign=E,t.textBaseline=_,t.fillText($.text,M,I),t.restore()}}renderRadioGroup(t,s){var E,_;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=((E=s.geometry)==null?void 0:E.width)||180,i=((_=s.geometry)==null?void 0:_.height)||100,a=-n/2,r=-i/2;let l=e.optionsList||["Option 1","Option 2","Option 3"];if(e.isDataVarEnabled&&e.dataInputId){let T=this.inputs.get(e.dataInputId);if(T===void 0){const A=this.inputNameMap.get(e.dataInputId);A&&A.length>0&&(T=this.inputs.get(A[0]))}T&&Array.isArray(T)&&(l=T.map(A=>typeof A=="string"?A:String(A)))}const f=e.selectedValue,p=e.orientation||"vertical",u=e.itemGap!==void 0?e.itemGap:16,g=e.activeColor||"#3b82f6",h=e.inactiveColor||"#4b5563",d=e.textColor||"#ffffff",w=e.fontSize||14,y=e.fontFamily||"Inter",c=e.fontWeight||400;t.save(),t.beginPath(),t.rect(a,r,n,i),t.clip(),e.disabled&&(t.globalAlpha*=.5);const v=8,b=v*2,S=e.radioShape||"circle",C=e.borderWidth!==void 0?e.borderWidth:2,M=e.fillEmpty||"transparent",I=(T,A,R,Y)=>{if(t.beginPath(),Y==="custom"&&e.customShapePath)try{const L=new Path2D(e.customShapePath);t.save(),t.translate(T-R,A-R),t.scale(R*2/24,R*2/24),t.fill(L),t.restore();return}catch{t.arc(T,A,R,0,Math.PI*2);return}if(Y==="square"){const L=R*1.6;t.rect(T-L/2,A-L/2,L,L)}else if(Y==="diamond"){const L=R*1.4;t.moveTo(T,A-L),t.lineTo(T+L,A),t.lineTo(T,A+L),t.lineTo(T-L,A),t.closePath()}else if(Y==="heart"){const L=R*.9;t.moveTo(T,A+L*.7),t.bezierCurveTo(T-L*1.5,A-L*.3,T-L*.5,A-L*1.5,T,A-L*.5),t.bezierCurveTo(T+L*.5,A-L*1.5,T+L*1.5,A-L*.3,T,A+L*.7)}else if(Y==="star"){const L=R*1.1,D=R*.5;for(let P=0;P<5;P++){const k=(P*72-90)*Math.PI/180,O=(P*72+36-90)*Math.PI/180;P===0?t.moveTo(T+L*Math.cos(k),A+L*Math.sin(k)):t.lineTo(T+L*Math.cos(k),A+L*Math.sin(k)),t.lineTo(T+D*Math.cos(O),A+D*Math.sin(O))}t.closePath()}else t.arc(T,A,R,0,Math.PI*2)};if(t.font=`${c} ${w}px "${y}", sans-serif`,t.textBaseline="middle",t.textAlign="left",p==="vertical"){const T=Math.max(b,w)+u,A=l.length*T-u,R=r+Math.max(0,(i-A)/2);l.forEach((Y,L)=>{const D=R+v+L*T,P=f===Y,k=this.createCanvasFill(t,g,b,b),O=this.createCanvasFill(t,h,b,b);P?(t.fillStyle=k||g,I(a+v,D,v,S),t.fill(),t.strokeStyle=k||g,t.lineWidth=C,I(a+v,D,v,S),t.stroke()):(M!=="transparent"&&(t.fillStyle=M,I(a+v,D,v,S),t.fill()),t.strokeStyle=O||h,t.lineWidth=C,I(a+v,D,v,S),t.stroke()),t.fillStyle=d,t.fillText(Y,a+b+8,D)})}else{const T=r+i/2;let A=0;t.font=`${c} ${w}px "${y}", sans-serif`,l.forEach(L=>{A+=b+6+t.measureText(L).width+u}),A-=u;let Y=a+Math.max(0,(n-A)/2);l.forEach(L=>{const D=f===L,P=t.measureText(L).width,k=this.createCanvasFill(t,g,b,b),O=this.createCanvasFill(t,h,b,b);D?(t.fillStyle=k||g,I(Y+v,T,v,S),t.fill(),t.strokeStyle=k||g,t.lineWidth=C,I(Y+v,T,v,S),t.stroke()):(M!=="transparent"&&(t.fillStyle=M,I(Y+v,T,v,S),t.fill()),t.strokeStyle=O||h,t.lineWidth=C,I(Y+v,T,v,S),t.stroke()),t.fillStyle=d,t.fillText(L,Y+b+6,T),Y+=b+6+P+u})}if(t.restore(),e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const T=e.label;t.save(),t.font=`${T.fontWeight||400} ${T.fontSize||14}px "${T.fontFamily||"Inter"}", sans-serif`,t.fillStyle=T.color||"#9ca3af",t.textBaseline="middle";const A=T.gap||8;let R=0,Y=0;T.position==="left"?(t.textAlign="right",R=a-A,Y=0):T.position==="right"?(t.textAlign="left",R=a+n+A,Y=0):T.position==="top"?(t.textAlign="center",R=0,Y=r-A,t.textBaseline="bottom"):T.position==="bottom"&&(t.textAlign="center",R=0,Y=r+i+A,t.textBaseline="top"),t.fillText(T.text,R,Y),t.restore()}}renderBarChart(t,s){var Y,L,D;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{};let n={...e};if(e.isDataVarEnabled&&e.dataInputId){let P=this.inputs.get(e.dataInputId);if(P===void 0){const k=this.inputNameMap.get(e.dataInputId);k&&k.length>0&&(P=this.inputs.get(k[0]))}P&&Array.isArray(P)&&(n.categories=P.map(k=>typeof k=="string"?k:String(k)))}if(e.isDatasetsVarEnabled&&((Y=e.datasetInputIds)==null?void 0:Y.length)>0){const P=e.datasetInputIds.map((k,O)=>{var F;let $=this.inputs.get(k);if($===void 0){const B=this.inputNameMap.get(k);B&&B.length>0&&($=this.inputs.get(B[0]))}const X=((F=e.datasets)==null?void 0:F[O])||{id:`ds-${O}`,label:`Series ${O+1}`,data:[],color:"#6366f1"};return $&&Array.isArray($)?{...X,data:$.map(B=>typeof B=="number"?B:parseFloat(B)||0)}:X});n.datasets=P}const i={width:((L=s.geometry)==null?void 0:L.width)||300,height:((D=s.geometry)==null?void 0:D.height)||180,chartType:n.chartType||"grouped",datasets:n.datasets||[{id:"ds-1",label:"Revenue",data:[42,67,31,55,78,48],color:"#6366f1"}],categories:n.categories||["Jan","Feb","Mar","Apr","May","Jun"],orientation:n.orientation||"vertical",barWidth:n.barWidth!==void 0?n.barWidth:14,barGap:n.barGap!==void 0?n.barGap:4,barCornerRadius:n.barCornerRadius!==void 0?n.barCornerRadius:5,showXAxis:!!n.showXAxis,showYAxis:!!n.showYAxis,xAxisColor:n.xAxisColor||"rgba(255,255,255,0.15)",yAxisColor:n.yAxisColor||"rgba(255,255,255,0.15)",showXLabels:n.showXLabels!==void 0?!!n.showXLabels:!0,showYLabels:!!n.showYLabels,axisLabelColor:n.axisLabelColor||"rgba(255,255,255,0.55)",axisLabelFontSize:n.axisLabelFontSize||9,showLegend:n.showLegend!==void 0?!!n.showLegend:!0,legendColor:n.legendColor||"rgba(255,255,255,0.7)",legendFontSize:n.legendFontSize||9,showGridLines:n.showGridLines!==void 0?!!n.showGridLines:!0,gridColor:n.gridColor||"rgba(255,255,255,0.06)",cardBackground:n.cardBackground||"#ffffff",cardBackgroundOpacity:n.cardBackgroundOpacity!==void 0?n.cardBackgroundOpacity:.04,cardBorderColor:n.cardBorderColor||"rgba(255,255,255,0.08)",barGradient:n.barGradient!==void 0?!!n.barGradient:!0,gradientStartColor:n.gradientStartColor||"",gradientEndOpacity:n.gradientEndOpacity!==void 0?n.gradientEndOpacity:.27,showValueOnTop:!!n.showValueOnTop,valueFontSize:n.valueFontSize||10,valueColor:n.valueColor||"",valueFontWeight:n.valueFontWeight||"bold",barStyle:n.barStyle||"solid",barBorderWidth:n.barBorderWidth!==void 0?n.barBorderWidth:1,barBorderColor:n.barBorderColor||"auto",enableShadows:!!n.enableShadows,shadowColor:n.shadowColor||"rgba(0,0,0,0.5)",shadowBlur:n.shadowBlur!==void 0?n.shadowBlur:4,shadowOffsetY:n.shadowOffsetY!==void 0?n.shadowOffsetY:2,xAxisLineWidth:n.xAxisLineWidth!==void 0?n.xAxisLineWidth:1,yAxisLineWidth:n.yAxisLineWidth!==void 0?n.yAxisLineWidth:1,gridLineWidth:n.gridLineWidth!==void 0?n.gridLineWidth:1,gridLineDash:n.gridLineDash||[3,4],showHoverTooltip:n.showHoverTooltip!==void 0?!!n.showHoverTooltip:!0,hoverHighlight:n.hoverHighlight!==void 0?!!n.hoverHighlight:!0,hoverHighlightColor:n.hoverHighlightColor||"rgba(255, 255, 255, 0.22)",tooltipBg:n.tooltipBg||"#111827",tooltipTextColor:n.tooltipTextColor||"#f9fafb",tooltipRadius:n.tooltipRadius!==void 0?n.tooltipRadius:6,_hexToRgb:function(P,k){if(P.startsWith("rgba")||P.startsWith("rgb"))return P;P.startsWith("#")||(P="#"+P),P.length===4&&(P="#"+P[1]+P[1]+P[2]+P[2]+P[3]+P[3]);const O=parseInt(P.slice(1,3),16),$=parseInt(P.slice(3,5),16),X=parseInt(P.slice(5,7),16);return`rgba(${O},${$},${X},${k})`},_resolveColor:function(P,k){return typeof P=="string"?P:"#6366f1"},_makeGradient:function(P,k,O,$,X,F){if(!this.barGradient)return k;const B=this.gradientStartColor||k,j=P.createLinearGradient(O,$,X,F);return j.addColorStop(0,k),j.addColorStop(1,this._hexToRgb(B,this.gradientEndOpacity)),j},_drawRoundedBar:function(P,k,O,$,X,F,B){if(F=Math.min(F,Math.min(Math.abs($),Math.abs(X))/2),F<=0||$===0||X===0){P.rect(k,O,$,X);return}P.beginPath(),B?(P.moveTo(k,O+X),P.lineTo(k,O+F),P.quadraticCurveTo(k,O,k+F,O),P.lineTo(k+$-F,O),P.quadraticCurveTo(k+$,O,k+$,O+F),P.lineTo(k+$,O+X),P.lineTo(k,O+X)):(P.moveTo(k,O),P.lineTo(k+$-F,O),P.quadraticCurveTo(k+$,O,k+$,O+F),P.lineTo(k+$,O+X-F),P.quadraticCurveTo(k+$,O+X,k+$-F,O+X),P.lineTo(k,O+X),P.lineTo(k,O)),P.closePath()}},a=i.width,r=i.height,l=-a/2,f=-r/2;if(!i.datasets||i.datasets.length===0||i.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}let p=-1/0,u=1/0;const g=i.categories.length,h=i.datasets.length;if(i.chartType==="stacked")for(let P=0;P<g;P++){let k=0,O=0;i.datasets.forEach($=>{const X=$.data[P]??0;X>=0?k+=X:O+=X}),k>p&&(p=k),O<u&&(u=O)}else i.datasets.forEach(P=>{P.data&&P.data.forEach(k=>{k>p&&(p=k),k<u&&(u=k)})});isFinite(p)||(p=10),isFinite(u)||(u=0),p=Math.max(p,0),u=Math.min(u,0);const d=p-u||10;t.save(),i.enableShadows&&(t.shadowColor=i.shadowColor,t.shadowBlur=i.shadowBlur,t.shadowOffsetY=i.shadowOffsetY),t.font=i.axisLabelFontSize+"px Inter, sans-serif";const w=i.showYLabels?t.measureText(p.toFixed(0)).width+14:10,y=i.showXLabels?i.axisLabelFontSize+12:8,v=(i.showLegend&&h>0?i.legendFontSize+10:0)+8,b=10,S=l+w,C=f+v,M=a-w-b,I=r-v-y;if(i.enableShadows&&(t.shadowColor="transparent"),t.beginPath(),t.roundRect(l,f,a,r,10),t.fillStyle=i._hexToRgb(i.cardBackground,i.cardBackgroundOpacity),t.fill(),t.strokeStyle=i.cardBorderColor,t.lineWidth=1,t.stroke(),i.showLegend&&h>0){t.font=i.legendFontSize+"px Inter, sans-serif",t.textBaseline="middle";const P=f+12;let k=S;i.datasets.forEach((O,$)=>{const X=i._resolveColor(O.color,$),F=O.label||"Series "+($+1),B=7;t.beginPath(),t.roundRect(k,P-B/2,B,B,2),t.fillStyle=X,t.fill(),t.fillStyle=i.legendColor,t.textAlign="left",t.fillText(F,k+B+4,P),k+=t.measureText(F).width+B+16})}const E=4;if(i.showGridLines){t.setLineDash(i.gridLineDash||[]),t.lineWidth=i.gridLineWidth||1,t.strokeStyle=i.gridColor;for(let P=0;P<=E;P++)if(i.orientation==="horizontal"){const k=S+P/E*M;t.beginPath(),t.moveTo(k,C),t.lineTo(k,C+I),t.stroke()}else{const k=C+P/E*I;t.beginPath(),t.moveTo(S,k),t.lineTo(S+M,k),t.stroke()}t.setLineDash([])}if(i.showYLabels){t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=i.axisLabelColor;for(let P=0;P<=E;P++)if(i.orientation==="horizontal"){const k=u+P/E*d,O=S+P/E*M;t.textAlign="center",t.fillText(k.toFixed(0),O,C+I+i.axisLabelFontSize)}else{const k=p-P/E*d,O=C+P/E*I;t.textAlign="right",t.fillText(k.toFixed(0),S-6,O)}}t.setLineDash([]),i.showXAxis&&(t.lineWidth=i.xAxisLineWidth||1,t.strokeStyle=i.xAxisColor,t.beginPath(),t.moveTo(S,C+I),t.lineTo(S+M,C+I),t.stroke()),i.showYAxis&&(t.lineWidth=i.yAxisLineWidth||1,t.strokeStyle=i.yAxisColor,t.beginPath(),t.moveTo(S,C),t.lineTo(S,C+I),t.stroke()),i.enableShadows&&(t.shadowColor=i.shadowColor);const _=[],T=this.graphHoverStates.get(s.id),A=T==null?void 0:T.hoveredCatIdx,R=T==null?void 0:T.hoveredDsIdx;if(i.chartType==="stacked")if(i.orientation==="horizontal"){const P=I/g;for(let k=0;k<g;k++){const O=C+k*P+P/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=i.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[k]||"",S-5,O),i.enableShadows&&(t.shadowColor=i.shadowColor));let $=S;i.datasets.forEach((X,F)=>{const B=X.data[k]??0;if(B===0)return;const j=B/d*M,z=Math.min(i.barWidth*h+i.barGap,P-8),q=O-z/2,U=$;$+=j;const J=i._resolveColor(X.color,F);_.push({catIdx:k,dsIdx:F,category:i.categories[k]||"",label:X.label||`Series ${F+1}`,val:B,color:J,x:U,y:q,w:j,h:z}),t.beginPath(),t.fillStyle=i._makeGradient(t,J,U,q,U+j,q),i._drawRoundedBar(t,U,q,j,z,F===h-1?i.barCornerRadius:0,!1),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?J:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),A===k&&R===F&&i.hoverHighlight&&(t.save(),t.fillStyle=i.hoverHighlightColor,i._drawRoundedBar(t,U,q,j,z,F===h-1?i.barCornerRadius:0,!1),t.fill(),t.restore())})}}else{const P=M/g;for(let k=0;k<g;k++){const O=S+k*P+P/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillStyle=i.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[k]||"",O,C+I+5),i.enableShadows&&(t.shadowColor=i.shadowColor));let $=C+I;i.datasets.forEach((X,F)=>{const B=X.data[k]??0;if(B===0)return;const j=B/d*I,z=Math.min(i.barWidth*h+i.barGap,P-8),q=O-z/2,U=$-j;$-=j;const J=i._resolveColor(X.color,F);_.push({catIdx:k,dsIdx:F,category:i.categories[k]||"",label:X.label||`Series ${F+1}`,val:B,color:J,x:q,y:U,w:z,h:j}),t.beginPath(),t.fillStyle=i._makeGradient(t,J,q,U,q,U+j),i._drawRoundedBar(t,q,U,z,j,F===h-1?i.barCornerRadius:0,!0),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?J:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),A===k&&R===F&&i.hoverHighlight&&(t.save(),t.fillStyle=i.hoverHighlightColor,i._drawRoundedBar(t,q,U,z,j,F===h-1?i.barCornerRadius:0,!0),t.fill(),t.restore())})}}else if(i.orientation==="horizontal"){const P=I/g,k=h*i.barWidth+Math.max(0,(h-1)*i.barGap),O=S+(0-u)/d*M;for(let $=0;$<g;$++){const X=C+$*P+P/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=i.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[$]||"",S-5,X),i.enableShadows&&(t.shadowColor=i.shadowColor));const F=X-k/2;i.datasets.forEach((B,j)=>{const z=B.data[$]??0,q=Math.abs(z/d*M);if(q<1)return;const U=F+j*(i.barWidth+i.barGap),J=z>=0?O:O-q,W=i._resolveColor(B.color,j);_.push({catIdx:$,dsIdx:j,category:i.categories[$]||"",label:B.label||`Series ${j+1}`,val:z,color:W,x:J,y:U,w:q,h:i.barWidth}),t.beginPath(),t.fillStyle=i._makeGradient(t,W,J,U,J+q,U),i._drawRoundedBar(t,J,U,q,i.barWidth,i.barCornerRadius,!1),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?W:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),A===$&&R===j&&i.hoverHighlight&&(t.save(),t.fillStyle=i.hoverHighlightColor,i._drawRoundedBar(t,J,U,q,i.barWidth,i.barCornerRadius,!1),t.fill(),t.restore()),i.showValueOnTop&&z!==0&&(t.font=(i.valueFontWeight||"bold")+" "+(i.valueFontSize||10)+"px Inter, sans-serif",t.textAlign=z>=0?"left":"right",t.textBaseline="middle",t.fillStyle=i.valueColor==="auto"?W:i.valueColor||"#fff",t.shadowColor="transparent",t.fillText(z.toString(),z>=0?J+q+4:J-4,U+i.barWidth/2),i.enableShadows&&(t.shadowColor=i.shadowColor))})}}else{const P=M/g,k=h*i.barWidth+Math.max(0,(h-1)*i.barGap),O=C+I-(0-u)/d*I;for(let $=0;$<g;$++){const X=S+$*P+P/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillStyle=i.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[$]||"",X,C+I+5),i.enableShadows&&(t.shadowColor=i.shadowColor));const F=X-k/2;i.datasets.forEach((B,j)=>{const z=B.data[$]??0,q=Math.abs(z/d*I);if(q<1)return;const U=F+j*(i.barWidth+i.barGap),J=z>=0?O-q:O,W=i._resolveColor(B.color,j);_.push({catIdx:$,dsIdx:j,category:i.categories[$]||"",label:B.label||`Series ${j+1}`,val:z,color:W,x:U,y:J,w:i.barWidth,h:q}),t.beginPath(),t.fillStyle=i._makeGradient(t,W,U,J,U,J+q),i._drawRoundedBar(t,U,J,i.barWidth,q,i.barCornerRadius,!0),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?W:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),A===$&&R===j&&i.hoverHighlight&&(t.save(),t.fillStyle=i.hoverHighlightColor,i._drawRoundedBar(t,U,J,i.barWidth,q,i.barCornerRadius,!0),t.fill(),t.restore()),i.showValueOnTop&&z!==0&&(t.font=(i.valueFontWeight||"bold")+" "+(i.valueFontSize||10)+"px Inter, sans-serif",t.textAlign="center",t.textBaseline=z>=0?"bottom":"top",t.fillStyle=i.valueColor==="auto"?W:i.valueColor||"#fff",t.shadowColor="transparent",t.fillText(z.toString(),U+i.barWidth/2,z>=0?J-4:J+q+4),i.enableShadows&&(t.shadowColor=i.shadowColor))})}}if(this.barChartRenderedBars.set(s.id,_),i.showHoverTooltip&&A!==null&&A!==void 0&&R!==null&&R!==void 0){const P=_.find(k=>k.catIdx===A&&k.dsIdx===R);if(P){t.save();const k=10,O=8,$=14,F=O*2+$+16;t.font="bold 10px Inter, system-ui, sans-serif";const B=t.measureText(P.category||"Category").width;t.font="9px Inter, system-ui, sans-serif";const j=t.measureText(`${P.label}: ${P.val}`).width+16,z=Math.max(B,j)+k*2;let q=P.x+P.w/2-z/2,U=P.y-F-8;q<-a/2+6&&(q=-a/2+6),q+z>a/2-6&&(q=a/2-z-6),U<-r/2+6&&(U=P.y+P.h+8),t.shadowColor="rgba(0, 0, 0, 0.35)",t.shadowBlur=10,t.shadowOffsetX=0,t.shadowOffsetY=4,t.beginPath(),this.drawRoundRect(t,q,U,z,F,i.tooltipRadius),t.fillStyle=i.tooltipBg,t.fill(),t.shadowColor="transparent",t.lineWidth=1,t.strokeStyle="rgba(255, 255, 255, 0.12)",t.stroke(),t.font="bold 10px Inter, system-ui, sans-serif",t.fillStyle=i.tooltipTextColor,t.textAlign="left",t.textBaseline="top",t.fillText(P.category,q+k,U+O);const J=U+O+$+2;t.beginPath(),t.arc(q+k+4,J+5,3.5,0,Math.PI*2),t.fillStyle=P.color,t.fill(),t.font="9px Inter, system-ui, sans-serif",t.fillStyle=i.tooltipTextColor,t.fillText(`${P.label}: `,q+k+12,J);const W=t.measureText(`${P.label}: `).width;t.font="bold 9px Inter, system-ui, sans-serif",t.fillStyle="#60a5fa",t.fillText(`${P.val}`,q+k+12+W,J),t.restore()}}t.restore()}renderPieChart(t,s){var S,C;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=e.colorPalette==="custom"&&Array.isArray(e.customPalette)&&e.customPalette.length>0?e.customPalette:us[e.colorPalette||"vibrant"]||us.vibrant;let i=e.slices||[{id:"slice-1",label:"Item 1",value:45,color:""}];if(e.isDataVarEnabled&&e.dataInputId){let M=this.inputs.get(e.dataInputId);if(M===void 0){const I=this.inputNameMap.get(e.dataInputId);I&&I.length>0&&(M=this.inputs.get(I[0]))}M&&Array.isArray(M)&&(i=M.map((I,E)=>{var _,T;return{id:`slice-${E}`,label:((_=i[E])==null?void 0:_.label)||`Item ${E+1}`,value:typeof I=="number"?I:0,color:((T=i[E])==null?void 0:T.color)||""}}))}const a={width:((S=s.geometry)==null?void 0:S.width)||180,height:((C=s.geometry)==null?void 0:C.height)||180,chartType:e.chartType||"donut",slices:i,innerRadius:e.innerRadius!==void 0?e.innerRadius:.55,sliceGap:e.sliceGap!==void 0?e.sliceGap:3,showLabels:!!e.showLabels,labelColor:e.labelColor||"#000000",labelFontSize:e.labelFontSize||10,showLegend:e.showLegend!==void 0?!!e.showLegend:!0,legendColor:e.legendColor||"rgba(0,0,0,0.65)",legendFontSize:e.legendFontSize||9,showCenterText:e.showCenterText!==void 0?!!e.showCenterText:!0,centerLabel:e.centerLabel||"Total",centerTextColor:e.centerTextColor||"#000000",centerLabelColor:e.centerLabelColor||"rgba(0,0,0,0.4)",cardBackground:e.cardBackground||"#ffffff",cardBackgroundOpacity:e.cardBackgroundOpacity!==void 0?e.cardBackgroundOpacity:.04,cardBorderColor:e.cardBorderColor||"rgba(0,0,0,0.08)",showHoverTooltip:e.showHoverTooltip!==void 0?!!e.showHoverTooltip:!0,hoverExplode:e.hoverExplode!==void 0?!!e.hoverExplode:!0,tooltipBg:e.tooltipBg||"#111827",tooltipTextColor:e.tooltipTextColor||"#f9fafb",tooltipRadius:e.tooltipRadius!==void 0?e.tooltipRadius:6,_resolveSliceColor:function(M,I){return M.color?M.color:n[I%n.length]},_hexToRgb:function(M){if(M.startsWith("rgba")||M.startsWith("rgb"))return M;const I=M.replace("#",""),E=parseInt(I.substring(0,2),16),_=parseInt(I.substring(2,4),16),T=parseInt(I.substring(4,6),16);return`rgba(${E},${_},${T},${a.cardBackgroundOpacity})`}},r=a.width,l=a.height;if(!a.slices||a.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 f=a.slices.reduce((M,I)=>M+(I.value||0),0);if(f<=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}t.save();const p=a._hexToRgb(a.cardBackground);t.beginPath(),t.roundRect(-r/2,-l/2,r,l,10),t.fillStyle=p,t.fill(),t.strokeStyle=a.cardBorderColor,t.lineWidth=1,t.stroke();const u=a.showLegend?Math.ceil(a.slices.length/2):0,g=u>0?u*(a.legendFontSize+8)+10:0,h=l-g-16,d=Math.min(r-24,h)/2,w=0,y=-g/2,c=[],v=this.graphHoverStates.get(s.id),b=(v==null?void 0:v.hoveredSliceIndex)??null;if(a.chartType==="rose"){const M=Math.max(...a.slices.map(_=>_.value||0)),I=Math.PI*2/a.slices.length,E=d>0?a.sliceGap/d:0;a.slices.forEach((_,T)=>{const A=_.value||0;if(A===0)return;const R=A/M*d,Y=-Math.PI/2+T*I+E/2,L=Y+I-E,D=a._resolveSliceColor(_,T),P=Y+(L-Y)/2,k=b===T;let O=w,$=y;if(k&&a.hoverExplode&&(O+=Math.cos(P)*6,$+=Math.sin(P)*6),c.push({index:T,startA:Y,endA:L,innerR:0,outerR:R,cx:O,cy:$,slice:_,color:D,pct:Math.round(A/f*100)}),t.beginPath(),t.moveTo(O,$),t.arc(O,$,R,Y,L),t.closePath(),t.fillStyle=D+"cc",t.fill(),t.strokeStyle=D,t.lineWidth=k?2.5:1.5,t.stroke(),a.showLabels){const X=O+R*.65*Math.cos(P),F=$+R*.65*Math.sin(P),B=Math.round(A/f*100);t.save(),t.font=`bold ${a.labelFontSize}px Inter, sans-serif`,t.fillStyle=a.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${B}%`,X,F),t.restore()}})}else{const M=a.chartType==="pie"?0:a.innerRadius,I=d*Math.max(0,M),E=d>0?a.sliceGap/d:0;let _=-Math.PI/2;if(a.slices.forEach((T,A)=>{const R=T.value||0;if(R===0){_+=R/f*Math.PI*2;return}const Y=R/f*Math.PI*2,L=_+E/2,D=_+Y-E/2;if(D<=L){_+=Y;return}const P=a._resolveSliceColor(T,A),k=L+(D-L)/2,O=b===A;let $=w,X=y;if(O&&a.hoverExplode&&($+=Math.cos(k)*6,X+=Math.sin(k)*6),c.push({index:A,startA:L,endA:D,innerR:I,outerR:d,cx:$,cy:X,slice:T,color:P,pct:Math.round(R/f*100)}),t.beginPath(),t.fillStyle=P,I<=0?(t.moveTo($,X),t.arc($,X,d,L,D),t.lineTo($,X)):(t.moveTo($+d*Math.cos(L),X+d*Math.sin(L)),t.arc($,X,d,L,D),t.arc($,X,I,D,L,!0),t.closePath()),t.fill(),O&&(t.lineWidth=2,t.strokeStyle="#ffffff",t.stroke()),a.showLabels){const F=I+(d-I)/2,B=$+F*Math.cos(k),j=X+F*Math.sin(k),z=Math.round(R/f*100);t.save(),t.font=`bold ${a.labelFontSize}px Inter, sans-serif`,t.fillStyle=a.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${z}%`,B,j),t.restore()}_+=Y}),a.chartType==="donut"&&a.showCenterText&&I>14){const T=Math.round(f),A=Math.min(Math.floor(I*.52),20),R=Math.min(Math.floor(I*.26),10);t.textAlign="center",t.textBaseline="middle",t.font=`bold ${A}px Inter, sans-serif`,t.fillStyle=a.centerTextColor,t.fillText(T.toString(),w,y-R*.5),t.font=`${R}px Inter, sans-serif`,t.fillStyle=a.centerLabelColor,t.fillText(a.centerLabel,w,y+A*.6)}}if(this.pieChartRenderedSlices.set(s.id,c),a.showLegend&&a.slices.length>0){t.font=`${a.legendFontSize}px Inter, sans-serif`;const M=2,I=r/M,E=a.legendFontSize+8,_=l/2-g+10,T=-r/2+10;a.slices.forEach((A,R)=>{const Y=R%M,L=Math.floor(R/M),D=T+Y*I,P=_+L*E,k=a._resolveSliceColor(A,R),O=7;t.beginPath(),t.roundRect(D,P-O/2,O,O,2),t.fillStyle=k,t.fill(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=a.legendColor;const $=Math.round((A.value||0)/f*100),X=`${A.label||"Item"} ${$}%`,F=I-O-20;let B=X;for(;t.measureText(B).width>F&&B.length>4;)B=B.slice(0,-4)+"…";t.fillText(B,D+O+4,P)})}if(a.showHoverTooltip&&b!==null&&b!==void 0){const M=c.find(I=>I.index===b);if(M){t.save();const I=10,E=8,_=14,A=E*2+_+16;t.font="bold 10px Inter, system-ui, sans-serif";const R=t.measureText(M.slice.label||"Item").width;t.font="9px Inter, system-ui, sans-serif";const Y=`${M.slice.value} (${M.pct}%)`,L=t.measureText(Y).width+16,D=Math.max(R,L)+I*2,P=M.startA+(M.endA-M.startA)/2,k=(M.innerR+M.outerR)/2;let O=M.cx+Math.cos(P)*(k+10)-D/2,$=M.cy+Math.sin(P)*(k+10)-A/2;O<-r/2+6&&(O=-r/2+6),O+D>r/2-6&&(O=r/2-D-6),$<-l/2+6&&($=-l/2+6),$+A>l/2-6&&($=l/2-A-6),t.shadowColor="rgba(0, 0, 0, 0.35)",t.shadowBlur=10,t.shadowOffsetX=0,t.shadowOffsetY=4,t.beginPath(),this.drawRoundRect(t,O,$,D,A,a.tooltipRadius),t.fillStyle=a.tooltipBg,t.fill(),t.shadowColor="transparent",t.lineWidth=1,t.strokeStyle="rgba(255, 255, 255, 0.12)",t.stroke(),t.font="bold 10px Inter, system-ui, sans-serif",t.fillStyle=a.tooltipTextColor,t.textAlign="left",t.textBaseline="top",t.fillText(M.slice.label||"Item",O+I,$+E);const X=$+E+_+2;t.beginPath(),t.arc(O+I+4,X+5,3.5,0,Math.PI*2),t.fillStyle=M.color,t.fill(),t.font="bold 9px Inter, system-ui, sans-serif",t.fillStyle="#60a5fa",t.fillText(Y,O+I+12,X),t.restore()}}t.restore()}renderJoystick(t,s){var w,y,c,v,b,S,C,M,I,E,_,T;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.width)!==void 0?o.width:((w=s.geometry)==null?void 0:w.width)??s.width??100,n=(o==null?void 0:o.height)!==void 0?o.height:((y=s.geometry)==null?void 0:y.height)??s.height??100,i=Math.min(e,n)*(((c=s.style)==null?void 0:c.baseSize)??.45),a=Math.min(e,n)*(((v=s.style)==null?void 0:v.handleSize)??.14);let r=s.handleX||0,l=s.handleY||0;o&&o.handleX!==void 0&&(r=o.handleX),o&&o.handleY!==void 0&&(l=o.handleY),t.save();let f=0,p=0;s.handleOrigin==="top-left"?(f=e/2,p=n/2):s.handleOrigin==="bottom-right"&&(f=-e/2,p=-n/2),t.translate(f,p);const u=t.globalAlpha;if(t.globalAlpha=u*(((b=s.style)==null?void 0:b.baseOpacity)??1),t.beginPath(),s.boundsShape==="square"){const A=s.joystickType==="2D"?12:18;t.roundRect(-i,-i,i*2,i*2,A)}else t.arc(0,0,i,0,Math.PI*2);t.fillStyle=((S=s.style)==null?void 0:S.baseColor)||"rgba(0,0,0,0.04)",t.fill(),(C=s.style)!=null&&C.baseBorderWidth?(t.lineWidth=s.style.baseBorderWidth,t.strokeStyle=s.style.baseBorderColor||"rgba(0,0,0,0.1)",t.stroke()):(t.lineWidth=1,t.strokeStyle=((M=s.style)==null?void 0:M.baseBorderColor)||"rgba(0,0,0,0.08)",t.stroke());const g=s.overflowHandle?i:Math.max(.1,i-a);let h=0,d=0;s.joystickType==="2D"?(h=r*g,d=l*g):s.joystickType==="1D_X"?(h=r*g,d=0):s.joystickType==="1D_Y"&&(h=0,d=l*g),t.globalAlpha=u*(((I=s.style)==null?void 0:I.handleOpacity)??1),t.beginPath(),t.arc(h,d,a,0,Math.PI*2),t.fillStyle=((E=s.style)==null?void 0:E.handleColor)||"#3b82f6",t.fill(),(_=s.style)!=null&&_.handleBorderWidth?(t.lineWidth=s.style.handleBorderWidth,t.strokeStyle=s.style.handleBorderColor||"rgba(255,255,255,0.5)",t.stroke()):(t.lineWidth=1,t.strokeStyle=((T=s.style)==null?void 0:T.handleBorderColor)||"rgba(255,255,255,0.5)",t.stroke()),t.globalAlpha=u,t.restore()}getRadioGroupItemIndexAtPointer(t,s,o){var I,E;const e=t.options||{},n=this.objectStates.get(t.id)||{},i=e.optionsList||[];if(i.length===0)return null;const a=n.width!==void 0?n.width:((I=t.geometry)==null?void 0:I.width)||180,r=n.height!==void 0?n.height:((E=t.geometry)==null?void 0:E.height)||100,l=e.orientation||"vertical",f=e.itemGap!==void 0?e.itemGap:16,p=e.fontSize||14,u=this.getWorldTransform(t.id),g=s-u.x,h=o-u.y,d=-u.rotation*(Math.PI/180),w=Math.cos(d),y=Math.sin(d),c=g*w-h*y,v=g*y+h*w,S=8*2,C=-a/2,M=-r/2;if(l==="vertical"){const _=Math.max(S,p)+f;for(let T=0;T<i.length;T++){const A=M+T*_;if(c>=C&&c<=C+a&&v>=A&&v<=A+_)return T}}else{let _=C;for(let T=0;T<i.length;T++){const R=i[T].length*8,Y=S+6+R+f;if(c>=_&&c<=_+Y&&v>=M&&v<=M+r)return T;_+=Y}}return null}renderLineGraph(t,s,o,e,n){let i=o.datasets||[];if((!i||i.length===0)&&(o.data||o.graphData)&&(i=[{id:"line-1",label:"Series 1",data:o.data||o.graphData||[],lineColor:o.lineColor||"#3b82f6",lineWidth:o.lineWidth||2,showArea:o.showArea||!1,areaColor:o.areaColor||"rgba(139, 92, 246, 0.3)",smoothing:o.smoothing||!1,showPoints:o.showPoints!==void 0?o.showPoints:!0,pointSize:o.pointSize||6,pointFill:o.pointFill||"#ffffff",pointStrokeColor:o.pointStrokeColor||o.lineColor||"#3b82f6",pointStrokeWidth:o.pointStrokeWidth||2}]),!i||i.length===0||!i.some(b=>b.data&&b.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 a=1/0,r=-1/0,l=0;if(i.forEach(b=>{let S=b.data;if(b.isVarEnabled&&b.inputId){let C=this.inputs.get(b.inputId);if(C===void 0){const M=this.inputNameMap.get(b.inputId);M&&M.length>0&&(C=this.inputs.get(M[0]))}C&&Array.isArray(C)&&(S=C)}if(S&&S.length>0){const C=S.filter(M=>typeof M=="number"&&!isNaN(M));C.length>0&&(a=Math.min(a,...C),r=Math.max(r,...C),l=Math.max(l,S.length))}b._resolvedData=S}),l<2)return;const f=r-a,p=e/(l-1),u=b=>{const S=f===0?.5:(b-a)/f;return n/2-S*n},g=b=>b*p-e/2,h=o.axisColor||"#333333";if(o.showXAxis&&(t.beginPath(),t.strokeStyle=o.xAxisColor||h,t.lineWidth=1,t.moveTo(-e/2,n/2),t.lineTo(e/2,n/2),t.stroke()),o.showYAxis&&(t.beginPath(),t.strokeStyle=o.yAxisColor||h,t.lineWidth=1,t.moveTo(-e/2,-n/2),t.lineTo(-e/2,n/2),t.stroke()),t.fillStyle=o.axisLabelColor||"#333333",t.font=`${o.axisLabelFontSize||10}px Inter, sans-serif`,o.showXLabels){t.textAlign="center",t.textBaseline="top";for(let b=0;b<l;b++){const S=g(b);t.fillText(`${b+1}`,S,n/2+5)}}if(o.showYLabels){t.textAlign="right",t.textBaseline="middle";const b=-e/2-5,S=(r+a)/2;t.fillText(r.toFixed(1),b,u(r)),t.fillText(S.toFixed(1),b,u(S)),t.fillText(a.toFixed(1),b,u(a))}const d=10;if(i.forEach(b=>{const S=b._resolvedData;if(!(!S||S.length<2)){if(b.showArea){if(t.beginPath(),t.moveTo(g(0),n/2),t.lineTo(g(0),u(S[0])),b.smoothing&&S.length>2)for(let M=0;M<S.length-1;M++){const I=S[M===0?M:M-1],E=S[M],_=S[M+1],T=S[M+1===S.length-1?M+1:M+2];for(let A=1;A<=d;A++){const R=A/d,Y=this._catmullRom(I,E,_,T,R);t.lineTo(g(M+R),u(Y))}}else for(let M=1;M<S.length;M++)t.lineTo(g(M),u(S[M]));t.lineTo(g(S.length-1),n/2),t.closePath();const C=t.globalAlpha;t.globalAlpha=C*(o.areaOpacity??.3),t.fillStyle=b.areaColor||"rgba(139, 92, 246, 0.2)",t.fill(),t.globalAlpha=C}if(t.beginPath(),t.strokeStyle=b.lineColor||"#3b82f6",t.lineWidth=b.lineWidth||2,t.lineJoin="round",t.lineCap="round",t.moveTo(g(0),u(S[0])),b.smoothing&&S.length>2)for(let C=0;C<S.length-1;C++){const M=S[C===0?C:C-1],I=S[C],E=S[C+1],_=S[C+1===S.length-1?C+1:C+2];for(let T=1;T<=d;T++){const A=T/d,R=this._catmullRom(M,I,E,_,A);t.lineTo(g(C+A),u(R))}}else for(let C=1;C<S.length;C++)t.lineTo(g(C),u(S[C]));t.stroke(),b.showPoints&&S.forEach((C,M)=>{const I=g(M),E=u(C);t.beginPath(),t.arc(I,E,(b.pointSize||6)/2,0,Math.PI*2),t.fillStyle=b.pointFill||"#ffffff",t.fill(),t.strokeStyle=b.pointStrokeColor||b.lineColor||"#3b82f6",t.lineWidth=b.pointStrokeWidth||1,t.stroke()})}}),o.showLegend&&i.length>0){const b=e/2-10;let S=-n/2+15;const C=o.legendFontSize||10,M=C+5;t.font=`${C}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="alphabetic",i.forEach(I=>{const _=I.label||"Series",T=t.measureText(_).width;t.beginPath(),t.rect(b-T-8-5,S-(8/2+2),8,8),t.fillStyle=I.lineColor||"#3b82f6",t.fill(),t.fillStyle=o.legendColor||"#333333",t.fillText(_,b,S),S+=M})}const w=this.graphHoverStates.get(s==null?void 0:s.id),y=w==null?void 0:w.hoveredIndex,c=o.showHoverTooltip!==!1,v=o.showHoverLine!==!1;if(y!=null&&(c||v)){const b=g(y);v&&(t.save(),t.beginPath(),t.strokeStyle=o.hoverLineColor||"rgba(255, 255, 255, 0.35)",t.lineWidth=1,t.setLineDash([3,3]),t.moveTo(b,-n/2),t.lineTo(b,n/2),t.stroke(),t.setLineDash([]),t.restore());const S=[];if(i.forEach(C=>{const M=C._resolvedData||C.data;if(M&&M[y]!==void 0&&typeof M[y]=="number"&&!isNaN(M[y])){const I=M[y],E=u(I),_=C.lineColor||"#3b82f6";S.push({y:E,color:_,label:C.label||"Series",val:I}),t.save(),t.beginPath();const T=o.pointHighlightRadius||5;t.arc(b,E,T+3,0,Math.PI*2),t.fillStyle=typeof _=="string"&&_.startsWith("#")?`${_}33`:"rgba(59, 130, 246, 0.2)",t.fill(),t.beginPath(),t.arc(b,E,T,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.strokeStyle=_,t.lineWidth=2.5,t.stroke(),t.restore()}}),c&&S.length>0){t.save();const C=10,M=8,I=16,E=14,_=M*2+E+S.length*I;t.font="bold 10px Inter, system-ui, sans-serif";let T=t.measureText(`Point #${y+1}`).width;t.font="9px Inter, system-ui, sans-serif",S.forEach(P=>{const k=t.measureText(`${P.label}: ${P.val.toFixed(1)}`).width+16;k>T&&(T=k)});const A=T+C*2;let R=b+12;R+A>e/2-4&&(R=b-A-12),R<-e/2+4&&(R=-e/2+4);let L=S.reduce((P,k)=>P+k.y,0)/S.length-_/2;L<-n/2+6&&(L=-n/2+6),L+_>n/2-6&&(L=n/2-_-6),t.shadowColor="rgba(0, 0, 0, 0.35)",t.shadowBlur=10,t.shadowOffsetX=0,t.shadowOffsetY=4,t.beginPath(),this.drawRoundRect(t,R,L,A,_,o.tooltipRadius||6),t.fillStyle=o.tooltipBg||"#111827",t.fill(),t.shadowColor="transparent",t.lineWidth=1,t.strokeStyle="rgba(255, 255, 255, 0.12)",t.stroke(),t.font="bold 10px Inter, system-ui, sans-serif",t.fillStyle=o.tooltipTextColor||"#f9fafb",t.textAlign="left",t.textBaseline="top",t.fillText(`Point #${y+1}`,R+C,L+M);let D=L+M+E+2;t.font="9px Inter, system-ui, sans-serif",S.forEach(P=>{t.beginPath(),t.arc(R+C+4,D+5,3.5,0,Math.PI*2),t.fillStyle=P.color,t.fill(),t.fillStyle=o.tooltipTextColor||"#f9fafb",t.fillText(`${P.label}: `,R+C+12,D);const k=t.measureText(`${P.label}: `).width;t.font="bold 9px Inter, system-ui, sans-serif",t.fillStyle="#60a5fa",t.fillText(`${P.val.toFixed(1)}`,R+C+12+k,D),t.font="9px Inter, system-ui, sans-serif",D+=I}),t.restore()}}}_catmullRom(t,s,o,e,n){const i=(o-t)*.5,a=(e-s)*.5,r=n*n,l=n*r;return(2*s-2*o+i+a)*l+(-3*s+3*o-2*i-a)*r+i*n+s}normalizeOpacity(t){const s=typeof t=="number"?t:parseFloat(String(t));return isNaN(s)?1:s>1?Math.min(1,s/100):Math.max(0,Math.min(1,s))}createCanvasFill(t,s,o,e){var n,i,a;if(!s||s.type==="None")return null;if(typeof s=="string")return s;if(s.type==="Solid"&&s.color){const r=s.color,f=(((i=(n=this.artboard)==null?void 0:n.tokens)==null?void 0:i.colors)||{})[r]||r;return t.fillStyle=f,f}if((s.type==="LinearGradient"||s.type==="RadialGradient"||s.type==="AngularGradient"||s.type==="DiamondGradient")&&s.stops){const r=(l,f=100)=>{var b,S;const u=(((S=(b=this.artboard)==null?void 0:b.tokens)==null?void 0:S.colors)||{})[l]||l,g=this.normalizeOpacity(s.opacity??100),d=this.normalizeOpacity(f)*g;if(d>=1&&u.startsWith("#"))return u;const w=u.startsWith("#")?u.replace("#",""):"ffffff",y=parseInt(w.substring(0,2),16),c=parseInt(w.substring(2,4),16),v=parseInt(w.substring(4,6),16);return`rgba(${y}, ${c}, ${v}, ${d})`};if(s.type==="LinearGradient"){let l=0,f=-e/2,p=0,u=e/2;if(s.angle!==void 0&&(!s.start||!s.end)){const h=(s.angle-90)*Math.PI/180,d=Math.max(o,e)/2;l=Math.cos(h)*-d,f=Math.sin(h)*-d,p=Math.cos(h)*d,u=Math.sin(h)*d}else if(s.start||s.end){const h=(d,w,y)=>Array.isArray(d)?d[w]??.5:d&&typeof d=="object"?d[y]??.5:.5;l=h(s.start,0,"x")*o-o/2,f=h(s.start,1,"y")*e-e/2,p=h(s.end,0,"x")*o-o/2,u=h(s.end,1,"y")*e-e/2}Math.abs(l-p)<.001&&Math.abs(f-u)<.001&&(l=0,f=-e/2,p=0,u=e/2);const g=t.createLinearGradient(l,f,p,u);if(s.stops.forEach(h=>{const d=h.offset!==void 0?h.offset:h.pos!==void 0?h.pos:h.position!==void 0?h.position:0,w=r(h.color||"#000000",h.opacity??100);g.addColorStop(Math.max(0,Math.min(1,d)),w)}),s.gradientTransform&&g.setTransform){const[h,d,w,y,c,v]=s.gradientTransform;g.setTransform({a:h,b:d,c:w,d:y,e:c,f:v})}return g}else if(s.type==="RadialGradient"){const l=(h,d,w)=>Array.isArray(h)?h[d]??.5:h&&typeof h=="object"?h[w]??.5:.5,f=l(s.center,0,"x")*o-o/2,p=l(s.center,1,"y")*e-e/2,u=(s.radius??.5)*Math.max(o,e),g=t.createRadialGradient(f,p,0,f,p,u);if(s.stops.forEach(h=>{const d=h.offset!==void 0?h.offset:h.pos!==void 0?h.pos:h.position!==void 0?h.position:0,w=r(h.color||"#000000",h.opacity??100);g.addColorStop(Math.max(0,Math.min(1,d)),w)}),s.gradientTransform&&g.setTransform){const[h,d,w,y,c,v]=s.gradientTransform;g.setTransform({a:h,b:d,c:w,d:y,e:c,f:v})}return g}else if(s.type==="AngularGradient"){const l=(h,d,w)=>Array.isArray(h)?h[d]??.5:h&&typeof h=="object"?h[w]??.5:.5,f=l(s.center||[.5,.5],0,"x")*o-o/2,p=l(s.center||[.5,.5],1,"y")*e-e/2,u=(s.degree||s.angle||0)*(Math.PI/180),g=(a=t.createConicGradient)==null?void 0:a.call(t,u,f,p);if(g){if(s.stops.forEach(h=>{const d=h.offset!==void 0?h.offset:h.pos!==void 0?h.pos:h.position!==void 0?h.position:0,w=r(h.color||"#000000",h.opacity??100);g.addColorStop(Math.max(0,Math.min(1,d)),w)}),s.gradientTransform&&g.setTransform){const[h,d,w,y,c,v]=s.gradientTransform;g.setTransform({a:h,b:d,c:w,d:y,e:c,f:v})}return g}}else if(s.type==="DiamondGradient"){const l=(h,d,w)=>Array.isArray(h)?h[d]??.5:h&&typeof h=="object"?h[w]??.5:.5,f=l(s.center||[.5,.5],0,"x")*o-o/2,p=l(s.center||[.5,.5],1,"y")*e-e/2,u=(s.radius??.5)*Math.max(o,e);t.save(),t.translate(f,p),t.rotate(Math.PI/4);const g=t.createRadialGradient(0,0,0,0,0,u);if(s.stops.forEach(h=>{const d=h.offset!==void 0?h.offset:h.pos!==void 0?h.pos:h.position!==void 0?h.position:0,w=r(h.color||"#000000",h.opacity??100);g.addColorStop(Math.max(0,Math.min(1,d)),w)}),s.gradientTransform&&g.setTransform){const[h,d,w,y,c,v]=s.gradientTransform;g.setTransform({a:h,b:d,c:w,d:y,e:c,f:v})}return t.scale(1/Math.SQRT2,1/Math.SQRT2),t.fillStyle=g,t.restore(),g}}if(s.type==="Pattern"&&s.url){let r=this.imageCache.get(s.url);if(r||(r=new Image,r.src=s.url,this.imageCache.set(s.url,r)),r.complete&&r.naturalWidth>0){const l=t.createPattern(r,"repeat");if(l&&(s.scaleX!==void 0||s.offsetX!==void 0)){const f=new DOMMatrix,p=s.scaleX??1,u=s.scaleY??1,g=s.offsetX??0,h=s.offsetY??0,d=s.rotation??0;f.translateSelf(g,h),f.rotateSelf(d),f.scaleSelf(p,u),l.setTransform(f)}return l}}return s.color||null}drawRoundRect(t,s,o,e,n,i){if(i===0||i===void 0||i===null){t.rect(s,o,e,n);return}let a=i;if(typeof a=="string")try{a=JSON.parse(a)}catch{a=parseFloat(a)||0}let r=0,l=0,f=0,p=0;typeof a=="number"?r=l=f=p=a:Array.isArray(a)?a.length===1?r=l=f=p=a[0]:a.length===2?(r=f=a[0],l=p=a[1]):a.length===3?(r=a[0],l=p=a[1],f=a[2]):a.length>=4&&(r=a[0],l=a[1],f=a[2],p=a[3]):a&&typeof a=="object"&&(r=a[0]??a.tl??a.corner_radius??a.cornerRadius??0,l=a[1]??a.tr??a.corner_radius??a.cornerRadius??0,f=a[2]??a.br??a.corner_radius??a.cornerRadius??0,p=a[3]??a.bl??a.corner_radius??a.cornerRadius??0);const u=Math.min(Math.abs(e)/2,Math.abs(n)/2);if(r=Math.min(Math.max(0,r),u),l=Math.min(Math.max(0,l),u),f=Math.min(Math.max(0,f),u),p=Math.min(Math.max(0,p),u),t.roundRect){t.roundRect(s,o,e,n,[r,l,f,p]);return}t.moveTo(s+r,o),t.lineTo(s+e-l,o),t.arcTo(s+e,o,s+e,o+l,l),t.lineTo(s+e,o+n-f),t.arcTo(s+e,o+n,s+e-f,o+n,f),t.lineTo(s+p,o+n),t.arcTo(s,o+n,s,o+n-p,p),t.lineTo(s,o+r),t.arcTo(s,o,s+r,o,r),t.closePath()}renderListView(t,s){var L,D,P,k,O,$,X,F,B,j;const o=this.objectStates.get(s.id)||{},e=o.options||s.options||{},n=o.width!==void 0?o.width:((L=s.geometry)==null?void 0:L.width)||200,i=o.height!==void 0?o.height:((D=s.geometry)==null?void 0:D.height)||300,a=-n/2,r=-i/2,l=e.cornerRadius!==void 0?e.cornerRadius:o.cornerRadius!==void 0?o.cornerRadius:o.corner_radius??e.corner_radius??((P=s.geometry)==null?void 0:P.cornerRadius)??((k=s.geometry)==null?void 0:k.corner_radius)??0,f=e.orientation||"vertical",p=this.getResolvedListViewItems(s,e),u=e.itemGap??10,g=e.itemHeight??50,h=e.itemWidth??200,d=e.scrollOffset??0,w=e.padding??0,y=e.glassEffect!==!1,c=e.accentColor||"#3b82f6",v=e.itemTextColor||"#333333",b=e.itemBackgroundColor||"#ffffff",S=e.hoveredIndex??null,C=e.activeItemIndex??null,M=e.glowIntensity??0,I=e.glowColor||"#3b82f6",E=typeof I=="string"?I:I.color||(($=(O=I.stops)==null?void 0:O[0])==null?void 0:$.color)||"#3b82f6",_=e.opacity!==void 0?e.opacity:s.opacity!==void 0?s.opacity:1;if(t.save(),t.globalAlpha*=_,M>0){const z=t.getTransform(),q=Math.sqrt(z.a*z.a+z.b*z.b)||1;t.shadowColor=E,t.shadowBlur=M*2*q,t.shadowOffsetX=0,t.shadowOffsetY=0}if(y){const z=e.listBackgroundColor||"rgba(31, 41, 55, 0.4)",q=this.createCanvasFill(t,z,n,i);t.fillStyle=q||"rgba(31, 41, 55, 0.4)",t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)||t.fill();const J=t.createLinearGradient(a,r,a+n,r+i);J.addColorStop(0,"rgba(255, 255, 255, 0.15)"),J.addColorStop(.5,"rgba(255, 255, 255, 0.08)"),J.addColorStop(1,"rgba(255, 255, 255, 0.03)"),t.fillStyle=J,t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)||t.fill();const N=e.borderWidth??0;if(N>0&&e.borderColor&&e.borderColor!=="transparent"){const rt=this.createCanvasFill(t,e.borderColor,n,i);t.strokeStyle=rt||"rgba(255, 255, 255, 0.25)",t.lineWidth=N}else t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1;t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)||t.stroke()}else{const z=e.backgroundColor&&e.backgroundColor!=="transparent"?e.backgroundColor:e.listBackgroundColor||"transparent",q=this.createCanvasFill(t,z,n,i);if(q){t.fillStyle=q,t.beginPath();const J=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l);t.fill()}const U=e.borderWidth??0;if(U>0){const J=this.createCanvasFill(t,e.borderColor||"#cccccc",n,i);t.strokeStyle=J||"#cccccc",t.lineWidth=U,t.beginPath();const W=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l);t.stroke()}}t.shadowBlur=0;const T=e.clipContent!==!1&&e.listLayout!=="circular";if(T)if(t.save(),t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)&&e.containerShape==="custom")try{const q=new Path2D(e.containerPath);t.translate(a,r),t.scale(n/100,i/100),t.clip(q),t.scale(100/n,100/i),t.translate(-a,-r)}catch{}else t.clip();const A=typeof w=="number"?w:f==="vertical"?w[0]:w[3];let R=(f==="vertical"?r:a)+d+A;if(t.textBaseline="middle",p.forEach((z,q)=>{var ft,Tt,Ot,_t;const U=e.listLayout||"linear",J=U==="circular"?h:f==="vertical"?n:h,W=U==="circular"||f==="vertical"?g:i;let N=0,H=0,rt=0;if(U==="circular"){const Rt=p.length||1,$t=Math.PI*2/Rt,Ht=e.circularStartAngle||0,zt=e.circularRadius||100,qt=d*.01+Ht*Math.PI/180,Jt=q*$t+qt,se=a+n/2,ie=r+i/2;N=se+Math.cos(Jt)*zt-J/2,H=ie+Math.sin(Jt)*zt-W/2,rt=Jt+(e.itemRotation||0)*Math.PI/180}else N=f==="vertical"?a:R,H=f==="vertical"?R:r,rt=(e.itemRotation||0)*Math.PI/180;const It=S===q,mt=C===q,St=e.itemBorderWidth??0;t.save(),rt!==0&&(t.translate(N+J/2,H+W/2),t.rotate(rt),t.translate(-(N+J/2),-(H+W/2)));const pt=It?((ft=e.hoverStyle)==null?void 0:ft.scale)??1:mt?((Tt=e.activeStyle)==null?void 0:Tt.scale)??1:1;if(pt!==1&&(t.translate(N+J/2,H+W/2),t.scale(pt,pt),t.translate(-(N+J/2),-(H+W/2))),mt){const Rt=((Ot=e.activeStyle)==null?void 0:Ot.itemBackgroundColor)||e.activeBackgroundColor||(y?"rgba(255, 255, 255, 0.15)":"rgba(0, 0, 0, 0.1)"),$t=this.createCanvasFill(t,Rt,J,W);t.fillStyle=$t||(typeof Rt=="string"?Rt:"transparent"),t.beginPath(),this.drawCustomShape(t,e.activeItemShape||e.itemShape||"rectangle",e.activeItemShape==="custom"?e.activeItemPath||"":e.itemPath||"",N,H,J,W,e.itemCornerRadius??0)||t.fill()}else if(It){const Rt=((_t=e.hoverStyle)==null?void 0:_t.itemBackgroundColor)||e.hoverBackgroundColor||(y?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)"),$t=this.createCanvasFill(t,Rt,J,W);t.fillStyle=$t||(typeof Rt=="string"?Rt:"transparent"),t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",N,H,J,W,e.itemCornerRadius??0)||t.fill()}else if(b!=="transparent"){const Rt=this.createCanvasFill(t,b,J,W);t.fillStyle=Rt||(typeof b=="string"?b:"transparent"),t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",N,H,J,W,e.itemCornerRadius??0)||t.fill()}if(St>0&&e.itemBorderColor&&e.itemBorderColor!=="transparent"){const Rt=this.createCanvasFill(t,e.itemBorderColor,J,W);t.strokeStyle=Rt||(typeof e.itemBorderColor=="string"?e.itemBorderColor:"#cccccc"),t.lineWidth=St,t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",N,H,J,W,e.itemCornerRadius??0)||t.stroke()}if(mt){const Rt=this.createCanvasFill(t,c,f==="vertical"?3:J,f==="vertical"?W:3);t.fillStyle=Rt||c,f==="vertical"?t.fillRect(N,H,3,W):t.fillRect(N,H+W-3,J,3)}const kt=mt?"#ffffff":y?"rgba(255, 255, 255, 0.9)":v;t.fillStyle=kt,t.font=mt||It?"600 14px Inter, sans-serif":"400 14px Inter, sans-serif";const Bt=typeof z=="string"?z:(z==null?void 0:z.label)||`Item ${q+1}`,vt=N+(f==="vertical"?16:J/2),Dt=H+W/2;f==="horizontal"||U==="circular"?t.textAlign="center":t.textAlign="left";const Z=U==="circular"?N+J/2:vt;t.fillText(Bt,Z,Dt),t.restore(),t.beginPath(),R+=(f==="vertical"?g:h)+u}),T&&t.restore(),e.showScrollbar!==!1){const z=typeof w=="number"?w:f==="vertical"?w[0]:w[3],U=(p.length||0)*(f==="vertical"?g:h)+Math.max(0,(p.length||0)-1)*u+z*2,J=f==="vertical"?i:n,W=e.listLayout||"linear",N=e.containerShape==="circle"||W==="circular",H=e.scrollbarColor||"rgba(255,255,255,0.3)";let rt=typeof H=="object"?H.color||((F=(X=H.stops)==null?void 0:X[0])==null?void 0:F.color)||"rgba(255,255,255,0.3)":H;const It=((j=(B=this.artboard)==null?void 0:B.tokens)==null?void 0:j.colors)||{};It[rt]&&(rt=It[rt]);const mt=e.scrollbarWidth||2;if(t.save(),N){const St=Math.min(n,i)/2-mt/2-2,pt=a+n/2,kt=r+i/2;if(t.strokeStyle=rt,t.lineWidth=mt,t.lineCap="round",t.beginPath(),W==="circular"){const Bt=Math.PI/4,vt=-(d*.01)-Math.PI/2;t.arc(pt,kt,St,vt,vt+Bt)}else{const Bt=Math.PI/2,vt=U>0?Math.min(1,J/U):1,Dt=Bt*vt,Z=U>0?-d/U*Bt:0,Tt=-Math.PI/4+Z;t.arc(pt,kt,St,Tt,Tt+Dt)}t.stroke()}else{let St=J,pt=0;if(U>J){const kt=J/U;St=Math.max(16,J*kt);const Bt=J-St,vt=U-J;pt=vt>0?Math.max(0,Math.min(Bt,-d/vt*Bt)):0}if(t.fillStyle=rt,f==="vertical"){const kt=a+n-mt-2,Bt=r+pt,vt=mt,Dt=St;if(mt>2){t.beginPath();const Z=Math.min(mt/2,St/2);if(t.roundRect)try{t.roundRect(kt,Bt,vt,Dt,Z),t.fill()}catch{t.fillRect(kt,Bt,vt,Dt)}else t.fillRect(kt,Bt,vt,Dt)}else t.fillRect(kt,Bt,vt,Dt)}else{const kt=a+pt,Bt=r+i-mt-2,vt=St,Dt=mt;if(mt>2){t.beginPath();const Z=Math.min(mt/2,St/2);if(t.roundRect)try{t.roundRect(kt,Bt,vt,Dt,Z),t.fill()}catch{t.fillRect(kt,Bt,vt,Dt)}else t.fillRect(kt,Bt,vt,Dt)}else t.fillRect(kt,Bt,vt,Dt)}}t.restore()}t.beginPath(),t.restore()}drawCustomShape(t,s,o,e,n,i,a,r){if(s==="circle"){const l=Math.min(i,a)/2;return t.arc(e+i/2,n+a/2,l,0,Math.PI*2),!1}else if(s==="pill"){const l=Math.min(i,a)/2;return this.drawListViewRect(t,e,n,i,a,l),!1}else if(s==="custom"&&o)try{const l=new Path2D(o);return t.save(),t.translate(e,n),t.scale(i/100,a/100),t.fill(l),t.restore(),!0}catch{return this.drawListViewRect(t,e,n,i,a,r),!1}return this.drawListViewRect(t,e,n,i,a,r),!1}updateListViewScrollFromPointer(t){var b,S,C,M;if(!this._lastPointerPos||!this._prevPointerPos)return;const s=this.objectStates.get(t.id);s&&!s.options&&(s.options=JSON.parse(JSON.stringify(t.options||{})));const o=(s==null?void 0:s.options)||t.options||{},e=o.orientation||"vertical",n=this._lastPointerPos.x-this._prevPointerPos.x,i=this._lastPointerPos.y-this._prevPointerPos.y;let a=o.scrollOffset||0;const r=this.getResolvedListViewItems(t,o),l=o.itemGap??10,f=o.itemHeight??50,p=o.itemWidth??200,u=(s==null?void 0:s.width)!==void 0?s.width:((b=t.geometry)==null?void 0:b.width)||200,g=(s==null?void 0:s.height)!==void 0?s.height:((S=t.geometry)==null?void 0:S.height)||300,h=typeof o.padding=="number"?o.padding:e==="vertical"?((C=o.padding)==null?void 0:C[0])||0:((M=o.padding)==null?void 0:M[3])||0,w=(r.length||0)*(e==="vertical"?f:p)+Math.max(0,(r.length||0)-1)*l+h*2,y=e==="vertical"?g:u,c=Math.max(0,w-y);if(this.draggingListViewIsScrollbar&&o.listLayout!=="circular"){const I=w>0?y/w:1,E=Math.max(16,y*I),_=Math.max(1,y-E),T=c>0?c/_:1;e==="vertical"?a-=i*T:a-=n*T}else e==="vertical"?a+=i:a+=n;if((o.listLayout||"linear")==="circular"){o.scrollOffset=a,s&&s.options&&(s.options.scrollOffset=a),t.options&&(t.options.scrollOffset=a);return}a>0&&(a=0),a<-c&&(a=-c),o.scrollOffset=a,s&&s.options&&(s.options.scrollOffset=a),t.options&&(t.options.scrollOffset=a)}updateListViewHoverFromPointer(t,s,o){const e=this.getListViewItemIndexAtPointer(t,s,o),n=this.objectStates.get(t.id);if(n&&n.options)n.options.hoveredIndex!==e&&(n.options.hoveredIndex=e);else{const i=t.options||{};i.hoveredIndex!==e&&(i.hoveredIndex=e)}}getListViewItemIndexAtPointer(t,s,o){var P,k;const e=this.objectStates.get(t.id),n=(e==null?void 0:e.options)||t.options||{},i=this.getResolvedListViewItems(t,n);if(i.length===0)return null;const a=(e==null?void 0:e.width)!==void 0?e.width:((P=t.geometry)==null?void 0:P.width)||200,r=(e==null?void 0:e.height)!==void 0?e.height:((k=t.geometry)==null?void 0:k.height)||300,l=n.orientation||"vertical",f=n.itemGap??10,p=n.itemHeight??50,u=n.itemWidth??200,g=n.scrollOffset??0,h=n.padding??0,d=this.getWorldTransform(t.id),w=s-d.x,y=o-d.y,c=-d.rotation*(Math.PI/180),v=Math.cos(c),b=Math.sin(c),S=w*v-y*b,C=w*b+y*v,M=-a/2,I=-r/2,E=typeof h=="number"?h:l==="vertical"?h[0]:h[3];let _=(l==="vertical"?I:M)+g+E;const T=n.listLayout||"linear",A=i.length||1,R=Math.PI*2/A,Y=n.circularStartAngle||0,L=n.circularRadius||100,D=g*.01+Y*Math.PI/180;for(let O=0;O<i.length;O++){const $=T==="circular"?u:l==="vertical"?a:u,X=T==="circular"||l==="vertical"?p:r;let F=0,B=0,j=0;if(T==="circular"){const z=O*R+D,q=M+a/2,U=I+r/2;F=q+Math.cos(z)*L-$/2,B=U+Math.sin(z)*L-X/2,j=z+(n.itemRotation||0)*Math.PI/180}else F=l==="vertical"?M:_,B=l==="vertical"?_:I,j=(n.itemRotation||0)*Math.PI/180;if(j!==0){const z=F+$/2,q=B+X/2,U=S-z,J=C-q,W=-j,N=U*Math.cos(W)-J*Math.sin(W)+z,H=U*Math.sin(W)+J*Math.cos(W)+q;if(N>=F&&N<=F+$&&H>=B&&H<=B+X)return O}else if(S>=F&&S<=F+$&&C>=B&&C<=B+X)return O;_+=(l==="vertical"?p:u)+f}return null}drawListViewRect(t,s,o,e,n,i){this.drawRoundRect(t,s,o,e,n,i)}solveBehaviors(t){if(!this.artboard)return;if(!this._lastPointerPos){this.frameCount%60;return}const{x:s,y:o}=this._lastPointerPos;this.artboard.objects.forEach(e=>{if(!e.behaviors||e.behaviors.length===0)return;const n=this.objectStates.get(e.id);n&&e.behaviors.forEach(i=>{var u,g,h,d,w,y,c,v,b,S,C,M,I,E,_,T,A,R,Y,L,D,P,k,O,$,X,F,B,j,z,q,U,J,W,N,H,rt,It,mt,St,pt,kt,Bt,vt,Dt,Z,ft,Tt,Ot,_t,Rt,$t,Ht,zt,qt,Jt,se,ie,Se,Pe,me,_e,Me,Zt,Le,Re,ve,ae,Oe,pe,bt,at,Ct,K,ot,G,V,Q,tt,ht,Et,Yt,jt,Xt,yt,x,wt,Vt,lt,gt,ut,he,ne,Mt,Gt,Pt,Nt,Ft,fe,ue,Ee,te,re,oe,$e,Be,We,xe,Ye,De,Ve,ee,ge,Ce,Xe,Ne,Ie,we;if(!i.enabled)return;const a=i.startTime||0,r=i.endTime||1/0;if(this.currentTime<a||this.currentTime>r)return;const l=n.x-s,f=n.y-o,p=Math.sqrt(l*l+f*f);if(this.frameCount%240===0&&Math.random()<.1&&this.log(`[ExodeUI] Executing ${i.type} on ${e.name}`),i.type===st.Proximity){const et=((u=i.settings)==null?void 0:u.radius)||300,it=((g=i.settings)==null?void 0:g.falloff)||"smooth";let nt=0;p<et&&(it==="linear"?nt=1-p/et:nt=Math.pow(1-p/et,2)),i.sensors.forEach(dt=>{this.applyBehaviorSensor(n,dt,nt,t,i.settings,e,l,f,p)})}else if(i.type===st.Magnetic){const et=((h=i.settings)==null?void 0:h.radius)||400,it=((d=i.settings)==null?void 0:d.strength)||.5;if(p<et&&p>5){const nt=1-p/et,dt=l*nt*it,Wt=f*nt*it;n.x-=dt*t*10,n.y-=Wt*t*10}}else if(i.type===st.Repel){const et=((w=i.settings)==null?void 0:w.radius)||300,it=((y=i.settings)==null?void 0:y.strength)||1;if(p<et){const nt=Math.pow(1-p/et,2);n.x+=l/(p||1)*nt*60*it*t*5,n.y+=f/(p||1)*nt*60*it*t*5}}else if(i.type===st.Orbit){const et=((c=i.settings)==null?void 0:c.speed)||1,it=((v=i.settings)==null?void 0:v.radius)||30,nt=this.currentTime*et*Math.PI*2;n.x+=Math.cos(nt)*it*t*5,n.y+=Math.sin(nt)*it*t*5,n.rotation+=2*t*5}else if(i.type===st.Vortex){const et=((b=i.settings)==null?void 0:b.radius)||400,it=((S=i.settings)==null?void 0:S.speed)||2,nt=((C=i.settings)==null?void 0:C.strength)||1;if(p<et){const dt=Math.pow(1-p/et,1.5),Wt=this.currentTime*it*Math.PI*2,xt=Math.cos(Wt)*30-l*.4,Ut=Math.sin(Wt)*30-f*.4;n.x+=xt*dt*nt*t*5,n.y+=Ut*dt*nt*t*5,n.rotation+=5*dt*nt*t*5,n.scale_x*=1-dt*.1*nt*t,n.scale_y*=1-dt*.1*nt*t}}else if(i.type===st.Fluid){const et=((M=i.settings)==null?void 0:M.radius)||300,it=((I=i.settings)==null?void 0:I.strength)||1;if(p<et){const nt=Math.pow(1-p/et,1.2),dt=l/(p||1)*nt*1.2*it,Wt=f/(p||1)*nt*1.2*it;n.x+=dt*10*t*5,n.y+=Wt*10*t*5,n.scale_x*=1+nt*.3*it*t,n.scale_y*=1+nt*.3*it*t}}else if(i.type===st.Elastic){const et=((E=i.settings)==null?void 0:E.radius)||300,it=((_=i.settings)==null?void 0:_.strength)||1;if(p<et){const nt=1-p/et;n.scale_x*=1+nt*.4*it*t,n.scale_y*=1+nt*.4*it*t}}else if(i.type===st.Holographic){const et=n.x-this.canvasWidth/2,it=n.y-this.canvasHeight/2,nt=((T=i.settings)==null?void 0:T.factor)||25;if(n.x-=et/1e3*nt*t*5,n.y-=it/1e3*nt*t*5,n.style){const dt=1-Math.min(1,p/400);n.style.exposure=(n.style.exposure||1)+dt*.5*t}}else if(i.type===st.Sticky){const et=((A=i.settings)==null?void 0:A.radius)||80,it=((R=i.settings)==null?void 0:R.strength)||1;if(p<et){const nt=Math.pow(1-p/et,2);n.x-=l*nt*it*t*10,n.y-=f*nt*it*t*10,n.scale_x*=1-nt*.1*it*t,n.scale_y*=1-nt*.1*it*t}}else if(i.type===st.Dilation){const et=((Y=i.settings)==null?void 0:Y.size)||120,it=((L=i.settings)==null?void 0:L.strength)||1;if(p<et){const nt=1-p/et;n.scale_x*=1+nt*.5*it*t,n.scale_y*=1+nt*.5*it*t}}else if(i.type===st.Parallax){const et=((D=i.settings)==null?void 0:D.factor)||15,it=((P=i.settings)==null?void 0:P.strength)||1,nt=this.canvasWidth/2,dt=this.canvasHeight/2,Wt=this._lastPointerPos||{x:nt,y:dt},xt=(Wt.x-nt)/nt,Ut=(Wt.y-dt)/dt,de=(((k=e.transform)==null?void 0:k.x)??0)+xt*et*it,ke=(((O=e.transform)==null?void 0:O.y)??0)+Ut*et*it,Fe=((($=e.transform)==null?void 0:$.rotate_x)??0)-Ut*et*1.5*it,ye=(((X=e.transform)==null?void 0:X.rotate_y)??0)+xt*et*1.5*it,Ae=Math.min(1,10*t);n.x=this.lerp(n.x??((F=e.transform)==null?void 0:F.x)??0,de,Ae),n.y=this.lerp(n.y??((B=e.transform)==null?void 0:B.y)??0,ke,Ae),n.rotate_x=this.lerp(n.rotate_x??((j=e.transform)==null?void 0:j.rotate_x)??0,Fe,Ae),n.rotate_y=this.lerp(n.rotate_y??((z=e.transform)==null?void 0:z.rotate_y)??0,ye,Ae)}else if(i.type===st.Fold){if(p<300){const et=1-p/300,it=(l>0?-1:1)*et*10,nt=1-et*.1,dt=f/300*et*20,Wt=-(l/300)*et*20,xt=Math.min(1,10*t);n.skew_x=this.lerp(n.skew_x??((q=e.transform)==null?void 0:q.skew_x)??0,it,xt),n.scale_y=this.lerp(n.scale_y??((U=e.transform)==null?void 0:U.scale_y)??1,(((J=e.transform)==null?void 0:J.scale_y)??1)*nt,xt),n.rotate_x=this.lerp(n.rotate_x??((W=e.transform)==null?void 0:W.rotate_x)??0,dt,xt),n.rotate_y=this.lerp(n.rotate_y??((N=e.transform)==null?void 0:N.rotate_y)??0,Wt,xt),n.style=n.style||{...e.style},n.style.artEffect={enabled:!0,type:"fold_overlay",intensity:((H=i.settings)==null?void 0:H.opacity)??.5}}}else if(i.type===st.Crumple){if(p<300){const et=1-p/300,it=et*(Math.random()-.5)*5,nt=et*(Math.random()-.5)*.05,dt=Math.min(1,15*t);n.skew_x=this.lerp(n.skew_x??((rt=e.transform)==null?void 0:rt.skew_x)??0,it,dt),n.scale_x=this.lerp(n.scale_x??((It=e.transform)==null?void 0:It.scale_x)??1,(((mt=e.transform)==null?void 0:mt.scale_x)??1)*(1+nt),dt),n.scale_y=this.lerp(n.scale_y??((St=e.transform)==null?void 0:St.scale_y)??1,(((pt=e.transform)==null?void 0:pt.scale_y)??1)*(1+nt),dt),n.style=n.style||{...e.style},n.style.artEffect={enabled:!0,type:"crumple_overlay",intensity:((kt=i.settings)==null?void 0:kt.intensity)??1,scale:((Bt=i.settings)==null?void 0:Bt.scale)??2}}}else if(i.type===st.Squash){const et=((vt=i.settings)==null?void 0:vt.strength)||.8;p<(e.width||100)&&this.isMouseDown?(n.scale_y=this.lerp(n.scale_y??1,(((Dt=e.transform)==null?void 0:Dt.scale_y)??1)*et,.3),n.scale_x=this.lerp(n.scale_x??1,(((Z=e.transform)==null?void 0:Z.scale_x)??1)*(1+(1-et)*.4),.3)):(n.scale_y=this.lerp(n.scale_y??1,((ft=e.transform)==null?void 0:ft.scale_y)??1,.2),n.scale_x=this.lerp(n.scale_x??1,((Tt=e.transform)==null?void 0:Tt.scale_x)??1,.2))}else if(i.type===st.TextCounter){const et=((Ot=i.settings)==null?void 0:Ot.duration)||2,it=((_t=i.settings)==null?void 0:_t.from)||0,nt=((Rt=i.settings)==null?void 0:Rt.to)||100;i._runtimeStart===void 0&&(i._runtimeStart=this.currentTime);const dt=this.currentTime-i._runtimeStart,Wt=Math.min(1,dt/et),xt=Math.floor(it+(nt-it)*Wt);if((($t=e.geometry)==null?void 0:$t.type)==="Text"){const Ut=((Ht=i.settings)==null?void 0:Ht.prefix)||"",de=((zt=i.settings)==null?void 0:zt.suffix)||"";n.geometry||(n.geometry={...e.geometry}),n.geometry.text=`${Ut}${xt}${de}`}}else if(i.type===st.Spotlight){const et=((qt=i.settings)==null?void 0:qt.radius)||250,it=((Jt=i.settings)==null?void 0:Jt.strength)||1.5;if(p<et){const nt=Math.pow(1-p/et,2);n.style||(n.style={...e.style}),n.style.adjustments||(n.style.adjustments={...(se=e.style)==null?void 0:se.adjustments}),n.style.adjustments.exposure=(((Se=(ie=e.style)==null?void 0:ie.adjustments)==null?void 0:Se.exposure)||0)+nt*it*50}else(Pe=n.style)!=null&&Pe.adjustments&&(n.style.adjustments.exposure=this.lerp(n.style.adjustments.exposure||0,((_e=(me=e.style)==null?void 0:me.adjustments)==null?void 0:_e.exposure)||0,.1))}else if(i.type===st.Noise||i.type===st.Float){const et=(((Me=i.settings)==null?void 0:Me.frequency)||((Zt=i.settings)==null?void 0:Zt.speed)||1)*.002,it=(((Le=i.settings)==null?void 0:Le.amplitude)||((Re=i.settings)==null?void 0:Re.range)||50)*(((ve=i.settings)==null?void 0:ve.strength)||1),nt=Date.now();n.x+=Math.sin(nt*et)*it*t,n.y+=Math.cos(nt*et*.8)*it*t,n.rotation+=Math.sin(nt*et*.5)*5*t}else if(i.type===st.Pulse){const et=(((ae=i.settings)==null?void 0:ae.speed)||1)*.005,it=(((Oe=i.settings)==null?void 0:Oe.scale)||1.2)-1,nt=Math.sin(Date.now()*et),dt=((pe=i.settings)==null?void 0:pe.strength)||1;n.scale_x*=1+nt*it*dt*t,n.scale_y*=1+nt*it*dt*t,n.style&&(n.style.exposure=(n.style.exposure||1)+Math.max(0,nt)*.1*dt*t)}else if(i.type===st.Draggable){if(!this.draggingBehaviors.has(e.id)){const it=((bt=i.settings)==null?void 0:bt.radius)||150;if(p<it){const nt=((at=i.settings)==null?void 0:at.strength)||1,dt=Math.max(0,1-p/it);this.applyBehaviorSensor(n,ce.PositionX,dt*nt,t,i.settings,e,l,f,p),this.applyBehaviorSensor(n,ce.PositionY,dt*nt,t,i.settings,e,l,f,p)}}}else if(i.type===st.Scroll){const et=((Ct=i.settings)==null?void 0:Ct.axis)||"vertical",it=((K=i.settings)==null?void 0:K.factor)||.5,nt=((ot=i.settings)==null?void 0:ot.strength)||1,dt=((G=i.settings)==null?void 0:G.scaleFactor)||0;(et==="vertical"||et==="both")&&(n.y+=this.scrollOffset.y*it*nt*t),(et==="horizontal"||et==="both")&&(n.x+=this.scrollOffset.x*it*nt*t),dt!==0&&(n.scale_x*=1+this.scrollOffset.y*dt*t,n.scale_y*=1+this.scrollOffset.y*dt*t)}else if(i.type===st.LookAt){const et=((V=i.settings)==null?void 0:V.factor)||1,it=((Q=i.settings)==null?void 0:Q.strength)||1,nt=Math.atan2(-f,-l)*(180/Math.PI),dt=n.rotation,Wt=(nt-dt+180)%360-180;n.rotation+=Wt*et*it*t*10}else if(i.type===st.Scan){const et=(((tt=i.settings)==null?void 0:tt.speed)||1)*.004,it=((ht=i.settings)==null?void 0:ht.strength)||1,nt=(Math.sin(Date.now()*et)+1)/2;n.style&&(n.style.exposure=(n.style.exposure||1)+nt*it*t*5),n.x+=(nt-.5)*20*it*t}else if(i.type===st.Glint)n.style=n.style||{...e.style},n.style.artEffect={enabled:!0,type:"glint_overlay",intensity:((Et=i.settings)==null?void 0:Et.strength)??.8};else if(i.type===st.Ratchet){const et=((Yt=i.settings)==null?void 0:Yt.steps)||12,it=(((jt=i.settings)==null?void 0:jt.speed)||1)*30,nt=Math.floor(n.rotation/(360/et))*(360/et);n.rotation=this.lerp(n.rotation,nt+it*t,.1)}else if(i.type===st.Jitter&&p<300){const et=((Xt=i.settings)==null?void 0:Xt.strength)||1,it=(((yt=i.settings)==null?void 0:yt.intensity)||5)*et;n.x+=(Math.random()-.5)*it*t*60,n.y+=(Math.random()-.5)*it*t*60,n.rotation+=(Math.random()-.5)*it*t*120}else if(i.type===st.Follower){const et=(x=i.settings)==null?void 0:x.targetId;if(et){const it=this.objectStates.get(et);if(it){const nt=((wt=i.settings)==null?void 0:wt.stiffness)||.1,dt=it.x-n.x,Wt=it.y-n.y;n.x+=dt*nt*t*60,n.y+=Wt*nt*t*60}}}else if(i.type===st.Wrap)n.x<0?n.x=this.canvasWidth:n.x>this.canvasWidth&&(n.x=0),n.y<0?n.y=this.canvasHeight:n.y>this.canvasHeight&&(n.y=0);else if(i.type===st.Gravity){const et=((Vt=i.settings)==null?void 0:Vt.strength)||9.8;n.y+=et*t*10}else if(i.type===st.Velocity){const et=((lt=i.settings)==null?void 0:lt.vx)||0,it=((gt=i.settings)==null?void 0:gt.vy)||0;n.x+=et*t*10,n.y+=it*t*10}else if(i.type===st.Shear){const et=((ut=i.settings)==null?void 0:ut.strength)||1,it=((he=i.settings)==null?void 0:he.radius)||300;if(p<it){const nt=1-p/it;n.skew_x=this.lerp(n.skew_x||0,(((ne=e.transform)==null?void 0:ne.skew_x)||0)+nt*et*30,.1)}else n.skew_x=this.lerp(n.skew_x||0,((Mt=e.transform)==null?void 0:Mt.skew_x)||0,.05)}else if(i.type===st.Lens){const et=((Gt=i.settings)==null?void 0:Gt.radius)||200,it=((Pt=i.settings)==null?void 0:Pt.strength)||.5;if(p<et){const nt=Math.pow(1-p/et,2);n.scale_x=this.lerp(n.scale_x??1,(((Nt=e.transform)==null?void 0:Nt.scale_x)??1)*(1+nt*it),.2),n.scale_y=this.lerp(n.scale_y??1,(((Ft=e.transform)==null?void 0:Ft.scale_y)??1)*(1+nt*it),.2)}else n.scale_x=this.lerp(n.scale_x??1,((fe=e.transform)==null?void 0:fe.scale_x)??1,.1),n.scale_y=this.lerp(n.scale_y??1,((ue=e.transform)==null?void 0:ue.scale_y)??1,.1)}else if(i.type===st.LayoutAnimation){const et=((Ee=i.settings)==null?void 0:Ee.watchProperties)||["x","y","scale_x","scale_y","opacity","rotation"],it=((te=i.settings)==null?void 0:te.duration)||.3;this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const nt=this._layoutAnimCache.get(e.id);for(const dt of et){const Wt=this.getObjectProperty(n,e,dt);if(Wt===void 0)continue;const xt=nt.get(dt);if(!xt)nt.set(dt,{from:Wt,to:Wt,startTime:this.currentTime,duration:0});else if(xt.to!==Wt){const de=this.getObjectProperty(n,e,dt);nt.set(dt,{from:de??xt.from,to:Wt,startTime:this.currentTime,duration:((re=i.settings)==null?void 0:re.duration)??it})}const Ut=nt.get(dt);if(Ut.duration>0&&Ut.from!==Ut.to){const de=this.currentTime-Ut.startTime,ke=Math.min(1,de/Ut.duration),Fe=this.applyEasing(ke,((oe=i.settings)==null?void 0:oe.easing)||"easeOutCubic"),ye=Ut.from+(Ut.to-Ut.from)*Fe;this.setObjectProperty(n,e,dt,ye)}}}else if(i.type===st.StateReactive){this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const et=this._layoutAnimCache.get(e.id),it=(($e=i.settings)==null?void 0:$e.defaultDuration)||.3,nt=["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 dt of nt){const Wt=this.getObjectProperty(n,e,dt);if(Wt===void 0||typeof Wt!="number")continue;const xt=et.get(dt);if(!xt)et.set(dt,{from:Wt,to:Wt,startTime:this.currentTime,duration:0});else if(xt.to!==Wt){const de=this.getObjectProperty(n,e,dt);et.set(dt,{from:de??xt.from,to:Wt,startTime:this.currentTime,duration:it})}const Ut=et.get(dt);if(Ut.duration>0&&Ut.from!==Ut.to){const de=this.currentTime-Ut.startTime,ke=Math.min(1,de/Ut.duration),Fe=this.applyEasing(ke,((Be=i.settings)==null?void 0:Be.defaultEasing)||"easeOutCubic"),ye=Ut.from+(Ut.to-Ut.from)*Fe;this.setObjectProperty(n,e,dt,ye)}}}else if(i.type===st.SpringChain){const et=((We=i.settings)==null?void 0:We.connections)||[],it=((xe=i.settings)==null?void 0:xe.globalDamping)||.3;this._springChainState.has(e.id)||this._springChainState.set(e.id,new Map);const nt=this._springChainState.get(e.id);for(const Wt of et){if(!nt.has(Wt.targetId)){const xt=this.objectStates.get(Wt.targetId);nt.set(Wt.targetId,{x:(xt==null?void 0:xt.x)??0,y:(xt==null?void 0:xt.y)??0,vx:0,vy:0})}nt.has(e.id)||nt.set(e.id,{x:n.x,y:n.y,vx:0,vy:0})}const dt=nt.get(e.id);if(dt){dt.x=n.x,dt.y=n.y;for(const Wt of et){const xt=nt.get(Wt.targetId);if(!xt)continue;const Ut=xt.x-dt.x,de=xt.y-dt.y,ke=Math.sqrt(Ut*Ut+de*de)||.001,ye=(ke-(Wt.restLength||50))*(Wt.stiffness||.8),Ae=Ut/ke*ye,Qe=de/ke*ye;dt.vx+=Ae*t*10,dt.vy+=Qe*t*10,xt.vx-=Ae*t*10,xt.vy-=Qe*t*10,dt.vx*=1-it*t*10,dt.vy*=1-it*t*10,xt.vx*=1-it*t*10,xt.vy*=1-it*t*10;const Te=this.objectStates.get(Wt.targetId);Te&&(Te.x+=xt.vx*t,Te.y+=xt.vy*t)}n.x+=dt.vx*t,n.y+=dt.vy*t}}else if(i.type===st.ParticleEmitter){const et=((Ye=i.settings)==null?void 0:Ye.rate)||10,it=((De=i.settings)==null?void 0:De.speed)||100,nt=((Ve=i.settings)==null?void 0:Ve.size)||5,dt=((ee=i.settings)==null?void 0:ee.lifetime)||2,Wt=((ge=i.settings)==null?void 0:ge.gravity)||0,xt=((Ce=i.settings)==null?void 0:Ce.color)||"#ffffff",Ut=((Xe=i.settings)==null?void 0:Xe.maxParticles)||200,de=(Ne=i.settings)!=null&&Ne.rateInputId?this.inputs.get(i.settings.rateInputId)??et:et,ke=(Ie=i.settings)!=null&&Ie.gravityInputId?this.inputs.get(i.settings.gravityInputId)??Wt:Wt,Fe=(we=i.settings)!=null&&we.speedInputId?this.inputs.get(i.settings.speedInputId)??it:it;this._emitterPools.has(e.id)||this._emitterPools.set(e.id,[]);const ye=this._emitterPools.get(e.id);let Ae=0;i._pendingBurst&&i._pendingBurst>0&&(Ae=i._pendingBurst,i._pendingBurst=0);const Qe=Math.floor(de*t)+(Ae||0);for(let Te=0;Te<Math.min(Qe,Ut-ye.length);Te++){const be=Math.random()*Math.PI*2,ms=Fe*(.5+Math.random()*.5);ye.push({x:n.x,y:n.y,vx:Math.cos(be)*ms,vy:Math.sin(be)*ms,life:0,maxLife:dt*(.5+Math.random()*.5),size:nt*(.5+Math.random()),color:xt,opacity:1})}for(let Te=ye.length-1;Te>=0;Te--){const be=ye[Te];be.vy+=ke*t*10,be.x+=be.vx*t,be.y+=be.vy*t,be.life+=t,be.opacity=Math.max(0,1-be.life/be.maxLife),be.life>=be.maxLife&&ye.splice(Te,1)}}})})}applyBehaviorSensor(t,s,o,e,n,i,a=0,r=0,l=1){var h,d,w,y,c,v,b,S,C,M,I,E,_,T,A,R,Y,L,D,P,k,O,$,X;const f=(n==null?void 0:n.intensity)||(n==null?void 0:n.strength)||1,p=Math.min(1,15*e),u=l>0?a/l:0,g=l>0?r/l:0;switch(s){case ce.Scale:{const F=((h=i==null?void 0:i.transform)==null?void 0:h.scale_x)??1,B=((d=i==null?void 0:i.transform)==null?void 0:d.scale_y)??1,j=F*(1+o*f*.4),z=B*(1+o*f*.4);t.scale_x=(t.scale_x??F)*(1-p)+j*p,t.scale_y=(t.scale_y??B)*(1-p)+z*p;break}case ce.Opacity:{const F=((w=i==null?void 0:i.transform)==null?void 0:w.opacity)??100,B=Math.max(0,Math.min(100,F-o*f*100));t.opacity=(t.opacity??F)*(1-p)+B*p;break}case ce.RotateZ:{const F=((y=i==null?void 0:i.transform)==null?void 0:y.rotation)??0,B=F+o*f*45;t.rotation=(t.rotation??F)*(1-p)+B*p;break}case ce.RotateX:{const F=((c=i==null?void 0:i.transform)==null?void 0:c.rotate_x)??0,B=F-g*o*f*60;t.rotate_x=(t.rotate_x??F)*(1-p)+B*p;break}case ce.RotateY:{const F=((v=i==null?void 0:i.transform)==null?void 0:v.rotate_y)??0,B=F+u*o*f*60;t.rotate_y=(t.rotate_y??F)*(1-p)+B*p;break}case ce.PositionX:{const F=((b=i==null?void 0:i.transform)==null?void 0:b.x)??0,B=F-u*o*f*40;t.x=(t.x??F)*(1-p)+B*p;break}case ce.PositionY:{const F=((S=i==null?void 0:i.transform)==null?void 0:S.y)??0,B=F-g*o*f*40;t.y=(t.y??F)*(1-p)+B*p;break}case ce.SkewX:{const F=((C=i==null?void 0:i.transform)==null?void 0:C.skew_x)??0,B=F+u*o*f*45;t.skew_x=(t.skew_x??F)*(1-p)+B*p,t.skew_x>85&&(t.skew_x=85),t.skew_x<-85&&(t.skew_x=-85);break}case ce.Blur:{t.style||(t.style={...i==null?void 0:i.style}),t.style.blur||(t.style.blur={...(M=i==null?void 0:i.style)==null?void 0:M.blur});const F=((E=(I=i==null?void 0:i.style)==null?void 0:I.blur)==null?void 0:E.amount)||0,B=F+o*((n==null?void 0:n.blur)||20)*f;t.style.blur.amount=(t.style.blur.amount??F)*(1-p)+B*p;break}case ce.Exposure:{t.style||(t.style={...i==null?void 0:i.style}),t.style.adjustments||(t.style.adjustments={...(_=i==null?void 0:i.style)==null?void 0:_.adjustments});const F=((A=(T=i==null?void 0:i.style)==null?void 0:T.adjustments)==null?void 0:A.exposure)||0,B=F+o*((n==null?void 0:n.exposure)||50)*f;t.style.adjustments.exposure=(t.style.adjustments.exposure??F)*(1-p)+B*p;break}case ce.HueShift:{t.style||(t.style={...i==null?void 0:i.style}),t.style.adjustments||(t.style.adjustments={...(R=i==null?void 0:i.style)==null?void 0:R.adjustments});const F=((L=(Y=i==null?void 0:i.style)==null?void 0:Y.adjustments)==null?void 0:L.hue)||0,B=F+o*((n==null?void 0:n.hue)||180)*f;t.style.adjustments.hue=(t.style.adjustments.hue??F)*(1-p)+B*p;break}case ce.Negative:{t.style||(t.style={...i==null?void 0:i.style}),t.style.adjustments||(t.style.adjustments={...(D=i==null?void 0:i.style)==null?void 0:D.adjustments});const F=((k=(P=i==null?void 0:i.style)==null?void 0:P.adjustments)==null?void 0:k.negative)||0,B=F+o*((n==null?void 0:n.negative)||100)*f;t.style.adjustments.negative=(t.style.adjustments.negative??F)*(1-p)+B*p;break}case ce.CornerRadius:{const F=((O=i==null?void 0:i.transform)==null?void 0:O.corner_radius)||0,B=F+o*f*50;t.corner_radius=(t.corner_radius??F)*(1-p)+B*p;break}case ce.StrokeWidth:{t.style||(t.style={...i==null?void 0:i.style});const F=(($=i==null?void 0:i.style)==null?void 0:$.borderWidth)||0,B=F+o*f*10;t.style.borderWidth=(t.style.borderWidth??F)*(1-p)+B*p;break}case ce.LetterSpacing:{t.geometry||(t.geometry={});const F=((X=i==null?void 0:i.geometry)==null?void 0:X.letterSpacing)||0,B=F+o*f*10;t.geometry.letterSpacing=(t.geometry.letterSpacing??F)*(1-p)+B*p;break}}}getObjectProperty(t,s,o){const e=o.replace(/\[(\d+)\]/g,".$1").split(".");let n=t;for(const i of e){if(n==null||typeof n!="object")return;if(i==="style"&&t.style===void 0){n=s.style;continue}n=n[i]}return typeof n=="number"?n:void 0}setObjectProperty(t,s,o,e){const n=o.replace(/\[(\d+)\]/g,".$1").split(".");let i=t;for(let r=0;r<n.length-1;r++){const l=n[r];if(i[l]===void 0||i[l]===null){const f=s,p=n.slice(0,r+1).reduce((h,d)=>h==null?void 0:h[d],f),u=n[r+1],g=!isNaN(Number(u));i[l]=p!==void 0?Array.isArray(p)?[...p]:{...p}:g?[]:{}}i=i[l]}const a=n[n.length-1];i!=null&&(i[a]=e)}applyEasing(t,s){switch(s){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,s,o){return t*(1-o)+s*o}deepMerge(t,s){if(!t)return s;if(!s)return t;if(typeof t!="object"||typeof s!="object"||t===null||s===null)return s;if(Array.isArray(s)){if(!Array.isArray(t))return s;const e=[...t];for(let n=0;n<s.length;n++)s[n]&&typeof s[n]=="object"&&!Array.isArray(s[n])&&t[n]&&typeof t[n]=="object"?e[n]=this.deepMerge(t[n],s[n]):e[n]=s[n];return e}const o={...t};for(const e in s)Object.prototype.hasOwnProperty.call(s,e)&&(s[e]&&typeof s[e]=="object"&&!Array.isArray(s[e])?o[e]=this.deepMerge(t[e],s[e]):Array.isArray(s[e])?o[e]=this.deepMerge(t[e],s[e]):o[e]=s[e]);return o}processFabricAdjustmentsCanvas(t,s,o,e){if(!e)return t;const n=(e.exposure||0)/100,i=(e.contrast||0)/100,a=(e.saturation||0)/100,r=(e.temperature||0)/200,l=(e.tint||0)/200,f=(e.highlights||0)/500,p=(e.shadows||0)/500,u=e.hue||0,g=(e.negative||0)/100,h=e.blur||0;if(!(n!==0||i!==0||a!==0||r!==0||l!==0||f!==0||p!==0||u!==0||g!==0||h>0))return t;const w=t.naturalWidth||Math.max(1,Math.round(s)),y=t.naturalHeight||Math.max(1,Math.round(o)),c=document.createElement("canvas");c.width=w,c.height=y;const v=c.getContext("2d");if(!v)return t;const b=[];h>0&&b.push(`blur(${h}px)`),u!==0&&b.push(`hue-rotate(${Math.round(u)}deg)`),b.length>0&&(v.filter=b.join(" ")),v.drawImage(t,0,0,w,y);try{const S=v.getImageData(0,0,w,y),C=S.data,M=C.length,I=n*255,E=i>=0?(1+i)/Math.max(.01,1-i):1+i,_=1+a,T=1+r-l/2,A=1+l,R=1-r-l/2,Y=1+f+p,L=p*25.5,D=1-g/50,P=(1-D)*255;for(let k=0;k<M;k+=4){let O=C[k],$=C[k+1],X=C[k+2];if(n!==0&&(O+=I,$+=I,X+=I),i!==0&&(O=(O-127.5)*E+127.5,$=($-127.5)*E+127.5,X=(X-127.5)*E+127.5),a!==0){const F=.2989*O+.587*$+.114*X;O=F+(O-F)*_,$=F+($-F)*_,X=F+(X-F)*_}(r!==0||l!==0)&&(O=O*T,$=$*A,X=X*R),(f!==0||p!==0)&&(O=O*Y+L,$=$*Y+L,X=X*Y+L),g!==0&&(O=O*D+P,$=$*D+P,X=X*D+P),C[k]=Math.min(255,Math.max(0,O)),C[k+1]=Math.min(255,Math.max(0,$)),C[k+2]=Math.min(255,Math.max(0,X))}return v.putImageData(S,0,0),c}catch{return c}}renderFittedImage(t,s,o,e,n,i,a="cover"){const r=s.naturalWidth||s.width||n,l=s.naturalHeight||s.height||i,f=r/l,p=n/i;let u=n,g=i,h=o,d=e;a==="cover"?f>p?(u=i*f,h=o-(u-n)/2):(g=n/f,d=e-(g-i)/2):a==="contain"&&(f>p?(g=n/f,d=e+(i-g)/2):(u=i*f,h=o+(n-u)/2)),t.drawImage(s,h,d,u,g)}}const ai=At.forwardRef(({artboard:m,src:t,style:s,autoPlay:o=!0,fit:e="Contain",alignment:n="Center",onReady:i,onTrigger:a,onInputUpdate:r,onComponentChange:l,onToggle:f,onInputChange:p,onInputFocus:u,onInputBlur:g,onLog:h,onLogicUpdate:d,onButtonClick:w,onGraphPointClick:y,currentTime:c,revision:v=0,scrollY:b,scrollX:S,mouseX:C,mouseY:M,isMouseDown:I,inputs:E,interactive:_=!0,onNavigation:T},A)=>{const R=At.useRef(null),Y=At.useRef(null);Y.current||(Y.current=new gs);const L=At.useRef(void 0),D=At.useRef(0),P=At.useRef(null),k=At.useRef(v),O=At.useRef(null),[,$]=At.useState(m||null),X=At.useRef(!0),F=At.useRef(o),B=At.useRef(c);At.useEffect(()=>{F.current=o},[o]),At.useEffect(()=>{B.current=c},[c]),At.useImperativeHandle(A,()=>R.current),At.useEffect(()=>(X.current=!0,()=>{X.current=!1,L.current&&cancelAnimationFrame(L.current)}),[]),At.useEffect(()=>{Y.current.setLayout(e,n)},[e,n]),At.useEffect(()=>{const W=Y.current;a&&W.setTriggerCallback(a),r&&W.setInputUpdateCallback((N,H)=>r({[N]:H})),l&&W.setComponentChangeCallback(N=>l(N)),f&&W.setToggleCallback(f),p&&W.setInputChangeCallback(p),u&&W.setInputFocusCallback(u),g&&W.setInputBlurCallback(g),h&&W.setOnLogCallback(N=>h(N,"info")),d&&W.setLogicUpdateCallback(d),w&&W.setButtonClickCallback(w),y&&W.setGraphPointClickCallback(N=>y(N.objectId,N)),T&&W.setNavigationCallback(T)},[a,r,l,f,p,u,g,h,d,w,y,T]),At.useEffect(()=>{(async()=>{let N=m;if(t&&!m)try{t.startsWith("{")?N=JSON.parse(t):N=await(await fetch(t)).json()}catch(H){console.error("[ExodeUI] Failed to load src:",H)}if(N){const H=Y.current,rt=N.id||N.name||"default";(P.current!==rt||k.current!==v||O.current!==N)&&(H.load(N),P.current=rt,k.current=v,O.current=N,$(N),D.current=-1,H.advance(0)),i&&i(H)}})()},[m,t,v]),At.useEffect(()=>{const W=N=>{if(!Y.current||!X.current)return;const H=Y.current,rt=R.current;if(!rt)return;const It=rt.getContext("2d");if(!It)return;const mt=N/1e3;D.current<0&&(D.current=mt),D.current===0&&(D.current=mt);let St=mt-D.current;St>.1&&(St=.1),D.current=mt;const pt=rt.getBoundingClientRect(),kt=window.devicePixelRatio||1,Bt=Math.round(pt.width*kt),vt=Math.round(pt.height*kt);(rt.width!==Bt||rt.height!==vt)&&(rt.width=Bt,rt.height=vt);try{F.current?H.advance(St):B.current!==void 0&&H.seek(B.current),H.render(It,rt.width,rt.height)}catch(Dt){console.error("[ExodeUICanvas] Error in animation loop:",Dt),h&&h(`[Error] Animation loop crashed: ${Dt}`,"error")}L.current=requestAnimationFrame(W)};return L.current=requestAnimationFrame(W),()=>{L.current&&cancelAnimationFrame(L.current)}},[]),At.useEffect(()=>{const W=Y.current;b!==void 0&&W.updateInput("scrollY",b),S!==void 0&&W.updateInput("scrollX",S),C!==void 0&&W.updateInput("mouseX",C),M!==void 0&&W.updateInput("mouseY",M),I!==void 0&&W.updateInput("isMouseDown",I),E&&Object.entries(E).forEach(([N,H])=>W.updateInput(N,H))},[b,S,C,M,I,E]);const j=(W,N)=>{if(!_||!R.current)return;W.stopPropagation(),"nativeEvent"in W&&W.nativeEvent&&typeof W.nativeEvent.stopImmediatePropagation=="function"?W.nativeEvent.stopImmediatePropagation():typeof W.stopImmediatePropagation=="function"&&W.stopImmediatePropagation();const H=R.current,rt=H.getBoundingClientRect(),It=W.clientX-rt.left,mt=W.clientY-rt.top,St=window.devicePixelRatio||1;(N==="click"||N==="down"||N==="up")&&h&&h(`[Canvas] Pointer ${N} at rect(${Math.round(It)},${Math.round(mt)}) mapped to buffer(${Math.round(It*St)},${Math.round(mt*St)})`,"info"),Y.current.handlePointerInput(N,It*St,mt*St,H.width,H.height)};At.useEffect(()=>{if(!_)return;const W=H=>{var rt,It,mt;((rt=document.activeElement)==null?void 0:rt.tagName)==="INPUT"||((It=document.activeElement)==null?void 0:It.tagName)==="TEXTAREA"||(mt=Y.current)==null||mt.handleKeyDown(H)},N=H=>{var rt,It,mt;((rt=document.activeElement)==null?void 0:rt.tagName)==="INPUT"||((It=document.activeElement)==null?void 0:It.tagName)==="TEXTAREA"||(mt=Y.current)==null||mt.handleKeyUp(H)};return window.addEventListener("keydown",W),window.addEventListener("keyup",N),()=>{window.removeEventListener("keydown",W),window.removeEventListener("keyup",N)}},[_]),At.useEffect(()=>{const W=R.current;if(!W||!_)return;const N=H=>{if(H.preventDefault(),H.stopPropagation(),Y.current){const rt=W.getBoundingClientRect(),It=window.devicePixelRatio||1,mt=(H.clientX-rt.left)*It,St=(H.clientY-rt.top)*It;let pt=H.deltaX,kt=H.deltaY;H.deltaMode===1?(pt*=25,kt*=25):H.deltaMode===2&&(pt*=100,kt*=100),Y.current.handlePointerInput("move",mt,St,W.width,W.height),Y.current.handleWheel(pt,kt,mt,St,W.width,W.height)}};return W.addEventListener("wheel",N,{passive:!1}),()=>{W.removeEventListener("wheel",N)}},[_]);const[z,q]=At.useState([]);At.useEffect(()=>{if(m&&m.objects){const W=m.objects.filter(N=>{var H,rt;return N.type==="Joystick"&&((H=N.inputBinding)==null?void 0:H.type)==="keyboard"&&((rt=N.inputBinding.keyboardConfig)==null?void 0:rt.showVirtualKeyboard)});q(W)}},[m]);const[,U]=At.useState(0);At.useEffect(()=>{if(z.length===0)return;let W;const N=()=>{U(H=>H+1),W=requestAnimationFrame(N)};return W=requestAnimationFrame(N),()=>cancelAnimationFrame(W)},[z.length]);const J=()=>z.map(W=>{const N=W.inputBinding.keyboardConfig,H=pt=>{var Bt;const kt={key:pt,code:pt,preventDefault:()=>{}};(Bt=Y.current)==null||Bt.handleKeyDown(kt)},rt=pt=>{var Bt;const kt={key:pt,code:pt,preventDefault:()=>{}};(Bt=Y.current)==null||Bt.handleKeyUp(kt)},It=Y.current,mt=pt=>It&&It.activeKeys?It.activeKeys.has(pt.toLowerCase()):!1,St=pt=>({width:"50px",height:"50px",background:pt?"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:pt?"none":"0 4px 6px rgba(0,0,0,0.1)"});return Qt.jsxs("div",{style:{position:"absolute",bottom:"40px",right:"40px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",pointerEvents:"auto",zIndex:100},children:[Qt.jsx("div",{style:St(mt(N.upKey)),onMouseDown:()=>H(N.upKey),onMouseUp:()=>rt(N.upKey),onMouseLeave:()=>rt(N.upKey),onTouchStart:pt=>{pt.preventDefault(),H(N.upKey)},onTouchEnd:pt=>{pt.preventDefault(),rt(N.upKey)},children:N.upKey.toUpperCase()}),Qt.jsxs("div",{style:{display:"flex",gap:"8px"},children:[Qt.jsx("div",{style:St(mt(N.leftKey)),onMouseDown:()=>H(N.leftKey),onMouseUp:()=>rt(N.leftKey),onMouseLeave:()=>rt(N.leftKey),onTouchStart:pt=>{pt.preventDefault(),H(N.leftKey)},onTouchEnd:pt=>{pt.preventDefault(),rt(N.leftKey)},children:N.leftKey.toUpperCase()}),Qt.jsx("div",{style:St(mt(N.downKey)),onMouseDown:()=>H(N.downKey),onMouseUp:()=>rt(N.downKey),onMouseLeave:()=>rt(N.downKey),onTouchStart:pt=>{pt.preventDefault(),H(N.downKey)},onTouchEnd:pt=>{pt.preventDefault(),rt(N.downKey)},children:N.downKey.toUpperCase()}),Qt.jsx("div",{style:St(mt(N.rightKey)),onMouseDown:()=>H(N.rightKey),onMouseUp:()=>rt(N.rightKey),onMouseLeave:()=>rt(N.rightKey),onTouchStart:pt=>{pt.preventDefault(),H(N.rightKey)},onTouchEnd:pt=>{pt.preventDefault(),rt(N.rightKey)},children:N.rightKey.toUpperCase()})]})]},W.id)});return Qt.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[Qt.jsx("canvas",{ref:R,onPointerDown:W=>{var N;j(W,"down"),W.currentTarget.setPointerCapture(W.pointerId),(N=R.current)==null||N.focus()},onPointerMove:W=>j(W,"move"),onPointerUp:W=>{j(W,"up"),W.currentTarget.releasePointerCapture(W.pointerId)},onPointerCancel:W=>{j(W,"up"),W.currentTarget.releasePointerCapture(W.pointerId)},onPointerLeave:W=>j(W,"blur"),onClick:W=>j(W,"click"),onKeyDown:W=>Y.current.handleKeyDown(W.nativeEvent),onKeyUp:W=>Y.current.handleKeyUp(W.nativeEvent),onContextMenu:W=>W.preventDefault(),tabIndex:0,style:{...s,width:"100%",height:"100%",outline:"none",display:"block",touchAction:"none",pointerEvents:_?"auto":"none"}}),J()]})});function ri(){const[m,t]=At.useState(null),s=At.useCallback((y,c)=>{m==null||m.setInputBool(y,c)},[m]),o=At.useCallback((y,c)=>{m==null||m.setInputNumber(y,c)},[m]),e=At.useCallback(y=>{m==null||m.fireTrigger(y)},[m]),n=At.useCallback((y,c)=>{m==null||m.setInputText(y,c)},[m]),i=At.useCallback((y,c)=>{m==null||m.setInputNumberArray(y,c)},[m]),a=At.useCallback((y,c)=>{m==null||m.setInputStringArray(y,c)},[m]),r=At.useCallback((y,c)=>{m==null||m.updateInput(y,c)},[m]),l=r,f=At.useCallback((y,c)=>{m==null||m.updateObjectOptions(y,c)},[m]),p=At.useCallback((y,c,v)=>{m==null||m.updateConstraint(y,c,v)},[m]),u=At.useCallback((y,c,v)=>{m==null||m.updateGraphData(y,c,v)},[m]),g=At.useCallback((y,c,v)=>{m==null||m.updateBarChartData(y,c,v)},[m]),h=At.useCallback((y,c)=>{m==null||m.updatePieChartData(y,c)},[m]),d=At.useCallback((y,c)=>{m==null||m.setDropdownOptions(y,c)},[m]),w=At.useCallback(y=>m==null?void 0:m.getInputValue(y),[m]);return{setEngine:t,engine:m,updateInput:r,setInputValue:l,setInputBool:s,setInputNumber:o,fireTrigger:e,setInputText:n,setInputNumberArray:i,setInputStringArray:a,updateConstraint:p,updateGraphData:u,updateBarChartData:g,updatePieChartData:h,setDropdownOptions:d,updateObjectOptions:f,getInputValue:w}}const li=({artboard:m,config:t})=>{const s={...m.seo,...t},o=s.enableSmartExtraction!==!1;At.useEffect(()=>{const a=s.title||m.name;a&&(document.title=a);let r=s.description;if(!r&&o){const p=m.objects.filter(u=>{var g;return((g=u.geometry)==null?void 0:g.type)==="Text"}).sort((u,g)=>{var h,d;return(((h=g.geometry.text)==null?void 0:h.length)||0)-(((d=u.geometry.text)==null?void 0:d.length)||0)});p.length>0&&(r=p[0].geometry.text)}r&&(e("name","description",r),e("property","og:description",r)),s.keywords&&s.keywords.length>0&&e("name","keywords",s.keywords.join(", "));const l=s.ogImage||m.backgroundImage;l&&e("property","og:image",l),a&&e("property","og:title",a),e("property","og:type","website")},[s,m,o]);const e=(a,r,l)=>{let f=document.querySelector(`meta[${a}="${r}"]`);f||(f=document.createElement("meta"),f.setAttribute(a,r),document.head.appendChild(f)),f.setAttribute("content",l)},n=()=>{const a=[];return a.push(Qt.jsx("h1",{children:s.title||m.name},"artboard-title")),m.objects.forEach((l,f)=>{var p,u;if(!(l.visible===!1||l.isVisible===!1))if(((p=l.geometry)==null?void 0:p.type)==="Text"){const g=l.geometry.text;g&&(l.geometry.fontSize>24?a.push(Qt.jsx("h2",{children:g},l.id||f)):a.push(Qt.jsx("p",{children:g},l.id||f)))}else if(((u=l.geometry)==null?void 0:u.type)==="Image"){const g=l.geometry.src,h=l.altText||l.name||"Illustration";a.push(Qt.jsx("img",{src:g,alt:h},l.id||f))}else l.type==="Button"&&a.push(Qt.jsx("button",{children:l.name||"Button"},l.id||f))}),a},i=s.jsonLd||{"@context":"https://schema.org","@type":"VisualArtwork",name:s.title||m.name,description:s.description,image:s.ogImage||m.backgroundImage,abstract:"Animated interface created with ExodeUI"};return Qt.jsxs("div",{id:`exode-seo-${m.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:[n(),Qt.jsx("script",{type:"application/ld+json",children:JSON.stringify(i)})]})},ci={version:"6.4.4"}.version;Kt.BAR_STYLE_PRESETS=oi,Kt.BehaviorSensor=ce,Kt.BehaviorType=st,Kt.ConditionOp=je,Kt.ExodeSEO=li,Kt.ExodeUICanvas=ai,Kt.ExodeUIEngine=gs,Kt.LogicOp=Lt,Kt.RapierPhysics=is,Kt.VERSION=ci,Kt.useExodeUI=ri,Object.defineProperty(Kt,Symbol.toStringTag,{value:"Module"})}));
1
+ (function(se,ne){typeof exports=="object"&&typeof module<"u"?ne(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"],ne):(se=typeof globalThis<"u"?globalThis:se||self,ne(se.ExodeUIReact={},se.jsxRuntime,se.React,se.pretext,se.Rapier,se.LZString))})(this,(function(se,ne,Nt,qe,ue,Ss){"use strict";var di=Object.defineProperty;var pi=(se,ne,Nt)=>ne in se?di(se,ne,{enumerable:!0,configurable:!0,writable:!0,value:Nt}):se[ne]=Nt;var pt=(se,ne,Nt)=>pi(se,typeof ne!="symbol"?ne+"":ne,Nt);function Cs(y){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(y){for(const s in y)if(s!=="default"){const o=Object.getOwnPropertyDescriptor(y,s);Object.defineProperty(t,s,o.get?o:{enumerable:!0,get:()=>y[s]})}}return t.default=y,Object.freeze(t)}const ws=Cs(Ss);var it=(y=>(y.Proximity="Proximity",y.Magnetic="Magnetic",y.Repel="Repel",y.Orbit="Orbit",y.Vortex="Vortex",y.Fluid="Fluid",y.Elastic="Elastic",y.Holographic="Holographic",y.Sticky="Sticky",y.Dilation="Dilation",y.Parallax="Parallax",y.Noise="Noise",y.Float="Float",y.Pulse="Pulse",y.Draggable="Draggable",y.Scroll="Scroll",y.LookAt="LookAt",y.Glint="Glint",y.Scan="Scan",y.Ratchet="Ratchet",y.Jitter="Jitter",y.Follower="Follower",y.Wrap="Wrap",y.Typewriter="Typewriter",y.Scramble="Scramble",y.Wave="Wave",y.Bounce="Bounce",y.TextTrail="TextTrail",y.Reveal3D="Reveal3D",y.RevealSlide="RevealSlide",y.RevealBlur="RevealBlur",y.TextLiquid="TextLiquid",y.TextVortex="TextVortex",y.TextExplosion="TextExplosion",y.TextRain="TextRain",y.TextGravity="TextGravity",y.TextMatrix="TextMatrix",y.TextNeon="TextNeon",y.TextDissolve="TextDissolve",y.TextOrganic="TextOrganic",y.TextBreathe="TextBreathe",y.TextSpin="TextSpin",y.TextMagnet="TextMagnet",y.TextPerspective="TextPerspective",y.TextMirror="TextMirror",y.TextFloral="TextFloral",y.TextSmoke="TextSmoke",y.TextVariable="TextVariable",y.TextZing="TextZing",y.TextElastic="TextElastic",y.TextGlitch3D="TextGlitch3D",y.GlitchText="GlitchText",y.TextCounter="TextCounter",y.Squash="Squash",y.Spotlight="Spotlight",y.Lens="Lens",y.Gravity="Gravity",y.Velocity="Velocity",y.Shear="Shear",y.LayoutAnimation="LayoutAnimation",y.SpringChain="SpringChain",y.ParticleEmitter="ParticleEmitter",y.StateReactive="StateReactive",y.Fold="Fold",y.Crumple="Crumple",y))(it||{}),ge=(y=>(y.Scale="Scale",y.Opacity="Opacity",y.RotateZ="RotateZ",y.RotateX="RotateX",y.RotateY="RotateY",y.PositionX="PositionX",y.PositionY="PositionY",y.SkewX="SkewX",y.Blur="Blur",y.Exposure="Exposure",y.HueShift="HueShift",y.Negative="Negative",y.CornerRadius="CornerRadius",y.StrokeWidth="StrokeWidth",y.BoxShadow="BoxShadow",y.FontSize="FontSize",y.LetterSpacing="LetterSpacing",y))(ge||{}),es=(y=>(y.Equal="Equal",y.NotEqual="NotEqual",y.GreaterThan="GreaterThan",y.LessThan="LessThan",y.GreaterEqual="GreaterEqual",y.LessEqual="LessEqual",y.IsTrue="IsTrue",y.IsFalse="IsFalse",y))(es||{}),Ht=(y=>(y.AND="AND",y.OR="OR",y.NOT="NOT",y.XOR="XOR",y.OBJECT="OBJECT",y.PROPERTY="PROPERTY",y.GET_PROPERTY="GET_PROPERTY",y.SET_PROPERTY="SET_PROPERTY",y.ADD="ADD",y.SUB="SUB",y.MUL="MUL",y.DIV="DIV",y.MOD="MOD",y.POW="POW",y.ABS="ABS",y.ROUND="ROUND",y.FLOOR="FLOOR",y.CEIL="CEIL",y.SIN="SIN",y.COS="COS",y.TAN="TAN",y.CLAMP="CLAMP",y.REMAP="REMAP",y.EQ="EQ",y.NEQ="NEQ",y.GT="GT",y.LT="LT",y.GTE="GTE",y.LTE="LTE",y.IF_ELSE="IF_ELSE",y.VALUE="VALUE",y.INPUT="INPUT",y.LOG="LOG",y.SCROLL_X="SCROLL_X",y.SCROLL_Y="SCROLL_Y",y.MOUSE_X="MOUSE_X",y.MOUSE_Y="MOUSE_Y",y.IS_MOUSE_DOWN="IS_MOUSE_DOWN",y.EFFECTOR="EFFECTOR",y.MONITOR="MONITOR",y.DELAY="DELAY",y.SPRING_PULL="SPRING_PULL",y.SPRING_SETTLE="SPRING_SETTLE",y.EMIT="EMIT",y))(Ht||{});function Ms(y){if(y.length<5)return y;const t=new Set("aeiouyAEIOUY".split(""));if(/[\u4E00-\u9FFF\u3400-\u4DBF]/.test(y))return y;let o="";for(let e=0;e<y.length;e++){if(o+=y[e],e>=y.length-2)continue;const n=t.has(y[e]),i=t.has(y[e+1]),a=t.has(y[e+2]);n&&!i&&a&&(o+="­"),n&&!i&&!a&&e>=1&&(o+="­")}return o}function Is(y){return y.replace(/\b([a-zA-Z]{4,})\b/g,(t,s)=>Ms(s))}function ks(y,t,s){return y}function Ts(y,t,s){return y}const Ge=new Map;function ss(y){var k;const{text:t,fontFamily:s="Inter",fontSize:o=16,fontWeight:e=400,fontStyle:n="normal",lineHeight:i=1.2,width:a=200,letterSpacing:r=0,paragraphSpacing:l=0,paragraphIndent:d=0,textCase:p="none",segments:g=[],enableSegments:u=!1}=y;let f=String(t||"");p==="uppercase"?f=f.toUpperCase():p==="lowercase"?f=f.toLowerCase():p==="capitalize"&&(f=f.replace(/\b\w/g,O=>O.toUpperCase())),y.hyphenation===!0&&(f=Is(f));const h=`${n} ${e} ${o}px "${s}", sans-serif`,m=`${f}|${h}|${r}|${l}|${d}|${u}|${JSON.stringify(g)}|hyp:${!!y.hyphenation}|comp:${y.composer}|bal:${!!y.balanceRaggedLines}`;let b=Ge.get(m);const c=typeof CanvasRenderingContext2D<"u"?CanvasRenderingContext2D.prototype.measureText:null,S=function(O){if(!c)return{width:0,fontBoundingBoxAscent:0,fontBoundingBoxDescent:0};const T=c.call(this,O);return r!==0&&O&&O.length>0?{...T,width:T.width+(O.length-1)*r}:T};if(!b){try{if(r!==0&&typeof CanvasRenderingContext2D<"u"&&(CanvasRenderingContext2D.prototype.measureText=S),u&&g&&g.length>0){const O=g.map(T=>{let A=T.text||"";const D=T.textCase||p||"none";return D==="uppercase"?A.toUpperCase():D==="lowercase"?A.toLowerCase():D==="capitalize"?A.replace(/\b\w/g,Y=>Y.toUpperCase()):A}).join("");if(b=qe.prepareWithSegments(O,h),b){let T=0,A=o;for(const D of g){let Y=D.text||"";if(!Y)continue;const B=D.textCase||p||"none";B==="uppercase"?Y=Y.toUpperCase():B==="lowercase"?Y=Y.toLowerCase():B==="capitalize"&&(Y=Y.replace(/\b\w/g,F=>F.toUpperCase()));const R=D.fontSize||o;R>A&&(A=R);const L=`${D.fontStyle||n} ${D.fontWeight||e} ${R}px "${D.fontFamily||s}", sans-serif`,$=qe.prepareWithSegments(Y,L);if($&&$.widths)for(let F=0;F<$.widths.length;F++){const X=T+F;if(X<b.widths.length){b.widths[X]=$.widths[F];const M=$.kinds[F];if(M===2){const E=Y[F];E===`
2
+ `||E==="\r"?b.kinds[X]=2:b.kinds[X]=0}else b.kinds[X]=M}}T+=Y.length}b.fullText=O,b.maxFontSize=A}}else b=qe.prepareWithSegments(f,h);b&&Ge.set(m,b)}catch(O){return console.error("[ExodeUI] Pretext prepare failed:",O),{width:a,height:0,lineCount:0,lines:[]}}finally{r!==0&&typeof CanvasRenderingContext2D<"u"&&c&&(CanvasRenderingContext2D.prototype.measureText=c)}if(Ge.size>500){const O=Ge.keys().next().value;O&&Ge.delete(O)}}if(d>0&&b&&b.widths&&!b.indentApplied){const O=[...b.widths],T=b.fullText||f;let A=!0;for(let D=0;D<T.length;D++)A&&O[D]!==void 0&&(O[D]+=d,A=!1),(T[D]===`
3
+ `||T[D]==="\r")&&(A=!0,T[D]==="\r"&&T[D+1]===`
4
+ `&&D++);b={...b,widths:O,indentApplied:!0}}if(!b)return{width:a,height:0,lineCount:0,lines:[]};let v=i;typeof v=="string"&&(v=parseFloat(v)),v>5&&o>0&&(v=v/o),r!==0&&(CanvasRenderingContext2D.prototype.measureText=S);let C;try{const O=b.maxFontSize||o;if(a>=1e5){const T=f.split(/\r\n|\r|\n/);C={lines:T.map(A=>({text:A,width:0})),height:T.length*(v*O),lineCount:T.length}}else C=qe.layoutWithLines(b,a,v*O)}finally{r!==0&&c&&(CanvasRenderingContext2D.prototype.measureText=c)}let w=(C==null?void 0:C.height)!==void 0&&C.height>0?C.height:(((k=C==null?void 0:C.lines)==null?void 0:k.length)||0)*v*o;if(l>0&&C&&C.lines&&C.lines.length>1){let O=0;const T=b.fullText||t;for(let A=0;A<C.lines.length-1;A++)O+=C.lines[A].text.length,(T[O]===`
5
+ `||T[O]==="\r")&&(w+=l,O++,T[O-1]==="\r"&&T[O]===`
6
+ `&&O++)}let I=(C==null?void 0:C.lines)||[];return y.composer==="every-line"&&I.length>1&&(I=ks(I)),y.balanceRaggedLines===!0&&I.length>1&&(I=Ts(I)),{width:a,height:w,lineCount:I.length,lines:I}}function is(y,t,s){let o=String(y||"").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),n=new Array(e.length).fill(0);let i=t-(e.length-1)*s,a=0;if(e.forEach((r,l)=>{if(r.endsWith("px")){const d=parseFloat(r);n[l]=d,i-=d}else r.endsWith("fr")?a+=parseFloat(r):r==="auto"&&(n[l]=100,i-=100)}),a>0&&i>0){const r=i/a;e.forEach((l,d)=>{l.endsWith("fr")&&(n[d]=r*parseFloat(l))})}return n}function ns(y,t,s){try{const o=y.autoLayout;return!o||!o.enabled?{childUpdates:[]}:(o.mode||"linear")==="grid"?_s(y,t,s):Ps(y,t,s)}catch(o){return console.error("Layout Engine Error:",o),{childUpdates:[]}}}function Ps(y,t,s){var Y,B;const o=y.autoLayout,{direction:e,spacing:n,padding:i,align:a,wrap:r}=o,l=e==="vertical",d=t.map(R=>{const L=s(R.id),$=R.geometry;let F=(L==null?void 0:L.width)??$.width??100,X=(L==null?void 0:L.height)??$.height??100;if($.type==="Ellipse"||$.type==="Polygon"||$.type==="Star"){const M=(L==null?void 0:L.radius)??$.radius??(L==null?void 0:L.outer_radius)??$.outer_radius??50;F=M*2,X=M*2}else if($.type==="Text"){const M=ss({text:(L==null?void 0:L.text)??$.text??"",fontFamily:$.fontFamily,fontSize:$.fontSize,fontWeight:$.fontWeight,fontStyle:$.fontStyle,lineHeight:$.lineHeight,width:$.width||200,letterSpacing:$.letterSpacing,paragraphSpacing:$.paragraphSpacing,paragraphIndent:$.paragraphIndent,textCase:$.textCase,segments:$.segments,enableSegments:$.enableSegments});X=M.height,$.width||(F=M.width)}return F*=R.transform.scale_x||1,X*=R.transform.scale_y||1,{id:R.id,w:F,h:X,original:R}});let p=y.width,g=y.height;const u=((Y=y.layoutProps)==null?void 0:Y.width)==="hug",f=((B=y.layoutProps)==null?void 0:B.height)==="hug",h=[];let m=[],b=0,c=0;const S=p-i.left-i.right,v=g-i.top-i.bottom;d.forEach(R=>{r&&m.length>0&&(l?c+n+R.h>v:b+n+R.w>S)?(h.push({children:m,width:b,height:c}),m=[R],b=R.w,c=R.h):(m.push(R),l?(b=Math.max(b,R.w),c+=(m.length>1?n:0)+R.h):(b+=(m.length>1?n:0)+R.w,c=Math.max(c,R.h)))}),m.length>0&&h.push({children:m,width:b,height:c}),u&&!l&&(p=Math.max(...h.map(R=>R.width),0)+i.left+i.right),f&&l&&(g=Math.max(...h.map(R=>R.height),0)+i.top+i.bottom);const C=[];let w=i.left,I=i.top;const k=a.toLowerCase(),O=k==="center"||k.endsWith("-center"),T=k.endsWith("-right"),A=k==="center"||k.startsWith("center-"),D=k.startsWith("bottom-");return h.forEach(R=>{let L=w,$=I;l?A?$=i.top+(g-i.top-i.bottom-R.height)/2:D&&($=g-i.bottom-R.height):O?L=i.left+(p-i.left-i.right-R.width)/2:T&&(L=p-i.right-R.width),R.children.forEach(F=>{var _,V;let X=L,M=$;l?O?X+=(R.width-F.w)/2:T&&(X+=R.width-F.w):A?M+=(R.height-F.h)/2:D&&(M+=R.height-F.h);const E=((_=F.original.layoutProps)==null?void 0:_.width)==="fill",P=((V=F.original.layoutProps)==null?void 0:V.height)==="fill";C.push({id:F.id,x:X+F.w/2-p/2,y:M+F.h/2-g/2,width:E&&l?R.width:void 0,height:P?l?void 0:R.height:void 0}),l?$+=F.h+n:L+=F.w+n}),l?w+=R.width+n:I+=R.height+n}),{frameWidth:u?p:void 0,frameHeight:f?g:void 0,childUpdates:C}}function _s(y,t,s){const o=y.autoLayout;if(!o)return{childUpdates:[]};const{gridColumns:e,gridRows:n,columnGap:i=0,rowGap:a=0,padding:r,align:l}=o;let d=y.width,p=y.height;const g=d-r.left-r.right,u=p-r.top-r.bottom,f=is(e||"1fr",g,i),h=is(n||"auto",u,a),m=f.length>0?f.reduce((T,A)=>T+A,0)+(f.length-1)*i:0,b=h.length>0?h.reduce((T,A)=>T+A,0)+(h.length-1)*a:0,c=l.toLowerCase(),S=c==="center"||c.endsWith("-center"),v=c.endsWith("-right"),C=c==="center"||c.startsWith("center-"),w=c.startsWith("bottom-");let I=0,k=0;S?I=(g-m)/2:v&&(I=g-m),C?k=(u-b)/2:w&&(k=u-b);const O=[];return t.forEach((T,A)=>{var V,G;const D=A%f.length||0,Y=Math.floor(A/f.length)||0;Y>=h.length&&h.push(100);const B=f[D],R=h[Y];let L=r.left+I+f.slice(0,D).reduce((x,U)=>x+U+i,0),$=r.top+k+h.slice(0,Y).reduce((x,U)=>x+U+a,0);const F=s(T.id),X=T.geometry;let M=(F==null?void 0:F.width)??X.width??100,E=(F==null?void 0:F.height)??X.height??100;if(X.type==="Ellipse"||X.type==="Polygon"||X.type==="Star"){const x=(F==null?void 0:F.radius)??X.radius??(F==null?void 0:F.outer_radius)??X.outer_radius??50;M=x*2,E=x*2}M*=T.transform.scale_x||1,E*=T.transform.scale_y||1;let P=L,_=$;S?P+=(B-M)/2:v&&(P+=B-M),C?_+=(R-E)/2:w&&(_+=R-E),O.push({id:T.id,x:P+M/2-d/2,y:_+E/2-p/2,width:((V=T.layoutProps)==null?void 0:V.width)==="fill"?B:void 0,height:((G=T.layoutProps)==null?void 0:G.height)==="fill"?R:void 0})}),{childUpdates:O}}class os{constructor(){pt(this,"world",null);pt(this,"bodies",new Map);pt(this,"colliders",new Map);pt(this,"joints",new Map);pt(this,"initialized",!1);pt(this,"bodyIdByCollider",new Map);pt(this,"onCollisionCB",null);pt(this,"eventQueue",null)}setCollisionCallback(t){this.onCollisionCB=t}async init(t){this.initialized||(await ue.init(),this.world=new ue.World(new ue.Vector2(t.x*100,t.y*100)),this.eventQueue=new ue.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 ue.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 s=t.isStatic?ue.RigidBodyDesc.fixed():ue.RigidBodyDesc.dynamic();s.setTranslation(t.x,t.y),t.rotation!==void 0&&s.setRotation(t.rotation);const o=this.world.createRigidBody(s);let e;switch(t.type){case"Rectangle":e=ue.ColliderDesc.cuboid(t.width/2,t.height/2);break;case"Ellipse":e=ue.ColliderDesc.ball(Math.max(t.width,t.height)/2);break;case"Triangle":case"Star":case"Polygon":e=ue.ColliderDesc.cuboid(t.width/2,t.height/2);break;default:e=ue.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 i=t.width*t.height;e.setDensity(t.mass/i)}t.isSensor&&e.setSensor(!0);const n=this.world.createCollider(e,o);this.bodyIdByCollider.set(n.handle,t.id),t.frictionAir!==void 0&&o.setLinearDamping(t.frictionAir*10),this.bodies.set(t.id,o),this.colliders.set(t.id,n)}removeBody(t){const s=this.bodies.get(t),o=this.colliders.get(t);o&&this.bodyIdByCollider.delete(o.handle),s&&this.world&&(this.world.removeRigidBody(s),this.bodies.delete(t),this.colliders.delete(t))}step(t){if(!this.world)return;this.world.step(this.eventQueue);const s=this.onCollisionCB,o=this.eventQueue;s&&o&&o.drainContactEvents((e,n,i)=>{const a=this.bodyIdByCollider.get(e),r=this.bodyIdByCollider.get(n);a&&r&&s(a,r,i)})}getPosition(t){const s=this.bodies.get(t);if(!s)return null;const o=s.translation();return{x:o.x,y:o.y}}getRotation(t){const s=this.bodies.get(t);return s?s.rotation():null}getVelocity(t){const s=this.bodies.get(t);if(!s)return null;const o=s.linvel();return{x:o.x,y:o.y}}setPosition(t,s,o){const e=this.bodies.get(t);e&&e.setTranslation(new ue.Vector2(s,o),!0)}setRotation(t,s){const o=this.bodies.get(t);o&&o.setRotation(s,!0)}setVelocity(t,s,o){const e=this.bodies.get(t);e&&e.setLinvel(new ue.Vector2(s,o),!0)}setAngularVelocity(t,s){const o=this.bodies.get(t);o&&o.setAngvel(s,!0)}applyForce(t,s,o){const e=this.bodies.get(t);e&&e.addForce(new ue.Vector2(s,o),!0)}applyImpulse(t,s,o){const e=this.bodies.get(t);e&&e.applyImpulse(new ue.Vector2(s,o),!0)}createJoint(t){if(!this.world){console.warn("[RapierPhysics] World not initialized");return}this.joints.has(t.id)&&this.removeJoint(t.id);const s=this.bodies.get(t.bodyA),o=this.bodies.get(t.bodyB);if(!s||!o){console.warn(`[RapierPhysics] Cannot create joint ${t.id}: bodyA (${t.bodyA}) or bodyB (${t.bodyB}) not found`);return}const e=new ue.Vector2(t.anchorA.x,t.anchorA.y),n=new ue.Vector2(t.anchorB.x,t.anchorB.y);let i;if(t.type==="Distance"){const a=t.length??100,r=t.stiffness??100,l=t.damping??10;i=ue.JointData.spring(a,r,l,e,n)}else i=ue.JointData.revolute(e,n);try{const a=this.world.createImpulseJoint(i,s,o,!0);this.joints.set(t.id,a)}catch(a){console.error(`[RapierPhysics] Failed to create joint ${t.id}:`,a)}}removeJoint(t){const s=this.joints.get(t);if(s&&this.world){try{this.world.removeImpulseJoint(s,!0)}catch(o){console.error(`[RapierPhysics] Failed to remove joint ${t}:`,o)}this.joints.delete(t)}}}const as=y=>y,As=y=>y>0?1:0,Es=y=>y<1?0:1,rs=y=>y*y,ls=y=>y*(2-y),cs=y=>y<.5?2*y*y:-1+(4-2*y)*y,Ls=y=>y*y*y,Os=y=>--y*y*y+1,Rs=y=>y<.5?4*y*y*y:(y-1)*(2*y-2)*(2*y-2)+1,$s=y=>y*y*y*y,Fs=y=>1- --y*y*y*y,Ws=y=>y<.5?8*y*y*y*y:1-8*--y*y*y*y,Bs=y=>y*y*y*y*y,Ys=y=>1+--y*y*y*y*y,Ds=y=>y<.5?16*y*y*y*y*y:1+16*--y*y*y*y*y,Xs=y=>1-Math.cos(y*Math.PI/2),Ns=y=>Math.sin(y*Math.PI/2),Hs=y=>-(Math.cos(Math.PI*y)-1)/2,Vs=y=>y===0?0:Math.pow(2,10*(y-1)),Gs=y=>y===1?1:1-Math.pow(2,-10*y),zs=y=>y===0?0:y===1?1:y<.5?Math.pow(2,20*y-10)/2:(2-Math.pow(2,-20*y+10))/2,xs=y=>1-Math.sqrt(1-y*y),Us=y=>Math.sqrt(1- --y*y),qs=y=>y<.5?(1-Math.sqrt(1-4*y*y))/2:(Math.sqrt(1-(-2*y+2)*(-2*y+2))+1)/2,Je=1.70158,Ke=Je*1.525,hs=Je+1,Js=y=>hs*y*y*y-Je*y*y,Ks=y=>1+hs*Math.pow(y-1,3)+Je*Math.pow(y-1,2),Qs=y=>y<.5?Math.pow(2*y,2)*((Ke+1)*2*y-Ke)/2:(Math.pow(2*y-2,2)*((Ke+1)*(y*2-2)+Ke)+2)/2,fs=2*Math.PI/3,ds=2*Math.PI/4.5,Zs=y=>y===0?0:y===1?1:-Math.pow(2,10*y-10)*Math.sin((y*10-10.75)*fs),js=y=>y===0?0:y===1?1:Math.pow(2,-10*y)*Math.sin((y*10-.75)*fs)+1,ti=y=>y===0?0:y===1?1:y<.5?-(Math.pow(2,20*y-10)*Math.sin((20*y-11.125)*ds))/2:Math.pow(2,-20*y+10)*Math.sin((20*y-11.125)*ds)/2+1,Qe=y=>y<1/2.75?7.5625*y*y:y<2/2.75?7.5625*(y-=1.5/2.75)*y+.75:y<2.5/2.75?7.5625*(y-=2.25/2.75)*y+.9375:7.5625*(y-=2.625/2.75)*y+.984375,ei=y=>1-Qe(1-y),si=Qe,ii=y=>y<.5?(1-Qe(1-2*y))/2:(1+Qe(2*y-1))/2,ts=new Map,ze=(y,t,s,o)=>{const e=`${y},${t},${s},${o}`;if(ts.has(e))return ts.get(e);const n=d=>(1-3*s+3*y)*d*d*d+(3*s-6*y)*d*d+3*y*d,i=d=>(1-3*o+3*t)*d*d*d+(3*o-6*t)*d*d+3*t*d,a=d=>3*(1-3*s+3*y)*d*d+2*(3*s-6*y)*d+3*y,r=d=>{let p=d;for(let g=0;g<8;g++){const u=n(p)-d;if(Math.abs(u)<1e-6)return p;const f=a(p);if(Math.abs(f)<1e-6)break;p=p-u/f}return p},l=d=>d===0?0:d===1?1:i(r(d));return ts.set(e,l),l},ps=y=>{const t=y.match(/cubic-bezier\s*\(\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*\)/);if(!t)return null;const[,s,o,e,n]=t.map(Number);return ze(s,o,e,n)},us={ease:ze(.25,.1,.25,1),"ease-in":ze(.42,0,1,1),"ease-out":ze(0,0,.58,1),"ease-in-out":ze(.42,0,.58,1)},Ze={Linear:as,EaseInQuad:rs,EaseOutQuad:ls,EaseInOutQuad:cs,EaseInCubic:Ls,EaseOutCubic:Os,EaseInOutCubic:Rs,EaseInQuart:$s,EaseOutQuart:Fs,EaseInOutQuart:Ws,EaseInQuint:Bs,EaseOutQuint:Ys,EaseInOutQuint:Ds,EaseInSine:Xs,EaseOutSine:Ns,EaseInOutSine:Hs,EaseInExpo:Vs,EaseOutExpo:Gs,EaseInOutExpo:zs,EaseInCirc:xs,EaseOutCirc:Us,EaseInOutCirc:qs,EaseInBack:Js,EaseOutBack:Ks,EaseInOutBack:Qs,EaseInElastic:Zs,EaseOutElastic:js,EaseInOutElastic:ti,EaseInBounce:ei,EaseOutBounce:si,EaseInOutBounce:ii,EaseIn:rs,EaseOut:ls,EaseInOut:cs,StepStart:As,StepEnd:Es},gs=y=>{const t=y.trim(),s=t.toLowerCase();if(Ze[t])return Ze[t];const o=Object.keys(Ze).find(n=>n.toLowerCase()===s);if(o)return Ze[o];const e=Object.keys(ms).find(n=>n.toLowerCase()===s);if(e){const n=ps(ms[e].value);if(n)return n}if(us[s])return us[s];if(s.startsWith("cubic-bezier")){const n=ps(t);if(n)return n}return as},ms={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)"}},ni=(y,t,s,o,e)=>{if(!y||!t||!s)return y;const n=o.scale_x??1,i=o.scale_y??1,a=(r,l,d)=>{let p=0,g=0;const u=o.rotation*Math.PI/180,f=Math.cos(u),h=Math.sin(u),m=r*n*f-l*i*h+o.x,b=r*n*h+l*i*f+o.y;d.forEach(k=>{const O=e(k.boneId);if(!O)return;const T={x:O.x,y:O.y,rotation:O.rotation,scaleX:O.scale_x??1,scaleY:O.scale_y??1},A=s[k.boneId]||[1,0,0,1,0,0],D=m*A[0]+b*A[2]+A[4],Y=m*A[1]+b*A[3]+A[5],B=T.rotation*Math.PI/180,R=Math.cos(B),L=Math.sin(B),$=D*T.scaleX*R-Y*T.scaleY*L+T.x,F=D*T.scaleX*L+Y*T.scaleY*R+T.y;p+=$*k.amount,g+=F*k.amount});const c=[...d].sort((k,O)=>O.amount-k.amount);if(c.length>=2&&c[0].amount>0&&c[1].amount>0){const k=e(c[0].boneId),O=e(c[1].boneId);if(k&&O&&k.length!==void 0&&O.length!==void 0){const T=k.length*(k.scale_y??1),A=k.rotation*Math.PI/180,D=k.x-T*Math.sin(A),Y=k.y+T*Math.cos(A),B=O.length*(O.scale_y??1),R=O.rotation*Math.PI/180,L=O.x-B*Math.sin(R),$=O.y+B*Math.cos(R);let F=null,X=null,M=!1;const E=1;if(Math.hypot(k.x-O.x,k.y-O.y)<E||Math.hypot(k.x-L,k.y-$)<E?(F=k.x,X=k.y):(Math.hypot(D-O.x,Y-O.y)<E||Math.hypot(D-L,Y-$)<E)&&(F=D,X=Y,M=!0),F!==null&&X!==null){const P=s[c[0].boneId]||[1,0,0,1,0,0],_=P[0]*P[3]-P[1]*P[2];let V=0,G=0;if(_!==0){const x=(P[2]*P[5]-P[3]*P[4])/_,U=(P[1]*P[4]-P[0]*P[5])/_,q=Math.atan2(-P[1],P[3]);if(!M)V=x,G=U;else{const z=-P[2]/_,et=P[0]/_,Mt=Math.hypot(z,et),ct=k.length*Mt;V=x-ct*Math.sin(q),G=U+ct*Math.cos(q)}const N=Math.hypot(m-V,b-G),H=Math.hypot(p-F,g-X);if(H>0&&N>0){const z=Math.max(H,.01),et=Math.min(N/z,3),Mt=F+(p-F)*et,ct=X+(g-X)*et,It=c[0].amount,mt=c[1].amount,kt=Math.min(It,mt)*2,Ot=1-Math.pow(1-kt,4);p=p*(1-Ot)+Mt*Ot,g=g*(1-Ot)+ct*Ot}}}}}const S=o.rotation*Math.PI/180,v=Math.cos(S),C=Math.sin(S),w=p-o.x,I=g-o.y;return{x:(w*v+I*C)/n,y:(-w*C+I*v)/i}};return y.map((r,l)=>{const d=t[l];if(!d||d.length===0)return{...r};const p={...r,...a(r.x,r.y,d)};if(r.in_x!==void 0&&r.in_y!==void 0){const g=a(r.in_x,r.in_y,d);p.in_x=g.x,p.in_y=g.y}if(r.out_x!==void 0&&r.out_y!==void 0){const g=a(r.out_x,r.out_y,d);p.out_x=g.x,p.out_y=g.y}return p})};function oi(y,t,s,o,e){const n=y*s*.01,i=t*s*.01,a=Math.sin(e*12.9898)*43758.5453%(Math.PI*2),r=Math.cos(e*78.233)*43758.5453%(Math.PI*2);return(Math.sin(n+a)*Math.cos(i+r)+.5*Math.sin(n*2.1-r)*Math.cos(i*2.3+a)+.25*Math.sin(n*4.5+a)*Math.cos(i*4.2-r))/1.75*o}function ai(y,t,s,o,e,n,i=0,a=0){const r=[];if(!y)return[];const l=y.type;if(l==="Rectangle"||l==="Image"||l==="Frame"){const f=Math.max(20,Math.floor((t+s)/10)),h=Math.max(2,Math.floor(f*(t/(t+s)))),m=Math.max(2,Math.floor(f*(s/(t+s))));for(let b=0;b<h;b++)r.push({x:-t/2+t/h*b,y:-s/2,nx:0,ny:-1});for(let b=0;b<m;b++)r.push({x:t/2,y:-s/2+s/m*b,nx:1,ny:0});for(let b=0;b<h;b++)r.push({x:t/2-t/h*b,y:s/2,nx:0,ny:1});for(let b=0;b<m;b++)r.push({x:-t/2,y:s/2-s/m*b,nx:-1,ny:0})}else if(l==="Ellipse"){const f=Math.max(60,Math.floor(Math.PI*Math.max(t,s)/5));for(let h=0;h<f;h++){const m=h/f*Math.PI*2,b=Math.cos(m),c=Math.sin(m);r.push({x:b*t/2,y:c*s/2,nx:b,ny:c})}}else if(l==="Triangle"){const f={x:0,y:-s/2},h={x:t/2,y:s/2},m={x:-t/2,y:s/2},b=20;let c=h.x-f.x,S=h.y-f.y,v=Math.hypot(c,S),C=-S/v,w=c/v;for(let I=0;I<b;I++)r.push({x:f.x+c*(I/b),y:f.y+S*(I/b),nx:C,ny:w});c=m.x-h.x,S=m.y-h.y,v=Math.hypot(c,S),C=-S/v,w=c/v;for(let I=0;I<b;I++)r.push({x:h.x+c*(I/b),y:h.y+S*(I/b),nx:C,ny:w});c=f.x-m.x,S=f.y-m.y,v=Math.hypot(c,S),C=-S/v,w=c/v;for(let I=0;I<b;I++)r.push({x:m.x+c*(I/b),y:m.y+S*(I/b),nx:C,ny:w})}else for(let h=0;h<80;h++){const m=h/80*Math.PI*2,b=Math.cos(m),c=Math.sin(m);r.push({x:b*t/2,y:c*s/2,nx:b,ny:c})}const d=i*Math.PI/180,p=Math.cos(d),g=Math.sin(d);return r.map(f=>{const h=oi(f.x,f.y,e,o,n),m=f.nx*(1-a)+p*a,b=f.ny*(1-a)+g*a;let c=Math.hypot(m,b);return c===0&&(c=1),{x:f.x+m/c*h,y:f.y+b/c*h}})}const ri={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}},ys={vibrant:["#6366f1","#22d3ee","#f59e0b","#ec4899","#34d399","#a855f7","#f87171"],pastel:["#a5b4fc","#67e8f9","#fcd34d","#f9a8d4","#6ee7b7","#c4b5fd","#fca5a5"],neon:["#00f5ff","#ff00e5","#00ff9f","#ff6b00","#b400ff","#ffe600","#00c3ff"],warm:["#f97316","#ef4444","#f59e0b","#dc2626","#fb923c","#e11d48","#ea580c"],ocean:["#06b6d4","#0ea5e9","#38bdf8","#7dd3fc","#0284c7","#0369a1","#bae6fd"]},xe={Rectangle:"M3 5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5z",Hexagon:"M12 2l8.5 5v10L12 22l-8.5-5V7L12 2z",Octagon:"M7.86 2h8.28L22 7.86v8.28L16.14 22H7.86L2 16.14V7.86L7.86 2z",Heart:"M12 21.35l-1.45-1.32C5.4 15.36 2 12.28 2 8.5 2 5.42 4.42 3 7.5 3c1.74 0 3.41.81 4.5 2.09C13.09 3.81 14.76 3 16.5 3 19.58 3 22 5.42 22 8.5c0 3.78-3.4 6.86-8.55 11.54L12 21.35z",Cloud:"M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96z",Shield:"M12 2L4 5v6.09c0 5.05 3.41 9.76 8 10.91 4.59-1.15 8-5.86 8-10.91V5l-8-3z",Badge:"M3.85 8.62a4 4 0 0 1 4.78-4.77 4 4 0 0 1 6.74 0 4 4 0 0 1 4.78 4.78 4 4 0 0 1 0 6.74 4 4 0 0 1-4.77 4.78 4 4 0 0 1-6.75 0 4 4 0 0 1-4.78-4.77 4 4 0 0 1 0-6.76z",Leaf:"M11 20A7 7 0 0 1 9.8 6.1C15.5 5 17 4.48 19 2c1 2 2 4.18 2 8 0 5.5-4.78 10-10 10Z",Tag:"M12 2H2v10l9.29 9.29c.94.94 2.48.94 3.42 0l6.58-6.58c.94-.94.94-2.48 0-3.42L12 2Z",Sparkle:"M12 2v4m0 12v4M4.93 4.93l2.83 2.83m8.48 8.48l2.83 2.83M2 12h4m12 0h4M4.93 19.07l2.83-2.83m8.48-8.48l2.83-2.83",Diamond:"M12 2L2 12l10 10 10-10L12 2z",Star:"M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z"},We=y=>{let t=1/0,s=1/0,o=-1/0,e=-1/0,n=0,i=0;const a=/([a-df-z])([^a-df-z]*)/gi;let r;for(;(r=a.exec(y))!==null;){const u=r[1],f=u===u.toLowerCase(),h=u.toUpperCase(),m=[],b=/[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/g;let c;for(;(c=b.exec(r[2]))!==null;)m.push(parseFloat(c[0]));const S=(v,C)=>{!isNaN(v)&&!isNaN(C)&&(v<t&&(t=v),v>o&&(o=v),C<s&&(s=C),C>e&&(e=C),n=v,i=C)};if(h==="M"||h==="L"||h==="T")for(let v=0;v<m.length-1;v+=2){const C=f?n+m[v]:m[v],w=f?i+m[v+1]:m[v+1];S(C,w)}else if(h==="H")for(let v=0;v<m.length;v++){const C=f?n+m[v]:m[v];S(C,i)}else if(h==="V")for(let v=0;v<m.length;v++){const C=f?i+m[v]:m[v];S(n,C)}else if(h==="C")for(let v=0;v<m.length-5;v+=6){const C=f?n+m[v]:m[v],w=f?i+m[v+1]:m[v+1],I=f?n+m[v+2]:m[v+2],k=f?i+m[v+3]:m[v+3],O=f?n+m[v+4]:m[v+4],T=f?i+m[v+5]:m[v+5];S(C,w),S(I,k),S(O,T)}else if(h==="S"||h==="Q")for(let v=0;v<m.length-3;v+=4){const C=f?n+m[v]:m[v],w=f?i+m[v+1]:m[v+1],I=f?n+m[v+2]:m[v+2],k=f?i+m[v+3]:m[v+3];S(C,w),S(I,k)}else if(h==="A")for(let v=0;v<m.length-6;v+=7){const C=f?n+m[v+5]:m[v+5],w=f?i+m[v+6]:m[v+6];S(C,w)}}(!isFinite(t)||!isFinite(o)||!isFinite(s)||!isFinite(e))&&(t=0,o=24,s=0,e=24);const l=Math.max(.001,o-t),d=Math.max(.001,e-s),p=(t+o)/2,g=(s+e)/2;return{minX:t,minY:s,maxX:o,maxY:e,width:l,height:d,cx:p,cy:g}};class bs{constructor(){pt(this,"artboard",null);pt(this,"objectStates",new Map);pt(this,"physicsEngine",null);pt(this,"activeStateMachine",null);pt(this,"inputs",new Map);pt(this,"inputNameMap",new Map);pt(this,"layerStates",new Map);pt(this,"pretextCache",new Map);pt(this,"pointerHistory",[]);pt(this,"MAX_HISTORY",200);pt(this,"imageCache",new Map);pt(this,"lastValidSvgImgMap",new Map);pt(this,"maskBuffer",null);pt(this,"maskCtx",null);pt(this,"lumaBuffer",null);pt(this,"lumaCtx",null);pt(this,"_noiseTileCanvas",null);pt(this,"layout",{fit:"Contain",alignment:"Center"});pt(this,"onTrigger");pt(this,"onInputUpdate");pt(this,"onComponentChange");pt(this,"onToggle");pt(this,"onInputChange");pt(this,"onInputFocus");pt(this,"onInputBlur");pt(this,"onLog");pt(this,"onButtonClick");pt(this,"onGraphPointClick");pt(this,"justFiredTriggers",new Set);pt(this,"rootTransform",null);pt(this,"canvasWidth",0);pt(this,"canvasHeight",0);pt(this,"lastHoveredObjectId",null);pt(this,"_lastPointerPos",null);pt(this,"_prevPointerPos",null);pt(this,"_mouseDelta",{dx:0,dy:0});pt(this,"focusedId",null);pt(this,"draggingSliderId",null);pt(this,"draggingJoystickId",null);pt(this,"activeDropdownId",null);pt(this,"activeObjectId",null);pt(this,"draggingListViewId",null);pt(this,"draggingListViewIsScrollbar",!1);pt(this,"scrollOffset",{x:0,y:0});pt(this,"_totalScroll",{x:0,y:0});pt(this,"draggingBehaviors",new Set);pt(this,"dragStartPointer",null);pt(this,"dragStartPositions",new Map);pt(this,"isMouseDown",!1);pt(this,"activeKeys",new Set);pt(this,"graphHoverStates",new Map);pt(this,"barChartRenderedBars",new Map);pt(this,"pieChartRenderedSlices",new Map);pt(this,"_layoutAnimCache",new Map);pt(this,"_springChainState",new Map);pt(this,"_emitterPools",new Map);pt(this,"objectVelocities",new Map);pt(this,"currentTime",0);pt(this,"frameCount",0);pt(this,"entranceStartTimes",new Map);pt(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});pt(this,"onLogicUpdate");pt(this,"logicNodeValues",new Map);pt(this,"logicNodeState",new Map);pt(this,"pointerDownTimes",new Map);pt(this,"activeHoverIds",new Set);pt(this,"onNavigation");pt(this,"periodicTriggerTimes",new Map);pt(this,"wasInView",new Set);pt(this,"scrollProgressLastValue",new Map);pt(this,"debug_objectsRendered",0);pt(this,"debug_objectsTotal",0);pt(this,"lastRenderTime",0);pt(this,"debugMode",!1);pt(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){if(this.inputs.has(t))return this.inputs.get(t);const s=this.inputNameMap.get(t);if(s&&s.length>0)return this.inputs.get(s[0])}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)return;const s=(t.type||"").toLowerCase();if(!(s==="path"||s==="custom"||s==="customshape"||s==="shape"||s==="subtract"||s==="union"||s==="intersect"||s==="exclude"||s==="booleanoperation"))return;const e=t.data||t.pathData||t.d||t.path||t.svgPath;if(t.points&&t.points.length>0){if(t.is_closed===void 0&&t.isClosed===void 0&&e){const{isClosed:a}=this.svgPathToPoints(e);t.is_closed=a}return}if(!e)return;const{points:n,isClosed:i}=this.svgPathToPoints(e);t.points=n,t.is_closed===void 0&&(t.is_closed=i)}svgPathToPoints(t){const s=/([MLHVCSQTAZmlhvcsqtaz])([^MLHVCSQTAZmlhvcsqtaz]*)/g,o=/[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/g,e=[];let n=!1,i=0,a=0,r=0,l=0,d=0,p=0,g="",u;for(;(u=s.exec(t))!==null;){const f=u[1],h=(u[2].match(o)||[]).map(parseFloat),m=f===f.toLowerCase(),b=f.toUpperCase();let c=0;const S=C=>{let w=h[c++];return m&&(w+=C?i:a),w},v=()=>({x:S(!0),y:S(!1)});switch(b){case"M":{const C=v();for(d=i=C.x,p=a=C.y,e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a,moveTo:!0});c<h.length;){const w=v();i=w.x,a=w.y,e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a})}break}case"L":for(;c<h.length;){const C=v();i=C.x,a=C.y,e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a})}break;case"H":for(;c<h.length;)i=S(!0),e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a});break;case"V":for(;c<h.length;)a=S(!1),e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a});break;case"C":for(;c<h.length;){const C=v(),w=v(),I=v();if(e.length>0){const k=e[e.length-1];k.out_x=C.x,k.out_y=C.y}i=I.x,a=I.y,e.push({x:i,y:a,in_x:w.x,in_y:w.y,out_x:i,out_y:a}),r=w.x,l=w.y}break;case"S":for(;c<h.length;){let C=i,w=a;(g==="C"||g==="S")&&(C=2*i-r,w=2*a-l);const I=v(),k=v();if(e.length>0){const O=e[e.length-1];O.out_x=C,O.out_y=w}i=k.x,a=k.y,e.push({x:i,y:a,in_x:I.x,in_y:I.y,out_x:i,out_y:a}),r=I.x,l=I.y}break;case"Q":for(;c<h.length;){const C=v(),w=v();if(e.length>0){const I=e[e.length-1];I.out_x=I.x+2/3*(C.x-I.x),I.out_y=I.y+2/3*(C.y-I.y)}i=w.x,a=w.y,e.push({x:i,y:a,in_x:i+2/3*(C.x-i),in_y:a+2/3*(C.y-a),out_x:i,out_y:a}),r=C.x,l=C.y}break;case"T":for(;c<h.length;){let C=i,w=a;(g==="Q"||g==="T")&&(C=2*i-r,w=2*a-l);const I=v();if(e.length>0){const k=e[e.length-1];k.out_x=k.x+2/3*(C-k.x),k.out_y=k.y+2/3*(w-k.y)}i=I.x,a=I.y,e.push({x:i,y:a,in_x:i+2/3*(C-i),in_y:a+2/3*(w-a),out_x:i,out_y:a}),r=C,l=w}break;case"A":for(;c+6<h.length;){const C=Math.abs(h[c++]),w=Math.abs(h[c++]),I=h[c++],k=h[c++],O=h[c++];let T=h[c++],A=h[c++];if(m&&(T+=i,A+=a),C===0||w===0||Math.abs(T-i)<.001&&Math.abs(A-a)<.001){i=T,a=A,e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a});break}const D=I*Math.PI/180,Y=Math.cos(D),B=Math.sin(D),R=(i-T)/2,L=(a-A)/2,$=Y*R+B*L,F=-B*R+Y*L;let X=C,M=w;const E=$*$,P=F*F;let _=X*X,V=M*M;const G=E/_+P/V;if(G>1){const St=Math.sqrt(G);X*=St,M*=St,_=X*X,V=M*M}const x=k!==O?1:-1,U=Math.max(0,_*V-_*P-V*E),q=_*P+V*E,N=q>0?Math.sqrt(U/q):0,H=x*N*(X*F)/M,z=x*N*-(M*$)/X,et=Y*H-B*z+(i+T)/2,Mt=B*H+Y*z+(a+A)/2,ct=($-H)/X,It=(F-z)/M,mt=(-$-H)/X,kt=(-F-z)/M,Ot=(St,Pt)=>{const Ft=St[0]*Pt[0]+St[1]*Pt[1],lt=Math.sqrt((St[0]**2+St[1]**2)*(Pt[0]**2+Pt[1]**2)),ht=Math.max(-1,Math.min(1,Ft/lt));return(St[0]*Pt[1]-St[1]*Pt[0]<0?-1:1)*Math.acos(ht)};let vt=Ot([1,0],[ct,It]),Wt=Ot([ct,It],[mt,kt]);!O&&Wt>0&&(Wt-=2*Math.PI),O&&Wt<0&&(Wt+=2*Math.PI);const J=Math.max(1,Math.ceil(Math.abs(Wt)/(Math.PI/2))),ut=Wt/J,$t=St=>({x:Y*X*Math.cos(St)-B*M*Math.sin(St)+et,y:B*X*Math.cos(St)+Y*M*Math.sin(St)+Mt,tx:-Y*X*Math.sin(St)-B*M*Math.cos(St),ty:-B*X*Math.sin(St)+Y*M*Math.cos(St)});for(let St=0;St<J;St++){const Pt=vt+St*ut,Ft=vt+(St+1)*ut,lt=Math.sin(ut)*(Math.sqrt(4+3*Math.tan(ut/2)**2)-1)/3,ht=$t(Pt),dt=$t(Ft),At=ht.x+lt*ht.tx,Tt=ht.y+lt*ht.ty,Ct=dt.x-lt*dt.tx,Yt=dt.y-lt*dt.ty;if(e.length>0){const ie=e[e.length-1];ie.out_x=At,ie.out_y=Tt}i=dt.x,a=dt.y,e.push({x:i,y:a,in_x:Ct,in_y:Yt,out_x:i,out_y:a})}r=i,l=a}break;case"Z":if(n=!0,e.length>0){const C=e[e.length-1];C.closePath=!0;const w=[...e].reverse().find(I=>I.moveTo)||e[0];w&&Math.hypot(w.x-C.x,w.y-C.y)<.1&&(w.in_x=C.in_x,w.in_y=C.in_y,e.pop(),e.length>0&&(e[e.length-1].closePath=!0))}i=d,a=p;break;default:if(h.length>=2){const C=v();i=C.x,a=C.y,e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a})}break}b!=="S"&&b!=="T"&&(g=b)}return{points:e,isClosed:n}}setOnLogCallback(t){this.onLog=t}debugLog(t){this.onLog&&this.onLog(t)}setInputFocusCallback(t){this.onInputFocus=t}setInputBlurCallback(t){this.onInputBlur=t}updateConstraint(t,s,o){var n;const e=(n=this.artboard)==null?void 0:n.objects.find(i=>i.id===t);e&&e.constraints&&e.constraints[s]&&(e.constraints[s]={...e.constraints[s],...o},o.useSpring===!1&&this.objectVelocities.delete(t))}log(...t){this.debugMode&&console.log(...t)}warn(...t){this.debugMode&&console.warn(...t)}setInternalInput(t,s){this.inputs.set(t,s),this.onInputUpdate&&this.onInputUpdate(t,s)}setLayout(t,s){this.layout={fit:t,alignment:s}}getActiveStateIds(t="Base Layer"){const s=this.layerStates.get(t);return s?s.currentStateIds:[]}getObjectState(t){return this.objectStates.get(t)}updateObjectOptions(t,s){const o=this.objectStates.get(t);o&&(o.options={...o.options,...s})}updateGraphData(t,s,o){var n,i,a;if(!this.artboard)return;const e=this.artboard.objects.find(r=>r.id===t||r.name===t);if(e){const r=((n=e.geometry)==null?void 0:n.type)==="LineGraph",l=e.type==="BarChart"||e.type==="Component"&&e.variant==="barchart",d=e.type==="PieChart"||e.type==="Component"&&e.variant==="piechart";if(r){const p=e.geometry,g=Array.isArray(s[0])?s[0]:s;!p.datasets||p.datasets.length===0?p.datasets=[{id:"default",label:"Runtime Data",data:g,lineColor:"#3b82f6",lineWidth:2,showArea:!1}]:p.datasets[0].data=g;const u=this.objectStates.get(e.id);u&&((i=u.geometry)==null?void 0:i.type)==="LineGraph"&&(!u.geometry.datasets||u.geometry.datasets.length===0?u.geometry.datasets=JSON.parse(JSON.stringify(p.datasets)):u.geometry.datasets[0].data=[...g]),(a=p.datasets[0])!=null&&a.inputId&&this.updateInput(p.datasets[0].inputId,g);return}else if(l){this.updateBarChartData(e.id,Array.isArray(s[0])?s:[s],o);return}else if(d){this.updatePieChartData(e.id,Array.isArray(s[0])?s[0]:s);return}}this.updateInput(t,s)}updateBarChartData(t,s,o){if(!this.artboard)return;const e=this.artboard.objects.find(l=>l.id===t||l.name===t);if(!e){this.updateInput(t,s);return}const n=this.objectStates.get(e.id),i=(n==null?void 0:n.options)||e.options||{},a=s.map((l,d)=>{var g;const p=((g=i.datasets)==null?void 0:g[d])||{};return Array.isArray(l)?{id:p.id||`ds-${d}`,label:p.label||`Series ${d+1}`,color:p.color||"#6366f1",data:l}:{id:l.id||p.id||`ds-${d}`,label:l.label||p.label||`Series ${d+1}`,color:l.color||p.color||"#6366f1",data:l.data||[]}}),r={...i,datasets:a};o&&Array.isArray(o)&&(r.categories=o),e.options=r,n&&(n.options=r),i.datasetInputIds&&Array.isArray(i.datasetInputIds)&&i.datasetInputIds.forEach((l,d)=>{a[d]&&this.updateInput(l,a[d].data)}),o&&i.dataInputId&&this.updateInput(i.dataInputId,o)}updatePieChartData(t,s){if(!this.artboard)return;const o=this.artboard.objects.find(l=>l.id===t||l.name===t);if(!o){this.updateInput(t,s);return}const e=this.objectStates.get(o.id),n=(e==null?void 0:e.options)||o.options||{},i=n.slices||[],a=s.map((l,d)=>{const p=i[d]||{};return typeof l=="number"?{id:p.id||`slice-${d}`,label:p.label||`Item ${d+1}`,color:p.color||"",value:l}:{id:l.id||p.id||`slice-${d}`,label:l.label||p.label||`Item ${d+1}`,color:l.color||p.color||"",value:typeof l.value=="number"?l.value:parseFloat(l.value)||0}}),r={...n,slices:a};o.options=r,e&&(e.options=r),n.dataInputId&&this.updateInput(n.dataInputId,a.map(l=>l.value))}setDropdownOptions(t,s){if(!this.artboard)return;const o=this.artboard.objects.find(a=>a.id===t||a.name===t);if(!o){this.updateInput(t,s);return}const e=this.objectStates.get(o.id),n=(e==null?void 0:e.options)||o.options||{},i={...n,optionsList:s};o.options=i,e&&(e.options=i),n.dataInputId&&this.updateInput(n.dataInputId,s)}load(t){var i,a;if(!t)return;let s=this.decompressStrings(t);const o=[],e=new Set,n=r=>{r&&r.forEach(l=>{if(e.has(l.id))return;const d={...l},p=d.childrenObjects||[];e.add(d.id),o.push(d),n(p)})};if(n(s.objects||[]),o.length>(s.objects||[]).length&&this.log(`[Engine] Flattened artboard from ${(s.objects||[]).length} to ${o.length} objects.`),s.objects=o,this.artboard=s,this.currentTime=0,this.objectStates.clear(),this.log(`[ExodeUIEngine] Loading artboard: "${(i=this.artboard)==null?void 0:i.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(l=>{r.set(l.id,l),l.children||(l.children=[])}),this.artboard.objects.forEach(l=>{if(l.parentId){const d=r.get(l.parentId);d&&(d.children||(d.children=[]),d.children.includes(l.id)||d.children.push(l.id))}})}this.loadFonts(),this.preloadImages(this.artboard),this.reset(),this.advance(0)}preloadImages(t){if(!t||!t.objects)return;const s=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=n=>{console.error("[ExodeUI Preload] failed:",n,`Src: ${o.substring(0,80)}...`)},e.src=o,this.imageCache.set(o,e)};t.objects.forEach(o=>{var e,n,i;(e=o.geometry)!=null&&e.src&&s(o.geometry.src),(i=(n=o.style)==null?void 0:n.fill)!=null&&i.src&&s(o.style.fill.src)})}decompressStrings(t){if(t&&typeof t=="object"&&!Array.isArray(t)){if(t._compressed&&t._data)try{const o=ws.decompressFromBase64(t._data);if(o)return o}catch(o){return console.error("[ExodeUI] Failed to decompress string:",o),t._data}const s={};for(const[o,e]of Object.entries(t))s[o]=this.decompressStrings(e);return s}return Array.isArray(t)?t.map(s=>this.decompressStrings(s)):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(s=>{var i,a,r,l,d,p,g;const o=s.width??((i=s.geometry)==null?void 0:i.width)??0,e=s.height??((a=s.geometry)==null?void 0:a.height)??0,n=s.cornerRadius??s.corner_radius??((r=s.geometry)==null?void 0:r.corner_radius)??((l=s.geometry)==null?void 0:l.cornerRadius)??0;this.objectStates.set(s.id,{...s.transform||{},x:((d=s.transform)==null?void 0:d.x)??s.x??0,y:((p=s.transform)==null?void 0:p.y)??s.y??0,width:o,height:e,cornerRadius:n,corner_radius:n,clipContent:s.clipContent??!1,autoLayout:s.autoLayout?JSON.parse(JSON.stringify(s.autoLayout)):void 0,layoutProps:s.layoutProps?JSON.parse(JSON.stringify(s.layoutProps)):void 0,opacity:((g=s.transform)==null?void 0:g.opacity)!==void 0?s.transform.opacity:s.opacity!==void 0?s.opacity:100,visible:s.visible!==void 0?s.visible:s.isVisible!==void 0?s.isVisible:!0,blendMode:s.blendMode||"Normal",style:JSON.parse(JSON.stringify(s.style||{})),geometry:JSON.parse(JSON.stringify(s.geometry||{})),options:s.options?JSON.parse(JSON.stringify(s.options)):{},masks:s.masks?JSON.parse(JSON.stringify(s.masks)):[],zIndex:s.zIndex!==void 0?s.zIndex:void 0})}),this.artboard.objects.some(s=>{var o;return(o=s.physics)==null?void 0:o.enabled})){this.physicsEngine=new os;const s=this.artboard.physics?{x:this.artboard.physics.gravity.x,y:this.artboard.physics.gravity.y}:{x:0,y:1};this.physicsEngine.init(s).then(()=>{var o;this.physicsEngine&&((o=this.artboard)==null||o.objects.forEach(e=>{var n,i;if((n=e.physics)!=null&&n.enabled&&e.type==="Shape"){const a=this.objectStates.get(e.id);if(!a)return;const r=e.geometry.width||100,l=e.geometry.height||100;this.physicsEngine.createBody({id:e.id,type:((i=e.geometry)==null?void 0:i.type)||"Rectangle",x:a.x,y:a.y,width:r,height:l,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(s=>{var n,i;let o=s.value;if(s.type==="RandomNumber"||s.type==="random_number"||s.min!==void 0&&s.max!==void 0&&((n=s.type)!=null&&n.toLowerCase().includes("random"))){const a=s.min??0,r=s.max??100;o=Math.random()*(r-a)+a}else if(s.type==="RandomColor"||s.type==="random_color"||s.minAlpha!==void 0&&((i=s.type)!=null&&i.toLowerCase().includes("random"))){const a=Math.floor(Math.random()*256),r=Math.floor(Math.random()*256),l=Math.floor(Math.random()*256),d=s.minAlpha??0,p=s.maxAlpha??1,g=(Math.random()*(p-d)+d).toFixed(2);o=`rgba(${a}, ${r}, ${l}, ${g})`}this.inputs.set(s.id,o);const e=this.inputNameMap.get(s.name)||[];e.includes(s.id)||e.push(s.id),this.inputNameMap.set(s.name,e)}),this.artboard.stateMachine&&(this.activeStateMachine=this.artboard.stateMachine,this.activeStateMachine.inputs.forEach(s=>{this.inputs.set(s.id,s.value.value);const o=this.inputNameMap.get(s.name)||[];o.push(s.id),this.inputNameMap.set(s.name,o)}),this.activeStateMachine.layers.forEach(s=>{let o=s.states.find(e=>e.id===s.entryStateId);!o&&s.states.length>0&&(console.warn(`[ExodeUI] Invalid entryStateId "${s.entryStateId}" in layer "${s.name}". Falling back to first state.`),o=s.states[0]),o&&this.enterStates(s.name,[o.id])}),this.evaluateTransitions()),this.initGlobalAnimationTriggers(),this.updateAutoLayout(!0),this.loadFonts()}updateAutoLayout(t=!1){var n;if(!this.artboard)return;const s=new Map;this.artboard.objects.forEach(i=>s.set(i.id,i));const o=.15,e=i=>{i.forEach(a=>{const r=this.objectStates.get(a.id);if(r){const l=Math.abs(r.x-a.x),d=Math.abs(r.y-a.y);!t&&(l>20||d>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((n=this.artboard.autoLayout)!=null&&n.enabled){const i=this.artboard.objects.filter(r=>!r.parentId),a=ns(this.artboard,i,r=>this.objectStates.get(r));e(a.childUpdates)}this.artboard.objects.forEach(i=>{var a;if(i.type==="Frame"&&((a=i.autoLayout)!=null&&a.enabled)&&i.children&&i.children.length>0){const r=i.children.map(p=>s.get(p)).filter(p=>!!p),l=this.objectStates.get(i.id);if(!l)return;const d=ns(l,r,p=>this.objectStates.get(p));d.frameWidth!==void 0&&(l.width=d.frameWidth),d.frameHeight!==void 0&&(l.height=d.frameHeight),e(d.childUpdates)}})}loadFonts(){if(!this.artboard)return;const t=new Set;if(this.artboard.objects.forEach(i=>{i.geometry&&i.geometry.type==="Text"&&i.geometry.fontFamily&&t.add(i.geometry.fontFamily)}),this.artboard.animations.forEach(i=>{i.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 s="";t.forEach(i=>{const a=i.replace(/ /g,"+");s+=`&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(s.length>0){const i=`https://fonts.googleapis.com/css2?display=swap${s}`;let a=document.getElementById(o);a||(a=document.createElement("link"),a.id=o,a.rel="stylesheet",document.head.appendChild(a)),a.href!==i&&(a.href=i)}const n=[];if(t.forEach(i=>{i.toLowerCase().includes("clash display")&&n.push("clash-display@200,300,400,500,600,700")}),n.length>0){const i=`https://api.fontshare.com/v2/css?f[]=${n.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!==i&&(a.href=i)}document.fonts&&document.fonts.ready&&document.fonts.ready.then(()=>{this.pretextCache.clear(),this.advance(0)})}enterStates(t,s){var i;if(s.length===0)return;const o=this.layerStates.get(t);if(o&&o.currentStateIds.length===s.length&&s.every(r=>o.currentStateIds.includes(r))&&this.justFiredTriggers.size===0)return;const e=[];let n=0;if(this.artboard&&this.activeStateMachine){const a=this.activeStateMachine.layers.find(r=>r.name===t);if(a)for(const r of s){const l=a.states.find(d=>d.id===r);if(l)if(l.isBlendState&&l.blendAnimations&&l.blendAnimations.length>0)e.push({animation:null,state:l}),l.blendAnimations.forEach(d=>{const p=this.artboard.animations.find(g=>g.id===d.animationId);p&&(n=Math.max(n,this.getAnimationDuration(p)))});else{let d=null;l.animationId&&(d=this.artboard.animations.find(p=>p.id===l.animationId)||null),d||(d=this.artboard.animations.find(p=>{var g,u;return p.name===l.name||p.id===l.name||(l.name==="Entry"||l.id==="entry")&&(((g=p.name)==null?void 0:g.toLowerCase())==="onload"||((u=p.name)==null?void 0:u.toLowerCase())==="intro")})||null),d&&((i=this.artboard.animationFlow)!=null&&i.some(g=>(g.trigger==="on_load"||g.trigger==="after_delay")&&g.targetAnimationId===(d==null?void 0:d.id))||(e.push({animation:d,state:l}),n=Math.max(n,this.getAnimationDuration(d))))}}}this.layerStates.set(t,{currentStateIds:s,animations:e,time:0,duration:n})}setInputBool(t,s){this.updateInput(t,s)}setInputNumber(t,s){this.updateInput(t,s)}fireTrigger(t){this.updateInput(t,!0)}setInputText(t,s){this.updateInput(t,s)}setInputNumberArray(t,s){this.updateInput(t,s)}setInputStringArray(t,s){this.updateInput(t,s)}updateObjectProperty(t,s,o){const e=this.objectStates.get(t);if(e)if(s.includes(".")||s.includes("[")){const n=s.replace(/\[(\d+)\]/g,".$1").split(".");let i=e;for(let a=0;a<n.length-1;a++){if(typeof i[n[a]]!="object"||i[n[a]]===null){const r=n[a+1],l=!isNaN(Number(r));i[n[a]]=l?[]:{}}i=i[n[a]]}i[n[n.length-1]]=o}else e[s]=o}updateInput(t,s){var l,d,p,g,u;let o;if(this.inputs.has(t)){const f=(l=this.activeStateMachine)==null?void 0:l.inputs.find(h=>h.id===t);f&&typeof f.value=="object"&&(o=f.value.type)}else{const f=this.inputNameMap.get(t);if(f&&f.length>0){const h=(d=this.activeStateMachine)==null?void 0:d.inputs.find(m=>m.id===f[0]);h&&typeof h.value=="object"&&(o=h.value.type)}}let e=s;o==="Trigger"&&(s===1?e=!0:s===0&&(e=!1));const n=(g=(p=this.artboard)==null?void 0:p.stateVariables)==null?void 0:g.find(f=>f.id===t||f.name===t);if(n&&(n.type==="RandomNumber"||n.type==="RandomColor"||n.type&&String(n.type).toLowerCase().includes("random"))){if(n.type==="RandomNumber"||n.type==="random_number"||n.min!==void 0&&n.max!==void 0){const f=n.min??0,h=n.max??100;e=Math.random()*(h-f)+f}else if(n.type==="RandomColor"||n.type==="random_color"||n.minAlpha!==void 0){const f=Math.floor(Math.random()*256),h=Math.floor(Math.random()*256),m=Math.floor(Math.random()*256),b=n.minAlpha??0,c=n.maxAlpha??1,S=(Math.random()*(c-b)+b).toFixed(2);e=`rgba(${f}, ${h}, ${m}, ${S})`}}let i=!1;this.inputs.has(t)&&(this.setInternalInput(t,e),i=!0);const a=this.inputNameMap.get(t);a&&a.length>0&&(a.forEach(f=>this.setInternalInput(f,e)),i=!0),i||this.setInternalInput(t,e),o==="Trigger"&&e===!0&&(this.justFiredTriggers.add(t),a&&a.forEach(f=>this.justFiredTriggers.add(f)));let r=null;if(Array.isArray(e))r=e;else if(typeof e=="string"&&e.trim().startsWith("[")&&e.trim().endsWith("]"))try{const f=JSON.parse(e);Array.isArray(f)&&(r=f)}catch{}r&&((u=this.artboard)==null||u.objects.forEach(f=>{var b;const h=(b=f.options)==null?void 0:b.dataInputId;if(f.inputId===t||f.name===t||h===t||a&&(a.includes(f.inputId)||h&&a.includes(h))){let c=this.objectStates.get(f.id);c&&!c.options&&(c.options=JSON.parse(JSON.stringify(f.options||{}))),c&&c.options&&(this.isListViewObject(f)?c.options.items=r:(f.type==="Dropdown"||f.variant==="dropdown")&&(c.options.optionsList=r)),f.options&&(this.isListViewObject(f)?f.options.items=r:(f.type==="Dropdown"||f.variant==="dropdown")&&(f.options.optionsList=r))}})),this.evaluateTransitions(),this.evaluateVariableTriggers(t,e)}evaluateVariableTriggers(t,s){if(!this.artboard)return;const o=this.artboard.animationFlow||[],e=this.inputNameMap.get(t);o.forEach(n=>{if(n.trigger==="variable"&&n.conditionVariableId&&n.targetAnimationId&&(n.conditionVariableId===t||e&&e.includes(n.conditionVariableId))){const a=n.conditionOperator||"IsTrue",r=n.conditionValue;let l=!1;switch(a){case"Equal":case"==":l=s==r;break;case"NotEqual":case"!=":l=s!=r;break;case"GreaterThan":case">":l=s>r;break;case"LessThan":case"<":l=s<r;break;case"GreaterEqual":case">=":l=s>=r;break;case"LessEqual":case"<=":l=s<=r;break;case"IsTrue":l=!!s;break;case"IsFalse":l=!s;break}if(l){const d=n.delay||0;d<=0?this.triggerGlobalAnimation(n.targetAnimationId,n.subAnimationIds,n.loop,n.id):setTimeout(()=>this.triggerGlobalAnimation(n.targetAnimationId,n.subAnimationIds,n.loop,n.id),d)}}})}evaluateTransitions(){this.activeStateMachine&&(this.activeStateMachine.layers.forEach(t=>{const s=this.layerStates.get(t.name);if(!s||s.currentStateIds.length===0)return;const o=[];let e=!1;for(const n of s.currentStateIds){const i=t.states.find(r=>r.id===n);if(!i)continue;let a=!1;for(const r of i.transitions||[])this.checkConditions(r.conditions)&&(o.push(r.targetStateId),a=!0,e=!0);a||o.push(n)}if(!e){const n=this.findGlobalTransition(t,s.currentStateIds);n&&(o.length=0,o.push(n.targetStateId),e=!0,n.conditions&&(n.conditions||[]).forEach(i=>{var r;const a=(r=this.activeStateMachine)==null?void 0:r.inputs.find(l=>l.id===i.inputId);a&&typeof a.value=="object"&&a.value.type==="Trigger"&&this.setInternalInput(i.inputId,!1)}))}if(e){const n=Array.from(new Set(o));this.enterStates(t.name,n)}}),this.justFiredTriggers.size>0&&(this.justFiredTriggers.forEach(t=>{var o,e;this.setInternalInput(t,!1);const s=(o=this.activeStateMachine)==null?void 0:o.inputs.find(n=>n.id===t);s&&this.inputNameMap.has(s.name)&&((e=this.inputNameMap.get(s.name))==null||e.forEach(n=>this.setInternalInput(n,!1)))}),this.justFiredTriggers.clear()))}findGlobalTransition(t,s){for(const o of t.states)if(!(s.includes(o.id)&&this.justFiredTriggers.size===0)){for(const n of o.transitions||[])if(!(s.includes(n.targetStateId)&&this.justFiredTriggers.size===0)&&this.checkConditions(n.conditions))return n}return null}checkConditions(t){return!t||t.length===0?!0:t.every(s=>{const o=s.inputId,e=s.op;let n=s.value;const i=this.evaluateLogicTree(o);if(i===void 0)return this.log(`[Engine] Condition Check Failed: Input ${o} is undefined`),!1;typeof i=="boolean"?n==="true"||n==="1"||n===1?n=!0:(n==="false"||n==="0"||n===0)&&(n=!1):typeof i=="number"&&typeof n=="string"&&(n=parseFloat(n));let a=!1;switch(e){case"Equal":case"==":a=i==n;break;case"NotEqual":case"!=":a=i!=n;break;case"GreaterThan":case">":a=i>n;break;case"LessThan":case"<":a=i<n;break;case"GreaterEqual":case">=":a=i>=n;break;case"LessEqual":case"<=":a=i<=n;break;case"IsTrue":a=!!i;break;case"IsFalse":a=!i;break;default:a=!1}return a||this.justFiredTriggers.has(o),a})}evaluateLogicTree(t,s=null,o=new Set){var a,r,l,d,p,g;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(u=>u.id===t);if(e){const u=(h,m)=>{const b=e.inputs.find(c=>c.id===h);return b?b.sourceId?this.evaluateLogicTree(b.sourceId,b.sourceHandleId,o):b.value!==void 0?b.value:m:m};let f=0;switch(e.op){case Ht.AND:f=u("a",!1)&&u("b",!1);break;case Ht.OR:f=u("a",!1)||u("b",!1);break;case Ht.NOT:f=!u("in",!1);break;case Ht.XOR:f=!!u("a",!1)!=!!u("b",!1);break;case Ht.OBJECT:f=e.name;break;case Ht.PROPERTY:case Ht.GET_PROPERTY:{const h=u("id","");if(!h){f=0;break}const m=e.name;if(!m||m==="GET_PROPERTY"||m==="PROPERTY"){f=0;break}const b=this.objectStates.get(h);if(!b){f=0;break}m in b?f=b[m]:f=this.resolvePath(b,m);break}case Ht.SET_PROPERTY:{const h=u("id",""),m=u("value",void 0);if(!h||m===void 0){f=0;break}const b=e.name;if(!b||b==="SET_PROPERTY"){f=0;break}const c=this.objectStates.get(h);if(!c){f=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(b))c[b]=m,f=m;else{const v=b.replace(/\[(\d+)\]/g,".$1").split(".");let C=c;for(let I=0;I<v.length-1;I++){const k=v[I],O=v[I+1];C[k]===void 0&&(C[k]=isNaN(Number(O))?{}:[]),C=C[k]}const w=v[v.length-1];C[w]=m,f=m}break}case Ht.ADD:f=u("a",0)+u("b",0);break;case Ht.SUB:f=u("a",0)-u("b",0);break;case Ht.MUL:f=u("a",0)*u("b",0);break;case Ht.DIV:{const h=u("b",1);f=h===0?0:u("a",0)/h;break}case Ht.MOD:f=u("a",0)%u("b",1);break;case Ht.POW:f=Math.pow(u("a",0),u("b",1));break;case Ht.ABS:f=Math.abs(u("in",0));break;case Ht.ROUND:f=Math.round(u("in",0));break;case Ht.FLOOR:f=Math.floor(u("in",0));break;case Ht.CEIL:f=Math.ceil(u("in",0));break;case Ht.SIN:f=Math.sin(u("in",0));break;case Ht.COS:f=Math.cos(u("in",0));break;case Ht.TAN:f=Math.tan(u("in",0));break;case Ht.CLAMP:{const h=u("in",0),m=u("min",0),b=u("max",1);f=Math.max(m,Math.min(b,h));break}case Ht.REMAP:{const h=u("in",0),m=u("inMin",0),b=u("inMax",100),c=u("outMin",0),S=u("outMax",1);f=b===m?c:c+(h-m)*(S-c)/(b-m);break}case Ht.EQ:f=u("a",0)==u("b",0);break;case Ht.NEQ:f=u("a",0)!=u("b",0);break;case Ht.GT:f=u("a",0)>u("b",0);break;case Ht.LT:f=u("a",0)<u("b",0);break;case Ht.GTE:f=u("a",0)>=u("b",0);break;case Ht.LTE:f=u("a",0)<=u("b",0);break;case Ht.IF_ELSE:f=u("cond",!1)?u("then",0):u("else",0);break;case Ht.VALUE:f=e.value!==void 0?e.value:0;break;case Ht.INPUT:f=this.inputs.get(e.name)??0;break;case Ht.LOG:{const h=u("in","");this.debugLog(`[User Logic] ${h}`),f=h;break}case Ht.SCROLL_X:f=this.inputs.get("scrollX")??0;break;case Ht.SCROLL_Y:f=this.inputs.get("scrollY")??0;break;case Ht.MOUSE_X:f=this.inputs.get("mouseX")??0;break;case Ht.MOUSE_Y:f=this.inputs.get("mouseY")??0;break;case Ht.IS_MOUSE_DOWN:f=this.inputs.get("isMouseDown")??!1;break;case Ht.EFFECTOR:{const h=u("id",""),m=u("intensity",1),b=u("trigger",!0);if(!h||!b){f=0;break}const c=e.name;if(!c){f=0;break}const S=this.objectStates.get(h);if(!S){f=0;break}if(["glitch","halftone","pixelate","noise","acid_gradient","acid_rave","shimmer"].includes(c))S.style||(S.style={}),S.style.artEffect={enabled:!0,type:c,intensity:m},f=1;else{S.behaviors||(S.behaviors=[]);let C=S.behaviors.find(w=>w.type===c);C?(C.enabled=!0,C.settings||(C.settings={}),C.settings.intensity=m):(C={id:`eff_${Date.now()}_${c}`,type:c,enabled:!0,sensors:[],settings:{intensity:m}},S.behaviors.push(C)),f=1}break}case Ht.MONITOR:{f=u("in",0);break}case Ht.SPRING_PULL:{const h=u("objectId",""),m=u("forceX",0),b=u("forceY",0);h&&((l=this.artboard)==null||l.objects.forEach(c=>{c.behaviors&&c.behaviors.forEach(S=>{var v;if(S.type===it.SpringChain&&((v=S.settings)!=null&&v.connections)&&(S.settings.connections.some(w=>w.targetId===h)||c.id===h)){this._springChainState.has(c.id)||this._springChainState.set(c.id,new Map);const w=this._springChainState.get(c.id);if(!w.has(h)){const k=this.objectStates.get(h);w.set(h,{x:(k==null?void 0:k.x)??0,y:(k==null?void 0:k.y)??0,vx:0,vy:0})}const I=w.get(h);I&&(I.vx+=m,I.vy+=b)}})})),f=1;break}case Ht.SPRING_SETTLE:{const h=u("objectId","");let m=!0;if(h){const b=u("threshold",1);this._springChainState.forEach(c=>{const S=c.get(h);S&&(Math.abs(S.vx)>b||Math.abs(S.vy)>b)&&(m=!1)})}f=m;break}case Ht.EMIT:{const h=u("objectId",""),m=u("count",20);h&&((d=this.artboard)==null||d.objects.forEach(b=>{b.behaviors&&b.behaviors.forEach(c=>{c.type===it.ParticleEmitter&&b.id===h&&(c._pendingBurst=(c._pendingBurst||0)+m)})})),f=1;break}default:f=0;break}if(this.logicNodeValues.set(t,f),e.op===Ht.DELAY){const h=u("delay",0),m=u("in",0);let b=this.logicNodeState.get(t);for(b||(b={queue:[]},this.logicNodeState.set(t,b)),b.queue.push({time:this.currentTime+h,value:m});b.queue.length>0&&b.queue[0].time<=this.currentTime;)b.lastValue=b.queue.shift().value;f=b.lastValue??0}return f}const n=(p=this.activeStateMachine)==null?void 0:p.inputs.find(u=>u.id===t||u.name===t);if(n&&n.sourceId&&!o.has(n.sourceId)){const u=this.evaluateLogicTree(n.sourceId,n.sourceHandleId,o);return this.inputs.set(n.id,u),u}let i=this.inputs.get(t)??(n?this.inputs.get(n.id):void 0);if((this.justFiredTriggers.has(t)||n&&this.justFiredTriggers.has(n.id))&&(i=!0),s&&i!==void 0){const u=(g=this.activeStateMachine)==null?void 0:g.inputs.find(f=>f.id===t);if(u&&u.value.type==="Number"&&typeof i=="number"){const f=u.value.defaultValue??u.value.value;if(s==="source-greater")return i>f;if(s==="source-less")return i<f;if(s==="source-equal")return i===f}if(s==="source-true")return i===!0;if(s==="source-false")return i===!1;if(s==="source-fire")return this.justFiredTriggers.has(t)}return i!==void 0?i:0}runLogicNodes(){!this.activeStateMachine||!this.activeStateMachine.logicNodes||this.activeStateMachine.logicNodes.forEach(t=>{(t.op===Ht.SET_PROPERTY||t.op===Ht.EFFECTOR)&&this.evaluateLogicTree(t.id)})}resolvePath(t,s){const o=s.replace(/\[(\d+)\]/g,".$1").split(".");let e=t;for(const n of o)if(e&&typeof e=="object"&&n in e)e=e[n];else return;return e}processLogicProperties(){!this.artboard||!this.artboard.objects||this.artboard.objects.forEach(t=>{const s=t.logicProperties;if(s&&s.length>0){const o=this.objectStates.get(t.id);if(!o)return;s.forEach(e=>{let n;if(e.valueType==="variable"?n=this.getInputValue(e.variableId):e.valueType==="constant"&&(n=e.value),n!==void 0){const i=e.name;if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(i))o[i]=n;else{const r=i.replace(/\[(\d+)\]/g,".$1").split(".");let l=o;for(let p=0;p<r.length-1;p++){const g=r[p],u=r[p+1];l[g]===void 0&&(l[g]=isNaN(Number(u))?{}:[]),l=l[g]}const d=r[r.length-1];l[d]=n}}})}})}seek(t){this.artboard&&(this.currentTime=t,this.layerStates.forEach(s=>{s.time=t,s.time>(s.duration||0)&&(s.animations.some(e=>{var n;return((n=e.state)==null?void 0:n.loop)===!0})?s.time%=s.duration||1:s.time=s.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 n=this.physicsEngine.getPosition(o.id),i=this.physicsEngine.getRotation(o.id),a=this.objectStates.get(o.id);a&&n!==null&&i!==null&&(a.x=n.x,a.y=n.y,a.rotation=i*(180/Math.PI))}})),this.activeStateMachine&&(this.runLogicNodes(),this.evaluateTransitions()),this.processLogicProperties();const s=[];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(i=>{var a;return((a=i.state)==null?void 0:a.loop)===!0}))o.time%=o.duration;else{const i=o.time<o.duration+.1;o.time=o.duration,i&&(e.startsWith("global_")&&console.log(`[Engine] GLOBAL layer done: ${e}, duration=${o.duration}, currentStateIds=${JSON.stringify(o.currentStateIds)}, ruleId=${o.ruleId}`),o.currentStateIds.length>0&&this.handleAnimationFinished(o.currentStateIds[0],o.ruleId),e.startsWith("global_")&&s.push(e))}o.animations.forEach(n=>{var i;(i=n.state)!=null&&i.isBlendState&&n.state.blendAnimations?this.applyBlendState(n.state,o.time):n.animation&&this.applyAnimation(n.animation,o.time,n.filterObjectIds)})}}),s.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 n,i,a,r,l,d,p;if(o.phase==="entry")o.time+=t,o.time>=this.getAnimationDuration(o.animation)&&((a=(i=(n=this.artboard)==null?void 0:n.objects.find(g=>g.id===e))==null?void 0:i.triggers)==null||a.find(g=>g.id===o.triggerId),o.phase="hold",o.elapsedHold=0,o.time=this.getAnimationDuration(o.animation)),this.applyAnimation(o.animation,o.time,o.filterObjectIds||o.filterObjectId||void 0);else if(o.phase==="hold"){const g=(d=(l=(r=this.artboard)==null?void 0:r.objects.find(h=>h.id===e))==null?void 0:l.triggers)==null?void 0:d.find(h=>h.id===o.triggerId),u=(g==null?void 0:g.duration)||0;o.elapsedHold+=t*1e3;let f=o.elapsedHold>=u;if((g==null?void 0:g.eventType)==="hover"&&!this.activeHoverIds.has(e)&&(f=!0),((g==null?void 0:g.eventType)==="onHold"||(g==null?void 0:g.eventType)==="pointerDown")&&!this.isMouseDown&&(f=!0),f)if(g!=null&&g.exitAnimationId){const h=(p=this.artboard)==null?void 0:p.animations.find(m=>m.id===g.exitAnimationId);h?(o.phase="exit",o.animation=h,o.time=0):this.activeTriggers.delete(e)}else this.activeTriggers.delete(e)}else o.phase==="exit"&&(o.time+=t,o.time>=this.getAnimationDuration(o.animation)?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(s=>{var e,n,i;const o=(e=s.style)==null?void 0:e.analytics;if(o&&o.isEnabled&&o.triggerType==="visible"){const a=this.objectStates.get(s.id);if(a&&a.visible!==!1){const r=this.getGlobalTransform(s.id),l=(((n=s.geometry)==null?void 0:n.width)||100)*(r.scale_x||1),d=(((i=s.geometry)==null?void 0:i.height)||100)*(r.scale_y||1),p=50,g=r.x+l/2>=-this.canvasWidth/2-p&&r.x-l/2<=this.canvasWidth/2+p&&r.y+d/2>=-this.canvasHeight/2-p&&r.y-d/2<=this.canvasHeight/2+p,u=`analytics_${s.id}`,f=this.wasInView.has(u);g&&!f&&this.fireAnalyticsEvent(s.id,"visible"),g?this.wasInView.add(u):this.wasInView.delete(u)}}}),this.artboard.objects.forEach(s=>{const o=s.interactions||[];o.length!==0&&o.forEach(e=>{const n=e.triggers||[e.event||e.trigger];n&&n.forEach(i=>{var r,l,d;const a=i.toLowerCase();if(a==="on interval"||a==="oninterval"){const p=e.intervalValue||2e3,g=this.periodicTriggerTimes.get(e.id)||0;this.currentTime*1e3-g>=p&&(!e.conditions||this.checkConditions(e.conditions))&&(this.fireEventForObject(s.id,"On Interval"),this.periodicTriggerTimes.set(e.id,this.currentTime*1e3))}if(a==="on delay"||a==="ondelay"){const p=e.delayValue||1e3;!this.periodicTriggerTimes.has(e.id)&&this.currentTime*1e3>=p&&(!e.conditions||this.checkConditions(e.conditions))&&(this.fireEventForObject(s.id,"On Delay"),this.periodicTriggerTimes.set(e.id,this.currentTime*1e3))}if(a==="scroll into view"||a==="scrollintoview"){const p=this.objectStates.get(s.id);if(p&&p.visible!==!1){const g=this.getGlobalTransform(s.id),u=(((r=s.geometry)==null?void 0:r.width)||100)*(g.scale_x||1),f=(((l=s.geometry)==null?void 0:l.height)||100)*(g.scale_y||1),h=50,m=g.x+u/2>=-this.canvasWidth/2-h&&g.x-u/2<=this.canvasWidth/2+h&&g.y+f/2>=-this.canvasHeight/2-h&&g.y-f/2<=this.canvasHeight/2+h,b=this.wasInView.has(s.id);m&&!b&&(!e.conditions||this.checkConditions(e.conditions))&&this.fireEventForObject(s.id,"Scroll Into View"),m?this.wasInView.add(s.id):this.wasInView.delete(s.id)}}if(a==="scroll progress"||a==="scrollprogress"){const p=Math.abs(this.scrollOffset.y)/(((d=this.artboard)==null?void 0:d.height)||1e3),g=this.scrollProgressLastValue.get(e.id)||0;Math.abs(p-g)>.001&&(this.scrollProgressLastValue.set(e.id,p),(e.action==="Set Input"||e.action==="setInput")&&this.updateInput(e.targetInputId,p))}})})}))}solveConstraints(t){this.artboard&&this.artboard.objects.forEach(s=>{if(!s.constraints||s.constraints.length===0)return;const o=this.objectStates.get(s.id);if(!o)return;const e=this.getGlobalTransform(s.id);if(s.constraints.forEach((n,i)=>{var d,p,g,u,f,h,m,b,c;const a=((d=o.constraints)==null?void 0:d[i])||{},r={...n,...a},l=r.strength??1;if(r.type==="Translation"){const S=this.getGlobalTransform(r.targetId);if(S){const v=r.offsetX||0,C=r.offsetY||0,w=S.x+v,I=S.y+C,k=r.useSpring;if(k){const A=this.objectVelocities.get(s.id)||{vx:0,vy:0},D=Math.max(0,Math.min(t,.05)),Y=r.copyX!==!1,B=r.copyY!==!1,R=Y?e.x+(w-e.x)*l:e.x,L=B?e.y+(I-e.y)*l:e.y,{x:$,y:F,vx:X,vy:M}=this.computeSpring(e.x,e.y,A.vx,A.vy,R,L,r,D);Y&&(e.x=$),B&&(e.y=F),this.objectVelocities.set(s.id,{vx:Y?X:0,vy:B?M:0})}else r.copyX!==!1&&(e.x=e.x+(w-e.x)*l),r.copyY!==!1&&(e.y=e.y+(I-e.y)*l);let O=!1,T=!1;if((p=r.limitX)!=null&&p.enabled){const A=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==A&&(O=!0)}if((g=r.limitY)!=null&&g.enabled){const A=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==A&&(T=!0)}if((O||T)&&k){const A=this.objectVelocities.get(s.id)||{vx:0,vy:0};this.objectVelocities.set(s.id,{vx:O?0:A.vx,vy:T?0:A.vy})}}}else if(r.type==="Rotation"){const S=this.getGlobalTransform(r.targetId);if(S){let C=(S.rotation+(r.offset||0)-e.rotation)%360;C>180&&(C-=360),C<-180&&(C+=360),e.rotation=e.rotation+C*l}}else if(r.type==="Scale"){const S=this.getGlobalTransform(r.targetId);S&&(r.copyX&&(e.scale_x=e.scale_x+(S.scale_x-e.scale_x)*l),r.copyY&&(e.scale_y=e.scale_y+(S.scale_y-e.scale_y)*l))}else if(r.type==="Transform"){const S=this.getGlobalTransform(r.targetId);if(S){e.x=e.x+(S.x-e.x)*l,e.y=e.y+(S.y-e.y)*l;let v=(S.rotation-e.rotation)%360;v>180&&(v-=360),v<-180&&(v+=360),e.rotation=e.rotation+v*l,e.scale_x=e.scale_x+(S.scale_x-e.scale_x)*l,e.scale_y=e.scale_y+(S.scale_y-e.scale_y)*l}}else if(r.type==="FollowPointer"){const S=((u=this._lastPointerPos)==null?void 0:u.x)??e.x,v=((f=this._lastPointerPos)==null?void 0:f.y)??e.y,C=r.useSpring;if(C){const I=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:k,y:O,vx:T,vy:A}=this.computeSpring(e.x,e.y,I.vx,I.vy,S,v,r,t);e.x=k,e.y=O,this.objectVelocities.set(s.id,{vx:T,vy:A})}else e.x=e.x+(S-e.x)*l,e.y=e.y+(v-e.y)*l;let w=!1;if((h=r.limitX)!=null&&h.enabled){const I=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==I&&(w=!0)}if((m=r.limitY)!=null&&m.enabled){const I=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==I&&(w=!0)}w&&C&&this.objectVelocities.set(s.id,{vx:0,vy:0})}else if(r.type==="Distance"){const S=this.getGlobalTransform(r.targetId);if(S){const v=e.x-S.x,C=e.y-S.y,w=Math.sqrt(v*v+C*C),I=r.distance||0;let k=w;switch(r.mode){case"exact":k=I;break;case"minimum":k=Math.max(I,w);break;case"maximum":k=Math.min(I,w);break;case"clamped":k=Math.max(0,Math.min(I,w));break}if(w>0){const O=e.x===S.x&&e.y===S.y?1:k/w;e.x=e.x+(S.x+v*O-e.x)*l,e.y=e.y+(S.y+C*O-e.y)*l}}}else if(r.type==="FollowPath"){const S=(b=this.artboard)==null?void 0:b.objects.find(v=>v.id===r.targetId);if(S){const v=this.getGlobalTransform(S.id);if(v){let C=S.geometry;if(S.type==="Frame"||S.type==="Group"||!C||C.type!=="Path"&&C.type!=="Ellipse"&&C.type!=="Rectangle"){const _=(c=this.artboard)==null?void 0:c.objects.find(V=>V.parentId===S.id&&V.type==="Shape"&&V.geometry&&(V.geometry.type==="Path"||V.geometry.type==="Ellipse"||V.geometry.type==="Rectangle"));_&&(C=_.geometry)}if(!C)return;const w=Math.max(0,Math.min(1,(r.distance||0)/100)),I=v.width||C.width||0,k=v.height||C.height||0,O=this.getPointOnPath(C,I,k,w),T=v.rotation*Math.PI/180,A=Math.cos(T),D=Math.sin(T),Y=O.x*v.scale_x*A-O.y*v.scale_y*D,B=O.x*v.scale_x*D+O.y*v.scale_y*A;let R=v.rotation+(r.offsetRotation||0);if(r.orient){const _=Math.cos(O.angle),V=Math.sin(O.angle),G=_*v.scale_x*A-V*v.scale_y*D,x=_*v.scale_x*D+V*v.scale_y*A;R=Math.atan2(x,G)*180/Math.PI+(r.offsetRotation||0)}const L=R*Math.PI/180,$=Math.cos(L),F=Math.sin(L),X=(r.offsetX||0)*$-(r.offsetY||0)*F,M=(r.offsetX||0)*F+(r.offsetY||0)*$,E=v.x+Y+X,P=v.y+B+M;if(e.x=e.x+(E-e.x)*l,e.y=e.y+(P-e.y)*l,r.orient){let _=(R-e.rotation)%360;_>180&&(_-=360),_<-180&&(_+=360),e.rotation=e.rotation+_*l}}}}else if(r.type==="IK"){const S=this.getGlobalTransform(r.targetId);S&&this.solveIK(s,S,r.boneCount||2,l)}}),s.constraints.some(n=>n.type!=="IK")){const n=this.globalToLocal(s.parentId,e);o.x=n.x,o.y=n.y,o.rotation=n.rotation,o.flip_x=n.scale_x<0,o.scale_x=Math.abs(n.scale_x),o.flip_y=n.scale_y<0,o.scale_y=Math.abs(n.scale_y)}})}getGlobalTransform(t){var p,g;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,rotation:0,scale_x:1,scale_y:1};const o=(p=this.artboard)==null?void 0:p.objects.find(u=>u.id===t),e=(o==null?void 0:o.type)==="Bone"?(g=o.geometry)==null?void 0:g.length:void 0;if(!o||!o.parentId)return{x:s.x,y:s.y,rotation:s.rotation,scale_x:(s.scale_x??1)*(s.flip_x?-1:1),scale_y:(s.scale_y??1)*(s.flip_y?-1:1),length:e};const n=this.getGlobalTransform(o.parentId),i=n.rotation*Math.PI/180,a=Math.cos(i),r=Math.sin(i),l=n.x+(s.x*n.scale_x*a-s.y*n.scale_y*r),d=n.y+(s.x*n.scale_x*r+s.y*n.scale_y*a);return{x:l,y:d,rotation:n.rotation+s.rotation,scale_x:n.scale_x*(s.scale_x??1)*(s.flip_x?-1:1),scale_y:n.scale_y*(s.scale_y??1)*(s.flip_y?-1:1),length:e}}globalToLocal(t,s){if(!t)return s;const o=this.getGlobalTransform(t),e=o.scale_x===0?0:1/o.scale_x,n=o.scale_y===0?0:1/o.scale_y,i=-o.rotation*Math.PI/180,a=Math.cos(i),r=Math.sin(i),l=s.x-o.x,d=s.y-o.y,p=(l*a-d*r)*e,g=(l*r+d*a)*n;return{x:p,y:g,rotation:s.rotation-o.rotation,scale_x:s.scale_x/(o.scale_x||1),scale_y:s.scale_y/(o.scale_y||1)}}solveIK(t,s,o,e){var l;const n=[];let i=t.id;for(let d=0;d<o&&i;d++){const p=(l=this.artboard)==null?void 0:l.objects.find(g=>g.id===i);if(!p)break;n.push({id:i,local:this.objectStates.get(i),global:this.getGlobalTransform(i)}),i=p.parentId}if(n.length<2)return;const a=n.reverse(),r=5;for(let d=0;d<r;d++){const p=this.getGlobalTransform(t.id);for(let g=a.length-2;g>=0;g--){const u=a[g],f=this.getGlobalTransform(u.id),h=p.x-f.x,m=p.y-f.y,b=s.x-f.x,c=s.y-f.y,S=Math.sqrt(h*h+m*m),v=Math.sqrt(b*b+c*c);if(S>.001&&v>.001){const C=Math.atan2(m,h);let I=(Math.atan2(c,b)-C)*180/Math.PI;I*=e;const k=this.objectStates.get(u.id);k&&(k.rotation+=I)}}}}computeSpring(t,s,o,e,n,i,a,r){const l=a.stiffness??100,d=a.damping??10,p=a.mass??1,g=-l*(t-n),u=-l*(s-i),f=-d*o,h=-d*e,m=(g+f)/p,b=(u+h)/p,c=o+m*r,S=e+b*r,v=t+c*r,C=s+S*r;return{x:v,y:C,vx:c,vy:S}}handlePointerInput(t,s,o,e,n){if(!this.artboard)return;const i=this.calculateTransform(e,n,this.artboard.width,this.artboard.height,this.layout.fit,this.layout.alignment),a=(s-i.tx)/i.scaleX,r=(o-i.ty)/i.scaleY;this._prevPointerPos=this._lastPointerPos,this._lastPointerPos={x:a,y:r},this._prevPointerPos&&(this._mouseDelta.dx+=a-this._prevPointerPos.x,this._mouseDelta.dy+=r-this._prevPointerPos.y),this.updateInput("mouseX",a),this.updateInput("mouseY",r),this.handlePointerEvent(t,a,r)}handleScroll(t,s){const o=this.scrollOffset.x,e=this.scrollOffset.y;this.scrollOffset={x:t,y:s},this._totalScroll.x+=t-o,this._totalScroll.y+=s-e,this.updateInput("scrollX",this._totalScroll.x),this.updateInput("scrollY",this._totalScroll.y)}isListViewObject(t){var n;if(!t)return!1;const s=(t.type||"").toLowerCase(),o=(t.variant||"").toLowerCase(),e=(((n=t.geometry)==null?void 0:n.type)||"").toLowerCase();return s==="listview"||o==="listview"||e==="listview"}isLineGraphObject(t){var i;if(!t)return!1;const s=(t.type||"").toLowerCase(),o=(t.variant||"").toLowerCase(),e=(((i=t.geometry)==null?void 0:i.type)||"").toLowerCase(),n=(t.name||"").toLowerCase();return s==="linegraph"||e==="linegraph"||o==="linegraph"||n.includes("linegraph")}isBarChartObject(t){var i;if(!t)return!1;const s=(t.type||"").toLowerCase(),o=(t.variant||"").toLowerCase(),e=(((i=t.geometry)==null?void 0:i.type)||"").toLowerCase(),n=(t.name||"").toLowerCase();return s==="barchart"||e==="barchart"||o==="barchart"||n.includes("barchart")}isPieChartObject(t){var i;if(!t)return!1;const s=(t.type||"").toLowerCase(),o=(t.variant||"").toLowerCase(),e=(((i=t.geometry)==null?void 0:i.type)||"").toLowerCase(),n=(t.name||"").toLowerCase();return s==="piechart"||e==="piechart"||o==="piechart"||n.includes("piechart")}isGraphObject(t){return this.isLineGraphObject(t)||this.isBarChartObject(t)||this.isPieChartObject(t)}isInputBoxObject(t){if(!t)return!1;const s=(t.type||"").toLowerCase(),o=(t.variant||"").toLowerCase(),e=(t.name||"").toLowerCase();return s==="inputbox"||o==="inputbox"||e==="inputbox"}isClickableObject(t){if(!t)return!1;const s=(t.variant||"").toLowerCase(),o=(t.type||"").toLowerCase(),e=["button","toggle","toggle_button","dropdown","slider","checkbox","radiogroup"];return e.includes(s)||e.includes(o)}getLastHoveredObject(){return!this.lastHoveredObjectId||!this.artboard?null:this.artboard.objects.find(t=>t.id===this.lastHoveredObjectId)||null}clearAllGraphHover(){this.graphHoverStates.size>0&&this.graphHoverStates.clear()}getLocalCoords(t,s,o){const e=this.getWorldTransform(t),n=s-e.x,i=o-e.y,a=-(e.rotation||0)*(Math.PI/180),r=Math.cos(a),l=Math.sin(a),d=e.scaleX||1,p=e.scaleY||1;return{x:(n*r-i*l)/(d!==0?d:1),y:(n*l+i*r)/(p!==0?p:1)}}updateGraphHoverFromPointer(t,s,o){var r,l;if(!t||!this.isGraphObject(t)){this.clearAllGraphHover();return}for(const d of Array.from(this.graphHoverStates.keys()))d!==t.id&&this.graphHoverStates.delete(d);const e=this.getLocalCoords(t.id,s,o),n=this.objectStates.get(t.id),i=(n==null?void 0:n.width)??((r=t.geometry)==null?void 0:r.width)??t.width??300,a=(n==null?void 0:n.height)??((l=t.geometry)==null?void 0:l.height)??t.height??180;if(e.x<-i/2||e.x>i/2||e.y<-a/2||e.y>a/2){this.graphHoverStates.delete(t.id);return}if(this.isLineGraphObject(t)){const d=n!=null&&n.geometry?this.deepMerge(t.geometry,n.geometry):t.geometry||{};let p=d.datasets||[];(!p||p.length===0)&&(d.data||d.graphData)&&(p=[{data:d.data||d.graphData}]);let g=0;if(p.forEach(u=>{let f=u.data;if(u.isVarEnabled&&u.inputId){let h=this.inputs.get(u.inputId);if(h===void 0){const m=this.inputNameMap.get(u.inputId);m&&m.length>0&&(h=this.inputs.get(m[0]))}h&&Array.isArray(h)&&(f=h)}f&&f.length>0&&(g=Math.max(g,f.length))}),g>=2){const u=i/(g-1),f=e.x+i/2,h=Math.max(0,Math.min(g-1,Math.round(f/u)));this.graphHoverStates.set(t.id,{hoveredIndex:h,hoverPointer:{x:e.x,y:e.y}})}}else if(this.isBarChartObject(t)){const d=this.barChartRenderedBars.get(t.id)||[];let p=null;for(let g=d.length-1;g>=0;g--){const u=d[g];if(e.x>=u.x&&e.x<=u.x+u.w&&e.y>=u.y&&e.y<=u.y+u.h){p=u;break}}p?this.graphHoverStates.set(t.id,{hoveredCatIdx:p.catIdx,hoveredDsIdx:p.dsIdx,bar:p,hoverPointer:{x:e.x,y:e.y}}):this.graphHoverStates.delete(t.id)}else if(this.isPieChartObject(t)){const d=this.pieChartRenderedSlices.get(t.id)||[];let p=null;for(const g of d){const u=e.x-g.cx,f=e.y-g.cy,h=Math.hypot(u,f);if(h>=g.innerR&&h<=g.outerR){let m=Math.atan2(f,u);const b=w=>(w%(Math.PI*2)+Math.PI*2)%(Math.PI*2),c=b(m),S=b(g.startA),v=b(g.endA);if(S<=v?c>=S&&c<=v:c>=S||c<=v){p=g.index;break}}}p!==null?this.graphHoverStates.set(t.id,{hoveredSliceIndex:p,hoverPointer:{x:e.x,y:e.y}}):this.graphHoverStates.delete(t.id)}}getGraphHoverState(t){return this.graphHoverStates.get(t)}getResolvedListViewItems(t,s){const o=this.objectStates.get(t==null?void 0:t.id),e=s||(o==null?void 0:o.options)||(t==null?void 0:t.options)||{};let n=Array.isArray(e.items)?e.items:typeof e.items=="string"?e.items.split(",").map(i=>i.trim()):[];if(e.isDataVarEnabled&&e.dataInputId){let i=this.inputs.get(e.dataInputId);if(i===void 0){const a=this.inputNameMap.get(e.dataInputId);a&&a.length>0&&(i=this.inputs.get(a[0]))}if(i&&Array.isArray(i))n=i.map(a=>typeof a=="string"?a:String(a));else if(typeof i=="string")try{n=JSON.parse(i).map(a=>String(a))}catch{}}return n}getResolvedDropdownOptions(t,s){const o=this.objectStates.get(t==null?void 0:t.id),e=s||(o==null?void 0:o.options)||(t==null?void 0:t.options)||{};let n=Array.isArray(e.optionsList)?e.optionsList:typeof e.optionsList=="string"?e.optionsList.split(",").map(i=>i.trim()):[];if(e.isDataVarEnabled&&e.dataInputId){let i=this.inputs.get(e.dataInputId);if(i===void 0){const a=this.inputNameMap.get(e.dataInputId);a&&a.length>0&&(i=this.inputs.get(a[0]))}if(i&&Array.isArray(i))n=i.map(a=>typeof a=="string"?a:String(a));else if(typeof i=="string")try{const a=JSON.parse(i);Array.isArray(a)?n=a.map(String):n=i.split(",").map(r=>r.trim())}catch{n=i.split(",").map(a=>a.trim())}}return n}handleWheel(t,s,o,e,n,i){var a,r,l,d;if(o!==void 0&&e!==void 0&&n&&i&&this.artboard){const p=this.calculateTransform(n,i,this.artboard.width,this.artboard.height,this.layout.fit,this.layout.alignment),g=(o-p.tx)/p.scaleX,u=(e-p.ty)/p.scaleY;this._lastPointerPos={x:g,y:u}}if(this._lastPointerPos&&this.artboard){let p=!1;for(let g=this.artboard.objects.length-1;g>=0;g--){const u=this.artboard.objects[g];if(this.isListViewObject(u)){const f=this.objectStates.get(u.id),h=(f==null?void 0:f.options)||u.options||{},m=(f==null?void 0:f.width)??(((a=u.geometry)==null?void 0:a.width)||200),b=(f==null?void 0:f.height)??(((r=u.geometry)==null?void 0:r.height)||300),c=this.getWorldTransform(u.id),S=this._lastPointerPos.x-c.x,v=this._lastPointerPos.y-c.y,C=-c.rotation*(Math.PI/180),w=Math.cos(C),I=Math.sin(C),k=S*w-v*I,O=S*I+v*w,T=c.scaleX||1,A=c.scaleY||1,D=m*Math.abs(T),Y=b*Math.abs(A);if(Math.abs(k)<=D/2&&Math.abs(O)<=Y/2){const B=h.orientation||"vertical";let R=h.scrollOffset||0;if(B==="vertical"?R-=s:R-=Math.abs(t)>Math.abs(s)?t:s,(h.listLayout||"linear")==="circular")h.scrollOffset=R,f&&f.options&&(f.options.scrollOffset=R),u.options&&(u.options.scrollOffset=R);else{const $=this.getResolvedListViewItems(u,h),F=h.itemGap??10,X=h.itemHeight??50,M=h.itemWidth??200,E=typeof h.padding=="number"?h.padding:B==="vertical"?((l=h.padding)==null?void 0:l[0])||0:((d=h.padding)==null?void 0:d[3])||0,_=($.length||0)*(B==="vertical"?X:M)+Math.max(0,($.length||0)-1)*F+E*2,G=Math.max(0,_-(B==="vertical"?b:m));R>0&&(R=0),R<-G&&(R=-G),h.scrollOffset=R,f&&f.options&&(f.options.scrollOffset=R),u.options&&(u.options.scrollOffset=R)}p=!0;break}}}if(p)return}this._totalScroll.x+=t,this._totalScroll.y+=s,this.scrollOffset={x:this._totalScroll.x,y:this._totalScroll.y},this.updateInput("scrollX",this._totalScroll.x),this.updateInput("scrollY",this._totalScroll.y)}handlePointerEvent(t,s,o){var r,l,d,p,g,u,f,h,m,b;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 n=(c,S)=>{var O;let v=S;S==="click"?v="onClick":S==="down"?v="onPointerDown":S==="up"?v="onPointerUp":S==="blur"&&(v="onPointerLeave");const C=new Set([v]);S==="move"&&(C.add("onPointerEnter").add("hover").add("onPointerLeave").add("blur"),C.add("Drag").add("drag").add("ondrag")),v==="onClick"&&C.add("click"),v==="onPointerDown"&&C.add("pointerDown"),v==="onPointerUp"&&C.add("pointerUp");const w=["button","toggle","toggle_button","dropdown","listview","inputbox","slider","checkbox","radiogroup","joystick","barchart","piechart","linegraph"];if(this.isListViewObject(c)||this.isGraphObject(c)||c.type==="Component"&&c.variant&&w.includes(String(c.variant).toLowerCase())||c.type==="Joystick"||w.includes((O=c.type)==null?void 0:O.toLowerCase()))return!0;const I=c.interactions||[];return!!(I.some(T=>C.has(T.event)||C.has(T.trigger))||I.some(T=>Array.isArray(T.triggers)&&T.triggers.some(A=>C.has(String(A))))||(c.triggers||[]).some(T=>C.has(T.eventType)))};let i=null;for(let c=this.artboard.objects.length-1;c>=0;c--){const S=this.artboard.objects[c],v=this.objectStates.get(S.id);if(v&&v.visible!==!1&&v.opacity>0&&this.hitTest(S,s,o)&&(i||(i=S),n(S,t))){e=S;break}}!e&&i&&(e=i),this.pointerHistory.push({x:s,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 c=this.artboard.objects.find(S=>S.id===this.draggingSliderId);c&&this.updateSliderValueFromPointer(c,s,o);return}if(this.draggingJoystickId){const c=this.artboard.objects.find(S=>S.id===this.draggingJoystickId);c&&this.updateJoystickValueFromPointer(c,s,o);return}if(this.draggingListViewId){const c=this.artboard.objects.find(S=>S.id===this.draggingListViewId);c&&this.updateListViewScrollFromPointer(c);return}if(e&&this.isListViewObject(e)&&this.updateListViewHoverFromPointer(e,s,o),this.updateGraphHoverFromPointer(e,s,o),this.isMouseDown&&this.dragStartPointer&&this.draggingBehaviors.size>0){const c=s-this.dragStartPointer.x,S=o-this.dragStartPointer.y;this.draggingBehaviors.forEach(v=>{const C=this.dragStartPositions.get(v);if(!C)return;const w=this.artboard.objects.find(k=>k.id===v);if(!w||w.parentId)return;const I=this.objectStates.get(v);I&&(I.x=C.x+c,I.y=C.y+S)})}if(this.isMouseDown){const c=this.activeObjectId&&this.artboard.objects.some(v=>v.id===this.activeObjectId)?this.activeObjectId:a,S=c?this.artboard.objects.find(v=>v.id===c):null;S&&n(S,"move")&&this.fireEventForObject(S.id,"Drag")}!this.isMouseDown&&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.draggingListViewIsScrollbar=!1,this.draggingBehaviors.clear(),this.dragStartPointer=null,this.dragStartPositions.clear(),this.pointerDownTimes.delete(a),this.activeObjectId=null,t==="blur"&&this.clearAllGraphHover()),t==="down"&&(this.pointerDownTimes.set(a,this.currentTime),this.activeObjectId=a,e&&((r=e.behaviors)!=null&&r.some(c=>c.type===it.Draggable)||this.hasDragInteraction(e)))){this.draggingBehaviors.add(a);const c=this.objectStates.get(a);c&&(this.dragStartPointer={x:s,y:o},this.dragStartPositions.set(a,{x:c.x??0,y:c.y??0}))}if(t==="move"?(a&&!this.activeHoverIds.has(a)&&this.activeHoverIds.add(a),this.activeHoverIds.forEach(c=>{c!==a&&this.activeHoverIds.delete(c)})):t==="blur"&&this.activeHoverIds.clear(),this.activeDropdownId&&t==="down"){const c=this.artboard.objects.find(S=>S.id===this.activeDropdownId);if(c&&(c.type==="Dropdown"||c.variant==="dropdown")){const S=this.objectStates.get(c.id),v=(S==null?void 0:S.options)||c.options||{},C=c.geometry||{},w=C.width??c.width??200,I=C.height??c.height??40,k=this.getResolvedDropdownOptions(c,v),O=v.itemHeight||32,T=v.listPadding??4,A=k.length*O+T*2,D=this.getWorldTransform(c.id),Y=w*Math.abs(D.scaleX),B=I*Math.abs(D.scaleY),R=D.y+B/2+4,L=Math.abs(s-D.x)<=Y/2,$=o>=R&&o<=R+A*Math.abs(D.scaleY);if(L&&$){const F=Math.abs(D.scaleY),X=o-(R+T*F),M=Math.floor(X/(O*F));if(M>=0&&M<k.length){const E=k[M];v.selectedOption=E,v.isOpen=!1,this.activeDropdownId=null,c.inputId&&this.setInternalInput(c.inputId,E),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"dropdown",property:"selectedOption",value:E})}return}else a!==this.activeDropdownId&&(v.isOpen=!1,this.activeDropdownId=null)}}if(e){let c=e,S=e;for(;S&&S.parentId;){const w=this.artboard.objects.find(I=>I.id===S.parentId);if(w&&w.type==="Component"){c=w;break}S=w}let v=t;if(t==="click"?v="onClick":t==="down"?v="onPointerDown":t==="up"?v="onPointerUp":t==="blur"&&(v="onPointerLeave"),this.fireEventForObject(e.id,v),c!==e&&this.fireEventForObject(c.id,v),c.type==="Component"&&c.variant==="toggle_button"&&t==="down"){const w=this.objectStates.get(c.id),I=(w==null?void 0:w.options)||c.options||{};I.checked=!I.checked,c.inputId&&this.setInternalInput(c.inputId,I.checked),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"toggle_button",property:"checked",value:I.checked}),this.fireEventForObject(c.id,"Toggle"),this.fireEventForObject(c.id,I.checked?"Toggle True":"Toggle False")}if(c.type==="Component"&&c.variant==="toggle"&&t==="down"){const w=this.objectStates.get(c.id),I=(w==null?void 0:w.options)||c.options||{};I.checked=!I.checked,c.inputId&&this.setInternalInput(c.inputId,I.checked),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"toggle",property:"checked",value:I.checked}),this.onToggle&&this.onToggle(c.name,I.checked),this.fireEventForObject(c.id,"Toggle"),this.fireEventForObject(c.id,I.checked?"Toggle True":"Toggle False")}if(c.type==="Component"&&c.variant==="dropdown"&&t==="down"){const w=this.objectStates.get(c.id),I=(w==null?void 0:w.options)||c.options||{},k=!I.isOpen;if(k&&this.activeDropdownId&&this.activeDropdownId!==c.id){const O=this.artboard.objects.find(T=>T.id===this.activeDropdownId);O&&O.options&&(O.options.isOpen=!1)}I.isOpen=k,this.activeDropdownId=k?c.id:null}if((c.type==="Button"||c.type==="Component"&&(c.variant==="button"||(c.name||"").toLowerCase().includes("button")||(c.name||"").toLowerCase().includes("cta")))&&t==="down"&&(this.onButtonClick&&this.onButtonClick(c.name,c.id),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"button",property:"click",value:!0})),this.isListViewObject(c)&&t==="down"){this.draggingListViewId=c.id;const w=this.objectStates.get(c.id),I=(w==null?void 0:w.options)||c.options||{},k=(w==null?void 0:w.width)??(((l=c.geometry)==null?void 0:l.width)||200),O=(w==null?void 0:w.height)??(((d=c.geometry)==null?void 0:d.height)||300),T=I.orientation||"vertical",A=I.scrollbarWidth||4,D=I.showScrollbar!==!1;let Y=!1;if(D&&I.listLayout!=="circular"){const R=this.getWorldTransform(c.id),L=-R.rotation*(Math.PI/180),$=Math.cos(L),F=Math.sin(L),X=s-R.x,M=o-R.y,E=X*$-M*F,P=X*F+M*$,_=R.scaleX||1,V=R.scaleY||1,G=E/_,x=P/V,U=12;T==="vertical"?G>=k/2-A-U&&G<=k/2+U&&(Y=!0):x>=O/2-A-U&&x<=O/2+U&&(Y=!0)}this.draggingListViewIsScrollbar=Y;const B=this.getListViewItemIndexAtPointer(c,s,o);if(B!==null){const R=c.options||{};R.activeItemIndex=B;const L=this.objectStates.get(c.id);L&&L.options&&(L.options.activeItemIndex=B);const F=this.getResolvedListViewItems(c,R)[B],X=typeof F=="string"?F:(F==null?void 0:F.label)||(F==null?void 0:F.value)||B;L&&L.options&&(L.options.selectedValue=X),c.inputId&&this.setInternalInput(c.inputId,X),this.onComponentChange&&(this.onComponentChange({objectId:c.id,componentName:c.name,variant:"listview",property:"activeItemIndex",value:B}),this.onComponentChange({objectId:c.id,componentName:c.name,variant:"listview",property:"selected",value:X}))}}if(c.type==="Component"&&c.variant==="slider"&&t==="down"&&(this.draggingSliderId=c.id,this.updateSliderValueFromPointer(c,s,o)),c.type==="Joystick"||c.type==="Component"&&c.variant==="joystick"){if(t==="down")this.draggingJoystickId=c.id,this.updateJoystickValueFromPointer(c,s,o);else if(t==="up"||t==="blur"){const w=this.objectStates.get(c.id);w&&c.isSpringReturn!==!1&&(w.handleX=0,w.handleY=0),c.isSpringReturn!==!1&&(c.handleX=0,c.handleY=0)}}if((c.type==="Checkbox"||c.type==="Component"&&c.variant==="checkbox")&&t==="down"){const w=this.objectStates.get(c.id),I=(w==null?void 0:w.options)||c.options||{};if(I.disabled)return;I.checked=!I.checked,I.indeterminate&&(I.indeterminate=!1),c.inputId&&this.setInternalInput(c.inputId,I.checked),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"checkbox",property:"checked",value:I.checked}),this.fireEventForObject(c.id,"Click"),this.fireEventForObject(c.id,I.checked?"Checked":"Unchecked")}if(c.type==="Component"&&c.variant==="radiogroup"&&t==="down"){const w=this.objectStates.get(c.id),I=(w==null?void 0:w.options)||c.options||{},k=I.optionsList||[],O=this.getRadioGroupItemIndexAtPointer(c,s,o);if(O!==null&&O>=0&&O<k.length){const T=k[O];I.selectedValue=T,c.inputId&&this.setInternalInput(c.inputId,T),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"radiogroup",property:"selectedValue",value:T}),this.fireEventForObject(c.id,"Click"),this.fireEventForObject(c.id,`Selected: ${T}`)}}if(c.type==="LineGraph"&&(t==="down"||t==="click")){const w=c.geometry,I=(w==null?void 0:w.datasets)||[],k=this.objectStates.get(c.id),O=(k==null?void 0:k.width)||(w==null?void 0:w.width)||200,T=(k==null?void 0:k.height)||(w==null?void 0:w.height)||150,A=this.getWorldTransform(c.id),D=30,Y=20,B=O-D,R=T-Y;let L=1;I.forEach(X=>{const M=Math.max(...X.data||[0]);M>L&&(L=M)});let $=1/0,F=null;I.forEach((X,M)=>{const E=X.data||[],P=B/Math.max(E.length-1,1);E.forEach((_,V)=>{const G=A.x-O/2+D+V*P,x=A.y+T/2-Y-_/L*R,U=Math.sqrt((s-G)**2+(o-x)**2);U<$&&($=U,F={dIdx:M,pIdx:V,val:_,label:X.label||`Dataset ${M+1}`})})}),F&&$<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:c.id,componentName:c.name,datasetIndex:F.dIdx,pointIndex:F.pIdx,value:F.val,label:F.label}),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"linegraph",property:"click",value:(F==null?void 0:F.val)??null})}if((c==null?void 0:c.type)==="InputBox"||(c==null?void 0:c.type)==="Component"&&(c.variant==="inputbox"||c.name==="InputBox")){if(t==="down"||t==="click"){const w=this.focusedId;if(this.focusedId=c.id,this.log(`[Engine] Focus set to: ${c.id}`),w!==this.focusedId){if(w){const V=(p=this.artboard)==null?void 0:p.objects.find(G=>G.id===w);V&&this.onInputBlur&&this.onInputBlur(V.name)}this.onInputFocus&&this.onInputFocus(c.name)}const I=this.objectStates.get(c.id),k=(I==null?void 0:I.options)||c.options||{},O=c.geometry||{},T=(I==null?void 0:I.width)||(O==null?void 0:O.width)||250,A=(I==null?void 0:I.height)||(O==null?void 0:O.height)||45,D=this.getWorldTransform(c.id),Y=-D.rotation*(Math.PI/180),B=Math.cos(Y),R=Math.sin(Y),L=s-D.x,$=o-D.y,F=(L*B-$*R)/(D.scaleX||1),X=(L*R+$*B)/(D.scaleY||1);if(k.inputType==="number"&&((g=k.number)==null?void 0:g.showSteppers)!==!1){const G=T/2-4,x=G-24;if(F>=x&&F<=G&&Math.abs(X)<=A/2){const U=Number(((u=k.number)==null?void 0:u.step)??1),q=((f=k.number)==null?void 0:f.min)!==void 0?Number(k.number.min):-1/0,N=((h=k.number)==null?void 0:h.max)!==void 0?Number(k.number.max):1/0;let H=parseFloat(k.text??k.value??"0");isNaN(H)&&(H=0),X<0?H=Math.min(N,H+U):H=Math.max(q,H-U);const z=String(H);k.text=z,k.value=z,c.options&&(c.options.text=z,c.options.value=z),I&&I.options&&(I.options.text=z,I.options.value=z),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"inputbox",property:"value",value:z}),this.onInputChange&&this.onInputChange(c.name,z),this.onInputUpdate&&this.onInputUpdate(c.id,z);return}}const M=k.rightIcon||{},E=k.inputType==="password",P=M.mode==="clear"||k.inputType==="search"&&(k.text||k.value),_=M.mode==="password-toggle"||E&&M.visible!==!1;if(M.visible||_||P){const V=M.offset??16,G=M.size??16,x=T/2-V;if(Math.abs(F-x)<=G&&Math.abs(X)<=A/2){if(_){k.passwordVisible=!k.passwordVisible,I&&I.options&&(I.options.passwordVisible=k.passwordVisible),c.options&&(c.options.passwordVisible=k.passwordVisible);return}else if(P){k.text="",k.value="",I&&I.options&&(I.options.text="",I.options.value=""),c.options&&(c.options.text="",c.options.value=""),this.onInputChange&&this.onInputChange(c.name,""),this.onInputUpdate&&this.onInputUpdate(c.id,"");return}}}}}else if((t==="click"||t==="down")&&this.focusedId){const w=this.focusedId;this.focusedId=null;const I=(m=this.artboard)==null?void 0:m.objects.find(k=>k.id===w);I&&this.onInputBlur&&this.onInputBlur(I.name)}}else if(t==="click"||t==="down"){const c=this.focusedId;if(this.focusedId=null,c){const S=(b=this.artboard)==null?void 0:b.objects.find(v=>v.id===c);S&&this.onInputBlur&&this.onInputBlur(S.name)}}}handleKeyDown(t){var l,d,p,g;if(!this.artboard||(this.activeKeys.add(t.key.toLowerCase()),this.activeKeys.add(t.code),!this.focusedId))return;const s=this.artboard.objects.find(u=>u.id===this.focusedId),o=(s==null?void 0:s.type)==="InputBox"||(s==null?void 0:s.type)==="Component"&&(s.variant==="inputbox"||s.name==="InputBox");if(!s||!o)return;const e=this.objectStates.get(s.id),n=(e==null?void 0:e.options)||s.options||{};let i=String(n.text??n.value??"");const a=n.inputType==="textarea"||n.multiline===!0;if(t.key==="Backspace")i=i.slice(0,-1),t.preventDefault();else if(t.key==="Escape"){this.focusedId=null,this.onInputBlur&&this.onInputBlur(s.name);return}else if(t.key==="Enter")if(a)i+=`
7
+ `,t.preventDefault();else{this.focusedId=null,this.onInputBlur&&this.onInputBlur(s.name);return}else if(t.key==="ArrowUp"&&n.inputType==="number"){const u=Number(((l=n.number)==null?void 0:l.step)??1),f=((d=n.number)==null?void 0:d.max)!==void 0?Number(n.number.max):1/0;let h=parseFloat(i)||0;h=Math.min(f,h+u),i=String(h),t.preventDefault()}else if(t.key==="ArrowDown"&&n.inputType==="number"){const u=Number(((p=n.number)==null?void 0:p.step)??1),f=((g=n.number)==null?void 0:g.min)!==void 0?Number(n.number.min):-1/0;let h=parseFloat(i)||0;h=Math.max(f,h-u),i=String(h),t.preventDefault()}else if(t.key.length===1&&!t.ctrlKey&&!t.metaKey&&!t.altKey){if(n.maxLength>0&&i.length>=n.maxLength||n.inputType==="number"&&(!/[\d.\-]/.test(t.key)||t.key==="-"&&i.includes("-")||t.key==="."&&i.includes(".")))return;i+=t.key,t.preventDefault()}else return;n.text=i,n.value=i,s.options&&(s.options.text=i,s.options.value=i),e&&e.options&&(e.options.text=i,e.options.value=i);const r=s.geometry;r!=null&&r.textInputId&&this.updateInput(r.textInputId,i),this.onComponentChange&&(this.onComponentChange({objectId:s.id,componentName:s.name,variant:"inputbox",property:"text",value:i}),this.onComponentChange({objectId:s.id,componentName:s.name,variant:"inputbox",property:"value",value:i})),this.onInputChange&&this.onInputChange(s.name,i),this.onInputUpdate&&this.onInputUpdate(this.focusedId,i)}handleKeyUp(t){this.artboard&&(this.activeKeys.delete(t.key.toLowerCase()),this.activeKeys.delete(t.code))}hasDragInteraction(t){return t?(t.interactions||[]).some(o=>{const e=o.triggers||[o.event||o.trigger];return Array.isArray(e)&&e.some(n=>String(n).toLowerCase()==="drag")}):!1}fireEventForObject(t,s){var d,p,g,u,f;const o=(d=this.artboard)==null?void 0:d.objects.find(h=>h.id===t);if(!o)return;const e=new Set([s,s.toLowerCase()]),n=s.toLowerCase();n==="onclick"||n==="click"||n==="onpointerdown"||n==="pointerdown"?this.fireAnalyticsEvent(t,"click"):(n==="onpointerenter"||n==="hover"||n==="move")&&this.fireAnalyticsEvent(t,"hover"),n==="onclick"||n==="click"?(e.add("click"),e.add("onclick")):n==="onpointerdown"||n==="pointerdown"?(e.add("pointerdown"),e.add("onpointerdown")):n==="onpointerup"||n==="pointerup"?(e.add("pointerup"),e.add("onpointerup")):n==="onpointerenter"||n==="hover"||n==="move"?(e.add("hover"),e.add("onpointerenter")):n==="onpointerleave"||n==="blur"?(e.add("onpointerleave"),e.add("blur")):n==="drag"||n==="ondrag"?(e.add("drag"),e.add("ondrag")):n==="toggle"||n==="ontoggle"?(e.add("toggle"),e.add("ontoggle")):n==="toggle true"||n==="toggle_true"||n==="toggletrue"?(e.add("toggle true"),e.add("toggle_true"),e.add("toggletrue")):(n==="toggle false"||n==="toggle_false"||n==="togglefalse")&&(e.add("toggle false"),e.add("toggle_false"),e.add("togglefalse"));const a=(o.interactions||[]).find(h=>{const m=h.triggers||[h.event||h.trigger||"click"];return((h.triggerLogic||"OR")==="AND"?m.every(S=>e.has(S.toLowerCase())):m.some(S=>e.has(S.toLowerCase())))?h.conditions&&h.conditions.length>0?this.checkConditions(h.conditions):!0:!1});if(a){if(this.log(`[Engine] Interaction matched: ${s} -> Action: ${a.action}`),a.action==="setInput"||a.action==="Set Input"){let h=a.value||a.inputValue;h==="toggle"&&(h=!this.inputs.get(a.targetInputId)),this.updateInput(a.targetInputId,h)}else if(a.action==="Toggle Boolean"){const h=a.targetInputId;if(h&&this.inputs.has(h)){const c=this.inputs.get(h);this.updateInput(h,!c)}const m=this.objectStates.get(o.id),b=(m==null?void 0:m.options)||o.options;b&&typeof b.checked=="boolean"&&(b.checked=!b.checked,b.indeterminate&&(b.indeterminate=!1),this.onComponentChange&&this.onComponentChange({objectId:o.id,componentName:o.name,variant:"checkbox",property:"checked",value:b.checked}))}else if(a.action==="fireTrigger")this.updateInput(a.targetInputId,!0);else if(a.action==="setProperty"){const h=a.targetObjectId||o.id,m=a.targetProperty;m&&this.updateObjectProperty(h,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 h=a.targetAnimationId,m=!a.playMode||a.playMode==="all"?void 0:a.subAnimationIds;h==="__all__"?(g=(p=this.artboard)==null?void 0:p.animations)==null||g.forEach(b=>{this.triggerGlobalAnimation(b.id,m)}):h&&this.triggerGlobalAnimation(h,m)}else if(a.action==="setState"||a.action==="Set State"){const h=a.targetObjectId||o.id,b={...this.objectStates.get(h)||{},...a.value||{}};this.objectStates.set(h,b),this.log(`[Engine] State updated for ${h}:`,b)}else if(a.action==="Stop Animation"||a.action==="Pause Animation"){const h=a.targetAnimationId;h==="__all__"?this.layerStates.forEach((m,b)=>{b.startsWith("global_")&&this.layerStates.delete(b)}):h&&this.layerStates.forEach((m,b)=>{b.startsWith(`global_${h}_`)&&this.layerStates.delete(b)})}else if(a.action==="Switch to State"&&this.activeStateMachine){const h=a.targetState,m=this.activeStateMachine.layers.find(b=>b.states.some(c=>c.id===h||c.name===h));m&&(this.log(`[Engine] Switching Layer ${m.name} to State ${h}`),this.enterStates(m.name,[h]))}this.onTrigger&&this.onTrigger(s,a.action)}const l=(o.triggers||[]).find(h=>{const m=h.eventType.toLowerCase();let b=!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"))&&(b=!0),b&&h.conditions&&h.conditions.length>0?this.checkConditions(h.conditions):b});if(l&&l.entryAnimationId){this.log(`[Engine] Trigger matched: ${s} (as ${l.eventType}) -> Animation ${l.entryAnimationId}`);const h=(f=(u=this.artboard)==null?void 0:u.animations)==null?void 0:f.find(m=>m.id===l.entryAnimationId);h&&(this.activeTriggers.set(o.id,{triggerId:l.id,animation:h,time:0,phase:"entry",elapsedHold:0,filterObjectId:l.targetObjectId}),this.onTrigger&&this.onTrigger(l.name,h.name))}}fireAnalyticsEvent(t,s){var r,l;const o=(r=this.artboard)==null?void 0:r.objects.find(d=>d.id===t);if(!o)return;const e=(l=o.style)==null?void 0:l.analytics;if(!e||!e.isEnabled||e.triggerType!==s)return;const n=e.eventName||`${o.name.toLowerCase().replace(/\s+/g,"_")}_interacted`,i={};e.parameters&&Array.isArray(e.parameters)&&e.parameters.forEach(d=>{if(d.type==="literal")i[d.key]=d.value;else if(d.type==="variable"){const p=this.inputs.get(d.value);i[d.key]=p!==void 0?p:""}}),this.log(`[ExodeUI Analytics] Dispatching event "${n}" via ${s} trigger:`,i);const a=e.platforms||{ga4:!0,meta:!0,mixpanel:!1};if(a.ga4){const d=window;typeof d.gtag=="function"?(d.gtag("event",n,i),this.log(`[ExodeUI Analytics] GA4: Event "${n}" sent successfully.`)):this.warn(`[ExodeUI Analytics] GA4: window.gtag is not a function. Event "${n}" skipped.`)}if(a.meta){const d=window;typeof d.fbq=="function"?(d.fbq("track",n,i),this.log(`[ExodeUI Analytics] Meta Pixel: Event "${n}" sent successfully.`)):this.warn(`[ExodeUI Analytics] Meta Pixel: window.fbq is not a function. Event "${n}" skipped.`)}if(a.mixpanel){const d=window;d.mixpanel&&typeof d.mixpanel.track=="function"?(d.mixpanel.track(n,i),this.log(`[ExodeUI Analytics] Mixpanel: Event "${n}" sent successfully.`)):this.warn(`[ExodeUI Analytics] Mixpanel: window.mixpanel.track is not a function. Event "${n}" skipped.`)}}getAnimationDuration(t){var o;if(!t)return 0;let s=t.duration||0;return s<=0&&((o=t.tracks)==null||o.forEach(e=>{var n;(n=e.keyframes)==null||n.forEach(i=>{i.time>s&&(s=i.time)})})),s>0?s:1}initGlobalAnimationTriggers(){if(!this.artboard)return;const t=this.artboard.animationFlow||[];let s=!1;t.forEach(o=>{if((o.trigger==="on_load"||o.trigger==="after_delay")&&o.targetAnimationId){s=!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)}}),!s&&this.artboard.startupAnimationId&&this.triggerGlobalAnimation(this.artboard.startupAnimationId,this.artboard.startupSubAnimationIds)}triggerGlobalAnimation(t,s,o=!1,e){var r;if(!this.artboard)return;const n=this.artboard.animations.find(l=>l.id===t);if(!n)return;let i=this.getAnimationDuration(n);const a=`global_${t}_${Math.random().toString(36).substr(2,5)}`;this.layerStates.set(a,{currentStateIds:[t],animations:[{animation:n,state:{loop:o},filterObjectIds:s}],time:0,duration:i,ruleId:e}),console.log(`[Engine] Triggered global animation: ${n.name} (AnimID: ${t}, RuleID: ${e}, Loop: ${o}, StoredDuration: ${i}, anim.duration: ${n.duration}, Tracks: ${((r=n.tracks)==null?void 0:r.length)||0})`),this.debugLog(`[Engine] Triggered global animation: ${n.name} (Loop: ${o}, Sub-Anims: ${(s==null?void 0:s.length)||"All"})`)}handleAnimationFinished(t,s){if(!this.artboard)return;console.log(`[Engine] Animation finished! AnimID: ${t}, RuleID: ${s}`);const o=this.artboard.animationFlow||[];o.forEach((e,n)=>{if(e.trigger==="after_anim"&&e.targetAnimationId){let i=e.afterAnim;!i&&n>0&&(i=o[n-1].id);const a=i===t||s&&i===s;if(console.log(`[Engine] Checking rule ${e.id} (Trigger: ${e.trigger}). ExpectedParent: ${i}. isMatch? ${a}`),a){const r=e.delay||0;console.log(`[Engine] Match found! Triggering target animation: ${e.targetAnimationId} after delay: ${r}`),r<=0?this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id):setTimeout(()=>this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id),r)}}})}getEntranceProgress(t,s,o){if((s.type||"none")==="none")return 1;const n=s.duration||1.2,i=s.delay||0,a=s.easing||"EaseOutCubic",r=gs(a);let l=0;if(o==="entrance"){const d=n+i+2,p=this.currentTime%d;p<i?l=0:p<i+n?l=(p-i)/n:l=1}else{this.entranceStartTimes.has(t)||this.entranceStartTimes.set(t,this.currentTime);const d=this.entranceStartTimes.get(t),p=this.currentTime-d;p<i?l=0:p<i+n?l=(p-i)/n:l=1}return r(l)}getWorldTransform(t){var g;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,scaleX:1,scaleY:1,rotation:0};const o=(g=this.artboard)==null?void 0:g.objects.find(u=>u.id===t);if(!o||!o.parentId)return{x:s.x,y:s.y,scaleX:s.scale_x??1,scaleY:s.scale_y??1,rotation:s.rotation??0};const e=this.getWorldTransform(o.parentId),n=e.rotation*(Math.PI/180),i=Math.cos(n),a=Math.sin(n),r=s.x*e.scaleX,l=s.y*e.scaleY,d=e.x+(r*i-l*a),p=e.y+(r*a+l*i);return{x:d,y:p,scaleX:(s.scale_x??1)*e.scaleX,scaleY:(s.scale_y??1)*e.scaleY,rotation:e.rotation+(s.rotation??0)}}hitTest(t,s,o){var S,v;if(!this.objectStates.get(t.id))return!1;const n=((S=t.geometry)==null?void 0:S.width)??t.width??100,i=((v=t.geometry)==null?void 0:v.height)??t.height??100,a=this.getWorldTransform(t.id),r=s-a.x,l=o-a.y,d=-a.rotation*(Math.PI/180),p=Math.cos(d),g=Math.sin(d),u=r*p-l*g,f=r*g+l*p,h=a.scaleX,m=a.scaleY,b=n*Math.abs(h),c=i*Math.abs(m);return Math.abs(u)<=b/2&&Math.abs(f)<=c/2}updateSliderValueFromPointer(t,s,o){var I;const e=this.objectStates.get(t.id);if(!e)return;const n=t.options||{},i=((I=t.geometry)==null?void 0:I.width)??t.width??200,a=this.getWorldTransform(t.id),r=s-a.x,l=o-a.y,d=-a.rotation*(Math.PI/180),p=Math.cos(d),g=Math.sin(d),u=r*p-l*g,f=n.thumbWidth??16,h=i-f;let b=(u+h/2)/h;b=Math.max(0,Math.min(1,b));const c=n.min??0,S=n.max??100,v=n.step||1;let C=c+b*(S-c);v>0&&(C=Math.round(C/v)*v),C=Math.max(c,Math.min(S,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,s,o){var I,k;const e=this.objectStates.get(t.id);if(!e)return;const n=(e==null?void 0:e.width)!==void 0?e.width:((I=t.geometry)==null?void 0:I.width)??t.width??100,i=(e==null?void 0:e.height)!==void 0?e.height:((k=t.geometry)==null?void 0:k.height)??t.height??100,a=this.getWorldTransform(t.id),r=s-a.x,l=o-a.y,d=-a.rotation*(Math.PI/180),p=Math.cos(d),g=Math.sin(d);let u=(r*p-l*g)/Math.max(.001,Math.abs(a.scaleX||1)),f=(r*g+l*p)/Math.max(.001,Math.abs(a.scaleY||1));t.handleOrigin==="top-left"?(u-=n/2,f-=i/2):t.handleOrigin==="bottom-right"&&(u+=n/2,f+=i/2);const h=Math.min(n,i)*.45,m=Math.min(n,i)*.15,b=h-m;let c=u/b,S=f/b;const v=Math.sqrt(c*c+S*S);t.boundsShape==="square"?(c=Math.max(-1,Math.min(1,c)),S=Math.max(-1,Math.min(1,S))):v>1&&(c/=v,S/=v),t.deadzone!==void 0&&v<t.deadzone?(c=0,S=0):(t.stepX!==void 0&&t.stepX>0&&(c=Math.round(c/t.stepX)*t.stepX),t.stepY!==void 0&&t.stepY>0&&(S=Math.round(S/t.stepY)*t.stepY)),t.joystickType==="1D_X"?S=0:t.joystickType==="1D_Y"&&(c=0);const C=e.handleX,w=e.handleY;(C!==c||w!==S)&&(e.handleX=c,e.handleY=S,t.handleX=c,t.handleY=S)}processJoysticks(t){this.artboard&&(this.artboard.objects.forEach(s=>{var l,d,p,g;if(s.type!=="Joystick"&&!(s.type==="Component"&&s.variant==="joystick"))return;const o=s,e=this.objectStates.get(o.id);if(!e)return;let n=e.handleX??o.handleX??0,i=e.handleY??o.handleY??0;const r=(o.globalInput??!1)||this.lastHoveredObjectId===o.id;if(r&&((l=o.inputBinding)==null?void 0:l.type)==="keyboard"&&o.inputBinding.keyboardConfig){const u=o.inputBinding.keyboardConfig;let f=n,h=i;const b=(u.speed||5)*t;let c=!1;this.activeKeys.has(u.upKey.toLowerCase())&&(h-=b,c=!0),this.activeKeys.has(u.downKey.toLowerCase())&&(h+=b,c=!0),this.activeKeys.has(u.leftKey.toLowerCase())&&(f-=b,c=!0),this.activeKeys.has(u.rightKey.toLowerCase())&&(f+=b,c=!0),o.joystickType==="1D_X"&&(h=0),o.joystickType==="1D_Y"&&(f=0);const S=Math.sqrt(f*f+h*h);S>1&&(f/=S,h/=S),!c&&o.isSpringReturn!==!1&&(f+=(0-f)*(10*t),h+=(0-h)*(10*t),Math.abs(f)<.01&&(f=0),Math.abs(h)<.01&&(h=0)),n=f,i=h}else if(r&&((d=o.inputBinding)==null?void 0:d.type)==="mouse"&&o.inputBinding.mouseConfig){const u=o.inputBinding.mouseConfig;let f=e._mouseTargetX??n,h=e._mouseTargetY??i;const m=u.sensitivity||.01;if(u.mode==="absolute"){const S=((p=this.artboard)==null?void 0:p.width)||window.innerWidth,v=((g=this.artboard)==null?void 0:g.height)||window.innerHeight,C=this.inputs.get("mouseX")||0,w=this.inputs.get("mouseY")||0;u.axisX&&(f=C/S*2-1),u.axisY&&(h=w/v*2-1)}else u.axisX&&(f+=this._mouseDelta.dx*m),u.axisY&&(h+=this._mouseDelta.dy*m);o.joystickType==="1D_X"&&(h=0),o.joystickType==="1D_Y"&&(f=0);const b=Math.sqrt(f*f+h*h);b>1&&(f/=b,h/=b),o.isSpringReturn!==!1&&(f+=(0-f)*(5*t),h+=(0-h)*(5*t),Math.abs(f)<.01&&(f=0),Math.abs(h)<.01&&(h=0)),e._mouseTargetX=f,e._mouseTargetY=h;const c=15*t;n+=(f-n)*Math.min(c,1),i+=(h-i)*Math.min(c,1)}if(e.handleX=n,e.handleY=i,o.handleX=n,o.handleY=i,o.bindings&&o.bindings.length>0){const u=Math.sqrt(n*n+i*i);let f=Math.atan2(i,n)*(180/Math.PI);f<0&&(f+=360),o.bindings.forEach(h=>{var c,S,v,C,w,I,k,O;let m=0;h.sourceAxis==="x"?m=o.invertX?-n:n:h.sourceAxis==="y"?m=o.invertY?-i:i:h.sourceAxis==="distance"?m=u:h.sourceAxis==="angle"&&(m=f);const b=(c=this.artboard)==null?void 0:c.objects.find(T=>T.id===h.targetObjectId);if(b){if(h.actionType==="bind"&&h.targetProperty&&h.isContinuous!==!1){const T=h.sourceMin??-1,A=h.sourceMax??1,D=h.targetMin??0,Y=h.targetMax??100;let B=!!h.isContinuous,R=0,L=0;if(B){if((h.sourceAxis==="x"||h.sourceAxis==="y")&&D>=0){const F=Math.max(Math.abs(T),Math.abs(A))||1;L=m/F*Y}else{let F=(m-T)/(A-T);F=Math.max(0,Math.min(1,F)),L=D+F*(Y-D)}Math.abs(m)<.05&&(L=0)}else{const F=(m-T)/(A-T),X=Math.max(0,Math.min(1,F));R=D+X*(Y-D),h.step&&h.step>0&&(R=Math.round(R/h.step)*h.step)}const $=this.objectStates.get(b.id);if($){const F=h.isRelative!==!1,X=F?((S=b.transform)==null?void 0:S.x)??0:0,M=F?((v=b.transform)==null?void 0:v.y)??0:0,E=F?((C=b.transform)==null?void 0:C.rotation)??0:0,P=F?((w=b.transform)==null?void 0:w.scale_x)??1:0,_=F?((I=b.transform)==null?void 0:I.scale_y)??1:0,V=F?((k=b.style)==null?void 0:k.opacity)??100:0,G=Math.min(t*60,3),x=(U,q)=>{let N=R;if(B){const H=`_internal_${U}_${h.id}`;let z=$[H];z===void 0&&(z=$[U]??q),N=z+L*G,$[H]=N,h.step&&h.step>0&&(N=Math.round(N/h.step)*h.step)}else{N=q+R;const H=`_internal_smooth_${U}_${h.id}`;let z=$[H];if(z===void 0)z=N;else{const et=Math.min(15*t,1);z+=(N-z)*et}$[H]=z,N=z}$[U]=N};h.targetProperty==="x"||h.targetProperty==="transform.x"?x("x",X):h.targetProperty==="y"||h.targetProperty==="transform.y"?x("y",M):h.targetProperty==="rotation"||h.targetProperty==="r"||h.targetProperty==="transform.rotation"?x("rotation",E):h.targetProperty==="scaleX"||h.targetProperty==="transform.scale_x"?x("scale_x",P):h.targetProperty==="scaleY"||h.targetProperty==="transform.scale_y"?x("scale_y",_):(h.targetProperty==="opacity"||h.targetProperty==="transform.opacity")&&x("opacity",V)}(O=b.physics)!=null&&O.enabled&&this.physicsEngine&&(h.targetProperty==="x"||h.targetProperty==="transform.x"||h.targetProperty==="y"||h.targetProperty==="transform.y")&&(h.targetProperty==="x"||h.targetProperty==="transform.x"?this.physicsEngine.applyForce(b.id,(R-(($==null?void 0:$.x)||0))*10,0):(h.targetProperty==="y"||h.targetProperty==="transform.y")&&this.physicsEngine.applyForce(b.id,0,(R-(($==null?void 0:$.y)||0))*10))}else if(h.actionType==="playAnimation"||h.actionType==="stopAnimation"||h.actionType==="pauseAnimation"){let T=!1;const A=h.threshold??0;h.condition==="always"?T=!0:h.condition===">"?T=m>A:h.condition==="<"?T=m<A:h.condition==="=="&&(T=Math.abs(m-A)<.01);const D=e[`_prev_src_${h.id}`]??m;let Y=!1;h.condition==="always"?Y=!0:h.condition===">"?Y=D>A:h.condition==="<"?Y=D<A:h.condition==="=="&&(Y=Math.abs(D-A)<.01),e[`_prev_src_${h.id}`]=m,T&&!Y&&h.targetAnimationId&&(h.actionType==="playAnimation"||h.actionType)}}})}}),this._mouseDelta.dx=0,this._mouseDelta.dy=0)}applyBlendState(t,s){var l,d,p,g,u,f,h,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 n=[];let i=0;if(t.blendType==="1D"){const b=[...t.blendAnimations].sort((c,S)=>c.position[0]-S.position[0]);if(b.length===1){const c=(d=(l=this.artboard)==null?void 0:l.animations)==null?void 0:d.find(S=>S.id===b[0].animationId);c&&(n.push({anim:c,weight:1}),i=1)}else{let c=0;for(;c<b.length-1&&b[c+1].position[0]<o;)c++;if(c===b.length-1&&o>b[c].position[0]){const S=(g=(p=this.artboard)==null?void 0:p.animations)==null?void 0:g.find(v=>v.id===b[c].animationId);S&&(n.push({anim:S,weight:1}),i=1)}else{const S=b[c].position[0],v=b[c+1].position[0],C=(f=(u=this.artboard)==null?void 0:u.animations)==null?void 0:f.find(T=>T.id===b[c].animationId),w=(m=(h=this.artboard)==null?void 0:h.animations)==null?void 0:m.find(T=>T.id===b[c+1].animationId),I=Math.max(.001,v-S);let k=(o-S)/I;k=Math.max(0,Math.min(1,k));const O=1-k;C&&(n.push({anim:C,weight:O}),i+=O),w&&(n.push({anim:w,weight:k}),i+=k)}}}else t.blendAnimations.forEach(b=>{var w,I;const c=(I=(w=this.artboard)==null?void 0:w.animations)==null?void 0:I.find(k=>k.id===b.animationId);if(!c)return;const S=b.position[0]-o,v=b.position[1]-e,C=S*S+v*v;if(C<1e-4)n.push({anim:c,weight:1e4}),i+=1e4;else{const k=1/C;n.push({anim:c,weight:k}),i+=k}});if(i===0)return;n.forEach(b=>b.weight/=i);const a=new Map,r=b=>{let c=b.startsWith("#")?b.substring(1):b;return c.length===3&&(c=[c[0],c[0],c[1],c[1],c[2],c[2]].join("")),c="0x"+c,{r:c>>16&255,g:c>>8&255,b:c&255,a:1}};n.forEach(({anim:b,weight:c})=>{b.tracks&&b.tracks.forEach(S=>{var A,D;const v=S.object_id||S.objectId,C=S.property,w=(A=this.artboard)==null?void 0:A.objects.find(Y=>Y.id===v);if(((D=w==null?void 0:w.physics)==null?void 0:D.enabled)&&w.physics.bodyType!=="Static"&&(C==="x"||C==="y"||C==="rotation"))return;const k=this.interpolate(S.keyframes,s);if(k===void 0)return;let O=a.get(v);O||(O=new Map,a.set(v,O));let T=O.get(C);if(!T){if(typeof k=="number")T={type:"number",value:0};else if(typeof k=="string"&&k.startsWith("#"))T={type:"color",value:k,colorAcc:{r:0,g:0,b:0,a:0}};else if(T={type:"number",value:k},c<.5)return;O.set(C,T)}if(T.type==="number"&&typeof k=="number")T.value+=k*c;else if(T.type==="color"&&typeof k=="string"&&T.colorAcc){const Y=r(k);Y&&(T.colorAcc.r+=Y.r*c,T.colorAcc.g+=Y.g*c,T.colorAcc.b+=Y.b*c,T.colorAcc.a+=Y.a*c)}else c>.5&&(T.value=k)})}),a.forEach((b,c)=>{var C;const S=this.objectStates.get(c),v=(C=this.artboard)==null?void 0:C.objects.find(w=>w.id===c);!S||!v||b.forEach((w,I)=>{let k=w.value;if(w.type==="color"&&w.colorAcc){const O=Math.round(w.colorAcc.r).toString(16).padStart(2,"0"),T=Math.round(w.colorAcc.g).toString(16).padStart(2,"0"),A=Math.round(w.colorAcc.b).toString(16).padStart(2,"0");k=`#${O}${T}${A}`}if(I.includes(".")||I.includes("[")){const O=(I||"").replace(/\[(\d+)\]/g,".$1").split(".");let T=S;for(let A=0;A<O.length-1;A++){if(typeof T[O[A]]!="object"||T[O[A]]===null){let D=v;for(let Y=0;Y<=A;Y++)D=D?D[O[Y]]:null;if(O[A]==="corner_radius"||O[A]==="cornerRadius"){const Y=typeof T[O[A]]=="number"?T[O[A]]:typeof D=="number"?D:0;T[O[A]]={tl:Y,tr:Y,bl:Y,br:Y}}else{const Y=O[A+1],B=!isNaN(Number(Y));T[O[A]]=D?JSON.parse(JSON.stringify(D)):B?[]:{}}}T=T[O[A]]}T[O[O.length-1]]=k,O[O.length-1]==="color"&&(O[O.length-2]==="fill"||O[O.length-2]==="stroke")&&(T.type="Solid")}else I==="fill"?(S.style||(S.style={}),S.style.fill=k):I==="stroke"?(S.style||(S.style={}),S.style.stroke=k):S[I]=k})})}applyAnimation(t,s,o){!t||!t.tracks||t.tracks.forEach(e=>{var p,g,u;const n=e.object_id||e.objectId;if(o){if(Array.isArray(o)){if(!o.includes(n))return}else if(n!==o)return}const i=(p=this.artboard)==null?void 0:p.objects.find(f=>f.id===n),a=((g=i==null?void 0:i.physics)==null?void 0:g.enabled)&&i.physics.bodyType!=="Static";let r=e.property;if(a&&(r==="x"||r==="y"||r==="rotation"))return;const l=this.objectStates.get(n);if(!l){this.frameCount%600===0&&this.debugLog(`Skipping track: Object ${n} not found in state`);return}const d=this.interpolate(e.keyframes,s);if(d!==void 0){if(this.frameCount%240===0){const f=(i==null?void 0:i.name)||n,h=typeof d=="object"?JSON.stringify(d).slice(0,50):d;this.debugLog(`[Anim] Applying ${r} = ${h} to ${f}`)}if(r.includes(".")||r.includes("[")){const f=(r||"").replace(/\[(\d+)\]/g,".$1").split(".");let h=l;for(let m=0;m<f.length-1;m++){if(typeof h[f[m]]!="object"||h[f[m]]===null){let b=i;for(let c=0;c<=m;c++)b=b?b[f[c]]:null;if(f[m]==="corner_radius"||f[m]==="cornerRadius"){let c=0,S=0,v=0,C=0;const w=h[f[m]]??b;typeof w=="number"?c=S=v=C=w:Array.isArray(w)?w.length===1?c=S=v=C=w[0]:w.length===2?(c=v=w[0],S=C=w[1]):w.length===3?(c=w[0],S=C=w[1],v=w[2]):w.length>=4&&(c=w[0],S=w[1],v=w[2],C=w[3]):w&&typeof w=="object"&&(c=w[0]??w.tl??w.corner_radius??w.cornerRadius??0,S=w[1]??w.tr??w.corner_radius??w.cornerRadius??0,v=w[2]??w.br??w.corner_radius??w.cornerRadius??0,C=w[3]??w.bl??w.corner_radius??w.cornerRadius??0),h[f[m]]={tl:c,tr:S,bl:C,br:v,0:c,1:S,2:v,3:C}}else{const c=f[m+1],S=!isNaN(Number(c));h[f[m]]=b?JSON.parse(JSON.stringify(b)):S?[]:{}}}h=h[f[m]]}h[f[f.length-1]]=d,f[f.length-1]==="color"&&(f[f.length-2]==="fill"||f[f.length-2]==="stroke")&&(h.type="Solid")}else r==="fill"?(l.style||(l.style={}),l.style.fill=d):r==="stroke"?(l.style||(l.style={}),l.style.stroke=d):l[r]=d;if(this.physicsEngine&&((u=i==null?void 0:i.physics)!=null&&u.enabled)&&i.physics.bodyType==="Static")if(r==="x"){const f=this.physicsEngine.getPosition(n);f&&this.physicsEngine.setPosition(n,d,f.y)}else if(r==="y"){const f=this.physicsEngine.getPosition(n);f&&this.physicsEngine.setPosition(n,f.x,d)}else r==="rotation"&&this.physicsEngine.setRotation(n,d*(Math.PI/180))}})}interpolate(t,s){if(t.length===0)return;let o=t[0],e=t[t.length-1];if(s<=o.time)return o.value;if(s>=e.time)return e.value;for(let a=0;a<t.length-1;a++)if(s>=t[a].time&&s<t[a+1].time){o=t[a],e=t[a+1];break}const n=e.time-o.time;let i=(s-o.time)/n;return o.easing&&(i=gs(o.easing)(i)),this.interpolateValue(o.value,e.value,i)}interpolateValue(t,s,o){if(t===void 0)return s;if(s===void 0)return t;if(typeof t=="string"&&typeof s=="string"){if(t.startsWith("#"))return this.interpolateColor(t,s,o);const e=parseFloat(t),n=parseFloat(s);return!isNaN(e)&&!isNaN(n)?Math.round(e+(n-e)*o).toString():o<.5?t:s}if(Array.isArray(t)&&Array.isArray(s))return t.length===s.length?t.map((e,n)=>this.interpolateValue(e,s[n],o)):o<.5?t:s;if(typeof t=="object"&&typeof s=="object"&&t!==null&&s!==null){if(t.width!==void 0&&t.color!==void 0&&typeof t.width=="number")return this.interpolateStroke(t,s,o);if(t.type&&s.type&&(t.type==="Solid"||t.type==="LinearGradient"||t.type==="RadialGradient"||t.type==="Image"))return this.interpolateFill(t,s,o);const e={};return new Set([...Object.keys(t),...Object.keys(s)]).forEach(i=>{e[i]=this.interpolateValue(t[i],s[i],o)}),e}return typeof t=="number"&&typeof s=="number"?t+(s-t)*o:o<.5?t:s}interpolateColor(t,s,o){var f,h;const e=((h=(f=this.artboard)==null?void 0:f.tokens)==null?void 0:h.colors)||{},n=e[t]||t,i=e[s]||s,a=m=>{if(!m)return{r:0,g:0,b:0};const b=m.startsWith("#")?m.replace("#",""):"000000";return b.length===3?{r:parseInt(b[0]+b[0],16),g:parseInt(b[1]+b[1],16),b:parseInt(b[2]+b[2],16)}:{r:parseInt(b.substring(0,2),16),g:parseInt(b.substring(2,4),16),b:parseInt(b.substring(4,6),16)}},r=a(n),l=a(i),d=Math.round(r.r+(l.r-r.r)*o),p=Math.round(r.g+(l.g-r.g)*o),g=Math.round(r.b+(l.b-r.b)*o),u=m=>{const b=Math.max(0,Math.min(255,m)).toString(16);return b.length===1?"0"+b:b};return`#${u(d)}${u(p)}${u(g)}`}interpolateStops(t,s,o){return!t||!s||t.length!==s.length?o<.5?t:s:t.map((e,n)=>{const i=s[n];return{offset:e.offset+(i.offset-e.offset)*o,color:this.interpolateColor(e.color,i.color,o),opacity:(e.opacity??1)+((i.opacity??1)-(e.opacity??1))*o}})}interpolateFill(t,s,o){if(!t||!s||t.type!==s.type)return o<.5?t:s;const e={...t,opacity:(t.opacity??1)+((s.opacity??1)-(t.opacity??1))*o};return t.type==="Solid"?e.color=this.interpolateColor(t.color,s.color,o):(t.type==="LinearGradient"||t.type==="RadialGradient")&&(t.start&&s.start&&(e.start=[t.start[0]+(s.start[0]-t.start[0])*o,t.start[1]+(s.start[1]-t.start[1])*o]),t.end&&s.end&&(e.end=[t.end[0]+(s.end[0]-t.end[0])*o,t.end[1]+(s.end[1]-t.end[1])*o]),t.center&&s.center&&(e.center=[t.center[0]+(s.center[0]-t.center[0])*o,t.center[1]+(s.center[1]-t.center[1])*o]),t.radius!==void 0&&s.radius!==void 0&&(e.radius=t.radius+(s.radius-t.radius)*o),e.stops=this.interpolateStops(t.stops,s.stops,o)),e}interpolateStroke(t,s,o){if(!t||!s)return o<.5?t:s;const e={...t};return e.width=(t.width??0)+((s.width??0)-(t.width??0))*o,e.opacity=(t.opacity??1)+((s.opacity??1)-(t.opacity??1))*o,t.fill&&s.fill?e.fill=this.interpolateFill(t.fill,s.fill,o):t.color&&s.color&&t.color.startsWith("#")&&s.color.startsWith("#")&&(e.color=this.interpolateColor(t.color,s.color,o)),e.trimStart=(t.trimStart??0)+((s.trimStart??0)-(t.trimStart??0))*o,e.trimEnd=(t.trimEnd??1)+((s.trimEnd??1)-(t.trimEnd??1))*o,e.trimOffset=(t.trimOffset??0)+((s.trimOffset??0)-(t.trimOffset??0))*o,e.dashOffset=(t.dashOffset??0)+((s.dashOffset??0)-(t.dashOffset??0))*o,e}render(t,s,o){var p;this.debug_objectsTotal=((p=this.artboard)==null?void 0:p.objects.length)||0,this.debug_objectsRendered=0;const e=performance.now();if(this.canvasWidth=s,this.canvasHeight=o,!this.artboard)return;t.clearRect(0,0,s,o);const n=this.artboard.width,i=this.artboard.height,a=this.calculateTransform(s,o,n,i,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,n,i)),this.artboard.backgroundImage){const g=this.artboard.backgroundImage;let u=this.imageCache.get(g);if(u||(u=new Image,u.src=g,this.imageCache.set(g,u)),u.complete&&u.naturalWidth>0){t.save(),t.globalAlpha=this.normalizeOpacity(this.artboard.backgroundOpacity??100);const f=u.naturalWidth/u.naturalHeight,h=n/i;let m,b,c,S;h>f?(m=n,b=n/f):(b=i,m=i*f),c=(n-m)/2,S=(i-b)/2,t.drawImage(u,c,S,m,b),t.restore()}}this.artboard.clipContent!==!1&&this.artboard.clip_content!==!1&&(t.beginPath(),t.rect(0,0,n,i),t.clip());const l=new Map;this.artboard.objects.forEach(g=>l.set(g.id,g)),this.artboard.objects.filter(g=>!g.parentId).map((g,u)=>{const f=this.objectStates.get(g.id),h=(f==null?void 0:f.zIndex)??u;return{obj:g,zIndex:h}}).sort((g,u)=>g.zIndex-u.zIndex).forEach(({obj:g})=>{this.renderObject(t,g,l)}),this._emitterPools.forEach((g,u)=>{if(!(g.length===0||!l.get(u)))for(const h of g)t.save(),t.globalAlpha=h.opacity,t.fillStyle=h.color,t.beginPath(),t.arc(h.x,h.y,Math.max(1,h.size*h.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,s,o,e,n,i=0){const a=t.getTransform(),r=s*a.a+o*a.c+a.e,l=s*a.b+o*a.d+a.f,d=Math.sqrt(a.a*a.a+a.b*a.b),p=Math.sqrt(a.c*a.c+a.d*a.d),g=(e/2+i)*d,u=(n/2+i)*p;return r+g>=0&&r-g<=this.canvasWidth&&l+u>=0&&l-u<=this.canvasHeight}calculateTransform(t,s,o,e,n,i){let a=1,r=1,l=1;const d=o/e,p=t/s;switch(n){case"Contain":p>d?l=s/e:l=t/o,a=r=l;break;case"Cover":p>d?l=t/o:l=s/e,a=r=l;break;case"Fill":a=t/o,r=s/e;break;case"FitWidth":l=t/o,a=r=l;break;case"FitHeight":l=s/e,a=r=l;break;case"None":a=r=1;break;case"ScaleDown":l=Math.min(t/o,s/e),l>1&&(l=1),a=r=l;break;default:a=r=1;break}const g=o*a,u=e*r;let f=0,h=0;return i.includes("Left")?f=0:i.includes("Right")?f=t-g:f=(t-g)/2,i.includes("Top")?h=0:i.includes("Bottom")?h=s-u:h=(s-u)/2,{scaleX:a,scaleY:r,tx:f,ty:h}}mapFontWeight(t){const s=t.toLowerCase();return s==="thin"||s==="100"?"100":s==="extralight"||s==="200"?"200":s==="light"||s==="300"?"300":s==="regular"||s==="normal"||s==="400"?"400":s==="medium"||s==="500"?"500":s==="semibold"||s==="600"?"600":s==="bold"||s==="700"?"700":s==="extrabold"||s==="800"?"800":s==="black"||s==="900"?"900":t}drawTextDecoration(t,s,o,e,n,i){t.beginPath();const a=Math.max(1,i/14);let r=e;s==="underline"?r=e+i*.12:s==="line-through"&&(r=e-i*.3),t.lineWidth=a,t.strokeStyle=t.fillStyle,t.moveTo(o-n/2,r),t.lineTo(o+n/2,r),t.stroke()}renderObject(t,s,o,e=!1,n=!1){var S,v,C,w,I,k,O,T,A,D,Y,B,R,L,$,F,X,M,E,P,_,V,G,x,U,q,N,H,z,et,Mt,ct,It,mt,kt,Ot;const i=this.objectStates.get(s.id);if(!i){this.warn("No state for object:",s.id);return}this.frameCount%60,t.roundRect||(t.roundRect=(vt,Wt,J,ut,$t)=>(this.drawRoundRect(t,vt,Wt,J,ut,$t),t));const a=i.geometry?this.deepMerge(s.geometry,i.geometry):s.geometry;let r=i.style?this.deepMerge(s.style,i.style):s.style,l=(a==null?void 0:a.width)||((S=s.geometry)==null?void 0:S.width)||s.width||0,d=(a==null?void 0:a.height)||((v=s.geometry)==null?void 0:v.height)||s.height||0;if((l===0||d===0)&&(a!=null&&a.points)&&Array.isArray(a.points)&&a.points.length>0){let vt=1/0,Wt=-1/0,J=1/0,ut=-1/0;a.points.forEach($t=>{vt=Math.min(vt,$t.x),Wt=Math.max(Wt,$t.x),J=Math.min(J,$t.y),ut=Math.max(ut,$t.y)}),l===0&&(l=Wt-vt),d===0&&(d=ut-J)}const p=vt=>{if(vt)return vt.corner_radius??vt.cornerRadius},g=p(a)??p(i)??p(r)??p(s.geometry)??p(s.style)??p(s)??0;let u={...a,width:l,height:d};if(delete u.cornerRadius,u.corner_radius=g,!u.type&&(s.type==="Frame"||s.type==="Component"||s.type==="Group")&&(u.type="Rectangle"),s.type==="Text"&&(u.type="Text"),u.type==="Path"&&s.weights&&s.bindMatrices&&u.points){const vt=this.getGlobalTransform(s.id);if(vt){const Wt=ni(u.points,s.weights,s.bindMatrices,vt,J=>this.getGlobalTransform(J));u={...u,points:Wt}}}if(i.visible===!1)return;const h=(r.effects||((C=s.style)==null?void 0:C.effects)||[]).find(vt=>vt.isEnabled!==!1&&vt.type==="PathDistortion");if(h){const vt=ai(u,l,d,h.amplitude||5,h.frequency||10,h.seed||0,h.direction||0,h.directionStrength||0);u={...u,type:"Path",points:vt}}const m=s.repeaterConfig,b=m&&m.isEnabled&&m.count>1,c=b?m.count:1;for(let vt=0;vt<c;vt++){let Wt=i.x!==void 0?i.x:((w=i.transform)==null?void 0:w.x)??0,J=i.y!==void 0?i.y:((I=i.transform)==null?void 0:I.y)??0,ut=i.rotation!==void 0?i.rotation:((k=i.transform)==null?void 0:k.rotation)??0,$t=i.scale_x!==void 0?i.scale_x:((O=i.transform)==null?void 0:O.scale_x)??1,St=i.scale_y!==void 0?i.scale_y:((T=i.transform)==null?void 0:T.scale_y)??1;if(b&&vt>0){if(m.type==="Linear"){const j=m.offsetX||0,bt=m.offsetY||0,st=m.rotation||0,K=m.scale!==void 0?m.scale:1;Wt+=vt*j,J+=vt*bt,ut+=vt*st,$t*=Math.pow(K,vt),St*=Math.pow(K,vt)}else if(m.type==="Grid"){const j=m.cols||Math.ceil(Math.sqrt(m.count)),bt=m.gapX||0,st=m.gapY||0,K=Math.floor(vt/j),rt=vt%j,ft=l+bt,Rt=d+st;Wt+=rt*ft,J+=K*Rt}else if(m.type==="Radial"){const j=m.radius||100,bt=m.startAngle||0,K=(m.endAngle||360)-bt,rt=m.count>1?K/(K===360?m.count:m.count-1):0,ft=bt+vt*rt,Rt=ft*Math.PI/180;Wt=i.x+j*Math.cos(Rt),J=i.y+j*Math.sin(Rt),ut+=ft}}const Pt=s.type==="Group"||s.type==="Frame"||s.type==="Component",Ft=l>0&&d>0;if(!Pt&&Ft&&!e){const j=(((A=r.shadow)==null?void 0:A.isEnabled)!==!1?(((D=r.shadow)==null?void 0:D.blur)||0)+10:0)+(((Y=r.blur)==null?void 0:Y.isEnabled)!==!1&&((B=r.blur)==null?void 0:B.radius)||0)+20;if(!this.isObjectInView(t,Wt,J,l,d,j))continue}this.debug_objectsRendered++,t.save();const lt=[],ht=r.blur||((R=s.style)==null?void 0:R.blur);ht&&ht.amount>0&&lt.push(`blur(${ht.amount}px)`);const dt=r.effects||((L=s.style)==null?void 0:L.effects)||[];let At=dt.find(j=>j.isEnabled!==!1&&(j.type==="BackgroundBlur"||j.type==="LayerBlur"));At||(At=r.effect||(($=s.style)==null?void 0:$.effect)||dt.find(j=>j.isEnabled!==!1));const Tt=At,Ct=(Tt==null?void 0:Tt.isEnabled)!==!1,Yt=Tt==null?void 0:Tt.type,ie=(Tt==null?void 0:Tt.radius)??10;Ct&&Yt==="LayerBlur"?lt.push(`blur(${ie}px)`):Ct&&Yt==="BackgroundBlur"&&(r===s.style&&(r={...r}),r.fill={type:"None"});const te=(u==null?void 0:u.adjustments)||(a==null?void 0:a.adjustments)||((F=s.geometry)==null?void 0:F.adjustments),Zt=(r==null?void 0:r.adjustments)||((X=s.style)==null?void 0:X.adjustments),le=((M=r==null?void 0:r.fill)==null?void 0:M.adjustments)||((P=(E=s.style)==null?void 0:E.fill)==null?void 0:P.adjustments),fe=s==null?void 0:s.adjustments,qt=te||Zt||le||fe;if(i&&qt&&(i.geometry=i.geometry||{},i.geometry.adjustments={...qt}),qt){const j=(qt.exposure||0)/100,bt=(qt.contrast||0)/100,st=(qt.saturation||0)/100,K=(qt.temperature||0)/200,rt=(qt.tint||0)/200,ft=(qt.highlights||0)/500,Rt=(qt.shadows||0)/500,Qt=qt.hue||0,Kt=(qt.negative||0)/100,ae=qt.blur||0;if(j!==0&&lt.push(`brightness(${1+j})`),bt!==0){const Et=bt>0?1+bt*2:1+bt;lt.push(`contrast(${Number(Et.toFixed(2))})`)}if(st!==0){const Et=st>0?1+st*1.5:1+st;lt.push(`saturate(${Number(Et.toFixed(2))})`)}const Jt=Qt+rt*30-K*20;Jt!==0&&lt.push(`hue-rotate(${Math.round(Jt)}deg)`),K>0&&lt.push(`sepia(${Math.round(K*40)}%)`),Kt!==0&&lt.push(`invert(${Math.abs(Kt)})`),ft!==0&&lt.push(`brightness(${1+ft})`),Rt!==0&&lt.push(`contrast(${1+Rt})`),ae>0&&lt.push(`blur(${ae}px)`)}lt.length>0?(t.filter=lt.join(" "),(!this._lastLoggedAdjustments||this._lastLoggedAdjustments!==t.filter)&&(this._lastLoggedAdjustments=t.filter,this.log(`[ExodeUI Engine] Applied Canvas Filter for (${s.name||s.id}): "${t.filter}" (Adjustments: ${JSON.stringify(qt)})`),console.log(`[ExodeUI Engine Log] Applied Canvas Filter for (${s.name||s.id}):`,{filter:t.filter,adjustments:qt}))):t.filter="none",t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";const Se=t.globalAlpha,Ce=this.normalizeOpacity(i.opacity!==void 0?i.opacity:100);t.globalAlpha=Se*Ce;const Ie=i.compositeOperation||i.blendMode;if(Ie&&Ie!=="Normal"){const j=Ie.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(j)&&(t.globalCompositeOperation=j)}const de=t,Re=i.masks||(s.maskedBy?[{maskId:s.maskedBy,inverted:s.maskInverted===!0,type:s.maskType||"alpha",opacity:s.maskOpacity!==void 0?s.maskOpacity/100:1,feather:s.maskFeather||0,isVisible:!0}]:[]);let ye=!1;const ke=Re.filter(j=>j.isVisible!==!1&&o.has(j.maskId));if(ke.length>0){const j=ke[0],bt=o.get(j.maskId),st=this.objectStates.get(bt.id);st&&st.visible!==!1&&(ye=!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),s.parentId&&this.applyAbsoluteTransform(this.maskCtx,s.parentId,o),this.maskCtx.save(),this.maskCtx.globalAlpha=1,t=this.maskCtx,t.filter=de.filter)}if(!n){t.translate(Wt,J),t.rotate(ut*Math.PI/180);const j=i.skew_x||0,bt=i.skew_y||0;if(j!==0||bt!==0){const Kt=Math.tan(j*Math.PI/180),ae=Math.tan(bt*Math.PI/180);t.transform(1+Kt*ae,ae,Kt,1,0,0)}const st=i.rotate_x!==void 0?i.rotate_x:((_=i.transform)==null?void 0:_.rotate_x)??0,K=i.rotate_y!==void 0?i.rotate_y:((V=i.transform)==null?void 0:V.rotate_y)??0,ft=1+(i.translate_z!==void 0?i.translate_z:((G=i.transform)==null?void 0:G.translate_z)??0)/1e3,Rt=(i.flip_x===!0?-1:1)*Math.cos(K*Math.PI/180)*ft,Qt=(i.flip_y===!0?-1:1)*Math.cos(st*Math.PI/180)*ft;t.scale($t*Rt,St*Qt)}r.shadow&&r.shadow.isEnabled===void 0&&((r.shadow.blur||0)>0||Math.abs(r.shadow.offsetX||0)>0||Math.abs(r.shadow.offsetY||0)>0)&&(r.shadow.isEnabled=!0);const Vt=r.shadow;if(Vt&&Vt.isEnabled!==!1&&!e){let j=Vt.color||"#000000";(U=(x=this.artboard)==null?void 0:x.tokens)!=null&&U.colors&&this.artboard.tokens.colors[j]&&(j=this.artboard.tokens.colors[j]);const bt=this.normalizeOpacity(Vt.opacity??100)*.75,st=Vt.spread||0,rt=(Vt.blur||0)+st*1.5;let ft=j;if(j.startsWith("#")){const Kt=j.replace("#",""),ae=parseInt(Kt.substring(0,2),16),Jt=parseInt(Kt.substring(2,4),16),Et=parseInt(Kt.substring(4,6),16);ft=`rgba(${ae}, ${Jt}, ${Et}, ${bt})`}else if(j.startsWith("rgba")){const Kt=j.match(/[\d.]+/g);if(Kt&&Kt.length>=4){const ae=Kt[0],Jt=Kt[1],Et=Kt[2],W=Kt[3];ft=`rgba(${ae}, ${Jt}, ${Et}, ${parseFloat(W)*bt})`}}const Rt=t.getTransform(),Qt=Math.sqrt(Rt.a*Rt.a+Rt.b*Rt.b)||1;t.shadowColor=ft,t.shadowBlur=rt*Qt,t.shadowOffsetX=(Vt.offsetX||0)*Qt,t.shadowOffsetY=(Vt.offsetY||0)*Qt}const ee=s.liquidFill||((q=s.style)==null?void 0:q.liquidFill);if(ee&&ee.enabled){t.save();const j=ee.fillLevel??.5;t.beginPath();const bt=d/2-d*j;t.rect(-l/2,bt,l,d*j),t.clip(),t.fillStyle=ee.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(ee.opacity??1)}if(e||this.applyOuterGlowUnderlay(t,s,u,l,d,g,r,o),(a==null?void 0:a.type)==="Text"||s.type==="Text")this._renderText(t,s,u,r,i,l,d,!1,!1);else if((a==null?void 0:a.type)==="Image"||((N=r.fill)==null?void 0:N.type)==="Image"||s.type==="Image"&&(a!=null&&a.src||(H=r.fill)!=null&&H.src)){const j=(a==null?void 0:a.originalSrc)||(a==null?void 0:a.src)||((z=r.fill)==null?void 0:z.originalSrc)||((et=r.fill)==null?void 0:et.src)||(s==null?void 0:s.src);if(j){let bt=this.imageCache.get(j);bt||(bt=new Image,bt.onload=()=>{this.log(`[ExodeUI] Image loaded successfully, size: ${bt.naturalWidth}x${bt.naturalHeight}`)},bt.onerror=rt=>{console.error("[ExodeUI] Image load failed:",rt,`Src preview: ${j.substring(0,100)}...`)},bt.src=j,this.imageCache.set(j,bt));const st=r.stroke&&r.stroke.width>0&&r.stroke.isEnabled!==!1,K=(((Mt=r.stroke)==null?void 0:Mt.alignment)||"center").toLowerCase();if(st&&K==="outside"&&this.applyStrokeAlignment(t,r,u,l,d,g),r.fill&&r.fill.type!=="None"){t.save();const rt=t.globalAlpha,ft=this.createCanvasFill(t,r.fill,l,d);t.fillStyle=ft||r.fill.color||"transparent",t.globalAlpha=rt*this.normalizeOpacity(r.fill.opacity??100),g!==0?(this.drawRoundRect(t,-l/2,-d/2,l,d,g),t.fill()):t.fillRect(-l/2,-d/2,l,d),t.globalAlpha=rt,t.restore()}if(bt.complete&&bt.naturalWidth>0){const rt=qt?this.processFabricAdjustmentsCanvas(bt,l,d,qt):bt;g!==0?(t.save(),this.drawRoundRect(t,-l/2,-d/2,l,d,g),t.clip(),t.drawImage(rt,-l/2,-d/2,l,d),t.restore()):t.drawImage(rt,-l/2,-d/2,l,d),st&&(K==="inside"||K==="center")&&this.applyStrokeAlignment(t,r,u,l,d,g)}else st&&(K==="inside"||K==="center")&&this.applyStrokeAlignment(t,r,u,l,d,g)}}else if(a.type==="SVG"){const j=a.svgContent;if(j){const bt=r.palette||[],st=r.fill,K=r.stroke,rt=st?this.normalizeOpacity(st.opacity??100):1,ft=K&&K.isEnabled!==!1?this.normalizeOpacity(K.opacity??100):1,Rt=(st==null?void 0:st.type)==="Solid"&&(!K||K.isEnabled===!1||K.type==="Solid"&&K.color===st.color&&ft===rt),Qt=st&&st.type!=="None"?Rt?"monochrome":st.type==="Solid"?(st.color||"")+"|opacity:"+rt:JSON.stringify(st.stops||[])+"|opacity:"+rt:"",Kt=K&&K.isEnabled!==!1&&(K.width||0)>0?Rt?["monochrome",K.width||0,K.trimStart??0,K.trimEnd??1,K.trimOffset??0,K.dashOffset??0].join("|"):[K.width||0,K.fill?K.fill.type==="Solid"?K.fill.color||"":JSON.stringify(K.fill.stops||[]):K.color||"",K.opacity??1,K.lineCap||"",K.lineJoin||"",(K.dashArray||[]).join(","),K.trimStart??0,K.trimEnd??1,K.trimOffset??0,K.dashOffset??0].join("|"):"nostroke",ae=[s.id,bt.join("_"),Qt,Kt,i.opacity??100,i.visible!==!1?"v":"h"].join("_");let Jt=this.imageCache.get(ae);if(!Jt){Jt=new Image,Jt.crossOrigin="anonymous";let W=j;W.match(/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i)||(W=W.replace(/<svg([^>]*)>/i,(yt,Bt)=>`<svg xmlns="http://www.w3.org/2000/svg"${Bt}>`));let nt=a.width||l||100,Lt=a.height||d||100;const tt=W.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(tt&&(nt=parseFloat(tt[1]),Lt=parseFloat(tt[2])),W=W.replace(/<svg([^>]*)>/i,(yt,Bt)=>{let _t=Bt.replace(/\b(?:width|height)=["'][^"']*["']/gi," ");return _t.match(/\bviewBox=/i)||(_t+=` viewBox="0 0 ${nt} ${Lt}"`),_t.match(/\bpreserveAspectRatio=/i)||(_t+=' preserveAspectRatio="none"'),_t+=' width="100%" height="100%"',`<svg${_t}>`}),a.colors&&a.colors.length>0&&bt.length>0&&a.colors.forEach((yt,Bt)=>{if(bt[Bt]){const _t=yt.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),Xt=new RegExp(_t,"gi");W=W.replace(Xt,bt[Bt])}}),st&&st.type&&st.type!=="None"){if(st.type==="Solid"&&st.color){const yt=Rt?"#FFFFFF":st.color,Bt=Rt?1:this.normalizeOpacity(st.opacity??100);W=W.replace(/\bfill\s*=\s*["'][^"']*["']/gi,_t=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(_t)?_t:`fill="${yt}"`),W=W.replace(/fill\s*:\s*[^;"')]+/gi,_t=>/fill\s*:\s*(none|transparent)/i.test(_t)?_t:`fill:${yt}`),Bt<1&&(W=W.replace(/\bfill-opacity\s*=\s*["'][^"']*["']/gi,`fill-opacity="${Bt}"`),W=W.replace(/fill-opacity\s*:\s*[^;"')]+/gi,`fill-opacity:${Bt}`),W.match(/\bfill-opacity\s*=/i)||(W=W.replace(/(<svg[^>]*>)/i,`$1<g fill-opacity="${Bt}">`),W=W.replace(/<\/svg>/i,"</g></svg>")))}else if(st.type==="LinearGradient"||st.type==="RadialGradient"||st.type==="Linear"||st.type==="Radial"){const yt="exode-fill",Bt=this.normalizeOpacity(st.opacity??100),_t=(st.stops||[]).map(Dt=>{const ce=Dt.offset!==void 0?Dt.offset:Dt.pos??0,be=this.normalizeOpacity(Dt.opacity??100)*Bt;return`<stop offset="${ce*100}%" stop-color="${Dt.color||"#000"}" stop-opacity="${be}"/>`}).join("");let Xt="";if(st.type==="LinearGradient"||st.type==="Linear"){const Dt=(pe,he)=>Array.isArray(pe)?pe[he]??(he===0?0:1):pe&&typeof pe=="object"?pe[he===0?"x":"y"]??(he===0?0:1):he===0?0:1,ce=Dt(st.start,0)*100,be=Dt(st.start,1)*100,Le=Dt(st.end,0)*100,oe=Dt(st.end,1)*100;Xt=`<linearGradient id="${yt}" x1="${ce}%" y1="${be}%" x2="${Le}%" y2="${oe}%" gradientUnits="objectBoundingBox">${_t}</linearGradient>`}else{const Dt=(oe,pe)=>Array.isArray(oe)?oe[pe]??.5:oe&&typeof oe=="object"?oe[pe===0?"x":"y"]??.5:.5,ce=Dt(st.center,0)*100,be=Dt(st.center,1)*100,Le=(st.radius??.5)*100;Xt=`<radialGradient id="${yt}" cx="${ce}%" cy="${be}%" r="${Le}%" gradientUnits="objectBoundingBox">${_t}</radialGradient>`}/<defs>/i.test(W)?W=W.replace(/<defs>/i,`<defs>${Xt}`):W=W.replace(/<svg([^>]*)>/i,`<svg$1><defs>${Xt}</defs>`),W=W.replace(/\bfill\s*=\s*["'][^"']*["']/gi,Dt=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Dt)?Dt:`fill="url(#${yt})"`),W=W.replace(/fill\s*:\s*[^;"')]+/gi,Dt=>/fill\s*:\s*(none|transparent)/i.test(Dt)?Dt:`fill:url(#${yt})`)}}const gt=(yt,Bt,_t=1)=>{const Xt=(yt.stops||[]).map(oe=>{const pe=oe.offset!==void 0?oe.offset:oe.pos??0,he=this.normalizeOpacity(oe.opacity??100)*_t;return`<stop offset="${pe*100}%" stop-color="${oe.color||"#000"}" stop-opacity="${he}"/>`}).join(""),Dt=(oe,pe,he=.5)=>Array.isArray(oe)?oe[pe]??he:oe&&typeof oe=="object"?oe[pe===0?"x":"y"]??he:he;if(yt.type==="LinearGradient"||yt.type==="Linear"){const oe=Dt(yt.start,0,0)*100,pe=Dt(yt.start,1,0)*100,he=Dt(yt.end,0,1)*100,$e=Dt(yt.end,1,1)*100;return`<linearGradient id="${Bt}" x1="${oe}%" y1="${pe}%" x2="${he}%" y2="${$e}%" gradientUnits="objectBoundingBox">${Xt}</linearGradient>`}const ce=Dt(yt.center,0,.5)*100,be=Dt(yt.center,1,.5)*100,Le=(yt.radius??.5)*100;return`<radialGradient id="${Bt}" cx="${ce}%" cy="${be}%" r="${Le}%" gradientUnits="objectBoundingBox">${Xt}</radialGradient>`},Q=(yt,Bt)=>/<defs>/i.test(yt)?yt.replace(/<defs>/i,`<defs>${Bt}`):yt.replace(/(<svg[^>]*>)/i,`$1<defs>${Bt}</defs>`);if(K&&K.isEnabled!==!1&&(K.width||0)>0){const yt=Rt?1:this.normalizeOpacity(K.opacity??100),Bt=Rt?"#FFFFFF":K.color||(st==null?void 0:st.color)||"#000000";let _t="";const Xt=K.fill;if(Xt&&Xt.type){if(Xt.type==="Solid")_t=Xt.color||K.color||"#000000";else if(Xt.type==="LinearGradient"||Xt.type==="RadialGradient"||Xt.type==="Linear"||Xt.type==="Radial"){const re="exode-stroke";W=Q(W,gt(Xt,re,yt)),_t=`url(#${re})`}}_t||(_t=Bt),W.match(/\bstroke\s*=\s*["']/i)?W=W.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,re=>/stroke\s*=\s*["']\s*(none|transparent)\s*["']/i.test(re)?re:`stroke="${_t}"`):W=W.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke="${_t}"`),W=W.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),`stroke:${_t}`);let Dt=a.width||l||100,ce=a.height||d||100;const be=j.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(be){const re=parseFloat(be[1]),ve=parseFloat(be[2]);!isNaN(re)&&!isNaN(ve)&&(Dt=re,ce=ve)}const Le=Math.max(.001,l/Dt),oe=Math.max(.001,d/ce),pe=(Le+oe)/2,he=(K.width||1)/pe;W.match(/\bstroke-width\s*=\s*["']/i)?W=W.replace(/\bstroke-width\s*=\s*["'][^"']*["']/gi,`stroke-width="${he}"`):W=W.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-width="${he}"`),W=W.replace(/stroke-width\s*:\s*[^;"')]+/gi,`stroke-width:${he}`),W.match(/\bstroke-opacity\s*=\s*["']/i)?W=W.replace(/\bstroke-opacity\s*=\s*["'][^"']*["']/gi,`stroke-opacity="${yt}"`):W=W.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-opacity="${yt}"`),W=W.replace(/stroke-opacity\s*:\s*[^;"')]+/gi,`stroke-opacity:${yt}`);const $e=K.lineCap||"round";W.match(/\bstroke-linecap\s*=\s*["']/i)?W=W.replace(/\bstroke-linecap\s*=\s*["'][^"']*["']/gi,`stroke-linecap="${$e}"`):W=W.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linecap="${$e}"`),W=W.replace(/stroke-linecap\s*:\s*[^;"')]+/gi,`stroke-linecap:${$e}`);const Be=K.lineJoin||"round";W.match(/\bstroke-linejoin\s*=\s*["']/i)?W=W.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${Be}"`):W=W.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linejoin="${Be}"`),W=W.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${Be}`);const Ye=K.trimStart??0,De=K.trimEnd??1,Xe=K.trimOffset??0,Ne=K.dashOffset??0,Ue=Ye!==0||De!==1||Xe!==0||Ne!==0;if(Ue){const re=Math.max(0,Math.min(1,Ye)),ve=Math.max(0,Math.min(1,De));this.frameCount%600===0&&this.debugLog(`SVG Trim - Object: ${s.name||s.id}, Start: ${re}, End: ${ve}`);const Te=(Dt+ce)*2,He=(Xe%1+1)%1,Ve=(Ne%1+1)%1;let _e="",Pe=0;if(re>=ve)_e=`0 ${Te}`,Pe=0;else{const Z=Te*(ve-re),ot=Te-Z;Pe=-(Te*(re+He+Ve)),_e=`${Z} ${ot}`}W.match(/\bstroke-dasharray\s*=/i)?W=W.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${_e}"`):W=W.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dasharray="${_e}"`),W=W.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${_e}`),W.match(/\bstroke-dashoffset\s*=/i)?W=W.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${Pe}"`):W=W.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dashoffset="${Pe}"`),W=W.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${Pe}`)}else if(K.dashArray&&K.dashArray.length>0){const re=K.dashArray.join(" ");if(W=W.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${re}"`),W=W.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${re}`),K.dashOffset){const ve=(Dt+ce)*2,Te=-(K.dashOffset*ve);W=W.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${Te}"`),W=W.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${Te}`)}}if(!/\bstroke\s*=\s*["']/i.test(j)&&!new RegExp("(?<![a-z-])stroke\\s*:","i").test(j)){let re="",ve="";if(Ue){const _e=a.width||l||100,Pe=a.height||d||100,Z=(_e+Pe)*2,ot=Math.max(0,Math.min(1,Ye)),at=Math.max(0,Math.min(1,De)),wt=(Xe%1+1)%1,Gt=(Ne%1+1)%1;if(ot>=at)re=` stroke-dasharray="0 ${Z}"`,ve=' stroke-dashoffset="0"';else{const xt=Z*(at-ot),jt=Z-xt,me=-(Z*(ot+wt+Gt));re=` stroke-dasharray="${xt} ${jt}"`,ve=` stroke-dashoffset="${me}"`}}else(ct=K.dashArray)!=null&&ct.length&&(re=` stroke-dasharray="${K.dashArray.join(" ")}"`,K.dashOffset&&(ve=` stroke-dashoffset="${K.dashOffset}"`));const Te=` stroke-linecap="${K.lineCap||"round"}"`,He=` stroke-linejoin="${K.lineJoin||"round"}"`,Ve=`stroke="${_t}" stroke-width="${he}" stroke-opacity="${yt}"${Te}${He}${re}${ve}`;W=W.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(_e,Pe,Z)=>`${Pe}${Z}<g ${Ve}>`),W=W.replace(/<\/svg>/i,"</g></svg>")}}else K&&K.isEnabled===!1&&(W=W.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,'stroke="none"'),W=W.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),"stroke:none"));const Ut=new Blob([W],{type:"image/svg+xml"}),zt=URL.createObjectURL(Ut);Jt.onload=()=>{if(URL.revokeObjectURL(zt),this.frameCount%900===0){const yt=this.imageCache.get(ae);yt&&this.debugLog(`SVG Payload Ready: ${s.name||s.id} (${yt.naturalWidth}x${yt.naturalHeight})`)}},Jt.onerror=()=>{URL.revokeObjectURL(zt),this.debugLog(`SVG Error: Failed to load payload for ${s.name||s.id}`)},Jt.src=zt,this.imageCache.set(ae,Jt)}let Et=null;if(Jt.complete&&Jt.naturalWidth>0?(Et=Jt,this.lastValidSvgImgMap.set(s.id,Jt)):Et=this.lastValidSvgImgMap.get(s.id)||null,Et&&Et.complete&&Et.naturalWidth>0){const W=Math.max(1,l),nt=Math.max(1,d);if(Rt&&(st==null?void 0:st.type)==="Solid"){this.maskBuffer||(this.maskBuffer=document.createElement("canvas"),this.maskCtx=this.maskBuffer.getContext("2d")),this.maskBuffer.width=W,this.maskBuffer.height=nt,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,W,nt),this.maskCtx.drawImage(Et,0,0,W,nt),this.maskCtx.globalCompositeOperation="source-in";const Lt=st.color||"#000000",tt=this.normalizeOpacity(st.opacity??100);this.maskCtx.fillStyle=Lt,this.maskCtx.globalAlpha=tt,this.maskCtx.fillRect(0,0,W,nt),t.drawImage(this.maskBuffer,-W/2,-nt/2,W,nt)}else g!==0?(t.save(),this.drawRoundRect(t,-W/2,-nt/2,W,nt,g),t.clip(),t.drawImage(Et,-W/2,-nt/2,W,nt),t.restore()):t.drawImage(Et,-W/2,-nt/2,W,nt)}}}else if(u.type==="LineGraph"||s.type==="LineGraph"||this.isLineGraphObject(s))this.renderLineGraph(t,s,u,l,d);else if(s.type==="Shape"){if(this.applyPath(t,u,l,d,g),t.save(),r.blur&&r.blur.amount>0&&(t.filter=`blur(${r.blur.amount}px)`),Ct&&Yt==="BackgroundBlur")if(e)t.fillStyle="#000000",t.globalAlpha=1,this.applyPath(t,u,l,d,g),t.fill();else{if(t.shadowColor&&t.shadowColor!=="rgba(0, 0, 0, 0)"&&t.shadowColor!=="transparent"){const st=t.getTransform(),K=t.shadowOffsetX,rt=t.shadowOffsetY;t.shadowOffsetX=K+1e4*st.a,t.shadowOffsetY=rt+1e4*st.b,t.save(),t.translate(-1e4,0),this.applyPath(t,u,l,d,g),t.fillStyle="white",t.fill(),t.restore(),t.shadowOffsetX=K,t.shadowOffsetY=rt,t.shadowColor="transparent"}this.applyBackgroundBlurGlass(t,u,l,d,g,Tt,r)}else if(r.fill){const bt=t.globalAlpha;if(((It=r.fill)==null?void 0:It.type)==="Image"&&(r.fill.originalSrc||r.fill.src)){const st=r.fill.originalSrc||r.fill.src;let K=this.imageCache.get(st);K||(K=new Image,K.src=st,this.imageCache.set(st,K)),K.complete&&K.naturalWidth>0&&(t.save(),this.applyPath(t,u,l,d,g),t.clip(),this.renderFittedImage(t,K,-l/2,-d/2,l,d,r.fill.fillMode),t.restore())}else{const st=this.createCanvasFill(t,r.fill,l,d);t.fillStyle=st||(typeof r.fill=="string"?r.fill:r.fill.color||"transparent"),t.globalAlpha=bt*this.normalizeOpacity(r.fill.opacity??100),this.applyPath(t,u,l,d,g),t.fill()}t.globalAlpha=bt}t.restore(),r.stroke&&r.stroke.width>0&&(this.applyPath(t,u,l,d,g),this.applyStrokeAlignment(t,r,u,l,d,g))}else if(s.type==="Frame"||s.type==="Component"&&!s.variant||s.type==="Group"&&!s.isStructuralGroup){const j=i.width??a.width??s.width??l,bt=i.height??a.height??s.height??d,st=g;if(t.save(),t.beginPath(),this.drawRoundRect(t,-j/2,-bt/2,j,bt,st),Ct&&Yt==="BackgroundBlur")if(e)t.fillStyle="#000000",t.globalAlpha=1,t.beginPath(),this.drawRoundRect(t,-j/2,-bt/2,j,bt,st),t.fill();else{if(t.shadowColor&&t.shadowColor!=="rgba(0, 0, 0, 0)"&&t.shadowColor!=="transparent"){const ft=t.getTransform(),Rt=t.shadowOffsetX,Qt=t.shadowOffsetY;t.shadowOffsetX=Rt+1e4*ft.a,t.shadowOffsetY=Qt+1e4*ft.b,t.save(),t.translate(-1e4,0),t.beginPath(),this.drawRoundRect(t,-j/2,-bt/2,j,bt,st),t.fillStyle="white",t.fill(),t.restore(),t.shadowOffsetX=Rt,t.shadowOffsetY=Qt,t.shadowColor="transparent"}this.applyBackgroundBlurGlass(t,u,j,bt,st,Tt,r)}else if(r.fill&&r.fill.type!=="None"){const rt=t.globalAlpha;if(((mt=r.fill)==null?void 0:mt.type)==="Image"&&(r.fill.originalSrc||r.fill.src)){const ft=r.fill.originalSrc||r.fill.src;let Rt=this.imageCache.get(ft);Rt||(Rt=new Image,Rt.src=ft,this.imageCache.set(ft,Rt)),Rt.complete&&Rt.naturalWidth>0&&(t.save(),t.beginPath(),this.drawRoundRect(t,-j/2,-bt/2,j,bt,st),t.clip(),this.renderFittedImage(t,Rt,-j/2,-bt/2,j,bt,r.fill.fillMode),t.restore())}else{const ft=this.createCanvasFill(t,r.fill,j,bt);t.fillStyle=ft||r.fill.color||"transparent",t.globalAlpha=rt*this.normalizeOpacity(r.fill.opacity??100),t.beginPath(),this.drawRoundRect(t,-j/2,-bt/2,j,bt,st),t.fill(),t.globalAlpha=rt}}if(t.restore(),!e&&(Ct&&Yt==="BackgroundBlur"||r.fill&&r.fill.type!=="None")&&(t.shadowColor="transparent"),r.stroke&&r.stroke.width>0&&r.stroke.isEnabled!==!1){const rt={type:"Rectangle"};t.beginPath(),this.drawRoundRect(t,-j/2,-bt/2,j,bt,st),this.applyStrokeAlignment(t,r,rt,j,bt,st)}}else s.type==="Group"&&s.isStructuralGroup||(s.type==="Component"&&s.variant==="inputbox"?this.renderInputBox(t,s):s.type==="Button"||s.type==="Component"&&(s.variant==="button"||(s.name||"").toLowerCase().includes("button")||(s.name||"").toLowerCase().includes("cta"))?this.renderButton(t,s):s.type==="Component"&&s.variant==="toggle_button"?this.renderToggleButton(t,s):s.type==="Toggle"||s.type==="Component"&&s.variant==="toggle"?this.renderToggle(t,s):s.type==="Slider"||s.type==="Component"&&s.variant==="slider"?this.renderSlider(t,s):s.type==="Dropdown"||s.type==="Component"&&s.variant==="dropdown"?this.renderDropdown(t,s):s.type==="ListView"||s.type==="Component"&&s.variant==="listview"?this.renderListView(t,s):s.type==="Checkbox"||((kt=s.geometry)==null?void 0:kt.type)==="Checkbox"||s.type==="Component"&&s.variant==="checkbox"?this.renderCheckbox(t,s):s.type==="RadioGroup"||s.type==="Component"&&s.variant==="radiogroup"?this.renderRadioGroup(t,s):s.type==="BarChart"||s.type==="Component"&&s.variant==="barchart"?this.renderBarChart(t,s):s.type==="PieChart"||s.type==="Component"&&s.variant==="piechart"?this.renderPieChart(t,s):s.type==="Joystick"||s.type==="Component"&&s.variant==="joystick"?this.renderJoystick(t,s):this.frameCount%300===0&&this.warn("[Engine] Unhandled object type in renderObject:",s.type,"Geo:",(Ot=s.geometry)==null?void 0:Ot.type));if(e||(this.applyInnerGlowOverlay(t,s,u,l,d,g,r),this.applyArtEffectOverlay(t,s,u,l,d,g)),ee&&ee.enabled&&t.restore(),s.children&&s.children.length>0){const bt=s.type==="Frame",st=s.clipsContent!==void 0?s.clipsContent:s.clipContent!==void 0?s.clipContent:bt;if(t.save(),st){t.beginPath();const rt=i.width??(a==null?void 0:a.width)??s.width??0,ft=i.height??(a==null?void 0:a.height)??s.height??0,Rt=i.cornerRadius??(a==null?void 0:a.corner_radius)??s.cornerRadius??0;this.drawRoundRect(t,-rt/2,-ft/2,rt,ft,Rt),t.clip()}let K=0;for(s.children.forEach(rt=>{const ft=o.get(rt);if(!ft)return;const Rt=this.objectStates.get(rt),Qt=(Rt==null?void 0:Rt.geometry)||ft.geometry;if(Qt&&Qt.isMask&&(Rt==null?void 0:Rt.visible)!==!1){const Kt=Qt.width||0,ae=Qt.height||0;this.applyObjectTransform(t,rt);const Jt=(Rt==null?void 0:Rt.corner_radius)??(Qt==null?void 0:Qt.corner_radius)??0;this.applyPath(t,Qt,Kt,ae,Jt),t.clip(),K++}else this.renderObject(t,ft,o,e)});K>0;)t.restore(),K--;t.restore()}if(ye){this.maskCtx.restore(),(i.masks||(s.maskedBy?[{maskId:s.maskedBy,inverted:s.maskInverted===!0,type:s.maskType||"alpha",opacity:s.maskOpacity!==void 0?s.maskOpacity/100:1,feather:s.maskFeather||0,isVisible:!0}]:[])).filter(K=>K.isVisible!==!1&&o.has(K.maskId)).forEach(K=>{var Jt,Et,W,nt,Lt,tt;const rt=o.get(K.maskId),ft=this.objectStates.get(rt.id),Rt=K.feather||0,Qt=K.inverted===!0,Kt=K.opacity!==void 0?typeof K.opacity=="number"?K.opacity:K.opacity/100:1;if((K.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,rt.id,o),Rt>0&&(this.lumaCtx.filter=`blur(${Rt}px)`),this.lumaCtx.globalAlpha=Kt;const gt=(ft==null?void 0:ft.width)||rt.geometry.width||0,Q=(ft==null?void 0:ft.height)||rt.geometry.height||0,Ut=(ft==null?void 0:ft.corner_radius)??rt.corner_radius??0;if(((Jt=rt.geometry)==null?void 0:Jt.type)==="Text"){const _t=ft!=null&&ft.geometry?this.deepMerge(rt.geometry,ft.geometry):rt.geometry,Xt=ft!=null&&ft.style?this.deepMerge(rt.style,ft.style):rt.style;this._renderText(this.lumaCtx,rt,{..._t,width:gt,height:Q,corner_radius:Ut},Xt,ft,gt,Q,!0,!1)}else if(((Et=rt.geometry)==null?void 0:Et.type)==="Image"){const _t=rt.geometry.src;if(_t){let Xt=this.imageCache.get(_t);Xt||(Xt=new Image,Xt.src=_t,this.imageCache.set(_t,Xt)),Xt.complete&&Xt.naturalWidth>0?this.lumaCtx.drawImage(Xt,-gt/2,-Q/2,gt,Q):(this.applyPath(this.lumaCtx,rt.geometry,gt,Q,Ut),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else if(((W=rt.geometry)==null?void 0:W.type)==="SVG"){const _t=rt.geometry.svgContent;if(_t){const Xt=`__lumamask_${rt.id}`;let Dt=this.imageCache.get(Xt);if(!Dt){Dt=new Image;const ce=new Blob([_t],{type:"image/svg+xml"});Dt.src=URL.createObjectURL(ce),Dt.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(Xt,Dt)}Dt.complete&&Dt.naturalWidth>0?this.lumaCtx.drawImage(Dt,-gt/2,-Q/2,gt,Q):(this.applyPath(this.lumaCtx,rt.geometry,gt,Q,Ut),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else this.applyPath(this.lumaCtx,rt.geometry,gt,Q,Ut),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill();this.lumaCtx.restore();const zt=this.maskCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight),yt=this.lumaCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight).data,Bt=zt.data;for(let _t=0;_t<Bt.length;_t+=4){const Xt=yt[_t],Dt=yt[_t+1],ce=yt[_t+2];let be=(.299*Xt+.587*Dt+.114*ce)/255;Qt&&(be=1-be),Bt[_t+3]*=be}this.maskCtx.putImageData(zt,0,0)}else{this.maskCtx.save(),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),this.maskCtx.globalCompositeOperation=Qt?"destination-out":"destination-in",Rt>0&&(this.maskCtx.filter=`blur(${Rt}px)`),this.maskCtx.globalAlpha=Kt,this.applyAbsoluteTransform(this.maskCtx,rt.id,o);const gt=(ft==null?void 0:ft.width)||rt.geometry.width||0,Q=(ft==null?void 0:ft.height)||rt.geometry.height||0,Ut=(ft==null?void 0:ft.corner_radius)??rt.corner_radius??0;if(((nt=rt.geometry)==null?void 0:nt.type)==="Text"){const zt=ft!=null&&ft.geometry?this.deepMerge(rt.geometry,ft.geometry):rt.geometry,yt=ft!=null&&ft.style?this.deepMerge(rt.style,ft.style):rt.style;this._renderText(this.maskCtx,rt,{...zt,width:gt,height:Q,corner_radius:Ut},yt,ft,gt,Q,!0,!1)}else if(((Lt=rt.geometry)==null?void 0:Lt.type)==="Image"){const zt=rt.geometry.src;if(zt){let yt=this.imageCache.get(zt);yt||(yt=new Image,yt.src=zt,this.imageCache.set(zt,yt)),yt.complete&&yt.naturalWidth>0?this.maskCtx.drawImage(yt,-gt/2,-Q/2,gt,Q):(this.applyPath(this.maskCtx,rt.geometry,gt,Q,Ut),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else if(((tt=rt.geometry)==null?void 0:tt.type)==="SVG"){const zt=rt.geometry.svgContent;if(zt){const yt=`__alphamask_${rt.id}`;let Bt=this.imageCache.get(yt);if(!Bt){Bt=new Image;const _t=new Blob([zt],{type:"image/svg+xml"});Bt.src=URL.createObjectURL(_t),Bt.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(yt,Bt)}Bt.complete&&Bt.naturalWidth>0?this.maskCtx.drawImage(Bt,-gt/2,-Q/2,gt,Q):(this.applyPath(this.maskCtx,rt.geometry,gt,Q,Ut),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else this.applyPath(this.maskCtx,rt.geometry,gt,Q,Ut),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill();this.maskCtx.restore()}}),de.save(),de.setTransform(1,0,0,1,0,0);const st=s.maskBlendMode||s.blendMode;st&&st!=="Normal"&&(de.globalCompositeOperation=st.toLowerCase()),de.drawImage(this.maskBuffer,0,0),de.restore(),de.restore()}else t.restore()}}applyOuterGlowUnderlay(t,s,o,e,n,i,a,r){var k,O,T;const l=a||s.style||{},d=l.effect,p=l.effects||(d?[d]:[]),g=p.find(A=>A.isEnabled!==!1&&A.type==="Glow"&&(A.mode==="outer"||A.mode==="Outer Glow"||!A.mode));if(!g)return;const u=g.blur||10,f=1e4;let h=g.color||"white";(O=(k=this.artboard)==null?void 0:k.tokens)!=null&&O.colors&&this.artboard.tokens.colors[h]&&(h=this.artboard.tokens.colors[h]),t.save();const m=l.fill&&l.fill.type!=="None",b=p.some(A=>A.isEnabled!==!1&&A.type==="BackgroundBlur"),c=s.type==="Text",S=s.type==="Group";!c&&!S&&(m||b)&&(t.beginPath(),t.rect(-1e6,-1e6,2e6,2e6),s.type==="Frame"||s.type==="Component"?this.drawRoundRect(t,-e/2,-n/2,e,n,i):this._tracePath(t,o,e,n,i),t.clip("evenodd"));const v=t.getTransform();t.shadowColor=h,t.shadowBlur=u,t.shadowOffsetX=f*v.a,t.shadowOffsetY=f*v.b,t.translate(-f,0);let C="black";l.fill&&l.fill.type!=="None"&&(C=this.createCanvasFill(t,l.fill,e,n)||l.fill.color||"black");let w="black";l.stroke&&l.stroke.width>0&&(w=this.createCanvasFill(t,l.stroke.fill||{type:"Solid",color:l.stroke.color},e,n)||l.stroke.color||"black"),t.fillStyle=C,t.strokeStyle=w,t.lineWidth=((T=l.stroke)==null?void 0:T.width)||0;const I=Math.min(g.intensity||1,10);for(let A=0;A<I;A++)if(r)this.renderObject(t,s,r,!0,!0);else if(o.type==="Text")l.fill&&l.fill.type!=="None"&&t.fillText(s.text||"",0,0),l.stroke&&l.stroke.width>0&&t.strokeText(s.text||"",0,0);else if(o.points&&o.type==="Path")this.applyPath(t,o,e,n,i),l.fill&&l.fill.type!=="None"&&t.fill(),l.stroke&&l.stroke.width>0&&t.stroke();else{if(t.beginPath(),o.type==="circle"||o.type==="Ellipse"){const B=e/2,R=n/2;t.ellipse(0,0,B,R,0,0,Math.PI*2)}else i!==0?this.drawRoundRect(t,-e/2,-n/2,e,n,i):t.rect(-e/2,-n/2,e,n);const D=l.fill&&l.fill.type!=="None",Y=l.stroke&&l.stroke.width>0;(D||!D&&!Y)&&t.fill(),Y&&t.stroke()}t.restore()}_renderText(t,s,o,e,n,i,a,r=!1,l=!1){var et,Mt,ct,It,mt,kt,Ot,vt,Wt;let d=(o==null?void 0:o.text)||(s==null?void 0:s.text)||(s==null?void 0:s.name)||"";if(o.textInputId&&!r){const J=this.inputs.get(o.textInputId);J!==void 0&&(d=String(J),n.geometry&&n.geometry.type==="Text"&&(n.geometry.text=d))}if(o.svgPath){const J=o.svgPath;t.save();const ut=((et=e==null?void 0:e.fill)==null?void 0:et.color)||"#000000",$t=((Mt=e==null?void 0:e.fill)==null?void 0:Mt.opacity)!==void 0?(ct=e==null?void 0:e.fill)==null?void 0:ct.opacity:1;t.fillStyle=ut,t.globalAlpha*=$t;const St=new Path2D(J);t.fill(St),t.restore();return}let p=d||"";o.enableSegments===!0&&o.segments&&Array.isArray(o.segments)&&(p=o.segments.map(J=>J&&J.text?J.text:"").join(""));const g=o.textCase||"none";g==="uppercase"?p=p.toUpperCase():g==="lowercase"?p=p.toLowerCase():g==="capitalize"&&(p=p.replace(/\b\w/g,J=>J.toUpperCase()));let u=((It=o.fontWeight)==null?void 0:It.toString())||"400",f=o.fontStyle||"normal";u.toLowerCase().includes("italic")&&(f="italic",u=u.replace(/italic/gi,"").trim()||"400");const h=this.mapFontWeight(u),m=Math.max(1,o.fontSize||32);let b=o.fontFamily||"Inter";const c=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];c.forEach(J=>{const ut=new RegExp(`[\\s-]${J}$`,"i");ut.test(b)&&(b=b.replace(ut,"").trim())});const S=o.smallCaps===!0,C=`${S?"small-caps ":""}${f} ${h} ${m}px "${b}", sans-serif`;t.font=C;const w=o.textVerticalAlign||"top";t.textBaseline="top";const I=o.textAlign||"left";t.textAlign=I;let k=0;if(typeof o.letterSpacing=="number")k=o.letterSpacing;else if(typeof o.letterSpacing=="object"&&o.letterSpacing.value!==void 0){const J=o.letterSpacing;k=J.unit==="PERCENT"?J.value/100*m:J.value}t.letterSpacing!==void 0&&(t.letterSpacing=`${k}px`);const O=o.kerning||"auto",T=o.kerningValue||0;O==="manual"&&T!==0&&(t.letterSpacing=`${k+T}px`);const A=o.paragraphSpacing||0;let D=o.lineHeight??1.2;typeof D=="string"&&(D=parseFloat(D)),D>5&&m>0&&(D=D/m);const Y=(D||1.2)*m,B=o.isPointText===!0||!o.width||o.width<=0,R=((mt=o.padding)==null?void 0:mt.left)||((kt=o.padding)==null?void 0:kt.right)||0,L=B?1e5:o.width&&o.width>0?Math.ceil(o.width)-R*2:1e5;o.autoHeight;const $=ss({text:p,fontFamily:b,fontSize:m,fontWeight:h,fontStyle:f,lineHeight:D,width:L,letterSpacing:k,paragraphSpacing:A,paragraphIndent:o.paragraphIndent||0,segments:o.segments,enableSegments:o.enableSegments,textCase:g,hyphenation:o.hyphenation,composer:o.composer,balanceRaggedLines:o.balanceRaggedLines}),F=$.lines||[],X=$.maxFontSize||m,M=this.fontLeadingFactors[b]??.5,E=(Y-m)*M;let P=$.height,_=i,V=a;if(_===0||V===0||_>=1e5||B){let J=0,ut=0;const $t=$.fullText||p;(F||[]).forEach(St=>{const Pt=St.text||"",Ft=t.measureText(Pt).width+(Pt.length>0?(Pt.length-1)*k:0);Ft>J&&(J=Ft),ut+=Pt.length,ut<$t.length&&($t[ut]===`
8
+ `||$t[ut]==="\r")&&(ut++,$t[ut-1]==="\r"&&$t[ut]===`
9
+ `&&ut++)}),(_===0||_>=1e5)&&(_=J),V===0&&(V=P||0)}let G=-P/2;a>0&&a>P&&(w==="top"?G=-a/2:w==="middle"||w==="center"?G=-P/2:w==="bottom"&&(G=a/2-P));const x=w==="top"&&a>0?0:E;let U=G+x+E,q=null,N=0;if(o.pathId&&this.artboard){const J=this.artboard.objects.find(ut=>ut.id===o.pathId);if(J&&J.type==="Shape"&&((Ot=J.geometry)==null?void 0:Ot.type)==="Path"){const ut=this.objectStates.get(J.id),$t=ut!=null&&ut.geometry?this.deepMerge(J.geometry,ut.geometry):J.geometry,St=(ut==null?void 0:ut.scale_x)!==void 0?(J.width||0)*ut.scale_x:J.width||0,Pt=(ut==null?void 0:ut.scale_y)!==void 0?(J.height||0)*ut.scale_y:J.height||0;q={geo:$t,obj:J,w:St,h:Pt},N=this.getPerimeter($t,St,Pt)}}const H=(J,ut)=>{var St,Pt;if(!k&&!S&&!r&&(!o.enableSegments||!((St=o.segments)!=null&&St.length)))return t.measureText(J).width;let $t=0;for(let Ft=0;Ft<J.length;Ft++){const lt=ut+Ft;let ht=0;if(o.enableSegments===!0&&((Pt=o.segments)==null?void 0:Pt.length)>0){let dt=0,At=null;for(const Tt of o.segments){if(lt<dt+(Tt.text||"").length){At=Tt;break}dt+=(Tt.text||"").length}if(At){t.save();let Tt=At.fontFamily||o.fontFamily||"Inter";const Ct=this.mapFontWeight((At.fontWeight||o.fontWeight||"400").toString()),Yt=At.fontStyle||f,ie=At.fontSize||m;t.font=`${Yt} ${Ct} ${ie}px "${Tt}", sans-serif`,ht=t.measureText(J[Ft]).width,t.restore()}else ht=t.measureText(J[Ft]).width}else ht=t.measureText(J[Ft]).width;$t+=ht+k}return $t-(J.length>0?k:0)},z=(J,ut,$t,St,Pt)=>{var ie,te;const lt=(Pt===0||p[Pt-1]===`
10
+ `||p[Pt-1]==="\r")&&o.paragraphIndent?o.paragraphIndent:0,ht=(!r||l)&&(s.behaviors||[]).some(Zt=>Zt.enabled&&(Zt.type.toString().includes("Text")||["Typewriter","Scramble","Wave","Bounce","GlitchText","Reveal3D","RevealSlide","RevealBlur"].includes(Zt.type))),dt=!o.pathId&&!ht&&(o.enableSegments!==!0||!o.segments||o.segments.length===0),At=o.baselineShift||0,Tt=$t+At,Ct=H(J,Pt);let Yt=ut+lt;if(I==="center"?Yt-=Ct/2:I==="right"&&(Yt-=Ct),dt){t.font=C;const Zt=t.textAlign;t.textAlign="left",St?t.strokeText(J,Yt,Tt):t.fillText(J,Yt,Tt),t.textAlign=Zt}else{const Zt=t.textAlign;t.textAlign="left";const le=Pt+J.length>=p.length||p[Pt+J.length]===`
11
+ `||p[Pt+J.length]==="\r";let fe=0,qt=0;const Se=o.justifyMinWordSpacing,Ce=o.justifyMaxWordSpacing;if(I==="justify"&&!le&&Ct>0&&!o.pathId){const ye=B?Ct:L-R*2+0,ke=Math.max(0,ye-Ct);for(let Vt=0;Vt<J.length;Vt++)J[Vt]===" "&&qt++;if(qt>0){const Vt=t.measureText(" ").width;let ee=Se||Vt*.5,j=Ce||Vt*2.5;fe=Math.max(0,Math.min(ke/qt,j-ee))}}let Ie=o.pathOffset||0;o.pathId&&N>0&&q&&(I==="center"?Ie+=N/2-Ct/2:I==="right"&&(Ie+=N-Ct));let de=Yt;const Re=r&&!l?[]:((ie=s.behaviors)==null?void 0:ie.filter(ye=>[it.Typewriter,it.Scramble,it.Wave,it.Bounce,it.GlitchText,it.TextTrail,it.Reveal3D,it.RevealSlide,it.RevealBlur,it.TextLiquid,it.TextVortex,it.TextExplosion,it.TextRain,it.TextGravity,it.TextElastic,it.TextMatrix,it.TextNeon,it.TextGlitch3D,it.TextDissolve,it.TextOrganic,it.TextBreathe,it.TextFloral,it.TextSmoke,it.TextVariable,it.TextMagnet,it.TextSpin,it.TextZing,it.TextPerspective,it.TextMirror].includes(ye.type)&&ye.enabled))||[];for(let ye=0;ye<J.length;ye++){let ke=J[ye];const Vt=Pt+ye;let ee=0,j=0,bt=1,st=1,K=0,rt=1,ft=ke;Re.forEach(Et=>{const W=Et.settings||{},nt=W.strength||1,Lt=Date.now();if(Et.type===it.Typewriter)this.currentTime*(W.speed||1)-Vt*(W.stagger||.05)<0&&(rt=0);else if(Et.type===it.Scramble)Math.max(0,Math.min(1,this.currentTime/(W.duration||1.5))-Vt*.02)<1&&Math.random()<.3&&(ft="$%#@!*&"[Math.floor(Math.random()*7)]);else if(Et.type===it.Wave)j+=Math.sin(this.currentTime*5*(W.speed||1)+Vt*(W.frequency||1))*(W.amplitude||20)*nt;else if(Et.type===it.Bounce){const tt=Math.max(0,this.currentTime%2-Vt*(W.stagger||.1));tt<1&&(j-=Math.abs(Math.sin(tt*Math.PI))*(W.height||50)*nt)}else if(Et.type===it.TextTrail){const tt=this.pointerHistory[Math.max(0,this.pointerHistory.length-1-Vt*(W.delay||5))];tt&&(ee+=(tt.x-(n.x+de))*nt*.2,j+=(tt.y-(n.y+$t+j))*nt*.2)}else if(Et.type===it.Reveal3D){const tt=Math.max(0,Math.min(1,this.currentTime*(W.speed||1)-Vt*(W.stagger||.1)));bt*=tt,st*=tt,rt=tt}else if(Et.type===it.RevealSlide){const tt=Math.max(0,Math.min(1,this.currentTime*1.5-Vt*.05)),gt=(1-tt)*(W.distance||40)*nt,Q=W.direction||"up";Q==="up"?j-=gt:Q==="down"?j+=gt:Q==="left"?ee-=gt:Q==="right"&&(ee+=gt),rt=tt}else if(Et.type===it.RevealBlur){const tt=Math.max(0,Math.min(1,this.currentTime*1.2-Vt*.1));rt=tt,ee+=(1-tt)*5}else if(Et.type===it.TextLiquid){const tt=Math.max(0,Math.sin(Lt*.001*(W.speed||1)+Vt*.5));j+=tt*(W.amplitude||10)*nt,st*=1+tt*.2}else if(Et.type===it.TextVortex){const tt=Lt*.002*(W.speed||1)+Vt*.2,gt=(1-(Math.sin(Lt*.001)*.5+.5))*(W.radius||50);ee+=Math.cos(tt)*gt*nt,j+=Math.sin(tt)*gt*nt}else if(Et.type===it.TextExplosion){const tt=W.force||1,gt=this.currentTime%2;if(gt<1){const Q=(Vt/J.length-.5)*Math.PI*2,Ut=gt*100*tt;ee+=Math.cos(Q)*Ut*nt,j+=Math.sin(Q)*Ut*nt,rt=1-gt}}else if(Et.type===it.TextRain){const tt=W.speed||1,gt=W.height||100,Q=(Lt*.001*tt+Vt*.1)%1;j-=(1-Q)*gt*nt,rt=Q>.1?1:Q*10}else if(Et.type===it.TextGravity){const tt=W.gravity||9.8,gt=this.currentTime%3/3,Q=.5*tt*Math.pow(gt*10,2);Q<100?j+=Q*nt:j+=100*nt}else if(Et.type===it.TextMatrix){const tt=W.speed||1;if(Math.random()<.1*tt){const Q="0123456789ABCDEF!@#$%^&*";ft=Q[Math.floor(Math.random()*Q.length)]}rt=.3+(Math.sin(Lt*.01*tt+Vt)+1)/2*.7}else if(Et.type===it.TextNeon){const tt=Math.random()>.95?.5:1;rt=(.7+(Math.sin(Lt*.005)+1)/2*.3)*tt}else if(Et.type===it.TextDissolve)Math.sin(Vt*1.5+Lt*.002*(W.speed||1))>.5&&(rt=0);else if(Et.type===it.TextOrganic){const tt=W.speed||1,gt=W.amplitude||10;ee+=Math.sin(Lt*.002*tt+Vt)*gt*nt,j+=Math.cos(Lt*.0015*tt+Vt*.7)*gt*nt}else if(Et.type===it.TextBreathe){const gt=1+(Math.sin(Lt*.003+Vt*.2)+1)/2*.2*nt;bt*=gt,st*=gt}else if(Et.type===it.TextSpin){const tt=W.speed||1;K+=Lt*.01*tt+Vt}else if(Et.type===it.TextMagnet){const tt=this.pointerHistory[this.pointerHistory.length-1];if(tt){const gt=tt.x-(n.x+de),Q=tt.y-(n.y+$t);K=Math.atan2(Q,gt)}}else if(Et.type===it.TextPerspective){const tt=J.length/2,gt=(Vt-tt)/tt,Q=1-Math.abs(gt)*.3*nt;bt*=Q,st*=Q,ee+=gt*20*nt}else if(Et.type===it.TextMirror)rt*=.8;else if(Et.type===it.TextFloral){const tt=W.speed||1,gt=W.stagger||.1,Q=(Lt*.001*tt+Vt*gt)%2;Q<1&&(bt*=Q,st*=Q,K+=Q*Math.PI)}else if(Et.type===it.TextSmoke){const tt=W.speed||1,gt=W.height||50,Q=(Lt*5e-4*tt+Vt*.2)%1;j-=Q*gt*nt,ee+=Math.sin(Lt*.002+Vt)*5*nt,rt=1-Q}else if(Et.type===it.TextVariable){const tt=W.speed||1,gt=W.intensity||1.5,Q=(Math.sin(Lt*.004*tt+Vt*.3)+1)/2;bt*=1+Q*(gt-1)*nt}else if(Et.type===it.TextZing){const tt=W.speed||2,gt=W.distance||100,Q=(Lt*.002*tt+Vt*.05)%1;ee+=(1-Q)*gt*nt,rt=Q}else if(Et.type===it.TextElastic){const tt=W.stiffness||.2,gt=W.damping||.1,Q=Math.sin(Lt*.01)*Math.exp(-Lt*.001*gt);st*=1+Q*tt*nt}else if(Et.type===it.TextGlitch3D){const tt=W.intensity||5;Math.random()<.2&&(ee+=(Math.random()-.5)*tt,j+=(Math.random()-.5)*tt,rt=.8)}else if(Et.type===it.GlitchText){const tt=W.intensity||5;Math.random()<.1&&(ee+=(Math.random()-.5)*tt,j+=(Math.random()-.5)*tt,Math.random()<.05&&(rt=.5))}});let Rt=null,Qt=o.textDecoration||"none",Kt=m;if(o.enableSegments===!0&&((te=o.segments)==null?void 0:te.length)>0){let Et=0,W=null;for(const nt of o.segments){if(Vt<Et+(nt.text||"").length){W=nt;break}Et+=(nt.text||"").length}if(W){let nt=W.fontFamily||o.fontFamily||"Inter";c.forEach(gt=>{const Q=new RegExp(`[\\s-]${gt}$`,"i");Q.test(nt)&&(nt=nt.replace(Q,"").trim())});const Lt=this.mapFontWeight((W.fontWeight||o.fontWeight||"400").toString()),tt=W.fontStyle||f;Kt=W.fontSize||m,t.font=`${tt} ${Lt} ${Kt}px "${nt}", sans-serif`,W.fill&&(Rt=W.fill),W.textDecoration&&(Qt=W.textDecoration),Kt<X&&(j+=(X-Kt)*.85)}}else t.font=C;const ae=t.globalAlpha;t.globalAlpha*=rt,t.save();const Jt=t.measureText(ft).width;if(q&&N>0){const Et=de-Yt+Jt/2,nt=(Ie+Et)/N,Lt=this.getPointOnPath(q.geo,q.w,q.h,Math.abs(nt%1)),tt=Lt.angle,gt=$t+j+(o.pathOffsetY||0),Q=o.pathSide==="right"?-1:1,Ut=Math.cos(tt+Math.PI/2)*gt*Q,zt=Math.sin(tt+Math.PI/2)*gt*Q;t.translate(Lt.x+Ut+ee,Lt.y+zt),t.rotate(tt+K+(Q===-1?Math.PI:0))}else t.translate(de+ee+Jt/2,$t+j),K!==0&&t.rotate(K);if(t.scale(bt,st),Rt&&!r&&!l){const Et=this.createCanvasFill(t,Rt,_,V);t.fillStyle=Et||Rt.color||"#000000"}else if(!r&&!l){const Et=this.createCanvasFill(t,e.fill,_,V);t.fillStyle=Et||e.fill.color||"#000000"}if(rt>0)if(r||l){const Et=l?"#000000":this.createCanvasFill(t,e.fill,_,V);t.fillStyle=Et||e.fill.color||"#ffffff",t.fillText(ft,-Jt/2,0)}else St?t.strokeText(ft,-Jt/2,0):t.fillText(ft,-Jt/2,0);Qt!=="none"&&!r&&this.drawTextDecoration(t,Qt,0,0,Jt,Kt),t.restore(),t.globalAlpha=ae,I==="justify"&&fe>0&&ft===" "&&!le?de+=Jt+k+fe:de+=Jt+k}t.textAlign=Zt}};if(r){let J=0,ut=U;(F||[]).forEach($t=>{const St=$t.text||"",Pt=p.indexOf(St,J);Pt!==-1&&(J=Pt);let Ft=-_/2;I==="center"?Ft=0:I==="right"&&(Ft=_/2),z(St,Ft,ut,!1,J),J+=St.length,ut+=Y})}else if(l){let J=0,ut=U;(F||[]).forEach($t=>{const St=$t.text||"";let Pt=-_/2;I==="center"?Pt=0:I==="right"&&(Pt=_/2),z(St,Pt,ut,!1,J),J+=St.length,J<p.length&&(p[J]===`
12
+ `||p[J]==="\r")&&(J++,p[J-1]==="\r"&&p[J]===`
13
+ `&&J++),ut+=Y})}else{if(e.fill){const ut=t.globalAlpha,$t=this.createCanvasFill(t,e.fill,_,V);t.fillStyle=$t||e.fill.color||"#000000",t.globalAlpha=ut*this.normalizeOpacity(e.fill.opacity??100);const St=$.fullText||(o.enableSegments?(o.segments||[]).map(lt=>{let ht=lt.text||"";const dt=lt.textCase||o.textCase||"none";return dt==="uppercase"?ht.toUpperCase():dt==="lowercase"?ht.toLowerCase():dt==="capitalize"?ht.replace(/\b\w/g,At=>At.toUpperCase()):ht}).join(""):p);let Pt=0,Ft=U;(F||[]).forEach(lt=>{const ht=lt.text||"";let dt=-_/2;I==="center"?dt=0:I==="right"&&(dt=_/2),z(ht,dt,Ft,!1,Pt),Pt+=ht.length,Ft+=Y,Pt<St.length&&(St[Pt]===`
14
+ `||St[Pt]==="\r")&&(A>0&&(Ft+=A),Pt++,St[Pt-1]==="\r"&&St[Pt]===`
15
+ `&&Pt++)}),t.globalAlpha=ut}const J=o.paragraphRule;if(J&&(((vt=J.top)==null?void 0:vt.width)>0||((Wt=J.bottom)==null?void 0:Wt.width)>0)){let ut=0;(F||[]).forEach(($t,St)=>{var lt,ht;const Ft=ut===0||ut<p.length&&(p[ut]===`
16
+ `||p[ut]==="\r");if(Ft&&St>0&&ut++,Ft){if(((lt=J.top)==null?void 0:lt.width)>0){const dt=U+St*Y-J.top.offset;t.strokeStyle=J.top.color||"#000000",t.lineWidth=J.top.width,t.beginPath();const At=-i/2+Y*.2;t.moveTo(At,dt),t.lineTo(i/2-Y*.2,dt),t.stroke()}if(((ht=J.bottom)==null?void 0:ht.width)>0){const dt=U+(St+1)*Y-J.bottom.offset;t.strokeStyle=J.bottom.color||"#000000",t.lineWidth=J.bottom.width,t.beginPath();const At=-i/2+Y*.2;t.moveTo(At,dt),t.lineTo(i/2-Y*.2,dt),t.stroke()}}ut+=($t.text||"").length})}if(e.stroke&&e.stroke.width>0){const ut=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;const St=t.getTransform(),Pt=Math.sqrt(St.a*St.a+St.b*St.b)||1,Ft=window.devicePixelRatio||1;t.lineWidth=(e.stroke.width||1)*Ft/Pt,t.globalAlpha=ut*this.normalizeOpacity(e.stroke.opacity??100);let lt=0,ht=U;(F||[]).forEach(dt=>{let At=-_/2;I==="center"?At=0:I==="right"&&(At=_/2),z(dt.text,At,ht,!0,lt),lt+=(dt.text||"").length,ht+=Y,lt<p.length&&(p[lt]===`
17
+ `||p[lt]==="\r")&&(A>0&&(ht+=A),lt++,p[lt-1]==="\r"&&p[lt]===`
18
+ `&&lt++)}),t.globalAlpha=ut}}}applyStrokeAlignment(t,s,o,e,n,i){if(!s.stroke||s.stroke.width<=0||s.stroke.isEnabled===!1)return;const a=s.stroke,r=t.getTransform(),l=Math.sqrt(r.a*r.a+r.b*r.b)||1,d=window.devicePixelRatio||1,p=(a.width||1)*d/l,g=(a.alignment||"center").toLowerCase();if(t.save(),s.fill&&s.fill.type!=="None"&&s.fill.isEnabled!==!1&&s.fill.opacity!==0&&s.fill.color!=="transparent"&&s.fill.color!=="rgba(0,0,0,0)"&&(t.shadowColor="transparent",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),a.fill){const v=this.createCanvasFill(t,a.fill,e,n);v?t.strokeStyle=v:t.strokeStyle=a.color||"#000000"}else t.strokeStyle=a.color||"#000000";const f=t.globalAlpha;t.globalAlpha=f*this.normalizeOpacity(a.opacity??100),t.lineWidth=p,t.lineCap=a.lineCap||"round",t.lineJoin=a.lineJoin||"round",a.miterLimit!==void 0&&(t.miterLimit=a.miterLimit);const h=a.trimStart??0,m=a.trimEnd??1,b=a.trimOffset??0,c=a.dashOffset??0,S=a.dashArray||[];if(h!==0||m!==1||b!==0){const v=this.getPerimeter(o,e,n);if(v>0){const C=Math.max(0,Math.min(1,h)),w=Math.max(0,Math.min(1,m));if(C<w){const I=v*(w-C),k=v-I,O=-(v*(C+b%1));t.setLineDash([I,k]),t.lineDashOffset=O-c*v}else if(C===w)t.setLineDash([0,v]);else{const I=v*(1-C+w),k=v-I,O=-(v*C);t.setLineDash([I,k]),t.lineDashOffset=O-c*v}}}else if(S.length>0||c!==0){S.length>0&&t.setLineDash(S);const v=this.getPerimeter(o,e,n);t.lineDashOffset=-(c*v)}if((o==null?void 0:o.type)==="Line"||e===0||n===0)this.applyPath(t,o,e,n,i),t.stroke();else if(g==="inside")t.lineWidth=p*2,t.save(),this.applyPath(t,o,e,n,i),t.clip(),t.stroke(),t.restore();else if(g==="outside"){t.save(),t.beginPath();const v=Math.max(e,n,2e4);t.rect(-v,-v,v*2,v*2),this._tracePath(t,o,e,n,i),t.clip("evenodd"),t.lineWidth=p*2,t.beginPath(),this.applyPath(t,o,e,n,i),t.stroke(),t.restore()}else t.lineWidth=p,this.applyPath(t,o,e,n,i),t.stroke();t.restore()}getPerimeter(t,s,o){switch(this.ensurePathPoints(t),t==null?void 0:t.type){case"Rectangle":return(s+o)*2;case"Ellipse":{const e=Math.abs(s)/2,n=Math.abs(o)/2,i=Math.abs(t.sweepAngle??360),a=t.ratio||0,r=Math.PI*(3*(e+n)-Math.sqrt((3*e+n)*(e+3*n)));if(i>=360&&a<=0)return r;let l=i/360*r;if(a>0){const d=Math.PI*(3*(e*a+n*a)-Math.sqrt((3*e*a+n*a)*(e*a+3*n*a)));l+=i/360*d,i<360&&(l+=2*Math.sqrt((e-e*a)**2+(n-n*a)**2))}else i<360&&(l+=2*Math.max(e,n));return isNaN(l)?0:l}case"Line":return t.length||Math.sqrt(s*s+o*o);case"Triangle":return s+Math.sqrt((s/2)**2+o**2)*2;case"Polygon":{const e=t.sides||3,n=t.radius||Math.min(s,o)/2;return 2*e*n*Math.sin(Math.PI/e)}case"Star":{const e=t.points||5,n=t.outer_radius||Math.min(s,o)/2,i=t.inner_radius||n/2,a=Math.PI/e;return Math.sqrt(n*n+i*i-2*n*i*Math.cos(a))*e*2}case"Path":{const e=t.points||[];if(e.length<2)return t.length||0;let n=0,i=e[0].x,a=e[0].y;for(let r=1;r<e.length;r++){const l=e[r];if(l.moveTo){i=l.x,a=l.y;continue}const d=i,p=a,g=e[r-1].out_x,u=e[r-1].out_y;if(g!==void 0||l.in_x!==void 0?n+=this.getBezierLength(d,p,g??d,u??p,l.in_x??l.x,l.in_y??l.y,l.x,l.y):n+=Math.sqrt((l.x-d)**2+(l.y-p)**2),i=l.x,a=l.y,l.closePath||r===e.length-1&&(t.is_closed||t.isClosed)){const f=i,h=a,m=[...e.slice(0,r+1)].reverse().find(I=>I.moveTo)||e[0],b=m.x,c=m.y,S=e[r].out_x,v=e[r].out_y,C=m.in_x,w=m.in_y;S!==void 0||C!==void 0?n+=this.getBezierLength(f,h,S??f,v??h,C??b,w??c,b,c):n+=Math.sqrt((b-f)**2+(c-h)**2)}}return n}default:return(s+o)*2}}getBezierLength(t,s,o,e,n,i,a,r,l=10){let d=0,p=t,g=s;for(let u=1;u<=l;u++){const f=u/l,h=1-f,m=f*f,b=h*h,c=b*h,S=m*f,v=c*t+3*b*f*o+3*h*m*n+S*a,C=c*s+3*b*f*e+3*h*m*i+S*r,w=v-p,I=C-g;d+=Math.sqrt(w*w+I*I),p=v,g=C}return d}getBezierTAtLength(t,s,o,e,n,i,a,r,l,d=20){if(t<=0)return 0;let p=0,g=s,u=o;for(let f=1;f<=d;f++){const h=f/d,m=1-h,b=h*h,c=m*m,S=c*m,v=b*h,C=S*s+3*c*h*e+3*m*b*i+v*r,w=S*o+3*c*h*n+3*m*b*a+v*l,I=C-g,k=w-u,O=Math.sqrt(I*I+k*k);if(p+O>=t){const T=t-p,A=O===0?0:T/O;return(f-1+A)/d}p+=O,g=C,u=w}return 1}getPointOnPath(t,s,o,e){if(this.ensurePathPoints(t),(t==null?void 0:t.type)==="Path"){const n=t.points||[];if(n.length<2)return{x:0,y:0,angle:0};let i=1/0,a=-1/0,r=1/0,l=-1/0;n.forEach(c=>{typeof c.x=="number"&&typeof c.y=="number"&&(i=Math.min(i,c.x),a=Math.max(a,c.x),r=Math.min(r,c.y),l=Math.max(l,c.y),c.out_x!==void 0&&(i=Math.min(i,c.out_x),a=Math.max(a,c.out_x)),c.out_y!==void 0&&(r=Math.min(r,c.out_y),l=Math.max(l,c.out_y)),c.in_x!==void 0&&(i=Math.min(i,c.in_x),a=Math.max(a,c.in_x)),c.in_y!==void 0&&(r=Math.min(r,c.in_y),l=Math.max(l,c.in_y)))});const d=(i+a)/2,p=(r+l)/2,u=this.getPerimeter(t,s,o)*e;let f=0;const h=[];let m=n[0],b=n[0];for(let c=1;c<n.length;c++){const S=n[c];if(S.moveTo){m=S,b=S;continue}h.push({p0:m,p1:S}),(S.closePath||c===n.length-1&&(t.is_closed||t.isClosed))&&h.push({p0:S,p1:b}),m=S}for(const c of h){const S=c.p0,v=c.p1;let C=0;const w=S.out_x!==void 0||v.in_x!==void 0;if(w?C=this.getBezierLength(S.x,S.y,S.out_x??S.x,S.out_y??S.y,v.in_x??v.x,v.in_y??v.y,v.x,v.y):C=Math.sqrt((v.x-S.x)**2+(v.y-S.y)**2),f+C>=u||c===h[h.length-1]){let I=0;if(w)return I=this.getBezierTAtLength(u-f,S.x,S.y,S.out_x??S.x,S.out_y??S.y,v.in_x??v.x,v.in_y??v.y,v.x,v.y,20),this.getBezierPointAndAngle(I,S,v,d,p);{I=C===0?0:(u-f)/C;const k=S.x+(v.x-S.x)*I-d,O=S.y+(v.y-S.y)*I-p,T=Math.atan2(v.y-S.y,v.x-S.x);return{x:k,y:O,angle:T}}}f+=C}}else if(t.type==="Ellipse"){const n=Math.abs(s)/2,i=Math.abs(o)/2,a=t.sweepAngle??360,l=((t.startAngle??0)+a*e)*Math.PI/180,d=n*Math.cos(l),p=i*Math.sin(l),g=-n*Math.sin(l),u=i*Math.cos(l),f=Math.atan2(u,g);return{x:d,y:p,angle:f}}else if((t==null?void 0:t.type)==="Rectangle"){const n=Math.abs(s),i=Math.abs(o),r=(n+i)*2*e;let l=0,d=0,p=0;return r<n?(l=-n/2+r,d=-i/2,p=0):r<n+i?(l=n/2,d=-i/2+(r-n),p=Math.PI/2):r<2*n+i?(l=n/2-(r-(n+i)),d=i/2,p=Math.PI):(l=-n/2,d=i/2-(r-(2*n+i)),p=-Math.PI/2),{x:l,y:d,angle:p}}return{x:0,y:0,angle:0}}getBezierPointAndAngle(t,s,o,e,n){const i=s.x,a=s.y,r=s.out_x??s.x,l=s.out_y??s.y,d=o.in_x??o.x,p=o.in_y??o.y,g=o.x,u=o.y,f=1-t,h=t*t,m=f*f,b=m*f,c=h*t,S=b*i+3*m*t*r+3*f*h*d+c*g-e,v=b*a+3*m*t*l+3*f*h*p+c*u-n,C=3*m*(r-i)+6*f*t*(d-r)+3*h*(g-d),w=3*m*(l-a)+6*f*t*(p-l)+3*h*(u-p),I=Math.atan2(w,C);return{x:S,y:v,angle:I}}applyAbsoluteTransform(t,s,o){if(!o.get(s))return;const n=[];let i=s;for(;i;){n.unshift(i);const a=o.get(i);i=a==null?void 0:a.parentId}n.forEach(a=>{this.applyObjectTransform(t,a)})}applyObjectTransform(t,s){var f,h,m;const o=this.objectStates.get(s);if(!o)return;t.translate(o.x,o.y),t.rotate((o.rotation??0)*Math.PI/180);const e=o.skew_x||0,n=o.skew_y||0;if(e!==0||n!==0){const b=Math.tan(e*Math.PI/180),c=Math.tan(n*Math.PI/180);t.transform(1+b*c,c,b,1,0,0)}const i=o.rotate_x!==void 0?o.rotate_x:((f=o.transform)==null?void 0:f.rotate_x)??0,a=o.rotate_y!==void 0?o.rotate_y:((h=o.transform)==null?void 0:h.rotate_y)??0,l=1+(o.translate_z!==void 0?o.translate_z:((m=o.transform)==null?void 0:m.translate_z)??0)/1e3,d=(o.flip_x===!0?-1:1)*Math.cos(a*Math.PI/180)*l,p=(o.flip_y===!0?-1:1)*Math.cos(i*Math.PI/180)*l,g=(o.scale_x??1)*d,u=(o.scale_y??1)*p;t.scale(g,u)}applyInnerGlowOverlay(t,s,o,e,n,i,a){var b,c;const r=a||s.style||{},l=r==null?void 0:r.effect,p=((r==null?void 0:r.effects)||(l?[l]:[])).find(S=>S.isEnabled!==!1&&S.type==="Glow"&&(S.mode==="inner"||S.mode==="Inner Glow"));if(!p)return;t.save(),t.beginPath(),this.applyPath(t,o,e,n,i),t.clip();const g=p.blur||10,u=1e4,f=t.getTransform();let h=p.color||"white";(c=(b=this.artboard)==null?void 0:b.tokens)!=null&&c.colors&&this.artboard.tokens.colors[h]&&(h=this.artboard.tokens.colors[h]),t.shadowColor=h,t.shadowBlur=g,t.shadowOffsetX=u*f.a,t.shadowOffsetY=u*f.b,t.translate(-u,0),t.lineWidth=g+5,t.strokeStyle=h;const m=Math.min(p.intensity||1,5);for(let S=0;S<m;S++)t.beginPath(),this.applyPath(t,o,e,n,i),t.stroke();t.restore()}applyArtEffectOverlay(t,s,o,e,n,i){var u,f,h,m,b;const a=this.objectStates.get(s.id),r=((u=a==null?void 0:a.style)==null?void 0:u.artEffect)||s.artEffect||((f=s.style)==null?void 0:f.artEffect);if(!r||!r.enabled)return;const l=r.type,d=r.intensity??.5,p=r.speed??1,g=r.scale??10;if(l==="acid_gradient"||l==="acid_rave"||l==="shimmer"||l==="glint_overlay"||l==="halftone"||l==="noise"||l==="scanlines"||l==="chromatic_aberration"||l==="pixelate"||l==="glitch"||l==="fold_overlay"||l==="crumple_overlay"){if(t.save(),this.applyPath(t,o,e,n,i),t.clip(),l==="shimmer"){const S=this.currentTime*p%2/2,v=t.createLinearGradient(-e,-n,e,n);v.addColorStop(Math.max(0,S-.2),"rgba(255,255,255,0)"),v.addColorStop(S,`rgba(255,255,255,${d*.8})`),v.addColorStop(Math.min(1,S+.2),"rgba(255,255,255,0)"),t.fillStyle=v,t.globalCompositeOperation="screen",t.fillRect(-e/2,-n/2,e,n),t.globalCompositeOperation="source-over"}else if(l==="glint_overlay"){let v=((this._lastPointerPos||{x:0}).x-(((h=s.transform)==null?void 0:h.x)??0)+300)/600;v=Math.max(-.2,Math.min(1.2,v));const C=t.createLinearGradient(-e,-n,e,n);C.addColorStop(Math.max(0,v-.15),"rgba(255,255,255,0)"),C.addColorStop(Math.max(0,Math.min(1,v)),`rgba(255,255,255,${d})`),C.addColorStop(Math.min(1,v+.15),"rgba(255,255,255,0)"),t.fillStyle=C,t.globalCompositeOperation="screen",t.fillRect(-e/2,-n/2,e,n),t.globalCompositeOperation="source-over"}else if(l==="fold_overlay"){const c=this._lastPointerPos||{x:0,y:0},S=c.x-(((m=s.transform)==null?void 0:m.x)??0),v=c.y-(((b=s.transform)==null?void 0:b.y)??0),C=t.createLinearGradient(S>0?-e/2:e/2,v>0?-n/2:n/2,S>0?e/2:-e/2,v>0?n/2:-n/2);C.addColorStop(0,`rgba(0,0,0,${d*.6})`),C.addColorStop(.4,"rgba(0,0,0,0)"),C.addColorStop(.5,`rgba(255,255,255,${d*.4})`),C.addColorStop(1,`rgba(0,0,0,${d*.2})`),t.fillStyle=C,t.globalCompositeOperation="overlay",t.fillRect(-e/2,-n/2,e,n),t.globalCompositeOperation="source-over",t.beginPath(),S>0&&v>0?(t.moveTo(e/2-40,n/2),t.lineTo(e/2,n/2-40),t.lineTo(e/2-40,n/2-40)):S<0&&v>0?(t.moveTo(-e/2+40,n/2),t.lineTo(-e/2,n/2-40),t.lineTo(-e/2+40,n/2-40)):S>0&&v<0?(t.moveTo(e/2-40,-n/2),t.lineTo(e/2,-n/2+40),t.lineTo(e/2-40,-n/2+40)):(t.moveTo(-e/2+40,-n/2),t.lineTo(-e/2,-n/2+40),t.lineTo(-e/2+40,-n/2+40)),t.closePath(),t.fillStyle="#ffffff",t.shadowColor="rgba(0,0,0,0.5)",t.shadowBlur=10,t.shadowOffsetX=S>0?-2:2,t.shadowOffsetY=v>0?-2:2,t.fill()}else if(l==="crumple_overlay"){const c=Math.floor(e/g),S=document.createElement("canvas");S.width=c,S.height=Math.floor(n/g);const v=S.getContext("2d"),C=v.createImageData(S.width,S.height);for(let w=0;w<C.data.length;w+=4){const I=Math.random()>.95?150:255;C.data[w]=I,C.data[w+1]=I,C.data[w+2]=I,C.data[w+3]=255*d}v.putImageData(C,0,0),t.globalCompositeOperation="multiply",t.imageSmoothingEnabled=!1,t.drawImage(S,-e/2,-n/2,e,n)}else if(l==="acid_gradient"||l==="acid_rave"){const c=this.currentTime*p,S=r.color1,v=r.color2,C=t.createLinearGradient(-e/2,-n/2,e/2,n/2);if(S&&v){const w=c*60%360;C.addColorStop(0,this._shiftHue(S,w,d*.7)),C.addColorStop(1,this._shiftHue(v,(w+180)%360,d*.7))}else{const w=c*100%360,I=(w+180)%360;C.addColorStop(0,`hsla(${w}, 80%, 50%, ${d*.5})`),C.addColorStop(1,`hsla(${I}, 80%, 50%, ${d*.5})`)}t.fillStyle=C,t.globalCompositeOperation="screen",t.fillRect(-e/2,-n/2,e,n)}else if(l==="halftone"){const c=Math.max(2,g*(1-d*.8)),S=document.createElement("canvas");S.width=c,S.height=c;const v=S.getContext("2d");if(v){v.fillStyle="black",v.beginPath(),v.arc(c/2,c/2,c/2*d,0,Math.PI*2),v.fill();const C=t.createPattern(S,"repeat");C&&(t.globalAlpha=.3*d,t.fillStyle=C,t.fillRect(-e/2,-n/2,e,n))}}else if(l==="noise"){const c=Math.floor(e*n*d*.02);t.globalAlpha=.4*d;for(let S=0;S<c;S++){const v=Math.random()>.5?255:0;t.fillStyle=`rgba(${v}, ${v}, ${v}, ${.5+Math.random()*.5})`,t.fillRect(-e/2+Math.random()*e,-n/2+Math.random()*n,2,2)}}else if(l==="scanlines"){t.globalAlpha=.2*d,t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1;for(let c=-n/2;c<n/2;c+=4)t.beginPath(),t.moveTo(-e/2,c),t.lineTo(e/2,c),t.stroke()}else if(l==="chromatic_aberration"){const c=5*d;t.globalCompositeOperation="screen",t.globalAlpha=.5,t.fillStyle="cyan",t.fillRect(-e/2-c,-n/2,e,n),t.fillStyle="magenta",t.fillRect(-e/2+c,-n/2,e,n)}else if(l==="pixelate"){const c=Math.max(2,Math.round(g*(1-d*.5))),S=document.createElement("canvas"),v=Math.max(1,Math.ceil(e/c)),C=Math.max(1,Math.ceil(n/c));S.width=v,S.height=C;const w=S.getContext("2d");if(w){w.imageSmoothingEnabled=!1;const I=t.getTransform(),k=I.e-e/2,O=I.f-n/2;w.drawImage(t.canvas,k,O,e,n,0,0,v,C),t.imageSmoothingEnabled=!1,t.drawImage(S,0,0,v,C,-e/2,-n/2,e,n),t.imageSmoothingEnabled=!0}}else if(l==="glitch"){const c=this.currentTime*p,S=r.chaosAmount??.2,v=Math.max(3,Math.floor(8*d)),C=d*e*.15;t.globalCompositeOperation="screen",t.globalAlpha=d*.4;const w=C*.3;t.fillStyle="rgba(255, 0, 0, 0.4)",t.fillRect(-e/2+w,-n/2,e,n),t.fillStyle="rgba(0, 255, 255, 0.4)",t.fillRect(-e/2-w,-n/2,e,n),t.globalCompositeOperation="source-over",t.globalAlpha=1;const I=n/v;for(let k=0;k<v;k++){const O=Math.sin(k*127.1+c*311.7*p)*43758.5,T=O-Math.floor(O);if(T>1-S){const A=(T-(1-S))/S*C*(Math.random()>.5?1:-1),D=-n/2+k*I,Y=t.getTransform(),B=Y.e-e/2+A,R=Y.f+D;t.save(),t.beginPath(),t.rect(-e/2,D,e,I),t.clip(),t.globalAlpha=.8,t.drawImage(t.canvas,B,R,e,I,-e/2+A,D,e,I),t.restore()}}}t.restore()}}_shiftHue(t,s,o){let e=0,n=0,i=0;if(t.startsWith("#")){const u=t.replace("#","");e=parseInt(u.substring(0,2),16)/255,n=parseInt(u.substring(2,4),16)/255,i=parseInt(u.substring(4,6),16)/255}const a=Math.max(e,n,i),r=Math.min(e,n,i);let l=0,d=0,p=(a+r)/2;if(a!==r){const u=a-r;switch(d=p>.5?u/(2-a-r):u/(a+r),a){case e:l=((n-i)/u+(n<i?6:0))/6;break;case n:l=((i-e)/u+2)/6;break;case i:l=((e-n)/u+4)/6;break}}return`hsla(${(((l*360+s)%360+360)%360).toFixed(0)}, ${(d*100).toFixed(0)}%, ${(p*100).toFixed(0)}%, ${o})`}applyBackgroundBlurGlass(t,s,o,e,n,i,a){const r=i.radius??10,l=i.opacity!==void 0?this.normalizeOpacity(i.opacity):.5,d=i.noise??0,p=i.color??"rgba(255,255,255,0.2)";t.save(),this.applyPath(t,s,o,e,n),t.clip();const g=t.getTransform(),u=t.canvas;try{const m=document.createElement("canvas");m.width=Math.max(1,Math.ceil(o)),m.height=Math.max(1,Math.ceil(e));const b=m.getContext("2d");if(b){b.save(),b.translate(o/2,e/2);const c=i.magnification||1;if(c!==1&&b.scale(c,c),typeof g.inverse=="function"){const C=g.inverse();b.transform(C.a,C.b,C.c,C.d,C.e,C.f)}else{const C=g.a*g.d-g.b*g.c;C!==0&&b.transform(g.d/C,-g.b/C,-g.c/C,g.a/C,(g.c*g.f-g.d*g.e)/C,(g.b*g.e-g.a*g.f)/C)}b.drawImage(u,0,0),b.restore();const S=document.createElement("canvas");S.width=m.width,S.height=m.height;const v=S.getContext("2d");v.filter=`blur(${r}px)`,v.drawImage(m,0,0),t.globalCompositeOperation="destination-out",t.fillRect(-o/2,-e/2,o,e),t.globalCompositeOperation="source-over",t.globalAlpha=1,t.drawImage(S,-o/2,-e/2,o,e)}}catch(m){console.error("Background blur failed:",m)}t.globalCompositeOperation="source-over",t.globalAlpha=l,t.fillStyle=p,t.fillRect(-o/2,-e/2,o,e),t.globalAlpha=1;const f=t.createLinearGradient(-o/2,-e/2,o/2,e/2);if(f.addColorStop(0,"rgba(255,255,255,0.12)"),f.addColorStop(.3,"rgba(255,255,255,0.04)"),f.addColorStop(.5,"rgba(255,255,255,0.0)"),f.addColorStop(1,"rgba(255,255,255,0.0)"),t.fillStyle=f,t.fillRect(-o/2,-e/2,o,e),d>0){if(t.globalAlpha=d/100,!this._noiseTileCanvas){const b=document.createElement("canvas");b.width=64,b.height=64;const c=b.getContext("2d"),S=c.createImageData(64,64),v=S.data;for(let C=0;C<v.length;C+=4){const w=Math.floor(Math.random()*255);v[C]=w,v[C+1]=w,v[C+2]=w,v[C+3]=18}c.putImageData(S,0,0),this._noiseTileCanvas=b}const m=t.createPattern(this._noiseTileCanvas,"repeat");m&&(t.fillStyle=m,t.fillRect(-o/2,-e/2,o,e))}t.restore(),t.save(),t.globalAlpha=1,(a==null?void 0:a.stroke)&&a.stroke.width>0&&a.stroke.isEnabled!==!1?(this.applyPath(t,s,o,e,n),this.applyStrokeAlignment(t,a,s,o,e,n)):(t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1.5,this.applyPath(t,s,o,e,n),t.stroke()),t.restore()}applyPath(t,s,o,e,n){s!=null&&s.data&&(s.type==="Path"||s.type==="Subtract"||s.type==="Union"||s.type==="Intersect"||s.type==="Exclude"||s.type),t.beginPath(),this._tracePath(t,s,o,e,n)}_tracePath(t,s,o,e,n){if(s){if(this.ensurePathPoints(s),(s==null?void 0:s.type)==="Rectangle"||s.type==="Image"){const i=n!==void 0?n:s.corner_radius??0;this.drawRoundRect(t,-o/2,-e/2,o,e,i)}else if(s.type==="Line")t.moveTo(-o/2,0),t.lineTo(o/2,0);else if(s.type==="Ellipse"||s.type==="circle"){const{startAngle:i=0,sweepAngle:a=360,ratio:r=0}=s,l=o/2,d=e/2,p=i*Math.PI/180,g=a*Math.PI/180,u=p+g;a>=360&&r<=0?t.ellipse(0,0,l,d,0,0,Math.PI*2):(t.ellipse(0,0,l,d,0,p,u,!1),r>0?t.ellipse(0,0,l*r,d*r,0,u,p,!0):t.lineTo(0,0),t.closePath())}else if(s.type==="Triangle")t.moveTo(0,-e/2),t.lineTo(o/2,e/2),t.lineTo(-o/2,e/2),t.closePath();else if(s.type==="Polygon"){const i=s.sides||3,a=s.radius||Math.min(o,e)/2;for(let r=0;r<i;r++){const l=r*2*Math.PI/i-Math.PI/2,d=a*Math.cos(l),p=a*Math.sin(l);r===0?t.moveTo(d,p):t.lineTo(d,p)}t.closePath()}else if(s.type==="Star"){const i=s.points||5,a=s.outer_radius||Math.min(o,e)/2;let r=s.inner_radius;r==null?r=a*.382:r<=1&&(r=a*r);for(let l=0;l<i*2;l++){const d=l*Math.PI/i-Math.PI/2,p=l%2===0?a:r,g=p*Math.cos(d),u=p*Math.sin(d);l===0?t.moveTo(g,u):t.lineTo(g,u)}t.closePath()}else if(s!=null&&s.points&&["path","custom","customshape","shape","subtract","union","intersect","exclude","booleanoperation"].includes((s.type||"").toLowerCase())){this.frameCount%300===0&&this.log("[Engine] Tracing Path:",s.points.length,"points");let i=1/0,a=-1/0,r=1/0,l=-1/0;if(s.points.forEach(g=>{typeof g.x=="number"&&typeof g.y=="number"&&(i=Math.min(i,g.x),a=Math.max(a,g.x),r=Math.min(r,g.y),l=Math.max(l,g.y),g.out_x!==void 0&&(i=Math.min(i,g.out_x),a=Math.max(a,g.out_x)),g.out_y!==void 0&&(r=Math.min(r,g.out_y),l=Math.max(l,g.out_y)),g.in_x!==void 0&&(i=Math.min(i,g.in_x),a=Math.max(a,g.in_x)),g.in_y!==void 0&&(r=Math.min(r,g.in_y),l=Math.max(l,g.in_y)))}),i===1/0)return;let d=(i+a)/2,p=(r+l)/2;if(isNaN(d)||isNaN(p)){this.warn("[Engine] Invalid path center:",d,p);return}s.points.forEach((g,u)=>{if(u===0||g.moveTo)t.moveTo(g.x-d,g.y-p);else{const f=s.points[u-1];if(!f)return;const h=(f.out_x??f.x)-d,m=(f.out_y??f.y)-p,b=(g.in_x??g.x)-d,c=(g.in_y??g.y)-p;isNaN(h)||isNaN(b)||isNaN(g.x)?t.lineTo(g.x-d,g.y-p):t.bezierCurveTo(h,m,b,c,g.x-d,g.y-p)}if(g.closePath||u===s.points.length-1&&(s.is_closed||s.isClosed)){const f=[...s.points.slice(0,u+1)].reverse().find(h=>h.moveTo)||s.points[0];f&&(g.out_x!==void 0||f.in_x!==void 0)&&t.bezierCurveTo((g.out_x??g.x)-d,(g.out_y??g.y)-p,(f.in_x??f.x)-d,(f.in_y??f.y)-p,f.x-d,f.y-p),t.closePath()}})}else if(s.points&&Array.isArray(s.points)){let i=1/0,a=-1/0,r=1/0,l=-1/0;s.points.forEach(g=>{i=Math.min(i,g.x),a=Math.max(a,g.x),r=Math.min(r,g.y),l=Math.max(l,g.y)});const d=(i+a)/2,p=(r+l)/2;s.points.forEach((g,u)=>{if(u===0)t.moveTo(g.x-d,g.y-p);else{const f=s.points[u-1];f.out_x!==void 0||g.in_x!==void 0?t.bezierCurveTo((f.out_x??f.x)-d,(f.out_y??f.y)-p,(g.in_x??g.x)-d,(g.in_y??g.y)-p,g.x-d,g.y-p):t.lineTo(g.x-d,g.y-p)}(g.closePath||u===s.points.length-1&&(s.is_closed||s.isClosed))&&t.closePath()})}}}renderInputBox(t,s){var qt,Se,Ce,Ie,de,Re,ye,ke,Vt,ee,j,bt,st,K,rt,ft,Rt,Qt,Kt,ae,Jt,Et;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=s.geometry||{},i=s.style||{},a=this.focusedId===s.id,r=this.lastHoveredObjectId===s.id,l=e.previewState||"default",d=l==="focused"||l==="active"||!e.disabled&&a,p=l==="hover"||!e.disabled&&r&&!d,g=l==="disabled"||!!e.disabled,u=l==="error"||!!e.error,f=e.inputType==="textarea"||e.multiline===!0;let h={};g&&e.disabledStyle&&Object.keys(e.disabledStyle).length>0?h=e.disabledStyle:u&&e.errorStyle&&Object.keys(e.errorStyle).length>0?h=e.errorStyle:d?h={...e.focusedStyle||{},...e.activeStyle||{}}:p&&(h={...e.hoveredStyle||{},...e.hoverStyle||{}});const m=Number(h.scale??1);m!==1&&t.scale(m,m);const b=Number(h.translateX??0),c=Number(h.translateY??0);(b||c)&&t.translate(b,c);const S=Number(h.rotate??0);S&&t.rotate(S*Math.PI/180);const v=Number(h.opacity??1);v!==1&&(t.globalAlpha=v);const C=Number(h.width??n.width)||250,w=Number(h.height??n.height)||45,I=e.label||{visible:!0,text:"Label"},k=e.helperText||{visible:!1,text:"Helper text"},O=e.leftIcon||{visible:!1},T=e.rightIcon||{visible:!1},A=((qt=h.leftIcon)==null?void 0:qt.color)||h.leftIconColor||h.iconColor,D=((Se=h.rightIcon)==null?void 0:Se.color)||h.rightIconColor||h.iconColor,Y={...O,...h.leftIcon||{},...A?{color:A}:{}},B={...T,...h.rightIcon||{},...D?{color:D}:{}};h.leftIconVisible!==void 0&&(Y.visible=h.leftIconVisible),h.rightIconVisible!==void 0&&(B.visible=h.rightIconVisible),((Ce=h.leftIcon)==null?void 0:Ce.visible)!==void 0&&(Y.visible=h.leftIcon.visible),((Ie=h.rightIcon)==null?void 0:Ie.visible)!==void 0&&(B.visible=h.rightIcon.visible);const R=n.corner_radius??n.cornerRadius,L=Array.isArray(R)?{tl:R[0],tr:R[1],br:R[2],bl:R[3]}:R&&typeof R=="object"?R:void 0,$=h.cornerRadius??h.corner_radius,F=Number($??e.cornerRadius??e.corner_radius??R??e.radius??8),X=h.corners??($!==void 0?{tl:F,tr:F,bl:F,br:F}:e.corners??L??{tl:F,tr:F,bl:F,br:F}),M=[Number(X.tl??F),Number(X.tr??F),Number(X.br??F),Number(X.bl??F)],E=(W,nt,Lt,tt,gt,Q=0)=>{const Ut=Math.max(0,Lt-Q*2),zt=Math.max(0,tt-Q*2);let[yt,Bt,_t,Xt]=gt.map(ce=>Math.max(0,(Number(ce)||0)-Q));const Dt=Math.min(Ut,zt)/2;yt=Math.min(yt,Dt),Bt=Math.min(Bt,Dt),_t=Math.min(_t,Dt),Xt=Math.min(Xt,Dt),t.beginPath(),t.roundRect?t.roundRect(W+Q,nt+Q,Ut,zt,[yt,Bt,_t,Xt]):(t.moveTo(W+Q+yt,nt+Q),t.lineTo(W+Q+Ut-Bt,nt+Q),t.arcTo(W+Q+Ut,nt+Q,W+Q+Ut,nt+Q+Bt,Bt),t.lineTo(W+Q+Ut,nt+Q+zt-_t),t.arcTo(W+Q+Ut,nt+Q+zt,W+Q+Ut-_t,nt+Q+zt,_t),t.lineTo(W+Q+Xt,nt+Q+zt),t.arcTo(W+Q,nt+Q+zt,W+Q,nt+Q+zt-Xt,Xt),t.lineTo(W+Q+yt,nt+Q),t.arcTo(W+Q,nt+Q,W+Q+yt,nt+Q,yt),t.closePath())};let P=h.backgroundColor??e.backgroundColor??((de=i.fill)==null?void 0:de.color)??"rgba(31, 41, 55, 1)",_=h.borderColor??e.borderColor??((ye=(Re=i.stroke)==null?void 0:Re.fill)==null?void 0:ye.color)??((ke=i.stroke)==null?void 0:ke.color)??"rgba(55, 65, 81, 1)",V=Number(h.borderWidth??e.borderWidth??((Vt=i.stroke)==null?void 0:Vt.width)??1),G=h.color??e.color??((ee=i.fill)==null?void 0:ee.color)??"#ffffff",x=h.placeholderColor??e.placeholderColor??"rgba(156, 163, 175, 1)",U=Number(h.fontSize??e.fontSize??14),q=h.caretColor??e.caretColor??e.accentColor??"#3b82f6";!h.borderColor&&!h.borderWidth&&(d&&!g?(_=e.focusBorderColor||e.accentColor||"#3b82f6",V=Math.max(V,1.5)):p&&!g?(_=e.hoverBorderColor||"#64748b",P=e.hoverBackgroundColor||P):g?(P=e.disabledBackgroundColor||"rgba(31, 41, 55, 0.6)",_=e.disabledBorderColor||"rgba(55, 65, 81, 0.4)"):u&&(_="rgba(239, 68, 68, 1)",V=Math.max(V,2)));const N=V>0?V/2:0,H=this.createCanvasFill(t,P,C,w);if(H&&P!=="transparent"&&(E(-C/2,-w/2,C,w,M,N),t.fillStyle=H,t.fill()),V>0){const W=this.createCanvasFill(t,_,C,w);W&&_!=="transparent"&&(E(-C/2,-w/2,C,w,M,N),t.strokeStyle=W,t.lineWidth=V,t.lineCap="round",t.lineJoin="round",t.stroke())}if(h.boxShadow&&h.boxShadow.color&&h.boxShadow.color!=="transparent"){t.save();const W=h.boxShadow;t.shadowColor=W.color,t.shadowOffsetX=Number(W.offsetX??0),t.shadowOffsetY=Number(W.offsetY??2),t.shadowBlur=Number(W.blur??8),E(-C/2,-w/2,C,w,M,N),t.fillStyle=P!=="transparent"?H||P:"rgba(0,0,0,0.01)",t.fill(),t.restore()}if(d&&!g){t.save();const W=-3,nt=M.map(gt=>Math.max(0,gt+3));E(-C/2+W,-w/2+W,C-W*2,w-W*2,nt);const Lt=h.borderColor||((j=e.activeStyle)==null?void 0:j.borderColor)||q||"rgba(59, 130, 246, 0.4)",tt=this.createCanvasFill(t,Lt,C,w)||"rgba(59, 130, 246, 0.4)";t.strokeStyle=tt,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",t.stroke(),t.restore()}const z=h.fontFamily||e.fontFamily||"Inter",et=(h.fontWeight??e.fontWeight)||400,Mt=Number(h.fontSize??U),ct=e.inputType==="number"&&((bt=e.number)==null?void 0:bt.showSteppers)!==!1,It=24,mt=ct?It+4:0,kt=String(e.text??e.value??"");let Ot="Enter text...";if(e.inputType==="tel")Ot=`${((st=e.tel)==null?void 0:st.dialCode)||"+1"} (555) 000-0000`;else if(e.inputType==="number"){const W=(K=e.number)!=null&&K.prefix?`${e.number.prefix} `:"",nt=(rt=e.number)!=null&&rt.suffix?` ${e.number.suffix}`:"";Ot=`${W}0.00${nt}`}else e.inputType==="email"?Ot="user@example.com":e.inputType==="search"?Ot="Search anything...":e.inputType==="url"?Ot="https://example.com":e.inputType==="password"?Ot="••••••••":e.inputType==="textarea"&&(Ot="Enter text...");const vt=e.placeholder||Ot,Wt=!kt,J=e.inputType==="password",ut=B.mode==="password-toggle"||J&&B.visible!==!1,$t=B.mode==="clear"||e.inputType==="search"&&!!kt,St=(W,nt)=>{var Bt;let Lt=W.svgPath||"";const tt=W.char||"";if(!Lt&&!tt&&(nt?e.inputType==="search"&&(Lt="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"):ut?Lt=e.passwordVisible?"M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24M1 1l22 22":"M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z M12 9a3 3 0 100 6 3 3 0 000-6z":$t&&(Lt="M18 6L6 18M6 6l12 12")),!(W.visible||!!(Lt||tt)&&(!nt&&(ut||$t)||nt&&e.inputType==="search")))return;const Q=W.size||16,Ut=(W.offset??16)+(nt?0:mt),zt=typeof W.color=="string"?W.color:((Bt=W.color)==null?void 0:Bt.color)||"#9ca3af",yt=nt?-(C/2)+Ut:C/2-Ut;if(Lt){if(t.save(),t.translate(yt,0),!Lt.startsWith("<svg")){const _t=new Path2D(Lt),Xt=Q/24;t.scale(Xt,Xt),t.translate(-12,-12),Lt.includes("M18 6L6 18")||Lt.includes("M1 1l22 22")||Lt.includes("M21 21")||Lt.includes("M11 19a8")?(t.strokeStyle=zt,t.lineWidth=2/Xt,t.lineCap="round",t.lineJoin="round",t.stroke(_t)):(t.fillStyle=zt,t.fill(_t))}t.restore()}else tt&&(t.save(),t.translate(yt,0),t.fillStyle=zt,t.font=`${Q}px sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText(tt,0,0),t.restore())};if(St(Y,!0),St(B,!1),ct){const W=C/2-It-4;t.save(),t.strokeStyle=_||"rgba(55, 65, 81, 0.5)",t.lineWidth=1,t.beginPath(),t.moveTo(W,-w/2+6),t.lineTo(W,w/2-6),t.stroke(),t.beginPath(),t.moveTo(W,0),t.lineTo(C/2-4,0),t.stroke(),t.fillStyle=G||"rgba(156, 163, 175, 0.8)",t.font=`600 8px "${z}", sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText("▲",W+It/2,-w/4),t.fillText("▼",W+It/2,w/4),t.restore()}const Pt=h.padding||e.padding||{},Ft=Pt.left??((ft=e.padding)==null?void 0:ft.left)??e.inputPadding??12,lt=Pt.right??((Rt=e.padding)==null?void 0:Rt.right)??e.inputPadding??12,ht=Y.visible||e.inputType==="search",dt=B.visible||ut||$t,At=ht?(Y.offset??16)+(Y.size||16)/2+8:Ft,Tt=dt?(B.offset??16)+(B.size||16)/2+8+mt:lt+mt,Ct=-(C/2)+At,Yt=Math.max(0,C-At-Tt);let ie=kt||vt;if(e.inputType==="number"&&kt){const W=(Qt=e.number)!=null&&Qt.prefix?`${e.number.prefix} `:"",nt=(Kt=e.number)!=null&&Kt.suffix?` ${e.number.suffix}`:"";ie=`${W}${kt}${nt}`}const te=J&&kt?e.passwordVisible?kt:"•".repeat(kt.length):ie,Zt=Wt?x:G;if(t.font=`${et} ${Mt}px "${z}", sans-serif`,t.fillStyle=Zt,t.textAlign="left",t.save(),t.beginPath(),t.rect(Ct-2,-w/2+4,Yt+4,w-8),t.clip(),f){t.textBaseline="top";const W=te.split(`
19
+ `);let nt=-w/2+(((ae=e.padding)==null?void 0:ae.top)??8);const Lt=Mt*1.4,tt=e.rows||3;let gt=0,Q=0;for(const Ut of W){if(gt>=tt)break;const zt=Ut.split(" ");let yt="";for(let Bt=0;Bt<zt.length;Bt++){const _t=yt+zt[Bt]+" ";if(t.measureText(_t).width>Yt&&Bt>0){if(gt>=tt)break;t.fillText(yt.trim(),Ct,nt),yt=zt[Bt]+" ",nt+=Lt,gt++}else yt=_t}gt<tt&&(t.fillText(yt.trim(),Ct,nt),Q=t.measureText(yt.trim()).width,nt+=Lt,gt++)}if(d&&!Wt&&Math.floor(performance.now()/500)%2===0){const Ut=nt-Lt;t.fillStyle=q,t.fillRect(Ct+Math.min(Q,Yt),Ut,1.5,Mt)}}else{t.textBaseline="middle";const nt=t.measureText(te).width;let Lt=0;if(nt>Yt&&(Lt=nt-Yt),t.fillText(te,Ct-Lt,0),d&&Math.floor(performance.now()/500)%2===0){const tt=Wt?Ct:Ct+nt-Lt;t.fillStyle=q,t.fillRect(tt,-(Mt/2),1.5,Mt)}}if(t.restore(),e.showCharCounter){t.save();const W=Number(e.maxLength||0),nt=W>0?`${kt.length}/${W}`:`${kt.length}`;t.font=`400 10px "${z}", sans-serif`,t.fillStyle=W>0&&kt.length>=W?"#ef4444":"rgba(156, 163, 175, 0.6)",t.textAlign="right",t.textBaseline="top",t.fillText(nt,-(C/2)+C-8,-(w/2)+w+4),t.restore()}if(I.visible!==!1){const W=!!(I.required||(Jt=e.validation)!=null&&Jt.required),nt=(I.text||"Label")+(W?" *":""),Lt=I.fontSize||12,tt=I.color||"rgba(156, 163, 175, 1)",gt=I.position||"top",Q=I.gap??I.offset??6;let Ut=-(C/2),zt=-(w/2)-Q,yt="left",Bt="bottom",_t=`600 ${Lt}px "${I.fontFamily||z}", sans-serif`;gt==="left"?(Ut=-(C/2)-Q,zt=0,yt="right",Bt="middle"):gt==="bottom"?(Ut=-(C/2),zt=w/2+Q,yt="left",Bt="top"):gt==="floating"&&(!!kt||a?(Ut=-(C/2)+12,zt=-(w/2)+4,yt="left",Bt="top",_t=`600 ${Math.max(9,Lt-2)}px "${I.fontFamily||z}", sans-serif`):_t=null),_t&&(t.save(),t.font=_t,t.fillStyle=tt,t.textAlign=yt,t.textBaseline=Bt,t.fillText(nt,Ut,zt),t.restore())}const le=(Et=e.validation)==null?void 0:Et.errorMessage;if(u&&le||k.visible===!0&&k.text){t.save();const W=k.fontSize||11,nt=u?"#ef4444":k.color||"rgba(156, 163, 175, 1)",Lt=k.offset??6,tt=u&&le?le:k.text;t.font=`400 ${W}px "${z}", sans-serif`,t.fillStyle=nt,t.textAlign="left",t.textBaseline="top",t.fillText(tt,-(C/2),w/2+Lt),t.restore()}g&&(t.save(),E(-C/2,-w/2,C,w,M),t.fillStyle="rgba(0, 0, 0, 0.3)",t.fill(),t.restore()),v!==1&&(t.globalAlpha=1)}renderSlider(t,s){const o=this.objectStates.get(s.id),e=(o==null?void 0:o.geometry)||s.geometry,n=(o==null?void 0:o.options)||s.options||{},i=e.width||200,a=n.value??50,r=n.min??0,d=(n.max??100)-r,p=d===0?0:(a-r)/d,g=n.trackHeight||4,u=n.trackRoundedness??2,f=n.trackShape??"Rectangle",h=n.trackPath||"",m=n.activeColor||n.accentColor||"#3b82f6",b=n.inactiveColor||"#374151",c=n.thumbShape||"Ellipse",S=n.thumbWidth??16,v=n.thumbHeight??16,C=n.thumbRoundedness??0,w=n.thumbColor||"#ffffff",I=n.thumbPath||"",k=n.thumbIcon||"",O=n.trackStrokeWidth??0,T=n.trackStrokeColor||"",A=n.thumbStrokeWidth??0,D=n.thumbStrokeColor||"",Y=n.showValueTooltip??!1,B=n.tooltipBgColor||"#333333",R=n.tooltipColor||"#ffffff",L=n.tooltipOffsetX??0,$=n.tooltipOffsetY??-25,F=this.lastHoveredObjectId===s.id,X=this.isMouseDown&&F,M=n.hoverStyle||{},E=n.activeStyle||{};let P=g,_=m,V=b,G=c,x=S,U=v,q=C,N=w,H=O,z=T,et=A,Mt=D,ct=1;X&&E?(ct=E.scale??1,P=E.trackHeight??P,_=E.activeColor??_,V=E.inactiveColor??V,N=E.thumbColor??N,x=E.thumbWidth??x,U=E.thumbHeight??U,q=E.thumbRoundedness??q,G=E.thumbShape||G,H=E.trackStrokeWidth??H,z=E.trackStrokeColor??z,et=E.thumbStrokeWidth??et,Mt=E.thumbStrokeColor??Mt):F&&M&&(ct=M.scale??1,P=M.trackHeight??P,_=M.activeColor??_,V=M.inactiveColor??V,N=M.thumbColor??N,x=M.thumbWidth??x,U=M.thumbHeight??U,q=M.thumbRoundedness??q,G=M.thumbShape||G,H=M.trackStrokeWidth??H,z=M.trackStrokeColor??z,et=M.thumbStrokeWidth??et,Mt=M.thumbStrokeColor??Mt);const It=X&&E.thumbPath?E.thumbPath:F&&M.thumbPath?M.thumbPath:I;ct!==1&&(t.save(),t.scale(ct,ct));const mt=(ht,dt,At,Tt,Ct,Yt,ie)=>{const te=xe[ht]||ie||(ht&&(ht.startsWith("M")||ht.startsWith("m"))?ht:"");if((ht==="Custom"||ht==="Icon"||te)&&te)try{const Zt=new Path2D(te),le=We(te),fe=Math.min(Tt/le.width,Ct/le.height);t.save(),t.translate(dt,At),t.scale(fe,fe),t.translate(-le.cx,-le.cy);const qt=!te.includes("z")&&!te.includes("Z");qt?(t.strokeStyle=t.fillStyle,t.lineWidth=Math.max(1.8,2.2/fe),t.lineCap="round",t.lineJoin="round",t.stroke(Zt)):t.fill(Zt),t.strokeStyle&&t.lineWidth>0&&!qt&&t.stroke(Zt),t.restore();return}catch(Zt){console.error("Error drawing slider shape in engine:",Zt)}if(t.beginPath(),ht==="Ellipse")t.ellipse(dt,At,Tt/2,Ct/2,0,0,Math.PI*2);else if(ht==="Rectangle")this.drawRoundRect(t,dt-Tt/2,At-Ct/2,Tt,Ct,Yt);else if(ht==="Triangle")t.moveTo(dt,At-Ct/2),t.lineTo(dt+Tt/2,At+Ct/2),t.lineTo(dt-Tt/2,At+Ct/2),t.closePath();else if(ht==="Diamond")t.moveTo(dt,At-Ct/2),t.lineTo(dt+Tt/2,At),t.lineTo(dt,At+Ct/2),t.lineTo(dt-Tt/2,At),t.closePath();else if(ht==="Polygon"){const Zt=s.geometry.sides||3,le=s.geometry.radius||Math.min(Tt,Ct)/2;for(let fe=0;fe<Zt;fe++){const qt=fe*2*Math.PI/Zt-Math.PI/2,Se=dt+le*Math.cos(qt),Ce=At+le*Math.sin(qt);fe===0?t.moveTo(Se,Ce):t.lineTo(Se,Ce)}t.closePath()}else if(ht==="Star"){const le=Math.min(Tt,Ct)/2,fe=le/2;for(let qt=0;qt<10;qt++){const Se=qt%2===0?le:fe,Ce=qt*Math.PI/5-Math.PI/2;t.lineTo(dt+Se*Math.cos(Ce),At+Se*Math.sin(Ce))}t.closePath()}else ht==="Line"&&(t.moveTo(dt-Tt/2,At),t.lineTo(dt+Tt/2,At));t.fill(),t.strokeStyle&&t.lineWidth>0&&t.stroke()},kt=this.createCanvasFill(t,V,i,P);kt&&(t.fillStyle=kt,t.strokeStyle=kt),f==="Line"?(t.strokeStyle=H>0&&z?z:kt,t.lineWidth=H>0?H:P,t.beginPath(),t.moveTo(-i/2,0),t.lineTo(i/2,0),t.stroke()):(H>0&&z&&(t.strokeStyle=z,t.lineWidth=H),mt(f,0,0,i,P,u,h));const Ot=i-x,vt=-i/2+x/2+p*Ot,Wt=vt- -i/2;if(Wt>0){const ht=this.createCanvasFill(t,_,i,P);if(ht&&(t.fillStyle=ht),f==="Line")t.strokeStyle=H>0&&z?z:ht||_,t.lineWidth=H>0?H:P,t.beginPath(),t.moveTo(-i/2,0),t.lineTo(vt,0),t.stroke();else{if(H>0&&z&&(t.strokeStyle=z,t.lineWidth=H),t.beginPath(),f==="Rectangle")this.drawRoundRect(t,-i/2,-P/2,Wt,P,u);else{const dt=xe[f]||h||"";if(dt)try{const At=new Path2D(dt),Tt=We(dt),Ct=Math.min(Wt/Tt.width,P/Tt.height);t.save(),t.translate(-i/2+Wt/2,0),t.scale(Ct,Ct),t.translate(-Tt.cx,-Tt.cy),t.fill(At),t.strokeStyle&&t.lineWidth>0&&t.stroke(At),t.restore()}catch{this.drawRoundRect(t,-i/2,-P/2,Wt,P,u)}else this.drawRoundRect(t,-i/2,-P/2,Wt,P,u)}t.fill(),t.strokeStyle&&t.lineWidth>0&&t.stroke()}}t.save(),t.translate(vt,0);const J=t.getTransform(),ut=Math.sqrt(J.a*J.a+J.b*J.b)||1;t.shadowColor="rgba(0,0,0,0.2)",t.shadowBlur=4*ut,t.shadowOffsetY=1*ut;const $t=this.createCanvasFill(t,N,x,U);$t&&(t.fillStyle=$t),et>0&&Mt&&(t.strokeStyle=Mt,t.lineWidth=et);const St=X&&E.thumbShape==="Icon"?E.thumbPath||k:F&&M.thumbShape==="Icon"&&M.thumbPath||k;if(mt(G,0,0,x,U,q,G==="Icon"?St:It),t.restore(),Y){t.save(),t.translate(vt+L,$);const ht=Math.round(a).toString();t.font="10px Inter, sans-serif";const dt=t.measureText(ht),At=6,Tt=4,Ct=dt.width+At*2,Yt=14+Tt;t.beginPath(),this.drawRoundRect(t,-Ct/2,-Yt/2,Ct,Yt,4),t.fillStyle=B,t.fill(),t.fillStyle=R,t.textAlign="center",t.textBaseline="middle",t.fillText(ht,0,0),t.restore()}const Pt=n.label||{},Ft=n.helperText||{},lt=n.fontFamily||"Inter";if(Pt.visible!==!1){const ht=Pt.text||"Label",dt=Pt.fontSize||12,At=Pt.color||"rgba(156, 163, 175, 1)",Tt=Pt.offset??8;t.font=`600 ${dt}px "${lt}", sans-serif`,t.fillStyle=At,t.textAlign="left",t.textBaseline="bottom";const Ct=-(i/2),Yt=-(P/2)-Tt;t.fillText(ht,Ct,Yt)}if(Ft.visible===!0){const ht=Ft.text||"Helper text",dt=Ft.fontSize||11,At=Ft.color||"rgba(156, 163, 175, 1)",Tt=Ft.offset??6;t.font=`400 ${dt}px "${lt}", sans-serif`,t.fillStyle=At,t.textAlign="left",t.textBaseline="top";const Ct=-(i/2),Yt=P/2+Tt;t.fillText(ht,Ct,Yt)}ct!==1&&t.restore()}renderDropdown(t,s){var Y;const o=this.objectStates.get(s.id);if(!o)return;const e=o.options||s.options||{},n=s.geometry.width||180,i=s.geometry.height||40,a=-n/2,r=-i/2,l=e.cornerRadius??e.corner_radius??6,d=e.disabled||e.previewState==="disabled",p=this.lastHoveredObjectId===s.id||e.previewState==="hover",g=(e.isOpen||e.previewState==="active")&&!d;let u=e.backgroundColor,f=e.borderColor,h=e.color||"#333333";d?(u=e.disabledBackgroundColor||"#f3f4f6",f=e.disabledBorderColor||"#e5e7eb",h=e.disabledColor||"#9ca3af"):g?(u=e.activeBackgroundColor||u,f=e.activeBorderColor||f,h=e.activeColor||h):p&&(u=e.hoverBackgroundColor||u,f=e.hoverBorderColor||f,h=e.hoverColor||h),u||(u="#ffffff"),f||(f="#e5e7eb"),t.save();const m=t.globalAlpha;t.globalAlpha=m*(e.opacity??1),t.beginPath(),this.drawRoundRect(t,a,r,n,i,l),t.fillStyle=this.createCanvasFill(t,typeof u=="string"?{type:"Solid",color:u}:u,n,i)||"#ffffff",t.fill();const b=e.borderWidth??1;b>0&&(t.beginPath(),this.drawRoundRect(t,a,r,n,i,l),t.strokeStyle=this.createCanvasFill(t,typeof f=="string"?{type:"Solid",color:f}:f,n,i)||"#e5e7eb",t.lineWidth=b,t.stroke());const c=12,S=e.chevronType||"chevron",v=e.chevronSize||16,C=(g?e.openIconColor:e.closedIconColor)||e.chevronColor||"#6b7280";if(S!=="none"){const B=a+n-c-v/2;t.save(),t.translate(B,0);const R=g?e.openIconAngle??180:e.closedIconAngle??0;if(t.rotate(R*Math.PI/180),t.strokeStyle=C,t.fillStyle=C,t.lineWidth=1.5,t.lineCap="round",t.lineJoin="round",S==="chevron")t.beginPath(),t.moveTo(-v/2,-v*.2),t.lineTo(0,v*.2),t.lineTo(v/2,-v*.2),t.stroke();else if(S==="custom"||S==="path"){const L=g&&e.openIconPath||e.closedIconPath;if(L){const $=new Path2D(L);t.save();const F=v/24;t.scale(F,F),t.translate(-12,-12),t.fill($),t.restore()}}t.restore()}const w=e.selectedOption||e.placeholder||"Select...",I=e.fontSize||14,k=e.fontWeight||400,O=e.fontFamily||"Inter, sans-serif";t.font=`${k} ${I}px ${O}`;const T=d?e.disabledColor||"#9ca3af":!e.selectedOption&&e.placeholder?"#9ca3af":h;t.fillStyle=this.createCanvasFill(t,typeof T=="string"?{type:"Solid",color:T}:T,n,i)||"#333333",t.textAlign="left",t.textBaseline="middle";const A=S==="none"?0:v+8,D=n-c*2-A;if(t.save(),t.beginPath(),t.rect(a+c,r,D,i),t.clip(),t.fillText(w,a+c,0),t.restore(),g&&!d){const B=r+i+4,R=this.getResolvedDropdownOptions(s,e),L=e.itemHeight||32,$=e.listPadding??4,F=R.length*L+$*2,X=e.listCornerRadius??l;t.save();const M=e.listShadow||{},E=t.getTransform(),P=Math.sqrt(E.a*E.a+E.b*E.b)||1;t.shadowColor=typeof M.color=="string"?M.color:((Y=M.color)==null?void 0:Y.color)||"rgba(0,0,0,0.15)",t.shadowBlur=(M.blur??12)*P,t.shadowOffsetY=(M.offsetY??6)*P,t.shadowOffsetX=(M.offsetX??0)*P,t.beginPath(),this.drawRoundRect(t,a,B,n,F,X),t.fillStyle=this.createCanvasFill(t,typeof e.listBackgroundColor=="string"?{type:"Solid",color:e.listBackgroundColor}:e.listBackgroundColor||{type:"Solid",color:"#ffffff"},n,F)||"#ffffff",t.fill();const _=e.listBorderWidth??1;_>0&&(t.shadowColor="transparent",t.beginPath(),this.drawRoundRect(t,a,B,n,F,X),t.strokeStyle=this.createCanvasFill(t,typeof e.listBorderColor=="string"?{type:"Solid",color:e.listBorderColor}:e.listBorderColor||{type:"Solid",color:f},n,F)||"#e5e7eb",t.lineWidth=_,t.stroke()),t.restore();const V=e.itemFontSize||I,G=e.itemFontFamily||O;t.font=`${k} ${V}px ${G}`,R.forEach((x,U)=>{const q=B+$+U*L;if(x===e.selectedOption)t.fillStyle=this.createCanvasFill(t,typeof e.itemSelectedBackgroundColor=="string"?{type:"Solid",color:e.itemSelectedBackgroundColor}:e.itemSelectedBackgroundColor||{type:"Solid",color:"#f3f4f6"},n,L)||"#f3f4f6",t.fillRect(a+_,q,n-_*2,L),t.fillStyle=e.itemSelectedColor||e.accentColor||h||"#374151";else if(t.fillStyle=e.listTextColor||h||"#333333",this.activeDropdownId===s.id&&this._lastPointerPos){const H=this._lastPointerPos.y-(B+$),z=Math.floor(H/L);U===z&&(t.fillStyle=this.createCanvasFill(t,typeof e.itemHoverBackgroundColor=="string"?{type:"Solid",color:e.itemHoverBackgroundColor}:e.itemHoverBackgroundColor||{type:"Solid",color:"#f9fafb"},n,L)||"#f9fafb",t.fillRect(a+_,q,n-_*2,L),t.fillStyle=e.itemHoverColor||h)}t.fillText(x,a+c,q+L/2)})}t.restore()}renderButton(t,s){var U;if(s.children&&s.children.length>0)return;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=s.geometry||{},i=n.width||s.width||160,a=n.height||s.height||45,r=this.lastHoveredObjectId===s.id,l=this.activeObjectId===s.id,d=e.label||{},p=e.hoverStyle||{},g=e.activeStyle||{},u=e.icon||{enabled:!1};let f=e.backgroundColor||e.buttonBgColor||((U=s.style)==null?void 0:U.fill)||"#3b82f6",h=(typeof d=="object"?d.color:null)||"#ffffff",m=typeof d=="string"?d:d.text||s.text||(s.name&&!s.name.toLowerCase().includes("component")?s.name:"Button"),b=n.cornerRadius??n.corner_radius??8,c=e.borderColor||"transparent",S=e.borderWidth||0,v=1;l&&g?(f=g.backgroundColor||f,h=g.color||h,m=g.text||m,v=g.scale??.95,b=g.cornerRadius??b):r&&p&&(f=p.backgroundColor||f,h=p.color||h,m=p.text||m,v=p.scale??1,b=p.cornerRadius??b,c=p.borderColor||c);const C=-i/2,w=-a/2;t.save(),t.scale(v,v),t.beginPath(),this.drawRoundRect(t,C,w,i,a,b);const I=this.createCanvasFill(t,f,i,a);I&&(t.fillStyle=I,t.fill()),(S>0||r&&p.borderColor)&&(t.strokeStyle=c,t.lineWidth=S||(r?1:0),t.stroke());const k=d.fontSize||14,O=d.fontFamily||"Inter",T=d.fontWeight||600;t.font=`${T} ${k}px "${O}", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle=h,t.textAlign="center",t.textBaseline="middle";const A=u.enabled===!0||u.enabled==="true",D=Number(u.size)||Math.round(k*1.15)||16,Y=u.color||h,B=Number(u.gap)??8,R=u.position||"left",L=u.margin||{left:0,right:0,top:0,bottom:0},$=(Number(L.left)||0)-(Number(L.right)||0),F=(Number(L.top)||0)-(Number(L.bottom)||0),X=!!(m&&String(m).trim().length>0),E=(X?t.measureText(String(m)):{width:0}).width,P=k*1.2;let _=0,V=0,G=0,x=0;if(A){if(!X||R==="center")G=$,x=F,_=0,V=0;else if(R==="left"){const q=D+B+E;G=-q/2+D/2+$,x=F,_=-q/2+D+B+E/2+$,V=0}else if(R==="right"){const q=E+B+D;_=-q/2+E/2+$,V=0,G=-q/2+E+B+D/2+$,x=F}else if(R==="top"){const q=D+B+P;G=$,x=-q/2+D/2+F,_=$,V=-q/2+D+B+P/2+F}else if(R==="bottom"){const q=P+B+D;_=$,V=-q/2+P/2+F,G=$,x=-q/2+P+B+D/2+F}this.drawButtonIcon(t,u,G,x,D,Y,O)}X&&R!=="center"&&(t.fillStyle=h,t.fillText(String(m),_,V)),t.restore()}drawButtonIcon(t,s,o,e,n,i,a="Inter"){const r=(s.svgPath||"").trim(),l=(s.character||s.char||"").trim(),d="M12 3L10.088 8.813A2 2 0 0 1 8.813 10.088L3 12L8.813 13.912A2 2 0 0 1 10.088 15.187L12 21L13.912 15.187A2 2 0 0 1 15.187 13.912L21 12L15.187 10.088A2 2 0 0 1 13.912 8.813L12 3Z";if(t.save(),l){t.font=`${Math.round(n)}px "${a}", -apple-system, sans-serif`,t.fillStyle=i,t.textAlign="center",t.textBaseline="middle",t.fillText(l,o,e),t.restore();return}if(r.startsWith("<svg")){const u=s.fill&&s.fill.type!=="None";let f=r.replace(/stroke\s*=\s*(['"])currentColor\1/gi,`stroke="${i}"`).replace(/stroke\s*:\s*currentColor/gi,`stroke: ${i}`);u?f=f.replace(/fill\s*=\s*(['"])currentColor\1/gi,`fill="${i}"`).replace(/fill\s*:\s*currentColor/gi,`fill: ${i}`):f=f.replace(/fill\s*=\s*(['"])currentColor\1/gi,'fill="none"').replace(/fill\s*:\s*currentColor/gi,"fill: none"),f.includes("xmlns=")||(f=f.replace("<svg",'<svg xmlns="http://www.w3.org/2000/svg"'));const h=`svg_icon_${i}_${n}_${btoa(f.slice(0,80))}`;let m=this.imageCache.get(h);if(m||(m=new Image,m.crossOrigin="anonymous",m.src=`data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(f)))}`,this.imageCache.set(h,m)),m.complete&&m.naturalWidth>0){t.drawImage(m,o-n/2,e-n/2,n,n),t.restore();return}const b=[...f.matchAll(/<path[^>]*\bd=["']([^"']+)["']/gi)];if(b.length>0){t.translate(o,e);const c=n/24;t.scale(c,c),t.translate(-12,-12);const S=new Path2D(b.map(v=>v[1]).join(" "));u?(t.fillStyle=i,t.fill(S)):(t.strokeStyle=i,t.lineWidth=2,t.lineCap="round",t.lineJoin="round",t.stroke(S)),t.restore();return}}if(r&&!r.startsWith("<")){t.translate(o,e);const u=n/24;t.scale(u,u),t.translate(-12,-12);const f=new Path2D(r);t.fillStyle=i,t.fill(f),t.strokeStyle=i,t.lineWidth=1,t.stroke(f),t.restore();return}t.translate(o,e);const p=n/24;t.scale(p,p),t.translate(-12,-12);const g=new Path2D(d);t.fillStyle=i,t.fill(g),t.restore()}renderToggleButton(t,s){var m,b;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=e.checked??!1,i=((m=s.geometry)==null?void 0:m.width)||120,a=((b=s.geometry)==null?void 0:b.height)||40,r=-i/2,l=-a/2,d=e.corner_radius??8,p=e.label||{},g=n?e.accentColor||"#3b82f6":e.inactiveColor||"#374151",u=n?e.activeTextColor||"#ffffff":e.inactiveTextColor||"#9ca3af";t.save(),t.beginPath(),this.drawRoundRect(t,r,l,i,a,d),t.fillStyle=g,t.fill();const f=p.fontSize||14,h=p.fontFamily||"Inter";t.font=`${p.fontWeight||600} ${f}px "${h}", sans-serif`,t.fillStyle=u,t.textAlign="center",t.textBaseline="middle",t.fillText(p.text||"Toggle",0,0),t.restore()}renderToggle(t,s){var Mt,ct,It,mt,kt,Ot,vt,Wt,J,ut,$t,St,Pt,Ft;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=s.geometry||{},i=n.width||52,a=n.height||30,r=e.checked??!1,l=e.toggleStyle||{},d=l.width,p=l.height,g=l.cornerRadius,u=r&&d?d:i,f=r&&p?p:a,h=-u/2,m=-f/2,b=r&&g!==void 0?g:e.cornerRadius??e.corner_radius??a/2,c=l.backgroundColor||e.activeColor||"#10b981",S=l.borderColor||e.borderColor||"transparent",v=l.borderWidth??e.borderWidth??0,C=l.knobColor||e.knobColor||"#ffffff",w=r?c:e.inactiveColor||"#374151",I=r?S:e.borderColor||"transparent",k=r?v:e.borderWidth??0,O=r?C:e.knobColor||"#ffffff",T=r&&l.knobShape||e.knobShape||"Circle",A=r&&l.knobSize||e.knobSize||0,D=r&&l.trackShape||e.trackShape||"Pill";e.disabled&&(t.globalAlpha*=.5);const Y=(lt,ht,dt,At,Tt,Ct)=>{try{const Yt=new Path2D(lt),ie=We(lt),te=Math.min(At/ie.width,Tt/ie.height),Zt=!lt.includes("z")&&!lt.includes("Z");t.save(),t.translate(ht,dt),t.scale(te,te),t.translate(-ie.cx,-ie.cy),Zt?(t.strokeStyle=Ct,t.lineWidth=Math.max(1.8,2.2/te),t.lineCap="round",t.lineJoin="round",t.stroke(Yt)):(t.fillStyle=Ct,t.fill(Yt)),t.restore()}catch{t.beginPath(),t.arc(ht,dt,Math.min(At,Tt)/2,0,Math.PI*2),Ct&&(t.fillStyle=Ct),t.fill()}},B=(lt,ht,dt,At,Tt,Ct,Yt)=>{try{const ie=new Path2D(lt),te=We(lt),Zt=Math.min(At/te.width,Tt/te.height);t.save(),t.translate(ht,dt),t.scale(Zt,Zt),t.translate(-te.cx,-te.cy),t.strokeStyle=Ct,t.lineWidth=Yt/Zt,t.lineCap="round",t.lineJoin="round",t.stroke(ie),t.restore()}catch{t.beginPath(),t.arc(ht,dt,Math.min(At,Tt)/2,0,Math.PI*2),Ct&&(t.strokeStyle=Ct),t.lineWidth=Yt,t.stroke()}},R=xe[D]||D,L=!["Pill","Rectangle","Circle"].includes(R),$=xe[T]||T,F=!["Circle","Square","Diamond","Star"].includes($),X=this.createCanvasFill(t,w,u,f);if(L?Y(R,h+u/2,m+f/2,u,f,X):(t.beginPath(),D==="Circle"?t.ellipse(h+u/2,m+f/2,u/2,f/2,0,0,Math.PI*2):D==="Pill"?this.drawRoundRect(t,h,m,u,f,f/2):this.drawRoundRect(t,h,m,u,f,b),X&&(t.fillStyle=X,t.fill())),k>0){const lt=this.createCanvasFill(t,I,u,f);L?B(R,h+u/2,m+f/2,u,f,lt,k):(t.beginPath(),D==="Circle"?t.ellipse(h+u/2,m+f/2,u/2,f/2,0,0,Math.PI*2):D==="Pill"?this.drawRoundRect(t,h,m,u,f,f/2):this.drawRoundRect(t,h,m,u,f,b),t.lineWidth=k,lt&&(t.strokeStyle=lt,t.stroke()))}const M=e.knobPadding??2,E=f-M*2,P=A>0?A:E,_=P/2,V=h+M,G=h+u-M-P,x=r?G:V,U=m+(f-P)/2,q=this.createCanvasFill(t,O,P,P);if(F)Y($,x+_,U+_,P,P,q);else{if(t.beginPath(),T==="Square"){const lt=Math.min(4,_/2);t.roundRect(x,U,P,P,lt)}else if(T==="Diamond"){const lt=x+_,ht=U+_;t.moveTo(lt,ht-_),t.lineTo(lt+_,ht),t.lineTo(lt,ht+_),t.lineTo(lt-_,ht),t.closePath()}else if(T==="Star"){const lt=x+_,ht=U+_,dt=5,At=_,Tt=_*.4;for(let Ct=0;Ct<dt*2;Ct++){const Yt=Ct%2===0?At:Tt,ie=Ct*Math.PI/dt-Math.PI/2,te=lt+Yt*Math.cos(ie),Zt=ht+Yt*Math.sin(ie);Ct===0?t.moveTo(te,Zt):t.lineTo(te,Zt)}t.closePath()}else t.arc(x+_,U+_,_,0,Math.PI*2);q&&(t.fillStyle=q,t.fill())}e.disabled&&(t.globalAlpha*=2);const N=((Mt=e.leftLabel)==null?void 0:Mt.enabled)&&((ct=e.leftLabel)==null?void 0:ct.text),H=((It=e.rightLabel)==null?void 0:It.enabled)&&((mt=e.rightLabel)==null?void 0:mt.text),z=((kt=e.leftLabel)==null?void 0:kt.gap)||8,et=((Ot=e.rightLabel)==null?void 0:Ot.gap)||8;if(N){const lt=(r?(vt=l.leftLabel)==null?void 0:vt.text:null)||((Wt=e.leftLabel)==null?void 0:Wt.text)||"",ht=(r?(J=l.leftLabel)==null?void 0:J.color:null)||((ut=e.leftLabel)==null?void 0:ut.color)||"#f3f4f6",dt=e.leftLabel;t.font=`${dt.fontWeight||400} ${dt.fontSize||12}px "${dt.fontFamily||"Inter"}", sans-serif`,t.fillStyle=ht,t.textBaseline="middle",t.textAlign="right",t.fillText(lt,h-z,0)}if(H){const lt=(r?($t=l.rightLabel)==null?void 0:$t.text:null)||((St=e.rightLabel)==null?void 0:St.text)||"",ht=(r?(Pt=l.rightLabel)==null?void 0:Pt.color:null)||((Ft=e.rightLabel)==null?void 0:Ft.color)||"#f3f4f6",dt=e.rightLabel;t.font=`${dt.fontWeight||400} ${dt.fontSize||12}px "${dt.fontFamily||"Inter"}", sans-serif`,t.fillStyle=ht,t.textBaseline="middle",t.textAlign="left",t.fillText(lt,h+u+et,0)}if(!N&&!H&&e.label&&e.label.text){const lt=e.label,ht=lt.fontSize||14,dt=lt.fontWeight||400,At=lt.fontFamily||"Inter";t.font=`${dt} ${ht}px "${At}", sans-serif`,t.fillStyle=lt.color||"#f3f4f6",t.textBaseline="middle";const Tt=lt.gap||10;let Ct=0,Yt=0;lt.position==="left"?(t.textAlign="right",Ct=h-Tt,Yt=0):lt.position==="right"?(t.textAlign="left",Ct=h+u+Tt,Yt=0):lt.position==="top"?(t.textAlign="center",Ct=0,Yt=m-Tt,t.textBaseline="bottom"):lt.position==="bottom"?(t.textAlign="center",Ct=0,Yt=m+f+Tt,t.textBaseline="top"):(t.textAlign="left",Ct=h+u+Tt,Yt=0),t.fillText(lt.text,Ct,Yt)}}renderCheckbox(t,s){var E,P,_,V;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=((E=s.geometry)==null?void 0:E.width)||140,i=((P=s.geometry)==null?void 0:P.height)||24,a=-n/2,r=-i/2,l=Math.max(12,Math.min(e.boxSize||18,i,n)),d=Math.min(e.cornerRadius??4,l/2),p=e.checked??!1,g=!!e.indeterminate,u=this.lastHoveredObjectId===s.id,f=this.activeObjectId===s.id,h=e.hoverStyle||{},m=e.activeStyle||{};let b=e.activeColor||"#3b82f6";const c=e.inactiveColor||"transparent";let S=e.checkColor||"#ffffff",v=e.borderColor||"#9ca3af";const C=e.borderWidth??1.5;let w=1;f&&m?(m.backgroundColor&&(b=m.backgroundColor),m.borderColor&&(v=m.borderColor),m.checkColor&&(S=m.checkColor),w=m.scale??.95):u&&h&&(h.backgroundColor&&(b=h.backgroundColor),h.borderColor&&(v=h.borderColor),h.checkColor&&(S=h.checkColor),w=h.scale??1);const I=!!(e.label&&e.label.text),k=((_=e.label)==null?void 0:_.gap)??8,O=((V=e.label)==null?void 0:V.position)||"right";let T=a,A=r+(i-l)/2,D=0,Y=0,B="left",R="middle";I?O==="right"?(T=a,A=r+(i-l)/2,D=T+l+k,Y=0,B="left",R="middle"):O==="left"?(T=a+n-l,A=r+(i-l)/2,D=T-k,Y=0,B="right",R="middle"):O==="top"?(T=a+(n-l)/2,A=r+i-l,D=0,Y=A-k,B="center",R="bottom"):O==="bottom"&&(T=a+(n-l)/2,A=r,D=0,Y=A+l+k,B="center",R="top"):(T=a+(n-l)/2,A=r+(i-l)/2);const L=p||g,$=L?b:c,F=L?b:v,X=L?0:C;e.disabled&&(t.globalAlpha*=.5),t.save(),w!==1&&t.scale(w,w),t.beginPath(),this.drawRoundRect(t,T,A,l,l,d);const M=this.createCanvasFill(t,$,l,l);if(M&&(t.fillStyle=M,t.fill()),X>0){t.lineWidth=X;const G=this.createCanvasFill(t,F,l,l);G&&(t.strokeStyle=G,t.stroke())}else if(L){t.lineWidth=1;const G=this.createCanvasFill(t,b,l,l);G&&(t.strokeStyle=G,t.stroke())}if(g){t.save(),t.beginPath();const G=this.createCanvasFill(t,S,l,l);t.strokeStyle=G||S,t.lineWidth=Math.max(2,l*.12),t.lineCap="round",t.moveTo(T+l*.25,A+l*.5),t.lineTo(T+l*.75,A+l*.5),t.stroke(),t.restore()}else if(p){t.save(),t.beginPath();const G=this.createCanvasFill(t,S,l,l);t.strokeStyle=G||S,t.lineWidth=Math.max(2,l*.12),t.lineCap="round",t.lineJoin="round";const x=T+l*.24,U=A+l*.5,q=T+l*.44,N=A+l*.7,H=T+l*.76,z=A+l*.28;t.moveTo(x,U),t.lineTo(q,N),t.lineTo(H,z),t.stroke(),t.restore()}if(e.disabled&&(t.globalAlpha*=2),I&&e.label&&e.label.text){const G=e.label;t.save(),t.font=`${G.fontWeight||400} ${G.fontSize||14}px "${G.fontFamily||"Inter"}", sans-serif`,t.fillStyle=G.color||"#111827",t.textAlign=B,t.textBaseline=R,t.fillText(G.text,D,Y),t.restore()}t.restore()}renderRadioGroup(t,s){var B,R;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=((B=s.geometry)==null?void 0:B.width)||180,i=((R=s.geometry)==null?void 0:R.height)||100,a=-n/2,r=-i/2;let l=e.optionsList||["Option 1","Option 2","Option 3"];if(e.isDataVarEnabled&&e.dataInputId){let L=this.inputs.get(e.dataInputId);if(L===void 0){const $=this.inputNameMap.get(e.dataInputId);$&&$.length>0&&(L=this.inputs.get($[0]))}L&&Array.isArray(L)&&(l=L.map($=>typeof $=="string"?$:String($)))}const d=e.selectedValue,p=e.orientation||"vertical",g=e.itemGap!==void 0?e.itemGap:16,u=this.lastHoveredObjectId===s.id,f=this.activeObjectId===s.id,h=e.hoverStyle||{},m=e.activeStyle||{};let b=e.activeColor||"#3b82f6",c=e.inactiveColor||"#4b5563",S=e.textColor||"#ffffff",v=1;f&&m?(m.activeColor&&(b=m.activeColor),m.inactiveColor&&(c=m.inactiveColor),m.textColor&&(S=m.textColor),v=m.scale??.95):u&&h&&(h.activeColor&&(b=h.activeColor),h.inactiveColor&&(c=h.inactiveColor),h.textColor&&(S=h.textColor),v=h.scale??1);const C=e.fontSize||14,w=e.fontFamily||"Inter",I=e.fontWeight||400;t.save(),e.disabled&&(t.globalAlpha*=.5),v!==1&&t.scale(v,v);const k=8,O=k*2,T=e.radioShape||"circle",A=e.borderWidth!==void 0?e.borderWidth:2,D=e.fillEmpty||"transparent",Y=(L,$,F,X)=>{if(t.beginPath(),X==="custom"&&e.customShapePath)try{const M=new Path2D(e.customShapePath),E=We(e.customShapePath),P=Math.min(F*2/E.width,F*2/E.height);t.save(),t.translate(L,$),t.scale(P,P),t.translate(-E.cx,-E.cy),!e.customShapePath.includes("z")&&!e.customShapePath.includes("Z")?(t.strokeStyle=t.fillStyle,t.lineWidth=Math.max(1.8,2.2/P),t.lineCap="round",t.lineJoin="round",t.stroke(M)):t.fill(M),t.restore();return}catch{t.arc(L,$,F,0,Math.PI*2);return}if(X==="square"){const M=F*1.6;t.rect(L-M/2,$-M/2,M,M)}else if(X==="diamond"){const M=F*1.4;t.moveTo(L,$-M),t.lineTo(L+M,$),t.lineTo(L,$+M),t.lineTo(L-M,$),t.closePath()}else if(X==="heart"){const M=F*.9;t.moveTo(L,$+M*.7),t.bezierCurveTo(L-M*1.5,$-M*.3,L-M*.5,$-M*1.5,L,$-M*.5),t.bezierCurveTo(L+M*.5,$-M*1.5,L+M*1.5,$-M*.3,L,$+M*.7)}else if(X==="star"){const M=F*1.1,E=F*.5;for(let P=0;P<5;P++){const _=(P*72-90)*Math.PI/180,V=(P*72+36-90)*Math.PI/180;P===0?t.moveTo(L+M*Math.cos(_),$+M*Math.sin(_)):t.lineTo(L+M*Math.cos(_),$+M*Math.sin(_)),t.lineTo(L+E*Math.cos(V),$+E*Math.sin(V))}t.closePath()}else t.arc(L,$,F,0,Math.PI*2)};if(t.font=`${I} ${C}px "${w}", sans-serif`,t.textBaseline="middle",t.textAlign="left",p==="vertical"){const L=Math.max(O,C)+g,$=l.length*L-g,F=r+Math.max(0,(i-$)/2);l.forEach((X,M)=>{const E=F+k+M*L,P=d===X,_=this.createCanvasFill(t,b,O,O),V=this.createCanvasFill(t,c,O,O);P?(t.fillStyle=_||b,Y(a+k,E,k,T),t.fill(),t.strokeStyle=_||b,t.lineWidth=A,Y(a+k,E,k,T),t.stroke()):(D!=="transparent"&&(t.fillStyle=D,Y(a+k,E,k,T),t.fill()),t.strokeStyle=V||c,t.lineWidth=A,Y(a+k,E,k,T),t.stroke()),t.fillStyle=S,t.fillText(X,a+O+8,E)})}else{const L=r+i/2;let $=0;t.font=`${I} ${C}px "${w}", sans-serif`,l.forEach(M=>{$+=O+6+t.measureText(M).width+g}),$-=g;let X=a+Math.max(0,(n-$)/2);l.forEach(M=>{const E=d===M,P=t.measureText(M).width,_=this.createCanvasFill(t,b,O,O),V=this.createCanvasFill(t,c,O,O);E?(t.fillStyle=_||b,Y(X+k,L,k,T),t.fill(),t.strokeStyle=_||b,t.lineWidth=A,Y(X+k,L,k,T),t.stroke()):(D!=="transparent"&&(t.fillStyle=D,Y(X+k,L,k,T),t.fill()),t.strokeStyle=V||c,t.lineWidth=A,Y(X+k,L,k,T),t.stroke()),t.fillStyle=S,t.fillText(M,X+O+6,L),X+=O+6+P+g})}if(t.restore(),e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const L=e.label;t.save(),t.font=`${L.fontWeight||400} ${L.fontSize||14}px "${L.fontFamily||"Inter"}", sans-serif`,t.fillStyle=L.color||"#9ca3af",t.textBaseline="middle";const $=L.gap||8;let F=0,X=0;L.position==="left"?(t.textAlign="right",F=a-$,X=0):L.position==="right"?(t.textAlign="left",F=a+n+$,X=0):L.position==="top"?(t.textAlign="center",F=0,X=r-$,t.textBaseline="bottom"):L.position==="bottom"&&(t.textAlign="center",F=0,X=r+i+$,t.textBaseline="top"),t.fillText(L.text,F,X),t.restore()}}renderBarChart(t,s){var $,F,X;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{};let n={...e};if(e.isDataVarEnabled&&e.dataInputId){let M=this.inputs.get(e.dataInputId);if(M===void 0){const E=this.inputNameMap.get(e.dataInputId);E&&E.length>0&&(M=this.inputs.get(E[0]))}M&&Array.isArray(M)&&(n.categories=M.map(E=>typeof E=="string"?E:String(E)))}if(e.isDatasetsVarEnabled&&(($=e.datasetInputIds)==null?void 0:$.length)>0){const M=e.datasetInputIds.map((E,P)=>{var G;let _=this.inputs.get(E);if(_===void 0){const x=this.inputNameMap.get(E);x&&x.length>0&&(_=this.inputs.get(x[0]))}const V=((G=e.datasets)==null?void 0:G[P])||{id:`ds-${P}`,label:`Series ${P+1}`,data:[],color:"#6366f1"};return _&&Array.isArray(_)?{...V,data:_.map(x=>typeof x=="number"?x:parseFloat(x)||0)}:V});n.datasets=M}const i={width:((F=s.geometry)==null?void 0:F.width)||300,height:((X=s.geometry)==null?void 0:X.height)||180,chartType:n.chartType||"grouped",datasets:n.datasets||[{id:"ds-1",label:"Revenue",data:[42,67,31,55,78,48],color:"#6366f1"}],categories:n.categories||["Jan","Feb","Mar","Apr","May","Jun"],orientation:n.orientation||"vertical",barWidth:n.barWidth!==void 0?n.barWidth:14,barGap:n.barGap!==void 0?n.barGap:4,barCornerRadius:n.barCornerRadius!==void 0?n.barCornerRadius:5,showXAxis:!!n.showXAxis,showYAxis:!!n.showYAxis,xAxisColor:n.xAxisColor||"rgba(255,255,255,0.15)",yAxisColor:n.yAxisColor||"rgba(255,255,255,0.15)",showXLabels:n.showXLabels!==void 0?!!n.showXLabels:!0,showYLabels:!!n.showYLabels,axisLabelColor:n.axisLabelColor||"rgba(255,255,255,0.55)",axisLabelFontSize:n.axisLabelFontSize||9,showLegend:n.showLegend!==void 0?!!n.showLegend:!0,legendColor:n.legendColor||"rgba(255,255,255,0.7)",legendFontSize:n.legendFontSize||9,showGridLines:n.showGridLines!==void 0?!!n.showGridLines:!0,gridColor:n.gridColor||"rgba(255,255,255,0.06)",cardBackground:n.cardBackground||"#ffffff",cardBackgroundOpacity:n.cardBackgroundOpacity!==void 0?n.cardBackgroundOpacity:.04,cardBorderColor:n.cardBorderColor||"rgba(255,255,255,0.08)",barGradient:n.barGradient!==void 0?!!n.barGradient:!0,gradientStartColor:n.gradientStartColor||"",gradientEndOpacity:n.gradientEndOpacity!==void 0?n.gradientEndOpacity:.27,showValueOnTop:!!n.showValueOnTop,valueFontSize:n.valueFontSize||10,valueColor:n.valueColor||"",valueFontWeight:n.valueFontWeight||"bold",barStyle:n.barStyle||"solid",barBorderWidth:n.barBorderWidth!==void 0?n.barBorderWidth:1,barBorderColor:n.barBorderColor||"auto",enableShadows:!!n.enableShadows,shadowColor:n.shadowColor||"rgba(0,0,0,0.5)",shadowBlur:n.shadowBlur!==void 0?n.shadowBlur:4,shadowOffsetY:n.shadowOffsetY!==void 0?n.shadowOffsetY:2,xAxisLineWidth:n.xAxisLineWidth!==void 0?n.xAxisLineWidth:1,yAxisLineWidth:n.yAxisLineWidth!==void 0?n.yAxisLineWidth:1,gridLineWidth:n.gridLineWidth!==void 0?n.gridLineWidth:1,gridLineDash:n.gridLineDash||[3,4],showHoverTooltip:n.showHoverTooltip!==void 0?!!n.showHoverTooltip:!0,hoverHighlight:n.hoverHighlight!==void 0?!!n.hoverHighlight:!0,hoverHighlightColor:n.hoverHighlightColor||"rgba(255, 255, 255, 0.22)",tooltipBg:n.tooltipBg||"#111827",tooltipTextColor:n.tooltipTextColor||"#f9fafb",tooltipRadius:n.tooltipRadius!==void 0?n.tooltipRadius:6,_hexToRgb:function(M,E){if(M.startsWith("rgba")||M.startsWith("rgb"))return M;M.startsWith("#")||(M="#"+M),M.length===4&&(M="#"+M[1]+M[1]+M[2]+M[2]+M[3]+M[3]);const P=parseInt(M.slice(1,3),16),_=parseInt(M.slice(3,5),16),V=parseInt(M.slice(5,7),16);return`rgba(${P},${_},${V},${E})`},_resolveColor:function(M,E){return typeof M=="string"?M:"#6366f1"},_makeGradient:function(M,E,P,_,V,G){if(!this.barGradient)return E;const x=this.gradientStartColor||E,U=M.createLinearGradient(P,_,V,G);return U.addColorStop(0,E),U.addColorStop(1,this._hexToRgb(x,this.gradientEndOpacity)),U},_drawRoundedBar:function(M,E,P,_,V,G,x){if(G=Math.min(G,Math.min(Math.abs(_),Math.abs(V))/2),G<=0||_===0||V===0){M.rect(E,P,_,V);return}M.beginPath(),x?(M.moveTo(E,P+V),M.lineTo(E,P+G),M.quadraticCurveTo(E,P,E+G,P),M.lineTo(E+_-G,P),M.quadraticCurveTo(E+_,P,E+_,P+G),M.lineTo(E+_,P+V),M.lineTo(E,P+V)):(M.moveTo(E,P),M.lineTo(E+_-G,P),M.quadraticCurveTo(E+_,P,E+_,P+G),M.lineTo(E+_,P+V-G),M.quadraticCurveTo(E+_,P+V,E+_-G,P+V),M.lineTo(E,P+V),M.lineTo(E,P)),M.closePath()}},a=i.width,r=i.height,l=-a/2,d=-r/2;if(!i.datasets||i.datasets.length===0||i.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}let p=-1/0,g=1/0;const u=i.categories.length,f=i.datasets.length;if(i.chartType==="stacked")for(let M=0;M<u;M++){let E=0,P=0;i.datasets.forEach(_=>{const V=_.data[M]??0;V>=0?E+=V:P+=V}),E>p&&(p=E),P<g&&(g=P)}else i.datasets.forEach(M=>{M.data&&M.data.forEach(E=>{E>p&&(p=E),E<g&&(g=E)})});isFinite(p)||(p=10),isFinite(g)||(g=0),p=Math.max(p,0),g=Math.min(g,0);const h=p-g||10;t.save();const m=n.entranceStyle||{},b=m.type||"none",c=this.getEntranceProgress(s.id,m,n.previewState||"default");if(b!=="none"){if(b==="fade")t.globalAlpha*=c;else if(b==="draw")t.beginPath(),t.rect(-a/2-10,-r/2-10,(a+20)*c,r+20),t.clip();else if(b==="barGrow"){const M=-r/2+r*(1-c);t.beginPath(),t.rect(-a/2-10,M,a+20,r+20),t.clip()}else if(b==="slideUp"){const M=(1-c)*r*.4;t.translate(0,M),t.globalAlpha*=Math.min(1,c*2)}else b==="stagger"&&(i._staggerProg=c);m.showLegend===!1&&(i.showLegend=!1),m.showAxes===!1&&(i.showXAxis=!1,i.showYAxis=!1),m.showLabels===!1&&(i.showXLabels=!1,i.showYLabels=!1),m.showGrid===!1&&(i.showGridLines=!1)}i.enableShadows&&(t.shadowColor=i.shadowColor,t.shadowBlur=i.shadowBlur,t.shadowOffsetY=i.shadowOffsetY),t.font=i.axisLabelFontSize+"px Inter, sans-serif";const S=i.showYLabels?t.measureText(p.toFixed(0)).width+14:10,v=i.showXLabels?i.axisLabelFontSize+12:8,w=(i.showLegend&&f>0?i.legendFontSize+10:0)+8,I=10,k=l+S,O=d+w,T=a-S-I,A=r-w-v;if(i.enableShadows&&(t.shadowColor="transparent"),t.beginPath(),t.roundRect(l,d,a,r,10),t.fillStyle=i._hexToRgb(i.cardBackground,i.cardBackgroundOpacity),t.fill(),t.strokeStyle=i.cardBorderColor,t.lineWidth=1,t.stroke(),i.showLegend&&f>0){t.font=i.legendFontSize+"px Inter, sans-serif",t.textBaseline="middle";const M=d+12;let E=k;i.datasets.forEach((P,_)=>{const V=i._resolveColor(P.color,_),G=P.label||"Series "+(_+1),x=7;t.beginPath(),t.roundRect(E,M-x/2,x,x,2),t.fillStyle=V,t.fill(),t.fillStyle=i.legendColor,t.textAlign="left",t.fillText(G,E+x+4,M),E+=t.measureText(G).width+x+16})}const D=4;if(i.showGridLines){t.setLineDash(i.gridLineDash||[]),t.lineWidth=i.gridLineWidth||1,t.strokeStyle=i.gridColor;for(let M=0;M<=D;M++)if(i.orientation==="horizontal"){const E=k+M/D*T;t.beginPath(),t.moveTo(E,O),t.lineTo(E,O+A),t.stroke()}else{const E=O+M/D*A;t.beginPath(),t.moveTo(k,E),t.lineTo(k+T,E),t.stroke()}t.setLineDash([])}if(i.showYLabels){t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=i.axisLabelColor;for(let M=0;M<=D;M++)if(i.orientation==="horizontal"){const E=g+M/D*h,P=k+M/D*T;t.textAlign="center",t.fillText(E.toFixed(0),P,O+A+i.axisLabelFontSize)}else{const E=p-M/D*h,P=O+M/D*A;t.textAlign="right",t.fillText(E.toFixed(0),k-6,P)}}t.setLineDash([]),i.showXAxis&&(t.lineWidth=i.xAxisLineWidth||1,t.strokeStyle=i.xAxisColor,t.beginPath(),t.moveTo(k,O+A),t.lineTo(k+T,O+A),t.stroke()),i.showYAxis&&(t.lineWidth=i.yAxisLineWidth||1,t.strokeStyle=i.yAxisColor,t.beginPath(),t.moveTo(k,O),t.lineTo(k,O+A),t.stroke()),i.enableShadows&&(t.shadowColor=i.shadowColor);const Y=[],B=this.graphHoverStates.get(s.id),R=B==null?void 0:B.hoveredCatIdx,L=B==null?void 0:B.hoveredDsIdx;if(i.chartType==="stacked")if(i.orientation==="horizontal"){const M=A/u;for(let E=0;E<u;E++){const P=O+E*M+M/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=i.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[E]||"",k-5,P),i.enableShadows&&(t.shadowColor=i.shadowColor));let _=k;i.datasets.forEach((V,G)=>{const x=V.data[E]??0;if(x===0)return;const U=x/h*T,q=Math.min(i.barWidth*f+i.barGap,M-8),N=P-q/2,H=_;_+=U;const z=i._resolveColor(V.color,G);Y.push({catIdx:E,dsIdx:G,category:i.categories[E]||"",label:V.label||`Series ${G+1}`,val:x,color:z,x:H,y:N,w:U,h:q}),t.beginPath(),t.fillStyle=i._makeGradient(t,z,H,N,H+U,N);const et=i._staggerProg;if(et!==void 0&&b==="stagger"){const ct=u*f,It=E*f+G,mt=Math.max(0,Math.min(1,et*ct-It));t.globalAlpha*=mt}i._drawRoundedBar(t,H,N,U,q,G===f-1?i.barCornerRadius:0,!1),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?z:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),R===E&&L===G&&i.hoverHighlight&&(t.save(),t.fillStyle=i.hoverHighlightColor,i._drawRoundedBar(t,H,N,U,q,G===f-1?i.barCornerRadius:0,!1),t.fill(),t.restore())})}}else{const M=T/u;for(let E=0;E<u;E++){const P=k+E*M+M/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillStyle=i.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[E]||"",P,O+A+5),i.enableShadows&&(t.shadowColor=i.shadowColor));let _=O+A;i.datasets.forEach((V,G)=>{const x=V.data[E]??0;if(x===0)return;const U=x/h*A,q=Math.min(i.barWidth*f+i.barGap,M-8),N=P-q/2,H=_-U;_-=U;const z=i._resolveColor(V.color,G);Y.push({catIdx:E,dsIdx:G,category:i.categories[E]||"",label:V.label||`Series ${G+1}`,val:x,color:z,x:N,y:H,w:q,h:U}),t.beginPath(),t.fillStyle=i._makeGradient(t,z,N,H,N,H+U);const et=i._staggerProg;if(et!==void 0&&b==="stagger"){const ct=u*f,It=E*f+G,mt=Math.max(0,Math.min(1,et*ct-It));t.globalAlpha*=mt}i._drawRoundedBar(t,N,H,q,U,G===f-1?i.barCornerRadius:0,!0),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?z:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),R===E&&L===G&&i.hoverHighlight&&(t.save(),t.fillStyle=i.hoverHighlightColor,i._drawRoundedBar(t,N,H,q,U,G===f-1?i.barCornerRadius:0,!0),t.fill(),t.restore())})}}else if(i.orientation==="horizontal"){const M=A/u,E=f*i.barWidth+Math.max(0,(f-1)*i.barGap),P=k+(0-g)/h*T;for(let _=0;_<u;_++){const V=O+_*M+M/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=i.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[_]||"",k-5,V),i.enableShadows&&(t.shadowColor=i.shadowColor));const G=V-E/2;i.datasets.forEach((x,U)=>{const q=x.data[_]??0,N=Math.abs(q/h*T);if(N<1)return;const H=G+U*(i.barWidth+i.barGap),z=q>=0?P:P-N,et=i._resolveColor(x.color,U);Y.push({catIdx:_,dsIdx:U,category:i.categories[_]||"",label:x.label||`Series ${U+1}`,val:q,color:et,x:z,y:H,w:N,h:i.barWidth}),t.beginPath(),t.fillStyle=i._makeGradient(t,et,z,H,z+N,H);const Mt=i._staggerProg;if(Mt!==void 0&&b==="stagger"){const It=u*f,mt=_*f+U,kt=Math.max(0,Math.min(1,Mt*It-mt));t.globalAlpha*=kt}i._drawRoundedBar(t,z,H,N,i.barWidth,i.barCornerRadius,!1),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?et:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),R===_&&L===U&&i.hoverHighlight&&(t.save(),t.fillStyle=i.hoverHighlightColor,i._drawRoundedBar(t,z,H,N,i.barWidth,i.barCornerRadius,!1),t.fill(),t.restore()),i.showValueOnTop&&q!==0&&(t.font=(i.valueFontWeight||"bold")+" "+(i.valueFontSize||10)+"px Inter, sans-serif",t.textAlign=q>=0?"left":"right",t.textBaseline="middle",t.fillStyle=i.valueColor==="auto"?et:i.valueColor||"#fff",t.shadowColor="transparent",t.fillText(q.toString(),q>=0?z+N+4:z-4,H+i.barWidth/2),i.enableShadows&&(t.shadowColor=i.shadowColor))})}}else{const M=T/u,E=f*i.barWidth+Math.max(0,(f-1)*i.barGap),P=O+A-(0-g)/h*A;for(let _=0;_<u;_++){const V=k+_*M+M/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillStyle=i.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[_]||"",V,O+A+5),i.enableShadows&&(t.shadowColor=i.shadowColor));const G=V-E/2;i.datasets.forEach((x,U)=>{const q=x.data[_]??0,N=Math.abs(q/h*A);if(N<1)return;const H=G+U*(i.barWidth+i.barGap),z=q>=0?P-N:P,et=i._resolveColor(x.color,U);Y.push({catIdx:_,dsIdx:U,category:i.categories[_]||"",label:x.label||`Series ${U+1}`,val:q,color:et,x:H,y:z,w:i.barWidth,h:N}),t.beginPath(),t.fillStyle=i._makeGradient(t,et,H,z,H,z+N);const Mt=i._staggerProg;if(Mt!==void 0&&b==="stagger"){const It=u*f,mt=_*f+U,kt=Math.max(0,Math.min(1,Mt*It-mt));t.globalAlpha*=kt}i._drawRoundedBar(t,H,z,i.barWidth,N,i.barCornerRadius,!0),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?et:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),R===_&&L===U&&i.hoverHighlight&&(t.save(),t.fillStyle=i.hoverHighlightColor,i._drawRoundedBar(t,H,z,i.barWidth,N,i.barCornerRadius,!0),t.fill(),t.restore()),i.showValueOnTop&&q!==0&&(t.font=(i.valueFontWeight||"bold")+" "+(i.valueFontSize||10)+"px Inter, sans-serif",t.textAlign="center",t.textBaseline=q>=0?"bottom":"top",t.fillStyle=i.valueColor==="auto"?et:i.valueColor||"#fff",t.shadowColor="transparent",t.fillText(q.toString(),H+i.barWidth/2,q>=0?z-4:z+N+4),i.enableShadows&&(t.shadowColor=i.shadowColor))})}}if(this.barChartRenderedBars.set(s.id,Y),i.showHoverTooltip&&R!==null&&R!==void 0&&L!==null&&L!==void 0){const M=Y.find(E=>E.catIdx===R&&E.dsIdx===L);if(M){t.save();const E=10,P=8,_=14,V=12,x=P*2+_+V+16,U=Math.max(...Y.map(Ot=>Math.abs(Ot.val))),q=U>0?Math.round(Math.abs(M.val)/U*100):0;t.font="bold 10px Inter, system-ui, sans-serif";const N=t.measureText(M.category||"Category").width;t.font="8px Inter, system-ui, sans-serif";const H=`${q}% of max (${U})`,z=t.measureText(H).width;t.font="9px Inter, system-ui, sans-serif";const et=t.measureText(`${M.label}: ${M.val}`).width+16,Mt=Math.max(N,z,et)+E*2;let ct=M.x+M.w/2-Mt/2,It=M.y-x-8;ct<-a/2+6&&(ct=-a/2+6),ct+Mt>a/2-6&&(ct=a/2-Mt-6),It<-r/2+6&&(It=M.y+M.h+8),It+x>r/2-6&&(It=r/2-x-6),t.shadowColor="rgba(0, 0, 0, 0.35)",t.shadowBlur=10,t.shadowOffsetX=0,t.shadowOffsetY=4,t.beginPath(),this.drawRoundRect(t,ct,It,Mt,x,i.tooltipRadius),t.fillStyle=i.tooltipBg,t.fill(),t.shadowColor="transparent",t.lineWidth=1,t.strokeStyle="rgba(255, 255, 255, 0.12)",t.stroke(),t.font="bold 10px Inter, system-ui, sans-serif",t.fillStyle=i.tooltipTextColor,t.textAlign="left",t.textBaseline="top",t.fillText(M.category,ct+E,It+P),t.font="8px Inter, system-ui, sans-serif",t.fillStyle="rgba(255,255,255,0.5)",t.fillText(H,ct+E,It+P+_);const mt=It+P+_+V+2;t.beginPath(),t.arc(ct+E+4,mt+5,3.5,0,Math.PI*2),t.fillStyle=M.color,t.fill(),t.font="9px Inter, system-ui, sans-serif",t.fillStyle=i.tooltipTextColor,t.fillText(`${M.label}: `,ct+E+12,mt);const kt=t.measureText(`${M.label}: `).width;t.font="bold 9px Inter, system-ui, sans-serif",t.fillStyle=M.color,t.fillText(`${M.val}`,ct+E+12+kt,mt),t.restore()}}t.restore()}renderPieChart(t,s){var k,O;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=e.colorPalette==="custom"&&Array.isArray(e.customPalette)&&e.customPalette.length>0?e.customPalette:ys[e.colorPalette||"vibrant"]||ys.vibrant;let i=e.slices||[{id:"slice-1",label:"Item 1",value:45,color:""}];if(e.isDataVarEnabled&&e.dataInputId){let T=this.inputs.get(e.dataInputId);if(T===void 0){const A=this.inputNameMap.get(e.dataInputId);A&&A.length>0&&(T=this.inputs.get(A[0]))}T&&Array.isArray(T)&&(i=T.map((A,D)=>{var Y,B;return{id:`slice-${D}`,label:((Y=i[D])==null?void 0:Y.label)||`Item ${D+1}`,value:typeof A=="number"?A:0,color:((B=i[D])==null?void 0:B.color)||""}}))}const a={width:((k=s.geometry)==null?void 0:k.width)||180,height:((O=s.geometry)==null?void 0:O.height)||180,chartType:e.chartType||"donut",slices:i,innerRadius:e.innerRadius!==void 0?e.innerRadius:.55,sliceGap:e.sliceGap!==void 0?e.sliceGap:3,showLabels:!!e.showLabels,labelColor:e.labelColor||"#000000",labelFontSize:e.labelFontSize||10,showLegend:e.showLegend!==void 0?!!e.showLegend:!0,legendColor:e.legendColor||"rgba(0,0,0,0.65)",legendFontSize:e.legendFontSize||9,showCenterText:e.showCenterText!==void 0?!!e.showCenterText:!0,centerLabel:e.centerLabel||"Total",centerTextColor:e.centerTextColor||"#000000",centerLabelColor:e.centerLabelColor||"rgba(0,0,0,0.4)",cardBackground:e.cardBackground||"#ffffff",cardBackgroundOpacity:e.cardBackgroundOpacity!==void 0?e.cardBackgroundOpacity:.04,cardBorderColor:e.cardBorderColor||"rgba(0,0,0,0.08)",showHoverTooltip:e.showHoverTooltip!==void 0?!!e.showHoverTooltip:!0,hoverExplode:e.hoverExplode!==void 0?!!e.hoverExplode:!0,tooltipBg:e.tooltipBg||"#111827",tooltipTextColor:e.tooltipTextColor||"#f9fafb",tooltipRadius:e.tooltipRadius!==void 0?e.tooltipRadius:6,_resolveSliceColor:function(T,A){return T.color?T.color:n[A%n.length]},_hexToRgb:function(T){if(T.startsWith("rgba")||T.startsWith("rgb"))return T;const A=T.replace("#",""),D=parseInt(A.substring(0,2),16),Y=parseInt(A.substring(2,4),16),B=parseInt(A.substring(4,6),16);return`rgba(${D},${Y},${B},${a.cardBackgroundOpacity})`}},r=a.width,l=a.height;if(!a.slices||a.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 d=a.slices.reduce((T,A)=>T+(A.value||0),0);if(d<=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}t.save();const p=e.entranceStyle||{},g=p.type||"none",u=this.getEntranceProgress(s.id,p,e.previewState||"default");if(g!=="none"){if(g==="fade")t.globalAlpha*=u;else if(g==="draw")t.beginPath(),t.rect(-r/2-10,-l/2-10,(r+20)*u,l+20),t.clip();else if(g==="radial"){const T=Math.sqrt(r*r+l*l)/2;t.beginPath(),t.arc(0,0,T*u,0,Math.PI*2),t.clip()}else if(g==="sliceReveal"){if(i.reduce((A,D)=>A+(D.value||0),0)>0){const A=-Math.PI/2+u*Math.PI*2;t.beginPath(),t.moveTo(0,0),t.arc(0,0,Math.max(r,l),-Math.PI/2,A),t.lineTo(0,0),t.clip()}}else if(g==="spinIn"){const T=(1-u)*Math.PI*2;t.rotate(T),t.globalAlpha*=u}else if(g==="grow"){const T=u;t.scale(T,T),t.globalAlpha*=Math.min(1,u*2)}p.showLegend===!1&&(a.showLegend=!1),p.showLabels===!1&&(a.showLabels=!1),p.showCenterText===!1&&(a.showCenterText=!1)}const f=a._hexToRgb(a.cardBackground);t.beginPath(),t.roundRect(-r/2,-l/2,r,l,10),t.fillStyle=f,t.fill(),t.strokeStyle=a.cardBorderColor,t.lineWidth=1,t.stroke();const h=a.showLegend?Math.ceil(a.slices.length/2):0,m=h>0?h*(a.legendFontSize+8)+10:0,b=l-m-16,c=Math.min(r-24,b)/2,S=0,v=-m/2,C=[],w=this.graphHoverStates.get(s.id),I=(w==null?void 0:w.hoveredSliceIndex)??null;if(a.chartType==="rose"){const T=Math.max(...a.slices.map(Y=>Y.value||0)),A=Math.PI*2/a.slices.length,D=c>0?a.sliceGap/c:0;a.slices.forEach((Y,B)=>{const R=Y.value||0;if(R===0)return;const L=R/T*c,$=-Math.PI/2+B*A+D/2,F=$+A-D,X=a._resolveSliceColor(Y,B),M=$+(F-$)/2,E=I===B;let P=S,_=v;if(E&&a.hoverExplode&&(P+=Math.cos(M)*6,_+=Math.sin(M)*6),C.push({index:B,startA:$,endA:F,innerR:0,outerR:L,cx:P,cy:_,slice:Y,color:X,pct:Math.round(R/d*100)}),t.beginPath(),t.moveTo(P,_),t.arc(P,_,L,$,F),t.closePath(),t.fillStyle=X+"cc",t.fill(),t.strokeStyle=X,t.lineWidth=E?2.5:1.5,t.stroke(),a.showLabels){const V=P+L*.65*Math.cos(M),G=_+L*.65*Math.sin(M),x=Math.round(R/d*100);t.save(),t.font=`bold ${a.labelFontSize}px Inter, sans-serif`,t.fillStyle=a.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${x}%`,V,G),t.restore()}})}else{const T=a.chartType==="pie"?0:a.innerRadius,A=c*Math.max(0,T),D=c>0?a.sliceGap/c:0;let Y=-Math.PI/2;if(a.slices.forEach((B,R)=>{const L=B.value||0;if(L===0){Y+=L/d*Math.PI*2;return}const $=L/d*Math.PI*2,F=Y+D/2,X=Y+$-D/2;if(X<=F){Y+=$;return}const M=a._resolveSliceColor(B,R),E=F+(X-F)/2,P=I===R;let _=S,V=v;if(P&&a.hoverExplode&&(_+=Math.cos(E)*6,V+=Math.sin(E)*6),C.push({index:R,startA:F,endA:X,innerR:A,outerR:c,cx:_,cy:V,slice:B,color:M,pct:Math.round(L/d*100)}),t.beginPath(),t.fillStyle=M,A<=0?(t.moveTo(_,V),t.arc(_,V,c,F,X),t.lineTo(_,V)):(t.moveTo(_+c*Math.cos(F),V+c*Math.sin(F)),t.arc(_,V,c,F,X),t.arc(_,V,A,X,F,!0),t.closePath()),t.fill(),P&&(t.lineWidth=2,t.strokeStyle="#ffffff",t.stroke()),a.showLabels){const G=A+(c-A)/2,x=_+G*Math.cos(E),U=V+G*Math.sin(E),q=Math.round(L/d*100);t.save(),t.font=`bold ${a.labelFontSize}px Inter, sans-serif`,t.fillStyle=a.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${q}%`,x,U),t.restore()}Y+=$}),a.chartType==="donut"&&a.showCenterText&&A>14){const B=Math.round(d),R=Math.min(Math.floor(A*.52),20),L=Math.min(Math.floor(A*.26),10);t.textAlign="center",t.textBaseline="middle",t.font=`bold ${R}px Inter, sans-serif`,t.fillStyle=a.centerTextColor,t.fillText(B.toString(),S,v-L*.5),t.font=`${L}px Inter, sans-serif`,t.fillStyle=a.centerLabelColor,t.fillText(a.centerLabel,S,v+R*.6)}}if(this.pieChartRenderedSlices.set(s.id,C),a.showLegend&&a.slices.length>0){t.font=`${a.legendFontSize}px Inter, sans-serif`;const T=2,A=r/T,D=a.legendFontSize+8,Y=l/2-m+10,B=-r/2+10;a.slices.forEach((R,L)=>{const $=L%T,F=Math.floor(L/T),X=B+$*A,M=Y+F*D,E=a._resolveSliceColor(R,L),P=7;t.beginPath(),t.roundRect(X,M-P/2,P,P,2),t.fillStyle=E,t.fill(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=a.legendColor;const _=Math.round((R.value||0)/d*100),V=`${R.label||"Item"} ${_}%`,G=A-P-20;let x=V;for(;t.measureText(x).width>G&&x.length>4;)x=x.slice(0,-4)+"…";t.fillText(x,X+P+4,M)})}if(a.showHoverTooltip&&I!==null&&I!==void 0){const T=C.find(A=>A.index===I);if(T){t.save();const A=10,D=8,Y=14,B=12,L=D*2+Y+B+16,$=i.reduce((N,H)=>N+(H.value||0),0);t.font="bold 10px Inter, system-ui, sans-serif";const F=t.measureText(T.slice.label||"Item").width;t.font="8px Inter, system-ui, sans-serif";const X=`of ${$} total`,M=t.measureText(X).width;t.font="9px Inter, system-ui, sans-serif";const E=`${T.slice.value} (${T.pct}%)`,P=t.measureText(E).width+16,_=Math.max(F,M,P)+A*2,V=T.startA+(T.endA-T.startA)/2,G=(T.innerR+T.outerR)/2;let x=T.cx+Math.cos(V)*(G+10)-_/2,U=T.cy+Math.sin(V)*(G+10)-L/2;x<-r/2+6&&(x=-r/2+6),x+_>r/2-6&&(x=r/2-_-6),U<-l/2+6&&(U=-l/2+6),U+L>l/2-6&&(U=l/2-L-6),t.shadowColor="rgba(0, 0, 0, 0.35)",t.shadowBlur=10,t.shadowOffsetX=0,t.shadowOffsetY=4,t.beginPath(),this.drawRoundRect(t,x,U,_,L,a.tooltipRadius),t.fillStyle=a.tooltipBg,t.fill(),t.shadowColor="transparent",t.lineWidth=1,t.strokeStyle="rgba(255, 255, 255, 0.12)",t.stroke(),t.font="bold 10px Inter, system-ui, sans-serif",t.fillStyle=a.tooltipTextColor,t.textAlign="left",t.textBaseline="top",t.fillText(T.slice.label||"Item",x+A,U+D),t.font="8px Inter, system-ui, sans-serif",t.fillStyle="rgba(255,255,255,0.5)",t.fillText(X,x+A,U+D+Y);const q=U+D+Y+B+2;t.beginPath(),t.arc(x+A+4,q+5,3.5,0,Math.PI*2),t.fillStyle=T.color,t.fill(),t.font="bold 9px Inter, system-ui, sans-serif",t.fillStyle="#60a5fa",t.fillText(E,x+A+12,q),t.restore()}}t.restore()}renderJoystick(t,s){var m,b,c,S,v,C,w,I,k,O,T,A;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.width)!==void 0?o.width:((m=s.geometry)==null?void 0:m.width)??s.width??100,n=(o==null?void 0:o.height)!==void 0?o.height:((b=s.geometry)==null?void 0:b.height)??s.height??100,i=Math.min(e,n)*(((c=s.style)==null?void 0:c.baseSize)??.45),a=Math.min(e,n)*(((S=s.style)==null?void 0:S.handleSize)??.14);let r=s.handleX||0,l=s.handleY||0;o&&o.handleX!==void 0&&(r=o.handleX),o&&o.handleY!==void 0&&(l=o.handleY),t.save();let d=0,p=0;s.handleOrigin==="top-left"?(d=e/2,p=n/2):s.handleOrigin==="bottom-right"&&(d=-e/2,p=-n/2),t.translate(d,p);const g=t.globalAlpha;if(t.globalAlpha=g*(((v=s.style)==null?void 0:v.baseOpacity)??1),t.beginPath(),s.boundsShape==="square"){const D=s.joystickType==="2D"?12:18;t.roundRect(-i,-i,i*2,i*2,D)}else t.arc(0,0,i,0,Math.PI*2);t.fillStyle=((C=s.style)==null?void 0:C.baseColor)||"rgba(0,0,0,0.04)",t.fill(),(w=s.style)!=null&&w.baseBorderWidth?(t.lineWidth=s.style.baseBorderWidth,t.strokeStyle=s.style.baseBorderColor||"rgba(0,0,0,0.1)",t.stroke()):(t.lineWidth=1,t.strokeStyle=((I=s.style)==null?void 0:I.baseBorderColor)||"rgba(0,0,0,0.08)",t.stroke());const u=s.overflowHandle?i:Math.max(.1,i-a);let f=0,h=0;s.joystickType==="2D"?(f=r*u,h=l*u):s.joystickType==="1D_X"?(f=r*u,h=0):s.joystickType==="1D_Y"&&(f=0,h=l*u),t.globalAlpha=g*(((k=s.style)==null?void 0:k.handleOpacity)??1),t.beginPath(),t.arc(f,h,a,0,Math.PI*2),t.fillStyle=((O=s.style)==null?void 0:O.handleColor)||"#3b82f6",t.fill(),(T=s.style)!=null&&T.handleBorderWidth?(t.lineWidth=s.style.handleBorderWidth,t.strokeStyle=s.style.handleBorderColor||"rgba(255,255,255,0.5)",t.stroke()):(t.lineWidth=1,t.strokeStyle=((A=s.style)==null?void 0:A.handleBorderColor)||"rgba(255,255,255,0.5)",t.stroke()),t.globalAlpha=g,t.restore()}getRadioGroupItemIndexAtPointer(t,s,o){var k,O;const e=t.options||{},n=this.objectStates.get(t.id)||{},i=e.optionsList||[];if(i.length===0)return null;const a=n.width!==void 0?n.width:((k=t.geometry)==null?void 0:k.width)||180,r=n.height!==void 0?n.height:((O=t.geometry)==null?void 0:O.height)||100,l=e.orientation||"vertical",d=e.itemGap!==void 0?e.itemGap:16,p=e.fontSize||14,g=this.getWorldTransform(t.id),u=s-g.x,f=o-g.y,h=-g.rotation*(Math.PI/180),m=Math.cos(h),b=Math.sin(h),c=u*m-f*b,S=u*b+f*m,C=8*2,w=-a/2,I=-r/2;if(l==="vertical"){const T=Math.max(C,p)+d;for(let A=0;A<i.length;A++){const D=I+A*T;if(c>=w&&c<=w+a&&S>=D&&S<=D+T)return A}}else{let T=w;for(let A=0;A<i.length;A++){const Y=i[A].length*8,B=C+6+Y+d;if(c>=T&&c<=T+B&&S>=I&&S<=I+r)return A;T+=B}}return null}renderLineGraph(t,s,o,e,n){const i=this.objectStates.get(s.id),a=(i==null?void 0:i.options)||s.options||{},r=a.hoverStyle||{},l=a.loadingStyle||{},d=a.entranceStyle||{},p=a.pressedStyle||{};let g=o.datasets||[];(!g||g.length===0)&&(o.data||o.graphData)&&(g=[{id:"line-1",label:"Series 1",data:o.data||o.graphData||[],lineColor:o.lineColor||"#3b82f6",lineWidth:o.lineWidth||2,showArea:o.showArea||!1,areaColor:o.areaColor||"rgba(139, 92, 246, 0.3)",smoothing:o.smoothing||!1,showPoints:o.showPoints!==void 0?o.showPoints:!0,pointSize:o.pointSize||6,pointFill:o.pointFill||"#ffffff",pointStrokeColor:o.pointStrokeColor||o.lineColor||"#3b82f6",pointStrokeWidth:o.pointStrokeWidth||2}]);let u=1/0,f=-1/0,h=0;g.forEach(B=>{let R=B.data;if(B.isVarEnabled&&B.inputId){let L=this.inputs.get(B.inputId);if(L===void 0){const $=this.inputNameMap.get(B.inputId);$&&$.length>0&&(L=this.inputs.get($[0]))}if(L!=null){if(typeof L=="string")try{L=JSON.parse(L)}catch{L=L.split(",").map($=>Number($.trim()))}Array.isArray(L)&&(R=L)}}if(R&&R.length>0){const L=R.map($=>Number($)).filter($=>!isNaN($));L.length>0&&(u=Math.min(u,...L),f=Math.max(f,...L),h=Math.max(h,L.length))}B._resolvedData=R});const m=a.previewState||"default";if(a.simulateLoading||m==="loading"||h<2){const B=l.skeletonColor||"rgba(100, 116, 139, 0.4)",R=l.pulseSpeed||1.5,L=l.minOpacity||.3,$=this.currentTime,F=L+(1-L)*(.5*(1+Math.sin($*Math.PI*2*R)));t.save(),t.globalAlpha=F,t.strokeStyle=B,t.lineWidth=o.lineWidth||2,t.lineJoin="round",t.lineCap="round",t.beginPath();const X=40;for(let M=0;M<=X;M++){const E=-e/2+e/X*M,P=Math.sin(M*.4-$*4)*(n/8);M===0?t.moveTo(E,P):t.lineTo(E,P)}t.stroke(),t.restore();return}const c=f-u,S=e/(h-1),v=B=>{const R=c===0?.5:(B-u)/c;return n/2-R*n},C=B=>B*S-e/2,w=o.axisColor||"#333333";if(o.showXAxis&&(t.beginPath(),t.strokeStyle=o.xAxisColor||w,t.lineWidth=1,t.moveTo(-e/2,n/2),t.lineTo(e/2,n/2),t.stroke()),o.showYAxis&&(t.beginPath(),t.strokeStyle=o.yAxisColor||w,t.lineWidth=1,t.moveTo(-e/2,-n/2),t.lineTo(-e/2,n/2),t.stroke()),t.fillStyle=o.axisLabelColor||"#333333",t.font=`${o.axisLabelFontSize||10}px Inter, sans-serif`,o.showXLabels){t.textAlign="center",t.textBaseline="top";for(let B=0;B<h;B++){const R=C(B);t.fillText(`${B+1}`,R,n/2+5)}}if(o.showYLabels){t.textAlign="right",t.textBaseline="middle";const B=-e/2-5,R=(f+u)/2;t.fillText(f.toFixed(1),B,v(f)),t.fillText(R.toFixed(1),B,v(R)),t.fillText(u.toFixed(1),B,v(u))}const I=10,k=d.type||"none",O=this.getEntranceProgress(s.id,d,m);if(t.save(),k==="fade"?t.globalAlpha*=O:k==="draw"&&(t.beginPath(),t.rect(-e/2-10,-n/2-10,(e+20)*O,n+20),t.clip()),k!=="none"&&(d.showAxes===!1&&(o.showXAxis=!1,o.showYAxis=!1),d.showLabels===!1&&(o.showXLabels=!1,o.showYLabels=!1)),g.forEach(B=>{const R=B._resolvedData;if(!(!R||R.length<2)){if(B.showArea){if(t.beginPath(),t.moveTo(C(0),n/2),t.lineTo(C(0),v(R[0])),B.smoothing&&R.length>2)for(let $=0;$<R.length-1;$++){const F=R[$===0?$:$-1],X=R[$],M=R[$+1],E=R[$+1===R.length-1?$+1:$+2];for(let P=1;P<=I;P++){const _=P/I,V=this._catmullRom(F,X,M,E,_);t.lineTo(C($+_),v(V))}}else for(let $=1;$<R.length;$++)t.lineTo(C($),v(R[$]));t.lineTo(C(R.length-1),n/2),t.closePath();const L=t.globalAlpha;t.globalAlpha=L*(o.areaOpacity??.3),t.fillStyle=B.areaColor||"rgba(139, 92, 246, 0.2)",t.fill(),t.globalAlpha=L}if(t.beginPath(),t.strokeStyle=B.lineColor||"#3b82f6",t.lineWidth=B.lineWidth||2,t.lineJoin="round",t.lineCap="round",t.moveTo(C(0),v(R[0])),B.smoothing&&R.length>2)for(let L=0;L<R.length-1;L++){const $=R[L===0?L:L-1],F=R[L],X=R[L+1],M=R[L+1===R.length-1?L+1:L+2];for(let E=1;E<=I;E++){const P=E/I,_=this._catmullRom($,F,X,M,P);t.lineTo(C(L+P),v(_))}}else for(let L=1;L<R.length;L++)t.lineTo(C(L),v(R[L]));t.stroke(),(B.showPoints||m==="hover"||m==="pressed")&&R.forEach((L,$)=>{const F=C($),X=v(L);let M=(B.pointSize||6)/2,E=!1,P=!1;const _=$===Math.floor(R.length/2);m==="pressed"&&_?P=!0:m==="hover"&&_&&(E=!0),!(!B.showPoints&&!E&&!P)&&(P?(M*=p.scale||1.5,t.beginPath(),t.arc(F,X,M*1.5,0,Math.PI*2),t.fillStyle=p.rippleColor||"rgba(59, 130, 246, 0.4)",t.fill()):E&&(M*=r.scale||1.02),t.beginPath(),t.arc(F,X,M,0,Math.PI*2),t.fillStyle=B.pointFill||"#ffffff",t.fill(),t.strokeStyle=B.pointStrokeColor||B.lineColor||"#3b82f6",t.lineWidth=B.pointStrokeWidth||1,t.stroke())})}}),t.restore(),o.showLegend&&g.length>0){const B=e/2-10;let R=-n/2+15;const L=o.legendFontSize||10,$=L+5;t.font=`${L}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="alphabetic",g.forEach(F=>{const M=F.label||"Series",E=t.measureText(M).width;t.beginPath(),t.rect(B-E-8-5,R-(8/2+2),8,8),t.fillStyle=F.lineColor||"#3b82f6",t.fill(),t.fillStyle=o.legendColor||"#333333",t.fillText(M,B,R),R+=$})}const T=this.graphHoverStates.get(s==null?void 0:s.id),A=T==null?void 0:T.hoveredIndex,D=o.showHoverTooltip!==!1,Y=o.showHoverLine!==!1;if(A!=null&&(D||Y)){const B=C(A);Y&&(t.save(),t.beginPath(),t.strokeStyle=o.hoverLineColor||"rgba(255, 255, 255, 0.35)",t.lineWidth=1,t.setLineDash([3,3]),t.moveTo(B,-n/2),t.lineTo(B,n/2),t.stroke(),t.setLineDash([]),t.restore());const R=[];if(g.forEach(L=>{const $=L._resolvedData||L.data;if($&&$[A]!==void 0&&typeof $[A]=="number"&&!isNaN($[A])){const F=$[A],X=v(F),M=L.lineColor||"#3b82f6";R.push({y:X,color:M,label:L.label||"Series",val:F});const E=this.isMouseDown,P=E?p.scale||1.5:1,_=E?p.rippleColor||"rgba(59, 130, 246, 0.4)":typeof M=="string"&&M.startsWith("#")?`${M}33`:"rgba(59, 130, 246, 0.2)";t.save(),t.beginPath();const V=o.pointHighlightRadius||5;t.arc(B,X,(V+3)*P,0,Math.PI*2),t.fillStyle=_,t.fill(),t.beginPath(),t.arc(B,X,V*P,0,Math.PI*2),t.fillStyle="#ffffff",t.fill(),t.strokeStyle=M,t.lineWidth=2.5*P,t.stroke(),t.restore()}}),D&&R.length>0){t.save();const L=10,$=8,F=16,X=14,M=$*2+X+R.length*F;t.font="bold 10px Inter, system-ui, sans-serif";let E=t.measureText(`Point #${A+1}`).width;t.font="9px Inter, system-ui, sans-serif",R.forEach(U=>{const q=t.measureText(`${U.label}: ${U.val.toFixed(1)}`).width+16;q>E&&(E=q)});const P=E+L*2;let _=B+12;_+P>e/2-4&&(_=B-P-12),_<-e/2+4&&(_=-e/2+4);let G=R.reduce((U,q)=>U+q.y,0)/R.length-M/2;G<-n/2+6&&(G=-n/2+6),G+M>n/2-6&&(G=n/2-M-6),t.shadowColor="rgba(0, 0, 0, 0.35)",t.shadowBlur=10,t.shadowOffsetX=0,t.shadowOffsetY=4,t.beginPath(),this.drawRoundRect(t,_,G,P,M,o.tooltipRadius||6),t.fillStyle=o.tooltipBg||"#111827",t.fill(),t.shadowColor="transparent",t.lineWidth=1,t.strokeStyle="rgba(255, 255, 255, 0.12)",t.stroke(),t.font="bold 10px Inter, system-ui, sans-serif",t.fillStyle=o.tooltipTextColor||"#f9fafb",t.textAlign="left",t.textBaseline="top",t.fillText(`Point #${A+1}`,_+L,G+$);let x=G+$+X+2;t.font="9px Inter, system-ui, sans-serif",R.forEach(U=>{t.beginPath(),t.arc(_+L+4,x+5,3.5,0,Math.PI*2),t.fillStyle=U.color,t.fill(),t.fillStyle=o.tooltipTextColor||"#f9fafb",t.fillText(`${U.label}: `,_+L+12,x);const q=t.measureText(`${U.label}: `).width;t.font="bold 9px Inter, system-ui, sans-serif",t.fillStyle="#60a5fa",t.fillText(`${U.val.toFixed(1)}`,_+L+12+q,x),t.font="9px Inter, system-ui, sans-serif",x+=F}),t.restore()}}}_catmullRom(t,s,o,e,n){const i=(o-t)*.5,a=(e-s)*.5,r=n*n,l=n*r;return(2*s-2*o+i+a)*l+(-3*s+3*o-2*i-a)*r+i*n+s}normalizeOpacity(t){const s=typeof t=="number"?t:parseFloat(String(t));return isNaN(s)?1:s>1?Math.min(1,s/100):Math.max(0,Math.min(1,s))}createCanvasFill(t,s,o,e){var n,i,a;if(!s||s.type==="None")return null;if(typeof s=="string")return s;if((s.type==="Solid"||!s.type)&&s.color){const r=typeof s.color=="string"?s.color:s.color.color||"#000000",d=(((i=(n=this.artboard)==null?void 0:n.tokens)==null?void 0:i.colors)||{})[r]||r;return t.fillStyle=d,d}if(typeof s=="object"&&"r"in s&&"g"in s&&"b"in s){const r=s.a!==void 0?s.a:s.opacity!==void 0?s.opacity:1;return`rgba(${s.r}, ${s.g}, ${s.b}, ${r})`}if((s.type==="LinearGradient"||s.type==="RadialGradient"||s.type==="AngularGradient"||s.type==="DiamondGradient")&&s.stops){const r=(l,d=100)=>{var v,C;const g=(((C=(v=this.artboard)==null?void 0:v.tokens)==null?void 0:C.colors)||{})[l]||l,u=this.normalizeOpacity(s.opacity??100),h=this.normalizeOpacity(d)*u;if(h>=1&&g.startsWith("#"))return g;const m=g.startsWith("#")?g.replace("#",""):"ffffff",b=parseInt(m.substring(0,2),16),c=parseInt(m.substring(2,4),16),S=parseInt(m.substring(4,6),16);return`rgba(${b}, ${c}, ${S}, ${h})`};if(s.type==="LinearGradient"){let l=0,d=-e/2,p=0,g=e/2;if(s.angle!==void 0&&(!s.start||!s.end)){const f=(s.angle-90)*Math.PI/180,h=Math.max(o,e)/2;l=Math.cos(f)*-h,d=Math.sin(f)*-h,p=Math.cos(f)*h,g=Math.sin(f)*h}else if(s.start||s.end){const f=(h,m,b)=>Array.isArray(h)?h[m]??.5:h&&typeof h=="object"?h[b]??.5:.5;l=f(s.start,0,"x")*o-o/2,d=f(s.start,1,"y")*e-e/2,p=f(s.end,0,"x")*o-o/2,g=f(s.end,1,"y")*e-e/2}Math.abs(l-p)<.001&&Math.abs(d-g)<.001&&(l=0,d=-e/2,p=0,g=e/2);const u=t.createLinearGradient(l,d,p,g);if(s.stops.forEach(f=>{const h=f.offset!==void 0?f.offset:f.pos!==void 0?f.pos:f.position!==void 0?f.position:0,m=r(f.color||"#000000",f.opacity??100);u.addColorStop(Math.max(0,Math.min(1,h)),m)}),s.gradientTransform&&u.setTransform){const[f,h,m,b,c,S]=s.gradientTransform;u.setTransform({a:f,b:h,c:m,d:b,e:c,f:S})}return u}else if(s.type==="RadialGradient"){const l=(f,h,m)=>Array.isArray(f)?f[h]??.5:f&&typeof f=="object"?f[m]??.5:.5,d=l(s.center,0,"x")*o-o/2,p=l(s.center,1,"y")*e-e/2,g=(s.radius??.5)*Math.max(o,e),u=t.createRadialGradient(d,p,0,d,p,g);if(s.stops.forEach(f=>{const h=f.offset!==void 0?f.offset:f.pos!==void 0?f.pos:f.position!==void 0?f.position:0,m=r(f.color||"#000000",f.opacity??100);u.addColorStop(Math.max(0,Math.min(1,h)),m)}),s.gradientTransform&&u.setTransform){const[f,h,m,b,c,S]=s.gradientTransform;u.setTransform({a:f,b:h,c:m,d:b,e:c,f:S})}return u}else if(s.type==="AngularGradient"){const l=(f,h,m)=>Array.isArray(f)?f[h]??.5:f&&typeof f=="object"?f[m]??.5:.5,d=l(s.center||[.5,.5],0,"x")*o-o/2,p=l(s.center||[.5,.5],1,"y")*e-e/2,g=(s.degree||s.angle||0)*(Math.PI/180),u=(a=t.createConicGradient)==null?void 0:a.call(t,g,d,p);if(u){if(s.stops.forEach(f=>{const h=f.offset!==void 0?f.offset:f.pos!==void 0?f.pos:f.position!==void 0?f.position:0,m=r(f.color||"#000000",f.opacity??100);u.addColorStop(Math.max(0,Math.min(1,h)),m)}),s.gradientTransform&&u.setTransform){const[f,h,m,b,c,S]=s.gradientTransform;u.setTransform({a:f,b:h,c:m,d:b,e:c,f:S})}return u}}else if(s.type==="DiamondGradient"){const l=(f,h,m)=>Array.isArray(f)?f[h]??.5:f&&typeof f=="object"?f[m]??.5:.5,d=l(s.center||[.5,.5],0,"x")*o-o/2,p=l(s.center||[.5,.5],1,"y")*e-e/2,g=(s.radius??.5)*Math.max(o,e);t.save(),t.translate(d,p),t.rotate(Math.PI/4);const u=t.createRadialGradient(0,0,0,0,0,g);if(s.stops.forEach(f=>{const h=f.offset!==void 0?f.offset:f.pos!==void 0?f.pos:f.position!==void 0?f.position:0,m=r(f.color||"#000000",f.opacity??100);u.addColorStop(Math.max(0,Math.min(1,h)),m)}),s.gradientTransform&&u.setTransform){const[f,h,m,b,c,S]=s.gradientTransform;u.setTransform({a:f,b:h,c:m,d:b,e:c,f:S})}return t.scale(1/Math.SQRT2,1/Math.SQRT2),t.fillStyle=u,t.restore(),u}}if(s.type==="Pattern"&&s.url){let r=this.imageCache.get(s.url);if(r||(r=new Image,r.src=s.url,this.imageCache.set(s.url,r)),r.complete&&r.naturalWidth>0){const l=t.createPattern(r,"repeat");if(l&&(s.scaleX!==void 0||s.offsetX!==void 0)){const d=new DOMMatrix,p=s.scaleX??1,g=s.scaleY??1,u=s.offsetX??0,f=s.offsetY??0,h=s.rotation??0;d.translateSelf(u,f),d.rotateSelf(h),d.scaleSelf(p,g),l.setTransform(d)}return l}}return s.color||null}drawRoundRect(t,s,o,e,n,i){if(i===0||i===void 0||i===null){t.rect(s,o,e,n);return}let a=i;if(typeof a=="string")try{a=JSON.parse(a)}catch{a=parseFloat(a)||0}let r=0,l=0,d=0,p=0;typeof a=="number"?r=l=d=p=a:Array.isArray(a)?a.length===1?r=l=d=p=a[0]:a.length===2?(r=d=a[0],l=p=a[1]):a.length===3?(r=a[0],l=p=a[1],d=a[2]):a.length>=4&&(r=a[0],l=a[1],d=a[2],p=a[3]):a&&typeof a=="object"&&(r=a[0]??a.tl??a.corner_radius??a.cornerRadius??0,l=a[1]??a.tr??a.corner_radius??a.cornerRadius??0,d=a[2]??a.br??a.corner_radius??a.cornerRadius??0,p=a[3]??a.bl??a.corner_radius??a.cornerRadius??0);const g=Math.min(Math.abs(e)/2,Math.abs(n)/2);if(r=Math.min(Math.max(0,r),g),l=Math.min(Math.max(0,l),g),d=Math.min(Math.max(0,d),g),p=Math.min(Math.max(0,p),g),t.roundRect){t.roundRect(s,o,e,n,[r,l,d,p]);return}t.moveTo(s+r,o),t.lineTo(s+e-l,o),t.arcTo(s+e,o,s+e,o+l,l),t.lineTo(s+e,o+n-d),t.arcTo(s+e,o+n,s+e-d,o+n,d),t.lineTo(s+p,o+n),t.arcTo(s,o+n,s,o+n-p,p),t.lineTo(s,o+r),t.arcTo(s,o,s+r,o,r),t.closePath()}renderListView(t,s){var R,L,$,F,X,M,E,P,_,V;const o=this.objectStates.get(s.id)||{},e=o.options||s.options||{},n=o.width!==void 0?o.width:((R=s.geometry)==null?void 0:R.width)||200,i=o.height!==void 0?o.height:((L=s.geometry)==null?void 0:L.height)||300,a=-n/2,r=-i/2,l=e.cornerRadius!==void 0?e.cornerRadius:o.cornerRadius!==void 0?o.cornerRadius:o.corner_radius??e.corner_radius??(($=s.geometry)==null?void 0:$.cornerRadius)??((F=s.geometry)==null?void 0:F.corner_radius)??0,d=e.orientation||"vertical",p=this.getResolvedListViewItems(s,e),g=e.itemGap??10,u=e.itemHeight??50,f=e.itemWidth??200,h=e.scrollOffset??0,m=e.padding??0,b=e.glassEffect!==!1,c=e.accentColor||"#3b82f6",S=e.itemTextColor||"#333333",v=e.itemBackgroundColor||"#ffffff",C=e.hoveredIndex??null,w=e.activeItemIndex??null,I=e.glowIntensity??0,k=e.glowColor||"#3b82f6",O=typeof k=="string"?k:k.color||((M=(X=k.stops)==null?void 0:X[0])==null?void 0:M.color)||"#3b82f6",T=e.opacity!==void 0?e.opacity:s.opacity!==void 0?s.opacity:1;if(t.save(),t.globalAlpha*=T,I>0){const G=t.getTransform(),x=Math.sqrt(G.a*G.a+G.b*G.b)||1;t.shadowColor=O,t.shadowBlur=I*2*x,t.shadowOffsetX=0,t.shadowOffsetY=0}if(b){const G=e.listBackgroundColor||"rgba(31, 41, 55, 0.4)",x=this.createCanvasFill(t,G,n,i);t.fillStyle=x||"rgba(31, 41, 55, 0.4)",t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)||t.fill();const q=t.createLinearGradient(a,r,a+n,r+i);q.addColorStop(0,"rgba(255, 255, 255, 0.15)"),q.addColorStop(.5,"rgba(255, 255, 255, 0.08)"),q.addColorStop(1,"rgba(255, 255, 255, 0.03)"),t.fillStyle=q,t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)||t.fill();const H=e.borderWidth??0;if(H>0&&e.borderColor&&e.borderColor!=="transparent"){const et=this.createCanvasFill(t,e.borderColor,n,i);t.strokeStyle=et||"rgba(255, 255, 255, 0.25)",t.lineWidth=H}else t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1;t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)||t.stroke()}else{const G=e.backgroundColor&&e.backgroundColor!=="transparent"?e.backgroundColor:e.listBackgroundColor||"transparent",x=this.createCanvasFill(t,G,n,i);if(x){t.fillStyle=x,t.beginPath();const q=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l);t.fill()}const U=e.borderWidth??0;if(U>0){const q=this.createCanvasFill(t,e.borderColor||"#cccccc",n,i);t.strokeStyle=q||"#cccccc",t.lineWidth=U,t.beginPath();const N=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l);t.stroke()}}t.shadowBlur=0;const A=e.clipContent!==!1&&e.listLayout!=="circular";if(A)if(t.save(),t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)&&e.containerShape==="custom")try{const x=new Path2D(e.containerPath);t.translate(a,r),t.scale(n/100,i/100),t.clip(x),t.scale(100/n,100/i),t.translate(-a,-r)}catch{}else t.clip();const D=typeof m=="number"?m:d==="vertical"?m[0]:m[3];let Y=(d==="vertical"?r:a)+h+D;if(t.textBaseline="middle",p.forEach((G,x)=>{var ut,$t,St,Pt;const U=e.listLayout||"linear",q=U==="circular"?f:d==="vertical"?n:f,N=U==="circular"||d==="vertical"?u:i;let H=0,z=0,et=0;if(U==="circular"){const Ft=p.length||1,lt=Math.PI*2/Ft,ht=e.circularStartAngle||0,dt=e.circularRadius||100,At=h*.01+ht*Math.PI/180,Tt=x*lt+At,Ct=a+n/2,Yt=r+i/2;H=Ct+Math.cos(Tt)*dt-q/2,z=Yt+Math.sin(Tt)*dt-N/2,et=Tt+(e.itemRotation||0)*Math.PI/180}else H=d==="vertical"?a:Y,z=d==="vertical"?Y:r,et=(e.itemRotation||0)*Math.PI/180;const Mt=C===x,ct=w===x,It=e.itemBorderWidth??0;t.save(),et!==0&&(t.translate(H+q/2,z+N/2),t.rotate(et),t.translate(-(H+q/2),-(z+N/2)));const mt=Mt?((ut=e.hoverStyle)==null?void 0:ut.scale)??1:ct?(($t=e.activeStyle)==null?void 0:$t.scale)??1:1;if(mt!==1&&(t.translate(H+q/2,z+N/2),t.scale(mt,mt),t.translate(-(H+q/2),-(z+N/2))),ct){const Ft=((St=e.activeStyle)==null?void 0:St.itemBackgroundColor)||e.activeBackgroundColor||(b?"rgba(255, 255, 255, 0.15)":"rgba(0, 0, 0, 0.1)"),lt=this.createCanvasFill(t,Ft,q,N);t.fillStyle=lt||(typeof Ft=="string"?Ft:"transparent"),t.beginPath(),this.drawCustomShape(t,e.activeItemShape||e.itemShape||"rectangle",e.activeItemShape==="custom"?e.activeItemPath||"":e.itemPath||"",H,z,q,N,e.itemCornerRadius??0)||t.fill()}else if(Mt){const Ft=((Pt=e.hoverStyle)==null?void 0:Pt.itemBackgroundColor)||e.hoverBackgroundColor||(b?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)"),lt=this.createCanvasFill(t,Ft,q,N);t.fillStyle=lt||(typeof Ft=="string"?Ft:"transparent"),t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",H,z,q,N,e.itemCornerRadius??0)||t.fill()}else if(v!=="transparent"){const Ft=this.createCanvasFill(t,v,q,N);t.fillStyle=Ft||(typeof v=="string"?v:"transparent"),t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",H,z,q,N,e.itemCornerRadius??0)||t.fill()}if(It>0&&e.itemBorderColor&&e.itemBorderColor!=="transparent"){const Ft=this.createCanvasFill(t,e.itemBorderColor,q,N);t.strokeStyle=Ft||(typeof e.itemBorderColor=="string"?e.itemBorderColor:"#cccccc"),t.lineWidth=It,t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",H,z,q,N,e.itemCornerRadius??0)||t.stroke()}if(ct){const Ft=this.createCanvasFill(t,c,d==="vertical"?3:q,d==="vertical"?N:3);t.fillStyle=Ft||c,d==="vertical"?t.fillRect(H,z,3,N):t.fillRect(H,z+N-3,q,3)}const kt=ct?"#ffffff":b?"rgba(255, 255, 255, 0.9)":S;t.fillStyle=kt,t.font=ct||Mt?"600 14px Inter, sans-serif":"400 14px Inter, sans-serif";const Ot=typeof G=="string"?G:(G==null?void 0:G.label)||`Item ${x+1}`,vt=H+(d==="vertical"?16:q/2),Wt=z+N/2;d==="horizontal"||U==="circular"?t.textAlign="center":t.textAlign="left";const J=U==="circular"?H+q/2:vt;t.fillText(Ot,J,Wt),t.restore(),t.beginPath(),Y+=(d==="vertical"?u:f)+g}),A&&t.restore(),e.showScrollbar!==!1){const G=typeof m=="number"?m:d==="vertical"?m[0]:m[3],U=(p.length||0)*(d==="vertical"?u:f)+Math.max(0,(p.length||0)-1)*g+G*2,q=d==="vertical"?i:n,N=e.listLayout||"linear",H=e.containerShape==="circle"||N==="circular",z=e.scrollbarColor||"rgba(255,255,255,0.3)";let et=typeof z=="object"?z.color||((P=(E=z.stops)==null?void 0:E[0])==null?void 0:P.color)||"rgba(255,255,255,0.3)":z;const Mt=((V=(_=this.artboard)==null?void 0:_.tokens)==null?void 0:V.colors)||{};Mt[et]&&(et=Mt[et]);const ct=e.scrollbarWidth||2;if(t.save(),H){const It=Math.min(n,i)/2-ct/2-2,mt=a+n/2,kt=r+i/2;if(t.strokeStyle=et,t.lineWidth=ct,t.lineCap="round",t.beginPath(),N==="circular"){const Ot=Math.PI/4,vt=-(h*.01)-Math.PI/2;t.arc(mt,kt,It,vt,vt+Ot)}else{const Ot=Math.PI/2,vt=U>0?Math.min(1,q/U):1,Wt=Ot*vt,J=U>0?-h/U*Ot:0,$t=-Math.PI/4+J;t.arc(mt,kt,It,$t,$t+Wt)}t.stroke()}else{let It=q,mt=0;if(U>q){const kt=q/U;It=Math.max(16,q*kt);const Ot=q-It,vt=U-q;mt=vt>0?Math.max(0,Math.min(Ot,-h/vt*Ot)):0}if(t.fillStyle=et,d==="vertical"){const kt=a+n-ct-2,Ot=r+mt,vt=ct,Wt=It;if(ct>2){t.beginPath();const J=Math.min(ct/2,It/2);if(t.roundRect)try{t.roundRect(kt,Ot,vt,Wt,J),t.fill()}catch{t.fillRect(kt,Ot,vt,Wt)}else t.fillRect(kt,Ot,vt,Wt)}else t.fillRect(kt,Ot,vt,Wt)}else{const kt=a+mt,Ot=r+i-ct-2,vt=It,Wt=ct;if(ct>2){t.beginPath();const J=Math.min(ct/2,It/2);if(t.roundRect)try{t.roundRect(kt,Ot,vt,Wt,J),t.fill()}catch{t.fillRect(kt,Ot,vt,Wt)}else t.fillRect(kt,Ot,vt,Wt)}else t.fillRect(kt,Ot,vt,Wt)}}t.restore()}t.beginPath(),t.restore()}drawCustomShape(t,s,o,e,n,i,a,r){if(s==="circle"){const l=Math.min(i,a)/2;return t.arc(e+i/2,n+a/2,l,0,Math.PI*2),!1}else if(s==="pill"){const l=Math.min(i,a)/2;return this.drawListViewRect(t,e,n,i,a,l),!1}else if(s==="custom"&&o)try{const l=new Path2D(o);return t.save(),t.translate(e,n),t.scale(i/100,a/100),t.fill(l),t.restore(),!0}catch{return this.drawListViewRect(t,e,n,i,a,r),!1}return this.drawListViewRect(t,e,n,i,a,r),!1}updateListViewScrollFromPointer(t){var v,C,w,I;if(!this._lastPointerPos||!this._prevPointerPos)return;const s=this.objectStates.get(t.id);s&&!s.options&&(s.options=JSON.parse(JSON.stringify(t.options||{})));const o=(s==null?void 0:s.options)||t.options||{},e=o.orientation||"vertical",n=this._lastPointerPos.x-this._prevPointerPos.x,i=this._lastPointerPos.y-this._prevPointerPos.y;let a=o.scrollOffset||0;const r=this.getResolvedListViewItems(t,o),l=o.itemGap??10,d=o.itemHeight??50,p=o.itemWidth??200,g=(s==null?void 0:s.width)!==void 0?s.width:((v=t.geometry)==null?void 0:v.width)||200,u=(s==null?void 0:s.height)!==void 0?s.height:((C=t.geometry)==null?void 0:C.height)||300,f=typeof o.padding=="number"?o.padding:e==="vertical"?((w=o.padding)==null?void 0:w[0])||0:((I=o.padding)==null?void 0:I[3])||0,m=(r.length||0)*(e==="vertical"?d:p)+Math.max(0,(r.length||0)-1)*l+f*2,b=e==="vertical"?u:g,c=Math.max(0,m-b);if(this.draggingListViewIsScrollbar&&o.listLayout!=="circular"){const k=m>0?b/m:1,O=Math.max(16,b*k),T=Math.max(1,b-O),A=c>0?c/T:1;e==="vertical"?a-=i*A:a-=n*A}else e==="vertical"?a+=i:a+=n;if((o.listLayout||"linear")==="circular"){o.scrollOffset=a,s&&s.options&&(s.options.scrollOffset=a),t.options&&(t.options.scrollOffset=a);return}a>0&&(a=0),a<-c&&(a=-c),o.scrollOffset=a,s&&s.options&&(s.options.scrollOffset=a),t.options&&(t.options.scrollOffset=a)}updateListViewHoverFromPointer(t,s,o){const e=this.getListViewItemIndexAtPointer(t,s,o),n=this.objectStates.get(t.id);if(n&&n.options)n.options.hoveredIndex!==e&&(n.options.hoveredIndex=e);else{const i=t.options||{};i.hoveredIndex!==e&&(i.hoveredIndex=e)}}getListViewItemIndexAtPointer(t,s,o){var $,F;const e=this.objectStates.get(t.id),n=(e==null?void 0:e.options)||t.options||{},i=this.getResolvedListViewItems(t,n);if(i.length===0)return null;const a=(e==null?void 0:e.width)!==void 0?e.width:(($=t.geometry)==null?void 0:$.width)||200,r=(e==null?void 0:e.height)!==void 0?e.height:((F=t.geometry)==null?void 0:F.height)||300,l=n.orientation||"vertical",d=n.itemGap??10,p=n.itemHeight??50,g=n.itemWidth??200,u=n.scrollOffset??0,f=n.padding??0,h=this.getWorldTransform(t.id),m=s-h.x,b=o-h.y,c=-h.rotation*(Math.PI/180),S=Math.cos(c),v=Math.sin(c),C=m*S-b*v,w=m*v+b*S,I=-a/2,k=-r/2,O=typeof f=="number"?f:l==="vertical"?f[0]:f[3];let T=(l==="vertical"?k:I)+u+O;const A=n.listLayout||"linear",D=i.length||1,Y=Math.PI*2/D,B=n.circularStartAngle||0,R=n.circularRadius||100,L=u*.01+B*Math.PI/180;for(let X=0;X<i.length;X++){const M=A==="circular"?g:l==="vertical"?a:g,E=A==="circular"||l==="vertical"?p:r;let P=0,_=0,V=0;if(A==="circular"){const G=X*Y+L,x=I+a/2,U=k+r/2;P=x+Math.cos(G)*R-M/2,_=U+Math.sin(G)*R-E/2,V=G+(n.itemRotation||0)*Math.PI/180}else P=l==="vertical"?I:T,_=l==="vertical"?T:k,V=(n.itemRotation||0)*Math.PI/180;if(V!==0){const G=P+M/2,x=_+E/2,U=C-G,q=w-x,N=-V,H=U*Math.cos(N)-q*Math.sin(N)+G,z=U*Math.sin(N)+q*Math.cos(N)+x;if(H>=P&&H<=P+M&&z>=_&&z<=_+E)return X}else if(C>=P&&C<=P+M&&w>=_&&w<=_+E)return X;T+=(l==="vertical"?p:g)+d}return null}drawListViewRect(t,s,o,e,n,i){this.drawRoundRect(t,s,o,e,n,i)}solveBehaviors(t){if(!this.artboard)return;if(!this._lastPointerPos){this.frameCount%60;return}const{x:s,y:o}=this._lastPointerPos;this.artboard.objects.forEach(e=>{if(!e.behaviors||e.behaviors.length===0)return;const n=this.objectStates.get(e.id);n&&e.behaviors.forEach(i=>{var g,u,f,h,m,b,c,S,v,C,w,I,k,O,T,A,D,Y,B,R,L,$,F,X,M,E,P,_,V,G,x,U,q,N,H,z,et,Mt,ct,It,mt,kt,Ot,vt,Wt,J,ut,$t,St,Pt,Ft,lt,ht,dt,At,Tt,Ct,Yt,ie,te,Zt,le,fe,qt,Se,Ce,Ie,de,Re,ye,ke,Vt,ee,j,bt,st,K,rt,ft,Rt,Qt,Kt,ae,Jt,Et,W,nt,Lt,tt,gt,Q,Ut,zt,yt,Bt,_t,Xt,Dt,ce,be,Le,oe,pe,he,$e,Be,Ye,De,Xe,Ne,Ue,re,ve,Te,He,Ve,_e,Pe;if(!i.enabled)return;const a=i.startTime||0,r=i.endTime||1/0;if(this.currentTime<a||this.currentTime>r)return;const l=n.x-s,d=n.y-o,p=Math.sqrt(l*l+d*d);if(this.frameCount%240===0&&Math.random()<.1&&this.log(`[ExodeUI] Executing ${i.type} on ${e.name}`),i.type===it.Proximity){const Z=((g=i.settings)==null?void 0:g.radius)||300,ot=((u=i.settings)==null?void 0:u.falloff)||"smooth";let at=0;p<Z&&(ot==="linear"?at=1-p/Z:at=Math.pow(1-p/Z,2)),i.sensors.forEach(wt=>{this.applyBehaviorSensor(n,wt,at,t,i.settings,e,l,d,p)})}else if(i.type===it.Magnetic){const Z=((f=i.settings)==null?void 0:f.radius)||400,ot=((h=i.settings)==null?void 0:h.strength)||.5;if(p<Z&&p>5){const at=1-p/Z,wt=l*at*ot,Gt=d*at*ot;n.x-=wt*t*10,n.y-=Gt*t*10}}else if(i.type===it.Repel){const Z=((m=i.settings)==null?void 0:m.radius)||300,ot=((b=i.settings)==null?void 0:b.strength)||1;if(p<Z){const at=Math.pow(1-p/Z,2);n.x+=l/(p||1)*at*60*ot*t*5,n.y+=d/(p||1)*at*60*ot*t*5}}else if(i.type===it.Orbit){const Z=((c=i.settings)==null?void 0:c.speed)||1,ot=((S=i.settings)==null?void 0:S.radius)||30,at=this.currentTime*Z*Math.PI*2;n.x+=Math.cos(at)*ot*t*5,n.y+=Math.sin(at)*ot*t*5,n.rotation+=2*t*5}else if(i.type===it.Vortex){const Z=((v=i.settings)==null?void 0:v.radius)||400,ot=((C=i.settings)==null?void 0:C.speed)||2,at=((w=i.settings)==null?void 0:w.strength)||1;if(p<Z){const wt=Math.pow(1-p/Z,1.5),Gt=this.currentTime*ot*Math.PI*2,xt=Math.cos(Gt)*30-l*.4,jt=Math.sin(Gt)*30-d*.4;n.x+=xt*wt*at*t*5,n.y+=jt*wt*at*t*5,n.rotation+=5*wt*at*t*5,n.scale_x*=1-wt*.1*at*t,n.scale_y*=1-wt*.1*at*t}}else if(i.type===it.Fluid){const Z=((I=i.settings)==null?void 0:I.radius)||300,ot=((k=i.settings)==null?void 0:k.strength)||1;if(p<Z){const at=Math.pow(1-p/Z,1.2),wt=l/(p||1)*at*1.2*ot,Gt=d/(p||1)*at*1.2*ot;n.x+=wt*10*t*5,n.y+=Gt*10*t*5,n.scale_x*=1+at*.3*ot*t,n.scale_y*=1+at*.3*ot*t}}else if(i.type===it.Elastic){const Z=((O=i.settings)==null?void 0:O.radius)||300,ot=((T=i.settings)==null?void 0:T.strength)||1;if(p<Z){const at=1-p/Z;n.scale_x*=1+at*.4*ot*t,n.scale_y*=1+at*.4*ot*t}}else if(i.type===it.Holographic){const Z=n.x-this.canvasWidth/2,ot=n.y-this.canvasHeight/2,at=((A=i.settings)==null?void 0:A.factor)||25;if(n.x-=Z/1e3*at*t*5,n.y-=ot/1e3*at*t*5,n.style){const wt=1-Math.min(1,p/400);n.style.exposure=(n.style.exposure||1)+wt*.5*t}}else if(i.type===it.Sticky){const Z=((D=i.settings)==null?void 0:D.radius)||80,ot=((Y=i.settings)==null?void 0:Y.strength)||1;if(p<Z){const at=Math.pow(1-p/Z,2);n.x-=l*at*ot*t*10,n.y-=d*at*ot*t*10,n.scale_x*=1-at*.1*ot*t,n.scale_y*=1-at*.1*ot*t}}else if(i.type===it.Dilation){const Z=((B=i.settings)==null?void 0:B.size)||120,ot=((R=i.settings)==null?void 0:R.strength)||1;if(p<Z){const at=1-p/Z;n.scale_x*=1+at*.5*ot*t,n.scale_y*=1+at*.5*ot*t}}else if(i.type===it.Parallax){const Z=((L=i.settings)==null?void 0:L.factor)||15,ot=(($=i.settings)==null?void 0:$.strength)||1,at=this.canvasWidth/2,wt=this.canvasHeight/2,Gt=this._lastPointerPos||{x:at,y:wt},xt=(Gt.x-at)/at,jt=(Gt.y-wt)/wt,me=(((F=e.transform)==null?void 0:F.x)??0)+xt*Z*ot,Ae=(((X=e.transform)==null?void 0:X.y)??0)+jt*Z*ot,Fe=(((M=e.transform)==null?void 0:M.rotate_x)??0)-jt*Z*1.5*ot,we=(((E=e.transform)==null?void 0:E.rotate_y)??0)+xt*Z*1.5*ot,Oe=Math.min(1,10*t);n.x=this.lerp(n.x??((P=e.transform)==null?void 0:P.x)??0,me,Oe),n.y=this.lerp(n.y??((_=e.transform)==null?void 0:_.y)??0,Ae,Oe),n.rotate_x=this.lerp(n.rotate_x??((V=e.transform)==null?void 0:V.rotate_x)??0,Fe,Oe),n.rotate_y=this.lerp(n.rotate_y??((G=e.transform)==null?void 0:G.rotate_y)??0,we,Oe)}else if(i.type===it.Fold){if(p<300){const Z=1-p/300,ot=(l>0?-1:1)*Z*10,at=1-Z*.1,wt=d/300*Z*20,Gt=-(l/300)*Z*20,xt=Math.min(1,10*t);n.skew_x=this.lerp(n.skew_x??((x=e.transform)==null?void 0:x.skew_x)??0,ot,xt),n.scale_y=this.lerp(n.scale_y??((U=e.transform)==null?void 0:U.scale_y)??1,(((q=e.transform)==null?void 0:q.scale_y)??1)*at,xt),n.rotate_x=this.lerp(n.rotate_x??((N=e.transform)==null?void 0:N.rotate_x)??0,wt,xt),n.rotate_y=this.lerp(n.rotate_y??((H=e.transform)==null?void 0:H.rotate_y)??0,Gt,xt),n.style=n.style||{...e.style},n.style.artEffect={enabled:!0,type:"fold_overlay",intensity:((z=i.settings)==null?void 0:z.opacity)??.5}}}else if(i.type===it.Crumple){if(p<300){const Z=1-p/300,ot=Z*(Math.random()-.5)*5,at=Z*(Math.random()-.5)*.05,wt=Math.min(1,15*t);n.skew_x=this.lerp(n.skew_x??((et=e.transform)==null?void 0:et.skew_x)??0,ot,wt),n.scale_x=this.lerp(n.scale_x??((Mt=e.transform)==null?void 0:Mt.scale_x)??1,(((ct=e.transform)==null?void 0:ct.scale_x)??1)*(1+at),wt),n.scale_y=this.lerp(n.scale_y??((It=e.transform)==null?void 0:It.scale_y)??1,(((mt=e.transform)==null?void 0:mt.scale_y)??1)*(1+at),wt),n.style=n.style||{...e.style},n.style.artEffect={enabled:!0,type:"crumple_overlay",intensity:((kt=i.settings)==null?void 0:kt.intensity)??1,scale:((Ot=i.settings)==null?void 0:Ot.scale)??2}}}else if(i.type===it.Squash){const Z=((vt=i.settings)==null?void 0:vt.strength)||.8;p<(e.width||100)&&this.isMouseDown?(n.scale_y=this.lerp(n.scale_y??1,(((Wt=e.transform)==null?void 0:Wt.scale_y)??1)*Z,.3),n.scale_x=this.lerp(n.scale_x??1,(((J=e.transform)==null?void 0:J.scale_x)??1)*(1+(1-Z)*.4),.3)):(n.scale_y=this.lerp(n.scale_y??1,((ut=e.transform)==null?void 0:ut.scale_y)??1,.2),n.scale_x=this.lerp(n.scale_x??1,(($t=e.transform)==null?void 0:$t.scale_x)??1,.2))}else if(i.type===it.TextCounter){const Z=((St=i.settings)==null?void 0:St.duration)||2,ot=((Pt=i.settings)==null?void 0:Pt.from)||0,at=((Ft=i.settings)==null?void 0:Ft.to)||100;i._runtimeStart===void 0&&(i._runtimeStart=this.currentTime);const wt=this.currentTime-i._runtimeStart,Gt=Math.min(1,wt/Z),xt=Math.floor(ot+(at-ot)*Gt);if(((lt=e.geometry)==null?void 0:lt.type)==="Text"){const jt=((ht=i.settings)==null?void 0:ht.prefix)||"",me=((dt=i.settings)==null?void 0:dt.suffix)||"";n.geometry||(n.geometry={...e.geometry}),n.geometry.text=`${jt}${xt}${me}`}}else if(i.type===it.Spotlight){const Z=((At=i.settings)==null?void 0:At.radius)||250,ot=((Tt=i.settings)==null?void 0:Tt.strength)||1.5;if(p<Z){const at=Math.pow(1-p/Z,2);n.style||(n.style={...e.style}),n.style.adjustments||(n.style.adjustments={...(Ct=e.style)==null?void 0:Ct.adjustments}),n.style.adjustments.exposure=(((ie=(Yt=e.style)==null?void 0:Yt.adjustments)==null?void 0:ie.exposure)||0)+at*ot*50}else(te=n.style)!=null&&te.adjustments&&(n.style.adjustments.exposure=this.lerp(n.style.adjustments.exposure||0,((le=(Zt=e.style)==null?void 0:Zt.adjustments)==null?void 0:le.exposure)||0,.1))}else if(i.type===it.Noise||i.type===it.Float){const Z=(((fe=i.settings)==null?void 0:fe.frequency)||((qt=i.settings)==null?void 0:qt.speed)||1)*.002,ot=(((Se=i.settings)==null?void 0:Se.amplitude)||((Ce=i.settings)==null?void 0:Ce.range)||50)*(((Ie=i.settings)==null?void 0:Ie.strength)||1),at=Date.now();n.x+=Math.sin(at*Z)*ot*t,n.y+=Math.cos(at*Z*.8)*ot*t,n.rotation+=Math.sin(at*Z*.5)*5*t}else if(i.type===it.Pulse){const Z=(((de=i.settings)==null?void 0:de.speed)||1)*.005,ot=(((Re=i.settings)==null?void 0:Re.scale)||1.2)-1,at=Math.sin(Date.now()*Z),wt=((ye=i.settings)==null?void 0:ye.strength)||1;n.scale_x*=1+at*ot*wt*t,n.scale_y*=1+at*ot*wt*t,n.style&&(n.style.exposure=(n.style.exposure||1)+Math.max(0,at)*.1*wt*t)}else if(i.type===it.Draggable){if(!this.draggingBehaviors.has(e.id)){const ot=((ke=i.settings)==null?void 0:ke.radius)||150;if(p<ot){const at=((Vt=i.settings)==null?void 0:Vt.strength)||1,wt=Math.max(0,1-p/ot);this.applyBehaviorSensor(n,ge.PositionX,wt*at,t,i.settings,e,l,d,p),this.applyBehaviorSensor(n,ge.PositionY,wt*at,t,i.settings,e,l,d,p)}}}else if(i.type===it.Scroll){const Z=((ee=i.settings)==null?void 0:ee.axis)||"vertical",ot=((j=i.settings)==null?void 0:j.factor)||.5,at=((bt=i.settings)==null?void 0:bt.strength)||1,wt=((st=i.settings)==null?void 0:st.scaleFactor)||0;(Z==="vertical"||Z==="both")&&(n.y+=this.scrollOffset.y*ot*at*t),(Z==="horizontal"||Z==="both")&&(n.x+=this.scrollOffset.x*ot*at*t),wt!==0&&(n.scale_x*=1+this.scrollOffset.y*wt*t,n.scale_y*=1+this.scrollOffset.y*wt*t)}else if(i.type===it.LookAt){const Z=((K=i.settings)==null?void 0:K.factor)||1,ot=((rt=i.settings)==null?void 0:rt.strength)||1,at=Math.atan2(-d,-l)*(180/Math.PI),wt=n.rotation,Gt=(at-wt+180)%360-180;n.rotation+=Gt*Z*ot*t*10}else if(i.type===it.Scan){const Z=(((ft=i.settings)==null?void 0:ft.speed)||1)*.004,ot=((Rt=i.settings)==null?void 0:Rt.strength)||1,at=(Math.sin(Date.now()*Z)+1)/2;n.style&&(n.style.exposure=(n.style.exposure||1)+at*ot*t*5),n.x+=(at-.5)*20*ot*t}else if(i.type===it.Glint)n.style=n.style||{...e.style},n.style.artEffect={enabled:!0,type:"glint_overlay",intensity:((Qt=i.settings)==null?void 0:Qt.strength)??.8};else if(i.type===it.Ratchet){const Z=((Kt=i.settings)==null?void 0:Kt.steps)||12,ot=(((ae=i.settings)==null?void 0:ae.speed)||1)*30,at=Math.floor(n.rotation/(360/Z))*(360/Z);n.rotation=this.lerp(n.rotation,at+ot*t,.1)}else if(i.type===it.Jitter&&p<300){const Z=((Jt=i.settings)==null?void 0:Jt.strength)||1,ot=(((Et=i.settings)==null?void 0:Et.intensity)||5)*Z;n.x+=(Math.random()-.5)*ot*t*60,n.y+=(Math.random()-.5)*ot*t*60,n.rotation+=(Math.random()-.5)*ot*t*120}else if(i.type===it.Follower){const Z=(W=i.settings)==null?void 0:W.targetId;if(Z){const ot=this.objectStates.get(Z);if(ot){const at=((nt=i.settings)==null?void 0:nt.stiffness)||.1,wt=ot.x-n.x,Gt=ot.y-n.y;n.x+=wt*at*t*60,n.y+=Gt*at*t*60}}}else if(i.type===it.Wrap)n.x<0?n.x=this.canvasWidth:n.x>this.canvasWidth&&(n.x=0),n.y<0?n.y=this.canvasHeight:n.y>this.canvasHeight&&(n.y=0);else if(i.type===it.Gravity){const Z=((Lt=i.settings)==null?void 0:Lt.strength)||9.8;n.y+=Z*t*10}else if(i.type===it.Velocity){const Z=((tt=i.settings)==null?void 0:tt.vx)||0,ot=((gt=i.settings)==null?void 0:gt.vy)||0;n.x+=Z*t*10,n.y+=ot*t*10}else if(i.type===it.Shear){const Z=((Q=i.settings)==null?void 0:Q.strength)||1,ot=((Ut=i.settings)==null?void 0:Ut.radius)||300;if(p<ot){const at=1-p/ot;n.skew_x=this.lerp(n.skew_x||0,(((zt=e.transform)==null?void 0:zt.skew_x)||0)+at*Z*30,.1)}else n.skew_x=this.lerp(n.skew_x||0,((yt=e.transform)==null?void 0:yt.skew_x)||0,.05)}else if(i.type===it.Lens){const Z=((Bt=i.settings)==null?void 0:Bt.radius)||200,ot=((_t=i.settings)==null?void 0:_t.strength)||.5;if(p<Z){const at=Math.pow(1-p/Z,2);n.scale_x=this.lerp(n.scale_x??1,(((Xt=e.transform)==null?void 0:Xt.scale_x)??1)*(1+at*ot),.2),n.scale_y=this.lerp(n.scale_y??1,(((Dt=e.transform)==null?void 0:Dt.scale_y)??1)*(1+at*ot),.2)}else n.scale_x=this.lerp(n.scale_x??1,((ce=e.transform)==null?void 0:ce.scale_x)??1,.1),n.scale_y=this.lerp(n.scale_y??1,((be=e.transform)==null?void 0:be.scale_y)??1,.1)}else if(i.type===it.LayoutAnimation){const Z=((Le=i.settings)==null?void 0:Le.watchProperties)||["x","y","scale_x","scale_y","opacity","rotation"],ot=((oe=i.settings)==null?void 0:oe.duration)||.3;this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const at=this._layoutAnimCache.get(e.id);for(const wt of Z){const Gt=this.getObjectProperty(n,e,wt);if(Gt===void 0)continue;const xt=at.get(wt);if(!xt)at.set(wt,{from:Gt,to:Gt,startTime:this.currentTime,duration:0});else if(xt.to!==Gt){const me=this.getObjectProperty(n,e,wt);at.set(wt,{from:me??xt.from,to:Gt,startTime:this.currentTime,duration:((pe=i.settings)==null?void 0:pe.duration)??ot})}const jt=at.get(wt);if(jt.duration>0&&jt.from!==jt.to){const me=this.currentTime-jt.startTime,Ae=Math.min(1,me/jt.duration),Fe=this.applyEasing(Ae,((he=i.settings)==null?void 0:he.easing)||"easeOutCubic"),we=jt.from+(jt.to-jt.from)*Fe;this.setObjectProperty(n,e,wt,we)}}}else if(i.type===it.StateReactive){this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const Z=this._layoutAnimCache.get(e.id),ot=(($e=i.settings)==null?void 0:$e.defaultDuration)||.3,at=["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 wt of at){const Gt=this.getObjectProperty(n,e,wt);if(Gt===void 0||typeof Gt!="number")continue;const xt=Z.get(wt);if(!xt)Z.set(wt,{from:Gt,to:Gt,startTime:this.currentTime,duration:0});else if(xt.to!==Gt){const me=this.getObjectProperty(n,e,wt);Z.set(wt,{from:me??xt.from,to:Gt,startTime:this.currentTime,duration:ot})}const jt=Z.get(wt);if(jt.duration>0&&jt.from!==jt.to){const me=this.currentTime-jt.startTime,Ae=Math.min(1,me/jt.duration),Fe=this.applyEasing(Ae,((Be=i.settings)==null?void 0:Be.defaultEasing)||"easeOutCubic"),we=jt.from+(jt.to-jt.from)*Fe;this.setObjectProperty(n,e,wt,we)}}}else if(i.type===it.SpringChain){const Z=((Ye=i.settings)==null?void 0:Ye.connections)||[],ot=((De=i.settings)==null?void 0:De.globalDamping)||.3;this._springChainState.has(e.id)||this._springChainState.set(e.id,new Map);const at=this._springChainState.get(e.id);for(const Gt of Z){if(!at.has(Gt.targetId)){const xt=this.objectStates.get(Gt.targetId);at.set(Gt.targetId,{x:(xt==null?void 0:xt.x)??0,y:(xt==null?void 0:xt.y)??0,vx:0,vy:0})}at.has(e.id)||at.set(e.id,{x:n.x,y:n.y,vx:0,vy:0})}const wt=at.get(e.id);if(wt){wt.x=n.x,wt.y=n.y;for(const Gt of Z){const xt=at.get(Gt.targetId);if(!xt)continue;const jt=xt.x-wt.x,me=xt.y-wt.y,Ae=Math.sqrt(jt*jt+me*me)||.001,we=(Ae-(Gt.restLength||50))*(Gt.stiffness||.8),Oe=jt/Ae*we,je=me/Ae*we;wt.vx+=Oe*t*10,wt.vy+=je*t*10,xt.vx-=Oe*t*10,xt.vy-=je*t*10,wt.vx*=1-ot*t*10,wt.vy*=1-ot*t*10,xt.vx*=1-ot*t*10,xt.vy*=1-ot*t*10;const Ee=this.objectStates.get(Gt.targetId);Ee&&(Ee.x+=xt.vx*t,Ee.y+=xt.vy*t)}n.x+=wt.vx*t,n.y+=wt.vy*t}}else if(i.type===it.ParticleEmitter){const Z=((Xe=i.settings)==null?void 0:Xe.rate)||10,ot=((Ne=i.settings)==null?void 0:Ne.speed)||100,at=((Ue=i.settings)==null?void 0:Ue.size)||5,wt=((re=i.settings)==null?void 0:re.lifetime)||2,Gt=((ve=i.settings)==null?void 0:ve.gravity)||0,xt=((Te=i.settings)==null?void 0:Te.color)||"#ffffff",jt=((He=i.settings)==null?void 0:He.maxParticles)||200,me=(Ve=i.settings)!=null&&Ve.rateInputId?this.inputs.get(i.settings.rateInputId)??Z:Z,Ae=(_e=i.settings)!=null&&_e.gravityInputId?this.inputs.get(i.settings.gravityInputId)??Gt:Gt,Fe=(Pe=i.settings)!=null&&Pe.speedInputId?this.inputs.get(i.settings.speedInputId)??ot:ot;this._emitterPools.has(e.id)||this._emitterPools.set(e.id,[]);const we=this._emitterPools.get(e.id);let Oe=0;i._pendingBurst&&i._pendingBurst>0&&(Oe=i._pendingBurst,i._pendingBurst=0);const je=Math.floor(me*t)+(Oe||0);for(let Ee=0;Ee<Math.min(je,jt-we.length);Ee++){const Me=Math.random()*Math.PI*2,vs=Fe*(.5+Math.random()*.5);we.push({x:n.x,y:n.y,vx:Math.cos(Me)*vs,vy:Math.sin(Me)*vs,life:0,maxLife:wt*(.5+Math.random()*.5),size:at*(.5+Math.random()),color:xt,opacity:1})}for(let Ee=we.length-1;Ee>=0;Ee--){const Me=we[Ee];Me.vy+=Ae*t*10,Me.x+=Me.vx*t,Me.y+=Me.vy*t,Me.life+=t,Me.opacity=Math.max(0,1-Me.life/Me.maxLife),Me.life>=Me.maxLife&&we.splice(Ee,1)}}})})}applyBehaviorSensor(t,s,o,e,n,i,a=0,r=0,l=1){var f,h,m,b,c,S,v,C,w,I,k,O,T,A,D,Y,B,R,L,$,F,X,M,E;const d=(n==null?void 0:n.intensity)||(n==null?void 0:n.strength)||1,p=Math.min(1,15*e),g=l>0?a/l:0,u=l>0?r/l:0;switch(s){case ge.Scale:{const P=((f=i==null?void 0:i.transform)==null?void 0:f.scale_x)??1,_=((h=i==null?void 0:i.transform)==null?void 0:h.scale_y)??1,V=P*(1+o*d*.4),G=_*(1+o*d*.4);t.scale_x=(t.scale_x??P)*(1-p)+V*p,t.scale_y=(t.scale_y??_)*(1-p)+G*p;break}case ge.Opacity:{const P=((m=i==null?void 0:i.transform)==null?void 0:m.opacity)??100,_=Math.max(0,Math.min(100,P-o*d*100));t.opacity=(t.opacity??P)*(1-p)+_*p;break}case ge.RotateZ:{const P=((b=i==null?void 0:i.transform)==null?void 0:b.rotation)??0,_=P+o*d*45;t.rotation=(t.rotation??P)*(1-p)+_*p;break}case ge.RotateX:{const P=((c=i==null?void 0:i.transform)==null?void 0:c.rotate_x)??0,_=P-u*o*d*60;t.rotate_x=(t.rotate_x??P)*(1-p)+_*p;break}case ge.RotateY:{const P=((S=i==null?void 0:i.transform)==null?void 0:S.rotate_y)??0,_=P+g*o*d*60;t.rotate_y=(t.rotate_y??P)*(1-p)+_*p;break}case ge.PositionX:{const P=((v=i==null?void 0:i.transform)==null?void 0:v.x)??0,_=P-g*o*d*40;t.x=(t.x??P)*(1-p)+_*p;break}case ge.PositionY:{const P=((C=i==null?void 0:i.transform)==null?void 0:C.y)??0,_=P-u*o*d*40;t.y=(t.y??P)*(1-p)+_*p;break}case ge.SkewX:{const P=((w=i==null?void 0:i.transform)==null?void 0:w.skew_x)??0,_=P+g*o*d*45;t.skew_x=(t.skew_x??P)*(1-p)+_*p,t.skew_x>85&&(t.skew_x=85),t.skew_x<-85&&(t.skew_x=-85);break}case ge.Blur:{t.style||(t.style={...i==null?void 0:i.style}),t.style.blur||(t.style.blur={...(I=i==null?void 0:i.style)==null?void 0:I.blur});const P=((O=(k=i==null?void 0:i.style)==null?void 0:k.blur)==null?void 0:O.amount)||0,_=P+o*((n==null?void 0:n.blur)||20)*d;t.style.blur.amount=(t.style.blur.amount??P)*(1-p)+_*p;break}case ge.Exposure:{t.style||(t.style={...i==null?void 0:i.style}),t.style.adjustments||(t.style.adjustments={...(T=i==null?void 0:i.style)==null?void 0:T.adjustments});const P=((D=(A=i==null?void 0:i.style)==null?void 0:A.adjustments)==null?void 0:D.exposure)||0,_=P+o*((n==null?void 0:n.exposure)||50)*d;t.style.adjustments.exposure=(t.style.adjustments.exposure??P)*(1-p)+_*p;break}case ge.HueShift:{t.style||(t.style={...i==null?void 0:i.style}),t.style.adjustments||(t.style.adjustments={...(Y=i==null?void 0:i.style)==null?void 0:Y.adjustments});const P=((R=(B=i==null?void 0:i.style)==null?void 0:B.adjustments)==null?void 0:R.hue)||0,_=P+o*((n==null?void 0:n.hue)||180)*d;t.style.adjustments.hue=(t.style.adjustments.hue??P)*(1-p)+_*p;break}case ge.Negative:{t.style||(t.style={...i==null?void 0:i.style}),t.style.adjustments||(t.style.adjustments={...(L=i==null?void 0:i.style)==null?void 0:L.adjustments});const P=((F=($=i==null?void 0:i.style)==null?void 0:$.adjustments)==null?void 0:F.negative)||0,_=P+o*((n==null?void 0:n.negative)||100)*d;t.style.adjustments.negative=(t.style.adjustments.negative??P)*(1-p)+_*p;break}case ge.CornerRadius:{const P=((X=i==null?void 0:i.transform)==null?void 0:X.corner_radius)||0,_=P+o*d*50;t.corner_radius=(t.corner_radius??P)*(1-p)+_*p;break}case ge.StrokeWidth:{t.style||(t.style={...i==null?void 0:i.style});const P=((M=i==null?void 0:i.style)==null?void 0:M.borderWidth)||0,_=P+o*d*10;t.style.borderWidth=(t.style.borderWidth??P)*(1-p)+_*p;break}case ge.LetterSpacing:{t.geometry||(t.geometry={});const P=((E=i==null?void 0:i.geometry)==null?void 0:E.letterSpacing)||0,_=P+o*d*10;t.geometry.letterSpacing=(t.geometry.letterSpacing??P)*(1-p)+_*p;break}}}getObjectProperty(t,s,o){const e=o.replace(/\[(\d+)\]/g,".$1").split(".");let n=t;for(const i of e){if(n==null||typeof n!="object")return;if(i==="style"&&t.style===void 0){n=s.style;continue}n=n[i]}return typeof n=="number"?n:void 0}setObjectProperty(t,s,o,e){const n=o.replace(/\[(\d+)\]/g,".$1").split(".");let i=t;for(let r=0;r<n.length-1;r++){const l=n[r];if(i[l]===void 0||i[l]===null){const d=s,p=n.slice(0,r+1).reduce((f,h)=>f==null?void 0:f[h],d),g=n[r+1],u=!isNaN(Number(g));i[l]=p!==void 0?Array.isArray(p)?[...p]:{...p}:u?[]:{}}i=i[l]}const a=n[n.length-1];i!=null&&(i[a]=e)}applyEasing(t,s){switch(s){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,s,o){return t*(1-o)+s*o}deepMerge(t,s){if(!t)return s;if(!s)return t;if(typeof t!="object"||typeof s!="object"||t===null||s===null)return s;if(Array.isArray(s)){if(!Array.isArray(t))return s;const e=[...t];for(let n=0;n<s.length;n++)s[n]&&typeof s[n]=="object"&&!Array.isArray(s[n])&&t[n]&&typeof t[n]=="object"?e[n]=this.deepMerge(t[n],s[n]):e[n]=s[n];return e}const o={...t};for(const e in s)Object.prototype.hasOwnProperty.call(s,e)&&(s[e]&&typeof s[e]=="object"&&!Array.isArray(s[e])?o[e]=this.deepMerge(t[e],s[e]):Array.isArray(s[e])?o[e]=this.deepMerge(t[e],s[e]):o[e]=s[e]);return o}processFabricAdjustmentsCanvas(t,s,o,e){if(!e)return t;const n=(e.exposure||0)/100,i=(e.contrast||0)/100,a=(e.saturation||0)/100,r=(e.temperature||0)/200,l=(e.tint||0)/200,d=(e.highlights||0)/500,p=(e.shadows||0)/500,g=e.hue||0,u=(e.negative||0)/100,f=e.blur||0;if(!(n!==0||i!==0||a!==0||r!==0||l!==0||d!==0||p!==0||g!==0||u!==0||f>0))return t;const m=t.naturalWidth||Math.max(1,Math.round(s)),b=t.naturalHeight||Math.max(1,Math.round(o)),c=document.createElement("canvas");c.width=m,c.height=b;const S=c.getContext("2d");if(!S)return t;const v=[];f>0&&v.push(`blur(${f}px)`),g!==0&&v.push(`hue-rotate(${Math.round(g)}deg)`),v.length>0&&(S.filter=v.join(" ")),S.drawImage(t,0,0,m,b);try{const C=S.getImageData(0,0,m,b),w=C.data,I=w.length,k=n*255,O=i>=0?(1+i)/Math.max(.01,1-i):1+i,T=1+a,A=1+r-l/2,D=1+l,Y=1-r-l/2,B=1+d+p,R=p*25.5,L=1-u/50,$=(1-L)*255;for(let F=0;F<I;F+=4){let X=w[F],M=w[F+1],E=w[F+2];if(n!==0&&(X+=k,M+=k,E+=k),i!==0&&(X=(X-127.5)*O+127.5,M=(M-127.5)*O+127.5,E=(E-127.5)*O+127.5),a!==0){const P=.2989*X+.587*M+.114*E;X=P+(X-P)*T,M=P+(M-P)*T,E=P+(E-P)*T}(r!==0||l!==0)&&(X=X*A,M=M*D,E=E*Y),(d!==0||p!==0)&&(X=X*B+R,M=M*B+R,E=E*B+R),u!==0&&(X=X*L+$,M=M*L+$,E=E*L+$),w[F]=Math.min(255,Math.max(0,X)),w[F+1]=Math.min(255,Math.max(0,M)),w[F+2]=Math.min(255,Math.max(0,E))}return S.putImageData(C,0,0),c}catch{return c}}renderFittedImage(t,s,o,e,n,i,a="cover"){const r=s.naturalWidth||s.width||n,l=s.naturalHeight||s.height||i,d=r/l,p=n/i;let g=n,u=i,f=o,h=e;a==="cover"?d>p?(g=i*d,f=o-(g-n)/2):(u=n/d,h=e-(u-i)/2):a==="contain"&&(d>p?(u=n/d,h=e+(i-u)/2):(g=i*d,f=o+(n-g)/2)),t.drawImage(s,f,h,g,u)}}const li=Nt.forwardRef(({artboard:y,src:t,style:s,autoPlay:o=!0,fit:e="Contain",alignment:n="Center",onReady:i,onTrigger:a,onInputUpdate:r,onComponentChange:l,onToggle:d,onInputChange:p,onInputFocus:g,onInputBlur:u,onLog:f,onLogicUpdate:h,onButtonClick:m,onGraphPointClick:b,currentTime:c,revision:S=0,scrollY:v,scrollX:C,mouseX:w,mouseY:I,isMouseDown:k,inputs:O,interactive:T=!0,onNavigation:A},D)=>{const Y=Nt.useRef(null),B=Nt.useRef(null);B.current||(B.current=new bs);const R=Nt.useRef(void 0),L=Nt.useRef(0),$=Nt.useRef(null),F=Nt.useRef(S),X=Nt.useRef(null),[,M]=Nt.useState(y||null),E=Nt.useRef(!0),P=Nt.useRef(o),_=Nt.useRef(c);Nt.useEffect(()=>{P.current=o},[o]),Nt.useEffect(()=>{_.current=c},[c]),Nt.useImperativeHandle(D,()=>Y.current),Nt.useEffect(()=>(E.current=!0,()=>{E.current=!1,R.current&&cancelAnimationFrame(R.current)}),[]),Nt.useEffect(()=>{B.current.setLayout(e,n)},[e,n]),Nt.useEffect(()=>{const N=B.current;a&&N.setTriggerCallback(a),r&&N.setInputUpdateCallback((H,z)=>r({[H]:z})),l&&N.setComponentChangeCallback(H=>l(H)),d&&N.setToggleCallback(d),p&&N.setInputChangeCallback(p),g&&N.setInputFocusCallback(g),u&&N.setInputBlurCallback(u),f&&N.setOnLogCallback(H=>f(H,"info")),h&&N.setLogicUpdateCallback(h),m&&N.setButtonClickCallback(m),b&&N.setGraphPointClickCallback(H=>b(H.objectId,H)),A&&N.setNavigationCallback(A)},[a,r,l,d,p,g,u,f,h,m,b,A]),Nt.useEffect(()=>{(async()=>{let H=y;if(t&&!y)try{t.startsWith("{")?H=JSON.parse(t):H=await(await fetch(t)).json()}catch(z){console.error("[ExodeUI] Failed to load src:",z)}if(H){const z=B.current,et=H.id||H.name||"default";($.current!==et||F.current!==S||X.current!==H)&&(z.load(H),$.current=et,F.current=S,X.current=H,M(H),L.current=-1,z.advance(0)),i&&i(z)}})()},[y,t,S]),Nt.useEffect(()=>{const N=H=>{if(!B.current||!E.current)return;const z=B.current,et=Y.current;if(!et)return;const Mt=et.getContext("2d");if(!Mt)return;const ct=H/1e3;L.current<0&&(L.current=ct),L.current===0&&(L.current=ct);let It=ct-L.current;It>.1&&(It=.1),L.current=ct;const mt=et.getBoundingClientRect(),kt=window.devicePixelRatio||1,Ot=Math.round(mt.width*kt),vt=Math.round(mt.height*kt);(et.width!==Ot||et.height!==vt)&&(et.width=Ot,et.height=vt);try{P.current?z.advance(It):_.current!==void 0&&z.seek(_.current),z.render(Mt,et.width,et.height)}catch(Wt){console.error("[ExodeUICanvas] Error in animation loop:",Wt),f&&f(`[Error] Animation loop crashed: ${Wt}`,"error")}R.current=requestAnimationFrame(N)};return R.current=requestAnimationFrame(N),()=>{R.current&&cancelAnimationFrame(R.current)}},[]),Nt.useEffect(()=>{const N=B.current;v!==void 0&&N.updateInput("scrollY",v),C!==void 0&&N.updateInput("scrollX",C),w!==void 0&&N.updateInput("mouseX",w),I!==void 0&&N.updateInput("mouseY",I),k!==void 0&&N.updateInput("isMouseDown",k),O&&Object.entries(O).forEach(([H,z])=>N.updateInput(H,z))},[v,C,w,I,k,O]);const V=(N,H)=>{var mt,kt,Ot;if(!T||!Y.current)return;N.stopPropagation(),"nativeEvent"in N&&N.nativeEvent&&typeof N.nativeEvent.stopImmediatePropagation=="function"?N.nativeEvent.stopImmediatePropagation():typeof N.stopImmediatePropagation=="function"&&N.stopImmediatePropagation();const z=Y.current,et=z.getBoundingClientRect(),Mt=N.clientX-et.left,ct=N.clientY-et.top,It=window.devicePixelRatio||1;if((H==="click"||H==="down"||H==="up")&&f&&f(`[Canvas] Pointer ${H} at rect(${Math.round(Mt)},${Math.round(ct)}) mapped to buffer(${Math.round(Mt*It)},${Math.round(ct*It)})`,"info"),B.current.handlePointerInput(H,Mt*It,ct*It,z.width,z.height),H==="move"){const vt=(mt=B.current)==null?void 0:mt.getLastHoveredObject();vt?(kt=B.current)!=null&&kt.isInputBoxObject(vt)?z.style.cursor="text":(Ot=B.current)!=null&&Ot.isClickableObject(vt)?z.style.cursor="pointer":z.style.cursor="default":z.style.cursor="default"}else H==="blur"&&(z.style.cursor="default")};Nt.useEffect(()=>{if(!T)return;const N=z=>{var et,Mt,ct;((et=document.activeElement)==null?void 0:et.tagName)==="INPUT"||((Mt=document.activeElement)==null?void 0:Mt.tagName)==="TEXTAREA"||(ct=B.current)==null||ct.handleKeyDown(z)},H=z=>{var et,Mt,ct;((et=document.activeElement)==null?void 0:et.tagName)==="INPUT"||((Mt=document.activeElement)==null?void 0:Mt.tagName)==="TEXTAREA"||(ct=B.current)==null||ct.handleKeyUp(z)};return window.addEventListener("keydown",N),window.addEventListener("keyup",H),()=>{window.removeEventListener("keydown",N),window.removeEventListener("keyup",H)}},[T]),Nt.useEffect(()=>{const N=Y.current;if(!N||!T)return;const H=z=>{if(z.preventDefault(),z.stopPropagation(),B.current){const et=N.getBoundingClientRect(),Mt=window.devicePixelRatio||1,ct=(z.clientX-et.left)*Mt,It=(z.clientY-et.top)*Mt;let mt=z.deltaX,kt=z.deltaY;z.deltaMode===1?(mt*=25,kt*=25):z.deltaMode===2&&(mt*=100,kt*=100),B.current.handlePointerInput("move",ct,It,N.width,N.height),B.current.handleWheel(mt,kt,ct,It,N.width,N.height)}};return N.addEventListener("wheel",H,{passive:!1}),()=>{N.removeEventListener("wheel",H)}},[T]);const[G,x]=Nt.useState([]);Nt.useEffect(()=>{if(y&&y.objects){const N=y.objects.filter(H=>{var z,et;return H.type==="Joystick"&&((z=H.inputBinding)==null?void 0:z.type)==="keyboard"&&((et=H.inputBinding.keyboardConfig)==null?void 0:et.showVirtualKeyboard)});x(N)}},[y]);const[,U]=Nt.useState(0);Nt.useEffect(()=>{if(G.length===0)return;let N;const H=()=>{U(z=>z+1),N=requestAnimationFrame(H)};return N=requestAnimationFrame(H),()=>cancelAnimationFrame(N)},[G.length]);const q=()=>G.map(N=>{const H=N.inputBinding.keyboardConfig,z=mt=>{var Ot;const kt={key:mt,code:mt,preventDefault:()=>{}};(Ot=B.current)==null||Ot.handleKeyDown(kt)},et=mt=>{var Ot;const kt={key:mt,code:mt,preventDefault:()=>{}};(Ot=B.current)==null||Ot.handleKeyUp(kt)},Mt=B.current,ct=mt=>Mt&&Mt.activeKeys?Mt.activeKeys.has(mt.toLowerCase()):!1,It=mt=>({width:"50px",height:"50px",background:mt?"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:mt?"none":"0 4px 6px rgba(0,0,0,0.1)"});return ne.jsxs("div",{style:{position:"absolute",bottom:"40px",right:"40px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",pointerEvents:"auto",zIndex:100},children:[ne.jsx("div",{style:It(ct(H.upKey)),onMouseDown:()=>z(H.upKey),onMouseUp:()=>et(H.upKey),onMouseLeave:()=>et(H.upKey),onTouchStart:mt=>{mt.preventDefault(),z(H.upKey)},onTouchEnd:mt=>{mt.preventDefault(),et(H.upKey)},children:H.upKey.toUpperCase()}),ne.jsxs("div",{style:{display:"flex",gap:"8px"},children:[ne.jsx("div",{style:It(ct(H.leftKey)),onMouseDown:()=>z(H.leftKey),onMouseUp:()=>et(H.leftKey),onMouseLeave:()=>et(H.leftKey),onTouchStart:mt=>{mt.preventDefault(),z(H.leftKey)},onTouchEnd:mt=>{mt.preventDefault(),et(H.leftKey)},children:H.leftKey.toUpperCase()}),ne.jsx("div",{style:It(ct(H.downKey)),onMouseDown:()=>z(H.downKey),onMouseUp:()=>et(H.downKey),onMouseLeave:()=>et(H.downKey),onTouchStart:mt=>{mt.preventDefault(),z(H.downKey)},onTouchEnd:mt=>{mt.preventDefault(),et(H.downKey)},children:H.downKey.toUpperCase()}),ne.jsx("div",{style:It(ct(H.rightKey)),onMouseDown:()=>z(H.rightKey),onMouseUp:()=>et(H.rightKey),onMouseLeave:()=>et(H.rightKey),onTouchStart:mt=>{mt.preventDefault(),z(H.rightKey)},onTouchEnd:mt=>{mt.preventDefault(),et(H.rightKey)},children:H.rightKey.toUpperCase()})]})]},N.id)});return ne.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[ne.jsx("canvas",{ref:Y,onPointerDown:N=>{var H;V(N,"down"),N.currentTarget.setPointerCapture(N.pointerId),(H=Y.current)==null||H.focus()},onPointerMove:N=>V(N,"move"),onPointerUp:N=>{V(N,"up"),N.currentTarget.releasePointerCapture(N.pointerId)},onPointerCancel:N=>{V(N,"up"),N.currentTarget.releasePointerCapture(N.pointerId)},onPointerLeave:N=>V(N,"blur"),onClick:N=>V(N,"click"),onKeyDown:N=>B.current.handleKeyDown(N.nativeEvent),onKeyUp:N=>B.current.handleKeyUp(N.nativeEvent),onContextMenu:N=>N.preventDefault(),tabIndex:0,style:{...s,width:"100%",height:"100%",outline:"none",display:"block",touchAction:"none",pointerEvents:T?"auto":"none"}}),q()]})});function ci(){const[y,t]=Nt.useState(null),s=Nt.useCallback((b,c)=>{y==null||y.setInputBool(b,c)},[y]),o=Nt.useCallback((b,c)=>{y==null||y.setInputNumber(b,c)},[y]),e=Nt.useCallback(b=>{y==null||y.fireTrigger(b)},[y]),n=Nt.useCallback((b,c)=>{y==null||y.setInputText(b,c)},[y]),i=Nt.useCallback((b,c)=>{y==null||y.setInputNumberArray(b,c)},[y]),a=Nt.useCallback((b,c)=>{y==null||y.setInputStringArray(b,c)},[y]),r=Nt.useCallback((b,c)=>{y==null||y.updateInput(b,c)},[y]),l=r,d=Nt.useCallback((b,c)=>{y==null||y.updateObjectOptions(b,c)},[y]),p=Nt.useCallback((b,c,S)=>{y==null||y.updateConstraint(b,c,S)},[y]),g=Nt.useCallback((b,c,S)=>{y==null||y.updateGraphData(b,c,S)},[y]),u=Nt.useCallback((b,c,S)=>{y==null||y.updateBarChartData(b,c,S)},[y]),f=Nt.useCallback((b,c)=>{y==null||y.updatePieChartData(b,c)},[y]),h=Nt.useCallback((b,c)=>{y==null||y.setDropdownOptions(b,c)},[y]),m=Nt.useCallback(b=>y==null?void 0:y.getInputValue(b),[y]);return{setEngine:t,engine:y,updateInput:r,setInputValue:l,setInputBool:s,setInputNumber:o,fireTrigger:e,setInputText:n,setInputNumberArray:i,setInputStringArray:a,updateConstraint:p,updateGraphData:g,updateBarChartData:u,updatePieChartData:f,setDropdownOptions:h,updateObjectOptions:d,getInputValue:m}}const hi=({artboard:y,config:t})=>{const s={...y.seo,...t},o=s.enableSmartExtraction!==!1;Nt.useEffect(()=>{const a=s.title||y.name;a&&(document.title=a);let r=s.description;if(!r&&o){const p=y.objects.filter(g=>{var u;return((u=g.geometry)==null?void 0:u.type)==="Text"}).sort((g,u)=>{var f,h;return(((f=u.geometry.text)==null?void 0:f.length)||0)-(((h=g.geometry.text)==null?void 0:h.length)||0)});p.length>0&&(r=p[0].geometry.text)}r&&(e("name","description",r),e("property","og:description",r)),s.keywords&&s.keywords.length>0&&e("name","keywords",s.keywords.join(", "));const l=s.ogImage||y.backgroundImage;l&&e("property","og:image",l),a&&e("property","og:title",a),e("property","og:type","website")},[s,y,o]);const e=(a,r,l)=>{let d=document.querySelector(`meta[${a}="${r}"]`);d||(d=document.createElement("meta"),d.setAttribute(a,r),document.head.appendChild(d)),d.setAttribute("content",l)},n=()=>{const a=[];return a.push(ne.jsx("h1",{children:s.title||y.name},"artboard-title")),y.objects.forEach((l,d)=>{var p,g;if(!(l.visible===!1||l.isVisible===!1))if(((p=l.geometry)==null?void 0:p.type)==="Text"){const u=l.geometry.text;u&&(l.geometry.fontSize>24?a.push(ne.jsx("h2",{children:u},l.id||d)):a.push(ne.jsx("p",{children:u},l.id||d)))}else if(((g=l.geometry)==null?void 0:g.type)==="Image"){const u=l.geometry.src,f=l.altText||l.name||"Illustration";a.push(ne.jsx("img",{src:u,alt:f},l.id||d))}else l.type==="Button"&&a.push(ne.jsx("button",{children:l.name||"Button"},l.id||d))}),a},i=s.jsonLd||{"@context":"https://schema.org","@type":"VisualArtwork",name:s.title||y.name,description:s.description,image:s.ogImage||y.backgroundImage,abstract:"Animated interface created with ExodeUI"};return ne.jsxs("div",{id:`exode-seo-${y.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:[n(),ne.jsx("script",{type:"application/ld+json",children:JSON.stringify(i)})]})},fi={version:"6.4.6"}.version;se.BAR_STYLE_PRESETS=ri,se.BehaviorSensor=ge,se.BehaviorType=it,se.ConditionOp=es,se.ExodeSEO=hi,se.ExodeUICanvas=li,se.ExodeUIEngine=bs,se.LogicOp=Ht,se.RapierPhysics=os,se.TOGGLE_SHAPE_NAME_MAP=xe,se.VERSION=fi,se.getToggleSvgPathBounds=We,se.useExodeUI=ci,Object.defineProperty(se,Symbol.toStringTag,{value:"Module"})}));