exodeui 6.3.50 → 6.4.0
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 +19 -19
- package/dist/index.mjs +3973 -3676
- package/dist/src/engine.d.ts +14 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`||
|
|
3
|
-
`||
|
|
4
|
-
`&&
|
|
5
|
-
`||
|
|
6
|
-
`&&T++)}let M=(C==null?void 0:C.lines)||[];return b.composer==="every-line"&&M.length>1&&(M=Ms(M)),b.balanceRaggedLines===!0&&M.length>1&&(M=Is(M)),{width:a,height:w,lineCount:M.length,lines:M}}function es(b,t,s){let o=String(b||"").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),i=new Array(e.length).fill(0);let n=t-(e.length-1)*s,a=0;if(e.forEach((r,c)=>{if(r.endsWith("px")){const d=parseFloat(r);i[c]=d,n-=d}else r.endsWith("fr")?a+=parseFloat(r):r==="auto"&&(i[c]=100,n-=100)}),a>0&&n>0){const r=n/a;e.forEach((c,d)=>{c.endsWith("fr")&&(i[d]=r*parseFloat(c))})}return i}function ss(b,t,s){try{const o=b.autoLayout;return!o||!o.enabled?{childUpdates:[]}:(o.mode||"linear")==="grid"?Ts(b,t,s):ks(b,t,s)}catch(o){return console.error("Layout Engine Error:",o),{childUpdates:[]}}}function ks(b,t,s){var _,L;const o=b.autoLayout,{direction:e,spacing:i,padding:n,align:a,wrap:r}=o,c=e==="vertical",d=t.map(A=>{const W=s(A.id),B=A.geometry;let R=(W==null?void 0:W.width)??B.width??100,Y=(W==null?void 0:W.height)??B.height??100;if(B.type==="Ellipse"||B.type==="Polygon"||B.type==="Star"){const G=(W==null?void 0:W.radius)??B.radius??(W==null?void 0:W.outer_radius)??B.outer_radius??50;R=G*2,Y=G*2}else if(B.type==="Text"){const G=ts({text:(W==null?void 0:W.text)??B.text??"",fontFamily:B.fontFamily,fontSize:B.fontSize,fontWeight:B.fontWeight,fontStyle:B.fontStyle,lineHeight:B.lineHeight,width:B.width||200,letterSpacing:B.letterSpacing,paragraphSpacing:B.paragraphSpacing,paragraphIndent:B.paragraphIndent,textCase:B.textCase,segments:B.segments,enableSegments:B.enableSegments});Y=G.height,B.width||(R=G.width)}return R*=A.transform.scale_x||1,Y*=A.transform.scale_y||1,{id:A.id,w:R,h:Y,original:A}});let u=b.width,p=b.height;const l=((_=b.layoutProps)==null?void 0:_.width)==="hug",h=((L=b.layoutProps)==null?void 0:L.height)==="hug",f=[];let g=[],y=0,m=0;const S=u-n.left-n.right,v=p-n.top-n.bottom;d.forEach(A=>{r&&g.length>0&&(c?m+i+A.h>v:y+i+A.w>S)?(f.push({children:g,width:y,height:m}),g=[A],y=A.w,m=A.h):(g.push(A),c?(y=Math.max(y,A.w),m+=(g.length>1?i:0)+A.h):(y+=(g.length>1?i:0)+A.w,m=Math.max(m,A.h)))}),g.length>0&&f.push({children:g,width:y,height:m}),l&&!c&&(u=Math.max(...f.map(A=>A.width),0)+n.left+n.right),h&&c&&(p=Math.max(...f.map(A=>A.height),0)+n.top+n.bottom);const C=[];let w=n.left,M=n.top;const I=a.toLowerCase(),T=I==="center"||I.endsWith("-center"),k=I.endsWith("-right"),E=I==="center"||I.startsWith("center-"),P=I.startsWith("bottom-");return f.forEach(A=>{let W=w,B=M;c?E?B=n.top+(p-n.top-n.bottom-A.height)/2:P&&(B=p-n.bottom-A.height):T?W=n.left+(u-n.left-n.right-A.width)/2:k&&(W=u-n.right-A.width),A.children.forEach(R=>{var F,Z;let Y=W,G=B;c?T?Y+=(A.width-R.w)/2:k&&(Y+=A.width-R.w):E?G+=(A.height-R.h)/2:P&&(G+=A.height-R.h);const z=((F=R.original.layoutProps)==null?void 0:F.width)==="fill",O=((Z=R.original.layoutProps)==null?void 0:Z.height)==="fill";C.push({id:R.id,x:Y+R.w/2-u/2,y:G+R.h/2-p/2,width:z&&c?A.width:void 0,height:O?c?void 0:A.height:void 0}),c?B+=R.h+i:W+=R.w+i}),c?w+=A.width+i:M+=A.height+i}),{frameWidth:l?u:void 0,frameHeight:h?p:void 0,childUpdates:C}}function Ts(b,t,s){const o=b.autoLayout;if(!o)return{childUpdates:[]};const{gridColumns:e,gridRows:i,columnGap:n=0,rowGap:a=0,padding:r,align:c}=o;let d=b.width,u=b.height;const p=d-r.left-r.right,l=u-r.top-r.bottom,h=es(e||"1fr",p,n),f=es(i||"auto",l,a),g=h.length>0?h.reduce((k,E)=>k+E,0)+(h.length-1)*n:0,y=f.length>0?f.reduce((k,E)=>k+E,0)+(f.length-1)*a:0,m=c.toLowerCase(),S=m==="center"||m.endsWith("-center"),v=m.endsWith("-right"),C=m==="center"||m.startsWith("center-"),w=m.startsWith("bottom-");let M=0,I=0;S?M=(p-g)/2:v&&(M=p-g),C?I=(l-y)/2:w&&(I=l-y);const T=[];return t.forEach((k,E)=>{var Z,st;const P=E%h.length||0,_=Math.floor(E/h.length)||0;_>=f.length&&f.push(100);const L=h[P],A=f[_];let W=r.left+M+h.slice(0,P).reduce((at,ct)=>at+ct+n,0),B=r.top+I+f.slice(0,_).reduce((at,ct)=>at+ct+a,0);const R=s(k.id),Y=k.geometry;let G=(R==null?void 0:R.width)??Y.width??100,z=(R==null?void 0:R.height)??Y.height??100;if(Y.type==="Ellipse"||Y.type==="Polygon"||Y.type==="Star"){const at=(R==null?void 0:R.radius)??Y.radius??(R==null?void 0:R.outer_radius)??Y.outer_radius??50;G=at*2,z=at*2}G*=k.transform.scale_x||1,z*=k.transform.scale_y||1;let O=W,F=B;S?O+=(L-G)/2:v&&(O+=L-G),C?F+=(A-z)/2:w&&(F+=A-z),T.push({id:k.id,x:O+G/2-d/2,y:F+z/2-u/2,width:((Z=k.layoutProps)==null?void 0:Z.width)==="fill"?L:void 0,height:((st=k.layoutProps)==null?void 0:st.height)==="fill"?A:void 0})}),{childUpdates:T}}class is{constructor(){nt(this,"world",null);nt(this,"bodies",new Map);nt(this,"colliders",new Map);nt(this,"joints",new Map);nt(this,"initialized",!1);nt(this,"bodyIdByCollider",new Map);nt(this,"onCollisionCB",null);nt(this,"eventQueue",null)}setCollisionCallback(t){this.onCollisionCB=t}async init(t){this.initialized||(await ie.init(),this.world=new ie.World(new ie.Vector2(t.x*100,t.y*100)),this.eventQueue=new ie.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 ie.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?ie.RigidBodyDesc.fixed():ie.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=ie.ColliderDesc.cuboid(t.width/2,t.height/2);break;case"Ellipse":e=ie.ColliderDesc.ball(Math.max(t.width,t.height)/2);break;case"Triangle":case"Star":case"Polygon":e=ie.ColliderDesc.cuboid(t.width/2,t.height/2);break;default:e=ie.ColliderDesc.cuboid(t.width/2,t.height/2)}if(t.friction!==void 0&&e.setFriction(t.friction),t.restitution!==void 0&&e.setRestitution(t.restitution),t.density!==void 0)e.setDensity(t.density);else if(t.mass!==void 0&&!t.isStatic){const n=t.width*t.height;e.setDensity(t.mass/n)}t.isSensor&&e.setSensor(!0);const i=this.world.createCollider(e,o);this.bodyIdByCollider.set(i.handle,t.id),t.frictionAir!==void 0&&o.setLinearDamping(t.frictionAir*10),this.bodies.set(t.id,o),this.colliders.set(t.id,i)}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,i,n)=>{const a=this.bodyIdByCollider.get(e),r=this.bodyIdByCollider.get(i);a&&r&&s(a,r,n)})}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 ie.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 ie.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 ie.Vector2(s,o),!0)}applyImpulse(t,s,o){const e=this.bodies.get(t);e&&e.applyImpulse(new ie.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 ie.Vector2(t.anchorA.x,t.anchorA.y),i=new ie.Vector2(t.anchorB.x,t.anchorB.y);let n;if(t.type==="Distance"){const a=t.length??100,r=t.stiffness??100,c=t.damping??10;n=ie.JointData.spring(a,r,c,e,i)}else n=ie.JointData.revolute(e,i);try{const a=this.world.createImpulseJoint(n,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=b=>b,Ps=b=>b>0?1:0,_s=b=>b<1?0:1,os=b=>b*b,as=b=>b*(2-b),rs=b=>b<.5?2*b*b:-1+(4-2*b)*b,Es=b=>b*b*b,As=b=>--b*b*b+1,Os=b=>b<.5?4*b*b*b:(b-1)*(2*b-2)*(2*b-2)+1,Ls=b=>b*b*b*b,xs=b=>1- --b*b*b*b,Rs=b=>b<.5?8*b*b*b*b:1-8*--b*b*b*b,Fs=b=>b*b*b*b*b,$s=b=>1+--b*b*b*b*b,Bs=b=>b<.5?16*b*b*b*b*b:1+16*--b*b*b*b*b,Ws=b=>1-Math.cos(b*Math.PI/2),Ys=b=>Math.sin(b*Math.PI/2),Xs=b=>-(Math.cos(Math.PI*b)-1)/2,Ds=b=>b===0?0:Math.pow(2,10*(b-1)),Gs=b=>b===1?1:1-Math.pow(2,-10*b),Ns=b=>b===0?0:b===1?1:b<.5?Math.pow(2,20*b-10)/2:(2-Math.pow(2,-20*b+10))/2,zs=b=>1-Math.sqrt(1-b*b),Vs=b=>Math.sqrt(1- --b*b),Hs=b=>b<.5?(1-Math.sqrt(1-4*b*b))/2:(Math.sqrt(1-(-2*b+2)*(-2*b+2))+1)/2,Ue=1.70158,qe=Ue*1.525,ls=Ue+1,Us=b=>ls*b*b*b-Ue*b*b,qs=b=>1+ls*Math.pow(b-1,3)+Ue*Math.pow(b-1,2),Ks=b=>b<.5?Math.pow(2*b,2)*((qe+1)*2*b-qe)/2:(Math.pow(2*b-2,2)*((qe+1)*(b*2-2)+qe)+2)/2,cs=2*Math.PI/3,fs=2*Math.PI/4.5,Js=b=>b===0?0:b===1?1:-Math.pow(2,10*b-10)*Math.sin((b*10-10.75)*cs),Qs=b=>b===0?0:b===1?1:Math.pow(2,-10*b)*Math.sin((b*10-.75)*cs)+1,Zs=b=>b===0?0:b===1?1:b<.5?-(Math.pow(2,20*b-10)*Math.sin((20*b-11.125)*fs))/2:Math.pow(2,-20*b+10)*Math.sin((20*b-11.125)*fs)/2+1,Ke=b=>b<1/2.75?7.5625*b*b:b<2/2.75?7.5625*(b-=1.5/2.75)*b+.75:b<2.5/2.75?7.5625*(b-=2.25/2.75)*b+.9375:7.5625*(b-=2.625/2.75)*b+.984375,js=b=>1-Ke(1-b),ti=Ke,ei=b=>b<.5?(1-Ke(1-2*b))/2:(1+Ke(2*b-1))/2,Ze=new Map,ze=(b,t,s,o)=>{const e=`${b},${t},${s},${o}`;if(Ze.has(e))return Ze.get(e);const i=d=>(1-3*s+3*b)*d*d*d+(3*s-6*b)*d*d+3*b*d,n=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*b)*d*d+2*(3*s-6*b)*d+3*b,r=d=>{let u=d;for(let p=0;p<8;p++){const l=i(u)-d;if(Math.abs(l)<1e-6)return u;const h=a(u);if(Math.abs(h)<1e-6)break;u=u-l/h}return u},c=d=>d===0?0:d===1?1:n(r(d));return Ze.set(e,c),c},hs=b=>{const t=b.match(/cubic-bezier\s*\(\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*,\s*([-?\d.]+)\s*\)/);if(!t)return null;const[,s,o,e,i]=t.map(Number);return ze(s,o,e,i)},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)},Je={Linear:ns,EaseInQuad:os,EaseOutQuad:as,EaseInOutQuad:rs,EaseInCubic:Es,EaseOutCubic:As,EaseInOutCubic:Os,EaseInQuart:Ls,EaseOutQuart:xs,EaseInOutQuart:Rs,EaseInQuint:Fs,EaseOutQuint:$s,EaseInOutQuint:Bs,EaseInSine:Ws,EaseOutSine:Ys,EaseInOutSine:Xs,EaseInExpo:Ds,EaseOutExpo:Gs,EaseInOutExpo:Ns,EaseInCirc:zs,EaseOutCirc:Vs,EaseInOutCirc:Hs,EaseInBack:Us,EaseOutBack:qs,EaseInOutBack:Ks,EaseInElastic:Js,EaseOutElastic:Qs,EaseInOutElastic:Zs,EaseInBounce:js,EaseOutBounce:ti,EaseInOutBounce:ei,EaseIn:os,EaseOut:as,EaseInOut:rs,StepStart:Ps,StepEnd:_s},si=b=>{const t=b.trim(),s=t.toLowerCase();if(Je[t])return Je[t];const o=Object.keys(Je).find(i=>i.toLowerCase()===s);if(o)return Je[o];const e=Object.keys(ps).find(i=>i.toLowerCase()===s);if(e){const i=hs(ps[e].value);if(i)return i}if(ds[s])return ds[s];if(s.startsWith("cubic-bezier")){const i=hs(t);if(i)return i}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)"}},ii=(b,t,s,o,e)=>{if(!b||!t||!s)return b;const i=o.scale_x??1,n=o.scale_y??1,a=(r,c,d)=>{let u=0,p=0;const l=o.rotation*Math.PI/180,h=Math.cos(l),f=Math.sin(l),g=r*i*h-c*n*f+o.x,y=r*i*f+c*n*h+o.y;d.forEach(I=>{const T=e(I.boneId);if(!T)return;const k={x:T.x,y:T.y,rotation:T.rotation,scaleX:T.scale_x??1,scaleY:T.scale_y??1},E=s[I.boneId]||[1,0,0,1,0,0],P=g*E[0]+y*E[2]+E[4],_=g*E[1]+y*E[3]+E[5],L=k.rotation*Math.PI/180,A=Math.cos(L),W=Math.sin(L),B=P*k.scaleX*A-_*k.scaleY*W+k.x,R=P*k.scaleX*W+_*k.scaleY*A+k.y;u+=B*I.amount,p+=R*I.amount});const m=[...d].sort((I,T)=>T.amount-I.amount);if(m.length>=2&&m[0].amount>0&&m[1].amount>0){const I=e(m[0].boneId),T=e(m[1].boneId);if(I&&T&&I.length!==void 0&&T.length!==void 0){const k=I.length*(I.scale_y??1),E=I.rotation*Math.PI/180,P=I.x-k*Math.sin(E),_=I.y+k*Math.cos(E),L=T.length*(T.scale_y??1),A=T.rotation*Math.PI/180,W=T.x-L*Math.sin(A),B=T.y+L*Math.cos(A);let R=null,Y=null,G=!1;const z=1;if(Math.hypot(I.x-T.x,I.y-T.y)<z||Math.hypot(I.x-W,I.y-B)<z?(R=I.x,Y=I.y):(Math.hypot(P-T.x,_-T.y)<z||Math.hypot(P-W,_-B)<z)&&(R=P,Y=_,G=!0),R!==null&&Y!==null){const O=s[m[0].boneId]||[1,0,0,1,0,0],F=O[0]*O[3]-O[1]*O[2];let Z=0,st=0;if(F!==0){const at=(O[2]*O[5]-O[3]*O[4])/F,ct=(O[1]*O[4]-O[0]*O[5])/F,dt=Math.atan2(-O[1],O[3]);if(!G)Z=at,st=ct;else{const N=-O[2]/F,ot=O[0]/F,bt=Math.hypot(N,ot),St=I.length*bt;Z=at-St*Math.sin(dt),st=ct+St*Math.cos(dt)}const $=Math.hypot(g-Z,y-st),X=Math.hypot(u-R,p-Y);if(X>0&&$>0){const N=Math.max(X,.01),ot=Math.min($/N,3),bt=R+(u-R)*ot,St=Y+(p-Y)*ot,Mt=m[0].amount,pt=m[1].amount,wt=Math.min(Mt,pt)*2,yt=1-Math.pow(1-wt,4);u=u*(1-yt)+bt*yt,p=p*(1-yt)+St*yt}}}}}const S=o.rotation*Math.PI/180,v=Math.cos(S),C=Math.sin(S),w=u-o.x,M=p-o.y;return{x:(w*v+M*C)/i,y:(-w*C+M*v)/n}};return b.map((r,c)=>{const d=t[c];if(!d||d.length===0)return{...r};const u={...r,...a(r.x,r.y,d)};if(r.in_x!==void 0&&r.in_y!==void 0){const p=a(r.in_x,r.in_y,d);u.in_x=p.x,u.in_y=p.y}if(r.out_x!==void 0&&r.out_y!==void 0){const p=a(r.out_x,r.out_y,d);u.out_x=p.x,u.out_y=p.y}return u})};function ni(b,t,s,o,e){const i=b*s*.01,n=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(i+a)*Math.cos(n+r)+.5*Math.sin(i*2.1-r)*Math.cos(n*2.3+a)+.25*Math.sin(i*4.5+a)*Math.cos(n*4.2-r))/1.75*o}function oi(b,t,s,o,e,i,n=0,a=0){const r=[];if(!b)return[];const c=b.type;if(c==="Rectangle"||c==="Image"||c==="Frame"){const h=Math.max(20,Math.floor((t+s)/10)),f=Math.max(2,Math.floor(h*(t/(t+s)))),g=Math.max(2,Math.floor(h*(s/(t+s))));for(let y=0;y<f;y++)r.push({x:-t/2+t/f*y,y:-s/2,nx:0,ny:-1});for(let y=0;y<g;y++)r.push({x:t/2,y:-s/2+s/g*y,nx:1,ny:0});for(let y=0;y<f;y++)r.push({x:t/2-t/f*y,y:s/2,nx:0,ny:1});for(let y=0;y<g;y++)r.push({x:-t/2,y:s/2-s/g*y,nx:-1,ny:0})}else if(c==="Ellipse"){const h=Math.max(60,Math.floor(Math.PI*Math.max(t,s)/5));for(let f=0;f<h;f++){const g=f/h*Math.PI*2,y=Math.cos(g),m=Math.sin(g);r.push({x:y*t/2,y:m*s/2,nx:y,ny:m})}}else if(c==="Triangle"){const h={x:0,y:-s/2},f={x:t/2,y:s/2},g={x:-t/2,y:s/2},y=20;let m=f.x-h.x,S=f.y-h.y,v=Math.hypot(m,S),C=-S/v,w=m/v;for(let M=0;M<y;M++)r.push({x:h.x+m*(M/y),y:h.y+S*(M/y),nx:C,ny:w});m=g.x-f.x,S=g.y-f.y,v=Math.hypot(m,S),C=-S/v,w=m/v;for(let M=0;M<y;M++)r.push({x:f.x+m*(M/y),y:f.y+S*(M/y),nx:C,ny:w});m=h.x-g.x,S=h.y-g.y,v=Math.hypot(m,S),C=-S/v,w=m/v;for(let M=0;M<y;M++)r.push({x:g.x+m*(M/y),y:g.y+S*(M/y),nx:C,ny:w})}else for(let f=0;f<80;f++){const g=f/80*Math.PI*2,y=Math.cos(g),m=Math.sin(g);r.push({x:y*t/2,y:m*s/2,nx:y,ny:m})}const d=n*Math.PI/180,u=Math.cos(d),p=Math.sin(d);return r.map(h=>{const f=ni(h.x,h.y,e,o,i),g=h.nx*(1-a)+u*a,y=h.ny*(1-a)+p*a;let m=Math.hypot(g,y);return m===0&&(m=1),{x:h.x+g/m*f,y:h.y+y/m*f}})}const us={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}},gs={default:{label:"Default",colors:["#6366f1","#22d3ee","#f59e0b","#ec4899","#34d399"],cardBackground:"rgba(255,255,255,0.04)",cardBorderColor:"rgba(255,255,255,0.08)",legendColor:"rgba(255,255,255,0.65)",labelColor:"#ffffff",centerTextColor:"#ffffff",centerLabelColor:"rgba(255,255,255,0.4)"},neon:{label:"Neon",colors:["#00f5ff","#ff00e5","#00ff9f","#ff6b00","#b400ff"],cardBackground:"rgba(0,0,0,0.55)",cardBorderColor:"rgba(0,245,255,0.2)",legendColor:"rgba(0,245,255,0.75)",labelColor:"#ffffff",centerTextColor:"#00f5ff",centerLabelColor:"rgba(0,245,255,0.5)"},pastel:{label:"Pastel",colors:["#a5b4fc","#67e8f9","#fcd34d","#f9a8d4","#6ee7b7"],cardBackground:"rgba(255,255,255,0.06)",cardBorderColor:"rgba(255,255,255,0.12)",legendColor:"rgba(255,255,255,0.6)",labelColor:"#1a1a2e",centerTextColor:"#ffffff",centerLabelColor:"rgba(255,255,255,0.45)"},warm:{label:"Warm",colors:["#f97316","#ef4444","#f59e0b","#dc2626","#fb923c"],cardBackground:"rgba(30,10,0,0.45)",cardBorderColor:"rgba(249,115,22,0.2)",legendColor:"rgba(253,186,116,0.8)",labelColor:"#ffffff",centerTextColor:"#fb923c",centerLabelColor:"rgba(253,186,116,0.5)"},ocean:{label:"Ocean",colors:["#06b6d4","#0ea5e9","#38bdf8","#7dd3fc","#0284c7"],cardBackground:"rgba(0,20,40,0.5)",cardBorderColor:"rgba(6,182,212,0.2)",legendColor:"rgba(125,211,252,0.75)",labelColor:"#ffffff",centerTextColor:"#38bdf8",centerLabelColor:"rgba(125,211,252,0.5)"},mono:{label:"Mono",colors:["rgba(255,255,255,0.9)","rgba(255,255,255,0.65)","rgba(255,255,255,0.45)","rgba(255,255,255,0.28)","rgba(255,255,255,0.15)"],cardBackground:"rgba(255,255,255,0.03)",cardBorderColor:"rgba(255,255,255,0.1)",legendColor:"rgba(255,255,255,0.55)",labelColor:"#000000",centerTextColor:"#ffffff",centerLabelColor:"rgba(255,255,255,0.4)"}};class ys{constructor(){nt(this,"artboard",null);nt(this,"objectStates",new Map);nt(this,"physicsEngine",null);nt(this,"activeStateMachine",null);nt(this,"inputs",new Map);nt(this,"inputNameMap",new Map);nt(this,"layerStates",new Map);nt(this,"pretextCache",new Map);nt(this,"pointerHistory",[]);nt(this,"MAX_HISTORY",200);nt(this,"imageCache",new Map);nt(this,"lastValidSvgImgMap",new Map);nt(this,"maskBuffer",null);nt(this,"maskCtx",null);nt(this,"lumaBuffer",null);nt(this,"lumaCtx",null);nt(this,"_noiseTileCanvas",null);nt(this,"layout",{fit:"Contain",alignment:"Center"});nt(this,"onTrigger");nt(this,"onInputUpdate");nt(this,"onComponentChange");nt(this,"onToggle");nt(this,"onInputChange");nt(this,"onInputFocus");nt(this,"onInputBlur");nt(this,"onLog");nt(this,"onButtonClick");nt(this,"onGraphPointClick");nt(this,"justFiredTriggers",new Set);nt(this,"rootTransform",null);nt(this,"canvasWidth",0);nt(this,"canvasHeight",0);nt(this,"lastHoveredObjectId",null);nt(this,"_lastPointerPos",null);nt(this,"_prevPointerPos",null);nt(this,"_mouseDelta",{dx:0,dy:0});nt(this,"focusedId",null);nt(this,"draggingSliderId",null);nt(this,"draggingJoystickId",null);nt(this,"activeDropdownId",null);nt(this,"activeObjectId",null);nt(this,"draggingListViewId",null);nt(this,"scrollOffset",{x:0,y:0});nt(this,"_totalScroll",{x:0,y:0});nt(this,"draggingBehaviors",new Set);nt(this,"dragStartPointer",null);nt(this,"dragStartPositions",new Map);nt(this,"isMouseDown",!1);nt(this,"activeKeys",new Set);nt(this,"_layoutAnimCache",new Map);nt(this,"_springChainState",new Map);nt(this,"_emitterPools",new Map);nt(this,"objectVelocities",new Map);nt(this,"currentTime",0);nt(this,"frameCount",0);nt(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});nt(this,"onLogicUpdate");nt(this,"logicNodeValues",new Map);nt(this,"logicNodeState",new Map);nt(this,"pointerDownTimes",new Map);nt(this,"activeHoverIds",new Set);nt(this,"onNavigation");nt(this,"periodicTriggerTimes",new Map);nt(this,"wasInView",new Set);nt(this,"scrollProgressLastValue",new Map);nt(this,"debug_objectsRendered",0);nt(this,"debug_objectsTotal",0);nt(this,"lastRenderTime",0);nt(this,"debugMode",!1);nt(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 i=!1,n=0,a=0,r=0,c=0,d=0,u=0,p;for(;(p=s.exec(t))!==null;){const l=p[1],h=(p[2].match(o)||[]).map(parseFloat),f=l===l.toLowerCase(),g=l.toUpperCase();let y=0;const m=v=>{let C=h[y++];return f&&(C+=v?n:a),C},S=()=>({x:m(!0),y:m(!1)});switch(g){case"M":{const v=S();for(d=n=v.x,u=a=v.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a,moveTo:!0});y<h.length;){const C=S();n=C.x,a=C.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}case"L":for(;y<h.length;){const v=S();n=v.x,a=v.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break;case"H":for(;y<h.length;)n=m(!0),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"V":for(;y<h.length;)a=m(!1),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"C":for(;y<h.length;){const v=S(),C=S(),w=S();if(e.length>0){const M=e[e.length-1];M.out_x=v.x,M.out_y=v.y}n=w.x,a=w.y,e.push({x:n,y:a,in_x:C.x,in_y:C.y,out_x:n,out_y:a}),r=C.x,c=C.y}break;case"S":for(;y<h.length;){const v={x:2*n-r,y:2*a-c},C=S(),w=S();if(e.length>0){const M=e[e.length-1];M.out_x=v.x,M.out_y=v.y}n=w.x,a=w.y,e.push({x:n,y:a,in_x:C.x,in_y:C.y,out_x:n,out_y:a}),r=C.x,c=C.y}break;case"Q":for(;y<h.length;){const v=S(),C=S();if(e.length>0){const w=e[e.length-1];w.out_x=w.x+2/3*(v.x-w.x),w.out_y=w.y+2/3*(v.y-w.y)}n=C.x,a=C.y,e.push({x:n,y:a,in_x:n+2/3*(v.x-n),in_y:a+2/3*(v.y-a),out_x:n,out_y:a}),r=v.x,c=v.y}break;case"T":for(;y<h.length;){const v={x:2*n-r,y:2*a-c},C=S();if(e.length>0){const w=e[e.length-1];w.out_x=w.x+2/3*(v.x-w.x),w.out_y=w.y+2/3*(v.y-w.y)}n=C.x,a=C.y,e.push({x:n,y:a,in_x:n+2/3*(v.x-n),in_y:a+2/3*(v.y-a),out_x:n,out_y:a}),r=v.x,c=v.y}break;case"Z":if(i=!0,e.length>0){const v=e[e.length-1];v.closePath=!0;const C=[...e].reverse().find(w=>w.moveTo)||e[0];C&&Math.hypot(C.x-v.x,C.y-v.y)<.1&&(C.in_x=v.in_x,C.in_y=v.in_y,e.pop(),e.length>0&&(e[e.length-1].closePath=!0))}n=d,a=u;break;default:if(h.length>=2){const v=S();n=v.x,a=v.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}}return{points:e,isClosed:i}}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 i;const e=(i=this.artboard)==null?void 0:i.objects.find(n=>n.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){var e,i;if(!this.artboard)return;const o=this.artboard.objects.find(n=>n.id===t||n.name===t);if(o&&((e=o.geometry)==null?void 0:e.type)==="LineGraph"){const n=o.geometry;!n.datasets||n.datasets.length===0?n.datasets=[{id:"default",label:"Runtime Data",data:s,lineColor:"#3b82f6",lineWidth:2,showArea:!1}]:n.datasets[0].data=s;const a=this.objectStates.get(o.id);a&&((i=a.geometry)==null?void 0:i.type)==="LineGraph"&&(!a.geometry.datasets||a.geometry.datasets.length===0?a.geometry.datasets=JSON.parse(JSON.stringify(n.datasets)):a.geometry.datasets[0].data=[...s]),n.datasets[0].inputId&&this.updateInput(n.datasets[0].inputId,s)}else this.updateInput(t,s)}load(t){var n,a;if(!t)return;let s=this.decompressStrings(t);const o=[],e=new Set,i=r=>{r&&r.forEach(c=>{if(e.has(c.id))return;const d={...c},u=d.childrenObjects||[];e.add(d.id),o.push(d),i(u)})};if(i(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: "${(n=this.artboard)==null?void 0:n.name}" with ${(a=this.artboard)==null?void 0:a.objects.length} objects`),this.artboard&&this.artboard.objects){const r=new Map;this.artboard.objects.forEach(c=>{r.set(c.id,c),c.children||(c.children=[])}),this.artboard.objects.forEach(c=>{if(c.parentId){const d=r.get(c.parentId);d&&(d.children||(d.children=[]),d.children.includes(c.id)||d.children.push(c.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=i=>{console.error("[ExodeUI Preload] failed:",i,`Src: ${o.substring(0,80)}...`)},e.src=o,this.imageCache.set(o,e)};t.objects.forEach(o=>{var e,i,n;(e=o.geometry)!=null&&e.src&&s(o.geometry.src),(n=(i=o.style)==null?void 0:i.fill)!=null&&n.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 n,a,r,c,d,u,p;const o=s.width??((n=s.geometry)==null?void 0:n.width)??0,e=s.height??((a=s.geometry)==null?void 0:a.height)??0,i=s.cornerRadius??s.corner_radius??((r=s.geometry)==null?void 0:r.corner_radius)??((c=s.geometry)==null?void 0:c.cornerRadius)??0;this.objectStates.set(s.id,{...s.transform||{},x:((d=s.transform)==null?void 0:d.x)??s.x??0,y:((u=s.transform)==null?void 0:u.y)??s.y??0,width:o,height:e,cornerRadius:i,corner_radius:i,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:((p=s.transform)==null?void 0:p.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 i,n;if((i=e.physics)!=null&&i.enabled&&e.type==="Shape"){const a=this.objectStates.get(e.id);if(!a)return;const r=e.geometry.width||100,c=e.geometry.height||100;this.physicsEngine.createBody({id:e.id,type:((n=e.geometry)==null?void 0:n.type)||"Rectangle",x:a.x,y:a.y,width:r,height:c,rotation:a.rotation*(Math.PI/180),isStatic:e.physics.bodyType==="Static",mass:e.physics.mass,friction:e.physics.friction,restitution:e.physics.restitution,frictionAir:e.physics.frictionAir,density:e.physics.density,isSensor:e.physics.isSensor})}}))})}this.artboard.stateVariables&&this.artboard.stateVariables.forEach(s=>{var i,n;let o=s.value;if(s.type==="RandomNumber"||s.type==="random_number"||s.min!==void 0&&s.max!==void 0&&((i=s.type)!=null&&i.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&&((n=s.type)!=null&&n.toLowerCase().includes("random"))){const a=Math.floor(Math.random()*256),r=Math.floor(Math.random()*256),c=Math.floor(Math.random()*256),d=s.minAlpha??0,u=s.maxAlpha??1,p=(Math.random()*(u-d)+d).toFixed(2);o=`rgba(${a}, ${r}, ${c}, ${p})`}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 i;if(!this.artboard)return;const s=new Map;this.artboard.objects.forEach(n=>s.set(n.id,n));const o=.15,e=n=>{n.forEach(a=>{const r=this.objectStates.get(a.id);if(r){const c=Math.abs(r.x-a.x),d=Math.abs(r.y-a.y);!t&&(c>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((i=this.artboard.autoLayout)!=null&&i.enabled){const n=this.artboard.objects.filter(r=>!r.parentId),a=ss(this.artboard,n,r=>this.objectStates.get(r));e(a.childUpdates)}this.artboard.objects.forEach(n=>{var a;if(n.type==="Frame"&&((a=n.autoLayout)!=null&&a.enabled)&&n.children&&n.children.length>0){const r=n.children.map(u=>s.get(u)).filter(u=>!!u),c=this.objectStates.get(n.id);if(!c)return;const d=ss(c,r,u=>this.objectStates.get(u));d.frameWidth!==void 0&&(c.width=d.frameWidth),d.frameHeight!==void 0&&(c.height=d.frameHeight),e(d.childUpdates)}})}loadFonts(){if(!this.artboard)return;const t=new Set;if(this.artboard.objects.forEach(n=>{n.geometry&&n.geometry.type==="Text"&&n.geometry.fontFamily&&t.add(n.geometry.fontFamily)}),this.artboard.animations.forEach(n=>{n.tracks.forEach(a=>{(a.property==="geometry.fontFamily"||a.property==="fontFamily")&&a.keyframes.forEach(r=>{r.value&&typeof r.value=="string"&&t.add(r.value)})})}),t.size===0)return;let s="";t.forEach(n=>{const a=n.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 n=`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!==n&&(a.href=n)}const i=[];if(t.forEach(n=>{n.toLowerCase().includes("clash display")&&i.push("clash-display@200,300,400,500,600,700")}),i.length>0){const n=`https://api.fontshare.com/v2/css?f[]=${i.join("&f[]=")}&display=swap`;let a=document.getElementById(e);a||(a=document.createElement("link"),a.id=e,a.rel="stylesheet",document.head.appendChild(a)),a.href!==n&&(a.href=n)}document.fonts&&document.fonts.ready&&document.fonts.ready.then(()=>{this.pretextCache.clear(),this.advance(0)})}enterStates(t,s){var n;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 i=0;if(this.artboard&&this.activeStateMachine){const a=this.activeStateMachine.layers.find(r=>r.name===t);if(a)for(const r of s){const c=a.states.find(d=>d.id===r);if(c)if(c.isBlendState&&c.blendAnimations&&c.blendAnimations.length>0)e.push({animation:null,state:c}),c.blendAnimations.forEach(d=>{const u=this.artboard.animations.find(p=>p.id===d.animationId);u&&(i=Math.max(i,this.getAnimationDuration(u)))});else{let d=null;c.animationId&&(d=this.artboard.animations.find(u=>u.id===c.animationId)||null),d||(d=this.artboard.animations.find(u=>{var p,l;return u.name===c.name||u.id===c.name||(c.name==="Entry"||c.id==="entry")&&(((p=u.name)==null?void 0:p.toLowerCase())==="onload"||((l=u.name)==null?void 0:l.toLowerCase())==="intro")})||null),d&&((n=this.artboard.animationFlow)!=null&&n.some(p=>(p.trigger==="on_load"||p.trigger==="after_delay")&&p.targetAnimationId===(d==null?void 0:d.id))||(e.push({animation:d,state:c}),i=Math.max(i,this.getAnimationDuration(d))))}}}this.layerStates.set(t,{currentStateIds:s,animations:e,time:0,duration:i})}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 i=s.replace(/\[(\d+)\]/g,".$1").split(".");let n=e;for(let a=0;a<i.length-1;a++){if(typeof n[i[a]]!="object"||n[i[a]]===null){const r=i[a+1],c=!isNaN(Number(r));n[i[a]]=c?[]:{}}n=n[i[a]]}n[i[i.length-1]]=o}else e[s]=o}updateInput(t,s){var a,r,c,d,u;let o;if(this.inputs.has(t)){const p=(a=this.activeStateMachine)==null?void 0:a.inputs.find(l=>l.id===t);p&&typeof p.value=="object"&&(o=p.value.type)}else{const p=this.inputNameMap.get(t);if(p&&p.length>0){const l=(r=this.activeStateMachine)==null?void 0:r.inputs.find(h=>h.id===p[0]);l&&typeof l.value=="object"&&(o=l.value.type)}}let e=s;o==="Trigger"&&(s===1?e=!0:s===0&&(e=!1));const i=(d=(c=this.artboard)==null?void 0:c.stateVariables)==null?void 0:d.find(p=>p.id===t||p.name===t);if(i&&(i.type==="RandomNumber"||i.type==="RandomColor"||i.type&&String(i.type).toLowerCase().includes("random"))){if(i.type==="RandomNumber"||i.type==="random_number"||i.min!==void 0&&i.max!==void 0){const p=i.min??0,l=i.max??100;e=Math.random()*(l-p)+p}else if(i.type==="RandomColor"||i.type==="random_color"||i.minAlpha!==void 0){const p=Math.floor(Math.random()*256),l=Math.floor(Math.random()*256),h=Math.floor(Math.random()*256),f=i.minAlpha??0,g=i.maxAlpha??1,y=(Math.random()*(g-f)+f).toFixed(2);e=`rgba(${p}, ${l}, ${h}, ${y})`}}this.inputs.has(t)&&this.setInternalInput(t,e);const n=this.inputNameMap.get(t);n&&n.forEach(p=>this.setInternalInput(p,e)),o==="Trigger"&&e===!0&&(this.justFiredTriggers.add(t),n&&n.forEach(p=>this.justFiredTriggers.add(p))),Array.isArray(e)&&((u=this.artboard)==null||u.objects.forEach(p=>{if(p.inputId===t||p.name===t){const l=this.objectStates.get(p.id);l&&l.options&&(p.type==="ListView"||p.variant==="listview"?l.options.items=e:(p.type==="Dropdown"||p.variant==="dropdown")&&(l.options.optionsList=e))}})),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(i=>{if(i.trigger==="variable"&&i.conditionVariableId&&i.targetAnimationId&&(i.conditionVariableId===t||e&&e.includes(i.conditionVariableId))){const a=i.conditionOperator||"IsTrue",r=i.conditionValue;let c=!1;switch(a){case"Equal":case"==":c=s==r;break;case"NotEqual":case"!=":c=s!=r;break;case"GreaterThan":case">":c=s>r;break;case"LessThan":case"<":c=s<r;break;case"GreaterEqual":case">=":c=s>=r;break;case"LessEqual":case"<=":c=s<=r;break;case"IsTrue":c=!!s;break;case"IsFalse":c=!s;break}if(c){const d=i.delay||0;d<=0?this.triggerGlobalAnimation(i.targetAnimationId,i.subAnimationIds,i.loop,i.id):setTimeout(()=>this.triggerGlobalAnimation(i.targetAnimationId,i.subAnimationIds,i.loop,i.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 i of s.currentStateIds){const n=t.states.find(r=>r.id===i);if(!n)continue;let a=!1;for(const r of n.transitions||[])this.checkConditions(r.conditions)&&(o.push(r.targetStateId),a=!0,e=!0);a||o.push(i)}if(!e){const i=this.findGlobalTransition(t,s.currentStateIds);i&&(o.length=0,o.push(i.targetStateId),e=!0,i.conditions&&(i.conditions||[]).forEach(n=>{var r;const a=(r=this.activeStateMachine)==null?void 0:r.inputs.find(c=>c.id===n.inputId);a&&typeof a.value=="object"&&a.value.type==="Trigger"&&this.setInternalInput(n.inputId,!1)}))}if(e){const i=Array.from(new Set(o));this.enterStates(t.name,i)}}),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(i=>i.id===t);s&&this.inputNameMap.has(s.name)&&((e=this.inputNameMap.get(s.name))==null||e.forEach(i=>this.setInternalInput(i,!1)))}),this.justFiredTriggers.clear()))}findGlobalTransition(t,s){for(const o of t.states)if(!(s.includes(o.id)&&this.justFiredTriggers.size===0)){for(const i of o.transitions||[])if(!(s.includes(i.targetStateId)&&this.justFiredTriggers.size===0)&&this.checkConditions(i.conditions))return i}return null}checkConditions(t){return!t||t.length===0?!0:t.every(s=>{const o=s.inputId,e=s.op;let i=s.value;const n=this.evaluateLogicTree(o);if(n===void 0)return this.log(`[Engine] Condition Check Failed: Input ${o} is undefined`),!1;typeof n=="boolean"?i==="true"||i==="1"||i===1?i=!0:(i==="false"||i==="0"||i===0)&&(i=!1):typeof n=="number"&&typeof i=="string"&&(i=parseFloat(i));let a=!1;switch(e){case"Equal":case"==":a=n==i;break;case"NotEqual":case"!=":a=n!=i;break;case"GreaterThan":case">":a=n>i;break;case"LessThan":case"<":a=n<i;break;case"GreaterEqual":case">=":a=n>=i;break;case"LessEqual":case"<=":a=n<=i;break;case"IsTrue":a=!!n;break;case"IsFalse":a=!n;break;default:a=!1}return a||this.justFiredTriggers.has(o),a})}evaluateLogicTree(t,s=null,o=new Set){var a,r,c,d,u,p;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(l=>l.id===t);if(e){const l=(f,g)=>{const y=e.inputs.find(m=>m.id===f);return y?y.sourceId?this.evaluateLogicTree(y.sourceId,y.sourceHandleId,o):y.value!==void 0?y.value:g:g};let h=0;switch(e.op){case Ct.AND:h=l("a",!1)&&l("b",!1);break;case Ct.OR:h=l("a",!1)||l("b",!1);break;case Ct.NOT:h=!l("in",!1);break;case Ct.XOR:h=!!l("a",!1)!=!!l("b",!1);break;case Ct.OBJECT:h=e.name;break;case Ct.PROPERTY:case Ct.GET_PROPERTY:{const f=l("id","");if(!f){h=0;break}const g=e.name;if(!g||g==="GET_PROPERTY"||g==="PROPERTY"){h=0;break}const y=this.objectStates.get(f);if(!y){h=0;break}g in y?h=y[g]:h=this.resolvePath(y,g);break}case Ct.SET_PROPERTY:{const f=l("id",""),g=l("value",void 0);if(!f||g===void 0){h=0;break}const y=e.name;if(!y||y==="SET_PROPERTY"){h=0;break}const m=this.objectStates.get(f);if(!m){h=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(y))m[y]=g,h=g;else{const v=y.replace(/\[(\d+)\]/g,".$1").split(".");let C=m;for(let M=0;M<v.length-1;M++){const I=v[M],T=v[M+1];C[I]===void 0&&(C[I]=isNaN(Number(T))?{}:[]),C=C[I]}const w=v[v.length-1];C[w]=g,h=g}break}case Ct.ADD:h=l("a",0)+l("b",0);break;case Ct.SUB:h=l("a",0)-l("b",0);break;case Ct.MUL:h=l("a",0)*l("b",0);break;case Ct.DIV:{const f=l("b",1);h=f===0?0:l("a",0)/f;break}case Ct.MOD:h=l("a",0)%l("b",1);break;case Ct.POW:h=Math.pow(l("a",0),l("b",1));break;case Ct.ABS:h=Math.abs(l("in",0));break;case Ct.ROUND:h=Math.round(l("in",0));break;case Ct.FLOOR:h=Math.floor(l("in",0));break;case Ct.CEIL:h=Math.ceil(l("in",0));break;case Ct.SIN:h=Math.sin(l("in",0));break;case Ct.COS:h=Math.cos(l("in",0));break;case Ct.TAN:h=Math.tan(l("in",0));break;case Ct.CLAMP:{const f=l("in",0),g=l("min",0),y=l("max",1);h=Math.max(g,Math.min(y,f));break}case Ct.REMAP:{const f=l("in",0),g=l("inMin",0),y=l("inMax",100),m=l("outMin",0),S=l("outMax",1);h=y===g?m:m+(f-g)*(S-m)/(y-g);break}case Ct.EQ:h=l("a",0)==l("b",0);break;case Ct.NEQ:h=l("a",0)!=l("b",0);break;case Ct.GT:h=l("a",0)>l("b",0);break;case Ct.LT:h=l("a",0)<l("b",0);break;case Ct.GTE:h=l("a",0)>=l("b",0);break;case Ct.LTE:h=l("a",0)<=l("b",0);break;case Ct.IF_ELSE:h=l("cond",!1)?l("then",0):l("else",0);break;case Ct.VALUE:h=e.value!==void 0?e.value:0;break;case Ct.INPUT:h=this.inputs.get(e.name)??0;break;case Ct.LOG:{const f=l("in","");this.debugLog(`[User Logic] ${f}`),h=f;break}case Ct.SCROLL_X:h=this.inputs.get("scrollX")??0;break;case Ct.SCROLL_Y:h=this.inputs.get("scrollY")??0;break;case Ct.MOUSE_X:h=this.inputs.get("mouseX")??0;break;case Ct.MOUSE_Y:h=this.inputs.get("mouseY")??0;break;case Ct.IS_MOUSE_DOWN:h=this.inputs.get("isMouseDown")??!1;break;case Ct.EFFECTOR:{const f=l("id",""),g=l("intensity",1),y=l("trigger",!0);if(!f||!y){h=0;break}const m=e.name;if(!m){h=0;break}const S=this.objectStates.get(f);if(!S){h=0;break}if(["glitch","halftone","pixelate","noise","acid_gradient","acid_rave","shimmer"].includes(m))S.style||(S.style={}),S.style.artEffect={enabled:!0,type:m,intensity:g},h=1;else{S.behaviors||(S.behaviors=[]);let C=S.behaviors.find(w=>w.type===m);C?(C.enabled=!0,C.settings||(C.settings={}),C.settings.intensity=g):(C={id:`eff_${Date.now()}_${m}`,type:m,enabled:!0,sensors:[],settings:{intensity:g}},S.behaviors.push(C)),h=1}break}case Ct.MONITOR:{h=l("in",0);break}case Ct.SPRING_PULL:{const f=l("objectId",""),g=l("forceX",0),y=l("forceY",0);f&&((c=this.artboard)==null||c.objects.forEach(m=>{m.behaviors&&m.behaviors.forEach(S=>{var v;if(S.type===H.SpringChain&&((v=S.settings)!=null&&v.connections)&&(S.settings.connections.some(w=>w.targetId===f)||m.id===f)){this._springChainState.has(m.id)||this._springChainState.set(m.id,new Map);const w=this._springChainState.get(m.id);if(!w.has(f)){const I=this.objectStates.get(f);w.set(f,{x:(I==null?void 0:I.x)??0,y:(I==null?void 0:I.y)??0,vx:0,vy:0})}const M=w.get(f);M&&(M.vx+=g,M.vy+=y)}})})),h=1;break}case Ct.SPRING_SETTLE:{const f=l("objectId","");let g=!0;if(f){const y=l("threshold",1);this._springChainState.forEach(m=>{const S=m.get(f);S&&(Math.abs(S.vx)>y||Math.abs(S.vy)>y)&&(g=!1)})}h=g;break}case Ct.EMIT:{const f=l("objectId",""),g=l("count",20);f&&((d=this.artboard)==null||d.objects.forEach(y=>{y.behaviors&&y.behaviors.forEach(m=>{m.type===H.ParticleEmitter&&y.id===f&&(m._pendingBurst=(m._pendingBurst||0)+g)})})),h=1;break}default:h=0;break}if(this.logicNodeValues.set(t,h),e.op===Ct.DELAY){const f=l("delay",0),g=l("in",0);let y=this.logicNodeState.get(t);for(y||(y={queue:[]},this.logicNodeState.set(t,y)),y.queue.push({time:this.currentTime+f,value:g});y.queue.length>0&&y.queue[0].time<=this.currentTime;)y.lastValue=y.queue.shift().value;h=y.lastValue??0}return h}const i=(u=this.activeStateMachine)==null?void 0:u.inputs.find(l=>l.id===t||l.name===t);if(i&&i.sourceId&&!o.has(i.sourceId)){const l=this.evaluateLogicTree(i.sourceId,i.sourceHandleId,o);return this.inputs.set(i.id,l),l}let n=this.inputs.get(t)??(i?this.inputs.get(i.id):void 0);if((this.justFiredTriggers.has(t)||i&&this.justFiredTriggers.has(i.id))&&(n=!0),s&&n!==void 0){const l=(p=this.activeStateMachine)==null?void 0:p.inputs.find(h=>h.id===t);if(l&&l.value.type==="Number"&&typeof n=="number"){const h=l.value.defaultValue??l.value.value;if(s==="source-greater")return n>h;if(s==="source-less")return n<h;if(s==="source-equal")return n===h}if(s==="source-true")return n===!0;if(s==="source-false")return n===!1;if(s==="source-fire")return this.justFiredTriggers.has(t)}return n!==void 0?n:0}runLogicNodes(){!this.activeStateMachine||!this.activeStateMachine.logicNodes||this.activeStateMachine.logicNodes.forEach(t=>{(t.op===Ct.SET_PROPERTY||t.op===Ct.EFFECTOR)&&this.evaluateLogicTree(t.id)})}resolvePath(t,s){const o=s.replace(/\[(\d+)\]/g,".$1").split(".");let e=t;for(const i of o)if(e&&typeof e=="object"&&i in e)e=e[i];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 i;if(e.valueType==="variable"?i=this.getInputValue(e.variableId):e.valueType==="constant"&&(i=e.value),i!==void 0){const n=e.name;if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(n))o[n]=i;else{const r=n.replace(/\[(\d+)\]/g,".$1").split(".");let c=o;for(let u=0;u<r.length-1;u++){const p=r[u],l=r[u+1];c[p]===void 0&&(c[p]=isNaN(Number(l))?{}:[]),c=c[p]}const d=r[r.length-1];c[d]=i}}})}})}seek(t){this.artboard&&(this.currentTime=t,this.layerStates.forEach(s=>{s.time=t,s.time>(s.duration||0)&&(s.animations.some(e=>{var i;return((i=e.state)==null?void 0:i.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 i=this.physicsEngine.getPosition(o.id),n=this.physicsEngine.getRotation(o.id),a=this.objectStates.get(o.id);a&&i!==null&&n!==null&&(a.x=i.x,a.y=i.y,a.rotation=n*(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(n=>{var a;return((a=n.state)==null?void 0:a.loop)===!0}))o.time%=o.duration;else{const n=o.time<o.duration+.1;o.time=o.duration,n&&(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(i=>{var n;(n=i.state)!=null&&n.isBlendState&&i.state.blendAnimations?this.applyBlendState(i.state,o.time):i.animation&&this.applyAnimation(i.animation,o.time,i.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 i,n,a,r,c,d,u;if(o.phase==="entry")o.time+=t,o.time>=this.getAnimationDuration(o.animation)&&((a=(n=(i=this.artboard)==null?void 0:i.objects.find(p=>p.id===e))==null?void 0:n.triggers)==null||a.find(p=>p.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 p=(d=(c=(r=this.artboard)==null?void 0:r.objects.find(f=>f.id===e))==null?void 0:c.triggers)==null?void 0:d.find(f=>f.id===o.triggerId),l=(p==null?void 0:p.duration)||0;o.elapsedHold+=t*1e3;let h=o.elapsedHold>=l;if((p==null?void 0:p.eventType)==="hover"&&!this.activeHoverIds.has(e)&&(h=!0),((p==null?void 0:p.eventType)==="onHold"||(p==null?void 0:p.eventType)==="pointerDown")&&!this.isMouseDown&&(h=!0),h)if(p!=null&&p.exitAnimationId){const f=(u=this.artboard)==null?void 0:u.animations.find(g=>g.id===p.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,i,n;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),c=(((i=s.geometry)==null?void 0:i.width)||100)*(r.scale_x||1),d=(((n=s.geometry)==null?void 0:n.height)||100)*(r.scale_y||1),u=50,p=r.x+c/2>=-this.canvasWidth/2-u&&r.x-c/2<=this.canvasWidth/2+u&&r.y+d/2>=-this.canvasHeight/2-u&&r.y-d/2<=this.canvasHeight/2+u,l=`analytics_${s.id}`,h=this.wasInView.has(l);p&&!h&&this.fireAnalyticsEvent(s.id,"visible"),p?this.wasInView.add(l):this.wasInView.delete(l)}}}),this.artboard.objects.forEach(s=>{const o=s.interactions||[];o.length!==0&&o.forEach(e=>{const i=e.triggers||[e.event||e.trigger];i&&i.forEach(n=>{var r,c,d;const a=n.toLowerCase();if(a==="on interval"||a==="oninterval"){const u=e.intervalValue||2e3,p=this.periodicTriggerTimes.get(e.id)||0;this.currentTime*1e3-p>=u&&(!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 u=e.delayValue||1e3;!this.periodicTriggerTimes.has(e.id)&&this.currentTime*1e3>=u&&(!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 u=this.objectStates.get(s.id);if(u&&u.visible!==!1){const p=this.getGlobalTransform(s.id),l=(((r=s.geometry)==null?void 0:r.width)||100)*(p.scale_x||1),h=(((c=s.geometry)==null?void 0:c.height)||100)*(p.scale_y||1),f=50,g=p.x+l/2>=-this.canvasWidth/2-f&&p.x-l/2<=this.canvasWidth/2+f&&p.y+h/2>=-this.canvasHeight/2-f&&p.y-h/2<=this.canvasHeight/2+f,y=this.wasInView.has(s.id);g&&!y&&(!e.conditions||this.checkConditions(e.conditions))&&this.fireEventForObject(s.id,"Scroll Into View"),g?this.wasInView.add(s.id):this.wasInView.delete(s.id)}}if(a==="scroll progress"||a==="scrollprogress"){const u=Math.abs(this.scrollOffset.y)/(((d=this.artboard)==null?void 0:d.height)||1e3),p=this.scrollProgressLastValue.get(e.id)||0;Math.abs(u-p)>.001&&(this.scrollProgressLastValue.set(e.id,u),(e.action==="Set Input"||e.action==="setInput")&&this.updateInput(e.targetInputId,u))}})})}))}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((i,n)=>{var d,u,p,l,h,f,g,y,m;const a=((d=o.constraints)==null?void 0:d[n])||{},r={...i,...a},c=r.strength??1;if(r.type==="Translation"){const S=this.getGlobalTransform(r.targetId);if(S){const v=r.offsetX||0,C=r.offsetY||0,w=S.x+v,M=S.y+C,I=r.useSpring;if(I){const E=this.objectVelocities.get(s.id)||{vx:0,vy:0},P=Math.max(0,Math.min(t,.05)),_=r.copyX!==!1,L=r.copyY!==!1,A=_?e.x+(w-e.x)*c:e.x,W=L?e.y+(M-e.y)*c:e.y,{x:B,y:R,vx:Y,vy:G}=this.computeSpring(e.x,e.y,E.vx,E.vy,A,W,r,P);_&&(e.x=B),L&&(e.y=R),this.objectVelocities.set(s.id,{vx:_?Y:0,vy:L?G:0})}else r.copyX!==!1&&(e.x=e.x+(w-e.x)*c),r.copyY!==!1&&(e.y=e.y+(M-e.y)*c);let T=!1,k=!1;if((u=r.limitX)!=null&&u.enabled){const E=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==E&&(T=!0)}if((p=r.limitY)!=null&&p.enabled){const E=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==E&&(k=!0)}if((T||k)&&I){const E=this.objectVelocities.get(s.id)||{vx:0,vy:0};this.objectVelocities.set(s.id,{vx:T?0:E.vx,vy:k?0:E.vy})}}}else if(r.type==="Rotation"){const S=this.getGlobalTransform(r.targetId);if(S){let C=(S.rotation+(r.offset||0)-e.rotation)%360;C>180&&(C-=360),C<-180&&(C+=360),e.rotation=e.rotation+C*c}}else if(r.type==="Scale"){const S=this.getGlobalTransform(r.targetId);S&&(r.copyX&&(e.scale_x=e.scale_x+(S.scale_x-e.scale_x)*c),r.copyY&&(e.scale_y=e.scale_y+(S.scale_y-e.scale_y)*c))}else if(r.type==="Transform"){const S=this.getGlobalTransform(r.targetId);if(S){e.x=e.x+(S.x-e.x)*c,e.y=e.y+(S.y-e.y)*c;let v=(S.rotation-e.rotation)%360;v>180&&(v-=360),v<-180&&(v+=360),e.rotation=e.rotation+v*c,e.scale_x=e.scale_x+(S.scale_x-e.scale_x)*c,e.scale_y=e.scale_y+(S.scale_y-e.scale_y)*c}}else if(r.type==="FollowPointer"){const S=((l=this._lastPointerPos)==null?void 0:l.x)??e.x,v=((h=this._lastPointerPos)==null?void 0:h.y)??e.y,C=r.useSpring;if(C){const M=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:I,y:T,vx:k,vy:E}=this.computeSpring(e.x,e.y,M.vx,M.vy,S,v,r,t);e.x=I,e.y=T,this.objectVelocities.set(s.id,{vx:k,vy:E})}else e.x=e.x+(S-e.x)*c,e.y=e.y+(v-e.y)*c;let w=!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&&(w=!0)}if((g=r.limitY)!=null&&g.enabled){const M=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==M&&(w=!0)}w&&C&&this.objectVelocities.set(s.id,{vx:0,vy:0})}else if(r.type==="Distance"){const S=this.getGlobalTransform(r.targetId);if(S){const v=e.x-S.x,C=e.y-S.y,w=Math.sqrt(v*v+C*C),M=r.distance||0;let I=w;switch(r.mode){case"exact":I=M;break;case"minimum":I=Math.max(M,w);break;case"maximum":I=Math.min(M,w);break;case"clamped":I=Math.max(0,Math.min(M,w));break}if(w>0){const T=e.x===S.x&&e.y===S.y?1:I/w;e.x=e.x+(S.x+v*T-e.x)*c,e.y=e.y+(S.y+C*T-e.y)*c}}}else if(r.type==="FollowPath"){const S=(y=this.artboard)==null?void 0:y.objects.find(v=>v.id===r.targetId);if(S){const v=this.getGlobalTransform(S.id);if(v){let C=S.geometry;if(S.type==="Frame"||S.type==="Group"||!C||C.type!=="Path"&&C.type!=="Ellipse"&&C.type!=="Rectangle"){const F=(m=this.artboard)==null?void 0:m.objects.find(Z=>Z.parentId===S.id&&Z.type==="Shape"&&Z.geometry&&(Z.geometry.type==="Path"||Z.geometry.type==="Ellipse"||Z.geometry.type==="Rectangle"));F&&(C=F.geometry)}if(!C)return;const w=Math.max(0,Math.min(1,(r.distance||0)/100)),M=v.width||C.width||0,I=v.height||C.height||0,T=this.getPointOnPath(C,M,I,w),k=v.rotation*Math.PI/180,E=Math.cos(k),P=Math.sin(k),_=T.x*v.scale_x*E-T.y*v.scale_y*P,L=T.x*v.scale_x*P+T.y*v.scale_y*E;let A=v.rotation+(r.offsetRotation||0);if(r.orient){const F=Math.cos(T.angle),Z=Math.sin(T.angle),st=F*v.scale_x*E-Z*v.scale_y*P,at=F*v.scale_x*P+Z*v.scale_y*E;A=Math.atan2(at,st)*180/Math.PI+(r.offsetRotation||0)}const W=A*Math.PI/180,B=Math.cos(W),R=Math.sin(W),Y=(r.offsetX||0)*B-(r.offsetY||0)*R,G=(r.offsetX||0)*R+(r.offsetY||0)*B,z=v.x+_+Y,O=v.y+L+G;if(e.x=e.x+(z-e.x)*c,e.y=e.y+(O-e.y)*c,r.orient){let F=(A-e.rotation)%360;F>180&&(F-=360),F<-180&&(F+=360),e.rotation=e.rotation+F*c}}}}else if(r.type==="IK"){const S=this.getGlobalTransform(r.targetId);S&&this.solveIK(s,S,r.boneCount||2,c)}}),s.constraints.some(i=>i.type!=="IK")){const i=this.globalToLocal(s.parentId,e);o.x=i.x,o.y=i.y,o.rotation=i.rotation,o.flip_x=i.scale_x<0,o.scale_x=Math.abs(i.scale_x),o.flip_y=i.scale_y<0,o.scale_y=Math.abs(i.scale_y)}})}getGlobalTransform(t){var u,p;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,rotation:0,scale_x:1,scale_y:1};const o=(u=this.artboard)==null?void 0:u.objects.find(l=>l.id===t),e=(o==null?void 0:o.type)==="Bone"?(p=o.geometry)==null?void 0:p.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 i=this.getGlobalTransform(o.parentId),n=i.rotation*Math.PI/180,a=Math.cos(n),r=Math.sin(n),c=i.x+(s.x*i.scale_x*a-s.y*i.scale_y*r),d=i.y+(s.x*i.scale_x*r+s.y*i.scale_y*a);return{x:c,y:d,rotation:i.rotation+s.rotation,scale_x:i.scale_x*(s.scale_x??1)*(s.flip_x?-1:1),scale_y:i.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,i=o.scale_y===0?0:1/o.scale_y,n=-o.rotation*Math.PI/180,a=Math.cos(n),r=Math.sin(n),c=s.x-o.x,d=s.y-o.y,u=(c*a-d*r)*e,p=(c*r+d*a)*i;return{x:u,y:p,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 c;const i=[];let n=t.id;for(let d=0;d<o&&n;d++){const u=(c=this.artboard)==null?void 0:c.objects.find(p=>p.id===n);if(!u)break;i.push({id:n,local:this.objectStates.get(n),global:this.getGlobalTransform(n)}),n=u.parentId}if(i.length<2)return;const a=i.reverse(),r=5;for(let d=0;d<r;d++){const u=this.getGlobalTransform(t.id);for(let p=a.length-2;p>=0;p--){const l=a[p],h=this.getGlobalTransform(l.id),f=u.x-h.x,g=u.y-h.y,y=s.x-h.x,m=s.y-h.y,S=Math.sqrt(f*f+g*g),v=Math.sqrt(y*y+m*m);if(S>.001&&v>.001){const C=Math.atan2(g,f);let M=(Math.atan2(m,y)-C)*180/Math.PI;M*=e;const I=this.objectStates.get(l.id);I&&(I.rotation+=M)}}}}computeSpring(t,s,o,e,i,n,a,r){const c=a.stiffness??100,d=a.damping??10,u=a.mass??1,p=-c*(t-i),l=-c*(s-n),h=-d*o,f=-d*e,g=(p+h)/u,y=(l+f)/u,m=o+g*r,S=e+y*r,v=t+m*r,C=s+S*r;return{x:v,y:C,vx:m,vy:S}}handlePointerInput(t,s,o,e,i){if(!this.artboard)return;const n=this.calculateTransform(e,i,this.artboard.width,this.artboard.height,this.layout.fit,this.layout.alignment),a=(s-n.tx)/n.scaleX,r=(o-n.ty)/n.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)}handleWheel(t,s){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,c,d,u,p;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 i=(l,h)=>{var v;let f=h;h==="click"?f="onClick":h==="down"?f="onPointerDown":h==="up"?f="onPointerUp":h==="blur"&&(f="onPointerLeave");const g=new Set([f]);h==="move"&&(g.add("onPointerEnter").add("hover").add("onPointerLeave").add("blur"),g.add("Drag").add("drag").add("ondrag")),f==="onClick"&&g.add("click"),f==="onPointerDown"&&g.add("pointerDown"),f==="onPointerUp"&&g.add("pointerUp");const y=["button","toggle","toggle_button","dropdown","listview","inputbox","slider","checkbox","radiogroup","joystick"];if(l.type==="Component"&&y.includes(l.variant)||l.type==="Joystick"||y.includes((v=l.type)==null?void 0:v.toLowerCase()))return!0;const m=l.interactions||[];return!!(m.some(C=>g.has(C.event))||m.some(C=>Array.isArray(C.triggers)&&C.triggers.some(w=>g.has(String(w))))||(l.triggers||[]).some(C=>g.has(C.eventType)))};let n=null;for(let l=this.artboard.objects.length-1;l>=0;l--){const h=this.artboard.objects[l],f=this.objectStates.get(h.id);if(f&&f.visible!==!1&&f.opacity>0&&this.hitTest(h,s,o)&&(n||(n=h),i(h,t))){e=h;break}}!e&&n&&(e=n),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 l=this.artboard.objects.find(h=>h.id===this.draggingSliderId);l&&this.updateSliderValueFromPointer(l,s,o);return}if(this.draggingJoystickId){const l=this.artboard.objects.find(h=>h.id===this.draggingJoystickId);l&&this.updateJoystickValueFromPointer(l,s,o);return}if(this.draggingListViewId){const l=this.artboard.objects.find(h=>h.id===this.draggingListViewId);l&&this.updateListViewScrollFromPointer(l);return}if(e&&(e.type==="ListView"||e.type==="Component"&&e.variant==="listview")&&this.updateListViewHoverFromPointer(e,s,o),this.isMouseDown&&this.dragStartPointer&&this.draggingBehaviors.size>0){const l=s-this.dragStartPointer.x,h=o-this.dragStartPointer.y;this.draggingBehaviors.forEach(f=>{const g=this.dragStartPositions.get(f);if(!g)return;const y=this.artboard.objects.find(S=>S.id===f);if(!y||y.parentId)return;const m=this.objectStates.get(f);m&&(m.x=g.x+l,m.y=g.y+h)})}if(this.isMouseDown){const l=this.activeObjectId&&this.artboard.objects.some(f=>f.id===this.activeObjectId)?this.activeObjectId:a,h=l?this.artboard.objects.find(f=>f.id===l):null;h&&i(h,"move")&&this.fireEventForObject(h.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.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(l=>l.type===H.Draggable)||this.hasDragInteraction(e)))){this.draggingBehaviors.add(a);const l=this.objectStates.get(a);l&&(this.dragStartPointer={x:s,y:o},this.dragStartPositions.set(a,{x:l.x??0,y:l.y??0}))}if(t==="move"?(a&&!this.activeHoverIds.has(a)&&this.activeHoverIds.add(a),this.activeHoverIds.forEach(l=>{l!==a&&this.activeHoverIds.delete(l)})):t==="blur"&&this.activeHoverIds.clear(),this.activeDropdownId&&t==="down"){const l=this.artboard.objects.find(h=>h.id===this.activeDropdownId);if(l&&(l.type==="Dropdown"||l.variant==="dropdown")){const h=this.objectStates.get(l.id),f=(h==null?void 0:h.options)||l.options||{},g=l.geometry||{},y=g.width??l.width??200,m=g.height??l.height??40,S=f.optionsList||[],v=f.itemHeight||32,C=f.listPadding??4,w=S.length*v+C*2,M=this.getWorldTransform(l.id),I=y*Math.abs(M.scaleX),T=m*Math.abs(M.scaleY),k=M.y+T/2+4,E=Math.abs(s-M.x)<=I/2,P=o>=k&&o<=k+w*Math.abs(M.scaleY);if(E&&P){const _=Math.abs(M.scaleY),L=o-(k+C*_),A=Math.floor(L/(v*_));if(A>=0&&A<S.length){const W=S[A];f.selectedOption=W,f.isOpen=!1,this.activeDropdownId=null,l.inputId&&this.setInternalInput(l.inputId,W),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"dropdown",property:"selectedOption",value:W})}return}else a!==this.activeDropdownId&&(f.isOpen=!1,this.activeDropdownId=null)}}if(e){let l=e,h=e;for(;h&&h.parentId;){const g=this.artboard.objects.find(y=>y.id===h.parentId);if(g&&g.type==="Component"){l=g;break}h=g}let f=t;if(t==="click"?f="onClick":t==="down"?f="onPointerDown":t==="up"?f="onPointerUp":t==="blur"&&(f="onPointerLeave"),this.fireEventForObject(e.id,f),l!==e&&this.fireEventForObject(l.id,f),l.type==="Component"&&l.variant==="toggle_button"&&t==="down"){const g=this.objectStates.get(l.id),y=(g==null?void 0:g.options)||l.options||{};y.checked=!y.checked,l.inputId&&this.setInternalInput(l.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"toggle_button",property:"checked",value:y.checked}),this.fireEventForObject(l.id,"Toggle"),this.fireEventForObject(l.id,y.checked?"Toggle True":"Toggle False")}if(l.type==="Component"&&l.variant==="toggle"&&t==="down"){const g=this.objectStates.get(l.id),y=(g==null?void 0:g.options)||l.options||{};y.checked=!y.checked,l.inputId&&this.setInternalInput(l.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"toggle",property:"checked",value:y.checked}),this.onToggle&&this.onToggle(l.name,y.checked),this.fireEventForObject(l.id,"Toggle"),this.fireEventForObject(l.id,y.checked?"Toggle True":"Toggle False")}if(l.type==="Component"&&l.variant==="dropdown"&&t==="down"){const g=this.objectStates.get(l.id),y=(g==null?void 0:g.options)||l.options||{},m=!y.isOpen;if(m&&this.activeDropdownId&&this.activeDropdownId!==l.id){const S=this.artboard.objects.find(v=>v.id===this.activeDropdownId);S&&S.options&&(S.options.isOpen=!1)}y.isOpen=m,this.activeDropdownId=m?l.id:null}if(l.type==="Component"&&l.variant==="button"&&t==="down"&&(this.onButtonClick&&this.onButtonClick(l.name,l.id),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"button",property:"click",value:!0})),(l.type==="ListView"||l.type==="Component"&&l.variant==="listview")&&t==="down"){this.draggingListViewId=l.id;const g=this.getListViewItemIndexAtPointer(l,s,o);if(g!==null){const y=l.options||{};y.activeItemIndex=g;const m=this.objectStates.get(l.id);m&&m.options&&(m.options.activeItemIndex=g);const S=(y.items||[])[g],v=typeof S=="string"?S:S.label||S.value||g;m&&m.options&&(m.options.selectedValue=v),l.inputId&&this.setInternalInput(l.inputId,v),this.onComponentChange&&(this.onComponentChange({objectId:l.id,componentName:l.name,variant:"listview",property:"activeItemIndex",value:g}),this.onComponentChange({objectId:l.id,componentName:l.name,variant:"listview",property:"selected",value:v}))}}if(l.type==="Component"&&l.variant==="slider"&&t==="down"&&(this.draggingSliderId=l.id,this.updateSliderValueFromPointer(l,s,o)),l.type==="Joystick"||l.type==="Component"&&l.variant==="joystick"){if(t==="down")this.draggingJoystickId=l.id,this.updateJoystickValueFromPointer(l,s,o);else if(t==="up"||t==="blur"){const g=this.objectStates.get(l.id);g&&l.isSpringReturn!==!1&&(g.handleX=0,g.handleY=0),l.isSpringReturn!==!1&&(l.handleX=0,l.handleY=0)}}if(l.type==="Component"&&l.variant==="checkbox"&&t==="down"){const g=this.objectStates.get(l.id),y=(g==null?void 0:g.options)||l.options||{};y.checked=!y.checked,l.inputId&&this.setInternalInput(l.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"checkbox",property:"checked",value:y.checked}),this.fireEventForObject(l.id,"Click"),this.fireEventForObject(l.id,y.checked?"Checked":"Unchecked")}if(l.type==="Component"&&l.variant==="radiogroup"&&t==="down"){const g=this.objectStates.get(l.id),y=(g==null?void 0:g.options)||l.options||{},m=y.optionsList||[],S=this.getRadioGroupItemIndexAtPointer(l,s,o);if(S!==null&&S>=0&&S<m.length){const v=m[S];y.selectedValue=v,l.inputId&&this.setInternalInput(l.inputId,v),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"radiogroup",property:"selectedValue",value:v}),this.fireEventForObject(l.id,"Click"),this.fireEventForObject(l.id,`Selected: ${v}`)}}if(l.type==="LineGraph"&&(t==="down"||t==="click")){const g=l.geometry,y=(g==null?void 0:g.datasets)||[],m=this.objectStates.get(l.id),S=(m==null?void 0:m.width)||(g==null?void 0:g.width)||200,v=(m==null?void 0:m.height)||(g==null?void 0:g.height)||150,C=this.getWorldTransform(l.id),w=30,M=20,I=S-w,T=v-M;let k=1;y.forEach(_=>{const L=Math.max(..._.data||[0]);L>k&&(k=L)});let E=1/0,P=null;y.forEach((_,L)=>{const A=_.data||[],W=I/Math.max(A.length-1,1);A.forEach((B,R)=>{const Y=C.x-S/2+w+R*W,G=C.y+v/2-M-B/k*T,z=Math.sqrt((s-Y)**2+(o-G)**2);z<E&&(E=z,P={dIdx:L,pIdx:R,val:B,label:_.label||`Dataset ${L+1}`})})}),P&&E<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:l.id,componentName:l.name,datasetIndex:P.dIdx,pointIndex:P.pIdx,value:P.val,label:P.label}),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"linegraph",property:"click",value:(P==null?void 0:P.val)??null})}if(t==="click"){const g=(c=this.artboard)==null?void 0:c.objects.find(S=>S.id===e.id),y=this.focusedId,m=(g==null?void 0:g.type)==="InputBox"||(g==null?void 0:g.type)==="Component"&&g.variant==="inputbox";if(g&&m){if(this.focusedId=e.id,this.log(`[Engine] Focus set to: ${e.id}`),y!==this.focusedId){if(y){const S=(d=this.artboard)==null?void 0:d.objects.find(v=>v.id===y);S&&this.onInputBlur&&this.onInputBlur(S.name)}this.onInputFocus&&this.onInputFocus(g.name)}}else if(this.focusedId=null,y){const S=(u=this.artboard)==null?void 0:u.objects.find(v=>v.id===y);S&&this.onInputBlur&&this.onInputBlur(S.name)}}}else if(t==="click"){const l=this.focusedId;if(this.focusedId=null,l){const h=(p=this.artboard)==null?void 0:p.objects.find(f=>f.id===l);h&&this.onInputBlur&&this.onInputBlur(h.name)}}}handleKeyDown(t){if(!this.artboard||(this.activeKeys.add(t.key.toLowerCase()),this.activeKeys.add(t.code),!this.focusedId))return;const s=this.artboard.objects.find(a=>a.id===this.focusedId),o=(s==null?void 0:s.type)==="InputBox"||(s==null?void 0:s.type)==="Component"&&s.variant==="inputbox";if(!s||!o)return;const e=s.options||{};let i=e.text||"";if(t.key==="Backspace")i=i.slice(0,-1);else if(t.key==="Enter")if(e.multiline)i+=`
|
|
7
|
-
`;else{this.focusedId=null;return}else if(t.key.length===1)i+=t.key;else return;e.text=i;const n=s.geometry;n.textInputId&&this.updateInput(n.textInputId,i),this.onComponentChange&&this.onComponentChange({objectId:s.id,componentName:s.name,variant:"inputbox",property:"text",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(i=>String(i).toLowerCase()==="drag")}):!1}fireEventForObject(t,s){var d,u,p,l,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()]),i=s.toLowerCase();i==="onclick"||i==="click"||i==="onpointerdown"||i==="pointerdown"?this.fireAnalyticsEvent(t,"click"):(i==="onpointerenter"||i==="hover"||i==="move")&&this.fireAnalyticsEvent(t,"hover"),i==="onclick"||i==="click"?(e.add("click"),e.add("onclick")):i==="onpointerdown"||i==="pointerdown"?(e.add("pointerdown"),e.add("onpointerdown")):i==="onpointerup"||i==="pointerup"?(e.add("pointerup"),e.add("onpointerup")):i==="onpointerenter"||i==="hover"||i==="move"?(e.add("hover"),e.add("onpointerenter")):i==="onpointerleave"||i==="blur"?(e.add("onpointerleave"),e.add("blur")):i==="drag"||i==="ondrag"?(e.add("drag"),e.add("ondrag")):i==="toggle"||i==="ontoggle"?(e.add("toggle"),e.add("ontoggle")):i==="toggle true"||i==="toggle_true"||i==="toggletrue"?(e.add("toggle true"),e.add("toggle_true"),e.add("toggletrue")):(i==="toggle false"||i==="toggle_false"||i==="togglefalse")&&(e.add("toggle false"),e.add("toggle_false"),e.add("togglefalse"));const a=(o.interactions||[]).find(f=>{const g=f.triggers||[f.event||f.trigger||"click"];return((f.triggerLogic||"OR")==="AND"?g.every(S=>e.has(S.toLowerCase())):g.some(S=>e.has(S.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,g=a.targetProperty;g&&this.updateObjectProperty(f,g,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,g=!a.playMode||a.playMode==="all"?void 0:a.subAnimationIds;f==="__all__"?(p=(u=this.artboard)==null?void 0:u.animations)==null||p.forEach(y=>{this.triggerGlobalAnimation(y.id,g)}):f&&this.triggerGlobalAnimation(f,g)}else if(a.action==="setState"||a.action==="Set State"){const f=a.targetObjectId||o.id,y={...this.objectStates.get(f)||{},...a.value||{}};this.objectStates.set(f,y),this.log(`[Engine] State updated for ${f}:`,y)}else if(a.action==="Stop Animation"||a.action==="Pause Animation"){const f=a.targetAnimationId;f==="__all__"?this.layerStates.forEach((g,y)=>{y.startsWith("global_")&&this.layerStates.delete(y)}):f&&this.layerStates.forEach((g,y)=>{y.startsWith(`global_${f}_`)&&this.layerStates.delete(y)})}else if(a.action==="Switch to State"&&this.activeStateMachine){const f=a.targetState,g=this.activeStateMachine.layers.find(y=>y.states.some(m=>m.id===f||m.name===f));g&&(this.log(`[Engine] Switching Layer ${g.name} to State ${f}`),this.enterStates(g.name,[f]))}this.onTrigger&&this.onTrigger(s,a.action)}const c=(o.triggers||[]).find(f=>{const g=f.eventType.toLowerCase();let y=!1;return(e.has(g)||g==="click"&&e.has("onclick")||g==="hover"&&(e.has("onpointerenter")||e.has("hover"))||g==="pointerdown"&&e.has("onpointerdown")||g==="pointerup"&&e.has("onpointerup"))&&(y=!0),y&&f.conditions&&f.conditions.length>0?this.checkConditions(f.conditions):y});if(c&&c.entryAnimationId){this.log(`[Engine] Trigger matched: ${s} (as ${c.eventType}) -> Animation ${c.entryAnimationId}`);const f=(h=(l=this.artboard)==null?void 0:l.animations)==null?void 0:h.find(g=>g.id===c.entryAnimationId);f&&(this.activeTriggers.set(o.id,{triggerId:c.id,animation:f,time:0,phase:"entry",elapsedHold:0,filterObjectId:c.targetObjectId}),this.onTrigger&&this.onTrigger(c.name,f.name))}}fireAnalyticsEvent(t,s){var r,c;const o=(r=this.artboard)==null?void 0:r.objects.find(d=>d.id===t);if(!o)return;const e=(c=o.style)==null?void 0:c.analytics;if(!e||!e.isEnabled||e.triggerType!==s)return;const i=e.eventName||`${o.name.toLowerCase().replace(/\s+/g,"_")}_interacted`,n={};e.parameters&&Array.isArray(e.parameters)&&e.parameters.forEach(d=>{if(d.type==="literal")n[d.key]=d.value;else if(d.type==="variable"){const u=this.inputs.get(d.value);n[d.key]=u!==void 0?u:""}}),this.log(`[ExodeUI Analytics] Dispatching event "${i}" via ${s} trigger:`,n);const a=e.platforms||{ga4:!0,meta:!0,mixpanel:!1};if(a.ga4){const d=window;typeof d.gtag=="function"?(d.gtag("event",i,n),this.log(`[ExodeUI Analytics] GA4: Event "${i}" sent successfully.`)):this.warn(`[ExodeUI Analytics] GA4: window.gtag is not a function. Event "${i}" skipped.`)}if(a.meta){const d=window;typeof d.fbq=="function"?(d.fbq("track",i,n),this.log(`[ExodeUI Analytics] Meta Pixel: Event "${i}" sent successfully.`)):this.warn(`[ExodeUI Analytics] Meta Pixel: window.fbq is not a function. Event "${i}" skipped.`)}if(a.mixpanel){const d=window;d.mixpanel&&typeof d.mixpanel.track=="function"?(d.mixpanel.track(i,n),this.log(`[ExodeUI Analytics] Mixpanel: Event "${i}" sent successfully.`)):this.warn(`[ExodeUI Analytics] Mixpanel: window.mixpanel.track is not a function. Event "${i}" 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 i;(i=e.keyframes)==null||i.forEach(n=>{n.time>s&&(s=n.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 i=this.artboard.animations.find(c=>c.id===t);if(!i)return;let n=this.getAnimationDuration(i);const a=`global_${t}_${Math.random().toString(36).substr(2,5)}`;this.layerStates.set(a,{currentStateIds:[t],animations:[{animation:i,state:{loop:o},filterObjectIds:s}],time:0,duration:n,ruleId:e}),console.log(`[Engine] Triggered global animation: ${i.name} (AnimID: ${t}, RuleID: ${e}, Loop: ${o}, StoredDuration: ${n}, anim.duration: ${i.duration}, Tracks: ${((r=i.tracks)==null?void 0:r.length)||0})`),this.debugLog(`[Engine] Triggered global animation: ${i.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,i)=>{if(e.trigger==="after_anim"&&e.targetAnimationId){let n=e.afterAnim;!n&&i>0&&(n=o[i-1].id);const a=n===t||s&&n===s;if(console.log(`[Engine] Checking rule ${e.id} (Trigger: ${e.trigger}). ExpectedParent: ${n}. 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 p;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,scaleX:1,scaleY:1,rotation:0};const o=(p=this.artboard)==null?void 0:p.objects.find(l=>l.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),i=e.rotation*(Math.PI/180),n=Math.cos(i),a=Math.sin(i),r=s.x*e.scaleX,c=s.y*e.scaleY,d=e.x+(r*n-c*a),u=e.y+(r*a+c*n);return{x:d,y:u,scaleX:(s.scale_x??1)*e.scaleX,scaleY:(s.scale_y??1)*e.scaleY,rotation:e.rotation+(s.rotation??0)}}hitTest(t,s,o){var S,v;if(!this.objectStates.get(t.id))return!1;const i=((S=t.geometry)==null?void 0:S.width)??t.width??100,n=((v=t.geometry)==null?void 0:v.height)??t.height??100,a=this.getWorldTransform(t.id),r=s-a.x,c=o-a.y,d=-a.rotation*(Math.PI/180),u=Math.cos(d),p=Math.sin(d),l=r*u-c*p,h=r*p+c*u,f=a.scaleX,g=a.scaleY,y=i*Math.abs(f),m=n*Math.abs(g);return Math.abs(l)<=y/2&&Math.abs(h)<=m/2}updateSliderValueFromPointer(t,s,o){var M;const e=this.objectStates.get(t.id);if(!e)return;const i=t.options||{},n=((M=t.geometry)==null?void 0:M.width)??t.width??200,a=this.getWorldTransform(t.id),r=s-a.x,c=o-a.y,d=-a.rotation*(Math.PI/180),u=Math.cos(d),p=Math.sin(d),l=r*u-c*p,h=i.thumbWidth??16,f=n-h;let y=(l+f/2)/f;y=Math.max(0,Math.min(1,y));const m=i.min??0,S=i.max??100,v=i.step||1;let C=m+y*(S-m);v>0&&(C=Math.round(C/v)*v),C=Math.max(m,Math.min(S,C));const w=e.options||{};w.value!==C&&(e.options={...w,value:C},t.inputId&&this.setInternalInput(t.inputId,C),this.onComponentChange&&this.onComponentChange({objectId:t.id,componentName:t.name,variant:"slider",property:"value",value:C}))}updateJoystickValueFromPointer(t,s,o){var M,I;const e=this.objectStates.get(t.id);if(!e)return;const i=(e==null?void 0:e.width)!==void 0?e.width:((M=t.geometry)==null?void 0:M.width)??t.width??100,n=(e==null?void 0:e.height)!==void 0?e.height:((I=t.geometry)==null?void 0:I.height)??t.height??100,a=this.getWorldTransform(t.id),r=s-a.x,c=o-a.y,d=-a.rotation*(Math.PI/180),u=Math.cos(d),p=Math.sin(d);let l=(r*u-c*p)/Math.max(.001,Math.abs(a.scaleX||1)),h=(r*p+c*u)/Math.max(.001,Math.abs(a.scaleY||1));t.handleOrigin==="top-left"?(l-=i/2,h-=n/2):t.handleOrigin==="bottom-right"&&(l+=i/2,h+=n/2);const f=Math.min(i,n)*.45,g=Math.min(i,n)*.15,y=f-g;let m=l/y,S=h/y;const v=Math.sqrt(m*m+S*S);t.boundsShape==="square"?(m=Math.max(-1,Math.min(1,m)),S=Math.max(-1,Math.min(1,S))):v>1&&(m/=v,S/=v),t.deadzone!==void 0&&v<t.deadzone?(m=0,S=0):(t.stepX!==void 0&&t.stepX>0&&(m=Math.round(m/t.stepX)*t.stepX),t.stepY!==void 0&&t.stepY>0&&(S=Math.round(S/t.stepY)*t.stepY)),t.joystickType==="1D_X"?S=0:t.joystickType==="1D_Y"&&(m=0);const C=e.handleX,w=e.handleY;(C!==m||w!==S)&&(e.handleX=m,e.handleY=S,t.handleX=m,t.handleY=S)}processJoysticks(t){this.artboard&&(this.artboard.objects.forEach(s=>{var c,d,u,p;if(s.type!=="Joystick"&&!(s.type==="Component"&&s.variant==="joystick"))return;const o=s,e=this.objectStates.get(o.id);if(!e)return;let i=e.handleX??o.handleX??0,n=e.handleY??o.handleY??0;const r=(o.globalInput??!1)||this.lastHoveredObjectId===o.id;if(r&&((c=o.inputBinding)==null?void 0:c.type)==="keyboard"&&o.inputBinding.keyboardConfig){const l=o.inputBinding.keyboardConfig;let h=i,f=n;const y=(l.speed||5)*t;let m=!1;this.activeKeys.has(l.upKey.toLowerCase())&&(f-=y,m=!0),this.activeKeys.has(l.downKey.toLowerCase())&&(f+=y,m=!0),this.activeKeys.has(l.leftKey.toLowerCase())&&(h-=y,m=!0),this.activeKeys.has(l.rightKey.toLowerCase())&&(h+=y,m=!0),o.joystickType==="1D_X"&&(f=0),o.joystickType==="1D_Y"&&(h=0);const S=Math.sqrt(h*h+f*f);S>1&&(h/=S,f/=S),!m&&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)),i=h,n=f}else if(r&&((d=o.inputBinding)==null?void 0:d.type)==="mouse"&&o.inputBinding.mouseConfig){const l=o.inputBinding.mouseConfig;let h=e._mouseTargetX??i,f=e._mouseTargetY??n;const g=l.sensitivity||.01;if(l.mode==="absolute"){const S=((u=this.artboard)==null?void 0:u.width)||window.innerWidth,v=((p=this.artboard)==null?void 0:p.height)||window.innerHeight,C=this.inputs.get("mouseX")||0,w=this.inputs.get("mouseY")||0;l.axisX&&(h=C/S*2-1),l.axisY&&(f=w/v*2-1)}else l.axisX&&(h+=this._mouseDelta.dx*g),l.axisY&&(f+=this._mouseDelta.dy*g);o.joystickType==="1D_X"&&(f=0),o.joystickType==="1D_Y"&&(h=0);const y=Math.sqrt(h*h+f*f);y>1&&(h/=y,f/=y),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 m=15*t;i+=(h-i)*Math.min(m,1),n+=(f-n)*Math.min(m,1)}if(e.handleX=i,e.handleY=n,o.handleX=i,o.handleY=n,o.bindings&&o.bindings.length>0){const l=Math.sqrt(i*i+n*n);let h=Math.atan2(n,i)*(180/Math.PI);h<0&&(h+=360),o.bindings.forEach(f=>{var m,S,v,C,w,M,I,T;let g=0;f.sourceAxis==="x"?g=o.invertX?-i:i:f.sourceAxis==="y"?g=o.invertY?-n:n:f.sourceAxis==="distance"?g=l:f.sourceAxis==="angle"&&(g=h);const y=(m=this.artboard)==null?void 0:m.objects.find(k=>k.id===f.targetObjectId);if(y){if(f.actionType==="bind"&&f.targetProperty&&f.isContinuous!==!1){const k=f.sourceMin??-1,E=f.sourceMax??1,P=f.targetMin??0,_=f.targetMax??100;let L=!!f.isContinuous,A=0,W=0;if(L){if((f.sourceAxis==="x"||f.sourceAxis==="y")&&P>=0){const R=Math.max(Math.abs(k),Math.abs(E))||1;W=g/R*_}else{let R=(g-k)/(E-k);R=Math.max(0,Math.min(1,R)),W=P+R*(_-P)}Math.abs(g)<.05&&(W=0)}else{const R=(g-k)/(E-k),Y=Math.max(0,Math.min(1,R));A=P+Y*(_-P),f.step&&f.step>0&&(A=Math.round(A/f.step)*f.step)}const B=this.objectStates.get(y.id);if(B){const R=f.isRelative!==!1,Y=R?((S=y.transform)==null?void 0:S.x)??0:0,G=R?((v=y.transform)==null?void 0:v.y)??0:0,z=R?((C=y.transform)==null?void 0:C.rotation)??0:0,O=R?((w=y.transform)==null?void 0:w.scale_x)??1:0,F=R?((M=y.transform)==null?void 0:M.scale_y)??1:0,Z=R?((I=y.style)==null?void 0:I.opacity)??100:0,st=Math.min(t*60,3),at=(ct,dt)=>{let $=A;if(L){const X=`_internal_${ct}_${f.id}`;let N=B[X];N===void 0&&(N=B[ct]??dt),$=N+W*st,B[X]=$,f.step&&f.step>0&&($=Math.round($/f.step)*f.step)}else{$=dt+A;const X=`_internal_smooth_${ct}_${f.id}`;let N=B[X];if(N===void 0)N=$;else{const ot=Math.min(15*t,1);N+=($-N)*ot}B[X]=N,$=N}B[ct]=$};f.targetProperty==="x"||f.targetProperty==="transform.x"?at("x",Y):f.targetProperty==="y"||f.targetProperty==="transform.y"?at("y",G):f.targetProperty==="rotation"||f.targetProperty==="r"||f.targetProperty==="transform.rotation"?at("rotation",z):f.targetProperty==="scaleX"||f.targetProperty==="transform.scale_x"?at("scale_x",O):f.targetProperty==="scaleY"||f.targetProperty==="transform.scale_y"?at("scale_y",F):(f.targetProperty==="opacity"||f.targetProperty==="transform.opacity")&&at("opacity",Z)}(T=y.physics)!=null&&T.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(y.id,(A-((B==null?void 0:B.x)||0))*10,0):(f.targetProperty==="y"||f.targetProperty==="transform.y")&&this.physicsEngine.applyForce(y.id,0,(A-((B==null?void 0:B.y)||0))*10))}else if(f.actionType==="playAnimation"||f.actionType==="stopAnimation"||f.actionType==="pauseAnimation"){let k=!1;const E=f.threshold??0;f.condition==="always"?k=!0:f.condition===">"?k=g>E:f.condition==="<"?k=g<E:f.condition==="=="&&(k=Math.abs(g-E)<.01);const P=e[`_prev_src_${f.id}`]??g;let _=!1;f.condition==="always"?_=!0:f.condition===">"?_=P>E:f.condition==="<"?_=P<E:f.condition==="=="&&(_=Math.abs(P-E)<.01),e[`_prev_src_${f.id}`]=g,k&&!_&&f.targetAnimationId&&(f.actionType==="playAnimation"||f.actionType)}}})}}),this._mouseDelta.dx=0,this._mouseDelta.dy=0)}applyBlendState(t,s){var c,d,u,p,l,h,f,g;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 i=[];let n=0;if(t.blendType==="1D"){const y=[...t.blendAnimations].sort((m,S)=>m.position[0]-S.position[0]);if(y.length===1){const m=(d=(c=this.artboard)==null?void 0:c.animations)==null?void 0:d.find(S=>S.id===y[0].animationId);m&&(i.push({anim:m,weight:1}),n=1)}else{let m=0;for(;m<y.length-1&&y[m+1].position[0]<o;)m++;if(m===y.length-1&&o>y[m].position[0]){const S=(p=(u=this.artboard)==null?void 0:u.animations)==null?void 0:p.find(v=>v.id===y[m].animationId);S&&(i.push({anim:S,weight:1}),n=1)}else{const S=y[m].position[0],v=y[m+1].position[0],C=(h=(l=this.artboard)==null?void 0:l.animations)==null?void 0:h.find(k=>k.id===y[m].animationId),w=(g=(f=this.artboard)==null?void 0:f.animations)==null?void 0:g.find(k=>k.id===y[m+1].animationId),M=Math.max(.001,v-S);let I=(o-S)/M;I=Math.max(0,Math.min(1,I));const T=1-I;C&&(i.push({anim:C,weight:T}),n+=T),w&&(i.push({anim:w,weight:I}),n+=I)}}}else t.blendAnimations.forEach(y=>{var w,M;const m=(M=(w=this.artboard)==null?void 0:w.animations)==null?void 0:M.find(I=>I.id===y.animationId);if(!m)return;const S=y.position[0]-o,v=y.position[1]-e,C=S*S+v*v;if(C<1e-4)i.push({anim:m,weight:1e4}),n+=1e4;else{const I=1/C;i.push({anim:m,weight:I}),n+=I}});if(n===0)return;i.forEach(y=>y.weight/=n);const a=new Map,r=y=>{let m=y.startsWith("#")?y.substring(1):y;return m.length===3&&(m=[m[0],m[0],m[1],m[1],m[2],m[2]].join("")),m="0x"+m,{r:m>>16&255,g:m>>8&255,b:m&255,a:1}};i.forEach(({anim:y,weight:m})=>{y.tracks&&y.tracks.forEach(S=>{var E,P;const v=S.object_id||S.objectId,C=S.property,w=(E=this.artboard)==null?void 0:E.objects.find(_=>_.id===v);if(((P=w==null?void 0:w.physics)==null?void 0:P.enabled)&&w.physics.bodyType!=="Static"&&(C==="x"||C==="y"||C==="rotation"))return;const I=this.interpolate(S.keyframes,s);if(I===void 0)return;let T=a.get(v);T||(T=new Map,a.set(v,T));let k=T.get(C);if(!k){if(typeof I=="number")k={type:"number",value:0};else if(typeof I=="string"&&I.startsWith("#"))k={type:"color",value:I,colorAcc:{r:0,g:0,b:0,a:0}};else if(k={type:"number",value:I},m<.5)return;T.set(C,k)}if(k.type==="number"&&typeof I=="number")k.value+=I*m;else if(k.type==="color"&&typeof I=="string"&&k.colorAcc){const _=r(I);_&&(k.colorAcc.r+=_.r*m,k.colorAcc.g+=_.g*m,k.colorAcc.b+=_.b*m,k.colorAcc.a+=_.a*m)}else m>.5&&(k.value=I)})}),a.forEach((y,m)=>{var C;const S=this.objectStates.get(m),v=(C=this.artboard)==null?void 0:C.objects.find(w=>w.id===m);!S||!v||y.forEach((w,M)=>{let I=w.value;if(w.type==="color"&&w.colorAcc){const T=Math.round(w.colorAcc.r).toString(16).padStart(2,"0"),k=Math.round(w.colorAcc.g).toString(16).padStart(2,"0"),E=Math.round(w.colorAcc.b).toString(16).padStart(2,"0");I=`#${T}${k}${E}`}if(M.includes(".")||M.includes("[")){const T=(M||"").replace(/\[(\d+)\]/g,".$1").split(".");let k=S;for(let E=0;E<T.length-1;E++){if(typeof k[T[E]]!="object"||k[T[E]]===null){let P=v;for(let _=0;_<=E;_++)P=P?P[T[_]]:null;if(T[E]==="corner_radius"||T[E]==="cornerRadius"){const _=typeof k[T[E]]=="number"?k[T[E]]:typeof P=="number"?P:0;k[T[E]]={tl:_,tr:_,bl:_,br:_}}else{const _=T[E+1],L=!isNaN(Number(_));k[T[E]]=P?JSON.parse(JSON.stringify(P)):L?[]:{}}}k=k[T[E]]}k[T[T.length-1]]=I,T[T.length-1]==="color"&&(T[T.length-2]==="fill"||T[T.length-2]==="stroke")&&(k.type="Solid")}else M==="fill"?(S.style||(S.style={}),S.style.fill=I):M==="stroke"?(S.style||(S.style={}),S.style.stroke=I):S[M]=I})})}applyAnimation(t,s,o){!t||!t.tracks||t.tracks.forEach(e=>{var u,p,l;const i=e.object_id||e.objectId;if(o){if(Array.isArray(o)){if(!o.includes(i))return}else if(i!==o)return}const n=(u=this.artboard)==null?void 0:u.objects.find(h=>h.id===i),a=((p=n==null?void 0:n.physics)==null?void 0:p.enabled)&&n.physics.bodyType!=="Static";let r=e.property;if(a&&(r==="x"||r==="y"||r==="rotation"))return;const c=this.objectStates.get(i);if(!c){this.frameCount%600===0&&this.debugLog(`Skipping track: Object ${i} not found in state`);return}const d=this.interpolate(e.keyframes,s);if(d!==void 0){if(this.frameCount%240===0){const h=(n==null?void 0:n.name)||i,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=c;for(let g=0;g<h.length-1;g++){if(typeof f[h[g]]!="object"||f[h[g]]===null){let y=n;for(let m=0;m<=g;m++)y=y?y[h[m]]:null;if(h[g]==="corner_radius"||h[g]==="cornerRadius"){let m=0,S=0,v=0,C=0;const w=f[h[g]]??y;typeof w=="number"?m=S=v=C=w:Array.isArray(w)?w.length===1?m=S=v=C=w[0]:w.length===2?(m=v=w[0],S=C=w[1]):w.length===3?(m=w[0],S=C=w[1],v=w[2]):w.length>=4&&(m=w[0],S=w[1],v=w[2],C=w[3]):w&&typeof w=="object"&&(m=w[0]??w.tl??w.corner_radius??w.cornerRadius??0,S=w[1]??w.tr??w.corner_radius??w.cornerRadius??0,v=w[2]??w.br??w.corner_radius??w.cornerRadius??0,C=w[3]??w.bl??w.corner_radius??w.cornerRadius??0),f[h[g]]={tl:m,tr:S,bl:C,br:v,0:m,1:S,2:v,3:C}}else{const m=h[g+1],S=!isNaN(Number(m));f[h[g]]=y?JSON.parse(JSON.stringify(y)):S?[]:{}}}f=f[h[g]]}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"?(c.style||(c.style={}),c.style.fill=d):r==="stroke"?(c.style||(c.style={}),c.style.stroke=d):c[r]=d;if(this.physicsEngine&&((l=n==null?void 0:n.physics)!=null&&l.enabled)&&n.physics.bodyType==="Static")if(r==="x"){const h=this.physicsEngine.getPosition(i);h&&this.physicsEngine.setPosition(i,d,h.y)}else if(r==="y"){const h=this.physicsEngine.getPosition(i);h&&this.physicsEngine.setPosition(i,h.x,d)}else r==="rotation"&&this.physicsEngine.setRotation(i,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 i=e.time-o.time;let n=(s-o.time)/i;return o.easing&&(n=si(o.easing)(n)),this.interpolateValue(o.value,e.value,n)}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),i=parseFloat(s);return!isNaN(e)&&!isNaN(i)?Math.round(e+(i-e)*o).toString():o<.5?t:s}if(Array.isArray(t)&&Array.isArray(s))return t.length===s.length?t.map((e,i)=>this.interpolateValue(e,s[i],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(n=>{e[n]=this.interpolateValue(t[n],s[n],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)||{},i=e[t]||t,n=e[s]||s,a=g=>{if(!g)return{r:0,g:0,b:0};const y=g.startsWith("#")?g.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(i),c=a(n),d=Math.round(r.r+(c.r-r.r)*o),u=Math.round(r.g+(c.g-r.g)*o),p=Math.round(r.b+(c.b-r.b)*o),l=g=>{const y=Math.max(0,Math.min(255,g)).toString(16);return y.length===1?"0"+y:y};return`#${l(d)}${l(u)}${l(p)}`}interpolateStops(t,s,o){return!t||!s||t.length!==s.length?o<.5?t:s:t.map((e,i)=>{const n=s[i];return{offset:e.offset+(n.offset-e.offset)*o,color:this.interpolateColor(e.color,n.color,o),opacity:(e.opacity??1)+((n.opacity??1)-(e.opacity??1))*o}})}interpolateFill(t,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 u;this.debug_objectsTotal=((u=this.artboard)==null?void 0:u.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 i=this.artboard.width,n=this.artboard.height,a=this.calculateTransform(s,o,i,n,this.layout.fit,this.layout.alignment);if(t.save(),t.translate(Math.round(a.tx),Math.round(a.ty)),t.scale(a.scaleX,a.scaleY),this.rootTransform=t.getTransform(),this.artboard.backgroundVisible!==!1&&(t.fillStyle=this.artboard.backgroundColor||"#000000",t.fillRect(0,0,i,n)),this.artboard.backgroundImage){const p=this.artboard.backgroundImage;let l=this.imageCache.get(p);if(l||(l=new Image,l.src=p,this.imageCache.set(p,l)),l.complete&&l.naturalWidth>0){t.save(),t.globalAlpha=this.normalizeOpacity(this.artboard.backgroundOpacity??100);const h=l.naturalWidth/l.naturalHeight,f=i/n;let g,y,m,S;f>h?(g=i,y=i/h):(y=n,g=n*h),m=(i-g)/2,S=(n-y)/2,t.drawImage(l,m,S,g,y),t.restore()}}this.artboard.clipContent!==!1&&this.artboard.clip_content!==!1&&(t.beginPath(),t.rect(0,0,i,n),t.clip());const c=new Map;this.artboard.objects.forEach(p=>c.set(p.id,p)),this.artboard.objects.filter(p=>!p.parentId).map((p,l)=>{const h=this.objectStates.get(p.id),f=(h==null?void 0:h.zIndex)??l;return{obj:p,zIndex:f}}).sort((p,l)=>p.zIndex-l.zIndex).forEach(({obj:p})=>{this.renderObject(t,p,c)}),this._emitterPools.forEach((p,l)=>{if(!(p.length===0||!c.get(l)))for(const f of p)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,i,n=0){const a=t.getTransform(),r=s*a.a+o*a.c+a.e,c=s*a.b+o*a.d+a.f,d=Math.sqrt(a.a*a.a+a.b*a.b),u=Math.sqrt(a.c*a.c+a.d*a.d),p=(e/2+n)*d,l=(i/2+n)*u;return r+p>=0&&r-p<=this.canvasWidth&&c+l>=0&&c-l<=this.canvasHeight}calculateTransform(t,s,o,e,i,n){let a=1,r=1,c=1;const d=o/e,u=t/s;switch(i){case"Contain":u>d?c=s/e:c=t/o,a=r=c;break;case"Cover":u>d?c=t/o:c=s/e,a=r=c;break;case"Fill":a=t/o,r=s/e;break;case"FitWidth":c=t/o,a=r=c;break;case"FitHeight":c=s/e,a=r=c;break;case"None":a=r=1;break;case"ScaleDown":c=Math.min(t/o,s/e),c>1&&(c=1),a=r=c;break;default:a=r=1;break}const p=o*a,l=e*r;let h=0,f=0;return n.includes("Left")?h=0:n.includes("Right")?h=t-p:h=(t-p)/2,n.includes("Top")?f=0:n.includes("Bottom")?f=s-l:f=(s-l)/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,i,n){t.beginPath();const a=Math.max(1,n/14);let r=e;s==="underline"?r=e+n*.12:s==="line-through"&&(r=e-n*.3),t.lineWidth=a,t.strokeStyle=t.fillStyle,t.moveTo(o-i/2,r),t.lineTo(o+i/2,r),t.stroke()}renderObject(t,s,o,e=!1,i=!1){var S,v,C,w,M,I,T,k,E,P,_,L,A,W,B,R,Y,G,z,O,F,Z,st,at,ct,dt,$,X,N,ot,bt,St,Mt,pt,wt;const n=this.objectStates.get(s.id);if(!n){this.warn("No state for object:",s.id);return}this.frameCount%60,t.roundRect||(t.roundRect=(yt,qt,Kt,j,ft)=>(this.drawRoundRect(t,yt,qt,Kt,j,ft),t));const a=n.geometry?this.deepMerge(s.geometry,n.geometry):s.geometry;let r=n.style?this.deepMerge(s.style,n.style):s.style,c=(a==null?void 0:a.width)||((S=s.geometry)==null?void 0:S.width)||s.width||0,d=(a==null?void 0:a.height)||((v=s.geometry)==null?void 0:v.height)||s.height||0;if((c===0||d===0)&&(a!=null&&a.points)&&Array.isArray(a.points)&&a.points.length>0){let yt=1/0,qt=-1/0,Kt=1/0,j=-1/0;a.points.forEach(ft=>{yt=Math.min(yt,ft.x),qt=Math.max(qt,ft.x),Kt=Math.min(Kt,ft.y),j=Math.max(j,ft.y)}),c===0&&(c=qt-yt),d===0&&(d=j-Kt)}const u=yt=>{if(yt)return yt.corner_radius??yt.cornerRadius},p=u(a)??u(n)??u(r)??u(s.geometry)??u(s.style)??u(s)??0;let l={...a,width:c,height:d};if(delete l.cornerRadius,l.corner_radius=p,!l.type&&(s.type==="Frame"||s.type==="Component"||s.type==="Group")&&(l.type="Rectangle"),l.type==="Path"&&s.weights&&s.bindMatrices&&l.points){const yt=this.getGlobalTransform(s.id);if(yt){const qt=ii(l.points,s.weights,s.bindMatrices,yt,Kt=>this.getGlobalTransform(Kt));l={...l,points:qt}}}if(n.visible===!1)return;const f=(r.effects||((C=s.style)==null?void 0:C.effects)||[]).find(yt=>yt.isEnabled!==!1&&yt.type==="PathDistortion");if(f){const yt=oi(l,c,d,f.amplitude||5,f.frequency||10,f.seed||0,f.direction||0,f.directionStrength||0);l={...l,type:"Path",points:yt}}const g=s.repeaterConfig,y=g&&g.isEnabled&&g.count>1,m=y?g.count:1;for(let yt=0;yt<m;yt++){let qt=n.x!==void 0?n.x:((w=n.transform)==null?void 0:w.x)??0,Kt=n.y!==void 0?n.y:((M=n.transform)==null?void 0:M.y)??0,j=n.rotation!==void 0?n.rotation:((I=n.transform)==null?void 0:I.rotation)??0,ft=n.scale_x!==void 0?n.scale_x:((T=n.transform)==null?void 0:T.scale_x)??1,Rt=n.scale_y!==void 0?n.scale_y:((k=n.transform)==null?void 0:k.scale_y)??1;if(y&&yt>0){if(g.type==="Linear"){const J=g.offsetX||0,et=g.offsetY||0,q=g.rotation||0,D=g.scale!==void 0?g.scale:1;qt+=yt*J,Kt+=yt*et,j+=yt*q,ft*=Math.pow(D,yt),Rt*=Math.pow(D,yt)}else if(g.type==="Grid"){const J=g.cols||Math.ceil(Math.sqrt(g.count)),et=g.gapX||0,q=g.gapY||0,D=Math.floor(yt/J),it=yt%J,tt=c+et,ut=d+q;qt+=it*tt,Kt+=D*ut}else if(g.type==="Radial"){const J=g.radius||100,et=g.startAngle||0,D=(g.endAngle||360)-et,it=g.count>1?D/(D===360?g.count:g.count-1):0,tt=et+yt*it,ut=tt*Math.PI/180;qt=n.x+J*Math.cos(ut),Kt=n.y+J*Math.sin(ut),j+=tt}}const At=s.type==="Group"||s.type==="Frame"||s.type==="Component",Pt=c>0&&d>0;if(!At&&Pt&&!e){const J=(((E=r.shadow)==null?void 0:E.isEnabled)!==!1?(((P=r.shadow)==null?void 0:P.blur)||0)+10:0)+(((_=r.blur)==null?void 0:_.isEnabled)!==!1&&((L=r.blur)==null?void 0:L.radius)||0)+20;if(!this.isObjectInView(t,qt,Kt,c,d,J))continue}this.debug_objectsRendered++,t.save();const Ot=[],Gt=r.blur||((A=s.style)==null?void 0:A.blur);Gt&&Gt.amount>0&&Ot.push(`blur(${Gt.amount}px)`);const Ht=r.effects||((W=s.style)==null?void 0:W.effects)||[];let Nt=Ht.find(J=>J.isEnabled!==!1&&(J.type==="BackgroundBlur"||J.type==="LayerBlur"));Nt||(Nt=r.effect||((B=s.style)==null?void 0:B.effect)||Ht.find(J=>J.isEnabled!==!1));const Bt=Nt,le=(Bt==null?void 0:Bt.isEnabled)!==!1,ae=Bt==null?void 0:Bt.type,ye=(Bt==null?void 0:Bt.radius)??10;le&&ae==="LayerBlur"?Ot.push(`blur(${ye}px)`):le&&ae==="BackgroundBlur"&&(r===s.style&&(r={...r}),r.fill={type:"None"});const Pe=(l==null?void 0:l.adjustments)||(a==null?void 0:a.adjustments)||((R=s.geometry)==null?void 0:R.adjustments),Le=(r==null?void 0:r.adjustments)||((Y=s.style)==null?void 0:Y.adjustments),me=((G=r==null?void 0:r.fill)==null?void 0:G.adjustments)||((O=(z=s.style)==null?void 0:z.fill)==null?void 0:O.adjustments),xe=s==null?void 0:s.adjustments,Zt=Pe||Le||me||xe;if(n&&Zt&&(n.geometry=n.geometry||{},n.geometry.adjustments={...Zt}),Zt){const J=(Zt.exposure||0)/100,et=(Zt.contrast||0)/100,q=(Zt.saturation||0)/100,D=(Zt.temperature||0)/200,it=(Zt.tint||0)/200,tt=(Zt.highlights||0)/500,ut=(Zt.shadows||0)/500,Wt=Zt.hue||0,Dt=(Zt.negative||0)/100,Qt=Zt.blur||0;if(J!==0&&Ot.push(`brightness(${1+J})`),et!==0){const Xt=et>0?1+et*2:1+et;Ot.push(`contrast(${Number(Xt.toFixed(2))})`)}if(q!==0){const Xt=q>0?1+q*1.5:1+q;Ot.push(`saturate(${Number(Xt.toFixed(2))})`)}const zt=Wt+it*30-D*20;zt!==0&&Ot.push(`hue-rotate(${Math.round(zt)}deg)`),D>0&&Ot.push(`sepia(${Math.round(D*40)}%)`),Dt!==0&&Ot.push(`invert(${Math.abs(Dt)})`),tt!==0&&Ot.push(`brightness(${1+tt})`),ut!==0&&Ot.push(`contrast(${1+ut})`),Qt>0&&Ot.push(`blur(${Qt}px)`)}Ot.length>0?(t.filter=Ot.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 _e=t.globalAlpha,Fe=this.normalizeOpacity(n.opacity!==void 0?n.opacity:100);t.globalAlpha=_e*Fe;const Ee=n.compositeOperation||n.blendMode;if(Ee&&Ee!=="Normal"){const J=Ee.toLowerCase();["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity","source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","copy","xor","multiply","screen"].includes(J)&&(t.globalCompositeOperation=J)}const pe=t,Ce=n.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 Re=!1;const he=Ce.filter(J=>J.isVisible!==!1&&o.has(J.maskId));if(he.length>0){const J=he[0],et=o.get(J.maskId),q=this.objectStates.get(et.id);q&&q.visible!==!1&&(Re=!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=pe.filter)}if(!i){t.translate(qt,Kt),t.rotate(j*Math.PI/180);const J=n.skew_x||0,et=n.skew_y||0;if(J!==0||et!==0){const Dt=Math.tan(J*Math.PI/180),Qt=Math.tan(et*Math.PI/180);t.transform(1+Dt*Qt,Qt,Dt,1,0,0)}const q=n.rotate_x!==void 0?n.rotate_x:((F=n.transform)==null?void 0:F.rotate_x)??0,D=n.rotate_y!==void 0?n.rotate_y:((Z=n.transform)==null?void 0:Z.rotate_y)??0,tt=1+(n.translate_z!==void 0?n.translate_z:((st=n.transform)==null?void 0:st.translate_z)??0)/1e3,ut=(n.flip_x===!0?-1:1)*Math.cos(D*Math.PI/180)*tt,Wt=(n.flip_y===!0?-1:1)*Math.cos(q*Math.PI/180)*tt;t.scale(ft*ut,Rt*Wt)}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 de=r.shadow;if(de&&de.isEnabled!==!1&&!e){let J=de.color||"#000000";(ct=(at=this.artboard)==null?void 0:at.tokens)!=null&&ct.colors&&this.artboard.tokens.colors[J]&&(J=this.artboard.tokens.colors[J]);const et=this.normalizeOpacity(de.opacity??100)*.75,q=de.spread||0,it=(de.blur||0)+q*1.5;let tt=J;if(J.startsWith("#")){const Dt=J.replace("#",""),Qt=parseInt(Dt.substring(0,2),16),zt=parseInt(Dt.substring(2,4),16),Xt=parseInt(Dt.substring(4,6),16);tt=`rgba(${Qt}, ${zt}, ${Xt}, ${et})`}else if(J.startsWith("rgba")){const Dt=J.match(/[\d.]+/g);if(Dt&&Dt.length>=4){const Qt=Dt[0],zt=Dt[1],Xt=Dt[2],x=Dt[3];tt=`rgba(${Qt}, ${zt}, ${Xt}, ${parseFloat(x)*et})`}}const ut=t.getTransform(),Wt=Math.sqrt(ut.a*ut.a+ut.b*ut.b)||1;t.shadowColor=tt,t.shadowBlur=it*Wt,t.shadowOffsetX=(de.offsetX||0)*Wt,t.shadowOffsetY=(de.offsetY||0)*Wt}const Et=s.liquidFill||((dt=s.style)==null?void 0:dt.liquidFill);if(Et&&Et.enabled){t.save();const J=Et.fillLevel??.5;t.beginPath();const et=d/2-d*J;t.rect(-c/2,et,c,d*J),t.clip(),t.fillStyle=Et.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(Et.opacity??1)}if(e||this.applyOuterGlowUnderlay(t,s,l,c,d,p,r,o),(a==null?void 0:a.type)==="Text")this._renderText(t,s,l,r,n,c,d,!1,!1);else if((a==null?void 0:a.type)==="Image"||(($=r.fill)==null?void 0:$.type)==="Image"||s.type==="Image"&&(a!=null&&a.src||(X=r.fill)!=null&&X.src)){const J=(a==null?void 0:a.originalSrc)||(a==null?void 0:a.src)||((N=r.fill)==null?void 0:N.originalSrc)||((ot=r.fill)==null?void 0:ot.src)||(s==null?void 0:s.src);if(J){let et=this.imageCache.get(J);et||(et=new Image,et.onload=()=>{this.log(`[ExodeUI] Image loaded successfully, size: ${et.naturalWidth}x${et.naturalHeight}`)},et.onerror=it=>{console.error("[ExodeUI] Image load failed:",it,`Src preview: ${J.substring(0,100)}...`)},et.src=J,this.imageCache.set(J,et));const q=r.stroke&&r.stroke.width>0&&r.stroke.isEnabled!==!1,D=(((bt=r.stroke)==null?void 0:bt.alignment)||"center").toLowerCase();if(q&&D==="outside"&&this.applyStrokeAlignment(t,r,l,c,d,p),r.fill&&r.fill.type!=="None"){t.save();const it=t.globalAlpha,tt=this.createCanvasFill(t,r.fill,c,d);t.fillStyle=tt||r.fill.color||"transparent",t.globalAlpha=it*this.normalizeOpacity(r.fill.opacity??100),p!==0?(this.drawRoundRect(t,-c/2,-d/2,c,d,p),t.fill()):t.fillRect(-c/2,-d/2,c,d),t.globalAlpha=it,t.restore()}if(et.complete&&et.naturalWidth>0){const it=Zt?this.processFabricAdjustmentsCanvas(et,c,d,Zt):et;p!==0?(t.save(),this.drawRoundRect(t,-c/2,-d/2,c,d,p),t.clip(),t.drawImage(it,-c/2,-d/2,c,d),t.restore()):t.drawImage(it,-c/2,-d/2,c,d),q&&(D==="inside"||D==="center")&&this.applyStrokeAlignment(t,r,l,c,d,p)}else q&&(D==="inside"||D==="center")&&this.applyStrokeAlignment(t,r,l,c,d,p)}}else if(a.type==="SVG"){const J=a.svgContent;if(J){const et=r.palette||[],q=r.fill,D=r.stroke,it=q?this.normalizeOpacity(q.opacity??100):1,tt=D&&D.isEnabled!==!1?this.normalizeOpacity(D.opacity??100):1,ut=(q==null?void 0:q.type)==="Solid"&&(!D||D.isEnabled===!1||D.type==="Solid"&&D.color===q.color&&tt===it),Wt=q&&q.type!=="None"?ut?"monochrome":q.type==="Solid"?(q.color||"")+"|opacity:"+it:JSON.stringify(q.stops||[])+"|opacity:"+it:"",Dt=D&&D.isEnabled!==!1&&(D.width||0)>0?ut?["monochrome",D.width||0,D.trimStart??0,D.trimEnd??1,D.trimOffset??0,D.dashOffset??0].join("|"):[D.width||0,D.fill?D.fill.type==="Solid"?D.fill.color||"":JSON.stringify(D.fill.stops||[]):D.color||"",D.opacity??1,D.lineCap||"",D.lineJoin||"",(D.dashArray||[]).join(","),D.trimStart??0,D.trimEnd??1,D.trimOffset??0,D.dashOffset??0].join("|"):"nostroke",Qt=[s.id,et.join("_"),Wt,Dt,n.opacity??100,n.visible!==!1?"v":"h"].join("_");let zt=this.imageCache.get(Qt);if(!zt){zt=new Image,zt.crossOrigin="anonymous";let x=J;x.match(/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i)||(x=x.replace(/<svg([^>]*)>/i,(mt,$t)=>`<svg xmlns="http://www.w3.org/2000/svg"${$t}>`));let rt=a.width||c||100,It=a.height||d||100;const Ft=x.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(Ft&&(rt=parseFloat(Ft[1]),It=parseFloat(Ft[2])),x=x.replace(/<svg([^>]*)>/i,(mt,$t)=>{let vt=$t.replace(/\b(?:width|height)=["'][^"']*["']/gi," ");return vt.match(/\bviewBox=/i)||(vt+=` viewBox="0 0 ${rt} ${It}"`),vt.match(/\bpreserveAspectRatio=/i)||(vt+=' preserveAspectRatio="none"'),vt+=' width="100%" height="100%"',`<svg${vt}>`}),a.colors&&a.colors.length>0&&et.length>0&&a.colors.forEach((mt,$t)=>{if(et[$t]){const vt=mt.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),xt=new RegExp(vt,"gi");x=x.replace(xt,et[$t])}}),q&&q.type&&q.type!=="None"){if(q.type==="Solid"&&q.color){const mt=ut?"#FFFFFF":q.color,$t=ut?1:this.normalizeOpacity(q.opacity??100);x=x.replace(/\bfill\s*=\s*["'][^"']*["']/gi,vt=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(vt)?vt:`fill="${mt}"`),x=x.replace(/fill\s*:\s*[^;"')]+/gi,vt=>/fill\s*:\s*(none|transparent)/i.test(vt)?vt:`fill:${mt}`),$t<1&&(x=x.replace(/\bfill-opacity\s*=\s*["'][^"']*["']/gi,`fill-opacity="${$t}"`),x=x.replace(/fill-opacity\s*:\s*[^;"')]+/gi,`fill-opacity:${$t}`),x.match(/\bfill-opacity\s*=/i)||(x=x.replace(/(<svg[^>]*>)/i,`$1<g fill-opacity="${$t}">`),x=x.replace(/<\/svg>/i,"</g></svg>")))}else if(q.type==="LinearGradient"||q.type==="RadialGradient"||q.type==="Linear"||q.type==="Radial"){const mt="exode-fill",$t=this.normalizeOpacity(q.opacity??100),vt=(q.stops||[]).map(kt=>{const oe=kt.offset!==void 0?kt.offset:kt.pos??0,re=this.normalizeOpacity(kt.opacity??100)*$t;return`<stop offset="${oe*100}%" stop-color="${kt.color||"#000"}" stop-opacity="${re}"/>`}).join("");let xt="";if(q.type==="LinearGradient"||q.type==="Linear"){const kt=(se,ee)=>Array.isArray(se)?se[ee]??(ee===0?0:1):se&&typeof se=="object"?se[ee===0?"x":"y"]??(ee===0?0:1):ee===0?0:1,oe=kt(q.start,0)*100,re=kt(q.start,1)*100,ke=kt(q.end,0)*100,Jt=kt(q.end,1)*100;xt=`<linearGradient id="${mt}" x1="${oe}%" y1="${re}%" x2="${ke}%" y2="${Jt}%" gradientUnits="objectBoundingBox">${vt}</linearGradient>`}else{const kt=(Jt,se)=>Array.isArray(Jt)?Jt[se]??.5:Jt&&typeof Jt=="object"?Jt[se===0?"x":"y"]??.5:.5,oe=kt(q.center,0)*100,re=kt(q.center,1)*100,ke=(q.radius??.5)*100;xt=`<radialGradient id="${mt}" cx="${oe}%" cy="${re}%" r="${ke}%" gradientUnits="objectBoundingBox">${vt}</radialGradient>`}/<defs>/i.test(x)?x=x.replace(/<defs>/i,`<defs>${xt}`):x=x.replace(/<svg([^>]*)>/i,`<svg$1><defs>${xt}</defs>`),x=x.replace(/\bfill\s*=\s*["'][^"']*["']/gi,kt=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(kt)?kt:`fill="url(#${mt})"`),x=x.replace(/fill\s*:\s*[^;"')]+/gi,kt=>/fill\s*:\s*(none|transparent)/i.test(kt)?kt:`fill:url(#${mt})`)}}const K=(mt,$t,vt=1)=>{const xt=(mt.stops||[]).map(Jt=>{const se=Jt.offset!==void 0?Jt.offset:Jt.pos??0,ee=this.normalizeOpacity(Jt.opacity??100)*vt;return`<stop offset="${se*100}%" stop-color="${Jt.color||"#000"}" stop-opacity="${ee}"/>`}).join(""),kt=(Jt,se,ee=.5)=>Array.isArray(Jt)?Jt[se]??ee:Jt&&typeof Jt=="object"?Jt[se===0?"x":"y"]??ee:ee;if(mt.type==="LinearGradient"||mt.type==="Linear"){const Jt=kt(mt.start,0,0)*100,se=kt(mt.start,1,0)*100,ee=kt(mt.end,0,1)*100,Ae=kt(mt.end,1,1)*100;return`<linearGradient id="${$t}" x1="${Jt}%" y1="${se}%" x2="${ee}%" y2="${Ae}%" gradientUnits="objectBoundingBox">${xt}</linearGradient>`}const oe=kt(mt.center,0,.5)*100,re=kt(mt.center,1,.5)*100,ke=(mt.radius??.5)*100;return`<radialGradient id="${$t}" cx="${oe}%" cy="${re}%" r="${ke}%" gradientUnits="objectBoundingBox">${xt}</radialGradient>`},ht=(mt,$t)=>/<defs>/i.test(mt)?mt.replace(/<defs>/i,`<defs>${$t}`):mt.replace(/(<svg[^>]*>)/i,`$1<defs>${$t}</defs>`);if(D&&D.isEnabled!==!1&&(D.width||0)>0){const mt=ut?1:this.normalizeOpacity(D.opacity??100),$t=ut?"#FFFFFF":D.color||(q==null?void 0:q.color)||"#000000";let vt="";const xt=D.fill;if(xt&&xt.type){if(xt.type==="Solid")vt=xt.color||D.color||"#000000";else if(xt.type==="LinearGradient"||xt.type==="RadialGradient"||xt.type==="Linear"||xt.type==="Radial"){const te="exode-stroke";x=ht(x,K(xt,te,mt)),vt=`url(#${te})`}}vt||(vt=$t),x.match(/\bstroke\s*=\s*["']/i)?x=x.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,te=>/stroke\s*=\s*["']\s*(none|transparent)\s*["']/i.test(te)?te:`stroke="${vt}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke="${vt}"`),x=x.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),`stroke:${vt}`);let kt=a.width||c||100,oe=a.height||d||100;const re=J.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(re){const te=parseFloat(re[1]),fe=parseFloat(re[2]);!isNaN(te)&&!isNaN(fe)&&(kt=te,oe=fe)}const ke=Math.max(.001,c/kt),Jt=Math.max(.001,d/oe),se=(ke+Jt)/2,ee=(D.width||1)/se;x.match(/\bstroke-width\s*=\s*["']/i)?x=x.replace(/\bstroke-width\s*=\s*["'][^"']*["']/gi,`stroke-width="${ee}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-width="${ee}"`),x=x.replace(/stroke-width\s*:\s*[^;"')]+/gi,`stroke-width:${ee}`),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 Ae=D.lineCap||"round";x.match(/\bstroke-linecap\s*=\s*["']/i)?x=x.replace(/\bstroke-linecap\s*=\s*["'][^"']*["']/gi,`stroke-linecap="${Ae}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linecap="${Ae}"`),x=x.replace(/stroke-linecap\s*:\s*[^;"')]+/gi,`stroke-linecap:${Ae}`);const $e=D.lineJoin||"round";x.match(/\bstroke-linejoin\s*=\s*["']/i)?x=x.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${$e}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linejoin="${$e}"`),x=x.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${$e}`);const Be=D.trimStart??0,We=D.trimEnd??1,Ye=D.trimOffset??0,Xe=D.dashOffset??0,Ve=Be!==0||We!==1||Ye!==0||Xe!==0;if(Ve){const te=Math.max(0,Math.min(1,Be)),fe=Math.max(0,Math.min(1,We));this.frameCount%600===0&&this.debugLog(`SVG Trim - Object: ${s.name||s.id}, Start: ${te}, End: ${fe}`);const be=(kt+oe)*2,De=(Ye%1+1)%1,Ge=(Xe%1+1)%1;let we="",Se=0;if(te>=fe)we=`0 ${be}`,Se=0;else{const ve=be*(fe-te),V=be-ve;Se=-(be*(te+De+Ge)),we=`${ve} ${V}`}x.match(/\bstroke-dasharray\s*=/i)?x=x.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${we}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dasharray="${we}"`),x=x.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${we}`),x.match(/\bstroke-dashoffset\s*=/i)?x=x.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${Se}"`):x=x.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dashoffset="${Se}"`),x=x.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${Se}`)}else if(D.dashArray&&D.dashArray.length>0){const te=D.dashArray.join(" ");if(x=x.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${te}"`),x=x.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${te}`),D.dashOffset){const fe=(kt+oe)*2,be=-(D.dashOffset*fe);x=x.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${be}"`),x=x.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${be}`)}}if(!/\bstroke\s*=\s*["']/i.test(J)&&!new RegExp("(?<![a-z-])stroke\\s*:","i").test(J)){let te="",fe="";if(Ve){const we=a.width||c||100,Se=a.height||d||100,ve=(we+Se)*2,V=Math.max(0,Math.min(1,Be)),Q=Math.max(0,Math.min(1,We)),U=(Ye%1+1)%1,lt=(Xe%1+1)%1;if(V>=Q)te=` stroke-dasharray="0 ${ve}"`,fe=' stroke-dashoffset="0"';else{const Tt=ve*(Q-V),Lt=ve-Tt,Yt=-(ve*(V+U+lt));te=` stroke-dasharray="${Tt} ${Lt}"`,fe=` stroke-dashoffset="${Yt}"`}}else(St=D.dashArray)!=null&&St.length&&(te=` stroke-dasharray="${D.dashArray.join(" ")}"`,D.dashOffset&&(fe=` stroke-dashoffset="${D.dashOffset}"`));const be=` stroke-linecap="${D.lineCap||"round"}"`,De=` stroke-linejoin="${D.lineJoin||"round"}"`,Ge=`stroke="${vt}" stroke-width="${ee}" stroke-opacity="${mt}"${be}${De}${te}${fe}`;x=x.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(we,Se,ve)=>`${Se}${ve}<g ${Ge}>`),x=x.replace(/<\/svg>/i,"</g></svg>")}}else D&&D.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 gt=new Blob([x],{type:"image/svg+xml"}),jt=URL.createObjectURL(gt);zt.onload=()=>{if(URL.revokeObjectURL(jt),this.frameCount%900===0){const mt=this.imageCache.get(Qt);mt&&this.debugLog(`SVG Payload Ready: ${s.name||s.id} (${mt.naturalWidth}x${mt.naturalHeight})`)}},zt.onerror=()=>{URL.revokeObjectURL(jt),this.debugLog(`SVG Error: Failed to load payload for ${s.name||s.id}`)},zt.src=jt,this.imageCache.set(Qt,zt)}let Xt=null;if(zt.complete&&zt.naturalWidth>0?(Xt=zt,this.lastValidSvgImgMap.set(s.id,zt)):Xt=this.lastValidSvgImgMap.get(s.id)||null,Xt&&Xt.complete&&Xt.naturalWidth>0){const x=Math.max(1,c),rt=Math.max(1,d);if(ut&&(q==null?void 0:q.type)==="Solid"){this.maskBuffer||(this.maskBuffer=document.createElement("canvas"),this.maskCtx=this.maskBuffer.getContext("2d")),this.maskBuffer.width=x,this.maskBuffer.height=rt,this.maskCtx.setTransform(1,0,0,1,0,0),this.maskCtx.globalCompositeOperation="source-over",this.maskCtx.globalAlpha=1,this.maskCtx.filter="none",this.maskCtx.clearRect(0,0,x,rt),this.maskCtx.drawImage(Xt,0,0,x,rt),this.maskCtx.globalCompositeOperation="source-in";const It=q.color||"#000000",Ft=this.normalizeOpacity(q.opacity??100);this.maskCtx.fillStyle=It,this.maskCtx.globalAlpha=Ft,this.maskCtx.fillRect(0,0,x,rt),t.drawImage(this.maskBuffer,-x/2,-rt/2,x,rt)}else p!==0?(t.save(),this.drawRoundRect(t,-x/2,-rt/2,x,rt,p),t.clip(),t.drawImage(Xt,-x/2,-rt/2,x,rt),t.restore()):t.drawImage(Xt,-x/2,-rt/2,x,rt)}}}else if(l.type==="LineGraph")this.renderLineGraph(t,l,c,d);else if(s.type==="Shape"){if(this.applyPath(t,l,c,d,p),t.save(),r.blur&&r.blur.amount>0&&(t.filter=`blur(${r.blur.amount}px)`),le&&ae==="BackgroundBlur")if(e)t.fillStyle="#000000",t.globalAlpha=1,this.applyPath(t,l,c,d,p),t.fill();else{if(t.shadowColor&&t.shadowColor!=="rgba(0, 0, 0, 0)"&&t.shadowColor!=="transparent"){const q=t.getTransform(),D=t.shadowOffsetX,it=t.shadowOffsetY;t.shadowOffsetX=D+1e4*q.a,t.shadowOffsetY=it+1e4*q.b,t.save(),t.translate(-1e4,0),this.applyPath(t,l,c,d,p),t.fillStyle="white",t.fill(),t.restore(),t.shadowOffsetX=D,t.shadowOffsetY=it,t.shadowColor="transparent"}this.applyBackgroundBlurGlass(t,l,c,d,p,Bt,r)}else if(r.fill){const et=t.globalAlpha;if(((Mt=r.fill)==null?void 0:Mt.type)==="Image"&&(r.fill.originalSrc||r.fill.src)){const q=r.fill.originalSrc||r.fill.src;let D=this.imageCache.get(q);D||(D=new Image,D.src=q,this.imageCache.set(q,D)),D.complete&&D.naturalWidth>0&&(t.save(),this.applyPath(t,l,c,d,p),t.clip(),this.renderFittedImage(t,D,-c/2,-d/2,c,d,r.fill.fillMode),t.restore())}else{const q=this.createCanvasFill(t,r.fill,c,d);t.fillStyle=q||(typeof r.fill=="string"?r.fill:r.fill.color||"transparent"),t.globalAlpha=et*this.normalizeOpacity(r.fill.opacity??100),this.applyPath(t,l,c,d,p),t.fill()}t.globalAlpha=et}t.restore(),r.stroke&&r.stroke.width>0&&(this.applyPath(t,l,c,d,p),this.applyStrokeAlignment(t,r,l,c,d,p))}else if(s.type==="Frame"||s.type==="Component"&&!s.variant||s.type==="Group"&&!s.isStructuralGroup){const J=n.width??a.width??s.width??c,et=n.height??a.height??s.height??d,q=p;if(t.save(),t.beginPath(),this.drawRoundRect(t,-J/2,-et/2,J,et,q),le&&ae==="BackgroundBlur")if(e)t.fillStyle="#000000",t.globalAlpha=1,t.beginPath(),this.drawRoundRect(t,-J/2,-et/2,J,et,q),t.fill();else{if(t.shadowColor&&t.shadowColor!=="rgba(0, 0, 0, 0)"&&t.shadowColor!=="transparent"){const tt=t.getTransform(),ut=t.shadowOffsetX,Wt=t.shadowOffsetY;t.shadowOffsetX=ut+1e4*tt.a,t.shadowOffsetY=Wt+1e4*tt.b,t.save(),t.translate(-1e4,0),t.beginPath(),this.drawRoundRect(t,-J/2,-et/2,J,et,q),t.fillStyle="white",t.fill(),t.restore(),t.shadowOffsetX=ut,t.shadowOffsetY=Wt,t.shadowColor="transparent"}this.applyBackgroundBlurGlass(t,l,J,et,q,Bt,r)}else if(r.fill&&r.fill.type!=="None"){const it=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 ut=this.imageCache.get(tt);ut||(ut=new Image,ut.src=tt,this.imageCache.set(tt,ut)),ut.complete&&ut.naturalWidth>0&&(t.save(),t.beginPath(),this.drawRoundRect(t,-J/2,-et/2,J,et,q),t.clip(),this.renderFittedImage(t,ut,-J/2,-et/2,J,et,r.fill.fillMode),t.restore())}else{const tt=this.createCanvasFill(t,r.fill,J,et);t.fillStyle=tt||r.fill.color||"transparent",t.globalAlpha=it*this.normalizeOpacity(r.fill.opacity??100),t.beginPath(),this.drawRoundRect(t,-J/2,-et/2,J,et,q),t.fill(),t.globalAlpha=it}}if(t.restore(),!e&&(le&&ae==="BackgroundBlur"||r.fill&&r.fill.type!=="None")&&(t.shadowColor="transparent"),r.stroke&&r.stroke.width>0&&r.stroke.isEnabled!==!1){const it={type:"Rectangle"};t.beginPath(),this.drawRoundRect(t,-J/2,-et/2,J,et,q),this.applyStrokeAlignment(t,r,it,J,et,q)}}else s.type==="Group"&&s.isStructuralGroup||(s.type==="Component"&&s.variant==="inputbox"?this.renderInputBox(t,s):s.type==="Component"&&s.variant==="button"?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:",(wt=s.geometry)==null?void 0:wt.type));if(e||(this.applyInnerGlowOverlay(t,s,l,c,d,p,r),this.applyArtEffectOverlay(t,s,l,c,d,p)),Et&&Et.enabled&&t.restore(),s.children&&s.children.length>0){const et=s.type==="Frame",q=s.clipsContent!==void 0?s.clipsContent:s.clipContent!==void 0?s.clipContent:et;if(t.save(),q){t.beginPath();const it=n.width??(a==null?void 0:a.width)??s.width??0,tt=n.height??(a==null?void 0:a.height)??s.height??0,ut=n.cornerRadius??(a==null?void 0:a.corner_radius)??s.cornerRadius??0;this.drawRoundRect(t,-it/2,-tt/2,it,tt,ut),t.clip()}let D=0;for(s.children.forEach(it=>{const tt=o.get(it);if(!tt)return;const ut=this.objectStates.get(it),Wt=(ut==null?void 0:ut.geometry)||tt.geometry;if(Wt&&Wt.isMask&&(ut==null?void 0:ut.visible)!==!1){const Dt=Wt.width||0,Qt=Wt.height||0;this.applyObjectTransform(t,it);const zt=(ut==null?void 0:ut.corner_radius)??(Wt==null?void 0:Wt.corner_radius)??0;this.applyPath(t,Wt,Dt,Qt,zt),t.clip(),D++}else this.renderObject(t,tt,o,e)});D>0;)t.restore(),D--;t.restore()}if(Re){this.maskCtx.restore(),(n.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(D=>D.isVisible!==!1&&o.has(D.maskId)).forEach(D=>{var zt,Xt,x,rt,It,Ft;const it=o.get(D.maskId),tt=this.objectStates.get(it.id),ut=D.feather||0,Wt=D.inverted===!0,Dt=D.opacity!==void 0?typeof D.opacity=="number"?D.opacity:D.opacity/100:1;if((D.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,it.id,o),ut>0&&(this.lumaCtx.filter=`blur(${ut}px)`),this.lumaCtx.globalAlpha=Dt;const K=(tt==null?void 0:tt.width)||it.geometry.width||0,ht=(tt==null?void 0:tt.height)||it.geometry.height||0,gt=(tt==null?void 0:tt.corner_radius)??it.corner_radius??0;if(((zt=it.geometry)==null?void 0:zt.type)==="Text"){const vt=tt!=null&&tt.geometry?this.deepMerge(it.geometry,tt.geometry):it.geometry,xt=tt!=null&&tt.style?this.deepMerge(it.style,tt.style):it.style;this._renderText(this.lumaCtx,it,{...vt,width:K,height:ht,corner_radius:gt},xt,tt,K,ht,!0,!1)}else if(((Xt=it.geometry)==null?void 0:Xt.type)==="Image"){const vt=it.geometry.src;if(vt){let xt=this.imageCache.get(vt);xt||(xt=new Image,xt.src=vt,this.imageCache.set(vt,xt)),xt.complete&&xt.naturalWidth>0?this.lumaCtx.drawImage(xt,-K/2,-ht/2,K,ht):(this.applyPath(this.lumaCtx,it.geometry,K,ht,gt),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else if(((x=it.geometry)==null?void 0:x.type)==="SVG"){const vt=it.geometry.svgContent;if(vt){const xt=`__lumamask_${it.id}`;let kt=this.imageCache.get(xt);if(!kt){kt=new Image;const oe=new Blob([vt],{type:"image/svg+xml"});kt.src=URL.createObjectURL(oe),kt.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(xt,kt)}kt.complete&&kt.naturalWidth>0?this.lumaCtx.drawImage(kt,-K/2,-ht/2,K,ht):(this.applyPath(this.lumaCtx,it.geometry,K,ht,gt),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else this.applyPath(this.lumaCtx,it.geometry,K,ht,gt),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill();this.lumaCtx.restore();const jt=this.maskCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight),mt=this.lumaCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight).data,$t=jt.data;for(let vt=0;vt<$t.length;vt+=4){const xt=mt[vt],kt=mt[vt+1],oe=mt[vt+2];let re=(.299*xt+.587*kt+.114*oe)/255;Wt&&(re=1-re),$t[vt+3]*=re}this.maskCtx.putImageData(jt,0,0)}else{this.maskCtx.save(),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),this.maskCtx.globalCompositeOperation=Wt?"destination-out":"destination-in",ut>0&&(this.maskCtx.filter=`blur(${ut}px)`),this.maskCtx.globalAlpha=Dt,this.applyAbsoluteTransform(this.maskCtx,it.id,o);const K=(tt==null?void 0:tt.width)||it.geometry.width||0,ht=(tt==null?void 0:tt.height)||it.geometry.height||0,gt=(tt==null?void 0:tt.corner_radius)??it.corner_radius??0;if(((rt=it.geometry)==null?void 0:rt.type)==="Text"){const jt=tt!=null&&tt.geometry?this.deepMerge(it.geometry,tt.geometry):it.geometry,mt=tt!=null&&tt.style?this.deepMerge(it.style,tt.style):it.style;this._renderText(this.maskCtx,it,{...jt,width:K,height:ht,corner_radius:gt},mt,tt,K,ht,!0,!1)}else if(((It=it.geometry)==null?void 0:It.type)==="Image"){const jt=it.geometry.src;if(jt){let mt=this.imageCache.get(jt);mt||(mt=new Image,mt.src=jt,this.imageCache.set(jt,mt)),mt.complete&&mt.naturalWidth>0?this.maskCtx.drawImage(mt,-K/2,-ht/2,K,ht):(this.applyPath(this.maskCtx,it.geometry,K,ht,gt),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else if(((Ft=it.geometry)==null?void 0:Ft.type)==="SVG"){const jt=it.geometry.svgContent;if(jt){const mt=`__alphamask_${it.id}`;let $t=this.imageCache.get(mt);if(!$t){$t=new Image;const vt=new Blob([jt],{type:"image/svg+xml"});$t.src=URL.createObjectURL(vt),$t.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(mt,$t)}$t.complete&&$t.naturalWidth>0?this.maskCtx.drawImage($t,-K/2,-ht/2,K,ht):(this.applyPath(this.maskCtx,it.geometry,K,ht,gt),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else this.applyPath(this.maskCtx,it.geometry,K,ht,gt),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill();this.maskCtx.restore()}}),pe.save(),pe.setTransform(1,0,0,1,0,0);const q=s.maskBlendMode||s.blendMode;q&&q!=="Normal"&&(pe.globalCompositeOperation=q.toLowerCase()),pe.drawImage(this.maskBuffer,0,0),pe.restore(),pe.restore()}else t.restore()}}applyOuterGlowUnderlay(t,s,o,e,i,n,a,r){var I,T,k;const c=a||s.style||{},d=c.effect,u=c.effects||(d?[d]:[]),p=u.find(E=>E.isEnabled!==!1&&E.type==="Glow"&&(E.mode==="outer"||E.mode==="Outer Glow"||!E.mode));if(!p)return;const l=p.blur||10,h=1e4;let f=p.color||"white";(T=(I=this.artboard)==null?void 0:I.tokens)!=null&&T.colors&&this.artboard.tokens.colors[f]&&(f=this.artboard.tokens.colors[f]),t.save();const g=c.fill&&c.fill.type!=="None",y=u.some(E=>E.isEnabled!==!1&&E.type==="BackgroundBlur"),m=s.type==="Text",S=s.type==="Group";!m&&!S&&(g||y)&&(t.beginPath(),t.rect(-1e6,-1e6,2e6,2e6),s.type==="Frame"||s.type==="Component"?this.drawRoundRect(t,-e/2,-i/2,e,i,n):this._tracePath(t,o,e,i,n),t.clip("evenodd"));const v=t.getTransform();t.shadowColor=f,t.shadowBlur=l,t.shadowOffsetX=h*v.a,t.shadowOffsetY=h*v.b,t.translate(-h,0);let C="black";c.fill&&c.fill.type!=="None"&&(C=this.createCanvasFill(t,c.fill,e,i)||c.fill.color||"black");let w="black";c.stroke&&c.stroke.width>0&&(w=this.createCanvasFill(t,c.stroke.fill||{type:"Solid",color:c.stroke.color},e,i)||c.stroke.color||"black"),t.fillStyle=C,t.strokeStyle=w,t.lineWidth=((k=c.stroke)==null?void 0:k.width)||0;const M=Math.min(p.intensity||1,10);for(let E=0;E<M;E++)if(r)this.renderObject(t,s,r,!0,!0);else if(o.type==="Text")c.fill&&c.fill.type!=="None"&&t.fillText(s.text||"",0,0),c.stroke&&c.stroke.width>0&&t.strokeText(s.text||"",0,0);else if(o.points&&o.type==="Path")this.applyPath(t,o,e,i,n),c.fill&&c.fill.type!=="None"&&t.fill(),c.stroke&&c.stroke.width>0&&t.stroke();else{if(t.beginPath(),o.type==="circle"||o.type==="Ellipse"){const L=e/2,A=i/2;t.ellipse(0,0,L,A,0,0,Math.PI*2)}else n!==0?this.drawRoundRect(t,-e/2,-i/2,e,i,n):t.rect(-e/2,-i/2,e,i);const P=c.fill&&c.fill.type!=="None",_=c.stroke&&c.stroke.width>0;(P||!P&&!_)&&t.fill(),_&&t.stroke()}t.restore()}_renderText(t,s,o,e,i,n,a,r=!1,c=!1){var ot,bt,St,Mt,pt,wt,yt,qt,Kt;let d=o.text||"";if(o.textInputId&&!r){const j=this.inputs.get(o.textInputId);j!==void 0&&(d=String(j),i.geometry&&i.geometry.type==="Text"&&(i.geometry.text=d))}if(o.svgPath){const j=o.svgPath;t.save();const ft=((ot=e==null?void 0:e.fill)==null?void 0:ot.color)||"#000000",Rt=((bt=e==null?void 0:e.fill)==null?void 0:bt.opacity)!==void 0?(St=e==null?void 0:e.fill)==null?void 0:St.opacity:1;t.fillStyle=ft,t.globalAlpha*=Rt;const At=new Path2D(j);t.fill(At),t.restore();return}let u=d||"";o.enableSegments===!0&&o.segments&&Array.isArray(o.segments)&&(u=o.segments.map(j=>j&&j.text?j.text:"").join(""));const p=o.textCase||"none";p==="uppercase"?u=u.toUpperCase():p==="lowercase"?u=u.toLowerCase():p==="capitalize"&&(u=u.replace(/\b\w/g,j=>j.toUpperCase()));let l=((Mt=o.fontWeight)==null?void 0:Mt.toString())||"400",h=o.fontStyle||"normal";l.toLowerCase().includes("italic")&&(h="italic",l=l.replace(/italic/gi,"").trim()||"400");const f=this.mapFontWeight(l),g=Math.max(1,o.fontSize||32);let y=o.fontFamily||"Inter";const m=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];m.forEach(j=>{const ft=new RegExp(`[\\s-]${j}$`,"i");ft.test(y)&&(y=y.replace(ft,"").trim())});const S=o.smallCaps===!0,C=`${S?"small-caps ":""}${h} ${f} ${g}px "${y}", sans-serif`;t.font=C;const w=o.textVerticalAlign||"top";t.textBaseline="top";const M=o.textAlign||"left";t.textAlign=M;let I=0;if(typeof o.letterSpacing=="number")I=o.letterSpacing;else if(typeof o.letterSpacing=="object"&&o.letterSpacing.value!==void 0){const j=o.letterSpacing;I=j.unit==="PERCENT"?j.value/100*g:j.value}t.letterSpacing!==void 0&&(t.letterSpacing=`${I}px`);const T=o.kerning||"auto",k=o.kerningValue||0;T==="manual"&&k!==0&&(t.letterSpacing=`${I+k}px`);const E=o.paragraphSpacing||0;let P=o.lineHeight??1.2;typeof P=="string"&&(P=parseFloat(P)),P>5&&g>0&&(P=P/g);const _=(P||1.2)*g,L=o.isPointText===!0||!o.width||o.width<=0,A=((pt=o.padding)==null?void 0:pt.left)||((wt=o.padding)==null?void 0:wt.right)||0,W=L?1e5:o.width&&o.width>0?Math.ceil(o.width)-A*2:1e5;o.autoHeight;const B=ts({text:u,fontFamily:y,fontSize:g,fontWeight:f,fontStyle:h,lineHeight:P,width:W,letterSpacing:I,paragraphSpacing:E,paragraphIndent:o.paragraphIndent||0,segments:o.segments,enableSegments:o.enableSegments,textCase:p,hyphenation:o.hyphenation,composer:o.composer,balanceRaggedLines:o.balanceRaggedLines}),R=B.lines||[],Y=B.maxFontSize||g,G=this.fontLeadingFactors[y]??.5,z=(_-g)*G;let O=B.height,F=n,Z=a;if(F===0||Z===0||F>=1e5||L){let j=0,ft=0;const Rt=B.fullText||u;(R||[]).forEach(At=>{const Pt=At.text||"",Ot=t.measureText(Pt).width+(Pt.length>0?(Pt.length-1)*I:0);Ot>j&&(j=Ot),ft+=Pt.length,ft<Rt.length&&(Rt[ft]===`
|
|
8
|
-
`||
|
|
9
|
-
`&&ft++)}),(
|
|
10
|
-
`||
|
|
11
|
-
`||
|
|
12
|
-
`||
|
|
13
|
-
`&&
|
|
14
|
-
`||At[Pt]==="\r")&&(
|
|
15
|
-
`&&Pt++)}),t.globalAlpha=ft}const
|
|
16
|
-
`||
|
|
17
|
-
`||
|
|
18
|
-
`&&Gt++)}),t.globalAlpha=ft}}}applyStrokeAlignment(t,s,o,e,i,n){if(!s.stroke||s.stroke.width<=0||s.stroke.isEnabled===!1)return;const a=s.stroke,r=t.getTransform(),c=Math.sqrt(r.a*r.a+r.b*r.b)||1,d=window.devicePixelRatio||1,u=(a.width||1)*d/c,p=(a.alignment||"center").toLowerCase();if(t.save(),s.fill&&s.fill.type!=="None"&&s.fill.isEnabled!==!1&&s.fill.opacity!==0&&s.fill.color!=="transparent"&&s.fill.color!=="rgba(0,0,0,0)"&&(t.shadowColor="transparent",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),a.fill){const v=this.createCanvasFill(t,a.fill,e,i);v?t.strokeStyle=v: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=u,t.lineCap=a.lineCap||"round",t.lineJoin=a.lineJoin||"round",a.miterLimit!==void 0&&(t.miterLimit=a.miterLimit);const f=a.trimStart??0,g=a.trimEnd??1,y=a.trimOffset??0,m=a.dashOffset??0,S=a.dashArray||[];if(f!==0||g!==1||y!==0){const v=this.getPerimeter(o,e,i);if(v>0){const C=Math.max(0,Math.min(1,f)),w=Math.max(0,Math.min(1,g));if(C<w){const M=v*(w-C),I=v-M,T=-(v*(C+y%1));t.setLineDash([M,I]),t.lineDashOffset=T-m*v}else if(C===w)t.setLineDash([0,v]);else{const M=v*(1-C+w),I=v-M,T=-(v*C);t.setLineDash([M,I]),t.lineDashOffset=T-m*v}}}else if(S.length>0||m!==0){S.length>0&&t.setLineDash(S);const v=this.getPerimeter(o,e,i);t.lineDashOffset=-(m*v)}if((o==null?void 0:o.type)==="Line"||e===0||i===0)this.applyPath(t,o,e,i,n),t.stroke();else if(p==="inside")t.lineWidth=u*2,t.save(),this.applyPath(t,o,e,i,n),t.clip(),t.stroke(),t.restore();else if(p==="outside"){t.save(),t.beginPath();const v=Math.max(e,i,2e4);t.rect(-v,-v,v*2,v*2),this._tracePath(t,o,e,i,n),t.clip("evenodd"),t.lineWidth=u*2,t.beginPath(),this.applyPath(t,o,e,i,n),t.stroke(),t.restore()}else t.lineWidth=u,this.applyPath(t,o,e,i,n),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,i=Math.abs(o)/2,n=Math.abs(t.sweepAngle??360),a=t.ratio||0,r=Math.PI*(3*(e+i)-Math.sqrt((3*e+i)*(e+3*i)));if(n>=360&&a<=0)return r;let c=n/360*r;if(a>0){const d=Math.PI*(3*(e*a+i*a)-Math.sqrt((3*e*a+i*a)*(e*a+3*i*a)));c+=n/360*d,n<360&&(c+=2*Math.sqrt((e-e*a)**2+(i-i*a)**2))}else n<360&&(c+=2*Math.max(e,i));return isNaN(c)?0:c}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,i=t.radius||Math.min(s,o)/2;return 2*e*i*Math.sin(Math.PI/e)}case"Star":{const e=t.points||5,i=t.outer_radius||Math.min(s,o)/2,n=t.inner_radius||i/2,a=Math.PI/e;return Math.sqrt(i*i+n*n-2*i*n*Math.cos(a))*e*2}case"Path":{const e=t.points||[];if(e.length<2)return t.length||0;let i=0,n=e[0].x,a=e[0].y;for(let r=1;r<e.length;r++){const c=e[r];if(c.moveTo){n=c.x,a=c.y;continue}const d=n,u=a,p=e[r-1].out_x,l=e[r-1].out_y;if(p!==void 0||c.in_x!==void 0?i+=this.getBezierLength(d,u,p??d,l??u,c.in_x??c.x,c.in_y??c.y,c.x,c.y):i+=Math.sqrt((c.x-d)**2+(c.y-u)**2),n=c.x,a=c.y,c.closePath||r===e.length-1&&(t.is_closed||t.isClosed)){const h=n,f=a,g=[...e.slice(0,r+1)].reverse().find(M=>M.moveTo)||e[0],y=g.x,m=g.y,S=e[r].out_x,v=e[r].out_y,C=g.in_x,w=g.in_y;S!==void 0||C!==void 0?i+=this.getBezierLength(h,f,S??h,v??f,C??y,w??m,y,m):i+=Math.sqrt((y-h)**2+(m-f)**2)}}return i}default:return(s+o)*2}}getBezierLength(t,s,o,e,i,n,a,r,c=10){let d=0,u=t,p=s;for(let l=1;l<=c;l++){const h=l/c,f=1-h,g=h*h,y=f*f,m=y*f,S=g*h,v=m*t+3*y*h*o+3*f*g*i+S*a,C=m*s+3*y*h*e+3*f*g*n+S*r,w=v-u,M=C-p;d+=Math.sqrt(w*w+M*M),u=v,p=C}return d}getBezierTAtLength(t,s,o,e,i,n,a,r,c,d=20){if(t<=0)return 0;let u=0,p=s,l=o;for(let h=1;h<=d;h++){const f=h/d,g=1-f,y=f*f,m=g*g,S=m*g,v=y*f,C=S*s+3*m*f*e+3*g*y*n+v*r,w=S*o+3*m*f*i+3*g*y*a+v*c,M=C-p,I=w-l,T=Math.sqrt(M*M+I*I);if(u+T>=t){const k=t-u,E=T===0?0:k/T;return(h-1+E)/d}u+=T,p=C,l=w}return 1}getPointOnPath(t,s,o,e){if(this.ensurePathPoints(t),(t==null?void 0:t.type)==="Path"){const i=t.points||[];if(i.length<2)return{x:0,y:0,angle:0};let n=1/0,a=-1/0,r=1/0,c=-1/0;i.forEach(m=>{typeof m.x=="number"&&typeof m.y=="number"&&(n=Math.min(n,m.x),a=Math.max(a,m.x),r=Math.min(r,m.y),c=Math.max(c,m.y),m.out_x!==void 0&&(n=Math.min(n,m.out_x),a=Math.max(a,m.out_x)),m.out_y!==void 0&&(r=Math.min(r,m.out_y),c=Math.max(c,m.out_y)),m.in_x!==void 0&&(n=Math.min(n,m.in_x),a=Math.max(a,m.in_x)),m.in_y!==void 0&&(r=Math.min(r,m.in_y),c=Math.max(c,m.in_y)))});const d=(n+a)/2,u=(r+c)/2,l=this.getPerimeter(t,s,o)*e;let h=0;const f=[];let g=i[0],y=i[0];for(let m=1;m<i.length;m++){const S=i[m];if(S.moveTo){g=S,y=S;continue}f.push({p0:g,p1:S}),(S.closePath||m===i.length-1&&(t.is_closed||t.isClosed))&&f.push({p0:S,p1:y}),g=S}for(const m of f){const S=m.p0,v=m.p1;let C=0;const w=S.out_x!==void 0||v.in_x!==void 0;if(w?C=this.getBezierLength(S.x,S.y,S.out_x??S.x,S.out_y??S.y,v.in_x??v.x,v.in_y??v.y,v.x,v.y):C=Math.sqrt((v.x-S.x)**2+(v.y-S.y)**2),h+C>=l||m===f[f.length-1]){let M=0;if(w)return M=this.getBezierTAtLength(l-h,S.x,S.y,S.out_x??S.x,S.out_y??S.y,v.in_x??v.x,v.in_y??v.y,v.x,v.y,20),this.getBezierPointAndAngle(M,S,v,d,u);{M=C===0?0:(l-h)/C;const I=S.x+(v.x-S.x)*M-d,T=S.y+(v.y-S.y)*M-u,k=Math.atan2(v.y-S.y,v.x-S.x);return{x:I,y:T,angle:k}}}h+=C}}else if(t.type==="Ellipse"){const i=Math.abs(s)/2,n=Math.abs(o)/2,a=t.sweepAngle??360,c=((t.startAngle??0)+a*e)*Math.PI/180,d=i*Math.cos(c),u=n*Math.sin(c),p=-i*Math.sin(c),l=n*Math.cos(c),h=Math.atan2(l,p);return{x:d,y:u,angle:h}}else if((t==null?void 0:t.type)==="Rectangle"){const i=Math.abs(s),n=Math.abs(o),r=(i+n)*2*e;let c=0,d=0,u=0;return r<i?(c=-i/2+r,d=-n/2,u=0):r<i+n?(c=i/2,d=-n/2+(r-i),u=Math.PI/2):r<2*i+n?(c=i/2-(r-(i+n)),d=n/2,u=Math.PI):(c=-i/2,d=n/2-(r-(2*i+n)),u=-Math.PI/2),{x:c,y:d,angle:u}}return{x:0,y:0,angle:0}}getBezierPointAndAngle(t,s,o,e,i){const n=s.x,a=s.y,r=s.out_x??s.x,c=s.out_y??s.y,d=o.in_x??o.x,u=o.in_y??o.y,p=o.x,l=o.y,h=1-t,f=t*t,g=h*h,y=g*h,m=f*t,S=y*n+3*g*t*r+3*h*f*d+m*p-e,v=y*a+3*g*t*c+3*h*f*u+m*l-i,C=3*g*(r-n)+6*h*t*(d-r)+3*f*(p-d),w=3*g*(c-a)+6*h*t*(u-c)+3*f*(l-u),M=Math.atan2(w,C);return{x:S,y:v,angle:M}}applyAbsoluteTransform(t,s,o){if(!o.get(s))return;const i=[];let n=s;for(;n;){i.unshift(n);const a=o.get(n);n=a==null?void 0:a.parentId}i.forEach(a=>{this.applyObjectTransform(t,a)})}applyObjectTransform(t,s){var h,f,g;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,i=o.skew_y||0;if(e!==0||i!==0){const y=Math.tan(e*Math.PI/180),m=Math.tan(i*Math.PI/180);t.transform(1+y*m,m,y,1,0,0)}const n=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,c=1+(o.translate_z!==void 0?o.translate_z:((g=o.transform)==null?void 0:g.translate_z)??0)/1e3,d=(o.flip_x===!0?-1:1)*Math.cos(a*Math.PI/180)*c,u=(o.flip_y===!0?-1:1)*Math.cos(n*Math.PI/180)*c,p=(o.scale_x??1)*d,l=(o.scale_y??1)*u;t.scale(p,l)}applyInnerGlowOverlay(t,s,o,e,i,n,a){var y,m;const r=a||s.style||{},c=r==null?void 0:r.effect,u=((r==null?void 0:r.effects)||(c?[c]:[])).find(S=>S.isEnabled!==!1&&S.type==="Glow"&&(S.mode==="inner"||S.mode==="Inner Glow"));if(!u)return;t.save(),t.beginPath(),this.applyPath(t,o,e,i,n),t.clip();const p=u.blur||10,l=1e4,h=t.getTransform();let f=u.color||"white";(m=(y=this.artboard)==null?void 0:y.tokens)!=null&&m.colors&&this.artboard.tokens.colors[f]&&(f=this.artboard.tokens.colors[f]),t.shadowColor=f,t.shadowBlur=p,t.shadowOffsetX=l*h.a,t.shadowOffsetY=l*h.b,t.translate(-l,0),t.lineWidth=p+5,t.strokeStyle=f;const g=Math.min(u.intensity||1,5);for(let S=0;S<g;S++)t.beginPath(),this.applyPath(t,o,e,i,n),t.stroke();t.restore()}applyArtEffectOverlay(t,s,o,e,i,n){var l,h,f,g,y;const a=this.objectStates.get(s.id),r=((l=a==null?void 0:a.style)==null?void 0:l.artEffect)||s.artEffect||((h=s.style)==null?void 0:h.artEffect);if(!r||!r.enabled)return;const c=r.type,d=r.intensity??.5,u=r.speed??1,p=r.scale??10;if(c==="acid_gradient"||c==="acid_rave"||c==="shimmer"||c==="glint_overlay"||c==="halftone"||c==="noise"||c==="scanlines"||c==="chromatic_aberration"||c==="pixelate"||c==="glitch"||c==="fold_overlay"||c==="crumple_overlay"){if(t.save(),this.applyPath(t,o,e,i,n),t.clip(),c==="shimmer"){const S=this.currentTime*u%2/2,v=t.createLinearGradient(-e,-i,e,i);v.addColorStop(Math.max(0,S-.2),"rgba(255,255,255,0)"),v.addColorStop(S,`rgba(255,255,255,${d*.8})`),v.addColorStop(Math.min(1,S+.2),"rgba(255,255,255,0)"),t.fillStyle=v,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i),t.globalCompositeOperation="source-over"}else if(c==="glint_overlay"){let v=((this._lastPointerPos||{x:0}).x-(((f=s.transform)==null?void 0:f.x)??0)+300)/600;v=Math.max(-.2,Math.min(1.2,v));const C=t.createLinearGradient(-e,-i,e,i);C.addColorStop(Math.max(0,v-.15),"rgba(255,255,255,0)"),C.addColorStop(Math.max(0,Math.min(1,v)),`rgba(255,255,255,${d})`),C.addColorStop(Math.min(1,v+.15),"rgba(255,255,255,0)"),t.fillStyle=C,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i),t.globalCompositeOperation="source-over"}else if(c==="fold_overlay"){const m=this._lastPointerPos||{x:0,y:0},S=m.x-(((g=s.transform)==null?void 0:g.x)??0),v=m.y-(((y=s.transform)==null?void 0:y.y)??0),C=t.createLinearGradient(S>0?-e/2:e/2,v>0?-i/2:i/2,S>0?e/2:-e/2,v>0?i/2:-i/2);C.addColorStop(0,`rgba(0,0,0,${d*.6})`),C.addColorStop(.4,"rgba(0,0,0,0)"),C.addColorStop(.5,`rgba(255,255,255,${d*.4})`),C.addColorStop(1,`rgba(0,0,0,${d*.2})`),t.fillStyle=C,t.globalCompositeOperation="overlay",t.fillRect(-e/2,-i/2,e,i),t.globalCompositeOperation="source-over",t.beginPath(),S>0&&v>0?(t.moveTo(e/2-40,i/2),t.lineTo(e/2,i/2-40),t.lineTo(e/2-40,i/2-40)):S<0&&v>0?(t.moveTo(-e/2+40,i/2),t.lineTo(-e/2,i/2-40),t.lineTo(-e/2+40,i/2-40)):S>0&&v<0?(t.moveTo(e/2-40,-i/2),t.lineTo(e/2,-i/2+40),t.lineTo(e/2-40,-i/2+40)):(t.moveTo(-e/2+40,-i/2),t.lineTo(-e/2,-i/2+40),t.lineTo(-e/2+40,-i/2+40)),t.closePath(),t.fillStyle="#ffffff",t.shadowColor="rgba(0,0,0,0.5)",t.shadowBlur=10,t.shadowOffsetX=S>0?-2:2,t.shadowOffsetY=v>0?-2:2,t.fill()}else if(c==="crumple_overlay"){const m=Math.floor(e/p),S=document.createElement("canvas");S.width=m,S.height=Math.floor(i/p);const v=S.getContext("2d"),C=v.createImageData(S.width,S.height);for(let w=0;w<C.data.length;w+=4){const M=Math.random()>.95?150:255;C.data[w]=M,C.data[w+1]=M,C.data[w+2]=M,C.data[w+3]=255*d}v.putImageData(C,0,0),t.globalCompositeOperation="multiply",t.imageSmoothingEnabled=!1,t.drawImage(S,-e/2,-i/2,e,i)}else if(c==="acid_gradient"||c==="acid_rave"){const m=this.currentTime*u,S=r.color1,v=r.color2,C=t.createLinearGradient(-e/2,-i/2,e/2,i/2);if(S&&v){const w=m*60%360;C.addColorStop(0,this._shiftHue(S,w,d*.7)),C.addColorStop(1,this._shiftHue(v,(w+180)%360,d*.7))}else{const w=m*100%360,M=(w+180)%360;C.addColorStop(0,`hsla(${w}, 80%, 50%, ${d*.5})`),C.addColorStop(1,`hsla(${M}, 80%, 50%, ${d*.5})`)}t.fillStyle=C,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i)}else if(c==="halftone"){const m=Math.max(2,p*(1-d*.8)),S=document.createElement("canvas");S.width=m,S.height=m;const v=S.getContext("2d");if(v){v.fillStyle="black",v.beginPath(),v.arc(m/2,m/2,m/2*d,0,Math.PI*2),v.fill();const C=t.createPattern(S,"repeat");C&&(t.globalAlpha=.3*d,t.fillStyle=C,t.fillRect(-e/2,-i/2,e,i))}}else if(c==="noise"){const m=Math.floor(e*i*d*.02);t.globalAlpha=.4*d;for(let S=0;S<m;S++){const v=Math.random()>.5?255:0;t.fillStyle=`rgba(${v}, ${v}, ${v}, ${.5+Math.random()*.5})`,t.fillRect(-e/2+Math.random()*e,-i/2+Math.random()*i,2,2)}}else if(c==="scanlines"){t.globalAlpha=.2*d,t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1;for(let m=-i/2;m<i/2;m+=4)t.beginPath(),t.moveTo(-e/2,m),t.lineTo(e/2,m),t.stroke()}else if(c==="chromatic_aberration"){const m=5*d;t.globalCompositeOperation="screen",t.globalAlpha=.5,t.fillStyle="cyan",t.fillRect(-e/2-m,-i/2,e,i),t.fillStyle="magenta",t.fillRect(-e/2+m,-i/2,e,i)}else if(c==="pixelate"){const m=Math.max(2,Math.round(p*(1-d*.5))),S=document.createElement("canvas"),v=Math.max(1,Math.ceil(e/m)),C=Math.max(1,Math.ceil(i/m));S.width=v,S.height=C;const w=S.getContext("2d");if(w){w.imageSmoothingEnabled=!1;const M=t.getTransform(),I=M.e-e/2,T=M.f-i/2;w.drawImage(t.canvas,I,T,e,i,0,0,v,C),t.imageSmoothingEnabled=!1,t.drawImage(S,0,0,v,C,-e/2,-i/2,e,i),t.imageSmoothingEnabled=!0}}else if(c==="glitch"){const m=this.currentTime*u,S=r.chaosAmount??.2,v=Math.max(3,Math.floor(8*d)),C=d*e*.15;t.globalCompositeOperation="screen",t.globalAlpha=d*.4;const w=C*.3;t.fillStyle="rgba(255, 0, 0, 0.4)",t.fillRect(-e/2+w,-i/2,e,i),t.fillStyle="rgba(0, 255, 255, 0.4)",t.fillRect(-e/2-w,-i/2,e,i),t.globalCompositeOperation="source-over",t.globalAlpha=1;const M=i/v;for(let I=0;I<v;I++){const T=Math.sin(I*127.1+m*311.7*u)*43758.5,k=T-Math.floor(T);if(k>1-S){const E=(k-(1-S))/S*C*(Math.random()>.5?1:-1),P=-i/2+I*M,_=t.getTransform(),L=_.e-e/2+E,A=_.f+P;t.save(),t.beginPath(),t.rect(-e/2,P,e,M),t.clip(),t.globalAlpha=.8,t.drawImage(t.canvas,L,A,e,M,-e/2+E,P,e,M),t.restore()}}}t.restore()}}_shiftHue(t,s,o){let e=0,i=0,n=0;if(t.startsWith("#")){const l=t.replace("#","");e=parseInt(l.substring(0,2),16)/255,i=parseInt(l.substring(2,4),16)/255,n=parseInt(l.substring(4,6),16)/255}const a=Math.max(e,i,n),r=Math.min(e,i,n);let c=0,d=0,u=(a+r)/2;if(a!==r){const l=a-r;switch(d=u>.5?l/(2-a-r):l/(a+r),a){case e:c=((i-n)/l+(i<n?6:0))/6;break;case i:c=((n-e)/l+2)/6;break;case n:c=((e-i)/l+4)/6;break}}return`hsla(${(((c*360+s)%360+360)%360).toFixed(0)}, ${(d*100).toFixed(0)}%, ${(u*100).toFixed(0)}%, ${o})`}applyBackgroundBlurGlass(t,s,o,e,i,n,a){const r=n.radius??10,c=n.opacity!==void 0?this.normalizeOpacity(n.opacity):.5,d=n.noise??0,u=n.color??"rgba(255,255,255,0.2)";t.save(),this.applyPath(t,s,o,e,i),t.clip();const p=t.getTransform(),l=t.canvas;try{const g=document.createElement("canvas");g.width=Math.max(1,Math.ceil(o)),g.height=Math.max(1,Math.ceil(e));const y=g.getContext("2d");if(y){y.save(),y.translate(o/2,e/2);const m=n.magnification||1;if(m!==1&&y.scale(m,m),typeof p.inverse=="function"){const C=p.inverse();y.transform(C.a,C.b,C.c,C.d,C.e,C.f)}else{const C=p.a*p.d-p.b*p.c;C!==0&&y.transform(p.d/C,-p.b/C,-p.c/C,p.a/C,(p.c*p.f-p.d*p.e)/C,(p.b*p.e-p.a*p.f)/C)}y.drawImage(l,0,0),y.restore();const S=document.createElement("canvas");S.width=g.width,S.height=g.height;const v=S.getContext("2d");v.filter=`blur(${r}px)`,v.drawImage(g,0,0),t.globalCompositeOperation="destination-out",t.fillRect(-o/2,-e/2,o,e),t.globalCompositeOperation="source-over",t.globalAlpha=1,t.drawImage(S,-o/2,-e/2,o,e)}}catch(g){console.error("Background blur failed:",g)}t.globalCompositeOperation="source-over",t.globalAlpha=c,t.fillStyle=u,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 y=document.createElement("canvas");y.width=64,y.height=64;const m=y.getContext("2d"),S=m.createImageData(64,64),v=S.data;for(let C=0;C<v.length;C+=4){const w=Math.floor(Math.random()*255);v[C]=w,v[C+1]=w,v[C+2]=w,v[C+3]=18}m.putImageData(S,0,0),this._noiseTileCanvas=y}const g=t.createPattern(this._noiseTileCanvas,"repeat");g&&(t.fillStyle=g,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,i),this.applyStrokeAlignment(t,a,s,o,e,i)):(t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1.5,this.applyPath(t,s,o,e,i),t.stroke()),t.restore()}applyPath(t,s,o,e,i){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,i)}_tracePath(t,s,o,e,i){if(s){if(this.ensurePathPoints(s),(s==null?void 0:s.type)==="Rectangle"||s.type==="Image"){const n=i!==void 0?i:s.corner_radius??0;this.drawRoundRect(t,-o/2,-e/2,o,e,n)}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:n=0,sweepAngle:a=360,ratio:r=0}=s,c=o/2,d=e/2,u=n*Math.PI/180,p=a*Math.PI/180,l=u+p;a>=360&&r<=0?t.ellipse(0,0,c,d,0,0,Math.PI*2):(t.ellipse(0,0,c,d,0,u,l,!1),r>0?t.ellipse(0,0,c*r,d*r,0,l,u,!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 n=s.sides||3,a=s.radius||Math.min(o,e)/2;for(let r=0;r<n;r++){const c=r*2*Math.PI/n-Math.PI/2,d=a*Math.cos(c),u=a*Math.sin(c);r===0?t.moveTo(d,u):t.lineTo(d,u)}t.closePath()}else if(s.type==="Star"){const n=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 c=0;c<n*2;c++){const d=c*Math.PI/n-Math.PI/2,u=c%2===0?a:r,p=u*Math.cos(d),l=u*Math.sin(d);c===0?t.moveTo(p,l):t.lineTo(p,l)}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 n=1/0,a=-1/0,r=1/0,c=-1/0;if(s.points.forEach(p=>{typeof p.x=="number"&&typeof p.y=="number"&&(n=Math.min(n,p.x),a=Math.max(a,p.x),r=Math.min(r,p.y),c=Math.max(c,p.y),p.out_x!==void 0&&(n=Math.min(n,p.out_x),a=Math.max(a,p.out_x)),p.out_y!==void 0&&(r=Math.min(r,p.out_y),c=Math.max(c,p.out_y)),p.in_x!==void 0&&(n=Math.min(n,p.in_x),a=Math.max(a,p.in_x)),p.in_y!==void 0&&(r=Math.min(r,p.in_y),c=Math.max(c,p.in_y)))}),n===1/0)return;let d=(n+a)/2,u=(r+c)/2;if(isNaN(d)||isNaN(u)){this.warn("[Engine] Invalid path center:",d,u);return}s.points.forEach((p,l)=>{if(l===0||p.moveTo)t.moveTo(p.x-d,p.y-u);else{const h=s.points[l-1];if(!h)return;const f=(h.out_x??h.x)-d,g=(h.out_y??h.y)-u,y=(p.in_x??p.x)-d,m=(p.in_y??p.y)-u;isNaN(f)||isNaN(y)||isNaN(p.x)?t.lineTo(p.x-d,p.y-u):t.bezierCurveTo(f,g,y,m,p.x-d,p.y-u)}if(p.closePath||l===s.points.length-1&&(s.is_closed||s.isClosed)){const h=[...s.points.slice(0,l+1)].reverse().find(f=>f.moveTo)||s.points[0];h&&(p.out_x!==void 0||h.in_x!==void 0)&&t.bezierCurveTo((p.out_x??p.x)-d,(p.out_y??p.y)-u,(h.in_x??h.x)-d,(h.in_y??h.y)-u,h.x-d,h.y-u),t.closePath()}})}else if(s.points&&Array.isArray(s.points)){let n=1/0,a=-1/0,r=1/0,c=-1/0;s.points.forEach(p=>{n=Math.min(n,p.x),a=Math.max(a,p.x),r=Math.min(r,p.y),c=Math.max(c,p.y)});const d=(n+a)/2,u=(r+c)/2;s.points.forEach((p,l)=>{if(l===0)t.moveTo(p.x-d,p.y-u);else{const h=s.points[l-1];h.out_x!==void 0||p.in_x!==void 0?t.bezierCurveTo((h.out_x??h.x)-d,(h.out_y??h.y)-u,(p.in_x??p.x)-d,(p.in_y??p.y)-u,p.x-d,p.y-u):t.lineTo(p.x-d,p.y-u)}(p.closePath||l===s.points.length-1&&(s.is_closed||s.isClosed))&&t.closePath()})}}}renderInputBox(t,s){var ct,dt;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((ct=s.geometry)==null?void 0:ct.width)||250,n=((dt=s.geometry)==null?void 0:dt.height)||45,a=this.focusedId===s.id,r=this.lastHoveredObjectId===s.id,c=e.previewState||"default",d=c!=="default"?c:a?"focused":r?"hovered":"default",u=e.label||{visible:!0,text:"Label"},p=e.helperText||{visible:!1,text:"Helper text"},l=e.leftIcon||{visible:!1},h=e.rightIcon||{visible:!1},f=e.multiline===!0,g=e.corner_radius??8,y=e.corners||{tl:g,tr:g,bl:g,br:g},m=[y.tl,y.tr,y.br,y.bl];let S=e.backgroundColor||"rgba(31, 41, 55, 1)",v=e.borderColor||"rgba(55, 65, 81, 1)",C=e.borderWidth??1.5,w=e.color||"#ffffff",M=e.placeholderColor||"rgba(156, 163, 175, 1)",I=e.fontSize||14;const T=`${d}Style`,k=e[T];k?(k.backgroundColor!==void 0&&(S=k.backgroundColor),k.borderColor!==void 0&&(v=k.borderColor),k.borderWidth!==void 0&&(C=k.borderWidth),k.color!==void 0&&(w=k.color),k.placeholderColor!==void 0&&(M=k.placeholderColor),k.fontSize!==void 0&&(I=k.fontSize)):d==="focused"?(v=e.focusBorderColor||"rgba(59, 130, 246, 1)",C=Math.max(C,2)):d==="hovered"||d==="hover"?(v=e.hoverBorderColor||v,S=e.hoverBackgroundColor||S):d==="disabled"?(S=e.disabledBackgroundColor||"rgba(31, 41, 55, 0.6)",v=e.disabledBorderColor||"rgba(55, 65, 81, 0.4)"):d==="error"&&(v="rgba(239, 68, 68, 1)",C=Math.max(C,2)),t.beginPath(),this.drawRoundRect(t,-i/2,-n/2,i,n,m);const E=this.createCanvasFill(t,S,i,n);if(E&&(t.fillStyle=E,t.fill()),C>0){const $=this.createCanvasFill(t,v,i,n);if($&&(t.strokeStyle=$,t.lineWidth=C,t.stroke()),d==="focused"||d==="focus"){t.save(),t.beginPath();const X=m.map(N=>N+2);this.drawRoundRect(t,-i/2-2,-n/2-2,i+4,n+4,X),t.strokeStyle="rgba(59, 130, 246, 0.3)",t.lineWidth=2,t.stroke(),t.restore()}}const P=($,X)=>{if(!$.visible||!$.svgPath)return;const N=$.size||14,ot=$.offset??16,bt=$.color||"#ffffff",St=X?-(i/2)+ot:i/2-ot,Mt=$.svgPath;if(t.save(),t.translate(St,0),!Mt.startsWith("<svg")){const pt=new Path2D(Mt),wt=N/24;t.scale(wt,wt),t.translate(-12,-12),t.fillStyle=bt,t.fill(pt)}t.restore()};P(l,!0),P(h,!1);const _=e.text||"",L=e.placeholder||"Enter text...",A=!_,W=_||L,B=A?M:w,R=I,Y=e.fontFamily||"Inter",G=e.fontWeight||400;t.font=`${G} ${R}px "${Y}", sans-serif`,t.fillStyle=B,t.textAlign="left",t.textBaseline=f?"top":"middle";const z=e.inputPadding??16,O=l.visible?(l.offset??16)+(l.size||14)/2+8:z,F=h.visible?(h.offset??16)+(h.size||14)/2+8:z,Z=-(i/2)+O,st=i-O-F,at=e.inputType==="password"?"•".repeat(W.length):W;if(t.save(),t.beginPath(),t.rect(Z-2,-n/2+4,st+4,n-8),t.clip(),f){const $=at.split(`
|
|
19
|
-
`);let X=-n/2+z;const N=R*1.2;let ot=0;$.forEach((bt,St)=>{const Mt=bt.split(" ");let pt="";for(let wt=0;wt<Mt.length;wt++){const yt=pt+Mt[wt]+" ";t.measureText(yt).width>st&&wt>0?(t.fillText(pt,Z,X),pt=Mt[wt]+" ",X+=N):pt=yt}t.fillText(pt,Z,X),ot=t.measureText(pt).width,St<$.length-1&&(X+=N,ot=0)}),a&&!A&&Math.floor(performance.now()/500)%2===0&&t.fillRect(Z+ot,X,1.5,R)}else{const X=t.measureText(at).width;let N=0;if(X>st&&(N=X-st),t.fillText(at,Z-N,0),a&&!A&&Math.floor(performance.now()/500)%2===0){const bt=Z+X-N;t.fillRect(bt,-(R/2),1.5,R)}}if(t.restore(),u.visible!==!1){const $=u.text||"Label",X=u.fontSize||12,N=u.color||"rgba(156, 163, 175, 1)",ot=u.offset??8;t.font=`600 ${X}px "${Y}", sans-serif`,t.fillStyle=N,t.textAlign="left",t.textBaseline="bottom";const bt=-(i/2),St=-(n/2)-ot;t.fillText($,bt,St)}if(p.visible===!0){const $=p.text||"Helper text",X=p.fontSize||11,N=d==="error"?"rgba(239, 68, 68, 1)":p.color||"rgba(156, 163, 175, 1)",ot=p.offset??6;t.font=`400 ${X}px "${Y}", sans-serif`,t.fillStyle=N,t.textAlign="left",t.textBaseline="top";const bt=-(i/2),St=n/2+ot;t.fillText($,bt,St)}}renderSlider(t,s){const o=this.objectStates.get(s.id),e=(o==null?void 0:o.geometry)||s.geometry,i=(o==null?void 0:o.options)||s.options||{},n=e.width||200,a=i.value??50,r=i.min??0,d=(i.max??100)-r,u=d===0?0:(a-r)/d,p=i.trackHeight||4,l=i.trackRoundedness??2,h=i.trackShape??"Rectangle",f=i.trackPath||"",g=i.accentColor||"#3b82f6",y=i.inactiveColor||"#374151",m=i.thumbShape||"Ellipse",S=i.thumbWidth??16,v=i.thumbHeight??16,C=i.thumbRoundedness??0,w=i.thumbColor||"#ffffff",M=i.thumbPath||"",I=i.thumbIcon||"",T=i.showValueTooltip??!1,k=i.tooltipBgColor||"#333333",E=i.tooltipColor||"#ffffff",P=i.tooltipOffsetX??0,_=i.tooltipOffsetY??-25,L=(st,at,ct,dt,$,X,N)=>{if((st==="Custom"||st==="Icon")&&N)try{const ot=new Path2D(N);if(t.save(),t.translate(at,ct),st==="Icon"){const bt=Math.min(dt,$)/24;t.scale(bt,bt),t.translate(-12,-12)}t.fill(ot),t.restore();return}catch(ot){console.error("Error drawing slider shape in engine:",ot)}if(t.beginPath(),st==="Ellipse")t.ellipse(at,ct,dt/2,$/2,0,0,Math.PI*2);else if(st==="Rectangle")this.drawRoundRect(t,at-dt/2,ct-$/2,dt,$,X);else if(st==="Triangle")t.moveTo(at,ct-$/2),t.lineTo(at+dt/2,ct+$/2),t.lineTo(at-dt/2,ct+$/2),t.closePath();else if(st==="Diamond")t.moveTo(at,ct-$/2),t.lineTo(at+dt/2,ct),t.lineTo(at,ct+$/2),t.lineTo(at-dt/2,ct),t.closePath();else if(st==="Polygon"){const ot=s.geometry.sides||3,bt=s.geometry.radius||Math.min(dt,$)/2;for(let St=0;St<ot;St++){const Mt=St*2*Math.PI/ot-Math.PI/2,pt=at+bt*Math.cos(Mt),wt=ct+bt*Math.sin(Mt);St===0?t.moveTo(pt,wt):t.lineTo(pt,wt)}t.closePath()}else if(st==="Star"){const bt=Math.min(dt,$)/2,St=bt/2;for(let Mt=0;Mt<10;Mt++){const pt=Mt%2===0?bt:St,wt=Mt*Math.PI/5-Math.PI/2;t.lineTo(at+pt*Math.cos(wt),ct+pt*Math.sin(wt))}t.closePath()}else st==="Line"&&(t.moveTo(at-dt/2,ct),t.lineTo(at+dt/2,ct));t.fill()},A=this.createCanvasFill(t,y,n,p);A&&(t.fillStyle=A,t.strokeStyle=A),h==="Line"?(t.lineWidth=p,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(n/2,0),t.stroke()):L(h,0,0,n,p,l,f);const W=n-S,B=-n/2+S/2+u*W,R=B- -n/2;if(R>0){const st=this.createCanvasFill(t,g,n,p);st&&(t.fillStyle=st,t.strokeStyle=st),h==="Line"?(t.lineWidth=p,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(B,0),t.stroke()):h==="Rectangle"&&(t.beginPath(),this.drawRoundRect(t,-n/2,-p/2,R,p,l),t.fill())}t.save(),t.translate(B,0);const Y=t.getTransform(),G=Math.sqrt(Y.a*Y.a+Y.b*Y.b)||1;t.shadowColor="rgba(0,0,0,0.2)",t.shadowBlur=4*G,t.shadowOffsetY=1*G;const z=this.createCanvasFill(t,w,S,v);if(z&&(t.fillStyle=z),L(m,0,0,S,v,C,m==="Icon"?I:M),t.restore(),T){t.save(),t.translate(B+P,_);const st=Math.round(a).toString();t.font="10px Inter, sans-serif";const at=t.measureText(st),ct=6,dt=4,$=at.width+ct*2,X=14+dt;t.beginPath(),this.drawRoundRect(t,-$/2,-X/2,$,X,4),t.fillStyle=k,t.fill(),t.fillStyle=E,t.textAlign="center",t.textBaseline="middle",t.fillText(st,0,0),t.restore()}const O=i.label||{},F=i.helperText||{},Z=i.fontFamily||"Inter";if(O.visible!==!1){const st=O.text||"Label",at=O.fontSize||12,ct=O.color||"rgba(156, 163, 175, 1)",dt=O.offset??8;t.font=`600 ${at}px "${Z}", sans-serif`,t.fillStyle=ct,t.textAlign="left",t.textBaseline="bottom";const $=-(n/2),X=-(p/2)-dt;t.fillText(st,$,X)}if(F.visible===!0){const st=F.text||"Helper text",at=F.fontSize||11,ct=F.color||"rgba(156, 163, 175, 1)",dt=F.offset??6;t.font=`400 ${at}px "${Z}", sans-serif`,t.fillStyle=ct,t.textAlign="left",t.textBaseline="top";const $=-(n/2),X=p/2+dt;t.fillText(st,$,X)}}renderDropdown(t,s){var _;const o=this.objectStates.get(s.id);if(!o)return;const e=o.options||s.options||{},i=s.geometry.width||160,n=s.geometry.height||40,a=-i/2,r=-n/2,c=e.corner_radius??6,d=e.disabled||e.previewState==="disabled",u=this.lastHoveredObjectId===s.id||e.previewState==="hover",p=(e.isOpen||e.previewState==="active")&&!d;let l=e.backgroundColor,h=e.borderColor,f=e.color||"#333333";d?(l=e.disabledBackgroundColor||"#f3f4f6",h=e.disabledBorderColor||"#e5e7eb",f=e.disabledColor||"#9ca3af"):p?(l=e.activeBackgroundColor||l,h=e.activeBorderColor||h,f=e.activeColor||f):u&&(l=e.hoverBackgroundColor||l,h=e.hoverBorderColor||h,f=e.hoverColor||f),l||(l="#ffffff"),h||(h="#e5e7eb");const g=t.globalAlpha;t.globalAlpha=g*(e.opacity??1),this.drawRoundRect(t,a,r,i,n,c),t.fillStyle=this.createCanvasFill(t,typeof l=="string"?{type:"Solid",color:l}:l,i,n)||"#ffffff",t.fill();const y=e.borderWidth??1;y>0&&(t.strokeStyle=this.createCanvasFill(t,typeof h=="string"?{type:"Solid",color:h}:h,i,n)||"#e5e7eb",t.lineWidth=y,t.stroke());const m=12,S=e.chevronType||"chevron",v=e.chevronSize||16,C=(p?e.openIconColor:e.closedIconColor)||e.chevronColor||"#6b7280";if(S!=="none"){const L=a+i-m-v/2;t.save(),t.translate(L,0);const A=p?e.openIconAngle??180:e.closedIconAngle??0;if(t.rotate(A*Math.PI/180),t.strokeStyle=C,t.fillStyle=C,t.lineWidth=1.5,t.lineCap="round",t.lineJoin="round",S==="chevron")t.beginPath(),t.moveTo(-v/2,-v*.2),t.lineTo(0,v*.2),t.lineTo(v/2,-v*.2),t.stroke();else if(S==="custom"||S==="path"){const W=p&&e.openIconPath||e.closedIconPath;if(W){const B=new Path2D(W);t.save();const R=v/24;t.scale(R,R),t.translate(-12,-12),t.fill(B),t.restore()}}t.restore()}const w=e.selectedOption||e.placeholder||"Select...",M=e.fontSize||14,I=e.fontWeight||400,T=e.fontFamily||"Inter, sans-serif";t.font=`${I} ${M}px ${T}`;const k=d?e.disabledColor||"#9ca3af":!e.selectedOption&&e.placeholder?"#9ca3af":f;t.fillStyle=this.createCanvasFill(t,typeof k=="string"?{type:"Solid",color:k}:k,i,n)||"#333333",t.textAlign="left",t.textBaseline="middle";const E=S==="none"?0:v+8,P=i-m*2-E;if(t.save(),t.beginPath(),t.rect(a+m,r,P,n),t.clip(),t.fillText(w,a+m,0),t.restore(),p&&!d){const L=r+n+4,A=e.optionsList||[],W=e.itemHeight||32,B=e.listPadding??4,R=A.length*W+B*2,Y=e.listCornerRadius??c;t.save();const G=e.listShadow||{},z=t.getTransform(),O=Math.sqrt(z.a*z.a+z.b*z.b)||1;t.shadowColor=typeof G.color=="string"?G.color:((_=G.color)==null?void 0:_.color)||"rgba(0,0,0,0.15)",t.shadowBlur=(G.blur??12)*O,t.shadowOffsetY=(G.offsetY??6)*O,t.shadowOffsetX=(G.offsetX??0)*O,t.beginPath(),this.drawRoundRect(t,a,L,i,R,Y),t.fillStyle=this.createCanvasFill(t,typeof e.listBackgroundColor=="string"?{type:"Solid",color:e.listBackgroundColor}:e.listBackgroundColor||{type:"Solid",color:"#ffffff"},i,R)||"#ffffff",t.fill();const F=e.listBorderWidth??1;F>0&&(t.shadowColor="transparent",t.strokeStyle=this.createCanvasFill(t,typeof e.listBorderColor=="string"?{type:"Solid",color:e.listBorderColor}:e.listBorderColor||{type:"Solid",color:h},i,R)||"#e5e7eb",t.lineWidth=F,t.stroke()),t.restore();const Z=e.itemFontSize||M,st=e.itemFontFamily||T;t.font=`${I} ${Z}px ${st}`,A.forEach((at,ct)=>{const dt=L+B+ct*W;if(at===e.selectedOption)t.fillStyle=this.createCanvasFill(t,typeof e.itemSelectedBackgroundColor=="string"?{type:"Solid",color:e.itemSelectedBackgroundColor}:e.itemSelectedBackgroundColor||{type:"Solid",color:"#f3f4f6"},i,W)||"#f3f4f6",t.fillRect(a+F,dt,i-F*2,W),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-(L+B),N=Math.floor(X/W);ct===N&&(t.fillStyle=this.createCanvasFill(t,typeof e.itemHoverBackgroundColor=="string"?{type:"Solid",color:e.itemHoverBackgroundColor}:e.itemHoverBackgroundColor||{type:"Solid",color:"#f9fafb"},i,W)||"#f9fafb",t.fillRect(a+F,dt,i-F*2,W),t.fillStyle=e.itemHoverColor||f)}t.fillText(at,a+m,dt+W/2)})}t.globalAlpha=g}renderButton(t,s){if(s.children&&s.children.length>0)return;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=s.geometry||{},n=i.width||120,a=i.height||40,r=this.lastHoveredObjectId===s.id,c=this.activeObjectId===s.id,d=e.label||{},u=e.hoverStyle||{},p=e.activeStyle||{},l=e.icon||{enabled:!1};let h=e.backgroundColor||"#3b82f6",f=d.color||"#ffffff",g=d.text||"Button",y=i.cornerRadius??8,m=e.borderColor||"transparent",S=e.borderWidth||0,v=1;c&&p?(h=p.backgroundColor||h,f=p.color||f,g=p.text||g,v=p.scale??.95,y=p.cornerRadius??y):r&&u&&(h=u.backgroundColor||h,f=u.color||f,g=u.text||g,v=u.scale??1,y=u.cornerRadius??y,m=u.borderColor||m);const C=-n/2,w=-a/2;t.save(),t.scale(v,v),t.beginPath(),this.drawRoundRect(t,C,w,n,a,y);const M=this.createCanvasFill(t,h,n,a);M&&(t.fillStyle=M,t.fill()),(S>0||r&&u.borderColor)&&(t.strokeStyle=m,t.lineWidth=S||(r?1:0),t.stroke());const I=d.fontSize||14,T=d.fontFamily||"Inter",k=d.fontWeight||600;t.font=`${k} ${I}px "${T}", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle=f,t.textAlign="center",t.textBaseline="middle";let E=0;if(l.enabled&&l.svgPath){const P=I*1.1,_=l.gap||8,L=t.measureText(g),W=-(L.width+P+_)/2,B=l.position==="left"?W+P/2:W+L.width+_+P/2;E=l.position==="left"?W+P+_+L.width/2:W+L.width/2,t.save(),t.translate(B,0);const R=new Path2D(l.svgPath),Y=P/24;t.scale(Y,Y),t.translate(-12,-12),t.fillStyle=f,t.fill(R),t.restore()}t.fillText(g,E,0),t.restore()}renderToggleButton(t,s){var g,y;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=e.checked??!1,n=((g=s.geometry)==null?void 0:g.width)||120,a=((y=s.geometry)==null?void 0:y.height)||40,r=-n/2,c=-a/2,d=e.corner_radius??8,u=e.label||{},p=i?e.accentColor||"#3b82f6":e.inactiveColor||"#374151",l=i?e.activeTextColor||"#ffffff":e.inactiveTextColor||"#9ca3af";t.save(),t.beginPath(),this.drawRoundRect(t,r,c,n,a,d),t.fillStyle=p,t.fill();const h=u.fontSize||14,f=u.fontFamily||"Inter";t.font=`${u.fontWeight||600} ${h}px "${f}", sans-serif`,t.fillStyle=l,t.textAlign="center",t.textBaseline="middle",t.fillText(u.text||"Toggle",0,0),t.restore()}renderToggle(t,s){var Y,G,z,O,F,Z,st,at,ct,dt,$,X;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((Y=s.geometry)==null?void 0:Y.width)||52,n=((G=s.geometry)==null?void 0:G.height)||30,a=-i/2,r=-n/2,c=e.checked??!1,d=e.cornerRadius??e.corner_radius??n/2,u=e.toggleStyle||{},p=u.backgroundColor||e.activeColor||"#10b981",l=u.borderColor||e.borderColor||"transparent",h=u.borderWidth??e.borderWidth??0,f=u.knobColor||e.knobColor||"#ffffff",g=c?p:e.inactiveColor||"#374151",y=c?l:e.borderColor||"transparent",m=c?h:e.borderWidth??0,S=c?f:e.knobColor||"#ffffff";e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,i,n,d);const v=this.createCanvasFill(t,g,i,n);if(v&&(t.fillStyle=v,t.fill()),m>0){t.lineWidth=m;const N=this.createCanvasFill(t,y,i,n);N&&(t.strokeStyle=N,t.stroke())}const C=2,w=n-C*2,M=w/2,I=a+C,T=a+i-C-w,k=c?T:I,E=r+C;t.beginPath(),t.arc(k+M,E+M,M,0,Math.PI*2);const P=this.createCanvasFill(t,S,w,w);P&&(t.fillStyle=P,t.fill()),e.disabled&&(t.globalAlpha*=2);let _=!1,L=!1;const A=(c?(z=u.leftLabel)==null?void 0:z.text:null)||((O=e.leftLabel)==null?void 0:O.text)||"",W=(c?(F=u.leftLabel)==null?void 0:F.color:null)||((Z=e.leftLabel)==null?void 0:Z.color)||"#f3f4f6";if((st=e.leftLabel)!=null&&st.enabled&&A){const N=e.leftLabel;t.font=`${N.fontWeight||400} ${N.fontSize||12}px "${N.fontFamily||"Inter"}", sans-serif`,t.fillStyle=W,t.textBaseline="middle",t.textAlign="right",t.fillText(A,a-(N.gap||8),0),_=!0}const B=(c?(at=u.rightLabel)==null?void 0:at.text:null)||((ct=e.rightLabel)==null?void 0:ct.text)||"",R=(c?(dt=u.rightLabel)==null?void 0:dt.color:null)||(($=e.rightLabel)==null?void 0:$.color)||"#f3f4f6";if((X=e.rightLabel)!=null&&X.enabled&&B){const N=e.rightLabel;t.font=`${N.fontWeight||400} ${N.fontSize||12}px "${N.fontFamily||"Inter"}", sans-serif`,t.fillStyle=R,t.textBaseline="middle",t.textAlign="left",t.fillText(B,a+i+(N.gap||8),0),L=!0}if(!_&&!L&&e.label&&e.label.text){const N=e.label,ot=N.fontSize||14,bt=N.fontWeight||400,St=N.fontFamily||"Inter";t.font=`${bt} ${ot}px "${St}", sans-serif`,t.fillStyle=N.color||"#f3f4f6",t.textBaseline="middle";const Mt=N.gap||10;let pt=0,wt=0;N.position==="left"?(t.textAlign="right",pt=a-Mt,wt=0):N.position==="right"?(t.textAlign="left",pt=a+i+Mt,wt=0):N.position==="top"?(t.textAlign="center",pt=0,wt=r-Mt,t.textBaseline="bottom"):N.position==="bottom"?(t.textAlign="center",pt=0,wt=r+n+Mt,t.textBaseline="top"):(t.textAlign="left",pt=a+i+Mt,wt=0),t.fillText(N.text,pt,wt)}}renderCheckbox(t,s){var v,C;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((v=s.geometry)==null?void 0:v.width)||20,n=((C=s.geometry)==null?void 0:C.height)||20,a=-i/2,r=-n/2,c=e.cornerRadius??4,d=e.checked??!1,u=e.activeColor||"#3b82f6",p=e.inactiveColor||"transparent",l=e.checkColor||"#ffffff",h=e.borderColor||"#4b5563",f=e.borderWidth??2,g=d?u:p,y=d?"transparent":h,m=d?0:f;e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,i,n,c);const S=this.createCanvasFill(t,g,i,n);if(S&&(t.fillStyle=S,t.fill()),m>0){t.lineWidth=m;const w=this.createCanvasFill(t,y,i,n);w&&(t.strokeStyle=w,t.stroke())}else if(d){t.lineWidth=1;const w=this.createCanvasFill(t,u,i,n);w&&(t.strokeStyle=w,t.stroke())}if(d){t.save(),t.beginPath();const w=this.createCanvasFill(t,l,i,n);t.strokeStyle=w||l,t.lineWidth=Math.max(2,i*.12),t.lineCap="round",t.lineJoin="round";const M=a+i*.25,I=r+n*.5,T=a+i*.45,k=r+n*.7,E=a+i*.75,P=r+n*.25;t.moveTo(M,I),t.lineTo(T,k),t.lineTo(E,P),t.stroke(),t.restore()}if(e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const w=e.label;t.save(),t.font=`${w.fontWeight||400} ${w.fontSize||14}px "${w.fontFamily||"Inter"}", sans-serif`,t.fillStyle=w.color||"#f3f4f6",t.textBaseline="middle";const M=w.gap||8;let I=0,T=0;w.position==="left"?(t.textAlign="right",I=a-M,T=0):w.position==="right"?(t.textAlign="left",I=a+i+M,T=0):w.position==="top"?(t.textAlign="center",I=0,T=r-M,t.textBaseline="bottom"):w.position==="bottom"&&(t.textAlign="center",I=0,T=r+n+M,t.textBaseline="top"),t.fillText(w.text,I,T),t.restore()}}renderRadioGroup(t,s){var C,w;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((C=s.geometry)==null?void 0:C.width)||180,n=((w=s.geometry)==null?void 0:w.height)||100,a=-i/2,r=-n/2,c=e.selectedValue,d=e.optionsList||["Option 1","Option 2","Option 3"],u=e.orientation||"vertical",p=e.itemGap!==void 0?e.itemGap:16,l=e.activeColor||"#3b82f6",h=e.inactiveColor||"#4b5563",f=e.textColor||"#ffffff",g=e.fontSize||14,y=e.fontFamily||"Inter",m=e.fontWeight||400;e.disabled&&(t.globalAlpha*=.5);const S=8,v=S*2;if(t.save(),t.font=`${m} ${g}px "${y}", sans-serif`,t.textBaseline="middle",t.textAlign="left",u==="vertical"){const M=Math.max(v,g)+p;d.forEach((I,T)=>{const k=r+T*M+S;t.beginPath(),t.arc(a+S,k,S,0,Math.PI*2);const E=c===I,P=this.createCanvasFill(t,l,v,v),_=this.createCanvasFill(t,h,v,v);E?(t.strokeStyle=P||l,t.lineWidth=2,t.stroke(),t.beginPath(),t.arc(a+S,k,S/2,0,Math.PI*2),t.fillStyle=P||l,t.fill()):(t.strokeStyle=_||h,t.lineWidth=1.5,t.stroke()),t.fillStyle=f,t.fillText(I,a+v+8,k)})}else{let M=a;d.forEach(I=>{const T=c===I,k=t.measureText(I).width;t.beginPath(),t.arc(M+S,0,S,0,Math.PI*2);const E=this.createCanvasFill(t,l,v,v),P=this.createCanvasFill(t,h,v,v);T?(t.strokeStyle=E||l,t.lineWidth=2,t.stroke(),t.beginPath(),t.arc(M+S,0,S/2,0,Math.PI*2),t.fillStyle=E||l,t.fill()):(t.strokeStyle=P||h,t.lineWidth=1.5,t.stroke()),t.fillStyle=f,t.fillText(I,M+v+6,0),M+=v+6+k+p})}if(t.restore(),e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const M=e.label;t.save(),t.font=`${M.fontWeight||400} ${M.fontSize||14}px "${M.fontFamily||"Inter"}", sans-serif`,t.fillStyle=M.color||"#9ca3af",t.textBaseline="middle";const I=M.gap||8;let T=0,k=0;M.position==="left"?(t.textAlign="right",T=a-I,k=0):M.position==="right"?(t.textAlign="left",T=a+i+I,k=0):M.position==="top"?(t.textAlign="center",T=0,k=r-I,t.textBaseline="bottom"):M.position==="bottom"&&(t.textAlign="center",T=0,k=r+n+I,t.textBaseline="top"),t.fillText(M.text,T,k),t.restore()}}renderBarChart(t,s){var k,E;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i={width:((k=s.geometry)==null?void 0:k.width)||300,height:((E=s.geometry)==null?void 0:E.height)||180,chartType:e.chartType||"grouped",stylePreset:e.stylePreset||"default",datasets:e.datasets||[{id:"ds-1",label:"Revenue",data:[42,67,31,55,78,48],color:"#6366f1"}],categories:e.categories||["Jan","Feb","Mar","Apr","May","Jun"],orientation:e.orientation||"vertical",barWidth:e.barWidth!==void 0?e.barWidth:14,barGap:e.barGap!==void 0?e.barGap:4,barCornerRadius:e.barCornerRadius!==void 0?e.barCornerRadius:5,showXAxis:!!e.showXAxis,showYAxis:!!e.showYAxis,xAxisColor:e.xAxisColor||"rgba(255,255,255,0.12)",yAxisColor:e.yAxisColor||"rgba(255,255,255,0.12)",showXLabels:e.showXLabels!==void 0?!!e.showXLabels:!0,showYLabels:!!e.showYLabels,axisLabelColor:e.axisLabelColor||"rgba(255,255,255,0.5)",axisLabelFontSize:e.axisLabelFontSize||9,showLegend:e.showLegend!==void 0?!!e.showLegend:!0,legendColor:e.legendColor||"rgba(255,255,255,0.7)",legendFontSize:e.legendFontSize||9,showGridLines:e.showGridLines!==void 0?!!e.showGridLines:!0,gridColor:e.gridColor||"rgba(255,255,255,0.06)",cardBackground:e.cardBackground||"rgba(255,255,255,0.04)",cardBorderColor:e.cardBorderColor||"rgba(255,255,255,0.08)",barGradient:e.barGradient!==void 0?!!e.barGradient:!0,showValueOnTop:!!e.showValueOnTop,chartBackground:e.chartBackground||"transparent",barStyle:e.barStyle||"solid",barBorderWidth:e.barBorderWidth!==void 0?e.barBorderWidth:1,barBorderColor:e.barBorderColor||"auto",enableShadows:!!e.enableShadows,shadowColor:e.shadowColor||"rgba(0,0,0,0.5)",shadowBlur:e.shadowBlur!==void 0?e.shadowBlur:4,shadowOffsetY:e.shadowOffsetY!==void 0?e.shadowOffsetY:2,valueFontSize:e.valueFontSize||10,valueColor:e.valueColor||"auto",valueFontWeight:e.valueFontWeight||"bold",xAxisLineWidth:e.xAxisLineWidth!==void 0?e.xAxisLineWidth:1,yAxisLineWidth:e.yAxisLineWidth!==void 0?e.yAxisLineWidth:1,gridLineWidth:e.gridLineWidth!==void 0?e.gridLineWidth:1,gridLineDash:e.gridLineDash||[3,4],_getPreset:function(){return us[this.stylePreset]||us.default},_resolveColor:function(P,_){const L=this._getPreset();return["#6366f1","#f59e0b","#10b981","#3b82f6","#a855f7"].includes(P)?L.colors[_%L.colors.length]:typeof P=="string"?P:L.colors[_%L.colors.length]},_makeGradient:function(P,_,L,A,W,B){if(!this._getPreset().barGradient&&!this.barGradient)return _;const Y=P.createLinearGradient(L,A,W,B);return Y.addColorStop(0,_),Y.addColorStop(1,_+"44"),Y},_drawRoundedBar:function(P,_,L,A,W,B,R){if(B=Math.min(B,Math.min(Math.abs(A),Math.abs(W))/2),B<=0||A===0||W===0){P.rect(_,L,A,W);return}P.beginPath(),R?(P.moveTo(_,L+W),P.lineTo(_,L+B),P.quadraticCurveTo(_,L,_+B,L),P.lineTo(_+A-B,L),P.quadraticCurveTo(_+A,L,_+A,L+B),P.lineTo(_+A,L+W),P.lineTo(_,L+W)):(P.moveTo(_,L),P.lineTo(_+A-B,L),P.quadraticCurveTo(_+A,L,_+A,L+B),P.lineTo(_+A,L+W-B),P.quadraticCurveTo(_+A,L+W,_+A-B,L+W),P.lineTo(_,L+W),P.lineTo(_,L)),P.closePath()}},n=i.width,a=i.height,r=-n/2,c=-a/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}const d=i._getPreset();let u=-1/0,p=1/0;const l=i.categories.length,h=i.datasets.length;if(i.chartType==="stacked")for(let P=0;P<l;P++){let _=0,L=0;i.datasets.forEach(A=>{const W=A.data[P]??0;W>=0?_+=W:L+=W}),_>u&&(u=_),L<p&&(p=L)}else i.datasets.forEach(P=>{P.data&&P.data.forEach(_=>{_>u&&(u=_),_<p&&(p=_)})});isFinite(u)||(u=10),isFinite(p)||(p=0),u=Math.max(u,0),p=Math.min(p,0);const f=u-p||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 g=i.showYLabels?t.measureText(u.toFixed(0)).width+14:10,y=i.showXLabels?i.axisLabelFontSize+12:8,S=(i.showLegend&&h>0?i.legendFontSize+10:0)+8,v=10,C=r+g,w=c+S,M=n-g-v,I=a-S-y;if(i.enableShadows&&(t.shadowColor="transparent"),t.beginPath(),t.roundRect(r,c,n,a,10),t.fillStyle=d.cardBackground,t.fill(),t.strokeStyle=d.cardBorderColor,t.lineWidth=1,t.stroke(),i.chartBackground&&i.chartBackground!=="transparent"&&(t.beginPath(),t.rect(C,w,M,I),t.fillStyle=i.chartBackground,t.fill()),i.showLegend&&h>0){t.font=i.legendFontSize+"px Inter, sans-serif",t.textBaseline="middle";const P=c+12;let _=C;i.datasets.forEach((L,A)=>{const W=i._resolveColor(L.color,A),B=L.label||"Series "+(A+1),R=7;t.beginPath(),t.roundRect(_,P-R/2,R,R,2),t.fillStyle=W,t.fill(),t.fillStyle=d.legendColor,t.textAlign="left",t.fillText(B,_+R+4,P),_+=t.measureText(B).width+R+16})}const T=4;if(i.showGridLines){t.setLineDash(i.gridLineDash||[]),t.lineWidth=i.gridLineWidth||1,t.strokeStyle=d.gridColor;for(let P=0;P<=T;P++)if(i.orientation==="horizontal"){const _=C+P/T*M;t.beginPath(),t.moveTo(_,w),t.lineTo(_,w+I),t.stroke()}else{const _=w+P/T*I;t.beginPath(),t.moveTo(C,_),t.lineTo(C+M,_),t.stroke()}t.setLineDash([])}if(i.showYLabels){t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=d.axisLabelColor;for(let P=0;P<=T;P++)if(i.orientation==="horizontal"){const _=p+P/T*f,L=C+P/T*M;t.textAlign="center",t.fillText(_.toFixed(0),L,w+I+i.axisLabelFontSize)}else{const _=u-P/T*f,L=w+P/T*I;t.textAlign="right",t.fillText(_.toFixed(0),C-6,L)}}if(t.setLineDash([]),i.showXAxis&&(t.lineWidth=i.xAxisLineWidth||1,t.strokeStyle=i.xAxisColor,t.beginPath(),t.moveTo(C,w+I),t.lineTo(C+M,w+I),t.stroke()),i.showYAxis&&(t.lineWidth=i.yAxisLineWidth||1,t.strokeStyle=i.yAxisColor,t.beginPath(),t.moveTo(C,w),t.lineTo(C,w+I),t.stroke()),i.enableShadows&&(t.shadowColor=i.shadowColor),i.chartType==="stacked")if(i.orientation==="horizontal"){const P=I/l;for(let _=0;_<l;_++){const L=w+_*P+P/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=d.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[_]||"",C-5,L),i.enableShadows&&(t.shadowColor=i.shadowColor));let A=C;i.datasets.forEach((W,B)=>{const R=W.data[_]??0;if(R===0)return;const Y=R/f*M,G=Math.min(i.barWidth*h+i.barGap,P-8),z=L-G/2,O=A;A+=Y;const F=i._resolveColor(W.color,B);t.beginPath(),t.fillStyle=i._makeGradient(t,F,O,z,O+Y,z),i._drawRoundedBar(t,O,z,Y,G,B===h-1?i.barCornerRadius:0,!1),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?F:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill()})}}else{const P=M/l;for(let _=0;_<l;_++){const L=C+_*P+P/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillStyle=d.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[_]||"",L,w+I+5),i.enableShadows&&(t.shadowColor=i.shadowColor));let A=w+I;i.datasets.forEach((W,B)=>{const R=W.data[_]??0;if(R===0)return;const Y=R/f*I,G=Math.min(i.barWidth*h+i.barGap,P-8),z=L-G/2,O=A-Y;A-=Y;const F=i._resolveColor(W.color,B);t.beginPath(),t.fillStyle=i._makeGradient(t,F,z,O,z,O+Y),i._drawRoundedBar(t,z,O,G,Y,B===h-1?i.barCornerRadius:0,!0),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?F: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 P=I/l,_=h*i.barWidth+Math.max(0,(h-1)*i.barGap),L=C+(0-p)/f*M;for(let A=0;A<l;A++){const W=w+A*P+P/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="right",t.textBaseline="middle",t.fillStyle=d.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[A]||"",C-5,W),i.enableShadows&&(t.shadowColor=i.shadowColor));const B=W-_/2;i.datasets.forEach((R,Y)=>{const G=R.data[A]??0,z=Math.abs(G/f*M);if(z<1)return;const O=B+Y*(i.barWidth+i.barGap),F=G>=0?L:L-z,Z=i._resolveColor(R.color,Y);t.beginPath(),t.fillStyle=i._makeGradient(t,Z,F,O,F+z,O),i._drawRoundedBar(t,F,O,z,i.barWidth,i.barCornerRadius,!1),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?Z:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),i.showValueOnTop&&G!==0&&(t.font=(i.valueFontWeight||"bold")+" "+(i.valueFontSize||10)+"px Inter, sans-serif",t.textAlign=G>=0?"left":"right",t.textBaseline="middle",t.fillStyle=i.valueColor==="auto"?Z:i.valueColor||"#fff",t.shadowColor="transparent",t.fillText(G.toString(),G>=0?F+z+4:F-4,O+i.barWidth/2),i.enableShadows&&(t.shadowColor=i.shadowColor))})}}else{const P=M/l,_=h*i.barWidth+Math.max(0,(h-1)*i.barGap),L=w+I-(0-p)/f*I;for(let A=0;A<l;A++){const W=C+A*P+P/2;i.showXLabels&&(t.font=i.axisLabelFontSize+"px Inter, sans-serif",t.textAlign="center",t.textBaseline="top",t.fillStyle=d.axisLabelColor,t.shadowColor="transparent",t.fillText(i.categories[A]||"",W,w+I+5),i.enableShadows&&(t.shadowColor=i.shadowColor));const B=W-_/2;i.datasets.forEach((R,Y)=>{const G=R.data[A]??0,z=Math.abs(G/f*I);if(z<1)return;const O=B+Y*(i.barWidth+i.barGap),F=G>=0?L-z:L,Z=i._resolveColor(R.color,Y);t.beginPath(),t.fillStyle=i._makeGradient(t,Z,O,F,O,F+z),i._drawRoundedBar(t,O,F,i.barWidth,z,i.barCornerRadius,!0),i.barStyle==="outline"||i.barStyle==="dashed"?(t.fillStyle="transparent",t.strokeStyle=i.barBorderColor==="auto"?Z:i.barBorderColor,t.lineWidth=i.barBorderWidth,i.barStyle==="dashed"&&t.setLineDash([4,4]),t.stroke(),t.setLineDash([])):t.fill(),i.showValueOnTop&&G!==0&&(t.font=(i.valueFontWeight||"bold")+" "+(i.valueFontSize||10)+"px Inter, sans-serif",t.textAlign="center",t.textBaseline=G>=0?"bottom":"top",t.fillStyle=i.valueColor==="auto"?Z:i.valueColor||"#fff",t.shadowColor="transparent",t.fillText(G.toString(),O+i.barWidth/2,G>=0?F-4:F+z+4),i.enableShadows&&(t.shadowColor=i.shadowColor))})}}t.restore()}renderPieChart(t,s){var g,y;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i={width:((g=s.geometry)==null?void 0:g.width)||180,height:((y=s.geometry)==null?void 0:y.height)||180,chartType:e.chartType||"donut",stylePreset:e.stylePreset||"default",slices:e.slices||[{id:"slice-1",label:"Item 1",value:45,color:"#6366f1"}],innerRadius:e.innerRadius!==void 0?e.innerRadius:.55,sliceGap:e.sliceGap!==void 0?e.sliceGap:3,showLabels:!!e.showLabels,labelColor:e.labelColor||"#ffffff",labelFontSize:e.labelFontSize||10,showLegend:e.showLegend!==void 0?!!e.showLegend:!0,legendColor:e.legendColor||"rgba(255,255,255,0.65)",legendFontSize:e.legendFontSize||9,showCenterText:e.showCenterText!==void 0?!!e.showCenterText:!0,centerLabel:e.centerLabel||"Total",centerTextColor:e.centerTextColor||"#ffffff",centerLabelColor:e.centerLabelColor||"rgba(255,255,255,0.4)",_getPreset:function(){return gs[this.stylePreset]||gs.default},_resolveSliceColor:function(m,S){const v=m.color,C=S,w=this._getPreset();return["#6366f1","#22d3ee","#f59e0b","#ec4899","#34d399","#a855f7","#f87171"].includes(v)?w.colors[C%w.colors.length]:typeof v=="string"?v:w.colors[C%w.colors.length]}},n=i.width,a=i.height;if(!i.slices||i.slices.length===0){t.save(),t.fillStyle="rgba(99,102,241,0.8)",t.font="bold 11px Inter, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("NO PIE DATA",0,0),t.restore();return}const r=i.slices.reduce((m,S)=>m+(S.value||0),0);if(r<=0){t.save(),t.fillStyle="rgba(99,102,241,0.8)",t.font="bold 11px Inter, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("EMPTY DATA",0,0),t.restore();return}const c=i._getPreset();t.save(),t.beginPath(),t.roundRect(-n/2,-a/2,n,a,10),t.fillStyle=c.cardBackground,t.fill(),t.strokeStyle=c.cardBorderColor,t.lineWidth=1,t.stroke();const d=i.showLegend?Math.ceil(i.slices.length/2):0,u=d>0?d*(i.legendFontSize+8)+10:0,p=a-u-16,l=Math.min(n-24,p)/2,h=0,f=-u/2;if(i.chartType==="rose"){const m=Math.max(...i.slices.map(C=>C.value||0)),S=Math.PI*2/i.slices.length,v=l>0?i.sliceGap/l:0;i.slices.forEach((C,w)=>{const M=C.value||0;if(M===0)return;const I=M/m*l,T=-Math.PI/2+w*S+v/2,k=T+S-v,E=i._resolveSliceColor(C,w);if(t.beginPath(),t.moveTo(h,f),t.arc(h,f,I,T,k),t.closePath(),t.fillStyle=E+"cc",t.fill(),t.strokeStyle=E,t.lineWidth=1.5,t.stroke(),i.showLabels){const P=T+(k-T)/2,_=h+I*.65*Math.cos(P),L=f+I*.65*Math.sin(P),A=Math.round(M/r*100);t.save(),t.font=`bold ${i.labelFontSize}px Inter, sans-serif`,t.fillStyle=c.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${A}%`,_,L),t.restore()}})}else{const m=i.chartType==="pie"?0:i.innerRadius,S=l*Math.max(0,m),v=l>0?i.sliceGap/l:0;let C=-Math.PI/2;if(i.slices.forEach((w,M)=>{const I=w.value||0;if(I===0){C+=I/r*Math.PI*2;return}const T=I/r*Math.PI*2,k=C+v/2,E=C+T-v/2;if(E<=k){C+=T;return}const P=i._resolveSliceColor(w,M);if(t.beginPath(),t.fillStyle=P,S<=0?(t.moveTo(h,f),t.arc(h,f,l,k,E),t.lineTo(h,f)):(t.moveTo(h+l*Math.cos(k),f+l*Math.sin(k)),t.arc(h,f,l,k,E),t.arc(h,f,S,E,k,!0),t.closePath()),t.fill(),i.showLabels){const _=k+(E-k)/2,L=S+(l-S)/2,A=h+L*Math.cos(_),W=f+L*Math.sin(_),B=Math.round(I/r*100);t.save(),t.font=`bold ${i.labelFontSize}px Inter, sans-serif`,t.fillStyle=c.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${B}%`,A,W),t.restore()}C+=T}),i.chartType==="donut"&&i.showCenterText&&S>14){const w=Math.round(r),M=Math.min(Math.floor(S*.52),20),I=Math.min(Math.floor(S*.26),10);t.textAlign="center",t.textBaseline="middle",t.font=`bold ${M}px Inter, sans-serif`,t.fillStyle=c.centerTextColor,t.fillText(w.toString(),h,f-I*.5),i.centerLabel&&(t.font=`${I}px Inter, sans-serif`,t.fillStyle=c.centerLabelColor,t.fillText(i.centerLabel,h,f+M*.6))}}if(i.showLegend&&i.slices.length>0){t.font=`${i.legendFontSize}px Inter, sans-serif`;const m=2,S=n/m,v=i.legendFontSize+8,C=a/2-u+10,w=-n/2+10;i.slices.forEach((M,I)=>{const T=I%m,k=Math.floor(I/m),E=w+T*S,P=C+k*v,_=i._resolveSliceColor(M,I),L=7;t.beginPath(),t.roundRect(E,P-L/2,L,L,2),t.fillStyle=_,t.fill(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=c.legendColor;const A=Math.round((M.value||0)/r*100),W=`${M.label||"Item"} ${A}%`,B=S-L-20;let R=W;for(;t.measureText(R).width>B&&R.length>4;)R=R.slice(0,-4)+"…";t.fillText(R,E+L+4,P)})}t.restore()}renderJoystick(t,s){var g,y,m,S,v,C,w,M,I,T,k,E;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.width)!==void 0?o.width:((g=s.geometry)==null?void 0:g.width)??s.width??100,i=(o==null?void 0:o.height)!==void 0?o.height:((y=s.geometry)==null?void 0:y.height)??s.height??100,n=Math.min(e,i)*(((m=s.style)==null?void 0:m.baseSize)??.45),a=Math.min(e,i)*(((S=s.style)==null?void 0:S.handleSize)??.14);let r=s.handleX||0,c=s.handleY||0;o&&o.handleX!==void 0&&(r=o.handleX),o&&o.handleY!==void 0&&(c=o.handleY),t.save();let d=0,u=0;s.handleOrigin==="top-left"?(d=e/2,u=i/2):s.handleOrigin==="bottom-right"&&(d=-e/2,u=-i/2),t.translate(d,u);const p=t.globalAlpha;if(t.globalAlpha=p*(((v=s.style)==null?void 0:v.baseOpacity)??1),t.beginPath(),s.boundsShape==="square"){const P=s.joystickType==="2D"?12:18;t.roundRect(-n,-n,n*2,n*2,P)}else t.arc(0,0,n,0,Math.PI*2);t.fillStyle=((C=s.style)==null?void 0:C.baseColor)||"rgba(0,0,0,0.04)",t.fill(),(w=s.style)!=null&&w.baseBorderWidth?(t.lineWidth=s.style.baseBorderWidth,t.strokeStyle=s.style.baseBorderColor||"rgba(0,0,0,0.1)",t.stroke()):(t.lineWidth=1,t.strokeStyle=((M=s.style)==null?void 0:M.baseBorderColor)||"rgba(0,0,0,0.08)",t.stroke());const l=s.overflowHandle?n:Math.max(.1,n-a);let h=0,f=0;s.joystickType==="2D"?(h=r*l,f=c*l):s.joystickType==="1D_X"?(h=r*l,f=0):s.joystickType==="1D_Y"&&(h=0,f=c*l),t.globalAlpha=p*(((I=s.style)==null?void 0:I.handleOpacity)??1),t.beginPath(),t.arc(h,f,a,0,Math.PI*2),t.fillStyle=((T=s.style)==null?void 0:T.handleColor)||"#3b82f6",t.fill(),(k=s.style)!=null&&k.handleBorderWidth?(t.lineWidth=s.style.handleBorderWidth,t.strokeStyle=s.style.handleBorderColor||"rgba(255,255,255,0.5)",t.stroke()):(t.lineWidth=1,t.strokeStyle=((E=s.style)==null?void 0:E.handleBorderColor)||"rgba(255,255,255,0.5)",t.stroke()),t.globalAlpha=p,t.restore()}getRadioGroupItemIndexAtPointer(t,s,o){var I,T;const e=t.options||{},i=this.objectStates.get(t.id)||{},n=e.optionsList||[];if(n.length===0)return null;const a=i.width!==void 0?i.width:((I=t.geometry)==null?void 0:I.width)||180,r=i.height!==void 0?i.height:((T=t.geometry)==null?void 0:T.height)||100,c=e.orientation||"vertical",d=e.itemGap!==void 0?e.itemGap:16,u=e.fontSize||14,p=this.getWorldTransform(t.id),l=s-p.x,h=o-p.y,f=-p.rotation*(Math.PI/180),g=Math.cos(f),y=Math.sin(f),m=l*g-h*y,S=l*y+h*g,C=8*2,w=-a/2,M=-r/2;if(c==="vertical"){const k=Math.max(C,u)+d;for(let E=0;E<n.length;E++){const P=M+E*k;if(m>=w&&m<=w+a&&S>=P&&S<=P+k)return E}}else{let k=w;for(let E=0;E<n.length;E++){const _=n[E].length*8,L=C+6+_+d;if(m>=k&&m<=k+L&&S>=M&&S<=M+r)return E;k+=L}}return null}renderLineGraph(t,s,o,e){let i=s.datasets||[];if((!i||i.length===0)&&(s.data||s.graphData)&&(i=[{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}]),!i||i.length===0||!i.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 n=1/0,a=-1/0,r=0;if(i.forEach(f=>{let g=f.data;if(f.isVarEnabled&&f.inputId){let y=this.inputs.get(f.inputId);if(y===void 0){const m=this.inputNameMap.get(f.inputId);m&&m.length>0&&(y=this.inputs.get(m[0]))}y&&Array.isArray(y)&&(g=y)}if(g&&g.length>0){const y=g.filter(m=>typeof m=="number"&&!isNaN(m));y.length>0&&(n=Math.min(n,...y),a=Math.max(a,...y),r=Math.max(r,g.length))}f._resolvedData=g}),r<2)return;const c=a-n,d=o/(r-1),u=f=>{const g=c===0?.5:(f-n)/c;return e/2-g*e},p=f=>f*d-o/2,l=s.axisColor||"#333333";if(s.showXAxis&&(t.beginPath(),t.strokeStyle=s.xAxisColor||l,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||l,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 g=p(f);t.fillText(`${f+1}`,g,e/2+5)}}if(s.showYLabels){t.textAlign="right",t.textBaseline="middle";const f=-o/2-5,g=(a+n)/2;t.fillText(a.toFixed(1),f,u(a)),t.fillText(g.toFixed(1),f,u(g)),t.fillText(n.toFixed(1),f,u(n))}const h=10;if(i.forEach(f=>{const g=f._resolvedData;if(!(!g||g.length<2)){if(f.showArea){if(t.beginPath(),t.moveTo(p(0),e/2),t.lineTo(p(0),u(g[0])),f.smoothing&&g.length>2)for(let m=0;m<g.length-1;m++){const S=g[m===0?m:m-1],v=g[m],C=g[m+1],w=g[m+1===g.length-1?m+1:m+2];for(let M=1;M<=h;M++){const I=M/h,T=this._catmullRom(S,v,C,w,I);t.lineTo(p(m+I),u(T))}}else for(let m=1;m<g.length;m++)t.lineTo(p(m),u(g[m]));t.lineTo(p(g.length-1),e/2),t.closePath();const y=t.globalAlpha;t.globalAlpha=y*(s.areaOpacity??.3),t.fillStyle=f.areaColor||"rgba(139, 92, 246, 0.2)",t.fill(),t.globalAlpha=y}if(t.beginPath(),t.strokeStyle=f.lineColor||"#3b82f6",t.lineWidth=f.lineWidth||2,t.lineJoin="round",t.lineCap="round",t.moveTo(p(0),u(g[0])),f.smoothing&&g.length>2)for(let y=0;y<g.length-1;y++){const m=g[y===0?y:y-1],S=g[y],v=g[y+1],C=g[y+1===g.length-1?y+1:y+2];for(let w=1;w<=h;w++){const M=w/h,I=this._catmullRom(m,S,v,C,M);t.lineTo(p(y+M),u(I))}}else for(let y=1;y<g.length;y++)t.lineTo(p(y),u(g[y]));t.stroke(),f.showPoints&&g.forEach((y,m)=>{const S=p(m),v=u(y);t.beginPath(),t.arc(S,v,(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&&i.length>0){const f=o/2-10;let g=-e/2+15;const y=s.legendFontSize||10,m=y+5;t.font=`${y}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="alphabetic",i.forEach(S=>{const C=S.label||"Series",w=t.measureText(C).width;t.beginPath(),t.rect(f-w-8-5,g-(8/2+2),8,8),t.fillStyle=S.lineColor||"#3b82f6",t.fill(),t.fillStyle=s.legendColor||"#333333",t.fillText(C,f,g),g+=m})}}_catmullRom(t,s,o,e,i){const n=(o-t)*.5,a=(e-s)*.5,r=i*i,c=i*r;return(2*s-2*o+n+a)*c+(-3*s+3*o-2*n-a)*r+n*i+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 i,n,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=(((n=(i=this.artboard)==null?void 0:i.tokens)==null?void 0:n.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=(c,d=100)=>{var v,C;const p=(((C=(v=this.artboard)==null?void 0:v.tokens)==null?void 0:C.colors)||{})[c]||c,l=this.normalizeOpacity(s.opacity??100),f=this.normalizeOpacity(d)*l;if(f>=1&&p.startsWith("#"))return p;const g=p.startsWith("#")?p.replace("#",""):"ffffff",y=parseInt(g.substring(0,2),16),m=parseInt(g.substring(2,4),16),S=parseInt(g.substring(4,6),16);return`rgba(${y}, ${m}, ${S}, ${f})`};if(s.type==="LinearGradient"){const c=(f,g,y)=>Array.isArray(f)?f[g]??(g===0?0:1):f&&typeof f=="object"?f[y]??(g===0?0:1):g===0?0:1,d=c(s.start,0,"x")*o-o/2,u=c(s.start,1,"y")*e-e/2,p=c(s.end,0,"x")*o-o/2,l=c(s.end,1,"y")*e-e/2,h=t.createLinearGradient(d,u,p,l);if(s.stops.forEach(f=>{const g=f.offset!==void 0?f.offset:f.pos!==void 0?f.pos:f.position!==void 0?f.position:0,y=r(f.color||"#000000",f.opacity??100);h.addColorStop(Math.max(0,Math.min(1,g)),y)}),s.gradientTransform&&h.setTransform){const[f,g,y,m,S,v]=s.gradientTransform;h.setTransform({a:f,b:g,c:y,d:m,e:S,f:v})}return h}else if(s.type==="RadialGradient"){const c=(h,f,g)=>Array.isArray(h)?h[f]??.5:h&&typeof h=="object"?h[g]??.5:.5,d=c(s.center,0,"x")*o-o/2,u=c(s.center,1,"y")*e-e/2,p=(s.radius??.5)*Math.max(o,e),l=t.createRadialGradient(d,u,0,d,u,p);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,g=r(h.color||"#000000",h.opacity??100);l.addColorStop(Math.max(0,Math.min(1,f)),g)}),s.gradientTransform&&l.setTransform){const[h,f,g,y,m,S]=s.gradientTransform;l.setTransform({a:h,b:f,c:g,d:y,e:m,f:S})}return l}else if(s.type==="AngularGradient"){const c=(h,f,g)=>Array.isArray(h)?h[f]??.5:h&&typeof h=="object"?h[g]??.5:.5,d=c(s.center||[.5,.5],0,"x")*o-o/2,u=c(s.center||[.5,.5],1,"y")*e-e/2,p=(s.degree||s.angle||0)*(Math.PI/180),l=(a=t.createConicGradient)==null?void 0:a.call(t,p,d,u);if(l){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,g=r(h.color||"#000000",h.opacity??100);l.addColorStop(Math.max(0,Math.min(1,f)),g)}),s.gradientTransform&&l.setTransform){const[h,f,g,y,m,S]=s.gradientTransform;l.setTransform({a:h,b:f,c:g,d:y,e:m,f:S})}return l}}else if(s.type==="DiamondGradient"){const c=(h,f,g)=>Array.isArray(h)?h[f]??.5:h&&typeof h=="object"?h[g]??.5:.5,d=c(s.center||[.5,.5],0,"x")*o-o/2,u=c(s.center||[.5,.5],1,"y")*e-e/2,p=(s.radius??.5)*Math.max(o,e);t.save(),t.translate(d,u),t.rotate(Math.PI/4);const l=t.createRadialGradient(0,0,0,0,0,p);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,g=r(h.color||"#000000",h.opacity??100);l.addColorStop(Math.max(0,Math.min(1,f)),g)}),s.gradientTransform&&l.setTransform){const[h,f,g,y,m,S]=s.gradientTransform;l.setTransform({a:h,b:f,c:g,d:y,e:m,f:S})}return t.scale(1/Math.SQRT2,1/Math.SQRT2),t.fillStyle=l,t.restore(),l}}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 c=t.createPattern(r,"repeat");if(c&&(s.scaleX!==void 0||s.offsetX!==void 0)){const d=new DOMMatrix,u=s.scaleX??1,p=s.scaleY??1,l=s.offsetX??0,h=s.offsetY??0,f=s.rotation??0;d.translateSelf(l,h),d.rotateSelf(f),d.scaleSelf(u,p),c.setTransform(d)}return c}}return s.color||null}drawRoundRect(t,s,o,e,i,n){if(n===0||n===void 0||n===null){t.rect(s,o,e,i);return}let a=n;if(typeof a=="string")try{a=JSON.parse(a)}catch{a=parseFloat(a)||0}let r=0,c=0,d=0,u=0;typeof a=="number"?r=c=d=u=a:Array.isArray(a)?a.length===1?r=c=d=u=a[0]:a.length===2?(r=d=a[0],c=u=a[1]):a.length===3?(r=a[0],c=u=a[1],d=a[2]):a.length>=4&&(r=a[0],c=a[1],d=a[2],u=a[3]):a&&typeof a=="object"&&(r=a[0]??a.tl??a.corner_radius??a.cornerRadius??0,c=a[1]??a.tr??a.corner_radius??a.cornerRadius??0,d=a[2]??a.br??a.corner_radius??a.cornerRadius??0,u=a[3]??a.bl??a.corner_radius??a.cornerRadius??0);const p=Math.min(Math.abs(e)/2,Math.abs(i)/2);if(r=Math.min(Math.max(0,r),p),c=Math.min(Math.max(0,c),p),d=Math.min(Math.max(0,d),p),u=Math.min(Math.max(0,u),p),t.roundRect){t.roundRect(s,o,e,i,[r,c,d,u]);return}t.moveTo(s+r,o),t.lineTo(s+e-c,o),t.arcTo(s+e,o,s+e,o+c,c),t.lineTo(s+e,o+i-d),t.arcTo(s+e,o+i,s+e-d,o+i,d),t.lineTo(s+u,o+i),t.arcTo(s,o+i,s,o+i-u,u),t.lineTo(s,o+r),t.arcTo(s,o,s+r,o,r),t.closePath()}renderListView(t,s){var A,W,B,R;const o=this.objectStates.get(s.id)||{},e=o.options||s.options||{},i=o.width!==void 0?o.width:((A=s.geometry)==null?void 0:A.width)||200,n=o.height!==void 0?o.height:((W=s.geometry)==null?void 0:W.height)||300,a=-i/2,r=-n/2,c=o.corner_radius!==void 0?o.corner_radius:e.corner_radius??0,d=e.orientation||"vertical",u=e.items||[],p=e.itemGap??10,l=e.itemHeight??50,h=e.itemWidth??200,f=e.scrollOffset??0,g=e.padding??0,y=e.glassEffect!==!1,m=e.accentColor||"#3b82f6",S=e.itemTextColor||"#333333",v=e.itemBackgroundColor||"#ffffff",C=e.hoveredIndex??null,w=e.activeItemIndex??null,M=e.glowIntensity??0,I=e.glowColor||"#3b82f6",T=typeof I=="string"?I:I.color||((R=(B=I.stops)==null?void 0:B[0])==null?void 0:R.color)||"#3b82f6",k=e.opacity!==void 0?e.opacity:s.opacity!==void 0?s.opacity:1;if(t.save(),t.globalAlpha*=k,M>0){const Y=t.getTransform(),G=Math.sqrt(Y.a*Y.a+Y.b*Y.b)||1;t.shadowColor=T,t.shadowBlur=M*2*G,t.shadowOffsetX=0,t.shadowOffsetY=0}if(y){const Y=e.listBackgroundColor||"rgba(31, 41, 55, 0.4)",G=this.createCanvasFill(t,Y,i,n);t.fillStyle=G||"rgba(31, 41, 55, 0.4)",t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,i,n,c)||t.fill();const O=t.createLinearGradient(a,r,a+i,r+n);O.addColorStop(0,"rgba(255, 255, 255, 0.15)"),O.addColorStop(.5,"rgba(255, 255, 255, 0.08)"),O.addColorStop(1,"rgba(255, 255, 255, 0.03)"),t.fillStyle=O,t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,i,n,c)||t.fill(),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1,t.beginPath(),this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,i,n,c)||t.stroke()}else{const Y=e.backgroundColor||e.listBackgroundColor||"transparent",G=this.createCanvasFill(t,Y,i,n);if(G){t.fillStyle=G,t.beginPath();const O=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,i,n,c);t.fill()}const z=e.borderWidth??0;if(z>0){t.strokeStyle=e.borderColor||"#cccccc",t.lineWidth=z,t.beginPath();const O=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,i,n,c);t.stroke()}}t.shadowBlur=0,t.save(),t.beginPath();const E=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,i,n,c);if(e.listLayout!=="circular")if(E&&e.containerShape==="custom")try{const Y=new Path2D(e.containerPath);t.translate(a,r),t.scale(i/100,n/100),t.clip(Y),t.scale(100/i,100/n),t.translate(-a,-r)}catch{}else t.clip();const P=typeof g=="number"?g:d==="vertical"?g[0]:g[3];let _=(d==="vertical"?r:a)+f+P;if(t.textBaseline="middle",u.forEach((Y,G)=>{const z=e.listLayout||"linear",O=z==="circular"?h:d==="vertical"?i:h,F=z==="circular"||d==="vertical"?l:n;let Z=0,st=0,at=0;if(z==="circular"){const wt=u.length||1,yt=Math.PI*2/wt,qt=e.circularStartAngle||0,Kt=e.circularRadius||100,j=f*.01+qt*Math.PI/180,ft=G*yt+j,Rt=a+i/2,At=r+n/2;Z=Rt+Math.cos(ft)*Kt-O/2,st=At+Math.sin(ft)*Kt-F/2,at=ft+(e.itemRotation||0)*Math.PI/180}else Z=d==="vertical"?a:_,st=d==="vertical"?_:r,at=(e.itemRotation||0)*Math.PI/180;const ct=C===G,dt=w===G,$=dt&&e.activeItemShape?e.activeItemShape:e.itemShape||"rectangle",X=dt&&e.activeItemShape?e.activeItemPath:e.itemPath||"",N=e.itemCornerRadius||0;if(t.save(),at!==0&&(t.translate(Z+O/2,st+F/2),t.rotate(at),t.translate(-(Z+O/2),-(st+F/2))),dt){const wt=this.createCanvasFill(t,m,O,F);t.fillStyle=wt||m;const yt=t.globalAlpha;t.globalAlpha=yt*.8,t.beginPath(),this.drawCustomShape(t,$,X,Z,st,O,F,N)||(t.rect(Z,st,O,F),t.fill()),t.globalAlpha=yt}else if(ct)t.fillStyle=y?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",t.beginPath(),this.drawCustomShape(t,$,X,Z,st,O,F,N)||(t.rect(Z,st,O,F),t.fill());else if(v!=="transparent"){const wt=this.createCanvasFill(t,v,O,F);t.fillStyle=wt||v,t.beginPath(),this.drawCustomShape(t,$,X,Z,st,O,F,N)||(t.rect(Z,st,O,F),t.fill())}if(dt||ct){const wt=this.createCanvasFill(t,m,d==="vertical"?3:O,d==="vertical"?F:3);t.fillStyle=wt||m,d==="vertical"?t.fillRect(Z,st,3,F):t.fillRect(Z,st+F-3,O,3)}const ot=dt?"#ffffff":y?"rgba(255, 255, 255, 0.9)":S;t.fillStyle=ot,t.font=dt||ct?"600 14px Inter, sans-serif":"400 14px Inter, sans-serif";const bt=typeof Y=="string"?Y:(Y==null?void 0:Y.label)||`Item ${G+1}`,St=Z+(d==="vertical"?16:O/2),Mt=st+F/2;d==="horizontal"||z==="circular"?t.textAlign="center":t.textAlign="left";const pt=z==="circular"?Z+O/2:St;t.fillText(bt,pt,Mt),t.restore(),_+=(d==="vertical"?l:h)+p}),t.restore(),e.showScrollbar!==!1){const Y=(u.length||0)*(d==="vertical"?l:h)+((u.length||0)-1)*p,G=d==="vertical"?n:i,z=e.listLayout||"linear",O=e.containerShape==="circle"||z==="circular";if(Y>G||z==="circular"&&u.length>0){const F=e.scrollbarColor||"rgba(255,255,255,0.3)",Z=e.scrollbarWidth||4;if(O){const st=Math.min(i,n)/2-Z/2-2,at=a+i/2,ct=r+n/2;if(t.strokeStyle=F,t.lineWidth=Z,t.lineCap="round",t.beginPath(),z==="circular"){const dt=Math.PI/4,$=-(f*.01)-Math.PI/2;t.arc(at,ct,st,$,$+dt)}else{const dt=Math.PI/2,$=G/Y,X=dt*$,N=-f/Y*dt,bt=-Math.PI/4+N;t.arc(at,ct,st,bt,bt+X)}t.stroke()}else{const st=G/Y,at=G*st,ct=-f/Y*G;t.fillStyle=F,d==="vertical"?t.fillRect(a+i-Z-2,r+ct,Z,at):t.fillRect(a+ct,r+n-Z-2,at,Z)}}}t.restore()}drawCustomShape(t,s,o,e,i,n,a,r){if(s==="circle"){const c=Math.min(n,a)/2;return t.arc(e+n/2,i+a/2,c,0,Math.PI*2),!1}else if(s==="pill"){const c=Math.min(n,a)/2;return this.drawListViewRect(t,e,i,n,a,c),!1}else if(s==="custom"&&o)try{const c=new Path2D(o);return t.save(),t.translate(e,i),t.scale(n/100,a/100),t.fill(c),t.restore(),!0}catch{return this.drawListViewRect(t,e,i,n,a,r),!1}return this.drawListViewRect(t,e,i,n,a,r),!1}updateListViewScrollFromPointer(t){var y,m;if(!this._lastPointerPos||!this._prevPointerPos)return;const s=t.options||{},o=s.orientation||"vertical",e=this._lastPointerPos.x-this._prevPointerPos.x,i=this._lastPointerPos.y-this._prevPointerPos.y;o==="vertical"?s.scrollOffset=(s.scrollOffset||0)+i:s.scrollOffset=(s.scrollOffset||0)+e;const n=s.listLayout||"linear",a=this.objectStates.get(t.id)||{},r=s.items||[],c=s.itemGap??10,d=s.itemHeight??50,u=s.itemWidth??200,p=a.width!==void 0?a.width:((y=t.geometry)==null?void 0:y.width)||200,l=a.height!==void 0?a.height:((m=t.geometry)==null?void 0:m.height)||300;if(n==="circular")return;const h=(r.length||0)*(o==="vertical"?d:u)+((r.length||0)-1)*c,g=Math.max(0,h-(o==="vertical"?l:p)+(s.padding*2||0));s.scrollOffset>0&&(s.scrollOffset=0),s.scrollOffset<-g&&(s.scrollOffset=-g)}updateListViewHoverFromPointer(t,s,o){const e=this.getListViewItemIndexAtPointer(t,s,o),i=t.options||{};i.hoveredIndex!==e&&(i.hoveredIndex=e)}getListViewItemIndexAtPointer(t,s,o){var B,R;const e=t.options||{},i=this.objectStates.get(t.id)||{},n=e.items||[];if(n.length===0)return null;const a=i.width!==void 0?i.width:((B=t.geometry)==null?void 0:B.width)||200,r=i.height!==void 0?i.height:((R=t.geometry)==null?void 0:R.height)||300,c=e.orientation||"vertical",d=e.itemGap??10,u=e.itemHeight??50,p=e.itemWidth??200,l=e.scrollOffset??0,h=e.padding??0,f=this.getWorldTransform(t.id),g=s-f.x,y=o-f.y,m=-f.rotation*(Math.PI/180),S=Math.cos(m),v=Math.sin(m),C=g*S-y*v,w=g*v+y*S,M=-a/2,I=-r/2,T=typeof h=="number"?h:c==="vertical"?h[0]:h[3];let k=(c==="vertical"?I:M)+l+T;const E=e.listLayout||"linear",P=n.length||1,_=Math.PI*2/P,L=e.circularStartAngle||0,A=e.circularRadius||100,W=l*.01+L*Math.PI/180;for(let Y=0;Y<n.length;Y++){const G=E==="circular"?p:c==="vertical"?a:p,z=E==="circular"||c==="vertical"?u:r;let O=0,F=0,Z=0;if(E==="circular"){const st=Y*_+W,at=M+a/2,ct=I+r/2;O=at+Math.cos(st)*A-G/2,F=ct+Math.sin(st)*A-z/2,Z=st+(e.itemRotation||0)*Math.PI/180}else O=c==="vertical"?M:k,F=c==="vertical"?k:I,Z=(e.itemRotation||0)*Math.PI/180;if(Z!==0){const st=O+G/2,at=F+z/2,ct=C-st,dt=w-at,$=-Z,X=ct*Math.cos($)-dt*Math.sin($)+st,N=ct*Math.sin($)+dt*Math.cos($)+at;if(X>=O&&X<=O+G&&N>=F&&N<=F+z)return Y}else if(C>=O&&C<=O+G&&w>=F&&w<=F+z)return Y;k+=(c==="vertical"?u:p)+d}return null}drawListViewRect(t,s,o,e,i,n){t.beginPath(),this.drawRoundRect(t,s,o,e,i,n),t.fill()}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 i=this.objectStates.get(e.id);i&&e.behaviors.forEach(n=>{var p,l,h,f,g,y,m,S,v,C,w,M,I,T,k,E,P,_,L,A,W,B,R,Y,G,z,O,F,Z,st,at,ct,dt,$,X,N,ot,bt,St,Mt,pt,wt,yt,qt,Kt,j,ft,Rt,At,Pt,Ot,Gt,Ht,Nt,Bt,le,ae,ye,Pe,Le,me,xe,Zt,_e,Fe,Ee,pe,Ce,Re,he,de,Et,J,et,q,D,it,tt,ut,Wt,Dt,Qt,zt,Xt,x,rt,It,Ft,K,ht,gt,jt,mt,$t,vt,xt,kt,oe,re,ke,Jt,se,ee,Ae,$e,Be,We,Ye,Xe,Ve,te,fe,be,De,Ge,we,Se,ve;if(!n.enabled)return;const a=n.startTime||0,r=n.endTime||1/0;if(this.currentTime<a||this.currentTime>r)return;const c=i.x-s,d=i.y-o,u=Math.sqrt(c*c+d*d);if(this.frameCount%240===0&&Math.random()<.1&&this.log(`[ExodeUI] Executing ${n.type} on ${e.name}`),n.type===H.Proximity){const V=((p=n.settings)==null?void 0:p.radius)||300,Q=((l=n.settings)==null?void 0:l.falloff)||"smooth";let U=0;u<V&&(Q==="linear"?U=1-u/V:U=Math.pow(1-u/V,2)),n.sensors.forEach(lt=>{this.applyBehaviorSensor(i,lt,U,t,n.settings,e,c,d,u)})}else if(n.type===H.Magnetic){const V=((h=n.settings)==null?void 0:h.radius)||400,Q=((f=n.settings)==null?void 0:f.strength)||.5;if(u<V&&u>5){const U=1-u/V,lt=c*U*Q,Tt=d*U*Q;i.x-=lt*t*10,i.y-=Tt*t*10}}else if(n.type===H.Repel){const V=((g=n.settings)==null?void 0:g.radius)||300,Q=((y=n.settings)==null?void 0:y.strength)||1;if(u<V){const U=Math.pow(1-u/V,2);i.x+=c/(u||1)*U*60*Q*t*5,i.y+=d/(u||1)*U*60*Q*t*5}}else if(n.type===H.Orbit){const V=((m=n.settings)==null?void 0:m.speed)||1,Q=((S=n.settings)==null?void 0:S.radius)||30,U=this.currentTime*V*Math.PI*2;i.x+=Math.cos(U)*Q*t*5,i.y+=Math.sin(U)*Q*t*5,i.rotation+=2*t*5}else if(n.type===H.Vortex){const V=((v=n.settings)==null?void 0:v.radius)||400,Q=((C=n.settings)==null?void 0:C.speed)||2,U=((w=n.settings)==null?void 0:w.strength)||1;if(u<V){const lt=Math.pow(1-u/V,1.5),Tt=this.currentTime*Q*Math.PI*2,Lt=Math.cos(Tt)*30-c*.4,Yt=Math.sin(Tt)*30-d*.4;i.x+=Lt*lt*U*t*5,i.y+=Yt*lt*U*t*5,i.rotation+=5*lt*U*t*5,i.scale_x*=1-lt*.1*U*t,i.scale_y*=1-lt*.1*U*t}}else if(n.type===H.Fluid){const V=((M=n.settings)==null?void 0:M.radius)||300,Q=((I=n.settings)==null?void 0:I.strength)||1;if(u<V){const U=Math.pow(1-u/V,1.2),lt=c/(u||1)*U*1.2*Q,Tt=d/(u||1)*U*1.2*Q;i.x+=lt*10*t*5,i.y+=Tt*10*t*5,i.scale_x*=1+U*.3*Q*t,i.scale_y*=1+U*.3*Q*t}}else if(n.type===H.Elastic){const V=((T=n.settings)==null?void 0:T.radius)||300,Q=((k=n.settings)==null?void 0:k.strength)||1;if(u<V){const U=1-u/V;i.scale_x*=1+U*.4*Q*t,i.scale_y*=1+U*.4*Q*t}}else if(n.type===H.Holographic){const V=i.x-this.canvasWidth/2,Q=i.y-this.canvasHeight/2,U=((E=n.settings)==null?void 0:E.factor)||25;if(i.x-=V/1e3*U*t*5,i.y-=Q/1e3*U*t*5,i.style){const lt=1-Math.min(1,u/400);i.style.exposure=(i.style.exposure||1)+lt*.5*t}}else if(n.type===H.Sticky){const V=((P=n.settings)==null?void 0:P.radius)||80,Q=((_=n.settings)==null?void 0:_.strength)||1;if(u<V){const U=Math.pow(1-u/V,2);i.x-=c*U*Q*t*10,i.y-=d*U*Q*t*10,i.scale_x*=1-U*.1*Q*t,i.scale_y*=1-U*.1*Q*t}}else if(n.type===H.Dilation){const V=((L=n.settings)==null?void 0:L.size)||120,Q=((A=n.settings)==null?void 0:A.strength)||1;if(u<V){const U=1-u/V;i.scale_x*=1+U*.5*Q*t,i.scale_y*=1+U*.5*Q*t}}else if(n.type===H.Parallax){const V=((W=n.settings)==null?void 0:W.factor)||15,Q=((B=n.settings)==null?void 0:B.strength)||1,U=this.canvasWidth/2,lt=this.canvasHeight/2,Tt=this._lastPointerPos||{x:U,y:lt},Lt=(Tt.x-U)/U,Yt=(Tt.y-lt)/lt,ce=(((R=e.transform)==null?void 0:R.x)??0)+Lt*V*Q,Me=(((Y=e.transform)==null?void 0:Y.y)??0)+Yt*V*Q,Oe=(((G=e.transform)==null?void 0:G.rotate_x)??0)-Yt*V*1.5*Q,ue=(((z=e.transform)==null?void 0:z.rotate_y)??0)+Lt*V*1.5*Q,Te=Math.min(1,10*t);i.x=this.lerp(i.x??((O=e.transform)==null?void 0:O.x)??0,ce,Te),i.y=this.lerp(i.y??((F=e.transform)==null?void 0:F.y)??0,Me,Te),i.rotate_x=this.lerp(i.rotate_x??((Z=e.transform)==null?void 0:Z.rotate_x)??0,Oe,Te),i.rotate_y=this.lerp(i.rotate_y??((st=e.transform)==null?void 0:st.rotate_y)??0,ue,Te)}else if(n.type===H.Fold){if(u<300){const V=1-u/300,Q=(c>0?-1:1)*V*10,U=1-V*.1,lt=d/300*V*20,Tt=-(c/300)*V*20,Lt=Math.min(1,10*t);i.skew_x=this.lerp(i.skew_x??((at=e.transform)==null?void 0:at.skew_x)??0,Q,Lt),i.scale_y=this.lerp(i.scale_y??((ct=e.transform)==null?void 0:ct.scale_y)??1,(((dt=e.transform)==null?void 0:dt.scale_y)??1)*U,Lt),i.rotate_x=this.lerp(i.rotate_x??(($=e.transform)==null?void 0:$.rotate_x)??0,lt,Lt),i.rotate_y=this.lerp(i.rotate_y??((X=e.transform)==null?void 0:X.rotate_y)??0,Tt,Lt),i.style=i.style||{...e.style},i.style.artEffect={enabled:!0,type:"fold_overlay",intensity:((N=n.settings)==null?void 0:N.opacity)??.5}}}else if(n.type===H.Crumple){if(u<300){const V=1-u/300,Q=V*(Math.random()-.5)*5,U=V*(Math.random()-.5)*.05,lt=Math.min(1,15*t);i.skew_x=this.lerp(i.skew_x??((ot=e.transform)==null?void 0:ot.skew_x)??0,Q,lt),i.scale_x=this.lerp(i.scale_x??((bt=e.transform)==null?void 0:bt.scale_x)??1,(((St=e.transform)==null?void 0:St.scale_x)??1)*(1+U),lt),i.scale_y=this.lerp(i.scale_y??((Mt=e.transform)==null?void 0:Mt.scale_y)??1,(((pt=e.transform)==null?void 0:pt.scale_y)??1)*(1+U),lt),i.style=i.style||{...e.style},i.style.artEffect={enabled:!0,type:"crumple_overlay",intensity:((wt=n.settings)==null?void 0:wt.intensity)??1,scale:((yt=n.settings)==null?void 0:yt.scale)??2}}}else if(n.type===H.Squash){const V=((qt=n.settings)==null?void 0:qt.strength)||.8;u<(e.width||100)&&this.isMouseDown?(i.scale_y=this.lerp(i.scale_y??1,(((Kt=e.transform)==null?void 0:Kt.scale_y)??1)*V,.3),i.scale_x=this.lerp(i.scale_x??1,(((j=e.transform)==null?void 0:j.scale_x)??1)*(1+(1-V)*.4),.3)):(i.scale_y=this.lerp(i.scale_y??1,((ft=e.transform)==null?void 0:ft.scale_y)??1,.2),i.scale_x=this.lerp(i.scale_x??1,((Rt=e.transform)==null?void 0:Rt.scale_x)??1,.2))}else if(n.type===H.TextCounter){const V=((At=n.settings)==null?void 0:At.duration)||2,Q=((Pt=n.settings)==null?void 0:Pt.from)||0,U=((Ot=n.settings)==null?void 0:Ot.to)||100;n._runtimeStart===void 0&&(n._runtimeStart=this.currentTime);const lt=this.currentTime-n._runtimeStart,Tt=Math.min(1,lt/V),Lt=Math.floor(Q+(U-Q)*Tt);if(((Gt=e.geometry)==null?void 0:Gt.type)==="Text"){const Yt=((Ht=n.settings)==null?void 0:Ht.prefix)||"",ce=((Nt=n.settings)==null?void 0:Nt.suffix)||"";i.geometry||(i.geometry={...e.geometry}),i.geometry.text=`${Yt}${Lt}${ce}`}}else if(n.type===H.Spotlight){const V=((Bt=n.settings)==null?void 0:Bt.radius)||250,Q=((le=n.settings)==null?void 0:le.strength)||1.5;if(u<V){const U=Math.pow(1-u/V,2);i.style||(i.style={...e.style}),i.style.adjustments||(i.style.adjustments={...(ae=e.style)==null?void 0:ae.adjustments}),i.style.adjustments.exposure=(((Pe=(ye=e.style)==null?void 0:ye.adjustments)==null?void 0:Pe.exposure)||0)+U*Q*50}else(Le=i.style)!=null&&Le.adjustments&&(i.style.adjustments.exposure=this.lerp(i.style.adjustments.exposure||0,((xe=(me=e.style)==null?void 0:me.adjustments)==null?void 0:xe.exposure)||0,.1))}else if(n.type===H.Noise||n.type===H.Float){const V=(((Zt=n.settings)==null?void 0:Zt.frequency)||((_e=n.settings)==null?void 0:_e.speed)||1)*.002,Q=(((Fe=n.settings)==null?void 0:Fe.amplitude)||((Ee=n.settings)==null?void 0:Ee.range)||50)*(((pe=n.settings)==null?void 0:pe.strength)||1),U=Date.now();i.x+=Math.sin(U*V)*Q*t,i.y+=Math.cos(U*V*.8)*Q*t,i.rotation+=Math.sin(U*V*.5)*5*t}else if(n.type===H.Pulse){const V=(((Ce=n.settings)==null?void 0:Ce.speed)||1)*.005,Q=(((Re=n.settings)==null?void 0:Re.scale)||1.2)-1,U=Math.sin(Date.now()*V),lt=((he=n.settings)==null?void 0:he.strength)||1;i.scale_x*=1+U*Q*lt*t,i.scale_y*=1+U*Q*lt*t,i.style&&(i.style.exposure=(i.style.exposure||1)+Math.max(0,U)*.1*lt*t)}else if(n.type===H.Draggable){if(!this.draggingBehaviors.has(e.id)){const Q=((de=n.settings)==null?void 0:de.radius)||150;if(u<Q){const U=((Et=n.settings)==null?void 0:Et.strength)||1,lt=Math.max(0,1-u/Q);this.applyBehaviorSensor(i,ne.PositionX,lt*U,t,n.settings,e,c,d,u),this.applyBehaviorSensor(i,ne.PositionY,lt*U,t,n.settings,e,c,d,u)}}}else if(n.type===H.Scroll){const V=((J=n.settings)==null?void 0:J.axis)||"vertical",Q=((et=n.settings)==null?void 0:et.factor)||.5,U=((q=n.settings)==null?void 0:q.strength)||1,lt=((D=n.settings)==null?void 0:D.scaleFactor)||0;(V==="vertical"||V==="both")&&(i.y+=this.scrollOffset.y*Q*U*t),(V==="horizontal"||V==="both")&&(i.x+=this.scrollOffset.x*Q*U*t),lt!==0&&(i.scale_x*=1+this.scrollOffset.y*lt*t,i.scale_y*=1+this.scrollOffset.y*lt*t)}else if(n.type===H.LookAt){const V=((it=n.settings)==null?void 0:it.factor)||1,Q=((tt=n.settings)==null?void 0:tt.strength)||1,U=Math.atan2(-d,-c)*(180/Math.PI),lt=i.rotation,Tt=(U-lt+180)%360-180;i.rotation+=Tt*V*Q*t*10}else if(n.type===H.Scan){const V=(((ut=n.settings)==null?void 0:ut.speed)||1)*.004,Q=((Wt=n.settings)==null?void 0:Wt.strength)||1,U=(Math.sin(Date.now()*V)+1)/2;i.style&&(i.style.exposure=(i.style.exposure||1)+U*Q*t*5),i.x+=(U-.5)*20*Q*t}else if(n.type===H.Glint)i.style=i.style||{...e.style},i.style.artEffect={enabled:!0,type:"glint_overlay",intensity:((Dt=n.settings)==null?void 0:Dt.strength)??.8};else if(n.type===H.Ratchet){const V=((Qt=n.settings)==null?void 0:Qt.steps)||12,Q=(((zt=n.settings)==null?void 0:zt.speed)||1)*30,U=Math.floor(i.rotation/(360/V))*(360/V);i.rotation=this.lerp(i.rotation,U+Q*t,.1)}else if(n.type===H.Jitter&&u<300){const V=((Xt=n.settings)==null?void 0:Xt.strength)||1,Q=(((x=n.settings)==null?void 0:x.intensity)||5)*V;i.x+=(Math.random()-.5)*Q*t*60,i.y+=(Math.random()-.5)*Q*t*60,i.rotation+=(Math.random()-.5)*Q*t*120}else if(n.type===H.Follower){const V=(rt=n.settings)==null?void 0:rt.targetId;if(V){const Q=this.objectStates.get(V);if(Q){const U=((It=n.settings)==null?void 0:It.stiffness)||.1,lt=Q.x-i.x,Tt=Q.y-i.y;i.x+=lt*U*t*60,i.y+=Tt*U*t*60}}}else if(n.type===H.Wrap)i.x<0?i.x=this.canvasWidth:i.x>this.canvasWidth&&(i.x=0),i.y<0?i.y=this.canvasHeight:i.y>this.canvasHeight&&(i.y=0);else if(n.type===H.Gravity){const V=((Ft=n.settings)==null?void 0:Ft.strength)||9.8;i.y+=V*t*10}else if(n.type===H.Velocity){const V=((K=n.settings)==null?void 0:K.vx)||0,Q=((ht=n.settings)==null?void 0:ht.vy)||0;i.x+=V*t*10,i.y+=Q*t*10}else if(n.type===H.Shear){const V=((gt=n.settings)==null?void 0:gt.strength)||1,Q=((jt=n.settings)==null?void 0:jt.radius)||300;if(u<Q){const U=1-u/Q;i.skew_x=this.lerp(i.skew_x||0,(((mt=e.transform)==null?void 0:mt.skew_x)||0)+U*V*30,.1)}else i.skew_x=this.lerp(i.skew_x||0,(($t=e.transform)==null?void 0:$t.skew_x)||0,.05)}else if(n.type===H.Lens){const V=((vt=n.settings)==null?void 0:vt.radius)||200,Q=((xt=n.settings)==null?void 0:xt.strength)||.5;if(u<V){const U=Math.pow(1-u/V,2);i.scale_x=this.lerp(i.scale_x??1,(((kt=e.transform)==null?void 0:kt.scale_x)??1)*(1+U*Q),.2),i.scale_y=this.lerp(i.scale_y??1,(((oe=e.transform)==null?void 0:oe.scale_y)??1)*(1+U*Q),.2)}else i.scale_x=this.lerp(i.scale_x??1,((re=e.transform)==null?void 0:re.scale_x)??1,.1),i.scale_y=this.lerp(i.scale_y??1,((ke=e.transform)==null?void 0:ke.scale_y)??1,.1)}else if(n.type===H.LayoutAnimation){const V=((Jt=n.settings)==null?void 0:Jt.watchProperties)||["x","y","scale_x","scale_y","opacity","rotation"],Q=((se=n.settings)==null?void 0:se.duration)||.3;this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const U=this._layoutAnimCache.get(e.id);for(const lt of V){const Tt=this.getObjectProperty(i,e,lt);if(Tt===void 0)continue;const Lt=U.get(lt);if(!Lt)U.set(lt,{from:Tt,to:Tt,startTime:this.currentTime,duration:0});else if(Lt.to!==Tt){const ce=this.getObjectProperty(i,e,lt);U.set(lt,{from:ce??Lt.from,to:Tt,startTime:this.currentTime,duration:((ee=n.settings)==null?void 0:ee.duration)??Q})}const Yt=U.get(lt);if(Yt.duration>0&&Yt.from!==Yt.to){const ce=this.currentTime-Yt.startTime,Me=Math.min(1,ce/Yt.duration),Oe=this.applyEasing(Me,((Ae=n.settings)==null?void 0:Ae.easing)||"easeOutCubic"),ue=Yt.from+(Yt.to-Yt.from)*Oe;this.setObjectProperty(i,e,lt,ue)}}}else if(n.type===H.StateReactive){this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const V=this._layoutAnimCache.get(e.id),Q=(($e=n.settings)==null?void 0:$e.defaultDuration)||.3,U=["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 lt of U){const Tt=this.getObjectProperty(i,e,lt);if(Tt===void 0||typeof Tt!="number")continue;const Lt=V.get(lt);if(!Lt)V.set(lt,{from:Tt,to:Tt,startTime:this.currentTime,duration:0});else if(Lt.to!==Tt){const ce=this.getObjectProperty(i,e,lt);V.set(lt,{from:ce??Lt.from,to:Tt,startTime:this.currentTime,duration:Q})}const Yt=V.get(lt);if(Yt.duration>0&&Yt.from!==Yt.to){const ce=this.currentTime-Yt.startTime,Me=Math.min(1,ce/Yt.duration),Oe=this.applyEasing(Me,((Be=n.settings)==null?void 0:Be.defaultEasing)||"easeOutCubic"),ue=Yt.from+(Yt.to-Yt.from)*Oe;this.setObjectProperty(i,e,lt,ue)}}}else if(n.type===H.SpringChain){const V=((We=n.settings)==null?void 0:We.connections)||[],Q=((Ye=n.settings)==null?void 0:Ye.globalDamping)||.3;this._springChainState.has(e.id)||this._springChainState.set(e.id,new Map);const U=this._springChainState.get(e.id);for(const Tt of V){if(!U.has(Tt.targetId)){const Lt=this.objectStates.get(Tt.targetId);U.set(Tt.targetId,{x:(Lt==null?void 0:Lt.x)??0,y:(Lt==null?void 0:Lt.y)??0,vx:0,vy:0})}U.has(e.id)||U.set(e.id,{x:i.x,y:i.y,vx:0,vy:0})}const lt=U.get(e.id);if(lt){lt.x=i.x,lt.y=i.y;for(const Tt of V){const Lt=U.get(Tt.targetId);if(!Lt)continue;const Yt=Lt.x-lt.x,ce=Lt.y-lt.y,Me=Math.sqrt(Yt*Yt+ce*ce)||.001,ue=(Me-(Tt.restLength||50))*(Tt.stiffness||.8),Te=Yt/Me*ue,Qe=ce/Me*ue;lt.vx+=Te*t*10,lt.vy+=Qe*t*10,Lt.vx-=Te*t*10,Lt.vy-=Qe*t*10,lt.vx*=1-Q*t*10,lt.vy*=1-Q*t*10,Lt.vx*=1-Q*t*10,Lt.vy*=1-Q*t*10;const Ie=this.objectStates.get(Tt.targetId);Ie&&(Ie.x+=Lt.vx*t,Ie.y+=Lt.vy*t)}i.x+=lt.vx*t,i.y+=lt.vy*t}}else if(n.type===H.ParticleEmitter){const V=((Xe=n.settings)==null?void 0:Xe.rate)||10,Q=((Ve=n.settings)==null?void 0:Ve.speed)||100,U=((te=n.settings)==null?void 0:te.size)||5,lt=((fe=n.settings)==null?void 0:fe.lifetime)||2,Tt=((be=n.settings)==null?void 0:be.gravity)||0,Lt=((De=n.settings)==null?void 0:De.color)||"#ffffff",Yt=((Ge=n.settings)==null?void 0:Ge.maxParticles)||200,ce=(we=n.settings)!=null&&we.rateInputId?this.inputs.get(n.settings.rateInputId)??V:V,Me=(Se=n.settings)!=null&&Se.gravityInputId?this.inputs.get(n.settings.gravityInputId)??Tt:Tt,Oe=(ve=n.settings)!=null&&ve.speedInputId?this.inputs.get(n.settings.speedInputId)??Q:Q;this._emitterPools.has(e.id)||this._emitterPools.set(e.id,[]);const ue=this._emitterPools.get(e.id);let Te=0;n._pendingBurst&&n._pendingBurst>0&&(Te=n._pendingBurst,n._pendingBurst=0);const Qe=Math.floor(ce*t)+(Te||0);for(let Ie=0;Ie<Math.min(Qe,Yt-ue.length);Ie++){const ge=Math.random()*Math.PI*2,ms=Oe*(.5+Math.random()*.5);ue.push({x:i.x,y:i.y,vx:Math.cos(ge)*ms,vy:Math.sin(ge)*ms,life:0,maxLife:lt*(.5+Math.random()*.5),size:U*(.5+Math.random()),color:Lt,opacity:1})}for(let Ie=ue.length-1;Ie>=0;Ie--){const ge=ue[Ie];ge.vy+=Me*t*10,ge.x+=ge.vx*t,ge.y+=ge.vy*t,ge.life+=t,ge.opacity=Math.max(0,1-ge.life/ge.maxLife),ge.life>=ge.maxLife&&ue.splice(Ie,1)}}})})}applyBehaviorSensor(t,s,o,e,i,n,a=0,r=0,c=1){var h,f,g,y,m,S,v,C,w,M,I,T,k,E,P,_,L,A,W,B,R,Y,G,z;const d=(i==null?void 0:i.intensity)||(i==null?void 0:i.strength)||1,u=Math.min(1,15*e),p=c>0?a/c:0,l=c>0?r/c:0;switch(s){case ne.Scale:{const O=((h=n==null?void 0:n.transform)==null?void 0:h.scale_x)??1,F=((f=n==null?void 0:n.transform)==null?void 0:f.scale_y)??1,Z=O*(1+o*d*.4),st=F*(1+o*d*.4);t.scale_x=(t.scale_x??O)*(1-u)+Z*u,t.scale_y=(t.scale_y??F)*(1-u)+st*u;break}case ne.Opacity:{const O=((g=n==null?void 0:n.transform)==null?void 0:g.opacity)??100,F=Math.max(0,Math.min(100,O-o*d*100));t.opacity=(t.opacity??O)*(1-u)+F*u;break}case ne.RotateZ:{const O=((y=n==null?void 0:n.transform)==null?void 0:y.rotation)??0,F=O+o*d*45;t.rotation=(t.rotation??O)*(1-u)+F*u;break}case ne.RotateX:{const O=((m=n==null?void 0:n.transform)==null?void 0:m.rotate_x)??0,F=O-l*o*d*60;t.rotate_x=(t.rotate_x??O)*(1-u)+F*u;break}case ne.RotateY:{const O=((S=n==null?void 0:n.transform)==null?void 0:S.rotate_y)??0,F=O+p*o*d*60;t.rotate_y=(t.rotate_y??O)*(1-u)+F*u;break}case ne.PositionX:{const O=((v=n==null?void 0:n.transform)==null?void 0:v.x)??0,F=O-p*o*d*40;t.x=(t.x??O)*(1-u)+F*u;break}case ne.PositionY:{const O=((C=n==null?void 0:n.transform)==null?void 0:C.y)??0,F=O-l*o*d*40;t.y=(t.y??O)*(1-u)+F*u;break}case ne.SkewX:{const O=((w=n==null?void 0:n.transform)==null?void 0:w.skew_x)??0,F=O+p*o*d*45;t.skew_x=(t.skew_x??O)*(1-u)+F*u,t.skew_x>85&&(t.skew_x=85),t.skew_x<-85&&(t.skew_x=-85);break}case ne.Blur:{t.style||(t.style={...n==null?void 0:n.style}),t.style.blur||(t.style.blur={...(M=n==null?void 0:n.style)==null?void 0:M.blur});const O=((T=(I=n==null?void 0:n.style)==null?void 0:I.blur)==null?void 0:T.amount)||0,F=O+o*((i==null?void 0:i.blur)||20)*d;t.style.blur.amount=(t.style.blur.amount??O)*(1-u)+F*u;break}case ne.Exposure:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(k=n==null?void 0:n.style)==null?void 0:k.adjustments});const O=((P=(E=n==null?void 0:n.style)==null?void 0:E.adjustments)==null?void 0:P.exposure)||0,F=O+o*((i==null?void 0:i.exposure)||50)*d;t.style.adjustments.exposure=(t.style.adjustments.exposure??O)*(1-u)+F*u;break}case ne.HueShift:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(_=n==null?void 0:n.style)==null?void 0:_.adjustments});const O=((A=(L=n==null?void 0:n.style)==null?void 0:L.adjustments)==null?void 0:A.hue)||0,F=O+o*((i==null?void 0:i.hue)||180)*d;t.style.adjustments.hue=(t.style.adjustments.hue??O)*(1-u)+F*u;break}case ne.Negative:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(W=n==null?void 0:n.style)==null?void 0:W.adjustments});const O=((R=(B=n==null?void 0:n.style)==null?void 0:B.adjustments)==null?void 0:R.negative)||0,F=O+o*((i==null?void 0:i.negative)||100)*d;t.style.adjustments.negative=(t.style.adjustments.negative??O)*(1-u)+F*u;break}case ne.CornerRadius:{const O=((Y=n==null?void 0:n.transform)==null?void 0:Y.corner_radius)||0,F=O+o*d*50;t.corner_radius=(t.corner_radius??O)*(1-u)+F*u;break}case ne.StrokeWidth:{t.style||(t.style={...n==null?void 0:n.style});const O=((G=n==null?void 0:n.style)==null?void 0:G.borderWidth)||0,F=O+o*d*10;t.style.borderWidth=(t.style.borderWidth??O)*(1-u)+F*u;break}case ne.LetterSpacing:{t.geometry||(t.geometry={});const O=((z=n==null?void 0:n.geometry)==null?void 0:z.letterSpacing)||0,F=O+o*d*10;t.geometry.letterSpacing=(t.geometry.letterSpacing??O)*(1-u)+F*u;break}}}getObjectProperty(t,s,o){const e=o.replace(/\[(\d+)\]/g,".$1").split(".");let i=t;for(const n of e){if(i==null||typeof i!="object")return;if(n==="style"&&t.style===void 0){i=s.style;continue}i=i[n]}return typeof i=="number"?i:void 0}setObjectProperty(t,s,o,e){const i=o.replace(/\[(\d+)\]/g,".$1").split(".");let n=t;for(let r=0;r<i.length-1;r++){const c=i[r];if(n[c]===void 0||n[c]===null){const d=s,u=i.slice(0,r+1).reduce((h,f)=>h==null?void 0:h[f],d),p=i[r+1],l=!isNaN(Number(p));n[c]=u!==void 0?Array.isArray(u)?[...u]:{...u}:l?[]:{}}n=n[c]}const a=i[i.length-1];n!=null&&(n[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 i=0;i<s.length;i++)s[i]&&typeof s[i]=="object"&&!Array.isArray(s[i])&&t[i]&&typeof t[i]=="object"?e[i]=this.deepMerge(t[i],s[i]):e[i]=s[i];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 i=(e.exposure||0)/100,n=(e.contrast||0)/100,a=(e.saturation||0)/100,r=(e.temperature||0)/200,c=(e.tint||0)/200,d=(e.highlights||0)/500,u=(e.shadows||0)/500,p=e.hue||0,l=(e.negative||0)/100,h=e.blur||0;if(!(i!==0||n!==0||a!==0||r!==0||c!==0||d!==0||u!==0||p!==0||l!==0||h>0))return t;const g=t.naturalWidth||Math.max(1,Math.round(s)),y=t.naturalHeight||Math.max(1,Math.round(o)),m=document.createElement("canvas");m.width=g,m.height=y;const S=m.getContext("2d");if(!S)return t;const v=[];h>0&&v.push(`blur(${h}px)`),p!==0&&v.push(`hue-rotate(${Math.round(p)}deg)`),v.length>0&&(S.filter=v.join(" ")),S.drawImage(t,0,0,g,y);try{const C=S.getImageData(0,0,g,y),w=C.data,M=w.length,I=i*255,T=n>=0?(1+n)/Math.max(.01,1-n):1+n,k=1+a,E=1+r-c/2,P=1+c,_=1-r-c/2,L=1+d+u,A=u*25.5,W=1-l/50,B=(1-W)*255;for(let R=0;R<M;R+=4){let Y=w[R],G=w[R+1],z=w[R+2];if(i!==0&&(Y+=I,G+=I,z+=I),n!==0&&(Y=(Y-127.5)*T+127.5,G=(G-127.5)*T+127.5,z=(z-127.5)*T+127.5),a!==0){const O=.2989*Y+.587*G+.114*z;Y=O+(Y-O)*k,G=O+(G-O)*k,z=O+(z-O)*k}(r!==0||c!==0)&&(Y=Y*E,G=G*P,z=z*_),(d!==0||u!==0)&&(Y=Y*L+A,G=G*L+A,z=z*L+A),l!==0&&(Y=Y*W+B,G=G*W+B,z=z*W+B),w[R]=Math.min(255,Math.max(0,Y)),w[R+1]=Math.min(255,Math.max(0,G)),w[R+2]=Math.min(255,Math.max(0,z))}return S.putImageData(C,0,0),m}catch{return m}}renderFittedImage(t,s,o,e,i,n,a="cover"){const r=s.naturalWidth||s.width||i,c=s.naturalHeight||s.height||n,d=r/c,u=i/n;let p=i,l=n,h=o,f=e;a==="cover"?d>u?(p=n*d,h=o-(p-i)/2):(l=i/d,f=e-(l-n)/2):a==="contain"&&(d>u?(l=i/d,f=e+(n-l)/2):(p=n*d,h=o+(i-p)/2)),t.drawImage(s,h,f,p,l)}}const ai=_t.forwardRef(({artboard:b,src:t,style:s,autoPlay:o=!0,fit:e="Contain",alignment:i="Center",onReady:n,onTrigger:a,onInputUpdate:r,onComponentChange:c,onToggle:d,onInputChange:u,onInputFocus:p,onInputBlur:l,onLog:h,onLogicUpdate:f,onButtonClick:g,onGraphPointClick:y,currentTime:m,revision:S=0,scrollY:v,scrollX:C,mouseX:w,mouseY:M,isMouseDown:I,inputs:T,interactive:k=!0,onNavigation:E},P)=>{const _=_t.useRef(null),L=_t.useRef(null);L.current||(L.current=new ys);const A=_t.useRef(void 0),W=_t.useRef(0),B=_t.useRef(null),R=_t.useRef(S),Y=_t.useRef(null),[,G]=_t.useState(b||null),z=_t.useRef(!0),O=_t.useRef(o),F=_t.useRef(m);_t.useEffect(()=>{O.current=o},[o]),_t.useEffect(()=>{F.current=m},[m]),_t.useImperativeHandle(P,()=>_.current),_t.useEffect(()=>(z.current=!0,()=>{z.current=!1,A.current&&cancelAnimationFrame(A.current)}),[]),_t.useEffect(()=>{L.current.setLayout(e,i)},[e,i]),_t.useEffect(()=>{const $=L.current;a&&$.setTriggerCallback(a),r&&$.setInputUpdateCallback((X,N)=>r({[X]:N})),c&&$.setComponentChangeCallback(X=>c(X)),d&&$.setToggleCallback(d),u&&$.setInputChangeCallback(u),p&&$.setInputFocusCallback(p),l&&$.setInputBlurCallback(l),h&&$.setOnLogCallback(X=>h(X,"info")),f&&$.setLogicUpdateCallback(f),g&&$.setButtonClickCallback(g),y&&$.setGraphPointClickCallback(X=>y(X.objectId,X)),E&&$.setNavigationCallback(E)},[a,r,c,d,u,p,l,h,f,g,y,E]),_t.useEffect(()=>{(async()=>{let X=b;if(t&&!b)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=L.current,ot=X.id||X.name||"default";(B.current!==ot||R.current!==S||Y.current!==X)&&(N.load(X),B.current=ot,R.current=S,Y.current=X,G(X),W.current=-1,N.advance(0)),n&&n(N)}})()},[b,t,S]),_t.useEffect(()=>{const $=X=>{if(!L.current||!z.current)return;const N=L.current,ot=_.current;if(!ot)return;const bt=ot.getContext("2d");if(!bt)return;const St=X/1e3;W.current<0&&(W.current=St),W.current===0&&(W.current=St);let Mt=St-W.current;Mt>.1&&(Mt=.1),W.current=St;const pt=ot.getBoundingClientRect(),wt=window.devicePixelRatio||1,yt=Math.round(pt.width*wt),qt=Math.round(pt.height*wt);(ot.width!==yt||ot.height!==qt)&&(ot.width=yt,ot.height=qt);try{O.current?N.advance(Mt):F.current!==void 0&&N.seek(F.current),N.render(bt,ot.width,ot.height)}catch(Kt){console.error("[ExodeUICanvas] Error in animation loop:",Kt),h&&h(`[Error] Animation loop crashed: ${Kt}`,"error")}A.current=requestAnimationFrame($)};return A.current=requestAnimationFrame($),()=>{A.current&&cancelAnimationFrame(A.current)}},[]),_t.useEffect(()=>{const $=L.current;v!==void 0&&$.updateInput("scrollY",v),C!==void 0&&$.updateInput("scrollX",C),w!==void 0&&$.updateInput("mouseX",w),M!==void 0&&$.updateInput("mouseY",M),I!==void 0&&$.updateInput("isMouseDown",I),T&&Object.entries(T).forEach(([X,N])=>$.updateInput(X,N))},[v,C,w,M,I,T]);const Z=($,X)=>{if(!k||!_.current)return;$.stopPropagation(),"nativeEvent"in $&&$.nativeEvent&&typeof $.nativeEvent.stopImmediatePropagation=="function"?$.nativeEvent.stopImmediatePropagation():typeof $.stopImmediatePropagation=="function"&&$.stopImmediatePropagation();const N=_.current,ot=N.getBoundingClientRect(),bt=$.clientX-ot.left,St=$.clientY-ot.top,Mt=window.devicePixelRatio||1;(X==="click"||X==="down"||X==="up")&&h&&h(`[Canvas] Pointer ${X} at rect(${Math.round(bt)},${Math.round(St)}) mapped to buffer(${Math.round(bt*Mt)},${Math.round(St*Mt)})`,"info"),L.current.handlePointerInput(X,bt*Mt,St*Mt,N.width,N.height)};_t.useEffect(()=>{if(!k)return;const $=N=>{var ot,bt,St;((ot=document.activeElement)==null?void 0:ot.tagName)==="INPUT"||((bt=document.activeElement)==null?void 0:bt.tagName)==="TEXTAREA"||(St=L.current)==null||St.handleKeyDown(N)},X=N=>{var ot,bt,St;((ot=document.activeElement)==null?void 0:ot.tagName)==="INPUT"||((bt=document.activeElement)==null?void 0:bt.tagName)==="TEXTAREA"||(St=L.current)==null||St.handleKeyUp(N)};return window.addEventListener("keydown",$),window.addEventListener("keyup",X),()=>{window.removeEventListener("keydown",$),window.removeEventListener("keyup",X)}},[k]);const[st,at]=_t.useState([]);_t.useEffect(()=>{if(b&&b.objects){const $=b.objects.filter(X=>{var N,ot;return X.type==="Joystick"&&((N=X.inputBinding)==null?void 0:N.type)==="keyboard"&&((ot=X.inputBinding.keyboardConfig)==null?void 0:ot.showVirtualKeyboard)});at($)}},[b]);const[,ct]=_t.useState(0);_t.useEffect(()=>{if(st.length===0)return;let $;const X=()=>{ct(N=>N+1),$=requestAnimationFrame(X)};return $=requestAnimationFrame(X),()=>cancelAnimationFrame($)},[st.length]);const dt=()=>st.map($=>{const X=$.inputBinding.keyboardConfig,N=pt=>{var yt;const wt={key:pt,code:pt,preventDefault:()=>{}};(yt=L.current)==null||yt.handleKeyDown(wt)},ot=pt=>{var yt;const wt={key:pt,code:pt,preventDefault:()=>{}};(yt=L.current)==null||yt.handleKeyUp(wt)},bt=L.current,St=pt=>bt&&bt.activeKeys?bt.activeKeys.has(pt.toLowerCase()):!1,Mt=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 Vt.jsxs("div",{style:{position:"absolute",bottom:"40px",right:"40px",display:"flex",flexDirection:"column",alignItems:"center",gap:"8px",pointerEvents:"auto",zIndex:100},children:[Vt.jsx("div",{style:Mt(St(X.upKey)),onMouseDown:()=>N(X.upKey),onMouseUp:()=>ot(X.upKey),onMouseLeave:()=>ot(X.upKey),onTouchStart:pt=>{pt.preventDefault(),N(X.upKey)},onTouchEnd:pt=>{pt.preventDefault(),ot(X.upKey)},children:X.upKey.toUpperCase()}),Vt.jsxs("div",{style:{display:"flex",gap:"8px"},children:[Vt.jsx("div",{style:Mt(St(X.leftKey)),onMouseDown:()=>N(X.leftKey),onMouseUp:()=>ot(X.leftKey),onMouseLeave:()=>ot(X.leftKey),onTouchStart:pt=>{pt.preventDefault(),N(X.leftKey)},onTouchEnd:pt=>{pt.preventDefault(),ot(X.leftKey)},children:X.leftKey.toUpperCase()}),Vt.jsx("div",{style:Mt(St(X.downKey)),onMouseDown:()=>N(X.downKey),onMouseUp:()=>ot(X.downKey),onMouseLeave:()=>ot(X.downKey),onTouchStart:pt=>{pt.preventDefault(),N(X.downKey)},onTouchEnd:pt=>{pt.preventDefault(),ot(X.downKey)},children:X.downKey.toUpperCase()}),Vt.jsx("div",{style:Mt(St(X.rightKey)),onMouseDown:()=>N(X.rightKey),onMouseUp:()=>ot(X.rightKey),onMouseLeave:()=>ot(X.rightKey),onTouchStart:pt=>{pt.preventDefault(),N(X.rightKey)},onTouchEnd:pt=>{pt.preventDefault(),ot(X.rightKey)},children:X.rightKey.toUpperCase()})]})]},$.id)});return Vt.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[Vt.jsx("canvas",{ref:_,onPointerDown:$=>{var X;Z($,"down"),(X=_.current)==null||X.focus()},onPointerMove:$=>Z($,"move"),onPointerUp:$=>Z($,"up"),onPointerCancel:$=>Z($,"up"),onClick:$=>Z($,"click"),onWheel:$=>{L.current.handleWheel($.deltaX,$.deltaY)},onKeyDown:$=>L.current.handleKeyDown($.nativeEvent),onKeyUp:$=>L.current.handleKeyUp($.nativeEvent),onContextMenu:$=>$.preventDefault(),tabIndex:0,style:{...s,width:"100%",height:"100%",outline:"none",display:"block",touchAction:"none",pointerEvents:k?"auto":"none"}}),dt()]})});function ri(){const[b,t]=_t.useState(null),s=_t.useCallback((p,l)=>{b==null||b.setInputBool(p,l)},[b]),o=_t.useCallback((p,l)=>{b==null||b.setInputNumber(p,l)},[b]),e=_t.useCallback(p=>{b==null||b.fireTrigger(p)},[b]),i=_t.useCallback((p,l)=>{b==null||b.setInputText(p,l)},[b]),n=_t.useCallback((p,l)=>{b==null||b.setInputNumberArray(p,l)},[b]),a=_t.useCallback((p,l)=>{b==null||b.setInputStringArray(p,l)},[b]),r=_t.useCallback((p,l)=>{b==null||b.updateObjectOptions(p,l)},[b]),c=_t.useCallback((p,l,h)=>{b==null||b.updateConstraint(p,l,h)},[b]),d=_t.useCallback((p,l)=>{b==null||b.updateGraphData(p,l)},[b]),u=_t.useCallback(p=>b==null?void 0:b.getInputValue(p),[b]);return{setEngine:t,engine:b,setInputBool:s,setInputNumber:o,fireTrigger:e,setInputText:i,setInputNumberArray:n,setInputStringArray:a,updateConstraint:c,updateGraphData:d,updateObjectOptions:r,getInputValue:u}}const li=({artboard:b,config:t})=>{const s={...b.seo,...t},o=s.enableSmartExtraction!==!1;_t.useEffect(()=>{const a=s.title||b.name;a&&(document.title=a);let r=s.description;if(!r&&o){const u=b.objects.filter(p=>{var l;return((l=p.geometry)==null?void 0:l.type)==="Text"}).sort((p,l)=>{var h,f;return(((h=l.geometry.text)==null?void 0:h.length)||0)-(((f=p.geometry.text)==null?void 0:f.length)||0)});u.length>0&&(r=u[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 c=s.ogImage||b.backgroundImage;c&&e("property","og:image",c),a&&e("property","og:title",a),e("property","og:type","website")},[s,b,o]);const e=(a,r,c)=>{let d=document.querySelector(`meta[${a}="${r}"]`);d||(d=document.createElement("meta"),d.setAttribute(a,r),document.head.appendChild(d)),d.setAttribute("content",c)},i=()=>{const a=[];return a.push(Vt.jsx("h1",{children:s.title||b.name},"artboard-title")),b.objects.forEach((c,d)=>{var u,p;if(!(c.visible===!1||c.isVisible===!1))if(((u=c.geometry)==null?void 0:u.type)==="Text"){const l=c.geometry.text;l&&(c.geometry.fontSize>24?a.push(Vt.jsx("h2",{children:l},c.id||d)):a.push(Vt.jsx("p",{children:l},c.id||d)))}else if(((p=c.geometry)==null?void 0:p.type)==="Image"){const l=c.geometry.src,h=c.altText||c.name||"Illustration";a.push(Vt.jsx("img",{src:l,alt:h},c.id||d))}else c.type==="Button"&&a.push(Vt.jsx("button",{children:c.name||"Button"},c.id||d))}),a},n=s.jsonLd||{"@context":"https://schema.org","@type":"VisualArtwork",name:s.title||b.name,description:s.description,image:s.ogImage||b.backgroundImage,abstract:"Animated interface created with ExodeUI"};return Vt.jsxs("div",{id:`exode-seo-${b.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:[i(),Vt.jsx("script",{type:"application/ld+json",children:JSON.stringify(n)})]})},ci={version:"6.3.50"}.version;Ut.BehaviorSensor=ne,Ut.BehaviorType=H,Ut.ConditionOp=je,Ut.ExodeSEO=li,Ut.ExodeUICanvas=ai,Ut.ExodeUIEngine=ys,Ut.LogicOp=Ct,Ut.RapierPhysics=is,Ut.VERSION=ci,Ut.useExodeUI=ri,Object.defineProperty(Ut,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,$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||{}),_t=(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))(_t||{});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:c=0,paragraphIndent:d=0,textCase:p="none",segments:u=[],enableSegments:g=!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}|${c}|${d}|${g}|${JSON.stringify(u)}|hyp:${!!y.hyphenation}|comp:${y.composer}|bal:${!!y.balanceRaggedLines}`;let m=Ve.get(v);const l=typeof CanvasRenderingContext2D<"u"?CanvasRenderingContext2D.prototype.measureText:null,b=function(_){if(!l)return{width:0,fontBoundingBoxAscent:0,fontBoundingBoxDescent:0};const E=l.call(this,_);return r!==0&&_&&_.length>0?{...E,width:E.width+(_.length-1)*r}:E};if(!m){try{if(r!==0&&typeof CanvasRenderingContext2D<"u"&&(CanvasRenderingContext2D.prototype.measureText=b),g&&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(m=He.prepareWithSegments(_,f),m){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<m.widths.length){m.widths[W]=F.widths[O];const V=F.kinds[O];if(V===2){const U=k[O];U===`
|
|
2
|
+
`||U==="\r"?m.kinds[W]=2:m.kinds[W]=0}else m.kinds[W]=V}}E+=k.length}m.fullText=_,m.maxFontSize=P}}else m=He.prepareWithSegments(h,f);m&&Ve.set(v,m)}catch(_){return console.error("[ExodeUI] Pretext prepare failed:",_),{width:a,height:0,lineCount:0,lines:[]}}finally{r!==0&&typeof CanvasRenderingContext2D<"u"&&l&&(CanvasRenderingContext2D.prototype.measureText=l)}if(Ve.size>500){const _=Ve.keys().next().value;_&&Ve.delete(_)}}if(d>0&&m&&m.widths&&!m.indentApplied){const _=[...m.widths],E=m.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++);m={...m,widths:_,indentApplied:!0}}if(!m)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 _=m.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(m,a,S*_)}finally{r!==0&&l&&(CanvasRenderingContext2D.prototype.measureText=l)}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(c>0&&w&&w.lines&&w.lines.length>1){let _=0;const E=m.fullText||t;for(let P=0;P<w.lines.length-1;P++)_+=w.lines[P].text.length,(E[_]===`
|
|
5
|
+
`||E[_]==="\r")&&(C+=c,_++,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,c)=>{if(r.endsWith("px")){const d=parseFloat(r);n[c]=d,i-=d}else r.endsWith("fr")?a+=parseFloat(r):r==="auto"&&(n[c]=100,i-=100)}),a>0&&i>0){const r=i/a;e.forEach((c,d)=>{c.endsWith("fr")&&(n[d]=r*parseFloat(c))})}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,c=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 g=((k=y.layoutProps)==null?void 0:k.width)==="hug",h=((A=y.layoutProps)==null?void 0:A.height)==="hug",f=[];let v=[],m=0,l=0;const b=p-i.left-i.right,S=u-i.top-i.bottom;d.forEach(T=>{r&&v.length>0&&(c?l+n+T.h>S:m+n+T.w>b)?(f.push({children:v,width:m,height:l}),v=[T],m=T.w,l=T.h):(v.push(T),c?(m=Math.max(m,T.w),l+=(v.length>1?n:0)+T.h):(m+=(v.length>1?n:0)+T.w,l=Math.max(l,T.h)))}),v.length>0&&f.push({children:v,width:m,height:l}),g&&!c&&(p=Math.max(...f.map(T=>T.width),0)+i.left+i.right),h&&c&&(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;c?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 X,ot;let W=R,V=F;c?_?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=((X=O.original.layoutProps)==null?void 0:X.width)==="fill",Y=((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&&c?T.width:void 0,height:Y?c?void 0:T.height:void 0}),c?F+=O.h+n:R+=O.w+n}),c?C+=T.width+n:M+=T.height+n}),{frameWidth:g?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:c}=o;let d=y.width,p=y.height;const u=d-r.left-r.right,g=p-r.top-r.bottom,h=es(e||"1fr",u,i),f=es(n||"auto",g,a),v=h.length>0?h.reduce((E,P)=>E+P,0)+(h.length-1)*i:0,m=f.length>0?f.reduce((E,P)=>E+P,0)+(f.length-1)*a:0,l=c.toLowerCase(),b=l==="center"||l.endsWith("-center"),S=l.endsWith("-right"),w=l==="center"||l.startsWith("center-"),C=l.startsWith("bottom-");let M=0,I=0;b?M=(u-v)/2:S&&(M=u-v),w?I=(g-m)/2:C&&(I=g-m);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 Y=R,X=F;b?Y+=(A-V)/2:S&&(Y+=A-V),w?X+=(T-U)/2:C&&(X+=T-U),_.push({id:E.id,x:Y+V/2-d/2,y:X+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,c=t.damping??10;i=ae.JointData.spring(a,r,c,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,xs=y=>y<.5?16*y*y*y*y*y:1+16*--y*y*y*y*y,Bs=y=>1-Math.cos(y*Math.PI/2),Ws=y=>Math.sin(y*Math.PI/2),Ys=y=>-(Math.cos(Math.PI*y)-1)/2,Xs=y=>y===0?0:Math.pow(2,10*(y-1)),Ds=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 g=n(p)-d;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},c=d=>d===0?0:d===1?1:i(r(d));return Ze.set(e,c),c},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:xs,EaseInSine:Bs,EaseOutSine:Ws,EaseInOutSine:Ys,EaseInExpo:Xs,EaseOutExpo:Ds,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,c,d)=>{let p=0,u=0;const g=o.rotation*Math.PI/180,h=Math.cos(g),f=Math.sin(g),v=r*n*h-c*i*f+o.x,m=r*n*f+c*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]+m*P[2]+P[4],k=v*P[1]+m*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 l=[...d].sort((I,_)=>_.amount-I.amount);if(l.length>=2&&l[0].amount>0&&l[1].amount>0){const I=e(l[0].boneId),_=e(l[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 Y=s[l[0].boneId]||[1,0,0,1,0,0],X=Y[0]*Y[3]-Y[1]*Y[2];let ot=0,J=0;if(X!==0){const at=(Y[2]*Y[5]-Y[3]*Y[4])/X,j=(Y[1]*Y[4]-Y[0]*Y[5])/X,it=Math.atan2(-Y[1],Y[3]);if(!V)ot=at,J=j;else{const N=-Y[2]/X,ct=Y[0]/X,Mt=Math.hypot(N,ct),bt=I.length*Mt;ot=at-bt*Math.sin(it),J=j+bt*Math.cos(it)}const x=Math.hypot(v-ot,m-J),D=Math.hypot(p-O,u-W);if(D>0&&x>0){const N=Math.max(D,.01),ct=Math.min(x/N,3),Mt=O+(p-O)*ct,bt=W+(u-W)*ct,wt=l[0].amount,gt=l[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,c)=>{const d=t[c];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 c=y.type;if(c==="Rectangle"||c==="Image"||c==="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 m=0;m<f;m++)r.push({x:-t/2+t/f*m,y:-s/2,nx:0,ny:-1});for(let m=0;m<v;m++)r.push({x:t/2,y:-s/2+s/v*m,nx:1,ny:0});for(let m=0;m<f;m++)r.push({x:t/2-t/f*m,y:s/2,nx:0,ny:1});for(let m=0;m<v;m++)r.push({x:-t/2,y:s/2-s/v*m,nx:-1,ny:0})}else if(c==="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,m=Math.cos(v),l=Math.sin(v);r.push({x:m*t/2,y:l*s/2,nx:m,ny:l})}}else if(c==="Triangle"){const h={x:0,y:-s/2},f={x:t/2,y:s/2},v={x:-t/2,y:s/2},m=20;let l=f.x-h.x,b=f.y-h.y,S=Math.hypot(l,b),w=-b/S,C=l/S;for(let M=0;M<m;M++)r.push({x:h.x+l*(M/m),y:h.y+b*(M/m),nx:w,ny:C});l=v.x-f.x,b=v.y-f.y,S=Math.hypot(l,b),w=-b/S,C=l/S;for(let M=0;M<m;M++)r.push({x:f.x+l*(M/m),y:f.y+b*(M/m),nx:w,ny:C});l=h.x-v.x,b=h.y-v.y,S=Math.hypot(l,b),w=-b/S,C=l/S;for(let M=0;M<m;M++)r.push({x:v.x+l*(M/m),y:v.y+b*(M/m),nx:w,ny:C})}else for(let f=0;f<80;f++){const v=f/80*Math.PI*2,m=Math.cos(v),l=Math.sin(v);r.push({x:m*t/2,y:l*s/2,nx:m,ny:l})}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,m=h.ny*(1-a)+u*a;let l=Math.hypot(v,m);return l===0&&(l=1),{x:h.x+v/l*f,y:h.y+m/l*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,c=0,d=0,p=0,u;for(;(u=s.exec(t))!==null;){const g=u[1],h=(u[2].match(o)||[]).map(parseFloat),f=g===g.toLowerCase(),v=g.toUpperCase();let m=0;const l=S=>{let w=h[m++];return f&&(w+=S?i:a),w},b=()=>({x:l(!0),y:l(!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});m<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(;m<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(;m<h.length;)i=l(!0),e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a});break;case"V":for(;m<h.length;)a=l(!1),e.push({x:i,y:a,in_x:i,in_y:a,out_x:i,out_y:a});break;case"C":for(;m<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,c=w.y}break;case"S":for(;m<h.length;){const S={x:2*i-r,y:2*a-c},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,c=w.y}break;case"Q":for(;m<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,c=S.y}break;case"T":for(;m<h.length;){const S={x:2*i-r,y:2*a-c},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,c=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){var e,n;if(!this.artboard)return;const o=this.artboard.objects.find(i=>i.id===t||i.name===t);if(o&&((e=o.geometry)==null?void 0:e.type)==="LineGraph"){const i=o.geometry;!i.datasets||i.datasets.length===0?i.datasets=[{id:"default",label:"Runtime Data",data:s,lineColor:"#3b82f6",lineWidth:2,showArea:!1}]:i.datasets[0].data=s;const a=this.objectStates.get(o.id);a&&((n=a.geometry)==null?void 0:n.type)==="LineGraph"&&(!a.geometry.datasets||a.geometry.datasets.length===0?a.geometry.datasets=JSON.parse(JSON.stringify(i.datasets)):a.geometry.datasets[0].data=[...s]),i.datasets[0].inputId&&this.updateInput(i.datasets[0].inputId,s)}else this.updateInput(t,s)}load(t){var i,a;if(!t)return;let s=this.decompressStrings(t);const o=[],e=new Set,n=r=>{r&&r.forEach(c=>{if(e.has(c.id))return;const d={...c},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(c=>{r.set(c.id,c),c.children||(c.children=[])}),this.artboard.objects.forEach(c=>{if(c.parentId){const d=r.get(c.parentId);d&&(d.children||(d.children=[]),d.children.includes(c.id)||d.children.push(c.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,c,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)??((c=s.geometry)==null?void 0:c.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,c=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:c,rotation:a.rotation*(Math.PI/180),isStatic:e.physics.bodyType==="Static",mass:e.physics.mass,friction:e.physics.friction,restitution:e.physics.restitution,frictionAir:e.physics.frictionAir,density:e.physics.density,isSensor:e.physics.isSensor})}}))})}this.artboard.stateVariables&&this.artboard.stateVariables.forEach(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),c=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}, ${c}, ${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 c=Math.abs(r.x-a.x),d=Math.abs(r.y-a.y);!t&&(c>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),c=this.objectStates.get(i.id);if(!c)return;const d=ss(c,r,p=>this.objectStates.get(p));d.frameWidth!==void 0&&(c.width=d.frameWidth),d.frameHeight!==void 0&&(c.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 c=a.states.find(d=>d.id===r);if(c)if(c.isBlendState&&c.blendAnimations&&c.blendAnimations.length>0)e.push({animation:null,state:c}),c.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;c.animationId&&(d=this.artboard.animations.find(p=>p.id===c.animationId)||null),d||(d=this.artboard.animations.find(p=>{var u,g;return p.name===c.name||p.id===c.name||(c.name==="Entry"||c.id==="entry")&&(((u=p.name)==null?void 0:u.toLowerCase())==="onload"||((g=p.name)==null?void 0:g.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:c}),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],c=!isNaN(Number(r));i[n[a]]=c?[]:{}}i=i[n[a]]}i[n[n.length-1]]=o}else e[s]=o}updateInput(t,s){var c,d,p,u,g;let o;if(this.inputs.has(t)){const h=(c=this.activeStateMachine)==null?void 0:c.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),m=n.minAlpha??0,l=n.maxAlpha??1,b=(Math.random()*(l-m)+m).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&&((g=this.artboard)==null||g.objects.forEach(h=>{var m;const f=(m=h.options)==null?void 0:m.dataInputId;if(h.inputId===t||h.name===t||f===t||a&&(a.includes(h.inputId)||f&&a.includes(f))){let l=this.objectStates.get(h.id);l&&!l.options&&(l.options=JSON.parse(JSON.stringify(h.options||{}))),l&&l.options&&(this.isListViewObject(h)?l.options.items=r:(h.type==="Dropdown"||h.variant==="dropdown")&&(l.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 c=!1;switch(a){case"Equal":case"==":c=s==r;break;case"NotEqual":case"!=":c=s!=r;break;case"GreaterThan":case">":c=s>r;break;case"LessThan":case"<":c=s<r;break;case"GreaterEqual":case">=":c=s>=r;break;case"LessEqual":case"<=":c=s<=r;break;case"IsTrue":c=!!s;break;case"IsFalse":c=!s;break}if(c){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(c=>c.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,c,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(g=>g.id===t);if(e){const g=(f,v)=>{const m=e.inputs.find(l=>l.id===f);return m?m.sourceId?this.evaluateLogicTree(m.sourceId,m.sourceHandleId,o):m.value!==void 0?m.value:v:v};let h=0;switch(e.op){case _t.AND:h=g("a",!1)&&g("b",!1);break;case _t.OR:h=g("a",!1)||g("b",!1);break;case _t.NOT:h=!g("in",!1);break;case _t.XOR:h=!!g("a",!1)!=!!g("b",!1);break;case _t.OBJECT:h=e.name;break;case _t.PROPERTY:case _t.GET_PROPERTY:{const f=g("id","");if(!f){h=0;break}const v=e.name;if(!v||v==="GET_PROPERTY"||v==="PROPERTY"){h=0;break}const m=this.objectStates.get(f);if(!m){h=0;break}v in m?h=m[v]:h=this.resolvePath(m,v);break}case _t.SET_PROPERTY:{const f=g("id",""),v=g("value",void 0);if(!f||v===void 0){h=0;break}const m=e.name;if(!m||m==="SET_PROPERTY"){h=0;break}const l=this.objectStates.get(f);if(!l){h=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(m))l[m]=v,h=v;else{const S=m.replace(/\[(\d+)\]/g,".$1").split(".");let w=l;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 _t.ADD:h=g("a",0)+g("b",0);break;case _t.SUB:h=g("a",0)-g("b",0);break;case _t.MUL:h=g("a",0)*g("b",0);break;case _t.DIV:{const f=g("b",1);h=f===0?0:g("a",0)/f;break}case _t.MOD:h=g("a",0)%g("b",1);break;case _t.POW:h=Math.pow(g("a",0),g("b",1));break;case _t.ABS:h=Math.abs(g("in",0));break;case _t.ROUND:h=Math.round(g("in",0));break;case _t.FLOOR:h=Math.floor(g("in",0));break;case _t.CEIL:h=Math.ceil(g("in",0));break;case _t.SIN:h=Math.sin(g("in",0));break;case _t.COS:h=Math.cos(g("in",0));break;case _t.TAN:h=Math.tan(g("in",0));break;case _t.CLAMP:{const f=g("in",0),v=g("min",0),m=g("max",1);h=Math.max(v,Math.min(m,f));break}case _t.REMAP:{const f=g("in",0),v=g("inMin",0),m=g("inMax",100),l=g("outMin",0),b=g("outMax",1);h=m===v?l:l+(f-v)*(b-l)/(m-v);break}case _t.EQ:h=g("a",0)==g("b",0);break;case _t.NEQ:h=g("a",0)!=g("b",0);break;case _t.GT:h=g("a",0)>g("b",0);break;case _t.LT:h=g("a",0)<g("b",0);break;case _t.GTE:h=g("a",0)>=g("b",0);break;case _t.LTE:h=g("a",0)<=g("b",0);break;case _t.IF_ELSE:h=g("cond",!1)?g("then",0):g("else",0);break;case _t.VALUE:h=e.value!==void 0?e.value:0;break;case _t.INPUT:h=this.inputs.get(e.name)??0;break;case _t.LOG:{const f=g("in","");this.debugLog(`[User Logic] ${f}`),h=f;break}case _t.SCROLL_X:h=this.inputs.get("scrollX")??0;break;case _t.SCROLL_Y:h=this.inputs.get("scrollY")??0;break;case _t.MOUSE_X:h=this.inputs.get("mouseX")??0;break;case _t.MOUSE_Y:h=this.inputs.get("mouseY")??0;break;case _t.IS_MOUSE_DOWN:h=this.inputs.get("isMouseDown")??!1;break;case _t.EFFECTOR:{const f=g("id",""),v=g("intensity",1),m=g("trigger",!0);if(!f||!m){h=0;break}const l=e.name;if(!l){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(l))b.style||(b.style={}),b.style.artEffect={enabled:!0,type:l,intensity:v},h=1;else{b.behaviors||(b.behaviors=[]);let w=b.behaviors.find(C=>C.type===l);w?(w.enabled=!0,w.settings||(w.settings={}),w.settings.intensity=v):(w={id:`eff_${Date.now()}_${l}`,type:l,enabled:!0,sensors:[],settings:{intensity:v}},b.behaviors.push(w)),h=1}break}case _t.MONITOR:{h=g("in",0);break}case _t.SPRING_PULL:{const f=g("objectId",""),v=g("forceX",0),m=g("forceY",0);f&&((c=this.artboard)==null||c.objects.forEach(l=>{l.behaviors&&l.behaviors.forEach(b=>{var S;if(b.type===tt.SpringChain&&((S=b.settings)!=null&&S.connections)&&(b.settings.connections.some(C=>C.targetId===f)||l.id===f)){this._springChainState.has(l.id)||this._springChainState.set(l.id,new Map);const C=this._springChainState.get(l.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+=m)}})})),h=1;break}case _t.SPRING_SETTLE:{const f=g("objectId","");let v=!0;if(f){const m=g("threshold",1);this._springChainState.forEach(l=>{const b=l.get(f);b&&(Math.abs(b.vx)>m||Math.abs(b.vy)>m)&&(v=!1)})}h=v;break}case _t.EMIT:{const f=g("objectId",""),v=g("count",20);f&&((d=this.artboard)==null||d.objects.forEach(m=>{m.behaviors&&m.behaviors.forEach(l=>{l.type===tt.ParticleEmitter&&m.id===f&&(l._pendingBurst=(l._pendingBurst||0)+v)})})),h=1;break}default:h=0;break}if(this.logicNodeValues.set(t,h),e.op===_t.DELAY){const f=g("delay",0),v=g("in",0);let m=this.logicNodeState.get(t);for(m||(m={queue:[]},this.logicNodeState.set(t,m)),m.queue.push({time:this.currentTime+f,value:v});m.queue.length>0&&m.queue[0].time<=this.currentTime;)m.lastValue=m.queue.shift().value;h=m.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===_t.SET_PROPERTY||t.op===_t.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 c=o;for(let p=0;p<r.length-1;p++){const u=r[p],g=r[p+1];c[u]===void 0&&(c[u]=isNaN(Number(g))?{}:[]),c=c[u]}const d=r[r.length-1];c[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,c,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=(c=(r=this.artboard)==null?void 0:r.objects.find(f=>f.id===e))==null?void 0:c.triggers)==null?void 0:d.find(f=>f.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 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),c=(((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+c/2>=-this.canvasWidth/2-p&&r.x-c/2<=this.canvasWidth/2+p&&r.y+d/2>=-this.canvasHeight/2-p&&r.y-d/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,c,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),g=(((r=s.geometry)==null?void 0:r.width)||100)*(u.scale_x||1),h=(((c=s.geometry)==null?void 0:c.height)||100)*(u.scale_y||1),f=50,v=u.x+g/2>=-this.canvasWidth/2-f&&u.x-g/2<=this.canvasWidth/2+f&&u.y+h/2>=-this.canvasHeight/2-f&&u.y-h/2<=this.canvasHeight/2+f,m=this.wasInView.has(s.id);v&&!m&&(!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,g,h,f,v,m,l;const a=((d=o.constraints)==null?void 0:d[i])||{},r={...n,...a},c=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)*c:e.x,R=A?e.y+(M-e.y)*c: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)*c),r.copyY!==!1&&(e.y=e.y+(M-e.y)*c);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*c}}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)*c),r.copyY&&(e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*c))}else if(r.type==="Transform"){const b=this.getGlobalTransform(r.targetId);if(b){e.x=e.x+(b.x-e.x)*c,e.y=e.y+(b.y-e.y)*c;let S=(b.rotation-e.rotation)%360;S>180&&(S-=360),S<-180&&(S+=360),e.rotation=e.rotation+S*c,e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*c,e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*c}}else if(r.type==="FollowPointer"){const b=((g=this._lastPointerPos)==null?void 0:g.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)*c,e.y=e.y+(S-e.y)*c;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)*c,e.y=e.y+(b.y+w*_-e.y)*c}}}else if(r.type==="FollowPath"){const b=(m=this.artboard)==null?void 0:m.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 X=(l=this.artboard)==null?void 0:l.objects.find(ot=>ot.parentId===b.id&&ot.type==="Shape"&&ot.geometry&&(ot.geometry.type==="Path"||ot.geometry.type==="Ellipse"||ot.geometry.type==="Rectangle"));X&&(w=X.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 X=Math.cos(_.angle),ot=Math.sin(_.angle),J=X*S.scale_x*P-ot*S.scale_y*L,at=X*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,Y=S.y+A+V;if(e.x=e.x+(U-e.x)*c,e.y=e.y+(Y-e.y)*c,r.orient){let X=(T-e.rotation)%360;X>180&&(X-=360),X<-180&&(X+=360),e.rotation=e.rotation+X*c}}}}else if(r.type==="IK"){const b=this.getGlobalTransform(r.targetId);b&&this.solveIK(s,b,r.boneCount||2,c)}}),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),c=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:c,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),c=s.x-o.x,d=s.y-o.y,p=(c*a-d*r)*e,u=(c*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 c;const n=[];let i=t.id;for(let d=0;d<o&&i;d++){const p=(c=this.artboard)==null?void 0:c.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 g=a[u],h=this.getGlobalTransform(g.id),f=p.x-h.x,v=p.y-h.y,m=s.x-h.x,l=s.y-h.y,b=Math.sqrt(f*f+v*v),S=Math.sqrt(m*m+l*l);if(b>.001&&S>.001){const w=Math.atan2(v,f);let M=(Math.atan2(l,m)-w)*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 c=a.stiffness??100,d=a.damping??10,p=a.mass??1,u=-c*(t-n),g=-c*(s-i),h=-d*o,f=-d*e,v=(u+h)/p,m=(g+f)/p,l=o+v*r,b=e+m*r,S=t+l*r,w=s+b*r;return{x:S,y:w,vx:l,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}handleWheel(t,s,o,e,n,i){var a,r,c,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,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),f=(h==null?void 0:h.options)||g.options||{},v=(h==null?void 0:h.width)??(((a=g.geometry)==null?void 0:a.width)||200),m=(h==null?void 0:h.height)??(((r=g.geometry)==null?void 0:r.height)||300),l=this.getWorldTransform(g.id),b=this._lastPointerPos.x-l.x,S=this._lastPointerPos.y-l.y,w=-l.rotation*(Math.PI/180),C=Math.cos(w),M=Math.sin(w),I=b*C-S*M,_=b*M+S*C,E=l.scaleX||1,P=l.scaleY||1,L=v*Math.abs(E),k=m*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),g.options&&(g.options.scrollOffset=T);else{const F=this.getResolvedListViewItems(g,f),O=f.itemGap??10,W=f.itemHeight??50,V=f.itemWidth??200,U=typeof f.padding=="number"?f.padding:A==="vertical"?((c=f.padding)==null?void 0:c[0])||0:((d=f.padding)==null?void 0:d[3])||0,X=(F.length||0)*(A==="vertical"?W:V)+Math.max(0,(F.length||0)-1)*O+U*2,J=Math.max(0,X-(A==="vertical"?m:v));T>0&&(T=0),T<-J&&(T=-J),f.scrollOffset=T,h&&h.options&&(h.options.scrollOffset=T),g.options&&(g.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,c,d,p,u,g,h,f,v,m;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=(l,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(l)||l.type==="Component"&&l.variant&&C.includes(String(l.variant).toLowerCase())||l.type==="Joystick"||C.includes((_=l.type)==null?void 0:_.toLowerCase()))return!0;const M=l.interactions||[];return!!(M.some(E=>w.has(E.event))||M.some(E=>Array.isArray(E.triggers)&&E.triggers.some(P=>w.has(String(P))))||(l.triggers||[]).some(E=>w.has(E.eventType)))};let i=null;for(let l=this.artboard.objects.length-1;l>=0;l--){const b=this.artboard.objects[l],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 l=this.artboard.objects.find(b=>b.id===this.draggingSliderId);l&&this.updateSliderValueFromPointer(l,s,o);return}if(this.draggingJoystickId){const l=this.artboard.objects.find(b=>b.id===this.draggingJoystickId);l&&this.updateJoystickValueFromPointer(l,s,o);return}if(this.draggingListViewId){const l=this.artboard.objects.find(b=>b.id===this.draggingListViewId);l&&this.updateListViewScrollFromPointer(l);return}if(e&&this.isListViewObject(e)&&this.updateListViewHoverFromPointer(e,s,o),this.isMouseDown&&this.dragStartPointer&&this.draggingBehaviors.size>0){const l=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+l,M.y=w.y+b)})}if(this.isMouseDown){const l=this.activeObjectId&&this.artboard.objects.some(S=>S.id===this.activeObjectId)?this.activeObjectId:a,b=l?this.artboard.objects.find(S=>S.id===l):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(l=>l.type===tt.Draggable)||this.hasDragInteraction(e)))){this.draggingBehaviors.add(a);const l=this.objectStates.get(a);l&&(this.dragStartPointer={x:s,y:o},this.dragStartPositions.set(a,{x:l.x??0,y:l.y??0}))}if(t==="move"?(a&&!this.activeHoverIds.has(a)&&this.activeHoverIds.add(a),this.activeHoverIds.forEach(l=>{l!==a&&this.activeHoverIds.delete(l)})):t==="blur"&&this.activeHoverIds.clear(),this.activeDropdownId&&t==="down"){const l=this.artboard.objects.find(b=>b.id===this.activeDropdownId);if(l&&(l.type==="Dropdown"||l.variant==="dropdown")){const b=this.objectStates.get(l.id),S=(b==null?void 0:b.options)||l.options||{},w=l.geometry||{},C=w.width??l.width??200,M=w.height??l.height??40,I=S.optionsList||[],_=S.itemHeight||32,E=S.listPadding??4,P=I.length*_+E*2,L=this.getWorldTransform(l.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,l.inputId&&this.setInternalInput(l.inputId,U),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"dropdown",property:"selectedOption",value:U})}return}else a!==this.activeDropdownId&&(S.isOpen=!1,this.activeDropdownId=null)}}if(e){let l=e,b=e;for(;b&&b.parentId;){const C=this.artboard.objects.find(M=>M.id===b.parentId);if(C&&C.type==="Component"){l=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),l!==e&&this.fireEventForObject(l.id,S),l.type==="Component"&&l.variant==="toggle_button"&&t==="down"){const C=this.objectStates.get(l.id),M=(C==null?void 0:C.options)||l.options||{};M.checked=!M.checked,l.inputId&&this.setInternalInput(l.inputId,M.checked),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"toggle_button",property:"checked",value:M.checked}),this.fireEventForObject(l.id,"Toggle"),this.fireEventForObject(l.id,M.checked?"Toggle True":"Toggle False")}if(l.type==="Component"&&l.variant==="toggle"&&t==="down"){const C=this.objectStates.get(l.id),M=(C==null?void 0:C.options)||l.options||{};M.checked=!M.checked,l.inputId&&this.setInternalInput(l.inputId,M.checked),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"toggle",property:"checked",value:M.checked}),this.onToggle&&this.onToggle(l.name,M.checked),this.fireEventForObject(l.id,"Toggle"),this.fireEventForObject(l.id,M.checked?"Toggle True":"Toggle False")}if(l.type==="Component"&&l.variant==="dropdown"&&t==="down"){const C=this.objectStates.get(l.id),M=(C==null?void 0:C.options)||l.options||{},I=!M.isOpen;if(I&&this.activeDropdownId&&this.activeDropdownId!==l.id){const _=this.artboard.objects.find(E=>E.id===this.activeDropdownId);_&&_.options&&(_.options.isOpen=!1)}M.isOpen=I,this.activeDropdownId=I?l.id:null}if((l.type==="Button"||l.type==="Component"&&(l.variant==="button"||(l.name||"").toLowerCase().includes("button")||(l.name||"").toLowerCase().includes("cta")))&&t==="down"&&(this.onButtonClick&&this.onButtonClick(l.name,l.id),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"button",property:"click",value:!0})),this.isListViewObject(l)&&t==="down"){this.draggingListViewId=l.id;const C=this.objectStates.get(l.id),M=(C==null?void 0:C.options)||l.options||{},I=(C==null?void 0:C.width)??(((c=l.geometry)==null?void 0:c.width)||200),_=(C==null?void 0:C.height)??(((d=l.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(l.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,Y=W*O+V*F,X=T.scaleX||1,ot=T.scaleY||1,J=U/X,at=Y/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(l,s,o);if(A!==null){const T=l.options||{};T.activeItemIndex=A;const R=this.objectStates.get(l.id);R&&R.options&&(R.options.activeItemIndex=A);const O=this.getResolvedListViewItems(l,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),l.inputId&&this.setInternalInput(l.inputId,W),this.onComponentChange&&(this.onComponentChange({objectId:l.id,componentName:l.name,variant:"listview",property:"activeItemIndex",value:A}),this.onComponentChange({objectId:l.id,componentName:l.name,variant:"listview",property:"selected",value:W}))}}if(l.type==="Component"&&l.variant==="slider"&&t==="down"&&(this.draggingSliderId=l.id,this.updateSliderValueFromPointer(l,s,o)),l.type==="Joystick"||l.type==="Component"&&l.variant==="joystick"){if(t==="down")this.draggingJoystickId=l.id,this.updateJoystickValueFromPointer(l,s,o);else if(t==="up"||t==="blur"){const C=this.objectStates.get(l.id);C&&l.isSpringReturn!==!1&&(C.handleX=0,C.handleY=0),l.isSpringReturn!==!1&&(l.handleX=0,l.handleY=0)}}if(l.type==="Component"&&l.variant==="checkbox"&&t==="down"){const C=this.objectStates.get(l.id),M=(C==null?void 0:C.options)||l.options||{};M.checked=!M.checked,l.inputId&&this.setInternalInput(l.inputId,M.checked),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"checkbox",property:"checked",value:M.checked}),this.fireEventForObject(l.id,"Click"),this.fireEventForObject(l.id,M.checked?"Checked":"Unchecked")}if(l.type==="Component"&&l.variant==="radiogroup"&&t==="down"){const C=this.objectStates.get(l.id),M=(C==null?void 0:C.options)||l.options||{},I=M.optionsList||[],_=this.getRadioGroupItemIndexAtPointer(l,s,o);if(_!==null&&_>=0&&_<I.length){const E=I[_];M.selectedValue=E,l.inputId&&this.setInternalInput(l.inputId,E),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"radiogroup",property:"selectedValue",value:E}),this.fireEventForObject(l.id,"Click"),this.fireEventForObject(l.id,`Selected: ${E}`)}}if(l.type==="LineGraph"&&(t==="down"||t==="click")){const C=l.geometry,M=(C==null?void 0:C.datasets)||[],I=this.objectStates.get(l.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(l.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||[],Y=A/Math.max(U.length-1,1);U.forEach((X,ot)=>{const J=P.x-_/2+L+ot*Y,at=P.y+E/2-k-X/R*T,j=Math.sqrt((s-J)**2+(o-at)**2);j<F&&(F=j,O={dIdx:V,pIdx:ot,val:X,label:W.label||`Dataset ${V+1}`})})}),O&&F<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:l.id,componentName:l.name,datasetIndex:O.dIdx,pointIndex:O.pIdx,value:O.val,label:O.label}),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"linegraph",property:"click",value:(O==null?void 0:O.val)??null})}if((l==null?void 0:l.type)==="InputBox"||(l==null?void 0:l.type)==="Component"&&(l.variant==="inputbox"||l.name==="InputBox")){if(t==="down"||t==="click"){const C=this.focusedId;if(this.focusedId=l.id,this.log(`[Engine] Focus set to: ${l.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(l.name)}const M=this.objectStates.get(l.id),I=(M==null?void 0:M.options)||l.options||{},_=l.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(l.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(((g=I.number)==null?void 0:g.step)??1),it=((h=I.number)==null?void 0:h.min)!==void 0?Number(I.number.min):-1/0,x=((f=I.number)==null?void 0:f.max)!==void 0?Number(I.number.max):1/0;let D=parseFloat(I.text??I.value??"0");isNaN(D)&&(D=0),W<0?D=Math.min(x,D+j):D=Math.max(it,D-j);const N=String(D);I.text=N,I.value=N,l.options&&(l.options.text=N,l.options.value=N),M&&M.options&&(M.options.text=N,M.options.value=N),this.onComponentChange&&this.onComponentChange({objectId:l.id,componentName:l.name,variant:"inputbox",property:"value",value:N}),this.onInputChange&&this.onInputChange(l.name,N),this.onInputUpdate&&this.onInputUpdate(l.id,N);return}}const V=I.rightIcon||{},U=I.inputType==="password",Y=V.mode==="clear"||I.inputType==="search"&&(I.text||I.value),X=V.mode==="password-toggle"||U&&V.visible!==!1;if(V.visible||X||Y){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(X){I.passwordVisible=!I.passwordVisible,M&&M.options&&(M.options.passwordVisible=I.passwordVisible),l.options&&(l.options.passwordVisible=I.passwordVisible);return}else if(Y){I.text="",I.value="",M&&M.options&&(M.options.text="",M.options.value=""),l.options&&(l.options.text="",l.options.value=""),this.onInputChange&&this.onInputChange(l.name,""),this.onInputUpdate&&this.onInputUpdate(l.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 l=this.focusedId;if(this.focusedId=null,l){const b=(m=this.artboard)==null?void 0:m.objects.find(S=>S.id===l);b&&this.onInputBlur&&this.onInputBlur(b.name)}}}handleKeyDown(t){var c,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(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(((c=n.number)==null?void 0:c.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+g),i=String(f),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 f=parseFloat(i)||0;f=Math.max(h,f-g),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,g,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(m=>{this.triggerGlobalAnimation(m.id,v)}):f&&this.triggerGlobalAnimation(f,v)}else if(a.action==="setState"||a.action==="Set State"){const f=a.targetObjectId||o.id,m={...this.objectStates.get(f)||{},...a.value||{}};this.objectStates.set(f,m),this.log(`[Engine] State updated for ${f}:`,m)}else if(a.action==="Stop Animation"||a.action==="Pause Animation"){const f=a.targetAnimationId;f==="__all__"?this.layerStates.forEach((v,m)=>{m.startsWith("global_")&&this.layerStates.delete(m)}):f&&this.layerStates.forEach((v,m)=>{m.startsWith(`global_${f}_`)&&this.layerStates.delete(m)})}else if(a.action==="Switch to State"&&this.activeStateMachine){const f=a.targetState,v=this.activeStateMachine.layers.find(m=>m.states.some(l=>l.id===f||l.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 c=(o.triggers||[]).find(f=>{const v=f.eventType.toLowerCase();let m=!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"))&&(m=!0),m&&f.conditions&&f.conditions.length>0?this.checkConditions(f.conditions):m});if(c&&c.entryAnimationId){this.log(`[Engine] Trigger matched: ${s} (as ${c.eventType}) -> Animation ${c.entryAnimationId}`);const f=(h=(g=this.artboard)==null?void 0:g.animations)==null?void 0:h.find(v=>v.id===c.entryAnimationId);f&&(this.activeTriggers.set(o.id,{triggerId:c.id,animation:f,time:0,phase:"entry",elapsedHold:0,filterObjectId:c.targetObjectId}),this.onTrigger&&this.onTrigger(c.name,f.name))}}fireAnalyticsEvent(t,s){var r,c;const o=(r=this.artboard)==null?void 0:r.objects.find(d=>d.id===t);if(!o)return;const e=(c=o.style)==null?void 0:c.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(c=>c.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,c=s.y*e.scaleY,d=e.x+(r*i-c*a),p=e.y+(r*a+c*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,c=o-a.y,d=-a.rotation*(Math.PI/180),p=Math.cos(d),u=Math.sin(d),g=r*p-c*u,h=r*u+c*p,f=a.scaleX,v=a.scaleY,m=n*Math.abs(f),l=i*Math.abs(v);return Math.abs(g)<=m/2&&Math.abs(h)<=l/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,c=o-a.y,d=-a.rotation*(Math.PI/180),p=Math.cos(d),u=Math.sin(d),g=r*p-c*u,h=n.thumbWidth??16,f=i-h;let m=(g+f/2)/f;m=Math.max(0,Math.min(1,m));const l=n.min??0,b=n.max??100,S=n.step||1;let w=l+m*(b-l);S>0&&(w=Math.round(w/S)*S),w=Math.max(l,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,c=o-a.y,d=-a.rotation*(Math.PI/180),p=Math.cos(d),u=Math.sin(d);let g=(r*p-c*u)/Math.max(.001,Math.abs(a.scaleX||1)),h=(r*u+c*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 f=Math.min(n,i)*.45,v=Math.min(n,i)*.15,m=f-v;let l=g/m,b=h/m;const S=Math.sqrt(l*l+b*b);t.boundsShape==="square"?(l=Math.max(-1,Math.min(1,l)),b=Math.max(-1,Math.min(1,b))):S>1&&(l/=S,b/=S),t.deadzone!==void 0&&S<t.deadzone?(l=0,b=0):(t.stepX!==void 0&&t.stepX>0&&(l=Math.round(l/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"&&(l=0);const w=e.handleX,C=e.handleY;(w!==l||C!==b)&&(e.handleX=l,e.handleY=b,t.handleX=l,t.handleY=b)}processJoysticks(t){this.artboard&&(this.artboard.objects.forEach(s=>{var c,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&&((c=o.inputBinding)==null?void 0:c.type)==="keyboard"&&o.inputBinding.keyboardConfig){const g=o.inputBinding.keyboardConfig;let h=n,f=i;const m=(g.speed||5)*t;let l=!1;this.activeKeys.has(g.upKey.toLowerCase())&&(f-=m,l=!0),this.activeKeys.has(g.downKey.toLowerCase())&&(f+=m,l=!0),this.activeKeys.has(g.leftKey.toLowerCase())&&(h-=m,l=!0),this.activeKeys.has(g.rightKey.toLowerCase())&&(h+=m,l=!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),!l&&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 g=o.inputBinding.mouseConfig;let h=e._mouseTargetX??n,f=e._mouseTargetY??i;const v=g.sensitivity||.01;if(g.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;g.axisX&&(h=w/b*2-1),g.axisY&&(f=C/S*2-1)}else g.axisX&&(h+=this._mouseDelta.dx*v),g.axisY&&(f+=this._mouseDelta.dy*v);o.joystickType==="1D_X"&&(f=0),o.joystickType==="1D_Y"&&(h=0);const m=Math.sqrt(h*h+f*f);m>1&&(h/=m,f/=m),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 l=15*t;n+=(h-n)*Math.min(l,1),i+=(f-i)*Math.min(l,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(f=>{var l,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=g:f.sourceAxis==="angle"&&(v=h);const m=(l=this.artboard)==null?void 0:l.objects.find(E=>E.id===f.targetObjectId);if(m){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(m.id);if(F){const O=f.isRelative!==!1,W=O?((b=m.transform)==null?void 0:b.x)??0:0,V=O?((S=m.transform)==null?void 0:S.y)??0:0,U=O?((w=m.transform)==null?void 0:w.rotation)??0:0,Y=O?((C=m.transform)==null?void 0:C.scale_x)??1:0,X=O?((M=m.transform)==null?void 0:M.scale_y)??1:0,ot=O?((I=m.style)==null?void 0:I.opacity)??100:0,J=Math.min(t*60,3),at=(j,it)=>{let x=T;if(A){const D=`_internal_${j}_${f.id}`;let N=F[D];N===void 0&&(N=F[j]??it),x=N+R*J,F[D]=x,f.step&&f.step>0&&(x=Math.round(x/f.step)*f.step)}else{x=it+T;const D=`_internal_smooth_${j}_${f.id}`;let N=F[D];if(N===void 0)N=x;else{const ct=Math.min(15*t,1);N+=(x-N)*ct}F[D]=N,x=N}F[j]=x};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",Y):f.targetProperty==="scaleY"||f.targetProperty==="transform.scale_y"?at("scale_y",X):(f.targetProperty==="opacity"||f.targetProperty==="transform.opacity")&&at("opacity",ot)}(_=m.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(m.id,(T-((F==null?void 0:F.x)||0))*10,0):(f.targetProperty==="y"||f.targetProperty==="transform.y")&&this.physicsEngine.applyForce(m.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 c,d,p,u,g,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 m=[...t.blendAnimations].sort((l,b)=>l.position[0]-b.position[0]);if(m.length===1){const l=(d=(c=this.artboard)==null?void 0:c.animations)==null?void 0:d.find(b=>b.id===m[0].animationId);l&&(n.push({anim:l,weight:1}),i=1)}else{let l=0;for(;l<m.length-1&&m[l+1].position[0]<o;)l++;if(l===m.length-1&&o>m[l].position[0]){const b=(u=(p=this.artboard)==null?void 0:p.animations)==null?void 0:u.find(S=>S.id===m[l].animationId);b&&(n.push({anim:b,weight:1}),i=1)}else{const b=m[l].position[0],S=m[l+1].position[0],w=(h=(g=this.artboard)==null?void 0:g.animations)==null?void 0:h.find(E=>E.id===m[l].animationId),C=(v=(f=this.artboard)==null?void 0:f.animations)==null?void 0:v.find(E=>E.id===m[l+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(m=>{var C,M;const l=(M=(C=this.artboard)==null?void 0:C.animations)==null?void 0:M.find(I=>I.id===m.animationId);if(!l)return;const b=m.position[0]-o,S=m.position[1]-e,w=b*b+S*S;if(w<1e-4)n.push({anim:l,weight:1e4}),i+=1e4;else{const I=1/w;n.push({anim:l,weight:I}),i+=I}});if(i===0)return;n.forEach(m=>m.weight/=i);const a=new Map,r=m=>{let l=m.startsWith("#")?m.substring(1):m;return l.length===3&&(l=[l[0],l[0],l[1],l[1],l[2],l[2]].join("")),l="0x"+l,{r:l>>16&255,g:l>>8&255,b:l&255,a:1}};n.forEach(({anim:m,weight:l})=>{m.tracks&&m.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},l<.5)return;_.set(w,E)}if(E.type==="number"&&typeof I=="number")E.value+=I*l;else if(E.type==="color"&&typeof I=="string"&&E.colorAcc){const k=r(I);k&&(E.colorAcc.r+=k.r*l,E.colorAcc.g+=k.g*l,E.colorAcc.b+=k.b*l,E.colorAcc.a+=k.a*l)}else l>.5&&(E.value=I)})}),a.forEach((m,l)=>{var w;const b=this.objectStates.get(l),S=(w=this.artboard)==null?void 0:w.objects.find(C=>C.id===l);!b||!S||m.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,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 c=this.objectStates.get(n);if(!c){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=c;for(let v=0;v<h.length-1;v++){if(typeof f[h[v]]!="object"||f[h[v]]===null){let m=i;for(let l=0;l<=v;l++)m=m?m[h[l]]:null;if(h[v]==="corner_radius"||h[v]==="cornerRadius"){let l=0,b=0,S=0,w=0;const C=f[h[v]]??m;typeof C=="number"?l=b=S=w=C:Array.isArray(C)?C.length===1?l=b=S=w=C[0]:C.length===2?(l=S=C[0],b=w=C[1]):C.length===3?(l=C[0],b=w=C[1],S=C[2]):C.length>=4&&(l=C[0],b=C[1],S=C[2],w=C[3]):C&&typeof C=="object"&&(l=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:l,tr:b,bl:w,br:S,0:l,1:b,2:S,3:w}}else{const l=h[v+1],b=!isNaN(Number(l));f[h[v]]=m?JSON.parse(JSON.stringify(m)):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"?(c.style||(c.style={}),c.style.fill=d):r==="stroke"?(c.style||(c.style={}),c.style.stroke=d):c[r]=d;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,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 m=v.startsWith("#")?v.replace("#",""):"000000";return m.length===3?{r:parseInt(m[0]+m[0],16),g:parseInt(m[1]+m[1],16),b:parseInt(m[2]+m[2],16)}:{r:parseInt(m.substring(0,2),16),g:parseInt(m.substring(2,4),16),b:parseInt(m.substring(4,6),16)}},r=a(n),c=a(i),d=Math.round(r.r+(c.r-r.r)*o),p=Math.round(r.g+(c.g-r.g)*o),u=Math.round(r.b+(c.b-r.b)*o),g=v=>{const m=Math.max(0,Math.min(255,v)).toString(16);return m.length===1?"0"+m:m};return`#${g(d)}${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,f=n/i;let v,m,l,b;f>h?(v=n,m=n/h):(m=i,v=i*h),l=(n-v)/2,b=(i-m)/2,t.drawImage(g,l,b,v,m),t.restore()}}this.artboard.clipContent!==!1&&this.artboard.clip_content!==!1&&(t.beginPath(),t.rect(0,0,n,i),t.clip());const c=new Map;this.artboard.objects.forEach(u=>c.set(u.id,u)),this.artboard.objects.filter(u=>!u.parentId).map((u,g)=>{const h=this.objectStates.get(u.id),f=(h==null?void 0:h.zIndex)??g;return{obj:u,zIndex:f}}).sort((u,g)=>u.zIndex-g.zIndex).forEach(({obj:u})=>{this.renderObject(t,u,c)}),this._emitterPools.forEach((u,g)=>{if(!(u.length===0||!c.get(g)))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,c=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,g=(n/2+i)*p;return r+u>=0&&r-u<=this.canvasWidth&&c+g>=0&&c-g<=this.canvasHeight}calculateTransform(t,s,o,e,n,i){let a=1,r=1,c=1;const d=o/e,p=t/s;switch(n){case"Contain":p>d?c=s/e:c=t/o,a=r=c;break;case"Cover":p>d?c=t/o:c=s/e,a=r=c;break;case"Fill":a=t/o,r=s/e;break;case"FitWidth":c=t/o,a=r=c;break;case"FitHeight":c=s/e,a=r=c;break;case"None":a=r=1;break;case"ScaleDown":c=Math.min(t/o,s/e),c>1&&(c=1),a=r=c;break;default:a=r=1;break}const u=o*a,g=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-g:f=(s-g)/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,Y,X,ot,J,at,j,it,x,D,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,Ot,Wt,q,ft)=>(this.drawRoundRect(t,ut,Ot,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,c=(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((c===0||d===0)&&(a!=null&&a.points)&&Array.isArray(a.points)&&a.points.length>0){let ut=1/0,Ot=-1/0,Wt=1/0,q=-1/0;a.points.forEach(ft=>{ut=Math.min(ut,ft.x),Ot=Math.max(Ot,ft.x),Wt=Math.min(Wt,ft.y),q=Math.max(q,ft.y)}),c===0&&(c=Ot-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 g={...a,width:c,height:d};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 ut=this.getGlobalTransform(s.id);if(ut){const Ot=si(g.points,s.weights,s.bindMatrices,ut,Wt=>this.getGlobalTransform(Wt));g={...g,points:Ot}}}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(g,c,d,f.amplitude||5,f.frequency||10,f.seed||0,f.direction||0,f.directionStrength||0);g={...g,type:"Path",points:ut}}const v=s.repeaterConfig,m=v&&v.isEnabled&&v.count>1,l=m?v.count:1;for(let ut=0;ut<l;ut++){let Ot=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,xt=i.scale_y!==void 0?i.scale_y:((E=i.transform)==null?void 0:E.scale_y)??1;if(m&&ut>0){if(v.type==="Linear"){const z=v.offsetX||0,K=v.offsetY||0,G=v.rotation||0,B=v.scale!==void 0?v.scale:1;Ot+=ut*z,Wt+=ut*K,q+=ut*G,ft*=Math.pow(B,ut),xt*=Math.pow(B,ut)}else if(v.type==="Grid"){const z=v.cols||Math.ceil(Math.sqrt(v.count)),K=v.gapX||0,G=v.gapY||0,B=Math.floor(ut/z),Q=ut%z,H=c+K,lt=d+G;Ot+=Q*H,Wt+=B*lt}else if(v.type==="Radial"){const z=v.radius||100,K=v.startAngle||0,B=(v.endAngle||360)-K,Q=v.count>1?B/(B===360?v.count:v.count-1):0,H=K+ut*Q,lt=H*Math.PI/180;Ot=i.x+z*Math.cos(lt),Wt=i.y+z*Math.sin(lt),q+=H}}const At=s.type==="Group"||s.type==="Frame"||s.type==="Component",Pt=c>0&&d>0;if(!At&&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,Ot,Wt,c,d,z))continue}this.debug_objectsRendered++,t.save();const vt=[],Xt=r.blur||((T=s.style)==null?void 0:T.blur);Xt&&Xt.amount>0&&vt.push(`blur(${Xt.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 Yt=Gt,te=(Yt==null?void 0:Yt.isEnabled)!==!1,ie=Yt==null?void 0:Yt.type,ce=(Yt==null?void 0:Yt.radius)??10;te&&ie==="LayerBlur"?vt.push(`blur(${ce}px)`):te&&ie==="BackgroundBlur"&&(r===s.style&&(r={...r}),r.fill={type:"None"});const ve=(g==null?void 0:g.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)||((Y=(U=s.style)==null?void 0:U.fill)==null?void 0:Y.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,B=(Zt.temperature||0)/200,Q=(Zt.tint||0)/200,H=(Zt.highlights||0)/500,lt=(Zt.shadows||0)/500,kt=Zt.hue||0,Et=(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-B*20;Ut!==0&&vt.push(`hue-rotate(${Math.round(Ut)}deg)`),B>0&&vt.push(`sepia(${Math.round(B*40)}%)`),Et!==0&&vt.push(`invert(${Math.abs(Et)})`),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(Ot,Wt),t.rotate(q*Math.PI/180);const z=i.skew_x||0,K=i.skew_y||0;if(z!==0||K!==0){const Et=Math.tan(z*Math.PI/180),Ht=Math.tan(K*Math.PI/180);t.transform(1+Et*Ht,Ht,Et,1,0,0)}const G=i.rotate_x!==void 0?i.rotate_x:((X=i.transform)==null?void 0:X.rotate_x)??0,B=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(B*Math.PI/180)*H,kt=(i.flip_y===!0?-1:1)*Math.cos(G*Math.PI/180)*H;t.scale(ft*lt,xt*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 Et=z.replace("#",""),Ht=parseInt(Et.substring(0,2),16),Ut=parseInt(Et.substring(2,4),16),qt=parseInt(Et.substring(4,6),16);H=`rgba(${Ht}, ${Ut}, ${qt}, ${K})`}else if(z.startsWith("rgba")){const Et=z.match(/[\d.]+/g);if(Et&&Et.length>=4){const Ht=Et[0],Ut=Et[1],qt=Et[2],$=Et[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(-c/2,K,c,d*z),t.clip(),t.fillStyle=rt.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(rt.opacity??1)}if(e||this.applyOuterGlowUnderlay(t,s,g,c,d,u,r,o),(a==null?void 0:a.type)==="Text"||s.type==="Text")this._renderText(t,s,g,r,i,c,d,!1,!1);else if((a==null?void 0:a.type)==="Image"||((x=r.fill)==null?void 0:x.type)==="Image"||s.type==="Image"&&(a!=null&&a.src||(D=r.fill)!=null&&D.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,B=(((Mt=r.stroke)==null?void 0:Mt.alignment)||"center").toLowerCase();if(G&&B==="outside"&&this.applyStrokeAlignment(t,r,g,c,d,u),r.fill&&r.fill.type!=="None"){t.save();const Q=t.globalAlpha,H=this.createCanvasFill(t,r.fill,c,d);t.fillStyle=H||r.fill.color||"transparent",t.globalAlpha=Q*this.normalizeOpacity(r.fill.opacity??100),u!==0?(this.drawRoundRect(t,-c/2,-d/2,c,d,u),t.fill()):t.fillRect(-c/2,-d/2,c,d),t.globalAlpha=Q,t.restore()}if(K.complete&&K.naturalWidth>0){const Q=Zt?this.processFabricAdjustmentsCanvas(K,c,d,Zt):K;u!==0?(t.save(),this.drawRoundRect(t,-c/2,-d/2,c,d,u),t.clip(),t.drawImage(Q,-c/2,-d/2,c,d),t.restore()):t.drawImage(Q,-c/2,-d/2,c,d),G&&(B==="inside"||B==="center")&&this.applyStrokeAlignment(t,r,g,c,d,u)}else G&&(B==="inside"||B==="center")&&this.applyStrokeAlignment(t,r,g,c,d,u)}}else if(a.type==="SVG"){const z=a.svgContent;if(z){const K=r.palette||[],G=r.fill,B=r.stroke,Q=G?this.normalizeOpacity(G.opacity??100):1,H=B&&B.isEnabled!==!1?this.normalizeOpacity(B.opacity??100):1,lt=(G==null?void 0:G.type)==="Solid"&&(!B||B.isEnabled===!1||B.type==="Solid"&&B.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:"",Et=B&&B.isEnabled!==!1&&(B.width||0)>0?lt?["monochrome",B.width||0,B.trimStart??0,B.trimEnd??1,B.trimOffset??0,B.dashOffset??0].join("|"):[B.width||0,B.fill?B.fill.type==="Solid"?B.fill.color||"":JSON.stringify(B.fill.stops||[]):B.color||"",B.opacity??1,B.lineCap||"",B.lineJoin||"",(B.dashArray||[]).join(","),B.trimStart??0,B.trimEnd??1,B.trimOffset??0,B.dashOffset??0].join("|"):"nostroke",Ht=[s.id,K.join("_"),kt,Et,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||c||100,Lt=a.height||d||100;const Nt=$.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(Nt&&(dt=parseFloat(Nt[1]),Lt=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} ${Lt}"`),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,"\\$&"),Dt=new RegExp(Tt,"gi");$=$.replace(Dt,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(Rt=>{const le=Rt.offset!==void 0?Rt.offset:Rt.pos??0,fe=this.normalizeOpacity(Rt.opacity??100)*Vt;return`<stop offset="${le*100}%" stop-color="${Rt.color||"#000"}" stop-opacity="${fe}"/>`}).join("");let Dt="";if(G.type==="LinearGradient"||G.type==="Linear"){const Rt=(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=Rt(G.start,0)*100,fe=Rt(G.start,1)*100,Oe=Rt(G.end,0)*100,jt=Rt(G.end,1)*100;Dt=`<linearGradient id="${Ct}" x1="${le}%" y1="${fe}%" x2="${Oe}%" y2="${jt}%" gradientUnits="objectBoundingBox">${Tt}</linearGradient>`}else{const Rt=(jt,oe)=>Array.isArray(jt)?jt[oe]??.5:jt&&typeof jt=="object"?jt[oe===0?"x":"y"]??.5:.5,le=Rt(G.center,0)*100,fe=Rt(G.center,1)*100,Oe=(G.radius??.5)*100;Dt=`<radialGradient id="${Ct}" cx="${le}%" cy="${fe}%" r="${Oe}%" gradientUnits="objectBoundingBox">${Tt}</radialGradient>`}/<defs>/i.test($)?$=$.replace(/<defs>/i,`<defs>${Dt}`):$=$.replace(/<svg([^>]*)>/i,`<svg$1><defs>${Dt}</defs>`),$=$.replace(/\bfill\s*=\s*["'][^"']*["']/gi,Rt=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Rt)?Rt:`fill="url(#${Ct})"`),$=$.replace(/fill\s*:\s*[^;"')]+/gi,Rt=>/fill\s*:\s*(none|transparent)/i.test(Rt)?Rt:`fill:url(#${Ct})`)}}const st=(Ct,Vt,Tt=1)=>{const Dt=(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(""),Rt=(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=Rt(Ct.start,0,0)*100,oe=Rt(Ct.start,1,0)*100,ne=Rt(Ct.end,0,1)*100,Fe=Rt(Ct.end,1,1)*100;return`<linearGradient id="${Vt}" x1="${jt}%" y1="${oe}%" x2="${ne}%" y2="${Fe}%" gradientUnits="objectBoundingBox">${Dt}</linearGradient>`}const le=Rt(Ct.center,0,.5)*100,fe=Rt(Ct.center,1,.5)*100,Oe=(Ct.radius??.5)*100;return`<radialGradient id="${Vt}" cx="${le}%" cy="${fe}%" r="${Oe}%" gradientUnits="objectBoundingBox">${Dt}</radialGradient>`},yt=(Ct,Vt)=>/<defs>/i.test(Ct)?Ct.replace(/<defs>/i,`<defs>${Vt}`):Ct.replace(/(<svg[^>]*>)/i,`$1<defs>${Vt}</defs>`);if(B&&B.isEnabled!==!1&&(B.width||0)>0){const Ct=lt?1:this.normalizeOpacity(B.opacity??100),Vt=lt?"#FFFFFF":B.color||(G==null?void 0:G.color)||"#000000";let Tt="";const Dt=B.fill;if(Dt&&Dt.type){if(Dt.type==="Solid")Tt=Dt.color||B.color||"#000000";else if(Dt.type==="LinearGradient"||Dt.type==="RadialGradient"||Dt.type==="Linear"||Dt.type==="Radial"){const se="exode-stroke";$=yt($,st(Dt,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 Rt=a.width||c||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)&&(Rt=se,le=ue)}const Oe=Math.max(.001,c/Rt),jt=Math.max(.001,d/le),oe=(Oe+jt)/2,ne=(B.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=B.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 xe=B.lineJoin||"round";$.match(/\bstroke-linejoin\s*=\s*["']/i)?$=$.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${xe}"`):$=$.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linejoin="${xe}"`),$=$.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${xe}`);const Be=B.trimStart??0,We=B.trimEnd??1,Ye=B.trimOffset??0,Xe=B.dashOffset??0,Ge=Be!==0||We!==1||Ye!==0||Xe!==0;if(Ge){const se=Math.max(0,Math.min(1,Be)),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=(Rt+le)*2,De=(Ye%1+1)%1,Ne=(Xe%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+De+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(B.dashArray&&B.dashArray.length>0){const se=B.dashArray.join(" ");if($=$.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${se}"`),$=$.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${se}`),B.dashOffset){const ue=(Rt+le)*2,Se=-(B.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||c||100,Ce=a.height||d||100,we=(ke+Ce)*2,Z=Math.max(0,Math.min(1,Be)),nt=Math.max(0,Math.min(1,We)),et=(Ye%1+1)%1,pt=(Xe%1+1)%1;if(Z>=nt)se=` stroke-dasharray="0 ${we}"`,ue=' stroke-dashoffset="0"';else{const Ft=we*(nt-Z),Bt=we-Ft,Jt=-(we*(Z+et+pt));se=` stroke-dasharray="${Ft} ${Bt}"`,ue=` stroke-dashoffset="${Jt}"`}}else(bt=B.dashArray)!=null&&bt.length&&(se=` stroke-dasharray="${B.dashArray.join(" ")}"`,B.dashOffset&&(ue=` stroke-dashoffset="${B.dashOffset}"`));const Se=` stroke-linecap="${B.lineCap||"round"}"`,De=` stroke-linejoin="${B.lineJoin||"round"}"`,Ne=`stroke="${Tt}" stroke-width="${ne}" stroke-opacity="${Ct}"${Se}${De}${se}${ue}`;$=$.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(ke,Ce,we)=>`${Ce}${we}<g ${Ne}>`),$=$.replace(/<\/svg>/i,"</g></svg>")}}else B&&B.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,c),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 Lt=G.color||"#000000",Nt=this.normalizeOpacity(G.opacity??100);this.maskCtx.fillStyle=Lt,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(g.type==="LineGraph")this.renderLineGraph(t,g,c,d);else if(s.type==="Shape"){if(this.applyPath(t,g,c,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,g,c,d,u),t.fill();else{if(t.shadowColor&&t.shadowColor!=="rgba(0, 0, 0, 0)"&&t.shadowColor!=="transparent"){const G=t.getTransform(),B=t.shadowOffsetX,Q=t.shadowOffsetY;t.shadowOffsetX=B+1e4*G.a,t.shadowOffsetY=Q+1e4*G.b,t.save(),t.translate(-1e4,0),this.applyPath(t,g,c,d,u),t.fillStyle="white",t.fill(),t.restore(),t.shadowOffsetX=B,t.shadowOffsetY=Q,t.shadowColor="transparent"}this.applyBackgroundBlurGlass(t,g,c,d,u,Yt,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 B=this.imageCache.get(G);B||(B=new Image,B.src=G,this.imageCache.set(G,B)),B.complete&&B.naturalWidth>0&&(t.save(),this.applyPath(t,g,c,d,u),t.clip(),this.renderFittedImage(t,B,-c/2,-d/2,c,d,r.fill.fillMode),t.restore())}else{const G=this.createCanvasFill(t,r.fill,c,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,g,c,d,u),t.fill()}t.globalAlpha=K}t.restore(),r.stroke&&r.stroke.width>0&&(this.applyPath(t,g,c,d,u),this.applyStrokeAlignment(t,r,g,c,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??c,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,g,z,K,G,Yt,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&<.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,g,c,d,u,r),this.applyArtEffectOverlay(t,s,g,c,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 B=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 Et=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,Et,Ht,Ut),t.clip(),B++}else this.renderObject(t,H,o,e)});B>0;)t.restore(),B--;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(B=>B.isVisible!==!1&&o.has(B.maskId)).forEach(B=>{var Ut,qt,$,dt,Lt,Nt;const Q=o.get(B.maskId),H=this.objectStates.get(Q.id),lt=B.feather||0,kt=B.inverted===!0,Et=B.opacity!==void 0?typeof B.opacity=="number"?B.opacity:B.opacity/100:1;if((B.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=Et;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,Dt=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},Dt,H,st,yt,!0,!1)}else if(((qt=Q.geometry)==null?void 0:qt.type)==="Image"){const Tt=Q.geometry.src;if(Tt){let Dt=this.imageCache.get(Tt);Dt||(Dt=new Image,Dt.src=Tt,this.imageCache.set(Tt,Dt)),Dt.complete&&Dt.naturalWidth>0?this.lumaCtx.drawImage(Dt,-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 Dt=`__lumamask_${Q.id}`;let Rt=this.imageCache.get(Dt);if(!Rt){Rt=new Image;const le=new Blob([Tt],{type:"image/svg+xml"});Rt.src=URL.createObjectURL(le),Rt.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(Dt,Rt)}Rt.complete&&Rt.naturalWidth>0?this.lumaCtx.drawImage(Rt,-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 Dt=Ct[Tt],Rt=Ct[Tt+1],le=Ct[Tt+2];let fe=(.299*Dt+.587*Rt+.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=Et,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(((Lt=Q.geometry)==null?void 0:Lt.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 c=a||s.style||{},d=c.effect,p=c.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 g=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=c.fill&&c.fill.type!=="None",m=p.some(P=>P.isEnabled!==!1&&P.type==="BackgroundBlur"),l=s.type==="Text",b=s.type==="Group";!l&&!b&&(v||m)&&(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=g,t.shadowOffsetX=h*S.a,t.shadowOffsetY=h*S.b,t.translate(-h,0);let w="black";c.fill&&c.fill.type!=="None"&&(w=this.createCanvasFill(t,c.fill,e,n)||c.fill.color||"black");let C="black";c.stroke&&c.stroke.width>0&&(C=this.createCanvasFill(t,c.stroke.fill||{type:"Solid",color:c.stroke.color},e,n)||c.stroke.color||"black"),t.fillStyle=w,t.strokeStyle=C,t.lineWidth=((E=c.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")c.fill&&c.fill.type!=="None"&&t.fillText(s.text||"",0,0),c.stroke&&c.stroke.width>0&&t.strokeText(s.text||"",0,0);else if(o.points&&o.type==="Path")this.applyPath(t,o,e,n,i),c.fill&&c.fill.type!=="None"&&t.fill(),c.stroke&&c.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=c.fill&&c.fill.type!=="None",k=c.stroke&&c.stroke.width>0;(L||!L&&!k)&&t.fill(),k&&t.stroke()}t.restore()}_renderText(t,s,o,e,n,i,a,r=!1,c=!1){var ct,Mt,bt,wt,gt,It,ut,Ot,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",xt=((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*=xt;const At=new Path2D(q);t.fill(At),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 g=((wt=o.fontWeight)==null?void 0:wt.toString())||"400",h=o.fontStyle||"normal";g.toLowerCase().includes("italic")&&(h="italic",g=g.replace(/italic/gi,"").trim()||"400");const f=this.mapFontWeight(g),v=Math.max(1,o.fontSize||32);let m=o.fontFamily||"Inter";const l=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];l.forEach(q=>{const ft=new RegExp(`[\\s-]${q}$`,"i");ft.test(m)&&(m=m.replace(ft,"").trim())});const b=o.smallCaps===!0,w=`${b?"small-caps ":""}${h} ${f} ${v}px "${m}", 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:m,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[m]??.5,U=(k-v)*V;let Y=F.height,X=i,ot=a;if(X===0||ot===0||X>=1e5||A){let q=0,ft=0;const xt=F.fullText||p;(O||[]).forEach(At=>{const Pt=At.text||"",vt=t.measureText(Pt).width+(Pt.length>0?(Pt.length-1)*I:0);vt>q&&(q=vt),ft+=Pt.length,ft<xt.length&&(xt[ft]===`
|
|
8
|
+
`||xt[ft]==="\r")&&(ft++,xt[ft-1]==="\r"&&xt[ft]===`
|
|
9
|
+
`&&ft++)}),(X===0||X>=1e5)&&(X=q),ot===0&&(ot=Y||0)}let J=-Y/2;a>0&&a>Y&&(C==="top"?J=-a/2:C==="middle"||C==="center"?J=-Y/2:C==="bottom"&&(J=a/2-Y));const at=C==="top"&&a>0?0:U;let j=J+at+U,it=null,x=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),xt=ft!=null&&ft.geometry?this.deepMerge(q.geometry,ft.geometry):q.geometry,At=(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:xt,obj:q,w:At,h:Pt},x=this.getPerimeter(xt,At,Pt)}}const D=(q,ft)=>{var At,Pt;if(!I&&!b&&!r&&(!o.enableSegments||!((At=o.segments)!=null&&At.length)))return t.measureText(q).width;let xt=0;for(let vt=0;vt<q.length;vt++){const Xt=ft+vt;let zt=0;if(o.enableSegments===!0&&((Pt=o.segments)==null?void 0:Pt.length)>0){let Gt=0,Yt=null;for(const te of o.segments){if(Xt<Gt+(te.text||"").length){Yt=te;break}Gt+=(te.text||"").length}if(Yt){t.save();let te=Yt.fontFamily||o.fontFamily||"Inter";const ie=this.mapFontWeight((Yt.fontWeight||o.fontWeight||"400").toString()),ce=Yt.fontStyle||h,ve=Yt.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;xt+=zt+I}return xt-(q.length>0?I:0)},N=(q,ft,xt,At,Pt)=>{var ve,_e;const Xt=(Pt===0||p[Pt-1]===`
|
|
10
|
+
`||p[Pt-1]==="\r")&&o.paragraphIndent?o.paragraphIndent:0,zt=(!r||c)&&(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),Yt=o.baselineShift||0,te=xt+Yt,ie=D(q,Pt);let ce=ft+Xt;if(M==="center"?ce-=ie/2:M==="right"&&(ce-=ie),Gt){t.font=w;const ge=t.textAlign;t.textAlign="left",At?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&&x>0&&it&&(M==="center"?de+=x/2-ie/2:M==="right"&&(de+=x-ie));let me=ce;const Ae=r&&!c?[]:((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,B=1,Q=0,H=1,lt=mt;Ae.forEach($=>{const dt=$.settings||{},Lt=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)*Lt;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)*Lt)}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))*Lt*.2,K+=(st.y-(n.y+xt+K))*Lt*.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,B*=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)*Lt,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)*Lt,B*=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*Lt,K+=Math.sin(st)*yt*Lt}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*Lt,K+=Math.sin(St)*ee*Lt,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*Lt,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*Lt:K+=100*Lt}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*Lt,K+=Math.cos(Nt*.0015*st+rt*.7)*yt*Lt}else if($.type===tt.TextBreathe){const yt=1+(Math.sin(Nt*.003+rt*.2)+1)/2*.2*Lt;G*=yt,B*=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+xt);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*Lt;G*=St,B*=St,z+=yt*20*Lt}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,B*=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*Lt,z+=Math.sin(Nt*.002+rt)*5*Lt,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)*Lt}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*Lt,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);B*=1+St*st*Lt}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,Et=o.textDecoration||"none",Ht=v;if(o.enableSegments===!0&&((_e=o.segments)==null?void 0:_e.length)>0){let $=0,dt=null;for(const Lt of o.segments){if(rt<$+(Lt.text||"").length){dt=Lt;break}$+=(Lt.text||"").length}if(dt){let Lt=dt.fontFamily||o.fontFamily||"Inter";l.forEach(yt=>{const St=new RegExp(`[\\s-]${yt}$`,"i");St.test(Lt)&&(Lt=Lt.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 "${Lt}", sans-serif`,dt.fill&&(kt=dt.fill),dt.textDecoration&&(Et=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&&x>0){const $=me-ce+qt/2,Lt=(de+$)/x,Nt=this.getPointOnPath(it.geo,it.w,it.h,Math.abs(Lt%1)),st=Nt.angle,yt=xt+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,xt+K),Q!==0&&t.rotate(Q);if(t.scale(G,B),kt&&!r&&!c){const $=this.createCanvasFill(t,kt,X,ot);t.fillStyle=$||kt.color||"#000000"}else if(!r&&!c){const $=this.createCanvasFill(t,e.fill,X,ot);t.fillStyle=$||e.fill.color||"#000000"}if(H>0)if(r||c){const $=c?"#000000":this.createCanvasFill(t,e.fill,X,ot);t.fillStyle=$||e.fill.color||"#ffffff",t.fillText(lt,-qt/2,0)}else At?t.strokeText(lt,-qt/2,0):t.fillText(lt,-qt/2,0);Et!=="none"&&!r&&this.drawTextDecoration(t,Et,0,0,qt,Ht),t.restore(),t.globalAlpha=Ut,M==="justify"&&Zt>0&<===" "&&!Ee?me+=qt+I+Zt:me+=qt+I}t.textAlign=ge}};if(r){let q=0,ft=j;(O||[]).forEach(xt=>{const At=xt.text||"",Pt=p.indexOf(At,q);Pt!==-1&&(q=Pt);let vt=-X/2;M==="center"?vt=0:M==="right"&&(vt=X/2),N(At,vt,ft,!1,q),q+=At.length,ft+=k})}else if(c){let q=0,ft=j;(O||[]).forEach(xt=>{const At=xt.text||"";let Pt=-X/2;M==="center"?Pt=0:M==="right"&&(Pt=X/2),N(At,Pt,ft,!1,q),q+=At.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,xt=this.createCanvasFill(t,e.fill,X,ot);t.fillStyle=xt||e.fill.color||"#000000",t.globalAlpha=ft*this.normalizeOpacity(e.fill.opacity??100);const At=F.fullText||(o.enableSegments?(o.segments||[]).map(Xt=>{let zt=Xt.text||"";const Gt=Xt.textCase||o.textCase||"none";return Gt==="uppercase"?zt.toUpperCase():Gt==="lowercase"?zt.toLowerCase():Gt==="capitalize"?zt.replace(/\b\w/g,Yt=>Yt.toUpperCase()):zt}).join(""):p);let Pt=0,vt=j;(O||[]).forEach(Xt=>{const zt=Xt.text||"";let Gt=-X/2;M==="center"?Gt=0:M==="right"&&(Gt=X/2),N(zt,Gt,vt,!1,Pt),Pt+=zt.length,vt+=k,Pt<At.length&&(At[Pt]===`
|
|
14
|
+
`||At[Pt]==="\r")&&(P>0&&(vt+=P),Pt++,At[Pt-1]==="\r"&&At[Pt]===`
|
|
15
|
+
`&&Pt++)}),t.globalAlpha=ft}const q=o.paragraphRule;if(q&&(((Ot=q.top)==null?void 0:Ot.width)>0||((Wt=q.bottom)==null?void 0:Wt.width)>0)){let ft=0;(O||[]).forEach((xt,At)=>{var Xt,zt;const vt=ft===0||ft<p.length&&(p[ft]===`
|
|
16
|
+
`||p[ft]==="\r");if(vt&&At>0&&ft++,vt){if(((Xt=q.top)==null?void 0:Xt.width)>0){const Gt=j+At*k-q.top.offset;t.strokeStyle=q.top.color||"#000000",t.lineWidth=q.top.width,t.beginPath();const Yt=-i/2+k*.2;t.moveTo(Yt,Gt),t.lineTo(i/2-k*.2,Gt),t.stroke()}if(((zt=q.bottom)==null?void 0:zt.width)>0){const Gt=j+(At+1)*k-q.bottom.offset;t.strokeStyle=q.bottom.color||"#000000",t.lineWidth=q.bottom.width,t.beginPath();const Yt=-i/2+k*.2;t.moveTo(Yt,Gt),t.lineTo(i/2-k*.2,Gt),t.stroke()}}ft+=(xt.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 At=t.getTransform(),Pt=Math.sqrt(At.a*At.a+At.b*At.b)||1,vt=window.devicePixelRatio||1;t.lineWidth=(e.stroke.width||1)*vt/Pt,t.globalAlpha=ft*this.normalizeOpacity(e.stroke.opacity??100);let Xt=0,zt=j;(O||[]).forEach(Gt=>{let Yt=-X/2;M==="center"?Yt=0:M==="right"&&(Yt=X/2),N(Gt.text,Yt,zt,!0,Xt),Xt+=(Gt.text||"").length,zt+=k,Xt<p.length&&(p[Xt]===`
|
|
17
|
+
`||p[Xt]==="\r")&&(P>0&&(zt+=P),Xt++,p[Xt-1]==="\r"&&p[Xt]===`
|
|
18
|
+
`&&Xt++)}),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(),c=Math.sqrt(r.a*r.a+r.b*r.b)||1,d=window.devicePixelRatio||1,p=(a.width||1)*d/c,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,m=a.trimOffset??0,l=a.dashOffset??0,b=a.dashArray||[];if(f!==0||v!==1||m!==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+m%1));t.setLineDash([M,I]),t.lineDashOffset=_-l*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=_-l*S}}}else if(b.length>0||l!==0){b.length>0&&t.setLineDash(b);const S=this.getPerimeter(o,e,n);t.lineDashOffset=-(l*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 c=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)));c+=i/360*d,i<360&&(c+=2*Math.sqrt((e-e*a)**2+(n-n*a)**2))}else i<360&&(c+=2*Math.max(e,n));return isNaN(c)?0:c}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 c=e[r];if(c.moveTo){i=c.x,a=c.y;continue}const d=i,p=a,u=e[r-1].out_x,g=e[r-1].out_y;if(u!==void 0||c.in_x!==void 0?n+=this.getBezierLength(d,p,u??d,g??p,c.in_x??c.x,c.in_y??c.y,c.x,c.y):n+=Math.sqrt((c.x-d)**2+(c.y-p)**2),i=c.x,a=c.y,c.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],m=v.x,l=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??m,C??l,m,l):n+=Math.sqrt((m-h)**2+(l-f)**2)}}return n}default:return(s+o)*2}}getBezierLength(t,s,o,e,n,i,a,r,c=10){let d=0,p=t,u=s;for(let g=1;g<=c;g++){const h=g/c,f=1-h,v=h*h,m=f*f,l=m*f,b=v*h,S=l*t+3*m*h*o+3*f*v*n+b*a,w=l*s+3*m*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,c,d=20){if(t<=0)return 0;let p=0,u=s,g=o;for(let h=1;h<=d;h++){const f=h/d,v=1-f,m=f*f,l=v*v,b=l*v,S=m*f,w=b*s+3*l*f*e+3*v*m*i+S*r,C=b*o+3*l*f*n+3*v*m*a+S*c,M=w-u,I=C-g,_=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,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,c=-1/0;n.forEach(l=>{typeof l.x=="number"&&typeof l.y=="number"&&(i=Math.min(i,l.x),a=Math.max(a,l.x),r=Math.min(r,l.y),c=Math.max(c,l.y),l.out_x!==void 0&&(i=Math.min(i,l.out_x),a=Math.max(a,l.out_x)),l.out_y!==void 0&&(r=Math.min(r,l.out_y),c=Math.max(c,l.out_y)),l.in_x!==void 0&&(i=Math.min(i,l.in_x),a=Math.max(a,l.in_x)),l.in_y!==void 0&&(r=Math.min(r,l.in_y),c=Math.max(c,l.in_y)))});const d=(i+a)/2,p=(r+c)/2,g=this.getPerimeter(t,s,o)*e;let h=0;const f=[];let v=n[0],m=n[0];for(let l=1;l<n.length;l++){const b=n[l];if(b.moveTo){v=b,m=b;continue}f.push({p0:v,p1:b}),(b.closePath||l===n.length-1&&(t.is_closed||t.isClosed))&&f.push({p0:b,p1:m}),v=b}for(const l of f){const b=l.p0,S=l.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>=g||l===f[f.length-1]){let M=0;if(C)return M=this.getBezierTAtLength(g-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:(g-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,c=((t.startAngle??0)+a*e)*Math.PI/180,d=n*Math.cos(c),p=i*Math.sin(c),u=-n*Math.sin(c),g=i*Math.cos(c),h=Math.atan2(g,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 c=0,d=0,p=0;return r<n?(c=-n/2+r,d=-i/2,p=0):r<n+i?(c=n/2,d=-i/2+(r-n),p=Math.PI/2):r<2*n+i?(c=n/2-(r-(n+i)),d=i/2,p=Math.PI):(c=-n/2,d=i/2-(r-(2*n+i)),p=-Math.PI/2),{x:c,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,c=s.out_y??s.y,d=o.in_x??o.x,p=o.in_y??o.y,u=o.x,g=o.y,h=1-t,f=t*t,v=h*h,m=v*h,l=f*t,b=m*i+3*v*t*r+3*h*f*d+l*u-e,S=m*a+3*v*t*c+3*h*f*p+l*g-n,w=3*v*(r-i)+6*h*t*(d-r)+3*f*(u-d),C=3*v*(c-a)+6*h*t*(p-c)+3*f*(g-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 m=Math.tan(e*Math.PI/180),l=Math.tan(n*Math.PI/180);t.transform(1+m*l,l,m,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,c=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)*c,p=(o.flip_y===!0?-1:1)*Math.cos(i*Math.PI/180)*c,u=(o.scale_x??1)*d,g=(o.scale_y??1)*p;t.scale(u,g)}applyInnerGlowOverlay(t,s,o,e,n,i,a){var m,l;const r=a||s.style||{},c=r==null?void 0:r.effect,p=((r==null?void 0:r.effects)||(c?[c]:[])).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,g=1e4,h=t.getTransform();let f=p.color||"white";(l=(m=this.artboard)==null?void 0:m.tokens)!=null&&l.colors&&this.artboard.tokens.colors[f]&&(f=this.artboard.tokens.colors[f]),t.shadowColor=f,t.shadowBlur=u,t.shadowOffsetX=g*h.a,t.shadowOffsetY=g*h.b,t.translate(-g,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 g,h,f,v,m;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 c=r.type,d=r.intensity??.5,p=r.speed??1,u=r.scale??10;if(c==="acid_gradient"||c==="acid_rave"||c==="shimmer"||c==="glint_overlay"||c==="halftone"||c==="noise"||c==="scanlines"||c==="chromatic_aberration"||c==="pixelate"||c==="glitch"||c==="fold_overlay"||c==="crumple_overlay"){if(t.save(),this.applyPath(t,o,e,n,i),t.clip(),c==="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(c==="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(c==="fold_overlay"){const l=this._lastPointerPos||{x:0,y:0},b=l.x-(((v=s.transform)==null?void 0:v.x)??0),S=l.y-(((m=s.transform)==null?void 0:m.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(c==="crumple_overlay"){const l=Math.floor(e/u),b=document.createElement("canvas");b.width=l,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(c==="acid_gradient"||c==="acid_rave"){const l=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=l*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=l*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(c==="halftone"){const l=Math.max(2,u*(1-d*.8)),b=document.createElement("canvas");b.width=l,b.height=l;const S=b.getContext("2d");if(S){S.fillStyle="black",S.beginPath(),S.arc(l/2,l/2,l/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(c==="noise"){const l=Math.floor(e*n*d*.02);t.globalAlpha=.4*d;for(let b=0;b<l;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(c==="scanlines"){t.globalAlpha=.2*d,t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1;for(let l=-n/2;l<n/2;l+=4)t.beginPath(),t.moveTo(-e/2,l),t.lineTo(e/2,l),t.stroke()}else if(c==="chromatic_aberration"){const l=5*d;t.globalCompositeOperation="screen",t.globalAlpha=.5,t.fillStyle="cyan",t.fillRect(-e/2-l,-n/2,e,n),t.fillStyle="magenta",t.fillRect(-e/2+l,-n/2,e,n)}else if(c==="pixelate"){const l=Math.max(2,Math.round(u*(1-d*.5))),b=document.createElement("canvas"),S=Math.max(1,Math.ceil(e/l)),w=Math.max(1,Math.ceil(n/l));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(c==="glitch"){const l=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+l*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 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 c=0,d=0,p=(a+r)/2;if(a!==r){const g=a-r;switch(d=p>.5?g/(2-a-r):g/(a+r),a){case e:c=((n-i)/g+(n<i?6:0))/6;break;case n:c=((i-e)/g+2)/6;break;case i:c=((e-n)/g+4)/6;break}}return`hsla(${(((c*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,c=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(),g=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 m=v.getContext("2d");if(m){m.save(),m.translate(o/2,e/2);const l=i.magnification||1;if(l!==1&&m.scale(l,l),typeof u.inverse=="function"){const w=u.inverse();m.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&&m.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)}m.drawImage(g,0,0),m.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=c,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 m=document.createElement("canvas");m.width=64,m.height=64;const l=m.getContext("2d"),b=l.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}l.putImageData(b,0,0),this._noiseTileCanvas=m}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,c=o/2,d=e/2,p=i*Math.PI/180,u=a*Math.PI/180,g=p+u;a>=360&&r<=0?t.ellipse(0,0,c,d,0,0,Math.PI*2):(t.ellipse(0,0,c,d,0,p,g,!1),r>0?t.ellipse(0,0,c*r,d*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 c=r*2*Math.PI/i-Math.PI/2,d=a*Math.cos(c),p=a*Math.sin(c);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 c=0;c<i*2;c++){const d=c*Math.PI/i-Math.PI/2,p=c%2===0?a:r,u=p*Math.cos(d),g=p*Math.sin(d);c===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,c=-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),c=Math.max(c,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),c=Math.max(c,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),c=Math.max(c,u.in_y)))}),i===1/0)return;let d=(i+a)/2,p=(r+c)/2;if(isNaN(d)||isNaN(p)){this.warn("[Engine] Invalid path center:",d,p);return}s.points.forEach((u,g)=>{if(g===0||u.moveTo)t.moveTo(u.x-d,u.y-p);else{const h=s.points[g-1];if(!h)return;const f=(h.out_x??h.x)-d,v=(h.out_y??h.y)-p,m=(u.in_x??u.x)-d,l=(u.in_y??u.y)-p;isNaN(f)||isNaN(m)||isNaN(u.x)?t.lineTo(u.x-d,u.y-p):t.bezierCurveTo(f,v,m,l,u.x-d,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(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,c=-1/0;s.points.forEach(u=>{i=Math.min(i,u.x),a=Math.max(a,u.x),r=Math.min(r,u.y),c=Math.max(c,u.y)});const d=(i+a)/2,p=(r+c)/2;s.points.forEach((u,g)=>{if(g===0)t.moveTo(u.x-d,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)-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||g===s.points.length-1&&(s.is_closed||s.isClosed))&&t.closePath()})}}}renderInputBox(t,s){var zt,Gt,Yt,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,c=this.focusedId===s.id,d=this.lastHoveredObjectId===s.id,p=e.previewState||"default",u=p!=="default"?p:c?"focused":d?"hovered":"default",g=e.label||{visible:!0,text:"Label"},h=e.helperText||{visible:!1,text:"Helper text"},f=e.leftIcon||{visible:!1},v=e.rightIcon||{visible:!1},m=e.inputType==="textarea"||e.multiline===!0,l=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,B=0)=>{const Q=Math.max(0,z-B*2),H=Math.max(0,K-B*2);let[lt,kt,Et,Ht]=G.map(qt=>Math.max(0,(Number(qt)||0)-B));const Ut=Math.min(Q,H)/2;lt=Math.min(lt,Ut),kt=Math.min(kt,Ut),Et=Math.min(Et,Ut),Ht=Math.min(Ht,Ut),t.beginPath(),t.roundRect?t.roundRect(mt+B,rt+B,Q,H,[lt,kt,Et,Ht]):(t.moveTo(mt+B+lt,rt+B),t.lineTo(mt+B+Q-kt,rt+B),t.arcTo(mt+B+Q,rt+B,mt+B+Q,rt+B+kt,kt),t.lineTo(mt+B+Q,rt+B+H-Et),t.arcTo(mt+B+Q,rt+B+H,mt+B+Q-Et,rt+B+H,Et),t.lineTo(mt+B+Ht,rt+B+H),t.arcTo(mt+B,rt+B+H,mt+B,rt+B+H-Ht,Ht),t.lineTo(mt+B+lt,rt+B),t.arcTo(mt+B,rt+B,mt+B+lt,rt+B,lt),t.closePath())};let E=e.backgroundColor||((zt=i.fill)==null?void 0:zt.color)||"rgba(31, 41, 55, 1)",P=e.borderColor||((Yt=(Gt=i.stroke)==null?void 0:Gt.fill)==null?void 0:Yt.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):l?(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")&&!l){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",Y=e.fontWeight||400,X=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 x=e.placeholder||it,D=!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,B=(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)+B:a/2-B;if(t.save(),t.translate(H,0),!z.startsWith("<svg")){const kt=new Path2D(z),Et=G/24;t.scale(Et,Et),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,Ot=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)+Ot,ft=Math.max(0,a-Ot-Wt);let xt=j||x;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}`:"";xt=`${mt}${j}${rt}`}const At=N&&j?e.passwordVisible?j:"•".repeat(j.length):xt,Pt=D?A:k;if(t.font=`${Y} ${X}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(),m){t.textBaseline="top";const mt=At.split(`
|
|
19
|
+
`);let rt=-r/2+(((me=e.padding)==null?void 0:me.top)??8);const z=X*1.4,K=e.rows||3;let G=0,B=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 Et=lt+H[kt]+" ";if(t.measureText(Et).width>ft&&kt>0){if(G>=K)break;t.fillText(lt.trim(),q,rt),lt=H[kt]+" ",rt+=z,G++}else lt=Et}G<K&&(t.fillText(lt.trim(),q,rt),B=t.measureText(lt.trim()).width,rt+=z,G++)}if(c&&!D&&Math.floor(performance.now()/500)%2===0){const Q=rt-z;t.fillStyle=R,t.fillRect(q+Math.min(B,ft),Q,1.5,X)}}else{t.textBaseline="middle";const rt=t.measureText(At).width;let z=0;if(rt>ft&&(z=rt-ft),t.fillText(At,q-z,0),c&&Math.floor(performance.now()/500)%2===0){const K=D?q:q+rt-z;t.fillStyle=R,t.fillRect(K,-(X/2),1.5,X)}}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(g.visible!==!1){const mt=!!(g.required||(Ae=e.validation)!=null&&Ae.required),rt=(g.text||"Label")+(mt?" *":""),z=g.fontSize||12,K=g.color||"rgba(156, 163, 175, 1)",G=g.position||"top",B=g.gap??g.offset??6;let Q=-(a/2),H=-(r/2)-B,lt="left",kt="bottom",Et=`600 ${z}px "${g.fontFamily||U}", sans-serif`;G==="left"?(Q=-(a/2)-B,H=0,lt="right",kt="middle"):G==="bottom"?(Q=-(a/2),H=r/2+B,lt="left",kt="top"):G==="floating"&&(!!j||c?(Q=-(a/2)+12,H=-(r/2)+4,lt="left",kt="top",Et=`600 ${Math.max(9,z-2)}px "${g.fontFamily||U}", sans-serif`):Et=null),Et&&(t.save(),t.font=Et,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()}l&&(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,g=n.trackRoundedness??2,h=n.trackShape??"Rectangle",f=n.trackPath||"",v=n.accentColor||"#3b82f6",m=n.inactiveColor||"#374151",l=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,x,D,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,x)/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,x/2,0,0,Math.PI*2);else if(J==="Rectangle")this.drawRoundRect(t,at-it/2,j-x/2,it,x,D);else if(J==="Triangle")t.moveTo(at,j-x/2),t.lineTo(at+it/2,j+x/2),t.lineTo(at-it/2,j+x/2),t.closePath();else if(J==="Diamond")t.moveTo(at,j-x/2),t.lineTo(at+it/2,j),t.lineTo(at,j+x/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,x)/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,x)/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,m,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,g,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,g),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(l,0,0,b,S,w,l==="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,x=at.width+j*2,D=14+it;t.beginPath(),this.drawRoundRect(t,-x/2,-D/2,x,D,4),t.fillStyle=E,t.fill(),t.fillStyle=P,t.textAlign="center",t.textBaseline="middle",t.fillText(J,0,0),t.restore()}const Y=n.label||{},X=n.helperText||{},ot=n.fontFamily||"Inter";if(Y.visible!==!1){const J=Y.text||"Label",at=Y.fontSize||12,j=Y.color||"rgba(156, 163, 175, 1)",it=Y.offset??8;t.font=`600 ${at}px "${ot}", sans-serif`,t.fillStyle=j,t.textAlign="left",t.textBaseline="bottom";const x=-(i/2),D=-(u/2)-it;t.fillText(J,x,D)}if(X.visible===!0){const J=X.text||"Helper text",at=X.fontSize||11,j=X.color||"rgba(156, 163, 175, 1)",it=X.offset??6;t.font=`400 ${at}px "${ot}", sans-serif`,t.fillStyle=j,t.textAlign="left",t.textBaseline="top";const x=-(i/2),D=u/2+it;t.fillText(J,x,D)}}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||160,i=s.geometry.height||40,a=-n/2,r=-i/2,c=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 g=e.backgroundColor,h=e.borderColor,f=e.color||"#333333";d?(g=e.disabledBackgroundColor||"#f3f4f6",h=e.disabledBorderColor||"#e5e7eb",f=e.disabledColor||"#9ca3af"):u?(g=e.activeBackgroundColor||g,h=e.activeBorderColor||h,f=e.activeColor||f):p&&(g=e.hoverBackgroundColor||g,h=e.hoverBorderColor||h,f=e.hoverColor||f),g||(g="#ffffff"),h||(h="#e5e7eb");const v=t.globalAlpha;t.globalAlpha=v*(e.opacity??1),this.drawRoundRect(t,a,r,n,i,c),t.fillStyle=this.createCanvasFill(t,typeof g=="string"?{type:"Solid",color:g}:g,n,i)||"#ffffff",t.fill();const m=e.borderWidth??1;m>0&&(t.strokeStyle=this.createCanvasFill(t,typeof h=="string"?{type:"Solid",color:h}:h,n,i)||"#e5e7eb",t.lineWidth=m,t.stroke());const l=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-l-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-l*2-P;if(t.save(),t.beginPath(),t.rect(a+l,r,L,i),t.clip(),t.fillText(C,a+l,0),t.restore(),u&&!d){const A=r+i+4,T=e.optionsList||[],R=e.itemHeight||32,F=e.listPadding??4,O=T.length*R+F*2,W=e.listCornerRadius??c;t.save();const V=e.listShadow||{},U=t.getTransform(),Y=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)*Y,t.shadowOffsetY=(V.offsetY??6)*Y,t.shadowOffsetX=(V.offsetX??0)*Y,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 X=e.listBorderWidth??1;X>0&&(t.shadowColor="transparent",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=X,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+X,it,n-X*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 D=this._lastPointerPos.y-(A+F),N=Math.floor(D/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+X,it,n-X*2,R),t.fillStyle=e.itemHoverColor||f)}t.fillText(at,a+l,it+R/2)})}t.globalAlpha=v}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,c=this.activeObjectId===s.id,d=e.label||{},p=e.hoverStyle||{},u=e.activeStyle||{},g=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"),m=n.cornerRadius??n.corner_radius??8,l=e.borderColor||"transparent",b=e.borderWidth||0,S=1;c&&u?(h=u.backgroundColor||h,f=u.color||f,v=u.text||v,S=u.scale??.95,m=u.cornerRadius??m):r&&p&&(h=p.backgroundColor||h,f=p.color||f,v=p.text||v,S=p.scale??1,m=p.cornerRadius??m,l=p.borderColor||l);const w=-i/2,C=-a/2;t.save(),t.scale(S,S),t.beginPath(),this.drawRoundRect(t,w,C,i,a,m);const M=this.createCanvasFill(t,h,i,a);M&&(t.fillStyle=M,t.fill()),(b>0||r&&p.borderColor)&&(t.strokeStyle=l,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(g.enabled&&g.svgPath){const k=I*1.1,A=g.gap||8,T=t.measureText(v),F=-(T.width+k+A)/2,O=g.position==="left"?F+k/2:F+T.width+A+k/2;P=g.position==="left"?F+k+A+T.width/2:F+T.width/2,t.save(),t.translate(O,0);const W=new Path2D(g.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,m;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=((m=s.geometry)==null?void 0:m.height)||40,r=-i/2,c=-a/2,d=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,c,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=g,t.textAlign="center",t.textBaseline="middle",t.fillText(p.text||"Toggle",0,0),t.restore()}renderToggle(t,s){var W,V,U,Y,X,ot,J,at,j,it,x,D;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,c=e.checked??!1,d=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,f=p.knobColor||e.knobColor||"#ffffff",v=c?u:e.inactiveColor||"#374151",m=c?g:e.borderColor||"transparent",l=c?h:e.borderWidth??0,b=c?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()),l>0){t.lineWidth=l;const N=this.createCanvasFill(t,m,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=c?_: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=(c?(U=p.leftLabel)==null?void 0:U.text:null)||((Y=e.leftLabel)==null?void 0:Y.text)||"",R=(c?(X=p.leftLabel)==null?void 0:X.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=(c?(at=p.rightLabel)==null?void 0:at.text:null)||((j=e.rightLabel)==null?void 0:j.text)||"",O=(c?(it=p.rightLabel)==null?void 0:it.color:null)||((x=e.rightLabel)==null?void 0:x.color)||"#f3f4f6";if((D=e.rightLabel)!=null&&D.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,c=e.cornerRadius??4,d=e.checked??!1,p=e.activeColor||"#3b82f6",u=e.inactiveColor||"transparent",g=e.checkColor||"#ffffff",h=e.borderColor||"#4b5563",f=e.borderWidth??2,v=d?p:u,m=d?"transparent":h,l=d?0:f;e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,n,i,c);const b=this.createCanvasFill(t,v,n,i);if(b&&(t.fillStyle=b,t.fill()),l>0){t.lineWidth=l;const C=this.createCanvasFill(t,m,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,g,n,i);t.strokeStyle=C||g,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 c=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)&&(c=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,g=e.activeColor||"#3b82f6",h=e.inactiveColor||"#4b5563",f=e.textColor||"#ffffff",v=e.fontSize||14,m=e.fontFamily||"Inter",l=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=`${l} ${v}px "${m}", sans-serif`,t.textBaseline="middle",t.textAlign="left",p==="vertical"){const P=Math.max(S,v)+u,L=c.length*P-u,k=r+Math.max(0,(i-L)/2);c.forEach((A,T)=>{const R=k+b+T*P,F=d===A,O=this.createCanvasFill(t,g,S,S),W=this.createCanvasFill(t,h,S,S);F?(t.fillStyle=O||g,I(a+b,R,b,w),t.fill(),t.strokeStyle=O||g,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=`${l} ${v}px "${m}", sans-serif`,c.forEach(T=>{L+=S+6+t.measureText(T).width+u}),L-=u;let A=a+Math.max(0,(n-L)/2);c.forEach(T=>{const R=d===T,F=t.measureText(T).width,O=this.createCanvasFill(t,g,S,S),W=this.createCanvasFill(t,h,S,S);R?(t.fillStyle=O||g,I(A+b,P,b,w),t.fill(),t.strokeStyle=O||g,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,c=-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 g=i.categories.length,h=i.datasets.length;if(i.chartType==="stacked")for(let k=0;k<g;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,m=i.showXLabels?i.axisLabelFontSize+12:8,b=(i.showLegend&&h>0?i.legendFontSize+10:0)+8,S=10,w=c+v,C=d+b,M=a-v-S,I=r-b-m;if(i.enableShadows&&(t.shadowColor="transparent"),t.beginPath(),t.roundRect(c,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/g;for(let A=0;A<g;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),Y=T-U/2,X=R;R+=V;const ot=i._resolveColor(F.color,O);t.beginPath(),t.fillStyle=i._makeGradient(t,ot,X,Y,X+V,Y),i._drawRoundedBar(t,X,Y,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/g;for(let A=0;A<g;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),Y=T-U/2,X=R-V;R-=V;const ot=i._resolveColor(F.color,O);t.beginPath(),t.fillStyle=i._makeGradient(t,ot,Y,X,Y,X+V),i._drawRoundedBar(t,Y,X,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/g,A=h*i.barWidth+Math.max(0,(h-1)*i.barGap),T=w+(0-u)/f*M;for(let R=0;R<g;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,Y=Math.abs(U/f*M);if(Y<1)return;const X=O+V*(i.barWidth+i.barGap),ot=U>=0?T:T-Y,J=i._resolveColor(W.color,V);t.beginPath(),t.fillStyle=i._makeGradient(t,J,ot,X,ot+Y,X),i._drawRoundedBar(t,ot,X,Y,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+Y+4:ot-4,X+i.barWidth/2),i.enableShadows&&(t.shadowColor=i.shadowColor))})}}else{const k=M/g,A=h*i.barWidth+Math.max(0,(h-1)*i.barGap),T=C+I-(0-u)/f*I;for(let R=0;R<g;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,Y=Math.abs(U/f*I);if(Y<1)return;const X=O+V*(i.barWidth+i.barGap),ot=U>=0?T-Y:T,J=i._resolveColor(W.color,V);t.beginPath(),t.fillStyle=i._makeGradient(t,J,X,ot,X,ot+Y),i._drawRoundedBar(t,X,ot,i.barWidth,Y,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(),X+i.barWidth/2,U>=0?ot-4:ot+Y+4),i.enableShadows&&(t.shadowColor=i.shadowColor))})}}t.restore()}renderPieChart(t,s){var l,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:((l=s.geometry)==null?void 0:l.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,c=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,-c/2,r,c,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=c-g-16,f=Math.min(r-24,h)/2,v=0,m=-g/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,m),t.arc(v,m,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=m+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,m),t.arc(v,m,f,L,k),t.lineTo(v,m)):(t.moveTo(v+f*Math.cos(L),m+f*Math.sin(L)),t.arc(v,m,f,L,k),t.arc(v,m,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=m+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,m-E*.5),t.font=`${E}px Inter, sans-serif`,t.fillStyle=a.centerLabelColor,t.fillText(a.centerLabel,v,m+_*.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=c/2-g+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,m,l,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:((m=s.geometry)==null?void 0:m.height)??s.height??100,i=Math.min(e,n)*(((l=s.style)==null?void 0:l.baseSize)??.45),a=Math.min(e,n)*(((b=s.style)==null?void 0:b.handleSize)??.14);let r=s.handleX||0,c=s.handleY||0;o&&o.handleX!==void 0&&(r=o.handleX),o&&o.handleY!==void 0&&(c=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 g=s.overflowHandle?i:Math.max(.1,i-a);let h=0,f=0;s.joystickType==="2D"?(h=r*g,f=c*g):s.joystickType==="1D_X"?(h=r*g,f=0):s.joystickType==="1D_Y"&&(h=0,f=c*g),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,c=e.orientation||"vertical",d=e.itemGap!==void 0?e.itemGap:16,p=e.fontSize||14,u=this.getWorldTransform(t.id),g=s-u.x,h=o-u.y,f=-u.rotation*(Math.PI/180),v=Math.cos(f),m=Math.sin(f),l=g*v-h*m,b=g*m+h*v,w=8*2,C=-a/2,M=-r/2;if(c==="vertical"){const E=Math.max(w,p)+d;for(let P=0;P<i.length;P++){const L=M+P*E;if(l>=C&&l<=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(l>=E&&l<=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 m=this.inputs.get(f.inputId);if(m===void 0){const l=this.inputNameMap.get(f.inputId);l&&l.length>0&&(m=this.inputs.get(l[0]))}m&&Array.isArray(m)&&(v=m)}if(v&&v.length>0){const m=v.filter(l=>typeof l=="number"&&!isNaN(l));m.length>0&&(i=Math.min(i,...m),a=Math.max(a,...m),r=Math.max(r,v.length))}f._resolvedData=v}),r<2)return;const c=a-i,d=o/(r-1),p=f=>{const v=c===0?.5:(f-i)/c;return e/2-v*e},u=f=>f*d-o/2,g=s.axisColor||"#333333";if(s.showXAxis&&(t.beginPath(),t.strokeStyle=s.xAxisColor||g,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||g,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 l=0;l<v.length-1;l++){const b=v[l===0?l:l-1],S=v[l],w=v[l+1],C=v[l+1===v.length-1?l+1:l+2];for(let M=1;M<=h;M++){const I=M/h,_=this._catmullRom(b,S,w,C,I);t.lineTo(u(l+I),p(_))}}else for(let l=1;l<v.length;l++)t.lineTo(u(l),p(v[l]));t.lineTo(u(v.length-1),e/2),t.closePath();const m=t.globalAlpha;t.globalAlpha=m*(s.areaOpacity??.3),t.fillStyle=f.areaColor||"rgba(139, 92, 246, 0.2)",t.fill(),t.globalAlpha=m}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 m=0;m<v.length-1;m++){const l=v[m===0?m:m-1],b=v[m],S=v[m+1],w=v[m+1===v.length-1?m+1:m+2];for(let C=1;C<=h;C++){const M=C/h,I=this._catmullRom(l,b,S,w,M);t.lineTo(u(m+M),p(I))}}else for(let m=1;m<v.length;m++)t.lineTo(u(m),p(v[m]));t.stroke(),f.showPoints&&v.forEach((m,l)=>{const b=u(l),S=p(m);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 m=s.legendFontSize||10,l=m+5;t.font=`${m}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+=l})}}_catmullRom(t,s,o,e,n){const i=(o-t)*.5,a=(e-s)*.5,r=n*n,c=n*r;return(2*s-2*o+i+a)*c+(-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=(c,d=100)=>{var S,w;const u=(((w=(S=this.artboard)==null?void 0:S.tokens)==null?void 0:w.colors)||{})[c]||c,g=this.normalizeOpacity(s.opacity??100),f=this.normalizeOpacity(d)*g;if(f>=1&&u.startsWith("#"))return u;const v=u.startsWith("#")?u.replace("#",""):"ffffff",m=parseInt(v.substring(0,2),16),l=parseInt(v.substring(2,4),16),b=parseInt(v.substring(4,6),16);return`rgba(${m}, ${l}, ${b}, ${f})`};if(s.type==="LinearGradient"){let c=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;c=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,m)=>Array.isArray(f)?f[v]??.5:f&&typeof f=="object"?f[m]??.5:.5;c=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(c-p)<.001&&Math.abs(d-u)<.001&&(c=0,d=-e/2,p=0,u=e/2);const g=t.createLinearGradient(c,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);g.addColorStop(Math.max(0,Math.min(1,f)),v)}),s.gradientTransform&&g.setTransform){const[h,f,v,m,l,b]=s.gradientTransform;g.setTransform({a:h,b:f,c:v,d:m,e:l,f:b})}return g}else if(s.type==="RadialGradient"){const c=(h,f,v)=>Array.isArray(h)?h[f]??.5:h&&typeof h=="object"?h[v]??.5:.5,d=c(s.center,0,"x")*o-o/2,p=c(s.center,1,"y")*e-e/2,u=(s.radius??.5)*Math.max(o,e),g=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);g.addColorStop(Math.max(0,Math.min(1,f)),v)}),s.gradientTransform&&g.setTransform){const[h,f,v,m,l,b]=s.gradientTransform;g.setTransform({a:h,b:f,c:v,d:m,e:l,f:b})}return g}else if(s.type==="AngularGradient"){const c=(h,f,v)=>Array.isArray(h)?h[f]??.5:h&&typeof h=="object"?h[v]??.5:.5,d=c(s.center||[.5,.5],0,"x")*o-o/2,p=c(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,d,p);if(g){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);g.addColorStop(Math.max(0,Math.min(1,f)),v)}),s.gradientTransform&&g.setTransform){const[h,f,v,m,l,b]=s.gradientTransform;g.setTransform({a:h,b:f,c:v,d:m,e:l,f:b})}return g}}else if(s.type==="DiamondGradient"){const c=(h,f,v)=>Array.isArray(h)?h[f]??.5:h&&typeof h=="object"?h[v]??.5:.5,d=c(s.center||[.5,.5],0,"x")*o-o/2,p=c(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 g=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);g.addColorStop(Math.max(0,Math.min(1,f)),v)}),s.gradientTransform&&g.setTransform){const[h,f,v,m,l,b]=s.gradientTransform;g.setTransform({a:h,b:f,c:v,d:m,e:l,f:b})}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 c=t.createPattern(r,"repeat");if(c&&(s.scaleX!==void 0||s.offsetX!==void 0)){const d=new DOMMatrix,p=s.scaleX??1,u=s.scaleY??1,g=s.offsetX??0,h=s.offsetY??0,f=s.rotation??0;d.translateSelf(g,h),d.rotateSelf(f),d.scaleSelf(p,u),c.setTransform(d)}return c}}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,c=0,d=0,p=0;typeof a=="number"?r=c=d=p=a:Array.isArray(a)?a.length===1?r=c=d=p=a[0]:a.length===2?(r=d=a[0],c=p=a[1]):a.length===3?(r=a[0],c=p=a[1],d=a[2]):a.length>=4&&(r=a[0],c=a[1],d=a[2],p=a[3]):a&&typeof a=="object"&&(r=a[0]??a.tl??a.corner_radius??a.cornerRadius??0,c=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),c=Math.min(Math.max(0,c),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,c,d,p]);return}t.moveTo(s+r,o),t.lineTo(s+e-c,o),t.arcTo(s+e,o,s+e,o+c,c),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,Y,X,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,c=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,g=e.itemHeight??50,h=e.itemWidth??200,f=e.scrollOffset??0,v=e.padding??0,m=e.glassEffect!==!1,l=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(m){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,c)||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,c)||t.fill();const D=e.borderWidth??0;if(D>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=D}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,c)||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,c);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 x=this.drawCustomShape(t,e.containerShape||"rectangle",e.containerPath||"",a,r,n,i,c);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,c)&&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,xt,At,Pt;const j=e.listLayout||"linear",it=j==="circular"?h:d==="vertical"?n:h,x=j==="circular"||d==="vertical"?g:i;let D=0,N=0,ct=0;if(j==="circular"){const vt=p.length||1,Xt=Math.PI*2/vt,zt=e.circularStartAngle||0,Gt=e.circularRadius||100,Yt=f*.01+zt*Math.PI/180,te=at*Xt+Yt,ie=a+n/2,ce=r+i/2;D=ie+Math.cos(te)*Gt-it/2,N=ce+Math.sin(te)*Gt-x/2,ct=te+(e.itemRotation||0)*Math.PI/180}else D=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(D+it/2,N+x/2),t.rotate(ct),t.translate(-(D+it/2),-(N+x/2)));const gt=Mt?((ft=e.hoverStyle)==null?void 0:ft.scale)??1:bt?((xt=e.activeStyle)==null?void 0:xt.scale)??1:1;if(gt!==1&&(t.translate(D+it/2,N+x/2),t.scale(gt,gt),t.translate(-(D+it/2),-(N+x/2))),bt){const vt=((At=e.activeStyle)==null?void 0:At.itemBackgroundColor)||e.activeBackgroundColor||(m?"rgba(255, 255, 255, 0.15)":"rgba(0, 0, 0, 0.1)"),Xt=this.createCanvasFill(t,vt,it,x);t.fillStyle=Xt||(typeof vt=="string"?vt:"transparent"),t.beginPath(),this.drawCustomShape(t,e.activeItemShape||e.itemShape||"rectangle",e.activeItemShape==="custom"?e.activeItemPath||"":e.itemPath||"",D,N,it,x,e.itemCornerRadius??0)||t.fill()}else if(Mt){const vt=((Pt=e.hoverStyle)==null?void 0:Pt.itemBackgroundColor)||e.hoverBackgroundColor||(m?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)"),Xt=this.createCanvasFill(t,vt,it,x);t.fillStyle=Xt||(typeof vt=="string"?vt:"transparent"),t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",D,N,it,x,e.itemCornerRadius??0)||t.fill()}else if(S!=="transparent"){const vt=this.createCanvasFill(t,S,it,x);t.fillStyle=vt||(typeof S=="string"?S:"transparent"),t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",D,N,it,x,e.itemCornerRadius??0)||t.fill()}if(wt>0&&e.itemBorderColor&&e.itemBorderColor!=="transparent"){const vt=this.createCanvasFill(t,e.itemBorderColor,it,x);t.strokeStyle=vt||(typeof e.itemBorderColor=="string"?e.itemBorderColor:"#cccccc"),t.lineWidth=wt,t.beginPath(),this.drawCustomShape(t,e.itemShape||"rectangle",e.itemPath||"",D,N,it,x,e.itemCornerRadius??0)||t.stroke()}if(bt){const vt=this.createCanvasFill(t,l,d==="vertical"?3:it,d==="vertical"?x:3);t.fillStyle=vt||l,d==="vertical"?t.fillRect(D,N,3,x):t.fillRect(D,N+x-3,it,3)}const It=bt?"#ffffff":m?"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}`,Ot=D+(d==="vertical"?16:it/2),Wt=N+x/2;d==="horizontal"||j==="circular"?t.textAlign="center":t.textAlign="left";const q=j==="circular"?D+it/2:Ot;t.fillText(ut,q,Wt),t.restore(),t.beginPath(),k+=(d==="vertical"?g: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"?g:h)+Math.max(0,(p.length||0)-1)*u+J*2,it=d==="vertical"?i:n,x=e.listLayout||"linear",D=e.containerShape==="circle"||x==="circular",N=e.scrollbarColor||"rgba(255,255,255,0.3)";let ct=typeof N=="object"?N.color||((Y=(U=N.stops)==null?void 0:U[0])==null?void 0:Y.color)||"rgba(255,255,255,0.3)":N;const Mt=((ot=(X=this.artboard)==null?void 0:X.tokens)==null?void 0:ot.colors)||{};Mt[ct]&&(ct=Mt[ct]);const bt=e.scrollbarWidth||2;if(t.save(),D){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(),x==="circular"){const ut=Math.PI/4,Ot=-(f*.01)-Math.PI/2;t.arc(gt,It,wt,Ot,Ot+ut)}else{const ut=Math.PI/2,Ot=j>0?Math.min(1,it/j):1,Wt=ut*Ot,q=j>0?-f/j*ut:0,xt=-Math.PI/4+q;t.arc(gt,It,wt,xt,xt+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,Ot=j-it;gt=Ot>0?Math.max(0,Math.min(ut,-f/Ot*ut)):0}if(t.fillStyle=ct,d==="vertical"){const It=a+n-bt-2,ut=r+gt,Ot=bt,Wt=wt;if(bt>2){t.beginPath();const q=Math.min(bt/2,wt/2);if(t.roundRect)try{t.roundRect(It,ut,Ot,Wt,q),t.fill()}catch{t.fillRect(It,ut,Ot,Wt)}else t.fillRect(It,ut,Ot,Wt)}else t.fillRect(It,ut,Ot,Wt)}else{const It=a+gt,ut=r+i-bt-2,Ot=wt,Wt=bt;if(bt>2){t.beginPath();const q=Math.min(bt/2,wt/2);if(t.roundRect)try{t.roundRect(It,ut,Ot,Wt,q),t.fill()}catch{t.fillRect(It,ut,Ot,Wt)}else t.fillRect(It,ut,Ot,Wt)}else t.fillRect(It,ut,Ot,Wt)}}t.restore()}t.beginPath(),t.restore()}drawCustomShape(t,s,o,e,n,i,a,r){if(s==="circle"){const c=Math.min(i,a)/2;return t.arc(e+i/2,n+a/2,c,0,Math.PI*2),!1}else if(s==="pill"){const c=Math.min(i,a)/2;return this.drawListViewRect(t,e,n,i,a,c),!1}else if(s==="custom"&&o)try{const c=new Path2D(o);return t.save(),t.translate(e,n),t.scale(i/100,a/100),t.fill(c),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),c=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,g=(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)*c+h*2,m=e==="vertical"?g:u,l=Math.max(0,v-m);if(this.draggingListViewIsScrollbar&&o.listLayout!=="circular"){const I=v>0?m/v:1,_=Math.max(16,m*I),E=Math.max(1,m-_),P=l>0?l/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<-l&&(a=-l),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,c=n.orientation||"vertical",d=n.itemGap??10,p=n.itemHeight??50,u=n.itemWidth??200,g=n.scrollOffset??0,h=n.padding??0,f=this.getWorldTransform(t.id),v=s-f.x,m=o-f.y,l=-f.rotation*(Math.PI/180),b=Math.cos(l),S=Math.sin(l),w=v*b-m*S,C=v*S+m*b,M=-a/2,I=-r/2,_=typeof h=="number"?h:c==="vertical"?h[0]:h[3];let E=(c==="vertical"?I:M)+g+_;const P=n.listLayout||"linear",L=i.length||1,k=Math.PI*2/L,A=n.circularStartAngle||0,T=n.circularRadius||100,R=g*.01+A*Math.PI/180;for(let W=0;W<i.length;W++){const V=P==="circular"?u:c==="vertical"?a:u,U=P==="circular"||c==="vertical"?p:r;let Y=0,X=0,ot=0;if(P==="circular"){const J=W*k+R,at=M+a/2,j=I+r/2;Y=at+Math.cos(J)*T-V/2,X=j+Math.sin(J)*T-U/2,ot=J+(n.itemRotation||0)*Math.PI/180}else Y=c==="vertical"?M:E,X=c==="vertical"?E:I,ot=(n.itemRotation||0)*Math.PI/180;if(ot!==0){const J=Y+V/2,at=X+U/2,j=w-J,it=C-at,x=-ot,D=j*Math.cos(x)-it*Math.sin(x)+J,N=j*Math.sin(x)+it*Math.cos(x)+at;if(D>=Y&&D<=Y+V&&N>=X&&N<=X+U)return W}else if(w>=Y&&w<=Y+V&&C>=X&&C<=X+U)return W;E+=(c==="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,g,h,f,v,m,l,b,S,w,C,M,I,_,E,P,L,k,A,T,R,F,O,W,V,U,Y,X,ot,J,at,j,it,x,D,N,ct,Mt,bt,wt,gt,It,ut,Ot,Wt,q,ft,xt,At,Pt,vt,Xt,zt,Gt,Yt,te,ie,ce,ve,_e,ge,Ee,Zt,Me,Re,Ie,de,me,Ae,he,mt,rt,z,K,G,B,Q,H,lt,kt,Et,Ht,Ut,qt,$,dt,Lt,Nt,st,yt,St,ee,Ct,Vt,Tt,Dt,Rt,le,fe,Oe,jt,oe,ne,Fe,xe,Be,We,Ye,Xe,Ge,se,ue,Se,De,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 c=n.x-s,d=n.y-o,p=Math.sqrt(c*c+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=((g=i.settings)==null?void 0:g.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,c,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=c*et*nt,Ft=d*et*nt;n.x-=pt*t*10,n.y-=Ft*t*10}}else if(i.type===tt.Repel){const Z=((v=i.settings)==null?void 0:v.radius)||300,nt=((m=i.settings)==null?void 0:m.strength)||1;if(p<Z){const et=Math.pow(1-p/Z,2);n.x+=c/(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=((l=i.settings)==null?void 0:l.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),Ft=this.currentTime*nt*Math.PI*2,Bt=Math.cos(Ft)*30-c*.4,Jt=Math.sin(Ft)*30-d*.4;n.x+=Bt*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=c/(p||1)*et*1.2*nt,Ft=d/(p||1)*et*1.2*nt;n.x+=pt*10*t*5,n.y+=Ft*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-=c*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,Ft=this._lastPointerPos||{x:et,y:pt},Bt=(Ft.x-et)/et,Jt=(Ft.y-pt)/pt,pe=(((O=e.transform)==null?void 0:O.x)??0)+Bt*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)+Bt*Z*1.5*nt,Le=Math.min(1,10*t);n.x=this.lerp(n.x??((Y=e.transform)==null?void 0:Y.x)??0,pe,Le),n.y=this.lerp(n.y??((X=e.transform)==null?void 0:X.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=(c>0?-1:1)*Z*10,et=1-Z*.1,pt=d/300*Z*20,Ft=-(c/300)*Z*20,Bt=Math.min(1,10*t);n.skew_x=this.lerp(n.skew_x??((at=e.transform)==null?void 0:at.skew_x)??0,nt,Bt),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,Bt),n.rotate_x=this.lerp(n.rotate_x??((x=e.transform)==null?void 0:x.rotate_x)??0,pt,Bt),n.rotate_y=this.lerp(n.rotate_y??((D=e.transform)==null?void 0:D.rotate_y)??0,Ft,Bt),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=((Ot=i.settings)==null?void 0:Ot.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,((xt=e.transform)==null?void 0:xt.scale_x)??1,.2))}else if(i.type===tt.TextCounter){const Z=((At=i.settings)==null?void 0:At.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,Ft=Math.min(1,pt/Z),Bt=Math.floor(nt+(et-nt)*Ft);if(((Xt=e.geometry)==null?void 0:Xt.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}${Bt}${pe}`}}else if(i.type===tt.Spotlight){const Z=((Yt=i.settings)==null?void 0:Yt.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,c,d,p),this.applyBehaviorSensor(n,re.PositionY,pt*et,t,i.settings,e,c,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=((B=i.settings)==null?void 0:B.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,-c)*(180/Math.PI),pt=n.rotation,Ft=(et-pt+180)%360-180;n.rotation+=Ft*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:((Et=i.settings)==null?void 0:Et.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=((Lt=i.settings)==null?void 0:Lt.stiffness)||.1,pt=nt.x-n.x,Ft=nt.y-n.y;n.x+=pt*et*t*60,n.y+=Ft*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=((Dt=i.settings)==null?void 0:Dt.strength)||.5;if(p<Z){const et=Math.pow(1-p/Z,2);n.scale_x=this.lerp(n.scale_x??1,(((Rt=e.transform)==null?void 0:Rt.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 Ft=this.getObjectProperty(n,e,pt);if(Ft===void 0)continue;const Bt=et.get(pt);if(!Bt)et.set(pt,{from:Ft,to:Ft,startTime:this.currentTime,duration:0});else if(Bt.to!==Ft){const pe=this.getObjectProperty(n,e,pt);et.set(pt,{from:pe??Bt.from,to:Ft,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=((xe=i.settings)==null?void 0:xe.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 Ft=this.getObjectProperty(n,e,pt);if(Ft===void 0||typeof Ft!="number")continue;const Bt=Z.get(pt);if(!Bt)Z.set(pt,{from:Ft,to:Ft,startTime:this.currentTime,duration:0});else if(Bt.to!==Ft){const pe=this.getObjectProperty(n,e,pt);Z.set(pt,{from:pe??Bt.from,to:Ft,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,((Be=i.settings)==null?void 0:Be.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=((Ye=i.settings)==null?void 0:Ye.globalDamping)||.3;this._springChainState.has(e.id)||this._springChainState.set(e.id,new Map);const et=this._springChainState.get(e.id);for(const Ft of Z){if(!et.has(Ft.targetId)){const Bt=this.objectStates.get(Ft.targetId);et.set(Ft.targetId,{x:(Bt==null?void 0:Bt.x)??0,y:(Bt==null?void 0:Bt.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 Ft of Z){const Bt=et.get(Ft.targetId);if(!Bt)continue;const Jt=Bt.x-pt.x,pe=Bt.y-pt.y,Te=Math.sqrt(Jt*Jt+pe*pe)||.001,ye=(Te-(Ft.restLength||50))*(Ft.stiffness||.8),Le=Jt/Te*ye,Qe=pe/Te*ye;pt.vx+=Le*t*10,pt.vy+=Qe*t*10,Bt.vx-=Le*t*10,Bt.vy-=Qe*t*10,pt.vx*=1-nt*t*10,pt.vy*=1-nt*t*10,Bt.vx*=1-nt*t*10,Bt.vy*=1-nt*t*10;const Pe=this.objectStates.get(Ft.targetId);Pe&&(Pe.x+=Bt.vx*t,Pe.y+=Bt.vy*t)}n.x+=pt.vx*t,n.y+=pt.vy*t}}else if(i.type===tt.ParticleEmitter){const Z=((Xe=i.settings)==null?void 0:Xe.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,Ft=((Se=i.settings)==null?void 0:Se.gravity)||0,Bt=((De=i.settings)==null?void 0:De.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)??Ft:Ft,$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:Bt,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,c=1){var h,f,v,m,l,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=c>0?a/c:0,g=c>0?r/c:0;switch(s){case re.Scale:{const Y=((h=i==null?void 0:i.transform)==null?void 0:h.scale_x)??1,X=((f=i==null?void 0:i.transform)==null?void 0:f.scale_y)??1,ot=Y*(1+o*d*.4),J=X*(1+o*d*.4);t.scale_x=(t.scale_x??Y)*(1-p)+ot*p,t.scale_y=(t.scale_y??X)*(1-p)+J*p;break}case re.Opacity:{const Y=((v=i==null?void 0:i.transform)==null?void 0:v.opacity)??100,X=Math.max(0,Math.min(100,Y-o*d*100));t.opacity=(t.opacity??Y)*(1-p)+X*p;break}case re.RotateZ:{const Y=((m=i==null?void 0:i.transform)==null?void 0:m.rotation)??0,X=Y+o*d*45;t.rotation=(t.rotation??Y)*(1-p)+X*p;break}case re.RotateX:{const Y=((l=i==null?void 0:i.transform)==null?void 0:l.rotate_x)??0,X=Y-g*o*d*60;t.rotate_x=(t.rotate_x??Y)*(1-p)+X*p;break}case re.RotateY:{const Y=((b=i==null?void 0:i.transform)==null?void 0:b.rotate_y)??0,X=Y+u*o*d*60;t.rotate_y=(t.rotate_y??Y)*(1-p)+X*p;break}case re.PositionX:{const Y=((S=i==null?void 0:i.transform)==null?void 0:S.x)??0,X=Y-u*o*d*40;t.x=(t.x??Y)*(1-p)+X*p;break}case re.PositionY:{const Y=((w=i==null?void 0:i.transform)==null?void 0:w.y)??0,X=Y-g*o*d*40;t.y=(t.y??Y)*(1-p)+X*p;break}case re.SkewX:{const Y=((C=i==null?void 0:i.transform)==null?void 0:C.skew_x)??0,X=Y+u*o*d*45;t.skew_x=(t.skew_x??Y)*(1-p)+X*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 Y=((_=(I=i==null?void 0:i.style)==null?void 0:I.blur)==null?void 0:_.amount)||0,X=Y+o*((n==null?void 0:n.blur)||20)*d;t.style.blur.amount=(t.style.blur.amount??Y)*(1-p)+X*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 Y=((L=(P=i==null?void 0:i.style)==null?void 0:P.adjustments)==null?void 0:L.exposure)||0,X=Y+o*((n==null?void 0:n.exposure)||50)*d;t.style.adjustments.exposure=(t.style.adjustments.exposure??Y)*(1-p)+X*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 Y=((T=(A=i==null?void 0:i.style)==null?void 0:A.adjustments)==null?void 0:T.hue)||0,X=Y+o*((n==null?void 0:n.hue)||180)*d;t.style.adjustments.hue=(t.style.adjustments.hue??Y)*(1-p)+X*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 Y=((O=(F=i==null?void 0:i.style)==null?void 0:F.adjustments)==null?void 0:O.negative)||0,X=Y+o*((n==null?void 0:n.negative)||100)*d;t.style.adjustments.negative=(t.style.adjustments.negative??Y)*(1-p)+X*p;break}case re.CornerRadius:{const Y=((W=i==null?void 0:i.transform)==null?void 0:W.corner_radius)||0,X=Y+o*d*50;t.corner_radius=(t.corner_radius??Y)*(1-p)+X*p;break}case re.StrokeWidth:{t.style||(t.style={...i==null?void 0:i.style});const Y=((V=i==null?void 0:i.style)==null?void 0:V.borderWidth)||0,X=Y+o*d*10;t.style.borderWidth=(t.style.borderWidth??Y)*(1-p)+X*p;break}case re.LetterSpacing:{t.geometry||(t.geometry={});const Y=((U=i==null?void 0:i.geometry)==null?void 0:U.letterSpacing)||0,X=Y+o*d*10;t.geometry.letterSpacing=(t.geometry.letterSpacing??Y)*(1-p)+X*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 c=n[r];if(i[c]===void 0||i[c]===null){const d=s,p=n.slice(0,r+1).reduce((h,f)=>h==null?void 0:h[f],d),u=n[r+1],g=!isNaN(Number(u));i[c]=p!==void 0?Array.isArray(p)?[...p]:{...p}:g?[]:{}}i=i[c]}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,c=(e.tint||0)/200,d=(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||c!==0||d!==0||p!==0||u!==0||g!==0||h>0))return t;const v=t.naturalWidth||Math.max(1,Math.round(s)),m=t.naturalHeight||Math.max(1,Math.round(o)),l=document.createElement("canvas");l.width=v,l.height=m;const b=l.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,m);try{const w=b.getImageData(0,0,v,m),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-c/2,L=1+c,k=1-r-c/2,A=1+d+p,T=p*25.5,R=1-g/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 Y=.2989*W+.587*V+.114*U;W=Y+(W-Y)*E,V=Y+(V-Y)*E,U=Y+(U-Y)*E}(r!==0||c!==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),g!==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),l}catch{return l}}renderFittedImage(t,s,o,e,n,i,a="cover"){const r=s.naturalWidth||s.width||n,c=s.naturalHeight||s.height||i,d=r/c,p=n/i;let u=n,g=i,h=o,f=e;a==="cover"?d>p?(u=i*d,h=o-(u-n)/2):(g=n/d,f=e-(g-i)/2):a==="contain"&&(d>p?(g=n/d,f=e+(i-g)/2):(u=i*d,h=o+(n-u)/2)),t.drawImage(s,h,f,u,g)}}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:c,onToggle:d,onInputChange:p,onInputFocus:u,onInputBlur:g,onLog:h,onLogicUpdate:f,onButtonClick:v,onGraphPointClick:m,currentTime:l,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),Y=$t.useRef(o),X=$t.useRef(l);$t.useEffect(()=>{Y.current=o},[o]),$t.useEffect(()=>{X.current=l},[l]),$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 x=A.current;a&&x.setTriggerCallback(a),r&&x.setInputUpdateCallback((D,N)=>r({[D]:N})),c&&x.setComponentChangeCallback(D=>c(D)),d&&x.setToggleCallback(d),p&&x.setInputChangeCallback(p),u&&x.setInputFocusCallback(u),g&&x.setInputBlurCallback(g),h&&x.setOnLogCallback(D=>h(D,"info")),f&&x.setLogicUpdateCallback(f),v&&x.setButtonClickCallback(v),m&&x.setGraphPointClickCallback(D=>m(D.objectId,D)),P&&x.setNavigationCallback(P)},[a,r,c,d,p,u,g,h,f,v,m,P]),$t.useEffect(()=>{(async()=>{let D=y;if(t&&!y)try{t.startsWith("{")?D=JSON.parse(t):D=await(await fetch(t)).json()}catch(N){console.error("[ExodeUI] Failed to load src:",N)}if(D){const N=A.current,ct=D.id||D.name||"default";(F.current!==ct||O.current!==b||W.current!==D)&&(N.load(D),F.current=ct,O.current=b,W.current=D,V(D),R.current=-1,N.advance(0)),i&&i(N)}})()},[y,t,b]),$t.useEffect(()=>{const x=D=>{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=D/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),Ot=Math.round(gt.height*It);(ct.width!==ut||ct.height!==Ot)&&(ct.width=ut,ct.height=Ot);try{Y.current?N.advance(wt):X.current!==void 0&&N.seek(X.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(x)};return T.current=requestAnimationFrame(x),()=>{T.current&&cancelAnimationFrame(T.current)}},[]),$t.useEffect(()=>{const x=A.current;S!==void 0&&x.updateInput("scrollY",S),w!==void 0&&x.updateInput("scrollX",w),C!==void 0&&x.updateInput("mouseX",C),M!==void 0&&x.updateInput("mouseY",M),I!==void 0&&x.updateInput("isMouseDown",I),_&&Object.entries(_).forEach(([D,N])=>x.updateInput(D,N))},[S,w,C,M,I,_]);const ot=(x,D)=>{if(!E||!k.current)return;x.stopPropagation(),"nativeEvent"in x&&x.nativeEvent&&typeof x.nativeEvent.stopImmediatePropagation=="function"?x.nativeEvent.stopImmediatePropagation():typeof x.stopImmediatePropagation=="function"&&x.stopImmediatePropagation();const N=k.current,ct=N.getBoundingClientRect(),Mt=x.clientX-ct.left,bt=x.clientY-ct.top,wt=window.devicePixelRatio||1;(D==="click"||D==="down"||D==="up")&&h&&h(`[Canvas] Pointer ${D} at rect(${Math.round(Mt)},${Math.round(bt)}) mapped to buffer(${Math.round(Mt*wt)},${Math.round(bt*wt)})`,"info"),A.current.handlePointerInput(D,Mt*wt,bt*wt,N.width,N.height)};$t.useEffect(()=>{if(!E)return;const 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.handleKeyDown(N)},D=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",x),window.addEventListener("keyup",D),()=>{window.removeEventListener("keydown",x),window.removeEventListener("keyup",D)}},[E]),$t.useEffect(()=>{const x=k.current;if(!x||!E)return;const D=N=>{if(N.preventDefault(),N.stopPropagation(),A.current){const ct=x.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,x.width,x.height),A.current.handleWheel(gt,It,bt,wt,x.width,x.height)}};return x.addEventListener("wheel",D,{passive:!1}),()=>{x.removeEventListener("wheel",D)}},[E]);const[J,at]=$t.useState([]);$t.useEffect(()=>{if(y&&y.objects){const x=y.objects.filter(D=>{var N,ct;return D.type==="Joystick"&&((N=D.inputBinding)==null?void 0:N.type)==="keyboard"&&((ct=D.inputBinding.keyboardConfig)==null?void 0:ct.showVirtualKeyboard)});at(x)}},[y]);const[,j]=$t.useState(0);$t.useEffect(()=>{if(J.length===0)return;let x;const D=()=>{j(N=>N+1),x=requestAnimationFrame(D)};return x=requestAnimationFrame(D),()=>cancelAnimationFrame(x)},[J.length]);const it=()=>J.map(x=>{const D=x.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(D.upKey)),onMouseDown:()=>N(D.upKey),onMouseUp:()=>ct(D.upKey),onMouseLeave:()=>ct(D.upKey),onTouchStart:gt=>{gt.preventDefault(),N(D.upKey)},onTouchEnd:gt=>{gt.preventDefault(),ct(D.upKey)},children:D.upKey.toUpperCase()}),Qt.jsxs("div",{style:{display:"flex",gap:"8px"},children:[Qt.jsx("div",{style:wt(bt(D.leftKey)),onMouseDown:()=>N(D.leftKey),onMouseUp:()=>ct(D.leftKey),onMouseLeave:()=>ct(D.leftKey),onTouchStart:gt=>{gt.preventDefault(),N(D.leftKey)},onTouchEnd:gt=>{gt.preventDefault(),ct(D.leftKey)},children:D.leftKey.toUpperCase()}),Qt.jsx("div",{style:wt(bt(D.downKey)),onMouseDown:()=>N(D.downKey),onMouseUp:()=>ct(D.downKey),onMouseLeave:()=>ct(D.downKey),onTouchStart:gt=>{gt.preventDefault(),N(D.downKey)},onTouchEnd:gt=>{gt.preventDefault(),ct(D.downKey)},children:D.downKey.toUpperCase()}),Qt.jsx("div",{style:wt(bt(D.rightKey)),onMouseDown:()=>N(D.rightKey),onMouseUp:()=>ct(D.rightKey),onMouseLeave:()=>ct(D.rightKey),onTouchStart:gt=>{gt.preventDefault(),N(D.rightKey)},onTouchEnd:gt=>{gt.preventDefault(),ct(D.rightKey)},children:D.rightKey.toUpperCase()})]})]},x.id)});return Qt.jsxs("div",{style:{position:"relative",width:"100%",height:"100%"},children:[Qt.jsx("canvas",{ref:k,onPointerDown:x=>{var D;ot(x,"down"),x.currentTarget.setPointerCapture(x.pointerId),(D=k.current)==null||D.focus()},onPointerMove:x=>ot(x,"move"),onPointerUp:x=>{ot(x,"up"),x.currentTarget.releasePointerCapture(x.pointerId)},onPointerCancel:x=>{ot(x,"up"),x.currentTarget.releasePointerCapture(x.pointerId)},onClick:x=>ot(x,"click"),onKeyDown:x=>A.current.handleKeyDown(x.nativeEvent),onKeyUp:x=>A.current.handleKeyUp(x.nativeEvent),onContextMenu:x=>x.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((u,g)=>{y==null||y.setInputBool(u,g)},[y]),o=$t.useCallback((u,g)=>{y==null||y.setInputNumber(u,g)},[y]),e=$t.useCallback(u=>{y==null||y.fireTrigger(u)},[y]),n=$t.useCallback((u,g)=>{y==null||y.setInputText(u,g)},[y]),i=$t.useCallback((u,g)=>{y==null||y.setInputNumberArray(u,g)},[y]),a=$t.useCallback((u,g)=>{y==null||y.setInputStringArray(u,g)},[y]),r=$t.useCallback((u,g)=>{y==null||y.updateObjectOptions(u,g)},[y]),c=$t.useCallback((u,g,h)=>{y==null||y.updateConstraint(u,g,h)},[y]),d=$t.useCallback((u,g)=>{y==null||y.updateGraphData(u,g)},[y]),p=$t.useCallback(u=>y==null?void 0:y.getInputValue(u),[y]);return{setEngine:t,engine:y,setInputBool:s,setInputNumber:o,fireTrigger:e,setInputText:n,setInputNumberArray:i,setInputStringArray:a,updateConstraint:c,updateGraphData:d,updateObjectOptions:r,getInputValue:p}}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 g;return((g=u.geometry)==null?void 0:g.type)==="Text"}).sort((u,g)=>{var h,f;return(((h=g.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 c=s.ogImage||y.backgroundImage;c&&e("property","og:image",c),a&&e("property","og:title",a),e("property","og:type","website")},[s,y,o]);const e=(a,r,c)=>{let d=document.querySelector(`meta[${a}="${r}"]`);d||(d=document.createElement("meta"),d.setAttribute(a,r),document.head.appendChild(d)),d.setAttribute("content",c)},n=()=>{const a=[];return a.push(Qt.jsx("h1",{children:s.title||y.name},"artboard-title")),y.objects.forEach((c,d)=>{var p,u;if(!(c.visible===!1||c.isVisible===!1))if(((p=c.geometry)==null?void 0:p.type)==="Text"){const g=c.geometry.text;g&&(c.geometry.fontSize>24?a.push(Qt.jsx("h2",{children:g},c.id||d)):a.push(Qt.jsx("p",{children:g},c.id||d)))}else if(((u=c.geometry)==null?void 0:u.type)==="Image"){const g=c.geometry.src,h=c.altText||c.name||"Illustration";a.push(Qt.jsx("img",{src:g,alt:h},c.id||d))}else c.type==="Button"&&a.push(Qt.jsx("button",{children:c.name||"Button"},c.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.0"}.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=_t,Kt.RapierPhysics=is,Kt.VERSION=ci,Kt.useExodeUI=ri,Object.defineProperty(Kt,Symbol.toStringTag,{value:"Module"})}));
|