exodeui 6.3.21 → 6.3.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +33 -31
- package/dist/index.mjs +1700 -1632
- package/dist/src/index.d.ts +1 -0
- package/dist/src/physics/PhysicsEngine.d.ts +25 -0
- package/dist/src/physics/RapierPhysics.d.ts +15 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,32 +1,34 @@
|
|
|
1
|
-
(function(
|
|
2
|
-
`||Q==="\r"?y.kinds[
|
|
1
|
+
(function(Nt,se){typeof exports=="object"&&typeof module<"u"?se(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"],se):(Nt=typeof globalThis<"u"?globalThis:Nt||self,se(Nt.ExodeUIReact={},Nt.jsxRuntime,Nt.React,Nt.pretext,Nt.Rapier,Nt.LZString))})(this,function(Nt,se,Wt,xe,ne,bs){"use strict";var li=Object.defineProperty;var ci=(Nt,se,Wt)=>se in Nt?li(Nt,se,{enumerable:!0,configurable:!0,writable:!0,value:Wt}):Nt[se]=Wt;var K=(Nt,se,Wt)=>ci(Nt,typeof se!="symbol"?se+"":se,Wt);function vs(u){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(u){for(const s in u)if(s!=="default"){const o=Object.getOwnPropertyDescriptor(u,s);Object.defineProperty(t,s,o.get?o:{enumerable:!0,get:()=>u[s]})}}return t.default=u,Object.freeze(t)}const Cs=vs(bs);var X=(u=>(u.Proximity="Proximity",u.Magnetic="Magnetic",u.Repel="Repel",u.Orbit="Orbit",u.Vortex="Vortex",u.Fluid="Fluid",u.Elastic="Elastic",u.Holographic="Holographic",u.Sticky="Sticky",u.Dilation="Dilation",u.Parallax="Parallax",u.Noise="Noise",u.Float="Float",u.Pulse="Pulse",u.Draggable="Draggable",u.Scroll="Scroll",u.LookAt="LookAt",u.Glint="Glint",u.Scan="Scan",u.Ratchet="Ratchet",u.Jitter="Jitter",u.Follower="Follower",u.Wrap="Wrap",u.Typewriter="Typewriter",u.Scramble="Scramble",u.Wave="Wave",u.Bounce="Bounce",u.TextTrail="TextTrail",u.Reveal3D="Reveal3D",u.RevealSlide="RevealSlide",u.RevealBlur="RevealBlur",u.TextLiquid="TextLiquid",u.TextVortex="TextVortex",u.TextExplosion="TextExplosion",u.TextRain="TextRain",u.TextGravity="TextGravity",u.TextMatrix="TextMatrix",u.TextNeon="TextNeon",u.TextDissolve="TextDissolve",u.TextOrganic="TextOrganic",u.TextBreathe="TextBreathe",u.TextSpin="TextSpin",u.TextMagnet="TextMagnet",u.TextPerspective="TextPerspective",u.TextMirror="TextMirror",u.TextFloral="TextFloral",u.TextSmoke="TextSmoke",u.TextVariable="TextVariable",u.TextZing="TextZing",u.TextElastic="TextElastic",u.TextGlitch3D="TextGlitch3D",u.GlitchText="GlitchText",u.TextCounter="TextCounter",u.Squash="Squash",u.Spotlight="Spotlight",u.Lens="Lens",u.Gravity="Gravity",u.Velocity="Velocity",u.Shear="Shear",u.LayoutAnimation="LayoutAnimation",u.SpringChain="SpringChain",u.ParticleEmitter="ParticleEmitter",u.StateReactive="StateReactive",u.Fold="Fold",u.Crumple="Crumple",u))(X||{}),oe=(u=>(u.Scale="Scale",u.Opacity="Opacity",u.RotateZ="RotateZ",u.RotateX="RotateX",u.RotateY="RotateY",u.PositionX="PositionX",u.PositionY="PositionY",u.SkewX="SkewX",u.Blur="Blur",u.Exposure="Exposure",u.HueShift="HueShift",u.Negative="Negative",u.CornerRadius="CornerRadius",u.StrokeWidth="StrokeWidth",u.BoxShadow="BoxShadow",u.FontSize="FontSize",u.LetterSpacing="LetterSpacing",u))(oe||{}),Ge=(u=>(u.Equal="Equal",u.NotEqual="NotEqual",u.GreaterThan="GreaterThan",u.LessThan="LessThan",u.GreaterEqual="GreaterEqual",u.LessEqual="LessEqual",u.IsTrue="IsTrue",u.IsFalse="IsFalse",u))(Ge||{}),bt=(u=>(u.AND="AND",u.OR="OR",u.NOT="NOT",u.XOR="XOR",u.OBJECT="OBJECT",u.PROPERTY="PROPERTY",u.GET_PROPERTY="GET_PROPERTY",u.SET_PROPERTY="SET_PROPERTY",u.ADD="ADD",u.SUB="SUB",u.MUL="MUL",u.DIV="DIV",u.MOD="MOD",u.POW="POW",u.ABS="ABS",u.ROUND="ROUND",u.FLOOR="FLOOR",u.CEIL="CEIL",u.SIN="SIN",u.COS="COS",u.TAN="TAN",u.CLAMP="CLAMP",u.REMAP="REMAP",u.EQ="EQ",u.NEQ="NEQ",u.GT="GT",u.LT="LT",u.GTE="GTE",u.LTE="LTE",u.IF_ELSE="IF_ELSE",u.VALUE="VALUE",u.INPUT="INPUT",u.LOG="LOG",u.SCROLL_X="SCROLL_X",u.SCROLL_Y="SCROLL_Y",u.MOUSE_X="MOUSE_X",u.MOUSE_Y="MOUSE_Y",u.IS_MOUSE_DOWN="IS_MOUSE_DOWN",u.EFFECTOR="EFFECTOR",u.MONITOR="MONITOR",u.DELAY="DELAY",u.SPRING_PULL="SPRING_PULL",u.SPRING_SETTLE="SPRING_SETTLE",u.EMIT="EMIT",u))(bt||{});function Ss(u){if(u.length<5)return u;const t=new Set("aeiouyAEIOUY".split(""));if(/[\u4E00-\u9FFF\u3400-\u4DBF]/.test(u))return u;let o="";for(let e=0;e<u.length;e++){if(o+=u[e],e>=u.length-2)continue;const i=t.has(u[e]),n=t.has(u[e+1]),a=t.has(u[e+2]);i&&!n&&a&&(o+=""),i&&!n&&!a&&e>=1&&(o+="")}return o}function ws(u){return u.replace(/\b([a-zA-Z]{4,})\b/g,(t,s)=>Ss(s))}function Is(u,t,s){return u}function Ms(u,t,s){return u}const ke=new Map;function De(u){var M;const{text:t,fontFamily:s="Inter",fontSize:o=16,fontWeight:e=400,fontStyle:i="normal",lineHeight:n=1.2,width:a=200,letterSpacing:r=0,paragraphSpacing:l=0,paragraphIndent:h=0,textCase:c="none",segments:g=[],enableSegments:f=!1}=u;let d=String(t||"");c==="uppercase"?d=d.toUpperCase():c==="lowercase"?d=d.toLowerCase():c==="capitalize"&&(d=d.replace(/\b\w/g,P=>P.toUpperCase())),u.hyphenation===!0&&(d=ws(d));const p=`${i} ${e} ${o}px "${s}", sans-serif`,m=`${d}|${p}|${r}|${l}|${h}|${f}|${JSON.stringify(g)}|hyp:${!!u.hyphenation}|comp:${u.composer}|bal:${!!u.balanceRaggedLines}`;let y=ke.get(m);const v=typeof CanvasRenderingContext2D<"u"?CanvasRenderingContext2D.prototype.measureText:null,b=function(P){if(!v)return{width:0,fontBoundingBoxAscent:0,fontBoundingBoxDescent:0};const T=v.call(this,P);return r!==0&&P&&P.length>0?{...T,width:T.width+(P.length-1)*r}:T};if(!y){try{if(r!==0&&typeof CanvasRenderingContext2D<"u"&&(CanvasRenderingContext2D.prototype.measureText=b),f&&g&&g.length>0){const P=g.map(T=>{let $=T.text||"";const k=T.textCase||c||"none";return k==="uppercase"?$.toUpperCase():k==="lowercase"?$.toLowerCase():k==="capitalize"?$.replace(/\b\w/g,E=>E.toUpperCase()):$}).join("");if(y=xe.prepareWithSegments(P,p),y){let T=0,$=o;for(const k of g){let E=k.text||"";if(!E)continue;const F=k.textCase||c||"none";F==="uppercase"?E=E.toUpperCase():F==="lowercase"?E=E.toLowerCase():F==="capitalize"&&(E=E.replace(/\b\w/g,x=>x.toUpperCase()));const O=k.fontSize||o;O>$&&($=O);const A=`${k.fontStyle||i} ${k.fontWeight||e} ${O}px "${k.fontFamily||s}", sans-serif`,W=xe.prepareWithSegments(E,A);if(W&&W.widths)for(let x=0;x<W.widths.length;x++){const B=T+x;if(B<y.widths.length){y.widths[B]=W.widths[x];const N=W.kinds[x];if(N===2){const Q=E[x];Q===`
|
|
2
|
+
`||Q==="\r"?y.kinds[B]=2:y.kinds[B]=0}else y.kinds[B]=N}}T+=E.length}y.fullText=P,y.maxFontSize=$}}else y=xe.prepareWithSegments(d,p);y&&ke.set(m,y)}catch(P){return console.error("[ExodeUI] Pretext prepare failed:",P),{width:a,height:0,lineCount:0,lines:[]}}finally{r!==0&&typeof CanvasRenderingContext2D<"u"&&v&&(CanvasRenderingContext2D.prototype.measureText=v)}if(ke.size>500){const P=ke.keys().next().value;P&&ke.delete(P)}}if(h>0&&y&&y.widths&&!y.indentApplied){const P=[...y.widths],T=y.fullText||d;let $=!0;for(let k=0;k<T.length;k++)$&&P[k]!==void 0&&(P[k]+=h,$=!1),(T[k]===`
|
|
3
3
|
`||T[k]==="\r")&&($=!0,T[k]==="\r"&&T[k+1]===`
|
|
4
|
-
`&&k++);y={...y,widths:
|
|
5
|
-
`||T[
|
|
6
|
-
`&&_++)}let w=(S==null?void 0:S.lines)||[];return u.composer==="every-line"&&w.length>1&&(w=Is(w)),u.balanceRaggedLines===!0&&w.length>1&&(w=ws(w)),{width:a,height:I,lineCount:w.length,lines:w}}function ze(u,t,s){let o=String(u||"").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,l)=>{if(r.endsWith("px")){const h=parseFloat(r);i[l]=h,n-=h}else r.endsWith("fr")?a+=parseFloat(r):r==="auto"&&(i[l]=100,n-=100)}),a>0&&n>0){const r=n/a;e.forEach((l,h)=>{l.endsWith("fr")&&(i[h]=r*parseFloat(l))})}return i}function Ve(u,t,s){try{const o=u.autoLayout;return!o||!o.enabled?{childUpdates:[]}:(o.mode||"linear")==="grid"?ks(u,t,s):Ms(u,t,s)}catch(o){return console.error("Layout Engine Error:",o),{childUpdates:[]}}}function Ms(u,t,s){var E,L;const o=u.autoLayout,{direction:e,spacing:i,padding:n,align:a,wrap:r}=o,l=e==="vertical",h=t.map(O=>{const A=s(O.id),W=O.geometry;let x=(A==null?void 0:A.width)??W.width??100,Y=(A==null?void 0:A.height)??W.height??100;if(W.type==="Ellipse"||W.type==="Polygon"||W.type==="Star"){const H=(A==null?void 0:A.radius)??W.radius??(A==null?void 0:A.outer_radius)??W.outer_radius??50;x=H*2,Y=H*2}else if(W.type==="Text"){const H=De({text:(A==null?void 0:A.text)??W.text??"",fontFamily:W.fontFamily,fontSize:W.fontSize,fontWeight:W.fontWeight,fontStyle:W.fontStyle,lineHeight:W.lineHeight,width:W.width||200,letterSpacing:W.letterSpacing,paragraphSpacing:W.paragraphSpacing,paragraphIndent:W.paragraphIndent,textCase:W.textCase,segments:W.segments,enableSegments:W.enableSegments});Y=H.height,W.width||(x=H.width)}return x*=O.transform.scale_x||1,Y*=O.transform.scale_y||1,{id:O.id,w:x,h:Y,original:O}});let c=u.width,g=u.height;const f=((E=u.layoutProps)==null?void 0:E.width)==="hug",d=((L=u.layoutProps)==null?void 0:L.height)==="hug",p=[];let m=[],y=0,v=0;const b=c-n.left-n.right,C=g-n.top-n.bottom;h.forEach(O=>{r&&m.length>0&&(l?v+i+O.h>C:y+i+O.w>b)?(p.push({children:m,width:y,height:v}),m=[O],y=O.w,v=O.h):(m.push(O),l?(y=Math.max(y,O.w),v+=(m.length>1?i:0)+O.h):(y+=(m.length>1?i:0)+O.w,v=Math.max(v,O.h)))}),m.length>0&&p.push({children:m,width:y,height:v}),f&&!l&&(c=Math.max(...p.map(O=>O.width),0)+n.left+n.right),d&&l&&(g=Math.max(...p.map(O=>O.height),0)+n.top+n.bottom);const S=[];let I=n.left,w=n.top;const M=a.toLowerCase(),_=M==="center"||M.endsWith("-center"),T=M.endsWith("-right"),$=M==="center"||M.startsWith("center-"),k=M.startsWith("bottom-");return p.forEach(O=>{let A=I,W=w;l?$?W=n.top+(g-n.top-n.bottom-O.height)/2:k&&(W=g-n.bottom-O.height):_?A=n.left+(c-n.left-n.right-O.width)/2:T&&(A=c-n.right-O.width),O.children.forEach(x=>{var F,U;let Y=A,H=W;l?_?Y+=(O.width-x.w)/2:T&&(Y+=O.width-x.w):$?H+=(O.height-x.h)/2:k&&(H+=O.height-x.h);const Q=((F=x.original.layoutProps)==null?void 0:F.width)==="fill",P=((U=x.original.layoutProps)==null?void 0:U.height)==="fill";S.push({id:x.id,x:Y+x.w/2-c/2,y:H+x.h/2-g/2,width:Q&&l?O.width:void 0,height:P?l?void 0:O.height:void 0}),l?W+=x.h+i:A+=x.w+i}),l?I+=O.width+i:w+=O.height+i}),{frameWidth:f?c:void 0,frameHeight:d?g:void 0,childUpdates:S}}function ks(u,t,s){const o=u.autoLayout;if(!o)return{childUpdates:[]};const{gridColumns:e,gridRows:i,columnGap:n=0,rowGap:a=0,padding:r,align:l}=o;let h=u.width,c=u.height;const g=h-r.left-r.right,f=c-r.top-r.bottom,d=ze(e||"1fr",g,n),p=ze(i||"auto",f,a),m=d.length>0?d.reduce((T,$)=>T+$,0)+(d.length-1)*n:0,y=p.length>0?p.reduce((T,$)=>T+$,0)+(p.length-1)*a:0,v=l.toLowerCase(),b=v==="center"||v.endsWith("-center"),C=v.endsWith("-right"),S=v==="center"||v.startsWith("center-"),I=v.startsWith("bottom-");let w=0,M=0;b?w=(g-m)/2:C&&(w=g-m),S?M=(f-y)/2:I&&(M=f-y);const _=[];return t.forEach((T,$)=>{var U,J;const k=$%d.length||0,E=Math.floor($/d.length)||0;E>=p.length&&p.push(100);const L=d[k],O=p[E];let A=r.left+w+d.slice(0,k).reduce((it,dt)=>it+dt+n,0),W=r.top+M+p.slice(0,E).reduce((it,dt)=>it+dt+a,0);const x=s(T.id),Y=T.geometry;let H=(x==null?void 0:x.width)??Y.width??100,Q=(x==null?void 0:x.height)??Y.height??100;if(Y.type==="Ellipse"||Y.type==="Polygon"||Y.type==="Star"){const it=(x==null?void 0:x.radius)??Y.radius??(x==null?void 0:x.outer_radius)??Y.outer_radius??50;H=it*2,Q=it*2}H*=T.transform.scale_x||1,Q*=T.transform.scale_y||1;let P=A,F=W;b?P+=(L-H)/2:C&&(P+=L-H),S?F+=(O-Q)/2:I&&(F+=O-Q),_.push({id:T.id,x:P+H/2-h/2,y:F+Q/2-c/2,width:((U=T.layoutProps)==null?void 0:U.width)==="fill"?L:void 0,height:((J=T.layoutProps)==null?void 0:J.height)==="fill"?O:void 0})}),{childUpdates:_}}class Ts{constructor(){et(this,"world",null);et(this,"bodies",new Map);et(this,"colliders",new Map);et(this,"initialized",!1)}async init(t){this.initialized||(await le.init(),this.world=new le.World(new le.Vector2(t.x,t.y)),this.initialized=!0)}destroy(){this.bodies.clear(),this.colliders.clear(),this.world&&(this.world.free(),this.world=null),this.initialized=!1}createBody(t){if(!this.world){console.warn("[RapierPhysics] World not initialized");return}this.bodies.has(t.id)&&this.removeBody(t.id);const s=t.isStatic?le.RigidBodyDesc.fixed():le.RigidBodyDesc.dynamic();s.setTranslation(t.x,t.y),t.rotation!==void 0&&s.setRotation(t.rotation);const o=this.world.createRigidBody(s);let e;switch(t.type){case"Rectangle":e=le.ColliderDesc.cuboid(t.width/2,t.height/2);break;case"Ellipse":e=le.ColliderDesc.ball(Math.max(t.width,t.height)/2);break;case"Triangle":case"Star":case"Polygon":e=le.ColliderDesc.cuboid(t.width/2,t.height/2);break;default:e=le.ColliderDesc.cuboid(t.width/2,t.height/2)}if(t.friction!==void 0&&e.setFriction(t.friction),t.restitution!==void 0&&e.setRestitution(t.restitution),t.density!==void 0)e.setDensity(t.density);else if(t.mass!==void 0&&!t.isStatic){const n=t.width*t.height;e.setDensity(t.mass/n)}t.isSensor&&e.setSensor(!0);const i=this.world.createCollider(e,o);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);s&&this.world&&(this.world.removeRigidBody(s),this.bodies.delete(t),this.colliders.delete(t))}step(t){this.world&&this.world.step()}getPosition(t){const s=this.bodies.get(t);if(!s)return null;const o=s.translation();return{x:o.x,y:o.y}}getRotation(t){const s=this.bodies.get(t);return s?s.rotation():null}getVelocity(t){const s=this.bodies.get(t);if(!s)return null;const o=s.linvel();return{x:o.x,y:o.y}}setPosition(t,s,o){const e=this.bodies.get(t);e&&e.setTranslation(new le.Vector2(s,o),!0)}setRotation(t,s){const o=this.bodies.get(t);o&&o.setRotation(s,!0)}setVelocity(t,s,o){const e=this.bodies.get(t);e&&e.setLinvel(new le.Vector2(s,o),!0)}applyForce(t,s,o){const e=this.bodies.get(t);e&&e.addForce(new le.Vector2(s,o),!0)}applyImpulse(t,s,o){const e=this.bodies.get(t);e&&e.applyImpulse(new le.Vector2(s,o),!0)}}const Ne=u=>u,_s=u=>u>0?1:0,Ps=u=>u<1?0:1,He=u=>u*u,Ue=u=>u*(2-u),qe=u=>u<.5?2*u*u:-1+(4-2*u)*u,Es=u=>u*u*u,xs=u=>--u*u*u+1,Os=u=>u<.5?4*u*u*u:(u-1)*(2*u-2)*(2*u-2)+1,As=u=>u*u*u*u,Ls=u=>1- --u*u*u*u,Rs=u=>u<.5?8*u*u*u*u:1-8*--u*u*u*u,Fs=u=>u*u*u*u*u,$s=u=>1+--u*u*u*u*u,Ws=u=>u<.5?16*u*u*u*u*u:1+16*--u*u*u*u*u,Bs=u=>1-Math.cos(u*Math.PI/2),Ys=u=>Math.sin(u*Math.PI/2),Xs=u=>-(Math.cos(Math.PI*u)-1)/2,Gs=u=>u===0?0:Math.pow(2,10*(u-1)),Ds=u=>u===1?1:1-Math.pow(2,-10*u),zs=u=>u===0?0:u===1?1:u<.5?Math.pow(2,20*u-10)/2:(2-Math.pow(2,-20*u+10))/2,Vs=u=>1-Math.sqrt(1-u*u),Ns=u=>Math.sqrt(1- --u*u),Hs=u=>u<.5?(1-Math.sqrt(1-4*u*u))/2:(Math.sqrt(1-(-2*u+2)*(-2*u+2))+1)/2,Oe=1.70158,Ae=Oe*1.525,Je=Oe+1,Us=u=>Je*u*u*u-Oe*u*u,qs=u=>1+Je*Math.pow(u-1,3)+Oe*Math.pow(u-1,2),Js=u=>u<.5?Math.pow(2*u,2)*((Ae+1)*2*u-Ae)/2:(Math.pow(2*u-2,2)*((Ae+1)*(u*2-2)+Ae)+2)/2,Qe=2*Math.PI/3,Ke=2*Math.PI/4.5,Qs=u=>u===0?0:u===1?1:-Math.pow(2,10*u-10)*Math.sin((u*10-10.75)*Qe),Ks=u=>u===0?0:u===1?1:Math.pow(2,-10*u)*Math.sin((u*10-.75)*Qe)+1,Zs=u=>u===0?0:u===1?1:u<.5?-(Math.pow(2,20*u-10)*Math.sin((20*u-11.125)*Ke))/2:Math.pow(2,-20*u+10)*Math.sin((20*u-11.125)*Ke)/2+1,Le=u=>u<1/2.75?7.5625*u*u:u<2/2.75?7.5625*(u-=1.5/2.75)*u+.75:u<2.5/2.75?7.5625*(u-=2.25/2.75)*u+.9375:7.5625*(u-=2.625/2.75)*u+.984375,js=u=>1-Le(1-u),ti=Le,ei=u=>u<.5?(1-Le(1-2*u))/2:(1+Le(2*u-1))/2,Xe=new Map,Te=(u,t,s,o)=>{const e=`${u},${t},${s},${o}`;if(Xe.has(e))return Xe.get(e);const i=h=>(1-3*s+3*u)*h*h*h+(3*s-6*u)*h*h+3*u*h,n=h=>(1-3*o+3*t)*h*h*h+(3*o-6*t)*h*h+3*t*h,a=h=>3*(1-3*s+3*u)*h*h+2*(3*s-6*u)*h+3*u,r=h=>{let c=h;for(let g=0;g<8;g++){const f=i(c)-h;if(Math.abs(f)<1e-6)return c;const d=a(c);if(Math.abs(d)<1e-6)break;c=c-f/d}return c},l=h=>h===0?0:h===1?1:n(r(h));return Xe.set(e,l),l},Ze=u=>{const t=u.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 Te(s,o,e,i)},je={ease:Te(.25,.1,.25,1),"ease-in":Te(.42,0,1,1),"ease-out":Te(0,0,.58,1),"ease-in-out":Te(.42,0,.58,1)},Re={Linear:Ne,EaseInQuad:He,EaseOutQuad:Ue,EaseInOutQuad:qe,EaseInCubic:Es,EaseOutCubic:xs,EaseInOutCubic:Os,EaseInQuart:As,EaseOutQuart:Ls,EaseInOutQuart:Rs,EaseInQuint:Fs,EaseOutQuint:$s,EaseInOutQuint:Ws,EaseInSine:Bs,EaseOutSine:Ys,EaseInOutSine:Xs,EaseInExpo:Gs,EaseOutExpo:Ds,EaseInOutExpo:zs,EaseInCirc:Vs,EaseOutCirc:Ns,EaseInOutCirc:Hs,EaseInBack:Us,EaseOutBack:qs,EaseInOutBack:Js,EaseInElastic:Qs,EaseOutElastic:Ks,EaseInOutElastic:Zs,EaseInBounce:js,EaseOutBounce:ti,EaseInOutBounce:ei,EaseIn:He,EaseOut:Ue,EaseInOut:qe,StepStart:_s,StepEnd:Ps},si=u=>{const t=u.trim(),s=t.toLowerCase();if(Re[t])return Re[t];const o=Object.keys(Re).find(i=>i.toLowerCase()===s);if(o)return Re[o];const e=Object.keys(ts).find(i=>i.toLowerCase()===s);if(e){const i=Ze(ts[e].value);if(i)return i}if(je[s])return je[s];if(s.startsWith("cubic-bezier")){const i=Ze(t);if(i)return i}return Ne},ts={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=(u,t,s,o,e)=>{if(!u||!t||!s)return u;const i=o.scale_x??1,n=o.scale_y??1,a=(r,l,h)=>{let c=0,g=0;const f=o.rotation*Math.PI/180,d=Math.cos(f),p=Math.sin(f),m=r*i*d-l*n*p+o.x,y=r*i*p+l*n*d+o.y;h.forEach(M=>{const _=e(M.boneId);if(!_)return;const T={x:_.x,y:_.y,rotation:_.rotation,scaleX:_.scale_x??1,scaleY:_.scale_y??1},$=s[M.boneId]||[1,0,0,1,0,0],k=m*$[0]+y*$[2]+$[4],E=m*$[1]+y*$[3]+$[5],L=T.rotation*Math.PI/180,O=Math.cos(L),A=Math.sin(L),W=k*T.scaleX*O-E*T.scaleY*A+T.x,x=k*T.scaleX*A+E*T.scaleY*O+T.y;c+=W*M.amount,g+=x*M.amount});const v=[...h].sort((M,_)=>_.amount-M.amount);if(v.length>=2&&v[0].amount>0&&v[1].amount>0){const M=e(v[0].boneId),_=e(v[1].boneId);if(M&&_&&M.length!==void 0&&_.length!==void 0){const T=M.length*(M.scale_y??1),$=M.rotation*Math.PI/180,k=M.x-T*Math.sin($),E=M.y+T*Math.cos($),L=_.length*(_.scale_y??1),O=_.rotation*Math.PI/180,A=_.x-L*Math.sin(O),W=_.y+L*Math.cos(O);let x=null,Y=null,H=!1;const Q=1;if(Math.hypot(M.x-_.x,M.y-_.y)<Q||Math.hypot(M.x-A,M.y-W)<Q?(x=M.x,Y=M.y):(Math.hypot(k-_.x,E-_.y)<Q||Math.hypot(k-A,E-W)<Q)&&(x=k,Y=E,H=!0),x!==null&&Y!==null){const P=s[v[0].boneId]||[1,0,0,1,0,0],F=P[0]*P[3]-P[1]*P[2];let U=0,J=0;if(F!==0){const it=(P[2]*P[5]-P[3]*P[4])/F,dt=(P[1]*P[4]-P[0]*P[5])/F,yt=Math.atan2(-P[1],P[3]);if(!H)U=it,J=dt;else{const ot=-P[2]/F,Et=P[0]/F,Ft=Math.hypot(ot,Et),wt=M.length*Ft;U=it-wt*Math.sin(yt),J=dt+wt*Math.cos(yt)}const ht=Math.hypot(m-U,y-J),ut=Math.hypot(c-x,g-Y);if(ut>0&&ht>0){const ot=Math.max(ut,.01),Et=Math.min(ht/ot,3),Ft=x+(c-x)*Et,wt=Y+(g-Y)*Et,Gt=v[0].amount,Yt=v[1].amount,B=Math.min(Gt,Yt)*2,nt=1-Math.pow(1-B,4);c=c*(1-nt)+Ft*nt,g=g*(1-nt)+wt*nt}}}}}const b=o.rotation*Math.PI/180,C=Math.cos(b),S=Math.sin(b),I=c-o.x,w=g-o.y;return{x:(I*C+w*S)/i,y:(-I*S+w*C)/n}};return u.map((r,l)=>{const h=t[l];if(!h||h.length===0)return{...r};const c={...r,...a(r.x,r.y,h)};if(r.in_x!==void 0&&r.in_y!==void 0){const g=a(r.in_x,r.in_y,h);c.in_x=g.x,c.in_y=g.y}if(r.out_x!==void 0&&r.out_y!==void 0){const g=a(r.out_x,r.out_y,h);c.out_x=g.x,c.out_y=g.y}return c})},es={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}},ss={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 is{constructor(){et(this,"artboard",null);et(this,"objectStates",new Map);et(this,"physicsEngine",null);et(this,"activeStateMachine",null);et(this,"inputs",new Map);et(this,"inputNameMap",new Map);et(this,"layerStates",new Map);et(this,"pretextCache",new Map);et(this,"pointerHistory",[]);et(this,"MAX_HISTORY",200);et(this,"imageCache",new Map);et(this,"lastValidSvgImgMap",new Map);et(this,"maskBuffer",null);et(this,"maskCtx",null);et(this,"lumaBuffer",null);et(this,"lumaCtx",null);et(this,"_noiseTileCanvas",null);et(this,"layout",{fit:"Contain",alignment:"Center"});et(this,"onTrigger");et(this,"onInputUpdate");et(this,"onComponentChange");et(this,"onToggle");et(this,"onInputChange");et(this,"onInputFocus");et(this,"onInputBlur");et(this,"onLog");et(this,"onButtonClick");et(this,"onGraphPointClick");et(this,"justFiredTriggers",new Set);et(this,"rootTransform",null);et(this,"canvasWidth",0);et(this,"canvasHeight",0);et(this,"lastHoveredObjectId",null);et(this,"_lastPointerPos",null);et(this,"_prevPointerPos",null);et(this,"focusedId",null);et(this,"draggingSliderId",null);et(this,"activeDropdownId",null);et(this,"activeObjectId",null);et(this,"draggingListViewId",null);et(this,"scrollOffset",{x:0,y:0});et(this,"_totalScroll",{x:0,y:0});et(this,"draggingBehaviors",new Set);et(this,"isMouseDown",!1);et(this,"_layoutAnimCache",new Map);et(this,"_springChainState",new Map);et(this,"_emitterPools",new Map);et(this,"objectVelocities",new Map);et(this,"currentTime",0);et(this,"frameCount",0);et(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});et(this,"onLogicUpdate");et(this,"logicNodeValues",new Map);et(this,"logicNodeState",new Map);et(this,"pointerDownTimes",new Map);et(this,"activeHoverIds",new Set);et(this,"onNavigation");et(this,"periodicTriggerTimes",new Map);et(this,"wasInView",new Set);et(this,"scrollProgressLastValue",new Map);et(this,"debug_objectsRendered",0);et(this,"debug_objectsTotal",0);et(this,"lastRenderTime",0);et(this,"debugMode",!1);et(this,"activeTriggers",new Map);console.info("%c[ExodeUI Engine] Pixel-Perfect Parity Active (v6.3.10) - SVG Fill & Gradient Parity Active","color: #3b82f6; font-weight: bold; padding: 2px 4px; border-radius: 4px; background: rgba(59, 130, 246, 0.1)")}setTriggerCallback(t){this.onTrigger=t}setInputUpdateCallback(t){this.onInputUpdate=t}setComponentChangeCallback(t){this.onComponentChange=t}setToggleCallback(t){this.onToggle=t}setLogicUpdateCallback(t){this.onLogicUpdate=t}setInputChangeCallback(t){this.onInputChange=t}setButtonClickCallback(t){this.onButtonClick=t}setGraphPointClickCallback(t){this.onGraphPointClick=t}setNavigationCallback(t){this.onNavigation=t}ensurePathPoints(t){if(!t||t.type!=="Path"&&t.type!=="Subtract"&&t.type!=="Union"&&t.type!=="Intersect"&&t.type!=="Exclude"&&t.type!=="BooleanOperation")return;if(t.points&&t.points.length>0){if(t.is_closed===void 0&&t.isClosed===void 0&&t.data){const{isClosed:e}=this.svgPathToPoints(t.data);t.is_closed=e}return}if(!t.data)return;const{points: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,l=0,h=0,c=0,g;for(;(g=s.exec(t))!==null;){const f=g[1],d=(g[2].match(o)||[]).map(parseFloat),p=f===f.toLowerCase(),m=f.toUpperCase();let y=0;const v=C=>{let S=d[y++];return p&&(S+=C?n:a),S},b=()=>({x:v(!0),y:v(!1)});switch(m){case"M":{const C=b();for(h=n=C.x,c=a=C.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a,moveTo:!0});y<d.length;){const S=b();n=S.x,a=S.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}case"L":for(;y<d.length;){const C=b();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"H":for(;y<d.length;)n=v(!0),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"V":for(;y<d.length;)a=v(!1),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"C":for(;y<d.length;){const C=b(),S=b(),I=b();if(e.length>0){const w=e[e.length-1];w.out_x=C.x,w.out_y=C.y}n=I.x,a=I.y,e.push({x:n,y:a,in_x:S.x,in_y:S.y,out_x:n,out_y:a}),r=S.x,l=S.y}break;case"S":for(;y<d.length;){const C={x:2*n-r,y:2*a-l},S=b(),I=b();if(e.length>0){const w=e[e.length-1];w.out_x=C.x,w.out_y=C.y}n=I.x,a=I.y,e.push({x:n,y:a,in_x:S.x,in_y:S.y,out_x:n,out_y:a}),r=S.x,l=S.y}break;case"Q":for(;y<d.length;){const C=b(),S=b();if(e.length>0){const I=e[e.length-1];I.out_x=I.x+2/3*(C.x-I.x),I.out_y=I.y+2/3*(C.y-I.y)}n=S.x,a=S.y,e.push({x:n,y:a,in_x:n+2/3*(C.x-n),in_y:a+2/3*(C.y-a),out_x:n,out_y:a}),r=C.x,l=C.y}break;case"T":for(;y<d.length;){const C={x:2*n-r,y:2*a-l},S=b();if(e.length>0){const I=e[e.length-1];I.out_x=I.x+2/3*(C.x-I.x),I.out_y=I.y+2/3*(C.y-I.y)}n=S.x,a=S.y,e.push({x:n,y:a,in_x:n+2/3*(C.x-n),in_y:a+2/3*(C.y-a),out_x:n,out_y:a}),r=C.x,l=C.y}break;case"Z":if(i=!0,e.length>0){const C=e[e.length-1];C.closePath=!0;const S=[...e].reverse().find(I=>I.moveTo)||e[0];S&&Math.hypot(S.x-C.x,S.y-C.y)<.1&&(S.in_x=C.in_x,S.in_y=C.in_y,e.pop(),e.length>0&&(e[e.length-1].closePath=!0))}n=h,a=c;break;default:if(d.length>=2){const C=b();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}}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))}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(l=>{if(e.has(l.id))return;const h={...l},c=h.childrenObjects||[];e.add(h.id),o.push(h),i(c)})};if(i(s.objects||[]),o.length>(s.objects||[]).length&&console.log(`[Engine] Flattened artboard from ${(s.objects||[]).length} to ${o.length} objects.`),s.objects=o,this.artboard=s,this.currentTime=0,this.objectStates.clear(),console.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(l=>{r.set(l.id,l),l.children||(l.children=[])}),this.artboard.objects.forEach(l=>{if(l.parentId){const h=r.get(l.parentId);h&&(h.children||(h.children=[]),h.children.includes(l.id)||h.children.push(l.id))}})}this.loadFonts(),this.preloadImages(this.artboard),this.reset(),this.advance(0)}preloadImages(t){if(!t||!t.objects)return;const s=o=>{if(!o||this.imageCache.has(o))return;const e=new Image;e.onload=()=>{console.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,l,h,c,g;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)??((l=s.geometry)==null?void 0:l.cornerRadius)??0;this.objectStates.set(s.id,{...s.transform||{},x:((h=s.transform)==null?void 0:h.x)??s.x??0,y:((c=s.transform)==null?void 0:c.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:((g=s.transform)==null?void 0:g.opacity)!==void 0?s.transform.opacity:s.opacity!==void 0?s.opacity:100,visible:s.visible!==void 0?s.visible:s.isVisible!==void 0?s.isVisible:!0,blendMode:s.blendMode||"Normal",style:JSON.parse(JSON.stringify(s.style||{})),geometry:JSON.parse(JSON.stringify(s.geometry||{})),options:s.options?JSON.parse(JSON.stringify(s.options)):{},masks:s.masks?JSON.parse(JSON.stringify(s.masks)):[],zIndex:s.zIndex!==void 0?s.zIndex:void 0})}),this.artboard.objects.some(s=>{var o;return(o=s.physics)==null?void 0:o.enabled})){this.physicsEngine=new Ts;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,l=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:l,rotation:a.rotation*(Math.PI/180),isStatic:e.physics.bodyType==="Static",mass:e.physics.mass,friction:e.physics.friction,restitution:e.physics.restitution,frictionAir:e.physics.frictionAir,density:e.physics.density,isSensor:e.physics.isSensor})}}))})}this.artboard.stateVariables&&this.artboard.stateVariables.forEach(s=>{this.inputs.set(s.id,s.value);const o=this.inputNameMap.get(s.name)||[];o.includes(s.id)||o.push(s.id),this.inputNameMap.set(s.name,o)}),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 l=Math.abs(r.x-a.x),h=Math.abs(r.y-a.y);!t&&(l>20||h>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=Ve(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(c=>s.get(c)).filter(c=>!!c),l=this.objectStates.get(n.id);if(!l)return;const h=Ve(l,r,c=>this.objectStates.get(c));h.frameWidth!==void 0&&(l.width=h.frameWidth),h.frameHeight!==void 0&&(l.height=h.frameHeight),e(h.childUpdates)}})}loadFonts(){if(!this.artboard)return;const t=new Set;if(this.artboard.objects.forEach(n=>{n.geometry&&n.geometry.type==="Text"&&n.geometry.fontFamily&&t.add(n.geometry.fontFamily)}),this.artboard.animations.forEach(n=>{n.tracks.forEach(a=>{(a.property==="geometry.fontFamily"||a.property==="fontFamily")&&a.keyframes.forEach(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 l=a.states.find(h=>h.id===r);if(l){let h=null;l.animationId&&(h=this.artboard.animations.find(c=>c.id===l.animationId)||null),h||(h=this.artboard.animations.find(c=>{var g,f;return c.name===l.name||c.id===l.name||(l.name==="Entry"||l.id==="entry")&&(((g=c.name)==null?void 0:g.toLowerCase())==="onload"||((f=c.name)==null?void 0:f.toLowerCase())==="intro")})||null),h&&((n=this.artboard.animationFlow)!=null&&n.some(g=>(g.trigger==="on_load"||g.trigger==="after_delay")&&g.targetAnimationId===(h==null?void 0:h.id))||(e.push({animation:h,state:l}),i=Math.max(i,h.duration)))}}}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(".")){const i=s.split(".");let n=e;for(let a=0;a<i.length-1;a++)n[i[a]]||(n[i[a]]={}),n=n[i[a]];n[i[i.length-1]]=o}else e[s]=o}updateInput(t,s){var n,a,r;let o;if(this.inputs.has(t)){const l=(n=this.activeStateMachine)==null?void 0:n.inputs.find(h=>h.id===t);l&&typeof l.value=="object"&&(o=l.value.type)}else{const l=this.inputNameMap.get(t);if(l&&l.length>0){const h=(a=this.activeStateMachine)==null?void 0:a.inputs.find(c=>c.id===l[0]);h&&typeof h.value=="object"&&(o=h.value.type)}}let e=s;o==="Trigger"&&(s===1?e=!0:s===0&&(e=!1)),this.inputs.has(t)&&this.setInternalInput(t,e);const i=this.inputNameMap.get(t);i&&i.forEach(l=>this.setInternalInput(l,e)),o==="Trigger"&&e===!0&&(this.justFiredTriggers.add(t),i&&i.forEach(l=>this.justFiredTriggers.add(l))),Array.isArray(e)&&((r=this.artboard)==null||r.objects.forEach(l=>{if(l.inputId===t||l.name===t){const h=this.objectStates.get(l.id);h&&h.options&&(l.type==="ListView"||l.variant==="listview"?h.options.items=e:(l.type==="Dropdown"||l.variant==="dropdown")&&(h.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 l=!1;switch(a){case"Equal":case"==":l=s==r;break;case"NotEqual":case"!=":l=s!=r;break;case"GreaterThan":case">":l=s>r;break;case"LessThan":case"<":l=s<r;break;case"GreaterEqual":case">=":l=s>=r;break;case"LessEqual":case"<=":l=s<=r;break;case"IsTrue":l=!!s;break;case"IsFalse":l=!s;break}if(l){const h=i.delay||0;h<=0?this.triggerGlobalAnimation(i.targetAnimationId,i.subAnimationIds,i.loop,i.id):setTimeout(()=>this.triggerGlobalAnimation(i.targetAnimationId,i.subAnimationIds,i.loop,i.id),h)}}})}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(l=>l.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,i=s.value,n=this.evaluateLogicTree(o);if(n===void 0)return console.log(`[Engine] Condition Check Failed: Input ${o} is undefined`),!1;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,l,h,c,g;if(o.has(t))return this.inputs.get(t)??this.logicNodeValues.get(t)??0;o.add(t);const e=(r=(a=this.activeStateMachine)==null?void 0:a.logicNodes)==null?void 0:r.find(f=>f.id===t);if(e){const f=(p,m)=>{const y=e.inputs.find(v=>v.id===p);return y?y.sourceId?this.evaluateLogicTree(y.sourceId,y.sourceHandleId,o):y.value!==void 0?y.value:m:m};let d=0;switch(e.op){case bt.AND:d=f("a",!1)&&f("b",!1);break;case bt.OR:d=f("a",!1)||f("b",!1);break;case bt.NOT:d=!f("in",!1);break;case bt.XOR:d=!!f("a",!1)!=!!f("b",!1);break;case bt.OBJECT:d=e.name;break;case bt.PROPERTY:case bt.GET_PROPERTY:{const p=f("id","");if(!p){d=0;break}const m=e.name;if(!m||m==="GET_PROPERTY"||m==="PROPERTY"){d=0;break}const y=this.objectStates.get(p);if(!y){d=0;break}m in y?d=y[m]:d=this.resolvePath(y,m);break}case bt.SET_PROPERTY:{const p=f("id",""),m=f("value",void 0);if(!p||m===void 0){d=0;break}const y=e.name;if(!y||y==="SET_PROPERTY"){d=0;break}const v=this.objectStates.get(p);if(!v){d=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(y))v[y]=m,d=m;else{const C=y.split(".");let S=v;for(let w=0;w<C.length-1;w++){const M=C[w];S[M]===void 0&&(S[M]={}),S=S[M]}const I=C[C.length-1];S[I]=m,d=m}break}case bt.ADD:d=f("a",0)+f("b",0);break;case bt.SUB:d=f("a",0)-f("b",0);break;case bt.MUL:d=f("a",0)*f("b",0);break;case bt.DIV:{const p=f("b",1);d=p===0?0:f("a",0)/p;break}case bt.MOD:d=f("a",0)%f("b",1);break;case bt.POW:d=Math.pow(f("a",0),f("b",1));break;case bt.ABS:d=Math.abs(f("in",0));break;case bt.ROUND:d=Math.round(f("in",0));break;case bt.FLOOR:d=Math.floor(f("in",0));break;case bt.CEIL:d=Math.ceil(f("in",0));break;case bt.SIN:d=Math.sin(f("in",0));break;case bt.COS:d=Math.cos(f("in",0));break;case bt.TAN:d=Math.tan(f("in",0));break;case bt.CLAMP:{const p=f("in",0),m=f("min",0),y=f("max",1);d=Math.max(m,Math.min(y,p));break}case bt.REMAP:{const p=f("in",0),m=f("inMin",0),y=f("inMax",100),v=f("outMin",0),b=f("outMax",1);d=y===m?v:v+(p-m)*(b-v)/(y-m);break}case bt.EQ:d=f("a",0)==f("b",0);break;case bt.NEQ:d=f("a",0)!=f("b",0);break;case bt.GT:d=f("a",0)>f("b",0);break;case bt.LT:d=f("a",0)<f("b",0);break;case bt.GTE:d=f("a",0)>=f("b",0);break;case bt.LTE:d=f("a",0)<=f("b",0);break;case bt.IF_ELSE:d=f("cond",!1)?f("then",0):f("else",0);break;case bt.VALUE:d=e.value!==void 0?e.value:0;break;case bt.INPUT:d=this.inputs.get(e.name)??0;break;case bt.LOG:{const p=f("in","");this.debugLog(`[User Logic] ${p}`),d=p;break}case bt.SCROLL_X:d=this.inputs.get("scrollX")??0;break;case bt.SCROLL_Y:d=this.inputs.get("scrollY")??0;break;case bt.MOUSE_X:d=this.inputs.get("mouseX")??0;break;case bt.MOUSE_Y:d=this.inputs.get("mouseY")??0;break;case bt.IS_MOUSE_DOWN:d=this.inputs.get("isMouseDown")??!1;break;case bt.EFFECTOR:{const p=f("id",""),m=f("intensity",1),y=f("trigger",!0);if(!p||!y){d=0;break}const v=e.name;if(!v){d=0;break}const b=this.objectStates.get(p);if(!b){d=0;break}if(["glitch","halftone","pixelate","noise","acid_gradient","acid_rave","shimmer"].includes(v))b.style||(b.style={}),b.style.artEffect={enabled:!0,type:v,intensity:m},d=1;else{b.behaviors||(b.behaviors=[]);let S=b.behaviors.find(I=>I.type===v);S?(S.enabled=!0,S.settings||(S.settings={}),S.settings.intensity=m):(S={id:`eff_${Date.now()}_${v}`,type:v,enabled:!0,sensors:[],settings:{intensity:m}},b.behaviors.push(S)),d=1}break}case bt.MONITOR:{d=f("in",0);break}case bt.SPRING_PULL:{const p=f("objectId",""),m=f("forceX",0),y=f("forceY",0);p&&((l=this.artboard)==null||l.objects.forEach(v=>{v.behaviors&&v.behaviors.forEach(b=>{var C;if(b.type===G.SpringChain&&((C=b.settings)!=null&&C.connections)&&(b.settings.connections.some(I=>I.targetId===p)||v.id===p)){this._springChainState.has(v.id)||this._springChainState.set(v.id,new Map);const I=this._springChainState.get(v.id);if(!I.has(p)){const M=this.objectStates.get(p);I.set(p,{x:(M==null?void 0:M.x)??0,y:(M==null?void 0:M.y)??0,vx:0,vy:0})}const w=I.get(p);w&&(w.vx+=m,w.vy+=y)}})})),d=1;break}case bt.SPRING_SETTLE:{const p=f("objectId","");let m=!0;if(p){const y=f("threshold",1);this._springChainState.forEach(v=>{const b=v.get(p);b&&(Math.abs(b.vx)>y||Math.abs(b.vy)>y)&&(m=!1)})}d=m;break}case bt.EMIT:{const p=f("objectId",""),m=f("count",20);p&&((h=this.artboard)==null||h.objects.forEach(y=>{y.behaviors&&y.behaviors.forEach(v=>{v.type===G.ParticleEmitter&&y.id===p&&(v._pendingBurst=(v._pendingBurst||0)+m)})})),d=1;break}default:d=0;break}if(this.logicNodeValues.set(t,d),e.op===bt.DELAY){const p=f("delay",0),m=f("in",0);let y=this.logicNodeState.get(t);for(y||(y={queue:[]},this.logicNodeState.set(t,y)),y.queue.push({time:this.currentTime+p,value:m});y.queue.length>0&&y.queue[0].time<=this.currentTime;)y.lastValue=y.queue.shift().value;d=y.lastValue??0}return d}const i=(c=this.activeStateMachine)==null?void 0:c.inputs.find(f=>f.id===t||f.name===t);if(i&&i.sourceId&&!o.has(i.sourceId)){const f=this.evaluateLogicTree(i.sourceId,i.sourceHandleId,o);return this.inputs.set(i.id,f),f}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 f=(g=this.activeStateMachine)==null?void 0:g.inputs.find(d=>d.id===t);if(f&&f.value.type==="Number"&&typeof n=="number"){const d=f.value.defaultValue??f.value.value;if(s==="source-greater")return n>d;if(s==="source-less")return n<d;if(s==="source-equal")return n===d}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===bt.SET_PROPERTY||t.op===bt.EFFECTOR)&&this.evaluateLogicTree(t.id)})}resolvePath(t,s){const o=s.split(".");let e=t;for(const i of o)if(e&&typeof e=="object"&&i in e)e=e[i];else return;return e}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&&(console.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.onLogicUpdate&&this.logicNodeValues.size>0&&this.onLogicUpdate(Object.fromEntries(this.logicNodeValues)));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&&(o.currentStateIds.length>0&&this.handleAnimationFinished(o.currentStateIds[0],o.ruleId),e.startsWith("global_")&&s.push(e))}o.animations.forEach(i=>{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,l,h,c;if(o.phase==="entry")o.time+=t,o.time>=o.animation.duration&&((a=(n=(i=this.artboard)==null?void 0:i.objects.find(g=>g.id===e))==null?void 0:n.triggers)==null||a.find(g=>g.id===o.triggerId),o.phase="hold",o.elapsedHold=0,o.time=o.animation.duration),this.applyAnimation(o.animation,o.time,o.filterObjectIds||o.filterObjectId||void 0);else if(o.phase==="hold"){const g=(h=(l=(r=this.artboard)==null?void 0:r.objects.find(p=>p.id===e))==null?void 0:l.triggers)==null?void 0:h.find(p=>p.id===o.triggerId),f=(g==null?void 0:g.duration)||0;o.elapsedHold+=t*1e3;let d=o.elapsedHold>=f;if((g==null?void 0:g.eventType)==="hover"&&!this.activeHoverIds.has(e)&&(d=!0),((g==null?void 0:g.eventType)==="onHold"||(g==null?void 0:g.eventType)==="pointerDown")&&!this.isMouseDown&&(d=!0),d)if(g!=null&&g.exitAnimationId){const p=(c=this.artboard)==null?void 0:c.animations.find(m=>m.id===g.exitAnimationId);p?(o.phase="exit",o.animation=p,o.time=0):this.activeTriggers.delete(e)}else this.activeTriggers.delete(e)}else o.phase==="exit"&&(o.time+=t,o.time>=o.animation.duration?this.activeTriggers.delete(e):this.applyAnimation(o.animation,o.time,o.filterObjectIds||o.filterObjectId||void 0))}),this.evaluateContinuousInteractions(t)}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),l=(((i=s.geometry)==null?void 0:i.width)||100)*(r.scale_x||1),h=(((n=s.geometry)==null?void 0:n.height)||100)*(r.scale_y||1),c=50,g=r.x+l/2>=-this.canvasWidth/2-c&&r.x-l/2<=this.canvasWidth/2+c&&r.y+h/2>=-this.canvasHeight/2-c&&r.y-h/2<=this.canvasHeight/2+c,f=`analytics_${s.id}`,d=this.wasInView.has(f);g&&!d&&this.fireAnalyticsEvent(s.id,"visible"),g?this.wasInView.add(f):this.wasInView.delete(f)}}}),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,l,h;const a=n.toLowerCase();if(a==="on interval"||a==="oninterval"){const c=e.intervalValue||2e3,g=this.periodicTriggerTimes.get(e.id)||0;this.currentTime*1e3-g>=c&&(!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 c=e.delayValue||1e3;!this.periodicTriggerTimes.has(e.id)&&this.currentTime*1e3>=c&&(!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 c=this.objectStates.get(s.id);if(c&&c.visible!==!1){const g=this.getGlobalTransform(s.id),f=(((r=s.geometry)==null?void 0:r.width)||100)*(g.scale_x||1),d=(((l=s.geometry)==null?void 0:l.height)||100)*(g.scale_y||1),p=50,m=g.x+f/2>=-this.canvasWidth/2-p&&g.x-f/2<=this.canvasWidth/2+p&&g.y+d/2>=-this.canvasHeight/2-p&&g.y-d/2<=this.canvasHeight/2+p,y=this.wasInView.has(s.id);m&&!y&&(!e.conditions||this.checkConditions(e.conditions))&&this.fireEventForObject(s.id,"Scroll Into View"),m?this.wasInView.add(s.id):this.wasInView.delete(s.id)}}if(a==="scroll progress"||a==="scrollprogress"){const c=Math.abs(this.scrollOffset.y)/(((h=this.artboard)==null?void 0:h.height)||1e3),g=this.scrollProgressLastValue.get(e.id)||0;Math.abs(c-g)>.001&&(this.scrollProgressLastValue.set(e.id,c),(e.action==="Set Input"||e.action==="setInput")&&this.updateInput(e.targetInputId,c))}})})}))}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 h,c,g,f,d,p,m,y,v;const a=((h=o.constraints)==null?void 0:h[n])||{},r={...i,...a},l=r.strength??1;if(r.type==="Translation"){const b=this.getGlobalTransform(r.targetId);if(b){const C=r.offsetX||0,S=r.offsetY||0,I=b.x+C,w=b.y+S,M=r.useSpring;if(M){const T=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:$,y:k,vx:E,vy:L}=this.computeSpring(e.x,e.y,T.vx,T.vy,I,w,r,t);r.copyX&&(e.x=e.x+($-e.x)*l),r.copyY&&(e.y=e.y+(k-e.y)*l),this.objectVelocities.set(s.id,{vx:E,vy:L})}else r.copyX&&(e.x=e.x+(I-e.x)*l),r.copyY&&(e.y=e.y+(w-e.y)*l);let _=!1;if((c=r.limitX)!=null&&c.enabled){const T=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==T&&(_=!0)}if((g=r.limitY)!=null&&g.enabled){const T=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==T&&(_=!0)}_&&M&&this.objectVelocities.set(s.id,{vx:0,vy:0})}}else if(r.type==="Rotation"){const b=this.getGlobalTransform(r.targetId);if(b){let S=(b.rotation+(r.offset||0)-e.rotation)%360;S>180&&(S-=360),S<-180&&(S+=360),e.rotation=e.rotation+S*l}}else if(r.type==="Scale"){const b=this.getGlobalTransform(r.targetId);b&&(r.copyX&&(e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*l),r.copyY&&(e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*l))}else if(r.type==="Transform"){const b=this.getGlobalTransform(r.targetId);if(b){e.x=e.x+(b.x-e.x)*l,e.y=e.y+(b.y-e.y)*l;let C=(b.rotation-e.rotation)%360;C>180&&(C-=360),C<-180&&(C+=360),e.rotation=e.rotation+C*l,e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*l,e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*l}}else if(r.type==="FollowPointer"){const b=((f=this._lastPointerPos)==null?void 0:f.x)??e.x,C=((d=this._lastPointerPos)==null?void 0:d.y)??e.y,S=r.useSpring;if(S){const w=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:M,y:_,vx:T,vy:$}=this.computeSpring(e.x,e.y,w.vx,w.vy,b,C,r,t);e.x=M,e.y=_,this.objectVelocities.set(s.id,{vx:T,vy:$})}else e.x=e.x+(b-e.x)*l,e.y=e.y+(C-e.y)*l;let I=!1;if((p=r.limitX)!=null&&p.enabled){const w=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==w&&(I=!0)}if((m=r.limitY)!=null&&m.enabled){const w=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==w&&(I=!0)}I&&S&&this.objectVelocities.set(s.id,{vx:0,vy:0})}else if(r.type==="Distance"){const b=this.getGlobalTransform(r.targetId);if(b){const C=e.x-b.x,S=e.y-b.y,I=Math.sqrt(C*C+S*S),w=r.distance||0;let M=I;switch(r.mode){case"exact":M=w;break;case"minimum":M=Math.max(w,I);break;case"maximum":M=Math.min(w,I);break;case"clamped":M=Math.max(0,Math.min(w,I));break}if(I>0){const _=e.x===b.x&&e.y===b.y?1:M/I;e.x=e.x+(b.x+C*_-e.x)*l,e.y=e.y+(b.y+S*_-e.y)*l}}}else if(r.type==="FollowPath"){const b=(y=this.artboard)==null?void 0:y.objects.find(C=>C.id===r.targetId);if(b){const C=this.getGlobalTransform(b.id);if(C){let S=b.geometry;if(b.type==="Frame"||b.type==="Group"||!S||S.type!=="Path"&&S.type!=="Ellipse"&&S.type!=="Rectangle"){const F=(v=this.artboard)==null?void 0:v.objects.find(U=>U.parentId===b.id&&U.type==="Shape"&&U.geometry&&(U.geometry.type==="Path"||U.geometry.type==="Ellipse"||U.geometry.type==="Rectangle"));F&&(S=F.geometry)}if(!S)return;const I=(r.distance||0)/100,w=C.width||S.width||0,M=C.height||S.height||0,_=this.getPointOnPath(S,w,M,I),T=C.rotation*Math.PI/180,$=Math.cos(T),k=Math.sin(T),E=_.x*C.scale_x*$-_.y*C.scale_y*k,L=_.x*C.scale_x*k+_.y*C.scale_y*$;let O=C.rotation+(r.offsetRotation||0);if(r.orient){const F=Math.cos(_.angle),U=Math.sin(_.angle),J=F*C.scale_x*$-U*C.scale_y*k,it=F*C.scale_x*k+U*C.scale_y*$;O=Math.atan2(it,J)*180/Math.PI+(r.offsetRotation||0)}const A=O*Math.PI/180,W=Math.cos(A),x=Math.sin(A),Y=(r.offsetX||0)*W-(r.offsetY||0)*x,H=(r.offsetX||0)*x+(r.offsetY||0)*W,Q=C.x+E+Y,P=C.y+L+H;if(e.x=e.x+(Q-e.x)*l,e.y=e.y+(P-e.y)*l,r.orient){let F=(O-e.rotation)%360;F>180&&(F-=360),F<-180&&(F+=360),e.rotation=e.rotation+F*l}}}}else if(r.type==="IK"){const b=this.getGlobalTransform(r.targetId);b&&this.solveIK(s,b,r.boneCount||2,l)}}),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 c,g;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,rotation:0,scale_x:1,scale_y:1};const o=(c=this.artboard)==null?void 0:c.objects.find(f=>f.id===t),e=(o==null?void 0:o.type)==="Bone"?(g=o.geometry)==null?void 0:g.length:void 0;if(!o||!o.parentId)return{x:s.x,y:s.y,rotation:s.rotation,scale_x:(s.scale_x??1)*(s.flip_x?-1:1),scale_y:(s.scale_y??1)*(s.flip_y?-1:1),length:e};const i=this.getGlobalTransform(o.parentId),n=i.rotation*Math.PI/180,a=Math.cos(n),r=Math.sin(n),l=i.x+(s.x*i.scale_x*a-s.y*i.scale_y*r),h=i.y+(s.x*i.scale_x*r+s.y*i.scale_y*a);return{x:l,y:h,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),l=s.x-o.x,h=s.y-o.y,c=(l*a-h*r)*e,g=(l*r+h*a)*i;return{x:c,y:g,rotation:s.rotation-o.rotation,scale_x:s.scale_x/(o.scale_x||1),scale_y:s.scale_y/(o.scale_y||1)}}solveIK(t,s,o,e){var l;const i=[];let n=t.id;for(let h=0;h<o&&n;h++){const c=(l=this.artboard)==null?void 0:l.objects.find(g=>g.id===n);if(!c)break;i.push({id:n,local:this.objectStates.get(n),global:this.getGlobalTransform(n)}),n=c.parentId}if(i.length<2)return;const a=i.reverse(),r=5;for(let h=0;h<r;h++){const c=this.getGlobalTransform(t.id);for(let g=a.length-2;g>=0;g--){const f=a[g],d=this.getGlobalTransform(f.id),p=c.x-d.x,m=c.y-d.y,y=s.x-d.x,v=s.y-d.y,b=Math.sqrt(p*p+m*m),C=Math.sqrt(y*y+v*v);if(b>.001&&C>.001){const S=Math.atan2(m,p);let w=(Math.atan2(v,y)-S)*180/Math.PI;w*=e;const M=this.objectStates.get(f.id);M&&(M.rotation+=w)}}}}computeSpring(t,s,o,e,i,n,a,r){const l=a.stiffness??100,h=a.damping??10,c=a.mass??1,g=-l*(t-i),f=-l*(s-n),d=-h*o,p=-h*e,m=(g+d)/c,y=(f+p)/c,v=o+m*r,b=e+y*r,C=t+v*r,S=s+b*r;return{x:C,y:S,vx:v,vy:b}}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-this.artboard.width/2,r=(o-n.ty)/n.scaleY-this.artboard.height/2;this._prevPointerPos=this._lastPointerPos,this._lastPointerPos={x:a,y:r},this.updateInput("mouseX",a),this.updateInput("mouseY",r),this.handlePointerEvent(t,a,r)}handleScroll(t,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,l,h,c,g;if(!this.artboard)return;t==="down"?(this.isMouseDown=!0,this.updateInput("isMouseDown",!0)):(t==="up"||t==="blur")&&(this.isMouseDown=!1,this.updateInput("isMouseDown",!1));let e=null;const i=(f,d)=>{var C;let p=d;d==="click"?p="onClick":d==="down"?p="onPointerDown":d==="up"?p="onPointerUp":d==="blur"&&(p="onPointerLeave");const m=new Set([p]);d==="move"&&m.add("onPointerEnter").add("hover").add("onPointerLeave").add("blur"),p==="onClick"&&m.add("click"),p==="onPointerDown"&&m.add("pointerDown"),p==="onPointerUp"&&m.add("pointerUp");const y=["button","toggle","toggle_button","dropdown","listview","inputbox","slider","checkbox","radiogroup"];return!!(f.type==="Component"&&y.includes(f.variant)||y.includes((C=f.type)==null?void 0:C.toLowerCase())||(f.interactions||[]).some(S=>m.has(S.event))||(f.triggers||[]).some(S=>m.has(S.eventType)))};let n=null;for(let f=this.artboard.objects.length-1;f>=0;f--){const d=this.artboard.objects[f],p=this.objectStates.get(d.id);if(p&&p.visible!==!1&&p.opacity>0&&this.hitTest(d,s,o)&&(n||(n=d),i(d,t))){e=d;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 f=this.artboard.objects.find(d=>d.id===this.draggingSliderId);f&&this.updateSliderValueFromPointer(f,s,o);return}if(this.draggingListViewId){const f=this.artboard.objects.find(d=>d.id===this.draggingListViewId);f&&this.updateListViewScrollFromPointer(f);return}e&&e.type==="Component"&&e.variant==="listview"&&this.updateListViewHoverFromPointer(e,s,o),this.isMouseDown&&a&&this.fireEventForObject(a,"Drag"),a!==this.lastHoveredObjectId&&(console.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.draggingListViewId=null,this.draggingBehaviors.clear(),this.pointerDownTimes.delete(a),this.activeObjectId=null),t==="down"&&(this.pointerDownTimes.set(a,this.currentTime),this.activeObjectId=a,e&&((r=e.behaviors)!=null&&r.some(f=>f.type===G.Draggable))&&this.draggingBehaviors.add(a)),t==="move"?(a&&!this.activeHoverIds.has(a)&&this.activeHoverIds.add(a),this.activeHoverIds.forEach(f=>{f!==a&&this.activeHoverIds.delete(f)})):t==="blur"&&this.activeHoverIds.clear(),this.activeDropdownId&&t==="down"){const f=this.artboard.objects.find(d=>d.id===this.activeDropdownId);if(f&&(f.type==="Dropdown"||f.variant==="dropdown")){const d=this.objectStates.get(f.id),p=(d==null?void 0:d.options)||f.options||{},m=f.geometry||{},y=m.width??f.width??200,v=m.height??f.height??40,b=p.optionsList||[],C=p.itemHeight||32,S=p.listPadding??4,I=b.length*C+S*2,w=this.getWorldTransform(f.id),M=y*Math.abs(w.scaleX),_=v*Math.abs(w.scaleY),T=w.y+_/2+4,$=Math.abs(s-w.x)<=M/2,k=o>=T&&o<=T+I*Math.abs(w.scaleY);if($&&k){const E=Math.abs(w.scaleY),L=o-(T+S*E),O=Math.floor(L/(C*E));if(O>=0&&O<b.length){const A=b[O];p.selectedOption=A,p.isOpen=!1,this.activeDropdownId=null,f.inputId&&this.setInternalInput(f.inputId,A),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"dropdown",property:"selectedOption",value:A})}return}else a!==this.activeDropdownId&&(p.isOpen=!1,this.activeDropdownId=null)}}if(e){let f=e,d=e;for(;d&&d.parentId;){const m=this.artboard.objects.find(y=>y.id===d.parentId);if(m&&m.type==="Component"){f=m;break}d=m}let p=t;if(t==="click"?p="onClick":t==="down"?p="onPointerDown":t==="up"?p="onPointerUp":t==="blur"&&(p="onPointerLeave"),this.fireEventForObject(e.id,p),f!==e&&this.fireEventForObject(f.id,p),f.type==="Component"&&f.variant==="toggle_button"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{};y.checked=!y.checked,f.inputId&&this.setInternalInput(f.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"toggle_button",property:"checked",value:y.checked}),this.fireEventForObject(f.id,"Toggle"),this.fireEventForObject(f.id,y.checked?"Toggle True":"Toggle False")}if(f.type==="Component"&&f.variant==="toggle"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{};y.checked=!y.checked,f.inputId&&this.setInternalInput(f.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"toggle",property:"checked",value:y.checked}),this.onToggle&&this.onToggle(f.name,y.checked),this.fireEventForObject(f.id,"Toggle"),this.fireEventForObject(f.id,y.checked?"Toggle True":"Toggle False")}if(f.type==="Component"&&f.variant==="dropdown"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{},v=!y.isOpen;if(v&&this.activeDropdownId&&this.activeDropdownId!==f.id){const b=this.artboard.objects.find(C=>C.id===this.activeDropdownId);b&&b.options&&(b.options.isOpen=!1)}y.isOpen=v,this.activeDropdownId=v?f.id:null}if(f.type==="Component"&&f.variant==="button"&&t==="down"&&(this.onButtonClick&&this.onButtonClick(f.name,f.id),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"button",property:"click",value:!0})),f.type==="Component"&&f.variant==="listview"&&t==="down"){this.draggingListViewId=f.id;const m=this.getListViewItemIndexAtPointer(f,s,o);if(m!==null){const y=f.options||{};y.activeItemIndex=m;const v=this.objectStates.get(f.id);v&&v.options&&(v.options.activeItemIndex=m);const b=(y.items||[])[m],C=typeof b=="string"?b:b.label||b.value||m;v&&v.options&&(v.options.selectedValue=C),f.inputId&&this.setInternalInput(f.inputId,C),this.onComponentChange&&(this.onComponentChange({objectId:f.id,componentName:f.name,variant:"listview",property:"activeItemIndex",value:m}),this.onComponentChange({objectId:f.id,componentName:f.name,variant:"listview",property:"selected",value:C}))}}if(f.type==="Component"&&f.variant==="slider"&&t==="down"&&(this.draggingSliderId=f.id,this.updateSliderValueFromPointer(f,s,o)),f.type==="Component"&&f.variant==="checkbox"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{};y.checked=!y.checked,f.inputId&&this.setInternalInput(f.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"checkbox",property:"checked",value:y.checked}),this.fireEventForObject(f.id,"Click"),this.fireEventForObject(f.id,y.checked?"Checked":"Unchecked")}if(f.type==="Component"&&f.variant==="radiogroup"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{},v=y.optionsList||[],b=this.getRadioGroupItemIndexAtPointer(f,s,o);if(b!==null&&b>=0&&b<v.length){const C=v[b];y.selectedValue=C,f.inputId&&this.setInternalInput(f.inputId,C),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"radiogroup",property:"selectedValue",value:C}),this.fireEventForObject(f.id,"Click"),this.fireEventForObject(f.id,`Selected: ${C}`)}}if(f.type==="LineGraph"&&(t==="down"||t==="click")){const m=f.geometry,y=(m==null?void 0:m.datasets)||[],v=this.objectStates.get(f.id),b=(v==null?void 0:v.width)||(m==null?void 0:m.width)||200,C=(v==null?void 0:v.height)||(m==null?void 0:m.height)||150,S=this.getWorldTransform(f.id),I=30,w=20,M=b-I,_=C-w;let T=1;y.forEach(E=>{const L=Math.max(...E.data||[0]);L>T&&(T=L)});let $=1/0,k=null;y.forEach((E,L)=>{const O=E.data||[],A=M/Math.max(O.length-1,1);O.forEach((W,x)=>{const Y=S.x-b/2+I+x*A,H=S.y+C/2-w-W/T*_,Q=Math.sqrt((s-Y)**2+(o-H)**2);Q<$&&($=Q,k={dIdx:L,pIdx:x,val:W,label:E.label||`Dataset ${L+1}`})})}),k&&$<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:f.id,componentName:f.name,datasetIndex:k.dIdx,pointIndex:k.pIdx,value:k.val,label:k.label}),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"linegraph",property:"click",value:(k==null?void 0:k.val)??null})}if(t==="click"){const m=(l=this.artboard)==null?void 0:l.objects.find(b=>b.id===e.id),y=this.focusedId,v=(m==null?void 0:m.type)==="InputBox"||(m==null?void 0:m.type)==="Component"&&m.variant==="inputbox";if(m&&v){if(this.focusedId=e.id,console.log(`[Engine] Focus set to: ${e.id}`),y!==this.focusedId){if(y){const b=(h=this.artboard)==null?void 0:h.objects.find(C=>C.id===y);b&&this.onInputBlur&&this.onInputBlur(b.name)}this.onInputFocus&&this.onInputFocus(m.name)}}else if(this.focusedId=null,y){const b=(c=this.artboard)==null?void 0:c.objects.find(C=>C.id===y);b&&this.onInputBlur&&this.onInputBlur(b.name)}}}else if(t==="click"){const f=this.focusedId;if(this.focusedId=null,f){const d=(g=this.artboard)==null?void 0:g.objects.find(p=>p.id===f);d&&this.onInputBlur&&this.onInputBlur(d.name)}}}handleKeyDown(t){if(!this.artboard||!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)}fireEventForObject(t,s){var h,c,g,f,d;const o=(h=this.artboard)==null?void 0:h.objects.find(p=>p.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(p=>{const m=p.triggers||[p.event||p.trigger||"click"];return((p.triggerLogic||"OR")==="AND"?m.every(b=>e.has(b.toLowerCase())):m.some(b=>e.has(b.toLowerCase())))?p.conditions&&p.conditions.length>0?this.checkConditions(p.conditions):!0:!1});if(a){if(console.log(`[Engine] Interaction matched: ${s} -> Action: ${a.action}`),a.action==="setInput"||a.action==="Set Input"){let p=a.value||a.inputValue;p==="toggle"&&(p=!this.inputs.get(a.targetInputId)),this.updateInput(a.targetInputId,p)}else if(a.action==="Toggle Boolean"){const p=this.inputs.get(a.targetInputId);this.updateInput(a.targetInputId,!p)}else if(a.action==="fireTrigger")this.updateInput(a.targetInputId,!0);else if(a.action==="setProperty"){const p=a.targetObjectId||o.id,m=a.targetProperty;m&&this.updateObjectProperty(p,m,a.value)}else if(a.action==="Navigate Artboard"||a.action==="navigate")this.onNavigation&&this.onNavigation({type:"artboard",value:a.targetArtboard||a.value});else if(a.action==="Navigate URL")this.onNavigation&&this.onNavigation({type:"url",value:a.navigateUrl});else if(a.action==="Play Animation"){const p=a.targetAnimationId;p==="__all__"?(g=(c=this.artboard)==null?void 0:c.animations)==null||g.forEach(m=>{this.triggerGlobalAnimation(m.id,a.subAnimationIds)}):p&&this.triggerGlobalAnimation(p,a.subAnimationIds)}else if(a.action==="setState"||a.action==="Set State"){const p=a.targetObjectId||o.id,y={...this.objectStates.get(p)||{},...a.value||{}};this.objectStates.set(p,y),console.log(`[Engine] State updated for ${p}:`,y)}else if(a.action==="Stop Animation"||a.action==="Pause Animation"){const p=a.targetAnimationId;p==="__all__"?this.layerStates.forEach((m,y)=>{y.startsWith("global_")&&this.layerStates.delete(y)}):p&&this.layerStates.forEach((m,y)=>{y.startsWith(`global_${p}_`)&&this.layerStates.delete(y)})}else if(a.action==="Switch to State"&&this.activeStateMachine){const p=a.targetState,m=this.activeStateMachine.layers.find(y=>y.states.some(v=>v.id===p||v.name===p));m&&(console.log(`[Engine] Switching Layer ${m.name} to State ${p}`),this.enterStates(m.name,[p]))}this.onTrigger&&this.onTrigger(s,a.action)}const l=(o.triggers||[]).find(p=>{const m=p.eventType.toLowerCase();let y=!1;return(e.has(m)||m==="click"&&e.has("onclick")||m==="hover"&&(e.has("onpointerenter")||e.has("hover"))||m==="pointerdown"&&e.has("onpointerdown")||m==="pointerup"&&e.has("onpointerup"))&&(y=!0),y&&p.conditions&&p.conditions.length>0?this.checkConditions(p.conditions):y});if(l&&l.entryAnimationId){console.log(`[Engine] Trigger matched: ${s} (as ${l.eventType}) -> Animation ${l.entryAnimationId}`);const p=(d=(f=this.artboard)==null?void 0:f.animations)==null?void 0:d.find(m=>m.id===l.entryAnimationId);p&&(this.activeTriggers.set(o.id,{triggerId:l.id,animation:p,time:0,phase:"entry",elapsedHold:0,filterObjectId:l.targetObjectId}),this.onTrigger&&this.onTrigger(l.name,p.name))}}fireAnalyticsEvent(t,s){var r,l;const o=(r=this.artboard)==null?void 0:r.objects.find(h=>h.id===t);if(!o)return;const e=(l=o.style)==null?void 0:l.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(h=>{if(h.type==="literal")n[h.key]=h.value;else if(h.type==="variable"){const c=this.inputs.get(h.value);n[h.key]=c!==void 0?c:""}}),console.log(`[ExodeUI Analytics] Dispatching event "${i}" via ${s} trigger:`,n);const a=e.platforms||{ga4:!0,meta:!0,mixpanel:!1};if(a.ga4){const h=window;typeof h.gtag=="function"?(h.gtag("event",i,n),console.log(`[ExodeUI Analytics] GA4: Event "${i}" sent successfully.`)):console.warn(`[ExodeUI Analytics] GA4: window.gtag is not a function. Event "${i}" skipped.`)}if(a.meta){const h=window;typeof h.fbq=="function"?(h.fbq("track",i,n),console.log(`[ExodeUI Analytics] Meta Pixel: Event "${i}" sent successfully.`)):console.warn(`[ExodeUI Analytics] Meta Pixel: window.fbq is not a function. Event "${i}" skipped.`)}if(a.mixpanel){const h=window;h.mixpanel&&typeof h.mixpanel.track=="function"?(h.mixpanel.track(i,n),console.log(`[ExodeUI Analytics] Mixpanel: Event "${i}" sent successfully.`)):console.warn(`[ExodeUI Analytics] Mixpanel: window.mixpanel.track is not a function. Event "${i}" skipped.`)}}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){if(!this.artboard)return;const i=this.artboard.animations.find(a=>a.id===t);if(!i)return;const n=`global_${t}_${Math.random().toString(36).substr(2,5)}`;this.layerStates.set(n,{currentStateIds:[t],animations:[{animation:i,state:{loop:o},filterObjectIds:s}],time:0,duration:i.duration,ruleId:e}),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;(this.artboard.animationFlow||[]).forEach(e=>{if(e.trigger==="after_anim"&&e.targetAnimationId&&(e.afterAnim===t||s&&e.afterAnim===s)){const n=e.delay||0;n<=0?this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id):setTimeout(()=>this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id),n)}})}getWorldTransform(t){var g;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,scaleX:1,scaleY:1,rotation:0};const o=(g=this.artboard)==null?void 0:g.objects.find(f=>f.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,l=s.y*e.scaleY,h=e.x+(r*n-l*a),c=e.y+(r*a+l*n);return{x:h,y:c,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,C;if(!this.objectStates.get(t.id))return!1;const i=((b=t.geometry)==null?void 0:b.width)??t.width??100,n=((C=t.geometry)==null?void 0:C.height)??t.height??100,a=this.getWorldTransform(t.id),r=s-a.x,l=o-a.y,h=-a.rotation*(Math.PI/180),c=Math.cos(h),g=Math.sin(h),f=r*c-l*g,d=r*g+l*c,p=a.scaleX,m=a.scaleY,y=i*Math.abs(p),v=n*Math.abs(m);return Math.abs(f)<=y/2&&Math.abs(d)<=v/2}updateSliderValueFromPointer(t,s,o){var w;const e=this.objectStates.get(t.id);if(!e)return;const i=t.options||{},n=((w=t.geometry)==null?void 0:w.width)??t.width??200,a=this.getWorldTransform(t.id),r=s-a.x,l=o-a.y,h=-a.rotation*(Math.PI/180),c=Math.cos(h),g=Math.sin(h),f=r*c-l*g,d=i.thumbWidth??16,p=n-d;let y=(f+p/2)/p;y=Math.max(0,Math.min(1,y));const v=i.min??0,b=i.max??100,C=i.step||1;let S=v+y*(b-v);C>0&&(S=Math.round(S/C)*C),S=Math.max(v,Math.min(b,S));const I=e.options||{};I.value!==S&&(e.options={...I,value:S},t.inputId&&this.setInternalInput(t.inputId,S),this.onComponentChange&&this.onComponentChange({objectId:t.id,componentName:t.name,variant:"slider",property:"value",value:S}))}applyAnimation(t,s,o){!t||!t.tracks||t.tracks.forEach(e=>{var c,g,f;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=(c=this.artboard)==null?void 0:c.objects.find(d=>d.id===i),a=((g=n==null?void 0:n.physics)==null?void 0:g.enabled)&&n.physics.bodyType!=="Static";let r=e.property;if(a&&(r==="x"||r==="y"||r==="rotation"))return;const l=this.objectStates.get(i);if(!l){this.frameCount%600===0&&this.debugLog(`Skipping track: Object ${i} not found in state`);return}const h=this.interpolate(e.keyframes,s);if(h!==void 0){if(this.frameCount%240===0){const d=(n==null?void 0:n.name)||i,p=typeof h=="object"?JSON.stringify(h).slice(0,50):h;this.debugLog(`[Anim] Applying ${r} = ${p} to ${d}`)}if(r.includes(".")){const d=(r||"").split(".");let p=l;for(let m=0;m<d.length-1;m++){if(typeof p[d[m]]!="object"||p[d[m]]===null){let y=n;for(let v=0;v<=m;v++)y=y?y[d[v]]:null;if(d[m]==="corner_radius"||d[m]==="cornerRadius"){const v=typeof p[d[m]]=="number"?p[d[m]]:typeof y=="number"?y:0;p[d[m]]={tl:v,tr:v,bl:v,br:v}}else p[d[m]]=y?JSON.parse(JSON.stringify(y)):{}}p=p[d[m]]}p[d[d.length-1]]=h,d[d.length-1]==="color"&&(d[d.length-2]==="fill"||d[d.length-2]==="stroke")&&(p.type="Solid")}else r==="fill"?(l.style||(l.style={}),l.style.fill=h):r==="stroke"?(l.style||(l.style={}),l.style.stroke=h):l[r]=h;if(this.physicsEngine&&((f=n==null?void 0:n.physics)!=null&&f.enabled)&&n.physics.bodyType==="Static")if(r==="x"){const d=this.physicsEngine.getPosition(i);d&&this.physicsEngine.setPosition(i,h,d.y)}else if(r==="y"){const d=this.physicsEngine.getPosition(i);d&&this.physicsEngine.setPosition(i,d.x,h)}else r==="rotation"&&this.physicsEngine.setRotation(i,h*(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;if(o.easing&&(n=si(o.easing)(n)),typeof o.value=="string"){if(o.value.startsWith("#"))return this.interpolateColor(o.value,e.value,n);const a=parseFloat(o.value),r=parseFloat(e.value);return!isNaN(a)&&!isNaN(r)?Math.round(a+(r-a)*n).toString():o.value}if(Array.isArray(o.value)&&Array.isArray(e.value))return o.value.length===e.value.length?o.value.map((a,r)=>{const l=e.value[r];return typeof a=="number"&&typeof l=="number"?a+(l-a)*n:n<.5?a:l}):n<.5?o.value:e.value;if(typeof o.value=="object"&&typeof e.value=="object"&&o.value!==null&&e.value!==null){if(o.value.width!==void 0&&o.value.color!==void 0)return this.interpolateStroke(o.value,e.value,n);if(o.value.type&&e.value.type)return this.interpolateFill(o.value,e.value,n);const a={};return new Set([...Object.keys(o.value),...Object.keys(e.value)]).forEach(l=>{const h=o.value[l],c=e.value[l];typeof h=="number"&&typeof c=="number"?a[l]=h+(c-h)*n:h===void 0?a[l]=c:c===void 0?a[l]=h:a[l]=n<.5?h:c}),a}return typeof o.value=="number"&&typeof e.value=="number"?o.value+(e.value-o.value)*n:n<.5?o.value:e.value}interpolateColor(t,s,o){var d,p;const e=((p=(d=this.artboard)==null?void 0:d.tokens)==null?void 0:p.colors)||{},i=e[t]||t,n=e[s]||s,a=m=>{if(!m)return{r:0,g:0,b:0};const y=m.startsWith("#")?m.replace("#",""):"000000";return y.length===3?{r:parseInt(y[0]+y[0],16),g:parseInt(y[1]+y[1],16),b:parseInt(y[2]+y[2],16)}:{r:parseInt(y.substring(0,2),16),g:parseInt(y.substring(2,4),16),b:parseInt(y.substring(4,6),16)}},r=a(i),l=a(n),h=Math.round(r.r+(l.r-r.r)*o),c=Math.round(r.g+(l.g-r.g)*o),g=Math.round(r.b+(l.b-r.b)*o),f=m=>{const y=Math.max(0,Math.min(255,m)).toString(16);return y.length===1?"0"+y:y};return`#${f(h)}${f(c)}${f(g)}`}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 h;this.debug_objectsTotal=((h=this.artboard)==null?void 0:h.objects.length)||0,this.debug_objectsRendered=0;const e=performance.now();if(this.canvasWidth=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),t.translate(i/2,n/2),this.rootTransform=t.getTransform(),this.artboard.backgroundVisible!==!1&&(t.fillStyle=this.artboard.backgroundColor||"#000000",t.fillRect(-i/2,-n/2,i,n)),this.artboard.backgroundImage){const c=this.artboard.backgroundImage;let g=this.imageCache.get(c);if(g||(g=new Image,g.src=c,this.imageCache.set(c,g)),g.complete&&g.naturalWidth>0){t.save(),t.globalAlpha=this.normalizeOpacity(this.artboard.backgroundOpacity??100);const f=g.naturalWidth/g.naturalHeight,d=i/n;let p,m,y,v;d>f?(p=i,m=i/f):(m=n,p=n*f),y=-p/2,v=-m/2,t.drawImage(g,y,v,p,m),t.restore()}}t.beginPath(),t.rect(-i/2,-n/2,i,n),t.clip();const r=new Map;this.artboard.objects.forEach(c=>r.set(c.id,c)),this.artboard.objects.filter(c=>!c.parentId).map((c,g)=>{const f=this.objectStates.get(c.id),d=(f==null?void 0:f.zIndex)??g;return{obj:c,zIndex:d}}).sort((c,g)=>c.zIndex-g.zIndex).forEach(({obj:c})=>{this.renderObject(t,c,r)}),this._emitterPools.forEach((c,g)=>{if(!(c.length===0||!r.get(g)))for(const d of c)t.save(),t.globalAlpha=d.opacity,t.fillStyle=d.color,t.beginPath(),t.arc(d.x,d.y,Math.max(1,d.size*d.opacity),0,Math.PI*2),t.fill(),t.restore()}),this.lastRenderTime=performance.now()-e,this.debugMode&&this.frameCount%60===0&&console.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,l=s*a.b+o*a.d+a.f,h=Math.sqrt(a.a*a.a+a.b*a.b),c=Math.sqrt(a.c*a.c+a.d*a.d),g=(e/2+n)*h,f=(i/2+n)*c;return r+g>=0&&r-g<=this.canvasWidth&&l+f>=0&&l-f<=this.canvasHeight}calculateTransform(t,s,o,e,i,n){let a=1,r=1,l=1;const h=o/e,c=t/s;switch(i){case"Contain":c>h?l=s/e:l=t/o,a=r=l;break;case"Cover":c>h?l=t/o:l=s/e,a=r=l;break;case"Fill":a=t/o,r=s/e;break;case"FitWidth":l=t/o,a=r=l;break;case"FitHeight":l=s/e,a=r=l;break;case"None":a=r=1;break;case"ScaleDown":l=Math.min(t/o,s/e),l>1&&(l=1),a=r=l;break;default:a=r=1;break}const g=o*a,f=e*r;let d=0,p=0;return n.includes("Left")?d=0:n.includes("Right")?d=t-g:d=(t-g)/2,n.includes("Top")?p=0:n.includes("Bottom")?p=s-f:p=(s-f)/2,{scaleX:a,scaleY:r,tx:d,ty:p}}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){var p,m,y,v,b,C,S,I,w,M,_,T,$,k,E,L,O;const e=this.objectStates.get(s.id);if(!e){console.warn("No state for object:",s.id);return}this.frameCount%60,t.roundRect||(t.roundRect=(A,W,x,Y,H)=>(this.drawRoundRect(t,A,W,x,Y,H),t));const i=e.geometry?this.deepMerge(s.geometry,e.geometry):s.geometry,n=e.style?this.deepMerge(s.style,e.style):s.style;let a=(i==null?void 0:i.width)||((p=s.geometry)==null?void 0:p.width)||s.width||0,r=(i==null?void 0:i.height)||((m=s.geometry)==null?void 0:m.height)||s.height||0;if((a===0||r===0)&&(i!=null&&i.points)&&Array.isArray(i.points)&&i.points.length>0){let A=1/0,W=-1/0,x=1/0,Y=-1/0;i.points.forEach(H=>{A=Math.min(A,H.x),W=Math.max(W,H.x),x=Math.min(x,H.y),Y=Math.max(Y,H.y)}),a===0&&(a=W-A),r===0&&(r=Y-x)}const l=A=>{if(A)return A.corner_radius??A.cornerRadius},h=l(e)??l(n)??l(i)??l(s.style)??l(s.geometry)??0;let c={...i,width:a,height:r};if(delete c.cornerRadius,c.corner_radius=h,c.type==="Path"&&s.weights&&s.bindMatrices&&c.points){const A=this.getGlobalTransform(s.id);if(A){const W=ii(c.points,s.weights,s.bindMatrices,A,x=>this.getGlobalTransform(x));c={...c,points:W}}}if(e.visible===!1)return;const g=s.repeaterConfig,f=g&&g.isEnabled&&g.count>1,d=f?g.count:1;for(let A=0;A<d;A++){let W=e.x,x=e.y,Y=e.rotation,H=e.scale_x??1,Q=e.scale_y??1;if(f&&A>0){if(g.type==="Linear"){const K=g.offsetX||0,ft=g.offsetY||0,q=g.rotation||0,X=g.scale!==void 0?g.scale:1;W+=A*K,x+=A*ft,Y+=A*q,H*=Math.pow(X,A),Q*=Math.pow(X,A)}else if(g.type==="Grid"){const K=g.cols||Math.ceil(Math.sqrt(g.count)),ft=g.gapX||0,q=g.gapY||0,X=Math.floor(A/K),Z=A%K,j=a+ft,At=r+q;W+=Z*j,x+=X*At}else if(g.type==="Radial"){const K=g.radius||100,ft=g.startAngle||0,X=(g.endAngle||360)-ft,Z=g.count>1?X/(X===360?g.count:g.count-1):0,j=ft+A*Z,At=j*Math.PI/180;W=e.x+K*Math.cos(At),x=e.y+K*Math.sin(At),Y+=j}}const P=s.type==="Group"||s.type==="Frame"||s.type==="Component",F=a>0&&r>0;if(!P&&F){const K=(((y=n.shadow)==null?void 0:y.isEnabled)!==!1?(((v=n.shadow)==null?void 0:v.blur)||0)+10:0)+(((b=n.blur)==null?void 0:b.isEnabled)!==!1&&((C=n.blur)==null?void 0:C.radius)||0)+20;if(!this.isObjectInView(t,W,x,a,r,K))continue}this.debug_objectsRendered++,t.save();const U=[],J=n.blur||((S=s.style)==null?void 0:S.blur);J&&J.amount>0&&U.push(`blur(${J.amount}px)`);const it=n.effect||((I=s.style)==null?void 0:I.effect),dt=(it==null?void 0:it.isEnabled)===!0,yt=it==null?void 0:it.type,ht=(it==null?void 0:it.radius)??10;dt&&yt==="LayerBlur"&&U.push(`blur(${ht}px)`);const ut=((w=i==null?void 0:i.type)==null?void 0:w.toLowerCase().includes("image"))||((M=s.type)==null?void 0:M.toLowerCase().includes("image")),ot=n.adjustments&&Object.keys(n.adjustments).length>0?n.adjustments:null,Et=i!=null&&i.adjustments&&Object.keys(i.adjustments).length>0?i.adjustments:null,Ft=ut?Et||ot:ot||Et,wt=ut&&!Ft?{exposure:0,contrast:0,saturation:100,temperature:0,tint:0,highlights:0,shadows:0,blur:0,negative:0,hue:0}:Ft;if(e&&wt&&(e.geometry=e.geometry||{},e.geometry.adjustments={...wt}),wt){const K=(wt.exposure||0)/100,ft=wt.contrast||0,q=1+(wt.saturation||0)/100,X=(wt.temperature||0)/200,Z=(wt.tint||0)/200,j=(wt.highlights||0)/500,At=(wt.shadows||0)/500;let Lt="",Tt="SourceGraphic";if(K!==0&&(Lt+=`
|
|
8
|
-
<feComponentTransfer in="${
|
|
9
|
-
<feFuncR type="linear" slope="1" intercept="${
|
|
10
|
-
<feFuncG type="linear" slope="1" intercept="${
|
|
11
|
-
<feFuncB type="linear" slope="1" intercept="${
|
|
12
|
-
</feComponentTransfer>`,
|
|
13
|
-
<feComponentTransfer in="${
|
|
14
|
-
<feFuncR type="linear" slope="${
|
|
15
|
-
<feFuncG type="linear" slope="${
|
|
16
|
-
<feFuncB type="linear" slope="${
|
|
17
|
-
</feComponentTransfer>`,
|
|
18
|
-
<feColorMatrix in="${
|
|
19
|
-
values="${
|
|
20
|
-
0 ${
|
|
21
|
-
0 0 ${
|
|
22
|
-
0 0 0 1 0"/>`,Tt="invert"}if(X!==0||Z!==0||j!==0||At!==0){const vt=1+j+At,R=vt*(1+X-Z/2),ct=vt*(1+Z),zt=vt*(1-X-Z/2),Ot=wt.shadows*.1/255,ie=[R,0,0,0,Ot,0,ct,0,0,Ot,0,0,zt,0,Ot,0,0,0,1,0].join(" ");Lt+=`<feColorMatrix in="${Tt}" type="matrix" values="${ie}" result="advanced"/>`,Tt="advanced"}if(wt.blur&&(Lt+=`<feGaussianBlur in="${Tt}" stdDeviation="${wt.blur}" result="blur"/>`,Tt="blur"),Lt){const vt=`<svg xmlns="http://www.w3.org/2000/svg"><filter id="f" color-interpolation-filters="sRGB">${Lt}</filter></svg>`,R=btoa(vt);U.push(`url('data:image/svg+xml;base64,${R}#f')`)}}U.length>0?t.filter=U.join(" "):t.filter="none",t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";const Gt=t.globalAlpha,Yt=this.normalizeOpacity(e.opacity!==void 0?e.opacity:100);t.globalAlpha=Gt*Yt;const B=e.compositeOperation||e.blendMode;if(B&&B!=="Normal"){const K=B.toLowerCase();["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity","source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","copy","xor","multiply","screen"].includes(K)&&(t.globalCompositeOperation=K)}const nt=t,Vt=e.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 kt=!1;const _t=Vt.filter(K=>K.isVisible!==!1&&o.has(K.maskId));if(_t.length>0){const K=_t[0],ft=o.get(K.maskId),q=this.objectStates.get(ft.id);q&&q.visible!==!1&&(kt=!0,(!this.maskBuffer||this.maskBuffer.width!==this.canvasWidth||this.maskBuffer.height!==this.canvasHeight)&&(this.maskBuffer=document.createElement("canvas"),this.maskBuffer.width=this.canvasWidth,this.maskBuffer.height=this.canvasHeight,this.maskCtx=this.maskBuffer.getContext("2d",{willReadFrequently:!0}),this.maskCtx&&(this.maskCtx.imageSmoothingEnabled=!0,this.maskCtx.imageSmoothingQuality="high")),this.maskCtx.setTransform(1,0,0,1,0,0),this.maskCtx.globalCompositeOperation="source-over",this.maskCtx.globalAlpha=1,this.maskCtx.filter="none",this.maskCtx.clearRect(0,0,this.maskBuffer.width,this.maskBuffer.height),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),s.parentId&&this.applyAbsoluteTransform(this.maskCtx,s.parentId,o),this.maskCtx.save(),this.maskCtx.globalAlpha=1,t=this.maskCtx,t.filter=nt.filter)}t.translate(Math.round(W),Math.round(x)),t.rotate(Y*Math.PI/180);const Nt=e.skew_x||0,Jt=e.skew_y||0;(Nt!==0||Jt!==0)&&t.transform(1,Math.tan(Jt*Math.PI/180),Math.tan(Nt*Math.PI/180),1,0,0);const Kt=e.rotate_x||0,Qt=e.rotate_y||0,te=(e.flip_x===!0?-1:1)*Math.cos(Qt*Math.PI/180),ce=(e.flip_y===!0?-1:1)*Math.cos(Kt*Math.PI/180);t.scale(H*te,Q*ce),n.shadow&&n.shadow.isEnabled!==!0&&((n.shadow.blur||0)>0||Math.abs(n.shadow.offsetX||0)>0||Math.abs(n.shadow.offsetY||0)>0)&&(n.shadow.isEnabled=!0);const se=n.shadow;if(se&&se.isEnabled!==!1){let K=se.color||"#000000";(T=(_=this.artboard)==null?void 0:_.tokens)!=null&&T.colors&&this.artboard.tokens.colors[K]&&(K=this.artboard.tokens.colors[K]);const ft=this.normalizeOpacity(se.opacity??100),q=se.spread||0,Z=(se.blur||0)+q*1.5;let j=K;if(K.startsWith("#")){const Tt=K.replace("#",""),Ut=parseInt(Tt.substring(0,2),16),vt=parseInt(Tt.substring(2,4),16),R=parseInt(Tt.substring(4,6),16);j=`rgba(${Ut}, ${vt}, ${R}, ${ft})`}else if(K.startsWith("rgba")){const Tt=K.match(/[\d.]+/g);if(Tt&&Tt.length>=4){const Ut=Tt[0],vt=Tt[1],R=Tt[2],ct=Tt[3];j=`rgba(${Ut}, ${vt}, ${R}, ${parseFloat(ct)*ft})`}}const At=t.getTransform(),Lt=Math.sqrt(At.a*At.a+At.b*At.b)||1;t.shadowColor=j,t.shadowBlur=Z*Lt,t.shadowOffsetX=(se.offsetX||0)*Lt,t.shadowOffsetY=(se.offsetY||0)*Lt}const ne=s.liquidFill||(($=s.style)==null?void 0:$.liquidFill);if(ne&&ne.enabled){t.save();const K=ne.fillLevel??.5;t.beginPath();const ft=r/2-r*K;t.rect(-a/2,ft,a,r*K),t.clip(),t.fillStyle=ne.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(ne.opacity??1)}if((i==null?void 0:i.type)==="Text")this._renderText(t,s,c,n,e,a,r);else if((i==null?void 0:i.type)==="Image"){const K=i.originalSrc||i.src;if(K){let ft=this.imageCache.get(K);ft||(ft=new Image,ft.onload=()=>{console.log(`[ExodeUI] Image loaded successfully, size: ${ft.naturalWidth}x${ft.naturalHeight}`)},ft.onerror=Z=>{console.error("[ExodeUI] Image load failed:",Z,`Src preview: ${K.substring(0,100)}...`)},ft.src=K,this.imageCache.set(K,ft));const q=n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1,X=(((k=n.stroke)==null?void 0:k.alignment)||"center").toLowerCase();if(q&&(X==="outside"||X==="center")&&this.applyStrokeAlignment(t,n,c,a,r,h),n.fill&&n.fill.type!=="None"){t.save();const Z=t.globalAlpha,j=this.createCanvasFill(t,n.fill,a,r);t.fillStyle=j||n.fill.color||"transparent",t.globalAlpha=Z*this.normalizeOpacity(n.fill.opacity??100),h!==0?(this.drawRoundRect(t,-a/2,-r/2,a,r,h),t.fill()):t.fillRect(-a/2,-r/2,a,r),t.globalAlpha=Z,t.restore()}ft.complete&&ft.naturalWidth>0?(h!==0?(t.save(),this.drawRoundRect(t,-a/2,-r/2,a,r,h),t.clip(),t.drawImage(ft,-a/2,-r/2,a,r),t.restore()):t.drawImage(ft,-a/2,-r/2,a,r),q&&X==="inside"&&this.applyStrokeAlignment(t,n,c,a,r,h)):q&&X==="inside"&&this.applyStrokeAlignment(t,n,c,a,r,h)}}else if(i.type==="SVG"){const K=i.svgContent;if(K){const ft=n.palette||[],q=n.fill,X=n.stroke,Z=q?this.normalizeOpacity(q.opacity??100):1,j=(q==null?void 0:q.type)==="Solid"&&(!X||X.isEnabled===!1||X.type==="Solid"&&X.color===q.color),At=q&&q.type!=="None"?j?"monochrome":q.type==="Solid"?(q.color||"")+"|opacity:"+Z:JSON.stringify(q.stops||[])+"|opacity:"+Z:"",Lt=X&&X.isEnabled!==!1&&(X.width||0)>0?j?["monochrome",X.width||0,X.trimStart??0,X.trimEnd??1,X.trimOffset??0,X.dashOffset??0].join("|"):[X.width||0,X.fill?X.fill.type==="Solid"?X.fill.color||"":JSON.stringify(X.fill.stops||[]):X.color||"",X.opacity??1,X.lineCap||"",X.lineJoin||"",(X.dashArray||[]).join(","),X.trimStart??0,X.trimEnd??1,X.trimOffset??0,X.dashOffset??0].join("|"):"nostroke",Tt=[s.id,ft.join("_"),At,Lt,e.opacity??100,e.visible!==!1?"v":"h"].join("_");let Ut=this.imageCache.get(Tt);if(!Ut){Ut=new Image,Ut.crossOrigin="anonymous";let R=K;R.match(/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i)||(R=R.replace(/<svg([^>]*)>/i,(rt,It)=>`<svg xmlns="http://www.w3.org/2000/svg"${It}>`));let ct=i.width||a||100,zt=i.height||r||100;const Ot=R.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(Ot&&(ct=parseFloat(Ot[1]),zt=parseFloat(Ot[2])),R=R.replace(/<svg([^>]*)>/i,(rt,It)=>{let Ct=It.replace(/\b(?:width|height)=["'][^"']*["']/gi," ");return Ct.match(/\bviewBox=/i)||(Ct+=` viewBox="0 0 ${ct} ${zt}"`),Ct.match(/\bpreserveAspectRatio=/i)||(Ct+=' preserveAspectRatio="none"'),Ct+=' width="100%" height="100%"',`<svg${Ct}>`}),i.colors&&i.colors.length>0&&ft.length>0&&i.colors.forEach((rt,It)=>{if(ft[It]){const Ct=rt.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),St=new RegExp(Ct,"gi");R=R.replace(St,ft[It])}}),q&&q.type&&q.type!=="None"){if(q.type==="Solid"&&q.color){const rt=j?"#FFFFFF":q.color,It=j?1:this.normalizeOpacity(q.opacity??100);R=R.replace(/\bfill\s*=\s*["'][^"']*["']/gi,Ct=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Ct)?Ct:`fill="${rt}"`),R=R.replace(/fill\s*:\s*[^;"')]+/gi,Ct=>/fill\s*:\s*(none|transparent)/i.test(Ct)?Ct:`fill:${rt}`),It<1&&(R=R.replace(/\bfill-opacity\s*=\s*["'][^"']*["']/gi,`fill-opacity="${It}"`),R=R.replace(/fill-opacity\s*:\s*[^;"')]+/gi,`fill-opacity:${It}`),R.match(/\bfill-opacity\s*=/i)||(R=R.replace(/(<svg[^>]*>)/i,`$1<g fill-opacity="${It}">`),R=R.replace(/<\/svg>/i,"</g></svg>")))}else if(q.type==="LinearGradient"||q.type==="RadialGradient"||q.type==="Linear"||q.type==="Radial"){const rt="exode-fill",It=this.normalizeOpacity(q.opacity??100),Ct=(q.stops||[]).map(mt=>{const Rt=mt.offset!==void 0?mt.offset:mt.pos??0,lt=this.normalizeOpacity(mt.opacity??100)*It;return`<stop offset="${Rt*100}%" stop-color="${mt.color||"#000"}" stop-opacity="${lt}"/>`}).join("");let St="";if(q.type==="LinearGradient"||q.type==="Linear"){const mt=(Mt,V)=>Array.isArray(Mt)?Mt[V]??(V===0?0:1):Mt&&typeof Mt=="object"?Mt[V===0?"x":"y"]??(V===0?0:1):V===0?0:1,Rt=mt(q.start,0)*100,lt=mt(q.start,1)*100,st=mt(q.end,0)*100,at=mt(q.end,1)*100;St=`<linearGradient id="${rt}" x1="${Rt}%" y1="${lt}%" x2="${st}%" y2="${at}%" gradientUnits="objectBoundingBox">${Ct}</linearGradient>`}else{const mt=(at,Mt)=>Array.isArray(at)?at[Mt]??.5:at&&typeof at=="object"?at[Mt===0?"x":"y"]??.5:.5,Rt=mt(q.center,0)*100,lt=mt(q.center,1)*100,st=(q.radius??.5)*100;St=`<radialGradient id="${rt}" cx="${Rt}%" cy="${lt}%" r="${st}%" gradientUnits="objectBoundingBox">${Ct}</radialGradient>`}/<defs>/i.test(R)?R=R.replace(/<defs>/i,`<defs>${St}`):R=R.replace(/<svg([^>]*)>/i,`<svg$1><defs>${St}</defs>`),R=R.replace(/\bfill\s*=\s*["'][^"']*["']/gi,mt=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(mt)?mt:`fill="url(#${rt})"`),R=R.replace(/fill\s*:\s*[^;"')]+/gi,mt=>/fill\s*:\s*(none|transparent)/i.test(mt)?mt:`fill:url(#${rt})`)}}const ie=(rt,It,Ct=1)=>{const St=(rt.stops||[]).map(at=>{const Mt=at.offset!==void 0?at.offset:at.pos??0,V=this.normalizeOpacity(at.opacity??100)*Ct;return`<stop offset="${Mt*100}%" stop-color="${at.color||"#000"}" stop-opacity="${V}"/>`}).join(""),mt=(at,Mt,V=.5)=>Array.isArray(at)?at[Mt]??V:at&&typeof at=="object"?at[Mt===0?"x":"y"]??V:V;if(rt.type==="LinearGradient"||rt.type==="Linear"){const at=mt(rt.start,0,0)*100,Mt=mt(rt.start,1,0)*100,V=mt(rt.end,0,1)*100,pt=mt(rt.end,1,1)*100;return`<linearGradient id="${It}" x1="${at}%" y1="${Mt}%" x2="${V}%" y2="${pt}%" gradientUnits="objectBoundingBox">${St}</linearGradient>`}const Rt=mt(rt.center,0,.5)*100,lt=mt(rt.center,1,.5)*100,st=(rt.radius??.5)*100;return`<radialGradient id="${It}" cx="${Rt}%" cy="${lt}%" r="${st}%" gradientUnits="objectBoundingBox">${St}</radialGradient>`},Bt=(rt,It)=>/<defs>/i.test(rt)?rt.replace(/<defs>/i,`<defs>${It}`):rt.replace(/(<svg[^>]*>)/i,`$1<defs>${It}</defs>`);if(X&&X.isEnabled!==!1&&(X.width||0)>0){const rt=j?1:this.normalizeOpacity(X.opacity??100),It=j?"#FFFFFF":X.color||(q==null?void 0:q.color)||"#000000";let Ct="";const St=X.fill;if(St&&St.type){if(St.type==="Solid")Ct=St.color||X.color||"#000000";else if(St.type==="LinearGradient"||St.type==="RadialGradient"||St.type==="Linear"||St.type==="Radial"){const qt="exode-stroke";R=Bt(R,ie(St,qt,rt)),Ct=`url(#${qt})`}}Ct||(Ct=It),R.match(/\bstroke\s*=\s*["']/i)?R=R.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,qt=>/stroke\s*=\s*["']\s*(none|transparent)\s*["']/i.test(qt)?qt:`stroke="${Ct}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke="${Ct}"`),R=R.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),`stroke:${Ct}`);let mt=i.width||a||100,Rt=i.height||r||100;const lt=K.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(lt){const qt=parseFloat(lt[1]),oe=parseFloat(lt[2]);!isNaN(qt)&&!isNaN(oe)&&(mt=qt,Rt=oe)}const st=Math.max(.001,a/mt),at=Math.max(.001,r/Rt),Mt=(st+at)/2,V=(X.width||1)/Mt;R.match(/\bstroke-width\s*=\s*["']/i)?R=R.replace(/\bstroke-width\s*=\s*["'][^"']*["']/gi,`stroke-width="${V}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-width="${V}"`),R=R.replace(/stroke-width\s*:\s*[^;"')]+/gi,`stroke-width:${V}`),R.match(/\bstroke-opacity\s*=\s*["']/i)?R=R.replace(/\bstroke-opacity\s*=\s*["'][^"']*["']/gi,`stroke-opacity="${rt}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-opacity="${rt}"`),R=R.replace(/stroke-opacity\s*:\s*[^;"')]+/gi,`stroke-opacity:${rt}`);const pt=X.lineCap||"round";R.match(/\bstroke-linecap\s*=\s*["']/i)?R=R.replace(/\bstroke-linecap\s*=\s*["'][^"']*["']/gi,`stroke-linecap="${pt}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linecap="${pt}"`),R=R.replace(/stroke-linecap\s*:\s*[^;"')]+/gi,`stroke-linecap:${pt}`);const gt=X.lineJoin||"round";R.match(/\bstroke-linejoin\s*=\s*["']/i)?R=R.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${gt}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linejoin="${gt}"`),R=R.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${gt}`);const de=X.trimStart??0,be=X.trimEnd??1,Se=X.trimOffset??0,Ie=X.dashOffset??0,_e=de!==0||be!==1||Se!==0||Ie!==0;if(_e){const qt=Math.max(0,Math.min(1,de)),oe=Math.max(0,Math.min(1,be));this.frameCount%600===0&&this.debugLog(`SVG Trim - Object: ${s.name||s.id}, Start: ${qt}, End: ${oe}`);const ye=(mt+Rt)*2,we=(Se%1+1)%1,Me=(Ie%1+1)%1;let ue="",fe=0;if(qt>=oe)ue=`0 ${ye}`,fe=0;else{const he=ye*(oe-qt),ve=ye-he;fe=-(ye*(qt+we+Me)),ue=`${he} ${ve}`}R.match(/\bstroke-dasharray\s*=/i)?R=R.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${ue}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dasharray="${ue}"`),R=R.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${ue}`),R.match(/\bstroke-dashoffset\s*=/i)?R=R.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${fe}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dashoffset="${fe}"`),R=R.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${fe}`)}else if(X.dashArray&&X.dashArray.length>0){const qt=X.dashArray.join(" ");R=R.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${qt}"`),R=R.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${qt}`),X.dashOffset&&(R=R.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${X.dashOffset}"`),R=R.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${X.dashOffset}`))}if(!/\bstroke\s*=\s*["']/i.test(K)&&!new RegExp("(?<![a-z-])stroke\\s*:","i").test(K)){let qt="",oe="";if(_e){const ue=i.width||a||100,fe=i.height||r||100,he=(ue+fe)*2,ve=Math.max(0,Math.min(1,de)),Pe=Math.max(0,Math.min(1,be)),Fe=(Se%1+1)%1,$e=(Ie%1+1)%1;if(ve>=Pe)qt=` stroke-dasharray="0 ${he}"`,oe=' stroke-dashoffset="0"';else{const Ee=he*(Pe-ve),We=he-Ee,Be=-(he*(ve+Fe+$e));qt=` stroke-dasharray="${Ee} ${We}"`,oe=` stroke-dashoffset="${Be}"`}}else(E=X.dashArray)!=null&&E.length&&(qt=` stroke-dasharray="${X.dashArray.join(" ")}"`,X.dashOffset&&(oe=` stroke-dashoffset="${X.dashOffset}"`));const ye=` stroke-linecap="${X.lineCap||"round"}"`,we=` stroke-linejoin="${X.lineJoin||"round"}"`,Me=`stroke="${Ct}" stroke-width="${V}" stroke-opacity="${rt}"${ye}${we}${qt}${oe}`;R=R.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(ue,fe,he)=>`${fe}${he}<g ${Me}>`),R=R.replace(/<\/svg>/i,"</g></svg>")}}else X&&X.isEnabled===!1&&(R=R.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,'stroke="none"'),R=R.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),"stroke:none"));const Xt=new Blob([R],{type:"image/svg+xml"}),$t=URL.createObjectURL(Xt);Ut.onload=()=>{if(URL.revokeObjectURL($t),this.frameCount%900===0){const rt=this.imageCache.get(Tt);rt&&this.debugLog(`SVG Payload Ready: ${s.name||s.id} (${rt.naturalWidth}x${rt.naturalHeight})`)}},Ut.onerror=()=>{URL.revokeObjectURL($t),this.debugLog(`SVG Error: Failed to load payload for ${s.name||s.id}`)},Ut.src=$t,this.imageCache.set(Tt,Ut)}let vt=null;if(Ut.complete&&Ut.naturalWidth>0?(vt=Ut,this.lastValidSvgImgMap.set(s.id,Ut)):vt=this.lastValidSvgImgMap.get(s.id)||null,vt&&vt.complete&&vt.naturalWidth>0){const R=Math.max(1,a),ct=Math.max(1,r);if(j&&(q==null?void 0:q.type)==="Solid"){this.maskBuffer||(this.maskBuffer=document.createElement("canvas"),this.maskCtx=this.maskBuffer.getContext("2d")),this.maskBuffer.width=R,this.maskBuffer.height=ct,this.maskCtx.setTransform(1,0,0,1,0,0),this.maskCtx.globalCompositeOperation="source-over",this.maskCtx.globalAlpha=1,this.maskCtx.filter="none",this.maskCtx.clearRect(0,0,R,ct),this.maskCtx.drawImage(vt,0,0,R,ct),this.maskCtx.globalCompositeOperation="source-in";const zt=q.color||"#000000",Ot=this.normalizeOpacity(q.opacity??100);this.maskCtx.fillStyle=zt,this.maskCtx.globalAlpha=Ot,this.maskCtx.fillRect(0,0,R,ct),t.drawImage(this.maskBuffer,-R/2,-ct/2,R,ct)}else h!==0?(t.save(),this.drawRoundRect(t,-R/2,-ct/2,R,ct,h),t.clip(),t.drawImage(vt,-R/2,-ct/2,R,ct),t.restore()):t.drawImage(vt,-R/2,-ct/2,R,ct)}}}else if(c.type==="LineGraph")this.renderLineGraph(t,c,a,r);else if(s.type==="Shape"){if(this.applyPath(t,c,a,r,h),t.save(),n.blur&&n.blur.amount>0&&(t.filter=`blur(${n.blur.amount}px)`),n.fill){const K=t.globalAlpha;if(((L=n.fill)==null?void 0:L.type)==="Image"&&(n.fill.originalSrc||n.fill.src)){const ft=n.fill.originalSrc||n.fill.src;let q=this.imageCache.get(ft);q||(q=new Image,q.src=ft,this.imageCache.set(ft,q)),q.complete&&q.naturalWidth>0&&(t.save(),this.applyPath(t,c,a,r,h),t.clip(),this.renderFittedImage(t,q,-a/2,-r/2,a,r,n.fill.fillMode),t.restore())}else{const ft=this.createCanvasFill(t,n.fill,a,r);t.fillStyle=ft||(typeof n.fill=="string"?n.fill:n.fill.color||"transparent"),t.globalAlpha=K*this.normalizeOpacity(n.fill.opacity??100),this.applyPath(t,c,a,r,h),t.fill()}t.globalAlpha=K}t.restore(),n.stroke&&n.stroke.width>0&&this.applyStrokeAlignment(t,n,c,a,r,h)}else if(s.type==="Frame"||s.type==="Group"&&!s.isStructuralGroup){const K=e.width??i.width??s.width??a,ft=e.height??i.height??s.height??r,q=h;if(t.save(),t.beginPath(),this.drawRoundRect(t,-K/2,-ft/2,K,ft,q),n.fill&&n.fill.type!=="None"){const X=t.globalAlpha,Z=this.createCanvasFill(t,n.fill,K,ft);t.fillStyle=Z||n.fill.color||"transparent",t.globalAlpha=X*this.normalizeOpacity(n.fill.opacity??100),t.fill(),t.globalAlpha=X}if(t.restore(),n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1){const X={type:"Rectangle"};this.applyStrokeAlignment(t,n,X,K,ft,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):this.frameCount%60===0&&console.warn("[Engine] Unhandled object type in renderObject:",s.type,"Geo:",(O=s.geometry)==null?void 0:O.type));if(this.applyArtEffectOverlay(t,s,c,a,r,h),dt&&yt==="BackgroundBlur"&&this.applyBackgroundBlurGlass(t,c,a,r,h,it),ne&&ne.enabled&&t.restore(),s.children&&s.children.length>0){const ft=s.type==="Frame",q=s.clipsContent!==void 0?s.clipsContent:s.clipContent!==void 0?s.clipContent:ft;if(t.save(),q){t.beginPath();const Z=e.width??(i==null?void 0:i.width)??s.width??0,j=e.height??(i==null?void 0:i.height)??s.height??0,At=e.cornerRadius??(i==null?void 0:i.corner_radius)??s.cornerRadius??0;this.drawRoundRect(t,-Z/2,-j/2,Z,j,At),t.clip()}let X=0;for(s.children.forEach(Z=>{const j=o.get(Z);if(!j)return;const At=this.objectStates.get(Z),Lt=(At==null?void 0:At.geometry)||j.geometry;if(Lt&&Lt.isMask&&(At==null?void 0:At.visible)!==!1){const Tt=Lt.width||0,Ut=Lt.height||0;this.applyObjectTransform(t,Z);const vt=(At==null?void 0:At.corner_radius)??(Lt==null?void 0:Lt.corner_radius)??0;this.applyPath(t,Lt,Tt,Ut,vt),t.clip(),X++}else this.renderObject(t,j,o)});X>0;)t.restore(),X--;t.restore()}if(kt){this.maskCtx.restore(),(e.masks||(s.maskedBy?[{maskId:s.maskedBy,inverted:s.maskInverted===!0,type:s.maskType||"alpha",opacity:s.maskOpacity!==void 0?s.maskOpacity/100:1,feather:s.maskFeather||0,isVisible:!0}]:[])).filter(X=>X.isVisible!==!1&&o.has(X.maskId)).forEach(X=>{var vt,R,ct,zt,Ot,ie;const Z=o.get(X.maskId),j=this.objectStates.get(Z.id),At=X.feather||0,Lt=X.inverted===!0,Tt=X.opacity!==void 0?typeof X.opacity=="number"?X.opacity:X.opacity/100:1;if((X.type||"alpha")==="luma"){(!this.lumaBuffer||this.lumaBuffer.width!==this.maskBuffer.width||this.lumaBuffer.height!==this.maskBuffer.height)&&(this.lumaBuffer=document.createElement("canvas"),this.lumaBuffer.width=this.maskBuffer.width,this.lumaBuffer.height=this.maskBuffer.height,this.lumaCtx=this.lumaBuffer.getContext("2d",{willReadFrequently:!0}),this.lumaCtx&&(this.lumaCtx.imageSmoothingEnabled=!0,this.lumaCtx.imageSmoothingQuality="high")),this.lumaCtx.setTransform(1,0,0,1,0,0),this.lumaCtx.globalCompositeOperation="source-over",this.lumaCtx.globalAlpha=1,this.lumaCtx.filter="none",this.lumaCtx.clearRect(0,0,this.lumaBuffer.width,this.lumaBuffer.height),this.lumaCtx.save(),this.rootTransform&&this.lumaCtx.setTransform(this.rootTransform),this.applyAbsoluteTransform(this.lumaCtx,Z.id,o),At>0&&(this.lumaCtx.filter=`blur(${At}px)`),this.lumaCtx.globalAlpha=Tt;const Bt=(j==null?void 0:j.width)||Z.geometry.width||0,Xt=(j==null?void 0:j.height)||Z.geometry.height||0,$t=(j==null?void 0:j.corner_radius)??Z.corner_radius??0;if(((vt=Z.geometry)==null?void 0:vt.type)==="Text"){const St=j!=null&&j.geometry?this.deepMerge(Z.geometry,j.geometry):Z.geometry,mt=j!=null&&j.style?this.deepMerge(Z.style,j.style):Z.style;this._renderText(this.lumaCtx,Z,{...St,width:Bt,height:Xt,corner_radius:$t},mt,j,Bt,Xt,!0)}else if(((R=Z.geometry)==null?void 0:R.type)==="Image"){const St=Z.geometry.src;if(St){let mt=this.imageCache.get(St);mt||(mt=new Image,mt.src=St,this.imageCache.set(St,mt)),mt.complete&&mt.naturalWidth>0?this.lumaCtx.drawImage(mt,-Bt/2,-Xt/2,Bt,Xt):(this.applyPath(this.lumaCtx,Z.geometry,Bt,Xt,$t),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else if(((ct=Z.geometry)==null?void 0:ct.type)==="SVG"){const St=Z.geometry.svgContent;if(St){const mt=`__lumamask_${Z.id}`;let Rt=this.imageCache.get(mt);if(!Rt){Rt=new Image;const lt=new Blob([St],{type:"image/svg+xml"});Rt.src=URL.createObjectURL(lt),Rt.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(mt,Rt)}Rt.complete&&Rt.naturalWidth>0?this.lumaCtx.drawImage(Rt,-Bt/2,-Xt/2,Bt,Xt):(this.applyPath(this.lumaCtx,Z.geometry,Bt,Xt,$t),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else this.applyPath(this.lumaCtx,Z.geometry,Bt,Xt,$t),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill();this.lumaCtx.restore();const rt=this.maskCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight),It=this.lumaCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight).data,Ct=rt.data;for(let St=0;St<Ct.length;St+=4){const mt=It[St],Rt=It[St+1],lt=It[St+2];let st=(.299*mt+.587*Rt+.114*lt)/255;Lt&&(st=1-st),Ct[St+3]*=st}this.maskCtx.putImageData(rt,0,0)}else{this.maskCtx.save(),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),this.maskCtx.globalCompositeOperation=Lt?"destination-out":"destination-in",At>0&&(this.maskCtx.filter=`blur(${At}px)`),this.maskCtx.globalAlpha=Tt,this.applyAbsoluteTransform(this.maskCtx,Z.id,o);const Bt=(j==null?void 0:j.width)||Z.geometry.width||0,Xt=(j==null?void 0:j.height)||Z.geometry.height||0,$t=(j==null?void 0:j.corner_radius)??Z.corner_radius??0;if(((zt=Z.geometry)==null?void 0:zt.type)==="Text"){const rt=j!=null&&j.geometry?this.deepMerge(Z.geometry,j.geometry):Z.geometry,It=j!=null&&j.style?this.deepMerge(Z.style,j.style):Z.style;this._renderText(this.maskCtx,Z,{...rt,width:Bt,height:Xt,corner_radius:$t},It,j,Bt,Xt,!0)}else if(((Ot=Z.geometry)==null?void 0:Ot.type)==="Image"){const rt=Z.geometry.src;if(rt){let It=this.imageCache.get(rt);It||(It=new Image,It.src=rt,this.imageCache.set(rt,It)),It.complete&&It.naturalWidth>0?this.maskCtx.drawImage(It,-Bt/2,-Xt/2,Bt,Xt):(this.applyPath(this.maskCtx,Z.geometry,Bt,Xt,$t),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else if(((ie=Z.geometry)==null?void 0:ie.type)==="SVG"){const rt=Z.geometry.svgContent;if(rt){const It=`__alphamask_${Z.id}`;let Ct=this.imageCache.get(It);if(!Ct){Ct=new Image;const St=new Blob([rt],{type:"image/svg+xml"});Ct.src=URL.createObjectURL(St),Ct.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(It,Ct)}Ct.complete&&Ct.naturalWidth>0?this.maskCtx.drawImage(Ct,-Bt/2,-Xt/2,Bt,Xt):(this.applyPath(this.maskCtx,Z.geometry,Bt,Xt,$t),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else this.applyPath(this.maskCtx,Z.geometry,Bt,Xt,$t),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill();this.maskCtx.restore()}}),nt.save(),nt.setTransform(1,0,0,1,0,0);const q=s.maskBlendMode||s.blendMode;q&&q!=="Normal"&&(nt.globalCompositeOperation=q.toLowerCase()),nt.drawImage(this.maskBuffer,0,0),nt.restore(),nt.restore()}else t.restore()}}_renderText(t,s,o,e,i,n,a,r=!1,l=!1){var yt,ht,ut,ot,Et,Ft,wt,Gt,Yt;let h=o.text||"";if(o.textInputId&&!r){const B=this.inputs.get(o.textInputId);B!==void 0&&(h=String(B),i.geometry&&i.geometry.type==="Text"&&(i.geometry.text=h))}if(o.svgPath){const B=o.svgPath;t.save();const nt=((yt=e==null?void 0:e.fill)==null?void 0:yt.color)||"#000000",Vt=((ht=e==null?void 0:e.fill)==null?void 0:ht.opacity)!==void 0?(ut=e==null?void 0:e.fill)==null?void 0:ut.opacity:1;t.fillStyle=nt,t.globalAlpha*=Vt;const kt=new Path2D(B);t.fill(kt),t.restore();return}let c=h||"";o.enableSegments===!0&&o.segments&&Array.isArray(o.segments)&&(c=o.segments.map(B=>B&&B.text?B.text:"").join(""));const g=o.textCase||"none";g==="uppercase"?c=c.toUpperCase():g==="lowercase"?c=c.toLowerCase():g==="capitalize"&&(c=c.replace(/\b\w/g,B=>B.toUpperCase()));let f=((ot=o.fontWeight)==null?void 0:ot.toString())||"400",d=o.fontStyle||"normal";f.toLowerCase().includes("italic")&&(d="italic",f=f.replace(/italic/gi,"").trim()||"400");const p=this.mapFontWeight(f),m=Math.max(1,o.fontSize||32);let y=o.fontFamily||"Inter";const v=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];v.forEach(B=>{const nt=new RegExp(`[\\s-]${B}$`,"i");nt.test(y)&&(y=y.replace(nt,"").trim())});const S=`${o.smallCaps===!0?"small-caps ":""}${d} ${p} ${m}px "${y}", sans-serif`;t.font=S;const I=o.textVerticalAlign||"top";t.textBaseline="top";const w=o.textAlign||"left";t.textAlign=w;let M=0;if(typeof o.letterSpacing=="number")M=o.letterSpacing;else if(typeof o.letterSpacing=="object"&&o.letterSpacing.value!==void 0){const B=o.letterSpacing;M=B.unit==="PERCENT"?B.value/100*m:B.value}t.letterSpacing!==void 0&&(t.letterSpacing=`${M}px`);const _=o.kerning||"auto",T=o.kerningValue||0;_==="manual"&&T!==0&&(t.letterSpacing=`${M+T}px`);const $=o.paragraphSpacing||0;let k=o.lineHeight??1.2;typeof k=="string"&&(k=parseFloat(k)),k>5&&m>0&&(k=k/m);const E=(k||1.2)*m,L=o.isPointText===!0||!o.width||o.width<=0,O=((Et=o.padding)==null?void 0:Et.left)||((Ft=o.padding)==null?void 0:Ft.right)||0,A=L?1e5:o.width&&o.width>0?Math.ceil(o.width)-O*2:1e5;o.autoHeight;const W=De({text:c,fontFamily:y,fontSize:m,fontWeight:p,fontStyle:d,lineHeight:k,width:A,letterSpacing:M,paragraphSpacing:$,paragraphIndent:o.paragraphIndent||0,segments:o.segments,enableSegments:o.enableSegments,textCase:g,hyphenation:o.hyphenation,composer:o.composer,balanceRaggedLines:o.balanceRaggedLines}),x=W.lines||[],Y=W.maxFontSize||m,H=this.fontLeadingFactors[y]??.5,Q=(E-m)*H;let P=W.height,F=-P/2;a>0&&a>P&&(I==="top"?F=-a/2:I==="middle"||I==="center"?F=-P/2:I==="bottom"&&(F=a/2-P)),F+=Q;let U=null,J=0;if(o.pathId&&this.artboard){const B=this.artboard.objects.find(nt=>nt.id===o.pathId);if(B&&B.type==="Shape"&&((wt=B.geometry)==null?void 0:wt.type)==="Path"){const nt=this.objectStates.get(B.id),Vt=nt!=null&&nt.geometry?this.deepMerge(B.geometry,nt.geometry):B.geometry,kt=(nt==null?void 0:nt.scale_x)!==void 0?(B.width||0)*nt.scale_x:B.width||0,_t=(nt==null?void 0:nt.scale_y)!==void 0?(B.height||0)*nt.scale_y:B.height||0;U={geo:Vt,obj:B,w:kt,h:_t},J=this.getPerimeter(Vt,kt,_t)}}const it=(B,nt)=>{var kt,_t;if(M===0&&(!o.enableSegments||!((kt=o.segments)!=null&&kt.length)))return t.measureText(B).width;let Vt=0;for(let Nt=0;Nt<B.length;Nt++){const Jt=nt+Nt;let Kt=0;if(o.enableSegments===!0&&((_t=o.segments)==null?void 0:_t.length)>0){let Qt=0,te=null;for(const ce of o.segments){if(Jt<Qt+(ce.text||"").length){te=ce;break}Qt+=(ce.text||"").length}if(te){t.save();let ce=te.fontFamily||o.fontFamily||"Inter";const se=this.mapFontWeight((te.fontWeight||o.fontWeight||"400").toString()),ne=te.fontStyle||d,K=te.fontSize||m;t.font=`${ne} ${se} ${K}px "${ce}", sans-serif`,Kt=t.measureText(B[Nt]).width,t.restore()}else Kt=t.measureText(B[Nt]).width}else Kt=t.measureText(B[Nt]).width;Vt+=Kt+M}return Vt-(B.length>0?M:0)},dt=(B,nt,Vt,kt,_t)=>{var se,ne;const Jt=(_t===0||c[_t-1]===`
|
|
23
|
-
`||
|
|
24
|
-
|
|
25
|
-
`||c[
|
|
26
|
-
|
|
27
|
-
`||
|
|
28
|
-
`&&
|
|
29
|
-
`||
|
|
30
|
-
|
|
31
|
-
`&&kt++)}),t.globalAlpha=nt}}}applyStrokeAlignment(t,s,o,e,i,n){if(!s.stroke||s.stroke.width<=0||s.stroke.isEnabled===!1)return;const a=s.stroke,r=a.width,l=(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 y=this.createCanvasFill(t,a.fill,e,i);y?t.strokeStyle=y:t.strokeStyle=a.color||"#000000"}else t.strokeStyle=a.color||"#000000";const c=t.globalAlpha;t.globalAlpha=c*this.normalizeOpacity(a.opacity??100),t.lineWidth=r,t.lineCap=a.lineCap||"round",t.lineJoin=a.lineJoin||"round",a.miterLimit!==void 0&&(t.miterLimit=a.miterLimit);const g=a.trimStart??0,f=a.trimEnd??1,d=a.trimOffset??0,p=a.dashOffset??0,m=a.dashArray||[];if(g!==0||f!==1||d!==0){const y=this.getPerimeter(o,e,i);if(y>0){const v=Math.max(0,Math.min(1,g)),b=Math.max(0,Math.min(1,f));if(v<b){const C=y*(b-v),S=y-C,I=-(y*(v+d%1));t.setLineDash([C,S]),t.lineDashOffset=I+p*y}else if(v===b)t.setLineDash([0,y]);else{const C=y*(1-v+b),S=y-C,I=-(y*v);t.setLineDash([C,S]),t.lineDashOffset=I+p*y}}}else m.length>0&&(t.setLineDash(m),t.lineDashOffset=p);(o==null?void 0:o.type)==="Line"||e===0||i===0?(this.applyPath(t,o,e,i,n),t.stroke()):l==="inside"?(t.lineWidth=r*2,t.save(),this.applyPath(t,o,e,i,n),t.clip(),t.stroke(),t.restore()):l==="outside"?(t.lineWidth=r*2,this.applyPath(t,o,e,i,n),t.stroke(),t.save(),t.globalCompositeOperation="destination-out",this.applyPath(t,o,e,i,n),t.fill(),t.restore()):(t.lineWidth=r,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 l=n/360*r;if(a>0){const h=Math.PI*(3*(e*a+i*a)-Math.sqrt((3*e*a+i*a)*(e*a+3*i*a)));l+=n/360*h,n<360&&(l+=2*Math.sqrt((e-e*a)**2+(i-i*a)**2))}else n<360&&(l+=2*Math.max(e,i));return isNaN(l)?0:l}case"Line":return t.length||Math.sqrt(s*s+o*o);case"Triangle":return s+Math.sqrt((s/2)**2+o**2)*2;case"Polygon":{const e=t.sides||3,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 l=e[r];if(l.moveTo){n=l.x,a=l.y;continue}const h=n,c=a,g=e[r-1].out_x,f=e[r-1].out_y;if(g!==void 0||l.in_x!==void 0?i+=this.getBezierLength(h,c,g??h,f??c,l.in_x??l.x,l.in_y??l.y,l.x,l.y):i+=Math.sqrt((l.x-h)**2+(l.y-c)**2),n=l.x,a=l.y,l.closePath||r===e.length-1&&(t.is_closed||t.isClosed)){const d=n,p=a,m=[...e.slice(0,r+1)].reverse().find(w=>w.moveTo)||e[0],y=m.x,v=m.y,b=e[r].out_x,C=e[r].out_y,S=m.in_x,I=m.in_y;b!==void 0||S!==void 0?i+=this.getBezierLength(d,p,b??d,C??p,S??y,I??v,y,v):i+=Math.sqrt((y-d)**2+(v-p)**2)}}return i}default:return(s+o)*2}}getBezierLength(t,s,o,e,i,n,a,r,l=10){let h=0,c=t,g=s;for(let f=1;f<=l;f++){const d=f/l,p=1-d,m=d*d,y=p*p,v=y*p,b=m*d,C=v*t+3*y*d*o+3*p*m*i+b*a,S=v*s+3*y*d*e+3*p*m*n+b*r,I=C-c,w=S-g;h+=Math.sqrt(I*I+w*w),c=C,g=S}return h}getBezierTAtLength(t,s,o,e,i,n,a,r,l,h=20){if(t<=0)return 0;let c=0,g=s,f=o;for(let d=1;d<=h;d++){const p=d/h,m=1-p,y=p*p,v=m*m,b=v*m,C=y*p,S=b*s+3*v*p*e+3*m*y*n+C*r,I=b*o+3*v*p*i+3*m*y*a+C*l,w=S-g,M=I-f,_=Math.sqrt(w*w+M*M);if(c+_>=t){const T=t-c,$=_===0?0:T/_;return(d-1+$)/h}c+=_,g=S,f=I}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,l=-1/0;i.forEach(v=>{typeof v.x=="number"&&typeof v.y=="number"&&(n=Math.min(n,v.x),a=Math.max(a,v.x),r=Math.min(r,v.y),l=Math.max(l,v.y),v.out_x!==void 0&&(n=Math.min(n,v.out_x),a=Math.max(a,v.out_x)),v.out_y!==void 0&&(r=Math.min(r,v.out_y),l=Math.max(l,v.out_y)),v.in_x!==void 0&&(n=Math.min(n,v.in_x),a=Math.max(a,v.in_x)),v.in_y!==void 0&&(r=Math.min(r,v.in_y),l=Math.max(l,v.in_y)))});const h=(n+a)/2,c=(r+l)/2,f=this.getPerimeter(t,s,o)*e;let d=0;const p=[];let m=i[0],y=i[0];for(let v=1;v<i.length;v++){const b=i[v];if(b.moveTo){m=b,y=b;continue}p.push({p0:m,p1:b}),(b.closePath||v===i.length-1&&(t.is_closed||t.isClosed))&&p.push({p0:b,p1:y}),m=b}for(const v of p){const b=v.p0,C=v.p1;let S=0;const I=b.out_x!==void 0||C.in_x!==void 0;if(I?S=this.getBezierLength(b.x,b.y,b.out_x??b.x,b.out_y??b.y,C.in_x??C.x,C.in_y??C.y,C.x,C.y):S=Math.sqrt((C.x-b.x)**2+(C.y-b.y)**2),d+S>=f||v===p[p.length-1]){let w=0;if(I)return w=this.getBezierTAtLength(f-d,b.x,b.y,b.out_x??b.x,b.out_y??b.y,C.in_x??C.x,C.in_y??C.y,C.x,C.y,20),this.getBezierPointAndAngle(w,b,C,h,c);{w=S===0?0:(f-d)/S;const M=b.x+(C.x-b.x)*w-h,_=b.y+(C.y-b.y)*w-c,T=Math.atan2(C.y-b.y,C.x-b.x);return{x:M,y:_,angle:T}}}d+=S}}else if(t.type==="Ellipse"){const i=Math.abs(s)/2,n=Math.abs(o)/2,a=t.sweepAngle??360,l=((t.startAngle??0)+a*e)*Math.PI/180,h=i*Math.cos(l),c=n*Math.sin(l),g=-i*Math.sin(l),f=n*Math.cos(l),d=Math.atan2(f,g);return{x:h,y:c,angle:d}}else if((t==null?void 0:t.type)==="Rectangle"){const i=Math.abs(s),n=Math.abs(o),r=(i+n)*2*e;let l=0,h=0,c=0;return r<i?(l=-i/2+r,h=-n/2,c=0):r<i+n?(l=i/2,h=-n/2+(r-i),c=Math.PI/2):r<2*i+n?(l=i/2-(r-(i+n)),h=n/2,c=Math.PI):(l=-i/2,h=n/2-(r-(2*i+n)),c=-Math.PI/2),{x:l,y:h,angle:c}}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,l=s.out_y??s.y,h=o.in_x??o.x,c=o.in_y??o.y,g=o.x,f=o.y,d=1-t,p=t*t,m=d*d,y=m*d,v=p*t,b=y*n+3*m*t*r+3*d*p*h+v*g-e,C=y*a+3*m*t*l+3*d*p*c+v*f-i,S=3*m*(r-n)+6*d*t*(h-r)+3*p*(g-h),I=3*m*(l-a)+6*d*t*(c-l)+3*p*(f-c),w=Math.atan2(I,S);return{x:b,y:C,angle:w}}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){const o=this.objectStates.get(s);if(!o)return;t.translate(o.x,o.y),t.rotate(o.rotation*Math.PI/180);const e=(o.scale_x??1)*(o.flip_x===!0?-1:1),i=(o.scale_y??1)*(o.flip_y===!0?-1:1);t.scale(e,i)}applyArtEffectOverlay(t,s,o,e,i,n){var f,d,p,m,y;const a=this.objectStates.get(s.id),r=((f=a==null?void 0:a.style)==null?void 0:f.artEffect)||s.artEffect||((d=s.style)==null?void 0:d.artEffect);if(!r||!r.enabled)return;const l=r.type,h=r.intensity??.5,c=r.speed??1,g=r.scale??10;if(l==="acid_gradient"||l==="acid_rave"||l==="shimmer"||l==="glint_overlay"||l==="halftone"||l==="noise"||l==="scanlines"||l==="chromatic_aberration"||l==="pixelate"||l==="glitch"||l==="fold_overlay"||l==="crumple_overlay"){if(t.save(),this.applyPath(t,o,e,i,n),t.clip(),l==="shimmer"){const b=this.currentTime*c%2/2,C=t.createLinearGradient(-e,-i,e,i);C.addColorStop(Math.max(0,b-.2),"rgba(255,255,255,0)"),C.addColorStop(b,`rgba(255,255,255,${h*.8})`),C.addColorStop(Math.min(1,b+.2),"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(l==="glint_overlay"){let C=((this._lastPointerPos||{x:0}).x-(((p=s.transform)==null?void 0:p.x)??0)+300)/600;C=Math.max(-.2,Math.min(1.2,C));const S=t.createLinearGradient(-e,-i,e,i);S.addColorStop(Math.max(0,C-.15),"rgba(255,255,255,0)"),S.addColorStop(Math.max(0,Math.min(1,C)),`rgba(255,255,255,${h})`),S.addColorStop(Math.min(1,C+.15),"rgba(255,255,255,0)"),t.fillStyle=S,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i),t.globalCompositeOperation="source-over"}else if(l==="fold_overlay"){const v=this._lastPointerPos||{x:0,y:0},b=v.x-(((m=s.transform)==null?void 0:m.x)??0),C=v.y-(((y=s.transform)==null?void 0:y.y)??0),S=t.createLinearGradient(b>0?-e/2:e/2,C>0?-i/2:i/2,b>0?e/2:-e/2,C>0?i/2:-i/2);S.addColorStop(0,`rgba(0,0,0,${h*.6})`),S.addColorStop(.4,"rgba(0,0,0,0)"),S.addColorStop(.5,`rgba(255,255,255,${h*.4})`),S.addColorStop(1,`rgba(0,0,0,${h*.2})`),t.fillStyle=S,t.globalCompositeOperation="overlay",t.fillRect(-e/2,-i/2,e,i),t.globalCompositeOperation="source-over",t.beginPath(),b>0&&C>0?(t.moveTo(e/2-40,i/2),t.lineTo(e/2,i/2-40),t.lineTo(e/2-40,i/2-40)):b<0&&C>0?(t.moveTo(-e/2+40,i/2),t.lineTo(-e/2,i/2-40),t.lineTo(-e/2+40,i/2-40)):b>0&&C<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=b>0?-2:2,t.shadowOffsetY=C>0?-2:2,t.fill()}else if(l==="crumple_overlay"){const v=Math.floor(e/g),b=document.createElement("canvas");b.width=v,b.height=Math.floor(i/g);const C=b.getContext("2d"),S=C.createImageData(b.width,b.height);for(let I=0;I<S.data.length;I+=4){const w=Math.random()>.95?150:255;S.data[I]=w,S.data[I+1]=w,S.data[I+2]=w,S.data[I+3]=255*h}C.putImageData(S,0,0),t.globalCompositeOperation="multiply",t.imageSmoothingEnabled=!1,t.drawImage(b,-e/2,-i/2,e,i)}else if(l==="acid_gradient"||l==="acid_rave"){const v=this.currentTime*c,b=r.color1,C=r.color2,S=t.createLinearGradient(-e/2,-i/2,e/2,i/2);if(b&&C){const I=v*60%360;S.addColorStop(0,this._shiftHue(b,I,h*.7)),S.addColorStop(1,this._shiftHue(C,(I+180)%360,h*.7))}else{const I=v*100%360,w=(I+180)%360;S.addColorStop(0,`hsla(${I}, 80%, 50%, ${h*.5})`),S.addColorStop(1,`hsla(${w}, 80%, 50%, ${h*.5})`)}t.fillStyle=S,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i)}else if(l==="halftone"){const v=Math.max(2,g*(1-h*.8)),b=document.createElement("canvas");b.width=v,b.height=v;const C=b.getContext("2d");if(C){C.fillStyle="black",C.beginPath(),C.arc(v/2,v/2,v/2*h,0,Math.PI*2),C.fill();const S=t.createPattern(b,"repeat");S&&(t.globalAlpha=.3*h,t.fillStyle=S,t.fillRect(-e/2,-i/2,e,i))}}else if(l==="noise"){const v=Math.floor(e*i*h*.02);t.globalAlpha=.4*h;for(let b=0;b<v;b++){const C=Math.random()>.5?255:0;t.fillStyle=`rgba(${C}, ${C}, ${C}, ${.5+Math.random()*.5})`,t.fillRect(-e/2+Math.random()*e,-i/2+Math.random()*i,2,2)}}else if(l==="scanlines"){t.globalAlpha=.2*h,t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1;for(let v=-i/2;v<i/2;v+=4)t.beginPath(),t.moveTo(-e/2,v),t.lineTo(e/2,v),t.stroke()}else if(l==="chromatic_aberration"){const v=5*h;t.globalCompositeOperation="screen",t.globalAlpha=.5,t.fillStyle="cyan",t.fillRect(-e/2-v,-i/2,e,i),t.fillStyle="magenta",t.fillRect(-e/2+v,-i/2,e,i)}else if(l==="pixelate"){const v=Math.max(2,Math.round(g*(1-h*.5))),b=document.createElement("canvas"),C=Math.max(1,Math.ceil(e/v)),S=Math.max(1,Math.ceil(i/v));b.width=C,b.height=S;const I=b.getContext("2d");if(I){I.imageSmoothingEnabled=!1;const w=t.getTransform(),M=w.e-e/2,_=w.f-i/2;I.drawImage(t.canvas,M,_,e,i,0,0,C,S),t.imageSmoothingEnabled=!1,t.drawImage(b,0,0,C,S,-e/2,-i/2,e,i),t.imageSmoothingEnabled=!0}}else if(l==="glitch"){const v=this.currentTime*c,b=r.chaosAmount??.2,C=Math.max(3,Math.floor(8*h)),S=h*e*.15;t.globalCompositeOperation="screen",t.globalAlpha=h*.4;const I=S*.3;t.fillStyle="rgba(255, 0, 0, 0.4)",t.fillRect(-e/2+I,-i/2,e,i),t.fillStyle="rgba(0, 255, 255, 0.4)",t.fillRect(-e/2-I,-i/2,e,i),t.globalCompositeOperation="source-over",t.globalAlpha=1;const w=i/C;for(let M=0;M<C;M++){const _=Math.sin(M*127.1+v*311.7*c)*43758.5,T=_-Math.floor(_);if(T>1-b){const $=(T-(1-b))/b*S*(Math.random()>.5?1:-1),k=-i/2+M*w,E=t.getTransform(),L=E.e-e/2+$,O=E.f+k;t.save(),t.beginPath(),t.rect(-e/2,k,e,w),t.clip(),t.globalAlpha=.8,t.drawImage(t.canvas,L,O,e,w,-e/2+$,k,e,w),t.restore()}}}t.restore()}}_shiftHue(t,s,o){let e=0,i=0,n=0;if(t.startsWith("#")){const f=t.replace("#","");e=parseInt(f.substring(0,2),16)/255,i=parseInt(f.substring(2,4),16)/255,n=parseInt(f.substring(4,6),16)/255}const a=Math.max(e,i,n),r=Math.min(e,i,n);let l=0,h=0,c=(a+r)/2;if(a!==r){const f=a-r;switch(h=c>.5?f/(2-a-r):f/(a+r),a){case e:l=((i-n)/f+(i<n?6:0))/6;break;case i:l=((n-e)/f+2)/6;break;case n:l=((e-i)/f+4)/6;break}}return`hsla(${(((l*360+s)%360+360)%360).toFixed(0)}, ${(h*100).toFixed(0)}%, ${(c*100).toFixed(0)}%, ${o})`}applyBackgroundBlurGlass(t,s,o,e,i,n){const a=n.radius??10,r=n.color??"rgba(255,255,255,0.2)",l=n.opacity??.5,h=n.noise??0;t.save(),this.applyPath(t,s,o,e,i),t.clip();const c=t.getTransform(),g=c.e-o/2,f=c.f-e/2;try{const p=document.createElement("canvas");p.width=Math.max(1,Math.ceil(o)),p.height=Math.max(1,Math.ceil(e));const m=p.getContext("2d");if(m){m.drawImage(t.canvas,g,f,o,e,0,0,o,e),m.filter=`blur(${a}px)`;const y=document.createElement("canvas");y.width=p.width,y.height=p.height;const v=y.getContext("2d");v.filter=`blur(${a}px)`,v.drawImage(p,0,0),t.globalCompositeOperation="source-over",t.globalAlpha=1,t.drawImage(y,-o/2,-e/2,o,e)}}catch{}t.globalCompositeOperation="source-over",t.globalAlpha=l,t.fillStyle=r,t.fillRect(-o/2,-e/2,o,e),t.globalAlpha=1,t.globalCompositeOperation="source-atop";const d=t.createLinearGradient(-o/2,-e/2,o/2,e/2);if(d.addColorStop(0,"rgba(255,255,255,0.12)"),d.addColorStop(.3,"rgba(255,255,255,0.04)"),d.addColorStop(.5,"rgba(255,255,255,0.0)"),d.addColorStop(1,"rgba(255,255,255,0.0)"),t.fillStyle=d,t.fillRect(-o/2,-e/2,o,e),h>0){if(t.globalAlpha=h/100,!this._noiseTileCanvas){const m=document.createElement("canvas");m.width=64,m.height=64;const y=m.getContext("2d"),v=y.createImageData(64,64),b=v.data;for(let C=0;C<b.length;C+=4){const S=Math.floor(Math.random()*255);b[C]=S,b[C+1]=S,b[C+2]=S,b[C+3]=18}y.putImageData(v,0,0),this._noiseTileCanvas=m}const p=t.createPattern(this._noiseTileCanvas,"repeat");p&&(t.fillStyle=p,t.fillRect(-o/2,-e/2,o,e))}t.restore(),t.save(),t.globalAlpha=1,t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1.5,this.applyPath(t,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"){const{startAngle:n=0,sweepAngle:a=360,ratio:r=0}=s,l=o/2,h=e/2,c=n*Math.PI/180,g=a*Math.PI/180,f=c+g;a>=360&&r<=0?t.ellipse(0,0,l,h,0,0,Math.PI*2):(t.ellipse(0,0,l,h,0,c,f,!1),r>0?t.ellipse(0,0,l*r,h*r,0,f,c,!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 l=r*2*Math.PI/n-Math.PI/2,h=a*Math.cos(l),c=a*Math.sin(l);r===0?t.moveTo(h,c):t.lineTo(h,c)}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 l=0;l<n*2;l++){const h=l*Math.PI/n-Math.PI/2,c=l%2===0?a:r,g=c*Math.cos(h),f=c*Math.sin(h);l===0?t.moveTo(g,f):t.lineTo(g,f)}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%10===0&&console.log("[Engine] Tracing Path:",s.points.length,"points");let n=1/0,a=-1/0,r=1/0,l=-1/0;if(s.points.forEach(g=>{typeof g.x=="number"&&typeof g.y=="number"&&(n=Math.min(n,g.x),a=Math.max(a,g.x),r=Math.min(r,g.y),l=Math.max(l,g.y),g.out_x!==void 0&&(n=Math.min(n,g.out_x),a=Math.max(a,g.out_x)),g.out_y!==void 0&&(r=Math.min(r,g.out_y),l=Math.max(l,g.out_y)),g.in_x!==void 0&&(n=Math.min(n,g.in_x),a=Math.max(a,g.in_x)),g.in_y!==void 0&&(r=Math.min(r,g.in_y),l=Math.max(l,g.in_y)))}),n===1/0)return;const h=(n+a)/2,c=(r+l)/2;if(isNaN(h)||isNaN(c)){console.warn("[Engine] Invalid path center:",h,c);return}s.points.forEach((g,f)=>{if(f===0||g.moveTo)t.moveTo(g.x-h,g.y-c);else{const d=s.points[f-1];if(!d)return;const p=(d.out_x??d.x)-h,m=(d.out_y??d.y)-c,y=(g.in_x??g.x)-h,v=(g.in_y??g.y)-c;isNaN(p)||isNaN(y)||isNaN(g.x)?t.lineTo(g.x-h,g.y-c):t.bezierCurveTo(p,m,y,v,g.x-h,g.y-c)}if(g.closePath||f===s.points.length-1&&(s.is_closed||s.isClosed)){const d=[...s.points.slice(0,f+1)].reverse().find(p=>p.moveTo)||s.points[0];d&&(g.out_x!==void 0||d.in_x!==void 0)&&t.bezierCurveTo((g.out_x??g.x)-h,(g.out_y??g.y)-c,(d.in_x??d.x)-h,(d.in_y??d.y)-c,d.x-h,d.y-c),t.closePath()}})}else if(s.points&&Array.isArray(s.points)){let n=1/0,a=-1/0,r=1/0,l=-1/0;s.points.forEach(g=>{n=Math.min(n,g.x),a=Math.max(a,g.x),r=Math.min(r,g.y),l=Math.max(l,g.y)});const h=(n+a)/2,c=(r+l)/2;s.points.forEach((g,f)=>{if(f===0)t.moveTo(g.x-h,g.y-c);else{const d=s.points[f-1];d.out_x!==void 0||g.in_x!==void 0?t.bezierCurveTo((d.out_x??d.x)-h,(d.out_y??d.y)-c,(g.in_x??g.x)-h,(g.in_y??g.y)-c,g.x-h,g.y-c):t.lineTo(g.x-h,g.y-c)}(g.closePath||f===s.points.length-1&&(s.is_closed||s.isClosed))&&t.closePath()})}}}renderInputBox(t,s){var dt,yt;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((dt=s.geometry)==null?void 0:dt.width)||250,n=((yt=s.geometry)==null?void 0:yt.height)||45,a=this.focusedId===s.id,r=this.lastHoveredObjectId===s.id,l=e.previewState||"default",h=l!=="default"?l:a?"focused":r?"hovered":"default",c=e.label||{visible:!0,text:"Label"},g=e.helperText||{visible:!1,text:"Helper text"},f=e.leftIcon||{visible:!1},d=e.rightIcon||{visible:!1},p=e.multiline===!0,m=e.corner_radius??8,y=e.corners||{tl:m,tr:m,bl:m,br:m},v=[y.tl,y.tr,y.br,y.bl];let b=e.backgroundColor||"rgba(31, 41, 55, 1)",C=e.borderColor||"rgba(55, 65, 81, 1)",S=e.borderWidth??1.5,I=e.color||"#ffffff",w=e.placeholderColor||"rgba(156, 163, 175, 1)",M=e.fontSize||14;const _=`${h}Style`,T=e[_];T?(T.backgroundColor!==void 0&&(b=T.backgroundColor),T.borderColor!==void 0&&(C=T.borderColor),T.borderWidth!==void 0&&(S=T.borderWidth),T.color!==void 0&&(I=T.color),T.placeholderColor!==void 0&&(w=T.placeholderColor),T.fontSize!==void 0&&(M=T.fontSize)):h==="focused"?(C=e.focusBorderColor||"rgba(59, 130, 246, 1)",S=Math.max(S,2)):h==="hovered"||h==="hover"?(C=e.hoverBorderColor||C,b=e.hoverBackgroundColor||b):h==="disabled"?(b=e.disabledBackgroundColor||"rgba(31, 41, 55, 0.6)",C=e.disabledBorderColor||"rgba(55, 65, 81, 0.4)"):h==="error"&&(C="rgba(239, 68, 68, 1)",S=Math.max(S,2)),t.beginPath(),this.drawRoundRect(t,-i/2,-n/2,i,n,v);const $=this.createCanvasFill(t,b,i,n);if($&&(t.fillStyle=$,t.fill()),S>0){const ht=this.createCanvasFill(t,C,i,n);if(ht&&(t.strokeStyle=ht,t.lineWidth=S,t.stroke()),h==="focused"||h==="focus"){t.save(),t.beginPath();const ut=v.map(ot=>ot+2);this.drawRoundRect(t,-i/2-2,-n/2-2,i+4,n+4,ut),t.strokeStyle="rgba(59, 130, 246, 0.3)",t.lineWidth=2,t.stroke(),t.restore()}}const k=(ht,ut)=>{if(!ht.visible||!ht.svgPath)return;const ot=ht.size||14,Et=ht.offset??16,Ft=ht.color||"#ffffff",wt=ut?-(i/2)+Et:i/2-Et,Gt=ht.svgPath;if(t.save(),t.translate(wt,0),!Gt.startsWith("<svg")){const Yt=new Path2D(Gt),B=ot/24;t.scale(B,B),t.translate(-12,-12),t.fillStyle=Ft,t.fill(Yt)}t.restore()};k(f,!0),k(d,!1);const E=e.text||"",L=e.placeholder||"Enter text...",O=!E,A=E||L,W=O?w:I,x=M,Y=e.fontFamily||"Inter",H=e.fontWeight||400;t.font=`${H} ${x}px "${Y}", sans-serif`,t.fillStyle=W,t.textAlign="left",t.textBaseline=p?"top":"middle";const Q=e.inputPadding??16,P=f.visible?(f.offset??16)+(f.size||14)/2+8:Q,F=d.visible?(d.offset??16)+(d.size||14)/2+8:Q,U=-(i/2)+P,J=i-P-F,it=e.inputType==="password"?"•".repeat(A.length):A;if(t.save(),t.beginPath(),t.rect(U-2,-n/2+4,J+4,n-8),t.clip(),p){const ht=it.split(`
|
|
32
|
-
`);let ut=-n/2+Q;const ot=x*1.2;let Et=0;ht.forEach((Ft,wt)=>{const Gt=Ft.split(" ");let Yt="";for(let B=0;B<Gt.length;B++){const nt=Yt+Gt[B]+" ";t.measureText(nt).width>J&&B>0?(t.fillText(Yt,U,ut),Yt=Gt[B]+" ",ut+=ot):Yt=nt}t.fillText(Yt,U,ut),Et=t.measureText(Yt).width,wt<ht.length-1&&(ut+=ot,Et=0)}),a&&!O&&Math.floor(performance.now()/500)%2===0&&t.fillRect(U+Et,ut,1.5,x)}else{const ut=t.measureText(it).width;let ot=0;if(ut>J&&(ot=ut-J),t.fillText(it,U-ot,0),a&&!O&&Math.floor(performance.now()/500)%2===0){const Ft=U+ut-ot;t.fillRect(Ft,-(x/2),1.5,x)}}if(t.restore(),c.visible!==!1){const ht=c.text||"Label",ut=c.fontSize||12,ot=c.color||"rgba(156, 163, 175, 1)",Et=c.offset??8;t.font=`600 ${ut}px "${Y}", sans-serif`,t.fillStyle=ot,t.textAlign="left",t.textBaseline="bottom";const Ft=-(i/2),wt=-(n/2)-Et;t.fillText(ht,Ft,wt)}if(g.visible===!0){const ht=g.text||"Helper text",ut=g.fontSize||11,ot=h==="error"?"rgba(239, 68, 68, 1)":g.color||"rgba(156, 163, 175, 1)",Et=g.offset??6;t.font=`400 ${ut}px "${Y}", sans-serif`,t.fillStyle=ot,t.textAlign="left",t.textBaseline="top";const Ft=-(i/2),wt=n/2+Et;t.fillText(ht,Ft,wt)}}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,h=(i.max??100)-r,c=h===0?0:(a-r)/h,g=i.trackHeight||4,f=i.trackRoundedness??2,d=i.trackShape??"Rectangle",p=i.trackPath||"",m=i.accentColor||"#3b82f6",y=i.inactiveColor||"#374151",v=i.thumbShape||"Ellipse",b=i.thumbWidth??16,C=i.thumbHeight??16,S=i.thumbRoundedness??0,I=i.thumbColor||"#ffffff",w=i.thumbPath||"",M=i.thumbIcon||"",_=i.showValueTooltip??!1,T=i.tooltipBgColor||"#333333",$=i.tooltipColor||"#ffffff",k=i.tooltipOffsetX??0,E=i.tooltipOffsetY??-25,L=(J,it,dt,yt,ht,ut,ot)=>{if((J==="Custom"||J==="Icon")&&ot)try{const Et=new Path2D(ot);if(t.save(),t.translate(it,dt),J==="Icon"){const Ft=Math.min(yt,ht)/24;t.scale(Ft,Ft),t.translate(-12,-12)}t.fill(Et),t.restore();return}catch(Et){console.error("Error drawing slider shape in engine:",Et)}if(t.beginPath(),J==="Ellipse")t.ellipse(it,dt,yt/2,ht/2,0,0,Math.PI*2);else if(J==="Rectangle")this.drawRoundRect(t,it-yt/2,dt-ht/2,yt,ht,ut);else if(J==="Triangle")t.moveTo(it,dt-ht/2),t.lineTo(it+yt/2,dt+ht/2),t.lineTo(it-yt/2,dt+ht/2),t.closePath();else if(J==="Diamond")t.moveTo(it,dt-ht/2),t.lineTo(it+yt/2,dt),t.lineTo(it,dt+ht/2),t.lineTo(it-yt/2,dt),t.closePath();else if(J==="Polygon"){const Et=s.geometry.sides||3,Ft=s.geometry.radius||Math.min(yt,ht)/2;for(let wt=0;wt<Et;wt++){const Gt=wt*2*Math.PI/Et-Math.PI/2,Yt=it+Ft*Math.cos(Gt),B=dt+Ft*Math.sin(Gt);wt===0?t.moveTo(Yt,B):t.lineTo(Yt,B)}t.closePath()}else if(J==="Star"){const Ft=Math.min(yt,ht)/2,wt=Ft/2;for(let Gt=0;Gt<5*2;Gt++){const Yt=Gt%2===0?Ft:wt,B=Gt*Math.PI/5-Math.PI/2;t.lineTo(it+Yt*Math.cos(B),dt+Yt*Math.sin(B))}t.closePath()}else J==="Line"&&(t.moveTo(it-yt/2,dt),t.lineTo(it+yt/2,dt));t.fill()},O=this.createCanvasFill(t,y,n,g);O&&(t.fillStyle=O,t.strokeStyle=O),d==="Line"?(t.lineWidth=g,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(n/2,0),t.stroke()):L(d,0,0,n,g,f,p);const A=n-b,W=-n/2+b/2+c*A,x=W- -n/2;if(x>0){const J=this.createCanvasFill(t,m,n,g);J&&(t.fillStyle=J,t.strokeStyle=J),d==="Line"?(t.lineWidth=g,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(W,0),t.stroke()):d==="Rectangle"&&(t.beginPath(),this.drawRoundRect(t,-n/2,-g/2,x,g,f),t.fill())}t.save(),t.translate(W,0);const Y=t.getTransform(),H=Math.sqrt(Y.a*Y.a+Y.b*Y.b)||1;t.shadowColor="rgba(0,0,0,0.2)",t.shadowBlur=4*H,t.shadowOffsetY=1*H;const Q=this.createCanvasFill(t,I,b,C);if(Q&&(t.fillStyle=Q),L(v,0,0,b,C,S,v==="Icon"?M:w),t.restore(),_){t.save(),t.translate(W+k,E);const J=Math.round(a).toString();t.font="10px Inter, sans-serif";const it=t.measureText(J),dt=6,yt=4,ht=it.width+dt*2,ut=14+yt;t.beginPath(),this.drawRoundRect(t,-ht/2,-ut/2,ht,ut,4),t.fillStyle=T,t.fill(),t.fillStyle=$,t.textAlign="center",t.textBaseline="middle",t.fillText(J,0,0),t.restore()}const P=i.label||{},F=i.helperText||{},U=i.fontFamily||"Inter";if(P.visible!==!1){const J=P.text||"Label",it=P.fontSize||12,dt=P.color||"rgba(156, 163, 175, 1)",yt=P.offset??8;t.font=`600 ${it}px "${U}", sans-serif`,t.fillStyle=dt,t.textAlign="left",t.textBaseline="bottom";const ht=-(n/2),ut=-(g/2)-yt;t.fillText(J,ht,ut)}if(F.visible===!0){const J=F.text||"Helper text",it=F.fontSize||11,dt=F.color||"rgba(156, 163, 175, 1)",yt=F.offset??6;t.font=`400 ${it}px "${U}", sans-serif`,t.fillStyle=dt,t.textAlign="left",t.textBaseline="top";const ht=-(n/2),ut=g/2+yt;t.fillText(J,ht,ut)}}renderDropdown(t,s){var E;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,l=e.corner_radius??6,h=e.disabled||e.previewState==="disabled",c=this.lastHoveredObjectId===s.id||e.previewState==="hover",g=(e.isOpen||e.previewState==="active")&&!h;let f=e.backgroundColor,d=e.borderColor,p=e.color||"#333333";h?(f=e.disabledBackgroundColor||"#f3f4f6",d=e.disabledBorderColor||"#e5e7eb",p=e.disabledColor||"#9ca3af"):g?(f=e.activeBackgroundColor||f,d=e.activeBorderColor||d,p=e.activeColor||p):c&&(f=e.hoverBackgroundColor||f,d=e.hoverBorderColor||d,p=e.hoverColor||p),f||(f="#ffffff"),d||(d="#e5e7eb");const m=t.globalAlpha;t.globalAlpha=m*(e.opacity??1),this.drawRoundRect(t,a,r,i,n,l),t.fillStyle=this.createCanvasFill(t,typeof f=="string"?{type:"Solid",color:f}:f,i,n)||"#ffffff",t.fill();const y=e.borderWidth??1;y>0&&(t.strokeStyle=this.createCanvasFill(t,typeof d=="string"?{type:"Solid",color:d}:d,i,n)||"#e5e7eb",t.lineWidth=y,t.stroke());const v=12,b=e.chevronType||"chevron",C=e.chevronSize||16,S=(g?e.openIconColor:e.closedIconColor)||e.chevronColor||"#6b7280";if(b!=="none"){const L=a+i-v-C/2;t.save(),t.translate(L,0);const O=g?e.openIconAngle??180:e.closedIconAngle??0;if(t.rotate(O*Math.PI/180),t.strokeStyle=S,t.fillStyle=S,t.lineWidth=1.5,t.lineCap="round",t.lineJoin="round",b==="chevron")t.beginPath(),t.moveTo(-C/2,-C*.2),t.lineTo(0,C*.2),t.lineTo(C/2,-C*.2),t.stroke();else if(b==="custom"||b==="path"){const A=g&&e.openIconPath||e.closedIconPath;if(A){const W=new Path2D(A);t.save();const x=C/24;t.scale(x,x),t.translate(-12,-12),t.fill(W),t.restore()}}t.restore()}const I=e.selectedOption||e.placeholder||"Select...",w=e.fontSize||14,M=e.fontWeight||400,_=e.fontFamily||"Inter, sans-serif";t.font=`${M} ${w}px ${_}`;const T=h?e.disabledColor||"#9ca3af":!e.selectedOption&&e.placeholder?"#9ca3af":p;t.fillStyle=this.createCanvasFill(t,typeof T=="string"?{type:"Solid",color:T}:T,i,n)||"#333333",t.textAlign="left",t.textBaseline="middle";const $=b==="none"?0:C+8,k=i-v*2-$;if(t.save(),t.beginPath(),t.rect(a+v,r,k,n),t.clip(),t.fillText(I,a+v,0),t.restore(),g&&!h){const L=r+n+4,O=e.optionsList||[],A=e.itemHeight||32,W=e.listPadding??4,x=O.length*A+W*2,Y=e.listCornerRadius??l;t.save();const H=e.listShadow||{},Q=t.getTransform(),P=Math.sqrt(Q.a*Q.a+Q.b*Q.b)||1;t.shadowColor=typeof H.color=="string"?H.color:((E=H.color)==null?void 0:E.color)||"rgba(0,0,0,0.15)",t.shadowBlur=(H.blur??12)*P,t.shadowOffsetY=(H.offsetY??6)*P,t.shadowOffsetX=(H.offsetX??0)*P,t.beginPath(),this.drawRoundRect(t,a,L,i,x,Y),t.fillStyle=this.createCanvasFill(t,typeof e.listBackgroundColor=="string"?{type:"Solid",color:e.listBackgroundColor}:e.listBackgroundColor||{type:"Solid",color:"#ffffff"},i,x)||"#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:d},i,x)||"#e5e7eb",t.lineWidth=F,t.stroke()),t.restore();const U=e.itemFontSize||w,J=e.itemFontFamily||_;t.font=`${M} ${U}px ${J}`,O.forEach((it,dt)=>{const yt=L+W+dt*A;if(it===e.selectedOption)t.fillStyle=this.createCanvasFill(t,typeof e.itemSelectedBackgroundColor=="string"?{type:"Solid",color:e.itemSelectedBackgroundColor}:e.itemSelectedBackgroundColor||{type:"Solid",color:"#f3f4f6"},i,A)||"#f3f4f6",t.fillRect(a+F,yt,i-F*2,A),t.fillStyle=e.itemSelectedColor||e.accentColor||p||"#374151";else if(t.fillStyle=e.listTextColor||p||"#333333",this.activeDropdownId===s.id&&this._lastPointerPos){const ut=this._lastPointerPos.y-(L+W),ot=Math.floor(ut/A);dt===ot&&(t.fillStyle=this.createCanvasFill(t,typeof e.itemHoverBackgroundColor=="string"?{type:"Solid",color:e.itemHoverBackgroundColor}:e.itemHoverBackgroundColor||{type:"Solid",color:"#f9fafb"},i,A)||"#f9fafb",t.fillRect(a+F,yt,i-F*2,A),t.fillStyle=e.itemHoverColor||p)}t.fillText(it,a+v,yt+A/2)})}t.globalAlpha=m}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,l=this.activeObjectId===s.id,h=e.label||{},c=e.hoverStyle||{},g=e.activeStyle||{},f=e.icon||{enabled:!1};let d=e.backgroundColor||"#3b82f6",p=h.color||"#ffffff",m=h.text||"Button",y=i.cornerRadius??8,v=e.borderColor||"transparent",b=e.borderWidth||0,C=1;l&&g?(d=g.backgroundColor||d,p=g.color||p,m=g.text||m,C=g.scale??.95,y=g.cornerRadius??y):r&&c&&(d=c.backgroundColor||d,p=c.color||p,m=c.text||m,C=c.scale??1,y=c.cornerRadius??y,v=c.borderColor||v);const S=-n/2,I=-a/2;t.save(),t.scale(C,C),t.beginPath(),this.drawRoundRect(t,S,I,n,a,y);const w=this.createCanvasFill(t,d,n,a);w&&(t.fillStyle=w,t.fill()),(b>0||r&&c.borderColor)&&(t.strokeStyle=v,t.lineWidth=b||(r?1:0),t.stroke());const M=h.fontSize||14,_=h.fontFamily||"Inter",T=h.fontWeight||600;t.font=`${T} ${M}px "${_}", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle=p,t.textAlign="center",t.textBaseline="middle";let $=0;if(f.enabled&&f.svgPath){const k=M*1.1,E=f.gap||8,L=t.measureText(m),A=-(L.width+k+E)/2,W=f.position==="left"?A+k/2:A+L.width+E+k/2;$=f.position==="left"?A+k+E+L.width/2:A+L.width/2,t.save(),t.translate(W,0);const x=new Path2D(f.svgPath),Y=k/24;t.scale(Y,Y),t.translate(-12,-12),t.fillStyle=p,t.fill(x),t.restore()}t.fillText(m,$,0),t.restore()}renderToggleButton(t,s){var m,y;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=e.checked??!1,n=((m=s.geometry)==null?void 0:m.width)||120,a=((y=s.geometry)==null?void 0:y.height)||40,r=-n/2,l=-a/2,h=e.corner_radius??8,c=e.label||{},g=i?e.accentColor||"#3b82f6":e.inactiveColor||"#374151",f=i?e.activeTextColor||"#ffffff":e.inactiveTextColor||"#9ca3af";t.save(),t.beginPath(),this.drawRoundRect(t,r,l,n,a,h),t.fillStyle=g,t.fill();const d=c.fontSize||14,p=c.fontFamily||"Inter";t.font=`${c.fontWeight||600} ${d}px "${p}", sans-serif`,t.fillStyle=f,t.textAlign="center",t.textBaseline="middle",t.fillText(c.text||"Toggle",0,0),t.restore()}renderToggle(t,s){var Y,H,Q,P,F,U,J,it,dt,yt,ht,ut;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=((H=s.geometry)==null?void 0:H.height)||30,a=-i/2,r=-n/2,l=e.checked??!1,h=e.cornerRadius??e.corner_radius??n/2,c=e.toggleStyle||{},g=c.backgroundColor||e.activeColor||"#10b981",f=c.borderColor||e.borderColor||"transparent",d=c.borderWidth??e.borderWidth??0,p=c.knobColor||e.knobColor||"#ffffff",m=l?g:e.inactiveColor||"#374151",y=l?f:e.borderColor||"transparent",v=l?d:e.borderWidth??0,b=l?p:e.knobColor||"#ffffff";e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,i,n,h);const C=this.createCanvasFill(t,m,i,n);if(C&&(t.fillStyle=C,t.fill()),v>0){t.lineWidth=v;const ot=this.createCanvasFill(t,y,i,n);ot&&(t.strokeStyle=ot,t.stroke())}const S=2,I=n-S*2,w=I/2,M=a+S,_=a+i-S-I,T=l?_:M,$=r+S;t.beginPath(),t.arc(T+w,$+w,w,0,Math.PI*2);const k=this.createCanvasFill(t,b,I,I);k&&(t.fillStyle=k,t.fill()),e.disabled&&(t.globalAlpha*=2);let E=!1,L=!1;const O=(l?(Q=c.leftLabel)==null?void 0:Q.text:null)||((P=e.leftLabel)==null?void 0:P.text)||"",A=(l?(F=c.leftLabel)==null?void 0:F.color:null)||((U=e.leftLabel)==null?void 0:U.color)||"#f3f4f6";if((J=e.leftLabel)!=null&&J.enabled&&O){const ot=e.leftLabel;t.font=`${ot.fontWeight||400} ${ot.fontSize||12}px "${ot.fontFamily||"Inter"}", sans-serif`,t.fillStyle=A,t.textBaseline="middle",t.textAlign="right",t.fillText(O,a-(ot.gap||8),0),E=!0}const W=(l?(it=c.rightLabel)==null?void 0:it.text:null)||((dt=e.rightLabel)==null?void 0:dt.text)||"",x=(l?(yt=c.rightLabel)==null?void 0:yt.color:null)||((ht=e.rightLabel)==null?void 0:ht.color)||"#f3f4f6";if((ut=e.rightLabel)!=null&&ut.enabled&&W){const ot=e.rightLabel;t.font=`${ot.fontWeight||400} ${ot.fontSize||12}px "${ot.fontFamily||"Inter"}", sans-serif`,t.fillStyle=x,t.textBaseline="middle",t.textAlign="left",t.fillText(W,a+i+(ot.gap||8),0),L=!0}if(!E&&!L&&e.label&&e.label.text){const ot=e.label,Et=ot.fontSize||14,Ft=ot.fontWeight||400,wt=ot.fontFamily||"Inter";t.font=`${Ft} ${Et}px "${wt}", sans-serif`,t.fillStyle=ot.color||"#f3f4f6",t.textBaseline="middle";const Gt=ot.gap||10;let Yt=0,B=0;ot.position==="left"?(t.textAlign="right",Yt=a-Gt,B=0):ot.position==="right"?(t.textAlign="left",Yt=a+i+Gt,B=0):ot.position==="top"?(t.textAlign="center",Yt=0,B=r-Gt,t.textBaseline="bottom"):ot.position==="bottom"?(t.textAlign="center",Yt=0,B=r+n+Gt,t.textBaseline="top"):(t.textAlign="left",Yt=a+i+Gt,B=0),t.fillText(ot.text,Yt,B)}}renderCheckbox(t,s){var C,S;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)||20,n=((S=s.geometry)==null?void 0:S.height)||20,a=-i/2,r=-n/2,l=e.cornerRadius??4,h=e.checked??!1,c=e.activeColor||"#3b82f6",g=e.inactiveColor||"transparent",f=e.checkColor||"#ffffff",d=e.borderColor||"#4b5563",p=e.borderWidth??2,m=h?c:g,y=h?"transparent":d,v=h?0:p;e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,i,n,l);const b=this.createCanvasFill(t,m,i,n);if(b&&(t.fillStyle=b,t.fill()),v>0){t.lineWidth=v;const I=this.createCanvasFill(t,y,i,n);I&&(t.strokeStyle=I,t.stroke())}else if(h){t.lineWidth=1;const I=this.createCanvasFill(t,c,i,n);I&&(t.strokeStyle=I,t.stroke())}if(h){t.save(),t.beginPath();const I=this.createCanvasFill(t,f,i,n);t.strokeStyle=I||f,t.lineWidth=Math.max(2,i*.12),t.lineCap="round",t.lineJoin="round";const w=a+i*.25,M=r+n*.5,_=a+i*.45,T=r+n*.7,$=a+i*.75,k=r+n*.25;t.moveTo(w,M),t.lineTo(_,T),t.lineTo($,k),t.stroke(),t.restore()}if(e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const I=e.label;t.save(),t.font=`${I.fontWeight||400} ${I.fontSize||14}px "${I.fontFamily||"Inter"}", sans-serif`,t.fillStyle=I.color||"#f3f4f6",t.textBaseline="middle";const w=I.gap||8;let M=0,_=0;I.position==="left"?(t.textAlign="right",M=a-w,_=0):I.position==="right"?(t.textAlign="left",M=a+i+w,_=0):I.position==="top"?(t.textAlign="center",M=0,_=r-w,t.textBaseline="bottom"):I.position==="bottom"&&(t.textAlign="center",M=0,_=r+n+w,t.textBaseline="top"),t.fillText(I.text,M,_),t.restore()}}renderRadioGroup(t,s){var S,I;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((S=s.geometry)==null?void 0:S.width)||180,n=((I=s.geometry)==null?void 0:I.height)||100,a=-i/2,r=-n/2,l=e.selectedValue,h=e.optionsList||["Option 1","Option 2","Option 3"],c=e.orientation||"vertical",g=e.itemGap!==void 0?e.itemGap:16,f=e.activeColor||"#3b82f6",d=e.inactiveColor||"#4b5563",p=e.textColor||"#ffffff",m=e.fontSize||14,y=e.fontFamily||"Inter",v=e.fontWeight||400;e.disabled&&(t.globalAlpha*=.5);const b=8,C=b*2;if(t.save(),t.font=`${v} ${m}px "${y}", sans-serif`,t.textBaseline="middle",t.textAlign="left",c==="vertical"){const w=Math.max(C,m)+g;h.forEach((M,_)=>{const T=r+_*w+b;t.beginPath(),t.arc(a+b,T,b,0,Math.PI*2);const $=l===M,k=this.createCanvasFill(t,f,C,C),E=this.createCanvasFill(t,d,C,C);$?(t.strokeStyle=k||f,t.lineWidth=2,t.stroke(),t.beginPath(),t.arc(a+b,T,b/2,0,Math.PI*2),t.fillStyle=k||f,t.fill()):(t.strokeStyle=E||d,t.lineWidth=1.5,t.stroke()),t.fillStyle=p,t.fillText(M,a+C+8,T)})}else{let w=a;h.forEach(M=>{const _=l===M,T=t.measureText(M).width;t.beginPath(),t.arc(w+b,0,b,0,Math.PI*2);const $=this.createCanvasFill(t,f,C,C),k=this.createCanvasFill(t,d,C,C);_?(t.strokeStyle=$||f,t.lineWidth=2,t.stroke(),t.beginPath(),t.arc(w+b,0,b/2,0,Math.PI*2),t.fillStyle=$||f,t.fill()):(t.strokeStyle=k||d,t.lineWidth=1.5,t.stroke()),t.fillStyle=p,t.fillText(M,w+C+6,0),w+=C+6+T+g})}if(t.restore(),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||"#9ca3af",t.textBaseline="middle";const M=w.gap||8;let _=0,T=0;w.position==="left"?(t.textAlign="right",_=a-M,T=0):w.position==="right"?(t.textAlign="left",_=a+i+M,T=0):w.position==="top"?(t.textAlign="center",_=0,T=r-M,t.textBaseline="bottom"):w.position==="bottom"&&(t.textAlign="center",_=0,T=r+n+M,t.textBaseline="top"),t.fillText(w.text,_,T),t.restore()}}renderBarChart(t,s){var T,$;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i={width:((T=s.geometry)==null?void 0:T.width)||300,height:(($=s.geometry)==null?void 0:$.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,_getPreset:function(){return es[this.stylePreset]||es.default},_resolveColor:function(k,E){const L=this._getPreset();return["#6366f1","#f59e0b","#10b981","#3b82f6","#a855f7"].includes(k)?L.colors[E%L.colors.length]:typeof k=="string"?k:L.colors[E%L.colors.length]},_makeGradient:function(k,E,L,O,A,W){if(!this._getPreset().barGradient&&!this.barGradient)return E;const Y=k.createLinearGradient(L,O,A,W);return Y.addColorStop(0,E),Y.addColorStop(1,E+"44"),Y},_drawRoundedBar:function(k,E,L,O,A,W,x){if(W=Math.min(W,Math.min(Math.abs(O),Math.abs(A))/2),W<=0||O===0||A===0){k.rect(E,L,O,A);return}k.beginPath(),x?(k.moveTo(E,L+A),k.lineTo(E,L+W),k.quadraticCurveTo(E,L,E+W,L),k.lineTo(E+O-W,L),k.quadraticCurveTo(E+O,L,E+O,L+W),k.lineTo(E+O,L+A),k.lineTo(E,L+A)):(k.moveTo(E,L),k.lineTo(E+O-W,L),k.quadraticCurveTo(E+O,L,E+O,L+W),k.lineTo(E+O,L+A-W),k.quadraticCurveTo(E+O,L+A,E+O-W,L+A),k.lineTo(E,L+A),k.lineTo(E,L)),k.closePath()}},n=i.width,a=i.height,r=-n/2,l=-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 h=i._getPreset();let c=-1/0,g=1/0;const f=i.categories.length,d=i.datasets.length;if(i.chartType==="stacked")for(let k=0;k<f;k++){let E=0,L=0;i.datasets.forEach(O=>{const A=O.data[k]??0;A>=0?E+=A:L+=A}),E>c&&(c=E),L<g&&(g=L)}else i.datasets.forEach(k=>{k.data&&k.data.forEach(E=>{E>c&&(c=E),E<g&&(g=E)})});isFinite(c)||(c=10),isFinite(g)||(g=0),c=Math.max(c,0),g=Math.min(g,0);const p=c-g||10;t.save(),t.font=`${i.axisLabelFontSize}px Inter, sans-serif`;const m=i.showYLabels?t.measureText(c.toFixed(0)).width+14:10,y=i.showXLabels?i.axisLabelFontSize+12:8,b=(i.showLegend&&d>0?i.legendFontSize+10:0)+8,C=10,S=r+m,I=l+b,w=n-m-C,M=a-b-y;if(t.beginPath(),t.roundRect(r,l,n,a,10),t.fillStyle=h.cardBackground,t.fill(),t.strokeStyle=h.cardBorderColor,t.lineWidth=1,t.stroke(),i.showLegend&&d>0){t.font=`${i.legendFontSize}px Inter, sans-serif`,t.textBaseline="middle";const k=l+12;let E=S;i.datasets.forEach((L,O)=>{const A=i._resolveColor(L.color,O),W=L.label||`Series ${O+1}`,x=7;t.beginPath(),t.roundRect(E,k-x/2,x,x,2),t.fillStyle=A,t.fill(),t.fillStyle=h.legendColor,t.textAlign="left",t.fillText(W,E+x+4,k),E+=t.measureText(W).width+x+16})}const _=4;if(i.showGridLines){t.setLineDash([3,4]),t.lineWidth=1,t.strokeStyle=h.gridColor;for(let k=0;k<=_;k++){const E=I+k/_*M;t.beginPath(),t.moveTo(S,E),t.lineTo(S+w,E),t.stroke()}t.setLineDash([])}if(i.showYLabels){t.font=`${i.axisLabelFontSize}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=h.axisLabelColor;for(let k=0;k<=_;k++){const E=c-k/_*p,L=I+k/_*M;t.fillText(E.toFixed(0),S-6,L)}}if(t.lineWidth=1,t.setLineDash([]),i.showXAxis&&(t.strokeStyle=i.xAxisColor,t.beginPath(),t.moveTo(S,I+M),t.lineTo(S+w,I+M),t.stroke()),i.showYAxis&&(t.strokeStyle=i.yAxisColor,t.beginPath(),t.moveTo(S,I),t.lineTo(S,I+M),t.stroke()),i.chartType==="stacked"){const k=w/f;for(let E=0;E<f;E++){const L=S+E*k+k/2;i.showXLabels&&(t.font=`${i.axisLabelFontSize}px Inter, sans-serif`,t.textAlign="center",t.textBaseline="top",t.fillStyle=h.axisLabelColor,t.fillText(i.categories[E]||"",L,I+M+5));let O=I+M;i.datasets.forEach((A,W)=>{const x=A.data[E]??0;if(x===0)return;const Y=x/p*M,H=Math.min(i.barWidth*d+i.barGap,k-8),Q=L-H/2,P=O-Y;O-=Y;const F=i._resolveColor(A.color,W);t.beginPath(),t.fillStyle=i._makeGradient(t,F,Q,P,Q,P+Y),i._drawRoundedBar(t,Q,P,H,Y,W===d-1?i.barCornerRadius:0,!0),t.fill()})}}else{const k=w/f,E=d*i.barWidth+Math.max(0,(d-1)*i.barGap),L=I+M-(0-g)/p*M;for(let O=0;O<f;O++){const A=S+O*k+k/2;i.showXLabels&&(t.font=`${i.axisLabelFontSize}px Inter, sans-serif`,t.textAlign="center",t.textBaseline="top",t.fillStyle=h.axisLabelColor,t.fillText(i.categories[O]||"",A,I+M+5));const W=A-E/2;i.datasets.forEach((x,Y)=>{const H=x.data[O]??0,Q=Math.abs(H/p*M);if(Q<1)return;const P=W+Y*(i.barWidth+i.barGap),F=H>=0?L-Q:L,U=i._resolveColor(x.color,Y);t.beginPath(),t.fillStyle=i._makeGradient(t,U,P,F,P,F+Q),i._drawRoundedBar(t,P,F,i.barWidth,Q,i.barCornerRadius,!0),t.fill(),i.showValueOnTop&&H!==0&&(t.font=`bold ${i.axisLabelFontSize}px Inter, sans-serif`,t.textAlign="center",t.textBaseline="bottom",t.fillStyle=U,t.fillText(H.toString(),P+i.barWidth/2,F-2))})}}t.restore()}renderPieChart(t,s){var m,y;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i={width:((m=s.geometry)==null?void 0:m.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 ss[this.stylePreset]||ss.default},_resolveSliceColor:function(v,b){const C=v.color,S=b,I=this._getPreset();return["#6366f1","#22d3ee","#f59e0b","#ec4899","#34d399","#a855f7","#f87171"].includes(C)?I.colors[S%I.colors.length]:typeof C=="string"?C:I.colors[S%I.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((v,b)=>v+(b.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 l=i._getPreset();t.save(),t.beginPath(),t.roundRect(-n/2,-a/2,n,a,10),t.fillStyle=l.cardBackground,t.fill(),t.strokeStyle=l.cardBorderColor,t.lineWidth=1,t.stroke();const h=i.showLegend?Math.ceil(i.slices.length/2):0,c=h>0?h*(i.legendFontSize+8)+10:0,g=a-c-16,f=Math.min(n-24,g)/2,d=0,p=-c/2;if(i.chartType==="rose"){const v=Math.max(...i.slices.map(S=>S.value||0)),b=Math.PI*2/i.slices.length,C=f>0?i.sliceGap/f:0;i.slices.forEach((S,I)=>{const w=S.value||0;if(w===0)return;const M=w/v*f,_=-Math.PI/2+I*b+C/2,T=_+b-C,$=i._resolveSliceColor(S,I);if(t.beginPath(),t.moveTo(d,p),t.arc(d,p,M,_,T),t.closePath(),t.fillStyle=$+"cc",t.fill(),t.strokeStyle=$,t.lineWidth=1.5,t.stroke(),i.showLabels){const k=_+(T-_)/2,E=d+M*.65*Math.cos(k),L=p+M*.65*Math.sin(k),O=Math.round(w/r*100);t.save(),t.font=`bold ${i.labelFontSize}px Inter, sans-serif`,t.fillStyle=l.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${O}%`,E,L),t.restore()}})}else{const v=i.chartType==="pie"?0:i.innerRadius,b=f*Math.max(0,v),C=f>0?i.sliceGap/f:0;let S=-Math.PI/2;if(i.slices.forEach((I,w)=>{const M=I.value||0;if(M===0){S+=M/r*Math.PI*2;return}const _=M/r*Math.PI*2,T=S+C/2,$=S+_-C/2;if($<=T){S+=_;return}const k=i._resolveSliceColor(I,w);if(t.beginPath(),t.fillStyle=k,b<=0?(t.moveTo(d,p),t.arc(d,p,f,T,$),t.lineTo(d,p)):(t.moveTo(d+f*Math.cos(T),p+f*Math.sin(T)),t.arc(d,p,f,T,$),t.arc(d,p,b,$,T,!0),t.closePath()),t.fill(),i.showLabels){const E=T+($-T)/2,L=b+(f-b)/2,O=d+L*Math.cos(E),A=p+L*Math.sin(E),W=Math.round(M/r*100);t.save(),t.font=`bold ${i.labelFontSize}px Inter, sans-serif`,t.fillStyle=l.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${W}%`,O,A),t.restore()}S+=_}),i.chartType==="donut"&&i.showCenterText&&b>14){const I=Math.round(r),w=Math.min(Math.floor(b*.52),20),M=Math.min(Math.floor(b*.26),10);t.textAlign="center",t.textBaseline="middle",t.font=`bold ${w}px Inter, sans-serif`,t.fillStyle=l.centerTextColor,t.fillText(I.toString(),d,p-M*.5),i.centerLabel&&(t.font=`${M}px Inter, sans-serif`,t.fillStyle=l.centerLabelColor,t.fillText(i.centerLabel,d,p+w*.6))}}if(i.showLegend&&i.slices.length>0){t.font=`${i.legendFontSize}px Inter, sans-serif`;const v=2,b=n/v,C=i.legendFontSize+8,S=a/2-c+10,I=-n/2+10;i.slices.forEach((w,M)=>{const _=M%v,T=Math.floor(M/v),$=I+_*b,k=S+T*C,E=i._resolveSliceColor(w,M),L=7;t.beginPath(),t.roundRect($,k-L/2,L,L,2),t.fillStyle=E,t.fill(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=l.legendColor;const O=Math.round((w.value||0)/r*100),A=`${w.label||"Item"} ${O}%`,W=b-L-20;let x=A;for(;t.measureText(x).width>W&&x.length>4;)x=x.slice(0,-4)+"…";t.fillText(x,$+L+4,k)})}t.restore()}getRadioGroupItemIndexAtPointer(t,s,o){var M,_;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:((M=t.geometry)==null?void 0:M.width)||180,r=i.height!==void 0?i.height:((_=t.geometry)==null?void 0:_.height)||100,l=e.orientation||"vertical",h=e.itemGap!==void 0?e.itemGap:16,c=e.fontSize||14,g=this.getWorldTransform(t.id),f=s-g.x,d=o-g.y,p=-g.rotation*(Math.PI/180),m=Math.cos(p),y=Math.sin(p),v=f*m-d*y,b=f*y+d*m,S=8*2,I=-a/2,w=-r/2;if(l==="vertical"){const T=Math.max(S,c)+h;for(let $=0;$<n.length;$++){const k=w+$*T;if(v>=I&&v<=I+a&&b>=k&&b<=k+T)return $}}else{let T=I;for(let $=0;$<n.length;$++){const E=n[$].length*8,L=S+6+E+h;if(v>=T&&v<=T+L&&b>=w&&b<=w+r)return $;T+=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(p=>p.data&&p.data.length>=2)){t.save(),t.fillStyle="#6366f1",t.font="12px Inter, system-ui, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("NO DATA",0,0),t.restore();return}let n=1/0,a=-1/0,r=0;if(i.forEach(p=>{let m=p.data;if(p.isVarEnabled&&p.inputId){let y=this.inputs.get(p.inputId);if(y===void 0){const v=this.inputNameMap.get(p.inputId);v&&v.length>0&&(y=this.inputs.get(v[0]))}y&&Array.isArray(y)&&(m=y)}if(m&&m.length>0){const y=m.filter(v=>typeof v=="number"&&!isNaN(v));y.length>0&&(n=Math.min(n,...y),a=Math.max(a,...y),r=Math.max(r,m.length))}p._resolvedData=m}),r<2)return;const l=a-n,h=o/(r-1),c=p=>{const m=l===0?.5:(p-n)/l;return e/2-m*e},g=p=>p*h-o/2,f=s.axisColor||"#333333";if(s.showXAxis&&(t.beginPath(),t.strokeStyle=s.xAxisColor||f,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||f,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 p=0;p<r;p++){const m=g(p);t.fillText(`${p+1}`,m,e/2+5)}}if(s.showYLabels){t.textAlign="right",t.textBaseline="middle";const p=-o/2-5,m=(a+n)/2;t.fillText(a.toFixed(1),p,c(a)),t.fillText(m.toFixed(1),p,c(m)),t.fillText(n.toFixed(1),p,c(n))}const d=10;if(i.forEach(p=>{const m=p._resolvedData;if(!(!m||m.length<2)){if(p.showArea){if(t.beginPath(),t.moveTo(g(0),e/2),t.lineTo(g(0),c(m[0])),p.smoothing&&m.length>2)for(let v=0;v<m.length-1;v++){const b=m[v===0?v:v-1],C=m[v],S=m[v+1],I=m[v+1===m.length-1?v+1:v+2];for(let w=1;w<=d;w++){const M=w/d,_=this._catmullRom(b,C,S,I,M);t.lineTo(g(v+M),c(_))}}else for(let v=1;v<m.length;v++)t.lineTo(g(v),c(m[v]));t.lineTo(g(m.length-1),e/2),t.closePath();const y=t.globalAlpha;t.globalAlpha=y*(s.areaOpacity??.3),t.fillStyle=p.areaColor||"rgba(139, 92, 246, 0.2)",t.fill(),t.globalAlpha=y}if(t.beginPath(),t.strokeStyle=p.lineColor||"#3b82f6",t.lineWidth=p.lineWidth||2,t.lineJoin="round",t.lineCap="round",t.moveTo(g(0),c(m[0])),p.smoothing&&m.length>2)for(let y=0;y<m.length-1;y++){const v=m[y===0?y:y-1],b=m[y],C=m[y+1],S=m[y+1===m.length-1?y+1:y+2];for(let I=1;I<=d;I++){const w=I/d,M=this._catmullRom(v,b,C,S,w);t.lineTo(g(y+w),c(M))}}else for(let y=1;y<m.length;y++)t.lineTo(g(y),c(m[y]));t.stroke(),p.showPoints&&m.forEach((y,v)=>{const b=g(v),C=c(y);t.beginPath(),t.arc(b,C,(p.pointSize||6)/2,0,Math.PI*2),t.fillStyle=p.pointFill||"#ffffff",t.fill(),t.strokeStyle=p.pointStrokeColor||p.lineColor||"#3b82f6",t.lineWidth=p.pointStrokeWidth||1,t.stroke()})}}),s.showLegend&&i.length>0){const p=o/2-10;let m=-e/2+15;const y=s.legendFontSize||10,v=y+5;t.font=`${y}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="alphabetic",i.forEach(b=>{const S=b.label||"Series",I=t.measureText(S).width;t.beginPath(),t.rect(p-I-8-5,m-(8/2+2),8,8),t.fillStyle=b.lineColor||"#3b82f6",t.fill(),t.fillStyle=s.legendColor||"#333333",t.fillText(S,p,m),m+=v})}}_catmullRom(t,s,o,e,i){const n=(o-t)*.5,a=(e-s)*.5,r=i*i,l=i*r;return(2*s-2*o+n+a)*l+(-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,h=(((n=(i=this.artboard)==null?void 0:i.tokens)==null?void 0:n.colors)||{})[r]||r;return t.fillStyle=h,h}if((s.type==="LinearGradient"||s.type==="RadialGradient"||s.type==="AngularGradient"||s.type==="DiamondGradient")&&s.stops){const r=(l,h=100)=>{var C,S;const g=(((S=(C=this.artboard)==null?void 0:C.tokens)==null?void 0:S.colors)||{})[l]||l,f=this.normalizeOpacity(s.opacity??100),p=this.normalizeOpacity(h)*f;if(p>=1&&g.startsWith("#"))return g;const m=g.startsWith("#")?g.replace("#",""):"ffffff",y=parseInt(m.substring(0,2),16),v=parseInt(m.substring(2,4),16),b=parseInt(m.substring(4,6),16);return`rgba(${y}, ${v}, ${b}, ${p})`};if(s.type==="LinearGradient"){const l=(p,m,y)=>Array.isArray(p)?p[m]??(m===0?0:1):p&&typeof p=="object"?p[y]??(m===0?0:1):m===0?0:1,h=l(s.start,0,"x")*o-o/2,c=l(s.start,1,"y")*e-e/2,g=l(s.end,0,"x")*o-o/2,f=l(s.end,1,"y")*e-e/2,d=t.createLinearGradient(h,c,g,f);if(s.stops.forEach(p=>{const m=p.offset!==void 0?p.offset:p.pos!==void 0?p.pos:p.position!==void 0?p.position:0,y=r(p.color||"#000000",p.opacity??100);d.addColorStop(Math.max(0,Math.min(1,m)),y)}),s.gradientTransform&&d.setTransform){const[p,m,y,v,b,C]=s.gradientTransform;d.setTransform({a:p,b:m,c:y,d:v,e:b,f:C})}return d}else if(s.type==="RadialGradient"){const l=(d,p,m)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[m]??.5:.5,h=l(s.center,0,"x")*o-o/2,c=l(s.center,1,"y")*e-e/2,g=(s.radius??.5)*Math.max(o,e),f=t.createRadialGradient(h,c,0,h,c,g);if(s.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,m=r(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),m)}),s.gradientTransform&&f.setTransform){const[d,p,m,y,v,b]=s.gradientTransform;f.setTransform({a:d,b:p,c:m,d:y,e:v,f:b})}return f}else if(s.type==="AngularGradient"){const l=(d,p,m)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[m]??.5:.5,h=l(s.center||[.5,.5],0,"x")*o-o/2,c=l(s.center||[.5,.5],1,"y")*e-e/2,g=(s.degree||s.angle||0)*(Math.PI/180),f=(a=t.createConicGradient)==null?void 0:a.call(t,g,h,c);if(f){if(s.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,m=r(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),m)}),s.gradientTransform&&f.setTransform){const[d,p,m,y,v,b]=s.gradientTransform;f.setTransform({a:d,b:p,c:m,d:y,e:v,f:b})}return f}}else if(s.type==="DiamondGradient"){const l=(d,p,m)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[m]??.5:.5,h=l(s.center||[.5,.5],0,"x")*o-o/2,c=l(s.center||[.5,.5],1,"y")*e-e/2,g=(s.radius??.5)*Math.max(o,e);t.save(),t.translate(h,c),t.rotate(Math.PI/4);const f=t.createRadialGradient(0,0,0,0,0,g);if(s.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,m=r(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),m)}),s.gradientTransform&&f.setTransform){const[d,p,m,y,v,b]=s.gradientTransform;f.setTransform({a:d,b:p,c:m,d:y,e:v,f:b})}return t.scale(1/Math.SQRT2,1/Math.SQRT2),t.fillStyle=f,t.restore(),f}}if(s.type==="Pattern"&&s.url){let r=this.imageCache.get(s.url);if(r||(r=new Image,r.src=s.url,this.imageCache.set(s.url,r)),r.complete&&r.naturalWidth>0){const l=t.createPattern(r,"repeat");if(l&&(s.scaleX!==void 0||s.offsetX!==void 0)){const h=new DOMMatrix,c=s.scaleX??1,g=s.scaleY??1,f=s.offsetX??0,d=s.offsetY??0,p=s.rotation??0;h.translateSelf(f,d),h.rotateSelf(p),h.scaleSelf(c,g),l.setTransform(h)}return l}}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,l=0,h=0,c=0;typeof a=="number"?r=l=h=c=a:Array.isArray(a)?a.length===1?r=l=h=c=a[0]:a.length===2?(r=h=a[0],l=c=a[1]):a.length===3?(r=a[0],l=c=a[1],h=a[2]):a.length>=4&&(r=a[0],l=a[1],h=a[2],c=a[3]):a&&typeof a=="object"&&(r=a.tl??a.corner_radius??a.cornerRadius??0,l=a.tr??a.corner_radius??a.cornerRadius??0,h=a.br??a.corner_radius??a.cornerRadius??0,c=a.bl??a.corner_radius??a.cornerRadius??0);const g=Math.min(Math.abs(e)/2,Math.abs(i)/2);if(r=Math.min(Math.max(0,r),g),l=Math.min(Math.max(0,l),g),h=Math.min(Math.max(0,h),g),c=Math.min(Math.max(0,c),g),t.roundRect){t.roundRect(s,o,e,i,[r,l,h,c]);return}t.moveTo(s+r,o),t.lineTo(s+e-l,o),t.arcTo(s+e,o,s+e,o+l,l),t.lineTo(s+e,o+i-h),t.arcTo(s+e,o+i,s+e-h,o+i,h),t.lineTo(s+c,o+i),t.arcTo(s,o+i,s,o+i-c,c),t.lineTo(s,o+r),t.arcTo(s,o,s+r,o,r),t.closePath()}renderListView(t,s){var L,O,A,W;const o=this.objectStates.get(s.id)||{},e=o.options||s.options||{},i=o.width!==void 0?o.width:((L=s.geometry)==null?void 0:L.width)||200,n=o.height!==void 0?o.height:((O=s.geometry)==null?void 0:O.height)||300,a=-i/2,r=-n/2,l=o.corner_radius!==void 0?o.corner_radius:e.corner_radius??0,h=e.orientation||"vertical",c=e.items||[],g=e.itemGap??10,f=e.itemHeight??50,d=e.itemWidth??200,p=e.scrollOffset??0,m=e.padding??0,y=e.glassEffect!==!1,v=e.accentColor||"#3b82f6",b=e.itemTextColor||"#333333",C=e.itemBackgroundColor||"#ffffff",S=e.hoveredIndex??null,I=e.activeItemIndex??null,w=e.glowIntensity??0,M=e.glowColor||"#3b82f6",_=typeof M=="string"?M:M.color||((W=(A=M.stops)==null?void 0:A[0])==null?void 0:W.color)||"#3b82f6",T=e.opacity!==void 0?e.opacity:s.opacity!==void 0?s.opacity:1;if(t.save(),t.globalAlpha*=T,w>0){const x=t.getTransform(),Y=Math.sqrt(x.a*x.a+x.b*x.b)||1;t.shadowColor=_,t.shadowBlur=w*2*Y,t.shadowOffsetX=0,t.shadowOffsetY=0}if(y){const x=e.listBackgroundColor||"rgba(31, 41, 55, 0.4)",Y=this.createCanvasFill(t,x,i,n);t.fillStyle=Y||"rgba(31, 41, 55, 0.4)",this.drawListViewRect(t,a,r,i,n,l),t.fill();const H=t.createLinearGradient(a,r,a+i,r+n);H.addColorStop(0,"rgba(255, 255, 255, 0.15)"),H.addColorStop(.5,"rgba(255, 255, 255, 0.08)"),H.addColorStop(1,"rgba(255, 255, 255, 0.03)"),t.fillStyle=H,this.drawListViewRect(t,a,r,i,n,l),t.fill(),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1,this.drawListViewRect(t,a,r,i,n,l),t.stroke()}else{const x=e.listBackgroundColor||"transparent",Y=this.createCanvasFill(t,x,i,n);Y&&(t.fillStyle=Y,this.drawListViewRect(t,a,r,i,n,l),t.fill());const H=e.borderWidth??0;H>0&&(t.strokeStyle=e.borderColor||"#cccccc",t.lineWidth=H,this.drawListViewRect(t,a,r,i,n,l),t.stroke())}t.shadowBlur=0,t.save(),this.drawListViewRect(t,a,r,i,n,l),t.clip();const $=typeof m=="number"?m:h==="vertical"?m[0]:m[3];let k=(h==="vertical"?r:a)+p+$;if(t.textBaseline="middle",c.forEach((x,Y)=>{const H=h==="vertical"?i:d,Q=h==="vertical"?f:n,P=h==="vertical"?a:k,F=h==="vertical"?k:r,U=S===Y,J=I===Y;if(J){const ut=this.createCanvasFill(t,v,H,Q);t.fillStyle=ut||v;const ot=t.globalAlpha;t.globalAlpha=ot*.8,t.fillRect(P,F,H,Q),t.globalAlpha=ot}else if(U)t.fillStyle=y?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",t.fillRect(P,F,H,Q);else if(C!=="transparent"){const ut=this.createCanvasFill(t,C,H,Q);t.fillStyle=ut||C,t.fillRect(P,F,H,Q)}if(J||U){const ut=this.createCanvasFill(t,v,h==="vertical"?3:H,h==="vertical"?Q:3);t.fillStyle=ut||v,h==="vertical"?t.fillRect(P,F,3,Q):t.fillRect(P,F+Q-3,H,3)}const it=J?"#ffffff":y?"rgba(255, 255, 255, 0.9)":b;t.fillStyle=it,t.font=J||U?"600 14px Inter, sans-serif":"400 14px Inter, sans-serif";const dt=typeof x=="string"?x:(x==null?void 0:x.label)||`Item ${Y+1}`,yt=P+(h==="vertical"?16:H/2),ht=F+Q/2;h==="horizontal"?t.textAlign="center":t.textAlign="left",t.fillText(dt,yt,ht),k+=(h==="vertical"?f:d)+g}),t.restore(),e.showScrollbar!==!1){const x=(c.length||0)*(h==="vertical"?f:d)+((c.length||0)-1)*g,Y=h==="vertical"?n:i;if(x>Y){const H=Y/x,Q=Y*H,P=-p/x*Y,F=e.scrollbarColor||"rgba(255,255,255,0.3)",U=e.scrollbarWidth||4;t.fillStyle=F,h==="vertical"?t.fillRect(a+i-U-2,r+P,U,Q):t.fillRect(a+P,r+n-U-2,Q,U)}}t.restore()}updateListViewScrollFromPointer(t){var m,y;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=this.objectStates.get(t.id)||{},a=s.items||[],r=s.itemGap??10,l=s.itemHeight??50,h=s.itemWidth??200,c=n.width!==void 0?n.width:((m=t.geometry)==null?void 0:m.width)||200,g=n.height!==void 0?n.height:((y=t.geometry)==null?void 0:y.height)||300,f=(a.length||0)*(o==="vertical"?l:h)+((a.length||0)-1)*r,p=Math.max(0,f-(o==="vertical"?g:c)+(s.padding*2||0));s.scrollOffset>0&&(s.scrollOffset=0),s.scrollOffset<-p&&(s.scrollOffset=-p)}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 $,k;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:(($=t.geometry)==null?void 0:$.width)||200,r=i.height!==void 0?i.height:((k=t.geometry)==null?void 0:k.height)||300,l=e.orientation||"vertical",h=e.itemGap??10,c=e.itemHeight??50,g=e.itemWidth??200,f=e.scrollOffset??0,d=e.padding??0,p=this.getWorldTransform(t.id),m=s-p.x,y=o-p.y,v=-p.rotation*(Math.PI/180),b=Math.cos(v),C=Math.sin(v),S=m*b-y*C,I=m*C+y*b,w=-a/2,M=-r/2,_=typeof d=="number"?d:l==="vertical"?d[0]:d[3];let T=(l==="vertical"?M:w)+f+_;for(let E=0;E<n.length;E++){const L=l==="vertical"?a:g,O=l==="vertical"?c:r,A=l==="vertical"?w:T,W=l==="vertical"?T:M;if(S>=A&&S<=A+L&&I>=W&&I<=W+O)return E;T+=(l==="vertical"?c:g)+h}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 g,f,d,p,m,y,v,b,C,S,I,w,M,_,T,$,k,E,L,O,A,W,x,Y,H,Q,P,F,U,J,it,dt,yt,ht,ut,ot,Et,Ft,wt,Gt,Yt,B,nt,Vt,kt,_t,Nt,Jt,Kt,Qt,te,ce,se,ne,K,ft,q,X,Z,j,At,Lt,Tt,Ut,vt,R,ct,zt,Ot,ie,Bt,Xt,$t,rt,It,Ct,St,mt,Rt,lt,st,at,Mt,V,pt,gt,de,be,Se,Ie,_e,qt,oe,ye,we,Me,ue,fe,he,ve,Pe,Fe,$e,Ee,We,Be,ns,os,as,rs,ls,cs,fs,hs,ds,us,ps,gs;if(!n.enabled)return;const a=n.startTime||0,r=n.endTime||1/0;if(this.currentTime<a||this.currentTime>r)return;const l=i.x-s,h=i.y-o,c=Math.sqrt(l*l+h*h);if(this.frameCount%240===0&&Math.random()<.1&&console.log(`[ExodeUI] Executing ${n.type} on ${e.name}`),n.type===G.Proximity){const D=((g=n.settings)==null?void 0:g.radius)||300,N=((f=n.settings)==null?void 0:f.falloff)||"smooth";let z=0;c<D&&(N==="linear"?z=1-c/D:z=Math.pow(1-c/D,2)),n.sensors.forEach(tt=>{this.applyBehaviorSensor(i,tt,z,t,n.settings,e,l,h,c)})}else if(n.type===G.Magnetic){const D=((d=n.settings)==null?void 0:d.radius)||400,N=((p=n.settings)==null?void 0:p.strength)||.5;if(c<D&&c>5){const z=1-c/D,tt=l*z*N,Pt=h*z*N;i.x-=tt*t*10,i.y-=Pt*t*10}}else if(n.type===G.Repel){const D=((m=n.settings)==null?void 0:m.radius)||300,N=((y=n.settings)==null?void 0:y.strength)||1;if(c<D){const z=Math.pow(1-c/D,2);i.x+=l/(c||1)*z*60*N*t*5,i.y+=h/(c||1)*z*60*N*t*5}}else if(n.type===G.Orbit){const D=((v=n.settings)==null?void 0:v.speed)||1,N=((b=n.settings)==null?void 0:b.radius)||30,z=this.currentTime*D*Math.PI*2;i.x+=Math.cos(z)*N*t*5,i.y+=Math.sin(z)*N*t*5,i.rotation+=2*t*5}else if(n.type===G.Vortex){const D=((C=n.settings)==null?void 0:C.radius)||400,N=((S=n.settings)==null?void 0:S.speed)||2,z=((I=n.settings)==null?void 0:I.strength)||1;if(c<D){const tt=Math.pow(1-c/D,1.5),Pt=this.currentTime*N*Math.PI*2,xt=Math.cos(Pt)*30-l*.4,Dt=Math.sin(Pt)*30-h*.4;i.x+=xt*tt*z*t*5,i.y+=Dt*tt*z*t*5,i.rotation+=5*tt*z*t*5,i.scale_x*=1-tt*.1*z*t,i.scale_y*=1-tt*.1*z*t}}else if(n.type===G.Fluid){const D=((w=n.settings)==null?void 0:w.radius)||300,N=((M=n.settings)==null?void 0:M.strength)||1;if(c<D){const z=Math.pow(1-c/D,1.2),tt=l/(c||1)*z*1.2*N,Pt=h/(c||1)*z*1.2*N;i.x+=tt*10*t*5,i.y+=Pt*10*t*5,i.scale_x*=1+z*.3*N*t,i.scale_y*=1+z*.3*N*t}}else if(n.type===G.Elastic){const D=((_=n.settings)==null?void 0:_.radius)||300,N=((T=n.settings)==null?void 0:T.strength)||1;if(c<D){const z=1-c/D;i.scale_x*=1+z*.4*N*t,i.scale_y*=1+z*.4*N*t}}else if(n.type===G.Holographic){const D=i.x-this.canvasWidth/2,N=i.y-this.canvasHeight/2,z=(($=n.settings)==null?void 0:$.factor)||25;if(i.x-=D/1e3*z*t*5,i.y-=N/1e3*z*t*5,i.style){const tt=1-Math.min(1,c/400);i.style.exposure=(i.style.exposure||1)+tt*.5*t}}else if(n.type===G.Sticky){const D=((k=n.settings)==null?void 0:k.radius)||80,N=((E=n.settings)==null?void 0:E.strength)||1;if(c<D){const z=Math.pow(1-c/D,2);i.x-=l*z*N*t*10,i.y-=h*z*N*t*10,i.scale_x*=1-z*.1*N*t,i.scale_y*=1-z*.1*N*t}}else if(n.type===G.Dilation){const D=((L=n.settings)==null?void 0:L.size)||120,N=((O=n.settings)==null?void 0:O.strength)||1;if(c<D){const z=1-c/D;i.scale_x*=1+z*.5*N*t,i.scale_y*=1+z*.5*N*t}}else if(n.type===G.Parallax){const D=((A=n.settings)==null?void 0:A.factor)||15,N=((W=n.settings)==null?void 0:W.strength)||1,z=this.canvasWidth/2,tt=this.canvasHeight/2,Pt=this._lastPointerPos||{x:z,y:tt},xt=(Pt.x-z)/z,Dt=(Pt.y-tt)/tt,ee=(((x=e.transform)==null?void 0:x.x)??0)+xt*D*N,pe=(((Y=e.transform)==null?void 0:Y.y)??0)+Dt*D*N,Ce=(((H=e.transform)==null?void 0:H.rotate_x)??0)-Dt*D*1.5*N,ae=(((Q=e.transform)==null?void 0:Q.rotate_y)??0)+xt*D*1.5*N,me=Math.min(1,10*t);i.x=this.lerp(i.x??((P=e.transform)==null?void 0:P.x)??0,ee,me),i.y=this.lerp(i.y??((F=e.transform)==null?void 0:F.y)??0,pe,me),i.rotate_x=this.lerp(i.rotate_x??((U=e.transform)==null?void 0:U.rotate_x)??0,Ce,me),i.rotate_y=this.lerp(i.rotate_y??((J=e.transform)==null?void 0:J.rotate_y)??0,ae,me)}else if(n.type===G.Fold){if(c<300){const D=1-c/300,N=(l>0?-1:1)*D*10,z=1-D*.1,tt=h/300*D*20,Pt=-(l/300)*D*20,xt=Math.min(1,10*t);i.skew_x=this.lerp(i.skew_x??((it=e.transform)==null?void 0:it.skew_x)??0,N,xt),i.scale_y=this.lerp(i.scale_y??((dt=e.transform)==null?void 0:dt.scale_y)??1,(((yt=e.transform)==null?void 0:yt.scale_y)??1)*z,xt),i.rotate_x=this.lerp(i.rotate_x??((ht=e.transform)==null?void 0:ht.rotate_x)??0,tt,xt),i.rotate_y=this.lerp(i.rotate_y??((ut=e.transform)==null?void 0:ut.rotate_y)??0,Pt,xt),i.style=i.style||{...e.style},i.style.artEffect={enabled:!0,type:"fold_overlay",intensity:((ot=n.settings)==null?void 0:ot.opacity)??.5}}}else if(n.type===G.Crumple){if(c<300){const D=1-c/300,N=D*(Math.random()-.5)*5,z=D*(Math.random()-.5)*.05,tt=Math.min(1,15*t);i.skew_x=this.lerp(i.skew_x??((Et=e.transform)==null?void 0:Et.skew_x)??0,N,tt),i.scale_x=this.lerp(i.scale_x??((Ft=e.transform)==null?void 0:Ft.scale_x)??1,(((wt=e.transform)==null?void 0:wt.scale_x)??1)*(1+z),tt),i.scale_y=this.lerp(i.scale_y??((Gt=e.transform)==null?void 0:Gt.scale_y)??1,(((Yt=e.transform)==null?void 0:Yt.scale_y)??1)*(1+z),tt),i.style=i.style||{...e.style},i.style.artEffect={enabled:!0,type:"crumple_overlay",intensity:((B=n.settings)==null?void 0:B.intensity)??1,scale:((nt=n.settings)==null?void 0:nt.scale)??2}}}else if(n.type===G.Squash){const D=((Vt=n.settings)==null?void 0:Vt.strength)||.8;c<(e.width||100)&&this.isMouseDown?(i.scale_y=this.lerp(i.scale_y??1,(((kt=e.transform)==null?void 0:kt.scale_y)??1)*D,.3),i.scale_x=this.lerp(i.scale_x??1,(((_t=e.transform)==null?void 0:_t.scale_x)??1)*(1+(1-D)*.4),.3)):(i.scale_y=this.lerp(i.scale_y??1,((Nt=e.transform)==null?void 0:Nt.scale_y)??1,.2),i.scale_x=this.lerp(i.scale_x??1,((Jt=e.transform)==null?void 0:Jt.scale_x)??1,.2))}else if(n.type===G.TextCounter){const D=((Kt=n.settings)==null?void 0:Kt.duration)||2,N=((Qt=n.settings)==null?void 0:Qt.from)||0,z=((te=n.settings)==null?void 0:te.to)||100;n._runtimeStart===void 0&&(n._runtimeStart=this.currentTime);const tt=this.currentTime-n._runtimeStart,Pt=Math.min(1,tt/D),xt=Math.floor(N+(z-N)*Pt);if(((ce=e.geometry)==null?void 0:ce.type)==="Text"){const Dt=((se=n.settings)==null?void 0:se.prefix)||"",ee=((ne=n.settings)==null?void 0:ne.suffix)||"";i.geometry||(i.geometry={...e.geometry}),i.geometry.text=`${Dt}${xt}${ee}`}}else if(n.type===G.Spotlight){const D=((K=n.settings)==null?void 0:K.radius)||250,N=((ft=n.settings)==null?void 0:ft.strength)||1.5;if(c<D){const z=Math.pow(1-c/D,2);i.style||(i.style={...e.style}),i.style.adjustments||(i.style.adjustments={...(q=e.style)==null?void 0:q.adjustments}),i.style.adjustments.exposure=(((Z=(X=e.style)==null?void 0:X.adjustments)==null?void 0:Z.exposure)||0)+z*N*50}else(j=i.style)!=null&&j.adjustments&&(i.style.adjustments.exposure=this.lerp(i.style.adjustments.exposure||0,((Lt=(At=e.style)==null?void 0:At.adjustments)==null?void 0:Lt.exposure)||0,.1))}else if(n.type===G.Noise||n.type===G.Float){const D=(((Tt=n.settings)==null?void 0:Tt.frequency)||((Ut=n.settings)==null?void 0:Ut.speed)||1)*.002,N=(((vt=n.settings)==null?void 0:vt.amplitude)||((R=n.settings)==null?void 0:R.range)||50)*(((ct=n.settings)==null?void 0:ct.strength)||1),z=Date.now();i.x+=Math.sin(z*D)*N*t,i.y+=Math.cos(z*D*.8)*N*t,i.rotation+=Math.sin(z*D*.5)*5*t}else if(n.type===G.Pulse){const D=(((zt=n.settings)==null?void 0:zt.speed)||1)*.005,N=(((Ot=n.settings)==null?void 0:Ot.scale)||1.2)-1,z=Math.sin(Date.now()*D),tt=((ie=n.settings)==null?void 0:ie.strength)||1;i.scale_x*=1+z*N*tt*t,i.scale_y*=1+z*N*tt*t,i.style&&(i.style.exposure=(i.style.exposure||1)+Math.max(0,z)*.1*tt*t)}else if(n.type===G.Draggable){const D=((Bt=n.settings)==null?void 0:Bt.radius)||150,N=this.draggingBehaviors.has(e.id);if(c<D||N){const z=((Xt=n.settings)==null?void 0:Xt.strength)||1,tt=N?1:Math.max(0,1-c/D);this.applyBehaviorSensor(i,jt.PositionX,tt*z,t,n.settings),this.applyBehaviorSensor(i,jt.PositionY,tt*z,t,n.settings)}}else if(n.type===G.Scroll){const D=(($t=n.settings)==null?void 0:$t.axis)||"vertical",N=((rt=n.settings)==null?void 0:rt.factor)||.5,z=((It=n.settings)==null?void 0:It.strength)||1,tt=((Ct=n.settings)==null?void 0:Ct.scaleFactor)||0;(D==="vertical"||D==="both")&&(i.y+=this.scrollOffset.y*N*z*t),(D==="horizontal"||D==="both")&&(i.x+=this.scrollOffset.x*N*z*t),tt!==0&&(i.scale_x*=1+this.scrollOffset.y*tt*t,i.scale_y*=1+this.scrollOffset.y*tt*t)}else if(n.type===G.LookAt){const D=((St=n.settings)==null?void 0:St.factor)||1,N=((mt=n.settings)==null?void 0:mt.strength)||1,z=Math.atan2(-h,-l)*(180/Math.PI),tt=i.rotation,Pt=(z-tt+180)%360-180;i.rotation+=Pt*D*N*t*10}else if(n.type===G.Scan){const D=(((Rt=n.settings)==null?void 0:Rt.speed)||1)*.004,N=((lt=n.settings)==null?void 0:lt.strength)||1,z=(Math.sin(Date.now()*D)+1)/2;i.style&&(i.style.exposure=(i.style.exposure||1)+z*N*t*5),i.x+=(z-.5)*20*N*t}else if(n.type===G.Glint)i.style=i.style||{...e.style},i.style.artEffect={enabled:!0,type:"glint_overlay",intensity:((st=n.settings)==null?void 0:st.strength)??.8};else if(n.type===G.Ratchet){const D=((at=n.settings)==null?void 0:at.steps)||12,N=(((Mt=n.settings)==null?void 0:Mt.speed)||1)*30,z=Math.floor(i.rotation/(360/D))*(360/D);i.rotation=this.lerp(i.rotation,z+N*t,.1)}else if(n.type===G.Jitter&&c<300){const D=((V=n.settings)==null?void 0:V.strength)||1,N=(((pt=n.settings)==null?void 0:pt.intensity)||5)*D;i.x+=(Math.random()-.5)*N*t*60,i.y+=(Math.random()-.5)*N*t*60,i.rotation+=(Math.random()-.5)*N*t*120}else if(n.type===G.Follower){const D=(gt=n.settings)==null?void 0:gt.targetId;if(D){const N=this.objectStates.get(D);if(N){const z=((de=n.settings)==null?void 0:de.stiffness)||.1,tt=N.x-i.x,Pt=N.y-i.y;i.x+=tt*z*t*60,i.y+=Pt*z*t*60}}}else if(n.type===G.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===G.Gravity){const D=((be=n.settings)==null?void 0:be.strength)||9.8;i.y+=D*t*10}else if(n.type===G.Velocity){const D=((Se=n.settings)==null?void 0:Se.vx)||0,N=((Ie=n.settings)==null?void 0:Ie.vy)||0;i.x+=D*t*10,i.y+=N*t*10}else if(n.type===G.Shear){const D=((_e=n.settings)==null?void 0:_e.strength)||1,N=((qt=n.settings)==null?void 0:qt.radius)||300;if(c<N){const z=1-c/N;i.skew_x=this.lerp(i.skew_x||0,(((oe=e.transform)==null?void 0:oe.skew_x)||0)+z*D*30,.1)}else i.skew_x=this.lerp(i.skew_x||0,((ye=e.transform)==null?void 0:ye.skew_x)||0,.05)}else if(n.type===G.Lens){const D=((we=n.settings)==null?void 0:we.radius)||200,N=((Me=n.settings)==null?void 0:Me.strength)||.5;if(c<D){const z=Math.pow(1-c/D,2);i.scale_x=this.lerp(i.scale_x??1,(((ue=e.transform)==null?void 0:ue.scale_x)??1)*(1+z*N),.2),i.scale_y=this.lerp(i.scale_y??1,(((fe=e.transform)==null?void 0:fe.scale_y)??1)*(1+z*N),.2)}else i.scale_x=this.lerp(i.scale_x??1,((he=e.transform)==null?void 0:he.scale_x)??1,.1),i.scale_y=this.lerp(i.scale_y??1,((ve=e.transform)==null?void 0:ve.scale_y)??1,.1)}else if(n.type===G.LayoutAnimation){const D=((Pe=n.settings)==null?void 0:Pe.watchProperties)||["x","y","scale_x","scale_y","opacity","rotation"],N=((Fe=n.settings)==null?void 0:Fe.duration)||.3;this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const z=this._layoutAnimCache.get(e.id);for(const tt of D){const Pt=this.getObjectProperty(i,e,tt);if(Pt===void 0)continue;const xt=z.get(tt);if(!xt)z.set(tt,{from:Pt,to:Pt,startTime:this.currentTime,duration:0});else if(xt.to!==Pt){const ee=this.getObjectProperty(i,e,tt);z.set(tt,{from:ee??xt.from,to:Pt,startTime:this.currentTime,duration:(($e=n.settings)==null?void 0:$e.duration)??N})}const Dt=z.get(tt);if(Dt.duration>0&&Dt.from!==Dt.to){const ee=this.currentTime-Dt.startTime,pe=Math.min(1,ee/Dt.duration),Ce=this.applyEasing(pe,((Ee=n.settings)==null?void 0:Ee.easing)||"easeOutCubic"),ae=Dt.from+(Dt.to-Dt.from)*Ce;this.setObjectProperty(i,e,tt,ae)}}}else if(n.type===G.StateReactive){this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const D=this._layoutAnimCache.get(e.id),N=((We=n.settings)==null?void 0:We.defaultDuration)||.3,z=["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 tt of z){const Pt=this.getObjectProperty(i,e,tt);if(Pt===void 0||typeof Pt!="number")continue;const xt=D.get(tt);if(!xt)D.set(tt,{from:Pt,to:Pt,startTime:this.currentTime,duration:0});else if(xt.to!==Pt){const ee=this.getObjectProperty(i,e,tt);D.set(tt,{from:ee??xt.from,to:Pt,startTime:this.currentTime,duration:N})}const Dt=D.get(tt);if(Dt.duration>0&&Dt.from!==Dt.to){const ee=this.currentTime-Dt.startTime,pe=Math.min(1,ee/Dt.duration),Ce=this.applyEasing(pe,((Be=n.settings)==null?void 0:Be.defaultEasing)||"easeOutCubic"),ae=Dt.from+(Dt.to-Dt.from)*Ce;this.setObjectProperty(i,e,tt,ae)}}}else if(n.type===G.SpringChain){const D=((ns=n.settings)==null?void 0:ns.connections)||[],N=((os=n.settings)==null?void 0:os.globalDamping)||.3;this._springChainState.has(e.id)||this._springChainState.set(e.id,new Map);const z=this._springChainState.get(e.id);for(const Pt of D){if(!z.has(Pt.targetId)){const xt=this.objectStates.get(Pt.targetId);z.set(Pt.targetId,{x:(xt==null?void 0:xt.x)??0,y:(xt==null?void 0:xt.y)??0,vx:0,vy:0})}z.has(e.id)||z.set(e.id,{x:i.x,y:i.y,vx:0,vy:0})}const tt=z.get(e.id);if(tt){tt.x=i.x,tt.y=i.y;for(const Pt of D){const xt=z.get(Pt.targetId);if(!xt)continue;const Dt=xt.x-tt.x,ee=xt.y-tt.y,pe=Math.sqrt(Dt*Dt+ee*ee)||.001,ae=(pe-(Pt.restLength||50))*(Pt.stiffness||.8),me=Dt/pe*ae,Ye=ee/pe*ae;tt.vx+=me*t*10,tt.vy+=Ye*t*10,xt.vx-=me*t*10,xt.vy-=Ye*t*10,tt.vx*=1-N*t*10,tt.vy*=1-N*t*10,xt.vx*=1-N*t*10,xt.vy*=1-N*t*10;const ge=this.objectStates.get(Pt.targetId);ge&&(ge.x+=xt.vx*t,ge.y+=xt.vy*t)}i.x+=tt.vx*t,i.y+=tt.vy*t}}else if(n.type===G.ParticleEmitter){const D=((as=n.settings)==null?void 0:as.rate)||10,N=((rs=n.settings)==null?void 0:rs.speed)||100,z=((ls=n.settings)==null?void 0:ls.size)||5,tt=((cs=n.settings)==null?void 0:cs.lifetime)||2,Pt=((fs=n.settings)==null?void 0:fs.gravity)||0,xt=((hs=n.settings)==null?void 0:hs.color)||"#ffffff",Dt=((ds=n.settings)==null?void 0:ds.maxParticles)||200,ee=(us=n.settings)!=null&&us.rateInputId?this.inputs.get(n.settings.rateInputId)??D:D,pe=(ps=n.settings)!=null&&ps.gravityInputId?this.inputs.get(n.settings.gravityInputId)??Pt:Pt,Ce=(gs=n.settings)!=null&&gs.speedInputId?this.inputs.get(n.settings.speedInputId)??N:N;this._emitterPools.has(e.id)||this._emitterPools.set(e.id,[]);const ae=this._emitterPools.get(e.id);let me=0;n._pendingBurst&&n._pendingBurst>0&&(me=n._pendingBurst,n._pendingBurst=0);const Ye=Math.floor(ee*t)+(me||0);for(let ge=0;ge<Math.min(Ye,Dt-ae.length);ge++){const re=Math.random()*Math.PI*2,ms=Ce*(.5+Math.random()*.5);ae.push({x:i.x,y:i.y,vx:Math.cos(re)*ms,vy:Math.sin(re)*ms,life:0,maxLife:tt*(.5+Math.random()*.5),size:z*(.5+Math.random()),color:xt,opacity:1})}for(let ge=ae.length-1;ge>=0;ge--){const re=ae[ge];re.vy+=pe*t*10,re.x+=re.vx*t,re.y+=re.vy*t,re.life+=t,re.opacity=Math.max(0,1-re.life/re.maxLife),re.life>=re.maxLife&&ae.splice(ge,1)}}})})}applyBehaviorSensor(t,s,o,e,i,n,a=0,r=0,l=1){var d,p,m,y,v,b,C,S,I,w,M,_,T,$,k,E,L,O,A,W,x,Y,H,Q;const h=(i==null?void 0:i.intensity)||(i==null?void 0:i.strength)||1,c=Math.min(1,15*e),g=l>0?a/l:0,f=l>0?r/l:0;switch(s){case jt.Scale:{const P=((d=n==null?void 0:n.transform)==null?void 0:d.scale_x)??1,F=((p=n==null?void 0:n.transform)==null?void 0:p.scale_y)??1,U=P*(1+o*h*.4),J=F*(1+o*h*.4);t.scale_x=(t.scale_x??P)*(1-c)+U*c,t.scale_y=(t.scale_y??F)*(1-c)+J*c;break}case jt.Opacity:{const P=((m=n==null?void 0:n.transform)==null?void 0:m.opacity)??100,F=Math.max(0,Math.min(100,P-o*h*100));t.opacity=(t.opacity??P)*(1-c)+F*c;break}case jt.RotateZ:{const P=((y=n==null?void 0:n.transform)==null?void 0:y.rotation)??0,F=P+o*h*45;t.rotation=(t.rotation??P)*(1-c)+F*c;break}case jt.RotateX:{const P=((v=n==null?void 0:n.transform)==null?void 0:v.rotate_x)??0,F=P-f*o*h*60;t.rotate_x=(t.rotate_x??P)*(1-c)+F*c;break}case jt.RotateY:{const P=((b=n==null?void 0:n.transform)==null?void 0:b.rotate_y)??0,F=P+g*o*h*60;t.rotate_y=(t.rotate_y??P)*(1-c)+F*c;break}case jt.PositionX:{const P=((C=n==null?void 0:n.transform)==null?void 0:C.x)??0,F=P-g*o*h*40;t.x=(t.x??P)*(1-c)+F*c;break}case jt.PositionY:{const P=((S=n==null?void 0:n.transform)==null?void 0:S.y)??0,F=P-f*o*h*40;t.y=(t.y??P)*(1-c)+F*c;break}case jt.SkewX:{const P=((I=n==null?void 0:n.transform)==null?void 0:I.skew_x)??0,F=P+g*o*h*45;t.skew_x=(t.skew_x??P)*(1-c)+F*c,t.skew_x>85&&(t.skew_x=85),t.skew_x<-85&&(t.skew_x=-85);break}case jt.Blur:{t.style||(t.style={...n==null?void 0:n.style}),t.style.blur||(t.style.blur={...(w=n==null?void 0:n.style)==null?void 0:w.blur});const P=((_=(M=n==null?void 0:n.style)==null?void 0:M.blur)==null?void 0:_.amount)||0,F=P+o*((i==null?void 0:i.blur)||20)*h;t.style.blur.amount=(t.style.blur.amount??P)*(1-c)+F*c;break}case jt.Exposure:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(T=n==null?void 0:n.style)==null?void 0:T.adjustments});const P=((k=($=n==null?void 0:n.style)==null?void 0:$.adjustments)==null?void 0:k.exposure)||0,F=P+o*((i==null?void 0:i.exposure)||50)*h;t.style.adjustments.exposure=(t.style.adjustments.exposure??P)*(1-c)+F*c;break}case jt.HueShift:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(E=n==null?void 0:n.style)==null?void 0:E.adjustments});const P=((O=(L=n==null?void 0:n.style)==null?void 0:L.adjustments)==null?void 0:O.hue)||0,F=P+o*((i==null?void 0:i.hue)||180)*h;t.style.adjustments.hue=(t.style.adjustments.hue??P)*(1-c)+F*c;break}case jt.Negative:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(A=n==null?void 0:n.style)==null?void 0:A.adjustments});const P=((x=(W=n==null?void 0:n.style)==null?void 0:W.adjustments)==null?void 0:x.negative)||0,F=P+o*((i==null?void 0:i.negative)||100)*h;t.style.adjustments.negative=(t.style.adjustments.negative??P)*(1-c)+F*c;break}case jt.CornerRadius:{const P=((Y=n==null?void 0:n.transform)==null?void 0:Y.corner_radius)||0,F=P+o*h*50;t.corner_radius=(t.corner_radius??P)*(1-c)+F*c;break}case jt.StrokeWidth:{t.style||(t.style={...n==null?void 0:n.style});const P=((H=n==null?void 0:n.style)==null?void 0:H.borderWidth)||0,F=P+o*h*10;t.style.borderWidth=(t.style.borderWidth??P)*(1-c)+F*c;break}case jt.LetterSpacing:{t.geometry||(t.geometry={});const P=((Q=n==null?void 0:n.geometry)==null?void 0:Q.letterSpacing)||0,F=P+o*h*10;t.geometry.letterSpacing=(t.geometry.letterSpacing??P)*(1-c)+F*c;break}}}getObjectProperty(t,s,o){const e=o.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.split(".");let n=t;for(let r=0;r<i.length-1;r++){const l=i[r];if(n[l]===void 0||n[l]===null){const h=s,c=i.slice(0,r+1).reduce((g,f)=>g==null?void 0:g[f],h);n[l]=c!==void 0?{...c}:{}}n=n[l]}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;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]):o[e]=s[e]);return o}renderFittedImage(t,s,o,e,i,n,a="cover"){const r=s.naturalWidth,l=s.naturalHeight,h=r/l,c=i/n;let g=i,f=n,d=o,p=e;a==="cover"?h>c?(g=n*h,d=o-(g-i)/2):(f=i/h,p=e-(f-n)/2):a==="contain"&&(h>c?(f=i/h,p=e+(n-f)/2):(g=n*h,d=o+(i-g)/2)),t.drawImage(s,d,p,g,f)}}const ni=Wt.forwardRef(({artboard:u,src:t,style:s,autoPlay:o=!0,fit:e="Contain",alignment:i="Center",onReady:n,onTrigger:a,onInputUpdate:r,onComponentChange:l,onToggle:h,onInputChange:c,onInputFocus:g,onInputBlur:f,onLog:d,onLogicUpdate:p,onButtonClick:m,onGraphPointClick:y,currentTime:v,revision:b=0,scrollY:C,scrollX:S,mouseX:I,mouseY:w,isMouseDown:M,inputs:_,interactive:T=!0,onNavigation:$},k)=>{const E=Wt.useRef(null),L=Wt.useRef(new is),O=Wt.useRef(void 0),A=Wt.useRef(0),W=Wt.useRef(null),x=Wt.useRef(b),[,Y]=Wt.useState(u||null),H=Wt.useRef(!0);Wt.useImperativeHandle(k,()=>E.current),Wt.useEffect(()=>(H.current=!0,()=>{H.current=!1,O.current&&cancelAnimationFrame(O.current)}),[]),Wt.useEffect(()=>{L.current.setLayout(e,i)},[e,i]),Wt.useEffect(()=>{const P=L.current;a&&P.setTriggerCallback(a),r&&P.setInputUpdateCallback((F,U)=>r({[F]:U})),l&&P.setComponentChangeCallback(F=>l(F)),h&&P.setToggleCallback(h),c&&P.setInputChangeCallback(c),g&&P.setInputFocusCallback(g),f&&P.setInputBlurCallback(f),d&&P.setOnLogCallback(F=>d(F,"info")),p&&P.setLogicUpdateCallback(p),m&&P.setButtonClickCallback(m),y&&P.setGraphPointClickCallback(F=>y(F.objectId,F)),$&&P.setNavigationCallback($)},[a,r,l,h,c,g,f,d,p,m,y,$]),Wt.useEffect(()=>{(async()=>{let F=u;if(t&&!u)try{t.startsWith("{")?F=JSON.parse(t):F=await(await fetch(t)).json()}catch(U){console.error("[ExodeUI] Failed to load src:",U)}if(F){const U=L.current,J=F.id||F.name||"default";(W.current!==J||x.current!==b)&&(U.load(F),W.current=J,x.current=b,Y(F),A.current=0,U.advance(0)),n&&n(U)}})()},[u==null?void 0:u.id,t,b]),Wt.useEffect(()=>{const P=F=>{if(!L.current||!H.current)return;const U=L.current,J=E.current;if(!J)return;const it=J.getContext("2d");if(!it)return;const dt=F/1e3;A.current===0&&(A.current=dt);let yt=dt-A.current;yt>.1&&(yt=.1),A.current=dt;const ht=J.getBoundingClientRect(),ut=window.devicePixelRatio||1,ot=Math.round(ht.width*ut),Et=Math.round(ht.height*ut);(J.width!==ot||J.height!==Et)&&(J.width=ot,J.height=Et),o?U.advance(yt):v!==void 0&&U.seek(v),U.render(it,J.width,J.height),O.current=requestAnimationFrame(P)};return O.current=requestAnimationFrame(P),()=>{O.current&&cancelAnimationFrame(O.current)}},[o,v]),Wt.useEffect(()=>{const P=L.current;C!==void 0&&P.updateInput("scrollY",C),S!==void 0&&P.updateInput("scrollX",S),I!==void 0&&P.updateInput("mouseX",I),w!==void 0&&P.updateInput("mouseY",w),M!==void 0&&P.updateInput("isMouseDown",M),_&&Object.entries(_).forEach(([F,U])=>P.updateInput(F,U))},[C,S,I,w,M,_]);const Q=(P,F)=>{if(!T||!E.current)return;const U=E.current,J=U.getBoundingClientRect(),it=P.clientX-J.left,dt=P.clientY-J.top,yt=window.devicePixelRatio||1;L.current.handlePointerInput(F,it*yt,dt*yt,U.width,U.height)};return Zt.jsx("canvas",{ref:E,onPointerDown:P=>{var F;Q(P,"down"),(F=E.current)==null||F.focus()},onPointerMove:P=>Q(P,"move"),onPointerUp:P=>Q(P,"up"),onPointerCancel:P=>Q(P,"up"),onClick:P=>Q(P,"click"),onWheel:P=>{L.current.handleWheel(P.deltaX,P.deltaY)},onKeyDown:P=>L.current.handleKeyDown(P.nativeEvent),onContextMenu:P=>P.preventDefault(),tabIndex:0,style:{...s,width:"100%",height:"100%",outline:"none",display:"block",touchAction:"none",pointerEvents:T?"auto":"none"}})});function oi(){const[u,t]=Wt.useState(null),s=Wt.useCallback((c,g)=>{u==null||u.setInputBool(c,g)},[u]),o=Wt.useCallback((c,g)=>{u==null||u.setInputNumber(c,g)},[u]),e=Wt.useCallback(c=>{u==null||u.fireTrigger(c)},[u]),i=Wt.useCallback((c,g)=>{u==null||u.setInputText(c,g)},[u]),n=Wt.useCallback((c,g)=>{u==null||u.setInputNumberArray(c,g)},[u]),a=Wt.useCallback((c,g)=>{u==null||u.setInputStringArray(c,g)},[u]),r=Wt.useCallback((c,g)=>{u==null||u.updateObjectOptions(c,g)},[u]),l=Wt.useCallback((c,g,f)=>{u==null||u.updateConstraint(c,g,f)},[u]),h=Wt.useCallback((c,g)=>{u==null||u.updateGraphData(c,g)},[u]);return{setEngine:t,engine:u,setInputBool:s,setInputNumber:o,fireTrigger:e,setInputText:i,setInputNumberArray:n,setInputStringArray:a,updateConstraint:l,updateGraphData:h,updateObjectOptions:r}}const ai=({artboard:u,config:t})=>{const s={...u.seo,...t},o=s.enableSmartExtraction!==!1;Wt.useEffect(()=>{const a=s.title||u.name;a&&(document.title=a);let r=s.description;if(!r&&o){const c=u.objects.filter(g=>{var f;return((f=g.geometry)==null?void 0:f.type)==="Text"}).sort((g,f)=>{var d,p;return(((d=f.geometry.text)==null?void 0:d.length)||0)-(((p=g.geometry.text)==null?void 0:p.length)||0)});c.length>0&&(r=c[0].geometry.text)}r&&(e("name","description",r),e("property","og:description",r)),s.keywords&&s.keywords.length>0&&e("name","keywords",s.keywords.join(", "));const l=s.ogImage||u.backgroundImage;l&&e("property","og:image",l),a&&e("property","og:title",a),e("property","og:type","website")},[s,u,o]);const e=(a,r,l)=>{let h=document.querySelector(`meta[${a}="${r}"]`);h||(h=document.createElement("meta"),h.setAttribute(a,r),document.head.appendChild(h)),h.setAttribute("content",l)},i=()=>{const a=[];return a.push(Zt.jsx("h1",{children:s.title||u.name},"artboard-title")),u.objects.forEach((l,h)=>{var c,g;if(!(l.visible===!1||l.isVisible===!1))if(((c=l.geometry)==null?void 0:c.type)==="Text"){const f=l.geometry.text;f&&(l.geometry.fontSize>24?a.push(Zt.jsx("h2",{children:f},l.id||h)):a.push(Zt.jsx("p",{children:f},l.id||h)))}else if(((g=l.geometry)==null?void 0:g.type)==="Image"){const f=l.geometry.src,d=l.altText||l.name||"Illustration";a.push(Zt.jsx("img",{src:f,alt:d},l.id||h))}else l.type==="Button"&&a.push(Zt.jsx("button",{children:l.name||"Button"},l.id||h))}),a},n=s.jsonLd||{"@context":"https://schema.org","@type":"VisualArtwork",name:s.title||u.name,description:s.description,image:s.ogImage||u.backgroundImage,abstract:"Animated interface created with ExodeUI"};return Zt.jsxs("div",{id:`exode-seo-${u.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(),Zt.jsx("script",{type:"application/ld+json",children:JSON.stringify(n)})]})},ri={version:"6.3.20"}.version;Ht.BehaviorSensor=jt,Ht.BehaviorType=G,Ht.ConditionOp=Ge,Ht.ExodeSEO=ai,Ht.ExodeUICanvas=ni,Ht.ExodeUIEngine=is,Ht.LogicOp=bt,Ht.VERSION=ri,Ht.useExodeUI=oi,Object.defineProperty(Ht,Symbol.toStringTag,{value:"Module"})});
|
|
4
|
+
`&&k++);y={...y,widths:P,indentApplied:!0}}if(!y)return{width:a,height:0,lineCount:0,lines:[]};let C=n;typeof C=="string"&&(C=parseFloat(C)),C>5&&o>0&&(C=C/o),r!==0&&(CanvasRenderingContext2D.prototype.measureText=b);let S;try{const P=y.maxFontSize||o;if(a>=1e5){const T=d.split(/\r\n|\r|\n/);S={lines:T.map($=>({text:$,width:0})),height:T.length*(C*P),lineCount:T.length}}else S=xe.layoutWithLines(y,a,C*P)}finally{r!==0&&v&&(CanvasRenderingContext2D.prototype.measureText=v)}let w=(S==null?void 0:S.height)!==void 0&&S.height>0?S.height:(((M=S==null?void 0:S.lines)==null?void 0:M.length)||0)*C*o;if(l>0&&S&&S.lines&&S.lines.length>1){let P=0;const T=y.fullText||t;for(let $=0;$<S.lines.length-1;$++)P+=S.lines[$].text.length,(T[P]===`
|
|
5
|
+
`||T[P]==="\r")&&(w+=l,P++,T[P-1]==="\r"&&T[P]===`
|
|
6
|
+
`&&P++)}let I=(S==null?void 0:S.lines)||[];return u.composer==="every-line"&&I.length>1&&(I=Is(I)),u.balanceRaggedLines===!0&&I.length>1&&(I=Ms(I)),{width:a,height:w,lineCount:I.length,lines:I}}function ze(u,t,s){let o=String(u||"").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,l)=>{if(r.endsWith("px")){const h=parseFloat(r);i[l]=h,n-=h}else r.endsWith("fr")?a+=parseFloat(r):r==="auto"&&(i[l]=100,n-=100)}),a>0&&n>0){const r=n/a;e.forEach((l,h)=>{l.endsWith("fr")&&(i[h]=r*parseFloat(l))})}return i}function Ve(u,t,s){try{const o=u.autoLayout;return!o||!o.enabled?{childUpdates:[]}:(o.mode||"linear")==="grid"?Ts(u,t,s):ks(u,t,s)}catch(o){return console.error("Layout Engine Error:",o),{childUpdates:[]}}}function ks(u,t,s){var E,F;const o=u.autoLayout,{direction:e,spacing:i,padding:n,align:a,wrap:r}=o,l=e==="vertical",h=t.map(O=>{const A=s(O.id),W=O.geometry;let x=(A==null?void 0:A.width)??W.width??100,B=(A==null?void 0:A.height)??W.height??100;if(W.type==="Ellipse"||W.type==="Polygon"||W.type==="Star"){const N=(A==null?void 0:A.radius)??W.radius??(A==null?void 0:A.outer_radius)??W.outer_radius??50;x=N*2,B=N*2}else if(W.type==="Text"){const N=De({text:(A==null?void 0:A.text)??W.text??"",fontFamily:W.fontFamily,fontSize:W.fontSize,fontWeight:W.fontWeight,fontStyle:W.fontStyle,lineHeight:W.lineHeight,width:W.width||200,letterSpacing:W.letterSpacing,paragraphSpacing:W.paragraphSpacing,paragraphIndent:W.paragraphIndent,textCase:W.textCase,segments:W.segments,enableSegments:W.enableSegments});B=N.height,W.width||(x=N.width)}return x*=O.transform.scale_x||1,B*=O.transform.scale_y||1,{id:O.id,w:x,h:B,original:O}});let c=u.width,g=u.height;const f=((E=u.layoutProps)==null?void 0:E.width)==="hug",d=((F=u.layoutProps)==null?void 0:F.height)==="hug",p=[];let m=[],y=0,v=0;const b=c-n.left-n.right,C=g-n.top-n.bottom;h.forEach(O=>{r&&m.length>0&&(l?v+i+O.h>C:y+i+O.w>b)?(p.push({children:m,width:y,height:v}),m=[O],y=O.w,v=O.h):(m.push(O),l?(y=Math.max(y,O.w),v+=(m.length>1?i:0)+O.h):(y+=(m.length>1?i:0)+O.w,v=Math.max(v,O.h)))}),m.length>0&&p.push({children:m,width:y,height:v}),f&&!l&&(c=Math.max(...p.map(O=>O.width),0)+n.left+n.right),d&&l&&(g=Math.max(...p.map(O=>O.height),0)+n.top+n.bottom);const S=[];let w=n.left,I=n.top;const M=a.toLowerCase(),P=M==="center"||M.endsWith("-center"),T=M.endsWith("-right"),$=M==="center"||M.startsWith("center-"),k=M.startsWith("bottom-");return p.forEach(O=>{let A=w,W=I;l?$?W=n.top+(g-n.top-n.bottom-O.height)/2:k&&(W=g-n.bottom-O.height):P?A=n.left+(c-n.left-n.right-O.width)/2:T&&(A=c-n.right-O.width),O.children.forEach(x=>{var L,U;let B=A,N=W;l?P?B+=(O.width-x.w)/2:T&&(B+=O.width-x.w):$?N+=(O.height-x.h)/2:k&&(N+=O.height-x.h);const Q=((L=x.original.layoutProps)==null?void 0:L.width)==="fill",_=((U=x.original.layoutProps)==null?void 0:U.height)==="fill";S.push({id:x.id,x:B+x.w/2-c/2,y:N+x.h/2-g/2,width:Q&&l?O.width:void 0,height:_?l?void 0:O.height:void 0}),l?W+=x.h+i:A+=x.w+i}),l?w+=O.width+i:I+=O.height+i}),{frameWidth:f?c:void 0,frameHeight:d?g:void 0,childUpdates:S}}function Ts(u,t,s){const o=u.autoLayout;if(!o)return{childUpdates:[]};const{gridColumns:e,gridRows:i,columnGap:n=0,rowGap:a=0,padding:r,align:l}=o;let h=u.width,c=u.height;const g=h-r.left-r.right,f=c-r.top-r.bottom,d=ze(e||"1fr",g,n),p=ze(i||"auto",f,a),m=d.length>0?d.reduce((T,$)=>T+$,0)+(d.length-1)*n:0,y=p.length>0?p.reduce((T,$)=>T+$,0)+(p.length-1)*a:0,v=l.toLowerCase(),b=v==="center"||v.endsWith("-center"),C=v.endsWith("-right"),S=v==="center"||v.startsWith("center-"),w=v.startsWith("bottom-");let I=0,M=0;b?I=(g-m)/2:C&&(I=g-m),S?M=(f-y)/2:w&&(M=f-y);const P=[];return t.forEach((T,$)=>{var U,q;const k=$%d.length||0,E=Math.floor($/d.length)||0;E>=p.length&&p.push(100);const F=d[k],O=p[E];let A=r.left+I+d.slice(0,k).reduce((et,ft)=>et+ft+n,0),W=r.top+M+p.slice(0,E).reduce((et,ft)=>et+ft+a,0);const x=s(T.id),B=T.geometry;let N=(x==null?void 0:x.width)??B.width??100,Q=(x==null?void 0:x.height)??B.height??100;if(B.type==="Ellipse"||B.type==="Polygon"||B.type==="Star"){const et=(x==null?void 0:x.radius)??B.radius??(x==null?void 0:x.outer_radius)??B.outer_radius??50;N=et*2,Q=et*2}N*=T.transform.scale_x||1,Q*=T.transform.scale_y||1;let _=A,L=W;b?_+=(F-N)/2:C&&(_+=F-N),S?L+=(O-Q)/2:w&&(L+=O-Q),P.push({id:T.id,x:_+N/2-h/2,y:L+Q/2-c/2,width:((U=T.layoutProps)==null?void 0:U.width)==="fill"?F:void 0,height:((q=T.layoutProps)==null?void 0:q.height)==="fill"?O:void 0})}),{childUpdates:P}}class Ne{constructor(){K(this,"world",null);K(this,"bodies",new Map);K(this,"colliders",new Map);K(this,"joints",new Map);K(this,"initialized",!1);K(this,"bodyIdByCollider",new Map);K(this,"onCollisionCB",null);K(this,"eventQueue",null)}setCollisionCallback(t){this.onCollisionCB=t}async init(t){this.initialized||(await ne.init(),this.world=new ne.World(new ne.Vector2(t.x*100,t.y*100)),this.eventQueue=new ne.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 ne.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?ne.RigidBodyDesc.fixed():ne.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=ne.ColliderDesc.cuboid(t.width/2,t.height/2);break;case"Ellipse":e=ne.ColliderDesc.ball(Math.max(t.width,t.height)/2);break;case"Triangle":case"Star":case"Polygon":e=ne.ColliderDesc.cuboid(t.width/2,t.height/2);break;default:e=ne.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 ne.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 ne.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 ne.Vector2(s,o),!0)}applyImpulse(t,s,o){const e=this.bodies.get(t);e&&e.applyImpulse(new ne.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 ne.Vector2(t.anchorA.x,t.anchorA.y),i=new ne.Vector2(t.anchorB.x,t.anchorB.y);let n;if(t.type==="Distance"){const a=t.length??100,r=t.stiffness??100,l=t.damping??10;n=ne.JointData.spring(a,r,l,e,i)}else n=ne.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 He=u=>u,_s=u=>u>0?1:0,Ps=u=>u<1?0:1,Ue=u=>u*u,qe=u=>u*(2-u),Je=u=>u<.5?2*u*u:-1+(4-2*u)*u,Es=u=>u*u*u,xs=u=>--u*u*u+1,Os=u=>u<.5?4*u*u*u:(u-1)*(2*u-2)*(2*u-2)+1,As=u=>u*u*u*u,Ls=u=>1- --u*u*u*u,Fs=u=>u<.5?8*u*u*u*u:1-8*--u*u*u*u,Rs=u=>u*u*u*u*u,$s=u=>1+--u*u*u*u*u,Ws=u=>u<.5?16*u*u*u*u*u:1+16*--u*u*u*u*u,Bs=u=>1-Math.cos(u*Math.PI/2),Ys=u=>Math.sin(u*Math.PI/2),Xs=u=>-(Math.cos(Math.PI*u)-1)/2,Gs=u=>u===0?0:Math.pow(2,10*(u-1)),Ds=u=>u===1?1:1-Math.pow(2,-10*u),zs=u=>u===0?0:u===1?1:u<.5?Math.pow(2,20*u-10)/2:(2-Math.pow(2,-20*u+10))/2,Vs=u=>1-Math.sqrt(1-u*u),Ns=u=>Math.sqrt(1- --u*u),Hs=u=>u<.5?(1-Math.sqrt(1-4*u*u))/2:(Math.sqrt(1-(-2*u+2)*(-2*u+2))+1)/2,Oe=1.70158,Ae=Oe*1.525,Qe=Oe+1,Us=u=>Qe*u*u*u-Oe*u*u,qs=u=>1+Qe*Math.pow(u-1,3)+Oe*Math.pow(u-1,2),Js=u=>u<.5?Math.pow(2*u,2)*((Ae+1)*2*u-Ae)/2:(Math.pow(2*u-2,2)*((Ae+1)*(u*2-2)+Ae)+2)/2,Ke=2*Math.PI/3,Ze=2*Math.PI/4.5,Qs=u=>u===0?0:u===1?1:-Math.pow(2,10*u-10)*Math.sin((u*10-10.75)*Ke),Ks=u=>u===0?0:u===1?1:Math.pow(2,-10*u)*Math.sin((u*10-.75)*Ke)+1,Zs=u=>u===0?0:u===1?1:u<.5?-(Math.pow(2,20*u-10)*Math.sin((20*u-11.125)*Ze))/2:Math.pow(2,-20*u+10)*Math.sin((20*u-11.125)*Ze)/2+1,Le=u=>u<1/2.75?7.5625*u*u:u<2/2.75?7.5625*(u-=1.5/2.75)*u+.75:u<2.5/2.75?7.5625*(u-=2.25/2.75)*u+.9375:7.5625*(u-=2.625/2.75)*u+.984375,js=u=>1-Le(1-u),ti=Le,ei=u=>u<.5?(1-Le(1-2*u))/2:(1+Le(2*u-1))/2,Xe=new Map,Te=(u,t,s,o)=>{const e=`${u},${t},${s},${o}`;if(Xe.has(e))return Xe.get(e);const i=h=>(1-3*s+3*u)*h*h*h+(3*s-6*u)*h*h+3*u*h,n=h=>(1-3*o+3*t)*h*h*h+(3*o-6*t)*h*h+3*t*h,a=h=>3*(1-3*s+3*u)*h*h+2*(3*s-6*u)*h+3*u,r=h=>{let c=h;for(let g=0;g<8;g++){const f=i(c)-h;if(Math.abs(f)<1e-6)return c;const d=a(c);if(Math.abs(d)<1e-6)break;c=c-f/d}return c},l=h=>h===0?0:h===1?1:n(r(h));return Xe.set(e,l),l},je=u=>{const t=u.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 Te(s,o,e,i)},ts={ease:Te(.25,.1,.25,1),"ease-in":Te(.42,0,1,1),"ease-out":Te(0,0,.58,1),"ease-in-out":Te(.42,0,.58,1)},Fe={Linear:He,EaseInQuad:Ue,EaseOutQuad:qe,EaseInOutQuad:Je,EaseInCubic:Es,EaseOutCubic:xs,EaseInOutCubic:Os,EaseInQuart:As,EaseOutQuart:Ls,EaseInOutQuart:Fs,EaseInQuint:Rs,EaseOutQuint:$s,EaseInOutQuint:Ws,EaseInSine:Bs,EaseOutSine:Ys,EaseInOutSine:Xs,EaseInExpo:Gs,EaseOutExpo:Ds,EaseInOutExpo:zs,EaseInCirc:Vs,EaseOutCirc:Ns,EaseInOutCirc:Hs,EaseInBack:Us,EaseOutBack:qs,EaseInOutBack:Js,EaseInElastic:Qs,EaseOutElastic:Ks,EaseInOutElastic:Zs,EaseInBounce:js,EaseOutBounce:ti,EaseInOutBounce:ei,EaseIn:Ue,EaseOut:qe,EaseInOut:Je,StepStart:_s,StepEnd:Ps},si=u=>{const t=u.trim(),s=t.toLowerCase();if(Fe[t])return Fe[t];const o=Object.keys(Fe).find(i=>i.toLowerCase()===s);if(o)return Fe[o];const e=Object.keys(es).find(i=>i.toLowerCase()===s);if(e){const i=je(es[e].value);if(i)return i}if(ts[s])return ts[s];if(s.startsWith("cubic-bezier")){const i=je(t);if(i)return i}return He},es={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=(u,t,s,o,e)=>{if(!u||!t||!s)return u;const i=o.scale_x??1,n=o.scale_y??1,a=(r,l,h)=>{let c=0,g=0;const f=o.rotation*Math.PI/180,d=Math.cos(f),p=Math.sin(f),m=r*i*d-l*n*p+o.x,y=r*i*p+l*n*d+o.y;h.forEach(M=>{const P=e(M.boneId);if(!P)return;const T={x:P.x,y:P.y,rotation:P.rotation,scaleX:P.scale_x??1,scaleY:P.scale_y??1},$=s[M.boneId]||[1,0,0,1,0,0],k=m*$[0]+y*$[2]+$[4],E=m*$[1]+y*$[3]+$[5],F=T.rotation*Math.PI/180,O=Math.cos(F),A=Math.sin(F),W=k*T.scaleX*O-E*T.scaleY*A+T.x,x=k*T.scaleX*A+E*T.scaleY*O+T.y;c+=W*M.amount,g+=x*M.amount});const v=[...h].sort((M,P)=>P.amount-M.amount);if(v.length>=2&&v[0].amount>0&&v[1].amount>0){const M=e(v[0].boneId),P=e(v[1].boneId);if(M&&P&&M.length!==void 0&&P.length!==void 0){const T=M.length*(M.scale_y??1),$=M.rotation*Math.PI/180,k=M.x-T*Math.sin($),E=M.y+T*Math.cos($),F=P.length*(P.scale_y??1),O=P.rotation*Math.PI/180,A=P.x-F*Math.sin(O),W=P.y+F*Math.cos(O);let x=null,B=null,N=!1;const Q=1;if(Math.hypot(M.x-P.x,M.y-P.y)<Q||Math.hypot(M.x-A,M.y-W)<Q?(x=M.x,B=M.y):(Math.hypot(k-P.x,E-P.y)<Q||Math.hypot(k-A,E-W)<Q)&&(x=k,B=E,N=!0),x!==null&&B!==null){const _=s[v[0].boneId]||[1,0,0,1,0,0],L=_[0]*_[3]-_[1]*_[2];let U=0,q=0;if(L!==0){const et=(_[2]*_[5]-_[3]*_[4])/L,ft=(_[1]*_[4]-_[0]*_[5])/L,vt=Math.atan2(-_[1],_[3]);if(!N)U=et,q=ft;else{const ot=-_[2]/L,Et=_[0]/L,Ft=Math.hypot(ot,Et),Mt=M.length*Ft;U=et-Mt*Math.sin(vt),q=ft+Mt*Math.cos(vt)}const lt=Math.hypot(m-U,y-q),ut=Math.hypot(c-x,g-B);if(ut>0&<>0){const ot=Math.max(ut,.01),Et=Math.min(lt/ot,3),Ft=x+(c-x)*Et,Mt=B+(g-B)*Et,Dt=v[0].amount,Yt=v[1].amount,Rt=Math.min(Dt,Yt)*2,ee=1-Math.pow(1-Rt,4);c=c*(1-ee)+Ft*ee,g=g*(1-ee)+Mt*ee}}}}}const b=o.rotation*Math.PI/180,C=Math.cos(b),S=Math.sin(b),w=c-o.x,I=g-o.y;return{x:(w*C+I*S)/i,y:(-w*S+I*C)/n}};return u.map((r,l)=>{const h=t[l];if(!h||h.length===0)return{...r};const c={...r,...a(r.x,r.y,h)};if(r.in_x!==void 0&&r.in_y!==void 0){const g=a(r.in_x,r.in_y,h);c.in_x=g.x,c.in_y=g.y}if(r.out_x!==void 0&&r.out_y!==void 0){const g=a(r.out_x,r.out_y,h);c.out_x=g.x,c.out_y=g.y}return c})},ss={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}},is={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 ns{constructor(){K(this,"artboard",null);K(this,"objectStates",new Map);K(this,"physicsEngine",null);K(this,"activeStateMachine",null);K(this,"inputs",new Map);K(this,"inputNameMap",new Map);K(this,"layerStates",new Map);K(this,"pretextCache",new Map);K(this,"pointerHistory",[]);K(this,"MAX_HISTORY",200);K(this,"imageCache",new Map);K(this,"lastValidSvgImgMap",new Map);K(this,"maskBuffer",null);K(this,"maskCtx",null);K(this,"lumaBuffer",null);K(this,"lumaCtx",null);K(this,"_noiseTileCanvas",null);K(this,"layout",{fit:"Contain",alignment:"Center"});K(this,"onTrigger");K(this,"onInputUpdate");K(this,"onComponentChange");K(this,"onToggle");K(this,"onInputChange");K(this,"onInputFocus");K(this,"onInputBlur");K(this,"onLog");K(this,"onButtonClick");K(this,"onGraphPointClick");K(this,"justFiredTriggers",new Set);K(this,"rootTransform",null);K(this,"canvasWidth",0);K(this,"canvasHeight",0);K(this,"lastHoveredObjectId",null);K(this,"_lastPointerPos",null);K(this,"_prevPointerPos",null);K(this,"focusedId",null);K(this,"draggingSliderId",null);K(this,"activeDropdownId",null);K(this,"activeObjectId",null);K(this,"draggingListViewId",null);K(this,"scrollOffset",{x:0,y:0});K(this,"_totalScroll",{x:0,y:0});K(this,"draggingBehaviors",new Set);K(this,"isMouseDown",!1);K(this,"_layoutAnimCache",new Map);K(this,"_springChainState",new Map);K(this,"_emitterPools",new Map);K(this,"objectVelocities",new Map);K(this,"currentTime",0);K(this,"frameCount",0);K(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});K(this,"onLogicUpdate");K(this,"logicNodeValues",new Map);K(this,"logicNodeState",new Map);K(this,"pointerDownTimes",new Map);K(this,"activeHoverIds",new Set);K(this,"onNavigation");K(this,"periodicTriggerTimes",new Map);K(this,"wasInView",new Set);K(this,"scrollProgressLastValue",new Map);K(this,"debug_objectsRendered",0);K(this,"debug_objectsTotal",0);K(this,"lastRenderTime",0);K(this,"debugMode",!1);K(this,"activeTriggers",new Map);console.info("%c[ExodeUI Engine] Pixel-Perfect Parity Active (v6.3.10) - SVG Fill & Gradient Parity Active","color: #3b82f6; font-weight: bold; padding: 2px 4px; border-radius: 4px; background: rgba(59, 130, 246, 0.1)")}setTriggerCallback(t){this.onTrigger=t}setInputUpdateCallback(t){this.onInputUpdate=t}setComponentChangeCallback(t){this.onComponentChange=t}setToggleCallback(t){this.onToggle=t}setLogicUpdateCallback(t){this.onLogicUpdate=t}setInputChangeCallback(t){this.onInputChange=t}setButtonClickCallback(t){this.onButtonClick=t}setGraphPointClickCallback(t){this.onGraphPointClick=t}setNavigationCallback(t){this.onNavigation=t}ensurePathPoints(t){if(!t||t.type!=="Path"&&t.type!=="Subtract"&&t.type!=="Union"&&t.type!=="Intersect"&&t.type!=="Exclude"&&t.type!=="BooleanOperation")return;if(t.points&&t.points.length>0){if(t.is_closed===void 0&&t.isClosed===void 0&&t.data){const{isClosed:e}=this.svgPathToPoints(t.data);t.is_closed=e}return}if(!t.data)return;const{points: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,l=0,h=0,c=0,g;for(;(g=s.exec(t))!==null;){const f=g[1],d=(g[2].match(o)||[]).map(parseFloat),p=f===f.toLowerCase(),m=f.toUpperCase();let y=0;const v=C=>{let S=d[y++];return p&&(S+=C?n:a),S},b=()=>({x:v(!0),y:v(!1)});switch(m){case"M":{const C=b();for(h=n=C.x,c=a=C.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a,moveTo:!0});y<d.length;){const S=b();n=S.x,a=S.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}case"L":for(;y<d.length;){const C=b();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"H":for(;y<d.length;)n=v(!0),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"V":for(;y<d.length;)a=v(!1),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"C":for(;y<d.length;){const C=b(),S=b(),w=b();if(e.length>0){const I=e[e.length-1];I.out_x=C.x,I.out_y=C.y}n=w.x,a=w.y,e.push({x:n,y:a,in_x:S.x,in_y:S.y,out_x:n,out_y:a}),r=S.x,l=S.y}break;case"S":for(;y<d.length;){const C={x:2*n-r,y:2*a-l},S=b(),w=b();if(e.length>0){const I=e[e.length-1];I.out_x=C.x,I.out_y=C.y}n=w.x,a=w.y,e.push({x:n,y:a,in_x:S.x,in_y:S.y,out_x:n,out_y:a}),r=S.x,l=S.y}break;case"Q":for(;y<d.length;){const C=b(),S=b();if(e.length>0){const w=e[e.length-1];w.out_x=w.x+2/3*(C.x-w.x),w.out_y=w.y+2/3*(C.y-w.y)}n=S.x,a=S.y,e.push({x:n,y:a,in_x:n+2/3*(C.x-n),in_y:a+2/3*(C.y-a),out_x:n,out_y:a}),r=C.x,l=C.y}break;case"T":for(;y<d.length;){const C={x:2*n-r,y:2*a-l},S=b();if(e.length>0){const w=e[e.length-1];w.out_x=w.x+2/3*(C.x-w.x),w.out_y=w.y+2/3*(C.y-w.y)}n=S.x,a=S.y,e.push({x:n,y:a,in_x:n+2/3*(C.x-n),in_y:a+2/3*(C.y-a),out_x:n,out_y:a}),r=C.x,l=C.y}break;case"Z":if(i=!0,e.length>0){const C=e[e.length-1];C.closePath=!0;const S=[...e].reverse().find(w=>w.moveTo)||e[0];S&&Math.hypot(S.x-C.x,S.y-C.y)<.1&&(S.in_x=C.in_x,S.in_y=C.in_y,e.pop(),e.length>0&&(e[e.length-1].closePath=!0))}n=h,a=c;break;default:if(d.length>=2){const C=b();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}}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))}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(l=>{if(e.has(l.id))return;const h={...l},c=h.childrenObjects||[];e.add(h.id),o.push(h),i(c)})};if(i(s.objects||[]),o.length>(s.objects||[]).length&&console.log(`[Engine] Flattened artboard from ${(s.objects||[]).length} to ${o.length} objects.`),s.objects=o,this.artboard=s,this.currentTime=0,this.objectStates.clear(),console.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(l=>{r.set(l.id,l),l.children||(l.children=[])}),this.artboard.objects.forEach(l=>{if(l.parentId){const h=r.get(l.parentId);h&&(h.children||(h.children=[]),h.children.includes(l.id)||h.children.push(l.id))}})}this.loadFonts(),this.preloadImages(this.artboard),this.reset(),this.advance(0)}preloadImages(t){if(!t||!t.objects)return;const s=o=>{if(!o||this.imageCache.has(o))return;const e=new Image;e.onload=()=>{console.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=Cs.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,l,h,c,g;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)??((l=s.geometry)==null?void 0:l.cornerRadius)??0;this.objectStates.set(s.id,{...s.transform||{},x:((h=s.transform)==null?void 0:h.x)??s.x??0,y:((c=s.transform)==null?void 0:c.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:((g=s.transform)==null?void 0:g.opacity)!==void 0?s.transform.opacity:s.opacity!==void 0?s.opacity:100,visible:s.visible!==void 0?s.visible:s.isVisible!==void 0?s.isVisible:!0,blendMode:s.blendMode||"Normal",style:JSON.parse(JSON.stringify(s.style||{})),geometry:JSON.parse(JSON.stringify(s.geometry||{})),options:s.options?JSON.parse(JSON.stringify(s.options)):{},masks:s.masks?JSON.parse(JSON.stringify(s.masks)):[],zIndex:s.zIndex!==void 0?s.zIndex:void 0})}),this.artboard.objects.some(s=>{var o;return(o=s.physics)==null?void 0:o.enabled})){this.physicsEngine=new Ne;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,l=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:l,rotation:a.rotation*(Math.PI/180),isStatic:e.physics.bodyType==="Static",mass:e.physics.mass,friction:e.physics.friction,restitution:e.physics.restitution,frictionAir:e.physics.frictionAir,density:e.physics.density,isSensor:e.physics.isSensor})}}))})}this.artboard.stateVariables&&this.artboard.stateVariables.forEach(s=>{this.inputs.set(s.id,s.value);const o=this.inputNameMap.get(s.name)||[];o.includes(s.id)||o.push(s.id),this.inputNameMap.set(s.name,o)}),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 l=Math.abs(r.x-a.x),h=Math.abs(r.y-a.y);!t&&(l>20||h>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=Ve(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(c=>s.get(c)).filter(c=>!!c),l=this.objectStates.get(n.id);if(!l)return;const h=Ve(l,r,c=>this.objectStates.get(c));h.frameWidth!==void 0&&(l.width=h.frameWidth),h.frameHeight!==void 0&&(l.height=h.frameHeight),e(h.childUpdates)}})}loadFonts(){if(!this.artboard)return;const t=new Set;if(this.artboard.objects.forEach(n=>{n.geometry&&n.geometry.type==="Text"&&n.geometry.fontFamily&&t.add(n.geometry.fontFamily)}),this.artboard.animations.forEach(n=>{n.tracks.forEach(a=>{(a.property==="geometry.fontFamily"||a.property==="fontFamily")&&a.keyframes.forEach(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 l=a.states.find(h=>h.id===r);if(l){let h=null;l.animationId&&(h=this.artboard.animations.find(c=>c.id===l.animationId)||null),h||(h=this.artboard.animations.find(c=>{var g,f;return c.name===l.name||c.id===l.name||(l.name==="Entry"||l.id==="entry")&&(((g=c.name)==null?void 0:g.toLowerCase())==="onload"||((f=c.name)==null?void 0:f.toLowerCase())==="intro")})||null),h&&((n=this.artboard.animationFlow)!=null&&n.some(g=>(g.trigger==="on_load"||g.trigger==="after_delay")&&g.targetAnimationId===(h==null?void 0:h.id))||(e.push({animation:h,state:l}),i=Math.max(i,h.duration)))}}}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(".")){const i=s.split(".");let n=e;for(let a=0;a<i.length-1;a++)n[i[a]]||(n[i[a]]={}),n=n[i[a]];n[i[i.length-1]]=o}else e[s]=o}updateInput(t,s){var n,a,r;let o;if(this.inputs.has(t)){const l=(n=this.activeStateMachine)==null?void 0:n.inputs.find(h=>h.id===t);l&&typeof l.value=="object"&&(o=l.value.type)}else{const l=this.inputNameMap.get(t);if(l&&l.length>0){const h=(a=this.activeStateMachine)==null?void 0:a.inputs.find(c=>c.id===l[0]);h&&typeof h.value=="object"&&(o=h.value.type)}}let e=s;o==="Trigger"&&(s===1?e=!0:s===0&&(e=!1)),this.inputs.has(t)&&this.setInternalInput(t,e);const i=this.inputNameMap.get(t);i&&i.forEach(l=>this.setInternalInput(l,e)),o==="Trigger"&&e===!0&&(this.justFiredTriggers.add(t),i&&i.forEach(l=>this.justFiredTriggers.add(l))),Array.isArray(e)&&((r=this.artboard)==null||r.objects.forEach(l=>{if(l.inputId===t||l.name===t){const h=this.objectStates.get(l.id);h&&h.options&&(l.type==="ListView"||l.variant==="listview"?h.options.items=e:(l.type==="Dropdown"||l.variant==="dropdown")&&(h.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 l=!1;switch(a){case"Equal":case"==":l=s==r;break;case"NotEqual":case"!=":l=s!=r;break;case"GreaterThan":case">":l=s>r;break;case"LessThan":case"<":l=s<r;break;case"GreaterEqual":case">=":l=s>=r;break;case"LessEqual":case"<=":l=s<=r;break;case"IsTrue":l=!!s;break;case"IsFalse":l=!s;break}if(l){const h=i.delay||0;h<=0?this.triggerGlobalAnimation(i.targetAnimationId,i.subAnimationIds,i.loop,i.id):setTimeout(()=>this.triggerGlobalAnimation(i.targetAnimationId,i.subAnimationIds,i.loop,i.id),h)}}})}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(l=>l.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,i=s.value,n=this.evaluateLogicTree(o);if(n===void 0)return console.log(`[Engine] Condition Check Failed: Input ${o} is undefined`),!1;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,l,h,c,g;if(o.has(t))return this.inputs.get(t)??this.logicNodeValues.get(t)??0;o.add(t);const e=(r=(a=this.activeStateMachine)==null?void 0:a.logicNodes)==null?void 0:r.find(f=>f.id===t);if(e){const f=(p,m)=>{const y=e.inputs.find(v=>v.id===p);return y?y.sourceId?this.evaluateLogicTree(y.sourceId,y.sourceHandleId,o):y.value!==void 0?y.value:m:m};let d=0;switch(e.op){case bt.AND:d=f("a",!1)&&f("b",!1);break;case bt.OR:d=f("a",!1)||f("b",!1);break;case bt.NOT:d=!f("in",!1);break;case bt.XOR:d=!!f("a",!1)!=!!f("b",!1);break;case bt.OBJECT:d=e.name;break;case bt.PROPERTY:case bt.GET_PROPERTY:{const p=f("id","");if(!p){d=0;break}const m=e.name;if(!m||m==="GET_PROPERTY"||m==="PROPERTY"){d=0;break}const y=this.objectStates.get(p);if(!y){d=0;break}m in y?d=y[m]:d=this.resolvePath(y,m);break}case bt.SET_PROPERTY:{const p=f("id",""),m=f("value",void 0);if(!p||m===void 0){d=0;break}const y=e.name;if(!y||y==="SET_PROPERTY"){d=0;break}const v=this.objectStates.get(p);if(!v){d=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(y))v[y]=m,d=m;else{const C=y.split(".");let S=v;for(let I=0;I<C.length-1;I++){const M=C[I];S[M]===void 0&&(S[M]={}),S=S[M]}const w=C[C.length-1];S[w]=m,d=m}break}case bt.ADD:d=f("a",0)+f("b",0);break;case bt.SUB:d=f("a",0)-f("b",0);break;case bt.MUL:d=f("a",0)*f("b",0);break;case bt.DIV:{const p=f("b",1);d=p===0?0:f("a",0)/p;break}case bt.MOD:d=f("a",0)%f("b",1);break;case bt.POW:d=Math.pow(f("a",0),f("b",1));break;case bt.ABS:d=Math.abs(f("in",0));break;case bt.ROUND:d=Math.round(f("in",0));break;case bt.FLOOR:d=Math.floor(f("in",0));break;case bt.CEIL:d=Math.ceil(f("in",0));break;case bt.SIN:d=Math.sin(f("in",0));break;case bt.COS:d=Math.cos(f("in",0));break;case bt.TAN:d=Math.tan(f("in",0));break;case bt.CLAMP:{const p=f("in",0),m=f("min",0),y=f("max",1);d=Math.max(m,Math.min(y,p));break}case bt.REMAP:{const p=f("in",0),m=f("inMin",0),y=f("inMax",100),v=f("outMin",0),b=f("outMax",1);d=y===m?v:v+(p-m)*(b-v)/(y-m);break}case bt.EQ:d=f("a",0)==f("b",0);break;case bt.NEQ:d=f("a",0)!=f("b",0);break;case bt.GT:d=f("a",0)>f("b",0);break;case bt.LT:d=f("a",0)<f("b",0);break;case bt.GTE:d=f("a",0)>=f("b",0);break;case bt.LTE:d=f("a",0)<=f("b",0);break;case bt.IF_ELSE:d=f("cond",!1)?f("then",0):f("else",0);break;case bt.VALUE:d=e.value!==void 0?e.value:0;break;case bt.INPUT:d=this.inputs.get(e.name)??0;break;case bt.LOG:{const p=f("in","");this.debugLog(`[User Logic] ${p}`),d=p;break}case bt.SCROLL_X:d=this.inputs.get("scrollX")??0;break;case bt.SCROLL_Y:d=this.inputs.get("scrollY")??0;break;case bt.MOUSE_X:d=this.inputs.get("mouseX")??0;break;case bt.MOUSE_Y:d=this.inputs.get("mouseY")??0;break;case bt.IS_MOUSE_DOWN:d=this.inputs.get("isMouseDown")??!1;break;case bt.EFFECTOR:{const p=f("id",""),m=f("intensity",1),y=f("trigger",!0);if(!p||!y){d=0;break}const v=e.name;if(!v){d=0;break}const b=this.objectStates.get(p);if(!b){d=0;break}if(["glitch","halftone","pixelate","noise","acid_gradient","acid_rave","shimmer"].includes(v))b.style||(b.style={}),b.style.artEffect={enabled:!0,type:v,intensity:m},d=1;else{b.behaviors||(b.behaviors=[]);let S=b.behaviors.find(w=>w.type===v);S?(S.enabled=!0,S.settings||(S.settings={}),S.settings.intensity=m):(S={id:`eff_${Date.now()}_${v}`,type:v,enabled:!0,sensors:[],settings:{intensity:m}},b.behaviors.push(S)),d=1}break}case bt.MONITOR:{d=f("in",0);break}case bt.SPRING_PULL:{const p=f("objectId",""),m=f("forceX",0),y=f("forceY",0);p&&((l=this.artboard)==null||l.objects.forEach(v=>{v.behaviors&&v.behaviors.forEach(b=>{var C;if(b.type===X.SpringChain&&((C=b.settings)!=null&&C.connections)&&(b.settings.connections.some(w=>w.targetId===p)||v.id===p)){this._springChainState.has(v.id)||this._springChainState.set(v.id,new Map);const w=this._springChainState.get(v.id);if(!w.has(p)){const M=this.objectStates.get(p);w.set(p,{x:(M==null?void 0:M.x)??0,y:(M==null?void 0:M.y)??0,vx:0,vy:0})}const I=w.get(p);I&&(I.vx+=m,I.vy+=y)}})})),d=1;break}case bt.SPRING_SETTLE:{const p=f("objectId","");let m=!0;if(p){const y=f("threshold",1);this._springChainState.forEach(v=>{const b=v.get(p);b&&(Math.abs(b.vx)>y||Math.abs(b.vy)>y)&&(m=!1)})}d=m;break}case bt.EMIT:{const p=f("objectId",""),m=f("count",20);p&&((h=this.artboard)==null||h.objects.forEach(y=>{y.behaviors&&y.behaviors.forEach(v=>{v.type===X.ParticleEmitter&&y.id===p&&(v._pendingBurst=(v._pendingBurst||0)+m)})})),d=1;break}default:d=0;break}if(this.logicNodeValues.set(t,d),e.op===bt.DELAY){const p=f("delay",0),m=f("in",0);let y=this.logicNodeState.get(t);for(y||(y={queue:[]},this.logicNodeState.set(t,y)),y.queue.push({time:this.currentTime+p,value:m});y.queue.length>0&&y.queue[0].time<=this.currentTime;)y.lastValue=y.queue.shift().value;d=y.lastValue??0}return d}const i=(c=this.activeStateMachine)==null?void 0:c.inputs.find(f=>f.id===t||f.name===t);if(i&&i.sourceId&&!o.has(i.sourceId)){const f=this.evaluateLogicTree(i.sourceId,i.sourceHandleId,o);return this.inputs.set(i.id,f),f}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 f=(g=this.activeStateMachine)==null?void 0:g.inputs.find(d=>d.id===t);if(f&&f.value.type==="Number"&&typeof n=="number"){const d=f.value.defaultValue??f.value.value;if(s==="source-greater")return n>d;if(s==="source-less")return n<d;if(s==="source-equal")return n===d}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===bt.SET_PROPERTY||t.op===bt.EFFECTOR)&&this.evaluateLogicTree(t.id)})}resolvePath(t,s){const o=s.split(".");let e=t;for(const i of o)if(e&&typeof e=="object"&&i in e)e=e[i];else return;return e}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&&(console.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.onLogicUpdate&&this.logicNodeValues.size>0&&this.onLogicUpdate(Object.fromEntries(this.logicNodeValues)));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&&(o.currentStateIds.length>0&&this.handleAnimationFinished(o.currentStateIds[0],o.ruleId),e.startsWith("global_")&&s.push(e))}o.animations.forEach(i=>{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,l,h,c;if(o.phase==="entry")o.time+=t,o.time>=o.animation.duration&&((a=(n=(i=this.artboard)==null?void 0:i.objects.find(g=>g.id===e))==null?void 0:n.triggers)==null||a.find(g=>g.id===o.triggerId),o.phase="hold",o.elapsedHold=0,o.time=o.animation.duration),this.applyAnimation(o.animation,o.time,o.filterObjectIds||o.filterObjectId||void 0);else if(o.phase==="hold"){const g=(h=(l=(r=this.artboard)==null?void 0:r.objects.find(p=>p.id===e))==null?void 0:l.triggers)==null?void 0:h.find(p=>p.id===o.triggerId),f=(g==null?void 0:g.duration)||0;o.elapsedHold+=t*1e3;let d=o.elapsedHold>=f;if((g==null?void 0:g.eventType)==="hover"&&!this.activeHoverIds.has(e)&&(d=!0),((g==null?void 0:g.eventType)==="onHold"||(g==null?void 0:g.eventType)==="pointerDown")&&!this.isMouseDown&&(d=!0),d)if(g!=null&&g.exitAnimationId){const p=(c=this.artboard)==null?void 0:c.animations.find(m=>m.id===g.exitAnimationId);p?(o.phase="exit",o.animation=p,o.time=0):this.activeTriggers.delete(e)}else this.activeTriggers.delete(e)}else o.phase==="exit"&&(o.time+=t,o.time>=o.animation.duration?this.activeTriggers.delete(e):this.applyAnimation(o.animation,o.time,o.filterObjectIds||o.filterObjectId||void 0))}),this.evaluateContinuousInteractions(t)}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),l=(((i=s.geometry)==null?void 0:i.width)||100)*(r.scale_x||1),h=(((n=s.geometry)==null?void 0:n.height)||100)*(r.scale_y||1),c=50,g=r.x+l/2>=-this.canvasWidth/2-c&&r.x-l/2<=this.canvasWidth/2+c&&r.y+h/2>=-this.canvasHeight/2-c&&r.y-h/2<=this.canvasHeight/2+c,f=`analytics_${s.id}`,d=this.wasInView.has(f);g&&!d&&this.fireAnalyticsEvent(s.id,"visible"),g?this.wasInView.add(f):this.wasInView.delete(f)}}}),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,l,h;const a=n.toLowerCase();if(a==="on interval"||a==="oninterval"){const c=e.intervalValue||2e3,g=this.periodicTriggerTimes.get(e.id)||0;this.currentTime*1e3-g>=c&&(!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 c=e.delayValue||1e3;!this.periodicTriggerTimes.has(e.id)&&this.currentTime*1e3>=c&&(!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 c=this.objectStates.get(s.id);if(c&&c.visible!==!1){const g=this.getGlobalTransform(s.id),f=(((r=s.geometry)==null?void 0:r.width)||100)*(g.scale_x||1),d=(((l=s.geometry)==null?void 0:l.height)||100)*(g.scale_y||1),p=50,m=g.x+f/2>=-this.canvasWidth/2-p&&g.x-f/2<=this.canvasWidth/2+p&&g.y+d/2>=-this.canvasHeight/2-p&&g.y-d/2<=this.canvasHeight/2+p,y=this.wasInView.has(s.id);m&&!y&&(!e.conditions||this.checkConditions(e.conditions))&&this.fireEventForObject(s.id,"Scroll Into View"),m?this.wasInView.add(s.id):this.wasInView.delete(s.id)}}if(a==="scroll progress"||a==="scrollprogress"){const c=Math.abs(this.scrollOffset.y)/(((h=this.artboard)==null?void 0:h.height)||1e3),g=this.scrollProgressLastValue.get(e.id)||0;Math.abs(c-g)>.001&&(this.scrollProgressLastValue.set(e.id,c),(e.action==="Set Input"||e.action==="setInput")&&this.updateInput(e.targetInputId,c))}})})}))}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 h,c,g,f,d,p,m,y,v;const a=((h=o.constraints)==null?void 0:h[n])||{},r={...i,...a},l=r.strength??1;if(r.type==="Translation"){const b=this.getGlobalTransform(r.targetId);if(b){const C=r.offsetX||0,S=r.offsetY||0,w=b.x+C,I=b.y+S,M=r.useSpring;if(M){const T=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:$,y:k,vx:E,vy:F}=this.computeSpring(e.x,e.y,T.vx,T.vy,w,I,r,t);r.copyX&&(e.x=e.x+($-e.x)*l),r.copyY&&(e.y=e.y+(k-e.y)*l),this.objectVelocities.set(s.id,{vx:E,vy:F})}else r.copyX&&(e.x=e.x+(w-e.x)*l),r.copyY&&(e.y=e.y+(I-e.y)*l);let P=!1;if((c=r.limitX)!=null&&c.enabled){const T=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==T&&(P=!0)}if((g=r.limitY)!=null&&g.enabled){const T=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==T&&(P=!0)}P&&M&&this.objectVelocities.set(s.id,{vx:0,vy:0})}}else if(r.type==="Rotation"){const b=this.getGlobalTransform(r.targetId);if(b){let S=(b.rotation+(r.offset||0)-e.rotation)%360;S>180&&(S-=360),S<-180&&(S+=360),e.rotation=e.rotation+S*l}}else if(r.type==="Scale"){const b=this.getGlobalTransform(r.targetId);b&&(r.copyX&&(e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*l),r.copyY&&(e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*l))}else if(r.type==="Transform"){const b=this.getGlobalTransform(r.targetId);if(b){e.x=e.x+(b.x-e.x)*l,e.y=e.y+(b.y-e.y)*l;let C=(b.rotation-e.rotation)%360;C>180&&(C-=360),C<-180&&(C+=360),e.rotation=e.rotation+C*l,e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*l,e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*l}}else if(r.type==="FollowPointer"){const b=((f=this._lastPointerPos)==null?void 0:f.x)??e.x,C=((d=this._lastPointerPos)==null?void 0:d.y)??e.y,S=r.useSpring;if(S){const I=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:M,y:P,vx:T,vy:$}=this.computeSpring(e.x,e.y,I.vx,I.vy,b,C,r,t);e.x=M,e.y=P,this.objectVelocities.set(s.id,{vx:T,vy:$})}else e.x=e.x+(b-e.x)*l,e.y=e.y+(C-e.y)*l;let w=!1;if((p=r.limitX)!=null&&p.enabled){const I=e.x;e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x)),e.x!==I&&(w=!0)}if((m=r.limitY)!=null&&m.enabled){const I=e.y;e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)),e.y!==I&&(w=!0)}w&&S&&this.objectVelocities.set(s.id,{vx:0,vy:0})}else if(r.type==="Distance"){const b=this.getGlobalTransform(r.targetId);if(b){const C=e.x-b.x,S=e.y-b.y,w=Math.sqrt(C*C+S*S),I=r.distance||0;let M=w;switch(r.mode){case"exact":M=I;break;case"minimum":M=Math.max(I,w);break;case"maximum":M=Math.min(I,w);break;case"clamped":M=Math.max(0,Math.min(I,w));break}if(w>0){const P=e.x===b.x&&e.y===b.y?1:M/w;e.x=e.x+(b.x+C*P-e.x)*l,e.y=e.y+(b.y+S*P-e.y)*l}}}else if(r.type==="FollowPath"){const b=(y=this.artboard)==null?void 0:y.objects.find(C=>C.id===r.targetId);if(b){const C=this.getGlobalTransform(b.id);if(C){let S=b.geometry;if(b.type==="Frame"||b.type==="Group"||!S||S.type!=="Path"&&S.type!=="Ellipse"&&S.type!=="Rectangle"){const L=(v=this.artboard)==null?void 0:v.objects.find(U=>U.parentId===b.id&&U.type==="Shape"&&U.geometry&&(U.geometry.type==="Path"||U.geometry.type==="Ellipse"||U.geometry.type==="Rectangle"));L&&(S=L.geometry)}if(!S)return;const w=(r.distance||0)/100,I=C.width||S.width||0,M=C.height||S.height||0,P=this.getPointOnPath(S,I,M,w),T=C.rotation*Math.PI/180,$=Math.cos(T),k=Math.sin(T),E=P.x*C.scale_x*$-P.y*C.scale_y*k,F=P.x*C.scale_x*k+P.y*C.scale_y*$;let O=C.rotation+(r.offsetRotation||0);if(r.orient){const L=Math.cos(P.angle),U=Math.sin(P.angle),q=L*C.scale_x*$-U*C.scale_y*k,et=L*C.scale_x*k+U*C.scale_y*$;O=Math.atan2(et,q)*180/Math.PI+(r.offsetRotation||0)}const A=O*Math.PI/180,W=Math.cos(A),x=Math.sin(A),B=(r.offsetX||0)*W-(r.offsetY||0)*x,N=(r.offsetX||0)*x+(r.offsetY||0)*W,Q=C.x+E+B,_=C.y+F+N;if(e.x=e.x+(Q-e.x)*l,e.y=e.y+(_-e.y)*l,r.orient){let L=(O-e.rotation)%360;L>180&&(L-=360),L<-180&&(L+=360),e.rotation=e.rotation+L*l}}}}else if(r.type==="IK"){const b=this.getGlobalTransform(r.targetId);b&&this.solveIK(s,b,r.boneCount||2,l)}}),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 c,g;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,rotation:0,scale_x:1,scale_y:1};const o=(c=this.artboard)==null?void 0:c.objects.find(f=>f.id===t),e=(o==null?void 0:o.type)==="Bone"?(g=o.geometry)==null?void 0:g.length:void 0;if(!o||!o.parentId)return{x:s.x,y:s.y,rotation:s.rotation,scale_x:(s.scale_x??1)*(s.flip_x?-1:1),scale_y:(s.scale_y??1)*(s.flip_y?-1:1),length:e};const i=this.getGlobalTransform(o.parentId),n=i.rotation*Math.PI/180,a=Math.cos(n),r=Math.sin(n),l=i.x+(s.x*i.scale_x*a-s.y*i.scale_y*r),h=i.y+(s.x*i.scale_x*r+s.y*i.scale_y*a);return{x:l,y:h,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),l=s.x-o.x,h=s.y-o.y,c=(l*a-h*r)*e,g=(l*r+h*a)*i;return{x:c,y:g,rotation:s.rotation-o.rotation,scale_x:s.scale_x/(o.scale_x||1),scale_y:s.scale_y/(o.scale_y||1)}}solveIK(t,s,o,e){var l;const i=[];let n=t.id;for(let h=0;h<o&&n;h++){const c=(l=this.artboard)==null?void 0:l.objects.find(g=>g.id===n);if(!c)break;i.push({id:n,local:this.objectStates.get(n),global:this.getGlobalTransform(n)}),n=c.parentId}if(i.length<2)return;const a=i.reverse(),r=5;for(let h=0;h<r;h++){const c=this.getGlobalTransform(t.id);for(let g=a.length-2;g>=0;g--){const f=a[g],d=this.getGlobalTransform(f.id),p=c.x-d.x,m=c.y-d.y,y=s.x-d.x,v=s.y-d.y,b=Math.sqrt(p*p+m*m),C=Math.sqrt(y*y+v*v);if(b>.001&&C>.001){const S=Math.atan2(m,p);let I=(Math.atan2(v,y)-S)*180/Math.PI;I*=e;const M=this.objectStates.get(f.id);M&&(M.rotation+=I)}}}}computeSpring(t,s,o,e,i,n,a,r){const l=a.stiffness??100,h=a.damping??10,c=a.mass??1,g=-l*(t-i),f=-l*(s-n),d=-h*o,p=-h*e,m=(g+d)/c,y=(f+p)/c,v=o+m*r,b=e+y*r,C=t+v*r,S=s+b*r;return{x:C,y:S,vx:v,vy:b}}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-this.artboard.width/2,r=(o-n.ty)/n.scaleY-this.artboard.height/2;this._prevPointerPos=this._lastPointerPos,this._lastPointerPos={x:a,y:r},this.updateInput("mouseX",a),this.updateInput("mouseY",r),this.handlePointerEvent(t,a,r)}handleScroll(t,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,l,h,c,g;if(!this.artboard)return;t==="down"?(this.isMouseDown=!0,this.updateInput("isMouseDown",!0)):(t==="up"||t==="blur")&&(this.isMouseDown=!1,this.updateInput("isMouseDown",!1));let e=null;const i=(f,d)=>{var C;let p=d;d==="click"?p="onClick":d==="down"?p="onPointerDown":d==="up"?p="onPointerUp":d==="blur"&&(p="onPointerLeave");const m=new Set([p]);d==="move"&&m.add("onPointerEnter").add("hover").add("onPointerLeave").add("blur"),p==="onClick"&&m.add("click"),p==="onPointerDown"&&m.add("pointerDown"),p==="onPointerUp"&&m.add("pointerUp");const y=["button","toggle","toggle_button","dropdown","listview","inputbox","slider","checkbox","radiogroup"];return!!(f.type==="Component"&&y.includes(f.variant)||y.includes((C=f.type)==null?void 0:C.toLowerCase())||(f.interactions||[]).some(S=>m.has(S.event))||(f.triggers||[]).some(S=>m.has(S.eventType)))};let n=null;for(let f=this.artboard.objects.length-1;f>=0;f--){const d=this.artboard.objects[f],p=this.objectStates.get(d.id);if(p&&p.visible!==!1&&p.opacity>0&&this.hitTest(d,s,o)&&(n||(n=d),i(d,t))){e=d;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 f=this.artboard.objects.find(d=>d.id===this.draggingSliderId);f&&this.updateSliderValueFromPointer(f,s,o);return}if(this.draggingListViewId){const f=this.artboard.objects.find(d=>d.id===this.draggingListViewId);f&&this.updateListViewScrollFromPointer(f);return}e&&e.type==="Component"&&e.variant==="listview"&&this.updateListViewHoverFromPointer(e,s,o),this.isMouseDown&&a&&this.fireEventForObject(a,"Drag"),a!==this.lastHoveredObjectId&&(console.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.draggingListViewId=null,this.draggingBehaviors.clear(),this.pointerDownTimes.delete(a),this.activeObjectId=null),t==="down"&&(this.pointerDownTimes.set(a,this.currentTime),this.activeObjectId=a,e&&((r=e.behaviors)!=null&&r.some(f=>f.type===X.Draggable))&&this.draggingBehaviors.add(a)),t==="move"?(a&&!this.activeHoverIds.has(a)&&this.activeHoverIds.add(a),this.activeHoverIds.forEach(f=>{f!==a&&this.activeHoverIds.delete(f)})):t==="blur"&&this.activeHoverIds.clear(),this.activeDropdownId&&t==="down"){const f=this.artboard.objects.find(d=>d.id===this.activeDropdownId);if(f&&(f.type==="Dropdown"||f.variant==="dropdown")){const d=this.objectStates.get(f.id),p=(d==null?void 0:d.options)||f.options||{},m=f.geometry||{},y=m.width??f.width??200,v=m.height??f.height??40,b=p.optionsList||[],C=p.itemHeight||32,S=p.listPadding??4,w=b.length*C+S*2,I=this.getWorldTransform(f.id),M=y*Math.abs(I.scaleX),P=v*Math.abs(I.scaleY),T=I.y+P/2+4,$=Math.abs(s-I.x)<=M/2,k=o>=T&&o<=T+w*Math.abs(I.scaleY);if($&&k){const E=Math.abs(I.scaleY),F=o-(T+S*E),O=Math.floor(F/(C*E));if(O>=0&&O<b.length){const A=b[O];p.selectedOption=A,p.isOpen=!1,this.activeDropdownId=null,f.inputId&&this.setInternalInput(f.inputId,A),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"dropdown",property:"selectedOption",value:A})}return}else a!==this.activeDropdownId&&(p.isOpen=!1,this.activeDropdownId=null)}}if(e){let f=e,d=e;for(;d&&d.parentId;){const m=this.artboard.objects.find(y=>y.id===d.parentId);if(m&&m.type==="Component"){f=m;break}d=m}let p=t;if(t==="click"?p="onClick":t==="down"?p="onPointerDown":t==="up"?p="onPointerUp":t==="blur"&&(p="onPointerLeave"),this.fireEventForObject(e.id,p),f!==e&&this.fireEventForObject(f.id,p),f.type==="Component"&&f.variant==="toggle_button"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{};y.checked=!y.checked,f.inputId&&this.setInternalInput(f.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"toggle_button",property:"checked",value:y.checked}),this.fireEventForObject(f.id,"Toggle"),this.fireEventForObject(f.id,y.checked?"Toggle True":"Toggle False")}if(f.type==="Component"&&f.variant==="toggle"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{};y.checked=!y.checked,f.inputId&&this.setInternalInput(f.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"toggle",property:"checked",value:y.checked}),this.onToggle&&this.onToggle(f.name,y.checked),this.fireEventForObject(f.id,"Toggle"),this.fireEventForObject(f.id,y.checked?"Toggle True":"Toggle False")}if(f.type==="Component"&&f.variant==="dropdown"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{},v=!y.isOpen;if(v&&this.activeDropdownId&&this.activeDropdownId!==f.id){const b=this.artboard.objects.find(C=>C.id===this.activeDropdownId);b&&b.options&&(b.options.isOpen=!1)}y.isOpen=v,this.activeDropdownId=v?f.id:null}if(f.type==="Component"&&f.variant==="button"&&t==="down"&&(this.onButtonClick&&this.onButtonClick(f.name,f.id),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"button",property:"click",value:!0})),f.type==="Component"&&f.variant==="listview"&&t==="down"){this.draggingListViewId=f.id;const m=this.getListViewItemIndexAtPointer(f,s,o);if(m!==null){const y=f.options||{};y.activeItemIndex=m;const v=this.objectStates.get(f.id);v&&v.options&&(v.options.activeItemIndex=m);const b=(y.items||[])[m],C=typeof b=="string"?b:b.label||b.value||m;v&&v.options&&(v.options.selectedValue=C),f.inputId&&this.setInternalInput(f.inputId,C),this.onComponentChange&&(this.onComponentChange({objectId:f.id,componentName:f.name,variant:"listview",property:"activeItemIndex",value:m}),this.onComponentChange({objectId:f.id,componentName:f.name,variant:"listview",property:"selected",value:C}))}}if(f.type==="Component"&&f.variant==="slider"&&t==="down"&&(this.draggingSliderId=f.id,this.updateSliderValueFromPointer(f,s,o)),f.type==="Component"&&f.variant==="checkbox"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{};y.checked=!y.checked,f.inputId&&this.setInternalInput(f.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"checkbox",property:"checked",value:y.checked}),this.fireEventForObject(f.id,"Click"),this.fireEventForObject(f.id,y.checked?"Checked":"Unchecked")}if(f.type==="Component"&&f.variant==="radiogroup"&&t==="down"){const m=this.objectStates.get(f.id),y=(m==null?void 0:m.options)||f.options||{},v=y.optionsList||[],b=this.getRadioGroupItemIndexAtPointer(f,s,o);if(b!==null&&b>=0&&b<v.length){const C=v[b];y.selectedValue=C,f.inputId&&this.setInternalInput(f.inputId,C),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"radiogroup",property:"selectedValue",value:C}),this.fireEventForObject(f.id,"Click"),this.fireEventForObject(f.id,`Selected: ${C}`)}}if(f.type==="LineGraph"&&(t==="down"||t==="click")){const m=f.geometry,y=(m==null?void 0:m.datasets)||[],v=this.objectStates.get(f.id),b=(v==null?void 0:v.width)||(m==null?void 0:m.width)||200,C=(v==null?void 0:v.height)||(m==null?void 0:m.height)||150,S=this.getWorldTransform(f.id),w=30,I=20,M=b-w,P=C-I;let T=1;y.forEach(E=>{const F=Math.max(...E.data||[0]);F>T&&(T=F)});let $=1/0,k=null;y.forEach((E,F)=>{const O=E.data||[],A=M/Math.max(O.length-1,1);O.forEach((W,x)=>{const B=S.x-b/2+w+x*A,N=S.y+C/2-I-W/T*P,Q=Math.sqrt((s-B)**2+(o-N)**2);Q<$&&($=Q,k={dIdx:F,pIdx:x,val:W,label:E.label||`Dataset ${F+1}`})})}),k&&$<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:f.id,componentName:f.name,datasetIndex:k.dIdx,pointIndex:k.pIdx,value:k.val,label:k.label}),this.onComponentChange&&this.onComponentChange({objectId:f.id,componentName:f.name,variant:"linegraph",property:"click",value:(k==null?void 0:k.val)??null})}if(t==="click"){const m=(l=this.artboard)==null?void 0:l.objects.find(b=>b.id===e.id),y=this.focusedId,v=(m==null?void 0:m.type)==="InputBox"||(m==null?void 0:m.type)==="Component"&&m.variant==="inputbox";if(m&&v){if(this.focusedId=e.id,console.log(`[Engine] Focus set to: ${e.id}`),y!==this.focusedId){if(y){const b=(h=this.artboard)==null?void 0:h.objects.find(C=>C.id===y);b&&this.onInputBlur&&this.onInputBlur(b.name)}this.onInputFocus&&this.onInputFocus(m.name)}}else if(this.focusedId=null,y){const b=(c=this.artboard)==null?void 0:c.objects.find(C=>C.id===y);b&&this.onInputBlur&&this.onInputBlur(b.name)}}}else if(t==="click"){const f=this.focusedId;if(this.focusedId=null,f){const d=(g=this.artboard)==null?void 0:g.objects.find(p=>p.id===f);d&&this.onInputBlur&&this.onInputBlur(d.name)}}}handleKeyDown(t){if(!this.artboard||!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)}fireEventForObject(t,s){var h,c,g,f,d;const o=(h=this.artboard)==null?void 0:h.objects.find(p=>p.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(p=>{const m=p.triggers||[p.event||p.trigger||"click"];return((p.triggerLogic||"OR")==="AND"?m.every(b=>e.has(b.toLowerCase())):m.some(b=>e.has(b.toLowerCase())))?p.conditions&&p.conditions.length>0?this.checkConditions(p.conditions):!0:!1});if(a){if(console.log(`[Engine] Interaction matched: ${s} -> Action: ${a.action}`),a.action==="setInput"||a.action==="Set Input"){let p=a.value||a.inputValue;p==="toggle"&&(p=!this.inputs.get(a.targetInputId)),this.updateInput(a.targetInputId,p)}else if(a.action==="Toggle Boolean"){const p=this.inputs.get(a.targetInputId);this.updateInput(a.targetInputId,!p)}else if(a.action==="fireTrigger")this.updateInput(a.targetInputId,!0);else if(a.action==="setProperty"){const p=a.targetObjectId||o.id,m=a.targetProperty;m&&this.updateObjectProperty(p,m,a.value)}else if(a.action==="Navigate Artboard"||a.action==="navigate")this.onNavigation&&this.onNavigation({type:"artboard",value:a.targetArtboard||a.value});else if(a.action==="Navigate URL")this.onNavigation&&this.onNavigation({type:"url",value:a.navigateUrl});else if(a.action==="Play Animation"){const p=a.targetAnimationId;p==="__all__"?(g=(c=this.artboard)==null?void 0:c.animations)==null||g.forEach(m=>{this.triggerGlobalAnimation(m.id,a.subAnimationIds)}):p&&this.triggerGlobalAnimation(p,a.subAnimationIds)}else if(a.action==="setState"||a.action==="Set State"){const p=a.targetObjectId||o.id,y={...this.objectStates.get(p)||{},...a.value||{}};this.objectStates.set(p,y),console.log(`[Engine] State updated for ${p}:`,y)}else if(a.action==="Stop Animation"||a.action==="Pause Animation"){const p=a.targetAnimationId;p==="__all__"?this.layerStates.forEach((m,y)=>{y.startsWith("global_")&&this.layerStates.delete(y)}):p&&this.layerStates.forEach((m,y)=>{y.startsWith(`global_${p}_`)&&this.layerStates.delete(y)})}else if(a.action==="Switch to State"&&this.activeStateMachine){const p=a.targetState,m=this.activeStateMachine.layers.find(y=>y.states.some(v=>v.id===p||v.name===p));m&&(console.log(`[Engine] Switching Layer ${m.name} to State ${p}`),this.enterStates(m.name,[p]))}this.onTrigger&&this.onTrigger(s,a.action)}const l=(o.triggers||[]).find(p=>{const m=p.eventType.toLowerCase();let y=!1;return(e.has(m)||m==="click"&&e.has("onclick")||m==="hover"&&(e.has("onpointerenter")||e.has("hover"))||m==="pointerdown"&&e.has("onpointerdown")||m==="pointerup"&&e.has("onpointerup"))&&(y=!0),y&&p.conditions&&p.conditions.length>0?this.checkConditions(p.conditions):y});if(l&&l.entryAnimationId){console.log(`[Engine] Trigger matched: ${s} (as ${l.eventType}) -> Animation ${l.entryAnimationId}`);const p=(d=(f=this.artboard)==null?void 0:f.animations)==null?void 0:d.find(m=>m.id===l.entryAnimationId);p&&(this.activeTriggers.set(o.id,{triggerId:l.id,animation:p,time:0,phase:"entry",elapsedHold:0,filterObjectId:l.targetObjectId}),this.onTrigger&&this.onTrigger(l.name,p.name))}}fireAnalyticsEvent(t,s){var r,l;const o=(r=this.artboard)==null?void 0:r.objects.find(h=>h.id===t);if(!o)return;const e=(l=o.style)==null?void 0:l.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(h=>{if(h.type==="literal")n[h.key]=h.value;else if(h.type==="variable"){const c=this.inputs.get(h.value);n[h.key]=c!==void 0?c:""}}),console.log(`[ExodeUI Analytics] Dispatching event "${i}" via ${s} trigger:`,n);const a=e.platforms||{ga4:!0,meta:!0,mixpanel:!1};if(a.ga4){const h=window;typeof h.gtag=="function"?(h.gtag("event",i,n),console.log(`[ExodeUI Analytics] GA4: Event "${i}" sent successfully.`)):console.warn(`[ExodeUI Analytics] GA4: window.gtag is not a function. Event "${i}" skipped.`)}if(a.meta){const h=window;typeof h.fbq=="function"?(h.fbq("track",i,n),console.log(`[ExodeUI Analytics] Meta Pixel: Event "${i}" sent successfully.`)):console.warn(`[ExodeUI Analytics] Meta Pixel: window.fbq is not a function. Event "${i}" skipped.`)}if(a.mixpanel){const h=window;h.mixpanel&&typeof h.mixpanel.track=="function"?(h.mixpanel.track(i,n),console.log(`[ExodeUI Analytics] Mixpanel: Event "${i}" sent successfully.`)):console.warn(`[ExodeUI Analytics] Mixpanel: window.mixpanel.track is not a function. Event "${i}" skipped.`)}}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){if(!this.artboard)return;const i=this.artboard.animations.find(a=>a.id===t);if(!i)return;const n=`global_${t}_${Math.random().toString(36).substr(2,5)}`;this.layerStates.set(n,{currentStateIds:[t],animations:[{animation:i,state:{loop:o},filterObjectIds:s}],time:0,duration:i.duration,ruleId:e}),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;(this.artboard.animationFlow||[]).forEach(e=>{if(e.trigger==="after_anim"&&e.targetAnimationId&&(e.afterAnim===t||s&&e.afterAnim===s)){const n=e.delay||0;n<=0?this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id):setTimeout(()=>this.triggerGlobalAnimation(e.targetAnimationId,e.subAnimationIds,e.loop,e.id),n)}})}getWorldTransform(t){var g;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,scaleX:1,scaleY:1,rotation:0};const o=(g=this.artboard)==null?void 0:g.objects.find(f=>f.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,l=s.y*e.scaleY,h=e.x+(r*n-l*a),c=e.y+(r*a+l*n);return{x:h,y:c,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,C;if(!this.objectStates.get(t.id))return!1;const i=((b=t.geometry)==null?void 0:b.width)??t.width??100,n=((C=t.geometry)==null?void 0:C.height)??t.height??100,a=this.getWorldTransform(t.id),r=s-a.x,l=o-a.y,h=-a.rotation*(Math.PI/180),c=Math.cos(h),g=Math.sin(h),f=r*c-l*g,d=r*g+l*c,p=a.scaleX,m=a.scaleY,y=i*Math.abs(p),v=n*Math.abs(m);return Math.abs(f)<=y/2&&Math.abs(d)<=v/2}updateSliderValueFromPointer(t,s,o){var I;const e=this.objectStates.get(t.id);if(!e)return;const i=t.options||{},n=((I=t.geometry)==null?void 0:I.width)??t.width??200,a=this.getWorldTransform(t.id),r=s-a.x,l=o-a.y,h=-a.rotation*(Math.PI/180),c=Math.cos(h),g=Math.sin(h),f=r*c-l*g,d=i.thumbWidth??16,p=n-d;let y=(f+p/2)/p;y=Math.max(0,Math.min(1,y));const v=i.min??0,b=i.max??100,C=i.step||1;let S=v+y*(b-v);C>0&&(S=Math.round(S/C)*C),S=Math.max(v,Math.min(b,S));const w=e.options||{};w.value!==S&&(e.options={...w,value:S},t.inputId&&this.setInternalInput(t.inputId,S),this.onComponentChange&&this.onComponentChange({objectId:t.id,componentName:t.name,variant:"slider",property:"value",value:S}))}applyAnimation(t,s,o){!t||!t.tracks||t.tracks.forEach(e=>{var c,g,f;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=(c=this.artboard)==null?void 0:c.objects.find(d=>d.id===i),a=((g=n==null?void 0:n.physics)==null?void 0:g.enabled)&&n.physics.bodyType!=="Static";let r=e.property;if(a&&(r==="x"||r==="y"||r==="rotation"))return;const l=this.objectStates.get(i);if(!l){this.frameCount%600===0&&this.debugLog(`Skipping track: Object ${i} not found in state`);return}const h=this.interpolate(e.keyframes,s);if(h!==void 0){if(this.frameCount%240===0){const d=(n==null?void 0:n.name)||i,p=typeof h=="object"?JSON.stringify(h).slice(0,50):h;this.debugLog(`[Anim] Applying ${r} = ${p} to ${d}`)}if(r.includes(".")){const d=(r||"").split(".");let p=l;for(let m=0;m<d.length-1;m++){if(typeof p[d[m]]!="object"||p[d[m]]===null){let y=n;for(let v=0;v<=m;v++)y=y?y[d[v]]:null;if(d[m]==="corner_radius"||d[m]==="cornerRadius"){const v=typeof p[d[m]]=="number"?p[d[m]]:typeof y=="number"?y:0;p[d[m]]={tl:v,tr:v,bl:v,br:v}}else p[d[m]]=y?JSON.parse(JSON.stringify(y)):{}}p=p[d[m]]}p[d[d.length-1]]=h,d[d.length-1]==="color"&&(d[d.length-2]==="fill"||d[d.length-2]==="stroke")&&(p.type="Solid")}else r==="fill"?(l.style||(l.style={}),l.style.fill=h):r==="stroke"?(l.style||(l.style={}),l.style.stroke=h):l[r]=h;if(this.physicsEngine&&((f=n==null?void 0:n.physics)!=null&&f.enabled)&&n.physics.bodyType==="Static")if(r==="x"){const d=this.physicsEngine.getPosition(i);d&&this.physicsEngine.setPosition(i,h,d.y)}else if(r==="y"){const d=this.physicsEngine.getPosition(i);d&&this.physicsEngine.setPosition(i,d.x,h)}else r==="rotation"&&this.physicsEngine.setRotation(i,h*(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;if(o.easing&&(n=si(o.easing)(n)),typeof o.value=="string"){if(o.value.startsWith("#"))return this.interpolateColor(o.value,e.value,n);const a=parseFloat(o.value),r=parseFloat(e.value);return!isNaN(a)&&!isNaN(r)?Math.round(a+(r-a)*n).toString():o.value}if(Array.isArray(o.value)&&Array.isArray(e.value))return o.value.length===e.value.length?o.value.map((a,r)=>{const l=e.value[r];return typeof a=="number"&&typeof l=="number"?a+(l-a)*n:n<.5?a:l}):n<.5?o.value:e.value;if(typeof o.value=="object"&&typeof e.value=="object"&&o.value!==null&&e.value!==null){if(o.value.width!==void 0&&o.value.color!==void 0)return this.interpolateStroke(o.value,e.value,n);if(o.value.type&&e.value.type)return this.interpolateFill(o.value,e.value,n);const a={};return new Set([...Object.keys(o.value),...Object.keys(e.value)]).forEach(l=>{const h=o.value[l],c=e.value[l];typeof h=="number"&&typeof c=="number"?a[l]=h+(c-h)*n:h===void 0?a[l]=c:c===void 0?a[l]=h:a[l]=n<.5?h:c}),a}return typeof o.value=="number"&&typeof e.value=="number"?o.value+(e.value-o.value)*n:n<.5?o.value:e.value}interpolateColor(t,s,o){var d,p;const e=((p=(d=this.artboard)==null?void 0:d.tokens)==null?void 0:p.colors)||{},i=e[t]||t,n=e[s]||s,a=m=>{if(!m)return{r:0,g:0,b:0};const y=m.startsWith("#")?m.replace("#",""):"000000";return y.length===3?{r:parseInt(y[0]+y[0],16),g:parseInt(y[1]+y[1],16),b:parseInt(y[2]+y[2],16)}:{r:parseInt(y.substring(0,2),16),g:parseInt(y.substring(2,4),16),b:parseInt(y.substring(4,6),16)}},r=a(i),l=a(n),h=Math.round(r.r+(l.r-r.r)*o),c=Math.round(r.g+(l.g-r.g)*o),g=Math.round(r.b+(l.b-r.b)*o),f=m=>{const y=Math.max(0,Math.min(255,m)).toString(16);return y.length===1?"0"+y:y};return`#${f(h)}${f(c)}${f(g)}`}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 h;this.debug_objectsTotal=((h=this.artboard)==null?void 0:h.objects.length)||0,this.debug_objectsRendered=0;const e=performance.now();if(this.canvasWidth=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),t.translate(i/2,n/2),this.rootTransform=t.getTransform(),this.artboard.backgroundVisible!==!1&&(t.fillStyle=this.artboard.backgroundColor||"#000000",t.fillRect(-i/2,-n/2,i,n)),this.artboard.backgroundImage){const c=this.artboard.backgroundImage;let g=this.imageCache.get(c);if(g||(g=new Image,g.src=c,this.imageCache.set(c,g)),g.complete&&g.naturalWidth>0){t.save(),t.globalAlpha=this.normalizeOpacity(this.artboard.backgroundOpacity??100);const f=g.naturalWidth/g.naturalHeight,d=i/n;let p,m,y,v;d>f?(p=i,m=i/f):(m=n,p=n*f),y=-p/2,v=-m/2,t.drawImage(g,y,v,p,m),t.restore()}}t.beginPath(),t.rect(-i/2,-n/2,i,n),t.clip();const r=new Map;this.artboard.objects.forEach(c=>r.set(c.id,c)),this.artboard.objects.filter(c=>!c.parentId).map((c,g)=>{const f=this.objectStates.get(c.id),d=(f==null?void 0:f.zIndex)??g;return{obj:c,zIndex:d}}).sort((c,g)=>c.zIndex-g.zIndex).forEach(({obj:c})=>{this.renderObject(t,c,r)}),this._emitterPools.forEach((c,g)=>{if(!(c.length===0||!r.get(g)))for(const d of c)t.save(),t.globalAlpha=d.opacity,t.fillStyle=d.color,t.beginPath(),t.arc(d.x,d.y,Math.max(1,d.size*d.opacity),0,Math.PI*2),t.fill(),t.restore()}),this.lastRenderTime=performance.now()-e,this.debugMode&&this.frameCount%60===0&&console.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,l=s*a.b+o*a.d+a.f,h=Math.sqrt(a.a*a.a+a.b*a.b),c=Math.sqrt(a.c*a.c+a.d*a.d),g=(e/2+n)*h,f=(i/2+n)*c;return r+g>=0&&r-g<=this.canvasWidth&&l+f>=0&&l-f<=this.canvasHeight}calculateTransform(t,s,o,e,i,n){let a=1,r=1,l=1;const h=o/e,c=t/s;switch(i){case"Contain":c>h?l=s/e:l=t/o,a=r=l;break;case"Cover":c>h?l=t/o:l=s/e,a=r=l;break;case"Fill":a=t/o,r=s/e;break;case"FitWidth":l=t/o,a=r=l;break;case"FitHeight":l=s/e,a=r=l;break;case"None":a=r=1;break;case"ScaleDown":l=Math.min(t/o,s/e),l>1&&(l=1),a=r=l;break;default:a=r=1;break}const g=o*a,f=e*r;let d=0,p=0;return n.includes("Left")?d=0:n.includes("Right")?d=t-g:d=(t-g)/2,n.includes("Top")?p=0:n.includes("Bottom")?p=s-f:p=(s-f)/2,{scaleX:a,scaleY:r,tx:d,ty:p}}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){var p,m,y,v,b,C,S,w,I,M,P,T,$,k,E,F,O;const e=this.objectStates.get(s.id);if(!e){console.warn("No state for object:",s.id);return}this.frameCount%60,t.roundRect||(t.roundRect=(A,W,x,B,N)=>(this.drawRoundRect(t,A,W,x,B,N),t));const i=e.geometry?this.deepMerge(s.geometry,e.geometry):s.geometry,n=e.style?this.deepMerge(s.style,e.style):s.style;let a=(i==null?void 0:i.width)||((p=s.geometry)==null?void 0:p.width)||s.width||0,r=(i==null?void 0:i.height)||((m=s.geometry)==null?void 0:m.height)||s.height||0;if((a===0||r===0)&&(i!=null&&i.points)&&Array.isArray(i.points)&&i.points.length>0){let A=1/0,W=-1/0,x=1/0,B=-1/0;i.points.forEach(N=>{A=Math.min(A,N.x),W=Math.max(W,N.x),x=Math.min(x,N.y),B=Math.max(B,N.y)}),a===0&&(a=W-A),r===0&&(r=B-x)}const l=A=>{if(A)return A.corner_radius??A.cornerRadius},h=l(e)??l(n)??l(i)??l(s.style)??l(s.geometry)??0;let c={...i,width:a,height:r};if(delete c.cornerRadius,c.corner_radius=h,c.type==="Path"&&s.weights&&s.bindMatrices&&c.points){const A=this.getGlobalTransform(s.id);if(A){const W=ii(c.points,s.weights,s.bindMatrices,A,x=>this.getGlobalTransform(x));c={...c,points:W}}}if(e.visible===!1)return;const g=s.repeaterConfig,f=g&&g.isEnabled&&g.count>1,d=f?g.count:1;for(let A=0;A<d;A++){let W=e.x,x=e.y,B=e.rotation,N=e.scale_x??1,Q=e.scale_y??1;if(f&&A>0){if(g.type==="Linear"){const nt=g.offsetX||0,ht=g.offsetY||0,z=g.rotation||0,Y=g.scale!==void 0?g.scale:1;W+=A*nt,x+=A*ht,B+=A*z,N*=Math.pow(Y,A),Q*=Math.pow(Y,A)}else if(g.type==="Grid"){const nt=g.cols||Math.ceil(Math.sqrt(g.count)),ht=g.gapX||0,z=g.gapY||0,Y=Math.floor(A/nt),tt=A%nt,Z=a+ht,xt=r+z;W+=tt*Z,x+=Y*xt}else if(g.type==="Radial"){const nt=g.radius||100,ht=g.startAngle||0,Y=(g.endAngle||360)-ht,tt=g.count>1?Y/(Y===360?g.count:g.count-1):0,Z=ht+A*tt,xt=Z*Math.PI/180;W=e.x+nt*Math.cos(xt),x=e.y+nt*Math.sin(xt),B+=Z}}const _=s.type==="Group"||s.type==="Frame"||s.type==="Component",L=a>0&&r>0;if(!_&&L){const nt=(((y=n.shadow)==null?void 0:y.isEnabled)!==!1?(((v=n.shadow)==null?void 0:v.blur)||0)+10:0)+(((b=n.blur)==null?void 0:b.isEnabled)!==!1&&((C=n.blur)==null?void 0:C.radius)||0)+20;if(!this.isObjectInView(t,W,x,a,r,nt))continue}this.debug_objectsRendered++,t.save();const U=[],q=n.blur||((S=s.style)==null?void 0:S.blur);q&&q.amount>0&&U.push(`blur(${q.amount}px)`);const et=n.effect||((w=s.style)==null?void 0:w.effect),ft=(et==null?void 0:et.isEnabled)===!0,vt=et==null?void 0:et.type,lt=(et==null?void 0:et.radius)??10;ft&&vt==="LayerBlur"&&U.push(`blur(${lt}px)`);const ut=((I=i==null?void 0:i.type)==null?void 0:I.toLowerCase().includes("image"))||((M=s.type)==null?void 0:M.toLowerCase().includes("image")),ot=n.adjustments&&Object.keys(n.adjustments).length>0?n.adjustments:null,Et=i!=null&&i.adjustments&&Object.keys(i.adjustments).length>0?i.adjustments:null,Ft=ut?Et||ot:ot||Et,Mt=ut&&!Ft?{exposure:0,contrast:0,saturation:100,temperature:0,tint:0,highlights:0,shadows:0,blur:0,negative:0,hue:0}:Ft;if(e&&Mt&&(e.geometry=e.geometry||{},e.geometry.adjustments={...Mt}),Mt){const nt=(Mt.exposure||0)/100,ht=Mt.contrast||0,z=1+(Mt.saturation||0)/100,Y=(Mt.temperature||0)/200,tt=(Mt.tint||0)/200,Z=(Mt.highlights||0)/500,xt=(Mt.shadows||0)/500;let Bt="",Pt="SourceGraphic";if(nt!==0&&(Bt+=`
|
|
8
|
+
<feComponentTransfer in="${Pt}" result="exposure">
|
|
9
|
+
<feFuncR type="linear" slope="1" intercept="${nt}"/>
|
|
10
|
+
<feFuncG type="linear" slope="1" intercept="${nt}"/>
|
|
11
|
+
<feFuncB type="linear" slope="1" intercept="${nt}"/>
|
|
12
|
+
</feComponentTransfer>`,Pt="exposure"),ht!==0){const Tt=(ht+100)/100,R=.5*(1-Tt);Bt+=`
|
|
13
|
+
<feComponentTransfer in="${Pt}" result="contrast">
|
|
14
|
+
<feFuncR type="linear" slope="${Tt}" intercept="${R}"/>
|
|
15
|
+
<feFuncG type="linear" slope="${Tt}" intercept="${R}"/>
|
|
16
|
+
<feFuncB type="linear" slope="${Tt}" intercept="${R}"/>
|
|
17
|
+
</feComponentTransfer>`,Pt="contrast"}if(z!==1&&(Bt+=`<feColorMatrix in="${Pt}" type="saturate" values="${z}" result="saturate"/>`,Pt="saturate"),Mt.hue&&(Bt+=`<feColorMatrix in="${Pt}" type="hueRotate" values="${Mt.hue}" result="hue"/>`,Pt="hue"),Mt.negative){const Tt=1-Mt.negative/50;Bt+=`
|
|
18
|
+
<feColorMatrix in="${Pt}" type="matrix" result="invert"
|
|
19
|
+
values="${Tt} 0 0 0 ${1-Tt}
|
|
20
|
+
0 ${Tt} 0 0 ${1-Tt}
|
|
21
|
+
0 0 ${Tt} 0 ${1-Tt}
|
|
22
|
+
0 0 0 1 0"/>`,Pt="invert"}if(Y!==0||tt!==0||Z!==0||xt!==0){const Tt=1+Z+xt,R=Tt*(1+Y-tt/2),At=Tt*(1+tt),le=Tt*(1-Y-tt/2),Ct=Mt.shadows*.1/255,qt=[R,0,0,0,Ct,0,At,0,0,Ct,0,0,le,0,Ct,0,0,0,1,0].join(" ");Bt+=`<feColorMatrix in="${Pt}" type="matrix" values="${qt}" result="advanced"/>`,Pt="advanced"}if(Mt.blur&&(Bt+=`<feGaussianBlur in="${Pt}" stdDeviation="${Mt.blur}" result="blur"/>`,Pt="blur"),Bt){const Tt=`<svg xmlns="http://www.w3.org/2000/svg"><filter id="f" color-interpolation-filters="sRGB">${Bt}</filter></svg>`,R=btoa(Tt);U.push(`url('data:image/svg+xml;base64,${R}#f')`)}}U.length>0?t.filter=U.join(" "):t.filter="none",t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";const Dt=t.globalAlpha,Yt=this.normalizeOpacity(e.opacity!==void 0?e.opacity:100);t.globalAlpha=Dt*Yt;const Rt=e.compositeOperation||e.blendMode;if(Rt&&Rt!=="Normal"){const nt=Rt.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(nt)&&(t.globalCompositeOperation=nt)}const ee=t,H=e.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 at=!1;const Lt=H.filter(nt=>nt.isVisible!==!1&&o.has(nt.maskId));if(Lt.length>0){const nt=Lt[0],ht=o.get(nt.maskId),z=this.objectStates.get(ht.id);z&&z.visible!==!1&&(at=!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=ee.filter)}t.translate(Math.round(W),Math.round(x)),t.rotate(B*Math.PI/180);const kt=e.skew_x||0,St=e.skew_y||0;(kt!==0||St!==0)&&t.transform(1,Math.tan(St*Math.PI/180),Math.tan(kt*Math.PI/180),1,0,0);const Vt=e.rotate_x||0,jt=e.rotate_y||0,te=(e.flip_x===!0?-1:1)*Math.cos(jt*Math.PI/180),Kt=(e.flip_y===!0?-1:1)*Math.cos(Vt*Math.PI/180);t.scale(N*te,Q*Kt),n.shadow&&n.shadow.isEnabled!==!0&&((n.shadow.blur||0)>0||Math.abs(n.shadow.offsetX||0)>0||Math.abs(n.shadow.offsetY||0)>0)&&(n.shadow.isEnabled=!0);const Ht=n.shadow;if(Ht&&Ht.isEnabled!==!1){let nt=Ht.color||"#000000";(T=(P=this.artboard)==null?void 0:P.tokens)!=null&&T.colors&&this.artboard.tokens.colors[nt]&&(nt=this.artboard.tokens.colors[nt]);const ht=this.normalizeOpacity(Ht.opacity??100),z=Ht.spread||0,tt=(Ht.blur||0)+z*1.5;let Z=nt;if(nt.startsWith("#")){const Pt=nt.replace("#",""),Ut=parseInt(Pt.substring(0,2),16),Tt=parseInt(Pt.substring(2,4),16),R=parseInt(Pt.substring(4,6),16);Z=`rgba(${Ut}, ${Tt}, ${R}, ${ht})`}else if(nt.startsWith("rgba")){const Pt=nt.match(/[\d.]+/g);if(Pt&&Pt.length>=4){const Ut=Pt[0],Tt=Pt[1],R=Pt[2],At=Pt[3];Z=`rgba(${Ut}, ${Tt}, ${R}, ${parseFloat(At)*ht})`}}const xt=t.getTransform(),Bt=Math.sqrt(xt.a*xt.a+xt.b*xt.b)||1;t.shadowColor=Z,t.shadowBlur=tt*Bt,t.shadowOffsetX=(Ht.offsetX||0)*Bt,t.shadowOffsetY=(Ht.offsetY||0)*Bt}const ae=s.liquidFill||(($=s.style)==null?void 0:$.liquidFill);if(ae&&ae.enabled){t.save();const nt=ae.fillLevel??.5;t.beginPath();const ht=r/2-r*nt;t.rect(-a/2,ht,a,r*nt),t.clip(),t.fillStyle=ae.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(ae.opacity??1)}if((i==null?void 0:i.type)==="Text")this._renderText(t,s,c,n,e,a,r);else if((i==null?void 0:i.type)==="Image"){const nt=i.originalSrc||i.src;if(nt){let ht=this.imageCache.get(nt);ht||(ht=new Image,ht.onload=()=>{console.log(`[ExodeUI] Image loaded successfully, size: ${ht.naturalWidth}x${ht.naturalHeight}`)},ht.onerror=tt=>{console.error("[ExodeUI] Image load failed:",tt,`Src preview: ${nt.substring(0,100)}...`)},ht.src=nt,this.imageCache.set(nt,ht));const z=n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1,Y=(((k=n.stroke)==null?void 0:k.alignment)||"center").toLowerCase();if(z&&(Y==="outside"||Y==="center")&&this.applyStrokeAlignment(t,n,c,a,r,h),n.fill&&n.fill.type!=="None"){t.save();const tt=t.globalAlpha,Z=this.createCanvasFill(t,n.fill,a,r);t.fillStyle=Z||n.fill.color||"transparent",t.globalAlpha=tt*this.normalizeOpacity(n.fill.opacity??100),h!==0?(this.drawRoundRect(t,-a/2,-r/2,a,r,h),t.fill()):t.fillRect(-a/2,-r/2,a,r),t.globalAlpha=tt,t.restore()}ht.complete&&ht.naturalWidth>0?(h!==0?(t.save(),this.drawRoundRect(t,-a/2,-r/2,a,r,h),t.clip(),t.drawImage(ht,-a/2,-r/2,a,r),t.restore()):t.drawImage(ht,-a/2,-r/2,a,r),z&&Y==="inside"&&this.applyStrokeAlignment(t,n,c,a,r,h)):z&&Y==="inside"&&this.applyStrokeAlignment(t,n,c,a,r,h)}}else if(i.type==="SVG"){const nt=i.svgContent;if(nt){const ht=n.palette||[],z=n.fill,Y=n.stroke,tt=z?this.normalizeOpacity(z.opacity??100):1,Z=(z==null?void 0:z.type)==="Solid"&&(!Y||Y.isEnabled===!1||Y.type==="Solid"&&Y.color===z.color),xt=z&&z.type!=="None"?Z?"monochrome":z.type==="Solid"?(z.color||"")+"|opacity:"+tt:JSON.stringify(z.stops||[])+"|opacity:"+tt:"",Bt=Y&&Y.isEnabled!==!1&&(Y.width||0)>0?Z?["monochrome",Y.width||0,Y.trimStart??0,Y.trimEnd??1,Y.trimOffset??0,Y.dashOffset??0].join("|"):[Y.width||0,Y.fill?Y.fill.type==="Solid"?Y.fill.color||"":JSON.stringify(Y.fill.stops||[]):Y.color||"",Y.opacity??1,Y.lineCap||"",Y.lineJoin||"",(Y.dashArray||[]).join(","),Y.trimStart??0,Y.trimEnd??1,Y.trimOffset??0,Y.dashOffset??0].join("|"):"nostroke",Pt=[s.id,ht.join("_"),xt,Bt,e.opacity??100,e.visible!==!1?"v":"h"].join("_");let Ut=this.imageCache.get(Pt);if(!Ut){Ut=new Image,Ut.crossOrigin="anonymous";let R=nt;R.match(/xmlns=["']http:\/\/www\.w3\.org\/2000\/svg["']/i)||(R=R.replace(/<svg([^>]*)>/i,(rt,ct)=>`<svg xmlns="http://www.w3.org/2000/svg"${ct}>`));let At=i.width||a||100,le=i.height||r||100;const Ct=R.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(Ct&&(At=parseFloat(Ct[1]),le=parseFloat(Ct[2])),R=R.replace(/<svg([^>]*)>/i,(rt,ct)=>{let gt=ct.replace(/\b(?:width|height)=["'][^"']*["']/gi," ");return gt.match(/\bviewBox=/i)||(gt+=` viewBox="0 0 ${At} ${le}"`),gt.match(/\bpreserveAspectRatio=/i)||(gt+=' preserveAspectRatio="none"'),gt+=' width="100%" height="100%"',`<svg${gt}>`}),i.colors&&i.colors.length>0&&ht.length>0&&i.colors.forEach((rt,ct)=>{if(ht[ct]){const gt=rt.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),It=new RegExp(gt,"gi");R=R.replace(It,ht[ct])}}),z&&z.type&&z.type!=="None"){if(z.type==="Solid"&&z.color){const rt=Z?"#FFFFFF":z.color,ct=Z?1:this.normalizeOpacity(z.opacity??100);R=R.replace(/\bfill\s*=\s*["'][^"']*["']/gi,gt=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(gt)?gt:`fill="${rt}"`),R=R.replace(/fill\s*:\s*[^;"')]+/gi,gt=>/fill\s*:\s*(none|transparent)/i.test(gt)?gt:`fill:${rt}`),ct<1&&(R=R.replace(/\bfill-opacity\s*=\s*["'][^"']*["']/gi,`fill-opacity="${ct}"`),R=R.replace(/fill-opacity\s*:\s*[^;"')]+/gi,`fill-opacity:${ct}`),R.match(/\bfill-opacity\s*=/i)||(R=R.replace(/(<svg[^>]*>)/i,`$1<g fill-opacity="${ct}">`),R=R.replace(/<\/svg>/i,"</g></svg>")))}else if(z.type==="LinearGradient"||z.type==="RadialGradient"||z.type==="Linear"||z.type==="Radial"){const rt="exode-fill",ct=this.normalizeOpacity(z.opacity??100),gt=(z.stops||[]).map(pt=>{const Gt=pt.offset!==void 0?pt.offset:pt.pos??0,ie=this.normalizeOpacity(pt.opacity??100)*ct;return`<stop offset="${Gt*100}%" stop-color="${pt.color||"#000"}" stop-opacity="${ie}"/>`}).join("");let It="";if(z.type==="LinearGradient"||z.type==="Linear"){const pt=(j,dt)=>Array.isArray(j)?j[dt]??(dt===0?0:1):j&&typeof j=="object"?j[dt===0?"x":"y"]??(dt===0?0:1):dt===0?0:1,Gt=pt(z.start,0)*100,ie=pt(z.start,1)*100,Zt=pt(z.end,0)*100,it=pt(z.end,1)*100;It=`<linearGradient id="${rt}" x1="${Gt}%" y1="${ie}%" x2="${Zt}%" y2="${it}%" gradientUnits="objectBoundingBox">${gt}</linearGradient>`}else{const pt=(it,j)=>Array.isArray(it)?it[j]??.5:it&&typeof it=="object"?it[j===0?"x":"y"]??.5:.5,Gt=pt(z.center,0)*100,ie=pt(z.center,1)*100,Zt=(z.radius??.5)*100;It=`<radialGradient id="${rt}" cx="${Gt}%" cy="${ie}%" r="${Zt}%" gradientUnits="objectBoundingBox">${gt}</radialGradient>`}/<defs>/i.test(R)?R=R.replace(/<defs>/i,`<defs>${It}`):R=R.replace(/<svg([^>]*)>/i,`<svg$1><defs>${It}</defs>`),R=R.replace(/\bfill\s*=\s*["'][^"']*["']/gi,pt=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(pt)?pt:`fill="url(#${rt})"`),R=R.replace(/fill\s*:\s*[^;"')]+/gi,pt=>/fill\s*:\s*(none|transparent)/i.test(pt)?pt:`fill:url(#${rt})`)}}const qt=(rt,ct,gt=1)=>{const It=(rt.stops||[]).map(it=>{const j=it.offset!==void 0?it.offset:it.pos??0,dt=this.normalizeOpacity(it.opacity??100)*gt;return`<stop offset="${j*100}%" stop-color="${it.color||"#000"}" stop-opacity="${dt}"/>`}).join(""),pt=(it,j,dt=.5)=>Array.isArray(it)?it[j]??dt:it&&typeof it=="object"?it[j===0?"x":"y"]??dt:dt;if(rt.type==="LinearGradient"||rt.type==="Linear"){const it=pt(rt.start,0,0)*100,j=pt(rt.start,1,0)*100,dt=pt(rt.end,0,1)*100,$t=pt(rt.end,1,1)*100;return`<linearGradient id="${ct}" x1="${it}%" y1="${j}%" x2="${dt}%" y2="${$t}%" gradientUnits="objectBoundingBox">${It}</linearGradient>`}const Gt=pt(rt.center,0,.5)*100,ie=pt(rt.center,1,.5)*100,Zt=(rt.radius??.5)*100;return`<radialGradient id="${ct}" cx="${Gt}%" cy="${ie}%" r="${Zt}%" gradientUnits="objectBoundingBox">${It}</radialGradient>`},wt=(rt,ct)=>/<defs>/i.test(rt)?rt.replace(/<defs>/i,`<defs>${ct}`):rt.replace(/(<svg[^>]*>)/i,`$1<defs>${ct}</defs>`);if(Y&&Y.isEnabled!==!1&&(Y.width||0)>0){const rt=Z?1:this.normalizeOpacity(Y.opacity??100),ct=Z?"#FFFFFF":Y.color||(z==null?void 0:z.color)||"#000000";let gt="";const It=Y.fill;if(It&&It.type){if(It.type==="Solid")gt=It.color||Y.color||"#000000";else if(It.type==="LinearGradient"||It.type==="RadialGradient"||It.type==="Linear"||It.type==="Radial"){const Qt="exode-stroke";R=wt(R,qt(It,Qt,rt)),gt=`url(#${Qt})`}}gt||(gt=ct),R.match(/\bstroke\s*=\s*["']/i)?R=R.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,Qt=>/stroke\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Qt)?Qt:`stroke="${gt}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke="${gt}"`),R=R.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),`stroke:${gt}`);let pt=i.width||a||100,Gt=i.height||r||100;const ie=nt.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(ie){const Qt=parseFloat(ie[1]),ce=parseFloat(ie[2]);!isNaN(Qt)&&!isNaN(ce)&&(pt=Qt,Gt=ce)}const Zt=Math.max(.001,a/pt),it=Math.max(.001,r/Gt),j=(Zt+it)/2,dt=(Y.width||1)/j;R.match(/\bstroke-width\s*=\s*["']/i)?R=R.replace(/\bstroke-width\s*=\s*["'][^"']*["']/gi,`stroke-width="${dt}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-width="${dt}"`),R=R.replace(/stroke-width\s*:\s*[^;"')]+/gi,`stroke-width:${dt}`),R.match(/\bstroke-opacity\s*=\s*["']/i)?R=R.replace(/\bstroke-opacity\s*=\s*["'][^"']*["']/gi,`stroke-opacity="${rt}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-opacity="${rt}"`),R=R.replace(/stroke-opacity\s*:\s*[^;"')]+/gi,`stroke-opacity:${rt}`);const $t=Y.lineCap||"round";R.match(/\bstroke-linecap\s*=\s*["']/i)?R=R.replace(/\bstroke-linecap\s*=\s*["'][^"']*["']/gi,`stroke-linecap="${$t}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linecap="${$t}"`),R=R.replace(/stroke-linecap\s*:\s*[^;"')]+/gi,`stroke-linecap:${$t}`);const J=Y.lineJoin||"round";R.match(/\bstroke-linejoin\s*=\s*["']/i)?R=R.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${J}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-linejoin="${J}"`),R=R.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${J}`);const yt=Y.trimStart??0,mt=Y.trimEnd??1,pe=Y.trimOffset??0,Ce=Y.dashOffset??0,_e=yt!==0||mt!==1||pe!==0||Ce!==0;if(_e){const Qt=Math.max(0,Math.min(1,yt)),ce=Math.max(0,Math.min(1,mt));this.frameCount%600===0&&this.debugLog(`SVG Trim - Object: ${s.name||s.id}, Start: ${Qt}, End: ${ce}`);const ve=(pt+Gt)*2,Ie=(pe%1+1)%1,Me=(Ce%1+1)%1;let ge="",de=0;if(Qt>=ce)ge=`0 ${ve}`,de=0;else{const ue=ve*(ce-Qt),Se=ve-ue;de=-(ve*(Qt+Ie+Me)),ge=`${ue} ${Se}`}R.match(/\bstroke-dasharray\s*=/i)?R=R.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${ge}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dasharray="${ge}"`),R=R.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${ge}`),R.match(/\bstroke-dashoffset\s*=/i)?R=R.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${de}"`):R=R.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dashoffset="${de}"`),R=R.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${de}`)}else if(Y.dashArray&&Y.dashArray.length>0){const Qt=Y.dashArray.join(" ");R=R.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${Qt}"`),R=R.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${Qt}`),Y.dashOffset&&(R=R.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${Y.dashOffset}"`),R=R.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${Y.dashOffset}`))}if(!/\bstroke\s*=\s*["']/i.test(nt)&&!new RegExp("(?<![a-z-])stroke\\s*:","i").test(nt)){let Qt="",ce="";if(_e){const ge=i.width||a||100,de=i.height||r||100,ue=(ge+de)*2,Se=Math.max(0,Math.min(1,yt)),Pe=Math.max(0,Math.min(1,mt)),Re=(pe%1+1)%1,$e=(Ce%1+1)%1;if(Se>=Pe)Qt=` stroke-dasharray="0 ${ue}"`,ce=' stroke-dashoffset="0"';else{const Ee=ue*(Pe-Se),We=ue-Ee,Be=-(ue*(Se+Re+$e));Qt=` stroke-dasharray="${Ee} ${We}"`,ce=` stroke-dashoffset="${Be}"`}}else(E=Y.dashArray)!=null&&E.length&&(Qt=` stroke-dasharray="${Y.dashArray.join(" ")}"`,Y.dashOffset&&(ce=` stroke-dashoffset="${Y.dashOffset}"`));const ve=` stroke-linecap="${Y.lineCap||"round"}"`,Ie=` stroke-linejoin="${Y.lineJoin||"round"}"`,Me=`stroke="${gt}" stroke-width="${dt}" stroke-opacity="${rt}"${ve}${Ie}${Qt}${ce}`;R=R.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(ge,de,ue)=>`${de}${ue}<g ${Me}>`),R=R.replace(/<\/svg>/i,"</g></svg>")}}else Y&&Y.isEnabled===!1&&(R=R.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,'stroke="none"'),R=R.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),"stroke:none"));const Xt=new Blob([R],{type:"image/svg+xml"}),Jt=URL.createObjectURL(Xt);Ut.onload=()=>{if(URL.revokeObjectURL(Jt),this.frameCount%900===0){const rt=this.imageCache.get(Pt);rt&&this.debugLog(`SVG Payload Ready: ${s.name||s.id} (${rt.naturalWidth}x${rt.naturalHeight})`)}},Ut.onerror=()=>{URL.revokeObjectURL(Jt),this.debugLog(`SVG Error: Failed to load payload for ${s.name||s.id}`)},Ut.src=Jt,this.imageCache.set(Pt,Ut)}let Tt=null;if(Ut.complete&&Ut.naturalWidth>0?(Tt=Ut,this.lastValidSvgImgMap.set(s.id,Ut)):Tt=this.lastValidSvgImgMap.get(s.id)||null,Tt&&Tt.complete&&Tt.naturalWidth>0){const R=Math.max(1,a),At=Math.max(1,r);if(Z&&(z==null?void 0:z.type)==="Solid"){this.maskBuffer||(this.maskBuffer=document.createElement("canvas"),this.maskCtx=this.maskBuffer.getContext("2d")),this.maskBuffer.width=R,this.maskBuffer.height=At,this.maskCtx.setTransform(1,0,0,1,0,0),this.maskCtx.globalCompositeOperation="source-over",this.maskCtx.globalAlpha=1,this.maskCtx.filter="none",this.maskCtx.clearRect(0,0,R,At),this.maskCtx.drawImage(Tt,0,0,R,At),this.maskCtx.globalCompositeOperation="source-in";const le=z.color||"#000000",Ct=this.normalizeOpacity(z.opacity??100);this.maskCtx.fillStyle=le,this.maskCtx.globalAlpha=Ct,this.maskCtx.fillRect(0,0,R,At),t.drawImage(this.maskBuffer,-R/2,-At/2,R,At)}else h!==0?(t.save(),this.drawRoundRect(t,-R/2,-At/2,R,At,h),t.clip(),t.drawImage(Tt,-R/2,-At/2,R,At),t.restore()):t.drawImage(Tt,-R/2,-At/2,R,At)}}}else if(c.type==="LineGraph")this.renderLineGraph(t,c,a,r);else if(s.type==="Shape"){if(this.applyPath(t,c,a,r,h),t.save(),n.blur&&n.blur.amount>0&&(t.filter=`blur(${n.blur.amount}px)`),n.fill){const nt=t.globalAlpha;if(((F=n.fill)==null?void 0:F.type)==="Image"&&(n.fill.originalSrc||n.fill.src)){const ht=n.fill.originalSrc||n.fill.src;let z=this.imageCache.get(ht);z||(z=new Image,z.src=ht,this.imageCache.set(ht,z)),z.complete&&z.naturalWidth>0&&(t.save(),this.applyPath(t,c,a,r,h),t.clip(),this.renderFittedImage(t,z,-a/2,-r/2,a,r,n.fill.fillMode),t.restore())}else{const ht=this.createCanvasFill(t,n.fill,a,r);t.fillStyle=ht||(typeof n.fill=="string"?n.fill:n.fill.color||"transparent"),t.globalAlpha=nt*this.normalizeOpacity(n.fill.opacity??100),this.applyPath(t,c,a,r,h),t.fill()}t.globalAlpha=nt}t.restore(),n.stroke&&n.stroke.width>0&&this.applyStrokeAlignment(t,n,c,a,r,h)}else if(s.type==="Frame"||s.type==="Group"&&!s.isStructuralGroup){const nt=e.width??i.width??s.width??a,ht=e.height??i.height??s.height??r,z=h;if(t.save(),t.beginPath(),this.drawRoundRect(t,-nt/2,-ht/2,nt,ht,z),n.fill&&n.fill.type!=="None"){const Y=t.globalAlpha,tt=this.createCanvasFill(t,n.fill,nt,ht);t.fillStyle=tt||n.fill.color||"transparent",t.globalAlpha=Y*this.normalizeOpacity(n.fill.opacity??100),t.fill(),t.globalAlpha=Y}if(t.restore(),n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1){const Y={type:"Rectangle"};this.applyStrokeAlignment(t,n,Y,nt,ht,z)}}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):this.frameCount%60===0&&console.warn("[Engine] Unhandled object type in renderObject:",s.type,"Geo:",(O=s.geometry)==null?void 0:O.type));if(this.applyArtEffectOverlay(t,s,c,a,r,h),ft&&vt==="BackgroundBlur"&&this.applyBackgroundBlurGlass(t,c,a,r,h,et),ae&&ae.enabled&&t.restore(),s.children&&s.children.length>0){const ht=s.type==="Frame",z=s.clipsContent!==void 0?s.clipsContent:s.clipContent!==void 0?s.clipContent:ht;if(t.save(),z){t.beginPath();const tt=e.width??(i==null?void 0:i.width)??s.width??0,Z=e.height??(i==null?void 0:i.height)??s.height??0,xt=e.cornerRadius??(i==null?void 0:i.corner_radius)??s.cornerRadius??0;this.drawRoundRect(t,-tt/2,-Z/2,tt,Z,xt),t.clip()}let Y=0;for(s.children.forEach(tt=>{const Z=o.get(tt);if(!Z)return;const xt=this.objectStates.get(tt),Bt=(xt==null?void 0:xt.geometry)||Z.geometry;if(Bt&&Bt.isMask&&(xt==null?void 0:xt.visible)!==!1){const Pt=Bt.width||0,Ut=Bt.height||0;this.applyObjectTransform(t,tt);const Tt=(xt==null?void 0:xt.corner_radius)??(Bt==null?void 0:Bt.corner_radius)??0;this.applyPath(t,Bt,Pt,Ut,Tt),t.clip(),Y++}else this.renderObject(t,Z,o)});Y>0;)t.restore(),Y--;t.restore()}if(at){this.maskCtx.restore(),(e.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(Y=>Y.isVisible!==!1&&o.has(Y.maskId)).forEach(Y=>{var Tt,R,At,le,Ct,qt;const tt=o.get(Y.maskId),Z=this.objectStates.get(tt.id),xt=Y.feather||0,Bt=Y.inverted===!0,Pt=Y.opacity!==void 0?typeof Y.opacity=="number"?Y.opacity:Y.opacity/100:1;if((Y.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,tt.id,o),xt>0&&(this.lumaCtx.filter=`blur(${xt}px)`),this.lumaCtx.globalAlpha=Pt;const wt=(Z==null?void 0:Z.width)||tt.geometry.width||0,Xt=(Z==null?void 0:Z.height)||tt.geometry.height||0,Jt=(Z==null?void 0:Z.corner_radius)??tt.corner_radius??0;if(((Tt=tt.geometry)==null?void 0:Tt.type)==="Text"){const It=Z!=null&&Z.geometry?this.deepMerge(tt.geometry,Z.geometry):tt.geometry,pt=Z!=null&&Z.style?this.deepMerge(tt.style,Z.style):tt.style;this._renderText(this.lumaCtx,tt,{...It,width:wt,height:Xt,corner_radius:Jt},pt,Z,wt,Xt,!0)}else if(((R=tt.geometry)==null?void 0:R.type)==="Image"){const It=tt.geometry.src;if(It){let pt=this.imageCache.get(It);pt||(pt=new Image,pt.src=It,this.imageCache.set(It,pt)),pt.complete&&pt.naturalWidth>0?this.lumaCtx.drawImage(pt,-wt/2,-Xt/2,wt,Xt):(this.applyPath(this.lumaCtx,tt.geometry,wt,Xt,Jt),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else if(((At=tt.geometry)==null?void 0:At.type)==="SVG"){const It=tt.geometry.svgContent;if(It){const pt=`__lumamask_${tt.id}`;let Gt=this.imageCache.get(pt);if(!Gt){Gt=new Image;const ie=new Blob([It],{type:"image/svg+xml"});Gt.src=URL.createObjectURL(ie),Gt.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(pt,Gt)}Gt.complete&&Gt.naturalWidth>0?this.lumaCtx.drawImage(Gt,-wt/2,-Xt/2,wt,Xt):(this.applyPath(this.lumaCtx,tt.geometry,wt,Xt,Jt),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else this.applyPath(this.lumaCtx,tt.geometry,wt,Xt,Jt),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill();this.lumaCtx.restore();const rt=this.maskCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight),ct=this.lumaCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight).data,gt=rt.data;for(let It=0;It<gt.length;It+=4){const pt=ct[It],Gt=ct[It+1],ie=ct[It+2];let Zt=(.299*pt+.587*Gt+.114*ie)/255;Bt&&(Zt=1-Zt),gt[It+3]*=Zt}this.maskCtx.putImageData(rt,0,0)}else{this.maskCtx.save(),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),this.maskCtx.globalCompositeOperation=Bt?"destination-out":"destination-in",xt>0&&(this.maskCtx.filter=`blur(${xt}px)`),this.maskCtx.globalAlpha=Pt,this.applyAbsoluteTransform(this.maskCtx,tt.id,o);const wt=(Z==null?void 0:Z.width)||tt.geometry.width||0,Xt=(Z==null?void 0:Z.height)||tt.geometry.height||0,Jt=(Z==null?void 0:Z.corner_radius)??tt.corner_radius??0;if(((le=tt.geometry)==null?void 0:le.type)==="Text"){const rt=Z!=null&&Z.geometry?this.deepMerge(tt.geometry,Z.geometry):tt.geometry,ct=Z!=null&&Z.style?this.deepMerge(tt.style,Z.style):tt.style;this._renderText(this.maskCtx,tt,{...rt,width:wt,height:Xt,corner_radius:Jt},ct,Z,wt,Xt,!0)}else if(((Ct=tt.geometry)==null?void 0:Ct.type)==="Image"){const rt=tt.geometry.src;if(rt){let ct=this.imageCache.get(rt);ct||(ct=new Image,ct.src=rt,this.imageCache.set(rt,ct)),ct.complete&&ct.naturalWidth>0?this.maskCtx.drawImage(ct,-wt/2,-Xt/2,wt,Xt):(this.applyPath(this.maskCtx,tt.geometry,wt,Xt,Jt),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else if(((qt=tt.geometry)==null?void 0:qt.type)==="SVG"){const rt=tt.geometry.svgContent;if(rt){const ct=`__alphamask_${tt.id}`;let gt=this.imageCache.get(ct);if(!gt){gt=new Image;const It=new Blob([rt],{type:"image/svg+xml"});gt.src=URL.createObjectURL(It),gt.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(ct,gt)}gt.complete&>.naturalWidth>0?this.maskCtx.drawImage(gt,-wt/2,-Xt/2,wt,Xt):(this.applyPath(this.maskCtx,tt.geometry,wt,Xt,Jt),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else this.applyPath(this.maskCtx,tt.geometry,wt,Xt,Jt),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill();this.maskCtx.restore()}}),ee.save(),ee.setTransform(1,0,0,1,0,0);const z=s.maskBlendMode||s.blendMode;z&&z!=="Normal"&&(ee.globalCompositeOperation=z.toLowerCase()),ee.drawImage(this.maskBuffer,0,0),ee.restore(),ee.restore()}else t.restore()}}_renderText(t,s,o,e,i,n,a,r=!1,l=!1){var ut,ot,Et,Ft,Mt,Dt,Yt,Rt,ee;let h=o.text||"";if(o.textInputId&&!r){const H=this.inputs.get(o.textInputId);H!==void 0&&(h=String(H),i.geometry&&i.geometry.type==="Text"&&(i.geometry.text=h))}if(o.svgPath){const H=o.svgPath;t.save();const at=((ut=e==null?void 0:e.fill)==null?void 0:ut.color)||"#000000",Lt=((ot=e==null?void 0:e.fill)==null?void 0:ot.opacity)!==void 0?(Et=e==null?void 0:e.fill)==null?void 0:Et.opacity:1;t.fillStyle=at,t.globalAlpha*=Lt;const kt=new Path2D(H);t.fill(kt),t.restore();return}let c=h||"";o.enableSegments===!0&&o.segments&&Array.isArray(o.segments)&&(c=o.segments.map(H=>H&&H.text?H.text:"").join(""));const g=o.textCase||"none";g==="uppercase"?c=c.toUpperCase():g==="lowercase"?c=c.toLowerCase():g==="capitalize"&&(c=c.replace(/\b\w/g,H=>H.toUpperCase()));let f=((Ft=o.fontWeight)==null?void 0:Ft.toString())||"400",d=o.fontStyle||"normal";f.toLowerCase().includes("italic")&&(d="italic",f=f.replace(/italic/gi,"").trim()||"400");const p=this.mapFontWeight(f),m=Math.max(1,o.fontSize||32);let y=o.fontFamily||"Inter";const v=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];v.forEach(H=>{const at=new RegExp(`[\\s-]${H}$`,"i");at.test(y)&&(y=y.replace(at,"").trim())});const S=`${o.smallCaps===!0?"small-caps ":""}${d} ${p} ${m}px "${y}", sans-serif`;t.font=S;const w=o.textVerticalAlign||"top";t.textBaseline="top";const I=o.textAlign||"left";t.textAlign=I;let M=0;if(typeof o.letterSpacing=="number")M=o.letterSpacing;else if(typeof o.letterSpacing=="object"&&o.letterSpacing.value!==void 0){const H=o.letterSpacing;M=H.unit==="PERCENT"?H.value/100*m:H.value}t.letterSpacing!==void 0&&(t.letterSpacing=`${M}px`);const P=o.kerning||"auto",T=o.kerningValue||0;P==="manual"&&T!==0&&(t.letterSpacing=`${M+T}px`);const $=o.paragraphSpacing||0;let k=o.lineHeight??1.2;typeof k=="string"&&(k=parseFloat(k)),k>5&&m>0&&(k=k/m);const E=(k||1.2)*m,F=o.isPointText===!0||!o.width||o.width<=0,O=((Mt=o.padding)==null?void 0:Mt.left)||((Dt=o.padding)==null?void 0:Dt.right)||0,A=F?1e5:o.width&&o.width>0?Math.ceil(o.width)-O*2:1e5;o.autoHeight;const W=De({text:c,fontFamily:y,fontSize:m,fontWeight:p,fontStyle:d,lineHeight:k,width:A,letterSpacing:M,paragraphSpacing:$,paragraphIndent:o.paragraphIndent||0,segments:o.segments,enableSegments:o.enableSegments,textCase:g,hyphenation:o.hyphenation,composer:o.composer,balanceRaggedLines:o.balanceRaggedLines}),x=W.lines||[],B=W.maxFontSize||m,N=this.fontLeadingFactors[y]??.5,Q=(E-m)*N;let _=W.height,L=n,U=a;if(L===0||U===0||L>=1e5){let H=0,at=0;const Lt=W.fullText||c;(x||[]).forEach(kt=>{const St=kt.text||"",Vt=t.measureText(St).width+(St.length>0?(St.length-1)*M:0);Vt>H&&(H=Vt),at+=St.length,at<Lt.length&&(Lt[at]===`
|
|
23
|
+
`||Lt[at]==="\r")&&(at++,Lt[at-1]==="\r"&&Lt[at]===`
|
|
24
|
+
`&&at++)}),(L===0||L>=1e5)&&(L=H),U===0&&(U=_||0)}let q=-_/2;a>0&&a>_&&(w==="top"?q=-a/2:w==="middle"||w==="center"?q=-_/2:w==="bottom"&&(q=a/2-_)),q+=Q;let et=null,ft=0;if(o.pathId&&this.artboard){const H=this.artboard.objects.find(at=>at.id===o.pathId);if(H&&H.type==="Shape"&&((Yt=H.geometry)==null?void 0:Yt.type)==="Path"){const at=this.objectStates.get(H.id),Lt=at!=null&&at.geometry?this.deepMerge(H.geometry,at.geometry):H.geometry,kt=(at==null?void 0:at.scale_x)!==void 0?(H.width||0)*at.scale_x:H.width||0,St=(at==null?void 0:at.scale_y)!==void 0?(H.height||0)*at.scale_y:H.height||0;et={geo:Lt,obj:H,w:kt,h:St},ft=this.getPerimeter(Lt,kt,St)}}const vt=(H,at)=>{var kt,St;if(M===0&&(!o.enableSegments||!((kt=o.segments)!=null&&kt.length)))return t.measureText(H).width;let Lt=0;for(let Vt=0;Vt<H.length;Vt++){const jt=at+Vt;let te=0;if(o.enableSegments===!0&&((St=o.segments)==null?void 0:St.length)>0){let Kt=0,Ht=null;for(const ae of o.segments){if(jt<Kt+(ae.text||"").length){Ht=ae;break}Kt+=(ae.text||"").length}if(Ht){t.save();let ae=Ht.fontFamily||o.fontFamily||"Inter";const nt=this.mapFontWeight((Ht.fontWeight||o.fontWeight||"400").toString()),ht=Ht.fontStyle||d,z=Ht.fontSize||m;t.font=`${ht} ${nt} ${z}px "${ae}", sans-serif`,te=t.measureText(H[Vt]).width,t.restore()}else te=t.measureText(H[Vt]).width}else te=t.measureText(H[Vt]).width;Lt+=te+M}return Lt-(H.length>0?M:0)},lt=(H,at,Lt,kt,St)=>{var nt,ht;const jt=(St===0||c[St-1]===`
|
|
25
|
+
`||c[St-1]==="\r")&&o.paragraphIndent?o.paragraphIndent:0,te=(!r||l)&&(s.behaviors||[]).some(z=>z.enabled&&(z.type.toString().includes("Text")||["Typewriter","Scramble","Wave","Bounce","GlitchText","Reveal3D","RevealSlide","RevealBlur"].includes(z.type))),Kt=!o.pathId&&!te&&(o.enableSegments!==!0||!o.segments||o.segments.length===0),Ht=o.baselineShift||0,ae=Lt+Ht;if(Kt)t.font=S,kt?t.strokeText(H,at+jt,ae):t.fillText(H,at+jt,ae);else{const z=vt(H,St);let Y=at+jt;I==="center"?Y-=z/2:I==="right"&&(Y-=z);const tt=St+H.length>=c.length||c[St+H.length]===`
|
|
26
|
+
`||c[St+H.length]==="\r";let Z=0,xt=0;const Bt=o.justifyMinWordSpacing,Pt=o.justifyMaxWordSpacing;if(I==="justify"&&!tt&&z>0&&!o.pathId){const At=F?z:A-O*2+0,le=Math.max(0,At-z);for(let Ct=0;Ct<H.length;Ct++)H[Ct]===" "&&xt++;if(xt>0){const Ct=t.measureText(" ").width;let qt=Bt||Ct*.5,wt=Pt||Ct*2.5;Z=Math.max(0,Math.min(le/xt,wt-qt))}}let Ut=o.pathOffset||0;o.pathId&&ft>0&&et&&(I==="center"?Ut+=ft/2-z/2:I==="right"&&(Ut+=ft-z));let Tt=Y;const R=r&&!l?[]:((nt=s.behaviors)==null?void 0:nt.filter(At=>[X.Typewriter,X.Scramble,X.Wave,X.Bounce,X.GlitchText,X.TextTrail,X.Reveal3D,X.RevealSlide,X.RevealBlur,X.TextLiquid,X.TextVortex,X.TextExplosion,X.TextRain,X.TextGravity,X.TextElastic,X.TextMatrix,X.TextNeon,X.TextGlitch3D,X.TextDissolve,X.TextOrganic,X.TextBreathe,X.TextFloral,X.TextSmoke,X.TextVariable,X.TextMagnet,X.TextSpin,X.TextZing,X.TextPerspective,X.TextMirror].includes(At.type)&&At.enabled))||[];for(let At=0;At<H.length;At++){let le=H[At];const Ct=St+At;let qt=0,wt=0,Xt=1,Jt=1,rt=0,ct=1,gt=le;R.forEach(it=>{const j=it.settings||{},dt=j.strength||1,$t=Date.now();if(it.type===X.Typewriter)this.currentTime*(j.speed||1)-Ct*(j.stagger||.05)<0&&(ct=0);else if(it.type===X.Scramble)Math.max(0,Math.min(1,this.currentTime/(j.duration||1.5))-Ct*.02)<1&&Math.random()<.3&&(gt="$%#@!*&"[Math.floor(Math.random()*7)]);else if(it.type===X.Wave)wt+=Math.sin(this.currentTime*5*(j.speed||1)+Ct*(j.frequency||1))*(j.amplitude||20)*dt;else if(it.type===X.Bounce){const J=Math.max(0,this.currentTime%2-Ct*(j.stagger||.1));J<1&&(wt-=Math.abs(Math.sin(J*Math.PI))*(j.height||50)*dt)}else if(it.type===X.TextTrail){const J=this.pointerHistory[Math.max(0,this.pointerHistory.length-1-Ct*(j.delay||5))];J&&(qt+=(J.x-(i.x+Tt))*dt*.2,wt+=(J.y-(i.y+Lt+wt))*dt*.2)}else if(it.type===X.Reveal3D){const J=Math.max(0,Math.min(1,this.currentTime*(j.speed||1)-Ct*(j.stagger||.1)));Xt*=J,Jt*=J,ct=J}else if(it.type===X.RevealSlide){const J=Math.max(0,Math.min(1,this.currentTime*1.5-Ct*.05)),yt=(1-J)*(j.distance||40)*dt,mt=j.direction||"up";mt==="up"?wt-=yt:mt==="down"?wt+=yt:mt==="left"?qt-=yt:mt==="right"&&(qt+=yt),ct=J}else if(it.type===X.RevealBlur){const J=Math.max(0,Math.min(1,this.currentTime*1.2-Ct*.1));ct=J,qt+=(1-J)*5}else if(it.type===X.TextLiquid){const J=Math.max(0,Math.sin($t*.001*(j.speed||1)+Ct*.5));wt+=J*(j.amplitude||10)*dt,Jt*=1+J*.2}else if(it.type===X.TextVortex){const J=$t*.002*(j.speed||1)+Ct*.2,yt=(1-(Math.sin($t*.001)*.5+.5))*(j.radius||50);qt+=Math.cos(J)*yt*dt,wt+=Math.sin(J)*yt*dt}else if(it.type===X.TextExplosion){const J=j.force||1,yt=this.currentTime%2;if(yt<1){const mt=(Ct/H.length-.5)*Math.PI*2,pe=yt*100*J;qt+=Math.cos(mt)*pe*dt,wt+=Math.sin(mt)*pe*dt,ct=1-yt}}else if(it.type===X.TextRain){const J=j.speed||1,yt=j.height||100,mt=($t*.001*J+Ct*.1)%1;wt-=(1-mt)*yt*dt,ct=mt>.1?1:mt*10}else if(it.type===X.TextGravity){const J=j.gravity||9.8,yt=this.currentTime%3/3,mt=.5*J*Math.pow(yt*10,2);mt<100?wt+=mt*dt:wt+=100*dt}else if(it.type===X.TextMatrix){const J=j.speed||1;if(Math.random()<.1*J){const mt="0123456789ABCDEF!@#$%^&*";gt=mt[Math.floor(Math.random()*mt.length)]}ct=.3+(Math.sin($t*.01*J+Ct)+1)/2*.7}else if(it.type===X.TextNeon){const J=Math.random()>.95?.5:1;ct=(.7+(Math.sin($t*.005)+1)/2*.3)*J}else if(it.type===X.TextDissolve)Math.sin(Ct*1.5+$t*.002*(j.speed||1))>.5&&(ct=0);else if(it.type===X.TextOrganic){const J=j.speed||1,yt=j.amplitude||10;qt+=Math.sin($t*.002*J+Ct)*yt*dt,wt+=Math.cos($t*.0015*J+Ct*.7)*yt*dt}else if(it.type===X.TextBreathe){const yt=1+(Math.sin($t*.003+Ct*.2)+1)/2*.2*dt;Xt*=yt,Jt*=yt}else if(it.type===X.TextSpin){const J=j.speed||1;rt+=$t*.01*J+Ct}else if(it.type===X.TextMagnet){const J=this.pointerHistory[this.pointerHistory.length-1];if(J){const yt=J.x-(i.x+Tt),mt=J.y-(i.y+Lt);rt=Math.atan2(mt,yt)}}else if(it.type===X.TextPerspective){const J=H.length/2,yt=(Ct-J)/J,mt=1-Math.abs(yt)*.3*dt;Xt*=mt,Jt*=mt,qt+=yt*20*dt}else if(it.type===X.TextMirror)ct*=.8;else if(it.type===X.TextFloral){const J=j.speed||1,yt=j.stagger||.1,mt=($t*.001*J+Ct*yt)%2;mt<1&&(Xt*=mt,Jt*=mt,rt+=mt*Math.PI)}else if(it.type===X.TextSmoke){const J=j.speed||1,yt=j.height||50,mt=($t*5e-4*J+Ct*.2)%1;wt-=mt*yt*dt,qt+=Math.sin($t*.002+Ct)*5*dt,ct=1-mt}else if(it.type===X.TextVariable){const J=j.speed||1,yt=j.intensity||1.5,mt=(Math.sin($t*.004*J+Ct*.3)+1)/2;Xt*=1+mt*(yt-1)*dt}else if(it.type===X.TextZing){const J=j.speed||2,yt=j.distance||100,mt=($t*.002*J+Ct*.05)%1;qt+=(1-mt)*yt*dt,ct=mt}else if(it.type===X.TextElastic){const J=j.stiffness||.2,yt=j.damping||.1,mt=Math.sin($t*.01)*Math.exp(-$t*.001*yt);Jt*=1+mt*J*dt}else if(it.type===X.TextGlitch3D){const J=j.intensity||5;Math.random()<.2&&(qt+=(Math.random()-.5)*J,wt+=(Math.random()-.5)*J,ct=.8)}else if(it.type===X.GlitchText){const J=j.intensity||5;Math.random()<.1&&(qt+=(Math.random()-.5)*J,wt+=(Math.random()-.5)*J,Math.random()<.05&&(ct=.5))}});let It=null,pt=o.textDecoration||"none",Gt=m;if(o.enableSegments===!0&&((ht=o.segments)==null?void 0:ht.length)>0){let it=0,j=null;for(const dt of o.segments){if(Ct<it+(dt.text||"").length){j=dt;break}it+=(dt.text||"").length}if(j){let dt=j.fontFamily||o.fontFamily||"Inter";v.forEach(yt=>{const mt=new RegExp(`[\\s-]${yt}$`,"i");mt.test(dt)&&(dt=dt.replace(mt,"").trim())});const $t=this.mapFontWeight((j.fontWeight||o.fontWeight||"400").toString()),J=j.fontStyle||d;Gt=j.fontSize||m,t.font=`${J} ${$t} ${Gt}px "${dt}", sans-serif`,j.fill&&(It=j.fill),j.textDecoration&&(pt=j.textDecoration),Gt<B&&(wt+=(B-Gt)*.85)}}else t.font=S;const ie=t.globalAlpha;t.globalAlpha*=ct,t.save();const Zt=t.measureText(gt).width;if(et&&ft>0){const it=Tt-Y+Zt/2,dt=(Ut+it)/ft,$t=this.getPointOnPath(et.geo,et.w,et.h,Math.abs(dt%1)),J=$t.angle,yt=Lt+wt+(o.pathOffsetY||0),mt=o.pathSide==="right"?-1:1,pe=Math.cos(J+Math.PI/2)*yt*mt,Ce=Math.sin(J+Math.PI/2)*yt*mt;t.translate($t.x+pe+qt,$t.y+Ce),t.rotate(J+rt+(mt===-1?Math.PI:0))}else t.translate(Tt+qt+Zt/2,Lt+wt),rt!==0&&t.rotate(rt);if(t.scale(Xt,Jt),It&&!r&&!l){const it=this.createCanvasFill(t,It,L,U);t.fillStyle=it||It.color||"#000000"}else if(!r&&!l){const it=this.createCanvasFill(t,e.fill,L,U);t.fillStyle=it||e.fill.color||"#000000"}if(ct>0)if(r||l){const it=l?"#000000":this.createCanvasFill(t,e.fill,L,U);t.fillStyle=it||e.fill.color||"#ffffff",t.fillText(gt,-Zt/2,0)}else kt?t.strokeText(gt,-Zt/2,0):t.fillText(gt,-Zt/2,0);pt!=="none"&&!r&&this.drawTextDecoration(t,pt,0,0,Zt,Gt),t.restore(),t.globalAlpha=ie,I==="justify"&&Z>0&>===" "&&!tt?Tt+=Zt+M+Z:Tt+=Zt+M}}};if(r){let H=0,at=q;(x||[]).forEach(Lt=>{const kt=Lt.text||"",St=c.indexOf(kt,H);St!==-1&&(H=St);let Vt=-L/2;I==="center"?Vt=0:I==="right"&&(Vt=L/2),lt(kt,Vt,at,!1,H),H+=kt.length,at+=E})}else if(l){let H=0,at=q;(x||[]).forEach(Lt=>{const kt=Lt.text||"";let St=-L/2;I==="center"?St=0:I==="right"&&(St=L/2),lt(kt,St,at,!1,H),H+=kt.length,H<c.length&&(c[H]===`
|
|
27
|
+
`||c[H]==="\r")&&(H++,c[H-1]==="\r"&&c[H]===`
|
|
28
|
+
`&&H++),at+=E})}else{if(e.fill){const at=t.globalAlpha,Lt=this.createCanvasFill(t,e.fill,L,U);t.fillStyle=Lt||e.fill.color||"#000000",t.globalAlpha=at*this.normalizeOpacity(e.fill.opacity??100);const kt=W.fullText||(o.enableSegments?(o.segments||[]).map(jt=>{let te=jt.text||"";const Kt=jt.textCase||o.textCase||"none";return Kt==="uppercase"?te.toUpperCase():Kt==="lowercase"?te.toLowerCase():Kt==="capitalize"?te.replace(/\b\w/g,Ht=>Ht.toUpperCase()):te}).join(""):c);let St=0,Vt=q;(x||[]).forEach(jt=>{const te=jt.text||"";let Kt=-L/2;I==="center"?Kt=0:I==="right"&&(Kt=L/2),lt(te,Kt,Vt,!1,St),St+=te.length,Vt+=E,St<kt.length&&(kt[St]===`
|
|
29
|
+
`||kt[St]==="\r")&&($>0&&(Vt+=$),St++,kt[St-1]==="\r"&&kt[St]===`
|
|
30
|
+
`&&St++)}),t.globalAlpha=at}const H=o.paragraphRule;if(H&&(((Rt=H.top)==null?void 0:Rt.width)>0||((ee=H.bottom)==null?void 0:ee.width)>0)){let at=0;(x||[]).forEach((Lt,kt)=>{var jt,te;const Vt=at===0||at<c.length&&(c[at]===`
|
|
31
|
+
`||c[at]==="\r");if(Vt&&kt>0&&at++,Vt){if(((jt=H.top)==null?void 0:jt.width)>0){const Kt=q+kt*E-H.top.offset;t.strokeStyle=H.top.color||"#000000",t.lineWidth=H.top.width,t.beginPath();const Ht=-n/2+E*.2;t.moveTo(Ht,Kt),t.lineTo(n/2-E*.2,Kt),t.stroke()}if(((te=H.bottom)==null?void 0:te.width)>0){const Kt=q+(kt+1)*E-H.bottom.offset;t.strokeStyle=H.bottom.color||"#000000",t.lineWidth=H.bottom.width,t.beginPath();const Ht=-n/2+E*.2;t.moveTo(Ht,Kt),t.lineTo(n/2-E*.2,Kt),t.stroke()}}at+=(Lt.text||"").length})}if(e.stroke&&e.stroke.width>0){const at=t.globalAlpha;e.fill&&e.fill.type!=="None"&&e.fill.isEnabled!==!1&&e.fill.opacity!==0&&e.fill.color!=="transparent"&&e.fill.color!=="rgba(0,0,0,0)"&&(t.shadowColor="transparent",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0),t.strokeStyle=e.stroke.color,t.lineWidth=e.stroke.width,t.globalAlpha=at*this.normalizeOpacity(e.stroke.opacity??100);let kt=0,St=q;(x||[]).forEach(Vt=>{let jt=-L/2;I==="center"?jt=0:I==="right"&&(jt=L/2),lt(Vt.text,jt,St,!0,kt),kt+=(Vt.text||"").length,St+=E,kt<c.length&&(c[kt]===`
|
|
32
|
+
`||c[kt]==="\r")&&($>0&&(St+=$),kt++,c[kt-1]==="\r"&&c[kt]===`
|
|
33
|
+
`&&kt++)}),t.globalAlpha=at}}}applyStrokeAlignment(t,s,o,e,i,n){if(!s.stroke||s.stroke.width<=0||s.stroke.isEnabled===!1)return;const a=s.stroke,r=a.width,l=(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 y=this.createCanvasFill(t,a.fill,e,i);y?t.strokeStyle=y:t.strokeStyle=a.color||"#000000"}else t.strokeStyle=a.color||"#000000";const c=t.globalAlpha;t.globalAlpha=c*this.normalizeOpacity(a.opacity??100),t.lineWidth=r,t.lineCap=a.lineCap||"round",t.lineJoin=a.lineJoin||"round",a.miterLimit!==void 0&&(t.miterLimit=a.miterLimit);const g=a.trimStart??0,f=a.trimEnd??1,d=a.trimOffset??0,p=a.dashOffset??0,m=a.dashArray||[];if(g!==0||f!==1||d!==0){const y=this.getPerimeter(o,e,i);if(y>0){const v=Math.max(0,Math.min(1,g)),b=Math.max(0,Math.min(1,f));if(v<b){const C=y*(b-v),S=y-C,w=-(y*(v+d%1));t.setLineDash([C,S]),t.lineDashOffset=w+p*y}else if(v===b)t.setLineDash([0,y]);else{const C=y*(1-v+b),S=y-C,w=-(y*v);t.setLineDash([C,S]),t.lineDashOffset=w+p*y}}}else m.length>0&&(t.setLineDash(m),t.lineDashOffset=p);(o==null?void 0:o.type)==="Line"||e===0||i===0?(this.applyPath(t,o,e,i,n),t.stroke()):l==="inside"?(t.lineWidth=r*2,t.save(),this.applyPath(t,o,e,i,n),t.clip(),t.stroke(),t.restore()):l==="outside"?(t.lineWidth=r*2,this.applyPath(t,o,e,i,n),t.stroke(),t.save(),t.globalCompositeOperation="destination-out",this.applyPath(t,o,e,i,n),t.fill(),t.restore()):(t.lineWidth=r,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 l=n/360*r;if(a>0){const h=Math.PI*(3*(e*a+i*a)-Math.sqrt((3*e*a+i*a)*(e*a+3*i*a)));l+=n/360*h,n<360&&(l+=2*Math.sqrt((e-e*a)**2+(i-i*a)**2))}else n<360&&(l+=2*Math.max(e,i));return isNaN(l)?0:l}case"Line":return t.length||Math.sqrt(s*s+o*o);case"Triangle":return s+Math.sqrt((s/2)**2+o**2)*2;case"Polygon":{const e=t.sides||3,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 l=e[r];if(l.moveTo){n=l.x,a=l.y;continue}const h=n,c=a,g=e[r-1].out_x,f=e[r-1].out_y;if(g!==void 0||l.in_x!==void 0?i+=this.getBezierLength(h,c,g??h,f??c,l.in_x??l.x,l.in_y??l.y,l.x,l.y):i+=Math.sqrt((l.x-h)**2+(l.y-c)**2),n=l.x,a=l.y,l.closePath||r===e.length-1&&(t.is_closed||t.isClosed)){const d=n,p=a,m=[...e.slice(0,r+1)].reverse().find(I=>I.moveTo)||e[0],y=m.x,v=m.y,b=e[r].out_x,C=e[r].out_y,S=m.in_x,w=m.in_y;b!==void 0||S!==void 0?i+=this.getBezierLength(d,p,b??d,C??p,S??y,w??v,y,v):i+=Math.sqrt((y-d)**2+(v-p)**2)}}return i}default:return(s+o)*2}}getBezierLength(t,s,o,e,i,n,a,r,l=10){let h=0,c=t,g=s;for(let f=1;f<=l;f++){const d=f/l,p=1-d,m=d*d,y=p*p,v=y*p,b=m*d,C=v*t+3*y*d*o+3*p*m*i+b*a,S=v*s+3*y*d*e+3*p*m*n+b*r,w=C-c,I=S-g;h+=Math.sqrt(w*w+I*I),c=C,g=S}return h}getBezierTAtLength(t,s,o,e,i,n,a,r,l,h=20){if(t<=0)return 0;let c=0,g=s,f=o;for(let d=1;d<=h;d++){const p=d/h,m=1-p,y=p*p,v=m*m,b=v*m,C=y*p,S=b*s+3*v*p*e+3*m*y*n+C*r,w=b*o+3*v*p*i+3*m*y*a+C*l,I=S-g,M=w-f,P=Math.sqrt(I*I+M*M);if(c+P>=t){const T=t-c,$=P===0?0:T/P;return(d-1+$)/h}c+=P,g=S,f=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,l=-1/0;i.forEach(v=>{typeof v.x=="number"&&typeof v.y=="number"&&(n=Math.min(n,v.x),a=Math.max(a,v.x),r=Math.min(r,v.y),l=Math.max(l,v.y),v.out_x!==void 0&&(n=Math.min(n,v.out_x),a=Math.max(a,v.out_x)),v.out_y!==void 0&&(r=Math.min(r,v.out_y),l=Math.max(l,v.out_y)),v.in_x!==void 0&&(n=Math.min(n,v.in_x),a=Math.max(a,v.in_x)),v.in_y!==void 0&&(r=Math.min(r,v.in_y),l=Math.max(l,v.in_y)))});const h=(n+a)/2,c=(r+l)/2,f=this.getPerimeter(t,s,o)*e;let d=0;const p=[];let m=i[0],y=i[0];for(let v=1;v<i.length;v++){const b=i[v];if(b.moveTo){m=b,y=b;continue}p.push({p0:m,p1:b}),(b.closePath||v===i.length-1&&(t.is_closed||t.isClosed))&&p.push({p0:b,p1:y}),m=b}for(const v of p){const b=v.p0,C=v.p1;let S=0;const w=b.out_x!==void 0||C.in_x!==void 0;if(w?S=this.getBezierLength(b.x,b.y,b.out_x??b.x,b.out_y??b.y,C.in_x??C.x,C.in_y??C.y,C.x,C.y):S=Math.sqrt((C.x-b.x)**2+(C.y-b.y)**2),d+S>=f||v===p[p.length-1]){let I=0;if(w)return I=this.getBezierTAtLength(f-d,b.x,b.y,b.out_x??b.x,b.out_y??b.y,C.in_x??C.x,C.in_y??C.y,C.x,C.y,20),this.getBezierPointAndAngle(I,b,C,h,c);{I=S===0?0:(f-d)/S;const M=b.x+(C.x-b.x)*I-h,P=b.y+(C.y-b.y)*I-c,T=Math.atan2(C.y-b.y,C.x-b.x);return{x:M,y:P,angle:T}}}d+=S}}else if(t.type==="Ellipse"){const i=Math.abs(s)/2,n=Math.abs(o)/2,a=t.sweepAngle??360,l=((t.startAngle??0)+a*e)*Math.PI/180,h=i*Math.cos(l),c=n*Math.sin(l),g=-i*Math.sin(l),f=n*Math.cos(l),d=Math.atan2(f,g);return{x:h,y:c,angle:d}}else if((t==null?void 0:t.type)==="Rectangle"){const i=Math.abs(s),n=Math.abs(o),r=(i+n)*2*e;let l=0,h=0,c=0;return r<i?(l=-i/2+r,h=-n/2,c=0):r<i+n?(l=i/2,h=-n/2+(r-i),c=Math.PI/2):r<2*i+n?(l=i/2-(r-(i+n)),h=n/2,c=Math.PI):(l=-i/2,h=n/2-(r-(2*i+n)),c=-Math.PI/2),{x:l,y:h,angle:c}}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,l=s.out_y??s.y,h=o.in_x??o.x,c=o.in_y??o.y,g=o.x,f=o.y,d=1-t,p=t*t,m=d*d,y=m*d,v=p*t,b=y*n+3*m*t*r+3*d*p*h+v*g-e,C=y*a+3*m*t*l+3*d*p*c+v*f-i,S=3*m*(r-n)+6*d*t*(h-r)+3*p*(g-h),w=3*m*(l-a)+6*d*t*(c-l)+3*p*(f-c),I=Math.atan2(w,S);return{x:b,y:C,angle:I}}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){const o=this.objectStates.get(s);if(!o)return;t.translate(o.x,o.y),t.rotate(o.rotation*Math.PI/180);const e=(o.scale_x??1)*(o.flip_x===!0?-1:1),i=(o.scale_y??1)*(o.flip_y===!0?-1:1);t.scale(e,i)}applyArtEffectOverlay(t,s,o,e,i,n){var f,d,p,m,y;const a=this.objectStates.get(s.id),r=((f=a==null?void 0:a.style)==null?void 0:f.artEffect)||s.artEffect||((d=s.style)==null?void 0:d.artEffect);if(!r||!r.enabled)return;const l=r.type,h=r.intensity??.5,c=r.speed??1,g=r.scale??10;if(l==="acid_gradient"||l==="acid_rave"||l==="shimmer"||l==="glint_overlay"||l==="halftone"||l==="noise"||l==="scanlines"||l==="chromatic_aberration"||l==="pixelate"||l==="glitch"||l==="fold_overlay"||l==="crumple_overlay"){if(t.save(),this.applyPath(t,o,e,i,n),t.clip(),l==="shimmer"){const b=this.currentTime*c%2/2,C=t.createLinearGradient(-e,-i,e,i);C.addColorStop(Math.max(0,b-.2),"rgba(255,255,255,0)"),C.addColorStop(b,`rgba(255,255,255,${h*.8})`),C.addColorStop(Math.min(1,b+.2),"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(l==="glint_overlay"){let C=((this._lastPointerPos||{x:0}).x-(((p=s.transform)==null?void 0:p.x)??0)+300)/600;C=Math.max(-.2,Math.min(1.2,C));const S=t.createLinearGradient(-e,-i,e,i);S.addColorStop(Math.max(0,C-.15),"rgba(255,255,255,0)"),S.addColorStop(Math.max(0,Math.min(1,C)),`rgba(255,255,255,${h})`),S.addColorStop(Math.min(1,C+.15),"rgba(255,255,255,0)"),t.fillStyle=S,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i),t.globalCompositeOperation="source-over"}else if(l==="fold_overlay"){const v=this._lastPointerPos||{x:0,y:0},b=v.x-(((m=s.transform)==null?void 0:m.x)??0),C=v.y-(((y=s.transform)==null?void 0:y.y)??0),S=t.createLinearGradient(b>0?-e/2:e/2,C>0?-i/2:i/2,b>0?e/2:-e/2,C>0?i/2:-i/2);S.addColorStop(0,`rgba(0,0,0,${h*.6})`),S.addColorStop(.4,"rgba(0,0,0,0)"),S.addColorStop(.5,`rgba(255,255,255,${h*.4})`),S.addColorStop(1,`rgba(0,0,0,${h*.2})`),t.fillStyle=S,t.globalCompositeOperation="overlay",t.fillRect(-e/2,-i/2,e,i),t.globalCompositeOperation="source-over",t.beginPath(),b>0&&C>0?(t.moveTo(e/2-40,i/2),t.lineTo(e/2,i/2-40),t.lineTo(e/2-40,i/2-40)):b<0&&C>0?(t.moveTo(-e/2+40,i/2),t.lineTo(-e/2,i/2-40),t.lineTo(-e/2+40,i/2-40)):b>0&&C<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=b>0?-2:2,t.shadowOffsetY=C>0?-2:2,t.fill()}else if(l==="crumple_overlay"){const v=Math.floor(e/g),b=document.createElement("canvas");b.width=v,b.height=Math.floor(i/g);const C=b.getContext("2d"),S=C.createImageData(b.width,b.height);for(let w=0;w<S.data.length;w+=4){const I=Math.random()>.95?150:255;S.data[w]=I,S.data[w+1]=I,S.data[w+2]=I,S.data[w+3]=255*h}C.putImageData(S,0,0),t.globalCompositeOperation="multiply",t.imageSmoothingEnabled=!1,t.drawImage(b,-e/2,-i/2,e,i)}else if(l==="acid_gradient"||l==="acid_rave"){const v=this.currentTime*c,b=r.color1,C=r.color2,S=t.createLinearGradient(-e/2,-i/2,e/2,i/2);if(b&&C){const w=v*60%360;S.addColorStop(0,this._shiftHue(b,w,h*.7)),S.addColorStop(1,this._shiftHue(C,(w+180)%360,h*.7))}else{const w=v*100%360,I=(w+180)%360;S.addColorStop(0,`hsla(${w}, 80%, 50%, ${h*.5})`),S.addColorStop(1,`hsla(${I}, 80%, 50%, ${h*.5})`)}t.fillStyle=S,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i)}else if(l==="halftone"){const v=Math.max(2,g*(1-h*.8)),b=document.createElement("canvas");b.width=v,b.height=v;const C=b.getContext("2d");if(C){C.fillStyle="black",C.beginPath(),C.arc(v/2,v/2,v/2*h,0,Math.PI*2),C.fill();const S=t.createPattern(b,"repeat");S&&(t.globalAlpha=.3*h,t.fillStyle=S,t.fillRect(-e/2,-i/2,e,i))}}else if(l==="noise"){const v=Math.floor(e*i*h*.02);t.globalAlpha=.4*h;for(let b=0;b<v;b++){const C=Math.random()>.5?255:0;t.fillStyle=`rgba(${C}, ${C}, ${C}, ${.5+Math.random()*.5})`,t.fillRect(-e/2+Math.random()*e,-i/2+Math.random()*i,2,2)}}else if(l==="scanlines"){t.globalAlpha=.2*h,t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1;for(let v=-i/2;v<i/2;v+=4)t.beginPath(),t.moveTo(-e/2,v),t.lineTo(e/2,v),t.stroke()}else if(l==="chromatic_aberration"){const v=5*h;t.globalCompositeOperation="screen",t.globalAlpha=.5,t.fillStyle="cyan",t.fillRect(-e/2-v,-i/2,e,i),t.fillStyle="magenta",t.fillRect(-e/2+v,-i/2,e,i)}else if(l==="pixelate"){const v=Math.max(2,Math.round(g*(1-h*.5))),b=document.createElement("canvas"),C=Math.max(1,Math.ceil(e/v)),S=Math.max(1,Math.ceil(i/v));b.width=C,b.height=S;const w=b.getContext("2d");if(w){w.imageSmoothingEnabled=!1;const I=t.getTransform(),M=I.e-e/2,P=I.f-i/2;w.drawImage(t.canvas,M,P,e,i,0,0,C,S),t.imageSmoothingEnabled=!1,t.drawImage(b,0,0,C,S,-e/2,-i/2,e,i),t.imageSmoothingEnabled=!0}}else if(l==="glitch"){const v=this.currentTime*c,b=r.chaosAmount??.2,C=Math.max(3,Math.floor(8*h)),S=h*e*.15;t.globalCompositeOperation="screen",t.globalAlpha=h*.4;const w=S*.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 I=i/C;for(let M=0;M<C;M++){const P=Math.sin(M*127.1+v*311.7*c)*43758.5,T=P-Math.floor(P);if(T>1-b){const $=(T-(1-b))/b*S*(Math.random()>.5?1:-1),k=-i/2+M*I,E=t.getTransform(),F=E.e-e/2+$,O=E.f+k;t.save(),t.beginPath(),t.rect(-e/2,k,e,I),t.clip(),t.globalAlpha=.8,t.drawImage(t.canvas,F,O,e,I,-e/2+$,k,e,I),t.restore()}}}t.restore()}}_shiftHue(t,s,o){let e=0,i=0,n=0;if(t.startsWith("#")){const f=t.replace("#","");e=parseInt(f.substring(0,2),16)/255,i=parseInt(f.substring(2,4),16)/255,n=parseInt(f.substring(4,6),16)/255}const a=Math.max(e,i,n),r=Math.min(e,i,n);let l=0,h=0,c=(a+r)/2;if(a!==r){const f=a-r;switch(h=c>.5?f/(2-a-r):f/(a+r),a){case e:l=((i-n)/f+(i<n?6:0))/6;break;case i:l=((n-e)/f+2)/6;break;case n:l=((e-i)/f+4)/6;break}}return`hsla(${(((l*360+s)%360+360)%360).toFixed(0)}, ${(h*100).toFixed(0)}%, ${(c*100).toFixed(0)}%, ${o})`}applyBackgroundBlurGlass(t,s,o,e,i,n){const a=n.radius??10,r=n.color??"rgba(255,255,255,0.2)",l=n.opacity??.5,h=n.noise??0;t.save(),this.applyPath(t,s,o,e,i),t.clip();const c=t.getTransform(),g=c.e-o/2,f=c.f-e/2;try{const p=document.createElement("canvas");p.width=Math.max(1,Math.ceil(o)),p.height=Math.max(1,Math.ceil(e));const m=p.getContext("2d");if(m){m.drawImage(t.canvas,g,f,o,e,0,0,o,e),m.filter=`blur(${a}px)`;const y=document.createElement("canvas");y.width=p.width,y.height=p.height;const v=y.getContext("2d");v.filter=`blur(${a}px)`,v.drawImage(p,0,0),t.globalCompositeOperation="source-over",t.globalAlpha=1,t.drawImage(y,-o/2,-e/2,o,e)}}catch{}t.globalCompositeOperation="source-over",t.globalAlpha=l,t.fillStyle=r,t.fillRect(-o/2,-e/2,o,e),t.globalAlpha=1,t.globalCompositeOperation="source-atop";const d=t.createLinearGradient(-o/2,-e/2,o/2,e/2);if(d.addColorStop(0,"rgba(255,255,255,0.12)"),d.addColorStop(.3,"rgba(255,255,255,0.04)"),d.addColorStop(.5,"rgba(255,255,255,0.0)"),d.addColorStop(1,"rgba(255,255,255,0.0)"),t.fillStyle=d,t.fillRect(-o/2,-e/2,o,e),h>0){if(t.globalAlpha=h/100,!this._noiseTileCanvas){const m=document.createElement("canvas");m.width=64,m.height=64;const y=m.getContext("2d"),v=y.createImageData(64,64),b=v.data;for(let C=0;C<b.length;C+=4){const S=Math.floor(Math.random()*255);b[C]=S,b[C+1]=S,b[C+2]=S,b[C+3]=18}y.putImageData(v,0,0),this._noiseTileCanvas=m}const p=t.createPattern(this._noiseTileCanvas,"repeat");p&&(t.fillStyle=p,t.fillRect(-o/2,-e/2,o,e))}t.restore(),t.save(),t.globalAlpha=1,t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1.5,this.applyPath(t,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"){const{startAngle:n=0,sweepAngle:a=360,ratio:r=0}=s,l=o/2,h=e/2,c=n*Math.PI/180,g=a*Math.PI/180,f=c+g;a>=360&&r<=0?t.ellipse(0,0,l,h,0,0,Math.PI*2):(t.ellipse(0,0,l,h,0,c,f,!1),r>0?t.ellipse(0,0,l*r,h*r,0,f,c,!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 l=r*2*Math.PI/n-Math.PI/2,h=a*Math.cos(l),c=a*Math.sin(l);r===0?t.moveTo(h,c):t.lineTo(h,c)}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 l=0;l<n*2;l++){const h=l*Math.PI/n-Math.PI/2,c=l%2===0?a:r,g=c*Math.cos(h),f=c*Math.sin(h);l===0?t.moveTo(g,f):t.lineTo(g,f)}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%10===0&&console.log("[Engine] Tracing Path:",s.points.length,"points");let n=1/0,a=-1/0,r=1/0,l=-1/0;if(s.points.forEach(g=>{typeof g.x=="number"&&typeof g.y=="number"&&(n=Math.min(n,g.x),a=Math.max(a,g.x),r=Math.min(r,g.y),l=Math.max(l,g.y),g.out_x!==void 0&&(n=Math.min(n,g.out_x),a=Math.max(a,g.out_x)),g.out_y!==void 0&&(r=Math.min(r,g.out_y),l=Math.max(l,g.out_y)),g.in_x!==void 0&&(n=Math.min(n,g.in_x),a=Math.max(a,g.in_x)),g.in_y!==void 0&&(r=Math.min(r,g.in_y),l=Math.max(l,g.in_y)))}),n===1/0)return;const h=(n+a)/2,c=(r+l)/2;if(isNaN(h)||isNaN(c)){console.warn("[Engine] Invalid path center:",h,c);return}s.points.forEach((g,f)=>{if(f===0||g.moveTo)t.moveTo(g.x-h,g.y-c);else{const d=s.points[f-1];if(!d)return;const p=(d.out_x??d.x)-h,m=(d.out_y??d.y)-c,y=(g.in_x??g.x)-h,v=(g.in_y??g.y)-c;isNaN(p)||isNaN(y)||isNaN(g.x)?t.lineTo(g.x-h,g.y-c):t.bezierCurveTo(p,m,y,v,g.x-h,g.y-c)}if(g.closePath||f===s.points.length-1&&(s.is_closed||s.isClosed)){const d=[...s.points.slice(0,f+1)].reverse().find(p=>p.moveTo)||s.points[0];d&&(g.out_x!==void 0||d.in_x!==void 0)&&t.bezierCurveTo((g.out_x??g.x)-h,(g.out_y??g.y)-c,(d.in_x??d.x)-h,(d.in_y??d.y)-c,d.x-h,d.y-c),t.closePath()}})}else if(s.points&&Array.isArray(s.points)){let n=1/0,a=-1/0,r=1/0,l=-1/0;s.points.forEach(g=>{n=Math.min(n,g.x),a=Math.max(a,g.x),r=Math.min(r,g.y),l=Math.max(l,g.y)});const h=(n+a)/2,c=(r+l)/2;s.points.forEach((g,f)=>{if(f===0)t.moveTo(g.x-h,g.y-c);else{const d=s.points[f-1];d.out_x!==void 0||g.in_x!==void 0?t.bezierCurveTo((d.out_x??d.x)-h,(d.out_y??d.y)-c,(g.in_x??g.x)-h,(g.in_y??g.y)-c,g.x-h,g.y-c):t.lineTo(g.x-h,g.y-c)}(g.closePath||f===s.points.length-1&&(s.is_closed||s.isClosed))&&t.closePath()})}}}renderInputBox(t,s){var ft,vt;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((ft=s.geometry)==null?void 0:ft.width)||250,n=((vt=s.geometry)==null?void 0:vt.height)||45,a=this.focusedId===s.id,r=this.lastHoveredObjectId===s.id,l=e.previewState||"default",h=l!=="default"?l:a?"focused":r?"hovered":"default",c=e.label||{visible:!0,text:"Label"},g=e.helperText||{visible:!1,text:"Helper text"},f=e.leftIcon||{visible:!1},d=e.rightIcon||{visible:!1},p=e.multiline===!0,m=e.corner_radius??8,y=e.corners||{tl:m,tr:m,bl:m,br:m},v=[y.tl,y.tr,y.br,y.bl];let b=e.backgroundColor||"rgba(31, 41, 55, 1)",C=e.borderColor||"rgba(55, 65, 81, 1)",S=e.borderWidth??1.5,w=e.color||"#ffffff",I=e.placeholderColor||"rgba(156, 163, 175, 1)",M=e.fontSize||14;const P=`${h}Style`,T=e[P];T?(T.backgroundColor!==void 0&&(b=T.backgroundColor),T.borderColor!==void 0&&(C=T.borderColor),T.borderWidth!==void 0&&(S=T.borderWidth),T.color!==void 0&&(w=T.color),T.placeholderColor!==void 0&&(I=T.placeholderColor),T.fontSize!==void 0&&(M=T.fontSize)):h==="focused"?(C=e.focusBorderColor||"rgba(59, 130, 246, 1)",S=Math.max(S,2)):h==="hovered"||h==="hover"?(C=e.hoverBorderColor||C,b=e.hoverBackgroundColor||b):h==="disabled"?(b=e.disabledBackgroundColor||"rgba(31, 41, 55, 0.6)",C=e.disabledBorderColor||"rgba(55, 65, 81, 0.4)"):h==="error"&&(C="rgba(239, 68, 68, 1)",S=Math.max(S,2)),t.beginPath(),this.drawRoundRect(t,-i/2,-n/2,i,n,v);const $=this.createCanvasFill(t,b,i,n);if($&&(t.fillStyle=$,t.fill()),S>0){const lt=this.createCanvasFill(t,C,i,n);if(lt&&(t.strokeStyle=lt,t.lineWidth=S,t.stroke()),h==="focused"||h==="focus"){t.save(),t.beginPath();const ut=v.map(ot=>ot+2);this.drawRoundRect(t,-i/2-2,-n/2-2,i+4,n+4,ut),t.strokeStyle="rgba(59, 130, 246, 0.3)",t.lineWidth=2,t.stroke(),t.restore()}}const k=(lt,ut)=>{if(!lt.visible||!lt.svgPath)return;const ot=lt.size||14,Et=lt.offset??16,Ft=lt.color||"#ffffff",Mt=ut?-(i/2)+Et:i/2-Et,Dt=lt.svgPath;if(t.save(),t.translate(Mt,0),!Dt.startsWith("<svg")){const Yt=new Path2D(Dt),Rt=ot/24;t.scale(Rt,Rt),t.translate(-12,-12),t.fillStyle=Ft,t.fill(Yt)}t.restore()};k(f,!0),k(d,!1);const E=e.text||"",F=e.placeholder||"Enter text...",O=!E,A=E||F,W=O?I:w,x=M,B=e.fontFamily||"Inter",N=e.fontWeight||400;t.font=`${N} ${x}px "${B}", sans-serif`,t.fillStyle=W,t.textAlign="left",t.textBaseline=p?"top":"middle";const Q=e.inputPadding??16,_=f.visible?(f.offset??16)+(f.size||14)/2+8:Q,L=d.visible?(d.offset??16)+(d.size||14)/2+8:Q,U=-(i/2)+_,q=i-_-L,et=e.inputType==="password"?"•".repeat(A.length):A;if(t.save(),t.beginPath(),t.rect(U-2,-n/2+4,q+4,n-8),t.clip(),p){const lt=et.split(`
|
|
34
|
+
`);let ut=-n/2+Q;const ot=x*1.2;let Et=0;lt.forEach((Ft,Mt)=>{const Dt=Ft.split(" ");let Yt="";for(let Rt=0;Rt<Dt.length;Rt++){const ee=Yt+Dt[Rt]+" ";t.measureText(ee).width>q&&Rt>0?(t.fillText(Yt,U,ut),Yt=Dt[Rt]+" ",ut+=ot):Yt=ee}t.fillText(Yt,U,ut),Et=t.measureText(Yt).width,Mt<lt.length-1&&(ut+=ot,Et=0)}),a&&!O&&Math.floor(performance.now()/500)%2===0&&t.fillRect(U+Et,ut,1.5,x)}else{const ut=t.measureText(et).width;let ot=0;if(ut>q&&(ot=ut-q),t.fillText(et,U-ot,0),a&&!O&&Math.floor(performance.now()/500)%2===0){const Ft=U+ut-ot;t.fillRect(Ft,-(x/2),1.5,x)}}if(t.restore(),c.visible!==!1){const lt=c.text||"Label",ut=c.fontSize||12,ot=c.color||"rgba(156, 163, 175, 1)",Et=c.offset??8;t.font=`600 ${ut}px "${B}", sans-serif`,t.fillStyle=ot,t.textAlign="left",t.textBaseline="bottom";const Ft=-(i/2),Mt=-(n/2)-Et;t.fillText(lt,Ft,Mt)}if(g.visible===!0){const lt=g.text||"Helper text",ut=g.fontSize||11,ot=h==="error"?"rgba(239, 68, 68, 1)":g.color||"rgba(156, 163, 175, 1)",Et=g.offset??6;t.font=`400 ${ut}px "${B}", sans-serif`,t.fillStyle=ot,t.textAlign="left",t.textBaseline="top";const Ft=-(i/2),Mt=n/2+Et;t.fillText(lt,Ft,Mt)}}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,h=(i.max??100)-r,c=h===0?0:(a-r)/h,g=i.trackHeight||4,f=i.trackRoundedness??2,d=i.trackShape??"Rectangle",p=i.trackPath||"",m=i.accentColor||"#3b82f6",y=i.inactiveColor||"#374151",v=i.thumbShape||"Ellipse",b=i.thumbWidth??16,C=i.thumbHeight??16,S=i.thumbRoundedness??0,w=i.thumbColor||"#ffffff",I=i.thumbPath||"",M=i.thumbIcon||"",P=i.showValueTooltip??!1,T=i.tooltipBgColor||"#333333",$=i.tooltipColor||"#ffffff",k=i.tooltipOffsetX??0,E=i.tooltipOffsetY??-25,F=(q,et,ft,vt,lt,ut,ot)=>{if((q==="Custom"||q==="Icon")&&ot)try{const Et=new Path2D(ot);if(t.save(),t.translate(et,ft),q==="Icon"){const Ft=Math.min(vt,lt)/24;t.scale(Ft,Ft),t.translate(-12,-12)}t.fill(Et),t.restore();return}catch(Et){console.error("Error drawing slider shape in engine:",Et)}if(t.beginPath(),q==="Ellipse")t.ellipse(et,ft,vt/2,lt/2,0,0,Math.PI*2);else if(q==="Rectangle")this.drawRoundRect(t,et-vt/2,ft-lt/2,vt,lt,ut);else if(q==="Triangle")t.moveTo(et,ft-lt/2),t.lineTo(et+vt/2,ft+lt/2),t.lineTo(et-vt/2,ft+lt/2),t.closePath();else if(q==="Diamond")t.moveTo(et,ft-lt/2),t.lineTo(et+vt/2,ft),t.lineTo(et,ft+lt/2),t.lineTo(et-vt/2,ft),t.closePath();else if(q==="Polygon"){const Et=s.geometry.sides||3,Ft=s.geometry.radius||Math.min(vt,lt)/2;for(let Mt=0;Mt<Et;Mt++){const Dt=Mt*2*Math.PI/Et-Math.PI/2,Yt=et+Ft*Math.cos(Dt),Rt=ft+Ft*Math.sin(Dt);Mt===0?t.moveTo(Yt,Rt):t.lineTo(Yt,Rt)}t.closePath()}else if(q==="Star"){const Ft=Math.min(vt,lt)/2,Mt=Ft/2;for(let Dt=0;Dt<5*2;Dt++){const Yt=Dt%2===0?Ft:Mt,Rt=Dt*Math.PI/5-Math.PI/2;t.lineTo(et+Yt*Math.cos(Rt),ft+Yt*Math.sin(Rt))}t.closePath()}else q==="Line"&&(t.moveTo(et-vt/2,ft),t.lineTo(et+vt/2,ft));t.fill()},O=this.createCanvasFill(t,y,n,g);O&&(t.fillStyle=O,t.strokeStyle=O),d==="Line"?(t.lineWidth=g,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(n/2,0),t.stroke()):F(d,0,0,n,g,f,p);const A=n-b,W=-n/2+b/2+c*A,x=W- -n/2;if(x>0){const q=this.createCanvasFill(t,m,n,g);q&&(t.fillStyle=q,t.strokeStyle=q),d==="Line"?(t.lineWidth=g,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(W,0),t.stroke()):d==="Rectangle"&&(t.beginPath(),this.drawRoundRect(t,-n/2,-g/2,x,g,f),t.fill())}t.save(),t.translate(W,0);const B=t.getTransform(),N=Math.sqrt(B.a*B.a+B.b*B.b)||1;t.shadowColor="rgba(0,0,0,0.2)",t.shadowBlur=4*N,t.shadowOffsetY=1*N;const Q=this.createCanvasFill(t,w,b,C);if(Q&&(t.fillStyle=Q),F(v,0,0,b,C,S,v==="Icon"?M:I),t.restore(),P){t.save(),t.translate(W+k,E);const q=Math.round(a).toString();t.font="10px Inter, sans-serif";const et=t.measureText(q),ft=6,vt=4,lt=et.width+ft*2,ut=14+vt;t.beginPath(),this.drawRoundRect(t,-lt/2,-ut/2,lt,ut,4),t.fillStyle=T,t.fill(),t.fillStyle=$,t.textAlign="center",t.textBaseline="middle",t.fillText(q,0,0),t.restore()}const _=i.label||{},L=i.helperText||{},U=i.fontFamily||"Inter";if(_.visible!==!1){const q=_.text||"Label",et=_.fontSize||12,ft=_.color||"rgba(156, 163, 175, 1)",vt=_.offset??8;t.font=`600 ${et}px "${U}", sans-serif`,t.fillStyle=ft,t.textAlign="left",t.textBaseline="bottom";const lt=-(n/2),ut=-(g/2)-vt;t.fillText(q,lt,ut)}if(L.visible===!0){const q=L.text||"Helper text",et=L.fontSize||11,ft=L.color||"rgba(156, 163, 175, 1)",vt=L.offset??6;t.font=`400 ${et}px "${U}", sans-serif`,t.fillStyle=ft,t.textAlign="left",t.textBaseline="top";const lt=-(n/2),ut=g/2+vt;t.fillText(q,lt,ut)}}renderDropdown(t,s){var E;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,l=e.corner_radius??6,h=e.disabled||e.previewState==="disabled",c=this.lastHoveredObjectId===s.id||e.previewState==="hover",g=(e.isOpen||e.previewState==="active")&&!h;let f=e.backgroundColor,d=e.borderColor,p=e.color||"#333333";h?(f=e.disabledBackgroundColor||"#f3f4f6",d=e.disabledBorderColor||"#e5e7eb",p=e.disabledColor||"#9ca3af"):g?(f=e.activeBackgroundColor||f,d=e.activeBorderColor||d,p=e.activeColor||p):c&&(f=e.hoverBackgroundColor||f,d=e.hoverBorderColor||d,p=e.hoverColor||p),f||(f="#ffffff"),d||(d="#e5e7eb");const m=t.globalAlpha;t.globalAlpha=m*(e.opacity??1),this.drawRoundRect(t,a,r,i,n,l),t.fillStyle=this.createCanvasFill(t,typeof f=="string"?{type:"Solid",color:f}:f,i,n)||"#ffffff",t.fill();const y=e.borderWidth??1;y>0&&(t.strokeStyle=this.createCanvasFill(t,typeof d=="string"?{type:"Solid",color:d}:d,i,n)||"#e5e7eb",t.lineWidth=y,t.stroke());const v=12,b=e.chevronType||"chevron",C=e.chevronSize||16,S=(g?e.openIconColor:e.closedIconColor)||e.chevronColor||"#6b7280";if(b!=="none"){const F=a+i-v-C/2;t.save(),t.translate(F,0);const O=g?e.openIconAngle??180:e.closedIconAngle??0;if(t.rotate(O*Math.PI/180),t.strokeStyle=S,t.fillStyle=S,t.lineWidth=1.5,t.lineCap="round",t.lineJoin="round",b==="chevron")t.beginPath(),t.moveTo(-C/2,-C*.2),t.lineTo(0,C*.2),t.lineTo(C/2,-C*.2),t.stroke();else if(b==="custom"||b==="path"){const A=g&&e.openIconPath||e.closedIconPath;if(A){const W=new Path2D(A);t.save();const x=C/24;t.scale(x,x),t.translate(-12,-12),t.fill(W),t.restore()}}t.restore()}const w=e.selectedOption||e.placeholder||"Select...",I=e.fontSize||14,M=e.fontWeight||400,P=e.fontFamily||"Inter, sans-serif";t.font=`${M} ${I}px ${P}`;const T=h?e.disabledColor||"#9ca3af":!e.selectedOption&&e.placeholder?"#9ca3af":p;t.fillStyle=this.createCanvasFill(t,typeof T=="string"?{type:"Solid",color:T}:T,i,n)||"#333333",t.textAlign="left",t.textBaseline="middle";const $=b==="none"?0:C+8,k=i-v*2-$;if(t.save(),t.beginPath(),t.rect(a+v,r,k,n),t.clip(),t.fillText(w,a+v,0),t.restore(),g&&!h){const F=r+n+4,O=e.optionsList||[],A=e.itemHeight||32,W=e.listPadding??4,x=O.length*A+W*2,B=e.listCornerRadius??l;t.save();const N=e.listShadow||{},Q=t.getTransform(),_=Math.sqrt(Q.a*Q.a+Q.b*Q.b)||1;t.shadowColor=typeof N.color=="string"?N.color:((E=N.color)==null?void 0:E.color)||"rgba(0,0,0,0.15)",t.shadowBlur=(N.blur??12)*_,t.shadowOffsetY=(N.offsetY??6)*_,t.shadowOffsetX=(N.offsetX??0)*_,t.beginPath(),this.drawRoundRect(t,a,F,i,x,B),t.fillStyle=this.createCanvasFill(t,typeof e.listBackgroundColor=="string"?{type:"Solid",color:e.listBackgroundColor}:e.listBackgroundColor||{type:"Solid",color:"#ffffff"},i,x)||"#ffffff",t.fill();const L=e.listBorderWidth??1;L>0&&(t.shadowColor="transparent",t.strokeStyle=this.createCanvasFill(t,typeof e.listBorderColor=="string"?{type:"Solid",color:e.listBorderColor}:e.listBorderColor||{type:"Solid",color:d},i,x)||"#e5e7eb",t.lineWidth=L,t.stroke()),t.restore();const U=e.itemFontSize||I,q=e.itemFontFamily||P;t.font=`${M} ${U}px ${q}`,O.forEach((et,ft)=>{const vt=F+W+ft*A;if(et===e.selectedOption)t.fillStyle=this.createCanvasFill(t,typeof e.itemSelectedBackgroundColor=="string"?{type:"Solid",color:e.itemSelectedBackgroundColor}:e.itemSelectedBackgroundColor||{type:"Solid",color:"#f3f4f6"},i,A)||"#f3f4f6",t.fillRect(a+L,vt,i-L*2,A),t.fillStyle=e.itemSelectedColor||e.accentColor||p||"#374151";else if(t.fillStyle=e.listTextColor||p||"#333333",this.activeDropdownId===s.id&&this._lastPointerPos){const ut=this._lastPointerPos.y-(F+W),ot=Math.floor(ut/A);ft===ot&&(t.fillStyle=this.createCanvasFill(t,typeof e.itemHoverBackgroundColor=="string"?{type:"Solid",color:e.itemHoverBackgroundColor}:e.itemHoverBackgroundColor||{type:"Solid",color:"#f9fafb"},i,A)||"#f9fafb",t.fillRect(a+L,vt,i-L*2,A),t.fillStyle=e.itemHoverColor||p)}t.fillText(et,a+v,vt+A/2)})}t.globalAlpha=m}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,l=this.activeObjectId===s.id,h=e.label||{},c=e.hoverStyle||{},g=e.activeStyle||{},f=e.icon||{enabled:!1};let d=e.backgroundColor||"#3b82f6",p=h.color||"#ffffff",m=h.text||"Button",y=i.cornerRadius??8,v=e.borderColor||"transparent",b=e.borderWidth||0,C=1;l&&g?(d=g.backgroundColor||d,p=g.color||p,m=g.text||m,C=g.scale??.95,y=g.cornerRadius??y):r&&c&&(d=c.backgroundColor||d,p=c.color||p,m=c.text||m,C=c.scale??1,y=c.cornerRadius??y,v=c.borderColor||v);const S=-n/2,w=-a/2;t.save(),t.scale(C,C),t.beginPath(),this.drawRoundRect(t,S,w,n,a,y);const I=this.createCanvasFill(t,d,n,a);I&&(t.fillStyle=I,t.fill()),(b>0||r&&c.borderColor)&&(t.strokeStyle=v,t.lineWidth=b||(r?1:0),t.stroke());const M=h.fontSize||14,P=h.fontFamily||"Inter",T=h.fontWeight||600;t.font=`${T} ${M}px "${P}", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle=p,t.textAlign="center",t.textBaseline="middle";let $=0;if(f.enabled&&f.svgPath){const k=M*1.1,E=f.gap||8,F=t.measureText(m),A=-(F.width+k+E)/2,W=f.position==="left"?A+k/2:A+F.width+E+k/2;$=f.position==="left"?A+k+E+F.width/2:A+F.width/2,t.save(),t.translate(W,0);const x=new Path2D(f.svgPath),B=k/24;t.scale(B,B),t.translate(-12,-12),t.fillStyle=p,t.fill(x),t.restore()}t.fillText(m,$,0),t.restore()}renderToggleButton(t,s){var m,y;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=e.checked??!1,n=((m=s.geometry)==null?void 0:m.width)||120,a=((y=s.geometry)==null?void 0:y.height)||40,r=-n/2,l=-a/2,h=e.corner_radius??8,c=e.label||{},g=i?e.accentColor||"#3b82f6":e.inactiveColor||"#374151",f=i?e.activeTextColor||"#ffffff":e.inactiveTextColor||"#9ca3af";t.save(),t.beginPath(),this.drawRoundRect(t,r,l,n,a,h),t.fillStyle=g,t.fill();const d=c.fontSize||14,p=c.fontFamily||"Inter";t.font=`${c.fontWeight||600} ${d}px "${p}", sans-serif`,t.fillStyle=f,t.textAlign="center",t.textBaseline="middle",t.fillText(c.text||"Toggle",0,0),t.restore()}renderToggle(t,s){var B,N,Q,_,L,U,q,et,ft,vt,lt,ut;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((B=s.geometry)==null?void 0:B.width)||52,n=((N=s.geometry)==null?void 0:N.height)||30,a=-i/2,r=-n/2,l=e.checked??!1,h=e.cornerRadius??e.corner_radius??n/2,c=e.toggleStyle||{},g=c.backgroundColor||e.activeColor||"#10b981",f=c.borderColor||e.borderColor||"transparent",d=c.borderWidth??e.borderWidth??0,p=c.knobColor||e.knobColor||"#ffffff",m=l?g:e.inactiveColor||"#374151",y=l?f:e.borderColor||"transparent",v=l?d:e.borderWidth??0,b=l?p:e.knobColor||"#ffffff";e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,i,n,h);const C=this.createCanvasFill(t,m,i,n);if(C&&(t.fillStyle=C,t.fill()),v>0){t.lineWidth=v;const ot=this.createCanvasFill(t,y,i,n);ot&&(t.strokeStyle=ot,t.stroke())}const S=2,w=n-S*2,I=w/2,M=a+S,P=a+i-S-w,T=l?P:M,$=r+S;t.beginPath(),t.arc(T+I,$+I,I,0,Math.PI*2);const k=this.createCanvasFill(t,b,w,w);k&&(t.fillStyle=k,t.fill()),e.disabled&&(t.globalAlpha*=2);let E=!1,F=!1;const O=(l?(Q=c.leftLabel)==null?void 0:Q.text:null)||((_=e.leftLabel)==null?void 0:_.text)||"",A=(l?(L=c.leftLabel)==null?void 0:L.color:null)||((U=e.leftLabel)==null?void 0:U.color)||"#f3f4f6";if((q=e.leftLabel)!=null&&q.enabled&&O){const ot=e.leftLabel;t.font=`${ot.fontWeight||400} ${ot.fontSize||12}px "${ot.fontFamily||"Inter"}", sans-serif`,t.fillStyle=A,t.textBaseline="middle",t.textAlign="right",t.fillText(O,a-(ot.gap||8),0),E=!0}const W=(l?(et=c.rightLabel)==null?void 0:et.text:null)||((ft=e.rightLabel)==null?void 0:ft.text)||"",x=(l?(vt=c.rightLabel)==null?void 0:vt.color:null)||((lt=e.rightLabel)==null?void 0:lt.color)||"#f3f4f6";if((ut=e.rightLabel)!=null&&ut.enabled&&W){const ot=e.rightLabel;t.font=`${ot.fontWeight||400} ${ot.fontSize||12}px "${ot.fontFamily||"Inter"}", sans-serif`,t.fillStyle=x,t.textBaseline="middle",t.textAlign="left",t.fillText(W,a+i+(ot.gap||8),0),F=!0}if(!E&&!F&&e.label&&e.label.text){const ot=e.label,Et=ot.fontSize||14,Ft=ot.fontWeight||400,Mt=ot.fontFamily||"Inter";t.font=`${Ft} ${Et}px "${Mt}", sans-serif`,t.fillStyle=ot.color||"#f3f4f6",t.textBaseline="middle";const Dt=ot.gap||10;let Yt=0,Rt=0;ot.position==="left"?(t.textAlign="right",Yt=a-Dt,Rt=0):ot.position==="right"?(t.textAlign="left",Yt=a+i+Dt,Rt=0):ot.position==="top"?(t.textAlign="center",Yt=0,Rt=r-Dt,t.textBaseline="bottom"):ot.position==="bottom"?(t.textAlign="center",Yt=0,Rt=r+n+Dt,t.textBaseline="top"):(t.textAlign="left",Yt=a+i+Dt,Rt=0),t.fillText(ot.text,Yt,Rt)}}renderCheckbox(t,s){var C,S;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)||20,n=((S=s.geometry)==null?void 0:S.height)||20,a=-i/2,r=-n/2,l=e.cornerRadius??4,h=e.checked??!1,c=e.activeColor||"#3b82f6",g=e.inactiveColor||"transparent",f=e.checkColor||"#ffffff",d=e.borderColor||"#4b5563",p=e.borderWidth??2,m=h?c:g,y=h?"transparent":d,v=h?0:p;e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,i,n,l);const b=this.createCanvasFill(t,m,i,n);if(b&&(t.fillStyle=b,t.fill()),v>0){t.lineWidth=v;const w=this.createCanvasFill(t,y,i,n);w&&(t.strokeStyle=w,t.stroke())}else if(h){t.lineWidth=1;const w=this.createCanvasFill(t,c,i,n);w&&(t.strokeStyle=w,t.stroke())}if(h){t.save(),t.beginPath();const w=this.createCanvasFill(t,f,i,n);t.strokeStyle=w||f,t.lineWidth=Math.max(2,i*.12),t.lineCap="round",t.lineJoin="round";const I=a+i*.25,M=r+n*.5,P=a+i*.45,T=r+n*.7,$=a+i*.75,k=r+n*.25;t.moveTo(I,M),t.lineTo(P,T),t.lineTo($,k),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 I=w.gap||8;let M=0,P=0;w.position==="left"?(t.textAlign="right",M=a-I,P=0):w.position==="right"?(t.textAlign="left",M=a+i+I,P=0):w.position==="top"?(t.textAlign="center",M=0,P=r-I,t.textBaseline="bottom"):w.position==="bottom"&&(t.textAlign="center",M=0,P=r+n+I,t.textBaseline="top"),t.fillText(w.text,M,P),t.restore()}}renderRadioGroup(t,s){var S,w;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((S=s.geometry)==null?void 0:S.width)||180,n=((w=s.geometry)==null?void 0:w.height)||100,a=-i/2,r=-n/2,l=e.selectedValue,h=e.optionsList||["Option 1","Option 2","Option 3"],c=e.orientation||"vertical",g=e.itemGap!==void 0?e.itemGap:16,f=e.activeColor||"#3b82f6",d=e.inactiveColor||"#4b5563",p=e.textColor||"#ffffff",m=e.fontSize||14,y=e.fontFamily||"Inter",v=e.fontWeight||400;e.disabled&&(t.globalAlpha*=.5);const b=8,C=b*2;if(t.save(),t.font=`${v} ${m}px "${y}", sans-serif`,t.textBaseline="middle",t.textAlign="left",c==="vertical"){const I=Math.max(C,m)+g;h.forEach((M,P)=>{const T=r+P*I+b;t.beginPath(),t.arc(a+b,T,b,0,Math.PI*2);const $=l===M,k=this.createCanvasFill(t,f,C,C),E=this.createCanvasFill(t,d,C,C);$?(t.strokeStyle=k||f,t.lineWidth=2,t.stroke(),t.beginPath(),t.arc(a+b,T,b/2,0,Math.PI*2),t.fillStyle=k||f,t.fill()):(t.strokeStyle=E||d,t.lineWidth=1.5,t.stroke()),t.fillStyle=p,t.fillText(M,a+C+8,T)})}else{let I=a;h.forEach(M=>{const P=l===M,T=t.measureText(M).width;t.beginPath(),t.arc(I+b,0,b,0,Math.PI*2);const $=this.createCanvasFill(t,f,C,C),k=this.createCanvasFill(t,d,C,C);P?(t.strokeStyle=$||f,t.lineWidth=2,t.stroke(),t.beginPath(),t.arc(I+b,0,b/2,0,Math.PI*2),t.fillStyle=$||f,t.fill()):(t.strokeStyle=k||d,t.lineWidth=1.5,t.stroke()),t.fillStyle=p,t.fillText(M,I+C+6,0),I+=C+6+T+g})}if(t.restore(),e.disabled&&(t.globalAlpha*=2),e.label&&e.label.text){const I=e.label;t.save(),t.font=`${I.fontWeight||400} ${I.fontSize||14}px "${I.fontFamily||"Inter"}", sans-serif`,t.fillStyle=I.color||"#9ca3af",t.textBaseline="middle";const M=I.gap||8;let P=0,T=0;I.position==="left"?(t.textAlign="right",P=a-M,T=0):I.position==="right"?(t.textAlign="left",P=a+i+M,T=0):I.position==="top"?(t.textAlign="center",P=0,T=r-M,t.textBaseline="bottom"):I.position==="bottom"&&(t.textAlign="center",P=0,T=r+n+M,t.textBaseline="top"),t.fillText(I.text,P,T),t.restore()}}renderBarChart(t,s){var T,$;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i={width:((T=s.geometry)==null?void 0:T.width)||300,height:(($=s.geometry)==null?void 0:$.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,_getPreset:function(){return ss[this.stylePreset]||ss.default},_resolveColor:function(k,E){const F=this._getPreset();return["#6366f1","#f59e0b","#10b981","#3b82f6","#a855f7"].includes(k)?F.colors[E%F.colors.length]:typeof k=="string"?k:F.colors[E%F.colors.length]},_makeGradient:function(k,E,F,O,A,W){if(!this._getPreset().barGradient&&!this.barGradient)return E;const B=k.createLinearGradient(F,O,A,W);return B.addColorStop(0,E),B.addColorStop(1,E+"44"),B},_drawRoundedBar:function(k,E,F,O,A,W,x){if(W=Math.min(W,Math.min(Math.abs(O),Math.abs(A))/2),W<=0||O===0||A===0){k.rect(E,F,O,A);return}k.beginPath(),x?(k.moveTo(E,F+A),k.lineTo(E,F+W),k.quadraticCurveTo(E,F,E+W,F),k.lineTo(E+O-W,F),k.quadraticCurveTo(E+O,F,E+O,F+W),k.lineTo(E+O,F+A),k.lineTo(E,F+A)):(k.moveTo(E,F),k.lineTo(E+O-W,F),k.quadraticCurveTo(E+O,F,E+O,F+W),k.lineTo(E+O,F+A-W),k.quadraticCurveTo(E+O,F+A,E+O-W,F+A),k.lineTo(E,F+A),k.lineTo(E,F)),k.closePath()}},n=i.width,a=i.height,r=-n/2,l=-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 h=i._getPreset();let c=-1/0,g=1/0;const f=i.categories.length,d=i.datasets.length;if(i.chartType==="stacked")for(let k=0;k<f;k++){let E=0,F=0;i.datasets.forEach(O=>{const A=O.data[k]??0;A>=0?E+=A:F+=A}),E>c&&(c=E),F<g&&(g=F)}else i.datasets.forEach(k=>{k.data&&k.data.forEach(E=>{E>c&&(c=E),E<g&&(g=E)})});isFinite(c)||(c=10),isFinite(g)||(g=0),c=Math.max(c,0),g=Math.min(g,0);const p=c-g||10;t.save(),t.font=`${i.axisLabelFontSize}px Inter, sans-serif`;const m=i.showYLabels?t.measureText(c.toFixed(0)).width+14:10,y=i.showXLabels?i.axisLabelFontSize+12:8,b=(i.showLegend&&d>0?i.legendFontSize+10:0)+8,C=10,S=r+m,w=l+b,I=n-m-C,M=a-b-y;if(t.beginPath(),t.roundRect(r,l,n,a,10),t.fillStyle=h.cardBackground,t.fill(),t.strokeStyle=h.cardBorderColor,t.lineWidth=1,t.stroke(),i.showLegend&&d>0){t.font=`${i.legendFontSize}px Inter, sans-serif`,t.textBaseline="middle";const k=l+12;let E=S;i.datasets.forEach((F,O)=>{const A=i._resolveColor(F.color,O),W=F.label||`Series ${O+1}`,x=7;t.beginPath(),t.roundRect(E,k-x/2,x,x,2),t.fillStyle=A,t.fill(),t.fillStyle=h.legendColor,t.textAlign="left",t.fillText(W,E+x+4,k),E+=t.measureText(W).width+x+16})}const P=4;if(i.showGridLines){t.setLineDash([3,4]),t.lineWidth=1,t.strokeStyle=h.gridColor;for(let k=0;k<=P;k++){const E=w+k/P*M;t.beginPath(),t.moveTo(S,E),t.lineTo(S+I,E),t.stroke()}t.setLineDash([])}if(i.showYLabels){t.font=`${i.axisLabelFontSize}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="middle",t.fillStyle=h.axisLabelColor;for(let k=0;k<=P;k++){const E=c-k/P*p,F=w+k/P*M;t.fillText(E.toFixed(0),S-6,F)}}if(t.lineWidth=1,t.setLineDash([]),i.showXAxis&&(t.strokeStyle=i.xAxisColor,t.beginPath(),t.moveTo(S,w+M),t.lineTo(S+I,w+M),t.stroke()),i.showYAxis&&(t.strokeStyle=i.yAxisColor,t.beginPath(),t.moveTo(S,w),t.lineTo(S,w+M),t.stroke()),i.chartType==="stacked"){const k=I/f;for(let E=0;E<f;E++){const F=S+E*k+k/2;i.showXLabels&&(t.font=`${i.axisLabelFontSize}px Inter, sans-serif`,t.textAlign="center",t.textBaseline="top",t.fillStyle=h.axisLabelColor,t.fillText(i.categories[E]||"",F,w+M+5));let O=w+M;i.datasets.forEach((A,W)=>{const x=A.data[E]??0;if(x===0)return;const B=x/p*M,N=Math.min(i.barWidth*d+i.barGap,k-8),Q=F-N/2,_=O-B;O-=B;const L=i._resolveColor(A.color,W);t.beginPath(),t.fillStyle=i._makeGradient(t,L,Q,_,Q,_+B),i._drawRoundedBar(t,Q,_,N,B,W===d-1?i.barCornerRadius:0,!0),t.fill()})}}else{const k=I/f,E=d*i.barWidth+Math.max(0,(d-1)*i.barGap),F=w+M-(0-g)/p*M;for(let O=0;O<f;O++){const A=S+O*k+k/2;i.showXLabels&&(t.font=`${i.axisLabelFontSize}px Inter, sans-serif`,t.textAlign="center",t.textBaseline="top",t.fillStyle=h.axisLabelColor,t.fillText(i.categories[O]||"",A,w+M+5));const W=A-E/2;i.datasets.forEach((x,B)=>{const N=x.data[O]??0,Q=Math.abs(N/p*M);if(Q<1)return;const _=W+B*(i.barWidth+i.barGap),L=N>=0?F-Q:F,U=i._resolveColor(x.color,B);t.beginPath(),t.fillStyle=i._makeGradient(t,U,_,L,_,L+Q),i._drawRoundedBar(t,_,L,i.barWidth,Q,i.barCornerRadius,!0),t.fill(),i.showValueOnTop&&N!==0&&(t.font=`bold ${i.axisLabelFontSize}px Inter, sans-serif`,t.textAlign="center",t.textBaseline="bottom",t.fillStyle=U,t.fillText(N.toString(),_+i.barWidth/2,L-2))})}}t.restore()}renderPieChart(t,s){var m,y;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i={width:((m=s.geometry)==null?void 0:m.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 is[this.stylePreset]||is.default},_resolveSliceColor:function(v,b){const C=v.color,S=b,w=this._getPreset();return["#6366f1","#22d3ee","#f59e0b","#ec4899","#34d399","#a855f7","#f87171"].includes(C)?w.colors[S%w.colors.length]:typeof C=="string"?C:w.colors[S%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((v,b)=>v+(b.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 l=i._getPreset();t.save(),t.beginPath(),t.roundRect(-n/2,-a/2,n,a,10),t.fillStyle=l.cardBackground,t.fill(),t.strokeStyle=l.cardBorderColor,t.lineWidth=1,t.stroke();const h=i.showLegend?Math.ceil(i.slices.length/2):0,c=h>0?h*(i.legendFontSize+8)+10:0,g=a-c-16,f=Math.min(n-24,g)/2,d=0,p=-c/2;if(i.chartType==="rose"){const v=Math.max(...i.slices.map(S=>S.value||0)),b=Math.PI*2/i.slices.length,C=f>0?i.sliceGap/f:0;i.slices.forEach((S,w)=>{const I=S.value||0;if(I===0)return;const M=I/v*f,P=-Math.PI/2+w*b+C/2,T=P+b-C,$=i._resolveSliceColor(S,w);if(t.beginPath(),t.moveTo(d,p),t.arc(d,p,M,P,T),t.closePath(),t.fillStyle=$+"cc",t.fill(),t.strokeStyle=$,t.lineWidth=1.5,t.stroke(),i.showLabels){const k=P+(T-P)/2,E=d+M*.65*Math.cos(k),F=p+M*.65*Math.sin(k),O=Math.round(I/r*100);t.save(),t.font=`bold ${i.labelFontSize}px Inter, sans-serif`,t.fillStyle=l.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${O}%`,E,F),t.restore()}})}else{const v=i.chartType==="pie"?0:i.innerRadius,b=f*Math.max(0,v),C=f>0?i.sliceGap/f:0;let S=-Math.PI/2;if(i.slices.forEach((w,I)=>{const M=w.value||0;if(M===0){S+=M/r*Math.PI*2;return}const P=M/r*Math.PI*2,T=S+C/2,$=S+P-C/2;if($<=T){S+=P;return}const k=i._resolveSliceColor(w,I);if(t.beginPath(),t.fillStyle=k,b<=0?(t.moveTo(d,p),t.arc(d,p,f,T,$),t.lineTo(d,p)):(t.moveTo(d+f*Math.cos(T),p+f*Math.sin(T)),t.arc(d,p,f,T,$),t.arc(d,p,b,$,T,!0),t.closePath()),t.fill(),i.showLabels){const E=T+($-T)/2,F=b+(f-b)/2,O=d+F*Math.cos(E),A=p+F*Math.sin(E),W=Math.round(M/r*100);t.save(),t.font=`bold ${i.labelFontSize}px Inter, sans-serif`,t.fillStyle=l.labelColor,t.textAlign="center",t.textBaseline="middle",t.fillText(`${W}%`,O,A),t.restore()}S+=P}),i.chartType==="donut"&&i.showCenterText&&b>14){const w=Math.round(r),I=Math.min(Math.floor(b*.52),20),M=Math.min(Math.floor(b*.26),10);t.textAlign="center",t.textBaseline="middle",t.font=`bold ${I}px Inter, sans-serif`,t.fillStyle=l.centerTextColor,t.fillText(w.toString(),d,p-M*.5),i.centerLabel&&(t.font=`${M}px Inter, sans-serif`,t.fillStyle=l.centerLabelColor,t.fillText(i.centerLabel,d,p+I*.6))}}if(i.showLegend&&i.slices.length>0){t.font=`${i.legendFontSize}px Inter, sans-serif`;const v=2,b=n/v,C=i.legendFontSize+8,S=a/2-c+10,w=-n/2+10;i.slices.forEach((I,M)=>{const P=M%v,T=Math.floor(M/v),$=w+P*b,k=S+T*C,E=i._resolveSliceColor(I,M),F=7;t.beginPath(),t.roundRect($,k-F/2,F,F,2),t.fillStyle=E,t.fill(),t.textAlign="left",t.textBaseline="middle",t.fillStyle=l.legendColor;const O=Math.round((I.value||0)/r*100),A=`${I.label||"Item"} ${O}%`,W=b-F-20;let x=A;for(;t.measureText(x).width>W&&x.length>4;)x=x.slice(0,-4)+"…";t.fillText(x,$+F+4,k)})}t.restore()}getRadioGroupItemIndexAtPointer(t,s,o){var M,P;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:((M=t.geometry)==null?void 0:M.width)||180,r=i.height!==void 0?i.height:((P=t.geometry)==null?void 0:P.height)||100,l=e.orientation||"vertical",h=e.itemGap!==void 0?e.itemGap:16,c=e.fontSize||14,g=this.getWorldTransform(t.id),f=s-g.x,d=o-g.y,p=-g.rotation*(Math.PI/180),m=Math.cos(p),y=Math.sin(p),v=f*m-d*y,b=f*y+d*m,S=8*2,w=-a/2,I=-r/2;if(l==="vertical"){const T=Math.max(S,c)+h;for(let $=0;$<n.length;$++){const k=I+$*T;if(v>=w&&v<=w+a&&b>=k&&b<=k+T)return $}}else{let T=w;for(let $=0;$<n.length;$++){const E=n[$].length*8,F=S+6+E+h;if(v>=T&&v<=T+F&&b>=I&&b<=I+r)return $;T+=F}}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(p=>p.data&&p.data.length>=2)){t.save(),t.fillStyle="#6366f1",t.font="12px Inter, system-ui, sans-serif",t.textAlign="center",t.textBaseline="middle",t.fillText("NO DATA",0,0),t.restore();return}let n=1/0,a=-1/0,r=0;if(i.forEach(p=>{let m=p.data;if(p.isVarEnabled&&p.inputId){let y=this.inputs.get(p.inputId);if(y===void 0){const v=this.inputNameMap.get(p.inputId);v&&v.length>0&&(y=this.inputs.get(v[0]))}y&&Array.isArray(y)&&(m=y)}if(m&&m.length>0){const y=m.filter(v=>typeof v=="number"&&!isNaN(v));y.length>0&&(n=Math.min(n,...y),a=Math.max(a,...y),r=Math.max(r,m.length))}p._resolvedData=m}),r<2)return;const l=a-n,h=o/(r-1),c=p=>{const m=l===0?.5:(p-n)/l;return e/2-m*e},g=p=>p*h-o/2,f=s.axisColor||"#333333";if(s.showXAxis&&(t.beginPath(),t.strokeStyle=s.xAxisColor||f,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||f,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 p=0;p<r;p++){const m=g(p);t.fillText(`${p+1}`,m,e/2+5)}}if(s.showYLabels){t.textAlign="right",t.textBaseline="middle";const p=-o/2-5,m=(a+n)/2;t.fillText(a.toFixed(1),p,c(a)),t.fillText(m.toFixed(1),p,c(m)),t.fillText(n.toFixed(1),p,c(n))}const d=10;if(i.forEach(p=>{const m=p._resolvedData;if(!(!m||m.length<2)){if(p.showArea){if(t.beginPath(),t.moveTo(g(0),e/2),t.lineTo(g(0),c(m[0])),p.smoothing&&m.length>2)for(let v=0;v<m.length-1;v++){const b=m[v===0?v:v-1],C=m[v],S=m[v+1],w=m[v+1===m.length-1?v+1:v+2];for(let I=1;I<=d;I++){const M=I/d,P=this._catmullRom(b,C,S,w,M);t.lineTo(g(v+M),c(P))}}else for(let v=1;v<m.length;v++)t.lineTo(g(v),c(m[v]));t.lineTo(g(m.length-1),e/2),t.closePath();const y=t.globalAlpha;t.globalAlpha=y*(s.areaOpacity??.3),t.fillStyle=p.areaColor||"rgba(139, 92, 246, 0.2)",t.fill(),t.globalAlpha=y}if(t.beginPath(),t.strokeStyle=p.lineColor||"#3b82f6",t.lineWidth=p.lineWidth||2,t.lineJoin="round",t.lineCap="round",t.moveTo(g(0),c(m[0])),p.smoothing&&m.length>2)for(let y=0;y<m.length-1;y++){const v=m[y===0?y:y-1],b=m[y],C=m[y+1],S=m[y+1===m.length-1?y+1:y+2];for(let w=1;w<=d;w++){const I=w/d,M=this._catmullRom(v,b,C,S,I);t.lineTo(g(y+I),c(M))}}else for(let y=1;y<m.length;y++)t.lineTo(g(y),c(m[y]));t.stroke(),p.showPoints&&m.forEach((y,v)=>{const b=g(v),C=c(y);t.beginPath(),t.arc(b,C,(p.pointSize||6)/2,0,Math.PI*2),t.fillStyle=p.pointFill||"#ffffff",t.fill(),t.strokeStyle=p.pointStrokeColor||p.lineColor||"#3b82f6",t.lineWidth=p.pointStrokeWidth||1,t.stroke()})}}),s.showLegend&&i.length>0){const p=o/2-10;let m=-e/2+15;const y=s.legendFontSize||10,v=y+5;t.font=`${y}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="alphabetic",i.forEach(b=>{const S=b.label||"Series",w=t.measureText(S).width;t.beginPath(),t.rect(p-w-8-5,m-(8/2+2),8,8),t.fillStyle=b.lineColor||"#3b82f6",t.fill(),t.fillStyle=s.legendColor||"#333333",t.fillText(S,p,m),m+=v})}}_catmullRom(t,s,o,e,i){const n=(o-t)*.5,a=(e-s)*.5,r=i*i,l=i*r;return(2*s-2*o+n+a)*l+(-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,h=(((n=(i=this.artboard)==null?void 0:i.tokens)==null?void 0:n.colors)||{})[r]||r;return t.fillStyle=h,h}if((s.type==="LinearGradient"||s.type==="RadialGradient"||s.type==="AngularGradient"||s.type==="DiamondGradient")&&s.stops){const r=(l,h=100)=>{var C,S;const g=(((S=(C=this.artboard)==null?void 0:C.tokens)==null?void 0:S.colors)||{})[l]||l,f=this.normalizeOpacity(s.opacity??100),p=this.normalizeOpacity(h)*f;if(p>=1&&g.startsWith("#"))return g;const m=g.startsWith("#")?g.replace("#",""):"ffffff",y=parseInt(m.substring(0,2),16),v=parseInt(m.substring(2,4),16),b=parseInt(m.substring(4,6),16);return`rgba(${y}, ${v}, ${b}, ${p})`};if(s.type==="LinearGradient"){const l=(p,m,y)=>Array.isArray(p)?p[m]??(m===0?0:1):p&&typeof p=="object"?p[y]??(m===0?0:1):m===0?0:1,h=l(s.start,0,"x")*o-o/2,c=l(s.start,1,"y")*e-e/2,g=l(s.end,0,"x")*o-o/2,f=l(s.end,1,"y")*e-e/2,d=t.createLinearGradient(h,c,g,f);if(s.stops.forEach(p=>{const m=p.offset!==void 0?p.offset:p.pos!==void 0?p.pos:p.position!==void 0?p.position:0,y=r(p.color||"#000000",p.opacity??100);d.addColorStop(Math.max(0,Math.min(1,m)),y)}),s.gradientTransform&&d.setTransform){const[p,m,y,v,b,C]=s.gradientTransform;d.setTransform({a:p,b:m,c:y,d:v,e:b,f:C})}return d}else if(s.type==="RadialGradient"){const l=(d,p,m)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[m]??.5:.5,h=l(s.center,0,"x")*o-o/2,c=l(s.center,1,"y")*e-e/2,g=(s.radius??.5)*Math.max(o,e),f=t.createRadialGradient(h,c,0,h,c,g);if(s.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,m=r(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),m)}),s.gradientTransform&&f.setTransform){const[d,p,m,y,v,b]=s.gradientTransform;f.setTransform({a:d,b:p,c:m,d:y,e:v,f:b})}return f}else if(s.type==="AngularGradient"){const l=(d,p,m)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[m]??.5:.5,h=l(s.center||[.5,.5],0,"x")*o-o/2,c=l(s.center||[.5,.5],1,"y")*e-e/2,g=(s.degree||s.angle||0)*(Math.PI/180),f=(a=t.createConicGradient)==null?void 0:a.call(t,g,h,c);if(f){if(s.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,m=r(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),m)}),s.gradientTransform&&f.setTransform){const[d,p,m,y,v,b]=s.gradientTransform;f.setTransform({a:d,b:p,c:m,d:y,e:v,f:b})}return f}}else if(s.type==="DiamondGradient"){const l=(d,p,m)=>Array.isArray(d)?d[p]??.5:d&&typeof d=="object"?d[m]??.5:.5,h=l(s.center||[.5,.5],0,"x")*o-o/2,c=l(s.center||[.5,.5],1,"y")*e-e/2,g=(s.radius??.5)*Math.max(o,e);t.save(),t.translate(h,c),t.rotate(Math.PI/4);const f=t.createRadialGradient(0,0,0,0,0,g);if(s.stops.forEach(d=>{const p=d.offset!==void 0?d.offset:d.pos!==void 0?d.pos:d.position!==void 0?d.position:0,m=r(d.color||"#000000",d.opacity??100);f.addColorStop(Math.max(0,Math.min(1,p)),m)}),s.gradientTransform&&f.setTransform){const[d,p,m,y,v,b]=s.gradientTransform;f.setTransform({a:d,b:p,c:m,d:y,e:v,f:b})}return t.scale(1/Math.SQRT2,1/Math.SQRT2),t.fillStyle=f,t.restore(),f}}if(s.type==="Pattern"&&s.url){let r=this.imageCache.get(s.url);if(r||(r=new Image,r.src=s.url,this.imageCache.set(s.url,r)),r.complete&&r.naturalWidth>0){const l=t.createPattern(r,"repeat");if(l&&(s.scaleX!==void 0||s.offsetX!==void 0)){const h=new DOMMatrix,c=s.scaleX??1,g=s.scaleY??1,f=s.offsetX??0,d=s.offsetY??0,p=s.rotation??0;h.translateSelf(f,d),h.rotateSelf(p),h.scaleSelf(c,g),l.setTransform(h)}return l}}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,l=0,h=0,c=0;typeof a=="number"?r=l=h=c=a:Array.isArray(a)?a.length===1?r=l=h=c=a[0]:a.length===2?(r=h=a[0],l=c=a[1]):a.length===3?(r=a[0],l=c=a[1],h=a[2]):a.length>=4&&(r=a[0],l=a[1],h=a[2],c=a[3]):a&&typeof a=="object"&&(r=a.tl??a.corner_radius??a.cornerRadius??0,l=a.tr??a.corner_radius??a.cornerRadius??0,h=a.br??a.corner_radius??a.cornerRadius??0,c=a.bl??a.corner_radius??a.cornerRadius??0);const g=Math.min(Math.abs(e)/2,Math.abs(i)/2);if(r=Math.min(Math.max(0,r),g),l=Math.min(Math.max(0,l),g),h=Math.min(Math.max(0,h),g),c=Math.min(Math.max(0,c),g),t.roundRect){t.roundRect(s,o,e,i,[r,l,h,c]);return}t.moveTo(s+r,o),t.lineTo(s+e-l,o),t.arcTo(s+e,o,s+e,o+l,l),t.lineTo(s+e,o+i-h),t.arcTo(s+e,o+i,s+e-h,o+i,h),t.lineTo(s+c,o+i),t.arcTo(s,o+i,s,o+i-c,c),t.lineTo(s,o+r),t.arcTo(s,o,s+r,o,r),t.closePath()}renderListView(t,s){var F,O,A,W;const o=this.objectStates.get(s.id)||{},e=o.options||s.options||{},i=o.width!==void 0?o.width:((F=s.geometry)==null?void 0:F.width)||200,n=o.height!==void 0?o.height:((O=s.geometry)==null?void 0:O.height)||300,a=-i/2,r=-n/2,l=o.corner_radius!==void 0?o.corner_radius:e.corner_radius??0,h=e.orientation||"vertical",c=e.items||[],g=e.itemGap??10,f=e.itemHeight??50,d=e.itemWidth??200,p=e.scrollOffset??0,m=e.padding??0,y=e.glassEffect!==!1,v=e.accentColor||"#3b82f6",b=e.itemTextColor||"#333333",C=e.itemBackgroundColor||"#ffffff",S=e.hoveredIndex??null,w=e.activeItemIndex??null,I=e.glowIntensity??0,M=e.glowColor||"#3b82f6",P=typeof M=="string"?M:M.color||((W=(A=M.stops)==null?void 0:A[0])==null?void 0:W.color)||"#3b82f6",T=e.opacity!==void 0?e.opacity:s.opacity!==void 0?s.opacity:1;if(t.save(),t.globalAlpha*=T,I>0){const x=t.getTransform(),B=Math.sqrt(x.a*x.a+x.b*x.b)||1;t.shadowColor=P,t.shadowBlur=I*2*B,t.shadowOffsetX=0,t.shadowOffsetY=0}if(y){const x=e.listBackgroundColor||"rgba(31, 41, 55, 0.4)",B=this.createCanvasFill(t,x,i,n);t.fillStyle=B||"rgba(31, 41, 55, 0.4)",this.drawListViewRect(t,a,r,i,n,l),t.fill();const N=t.createLinearGradient(a,r,a+i,r+n);N.addColorStop(0,"rgba(255, 255, 255, 0.15)"),N.addColorStop(.5,"rgba(255, 255, 255, 0.08)"),N.addColorStop(1,"rgba(255, 255, 255, 0.03)"),t.fillStyle=N,this.drawListViewRect(t,a,r,i,n,l),t.fill(),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1,this.drawListViewRect(t,a,r,i,n,l),t.stroke()}else{const x=e.listBackgroundColor||"transparent",B=this.createCanvasFill(t,x,i,n);B&&(t.fillStyle=B,this.drawListViewRect(t,a,r,i,n,l),t.fill());const N=e.borderWidth??0;N>0&&(t.strokeStyle=e.borderColor||"#cccccc",t.lineWidth=N,this.drawListViewRect(t,a,r,i,n,l),t.stroke())}t.shadowBlur=0,t.save(),this.drawListViewRect(t,a,r,i,n,l),t.clip();const $=typeof m=="number"?m:h==="vertical"?m[0]:m[3];let k=(h==="vertical"?r:a)+p+$;if(t.textBaseline="middle",c.forEach((x,B)=>{const N=h==="vertical"?i:d,Q=h==="vertical"?f:n,_=h==="vertical"?a:k,L=h==="vertical"?k:r,U=S===B,q=w===B;if(q){const ut=this.createCanvasFill(t,v,N,Q);t.fillStyle=ut||v;const ot=t.globalAlpha;t.globalAlpha=ot*.8,t.fillRect(_,L,N,Q),t.globalAlpha=ot}else if(U)t.fillStyle=y?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",t.fillRect(_,L,N,Q);else if(C!=="transparent"){const ut=this.createCanvasFill(t,C,N,Q);t.fillStyle=ut||C,t.fillRect(_,L,N,Q)}if(q||U){const ut=this.createCanvasFill(t,v,h==="vertical"?3:N,h==="vertical"?Q:3);t.fillStyle=ut||v,h==="vertical"?t.fillRect(_,L,3,Q):t.fillRect(_,L+Q-3,N,3)}const et=q?"#ffffff":y?"rgba(255, 255, 255, 0.9)":b;t.fillStyle=et,t.font=q||U?"600 14px Inter, sans-serif":"400 14px Inter, sans-serif";const ft=typeof x=="string"?x:(x==null?void 0:x.label)||`Item ${B+1}`,vt=_+(h==="vertical"?16:N/2),lt=L+Q/2;h==="horizontal"?t.textAlign="center":t.textAlign="left",t.fillText(ft,vt,lt),k+=(h==="vertical"?f:d)+g}),t.restore(),e.showScrollbar!==!1){const x=(c.length||0)*(h==="vertical"?f:d)+((c.length||0)-1)*g,B=h==="vertical"?n:i;if(x>B){const N=B/x,Q=B*N,_=-p/x*B,L=e.scrollbarColor||"rgba(255,255,255,0.3)",U=e.scrollbarWidth||4;t.fillStyle=L,h==="vertical"?t.fillRect(a+i-U-2,r+_,U,Q):t.fillRect(a+_,r+n-U-2,Q,U)}}t.restore()}updateListViewScrollFromPointer(t){var m,y;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=this.objectStates.get(t.id)||{},a=s.items||[],r=s.itemGap??10,l=s.itemHeight??50,h=s.itemWidth??200,c=n.width!==void 0?n.width:((m=t.geometry)==null?void 0:m.width)||200,g=n.height!==void 0?n.height:((y=t.geometry)==null?void 0:y.height)||300,f=(a.length||0)*(o==="vertical"?l:h)+((a.length||0)-1)*r,p=Math.max(0,f-(o==="vertical"?g:c)+(s.padding*2||0));s.scrollOffset>0&&(s.scrollOffset=0),s.scrollOffset<-p&&(s.scrollOffset=-p)}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 $,k;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:(($=t.geometry)==null?void 0:$.width)||200,r=i.height!==void 0?i.height:((k=t.geometry)==null?void 0:k.height)||300,l=e.orientation||"vertical",h=e.itemGap??10,c=e.itemHeight??50,g=e.itemWidth??200,f=e.scrollOffset??0,d=e.padding??0,p=this.getWorldTransform(t.id),m=s-p.x,y=o-p.y,v=-p.rotation*(Math.PI/180),b=Math.cos(v),C=Math.sin(v),S=m*b-y*C,w=m*C+y*b,I=-a/2,M=-r/2,P=typeof d=="number"?d:l==="vertical"?d[0]:d[3];let T=(l==="vertical"?M:I)+f+P;for(let E=0;E<n.length;E++){const F=l==="vertical"?a:g,O=l==="vertical"?c:r,A=l==="vertical"?I:T,W=l==="vertical"?T:M;if(S>=A&&S<=A+F&&w>=W&&w<=W+O)return E;T+=(l==="vertical"?c:g)+h}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 g,f,d,p,m,y,v,b,C,S,w,I,M,P,T,$,k,E,F,O,A,W,x,B,N,Q,_,L,U,q,et,ft,vt,lt,ut,ot,Et,Ft,Mt,Dt,Yt,Rt,ee,H,at,Lt,kt,St,Vt,jt,te,Kt,Ht,ae,nt,ht,z,Y,tt,Z,xt,Bt,Pt,Ut,Tt,R,At,le,Ct,qt,wt,Xt,Jt,rt,ct,gt,It,pt,Gt,ie,Zt,it,j,dt,$t,J,yt,mt,pe,Ce,_e,Qt,ce,ve,Ie,Me,ge,de,ue,Se,Pe,Re,$e,Ee,We,Be,os,as,rs,ls,cs,fs,hs,ds,us,ps,gs,ms;if(!n.enabled)return;const a=n.startTime||0,r=n.endTime||1/0;if(this.currentTime<a||this.currentTime>r)return;const l=i.x-s,h=i.y-o,c=Math.sqrt(l*l+h*h);if(this.frameCount%240===0&&Math.random()<.1&&console.log(`[ExodeUI] Executing ${n.type} on ${e.name}`),n.type===X.Proximity){const G=((g=n.settings)==null?void 0:g.radius)||300,V=((f=n.settings)==null?void 0:f.falloff)||"smooth";let D=0;c<G&&(V==="linear"?D=1-c/G:D=Math.pow(1-c/G,2)),n.sensors.forEach(st=>{this.applyBehaviorSensor(i,st,D,t,n.settings,e,l,h,c)})}else if(n.type===X.Magnetic){const G=((d=n.settings)==null?void 0:d.radius)||400,V=((p=n.settings)==null?void 0:p.strength)||.5;if(c<G&&c>5){const D=1-c/G,st=l*D*V,_t=h*D*V;i.x-=st*t*10,i.y-=_t*t*10}}else if(n.type===X.Repel){const G=((m=n.settings)==null?void 0:m.radius)||300,V=((y=n.settings)==null?void 0:y.strength)||1;if(c<G){const D=Math.pow(1-c/G,2);i.x+=l/(c||1)*D*60*V*t*5,i.y+=h/(c||1)*D*60*V*t*5}}else if(n.type===X.Orbit){const G=((v=n.settings)==null?void 0:v.speed)||1,V=((b=n.settings)==null?void 0:b.radius)||30,D=this.currentTime*G*Math.PI*2;i.x+=Math.cos(D)*V*t*5,i.y+=Math.sin(D)*V*t*5,i.rotation+=2*t*5}else if(n.type===X.Vortex){const G=((C=n.settings)==null?void 0:C.radius)||400,V=((S=n.settings)==null?void 0:S.speed)||2,D=((w=n.settings)==null?void 0:w.strength)||1;if(c<G){const st=Math.pow(1-c/G,1.5),_t=this.currentTime*V*Math.PI*2,Ot=Math.cos(_t)*30-l*.4,zt=Math.sin(_t)*30-h*.4;i.x+=Ot*st*D*t*5,i.y+=zt*st*D*t*5,i.rotation+=5*st*D*t*5,i.scale_x*=1-st*.1*D*t,i.scale_y*=1-st*.1*D*t}}else if(n.type===X.Fluid){const G=((I=n.settings)==null?void 0:I.radius)||300,V=((M=n.settings)==null?void 0:M.strength)||1;if(c<G){const D=Math.pow(1-c/G,1.2),st=l/(c||1)*D*1.2*V,_t=h/(c||1)*D*1.2*V;i.x+=st*10*t*5,i.y+=_t*10*t*5,i.scale_x*=1+D*.3*V*t,i.scale_y*=1+D*.3*V*t}}else if(n.type===X.Elastic){const G=((P=n.settings)==null?void 0:P.radius)||300,V=((T=n.settings)==null?void 0:T.strength)||1;if(c<G){const D=1-c/G;i.scale_x*=1+D*.4*V*t,i.scale_y*=1+D*.4*V*t}}else if(n.type===X.Holographic){const G=i.x-this.canvasWidth/2,V=i.y-this.canvasHeight/2,D=(($=n.settings)==null?void 0:$.factor)||25;if(i.x-=G/1e3*D*t*5,i.y-=V/1e3*D*t*5,i.style){const st=1-Math.min(1,c/400);i.style.exposure=(i.style.exposure||1)+st*.5*t}}else if(n.type===X.Sticky){const G=((k=n.settings)==null?void 0:k.radius)||80,V=((E=n.settings)==null?void 0:E.strength)||1;if(c<G){const D=Math.pow(1-c/G,2);i.x-=l*D*V*t*10,i.y-=h*D*V*t*10,i.scale_x*=1-D*.1*V*t,i.scale_y*=1-D*.1*V*t}}else if(n.type===X.Dilation){const G=((F=n.settings)==null?void 0:F.size)||120,V=((O=n.settings)==null?void 0:O.strength)||1;if(c<G){const D=1-c/G;i.scale_x*=1+D*.5*V*t,i.scale_y*=1+D*.5*V*t}}else if(n.type===X.Parallax){const G=((A=n.settings)==null?void 0:A.factor)||15,V=((W=n.settings)==null?void 0:W.strength)||1,D=this.canvasWidth/2,st=this.canvasHeight/2,_t=this._lastPointerPos||{x:D,y:st},Ot=(_t.x-D)/D,zt=(_t.y-st)/st,re=(((x=e.transform)==null?void 0:x.x)??0)+Ot*G*V,me=(((B=e.transform)==null?void 0:B.y)??0)+zt*G*V,we=(((N=e.transform)==null?void 0:N.rotate_x)??0)-zt*G*1.5*V,fe=(((Q=e.transform)==null?void 0:Q.rotate_y)??0)+Ot*G*1.5*V,be=Math.min(1,10*t);i.x=this.lerp(i.x??((_=e.transform)==null?void 0:_.x)??0,re,be),i.y=this.lerp(i.y??((L=e.transform)==null?void 0:L.y)??0,me,be),i.rotate_x=this.lerp(i.rotate_x??((U=e.transform)==null?void 0:U.rotate_x)??0,we,be),i.rotate_y=this.lerp(i.rotate_y??((q=e.transform)==null?void 0:q.rotate_y)??0,fe,be)}else if(n.type===X.Fold){if(c<300){const G=1-c/300,V=(l>0?-1:1)*G*10,D=1-G*.1,st=h/300*G*20,_t=-(l/300)*G*20,Ot=Math.min(1,10*t);i.skew_x=this.lerp(i.skew_x??((et=e.transform)==null?void 0:et.skew_x)??0,V,Ot),i.scale_y=this.lerp(i.scale_y??((ft=e.transform)==null?void 0:ft.scale_y)??1,(((vt=e.transform)==null?void 0:vt.scale_y)??1)*D,Ot),i.rotate_x=this.lerp(i.rotate_x??((lt=e.transform)==null?void 0:lt.rotate_x)??0,st,Ot),i.rotate_y=this.lerp(i.rotate_y??((ut=e.transform)==null?void 0:ut.rotate_y)??0,_t,Ot),i.style=i.style||{...e.style},i.style.artEffect={enabled:!0,type:"fold_overlay",intensity:((ot=n.settings)==null?void 0:ot.opacity)??.5}}}else if(n.type===X.Crumple){if(c<300){const G=1-c/300,V=G*(Math.random()-.5)*5,D=G*(Math.random()-.5)*.05,st=Math.min(1,15*t);i.skew_x=this.lerp(i.skew_x??((Et=e.transform)==null?void 0:Et.skew_x)??0,V,st),i.scale_x=this.lerp(i.scale_x??((Ft=e.transform)==null?void 0:Ft.scale_x)??1,(((Mt=e.transform)==null?void 0:Mt.scale_x)??1)*(1+D),st),i.scale_y=this.lerp(i.scale_y??((Dt=e.transform)==null?void 0:Dt.scale_y)??1,(((Yt=e.transform)==null?void 0:Yt.scale_y)??1)*(1+D),st),i.style=i.style||{...e.style},i.style.artEffect={enabled:!0,type:"crumple_overlay",intensity:((Rt=n.settings)==null?void 0:Rt.intensity)??1,scale:((ee=n.settings)==null?void 0:ee.scale)??2}}}else if(n.type===X.Squash){const G=((H=n.settings)==null?void 0:H.strength)||.8;c<(e.width||100)&&this.isMouseDown?(i.scale_y=this.lerp(i.scale_y??1,(((at=e.transform)==null?void 0:at.scale_y)??1)*G,.3),i.scale_x=this.lerp(i.scale_x??1,(((Lt=e.transform)==null?void 0:Lt.scale_x)??1)*(1+(1-G)*.4),.3)):(i.scale_y=this.lerp(i.scale_y??1,((kt=e.transform)==null?void 0:kt.scale_y)??1,.2),i.scale_x=this.lerp(i.scale_x??1,((St=e.transform)==null?void 0:St.scale_x)??1,.2))}else if(n.type===X.TextCounter){const G=((Vt=n.settings)==null?void 0:Vt.duration)||2,V=((jt=n.settings)==null?void 0:jt.from)||0,D=((te=n.settings)==null?void 0:te.to)||100;n._runtimeStart===void 0&&(n._runtimeStart=this.currentTime);const st=this.currentTime-n._runtimeStart,_t=Math.min(1,st/G),Ot=Math.floor(V+(D-V)*_t);if(((Kt=e.geometry)==null?void 0:Kt.type)==="Text"){const zt=((Ht=n.settings)==null?void 0:Ht.prefix)||"",re=((ae=n.settings)==null?void 0:ae.suffix)||"";i.geometry||(i.geometry={...e.geometry}),i.geometry.text=`${zt}${Ot}${re}`}}else if(n.type===X.Spotlight){const G=((nt=n.settings)==null?void 0:nt.radius)||250,V=((ht=n.settings)==null?void 0:ht.strength)||1.5;if(c<G){const D=Math.pow(1-c/G,2);i.style||(i.style={...e.style}),i.style.adjustments||(i.style.adjustments={...(z=e.style)==null?void 0:z.adjustments}),i.style.adjustments.exposure=(((tt=(Y=e.style)==null?void 0:Y.adjustments)==null?void 0:tt.exposure)||0)+D*V*50}else(Z=i.style)!=null&&Z.adjustments&&(i.style.adjustments.exposure=this.lerp(i.style.adjustments.exposure||0,((Bt=(xt=e.style)==null?void 0:xt.adjustments)==null?void 0:Bt.exposure)||0,.1))}else if(n.type===X.Noise||n.type===X.Float){const G=(((Pt=n.settings)==null?void 0:Pt.frequency)||((Ut=n.settings)==null?void 0:Ut.speed)||1)*.002,V=(((Tt=n.settings)==null?void 0:Tt.amplitude)||((R=n.settings)==null?void 0:R.range)||50)*(((At=n.settings)==null?void 0:At.strength)||1),D=Date.now();i.x+=Math.sin(D*G)*V*t,i.y+=Math.cos(D*G*.8)*V*t,i.rotation+=Math.sin(D*G*.5)*5*t}else if(n.type===X.Pulse){const G=(((le=n.settings)==null?void 0:le.speed)||1)*.005,V=(((Ct=n.settings)==null?void 0:Ct.scale)||1.2)-1,D=Math.sin(Date.now()*G),st=((qt=n.settings)==null?void 0:qt.strength)||1;i.scale_x*=1+D*V*st*t,i.scale_y*=1+D*V*st*t,i.style&&(i.style.exposure=(i.style.exposure||1)+Math.max(0,D)*.1*st*t)}else if(n.type===X.Draggable){const G=((wt=n.settings)==null?void 0:wt.radius)||150,V=this.draggingBehaviors.has(e.id);if(c<G||V){const D=((Xt=n.settings)==null?void 0:Xt.strength)||1,st=V?1:Math.max(0,1-c/G);this.applyBehaviorSensor(i,oe.PositionX,st*D,t,n.settings),this.applyBehaviorSensor(i,oe.PositionY,st*D,t,n.settings)}}else if(n.type===X.Scroll){const G=((Jt=n.settings)==null?void 0:Jt.axis)||"vertical",V=((rt=n.settings)==null?void 0:rt.factor)||.5,D=((ct=n.settings)==null?void 0:ct.strength)||1,st=((gt=n.settings)==null?void 0:gt.scaleFactor)||0;(G==="vertical"||G==="both")&&(i.y+=this.scrollOffset.y*V*D*t),(G==="horizontal"||G==="both")&&(i.x+=this.scrollOffset.x*V*D*t),st!==0&&(i.scale_x*=1+this.scrollOffset.y*st*t,i.scale_y*=1+this.scrollOffset.y*st*t)}else if(n.type===X.LookAt){const G=((It=n.settings)==null?void 0:It.factor)||1,V=((pt=n.settings)==null?void 0:pt.strength)||1,D=Math.atan2(-h,-l)*(180/Math.PI),st=i.rotation,_t=(D-st+180)%360-180;i.rotation+=_t*G*V*t*10}else if(n.type===X.Scan){const G=(((Gt=n.settings)==null?void 0:Gt.speed)||1)*.004,V=((ie=n.settings)==null?void 0:ie.strength)||1,D=(Math.sin(Date.now()*G)+1)/2;i.style&&(i.style.exposure=(i.style.exposure||1)+D*V*t*5),i.x+=(D-.5)*20*V*t}else if(n.type===X.Glint)i.style=i.style||{...e.style},i.style.artEffect={enabled:!0,type:"glint_overlay",intensity:((Zt=n.settings)==null?void 0:Zt.strength)??.8};else if(n.type===X.Ratchet){const G=((it=n.settings)==null?void 0:it.steps)||12,V=(((j=n.settings)==null?void 0:j.speed)||1)*30,D=Math.floor(i.rotation/(360/G))*(360/G);i.rotation=this.lerp(i.rotation,D+V*t,.1)}else if(n.type===X.Jitter&&c<300){const G=((dt=n.settings)==null?void 0:dt.strength)||1,V=((($t=n.settings)==null?void 0:$t.intensity)||5)*G;i.x+=(Math.random()-.5)*V*t*60,i.y+=(Math.random()-.5)*V*t*60,i.rotation+=(Math.random()-.5)*V*t*120}else if(n.type===X.Follower){const G=(J=n.settings)==null?void 0:J.targetId;if(G){const V=this.objectStates.get(G);if(V){const D=((yt=n.settings)==null?void 0:yt.stiffness)||.1,st=V.x-i.x,_t=V.y-i.y;i.x+=st*D*t*60,i.y+=_t*D*t*60}}}else if(n.type===X.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===X.Gravity){const G=((mt=n.settings)==null?void 0:mt.strength)||9.8;i.y+=G*t*10}else if(n.type===X.Velocity){const G=((pe=n.settings)==null?void 0:pe.vx)||0,V=((Ce=n.settings)==null?void 0:Ce.vy)||0;i.x+=G*t*10,i.y+=V*t*10}else if(n.type===X.Shear){const G=((_e=n.settings)==null?void 0:_e.strength)||1,V=((Qt=n.settings)==null?void 0:Qt.radius)||300;if(c<V){const D=1-c/V;i.skew_x=this.lerp(i.skew_x||0,(((ce=e.transform)==null?void 0:ce.skew_x)||0)+D*G*30,.1)}else i.skew_x=this.lerp(i.skew_x||0,((ve=e.transform)==null?void 0:ve.skew_x)||0,.05)}else if(n.type===X.Lens){const G=((Ie=n.settings)==null?void 0:Ie.radius)||200,V=((Me=n.settings)==null?void 0:Me.strength)||.5;if(c<G){const D=Math.pow(1-c/G,2);i.scale_x=this.lerp(i.scale_x??1,(((ge=e.transform)==null?void 0:ge.scale_x)??1)*(1+D*V),.2),i.scale_y=this.lerp(i.scale_y??1,(((de=e.transform)==null?void 0:de.scale_y)??1)*(1+D*V),.2)}else i.scale_x=this.lerp(i.scale_x??1,((ue=e.transform)==null?void 0:ue.scale_x)??1,.1),i.scale_y=this.lerp(i.scale_y??1,((Se=e.transform)==null?void 0:Se.scale_y)??1,.1)}else if(n.type===X.LayoutAnimation){const G=((Pe=n.settings)==null?void 0:Pe.watchProperties)||["x","y","scale_x","scale_y","opacity","rotation"],V=((Re=n.settings)==null?void 0:Re.duration)||.3;this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const D=this._layoutAnimCache.get(e.id);for(const st of G){const _t=this.getObjectProperty(i,e,st);if(_t===void 0)continue;const Ot=D.get(st);if(!Ot)D.set(st,{from:_t,to:_t,startTime:this.currentTime,duration:0});else if(Ot.to!==_t){const re=this.getObjectProperty(i,e,st);D.set(st,{from:re??Ot.from,to:_t,startTime:this.currentTime,duration:(($e=n.settings)==null?void 0:$e.duration)??V})}const zt=D.get(st);if(zt.duration>0&&zt.from!==zt.to){const re=this.currentTime-zt.startTime,me=Math.min(1,re/zt.duration),we=this.applyEasing(me,((Ee=n.settings)==null?void 0:Ee.easing)||"easeOutCubic"),fe=zt.from+(zt.to-zt.from)*we;this.setObjectProperty(i,e,st,fe)}}}else if(n.type===X.StateReactive){this._layoutAnimCache.has(e.id)||this._layoutAnimCache.set(e.id,new Map);const G=this._layoutAnimCache.get(e.id),V=((We=n.settings)==null?void 0:We.defaultDuration)||.3,D=["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 st of D){const _t=this.getObjectProperty(i,e,st);if(_t===void 0||typeof _t!="number")continue;const Ot=G.get(st);if(!Ot)G.set(st,{from:_t,to:_t,startTime:this.currentTime,duration:0});else if(Ot.to!==_t){const re=this.getObjectProperty(i,e,st);G.set(st,{from:re??Ot.from,to:_t,startTime:this.currentTime,duration:V})}const zt=G.get(st);if(zt.duration>0&&zt.from!==zt.to){const re=this.currentTime-zt.startTime,me=Math.min(1,re/zt.duration),we=this.applyEasing(me,((Be=n.settings)==null?void 0:Be.defaultEasing)||"easeOutCubic"),fe=zt.from+(zt.to-zt.from)*we;this.setObjectProperty(i,e,st,fe)}}}else if(n.type===X.SpringChain){const G=((os=n.settings)==null?void 0:os.connections)||[],V=((as=n.settings)==null?void 0:as.globalDamping)||.3;this._springChainState.has(e.id)||this._springChainState.set(e.id,new Map);const D=this._springChainState.get(e.id);for(const _t of G){if(!D.has(_t.targetId)){const Ot=this.objectStates.get(_t.targetId);D.set(_t.targetId,{x:(Ot==null?void 0:Ot.x)??0,y:(Ot==null?void 0:Ot.y)??0,vx:0,vy:0})}D.has(e.id)||D.set(e.id,{x:i.x,y:i.y,vx:0,vy:0})}const st=D.get(e.id);if(st){st.x=i.x,st.y=i.y;for(const _t of G){const Ot=D.get(_t.targetId);if(!Ot)continue;const zt=Ot.x-st.x,re=Ot.y-st.y,me=Math.sqrt(zt*zt+re*re)||.001,fe=(me-(_t.restLength||50))*(_t.stiffness||.8),be=zt/me*fe,Ye=re/me*fe;st.vx+=be*t*10,st.vy+=Ye*t*10,Ot.vx-=be*t*10,Ot.vy-=Ye*t*10,st.vx*=1-V*t*10,st.vy*=1-V*t*10,Ot.vx*=1-V*t*10,Ot.vy*=1-V*t*10;const ye=this.objectStates.get(_t.targetId);ye&&(ye.x+=Ot.vx*t,ye.y+=Ot.vy*t)}i.x+=st.vx*t,i.y+=st.vy*t}}else if(n.type===X.ParticleEmitter){const G=((rs=n.settings)==null?void 0:rs.rate)||10,V=((ls=n.settings)==null?void 0:ls.speed)||100,D=((cs=n.settings)==null?void 0:cs.size)||5,st=((fs=n.settings)==null?void 0:fs.lifetime)||2,_t=((hs=n.settings)==null?void 0:hs.gravity)||0,Ot=((ds=n.settings)==null?void 0:ds.color)||"#ffffff",zt=((us=n.settings)==null?void 0:us.maxParticles)||200,re=(ps=n.settings)!=null&&ps.rateInputId?this.inputs.get(n.settings.rateInputId)??G:G,me=(gs=n.settings)!=null&&gs.gravityInputId?this.inputs.get(n.settings.gravityInputId)??_t:_t,we=(ms=n.settings)!=null&&ms.speedInputId?this.inputs.get(n.settings.speedInputId)??V:V;this._emitterPools.has(e.id)||this._emitterPools.set(e.id,[]);const fe=this._emitterPools.get(e.id);let be=0;n._pendingBurst&&n._pendingBurst>0&&(be=n._pendingBurst,n._pendingBurst=0);const Ye=Math.floor(re*t)+(be||0);for(let ye=0;ye<Math.min(Ye,zt-fe.length);ye++){const he=Math.random()*Math.PI*2,ys=we*(.5+Math.random()*.5);fe.push({x:i.x,y:i.y,vx:Math.cos(he)*ys,vy:Math.sin(he)*ys,life:0,maxLife:st*(.5+Math.random()*.5),size:D*(.5+Math.random()),color:Ot,opacity:1})}for(let ye=fe.length-1;ye>=0;ye--){const he=fe[ye];he.vy+=me*t*10,he.x+=he.vx*t,he.y+=he.vy*t,he.life+=t,he.opacity=Math.max(0,1-he.life/he.maxLife),he.life>=he.maxLife&&fe.splice(ye,1)}}})})}applyBehaviorSensor(t,s,o,e,i,n,a=0,r=0,l=1){var d,p,m,y,v,b,C,S,w,I,M,P,T,$,k,E,F,O,A,W,x,B,N,Q;const h=(i==null?void 0:i.intensity)||(i==null?void 0:i.strength)||1,c=Math.min(1,15*e),g=l>0?a/l:0,f=l>0?r/l:0;switch(s){case oe.Scale:{const _=((d=n==null?void 0:n.transform)==null?void 0:d.scale_x)??1,L=((p=n==null?void 0:n.transform)==null?void 0:p.scale_y)??1,U=_*(1+o*h*.4),q=L*(1+o*h*.4);t.scale_x=(t.scale_x??_)*(1-c)+U*c,t.scale_y=(t.scale_y??L)*(1-c)+q*c;break}case oe.Opacity:{const _=((m=n==null?void 0:n.transform)==null?void 0:m.opacity)??100,L=Math.max(0,Math.min(100,_-o*h*100));t.opacity=(t.opacity??_)*(1-c)+L*c;break}case oe.RotateZ:{const _=((y=n==null?void 0:n.transform)==null?void 0:y.rotation)??0,L=_+o*h*45;t.rotation=(t.rotation??_)*(1-c)+L*c;break}case oe.RotateX:{const _=((v=n==null?void 0:n.transform)==null?void 0:v.rotate_x)??0,L=_-f*o*h*60;t.rotate_x=(t.rotate_x??_)*(1-c)+L*c;break}case oe.RotateY:{const _=((b=n==null?void 0:n.transform)==null?void 0:b.rotate_y)??0,L=_+g*o*h*60;t.rotate_y=(t.rotate_y??_)*(1-c)+L*c;break}case oe.PositionX:{const _=((C=n==null?void 0:n.transform)==null?void 0:C.x)??0,L=_-g*o*h*40;t.x=(t.x??_)*(1-c)+L*c;break}case oe.PositionY:{const _=((S=n==null?void 0:n.transform)==null?void 0:S.y)??0,L=_-f*o*h*40;t.y=(t.y??_)*(1-c)+L*c;break}case oe.SkewX:{const _=((w=n==null?void 0:n.transform)==null?void 0:w.skew_x)??0,L=_+g*o*h*45;t.skew_x=(t.skew_x??_)*(1-c)+L*c,t.skew_x>85&&(t.skew_x=85),t.skew_x<-85&&(t.skew_x=-85);break}case oe.Blur:{t.style||(t.style={...n==null?void 0:n.style}),t.style.blur||(t.style.blur={...(I=n==null?void 0:n.style)==null?void 0:I.blur});const _=((P=(M=n==null?void 0:n.style)==null?void 0:M.blur)==null?void 0:P.amount)||0,L=_+o*((i==null?void 0:i.blur)||20)*h;t.style.blur.amount=(t.style.blur.amount??_)*(1-c)+L*c;break}case oe.Exposure:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(T=n==null?void 0:n.style)==null?void 0:T.adjustments});const _=((k=($=n==null?void 0:n.style)==null?void 0:$.adjustments)==null?void 0:k.exposure)||0,L=_+o*((i==null?void 0:i.exposure)||50)*h;t.style.adjustments.exposure=(t.style.adjustments.exposure??_)*(1-c)+L*c;break}case oe.HueShift:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(E=n==null?void 0:n.style)==null?void 0:E.adjustments});const _=((O=(F=n==null?void 0:n.style)==null?void 0:F.adjustments)==null?void 0:O.hue)||0,L=_+o*((i==null?void 0:i.hue)||180)*h;t.style.adjustments.hue=(t.style.adjustments.hue??_)*(1-c)+L*c;break}case oe.Negative:{t.style||(t.style={...n==null?void 0:n.style}),t.style.adjustments||(t.style.adjustments={...(A=n==null?void 0:n.style)==null?void 0:A.adjustments});const _=((x=(W=n==null?void 0:n.style)==null?void 0:W.adjustments)==null?void 0:x.negative)||0,L=_+o*((i==null?void 0:i.negative)||100)*h;t.style.adjustments.negative=(t.style.adjustments.negative??_)*(1-c)+L*c;break}case oe.CornerRadius:{const _=((B=n==null?void 0:n.transform)==null?void 0:B.corner_radius)||0,L=_+o*h*50;t.corner_radius=(t.corner_radius??_)*(1-c)+L*c;break}case oe.StrokeWidth:{t.style||(t.style={...n==null?void 0:n.style});const _=((N=n==null?void 0:n.style)==null?void 0:N.borderWidth)||0,L=_+o*h*10;t.style.borderWidth=(t.style.borderWidth??_)*(1-c)+L*c;break}case oe.LetterSpacing:{t.geometry||(t.geometry={});const _=((Q=n==null?void 0:n.geometry)==null?void 0:Q.letterSpacing)||0,L=_+o*h*10;t.geometry.letterSpacing=(t.geometry.letterSpacing??_)*(1-c)+L*c;break}}}getObjectProperty(t,s,o){const e=o.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.split(".");let n=t;for(let r=0;r<i.length-1;r++){const l=i[r];if(n[l]===void 0||n[l]===null){const h=s,c=i.slice(0,r+1).reduce((g,f)=>g==null?void 0:g[f],h);n[l]=c!==void 0?{...c}:{}}n=n[l]}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;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]):o[e]=s[e]);return o}renderFittedImage(t,s,o,e,i,n,a="cover"){const r=s.naturalWidth,l=s.naturalHeight,h=r/l,c=i/n;let g=i,f=n,d=o,p=e;a==="cover"?h>c?(g=n*h,d=o-(g-i)/2):(f=i/h,p=e-(f-n)/2):a==="contain"&&(h>c?(f=i/h,p=e+(n-f)/2):(g=n*h,d=o+(i-g)/2)),t.drawImage(s,d,p,g,f)}}const ni=Wt.forwardRef(({artboard:u,src:t,style:s,autoPlay:o=!0,fit:e="Contain",alignment:i="Center",onReady:n,onTrigger:a,onInputUpdate:r,onComponentChange:l,onToggle:h,onInputChange:c,onInputFocus:g,onInputBlur:f,onLog:d,onLogicUpdate:p,onButtonClick:m,onGraphPointClick:y,currentTime:v,revision:b=0,scrollY:C,scrollX:S,mouseX:w,mouseY:I,isMouseDown:M,inputs:P,interactive:T=!0,onNavigation:$},k)=>{const E=Wt.useRef(null),F=Wt.useRef(new ns),O=Wt.useRef(void 0),A=Wt.useRef(0),W=Wt.useRef(null),x=Wt.useRef(b),[,B]=Wt.useState(u||null),N=Wt.useRef(!0);Wt.useImperativeHandle(k,()=>E.current),Wt.useEffect(()=>(N.current=!0,()=>{N.current=!1,O.current&&cancelAnimationFrame(O.current)}),[]),Wt.useEffect(()=>{F.current.setLayout(e,i)},[e,i]),Wt.useEffect(()=>{const _=F.current;a&&_.setTriggerCallback(a),r&&_.setInputUpdateCallback((L,U)=>r({[L]:U})),l&&_.setComponentChangeCallback(L=>l(L)),h&&_.setToggleCallback(h),c&&_.setInputChangeCallback(c),g&&_.setInputFocusCallback(g),f&&_.setInputBlurCallback(f),d&&_.setOnLogCallback(L=>d(L,"info")),p&&_.setLogicUpdateCallback(p),m&&_.setButtonClickCallback(m),y&&_.setGraphPointClickCallback(L=>y(L.objectId,L)),$&&_.setNavigationCallback($)},[a,r,l,h,c,g,f,d,p,m,y,$]),Wt.useEffect(()=>{(async()=>{let L=u;if(t&&!u)try{t.startsWith("{")?L=JSON.parse(t):L=await(await fetch(t)).json()}catch(U){console.error("[ExodeUI] Failed to load src:",U)}if(L){const U=F.current,q=L.id||L.name||"default";(W.current!==q||x.current!==b)&&(U.load(L),W.current=q,x.current=b,B(L),A.current=0,U.advance(0)),n&&n(U)}})()},[u==null?void 0:u.id,t,b]),Wt.useEffect(()=>{const _=L=>{if(!F.current||!N.current)return;const U=F.current,q=E.current;if(!q)return;const et=q.getContext("2d");if(!et)return;const ft=L/1e3;A.current===0&&(A.current=ft);let vt=ft-A.current;vt>.1&&(vt=.1),A.current=ft;const lt=q.getBoundingClientRect(),ut=window.devicePixelRatio||1,ot=Math.round(lt.width*ut),Et=Math.round(lt.height*ut);(q.width!==ot||q.height!==Et)&&(q.width=ot,q.height=Et),o?U.advance(vt):v!==void 0&&U.seek(v),U.render(et,q.width,q.height),O.current=requestAnimationFrame(_)};return O.current=requestAnimationFrame(_),()=>{O.current&&cancelAnimationFrame(O.current)}},[o,v]),Wt.useEffect(()=>{const _=F.current;C!==void 0&&_.updateInput("scrollY",C),S!==void 0&&_.updateInput("scrollX",S),w!==void 0&&_.updateInput("mouseX",w),I!==void 0&&_.updateInput("mouseY",I),M!==void 0&&_.updateInput("isMouseDown",M),P&&Object.entries(P).forEach(([L,U])=>_.updateInput(L,U))},[C,S,w,I,M,P]);const Q=(_,L)=>{if(!T||!E.current)return;const U=E.current,q=U.getBoundingClientRect(),et=_.clientX-q.left,ft=_.clientY-q.top,vt=window.devicePixelRatio||1;F.current.handlePointerInput(L,et*vt,ft*vt,U.width,U.height)};return se.jsx("canvas",{ref:E,onPointerDown:_=>{var L;Q(_,"down"),(L=E.current)==null||L.focus()},onPointerMove:_=>Q(_,"move"),onPointerUp:_=>Q(_,"up"),onPointerCancel:_=>Q(_,"up"),onClick:_=>Q(_,"click"),onWheel:_=>{F.current.handleWheel(_.deltaX,_.deltaY)},onKeyDown:_=>F.current.handleKeyDown(_.nativeEvent),onContextMenu:_=>_.preventDefault(),tabIndex:0,style:{...s,width:"100%",height:"100%",outline:"none",display:"block",touchAction:"none",pointerEvents:T?"auto":"none"}})});function oi(){const[u,t]=Wt.useState(null),s=Wt.useCallback((c,g)=>{u==null||u.setInputBool(c,g)},[u]),o=Wt.useCallback((c,g)=>{u==null||u.setInputNumber(c,g)},[u]),e=Wt.useCallback(c=>{u==null||u.fireTrigger(c)},[u]),i=Wt.useCallback((c,g)=>{u==null||u.setInputText(c,g)},[u]),n=Wt.useCallback((c,g)=>{u==null||u.setInputNumberArray(c,g)},[u]),a=Wt.useCallback((c,g)=>{u==null||u.setInputStringArray(c,g)},[u]),r=Wt.useCallback((c,g)=>{u==null||u.updateObjectOptions(c,g)},[u]),l=Wt.useCallback((c,g,f)=>{u==null||u.updateConstraint(c,g,f)},[u]),h=Wt.useCallback((c,g)=>{u==null||u.updateGraphData(c,g)},[u]);return{setEngine:t,engine:u,setInputBool:s,setInputNumber:o,fireTrigger:e,setInputText:i,setInputNumberArray:n,setInputStringArray:a,updateConstraint:l,updateGraphData:h,updateObjectOptions:r}}const ai=({artboard:u,config:t})=>{const s={...u.seo,...t},o=s.enableSmartExtraction!==!1;Wt.useEffect(()=>{const a=s.title||u.name;a&&(document.title=a);let r=s.description;if(!r&&o){const c=u.objects.filter(g=>{var f;return((f=g.geometry)==null?void 0:f.type)==="Text"}).sort((g,f)=>{var d,p;return(((d=f.geometry.text)==null?void 0:d.length)||0)-(((p=g.geometry.text)==null?void 0:p.length)||0)});c.length>0&&(r=c[0].geometry.text)}r&&(e("name","description",r),e("property","og:description",r)),s.keywords&&s.keywords.length>0&&e("name","keywords",s.keywords.join(", "));const l=s.ogImage||u.backgroundImage;l&&e("property","og:image",l),a&&e("property","og:title",a),e("property","og:type","website")},[s,u,o]);const e=(a,r,l)=>{let h=document.querySelector(`meta[${a}="${r}"]`);h||(h=document.createElement("meta"),h.setAttribute(a,r),document.head.appendChild(h)),h.setAttribute("content",l)},i=()=>{const a=[];return a.push(se.jsx("h1",{children:s.title||u.name},"artboard-title")),u.objects.forEach((l,h)=>{var c,g;if(!(l.visible===!1||l.isVisible===!1))if(((c=l.geometry)==null?void 0:c.type)==="Text"){const f=l.geometry.text;f&&(l.geometry.fontSize>24?a.push(se.jsx("h2",{children:f},l.id||h)):a.push(se.jsx("p",{children:f},l.id||h)))}else if(((g=l.geometry)==null?void 0:g.type)==="Image"){const f=l.geometry.src,d=l.altText||l.name||"Illustration";a.push(se.jsx("img",{src:f,alt:d},l.id||h))}else l.type==="Button"&&a.push(se.jsx("button",{children:l.name||"Button"},l.id||h))}),a},n=s.jsonLd||{"@context":"https://schema.org","@type":"VisualArtwork",name:s.title||u.name,description:s.description,image:s.ogImage||u.backgroundImage,abstract:"Animated interface created with ExodeUI"};return se.jsxs("div",{id:`exode-seo-${u.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(),se.jsx("script",{type:"application/ld+json",children:JSON.stringify(n)})]})},ri={version:"6.3.21"}.version;Nt.BehaviorSensor=oe,Nt.BehaviorType=X,Nt.ConditionOp=Ge,Nt.ExodeSEO=ai,Nt.ExodeUICanvas=ni,Nt.ExodeUIEngine=ns,Nt.LogicOp=bt,Nt.RapierPhysics=Ne,Nt.VERSION=ri,Nt.useExodeUI=oi,Object.defineProperty(Nt,Symbol.toStringTag,{value:"Module"})});
|