exodeui 6.3.13 → 6.3.14
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 +18 -18
- package/dist/index.mjs +901 -862
- package/dist/src/engine.d.ts +1 -0
- package/dist/src/types.d.ts +17 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,30 +1,30 @@
|
|
|
1
|
-
(function(At,Lt){typeof exports=="object"&&typeof module<"u"?Lt(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"],Lt):(At=typeof globalThis<"u"?globalThis:At||self,Lt(At.ExodeUIReact={},At.jsxRuntime,At.React,At.pretext,At.Rapier,At.LZString))})(this,function(At,Lt,xt,Zt,
|
|
2
|
-
`||j==="\r"?y.kinds[P]=2:y.kinds[P]=0}else y.kinds[P]=J}}B+=tt.length}y.fullText=x,y.maxFontSize
|
|
3
|
-
`||B[K]==="\r")&&(
|
|
4
|
-
`&&K++);y={...y,widths:x,indentApplied:!0}}if(!y)return{width:a,height:0,lineCount:0,lines:[]};let v=n;typeof v=="string"&&(v=parseFloat(v)),v>5&&o>0&&(v=v/o),r!==0&&(CanvasRenderingContext2D.prototype.measureText=b);let
|
|
1
|
+
(function(At,Lt){typeof exports=="object"&&typeof module<"u"?Lt(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"],Lt):(At=typeof globalThis<"u"?globalThis:At||self,Lt(At.ExodeUIReact={},At.jsxRuntime,At.React,At.pretext,At.Rapier,At.LZString))})(this,function(At,Lt,xt,Zt,Nt,we){"use strict";var cs=Object.defineProperty;var fs=(At,Lt,xt)=>Lt in At?cs(At,Lt,{enumerable:!0,configurable:!0,writable:!0,value:xt}):At[Lt]=xt;var ot=(At,Lt,xt)=>fs(At,typeof Lt!="symbol"?Lt+"":Lt,xt);function Ce(h){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(h){for(const s in h)if(s!=="default"){const o=Object.getOwnPropertyDescriptor(h,s);Object.defineProperty(t,s,o.get?o:{enumerable:!0,get:()=>h[s]})}}return t.default=h,Object.freeze(t)}const Ie=Ce(we);var W=(h=>(h.Proximity="Proximity",h.Magnetic="Magnetic",h.Repel="Repel",h.Orbit="Orbit",h.Vortex="Vortex",h.Fluid="Fluid",h.Elastic="Elastic",h.Holographic="Holographic",h.Sticky="Sticky",h.Dilation="Dilation",h.Parallax="Parallax",h.Noise="Noise",h.Float="Float",h.Pulse="Pulse",h.Draggable="Draggable",h.Scroll="Scroll",h.LookAt="LookAt",h.Glint="Glint",h.Scan="Scan",h.Ratchet="Ratchet",h.Jitter="Jitter",h.Follower="Follower",h.Wrap="Wrap",h.Typewriter="Typewriter",h.Scramble="Scramble",h.Wave="Wave",h.Bounce="Bounce",h.TextTrail="TextTrail",h.Reveal3D="Reveal3D",h.RevealSlide="RevealSlide",h.RevealBlur="RevealBlur",h.TextLiquid="TextLiquid",h.TextVortex="TextVortex",h.TextExplosion="TextExplosion",h.TextRain="TextRain",h.TextGravity="TextGravity",h.TextMatrix="TextMatrix",h.TextNeon="TextNeon",h.TextDissolve="TextDissolve",h.TextOrganic="TextOrganic",h.TextBreathe="TextBreathe",h.TextSpin="TextSpin",h.TextMagnet="TextMagnet",h.TextPerspective="TextPerspective",h.TextMirror="TextMirror",h.TextFloral="TextFloral",h.TextSmoke="TextSmoke",h.TextVariable="TextVariable",h.TextZing="TextZing",h.TextElastic="TextElastic",h.TextGlitch3D="TextGlitch3D",h.GlitchText="GlitchText",h.TextCounter="TextCounter",h.Squash="Squash",h.Spotlight="Spotlight",h.Lens="Lens",h.Gravity="Gravity",h.Velocity="Velocity",h.Shear="Shear",h))(W||{}),Bt=(h=>(h.Scale="Scale",h.Opacity="Opacity",h.RotateZ="RotateZ",h.RotateX="RotateX",h.RotateY="RotateY",h.PositionX="PositionX",h.PositionY="PositionY",h.SkewX="SkewX",h.Blur="Blur",h.Exposure="Exposure",h.HueShift="HueShift",h.Negative="Negative",h.CornerRadius="CornerRadius",h.StrokeWidth="StrokeWidth",h.BoxShadow="BoxShadow",h.FontSize="FontSize",h.LetterSpacing="LetterSpacing",h))(Bt||{}),oe=(h=>(h.Equal="Equal",h.NotEqual="NotEqual",h.GreaterThan="GreaterThan",h.LessThan="LessThan",h.GreaterEqual="GreaterEqual",h.LessEqual="LessEqual",h.IsTrue="IsTrue",h.IsFalse="IsFalse",h))(oe||{}),gt=(h=>(h.AND="AND",h.OR="OR",h.NOT="NOT",h.XOR="XOR",h.OBJECT="OBJECT",h.PROPERTY="PROPERTY",h.GET_PROPERTY="GET_PROPERTY",h.SET_PROPERTY="SET_PROPERTY",h.ADD="ADD",h.SUB="SUB",h.MUL="MUL",h.DIV="DIV",h.MOD="MOD",h.POW="POW",h.ABS="ABS",h.ROUND="ROUND",h.FLOOR="FLOOR",h.CEIL="CEIL",h.SIN="SIN",h.COS="COS",h.TAN="TAN",h.CLAMP="CLAMP",h.REMAP="REMAP",h.EQ="EQ",h.NEQ="NEQ",h.GT="GT",h.LT="LT",h.GTE="GTE",h.LTE="LTE",h.IF_ELSE="IF_ELSE",h.VALUE="VALUE",h.INPUT="INPUT",h.LOG="LOG",h.SCROLL_X="SCROLL_X",h.SCROLL_Y="SCROLL_Y",h.MOUSE_X="MOUSE_X",h.MOUSE_Y="MOUSE_Y",h.IS_MOUSE_DOWN="IS_MOUSE_DOWN",h.EFFECTOR="EFFECTOR",h.MONITOR="MONITOR",h.DELAY="DELAY",h))(gt||{});const Kt=new Map;function ae(h){var A;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:c=0,paragraphIndent:d=0,textCase:l="none",segments:f=[],enableSegments:g=!1}=h;let u=String(t||"");l==="uppercase"?u=u.toUpperCase():l==="lowercase"?u=u.toLowerCase():l==="capitalize"&&(u=u.replace(/\b\w/g,x=>x.toUpperCase()));const p=`${i} ${e} ${o}px "${s}", sans-serif`,m=`${u}|${p}|${r}|${c}|${d}|${g}|${JSON.stringify(f)}`;let y=Kt.get(m);const S=CanvasRenderingContext2D.prototype.measureText,b=function(x){const B=S.call(this,x);return r!==0&&x&&x.length>0?{...B,width:B.width+(x.length-1)*r}:B};if(!y){try{if(r!==0&&(CanvasRenderingContext2D.prototype.measureText=b),g&&f&&f.length>0){const x=f.map(B=>{let $=B.text||"";const K=B.textCase||l||"none";return K==="uppercase"?$.toUpperCase():K==="lowercase"?$.toLowerCase():K==="capitalize"?$.replace(/\b\w/g,tt=>tt.toUpperCase()):$}).join("");if(y=Zt.prepareWithSegments(x,p),y){let B=0,$=o;for(const K of f){let tt=K.text||"";if(!tt)continue;const rt=K.textCase||l||"none";rt==="uppercase"?tt=tt.toUpperCase():rt==="lowercase"?tt=tt.toLowerCase():rt==="capitalize"&&(tt=tt.replace(/\b\w/g,R=>R.toUpperCase()));const at=K.fontSize||o;at>$&&($=at);const V=`${K.fontStyle||i} ${K.fontWeight||e} ${at}px "${K.fontFamily||s}", sans-serif`,O=Zt.prepareWithSegments(tt,V);if(O&&O.widths)for(let R=0;R<O.widths.length;R++){const P=B+R;if(P<y.widths.length){y.widths[P]=O.widths[R];const J=O.kinds[R];if(J===2){const j=tt[R];j===`
|
|
2
|
+
`||j==="\r"?y.kinds[P]=2:y.kinds[P]=0}else y.kinds[P]=J}}B+=tt.length}y.fullText=x,y.maxFontSize=$}}else y=Zt.prepareWithSegments(u,p);y&&Kt.set(m,y)}catch(x){return console.error("[ExodeUI] Pretext prepare failed:",x),{width:a,height:0,lineCount:0,lines:[]}}finally{r!==0&&(CanvasRenderingContext2D.prototype.measureText=S)}if(Kt.size>500){const x=Kt.keys().next().value;x&&Kt.delete(x)}}if(d>0&&y&&y.widths&&!y.indentApplied){const x=[...y.widths],B=y.fullText||u;let $=!0;for(let K=0;K<B.length;K++)$&&x[K]!==void 0&&(x[K]+=d,$=!1),(B[K]===`
|
|
3
|
+
`||B[K]==="\r")&&($=!0,B[K]==="\r"&&B[K+1]===`
|
|
4
|
+
`&&K++);y={...y,widths:x,indentApplied:!0}}if(!y)return{width:a,height:0,lineCount:0,lines:[]};let v=n;typeof v=="string"&&(v=parseFloat(v)),v>5&&o>0&&(v=v/o),r!==0&&(CanvasRenderingContext2D.prototype.measureText=b);let w;try{const x=y.maxFontSize||o;if(a>=1e5){const B=u.split(/\r\n|\r|\n/);w={lines:B.map($=>({text:$,width:0})),height:B.length*(v*x),lineCount:B.length}}else w=Zt.layoutWithLines(y,a,v*x)}finally{r!==0&&(CanvasRenderingContext2D.prototype.measureText=S)}let k=(w==null?void 0:w.height)!==void 0&&w.height>0?w.height:(((A=w==null?void 0:w.lines)==null?void 0:A.length)||0)*v*o;if(c>0&&w&&w.lines&&w.lines.length>1){let x=0;const B=y.fullText||t;for(let $=0;$<w.lines.length-1;$++)x+=w.lines[$].text.length,(B[x]===`
|
|
5
5
|
`||B[x]==="\r")&&(k+=c,x++,B[x-1]==="\r"&&B[x]===`
|
|
6
|
-
`&&x++)}return{width:a,height:k,lineCount:(C==null?void 0:C.lineCount)||0,lines:(C==null?void 0:C.lines)||[]}}function re(h,t,s){let o=String(h||"").trim();if(o&&!isNaN(Number(o))&&!o.includes(" ")&&!o.endsWith("fr")&&!o.endsWith("px")&&!o.endsWith("%")){const r=Math.max(1,parseInt(o));o=new Array(r).fill("1fr").join(" ")}const e=o.split(/\s+/).filter(Boolean),i=new Array(e.length).fill(0);let n=t-(e.length-1)*s,a=0;if(e.forEach((r,c)=>{if(r.endsWith("px")){const p=parseFloat(r);i[c]=p,n-=p}else r.endsWith("fr")?a+=parseFloat(r):r==="auto"&&(i[c]=100,n-=100)}),a>0&&n>0){const r=n/a;e.forEach((c,p)=>{c.endsWith("fr")&&(i[p]=r*parseFloat(c))})}return i}function le(h,t,s){try{const o=h.autoLayout;return!o||!o.enabled?{childUpdates:[]}:(o.mode||"linear")==="grid"?Me(h,t,s):ke(h,t,s)}catch(o){return console.error("Layout Engine Error:",o),{childUpdates:[]}}}function ke(h,t,s){var rt,at;const o=h.autoLayout,{direction:e,spacing:i,padding:n,align:a,wrap:r}=o,c=e==="vertical",p=t.map(N=>{const O=s(N.id),$=N.geometry;let P=(O==null?void 0:O.width)??$.width??100,J=(O==null?void 0:O.height)??$.height??100;if($.type==="Ellipse"||$.type==="Polygon"||$.type==="Star"){const j=(O==null?void 0:O.radius)??$.radius??(O==null?void 0:O.outer_radius)??$.outer_radius??50;P=j*2,J=j*2}else if($.type==="Text"){const j=ae({text:(O==null?void 0:O.text)??$.text??"",fontFamily:$.fontFamily,fontSize:$.fontSize,fontWeight:$.fontWeight,fontStyle:$.fontStyle,lineHeight:$.lineHeight,width:$.width||200,letterSpacing:$.letterSpacing,paragraphSpacing:$.paragraphSpacing,segments:$.segments,enableSegments:$.enableSegments});J=j.height,$.width||(P=j.width)}return P*=N.transform.scale_x||1,J*=N.transform.scale_y||1,{id:N.id,w:P,h:J,original:N}});let l=h.width,f=h.height;const g=((rt=h.layoutProps)==null?void 0:rt.width)==="hug",d=((at=h.layoutProps)==null?void 0:at.height)==="hug",u=[];let m=[],y=0,S=0;const b=l-n.left-n.right,v=f-n.top-n.bottom;p.forEach(N=>{r&&m.length>0&&(c?S+i+N.h>v:y+i+N.w>b)?(u.push({children:m,width:y,height:S}),m=[N],y=N.w,S=N.h):(m.push(N),c?(y=Math.max(y,N.w),S+=(m.length>1?i:0)+N.h):(y+=(m.length>1?i:0)+N.w,S=Math.max(S,N.h)))}),m.length>0&&u.push({children:m,width:y,height:S}),g&&!c&&(l=Math.max(...u.map(N=>N.width),0)+n.left+n.right),d&&c&&(f=Math.max(...u.map(N=>N.height),0)+n.top+n.bottom);const C=[];let k=n.left,A=n.top;const x=a.toLowerCase(),B=x==="center"||x.endsWith("-center"),R=x.endsWith("-right"),K=x==="center"||x.startsWith("center-"),tt=x.startsWith("bottom-");return u.forEach(N=>{let O=k,$=A;c?K?$=n.top+(f-n.top-n.bottom-N.height)/2:tt&&($=f-n.bottom-N.height):B?O=n.left+(l-n.left-n.right-N.width)/2:R&&(O=l-n.right-N.width),N.children.forEach(P=>{var H,it;let J=O,j=$;c?B?J+=(N.width-P.w)/2:R&&(J+=N.width-P.w):K?j+=(N.height-P.h)/2:tt&&(j+=N.height-P.h);const lt=((H=P.original.layoutProps)==null?void 0:H.width)==="fill",V=((it=P.original.layoutProps)==null?void 0:it.height)==="fill";C.push({id:P.id,x:J+P.w/2-l/2,y:j+P.h/2-f/2,width:lt&&c?N.width:void 0,height:V?c?void 0:N.height:void 0}),c?$+=P.h+i:O+=P.w+i}),c?k+=N.width+i:A+=N.height+i}),{frameWidth:g?l:void 0,frameHeight:d?f:void 0,childUpdates:C}}function Me(h,t,s){const o=h.autoLayout;if(!o)return{childUpdates:[]};const{gridColumns:e,gridRows:i,columnGap:n=0,rowGap:a=0,padding:r,align:c}=o;let p=h.width,l=h.height;const f=p-r.left-r.right,g=l-r.top-r.bottom,d=re(e||"1fr",f,n),u=re(i||"auto",g,a),m=d.length>0?d.reduce((R,K)=>R+K,0)+(d.length-1)*n:0,y=u.length>0?u.reduce((R,K)=>R+K,0)+(u.length-1)*a:0,S=c.toLowerCase(),b=S==="center"||S.endsWith("-center"),v=S.endsWith("-right"),C=S==="center"||S.startsWith("center-"),k=S.startsWith("bottom-");let A=0,x=0;b?A=(f-m)/2:v&&(A=f-m),C?x=(g-y)/2:k&&(x=g-y);const B=[];return t.forEach((R,K)=>{var it,nt;const tt=K%d.length||0,rt=Math.floor(K/d.length)||0;rt>=u.length&&u.push(100);const at=d[tt],N=u[rt];let O=r.left+A+d.slice(0,tt).reduce((ft,M)=>ft+M+n,0),$=r.top+x+u.slice(0,rt).reduce((ft,M)=>ft+M+a,0);const P=s(R.id),J=R.geometry;let j=(P==null?void 0:P.width)??J.width??100,lt=(P==null?void 0:P.height)??J.height??100;if(J.type==="Ellipse"||J.type==="Polygon"||J.type==="Star"){const ft=(P==null?void 0:P.radius)??J.radius??(P==null?void 0:P.outer_radius)??J.outer_radius??50;j=ft*2,lt=ft*2}j*=R.transform.scale_x||1,lt*=R.transform.scale_y||1;let V=O,H=$;b?V+=(at-j)/2:v&&(V+=at-j),C?H+=(N-lt)/2:k&&(H+=N-lt),B.push({id:R.id,x:V+j/2-p/2,y:H+lt/2-l/2,width:((it=R.layoutProps)==null?void 0:it.width)==="fill"?at:void 0,height:((nt=R.layoutProps)==null?void 0:nt.height)==="fill"?N:void 0})}),{childUpdates:B}}class Te{constructor(){ot(this,"world",null);ot(this,"bodies",new Map);ot(this,"colliders",new Map);ot(this,"initialized",!1)}async init(t){this.initialized||(await Yt.init(),this.world=new Yt.World(new Yt.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?Yt.RigidBodyDesc.fixed():Yt.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=Yt.ColliderDesc.cuboid(t.width/2,t.height/2);break;case"Ellipse":e=Yt.ColliderDesc.ball(Math.max(t.width,t.height)/2);break;case"Triangle":case"Star":case"Polygon":e=Yt.ColliderDesc.cuboid(t.width/2,t.height/2);break;default:e=Yt.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 Yt.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 Yt.Vector2(s,o),!0)}applyForce(t,s,o){const e=this.bodies.get(t);e&&e.addForce(new Yt.Vector2(s,o),!0)}applyImpulse(t,s,o){const e=this.bodies.get(t);e&&e.applyImpulse(new Yt.Vector2(s,o),!0)}}const ce=h=>h,xe=h=>h>0?1:0,_e=h=>h<1?0:1,fe=h=>h*h,he=h=>h*(2-h),de=h=>h<.5?2*h*h:-1+(4-2*h)*h,Ee=h=>h*h*h,Pe=h=>--h*h*h+1,Oe=h=>h<.5?4*h*h*h:(h-1)*(2*h-2)*(2*h-2)+1,Ae=h=>h*h*h*h,Fe=h=>1- --h*h*h*h,Re=h=>h<.5?8*h*h*h*h:1-8*--h*h*h*h,$e=h=>h*h*h*h*h,Le=h=>1+--h*h*h*h*h,We=h=>h<.5?16*h*h*h*h*h:1+16*--h*h*h*h*h,De=h=>1-Math.cos(h*Math.PI/2),Be=h=>Math.sin(h*Math.PI/2),Ne=h=>-(Math.cos(Math.PI*h)-1)/2,Ye=h=>h===0?0:Math.pow(2,10*(h-1)),Ve=h=>h===1?1:1-Math.pow(2,-10*h),Xe=h=>h===0?0:h===1?1:h<.5?Math.pow(2,20*h-10)/2:(2-Math.pow(2,-20*h+10))/2,Ge=h=>1-Math.sqrt(1-h*h),ze=h=>Math.sqrt(1- --h*h),He=h=>h<.5?(1-Math.sqrt(1-4*h*h))/2:(Math.sqrt(1-(-2*h+2)*(-2*h+2))+1)/2,te=1.70158,ee=te*1.525,ue=te+1,Ue=h=>ue*h*h*h-te*h*h,qe=h=>1+ue*Math.pow(h-1,3)+te*Math.pow(h-1,2),Je=h=>h<.5?Math.pow(2*h,2)*((ee+1)*2*h-ee)/2:(Math.pow(2*h-2,2)*((ee+1)*(h*2-2)+ee)+2)/2,pe=2*Math.PI/3,ge=2*Math.PI/4.5,Qe=h=>h===0?0:h===1?1:-Math.pow(2,10*h-10)*Math.sin((h*10-10.75)*pe),Ke=h=>h===0?0:h===1?1:Math.pow(2,-10*h)*Math.sin((h*10-.75)*pe)+1,je=h=>h===0?0:h===1?1:h<.5?-(Math.pow(2,20*h-10)*Math.sin((20*h-11.125)*ge))/2:Math.pow(2,-20*h+10)*Math.sin((20*h-11.125)*ge)/2+1,se=h=>h<1/2.75?7.5625*h*h:h<2/2.75?7.5625*(h-=1.5/2.75)*h+.75:h<2.5/2.75?7.5625*(h-=2.25/2.75)*h+.9375:7.5625*(h-=2.625/2.75)*h+.984375,Ze=h=>1-se(1-h),ts=se,es=h=>h<.5?(1-se(1-2*h))/2:(1+se(2*h-1))/2,ne=new Map,jt=(h,t,s,o)=>{const e=`${h},${t},${s},${o}`;if(ne.has(e))return ne.get(e);const i=p=>(1-3*s+3*h)*p*p*p+(3*s-6*h)*p*p+3*h*p,n=p=>(1-3*o+3*t)*p*p*p+(3*o-6*t)*p*p+3*t*p,a=p=>3*(1-3*s+3*h)*p*p+2*(3*s-6*h)*p+3*h,r=p=>{let l=p;for(let f=0;f<8;f++){const g=i(l)-p;if(Math.abs(g)<1e-6)return l;const d=a(l);if(Math.abs(d)<1e-6)break;l=l-g/d}return l},c=p=>p===0?0:p===1?1:n(r(p));return ne.set(e,c),c},me=h=>{const t=h.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 jt(s,o,e,i)},ye={ease:jt(.25,.1,.25,1),"ease-in":jt(.42,0,1,1),"ease-out":jt(0,0,.58,1),"ease-in-out":jt(.42,0,.58,1)},ie={Linear:ce,EaseInQuad:fe,EaseOutQuad:he,EaseInOutQuad:de,EaseInCubic:Ee,EaseOutCubic:Pe,EaseInOutCubic:Oe,EaseInQuart:Ae,EaseOutQuart:Fe,EaseInOutQuart:Re,EaseInQuint:$e,EaseOutQuint:Le,EaseInOutQuint:We,EaseInSine:De,EaseOutSine:Be,EaseInOutSine:Ne,EaseInExpo:Ye,EaseOutExpo:Ve,EaseInOutExpo:Xe,EaseInCirc:Ge,EaseOutCirc:ze,EaseInOutCirc:He,EaseInBack:Ue,EaseOutBack:qe,EaseInOutBack:Je,EaseInElastic:Qe,EaseOutElastic:Ke,EaseInOutElastic:je,EaseInBounce:Ze,EaseOutBounce:ts,EaseInOutBounce:es,EaseIn:fe,EaseOut:he,EaseInOut:de,StepStart:xe,StepEnd:_e},ss=h=>{const t=h.trim(),s=t.toLowerCase();if(ie[t])return ie[t];const o=Object.keys(ie).find(i=>i.toLowerCase()===s);if(o)return ie[o];const e=Object.keys(be).find(i=>i.toLowerCase()===s);if(e){const i=me(be[e].value);if(i)return i}if(ye[s])return ye[s];if(s.startsWith("cubic-bezier")){const i=me(t);if(i)return i}return ce},be={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)"}};class ve{constructor(){ot(this,"artboard",null);ot(this,"objectStates",new Map);ot(this,"physicsEngine",null);ot(this,"activeStateMachine",null);ot(this,"inputs",new Map);ot(this,"inputNameMap",new Map);ot(this,"layerStates",new Map);ot(this,"pretextCache",new Map);ot(this,"pointerHistory",[]);ot(this,"MAX_HISTORY",200);ot(this,"imageCache",new Map);ot(this,"lastValidSvgImgMap",new Map);ot(this,"maskBuffer",null);ot(this,"maskCtx",null);ot(this,"lumaBuffer",null);ot(this,"lumaCtx",null);ot(this,"layout",{fit:"Contain",alignment:"Center"});ot(this,"onTrigger");ot(this,"onInputUpdate");ot(this,"onComponentChange");ot(this,"onToggle");ot(this,"onInputChange");ot(this,"onInputFocus");ot(this,"onInputBlur");ot(this,"onLog");ot(this,"onButtonClick");ot(this,"onGraphPointClick");ot(this,"justFiredTriggers",new Set);ot(this,"rootTransform",null);ot(this,"canvasWidth",0);ot(this,"canvasHeight",0);ot(this,"lastHoveredObjectId",null);ot(this,"_lastPointerPos",null);ot(this,"_prevPointerPos",null);ot(this,"focusedId",null);ot(this,"draggingSliderId",null);ot(this,"activeDropdownId",null);ot(this,"activeObjectId",null);ot(this,"draggingListViewId",null);ot(this,"scrollOffset",{x:0,y:0});ot(this,"_totalScroll",{x:0,y:0});ot(this,"draggingBehaviors",new Set);ot(this,"isMouseDown",!1);ot(this,"objectVelocities",new Map);ot(this,"currentTime",0);ot(this,"frameCount",0);ot(this,"fontLeadingFactors",{Inter:.35,Roboto:.45,Montserrat:.4,Outfit:.35,"Open Sans":.4,Poppins:.45,"Playfair Display":.35,Lora:.4,Lato:.35,"Bebas Neue":.45,Oswald:.4});ot(this,"onLogicUpdate");ot(this,"logicNodeValues",new Map);ot(this,"logicNodeState",new Map);ot(this,"pointerDownTimes",new Map);ot(this,"activeHoverIds",new Set);ot(this,"onNavigation");ot(this,"periodicTriggerTimes",new Map);ot(this,"wasInView",new Set);ot(this,"scrollProgressLastValue",new Map);ot(this,"debug_objectsRendered",0);ot(this,"debug_objectsTotal",0);ot(this,"lastRenderTime",0);ot(this,"debugMode",!1);ot(this,"activeTriggers",new Map);console.info("%c[ExodeUI Engine] Pixel-Perfect Parity Active (v6.3.10) - SVG Fill & Gradient Parity Active","color: #3b82f6; font-weight: bold; padding: 2px 4px; border-radius: 4px; background: rgba(59, 130, 246, 0.1)")}setTriggerCallback(t){this.onTrigger=t}setInputUpdateCallback(t){this.onInputUpdate=t}setComponentChangeCallback(t){this.onComponentChange=t}setToggleCallback(t){this.onToggle=t}setLogicUpdateCallback(t){this.onLogicUpdate=t}setInputChangeCallback(t){this.onInputChange=t}setButtonClickCallback(t){this.onButtonClick=t}setGraphPointClickCallback(t){this.onGraphPointClick=t}setNavigationCallback(t){this.onNavigation=t}ensurePathPoints(t){if(!t||t.type!=="Path"&&t.type!=="Subtract"&&t.type!=="Union"&&t.type!=="Intersect"&&t.type!=="Exclude"&&t.type!=="BooleanOperation")return;if(t.points&&t.points.length>0){if(t.is_closed===void 0&&t.isClosed===void 0&&t.data){const{isClosed:e}=this.svgPathToPoints(t.data);t.is_closed=e}return}if(!t.data)return;const{points:s,isClosed:o}=this.svgPathToPoints(t.data);t.points=s,t.is_closed===void 0&&(t.is_closed=o)}svgPathToPoints(t){const s=/([MLHVCSQTAZmlhvcsqtaz])([^MLHVCSQTAZmlhvcsqtaz]*)/g,o=/[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/g,e=[];let i=!1,n=0,a=0,r=0,c=0,p=0,l=0,f;for(;(f=s.exec(t))!==null;){const g=f[1],d=(f[2].match(o)||[]).map(parseFloat),u=g===g.toLowerCase(),m=g.toUpperCase();let y=0;const S=v=>{let C=d[y++];return u&&(C+=v?n:a),C},b=()=>({x:S(!0),y:S(!1)});switch(m){case"M":{const v=b();for(p=n=v.x,l=a=v.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a,moveTo:!0});y<d.length;){const C=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"L":for(;y<d.length;){const v=b();n=v.x,a=v.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break;case"H":for(;y<d.length;)n=S(!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=S(!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 v=b(),C=b(),k=b();if(e.length>0){const A=e[e.length-1];A.out_x=v.x,A.out_y=v.y}n=k.x,a=k.y,e.push({x:n,y:a,in_x:C.x,in_y:C.y,out_x:n,out_y:a}),r=C.x,c=C.y}break;case"S":for(;y<d.length;){const v={x:2*n-r,y:2*a-c},C=b(),k=b();if(e.length>0){const A=e[e.length-1];A.out_x=v.x,A.out_y=v.y}n=k.x,a=k.y,e.push({x:n,y:a,in_x:C.x,in_y:C.y,out_x:n,out_y:a}),r=C.x,c=C.y}break;case"Q":for(;y<d.length;){const v=b(),C=b();if(e.length>0){const k=e[e.length-1];k.out_x=k.x+2/3*(v.x-k.x),k.out_y=k.y+2/3*(v.y-k.y)}n=C.x,a=C.y,e.push({x:n,y:a,in_x:n+2/3*(v.x-n),in_y:a+2/3*(v.y-a),out_x:n,out_y:a}),r=v.x,c=v.y}break;case"T":for(;y<d.length;){const v={x:2*n-r,y:2*a-c},C=b();if(e.length>0){const k=e[e.length-1];k.out_x=k.x+2/3*(v.x-k.x),k.out_y=k.y+2/3*(v.y-k.y)}n=C.x,a=C.y,e.push({x:n,y:a,in_x:n+2/3*(v.x-n),in_y:a+2/3*(v.y-a),out_x:n,out_y:a}),r=v.x,c=v.y}break;case"Z":if(i=!0,e.length>0){const v=e[e.length-1];v.closePath=!0;const C=[...e].reverse().find(k=>k.moveTo)||e[0];C&&Math.hypot(C.x-v.x,C.y-v.y)<.1&&(C.in_x=v.in_x,C.in_y=v.in_y,e.pop(),e.length>0&&(e[e.length-1].closePath=!0))}n=p,a=l;break;default:if(d.length>=2){const v=b();n=v.x,a=v.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}}return{points:e,isClosed:i}}setOnLogCallback(t){this.onLog=t}debugLog(t){this.onLog&&this.onLog(t)}setInputFocusCallback(t){this.onInputFocus=t}setInputBlurCallback(t){this.onInputBlur=t}updateConstraint(t,s,o){var i;const e=(i=this.artboard)==null?void 0:i.objects.find(n=>n.id===t);e&&e.constraints&&e.constraints[s]&&(e.constraints[s]={...e.constraints[s],...o},o.useSpring===!1&&this.objectVelocities.delete(t))}setInternalInput(t,s){this.inputs.set(t,s),this.onInputUpdate&&this.onInputUpdate(t,s)}setLayout(t,s){this.layout={fit:t,alignment:s}}getActiveStateIds(t="Base Layer"){const s=this.layerStates.get(t);return s?s.currentStateIds:[]}getObjectState(t){return this.objectStates.get(t)}updateObjectOptions(t,s){const o=this.objectStates.get(t);o&&(o.options={...o.options,...s})}updateGraphData(t,s){var e,i;if(!this.artboard)return;const o=this.artboard.objects.find(n=>n.id===t||n.name===t);if(o&&((e=o.geometry)==null?void 0:e.type)==="LineGraph"){const n=o.geometry;!n.datasets||n.datasets.length===0?n.datasets=[{id:"default",label:"Runtime Data",data:s,lineColor:"#3b82f6",lineWidth:2,showArea:!1}]:n.datasets[0].data=s;const a=this.objectStates.get(o.id);a&&((i=a.geometry)==null?void 0:i.type)==="LineGraph"&&(!a.geometry.datasets||a.geometry.datasets.length===0?a.geometry.datasets=JSON.parse(JSON.stringify(n.datasets)):a.geometry.datasets[0].data=[...s]),n.datasets[0].inputId&&this.updateInput(n.datasets[0].inputId,s)}else this.updateInput(t,s)}load(t){var n,a;if(!t)return;let s=this.decompressStrings(t);const o=[],e=new Set,i=r=>{r&&r.forEach(c=>{if(e.has(c.id))return;const p={...c},l=p.childrenObjects||[];e.add(p.id),o.push(p),i(l)})};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(c=>{r.set(c.id,c),c.children||(c.children=[])}),this.artboard.objects.forEach(c=>{if(c.parentId){const p=r.get(c.parentId);p&&(p.children||(p.children=[]),p.children.includes(c.id)||p.children.push(c.id))}})}this.loadFonts(),this.preloadImages(this.artboard),this.reset(),this.advance(0)}preloadImages(t){if(!t||!t.objects)return;const s=o=>{if(!o||this.imageCache.has(o))return;const e=new Image;e.onload=()=>{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=Ie.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.artboard.objects.forEach(s=>{var n,a,r,c,p,l,f;const o=s.width??((n=s.geometry)==null?void 0:n.width)??0,e=s.height??((a=s.geometry)==null?void 0:a.height)??0,i=s.cornerRadius??s.corner_radius??((r=s.geometry)==null?void 0:r.corner_radius)??((c=s.geometry)==null?void 0:c.cornerRadius)??0;this.objectStates.set(s.id,{...s.transform||{},x:((p=s.transform)==null?void 0:p.x)??s.x??0,y:((l=s.transform)==null?void 0:l.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:((f=s.transform)==null?void 0:f.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 Te;const s=this.artboard.physics?{x:this.artboard.physics.gravity.x,y:this.artboard.physics.gravity.y}:{x:0,y:1};this.physicsEngine.init(s).then(()=>{var o;this.physicsEngine&&((o=this.artboard)==null||o.objects.forEach(e=>{var i,n;if((i=e.physics)!=null&&i.enabled&&e.type==="Shape"){const a=this.objectStates.get(e.id);if(!a)return;const r=e.geometry.width||100,c=e.geometry.height||100;this.physicsEngine.createBody({id:e.id,type:((n=e.geometry)==null?void 0:n.type)||"Rectangle",x:a.x,y:a.y,width:r,height:c,rotation:a.rotation*(Math.PI/180),isStatic:e.physics.bodyType==="Static",mass:e.physics.mass,friction:e.physics.friction,restitution:e.physics.restitution,frictionAir:e.physics.frictionAir,density:e.physics.density,isSensor:e.physics.isSensor})}}))})}this.artboard.stateVariables&&this.artboard.stateVariables.forEach(s=>{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(),this.loadFonts()}updateAutoLayout(){var e;if(!this.artboard)return;const t=new Map;this.artboard.objects.forEach(i=>t.set(i.id,i));const s=.15,o=i=>{i.forEach(n=>{const a=this.objectStates.get(n.id);if(a){const r=Math.abs(a.x-n.x),c=Math.abs(a.y-n.y);r>20||c>20?(a.x+=(n.x-a.x)*s,a.y+=(n.y-a.y)*s):(a.x=n.x,a.y=n.y),n.width!==void 0&&(a.width=n.width),n.height!==void 0&&(a.height=n.height)}})};if((e=this.artboard.autoLayout)!=null&&e.enabled){const i=this.artboard.objects.filter(a=>!a.parentId),n=le(this.artboard,i,a=>this.objectStates.get(a));o(n.childUpdates)}this.artboard.objects.forEach(i=>{var n;if(i.type==="Frame"&&((n=i.autoLayout)!=null&&n.enabled)&&i.children&&i.children.length>0){const a=i.children.map(p=>t.get(p)).filter(p=>!!p),r=this.objectStates.get(i.id);if(!r)return;const c=le(r,a,p=>this.objectStates.get(p));c.frameWidth!==void 0&&(r.width=c.frameWidth),c.frameHeight!==void 0&&(r.height=c.frameHeight),o(c.childUpdates)}})}loadFonts(){if(!this.artboard)return;const t=new Set;if(this.artboard.objects.forEach(n=>{n.geometry&&n.geometry.type==="Text"&&n.geometry.fontFamily&&t.add(n.geometry.fontFamily)}),this.artboard.animations.forEach(n=>{n.tracks.forEach(a=>{(a.property==="geometry.fontFamily"||a.property==="fontFamily")&&a.keyframes.forEach(r=>{r.value&&typeof r.value=="string"&&t.add(r.value)})})}),t.size===0)return;let s="";t.forEach(n=>{const a=n.replace(/ /g,"+");s+=`&family=${a}:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900`});const o="exodeui-google-fonts",e="exodeui-fontshare-fonts";if(s.length>0){const n=`https://fonts.googleapis.com/css2?display=swap${s}`;let a=document.getElementById(o);a||(a=document.createElement("link"),a.id=o,a.rel="stylesheet",document.head.appendChild(a)),a.href!==n&&(a.href=n)}const i=[];if(t.forEach(n=>{n.toLowerCase().includes("clash display")&&i.push("clash-display@200,300,400,500,600,700")}),i.length>0){const n=`https://api.fontshare.com/v2/css?f[]=${i.join("&f[]=")}&display=swap`;let a=document.getElementById(e);a||(a=document.createElement("link"),a.id=e,a.rel="stylesheet",document.head.appendChild(a)),a.href!==n&&(a.href=n)}document.fonts&&document.fonts.ready&&document.fonts.ready.then(()=>{this.pretextCache.clear(),this.advance(0)})}enterStates(t,s){var n;if(s.length===0)return;const o=this.layerStates.get(t);if(o&&o.currentStateIds.length===s.length&&s.every(r=>o.currentStateIds.includes(r))&&this.justFiredTriggers.size===0)return;const e=[];let i=0;if(this.artboard&&this.activeStateMachine){const a=this.activeStateMachine.layers.find(r=>r.name===t);if(a)for(const r of s){const c=a.states.find(p=>p.id===r);if(c){let p=null;c.animationId&&(p=this.artboard.animations.find(l=>l.id===c.animationId)||null),p||(p=this.artboard.animations.find(l=>{var f,g;return l.name===c.name||l.id===c.name||(c.name==="Entry"||c.id==="entry")&&(((f=l.name)==null?void 0:f.toLowerCase())==="onload"||((g=l.name)==null?void 0:g.toLowerCase())==="intro")})||null),p&&((n=this.artboard.animationFlow)!=null&&n.some(f=>(f.trigger==="on_load"||f.trigger==="after_delay")&&f.targetAnimationId===(p==null?void 0:p.id))||(e.push({animation:p,state:c}),i=Math.max(i,p.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 c=(n=this.activeStateMachine)==null?void 0:n.inputs.find(p=>p.id===t);c&&typeof c.value=="object"&&(o=c.value.type)}else{const c=this.inputNameMap.get(t);if(c&&c.length>0){const p=(a=this.activeStateMachine)==null?void 0:a.inputs.find(l=>l.id===c[0]);p&&typeof p.value=="object"&&(o=p.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(c=>this.setInternalInput(c,e)),o==="Trigger"&&e===!0&&(this.justFiredTriggers.add(t),i&&i.forEach(c=>this.justFiredTriggers.add(c))),Array.isArray(e)&&((r=this.artboard)==null||r.objects.forEach(c=>{if(c.inputId===t||c.name===t){const p=this.objectStates.get(c.id);p&&p.options&&(c.type==="ListView"||c.variant==="listview"?p.options.items=e:(c.type==="Dropdown"||c.variant==="dropdown")&&(p.options.optionsList=e))}})),this.evaluateTransitions(),this.evaluateVariableTriggers(t,e)}evaluateVariableTriggers(t,s){if(!this.artboard)return;const o=this.artboard.animationFlow||[],e=this.inputNameMap.get(t);o.forEach(i=>{if(i.trigger==="variable"&&i.conditionVariableId&&i.targetAnimationId&&(i.conditionVariableId===t||e&&e.includes(i.conditionVariableId))){const a=i.conditionOperator||"IsTrue",r=i.conditionValue;let c=!1;switch(a){case"Equal":case"==":c=s==r;break;case"NotEqual":case"!=":c=s!=r;break;case"GreaterThan":case">":c=s>r;break;case"LessThan":case"<":c=s<r;break;case"GreaterEqual":case">=":c=s>=r;break;case"LessEqual":case"<=":c=s<=r;break;case"IsTrue":c=!!s;break;case"IsFalse":c=!s;break}if(c){const p=i.delay||0;p<=0?this.triggerGlobalAnimation(i.targetAnimationId,i.subAnimationIds,i.loop,i.id):setTimeout(()=>this.triggerGlobalAnimation(i.targetAnimationId,i.subAnimationIds,i.loop,i.id),p)}}})}evaluateTransitions(){this.activeStateMachine&&(this.activeStateMachine.layers.forEach(t=>{const s=this.layerStates.get(t.name);if(!s||s.currentStateIds.length===0)return;const o=[];let e=!1;for(const i of s.currentStateIds){const n=t.states.find(r=>r.id===i);if(!n)continue;let a=!1;for(const r of n.transitions||[])this.checkConditions(r.conditions)&&(o.push(r.targetStateId),a=!0,e=!0);a||o.push(i)}if(!e){const i=this.findGlobalTransition(t,s.currentStateIds);i&&(o.length=0,o.push(i.targetStateId),e=!0,i.conditions&&(i.conditions||[]).forEach(n=>{var r;const a=(r=this.activeStateMachine)==null?void 0:r.inputs.find(c=>c.id===n.inputId);a&&typeof a.value=="object"&&a.value.type==="Trigger"&&this.setInternalInput(n.inputId,!1)}))}if(e){const i=Array.from(new Set(o));this.enterStates(t.name,i)}}),this.justFiredTriggers.size>0&&(this.justFiredTriggers.forEach(t=>{var o,e;this.setInternalInput(t,!1);const s=(o=this.activeStateMachine)==null?void 0:o.inputs.find(i=>i.id===t);s&&this.inputNameMap.has(s.name)&&((e=this.inputNameMap.get(s.name))==null||e.forEach(i=>this.setInternalInput(i,!1)))}),this.justFiredTriggers.clear()))}findGlobalTransition(t,s){for(const o of t.states)if(!(s.includes(o.id)&&this.justFiredTriggers.size===0)){for(const i of o.transitions||[])if(!(s.includes(i.targetStateId)&&this.justFiredTriggers.size===0)&&this.checkConditions(i.conditions))return i}return null}checkConditions(t){return!t||t.length===0?!0:t.every(s=>{const o=s.inputId,e=s.op,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,c,p;if(o.has(t))return this.inputs.get(t)??this.logicNodeValues.get(t)??0;o.add(t);const e=(r=(a=this.activeStateMachine)==null?void 0:a.logicNodes)==null?void 0:r.find(l=>l.id===t);if(e){const l=(g,d)=>{const u=e.inputs.find(m=>m.id===g);return u?u.sourceId?this.evaluateLogicTree(u.sourceId,u.sourceHandleId,o):u.value!==void 0?u.value:d:d};let f=0;switch(e.op){case gt.AND:f=l("a",!1)&&l("b",!1);break;case gt.OR:f=l("a",!1)||l("b",!1);break;case gt.NOT:f=!l("in",!1);break;case gt.XOR:f=!!l("a",!1)!=!!l("b",!1);break;case gt.OBJECT:f=e.name;break;case gt.PROPERTY:case gt.GET_PROPERTY:{const g=l("id","");if(!g){f=0;break}const d=e.name;if(!d||d==="GET_PROPERTY"||d==="PROPERTY"){f=0;break}const u=this.objectStates.get(g);if(!u){f=0;break}d in u?f=u[d]:f=this.resolvePath(u,d);break}case gt.SET_PROPERTY:{const g=l("id",""),d=l("value",void 0);if(!g||d===void 0){f=0;break}const u=e.name;if(!u||u==="SET_PROPERTY"){f=0;break}const m=this.objectStates.get(g);if(!m){f=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(u))m[u]=d,f=d;else{const S=u.split(".");let b=m;for(let C=0;C<S.length-1;C++){const k=S[C];b[k]===void 0&&(b[k]={}),b=b[k]}const v=S[S.length-1];b[v]=d,f=d}break}case gt.ADD:f=l("a",0)+l("b",0);break;case gt.SUB:f=l("a",0)-l("b",0);break;case gt.MUL:f=l("a",0)*l("b",0);break;case gt.DIV:{const g=l("b",1);f=g===0?0:l("a",0)/g;break}case gt.MOD:f=l("a",0)%l("b",1);break;case gt.POW:f=Math.pow(l("a",0),l("b",1));break;case gt.ABS:f=Math.abs(l("in",0));break;case gt.ROUND:f=Math.round(l("in",0));break;case gt.FLOOR:f=Math.floor(l("in",0));break;case gt.CEIL:f=Math.ceil(l("in",0));break;case gt.SIN:f=Math.sin(l("in",0));break;case gt.COS:f=Math.cos(l("in",0));break;case gt.TAN:f=Math.tan(l("in",0));break;case gt.CLAMP:{const g=l("in",0),d=l("min",0),u=l("max",1);f=Math.max(d,Math.min(u,g));break}case gt.REMAP:{const g=l("in",0),d=l("inMin",0),u=l("inMax",100),m=l("outMin",0),y=l("outMax",1);f=u===d?m:m+(g-d)*(y-m)/(u-d);break}case gt.EQ:f=l("a",0)==l("b",0);break;case gt.NEQ:f=l("a",0)!=l("b",0);break;case gt.GT:f=l("a",0)>l("b",0);break;case gt.LT:f=l("a",0)<l("b",0);break;case gt.GTE:f=l("a",0)>=l("b",0);break;case gt.LTE:f=l("a",0)<=l("b",0);break;case gt.IF_ELSE:f=l("cond",!1)?l("then",0):l("else",0);break;case gt.VALUE:f=e.value!==void 0?e.value:0;break;case gt.INPUT:f=this.inputs.get(e.name)??0;break;case gt.LOG:{const g=l("in","");this.debugLog(`[User Logic] ${g}`),f=g;break}case gt.SCROLL_X:f=this.inputs.get("scrollX")??0;break;case gt.SCROLL_Y:f=this.inputs.get("scrollY")??0;break;case gt.MOUSE_X:f=this.inputs.get("mouseX")??0;break;case gt.MOUSE_Y:f=this.inputs.get("mouseY")??0;break;case gt.IS_MOUSE_DOWN:f=this.inputs.get("isMouseDown")??!1;break;case gt.EFFECTOR:{const g=l("id",""),d=l("intensity",1),u=l("trigger",!0);if(!g||!u){f=0;break}const m=e.name;if(!m){f=0;break}const y=this.objectStates.get(g);if(!y){f=0;break}if(["glitch","halftone","pixelate","noise","acid_gradient","acid_rave","shimmer"].includes(m))y.style||(y.style={}),y.style.artEffect={enabled:!0,type:m,intensity:d},f=1;else{y.behaviors||(y.behaviors=[]);let b=y.behaviors.find(v=>v.type===m);b?(b.enabled=!0,b.settings||(b.settings={}),b.settings.intensity=d):(b={id:`eff_${Date.now()}_${m}`,type:m,enabled:!0,sensors:[],settings:{intensity:d}},y.behaviors.push(b)),f=1}break}case gt.MONITOR:{f=l("in",0);break}default:f=0;break}if(this.logicNodeValues.set(t,f),e.op===gt.DELAY){const g=l("delay",0),d=l("in",0);let u=this.logicNodeState.get(t);for(u||(u={queue:[]},this.logicNodeState.set(t,u)),u.queue.push({time:this.currentTime+g,value:d});u.queue.length>0&&u.queue[0].time<=this.currentTime;)u.lastValue=u.queue.shift().value;f=u.lastValue??0}return f}const i=(c=this.activeStateMachine)==null?void 0:c.inputs.find(l=>l.id===t||l.name===t);if(i&&i.sourceId&&!o.has(i.sourceId)){const l=this.evaluateLogicTree(i.sourceId,i.sourceHandleId,o);return this.inputs.set(i.id,l),l}let n=this.inputs.get(t)??(i?this.inputs.get(i.id):void 0);if((this.justFiredTriggers.has(t)||i&&this.justFiredTriggers.has(i.id))&&(n=!0),s&&n!==void 0){const l=(p=this.activeStateMachine)==null?void 0:p.inputs.find(f=>f.id===t);if(l&&l.value.type==="Number"&&typeof n=="number"){const f=l.value.defaultValue??l.value.value;if(s==="source-greater")return n>f;if(s==="source-less")return n<f;if(s==="source-equal")return n===f}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===gt.SET_PROPERTY||t.op===gt.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,c,p,l;if(o.phase==="entry")o.time+=t,o.time>=o.animation.duration&&((a=(n=(i=this.artboard)==null?void 0:i.objects.find(f=>f.id===e))==null?void 0:n.triggers)==null||a.find(f=>f.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 f=(p=(c=(r=this.artboard)==null?void 0:r.objects.find(u=>u.id===e))==null?void 0:c.triggers)==null?void 0:p.find(u=>u.id===o.triggerId),g=(f==null?void 0:f.duration)||0;o.elapsedHold+=t*1e3;let d=o.elapsedHold>=g;if((f==null?void 0:f.eventType)==="hover"&&!this.activeHoverIds.has(e)&&(d=!0),((f==null?void 0:f.eventType)==="onHold"||(f==null?void 0:f.eventType)==="pointerDown")&&!this.isMouseDown&&(d=!0),d)if(f!=null&&f.exitAnimationId){const u=(l=this.artboard)==null?void 0:l.animations.find(m=>m.id===f.exitAnimationId);u?(o.phase="exit",o.animation=u,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=>{const o=s.interactions||[];o.length!==0&&o.forEach(e=>{const i=e.triggers||[e.event||e.trigger];i&&i.forEach(n=>{var r,c,p;const a=n.toLowerCase();if(a==="on interval"||a==="oninterval"){const l=e.intervalValue||2e3,f=this.periodicTriggerTimes.get(e.id)||0;this.currentTime*1e3-f>=l&&(!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 l=e.delayValue||1e3;!this.periodicTriggerTimes.has(e.id)&&this.currentTime*1e3>=l&&(!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 l=this.objectStates.get(s.id);if(l&&l.visible!==!1){const f=this.getGlobalTransform(s.id),g=(((r=s.geometry)==null?void 0:r.width)||100)*(f.scale_x||1),d=(((c=s.geometry)==null?void 0:c.height)||100)*(f.scale_y||1),u=50,m=f.x+g/2>=-this.canvasWidth/2-u&&f.x-g/2<=this.canvasWidth/2+u&&f.y+d/2>=-this.canvasHeight/2-u&&f.y-d/2<=this.canvasHeight/2+u,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 l=Math.abs(this.scrollOffset.y)/(((p=this.artboard)==null?void 0:p.height)||1e3),f=this.scrollProgressLastValue.get(e.id)||0;Math.abs(l-f)>.001&&(this.scrollProgressLastValue.set(e.id,l),(e.action==="Set Input"||e.action==="setInput")&&this.updateInput(e.targetInputId,l))}})})})}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 p,l,f,g,d,u,m,y,S;const a=((p=o.constraints)==null?void 0:p[n])||{},r={...i,...a},c=r.strength??1;if(r.type==="Translation"){const b=this.getGlobalTransform(r.targetId);if(b){const v=r.offsetX||0,C=r.offsetY||0,k=b.x+v,A=b.y+C;if(r.useSpring){const B=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:R,y:K,vx:tt,vy:rt}=this.computeSpring(e.x,e.y,B.vx,B.vy,k,A,r,t);r.copyX&&(e.x=e.x+(R-e.x)*c),r.copyY&&(e.y=e.y+(K-e.y)*c),this.objectVelocities.set(s.id,{vx:tt,vy:rt})}else r.copyX&&(e.x=e.x+(k-e.x)*c),r.copyY&&(e.y=e.y+(A-e.y)*c);(l=r.limitX)!=null&&l.enabled&&(e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x))),(f=r.limitY)!=null&&f.enabled&&(e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)))}}else if(r.type==="Rotation"){const b=this.getGlobalTransform(r.targetId);if(b){let C=(b.rotation+(r.offset||0)-e.rotation)%360;C>180&&(C-=360),C<-180&&(C+=360),e.rotation=e.rotation+C*c}}else if(r.type==="Scale"){const b=this.getGlobalTransform(r.targetId);b&&(r.copyX&&(e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*c),r.copyY&&(e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*c))}else if(r.type==="Transform"){const b=this.getGlobalTransform(r.targetId);if(b){e.x=e.x+(b.x-e.x)*c,e.y=e.y+(b.y-e.y)*c;let v=(b.rotation-e.rotation)%360;v>180&&(v-=360),v<-180&&(v+=360),e.rotation=e.rotation+v*c,e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*c,e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*c}}else if(r.type==="FollowPointer"){const b=((g=this._lastPointerPos)==null?void 0:g.x)??e.x,v=((d=this._lastPointerPos)==null?void 0:d.y)??e.y;if(r.useSpring){const k=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:A,y:x,vx:B,vy:R}=this.computeSpring(e.x,e.y,k.vx,k.vy,b,v,r,t);e.x=A,e.y=x,this.objectVelocities.set(s.id,{vx:B,vy:R})}else e.x=e.x+(b-e.x)*c,e.y=e.y+(v-e.y)*c;(u=r.limitX)!=null&&u.enabled&&(e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x))),(m=r.limitY)!=null&&m.enabled&&(e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)))}else if(r.type==="Distance"){const b=this.getGlobalTransform(r.targetId);if(b){const v=e.x-b.x,C=e.y-b.y,k=Math.sqrt(v*v+C*C),A=r.distance||0;let x=k;switch(r.mode){case"exact":x=A;break;case"minimum":x=Math.max(A,k);break;case"maximum":x=Math.min(A,k);break;case"clamped":x=Math.max(0,Math.min(A,k));break}if(k>0){const B=e.x===b.x&&e.y===b.y?1:x/k;e.x=e.x+(b.x+v*B-e.x)*c,e.y=e.y+(b.y+C*B-e.y)*c}}}else if(r.type==="FollowPath"){const b=(y=this.artboard)==null?void 0:y.objects.find(v=>v.id===r.targetId);if(b){const v=this.getGlobalTransform(b.id);if(v){let C=b.geometry;if(b.type==="Frame"||b.type==="Group"||!C||C.type!=="Path"&&C.type!=="Ellipse"&&C.type!=="Rectangle"){const H=(S=this.artboard)==null?void 0:S.objects.find(it=>it.parentId===b.id&&it.type==="Shape"&&it.geometry&&(it.geometry.type==="Path"||it.geometry.type==="Ellipse"||it.geometry.type==="Rectangle"));H&&(C=H.geometry)}if(!C)return;const k=(r.distance||0)/100,A=v.width||C.width||0,x=v.height||C.height||0,B=this.getPointOnPath(C,A,x,k),R=v.rotation*Math.PI/180,K=Math.cos(R),tt=Math.sin(R),rt=B.x*v.scale_x*K-B.y*v.scale_y*tt,at=B.x*v.scale_x*tt+B.y*v.scale_y*K;let N=v.rotation+(r.offsetRotation||0);if(r.orient){const H=Math.cos(B.angle),it=Math.sin(B.angle),nt=H*v.scale_x*K-it*v.scale_y*tt,ft=H*v.scale_x*tt+it*v.scale_y*K;N=Math.atan2(ft,nt)*180/Math.PI+(r.offsetRotation||0)}const O=N*Math.PI/180,$=Math.cos(O),P=Math.sin(O),J=(r.offsetX||0)*$-(r.offsetY||0)*P,j=(r.offsetX||0)*P+(r.offsetY||0)*$,lt=v.x+rt+J,V=v.y+at+j;if(e.x=e.x+(lt-e.x)*c,e.y=e.y+(V-e.y)*c,r.orient){let H=(N-e.rotation)%360;H>180&&(H-=360),H<-180&&(H+=360),e.rotation=e.rotation+H*c}}}}else if(r.type==="IK"){const b=this.getGlobalTransform(r.targetId);b&&this.solveIK(s,b,r.boneCount||2,c)}}),s.constraints.some(i=>i.type!=="IK")){const i=this.globalToLocal(s.parentId,e);o.x=i.x,o.y=i.y,o.rotation=i.rotation,o.flip_x=i.scale_x<0,o.scale_x=Math.abs(i.scale_x),o.flip_y=i.scale_y<0,o.scale_y=Math.abs(i.scale_y)}})}getGlobalTransform(t){var p;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,rotation:0,scale_x:1,scale_y:1};const o=(p=this.artboard)==null?void 0:p.objects.find(l=>l.id===t);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)};const e=this.getGlobalTransform(o.parentId),i=e.rotation*Math.PI/180,n=Math.cos(i),a=Math.sin(i),r=e.x+(s.x*e.scale_x*n-s.y*e.scale_y*a),c=e.y+(s.x*e.scale_x*a+s.y*e.scale_y*n);return{x:r,y:c,rotation:e.rotation+s.rotation,scale_x:e.scale_x*(s.scale_x??1)*(s.flip_x?-1:1),scale_y:e.scale_y*(s.scale_y??1)*(s.flip_y?-1:1)}}globalToLocal(t,s){if(!t)return s;const o=this.getGlobalTransform(t),e=o.scale_x===0?0:1/o.scale_x,i=o.scale_y===0?0:1/o.scale_y,n=-o.rotation*Math.PI/180,a=Math.cos(n),r=Math.sin(n),c=s.x-o.x,p=s.y-o.y,l=(c*a-p*r)*e,f=(c*r+p*a)*i;return{x:l,y:f,rotation:s.rotation-o.rotation,scale_x:s.scale_x/(o.scale_x||1),scale_y:s.scale_y/(o.scale_y||1)}}solveIK(t,s,o,e){var c;const i=[];let n=t.id;for(let p=0;p<o&&n;p++){const l=(c=this.artboard)==null?void 0:c.objects.find(f=>f.id===n);if(!l)break;i.push({id:n,local:this.objectStates.get(n),global:this.getGlobalTransform(n)}),n=l.parentId}if(i.length<2)return;const a=i.reverse(),r=5;for(let p=0;p<r;p++){const l=this.getGlobalTransform(t.id);for(let f=a.length-2;f>=0;f--){const g=a[f],d=this.getGlobalTransform(g.id),u=l.x-d.x,m=l.y-d.y,y=s.x-d.x,S=s.y-d.y,b=Math.sqrt(u*u+m*m),v=Math.sqrt(y*y+S*S);if(b>.001&&v>.001){const C=Math.atan2(m,u);let A=(Math.atan2(S,y)-C)*180/Math.PI;A*=e;const x=this.objectStates.get(g.id);x&&(x.rotation+=A)}}}}computeSpring(t,s,o,e,i,n,a,r){const c=a.stiffness??100,p=a.damping??10,l=a.mass??1,f=-c*(t-i),g=-c*(s-n),d=-p*o,u=-p*e,m=(f+d)/l,y=(g+u)/l,S=o+m*r,b=e+y*r,v=t+S*r,C=s+b*r;return{x:v,y:C,vx:S,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,c,p,l,f;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=(g,d)=>{var v;let u=d;d==="click"?u="onClick":d==="down"?u="onPointerDown":d==="up"?u="onPointerUp":d==="blur"&&(u="onPointerLeave");const m=new Set([u]);d==="move"&&m.add("onPointerEnter").add("hover").add("onPointerLeave").add("blur"),u==="onClick"&&m.add("click"),u==="onPointerDown"&&m.add("pointerDown"),u==="onPointerUp"&&m.add("pointerUp");const y=["button","toggle","toggle_button","dropdown","listview","inputbox","slider"];return!!(g.type==="Component"&&y.includes(g.variant)||y.includes((v=g.type)==null?void 0:v.toLowerCase())||(g.interactions||[]).some(C=>m.has(C.event))||(g.triggers||[]).some(C=>m.has(C.eventType)))};let n=null;for(let g=this.artboard.objects.length-1;g>=0;g--){const d=this.artboard.objects[g],u=this.objectStates.get(d.id);if(u&&u.visible!==!1&&u.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 g=this.artboard.objects.find(d=>d.id===this.draggingSliderId);g&&this.updateSliderValueFromPointer(g,s,o);return}if(this.draggingListViewId){const g=this.artboard.objects.find(d=>d.id===this.draggingListViewId);g&&this.updateListViewScrollFromPointer(g);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(g=>g.type===W.Draggable))&&this.draggingBehaviors.add(a)),t==="move"?(a&&!this.activeHoverIds.has(a)&&this.activeHoverIds.add(a),this.activeHoverIds.forEach(g=>{g!==a&&this.activeHoverIds.delete(g)})):t==="blur"&&this.activeHoverIds.clear(),this.activeDropdownId&&t==="down"){const g=this.artboard.objects.find(d=>d.id===this.activeDropdownId);if(g&&(g.type==="Dropdown"||g.variant==="dropdown")){const d=this.objectStates.get(g.id),u=(d==null?void 0:d.options)||g.options||{},m=g.geometry||{},y=m.width??g.width??200,S=m.height??g.height??40,b=u.optionsList||[],v=u.itemHeight||32,C=u.listPadding??4,k=b.length*v+C*2,A=this.getWorldTransform(g.id),x=y*Math.abs(A.scaleX),B=S*Math.abs(A.scaleY),R=A.y+B/2+4,K=Math.abs(s-A.x)<=x/2,tt=o>=R&&o<=R+k*Math.abs(A.scaleY);if(K&&tt){const rt=Math.abs(A.scaleY),at=o-(R+C*rt),N=Math.floor(at/(v*rt));if(N>=0&&N<b.length){const O=b[N];u.selectedOption=O,u.isOpen=!1,this.activeDropdownId=null,g.inputId&&this.setInternalInput(g.inputId,O),this.onComponentChange&&this.onComponentChange({objectId:g.id,componentName:g.name,variant:"dropdown",property:"selectedOption",value:O})}return}else a!==this.activeDropdownId&&(u.isOpen=!1,this.activeDropdownId=null)}}if(e){let g=e,d=e;for(;d&&d.parentId;){const m=this.artboard.objects.find(y=>y.id===d.parentId);if(m&&m.type==="Component"){g=m;break}d=m}let u=t;if(t==="click"?u="onClick":t==="down"?u="onPointerDown":t==="up"?u="onPointerUp":t==="blur"&&(u="onPointerLeave"),this.fireEventForObject(e.id,u),g!==e&&this.fireEventForObject(g.id,u),g.type==="Component"&&g.variant==="toggle_button"&&t==="down"){const m=this.objectStates.get(g.id),y=(m==null?void 0:m.options)||g.options||{};y.checked=!y.checked,g.inputId&&this.setInternalInput(g.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:g.id,componentName:g.name,variant:"toggle_button",property:"checked",value:y.checked}),this.fireEventForObject(g.id,"Toggle"),this.fireEventForObject(g.id,y.checked?"Toggle True":"Toggle False")}if(g.type==="Component"&&g.variant==="toggle"&&t==="down"){const m=this.objectStates.get(g.id),y=(m==null?void 0:m.options)||g.options||{};y.checked=!y.checked,g.inputId&&this.setInternalInput(g.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:g.id,componentName:g.name,variant:"toggle",property:"checked",value:y.checked}),this.onToggle&&this.onToggle(g.name,y.checked),this.fireEventForObject(g.id,"Toggle"),this.fireEventForObject(g.id,y.checked?"Toggle True":"Toggle False")}if(g.type==="Component"&&g.variant==="dropdown"&&t==="down"){const m=this.objectStates.get(g.id),y=(m==null?void 0:m.options)||g.options||{},S=!y.isOpen;if(S&&this.activeDropdownId&&this.activeDropdownId!==g.id){const b=this.artboard.objects.find(v=>v.id===this.activeDropdownId);b&&b.options&&(b.options.isOpen=!1)}y.isOpen=S,this.activeDropdownId=S?g.id:null}if(g.type==="Component"&&g.variant==="button"&&t==="down"&&(this.onButtonClick&&this.onButtonClick(g.name,g.id),this.onComponentChange&&this.onComponentChange({objectId:g.id,componentName:g.name,variant:"button",property:"click",value:!0})),g.type==="Component"&&g.variant==="listview"&&t==="down"){this.draggingListViewId=g.id;const m=this.getListViewItemIndexAtPointer(g,s,o);if(m!==null){const y=g.options||{};y.activeItemIndex=m;const S=this.objectStates.get(g.id);S&&S.options&&(S.options.activeItemIndex=m);const b=(y.items||[])[m],v=typeof b=="string"?b:b.label||b.value||m;S&&S.options&&(S.options.selectedValue=v),g.inputId&&this.setInternalInput(g.inputId,v),this.onComponentChange&&(this.onComponentChange({objectId:g.id,componentName:g.name,variant:"listview",property:"activeItemIndex",value:m}),this.onComponentChange({objectId:g.id,componentName:g.name,variant:"listview",property:"selected",value:v}))}}if(g.type==="Component"&&g.variant==="slider"&&t==="down"&&(this.draggingSliderId=g.id,this.updateSliderValueFromPointer(g,s,o)),g.type==="LineGraph"&&(t==="down"||t==="click")){const m=g.geometry,y=(m==null?void 0:m.datasets)||[],S=this.objectStates.get(g.id),b=(S==null?void 0:S.width)||(m==null?void 0:m.width)||200,v=(S==null?void 0:S.height)||(m==null?void 0:m.height)||150,C=this.getWorldTransform(g.id),k=30,A=20,x=b-k,B=v-A;let R=1;y.forEach(rt=>{const at=Math.max(...rt.data||[0]);at>R&&(R=at)});let K=1/0,tt=null;y.forEach((rt,at)=>{const N=rt.data||[],O=x/Math.max(N.length-1,1);N.forEach(($,P)=>{const J=C.x-b/2+k+P*O,j=C.y+v/2-A-$/R*B,lt=Math.sqrt((s-J)**2+(o-j)**2);lt<K&&(K=lt,tt={dIdx:at,pIdx:P,val:$,label:rt.label||`Dataset ${at+1}`})})}),tt&&K<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:g.id,componentName:g.name,datasetIndex:tt.dIdx,pointIndex:tt.pIdx,value:tt.val,label:tt.label}),this.onComponentChange&&this.onComponentChange({objectId:g.id,componentName:g.name,variant:"linegraph",property:"click",value:(tt==null?void 0:tt.val)??null})}if(t==="click"){const m=(c=this.artboard)==null?void 0:c.objects.find(b=>b.id===e.id),y=this.focusedId,S=(m==null?void 0:m.type)==="InputBox"||(m==null?void 0:m.type)==="Component"&&m.variant==="inputbox";if(m&&S){if(this.focusedId=e.id,console.log(`[Engine] Focus set to: ${e.id}`),y!==this.focusedId){if(y){const b=(p=this.artboard)==null?void 0:p.objects.find(v=>v.id===y);b&&this.onInputBlur&&this.onInputBlur(b.name)}this.onInputFocus&&this.onInputFocus(m.name)}}else if(this.focusedId=null,y){const b=(l=this.artboard)==null?void 0:l.objects.find(v=>v.id===y);b&&this.onInputBlur&&this.onInputBlur(b.name)}}}else if(t==="click"){const g=this.focusedId;if(this.focusedId=null,g){const d=(f=this.artboard)==null?void 0:f.objects.find(u=>u.id===g);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 p,l,f,g,d;const o=(p=this.artboard)==null?void 0:p.objects.find(u=>u.id===t);if(!o)return;const e=new Set([s,s.toLowerCase()]),i=s.toLowerCase();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(u=>{const m=u.triggers||[u.event||u.trigger||"click"];return((u.triggerLogic||"OR")==="AND"?m.every(b=>e.has(b.toLowerCase())):m.some(b=>e.has(b.toLowerCase())))?u.conditions&&u.conditions.length>0?this.checkConditions(u.conditions):!0:!1});if(a){if(console.log(`[Engine] Interaction matched: ${s} -> Action: ${a.action}`),a.action==="setInput"||a.action==="Set Input"){let u=a.value||a.inputValue;u==="toggle"&&(u=!this.inputs.get(a.targetInputId)),this.updateInput(a.targetInputId,u)}else if(a.action==="Toggle Boolean"){const u=this.inputs.get(a.targetInputId);this.updateInput(a.targetInputId,!u)}else if(a.action==="fireTrigger")this.updateInput(a.targetInputId,!0);else if(a.action==="setProperty"){const u=a.targetObjectId||o.id,m=a.targetProperty;m&&this.updateObjectProperty(u,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 u=a.targetAnimationId;u==="__all__"?(f=(l=this.artboard)==null?void 0:l.animations)==null||f.forEach(m=>{this.triggerGlobalAnimation(m.id,a.subAnimationIds)}):u&&this.triggerGlobalAnimation(u,a.subAnimationIds)}else if(a.action==="setState"||a.action==="Set State"){const u=a.targetObjectId||o.id,y={...this.objectStates.get(u)||{},...a.value||{}};this.objectStates.set(u,y),console.log(`[Engine] State updated for ${u}:`,y)}else if(a.action==="Stop Animation"||a.action==="Pause Animation"){const u=a.targetAnimationId;u==="__all__"?this.layerStates.forEach((m,y)=>{y.startsWith("global_")&&this.layerStates.delete(y)}):u&&this.layerStates.forEach((m,y)=>{y.startsWith(`global_${u}_`)&&this.layerStates.delete(y)})}else if(a.action==="Switch to State"&&this.activeStateMachine){const u=a.targetState,m=this.activeStateMachine.layers.find(y=>y.states.some(S=>S.id===u||S.name===u));m&&(console.log(`[Engine] Switching Layer ${m.name} to State ${u}`),this.enterStates(m.name,[u]))}this.onTrigger&&this.onTrigger(s,a.action)}const c=(o.triggers||[]).find(u=>{const m=u.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&&u.conditions&&u.conditions.length>0?this.checkConditions(u.conditions):y});if(c&&c.entryAnimationId){console.log(`[Engine] Trigger matched: ${s} (as ${c.eventType}) -> Animation ${c.entryAnimationId}`);const u=(d=(g=this.artboard)==null?void 0:g.animations)==null?void 0:d.find(m=>m.id===c.entryAnimationId);u&&(this.activeTriggers.set(o.id,{triggerId:c.id,animation:u,time:0,phase:"entry",elapsedHold:0,filterObjectId:c.targetObjectId}),this.onTrigger&&this.onTrigger(c.name,u.name))}}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 f;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,scaleX:1,scaleY:1,rotation:0};const o=(f=this.artboard)==null?void 0:f.objects.find(g=>g.id===t);if(!o||!o.parentId)return{x:s.x,y:s.y,scaleX:s.scale_x??1,scaleY:s.scale_y??1,rotation:s.rotation??0};const e=this.getWorldTransform(o.parentId),i=e.rotation*(Math.PI/180),n=Math.cos(i),a=Math.sin(i),r=s.x*e.scaleX,c=s.y*e.scaleY,p=e.x+(r*n-c*a),l=e.y+(r*a+c*n);return{x:p,y:l,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,v;if(!this.objectStates.get(t.id))return!1;const i=((b=t.geometry)==null?void 0:b.width)??t.width??100,n=((v=t.geometry)==null?void 0:v.height)??t.height??100,a=this.getWorldTransform(t.id),r=s-a.x,c=o-a.y,p=-a.rotation*(Math.PI/180),l=Math.cos(p),f=Math.sin(p),g=r*l-c*f,d=r*f+c*l,u=a.scaleX,m=a.scaleY,y=i*Math.abs(u),S=n*Math.abs(m);return Math.abs(g)<=y/2&&Math.abs(d)<=S/2}updateSliderValueFromPointer(t,s,o){var A;const e=this.objectStates.get(t.id);if(!e)return;const i=t.options||{},n=((A=t.geometry)==null?void 0:A.width)??t.width??200,a=this.getWorldTransform(t.id),r=s-a.x,c=o-a.y,p=-a.rotation*(Math.PI/180),l=Math.cos(p),f=Math.sin(p),g=r*l-c*f,d=i.thumbWidth??16,u=n-d;let y=(g+u/2)/u;y=Math.max(0,Math.min(1,y));const S=i.min??0,b=i.max??100,v=i.step||1;let C=S+y*(b-S);v>0&&(C=Math.round(C/v)*v),C=Math.max(S,Math.min(b,C));const k=e.options||{};k.value!==C&&(e.options={...k,value:C},t.inputId&&this.setInternalInput(t.inputId,C),this.onComponentChange&&this.onComponentChange({objectId:t.id,componentName:t.name,variant:"slider",property:"value",value:C}))}applyAnimation(t,s,o){!t||!t.tracks||t.tracks.forEach(e=>{var l,f,g;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=(l=this.artboard)==null?void 0:l.objects.find(d=>d.id===i),a=((f=n==null?void 0:n.physics)==null?void 0:f.enabled)&&n.physics.bodyType!=="Static";let r=e.property;if(a&&(r==="x"||r==="y"||r==="rotation"))return;const c=this.objectStates.get(i);if(!c){this.frameCount%600===0&&this.debugLog(`Skipping track: Object ${i} not found in state`);return}const p=this.interpolate(e.keyframes,s);if(p!==void 0){if(this.frameCount%240===0){const d=(n==null?void 0:n.name)||i,u=typeof p=="object"?JSON.stringify(p).slice(0,50):p;this.debugLog(`[Anim] Applying ${r} = ${u} to ${d}`)}if(r.includes(".")){const d=(r||"").split(".");let u=c;for(let m=0;m<d.length-1;m++){if(typeof u[d[m]]!="object"||u[d[m]]===null){let y=n;for(let S=0;S<=m;S++)y=y?y[d[S]]:null;if(d[m]==="corner_radius"||d[m]==="cornerRadius"){const S=typeof u[d[m]]=="number"?u[d[m]]:typeof y=="number"?y:0;u[d[m]]={tl:S,tr:S,bl:S,br:S}}else u[d[m]]=y?JSON.parse(JSON.stringify(y)):{}}u=u[d[m]]}u[d[d.length-1]]=p,d[d.length-1]==="color"&&(d[d.length-2]==="fill"||d[d.length-2]==="stroke")&&(u.type="Solid")}else r==="fill"?(c.style||(c.style={}),c.style.fill=p):r==="stroke"?(c.style||(c.style={}),c.style.stroke=p):c[r]=p;if(this.physicsEngine&&((g=n==null?void 0:n.physics)!=null&&g.enabled)&&n.physics.bodyType==="Static")if(r==="x"){const d=this.physicsEngine.getPosition(i);d&&this.physicsEngine.setPosition(i,p,d.y)}else if(r==="y"){const d=this.physicsEngine.getPosition(i);d&&this.physicsEngine.setPosition(i,d.x,p)}else r==="rotation"&&this.physicsEngine.setRotation(i,p*(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=ss(o.easing)(n)),typeof o.value=="string"){if(o.value.startsWith("#"))return this.interpolateColor(o.value,e.value,n);const a=parseFloat(o.value),r=parseFloat(e.value);return!isNaN(a)&&!isNaN(r)?Math.round(a+(r-a)*n).toString():o.value}if(Array.isArray(o.value)&&Array.isArray(e.value))return o.value.length===e.value.length?o.value.map((a,r)=>{const c=e.value[r];return typeof a=="number"&&typeof c=="number"?a+(c-a)*n:n<.5?a:c}):n<.5?o.value:e.value;if(typeof o.value=="object"&&typeof e.value=="object"&&o.value!==null&&e.value!==null){if(o.value.width!==void 0&&o.value.color!==void 0)return this.interpolateStroke(o.value,e.value,n);if(o.value.type&&e.value.type)return this.interpolateFill(o.value,e.value,n);const a={};return new Set([...Object.keys(o.value),...Object.keys(e.value)]).forEach(c=>{const p=o.value[c],l=e.value[c];typeof p=="number"&&typeof l=="number"?a[c]=p+(l-p)*n:p===void 0?a[c]=l:l===void 0?a[c]=p:a[c]=n<.5?p:l}),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,u;const e=((u=(d=this.artboard)==null?void 0:d.tokens)==null?void 0:u.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),c=a(n),p=Math.round(r.r+(c.r-r.r)*o),l=Math.round(r.g+(c.g-r.g)*o),f=Math.round(r.b+(c.b-r.b)*o),g=m=>{const y=Math.max(0,Math.min(255,m)).toString(16);return y.length===1?"0"+y:y};return`#${g(p)}${g(l)}${g(f)}`}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 p;this.debug_objectsTotal=((p=this.artboard)==null?void 0:p.objects.length)||0,this.debug_objectsRendered=0;const e=performance.now();if(this.canvasWidth=s,this.canvasHeight=o,!this.artboard)return;t.clearRect(0,0,s,o);const 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 l=this.artboard.backgroundImage;let f=this.imageCache.get(l);if(f||(f=new Image,f.src=l,this.imageCache.set(l,f)),f.complete&&f.naturalWidth>0){t.save(),t.globalAlpha=this.normalizeOpacity(this.artboard.backgroundOpacity??100);const g=f.naturalWidth/f.naturalHeight,d=i/n;let u,m,y,S;d>g?(u=i,m=i/g):(m=n,u=n*g),y=-u/2,S=-m/2,t.drawImage(f,y,S,u,m),t.restore()}}t.beginPath(),t.rect(-i/2,-n/2,i,n),t.clip();const r=new Map;this.artboard.objects.forEach(l=>r.set(l.id,l)),this.artboard.objects.filter(l=>!l.parentId).map((l,f)=>{const g=this.objectStates.get(l.id),d=(g==null?void 0:g.zIndex)??f;return{obj:l,zIndex:d}}).sort((l,f)=>l.zIndex-f.zIndex).forEach(({obj:l})=>{this.renderObject(t,l,r)}),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,c=s*a.b+o*a.d+a.f,p=Math.sqrt(a.a*a.a+a.b*a.b),l=Math.sqrt(a.c*a.c+a.d*a.d),f=(e/2+n)*p,g=(i/2+n)*l;return r+f>=0&&r-f<=this.canvasWidth&&c+g>=0&&c-g<=this.canvasHeight}calculateTransform(t,s,o,e,i,n){let a=1,r=1,c=1;const p=o/e,l=t/s;switch(i){case"Contain":l>p?c=s/e:c=t/o,a=r=c;break;case"Cover":l>p?c=t/o:c=s/e,a=r=c;break;case"Fill":a=t/o,r=s/e;break;case"FitWidth":c=t/o,a=r=c;break;case"FitHeight":c=s/e,a=r=c;break;case"None":a=r=1;break;case"ScaleDown":c=Math.min(t/o,s/e),c>1&&(c=1),a=r=c;break;default:a=r=1;break}const f=o*a,g=e*r;let d=0,u=0;return n.includes("Left")?d=0:n.includes("Right")?d=t-f:d=(t-f)/2,n.includes("Top")?u=0:n.includes("Bottom")?u=s-g:u=(s-g)/2,{scaleX:a,scaleY:r,tx:d,ty:u}}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 u,m,y,S,b,v,C,k,A,x,B,R,K,tt,rt,at,N;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=(O,$,P,J,j)=>(this.drawRoundRect(t,O,$,P,J,j),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)||((u=s.geometry)==null?void 0:u.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 O=1/0,$=-1/0,P=1/0,J=-1/0;i.points.forEach(j=>{O=Math.min(O,j.x),$=Math.max($,j.x),P=Math.min(P,j.y),J=Math.max(J,j.y)}),a===0&&(a=$-O),r===0&&(r=J-P)}const c=O=>{if(O)return O.corner_radius??O.cornerRadius},p=c(e)??c(n)??c(i)??c(s.style)??c(s.geometry)??0,l={...i,width:a,height:r};if(delete l.cornerRadius,l.corner_radius=p,e.visible===!1)return;const f=s.repeaterConfig,g=f&&f.isEnabled&&f.count>1,d=g?f.count:1;for(let O=0;O<d;O++){let $=e.x,P=e.y,J=e.rotation,j=e.scale_x??1,lt=e.scale_y??1;if(g&&O>0){if(f.type==="Linear"){const st=f.offsetX||0,ct=f.offsetY||0,_=f.rotation||0,I=f.scale!==void 0?f.scale:1;$+=O*st,P+=O*ct,J+=O*_,j*=Math.pow(I,O),lt*=Math.pow(I,O)}else if(f.type==="Grid"){const st=f.cols||Math.ceil(Math.sqrt(f.count)),ct=f.gapX||0,_=f.gapY||0,I=Math.floor(O/st),D=O%st,Z=a+ct,bt=r+_;$+=D*Z,P+=I*bt}else if(f.type==="Radial"){const st=f.radius||100,ct=f.startAngle||0,I=(f.endAngle||360)-ct,D=f.count>1?I/(I===360?f.count:f.count-1):0,Z=ct+O*D,bt=Z*Math.PI/180;$=e.x+st*Math.cos(bt),P=e.y+st*Math.sin(bt),J+=Z}}const V=s.type==="Group"||s.type==="Frame"||s.type==="Component",H=a>0&&r>0;if(!V&&H){const st=(((y=n.shadow)==null?void 0:y.isEnabled)!==!1?(((S=n.shadow)==null?void 0:S.blur)||0)+10:0)+(((b=n.blur)==null?void 0:b.isEnabled)!==!1&&((v=n.blur)==null?void 0:v.radius)||0)+20;if(!this.isObjectInView(t,$,P,a,r,st))continue}this.debug_objectsRendered++,t.save();const it=[],nt=n.blur||((C=s.style)==null?void 0:C.blur);nt&&nt.amount>0&&it.push(`blur(${nt.amount}px)`);const ft=((k=i==null?void 0:i.type)==null?void 0:k.toLowerCase().includes("image"))||((A=s.type)==null?void 0:A.toLowerCase().includes("image")),M=n.adjustments&&Object.keys(n.adjustments).length>0?n.adjustments:null,Q=i!=null&&i.adjustments&&Object.keys(i.adjustments).length>0?i.adjustments:null,Y=ft?Q||M:M||Q,L=ft&&!Y?{exposure:0,contrast:0,saturation:100,temperature:0,tint:0,highlights:0,shadows:0,blur:0,negative:0,hue:0}:Y;if(e&&L&&(e.geometry=e.geometry||{},e.geometry.adjustments={...L}),L){const st=(L.exposure||0)/100,ct=L.contrast||0,_=1+(L.saturation||0)/100,I=(L.temperature||0)/200,D=(L.tint||0)/200,Z=(L.highlights||0)/500,bt=(L.shadows||0)/500;let Mt="",ht="SourceGraphic";if(st!==0&&(Mt+=`
|
|
6
|
+
`&&x++)}return{width:a,height:k,lineCount:(w==null?void 0:w.lineCount)||0,lines:(w==null?void 0:w.lines)||[]}}function re(h,t,s){let o=String(h||"").trim();if(o&&!isNaN(Number(o))&&!o.includes(" ")&&!o.endsWith("fr")&&!o.endsWith("px")&&!o.endsWith("%")){const r=Math.max(1,parseInt(o));o=new Array(r).fill("1fr").join(" ")}const e=o.split(/\s+/).filter(Boolean),i=new Array(e.length).fill(0);let n=t-(e.length-1)*s,a=0;if(e.forEach((r,c)=>{if(r.endsWith("px")){const d=parseFloat(r);i[c]=d,n-=d}else r.endsWith("fr")?a+=parseFloat(r):r==="auto"&&(i[c]=100,n-=100)}),a>0&&n>0){const r=n/a;e.forEach((c,d)=>{c.endsWith("fr")&&(i[d]=r*parseFloat(c))})}return i}function le(h,t,s){try{const o=h.autoLayout;return!o||!o.enabled?{childUpdates:[]}:(o.mode||"linear")==="grid"?Me(h,t,s):ke(h,t,s)}catch(o){return console.error("Layout Engine Error:",o),{childUpdates:[]}}}function ke(h,t,s){var rt,at;const o=h.autoLayout,{direction:e,spacing:i,padding:n,align:a,wrap:r}=o,c=e==="vertical",d=t.map(V=>{const O=s(V.id),R=V.geometry;let P=(O==null?void 0:O.width)??R.width??100,J=(O==null?void 0:O.height)??R.height??100;if(R.type==="Ellipse"||R.type==="Polygon"||R.type==="Star"){const j=(O==null?void 0:O.radius)??R.radius??(O==null?void 0:O.outer_radius)??R.outer_radius??50;P=j*2,J=j*2}else if(R.type==="Text"){const j=ae({text:(O==null?void 0:O.text)??R.text??"",fontFamily:R.fontFamily,fontSize:R.fontSize,fontWeight:R.fontWeight,fontStyle:R.fontStyle,lineHeight:R.lineHeight,width:R.width||200,letterSpacing:R.letterSpacing,paragraphSpacing:R.paragraphSpacing,segments:R.segments,enableSegments:R.enableSegments});J=j.height,R.width||(P=j.width)}return P*=V.transform.scale_x||1,J*=V.transform.scale_y||1,{id:V.id,w:P,h:J,original:V}});let l=h.width,f=h.height;const g=((rt=h.layoutProps)==null?void 0:rt.width)==="hug",u=((at=h.layoutProps)==null?void 0:at.height)==="hug",p=[];let m=[],y=0,S=0;const b=l-n.left-n.right,v=f-n.top-n.bottom;d.forEach(V=>{r&&m.length>0&&(c?S+i+V.h>v:y+i+V.w>b)?(p.push({children:m,width:y,height:S}),m=[V],y=V.w,S=V.h):(m.push(V),c?(y=Math.max(y,V.w),S+=(m.length>1?i:0)+V.h):(y+=(m.length>1?i:0)+V.w,S=Math.max(S,V.h)))}),m.length>0&&p.push({children:m,width:y,height:S}),g&&!c&&(l=Math.max(...p.map(V=>V.width),0)+n.left+n.right),u&&c&&(f=Math.max(...p.map(V=>V.height),0)+n.top+n.bottom);const w=[];let k=n.left,A=n.top;const x=a.toLowerCase(),B=x==="center"||x.endsWith("-center"),$=x.endsWith("-right"),K=x==="center"||x.startsWith("center-"),tt=x.startsWith("bottom-");return p.forEach(V=>{let O=k,R=A;c?K?R=n.top+(f-n.top-n.bottom-V.height)/2:tt&&(R=f-n.bottom-V.height):B?O=n.left+(l-n.left-n.right-V.width)/2:$&&(O=l-n.right-V.width),V.children.forEach(P=>{var H,it;let J=O,j=R;c?B?J+=(V.width-P.w)/2:$&&(J+=V.width-P.w):K?j+=(V.height-P.h)/2:tt&&(j+=V.height-P.h);const lt=((H=P.original.layoutProps)==null?void 0:H.width)==="fill",Y=((it=P.original.layoutProps)==null?void 0:it.height)==="fill";w.push({id:P.id,x:J+P.w/2-l/2,y:j+P.h/2-f/2,width:lt&&c?V.width:void 0,height:Y?c?void 0:V.height:void 0}),c?R+=P.h+i:O+=P.w+i}),c?k+=V.width+i:A+=V.height+i}),{frameWidth:g?l:void 0,frameHeight:u?f:void 0,childUpdates:w}}function Me(h,t,s){const o=h.autoLayout;if(!o)return{childUpdates:[]};const{gridColumns:e,gridRows:i,columnGap:n=0,rowGap:a=0,padding:r,align:c}=o;let d=h.width,l=h.height;const f=d-r.left-r.right,g=l-r.top-r.bottom,u=re(e||"1fr",f,n),p=re(i||"auto",g,a),m=u.length>0?u.reduce(($,K)=>$+K,0)+(u.length-1)*n:0,y=p.length>0?p.reduce(($,K)=>$+K,0)+(p.length-1)*a:0,S=c.toLowerCase(),b=S==="center"||S.endsWith("-center"),v=S.endsWith("-right"),w=S==="center"||S.startsWith("center-"),k=S.startsWith("bottom-");let A=0,x=0;b?A=(f-m)/2:v&&(A=f-m),w?x=(g-y)/2:k&&(x=g-y);const B=[];return t.forEach(($,K)=>{var it,nt;const tt=K%u.length||0,rt=Math.floor(K/u.length)||0;rt>=p.length&&p.push(100);const at=u[tt],V=p[rt];let O=r.left+A+u.slice(0,tt).reduce((ft,M)=>ft+M+n,0),R=r.top+x+p.slice(0,rt).reduce((ft,M)=>ft+M+a,0);const P=s($.id),J=$.geometry;let j=(P==null?void 0:P.width)??J.width??100,lt=(P==null?void 0:P.height)??J.height??100;if(J.type==="Ellipse"||J.type==="Polygon"||J.type==="Star"){const ft=(P==null?void 0:P.radius)??J.radius??(P==null?void 0:P.outer_radius)??J.outer_radius??50;j=ft*2,lt=ft*2}j*=$.transform.scale_x||1,lt*=$.transform.scale_y||1;let Y=O,H=R;b?Y+=(at-j)/2:v&&(Y+=at-j),w?H+=(V-lt)/2:k&&(H+=V-lt),B.push({id:$.id,x:Y+j/2-d/2,y:H+lt/2-l/2,width:((it=$.layoutProps)==null?void 0:it.width)==="fill"?at:void 0,height:((nt=$.layoutProps)==null?void 0:nt.height)==="fill"?V:void 0})}),{childUpdates:B}}class Te{constructor(){ot(this,"world",null);ot(this,"bodies",new Map);ot(this,"colliders",new Map);ot(this,"initialized",!1)}async init(t){this.initialized||(await Nt.init(),this.world=new Nt.World(new Nt.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?Nt.RigidBodyDesc.fixed():Nt.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=Nt.ColliderDesc.cuboid(t.width/2,t.height/2);break;case"Ellipse":e=Nt.ColliderDesc.ball(Math.max(t.width,t.height)/2);break;case"Triangle":case"Star":case"Polygon":e=Nt.ColliderDesc.cuboid(t.width/2,t.height/2);break;default:e=Nt.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 Nt.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 Nt.Vector2(s,o),!0)}applyForce(t,s,o){const e=this.bodies.get(t);e&&e.addForce(new Nt.Vector2(s,o),!0)}applyImpulse(t,s,o){const e=this.bodies.get(t);e&&e.applyImpulse(new Nt.Vector2(s,o),!0)}}const ce=h=>h,xe=h=>h>0?1:0,_e=h=>h<1?0:1,fe=h=>h*h,he=h=>h*(2-h),de=h=>h<.5?2*h*h:-1+(4-2*h)*h,Ee=h=>h*h*h,Pe=h=>--h*h*h+1,Oe=h=>h<.5?4*h*h*h:(h-1)*(2*h-2)*(2*h-2)+1,Ae=h=>h*h*h*h,Fe=h=>1- --h*h*h*h,$e=h=>h<.5?8*h*h*h*h:1-8*--h*h*h*h,Re=h=>h*h*h*h*h,Le=h=>1+--h*h*h*h*h,We=h=>h<.5?16*h*h*h*h*h:1+16*--h*h*h*h*h,De=h=>1-Math.cos(h*Math.PI/2),Be=h=>Math.sin(h*Math.PI/2),Ve=h=>-(Math.cos(Math.PI*h)-1)/2,Ne=h=>h===0?0:Math.pow(2,10*(h-1)),Ye=h=>h===1?1:1-Math.pow(2,-10*h),Ge=h=>h===0?0:h===1?1:h<.5?Math.pow(2,20*h-10)/2:(2-Math.pow(2,-20*h+10))/2,Xe=h=>1-Math.sqrt(1-h*h),ze=h=>Math.sqrt(1- --h*h),He=h=>h<.5?(1-Math.sqrt(1-4*h*h))/2:(Math.sqrt(1-(-2*h+2)*(-2*h+2))+1)/2,te=1.70158,ee=te*1.525,ue=te+1,Ue=h=>ue*h*h*h-te*h*h,qe=h=>1+ue*Math.pow(h-1,3)+te*Math.pow(h-1,2),Je=h=>h<.5?Math.pow(2*h,2)*((ee+1)*2*h-ee)/2:(Math.pow(2*h-2,2)*((ee+1)*(h*2-2)+ee)+2)/2,pe=2*Math.PI/3,ge=2*Math.PI/4.5,Qe=h=>h===0?0:h===1?1:-Math.pow(2,10*h-10)*Math.sin((h*10-10.75)*pe),Ke=h=>h===0?0:h===1?1:Math.pow(2,-10*h)*Math.sin((h*10-.75)*pe)+1,je=h=>h===0?0:h===1?1:h<.5?-(Math.pow(2,20*h-10)*Math.sin((20*h-11.125)*ge))/2:Math.pow(2,-20*h+10)*Math.sin((20*h-11.125)*ge)/2+1,se=h=>h<1/2.75?7.5625*h*h:h<2/2.75?7.5625*(h-=1.5/2.75)*h+.75:h<2.5/2.75?7.5625*(h-=2.25/2.75)*h+.9375:7.5625*(h-=2.625/2.75)*h+.984375,Ze=h=>1-se(1-h),ts=se,es=h=>h<.5?(1-se(1-2*h))/2:(1+se(2*h-1))/2,ne=new Map,jt=(h,t,s,o)=>{const e=`${h},${t},${s},${o}`;if(ne.has(e))return ne.get(e);const i=d=>(1-3*s+3*h)*d*d*d+(3*s-6*h)*d*d+3*h*d,n=d=>(1-3*o+3*t)*d*d*d+(3*o-6*t)*d*d+3*t*d,a=d=>3*(1-3*s+3*h)*d*d+2*(3*s-6*h)*d+3*h,r=d=>{let l=d;for(let f=0;f<8;f++){const g=i(l)-d;if(Math.abs(g)<1e-6)return l;const u=a(l);if(Math.abs(u)<1e-6)break;l=l-g/u}return l},c=d=>d===0?0:d===1?1:n(r(d));return ne.set(e,c),c},me=h=>{const t=h.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 jt(s,o,e,i)},ye={ease:jt(.25,.1,.25,1),"ease-in":jt(.42,0,1,1),"ease-out":jt(0,0,.58,1),"ease-in-out":jt(.42,0,.58,1)},ie={Linear:ce,EaseInQuad:fe,EaseOutQuad:he,EaseInOutQuad:de,EaseInCubic:Ee,EaseOutCubic:Pe,EaseInOutCubic:Oe,EaseInQuart:Ae,EaseOutQuart:Fe,EaseInOutQuart:$e,EaseInQuint:Re,EaseOutQuint:Le,EaseInOutQuint:We,EaseInSine:De,EaseOutSine:Be,EaseInOutSine:Ve,EaseInExpo:Ne,EaseOutExpo:Ye,EaseInOutExpo:Ge,EaseInCirc:Xe,EaseOutCirc:ze,EaseInOutCirc:He,EaseInBack:Ue,EaseOutBack:qe,EaseInOutBack:Je,EaseInElastic:Qe,EaseOutElastic:Ke,EaseInOutElastic:je,EaseInBounce:Ze,EaseOutBounce:ts,EaseInOutBounce:es,EaseIn:fe,EaseOut:he,EaseInOut:de,StepStart:xe,StepEnd:_e},ss=h=>{const t=h.trim(),s=t.toLowerCase();if(ie[t])return ie[t];const o=Object.keys(ie).find(i=>i.toLowerCase()===s);if(o)return ie[o];const e=Object.keys(be).find(i=>i.toLowerCase()===s);if(e){const i=me(be[e].value);if(i)return i}if(ye[s])return ye[s];if(s.startsWith("cubic-bezier")){const i=me(t);if(i)return i}return ce},be={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)"}};class ve{constructor(){ot(this,"artboard",null);ot(this,"objectStates",new Map);ot(this,"physicsEngine",null);ot(this,"activeStateMachine",null);ot(this,"inputs",new Map);ot(this,"inputNameMap",new Map);ot(this,"layerStates",new Map);ot(this,"pretextCache",new Map);ot(this,"pointerHistory",[]);ot(this,"MAX_HISTORY",200);ot(this,"imageCache",new Map);ot(this,"lastValidSvgImgMap",new Map);ot(this,"maskBuffer",null);ot(this,"maskCtx",null);ot(this,"lumaBuffer",null);ot(this,"lumaCtx",null);ot(this,"layout",{fit:"Contain",alignment:"Center"});ot(this,"onTrigger");ot(this,"onInputUpdate");ot(this,"onComponentChange");ot(this,"onToggle");ot(this,"onInputChange");ot(this,"onInputFocus");ot(this,"onInputBlur");ot(this,"onLog");ot(this,"onButtonClick");ot(this,"onGraphPointClick");ot(this,"justFiredTriggers",new Set);ot(this,"rootTransform",null);ot(this,"canvasWidth",0);ot(this,"canvasHeight",0);ot(this,"lastHoveredObjectId",null);ot(this,"_lastPointerPos",null);ot(this,"_prevPointerPos",null);ot(this,"focusedId",null);ot(this,"draggingSliderId",null);ot(this,"activeDropdownId",null);ot(this,"activeObjectId",null);ot(this,"draggingListViewId",null);ot(this,"scrollOffset",{x:0,y:0});ot(this,"_totalScroll",{x:0,y:0});ot(this,"draggingBehaviors",new Set);ot(this,"isMouseDown",!1);ot(this,"objectVelocities",new Map);ot(this,"currentTime",0);ot(this,"frameCount",0);ot(this,"fontLeadingFactors",{Inter:.35,Roboto:.45,Montserrat:.4,Outfit:.35,"Open Sans":.4,Poppins:.45,"Playfair Display":.35,Lora:.4,Lato:.35,"Bebas Neue":.45,Oswald:.4});ot(this,"onLogicUpdate");ot(this,"logicNodeValues",new Map);ot(this,"logicNodeState",new Map);ot(this,"pointerDownTimes",new Map);ot(this,"activeHoverIds",new Set);ot(this,"onNavigation");ot(this,"periodicTriggerTimes",new Map);ot(this,"wasInView",new Set);ot(this,"scrollProgressLastValue",new Map);ot(this,"debug_objectsRendered",0);ot(this,"debug_objectsTotal",0);ot(this,"lastRenderTime",0);ot(this,"debugMode",!1);ot(this,"activeTriggers",new Map);console.info("%c[ExodeUI Engine] Pixel-Perfect Parity Active (v6.3.10) - SVG Fill & Gradient Parity Active","color: #3b82f6; font-weight: bold; padding: 2px 4px; border-radius: 4px; background: rgba(59, 130, 246, 0.1)")}setTriggerCallback(t){this.onTrigger=t}setInputUpdateCallback(t){this.onInputUpdate=t}setComponentChangeCallback(t){this.onComponentChange=t}setToggleCallback(t){this.onToggle=t}setLogicUpdateCallback(t){this.onLogicUpdate=t}setInputChangeCallback(t){this.onInputChange=t}setButtonClickCallback(t){this.onButtonClick=t}setGraphPointClickCallback(t){this.onGraphPointClick=t}setNavigationCallback(t){this.onNavigation=t}ensurePathPoints(t){if(!t||t.type!=="Path"&&t.type!=="Subtract"&&t.type!=="Union"&&t.type!=="Intersect"&&t.type!=="Exclude"&&t.type!=="BooleanOperation")return;if(t.points&&t.points.length>0){if(t.is_closed===void 0&&t.isClosed===void 0&&t.data){const{isClosed:e}=this.svgPathToPoints(t.data);t.is_closed=e}return}if(!t.data)return;const{points:s,isClosed:o}=this.svgPathToPoints(t.data);t.points=s,t.is_closed===void 0&&(t.is_closed=o)}svgPathToPoints(t){const s=/([MLHVCSQTAZmlhvcsqtaz])([^MLHVCSQTAZmlhvcsqtaz]*)/g,o=/[-+]?(?:\d*\.\d+|\d+)(?:[eE][-+]?\d+)?/g,e=[];let i=!1,n=0,a=0,r=0,c=0,d=0,l=0,f;for(;(f=s.exec(t))!==null;){const g=f[1],u=(f[2].match(o)||[]).map(parseFloat),p=g===g.toLowerCase(),m=g.toUpperCase();let y=0;const S=v=>{let w=u[y++];return p&&(w+=v?n:a),w},b=()=>({x:S(!0),y:S(!1)});switch(m){case"M":{const v=b();for(d=n=v.x,l=a=v.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a,moveTo:!0});y<u.length;){const w=b();n=w.x,a=w.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}case"L":for(;y<u.length;){const v=b();n=v.x,a=v.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break;case"H":for(;y<u.length;)n=S(!0),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"V":for(;y<u.length;)a=S(!1),e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a});break;case"C":for(;y<u.length;){const v=b(),w=b(),k=b();if(e.length>0){const A=e[e.length-1];A.out_x=v.x,A.out_y=v.y}n=k.x,a=k.y,e.push({x:n,y:a,in_x:w.x,in_y:w.y,out_x:n,out_y:a}),r=w.x,c=w.y}break;case"S":for(;y<u.length;){const v={x:2*n-r,y:2*a-c},w=b(),k=b();if(e.length>0){const A=e[e.length-1];A.out_x=v.x,A.out_y=v.y}n=k.x,a=k.y,e.push({x:n,y:a,in_x:w.x,in_y:w.y,out_x:n,out_y:a}),r=w.x,c=w.y}break;case"Q":for(;y<u.length;){const v=b(),w=b();if(e.length>0){const k=e[e.length-1];k.out_x=k.x+2/3*(v.x-k.x),k.out_y=k.y+2/3*(v.y-k.y)}n=w.x,a=w.y,e.push({x:n,y:a,in_x:n+2/3*(v.x-n),in_y:a+2/3*(v.y-a),out_x:n,out_y:a}),r=v.x,c=v.y}break;case"T":for(;y<u.length;){const v={x:2*n-r,y:2*a-c},w=b();if(e.length>0){const k=e[e.length-1];k.out_x=k.x+2/3*(v.x-k.x),k.out_y=k.y+2/3*(v.y-k.y)}n=w.x,a=w.y,e.push({x:n,y:a,in_x:n+2/3*(v.x-n),in_y:a+2/3*(v.y-a),out_x:n,out_y:a}),r=v.x,c=v.y}break;case"Z":if(i=!0,e.length>0){const v=e[e.length-1];v.closePath=!0;const w=[...e].reverse().find(k=>k.moveTo)||e[0];w&&Math.hypot(w.x-v.x,w.y-v.y)<.1&&(w.in_x=v.in_x,w.in_y=v.in_y,e.pop(),e.length>0&&(e[e.length-1].closePath=!0))}n=d,a=l;break;default:if(u.length>=2){const v=b();n=v.x,a=v.y,e.push({x:n,y:a,in_x:n,in_y:a,out_x:n,out_y:a})}break}}return{points:e,isClosed:i}}setOnLogCallback(t){this.onLog=t}debugLog(t){this.onLog&&this.onLog(t)}setInputFocusCallback(t){this.onInputFocus=t}setInputBlurCallback(t){this.onInputBlur=t}updateConstraint(t,s,o){var i;const e=(i=this.artboard)==null?void 0:i.objects.find(n=>n.id===t);e&&e.constraints&&e.constraints[s]&&(e.constraints[s]={...e.constraints[s],...o},o.useSpring===!1&&this.objectVelocities.delete(t))}setInternalInput(t,s){this.inputs.set(t,s),this.onInputUpdate&&this.onInputUpdate(t,s)}setLayout(t,s){this.layout={fit:t,alignment:s}}getActiveStateIds(t="Base Layer"){const s=this.layerStates.get(t);return s?s.currentStateIds:[]}getObjectState(t){return this.objectStates.get(t)}updateObjectOptions(t,s){const o=this.objectStates.get(t);o&&(o.options={...o.options,...s})}updateGraphData(t,s){var e,i;if(!this.artboard)return;const o=this.artboard.objects.find(n=>n.id===t||n.name===t);if(o&&((e=o.geometry)==null?void 0:e.type)==="LineGraph"){const n=o.geometry;!n.datasets||n.datasets.length===0?n.datasets=[{id:"default",label:"Runtime Data",data:s,lineColor:"#3b82f6",lineWidth:2,showArea:!1}]:n.datasets[0].data=s;const a=this.objectStates.get(o.id);a&&((i=a.geometry)==null?void 0:i.type)==="LineGraph"&&(!a.geometry.datasets||a.geometry.datasets.length===0?a.geometry.datasets=JSON.parse(JSON.stringify(n.datasets)):a.geometry.datasets[0].data=[...s]),n.datasets[0].inputId&&this.updateInput(n.datasets[0].inputId,s)}else this.updateInput(t,s)}load(t){var n,a;if(!t)return;let s=this.decompressStrings(t);const o=[],e=new Set,i=r=>{r&&r.forEach(c=>{if(e.has(c.id))return;const d={...c},l=d.childrenObjects||[];e.add(d.id),o.push(d),i(l)})};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(c=>{r.set(c.id,c),c.children||(c.children=[])}),this.artboard.objects.forEach(c=>{if(c.parentId){const d=r.get(c.parentId);d&&(d.children||(d.children=[]),d.children.includes(c.id)||d.children.push(c.id))}})}this.loadFonts(),this.preloadImages(this.artboard),this.reset(),this.advance(0)}preloadImages(t){if(!t||!t.objects)return;const s=o=>{if(!o||this.imageCache.has(o))return;const e=new Image;e.onload=()=>{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=Ie.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.artboard.objects.forEach(s=>{var n,a,r,c,d,l,f;const o=s.width??((n=s.geometry)==null?void 0:n.width)??0,e=s.height??((a=s.geometry)==null?void 0:a.height)??0,i=s.cornerRadius??s.corner_radius??((r=s.geometry)==null?void 0:r.corner_radius)??((c=s.geometry)==null?void 0:c.cornerRadius)??0;this.objectStates.set(s.id,{...s.transform||{},x:((d=s.transform)==null?void 0:d.x)??s.x??0,y:((l=s.transform)==null?void 0:l.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:((f=s.transform)==null?void 0:f.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 Te;const s=this.artboard.physics?{x:this.artboard.physics.gravity.x,y:this.artboard.physics.gravity.y}:{x:0,y:1};this.physicsEngine.init(s).then(()=>{var o;this.physicsEngine&&((o=this.artboard)==null||o.objects.forEach(e=>{var i,n;if((i=e.physics)!=null&&i.enabled&&e.type==="Shape"){const a=this.objectStates.get(e.id);if(!a)return;const r=e.geometry.width||100,c=e.geometry.height||100;this.physicsEngine.createBody({id:e.id,type:((n=e.geometry)==null?void 0:n.type)||"Rectangle",x:a.x,y:a.y,width:r,height:c,rotation:a.rotation*(Math.PI/180),isStatic:e.physics.bodyType==="Static",mass:e.physics.mass,friction:e.physics.friction,restitution:e.physics.restitution,frictionAir:e.physics.frictionAir,density:e.physics.density,isSensor:e.physics.isSensor})}}))})}this.artboard.stateVariables&&this.artboard.stateVariables.forEach(s=>{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(),this.loadFonts()}updateAutoLayout(){var e;if(!this.artboard)return;const t=new Map;this.artboard.objects.forEach(i=>t.set(i.id,i));const s=.15,o=i=>{i.forEach(n=>{const a=this.objectStates.get(n.id);if(a){const r=Math.abs(a.x-n.x),c=Math.abs(a.y-n.y);r>20||c>20?(a.x+=(n.x-a.x)*s,a.y+=(n.y-a.y)*s):(a.x=n.x,a.y=n.y),n.width!==void 0&&(a.width=n.width),n.height!==void 0&&(a.height=n.height)}})};if((e=this.artboard.autoLayout)!=null&&e.enabled){const i=this.artboard.objects.filter(a=>!a.parentId),n=le(this.artboard,i,a=>this.objectStates.get(a));o(n.childUpdates)}this.artboard.objects.forEach(i=>{var n;if(i.type==="Frame"&&((n=i.autoLayout)!=null&&n.enabled)&&i.children&&i.children.length>0){const a=i.children.map(d=>t.get(d)).filter(d=>!!d),r=this.objectStates.get(i.id);if(!r)return;const c=le(r,a,d=>this.objectStates.get(d));c.frameWidth!==void 0&&(r.width=c.frameWidth),c.frameHeight!==void 0&&(r.height=c.frameHeight),o(c.childUpdates)}})}loadFonts(){if(!this.artboard)return;const t=new Set;if(this.artboard.objects.forEach(n=>{n.geometry&&n.geometry.type==="Text"&&n.geometry.fontFamily&&t.add(n.geometry.fontFamily)}),this.artboard.animations.forEach(n=>{n.tracks.forEach(a=>{(a.property==="geometry.fontFamily"||a.property==="fontFamily")&&a.keyframes.forEach(r=>{r.value&&typeof r.value=="string"&&t.add(r.value)})})}),t.size===0)return;let s="";t.forEach(n=>{const a=n.replace(/ /g,"+");s+=`&family=${a}:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900`});const o="exodeui-google-fonts",e="exodeui-fontshare-fonts";if(s.length>0){const n=`https://fonts.googleapis.com/css2?display=swap${s}`;let a=document.getElementById(o);a||(a=document.createElement("link"),a.id=o,a.rel="stylesheet",document.head.appendChild(a)),a.href!==n&&(a.href=n)}const i=[];if(t.forEach(n=>{n.toLowerCase().includes("clash display")&&i.push("clash-display@200,300,400,500,600,700")}),i.length>0){const n=`https://api.fontshare.com/v2/css?f[]=${i.join("&f[]=")}&display=swap`;let a=document.getElementById(e);a||(a=document.createElement("link"),a.id=e,a.rel="stylesheet",document.head.appendChild(a)),a.href!==n&&(a.href=n)}document.fonts&&document.fonts.ready&&document.fonts.ready.then(()=>{this.pretextCache.clear(),this.advance(0)})}enterStates(t,s){var n;if(s.length===0)return;const o=this.layerStates.get(t);if(o&&o.currentStateIds.length===s.length&&s.every(r=>o.currentStateIds.includes(r))&&this.justFiredTriggers.size===0)return;const e=[];let i=0;if(this.artboard&&this.activeStateMachine){const a=this.activeStateMachine.layers.find(r=>r.name===t);if(a)for(const r of s){const c=a.states.find(d=>d.id===r);if(c){let d=null;c.animationId&&(d=this.artboard.animations.find(l=>l.id===c.animationId)||null),d||(d=this.artboard.animations.find(l=>{var f,g;return l.name===c.name||l.id===c.name||(c.name==="Entry"||c.id==="entry")&&(((f=l.name)==null?void 0:f.toLowerCase())==="onload"||((g=l.name)==null?void 0:g.toLowerCase())==="intro")})||null),d&&((n=this.artboard.animationFlow)!=null&&n.some(f=>(f.trigger==="on_load"||f.trigger==="after_delay")&&f.targetAnimationId===(d==null?void 0:d.id))||(e.push({animation:d,state:c}),i=Math.max(i,d.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 c=(n=this.activeStateMachine)==null?void 0:n.inputs.find(d=>d.id===t);c&&typeof c.value=="object"&&(o=c.value.type)}else{const c=this.inputNameMap.get(t);if(c&&c.length>0){const d=(a=this.activeStateMachine)==null?void 0:a.inputs.find(l=>l.id===c[0]);d&&typeof d.value=="object"&&(o=d.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(c=>this.setInternalInput(c,e)),o==="Trigger"&&e===!0&&(this.justFiredTriggers.add(t),i&&i.forEach(c=>this.justFiredTriggers.add(c))),Array.isArray(e)&&((r=this.artboard)==null||r.objects.forEach(c=>{if(c.inputId===t||c.name===t){const d=this.objectStates.get(c.id);d&&d.options&&(c.type==="ListView"||c.variant==="listview"?d.options.items=e:(c.type==="Dropdown"||c.variant==="dropdown")&&(d.options.optionsList=e))}})),this.evaluateTransitions(),this.evaluateVariableTriggers(t,e)}evaluateVariableTriggers(t,s){if(!this.artboard)return;const o=this.artboard.animationFlow||[],e=this.inputNameMap.get(t);o.forEach(i=>{if(i.trigger==="variable"&&i.conditionVariableId&&i.targetAnimationId&&(i.conditionVariableId===t||e&&e.includes(i.conditionVariableId))){const a=i.conditionOperator||"IsTrue",r=i.conditionValue;let c=!1;switch(a){case"Equal":case"==":c=s==r;break;case"NotEqual":case"!=":c=s!=r;break;case"GreaterThan":case">":c=s>r;break;case"LessThan":case"<":c=s<r;break;case"GreaterEqual":case">=":c=s>=r;break;case"LessEqual":case"<=":c=s<=r;break;case"IsTrue":c=!!s;break;case"IsFalse":c=!s;break}if(c){const d=i.delay||0;d<=0?this.triggerGlobalAnimation(i.targetAnimationId,i.subAnimationIds,i.loop,i.id):setTimeout(()=>this.triggerGlobalAnimation(i.targetAnimationId,i.subAnimationIds,i.loop,i.id),d)}}})}evaluateTransitions(){this.activeStateMachine&&(this.activeStateMachine.layers.forEach(t=>{const s=this.layerStates.get(t.name);if(!s||s.currentStateIds.length===0)return;const o=[];let e=!1;for(const i of s.currentStateIds){const n=t.states.find(r=>r.id===i);if(!n)continue;let a=!1;for(const r of n.transitions||[])this.checkConditions(r.conditions)&&(o.push(r.targetStateId),a=!0,e=!0);a||o.push(i)}if(!e){const i=this.findGlobalTransition(t,s.currentStateIds);i&&(o.length=0,o.push(i.targetStateId),e=!0,i.conditions&&(i.conditions||[]).forEach(n=>{var r;const a=(r=this.activeStateMachine)==null?void 0:r.inputs.find(c=>c.id===n.inputId);a&&typeof a.value=="object"&&a.value.type==="Trigger"&&this.setInternalInput(n.inputId,!1)}))}if(e){const i=Array.from(new Set(o));this.enterStates(t.name,i)}}),this.justFiredTriggers.size>0&&(this.justFiredTriggers.forEach(t=>{var o,e;this.setInternalInput(t,!1);const s=(o=this.activeStateMachine)==null?void 0:o.inputs.find(i=>i.id===t);s&&this.inputNameMap.has(s.name)&&((e=this.inputNameMap.get(s.name))==null||e.forEach(i=>this.setInternalInput(i,!1)))}),this.justFiredTriggers.clear()))}findGlobalTransition(t,s){for(const o of t.states)if(!(s.includes(o.id)&&this.justFiredTriggers.size===0)){for(const i of o.transitions||[])if(!(s.includes(i.targetStateId)&&this.justFiredTriggers.size===0)&&this.checkConditions(i.conditions))return i}return null}checkConditions(t){return!t||t.length===0?!0:t.every(s=>{const o=s.inputId,e=s.op,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,c,d;if(o.has(t))return this.inputs.get(t)??this.logicNodeValues.get(t)??0;o.add(t);const e=(r=(a=this.activeStateMachine)==null?void 0:a.logicNodes)==null?void 0:r.find(l=>l.id===t);if(e){const l=(g,u)=>{const p=e.inputs.find(m=>m.id===g);return p?p.sourceId?this.evaluateLogicTree(p.sourceId,p.sourceHandleId,o):p.value!==void 0?p.value:u:u};let f=0;switch(e.op){case gt.AND:f=l("a",!1)&&l("b",!1);break;case gt.OR:f=l("a",!1)||l("b",!1);break;case gt.NOT:f=!l("in",!1);break;case gt.XOR:f=!!l("a",!1)!=!!l("b",!1);break;case gt.OBJECT:f=e.name;break;case gt.PROPERTY:case gt.GET_PROPERTY:{const g=l("id","");if(!g){f=0;break}const u=e.name;if(!u||u==="GET_PROPERTY"||u==="PROPERTY"){f=0;break}const p=this.objectStates.get(g);if(!p){f=0;break}u in p?f=p[u]:f=this.resolvePath(p,u);break}case gt.SET_PROPERTY:{const g=l("id",""),u=l("value",void 0);if(!g||u===void 0){f=0;break}const p=e.name;if(!p||p==="SET_PROPERTY"){f=0;break}const m=this.objectStates.get(g);if(!m){f=0;break}if(["x","y","rotation","scale_x","scale_y","opacity","width","height","cornerRadius","visible","zIndex"].includes(p))m[p]=u,f=u;else{const S=p.split(".");let b=m;for(let w=0;w<S.length-1;w++){const k=S[w];b[k]===void 0&&(b[k]={}),b=b[k]}const v=S[S.length-1];b[v]=u,f=u}break}case gt.ADD:f=l("a",0)+l("b",0);break;case gt.SUB:f=l("a",0)-l("b",0);break;case gt.MUL:f=l("a",0)*l("b",0);break;case gt.DIV:{const g=l("b",1);f=g===0?0:l("a",0)/g;break}case gt.MOD:f=l("a",0)%l("b",1);break;case gt.POW:f=Math.pow(l("a",0),l("b",1));break;case gt.ABS:f=Math.abs(l("in",0));break;case gt.ROUND:f=Math.round(l("in",0));break;case gt.FLOOR:f=Math.floor(l("in",0));break;case gt.CEIL:f=Math.ceil(l("in",0));break;case gt.SIN:f=Math.sin(l("in",0));break;case gt.COS:f=Math.cos(l("in",0));break;case gt.TAN:f=Math.tan(l("in",0));break;case gt.CLAMP:{const g=l("in",0),u=l("min",0),p=l("max",1);f=Math.max(u,Math.min(p,g));break}case gt.REMAP:{const g=l("in",0),u=l("inMin",0),p=l("inMax",100),m=l("outMin",0),y=l("outMax",1);f=p===u?m:m+(g-u)*(y-m)/(p-u);break}case gt.EQ:f=l("a",0)==l("b",0);break;case gt.NEQ:f=l("a",0)!=l("b",0);break;case gt.GT:f=l("a",0)>l("b",0);break;case gt.LT:f=l("a",0)<l("b",0);break;case gt.GTE:f=l("a",0)>=l("b",0);break;case gt.LTE:f=l("a",0)<=l("b",0);break;case gt.IF_ELSE:f=l("cond",!1)?l("then",0):l("else",0);break;case gt.VALUE:f=e.value!==void 0?e.value:0;break;case gt.INPUT:f=this.inputs.get(e.name)??0;break;case gt.LOG:{const g=l("in","");this.debugLog(`[User Logic] ${g}`),f=g;break}case gt.SCROLL_X:f=this.inputs.get("scrollX")??0;break;case gt.SCROLL_Y:f=this.inputs.get("scrollY")??0;break;case gt.MOUSE_X:f=this.inputs.get("mouseX")??0;break;case gt.MOUSE_Y:f=this.inputs.get("mouseY")??0;break;case gt.IS_MOUSE_DOWN:f=this.inputs.get("isMouseDown")??!1;break;case gt.EFFECTOR:{const g=l("id",""),u=l("intensity",1),p=l("trigger",!0);if(!g||!p){f=0;break}const m=e.name;if(!m){f=0;break}const y=this.objectStates.get(g);if(!y){f=0;break}if(["glitch","halftone","pixelate","noise","acid_gradient","acid_rave","shimmer"].includes(m))y.style||(y.style={}),y.style.artEffect={enabled:!0,type:m,intensity:u},f=1;else{y.behaviors||(y.behaviors=[]);let b=y.behaviors.find(v=>v.type===m);b?(b.enabled=!0,b.settings||(b.settings={}),b.settings.intensity=u):(b={id:`eff_${Date.now()}_${m}`,type:m,enabled:!0,sensors:[],settings:{intensity:u}},y.behaviors.push(b)),f=1}break}case gt.MONITOR:{f=l("in",0);break}default:f=0;break}if(this.logicNodeValues.set(t,f),e.op===gt.DELAY){const g=l("delay",0),u=l("in",0);let p=this.logicNodeState.get(t);for(p||(p={queue:[]},this.logicNodeState.set(t,p)),p.queue.push({time:this.currentTime+g,value:u});p.queue.length>0&&p.queue[0].time<=this.currentTime;)p.lastValue=p.queue.shift().value;f=p.lastValue??0}return f}const i=(c=this.activeStateMachine)==null?void 0:c.inputs.find(l=>l.id===t||l.name===t);if(i&&i.sourceId&&!o.has(i.sourceId)){const l=this.evaluateLogicTree(i.sourceId,i.sourceHandleId,o);return this.inputs.set(i.id,l),l}let n=this.inputs.get(t)??(i?this.inputs.get(i.id):void 0);if((this.justFiredTriggers.has(t)||i&&this.justFiredTriggers.has(i.id))&&(n=!0),s&&n!==void 0){const l=(d=this.activeStateMachine)==null?void 0:d.inputs.find(f=>f.id===t);if(l&&l.value.type==="Number"&&typeof n=="number"){const f=l.value.defaultValue??l.value.value;if(s==="source-greater")return n>f;if(s==="source-less")return n<f;if(s==="source-equal")return n===f}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===gt.SET_PROPERTY||t.op===gt.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,c,d,l;if(o.phase==="entry")o.time+=t,o.time>=o.animation.duration&&((a=(n=(i=this.artboard)==null?void 0:i.objects.find(f=>f.id===e))==null?void 0:n.triggers)==null||a.find(f=>f.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 f=(d=(c=(r=this.artboard)==null?void 0:r.objects.find(p=>p.id===e))==null?void 0:c.triggers)==null?void 0:d.find(p=>p.id===o.triggerId),g=(f==null?void 0:f.duration)||0;o.elapsedHold+=t*1e3;let u=o.elapsedHold>=g;if((f==null?void 0:f.eventType)==="hover"&&!this.activeHoverIds.has(e)&&(u=!0),((f==null?void 0:f.eventType)==="onHold"||(f==null?void 0:f.eventType)==="pointerDown")&&!this.isMouseDown&&(u=!0),u)if(f!=null&&f.exitAnimationId){const p=(l=this.artboard)==null?void 0:l.animations.find(m=>m.id===f.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),c=(((i=s.geometry)==null?void 0:i.width)||100)*(r.scale_x||1),d=(((n=s.geometry)==null?void 0:n.height)||100)*(r.scale_y||1),l=50,f=r.x+c/2>=-this.canvasWidth/2-l&&r.x-c/2<=this.canvasWidth/2+l&&r.y+d/2>=-this.canvasHeight/2-l&&r.y-d/2<=this.canvasHeight/2+l,g=`analytics_${s.id}`,u=this.wasInView.has(g);f&&!u&&this.fireAnalyticsEvent(s.id,"visible"),f?this.wasInView.add(g):this.wasInView.delete(g)}}}),this.artboard.objects.forEach(s=>{const o=s.interactions||[];o.length!==0&&o.forEach(e=>{const i=e.triggers||[e.event||e.trigger];i&&i.forEach(n=>{var r,c,d;const a=n.toLowerCase();if(a==="on interval"||a==="oninterval"){const l=e.intervalValue||2e3,f=this.periodicTriggerTimes.get(e.id)||0;this.currentTime*1e3-f>=l&&(!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 l=e.delayValue||1e3;!this.periodicTriggerTimes.has(e.id)&&this.currentTime*1e3>=l&&(!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 l=this.objectStates.get(s.id);if(l&&l.visible!==!1){const f=this.getGlobalTransform(s.id),g=(((r=s.geometry)==null?void 0:r.width)||100)*(f.scale_x||1),u=(((c=s.geometry)==null?void 0:c.height)||100)*(f.scale_y||1),p=50,m=f.x+g/2>=-this.canvasWidth/2-p&&f.x-g/2<=this.canvasWidth/2+p&&f.y+u/2>=-this.canvasHeight/2-p&&f.y-u/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 l=Math.abs(this.scrollOffset.y)/(((d=this.artboard)==null?void 0:d.height)||1e3),f=this.scrollProgressLastValue.get(e.id)||0;Math.abs(l-f)>.001&&(this.scrollProgressLastValue.set(e.id,l),(e.action==="Set Input"||e.action==="setInput")&&this.updateInput(e.targetInputId,l))}})})}))}solveConstraints(t){this.artboard&&this.artboard.objects.forEach(s=>{if(!s.constraints||s.constraints.length===0)return;const o=this.objectStates.get(s.id);if(!o)return;const e=this.getGlobalTransform(s.id);if(s.constraints.forEach((i,n)=>{var d,l,f,g,u,p,m,y,S;const a=((d=o.constraints)==null?void 0:d[n])||{},r={...i,...a},c=r.strength??1;if(r.type==="Translation"){const b=this.getGlobalTransform(r.targetId);if(b){const v=r.offsetX||0,w=r.offsetY||0,k=b.x+v,A=b.y+w;if(r.useSpring){const B=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:$,y:K,vx:tt,vy:rt}=this.computeSpring(e.x,e.y,B.vx,B.vy,k,A,r,t);r.copyX&&(e.x=e.x+($-e.x)*c),r.copyY&&(e.y=e.y+(K-e.y)*c),this.objectVelocities.set(s.id,{vx:tt,vy:rt})}else r.copyX&&(e.x=e.x+(k-e.x)*c),r.copyY&&(e.y=e.y+(A-e.y)*c);(l=r.limitX)!=null&&l.enabled&&(e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x))),(f=r.limitY)!=null&&f.enabled&&(e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)))}}else if(r.type==="Rotation"){const b=this.getGlobalTransform(r.targetId);if(b){let w=(b.rotation+(r.offset||0)-e.rotation)%360;w>180&&(w-=360),w<-180&&(w+=360),e.rotation=e.rotation+w*c}}else if(r.type==="Scale"){const b=this.getGlobalTransform(r.targetId);b&&(r.copyX&&(e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*c),r.copyY&&(e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*c))}else if(r.type==="Transform"){const b=this.getGlobalTransform(r.targetId);if(b){e.x=e.x+(b.x-e.x)*c,e.y=e.y+(b.y-e.y)*c;let v=(b.rotation-e.rotation)%360;v>180&&(v-=360),v<-180&&(v+=360),e.rotation=e.rotation+v*c,e.scale_x=e.scale_x+(b.scale_x-e.scale_x)*c,e.scale_y=e.scale_y+(b.scale_y-e.scale_y)*c}}else if(r.type==="FollowPointer"){const b=((g=this._lastPointerPos)==null?void 0:g.x)??e.x,v=((u=this._lastPointerPos)==null?void 0:u.y)??e.y;if(r.useSpring){const k=this.objectVelocities.get(s.id)||{vx:0,vy:0},{x:A,y:x,vx:B,vy:$}=this.computeSpring(e.x,e.y,k.vx,k.vy,b,v,r,t);e.x=A,e.y=x,this.objectVelocities.set(s.id,{vx:B,vy:$})}else e.x=e.x+(b-e.x)*c,e.y=e.y+(v-e.y)*c;(p=r.limitX)!=null&&p.enabled&&(e.x=Math.max(r.limitX.min,Math.min(r.limitX.max,e.x))),(m=r.limitY)!=null&&m.enabled&&(e.y=Math.max(r.limitY.min,Math.min(r.limitY.max,e.y)))}else if(r.type==="Distance"){const b=this.getGlobalTransform(r.targetId);if(b){const v=e.x-b.x,w=e.y-b.y,k=Math.sqrt(v*v+w*w),A=r.distance||0;let x=k;switch(r.mode){case"exact":x=A;break;case"minimum":x=Math.max(A,k);break;case"maximum":x=Math.min(A,k);break;case"clamped":x=Math.max(0,Math.min(A,k));break}if(k>0){const B=e.x===b.x&&e.y===b.y?1:x/k;e.x=e.x+(b.x+v*B-e.x)*c,e.y=e.y+(b.y+w*B-e.y)*c}}}else if(r.type==="FollowPath"){const b=(y=this.artboard)==null?void 0:y.objects.find(v=>v.id===r.targetId);if(b){const v=this.getGlobalTransform(b.id);if(v){let w=b.geometry;if(b.type==="Frame"||b.type==="Group"||!w||w.type!=="Path"&&w.type!=="Ellipse"&&w.type!=="Rectangle"){const H=(S=this.artboard)==null?void 0:S.objects.find(it=>it.parentId===b.id&&it.type==="Shape"&&it.geometry&&(it.geometry.type==="Path"||it.geometry.type==="Ellipse"||it.geometry.type==="Rectangle"));H&&(w=H.geometry)}if(!w)return;const k=(r.distance||0)/100,A=v.width||w.width||0,x=v.height||w.height||0,B=this.getPointOnPath(w,A,x,k),$=v.rotation*Math.PI/180,K=Math.cos($),tt=Math.sin($),rt=B.x*v.scale_x*K-B.y*v.scale_y*tt,at=B.x*v.scale_x*tt+B.y*v.scale_y*K;let V=v.rotation+(r.offsetRotation||0);if(r.orient){const H=Math.cos(B.angle),it=Math.sin(B.angle),nt=H*v.scale_x*K-it*v.scale_y*tt,ft=H*v.scale_x*tt+it*v.scale_y*K;V=Math.atan2(ft,nt)*180/Math.PI+(r.offsetRotation||0)}const O=V*Math.PI/180,R=Math.cos(O),P=Math.sin(O),J=(r.offsetX||0)*R-(r.offsetY||0)*P,j=(r.offsetX||0)*P+(r.offsetY||0)*R,lt=v.x+rt+J,Y=v.y+at+j;if(e.x=e.x+(lt-e.x)*c,e.y=e.y+(Y-e.y)*c,r.orient){let H=(V-e.rotation)%360;H>180&&(H-=360),H<-180&&(H+=360),e.rotation=e.rotation+H*c}}}}else if(r.type==="IK"){const b=this.getGlobalTransform(r.targetId);b&&this.solveIK(s,b,r.boneCount||2,c)}}),s.constraints.some(i=>i.type!=="IK")){const i=this.globalToLocal(s.parentId,e);o.x=i.x,o.y=i.y,o.rotation=i.rotation,o.flip_x=i.scale_x<0,o.scale_x=Math.abs(i.scale_x),o.flip_y=i.scale_y<0,o.scale_y=Math.abs(i.scale_y)}})}getGlobalTransform(t){var d;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,rotation:0,scale_x:1,scale_y:1};const o=(d=this.artboard)==null?void 0:d.objects.find(l=>l.id===t);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)};const e=this.getGlobalTransform(o.parentId),i=e.rotation*Math.PI/180,n=Math.cos(i),a=Math.sin(i),r=e.x+(s.x*e.scale_x*n-s.y*e.scale_y*a),c=e.y+(s.x*e.scale_x*a+s.y*e.scale_y*n);return{x:r,y:c,rotation:e.rotation+s.rotation,scale_x:e.scale_x*(s.scale_x??1)*(s.flip_x?-1:1),scale_y:e.scale_y*(s.scale_y??1)*(s.flip_y?-1:1)}}globalToLocal(t,s){if(!t)return s;const o=this.getGlobalTransform(t),e=o.scale_x===0?0:1/o.scale_x,i=o.scale_y===0?0:1/o.scale_y,n=-o.rotation*Math.PI/180,a=Math.cos(n),r=Math.sin(n),c=s.x-o.x,d=s.y-o.y,l=(c*a-d*r)*e,f=(c*r+d*a)*i;return{x:l,y:f,rotation:s.rotation-o.rotation,scale_x:s.scale_x/(o.scale_x||1),scale_y:s.scale_y/(o.scale_y||1)}}solveIK(t,s,o,e){var c;const i=[];let n=t.id;for(let d=0;d<o&&n;d++){const l=(c=this.artboard)==null?void 0:c.objects.find(f=>f.id===n);if(!l)break;i.push({id:n,local:this.objectStates.get(n),global:this.getGlobalTransform(n)}),n=l.parentId}if(i.length<2)return;const a=i.reverse(),r=5;for(let d=0;d<r;d++){const l=this.getGlobalTransform(t.id);for(let f=a.length-2;f>=0;f--){const g=a[f],u=this.getGlobalTransform(g.id),p=l.x-u.x,m=l.y-u.y,y=s.x-u.x,S=s.y-u.y,b=Math.sqrt(p*p+m*m),v=Math.sqrt(y*y+S*S);if(b>.001&&v>.001){const w=Math.atan2(m,p);let A=(Math.atan2(S,y)-w)*180/Math.PI;A*=e;const x=this.objectStates.get(g.id);x&&(x.rotation+=A)}}}}computeSpring(t,s,o,e,i,n,a,r){const c=a.stiffness??100,d=a.damping??10,l=a.mass??1,f=-c*(t-i),g=-c*(s-n),u=-d*o,p=-d*e,m=(f+u)/l,y=(g+p)/l,S=o+m*r,b=e+y*r,v=t+S*r,w=s+b*r;return{x:v,y:w,vx:S,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,c,d,l,f;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=(g,u)=>{var v;let p=u;u==="click"?p="onClick":u==="down"?p="onPointerDown":u==="up"?p="onPointerUp":u==="blur"&&(p="onPointerLeave");const m=new Set([p]);u==="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"];return!!(g.type==="Component"&&y.includes(g.variant)||y.includes((v=g.type)==null?void 0:v.toLowerCase())||(g.interactions||[]).some(w=>m.has(w.event))||(g.triggers||[]).some(w=>m.has(w.eventType)))};let n=null;for(let g=this.artboard.objects.length-1;g>=0;g--){const u=this.artboard.objects[g],p=this.objectStates.get(u.id);if(p&&p.visible!==!1&&p.opacity>0&&this.hitTest(u,s,o)&&(n||(n=u),i(u,t))){e=u;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 g=this.artboard.objects.find(u=>u.id===this.draggingSliderId);g&&this.updateSliderValueFromPointer(g,s,o);return}if(this.draggingListViewId){const g=this.artboard.objects.find(u=>u.id===this.draggingListViewId);g&&this.updateListViewScrollFromPointer(g);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(g=>g.type===W.Draggable))&&this.draggingBehaviors.add(a)),t==="move"?(a&&!this.activeHoverIds.has(a)&&this.activeHoverIds.add(a),this.activeHoverIds.forEach(g=>{g!==a&&this.activeHoverIds.delete(g)})):t==="blur"&&this.activeHoverIds.clear(),this.activeDropdownId&&t==="down"){const g=this.artboard.objects.find(u=>u.id===this.activeDropdownId);if(g&&(g.type==="Dropdown"||g.variant==="dropdown")){const u=this.objectStates.get(g.id),p=(u==null?void 0:u.options)||g.options||{},m=g.geometry||{},y=m.width??g.width??200,S=m.height??g.height??40,b=p.optionsList||[],v=p.itemHeight||32,w=p.listPadding??4,k=b.length*v+w*2,A=this.getWorldTransform(g.id),x=y*Math.abs(A.scaleX),B=S*Math.abs(A.scaleY),$=A.y+B/2+4,K=Math.abs(s-A.x)<=x/2,tt=o>=$&&o<=$+k*Math.abs(A.scaleY);if(K&&tt){const rt=Math.abs(A.scaleY),at=o-($+w*rt),V=Math.floor(at/(v*rt));if(V>=0&&V<b.length){const O=b[V];p.selectedOption=O,p.isOpen=!1,this.activeDropdownId=null,g.inputId&&this.setInternalInput(g.inputId,O),this.onComponentChange&&this.onComponentChange({objectId:g.id,componentName:g.name,variant:"dropdown",property:"selectedOption",value:O})}return}else a!==this.activeDropdownId&&(p.isOpen=!1,this.activeDropdownId=null)}}if(e){let g=e,u=e;for(;u&&u.parentId;){const m=this.artboard.objects.find(y=>y.id===u.parentId);if(m&&m.type==="Component"){g=m;break}u=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),g!==e&&this.fireEventForObject(g.id,p),g.type==="Component"&&g.variant==="toggle_button"&&t==="down"){const m=this.objectStates.get(g.id),y=(m==null?void 0:m.options)||g.options||{};y.checked=!y.checked,g.inputId&&this.setInternalInput(g.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:g.id,componentName:g.name,variant:"toggle_button",property:"checked",value:y.checked}),this.fireEventForObject(g.id,"Toggle"),this.fireEventForObject(g.id,y.checked?"Toggle True":"Toggle False")}if(g.type==="Component"&&g.variant==="toggle"&&t==="down"){const m=this.objectStates.get(g.id),y=(m==null?void 0:m.options)||g.options||{};y.checked=!y.checked,g.inputId&&this.setInternalInput(g.inputId,y.checked),this.onComponentChange&&this.onComponentChange({objectId:g.id,componentName:g.name,variant:"toggle",property:"checked",value:y.checked}),this.onToggle&&this.onToggle(g.name,y.checked),this.fireEventForObject(g.id,"Toggle"),this.fireEventForObject(g.id,y.checked?"Toggle True":"Toggle False")}if(g.type==="Component"&&g.variant==="dropdown"&&t==="down"){const m=this.objectStates.get(g.id),y=(m==null?void 0:m.options)||g.options||{},S=!y.isOpen;if(S&&this.activeDropdownId&&this.activeDropdownId!==g.id){const b=this.artboard.objects.find(v=>v.id===this.activeDropdownId);b&&b.options&&(b.options.isOpen=!1)}y.isOpen=S,this.activeDropdownId=S?g.id:null}if(g.type==="Component"&&g.variant==="button"&&t==="down"&&(this.onButtonClick&&this.onButtonClick(g.name,g.id),this.onComponentChange&&this.onComponentChange({objectId:g.id,componentName:g.name,variant:"button",property:"click",value:!0})),g.type==="Component"&&g.variant==="listview"&&t==="down"){this.draggingListViewId=g.id;const m=this.getListViewItemIndexAtPointer(g,s,o);if(m!==null){const y=g.options||{};y.activeItemIndex=m;const S=this.objectStates.get(g.id);S&&S.options&&(S.options.activeItemIndex=m);const b=(y.items||[])[m],v=typeof b=="string"?b:b.label||b.value||m;S&&S.options&&(S.options.selectedValue=v),g.inputId&&this.setInternalInput(g.inputId,v),this.onComponentChange&&(this.onComponentChange({objectId:g.id,componentName:g.name,variant:"listview",property:"activeItemIndex",value:m}),this.onComponentChange({objectId:g.id,componentName:g.name,variant:"listview",property:"selected",value:v}))}}if(g.type==="Component"&&g.variant==="slider"&&t==="down"&&(this.draggingSliderId=g.id,this.updateSliderValueFromPointer(g,s,o)),g.type==="LineGraph"&&(t==="down"||t==="click")){const m=g.geometry,y=(m==null?void 0:m.datasets)||[],S=this.objectStates.get(g.id),b=(S==null?void 0:S.width)||(m==null?void 0:m.width)||200,v=(S==null?void 0:S.height)||(m==null?void 0:m.height)||150,w=this.getWorldTransform(g.id),k=30,A=20,x=b-k,B=v-A;let $=1;y.forEach(rt=>{const at=Math.max(...rt.data||[0]);at>$&&($=at)});let K=1/0,tt=null;y.forEach((rt,at)=>{const V=rt.data||[],O=x/Math.max(V.length-1,1);V.forEach((R,P)=>{const J=w.x-b/2+k+P*O,j=w.y+v/2-A-R/$*B,lt=Math.sqrt((s-J)**2+(o-j)**2);lt<K&&(K=lt,tt={dIdx:at,pIdx:P,val:R,label:rt.label||`Dataset ${at+1}`})})}),tt&&K<20&&this.onGraphPointClick&&this.onGraphPointClick({objectId:g.id,componentName:g.name,datasetIndex:tt.dIdx,pointIndex:tt.pIdx,value:tt.val,label:tt.label}),this.onComponentChange&&this.onComponentChange({objectId:g.id,componentName:g.name,variant:"linegraph",property:"click",value:(tt==null?void 0:tt.val)??null})}if(t==="click"){const m=(c=this.artboard)==null?void 0:c.objects.find(b=>b.id===e.id),y=this.focusedId,S=(m==null?void 0:m.type)==="InputBox"||(m==null?void 0:m.type)==="Component"&&m.variant==="inputbox";if(m&&S){if(this.focusedId=e.id,console.log(`[Engine] Focus set to: ${e.id}`),y!==this.focusedId){if(y){const b=(d=this.artboard)==null?void 0:d.objects.find(v=>v.id===y);b&&this.onInputBlur&&this.onInputBlur(b.name)}this.onInputFocus&&this.onInputFocus(m.name)}}else if(this.focusedId=null,y){const b=(l=this.artboard)==null?void 0:l.objects.find(v=>v.id===y);b&&this.onInputBlur&&this.onInputBlur(b.name)}}}else if(t==="click"){const g=this.focusedId;if(this.focusedId=null,g){const u=(f=this.artboard)==null?void 0:f.objects.find(p=>p.id===g);u&&this.onInputBlur&&this.onInputBlur(u.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 d,l,f,g,u;const o=(d=this.artboard)==null?void 0:d.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__"?(f=(l=this.artboard)==null?void 0:l.animations)==null||f.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(S=>S.id===p||S.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 c=(o.triggers||[]).find(p=>{const m=p.eventType.toLowerCase();let y=!1;return(e.has(m)||m==="click"&&e.has("onclick")||m==="hover"&&(e.has("onpointerenter")||e.has("hover"))||m==="pointerdown"&&e.has("onpointerdown")||m==="pointerup"&&e.has("onpointerup"))&&(y=!0),y&&p.conditions&&p.conditions.length>0?this.checkConditions(p.conditions):y});if(c&&c.entryAnimationId){console.log(`[Engine] Trigger matched: ${s} (as ${c.eventType}) -> Animation ${c.entryAnimationId}`);const p=(u=(g=this.artboard)==null?void 0:g.animations)==null?void 0:u.find(m=>m.id===c.entryAnimationId);p&&(this.activeTriggers.set(o.id,{triggerId:c.id,animation:p,time:0,phase:"entry",elapsedHold:0,filterObjectId:c.targetObjectId}),this.onTrigger&&this.onTrigger(c.name,p.name))}}fireAnalyticsEvent(t,s){var r,c;const o=(r=this.artboard)==null?void 0:r.objects.find(d=>d.id===t);if(!o)return;const e=(c=o.style)==null?void 0:c.analytics;if(!e||!e.isEnabled||e.triggerType!==s)return;const i=e.eventName||`${o.name.toLowerCase().replace(/\s+/g,"_")}_interacted`,n={};e.parameters&&Array.isArray(e.parameters)&&e.parameters.forEach(d=>{if(d.type==="literal")n[d.key]=d.value;else if(d.type==="variable"){const l=this.inputs.get(d.value);n[d.key]=l!==void 0?l:""}}),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 d=window;typeof d.gtag=="function"?(d.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 d=window;typeof d.fbq=="function"?(d.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 d=window;d.mixpanel&&typeof d.mixpanel.track=="function"?(d.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 f;const s=this.objectStates.get(t);if(!s)return{x:0,y:0,scaleX:1,scaleY:1,rotation:0};const o=(f=this.artboard)==null?void 0:f.objects.find(g=>g.id===t);if(!o||!o.parentId)return{x:s.x,y:s.y,scaleX:s.scale_x??1,scaleY:s.scale_y??1,rotation:s.rotation??0};const e=this.getWorldTransform(o.parentId),i=e.rotation*(Math.PI/180),n=Math.cos(i),a=Math.sin(i),r=s.x*e.scaleX,c=s.y*e.scaleY,d=e.x+(r*n-c*a),l=e.y+(r*a+c*n);return{x:d,y:l,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,v;if(!this.objectStates.get(t.id))return!1;const i=((b=t.geometry)==null?void 0:b.width)??t.width??100,n=((v=t.geometry)==null?void 0:v.height)??t.height??100,a=this.getWorldTransform(t.id),r=s-a.x,c=o-a.y,d=-a.rotation*(Math.PI/180),l=Math.cos(d),f=Math.sin(d),g=r*l-c*f,u=r*f+c*l,p=a.scaleX,m=a.scaleY,y=i*Math.abs(p),S=n*Math.abs(m);return Math.abs(g)<=y/2&&Math.abs(u)<=S/2}updateSliderValueFromPointer(t,s,o){var A;const e=this.objectStates.get(t.id);if(!e)return;const i=t.options||{},n=((A=t.geometry)==null?void 0:A.width)??t.width??200,a=this.getWorldTransform(t.id),r=s-a.x,c=o-a.y,d=-a.rotation*(Math.PI/180),l=Math.cos(d),f=Math.sin(d),g=r*l-c*f,u=i.thumbWidth??16,p=n-u;let y=(g+p/2)/p;y=Math.max(0,Math.min(1,y));const S=i.min??0,b=i.max??100,v=i.step||1;let w=S+y*(b-S);v>0&&(w=Math.round(w/v)*v),w=Math.max(S,Math.min(b,w));const k=e.options||{};k.value!==w&&(e.options={...k,value:w},t.inputId&&this.setInternalInput(t.inputId,w),this.onComponentChange&&this.onComponentChange({objectId:t.id,componentName:t.name,variant:"slider",property:"value",value:w}))}applyAnimation(t,s,o){!t||!t.tracks||t.tracks.forEach(e=>{var l,f,g;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=(l=this.artboard)==null?void 0:l.objects.find(u=>u.id===i),a=((f=n==null?void 0:n.physics)==null?void 0:f.enabled)&&n.physics.bodyType!=="Static";let r=e.property;if(a&&(r==="x"||r==="y"||r==="rotation"))return;const c=this.objectStates.get(i);if(!c){this.frameCount%600===0&&this.debugLog(`Skipping track: Object ${i} not found in state`);return}const d=this.interpolate(e.keyframes,s);if(d!==void 0){if(this.frameCount%240===0){const u=(n==null?void 0:n.name)||i,p=typeof d=="object"?JSON.stringify(d).slice(0,50):d;this.debugLog(`[Anim] Applying ${r} = ${p} to ${u}`)}if(r.includes(".")){const u=(r||"").split(".");let p=c;for(let m=0;m<u.length-1;m++){if(typeof p[u[m]]!="object"||p[u[m]]===null){let y=n;for(let S=0;S<=m;S++)y=y?y[u[S]]:null;if(u[m]==="corner_radius"||u[m]==="cornerRadius"){const S=typeof p[u[m]]=="number"?p[u[m]]:typeof y=="number"?y:0;p[u[m]]={tl:S,tr:S,bl:S,br:S}}else p[u[m]]=y?JSON.parse(JSON.stringify(y)):{}}p=p[u[m]]}p[u[u.length-1]]=d,u[u.length-1]==="color"&&(u[u.length-2]==="fill"||u[u.length-2]==="stroke")&&(p.type="Solid")}else r==="fill"?(c.style||(c.style={}),c.style.fill=d):r==="stroke"?(c.style||(c.style={}),c.style.stroke=d):c[r]=d;if(this.physicsEngine&&((g=n==null?void 0:n.physics)!=null&&g.enabled)&&n.physics.bodyType==="Static")if(r==="x"){const u=this.physicsEngine.getPosition(i);u&&this.physicsEngine.setPosition(i,d,u.y)}else if(r==="y"){const u=this.physicsEngine.getPosition(i);u&&this.physicsEngine.setPosition(i,u.x,d)}else r==="rotation"&&this.physicsEngine.setRotation(i,d*(Math.PI/180))}})}interpolate(t,s){if(t.length===0)return;let o=t[0],e=t[t.length-1];if(s<=o.time)return o.value;if(s>=e.time)return e.value;for(let a=0;a<t.length-1;a++)if(s>=t[a].time&&s<t[a+1].time){o=t[a],e=t[a+1];break}const i=e.time-o.time;let n=(s-o.time)/i;if(o.easing&&(n=ss(o.easing)(n)),typeof o.value=="string"){if(o.value.startsWith("#"))return this.interpolateColor(o.value,e.value,n);const a=parseFloat(o.value),r=parseFloat(e.value);return!isNaN(a)&&!isNaN(r)?Math.round(a+(r-a)*n).toString():o.value}if(Array.isArray(o.value)&&Array.isArray(e.value))return o.value.length===e.value.length?o.value.map((a,r)=>{const c=e.value[r];return typeof a=="number"&&typeof c=="number"?a+(c-a)*n:n<.5?a:c}):n<.5?o.value:e.value;if(typeof o.value=="object"&&typeof e.value=="object"&&o.value!==null&&e.value!==null){if(o.value.width!==void 0&&o.value.color!==void 0)return this.interpolateStroke(o.value,e.value,n);if(o.value.type&&e.value.type)return this.interpolateFill(o.value,e.value,n);const a={};return new Set([...Object.keys(o.value),...Object.keys(e.value)]).forEach(c=>{const d=o.value[c],l=e.value[c];typeof d=="number"&&typeof l=="number"?a[c]=d+(l-d)*n:d===void 0?a[c]=l:l===void 0?a[c]=d:a[c]=n<.5?d:l}),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 u,p;const e=((p=(u=this.artboard)==null?void 0:u.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),c=a(n),d=Math.round(r.r+(c.r-r.r)*o),l=Math.round(r.g+(c.g-r.g)*o),f=Math.round(r.b+(c.b-r.b)*o),g=m=>{const y=Math.max(0,Math.min(255,m)).toString(16);return y.length===1?"0"+y:y};return`#${g(d)}${g(l)}${g(f)}`}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 d;this.debug_objectsTotal=((d=this.artboard)==null?void 0:d.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 l=this.artboard.backgroundImage;let f=this.imageCache.get(l);if(f||(f=new Image,f.src=l,this.imageCache.set(l,f)),f.complete&&f.naturalWidth>0){t.save(),t.globalAlpha=this.normalizeOpacity(this.artboard.backgroundOpacity??100);const g=f.naturalWidth/f.naturalHeight,u=i/n;let p,m,y,S;u>g?(p=i,m=i/g):(m=n,p=n*g),y=-p/2,S=-m/2,t.drawImage(f,y,S,p,m),t.restore()}}t.beginPath(),t.rect(-i/2,-n/2,i,n),t.clip();const r=new Map;this.artboard.objects.forEach(l=>r.set(l.id,l)),this.artboard.objects.filter(l=>!l.parentId).map((l,f)=>{const g=this.objectStates.get(l.id),u=(g==null?void 0:g.zIndex)??f;return{obj:l,zIndex:u}}).sort((l,f)=>l.zIndex-f.zIndex).forEach(({obj:l})=>{this.renderObject(t,l,r)}),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,c=s*a.b+o*a.d+a.f,d=Math.sqrt(a.a*a.a+a.b*a.b),l=Math.sqrt(a.c*a.c+a.d*a.d),f=(e/2+n)*d,g=(i/2+n)*l;return r+f>=0&&r-f<=this.canvasWidth&&c+g>=0&&c-g<=this.canvasHeight}calculateTransform(t,s,o,e,i,n){let a=1,r=1,c=1;const d=o/e,l=t/s;switch(i){case"Contain":l>d?c=s/e:c=t/o,a=r=c;break;case"Cover":l>d?c=t/o:c=s/e,a=r=c;break;case"Fill":a=t/o,r=s/e;break;case"FitWidth":c=t/o,a=r=c;break;case"FitHeight":c=s/e,a=r=c;break;case"None":a=r=1;break;case"ScaleDown":c=Math.min(t/o,s/e),c>1&&(c=1),a=r=c;break;default:a=r=1;break}const f=o*a,g=e*r;let u=0,p=0;return n.includes("Left")?u=0:n.includes("Right")?u=t-f:u=(t-f)/2,n.includes("Top")?p=0:n.includes("Bottom")?p=s-g:p=(s-g)/2,{scaleX:a,scaleY:r,tx:u,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,S,b,v,w,k,A,x,B,$,K,tt,rt,at,V;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=(O,R,P,J,j)=>(this.drawRoundRect(t,O,R,P,J,j),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 O=1/0,R=-1/0,P=1/0,J=-1/0;i.points.forEach(j=>{O=Math.min(O,j.x),R=Math.max(R,j.x),P=Math.min(P,j.y),J=Math.max(J,j.y)}),a===0&&(a=R-O),r===0&&(r=J-P)}const c=O=>{if(O)return O.corner_radius??O.cornerRadius},d=c(e)??c(n)??c(i)??c(s.style)??c(s.geometry)??0,l={...i,width:a,height:r};if(delete l.cornerRadius,l.corner_radius=d,e.visible===!1)return;const f=s.repeaterConfig,g=f&&f.isEnabled&&f.count>1,u=g?f.count:1;for(let O=0;O<u;O++){let R=e.x,P=e.y,J=e.rotation,j=e.scale_x??1,lt=e.scale_y??1;if(g&&O>0){if(f.type==="Linear"){const st=f.offsetX||0,ct=f.offsetY||0,_=f.rotation||0,I=f.scale!==void 0?f.scale:1;R+=O*st,P+=O*ct,J+=O*_,j*=Math.pow(I,O),lt*=Math.pow(I,O)}else if(f.type==="Grid"){const st=f.cols||Math.ceil(Math.sqrt(f.count)),ct=f.gapX||0,_=f.gapY||0,I=Math.floor(O/st),D=O%st,Z=a+ct,bt=r+_;R+=D*Z,P+=I*bt}else if(f.type==="Radial"){const st=f.radius||100,ct=f.startAngle||0,I=(f.endAngle||360)-ct,D=f.count>1?I/(I===360?f.count:f.count-1):0,Z=ct+O*D,bt=Z*Math.PI/180;R=e.x+st*Math.cos(bt),P=e.y+st*Math.sin(bt),J+=Z}}const Y=s.type==="Group"||s.type==="Frame"||s.type==="Component",H=a>0&&r>0;if(!Y&&H){const st=(((y=n.shadow)==null?void 0:y.isEnabled)!==!1?(((S=n.shadow)==null?void 0:S.blur)||0)+10:0)+(((b=n.blur)==null?void 0:b.isEnabled)!==!1&&((v=n.blur)==null?void 0:v.radius)||0)+20;if(!this.isObjectInView(t,R,P,a,r,st))continue}this.debug_objectsRendered++,t.save();const it=[],nt=n.blur||((w=s.style)==null?void 0:w.blur);nt&&nt.amount>0&&it.push(`blur(${nt.amount}px)`);const ft=((k=i==null?void 0:i.type)==null?void 0:k.toLowerCase().includes("image"))||((A=s.type)==null?void 0:A.toLowerCase().includes("image")),M=n.adjustments&&Object.keys(n.adjustments).length>0?n.adjustments:null,Q=i!=null&&i.adjustments&&Object.keys(i.adjustments).length>0?i.adjustments:null,N=ft?Q||M:M||Q,L=ft&&!N?{exposure:0,contrast:0,saturation:100,temperature:0,tint:0,highlights:0,shadows:0,blur:0,negative:0,hue:0}:N;if(e&&L&&(e.geometry=e.geometry||{},e.geometry.adjustments={...L}),L){const st=(L.exposure||0)/100,ct=L.contrast||0,_=1+(L.saturation||0)/100,I=(L.temperature||0)/200,D=(L.tint||0)/200,Z=(L.highlights||0)/500,bt=(L.shadows||0)/500;let Mt="",ht="SourceGraphic";if(st!==0&&(Mt+=`
|
|
8
8
|
<feComponentTransfer in="${ht}" result="exposure">
|
|
9
9
|
<feFuncR type="linear" slope="1" intercept="${st}"/>
|
|
10
10
|
<feFuncG type="linear" slope="1" intercept="${st}"/>
|
|
11
11
|
<feFuncB type="linear" slope="1" intercept="${st}"/>
|
|
12
|
-
</feComponentTransfer>`,ht="exposure"),ct!==0){const mt=(ct+100)/100,
|
|
12
|
+
</feComponentTransfer>`,ht="exposure"),ct!==0){const mt=(ct+100)/100,C=.5*(1-mt);Mt+=`
|
|
13
13
|
<feComponentTransfer in="${ht}" result="contrast">
|
|
14
|
-
<feFuncR type="linear" slope="${mt}" intercept="${
|
|
15
|
-
<feFuncG type="linear" slope="${mt}" intercept="${
|
|
16
|
-
<feFuncB type="linear" slope="${mt}" intercept="${
|
|
14
|
+
<feFuncR type="linear" slope="${mt}" intercept="${C}"/>
|
|
15
|
+
<feFuncG type="linear" slope="${mt}" intercept="${C}"/>
|
|
16
|
+
<feFuncB type="linear" slope="${mt}" intercept="${C}"/>
|
|
17
17
|
</feComponentTransfer>`,ht="contrast"}if(_!==1&&(Mt+=`<feColorMatrix in="${ht}" type="saturate" values="${_}" result="saturate"/>`,ht="saturate"),L.hue&&(Mt+=`<feColorMatrix in="${ht}" type="hueRotate" values="${L.hue}" result="hue"/>`,ht="hue"),L.negative){const mt=1-L.negative/50;Mt+=`
|
|
18
18
|
<feColorMatrix in="${ht}" type="matrix" result="invert"
|
|
19
19
|
values="${mt} 0 0 0 ${1-mt}
|
|
20
20
|
0 ${mt} 0 0 ${1-mt}
|
|
21
21
|
0 0 ${mt} 0 ${1-mt}
|
|
22
|
-
0 0 0 1 0"/>`,ht="invert"}if(I!==0||D!==0||Z!==0||bt!==0){const mt=1+Z+bt,w=mt*(1+I-D/2),Et=mt*(1+D),Xt=mt*(1-I-D/2),$t=L.shadows*.1/255,dt=[w,0,0,0,$t,0,Et,0,0,$t,0,0,Xt,0,$t,0,0,0,1,0].join(" ");Mt+=`<feColorMatrix in="${ht}" type="matrix" values="${dt}" result="advanced"/>`,ht="advanced"}if(L.blur&&(Mt+=`<feGaussianBlur in="${ht}" stdDeviation="${L.blur}" result="blur"/>`,ht="blur"),Mt){const mt=`<svg xmlns="http://www.w3.org/2000/svg"><filter id="f" color-interpolation-filters="sRGB">${Mt}</filter></svg>`,w=btoa(mt);it.push(`url('data:image/svg+xml;base64,${w}#f')`)}}it.length>0?t.filter=it.join(" "):t.filter="none",t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";const z=t.globalAlpha,pt=this.normalizeOpacity(e.opacity!==void 0?e.opacity:100);t.globalAlpha=z*pt;const vt=e.compositeOperation||e.blendMode;if(vt&&vt!=="Normal"){const st=vt.toLowerCase();["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity","source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","copy","xor","multiply","screen"].includes(st)&&(t.globalCompositeOperation=st)}const yt=t,_t=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 Tt=_t.filter(st=>st.isVisible!==!1&&o.has(st.maskId));if(Tt.length>0){const st=Tt[0],ct=o.get(st.maskId),_=this.objectStates.get(ct.id);_&&_.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=yt.filter)}t.translate(Math.round($),Math.round(P)),t.rotate(J*Math.PI/180);const Wt=e.skew_x||0,Vt=e.skew_y||0;(Wt!==0||Vt!==0)&&t.transform(1,Math.tan(Vt*Math.PI/180),Math.tan(Wt*Math.PI/180),1,0,0),t.scale(j*(e.flip_x===!0?-1:1),lt*(e.flip_y===!0?-1:1)),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 Dt=n.shadow;if(Dt&&Dt.isEnabled!==!1){let st=Dt.color||"#000000";(B=(x=this.artboard)==null?void 0:x.tokens)!=null&&B.colors&&this.artboard.tokens.colors[st]&&(st=this.artboard.tokens.colors[st]);const ct=this.normalizeOpacity(Dt.opacity??100),_=Dt.spread||0,D=(Dt.blur||0)+_*1.5;let Z=st;if(st.startsWith("#")){const ht=st.replace("#",""),Pt=parseInt(ht.substring(0,2),16),mt=parseInt(ht.substring(2,4),16),w=parseInt(ht.substring(4,6),16);Z=`rgba(${Pt}, ${mt}, ${w}, ${ct})`}else if(st.startsWith("rgba")){const ht=st.match(/[\d.]+/g);if(ht&&ht.length>=4){const Pt=ht[0],mt=ht[1],w=ht[2],Et=ht[3];Z=`rgba(${Pt}, ${mt}, ${w}, ${parseFloat(Et)*ct})`}}const bt=t.getTransform(),Mt=Math.sqrt(bt.a*bt.a+bt.b*bt.b)||1;t.shadowColor=Z,t.shadowBlur=D*Mt,t.shadowOffsetX=(Dt.offsetX||0)*Mt,t.shadowOffsetY=(Dt.offsetY||0)*Mt}const Nt=s.liquidFill||((R=s.style)==null?void 0:R.liquidFill),zt=s.artEffect||((K=s.style)==null?void 0:K.artEffect);if(Nt&&Nt.enabled){t.save();const st=Nt.fillLevel??.5;t.beginPath();const ct=r/2-r*st;t.rect(-a/2,ct,a,r*st),t.clip(),t.fillStyle=Nt.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(Nt.opacity??1)}if(zt&&zt.enabled){const st=zt.type,ct=zt.intensity??.5;if(st==="glitch"){t.save();const _=ct*10,I=t.getTransform(),D=Math.sqrt(I.a*I.a+I.b*I.b)||1;t.shadowColor="rgba(255, 0, 0, 0.5)",t.shadowBlur=_*D,t.translate(_/2,0)}}if((i==null?void 0:i.type)==="Text")this._renderText(t,s,l,n,e,a,r);else if((i==null?void 0:i.type)==="Image"){const st=i.originalSrc||i.src;if(st){let ct=this.imageCache.get(st);ct||(ct=new Image,ct.onload=()=>{console.log(`[ExodeUI] Image loaded successfully, size: ${ct.naturalWidth}x${ct.naturalHeight}`)},ct.onerror=D=>{console.error("[ExodeUI] Image load failed:",D,`Src preview: ${st.substring(0,100)}...`)},ct.src=st,this.imageCache.set(st,ct));const _=n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1,I=(((tt=n.stroke)==null?void 0:tt.alignment)||"center").toLowerCase();if(_&&(I==="outside"||I==="center")&&this.applyStrokeAlignment(t,n,l,a,r,p),n.fill&&n.fill.type!=="None"){t.save();const D=t.globalAlpha,Z=this.createCanvasFill(t,n.fill,a,r);t.fillStyle=Z||n.fill.color||"transparent",t.globalAlpha=D*this.normalizeOpacity(n.fill.opacity??100),p!==0?(this.drawRoundRect(t,-a/2,-r/2,a,r,p),t.fill()):t.fillRect(-a/2,-r/2,a,r),t.globalAlpha=D,t.restore()}ct.complete&&ct.naturalWidth>0?(p!==0?(t.save(),this.drawRoundRect(t,-a/2,-r/2,a,r,p),t.clip(),t.drawImage(ct,-a/2,-r/2,a,r),t.restore()):t.drawImage(ct,-a/2,-r/2,a,r),_&&I==="inside"&&this.applyStrokeAlignment(t,n,l,a,r,p)):_&&I==="inside"&&this.applyStrokeAlignment(t,n,l,a,r,p)}}else if(i.type==="SVG"){const st=i.svgContent;if(st){const ct=n.palette||[],_=n.fill,I=n.stroke,D=_?this.normalizeOpacity(_.opacity??100):1,Z=(_==null?void 0:_.type)==="Solid"&&(!I||I.isEnabled===!1||I.type==="Solid"&&I.color===_.color),bt=_&&_.type!=="None"?Z?"monochrome":_.type==="Solid"?(_.color||"")+"|opacity:"+D:JSON.stringify(_.stops||[])+"|opacity:"+D:"",Mt=I&&I.isEnabled!==!1&&(I.width||0)>0?Z?["monochrome",I.width||0,I.trimStart??0,I.trimEnd??1,I.trimOffset??0,I.dashOffset??0].join("|"):[I.width||0,I.fill?I.fill.type==="Solid"?I.fill.color||"":JSON.stringify(I.fill.stops||[]):I.color||"",I.opacity??1,I.lineCap||"",I.lineJoin||"",(I.dashArray||[]).join(","),I.trimStart??0,I.trimEnd??1,I.trimOffset??0,I.dashOffset??0].join("|"):"nostroke",ht=[s.id,ct.join("_"),bt,Mt,e.opacity??100,e.visible!==!1?"v":"h"].join("_");let Pt=this.imageCache.get(ht);if(!Pt){Pt=new Image,Pt.crossOrigin="anonymous";let w=st;if(w.match(/xmlns\s*=\s*["']http:\/\/www\.w3\.org\/2000\/svg["']/i)||(w=w.replace(/<svg([^>]*)>/i,(T,X)=>X.includes("xmlns=")?T:`<svg xmlns="http://www.w3.org/2000/svg"${X}>`)),i.colors&&i.colors.length>0&&ct.length>0&&i.colors.forEach((T,X)=>{if(ct[X]){const ut=T.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),E=new RegExp(ut,"gi");w=w.replace(E,ct[X])}}),_&&_.type&&_.type!=="None"){if(_.type==="Solid"&&_.color){const T=Z?"#FFFFFF":_.color,X=Z?1:this.normalizeOpacity(_.opacity??100);w=w.replace(/\bfill\s*=\s*["'][^"']*["']/gi,ut=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(ut)?ut:`fill="${T}"`),w=w.replace(/fill\s*:\s*[^;"')]+/gi,ut=>/fill\s*:\s*(none|transparent)/i.test(ut)?ut:`fill:${T}`),X<1&&(w=w.replace(/\bfill-opacity\s*=\s*["'][^"']*["']/gi,`fill-opacity="${X}"`),w=w.replace(/fill-opacity\s*:\s*[^;"')]+/gi,`fill-opacity:${X}`),w.match(/\bfill-opacity\s*=/i)||(w=w.replace(/(<svg[^>]*>)/i,`$1<g fill-opacity="${X}">`),w=w.replace(/<\/svg>/i,"</g></svg>")))}else if(_.type==="LinearGradient"||_.type==="RadialGradient"||_.type==="Linear"||_.type==="Radial"){const T="exode-fill",X=this.normalizeOpacity(_.opacity??100),ut=(_.stops||[]).map(F=>{const et=F.offset!==void 0?F.offset:F.pos??0,It=this.normalizeOpacity(F.opacity??100)*X;return`<stop offset="${et*100}%" stop-color="${F.color||"#000"}" stop-opacity="${It}"/>`}).join("");let E="";if(_.type==="LinearGradient"||_.type==="Linear"){const F=(Ft,Ct)=>Array.isArray(Ft)?Ft[Ct]??(Ct===0?0:1):Ft&&typeof Ft=="object"?Ft[Ct===0?"x":"y"]??(Ct===0?0:1):Ct===0?0:1,et=F(_.start,0)*100,It=F(_.start,1)*100,Ot=F(_.end,0)*100,St=F(_.end,1)*100;E=`<linearGradient id="${T}" x1="${et}%" y1="${It}%" x2="${Ot}%" y2="${St}%" gradientUnits="objectBoundingBox">${ut}</linearGradient>`}else{const F=(St,Ft)=>Array.isArray(St)?St[Ft]??.5:St&&typeof St=="object"?St[Ft===0?"x":"y"]??.5:.5,et=F(_.center,0)*100,It=F(_.center,1)*100,Ot=(_.radius??.5)*100;E=`<radialGradient id="${T}" cx="${et}%" cy="${It}%" r="${Ot}%" gradientUnits="objectBoundingBox">${ut}</radialGradient>`}/<defs>/i.test(w)?w=w.replace(/<defs>/i,`<defs>${E}`):w=w.replace(/<svg([^>]*)>/i,`<svg$1><defs>${E}</defs>`),w=w.replace(/\bfill\s*=\s*["'][^"']*["']/gi,F=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(F)?F:`fill="url(#${T})"`),w=w.replace(/fill\s*:\s*[^;"')]+/gi,F=>/fill\s*:\s*(none|transparent)/i.test(F)?F:`fill:url(#${T})`)}}const Et=(T,X,ut=1)=>{const E=(T.stops||[]).map(St=>{const Ft=St.offset!==void 0?St.offset:St.pos??0,Ct=this.normalizeOpacity(St.opacity??100)*ut;return`<stop offset="${Ft*100}%" stop-color="${St.color||"#000"}" stop-opacity="${Ct}"/>`}).join(""),F=(St,Ft,Ct=.5)=>Array.isArray(St)?St[Ft]??Ct:St&&typeof St=="object"?St[Ft===0?"x":"y"]??Ct:Ct;if(T.type==="LinearGradient"||T.type==="Linear"){const St=F(T.start,0,0)*100,Ft=F(T.start,1,0)*100,Ct=F(T.end,0,1)*100,Gt=F(T.end,1,1)*100;return`<linearGradient id="${X}" x1="${St}%" y1="${Ft}%" x2="${Ct}%" y2="${Gt}%" gradientUnits="objectBoundingBox">${E}</linearGradient>`}const et=F(T.center,0,.5)*100,It=F(T.center,1,.5)*100,Ot=(T.radius??.5)*100;return`<radialGradient id="${X}" cx="${et}%" cy="${It}%" r="${Ot}%" gradientUnits="objectBoundingBox">${E}</radialGradient>`},Xt=(T,X)=>/<defs>/i.test(T)?T.replace(/<defs>/i,`<defs>${X}`):T.replace(/(<svg[^>]*>)/i,`$1<defs>${X}</defs>`);if(I&&I.isEnabled!==!1&&(I.width||0)>0){const T=I.width||1,X=Z?1:this.normalizeOpacity(I.opacity??100),ut=Z?"#FFFFFF":I.color||(_==null?void 0:_.color)||"#000000";let E="";const F=I.fill;if(F&&F.type){if(F.type==="Solid")E=F.color||I.color||"#000000";else if(F.type==="LinearGradient"||F.type==="RadialGradient"||F.type==="Linear"||F.type==="Radial"){const Ct="exode-stroke";w=Xt(w,Et(F,Ct,X)),E=`url(#${Ct})`}}E||(E=ut),w.match(/\bstroke\s*=\s*["']/i)?w=w.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,Ct=>/stroke\s*=\s*["']\s*(none|transparent)\s*["']/i.test(Ct)?Ct:`stroke="${E}"`):w=w.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke="${E}"`),w=w.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),`stroke:${E}`),w.match(/\bstroke-width\s*=\s*["']/i)?w=w.replace(/\bstroke-width\s*=\s*["'][^"']*["']/gi,`stroke-width="${T}"`):w=w.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-width="${T}"`),w=w.replace(/stroke-width\s*:\s*[^;"')]+/gi,`stroke-width:${T}`),w.match(/\bstroke-opacity\s*=\s*["']/i)?w=w.replace(/\bstroke-opacity\s*=\s*["'][^"']*["']/gi,`stroke-opacity="${X}"`):w=w.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-opacity="${X}"`),w=w.replace(/stroke-opacity\s*:\s*[^;"')]+/gi,`stroke-opacity:${X}`),I.lineCap&&(w=w.replace(/\bstroke-linecap\s*=\s*["'][^"']*["']/gi,`stroke-linecap="${I.lineCap}"`),w=w.replace(/stroke-linecap\s*:\s*[^;"')]+/gi,`stroke-linecap:${I.lineCap}`)),I.lineJoin&&(w=w.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${I.lineJoin}"`),w=w.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${I.lineJoin}`));const et=I.trimStart??0,It=I.trimEnd??1,Ot=I.trimOffset??0,St=I.dashOffset??0,Ft=et!==0||It!==1||Ot!==0||St!==0;if(Ft){const Ct=Math.max(0,Math.min(1,et)),Gt=Math.max(0,Math.min(1,It));this.frameCount%600===0&&this.debugLog(`SVG Trim - Object: ${s.name||s.id}, Start: ${Ct}, End: ${Gt}`);let Jt=i.width||a||100,Qt=i.height||r||100;const U=st.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(U){const Ut=parseFloat(U[1]),qt=parseFloat(U[2]);!isNaN(Ut)&&!isNaN(qt)&&(Jt=Ut,Qt=qt)}const G=(Jt+Qt)*2,q=(Ot%1+1)%1,wt=(St%1+1)%1;let Rt="",Ht=0;if(Ct>=Gt)Rt=`0 ${G}`,Ht=0;else{const Ut=G*(Gt-Ct),qt=G-Ut;Ht=-(G*(Ct+q+wt)),Rt=`${Ut} ${qt}`}w.match(/\bstroke-dasharray\s*=/i)?w=w.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${Rt}"`):w=w.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dasharray="${Rt}"`),w=w.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${Rt}`),w.match(/\bstroke-dashoffset\s*=/i)?w=w.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${Ht}"`):w=w.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dashoffset="${Ht}"`),w=w.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${Ht}`)}else if(I.dashArray&&I.dashArray.length>0){const Ct=I.dashArray.join(" ");w=w.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${Ct}"`),w=w.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${Ct}`),I.dashOffset&&(w=w.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${I.dashOffset}"`),w=w.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${I.dashOffset}`))}if(!/\bstroke\s*=\s*["']/i.test(st)&&!new RegExp("(?<![a-z-])stroke\\s*:","i").test(st)){let Ct="",Gt="";if(Ft){const G=i.width||a||100,q=i.height||r||100,wt=(G+q)*2,Rt=Math.max(0,Math.min(1,et)),Ht=Math.max(0,Math.min(1,It)),Ut=(Ot%1+1)%1,qt=(St%1+1)%1;if(Rt>=Ht)Ct=` stroke-dasharray="0 ${wt}"`,Gt=' stroke-dashoffset="0"';else{const Se=wt*(Ht-Rt),rs=wt-Se,ls=-(wt*(Rt+Ut+qt));Ct=` stroke-dasharray="${Se} ${rs}"`,Gt=` stroke-dashoffset="${ls}"`}}else(rt=I.dashArray)!=null&&rt.length&&(Ct=` stroke-dasharray="${I.dashArray.join(" ")}"`,I.dashOffset&&(Gt=` stroke-dashoffset="${I.dashOffset}"`));const Jt=I.lineCap?` stroke-linecap="${I.lineCap}"`:"",Qt=I.lineJoin?` stroke-linejoin="${I.lineJoin}"`:"",U=`stroke="${E}" stroke-width="${T}" stroke-opacity="${X}"${Jt}${Qt}${Ct}${Gt}`;w=w.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(G,q,wt)=>`${q}${wt}<g ${U}>`),w=w.replace(/<\/svg>/i,"</g></svg>")}}else I&&I.isEnabled===!1&&(w=w.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,'stroke="none"'),w=w.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),"stroke:none"));const $t=new Blob([w],{type:"image/svg+xml"}),dt=URL.createObjectURL($t);Pt.onload=()=>{if(URL.revokeObjectURL(dt),this.frameCount%900===0){const T=this.imageCache.get(ht);T&&this.debugLog(`SVG Payload Ready: ${s.name||s.id} (${T.naturalWidth}x${T.naturalHeight})`)}},Pt.onerror=()=>{URL.revokeObjectURL(dt),this.debugLog(`SVG Error: Failed to load payload for ${s.name||s.id}`)},Pt.src=dt,this.imageCache.set(ht,Pt)}let mt=null;if(Pt.complete&&Pt.naturalWidth>0?(mt=Pt,this.lastValidSvgImgMap.set(s.id,Pt)):mt=this.lastValidSvgImgMap.get(s.id)||null,mt&&mt.complete&&mt.naturalWidth>0){const w=Math.max(1,a),Et=Math.max(1,r);if(Z&&(_==null?void 0:_.type)==="Solid"){this.maskBuffer||(this.maskBuffer=document.createElement("canvas"),this.maskCtx=this.maskBuffer.getContext("2d")),this.maskBuffer.width=w,this.maskBuffer.height=Et,this.maskCtx.setTransform(1,0,0,1,0,0),this.maskCtx.globalCompositeOperation="source-over",this.maskCtx.globalAlpha=1,this.maskCtx.filter="none",this.maskCtx.clearRect(0,0,w,Et),this.maskCtx.drawImage(mt,0,0,w,Et),this.maskCtx.globalCompositeOperation="source-in";const Xt=_.color||"#000000",$t=this.normalizeOpacity(_.opacity??100);this.maskCtx.fillStyle=Xt,this.maskCtx.globalAlpha=$t,this.maskCtx.fillRect(0,0,w,Et),t.drawImage(this.maskBuffer,-w/2,-Et/2,w,Et)}else p!==0?(t.save(),this.drawRoundRect(t,-w/2,-Et/2,w,Et,p),t.clip(),t.drawImage(mt,-w/2,-Et/2,w,Et),t.restore()):t.drawImage(mt,-w/2,-Et/2,w,Et)}}}else if(l.type==="LineGraph")this.renderLineGraph(t,l,a,r);else if(s.type==="Shape"){if(this.applyPath(t,l,a,r,p),t.save(),n.blur&&n.blur.amount>0&&(t.filter=`blur(${n.blur.amount}px)`),n.fill){const st=t.globalAlpha;if(((at=n.fill)==null?void 0:at.type)==="Image"&&(n.fill.originalSrc||n.fill.src)){const ct=n.fill.originalSrc||n.fill.src;let _=this.imageCache.get(ct);_||(_=new Image,_.src=ct,this.imageCache.set(ct,_)),_.complete&&_.naturalWidth>0&&(t.save(),this.applyPath(t,l,a,r,p),t.clip(),this.renderFittedImage(t,_,-a/2,-r/2,a,r,n.fill.fillMode),t.restore())}else{const ct=this.createCanvasFill(t,n.fill,a,r);t.fillStyle=ct||(typeof n.fill=="string"?n.fill:n.fill.color||"transparent"),t.globalAlpha=st*this.normalizeOpacity(n.fill.opacity??100),this.applyPath(t,l,a,r,p),t.fill()}t.globalAlpha=st}t.restore(),n.stroke&&n.stroke.width>0&&this.applyStrokeAlignment(t,n,l,a,r,p)}else if(s.type==="Frame"||s.type==="Group"&&!s.isStructuralGroup){const st=e.width??i.width??s.width??a,ct=e.height??i.height??s.height??r,_=p;if(t.save(),t.beginPath(),this.drawRoundRect(t,-st/2,-ct/2,st,ct,_),n.fill&&n.fill.type!=="None"){const I=t.globalAlpha,D=this.createCanvasFill(t,n.fill,st,ct);t.fillStyle=D||n.fill.color||"transparent",t.globalAlpha=I*this.normalizeOpacity(n.fill.opacity??100),t.fill(),t.globalAlpha=I}if(t.restore(),n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1){const I={type:"Rectangle"};this.applyStrokeAlignment(t,n,I,st,ct,_)}}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):this.frameCount%60===0&&console.warn("[Engine] Unhandled object type in renderObject:",s.type,"Geo:",(N=s.geometry)==null?void 0:N.type));if(this.applyArtEffectOverlay(t,s,l,a,r,p),zt&&zt.enabled&&zt.type==="glitch"&&t.restore(),Nt&&Nt.enabled&&t.restore(),s.children&&s.children.length>0){const ct=s.type==="Frame",_=s.clipsContent!==void 0?s.clipsContent:s.clipContent!==void 0?s.clipContent:ct;if(t.save(),_){t.beginPath();const D=e.width??(i==null?void 0:i.width)??s.width??0,Z=e.height??(i==null?void 0:i.height)??s.height??0,bt=e.cornerRadius??(i==null?void 0:i.corner_radius)??s.cornerRadius??0;this.drawRoundRect(t,-D/2,-Z/2,D,Z,bt),t.clip()}let I=0;for(s.children.forEach(D=>{const Z=o.get(D);if(!Z)return;const bt=this.objectStates.get(D),Mt=(bt==null?void 0:bt.geometry)||Z.geometry;if(Mt&&Mt.isMask&&(bt==null?void 0:bt.visible)!==!1){const ht=Mt.width||0,Pt=Mt.height||0;this.applyObjectTransform(t,D);const mt=(bt==null?void 0:bt.corner_radius)??(Mt==null?void 0:Mt.corner_radius)??0;this.applyPath(t,Mt,ht,Pt,mt),t.clip(),I++}else this.renderObject(t,Z,o)});I>0;)t.restore(),I--;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(I=>I.isVisible!==!1&&o.has(I.maskId)).forEach(I=>{var mt,w,Et,Xt,$t,dt;const D=o.get(I.maskId),Z=this.objectStates.get(D.id),bt=I.feather||0,Mt=I.inverted===!0,ht=I.opacity!==void 0?typeof I.opacity=="number"?I.opacity:I.opacity/100:1;if((I.type||"alpha")==="luma"){(!this.lumaBuffer||this.lumaBuffer.width!==this.maskBuffer.width||this.lumaBuffer.height!==this.maskBuffer.height)&&(this.lumaBuffer=document.createElement("canvas"),this.lumaBuffer.width=this.maskBuffer.width,this.lumaBuffer.height=this.maskBuffer.height,this.lumaCtx=this.lumaBuffer.getContext("2d",{willReadFrequently:!0}),this.lumaCtx&&(this.lumaCtx.imageSmoothingEnabled=!0,this.lumaCtx.imageSmoothingQuality="high")),this.lumaCtx.setTransform(1,0,0,1,0,0),this.lumaCtx.globalCompositeOperation="source-over",this.lumaCtx.globalAlpha=1,this.lumaCtx.filter="none",this.lumaCtx.clearRect(0,0,this.lumaBuffer.width,this.lumaBuffer.height),this.lumaCtx.save(),this.rootTransform&&this.lumaCtx.setTransform(this.rootTransform),this.applyAbsoluteTransform(this.lumaCtx,D.id,o),bt>0&&(this.lumaCtx.filter=`blur(${bt}px)`),this.lumaCtx.globalAlpha=ht;const T=(Z==null?void 0:Z.width)||D.geometry.width||0,X=(Z==null?void 0:Z.height)||D.geometry.height||0,ut=(Z==null?void 0:Z.corner_radius)??D.corner_radius??0;if(((mt=D.geometry)==null?void 0:mt.type)==="Text"){const It=Z!=null&&Z.geometry?this.deepMerge(D.geometry,Z.geometry):D.geometry,Ot=Z!=null&&Z.style?this.deepMerge(D.style,Z.style):D.style;this._renderText(this.lumaCtx,D,{...It,width:T,height:X,corner_radius:ut},Ot,Z,T,X,!0)}else if(((w=D.geometry)==null?void 0:w.type)==="Image"){const It=D.geometry.src;if(It){let Ot=this.imageCache.get(It);Ot||(Ot=new Image,Ot.src=It,this.imageCache.set(It,Ot)),Ot.complete&&Ot.naturalWidth>0?this.lumaCtx.drawImage(Ot,-T/2,-X/2,T,X):(this.applyPath(this.lumaCtx,D.geometry,T,X,ut),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else if(((Et=D.geometry)==null?void 0:Et.type)==="SVG"){const It=D.geometry.svgContent;if(It){const Ot=`__lumamask_${D.id}`;let St=this.imageCache.get(Ot);if(!St){St=new Image;const Ft=new Blob([It],{type:"image/svg+xml"});St.src=URL.createObjectURL(Ft),St.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(Ot,St)}St.complete&&St.naturalWidth>0?this.lumaCtx.drawImage(St,-T/2,-X/2,T,X):(this.applyPath(this.lumaCtx,D.geometry,T,X,ut),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else this.applyPath(this.lumaCtx,D.geometry,T,X,ut),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill();this.lumaCtx.restore();const E=this.maskCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight),F=this.lumaCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight).data,et=E.data;for(let It=0;It<et.length;It+=4){const Ot=F[It],St=F[It+1],Ft=F[It+2];let Ct=(.299*Ot+.587*St+.114*Ft)/255;Mt&&(Ct=1-Ct),et[It+3]*=Ct}this.maskCtx.putImageData(E,0,0)}else{this.maskCtx.save(),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),this.maskCtx.globalCompositeOperation=Mt?"destination-out":"destination-in",bt>0&&(this.maskCtx.filter=`blur(${bt}px)`),this.maskCtx.globalAlpha=ht,this.applyAbsoluteTransform(this.maskCtx,D.id,o);const T=(Z==null?void 0:Z.width)||D.geometry.width||0,X=(Z==null?void 0:Z.height)||D.geometry.height||0,ut=(Z==null?void 0:Z.corner_radius)??D.corner_radius??0;if(((Xt=D.geometry)==null?void 0:Xt.type)==="Text"){const E=Z!=null&&Z.geometry?this.deepMerge(D.geometry,Z.geometry):D.geometry,F=Z!=null&&Z.style?this.deepMerge(D.style,Z.style):D.style;this._renderText(this.maskCtx,D,{...E,width:T,height:X,corner_radius:ut},F,Z,T,X,!0)}else if((($t=D.geometry)==null?void 0:$t.type)==="Image"){const E=D.geometry.src;if(E){let F=this.imageCache.get(E);F||(F=new Image,F.src=E,this.imageCache.set(E,F)),F.complete&&F.naturalWidth>0?this.maskCtx.drawImage(F,-T/2,-X/2,T,X):(this.applyPath(this.maskCtx,D.geometry,T,X,ut),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else if(((dt=D.geometry)==null?void 0:dt.type)==="SVG"){const E=D.geometry.svgContent;if(E){const F=`__alphamask_${D.id}`;let et=this.imageCache.get(F);if(!et){et=new Image;const It=new Blob([E],{type:"image/svg+xml"});et.src=URL.createObjectURL(It),et.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(F,et)}et.complete&&et.naturalWidth>0?this.maskCtx.drawImage(et,-T/2,-X/2,T,X):(this.applyPath(this.maskCtx,D.geometry,T,X,ut),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else this.applyPath(this.maskCtx,D.geometry,T,X,ut),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill();this.maskCtx.restore()}}),yt.save(),yt.setTransform(1,0,0,1,0,0);const _=s.maskBlendMode||s.blendMode;_&&_!=="Normal"&&(yt.globalCompositeOperation=_.toLowerCase()),yt.drawImage(this.maskBuffer,0,0),yt.restore(),yt.restore()}else t.restore()}}_renderText(t,s,o,e,i,n,a,r=!1,c=!1){var V,H,it,nt,ft;let p=o.text||"";if(o.textInputId&&!r){const M=this.inputs.get(o.textInputId);M!==void 0&&(p=String(M),i.geometry&&i.geometry.type==="Text"&&(i.geometry.text=p))}if(o.svgPath){const M=o.svgPath;t.save();const Q=((V=e==null?void 0:e.fill)==null?void 0:V.color)||"#000000",Y=((H=e==null?void 0:e.fill)==null?void 0:H.opacity)!==void 0?(it=e==null?void 0:e.fill)==null?void 0:it.opacity:1;t.fillStyle=Q,t.globalAlpha*=Y;const L=new Path2D(M);t.fill(L),t.restore();return}let l=p||"";o.enableSegments===!0&&o.segments&&Array.isArray(o.segments)&&(l=o.segments.map(M=>M&&M.text?M.text:"").join(""));const f=o.textCase||"none";f==="uppercase"?l=l.toUpperCase():f==="lowercase"?l=l.toLowerCase():f==="capitalize"&&(l=l.replace(/\b\w/g,M=>M.toUpperCase()));let g=((nt=o.fontWeight)==null?void 0:nt.toString())||"400",d=o.fontStyle||"normal";g.toLowerCase().includes("italic")&&(d="italic",g=g.replace(/italic/gi,"").trim()||"400");const u=this.mapFontWeight(g),m=Math.max(1,o.fontSize||32);let y=o.fontFamily||"Inter";const S=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];S.forEach(M=>{const Q=new RegExp(`[\\s-]${M}$`,"i");Q.test(y)&&(y=y.replace(Q,"").trim())});const b=`${d} ${u} ${m}px "${y}", sans-serif`;t.font=b;const v=o.textVerticalAlign||"top";t.textBaseline="top";const C=o.textAlign||"left";t.textAlign=C;let k=0;if(typeof o.letterSpacing=="number")k=o.letterSpacing;else if(typeof o.letterSpacing=="object"&&o.letterSpacing.value!==void 0){const M=o.letterSpacing;k=M.unit==="PERCENT"?M.value/100*m:M.value}t.letterSpacing!==void 0&&(t.letterSpacing=`${k}px`);const A=o.paragraphSpacing||0;let x=o.lineHeight??1.2;typeof x=="string"&&(x=parseFloat(x)),x>5&&m>0&&(x=x/m);const B=(x||1.2)*m,R=o.width&&o.width>0?Math.ceil(o.width):1e5,K=ae({text:l,fontFamily:y,fontSize:m,fontWeight:u,fontStyle:d,lineHeight:x,width:R,letterSpacing:k,paragraphSpacing:A,segments:o.segments,enableSegments:o.enableSegments,textCase:f}),tt=K.lines||[],rt=K.maxFontSize||m,at=this.fontLeadingFactors[y]??.5,N=(B-m)*at;let O=K.height,$=-O/2;a>0&&a>O&&(v==="top"?$=-a/2:v==="middle"||v==="center"?$=-O/2:v==="bottom"&&($=a/2-O)),$+=N;let P=null,J=0;if(o.pathId&&this.artboard){const M=this.artboard.objects.find(Q=>Q.id===o.pathId);if(M&&M.type==="Shape"&&((ft=M.geometry)==null?void 0:ft.type)==="Path"){const Q=this.objectStates.get(M.id),Y=Q!=null&&Q.geometry?this.deepMerge(M.geometry,Q.geometry):M.geometry,L=(Q==null?void 0:Q.scale_x)!==void 0?(M.width||0)*Q.scale_x:M.width||0,z=(Q==null?void 0:Q.scale_y)!==void 0?(M.height||0)*Q.scale_y:M.height||0;P={geo:Y,obj:M,w:L,h:z},J=this.getPerimeter(Y,L,z)}}const j=(M,Q)=>{var L,z;if(k===0&&(!o.enableSegments||!((L=o.segments)!=null&&L.length)))return t.measureText(M).width;let Y=0;for(let pt=0;pt<M.length;pt++){const vt=Q+pt;let yt=0;if(o.enableSegments===!0&&((z=o.segments)==null?void 0:z.length)>0){let _t=0,kt=null;for(const Tt of o.segments){if(vt<_t+(Tt.text||"").length){kt=Tt;break}_t+=(Tt.text||"").length}if(kt){t.save();let Tt=kt.fontFamily||o.fontFamily||"Inter";const Wt=this.mapFontWeight((kt.fontWeight||o.fontWeight||"400").toString()),Vt=kt.fontStyle||d,Dt=kt.fontSize||m;t.font=`${Vt} ${Wt} ${Dt}px "${Tt}", sans-serif`,yt=t.measureText(M[pt]).width,t.restore()}else yt=t.measureText(M[pt]).width}else yt=t.measureText(M[pt]).width;Y+=yt+k}return Y-(M.length>0?k:0)},lt=(M,Q,Y,L,z)=>{var kt,Tt;const vt=(z===0||l[z-1]===`
|
|
23
|
-
`||l[z-1]==="\r")&&o.paragraphIndent?o.paragraphIndent:0,yt=(!r||c)&&(s.behaviors||[]).some(Wt=>Wt.enabled&&(Wt.type.toString().includes("Text")||["Typewriter","Scramble","Wave","Bounce","GlitchText","Reveal3D","RevealSlide","RevealBlur"].includes(Wt.type)));if(!o.pathId&&!yt&&(o.enableSegments!==!0||!o.segments||o.segments.length===0))t.font=b,L?t.strokeText(M,Q+vt,
|
|
22
|
+
0 0 0 1 0"/>`,ht="invert"}if(I!==0||D!==0||Z!==0||bt!==0){const mt=1+Z+bt,C=mt*(1+I-D/2),Et=mt*(1+D),Gt=mt*(1-I-D/2),Rt=L.shadows*.1/255,dt=[C,0,0,0,Rt,0,Et,0,0,Rt,0,0,Gt,0,Rt,0,0,0,1,0].join(" ");Mt+=`<feColorMatrix in="${ht}" type="matrix" values="${dt}" result="advanced"/>`,ht="advanced"}if(L.blur&&(Mt+=`<feGaussianBlur in="${ht}" stdDeviation="${L.blur}" result="blur"/>`,ht="blur"),Mt){const mt=`<svg xmlns="http://www.w3.org/2000/svg"><filter id="f" color-interpolation-filters="sRGB">${Mt}</filter></svg>`,C=btoa(mt);it.push(`url('data:image/svg+xml;base64,${C}#f')`)}}it.length>0?t.filter=it.join(" "):t.filter="none",t.imageSmoothingEnabled=!0,t.imageSmoothingQuality="high";const z=t.globalAlpha,pt=this.normalizeOpacity(e.opacity!==void 0?e.opacity:100);t.globalAlpha=z*pt;const vt=e.compositeOperation||e.blendMode;if(vt&&vt!=="Normal"){const st=vt.toLowerCase();["multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity","source-over","source-in","source-out","source-atop","destination-over","destination-in","destination-out","destination-atop","lighter","copy","xor","multiply","screen"].includes(st)&&(t.globalCompositeOperation=st)}const yt=t,_t=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 Tt=_t.filter(st=>st.isVisible!==!1&&o.has(st.maskId));if(Tt.length>0){const st=Tt[0],ct=o.get(st.maskId),_=this.objectStates.get(ct.id);_&&_.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=yt.filter)}t.translate(Math.round(R),Math.round(P)),t.rotate(J*Math.PI/180);const Wt=e.skew_x||0,Yt=e.skew_y||0;(Wt!==0||Yt!==0)&&t.transform(1,Math.tan(Yt*Math.PI/180),Math.tan(Wt*Math.PI/180),1,0,0),t.scale(j*(e.flip_x===!0?-1:1),lt*(e.flip_y===!0?-1:1)),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 Dt=n.shadow;if(Dt&&Dt.isEnabled!==!1){let st=Dt.color||"#000000";(B=(x=this.artboard)==null?void 0:x.tokens)!=null&&B.colors&&this.artboard.tokens.colors[st]&&(st=this.artboard.tokens.colors[st]);const ct=this.normalizeOpacity(Dt.opacity??100),_=Dt.spread||0,D=(Dt.blur||0)+_*1.5;let Z=st;if(st.startsWith("#")){const ht=st.replace("#",""),Pt=parseInt(ht.substring(0,2),16),mt=parseInt(ht.substring(2,4),16),C=parseInt(ht.substring(4,6),16);Z=`rgba(${Pt}, ${mt}, ${C}, ${ct})`}else if(st.startsWith("rgba")){const ht=st.match(/[\d.]+/g);if(ht&&ht.length>=4){const Pt=ht[0],mt=ht[1],C=ht[2],Et=ht[3];Z=`rgba(${Pt}, ${mt}, ${C}, ${parseFloat(Et)*ct})`}}const bt=t.getTransform(),Mt=Math.sqrt(bt.a*bt.a+bt.b*bt.b)||1;t.shadowColor=Z,t.shadowBlur=D*Mt,t.shadowOffsetX=(Dt.offsetX||0)*Mt,t.shadowOffsetY=(Dt.offsetY||0)*Mt}const Vt=s.liquidFill||(($=s.style)==null?void 0:$.liquidFill),zt=s.artEffect||((K=s.style)==null?void 0:K.artEffect);if(Vt&&Vt.enabled){t.save();const st=Vt.fillLevel??.5;t.beginPath();const ct=r/2-r*st;t.rect(-a/2,ct,a,r*st),t.clip(),t.fillStyle=Vt.color||"#3b82f6",t.globalAlpha=t.globalAlpha*(Vt.opacity??1)}if(zt&&zt.enabled){const st=zt.type,ct=zt.intensity??.5;if(st==="glitch"){t.save();const _=ct*10,I=t.getTransform(),D=Math.sqrt(I.a*I.a+I.b*I.b)||1;t.shadowColor="rgba(255, 0, 0, 0.5)",t.shadowBlur=_*D,t.translate(_/2,0)}}if((i==null?void 0:i.type)==="Text")this._renderText(t,s,l,n,e,a,r);else if((i==null?void 0:i.type)==="Image"){const st=i.originalSrc||i.src;if(st){let ct=this.imageCache.get(st);ct||(ct=new Image,ct.onload=()=>{console.log(`[ExodeUI] Image loaded successfully, size: ${ct.naturalWidth}x${ct.naturalHeight}`)},ct.onerror=D=>{console.error("[ExodeUI] Image load failed:",D,`Src preview: ${st.substring(0,100)}...`)},ct.src=st,this.imageCache.set(st,ct));const _=n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1,I=(((tt=n.stroke)==null?void 0:tt.alignment)||"center").toLowerCase();if(_&&(I==="outside"||I==="center")&&this.applyStrokeAlignment(t,n,l,a,r,d),n.fill&&n.fill.type!=="None"){t.save();const D=t.globalAlpha,Z=this.createCanvasFill(t,n.fill,a,r);t.fillStyle=Z||n.fill.color||"transparent",t.globalAlpha=D*this.normalizeOpacity(n.fill.opacity??100),d!==0?(this.drawRoundRect(t,-a/2,-r/2,a,r,d),t.fill()):t.fillRect(-a/2,-r/2,a,r),t.globalAlpha=D,t.restore()}ct.complete&&ct.naturalWidth>0?(d!==0?(t.save(),this.drawRoundRect(t,-a/2,-r/2,a,r,d),t.clip(),t.drawImage(ct,-a/2,-r/2,a,r),t.restore()):t.drawImage(ct,-a/2,-r/2,a,r),_&&I==="inside"&&this.applyStrokeAlignment(t,n,l,a,r,d)):_&&I==="inside"&&this.applyStrokeAlignment(t,n,l,a,r,d)}}else if(i.type==="SVG"){const st=i.svgContent;if(st){const ct=n.palette||[],_=n.fill,I=n.stroke,D=_?this.normalizeOpacity(_.opacity??100):1,Z=(_==null?void 0:_.type)==="Solid"&&(!I||I.isEnabled===!1||I.type==="Solid"&&I.color===_.color),bt=_&&_.type!=="None"?Z?"monochrome":_.type==="Solid"?(_.color||"")+"|opacity:"+D:JSON.stringify(_.stops||[])+"|opacity:"+D:"",Mt=I&&I.isEnabled!==!1&&(I.width||0)>0?Z?["monochrome",I.width||0,I.trimStart??0,I.trimEnd??1,I.trimOffset??0,I.dashOffset??0].join("|"):[I.width||0,I.fill?I.fill.type==="Solid"?I.fill.color||"":JSON.stringify(I.fill.stops||[]):I.color||"",I.opacity??1,I.lineCap||"",I.lineJoin||"",(I.dashArray||[]).join(","),I.trimStart??0,I.trimEnd??1,I.trimOffset??0,I.dashOffset??0].join("|"):"nostroke",ht=[s.id,ct.join("_"),bt,Mt,e.opacity??100,e.visible!==!1?"v":"h"].join("_");let Pt=this.imageCache.get(ht);if(!Pt){Pt=new Image,Pt.crossOrigin="anonymous";let C=st;if(C.match(/xmlns\s*=\s*["']http:\/\/www\.w3\.org\/2000\/svg["']/i)||(C=C.replace(/<svg([^>]*)>/i,(T,G)=>G.includes("xmlns=")?T:`<svg xmlns="http://www.w3.org/2000/svg"${G}>`)),i.colors&&i.colors.length>0&&ct.length>0&&i.colors.forEach((T,G)=>{if(ct[G]){const ut=T.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&"),E=new RegExp(ut,"gi");C=C.replace(E,ct[G])}}),_&&_.type&&_.type!=="None"){if(_.type==="Solid"&&_.color){const T=Z?"#FFFFFF":_.color,G=Z?1:this.normalizeOpacity(_.opacity??100);C=C.replace(/\bfill\s*=\s*["'][^"']*["']/gi,ut=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(ut)?ut:`fill="${T}"`),C=C.replace(/fill\s*:\s*[^;"')]+/gi,ut=>/fill\s*:\s*(none|transparent)/i.test(ut)?ut:`fill:${T}`),G<1&&(C=C.replace(/\bfill-opacity\s*=\s*["'][^"']*["']/gi,`fill-opacity="${G}"`),C=C.replace(/fill-opacity\s*:\s*[^;"')]+/gi,`fill-opacity:${G}`),C.match(/\bfill-opacity\s*=/i)||(C=C.replace(/(<svg[^>]*>)/i,`$1<g fill-opacity="${G}">`),C=C.replace(/<\/svg>/i,"</g></svg>")))}else if(_.type==="LinearGradient"||_.type==="RadialGradient"||_.type==="Linear"||_.type==="Radial"){const T="exode-fill",G=this.normalizeOpacity(_.opacity??100),ut=(_.stops||[]).map(F=>{const et=F.offset!==void 0?F.offset:F.pos??0,It=this.normalizeOpacity(F.opacity??100)*G;return`<stop offset="${et*100}%" stop-color="${F.color||"#000"}" stop-opacity="${It}"/>`}).join("");let E="";if(_.type==="LinearGradient"||_.type==="Linear"){const F=(Ft,wt)=>Array.isArray(Ft)?Ft[wt]??(wt===0?0:1):Ft&&typeof Ft=="object"?Ft[wt===0?"x":"y"]??(wt===0?0:1):wt===0?0:1,et=F(_.start,0)*100,It=F(_.start,1)*100,Ot=F(_.end,0)*100,St=F(_.end,1)*100;E=`<linearGradient id="${T}" x1="${et}%" y1="${It}%" x2="${Ot}%" y2="${St}%" gradientUnits="objectBoundingBox">${ut}</linearGradient>`}else{const F=(St,Ft)=>Array.isArray(St)?St[Ft]??.5:St&&typeof St=="object"?St[Ft===0?"x":"y"]??.5:.5,et=F(_.center,0)*100,It=F(_.center,1)*100,Ot=(_.radius??.5)*100;E=`<radialGradient id="${T}" cx="${et}%" cy="${It}%" r="${Ot}%" gradientUnits="objectBoundingBox">${ut}</radialGradient>`}/<defs>/i.test(C)?C=C.replace(/<defs>/i,`<defs>${E}`):C=C.replace(/<svg([^>]*)>/i,`<svg$1><defs>${E}</defs>`),C=C.replace(/\bfill\s*=\s*["'][^"']*["']/gi,F=>/fill\s*=\s*["']\s*(none|transparent)\s*["']/i.test(F)?F:`fill="url(#${T})"`),C=C.replace(/fill\s*:\s*[^;"')]+/gi,F=>/fill\s*:\s*(none|transparent)/i.test(F)?F:`fill:url(#${T})`)}}const Et=(T,G,ut=1)=>{const E=(T.stops||[]).map(St=>{const Ft=St.offset!==void 0?St.offset:St.pos??0,wt=this.normalizeOpacity(St.opacity??100)*ut;return`<stop offset="${Ft*100}%" stop-color="${St.color||"#000"}" stop-opacity="${wt}"/>`}).join(""),F=(St,Ft,wt=.5)=>Array.isArray(St)?St[Ft]??wt:St&&typeof St=="object"?St[Ft===0?"x":"y"]??wt:wt;if(T.type==="LinearGradient"||T.type==="Linear"){const St=F(T.start,0,0)*100,Ft=F(T.start,1,0)*100,wt=F(T.end,0,1)*100,Xt=F(T.end,1,1)*100;return`<linearGradient id="${G}" x1="${St}%" y1="${Ft}%" x2="${wt}%" y2="${Xt}%" gradientUnits="objectBoundingBox">${E}</linearGradient>`}const et=F(T.center,0,.5)*100,It=F(T.center,1,.5)*100,Ot=(T.radius??.5)*100;return`<radialGradient id="${G}" cx="${et}%" cy="${It}%" r="${Ot}%" gradientUnits="objectBoundingBox">${E}</radialGradient>`},Gt=(T,G)=>/<defs>/i.test(T)?T.replace(/<defs>/i,`<defs>${G}`):T.replace(/(<svg[^>]*>)/i,`$1<defs>${G}</defs>`);if(I&&I.isEnabled!==!1&&(I.width||0)>0){const T=I.width||1,G=Z?1:this.normalizeOpacity(I.opacity??100),ut=Z?"#FFFFFF":I.color||(_==null?void 0:_.color)||"#000000";let E="";const F=I.fill;if(F&&F.type){if(F.type==="Solid")E=F.color||I.color||"#000000";else if(F.type==="LinearGradient"||F.type==="RadialGradient"||F.type==="Linear"||F.type==="Radial"){const wt="exode-stroke";C=Gt(C,Et(F,wt,G)),E=`url(#${wt})`}}E||(E=ut),C.match(/\bstroke\s*=\s*["']/i)?C=C.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,wt=>/stroke\s*=\s*["']\s*(none|transparent)\s*["']/i.test(wt)?wt:`stroke="${E}"`):C=C.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke="${E}"`),C=C.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),`stroke:${E}`),C.match(/\bstroke-width\s*=\s*["']/i)?C=C.replace(/\bstroke-width\s*=\s*["'][^"']*["']/gi,`stroke-width="${T}"`):C=C.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-width="${T}"`),C=C.replace(/stroke-width\s*:\s*[^;"')]+/gi,`stroke-width:${T}`),C.match(/\bstroke-opacity\s*=\s*["']/i)?C=C.replace(/\bstroke-opacity\s*=\s*["'][^"']*["']/gi,`stroke-opacity="${G}"`):C=C.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-opacity="${G}"`),C=C.replace(/stroke-opacity\s*:\s*[^;"')]+/gi,`stroke-opacity:${G}`),I.lineCap&&(C=C.replace(/\bstroke-linecap\s*=\s*["'][^"']*["']/gi,`stroke-linecap="${I.lineCap}"`),C=C.replace(/stroke-linecap\s*:\s*[^;"')]+/gi,`stroke-linecap:${I.lineCap}`)),I.lineJoin&&(C=C.replace(/\bstroke-linejoin\s*=\s*["'][^"']*["']/gi,`stroke-linejoin="${I.lineJoin}"`),C=C.replace(/stroke-linejoin\s*:\s*[^;"')]+/gi,`stroke-linejoin:${I.lineJoin}`));const et=I.trimStart??0,It=I.trimEnd??1,Ot=I.trimOffset??0,St=I.dashOffset??0,Ft=et!==0||It!==1||Ot!==0||St!==0;if(Ft){const wt=Math.max(0,Math.min(1,et)),Xt=Math.max(0,Math.min(1,It));this.frameCount%600===0&&this.debugLog(`SVG Trim - Object: ${s.name||s.id}, Start: ${wt}, End: ${Xt}`);let Jt=i.width||a||100,Qt=i.height||r||100;const U=st.match(/viewBox=["']\s*0\s+0\s+([\d.]+)\s+([\d.]+)\s*["']/i);if(U){const Ut=parseFloat(U[1]),qt=parseFloat(U[2]);!isNaN(Ut)&&!isNaN(qt)&&(Jt=Ut,Qt=qt)}const X=(Jt+Qt)*2,q=(Ot%1+1)%1,Ct=(St%1+1)%1;let $t="",Ht=0;if(wt>=Xt)$t=`0 ${X}`,Ht=0;else{const Ut=X*(Xt-wt),qt=X-Ut;Ht=-(X*(wt+q+Ct)),$t=`${Ut} ${qt}`}C.match(/\bstroke-dasharray\s*=/i)?C=C.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${$t}"`):C=C.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dasharray="${$t}"`),C=C.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${$t}`),C.match(/\bstroke-dashoffset\s*=/i)?C=C.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${Ht}"`):C=C.replace(/<(path|circle|rect|ellipse|polygon|polyline)/gi,`<$1 stroke-dashoffset="${Ht}"`),C=C.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${Ht}`)}else if(I.dashArray&&I.dashArray.length>0){const wt=I.dashArray.join(" ");C=C.replace(/\bstroke-dasharray\s*=\s*["'][^"']*["']/gi,`stroke-dasharray="${wt}"`),C=C.replace(/stroke-dasharray\s*:\s*[^;"')]+/gi,`stroke-dasharray:${wt}`),I.dashOffset&&(C=C.replace(/\bstroke-dashoffset\s*=\s*["'][^"']*["']/gi,`stroke-dashoffset="${I.dashOffset}"`),C=C.replace(/stroke-dashoffset\s*:\s*[^;"')]+/gi,`stroke-dashoffset:${I.dashOffset}`))}if(!/\bstroke\s*=\s*["']/i.test(st)&&!new RegExp("(?<![a-z-])stroke\\s*:","i").test(st)){let wt="",Xt="";if(Ft){const X=i.width||a||100,q=i.height||r||100,Ct=(X+q)*2,$t=Math.max(0,Math.min(1,et)),Ht=Math.max(0,Math.min(1,It)),Ut=(Ot%1+1)%1,qt=(St%1+1)%1;if($t>=Ht)wt=` stroke-dasharray="0 ${Ct}"`,Xt=' stroke-dashoffset="0"';else{const Se=Ct*(Ht-$t),rs=Ct-Se,ls=-(Ct*($t+Ut+qt));wt=` stroke-dasharray="${Se} ${rs}"`,Xt=` stroke-dashoffset="${ls}"`}}else(rt=I.dashArray)!=null&&rt.length&&(wt=` stroke-dasharray="${I.dashArray.join(" ")}"`,I.dashOffset&&(Xt=` stroke-dashoffset="${I.dashOffset}"`));const Jt=I.lineCap?` stroke-linecap="${I.lineCap}"`:"",Qt=I.lineJoin?` stroke-linejoin="${I.lineJoin}"`:"",U=`stroke="${E}" stroke-width="${T}" stroke-opacity="${G}"${Jt}${Qt}${wt}${Xt}`;C=C.replace(/(<svg[^>]*>)(\s*(?:<defs>[\s\S]*?<\/defs>)?)/i,(X,q,Ct)=>`${q}${Ct}<g ${U}>`),C=C.replace(/<\/svg>/i,"</g></svg>")}}else I&&I.isEnabled===!1&&(C=C.replace(/\bstroke\s*=\s*["'][^"']*["']/gi,'stroke="none"'),C=C.replace(new RegExp(`(?<![a-z-])stroke\\s*:\\s*(?!none|transparent)[^;"')]+`,"gi"),"stroke:none"));const Rt=new Blob([C],{type:"image/svg+xml"}),dt=URL.createObjectURL(Rt);Pt.onload=()=>{if(URL.revokeObjectURL(dt),this.frameCount%900===0){const T=this.imageCache.get(ht);T&&this.debugLog(`SVG Payload Ready: ${s.name||s.id} (${T.naturalWidth}x${T.naturalHeight})`)}},Pt.onerror=()=>{URL.revokeObjectURL(dt),this.debugLog(`SVG Error: Failed to load payload for ${s.name||s.id}`)},Pt.src=dt,this.imageCache.set(ht,Pt)}let mt=null;if(Pt.complete&&Pt.naturalWidth>0?(mt=Pt,this.lastValidSvgImgMap.set(s.id,Pt)):mt=this.lastValidSvgImgMap.get(s.id)||null,mt&&mt.complete&&mt.naturalWidth>0){const C=Math.max(1,a),Et=Math.max(1,r);if(Z&&(_==null?void 0:_.type)==="Solid"){this.maskBuffer||(this.maskBuffer=document.createElement("canvas"),this.maskCtx=this.maskBuffer.getContext("2d")),this.maskBuffer.width=C,this.maskBuffer.height=Et,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,C,Et),this.maskCtx.drawImage(mt,0,0,C,Et),this.maskCtx.globalCompositeOperation="source-in";const Gt=_.color||"#000000",Rt=this.normalizeOpacity(_.opacity??100);this.maskCtx.fillStyle=Gt,this.maskCtx.globalAlpha=Rt,this.maskCtx.fillRect(0,0,C,Et),t.drawImage(this.maskBuffer,-C/2,-Et/2,C,Et)}else d!==0?(t.save(),this.drawRoundRect(t,-C/2,-Et/2,C,Et,d),t.clip(),t.drawImage(mt,-C/2,-Et/2,C,Et),t.restore()):t.drawImage(mt,-C/2,-Et/2,C,Et)}}}else if(l.type==="LineGraph")this.renderLineGraph(t,l,a,r);else if(s.type==="Shape"){if(this.applyPath(t,l,a,r,d),t.save(),n.blur&&n.blur.amount>0&&(t.filter=`blur(${n.blur.amount}px)`),n.fill){const st=t.globalAlpha;if(((at=n.fill)==null?void 0:at.type)==="Image"&&(n.fill.originalSrc||n.fill.src)){const ct=n.fill.originalSrc||n.fill.src;let _=this.imageCache.get(ct);_||(_=new Image,_.src=ct,this.imageCache.set(ct,_)),_.complete&&_.naturalWidth>0&&(t.save(),this.applyPath(t,l,a,r,d),t.clip(),this.renderFittedImage(t,_,-a/2,-r/2,a,r,n.fill.fillMode),t.restore())}else{const ct=this.createCanvasFill(t,n.fill,a,r);t.fillStyle=ct||(typeof n.fill=="string"?n.fill:n.fill.color||"transparent"),t.globalAlpha=st*this.normalizeOpacity(n.fill.opacity??100),this.applyPath(t,l,a,r,d),t.fill()}t.globalAlpha=st}t.restore(),n.stroke&&n.stroke.width>0&&this.applyStrokeAlignment(t,n,l,a,r,d)}else if(s.type==="Frame"||s.type==="Group"&&!s.isStructuralGroup){const st=e.width??i.width??s.width??a,ct=e.height??i.height??s.height??r,_=d;if(t.save(),t.beginPath(),this.drawRoundRect(t,-st/2,-ct/2,st,ct,_),n.fill&&n.fill.type!=="None"){const I=t.globalAlpha,D=this.createCanvasFill(t,n.fill,st,ct);t.fillStyle=D||n.fill.color||"transparent",t.globalAlpha=I*this.normalizeOpacity(n.fill.opacity??100),t.fill(),t.globalAlpha=I}if(t.restore(),n.stroke&&n.stroke.width>0&&n.stroke.isEnabled!==!1){const I={type:"Rectangle"};this.applyStrokeAlignment(t,n,I,st,ct,_)}}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):this.frameCount%60===0&&console.warn("[Engine] Unhandled object type in renderObject:",s.type,"Geo:",(V=s.geometry)==null?void 0:V.type));if(this.applyArtEffectOverlay(t,s,l,a,r,d),zt&&zt.enabled&&zt.type==="glitch"&&t.restore(),Vt&&Vt.enabled&&t.restore(),s.children&&s.children.length>0){const ct=s.type==="Frame",_=s.clipsContent!==void 0?s.clipsContent:s.clipContent!==void 0?s.clipContent:ct;if(t.save(),_){t.beginPath();const D=e.width??(i==null?void 0:i.width)??s.width??0,Z=e.height??(i==null?void 0:i.height)??s.height??0,bt=e.cornerRadius??(i==null?void 0:i.corner_radius)??s.cornerRadius??0;this.drawRoundRect(t,-D/2,-Z/2,D,Z,bt),t.clip()}let I=0;for(s.children.forEach(D=>{const Z=o.get(D);if(!Z)return;const bt=this.objectStates.get(D),Mt=(bt==null?void 0:bt.geometry)||Z.geometry;if(Mt&&Mt.isMask&&(bt==null?void 0:bt.visible)!==!1){const ht=Mt.width||0,Pt=Mt.height||0;this.applyObjectTransform(t,D);const mt=(bt==null?void 0:bt.corner_radius)??(Mt==null?void 0:Mt.corner_radius)??0;this.applyPath(t,Mt,ht,Pt,mt),t.clip(),I++}else this.renderObject(t,Z,o)});I>0;)t.restore(),I--;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(I=>I.isVisible!==!1&&o.has(I.maskId)).forEach(I=>{var mt,C,Et,Gt,Rt,dt;const D=o.get(I.maskId),Z=this.objectStates.get(D.id),bt=I.feather||0,Mt=I.inverted===!0,ht=I.opacity!==void 0?typeof I.opacity=="number"?I.opacity:I.opacity/100:1;if((I.type||"alpha")==="luma"){(!this.lumaBuffer||this.lumaBuffer.width!==this.maskBuffer.width||this.lumaBuffer.height!==this.maskBuffer.height)&&(this.lumaBuffer=document.createElement("canvas"),this.lumaBuffer.width=this.maskBuffer.width,this.lumaBuffer.height=this.maskBuffer.height,this.lumaCtx=this.lumaBuffer.getContext("2d",{willReadFrequently:!0}),this.lumaCtx&&(this.lumaCtx.imageSmoothingEnabled=!0,this.lumaCtx.imageSmoothingQuality="high")),this.lumaCtx.setTransform(1,0,0,1,0,0),this.lumaCtx.globalCompositeOperation="source-over",this.lumaCtx.globalAlpha=1,this.lumaCtx.filter="none",this.lumaCtx.clearRect(0,0,this.lumaBuffer.width,this.lumaBuffer.height),this.lumaCtx.save(),this.rootTransform&&this.lumaCtx.setTransform(this.rootTransform),this.applyAbsoluteTransform(this.lumaCtx,D.id,o),bt>0&&(this.lumaCtx.filter=`blur(${bt}px)`),this.lumaCtx.globalAlpha=ht;const T=(Z==null?void 0:Z.width)||D.geometry.width||0,G=(Z==null?void 0:Z.height)||D.geometry.height||0,ut=(Z==null?void 0:Z.corner_radius)??D.corner_radius??0;if(((mt=D.geometry)==null?void 0:mt.type)==="Text"){const It=Z!=null&&Z.geometry?this.deepMerge(D.geometry,Z.geometry):D.geometry,Ot=Z!=null&&Z.style?this.deepMerge(D.style,Z.style):D.style;this._renderText(this.lumaCtx,D,{...It,width:T,height:G,corner_radius:ut},Ot,Z,T,G,!0)}else if(((C=D.geometry)==null?void 0:C.type)==="Image"){const It=D.geometry.src;if(It){let Ot=this.imageCache.get(It);Ot||(Ot=new Image,Ot.src=It,this.imageCache.set(It,Ot)),Ot.complete&&Ot.naturalWidth>0?this.lumaCtx.drawImage(Ot,-T/2,-G/2,T,G):(this.applyPath(this.lumaCtx,D.geometry,T,G,ut),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else if(((Et=D.geometry)==null?void 0:Et.type)==="SVG"){const It=D.geometry.svgContent;if(It){const Ot=`__lumamask_${D.id}`;let St=this.imageCache.get(Ot);if(!St){St=new Image;const Ft=new Blob([It],{type:"image/svg+xml"});St.src=URL.createObjectURL(Ft),St.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(Ot,St)}St.complete&&St.naturalWidth>0?this.lumaCtx.drawImage(St,-T/2,-G/2,T,G):(this.applyPath(this.lumaCtx,D.geometry,T,G,ut),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill())}}else this.applyPath(this.lumaCtx,D.geometry,T,G,ut),this.lumaCtx.fillStyle="#ffffff",this.lumaCtx.fill();this.lumaCtx.restore();const E=this.maskCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight),F=this.lumaCtx.getImageData(0,0,this.canvasWidth,this.canvasHeight).data,et=E.data;for(let It=0;It<et.length;It+=4){const Ot=F[It],St=F[It+1],Ft=F[It+2];let wt=(.299*Ot+.587*St+.114*Ft)/255;Mt&&(wt=1-wt),et[It+3]*=wt}this.maskCtx.putImageData(E,0,0)}else{this.maskCtx.save(),this.rootTransform&&this.maskCtx.setTransform(this.rootTransform),this.maskCtx.globalCompositeOperation=Mt?"destination-out":"destination-in",bt>0&&(this.maskCtx.filter=`blur(${bt}px)`),this.maskCtx.globalAlpha=ht,this.applyAbsoluteTransform(this.maskCtx,D.id,o);const T=(Z==null?void 0:Z.width)||D.geometry.width||0,G=(Z==null?void 0:Z.height)||D.geometry.height||0,ut=(Z==null?void 0:Z.corner_radius)??D.corner_radius??0;if(((Gt=D.geometry)==null?void 0:Gt.type)==="Text"){const E=Z!=null&&Z.geometry?this.deepMerge(D.geometry,Z.geometry):D.geometry,F=Z!=null&&Z.style?this.deepMerge(D.style,Z.style):D.style;this._renderText(this.maskCtx,D,{...E,width:T,height:G,corner_radius:ut},F,Z,T,G,!0)}else if(((Rt=D.geometry)==null?void 0:Rt.type)==="Image"){const E=D.geometry.src;if(E){let F=this.imageCache.get(E);F||(F=new Image,F.src=E,this.imageCache.set(E,F)),F.complete&&F.naturalWidth>0?this.maskCtx.drawImage(F,-T/2,-G/2,T,G):(this.applyPath(this.maskCtx,D.geometry,T,G,ut),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else if(((dt=D.geometry)==null?void 0:dt.type)==="SVG"){const E=D.geometry.svgContent;if(E){const F=`__alphamask_${D.id}`;let et=this.imageCache.get(F);if(!et){et=new Image;const It=new Blob([E],{type:"image/svg+xml"});et.src=URL.createObjectURL(It),et.onload=()=>{this.artboard&&this.reset()},this.imageCache.set(F,et)}et.complete&&et.naturalWidth>0?this.maskCtx.drawImage(et,-T/2,-G/2,T,G):(this.applyPath(this.maskCtx,D.geometry,T,G,ut),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill())}}else this.applyPath(this.maskCtx,D.geometry,T,G,ut),this.maskCtx.fillStyle="#ffffff",this.maskCtx.fill();this.maskCtx.restore()}}),yt.save(),yt.setTransform(1,0,0,1,0,0);const _=s.maskBlendMode||s.blendMode;_&&_!=="Normal"&&(yt.globalCompositeOperation=_.toLowerCase()),yt.drawImage(this.maskBuffer,0,0),yt.restore(),yt.restore()}else t.restore()}}_renderText(t,s,o,e,i,n,a,r=!1,c=!1){var Y,H,it,nt,ft;let d=o.text||"";if(o.textInputId&&!r){const M=this.inputs.get(o.textInputId);M!==void 0&&(d=String(M),i.geometry&&i.geometry.type==="Text"&&(i.geometry.text=d))}if(o.svgPath){const M=o.svgPath;t.save();const Q=((Y=e==null?void 0:e.fill)==null?void 0:Y.color)||"#000000",N=((H=e==null?void 0:e.fill)==null?void 0:H.opacity)!==void 0?(it=e==null?void 0:e.fill)==null?void 0:it.opacity:1;t.fillStyle=Q,t.globalAlpha*=N;const L=new Path2D(M);t.fill(L),t.restore();return}let l=d||"";o.enableSegments===!0&&o.segments&&Array.isArray(o.segments)&&(l=o.segments.map(M=>M&&M.text?M.text:"").join(""));const f=o.textCase||"none";f==="uppercase"?l=l.toUpperCase():f==="lowercase"?l=l.toLowerCase():f==="capitalize"&&(l=l.replace(/\b\w/g,M=>M.toUpperCase()));let g=((nt=o.fontWeight)==null?void 0:nt.toString())||"400",u=o.fontStyle||"normal";g.toLowerCase().includes("italic")&&(u="italic",g=g.replace(/italic/gi,"").trim()||"400");const p=this.mapFontWeight(g),m=Math.max(1,o.fontSize||32);let y=o.fontFamily||"Inter";const S=["Bold","SemiBold","Medium","Regular","Light","Thin","ExtraBold","Black","Italic"];S.forEach(M=>{const Q=new RegExp(`[\\s-]${M}$`,"i");Q.test(y)&&(y=y.replace(Q,"").trim())});const b=`${u} ${p} ${m}px "${y}", sans-serif`;t.font=b;const v=o.textVerticalAlign||"top";t.textBaseline="top";const w=o.textAlign||"left";t.textAlign=w;let k=0;if(typeof o.letterSpacing=="number")k=o.letterSpacing;else if(typeof o.letterSpacing=="object"&&o.letterSpacing.value!==void 0){const M=o.letterSpacing;k=M.unit==="PERCENT"?M.value/100*m:M.value}t.letterSpacing!==void 0&&(t.letterSpacing=`${k}px`);const A=o.paragraphSpacing||0;let x=o.lineHeight??1.2;typeof x=="string"&&(x=parseFloat(x)),x>5&&m>0&&(x=x/m);const B=(x||1.2)*m,$=o.width&&o.width>0?Math.ceil(o.width):1e5,K=ae({text:l,fontFamily:y,fontSize:m,fontWeight:p,fontStyle:u,lineHeight:x,width:$,letterSpacing:k,paragraphSpacing:A,segments:o.segments,enableSegments:o.enableSegments,textCase:f}),tt=K.lines||[],rt=K.maxFontSize||m,at=this.fontLeadingFactors[y]??.5,V=(B-m)*at;let O=K.height,R=-O/2;a>0&&a>O&&(v==="top"?R=-a/2:v==="middle"||v==="center"?R=-O/2:v==="bottom"&&(R=a/2-O)),R+=V;let P=null,J=0;if(o.pathId&&this.artboard){const M=this.artboard.objects.find(Q=>Q.id===o.pathId);if(M&&M.type==="Shape"&&((ft=M.geometry)==null?void 0:ft.type)==="Path"){const Q=this.objectStates.get(M.id),N=Q!=null&&Q.geometry?this.deepMerge(M.geometry,Q.geometry):M.geometry,L=(Q==null?void 0:Q.scale_x)!==void 0?(M.width||0)*Q.scale_x:M.width||0,z=(Q==null?void 0:Q.scale_y)!==void 0?(M.height||0)*Q.scale_y:M.height||0;P={geo:N,obj:M,w:L,h:z},J=this.getPerimeter(N,L,z)}}const j=(M,Q)=>{var L,z;if(k===0&&(!o.enableSegments||!((L=o.segments)!=null&&L.length)))return t.measureText(M).width;let N=0;for(let pt=0;pt<M.length;pt++){const vt=Q+pt;let yt=0;if(o.enableSegments===!0&&((z=o.segments)==null?void 0:z.length)>0){let _t=0,kt=null;for(const Tt of o.segments){if(vt<_t+(Tt.text||"").length){kt=Tt;break}_t+=(Tt.text||"").length}if(kt){t.save();let Tt=kt.fontFamily||o.fontFamily||"Inter";const Wt=this.mapFontWeight((kt.fontWeight||o.fontWeight||"400").toString()),Yt=kt.fontStyle||u,Dt=kt.fontSize||m;t.font=`${Yt} ${Wt} ${Dt}px "${Tt}", sans-serif`,yt=t.measureText(M[pt]).width,t.restore()}else yt=t.measureText(M[pt]).width}else yt=t.measureText(M[pt]).width;N+=yt+k}return N-(M.length>0?k:0)},lt=(M,Q,N,L,z)=>{var kt,Tt;const vt=(z===0||l[z-1]===`
|
|
23
|
+
`||l[z-1]==="\r")&&o.paragraphIndent?o.paragraphIndent:0,yt=(!r||c)&&(s.behaviors||[]).some(Wt=>Wt.enabled&&(Wt.type.toString().includes("Text")||["Typewriter","Scramble","Wave","Bounce","GlitchText","Reveal3D","RevealSlide","RevealBlur"].includes(Wt.type)));if(!o.pathId&&!yt&&(o.enableSegments!==!0||!o.segments||o.segments.length===0))t.font=b,L?t.strokeText(M,Q+vt,N):t.fillText(M,Q+vt,N);else{const Wt=j(M,z);let Yt=Q+vt;w==="center"?Yt-=Wt/2:w==="right"&&(Yt-=Wt);let Dt=o.pathOffset||0;o.pathId&&J>0&&P&&(w==="center"?Dt+=J/2-Wt/2:w==="right"&&(Dt+=J-Wt));let Vt=Yt;const zt=r&&!c?[]:((kt=s.behaviors)==null?void 0:kt.filter(st=>[W.Typewriter,W.Scramble,W.Wave,W.Bounce,W.GlitchText,W.TextTrail,W.Reveal3D,W.RevealSlide,W.RevealBlur,W.TextLiquid,W.TextVortex,W.TextExplosion,W.TextRain,W.TextGravity,W.TextElastic,W.TextMatrix,W.TextNeon,W.TextGlitch3D,W.TextDissolve,W.TextOrganic,W.TextBreathe,W.TextFloral,W.TextSmoke,W.TextVariable,W.TextMagnet,W.TextSpin,W.TextZing,W.TextPerspective,W.TextMirror].includes(st.type)&&st.enabled))||[];for(let st=0;st<M.length;st++){let ct=M[st];const _=z+st;let I=0,D=0,Z=1,bt=1,Mt=0,ht=1,Pt=ct;zt.forEach(dt=>{const T=dt.settings||{},G=T.strength||1,ut=Date.now();if(dt.type===W.Typewriter)this.currentTime*(T.speed||1)-_*(T.stagger||.05)<0&&(ht=0);else if(dt.type===W.Scramble)Math.max(0,Math.min(1,this.currentTime/(T.duration||1.5))-_*.02)<1&&Math.random()<.3&&(Pt="$%#@!*&"[Math.floor(Math.random()*7)]);else if(dt.type===W.Wave)D+=Math.sin(this.currentTime*5*(T.speed||1)+_*(T.frequency||1))*(T.amplitude||20)*G;else if(dt.type===W.Bounce){const E=Math.max(0,this.currentTime%2-_*(T.stagger||.1));E<1&&(D-=Math.abs(Math.sin(E*Math.PI))*(T.height||50)*G)}else if(dt.type===W.TextTrail){const E=this.pointerHistory[Math.max(0,this.pointerHistory.length-1-_*(T.delay||5))];E&&(I+=(E.x-(i.x+Vt))*G*.2,D+=(E.y-(i.y+N+D))*G*.2)}else if(dt.type===W.Reveal3D){const E=Math.max(0,Math.min(1,this.currentTime*(T.speed||1)-_*(T.stagger||.1)));Z*=E,bt*=E,ht=E}else if(dt.type===W.RevealSlide){const E=Math.max(0,Math.min(1,this.currentTime*1.5-_*.05)),F=(1-E)*(T.distance||40)*G,et=T.direction||"up";et==="up"?D-=F:et==="down"?D+=F:et==="left"?I-=F:et==="right"&&(I+=F),ht=E}else if(dt.type===W.RevealBlur){const E=Math.max(0,Math.min(1,this.currentTime*1.2-_*.1));ht=E,I+=(1-E)*5}else if(dt.type===W.TextLiquid){const E=Math.max(0,Math.sin(ut*.001*(T.speed||1)+_*.5));D+=E*(T.amplitude||10)*G,bt*=1+E*.2}else if(dt.type===W.TextVortex){const E=ut*.002*(T.speed||1)+_*.2,F=(1-(Math.sin(ut*.001)*.5+.5))*(T.radius||50);I+=Math.cos(E)*F*G,D+=Math.sin(E)*F*G}else if(dt.type===W.TextExplosion){const E=T.force||1,F=this.currentTime%2;if(F<1){const et=(_/M.length-.5)*Math.PI*2,It=F*100*E;I+=Math.cos(et)*It*G,D+=Math.sin(et)*It*G,ht=1-F}}else if(dt.type===W.TextRain){const E=T.speed||1,F=T.height||100,et=(ut*.001*E+_*.1)%1;D-=(1-et)*F*G,ht=et>.1?1:et*10}else if(dt.type===W.TextGravity){const E=T.gravity||9.8,F=this.currentTime%3/3,et=.5*E*Math.pow(F*10,2);et<100?D+=et*G:D+=100*G}else if(dt.type===W.TextMatrix){const E=T.speed||1;if(Math.random()<.1*E){const et="0123456789ABCDEF!@#$%^&*";Pt=et[Math.floor(Math.random()*et.length)]}ht=.3+(Math.sin(ut*.01*E+_)+1)/2*.7}else if(dt.type===W.TextNeon){const E=Math.random()>.95?.5:1;ht=(.7+(Math.sin(ut*.005)+1)/2*.3)*E}else if(dt.type===W.TextDissolve)Math.sin(_*1.5+ut*.002*(T.speed||1))>.5&&(ht=0);else if(dt.type===W.TextOrganic){const E=T.speed||1,F=T.amplitude||10;I+=Math.sin(ut*.002*E+_)*F*G,D+=Math.cos(ut*.0015*E+_*.7)*F*G}else if(dt.type===W.TextBreathe){const F=1+(Math.sin(ut*.003+_*.2)+1)/2*.2*G;Z*=F,bt*=F}else if(dt.type===W.TextSpin){const E=T.speed||1;Mt+=ut*.01*E+_}else if(dt.type===W.TextMagnet){const E=this.pointerHistory[this.pointerHistory.length-1];if(E){const F=E.x-(i.x+Vt),et=E.y-(i.y+N);Mt=Math.atan2(et,F)}}else if(dt.type===W.TextPerspective){const E=M.length/2,F=(_-E)/E,et=1-Math.abs(F)*.3*G;Z*=et,bt*=et,I+=F*20*G}else if(dt.type===W.TextMirror)ht*=.8;else if(dt.type===W.TextFloral){const E=T.speed||1,F=T.stagger||.1,et=(ut*.001*E+_*F)%2;et<1&&(Z*=et,bt*=et,Mt+=et*Math.PI)}else if(dt.type===W.TextSmoke){const E=T.speed||1,F=T.height||50,et=(ut*5e-4*E+_*.2)%1;D-=et*F*G,I+=Math.sin(ut*.002+_)*5*G,ht=1-et}else if(dt.type===W.TextVariable){const E=T.speed||1,F=T.intensity||1.5,et=(Math.sin(ut*.004*E+_*.3)+1)/2;Z*=1+et*(F-1)*G}else if(dt.type===W.TextZing){const E=T.speed||2,F=T.distance||100,et=(ut*.002*E+_*.05)%1;I+=(1-et)*F*G,ht=et}else if(dt.type===W.TextElastic){const E=T.stiffness||.2,F=T.damping||.1,et=Math.sin(ut*.01)*Math.exp(-ut*.001*F);bt*=1+et*E*G}else if(dt.type===W.TextGlitch3D){const E=T.intensity||5;Math.random()<.2&&(I+=(Math.random()-.5)*E,D+=(Math.random()-.5)*E,ht=.8)}else if(dt.type===W.GlitchText){const E=T.intensity||5;Math.random()<.1&&(I+=(Math.random()-.5)*E,D+=(Math.random()-.5)*E,Math.random()<.05&&(ht=.5))}});let mt=null,C=o.textDecoration||"none",Et=m;if(o.enableSegments===!0&&((Tt=o.segments)==null?void 0:Tt.length)>0){let dt=0,T=null;for(const G of o.segments){if(_<dt+(G.text||"").length){T=G;break}dt+=(G.text||"").length}if(T){let G=T.fontFamily||o.fontFamily||"Inter";S.forEach(F=>{const et=new RegExp(`[\\s-]${F}$`,"i");et.test(G)&&(G=G.replace(et,"").trim())});const ut=this.mapFontWeight((T.fontWeight||o.fontWeight||"400").toString()),E=T.fontStyle||u;Et=T.fontSize||m,t.font=`${E} ${ut} ${Et}px "${G}", sans-serif`,T.fill&&(mt=T.fill),T.textDecoration&&(C=T.textDecoration),Et<rt&&(D+=(rt-Et)*.85)}}else t.font=b;const Gt=t.globalAlpha;t.globalAlpha*=ht,t.save();const Rt=t.measureText(Pt).width;if(P&&J>0){const dt=Vt-Yt+Rt/2,G=(Dt+dt)/J,ut=this.getPointOnPath(P.geo,P.w,P.h,Math.abs(G%1)),E=ut.angle,F=N+D+(o.pathOffsetY||0),et=o.pathSide==="right"?-1:1,It=Math.cos(E+Math.PI/2)*F*et,Ot=Math.sin(E+Math.PI/2)*F*et;t.translate(ut.x+It+I,ut.y+Ot),t.rotate(E+Mt+(et===-1?Math.PI:0))}else t.translate(Vt+I+Rt/2,N+D),Mt!==0&&t.rotate(Mt);if(t.scale(Z,bt),mt&&!r&&!c){const dt=this.createCanvasFill(t,mt,n,a);t.fillStyle=dt||mt.color||"#000000"}else if(!r&&!c){const dt=this.createCanvasFill(t,e.fill,n,a);t.fillStyle=dt||e.fill.color||"#000000"}if(ht>0)if(r||c){const dt=c?"#000000":this.createCanvasFill(t,e.fill,n,a);t.fillStyle=dt||e.fill.color||"#ffffff",t.fillText(Pt,-Rt/2,0)}else L?t.strokeText(Pt,-Rt/2,0):t.fillText(Pt,-Rt/2,0);C!=="none"&&!r&&this.drawTextDecoration(t,C,0,0,Rt,Et),t.restore(),t.globalAlpha=Gt,Vt+=Rt+k}}};if(r){let M=0,Q=R;(tt||[]).forEach(N=>{const L=N.text||"",z=l.indexOf(L,M);z!==-1&&(M=z);let pt=-n/2;w==="center"?pt=0:w==="right"&&(pt=n/2),lt(L,pt,Q,!1,M),M+=L.length,Q+=B})}else if(c){let M=0,Q=R;(tt||[]).forEach(N=>{const L=N.text||"";let z=-n/2;w==="center"?z=0:w==="right"&&(z=n/2),lt(L,z,Q,!1,M),M+=L.length,M<l.length&&(l[M]===`
|
|
24
24
|
`||l[M]==="\r")&&(M++,l[M-1]==="\r"&&l[M]===`
|
|
25
|
-
`&&M++),Q+=B})}else{if(e.fill){const M=t.globalAlpha,Q=this.createCanvasFill(t,e.fill,n,a);t.fillStyle=Q||e.fill.color||"#000000",t.globalAlpha=M*this.normalizeOpacity(e.fill.opacity??100);const
|
|
26
|
-
`||
|
|
27
|
-
`&&L++)}),t.globalAlpha=M}if(e.stroke&&e.stroke.width>0){const M=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=M*this.normalizeOpacity(e.stroke.opacity??100);let
|
|
28
|
-
`||l[
|
|
29
|
-
`&&Y++)}),t.globalAlpha=M}}}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,c=(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 l=t.globalAlpha;t.globalAlpha=l*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 f=a.trimStart??0,g=a.trimEnd??1,d=a.trimOffset??0,u=a.dashOffset??0,m=a.dashArray||[];if(f!==0||g!==1||d!==0){const y=this.getPerimeter(o,e,i);if(y>0){const S=Math.max(0,Math.min(1,f)),b=Math.max(0,Math.min(1,g));if(S<b){const v=y*(b-S),C=y-v,k=-(y*(S+d%1));t.setLineDash([v,C]),t.lineDashOffset=k+u*y}else if(S===b)t.setLineDash([0,y]);else{const v=y*(1-S+b),C=y-v,k=-(y*S);t.setLineDash([v,C]),t.lineDashOffset=k+u*y}}}else m.length>0&&(t.setLineDash(m),t.lineDashOffset=u);(o==null?void 0:o.type)==="Line"||e===0||i===0?(this.applyPath(t,o,e,i,n),t.stroke()):c==="inside"?(t.lineWidth=r*2,t.save(),this.applyPath(t,o,e,i,n),t.clip(),t.stroke(),t.restore()):c==="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 c=n/360*r;if(a>0){const p=Math.PI*(3*(e*a+i*a)-Math.sqrt((3*e*a+i*a)*(e*a+3*i*a)));c+=n/360*p,n<360&&(c+=2*Math.sqrt((e-e*a)**2+(i-i*a)**2))}else n<360&&(c+=2*Math.max(e,i));return isNaN(c)?0:c}case"Line":return t.length||Math.sqrt(s*s+o*o);case"Triangle":return s+Math.sqrt((s/2)**2+o**2)*2;case"Polygon":{const e=t.sides||3,i=t.radius||Math.min(s,o)/2;return 2*e*i*Math.sin(Math.PI/e)}case"Star":{const e=t.points||5,i=t.outer_radius||Math.min(s,o)/2,n=t.inner_radius||i/2,a=Math.PI/e;return Math.sqrt(i*i+n*n-2*i*n*Math.cos(a))*e*2}case"Path":{const e=t.points||[];if(e.length<2)return t.length||0;let i=0,n=e[0].x,a=e[0].y;for(let r=1;r<e.length;r++){const c=e[r];if(c.moveTo){n=c.x,a=c.y;continue}const p=n,l=a,f=e[r-1].out_x,g=e[r-1].out_y;if(f!==void 0||c.in_x!==void 0?i+=this.getBezierLength(p,l,f??p,g??l,c.in_x??c.x,c.in_y??c.y,c.x,c.y):i+=Math.sqrt((c.x-p)**2+(c.y-l)**2),n=c.x,a=c.y,c.closePath||r===e.length-1&&(t.is_closed||t.isClosed)){const d=n,u=a,m=[...e.slice(0,r+1)].reverse().find(A=>A.moveTo)||e[0],y=m.x,S=m.y,b=e[r].out_x,v=e[r].out_y,C=m.in_x,k=m.in_y;b!==void 0||C!==void 0?i+=this.getBezierLength(d,u,b??d,v??u,C??y,k??S,y,S):i+=Math.sqrt((y-d)**2+(S-u)**2)}}return i}default:return(s+o)*2}}getBezierLength(t,s,o,e,i,n,a,r,c=10){let p=0,l=t,f=s;for(let g=1;g<=c;g++){const d=g/c,u=1-d,m=d*d,y=u*u,S=y*u,b=m*d,v=S*t+3*y*d*o+3*u*m*i+b*a,C=S*s+3*y*d*e+3*u*m*n+b*r,k=v-l,A=C-f;p+=Math.sqrt(k*k+A*A),l=v,f=C}return p}getBezierTAtLength(t,s,o,e,i,n,a,r,c,p=20){if(t<=0)return 0;let l=0,f=s,g=o;for(let d=1;d<=p;d++){const u=d/p,m=1-u,y=u*u,S=m*m,b=S*m,v=y*u,C=b*s+3*S*u*e+3*m*y*n+v*r,k=b*o+3*S*u*i+3*m*y*a+v*c,A=C-f,x=k-g,B=Math.sqrt(A*A+x*x);if(l+B>=t){const R=t-l,K=B===0?0:R/B;return(d-1+K)/p}l+=B,f=C,g=k}return 1}getPointOnPath(t,s,o,e){if(this.ensurePathPoints(t),(t==null?void 0:t.type)==="Path"){const i=t.points||[];if(i.length<2)return{x:0,y:0,angle:0};let n=1/0,a=-1/0,r=1/0,c=-1/0;i.forEach(S=>{typeof S.x=="number"&&typeof S.y=="number"&&(n=Math.min(n,S.x),a=Math.max(a,S.x),r=Math.min(r,S.y),c=Math.max(c,S.y),S.out_x!==void 0&&(n=Math.min(n,S.out_x),a=Math.max(a,S.out_x)),S.out_y!==void 0&&(r=Math.min(r,S.out_y),c=Math.max(c,S.out_y)),S.in_x!==void 0&&(n=Math.min(n,S.in_x),a=Math.max(a,S.in_x)),S.in_y!==void 0&&(r=Math.min(r,S.in_y),c=Math.max(c,S.in_y)))});const p=(n+a)/2,l=(r+c)/2,g=this.getPerimeter(t,s,o)*e;let d=0;const u=[];let m=i[0],y=i[0];for(let S=1;S<i.length;S++){const b=i[S];if(b.moveTo){m=b,y=b;continue}u.push({p0:m,p1:b}),(b.closePath||S===i.length-1&&(t.is_closed||t.isClosed))&&u.push({p0:b,p1:y}),m=b}for(const S of u){const b=S.p0,v=S.p1;let C=0;const k=b.out_x!==void 0||v.in_x!==void 0;if(k?C=this.getBezierLength(b.x,b.y,b.out_x??b.x,b.out_y??b.y,v.in_x??v.x,v.in_y??v.y,v.x,v.y):C=Math.sqrt((v.x-b.x)**2+(v.y-b.y)**2),d+C>=g||S===u[u.length-1]){let A=0;if(k)return A=this.getBezierTAtLength(g-d,b.x,b.y,b.out_x??b.x,b.out_y??b.y,v.in_x??v.x,v.in_y??v.y,v.x,v.y,20),this.getBezierPointAndAngle(A,b,v,p,l);{A=C===0?0:(g-d)/C;const x=b.x+(v.x-b.x)*A-p,B=b.y+(v.y-b.y)*A-l,R=Math.atan2(v.y-b.y,v.x-b.x);return{x,y:B,angle:R}}}d+=C}}else if(t.type==="Ellipse"){const i=Math.abs(s)/2,n=Math.abs(o)/2,a=t.sweepAngle??360,c=((t.startAngle??0)+a*e)*Math.PI/180,p=i*Math.cos(c),l=n*Math.sin(c),f=-i*Math.sin(c),g=n*Math.cos(c),d=Math.atan2(g,f);return{x:p,y:l,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 c=0,p=0,l=0;return r<i?(c=-i/2+r,p=-n/2,l=0):r<i+n?(c=i/2,p=-n/2+(r-i),l=Math.PI/2):r<2*i+n?(c=i/2-(r-(i+n)),p=n/2,l=Math.PI):(c=-i/2,p=n/2-(r-(2*i+n)),l=-Math.PI/2),{x:c,y:p,angle:l}}return{x:0,y:0,angle:0}}getBezierPointAndAngle(t,s,o,e,i){const n=s.x,a=s.y,r=s.out_x??s.x,c=s.out_y??s.y,p=o.in_x??o.x,l=o.in_y??o.y,f=o.x,g=o.y,d=1-t,u=t*t,m=d*d,y=m*d,S=u*t,b=y*n+3*m*t*r+3*d*u*p+S*f-e,v=y*a+3*m*t*c+3*d*u*l+S*g-i,C=3*m*(r-n)+6*d*t*(p-r)+3*u*(f-p),k=3*m*(c-a)+6*d*t*(l-c)+3*u*(g-l),A=Math.atan2(k,C);return{x:b,y:v,angle:A}}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 l;const a=s.artEffect||((l=s.style)==null?void 0:l.artEffect);if(!a||!a.enabled)return;const r=a.type,c=a.intensity??.5,p=a.speed??1;if(r==="acid_gradient"||r==="acid_rave"||r==="shimmer"||r==="halftone"||r==="noise"||r==="scanlines"||r==="chromatic_aberration"){if(t.save(),this.applyPath(t,o,e,i,n),t.clip(),r==="shimmer"){const g=this.currentTime*p%2/2,d=t.createLinearGradient(-e,-i,e,i);d.addColorStop(Math.max(0,g-.2),"rgba(255,255,255,0)"),d.addColorStop(g,`rgba(255,255,255,${c*.8})`),d.addColorStop(Math.min(1,g+.2),"rgba(255,255,255,0)"),t.fillStyle=d,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i)}else if(r==="acid_gradient"||r==="acid_rave"){const f=this.currentTime*p,g=t.createLinearGradient(-e/2,-i/2,e/2,i/2),d=f*100%360,u=(d+180)%360;g.addColorStop(0,`hsla(${d}, 80%, 50%, ${c*.5})`),g.addColorStop(1,`hsla(${u}, 80%, 50%, ${c*.5})`),t.fillStyle=g,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i)}else if(r==="halftone"){const f=Math.max(2,20*(1-c)),g=document.createElement("canvas");g.width=f,g.height=f;const d=g.getContext("2d");if(d){d.fillStyle="black",d.beginPath(),d.arc(f/2,f/2,f/2*c,0,Math.PI*2),d.fill();const u=t.createPattern(g,"repeat");u&&(t.globalAlpha=.3*c,t.fillStyle=u,t.fillRect(-e/2,-i/2,e,i))}}else if(r==="noise"){t.globalAlpha=.1*c;for(let f=0;f<5;f++)t.fillStyle=`rgba(${Math.random()*255}, ${Math.random()*255}, ${Math.random()*255}, ${c})`,t.fillRect(-e/2+Math.random()*e,-i/2+Math.random()*i,2,2)}else if(r==="scanlines"){t.globalAlpha=.2*c,t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1;for(let f=-i/2;f<i/2;f+=4)t.beginPath(),t.moveTo(-e/2,f),t.lineTo(e/2,f),t.stroke()}else if(r==="chromatic_aberration"){const f=5*c;t.globalCompositeOperation="screen",t.globalAlpha=.5,t.fillStyle="cyan",t.fillRect(-e/2-f,-i/2,e,i),t.fillStyle="magenta",t.fillRect(-e/2+f,-i/2,e,i)}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,c=o/2,p=e/2,l=n*Math.PI/180,f=a*Math.PI/180,g=l+f;a>=360&&r<=0?t.ellipse(0,0,c,p,0,0,Math.PI*2):(t.ellipse(0,0,c,p,0,l,g,!1),r>0?t.ellipse(0,0,c*r,p*r,0,g,l,!0):t.lineTo(0,0),t.closePath())}else if(s.type==="Triangle")t.moveTo(0,-e/2),t.lineTo(o/2,e/2),t.lineTo(-o/2,e/2),t.closePath();else if(s.type==="Polygon"){const n=s.sides||3,a=s.radius||Math.min(o,e)/2;for(let r=0;r<n;r++){const c=r*2*Math.PI/n-Math.PI/2,p=a*Math.cos(c),l=a*Math.sin(c);r===0?t.moveTo(p,l):t.lineTo(p,l)}t.closePath()}else if(s.type==="Star"){const n=s.inner_radius||20,a=s.outer_radius||50,r=s.points||5;for(let c=0;c<r*2;c++){const p=c*Math.PI/r-Math.PI/2,l=c%2===0?a:n,f=l*Math.cos(p),g=l*Math.sin(p);c===0?t.moveTo(f,g):t.lineTo(f,g)}t.closePath()}else if(((s==null?void 0:s.type)==="Path"||s.type==="Subtract"||s.type==="Union"||s.type==="Intersect"||s.type==="Exclude"||s.type==="BooleanOperation")&&s.points){this.frameCount%10===0&&console.log("[Engine] Tracing Path:",s.points.length,"points");let n=1/0,a=-1/0,r=1/0,c=-1/0;if(s.points.forEach(f=>{typeof f.x=="number"&&typeof f.y=="number"&&(n=Math.min(n,f.x),a=Math.max(a,f.x),r=Math.min(r,f.y),c=Math.max(c,f.y),f.out_x!==void 0&&(n=Math.min(n,f.out_x),a=Math.max(a,f.out_x)),f.out_y!==void 0&&(r=Math.min(r,f.out_y),c=Math.max(c,f.out_y)),f.in_x!==void 0&&(n=Math.min(n,f.in_x),a=Math.max(a,f.in_x)),f.in_y!==void 0&&(r=Math.min(r,f.in_y),c=Math.max(c,f.in_y)))}),n===1/0)return;const p=(n+a)/2,l=(r+c)/2;if(isNaN(p)||isNaN(l)){console.warn("[Engine] Invalid path center:",p,l);return}s.points.forEach((f,g)=>{if(g===0||f.moveTo)t.moveTo(f.x-p,f.y-l);else{const d=s.points[g-1];if(!d)return;const u=(d.out_x??d.x)-p,m=(d.out_y??d.y)-l,y=(f.in_x??f.x)-p,S=(f.in_y??f.y)-l;isNaN(u)||isNaN(y)||isNaN(f.x)?t.lineTo(f.x-p,f.y-l):t.bezierCurveTo(u,m,y,S,f.x-p,f.y-l)}if(f.closePath||g===s.points.length-1&&(s.is_closed||s.isClosed)){const d=[...s.points.slice(0,g+1)].reverse().find(u=>u.moveTo)||s.points[0];d&&(f.out_x!==void 0||d.in_x!==void 0)&&t.bezierCurveTo((f.out_x??f.x)-p,(f.out_y??f.y)-l,(d.in_x??d.x)-p,(d.in_y??d.y)-l,d.x-p,d.y-l),t.closePath()}})}else if(s.points&&Array.isArray(s.points)){let n=1/0,a=-1/0,r=1/0,c=-1/0;s.points.forEach(f=>{n=Math.min(n,f.x),a=Math.max(a,f.x),r=Math.min(r,f.y),c=Math.max(c,f.y)});const p=(n+a)/2,l=(r+c)/2;s.points.forEach((f,g)=>{if(g===0)t.moveTo(f.x-p,f.y-l);else{const d=s.points[g-1];d.out_x!==void 0||f.in_x!==void 0?t.bezierCurveTo((d.out_x??d.x)-p,(d.out_y??d.y)-l,(f.in_x??f.x)-p,(f.in_y??f.y)-l,f.x-p,f.y-l):t.lineTo(f.x-p,f.y-l)}(f.closePath||g===s.points.length-1&&(s.is_closed||s.isClosed))&&t.closePath()})}}}renderInputBox(t,s){var M,Q;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((M=s.geometry)==null?void 0:M.width)||250,n=((Q=s.geometry)==null?void 0:Q.height)||45,a=this.focusedId===s.id,r=this.lastHoveredObjectId===s.id,c=e.previewState||"default",p=c!=="default"?c:a?"focused":r?"hovered":"default",l=e.label||{visible:!0,text:"Label"},f=e.helperText||{visible:!1,text:"Helper text"},g=e.leftIcon||{visible:!1},d=e.rightIcon||{visible:!1},u=e.multiline===!0,m=e.corner_radius??8,y=e.corners||{tl:m,tr:m,bl:m,br:m},S=[y.tl,y.tr,y.br,y.bl];let b=e.backgroundColor||"rgba(31, 41, 55, 1)",v=e.borderColor||"rgba(55, 65, 81, 1)",C=e.borderWidth??1.5,k=e.color||"#ffffff",A=e.placeholderColor||"rgba(156, 163, 175, 1)",x=e.fontSize||14;const B=`${p}Style`,R=e[B];R?(R.backgroundColor!==void 0&&(b=R.backgroundColor),R.borderColor!==void 0&&(v=R.borderColor),R.borderWidth!==void 0&&(C=R.borderWidth),R.color!==void 0&&(k=R.color),R.placeholderColor!==void 0&&(A=R.placeholderColor),R.fontSize!==void 0&&(x=R.fontSize)):p==="focused"?(v=e.focusBorderColor||"rgba(59, 130, 246, 1)",C=Math.max(C,2)):p==="hovered"||p==="hover"?(v=e.hoverBorderColor||v,b=e.hoverBackgroundColor||b):p==="disabled"?(b=e.disabledBackgroundColor||"rgba(31, 41, 55, 0.6)",v=e.disabledBorderColor||"rgba(55, 65, 81, 0.4)"):p==="error"&&(v="rgba(239, 68, 68, 1)",C=Math.max(C,2)),t.beginPath(),this.drawRoundRect(t,-i/2,-n/2,i,n,S);const K=this.createCanvasFill(t,b,i,n);if(K&&(t.fillStyle=K,t.fill()),C>0){const Y=this.createCanvasFill(t,v,i,n);if(Y&&(t.strokeStyle=Y,t.lineWidth=C,t.stroke()),p==="focused"||p==="focus"){t.save(),t.beginPath();const L=S.map(z=>z+2);this.drawRoundRect(t,-i/2-2,-n/2-2,i+4,n+4,L),t.strokeStyle="rgba(59, 130, 246, 0.3)",t.lineWidth=2,t.stroke(),t.restore()}}const tt=(Y,L)=>{if(!Y.visible||!Y.svgPath)return;const z=Y.size||14,pt=Y.offset??16,vt=Y.color||"#ffffff",yt=L?-(i/2)+pt:i/2-pt,_t=Y.svgPath;if(t.save(),t.translate(yt,0),!_t.startsWith("<svg")){const kt=new Path2D(_t),Tt=z/24;t.scale(Tt,Tt),t.translate(-12,-12),t.fillStyle=vt,t.fill(kt)}t.restore()};tt(g,!0),tt(d,!1);const rt=e.text||"",at=e.placeholder||"Enter text...",N=!rt,O=rt||at,$=N?A:k,P=x,J=e.fontFamily||"Inter",j=e.fontWeight||400;t.font=`${j} ${P}px "${J}", sans-serif`,t.fillStyle=$,t.textAlign="left",t.textBaseline=u?"top":"middle";const lt=e.inputPadding??16,V=g.visible?(g.offset??16)+(g.size||14)/2+8:lt,H=d.visible?(d.offset??16)+(d.size||14)/2+8:lt,it=-(i/2)+V,nt=i-V-H,ft=e.inputType==="password"?"•".repeat(O.length):O;if(t.save(),t.beginPath(),t.rect(it-2,-n/2+4,nt+4,n-8),t.clip(),u){const Y=ft.split(`
|
|
30
|
-
`);let L=-n/2+lt;const z=P*1.2;let pt=0;Y.forEach((vt,yt)=>{const _t=vt.split(" ");let kt="";for(let Tt=0;Tt<_t.length;Tt++){const Wt=kt+_t[Tt]+" ";t.measureText(Wt).width>nt&&Tt>0?(t.fillText(kt,it,L),kt=_t[Tt]+" ",L+=z):kt=Wt}t.fillText(kt,it,L),pt=t.measureText(kt).width,yt<Y.length-1&&(L+=z,pt=0)}),a&&!N&&Math.floor(performance.now()/500)%2===0&&t.fillRect(it+pt,L,1.5,P)}else{const L=t.measureText(ft).width;let z=0;if(L>nt&&(z=L-nt),t.fillText(ft,it-z,0),a&&!N&&Math.floor(performance.now()/500)%2===0){const vt=it+L-z;t.fillRect(vt,-(P/2),1.5,P)}}if(t.restore(),l.visible!==!1){const Y=l.text||"Label",L=l.fontSize||12,z=l.color||"rgba(156, 163, 175, 1)",pt=l.offset??8;t.font=`600 ${L}px "${J}", sans-serif`,t.fillStyle=z,t.textAlign="left",t.textBaseline="bottom";const vt=-(i/2),yt=-(n/2)-pt;t.fillText(Y,vt,yt)}if(f.visible===!0){const Y=f.text||"Helper text",L=f.fontSize||11,z=p==="error"?"rgba(239, 68, 68, 1)":f.color||"rgba(156, 163, 175, 1)",pt=f.offset??6;t.font=`400 ${L}px "${J}", sans-serif`,t.fillStyle=z,t.textAlign="left",t.textBaseline="top";const vt=-(i/2),yt=n/2+pt;t.fillText(Y,vt,yt)}}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,p=(i.max??100)-r,l=p===0?0:(a-r)/p,f=i.trackHeight||4,g=i.trackRoundedness??2,d=i.trackShape??"Rectangle",u=i.trackPath||"",m=i.accentColor||"#3b82f6",y=i.inactiveColor||"#374151",S=i.thumbShape||"Ellipse",b=i.thumbWidth??16,v=i.thumbHeight??16,C=i.thumbRoundedness??0,k=i.thumbColor||"#ffffff",A=i.thumbPath||"",x=i.thumbIcon||"",B=i.showValueTooltip??!1,R=i.tooltipBgColor||"#333333",K=i.tooltipColor||"#ffffff",tt=i.tooltipOffsetX??0,rt=i.tooltipOffsetY??-25,at=(nt,ft,M,Q,Y,L,z)=>{if((nt==="Custom"||nt==="Icon")&&z)try{const pt=new Path2D(z);if(t.save(),t.translate(ft,M),nt==="Icon"){const vt=Math.min(Q,Y)/24;t.scale(vt,vt),t.translate(-12,-12)}t.fill(pt),t.restore();return}catch(pt){console.error("Error drawing slider shape in engine:",pt)}if(t.beginPath(),nt==="Ellipse")t.ellipse(ft,M,Q/2,Y/2,0,0,Math.PI*2);else if(nt==="Rectangle")this.drawRoundRect(t,ft-Q/2,M-Y/2,Q,Y,L);else if(nt==="Triangle")t.moveTo(ft,M-Y/2),t.lineTo(ft+Q/2,M+Y/2),t.lineTo(ft-Q/2,M+Y/2),t.closePath();else if(nt==="Diamond")t.moveTo(ft,M-Y/2),t.lineTo(ft+Q/2,M),t.lineTo(ft,M+Y/2),t.lineTo(ft-Q/2,M),t.closePath();else if(nt==="Polygon"){const pt=s.geometry.sides||3,vt=s.geometry.radius||Math.min(Q,Y)/2;for(let yt=0;yt<pt;yt++){const _t=yt*2*Math.PI/pt-Math.PI/2,kt=ft+vt*Math.cos(_t),Tt=M+vt*Math.sin(_t);yt===0?t.moveTo(kt,Tt):t.lineTo(kt,Tt)}t.closePath()}else if(nt==="Star"){const vt=Math.min(Q,Y)/2,yt=vt/2;for(let _t=0;_t<5*2;_t++){const kt=_t%2===0?vt:yt,Tt=_t*Math.PI/5-Math.PI/2;t.lineTo(ft+kt*Math.cos(Tt),M+kt*Math.sin(Tt))}t.closePath()}else nt==="Line"&&(t.moveTo(ft-Q/2,M),t.lineTo(ft+Q/2,M));t.fill()},N=this.createCanvasFill(t,y,n,f);N&&(t.fillStyle=N,t.strokeStyle=N),d==="Line"?(t.lineWidth=f,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(n/2,0),t.stroke()):at(d,0,0,n,f,g,u);const O=n-b,$=-n/2+b/2+l*O,P=$- -n/2;if(P>0){const nt=this.createCanvasFill(t,m,n,f);nt&&(t.fillStyle=nt,t.strokeStyle=nt),d==="Line"?(t.lineWidth=f,t.beginPath(),t.moveTo(-n/2,0),t.lineTo($,0),t.stroke()):d==="Rectangle"&&(t.beginPath(),this.drawRoundRect(t,-n/2,-f/2,P,f,g),t.fill())}t.save(),t.translate($,0);const J=t.getTransform(),j=Math.sqrt(J.a*J.a+J.b*J.b)||1;t.shadowColor="rgba(0,0,0,0.2)",t.shadowBlur=4*j,t.shadowOffsetY=1*j;const lt=this.createCanvasFill(t,k,b,v);if(lt&&(t.fillStyle=lt),at(S,0,0,b,v,C,S==="Icon"?x:A),t.restore(),B){t.save(),t.translate($+tt,rt);const nt=Math.round(a).toString();t.font="10px Inter, sans-serif";const ft=t.measureText(nt),M=6,Q=4,Y=ft.width+M*2,L=14+Q;t.beginPath(),this.drawRoundRect(t,-Y/2,-L/2,Y,L,4),t.fillStyle=R,t.fill(),t.fillStyle=K,t.textAlign="center",t.textBaseline="middle",t.fillText(nt,0,0),t.restore()}const V=i.label||{},H=i.helperText||{},it=i.fontFamily||"Inter";if(V.visible!==!1){const nt=V.text||"Label",ft=V.fontSize||12,M=V.color||"rgba(156, 163, 175, 1)",Q=V.offset??8;t.font=`600 ${ft}px "${it}", sans-serif`,t.fillStyle=M,t.textAlign="left",t.textBaseline="bottom";const Y=-(n/2),L=-(f/2)-Q;t.fillText(nt,Y,L)}if(H.visible===!0){const nt=H.text||"Helper text",ft=H.fontSize||11,M=H.color||"rgba(156, 163, 175, 1)",Q=H.offset??6;t.font=`400 ${ft}px "${it}", sans-serif`,t.fillStyle=M,t.textAlign="left",t.textBaseline="top";const Y=-(n/2),L=f/2+Q;t.fillText(nt,Y,L)}}renderDropdown(t,s){var rt;const o=this.objectStates.get(s.id);if(!o)return;const e=o.options||s.options||{},i=s.geometry.width||160,n=s.geometry.height||40,a=-i/2,r=-n/2,c=e.corner_radius??6,p=e.disabled||e.previewState==="disabled",l=this.lastHoveredObjectId===s.id||e.previewState==="hover",f=(e.isOpen||e.previewState==="active")&&!p;let g=e.backgroundColor,d=e.borderColor,u=e.color||"#333333";p?(g=e.disabledBackgroundColor||"#f3f4f6",d=e.disabledBorderColor||"#e5e7eb",u=e.disabledColor||"#9ca3af"):f?(g=e.activeBackgroundColor||g,d=e.activeBorderColor||d,u=e.activeColor||u):l&&(g=e.hoverBackgroundColor||g,d=e.hoverBorderColor||d,u=e.hoverColor||u),g||(g="#ffffff"),d||(d="#e5e7eb");const m=t.globalAlpha;t.globalAlpha=m*(e.opacity??1),this.drawRoundRect(t,a,r,i,n,c),t.fillStyle=this.createCanvasFill(t,typeof g=="string"?{type:"Solid",color:g}:g,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 S=12,b=e.chevronType||"chevron",v=e.chevronSize||16,C=(f?e.openIconColor:e.closedIconColor)||e.chevronColor||"#6b7280";if(b!=="none"){const at=a+i-S-v/2;t.save(),t.translate(at,0);const N=f?e.openIconAngle??180:e.closedIconAngle??0;if(t.rotate(N*Math.PI/180),t.strokeStyle=C,t.fillStyle=C,t.lineWidth=1.5,t.lineCap="round",t.lineJoin="round",b==="chevron")t.beginPath(),t.moveTo(-v/2,-v*.2),t.lineTo(0,v*.2),t.lineTo(v/2,-v*.2),t.stroke();else if(b==="custom"||b==="path"){const O=f&&e.openIconPath||e.closedIconPath;if(O){const $=new Path2D(O);t.save();const P=v/24;t.scale(P,P),t.translate(-12,-12),t.fill($),t.restore()}}t.restore()}const k=e.selectedOption||e.placeholder||"Select...",A=e.fontSize||14,x=e.fontWeight||400,B=e.fontFamily||"Inter, sans-serif";t.font=`${x} ${A}px ${B}`;const R=p?e.disabledColor||"#9ca3af":!e.selectedOption&&e.placeholder?"#9ca3af":u;t.fillStyle=this.createCanvasFill(t,typeof R=="string"?{type:"Solid",color:R}:R,i,n)||"#333333",t.textAlign="left",t.textBaseline="middle";const K=b==="none"?0:v+8,tt=i-S*2-K;if(t.save(),t.beginPath(),t.rect(a+S,r,tt,n),t.clip(),t.fillText(k,a+S,0),t.restore(),f&&!p){const at=r+n+4,N=e.optionsList||[],O=e.itemHeight||32,$=e.listPadding??4,P=N.length*O+$*2,J=e.listCornerRadius??c;t.save();const j=e.listShadow||{},lt=t.getTransform(),V=Math.sqrt(lt.a*lt.a+lt.b*lt.b)||1;t.shadowColor=typeof j.color=="string"?j.color:((rt=j.color)==null?void 0:rt.color)||"rgba(0,0,0,0.15)",t.shadowBlur=(j.blur??12)*V,t.shadowOffsetY=(j.offsetY??6)*V,t.shadowOffsetX=(j.offsetX??0)*V,t.beginPath(),this.drawRoundRect(t,a,at,i,P,J),t.fillStyle=this.createCanvasFill(t,typeof e.listBackgroundColor=="string"?{type:"Solid",color:e.listBackgroundColor}:e.listBackgroundColor||{type:"Solid",color:"#ffffff"},i,P)||"#ffffff",t.fill();const H=e.listBorderWidth??1;H>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,P)||"#e5e7eb",t.lineWidth=H,t.stroke()),t.restore();const it=e.itemFontSize||A,nt=e.itemFontFamily||B;t.font=`${x} ${it}px ${nt}`,N.forEach((ft,M)=>{const Q=at+$+M*O;if(ft===e.selectedOption)t.fillStyle=this.createCanvasFill(t,typeof e.itemSelectedBackgroundColor=="string"?{type:"Solid",color:e.itemSelectedBackgroundColor}:e.itemSelectedBackgroundColor||{type:"Solid",color:"#f3f4f6"},i,O)||"#f3f4f6",t.fillRect(a+H,Q,i-H*2,O),t.fillStyle=e.itemSelectedColor||e.accentColor||u||"#374151";else if(t.fillStyle=e.listTextColor||u||"#333333",this.activeDropdownId===s.id&&this._lastPointerPos){const L=this._lastPointerPos.y-(at+$),z=Math.floor(L/O);M===z&&(t.fillStyle=this.createCanvasFill(t,typeof e.itemHoverBackgroundColor=="string"?{type:"Solid",color:e.itemHoverBackgroundColor}:e.itemHoverBackgroundColor||{type:"Solid",color:"#f9fafb"},i,O)||"#f9fafb",t.fillRect(a+H,Q,i-H*2,O),t.fillStyle=e.itemHoverColor||u)}t.fillText(ft,a+S,Q+O/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,c=this.activeObjectId===s.id,p=e.label||{},l=e.hoverStyle||{},f=e.activeStyle||{},g=e.icon||{enabled:!1};let d=e.backgroundColor||"#3b82f6",u=p.color||"#ffffff",m=p.text||"Button",y=i.cornerRadius??8,S=e.borderColor||"transparent",b=e.borderWidth||0,v=1;c&&f?(d=f.backgroundColor||d,u=f.color||u,m=f.text||m,v=f.scale??.95,y=f.cornerRadius??y):r&&l&&(d=l.backgroundColor||d,u=l.color||u,m=l.text||m,v=l.scale??1,y=l.cornerRadius??y,S=l.borderColor||S);const C=-n/2,k=-a/2;t.save(),t.scale(v,v),t.beginPath(),this.drawRoundRect(t,C,k,n,a,y);const A=this.createCanvasFill(t,d,n,a);A&&(t.fillStyle=A,t.fill()),(b>0||r&&l.borderColor)&&(t.strokeStyle=S,t.lineWidth=b||(r?1:0),t.stroke());const x=p.fontSize||14,B=p.fontFamily||"Inter",R=p.fontWeight||600;t.font=`${R} ${x}px "${B}", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle=u,t.textAlign="center",t.textBaseline="middle";let K=0;if(g.enabled&&g.svgPath){const tt=x*1.1,rt=g.gap||8,at=t.measureText(m),O=-(at.width+tt+rt)/2,$=g.position==="left"?O+tt/2:O+at.width+rt+tt/2;K=g.position==="left"?O+tt+rt+at.width/2:O+at.width/2,t.save(),t.translate($,0);const P=new Path2D(g.svgPath),J=tt/24;t.scale(J,J),t.translate(-12,-12),t.fillStyle=u,t.fill(P),t.restore()}t.fillText(m,K,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,c=-a/2,p=e.corner_radius??8,l=e.label||{},f=i?e.accentColor||"#3b82f6":e.inactiveColor||"#374151",g=i?e.activeTextColor||"#ffffff":e.inactiveTextColor||"#9ca3af";t.save(),t.beginPath(),this.drawRoundRect(t,r,c,n,a,p),t.fillStyle=f,t.fill();const d=l.fontSize||14,u=l.fontFamily||"Inter";t.font=`${l.fontWeight||600} ${d}px "${u}", sans-serif`,t.fillStyle=g,t.textAlign="center",t.textBaseline="middle",t.fillText(l.text||"Toggle",0,0),t.restore()}renderToggle(t,s){var J,j,lt,V,H,it,nt,ft,M,Q,Y,L;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((J=s.geometry)==null?void 0:J.width)||52,n=((j=s.geometry)==null?void 0:j.height)||30,a=-i/2,r=-n/2,c=e.checked??!1,p=e.cornerRadius??e.corner_radius??n/2,l=e.toggleStyle||{},f=l.backgroundColor||e.activeColor||"#10b981",g=l.borderColor||e.borderColor||"transparent",d=l.borderWidth??e.borderWidth??0,u=l.knobColor||e.knobColor||"#ffffff",m=c?f:e.inactiveColor||"#374151",y=c?g:e.borderColor||"transparent",S=c?d:e.borderWidth??0,b=c?u:e.knobColor||"#ffffff";e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,i,n,p);const v=this.createCanvasFill(t,m,i,n);if(v&&(t.fillStyle=v,t.fill()),S>0){t.lineWidth=S;const z=this.createCanvasFill(t,y,i,n);z&&(t.strokeStyle=z,t.stroke())}const C=2,k=n-C*2,A=k/2,x=a+C,B=a+i-C-k,R=c?B:x,K=r+C;t.beginPath(),t.arc(R+A,K+A,A,0,Math.PI*2);const tt=this.createCanvasFill(t,b,k,k);tt&&(t.fillStyle=tt,t.fill()),e.disabled&&(t.globalAlpha*=2);let rt=!1,at=!1;const N=(c?(lt=l.leftLabel)==null?void 0:lt.text:null)||((V=e.leftLabel)==null?void 0:V.text)||"",O=(c?(H=l.leftLabel)==null?void 0:H.color:null)||((it=e.leftLabel)==null?void 0:it.color)||"#f3f4f6";if((nt=e.leftLabel)!=null&&nt.enabled&&N){const z=e.leftLabel;t.font=`${z.fontWeight||400} ${z.fontSize||12}px "${z.fontFamily||"Inter"}", sans-serif`,t.fillStyle=O,t.textBaseline="middle",t.textAlign="right",t.fillText(N,a-(z.gap||8),0),rt=!0}const $=(c?(ft=l.rightLabel)==null?void 0:ft.text:null)||((M=e.rightLabel)==null?void 0:M.text)||"",P=(c?(Q=l.rightLabel)==null?void 0:Q.color:null)||((Y=e.rightLabel)==null?void 0:Y.color)||"#f3f4f6";if((L=e.rightLabel)!=null&&L.enabled&&$){const z=e.rightLabel;t.font=`${z.fontWeight||400} ${z.fontSize||12}px "${z.fontFamily||"Inter"}", sans-serif`,t.fillStyle=P,t.textBaseline="middle",t.textAlign="left",t.fillText($,a+i+(z.gap||8),0),at=!0}if(!rt&&!at&&e.label&&e.label.text){const z=e.label,pt=z.fontSize||14,vt=z.fontWeight||400,yt=z.fontFamily||"Inter";t.font=`${vt} ${pt}px "${yt}", sans-serif`,t.fillStyle=z.color||"#f3f4f6",t.textBaseline="middle";const _t=z.gap||10;let kt=0,Tt=0;z.position==="left"?(t.textAlign="right",kt=a-_t,Tt=0):z.position==="right"?(t.textAlign="left",kt=a+i+_t,Tt=0):z.position==="top"?(t.textAlign="center",kt=0,Tt=r-_t,t.textBaseline="bottom"):z.position==="bottom"?(t.textAlign="center",kt=0,Tt=r+n+_t,t.textBaseline="top"):(t.textAlign="left",kt=a+i+_t,Tt=0),t.fillText(z.text,kt,Tt)}}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(u=>u.data&&u.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(u=>{let m=u.data;if(u.isVarEnabled&&u.inputId){let y=this.inputs.get(u.inputId);if(y===void 0){const S=this.inputNameMap.get(u.inputId);S&&S.length>0&&(y=this.inputs.get(S[0]))}y&&Array.isArray(y)&&(m=y)}if(m&&m.length>0){const y=m.filter(S=>typeof S=="number"&&!isNaN(S));y.length>0&&(n=Math.min(n,...y),a=Math.max(a,...y),r=Math.max(r,m.length))}u._resolvedData=m}),r<2)return;const c=a-n,p=o/(r-1),l=u=>{const m=c===0?.5:(u-n)/c;return e/2-m*e},f=u=>u*p-o/2,g=s.axisColor||"#333333";if(s.showXAxis&&(t.beginPath(),t.strokeStyle=s.xAxisColor||g,t.lineWidth=1,t.moveTo(-o/2,e/2),t.lineTo(o/2,e/2),t.stroke()),s.showYAxis&&(t.beginPath(),t.strokeStyle=s.yAxisColor||g,t.lineWidth=1,t.moveTo(-o/2,-e/2),t.lineTo(-o/2,e/2),t.stroke()),t.fillStyle=s.axisLabelColor||"#333333",t.font=`${s.axisLabelFontSize||10}px Inter, sans-serif`,s.showXLabels){t.textAlign="center",t.textBaseline="top";for(let u=0;u<r;u++){const m=f(u);t.fillText(`${u+1}`,m,e/2+5)}}if(s.showYLabels){t.textAlign="right",t.textBaseline="middle";const u=-o/2-5,m=(a+n)/2;t.fillText(a.toFixed(1),u,l(a)),t.fillText(m.toFixed(1),u,l(m)),t.fillText(n.toFixed(1),u,l(n))}const d=10;if(i.forEach(u=>{const m=u._resolvedData;if(!(!m||m.length<2)){if(u.showArea){if(t.beginPath(),t.moveTo(f(0),e/2),t.lineTo(f(0),l(m[0])),u.smoothing&&m.length>2)for(let S=0;S<m.length-1;S++){const b=m[S===0?S:S-1],v=m[S],C=m[S+1],k=m[S+1===m.length-1?S+1:S+2];for(let A=1;A<=d;A++){const x=A/d,B=this._catmullRom(b,v,C,k,x);t.lineTo(f(S+x),l(B))}}else for(let S=1;S<m.length;S++)t.lineTo(f(S),l(m[S]));t.lineTo(f(m.length-1),e/2),t.closePath();const y=t.globalAlpha;t.globalAlpha=y*(s.areaOpacity??.3),t.fillStyle=u.areaColor||"rgba(139, 92, 246, 0.2)",t.fill(),t.globalAlpha=y}if(t.beginPath(),t.strokeStyle=u.lineColor||"#3b82f6",t.lineWidth=u.lineWidth||2,t.lineJoin="round",t.lineCap="round",t.moveTo(f(0),l(m[0])),u.smoothing&&m.length>2)for(let y=0;y<m.length-1;y++){const S=m[y===0?y:y-1],b=m[y],v=m[y+1],C=m[y+1===m.length-1?y+1:y+2];for(let k=1;k<=d;k++){const A=k/d,x=this._catmullRom(S,b,v,C,A);t.lineTo(f(y+A),l(x))}}else for(let y=1;y<m.length;y++)t.lineTo(f(y),l(m[y]));t.stroke(),u.showPoints&&m.forEach((y,S)=>{const b=f(S),v=l(y);t.beginPath(),t.arc(b,v,(u.pointSize||6)/2,0,Math.PI*2),t.fillStyle=u.pointFill||"#ffffff",t.fill(),t.strokeStyle=u.pointStrokeColor||u.lineColor||"#3b82f6",t.lineWidth=u.pointStrokeWidth||1,t.stroke()})}}),s.showLegend&&i.length>0){const u=o/2-10;let m=-e/2+15;const y=s.legendFontSize||10,S=y+5;t.font=`${y}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="alphabetic",i.forEach(b=>{const C=b.label||"Series",k=t.measureText(C).width;t.beginPath(),t.rect(u-k-8-5,m-(8/2+2),8,8),t.fillStyle=b.lineColor||"#3b82f6",t.fill(),t.fillStyle=s.legendColor||"#333333",t.fillText(C,u,m),m+=S})}}_catmullRom(t,s,o,e,i){const n=(o-t)*.5,a=(e-s)*.5,r=i*i,c=i*r;return(2*s-2*o+n+a)*c+(-3*s+3*o-2*n-a)*r+n*i+s}normalizeOpacity(t){const s=typeof t=="number"?t:parseFloat(String(t));return isNaN(s)?1:s>1?Math.min(1,s/100):Math.max(0,Math.min(1,s))}createCanvasFill(t,s,o,e){var i,n,a;if(!s||s.type==="None")return null;if(typeof s=="string")return s;if(s.type==="Solid"&&s.color){const r=s.color,p=(((n=(i=this.artboard)==null?void 0:i.tokens)==null?void 0:n.colors)||{})[r]||r;return t.fillStyle=p,p}if((s.type==="LinearGradient"||s.type==="RadialGradient"||s.type==="AngularGradient"||s.type==="DiamondGradient")&&s.stops){const r=(c,p=100)=>{var v,C;const f=(((C=(v=this.artboard)==null?void 0:v.tokens)==null?void 0:C.colors)||{})[c]||c,g=this.normalizeOpacity(s.opacity??100),u=this.normalizeOpacity(p)*g;if(u>=1&&f.startsWith("#"))return f;const m=f.startsWith("#")?f.replace("#",""):"ffffff",y=parseInt(m.substring(0,2),16),S=parseInt(m.substring(2,4),16),b=parseInt(m.substring(4,6),16);return`rgba(${y}, ${S}, ${b}, ${u})`};if(s.type==="LinearGradient"){const c=(u,m,y)=>Array.isArray(u)?u[m]??(m===0?0:1):u&&typeof u=="object"?u[y]??(m===0?0:1):m===0?0:1,p=c(s.start,0,"x")*o-o/2,l=c(s.start,1,"y")*e-e/2,f=c(s.end,0,"x")*o-o/2,g=c(s.end,1,"y")*e-e/2,d=t.createLinearGradient(p,l,f,g);if(s.stops.forEach(u=>{const m=u.offset!==void 0?u.offset:u.pos!==void 0?u.pos:u.position!==void 0?u.position:0,y=r(u.color||"#000000",u.opacity??100);d.addColorStop(Math.max(0,Math.min(1,m)),y)}),s.gradientTransform&&d.setTransform){const[u,m,y,S,b,v]=s.gradientTransform;d.setTransform({a:u,b:m,c:y,d:S,e:b,f:v})}return d}else if(s.type==="RadialGradient"){const c=(d,u,m)=>Array.isArray(d)?d[u]??.5:d&&typeof d=="object"?d[m]??.5:.5,p=c(s.center,0,"x")*o-o/2,l=c(s.center,1,"y")*e-e/2,f=(s.radius??.5)*Math.max(o,e),g=t.createRadialGradient(p,l,0,p,l,f);if(s.stops.forEach(d=>{const u=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);g.addColorStop(Math.max(0,Math.min(1,u)),m)}),s.gradientTransform&&g.setTransform){const[d,u,m,y,S,b]=s.gradientTransform;g.setTransform({a:d,b:u,c:m,d:y,e:S,f:b})}return g}else if(s.type==="AngularGradient"){const c=(d,u,m)=>Array.isArray(d)?d[u]??.5:d&&typeof d=="object"?d[m]??.5:.5,p=c(s.center||[.5,.5],0,"x")*o-o/2,l=c(s.center||[.5,.5],1,"y")*e-e/2,f=(s.degree||s.angle||0)*(Math.PI/180),g=(a=t.createConicGradient)==null?void 0:a.call(t,f,p,l);if(g){if(s.stops.forEach(d=>{const u=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);g.addColorStop(Math.max(0,Math.min(1,u)),m)}),s.gradientTransform&&g.setTransform){const[d,u,m,y,S,b]=s.gradientTransform;g.setTransform({a:d,b:u,c:m,d:y,e:S,f:b})}return g}}else if(s.type==="DiamondGradient"){const c=(d,u,m)=>Array.isArray(d)?d[u]??.5:d&&typeof d=="object"?d[m]??.5:.5,p=c(s.center||[.5,.5],0,"x")*o-o/2,l=c(s.center||[.5,.5],1,"y")*e-e/2,f=(s.radius??.5)*Math.max(o,e);t.save(),t.translate(p,l),t.rotate(Math.PI/4);const g=t.createRadialGradient(0,0,0,0,0,f);if(s.stops.forEach(d=>{const u=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);g.addColorStop(Math.max(0,Math.min(1,u)),m)}),s.gradientTransform&&g.setTransform){const[d,u,m,y,S,b]=s.gradientTransform;g.setTransform({a:d,b:u,c:m,d:y,e:S,f:b})}return t.scale(1/Math.SQRT2,1/Math.SQRT2),t.fillStyle=g,t.restore(),g}}if(s.type==="Pattern"&&s.url){let r=this.imageCache.get(s.url);if(r||(r=new Image,r.src=s.url,this.imageCache.set(s.url,r)),r.complete&&r.naturalWidth>0){const c=t.createPattern(r,"repeat");if(c&&(s.scaleX!==void 0||s.offsetX!==void 0)){const p=new DOMMatrix,l=s.scaleX??1,f=s.scaleY??1,g=s.offsetX??0,d=s.offsetY??0,u=s.rotation??0;p.translateSelf(g,d),p.rotateSelf(u),p.scaleSelf(l,f),c.setTransform(p)}return c}}return s.color||null}drawRoundRect(t,s,o,e,i,n){if(n===0||n===void 0||n===null){t.rect(s,o,e,i);return}let a=n;if(typeof a=="string")try{a=JSON.parse(a)}catch{a=parseFloat(a)||0}let r=0,c=0,p=0,l=0;typeof a=="number"?r=c=p=l=a:Array.isArray(a)?a.length===1?r=c=p=l=a[0]:a.length===2?(r=p=a[0],c=l=a[1]):a.length===3?(r=a[0],c=l=a[1],p=a[2]):a.length>=4&&(r=a[0],c=a[1],p=a[2],l=a[3]):a&&typeof a=="object"&&(r=a.tl??a.corner_radius??a.cornerRadius??0,c=a.tr??a.corner_radius??a.cornerRadius??0,p=a.br??a.corner_radius??a.cornerRadius??0,l=a.bl??a.corner_radius??a.cornerRadius??0);const f=Math.min(Math.abs(e)/2,Math.abs(i)/2);if(r=Math.min(Math.max(0,r),f),c=Math.min(Math.max(0,c),f),p=Math.min(Math.max(0,p),f),l=Math.min(Math.max(0,l),f),t.roundRect){t.roundRect(s,o,e,i,[r,c,p,l]);return}t.moveTo(s+r,o),t.lineTo(s+e-c,o),t.arcTo(s+e,o,s+e,o+c,c),t.lineTo(s+e,o+i-p),t.arcTo(s+e,o+i,s+e-p,o+i,p),t.lineTo(s+l,o+i),t.arcTo(s,o+i,s,o+i-l,l),t.lineTo(s,o+r),t.arcTo(s,o,s+r,o,r),t.closePath()}renderListView(t,s){var at,N,O,$;const o=this.objectStates.get(s.id)||{},e=o.options||s.options||{},i=o.width!==void 0?o.width:((at=s.geometry)==null?void 0:at.width)||200,n=o.height!==void 0?o.height:((N=s.geometry)==null?void 0:N.height)||300,a=-i/2,r=-n/2,c=o.corner_radius!==void 0?o.corner_radius:e.corner_radius??0,p=e.orientation||"vertical",l=e.items||[],f=e.itemGap??10,g=e.itemHeight??50,d=e.itemWidth??200,u=e.scrollOffset??0,m=e.padding??0,y=e.glassEffect!==!1,S=e.accentColor||"#3b82f6",b=e.itemTextColor||"#333333",v=e.itemBackgroundColor||"#ffffff",C=e.hoveredIndex??null,k=e.activeItemIndex??null,A=e.glowIntensity??0,x=e.glowColor||"#3b82f6",B=typeof x=="string"?x:x.color||(($=(O=x.stops)==null?void 0:O[0])==null?void 0:$.color)||"#3b82f6",R=e.opacity!==void 0?e.opacity:s.opacity!==void 0?s.opacity:1;if(t.save(),t.globalAlpha*=R,A>0){const P=t.getTransform(),J=Math.sqrt(P.a*P.a+P.b*P.b)||1;t.shadowColor=B,t.shadowBlur=A*2*J,t.shadowOffsetX=0,t.shadowOffsetY=0}if(y){const P=e.listBackgroundColor||"rgba(31, 41, 55, 0.4)",J=this.createCanvasFill(t,P,i,n);t.fillStyle=J||"rgba(31, 41, 55, 0.4)",this.drawListViewRect(t,a,r,i,n,c),t.fill();const j=t.createLinearGradient(a,r,a+i,r+n);j.addColorStop(0,"rgba(255, 255, 255, 0.15)"),j.addColorStop(.5,"rgba(255, 255, 255, 0.08)"),j.addColorStop(1,"rgba(255, 255, 255, 0.03)"),t.fillStyle=j,this.drawListViewRect(t,a,r,i,n,c),t.fill(),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1,this.drawListViewRect(t,a,r,i,n,c),t.stroke()}else{const P=e.listBackgroundColor||"transparent",J=this.createCanvasFill(t,P,i,n);J&&(t.fillStyle=J,this.drawListViewRect(t,a,r,i,n,c),t.fill());const j=e.borderWidth??0;j>0&&(t.strokeStyle=e.borderColor||"#cccccc",t.lineWidth=j,this.drawListViewRect(t,a,r,i,n,c),t.stroke())}t.shadowBlur=0,t.save(),this.drawListViewRect(t,a,r,i,n,c),t.clip();const K=typeof m=="number"?m:p==="vertical"?m[0]:m[3];let tt=(p==="vertical"?r:a)+u+K;if(t.textBaseline="middle",l.forEach((P,J)=>{const j=p==="vertical"?i:d,lt=p==="vertical"?g:n,V=p==="vertical"?a:tt,H=p==="vertical"?tt:r,it=C===J,nt=k===J;if(nt){const L=this.createCanvasFill(t,S,j,lt);t.fillStyle=L||S;const z=t.globalAlpha;t.globalAlpha=z*.8,t.fillRect(V,H,j,lt),t.globalAlpha=z}else if(it)t.fillStyle=y?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",t.fillRect(V,H,j,lt);else if(v!=="transparent"){const L=this.createCanvasFill(t,v,j,lt);t.fillStyle=L||v,t.fillRect(V,H,j,lt)}if(nt||it){const L=this.createCanvasFill(t,S,p==="vertical"?3:j,p==="vertical"?lt:3);t.fillStyle=L||S,p==="vertical"?t.fillRect(V,H,3,lt):t.fillRect(V,H+lt-3,j,3)}const ft=nt?"#ffffff":y?"rgba(255, 255, 255, 0.9)":b;t.fillStyle=ft,t.font=nt||it?"600 14px Inter, sans-serif":"400 14px Inter, sans-serif";const M=typeof P=="string"?P:(P==null?void 0:P.label)||`Item ${J+1}`,Q=V+(p==="vertical"?16:j/2),Y=H+lt/2;p==="horizontal"?t.textAlign="center":t.textAlign="left",t.fillText(M,Q,Y),tt+=(p==="vertical"?g:d)+f}),t.restore(),e.showScrollbar!==!1){const P=(l.length||0)*(p==="vertical"?g:d)+((l.length||0)-1)*f,J=p==="vertical"?n:i;if(P>J){const j=J/P,lt=J*j,V=-u/P*J,H=e.scrollbarColor||"rgba(255,255,255,0.3)",it=e.scrollbarWidth||4;t.fillStyle=H,p==="vertical"?t.fillRect(a+i-it-2,r+V,it,lt):t.fillRect(a+V,r+n-it-2,lt,it)}}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,c=s.itemHeight??50,p=s.itemWidth??200,l=n.width!==void 0?n.width:((m=t.geometry)==null?void 0:m.width)||200,f=n.height!==void 0?n.height:((y=t.geometry)==null?void 0:y.height)||300,g=(a.length||0)*(o==="vertical"?c:p)+((a.length||0)-1)*r,u=Math.max(0,g-(o==="vertical"?f:l)+(s.padding*2||0));s.scrollOffset>0&&(s.scrollOffset=0),s.scrollOffset<-u&&(s.scrollOffset=-u)}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,tt;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:((K=t.geometry)==null?void 0:K.width)||200,r=i.height!==void 0?i.height:((tt=t.geometry)==null?void 0:tt.height)||300,c=e.orientation||"vertical",p=e.itemGap??10,l=e.itemHeight??50,f=e.itemWidth??200,g=e.scrollOffset??0,d=e.padding??0,u=this.getWorldTransform(t.id),m=s-u.x,y=o-u.y,S=-u.rotation*(Math.PI/180),b=Math.cos(S),v=Math.sin(S),C=m*b-y*v,k=m*v+y*b,A=-a/2,x=-r/2,B=typeof d=="number"?d:c==="vertical"?d[0]:d[3];let R=(c==="vertical"?x:A)+g+B;for(let rt=0;rt<n.length;rt++){const at=c==="vertical"?a:f,N=c==="vertical"?l:r,O=c==="vertical"?A:R,$=c==="vertical"?R:x;if(C>=O&&C<=O+at&&k>=$&&k<=$+N)return rt;R+=(c==="vertical"?l:f)+p}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 f,g,d,u,m,y,S,b,v,C,k,A,x,B,R,K,tt,rt,at,N,O,$,P,J,j,lt,V,H,it,nt,ft,M,Q,Y,L,z,pt,vt,yt,_t,kt,Tt,Wt,Vt,Dt,Nt,zt,st,ct,_,I,D,Z,bt,Mt,ht,Pt,mt,w,Et,Xt,$t,dt,T,X,ut,E,F,et,It,Ot,St,Ft,Ct,Gt,Jt,Qt;if(!n.enabled)return;const a=n.startTime||0,r=n.endTime||1/0;if(this.currentTime<a||this.currentTime>r)return;const c=i.x-s,p=i.y-o,l=Math.sqrt(c*c+p*p);if(this.frameCount%240===0&&Math.random()<.1&&console.log(`[ExodeUI] Executing ${n.type} on ${e.name}`),n.type===W.Proximity){const U=((f=n.settings)==null?void 0:f.radius)||300,G=((g=n.settings)==null?void 0:g.falloff)||"smooth";let q=0;l<U&&(G==="linear"?q=1-l/U:q=Math.pow(1-l/U,2)),q>0&&n.sensors.forEach(wt=>{this.applyBehaviorSensor(i,wt,q,t,n.settings,e)})}else if(n.type===W.Magnetic){const U=((d=n.settings)==null?void 0:d.radius)||400,G=((u=n.settings)==null?void 0:u.strength)||.5;if(l<U&&l>5){const q=1-l/U,wt=c*q*G,Rt=p*q*G;i.x-=wt*t*10,i.y-=Rt*t*10}}else if(n.type===W.Repel){const U=((m=n.settings)==null?void 0:m.radius)||300,G=((y=n.settings)==null?void 0:y.strength)||1;if(l<U){const q=Math.pow(1-l/U,2);i.x+=c/(l||1)*q*60*G*t*5,i.y+=p/(l||1)*q*60*G*t*5}}else if(n.type===W.Orbit){const U=((S=n.settings)==null?void 0:S.speed)||1,G=((b=n.settings)==null?void 0:b.radius)||30,q=this.currentTime*U*Math.PI*2;i.x+=Math.cos(q)*G*t*5,i.y+=Math.sin(q)*G*t*5,i.rotation+=2*t*5}else if(n.type===W.Vortex){const U=((v=n.settings)==null?void 0:v.radius)||400,G=((C=n.settings)==null?void 0:C.speed)||2,q=((k=n.settings)==null?void 0:k.strength)||1;if(l<U){const wt=Math.pow(1-l/U,1.5),Rt=this.currentTime*G*Math.PI*2,Ht=Math.cos(Rt)*30-c*.4,Ut=Math.sin(Rt)*30-p*.4;i.x+=Ht*wt*q*t*5,i.y+=Ut*wt*q*t*5,i.rotation+=5*wt*q*t*5,i.scale_x*=1-wt*.1*q*t,i.scale_y*=1-wt*.1*q*t}}else if(n.type===W.Fluid){const U=((A=n.settings)==null?void 0:A.radius)||300,G=((x=n.settings)==null?void 0:x.strength)||1;if(l<U){const q=Math.pow(1-l/U,1.2),wt=c/(l||1)*q*1.2*G,Rt=p/(l||1)*q*1.2*G;i.x+=wt*10*t*5,i.y+=Rt*10*t*5,i.scale_x*=1+q*.3*G*t,i.scale_y*=1+q*.3*G*t}}else if(n.type===W.Elastic){const U=((B=n.settings)==null?void 0:B.radius)||300,G=((R=n.settings)==null?void 0:R.strength)||1;if(l<U){const q=1-l/U;i.scale_x*=1+q*.4*G*t,i.scale_y*=1+q*.4*G*t}}else if(n.type===W.Holographic){const U=i.x-this.canvasWidth/2,G=i.y-this.canvasHeight/2,q=((K=n.settings)==null?void 0:K.factor)||25;if(i.x-=U/1e3*q*t*5,i.y-=G/1e3*q*t*5,i.style){const wt=1-Math.min(1,l/400);i.style.exposure=(i.style.exposure||1)+wt*.5*t}}else if(n.type===W.Sticky){const U=((tt=n.settings)==null?void 0:tt.radius)||80,G=((rt=n.settings)==null?void 0:rt.strength)||1;if(l<U){const q=Math.pow(1-l/U,2);i.x-=c*q*G*t*10,i.y-=p*q*G*t*10,i.scale_x*=1-q*.1*G*t,i.scale_y*=1-q*.1*G*t}}else if(n.type===W.Dilation){const U=((at=n.settings)==null?void 0:at.size)||120,G=((N=n.settings)==null?void 0:N.strength)||1;if(l<U){const q=1-l/U;i.scale_x*=1+q*.5*G*t,i.scale_y*=1+q*.5*G*t}}else if(n.type===W.Parallax){const U=((O=n.settings)==null?void 0:O.factor)||.05,G=this.canvasHeight/2,q=(this._lastPointerPos.y-G)*U;i.y+=q*t*10}else if(n.type===W.Squash){const U=(($=n.settings)==null?void 0:$.strength)||.8;l<(e.width||100)&&this.isMouseDown?(i.scale_y=this.lerp(i.scale_y??1,(((P=e.transform)==null?void 0:P.scale_y)??1)*U,.3),i.scale_x=this.lerp(i.scale_x??1,(((J=e.transform)==null?void 0:J.scale_x)??1)*(1+(1-U)*.4),.3)):(i.scale_y=this.lerp(i.scale_y??1,((j=e.transform)==null?void 0:j.scale_y)??1,.2),i.scale_x=this.lerp(i.scale_x??1,((lt=e.transform)==null?void 0:lt.scale_x)??1,.2))}else if(n.type===W.TextCounter){const U=((V=n.settings)==null?void 0:V.duration)||2,G=((H=n.settings)==null?void 0:H.from)||0,q=((it=n.settings)==null?void 0:it.to)||100;n._runtimeStart===void 0&&(n._runtimeStart=this.currentTime);const wt=this.currentTime-n._runtimeStart,Rt=Math.min(1,wt/U),Ht=Math.floor(G+(q-G)*Rt);if(((nt=e.geometry)==null?void 0:nt.type)==="Text"){const Ut=((ft=n.settings)==null?void 0:ft.prefix)||"",qt=((M=n.settings)==null?void 0:M.suffix)||"";i.geometry||(i.geometry={...e.geometry}),i.geometry.text=`${Ut}${Ht}${qt}`}}else if(n.type===W.Spotlight){const U=((Q=n.settings)==null?void 0:Q.radius)||250,G=((Y=n.settings)==null?void 0:Y.strength)||1.5;if(l<U){const q=Math.pow(1-l/U,2);i.style||(i.style={...e.style}),i.style.adjustments||(i.style.adjustments={...(L=e.style)==null?void 0:L.adjustments}),i.style.adjustments.exposure=(((pt=(z=e.style)==null?void 0:z.adjustments)==null?void 0:pt.exposure)||0)+q*G*50}else(vt=i.style)!=null&&vt.adjustments&&(i.style.adjustments.exposure=this.lerp(i.style.adjustments.exposure||0,((_t=(yt=e.style)==null?void 0:yt.adjustments)==null?void 0:_t.exposure)||0,.1))}else if(n.type===W.Noise||n.type===W.Float){const U=(((kt=n.settings)==null?void 0:kt.frequency)||((Tt=n.settings)==null?void 0:Tt.speed)||1)*.002,G=(((Wt=n.settings)==null?void 0:Wt.amplitude)||((Vt=n.settings)==null?void 0:Vt.range)||50)*(((Dt=n.settings)==null?void 0:Dt.strength)||1),q=Date.now();i.x+=Math.sin(q*U)*G*t,i.y+=Math.cos(q*U*.8)*G*t,i.rotation+=Math.sin(q*U*.5)*5*t}else if(n.type===W.Pulse){const U=(((Nt=n.settings)==null?void 0:Nt.speed)||1)*.005,G=(((zt=n.settings)==null?void 0:zt.scale)||1.2)-1,q=Math.sin(Date.now()*U),wt=((st=n.settings)==null?void 0:st.strength)||1;i.scale_x*=1+q*G*wt*t,i.scale_y*=1+q*G*wt*t,i.style&&(i.style.exposure=(i.style.exposure||1)+Math.max(0,q)*.1*wt*t)}else if(n.type===W.Draggable){const U=((ct=n.settings)==null?void 0:ct.radius)||150,G=this.draggingBehaviors.has(e.id);if(l<U||G){const q=((_=n.settings)==null?void 0:_.strength)||1,wt=G?1:Math.max(0,1-l/U);this.applyBehaviorSensor(i,Bt.PositionX,wt*q,t,n.settings),this.applyBehaviorSensor(i,Bt.PositionY,wt*q,t,n.settings)}}else if(n.type===W.Scroll){const U=((I=n.settings)==null?void 0:I.axis)||"vertical",G=((D=n.settings)==null?void 0:D.factor)||.5,q=((Z=n.settings)==null?void 0:Z.strength)||1,wt=((bt=n.settings)==null?void 0:bt.scaleFactor)||0;(U==="vertical"||U==="both")&&(i.y+=this.scrollOffset.y*G*q*t),(U==="horizontal"||U==="both")&&(i.x+=this.scrollOffset.x*G*q*t),wt!==0&&(i.scale_x*=1+this.scrollOffset.y*wt*t,i.scale_y*=1+this.scrollOffset.y*wt*t)}else if(n.type===W.LookAt){const U=((Mt=n.settings)==null?void 0:Mt.factor)||1,G=((ht=n.settings)==null?void 0:ht.strength)||1,q=Math.atan2(-p,-c)*(180/Math.PI),wt=i.rotation,Rt=(q-wt+180)%360-180;i.rotation+=Rt*U*G*t*10}else if(n.type===W.Glint||n.type===W.Scan){const U=(((Pt=n.settings)==null?void 0:Pt.speed)||1)*.004,G=((mt=n.settings)==null?void 0:mt.strength)||1,q=(Math.sin(Date.now()*U)+1)/2;i.style&&(i.style.exposure=(i.style.exposure||1)+q*G*t*5),i.x+=(q-.5)*20*G*t}else if(n.type===W.Ratchet){const U=((w=n.settings)==null?void 0:w.steps)||12,G=(((Et=n.settings)==null?void 0:Et.speed)||1)*30,q=Math.floor(i.rotation/(360/U))*(360/U);i.rotation=this.lerp(i.rotation,q+G*t,.1)}else if(n.type===W.Jitter&&l<300){const U=((Xt=n.settings)==null?void 0:Xt.strength)||1,G=((($t=n.settings)==null?void 0:$t.intensity)||5)*U;i.x+=(Math.random()-.5)*G*t*60,i.y+=(Math.random()-.5)*G*t*60,i.rotation+=(Math.random()-.5)*G*t*120}else if(n.type===W.Follower){const U=(dt=n.settings)==null?void 0:dt.targetId;if(U){const G=this.objectStates.get(U);if(G){const q=((T=n.settings)==null?void 0:T.stiffness)||.1,wt=G.x-i.x,Rt=G.y-i.y;i.x+=wt*q*t*60,i.y+=Rt*q*t*60}}}else if(n.type===W.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===W.Gravity){const U=((X=n.settings)==null?void 0:X.strength)||9.8;i.y+=U*t*10}else if(n.type===W.Velocity){const U=((ut=n.settings)==null?void 0:ut.vx)||0,G=((E=n.settings)==null?void 0:E.vy)||0;i.x+=U*t*10,i.y+=G*t*10}else if(n.type===W.Shear){const U=((F=n.settings)==null?void 0:F.strength)||1,G=((et=n.settings)==null?void 0:et.radius)||300;if(l<G){const q=1-l/G;i.skew_x=this.lerp(i.skew_x||0,(((It=e.transform)==null?void 0:It.skew_x)||0)+q*U*30,.1)}else i.skew_x=this.lerp(i.skew_x||0,((Ot=e.transform)==null?void 0:Ot.skew_x)||0,.05)}else if(n.type===W.Lens){const U=((St=n.settings)==null?void 0:St.radius)||200,G=((Ft=n.settings)==null?void 0:Ft.strength)||.5;if(l<U){const q=Math.pow(1-l/U,2);i.scale_x=this.lerp(i.scale_x??1,(((Ct=e.transform)==null?void 0:Ct.scale_x)??1)*(1+q*G),.2),i.scale_y=this.lerp(i.scale_y??1,(((Gt=e.transform)==null?void 0:Gt.scale_y)??1)*(1+q*G),.2)}else i.scale_x=this.lerp(i.scale_x??1,((Jt=e.transform)==null?void 0:Jt.scale_x)??1,.1),i.scale_y=this.lerp(i.scale_y??1,((Qt=e.transform)==null?void 0:Qt.scale_y)??1,.1)}})})}applyBehaviorSensor(t,s,o,e,i,n){var c,p,l,f,g,d,u,m,y;const a=(i==null?void 0:i.intensity)||(i==null?void 0:i.strength)||1,r=o*a*e;switch(s){case Bt.Scale:t.scale_x*=1+r*.5,t.scale_y*=1+r*.5;break;case Bt.Opacity:t.opacity=Math.max(0,Math.min(100,t.opacity-r*100));break;case Bt.RotateZ:t.rotation+=r*180;break;case Bt.RotateX:t.rotate_x=(t.rotate_x||0)+r*180;break;case Bt.RotateY:t.rotate_y=(t.rotate_y||0)+r*180;break;case Bt.PositionX:t.x+=r*300;break;case Bt.PositionY:t.y+=r*300;break;case Bt.SkewX:t.skew_x=(t.skew_x||0)+r*45;break;case Bt.Blur:t.style||(t.style={...n.style}),t.style.blur||(t.style.blur={...(c=n.style)==null?void 0:c.blur}),t.style.blur.amount=(((l=(p=n.style)==null?void 0:p.blur)==null?void 0:l.amount)||0)+o*((i==null?void 0:i.blur)||50)*a;break;case Bt.Exposure:t.style||(t.style={...n.style}),t.style.adjustments||(t.style.adjustments={...(f=n.style)==null?void 0:f.adjustments}),t.style.adjustments.exposure=(((d=(g=n.style)==null?void 0:g.adjustments)==null?void 0:d.exposure)||0)+o*((i==null?void 0:i.exposure)||50)*a;break;case Bt.HueShift:t.style||(t.style={...n.style}),t.style.adjustments||(t.style.adjustments={...(u=n.style)==null?void 0:u.adjustments}),t.style.adjustments.hue=(((y=(m=n.style)==null?void 0:m.adjustments)==null?void 0:y.hue)||0)+o*((i==null?void 0:i.hue)||180)*a;break;case Bt.CornerRadius:t.corner_radius=Math.min(200,(t.corner_radius||0)+r*100);break;case Bt.LetterSpacing:t.geometry||(t.geometry={}),t.geometry.letterSpacing=(t.geometry.letterSpacing||0)+r*10;break}}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,c=s.naturalHeight,p=r/c,l=i/n;let f=i,g=n,d=o,u=e;a==="cover"?p>l?(f=n*p,d=o-(f-i)/2):(g=i/p,u=e-(g-n)/2):a==="contain"&&(p>l?(g=i/p,u=e+(n-g)/2):(f=n*p,d=o+(i-f)/2)),t.drawImage(s,d,u,f,g)}}const is=xt.forwardRef(({artboard:h,src:t,style:s,autoPlay:o=!0,fit:e="Contain",alignment:i="Center",onReady:n,onTrigger:a,onInputUpdate:r,onComponentChange:c,onToggle:p,onInputChange:l,onInputFocus:f,onInputBlur:g,onLog:d,onLogicUpdate:u,onButtonClick:m,onGraphPointClick:y,currentTime:S,revision:b=0,scrollY:v,scrollX:C,mouseX:k,mouseY:A,isMouseDown:x,inputs:B,interactive:R=!0,onNavigation:K},tt)=>{const rt=xt.useRef(null),at=xt.useRef(new ve),N=xt.useRef(void 0),O=xt.useRef(0),$=xt.useRef(null),P=xt.useRef(b),[,J]=xt.useState(h||null),j=xt.useRef(!0);xt.useImperativeHandle(tt,()=>rt.current),xt.useEffect(()=>(j.current=!0,()=>{j.current=!1,N.current&&cancelAnimationFrame(N.current)}),[]),xt.useEffect(()=>{at.current.setLayout(e,i)},[e,i]),xt.useEffect(()=>{const V=at.current;a&&V.setTriggerCallback(a),r&&V.setInputUpdateCallback((H,it)=>r({[H]:it})),c&&V.setComponentChangeCallback(H=>c(H)),p&&V.setToggleCallback(p),l&&V.setInputChangeCallback(l),f&&V.setInputFocusCallback(f),g&&V.setInputBlurCallback(g),d&&V.setOnLogCallback(H=>d(H,"info")),u&&V.setLogicUpdateCallback(u),m&&V.setButtonClickCallback(m),y&&V.setGraphPointClickCallback(H=>y(H.objectId,H)),K&&V.setNavigationCallback(K)},[a,r,c,p,l,f,g,d,u,m,y,K]),xt.useEffect(()=>{(async()=>{let H=h;if(t&&!h)try{t.startsWith("{")?H=JSON.parse(t):H=await(await fetch(t)).json()}catch(it){console.error("[ExodeUI] Failed to load src:",it)}if(H){const it=at.current,nt=H.id||H.name||"default";($.current!==nt||P.current!==b)&&(it.load(H),$.current=nt,P.current=b,J(H),O.current=0,it.advance(0)),n&&n(it)}})()},[h==null?void 0:h.id,t,b]),xt.useEffect(()=>{const V=H=>{if(!at.current||!j.current)return;const it=at.current,nt=rt.current;if(!nt)return;const ft=nt.getContext("2d");if(!ft)return;const M=H/1e3;O.current===0&&(O.current=M);let Q=M-O.current;Q>.1&&(Q=.1),O.current=M;const Y=nt.getBoundingClientRect(),L=window.devicePixelRatio||1,z=Math.round(Y.width*L),pt=Math.round(Y.height*L);(nt.width!==z||nt.height!==pt)&&(nt.width=z,nt.height=pt),o?it.advance(Q):S!==void 0&&it.seek(S),it.render(ft,nt.width,nt.height),N.current=requestAnimationFrame(V)};return N.current=requestAnimationFrame(V),()=>{N.current&&cancelAnimationFrame(N.current)}},[o,S]),xt.useEffect(()=>{const V=at.current;v!==void 0&&V.updateInput("scrollY",v),C!==void 0&&V.updateInput("scrollX",C),k!==void 0&&V.updateInput("mouseX",k),A!==void 0&&V.updateInput("mouseY",A),x!==void 0&&V.updateInput("isMouseDown",x),B&&Object.entries(B).forEach(([H,it])=>V.updateInput(H,it))},[v,C,k,A,x,B]);const lt=(V,H)=>{if(!R||!rt.current)return;const it=rt.current,nt=it.getBoundingClientRect(),ft=V.clientX-nt.left,M=V.clientY-nt.top,Q=window.devicePixelRatio||1;at.current.handlePointerInput(H,ft*Q,M*Q,it.width,it.height)};return Lt.jsx("canvas",{ref:rt,onPointerDown:V=>{var H;lt(V,"down"),(H=rt.current)==null||H.focus()},onPointerMove:V=>lt(V,"move"),onPointerUp:V=>lt(V,"up"),onPointerCancel:V=>lt(V,"up"),onClick:V=>lt(V,"click"),onWheel:V=>{at.current.handleWheel(V.deltaX,V.deltaY)},onKeyDown:V=>at.current.handleKeyDown(V.nativeEvent),onContextMenu:V=>V.preventDefault(),tabIndex:0,style:{...s,width:"100%",height:"100%",outline:"none",display:"block",touchAction:"none",pointerEvents:R?"auto":"none"}})});function ns(){const[h,t]=xt.useState(null),s=xt.useCallback((l,f)=>{h==null||h.setInputBool(l,f)},[h]),o=xt.useCallback((l,f)=>{h==null||h.setInputNumber(l,f)},[h]),e=xt.useCallback(l=>{h==null||h.fireTrigger(l)},[h]),i=xt.useCallback((l,f)=>{h==null||h.setInputText(l,f)},[h]),n=xt.useCallback((l,f)=>{h==null||h.setInputNumberArray(l,f)},[h]),a=xt.useCallback((l,f)=>{h==null||h.setInputStringArray(l,f)},[h]),r=xt.useCallback((l,f)=>{h==null||h.updateObjectOptions(l,f)},[h]),c=xt.useCallback((l,f,g)=>{h==null||h.updateConstraint(l,f,g)},[h]),p=xt.useCallback((l,f)=>{h==null||h.updateGraphData(l,f)},[h]);return{setEngine:t,engine:h,setInputBool:s,setInputNumber:o,fireTrigger:e,setInputText:i,setInputNumberArray:n,setInputStringArray:a,updateConstraint:c,updateGraphData:p,updateObjectOptions:r}}const os=({artboard:h,config:t})=>{const s={...h.seo,...t},o=s.enableSmartExtraction!==!1;xt.useEffect(()=>{const a=s.title||h.name;a&&(document.title=a);let r=s.description;if(!r&&o){const l=h.objects.filter(f=>{var g;return((g=f.geometry)==null?void 0:g.type)==="Text"}).sort((f,g)=>{var d,u;return(((d=g.geometry.text)==null?void 0:d.length)||0)-(((u=f.geometry.text)==null?void 0:u.length)||0)});l.length>0&&(r=l[0].geometry.text)}r&&(e("name","description",r),e("property","og:description",r)),s.keywords&&s.keywords.length>0&&e("name","keywords",s.keywords.join(", "));const c=s.ogImage||h.backgroundImage;c&&e("property","og:image",c),a&&e("property","og:title",a),e("property","og:type","website")},[s,h,o]);const e=(a,r,c)=>{let p=document.querySelector(`meta[${a}="${r}"]`);p||(p=document.createElement("meta"),p.setAttribute(a,r),document.head.appendChild(p)),p.setAttribute("content",c)},i=()=>{const a=[];return a.push(Lt.jsx("h1",{children:s.title||h.name},"artboard-title")),h.objects.forEach((c,p)=>{var l,f;if(!(!c.visible&&c.isVisible!==!0))if(((l=c.geometry)==null?void 0:l.type)==="Text"){const g=c.geometry.text;g&&(c.geometry.fontSize>24?a.push(Lt.jsx("h2",{children:g},c.id||p)):a.push(Lt.jsx("p",{children:g},c.id||p)))}else if(((f=c.geometry)==null?void 0:f.type)==="Image"){const g=c.geometry.src,d=c.altText||c.name||"Illustration";a.push(Lt.jsx("img",{src:g,alt:d},c.id||p))}else c.type==="Button"&&a.push(Lt.jsx("button",{children:c.name||"Button"},c.id||p))}),a},n=s.jsonLd||{"@context":"https://schema.org","@type":"VisualArtwork",name:s.title||h.name,description:s.description,image:s.ogImage||h.backgroundImage,abstract:"Animated interface created with ExodeUI"};return Lt.jsxs("div",{id:`exode-seo-${h.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(),Lt.jsx("script",{type:"application/ld+json",children:JSON.stringify(n)})]})},as={version:"6.3.13"}.version;At.BehaviorSensor=Bt,At.BehaviorType=W,At.ConditionOp=oe,At.ExodeSEO=os,At.ExodeUICanvas=is,At.ExodeUIEngine=ve,At.LogicOp=gt,At.VERSION=as,At.useExodeUI=ns,Object.defineProperty(At,Symbol.toStringTag,{value:"Module"})});
|
|
25
|
+
`&&M++),Q+=B})}else{if(e.fill){const M=t.globalAlpha,Q=this.createCanvasFill(t,e.fill,n,a);t.fillStyle=Q||e.fill.color||"#000000",t.globalAlpha=M*this.normalizeOpacity(e.fill.opacity??100);const N=K.fullText||(o.enableSegments?(o.segments||[]).map(pt=>{let vt=pt.text||"";const yt=pt.textCase||o.textCase||"none";return yt==="uppercase"?vt.toUpperCase():yt==="lowercase"?vt.toLowerCase():yt==="capitalize"?vt.replace(/\b\w/g,_t=>_t.toUpperCase()):vt}).join(""):l);let L=0,z=R;(tt||[]).forEach(pt=>{const vt=pt.text||"";let yt=-n/2;w==="center"?yt=0:w==="right"&&(yt=n/2),lt(vt,yt,z,!1,L),L+=vt.length,z+=B,L<N.length&&(N[L]===`
|
|
26
|
+
`||N[L]==="\r")&&(A>0&&(z+=A),L++,N[L-1]==="\r"&&N[L]===`
|
|
27
|
+
`&&L++)}),t.globalAlpha=M}if(e.stroke&&e.stroke.width>0){const M=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=M*this.normalizeOpacity(e.stroke.opacity??100);let N=0,L=R;(tt||[]).forEach(z=>{let pt=-n/2;w==="center"?pt=0:w==="right"&&(pt=n/2),lt(z.text,pt,L,!0,N),N+=(z.text||"").length,L+=B,N<l.length&&(l[N]===`
|
|
28
|
+
`||l[N]==="\r")&&(A>0&&(L+=A),N++,l[N-1]==="\r"&&l[N]===`
|
|
29
|
+
`&&N++)}),t.globalAlpha=M}}}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,c=(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 l=t.globalAlpha;t.globalAlpha=l*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 f=a.trimStart??0,g=a.trimEnd??1,u=a.trimOffset??0,p=a.dashOffset??0,m=a.dashArray||[];if(f!==0||g!==1||u!==0){const y=this.getPerimeter(o,e,i);if(y>0){const S=Math.max(0,Math.min(1,f)),b=Math.max(0,Math.min(1,g));if(S<b){const v=y*(b-S),w=y-v,k=-(y*(S+u%1));t.setLineDash([v,w]),t.lineDashOffset=k+p*y}else if(S===b)t.setLineDash([0,y]);else{const v=y*(1-S+b),w=y-v,k=-(y*S);t.setLineDash([v,w]),t.lineDashOffset=k+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()):c==="inside"?(t.lineWidth=r*2,t.save(),this.applyPath(t,o,e,i,n),t.clip(),t.stroke(),t.restore()):c==="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 c=n/360*r;if(a>0){const d=Math.PI*(3*(e*a+i*a)-Math.sqrt((3*e*a+i*a)*(e*a+3*i*a)));c+=n/360*d,n<360&&(c+=2*Math.sqrt((e-e*a)**2+(i-i*a)**2))}else n<360&&(c+=2*Math.max(e,i));return isNaN(c)?0:c}case"Line":return t.length||Math.sqrt(s*s+o*o);case"Triangle":return s+Math.sqrt((s/2)**2+o**2)*2;case"Polygon":{const e=t.sides||3,i=t.radius||Math.min(s,o)/2;return 2*e*i*Math.sin(Math.PI/e)}case"Star":{const e=t.points||5,i=t.outer_radius||Math.min(s,o)/2,n=t.inner_radius||i/2,a=Math.PI/e;return Math.sqrt(i*i+n*n-2*i*n*Math.cos(a))*e*2}case"Path":{const e=t.points||[];if(e.length<2)return t.length||0;let i=0,n=e[0].x,a=e[0].y;for(let r=1;r<e.length;r++){const c=e[r];if(c.moveTo){n=c.x,a=c.y;continue}const d=n,l=a,f=e[r-1].out_x,g=e[r-1].out_y;if(f!==void 0||c.in_x!==void 0?i+=this.getBezierLength(d,l,f??d,g??l,c.in_x??c.x,c.in_y??c.y,c.x,c.y):i+=Math.sqrt((c.x-d)**2+(c.y-l)**2),n=c.x,a=c.y,c.closePath||r===e.length-1&&(t.is_closed||t.isClosed)){const u=n,p=a,m=[...e.slice(0,r+1)].reverse().find(A=>A.moveTo)||e[0],y=m.x,S=m.y,b=e[r].out_x,v=e[r].out_y,w=m.in_x,k=m.in_y;b!==void 0||w!==void 0?i+=this.getBezierLength(u,p,b??u,v??p,w??y,k??S,y,S):i+=Math.sqrt((y-u)**2+(S-p)**2)}}return i}default:return(s+o)*2}}getBezierLength(t,s,o,e,i,n,a,r,c=10){let d=0,l=t,f=s;for(let g=1;g<=c;g++){const u=g/c,p=1-u,m=u*u,y=p*p,S=y*p,b=m*u,v=S*t+3*y*u*o+3*p*m*i+b*a,w=S*s+3*y*u*e+3*p*m*n+b*r,k=v-l,A=w-f;d+=Math.sqrt(k*k+A*A),l=v,f=w}return d}getBezierTAtLength(t,s,o,e,i,n,a,r,c,d=20){if(t<=0)return 0;let l=0,f=s,g=o;for(let u=1;u<=d;u++){const p=u/d,m=1-p,y=p*p,S=m*m,b=S*m,v=y*p,w=b*s+3*S*p*e+3*m*y*n+v*r,k=b*o+3*S*p*i+3*m*y*a+v*c,A=w-f,x=k-g,B=Math.sqrt(A*A+x*x);if(l+B>=t){const $=t-l,K=B===0?0:$/B;return(u-1+K)/d}l+=B,f=w,g=k}return 1}getPointOnPath(t,s,o,e){if(this.ensurePathPoints(t),(t==null?void 0:t.type)==="Path"){const i=t.points||[];if(i.length<2)return{x:0,y:0,angle:0};let n=1/0,a=-1/0,r=1/0,c=-1/0;i.forEach(S=>{typeof S.x=="number"&&typeof S.y=="number"&&(n=Math.min(n,S.x),a=Math.max(a,S.x),r=Math.min(r,S.y),c=Math.max(c,S.y),S.out_x!==void 0&&(n=Math.min(n,S.out_x),a=Math.max(a,S.out_x)),S.out_y!==void 0&&(r=Math.min(r,S.out_y),c=Math.max(c,S.out_y)),S.in_x!==void 0&&(n=Math.min(n,S.in_x),a=Math.max(a,S.in_x)),S.in_y!==void 0&&(r=Math.min(r,S.in_y),c=Math.max(c,S.in_y)))});const d=(n+a)/2,l=(r+c)/2,g=this.getPerimeter(t,s,o)*e;let u=0;const p=[];let m=i[0],y=i[0];for(let S=1;S<i.length;S++){const b=i[S];if(b.moveTo){m=b,y=b;continue}p.push({p0:m,p1:b}),(b.closePath||S===i.length-1&&(t.is_closed||t.isClosed))&&p.push({p0:b,p1:y}),m=b}for(const S of p){const b=S.p0,v=S.p1;let w=0;const k=b.out_x!==void 0||v.in_x!==void 0;if(k?w=this.getBezierLength(b.x,b.y,b.out_x??b.x,b.out_y??b.y,v.in_x??v.x,v.in_y??v.y,v.x,v.y):w=Math.sqrt((v.x-b.x)**2+(v.y-b.y)**2),u+w>=g||S===p[p.length-1]){let A=0;if(k)return A=this.getBezierTAtLength(g-u,b.x,b.y,b.out_x??b.x,b.out_y??b.y,v.in_x??v.x,v.in_y??v.y,v.x,v.y,20),this.getBezierPointAndAngle(A,b,v,d,l);{A=w===0?0:(g-u)/w;const x=b.x+(v.x-b.x)*A-d,B=b.y+(v.y-b.y)*A-l,$=Math.atan2(v.y-b.y,v.x-b.x);return{x,y:B,angle:$}}}u+=w}}else if(t.type==="Ellipse"){const i=Math.abs(s)/2,n=Math.abs(o)/2,a=t.sweepAngle??360,c=((t.startAngle??0)+a*e)*Math.PI/180,d=i*Math.cos(c),l=n*Math.sin(c),f=-i*Math.sin(c),g=n*Math.cos(c),u=Math.atan2(g,f);return{x:d,y:l,angle:u}}else if((t==null?void 0:t.type)==="Rectangle"){const i=Math.abs(s),n=Math.abs(o),r=(i+n)*2*e;let c=0,d=0,l=0;return r<i?(c=-i/2+r,d=-n/2,l=0):r<i+n?(c=i/2,d=-n/2+(r-i),l=Math.PI/2):r<2*i+n?(c=i/2-(r-(i+n)),d=n/2,l=Math.PI):(c=-i/2,d=n/2-(r-(2*i+n)),l=-Math.PI/2),{x:c,y:d,angle:l}}return{x:0,y:0,angle:0}}getBezierPointAndAngle(t,s,o,e,i){const n=s.x,a=s.y,r=s.out_x??s.x,c=s.out_y??s.y,d=o.in_x??o.x,l=o.in_y??o.y,f=o.x,g=o.y,u=1-t,p=t*t,m=u*u,y=m*u,S=p*t,b=y*n+3*m*t*r+3*u*p*d+S*f-e,v=y*a+3*m*t*c+3*u*p*l+S*g-i,w=3*m*(r-n)+6*u*t*(d-r)+3*p*(f-d),k=3*m*(c-a)+6*u*t*(l-c)+3*p*(g-l),A=Math.atan2(k,w);return{x:b,y:v,angle:A}}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 l;const a=s.artEffect||((l=s.style)==null?void 0:l.artEffect);if(!a||!a.enabled)return;const r=a.type,c=a.intensity??.5,d=a.speed??1;if(r==="acid_gradient"||r==="acid_rave"||r==="shimmer"||r==="halftone"||r==="noise"||r==="scanlines"||r==="chromatic_aberration"){if(t.save(),this.applyPath(t,o,e,i,n),t.clip(),r==="shimmer"){const g=this.currentTime*d%2/2,u=t.createLinearGradient(-e,-i,e,i);u.addColorStop(Math.max(0,g-.2),"rgba(255,255,255,0)"),u.addColorStop(g,`rgba(255,255,255,${c*.8})`),u.addColorStop(Math.min(1,g+.2),"rgba(255,255,255,0)"),t.fillStyle=u,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i)}else if(r==="acid_gradient"||r==="acid_rave"){const f=this.currentTime*d,g=t.createLinearGradient(-e/2,-i/2,e/2,i/2),u=f*100%360,p=(u+180)%360;g.addColorStop(0,`hsla(${u}, 80%, 50%, ${c*.5})`),g.addColorStop(1,`hsla(${p}, 80%, 50%, ${c*.5})`),t.fillStyle=g,t.globalCompositeOperation="screen",t.fillRect(-e/2,-i/2,e,i)}else if(r==="halftone"){const f=Math.max(2,20*(1-c)),g=document.createElement("canvas");g.width=f,g.height=f;const u=g.getContext("2d");if(u){u.fillStyle="black",u.beginPath(),u.arc(f/2,f/2,f/2*c,0,Math.PI*2),u.fill();const p=t.createPattern(g,"repeat");p&&(t.globalAlpha=.3*c,t.fillStyle=p,t.fillRect(-e/2,-i/2,e,i))}}else if(r==="noise"){t.globalAlpha=.1*c;for(let f=0;f<5;f++)t.fillStyle=`rgba(${Math.random()*255}, ${Math.random()*255}, ${Math.random()*255}, ${c})`,t.fillRect(-e/2+Math.random()*e,-i/2+Math.random()*i,2,2)}else if(r==="scanlines"){t.globalAlpha=.2*c,t.strokeStyle="rgba(0,0,0,0.5)",t.lineWidth=1;for(let f=-i/2;f<i/2;f+=4)t.beginPath(),t.moveTo(-e/2,f),t.lineTo(e/2,f),t.stroke()}else if(r==="chromatic_aberration"){const f=5*c;t.globalCompositeOperation="screen",t.globalAlpha=.5,t.fillStyle="cyan",t.fillRect(-e/2-f,-i/2,e,i),t.fillStyle="magenta",t.fillRect(-e/2+f,-i/2,e,i)}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,c=o/2,d=e/2,l=n*Math.PI/180,f=a*Math.PI/180,g=l+f;a>=360&&r<=0?t.ellipse(0,0,c,d,0,0,Math.PI*2):(t.ellipse(0,0,c,d,0,l,g,!1),r>0?t.ellipse(0,0,c*r,d*r,0,g,l,!0):t.lineTo(0,0),t.closePath())}else if(s.type==="Triangle")t.moveTo(0,-e/2),t.lineTo(o/2,e/2),t.lineTo(-o/2,e/2),t.closePath();else if(s.type==="Polygon"){const n=s.sides||3,a=s.radius||Math.min(o,e)/2;for(let r=0;r<n;r++){const c=r*2*Math.PI/n-Math.PI/2,d=a*Math.cos(c),l=a*Math.sin(c);r===0?t.moveTo(d,l):t.lineTo(d,l)}t.closePath()}else if(s.type==="Star"){const n=s.inner_radius||20,a=s.outer_radius||50,r=s.points||5;for(let c=0;c<r*2;c++){const d=c*Math.PI/r-Math.PI/2,l=c%2===0?a:n,f=l*Math.cos(d),g=l*Math.sin(d);c===0?t.moveTo(f,g):t.lineTo(f,g)}t.closePath()}else if(((s==null?void 0:s.type)==="Path"||s.type==="Subtract"||s.type==="Union"||s.type==="Intersect"||s.type==="Exclude"||s.type==="BooleanOperation")&&s.points){this.frameCount%10===0&&console.log("[Engine] Tracing Path:",s.points.length,"points");let n=1/0,a=-1/0,r=1/0,c=-1/0;if(s.points.forEach(f=>{typeof f.x=="number"&&typeof f.y=="number"&&(n=Math.min(n,f.x),a=Math.max(a,f.x),r=Math.min(r,f.y),c=Math.max(c,f.y),f.out_x!==void 0&&(n=Math.min(n,f.out_x),a=Math.max(a,f.out_x)),f.out_y!==void 0&&(r=Math.min(r,f.out_y),c=Math.max(c,f.out_y)),f.in_x!==void 0&&(n=Math.min(n,f.in_x),a=Math.max(a,f.in_x)),f.in_y!==void 0&&(r=Math.min(r,f.in_y),c=Math.max(c,f.in_y)))}),n===1/0)return;const d=(n+a)/2,l=(r+c)/2;if(isNaN(d)||isNaN(l)){console.warn("[Engine] Invalid path center:",d,l);return}s.points.forEach((f,g)=>{if(g===0||f.moveTo)t.moveTo(f.x-d,f.y-l);else{const u=s.points[g-1];if(!u)return;const p=(u.out_x??u.x)-d,m=(u.out_y??u.y)-l,y=(f.in_x??f.x)-d,S=(f.in_y??f.y)-l;isNaN(p)||isNaN(y)||isNaN(f.x)?t.lineTo(f.x-d,f.y-l):t.bezierCurveTo(p,m,y,S,f.x-d,f.y-l)}if(f.closePath||g===s.points.length-1&&(s.is_closed||s.isClosed)){const u=[...s.points.slice(0,g+1)].reverse().find(p=>p.moveTo)||s.points[0];u&&(f.out_x!==void 0||u.in_x!==void 0)&&t.bezierCurveTo((f.out_x??f.x)-d,(f.out_y??f.y)-l,(u.in_x??u.x)-d,(u.in_y??u.y)-l,u.x-d,u.y-l),t.closePath()}})}else if(s.points&&Array.isArray(s.points)){let n=1/0,a=-1/0,r=1/0,c=-1/0;s.points.forEach(f=>{n=Math.min(n,f.x),a=Math.max(a,f.x),r=Math.min(r,f.y),c=Math.max(c,f.y)});const d=(n+a)/2,l=(r+c)/2;s.points.forEach((f,g)=>{if(g===0)t.moveTo(f.x-d,f.y-l);else{const u=s.points[g-1];u.out_x!==void 0||f.in_x!==void 0?t.bezierCurveTo((u.out_x??u.x)-d,(u.out_y??u.y)-l,(f.in_x??f.x)-d,(f.in_y??f.y)-l,f.x-d,f.y-l):t.lineTo(f.x-d,f.y-l)}(f.closePath||g===s.points.length-1&&(s.is_closed||s.isClosed))&&t.closePath()})}}}renderInputBox(t,s){var M,Q;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((M=s.geometry)==null?void 0:M.width)||250,n=((Q=s.geometry)==null?void 0:Q.height)||45,a=this.focusedId===s.id,r=this.lastHoveredObjectId===s.id,c=e.previewState||"default",d=c!=="default"?c:a?"focused":r?"hovered":"default",l=e.label||{visible:!0,text:"Label"},f=e.helperText||{visible:!1,text:"Helper text"},g=e.leftIcon||{visible:!1},u=e.rightIcon||{visible:!1},p=e.multiline===!0,m=e.corner_radius??8,y=e.corners||{tl:m,tr:m,bl:m,br:m},S=[y.tl,y.tr,y.br,y.bl];let b=e.backgroundColor||"rgba(31, 41, 55, 1)",v=e.borderColor||"rgba(55, 65, 81, 1)",w=e.borderWidth??1.5,k=e.color||"#ffffff",A=e.placeholderColor||"rgba(156, 163, 175, 1)",x=e.fontSize||14;const B=`${d}Style`,$=e[B];$?($.backgroundColor!==void 0&&(b=$.backgroundColor),$.borderColor!==void 0&&(v=$.borderColor),$.borderWidth!==void 0&&(w=$.borderWidth),$.color!==void 0&&(k=$.color),$.placeholderColor!==void 0&&(A=$.placeholderColor),$.fontSize!==void 0&&(x=$.fontSize)):d==="focused"?(v=e.focusBorderColor||"rgba(59, 130, 246, 1)",w=Math.max(w,2)):d==="hovered"||d==="hover"?(v=e.hoverBorderColor||v,b=e.hoverBackgroundColor||b):d==="disabled"?(b=e.disabledBackgroundColor||"rgba(31, 41, 55, 0.6)",v=e.disabledBorderColor||"rgba(55, 65, 81, 0.4)"):d==="error"&&(v="rgba(239, 68, 68, 1)",w=Math.max(w,2)),t.beginPath(),this.drawRoundRect(t,-i/2,-n/2,i,n,S);const K=this.createCanvasFill(t,b,i,n);if(K&&(t.fillStyle=K,t.fill()),w>0){const N=this.createCanvasFill(t,v,i,n);if(N&&(t.strokeStyle=N,t.lineWidth=w,t.stroke()),d==="focused"||d==="focus"){t.save(),t.beginPath();const L=S.map(z=>z+2);this.drawRoundRect(t,-i/2-2,-n/2-2,i+4,n+4,L),t.strokeStyle="rgba(59, 130, 246, 0.3)",t.lineWidth=2,t.stroke(),t.restore()}}const tt=(N,L)=>{if(!N.visible||!N.svgPath)return;const z=N.size||14,pt=N.offset??16,vt=N.color||"#ffffff",yt=L?-(i/2)+pt:i/2-pt,_t=N.svgPath;if(t.save(),t.translate(yt,0),!_t.startsWith("<svg")){const kt=new Path2D(_t),Tt=z/24;t.scale(Tt,Tt),t.translate(-12,-12),t.fillStyle=vt,t.fill(kt)}t.restore()};tt(g,!0),tt(u,!1);const rt=e.text||"",at=e.placeholder||"Enter text...",V=!rt,O=rt||at,R=V?A:k,P=x,J=e.fontFamily||"Inter",j=e.fontWeight||400;t.font=`${j} ${P}px "${J}", sans-serif`,t.fillStyle=R,t.textAlign="left",t.textBaseline=p?"top":"middle";const lt=e.inputPadding??16,Y=g.visible?(g.offset??16)+(g.size||14)/2+8:lt,H=u.visible?(u.offset??16)+(u.size||14)/2+8:lt,it=-(i/2)+Y,nt=i-Y-H,ft=e.inputType==="password"?"•".repeat(O.length):O;if(t.save(),t.beginPath(),t.rect(it-2,-n/2+4,nt+4,n-8),t.clip(),p){const N=ft.split(`
|
|
30
|
+
`);let L=-n/2+lt;const z=P*1.2;let pt=0;N.forEach((vt,yt)=>{const _t=vt.split(" ");let kt="";for(let Tt=0;Tt<_t.length;Tt++){const Wt=kt+_t[Tt]+" ";t.measureText(Wt).width>nt&&Tt>0?(t.fillText(kt,it,L),kt=_t[Tt]+" ",L+=z):kt=Wt}t.fillText(kt,it,L),pt=t.measureText(kt).width,yt<N.length-1&&(L+=z,pt=0)}),a&&!V&&Math.floor(performance.now()/500)%2===0&&t.fillRect(it+pt,L,1.5,P)}else{const L=t.measureText(ft).width;let z=0;if(L>nt&&(z=L-nt),t.fillText(ft,it-z,0),a&&!V&&Math.floor(performance.now()/500)%2===0){const vt=it+L-z;t.fillRect(vt,-(P/2),1.5,P)}}if(t.restore(),l.visible!==!1){const N=l.text||"Label",L=l.fontSize||12,z=l.color||"rgba(156, 163, 175, 1)",pt=l.offset??8;t.font=`600 ${L}px "${J}", sans-serif`,t.fillStyle=z,t.textAlign="left",t.textBaseline="bottom";const vt=-(i/2),yt=-(n/2)-pt;t.fillText(N,vt,yt)}if(f.visible===!0){const N=f.text||"Helper text",L=f.fontSize||11,z=d==="error"?"rgba(239, 68, 68, 1)":f.color||"rgba(156, 163, 175, 1)",pt=f.offset??6;t.font=`400 ${L}px "${J}", sans-serif`,t.fillStyle=z,t.textAlign="left",t.textBaseline="top";const vt=-(i/2),yt=n/2+pt;t.fillText(N,vt,yt)}}renderSlider(t,s){const o=this.objectStates.get(s.id),e=(o==null?void 0:o.geometry)||s.geometry,i=(o==null?void 0:o.options)||s.options||{},n=e.width||200,a=i.value??50,r=i.min??0,d=(i.max??100)-r,l=d===0?0:(a-r)/d,f=i.trackHeight||4,g=i.trackRoundedness??2,u=i.trackShape??"Rectangle",p=i.trackPath||"",m=i.accentColor||"#3b82f6",y=i.inactiveColor||"#374151",S=i.thumbShape||"Ellipse",b=i.thumbWidth??16,v=i.thumbHeight??16,w=i.thumbRoundedness??0,k=i.thumbColor||"#ffffff",A=i.thumbPath||"",x=i.thumbIcon||"",B=i.showValueTooltip??!1,$=i.tooltipBgColor||"#333333",K=i.tooltipColor||"#ffffff",tt=i.tooltipOffsetX??0,rt=i.tooltipOffsetY??-25,at=(nt,ft,M,Q,N,L,z)=>{if((nt==="Custom"||nt==="Icon")&&z)try{const pt=new Path2D(z);if(t.save(),t.translate(ft,M),nt==="Icon"){const vt=Math.min(Q,N)/24;t.scale(vt,vt),t.translate(-12,-12)}t.fill(pt),t.restore();return}catch(pt){console.error("Error drawing slider shape in engine:",pt)}if(t.beginPath(),nt==="Ellipse")t.ellipse(ft,M,Q/2,N/2,0,0,Math.PI*2);else if(nt==="Rectangle")this.drawRoundRect(t,ft-Q/2,M-N/2,Q,N,L);else if(nt==="Triangle")t.moveTo(ft,M-N/2),t.lineTo(ft+Q/2,M+N/2),t.lineTo(ft-Q/2,M+N/2),t.closePath();else if(nt==="Diamond")t.moveTo(ft,M-N/2),t.lineTo(ft+Q/2,M),t.lineTo(ft,M+N/2),t.lineTo(ft-Q/2,M),t.closePath();else if(nt==="Polygon"){const pt=s.geometry.sides||3,vt=s.geometry.radius||Math.min(Q,N)/2;for(let yt=0;yt<pt;yt++){const _t=yt*2*Math.PI/pt-Math.PI/2,kt=ft+vt*Math.cos(_t),Tt=M+vt*Math.sin(_t);yt===0?t.moveTo(kt,Tt):t.lineTo(kt,Tt)}t.closePath()}else if(nt==="Star"){const vt=Math.min(Q,N)/2,yt=vt/2;for(let _t=0;_t<5*2;_t++){const kt=_t%2===0?vt:yt,Tt=_t*Math.PI/5-Math.PI/2;t.lineTo(ft+kt*Math.cos(Tt),M+kt*Math.sin(Tt))}t.closePath()}else nt==="Line"&&(t.moveTo(ft-Q/2,M),t.lineTo(ft+Q/2,M));t.fill()},V=this.createCanvasFill(t,y,n,f);V&&(t.fillStyle=V,t.strokeStyle=V),u==="Line"?(t.lineWidth=f,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(n/2,0),t.stroke()):at(u,0,0,n,f,g,p);const O=n-b,R=-n/2+b/2+l*O,P=R- -n/2;if(P>0){const nt=this.createCanvasFill(t,m,n,f);nt&&(t.fillStyle=nt,t.strokeStyle=nt),u==="Line"?(t.lineWidth=f,t.beginPath(),t.moveTo(-n/2,0),t.lineTo(R,0),t.stroke()):u==="Rectangle"&&(t.beginPath(),this.drawRoundRect(t,-n/2,-f/2,P,f,g),t.fill())}t.save(),t.translate(R,0);const J=t.getTransform(),j=Math.sqrt(J.a*J.a+J.b*J.b)||1;t.shadowColor="rgba(0,0,0,0.2)",t.shadowBlur=4*j,t.shadowOffsetY=1*j;const lt=this.createCanvasFill(t,k,b,v);if(lt&&(t.fillStyle=lt),at(S,0,0,b,v,w,S==="Icon"?x:A),t.restore(),B){t.save(),t.translate(R+tt,rt);const nt=Math.round(a).toString();t.font="10px Inter, sans-serif";const ft=t.measureText(nt),M=6,Q=4,N=ft.width+M*2,L=14+Q;t.beginPath(),this.drawRoundRect(t,-N/2,-L/2,N,L,4),t.fillStyle=$,t.fill(),t.fillStyle=K,t.textAlign="center",t.textBaseline="middle",t.fillText(nt,0,0),t.restore()}const Y=i.label||{},H=i.helperText||{},it=i.fontFamily||"Inter";if(Y.visible!==!1){const nt=Y.text||"Label",ft=Y.fontSize||12,M=Y.color||"rgba(156, 163, 175, 1)",Q=Y.offset??8;t.font=`600 ${ft}px "${it}", sans-serif`,t.fillStyle=M,t.textAlign="left",t.textBaseline="bottom";const N=-(n/2),L=-(f/2)-Q;t.fillText(nt,N,L)}if(H.visible===!0){const nt=H.text||"Helper text",ft=H.fontSize||11,M=H.color||"rgba(156, 163, 175, 1)",Q=H.offset??6;t.font=`400 ${ft}px "${it}", sans-serif`,t.fillStyle=M,t.textAlign="left",t.textBaseline="top";const N=-(n/2),L=f/2+Q;t.fillText(nt,N,L)}}renderDropdown(t,s){var rt;const o=this.objectStates.get(s.id);if(!o)return;const e=o.options||s.options||{},i=s.geometry.width||160,n=s.geometry.height||40,a=-i/2,r=-n/2,c=e.corner_radius??6,d=e.disabled||e.previewState==="disabled",l=this.lastHoveredObjectId===s.id||e.previewState==="hover",f=(e.isOpen||e.previewState==="active")&&!d;let g=e.backgroundColor,u=e.borderColor,p=e.color||"#333333";d?(g=e.disabledBackgroundColor||"#f3f4f6",u=e.disabledBorderColor||"#e5e7eb",p=e.disabledColor||"#9ca3af"):f?(g=e.activeBackgroundColor||g,u=e.activeBorderColor||u,p=e.activeColor||p):l&&(g=e.hoverBackgroundColor||g,u=e.hoverBorderColor||u,p=e.hoverColor||p),g||(g="#ffffff"),u||(u="#e5e7eb");const m=t.globalAlpha;t.globalAlpha=m*(e.opacity??1),this.drawRoundRect(t,a,r,i,n,c),t.fillStyle=this.createCanvasFill(t,typeof g=="string"?{type:"Solid",color:g}:g,i,n)||"#ffffff",t.fill();const y=e.borderWidth??1;y>0&&(t.strokeStyle=this.createCanvasFill(t,typeof u=="string"?{type:"Solid",color:u}:u,i,n)||"#e5e7eb",t.lineWidth=y,t.stroke());const S=12,b=e.chevronType||"chevron",v=e.chevronSize||16,w=(f?e.openIconColor:e.closedIconColor)||e.chevronColor||"#6b7280";if(b!=="none"){const at=a+i-S-v/2;t.save(),t.translate(at,0);const V=f?e.openIconAngle??180:e.closedIconAngle??0;if(t.rotate(V*Math.PI/180),t.strokeStyle=w,t.fillStyle=w,t.lineWidth=1.5,t.lineCap="round",t.lineJoin="round",b==="chevron")t.beginPath(),t.moveTo(-v/2,-v*.2),t.lineTo(0,v*.2),t.lineTo(v/2,-v*.2),t.stroke();else if(b==="custom"||b==="path"){const O=f&&e.openIconPath||e.closedIconPath;if(O){const R=new Path2D(O);t.save();const P=v/24;t.scale(P,P),t.translate(-12,-12),t.fill(R),t.restore()}}t.restore()}const k=e.selectedOption||e.placeholder||"Select...",A=e.fontSize||14,x=e.fontWeight||400,B=e.fontFamily||"Inter, sans-serif";t.font=`${x} ${A}px ${B}`;const $=d?e.disabledColor||"#9ca3af":!e.selectedOption&&e.placeholder?"#9ca3af":p;t.fillStyle=this.createCanvasFill(t,typeof $=="string"?{type:"Solid",color:$}:$,i,n)||"#333333",t.textAlign="left",t.textBaseline="middle";const K=b==="none"?0:v+8,tt=i-S*2-K;if(t.save(),t.beginPath(),t.rect(a+S,r,tt,n),t.clip(),t.fillText(k,a+S,0),t.restore(),f&&!d){const at=r+n+4,V=e.optionsList||[],O=e.itemHeight||32,R=e.listPadding??4,P=V.length*O+R*2,J=e.listCornerRadius??c;t.save();const j=e.listShadow||{},lt=t.getTransform(),Y=Math.sqrt(lt.a*lt.a+lt.b*lt.b)||1;t.shadowColor=typeof j.color=="string"?j.color:((rt=j.color)==null?void 0:rt.color)||"rgba(0,0,0,0.15)",t.shadowBlur=(j.blur??12)*Y,t.shadowOffsetY=(j.offsetY??6)*Y,t.shadowOffsetX=(j.offsetX??0)*Y,t.beginPath(),this.drawRoundRect(t,a,at,i,P,J),t.fillStyle=this.createCanvasFill(t,typeof e.listBackgroundColor=="string"?{type:"Solid",color:e.listBackgroundColor}:e.listBackgroundColor||{type:"Solid",color:"#ffffff"},i,P)||"#ffffff",t.fill();const H=e.listBorderWidth??1;H>0&&(t.shadowColor="transparent",t.strokeStyle=this.createCanvasFill(t,typeof e.listBorderColor=="string"?{type:"Solid",color:e.listBorderColor}:e.listBorderColor||{type:"Solid",color:u},i,P)||"#e5e7eb",t.lineWidth=H,t.stroke()),t.restore();const it=e.itemFontSize||A,nt=e.itemFontFamily||B;t.font=`${x} ${it}px ${nt}`,V.forEach((ft,M)=>{const Q=at+R+M*O;if(ft===e.selectedOption)t.fillStyle=this.createCanvasFill(t,typeof e.itemSelectedBackgroundColor=="string"?{type:"Solid",color:e.itemSelectedBackgroundColor}:e.itemSelectedBackgroundColor||{type:"Solid",color:"#f3f4f6"},i,O)||"#f3f4f6",t.fillRect(a+H,Q,i-H*2,O),t.fillStyle=e.itemSelectedColor||e.accentColor||p||"#374151";else if(t.fillStyle=e.listTextColor||p||"#333333",this.activeDropdownId===s.id&&this._lastPointerPos){const L=this._lastPointerPos.y-(at+R),z=Math.floor(L/O);M===z&&(t.fillStyle=this.createCanvasFill(t,typeof e.itemHoverBackgroundColor=="string"?{type:"Solid",color:e.itemHoverBackgroundColor}:e.itemHoverBackgroundColor||{type:"Solid",color:"#f9fafb"},i,O)||"#f9fafb",t.fillRect(a+H,Q,i-H*2,O),t.fillStyle=e.itemHoverColor||p)}t.fillText(ft,a+S,Q+O/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,c=this.activeObjectId===s.id,d=e.label||{},l=e.hoverStyle||{},f=e.activeStyle||{},g=e.icon||{enabled:!1};let u=e.backgroundColor||"#3b82f6",p=d.color||"#ffffff",m=d.text||"Button",y=i.cornerRadius??8,S=e.borderColor||"transparent",b=e.borderWidth||0,v=1;c&&f?(u=f.backgroundColor||u,p=f.color||p,m=f.text||m,v=f.scale??.95,y=f.cornerRadius??y):r&&l&&(u=l.backgroundColor||u,p=l.color||p,m=l.text||m,v=l.scale??1,y=l.cornerRadius??y,S=l.borderColor||S);const w=-n/2,k=-a/2;t.save(),t.scale(v,v),t.beginPath(),this.drawRoundRect(t,w,k,n,a,y);const A=this.createCanvasFill(t,u,n,a);A&&(t.fillStyle=A,t.fill()),(b>0||r&&l.borderColor)&&(t.strokeStyle=S,t.lineWidth=b||(r?1:0),t.stroke());const x=d.fontSize||14,B=d.fontFamily||"Inter",$=d.fontWeight||600;t.font=`${$} ${x}px "${B}", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif`,t.fillStyle=p,t.textAlign="center",t.textBaseline="middle";let K=0;if(g.enabled&&g.svgPath){const tt=x*1.1,rt=g.gap||8,at=t.measureText(m),O=-(at.width+tt+rt)/2,R=g.position==="left"?O+tt/2:O+at.width+rt+tt/2;K=g.position==="left"?O+tt+rt+at.width/2:O+at.width/2,t.save(),t.translate(R,0);const P=new Path2D(g.svgPath),J=tt/24;t.scale(J,J),t.translate(-12,-12),t.fillStyle=p,t.fill(P),t.restore()}t.fillText(m,K,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,c=-a/2,d=e.corner_radius??8,l=e.label||{},f=i?e.accentColor||"#3b82f6":e.inactiveColor||"#374151",g=i?e.activeTextColor||"#ffffff":e.inactiveTextColor||"#9ca3af";t.save(),t.beginPath(),this.drawRoundRect(t,r,c,n,a,d),t.fillStyle=f,t.fill();const u=l.fontSize||14,p=l.fontFamily||"Inter";t.font=`${l.fontWeight||600} ${u}px "${p}", sans-serif`,t.fillStyle=g,t.textAlign="center",t.textBaseline="middle",t.fillText(l.text||"Toggle",0,0),t.restore()}renderToggle(t,s){var J,j,lt,Y,H,it,nt,ft,M,Q,N,L;const o=this.objectStates.get(s.id),e=(o==null?void 0:o.options)||s.options||{},i=((J=s.geometry)==null?void 0:J.width)||52,n=((j=s.geometry)==null?void 0:j.height)||30,a=-i/2,r=-n/2,c=e.checked??!1,d=e.cornerRadius??e.corner_radius??n/2,l=e.toggleStyle||{},f=l.backgroundColor||e.activeColor||"#10b981",g=l.borderColor||e.borderColor||"transparent",u=l.borderWidth??e.borderWidth??0,p=l.knobColor||e.knobColor||"#ffffff",m=c?f:e.inactiveColor||"#374151",y=c?g:e.borderColor||"transparent",S=c?u:e.borderWidth??0,b=c?p:e.knobColor||"#ffffff";e.disabled&&(t.globalAlpha*=.5),t.beginPath(),this.drawRoundRect(t,a,r,i,n,d);const v=this.createCanvasFill(t,m,i,n);if(v&&(t.fillStyle=v,t.fill()),S>0){t.lineWidth=S;const z=this.createCanvasFill(t,y,i,n);z&&(t.strokeStyle=z,t.stroke())}const w=2,k=n-w*2,A=k/2,x=a+w,B=a+i-w-k,$=c?B:x,K=r+w;t.beginPath(),t.arc($+A,K+A,A,0,Math.PI*2);const tt=this.createCanvasFill(t,b,k,k);tt&&(t.fillStyle=tt,t.fill()),e.disabled&&(t.globalAlpha*=2);let rt=!1,at=!1;const V=(c?(lt=l.leftLabel)==null?void 0:lt.text:null)||((Y=e.leftLabel)==null?void 0:Y.text)||"",O=(c?(H=l.leftLabel)==null?void 0:H.color:null)||((it=e.leftLabel)==null?void 0:it.color)||"#f3f4f6";if((nt=e.leftLabel)!=null&&nt.enabled&&V){const z=e.leftLabel;t.font=`${z.fontWeight||400} ${z.fontSize||12}px "${z.fontFamily||"Inter"}", sans-serif`,t.fillStyle=O,t.textBaseline="middle",t.textAlign="right",t.fillText(V,a-(z.gap||8),0),rt=!0}const R=(c?(ft=l.rightLabel)==null?void 0:ft.text:null)||((M=e.rightLabel)==null?void 0:M.text)||"",P=(c?(Q=l.rightLabel)==null?void 0:Q.color:null)||((N=e.rightLabel)==null?void 0:N.color)||"#f3f4f6";if((L=e.rightLabel)!=null&&L.enabled&&R){const z=e.rightLabel;t.font=`${z.fontWeight||400} ${z.fontSize||12}px "${z.fontFamily||"Inter"}", sans-serif`,t.fillStyle=P,t.textBaseline="middle",t.textAlign="left",t.fillText(R,a+i+(z.gap||8),0),at=!0}if(!rt&&!at&&e.label&&e.label.text){const z=e.label,pt=z.fontSize||14,vt=z.fontWeight||400,yt=z.fontFamily||"Inter";t.font=`${vt} ${pt}px "${yt}", sans-serif`,t.fillStyle=z.color||"#f3f4f6",t.textBaseline="middle";const _t=z.gap||10;let kt=0,Tt=0;z.position==="left"?(t.textAlign="right",kt=a-_t,Tt=0):z.position==="right"?(t.textAlign="left",kt=a+i+_t,Tt=0):z.position==="top"?(t.textAlign="center",kt=0,Tt=r-_t,t.textBaseline="bottom"):z.position==="bottom"?(t.textAlign="center",kt=0,Tt=r+n+_t,t.textBaseline="top"):(t.textAlign="left",kt=a+i+_t,Tt=0),t.fillText(z.text,kt,Tt)}}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 S=this.inputNameMap.get(p.inputId);S&&S.length>0&&(y=this.inputs.get(S[0]))}y&&Array.isArray(y)&&(m=y)}if(m&&m.length>0){const y=m.filter(S=>typeof S=="number"&&!isNaN(S));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 c=a-n,d=o/(r-1),l=p=>{const m=c===0?.5:(p-n)/c;return e/2-m*e},f=p=>p*d-o/2,g=s.axisColor||"#333333";if(s.showXAxis&&(t.beginPath(),t.strokeStyle=s.xAxisColor||g,t.lineWidth=1,t.moveTo(-o/2,e/2),t.lineTo(o/2,e/2),t.stroke()),s.showYAxis&&(t.beginPath(),t.strokeStyle=s.yAxisColor||g,t.lineWidth=1,t.moveTo(-o/2,-e/2),t.lineTo(-o/2,e/2),t.stroke()),t.fillStyle=s.axisLabelColor||"#333333",t.font=`${s.axisLabelFontSize||10}px Inter, sans-serif`,s.showXLabels){t.textAlign="center",t.textBaseline="top";for(let p=0;p<r;p++){const m=f(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,l(a)),t.fillText(m.toFixed(1),p,l(m)),t.fillText(n.toFixed(1),p,l(n))}const u=10;if(i.forEach(p=>{const m=p._resolvedData;if(!(!m||m.length<2)){if(p.showArea){if(t.beginPath(),t.moveTo(f(0),e/2),t.lineTo(f(0),l(m[0])),p.smoothing&&m.length>2)for(let S=0;S<m.length-1;S++){const b=m[S===0?S:S-1],v=m[S],w=m[S+1],k=m[S+1===m.length-1?S+1:S+2];for(let A=1;A<=u;A++){const x=A/u,B=this._catmullRom(b,v,w,k,x);t.lineTo(f(S+x),l(B))}}else for(let S=1;S<m.length;S++)t.lineTo(f(S),l(m[S]));t.lineTo(f(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(f(0),l(m[0])),p.smoothing&&m.length>2)for(let y=0;y<m.length-1;y++){const S=m[y===0?y:y-1],b=m[y],v=m[y+1],w=m[y+1===m.length-1?y+1:y+2];for(let k=1;k<=u;k++){const A=k/u,x=this._catmullRom(S,b,v,w,A);t.lineTo(f(y+A),l(x))}}else for(let y=1;y<m.length;y++)t.lineTo(f(y),l(m[y]));t.stroke(),p.showPoints&&m.forEach((y,S)=>{const b=f(S),v=l(y);t.beginPath(),t.arc(b,v,(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,S=y+5;t.font=`${y}px Inter, sans-serif`,t.textAlign="right",t.textBaseline="alphabetic",i.forEach(b=>{const w=b.label||"Series",k=t.measureText(w).width;t.beginPath(),t.rect(p-k-8-5,m-(8/2+2),8,8),t.fillStyle=b.lineColor||"#3b82f6",t.fill(),t.fillStyle=s.legendColor||"#333333",t.fillText(w,p,m),m+=S})}}_catmullRom(t,s,o,e,i){const n=(o-t)*.5,a=(e-s)*.5,r=i*i,c=i*r;return(2*s-2*o+n+a)*c+(-3*s+3*o-2*n-a)*r+n*i+s}normalizeOpacity(t){const s=typeof t=="number"?t:parseFloat(String(t));return isNaN(s)?1:s>1?Math.min(1,s/100):Math.max(0,Math.min(1,s))}createCanvasFill(t,s,o,e){var i,n,a;if(!s||s.type==="None")return null;if(typeof s=="string")return s;if(s.type==="Solid"&&s.color){const r=s.color,d=(((n=(i=this.artboard)==null?void 0:i.tokens)==null?void 0:n.colors)||{})[r]||r;return t.fillStyle=d,d}if((s.type==="LinearGradient"||s.type==="RadialGradient"||s.type==="AngularGradient"||s.type==="DiamondGradient")&&s.stops){const r=(c,d=100)=>{var v,w;const f=(((w=(v=this.artboard)==null?void 0:v.tokens)==null?void 0:w.colors)||{})[c]||c,g=this.normalizeOpacity(s.opacity??100),p=this.normalizeOpacity(d)*g;if(p>=1&&f.startsWith("#"))return f;const m=f.startsWith("#")?f.replace("#",""):"ffffff",y=parseInt(m.substring(0,2),16),S=parseInt(m.substring(2,4),16),b=parseInt(m.substring(4,6),16);return`rgba(${y}, ${S}, ${b}, ${p})`};if(s.type==="LinearGradient"){const c=(p,m,y)=>Array.isArray(p)?p[m]??(m===0?0:1):p&&typeof p=="object"?p[y]??(m===0?0:1):m===0?0:1,d=c(s.start,0,"x")*o-o/2,l=c(s.start,1,"y")*e-e/2,f=c(s.end,0,"x")*o-o/2,g=c(s.end,1,"y")*e-e/2,u=t.createLinearGradient(d,l,f,g);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);u.addColorStop(Math.max(0,Math.min(1,m)),y)}),s.gradientTransform&&u.setTransform){const[p,m,y,S,b,v]=s.gradientTransform;u.setTransform({a:p,b:m,c:y,d:S,e:b,f:v})}return u}else if(s.type==="RadialGradient"){const c=(u,p,m)=>Array.isArray(u)?u[p]??.5:u&&typeof u=="object"?u[m]??.5:.5,d=c(s.center,0,"x")*o-o/2,l=c(s.center,1,"y")*e-e/2,f=(s.radius??.5)*Math.max(o,e),g=t.createRadialGradient(d,l,0,d,l,f);if(s.stops.forEach(u=>{const p=u.offset!==void 0?u.offset:u.pos!==void 0?u.pos:u.position!==void 0?u.position:0,m=r(u.color||"#000000",u.opacity??100);g.addColorStop(Math.max(0,Math.min(1,p)),m)}),s.gradientTransform&&g.setTransform){const[u,p,m,y,S,b]=s.gradientTransform;g.setTransform({a:u,b:p,c:m,d:y,e:S,f:b})}return g}else if(s.type==="AngularGradient"){const c=(u,p,m)=>Array.isArray(u)?u[p]??.5:u&&typeof u=="object"?u[m]??.5:.5,d=c(s.center||[.5,.5],0,"x")*o-o/2,l=c(s.center||[.5,.5],1,"y")*e-e/2,f=(s.degree||s.angle||0)*(Math.PI/180),g=(a=t.createConicGradient)==null?void 0:a.call(t,f,d,l);if(g){if(s.stops.forEach(u=>{const p=u.offset!==void 0?u.offset:u.pos!==void 0?u.pos:u.position!==void 0?u.position:0,m=r(u.color||"#000000",u.opacity??100);g.addColorStop(Math.max(0,Math.min(1,p)),m)}),s.gradientTransform&&g.setTransform){const[u,p,m,y,S,b]=s.gradientTransform;g.setTransform({a:u,b:p,c:m,d:y,e:S,f:b})}return g}}else if(s.type==="DiamondGradient"){const c=(u,p,m)=>Array.isArray(u)?u[p]??.5:u&&typeof u=="object"?u[m]??.5:.5,d=c(s.center||[.5,.5],0,"x")*o-o/2,l=c(s.center||[.5,.5],1,"y")*e-e/2,f=(s.radius??.5)*Math.max(o,e);t.save(),t.translate(d,l),t.rotate(Math.PI/4);const g=t.createRadialGradient(0,0,0,0,0,f);if(s.stops.forEach(u=>{const p=u.offset!==void 0?u.offset:u.pos!==void 0?u.pos:u.position!==void 0?u.position:0,m=r(u.color||"#000000",u.opacity??100);g.addColorStop(Math.max(0,Math.min(1,p)),m)}),s.gradientTransform&&g.setTransform){const[u,p,m,y,S,b]=s.gradientTransform;g.setTransform({a:u,b:p,c:m,d:y,e:S,f:b})}return t.scale(1/Math.SQRT2,1/Math.SQRT2),t.fillStyle=g,t.restore(),g}}if(s.type==="Pattern"&&s.url){let r=this.imageCache.get(s.url);if(r||(r=new Image,r.src=s.url,this.imageCache.set(s.url,r)),r.complete&&r.naturalWidth>0){const c=t.createPattern(r,"repeat");if(c&&(s.scaleX!==void 0||s.offsetX!==void 0)){const d=new DOMMatrix,l=s.scaleX??1,f=s.scaleY??1,g=s.offsetX??0,u=s.offsetY??0,p=s.rotation??0;d.translateSelf(g,u),d.rotateSelf(p),d.scaleSelf(l,f),c.setTransform(d)}return c}}return s.color||null}drawRoundRect(t,s,o,e,i,n){if(n===0||n===void 0||n===null){t.rect(s,o,e,i);return}let a=n;if(typeof a=="string")try{a=JSON.parse(a)}catch{a=parseFloat(a)||0}let r=0,c=0,d=0,l=0;typeof a=="number"?r=c=d=l=a:Array.isArray(a)?a.length===1?r=c=d=l=a[0]:a.length===2?(r=d=a[0],c=l=a[1]):a.length===3?(r=a[0],c=l=a[1],d=a[2]):a.length>=4&&(r=a[0],c=a[1],d=a[2],l=a[3]):a&&typeof a=="object"&&(r=a.tl??a.corner_radius??a.cornerRadius??0,c=a.tr??a.corner_radius??a.cornerRadius??0,d=a.br??a.corner_radius??a.cornerRadius??0,l=a.bl??a.corner_radius??a.cornerRadius??0);const f=Math.min(Math.abs(e)/2,Math.abs(i)/2);if(r=Math.min(Math.max(0,r),f),c=Math.min(Math.max(0,c),f),d=Math.min(Math.max(0,d),f),l=Math.min(Math.max(0,l),f),t.roundRect){t.roundRect(s,o,e,i,[r,c,d,l]);return}t.moveTo(s+r,o),t.lineTo(s+e-c,o),t.arcTo(s+e,o,s+e,o+c,c),t.lineTo(s+e,o+i-d),t.arcTo(s+e,o+i,s+e-d,o+i,d),t.lineTo(s+l,o+i),t.arcTo(s,o+i,s,o+i-l,l),t.lineTo(s,o+r),t.arcTo(s,o,s+r,o,r),t.closePath()}renderListView(t,s){var at,V,O,R;const o=this.objectStates.get(s.id)||{},e=o.options||s.options||{},i=o.width!==void 0?o.width:((at=s.geometry)==null?void 0:at.width)||200,n=o.height!==void 0?o.height:((V=s.geometry)==null?void 0:V.height)||300,a=-i/2,r=-n/2,c=o.corner_radius!==void 0?o.corner_radius:e.corner_radius??0,d=e.orientation||"vertical",l=e.items||[],f=e.itemGap??10,g=e.itemHeight??50,u=e.itemWidth??200,p=e.scrollOffset??0,m=e.padding??0,y=e.glassEffect!==!1,S=e.accentColor||"#3b82f6",b=e.itemTextColor||"#333333",v=e.itemBackgroundColor||"#ffffff",w=e.hoveredIndex??null,k=e.activeItemIndex??null,A=e.glowIntensity??0,x=e.glowColor||"#3b82f6",B=typeof x=="string"?x:x.color||((R=(O=x.stops)==null?void 0:O[0])==null?void 0:R.color)||"#3b82f6",$=e.opacity!==void 0?e.opacity:s.opacity!==void 0?s.opacity:1;if(t.save(),t.globalAlpha*=$,A>0){const P=t.getTransform(),J=Math.sqrt(P.a*P.a+P.b*P.b)||1;t.shadowColor=B,t.shadowBlur=A*2*J,t.shadowOffsetX=0,t.shadowOffsetY=0}if(y){const P=e.listBackgroundColor||"rgba(31, 41, 55, 0.4)",J=this.createCanvasFill(t,P,i,n);t.fillStyle=J||"rgba(31, 41, 55, 0.4)",this.drawListViewRect(t,a,r,i,n,c),t.fill();const j=t.createLinearGradient(a,r,a+i,r+n);j.addColorStop(0,"rgba(255, 255, 255, 0.15)"),j.addColorStop(.5,"rgba(255, 255, 255, 0.08)"),j.addColorStop(1,"rgba(255, 255, 255, 0.03)"),t.fillStyle=j,this.drawListViewRect(t,a,r,i,n,c),t.fill(),t.strokeStyle="rgba(255, 255, 255, 0.25)",t.lineWidth=1,this.drawListViewRect(t,a,r,i,n,c),t.stroke()}else{const P=e.listBackgroundColor||"transparent",J=this.createCanvasFill(t,P,i,n);J&&(t.fillStyle=J,this.drawListViewRect(t,a,r,i,n,c),t.fill());const j=e.borderWidth??0;j>0&&(t.strokeStyle=e.borderColor||"#cccccc",t.lineWidth=j,this.drawListViewRect(t,a,r,i,n,c),t.stroke())}t.shadowBlur=0,t.save(),this.drawListViewRect(t,a,r,i,n,c),t.clip();const K=typeof m=="number"?m:d==="vertical"?m[0]:m[3];let tt=(d==="vertical"?r:a)+p+K;if(t.textBaseline="middle",l.forEach((P,J)=>{const j=d==="vertical"?i:u,lt=d==="vertical"?g:n,Y=d==="vertical"?a:tt,H=d==="vertical"?tt:r,it=w===J,nt=k===J;if(nt){const L=this.createCanvasFill(t,S,j,lt);t.fillStyle=L||S;const z=t.globalAlpha;t.globalAlpha=z*.8,t.fillRect(Y,H,j,lt),t.globalAlpha=z}else if(it)t.fillStyle=y?"rgba(255, 255, 255, 0.1)":"rgba(0, 0, 0, 0.05)",t.fillRect(Y,H,j,lt);else if(v!=="transparent"){const L=this.createCanvasFill(t,v,j,lt);t.fillStyle=L||v,t.fillRect(Y,H,j,lt)}if(nt||it){const L=this.createCanvasFill(t,S,d==="vertical"?3:j,d==="vertical"?lt:3);t.fillStyle=L||S,d==="vertical"?t.fillRect(Y,H,3,lt):t.fillRect(Y,H+lt-3,j,3)}const ft=nt?"#ffffff":y?"rgba(255, 255, 255, 0.9)":b;t.fillStyle=ft,t.font=nt||it?"600 14px Inter, sans-serif":"400 14px Inter, sans-serif";const M=typeof P=="string"?P:(P==null?void 0:P.label)||`Item ${J+1}`,Q=Y+(d==="vertical"?16:j/2),N=H+lt/2;d==="horizontal"?t.textAlign="center":t.textAlign="left",t.fillText(M,Q,N),tt+=(d==="vertical"?g:u)+f}),t.restore(),e.showScrollbar!==!1){const P=(l.length||0)*(d==="vertical"?g:u)+((l.length||0)-1)*f,J=d==="vertical"?n:i;if(P>J){const j=J/P,lt=J*j,Y=-p/P*J,H=e.scrollbarColor||"rgba(255,255,255,0.3)",it=e.scrollbarWidth||4;t.fillStyle=H,d==="vertical"?t.fillRect(a+i-it-2,r+Y,it,lt):t.fillRect(a+Y,r+n-it-2,lt,it)}}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,c=s.itemHeight??50,d=s.itemWidth??200,l=n.width!==void 0?n.width:((m=t.geometry)==null?void 0:m.width)||200,f=n.height!==void 0?n.height:((y=t.geometry)==null?void 0:y.height)||300,g=(a.length||0)*(o==="vertical"?c:d)+((a.length||0)-1)*r,p=Math.max(0,g-(o==="vertical"?f:l)+(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,tt;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:((K=t.geometry)==null?void 0:K.width)||200,r=i.height!==void 0?i.height:((tt=t.geometry)==null?void 0:tt.height)||300,c=e.orientation||"vertical",d=e.itemGap??10,l=e.itemHeight??50,f=e.itemWidth??200,g=e.scrollOffset??0,u=e.padding??0,p=this.getWorldTransform(t.id),m=s-p.x,y=o-p.y,S=-p.rotation*(Math.PI/180),b=Math.cos(S),v=Math.sin(S),w=m*b-y*v,k=m*v+y*b,A=-a/2,x=-r/2,B=typeof u=="number"?u:c==="vertical"?u[0]:u[3];let $=(c==="vertical"?x:A)+g+B;for(let rt=0;rt<n.length;rt++){const at=c==="vertical"?a:f,V=c==="vertical"?l:r,O=c==="vertical"?A:$,R=c==="vertical"?$:x;if(w>=O&&w<=O+at&&k>=R&&k<=R+V)return rt;$+=(c==="vertical"?l:f)+d}return null}drawListViewRect(t,s,o,e,i,n){t.beginPath(),this.drawRoundRect(t,s,o,e,i,n),t.fill()}solveBehaviors(t){if(!this.artboard)return;if(!this._lastPointerPos){this.frameCount%60;return}const{x:s,y:o}=this._lastPointerPos;this.artboard.objects.forEach(e=>{if(!e.behaviors||e.behaviors.length===0)return;const i=this.objectStates.get(e.id);i&&e.behaviors.forEach(n=>{var f,g,u,p,m,y,S,b,v,w,k,A,x,B,$,K,tt,rt,at,V,O,R,P,J,j,lt,Y,H,it,nt,ft,M,Q,N,L,z,pt,vt,yt,_t,kt,Tt,Wt,Yt,Dt,Vt,zt,st,ct,_,I,D,Z,bt,Mt,ht,Pt,mt,C,Et,Gt,Rt,dt,T,G,ut,E,F,et,It,Ot,St,Ft,wt,Xt,Jt,Qt;if(!n.enabled)return;const a=n.startTime||0,r=n.endTime||1/0;if(this.currentTime<a||this.currentTime>r)return;const c=i.x-s,d=i.y-o,l=Math.sqrt(c*c+d*d);if(this.frameCount%240===0&&Math.random()<.1&&console.log(`[ExodeUI] Executing ${n.type} on ${e.name}`),n.type===W.Proximity){const U=((f=n.settings)==null?void 0:f.radius)||300,X=((g=n.settings)==null?void 0:g.falloff)||"smooth";let q=0;l<U&&(X==="linear"?q=1-l/U:q=Math.pow(1-l/U,2)),q>0&&n.sensors.forEach(Ct=>{this.applyBehaviorSensor(i,Ct,q,t,n.settings,e)})}else if(n.type===W.Magnetic){const U=((u=n.settings)==null?void 0:u.radius)||400,X=((p=n.settings)==null?void 0:p.strength)||.5;if(l<U&&l>5){const q=1-l/U,Ct=c*q*X,$t=d*q*X;i.x-=Ct*t*10,i.y-=$t*t*10}}else if(n.type===W.Repel){const U=((m=n.settings)==null?void 0:m.radius)||300,X=((y=n.settings)==null?void 0:y.strength)||1;if(l<U){const q=Math.pow(1-l/U,2);i.x+=c/(l||1)*q*60*X*t*5,i.y+=d/(l||1)*q*60*X*t*5}}else if(n.type===W.Orbit){const U=((S=n.settings)==null?void 0:S.speed)||1,X=((b=n.settings)==null?void 0:b.radius)||30,q=this.currentTime*U*Math.PI*2;i.x+=Math.cos(q)*X*t*5,i.y+=Math.sin(q)*X*t*5,i.rotation+=2*t*5}else if(n.type===W.Vortex){const U=((v=n.settings)==null?void 0:v.radius)||400,X=((w=n.settings)==null?void 0:w.speed)||2,q=((k=n.settings)==null?void 0:k.strength)||1;if(l<U){const Ct=Math.pow(1-l/U,1.5),$t=this.currentTime*X*Math.PI*2,Ht=Math.cos($t)*30-c*.4,Ut=Math.sin($t)*30-d*.4;i.x+=Ht*Ct*q*t*5,i.y+=Ut*Ct*q*t*5,i.rotation+=5*Ct*q*t*5,i.scale_x*=1-Ct*.1*q*t,i.scale_y*=1-Ct*.1*q*t}}else if(n.type===W.Fluid){const U=((A=n.settings)==null?void 0:A.radius)||300,X=((x=n.settings)==null?void 0:x.strength)||1;if(l<U){const q=Math.pow(1-l/U,1.2),Ct=c/(l||1)*q*1.2*X,$t=d/(l||1)*q*1.2*X;i.x+=Ct*10*t*5,i.y+=$t*10*t*5,i.scale_x*=1+q*.3*X*t,i.scale_y*=1+q*.3*X*t}}else if(n.type===W.Elastic){const U=((B=n.settings)==null?void 0:B.radius)||300,X=(($=n.settings)==null?void 0:$.strength)||1;if(l<U){const q=1-l/U;i.scale_x*=1+q*.4*X*t,i.scale_y*=1+q*.4*X*t}}else if(n.type===W.Holographic){const U=i.x-this.canvasWidth/2,X=i.y-this.canvasHeight/2,q=((K=n.settings)==null?void 0:K.factor)||25;if(i.x-=U/1e3*q*t*5,i.y-=X/1e3*q*t*5,i.style){const Ct=1-Math.min(1,l/400);i.style.exposure=(i.style.exposure||1)+Ct*.5*t}}else if(n.type===W.Sticky){const U=((tt=n.settings)==null?void 0:tt.radius)||80,X=((rt=n.settings)==null?void 0:rt.strength)||1;if(l<U){const q=Math.pow(1-l/U,2);i.x-=c*q*X*t*10,i.y-=d*q*X*t*10,i.scale_x*=1-q*.1*X*t,i.scale_y*=1-q*.1*X*t}}else if(n.type===W.Dilation){const U=((at=n.settings)==null?void 0:at.size)||120,X=((V=n.settings)==null?void 0:V.strength)||1;if(l<U){const q=1-l/U;i.scale_x*=1+q*.5*X*t,i.scale_y*=1+q*.5*X*t}}else if(n.type===W.Parallax){const U=((O=n.settings)==null?void 0:O.factor)||.05,X=this.canvasHeight/2,q=(this._lastPointerPos.y-X)*U;i.y+=q*t*10}else if(n.type===W.Squash){const U=((R=n.settings)==null?void 0:R.strength)||.8;l<(e.width||100)&&this.isMouseDown?(i.scale_y=this.lerp(i.scale_y??1,(((P=e.transform)==null?void 0:P.scale_y)??1)*U,.3),i.scale_x=this.lerp(i.scale_x??1,(((J=e.transform)==null?void 0:J.scale_x)??1)*(1+(1-U)*.4),.3)):(i.scale_y=this.lerp(i.scale_y??1,((j=e.transform)==null?void 0:j.scale_y)??1,.2),i.scale_x=this.lerp(i.scale_x??1,((lt=e.transform)==null?void 0:lt.scale_x)??1,.2))}else if(n.type===W.TextCounter){const U=((Y=n.settings)==null?void 0:Y.duration)||2,X=((H=n.settings)==null?void 0:H.from)||0,q=((it=n.settings)==null?void 0:it.to)||100;n._runtimeStart===void 0&&(n._runtimeStart=this.currentTime);const Ct=this.currentTime-n._runtimeStart,$t=Math.min(1,Ct/U),Ht=Math.floor(X+(q-X)*$t);if(((nt=e.geometry)==null?void 0:nt.type)==="Text"){const Ut=((ft=n.settings)==null?void 0:ft.prefix)||"",qt=((M=n.settings)==null?void 0:M.suffix)||"";i.geometry||(i.geometry={...e.geometry}),i.geometry.text=`${Ut}${Ht}${qt}`}}else if(n.type===W.Spotlight){const U=((Q=n.settings)==null?void 0:Q.radius)||250,X=((N=n.settings)==null?void 0:N.strength)||1.5;if(l<U){const q=Math.pow(1-l/U,2);i.style||(i.style={...e.style}),i.style.adjustments||(i.style.adjustments={...(L=e.style)==null?void 0:L.adjustments}),i.style.adjustments.exposure=(((pt=(z=e.style)==null?void 0:z.adjustments)==null?void 0:pt.exposure)||0)+q*X*50}else(vt=i.style)!=null&&vt.adjustments&&(i.style.adjustments.exposure=this.lerp(i.style.adjustments.exposure||0,((_t=(yt=e.style)==null?void 0:yt.adjustments)==null?void 0:_t.exposure)||0,.1))}else if(n.type===W.Noise||n.type===W.Float){const U=(((kt=n.settings)==null?void 0:kt.frequency)||((Tt=n.settings)==null?void 0:Tt.speed)||1)*.002,X=(((Wt=n.settings)==null?void 0:Wt.amplitude)||((Yt=n.settings)==null?void 0:Yt.range)||50)*(((Dt=n.settings)==null?void 0:Dt.strength)||1),q=Date.now();i.x+=Math.sin(q*U)*X*t,i.y+=Math.cos(q*U*.8)*X*t,i.rotation+=Math.sin(q*U*.5)*5*t}else if(n.type===W.Pulse){const U=(((Vt=n.settings)==null?void 0:Vt.speed)||1)*.005,X=(((zt=n.settings)==null?void 0:zt.scale)||1.2)-1,q=Math.sin(Date.now()*U),Ct=((st=n.settings)==null?void 0:st.strength)||1;i.scale_x*=1+q*X*Ct*t,i.scale_y*=1+q*X*Ct*t,i.style&&(i.style.exposure=(i.style.exposure||1)+Math.max(0,q)*.1*Ct*t)}else if(n.type===W.Draggable){const U=((ct=n.settings)==null?void 0:ct.radius)||150,X=this.draggingBehaviors.has(e.id);if(l<U||X){const q=((_=n.settings)==null?void 0:_.strength)||1,Ct=X?1:Math.max(0,1-l/U);this.applyBehaviorSensor(i,Bt.PositionX,Ct*q,t,n.settings),this.applyBehaviorSensor(i,Bt.PositionY,Ct*q,t,n.settings)}}else if(n.type===W.Scroll){const U=((I=n.settings)==null?void 0:I.axis)||"vertical",X=((D=n.settings)==null?void 0:D.factor)||.5,q=((Z=n.settings)==null?void 0:Z.strength)||1,Ct=((bt=n.settings)==null?void 0:bt.scaleFactor)||0;(U==="vertical"||U==="both")&&(i.y+=this.scrollOffset.y*X*q*t),(U==="horizontal"||U==="both")&&(i.x+=this.scrollOffset.x*X*q*t),Ct!==0&&(i.scale_x*=1+this.scrollOffset.y*Ct*t,i.scale_y*=1+this.scrollOffset.y*Ct*t)}else if(n.type===W.LookAt){const U=((Mt=n.settings)==null?void 0:Mt.factor)||1,X=((ht=n.settings)==null?void 0:ht.strength)||1,q=Math.atan2(-d,-c)*(180/Math.PI),Ct=i.rotation,$t=(q-Ct+180)%360-180;i.rotation+=$t*U*X*t*10}else if(n.type===W.Glint||n.type===W.Scan){const U=(((Pt=n.settings)==null?void 0:Pt.speed)||1)*.004,X=((mt=n.settings)==null?void 0:mt.strength)||1,q=(Math.sin(Date.now()*U)+1)/2;i.style&&(i.style.exposure=(i.style.exposure||1)+q*X*t*5),i.x+=(q-.5)*20*X*t}else if(n.type===W.Ratchet){const U=((C=n.settings)==null?void 0:C.steps)||12,X=(((Et=n.settings)==null?void 0:Et.speed)||1)*30,q=Math.floor(i.rotation/(360/U))*(360/U);i.rotation=this.lerp(i.rotation,q+X*t,.1)}else if(n.type===W.Jitter&&l<300){const U=((Gt=n.settings)==null?void 0:Gt.strength)||1,X=(((Rt=n.settings)==null?void 0:Rt.intensity)||5)*U;i.x+=(Math.random()-.5)*X*t*60,i.y+=(Math.random()-.5)*X*t*60,i.rotation+=(Math.random()-.5)*X*t*120}else if(n.type===W.Follower){const U=(dt=n.settings)==null?void 0:dt.targetId;if(U){const X=this.objectStates.get(U);if(X){const q=((T=n.settings)==null?void 0:T.stiffness)||.1,Ct=X.x-i.x,$t=X.y-i.y;i.x+=Ct*q*t*60,i.y+=$t*q*t*60}}}else if(n.type===W.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===W.Gravity){const U=((G=n.settings)==null?void 0:G.strength)||9.8;i.y+=U*t*10}else if(n.type===W.Velocity){const U=((ut=n.settings)==null?void 0:ut.vx)||0,X=((E=n.settings)==null?void 0:E.vy)||0;i.x+=U*t*10,i.y+=X*t*10}else if(n.type===W.Shear){const U=((F=n.settings)==null?void 0:F.strength)||1,X=((et=n.settings)==null?void 0:et.radius)||300;if(l<X){const q=1-l/X;i.skew_x=this.lerp(i.skew_x||0,(((It=e.transform)==null?void 0:It.skew_x)||0)+q*U*30,.1)}else i.skew_x=this.lerp(i.skew_x||0,((Ot=e.transform)==null?void 0:Ot.skew_x)||0,.05)}else if(n.type===W.Lens){const U=((St=n.settings)==null?void 0:St.radius)||200,X=((Ft=n.settings)==null?void 0:Ft.strength)||.5;if(l<U){const q=Math.pow(1-l/U,2);i.scale_x=this.lerp(i.scale_x??1,(((wt=e.transform)==null?void 0:wt.scale_x)??1)*(1+q*X),.2),i.scale_y=this.lerp(i.scale_y??1,(((Xt=e.transform)==null?void 0:Xt.scale_y)??1)*(1+q*X),.2)}else i.scale_x=this.lerp(i.scale_x??1,((Jt=e.transform)==null?void 0:Jt.scale_x)??1,.1),i.scale_y=this.lerp(i.scale_y??1,((Qt=e.transform)==null?void 0:Qt.scale_y)??1,.1)}})})}applyBehaviorSensor(t,s,o,e,i,n){var c,d,l,f,g,u,p,m,y;const a=(i==null?void 0:i.intensity)||(i==null?void 0:i.strength)||1,r=o*a*e;switch(s){case Bt.Scale:t.scale_x*=1+r*.5,t.scale_y*=1+r*.5;break;case Bt.Opacity:t.opacity=Math.max(0,Math.min(100,t.opacity-r*100));break;case Bt.RotateZ:t.rotation+=r*180;break;case Bt.RotateX:t.rotate_x=(t.rotate_x||0)+r*180;break;case Bt.RotateY:t.rotate_y=(t.rotate_y||0)+r*180;break;case Bt.PositionX:t.x+=r*300;break;case Bt.PositionY:t.y+=r*300;break;case Bt.SkewX:t.skew_x=(t.skew_x||0)+r*45;break;case Bt.Blur:t.style||(t.style={...n.style}),t.style.blur||(t.style.blur={...(c=n.style)==null?void 0:c.blur}),t.style.blur.amount=(((l=(d=n.style)==null?void 0:d.blur)==null?void 0:l.amount)||0)+o*((i==null?void 0:i.blur)||50)*a;break;case Bt.Exposure:t.style||(t.style={...n.style}),t.style.adjustments||(t.style.adjustments={...(f=n.style)==null?void 0:f.adjustments}),t.style.adjustments.exposure=(((u=(g=n.style)==null?void 0:g.adjustments)==null?void 0:u.exposure)||0)+o*((i==null?void 0:i.exposure)||50)*a;break;case Bt.HueShift:t.style||(t.style={...n.style}),t.style.adjustments||(t.style.adjustments={...(p=n.style)==null?void 0:p.adjustments}),t.style.adjustments.hue=(((y=(m=n.style)==null?void 0:m.adjustments)==null?void 0:y.hue)||0)+o*((i==null?void 0:i.hue)||180)*a;break;case Bt.CornerRadius:t.corner_radius=Math.min(200,(t.corner_radius||0)+r*100);break;case Bt.LetterSpacing:t.geometry||(t.geometry={}),t.geometry.letterSpacing=(t.geometry.letterSpacing||0)+r*10;break}}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,c=s.naturalHeight,d=r/c,l=i/n;let f=i,g=n,u=o,p=e;a==="cover"?d>l?(f=n*d,u=o-(f-i)/2):(g=i/d,p=e-(g-n)/2):a==="contain"&&(d>l?(g=i/d,p=e+(n-g)/2):(f=n*d,u=o+(i-f)/2)),t.drawImage(s,u,p,f,g)}}const is=xt.forwardRef(({artboard:h,src:t,style:s,autoPlay:o=!0,fit:e="Contain",alignment:i="Center",onReady:n,onTrigger:a,onInputUpdate:r,onComponentChange:c,onToggle:d,onInputChange:l,onInputFocus:f,onInputBlur:g,onLog:u,onLogicUpdate:p,onButtonClick:m,onGraphPointClick:y,currentTime:S,revision:b=0,scrollY:v,scrollX:w,mouseX:k,mouseY:A,isMouseDown:x,inputs:B,interactive:$=!0,onNavigation:K},tt)=>{const rt=xt.useRef(null),at=xt.useRef(new ve),V=xt.useRef(void 0),O=xt.useRef(0),R=xt.useRef(null),P=xt.useRef(b),[,J]=xt.useState(h||null),j=xt.useRef(!0);xt.useImperativeHandle(tt,()=>rt.current),xt.useEffect(()=>(j.current=!0,()=>{j.current=!1,V.current&&cancelAnimationFrame(V.current)}),[]),xt.useEffect(()=>{at.current.setLayout(e,i)},[e,i]),xt.useEffect(()=>{const Y=at.current;a&&Y.setTriggerCallback(a),r&&Y.setInputUpdateCallback((H,it)=>r({[H]:it})),c&&Y.setComponentChangeCallback(H=>c(H)),d&&Y.setToggleCallback(d),l&&Y.setInputChangeCallback(l),f&&Y.setInputFocusCallback(f),g&&Y.setInputBlurCallback(g),u&&Y.setOnLogCallback(H=>u(H,"info")),p&&Y.setLogicUpdateCallback(p),m&&Y.setButtonClickCallback(m),y&&Y.setGraphPointClickCallback(H=>y(H.objectId,H)),K&&Y.setNavigationCallback(K)},[a,r,c,d,l,f,g,u,p,m,y,K]),xt.useEffect(()=>{(async()=>{let H=h;if(t&&!h)try{t.startsWith("{")?H=JSON.parse(t):H=await(await fetch(t)).json()}catch(it){console.error("[ExodeUI] Failed to load src:",it)}if(H){const it=at.current,nt=H.id||H.name||"default";(R.current!==nt||P.current!==b)&&(it.load(H),R.current=nt,P.current=b,J(H),O.current=0,it.advance(0)),n&&n(it)}})()},[h==null?void 0:h.id,t,b]),xt.useEffect(()=>{const Y=H=>{if(!at.current||!j.current)return;const it=at.current,nt=rt.current;if(!nt)return;const ft=nt.getContext("2d");if(!ft)return;const M=H/1e3;O.current===0&&(O.current=M);let Q=M-O.current;Q>.1&&(Q=.1),O.current=M;const N=nt.getBoundingClientRect(),L=window.devicePixelRatio||1,z=Math.round(N.width*L),pt=Math.round(N.height*L);(nt.width!==z||nt.height!==pt)&&(nt.width=z,nt.height=pt),o?it.advance(Q):S!==void 0&&it.seek(S),it.render(ft,nt.width,nt.height),V.current=requestAnimationFrame(Y)};return V.current=requestAnimationFrame(Y),()=>{V.current&&cancelAnimationFrame(V.current)}},[o,S]),xt.useEffect(()=>{const Y=at.current;v!==void 0&&Y.updateInput("scrollY",v),w!==void 0&&Y.updateInput("scrollX",w),k!==void 0&&Y.updateInput("mouseX",k),A!==void 0&&Y.updateInput("mouseY",A),x!==void 0&&Y.updateInput("isMouseDown",x),B&&Object.entries(B).forEach(([H,it])=>Y.updateInput(H,it))},[v,w,k,A,x,B]);const lt=(Y,H)=>{if(!$||!rt.current)return;const it=rt.current,nt=it.getBoundingClientRect(),ft=Y.clientX-nt.left,M=Y.clientY-nt.top,Q=window.devicePixelRatio||1;at.current.handlePointerInput(H,ft*Q,M*Q,it.width,it.height)};return Lt.jsx("canvas",{ref:rt,onPointerDown:Y=>{var H;lt(Y,"down"),(H=rt.current)==null||H.focus()},onPointerMove:Y=>lt(Y,"move"),onPointerUp:Y=>lt(Y,"up"),onPointerCancel:Y=>lt(Y,"up"),onClick:Y=>lt(Y,"click"),onWheel:Y=>{at.current.handleWheel(Y.deltaX,Y.deltaY)},onKeyDown:Y=>at.current.handleKeyDown(Y.nativeEvent),onContextMenu:Y=>Y.preventDefault(),tabIndex:0,style:{...s,width:"100%",height:"100%",outline:"none",display:"block",touchAction:"none",pointerEvents:$?"auto":"none"}})});function ns(){const[h,t]=xt.useState(null),s=xt.useCallback((l,f)=>{h==null||h.setInputBool(l,f)},[h]),o=xt.useCallback((l,f)=>{h==null||h.setInputNumber(l,f)},[h]),e=xt.useCallback(l=>{h==null||h.fireTrigger(l)},[h]),i=xt.useCallback((l,f)=>{h==null||h.setInputText(l,f)},[h]),n=xt.useCallback((l,f)=>{h==null||h.setInputNumberArray(l,f)},[h]),a=xt.useCallback((l,f)=>{h==null||h.setInputStringArray(l,f)},[h]),r=xt.useCallback((l,f)=>{h==null||h.updateObjectOptions(l,f)},[h]),c=xt.useCallback((l,f,g)=>{h==null||h.updateConstraint(l,f,g)},[h]),d=xt.useCallback((l,f)=>{h==null||h.updateGraphData(l,f)},[h]);return{setEngine:t,engine:h,setInputBool:s,setInputNumber:o,fireTrigger:e,setInputText:i,setInputNumberArray:n,setInputStringArray:a,updateConstraint:c,updateGraphData:d,updateObjectOptions:r}}const os=({artboard:h,config:t})=>{const s={...h.seo,...t},o=s.enableSmartExtraction!==!1;xt.useEffect(()=>{const a=s.title||h.name;a&&(document.title=a);let r=s.description;if(!r&&o){const l=h.objects.filter(f=>{var g;return((g=f.geometry)==null?void 0:g.type)==="Text"}).sort((f,g)=>{var u,p;return(((u=g.geometry.text)==null?void 0:u.length)||0)-(((p=f.geometry.text)==null?void 0:p.length)||0)});l.length>0&&(r=l[0].geometry.text)}r&&(e("name","description",r),e("property","og:description",r)),s.keywords&&s.keywords.length>0&&e("name","keywords",s.keywords.join(", "));const c=s.ogImage||h.backgroundImage;c&&e("property","og:image",c),a&&e("property","og:title",a),e("property","og:type","website")},[s,h,o]);const e=(a,r,c)=>{let d=document.querySelector(`meta[${a}="${r}"]`);d||(d=document.createElement("meta"),d.setAttribute(a,r),document.head.appendChild(d)),d.setAttribute("content",c)},i=()=>{const a=[];return a.push(Lt.jsx("h1",{children:s.title||h.name},"artboard-title")),h.objects.forEach((c,d)=>{var l,f;if(!(!c.visible&&c.isVisible!==!0))if(((l=c.geometry)==null?void 0:l.type)==="Text"){const g=c.geometry.text;g&&(c.geometry.fontSize>24?a.push(Lt.jsx("h2",{children:g},c.id||d)):a.push(Lt.jsx("p",{children:g},c.id||d)))}else if(((f=c.geometry)==null?void 0:f.type)==="Image"){const g=c.geometry.src,u=c.altText||c.name||"Illustration";a.push(Lt.jsx("img",{src:g,alt:u},c.id||d))}else c.type==="Button"&&a.push(Lt.jsx("button",{children:c.name||"Button"},c.id||d))}),a},n=s.jsonLd||{"@context":"https://schema.org","@type":"VisualArtwork",name:s.title||h.name,description:s.description,image:s.ogImage||h.backgroundImage,abstract:"Animated interface created with ExodeUI"};return Lt.jsxs("div",{id:`exode-seo-${h.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(),Lt.jsx("script",{type:"application/ld+json",children:JSON.stringify(n)})]})},as={version:"6.3.14"}.version;At.BehaviorSensor=Bt,At.BehaviorType=W,At.ConditionOp=oe,At.ExodeSEO=os,At.ExodeUICanvas=is,At.ExodeUIEngine=ve,At.LogicOp=gt,At.VERSION=as,At.useExodeUI=ns,Object.defineProperty(At,Symbol.toStringTag,{value:"Module"})});
|