exodeui 6.4.3 → 6.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/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,_t,He,ae,ys){"use strict";var hi=Object.defineProperty;var fi=(Kt,Qt,_t)=>Qt in Kt?hi(Kt,Qt,{enumerable:!0,configurable:!0,writable:!0,value:_t}):Kt[Qt]=_t;var ht=(Kt,Qt,_t)=>fi(Kt,typeof Qt!="symbol"?Qt+"":Qt,_t);function bs(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 vs=bs(ys);var tt=(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))(tt||{}),re=(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))(re||{}),je=(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))(je||{}),Et=(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))(Et||{});function Ss(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 Cs(y){return y.replace(/\b([a-zA-Z]{4,})\b/g,(t,s)=>Ss(s))}function ws(y,t,s){return y}function Ms(y,t,s){return y}const Ve=new Map;function ts(y){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:d=0,textCase:p="none",segments:u=[],enableSegments:m=!1}=y;let h=String(t||"");p==="uppercase"?h=h.toUpperCase():p==="lowercase"?h=h.toLowerCase():p==="capitalize"&&(h=h.replace(/\b\w/g,_=>_.toUpperCase())),y.hyphenation===!0&&(h=Cs(h));const f=`${n} ${e} ${o}px "${s}", sans-serif`,v=`${h}|${f}|${r}|${l}|${d}|${m}|${JSON.stringify(u)}|hyp:${!!y.hyphenation}|comp:${y.composer}|bal:${!!y.balanceRaggedLines}`;let g=Ve.get(v);const c=typeof CanvasRenderingContext2D<"u"?CanvasRenderingContext2D.prototype.measureText:null,b=function(_){if(!c)return{width:0,fontBoundingBoxAscent:0,fontBoundingBoxDescent:0};const E=c.call(this,_);return r!==0&&_&&_.length>0?{...E,width:E.width+(_.length-1)*r}:E};if(!g){try{if(r!==0&&typeof CanvasRenderingContext2D<"u"&&(CanvasRenderingContext2D.prototype.measureText=b),m&&u&&u.length>0){const _=u.map(E=>{let P=E.text||"";const L=E.textCase||p||"none";return L==="uppercase"?P.toUpperCase():L==="lowercase"?P.toLowerCase():L==="capitalize"?P.replace(/\b\w/g,k=>k.toUpperCase()):P}).join("");if(g=He.prepareWithSegments(_,f),g){let E=0,P=o;for(const L of u){let k=L.text||"";if(!k)continue;const A=L.textCase||p||"none";A==="uppercase"?k=k.toUpperCase():A==="lowercase"?k=k.toLowerCase():A==="capitalize"&&(k=k.replace(/\b\w/g,O=>O.toUpperCase()));const T=L.fontSize||o;T>P&&(P=T);const R=`${L.fontStyle||n} ${L.fontWeight||e} ${T}px "${L.fontFamily||s}", sans-serif`,F=He.prepareWithSegments(k,R);if(F&&F.widths)for(let O=0;O<F.widths.length;O++){const W=E+O;if(W<g.widths.length){g.widths[W]=F.widths[O];const V=F.kinds[O];if(V===2){const U=k[O];U===`
2
- `||U==="\r"?g.kinds[W]=2:g.kinds[W]=0}else g.kinds[W]=V}}E+=k.length}g.fullText=_,g.maxFontSize=P}}else g=He.prepareWithSegments(h,f);g&&Ve.set(v,g)}catch(_){return console.error("[ExodeUI] Pretext prepare failed:",_),{width:a,height:0,lineCount:0,lines:[]}}finally{r!==0&&typeof CanvasRenderingContext2D<"u"&&c&&(CanvasRenderingContext2D.prototype.measureText=c)}if(Ve.size>500){const _=Ve.keys().next().value;_&&Ve.delete(_)}}if(d>0&&g&&g.widths&&!g.indentApplied){const _=[...g.widths],E=g.fullText||h;let P=!0;for(let L=0;L<E.length;L++)P&&_[L]!==void 0&&(_[L]+=d,P=!1),(E[L]===`
3
- `||E[L]==="\r")&&(P=!0,E[L]==="\r"&&E[L+1]===`
4
- `&&L++);g={...g,widths:_,indentApplied:!0}}if(!g)return{width:a,height:0,lineCount:0,lines:[]};let S=i;typeof S=="string"&&(S=parseFloat(S)),S>5&&o>0&&(S=S/o),r!==0&&(CanvasRenderingContext2D.prototype.measureText=b);let w;try{const _=g.maxFontSize||o;if(a>=1e5){const E=h.split(/\r\n|\r|\n/);w={lines:E.map(P=>({text:P,width:0})),height:E.length*(S*_),lineCount:E.length}}else w=He.layoutWithLines(g,a,S*_)}finally{r!==0&&c&&(CanvasRenderingContext2D.prototype.measureText=c)}let C=(w==null?void 0:w.height)!==void 0&&w.height>0?w.height:(((I=w==null?void 0:w.lines)==null?void 0:I.length)||0)*S*o;if(l>0&&w&&w.lines&&w.lines.length>1){let _=0;const E=g.fullText||t;for(let P=0;P<w.lines.length-1;P++)_+=w.lines[P].text.length,(E[_]===`
5
- `||E[_]==="\r")&&(C+=l,_++,E[_-1]==="\r"&&E[_]===`
6
- `&&_++)}let M=(w==null?void 0:w.lines)||[];return y.composer==="every-line"&&M.length>1&&(M=ws(M)),y.balanceRaggedLines===!0&&M.length>1&&(M=Ms(M)),{width:a,height:C,lineCount:M.length,lines:M}}function es(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 ss(y,t,s){try{const o=y.autoLayout;return!o||!o.enabled?{childUpdates:[]}:(o.mode||"linear")==="grid"?ks(y,t,s):Is(y,t,s)}catch(o){return console.error("Layout Engine Error:",o),{childUpdates:[]}}}function Is(y,t,s){var k,A;const o=y.autoLayout,{direction:e,spacing:n,padding:i,align:a,wrap:r}=o,l=e==="vertical",d=t.map(T=>{const R=s(T.id),F=T.geometry;let O=(R==null?void 0:R.width)??F.width??100,W=(R==null?void 0:R.height)??F.height??100;if(F.type==="Ellipse"||F.type==="Polygon"||F.type==="Star"){const V=(R==null?void 0:R.radius)??F.radius??(R==null?void 0:R.outer_radius)??F.outer_radius??50;O=V*2,W=V*2}else if(F.type==="Text"){const V=ts({text:(R==null?void 0:R.text)??F.text??"",fontFamily:F.fontFamily,fontSize:F.fontSize,fontWeight:F.fontWeight,fontStyle:F.fontStyle,lineHeight:F.lineHeight,width:F.width||200,letterSpacing:F.letterSpacing,paragraphSpacing:F.paragraphSpacing,paragraphIndent:F.paragraphIndent,textCase:F.textCase,segments:F.segments,enableSegments:F.enableSegments});W=V.height,F.width||(O=V.width)}return O*=T.transform.scale_x||1,W*=T.transform.scale_y||1,{id:T.id,w:O,h:W,original:T}});let p=y.width,u=y.height;const m=((k=y.layoutProps)==null?void 0:k.width)==="hug",h=((A=y.layoutProps)==null?void 0:A.height)==="hug",f=[];let v=[],g=0,c=0;const b=p-i.left-i.right,S=u-i.top-i.bottom;d.forEach(T=>{r&&v.length>0&&(l?c+n+T.h>S:g+n+T.w>b)?(f.push({children:v,width:g,height:c}),v=[T],g=T.w,c=T.h):(v.push(T),l?(g=Math.max(g,T.w),c+=(v.length>1?n:0)+T.h):(g+=(v.length>1?n:0)+T.w,c=Math.max(c,T.h)))}),v.length>0&&f.push({children:v,width:g,height:c}),m&&!l&&(p=Math.max(...f.map(T=>T.width),0)+i.left+i.right),h&&l&&(u=Math.max(...f.map(T=>T.height),0)+i.top+i.bottom);const w=[];let C=i.left,M=i.top;const I=a.toLowerCase(),_=I==="center"||I.endsWith("-center"),E=I.endsWith("-right"),P=I==="center"||I.startsWith("center-"),L=I.startsWith("bottom-");return f.forEach(T=>{let R=C,F=M;l?P?F=i.top+(u-i.top-i.bottom-T.height)/2:L&&(F=u-i.bottom-T.height):_?R=i.left+(p-i.left-i.right-T.width)/2:E&&(R=p-i.right-T.width),T.children.forEach(O=>{var Y,ot;let W=R,V=F;l?_?W+=(T.width-O.w)/2:E&&(W+=T.width-O.w):P?V+=(T.height-O.h)/2:L&&(V+=T.height-O.h);const U=((Y=O.original.layoutProps)==null?void 0:Y.width)==="fill",D=((ot=O.original.layoutProps)==null?void 0:ot.height)==="fill";w.push({id:O.id,x:W+O.w/2-p/2,y:V+O.h/2-u/2,width:U&&l?T.width:void 0,height:D?l?void 0:T.height:void 0}),l?F+=O.h+n:R+=O.w+n}),l?C+=T.width+n:M+=T.height+n}),{frameWidth:m?p:void 0,frameHeight:h?u:void 0,childUpdates:w}}function ks(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 u=d-r.left-r.right,m=p-r.top-r.bottom,h=es(e||"1fr",u,i),f=es(n||"auto",m,a),v=h.length>0?h.reduce((E,P)=>E+P,0)+(h.length-1)*i:0,g=f.length>0?f.reduce((E,P)=>E+P,0)+(f.length-1)*a:0,c=l.toLowerCase(),b=c==="center"||c.endsWith("-center"),S=c.endsWith("-right"),w=c==="center"||c.startsWith("center-"),C=c.startsWith("bottom-");let M=0,I=0;b?M=(u-v)/2:S&&(M=u-v),w?I=(m-g)/2:C&&(I=m-g);const _=[];return t.forEach((E,P)=>{var ot,J;const L=P%h.length||0,k=Math.floor(P/h.length)||0;k>=f.length&&f.push(100);const A=h[L],T=f[k];let R=r.left+M+h.slice(0,L).reduce((at,j)=>at+j+i,0),F=r.top+I+f.slice(0,k).reduce((at,j)=>at+j+a,0);const O=s(E.id),W=E.geometry;let V=(O==null?void 0:O.width)??W.width??100,U=(O==null?void 0:O.height)??W.height??100;if(W.type==="Ellipse"||W.type==="Polygon"||W.type==="Star"){const at=(O==null?void 0:O.radius)??W.radius??(O==null?void 0:O.outer_radius)??W.outer_radius??50;V=at*2,U=at*2}V*=E.transform.scale_x||1,U*=E.transform.scale_y||1;let D=R,Y=F;b?D+=(A-V)/2:S&&(D+=A-V),w?Y+=(T-U)/2:C&&(Y+=T-U),_.push({id:E.id,x:D+V/2-d/2,y:Y+U/2-p/2,width:((ot=E.layoutProps)==null?void 0:ot.width)==="fill"?A:void 0,height:((J=E.layoutProps)==null?void 0:J.height)==="fill"?T:void 0})}),{childUpdates:_}}class is{constructor(){ht(this,"world",null);ht(this,"bodies",new Map);ht(this,"colliders",new Map);ht(this,"joints",new Map);ht(this,"initialized",!1);ht(this,"bodyIdByCollider",new Map);ht(this,"onCollisionCB",null);ht(this,"eventQueue",null)}setCollisionCallback(t){this.onCollisionCB=t}async init(t){this.initialized||(await ae.init(),this.world=new ae.World(new ae.Vector2(t.x*100,t.y*100)),this.eventQueue=new ae.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 ae.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?ae.RigidBodyDesc.fixed():ae.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=ae.ColliderDesc.cuboid(t.width/2,t.height/2);break;case"Ellipse":e=ae.ColliderDesc.ball(Math.max(t.width,t.height)/2);break;case"Triangle":case"Star":case"Polygon":e=ae.ColliderDesc.cuboid(t.width/2,t.height/2);break;default:e=ae.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 ae.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 ae.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 ae.Vector2(s,o),!0)}applyImpulse(t,s,o){const e=this.bodies.get(t);e&&e.applyImpulse(new ae.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 ae.Vector2(t.anchorA.x,t.anchorA.y),n=new ae.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=ae.JointData.spring(a,r,l,e,n)}else i=ae.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=y=>y,Ts=y=>y>0?1:0,Ps=y=>y<1?0:1,os=y=>y*y,as=y=>y*(2-y),rs=y=>y<.5?2*y*y:-1+(4-2*y)*y,_s=y=>y*y*y,Es=y=>--y*y*y+1,As=y=>y<.5?4*y*y*y:(y-1)*(2*y-2)*(2*y-2)+1,Os=y=>y*y*y*y,Ls=y=>1- --y*y*y*y,Rs=y=>y<.5?8*y*y*y*y:1-8*--y*y*y*y,Fs=y=>y*y*y*y*y,$s=y=>1+--y*y*y*y*y,Bs=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),Ws=y=>Math.sin(y*Math.PI/2),Ds=y=>-(Math.cos(Math.PI*y)-1)/2,Ys=y=>y===0?0:Math.pow(2,10*(y-1)),Xs=y=>y===1?1:1-Math.pow(2,-10*y),Ns=y=>y===0?0:y===1?1:y<.5?Math.pow(2,20*y-10)/2:(2-Math.pow(2,-20*y+10))/2,Vs=y=>1-Math.sqrt(1-y*y),zs=y=>Math.sqrt(1- --y*y),Gs=y=>y<.5?(1-Math.sqrt(1-4*y*y))/2:(Math.sqrt(1-(-2*y+2)*(-2*y+2))+1)/2,Ue=1.70158,qe=Ue*1.525,ls=Ue+1,Hs=y=>ls*y*y*y-Ue*y*y,Us=y=>1+ls*Math.pow(y-1,3)+Ue*Math.pow(y-1,2),qs=y=>y<.5?Math.pow(2*y,2)*((qe+1)*2*y-qe)/2:(Math.pow(2*y-2,2)*((qe+1)*(y*2-2)+qe)+2)/2,cs=2*Math.PI/3,hs=2*Math.PI/4.5,Js=y=>y===0?0:y===1?1:-Math.pow(2,10*y-10)*Math.sin((y*10-10.75)*cs),Ks=y=>y===0?0:y===1?1:Math.pow(2,-10*y)*Math.sin((y*10-.75)*cs)+1,Qs=y=>y===0?0:y===1?1:y<.5?-(Math.pow(2,20*y-10)*Math.sin((20*y-11.125)*hs))/2:Math.pow(2,-20*y+10)*Math.sin((20*y-11.125)*hs)/2+1,Je=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,Zs=y=>1-Je(1-y),js=Je,ti=y=>y<.5?(1-Je(1-2*y))/2:(1+Je(2*y-1))/2,Ze=new Map,ze=(y,t,s,o)=>{const e=`${y},${t},${s},${o}`;if(Ze.has(e))return Ze.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 u=0;u<8;u++){const m=n(p)-d;if(Math.abs(m)<1e-6)return p;const h=a(p);if(Math.abs(h)<1e-6)break;p=p-m/h}return p},l=d=>d===0?0:d===1?1:i(r(d));return Ze.set(e,l),l},fs=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)},ds={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)},Ke={Linear:ns,EaseInQuad:os,EaseOutQuad:as,EaseInOutQuad:rs,EaseInCubic:_s,EaseOutCubic:Es,EaseInOutCubic:As,EaseInQuart:Os,EaseOutQuart:Ls,EaseInOutQuart:Rs,EaseInQuint:Fs,EaseOutQuint:$s,EaseInOutQuint:Bs,EaseInSine:xs,EaseOutSine:Ws,EaseInOutSine:Ds,EaseInExpo:Ys,EaseOutExpo:Xs,EaseInOutExpo:Ns,EaseInCirc:Vs,EaseOutCirc:zs,EaseInOutCirc:Gs,EaseInBack:Hs,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=y=>{const t=y.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=(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,u=0;const m=o.rotation*Math.PI/180,h=Math.cos(m),f=Math.sin(m),v=r*n*h-l*i*f+o.x,g=r*n*f+l*i*h+o.y;d.forEach(I=>{const _=e(I.boneId);if(!_)return;const E={x:_.x,y:_.y,rotation:_.rotation,scaleX:_.scale_x??1,scaleY:_.scale_y??1},P=s[I.boneId]||[1,0,0,1,0,0],L=v*P[0]+g*P[2]+P[4],k=v*P[1]+g*P[3]+P[5],A=E.rotation*Math.PI/180,T=Math.cos(A),R=Math.sin(A),F=L*E.scaleX*T-k*E.scaleY*R+E.x,O=L*E.scaleX*R+k*E.scaleY*T+E.y;p+=F*I.amount,u+=O*I.amount});const c=[...d].sort((I,_)=>_.amount-I.amount);if(c.length>=2&&c[0].amount>0&&c[1].amount>0){const I=e(c[0].boneId),_=e(c[1].boneId);if(I&&_&&I.length!==void 0&&_.length!==void 0){const E=I.length*(I.scale_y??1),P=I.rotation*Math.PI/180,L=I.x-E*Math.sin(P),k=I.y+E*Math.cos(P),A=_.length*(_.scale_y??1),T=_.rotation*Math.PI/180,R=_.x-A*Math.sin(T),F=_.y+A*Math.cos(T);let O=null,W=null,V=!1;const U=1;if(Math.hypot(I.x-_.x,I.y-_.y)<U||Math.hypot(I.x-R,I.y-F)<U?(O=I.x,W=I.y):(Math.hypot(L-_.x,k-_.y)<U||Math.hypot(L-R,k-F)<U)&&(O=L,W=k,V=!0),O!==null&&W!==null){const D=s[c[0].boneId]||[1,0,0,1,0,0],Y=D[0]*D[3]-D[1]*D[2];let ot=0,J=0;if(Y!==0){const at=(D[2]*D[5]-D[3]*D[4])/Y,j=(D[1]*D[4]-D[0]*D[5])/Y,it=Math.atan2(-D[1],D[3]);if(!V)ot=at,J=j;else{const N=-D[2]/Y,ct=D[0]/Y,Mt=Math.hypot(N,ct),bt=I.length*Mt;ot=at-bt*Math.sin(it),J=j+bt*Math.cos(it)}const B=Math.hypot(v-ot,g-J),X=Math.hypot(p-O,u-W);if(X>0&&B>0){const N=Math.max(X,.01),ct=Math.min(B/N,3),Mt=O+(p-O)*ct,bt=W+(u-W)*ct,wt=c[0].amount,gt=c[1].amount,It=Math.min(wt,gt)*2,ut=1-Math.pow(1-It,4);p=p*(1-ut)+Mt*ut,u=u*(1-ut)+bt*ut}}}}}const b=o.rotation*Math.PI/180,S=Math.cos(b),w=Math.sin(b),C=p-o.x,M=u-o.y;return{x:(C*S+M*w)/n,y:(-C*w+M*S)/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 u=a(r.in_x,r.in_y,d);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,d);p.out_x=u.x,p.out_y=u.y}return p})};function ii(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 ni(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 h=Math.max(20,Math.floor((t+s)/10)),f=Math.max(2,Math.floor(h*(t/(t+s)))),v=Math.max(2,Math.floor(h*(s/(t+s))));for(let g=0;g<f;g++)r.push({x:-t/2+t/f*g,y:-s/2,nx:0,ny:-1});for(let g=0;g<v;g++)r.push({x:t/2,y:-s/2+s/v*g,nx:1,ny:0});for(let g=0;g<f;g++)r.push({x:t/2-t/f*g,y:s/2,nx:0,ny:1});for(let g=0;g<v;g++)r.push({x:-t/2,y:s/2-s/v*g,nx:-1,ny:0})}else if(l==="Ellipse"){const h=Math.max(60,Math.floor(Math.PI*Math.max(t,s)/5));for(let f=0;f<h;f++){const v=f/h*Math.PI*2,g=Math.cos(v),c=Math.sin(v);r.push({x:g*t/2,y:c*s/2,nx:g,ny:c})}}else if(l==="Triangle"){const h={x:0,y:-s/2},f={x:t/2,y:s/2},v={x:-t/2,y:s/2},g=20;let c=f.x-h.x,b=f.y-h.y,S=Math.hypot(c,b),w=-b/S,C=c/S;for(let M=0;M<g;M++)r.push({x:h.x+c*(M/g),y:h.y+b*(M/g),nx:w,ny:C});c=v.x-f.x,b=v.y-f.y,S=Math.hypot(c,b),w=-b/S,C=c/S;for(let M=0;M<g;M++)r.push({x:f.x+c*(M/g),y:f.y+b*(M/g),nx:w,ny:C});c=h.x-v.x,b=h.y-v.y,S=Math.hypot(c,b),w=-b/S,C=c/S;for(let M=0;M<g;M++)r.push({x:v.x+c*(M/g),y:v.y+b*(M/g),nx:w,ny:C})}else for(let f=0;f<80;f++){const v=f/80*Math.PI*2,g=Math.cos(v),c=Math.sin(v);r.push({x:g*t/2,y:c*s/2,nx:g,ny:c})}const d=i*Math.PI/180,p=Math.cos(d),u=Math.sin(d);return r.map(h=>{const f=ii(h.x,h.y,e,o,n),v=h.nx*(1-a)+p*a,g=h.ny*(1-a)+u*a;let c=Math.hypot(v,g);return c===0&&(c=1),{x:h.x+v/c*f,y:h.y+g/c*f}})}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(){ht(this,"artboard",null);ht(this,"objectStates",new Map);ht(this,"physicsEngine",null);ht(this,"activeStateMachine",null);ht(this,"inputs",new Map);ht(this,"inputNameMap",new Map);ht(this,"layerStates",new Map);ht(this,"pretextCache",new Map);ht(this,"pointerHistory",[]);ht(this,"MAX_HISTORY",200);ht(this,"imageCache",new Map);ht(this,"lastValidSvgImgMap",new Map);ht(this,"maskBuffer",null);ht(this,"maskCtx",null);ht(this,"lumaBuffer",null);ht(this,"lumaCtx",null);ht(this,"_noiseTileCanvas",null);ht(this,"layout",{fit:"Contain",alignment:"Center"});ht(this,"onTrigger");ht(this,"onInputUpdate");ht(this,"onComponentChange");ht(this,"onToggle");ht(this,"onInputChange");ht(this,"onInputFocus");ht(this,"onInputBlur");ht(this,"onLog");ht(this,"onButtonClick");ht(this,"onGraphPointClick");ht(this,"justFiredTriggers",new Set);ht(this,"rootTransform",null);ht(this,"canvasWidth",0);ht(this,"canvasHeight",0);ht(this,"lastHoveredObjectId",null);ht(this,"_lastPointerPos",null);ht(this,"_prevPointerPos",null);ht(this,"_mouseDelta",{dx:0,dy:0});ht(this,"focusedId",null);ht(this,"draggingSliderId",null);ht(this,"draggingJoystickId",null);ht(this,"activeDropdownId",null);ht(this,"activeObjectId",null);ht(this,"draggingListViewId",null);ht(this,"draggingListViewIsScrollbar",!1);ht(this,"scrollOffset",{x:0,y:0});ht(this,"_totalScroll",{x:0,y:0});ht(this,"draggingBehaviors",new Set);ht(this,"dragStartPointer",null);ht(this,"dragStartPositions",new Map);ht(this,"isMouseDown",!1);ht(this,"activeKeys",new Set);ht(this,"_layoutAnimCache",new Map);ht(this,"_springChainState",new Map);ht(this,"_emitterPools",new Map);ht(this,"objectVelocities",new Map);ht(this,"currentTime",0);ht(this,"frameCount",0);ht(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});ht(this,"onLogicUpdate");ht(this,"logicNodeValues",new Map);ht(this,"logicNodeState",new Map);ht(this,"pointerDownTimes",new Map);ht(this,"activeHoverIds",new Set);ht(this,"onNavigation");ht(this,"periodicTriggerTimes",new Map);ht(this,"wasInView",new Set);ht(this,"scrollProgressLastValue",new Map);ht(this,"debug_objectsRendered",0);ht(this,"debug_objectsTotal",0);ht(this,"lastRenderTime",0);ht(this,"debugMode",!1);ht(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,d=0,p=0,u;for(;(u=s.exec(t))!==null;){const m=u[1],h=(u[2].match(o)||[]).map(parseFloat),f=m===m.toLowerCase(),v=m.toUpperCase();let g=0;const c=S=>{let w=h[g++];return f&&(w+=S?i:a),w},b=()=>({x:c(!0),y:c(!1)});switch(v){case"M":{const S=b();for(d=i=S.x,p=a=S.y,e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a,moveTo:!0});g<h.length;){const w=b();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(;g<h.length;){const S=b();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"H":for(;g<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(;g<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(;g<h.length;){const S=b(),w=b(),C=b();if(e.length>0){const M=e[e.length-1];M.out_x=S.x,M.out_y=S.y}i=C.x,a=C.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(;g<h.length;){const S={x:2*i-r,y:2*a-l},w=b(),C=b();if(e.length>0){const M=e[e.length-1];M.out_x=S.x,M.out_y=S.y}i=C.x,a=C.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"Q":for(;g<h.length;){const S=b(),w=b();if(e.length>0){const C=e[e.length-1];C.out_x=C.x+2/3*(S.x-C.x),C.out_y=C.y+2/3*(S.y-C.y)}i=w.x,a=w.y,e.push({x:i,y:a,in_x:i+2/3*(S.x-i),in_y:a+2/3*(S.y-a),out_x:i,out_y:a}),r=S.x,l=S.y}break;case"T":for(;g<h.length;){const S={x:2*i-r,y:2*a-l},w=b();if(e.length>0){const C=e[e.length-1];C.out_x=C.x+2/3*(S.x-C.x),C.out_y=C.y+2/3*(S.y-C.y)}i=w.x,a=w.y,e.push({x:i,y:a,in_x:i+2/3*(S.x-i),in_y:a+2/3*(S.y-a),out_x:i,out_y:a}),r=S.x,l=S.y}break;case"Z":if(n=!0,e.length>0){const S=e[e.length-1];S.closePath=!0;const w=[...e].reverse().find(C=>C.moveTo)||e[0];w&&Math.hypot(w.x-S.x,w.y-S.y)<.1&&(w.in_x=S.in_x,w.in_y=S.in_y,e.pop(),e.length>0&&(e[e.length-1].closePath=!0))}i=d,a=p;break;default:if(h.length>=2){const S=b();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}}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,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 m=this.objectStates.get(e.id);m&&((i=m.geometry)==null?void 0:i.type)==="LineGraph"&&(!m.geometry.datasets||m.geometry.datasets.length===0?m.geometry.datasets=JSON.parse(JSON.stringify(p.datasets)):m.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(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 u;const p=((u=i.datasets)==null?void 0:u[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=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,d,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:((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:((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),d=s.minAlpha??0,p=s.maxAlpha??1,u=(Math.random()*(p-d)+d).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),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=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 d=ss(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(u=>u.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 u,m;return p.name===l.name||p.id===l.name||(l.name==="Entry"||l.id==="entry")&&(((u=p.name)==null?void 0:u.toLowerCase())==="onload"||((m=p.name)==null?void 0:m.toLowerCase())==="intro")})||null),d&&((i=this.artboard.animationFlow)!=null&&i.some(u=>(u.trigger==="on_load"||u.trigger==="after_delay")&&u.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,u,m;let o;if(this.inputs.has(t)){const h=(l=this.activeStateMachine)==null?void 0:l.inputs.find(f=>f.id===t);h&&typeof h.value=="object"&&(o=h.value.type)}else{const h=this.inputNameMap.get(t);if(h&&h.length>0){const f=(d=this.activeStateMachine)==null?void 0:d.inputs.find(v=>v.id===h[0]);f&&typeof f.value=="object"&&(o=f.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,f=n.max??100;e=Math.random()*(f-h)+h}else if(n.type==="RandomColor"||n.type==="random_color"||n.minAlpha!==void 0){const h=Math.floor(Math.random()*256),f=Math.floor(Math.random()*256),v=Math.floor(Math.random()*256),g=n.minAlpha??0,c=n.maxAlpha??1,b=(Math.random()*(c-g)+g).toFixed(2);e=`rgba(${h}, ${f}, ${v}, ${b})`}}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&&((m=this.artboard)==null||m.objects.forEach(h=>{var g;const f=(g=h.options)==null?void 0:g.dataInputId;if(h.inputId===t||h.name===t||f===t||a&&(a.includes(h.inputId)||f&&a.includes(f))){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 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,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(m=>m.id===t);if(e){const m=(f,v)=>{const g=e.inputs.find(c=>c.id===f);return g?g.sourceId?this.evaluateLogicTree(g.sourceId,g.sourceHandleId,o):g.value!==void 0?g.value:v:v};let h=0;switch(e.op){case Et.AND:h=m("a",!1)&&m("b",!1);break;case Et.OR:h=m("a",!1)||m("b",!1);break;case Et.NOT:h=!m("in",!1);break;case Et.XOR:h=!!m("a",!1)!=!!m("b",!1);break;case Et.OBJECT:h=e.name;break;case Et.PROPERTY:case Et.GET_PROPERTY:{const f=m("id","");if(!f){h=0;break}const v=e.name;if(!v||v==="GET_PROPERTY"||v==="PROPERTY"){h=0;break}const g=this.objectStates.get(f);if(!g){h=0;break}v in g?h=g[v]:h=this.resolvePath(g,v);break}case Et.SET_PROPERTY:{const f=m("id",""),v=m("value",void 0);if(!f||v===void 0){h=0;break}const g=e.name;if(!g||g==="SET_PROPERTY"){h=0;break}const c=this.objectStates.get(f);if(!c){h=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(g))c[g]=v,h=v;else{const S=g.replace(/\[(\d+)\]/g,".$1").split(".");let w=c;for(let M=0;M<S.length-1;M++){const I=S[M],_=S[M+1];w[I]===void 0&&(w[I]=isNaN(Number(_))?{}:[]),w=w[I]}const C=S[S.length-1];w[C]=v,h=v}break}case Et.ADD:h=m("a",0)+m("b",0);break;case Et.SUB:h=m("a",0)-m("b",0);break;case Et.MUL:h=m("a",0)*m("b",0);break;case Et.DIV:{const f=m("b",1);h=f===0?0:m("a",0)/f;break}case Et.MOD:h=m("a",0)%m("b",1);break;case Et.POW:h=Math.pow(m("a",0),m("b",1));break;case Et.ABS:h=Math.abs(m("in",0));break;case Et.ROUND:h=Math.round(m("in",0));break;case Et.FLOOR:h=Math.floor(m("in",0));break;case Et.CEIL:h=Math.ceil(m("in",0));break;case Et.SIN:h=Math.sin(m("in",0));break;case Et.COS:h=Math.cos(m("in",0));break;case Et.TAN:h=Math.tan(m("in",0));break;case Et.CLAMP:{const f=m("in",0),v=m("min",0),g=m("max",1);h=Math.max(v,Math.min(g,f));break}case Et.REMAP:{const f=m("in",0),v=m("inMin",0),g=m("inMax",100),c=m("outMin",0),b=m("outMax",1);h=g===v?c:c+(f-v)*(b-c)/(g-v);break}case Et.EQ:h=m("a",0)==m("b",0);break;case Et.NEQ:h=m("a",0)!=m("b",0);break;case Et.GT:h=m("a",0)>m("b",0);break;case Et.LT:h=m("a",0)<m("b",0);break;case Et.GTE:h=m("a",0)>=m("b",0);break;case Et.LTE:h=m("a",0)<=m("b",0);break;case Et.IF_ELSE:h=m("cond",!1)?m("then",0):m("else",0);break;case Et.VALUE:h=e.value!==void 0?e.value:0;break;case Et.INPUT:h=this.inputs.get(e.name)??0;break;case Et.LOG:{const f=m("in","");this.debugLog(`[User Logic] ${f}`),h=f;break}case Et.SCROLL_X:h=this.inputs.get("scrollX")??0;break;case Et.SCROLL_Y:h=this.inputs.get("scrollY")??0;break;case Et.MOUSE_X:h=this.inputs.get("mouseX")??0;break;case Et.MOUSE_Y:h=this.inputs.get("mouseY")??0;break;case Et.IS_MOUSE_DOWN:h=this.inputs.get("isMouseDown")??!1;break;case Et.EFFECTOR:{const f=m("id",""),v=m("intensity",1),g=m("trigger",!0);if(!f||!g){h=0;break}const c=e.name;if(!c){h=0;break}const b=this.objectStates.get(f);if(!b){h=0;break}if(["glitch","halftone","pixelate","noise","acid_gradient","acid_rave","shimmer"].includes(c))b.style||(b.style={}),b.style.artEffect={enabled:!0,type:c,intensity:v},h=1;else{b.behaviors||(b.behaviors=[]);let w=b.behaviors.find(C=>C.type===c);w?(w.enabled=!0,w.settings||(w.settings={}),w.settings.intensity=v):(w={id:`eff_${Date.now()}_${c}`,type:c,enabled:!0,sensors:[],settings:{intensity:v}},b.behaviors.push(w)),h=1}break}case Et.MONITOR:{h=m("in",0);break}case Et.SPRING_PULL:{const f=m("objectId",""),v=m("forceX",0),g=m("forceY",0);f&&((l=this.artboard)==null||l.objects.forEach(c=>{c.behaviors&&c.behaviors.forEach(b=>{var S;if(b.type===tt.SpringChain&&((S=b.settings)!=null&&S.connections)&&(b.settings.connections.some(C=>C.targetId===f)||c.id===f)){this._springChainState.has(c.id)||this._springChainState.set(c.id,new Map);const C=this._springChainState.get(c.id);if(!C.has(f)){const I=this.objectStates.get(f);C.set(f,{x:(I==null?void 0:I.x)??0,y:(I==null?void 0:I.y)??0,vx:0,vy:0})}const M=C.get(f);M&&(M.vx+=v,M.vy+=g)}})})),h=1;break}case Et.SPRING_SETTLE:{const f=m("objectId","");let v=!0;if(f){const g=m("threshold",1);this._springChainState.forEach(c=>{const b=c.get(f);b&&(Math.abs(b.vx)>g||Math.abs(b.vy)>g)&&(v=!1)})}h=v;break}case Et.EMIT:{const f=m("objectId",""),v=m("count",20);f&&((d=this.artboard)==null||d.objects.forEach(g=>{g.behaviors&&g.behaviors.forEach(c=>{c.type===tt.ParticleEmitter&&g.id===f&&(c._pendingBurst=(c._pendingBurst||0)+v)})})),h=1;break}default:h=0;break}if(this.logicNodeValues.set(t,h),e.op===Et.DELAY){const f=m("delay",0),v=m("in",0);let g=this.logicNodeState.get(t);for(g||(g={queue:[]},this.logicNodeState.set(t,g)),g.queue.push({time:this.currentTime+f,value:v});g.queue.length>0&&g.queue[0].time<=this.currentTime;)g.lastValue=g.queue.shift().value;h=g.lastValue??0}return h}const n=(p=this.activeStateMachine)==null?void 0:p.inputs.find(m=>m.id===t||m.name===t);if(n&&n.sourceId&&!o.has(n.sourceId)){const m=this.evaluateLogicTree(n.sourceId,n.sourceHandleId,o);return this.inputs.set(n.id,m),m}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 m=(u=this.activeStateMachine)==null?void 0:u.inputs.find(h=>h.id===t);if(m&&m.value.type==="Number"&&typeof i=="number"){const h=m.value.defaultValue??m.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===Et.SET_PROPERTY||t.op===Et.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],m=r[p+1];l[u]===void 0&&(l[u]=isNaN(Number(m))?{}:[]),l=l[u]}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(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=(d=(l=(r=this.artboard)==null?void 0:r.objects.find(f=>f.id===e))==null?void 0:l.triggers)==null?void 0:d.find(f=>f.id===o.triggerId),m=(u==null?void 0:u.duration)||0;o.elapsedHold+=t*1e3;let h=o.elapsedHold>=m;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 f=(p=this.artboard)==null?void 0:p.animations.find(v=>v.id===u.exitAnimationId);f?(o.phase="exit",o.animation=f,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,u=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,m=`analytics_${s.id}`,h=this.wasInView.has(m);u&&!h&&this.fireAnalyticsEvent(s.id,"visible"),u?this.wasInView.add(m):this.wasInView.delete(m)}}}),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,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),m=(((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),f=50,v=u.x+m/2>=-this.canvasWidth/2-f&&u.x-m/2<=this.canvasWidth/2+f&&u.y+h/2>=-this.canvasHeight/2-f&&u.y-h/2<=this.canvasHeight/2+f,g=this.wasInView.has(s.id);v&&!g&&(!e.conditions||this.checkConditions(e.conditions))&&this.fireEventForObject(s.id,"Scroll Into View"),v?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),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 d,p,u,m,h,f,v,g,c;const a=((d=o.constraints)==null?void 0:d[i])||{},r={...n,...a},l=r.strength??1;if(r.type==="Translation"){const b=this.getGlobalTransform(r.targetId);if(b){const S=r.offsetX||0,w=r.offsetY||0,C=b.x+S,M=b.y+w,I=r.useSpring;if(I){const P=this.objectVelocities.get(s.id)||{vx:0,vy:0},L=Math.max(0,Math.min(t,.05)),k=r.copyX!==!1,A=r.copyY!==!1,T=k?e.x+(C-e.x)*l:e.x,R=A?e.y+(M-e.y)*l:e.y,{x:F,y:O,vx:W,vy:V}=this.computeSpring(e.x,e.y,P.vx,P.vy,T,R,r,L);k&&(e.x=F),A&&(e.y=O),this.objectVelocities.set(s.id,{vx:k?W:0,vy:A?V: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 _=!1,E=!1;if((p=r.limitX)!=null&&p.enabled){const P=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==P&&(_=!0)}if((u=r.limitY)!=null&&u.enabled){const P=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==P&&(E=!0)}if((_||E)&&I){const P=this.objectVelocities.get(s.id)||{vx:0,vy:0};this.objectVelocities.set(s.id,{vx:_?0:P.vx,vy:E?0:P.vy})}}}else if(r.type==="Rotation"){const b=this.getGlobalTransform(r.targetId);if(b){let w=(b.rotation+(r.offset||0)-e.rotation)%360;w>180&&(w-=360),w<-180&&(w+=360),e.rotation=e.rotation+w*l}}else if(r.type==="Scale"){const b=this.getGlobalTransform(r.targetId);b&&(r.copyX&&(e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*l),r.copyY&&(e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*l))}else if(r.type==="Transform"){const b=this.getGlobalTransform(r.targetId);if(b){e.x=e.x+(b.x-e.x)*l,e.y=e.y+(b.y-e.y)*l;let S=(b.rotation-e.rotation)%360;S>180&&(S-=360),S<-180&&(S+=360),e.rotation=e.rotation+S*l,e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*l,e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*l}}else if(r.type==="FollowPointer"){const b=((m=this._lastPointerPos)==null?void 0:m.x)??e.x,S=((h=this._lastPointerPos)==null?void 0:h.y)??e.y,w=r.useSpring;if(w){const M=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:I,y:_,vx:E,vy:P}=this.computeSpring(e.x,e.y,M.vx,M.vy,b,S,r,t);e.x=I,e.y=_,this.objectVelocities.set(s.id,{vx:E,vy:P})}else e.x=e.x+(b-e.x)*l,e.y=e.y+(S-e.y)*l;let C=!1;if((f=r.limitX)!=null&&f.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((v=r.limitY)!=null&&v.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&&w&&this.objectVelocities.set(s.id,{vx:0,vy:0})}else if(r.type==="Distance"){const b=this.getGlobalTransform(r.targetId);if(b){const S=e.x-b.x,w=e.y-b.y,C=Math.sqrt(S*S+w*w),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.x===b.x&&e.y===b.y?1:I/C;e.x=e.x+(b.x+S*_-e.x)*l,e.y=e.y+(b.y+w*_-e.y)*l}}}else if(r.type==="FollowPath"){const b=(g=this.artboard)==null?void 0:g.objects.find(S=>S.id===r.targetId);if(b){const S=this.getGlobalTransform(b.id);if(S){let w=b.geometry;if(b.type==="Frame"||b.type==="Group"||!w||w.type!=="Path"&&w.type!=="Ellipse"&&w.type!=="Rectangle"){const Y=(c=this.artboard)==null?void 0:c.objects.find(ot=>ot.parentId===b.id&&ot.type==="Shape"&&ot.geometry&&(ot.geometry.type==="Path"||ot.geometry.type==="Ellipse"||ot.geometry.type==="Rectangle"));Y&&(w=Y.geometry)}if(!w)return;const C=Math.max(0,Math.min(1,(r.distance||0)/100)),M=S.width||w.width||0,I=S.height||w.height||0,_=this.getPointOnPath(w,M,I,C),E=S.rotation*Math.PI/180,P=Math.cos(E),L=Math.sin(E),k=_.x*S.scale_x*P-_.y*S.scale_y*L,A=_.x*S.scale_x*L+_.y*S.scale_y*P;let T=S.rotation+(r.offsetRotation||0);if(r.orient){const Y=Math.cos(_.angle),ot=Math.sin(_.angle),J=Y*S.scale_x*P-ot*S.scale_y*L,at=Y*S.scale_x*L+ot*S.scale_y*P;T=Math.atan2(at,J)*180/Math.PI+(r.offsetRotation||0)}const R=T*Math.PI/180,F=Math.cos(R),O=Math.sin(R),W=(r.offsetX||0)*F-(r.offsetY||0)*O,V=(r.offsetX||0)*O+(r.offsetY||0)*F,U=S.x+k+W,D=S.y+A+V;if(e.x=e.x+(U-e.x)*l,e.y=e.y+(D-e.y)*l,r.orient){let Y=(T-e.rotation)%360;Y>180&&(Y-=360),Y<-180&&(Y+=360),e.rotation=e.rotation+Y*l}}}}else if(r.type==="IK"){const b=this.getGlobalTransform(r.targetId);b&&this.solveIK(s,b,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(m=>m.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),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,u=(l*r+d*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 d=0;d<o&&i;d++){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 d=0;d<r;d++){const p=this.getGlobalTransform(t.id);for(let u=a.length-2;u>=0;u--){const m=a[u],h=this.getGlobalTransform(m.id),f=p.x-h.x,v=p.y-h.y,g=s.x-h.x,c=s.y-h.y,b=Math.sqrt(f*f+v*v),S=Math.sqrt(g*g+c*c);if(b>.001&&S>.001){const w=Math.atan2(v,f);let M=(Math.atan2(c,g)-w)*180/Math.PI;M*=e;const I=this.objectStates.get(m.id);I&&(I.rotation+=M)}}}}computeSpring(t,s,o,e,n,i,a,r){const l=a.stiffness??100,d=a.damping??10,p=a.mass??1,u=-l*(t-n),m=-l*(s-i),h=-d*o,f=-d*e,v=(u+h)/p,g=(m+f)/p,c=o+v*r,b=e+g*r,S=t+c*r,w=s+b*r;return{x:S,y:w,vx:c,vy:b}}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"}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),u=(o-p.tx)/p.scaleX,m=(e-p.ty)/p.scaleY;this._lastPointerPos={x:u,y:m}}if(this._lastPointerPos&&this.artboard){let p=!1;for(let u=this.artboard.objects.length-1;u>=0;u--){const m=this.artboard.objects[u];if(this.isListViewObject(m)){const h=this.objectStates.get(m.id),f=(h==null?void 0:h.options)||m.options||{},v=(h==null?void 0:h.width)??(((a=m.geometry)==null?void 0:a.width)||200),g=(h==null?void 0:h.height)??(((r=m.geometry)==null?void 0:r.height)||300),c=this.getWorldTransform(m.id),b=this._lastPointerPos.x-c.x,S=this._lastPointerPos.y-c.y,w=-c.rotation*(Math.PI/180),C=Math.cos(w),M=Math.sin(w),I=b*C-S*M,_=b*M+S*C,E=c.scaleX||1,P=c.scaleY||1,L=v*Math.abs(E),k=g*Math.abs(P);if(Math.abs(I)<=L/2&&Math.abs(_)<=k/2){const A=f.orientation||"vertical";let T=f.scrollOffset||0;if(A==="vertical"?T-=s:T-=Math.abs(t)>Math.abs(s)?t:s,(f.listLayout||"linear")==="circular")f.scrollOffset=T,h&&h.options&&(h.options.scrollOffset=T),m.options&&(m.options.scrollOffset=T);else{const F=this.getResolvedListViewItems(m,f),O=f.itemGap??10,W=f.itemHeight??50,V=f.itemWidth??200,U=typeof f.padding=="number"?f.padding:A==="vertical"?((l=f.padding)==null?void 0:l[0])||0:((d=f.padding)==null?void 0:d[3])||0,Y=(F.length||0)*(A==="vertical"?W:V)+Math.max(0,(F.length||0)-1)*O+U*2,J=Math.max(0,Y-(A==="vertical"?g:v));T>0&&(T=0),T<-J&&(T=-J),f.scrollOffset=T,h&&h.options&&(h.options.scrollOffset=T),m.options&&(m.options.scrollOffset=T)}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,u,m,h,f,v,g;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,b)=>{var _;let S=b;b==="click"?S="onClick":b==="down"?S="onPointerDown":b==="up"?S="onPointerUp":b==="blur"&&(S="onPointerLeave");const w=new Set([S]);b==="move"&&(w.add("onPointerEnter").add("hover").add("onPointerLeave").add("blur"),w.add("Drag").add("drag").add("ondrag")),S==="onClick"&&w.add("click"),S==="onPointerDown"&&w.add("pointerDown"),S==="onPointerUp"&&w.add("pointerUp");const C=["button","toggle","toggle_button","dropdown","listview","inputbox","slider","checkbox","radiogroup","joystick"];if(this.isListViewObject(c)||c.type==="Component"&&c.variant&&C.includes(String(c.variant).toLowerCase())||c.type==="Joystick"||C.includes((_=c.type)==null?void 0:_.toLowerCase()))return!0;const M=c.interactions||[];return!!(M.some(E=>w.has(E.event))||M.some(E=>Array.isArray(E.triggers)&&E.triggers.some(P=>w.has(String(P))))||(c.triggers||[]).some(E=>w.has(E.eventType)))};let i=null;for(let c=this.artboard.objects.length-1;c>=0;c--){const b=this.artboard.objects[c],S=this.objectStates.get(b.id);if(S&&S.visible!==!1&&S.opacity>0&&this.hitTest(b,s,o)&&(i||(i=b),n(b,t))){e=b;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(b=>b.id===this.draggingSliderId);c&&this.updateSliderValueFromPointer(c,s,o);return}if(this.draggingJoystickId){const c=this.artboard.objects.find(b=>b.id===this.draggingJoystickId);c&&this.updateJoystickValueFromPointer(c,s,o);return}if(this.draggingListViewId){const c=this.artboard.objects.find(b=>b.id===this.draggingListViewId);c&&this.updateListViewScrollFromPointer(c);return}if(e&&this.isListViewObject(e)&&this.updateListViewHoverFromPointer(e,s,o),this.isMouseDown&&this.dragStartPointer&&this.draggingBehaviors.size>0){const c=s-this.dragStartPointer.x,b=o-this.dragStartPointer.y;this.draggingBehaviors.forEach(S=>{const w=this.dragStartPositions.get(S);if(!w)return;const C=this.artboard.objects.find(I=>I.id===S);if(!C||C.parentId)return;const M=this.objectStates.get(S);M&&(M.x=w.x+c,M.y=w.y+b)})}if(this.isMouseDown){const c=this.activeObjectId&&this.artboard.objects.some(S=>S.id===this.activeObjectId)?this.activeObjectId:a,b=c?this.artboard.objects.find(S=>S.id===c):null;b&&n(b,"move")&&this.fireEventForObject(b.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==="down"&&(this.pointerDownTimes.set(a,this.currentTime),this.activeObjectId=a,e&&((r=e.behaviors)!=null&&r.some(c=>c.type===tt.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(b=>b.id===this.activeDropdownId);if(c&&(c.type==="Dropdown"||c.variant==="dropdown")){const b=this.objectStates.get(c.id),S=(b==null?void 0:b.options)||c.options||{},w=c.geometry||{},C=w.width??c.width??200,M=w.height??c.height??40,I=this.getResolvedDropdownOptions(c,S),_=S.itemHeight||32,E=S.listPadding??4,P=I.length*_+E*2,L=this.getWorldTransform(c.id),k=C*Math.abs(L.scaleX),A=M*Math.abs(L.scaleY),T=L.y+A/2+4,R=Math.abs(s-L.x)<=k/2,F=o>=T&&o<=T+P*Math.abs(L.scaleY);if(R&&F){const O=Math.abs(L.scaleY),W=o-(T+E*O),V=Math.floor(W/(_*O));if(V>=0&&V<I.length){const U=I[V];S.selectedOption=U,S.isOpen=!1,this.activeDropdownId=null,c.inputId&&this.setInternalInput(c.inputId,U),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"dropdown",property:"selectedOption",value:U})}return}else a!==this.activeDropdownId&&(S.isOpen=!1,this.activeDropdownId=null)}}if(e){let c=e,b=e;for(;b&&b.parentId;){const C=this.artboard.objects.find(M=>M.id===b.parentId);if(C&&C.type==="Component"){c=C;break}b=C}let S=t;if(t==="click"?S="onClick":t==="down"?S="onPointerDown":t==="up"?S="onPointerUp":t==="blur"&&(S="onPointerLeave"),this.fireEventForObject(e.id,S),c!==e&&this.fireEventForObject(c.id,S),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 _=this.artboard.objects.find(E=>E.id===this.activeDropdownId);_&&_.options&&(_.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),_=(C==null?void 0:C.height)??(((d=c.geometry)==null?void 0:d.height)||300),E=M.orientation||"vertical",P=M.scrollbarWidth||4,L=M.showScrollbar!==!1;let k=!1;if(L&&M.listLayout!=="circular"){const T=this.getWorldTransform(c.id),R=-T.rotation*(Math.PI/180),F=Math.cos(R),O=Math.sin(R),W=s-T.x,V=o-T.y,U=W*F-V*O,D=W*O+V*F,Y=T.scaleX||1,ot=T.scaleY||1,J=U/Y,at=D/ot,j=12;E==="vertical"?J>=I/2-P-j&&J<=I/2+j&&(k=!0):at>=_/2-P-j&&at<=_/2+j&&(k=!0)}this.draggingListViewIsScrollbar=k;const A=this.getListViewItemIndexAtPointer(c,s,o);if(A!==null){const T=c.options||{};T.activeItemIndex=A;const R=this.objectStates.get(c.id);R&&R.options&&(R.options.activeItemIndex=A);const O=this.getResolvedListViewItems(c,T)[A],W=typeof O=="string"?O:(O==null?void 0:O.label)||(O==null?void 0:O.value)||A;R&&R.options&&(R.options.selectedValue=W),c.inputId&&this.setInternalInput(c.inputId,W),this.onComponentChange&&(this.onComponentChange({objectId:c.id,componentName:c.name,variant:"listview",property:"activeItemIndex",value:A}),this.onComponentChange({objectId:c.id,componentName:c.name,variant:"listview",property:"selected",value:W}))}}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==="Component"&&c.variant==="checkbox"&&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:"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||[],_=this.getRadioGroupItemIndexAtPointer(c,s,o);if(_!==null&&_>=0&&_<I.length){const E=I[_];M.selectedValue=E,c.inputId&&this.setInternalInput(c.inputId,E),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"radiogroup",property:"selectedValue",value:E}),this.fireEventForObject(c.id,"Click"),this.fireEventForObject(c.id,`Selected: ${E}`)}}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),_=(I==null?void 0:I.width)||(C==null?void 0:C.width)||200,E=(I==null?void 0:I.height)||(C==null?void 0:C.height)||150,P=this.getWorldTransform(c.id),L=30,k=20,A=_-L,T=E-k;let R=1;M.forEach(W=>{const V=Math.max(...W.data||[0]);V>R&&(R=V)});let F=1/0,O=null;M.forEach((W,V)=>{const U=W.data||[],D=A/Math.max(U.length-1,1);U.forEach((Y,ot)=>{const J=P.x-_/2+L+ot*D,at=P.y+E/2-k-Y/R*T,j=Math.sqrt((s-J)**2+(o-at)**2);j<F&&(F=j,O={dIdx:V,pIdx:ot,val:Y,label:W.label||`Dataset ${V+1}`})})}),O&&F<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:c.id,componentName:c.name,datasetIndex:O.dIdx,pointIndex:O.pIdx,value:O.val,label:O.label}),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"linegraph",property:"click",value:(O==null?void 0:O.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 ot=(p=this.artboard)==null?void 0:p.objects.find(J=>J.id===C);ot&&this.onInputBlur&&this.onInputBlur(ot.name)}this.onInputFocus&&this.onInputFocus(c.name)}const M=this.objectStates.get(c.id),I=(M==null?void 0:M.options)||c.options||{},_=c.geometry||{},E=(M==null?void 0:M.width)||(_==null?void 0:_.width)||250,P=(M==null?void 0:M.height)||(_==null?void 0:_.height)||45,L=this.getWorldTransform(c.id),k=-L.rotation*(Math.PI/180),A=Math.cos(k),T=Math.sin(k),R=s-L.x,F=o-L.y,O=(R*A-F*T)/(L.scaleX||1),W=(R*T+F*A)/(L.scaleY||1);if(I.inputType==="number"&&((u=I.number)==null?void 0:u.showSteppers)!==!1){const J=E/2-4,at=J-24;if(O>=at&&O<=J&&Math.abs(W)<=P/2){const j=Number(((m=I.number)==null?void 0:m.step)??1),it=((h=I.number)==null?void 0:h.min)!==void 0?Number(I.number.min):-1/0,B=((f=I.number)==null?void 0:f.max)!==void 0?Number(I.number.max):1/0;let X=parseFloat(I.text??I.value??"0");isNaN(X)&&(X=0),W<0?X=Math.min(B,X+j):X=Math.max(it,X-j);const N=String(X);I.text=N,I.value=N,c.options&&(c.options.text=N,c.options.value=N),M&&M.options&&(M.options.text=N,M.options.value=N),this.onComponentChange&&this.onComponentChange({objectId:c.id,componentName:c.name,variant:"inputbox",property:"value",value:N}),this.onInputChange&&this.onInputChange(c.name,N),this.onInputUpdate&&this.onInputUpdate(c.id,N);return}}const V=I.rightIcon||{},U=I.inputType==="password",D=V.mode==="clear"||I.inputType==="search"&&(I.text||I.value),Y=V.mode==="password-toggle"||U&&V.visible!==!1;if(V.visible||Y||D){const ot=V.offset??16,J=V.size??16,at=E/2-ot;if(Math.abs(O-at)<=J&&Math.abs(W)<=P/2){if(Y){I.passwordVisible=!I.passwordVisible,M&&M.options&&(M.options.passwordVisible=I.passwordVisible),c.options&&(c.options.passwordVisible=I.passwordVisible);return}else if(D){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=(v=this.artboard)==null?void 0:v.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 b=(g=this.artboard)==null?void 0:g.objects.find(S=>S.id===c);b&&this.onInputBlur&&this.onInputBlur(b.name)}}}handleKeyDown(t){var l,d,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(m=>m.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 m=Number(((l=n.number)==null?void 0:l.step)??1),h=((d=n.number)==null?void 0:d.max)!==void 0?Number(n.number.max):1/0;let f=parseFloat(i)||0;f=Math.min(h,f+m),i=String(f),t.preventDefault()}else if(t.key==="ArrowDown"&&n.inputType==="number"){const m=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 f=parseFloat(i)||0;f=Math.max(h,f-m),i=String(f),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,u,m,h;const o=(d=this.artboard)==null?void 0:d.objects.find(f=>f.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(f=>{const v=f.triggers||[f.event||f.trigger||"click"];return((f.triggerLogic||"OR")==="AND"?v.every(b=>e.has(b.toLowerCase())):v.some(b=>e.has(b.toLowerCase())))?f.conditions&&f.conditions.length>0?this.checkConditions(f.conditions):!0:!1});if(a){if(this.log(`[Engine] Interaction matched: ${s} -> Action: ${a.action}`),a.action==="setInput"||a.action==="Set Input"){let f=a.value||a.inputValue;f==="toggle"&&(f=!this.inputs.get(a.targetInputId)),this.updateInput(a.targetInputId,f)}else if(a.action==="Toggle Boolean"){const f=this.inputs.get(a.targetInputId);this.updateInput(a.targetInputId,!f)}else if(a.action==="fireTrigger")this.updateInput(a.targetInputId,!0);else if(a.action==="setProperty"){const f=a.targetObjectId||o.id,v=a.targetProperty;v&&this.updateObjectProperty(f,v,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 f=a.targetAnimationId,v=!a.playMode||a.playMode==="all"?void 0:a.subAnimationIds;f==="__all__"?(u=(p=this.artboard)==null?void 0:p.animations)==null||u.forEach(g=>{this.triggerGlobalAnimation(g.id,v)}):f&&this.triggerGlobalAnimation(f,v)}else if(a.action==="setState"||a.action==="Set State"){const f=a.targetObjectId||o.id,g={...this.objectStates.get(f)||{},...a.value||{}};this.objectStates.set(f,g),this.log(`[Engine] State updated for ${f}:`,g)}else if(a.action==="Stop Animation"||a.action==="Pause Animation"){const f=a.targetAnimationId;f==="__all__"?this.layerStates.forEach((v,g)=>{g.startsWith("global_")&&this.layerStates.delete(g)}):f&&this.layerStates.forEach((v,g)=>{g.startsWith(`global_${f}_`)&&this.layerStates.delete(g)})}else if(a.action==="Switch to State"&&this.activeStateMachine){const f=a.targetState,v=this.activeStateMachine.layers.find(g=>g.states.some(c=>c.id===f||c.name===f));v&&(this.log(`[Engine] Switching Layer ${v.name} to State ${f}`),this.enterStates(v.name,[f]))}this.onTrigger&&this.onTrigger(s,a.action)}const l=(o.triggers||[]).find(f=>{const v=f.eventType.toLowerCase();let g=!1;return(e.has(v)||v==="click"&&e.has("onclick")||v==="hover"&&(e.has("onpointerenter")||e.has("hover"))||v==="pointerdown"&&e.has("onpointerdown")||v==="pointerup"&&e.has("onpointerup"))&&(g=!0),g&&f.conditions&&f.conditions.length>0?this.checkConditions(f.conditions):g});if(l&&l.entryAnimationId){this.log(`[Engine] Trigger matched: ${s} (as ${l.eventType}) -> Animation ${l.entryAnimationId}`);const f=(h=(m=this.artboard)==null?void 0:m.animations)==null?void 0:h.find(v=>v.id===l.entryAnimationId);f&&(this.activeTriggers.set(o.id,{triggerId:l.id,animation:f,time:0,phase:"entry",elapsedHold:0,filterObjectId:l.targetObjectId}),this.onTrigger&&this.onTrigger(l.name,f.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)}}})}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(m=>m.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 b,S;if(!this.objectStates.get(t.id))return!1;const n=((b=t.geometry)==null?void 0:b.width)??t.width??100,i=((S=t.geometry)==null?void 0:S.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),u=Math.sin(d),m=r*p-l*u,h=r*u+l*p,f=a.scaleX,v=a.scaleY,g=n*Math.abs(f),c=i*Math.abs(v);return Math.abs(m)<=g/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,d=-a.rotation*(Math.PI/180),p=Math.cos(d),u=Math.sin(d),m=r*p-l*u,h=n.thumbWidth??16,f=i-h;let g=(m+f/2)/f;g=Math.max(0,Math.min(1,g));const c=n.min??0,b=n.max??100,S=n.step||1;let w=c+g*(b-c);S>0&&(w=Math.round(w/S)*S),w=Math.max(c,Math.min(b,w));const C=e.options||{};C.value!==w&&(e.options={...C,value:w},t.inputId&&this.setInternalInput(t.inputId,w),this.onComponentChange&&this.onComponentChange({objectId:t.id,componentName:t.name,variant:"slider",property:"value",value:w}))}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,d=-a.rotation*(Math.PI/180),p=Math.cos(d),u=Math.sin(d);let m=(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"?(m-=n/2,h-=i/2):t.handleOrigin==="bottom-right"&&(m+=n/2,h+=i/2);const f=Math.min(n,i)*.45,v=Math.min(n,i)*.15,g=f-v;let c=m/g,b=h/g;const S=Math.sqrt(c*c+b*b);t.boundsShape==="square"?(c=Math.max(-1,Math.min(1,c)),b=Math.max(-1,Math.min(1,b))):S>1&&(c/=S,b/=S),t.deadzone!==void 0&&S<t.deadzone?(c=0,b=0):(t.stepX!==void 0&&t.stepX>0&&(c=Math.round(c/t.stepX)*t.stepX),t.stepY!==void 0&&t.stepY>0&&(b=Math.round(b/t.stepY)*t.stepY)),t.joystickType==="1D_X"?b=0:t.joystickType==="1D_Y"&&(c=0);const w=e.handleX,C=e.handleY;(w!==c||C!==b)&&(e.handleX=c,e.handleY=b,t.handleX=c,t.handleY=b)}processJoysticks(t){this.artboard&&(this.artboard.objects.forEach(s=>{var l,d,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 m=o.inputBinding.keyboardConfig;let h=n,f=i;const g=(m.speed||5)*t;let c=!1;this.activeKeys.has(m.upKey.toLowerCase())&&(f-=g,c=!0),this.activeKeys.has(m.downKey.toLowerCase())&&(f+=g,c=!0),this.activeKeys.has(m.leftKey.toLowerCase())&&(h-=g,c=!0),this.activeKeys.has(m.rightKey.toLowerCase())&&(h+=g,c=!0),o.joystickType==="1D_X"&&(f=0),o.joystickType==="1D_Y"&&(h=0);const b=Math.sqrt(h*h+f*f);b>1&&(h/=b,f/=b),!c&&o.isSpringReturn!==!1&&(h+=(0-h)*(10*t),f+=(0-f)*(10*t),Math.abs(h)<.01&&(h=0),Math.abs(f)<.01&&(f=0)),n=h,i=f}else if(r&&((d=o.inputBinding)==null?void 0:d.type)==="mouse"&&o.inputBinding.mouseConfig){const m=o.inputBinding.mouseConfig;let h=e._mouseTargetX??n,f=e._mouseTargetY??i;const v=m.sensitivity||.01;if(m.mode==="absolute"){const b=((p=this.artboard)==null?void 0:p.width)||window.innerWidth,S=((u=this.artboard)==null?void 0:u.height)||window.innerHeight,w=this.inputs.get("mouseX")||0,C=this.inputs.get("mouseY")||0;m.axisX&&(h=w/b*2-1),m.axisY&&(f=C/S*2-1)}else m.axisX&&(h+=this._mouseDelta.dx*v),m.axisY&&(f+=this._mouseDelta.dy*v);o.joystickType==="1D_X"&&(f=0),o.joystickType==="1D_Y"&&(h=0);const g=Math.sqrt(h*h+f*f);g>1&&(h/=g,f/=g),o.isSpringReturn!==!1&&(h+=(0-h)*(5*t),f+=(0-f)*(5*t),Math.abs(h)<.01&&(h=0),Math.abs(f)<.01&&(f=0)),e._mouseTargetX=h,e._mouseTargetY=f;const c=15*t;n+=(h-n)*Math.min(c,1),i+=(f-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 m=Math.sqrt(n*n+i*i);let h=Math.atan2(i,n)*(180/Math.PI);h<0&&(h+=360),o.bindings.forEach(f=>{var c,b,S,w,C,M,I,_;let v=0;f.sourceAxis==="x"?v=o.invertX?-n:n:f.sourceAxis==="y"?v=o.invertY?-i:i:f.sourceAxis==="distance"?v=m:f.sourceAxis==="angle"&&(v=h);const g=(c=this.artboard)==null?void 0:c.objects.find(E=>E.id===f.targetObjectId);if(g){if(f.actionType==="bind"&&f.targetProperty&&f.isContinuous!==!1){const E=f.sourceMin??-1,P=f.sourceMax??1,L=f.targetMin??0,k=f.targetMax??100;let A=!!f.isContinuous,T=0,R=0;if(A){if((f.sourceAxis==="x"||f.sourceAxis==="y")&&L>=0){const O=Math.max(Math.abs(E),Math.abs(P))||1;R=v/O*k}else{let O=(v-E)/(P-E);O=Math.max(0,Math.min(1,O)),R=L+O*(k-L)}Math.abs(v)<.05&&(R=0)}else{const O=(v-E)/(P-E),W=Math.max(0,Math.min(1,O));T=L+W*(k-L),f.step&&f.step>0&&(T=Math.round(T/f.step)*f.step)}const F=this.objectStates.get(g.id);if(F){const O=f.isRelative!==!1,W=O?((b=g.transform)==null?void 0:b.x)??0:0,V=O?((S=g.transform)==null?void 0:S.y)??0:0,U=O?((w=g.transform)==null?void 0:w.rotation)??0:0,D=O?((C=g.transform)==null?void 0:C.scale_x)??1:0,Y=O?((M=g.transform)==null?void 0:M.scale_y)??1:0,ot=O?((I=g.style)==null?void 0:I.opacity)??100:0,J=Math.min(t*60,3),at=(j,it)=>{let B=T;if(A){const X=`_internal_${j}_${f.id}`;let N=F[X];N===void 0&&(N=F[j]??it),B=N+R*J,F[X]=B,f.step&&f.step>0&&(B=Math.round(B/f.step)*f.step)}else{B=it+T;const X=`_internal_smooth_${j}_${f.id}`;let N=F[X];if(N===void 0)N=B;else{const ct=Math.min(15*t,1);N+=(B-N)*ct}F[X]=N,B=N}F[j]=B};f.targetProperty==="x"||f.targetProperty==="transform.x"?at("x",W):f.targetProperty==="y"||f.targetProperty==="transform.y"?at("y",V):f.targetProperty==="rotation"||f.targetProperty==="r"||f.targetProperty==="transform.rotation"?at("rotation",U):f.targetProperty==="scaleX"||f.targetProperty==="transform.scale_x"?at("scale_x",D):f.targetProperty==="scaleY"||f.targetProperty==="transform.scale_y"?at("scale_y",Y):(f.targetProperty==="opacity"||f.targetProperty==="transform.opacity")&&at("opacity",ot)}(_=g.physics)!=null&&_.enabled&&this.physicsEngine&&(f.targetProperty==="x"||f.targetProperty==="transform.x"||f.targetProperty==="y"||f.targetProperty==="transform.y")&&(f.targetProperty==="x"||f.targetProperty==="transform.x"?this.physicsEngine.applyForce(g.id,(T-((F==null?void 0:F.x)||0))*10,0):(f.targetProperty==="y"||f.targetProperty==="transform.y")&&this.physicsEngine.applyForce(g.id,0,(T-((F==null?void 0:F.y)||0))*10))}else if(f.actionType==="playAnimation"||f.actionType==="stopAnimation"||f.actionType==="pauseAnimation"){let E=!1;const P=f.threshold??0;f.condition==="always"?E=!0:f.condition===">"?E=v>P:f.condition==="<"?E=v<P:f.condition==="=="&&(E=Math.abs(v-P)<.01);const L=e[`_prev_src_${f.id}`]??v;let k=!1;f.condition==="always"?k=!0:f.condition===">"?k=L>P:f.condition==="<"?k=L<P:f.condition==="=="&&(k=Math.abs(L-P)<.01),e[`_prev_src_${f.id}`]=v,E&&!k&&f.targetAnimationId&&(f.actionType==="playAnimation"||f.actionType)}}})}}),this._mouseDelta.dx=0,this._mouseDelta.dy=0)}applyBlendState(t,s){var l,d,p,u,m,h,f,v;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 g=[...t.blendAnimations].sort((c,b)=>c.position[0]-b.position[0]);if(g.length===1){const c=(d=(l=this.artboard)==null?void 0:l.animations)==null?void 0:d.find(b=>b.id===g[0].animationId);c&&(n.push({anim:c,weight:1}),i=1)}else{let c=0;for(;c<g.length-1&&g[c+1].position[0]<o;)c++;if(c===g.length-1&&o>g[c].position[0]){const b=(u=(p=this.artboard)==null?void 0:p.animations)==null?void 0:u.find(S=>S.id===g[c].animationId);b&&(n.push({anim:b,weight:1}),i=1)}else{const b=g[c].position[0],S=g[c+1].position[0],w=(h=(m=this.artboard)==null?void 0:m.animations)==null?void 0:h.find(E=>E.id===g[c].animationId),C=(v=(f=this.artboard)==null?void 0:f.animations)==null?void 0:v.find(E=>E.id===g[c+1].animationId),M=Math.max(.001,S-b);let I=(o-b)/M;I=Math.max(0,Math.min(1,I));const _=1-I;w&&(n.push({anim:w,weight:_}),i+=_),C&&(n.push({anim:C,weight:I}),i+=I)}}}else t.blendAnimations.forEach(g=>{var C,M;const c=(M=(C=this.artboard)==null?void 0:C.animations)==null?void 0:M.find(I=>I.id===g.animationId);if(!c)return;const b=g.position[0]-o,S=g.position[1]-e,w=b*b+S*S;if(w<1e-4)n.push({anim:c,weight:1e4}),i+=1e4;else{const I=1/w;n.push({anim:c,weight:I}),i+=I}});if(i===0)return;n.forEach(g=>g.weight/=i);const a=new Map,r=g=>{let c=g.startsWith("#")?g.substring(1):g;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:g,weight:c})=>{g.tracks&&g.tracks.forEach(b=>{var P,L;const S=b.object_id||b.objectId,w=b.property,C=(P=this.artboard)==null?void 0:P.objects.find(k=>k.id===S);if(((L=C==null?void 0:C.physics)==null?void 0:L.enabled)&&C.physics.bodyType!=="Static"&&(w==="x"||w==="y"||w==="rotation"))return;const I=this.interpolate(b.keyframes,s);if(I===void 0)return;let _=a.get(S);_||(_=new Map,a.set(S,_));let E=_.get(w);if(!E){if(typeof I=="number")E={type:"number",value:0};else if(typeof I=="string"&&I.startsWith("#"))E={type:"color",value:I,colorAcc:{r:0,g:0,b:0,a:0}};else if(E={type:"number",value:I},c<.5)return;_.set(w,E)}if(E.type==="number"&&typeof I=="number")E.value+=I*c;else if(E.type==="color"&&typeof I=="string"&&E.colorAcc){const k=r(I);k&&(E.colorAcc.r+=k.r*c,E.colorAcc.g+=k.g*c,E.colorAcc.b+=k.b*c,E.colorAcc.a+=k.a*c)}else c>.5&&(E.value=I)})}),a.forEach((g,c)=>{var w;const b=this.objectStates.get(c),S=(w=this.artboard)==null?void 0:w.objects.find(C=>C.id===c);!b||!S||g.forEach((C,M)=>{let I=C.value;if(C.type==="color"&&C.colorAcc){const _=Math.round(C.colorAcc.r).toString(16).padStart(2,"0"),E=Math.round(C.colorAcc.g).toString(16).padStart(2,"0"),P=Math.round(C.colorAcc.b).toString(16).padStart(2,"0");I=`#${_}${E}${P}`}if(M.includes(".")||M.includes("[")){const _=(M||"").replace(/\[(\d+)\]/g,".$1").split(".");let E=b;for(let P=0;P<_.length-1;P++){if(typeof E[_[P]]!="object"||E[_[P]]===null){let L=S;for(let k=0;k<=P;k++)L=L?L[_[k]]:null;if(_[P]==="corner_radius"||_[P]==="cornerRadius"){const k=typeof E[_[P]]=="number"?E[_[P]]:typeof L=="number"?L:0;E[_[P]]={tl:k,tr:k,bl:k,br:k}}else{const k=_[P+1],A=!isNaN(Number(k));E[_[P]]=L?JSON.parse(JSON.stringify(L)):A?[]:{}}}E=E[_[P]]}E[_[_.length-1]]=I,_[_.length-1]==="color"&&(_[_.length-2]==="fill"||_[_.length-2]==="stroke")&&(E.type="Solid")}else M==="fill"?(b.style||(b.style={}),b.style.fill=I):M==="stroke"?(b.style||(b.style={}),b.style.stroke=I):b[M]=I})})}applyAnimation(t,s,o){!t||!t.tracks||t.tracks.forEach(e=>{var p,u,m;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 d=this.interpolate(e.keyframes,s);if(d!==void 0){if(this.frameCount%240===0){const h=(i==null?void 0:i.name)||n,f=typeof d=="object"?JSON.stringify(d).slice(0,50):d;this.debugLog(`[Anim] Applying ${r} = ${f} to ${h}`)}if(r.includes(".")||r.includes("[")){const h=(r||"").replace(/\[(\d+)\]/g,".$1").split(".");let f=l;for(let v=0;v<h.length-1;v++){if(typeof f[h[v]]!="object"||f[h[v]]===null){let g=i;for(let c=0;c<=v;c++)g=g?g[h[c]]:null;if(h[v]==="corner_radius"||h[v]==="cornerRadius"){let c=0,b=0,S=0,w=0;const C=f[h[v]]??g;typeof C=="number"?c=b=S=w=C:Array.isArray(C)?C.length===1?c=b=S=w=C[0]:C.length===2?(c=S=C[0],b=w=C[1]):C.length===3?(c=C[0],b=w=C[1],S=C[2]):C.length>=4&&(c=C[0],b=C[1],S=C[2],w=C[3]):C&&typeof C=="object"&&(c=C[0]??C.tl??C.corner_radius??C.cornerRadius??0,b=C[1]??C.tr??C.corner_radius??C.cornerRadius??0,S=C[2]??C.br??C.corner_radius??C.cornerRadius??0,w=C[3]??C.bl??C.corner_radius??C.cornerRadius??0),f[h[v]]={tl:c,tr:b,bl:w,br:S,0:c,1:b,2:S,3:w}}else{const c=h[v+1],b=!isNaN(Number(c));f[h[v]]=g?JSON.parse(JSON.stringify(g)):b?[]:{}}}f=f[h[v]]}f[h[h.length-1]]=d,h[h.length-1]==="color"&&(h[h.length-2]==="fill"||h[h.length-2]==="stroke")&&(f.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&&((m=i==null?void 0:i.physics)!=null&&m.enabled)&&i.physics.bodyType==="Static")if(r==="x"){const h=this.physicsEngine.getPosition(n);h&&this.physicsEngine.setPosition(n,d,h.y)}else if(r==="y"){const h=this.physicsEngine.getPosition(n);h&&this.physicsEngine.setPosition(n,h.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=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,f;const e=((f=(h=this.artboard)==null?void 0:h.tokens)==null?void 0:f.colors)||{},n=e[t]||t,i=e[s]||s,a=v=>{if(!v)return{r:0,g:0,b:0};const g=v.startsWith("#")?v.replace("#",""):"000000";return g.length===3?{r:parseInt(g[0]+g[0],16),g:parseInt(g[1]+g[1],16),b:parseInt(g[2]+g[2],16)}:{r:parseInt(g.substring(0,2),16),g:parseInt(g.substring(2,4),16),b:parseInt(g.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),u=Math.round(r.b+(l.b-r.b)*o),m=v=>{const g=Math.max(0,Math.min(255,v)).toString(16);return g.length===1?"0"+g:g};return`#${m(d)}${m(p)}${m(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 m=this.imageCache.get(u);if(m||(m=new Image,m.src=u,this.imageCache.set(u,m)),m.complete&&m.naturalWidth>0){t.save(),t.globalAlpha=this.normalizeOpacity(this.artboard.backgroundOpacity??100);const h=m.naturalWidth/m.naturalHeight,f=n/i;let v,g,c,b;f>h?(v=n,g=n/h):(g=i,v=i*h),c=(n-v)/2,b=(i-g)/2,t.drawImage(m,c,b,v,g),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,m)=>{const h=this.objectStates.get(u.id),f=(h==null?void 0:h.zIndex)??m;return{obj:u,zIndex:f}}).sort((u,m)=>u.zIndex-m.zIndex).forEach(({obj:u})=>{this.renderObject(t,u,l)}),this._emitterPools.forEach((u,m)=>{if(!(u.length===0||!l.get(m)))for(const f of u)t.save(),t.globalAlpha=f.opacity,t.fillStyle=f.color,t.beginPath(),t.arc(f.x,f.y,Math.max(1,f.size*f.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),u=(e/2+i)*d,m=(n/2+i)*p;return r+u>=0&&r-u<=this.canvasWidth&&l+m>=0&&l-m<=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 u=o*a,m=e*r;let h=0,f=0;return i.includes("Left")?h=0:i.includes("Right")?h=t-u:h=(t-u)/2,i.includes("Top")?f=0:i.includes("Bottom")?f=s-m:f=(s-m)/2,{scaleX:a,scaleY:r,tx:h,ty:f}}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 b,S,w,C,M,I,_,E,P,L,k,A,T,R,F,O,W,V,U,D,Y,ot,J,at,j,it,B,X,N,ct,Mt,bt,wt,gt,It;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=(ut,Lt,Wt,q,ft)=>(this.drawRoundRect(t,ut,Lt,Wt,q,ft),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)||((b=s.geometry)==null?void 0:b.width)||s.width||0,d=(a==null?void 0:a.height)||((S=s.geometry)==null?void 0:S.height)||s.height||0;if((l===0||d===0)&&(a!=null&&a.points)&&Array.isArray(a.points)&&a.points.length>0){let ut=1/0,Lt=-1/0,Wt=1/0,q=-1/0;a.points.forEach(ft=>{ut=Math.min(ut,ft.x),Lt=Math.max(Lt,ft.x),Wt=Math.min(Wt,ft.y),q=Math.max(q,ft.y)}),l===0&&(l=Lt-ut),d===0&&(d=q-Wt)}const p=ut=>{if(ut)return ut.corner_radius??ut.cornerRadius},u=p(a)??p(i)??p(r)??p(s.geometry)??p(s.style)??p(s)??0;let m={...a,width:l,height:d};if(delete m.cornerRadius,m.corner_radius=u,!m.type&&(s.type==="Frame"||s.type==="Component"||s.type==="Group")&&(m.type="Rectangle"),s.type==="Text"&&(m.type="Text"),m.type==="Path"&&s.weights&&s.bindMatrices&&m.points){const ut=this.getGlobalTransform(s.id);if(ut){const Lt=si(m.points,s.weights,s.bindMatrices,ut,Wt=>this.getGlobalTransform(Wt));m={...m,points:Lt}}}if(i.visible===!1)return;const f=(r.effects||((w=s.style)==null?void 0:w.effects)||[]).find(ut=>ut.isEnabled!==!1&&ut.type==="PathDistortion");if(f){const ut=ni(m,l,d,f.amplitude||5,f.frequency||10,f.seed||0,f.direction||0,f.directionStrength||0);m={...m,type:"Path",points:ut}}const v=s.repeaterConfig,g=v&&v.isEnabled&&v.count>1,c=g?v.count:1;for(let ut=0;ut<c;ut++){let Lt=i.x!==void 0?i.x:((C=i.transform)==null?void 0:C.x)??0,Wt=i.y!==void 0?i.y:((M=i.transform)==null?void 0:M.y)??0,q=i.rotation!==void 0?i.rotation:((I=i.transform)==null?void 0:I.rotation)??0,ft=i.scale_x!==void 0?i.scale_x:((_=i.transform)==null?void 0:_.scale_x)??1,Bt=i.scale_y!==void 0?i.scale_y:((E=i.transform)==null?void 0:E.scale_y)??1;if(g&&ut>0){if(v.type==="Linear"){const z=v.offsetX||0,K=v.offsetY||0,G=v.rotation||0,x=v.scale!==void 0?v.scale:1;Lt+=ut*z,Wt+=ut*K,q+=ut*G,ft*=Math.pow(x,ut),Bt*=Math.pow(x,ut)}else if(v.type==="Grid"){const z=v.cols||Math.ceil(Math.sqrt(v.count)),K=v.gapX||0,G=v.gapY||0,x=Math.floor(ut/z),Q=ut%z,H=l+K,lt=d+G;Lt+=Q*H,Wt+=x*lt}else if(v.type==="Radial"){const z=v.radius||100,K=v.startAngle||0,x=(v.endAngle||360)-K,Q=v.count>1?x/(x===360?v.count:v.count-1):0,H=K+ut*Q,lt=H*Math.PI/180;Lt=i.x+z*Math.cos(lt),Wt=i.y+z*Math.sin(lt),q+=H}}const Ot=s.type==="Group"||s.type==="Frame"||s.type==="Component",Pt=l>0&&d>0;if(!Ot&&Pt&&!e){const z=(((P=r.shadow)==null?void 0:P.isEnabled)!==!1?(((L=r.shadow)==null?void 0:L.blur)||0)+10:0)+(((k=r.blur)==null?void 0:k.isEnabled)!==!1&&((A=r.blur)==null?void 0:A.radius)||0)+20;if(!this.isObjectInView(t,Lt,Wt,l,d,z))continue}this.debug_objectsRendered++,t.save();const vt=[],Yt=r.blur||((T=s.style)==null?void 0:T.blur);Yt&&Yt.amount>0&&vt.push(`blur(${Yt.amount}px)`);const zt=r.effects||((R=s.style)==null?void 0:R.effects)||[];let Gt=zt.find(z=>z.isEnabled!==!1&&(z.type==="BackgroundBlur"||z.type==="LayerBlur"));Gt||(Gt=r.effect||((F=s.style)==null?void 0:F.effect)||zt.find(z=>z.isEnabled!==!1));const Dt=Gt,te=(Dt==null?void 0:Dt.isEnabled)!==!1,ie=Dt==null?void 0:Dt.type,ce=(Dt==null?void 0:Dt.radius)??10;te&&ie==="LayerBlur"?vt.push(`blur(${ce}px)`):te&&ie==="BackgroundBlur"&&(r===s.style&&(r={...r}),r.fill={type:"None"});const ve=(m==null?void 0:m.adjustments)||(a==null?void 0:a.adjustments)||((O=s.geometry)==null?void 0:O.adjustments),_e=(r==null?void 0:r.adjustments)||((W=s.style)==null?void 0:W.adjustments),ge=((V=r==null?void 0:r.fill)==null?void 0:V.adjustments)||((D=(U=s.style)==null?void 0:U.fill)==null?void 0:D.adjustments),Ee=s==null?void 0:s.adjustments,Zt=ve||_e||ge||Ee;if(i&&Zt&&(i.geometry=i.geometry||{},i.geometry.adjustments={...Zt}),Zt){const z=(Zt.exposure||0)/100,K=(Zt.contrast||0)/100,G=(Zt.saturation||0)/100,x=(Zt.temperature||0)/200,Q=(Zt.tint||0)/200,H=(Zt.highlights||0)/500,lt=(Zt.shadows||0)/500,kt=Zt.hue||0,At=(Zt.negative||0)/100,Ht=Zt.blur||0;if(z!==0&&vt.push(`brightness(${1+z})`),K!==0){const qt=K>0?1+K*2:1+K;vt.push(`contrast(${Number(qt.toFixed(2))})`)}if(G!==0){const qt=G>0?1+G*1.5:1+G;vt.push(`saturate(${Number(qt.toFixed(2))})`)}const Ut=kt+Q*30-x*20;Ut!==0&&vt.push(`hue-rotate(${Math.round(Ut)}deg)`),x>0&&vt.push(`sepia(${Math.round(x*40)}%)`),At!==0&&vt.push(`invert(${Math.abs(At)})`),H!==0&&vt.push(`brightness(${1+H})`),lt!==0&&vt.push(`contrast(${1+lt})`),Ht>0&&vt.push(`blur(${Ht}px)`)}vt.length>0?(t.filter=vt.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 Me=t.globalAlpha,Re=this.normalizeOpacity(i.opacity!==void 0?i.opacity:100);t.globalAlpha=Me*Re;const Ie=i.compositeOperation||i.blendMode;if(Ie&&Ie!=="Normal"){const z=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(z)&&(t.globalCompositeOperation=z)}const de=t,me=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 Ae=!1;const he=me.filter(z=>z.isVisible!==!1&&o.has(z.maskId));if(he.length>0){const z=he[0],K=o.get(z.maskId),G=this.objectStates.get(K.id);G&&G.visible!==!1&&(Ae=!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(Lt,Wt),t.rotate(q*Math.PI/180);const z=i.skew_x||0,K=i.skew_y||0;if(z!==0||K!==0){const At=Math.tan(z*Math.PI/180),Ht=Math.tan(K*Math.PI/180);t.transform(1+At*Ht,Ht,At,1,0,0)}const G=i.rotate_x!==void 0?i.rotate_x:((Y=i.transform)==null?void 0:Y.rotate_x)??0,x=i.rotate_y!==void 0?i.rotate_y:((ot=i.transform)==null?void 0:ot.rotate_y)??0,H=1+(i.translate_z!==void 0?i.translate_z:((J=i.transform)==null?void 0:J.translate_z)??0)/1e3,lt=(i.flip_x===!0?-1:1)*Math.cos(x*Math.PI/180)*H,kt=(i.flip_y===!0?-1:1)*Math.cos(G*Math.PI/180)*H;t.scale(ft*lt,Bt*kt)}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 mt=r.shadow;if(mt&&mt.isEnabled!==!1&&!e){let z=mt.color||"#000000";(j=(at=this.artboard)==null?void 0:at.tokens)!=null&&j.colors&&this.artboard.tokens.colors[z]&&(z=this.artboard.tokens.colors[z]);const K=this.normalizeOpacity(mt.opacity??100)*.75,G=mt.spread||0,Q=(mt.blur||0)+G*1.5;let H=z;if(z.startsWith("#")){const At=z.replace("#",""),Ht=parseInt(At.substring(0,2),16),Ut=parseInt(At.substring(2,4),16),qt=parseInt(At.substring(4,6),16);H=`rgba(${Ht}, ${Ut}, ${qt}, ${K})`}else if(z.startsWith("rgba")){const At=z.match(/[\d.]+/g);if(At&&At.length>=4){const Ht=At[0],Ut=At[1],qt=At[2],$=At[3];H=`rgba(${Ht}, ${Ut}, ${qt}, ${parseFloat($)*K})`}}const lt=t.getTransform(),kt=Math.sqrt(lt.a*lt.a+lt.b*lt.b)||1;t.shadowColor=H,t.shadowBlur=Q*kt,t.shadowOffsetX=(mt.offsetX||0)*kt,t.shadowOffsetY=(mt.offsetY||0)*kt}const rt=s.liquidFill||((it=s.style)==null?void 0:it.liquidFill);if(rt&&rt.enabled){t.save();const z=rt.fillLevel??.5;t.beginPath();const K=d/2-d*z;t.rect(-l/2,K,l,d*z),t.clip(),t.fillStyle=rt.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(rt.opacity??1)}if(e||this.applyOuterGlowUnderlay(t,s,m,l,d,u,r,o),(a==null?void 0:a.type)==="Text"||s.type==="Text")this._renderText(t,s,m,r,i,l,d,!1,!1);else if((a==null?void 0:a.type)==="Image"||((B=r.fill)==null?void 0:B.type)==="Image"||s.type==="Image"&&(a!=null&&a.src||(X=r.fill)!=null&&X.src)){const z=(a==null?void 0:a.originalSrc)||(a==null?void 0:a.src)||((N=r.fill)==null?void 0:N.originalSrc)||((ct=r.fill)==null?void 0:ct.src)||(s==null?void 0:s.src);if(z){let K=this.imageCache.get(z);K||(K=new Image,K.onload=()=>{this.log(`[ExodeUI] Image loaded successfully, size: ${K.naturalWidth}x${K.naturalHeight}`)},K.onerror=Q=>{console.error("[ExodeUI] Image load failed:",Q,`Src preview: ${z.substring(0,100)}...`)},K.src=z,this.imageCache.set(z,K));const G=r.stroke&&r.stroke.width>0&&r.stroke.isEnabled!==!1,x=(((Mt=r.stroke)==null?void 0:Mt.alignment)||"center").toLowerCase();if(G&&x==="outside"&&this.applyStrokeAlignment(t,r,m,l,d,u),r.fill&&r.fill.type!=="None"){t.save();const Q=t.globalAlpha,H=this.createCanvasFill(t,r.fill,l,d);t.fillStyle=H||r.fill.color||"transparent",t.globalAlpha=Q*this.normalizeOpacity(r.fill.opacity??100),u!==0?(this.drawRoundRect(t,-l/2,-d/2,l,d,u),t.fill()):t.fillRect(-l/2,-d/2,l,d),t.globalAlpha=Q,t.restore()}if(K.complete&&K.naturalWidth>0){const Q=Zt?this.processFabricAdjustmentsCanvas(K,l,d,Zt):K;u!==0?(t.save(),this.drawRoundRect(t,-l/2,-d/2,l,d,u),t.clip(),t.drawImage(Q,-l/2,-d/2,l,d),t.restore()):t.drawImage(Q,-l/2,-d/2,l,d),G&&(x==="inside"||x==="center")&&this.applyStrokeAlignment(t,r,m,l,d,u)}else G&&(x==="inside"||x==="center")&&this.applyStrokeAlignment(t,r,m,l,d,u)}}else if(a.type==="SVG"){const z=a.svgContent;if(z){const K=r.palette||[],G=r.fill,x=r.stroke,Q=G?this.normalizeOpacity(G.opacity??100):1,H=x&&x.isEnabled!==!1?this.normalizeOpacity(x.opacity??100):1,lt=(G==null?void 0:G.type)==="Solid"&&(!x||x.isEnabled===!1||x.type==="Solid"&&x.color===G.color&&H===Q),kt=G&&G.type!=="None"?lt?"monochrome":G.type==="Solid"?(G.color||"")+"|opacity:"+Q:JSON.stringify(G.stops||[])+"|opacity:"+Q:"",At=x&&x.isEnabled!==!1&&(x.width||0)>0?lt?["monochrome",x.width||0,x.trimStart??0,x.trimEnd??1,x.trimOffset??0,x.dashOffset??0].join("|"):[x.width||0,x.fill?x.fill.type==="Solid"?x.fill.color||"":JSON.stringify(x.fill.stops||[]):x.color||"",x.opacity??1,x.lineCap||"",x.lineJoin||"",(x.dashArray||[]).join(","),x.trimStart??0,x.trimEnd??1,x.trimOffset??0,x.dashOffset??0].join("|"):"nostroke",Ht=[s.id,K.join("_"),kt,At,i.opacity??100,i.visible!==!1?"v":"h"].join("_");let Ut=this.imageCache.get(Ht);if(!Ut){Ut=new Image,Ut.crossOrigin="anonymous";let $=z;$.match(/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i)||($=$.replace(/<svg([^>]*)>/i,(Ct,Vt)=>`<svg xmlns="http://www.w3.org/2000/svg"${Vt}>`));let dt=a.width||l||100,Rt=a.height||d||100;const Nt=$.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(Nt&&(dt=parseFloat(Nt[1]),Rt=parseFloat(Nt[2])),$=$.replace(/<svg([^>]*)>/i,(Ct,Vt)=>{let Tt=Vt.replace(/\b(?:width|height)=["'][^"']*["']/gi," ");return Tt.match(/\bviewBox=/i)||(Tt+=` viewBox="0 0 ${dt} ${Rt}"`),Tt.match(/\bpreserveAspectRatio=/i)||(Tt+=' preserveAspectRatio="none"'),Tt+=' width="100%" height="100%"',`<svg${Tt}>`}),a.colors&&a.colors.length>0&&K.length>0&&a.colors.forEach((Ct,Vt)=>{if(K[Vt]){const Tt=Ct.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),Xt=new RegExp(Tt,"gi");$=$.replace(Xt,K[Vt])}}),G&&G.type&&G.type!=="None"){if(G.type==="Solid"&&G.color){const Ct=lt?"#FFFFFF":G.color,Vt=lt?1:this.normalizeOpacity(G.opacity??100);$=$.replace(/\bfill\s*=\s*["'][^"']*["']/gi,Tt=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Tt)?Tt:`fill="${Ct}"`),$=$.replace(/fill\s*:\s*[^;"')]+/gi,Tt=>/fill\s*:\s*(none|transparent)/i.test(Tt)?Tt:`fill:${Ct}`),Vt<1&&($=$.replace(/\bfill-opacity\s*=\s*["'][^"']*["']/gi,`fill-opacity="${Vt}"`),$=$.replace(/fill-opacity\s*:\s*[^;"')]+/gi,`fill-opacity:${Vt}`),$.match(/\bfill-opacity\s*=/i)||($=$.replace(/(<svg[^>]*>)/i,`$1<g fill-opacity="${Vt}">`),$=$.replace(/<\/svg>/i,"</g></svg>")))}else if(G.type==="LinearGradient"||G.type==="RadialGradient"||G.type==="Linear"||G.type==="Radial"){const Ct="exode-fill",Vt=this.normalizeOpacity(G.opacity??100),Tt=(G.stops||[]).map(Ft=>{const le=Ft.offset!==void 0?Ft.offset:Ft.pos??0,fe=this.normalizeOpacity(Ft.opacity??100)*Vt;return`<stop offset="${le*100}%" stop-color="${Ft.color||"#000"}" stop-opacity="${fe}"/>`}).join("");let Xt="";if(G.type==="LinearGradient"||G.type==="Linear"){const Ft=(oe,ne)=>Array.isArray(oe)?oe[ne]??(ne===0?0:1):oe&&typeof oe=="object"?oe[ne===0?"x":"y"]??(ne===0?0:1):ne===0?0:1,le=Ft(G.start,0)*100,fe=Ft(G.start,1)*100,Oe=Ft(G.end,0)*100,jt=Ft(G.end,1)*100;Xt=`<linearGradient id="${Ct}" x1="${le}%" y1="${fe}%" x2="${Oe}%" y2="${jt}%" gradientUnits="objectBoundingBox">${Tt}</linearGradient>`}else{const Ft=(jt,oe)=>Array.isArray(jt)?jt[oe]??.5:jt&&typeof jt=="object"?jt[oe===0?"x":"y"]??.5:.5,le=Ft(G.center,0)*100,fe=Ft(G.center,1)*100,Oe=(G.radius??.5)*100;Xt=`<radialGradient id="${Ct}" cx="${le}%" cy="${fe}%" r="${Oe}%" gradientUnits="objectBoundingBox">${Tt}</radialGradient>`}/<defs>/i.test($)?$=$.replace(/<defs>/i,`<defs>${Xt}`):$=$.replace(/<svg([^>]*)>/i,`<svg$1><defs>${Xt}</defs>`),$=$.replace(/\bfill\s*=\s*["'][^"']*["']/gi,Ft=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Ft)?Ft:`fill="url(#${Ct})"`),$=$.replace(/fill\s*:\s*[^;"')]+/gi,Ft=>/fill\s*:\s*(none|transparent)/i.test(Ft)?Ft:`fill:url(#${Ct})`)}}const st=(Ct,Vt,Tt=1)=>{const Xt=(Ct.stops||[]).map(jt=>{const oe=jt.offset!==void 0?jt.offset:jt.pos??0,ne=this.normalizeOpacity(jt.opacity??100)*Tt;return`<stop offset="${oe*100}%" stop-color="${jt.color||"#000"}" stop-opacity="${ne}"/>`}).join(""),Ft=(jt,oe,ne=.5)=>Array.isArray(jt)?jt[oe]??ne:jt&&typeof jt=="object"?jt[oe===0?"x":"y"]??ne:ne;if(Ct.type==="LinearGradient"||Ct.type==="Linear"){const jt=Ft(Ct.start,0,0)*100,oe=Ft(Ct.start,1,0)*100,ne=Ft(Ct.end,0,1)*100,Fe=Ft(Ct.end,1,1)*100;return`<linearGradient id="${Vt}" x1="${jt}%" y1="${oe}%" x2="${ne}%" y2="${Fe}%" gradientUnits="objectBoundingBox">${Xt}</linearGradient>`}const le=Ft(Ct.center,0,.5)*100,fe=Ft(Ct.center,1,.5)*100,Oe=(Ct.radius??.5)*100;return`<radialGradient id="${Vt}" cx="${le}%" cy="${fe}%" r="${Oe}%" gradientUnits="objectBoundingBox">${Xt}</radialGradient>`},yt=(Ct,Vt)=>/<defs>/i.test(Ct)?Ct.replace(/<defs>/i,`<defs>${Vt}`):Ct.replace(/(<svg[^>]*>)/i,`$1<defs>${Vt}</defs>`);if(x&&x.isEnabled!==!1&&(x.width||0)>0){const Ct=lt?1:this.normalizeOpacity(x.opacity??100),Vt=lt?"#FFFFFF":x.color||(G==null?void 0:G.color)||"#000000";let Tt="";const Xt=x.fill;if(Xt&&Xt.type){if(Xt.type==="Solid")Tt=Xt.color||x.color||"#000000";else if(Xt.type==="LinearGradient"||Xt.type==="RadialGradient"||Xt.type==="Linear"||Xt.type==="Radial"){const se="exode-stroke";$=yt($,st(Xt,se,Ct)),Tt=`url(#${se})`}}Tt||(Tt=Vt),$.match(/\bstroke\s*=\s*["']/i)?$=$.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,se=>/stroke\s*=\s*["']\s*(none|transparent)\s*["']/i.test(se)?se:`stroke="${Tt}"`):$=$.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke="${Tt}"`),$=$.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),`stroke:${Tt}`);let Ft=a.width||l||100,le=a.height||d||100;const fe=z.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(fe){const se=parseFloat(fe[1]),ue=parseFloat(fe[2]);!isNaN(se)&&!isNaN(ue)&&(Ft=se,le=ue)}const Oe=Math.max(.001,l/Ft),jt=Math.max(.001,d/le),oe=(Oe+jt)/2,ne=(x.width||1)/oe;$.match(/\bstroke-width\s*=\s*["']/i)?$=$.replace(/\bstroke-width\s*=\s*["'][^"']*["']/gi,`stroke-width="${ne}"`):$=$.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-width="${ne}"`),$=$.replace(/stroke-width\s*:\s*[^;"')]+/gi,`stroke-width:${ne}`),$.match(/\bstroke-opacity\s*=\s*["']/i)?$=$.replace(/\bstroke-opacity\s*=\s*["'][^"']*["']/gi,`stroke-opacity="${Ct}"`):$=$.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-opacity="${Ct}"`),$=$.replace(/stroke-opacity\s*:\s*[^;"')]+/gi,`stroke-opacity:${Ct}`);const Fe=x.lineCap||"round";$.match(/\bstroke-linecap\s*=\s*["']/i)?$=$.replace(/\bstroke-linecap\s*=\s*["'][^"']*["']/gi,`stroke-linecap="${Fe}"`):$=$.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linecap="${Fe}"`),$=$.replace(/stroke-linecap\s*:\s*[^;"')]+/gi,`stroke-linecap:${Fe}`);const Be=x.lineJoin||"round";$.match(/\bstroke-linejoin\s*=\s*["']/i)?$=$.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${Be}"`):$=$.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linejoin="${Be}"`),$=$.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${Be}`);const xe=x.trimStart??0,We=x.trimEnd??1,De=x.trimOffset??0,Ye=x.dashOffset??0,Ge=xe!==0||We!==1||De!==0||Ye!==0;if(Ge){const se=Math.max(0,Math.min(1,xe)),ue=Math.max(0,Math.min(1,We));this.frameCount%600===0&&this.debugLog(`SVG Trim - Object: ${s.name||s.id}, Start: ${se}, End: ${ue}`);const Se=(Ft+le)*2,Xe=(De%1+1)%1,Ne=(Ye%1+1)%1;let ke="",Ce=0;if(se>=ue)ke=`0 ${Se}`,Ce=0;else{const we=Se*(ue-se),Z=Se-we;Ce=-(Se*(se+Xe+Ne)),ke=`${we} ${Z}`}$.match(/\bstroke-dasharray\s*=/i)?$=$.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${ke}"`):$=$.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dasharray="${ke}"`),$=$.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${ke}`),$.match(/\bstroke-dashoffset\s*=/i)?$=$.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${Ce}"`):$=$.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dashoffset="${Ce}"`),$=$.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${Ce}`)}else if(x.dashArray&&x.dashArray.length>0){const se=x.dashArray.join(" ");if($=$.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${se}"`),$=$.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${se}`),x.dashOffset){const ue=(Ft+le)*2,Se=-(x.dashOffset*ue);$=$.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${Se}"`),$=$.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${Se}`)}}if(!/\bstroke\s*=\s*["']/i.test(z)&&!new RegExp("(?<![a-z-])stroke\\s*:","i").test(z)){let se="",ue="";if(Ge){const ke=a.width||l||100,Ce=a.height||d||100,we=(ke+Ce)*2,Z=Math.max(0,Math.min(1,xe)),nt=Math.max(0,Math.min(1,We)),et=(De%1+1)%1,pt=(Ye%1+1)%1;if(Z>=nt)se=` stroke-dasharray="0 ${we}"`,ue=' stroke-dashoffset="0"';else{const $t=we*(nt-Z),xt=we-$t,Jt=-(we*(Z+et+pt));se=` stroke-dasharray="${$t} ${xt}"`,ue=` stroke-dashoffset="${Jt}"`}}else(bt=x.dashArray)!=null&&bt.length&&(se=` stroke-dasharray="${x.dashArray.join(" ")}"`,x.dashOffset&&(ue=` stroke-dashoffset="${x.dashOffset}"`));const Se=` stroke-linecap="${x.lineCap||"round"}"`,Xe=` stroke-linejoin="${x.lineJoin||"round"}"`,Ne=`stroke="${Tt}" stroke-width="${ne}" stroke-opacity="${Ct}"${Se}${Xe}${se}${ue}`;$=$.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(ke,Ce,we)=>`${Ce}${we}<g ${Ne}>`),$=$.replace(/<\/svg>/i,"</g></svg>")}}else x&&x.isEnabled===!1&&($=$.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,'stroke="none"'),$=$.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),"stroke:none"));const St=new Blob([$],{type:"image/svg+xml"}),ee=URL.createObjectURL(St);Ut.onload=()=>{if(URL.revokeObjectURL(ee),this.frameCount%900===0){const Ct=this.imageCache.get(Ht);Ct&&this.debugLog(`SVG Payload Ready: ${s.name||s.id} (${Ct.naturalWidth}x${Ct.naturalHeight})`)}},Ut.onerror=()=>{URL.revokeObjectURL(ee),this.debugLog(`SVG Error: Failed to load payload for ${s.name||s.id}`)},Ut.src=ee,this.imageCache.set(Ht,Ut)}let qt=null;if(Ut.complete&&Ut.naturalWidth>0?(qt=Ut,this.lastValidSvgImgMap.set(s.id,Ut)):qt=this.lastValidSvgImgMap.get(s.id)||null,qt&&qt.complete&&qt.naturalWidth>0){const $=Math.max(1,l),dt=Math.max(1,d);if(lt&&(G==null?void 0:G.type)==="Solid"){this.maskBuffer||(this.maskBuffer=document.createElement("canvas"),this.maskCtx=this.maskBuffer.getContext("2d")),this.maskBuffer.width=$,this.maskBuffer.height=dt,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,$,dt),this.maskCtx.drawImage(qt,0,0,$,dt),this.maskCtx.globalCompositeOperation="source-in";const Rt=G.color||"#000000",Nt=this.normalizeOpacity(G.opacity??100);this.maskCtx.fillStyle=Rt,this.maskCtx.globalAlpha=Nt,this.maskCtx.fillRect(0,0,$,dt),t.drawImage(this.maskBuffer,-$/2,-dt/2,$,dt)}else u!==0?(t.save(),this.drawRoundRect(t,-$/2,-dt/2,$,dt,u),t.clip(),t.drawImage(qt,-$/2,-dt/2,$,dt),t.restore()):t.drawImage(qt,-$/2,-dt/2,$,dt)}}}else if(m.type==="LineGraph")this.renderLineGraph(t,m,l,d);else if(s.type==="Shape"){if(this.applyPath(t,m,l,d,u),t.save(),r.blur&&r.blur.amount>0&&(t.filter=`blur(${r.blur.amount}px)`),te&&ie==="BackgroundBlur")if(e)t.fillStyle="#000000",t.globalAlpha=1,this.applyPath(t,m,l,d,u),t.fill();else{if(t.shadowColor&&t.shadowColor!=="rgba(0, 0, 0, 0)"&&t.shadowColor!=="transparent"){const G=t.getTransform(),x=t.shadowOffsetX,Q=t.shadowOffsetY;t.shadowOffsetX=x+1e4*G.a,t.shadowOffsetY=Q+1e4*G.b,t.save(),t.translate(-1e4,0),this.applyPath(t,m,l,d,u),t.fillStyle="white",t.fill(),t.restore(),t.shadowOffsetX=x,t.shadowOffsetY=Q,t.shadowColor="transparent"}this.applyBackgroundBlurGlass(t,m,l,d,u,Dt,r)}else if(r.fill){const K=t.globalAlpha;if(((wt=r.fill)==null?void 0:wt.type)==="Image"&&(r.fill.originalSrc||r.fill.src)){const G=r.fill.originalSrc||r.fill.src;let x=this.imageCache.get(G);x||(x=new Image,x.src=G,this.imageCache.set(G,x)),x.complete&&x.naturalWidth>0&&(t.save(),this.applyPath(t,m,l,d,u),t.clip(),this.renderFittedImage(t,x,-l/2,-d/2,l,d,r.fill.fillMode),t.restore())}else{const G=this.createCanvasFill(t,r.fill,l,d);t.fillStyle=G||(typeof r.fill=="string"?r.fill:r.fill.color||"transparent"),t.globalAlpha=K*this.normalizeOpacity(r.fill.opacity??100),this.applyPath(t,m,l,d,u),t.fill()}t.globalAlpha=K}t.restore(),r.stroke&&r.stroke.width>0&&(this.applyPath(t,m,l,d,u),this.applyStrokeAlignment(t,r,m,l,d,u))}else if(s.type==="Frame"||s.type==="Component"&&!s.variant||s.type==="Group"&&!s.isStructuralGroup){const z=i.width??a.width??s.width??l,K=i.height??a.height??s.height??d,G=u;if(t.save(),t.beginPath(),this.drawRoundRect(t,-z/2,-K/2,z,K,G),te&&ie==="BackgroundBlur")if(e)t.fillStyle="#000000",t.globalAlpha=1,t.beginPath(),this.drawRoundRect(t,-z/2,-K/2,z,K,G),t.fill();else{if(t.shadowColor&&t.shadowColor!=="rgba(0, 0, 0, 0)"&&t.shadowColor!=="transparent"){const H=t.getTransform(),lt=t.shadowOffsetX,kt=t.shadowOffsetY;t.shadowOffsetX=lt+1e4*H.a,t.shadowOffsetY=kt+1e4*H.b,t.save(),t.translate(-1e4,0),t.beginPath(),this.drawRoundRect(t,-z/2,-K/2,z,K,G),t.fillStyle="white",t.fill(),t.restore(),t.shadowOffsetX=lt,t.shadowOffsetY=kt,t.shadowColor="transparent"}this.applyBackgroundBlurGlass(t,m,z,K,G,Dt,r)}else if(r.fill&&r.fill.type!=="None"){const Q=t.globalAlpha;if(((gt=r.fill)==null?void 0:gt.type)==="Image"&&(r.fill.originalSrc||r.fill.src)){const H=r.fill.originalSrc||r.fill.src;let lt=this.imageCache.get(H);lt||(lt=new Image,lt.src=H,this.imageCache.set(H,lt)),lt.complete&&lt.naturalWidth>0&&(t.save(),t.beginPath(),this.drawRoundRect(t,-z/2,-K/2,z,K,G),t.clip(),this.renderFittedImage(t,lt,-z/2,-K/2,z,K,r.fill.fillMode),t.restore())}else{const H=this.createCanvasFill(t,r.fill,z,K);t.fillStyle=H||r.fill.color||"transparent",t.globalAlpha=Q*this.normalizeOpacity(r.fill.opacity??100),t.beginPath(),this.drawRoundRect(t,-z/2,-K/2,z,K,G),t.fill(),t.globalAlpha=Q}}if(t.restore(),!e&&(te&&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,-z/2,-K/2,z,K,G),this.applyStrokeAlignment(t,r,Q,z,K,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"||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:",(It=s.geometry)==null?void 0:It.type));if(e||(this.applyInnerGlowOverlay(t,s,m,l,d,u,r),this.applyArtEffectOverlay(t,s,m,l,d,u)),rt&&rt.enabled&&t.restore(),s.children&&s.children.length>0){const K=s.type==="Frame",G=s.clipsContent!==void 0?s.clipsContent:s.clipContent!==void 0?s.clipContent:K;if(t.save(),G){t.beginPath();const Q=i.width??(a==null?void 0:a.width)??s.width??0,H=i.height??(a==null?void 0:a.height)??s.height??0,lt=i.cornerRadius??(a==null?void 0:a.corner_radius)??s.cornerRadius??0;this.drawRoundRect(t,-Q/2,-H/2,Q,H,lt),t.clip()}let x=0;for(s.children.forEach(Q=>{const H=o.get(Q);if(!H)return;const lt=this.objectStates.get(Q),kt=(lt==null?void 0:lt.geometry)||H.geometry;if(kt&&kt.isMask&&(lt==null?void 0:lt.visible)!==!1){const At=kt.width||0,Ht=kt.height||0;this.applyObjectTransform(t,Q);const Ut=(lt==null?void 0:lt.corner_radius)??(kt==null?void 0:kt.corner_radius)??0;this.applyPath(t,kt,At,Ht,Ut),t.clip(),x++}else this.renderObject(t,H,o,e)});x>0;)t.restore(),x--;t.restore()}if(Ae){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(x=>x.isVisible!==!1&&o.has(x.maskId)).forEach(x=>{var Ut,qt,$,dt,Rt,Nt;const Q=o.get(x.maskId),H=this.objectStates.get(Q.id),lt=x.feather||0,kt=x.inverted===!0,At=x.opacity!==void 0?typeof x.opacity=="number"?x.opacity:x.opacity/100:1;if((x.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),lt>0&&(this.lumaCtx.filter=`blur(${lt}px)`),this.lumaCtx.globalAlpha=At;const st=(H==null?void 0:H.width)||Q.geometry.width||0,yt=(H==null?void 0:H.height)||Q.geometry.height||0,St=(H==null?void 0:H.corner_radius)??Q.corner_radius??0;if(((Ut=Q.geometry)==null?void 0:Ut.type)==="Text"){const Tt=H!=null&&H.geometry?this.deepMerge(Q.geometry,H.geometry):Q.geometry,Xt=H!=null&&H.style?this.deepMerge(Q.style,H.style):Q.style;this._renderText(this.lumaCtx,Q,{...Tt,width:st,height:yt,corner_radius:St},Xt,H,st,yt,!0,!1)}else if(((qt=Q.geometry)==null?void 0:qt.type)==="Image"){const Tt=Q.geometry.src;if(Tt){let Xt=this.imageCache.get(Tt);Xt||(Xt=new Image,Xt.src=Tt,this.imageCache.set(Tt,Xt)),Xt.complete&&Xt.naturalWidth>0?this.lumaCtx.drawImage(Xt,-st/2,-yt/2,st,yt):(this.applyPath(this.lumaCtx,Q.geometry,st,yt,St),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else if((($=Q.geometry)==null?void 0:$.type)==="SVG"){const Tt=Q.geometry.svgContent;if(Tt){const Xt=`__lumamask_${Q.id}`;let Ft=this.imageCache.get(Xt);if(!Ft){Ft=new Image;const le=new Blob([Tt],{type:"image/svg+xml"});Ft.src=URL.createObjectURL(le),Ft.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(Xt,Ft)}Ft.complete&&Ft.naturalWidth>0?this.lumaCtx.drawImage(Ft,-st/2,-yt/2,st,yt):(this.applyPath(this.lumaCtx,Q.geometry,st,yt,St),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else this.applyPath(this.lumaCtx,Q.geometry,st,yt,St),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill();this.lumaCtx.restore();const ee=this.maskCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight),Ct=this.lumaCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight).data,Vt=ee.data;for(let Tt=0;Tt<Vt.length;Tt+=4){const Xt=Ct[Tt],Ft=Ct[Tt+1],le=Ct[Tt+2];let fe=(.299*Xt+.587*Ft+.114*le)/255;kt&&(fe=1-fe),Vt[Tt+3]*=fe}this.maskCtx.putImageData(ee,0,0)}else{this.maskCtx.save(),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),this.maskCtx.globalCompositeOperation=kt?"destination-out":"destination-in",lt>0&&(this.maskCtx.filter=`blur(${lt}px)`),this.maskCtx.globalAlpha=At,this.applyAbsoluteTransform(this.maskCtx,Q.id,o);const st=(H==null?void 0:H.width)||Q.geometry.width||0,yt=(H==null?void 0:H.height)||Q.geometry.height||0,St=(H==null?void 0:H.corner_radius)??Q.corner_radius??0;if(((dt=Q.geometry)==null?void 0:dt.type)==="Text"){const ee=H!=null&&H.geometry?this.deepMerge(Q.geometry,H.geometry):Q.geometry,Ct=H!=null&&H.style?this.deepMerge(Q.style,H.style):Q.style;this._renderText(this.maskCtx,Q,{...ee,width:st,height:yt,corner_radius:St},Ct,H,st,yt,!0,!1)}else if(((Rt=Q.geometry)==null?void 0:Rt.type)==="Image"){const ee=Q.geometry.src;if(ee){let Ct=this.imageCache.get(ee);Ct||(Ct=new Image,Ct.src=ee,this.imageCache.set(ee,Ct)),Ct.complete&&Ct.naturalWidth>0?this.maskCtx.drawImage(Ct,-st/2,-yt/2,st,yt):(this.applyPath(this.maskCtx,Q.geometry,st,yt,St),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else if(((Nt=Q.geometry)==null?void 0:Nt.type)==="SVG"){const ee=Q.geometry.svgContent;if(ee){const Ct=`__alphamask_${Q.id}`;let Vt=this.imageCache.get(Ct);if(!Vt){Vt=new Image;const Tt=new Blob([ee],{type:"image/svg+xml"});Vt.src=URL.createObjectURL(Tt),Vt.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(Ct,Vt)}Vt.complete&&Vt.naturalWidth>0?this.maskCtx.drawImage(Vt,-st/2,-yt/2,st,yt):(this.applyPath(this.maskCtx,Q.geometry,st,yt,St),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else this.applyPath(this.maskCtx,Q.geometry,st,yt,St),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill();this.maskCtx.restore()}}),de.save(),de.setTransform(1,0,0,1,0,0);const G=s.maskBlendMode||s.blendMode;G&&G!=="Normal"&&(de.globalCompositeOperation=G.toLowerCase()),de.drawImage(this.maskBuffer,0,0),de.restore(),de.restore()}else t.restore()}}applyOuterGlowUnderlay(t,s,o,e,n,i,a,r){var I,_,E;const l=a||s.style||{},d=l.effect,p=l.effects||(d?[d]:[]),u=p.find(P=>P.isEnabled!==!1&&P.type==="Glow"&&(P.mode==="outer"||P.mode==="Outer Glow"||!P.mode));if(!u)return;const m=u.blur||10,h=1e4;let f=u.color||"white";(_=(I=this.artboard)==null?void 0:I.tokens)!=null&&_.colors&&this.artboard.tokens.colors[f]&&(f=this.artboard.tokens.colors[f]),t.save();const v=l.fill&&l.fill.type!=="None",g=p.some(P=>P.isEnabled!==!1&&P.type==="BackgroundBlur"),c=s.type==="Text",b=s.type==="Group";!c&&!b&&(v||g)&&(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 S=t.getTransform();t.shadowColor=f,t.shadowBlur=m,t.shadowOffsetX=h*S.a,t.shadowOffsetY=h*S.b,t.translate(-h,0);let w="black";l.fill&&l.fill.type!=="None"&&(w=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=w,t.strokeStyle=C,t.lineWidth=((E=l.stroke)==null?void 0:E.width)||0;const M=Math.min(u.intensity||1,10);for(let P=0;P<M;P++)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 A=e/2,T=n/2;t.ellipse(0,0,A,T,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 L=l.fill&&l.fill.type!=="None",k=l.stroke&&l.stroke.width>0;(L||!L&&!k)&&t.fill(),k&&t.stroke()}t.restore()}_renderText(t,s,o,e,n,i,a,r=!1,l=!1){var ct,Mt,bt,wt,gt,It,ut,Lt,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 q=this.inputs.get(o.textInputId);q!==void 0&&(d=String(q),n.geometry&&n.geometry.type==="Text"&&(n.geometry.text=d))}if(o.svgPath){const q=o.svgPath;t.save();const ft=((ct=e==null?void 0:e.fill)==null?void 0:ct.color)||"#000000",Bt=((Mt=e==null?void 0:e.fill)==null?void 0:Mt.opacity)!==void 0?(bt=e==null?void 0:e.fill)==null?void 0:bt.opacity:1;t.fillStyle=ft,t.globalAlpha*=Bt;const Ot=new Path2D(q);t.fill(Ot),t.restore();return}let p=d||"";o.enableSegments===!0&&o.segments&&Array.isArray(o.segments)&&(p=o.segments.map(q=>q&&q.text?q.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,q=>q.toUpperCase()));let m=((wt=o.fontWeight)==null?void 0:wt.toString())||"400",h=o.fontStyle||"normal";m.toLowerCase().includes("italic")&&(h="italic",m=m.replace(/italic/gi,"").trim()||"400");const f=this.mapFontWeight(m),v=Math.max(1,o.fontSize||32);let g=o.fontFamily||"Inter";const c=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];c.forEach(q=>{const ft=new RegExp(`[\\s-]${q}$`,"i");ft.test(g)&&(g=g.replace(ft,"").trim())});const b=o.smallCaps===!0,w=`${b?"small-caps ":""}${h} ${f} ${v}px "${g}", sans-serif`;t.font=w;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 q=o.letterSpacing;I=q.unit==="PERCENT"?q.value/100*v:q.value}t.letterSpacing!==void 0&&(t.letterSpacing=`${I}px`);const _=o.kerning||"auto",E=o.kerningValue||0;_==="manual"&&E!==0&&(t.letterSpacing=`${I+E}px`);const P=o.paragraphSpacing||0;let L=o.lineHeight??1.2;typeof L=="string"&&(L=parseFloat(L)),L>5&&v>0&&(L=L/v);const k=(L||1.2)*v,A=o.isPointText===!0||!o.width||o.width<=0,T=((gt=o.padding)==null?void 0:gt.left)||((It=o.padding)==null?void 0:It.right)||0,R=A?1e5:o.width&&o.width>0?Math.ceil(o.width)-T*2:1e5;o.autoHeight;const F=ts({text:p,fontFamily:g,fontSize:v,fontWeight:f,fontStyle:h,lineHeight:L,width:R,letterSpacing:I,paragraphSpacing:P,paragraphIndent:o.paragraphIndent||0,segments:o.segments,enableSegments:o.enableSegments,textCase:u,hyphenation:o.hyphenation,composer:o.composer,balanceRaggedLines:o.balanceRaggedLines}),O=F.lines||[],W=F.maxFontSize||v,V=this.fontLeadingFactors[g]??.5,U=(k-v)*V;let D=F.height,Y=i,ot=a;if(Y===0||ot===0||Y>=1e5||A){let q=0,ft=0;const Bt=F.fullText||p;(O||[]).forEach(Ot=>{const Pt=Ot.text||"",vt=t.measureText(Pt).width+(Pt.length>0?(Pt.length-1)*I:0);vt>q&&(q=vt),ft+=Pt.length,ft<Bt.length&&(Bt[ft]===`
8
- `||Bt[ft]==="\r")&&(ft++,Bt[ft-1]==="\r"&&Bt[ft]===`
9
- `&&ft++)}),(Y===0||Y>=1e5)&&(Y=q),ot===0&&(ot=D||0)}let J=-D/2;a>0&&a>D&&(C==="top"?J=-a/2:C==="middle"||C==="center"?J=-D/2:C==="bottom"&&(J=a/2-D));const at=C==="top"&&a>0?0:U;let j=J+at+U,it=null,B=0;if(o.pathId&&this.artboard){const q=this.artboard.objects.find(ft=>ft.id===o.pathId);if(q&&q.type==="Shape"&&((ut=q.geometry)==null?void 0:ut.type)==="Path"){const ft=this.objectStates.get(q.id),Bt=ft!=null&&ft.geometry?this.deepMerge(q.geometry,ft.geometry):q.geometry,Ot=(ft==null?void 0:ft.scale_x)!==void 0?(q.width||0)*ft.scale_x:q.width||0,Pt=(ft==null?void 0:ft.scale_y)!==void 0?(q.height||0)*ft.scale_y:q.height||0;it={geo:Bt,obj:q,w:Ot,h:Pt},B=this.getPerimeter(Bt,Ot,Pt)}}const X=(q,ft)=>{var Ot,Pt;if(!I&&!b&&!r&&(!o.enableSegments||!((Ot=o.segments)!=null&&Ot.length)))return t.measureText(q).width;let Bt=0;for(let vt=0;vt<q.length;vt++){const Yt=ft+vt;let zt=0;if(o.enableSegments===!0&&((Pt=o.segments)==null?void 0:Pt.length)>0){let Gt=0,Dt=null;for(const te of o.segments){if(Yt<Gt+(te.text||"").length){Dt=te;break}Gt+=(te.text||"").length}if(Dt){t.save();let te=Dt.fontFamily||o.fontFamily||"Inter";const ie=this.mapFontWeight((Dt.fontWeight||o.fontWeight||"400").toString()),ce=Dt.fontStyle||h,ve=Dt.fontSize||v;t.font=`${ce} ${ie} ${ve}px "${te}", sans-serif`,zt=t.measureText(q[vt]).width,t.restore()}else zt=t.measureText(q[vt]).width}else zt=t.measureText(q[vt]).width;Bt+=zt+I}return Bt-(q.length>0?I:0)},N=(q,ft,Bt,Ot,Pt)=>{var ve,_e;const Yt=(Pt===0||p[Pt-1]===`
10
- `||p[Pt-1]==="\r")&&o.paragraphIndent?o.paragraphIndent:0,zt=(!r||l)&&(s.behaviors||[]).some(ge=>ge.enabled&&(ge.type.toString().includes("Text")||["Typewriter","Scramble","Wave","Bounce","GlitchText","Reveal3D","RevealSlide","RevealBlur"].includes(ge.type))),Gt=!o.pathId&&!zt&&(o.enableSegments!==!0||!o.segments||o.segments.length===0),Dt=o.baselineShift||0,te=Bt+Dt,ie=X(q,Pt);let ce=ft+Yt;if(M==="center"?ce-=ie/2:M==="right"&&(ce-=ie),Gt){t.font=w;const ge=t.textAlign;t.textAlign="left",Ot?t.strokeText(q,ce,te):t.fillText(q,ce,te),t.textAlign=ge}else{const ge=t.textAlign;t.textAlign="left";const Ee=Pt+q.length>=p.length||p[Pt+q.length]===`
11
- `||p[Pt+q.length]==="\r";let Zt=0,Me=0;const Re=o.justifyMinWordSpacing,Ie=o.justifyMaxWordSpacing;if(M==="justify"&&!Ee&&ie>0&&!o.pathId){const he=A?ie:R-T*2+0,mt=Math.max(0,he-ie);for(let rt=0;rt<q.length;rt++)q[rt]===" "&&Me++;if(Me>0){const rt=t.measureText(" ").width;let z=Re||rt*.5,K=Ie||rt*2.5;Zt=Math.max(0,Math.min(mt/Me,K-z))}}let de=o.pathOffset||0;o.pathId&&B>0&&it&&(M==="center"?de+=B/2-ie/2:M==="right"&&(de+=B-ie));let me=ce;const Ae=r&&!l?[]:((ve=s.behaviors)==null?void 0:ve.filter(he=>[tt.Typewriter,tt.Scramble,tt.Wave,tt.Bounce,tt.GlitchText,tt.TextTrail,tt.Reveal3D,tt.RevealSlide,tt.RevealBlur,tt.TextLiquid,tt.TextVortex,tt.TextExplosion,tt.TextRain,tt.TextGravity,tt.TextElastic,tt.TextMatrix,tt.TextNeon,tt.TextGlitch3D,tt.TextDissolve,tt.TextOrganic,tt.TextBreathe,tt.TextFloral,tt.TextSmoke,tt.TextVariable,tt.TextMagnet,tt.TextSpin,tt.TextZing,tt.TextPerspective,tt.TextMirror].includes(he.type)&&he.enabled))||[];for(let he=0;he<q.length;he++){let mt=q[he];const rt=Pt+he;let z=0,K=0,G=1,x=1,Q=0,H=1,lt=mt;Ae.forEach($=>{const dt=$.settings||{},Rt=dt.strength||1,Nt=Date.now();if($.type===tt.Typewriter)this.currentTime*(dt.speed||1)-rt*(dt.stagger||.05)<0&&(H=0);else if($.type===tt.Scramble)Math.max(0,Math.min(1,this.currentTime/(dt.duration||1.5))-rt*.02)<1&&Math.random()<.3&&(lt="$%#@!*&"[Math.floor(Math.random()*7)]);else if($.type===tt.Wave)K+=Math.sin(this.currentTime*5*(dt.speed||1)+rt*(dt.frequency||1))*(dt.amplitude||20)*Rt;else if($.type===tt.Bounce){const st=Math.max(0,this.currentTime%2-rt*(dt.stagger||.1));st<1&&(K-=Math.abs(Math.sin(st*Math.PI))*(dt.height||50)*Rt)}else if($.type===tt.TextTrail){const st=this.pointerHistory[Math.max(0,this.pointerHistory.length-1-rt*(dt.delay||5))];st&&(z+=(st.x-(n.x+me))*Rt*.2,K+=(st.y-(n.y+Bt+K))*Rt*.2)}else if($.type===tt.Reveal3D){const st=Math.max(0,Math.min(1,this.currentTime*(dt.speed||1)-rt*(dt.stagger||.1)));G*=st,x*=st,H=st}else if($.type===tt.RevealSlide){const st=Math.max(0,Math.min(1,this.currentTime*1.5-rt*.05)),yt=(1-st)*(dt.distance||40)*Rt,St=dt.direction||"up";St==="up"?K-=yt:St==="down"?K+=yt:St==="left"?z-=yt:St==="right"&&(z+=yt),H=st}else if($.type===tt.RevealBlur){const st=Math.max(0,Math.min(1,this.currentTime*1.2-rt*.1));H=st,z+=(1-st)*5}else if($.type===tt.TextLiquid){const st=Math.max(0,Math.sin(Nt*.001*(dt.speed||1)+rt*.5));K+=st*(dt.amplitude||10)*Rt,x*=1+st*.2}else if($.type===tt.TextVortex){const st=Nt*.002*(dt.speed||1)+rt*.2,yt=(1-(Math.sin(Nt*.001)*.5+.5))*(dt.radius||50);z+=Math.cos(st)*yt*Rt,K+=Math.sin(st)*yt*Rt}else if($.type===tt.TextExplosion){const st=dt.force||1,yt=this.currentTime%2;if(yt<1){const St=(rt/q.length-.5)*Math.PI*2,ee=yt*100*st;z+=Math.cos(St)*ee*Rt,K+=Math.sin(St)*ee*Rt,H=1-yt}}else if($.type===tt.TextRain){const st=dt.speed||1,yt=dt.height||100,St=(Nt*.001*st+rt*.1)%1;K-=(1-St)*yt*Rt,H=St>.1?1:St*10}else if($.type===tt.TextGravity){const st=dt.gravity||9.8,yt=this.currentTime%3/3,St=.5*st*Math.pow(yt*10,2);St<100?K+=St*Rt:K+=100*Rt}else if($.type===tt.TextMatrix){const st=dt.speed||1;if(Math.random()<.1*st){const St="0123456789ABCDEF!@#$%^&*";lt=St[Math.floor(Math.random()*St.length)]}H=.3+(Math.sin(Nt*.01*st+rt)+1)/2*.7}else if($.type===tt.TextNeon){const st=Math.random()>.95?.5:1;H=(.7+(Math.sin(Nt*.005)+1)/2*.3)*st}else if($.type===tt.TextDissolve)Math.sin(rt*1.5+Nt*.002*(dt.speed||1))>.5&&(H=0);else if($.type===tt.TextOrganic){const st=dt.speed||1,yt=dt.amplitude||10;z+=Math.sin(Nt*.002*st+rt)*yt*Rt,K+=Math.cos(Nt*.0015*st+rt*.7)*yt*Rt}else if($.type===tt.TextBreathe){const yt=1+(Math.sin(Nt*.003+rt*.2)+1)/2*.2*Rt;G*=yt,x*=yt}else if($.type===tt.TextSpin){const st=dt.speed||1;Q+=Nt*.01*st+rt}else if($.type===tt.TextMagnet){const st=this.pointerHistory[this.pointerHistory.length-1];if(st){const yt=st.x-(n.x+me),St=st.y-(n.y+Bt);Q=Math.atan2(St,yt)}}else if($.type===tt.TextPerspective){const st=q.length/2,yt=(rt-st)/st,St=1-Math.abs(yt)*.3*Rt;G*=St,x*=St,z+=yt*20*Rt}else if($.type===tt.TextMirror)H*=.8;else if($.type===tt.TextFloral){const st=dt.speed||1,yt=dt.stagger||.1,St=(Nt*.001*st+rt*yt)%2;St<1&&(G*=St,x*=St,Q+=St*Math.PI)}else if($.type===tt.TextSmoke){const st=dt.speed||1,yt=dt.height||50,St=(Nt*5e-4*st+rt*.2)%1;K-=St*yt*Rt,z+=Math.sin(Nt*.002+rt)*5*Rt,H=1-St}else if($.type===tt.TextVariable){const st=dt.speed||1,yt=dt.intensity||1.5,St=(Math.sin(Nt*.004*st+rt*.3)+1)/2;G*=1+St*(yt-1)*Rt}else if($.type===tt.TextZing){const st=dt.speed||2,yt=dt.distance||100,St=(Nt*.002*st+rt*.05)%1;z+=(1-St)*yt*Rt,H=St}else if($.type===tt.TextElastic){const st=dt.stiffness||.2,yt=dt.damping||.1,St=Math.sin(Nt*.01)*Math.exp(-Nt*.001*yt);x*=1+St*st*Rt}else if($.type===tt.TextGlitch3D){const st=dt.intensity||5;Math.random()<.2&&(z+=(Math.random()-.5)*st,K+=(Math.random()-.5)*st,H=.8)}else if($.type===tt.GlitchText){const st=dt.intensity||5;Math.random()<.1&&(z+=(Math.random()-.5)*st,K+=(Math.random()-.5)*st,Math.random()<.05&&(H=.5))}});let kt=null,At=o.textDecoration||"none",Ht=v;if(o.enableSegments===!0&&((_e=o.segments)==null?void 0:_e.length)>0){let $=0,dt=null;for(const Rt of o.segments){if(rt<$+(Rt.text||"").length){dt=Rt;break}$+=(Rt.text||"").length}if(dt){let Rt=dt.fontFamily||o.fontFamily||"Inter";c.forEach(yt=>{const St=new RegExp(`[\\s-]${yt}$`,"i");St.test(Rt)&&(Rt=Rt.replace(St,"").trim())});const Nt=this.mapFontWeight((dt.fontWeight||o.fontWeight||"400").toString()),st=dt.fontStyle||h;Ht=dt.fontSize||v,t.font=`${st} ${Nt} ${Ht}px "${Rt}", sans-serif`,dt.fill&&(kt=dt.fill),dt.textDecoration&&(At=dt.textDecoration),Ht<W&&(K+=(W-Ht)*.85)}}else t.font=w;const Ut=t.globalAlpha;t.globalAlpha*=H,t.save();const qt=t.measureText(lt).width;if(it&&B>0){const $=me-ce+qt/2,Rt=(de+$)/B,Nt=this.getPointOnPath(it.geo,it.w,it.h,Math.abs(Rt%1)),st=Nt.angle,yt=Bt+K+(o.pathOffsetY||0),St=o.pathSide==="right"?-1:1,ee=Math.cos(st+Math.PI/2)*yt*St,Ct=Math.sin(st+Math.PI/2)*yt*St;t.translate(Nt.x+ee+z,Nt.y+Ct),t.rotate(st+Q+(St===-1?Math.PI:0))}else t.translate(me+z+qt/2,Bt+K),Q!==0&&t.rotate(Q);if(t.scale(G,x),kt&&!r&&!l){const $=this.createCanvasFill(t,kt,Y,ot);t.fillStyle=$||kt.color||"#000000"}else if(!r&&!l){const $=this.createCanvasFill(t,e.fill,Y,ot);t.fillStyle=$||e.fill.color||"#000000"}if(H>0)if(r||l){const $=l?"#000000":this.createCanvasFill(t,e.fill,Y,ot);t.fillStyle=$||e.fill.color||"#ffffff",t.fillText(lt,-qt/2,0)}else Ot?t.strokeText(lt,-qt/2,0):t.fillText(lt,-qt/2,0);At!=="none"&&!r&&this.drawTextDecoration(t,At,0,0,qt,Ht),t.restore(),t.globalAlpha=Ut,M==="justify"&&Zt>0&&lt===" "&&!Ee?me+=qt+I+Zt:me+=qt+I}t.textAlign=ge}};if(r){let q=0,ft=j;(O||[]).forEach(Bt=>{const Ot=Bt.text||"",Pt=p.indexOf(Ot,q);Pt!==-1&&(q=Pt);let vt=-Y/2;M==="center"?vt=0:M==="right"&&(vt=Y/2),N(Ot,vt,ft,!1,q),q+=Ot.length,ft+=k})}else if(l){let q=0,ft=j;(O||[]).forEach(Bt=>{const Ot=Bt.text||"";let Pt=-Y/2;M==="center"?Pt=0:M==="right"&&(Pt=Y/2),N(Ot,Pt,ft,!1,q),q+=Ot.length,q<p.length&&(p[q]===`
12
- `||p[q]==="\r")&&(q++,p[q-1]==="\r"&&p[q]===`
13
- `&&q++),ft+=k})}else{if(e.fill){const ft=t.globalAlpha,Bt=this.createCanvasFill(t,e.fill,Y,ot);t.fillStyle=Bt||e.fill.color||"#000000",t.globalAlpha=ft*this.normalizeOpacity(e.fill.opacity??100);const Ot=F.fullText||(o.enableSegments?(o.segments||[]).map(Yt=>{let zt=Yt.text||"";const Gt=Yt.textCase||o.textCase||"none";return Gt==="uppercase"?zt.toUpperCase():Gt==="lowercase"?zt.toLowerCase():Gt==="capitalize"?zt.replace(/\b\w/g,Dt=>Dt.toUpperCase()):zt}).join(""):p);let Pt=0,vt=j;(O||[]).forEach(Yt=>{const zt=Yt.text||"";let Gt=-Y/2;M==="center"?Gt=0:M==="right"&&(Gt=Y/2),N(zt,Gt,vt,!1,Pt),Pt+=zt.length,vt+=k,Pt<Ot.length&&(Ot[Pt]===`
14
- `||Ot[Pt]==="\r")&&(P>0&&(vt+=P),Pt++,Ot[Pt-1]==="\r"&&Ot[Pt]===`
15
- `&&Pt++)}),t.globalAlpha=ft}const q=o.paragraphRule;if(q&&(((Lt=q.top)==null?void 0:Lt.width)>0||((Wt=q.bottom)==null?void 0:Wt.width)>0)){let ft=0;(O||[]).forEach((Bt,Ot)=>{var Yt,zt;const vt=ft===0||ft<p.length&&(p[ft]===`
16
- `||p[ft]==="\r");if(vt&&Ot>0&&ft++,vt){if(((Yt=q.top)==null?void 0:Yt.width)>0){const Gt=j+Ot*k-q.top.offset;t.strokeStyle=q.top.color||"#000000",t.lineWidth=q.top.width,t.beginPath();const Dt=-i/2+k*.2;t.moveTo(Dt,Gt),t.lineTo(i/2-k*.2,Gt),t.stroke()}if(((zt=q.bottom)==null?void 0:zt.width)>0){const Gt=j+(Ot+1)*k-q.bottom.offset;t.strokeStyle=q.bottom.color||"#000000",t.lineWidth=q.bottom.width,t.beginPath();const Dt=-i/2+k*.2;t.moveTo(Dt,Gt),t.lineTo(i/2-k*.2,Gt),t.stroke()}}ft+=(Bt.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(),Pt=Math.sqrt(Ot.a*Ot.a+Ot.b*Ot.b)||1,vt=window.devicePixelRatio||1;t.lineWidth=(e.stroke.width||1)*vt/Pt,t.globalAlpha=ft*this.normalizeOpacity(e.stroke.opacity??100);let Yt=0,zt=j;(O||[]).forEach(Gt=>{let Dt=-Y/2;M==="center"?Dt=0:M==="right"&&(Dt=Y/2),N(Gt.text,Dt,zt,!0,Yt),Yt+=(Gt.text||"").length,zt+=k,Yt<p.length&&(p[Yt]===`
17
- `||p[Yt]==="\r")&&(P>0&&(zt+=P),Yt++,p[Yt-1]==="\r"&&p[Yt]===`
18
- `&&Yt++)}),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,d=window.devicePixelRatio||1,p=(a.width||1)*d/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 S=this.createCanvasFill(t,a.fill,e,n);S?t.strokeStyle=S: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 f=a.trimStart??0,v=a.trimEnd??1,g=a.trimOffset??0,c=a.dashOffset??0,b=a.dashArray||[];if(f!==0||v!==1||g!==0){const S=this.getPerimeter(o,e,n);if(S>0){const w=Math.max(0,Math.min(1,f)),C=Math.max(0,Math.min(1,v));if(w<C){const M=S*(C-w),I=S-M,_=-(S*(w+g%1));t.setLineDash([M,I]),t.lineDashOffset=_-c*S}else if(w===C)t.setLineDash([0,S]);else{const M=S*(1-w+C),I=S-M,_=-(S*w);t.setLineDash([M,I]),t.lineDashOffset=_-c*S}}}else if(b.length>0||c!==0){b.length>0&&t.setLineDash(b);const S=this.getPerimeter(o,e,n);t.lineDashOffset=-(c*S)}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 S=Math.max(e,n,2e4);t.rect(-S,-S,S*2,S*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,u=e[r-1].out_x,m=e[r-1].out_y;if(u!==void 0||l.in_x!==void 0?n+=this.getBezierLength(d,p,u??d,m??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 h=i,f=a,v=[...e.slice(0,r+1)].reverse().find(M=>M.moveTo)||e[0],g=v.x,c=v.y,b=e[r].out_x,S=e[r].out_y,w=v.in_x,C=v.in_y;b!==void 0||w!==void 0?n+=this.getBezierLength(h,f,b??h,S??f,w??g,C??c,g,c):n+=Math.sqrt((g-h)**2+(c-f)**2)}}return n}default:return(s+o)*2}}getBezierLength(t,s,o,e,n,i,a,r,l=10){let d=0,p=t,u=s;for(let m=1;m<=l;m++){const h=m/l,f=1-h,v=h*h,g=f*f,c=g*f,b=v*h,S=c*t+3*g*h*o+3*f*v*n+b*a,w=c*s+3*g*h*e+3*f*v*i+b*r,C=S-p,M=w-u;d+=Math.sqrt(C*C+M*M),p=S,u=w}return d}getBezierTAtLength(t,s,o,e,n,i,a,r,l,d=20){if(t<=0)return 0;let p=0,u=s,m=o;for(let h=1;h<=d;h++){const f=h/d,v=1-f,g=f*f,c=v*v,b=c*v,S=g*f,w=b*s+3*c*f*e+3*v*g*i+S*r,C=b*o+3*c*f*n+3*v*g*a+S*l,M=w-u,I=C-m,_=Math.sqrt(M*M+I*I);if(p+_>=t){const E=t-p,P=_===0?0:E/_;return(h-1+P)/d}p+=_,u=w,m=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 d=(i+a)/2,p=(r+l)/2,m=this.getPerimeter(t,s,o)*e;let h=0;const f=[];let v=n[0],g=n[0];for(let c=1;c<n.length;c++){const b=n[c];if(b.moveTo){v=b,g=b;continue}f.push({p0:v,p1:b}),(b.closePath||c===n.length-1&&(t.is_closed||t.isClosed))&&f.push({p0:b,p1:g}),v=b}for(const c of f){const b=c.p0,S=c.p1;let w=0;const C=b.out_x!==void 0||S.in_x!==void 0;if(C?w=this.getBezierLength(b.x,b.y,b.out_x??b.x,b.out_y??b.y,S.in_x??S.x,S.in_y??S.y,S.x,S.y):w=Math.sqrt((S.x-b.x)**2+(S.y-b.y)**2),h+w>=m||c===f[f.length-1]){let M=0;if(C)return M=this.getBezierTAtLength(m-h,b.x,b.y,b.out_x??b.x,b.out_y??b.y,S.in_x??S.x,S.in_y??S.y,S.x,S.y,20),this.getBezierPointAndAngle(M,b,S,d,p);{M=w===0?0:(m-h)/w;const I=b.x+(S.x-b.x)*M-d,_=b.y+(S.y-b.y)*M-p,E=Math.atan2(S.y-b.y,S.x-b.x);return{x:I,y:_,angle:E}}}h+=w}}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),u=-n*Math.sin(l),m=i*Math.cos(l),h=Math.atan2(m,u);return{x:d,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,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,u=o.x,m=o.y,h=1-t,f=t*t,v=h*h,g=v*h,c=f*t,b=g*i+3*v*t*r+3*h*f*d+c*u-e,S=g*a+3*v*t*l+3*h*f*p+c*m-n,w=3*v*(r-i)+6*h*t*(d-r)+3*f*(u-d),C=3*v*(l-a)+6*h*t*(p-l)+3*f*(m-p),M=Math.atan2(C,w);return{x:b,y:S,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,f,v;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 g=Math.tan(e*Math.PI/180),c=Math.tan(n*Math.PI/180);t.transform(1+g*c,c,g,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:((f=o.transform)==null?void 0:f.rotate_y)??0,l=1+(o.translate_z!==void 0?o.translate_z:((v=o.transform)==null?void 0:v.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,u=(o.scale_x??1)*d,m=(o.scale_y??1)*p;t.scale(u,m)}applyInnerGlowOverlay(t,s,o,e,n,i,a){var g,c;const r=a||s.style||{},l=r==null?void 0:r.effect,p=((r==null?void 0:r.effects)||(l?[l]:[])).find(b=>b.isEnabled!==!1&&b.type==="Glow"&&(b.mode==="inner"||b.mode==="Inner Glow"));if(!p)return;t.save(),t.beginPath(),this.applyPath(t,o,e,n,i),t.clip();const u=p.blur||10,m=1e4,h=t.getTransform();let f=p.color||"white";(c=(g=this.artboard)==null?void 0:g.tokens)!=null&&c.colors&&this.artboard.tokens.colors[f]&&(f=this.artboard.tokens.colors[f]),t.shadowColor=f,t.shadowBlur=u,t.shadowOffsetX=m*h.a,t.shadowOffsetY=m*h.b,t.translate(-m,0),t.lineWidth=u+5,t.strokeStyle=f;const v=Math.min(p.intensity||1,5);for(let b=0;b<v;b++)t.beginPath(),this.applyPath(t,o,e,n,i),t.stroke();t.restore()}applyArtEffectOverlay(t,s,o,e,n,i){var m,h,f,v,g;const a=this.objectStates.get(s.id),r=((m=a==null?void 0:a.style)==null?void 0:m.artEffect)||s.artEffect||((h=s.style)==null?void 0:h.artEffect);if(!r||!r.enabled)return;const l=r.type,d=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 b=this.currentTime*p%2/2,S=t.createLinearGradient(-e,-n,e,n);S.addColorStop(Math.max(0,b-.2),"rgba(255,255,255,0)"),S.addColorStop(b,`rgba(255,255,255,${d*.8})`),S.addColorStop(Math.min(1,b+.2),"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==="glint_overlay"){let S=((this._lastPointerPos||{x:0}).x-(((f=s.transform)==null?void 0:f.x)??0)+300)/600;S=Math.max(-.2,Math.min(1.2,S));const w=t.createLinearGradient(-e,-n,e,n);w.addColorStop(Math.max(0,S-.15),"rgba(255,255,255,0)"),w.addColorStop(Math.max(0,Math.min(1,S)),`rgba(255,255,255,${d})`),w.addColorStop(Math.min(1,S+.15),"rgba(255,255,255,0)"),t.fillStyle=w,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},b=c.x-(((v=s.transform)==null?void 0:v.x)??0),S=c.y-(((g=s.transform)==null?void 0:g.y)??0),w=t.createLinearGradient(b>0?-e/2:e/2,S>0?-n/2:n/2,b>0?e/2:-e/2,S>0?n/2:-n/2);w.addColorStop(0,`rgba(0,0,0,${d*.6})`),w.addColorStop(.4,"rgba(0,0,0,0)"),w.addColorStop(.5,`rgba(255,255,255,${d*.4})`),w.addColorStop(1,`rgba(0,0,0,${d*.2})`),t.fillStyle=w,t.globalCompositeOperation="overlay",t.fillRect(-e/2,-n/2,e,n),t.globalCompositeOperation="source-over",t.beginPath(),b>0&&S>0?(t.moveTo(e/2-40,n/2),t.lineTo(e/2,n/2-40),t.lineTo(e/2-40,n/2-40)):b<0&&S>0?(t.moveTo(-e/2+40,n/2),t.lineTo(-e/2,n/2-40),t.lineTo(-e/2+40,n/2-40)):b>0&&S<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=b>0?-2:2,t.shadowOffsetY=S>0?-2:2,t.fill()}else if(l==="crumple_overlay"){const c=Math.floor(e/u),b=document.createElement("canvas");b.width=c,b.height=Math.floor(n/u);const S=b.getContext("2d"),w=S.createImageData(b.width,b.height);for(let C=0;C<w.data.length;C+=4){const M=Math.random()>.95?150:255;w.data[C]=M,w.data[C+1]=M,w.data[C+2]=M,w.data[C+3]=255*d}S.putImageData(w,0,0),t.globalCompositeOperation="multiply",t.imageSmoothingEnabled=!1,t.drawImage(b,-e/2,-n/2,e,n)}else if(l==="acid_gradient"||l==="acid_rave"){const c=this.currentTime*p,b=r.color1,S=r.color2,w=t.createLinearGradient(-e/2,-n/2,e/2,n/2);if(b&&S){const C=c*60%360;w.addColorStop(0,this._shiftHue(b,C,d*.7)),w.addColorStop(1,this._shiftHue(S,(C+180)%360,d*.7))}else{const C=c*100%360,M=(C+180)%360;w.addColorStop(0,`hsla(${C}, 80%, 50%, ${d*.5})`),w.addColorStop(1,`hsla(${M}, 80%, 50%, ${d*.5})`)}t.fillStyle=w,t.globalCompositeOperation="screen",t.fillRect(-e/2,-n/2,e,n)}else if(l==="halftone"){const c=Math.max(2,u*(1-d*.8)),b=document.createElement("canvas");b.width=c,b.height=c;const S=b.getContext("2d");if(S){S.fillStyle="black",S.beginPath(),S.arc(c/2,c/2,c/2*d,0,Math.PI*2),S.fill();const w=t.createPattern(b,"repeat");w&&(t.globalAlpha=.3*d,t.fillStyle=w,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 b=0;b<c;b++){const S=Math.random()>.5?255:0;t.fillStyle=`rgba(${S}, ${S}, ${S}, ${.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(u*(1-d*.5))),b=document.createElement("canvas"),S=Math.max(1,Math.ceil(e/c)),w=Math.max(1,Math.ceil(n/c));b.width=S,b.height=w;const C=b.getContext("2d");if(C){C.imageSmoothingEnabled=!1;const M=t.getTransform(),I=M.e-e/2,_=M.f-n/2;C.drawImage(t.canvas,I,_,e,n,0,0,S,w),t.imageSmoothingEnabled=!1,t.drawImage(b,0,0,S,w,-e/2,-n/2,e,n),t.imageSmoothingEnabled=!0}}else if(l==="glitch"){const c=this.currentTime*p,b=r.chaosAmount??.2,S=Math.max(3,Math.floor(8*d)),w=d*e*.15;t.globalCompositeOperation="screen",t.globalAlpha=d*.4;const C=w*.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/S;for(let I=0;I<S;I++){const _=Math.sin(I*127.1+c*311.7*p)*43758.5,E=_-Math.floor(_);if(E>1-b){const P=(E-(1-b))/b*w*(Math.random()>.5?1:-1),L=-n/2+I*M,k=t.getTransform(),A=k.e-e/2+P,T=k.f+L;t.save(),t.beginPath(),t.rect(-e/2,L,e,M),t.clip(),t.globalAlpha=.8,t.drawImage(t.canvas,A,T,e,M,-e/2+P,L,e,M),t.restore()}}}t.restore()}}_shiftHue(t,s,o){let e=0,n=0,i=0;if(t.startsWith("#")){const m=t.replace("#","");e=parseInt(m.substring(0,2),16)/255,n=parseInt(m.substring(2,4),16)/255,i=parseInt(m.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 m=a-r;switch(d=p>.5?m/(2-a-r):m/(a+r),a){case e:l=((n-i)/m+(n<i?6:0))/6;break;case n:l=((i-e)/m+2)/6;break;case i:l=((e-n)/m+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 u=t.getTransform(),m=t.canvas;try{const v=document.createElement("canvas");v.width=Math.max(1,Math.ceil(o)),v.height=Math.max(1,Math.ceil(e));const g=v.getContext("2d");if(g){g.save(),g.translate(o/2,e/2);const c=i.magnification||1;if(c!==1&&g.scale(c,c),typeof u.inverse=="function"){const w=u.inverse();g.transform(w.a,w.b,w.c,w.d,w.e,w.f)}else{const w=u.a*u.d-u.b*u.c;w!==0&&g.transform(u.d/w,-u.b/w,-u.c/w,u.a/w,(u.c*u.f-u.d*u.e)/w,(u.b*u.e-u.a*u.f)/w)}g.drawImage(m,0,0),g.restore();const b=document.createElement("canvas");b.width=v.width,b.height=v.height;const S=b.getContext("2d");S.filter=`blur(${r}px)`,S.drawImage(v,0,0),t.globalCompositeOperation="destination-out",t.fillRect(-o/2,-e/2,o,e),t.globalCompositeOperation="source-over",t.globalAlpha=1,t.drawImage(b,-o/2,-e/2,o,e)}}catch(v){console.error("Background blur failed:",v)}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),d>0){if(t.globalAlpha=d/100,!this._noiseTileCanvas){const g=document.createElement("canvas");g.width=64,g.height=64;const c=g.getContext("2d"),b=c.createImageData(64,64),S=b.data;for(let w=0;w<S.length;w+=4){const C=Math.floor(Math.random()*255);S[w]=C,S[w+1]=C,S[w+2]=C,S[w+3]=18}c.putImageData(b,0,0),this._noiseTileCanvas=g}const v=t.createPattern(this._noiseTileCanvas,"repeat");v&&(t.fillStyle=v,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,u=a*Math.PI/180,m=p+u;a>=360&&r<=0?t.ellipse(0,0,l,d,0,0,Math.PI*2):(t.ellipse(0,0,l,d,0,p,m,!1),r>0?t.ellipse(0,0,l*r,d*r,0,m,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,u=p*Math.cos(d),m=p*Math.sin(d);l===0?t.moveTo(u,m):t.lineTo(u,m)}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 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((u,m)=>{if(m===0||u.moveTo)t.moveTo(u.x-d,u.y-p);else{const h=s.points[m-1];if(!h)return;const f=(h.out_x??h.x)-d,v=(h.out_y??h.y)-p,g=(u.in_x??u.x)-d,c=(u.in_y??u.y)-p;isNaN(f)||isNaN(g)||isNaN(u.x)?t.lineTo(u.x-d,u.y-p):t.bezierCurveTo(f,v,g,c,u.x-d,u.y-p)}if(u.closePath||m===s.points.length-1&&(s.is_closed||s.isClosed)){const h=[...s.points.slice(0,m+1)].reverse().find(f=>f.moveTo)||s.points[0];h&&(u.out_x!==void 0||h.in_x!==void 0)&&t.bezierCurveTo((u.out_x??u.x)-d,(u.out_y??u.y)-p,(h.in_x??h.x)-d,(h.in_y??h.y)-p,h.x-d,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 d=(i+a)/2,p=(r+l)/2;s.points.forEach((u,m)=>{if(m===0)t.moveTo(u.x-d,u.y-p);else{const h=s.points[m-1];h.out_x!==void 0||u.in_x!==void 0?t.bezierCurveTo((h.out_x??h.x)-d,(h.out_y??h.y)-p,(u.in_x??u.x)-d,(u.in_y??u.y)-p,u.x-d,u.y-p):t.lineTo(u.x-d,u.y-p)}(u.closePath||m===s.points.length-1&&(s.is_closed||s.isClosed))&&t.closePath()})}}}renderInputBox(t,s){var zt,Gt,Dt,te,ie,ce,ve,_e,ge,Ee,Zt,Me,Re,Ie,de,me,Ae,he;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,d=this.lastHoveredObjectId===s.id,p=e.previewState||"default",u=p!=="default"?p:l?"focused":d?"hovered":"default",m=e.label||{visible:!0,text:"Label"},h=e.helperText||{visible:!1,text:"Helper text"},f=e.leftIcon||{visible:!1},v=e.rightIcon||{visible:!1},g=e.inputType==="textarea"||e.multiline===!0,c=u==="disabled",b=u==="error",S=n.corner_radius??n.cornerRadius,w=Array.isArray(S)?{tl:S[0],tr:S[1],br:S[2],bl:S[3]}:S&&typeof S=="object"?S:void 0,C=Number(e.cornerRadius??e.corner_radius??S??e.radius??8),M=e.corners??w??{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)],_=(mt,rt,z,K,G,x=0)=>{const Q=Math.max(0,z-x*2),H=Math.max(0,K-x*2);let[lt,kt,At,Ht]=G.map(qt=>Math.max(0,(Number(qt)||0)-x));const Ut=Math.min(Q,H)/2;lt=Math.min(lt,Ut),kt=Math.min(kt,Ut),At=Math.min(At,Ut),Ht=Math.min(Ht,Ut),t.beginPath(),t.roundRect?t.roundRect(mt+x,rt+x,Q,H,[lt,kt,At,Ht]):(t.moveTo(mt+x+lt,rt+x),t.lineTo(mt+x+Q-kt,rt+x),t.arcTo(mt+x+Q,rt+x,mt+x+Q,rt+x+kt,kt),t.lineTo(mt+x+Q,rt+x+H-At),t.arcTo(mt+x+Q,rt+x+H,mt+x+Q-At,rt+x+H,At),t.lineTo(mt+x+Ht,rt+x+H),t.arcTo(mt+x,rt+x+H,mt+x,rt+x+H-Ht,Ht),t.lineTo(mt+x+lt,rt+x),t.arcTo(mt+x,rt+x,mt+x+lt,rt+x,lt),t.closePath())};let E=e.backgroundColor||((zt=i.fill)==null?void 0:zt.color)||"rgba(31, 41, 55, 1)",P=e.borderColor||((Dt=(Gt=i.stroke)==null?void 0:Gt.fill)==null?void 0:Dt.color)||((te=i.stroke)==null?void 0:te.color)||"rgba(55, 65, 81, 1)",L=Number(e.borderWidth??((ie=i.stroke)==null?void 0:ie.width)??1),k=e.color||((ce=i.fill)==null?void 0:ce.color)||"#ffffff",A=e.placeholderColor||"rgba(156, 163, 175, 1)",T=e.fontSize||14,R=e.caretColor||"#3b82f6";const F=`${u}Style`,O=e[F];O?(O.backgroundColor!==void 0&&(E=O.backgroundColor),O.borderColor!==void 0&&(P=O.borderColor),O.borderWidth!==void 0&&(L=O.borderWidth),O.color!==void 0&&(k=O.color),O.placeholderColor!==void 0&&(A=O.placeholderColor),O.fontSize!==void 0&&(T=O.fontSize),O.caretColor!==void 0&&(R=O.caretColor)):u==="focused"?(P=e.focusBorderColor||"rgba(59, 130, 246, 1)",L=Math.max(L,2)):u==="hovered"||u==="hover"?(P=e.hoverBorderColor||P,E=e.hoverBackgroundColor||E):c?(E=e.disabledBackgroundColor||"rgba(31, 41, 55, 0.6)",P=e.disabledBorderColor||"rgba(55, 65, 81, 0.4)"):b&&(P="rgba(239, 68, 68, 1)",L=Math.max(L,2));const W=L>0?L/2:0,V=this.createCanvasFill(t,E,a,r);if(V&&E!=="transparent"&&(_(-a/2,-r/2,a,r,I,W),t.fillStyle=V,t.fill()),L>0){const mt=this.createCanvasFill(t,P,a,r);mt&&P!=="transparent"&&(_(-a/2,-r/2,a,r,I,W),t.strokeStyle=mt,t.lineWidth=L,t.lineCap="round",t.lineJoin="round",t.stroke())}if((u==="focused"||u==="focus")&&!c){t.save();const mt=-3,rt=I.map(G=>Math.max(0,G+3));_(-a/2+mt,-r/2+mt,a-mt*2,r-mt*2,rt);const z=((ve=e.activeStyle)==null?void 0:ve.borderColor)||R||"rgba(59, 130, 246, 0.4)",K=this.createCanvasFill(t,z,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 U=e.fontFamily||"Inter",D=e.fontWeight||400,Y=T,ot=e.inputType==="number"&&((_e=e.number)==null?void 0:_e.showSteppers)!==!1,J=24,at=ot?J+4:0,j=String(e.text??e.value??"");let it="Enter text...";if(e.inputType==="tel")it=`${((ge=e.tel)==null?void 0:ge.dialCode)||"+1"} (555) 000-0000`;else if(e.inputType==="number"){const mt=(Ee=e.number)!=null&&Ee.prefix?`${e.number.prefix} `:"",rt=(Zt=e.number)!=null&&Zt.suffix?` ${e.number.suffix}`:"";it=`${mt}0.00${rt}`}else e.inputType==="email"?it="user@example.com":e.inputType==="search"?it="Search anything...":e.inputType==="url"?it="https://example.com":e.inputType==="password"?it="••••••••":e.inputType==="textarea"&&(it="Enter text...");const B=e.placeholder||it,X=!j,N=e.inputType==="password",ct=v.mode==="password-toggle"||N&&v.visible!==!1,Mt=v.mode==="clear"||e.inputType==="search"&&!!j,bt=(mt,rt)=>{var lt;let z=mt.svgPath||"";if(z||(rt?e.inputType==="search"&&(z="M21 21l-6-6m2-5a7 7 0 11-14 0 7 7 0 0114 0z"):ct?z=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":Mt&&(z="M18 6L6 18M6 6l12 12")),!(mt.visible||!!z&&(!rt&&(ct||Mt)||rt&&e.inputType==="search"))||!z)return;const G=mt.size||16,x=(mt.offset??16)+(rt?0:at),Q=typeof mt.color=="string"?mt.color:((lt=mt.color)==null?void 0:lt.color)||"#9ca3af",H=rt?-(a/2)+x:a/2-x;if(t.save(),t.translate(H,0),!z.startsWith("<svg")){const kt=new Path2D(z),At=G/24;t.scale(At,At),t.translate(-12,-12),z.includes("M18 6L6 18")||z.includes("M1 1l22 22")||z.includes("M21 21")?(t.strokeStyle=Q,t.lineWidth=2,t.lineCap="round",t.stroke(kt)):(t.fillStyle=Q,t.fill(kt))}t.restore()};if(bt(f,!0),bt(v,!1),ot){const mt=a/2-J-4;t.save(),t.strokeStyle=P||"rgba(55, 65, 81, 0.5)",t.lineWidth=1,t.beginPath(),t.moveTo(mt,-r/2+6),t.lineTo(mt,r/2-6),t.stroke(),t.beginPath(),t.moveTo(mt,0),t.lineTo(a/2-4,0),t.stroke(),t.fillStyle=k||"rgba(156, 163, 175, 0.8)",t.font=`600 8px "${U}", sans-serif`,t.textAlign="center",t.textBaseline="middle",t.fillText("▲",mt+J/2,-r/4),t.fillText("▼",mt+J/2,r/4),t.restore()}const wt=((Me=e.padding)==null?void 0:Me.left)??e.inputPadding??12,gt=((Re=e.padding)==null?void 0:Re.right)??e.inputPadding??12,It=f.visible||e.inputType==="search",ut=v.visible||ct||Mt,Lt=It?(f.offset??16)+(f.size||16)/2+8:wt,Wt=ut?(v.offset??16)+(v.size||16)/2+8+at:gt+at,q=-(a/2)+Lt,ft=Math.max(0,a-Lt-Wt);let Bt=j||B;if(e.inputType==="number"&&j){const mt=(Ie=e.number)!=null&&Ie.prefix?`${e.number.prefix} `:"",rt=(de=e.number)!=null&&de.suffix?` ${e.number.suffix}`:"";Bt=`${mt}${j}${rt}`}const Ot=N&&j?e.passwordVisible?j:"•".repeat(j.length):Bt,Pt=X?A:k;if(t.font=`${D} ${Y}px "${U}", sans-serif`,t.fillStyle=Pt,t.textAlign="left",t.save(),t.beginPath(),t.rect(q-2,-r/2+4,ft+4,r-8),t.clip(),g){t.textBaseline="top";const mt=Ot.split(`
19
- `);let rt=-r/2+(((me=e.padding)==null?void 0:me.top)??8);const z=Y*1.4,K=e.rows||3;let G=0,x=0;for(const Q of mt){if(G>=K)break;const H=Q.split(" ");let lt="";for(let kt=0;kt<H.length;kt++){const At=lt+H[kt]+" ";if(t.measureText(At).width>ft&&kt>0){if(G>=K)break;t.fillText(lt.trim(),q,rt),lt=H[kt]+" ",rt+=z,G++}else lt=At}G<K&&(t.fillText(lt.trim(),q,rt),x=t.measureText(lt.trim()).width,rt+=z,G++)}if(l&&!X&&Math.floor(performance.now()/500)%2===0){const Q=rt-z;t.fillStyle=R,t.fillRect(q+Math.min(x,ft),Q,1.5,Y)}}else{t.textBaseline="middle";const rt=t.measureText(Ot).width;let z=0;if(rt>ft&&(z=rt-ft),t.fillText(Ot,q-z,0),l&&Math.floor(performance.now()/500)%2===0){const K=X?q:q+rt-z;t.fillStyle=R,t.fillRect(K,-(Y/2),1.5,Y)}}if(t.restore(),e.showCharCounter){t.save();const mt=Number(e.maxLength||0),rt=mt>0?`${j.length}/${mt}`:`${j.length}`;t.font=`400 10px "${U}", sans-serif`,t.fillStyle=mt>0&&j.length>=mt?"#ef4444":"rgba(156, 163, 175, 0.6)",t.textAlign="right",t.textBaseline="top",t.fillText(rt,-(a/2)+a-8,-(r/2)+r+4),t.restore()}if(m.visible!==!1){const mt=!!(m.required||(Ae=e.validation)!=null&&Ae.required),rt=(m.text||"Label")+(mt?" *":""),z=m.fontSize||12,K=m.color||"rgba(156, 163, 175, 1)",G=m.position||"top",x=m.gap??m.offset??6;let Q=-(a/2),H=-(r/2)-x,lt="left",kt="bottom",At=`600 ${z}px "${m.fontFamily||U}", sans-serif`;G==="left"?(Q=-(a/2)-x,H=0,lt="right",kt="middle"):G==="bottom"?(Q=-(a/2),H=r/2+x,lt="left",kt="top"):G==="floating"&&(!!j||l?(Q=-(a/2)+12,H=-(r/2)+4,lt="left",kt="top",At=`600 ${Math.max(9,z-2)}px "${m.fontFamily||U}", sans-serif`):At=null),At&&(t.save(),t.font=At,t.fillStyle=K,t.textAlign=lt,t.textBaseline=kt,t.fillText(rt,Q,H),t.restore())}const vt=(he=e.validation)==null?void 0:he.errorMessage;if(b&&vt||h.visible===!0&&h.text){t.save();const mt=h.fontSize||11,rt=b?"#ef4444":h.color||"rgba(156, 163, 175, 1)",z=h.offset??6,K=b&&vt?vt:h.text;t.font=`400 ${mt}px "${U}", sans-serif`,t.fillStyle=rt,t.textAlign="left",t.textBaseline="top",t.fillText(K,-(a/2),r/2+z),t.restore()}c&&(t.save(),_(-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,d=(n.max??100)-r,p=d===0?0:(a-r)/d,u=n.trackHeight||4,m=n.trackRoundedness??2,h=n.trackShape??"Rectangle",f=n.trackPath||"",v=n.accentColor||"#3b82f6",g=n.inactiveColor||"#374151",c=n.thumbShape||"Ellipse",b=n.thumbWidth??16,S=n.thumbHeight??16,w=n.thumbRoundedness??0,C=n.thumbColor||"#ffffff",M=n.thumbPath||"",I=n.thumbIcon||"",_=n.showValueTooltip??!1,E=n.tooltipBgColor||"#333333",P=n.tooltipColor||"#ffffff",L=n.tooltipOffsetX??0,k=n.tooltipOffsetY??-25,A=(J,at,j,it,B,X,N)=>{if((J==="Custom"||J==="Icon")&&N)try{const ct=new Path2D(N);if(t.save(),t.translate(at,j),J==="Icon"){const Mt=Math.min(it,B)/24;t.scale(Mt,Mt),t.translate(-12,-12)}t.fill(ct),t.restore();return}catch(ct){console.error("Error drawing slider shape in engine:",ct)}if(t.beginPath(),J==="Ellipse")t.ellipse(at,j,it/2,B/2,0,0,Math.PI*2);else if(J==="Rectangle")this.drawRoundRect(t,at-it/2,j-B/2,it,B,X);else if(J==="Triangle")t.moveTo(at,j-B/2),t.lineTo(at+it/2,j+B/2),t.lineTo(at-it/2,j+B/2),t.closePath();else if(J==="Diamond")t.moveTo(at,j-B/2),t.lineTo(at+it/2,j),t.lineTo(at,j+B/2),t.lineTo(at-it/2,j),t.closePath();else if(J==="Polygon"){const ct=s.geometry.sides||3,Mt=s.geometry.radius||Math.min(it,B)/2;for(let bt=0;bt<ct;bt++){const wt=bt*2*Math.PI/ct-Math.PI/2,gt=at+Mt*Math.cos(wt),It=j+Mt*Math.sin(wt);bt===0?t.moveTo(gt,It):t.lineTo(gt,It)}t.closePath()}else if(J==="Star"){const Mt=Math.min(it,B)/2,bt=Mt/2;for(let wt=0;wt<10;wt++){const gt=wt%2===0?Mt:bt,It=wt*Math.PI/5-Math.PI/2;t.lineTo(at+gt*Math.cos(It),j+gt*Math.sin(It))}t.closePath()}else J==="Line"&&(t.moveTo(at-it/2,j),t.lineTo(at+it/2,j));t.fill()},T=this.createCanvasFill(t,g,i,u);T&&(t.fillStyle=T,t.strokeStyle=T),h==="Line"?(t.lineWidth=u,t.beginPath(),t.moveTo(-i/2,0),t.lineTo(i/2,0),t.stroke()):A(h,0,0,i,u,m,f);const R=i-b,F=-i/2+b/2+p*R,O=F- -i/2;if(O>0){const J=this.createCanvasFill(t,v,i,u);J&&(t.fillStyle=J,t.strokeStyle=J),h==="Line"?(t.lineWidth=u,t.beginPath(),t.moveTo(-i/2,0),t.lineTo(F,0),t.stroke()):h==="Rectangle"&&(t.beginPath(),this.drawRoundRect(t,-i/2,-u/2,O,u,m),t.fill())}t.save(),t.translate(F,0);const W=t.getTransform(),V=Math.sqrt(W.a*W.a+W.b*W.b)||1;t.shadowColor="rgba(0,0,0,0.2)",t.shadowBlur=4*V,t.shadowOffsetY=1*V;const U=this.createCanvasFill(t,C,b,S);if(U&&(t.fillStyle=U),A(c,0,0,b,S,w,c==="Icon"?I:M),t.restore(),_){t.save(),t.translate(F+L,k);const J=Math.round(a).toString();t.font="10px Inter, sans-serif";const at=t.measureText(J),j=6,it=4,B=at.width+j*2,X=14+it;t.beginPath(),this.drawRoundRect(t,-B/2,-X/2,B,X,4),t.fillStyle=E,t.fill(),t.fillStyle=P,t.textAlign="center",t.textBaseline="middle",t.fillText(J,0,0),t.restore()}const D=n.label||{},Y=n.helperText||{},ot=n.fontFamily||"Inter";if(D.visible!==!1){const J=D.text||"Label",at=D.fontSize||12,j=D.color||"rgba(156, 163, 175, 1)",it=D.offset??8;t.font=`600 ${at}px "${ot}", sans-serif`,t.fillStyle=j,t.textAlign="left",t.textBaseline="bottom";const B=-(i/2),X=-(u/2)-it;t.fillText(J,B,X)}if(Y.visible===!0){const J=Y.text||"Helper text",at=Y.fontSize||11,j=Y.color||"rgba(156, 163, 175, 1)",it=Y.offset??6;t.font=`400 ${at}px "${ot}", sans-serif`,t.fillStyle=j,t.textAlign="left",t.textBaseline="top";const B=-(i/2),X=u/2+it;t.fillText(J,B,X)}}renderDropdown(t,s){var k;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",u=(e.isOpen||e.previewState==="active")&&!d;let m=e.backgroundColor,h=e.borderColor,f=e.color||"#333333";d?(m=e.disabledBackgroundColor||"#f3f4f6",h=e.disabledBorderColor||"#e5e7eb",f=e.disabledColor||"#9ca3af"):u?(m=e.activeBackgroundColor||m,h=e.activeBorderColor||h,f=e.activeColor||f):p&&(m=e.hoverBackgroundColor||m,h=e.hoverBorderColor||h,f=e.hoverColor||f),m||(m="#ffffff"),h||(h="#e5e7eb"),t.save();const v=t.globalAlpha;t.globalAlpha=v*(e.opacity??1),t.beginPath(),this.drawRoundRect(t,a,r,n,i,l),t.fillStyle=this.createCanvasFill(t,typeof m=="string"?{type:"Solid",color:m}:m,n,i)||"#ffffff",t.fill();const g=e.borderWidth??1;g>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=g,t.stroke());const c=12,b=e.chevronType||"chevron",S=e.chevronSize||16,w=(u?e.openIconColor:e.closedIconColor)||e.chevronColor||"#6b7280";if(b!=="none"){const A=a+n-c-S/2;t.save(),t.translate(A,0);const T=u?e.openIconAngle??180:e.closedIconAngle??0;if(t.rotate(T*Math.PI/180),t.strokeStyle=w,t.fillStyle=w,t.lineWidth=1.5,t.lineCap="round",t.lineJoin="round",b==="chevron")t.beginPath(),t.moveTo(-S/2,-S*.2),t.lineTo(0,S*.2),t.lineTo(S/2,-S*.2),t.stroke();else if(b==="custom"||b==="path"){const R=u&&e.openIconPath||e.closedIconPath;if(R){const F=new Path2D(R);t.save();const O=S/24;t.scale(O,O),t.translate(-12,-12),t.fill(F),t.restore()}}t.restore()}const C=e.selectedOption||e.placeholder||"Select...",M=e.fontSize||14,I=e.fontWeight||400,_=e.fontFamily||"Inter, sans-serif";t.font=`${I} ${M}px ${_}`;const E=d?e.disabledColor||"#9ca3af":!e.selectedOption&&e.placeholder?"#9ca3af":f;t.fillStyle=this.createCanvasFill(t,typeof E=="string"?{type:"Solid",color:E}:E,n,i)||"#333333",t.textAlign="left",t.textBaseline="middle";const P=b==="none"?0:S+8,L=n-c*2-P;if(t.save(),t.beginPath(),t.rect(a+c,r,L,i),t.clip(),t.fillText(C,a+c,0),t.restore(),u&&!d){const A=r+i+4,T=this.getResolvedDropdownOptions(s,e),R=e.itemHeight||32,F=e.listPadding??4,O=T.length*R+F*2,W=e.listCornerRadius??l;t.save();const V=e.listShadow||{},U=t.getTransform(),D=Math.sqrt(U.a*U.a+U.b*U.b)||1;t.shadowColor=typeof V.color=="string"?V.color:((k=V.color)==null?void 0:k.color)||"rgba(0,0,0,0.15)",t.shadowBlur=(V.blur??12)*D,t.shadowOffsetY=(V.offsetY??6)*D,t.shadowOffsetX=(V.offsetX??0)*D,t.beginPath(),this.drawRoundRect(t,a,A,n,O,W),t.fillStyle=this.createCanvasFill(t,typeof e.listBackgroundColor=="string"?{type:"Solid",color:e.listBackgroundColor}:e.listBackgroundColor||{type:"Solid",color:"#ffffff"},n,O)||"#ffffff",t.fill();const Y=e.listBorderWidth??1;Y>0&&(t.shadowColor="transparent",t.beginPath(),this.drawRoundRect(t,a,A,n,O,W),t.strokeStyle=this.createCanvasFill(t,typeof e.listBorderColor=="string"?{type:"Solid",color:e.listBorderColor}:e.listBorderColor||{type:"Solid",color:h},n,O)||"#e5e7eb",t.lineWidth=Y,t.stroke()),t.restore();const ot=e.itemFontSize||M,J=e.itemFontFamily||_;t.font=`${I} ${ot}px ${J}`,T.forEach((at,j)=>{const it=A+F+j*R;if(at===e.selectedOption)t.fillStyle=this.createCanvasFill(t,typeof e.itemSelectedBackgroundColor=="string"?{type:"Solid",color:e.itemSelectedBackgroundColor}:e.itemSelectedBackgroundColor||{type:"Solid",color:"#f3f4f6"},n,R)||"#f3f4f6",t.fillRect(a+Y,it,n-Y*2,R),t.fillStyle=e.itemSelectedColor||e.accentColor||f||"#374151";else if(t.fillStyle=e.listTextColor||f||"#333333",this.activeDropdownId===s.id&&this._lastPointerPos){const X=this._lastPointerPos.y-(A+F),N=Math.floor(X/R);j===N&&(t.fillStyle=this.createCanvasFill(t,typeof e.itemHoverBackgroundColor=="string"?{type:"Solid",color:e.itemHoverBackgroundColor}:e.itemHoverBackgroundColor||{type:"Solid",color:"#f9fafb"},n,R)||"#f9fafb",t.fillRect(a+Y,it,n-Y*2,R),t.fillStyle=e.itemHoverColor||f)}t.fillText(at,a+c,it+R/2)})}t.restore()}renderButton(t,s){var L;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||{},u=e.activeStyle||{},m=e.icon||{enabled:!1};let h=e.backgroundColor||e.buttonBgColor||((L=s.style)==null?void 0:L.fill)||"#3b82f6",f=(typeof d=="object"?d.color:null)||"#ffffff",v=typeof d=="string"?d:d.text||s.text||(s.name&&!s.name.toLowerCase().includes("component")?s.name:"Button"),g=n.cornerRadius??n.corner_radius??8,c=e.borderColor||"transparent",b=e.borderWidth||0,S=1;l&&u?(h=u.backgroundColor||h,f=u.color||f,v=u.text||v,S=u.scale??.95,g=u.cornerRadius??g):r&&p&&(h=p.backgroundColor||h,f=p.color||f,v=p.text||v,S=p.scale??1,g=p.cornerRadius??g,c=p.borderColor||c);const w=-i/2,C=-a/2;t.save(),t.scale(S,S),t.beginPath(),this.drawRoundRect(t,w,C,i,a,g);const M=this.createCanvasFill(t,h,i,a);M&&(t.fillStyle=M,t.fill()),(b>0||r&&p.borderColor)&&(t.strokeStyle=c,t.lineWidth=b||(r?1:0),t.stroke());const I=d.fontSize||14,_=d.fontFamily||"Inter",E=d.fontWeight||600;t.font=`${E} ${I}px "${_}", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle=f,t.textAlign="center",t.textBaseline="middle";let P=0;if(m.enabled&&m.svgPath){const k=I*1.1,A=m.gap||8,T=t.measureText(v),F=-(T.width+k+A)/2,O=m.position==="left"?F+k/2:F+T.width+A+k/2;P=m.position==="left"?F+k+A+T.width/2:F+T.width/2,t.save(),t.translate(O,0);const W=new Path2D(m.svgPath),V=k/24;t.scale(V,V),t.translate(-12,-12),t.fillStyle=f,t.fill(W),t.restore()}t.fillText(v,P,0),t.restore()}renderToggleButton(t,s){var v,g;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=e.checked??!1,i=((v=s.geometry)==null?void 0:v.width)||120,a=((g=s.geometry)==null?void 0:g.height)||40,r=-i/2,l=-a/2,d=e.corner_radius??8,p=e.label||{},u=n?e.accentColor||"#3b82f6":e.inactiveColor||"#374151",m=n?e.activeTextColor||"#ffffff":e.inactiveTextColor||"#9ca3af";t.save(),t.beginPath(),this.drawRoundRect(t,r,l,i,a,d),t.fillStyle=u,t.fill();const h=p.fontSize||14,f=p.fontFamily||"Inter";t.font=`${p.fontWeight||600} ${h}px "${f}", sans-serif`,t.fillStyle=m,t.textAlign="center",t.textBaseline="middle",t.fillText(p.text||"Toggle",0,0),t.restore()}renderToggle(t,s){var W,V,U,D,Y,ot,J,at,j,it,B,X;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=((W=s.geometry)==null?void 0:W.width)||52,i=((V=s.geometry)==null?void 0:V.height)||30,a=-n/2,r=-i/2,l=e.checked??!1,d=e.cornerRadius??e.corner_radius??i/2,p=e.toggleStyle||{},u=p.backgroundColor||e.activeColor||"#10b981",m=p.borderColor||e.borderColor||"transparent",h=p.borderWidth??e.borderWidth??0,f=p.knobColor||e.knobColor||"#ffffff",v=l?u:e.inactiveColor||"#374151",g=l?m:e.borderColor||"transparent",c=l?h:e.borderWidth??0,b=l?f:e.knobColor||"#ffffff";e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,n,i,d);const S=this.createCanvasFill(t,v,n,i);if(S&&(t.fillStyle=S,t.fill()),c>0){t.lineWidth=c;const N=this.createCanvasFill(t,g,n,i);N&&(t.strokeStyle=N,t.stroke())}const w=2,C=i-w*2,M=C/2,I=a+w,_=a+n-w-C,E=l?_:I,P=r+w;t.beginPath(),t.arc(E+M,P+M,M,0,Math.PI*2);const L=this.createCanvasFill(t,b,C,C);L&&(t.fillStyle=L,t.fill()),e.disabled&&(t.globalAlpha*=2);let k=!1,A=!1;const T=(l?(U=p.leftLabel)==null?void 0:U.text:null)||((D=e.leftLabel)==null?void 0:D.text)||"",R=(l?(Y=p.leftLabel)==null?void 0:Y.color:null)||((ot=e.leftLabel)==null?void 0:ot.color)||"#f3f4f6";if((J=e.leftLabel)!=null&&J.enabled&&T){const N=e.leftLabel;t.font=`${N.fontWeight||400} ${N.fontSize||12}px "${N.fontFamily||"Inter"}", sans-serif`,t.fillStyle=R,t.textBaseline="middle",t.textAlign="right",t.fillText(T,a-(N.gap||8),0),k=!0}const F=(l?(at=p.rightLabel)==null?void 0:at.text:null)||((j=e.rightLabel)==null?void 0:j.text)||"",O=(l?(it=p.rightLabel)==null?void 0:it.color:null)||((B=e.rightLabel)==null?void 0:B.color)||"#f3f4f6";if((X=e.rightLabel)!=null&&X.enabled&&F){const N=e.rightLabel;t.font=`${N.fontWeight||400} ${N.fontSize||12}px "${N.fontFamily||"Inter"}", sans-serif`,t.fillStyle=O,t.textBaseline="middle",t.textAlign="left",t.fillText(F,a+n+(N.gap||8),0),A=!0}if(!k&&!A&&e.label&&e.label.text){const N=e.label,ct=N.fontSize||14,Mt=N.fontWeight||400,bt=N.fontFamily||"Inter";t.font=`${Mt} ${ct}px "${bt}", sans-serif`,t.fillStyle=N.color||"#f3f4f6",t.textBaseline="middle";const wt=N.gap||10;let gt=0,It=0;N.position==="left"?(t.textAlign="right",gt=a-wt,It=0):N.position==="right"?(t.textAlign="left",gt=a+n+wt,It=0):N.position==="top"?(t.textAlign="center",gt=0,It=r-wt,t.textBaseline="bottom"):N.position==="bottom"?(t.textAlign="center",gt=0,It=r+i+wt,t.textBaseline="top"):(t.textAlign="left",gt=a+n+wt,It=0),t.fillText(N.text,gt,It)}}renderCheckbox(t,s){var S,w;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},n=((S=s.geometry)==null?void 0:S.width)||20,i=((w=s.geometry)==null?void 0:w.height)||20,a=-n/2,r=-i/2,l=e.cornerRadius??4,d=e.checked??!1,p=e.activeColor||"#3b82f6",u=e.inactiveColor||"transparent",m=e.checkColor||"#ffffff",h=e.borderColor||"#4b5563",f=e.borderWidth??2,v=d?p:u,g=d?"transparent":h,c=d?0:f;e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,n,i,l);const b=this.createCanvasFill(t,v,n,i);if(b&&(t.fillStyle=b,t.fill()),c>0){t.lineWidth=c;const C=this.createCanvasFill(t,g,n,i);C&&(t.strokeStyle=C,t.stroke())}else if(d){t.lineWidth=1;const C=this.createCanvasFill(t,p,n,i);C&&(t.strokeStyle=C,t.stroke())}if(d){t.save(),t.beginPath();const C=this.createCanvasFill(t,m,n,i);t.strokeStyle=C||m,t.lineWidth=Math.max(2,n*.12),t.lineCap="round",t.lineJoin="round";const M=a+n*.25,I=r+i*.5,_=a+n*.45,E=r+i*.7,P=a+n*.75,L=r+i*.25;t.moveTo(M,I),t.lineTo(_,E),t.lineTo(P,L),t.stroke(),t.restore()}if(e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const C=e.label;t.save(),t.font=`${C.fontWeight||400} ${C.fontSize||14}px "${C.fontFamily||"Inter"}", sans-serif`,t.fillStyle=C.color||"#f3f4f6",t.textBaseline="middle";const M=C.gap||8;let I=0,_=0;C.position==="left"?(t.textAlign="right",I=a-M,_=0):C.position==="right"?(t.textAlign="left",I=a+n+M,_=0):C.position==="top"?(t.textAlign="center",I=0,_=r-M,t.textBaseline="bottom"):C.position==="bottom"&&(t.textAlign="center",I=0,_=r+i+M,t.textBaseline="top"),t.fillText(C.text,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=((_=s.geometry)==null?void 0:_.width)||180,i=((E=s.geometry)==null?void 0:E.height)||100,a=-n/2,r=-i/2;let l=e.optionsList||["Option 1","Option 2","Option 3"];if(e.isDataVarEnabled&&e.dataInputId){let P=this.inputs.get(e.dataInputId);if(P===void 0){const L=this.inputNameMap.get(e.dataInputId);L&&L.length>0&&(P=this.inputs.get(L[0]))}P&&Array.isArray(P)&&(l=P.map(L=>typeof L=="string"?L:String(L)))}const d=e.selectedValue,p=e.orientation||"vertical",u=e.itemGap!==void 0?e.itemGap:16,m=e.activeColor||"#3b82f6",h=e.inactiveColor||"#4b5563",f=e.textColor||"#ffffff",v=e.fontSize||14,g=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 b=8,S=b*2,w=e.radioShape||"circle",C=e.borderWidth!==void 0?e.borderWidth:2,M=e.fillEmpty||"transparent",I=(P,L,k,A)=>{if(t.beginPath(),A==="custom"&&e.customShapePath)try{const T=new Path2D(e.customShapePath);t.save(),t.translate(P-k,L-k),t.scale(k*2/24,k*2/24),t.fill(T),t.restore();return}catch{t.arc(P,L,k,0,Math.PI*2);return}if(A==="square"){const T=k*1.6;t.rect(P-T/2,L-T/2,T,T)}else if(A==="diamond"){const T=k*1.4;t.moveTo(P,L-T),t.lineTo(P+T,L),t.lineTo(P,L+T),t.lineTo(P-T,L),t.closePath()}else if(A==="heart"){const T=k*.9;t.moveTo(P,L+T*.7),t.bezierCurveTo(P-T*1.5,L-T*.3,P-T*.5,L-T*1.5,P,L-T*.5),t.bezierCurveTo(P+T*.5,L-T*1.5,P+T*1.5,L-T*.3,P,L+T*.7)}else if(A==="star"){const T=k*1.1,R=k*.5;for(let F=0;F<5;F++){const O=(F*72-90)*Math.PI/180,W=(F*72+36-90)*Math.PI/180;F===0?t.moveTo(P+T*Math.cos(O),L+T*Math.sin(O)):t.lineTo(P+T*Math.cos(O),L+T*Math.sin(O)),t.lineTo(P+R*Math.cos(W),L+R*Math.sin(W))}t.closePath()}else t.arc(P,L,k,0,Math.PI*2)};if(t.font=`${c} ${v}px "${g}", sans-serif`,t.textBaseline="middle",t.textAlign="left",p==="vertical"){const P=Math.max(S,v)+u,L=l.length*P-u,k=r+Math.max(0,(i-L)/2);l.forEach((A,T)=>{const R=k+b+T*P,F=d===A,O=this.createCanvasFill(t,m,S,S),W=this.createCanvasFill(t,h,S,S);F?(t.fillStyle=O||m,I(a+b,R,b,w),t.fill(),t.strokeStyle=O||m,t.lineWidth=C,I(a+b,R,b,w),t.stroke()):(M!=="transparent"&&(t.fillStyle=M,I(a+b,R,b,w),t.fill()),t.strokeStyle=W||h,t.lineWidth=C,I(a+b,R,b,w),t.stroke()),t.fillStyle=f,t.fillText(A,a+S+8,R)})}else{const P=r+i/2;let L=0;t.font=`${c} ${v}px "${g}", sans-serif`,l.forEach(T=>{L+=S+6+t.measureText(T).width+u}),L-=u;let A=a+Math.max(0,(n-L)/2);l.forEach(T=>{const R=d===T,F=t.measureText(T).width,O=this.createCanvasFill(t,m,S,S),W=this.createCanvasFill(t,h,S,S);R?(t.fillStyle=O||m,I(A+b,P,b,w),t.fill(),t.strokeStyle=O||m,t.lineWidth=C,I(A+b,P,b,w),t.stroke()):(M!=="transparent"&&(t.fillStyle=M,I(A+b,P,b,w),t.fill()),t.strokeStyle=W||h,t.lineWidth=C,I(A+b,P,b,w),t.stroke()),t.fillStyle=f,t.fillText(T,A+S+6,P),A+=S+6+F+u})}if(t.restore(),e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const P=e.label;t.save(),t.font=`${P.fontWeight||400} ${P.fontSize||14}px "${P.fontFamily||"Inter"}", sans-serif`,t.fillStyle=P.color||"#9ca3af",t.textBaseline="middle";const L=P.gap||8;let k=0,A=0;P.position==="left"?(t.textAlign="right",k=a-L,A=0):P.position==="right"?(t.textAlign="left",k=a+n+L,A=0):P.position==="top"?(t.textAlign="center",k=0,A=r-L,t.textBaseline="bottom"):P.position==="bottom"&&(t.textAlign="center",k=0,A=r+i+L,t.textBaseline="top"),t.fillText(P.text,k,A),t.restore()}}renderBarChart(t,s){var E,P,L;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 k=this.inputs.get(e.dataInputId);if(k===void 0){const A=this.inputNameMap.get(e.dataInputId);A&&A.length>0&&(k=this.inputs.get(A[0]))}k&&Array.isArray(k)&&(n.categories=k.map(A=>typeof A=="string"?A:String(A)))}if(e.isDatasetsVarEnabled&&((E=e.datasetInputIds)==null?void 0:E.length)>0){const k=e.datasetInputIds.map((A,T)=>{var O;let R=this.inputs.get(A);if(R===void 0){const W=this.inputNameMap.get(A);W&&W.length>0&&(R=this.inputs.get(W[0]))}const F=((O=e.datasets)==null?void 0:O[T])||{id:`ds-${T}`,label:`Series ${T+1}`,data:[],color:"#6366f1"};return R&&Array.isArray(R)?{...F,data:R.map(W=>typeof W=="number"?W:parseFloat(W)||0)}:F});n.datasets=k}const i={width:((P=s.geometry)==null?void 0:P.width)||300,height:((L=s.geometry)==null?void 0:L.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],_hexToRgb:function(k,A){if(k.startsWith("rgba")||k.startsWith("rgb"))return k;k.startsWith("#")||(k="#"+k),k.length===4&&(k="#"+k[1]+k[1]+k[2]+k[2]+k[3]+k[3]);const T=parseInt(k.slice(1,3),16),R=parseInt(k.slice(3,5),16),F=parseInt(k.slice(5,7),16);return`rgba(${T},${R},${F},${A})`},_resolveColor:function(k,A){return typeof k=="string"?k:"#6366f1"},_makeGradient:function(k,A,T,R,F,O){if(!this.barGradient)return A;const W=this.gradientStartColor||A,V=k.createLinearGradient(T,R,F,O);return V.addColorStop(0,A),V.addColorStop(1,this._hexToRgb(W,this.gradientEndOpacity)),V},_drawRoundedBar:function(k,A,T,R,F,O,W){if(O=Math.min(O,Math.min(Math.abs(R),Math.abs(F))/2),O<=0||R===0||F===0){k.rect(A,T,R,F);return}k.beginPath(),W?(k.moveTo(A,T+F),k.lineTo(A,T+O),k.quadraticCurveTo(A,T,A+O,T),k.lineTo(A+R-O,T),k.quadraticCurveTo(A+R,T,A+R,T+O),k.lineTo(A+R,T+F),k.lineTo(A,T+F)):(k.moveTo(A,T),k.lineTo(A+R-O,T),k.quadraticCurveTo(A+R,T,A+R,T+O),k.lineTo(A+R,T+F-O),k.quadraticCurveTo(A+R,T+F,A+R-O,T+F),k.lineTo(A,T+F),k.lineTo(A,T)),k.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,u=1/0;const m=i.categories.length,h=i.datasets.length;if(i.chartType==="stacked")for(let k=0;k<m;k++){let A=0,T=0;i.datasets.forEach(R=>{const F=R.data[k]??0;F>=0?A+=F:T+=F}),A>p&&(p=A),T<u&&(u=T)}else i.datasets.forEach(k=>{k.data&&k.data.forEach(A=>{A>p&&(p=A),A<u&&(u=A)})});isFinite(p)||(p=10),isFinite(u)||(u=0),p=Math.max(p,0),u=Math.min(u,0);const f=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 v=i.showYLabels?t.measureText(p.toFixed(0)).width+14:10,g=i.showXLabels?i.axisLabelFontSize+12:8,b=(i.showLegend&&h>0?i.legendFontSize+10:0)+8,S=10,w=l+v,C=d+b,M=a-v-S,I=r-b-g;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&&h>0){t.font=i.legendFontSize+"px Inter, sans-serif",t.textBaseline="middle";const k=d+12;let A=w;i.datasets.forEach((T,R)=>{const F=i._resolveColor(T.color,R),O=T.label||"Series "+(R+1),W=7;t.beginPath(),t.roundRect(A,k-W/2,W,W,2),t.fillStyle=F,t.fill(),t.fillStyle=i.legendColor,t.textAlign="left",t.fillText(O,A+W+4,k),A+=t.measureText(O).width+W+16})}const _=4;if(i.showGridLines){t.setLineDash(i.gridLineDash||[]),t.lineWidth=i.gridLineWidth||1,t.strokeStyle=i.gridColor;for(let k=0;k<=_;k++)if(i.orientation==="horizontal"){const A=w+k/_*M;t.beginPath(),t.moveTo(A,C),t.lineTo(A,C+I),t.stroke()}else{const A=C+k/_*I;t.beginPath(),t.moveTo(w,A),t.lineTo(w+M,A),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 k=0;k<=_;k++)if(i.orientation==="horizontal"){const A=u+k/_*f,T=w+k/_*M;t.textAlign="center",t.fillText(A.toFixed(0),T,C+I+i.axisLabelFontSize)}else{const A=p-k/_*f,T=C+k/_*I;t.textAlign="right",t.fillText(A.toFixed(0),w-6,T)}}if(t.setLineDash([]),i.showXAxis&&(t.lineWidth=i.xAxisLineWidth||1,t.strokeStyle=i.xAxisColor,t.beginPath(),t.moveTo(w,C+I),t.lineTo(w+M,C+I),t.stroke()),i.showYAxis&&(t.lineWidth=i.yAxisLineWidth||1,t.strokeStyle=i.yAxisColor,t.beginPath(),t.moveTo(w,C),t.lineTo(w,C+I),t.stroke()),i.enableShadows&&(t.shadowColor=i.shadowColor),i.chartType==="stacked")if(i.orientation==="horizontal"){const k=I/m;for(let A=0;A<m;A++){const T=C+A*k+k/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[A]||"",w-5,T),i.enableShadows&&(t.shadowColor=i.shadowColor));let R=w;i.datasets.forEach((F,O)=>{const W=F.data[A]??0;if(W===0)return;const V=W/f*M,U=Math.min(i.barWidth*h+i.barGap,k-8),D=T-U/2,Y=R;R+=V;const ot=i._resolveColor(F.color,O);t.beginPath(),t.fillStyle=i._makeGradient(t,ot,Y,D,Y+V,D),i._drawRoundedBar(t,Y,D,V,U,O===h-1?i.barCornerRadius:0,!1),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?ot:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill()})}}else{const k=M/m;for(let A=0;A<m;A++){const T=w+A*k+k/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[A]||"",T,C+I+5),i.enableShadows&&(t.shadowColor=i.shadowColor));let R=C+I;i.datasets.forEach((F,O)=>{const W=F.data[A]??0;if(W===0)return;const V=W/f*I,U=Math.min(i.barWidth*h+i.barGap,k-8),D=T-U/2,Y=R-V;R-=V;const ot=i._resolveColor(F.color,O);t.beginPath(),t.fillStyle=i._makeGradient(t,ot,D,Y,D,Y+V),i._drawRoundedBar(t,D,Y,U,V,O===h-1?i.barCornerRadius:0,!0),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?ot:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill()})}}else if(i.orientation==="horizontal"){const k=I/m,A=h*i.barWidth+Math.max(0,(h-1)*i.barGap),T=w+(0-u)/f*M;for(let R=0;R<m;R++){const F=C+R*k+k/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[R]||"",w-5,F),i.enableShadows&&(t.shadowColor=i.shadowColor));const O=F-A/2;i.datasets.forEach((W,V)=>{const U=W.data[R]??0,D=Math.abs(U/f*M);if(D<1)return;const Y=O+V*(i.barWidth+i.barGap),ot=U>=0?T:T-D,J=i._resolveColor(W.color,V);t.beginPath(),t.fillStyle=i._makeGradient(t,J,ot,Y,ot+D,Y),i._drawRoundedBar(t,ot,Y,D,i.barWidth,i.barCornerRadius,!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(),i.showValueOnTop&&U!==0&&(t.font=(i.valueFontWeight||"bold")+" "+(i.valueFontSize||10)+"px Inter, sans-serif",t.textAlign=U>=0?"left":"right",t.textBaseline="middle",t.fillStyle=i.valueColor==="auto"?J:i.valueColor||"#fff",t.shadowColor="transparent",t.fillText(U.toString(),U>=0?ot+D+4:ot-4,Y+i.barWidth/2),i.enableShadows&&(t.shadowColor=i.shadowColor))})}}else{const k=M/m,A=h*i.barWidth+Math.max(0,(h-1)*i.barGap),T=C+I-(0-u)/f*I;for(let R=0;R<m;R++){const F=w+R*k+k/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[R]||"",F,C+I+5),i.enableShadows&&(t.shadowColor=i.shadowColor));const O=F-A/2;i.datasets.forEach((W,V)=>{const U=W.data[R]??0,D=Math.abs(U/f*I);if(D<1)return;const Y=O+V*(i.barWidth+i.barGap),ot=U>=0?T-D:T,J=i._resolveColor(W.color,V);t.beginPath(),t.fillStyle=i._makeGradient(t,J,Y,ot,Y,ot+D),i._drawRoundedBar(t,Y,ot,i.barWidth,D,i.barCornerRadius,!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(),i.showValueOnTop&&U!==0&&(t.font=(i.valueFontWeight||"bold")+" "+(i.valueFontSize||10)+"px Inter, sans-serif",t.textAlign="center",t.textBaseline=U>=0?"bottom":"top",t.fillStyle=i.valueColor==="auto"?J:i.valueColor||"#fff",t.shadowColor="transparent",t.fillText(U.toString(),Y+i.barWidth/2,U>=0?ot-4:ot+D+4),i.enableShadows&&(t.shadowColor=i.shadowColor))})}}t.restore()}renderPieChart(t,s){var c,b;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 S=this.inputs.get(e.dataInputId);if(S===void 0){const w=this.inputNameMap.get(e.dataInputId);w&&w.length>0&&(S=this.inputs.get(w[0]))}S&&Array.isArray(S)&&(i=S.map((w,C)=>{var M,I;return{id:`slice-${C}`,label:((M=i[C])==null?void 0:M.label)||`Item ${C+1}`,value:typeof w=="number"?w:0,color:((I=i[C])==null?void 0:I.color)||""}}))}const a={width:((c=s.geometry)==null?void 0:c.width)||180,height:((b=s.geometry)==null?void 0:b.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)",_resolveSliceColor:function(S,w){return S.color?S.color:n[w%n.length]},_hexToRgb:function(S){if(S.startsWith("rgba")||S.startsWith("rgb"))return S;const w=S.replace("#",""),C=parseInt(w.substring(0,2),16),M=parseInt(w.substring(2,4),16),I=parseInt(w.substring(4,6),16);return`rgba(${C},${M},${I},${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((S,w)=>S+(w.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=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,m=u>0?u*(a.legendFontSize+8)+10:0,h=l-m-16,f=Math.min(r-24,h)/2,v=0,g=-m/2;if(a.chartType==="rose"){const S=Math.max(...a.slices.map(M=>M.value||0)),w=Math.PI*2/a.slices.length,C=f>0?a.sliceGap/f:0;a.slices.forEach((M,I)=>{const _=M.value||0;if(_===0)return;const E=_/S*f,P=-Math.PI/2+I*w+C/2,L=P+w-C,k=a._resolveSliceColor(M,I);if(t.beginPath(),t.moveTo(v,g),t.arc(v,g,E,P,L),t.closePath(),t.fillStyle=k+"cc",t.fill(),t.strokeStyle=k,t.lineWidth=1.5,t.stroke(),a.showLabels){const A=P+(L-P)/2,T=v+E*.65*Math.cos(A),R=g+E*.65*Math.sin(A),F=Math.round(_/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(`${F}%`,T,R),t.restore()}})}else{const S=a.chartType==="pie"?0:a.innerRadius,w=f*Math.max(0,S),C=f>0?a.sliceGap/f:0;let M=-Math.PI/2;if(a.slices.forEach((I,_)=>{const E=I.value||0;if(E===0){M+=E/d*Math.PI*2;return}const P=E/d*Math.PI*2,L=M+C/2,k=M+P-C/2;if(k<=L){M+=P;return}const A=a._resolveSliceColor(I,_);if(t.beginPath(),t.fillStyle=A,w<=0?(t.moveTo(v,g),t.arc(v,g,f,L,k),t.lineTo(v,g)):(t.moveTo(v+f*Math.cos(L),g+f*Math.sin(L)),t.arc(v,g,f,L,k),t.arc(v,g,w,k,L,!0),t.closePath()),t.fill(),a.showLabels){const T=L+(k-L)/2,R=w+(f-w)/2,F=v+R*Math.cos(T),O=g+R*Math.sin(T),W=Math.round(E/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(`${W}%`,F,O),t.restore()}M+=P}),a.chartType==="donut"&&a.showCenterText&&w>14){const I=Math.round(d),_=Math.min(Math.floor(w*.52),20),E=Math.min(Math.floor(w*.26),10);t.textAlign="center",t.textBaseline="middle",t.font=`bold ${_}px Inter, sans-serif`,t.fillStyle=a.centerTextColor,t.fillText(I.toString(),v,g-E*.5),t.font=`${E}px Inter, sans-serif`,t.fillStyle=a.centerLabelColor,t.fillText(a.centerLabel,v,g+_*.6)}}if(a.showLegend&&a.slices.length>0){t.font=`${a.legendFontSize}px Inter, sans-serif`;const S=2,w=r/S,C=a.legendFontSize+8,M=l/2-m+10,I=-r/2+10;a.slices.forEach((_,E)=>{const P=E%S,L=Math.floor(E/S),k=I+P*w,A=M+L*C,T=a._resolveSliceColor(_,E),R=7;t.beginPath(),t.roundRect(k,A-R/2,R,R,2),t.fillStyle=T,t.fill(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=a.legendColor;const F=Math.round((_.value||0)/d*100),O=`${_.label||"Item"} ${F}%`,W=w-R-20;let V=O;for(;t.measureText(V).width>W&&V.length>4;)V=V.slice(0,-4)+"…";t.fillText(V,k+R+4,A)})}t.restore()}renderJoystick(t,s){var v,g,c,b,S,w,C,M,I,_,E,P;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.width)!==void 0?o.width:((v=s.geometry)==null?void 0:v.width)??s.width??100,n=(o==null?void 0:o.height)!==void 0?o.height:((g=s.geometry)==null?void 0:g.height)??s.height??100,i=Math.min(e,n)*(((c=s.style)==null?void 0:c.baseSize)??.45),a=Math.min(e,n)*(((b=s.style)==null?void 0:b.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 u=t.globalAlpha;if(t.globalAlpha=u*(((S=s.style)==null?void 0:S.baseOpacity)??1),t.beginPath(),s.boundsShape==="square"){const L=s.joystickType==="2D"?12:18;t.roundRect(-i,-i,i*2,i*2,L)}else t.arc(0,0,i,0,Math.PI*2);t.fillStyle=((w=s.style)==null?void 0:w.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 m=s.overflowHandle?i:Math.max(.1,i-a);let h=0,f=0;s.joystickType==="2D"?(h=r*m,f=l*m):s.joystickType==="1D_X"?(h=r*m,f=0):s.joystickType==="1D_Y"&&(h=0,f=l*m),t.globalAlpha=u*(((I=s.style)==null?void 0:I.handleOpacity)??1),t.beginPath(),t.arc(h,f,a,0,Math.PI*2),t.fillStyle=((_=s.style)==null?void 0:_.handleColor)||"#3b82f6",t.fill(),(E=s.style)!=null&&E.handleBorderWidth?(t.lineWidth=s.style.handleBorderWidth,t.strokeStyle=s.style.handleBorderColor||"rgba(255,255,255,0.5)",t.stroke()):(t.lineWidth=1,t.strokeStyle=((P=s.style)==null?void 0:P.handleBorderColor)||"rgba(255,255,255,0.5)",t.stroke()),t.globalAlpha=u,t.restore()}getRadioGroupItemIndexAtPointer(t,s,o){var I,_;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:((_=t.geometry)==null?void 0:_.height)||100,l=e.orientation||"vertical",d=e.itemGap!==void 0?e.itemGap:16,p=e.fontSize||14,u=this.getWorldTransform(t.id),m=s-u.x,h=o-u.y,f=-u.rotation*(Math.PI/180),v=Math.cos(f),g=Math.sin(f),c=m*v-h*g,b=m*g+h*v,w=8*2,C=-a/2,M=-r/2;if(l==="vertical"){const E=Math.max(w,p)+d;for(let P=0;P<i.length;P++){const L=M+P*E;if(c>=C&&c<=C+a&&b>=L&&b<=L+E)return P}}else{let E=C;for(let P=0;P<i.length;P++){const k=i[P].length*8,A=w+6+k+d;if(c>=E&&c<=E+A&&b>=M&&b<=M+r)return P;E+=A}}return null}renderLineGraph(t,s,o,e){let n=s.datasets||[];if((!n||n.length===0)&&(s.data||s.graphData)&&(n=[{id:"line-1",label:"Series 1",data:s.data||s.graphData||[],lineColor:s.lineColor||"#3b82f6",lineWidth:s.lineWidth||2,showArea:s.showArea||!1,areaColor:s.areaColor||"rgba(139, 92, 246, 0.3)",smoothing:s.smoothing||!1,showPoints:s.showPoints!==void 0?s.showPoints:!0,pointSize:s.pointSize||6,pointFill:s.pointFill||"#ffffff",pointStrokeColor:s.pointStrokeColor||s.lineColor||"#3b82f6",pointStrokeWidth:s.pointStrokeWidth||2}]),!n||n.length===0||!n.some(f=>f.data&&f.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 i=1/0,a=-1/0,r=0;if(n.forEach(f=>{let v=f.data;if(f.isVarEnabled&&f.inputId){let g=this.inputs.get(f.inputId);if(g===void 0){const c=this.inputNameMap.get(f.inputId);c&&c.length>0&&(g=this.inputs.get(c[0]))}g&&Array.isArray(g)&&(v=g)}if(v&&v.length>0){const g=v.filter(c=>typeof c=="number"&&!isNaN(c));g.length>0&&(i=Math.min(i,...g),a=Math.max(a,...g),r=Math.max(r,v.length))}f._resolvedData=v}),r<2)return;const l=a-i,d=o/(r-1),p=f=>{const v=l===0?.5:(f-i)/l;return e/2-v*e},u=f=>f*d-o/2,m=s.axisColor||"#333333";if(s.showXAxis&&(t.beginPath(),t.strokeStyle=s.xAxisColor||m,t.lineWidth=1,t.moveTo(-o/2,e/2),t.lineTo(o/2,e/2),t.stroke()),s.showYAxis&&(t.beginPath(),t.strokeStyle=s.yAxisColor||m,t.lineWidth=1,t.moveTo(-o/2,-e/2),t.lineTo(-o/2,e/2),t.stroke()),t.fillStyle=s.axisLabelColor||"#333333",t.font=`${s.axisLabelFontSize||10}px Inter, sans-serif`,s.showXLabels){t.textAlign="center",t.textBaseline="top";for(let f=0;f<r;f++){const v=u(f);t.fillText(`${f+1}`,v,e/2+5)}}if(s.showYLabels){t.textAlign="right",t.textBaseline="middle";const f=-o/2-5,v=(a+i)/2;t.fillText(a.toFixed(1),f,p(a)),t.fillText(v.toFixed(1),f,p(v)),t.fillText(i.toFixed(1),f,p(i))}const h=10;if(n.forEach(f=>{const v=f._resolvedData;if(!(!v||v.length<2)){if(f.showArea){if(t.beginPath(),t.moveTo(u(0),e/2),t.lineTo(u(0),p(v[0])),f.smoothing&&v.length>2)for(let c=0;c<v.length-1;c++){const b=v[c===0?c:c-1],S=v[c],w=v[c+1],C=v[c+1===v.length-1?c+1:c+2];for(let M=1;M<=h;M++){const I=M/h,_=this._catmullRom(b,S,w,C,I);t.lineTo(u(c+I),p(_))}}else for(let c=1;c<v.length;c++)t.lineTo(u(c),p(v[c]));t.lineTo(u(v.length-1),e/2),t.closePath();const g=t.globalAlpha;t.globalAlpha=g*(s.areaOpacity??.3),t.fillStyle=f.areaColor||"rgba(139, 92, 246, 0.2)",t.fill(),t.globalAlpha=g}if(t.beginPath(),t.strokeStyle=f.lineColor||"#3b82f6",t.lineWidth=f.lineWidth||2,t.lineJoin="round",t.lineCap="round",t.moveTo(u(0),p(v[0])),f.smoothing&&v.length>2)for(let g=0;g<v.length-1;g++){const c=v[g===0?g:g-1],b=v[g],S=v[g+1],w=v[g+1===v.length-1?g+1:g+2];for(let C=1;C<=h;C++){const M=C/h,I=this._catmullRom(c,b,S,w,M);t.lineTo(u(g+M),p(I))}}else for(let g=1;g<v.length;g++)t.lineTo(u(g),p(v[g]));t.stroke(),f.showPoints&&v.forEach((g,c)=>{const b=u(c),S=p(g);t.beginPath(),t.arc(b,S,(f.pointSize||6)/2,0,Math.PI*2),t.fillStyle=f.pointFill||"#ffffff",t.fill(),t.strokeStyle=f.pointStrokeColor||f.lineColor||"#3b82f6",t.lineWidth=f.pointStrokeWidth||1,t.stroke()})}}),s.showLegend&&n.length>0){const f=o/2-10;let v=-e/2+15;const g=s.legendFontSize||10,c=g+5;t.font=`${g}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="alphabetic",n.forEach(b=>{const w=b.label||"Series",C=t.measureText(w).width;t.beginPath(),t.rect(f-C-8-5,v-(8/2+2),8,8),t.fillStyle=b.lineColor||"#3b82f6",t.fill(),t.fillStyle=s.legendColor||"#333333",t.fillText(w,f,v),v+=c})}}_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,d=(((i=(n=this.artboard)==null?void 0:n.tokens)==null?void 0:i.colors)||{})[r]||r;return t.fillStyle=d,d}if((s.type==="LinearGradient"||s.type==="RadialGradient"||s.type==="AngularGradient"||s.type==="DiamondGradient")&&s.stops){const r=(l,d=100)=>{var S,w;const u=(((w=(S=this.artboard)==null?void 0:S.tokens)==null?void 0:w.colors)||{})[l]||l,m=this.normalizeOpacity(s.opacity??100),f=this.normalizeOpacity(d)*m;if(f>=1&&u.startsWith("#"))return u;const v=u.startsWith("#")?u.replace("#",""):"ffffff",g=parseInt(v.substring(0,2),16),c=parseInt(v.substring(2,4),16),b=parseInt(v.substring(4,6),16);return`rgba(${g}, ${c}, ${b}, ${f})`};if(s.type==="LinearGradient"){let l=0,d=-e/2,p=0,u=e/2;if(s.angle!==void 0&&(!s.start||!s.end)){const h=(s.angle-90)*Math.PI/180,f=Math.max(o,e)/2;l=Math.cos(h)*-f,d=Math.sin(h)*-f,p=Math.cos(h)*f,u=Math.sin(h)*f}else if(s.start||s.end){const h=(f,v,g)=>Array.isArray(f)?f[v]??.5:f&&typeof f=="object"?f[g]??.5:.5;l=h(s.start,0,"x")*o-o/2,d=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(d-u)<.001&&(l=0,d=-e/2,p=0,u=e/2);const m=t.createLinearGradient(l,d,p,u);if(s.stops.forEach(h=>{const f=h.offset!==void 0?h.offset:h.pos!==void 0?h.pos:h.position!==void 0?h.position:0,v=r(h.color||"#000000",h.opacity??100);m.addColorStop(Math.max(0,Math.min(1,f)),v)}),s.gradientTransform&&m.setTransform){const[h,f,v,g,c,b]=s.gradientTransform;m.setTransform({a:h,b:f,c:v,d:g,e:c,f:b})}return m}else if(s.type==="RadialGradient"){const l=(h,f,v)=>Array.isArray(h)?h[f]??.5:h&&typeof h=="object"?h[v]??.5:.5,d=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),m=t.createRadialGradient(d,p,0,d,p,u);if(s.stops.forEach(h=>{const f=h.offset!==void 0?h.offset:h.pos!==void 0?h.pos:h.position!==void 0?h.position:0,v=r(h.color||"#000000",h.opacity??100);m.addColorStop(Math.max(0,Math.min(1,f)),v)}),s.gradientTransform&&m.setTransform){const[h,f,v,g,c,b]=s.gradientTransform;m.setTransform({a:h,b:f,c:v,d:g,e:c,f:b})}return m}else if(s.type==="AngularGradient"){const l=(h,f,v)=>Array.isArray(h)?h[f]??.5:h&&typeof h=="object"?h[v]??.5:.5,d=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),m=(a=t.createConicGradient)==null?void 0:a.call(t,u,d,p);if(m){if(s.stops.forEach(h=>{const f=h.offset!==void 0?h.offset:h.pos!==void 0?h.pos:h.position!==void 0?h.position:0,v=r(h.color||"#000000",h.opacity??100);m.addColorStop(Math.max(0,Math.min(1,f)),v)}),s.gradientTransform&&m.setTransform){const[h,f,v,g,c,b]=s.gradientTransform;m.setTransform({a:h,b:f,c:v,d:g,e:c,f:b})}return m}}else if(s.type==="DiamondGradient"){const l=(h,f,v)=>Array.isArray(h)?h[f]??.5:h&&typeof h=="object"?h[v]??.5:.5,d=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(d,p),t.rotate(Math.PI/4);const m=t.createRadialGradient(0,0,0,0,0,u);if(s.stops.forEach(h=>{const f=h.offset!==void 0?h.offset:h.pos!==void 0?h.pos:h.position!==void 0?h.position:0,v=r(h.color||"#000000",h.opacity??100);m.addColorStop(Math.max(0,Math.min(1,f)),v)}),s.gradientTransform&&m.setTransform){const[h,f,v,g,c,b]=s.gradientTransform;m.setTransform({a:h,b:f,c:v,d:g,e:c,f:b})}return t.scale(1/Math.SQRT2,1/Math.SQRT2),t.fillStyle=m,t.restore(),m}}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,u=s.scaleY??1,m=s.offsetX??0,h=s.offsetY??0,f=s.rotation??0;d.translateSelf(m,h),d.rotateSelf(f),d.scaleSelf(p,u),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 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),d=Math.min(Math.max(0,d),u),p=Math.min(Math.max(0,p),u),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 T,R,F,O,W,V,U,D,Y,ot;const o=this.objectStates.get(s.id)||{},e=o.options||s.options||{},n=o.width!==void 0?o.width:((T=s.geometry)==null?void 0:T.width)||200,i=o.height!==void 0?o.height:((R=s.geometry)==null?void 0:R.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??((F=s.geometry)==null?void 0:F.cornerRadius)??((O=s.geometry)==null?void 0:O.corner_radius)??0,d=e.orientation||"vertical",p=this.getResolvedListViewItems(s,e),u=e.itemGap??10,m=e.itemHeight??50,h=e.itemWidth??200,f=e.scrollOffset??0,v=e.padding??0,g=e.glassEffect!==!1,c=e.accentColor||"#3b82f6",b=e.itemTextColor||"#333333",S=e.itemBackgroundColor||"#ffffff",w=e.hoveredIndex??null,C=e.activeItemIndex??null,M=e.glowIntensity??0,I=e.glowColor||"#3b82f6",_=typeof I=="string"?I:I.color||((V=(W=I.stops)==null?void 0:W[0])==null?void 0:V.color)||"#3b82f6",E=e.opacity!==void 0?e.opacity:s.opacity!==void 0?s.opacity:1;if(t.save(),t.globalAlpha*=E,M>0){const J=t.getTransform(),at=Math.sqrt(J.a*J.a+J.b*J.b)||1;t.shadowColor=_,t.shadowBlur=M*2*at,t.shadowOffsetX=0,t.shadowOffsetY=0}if(g){const J=e.listBackgroundColor||"rgba(31, 41, 55, 0.4)",at=this.createCanvasFill(t,J,n,i);t.fillStyle=at||"rgba(31, 41, 55, 0.4)",t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)||t.fill();const it=t.createLinearGradient(a,r,a+n,r+i);it.addColorStop(0,"rgba(255, 255, 255, 0.15)"),it.addColorStop(.5,"rgba(255, 255, 255, 0.08)"),it.addColorStop(1,"rgba(255, 255, 255, 0.03)"),t.fillStyle=it,t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)||t.fill();const X=e.borderWidth??0;if(X>0&&e.borderColor&&e.borderColor!=="transparent"){const ct=this.createCanvasFill(t,e.borderColor,n,i);t.strokeStyle=ct||"rgba(255, 255, 255, 0.25)",t.lineWidth=X}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 J=e.backgroundColor&&e.backgroundColor!=="transparent"?e.backgroundColor:e.listBackgroundColor||"transparent",at=this.createCanvasFill(t,J,n,i);if(at){t.fillStyle=at,t.beginPath();const it=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l);t.fill()}const j=e.borderWidth??0;if(j>0){const it=this.createCanvasFill(t,e.borderColor||"#cccccc",n,i);t.strokeStyle=it||"#cccccc",t.lineWidth=j,t.beginPath();const B=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l);t.stroke()}}t.shadowBlur=0;const P=e.clipContent!==!1&&e.listLayout!=="circular";if(P)if(t.save(),t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,l)&&e.containerShape==="custom")try{const at=new Path2D(e.containerPath);t.translate(a,r),t.scale(n/100,i/100),t.clip(at),t.scale(100/n,100/i),t.translate(-a,-r)}catch{}else t.clip();const L=typeof v=="number"?v:d==="vertical"?v[0]:v[3];let k=(d==="vertical"?r:a)+f+L;if(t.textBaseline="middle",p.forEach((J,at)=>{var ft,Bt,Ot,Pt;const j=e.listLayout||"linear",it=j==="circular"?h:d==="vertical"?n:h,B=j==="circular"||d==="vertical"?m:i;let X=0,N=0,ct=0;if(j==="circular"){const vt=p.length||1,Yt=Math.PI*2/vt,zt=e.circularStartAngle||0,Gt=e.circularRadius||100,Dt=f*.01+zt*Math.PI/180,te=at*Yt+Dt,ie=a+n/2,ce=r+i/2;X=ie+Math.cos(te)*Gt-it/2,N=ce+Math.sin(te)*Gt-B/2,ct=te+(e.itemRotation||0)*Math.PI/180}else X=d==="vertical"?a:k,N=d==="vertical"?k:r,ct=(e.itemRotation||0)*Math.PI/180;const Mt=w===at,bt=C===at,wt=e.itemBorderWidth??0;t.save(),ct!==0&&(t.translate(X+it/2,N+B/2),t.rotate(ct),t.translate(-(X+it/2),-(N+B/2)));const gt=Mt?((ft=e.hoverStyle)==null?void 0:ft.scale)??1:bt?((Bt=e.activeStyle)==null?void 0:Bt.scale)??1:1;if(gt!==1&&(t.translate(X+it/2,N+B/2),t.scale(gt,gt),t.translate(-(X+it/2),-(N+B/2))),bt){const vt=((Ot=e.activeStyle)==null?void 0:Ot.itemBackgroundColor)||e.activeBackgroundColor||(g?"rgba(255, 255, 255, 0.15)":"rgba(0, 0, 0, 0.1)"),Yt=this.createCanvasFill(t,vt,it,B);t.fillStyle=Yt||(typeof vt=="string"?vt:"transparent"),t.beginPath(),this.drawCustomShape(t,e.activeItemShape||e.itemShape||"rectangle",e.activeItemShape==="custom"?e.activeItemPath||"":e.itemPath||"",X,N,it,B,e.itemCornerRadius??0)||t.fill()}else if(Mt){const vt=((Pt=e.hoverStyle)==null?void 0:Pt.itemBackgroundColor)||e.hoverBackgroundColor||(g?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)"),Yt=this.createCanvasFill(t,vt,it,B);t.fillStyle=Yt||(typeof vt=="string"?vt:"transparent"),t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",X,N,it,B,e.itemCornerRadius??0)||t.fill()}else if(S!=="transparent"){const vt=this.createCanvasFill(t,S,it,B);t.fillStyle=vt||(typeof S=="string"?S:"transparent"),t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",X,N,it,B,e.itemCornerRadius??0)||t.fill()}if(wt>0&&e.itemBorderColor&&e.itemBorderColor!=="transparent"){const vt=this.createCanvasFill(t,e.itemBorderColor,it,B);t.strokeStyle=vt||(typeof e.itemBorderColor=="string"?e.itemBorderColor:"#cccccc"),t.lineWidth=wt,t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",X,N,it,B,e.itemCornerRadius??0)||t.stroke()}if(bt){const vt=this.createCanvasFill(t,c,d==="vertical"?3:it,d==="vertical"?B:3);t.fillStyle=vt||c,d==="vertical"?t.fillRect(X,N,3,B):t.fillRect(X,N+B-3,it,3)}const It=bt?"#ffffff":g?"rgba(255, 255, 255, 0.9)":b;t.fillStyle=It,t.font=bt||Mt?"600 14px Inter, sans-serif":"400 14px Inter, sans-serif";const ut=typeof J=="string"?J:(J==null?void 0:J.label)||`Item ${at+1}`,Lt=X+(d==="vertical"?16:it/2),Wt=N+B/2;d==="horizontal"||j==="circular"?t.textAlign="center":t.textAlign="left";const q=j==="circular"?X+it/2:Lt;t.fillText(ut,q,Wt),t.restore(),t.beginPath(),k+=(d==="vertical"?m:h)+u}),P&&t.restore(),e.showScrollbar!==!1){const J=typeof v=="number"?v:d==="vertical"?v[0]:v[3],j=(p.length||0)*(d==="vertical"?m:h)+Math.max(0,(p.length||0)-1)*u+J*2,it=d==="vertical"?i:n,B=e.listLayout||"linear",X=e.containerShape==="circle"||B==="circular",N=e.scrollbarColor||"rgba(255,255,255,0.3)";let ct=typeof N=="object"?N.color||((D=(U=N.stops)==null?void 0:U[0])==null?void 0:D.color)||"rgba(255,255,255,0.3)":N;const Mt=((ot=(Y=this.artboard)==null?void 0:Y.tokens)==null?void 0:ot.colors)||{};Mt[ct]&&(ct=Mt[ct]);const bt=e.scrollbarWidth||2;if(t.save(),X){const wt=Math.min(n,i)/2-bt/2-2,gt=a+n/2,It=r+i/2;if(t.strokeStyle=ct,t.lineWidth=bt,t.lineCap="round",t.beginPath(),B==="circular"){const ut=Math.PI/4,Lt=-(f*.01)-Math.PI/2;t.arc(gt,It,wt,Lt,Lt+ut)}else{const ut=Math.PI/2,Lt=j>0?Math.min(1,it/j):1,Wt=ut*Lt,q=j>0?-f/j*ut:0,Bt=-Math.PI/4+q;t.arc(gt,It,wt,Bt,Bt+Wt)}t.stroke()}else{let wt=it,gt=0;if(j>it){const It=it/j;wt=Math.max(16,it*It);const ut=it-wt,Lt=j-it;gt=Lt>0?Math.max(0,Math.min(ut,-f/Lt*ut)):0}if(t.fillStyle=ct,d==="vertical"){const It=a+n-bt-2,ut=r+gt,Lt=bt,Wt=wt;if(bt>2){t.beginPath();const q=Math.min(bt/2,wt/2);if(t.roundRect)try{t.roundRect(It,ut,Lt,Wt,q),t.fill()}catch{t.fillRect(It,ut,Lt,Wt)}else t.fillRect(It,ut,Lt,Wt)}else t.fillRect(It,ut,Lt,Wt)}else{const It=a+gt,ut=r+i-bt-2,Lt=wt,Wt=bt;if(bt>2){t.beginPath();const q=Math.min(bt/2,wt/2);if(t.roundRect)try{t.roundRect(It,ut,Lt,Wt,q),t.fill()}catch{t.fillRect(It,ut,Lt,Wt)}else t.fillRect(It,ut,Lt,Wt)}else t.fillRect(It,ut,Lt,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 S,w,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,d=o.itemHeight??50,p=o.itemWidth??200,u=(s==null?void 0:s.width)!==void 0?s.width:((S=t.geometry)==null?void 0:S.width)||200,m=(s==null?void 0:s.height)!==void 0?s.height:((w=t.geometry)==null?void 0:w.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,v=(r.length||0)*(e==="vertical"?d:p)+Math.max(0,(r.length||0)-1)*l+h*2,g=e==="vertical"?m:u,c=Math.max(0,v-g);if(this.draggingListViewIsScrollbar&&o.listLayout!=="circular"){const I=v>0?g/v:1,_=Math.max(16,g*I),E=Math.max(1,g-_),P=c>0?c/E:1;e==="vertical"?a-=i*P:a-=n*P}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,O;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:((F=t.geometry)==null?void 0:F.width)||200,r=(e==null?void 0:e.height)!==void 0?e.height:((O=t.geometry)==null?void 0:O.height)||300,l=n.orientation||"vertical",d=n.itemGap??10,p=n.itemHeight??50,u=n.itemWidth??200,m=n.scrollOffset??0,h=n.padding??0,f=this.getWorldTransform(t.id),v=s-f.x,g=o-f.y,c=-f.rotation*(Math.PI/180),b=Math.cos(c),S=Math.sin(c),w=v*b-g*S,C=v*S+g*b,M=-a/2,I=-r/2,_=typeof h=="number"?h:l==="vertical"?h[0]:h[3];let E=(l==="vertical"?I:M)+m+_;const P=n.listLayout||"linear",L=i.length||1,k=Math.PI*2/L,A=n.circularStartAngle||0,T=n.circularRadius||100,R=m*.01+A*Math.PI/180;for(let W=0;W<i.length;W++){const V=P==="circular"?u:l==="vertical"?a:u,U=P==="circular"||l==="vertical"?p:r;let D=0,Y=0,ot=0;if(P==="circular"){const J=W*k+R,at=M+a/2,j=I+r/2;D=at+Math.cos(J)*T-V/2,Y=j+Math.sin(J)*T-U/2,ot=J+(n.itemRotation||0)*Math.PI/180}else D=l==="vertical"?M:E,Y=l==="vertical"?E:I,ot=(n.itemRotation||0)*Math.PI/180;if(ot!==0){const J=D+V/2,at=Y+U/2,j=w-J,it=C-at,B=-ot,X=j*Math.cos(B)-it*Math.sin(B)+J,N=j*Math.sin(B)+it*Math.cos(B)+at;if(X>=D&&X<=D+V&&N>=Y&&N<=Y+U)return W}else if(w>=D&&w<=D+V&&C>=Y&&C<=Y+U)return W;E+=(l==="vertical"?p:u)+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 u,m,h,f,v,g,c,b,S,w,C,M,I,_,E,P,L,k,A,T,R,F,O,W,V,U,D,Y,ot,J,at,j,it,B,X,N,ct,Mt,bt,wt,gt,It,ut,Lt,Wt,q,ft,Bt,Ot,Pt,vt,Yt,zt,Gt,Dt,te,ie,ce,ve,_e,ge,Ee,Zt,Me,Re,Ie,de,me,Ae,he,mt,rt,z,K,G,x,Q,H,lt,kt,At,Ht,Ut,qt,$,dt,Rt,Nt,st,yt,St,ee,Ct,Vt,Tt,Xt,Ft,le,fe,Oe,jt,oe,ne,Fe,Be,xe,We,De,Ye,Ge,se,ue,Se,Xe,Ne,ke,Ce,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,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===tt.Proximity){const Z=((u=i.settings)==null?void 0:u.radius)||300,nt=((m=i.settings)==null?void 0:m.falloff)||"smooth";let et=0;p<Z&&(nt==="linear"?et=1-p/Z:et=Math.pow(1-p/Z,2)),i.sensors.forEach(pt=>{this.applyBehaviorSensor(n,pt,et,t,i.settings,e,l,d,p)})}else if(i.type===tt.Magnetic){const Z=((h=i.settings)==null?void 0:h.radius)||400,nt=((f=i.settings)==null?void 0:f.strength)||.5;if(p<Z&&p>5){const et=1-p/Z,pt=l*et*nt,$t=d*et*nt;n.x-=pt*t*10,n.y-=$t*t*10}}else if(i.type===tt.Repel){const Z=((v=i.settings)==null?void 0:v.radius)||300,nt=((g=i.settings)==null?void 0:g.strength)||1;if(p<Z){const et=Math.pow(1-p/Z,2);n.x+=l/(p||1)*et*60*nt*t*5,n.y+=d/(p||1)*et*60*nt*t*5}}else if(i.type===tt.Orbit){const Z=((c=i.settings)==null?void 0:c.speed)||1,nt=((b=i.settings)==null?void 0:b.radius)||30,et=this.currentTime*Z*Math.PI*2;n.x+=Math.cos(et)*nt*t*5,n.y+=Math.sin(et)*nt*t*5,n.rotation+=2*t*5}else if(i.type===tt.Vortex){const Z=((S=i.settings)==null?void 0:S.radius)||400,nt=((w=i.settings)==null?void 0:w.speed)||2,et=((C=i.settings)==null?void 0:C.strength)||1;if(p<Z){const pt=Math.pow(1-p/Z,1.5),$t=this.currentTime*nt*Math.PI*2,xt=Math.cos($t)*30-l*.4,Jt=Math.sin($t)*30-d*.4;n.x+=xt*pt*et*t*5,n.y+=Jt*pt*et*t*5,n.rotation+=5*pt*et*t*5,n.scale_x*=1-pt*.1*et*t,n.scale_y*=1-pt*.1*et*t}}else if(i.type===tt.Fluid){const Z=((M=i.settings)==null?void 0:M.radius)||300,nt=((I=i.settings)==null?void 0:I.strength)||1;if(p<Z){const et=Math.pow(1-p/Z,1.2),pt=l/(p||1)*et*1.2*nt,$t=d/(p||1)*et*1.2*nt;n.x+=pt*10*t*5,n.y+=$t*10*t*5,n.scale_x*=1+et*.3*nt*t,n.scale_y*=1+et*.3*nt*t}}else if(i.type===tt.Elastic){const Z=((_=i.settings)==null?void 0:_.radius)||300,nt=((E=i.settings)==null?void 0:E.strength)||1;if(p<Z){const et=1-p/Z;n.scale_x*=1+et*.4*nt*t,n.scale_y*=1+et*.4*nt*t}}else if(i.type===tt.Holographic){const Z=n.x-this.canvasWidth/2,nt=n.y-this.canvasHeight/2,et=((P=i.settings)==null?void 0:P.factor)||25;if(n.x-=Z/1e3*et*t*5,n.y-=nt/1e3*et*t*5,n.style){const pt=1-Math.min(1,p/400);n.style.exposure=(n.style.exposure||1)+pt*.5*t}}else if(i.type===tt.Sticky){const Z=((L=i.settings)==null?void 0:L.radius)||80,nt=((k=i.settings)==null?void 0:k.strength)||1;if(p<Z){const et=Math.pow(1-p/Z,2);n.x-=l*et*nt*t*10,n.y-=d*et*nt*t*10,n.scale_x*=1-et*.1*nt*t,n.scale_y*=1-et*.1*nt*t}}else if(i.type===tt.Dilation){const Z=((A=i.settings)==null?void 0:A.size)||120,nt=((T=i.settings)==null?void 0:T.strength)||1;if(p<Z){const et=1-p/Z;n.scale_x*=1+et*.5*nt*t,n.scale_y*=1+et*.5*nt*t}}else if(i.type===tt.Parallax){const Z=((R=i.settings)==null?void 0:R.factor)||15,nt=((F=i.settings)==null?void 0:F.strength)||1,et=this.canvasWidth/2,pt=this.canvasHeight/2,$t=this._lastPointerPos||{x:et,y:pt},xt=($t.x-et)/et,Jt=($t.y-pt)/pt,pe=(((O=e.transform)==null?void 0:O.x)??0)+xt*Z*nt,Te=(((W=e.transform)==null?void 0:W.y)??0)+Jt*Z*nt,$e=(((V=e.transform)==null?void 0:V.rotate_x)??0)-Jt*Z*1.5*nt,ye=(((U=e.transform)==null?void 0:U.rotate_y)??0)+xt*Z*1.5*nt,Le=Math.min(1,10*t);n.x=this.lerp(n.x??((D=e.transform)==null?void 0:D.x)??0,pe,Le),n.y=this.lerp(n.y??((Y=e.transform)==null?void 0:Y.y)??0,Te,Le),n.rotate_x=this.lerp(n.rotate_x??((ot=e.transform)==null?void 0:ot.rotate_x)??0,$e,Le),n.rotate_y=this.lerp(n.rotate_y??((J=e.transform)==null?void 0:J.rotate_y)??0,ye,Le)}else if(i.type===tt.Fold){if(p<300){const Z=1-p/300,nt=(l>0?-1:1)*Z*10,et=1-Z*.1,pt=d/300*Z*20,$t=-(l/300)*Z*20,xt=Math.min(1,10*t);n.skew_x=this.lerp(n.skew_x??((at=e.transform)==null?void 0:at.skew_x)??0,nt,xt),n.scale_y=this.lerp(n.scale_y??((j=e.transform)==null?void 0:j.scale_y)??1,(((it=e.transform)==null?void 0:it.scale_y)??1)*et,xt),n.rotate_x=this.lerp(n.rotate_x??((B=e.transform)==null?void 0:B.rotate_x)??0,pt,xt),n.rotate_y=this.lerp(n.rotate_y??((X=e.transform)==null?void 0:X.rotate_y)??0,$t,xt),n.style=n.style||{...e.style},n.style.artEffect={enabled:!0,type:"fold_overlay",intensity:((N=i.settings)==null?void 0:N.opacity)??.5}}}else if(i.type===tt.Crumple){if(p<300){const Z=1-p/300,nt=Z*(Math.random()-.5)*5,et=Z*(Math.random()-.5)*.05,pt=Math.min(1,15*t);n.skew_x=this.lerp(n.skew_x??((ct=e.transform)==null?void 0:ct.skew_x)??0,nt,pt),n.scale_x=this.lerp(n.scale_x??((Mt=e.transform)==null?void 0:Mt.scale_x)??1,(((bt=e.transform)==null?void 0:bt.scale_x)??1)*(1+et),pt),n.scale_y=this.lerp(n.scale_y??((wt=e.transform)==null?void 0:wt.scale_y)??1,(((gt=e.transform)==null?void 0:gt.scale_y)??1)*(1+et),pt),n.style=n.style||{...e.style},n.style.artEffect={enabled:!0,type:"crumple_overlay",intensity:((It=i.settings)==null?void 0:It.intensity)??1,scale:((ut=i.settings)==null?void 0:ut.scale)??2}}}else if(i.type===tt.Squash){const Z=((Lt=i.settings)==null?void 0:Lt.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,(((q=e.transform)==null?void 0:q.scale_x)??1)*(1+(1-Z)*.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,((Bt=e.transform)==null?void 0:Bt.scale_x)??1,.2))}else if(i.type===tt.TextCounter){const Z=((Ot=i.settings)==null?void 0:Ot.duration)||2,nt=((Pt=i.settings)==null?void 0:Pt.from)||0,et=((vt=i.settings)==null?void 0:vt.to)||100;i._runtimeStart===void 0&&(i._runtimeStart=this.currentTime);const pt=this.currentTime-i._runtimeStart,$t=Math.min(1,pt/Z),xt=Math.floor(nt+(et-nt)*$t);if(((Yt=e.geometry)==null?void 0:Yt.type)==="Text"){const Jt=((zt=i.settings)==null?void 0:zt.prefix)||"",pe=((Gt=i.settings)==null?void 0:Gt.suffix)||"";n.geometry||(n.geometry={...e.geometry}),n.geometry.text=`${Jt}${xt}${pe}`}}else if(i.type===tt.Spotlight){const Z=((Dt=i.settings)==null?void 0:Dt.radius)||250,nt=((te=i.settings)==null?void 0:te.strength)||1.5;if(p<Z){const et=Math.pow(1-p/Z,2);n.style||(n.style={...e.style}),n.style.adjustments||(n.style.adjustments={...(ie=e.style)==null?void 0:ie.adjustments}),n.style.adjustments.exposure=(((ve=(ce=e.style)==null?void 0:ce.adjustments)==null?void 0:ve.exposure)||0)+et*nt*50}else(_e=n.style)!=null&&_e.adjustments&&(n.style.adjustments.exposure=this.lerp(n.style.adjustments.exposure||0,((Ee=(ge=e.style)==null?void 0:ge.adjustments)==null?void 0:Ee.exposure)||0,.1))}else if(i.type===tt.Noise||i.type===tt.Float){const Z=(((Zt=i.settings)==null?void 0:Zt.frequency)||((Me=i.settings)==null?void 0:Me.speed)||1)*.002,nt=(((Re=i.settings)==null?void 0:Re.amplitude)||((Ie=i.settings)==null?void 0:Ie.range)||50)*(((de=i.settings)==null?void 0:de.strength)||1),et=Date.now();n.x+=Math.sin(et*Z)*nt*t,n.y+=Math.cos(et*Z*.8)*nt*t,n.rotation+=Math.sin(et*Z*.5)*5*t}else if(i.type===tt.Pulse){const Z=(((me=i.settings)==null?void 0:me.speed)||1)*.005,nt=(((Ae=i.settings)==null?void 0:Ae.scale)||1.2)-1,et=Math.sin(Date.now()*Z),pt=((he=i.settings)==null?void 0:he.strength)||1;n.scale_x*=1+et*nt*pt*t,n.scale_y*=1+et*nt*pt*t,n.style&&(n.style.exposure=(n.style.exposure||1)+Math.max(0,et)*.1*pt*t)}else if(i.type===tt.Draggable){if(!this.draggingBehaviors.has(e.id)){const nt=((mt=i.settings)==null?void 0:mt.radius)||150;if(p<nt){const et=((rt=i.settings)==null?void 0:rt.strength)||1,pt=Math.max(0,1-p/nt);this.applyBehaviorSensor(n,re.PositionX,pt*et,t,i.settings,e,l,d,p),this.applyBehaviorSensor(n,re.PositionY,pt*et,t,i.settings,e,l,d,p)}}}else if(i.type===tt.Scroll){const Z=((z=i.settings)==null?void 0:z.axis)||"vertical",nt=((K=i.settings)==null?void 0:K.factor)||.5,et=((G=i.settings)==null?void 0:G.strength)||1,pt=((x=i.settings)==null?void 0:x.scaleFactor)||0;(Z==="vertical"||Z==="both")&&(n.y+=this.scrollOffset.y*nt*et*t),(Z==="horizontal"||Z==="both")&&(n.x+=this.scrollOffset.x*nt*et*t),pt!==0&&(n.scale_x*=1+this.scrollOffset.y*pt*t,n.scale_y*=1+this.scrollOffset.y*pt*t)}else if(i.type===tt.LookAt){const Z=((Q=i.settings)==null?void 0:Q.factor)||1,nt=((H=i.settings)==null?void 0:H.strength)||1,et=Math.atan2(-d,-l)*(180/Math.PI),pt=n.rotation,$t=(et-pt+180)%360-180;n.rotation+=$t*Z*nt*t*10}else if(i.type===tt.Scan){const Z=(((lt=i.settings)==null?void 0:lt.speed)||1)*.004,nt=((kt=i.settings)==null?void 0:kt.strength)||1,et=(Math.sin(Date.now()*Z)+1)/2;n.style&&(n.style.exposure=(n.style.exposure||1)+et*nt*t*5),n.x+=(et-.5)*20*nt*t}else if(i.type===tt.Glint)n.style=n.style||{...e.style},n.style.artEffect={enabled:!0,type:"glint_overlay",intensity:((At=i.settings)==null?void 0:At.strength)??.8};else if(i.type===tt.Ratchet){const Z=((Ht=i.settings)==null?void 0:Ht.steps)||12,nt=(((Ut=i.settings)==null?void 0:Ut.speed)||1)*30,et=Math.floor(n.rotation/(360/Z))*(360/Z);n.rotation=this.lerp(n.rotation,et+nt*t,.1)}else if(i.type===tt.Jitter&&p<300){const Z=((qt=i.settings)==null?void 0:qt.strength)||1,nt=((($=i.settings)==null?void 0:$.intensity)||5)*Z;n.x+=(Math.random()-.5)*nt*t*60,n.y+=(Math.random()-.5)*nt*t*60,n.rotation+=(Math.random()-.5)*nt*t*120}else if(i.type===tt.Follower){const Z=(dt=i.settings)==null?void 0:dt.targetId;if(Z){const nt=this.objectStates.get(Z);if(nt){const et=((Rt=i.settings)==null?void 0:Rt.stiffness)||.1,pt=nt.x-n.x,$t=nt.y-n.y;n.x+=pt*et*t*60,n.y+=$t*et*t*60}}}else if(i.type===tt.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===tt.Gravity){const Z=((Nt=i.settings)==null?void 0:Nt.strength)||9.8;n.y+=Z*t*10}else if(i.type===tt.Velocity){const Z=((st=i.settings)==null?void 0:st.vx)||0,nt=((yt=i.settings)==null?void 0:yt.vy)||0;n.x+=Z*t*10,n.y+=nt*t*10}else if(i.type===tt.Shear){const Z=((St=i.settings)==null?void 0:St.strength)||1,nt=((ee=i.settings)==null?void 0:ee.radius)||300;if(p<nt){const et=1-p/nt;n.skew_x=this.lerp(n.skew_x||0,(((Ct=e.transform)==null?void 0:Ct.skew_x)||0)+et*Z*30,.1)}else n.skew_x=this.lerp(n.skew_x||0,((Vt=e.transform)==null?void 0:Vt.skew_x)||0,.05)}else if(i.type===tt.Lens){const Z=((Tt=i.settings)==null?void 0:Tt.radius)||200,nt=((Xt=i.settings)==null?void 0:Xt.strength)||.5;if(p<Z){const et=Math.pow(1-p/Z,2);n.scale_x=this.lerp(n.scale_x??1,(((Ft=e.transform)==null?void 0:Ft.scale_x)??1)*(1+et*nt),.2),n.scale_y=this.lerp(n.scale_y??1,(((le=e.transform)==null?void 0:le.scale_y)??1)*(1+et*nt),.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,((Oe=e.transform)==null?void 0:Oe.scale_y)??1,.1)}else if(i.type===tt.LayoutAnimation){const Z=((jt=i.settings)==null?void 0:jt.watchProperties)||["x","y","scale_x","scale_y","opacity","rotation"],nt=((oe=i.settings)==null?void 0:oe.duration)||.3;this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const et=this._layoutAnimCache.get(e.id);for(const pt of Z){const $t=this.getObjectProperty(n,e,pt);if($t===void 0)continue;const xt=et.get(pt);if(!xt)et.set(pt,{from:$t,to:$t,startTime:this.currentTime,duration:0});else if(xt.to!==$t){const pe=this.getObjectProperty(n,e,pt);et.set(pt,{from:pe??xt.from,to:$t,startTime:this.currentTime,duration:((ne=i.settings)==null?void 0:ne.duration)??nt})}const Jt=et.get(pt);if(Jt.duration>0&&Jt.from!==Jt.to){const pe=this.currentTime-Jt.startTime,Te=Math.min(1,pe/Jt.duration),$e=this.applyEasing(Te,((Fe=i.settings)==null?void 0:Fe.easing)||"easeOutCubic"),ye=Jt.from+(Jt.to-Jt.from)*$e;this.setObjectProperty(n,e,pt,ye)}}}else if(i.type===tt.StateReactive){this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const Z=this._layoutAnimCache.get(e.id),nt=((Be=i.settings)==null?void 0:Be.defaultDuration)||.3,et=["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 pt of et){const $t=this.getObjectProperty(n,e,pt);if($t===void 0||typeof $t!="number")continue;const xt=Z.get(pt);if(!xt)Z.set(pt,{from:$t,to:$t,startTime:this.currentTime,duration:0});else if(xt.to!==$t){const pe=this.getObjectProperty(n,e,pt);Z.set(pt,{from:pe??xt.from,to:$t,startTime:this.currentTime,duration:nt})}const Jt=Z.get(pt);if(Jt.duration>0&&Jt.from!==Jt.to){const pe=this.currentTime-Jt.startTime,Te=Math.min(1,pe/Jt.duration),$e=this.applyEasing(Te,((xe=i.settings)==null?void 0:xe.defaultEasing)||"easeOutCubic"),ye=Jt.from+(Jt.to-Jt.from)*$e;this.setObjectProperty(n,e,pt,ye)}}}else if(i.type===tt.SpringChain){const Z=((We=i.settings)==null?void 0:We.connections)||[],nt=((De=i.settings)==null?void 0:De.globalDamping)||.3;this._springChainState.has(e.id)||this._springChainState.set(e.id,new Map);const et=this._springChainState.get(e.id);for(const $t of Z){if(!et.has($t.targetId)){const xt=this.objectStates.get($t.targetId);et.set($t.targetId,{x:(xt==null?void 0:xt.x)??0,y:(xt==null?void 0:xt.y)??0,vx:0,vy:0})}et.has(e.id)||et.set(e.id,{x:n.x,y:n.y,vx:0,vy:0})}const pt=et.get(e.id);if(pt){pt.x=n.x,pt.y=n.y;for(const $t of Z){const xt=et.get($t.targetId);if(!xt)continue;const Jt=xt.x-pt.x,pe=xt.y-pt.y,Te=Math.sqrt(Jt*Jt+pe*pe)||.001,ye=(Te-($t.restLength||50))*($t.stiffness||.8),Le=Jt/Te*ye,Qe=pe/Te*ye;pt.vx+=Le*t*10,pt.vy+=Qe*t*10,xt.vx-=Le*t*10,xt.vy-=Qe*t*10,pt.vx*=1-nt*t*10,pt.vy*=1-nt*t*10,xt.vx*=1-nt*t*10,xt.vy*=1-nt*t*10;const Pe=this.objectStates.get($t.targetId);Pe&&(Pe.x+=xt.vx*t,Pe.y+=xt.vy*t)}n.x+=pt.vx*t,n.y+=pt.vy*t}}else if(i.type===tt.ParticleEmitter){const Z=((Ye=i.settings)==null?void 0:Ye.rate)||10,nt=((Ge=i.settings)==null?void 0:Ge.speed)||100,et=((se=i.settings)==null?void 0:se.size)||5,pt=((ue=i.settings)==null?void 0:ue.lifetime)||2,$t=((Se=i.settings)==null?void 0:Se.gravity)||0,xt=((Xe=i.settings)==null?void 0:Xe.color)||"#ffffff",Jt=((Ne=i.settings)==null?void 0:Ne.maxParticles)||200,pe=(ke=i.settings)!=null&&ke.rateInputId?this.inputs.get(i.settings.rateInputId)??Z:Z,Te=(Ce=i.settings)!=null&&Ce.gravityInputId?this.inputs.get(i.settings.gravityInputId)??$t:$t,$e=(we=i.settings)!=null&&we.speedInputId?this.inputs.get(i.settings.speedInputId)??nt:nt;this._emitterPools.has(e.id)||this._emitterPools.set(e.id,[]);const ye=this._emitterPools.get(e.id);let Le=0;i._pendingBurst&&i._pendingBurst>0&&(Le=i._pendingBurst,i._pendingBurst=0);const Qe=Math.floor(pe*t)+(Le||0);for(let Pe=0;Pe<Math.min(Qe,Jt-ye.length);Pe++){const be=Math.random()*Math.PI*2,ms=$e*(.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:pt*(.5+Math.random()*.5),size:et*(.5+Math.random()),color:xt,opacity:1})}for(let Pe=ye.length-1;Pe>=0;Pe--){const be=ye[Pe];be.vy+=Te*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(Pe,1)}}})})}applyBehaviorSensor(t,s,o,e,n,i,a=0,r=0,l=1){var h,f,v,g,c,b,S,w,C,M,I,_,E,P,L,k,A,T,R,F,O,W,V,U;const d=(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,m=l>0?r/l:0;switch(s){case re.Scale:{const D=((h=i==null?void 0:i.transform)==null?void 0:h.scale_x)??1,Y=((f=i==null?void 0:i.transform)==null?void 0:f.scale_y)??1,ot=D*(1+o*d*.4),J=Y*(1+o*d*.4);t.scale_x=(t.scale_x??D)*(1-p)+ot*p,t.scale_y=(t.scale_y??Y)*(1-p)+J*p;break}case re.Opacity:{const D=((v=i==null?void 0:i.transform)==null?void 0:v.opacity)??100,Y=Math.max(0,Math.min(100,D-o*d*100));t.opacity=(t.opacity??D)*(1-p)+Y*p;break}case re.RotateZ:{const D=((g=i==null?void 0:i.transform)==null?void 0:g.rotation)??0,Y=D+o*d*45;t.rotation=(t.rotation??D)*(1-p)+Y*p;break}case re.RotateX:{const D=((c=i==null?void 0:i.transform)==null?void 0:c.rotate_x)??0,Y=D-m*o*d*60;t.rotate_x=(t.rotate_x??D)*(1-p)+Y*p;break}case re.RotateY:{const D=((b=i==null?void 0:i.transform)==null?void 0:b.rotate_y)??0,Y=D+u*o*d*60;t.rotate_y=(t.rotate_y??D)*(1-p)+Y*p;break}case re.PositionX:{const D=((S=i==null?void 0:i.transform)==null?void 0:S.x)??0,Y=D-u*o*d*40;t.x=(t.x??D)*(1-p)+Y*p;break}case re.PositionY:{const D=((w=i==null?void 0:i.transform)==null?void 0:w.y)??0,Y=D-m*o*d*40;t.y=(t.y??D)*(1-p)+Y*p;break}case re.SkewX:{const D=((C=i==null?void 0:i.transform)==null?void 0:C.skew_x)??0,Y=D+u*o*d*45;t.skew_x=(t.skew_x??D)*(1-p)+Y*p,t.skew_x>85&&(t.skew_x=85),t.skew_x<-85&&(t.skew_x=-85);break}case re.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 D=((_=(I=i==null?void 0:i.style)==null?void 0:I.blur)==null?void 0:_.amount)||0,Y=D+o*((n==null?void 0:n.blur)||20)*d;t.style.blur.amount=(t.style.blur.amount??D)*(1-p)+Y*p;break}case re.Exposure:{t.style||(t.style={...i==null?void 0:i.style}),t.style.adjustments||(t.style.adjustments={...(E=i==null?void 0:i.style)==null?void 0:E.adjustments});const D=((L=(P=i==null?void 0:i.style)==null?void 0:P.adjustments)==null?void 0:L.exposure)||0,Y=D+o*((n==null?void 0:n.exposure)||50)*d;t.style.adjustments.exposure=(t.style.adjustments.exposure??D)*(1-p)+Y*p;break}case re.HueShift:{t.style||(t.style={...i==null?void 0:i.style}),t.style.adjustments||(t.style.adjustments={...(k=i==null?void 0:i.style)==null?void 0:k.adjustments});const D=((T=(A=i==null?void 0:i.style)==null?void 0:A.adjustments)==null?void 0:T.hue)||0,Y=D+o*((n==null?void 0:n.hue)||180)*d;t.style.adjustments.hue=(t.style.adjustments.hue??D)*(1-p)+Y*p;break}case re.Negative:{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 D=((O=(F=i==null?void 0:i.style)==null?void 0:F.adjustments)==null?void 0:O.negative)||0,Y=D+o*((n==null?void 0:n.negative)||100)*d;t.style.adjustments.negative=(t.style.adjustments.negative??D)*(1-p)+Y*p;break}case re.CornerRadius:{const D=((W=i==null?void 0:i.transform)==null?void 0:W.corner_radius)||0,Y=D+o*d*50;t.corner_radius=(t.corner_radius??D)*(1-p)+Y*p;break}case re.StrokeWidth:{t.style||(t.style={...i==null?void 0:i.style});const D=((V=i==null?void 0:i.style)==null?void 0:V.borderWidth)||0,Y=D+o*d*10;t.style.borderWidth=(t.style.borderWidth??D)*(1-p)+Y*p;break}case re.LetterSpacing:{t.geometry||(t.geometry={});const D=((U=i==null?void 0:i.geometry)==null?void 0:U.letterSpacing)||0,Y=D+o*d*10;t.geometry.letterSpacing=(t.geometry.letterSpacing??D)*(1-p)+Y*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((h,f)=>h==null?void 0:h[f],d),u=n[r+1],m=!isNaN(Number(u));i[l]=p!==void 0?Array.isArray(p)?[...p]:{...p}:m?[]:{}}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,u=e.hue||0,m=(e.negative||0)/100,h=e.blur||0;if(!(n!==0||i!==0||a!==0||r!==0||l!==0||d!==0||p!==0||u!==0||m!==0||h>0))return t;const v=t.naturalWidth||Math.max(1,Math.round(s)),g=t.naturalHeight||Math.max(1,Math.round(o)),c=document.createElement("canvas");c.width=v,c.height=g;const b=c.getContext("2d");if(!b)return t;const S=[];h>0&&S.push(`blur(${h}px)`),u!==0&&S.push(`hue-rotate(${Math.round(u)}deg)`),S.length>0&&(b.filter=S.join(" ")),b.drawImage(t,0,0,v,g);try{const w=b.getImageData(0,0,v,g),C=w.data,M=C.length,I=n*255,_=i>=0?(1+i)/Math.max(.01,1-i):1+i,E=1+a,P=1+r-l/2,L=1+l,k=1-r-l/2,A=1+d+p,T=p*25.5,R=1-m/50,F=(1-R)*255;for(let O=0;O<M;O+=4){let W=C[O],V=C[O+1],U=C[O+2];if(n!==0&&(W+=I,V+=I,U+=I),i!==0&&(W=(W-127.5)*_+127.5,V=(V-127.5)*_+127.5,U=(U-127.5)*_+127.5),a!==0){const D=.2989*W+.587*V+.114*U;W=D+(W-D)*E,V=D+(V-D)*E,U=D+(U-D)*E}(r!==0||l!==0)&&(W=W*P,V=V*L,U=U*k),(d!==0||p!==0)&&(W=W*A+T,V=V*A+T,U=U*A+T),m!==0&&(W=W*R+F,V=V*R+F,U=U*R+F),C[O]=Math.min(255,Math.max(0,W)),C[O+1]=Math.min(255,Math.max(0,V)),C[O+2]=Math.min(255,Math.max(0,U))}return b.putImageData(w,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 u=n,m=i,h=o,f=e;a==="cover"?d>p?(u=i*d,h=o-(u-n)/2):(m=n/d,f=e-(m-i)/2):a==="contain"&&(d>p?(m=n/d,f=e+(i-m)/2):(u=i*d,h=o+(n-u)/2)),t.drawImage(s,h,f,u,m)}}const ai=_t.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:u,onInputBlur:m,onLog:h,onLogicUpdate:f,onButtonClick:v,onGraphPointClick:g,currentTime:c,revision:b=0,scrollY:S,scrollX:w,mouseX:C,mouseY:M,isMouseDown:I,inputs:_,interactive:E=!0,onNavigation:P},L)=>{const k=_t.useRef(null),A=_t.useRef(null);A.current||(A.current=new gs);const T=_t.useRef(void 0),R=_t.useRef(0),F=_t.useRef(null),O=_t.useRef(b),W=_t.useRef(null),[,V]=_t.useState(y||null),U=_t.useRef(!0),D=_t.useRef(o),Y=_t.useRef(c);_t.useEffect(()=>{D.current=o},[o]),_t.useEffect(()=>{Y.current=c},[c]),_t.useImperativeHandle(L,()=>k.current),_t.useEffect(()=>(U.current=!0,()=>{U.current=!1,T.current&&cancelAnimationFrame(T.current)}),[]),_t.useEffect(()=>{A.current.setLayout(e,n)},[e,n]),_t.useEffect(()=>{const B=A.current;a&&B.setTriggerCallback(a),r&&B.setInputUpdateCallback((X,N)=>r({[X]:N})),l&&B.setComponentChangeCallback(X=>l(X)),d&&B.setToggleCallback(d),p&&B.setInputChangeCallback(p),u&&B.setInputFocusCallback(u),m&&B.setInputBlurCallback(m),h&&B.setOnLogCallback(X=>h(X,"info")),f&&B.setLogicUpdateCallback(f),v&&B.setButtonClickCallback(v),g&&B.setGraphPointClickCallback(X=>g(X.objectId,X)),P&&B.setNavigationCallback(P)},[a,r,l,d,p,u,m,h,f,v,g,P]),_t.useEffect(()=>{(async()=>{let X=y;if(t&&!y)try{t.startsWith("{")?X=JSON.parse(t):X=await(await fetch(t)).json()}catch(N){console.error("[ExodeUI] Failed to load src:",N)}if(X){const N=A.current,ct=X.id||X.name||"default";(F.current!==ct||O.current!==b||W.current!==X)&&(N.load(X),F.current=ct,O.current=b,W.current=X,V(X),R.current=-1,N.advance(0)),i&&i(N)}})()},[y,t,b]),_t.useEffect(()=>{const B=X=>{if(!A.current||!U.current)return;const N=A.current,ct=k.current;if(!ct)return;const Mt=ct.getContext("2d");if(!Mt)return;const bt=X/1e3;R.current<0&&(R.current=bt),R.current===0&&(R.current=bt);let wt=bt-R.current;wt>.1&&(wt=.1),R.current=bt;const gt=ct.getBoundingClientRect(),It=window.devicePixelRatio||1,ut=Math.round(gt.width*It),Lt=Math.round(gt.height*It);(ct.width!==ut||ct.height!==Lt)&&(ct.width=ut,ct.height=Lt);try{D.current?N.advance(wt):Y.current!==void 0&&N.seek(Y.current),N.render(Mt,ct.width,ct.height)}catch(Wt){console.error("[ExodeUICanvas] Error in animation loop:",Wt),h&&h(`[Error] Animation loop crashed: ${Wt}`,"error")}T.current=requestAnimationFrame(B)};return T.current=requestAnimationFrame(B),()=>{T.current&&cancelAnimationFrame(T.current)}},[]),_t.useEffect(()=>{const B=A.current;S!==void 0&&B.updateInput("scrollY",S),w!==void 0&&B.updateInput("scrollX",w),C!==void 0&&B.updateInput("mouseX",C),M!==void 0&&B.updateInput("mouseY",M),I!==void 0&&B.updateInput("isMouseDown",I),_&&Object.entries(_).forEach(([X,N])=>B.updateInput(X,N))},[S,w,C,M,I,_]);const ot=(B,X)=>{if(!E||!k.current)return;B.stopPropagation(),"nativeEvent"in B&&B.nativeEvent&&typeof B.nativeEvent.stopImmediatePropagation=="function"?B.nativeEvent.stopImmediatePropagation():typeof B.stopImmediatePropagation=="function"&&B.stopImmediatePropagation();const N=k.current,ct=N.getBoundingClientRect(),Mt=B.clientX-ct.left,bt=B.clientY-ct.top,wt=window.devicePixelRatio||1;(X==="click"||X==="down"||X==="up")&&h&&h(`[Canvas] Pointer ${X} at rect(${Math.round(Mt)},${Math.round(bt)}) mapped to buffer(${Math.round(Mt*wt)},${Math.round(bt*wt)})`,"info"),A.current.handlePointerInput(X,Mt*wt,bt*wt,N.width,N.height)};_t.useEffect(()=>{if(!E)return;const B=N=>{var ct,Mt,bt;((ct=document.activeElement)==null?void 0:ct.tagName)==="INPUT"||((Mt=document.activeElement)==null?void 0:Mt.tagName)==="TEXTAREA"||(bt=A.current)==null||bt.handleKeyDown(N)},X=N=>{var ct,Mt,bt;((ct=document.activeElement)==null?void 0:ct.tagName)==="INPUT"||((Mt=document.activeElement)==null?void 0:Mt.tagName)==="TEXTAREA"||(bt=A.current)==null||bt.handleKeyUp(N)};return window.addEventListener("keydown",B),window.addEventListener("keyup",X),()=>{window.removeEventListener("keydown",B),window.removeEventListener("keyup",X)}},[E]),_t.useEffect(()=>{const B=k.current;if(!B||!E)return;const X=N=>{if(N.preventDefault(),N.stopPropagation(),A.current){const ct=B.getBoundingClientRect(),Mt=window.devicePixelRatio||1,bt=(N.clientX-ct.left)*Mt,wt=(N.clientY-ct.top)*Mt;let gt=N.deltaX,It=N.deltaY;N.deltaMode===1?(gt*=25,It*=25):N.deltaMode===2&&(gt*=100,It*=100),A.current.handlePointerInput("move",bt,wt,B.width,B.height),A.current.handleWheel(gt,It,bt,wt,B.width,B.height)}};return B.addEventListener("wheel",X,{passive:!1}),()=>{B.removeEventListener("wheel",X)}},[E]);const[J,at]=_t.useState([]);_t.useEffect(()=>{if(y&&y.objects){const B=y.objects.filter(X=>{var N,ct;return X.type==="Joystick"&&((N=X.inputBinding)==null?void 0:N.type)==="keyboard"&&((ct=X.inputBinding.keyboardConfig)==null?void 0:ct.showVirtualKeyboard)});at(B)}},[y]);const[,j]=_t.useState(0);_t.useEffect(()=>{if(J.length===0)return;let B;const X=()=>{j(N=>N+1),B=requestAnimationFrame(X)};return B=requestAnimationFrame(X),()=>cancelAnimationFrame(B)},[J.length]);const it=()=>J.map(B=>{const X=B.inputBinding.keyboardConfig,N=gt=>{var ut;const It={key:gt,code:gt,preventDefault:()=>{}};(ut=A.current)==null||ut.handleKeyDown(It)},ct=gt=>{var ut;const It={key:gt,code:gt,preventDefault:()=>{}};(ut=A.current)==null||ut.handleKeyUp(It)},Mt=A.current,bt=gt=>Mt&&Mt.activeKeys?Mt.activeKeys.has(gt.toLowerCase()):!1,wt=gt=>({width:"50px",height:"50px",background:gt?"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:gt?"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:wt(bt(X.upKey)),onMouseDown:()=>N(X.upKey),onMouseUp:()=>ct(X.upKey),onMouseLeave:()=>ct(X.upKey),onTouchStart:gt=>{gt.preventDefault(),N(X.upKey)},onTouchEnd:gt=>{gt.preventDefault(),ct(X.upKey)},children:X.upKey.toUpperCase()}),Qt.jsxs("div",{style:{display:"flex",gap:"8px"},children:[Qt.jsx("div",{style:wt(bt(X.leftKey)),onMouseDown:()=>N(X.leftKey),onMouseUp:()=>ct(X.leftKey),onMouseLeave:()=>ct(X.leftKey),onTouchStart:gt=>{gt.preventDefault(),N(X.leftKey)},onTouchEnd:gt=>{gt.preventDefault(),ct(X.leftKey)},children:X.leftKey.toUpperCase()}),Qt.jsx("div",{style:wt(bt(X.downKey)),onMouseDown:()=>N(X.downKey),onMouseUp:()=>ct(X.downKey),onMouseLeave:()=>ct(X.downKey),onTouchStart:gt=>{gt.preventDefault(),N(X.downKey)},onTouchEnd:gt=>{gt.preventDefault(),ct(X.downKey)},children:X.downKey.toUpperCase()}),Qt.jsx("div",{style:wt(bt(X.rightKey)),onMouseDown:()=>N(X.rightKey),onMouseUp:()=>ct(X.rightKey),onMouseLeave:()=>ct(X.rightKey),onTouchStart:gt=>{gt.preventDefault(),N(X.rightKey)},onTouchEnd:gt=>{gt.preventDefault(),ct(X.rightKey)},children:X.rightKey.toUpperCase()})]})]},B.id)});return Qt.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[Qt.jsx("canvas",{ref:k,onPointerDown:B=>{var X;ot(B,"down"),B.currentTarget.setPointerCapture(B.pointerId),(X=k.current)==null||X.focus()},onPointerMove:B=>ot(B,"move"),onPointerUp:B=>{ot(B,"up"),B.currentTarget.releasePointerCapture(B.pointerId)},onPointerCancel:B=>{ot(B,"up"),B.currentTarget.releasePointerCapture(B.pointerId)},onClick:B=>ot(B,"click"),onKeyDown:B=>A.current.handleKeyDown(B.nativeEvent),onKeyUp:B=>A.current.handleKeyUp(B.nativeEvent),onContextMenu:B=>B.preventDefault(),tabIndex:0,style:{...s,width:"100%",height:"100%",outline:"none",display:"block",touchAction:"none",pointerEvents:E?"auto":"none"}}),it()]})});function ri(){const[y,t]=_t.useState(null),s=_t.useCallback((g,c)=>{y==null||y.setInputBool(g,c)},[y]),o=_t.useCallback((g,c)=>{y==null||y.setInputNumber(g,c)},[y]),e=_t.useCallback(g=>{y==null||y.fireTrigger(g)},[y]),n=_t.useCallback((g,c)=>{y==null||y.setInputText(g,c)},[y]),i=_t.useCallback((g,c)=>{y==null||y.setInputNumberArray(g,c)},[y]),a=_t.useCallback((g,c)=>{y==null||y.setInputStringArray(g,c)},[y]),r=_t.useCallback((g,c)=>{y==null||y.updateInput(g,c)},[y]),l=r,d=_t.useCallback((g,c)=>{y==null||y.updateObjectOptions(g,c)},[y]),p=_t.useCallback((g,c,b)=>{y==null||y.updateConstraint(g,c,b)},[y]),u=_t.useCallback((g,c,b)=>{y==null||y.updateGraphData(g,c,b)},[y]),m=_t.useCallback((g,c,b)=>{y==null||y.updateBarChartData(g,c,b)},[y]),h=_t.useCallback((g,c)=>{y==null||y.updatePieChartData(g,c)},[y]),f=_t.useCallback((g,c)=>{y==null||y.setDropdownOptions(g,c)},[y]),v=_t.useCallback(g=>y==null?void 0:y.getInputValue(g),[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:u,updateBarChartData:m,updatePieChartData:h,setDropdownOptions:f,updateObjectOptions:d,getInputValue:v}}const li=({artboard:y,config:t})=>{const s={...y.seo,...t},o=s.enableSmartExtraction!==!1;_t.useEffect(()=>{const a=s.title||y.name;a&&(document.title=a);let r=s.description;if(!r&&o){const p=y.objects.filter(u=>{var m;return((m=u.geometry)==null?void 0:m.type)==="Text"}).sort((u,m)=>{var h,f;return(((h=m.geometry.text)==null?void 0:h.length)||0)-(((f=u.geometry.text)==null?void 0:f.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(Qt.jsx("h1",{children:s.title||y.name},"artboard-title")),y.objects.forEach((l,d)=>{var p,u;if(!(l.visible===!1||l.isVisible===!1))if(((p=l.geometry)==null?void 0:p.type)==="Text"){const m=l.geometry.text;m&&(l.geometry.fontSize>24?a.push(Qt.jsx("h2",{children:m},l.id||d)):a.push(Qt.jsx("p",{children:m},l.id||d)))}else if(((u=l.geometry)==null?void 0:u.type)==="Image"){const m=l.geometry.src,h=l.altText||l.name||"Illustration";a.push(Qt.jsx("img",{src:m,alt:h},l.id||d))}else l.type==="Button"&&a.push(Qt.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 Qt.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(),Qt.jsx("script",{type:"application/ld+json",children:JSON.stringify(i)})]})},ci={version:"6.4.3"}.version;Kt.BAR_STYLE_PRESETS=oi,Kt.BehaviorSensor=re,Kt.BehaviorType=tt,Kt.ConditionOp=je,Kt.ExodeSEO=li,Kt.ExodeUICanvas=ai,Kt.ExodeUIEngine=gs,Kt.LogicOp=Et,Kt.RapierPhysics=is,Kt.VERSION=ci,Kt.useExodeUI=ri,Object.defineProperty(Kt,Symbol.toStringTag,{value:"Module"})}));
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"})}));