@snowcone-app/canvas 0.1.13 → 0.1.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.
@@ -1,4 +1,4 @@
1
- "use strict";const n=require("react/jsx-runtime"),l=require("react"),Yt=require("./ThemeContext-BMNQKl1c.cjs"),T=require("./HybridHistoryManager-BXD93pp8.cjs"),Qn=require("react-dom"),rt=require("./ImportManager-W1eWhfyM.cjs"),Uc=require("react-dom/server"),m=require("@snowcone-app/ui"),Yc=require("clsx"),Wc=require("tailwind-merge"),Xc=require("@runware/sdk-js"),Pi=require("lodash-es");function Vc(e,t){const r=e.icons,o=e.aliases||Object.create(null),s=Object.create(null);function i(a){if(r[a])return s[a]=[];if(!(a in s)){s[a]=null;const c=o[a]&&o[a].parent,d=c&&i(c);d&&(s[a]=[c].concat(d))}return s[a]}return Object.keys(r).concat(Object.keys(o)).forEach(i),s}const Fa=Object.freeze({left:0,top:0,width:16,height:16}),So=Object.freeze({rotate:0,vFlip:!1,hFlip:!1}),Gs=Object.freeze({...Fa,...So}),js=Object.freeze({...Gs,body:"",hidden:!1});function Gc(e,t){const r={};!e.hFlip!=!t.hFlip&&(r.hFlip=!0),!e.vFlip!=!t.vFlip&&(r.vFlip=!0);const o=((e.rotate||0)+(t.rotate||0))%4;return o&&(r.rotate=o),r}function Fi(e,t){const r=Gc(e,t);for(const o in js)o in So?o in e&&!(o in r)&&(r[o]=So[o]):o in t?r[o]=t[o]:o in e&&(r[o]=e[o]);return r}function Kc(e,t,r){const o=e.icons,s=e.aliases||Object.create(null);let i={};function a(c){i=Fi(o[c]||s[c],i)}return a(t),r.forEach(a),Fi(e,i)}function za(e,t){const r=[];if(typeof e!="object"||typeof e.icons!="object")return r;e.not_found instanceof Array&&e.not_found.forEach(s=>{t(s,null),r.push(s)});const o=Vc(e);for(const s in o){const i=o[s];i&&(t(s,Kc(e,s,i)),r.push(s))}return r}const qc={provider:"",aliases:{},not_found:{},...Fa};function ts(e,t){for(const r in t)if(r in e&&typeof e[r]!=typeof t[r])return!1;return!0}function Oa(e){if(typeof e!="object"||e===null)return null;const t=e;if(typeof t.prefix!="string"||!e.icons||typeof e.icons!="object"||!ts(e,qc))return null;const r=t.icons;for(const s in r){const i=r[s];if(!s||typeof i.body!="string"||!ts(i,js))return null}const o=t.aliases||Object.create(null);for(const s in o){const i=o[s],a=i.parent;if(!s||typeof a!="string"||!r[a]&&!o[a]||!ts(i,js))return null}return t}const zi=Object.create(null);function Zc(e,t){return{provider:e,prefix:t,icons:Object.create(null),missing:new Set}}function vr(e,t){const r=zi[e]||(zi[e]=Object.create(null));return r[t]||(r[t]=Zc(e,t))}function Ba(e,t){return Oa(t)?za(t,(r,o)=>{o?e.icons[r]=o:e.missing.add(r)}):[]}function Jc(e,t,r){try{if(typeof r.body=="string")return e.icons[t]={...r},!0}catch{}return!1}const _a=/^[a-z0-9]+(-[a-z0-9]+)*$/,Do=(e,t,r,o="")=>{const s=e.split(":");if(e.slice(0,1)==="@"){if(s.length<2||s.length>3)return null;o=s.shift().slice(1)}if(s.length>3||!s.length)return null;if(s.length>1){const c=s.pop(),d=s.pop(),u={provider:s.length>0?s[0]:o,prefix:d,name:c};return t&&!bo(u)?null:u}const i=s[0],a=i.split("-");if(a.length>1){const c={provider:o,prefix:a.shift(),name:a.join("-")};return t&&!bo(c)?null:c}if(r&&o===""){const c={provider:o,prefix:"",name:i};return t&&!bo(c,r)?null:c}return null},bo=(e,t)=>e?!!((t&&e.prefix===""||e.prefix)&&e.name):!1;let Ur=!1;function Ha(e){return typeof e=="boolean"&&(Ur=e),Ur}function Oi(e){const t=typeof e=="string"?Do(e,!0,Ur):e;if(t){const r=vr(t.provider,t.prefix),o=t.name;return r.icons[o]||(r.missing.has(o)?null:void 0)}}function $a(e,t){const r=Do(e,!0,Ur);if(!r)return!1;const o=vr(r.provider,r.prefix);return t?Jc(o,r.name,t):(o.missing.add(r.name),!0)}function Qc(e,t){if(typeof e!="object")return!1;if(typeof t!="string"&&(t=e.provider||""),Ur&&!t&&!e.prefix){let s=!1;return Oa(e)&&(e.prefix="",za(e,(i,a)=>{$a(i,a)&&(s=!0)})),s}const r=e.prefix;if(!bo({prefix:r,name:"a"}))return!1;const o=vr(t,r);return!!Ba(o,e)}const Ua=Object.freeze({width:null,height:null}),Ya=Object.freeze({...Ua,...So}),ed=/(-?[0-9.]*[0-9]+[0-9.]*)/g,td=/^-?[0-9.]*[0-9]+[0-9.]*$/g;function Bi(e,t,r){if(t===1)return e;if(r=r||100,typeof e=="number")return Math.ceil(e*t*r)/r;if(typeof e!="string")return e;const o=e.split(ed);if(o===null||!o.length)return e;const s=[];let i=o.shift(),a=td.test(i);for(;;){if(a){const c=parseFloat(i);isNaN(c)?s.push(i):s.push(Math.ceil(c*t*r)/r)}else s.push(i);if(i=o.shift(),i===void 0)return s.join("");a=!a}}function nd(e,t="defs"){let r="";const o=e.indexOf("<"+t);for(;o>=0;){const s=e.indexOf(">",o),i=e.indexOf("</"+t);if(s===-1||i===-1)break;const a=e.indexOf(">",i);if(a===-1)break;r+=e.slice(s+1,i).trim(),e=e.slice(0,o).trim()+e.slice(a+1)}return{defs:r,content:e}}function rd(e,t){return e?"<defs>"+e+"</defs>"+t:t}function od(e,t,r){const o=nd(e);return rd(o.defs,t+o.content+r)}const sd=e=>e==="unset"||e==="undefined"||e==="none";function id(e,t){const r={...Gs,...e},o={...Ya,...t},s={left:r.left,top:r.top,width:r.width,height:r.height};let i=r.body;[r,o].forEach(x=>{const y=[],v=x.hFlip,w=x.vFlip;let C=x.rotate;v?w?C+=2:(y.push("translate("+(s.width+s.left).toString()+" "+(0-s.top).toString()+")"),y.push("scale(-1 1)"),s.top=s.left=0):w&&(y.push("translate("+(0-s.left).toString()+" "+(s.height+s.top).toString()+")"),y.push("scale(1 -1)"),s.top=s.left=0);let j;switch(C<0&&(C-=Math.floor(C/4)*4),C=C%4,C){case 1:j=s.height/2+s.top,y.unshift("rotate(90 "+j.toString()+" "+j.toString()+")");break;case 2:y.unshift("rotate(180 "+(s.width/2+s.left).toString()+" "+(s.height/2+s.top).toString()+")");break;case 3:j=s.width/2+s.left,y.unshift("rotate(-90 "+j.toString()+" "+j.toString()+")");break}C%2===1&&(s.left!==s.top&&(j=s.left,s.left=s.top,s.top=j),s.width!==s.height&&(j=s.width,s.width=s.height,s.height=j)),y.length&&(i=od(i,'<g transform="'+y.join(" ")+'">',"</g>"))});const a=o.width,c=o.height,d=s.width,u=s.height;let h,f;a===null?(f=c===null?"1em":c==="auto"?u:c,h=Bi(f,d/u)):(h=a==="auto"?d:a,f=c===null?Bi(h,u/d):c==="auto"?u:c);const p={},g=(x,y)=>{sd(y)||(p[x]=y.toString())};g("width",h),g("height",f);const b=[s.left,s.top,d,u];return p.viewBox=b.join(" "),{attributes:p,viewBox:b,body:i}}const ad=/\sid="(\S+)"/g,ld="IconifyId"+Date.now().toString(16)+(Math.random()*16777216|0).toString(16);let cd=0;function dd(e,t=ld){const r=[];let o;for(;o=ad.exec(e);)r.push(o[1]);if(!r.length)return e;const s="suffix"+(Math.random()*16777216|Date.now()).toString(16);return r.forEach(i=>{const a=typeof t=="function"?t(i):t+(cd++).toString(),c=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp('([#;"])('+c+')([")]|\\.[a-z])',"g"),"$1"+a+s+"$3")}),e=e.replace(new RegExp(s,"g"),""),e}const Es=Object.create(null);function ud(e,t){Es[e]=t}function Ts(e){return Es[e]||Es[""]}function Ks(e){let t;if(typeof e.resources=="string")t=[e.resources];else if(t=e.resources,!(t instanceof Array)||!t.length)return null;return{resources:t,path:e.path||"/",maxURL:e.maxURL||500,rotate:e.rotate||750,timeout:e.timeout||5e3,random:e.random===!0,index:e.index||0,dataAfterTimeout:e.dataAfterTimeout!==!1}}const qs=Object.create(null),Nr=["https://api.simplesvg.com","https://api.unisvg.com"],yo=[];for(;Nr.length>0;)Nr.length===1||Math.random()>.5?yo.push(Nr.shift()):yo.push(Nr.pop());qs[""]=Ks({resources:["https://api.iconify.design"].concat(yo)});function hd(e,t){const r=Ks(t);return r===null?!1:(qs[e]=r,!0)}function Zs(e){return qs[e]}const fd=()=>{let e;try{if(e=fetch,typeof e=="function")return e}catch{}};let _i=fd();function pd(e,t){const r=Zs(e);if(!r)return 0;let o;if(!r.maxURL)o=0;else{let s=0;r.resources.forEach(a=>{s=Math.max(s,a.length)});const i=t+".json?icons=";o=r.maxURL-s-r.path.length-i.length}return o}function md(e){return e===404}const gd=(e,t,r)=>{const o=[],s=pd(e,t),i="icons";let a={type:i,provider:e,prefix:t,icons:[]},c=0;return r.forEach((d,u)=>{c+=d.length+1,c>=s&&u>0&&(o.push(a),a={type:i,provider:e,prefix:t,icons:[]},c=d.length),a.icons.push(d)}),o.push(a),o};function xd(e){if(typeof e=="string"){const t=Zs(e);if(t)return t.path}return"/"}const bd=(e,t,r)=>{if(!_i){r("abort",424);return}let o=xd(t.provider);switch(t.type){case"icons":{const i=t.prefix,c=t.icons.join(","),d=new URLSearchParams({icons:c});o+=i+".json?"+d.toString();break}case"custom":{const i=t.uri;o+=i.slice(0,1)==="/"?i.slice(1):i;break}default:r("abort",400);return}let s=503;_i(e+o).then(i=>{const a=i.status;if(a!==200){setTimeout(()=>{r(md(a)?"abort":"next",a)});return}return s=501,i.json()}).then(i=>{if(typeof i!="object"||i===null){setTimeout(()=>{i===404?r("abort",i):r("next",s)});return}setTimeout(()=>{r("success",i)})}).catch(()=>{r("next",s)})},yd={prepare:gd,send:bd};function Wa(e,t){e.forEach(r=>{const o=r.loaderCallbacks;o&&(r.loaderCallbacks=o.filter(s=>s.id!==t))})}function vd(e){e.pendingCallbacksFlag||(e.pendingCallbacksFlag=!0,setTimeout(()=>{e.pendingCallbacksFlag=!1;const t=e.loaderCallbacks?e.loaderCallbacks.slice(0):[];if(!t.length)return;let r=!1;const o=e.provider,s=e.prefix;t.forEach(i=>{const a=i.icons,c=a.pending.length;a.pending=a.pending.filter(d=>{if(d.prefix!==s)return!0;const u=d.name;if(e.icons[u])a.loaded.push({provider:o,prefix:s,name:u});else if(e.missing.has(u))a.missing.push({provider:o,prefix:s,name:u});else return r=!0,!0;return!1}),a.pending.length!==c&&(r||Wa([e],i.id),i.callback(a.loaded.slice(0),a.missing.slice(0),a.pending.slice(0),i.abort))})}))}let wd=0;function Cd(e,t,r){const o=wd++,s=Wa.bind(null,r,o);if(!t.pending.length)return s;const i={id:o,icons:t,callback:e,abort:s};return r.forEach(a=>{(a.loaderCallbacks||(a.loaderCallbacks=[])).push(i)}),s}function Sd(e){const t={loaded:[],missing:[],pending:[]},r=Object.create(null);e.sort((s,i)=>s.provider!==i.provider?s.provider.localeCompare(i.provider):s.prefix!==i.prefix?s.prefix.localeCompare(i.prefix):s.name.localeCompare(i.name));let o={provider:"",prefix:"",name:""};return e.forEach(s=>{if(o.name===s.name&&o.prefix===s.prefix&&o.provider===s.provider)return;o=s;const i=s.provider,a=s.prefix,c=s.name,d=r[i]||(r[i]=Object.create(null)),u=d[a]||(d[a]=vr(i,a));let h;c in u.icons?h=t.loaded:a===""||u.missing.has(c)?h=t.missing:h=t.pending;const f={provider:i,prefix:a,name:c};h.push(f)}),t}function kd(e,t=!0,r=!1){const o=[];return e.forEach(s=>{const i=typeof s=="string"?Do(s,t,r):s;i&&o.push(i)}),o}const jd={resources:[],index:0,timeout:2e3,rotate:750,random:!1,dataAfterTimeout:!1};function Ed(e,t,r,o){const s=e.resources.length,i=e.random?Math.floor(Math.random()*s):e.index;let a;if(e.random){let S=e.resources.slice(0);for(a=[];S.length>1;){const R=Math.floor(Math.random()*S.length);a.push(S[R]),S=S.slice(0,R).concat(S.slice(R+1))}a=a.concat(S)}else a=e.resources.slice(i).concat(e.resources.slice(0,i));const c=Date.now();let d="pending",u=0,h,f=null,p=[],g=[];typeof o=="function"&&g.push(o);function b(){f&&(clearTimeout(f),f=null)}function x(){d==="pending"&&(d="aborted"),b(),p.forEach(S=>{S.status==="pending"&&(S.status="aborted")}),p=[]}function y(S,R){R&&(g=[]),typeof S=="function"&&g.push(S)}function v(){return{startTime:c,payload:t,status:d,queriesSent:u,queriesPending:p.length,subscribe:y,abort:x}}function w(){d="failed",g.forEach(S=>{S(void 0,h)})}function C(){p.forEach(S=>{S.status==="pending"&&(S.status="aborted")}),p=[]}function j(S,R,I){const D=R!=="success";switch(p=p.filter(E=>E!==S),d){case"pending":break;case"failed":if(D||!e.dataAfterTimeout)return;break;default:return}if(R==="abort"){h=I,w();return}if(D){h=I,p.length||(a.length?M():w());return}if(b(),C(),!e.random){const E=e.resources.indexOf(S.resource);E!==-1&&E!==e.index&&(e.index=E)}d="completed",g.forEach(E=>{E(I)})}function M(){if(d!=="pending")return;b();const S=a.shift();if(S===void 0){if(p.length){f=setTimeout(()=>{b(),d==="pending"&&(C(),w())},e.timeout);return}w();return}const R={status:"pending",resource:S,callback:(I,D)=>{j(R,I,D)}};p.push(R),u++,f=setTimeout(M,e.rotate),r(S,t,R.callback)}return setTimeout(M),v}function Xa(e){const t={...jd,...e};let r=[];function o(){r=r.filter(c=>c().status==="pending")}function s(c,d,u){const h=Ed(t,c,d,(f,p)=>{o(),u&&u(f,p)});return r.push(h),h}function i(c){return r.find(d=>c(d))||null}return{query:s,find:i,setIndex:c=>{t.index=c},getIndex:()=>t.index,cleanup:o}}function Hi(){}const ns=Object.create(null);function Td(e){if(!ns[e]){const t=Zs(e);if(!t)return;const r=Xa(t),o={config:t,redundancy:r};ns[e]=o}return ns[e]}function Rd(e,t,r){let o,s;if(typeof e=="string"){const i=Ts(e);if(!i)return r(void 0,424),Hi;s=i.send;const a=Td(e);a&&(o=a.redundancy)}else{const i=Ks(e);if(i){o=Xa(i);const a=e.resources?e.resources[0]:"",c=Ts(a);c&&(s=c.send)}}return!o||!s?(r(void 0,424),Hi):o.query(t,s,r)().abort}function $i(){}function Nd(e){e.iconsLoaderFlag||(e.iconsLoaderFlag=!0,setTimeout(()=>{e.iconsLoaderFlag=!1,vd(e)}))}function Md(e){const t=[],r=[];return e.forEach(o=>{(o.match(_a)?t:r).push(o)}),{valid:t,invalid:r}}function Mr(e,t,r){function o(){const s=e.pendingIcons;t.forEach(i=>{s&&s.delete(i),e.icons[i]||e.missing.add(i)})}if(r&&typeof r=="object")try{if(!Ba(e,r).length){o();return}}catch(s){console.error(s)}o(),Nd(e)}function Ui(e,t){e instanceof Promise?e.then(r=>{t(r)}).catch(()=>{t(null)}):t(e)}function Id(e,t){e.iconsToLoad?e.iconsToLoad=e.iconsToLoad.concat(t).sort():e.iconsToLoad=t,e.iconsQueueFlag||(e.iconsQueueFlag=!0,setTimeout(()=>{e.iconsQueueFlag=!1;const{provider:r,prefix:o}=e,s=e.iconsToLoad;if(delete e.iconsToLoad,!s||!s.length)return;const i=e.loadIcon;if(e.loadIcons&&(s.length>1||!i)){Ui(e.loadIcons(s,o,r),h=>{Mr(e,s,h)});return}if(i){s.forEach(h=>{const f=i(h,o,r);Ui(f,p=>{const g=p?{prefix:o,icons:{[h]:p}}:null;Mr(e,[h],g)})});return}const{valid:a,invalid:c}=Md(s);if(c.length&&Mr(e,c,null),!a.length)return;const d=o.match(_a)?Ts(r):null;if(!d){Mr(e,a,null);return}d.prepare(r,o,a).forEach(h=>{Rd(r,h,f=>{Mr(e,h.icons,f)})})}))}const Ad=(e,t)=>{const r=kd(e,!0,Ha()),o=Sd(r);if(!o.pending.length){let d=!0;return t&&setTimeout(()=>{d&&t(o.loaded,o.missing,o.pending,$i)}),()=>{d=!1}}const s=Object.create(null),i=[];let a,c;return o.pending.forEach(d=>{const{provider:u,prefix:h}=d;if(h===c&&u===a)return;a=u,c=h,i.push(vr(u,h));const f=s[u]||(s[u]=Object.create(null));f[h]||(f[h]=[])}),o.pending.forEach(d=>{const{provider:u,prefix:h,name:f}=d,p=vr(u,h),g=p.pendingIcons||(p.pendingIcons=new Set);g.has(f)||(g.add(f),s[u][h].push(f))}),i.forEach(d=>{const u=s[d.provider][d.prefix];u.length&&Id(d,u)}),t?Cd(t,o,i):$i};function Dd(e,t){const r={...e};for(const o in t){const s=t[o],i=typeof s;o in Ua?(s===null||s&&(i==="string"||i==="number"))&&(r[o]=s):i===typeof r[o]&&(r[o]=o==="rotate"?s%4:s)}return r}const Ld=/[\s,]+/;function Pd(e,t){t.split(Ld).forEach(r=>{switch(r.trim()){case"horizontal":e.hFlip=!0;break;case"vertical":e.vFlip=!0;break}})}function Fd(e,t=0){const r=e.replace(/^-?[0-9.]*/,"");function o(s){for(;s<0;)s+=4;return s%4}if(r===""){const s=parseInt(e);return isNaN(s)?0:o(s)}else if(r!==e){let s=0;switch(r){case"%":s=25;break;case"deg":s=90}if(s){let i=parseFloat(e.slice(0,e.length-r.length));return isNaN(i)?0:(i=i/s,i%1===0?o(i):0)}}return t}function zd(e,t){let r=e.indexOf("xlink:")===-1?"":' xmlns:xlink="http://www.w3.org/1999/xlink"';for(const o in t)r+=" "+o+'="'+t[o]+'"';return'<svg xmlns="http://www.w3.org/2000/svg"'+r+">"+e+"</svg>"}function Od(e){return e.replace(/"/g,"'").replace(/%/g,"%25").replace(/#/g,"%23").replace(/</g,"%3C").replace(/>/g,"%3E").replace(/\s+/g," ")}function Bd(e){return"data:image/svg+xml,"+Od(e)}function _d(e){return'url("'+Bd(e)+'")'}let Pr;function Hd(){try{Pr=window.trustedTypes.createPolicy("iconify",{createHTML:e=>e})}catch{Pr=null}}function $d(e){return Pr===void 0&&Hd(),Pr?Pr.createHTML(e):e}const Va={...Ya,inline:!1},Ud={xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink","aria-hidden":!0,role:"img"},Yd={display:"inline-block"},Rs={backgroundColor:"currentColor"},Ga={backgroundColor:"transparent"},Yi={Image:"var(--svg)",Repeat:"no-repeat",Size:"100% 100%"},Wi={WebkitMask:Rs,mask:Rs,background:Ga};for(const e in Wi){const t=Wi[e];for(const r in Yi)t[e+r]=Yi[r]}const Wd={...Va,inline:!0};function Xi(e){return e+(e.match(/^[-0-9.]+$/)?"px":"")}const Xd=(e,t,r)=>{const o=t.inline?Wd:Va,s=Dd(o,t),i=t.mode||"svg",a={},c=t.style||{},d={...i==="svg"?Ud:{}};if(r){const y=Do(r,!1,!0);if(y){const v=["iconify"],w=["provider","prefix"];for(const C of w)y[C]&&v.push("iconify--"+y[C]);d.className=v.join(" ")}}for(let y in t){const v=t[y];if(v!==void 0)switch(y){case"icon":case"style":case"children":case"onLoad":case"mode":case"ssr":case"fallback":break;case"_ref":d.ref=v;break;case"className":d[y]=(d[y]?d[y]+" ":"")+v;break;case"inline":case"hFlip":case"vFlip":s[y]=v===!0||v==="true"||v===1;break;case"flip":typeof v=="string"&&Pd(s,v);break;case"color":a.color=v;break;case"rotate":typeof v=="string"?s[y]=Fd(v):typeof v=="number"&&(s[y]=v);break;case"ariaHidden":case"aria-hidden":v!==!0&&v!=="true"&&delete d["aria-hidden"];break;default:o[y]===void 0&&(d[y]=v)}}const u=id(e,s),h=u.attributes;if(s.inline&&(a.verticalAlign="-0.125em"),i==="svg"){d.style={...a,...c},Object.assign(d,h);let y=0,v=t.id;return typeof v=="string"&&(v=v.replace(/-/g,"_")),d.dangerouslySetInnerHTML={__html:$d(dd(u.body,v?()=>v+"ID"+y++:"iconifyReact"))},l.createElement("svg",d)}const{body:f,width:p,height:g}=e,b=i==="mask"||(i==="bg"?!1:f.indexOf("currentColor")!==-1),x=zd(f,{...h,width:p+"",height:g+""});return d.style={...a,"--svg":_d(x),width:Xi(h.width),height:Xi(h.height),...Yd,...b?Rs:Ga,...c},l.createElement("span",d)};Ha(!0);ud("",yd);if(typeof document<"u"&&typeof window<"u"){const e=window;if(e.IconifyPreload!==void 0){const t=e.IconifyPreload,r="Invalid IconifyPreload syntax.";typeof t=="object"&&t!==null&&(t instanceof Array?t:[t]).forEach(o=>{try{(typeof o!="object"||o===null||o instanceof Array||typeof o.icons!="object"||typeof o.prefix!="string"||!Qc(o))&&console.error(r)}catch{console.error(r)}})}if(e.IconifyProviders!==void 0){const t=e.IconifyProviders;if(typeof t=="object"&&t!==null)for(let r in t){const o="IconifyProviders["+r+"] is invalid.";try{const s=t[r];if(typeof s!="object"||!s||s.resources===void 0)continue;hd(r,s)||console.error(o)}catch{console.error(o)}}}}function Ka(e){const[t,r]=l.useState(!!e.ssr),[o,s]=l.useState({});function i(g){if(g){const b=e.icon;if(typeof b=="object")return{name:"",data:b};const x=Oi(b);if(x)return{name:b,data:x}}return{name:""}}const[a,c]=l.useState(i(!!e.ssr));function d(){const g=o.callback;g&&(g(),s({}))}function u(g){if(JSON.stringify(a)!==JSON.stringify(g))return d(),c(g),!0}function h(){var g;const b=e.icon;if(typeof b=="object"){u({name:"",data:b});return}const x=Oi(b);if(u({name:b,data:x}))if(x===void 0){const y=Ad([b],h);s({callback:y})}else x&&((g=e.onLoad)===null||g===void 0||g.call(e,b))}l.useEffect(()=>(r(!0),d),[]),l.useEffect(()=>{t&&h()},[e.icon,t]);const{name:f,data:p}=a;return p?Xd({...Gs,...p},e,f):e.children?e.children:e.fallback?e.fallback:l.createElement("span",{})}const de=l.forwardRef((e,t)=>Ka({...e,_ref:t}));l.forwardRef((e,t)=>Ka({inline:!0,...e,_ref:t}));const Vd={"eos-icons:loading":{body:'<path fill="currentColor" d="M12 2A10 10 0 1 0 22 12A10 10 0 0 0 12 2Zm0 18a8 8 0 1 1 8-8A8 8 0 0 1 12 20Z" opacity=".5"/><path fill="currentColor" d="M20 12h2A10 10 0 0 0 12 2V4A8 8 0 0 1 20 12Z"><animateTransform attributeName="transform" dur="1s" from="0 12 12" repeatCount="indefinite" to="360 12 12" type="rotate"/></path>',width:24,height:24},"fa6-solid:icons":{body:'<path fill="currentColor" d="M500.3 7.3c7.4 6 11.7 15.1 11.7 24.7v144c0 26.5-28.7 48-64 48s-64-21.5-64-48s28.7-48 64-48V71l-96 19.2V208c0 26.5-28.7 48-64 48s-64-21.5-64-48s28.7-48 64-48V64c0-15.3 10.8-28.4 25.7-31.4l160-32c9.4-1.9 19.1.6 26.6 6.6zM74.7 304l11.8-17.8c5.9-8.9 15.9-14.2 26.6-14.2h61.7c10.7 0 20.7 5.3 26.6 14.2l11.9 17.8H240c26.5 0 48 21.5 48 48v112c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V352c0-26.5 21.5-48 48-48zM192 408a48 48 0 1 0-96 0a48 48 0 1 0 96 0m286.7-129.7L440.3 368H496c6.7 0 12.6 4.1 15 10.4s.6 13.3-4.4 17.7l-128 112c-5.6 4.9-13.9 5.3-19.9.9s-8.2-12.4-5.3-19.2l38.3-89.8H336c-6.7 0-12.6-4.1-15-10.4s-.6-13.3 4.4-17.7l128-112c5.6-4.9 13.9-5.3 19.9-.9s8.2 12.4 5.3 19.2zm-339-59.2c-6.5 6.5-17 6.5-23 0l-96.8-99.9c-28-29-26.5-76.9 5-103.9c27-23.5 68.4-19 93.4 6.5l10 10.5l9.5-10.5c25-25.5 65.9-30 93.9-6.5c31 27 32.5 74.9 4.5 103.9l-96.4 99.9z"/>',width:512,height:512},"gravity-ui:arrow-down-to-square":{body:'<path fill="currentColor" fill-rule="evenodd" d="M8.53 11.78a.75.75 0 0 1-1.06 0l-2.5-2.5a.75.75 0 0 1 1.06-1.06l1.22 1.22V1.75a.75.75 0 0 1 1.5 0v7.69l1.22-1.22a.75.75 0 1 1 1.06 1.06zM4.25 4a.75.75 0 1 1 0 1.5H4A1.5 1.5 0 0 0 2.5 7v5A1.5 1.5 0 0 0 4 13.5h8a1.5 1.5 0 0 0 1.5-1.5V7A1.5 1.5 0 0 0 12 5.5h-.25a.75.75 0 0 1 0-1.5H12a3 3 0 0 1 3 3v5a3 3 0 0 1-3 3H4a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:arrow-left":{body:'<path fill="currentColor" fill-rule="evenodd" d="M14.75 8a.75.75 0 0 1-.75.75H3.81l2.72 2.72a.75.75 0 1 1-1.06 1.06l-4-4a.75.75 0 0 1 0-1.06l4-4a.75.75 0 0 1 1.06 1.06L3.81 7.25H14a.75.75 0 0 1 .75.75" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:arrow-rotate-left":{body:'<path fill="currentColor" fill-rule="evenodd" d="M8 1.5a6.5 6.5 0 1 1-6.445 7.348a.75.75 0 1 1 1.487-.194A5.001 5.001 0 1 0 4.43 4.5h1.32a.75.75 0 0 1 0 1.5h-3A.75.75 0 0 1 2 5.25v-3a.75.75 0 0 1 1.5 0v1.06A6.48 6.48 0 0 1 8 1.5" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:bars":{body:'<path fill="currentColor" fill-rule="evenodd" d="M1.25 3.25A.75.75 0 0 1 2 2.5h12A.75.75 0 0 1 14 4H2a.75.75 0 0 1-.75-.75m0 4.75A.75.75 0 0 1 2 7.25h12a.75.75 0 0 1 0 1.5H2A.75.75 0 0 1 1.25 8M2 12a.75.75 0 0 0 0 1.5h12a.75.75 0 0 0 0-1.5z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:bold":{body:'<path fill="currentColor" fill-rule="evenodd" d="M4.25 2.25A.75.75 0 0 0 3.5 3v10c0 .414.336.75.75.75H9.5a3.25 3.25 0 0 0 1.477-6.146A3.25 3.25 0 0 0 8.5 2.25zm3.5 5a1.75 1.75 0 1 0 0-3.5h-2v3.5zm-2 1.5v3.5h3a1.75 1.75 0 1 0 0-3.5z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:copy":{body:'<path fill="currentColor" fill-rule="evenodd" d="M12 2.5H8A1.5 1.5 0 0 0 6.5 4v1H8a3 3 0 0 1 3 3v1.5h1A1.5 1.5 0 0 0 13.5 8V4A1.5 1.5 0 0 0 12 2.5M11 11h1a3 3 0 0 0 3-3V4a3 3 0 0 0-3-3H8a3 3 0 0 0-3 3v1H4a3 3 0 0 0-3 3v4a3 3 0 0 0 3 3h4a3 3 0 0 0 3-3zM4 6.5h4A1.5 1.5 0 0 1 9.5 8v4A1.5 1.5 0 0 1 8 13.5H4A1.5 1.5 0 0 1 2.5 12V8A1.5 1.5 0 0 1 4 6.5" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:italic":{body:'<path fill="currentColor" fill-rule="evenodd" d="M7.25 2a.75.75 0 0 0 0 1.5h1.317l-2.7 9H4.25a.75.75 0 1 0 0 1.5h4.5a.75.75 0 0 0 0-1.5H7.433l2.7-9h1.617a.75.75 0 0 0 0-1.5z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:layers":{body:'<path fill="currentColor" fill-rule="evenodd" d="m2.789 5.283l4.037-2.02A2.5 2.5 0 0 1 7.944 3h.112c.388 0 .77.09 1.118.264l4.037 2.019a.522.522 0 0 1 0 .934l-4.037 2.02a2.5 2.5 0 0 1-1.118.263h-.112a2.5 2.5 0 0 1-1.118-.264L2.79 6.217a.523.523 0 0 1 0-.934M1 5.75c0-.766.433-1.466 1.118-1.809l4.037-2.019a4 4 0 0 1 1.79-.422h.11a4 4 0 0 1 1.79.422l4.037 2.019a2.023 2.023 0 0 1 0 3.618l-.882.44l.882.442a2.023 2.023 0 0 1 0 3.618l-4.037 2.019a4 4 0 0 1-1.79.422h-.11a4 4 0 0 1-1.79-.422l-4.037-2.02a2.023 2.023 0 0 1 0-3.617L3 8l-.882-.441A2.02 2.02 0 0 1 1 5.75m3.677 3.088l-1.888.945a.523.523 0 0 0 0 .934l4.037 2.019A2.5 2.5 0 0 0 7.944 13h.112a2.5 2.5 0 0 0 1.118-.264l4.037-2.019a.523.523 0 0 0 0-.934l-1.888-.945l-1.478.74a4 4 0 0 1-1.79.422h-.11a4 4 0 0 1-1.79-.422z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:magnifier":{body:'<path fill="currentColor" fill-rule="evenodd" d="M11.5 7a4.5 4.5 0 1 1-9 0a4.5 4.5 0 0 1 9 0m-.82 4.74a6 6 0 1 1 1.06-1.06l2.79 2.79a.75.75 0 1 1-1.06 1.06z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:pencil":{body:'<path fill="currentColor" fill-rule="evenodd" d="M11.423 1A3.577 3.577 0 0 1 15 4.577c0 .27-.108.53-.3.722l-.528.529l-1.971 1.971l-5.059 5.059a3 3 0 0 1-1.533.82l-2.638.528a1 1 0 0 1-1.177-1.177l.528-2.638a3 3 0 0 1 .82-1.533l5.059-5.059l2.5-2.5c.191-.191.451-.299.722-.299m-2.31 4.009l-4.91 4.91a1.5 1.5 0 0 0-.41.766l-.38 1.903l1.902-.38a1.5 1.5 0 0 0 .767-.41l4.91-4.91a2.08 2.08 0 0 0-1.88-1.88m3.098.658a3.6 3.6 0 0 0-1.878-1.879l1.28-1.28c.995.09 1.788.884 1.878 1.88z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:picture":{body:'<path fill="currentColor" fill-rule="evenodd" d="M11.5 3h-7A1.5 1.5 0 0 0 3 4.5v5.027l.962-.7a1.75 1.75 0 0 1 2.079.016l.928.696l2.368-2.03a1.75 1.75 0 0 1 2.325.043L13 8.787V4.5A1.5 1.5 0 0 0 11.5 3m3 7.498V4.5a3 3 0 0 0-3-3h-7a3 3 0 0 0-3 3v7a3 3 0 0 0 3 3h7a3 3 0 0 0 3-3zm-1.5.33l-2.355-2.174a.25.25 0 0 0-.332-.006L7.488 11.07l-.457.392l-.481-.361l-1.41-1.057a.25.25 0 0 0-.296-.002L3 11.381v.119A1.5 1.5 0 0 0 4.5 13h7a1.5 1.5 0 0 0 1.5-1.5zM7.5 6a1.5 1.5 0 1 1-3 0a1.5 1.5 0 0 1 3 0" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:plus":{body:'<path fill="currentColor" fill-rule="evenodd" d="M8 1.75a.75.75 0 0 1 .75.75v4.75h4.75a.75.75 0 0 1 0 1.5H8.75v4.75a.75.75 0 0 1-1.5 0V8.75H2.5a.75.75 0 0 1 0-1.5h4.75V2.5A.75.75 0 0 1 8 1.75" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:scissors":{body:'<path fill="currentColor" fill-rule="evenodd" d="M4.5 6a1.5 1.5 0 1 0 0-3a1.5 1.5 0 0 0 0 3m-3-1.5a3 3 0 0 0 4.524 2.585L6.939 8l-.915.915a3 3 0 1 0 1.06 1.06L8.122 8.94l5.501 3.209a.75.75 0 1 0 .756-1.296L9.488 8l4.89-2.852a.75.75 0 0 0-.756-1.296l-5.5 3.209l-1.037-1.037A3 3 0 1 0 1.5 4.5m3 5.5a1.5 1.5 0 1 1 0 3a1.5 1.5 0 0 1 0-3" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:sparkles":{body:'<path fill="currentColor" d="M13 10a.75.75 0 0 1 .725.556a2.37 2.37 0 0 0 1.72 1.72a.75.75 0 0 1 0 1.449a2.37 2.37 0 0 0-1.72 1.72a.75.75 0 0 1-1.45 0a2.37 2.37 0 0 0-1.72-1.72a.75.75 0 0 1 0-1.45a2.37 2.37 0 0 0 1.72-1.72l.043-.117A.75.75 0 0 1 13 10M7 0a1.5 1.5 0 0 1 1.48 1.253c.242 1.455.696 2.364 1.3 2.968c.603.603 1.512 1.057 2.967 1.3a1.5 1.5 0 0 1 0 2.958c-1.455.243-2.364.697-2.968 1.3c-.603.604-1.057 1.513-1.3 2.968a1.5 1.5 0 0 1-2.958 0c-.243-1.455-.697-2.364-1.3-2.968c-.604-.603-1.513-1.057-2.968-1.3a1.5 1.5 0 0 1 0-2.958c1.455-.243 2.364-.697 2.968-1.3c.603-.604 1.057-1.513 1.3-2.968l.028-.133A1.5 1.5 0 0 1 7 0m0 1.5C6.45 4.8 4.8 6.45 1.5 7c3.3.55 4.95 2.2 5.5 5.5c.55-3.3 2.2-4.95 5.5-5.5C9.2 6.45 7.55 4.8 7 1.5"/>',width:24,height:24},"gravity-ui:text":{body:'<path fill="currentColor" fill-rule="evenodd" d="M3.279 2.544A.75.75 0 0 1 4 2h8a.75.75 0 0 1 .721.544l.5 1.75a.75.75 0 1 1-1.442.412L11.434 3.5H8.75l-.004 9H9.5a.75.75 0 0 1 0 1.5h-3a.75.75 0 0 1 0-1.5h.746l.004-9H4.566L4.22 4.706a.75.75 0 1 1-1.442-.412z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:text-align-center":{body:'<path fill="currentColor" fill-rule="evenodd" d="M2.75 2a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm0 7a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm2 3.5a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5zM4 6.25a.75.75 0 0 1 .75-.75h6.5a.75.75 0 0 1 0 1.5h-6.5A.75.75 0 0 1 4 6.25" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:text-align-justify":{body:'<path fill="currentColor" fill-rule="evenodd" d="M2.75 2a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zM2 6.25a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H2.75A.75.75 0 0 1 2 6.25M2.75 9a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm0 3.5a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:text-align-left":{body:'<path fill="currentColor" fill-rule="evenodd" d="M2.75 2a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm0 7a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm0 3.5a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5zM2 6.25a.75.75 0 0 1 .75-.75h6.5a.75.75 0 0 1 0 1.5h-6.5A.75.75 0 0 1 2 6.25" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:text-align-right":{body:'<path fill="currentColor" fill-rule="evenodd" d="M2.75 2a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zM6 6.25a.75.75 0 0 1 .75-.75h6.5a.75.75 0 0 1 0 1.5h-6.5A.75.75 0 0 1 6 6.25M2.75 9a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm4 3.5a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:underline":{body:'<path fill="currentColor" fill-rule="evenodd" d="M5 2.75a.75.75 0 0 0-1.5 0V7a4.5 4.5 0 0 0 9 0V2.75a.75.75 0 0 0-1.5 0V7a3 3 0 0 1-6 0zm-.75 9.75a.75.75 0 0 0 0 1.5h7.5a.75.75 0 0 0 0-1.5z" clip-rule="evenodd"/>',width:24,height:24},"healthicons:polygon":{body:'<path fill="currentColor" fill-rule="evenodd" d="M28 10c0 .507-.094.992-.266 1.438l7.696 5.497a4 4 0 1 1 2.706 7.063l-2.32 10.437A4 4 0 1 1 30.126 39H17.874A4.002 4.002 0 0 1 10 38a4 4 0 0 1 2.184-3.565l-2.32-10.437a4 4 0 1 1 2.706-7.063l7.696-5.497A4 4 0 1 1 28 10m-6.57 3.065l-7.696 5.497a4 4 0 0 1-1.917 5.003l2.319 10.437A4 4 0 0 1 17.874 37h12.252a4 4 0 0 1 3.738-2.998l2.32-10.437a4 4 0 0 1-1.918-5.003l-7.695-5.497A3.98 3.98 0 0 1 24 14a3.98 3.98 0 0 1-2.57-.935" clip-rule="evenodd"/>',width:48,height:48},"heroicons:swatch":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4.098 19.902a3.75 3.75 0 0 0 5.304 0l6.401-6.402M6.75 21A3.75 3.75 0 0 1 3 17.25V4.125C3 3.504 3.504 3 4.125 3h5.25c.621 0 1.125.504 1.125 1.125v4.072M6.75 21a3.75 3.75 0 0 0 3.75-3.75V8.197M6.75 21h13.125c.621 0 1.125-.504 1.125-1.125v-5.25c0-.621-.504-1.125-1.125-1.125h-4.072M10.5 8.197l2.88-2.88a1.124 1.124 0 0 1 1.59 0l3.712 3.713c.44.44.44 1.152 0 1.59l-2.879 2.88M6.75 17.25h.008v.008H6.75z"/>',width:24,height:24},"hugeicons:layer-bring-forward":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m15.89 11.5l3.397 1.56C21.096 13.892 22 14.308 22 15s-.904 1.109-2.713 1.94l-4.893 2.247c-1.18.542-1.77.813-2.394.813s-1.214-.271-2.394-.813l-4.893-2.248C2.904 16.11 2 15.693 2 15s.904-1.109 2.713-1.94L8.11 11.5m3.89-7V15m3-8c-.59-.607-2.16-3-3-3S9.59 6.393 9 7"/>',width:24,height:24},"hugeicons:layer-send-backward":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m15.89 12.5l3.397-1.56C21.096 10.108 22 9.692 22 9s-.904-1.109-2.713-1.94l-4.893-2.247C13.214 4.271 12.624 4 12 4s-1.214.271-2.394.813L4.713 7.061C2.904 7.89 2 8.307 2 9s.904 1.109 2.713 1.94L8.11 12.5m3.89 7V9m3 8c-.59.607-2.16 3-3 3s-2.41-2.393-3-3"/>',width:24,height:24},"lucide:a-large-small":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m15 16l2.536-7.328a1.02 1.02 1 0 1 1.928 0L22 16m-6.303-2h5.606M2 16l4.039-9.69a.5.5 0 0 1 .923 0L11 16m-7.696-3h6.392"/>',width:24,height:24},"lucide:aperture":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="m14.31 8l5.74 9.94M9.69 8h11.48M7.38 12l5.74-9.94M9.69 16L3.95 6.06M14.31 16H2.83m13.79-4l-5.74 9.94"/></g>',width:24,height:24},"lucide:arrow-left":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m12 19l-7-7l7-7m7 7H5"/>',width:24,height:24},"lucide:arrow-up-from-dot":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="m5 9l7-7l7 7m-7 7V2"/><circle cx="12" cy="21" r="1"/></g>',width:24,height:24},"lucide:blend":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="9" cy="9" r="7"/><circle cx="15" cy="15" r="7"/></g>',width:24,height:24},"lucide:case-upper":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11h4.5a1 1 0 0 1 0 5h-4a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h3a1 1 0 0 1 0 5M2 16l4.039-9.69a.5.5 0 0 1 .923 0L11 16m-7.696-3h6.392"/>',width:24,height:24},"lucide:circle":{body:'<circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>',width:24,height:24},"lucide:circle-dashed":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.1 2.182a10 10 0 0 1 3.8 0m0 19.636a10 10 0 0 1-3.8 0m7.509-18.097a10 10 0 0 1 2.69 2.7M2.182 13.9a10 10 0 0 1 0-3.8m18.097 7.509a10 10 0 0 1-2.7 2.69M21.818 10.1a10 10 0 0 1 0 3.8M3.721 6.391a10 10 0 0 1 2.7-2.69m-.03 16.578a10 10 0 0 1-2.69-2.7"/>',width:24,height:24},"lucide:cloud":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9"/>',width:24,height:24},"lucide:copy":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></g>',width:24,height:24},"lucide:credit-card":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="20" height="14" x="2" y="5" rx="2"/><path d="M2 10h20"/></g>',width:24,height:24},"lucide:crop":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M6 2v14a2 2 0 0 0 2 2h14"/><path d="M18 22V8a2 2 0 0 0-2-2H2"/></g>',width:24,height:24},"lucide:ellipsis-vertical":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></g>',width:24,height:24},"lucide:flag":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528"/>',width:24,height:24},"lucide:flip-horizontal-2":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m3 7l5 5l-5 5zm18 0l-5 5l5 5zm-9 13v2m0-8v2m0-8v2m0-8v2"/>',width:24,height:24},"lucide:flip-vertical-2":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m17 3l-5 5l-5-5zm0 18l-5-5l-5 5zM4 12H2m8 0H8m8 0h-2m8 0h-2"/>',width:24,height:24},"lucide:folder-open":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m6 14l1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"/>',width:24,height:24},"lucide:folder-plus":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m-3-3h6m5 7a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/>',width:24,height:24},"lucide:grid-2x2":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M12 3v18m-9-9h18"/><rect width="18" height="18" x="3" y="3" rx="2"/></g>',width:24,height:24},"lucide:grid-3x3":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M3 9h18M3 15h18M9 3v18m6-18v18"/></g>',width:24,height:24},"lucide:grip-vertical":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="9" cy="12" r="1"/><circle cx="9" cy="5" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="19" r="1"/></g>',width:24,height:24},"lucide:hexagon":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16"/>',width:24,height:24},"lucide:image":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15l-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></g>',width:24,height:24},"lucide:italic":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 4h-9m4 16H5M15 4L9 20"/>',width:24,height:24},"lucide:layout-grid":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></g>',width:24,height:24},"lucide:lightbulb":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 14c.2-1 .7-1.7 1.5-2.5c1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5c.7.7 1.3 1.5 1.5 2.5m0 4h6m-5 4h4"/>',width:24,height:24},"lucide:loader-circle":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 1 1-6.219-8.56"/>',width:24,height:24},"lucide:minus":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h14"/>',width:24,height:24},"lucide:moon":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401"/>',width:24,height:24},"lucide:move-vertical":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 2v20m-4-4l4 4l4-4M8 6l4-4l4 4"/>',width:24,height:24},"lucide:paint-bucket":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 7L6 2m12.992 10H2.041m19.104 6.38A3.34 3.34 0 0 1 20 16.5a3.3 3.3 0 0 1-1.145 1.88c-.575.46-.855 1.02-.855 1.595A2 2 0 0 0 20 22a2 2 0 0 0 2-2.025c0-.58-.285-1.13-.855-1.595M8.5 4.5l2.148-2.148a1.205 1.205 0 0 1 1.704 0l7.296 7.296a1.205 1.205 0 0 1 0 1.704l-7.592 7.592a3.615 3.615 0 0 1-5.112 0l-3.888-3.888a3.615 3.615 0 0 1 0-5.112L5.67 7.33"/>',width:24,height:24},"lucide:palette":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M12 22a1 1 0 0 1 0-20a10 9 0 0 1 10 9a5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z"/><circle cx="13.5" cy="6.5" r=".5" fill="currentColor"/><circle cx="17.5" cy="10.5" r=".5" fill="currentColor"/><circle cx="6.5" cy="12.5" r=".5" fill="currentColor"/><circle cx="8.5" cy="7.5" r=".5" fill="currentColor"/></g>',width:24,height:24},"lucide:pen-line":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 21h8m.174-14.188a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/>',width:24,height:24},"lucide:pen-tool":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M15.707 21.293a1 1 0 0 1-1.414 0l-1.586-1.586a1 1 0 0 1 0-1.414l5.586-5.586a1 1 0 0 1 1.414 0l1.586 1.586a1 1 0 0 1 0 1.414z"/><path d="m18 13l-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18M2.3 2.3l7.286 7.286"/><circle cx="11" cy="11" r="2"/></g>',width:24,height:24},"lucide:redo-2":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="m15 14l5-5l-5-5"/><path d="M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13"/></g>',width:24,height:24},"lucide:rotate-ccw":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M3 12a9 9 0 1 0 9-9a9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></g>',width:24,height:24},"lucide:rotate-cw":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/></g>',width:24,height:24},"lucide:scissors":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="6" cy="6" r="3"/><path d="M8.12 8.12L12 12m8-8L8.12 15.88"/><circle cx="6" cy="18" r="3"/><path d="M14.8 14.8L20 20"/></g>',width:24,height:24},"lucide:settings":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0a2.34 2.34 0 0 0 3.319 1.915a2.34 2.34 0 0 1 2.33 4.033a2.34 2.34 0 0 0 0 3.831a2.34 2.34 0 0 1-2.33 4.033a2.34 2.34 0 0 0-3.319 1.915a2.34 2.34 0 0 1-4.659 0a2.34 2.34 0 0 0-3.32-1.915a2.34 2.34 0 0 1-2.33-4.033a2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"/><circle cx="12" cy="12" r="3"/></g>',width:24,height:24},"lucide:shapes":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z"/><rect width="7" height="7" x="3" y="14" rx="1"/><circle cx="17.5" cy="17.5" r="3.5"/></g>',width:24,height:24},"lucide:sparkles":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594zM20 2v4m2-2h-4"/><circle cx="4" cy="20" r="2"/></g>',width:24,height:24},"lucide:square":{body:'<rect width="18" height="18" x="3" y="3" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" rx="2"/>',width:24,height:24},"lucide:square-round-corner":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 11a8 8 0 0 0-8-8m8 12v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/>',width:24,height:24},"lucide:stamp":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 13V8.5C14 7 15 7 15 5a3 3 0 0 0-6 0c0 2 1 2 1 3.5V13m10 2.5a2.5 2.5 0 0 0-2.5-2.5h-11A2.5 2.5 0 0 0 4 15.5V17a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1zM5 22h14"/>',width:24,height:24},"lucide:star":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.12 2.12 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.12 2.12 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.12 2.12 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.12 2.12 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.12 2.12 0 0 0 1.597-1.16z"/>',width:24,height:24},"lucide:sun":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M4.93 4.93l1.41 1.41m11.32 11.32l1.41 1.41M2 12h2m16 0h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"/></g>',width:24,height:24},"lucide:text-cursor":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 22h-1a4 4 0 0 1-4-4V6a4 4 0 0 1 4-4h1M7 22h1a4 4 0 0 0 4-4M7 2h1a4 4 0 0 1 4 4"/>',width:24,height:24},"lucide:trash":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>',width:24,height:24},"lucide:trending-up":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M16 7h6v6"/><path d="m22 7l-8.5 8.5l-5-5L2 17"/></g>',width:24,height:24},"lucide:triangle":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.73 4a2 2 0 0 0-3.46 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/>',width:24,height:24},"lucide:type":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2M9 20h6"/>',width:24,height:24},"lucide:undo-2":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M9 14L4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/></g>',width:24,height:24},"lucide:venetian-mask":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M18 11c-1.5 0-2.5.5-3 2"/><path d="M4 6a2 2 0 0 0-2 2v4a5 5 0 0 0 5 5a8 8 0 0 1 5 2a8 8 0 0 1 5-2a5 5 0 0 0 5-5V8a2 2 0 0 0-2-2h-3a8 8 0 0 0-5 2a8 8 0 0 0-5-2z"/><path d="M6 11c1.5 0 2.5.5 3 2"/></g>',width:24,height:24},"lucide:waves":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2 6c.6.5 1.2 1 2.5 1C7 7 7 5 9.5 5c2.6 0 2.4 2 5 2c2.5 0 2.5-2 5-2c1.3 0 1.9.5 2.5 1M2 12c.6.5 1.2 1 2.5 1c2.5 0 2.5-2 5-2c2.6 0 2.4 2 5 2c2.5 0 2.5-2 5-2c1.3 0 1.9.5 2.5 1M2 18c.6.5 1.2 1 2.5 1c2.5 0 2.5-2 5-2c2.6 0 2.4 2 5 2c2.5 0 2.5-2 5-2c1.3 0 1.9.5 2.5 1"/>',width:24,height:24},"material-symbols:award-star-outline":{body:'<path fill="currentColor" d="M9.075 16.25L12 14.475l2.925 1.775l-.775-3.325l2.6-2.25l-3.425-.275L12 7.25l-1.325 3.15l-3.425.275l2.6 2.25zM12 23.3L8.65 20H4v-4.65L.7 12L4 8.65V4h4.65L12 .7L15.35 4H20v4.65L23.3 12L20 15.35V20h-4.65zm0-2.8l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18h3.5zm0-8.5"/>',width:24,height:24},"mdi:cube-outline":{body:'<path fill="currentColor" d="M21 16.5c0 .38-.21.71-.53.88l-7.9 4.44c-.16.12-.36.18-.57.18s-.41-.06-.57-.18l-7.9-4.44A.99.99 0 0 1 3 16.5v-9c0-.38.21-.71.53-.88l7.9-4.44c.16-.12.36-.18.57-.18s.41.06.57.18l7.9 4.44c.32.17.53.5.53.88zM12 4.15L6.04 7.5L12 10.85l5.96-3.35zM5 15.91l6 3.38v-6.71L5 9.21zm14 0v-6.7l-6 3.37v6.71z"/>',width:24,height:24},"mdi:format-color-fill":{body:'<path fill="currentColor" d="M19 11.5s-2 2.17-2 3.5a2 2 0 0 0 2 2a2 2 0 0 0 2-2c0-1.33-2-3.5-2-3.5M5.21 10L10 5.21L14.79 10m1.77-1.06L7.62 0L6.21 1.41l2.38 2.38l-5.15 5.15c-.59.56-.59 1.53 0 2.12l5.5 5.5c.29.29.68.44 1.06.44s.77-.15 1.06-.44l5.5-5.5c.59-.59.59-1.56 0-2.12"/>',width:24,height:24},"mdi:image-remove":{body:'<path fill="currentColor" d="M13.3 21H5c-1.1 0-2-.9-2-2V5c0-1.1.9-2 2-2h14c1.1 0 2 .9 2 2v8.3c-.6-.2-1.3-.3-2-.3c-1.1 0-2.2.3-3.1.9L14.5 12L11 16.5l-2.5-3L5 18h8.1c-.1.3-.1.7-.1 1c0 .7.1 1.4.3 2m7.1-2l2.1 2.1l-1.4 1.4l-2.1-2.1l-2.1 2.1l-1.4-1.4l2.1-2.1l-2.1-2.1l1.4-1.4l2.1 2.1l2.1-2.1l1.4 1.4z"/>',width:24,height:24},"ph:monitor-fill":{body:'<path fill="currentColor" d="M232 64v112a24 24 0 0 1-24 24H48a24 24 0 0 1-24-24V64a24 24 0 0 1 24-24h160a24 24 0 0 1 24 24m-72 152H96a8 8 0 0 0 0 16h64a8 8 0 0 0 0-16"/>',width:256,height:256},"radix-icons:font-size":{body:'<path fill="currentColor" d="M2.5 2.1a.4.4 0 0 1 .283.117l2 2l.05.064a.4.4 0 0 1-.05.503a.4.4 0 0 1-.503.05l-.063-.05L2.9 3.467v8.067l1.317-1.317a.4.4 0 0 1 .566.566l-2 2a.4.4 0 0 1-.566 0l-2-2l-.051-.063a.4.4 0 0 1 .554-.554l.063.051l1.316 1.316V3.467L.783 4.784a.401.401 0 0 1-.566-.567l2-2l.061-.05A.4.4 0 0 1 2.5 2.1m5.47 9.64a.501.501 0 0 1-.94-.34zm2.53-8.99a.5.5 0 0 1 .47.33l3 8.32a.5.5 0 0 1-.94.34l-.983-2.724H8.953l-.982 2.724l-.471-.17l-.47-.17l3-8.32l.031-.07a.5.5 0 0 1 .439-.26M9.259 8.166h2.482L10.5 4.725z"/>',width:15,height:15}};function Gd(){for(const[e,t]of Object.entries(Vd))$a(e,t)}let Vi=!1;function Kd(){Vi||(Gd(),Vi=!0)}const qa={elements:["text","image","shape","path","group"],transforms:["custom","circle","lean","arch","ascend","wave","flag","image","group","shape","path"],effects:["stroke","mask","distress","knockout"],panels:["layers","effects","export","images","artboards"],tools:["select","pen","crop","zoom"],features:{export:!0,multiArtboard:!0,richText:!0,undo:!0,keyboardShortcuts:!0}},Js={elements:["text","image"],transforms:["custom","circle","arch","wave","image"],effects:["stroke"],panels:[],tools:["select","zoom"],features:{export:!0,multiArtboard:!1,richText:!1,undo:!0,keyboardShortcuts:!0}},Za={name:"compact-customizer",layout:{slots:{topbar:["contextual-toolbar"],canvas:["canvas"]}},capabilities:{...Js,effects:["stroke"],panels:[],tools:["select","zoom"]},behavior:{toolbar:"contextual",selection:"single",panelMode:"drawer",onEmptyClick:"deselect",autoExport:!1},style:{density:"compact",toolbarVariant:"pill",panelVariant:"floating"},content:{sampleText:"Your Text",defaultFontFamily:"Poppins"}},Ja={name:"pro-studio",layout:{slots:{topbar:["add-element-menu","undo-redo-controls","contextual-toolbar"],left:["layers-panel"],canvas:["canvas"],right:["effects-panel"]}},capabilities:qa,behavior:{toolbar:"contextual",selection:"multi",panelMode:"sidebar",onEmptyClick:"deselect",autoExport:!1},style:{density:"comfortable",toolbarVariant:"flat",panelVariant:"card"},content:{sampleText:"New Text",defaultFontFamily:"Poppins"}},Qa={name:"embed-only",layout:{slots:{canvas:["canvas"]}},capabilities:{...Js,panels:[],tools:["select"],features:{export:!0,multiArtboard:!1,richText:!1,undo:!0,keyboardShortcuts:!1}},behavior:{toolbar:"none",selection:"single",panelMode:"inline",onEmptyClick:"noop",autoExport:!0},style:{density:"compact",toolbarVariant:"minimal",panelVariant:"flush"}},Ns=new Map([["compact-customizer",Za],["pro-studio",Ja],["embed-only",Qa]]);function el(e){if(typeof e=="string"){const t=Ns.get(e);if(!t){const r=Array.from(Ns.keys()).join(", ");throw new Error(`[resolveKit] Unknown kit preset "${e}". Valid presets: ${r}`)}return t}return e}const tl=l.createContext(null);function qd({kit:e,children:t}){const[r,o]=l.useState(e);l.useEffect(()=>{o(e)},[e]);const s=l.useCallback(a=>{const c=typeof a=="string"?el(a):a;o(c)},[]),i=l.useMemo(()=>({kit:r,setKit:s}),[r,s]);return n.jsx(tl.Provider,{value:i,children:t})}function nl(){const e=l.useContext(tl);if(!e)throw new Error("useKit must be used within a KitProvider");return e}function Zd(){const{kit:e}=nl();return e.capabilities}const Jd=T.createLogger("ElementPreviewRenderer"),Qd={width:40,height:40,padding:4,backgroundColor:"transparent"};function Ms(e,t={}){const r={...Qd,...t},o=document.createElement("canvas");o.width=r.width,o.height=r.height;const s=o.getContext("2d");if(!s)return"";r.backgroundColor!=="transparent"&&(s.fillStyle=r.backgroundColor,s.fillRect(0,0,r.width,r.height)),s.save();try{e instanceof T.GroupElement?tu(s,e,r):eu(s,e,r)}catch(i){Jd.warn("Failed to generate preview:",i)}return s.restore(),o.toDataURL("image/png")}function eu(e,t,r){var g;const o=((g=t.getBoundingBox)==null?void 0:g.call(t))||{x:0,y:0,width:100,height:100},s=o.width,i=o.height;if(s===0||i===0){Gi(e,t,r);return}const a=r.width-r.padding*2,c=r.height-r.padding*2,d=Math.min(a/s,c/i,1),u=s*d,h=i*d,f=r.padding+(a-u)/2,p=r.padding+(c-h)/2;e.save(),e.translate(f-o.x*d,p-o.y*d),e.scale(d,d),typeof t.render=="function"?t.render(e,!1,!1):Gi(e,t,r),e.restore()}function Gi(e,t,r){e.fillStyle="#888888",e.font="10px Arial",e.textAlign="center",e.textBaseline="middle";const o=t.transformType||"Element";e.fillText(o,r.width/2,r.height/2)}function tu(e,t,r){const o=r.width-r.padding*2,s=r.height-r.padding*2,i=r.padding,a=r.padding;e.fillStyle="#888888",e.strokeStyle="#666666",e.lineWidth=1;const c=s*.7,d=a+s*.3,u=o*.4,h=s*.2;e.fillRect(i,d,o,c),e.fillRect(i,d-h,u,h),t.children&&t.children.length>0&&(e.fillStyle="#FFFFFF",e.font="bold 10px Arial",e.textAlign="center",e.textBaseline="middle",e.fillText(t.children.length.toString(),i+o/2,d+c/2))}const Vt=T.createLogger("Layers");async function Ki(e,t=64,r="transparent"){try{return Ms(e,{width:t,height:t,padding:8,backgroundColor:r})||null}catch(o){return Vt.error("Failed to generate preview:",o),null}}function rl(e,t,r,o,s,i=0,a=null){return(i>0?e:e.filter(d=>{const u=d.parentId??null;return d instanceof T.GroupElement,u===null})).map(d=>{const u=d instanceof T.GroupElement,h=t===d.id||r.includes(d.id),f={id:d.id,name:d.name||`Layer ${d.id.slice(0,8)}`,type:d.transformType,visible:d.visible??!0,locked:d.locked??!1,isSelected:h,isGroup:u,depth:i,parentId:a,previewUrl:o.get(d.id)||null,refreshPreview:async()=>{await s(d.id)}};return u&&d instanceof T.GroupElement&&(f.children=rl(d.children,t,r,o,s,i+1,d.id)),f})}function ol(e){const t=[];for(const r of e)t.push(r),r.children&&t.push(...ol(r.children));return t}function Qs(e={}){const{artboardId:t,includeHidden:r=!0,previewSize:o=64,previewBackgroundColor:s="transparent"}=e,{elements:i,selectedId:a,multiSelection:c,artboardManager:d,handleSelectionChange:u,handleElementUpdate:h,setMultiSelection:f,executeAddElement:p,executeRemoveElement:g,executeReorderElement:b}=Yt.useEditor(),x=l.useRef(new Map),[y,v]=l.useState(0),w=d.getActiveArtboardId(),C=t!==void 0?t:w,j=l.useCallback(async re=>{const te=i.find(ye=>ye.id===re);if(!te)return;const he=await Ki(te,o,s);x.current.set(re,he),v(ye=>ye+1)},[i,o,s]),M=l.useMemo(()=>{let re=i;if(C){const te=d.getElementsOnArtboard(C);re=re.filter(he=>te.includes(he.id))}return r||(re=re.filter(te=>te.visible!==!1)),re},[i,C,r,d]),S=l.useMemo(()=>rl(M,a,c,x.current,j),[M,a,c,j,y]),R=l.useMemo(()=>ol(S),[S]),I=l.useMemo(()=>R.filter(re=>re.isSelected),[R]),D=l.useCallback((re,te=!1)=>{te?c.includes(re)?f(c.filter(he=>he!==re)):f([...c,re]):u(re)},[c,f,u]),E=l.useCallback(re=>{f(re)},[f]),O=l.useCallback(()=>{u(null),f([])},[u,f]),z=l.useCallback(re=>{const te=i.find(ye=>ye.id===re);if(!te)return;const he=te.clone();he.visible=!(te.visible??!0),h(he)},[i,h]),_=l.useCallback(re=>{const te=i.find(ye=>ye.id===re);if(!te)return;const he=te.clone();he.locked=!(te.locked??!1),h(he)},[i,h]),k=l.useCallback((re,te)=>{const he=i.find(we=>we.id===re);if(!he)return;const ye=he.clone();ye.name=te,h(ye)},[i,h]),Y=l.useCallback(re=>{const te=i.find(he=>he.id===re);if(!te){Vt.warn(`Element ${re} not found for deletion`);return}g(te),(a===re||c.includes(re))&&(u(null),f(c.filter(he=>he!==re)))},[i,g,a,c,u,f]),B=l.useCallback(re=>{const te=i.find(N=>N.id===re);if(!te){Vt.warn(`Element ${re} not found for duplication`);return}const ye=te.clone().toJSON();delete ye.id;const we=te.constructor,Pe=new we(ye);Pe.x=te.x+20,Pe.y=te.y+20;const me=d.getArtboardIdForElement(re);if(!me){Vt.warn(`Element ${re} not associated with any artboard`);return}p(Pe,me,re),u(Pe.id)},[i,d,p,u]),G=l.useCallback((re,te)=>{if(re===te)return;if(re<0||re>=M.length){Vt.warn(`Invalid fromIndex: ${re}`);return}if(te<0||te>=M.length){Vt.warn(`Invalid toIndex: ${te}`);return}const he=M[re],ye=M[te],we=re<te?"after":"before";b(he.id,ye.id,we)},[M,b]),se=l.useCallback(re=>{const te=R.findIndex(he=>he.id===re);if(te<0){Vt.warn(`Layer ${re} not found`);return}te>=R.length-1||G(te,te+1)},[R,G]),A=l.useCallback(re=>{const te=R.findIndex(he=>he.id===re);if(te<0){Vt.warn(`Layer ${re} not found`);return}te<=0||G(te,te-1)},[R,G]),Z=l.useCallback(re=>{if(re.length<2){Vt.warn("Need at least 2 elements to create a group");return}const te=i.filter(le=>re.includes(le.id)&&le.transformType!=="shape");if(te.length<2){Vt.warn("Need at least 2 groupable elements (shapes cannot be grouped)");return}const he=te.map(le=>d.getArtboardIdForElement(le.id)),ye=[...new Set(he)];if(ye.length!==1||!ye[0]){Vt.warn("All elements must be on the same artboard to group");return}const we=ye[0],Pe=te.map(le=>le.getBoundingBox()).filter(Boolean);if(Pe.length===0){Vt.warn("Could not calculate bounding boxes for group");return}const me=Math.min(...Pe.map(le=>le.x)),N=Math.min(...Pe.map(le=>le.y)),ce=new T.GroupElement({x:me,y:N});ce.children=te.map(le=>{const Me=le.clone();return Me.x=le.x-me,Me.y=le.y-N,Me}),te.forEach(le=>g(le)),p(ce,we),u(ce.id),f([])},[i,d,g,p,u,f]),J=l.useCallback(re=>{const te=i.find(Pe=>Pe.id===re);if(!te){Vt.warn(`Element ${re} not found for ungrouping`);return}if(!(te instanceof T.GroupElement)){Vt.warn(`Element ${re} is not a group`);return}const he=te;if(!he.children||he.children.length===0){Vt.warn(`Group ${re} has no children`);return}const ye=d.getArtboardIdForElement(re);if(!ye){Vt.warn(`Group ${re} not associated with any artboard`);return}const we=he.children.map(Pe=>{const me=Pe.clone();return me.x=Pe.x+he.x,me.y=Pe.y+he.y,me});g(he),we.forEach(Pe=>p(Pe,ye)),we.length>0&&u(we[0].id),f([])},[i,d,g,p,u,f]),q=l.useCallback(async(re=o)=>{const te=async he=>{for(const ye of he){const we=await Ki(ye,re,s);x.current.set(ye.id,we),ye instanceof T.GroupElement&&ye.children.length>0&&await te(ye.children)}};await te(M),v(he=>he+1)},[o,s,M]),ae=l.useCallback(()=>{x.current.clear()},[]),Le=l.useCallback((re,te,he)=>{b(re,te,he)},[b]),pe=l.useCallback((re,te,he,ye)=>{const we=i.find(ge=>ge.id===ye);if(!we||!(we instanceof T.GroupElement)){Vt.warn(`Group ${ye} not found for reorder`);return}const Pe=we.clone(),me=Pe.children.findIndex(ge=>ge.id===re),N=Pe.children.findIndex(ge=>ge.id===te);if(me===-1||N===-1){Vt.warn(`Children not found in group for reorder: ${re}, ${te}`);return}const[ce]=Pe.children.splice(me,1),le=Pe.children.findIndex(ge=>ge.id===te),Me=he==="before"?le:le+1;Pe.children.splice(Me,0,ce),h(Pe)},[i,h]),U=l.useCallback(re=>{for(const te of i){if(te.id===re)return te;if(te instanceof T.GroupElement){const he=te.children.find(ye=>ye.id===re);if(he)return he}}return null},[i]),W=l.useCallback(re=>{for(const te of i)if(te instanceof T.GroupElement&&te.children.some(he=>he.id===re))return te;return null},[i]),Ie=l.useCallback((re,te)=>{const he=i.find(N=>N.id===re),ye=i.find(N=>N.id===te);if(!he||!ye||!(ye instanceof T.GroupElement)){Vt.warn(`Cannot add ${re} to group ${te}`);return}if(!d.getArtboardIdForElement(re))return;const Pe=ye.clone(),me=he.clone();me.x=he.x,me.y=he.y,Pe.addChild(me),g(he),h(Pe)},[i,d,g,h]),ke=l.useCallback((re,te,he)=>{const ye=W(re);if(!ye){Vt.warn(`Element ${re} is not inside a group`);return}const we=ye.children.find(ce=>ce.id===re);if(!we)return;const Pe=d.getArtboardIdForElement(ye.id);if(!Pe)return;const me=we.clone(),N=ye.clone();N.removeChild(re),h(N),te&&he?p(me,Pe,he==="after"?te:void 0,he==="before"?te:void 0):p(me,Pe,void 0,ye.id),u(me.id)},[W,d,g,h,p,u]),Ke=l.useCallback(()=>{const re=d.getActiveArtboardId();if(!re){Vt.warn("No active artboard for creating a group");return}const te=new T.GroupElement({x:0,y:0,name:"New Group"});p(te,re),u(te.id)},[d,p,u]);return{layers:S,flatLayers:R,selectedLayers:I,selectLayer:D,selectMultipleLayers:E,clearSelection:O,toggleVisibility:z,toggleLock:_,renameLayer:k,deleteLayer:Y,duplicateLayer:B,reorderLayers:G,reorderById:Le,reorderWithinGroup:pe,moveLayerForward:se,moveLayerBackward:A,groupLayers:Z,ungroupLayer:J,addToGroup:Ie,removeFromGroup:ke,createEmptyGroup:Ke,findElementById:U,findParentGroup:W,generateAllPreviews:q,clearPreviewCache:ae,artboardId:C,artboardManager:d,layerCount:R.length}}function nu(e,t){if(t instanceof T.ImageElement&&t.isCropping||e instanceof T.ImageElement&&e.isCropping)return!0;if(e instanceof T.GroupElement){for(const r of e.children)if(r instanceof T.ImageElement&&r.isCropping)return!0}return!1}function ru(e){const t=(e==null?void 0:e.enabled)??!0,{selectedElement:r,activeChildElement:o,multiSelection:s,elements:i,handleElementUpdate:a,handleCopyElements:c,handlePasteElements:d,executeRemoveElement:u,handleSelectionChange:h,setMultiSelection:f,undoActiveArtboard:p,redoActiveArtboard:g,setHideHandles:b,handleAddElement:x,isToolbarMenuOpen:y}=Yt.useEditor(),{duplicateLayer:v}=Qs();l.useEffect(()=>{if(!t)return;const w=j=>{var S;const M=j.target;if(!(M.tagName==="INPUT"||M.tagName==="TEXTAREA")&&!((S=M.closest)!=null&&S.call(M,'[role="listbox"], [role="menu"], [role="tablist"]'))){if((j.metaKey||j.ctrlKey)&&j.key==="z"&&!j.shiftKey){j.preventDefault(),p();return}if((j.metaKey||j.ctrlKey)&&j.shiftKey&&j.key==="z"||j.ctrlKey&&j.key==="y"){j.preventDefault(),g();return}if((j.metaKey||j.ctrlKey)&&j.key==="c"){j.preventDefault(),c();return}if((j.metaKey||j.ctrlKey)&&j.key==="v"){j.preventDefault(),d();return}if((j.metaKey||j.ctrlKey)&&j.key==="d"){j.preventDefault(),r?v(r.id):s.length>0&&s.forEach(R=>{v(R)});return}if(j.key==="Escape"){j.preventDefault(),(r||s.length>0)&&(h(null),f([]));return}if(j.key==="t"&&!j.metaKey&&!j.ctrlKey&&!j.shiftKey&&!j.altKey){j.preventDefault(),x("text");return}if(j.key==="Delete"||j.key==="Backspace"){if(y||nu(r,o))return;if(j.preventDefault(),s.length>0){i.filter(I=>s.includes(I.id)).forEach(I=>{u(I)}),f([]),h(null);return}r&&(u(r),h(null));return}if(j.key==="ArrowUp"||j.key==="ArrowDown"||j.key==="ArrowLeft"||j.key==="ArrowRight"){if(s.length>0){j.preventDefault(),b(!0);const R=j.shiftKey?10:1;let I=0,D=0;j.key==="ArrowLeft"&&(I=-R),j.key==="ArrowRight"&&(I=R),j.key==="ArrowUp"&&(D=-R),j.key==="ArrowDown"&&(D=R),i.filter(O=>s.includes(O.id)).forEach(O=>{const z=O.clone();z.x+=I,z.y+=D,a(z)});return}if(r){j.preventDefault(),b(!0);const R=j.shiftKey?10:1;let I=0,D=0;j.key==="ArrowLeft"&&(I=-R),j.key==="ArrowRight"&&(I=R),j.key==="ArrowUp"&&(D=-R),j.key==="ArrowDown"&&(D=R);const E=r.clone();E.x+=I,E.y+=D,a(E);return}}}},C=j=>{(j.key==="ArrowUp"||j.key==="ArrowDown"||j.key==="ArrowLeft"||j.key==="ArrowRight")&&b(!1)};return window.addEventListener("keydown",w),window.addEventListener("keyup",C),()=>{window.removeEventListener("keydown",w),window.removeEventListener("keyup",C)}},[t,r,o,s,i,a,c,d,u,h,f,p,g,b,v,y])}const ou=280,su=e=>1-Math.pow(1-e,3);function iu(e,t=ou){const[r,o]=l.useState(e),s=l.useRef(r);s.current=r;const i=l.useRef(null),a=e?`${e.x},${e.y},${e.width},${e.height}`:"none";return l.useEffect(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),!e){o(null);return}const c=s.current;if(!c){o(e);return}if(c.x===e.x&&c.y===e.y&&c.width===e.width&&c.height===e.height)return;const d=performance.now(),u=h=>{const f=Math.min(1,(h-d)/t),p=su(f);o({x:c.x+(e.x-c.x)*p,y:c.y+(e.y-c.y)*p,width:c.width+(e.width-c.width)*p,height:c.height+(e.height-c.height)*p}),f<1?i.current=requestAnimationFrame(u):i.current=null};return i.current=requestAnimationFrame(u),()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)}},[a,t]),r}function sl(e,t){if(e.length===0)return{start:0,end:0};const r=Math.max(0,Math.min(t,e.length-1)),o=/[^\s]/;if(!o.test(e[r])){let a=r;for(;a<e.length&&!o.test(e[a]);)a++;if(a<e.length){let d=a;for(;d<e.length&&o.test(e[d]);)d++;return{start:a,end:d}}let c=r;for(;c>0&&!o.test(e[c-1]);)c--;if(c>0){let d=c;for(;d>0&&o.test(e[d-1]);)d--;return{start:d,end:c}}return{start:r,end:r}}let s=r;for(;s>0&&o.test(e[s-1]);)s--;let i=r;for(;i<e.length&&o.test(e[i]);)i++;return{start:s,end:i}}function au(e,t){const{fontSize:r,fontFamily:o,bold:s,italic:i,textAlign:a}=e,c=e.getRichText(),u=e.getVisualBoundingBox().width;let h=u,f=0;e.transformType==="custom"&&(f=T.HORIZONTAL_PADDING,h=u-f*2);const p=T.wrapText(e.getText(),h,r,o,s,i,void 0,!0);let g=0,b=0;for(let D=0;D<p.length;D++){const E=g+p[D].length;if(t<=E){b=D;break}g+=p[D].length+1,D===p.length-1&&(b=D)}const x=p[b],y=t-g;let v=x,w=0;const C=b===0,j=b===p.length-1;if(!C){const D=x.match(/^ +/);w=D?D[0].length:0,w>0&&(v=v.substring(w))}if(!j){const D=v.match(/ +$/),E=D?D[0].length:0;E>0&&(v=v.substring(0,v.length-E))}const M=T.measureTextWidth(v,r,o,s,i);let S=f;a==="center"?S=(u-M)/2:a==="right"&&(S=u-f-M);let R=S;const I=Math.min(y,x.length);for(let D=0;D<I;D++){if(!C&&D<w)continue;const E=x[D],O=g+D,z=c.getStyleAt(O),_=z.fontSize||r,k=z.fontFamily||o,Y=z.bold!==void 0?z.bold:s,B=z.italic!==void 0?z.italic:i;R+=T.measureTextWidth(E,_,k,Y,B)}return{lineIndex:b,lineCount:p.length,xPositionInLine:R,lineStartIndex:g}}function lu(e,t,r){const{fontSize:o}=e,i=o*1.2,a=au(e,t),c=r==="up"?Math.max(0,a.lineIndex-1):Math.min(a.lineCount-1,a.lineIndex+1);if(c===a.lineIndex)return t;const d=c*i+i/2;return Xn(e,{x:a.xPositionInLine,y:d})}function Xn(e,t){const{fontSize:r,fontFamily:o,bold:s,italic:i,textAlign:a}=e,c=e.getRichText(),u=e.getVisualBoundingBox().width;let h=u,f=0;e.transformType==="custom"&&(f=T.HORIZONTAL_PADDING,h=u-f*2);const p=T.wrapText(e.getText(),h,r,o,s,i,void 0,!0),b=r*1.2;let x=0,y=0;if(t.y<0)return 0;for(let z=0;z<p.length;z++){if(t.y>=y&&t.y<y+b){x=z;break}y+=b,z===p.length-1&&(x=z)}let v=0;for(let z=0;z<x;z++)v+=p[z].length+1;const w=p[x];let C=w,j=0,M=0;const S=x===0,R=x===p.length-1;if(!S){const z=w.match(/^ +/);j=z?z[0].length:0,j>0&&(C=C.substring(j))}if(!R){const z=C.match(/ +$/);M=z?z[0].length:0,M>0&&(C=C.substring(0,C.length-M))}const I=T.measureTextWidth(C,r,o,s,i);let D=f;a==="center"?D=(u-I)/2:a==="right"&&(D=u-f-I);const E=t.x-D;if(E<=0)return v+j;if(E>=I)return v+w.length-M;let O=0;for(let z=0;z<w.length;z++){if(!S&&z<j||!R&&z>=w.length-M)continue;const _=w[z],k=v+z,Y=c.getStyleAt(k),B=Y.fontSize||r,G=Y.fontFamily||o,se=Y.bold!==void 0?Y.bold:s,A=Y.italic!==void 0?Y.italic:i,Z=T.measureTextWidth(_,B,G,se,A);if(E<O+Z/2)return k;O+=Z}return v+w.length}function cu(){const[e,t]=l.useState(!1),[r,o]=l.useState({x:0,y:0}),[s,i]=l.useState({x:0,y:0}),[a,c]=l.useState([]);return l.useEffect(()=>{},[e]),{isMarqueeSelecting:e,marqueeStart:r,marqueeEnd:s,marqueePreviewSelection:a,startMarqueeSelection:(f,p)=>{t(!0),o({x:f,y:p}),i({x:f,y:p}),c([])},updateMarqueeSelection:(f,p,g)=>{i({x:f,y:p});const b=Math.min(r.x,f),x=Math.max(r.x,f),y=Math.min(r.y,p),v=Math.max(r.y,p),w=[];g.forEach(C=>{if(C.visible===!1)return;const j=C.getVisualBoundingBox(),M=j.x,S=j.x+j.width,R=j.y,I=j.y+j.height;!(S<b||M>x||I<y||R>v)&&w.push(C.id)}),c(w)},finishMarqueeSelection:f=>{const p=[...a];t(!1),p.length>0&&f(p),c([])}}}class du{constructor(){this.state={active:!1,pathElement:null,points:[],currentPoint:null,isDraggingHandle:!1,previewPoint:null,isClosing:!1,closingClickPos:null}}startPath(t){this.state.active=!0,this.state.pathElement=t,this.state.points=[],this.state.currentPoint=null,this.state.isDraggingHandle=!1,this.state.previewPoint=null,this.state.isClosing=!1,this.state.closingClickPos=null}editPath(t){this.state.active=!0,this.state.pathElement=t,this.state.points=t.transformData.points.map(r=>({...r})),this.state.currentPoint=null,this.state.isDraggingHandle=!1,this.state.previewPoint=null,this.state.isClosing=!1,this.state.closingClickPos=null}isActive(){return this.state.active}getState(){return{...this.state}}setPreviewPoint(t,r){this.state.previewPoint={x:t,y:r}}clearPreviewPoint(){this.state.previewPoint=null}addPoint(t,r){const o={id:`point-${Date.now()}-${Math.random()}`,x:t,y:r,type:"corner"};return this.state.points.push(o),this.state.currentPoint=o,this.state.isDraggingHandle=!1,o}startDraggingHandle(){this.state.currentPoint&&(this.state.isDraggingHandle=!0,this.state.currentPoint.type==="corner"&&(this.state.currentPoint.type="bezier"))}updateHandle(t,r){if(!(!this.state.currentPoint||!this.state.isDraggingHandle))if(this.state.isClosing&&this.state.closingClickPos){const o=t-this.state.closingClickPos.x,s=r-this.state.closingClickPos.y,i=this.state.points[0];i.handleIn={x:o,y:s},i.handleOut={x:-o,y:-s},i.type==="corner"&&(i.type="bezier")}else{const o=t-this.state.currentPoint.x,s=r-this.state.currentPoint.y;this.state.currentPoint.handleOut={x:o,y:s},this.state.currentPoint.type==="smooth"?this.state.currentPoint.handleIn={x:-o,y:-s}:this.state.currentPoint.type==="bezier"&&(this.state.currentPoint.handleIn={x:-o,y:-s})}}finishDraggingHandle(){this.state.isDraggingHandle=!1,this.state.isClosing?this.closePath():this.state.currentPoint=null}canClosePath(t,r,o=10){if(this.state.points.length<3)return!1;const s=this.state.points[0],i=t-s.x,a=r-s.y;return Math.sqrt(i*i+a*a)<=o}startClosing(t,r){this.state.points.length<3||(this.state.isClosing=!0,this.state.closingClickPos={x:t,y:r},this.state.currentPoint=this.state.points[0])}isClosingPath(){return this.state.isClosing}recenterPath(){if(!this.state.pathElement||this.state.points.length===0)return;let t=1/0,r=1/0,o=-1/0,s=-1/0;for(const c of this.state.points)t=Math.min(t,c.x),r=Math.min(r,c.y),o=Math.max(o,c.x),s=Math.max(s,c.y);const i=(t+o)/2,a=(r+s)/2;this.state.pathElement.x+=i,this.state.pathElement.y+=a;for(const c of this.state.points)c.x-=i,c.y-=a}closePath(){this.state.pathElement&&(this.recenterPath(),this.state.pathElement.transformData.points=[...this.state.points],this.state.pathElement.transformData.closed=!0,this.state.pathElement.transformData.fillEnabled=!0,this.state.pathElement.transformData.fillColor=T.getThemeShapeFillColor(),this.state.pathElement.updateBounds(),this.endPath())}finishPath(){this.state.pathElement&&(this.recenterPath(),this.state.pathElement.transformData.points=[...this.state.points],this.state.pathElement.transformData.closed=!1,this.state.pathElement.updateBounds(),this.endPath())}deleteLastPoint(){this.state.points.length!==0&&(this.state.points.pop(),this.state.currentPoint=null)}cancelPath(){const t=this.state.pathElement;return this.state.active=!1,this.state.pathElement=null,this.state.points=[],this.state.currentPoint=null,this.state.isDraggingHandle=!1,this.state.previewPoint=null,this.state.isClosing=!1,this.state.closingClickPos=null,t}endPath(){this.state.active=!1,this.state.pathElement=null,this.state.points=[],this.state.currentPoint=null,this.state.isDraggingHandle=!1,this.state.previewPoint=null,this.state.isClosing=!1,this.state.closingClickPos=null}getPoints(){return this.state.points}getCurrentPoint(){return this.state.currentPoint}isDraggingHandle(){return this.state.isDraggingHandle}renderPreview(t,r){var a,c,d,u,h,f,p,g;if(!this.state.active||this.state.points.length===0)return;const{points:o,previewPoint:s,currentPoint:i}=this.state;if(t.save(),t.translate(r.x,r.y),t.strokeStyle=T.getThemePenPathColor(),t.lineWidth=2,t.setLineDash([]),t.beginPath(),o.length>0){const b=o[0];t.moveTo(b.x,b.y);for(let y=1;y<o.length;y++){const v=o[y-1],w=o[y];if(v.handleOut||w.handleIn){const j=v.x+(((a=v.handleOut)==null?void 0:a.x)||0),M=v.y+(((c=v.handleOut)==null?void 0:c.y)||0),S=w.x+(((d=w.handleIn)==null?void 0:d.x)||0),R=w.y+(((u=w.handleIn)==null?void 0:u.y)||0);t.bezierCurveTo(j,M,S,R,w.x,w.y)}else t.lineTo(w.x,w.y)}const x=this.state.isClosing||r.transformData.closed;if(x&&o.length>2){const y=o[o.length-1],v=o[0];if(y.handleOut||v.handleIn){const C=y.x+(((h=y.handleOut)==null?void 0:h.x)||0),j=y.y+(((f=y.handleOut)==null?void 0:f.y)||0),M=v.x+(((p=v.handleIn)==null?void 0:p.x)||0),S=v.y+(((g=v.handleIn)==null?void 0:g.y)||0);t.bezierCurveTo(C,j,M,S,v.x,v.y)}else t.lineTo(v.x,v.y)}else s&&!this.state.isDraggingHandle&&t.lineTo(s.x,s.y);t.stroke(),x&&r.transformData.fillEnabled&&(t.fillStyle=r.transformData.fillColor||T.getThemeShapeFillColor(),t.globalAlpha=r.transformData.fillOpacity??1,t.fill(),t.globalAlpha=1)}t.setLineDash([]);for(let b=0;b<o.length;b++){const x=o[b];if(b===0&&o.length>1&&(t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=2,t.beginPath(),t.arc(x.x,x.y,8,0,Math.PI*2),t.stroke()),t.fillStyle=T.getThemePenAnchorFillColor(),t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=2,t.beginPath(),t.arc(x.x,x.y,4,0,Math.PI*2),t.fill(),t.stroke(),x.handleIn){const v=x.x+x.handleIn.x,w=x.y+x.handleIn.y;t.strokeStyle=T.getThemePenHandleColor(),t.lineWidth=1,t.beginPath(),t.moveTo(x.x,x.y),t.lineTo(v,w),t.stroke(),t.fillStyle=T.getThemePenHandleColor(),t.beginPath(),t.arc(v,w,3,0,Math.PI*2),t.fill()}if(x.handleOut){const v=x.x+x.handleOut.x,w=x.y+x.handleOut.y;t.strokeStyle=T.getThemePenHandleColor(),t.lineWidth=1,t.beginPath(),t.moveTo(x.x,x.y),t.lineTo(v,w),t.stroke(),t.fillStyle=T.getThemePenHandleColor(),t.beginPath(),t.arc(v,w,3,0,Math.PI*2),t.fill()}}if(s&&this.canClosePath(s.x,s.y)){const b=o[0];t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=3,t.beginPath(),t.arc(b.x,b.y,6,0,Math.PI*2),t.stroke()}if(s&&!this.state.isDraggingHandle){const b=T.getThemeAccentColor(),x=b.replace("#",""),y=parseInt(x.substring(0,2),16),v=parseInt(x.substring(2,4),16),w=parseInt(x.substring(4,6),16);t.fillStyle=`rgba(${y}, ${v}, ${w}, 0.3)`,t.strokeStyle=b,t.lineWidth=2,t.beginPath(),t.arc(s.x,s.y,4,0,Math.PI*2),t.fill(),t.stroke()}t.restore()}}const uu=T.createLogger("usePenTool");function hu({selectedElement:e}){const[t]=l.useState(()=>new du),[r,o]=l.useState("crosshair");return l.useEffect(()=>{try{const s=Uc.renderToStaticMarkup(n.jsx(de,{icon:"lucide:pen-tool",width:24,height:24})).replace(/<svg[^>]*>|<\/svg>/g,""),i=`
1
+ "use strict";const n=require("react/jsx-runtime"),l=require("react"),Yt=require("./ThemeContext-BMNQKl1c.cjs"),T=require("./HybridHistoryManager-BXD93pp8.cjs"),Qn=require("react-dom"),rt=require("./ImportManager-W1eWhfyM.cjs"),Kc=require("react-dom/server"),m=require("@snowcone-app/ui"),qc=require("clsx"),Zc=require("tailwind-merge"),Jc=require("@runware/sdk-js"),zi=require("lodash-es"),Qc={"eos-icons:loading":{body:'<path fill="currentColor" d="M12 2A10 10 0 1 0 22 12A10 10 0 0 0 12 2Zm0 18a8 8 0 1 1 8-8A8 8 0 0 1 12 20Z" opacity=".5"/><path fill="currentColor" d="M20 12h2A10 10 0 0 0 12 2V4A8 8 0 0 1 20 12Z"><animateTransform attributeName="transform" dur="1s" from="0 12 12" repeatCount="indefinite" to="360 12 12" type="rotate"/></path>',width:24,height:24},"fa6-solid:icons":{body:'<path fill="currentColor" d="M500.3 7.3c7.4 6 11.7 15.1 11.7 24.7v144c0 26.5-28.7 48-64 48s-64-21.5-64-48s28.7-48 64-48V71l-96 19.2V208c0 26.5-28.7 48-64 48s-64-21.5-64-48s28.7-48 64-48V64c0-15.3 10.8-28.4 25.7-31.4l160-32c9.4-1.9 19.1.6 26.6 6.6zM74.7 304l11.8-17.8c5.9-8.9 15.9-14.2 26.6-14.2h61.7c10.7 0 20.7 5.3 26.6 14.2l11.9 17.8H240c26.5 0 48 21.5 48 48v112c0 26.5-21.5 48-48 48H48c-26.5 0-48-21.5-48-48V352c0-26.5 21.5-48 48-48zM192 408a48 48 0 1 0-96 0a48 48 0 1 0 96 0m286.7-129.7L440.3 368H496c6.7 0 12.6 4.1 15 10.4s.6 13.3-4.4 17.7l-128 112c-5.6 4.9-13.9 5.3-19.9.9s-8.2-12.4-5.3-19.2l38.3-89.8H336c-6.7 0-12.6-4.1-15-10.4s-.6-13.3 4.4-17.7l128-112c5.6-4.9 13.9-5.3 19.9-.9s8.2 12.4 5.3 19.2zm-339-59.2c-6.5 6.5-17 6.5-23 0l-96.8-99.9c-28-29-26.5-76.9 5-103.9c27-23.5 68.4-19 93.4 6.5l10 10.5l9.5-10.5c25-25.5 65.9-30 93.9-6.5c31 27 32.5 74.9 4.5 103.9l-96.4 99.9z"/>',width:512,height:512},"gravity-ui:arrow-down-to-square":{body:'<path fill="currentColor" fill-rule="evenodd" d="M8.53 11.78a.75.75 0 0 1-1.06 0l-2.5-2.5a.75.75 0 0 1 1.06-1.06l1.22 1.22V1.75a.75.75 0 0 1 1.5 0v7.69l1.22-1.22a.75.75 0 1 1 1.06 1.06zM4.25 4a.75.75 0 1 1 0 1.5H4A1.5 1.5 0 0 0 2.5 7v5A1.5 1.5 0 0 0 4 13.5h8a1.5 1.5 0 0 0 1.5-1.5V7A1.5 1.5 0 0 0 12 5.5h-.25a.75.75 0 0 1 0-1.5H12a3 3 0 0 1 3 3v5a3 3 0 0 1-3 3H4a3 3 0 0 1-3-3V7a3 3 0 0 1 3-3z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:arrow-left":{body:'<path fill="currentColor" fill-rule="evenodd" d="M14.75 8a.75.75 0 0 1-.75.75H3.81l2.72 2.72a.75.75 0 1 1-1.06 1.06l-4-4a.75.75 0 0 1 0-1.06l4-4a.75.75 0 0 1 1.06 1.06L3.81 7.25H14a.75.75 0 0 1 .75.75" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:arrow-rotate-left":{body:'<path fill="currentColor" fill-rule="evenodd" d="M8 1.5a6.5 6.5 0 1 1-6.445 7.348a.75.75 0 1 1 1.487-.194A5.001 5.001 0 1 0 4.43 4.5h1.32a.75.75 0 0 1 0 1.5h-3A.75.75 0 0 1 2 5.25v-3a.75.75 0 0 1 1.5 0v1.06A6.48 6.48 0 0 1 8 1.5" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:bars":{body:'<path fill="currentColor" fill-rule="evenodd" d="M1.25 3.25A.75.75 0 0 1 2 2.5h12A.75.75 0 0 1 14 4H2a.75.75 0 0 1-.75-.75m0 4.75A.75.75 0 0 1 2 7.25h12a.75.75 0 0 1 0 1.5H2A.75.75 0 0 1 1.25 8M2 12a.75.75 0 0 0 0 1.5h12a.75.75 0 0 0 0-1.5z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:bold":{body:'<path fill="currentColor" fill-rule="evenodd" d="M4.25 2.25A.75.75 0 0 0 3.5 3v10c0 .414.336.75.75.75H9.5a3.25 3.25 0 0 0 1.477-6.146A3.25 3.25 0 0 0 8.5 2.25zm3.5 5a1.75 1.75 0 1 0 0-3.5h-2v3.5zm-2 1.5v3.5h3a1.75 1.75 0 1 0 0-3.5z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:copy":{body:'<path fill="currentColor" fill-rule="evenodd" d="M12 2.5H8A1.5 1.5 0 0 0 6.5 4v1H8a3 3 0 0 1 3 3v1.5h1A1.5 1.5 0 0 0 13.5 8V4A1.5 1.5 0 0 0 12 2.5M11 11h1a3 3 0 0 0 3-3V4a3 3 0 0 0-3-3H8a3 3 0 0 0-3 3v1H4a3 3 0 0 0-3 3v4a3 3 0 0 0 3 3h4a3 3 0 0 0 3-3zM4 6.5h4A1.5 1.5 0 0 1 9.5 8v4A1.5 1.5 0 0 1 8 13.5H4A1.5 1.5 0 0 1 2.5 12V8A1.5 1.5 0 0 1 4 6.5" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:italic":{body:'<path fill="currentColor" fill-rule="evenodd" d="M7.25 2a.75.75 0 0 0 0 1.5h1.317l-2.7 9H4.25a.75.75 0 1 0 0 1.5h4.5a.75.75 0 0 0 0-1.5H7.433l2.7-9h1.617a.75.75 0 0 0 0-1.5z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:layers":{body:'<path fill="currentColor" fill-rule="evenodd" d="m2.789 5.283l4.037-2.02A2.5 2.5 0 0 1 7.944 3h.112c.388 0 .77.09 1.118.264l4.037 2.019a.522.522 0 0 1 0 .934l-4.037 2.02a2.5 2.5 0 0 1-1.118.263h-.112a2.5 2.5 0 0 1-1.118-.264L2.79 6.217a.523.523 0 0 1 0-.934M1 5.75c0-.766.433-1.466 1.118-1.809l4.037-2.019a4 4 0 0 1 1.79-.422h.11a4 4 0 0 1 1.79.422l4.037 2.019a2.023 2.023 0 0 1 0 3.618l-.882.44l.882.442a2.023 2.023 0 0 1 0 3.618l-4.037 2.019a4 4 0 0 1-1.79.422h-.11a4 4 0 0 1-1.79-.422l-4.037-2.02a2.023 2.023 0 0 1 0-3.617L3 8l-.882-.441A2.02 2.02 0 0 1 1 5.75m3.677 3.088l-1.888.945a.523.523 0 0 0 0 .934l4.037 2.019A2.5 2.5 0 0 0 7.944 13h.112a2.5 2.5 0 0 0 1.118-.264l4.037-2.019a.523.523 0 0 0 0-.934l-1.888-.945l-1.478.74a4 4 0 0 1-1.79.422h-.11a4 4 0 0 1-1.79-.422z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:magnifier":{body:'<path fill="currentColor" fill-rule="evenodd" d="M11.5 7a4.5 4.5 0 1 1-9 0a4.5 4.5 0 0 1 9 0m-.82 4.74a6 6 0 1 1 1.06-1.06l2.79 2.79a.75.75 0 1 1-1.06 1.06z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:pencil":{body:'<path fill="currentColor" fill-rule="evenodd" d="M11.423 1A3.577 3.577 0 0 1 15 4.577c0 .27-.108.53-.3.722l-.528.529l-1.971 1.971l-5.059 5.059a3 3 0 0 1-1.533.82l-2.638.528a1 1 0 0 1-1.177-1.177l.528-2.638a3 3 0 0 1 .82-1.533l5.059-5.059l2.5-2.5c.191-.191.451-.299.722-.299m-2.31 4.009l-4.91 4.91a1.5 1.5 0 0 0-.41.766l-.38 1.903l1.902-.38a1.5 1.5 0 0 0 .767-.41l4.91-4.91a2.08 2.08 0 0 0-1.88-1.88m3.098.658a3.6 3.6 0 0 0-1.878-1.879l1.28-1.28c.995.09 1.788.884 1.878 1.88z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:picture":{body:'<path fill="currentColor" fill-rule="evenodd" d="M11.5 3h-7A1.5 1.5 0 0 0 3 4.5v5.027l.962-.7a1.75 1.75 0 0 1 2.079.016l.928.696l2.368-2.03a1.75 1.75 0 0 1 2.325.043L13 8.787V4.5A1.5 1.5 0 0 0 11.5 3m3 7.498V4.5a3 3 0 0 0-3-3h-7a3 3 0 0 0-3 3v7a3 3 0 0 0 3 3h7a3 3 0 0 0 3-3zm-1.5.33l-2.355-2.174a.25.25 0 0 0-.332-.006L7.488 11.07l-.457.392l-.481-.361l-1.41-1.057a.25.25 0 0 0-.296-.002L3 11.381v.119A1.5 1.5 0 0 0 4.5 13h7a1.5 1.5 0 0 0 1.5-1.5zM7.5 6a1.5 1.5 0 1 1-3 0a1.5 1.5 0 0 1 3 0" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:plus":{body:'<path fill="currentColor" fill-rule="evenodd" d="M8 1.75a.75.75 0 0 1 .75.75v4.75h4.75a.75.75 0 0 1 0 1.5H8.75v4.75a.75.75 0 0 1-1.5 0V8.75H2.5a.75.75 0 0 1 0-1.5h4.75V2.5A.75.75 0 0 1 8 1.75" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:scissors":{body:'<path fill="currentColor" fill-rule="evenodd" d="M4.5 6a1.5 1.5 0 1 0 0-3a1.5 1.5 0 0 0 0 3m-3-1.5a3 3 0 0 0 4.524 2.585L6.939 8l-.915.915a3 3 0 1 0 1.06 1.06L8.122 8.94l5.501 3.209a.75.75 0 1 0 .756-1.296L9.488 8l4.89-2.852a.75.75 0 0 0-.756-1.296l-5.5 3.209l-1.037-1.037A3 3 0 1 0 1.5 4.5m3 5.5a1.5 1.5 0 1 1 0 3a1.5 1.5 0 0 1 0-3" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:sparkles":{body:'<path fill="currentColor" d="M13 10a.75.75 0 0 1 .725.556a2.37 2.37 0 0 0 1.72 1.72a.75.75 0 0 1 0 1.449a2.37 2.37 0 0 0-1.72 1.72a.75.75 0 0 1-1.45 0a2.37 2.37 0 0 0-1.72-1.72a.75.75 0 0 1 0-1.45a2.37 2.37 0 0 0 1.72-1.72l.043-.117A.75.75 0 0 1 13 10M7 0a1.5 1.5 0 0 1 1.48 1.253c.242 1.455.696 2.364 1.3 2.968c.603.603 1.512 1.057 2.967 1.3a1.5 1.5 0 0 1 0 2.958c-1.455.243-2.364.697-2.968 1.3c-.603.604-1.057 1.513-1.3 2.968a1.5 1.5 0 0 1-2.958 0c-.243-1.455-.697-2.364-1.3-2.968c-.604-.603-1.513-1.057-2.968-1.3a1.5 1.5 0 0 1 0-2.958c1.455-.243 2.364-.697 2.968-1.3c.603-.604 1.057-1.513 1.3-2.968l.028-.133A1.5 1.5 0 0 1 7 0m0 1.5C6.45 4.8 4.8 6.45 1.5 7c3.3.55 4.95 2.2 5.5 5.5c.55-3.3 2.2-4.95 5.5-5.5C9.2 6.45 7.55 4.8 7 1.5"/>',width:24,height:24},"gravity-ui:text":{body:'<path fill="currentColor" fill-rule="evenodd" d="M3.279 2.544A.75.75 0 0 1 4 2h8a.75.75 0 0 1 .721.544l.5 1.75a.75.75 0 1 1-1.442.412L11.434 3.5H8.75l-.004 9H9.5a.75.75 0 0 1 0 1.5h-3a.75.75 0 0 1 0-1.5h.746l.004-9H4.566L4.22 4.706a.75.75 0 1 1-1.442-.412z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:text-align-center":{body:'<path fill="currentColor" fill-rule="evenodd" d="M2.75 2a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm0 7a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm2 3.5a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5zM4 6.25a.75.75 0 0 1 .75-.75h6.5a.75.75 0 0 1 0 1.5h-6.5A.75.75 0 0 1 4 6.25" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:text-align-justify":{body:'<path fill="currentColor" fill-rule="evenodd" d="M2.75 2a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zM2 6.25a.75.75 0 0 1 .75-.75h10.5a.75.75 0 0 1 0 1.5H2.75A.75.75 0 0 1 2 6.25M2.75 9a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm0 3.5a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:text-align-left":{body:'<path fill="currentColor" fill-rule="evenodd" d="M2.75 2a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm0 7a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm0 3.5a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5zM2 6.25a.75.75 0 0 1 .75-.75h6.5a.75.75 0 0 1 0 1.5h-6.5A.75.75 0 0 1 2 6.25" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:text-align-right":{body:'<path fill="currentColor" fill-rule="evenodd" d="M2.75 2a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zM6 6.25a.75.75 0 0 1 .75-.75h6.5a.75.75 0 0 1 0 1.5h-6.5A.75.75 0 0 1 6 6.25M2.75 9a.75.75 0 0 0 0 1.5h10.5a.75.75 0 0 0 0-1.5zm4 3.5a.75.75 0 0 0 0 1.5h6.5a.75.75 0 0 0 0-1.5z" clip-rule="evenodd"/>',width:24,height:24},"gravity-ui:underline":{body:'<path fill="currentColor" fill-rule="evenodd" d="M5 2.75a.75.75 0 0 0-1.5 0V7a4.5 4.5 0 0 0 9 0V2.75a.75.75 0 0 0-1.5 0V7a3 3 0 0 1-6 0zm-.75 9.75a.75.75 0 0 0 0 1.5h7.5a.75.75 0 0 0 0-1.5z" clip-rule="evenodd"/>',width:24,height:24},"healthicons:polygon":{body:'<path fill="currentColor" fill-rule="evenodd" d="M28 10c0 .507-.094.992-.266 1.438l7.696 5.497a4 4 0 1 1 2.706 7.063l-2.32 10.437A4 4 0 1 1 30.126 39H17.874A4.002 4.002 0 0 1 10 38a4 4 0 0 1 2.184-3.565l-2.32-10.437a4 4 0 1 1 2.706-7.063l7.696-5.497A4 4 0 1 1 28 10m-6.57 3.065l-7.696 5.497a4 4 0 0 1-1.917 5.003l2.319 10.437A4 4 0 0 1 17.874 37h12.252a4 4 0 0 1 3.738-2.998l2.32-10.437a4 4 0 0 1-1.918-5.003l-7.695-5.497A3.98 3.98 0 0 1 24 14a3.98 3.98 0 0 1-2.57-.935" clip-rule="evenodd"/>',width:48,height:48},"heroicons:swatch":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4.098 19.902a3.75 3.75 0 0 0 5.304 0l6.401-6.402M6.75 21A3.75 3.75 0 0 1 3 17.25V4.125C3 3.504 3.504 3 4.125 3h5.25c.621 0 1.125.504 1.125 1.125v4.072M6.75 21a3.75 3.75 0 0 0 3.75-3.75V8.197M6.75 21h13.125c.621 0 1.125-.504 1.125-1.125v-5.25c0-.621-.504-1.125-1.125-1.125h-4.072M10.5 8.197l2.88-2.88a1.124 1.124 0 0 1 1.59 0l3.712 3.713c.44.44.44 1.152 0 1.59l-2.879 2.88M6.75 17.25h.008v.008H6.75z"/>',width:24,height:24},"hugeicons:layer-bring-forward":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m15.89 11.5l3.397 1.56C21.096 13.892 22 14.308 22 15s-.904 1.109-2.713 1.94l-4.893 2.247c-1.18.542-1.77.813-2.394.813s-1.214-.271-2.394-.813l-4.893-2.248C2.904 16.11 2 15.693 2 15s.904-1.109 2.713-1.94L8.11 11.5m3.89-7V15m3-8c-.59-.607-2.16-3-3-3S9.59 6.393 9 7"/>',width:24,height:24},"hugeicons:layer-send-backward":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="m15.89 12.5l3.397-1.56C21.096 10.108 22 9.692 22 9s-.904-1.109-2.713-1.94l-4.893-2.247C13.214 4.271 12.624 4 12 4s-1.214.271-2.394.813L4.713 7.061C2.904 7.89 2 8.307 2 9s.904 1.109 2.713 1.94L8.11 12.5m3.89 7V9m3 8c-.59.607-2.16 3-3 3s-2.41-2.393-3-3"/>',width:24,height:24},"lucide:a-large-small":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m15 16l2.536-7.328a1.02 1.02 1 0 1 1.928 0L22 16m-6.303-2h5.606M2 16l4.039-9.69a.5.5 0 0 1 .923 0L11 16m-7.696-3h6.392"/>',width:24,height:24},"lucide:aperture":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="10"/><path d="m14.31 8l5.74 9.94M9.69 8h11.48M7.38 12l5.74-9.94M9.69 16L3.95 6.06M14.31 16H2.83m13.79-4l-5.74 9.94"/></g>',width:24,height:24},"lucide:arrow-left":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m12 19l-7-7l7-7m7 7H5"/>',width:24,height:24},"lucide:arrow-up-from-dot":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="m5 9l7-7l7 7m-7 7V2"/><circle cx="12" cy="21" r="1"/></g>',width:24,height:24},"lucide:blend":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="9" cy="9" r="7"/><circle cx="15" cy="15" r="7"/></g>',width:24,height:24},"lucide:case-upper":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 11h4.5a1 1 0 0 1 0 5h-4a.5.5 0 0 1-.5-.5v-9a.5.5 0 0 1 .5-.5h3a1 1 0 0 1 0 5M2 16l4.039-9.69a.5.5 0 0 1 .923 0L11 16m-7.696-3h6.392"/>',width:24,height:24},"lucide:circle":{body:'<circle cx="12" cy="12" r="10" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"/>',width:24,height:24},"lucide:circle-dashed":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10.1 2.182a10 10 0 0 1 3.8 0m0 19.636a10 10 0 0 1-3.8 0m7.509-18.097a10 10 0 0 1 2.69 2.7M2.182 13.9a10 10 0 0 1 0-3.8m18.097 7.509a10 10 0 0 1-2.7 2.69M21.818 10.1a10 10 0 0 1 0 3.8M3.721 6.391a10 10 0 0 1 2.7-2.69m-.03 16.578a10 10 0 0 1-2.69-2.7"/>',width:24,height:24},"lucide:cloud":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17.5 19H9a7 7 0 1 1 6.71-9h1.79a4.5 4.5 0 1 1 0 9"/>',width:24,height:24},"lucide:copy":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="14" height="14" x="8" y="8" rx="2" ry="2"/><path d="M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"/></g>',width:24,height:24},"lucide:credit-card":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="20" height="14" x="2" y="5" rx="2"/><path d="M2 10h20"/></g>',width:24,height:24},"lucide:crop":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M6 2v14a2 2 0 0 0 2 2h14"/><path d="M18 22V8a2 2 0 0 0-2-2H2"/></g>',width:24,height:24},"lucide:ellipsis-vertical":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="1"/><circle cx="12" cy="5" r="1"/><circle cx="12" cy="19" r="1"/></g>',width:24,height:24},"lucide:flag":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 22V4a1 1 0 0 1 .4-.8A6 6 0 0 1 8 2c3 0 5 2 7.333 2q2 0 3.067-.8A1 1 0 0 1 20 4v10a1 1 0 0 1-.4.8A6 6 0 0 1 16 16c-3 0-5-2-8-2a6 6 0 0 0-4 1.528"/>',width:24,height:24},"lucide:flip-horizontal-2":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m3 7l5 5l-5 5zm18 0l-5 5l5 5zm-9 13v2m0-8v2m0-8v2m0-8v2"/>',width:24,height:24},"lucide:flip-vertical-2":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m17 3l-5 5l-5-5zm0 18l-5-5l-5 5zM4 12H2m8 0H8m8 0h-2m8 0h-2"/>',width:24,height:24},"lucide:folder-open":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m6 14l1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2"/>',width:24,height:24},"lucide:folder-plus":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 10v6m-3-3h6m5 7a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z"/>',width:24,height:24},"lucide:grid-2x2":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M12 3v18m-9-9h18"/><rect width="18" height="18" x="3" y="3" rx="2"/></g>',width:24,height:24},"lucide:grid-3x3":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="18" height="18" x="3" y="3" rx="2"/><path d="M3 9h18M3 15h18M9 3v18m6-18v18"/></g>',width:24,height:24},"lucide:grip-vertical":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="9" cy="12" r="1"/><circle cx="9" cy="5" r="1"/><circle cx="9" cy="19" r="1"/><circle cx="15" cy="12" r="1"/><circle cx="15" cy="5" r="1"/><circle cx="15" cy="19" r="1"/></g>',width:24,height:24},"lucide:hexagon":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16"/>',width:24,height:24},"lucide:image":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="18" height="18" x="3" y="3" rx="2" ry="2"/><circle cx="9" cy="9" r="2"/><path d="m21 15l-3.086-3.086a2 2 0 0 0-2.828 0L6 21"/></g>',width:24,height:24},"lucide:italic":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 4h-9m4 16H5M15 4L9 20"/>',width:24,height:24},"lucide:layout-grid":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></g>',width:24,height:24},"lucide:lightbulb":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M15 14c.2-1 .7-1.7 1.5-2.5c1-.9 1.5-2.2 1.5-3.5A6 6 0 0 0 6 8c0 1 .2 2.2 1.5 3.5c.7.7 1.3 1.5 1.5 2.5m0 4h6m-5 4h4"/>',width:24,height:24},"lucide:loader-circle":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 12a9 9 0 1 1-6.219-8.56"/>',width:24,height:24},"lucide:minus":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 12h14"/>',width:24,height:24},"lucide:moon":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401"/>',width:24,height:24},"lucide:move-vertical":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 2v20m-4-4l4 4l4-4M8 6l4-4l4 4"/>',width:24,height:24},"lucide:paint-bucket":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11 7L6 2m12.992 10H2.041m19.104 6.38A3.34 3.34 0 0 1 20 16.5a3.3 3.3 0 0 1-1.145 1.88c-.575.46-.855 1.02-.855 1.595A2 2 0 0 0 20 22a2 2 0 0 0 2-2.025c0-.58-.285-1.13-.855-1.595M8.5 4.5l2.148-2.148a1.205 1.205 0 0 1 1.704 0l7.296 7.296a1.205 1.205 0 0 1 0 1.704l-7.592 7.592a3.615 3.615 0 0 1-5.112 0l-3.888-3.888a3.615 3.615 0 0 1 0-5.112L5.67 7.33"/>',width:24,height:24},"lucide:palette":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M12 22a1 1 0 0 1 0-20a10 9 0 0 1 10 9a5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z"/><circle cx="13.5" cy="6.5" r=".5" fill="currentColor"/><circle cx="17.5" cy="10.5" r=".5" fill="currentColor"/><circle cx="6.5" cy="12.5" r=".5" fill="currentColor"/><circle cx="8.5" cy="7.5" r=".5" fill="currentColor"/></g>',width:24,height:24},"lucide:pen-line":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 21h8m.174-14.188a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z"/>',width:24,height:24},"lucide:pen-tool":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M15.707 21.293a1 1 0 0 1-1.414 0l-1.586-1.586a1 1 0 0 1 0-1.414l5.586-5.586a1 1 0 0 1 1.414 0l1.586 1.586a1 1 0 0 1 0 1.414z"/><path d="m18 13l-1.375-6.874a1 1 0 0 0-.746-.776L3.235 2.028a1 1 0 0 0-1.207 1.207L5.35 15.879a1 1 0 0 0 .776.746L13 18M2.3 2.3l7.286 7.286"/><circle cx="11" cy="11" r="2"/></g>',width:24,height:24},"lucide:redo-2":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="m15 14l5-5l-5-5"/><path d="M20 9H9.5A5.5 5.5 0 0 0 4 14.5A5.5 5.5 0 0 0 9.5 20H13"/></g>',width:24,height:24},"lucide:rotate-ccw":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M3 12a9 9 0 1 0 9-9a9.75 9.75 0 0 0-6.74 2.74L3 8"/><path d="M3 3v5h5"/></g>',width:24,height:24},"lucide:rotate-cw":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8"/><path d="M21 3v5h-5"/></g>',width:24,height:24},"lucide:scissors":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="6" cy="6" r="3"/><path d="M8.12 8.12L12 12m8-8L8.12 15.88"/><circle cx="6" cy="18" r="3"/><path d="M14.8 14.8L20 20"/></g>',width:24,height:24},"lucide:settings":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M9.671 4.136a2.34 2.34 0 0 1 4.659 0a2.34 2.34 0 0 0 3.319 1.915a2.34 2.34 0 0 1 2.33 4.033a2.34 2.34 0 0 0 0 3.831a2.34 2.34 0 0 1-2.33 4.033a2.34 2.34 0 0 0-3.319 1.915a2.34 2.34 0 0 1-4.659 0a2.34 2.34 0 0 0-3.32-1.915a2.34 2.34 0 0 1-2.33-4.033a2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915"/><circle cx="12" cy="12" r="3"/></g>',width:24,height:24},"lucide:shapes":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M8.3 10a.7.7 0 0 1-.626-1.079L11.4 3a.7.7 0 0 1 1.198-.043L16.3 8.9a.7.7 0 0 1-.572 1.1Z"/><rect width="7" height="7" x="3" y="14" rx="1"/><circle cx="17.5" cy="17.5" r="3.5"/></g>',width:24,height:24},"lucide:sparkles":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M11.017 2.814a1 1 0 0 1 1.966 0l1.051 5.558a2 2 0 0 0 1.594 1.594l5.558 1.051a1 1 0 0 1 0 1.966l-5.558 1.051a2 2 0 0 0-1.594 1.594l-1.051 5.558a1 1 0 0 1-1.966 0l-1.051-5.558a2 2 0 0 0-1.594-1.594l-5.558-1.051a1 1 0 0 1 0-1.966l5.558-1.051a2 2 0 0 0 1.594-1.594zM20 2v4m2-2h-4"/><circle cx="4" cy="20" r="2"/></g>',width:24,height:24},"lucide:square":{body:'<rect width="18" height="18" x="3" y="3" fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" rx="2"/>',width:24,height:24},"lucide:square-round-corner":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M21 11a8 8 0 0 0-8-8m8 12v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4"/>',width:24,height:24},"lucide:stamp":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 13V8.5C14 7 15 7 15 5a3 3 0 0 0-6 0c0 2 1 2 1 3.5V13m10 2.5a2.5 2.5 0 0 0-2.5-2.5h-11A2.5 2.5 0 0 0 4 15.5V17a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1zM5 22h14"/>',width:24,height:24},"lucide:star":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M11.525 2.295a.53.53 0 0 1 .95 0l2.31 4.679a2.12 2.12 0 0 0 1.595 1.16l5.166.756a.53.53 0 0 1 .294.904l-3.736 3.638a2.12 2.12 0 0 0-.611 1.878l.882 5.14a.53.53 0 0 1-.771.56l-4.618-2.428a2.12 2.12 0 0 0-1.973 0L6.396 21.01a.53.53 0 0 1-.77-.56l.881-5.139a2.12 2.12 0 0 0-.611-1.879L2.16 9.795a.53.53 0 0 1 .294-.906l5.165-.755a2.12 2.12 0 0 0 1.597-1.16z"/>',width:24,height:24},"lucide:sun":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><circle cx="12" cy="12" r="4"/><path d="M12 2v2m0 16v2M4.93 4.93l1.41 1.41m11.32 11.32l1.41 1.41M2 12h2m16 0h2M6.34 17.66l-1.41 1.41M19.07 4.93l-1.41 1.41"/></g>',width:24,height:24},"lucide:text-cursor":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M17 22h-1a4 4 0 0 1-4-4V6a4 4 0 0 1 4-4h1M7 22h1a4 4 0 0 0 4-4M7 2h1a4 4 0 0 1 4 4"/>',width:24,height:24},"lucide:trash":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6M3 6h18M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/>',width:24,height:24},"lucide:trending-up":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M16 7h6v6"/><path d="m22 7l-8.5 8.5l-5-5L2 17"/></g>',width:24,height:24},"lucide:triangle":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13.73 4a2 2 0 0 0-3.46 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3Z"/>',width:24,height:24},"lucide:type":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 4v16M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2M9 20h6"/>',width:24,height:24},"lucide:undo-2":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M9 14L4 9l5-5"/><path d="M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11"/></g>',width:24,height:24},"lucide:venetian-mask":{body:'<g fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"><path d="M18 11c-1.5 0-2.5.5-3 2"/><path d="M4 6a2 2 0 0 0-2 2v4a5 5 0 0 0 5 5a8 8 0 0 1 5 2a8 8 0 0 1 5-2a5 5 0 0 0 5-5V8a2 2 0 0 0-2-2h-3a8 8 0 0 0-5 2a8 8 0 0 0-5-2z"/><path d="M6 11c1.5 0 2.5.5 3 2"/></g>',width:24,height:24},"lucide:waves":{body:'<path fill="none" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2 6c.6.5 1.2 1 2.5 1C7 7 7 5 9.5 5c2.6 0 2.4 2 5 2c2.5 0 2.5-2 5-2c1.3 0 1.9.5 2.5 1M2 12c.6.5 1.2 1 2.5 1c2.5 0 2.5-2 5-2c2.6 0 2.4 2 5 2c2.5 0 2.5-2 5-2c1.3 0 1.9.5 2.5 1M2 18c.6.5 1.2 1 2.5 1c2.5 0 2.5-2 5-2c2.6 0 2.4 2 5 2c2.5 0 2.5-2 5-2c1.3 0 1.9.5 2.5 1"/>',width:24,height:24},"material-symbols:award-star-outline":{body:'<path fill="currentColor" d="M9.075 16.25L12 14.475l2.925 1.775l-.775-3.325l2.6-2.25l-3.425-.275L12 7.25l-1.325 3.15l-3.425.275l2.6 2.25zM12 23.3L8.65 20H4v-4.65L.7 12L4 8.65V4h4.65L12 .7L15.35 4H20v4.65L23.3 12L20 15.35V20h-4.65zm0-2.8l2.5-2.5H18v-3.5l2.5-2.5L18 9.5V6h-3.5L12 3.5L9.5 6H6v3.5L3.5 12L6 14.5V18h3.5zm0-8.5"/>',width:24,height:24},"mdi:cube-outline":{body:'<path fill="currentColor" d="M21 16.5c0 .38-.21.71-.53.88l-7.9 4.44c-.16.12-.36.18-.57.18s-.41-.06-.57-.18l-7.9-4.44A.99.99 0 0 1 3 16.5v-9c0-.38.21-.71.53-.88l7.9-4.44c.16-.12.36-.18.57-.18s.41.06.57.18l7.9 4.44c.32.17.53.5.53.88zM12 4.15L6.04 7.5L12 10.85l5.96-3.35zM5 15.91l6 3.38v-6.71L5 9.21zm14 0v-6.7l-6 3.37v6.71z"/>',width:24,height:24},"mdi:format-color-fill":{body:'<path fill="currentColor" d="M19 11.5s-2 2.17-2 3.5a2 2 0 0 0 2 2a2 2 0 0 0 2-2c0-1.33-2-3.5-2-3.5M5.21 10L10 5.21L14.79 10m1.77-1.06L7.62 0L6.21 1.41l2.38 2.38l-5.15 5.15c-.59.56-.59 1.53 0 2.12l5.5 5.5c.29.29.68.44 1.06.44s.77-.15 1.06-.44l5.5-5.5c.59-.59.59-1.56 0-2.12"/>',width:24,height:24},"mdi:image-remove":{body:'<path fill="currentColor" d="M13.3 21H5c-1.1 0-2-.9-2-2V5c0-1.1.9-2 2-2h14c1.1 0 2 .9 2 2v8.3c-.6-.2-1.3-.3-2-.3c-1.1 0-2.2.3-3.1.9L14.5 12L11 16.5l-2.5-3L5 18h8.1c-.1.3-.1.7-.1 1c0 .7.1 1.4.3 2m7.1-2l2.1 2.1l-1.4 1.4l-2.1-2.1l-2.1 2.1l-1.4-1.4l2.1-2.1l-2.1-2.1l1.4-1.4l2.1 2.1l2.1-2.1l1.4 1.4z"/>',width:24,height:24},"ph:monitor-fill":{body:'<path fill="currentColor" d="M232 64v112a24 24 0 0 1-24 24H48a24 24 0 0 1-24-24V64a24 24 0 0 1 24-24h160a24 24 0 0 1 24 24m-72 152H96a8 8 0 0 0 0 16h64a8 8 0 0 0 0-16"/>',width:256,height:256},"radix-icons:font-size":{body:'<path fill="currentColor" d="M2.5 2.1a.4.4 0 0 1 .283.117l2 2l.05.064a.4.4 0 0 1-.05.503a.4.4 0 0 1-.503.05l-.063-.05L2.9 3.467v8.067l1.317-1.317a.4.4 0 0 1 .566.566l-2 2a.4.4 0 0 1-.566 0l-2-2l-.051-.063a.4.4 0 0 1 .554-.554l.063.051l1.316 1.316V3.467L.783 4.784a.401.401 0 0 1-.566-.567l2-2l.061-.05A.4.4 0 0 1 2.5 2.1m5.47 9.64a.501.501 0 0 1-.94-.34zm2.53-8.99a.5.5 0 0 1 .47.33l3 8.32a.5.5 0 0 1-.94.34l-.983-2.724H8.953l-.982 2.724l-.471-.17l-.47-.17l3-8.32l.031-.07a.5.5 0 0 1 .439-.26M9.259 8.166h2.482L10.5 4.725z"/>',width:15,height:15}},Fa=typeof window<"u";async function ed(){if(!Fa)return;const{addIcon:e}=await Promise.resolve().then(()=>hu);for(const[t,r]of Object.entries(Qc))e(t,r)}let ts=!1;function td(){ts||!Fa||(ts=!0,ed().catch(()=>{ts=!1}))}const za={elements:["text","image","shape","path","group"],transforms:["custom","circle","lean","arch","ascend","wave","flag","image","group","shape","path"],effects:["stroke","mask","distress","knockout"],panels:["layers","effects","export","images","artboards"],tools:["select","pen","crop","zoom"],features:{export:!0,multiArtboard:!0,richText:!0,undo:!0,keyboardShortcuts:!0}},qs={elements:["text","image"],transforms:["custom","circle","arch","wave","image"],effects:["stroke"],panels:[],tools:["select","zoom"],features:{export:!0,multiArtboard:!1,richText:!1,undo:!0,keyboardShortcuts:!0}},Oa={name:"compact-customizer",layout:{slots:{topbar:["contextual-toolbar"],canvas:["canvas"]}},capabilities:{...qs,effects:["stroke"],panels:[],tools:["select","zoom"]},behavior:{toolbar:"contextual",selection:"single",panelMode:"drawer",onEmptyClick:"deselect",autoExport:!1},style:{density:"compact",toolbarVariant:"pill",panelVariant:"floating"},content:{sampleText:"Your Text",defaultFontFamily:"Poppins"}},_a={name:"pro-studio",layout:{slots:{topbar:["add-element-menu","undo-redo-controls","contextual-toolbar"],left:["layers-panel"],canvas:["canvas"],right:["effects-panel"]}},capabilities:za,behavior:{toolbar:"contextual",selection:"multi",panelMode:"sidebar",onEmptyClick:"deselect",autoExport:!1},style:{density:"comfortable",toolbarVariant:"flat",panelVariant:"card"},content:{sampleText:"New Text",defaultFontFamily:"Poppins"}},Ba={name:"embed-only",layout:{slots:{canvas:["canvas"]}},capabilities:{...qs,panels:[],tools:["select"],features:{export:!0,multiArtboard:!1,richText:!1,undo:!0,keyboardShortcuts:!1}},behavior:{toolbar:"none",selection:"single",panelMode:"inline",onEmptyClick:"noop",autoExport:!0},style:{density:"compact",toolbarVariant:"minimal",panelVariant:"flush"}},Es=new Map([["compact-customizer",Oa],["pro-studio",_a],["embed-only",Ba]]);function Ha(e){if(typeof e=="string"){const t=Es.get(e);if(!t){const r=Array.from(Es.keys()).join(", ");throw new Error(`[resolveKit] Unknown kit preset "${e}". Valid presets: ${r}`)}return t}return e}const $a=l.createContext(null);function nd({kit:e,children:t}){const[r,o]=l.useState(e);l.useEffect(()=>{o(e)},[e]);const s=l.useCallback(a=>{const c=typeof a=="string"?Ha(a):a;o(c)},[]),i=l.useMemo(()=>({kit:r,setKit:s}),[r,s]);return n.jsx($a.Provider,{value:i,children:t})}function Ua(){const e=l.useContext($a);if(!e)throw new Error("useKit must be used within a KitProvider");return e}function rd(){const{kit:e}=Ua();return e.capabilities}const od=T.createLogger("ElementPreviewRenderer"),sd={width:40,height:40,padding:4,backgroundColor:"transparent"};function Ts(e,t={}){const r={...sd,...t},o=document.createElement("canvas");o.width=r.width,o.height=r.height;const s=o.getContext("2d");if(!s)return"";r.backgroundColor!=="transparent"&&(s.fillStyle=r.backgroundColor,s.fillRect(0,0,r.width,r.height)),s.save();try{e instanceof T.GroupElement?ad(s,e,r):id(s,e,r)}catch(i){od.warn("Failed to generate preview:",i)}return s.restore(),o.toDataURL("image/png")}function id(e,t,r){var g;const o=((g=t.getBoundingBox)==null?void 0:g.call(t))||{x:0,y:0,width:100,height:100},s=o.width,i=o.height;if(s===0||i===0){Oi(e,t,r);return}const a=r.width-r.padding*2,c=r.height-r.padding*2,d=Math.min(a/s,c/i,1),u=s*d,h=i*d,f=r.padding+(a-u)/2,p=r.padding+(c-h)/2;e.save(),e.translate(f-o.x*d,p-o.y*d),e.scale(d,d),typeof t.render=="function"?t.render(e,!1,!1):Oi(e,t,r),e.restore()}function Oi(e,t,r){e.fillStyle="#888888",e.font="10px Arial",e.textAlign="center",e.textBaseline="middle";const o=t.transformType||"Element";e.fillText(o,r.width/2,r.height/2)}function ad(e,t,r){const o=r.width-r.padding*2,s=r.height-r.padding*2,i=r.padding,a=r.padding;e.fillStyle="#888888",e.strokeStyle="#666666",e.lineWidth=1;const c=s*.7,d=a+s*.3,u=o*.4,h=s*.2;e.fillRect(i,d,o,c),e.fillRect(i,d-h,u,h),t.children&&t.children.length>0&&(e.fillStyle="#FFFFFF",e.font="bold 10px Arial",e.textAlign="center",e.textBaseline="middle",e.fillText(t.children.length.toString(),i+o/2,d+c/2))}const Vt=T.createLogger("Layers");async function _i(e,t=64,r="transparent"){try{return Ts(e,{width:t,height:t,padding:8,backgroundColor:r})||null}catch(o){return Vt.error("Failed to generate preview:",o),null}}function Ya(e,t,r,o,s,i=0,a=null){return(i>0?e:e.filter(d=>{const u=d.parentId??null;return d instanceof T.GroupElement,u===null})).map(d=>{const u=d instanceof T.GroupElement,h=t===d.id||r.includes(d.id),f={id:d.id,name:d.name||`Layer ${d.id.slice(0,8)}`,type:d.transformType,visible:d.visible??!0,locked:d.locked??!1,isSelected:h,isGroup:u,depth:i,parentId:a,previewUrl:o.get(d.id)||null,refreshPreview:async()=>{await s(d.id)}};return u&&d instanceof T.GroupElement&&(f.children=Ya(d.children,t,r,o,s,i+1,d.id)),f})}function Wa(e){const t=[];for(const r of e)t.push(r),r.children&&t.push(...Wa(r.children));return t}function Zs(e={}){const{artboardId:t,includeHidden:r=!0,previewSize:o=64,previewBackgroundColor:s="transparent"}=e,{elements:i,selectedId:a,multiSelection:c,artboardManager:d,handleSelectionChange:u,handleElementUpdate:h,setMultiSelection:f,executeAddElement:p,executeRemoveElement:g,executeReorderElement:b}=Yt.useEditor(),x=l.useRef(new Map),[y,v]=l.useState(0),w=d.getActiveArtboardId(),C=t!==void 0?t:w,j=l.useCallback(async re=>{const te=i.find(ye=>ye.id===re);if(!te)return;const he=await _i(te,o,s);x.current.set(re,he),v(ye=>ye+1)},[i,o,s]),M=l.useMemo(()=>{let re=i;if(C){const te=d.getElementsOnArtboard(C);re=re.filter(he=>te.includes(he.id))}return r||(re=re.filter(te=>te.visible!==!1)),re},[i,C,r,d]),S=l.useMemo(()=>Ya(M,a,c,x.current,j),[M,a,c,j,y]),R=l.useMemo(()=>Wa(S),[S]),I=l.useMemo(()=>R.filter(re=>re.isSelected),[R]),D=l.useCallback((re,te=!1)=>{te?c.includes(re)?f(c.filter(he=>he!==re)):f([...c,re]):u(re)},[c,f,u]),E=l.useCallback(re=>{f(re)},[f]),O=l.useCallback(()=>{u(null),f([])},[u,f]),z=l.useCallback(re=>{const te=i.find(ye=>ye.id===re);if(!te)return;const he=te.clone();he.visible=!(te.visible??!0),h(he)},[i,h]),B=l.useCallback(re=>{const te=i.find(ye=>ye.id===re);if(!te)return;const he=te.clone();he.locked=!(te.locked??!1),h(he)},[i,h]),k=l.useCallback((re,te)=>{const he=i.find(we=>we.id===re);if(!he)return;const ye=he.clone();ye.name=te,h(ye)},[i,h]),Y=l.useCallback(re=>{const te=i.find(he=>he.id===re);if(!te){Vt.warn(`Element ${re} not found for deletion`);return}g(te),(a===re||c.includes(re))&&(u(null),f(c.filter(he=>he!==re)))},[i,g,a,c,u,f]),_=l.useCallback(re=>{const te=i.find(N=>N.id===re);if(!te){Vt.warn(`Element ${re} not found for duplication`);return}const ye=te.clone().toJSON();delete ye.id;const we=te.constructor,Pe=new we(ye);Pe.x=te.x+20,Pe.y=te.y+20;const me=d.getArtboardIdForElement(re);if(!me){Vt.warn(`Element ${re} not associated with any artboard`);return}p(Pe,me,re),u(Pe.id)},[i,d,p,u]),G=l.useCallback((re,te)=>{if(re===te)return;if(re<0||re>=M.length){Vt.warn(`Invalid fromIndex: ${re}`);return}if(te<0||te>=M.length){Vt.warn(`Invalid toIndex: ${te}`);return}const he=M[re],ye=M[te],we=re<te?"after":"before";b(he.id,ye.id,we)},[M,b]),se=l.useCallback(re=>{const te=R.findIndex(he=>he.id===re);if(te<0){Vt.warn(`Layer ${re} not found`);return}te>=R.length-1||G(te,te+1)},[R,G]),A=l.useCallback(re=>{const te=R.findIndex(he=>he.id===re);if(te<0){Vt.warn(`Layer ${re} not found`);return}te<=0||G(te,te-1)},[R,G]),Z=l.useCallback(re=>{if(re.length<2){Vt.warn("Need at least 2 elements to create a group");return}const te=i.filter(le=>re.includes(le.id)&&le.transformType!=="shape");if(te.length<2){Vt.warn("Need at least 2 groupable elements (shapes cannot be grouped)");return}const he=te.map(le=>d.getArtboardIdForElement(le.id)),ye=[...new Set(he)];if(ye.length!==1||!ye[0]){Vt.warn("All elements must be on the same artboard to group");return}const we=ye[0],Pe=te.map(le=>le.getBoundingBox()).filter(Boolean);if(Pe.length===0){Vt.warn("Could not calculate bounding boxes for group");return}const me=Math.min(...Pe.map(le=>le.x)),N=Math.min(...Pe.map(le=>le.y)),ce=new T.GroupElement({x:me,y:N});ce.children=te.map(le=>{const Me=le.clone();return Me.x=le.x-me,Me.y=le.y-N,Me}),te.forEach(le=>g(le)),p(ce,we),u(ce.id),f([])},[i,d,g,p,u,f]),J=l.useCallback(re=>{const te=i.find(Pe=>Pe.id===re);if(!te){Vt.warn(`Element ${re} not found for ungrouping`);return}if(!(te instanceof T.GroupElement)){Vt.warn(`Element ${re} is not a group`);return}const he=te;if(!he.children||he.children.length===0){Vt.warn(`Group ${re} has no children`);return}const ye=d.getArtboardIdForElement(re);if(!ye){Vt.warn(`Group ${re} not associated with any artboard`);return}const we=he.children.map(Pe=>{const me=Pe.clone();return me.x=Pe.x+he.x,me.y=Pe.y+he.y,me});g(he),we.forEach(Pe=>p(Pe,ye)),we.length>0&&u(we[0].id),f([])},[i,d,g,p,u,f]),q=l.useCallback(async(re=o)=>{const te=async he=>{for(const ye of he){const we=await _i(ye,re,s);x.current.set(ye.id,we),ye instanceof T.GroupElement&&ye.children.length>0&&await te(ye.children)}};await te(M),v(he=>he+1)},[o,s,M]),ae=l.useCallback(()=>{x.current.clear()},[]),Le=l.useCallback((re,te,he)=>{b(re,te,he)},[b]),pe=l.useCallback((re,te,he,ye)=>{const we=i.find(ge=>ge.id===ye);if(!we||!(we instanceof T.GroupElement)){Vt.warn(`Group ${ye} not found for reorder`);return}const Pe=we.clone(),me=Pe.children.findIndex(ge=>ge.id===re),N=Pe.children.findIndex(ge=>ge.id===te);if(me===-1||N===-1){Vt.warn(`Children not found in group for reorder: ${re}, ${te}`);return}const[ce]=Pe.children.splice(me,1),le=Pe.children.findIndex(ge=>ge.id===te),Me=he==="before"?le:le+1;Pe.children.splice(Me,0,ce),h(Pe)},[i,h]),U=l.useCallback(re=>{for(const te of i){if(te.id===re)return te;if(te instanceof T.GroupElement){const he=te.children.find(ye=>ye.id===re);if(he)return he}}return null},[i]),W=l.useCallback(re=>{for(const te of i)if(te instanceof T.GroupElement&&te.children.some(he=>he.id===re))return te;return null},[i]),Ie=l.useCallback((re,te)=>{const he=i.find(N=>N.id===re),ye=i.find(N=>N.id===te);if(!he||!ye||!(ye instanceof T.GroupElement)){Vt.warn(`Cannot add ${re} to group ${te}`);return}if(!d.getArtboardIdForElement(re))return;const Pe=ye.clone(),me=he.clone();me.x=he.x,me.y=he.y,Pe.addChild(me),g(he),h(Pe)},[i,d,g,h]),ke=l.useCallback((re,te,he)=>{const ye=W(re);if(!ye){Vt.warn(`Element ${re} is not inside a group`);return}const we=ye.children.find(ce=>ce.id===re);if(!we)return;const Pe=d.getArtboardIdForElement(ye.id);if(!Pe)return;const me=we.clone(),N=ye.clone();N.removeChild(re),h(N),te&&he?p(me,Pe,he==="after"?te:void 0,he==="before"?te:void 0):p(me,Pe,void 0,ye.id),u(me.id)},[W,d,g,h,p,u]),Ke=l.useCallback(()=>{const re=d.getActiveArtboardId();if(!re){Vt.warn("No active artboard for creating a group");return}const te=new T.GroupElement({x:0,y:0,name:"New Group"});p(te,re),u(te.id)},[d,p,u]);return{layers:S,flatLayers:R,selectedLayers:I,selectLayer:D,selectMultipleLayers:E,clearSelection:O,toggleVisibility:z,toggleLock:B,renameLayer:k,deleteLayer:Y,duplicateLayer:_,reorderLayers:G,reorderById:Le,reorderWithinGroup:pe,moveLayerForward:se,moveLayerBackward:A,groupLayers:Z,ungroupLayer:J,addToGroup:Ie,removeFromGroup:ke,createEmptyGroup:Ke,findElementById:U,findParentGroup:W,generateAllPreviews:q,clearPreviewCache:ae,artboardId:C,artboardManager:d,layerCount:R.length}}function ld(e,t){if(t instanceof T.ImageElement&&t.isCropping||e instanceof T.ImageElement&&e.isCropping)return!0;if(e instanceof T.GroupElement){for(const r of e.children)if(r instanceof T.ImageElement&&r.isCropping)return!0}return!1}function cd(e){const t=(e==null?void 0:e.enabled)??!0,{selectedElement:r,activeChildElement:o,multiSelection:s,elements:i,handleElementUpdate:a,handleCopyElements:c,handlePasteElements:d,executeRemoveElement:u,handleSelectionChange:h,setMultiSelection:f,undoActiveArtboard:p,redoActiveArtboard:g,setHideHandles:b,handleAddElement:x,isToolbarMenuOpen:y}=Yt.useEditor(),{duplicateLayer:v}=Zs();l.useEffect(()=>{if(!t)return;const w=j=>{var S;const M=j.target;if(!(M.tagName==="INPUT"||M.tagName==="TEXTAREA")&&!((S=M.closest)!=null&&S.call(M,'[role="listbox"], [role="menu"], [role="tablist"]'))){if((j.metaKey||j.ctrlKey)&&j.key==="z"&&!j.shiftKey){j.preventDefault(),p();return}if((j.metaKey||j.ctrlKey)&&j.shiftKey&&j.key==="z"||j.ctrlKey&&j.key==="y"){j.preventDefault(),g();return}if((j.metaKey||j.ctrlKey)&&j.key==="c"){j.preventDefault(),c();return}if((j.metaKey||j.ctrlKey)&&j.key==="v"){j.preventDefault(),d();return}if((j.metaKey||j.ctrlKey)&&j.key==="d"){j.preventDefault(),r?v(r.id):s.length>0&&s.forEach(R=>{v(R)});return}if(j.key==="Escape"){j.preventDefault(),(r||s.length>0)&&(h(null),f([]));return}if(j.key==="t"&&!j.metaKey&&!j.ctrlKey&&!j.shiftKey&&!j.altKey){j.preventDefault(),x("text");return}if(j.key==="Delete"||j.key==="Backspace"){if(y||ld(r,o))return;if(j.preventDefault(),s.length>0){i.filter(I=>s.includes(I.id)).forEach(I=>{u(I)}),f([]),h(null);return}r&&(u(r),h(null));return}if(j.key==="ArrowUp"||j.key==="ArrowDown"||j.key==="ArrowLeft"||j.key==="ArrowRight"){if(s.length>0){j.preventDefault(),b(!0);const R=j.shiftKey?10:1;let I=0,D=0;j.key==="ArrowLeft"&&(I=-R),j.key==="ArrowRight"&&(I=R),j.key==="ArrowUp"&&(D=-R),j.key==="ArrowDown"&&(D=R),i.filter(O=>s.includes(O.id)).forEach(O=>{const z=O.clone();z.x+=I,z.y+=D,a(z)});return}if(r){j.preventDefault(),b(!0);const R=j.shiftKey?10:1;let I=0,D=0;j.key==="ArrowLeft"&&(I=-R),j.key==="ArrowRight"&&(I=R),j.key==="ArrowUp"&&(D=-R),j.key==="ArrowDown"&&(D=R);const E=r.clone();E.x+=I,E.y+=D,a(E);return}}}},C=j=>{(j.key==="ArrowUp"||j.key==="ArrowDown"||j.key==="ArrowLeft"||j.key==="ArrowRight")&&b(!1)};return window.addEventListener("keydown",w),window.addEventListener("keyup",C),()=>{window.removeEventListener("keydown",w),window.removeEventListener("keyup",C)}},[t,r,o,s,i,a,c,d,u,h,f,p,g,b,v,y])}const dd=280,ud=e=>1-Math.pow(1-e,3);function hd(e,t=dd){const[r,o]=l.useState(e),s=l.useRef(r);s.current=r;const i=l.useRef(null),a=e?`${e.x},${e.y},${e.width},${e.height}`:"none";return l.useEffect(()=>{if(i.current!==null&&(cancelAnimationFrame(i.current),i.current=null),!e){o(null);return}const c=s.current;if(!c){o(e);return}if(c.x===e.x&&c.y===e.y&&c.width===e.width&&c.height===e.height)return;const d=performance.now(),u=h=>{const f=Math.min(1,(h-d)/t),p=ud(f);o({x:c.x+(e.x-c.x)*p,y:c.y+(e.y-c.y)*p,width:c.width+(e.width-c.width)*p,height:c.height+(e.height-c.height)*p}),f<1?i.current=requestAnimationFrame(u):i.current=null};return i.current=requestAnimationFrame(u),()=>{i.current!==null&&(cancelAnimationFrame(i.current),i.current=null)}},[a,t]),r}function Xa(e,t){if(e.length===0)return{start:0,end:0};const r=Math.max(0,Math.min(t,e.length-1)),o=/[^\s]/;if(!o.test(e[r])){let a=r;for(;a<e.length&&!o.test(e[a]);)a++;if(a<e.length){let d=a;for(;d<e.length&&o.test(e[d]);)d++;return{start:a,end:d}}let c=r;for(;c>0&&!o.test(e[c-1]);)c--;if(c>0){let d=c;for(;d>0&&o.test(e[d-1]);)d--;return{start:d,end:c}}return{start:r,end:r}}let s=r;for(;s>0&&o.test(e[s-1]);)s--;let i=r;for(;i<e.length&&o.test(e[i]);)i++;return{start:s,end:i}}function fd(e,t){const{fontSize:r,fontFamily:o,bold:s,italic:i,textAlign:a}=e,c=e.getRichText(),u=e.getVisualBoundingBox().width;let h=u,f=0;e.transformType==="custom"&&(f=T.HORIZONTAL_PADDING,h=u-f*2);const p=T.wrapText(e.getText(),h,r,o,s,i,void 0,!0);let g=0,b=0;for(let D=0;D<p.length;D++){const E=g+p[D].length;if(t<=E){b=D;break}g+=p[D].length+1,D===p.length-1&&(b=D)}const x=p[b],y=t-g;let v=x,w=0;const C=b===0,j=b===p.length-1;if(!C){const D=x.match(/^ +/);w=D?D[0].length:0,w>0&&(v=v.substring(w))}if(!j){const D=v.match(/ +$/),E=D?D[0].length:0;E>0&&(v=v.substring(0,v.length-E))}const M=T.measureTextWidth(v,r,o,s,i);let S=f;a==="center"?S=(u-M)/2:a==="right"&&(S=u-f-M);let R=S;const I=Math.min(y,x.length);for(let D=0;D<I;D++){if(!C&&D<w)continue;const E=x[D],O=g+D,z=c.getStyleAt(O),B=z.fontSize||r,k=z.fontFamily||o,Y=z.bold!==void 0?z.bold:s,_=z.italic!==void 0?z.italic:i;R+=T.measureTextWidth(E,B,k,Y,_)}return{lineIndex:b,lineCount:p.length,xPositionInLine:R,lineStartIndex:g}}function pd(e,t,r){const{fontSize:o}=e,i=o*1.2,a=fd(e,t),c=r==="up"?Math.max(0,a.lineIndex-1):Math.min(a.lineCount-1,a.lineIndex+1);if(c===a.lineIndex)return t;const d=c*i+i/2;return Xn(e,{x:a.xPositionInLine,y:d})}function Xn(e,t){const{fontSize:r,fontFamily:o,bold:s,italic:i,textAlign:a}=e,c=e.getRichText(),u=e.getVisualBoundingBox().width;let h=u,f=0;e.transformType==="custom"&&(f=T.HORIZONTAL_PADDING,h=u-f*2);const p=T.wrapText(e.getText(),h,r,o,s,i,void 0,!0),b=r*1.2;let x=0,y=0;if(t.y<0)return 0;for(let z=0;z<p.length;z++){if(t.y>=y&&t.y<y+b){x=z;break}y+=b,z===p.length-1&&(x=z)}let v=0;for(let z=0;z<x;z++)v+=p[z].length+1;const w=p[x];let C=w,j=0,M=0;const S=x===0,R=x===p.length-1;if(!S){const z=w.match(/^ +/);j=z?z[0].length:0,j>0&&(C=C.substring(j))}if(!R){const z=C.match(/ +$/);M=z?z[0].length:0,M>0&&(C=C.substring(0,C.length-M))}const I=T.measureTextWidth(C,r,o,s,i);let D=f;a==="center"?D=(u-I)/2:a==="right"&&(D=u-f-I);const E=t.x-D;if(E<=0)return v+j;if(E>=I)return v+w.length-M;let O=0;for(let z=0;z<w.length;z++){if(!S&&z<j||!R&&z>=w.length-M)continue;const B=w[z],k=v+z,Y=c.getStyleAt(k),_=Y.fontSize||r,G=Y.fontFamily||o,se=Y.bold!==void 0?Y.bold:s,A=Y.italic!==void 0?Y.italic:i,Z=T.measureTextWidth(B,_,G,se,A);if(E<O+Z/2)return k;O+=Z}return v+w.length}function md(){const[e,t]=l.useState(!1),[r,o]=l.useState({x:0,y:0}),[s,i]=l.useState({x:0,y:0}),[a,c]=l.useState([]);return l.useEffect(()=>{},[e]),{isMarqueeSelecting:e,marqueeStart:r,marqueeEnd:s,marqueePreviewSelection:a,startMarqueeSelection:(f,p)=>{t(!0),o({x:f,y:p}),i({x:f,y:p}),c([])},updateMarqueeSelection:(f,p,g)=>{i({x:f,y:p});const b=Math.min(r.x,f),x=Math.max(r.x,f),y=Math.min(r.y,p),v=Math.max(r.y,p),w=[];g.forEach(C=>{if(C.visible===!1)return;const j=C.getVisualBoundingBox(),M=j.x,S=j.x+j.width,R=j.y,I=j.y+j.height;!(S<b||M>x||I<y||R>v)&&w.push(C.id)}),c(w)},finishMarqueeSelection:f=>{const p=[...a];t(!1),p.length>0&&f(p),c([])}}}class gd{constructor(){this.state={active:!1,pathElement:null,points:[],currentPoint:null,isDraggingHandle:!1,previewPoint:null,isClosing:!1,closingClickPos:null}}startPath(t){this.state.active=!0,this.state.pathElement=t,this.state.points=[],this.state.currentPoint=null,this.state.isDraggingHandle=!1,this.state.previewPoint=null,this.state.isClosing=!1,this.state.closingClickPos=null}editPath(t){this.state.active=!0,this.state.pathElement=t,this.state.points=t.transformData.points.map(r=>({...r})),this.state.currentPoint=null,this.state.isDraggingHandle=!1,this.state.previewPoint=null,this.state.isClosing=!1,this.state.closingClickPos=null}isActive(){return this.state.active}getState(){return{...this.state}}setPreviewPoint(t,r){this.state.previewPoint={x:t,y:r}}clearPreviewPoint(){this.state.previewPoint=null}addPoint(t,r){const o={id:`point-${Date.now()}-${Math.random()}`,x:t,y:r,type:"corner"};return this.state.points.push(o),this.state.currentPoint=o,this.state.isDraggingHandle=!1,o}startDraggingHandle(){this.state.currentPoint&&(this.state.isDraggingHandle=!0,this.state.currentPoint.type==="corner"&&(this.state.currentPoint.type="bezier"))}updateHandle(t,r){if(!(!this.state.currentPoint||!this.state.isDraggingHandle))if(this.state.isClosing&&this.state.closingClickPos){const o=t-this.state.closingClickPos.x,s=r-this.state.closingClickPos.y,i=this.state.points[0];i.handleIn={x:o,y:s},i.handleOut={x:-o,y:-s},i.type==="corner"&&(i.type="bezier")}else{const o=t-this.state.currentPoint.x,s=r-this.state.currentPoint.y;this.state.currentPoint.handleOut={x:o,y:s},this.state.currentPoint.type==="smooth"?this.state.currentPoint.handleIn={x:-o,y:-s}:this.state.currentPoint.type==="bezier"&&(this.state.currentPoint.handleIn={x:-o,y:-s})}}finishDraggingHandle(){this.state.isDraggingHandle=!1,this.state.isClosing?this.closePath():this.state.currentPoint=null}canClosePath(t,r,o=10){if(this.state.points.length<3)return!1;const s=this.state.points[0],i=t-s.x,a=r-s.y;return Math.sqrt(i*i+a*a)<=o}startClosing(t,r){this.state.points.length<3||(this.state.isClosing=!0,this.state.closingClickPos={x:t,y:r},this.state.currentPoint=this.state.points[0])}isClosingPath(){return this.state.isClosing}recenterPath(){if(!this.state.pathElement||this.state.points.length===0)return;let t=1/0,r=1/0,o=-1/0,s=-1/0;for(const c of this.state.points)t=Math.min(t,c.x),r=Math.min(r,c.y),o=Math.max(o,c.x),s=Math.max(s,c.y);const i=(t+o)/2,a=(r+s)/2;this.state.pathElement.x+=i,this.state.pathElement.y+=a;for(const c of this.state.points)c.x-=i,c.y-=a}closePath(){this.state.pathElement&&(this.recenterPath(),this.state.pathElement.transformData.points=[...this.state.points],this.state.pathElement.transformData.closed=!0,this.state.pathElement.transformData.fillEnabled=!0,this.state.pathElement.transformData.fillColor=T.getThemeShapeFillColor(),this.state.pathElement.updateBounds(),this.endPath())}finishPath(){this.state.pathElement&&(this.recenterPath(),this.state.pathElement.transformData.points=[...this.state.points],this.state.pathElement.transformData.closed=!1,this.state.pathElement.updateBounds(),this.endPath())}deleteLastPoint(){this.state.points.length!==0&&(this.state.points.pop(),this.state.currentPoint=null)}cancelPath(){const t=this.state.pathElement;return this.state.active=!1,this.state.pathElement=null,this.state.points=[],this.state.currentPoint=null,this.state.isDraggingHandle=!1,this.state.previewPoint=null,this.state.isClosing=!1,this.state.closingClickPos=null,t}endPath(){this.state.active=!1,this.state.pathElement=null,this.state.points=[],this.state.currentPoint=null,this.state.isDraggingHandle=!1,this.state.previewPoint=null,this.state.isClosing=!1,this.state.closingClickPos=null}getPoints(){return this.state.points}getCurrentPoint(){return this.state.currentPoint}isDraggingHandle(){return this.state.isDraggingHandle}renderPreview(t,r){var a,c,d,u,h,f,p,g;if(!this.state.active||this.state.points.length===0)return;const{points:o,previewPoint:s,currentPoint:i}=this.state;if(t.save(),t.translate(r.x,r.y),t.strokeStyle=T.getThemePenPathColor(),t.lineWidth=2,t.setLineDash([]),t.beginPath(),o.length>0){const b=o[0];t.moveTo(b.x,b.y);for(let y=1;y<o.length;y++){const v=o[y-1],w=o[y];if(v.handleOut||w.handleIn){const j=v.x+(((a=v.handleOut)==null?void 0:a.x)||0),M=v.y+(((c=v.handleOut)==null?void 0:c.y)||0),S=w.x+(((d=w.handleIn)==null?void 0:d.x)||0),R=w.y+(((u=w.handleIn)==null?void 0:u.y)||0);t.bezierCurveTo(j,M,S,R,w.x,w.y)}else t.lineTo(w.x,w.y)}const x=this.state.isClosing||r.transformData.closed;if(x&&o.length>2){const y=o[o.length-1],v=o[0];if(y.handleOut||v.handleIn){const C=y.x+(((h=y.handleOut)==null?void 0:h.x)||0),j=y.y+(((f=y.handleOut)==null?void 0:f.y)||0),M=v.x+(((p=v.handleIn)==null?void 0:p.x)||0),S=v.y+(((g=v.handleIn)==null?void 0:g.y)||0);t.bezierCurveTo(C,j,M,S,v.x,v.y)}else t.lineTo(v.x,v.y)}else s&&!this.state.isDraggingHandle&&t.lineTo(s.x,s.y);t.stroke(),x&&r.transformData.fillEnabled&&(t.fillStyle=r.transformData.fillColor||T.getThemeShapeFillColor(),t.globalAlpha=r.transformData.fillOpacity??1,t.fill(),t.globalAlpha=1)}t.setLineDash([]);for(let b=0;b<o.length;b++){const x=o[b];if(b===0&&o.length>1&&(t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=2,t.beginPath(),t.arc(x.x,x.y,8,0,Math.PI*2),t.stroke()),t.fillStyle=T.getThemePenAnchorFillColor(),t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=2,t.beginPath(),t.arc(x.x,x.y,4,0,Math.PI*2),t.fill(),t.stroke(),x.handleIn){const v=x.x+x.handleIn.x,w=x.y+x.handleIn.y;t.strokeStyle=T.getThemePenHandleColor(),t.lineWidth=1,t.beginPath(),t.moveTo(x.x,x.y),t.lineTo(v,w),t.stroke(),t.fillStyle=T.getThemePenHandleColor(),t.beginPath(),t.arc(v,w,3,0,Math.PI*2),t.fill()}if(x.handleOut){const v=x.x+x.handleOut.x,w=x.y+x.handleOut.y;t.strokeStyle=T.getThemePenHandleColor(),t.lineWidth=1,t.beginPath(),t.moveTo(x.x,x.y),t.lineTo(v,w),t.stroke(),t.fillStyle=T.getThemePenHandleColor(),t.beginPath(),t.arc(v,w,3,0,Math.PI*2),t.fill()}}if(s&&this.canClosePath(s.x,s.y)){const b=o[0];t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=3,t.beginPath(),t.arc(b.x,b.y,6,0,Math.PI*2),t.stroke()}if(s&&!this.state.isDraggingHandle){const b=T.getThemeAccentColor(),x=b.replace("#",""),y=parseInt(x.substring(0,2),16),v=parseInt(x.substring(2,4),16),w=parseInt(x.substring(4,6),16);t.fillStyle=`rgba(${y}, ${v}, ${w}, 0.3)`,t.strokeStyle=b,t.lineWidth=2,t.beginPath(),t.arc(s.x,s.y,4,0,Math.PI*2),t.fill(),t.stroke()}t.restore()}}function xd(e,t){const r=e.icons,o=e.aliases||Object.create(null),s=Object.create(null);function i(a){if(r[a])return s[a]=[];if(!(a in s)){s[a]=null;const c=o[a]&&o[a].parent,d=c&&i(c);d&&(s[a]=[c].concat(d))}return s[a]}return Object.keys(r).concat(Object.keys(o)).forEach(i),s}const Va=Object.freeze({left:0,top:0,width:16,height:16}),So=Object.freeze({rotate:0,vFlip:!1,hFlip:!1}),Js=Object.freeze({...Va,...So}),Rs=Object.freeze({...Js,body:"",hidden:!1});function bd(e,t){const r={};!e.hFlip!=!t.hFlip&&(r.hFlip=!0),!e.vFlip!=!t.vFlip&&(r.vFlip=!0);const o=((e.rotate||0)+(t.rotate||0))%4;return o&&(r.rotate=o),r}function Bi(e,t){const r=bd(e,t);for(const o in Rs)o in So?o in e&&!(o in r)&&(r[o]=So[o]):o in t?r[o]=t[o]:o in e&&(r[o]=e[o]);return r}function yd(e,t,r){const o=e.icons,s=e.aliases||Object.create(null);let i={};function a(c){i=Bi(o[c]||s[c],i)}return a(t),r.forEach(a),Bi(e,i)}function Ga(e,t){const r=[];if(typeof e!="object"||typeof e.icons!="object")return r;e.not_found instanceof Array&&e.not_found.forEach(s=>{t(s,null),r.push(s)});const o=xd(e);for(const s in o){const i=o[s];i&&(t(s,yd(e,s,i)),r.push(s))}return r}const vd={provider:"",aliases:{},not_found:{},...Va};function ns(e,t){for(const r in t)if(r in e&&typeof e[r]!=typeof t[r])return!1;return!0}function Ka(e){if(typeof e!="object"||e===null)return null;const t=e;if(typeof t.prefix!="string"||!e.icons||typeof e.icons!="object"||!ns(e,vd))return null;const r=t.icons;for(const s in r){const i=r[s];if(!s||typeof i.body!="string"||!ns(i,Rs))return null}const o=t.aliases||Object.create(null);for(const s in o){const i=o[s],a=i.parent;if(!s||typeof a!="string"||!r[a]&&!o[a]||!ns(i,Rs))return null}return t}const Hi=Object.create(null);function wd(e,t){return{provider:e,prefix:t,icons:Object.create(null),missing:new Set}}function vr(e,t){const r=Hi[e]||(Hi[e]=Object.create(null));return r[t]||(r[t]=wd(e,t))}function qa(e,t){return Ka(t)?Ga(t,(r,o)=>{o?e.icons[r]=o:e.missing.add(r)}):[]}function Cd(e,t,r){try{if(typeof r.body=="string")return e.icons[t]={...r},!0}catch{}return!1}const Za=/^[a-z0-9]+(-[a-z0-9]+)*$/,Do=(e,t,r,o="")=>{const s=e.split(":");if(e.slice(0,1)==="@"){if(s.length<2||s.length>3)return null;o=s.shift().slice(1)}if(s.length>3||!s.length)return null;if(s.length>1){const c=s.pop(),d=s.pop(),u={provider:s.length>0?s[0]:o,prefix:d,name:c};return t&&!bo(u)?null:u}const i=s[0],a=i.split("-");if(a.length>1){const c={provider:o,prefix:a.shift(),name:a.join("-")};return t&&!bo(c)?null:c}if(r&&o===""){const c={provider:o,prefix:"",name:i};return t&&!bo(c,r)?null:c}return null},bo=(e,t)=>e?!!((t&&e.prefix===""||e.prefix)&&e.name):!1;let Ur=!1;function Ja(e){return typeof e=="boolean"&&(Ur=e),Ur}function $i(e){const t=typeof e=="string"?Do(e,!0,Ur):e;if(t){const r=vr(t.provider,t.prefix),o=t.name;return r.icons[o]||(r.missing.has(o)?null:void 0)}}function Qa(e,t){const r=Do(e,!0,Ur);if(!r)return!1;const o=vr(r.provider,r.prefix);return t?Cd(o,r.name,t):(o.missing.add(r.name),!0)}function el(e,t){if(typeof e!="object")return!1;if(typeof t!="string"&&(t=e.provider||""),Ur&&!t&&!e.prefix){let s=!1;return Ka(e)&&(e.prefix="",Ga(e,(i,a)=>{Qa(i,a)&&(s=!0)})),s}const r=e.prefix;if(!bo({prefix:r,name:"a"}))return!1;const o=vr(t,r);return!!qa(o,e)}const tl=Object.freeze({width:null,height:null}),nl=Object.freeze({...tl,...So}),Sd=/(-?[0-9.]*[0-9]+[0-9.]*)/g,kd=/^-?[0-9.]*[0-9]+[0-9.]*$/g;function Ns(e,t,r){if(t===1)return e;if(r=r||100,typeof e=="number")return Math.ceil(e*t*r)/r;if(typeof e!="string")return e;const o=e.split(Sd);if(o===null||!o.length)return e;const s=[];let i=o.shift(),a=kd.test(i);for(;;){if(a){const c=parseFloat(i);isNaN(c)?s.push(i):s.push(Math.ceil(c*t*r)/r)}else s.push(i);if(i=o.shift(),i===void 0)return s.join("");a=!a}}function jd(e,t="defs"){let r="";const o=e.indexOf("<"+t);for(;o>=0;){const s=e.indexOf(">",o),i=e.indexOf("</"+t);if(s===-1||i===-1)break;const a=e.indexOf(">",i);if(a===-1)break;r+=e.slice(s+1,i).trim(),e=e.slice(0,o).trim()+e.slice(a+1)}return{defs:r,content:e}}function Ed(e,t){return e?"<defs>"+e+"</defs>"+t:t}function Td(e,t,r){const o=jd(e);return Ed(o.defs,t+o.content+r)}const Rd=e=>e==="unset"||e==="undefined"||e==="none";function rl(e,t){const r={...Js,...e},o={...nl,...t},s={left:r.left,top:r.top,width:r.width,height:r.height};let i=r.body;[r,o].forEach(x=>{const y=[],v=x.hFlip,w=x.vFlip;let C=x.rotate;v?w?C+=2:(y.push("translate("+(s.width+s.left).toString()+" "+(0-s.top).toString()+")"),y.push("scale(-1 1)"),s.top=s.left=0):w&&(y.push("translate("+(0-s.left).toString()+" "+(s.height+s.top).toString()+")"),y.push("scale(1 -1)"),s.top=s.left=0);let j;switch(C<0&&(C-=Math.floor(C/4)*4),C=C%4,C){case 1:j=s.height/2+s.top,y.unshift("rotate(90 "+j.toString()+" "+j.toString()+")");break;case 2:y.unshift("rotate(180 "+(s.width/2+s.left).toString()+" "+(s.height/2+s.top).toString()+")");break;case 3:j=s.width/2+s.left,y.unshift("rotate(-90 "+j.toString()+" "+j.toString()+")");break}C%2===1&&(s.left!==s.top&&(j=s.left,s.left=s.top,s.top=j),s.width!==s.height&&(j=s.width,s.width=s.height,s.height=j)),y.length&&(i=Td(i,'<g transform="'+y.join(" ")+'">',"</g>"))});const a=o.width,c=o.height,d=s.width,u=s.height;let h,f;a===null?(f=c===null?"1em":c==="auto"?u:c,h=Ns(f,d/u)):(h=a==="auto"?d:a,f=c===null?Ns(h,u/d):c==="auto"?u:c);const p={},g=(x,y)=>{Rd(y)||(p[x]=y.toString())};g("width",h),g("height",f);const b=[s.left,s.top,d,u];return p.viewBox=b.join(" "),{attributes:p,viewBox:b,body:i}}const Nd=/\sid="(\S+)"/g,Md="IconifyId"+Date.now().toString(16)+(Math.random()*16777216|0).toString(16);let Id=0;function ol(e,t=Md){const r=[];let o;for(;o=Nd.exec(e);)r.push(o[1]);if(!r.length)return e;const s="suffix"+(Math.random()*16777216|Date.now()).toString(16);return r.forEach(i=>{const a=typeof t=="function"?t(i):t+(Id++).toString(),c=i.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");e=e.replace(new RegExp('([#;"])('+c+')([")]|\\.[a-z])',"g"),"$1"+a+s+"$3")}),e=e.replace(new RegExp(s,"g"),""),e}const Ms=Object.create(null);function Ad(e,t){Ms[e]=t}function Is(e){return Ms[e]||Ms[""]}function Qs(e){let t;if(typeof e.resources=="string")t=[e.resources];else if(t=e.resources,!(t instanceof Array)||!t.length)return null;return{resources:t,path:e.path||"/",maxURL:e.maxURL||500,rotate:e.rotate||750,timeout:e.timeout||5e3,random:e.random===!0,index:e.index||0,dataAfterTimeout:e.dataAfterTimeout!==!1}}const ei=Object.create(null),Nr=["https://api.simplesvg.com","https://api.unisvg.com"],yo=[];for(;Nr.length>0;)Nr.length===1||Math.random()>.5?yo.push(Nr.shift()):yo.push(Nr.pop());ei[""]=Qs({resources:["https://api.iconify.design"].concat(yo)});function sl(e,t){const r=Qs(t);return r===null?!1:(ei[e]=r,!0)}function ti(e){return ei[e]}const Dd=()=>{let e;try{if(e=fetch,typeof e=="function")return e}catch{}};let Ui=Dd();function Ld(e,t){const r=ti(e);if(!r)return 0;let o;if(!r.maxURL)o=0;else{let s=0;r.resources.forEach(a=>{s=Math.max(s,a.length)});const i=t+".json?icons=";o=r.maxURL-s-r.path.length-i.length}return o}function Pd(e){return e===404}const Fd=(e,t,r)=>{const o=[],s=Ld(e,t),i="icons";let a={type:i,provider:e,prefix:t,icons:[]},c=0;return r.forEach((d,u)=>{c+=d.length+1,c>=s&&u>0&&(o.push(a),a={type:i,provider:e,prefix:t,icons:[]},c=d.length),a.icons.push(d)}),o.push(a),o};function zd(e){if(typeof e=="string"){const t=ti(e);if(t)return t.path}return"/"}const Od=(e,t,r)=>{if(!Ui){r("abort",424);return}let o=zd(t.provider);switch(t.type){case"icons":{const i=t.prefix,c=t.icons.join(","),d=new URLSearchParams({icons:c});o+=i+".json?"+d.toString();break}case"custom":{const i=t.uri;o+=i.slice(0,1)==="/"?i.slice(1):i;break}default:r("abort",400);return}let s=503;Ui(e+o).then(i=>{const a=i.status;if(a!==200){setTimeout(()=>{r(Pd(a)?"abort":"next",a)});return}return s=501,i.json()}).then(i=>{if(typeof i!="object"||i===null){setTimeout(()=>{i===404?r("abort",i):r("next",s)});return}setTimeout(()=>{r("success",i)})}).catch(()=>{r("next",s)})},_d={prepare:Fd,send:Od};function il(e,t){e.forEach(r=>{const o=r.loaderCallbacks;o&&(r.loaderCallbacks=o.filter(s=>s.id!==t))})}function Bd(e){e.pendingCallbacksFlag||(e.pendingCallbacksFlag=!0,setTimeout(()=>{e.pendingCallbacksFlag=!1;const t=e.loaderCallbacks?e.loaderCallbacks.slice(0):[];if(!t.length)return;let r=!1;const o=e.provider,s=e.prefix;t.forEach(i=>{const a=i.icons,c=a.pending.length;a.pending=a.pending.filter(d=>{if(d.prefix!==s)return!0;const u=d.name;if(e.icons[u])a.loaded.push({provider:o,prefix:s,name:u});else if(e.missing.has(u))a.missing.push({provider:o,prefix:s,name:u});else return r=!0,!0;return!1}),a.pending.length!==c&&(r||il([e],i.id),i.callback(a.loaded.slice(0),a.missing.slice(0),a.pending.slice(0),i.abort))})}))}let Hd=0;function $d(e,t,r){const o=Hd++,s=il.bind(null,r,o);if(!t.pending.length)return s;const i={id:o,icons:t,callback:e,abort:s};return r.forEach(a=>{(a.loaderCallbacks||(a.loaderCallbacks=[])).push(i)}),s}function Ud(e){const t={loaded:[],missing:[],pending:[]},r=Object.create(null);e.sort((s,i)=>s.provider!==i.provider?s.provider.localeCompare(i.provider):s.prefix!==i.prefix?s.prefix.localeCompare(i.prefix):s.name.localeCompare(i.name));let o={provider:"",prefix:"",name:""};return e.forEach(s=>{if(o.name===s.name&&o.prefix===s.prefix&&o.provider===s.provider)return;o=s;const i=s.provider,a=s.prefix,c=s.name,d=r[i]||(r[i]=Object.create(null)),u=d[a]||(d[a]=vr(i,a));let h;c in u.icons?h=t.loaded:a===""||u.missing.has(c)?h=t.missing:h=t.pending;const f={provider:i,prefix:a,name:c};h.push(f)}),t}function Yd(e,t=!0,r=!1){const o=[];return e.forEach(s=>{const i=typeof s=="string"?Do(s,t,r):s;i&&o.push(i)}),o}const Wd={resources:[],index:0,timeout:2e3,rotate:750,random:!1,dataAfterTimeout:!1};function Xd(e,t,r,o){const s=e.resources.length,i=e.random?Math.floor(Math.random()*s):e.index;let a;if(e.random){let S=e.resources.slice(0);for(a=[];S.length>1;){const R=Math.floor(Math.random()*S.length);a.push(S[R]),S=S.slice(0,R).concat(S.slice(R+1))}a=a.concat(S)}else a=e.resources.slice(i).concat(e.resources.slice(0,i));const c=Date.now();let d="pending",u=0,h,f=null,p=[],g=[];typeof o=="function"&&g.push(o);function b(){f&&(clearTimeout(f),f=null)}function x(){d==="pending"&&(d="aborted"),b(),p.forEach(S=>{S.status==="pending"&&(S.status="aborted")}),p=[]}function y(S,R){R&&(g=[]),typeof S=="function"&&g.push(S)}function v(){return{startTime:c,payload:t,status:d,queriesSent:u,queriesPending:p.length,subscribe:y,abort:x}}function w(){d="failed",g.forEach(S=>{S(void 0,h)})}function C(){p.forEach(S=>{S.status==="pending"&&(S.status="aborted")}),p=[]}function j(S,R,I){const D=R!=="success";switch(p=p.filter(E=>E!==S),d){case"pending":break;case"failed":if(D||!e.dataAfterTimeout)return;break;default:return}if(R==="abort"){h=I,w();return}if(D){h=I,p.length||(a.length?M():w());return}if(b(),C(),!e.random){const E=e.resources.indexOf(S.resource);E!==-1&&E!==e.index&&(e.index=E)}d="completed",g.forEach(E=>{E(I)})}function M(){if(d!=="pending")return;b();const S=a.shift();if(S===void 0){if(p.length){f=setTimeout(()=>{b(),d==="pending"&&(C(),w())},e.timeout);return}w();return}const R={status:"pending",resource:S,callback:(I,D)=>{j(R,I,D)}};p.push(R),u++,f=setTimeout(M,e.rotate),r(S,t,R.callback)}return setTimeout(M),v}function al(e){const t={...Wd,...e};let r=[];function o(){r=r.filter(c=>c().status==="pending")}function s(c,d,u){const h=Xd(t,c,d,(f,p)=>{o(),u&&u(f,p)});return r.push(h),h}function i(c){return r.find(d=>c(d))||null}return{query:s,find:i,setIndex:c=>{t.index=c},getIndex:()=>t.index,cleanup:o}}function Yi(){}const rs=Object.create(null);function Vd(e){if(!rs[e]){const t=ti(e);if(!t)return;const r=al(t),o={config:t,redundancy:r};rs[e]=o}return rs[e]}function Gd(e,t,r){let o,s;if(typeof e=="string"){const i=Is(e);if(!i)return r(void 0,424),Yi;s=i.send;const a=Vd(e);a&&(o=a.redundancy)}else{const i=Qs(e);if(i){o=al(i);const a=e.resources?e.resources[0]:"",c=Is(a);c&&(s=c.send)}}return!o||!s?(r(void 0,424),Yi):o.query(t,s,r)().abort}function Wi(){}function Kd(e){e.iconsLoaderFlag||(e.iconsLoaderFlag=!0,setTimeout(()=>{e.iconsLoaderFlag=!1,Bd(e)}))}function qd(e){const t=[],r=[];return e.forEach(o=>{(o.match(Za)?t:r).push(o)}),{valid:t,invalid:r}}function Mr(e,t,r){function o(){const s=e.pendingIcons;t.forEach(i=>{s&&s.delete(i),e.icons[i]||e.missing.add(i)})}if(r&&typeof r=="object")try{if(!qa(e,r).length){o();return}}catch(s){console.error(s)}o(),Kd(e)}function Xi(e,t){e instanceof Promise?e.then(r=>{t(r)}).catch(()=>{t(null)}):t(e)}function Zd(e,t){e.iconsToLoad?e.iconsToLoad=e.iconsToLoad.concat(t).sort():e.iconsToLoad=t,e.iconsQueueFlag||(e.iconsQueueFlag=!0,setTimeout(()=>{e.iconsQueueFlag=!1;const{provider:r,prefix:o}=e,s=e.iconsToLoad;if(delete e.iconsToLoad,!s||!s.length)return;const i=e.loadIcon;if(e.loadIcons&&(s.length>1||!i)){Xi(e.loadIcons(s,o,r),h=>{Mr(e,s,h)});return}if(i){s.forEach(h=>{const f=i(h,o,r);Xi(f,p=>{const g=p?{prefix:o,icons:{[h]:p}}:null;Mr(e,[h],g)})});return}const{valid:a,invalid:c}=qd(s);if(c.length&&Mr(e,c,null),!a.length)return;const d=o.match(Za)?Is(r):null;if(!d){Mr(e,a,null);return}d.prepare(r,o,a).forEach(h=>{Gd(r,h,f=>{Mr(e,h.icons,f)})})}))}const ll=(e,t)=>{const r=Yd(e,!0,Ja()),o=Ud(r);if(!o.pending.length){let d=!0;return t&&setTimeout(()=>{d&&t(o.loaded,o.missing,o.pending,Wi)}),()=>{d=!1}}const s=Object.create(null),i=[];let a,c;return o.pending.forEach(d=>{const{provider:u,prefix:h}=d;if(h===c&&u===a)return;a=u,c=h,i.push(vr(u,h));const f=s[u]||(s[u]=Object.create(null));f[h]||(f[h]=[])}),o.pending.forEach(d=>{const{provider:u,prefix:h,name:f}=d,p=vr(u,h),g=p.pendingIcons||(p.pendingIcons=new Set);g.has(f)||(g.add(f),s[u][h].push(f))}),i.forEach(d=>{const u=s[d.provider][d.prefix];u.length&&Zd(d,u)}),t?$d(t,o,i):Wi};function Jd(e,t){const r={...e};for(const o in t){const s=t[o],i=typeof s;o in tl?(s===null||s&&(i==="string"||i==="number"))&&(r[o]=s):i===typeof r[o]&&(r[o]=o==="rotate"?s%4:s)}return r}const Qd=/[\s,]+/;function eu(e,t){t.split(Qd).forEach(r=>{switch(r.trim()){case"horizontal":e.hFlip=!0;break;case"vertical":e.vFlip=!0;break}})}function tu(e,t=0){const r=e.replace(/^-?[0-9.]*/,"");function o(s){for(;s<0;)s+=4;return s%4}if(r===""){const s=parseInt(e);return isNaN(s)?0:o(s)}else if(r!==e){let s=0;switch(r){case"%":s=25;break;case"deg":s=90}if(s){let i=parseFloat(e.slice(0,e.length-r.length));return isNaN(i)?0:(i=i/s,i%1===0?o(i):0)}}return t}function nu(e,t){let r=e.indexOf("xlink:")===-1?"":' xmlns:xlink="http://www.w3.org/1999/xlink"';for(const o in t)r+=" "+o+'="'+t[o]+'"';return'<svg xmlns="http://www.w3.org/2000/svg"'+r+">"+e+"</svg>"}function ru(e){return e.replace(/"/g,"'").replace(/%/g,"%25").replace(/#/g,"%23").replace(/</g,"%3C").replace(/>/g,"%3E").replace(/\s+/g," ")}function ou(e){return"data:image/svg+xml,"+ru(e)}function su(e){return'url("'+ou(e)+'")'}let Pr;function iu(){try{Pr=window.trustedTypes.createPolicy("iconify",{createHTML:e=>e})}catch{Pr=null}}function au(e){return Pr===void 0&&iu(),Pr?Pr.createHTML(e):e}const cl={...nl,inline:!1},lu={xmlns:"http://www.w3.org/2000/svg",xmlnsXlink:"http://www.w3.org/1999/xlink","aria-hidden":!0,role:"img"},cu={display:"inline-block"},As={backgroundColor:"currentColor"},dl={backgroundColor:"transparent"},Vi={Image:"var(--svg)",Repeat:"no-repeat",Size:"100% 100%"},Gi={WebkitMask:As,mask:As,background:dl};for(const e in Gi){const t=Gi[e];for(const r in Vi)t[e+r]=Vi[r]}const du={...cl,inline:!0};function Ki(e){return e+(e.match(/^[-0-9.]+$/)?"px":"")}const uu=(e,t,r)=>{const o=t.inline?du:cl,s=Jd(o,t),i=t.mode||"svg",a={},c=t.style||{},d={...i==="svg"?lu:{}};if(r){const y=Do(r,!1,!0);if(y){const v=["iconify"],w=["provider","prefix"];for(const C of w)y[C]&&v.push("iconify--"+y[C]);d.className=v.join(" ")}}for(let y in t){const v=t[y];if(v!==void 0)switch(y){case"icon":case"style":case"children":case"onLoad":case"mode":case"ssr":case"fallback":break;case"_ref":d.ref=v;break;case"className":d[y]=(d[y]?d[y]+" ":"")+v;break;case"inline":case"hFlip":case"vFlip":s[y]=v===!0||v==="true"||v===1;break;case"flip":typeof v=="string"&&eu(s,v);break;case"color":a.color=v;break;case"rotate":typeof v=="string"?s[y]=tu(v):typeof v=="number"&&(s[y]=v);break;case"ariaHidden":case"aria-hidden":v!==!0&&v!=="true"&&delete d["aria-hidden"];break;default:o[y]===void 0&&(d[y]=v)}}const u=rl(e,s),h=u.attributes;if(s.inline&&(a.verticalAlign="-0.125em"),i==="svg"){d.style={...a,...c},Object.assign(d,h);let y=0,v=t.id;return typeof v=="string"&&(v=v.replace(/-/g,"_")),d.dangerouslySetInnerHTML={__html:au(ol(u.body,v?()=>v+"ID"+y++:"iconifyReact"))},l.createElement("svg",d)}const{body:f,width:p,height:g}=e,b=i==="mask"||(i==="bg"?!1:f.indexOf("currentColor")!==-1),x=nu(f,{...h,width:p+"",height:g+""});return d.style={...a,"--svg":su(x),width:Ki(h.width),height:Ki(h.height),...cu,...b?As:dl,...c},l.createElement("span",d)};Ja(!0);Ad("",_d);if(typeof document<"u"&&typeof window<"u"){const e=window;if(e.IconifyPreload!==void 0){const t=e.IconifyPreload,r="Invalid IconifyPreload syntax.";typeof t=="object"&&t!==null&&(t instanceof Array?t:[t]).forEach(o=>{try{(typeof o!="object"||o===null||o instanceof Array||typeof o.icons!="object"||typeof o.prefix!="string"||!el(o))&&console.error(r)}catch{console.error(r)}})}if(e.IconifyProviders!==void 0){const t=e.IconifyProviders;if(typeof t=="object"&&t!==null)for(let r in t){const o="IconifyProviders["+r+"] is invalid.";try{const s=t[r];if(typeof s!="object"||!s||s.resources===void 0)continue;sl(r,s)||console.error(o)}catch{console.error(o)}}}}function ul(e){const[t,r]=l.useState(!!e.ssr),[o,s]=l.useState({});function i(g){if(g){const b=e.icon;if(typeof b=="object")return{name:"",data:b};const x=$i(b);if(x)return{name:b,data:x}}return{name:""}}const[a,c]=l.useState(i(!!e.ssr));function d(){const g=o.callback;g&&(g(),s({}))}function u(g){if(JSON.stringify(a)!==JSON.stringify(g))return d(),c(g),!0}function h(){var g;const b=e.icon;if(typeof b=="object"){u({name:"",data:b});return}const x=$i(b);if(u({name:b,data:x}))if(x===void 0){const y=ll([b],h);s({callback:y})}else x&&((g=e.onLoad)===null||g===void 0||g.call(e,b))}l.useEffect(()=>(r(!0),d),[]),l.useEffect(()=>{t&&h()},[e.icon,t]);const{name:f,data:p}=a;return p?uu({...Js,...p},e,f):e.children?e.children:e.fallback?e.fallback:l.createElement("span",{})}const de=l.forwardRef((e,t)=>ul({...e,_ref:t}));l.forwardRef((e,t)=>ul({inline:!0,...e,_ref:t}));const hu=Object.freeze(Object.defineProperty({__proto__:null,Icon:de,addAPIProvider:sl,addCollection:el,addIcon:Qa,buildIcon:rl,calculateSize:Ns,loadIcons:ll,replaceIDs:ol},Symbol.toStringTag,{value:"Module"})),fu=T.createLogger("usePenTool");function pu({selectedElement:e}){const[t]=l.useState(()=>new gd),[r,o]=l.useState("crosshair");return l.useEffect(()=>{try{const s=Kc.renderToStaticMarkup(n.jsx(de,{icon:"lucide:pen-tool",width:24,height:24})).replace(/<svg[^>]*>|<\/svg>/g,""),i=`
2
2
  <svg width="24" height="24" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
3
3
  <!-- White background stroke (thicker) -->
4
4
  <g stroke="white" stroke-width="4" fill="none" stroke-linejoin="round" stroke-linecap="round">
@@ -9,12 +9,12 @@
9
9
  ${s}
10
10
  </g>
11
11
  </svg>
12
- `.trim(),c=`data:image/svg+xml,${encodeURIComponent(i)}`;o(`url('${c}') 0 0, crosshair`)}catch(s){uu.error("Failed to create pen cursor:",s),o("crosshair")}},[]),l.useEffect(()=>{e instanceof T.PathElement&&e.transformData.points.length===0&&!t.isActive()&&t.startPath(e)},[e,t]),{penTool:t,penCursor:r}}function fu({elements:e,selectedElement:t,transformHandles:r,onActiveChildChange:o}){const[s,i]=l.useState(null),a=l.useRef(null),c=l.useCallback(d=>{i(d),o==null||o(d)},[o]);return l.useEffect(()=>{if(s&&t instanceof T.GroupElement){const d=t.children.find(u=>u.id===s.id);d&&d!==s&&(d instanceof T.GroupElement||(i(d),o==null||o(d),r.update(d)))}},[e,s,t,r,o]),{activeChildElement:s,setActiveChildElement:i,updateActiveChild:c,editingChildIdRef:a}}function pu({onHoverChange:e}){const[t,r]=l.useState({type:null,data:null,startTime:null}),o=l.useCallback(s=>{r(i=>{var c,d,u,h;const a=s.type!==i.type||s.type==="element"&&((c=s.data)==null?void 0:c.id)!==((d=i.data)==null?void 0:d.id)||s.type==="group-sibling"&&((u=s.data)==null?void 0:u.id)!==((h=i.data)==null?void 0:h.id);return{...s,startTime:a&&s.type!==null?performance.now():i.startTime}})},[]);return l.useEffect(()=>{if(!e)return;let s=null;if(t.type==="element"||t.type==="group-sibling"){const i=t.data;s=(i==null?void 0:i.id)??null}e(s)},[t,e]),{hoverState:t,setHoverState:o}}class ei{constructor(t,r,o,s,i){this.x=t,this.y=r,this.rotation=o,this.flipH=s,this.flipV=i}worldToLocal(t,r){const o=t-this.x,s=r-this.y,i=T.RotationUtils.toRadiansInverse(this.rotation),a=Math.cos(i),c=Math.sin(i);let d=o*a+s*c,u=-o*c+s*a;return this.flipH&&(d=-d),this.flipV&&(u=-u),{x:d,y:u}}localToWorld(t,r){let o=this.flipH?-t:t,s=this.flipV?-r:r;const i=T.RotationUtils.toRadians(this.rotation),a=Math.cos(i),c=Math.sin(i),d=o*a-s*c,u=o*c+s*a;return{x:d+this.x,y:u+this.y}}transformVector(t,r,o=!1){let s=this.flipH?-t:t,i=this.flipV?-r:r;const a=o?T.RotationUtils.toRadiansInverse(this.rotation):T.RotationUtils.toRadians(this.rotation),c=Math.cos(a),d=Math.sin(a);return o?{dx:s*c+i*d,dy:-s*d+i*c}:{dx:s*c-i*d,dy:s*d+i*c}}static fromElement(t){return new ei(t.x,t.y,t.rotation||0,t.flipH||!1,t.flipV||!1)}}class mu{handleCropImageDrag(t,r,o,s){const i=o-r.startX,a=s-r.startY,c=r.startData.x,d=r.startData.y,u=r.startData.transformData,h=u.width,f=u.height,p=r.startData.cropX??0,g=r.startData.cropY??0,b=r.startData.cropWidth??1,x=r.startData.cropHeight??1,v=T.Transform.fromSnapshot(r.startData).worldDeltaToLocal(i,a);let w=v.dx,C=v.dy;const j=u.flipHorizontal?-1:1,M=u.flipVertical?-1:1;w*=j,C*=M;const S=-w/h,R=-C/f;let I=p+S,D=g+R;const E=1-b,O=1-x;return I=Math.max(0,Math.min(E,I)),D=Math.max(0,Math.min(O,D)),{cropX:I,cropY:D,cropWidth:b,cropHeight:x,x:c,y:d}}handleCropBoxResize(t,r,o,s,i,a){const c=o.startData.transformData,d=c.flipHorizontal,u=c.flipVertical,h=this._getCropResizeCursor(r,!!d,!!u),f=o.startData.rotation,p=o.startData.x,g=o.startData.y,b=T.Transform.fromSnapshot(o.startData),{cos:x,sin:y}=b.getInverseCosSin(),v=d?-1:1,w=u?-1:1,C=i-p,j=a-g;let M=C*x-j*y,S=C*y+j*x;M*=v,S*=w;const R=s.startX-p,I=s.startY-g;let D=R*x-I*y,E=R*y+I*x;D*=v,E*=w;const O=M-D,z=S-E,_=c.cropX,k=c.cropY,Y=c.cropWidth,B=c.cropHeight,G=c.width,se=c.height,A=O/G,Z=z/se,J=this._calculateNewCropValues(r,_,k,Y,B,A,Z),q=this._calculateCropCenterOffset(_,k,Y,B,J.cropX,J.cropY,J.cropWidth,J.cropHeight,G,se,f,v,w);return{...J,x:p+q.worldOffsetX,y:g+q.worldOffsetY,rotation:f,width:G,height:se,cursor:h}}_getCropResizeCursor(t,r,o){let s=t;return r&&(s.includes("left")?s=s.replace("left","right"):s.includes("right")&&(s=s.replace("right","left"))),o&&(s.includes("top")?s=s.replace("top","bottom"):s.includes("bottom")&&(s=s.replace("bottom","top"))),s==="top-left"||s==="bottom-right"?"nwse-resize":s==="top-right"||s==="bottom-left"?"nesw-resize":s==="top"||s==="bottom"?"ns-resize":s==="left"||s==="right"?"ew-resize":"default"}_calculateNewCropValues(t,r,o,s,i,a,c){const d=T.MIN_CROP_SIZE;let u=r,h=o,f=s,p=i;return t==="top-left"?(u=r+a,h=o+c,f=s-a,p=i-c):t==="top-right"?(h=o+c,f=s+a,p=i-c):t==="bottom-left"?(u=r+a,f=s-a,p=i+c):t==="bottom-right"?(f=s+a,p=i+c):t==="top"?(h=o+c,p=i-c):t==="bottom"?p=i+c:t==="left"?(u=r+a,f=s-a):t==="right"&&(f=s+a),this._constrainCropValues(t,u,h,f,p,r,o,s,i,d)}_constrainCropValues(t,r,o,s,i,a,c,d,u,h){let f=r,p=o,g=s,b=i;return g<h&&(g=h,t.includes("left")&&(f=a+d-h)),f+g>1&&(t.includes("left")?f=1-g:g=1-f),f<0&&(g=g+f,f=0),b<h&&(b=h,t.includes("top")&&(p=c+u-h)),p+b>1&&(t.includes("top")?p=1-b:b=1-p),p<0&&(b=b+p,p=0),{cropX:f,cropY:p,cropWidth:g,cropHeight:b}}_calculateCropCenterOffset(t,r,o,s,i,a,c,d,u,h,f,p,g){const b=t*u+o*u/2,x=r*h+s*h/2,y=i*u+c*u/2,v=a*h+d*h/2;let w=y-b,C=v-x;w*=p,C*=g;const M=new T.Transform({rotation:f,x:0,y:0}).localDeltaToWorld(w,C),S=M.dx,R=M.dy;return{worldOffsetX:S,worldOffsetY:R}}getCropBoxHandlePosition(t,r){const o=ei.fromElement(t),s=t.transformData,i=s.width,a=s.height,c=s.cropX||0,d=s.cropY||0,u=s.cropWidth||1,h=s.cropHeight||1;let f=0,p=0;return r.includes("left")?f=(c-.5)*i:r.includes("right")?f=(c+u-.5)*i:f=(c+u/2-.5)*i,r.includes("top")?p=(d-.5)*a:r.includes("bottom")?p=(d+h-.5)*a:p=(d+h/2-.5)*a,o.localToWorld(f,p)}}function gu(){const[e]=l.useState(()=>new mu);return{cropController:e}}function xu(e){const t=l.useRef(null),r=l.useRef(null);return l.useEffect(()=>{r.current=null},[e]),{multiSelectionGroupBoundsRef:t,multiSelectionOBBRef:r}}function qi(e){return e!=null&&e instanceof T.TextElement}function bu({selectedElement:e,ref:t}){const[r,o]=l.useState(!1),[s,i]=l.useState(""),[a,c]=l.useState({x:0,y:0,width:200,height:50}),[d,u]=l.useState(0),[h,f]=l.useState(0),[p,g]=l.useState(0),b=l.useRef(1),x=l.useRef(performance.now()),y=l.useRef(0),v=l.useRef(!1),[w,C]=l.useState(null),[j,M]=l.useState(null),S=l.useRef(null),R=l.useCallback(E=>{if(!r||!w)return;const O=Math.min(h,p),z=Math.max(h,p);if(O===z){const _=w.clone(),k=_.getText().length;_.applyStyle(0,k,E),S.current=_,C(_),i(_.getText()),M(Y=>({...Y,...E}))}else{const _=w.clone();_.applyStyle(O,z,E),S.current=_,C(_),i(_.getText()),M(k=>({...k,...E}))}},[r,w,h,p]),I=l.useCallback(()=>{if(!r||!w||!e)return null;const E=Math.min(h,p),O=Math.max(h,p);return E===O?E===0?qi(e)?e.getDefaultStyle():{}:w.getStyleAt(Math.max(0,E-1)):w.getStyleAt(E)},[r,w,h,p,e]),D=l.useCallback(E=>{if(!r||!w||!e)return;const O=I(),k=!{...qi(e)?e.getDefaultStyle():{},...O}[E];R({[E]:k})},[r,w,e,I,R]);return l.useImperativeHandle(t,()=>({applyTextFormatting:E=>{R(E)},toggleFormattingProperty:E=>{D(E)},isEditingText:()=>r,getSelectionStyle:()=>I()}),[R,D,r,I]),{isEditing:r,setIsEditing:o,editText:s,setEditText:i,editPosition:a,setEditPosition:c,cursorPosition:d,setCursorPosition:u,selectionStart:h,setSelectionStart:f,selectionEnd:p,setSelectionEnd:g,cursorOpacityRef:b,cursorStartTimeRef:x,selectionAnchorRef:y,didDragSelectRef:v,editRichText:w,setEditRichText:C,editRichTextRef:S,currentFormattingStyle:j,setCurrentFormattingStyle:M,applyFormattingToSelection:R,getSelectionStyle:I,toggleFormattingProperty:D}}function yu({width:e,height:t,zoom:r,viewPadding:o,artboardBorderRadius:s,fixedMargin:i,fixedMarginX:a,fixedMarginY:c,artboards:d,artboardManager:u,focusedPieceRect:h}){const[f,p]=l.useState(!1);l.useEffect(()=>{const z="ontouchstart"in window||navigator.maxTouchPoints>0;p(z)},[]);const g=l.useRef(null);l.useEffect(()=>{const z=_=>{g.current=_.target,setTimeout(()=>{g.current=null},500)};return document.addEventListener("touchstart",z,{capture:!0,passive:!0}),document.addEventListener("pointerdown",z,{capture:!0,passive:!0}),()=>{document.removeEventListener("touchstart",z,{capture:!0}),document.removeEventListener("pointerdown",z,{capture:!0})}},[]);const[b,x]=l.useState({width:e??window.innerWidth,height:t??window.innerHeight});l.useEffect(()=>{if(h){x({width:h.width,height:h.height});return}if(e!==void 0&&t!==void 0){x({width:e,height:t});return}const z=u.getActiveArtboard();z&&x({width:z.width,height:z.height})},[e,t,d,u,h]),l.useEffect(()=>{const z=()=>{if(h){x({width:h.width,height:h.height});return}if(e===void 0&&t===void 0){const _=u.getActiveArtboard();x(_?{width:_.width,height:_.height}:{width:window.innerWidth,height:window.innerHeight})}};return window.addEventListener("resize",z),()=>window.removeEventListener("resize",z)},[e,t,u,h]);const y=Math.max(.1,Math.min(1,o)),v=a??i,w=c??i,C=v!==void 0&&r>0?v/r:0,j=w!==void 0&&r>0?w/r:0,M=v!==void 0?b.width+C*2:b.width/y,S=w!==void 0?b.height+j*2:b.height/y,R=v!==void 0?C:(M-b.width)/2,I=w!==void 0?j:(S-b.height)/2,D=h?R-h.x:R,E=h?I-h.y:I,O=r>0?s/r:s;return{isTouchDevice:f,canvasSize:b,lastTouchTargetRef:g,effectiveViewPadding:y,paddedCanvasWidth:M,paddedCanvasHeight:S,paddingOffsetX:D,paddingOffsetY:E,zoomInvariantBorderRadius:O}}function vu(){const[e,t]=l.useState([]),[r,o]=l.useState([]),[s,i]=l.useState(!1),[a,c]=l.useState(!1),[d,u]=l.useState(0),[h,f]=l.useState(0),[,p]=l.useState(0);return{snapGuides:e,setSnapGuides:t,spacingIndicators:r,setSpacingIndicators:o,isAltKeyPressed:s,setIsAltKeyPressed:i,isRotating:a,setIsRotating:c,setRotationStartAngle:u,currentRotation:h,setCurrentRotation:f,setRotatingElementVersion:p}}function wu({elements:e}){const[,t]=l.useState({}),[r,o]=l.useState(0),[s,i]=l.useState(0),[a,c]=l.useState(0),d=l.useCallback(()=>{i(u=>u+1)},[]);return l.useEffect(()=>T.subscribeToImageLoads(h=>{e.some(p=>p.id===h)&&i(p=>p+1)}),[e]),{renderVersion:s,forceRender:d,handlesVersion:r,setHandlesVersion:o,forceUpdate:t,cursorAnimationFrame:a,setCursorAnimationFrame:c}}const Ir={bleedMode:"gradient",bleedInnerEdge:"boundary",bleedFill:"#000000",bleedOpacity:1,dieCutMode:"blur-tint",dieCutTint:"#333",dieCutTintAlpha:.7,dieCutBlurPx:4,dieCutStroke:"",dieCutStrokeWidthPx:1,bleedBlurScale:.04,boundaryStroke:"",boundaryStrokeWidthPx:1,safeAreaStroke:"",safeAreaStrokeWidthPx:1.5,safeAreaDashPx:[6,4],zoneFill:{wrap:"rgba(148, 163, 184, 0.25)",binding:"rgba(234, 88, 12, 0.20)",dieCut:"rgba(0, 0, 0, 0.7)",warning:"rgba(245, 158, 11, 0.25)",custom:"rgba(100, 100, 100, 0.15)"},zoneStroke:{wrap:"#64748b",binding:"#ea580c",dieCut:"#ffffff",warning:"#f59e0b",custom:"#6b7280"},labelColor:"#111827",labelFontSizePx:14,labelFontFamily:"ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif",labelHaloColor:"#ffffff"};let Zn=null;function Cu(e){const t=e.width,r=e.height;if(t<=0||r<=0)return null;Zn||(Zn=document.createElement("canvas")),Zn.width!==t&&(Zn.width=t),Zn.height!==r&&(Zn.height=r);const o=Zn.getContext("2d");return o?(o.setTransform(1,0,0,1,0,0),o.clearRect(0,0,t,r),o.drawImage(e,0,0),Zn):null}function rs(e,t){const r=e.trim();if(!r.startsWith("var("))return r;const o=r.slice(4,-1),[s,...i]=o.split(","),a=s.trim(),c=i.length>0?i.join(",").trim():"",d=t??document.documentElement;return getComputedStyle(d).getPropertyValue(a).trim()||c||"#333"}function Su(e){if(typeof document>"u")return!1;const t=document.documentElement;return!!(t.classList.contains("dark")||t.getAttribute("data-theme")==="dark")}function Zi(e){const t=il(e);return t!==null&&t<.5}function Ji(e){const t=il(e);return t!==null&&t>=.5}function il(e){const t=e.trim();if(t.startsWith("#")){const o=t.slice(1);let s,i,a;if(o.length===3)s=parseInt(o[0]+o[0],16),i=parseInt(o[1]+o[1],16),a=parseInt(o[2]+o[2],16);else if(o.length===6)s=parseInt(o.slice(0,2),16),i=parseInt(o.slice(2,4),16),a=parseInt(o.slice(4,6),16);else return null;return Number.isNaN(s)||Number.isNaN(i)||Number.isNaN(a)?null:Qi(s,i,a)}const r=t.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return r?Qi(Number(r[1]),Number(r[2]),Number(r[3])):null}function Qi(e,t,r){const o=s=>{const i=s/255;return i<=.03928?i/12.92:Math.pow((i+.055)/1.055,2.4)};return .2126*o(e)+.7152*o(t)+.0722*o(r)}function Zr(e,t){if(t.kind==="rect"){e.rect(t.x,t.y,t.width,t.height);return}if(t.kind==="roundedRect"){const o=t.rx??t.ry??0,s=t.ry??t.rx??0;if(o<=0&&s<=0){e.rect(t.x,t.y,t.width,t.height);return}o===s?e.roundRect(t.x,t.y,t.width,t.height,o):e.roundRect(t.x,t.y,t.width,t.height,[{x:o,y:s}]);return}const r=new Path2D(t.d);e.__pieceGuidePath2D=r}function Yr(e,t,r){if(t.kind==="path"){const o=new Path2D(t.d);e.fill(o);return}e.beginPath(),Zr(e,t),e.fill()}function Fr(e,t){if(t.kind==="path"){const r=new Path2D(t.d);e.stroke(r);return}e.beginPath(),Zr(e,t),e.stroke()}function ku(e,t){t.kind!=="path"&&Zr(e,t)}function ko(e,t){if(t.kind==="rect"){e.rect(t.x,t.y,t.width,t.height);return}if(t.kind==="roundedRect"){const r=t.rx??t.ry??0,o=t.ry??t.rx??0;if(r<=0&&o<=0){e.rect(t.x,t.y,t.width,t.height);return}r===o?e.roundRect(t.x,t.y,t.width,t.height,r):e.roundRect(t.x,t.y,t.width,t.height,[{x:r,y:o}]);return}e.addPath(new Path2D(t.d))}function ju(e,t,r){return(e==null?void 0:e.boundary)??{kind:"rect",x:0,y:0,width:t,height:r}}function Eu(e,t,r,o){if(e!=null&&e.safeArea)return e.safeArea;if(t.safeAreaInsetPx&&t.safeAreaInsetPx>0){const s=t.safeAreaInsetPx;return{kind:"rect",x:s,y:s,width:Math.max(0,r-s*2),height:Math.max(0,o-s*2)}}return null}function al(e){var v,w,C,j,M,S,R;const{ctx:t,pieces:r,pieceGuides:o,artboardOrigin:s,zoom:i}=e;if(!r.length)return;const a={bleed:((v=e.show)==null?void 0:v.bleed)??!0,zones:((w=e.show)==null?void 0:w.zones)??!0,boundary:((C=e.show)==null?void 0:C.boundary)??!0,safeArea:((j=e.show)==null?void 0:j.safeArea)??!0,labels:((M=e.show)==null?void 0:M.labels)??!0},c=t.canvas,d=c instanceof HTMLCanvasElement?c:null,u=Su(),f={...{...Ir,bleedFill:u?"#ffffff":"#000000"},...e.style};f.zoneFill={...Ir.zoneFill,...((S=e.style)==null?void 0:S.zoneFill)??{}},f.zoneStroke={...Ir.zoneStroke,...((R=e.style)==null?void 0:R.zoneStroke)??{}};let p=rs(f.bleedFill,d);const g=rs(f.dieCutTint,d);let b=rs(f.boundaryStroke,d);u&&Zi(p)?p="#ffffff":!u&&Ji(p)&&(p="#000000"),u&&Zi(b)?b="#ffffff":!u&&Ji(b)&&(b="#000000");const y=r.some(I=>{var D;return(((D=o==null?void 0:o[I.id])==null?void 0:D.zones)??[]).some(E=>E.kind==="dieCut")})&&d?Cu(d):null;t.save(),t.translate(s.x,s.y);for(const I of r){if(e.focusedPieceId!=null&&I.id!==e.focusedPieceId)continue;const D=o==null?void 0:o[I.id],E=(D==null?void 0:D.zones)??[],O=(D==null?void 0:D.labels)??[];t.save(),t.translate(I.x,I.y);const z=I.rotation??0;z===90?(t.translate(I.width,0),t.rotate(Math.PI/2)):z===180?(t.translate(I.width,I.height),t.rotate(Math.PI)):z===270&&(t.translate(0,I.height),t.rotate(3*Math.PI/2));const _=z===90||z===270,k=_?I.height:I.width,Y=_?I.width:I.height,B=ju(D,k,Y),G=Eu(D,I,k,Y),se=!0,A=Math.max(0,(D==null?void 0:D.outerRadius)??0),Z=A>0?{kind:"roundedRect",x:0,y:0,width:k,height:Y,rx:A,ry:A}:{kind:"rect",x:0,y:0,width:k,height:Y};if(A>0&&(t.save(),t.beginPath(),ku(t,Z),t.clip()),a.bleed&&f.bleedOpacity>0){const J=f.bleedInnerEdge==="safeArea"&&G?G:B;if(J){const q=u?"screen":"multiply",ae=f.bleedOpacity;f.bleedMode==="solid"?Ru(t,Z,J,p,ae,q):Tu(t,k,Y,Z,J,p,ae,f.bleedBlurScale,i,q)}}if(a.zones)for(const J of E)J.kind!=="dieCut"&&(t.save(),t.fillStyle=f.zoneFill[J.kind]??Ir.zoneFill[J.kind],Yr(t,J.path),t.strokeStyle=f.zoneStroke[J.kind]??Ir.zoneStroke[J.kind],T.setZoomInvariantStroke(t,1.5,J.kind==="wrap"?[4,3]:[]),Fr(t,J.path),t.setLineDash([]),t.restore());if(a.zones)for(const J of E)J.kind==="dieCut"&&(f.dieCutMode==="knockout"?Au(t,J,f.dieCutStroke,f.dieCutStrokeWidthPx,e.interacting===!0,se,y,f.dieCutBlurPx):Mu(t,J,y,g,f.dieCutTintAlpha,f.dieCutBlurPx,f.dieCutStroke,f.dieCutStrokeWidthPx));a.boundary&&b&&f.boundaryStrokeWidthPx>0&&(t.save(),t.strokeStyle=b,T.setZoomInvariantStroke(t,f.boundaryStrokeWidthPx),Fr(t,B),t.restore()),a.safeArea&&G&&f.safeAreaStroke&&(t.save(),t.strokeStyle=f.safeAreaStroke,T.setZoomInvariantStroke(t,f.safeAreaStrokeWidthPx,f.safeAreaDashPx),Fr(t,G),t.setLineDash([]),t.restore()),a.labels&&O.length>0&&Du(t,O,f,i),A>0&&t.restore(),t.restore()}t.restore()}function Tu(e,t,r,o,s,i,a,c,d,u="source-over"){const h=Math.max(6,Math.round(Math.min(t,r)*c)),f=d>0?h*d:h,p=typeof window<"u"&&window.devicePixelRatio||1,g=h,b=t+2*g,x=r+2*g,y=Math.max(1,Math.ceil(b*d*p)),v=Math.max(1,Math.ceil(x*d*p)),w=Nu(y,v);if(!w)return;const C=w.getContext("2d");if(!C)return;C.setTransform(1,0,0,1,0,0),C.clearRect(0,0,y,v),C.scale(d*p,d*p),C.translate(g,g),C.fillStyle=i,C.globalAlpha=a;const j=new Path2D;ko(j,o),C.fill(j),C.globalAlpha=1,C.filter=`blur(${f*p}px)`,C.globalCompositeOperation="destination-out",C.fillStyle="#000";const M=new Path2D;ko(M,s),C.fill(M),C.filter="none",C.globalCompositeOperation="source-over";const S=e.globalCompositeOperation;e.globalCompositeOperation=u,e.drawImage(w,-g,-g,b,x),e.globalCompositeOperation=S}function Ru(e,t,r,o,s,i="source-over"){e.save(),e.globalAlpha=e.globalAlpha*s,e.globalCompositeOperation=i,e.fillStyle=o;const a=new Path2D;ko(a,t),ko(a,r),e.fill(a,"evenodd"),e.restore()}let or=null;function Nu(e,t){return typeof document>"u"?null:(or||(or=document.createElement("canvas")),or.width!==e&&(or.width=e),or.height!==t&&(or.height=t),or)}function Mu(e,t,r,o,s,i,a,c){const d=t.path;if(e.save(),e.beginPath(),Zr(e,d),e.clip(),r&&(e.save(),e.globalCompositeOperation="destination-out",e.fillStyle="#000",d.kind==="path"?Yr(e,d):e.fillRect(d.x,d.y,d.width,d.height),e.restore(),i>0)){const u=e.globalAlpha,h=e.getTransform();e.save(),e.setTransform(1,0,0,1,0,0),e.filter=`blur(${i}px)`,e.globalAlpha=u*.4,e.drawImage(r,0,0),e.filter="none",e.globalAlpha=u,e.setTransform(h),e.restore()}if(s>0){const u=e.globalAlpha;e.fillStyle=o,e.globalAlpha=u*s,d.kind==="path"?Yr(e,d):e.fillRect(d.x,d.y,d.width,d.height),e.globalAlpha=u}e.restore(),a&&(e.save(),e.strokeStyle=a,T.setZoomInvariantStroke(e,c),Fr(e,d),e.restore())}const Iu=.3;function Au(e,t,r,o,s,i=!0,a,c=0){const d=t.path;if(i)if(s&&a&&c>0){e.save(),e.beginPath(),Zr(e,d),e.clip(),e.save(),e.globalCompositeOperation="destination-out",e.fillStyle="#000",d.kind==="path"||d.kind==="roundedRect"?Yr(e,d):e.fillRect(d.x,d.y,d.width,d.height),e.restore();const u=e.globalAlpha,h=e.getTransform();e.save(),e.setTransform(1,0,0,1,0,0),e.filter=`blur(${c}px)`,e.globalAlpha=u*.4,e.drawImage(a,0,0),e.filter="none",e.globalAlpha=u,e.setTransform(h),e.restore(),e.restore()}else e.save(),e.globalCompositeOperation="destination-out",e.globalAlpha=s?1-Iu:1,e.fillStyle="#000",d.kind==="path"||d.kind==="roundedRect"?Yr(e,d):e.fillRect(d.x,d.y,d.width,d.height),e.restore();r&&(e.save(),e.strokeStyle=r,T.setZoomInvariantStroke(e,o),Fr(e,d),e.restore())}function Du(e,t,r,o){const s=o>0?r.labelFontSizePx/o:r.labelFontSizePx,i=Math.max(2,r.labelFontSizePx*.25),a=o>0?i/o:i;e.save(),e.font=`${s}px ${r.labelFontFamily}`;for(const c of t){const d=c.anchor??"c";e.textAlign=Lu(d),e.textBaseline=Pu(d),e.lineJoin="round",e.strokeStyle=r.labelHaloColor,e.lineWidth=a,e.strokeText(c.text,c.x,c.y),e.fillStyle=r.labelColor,e.fillText(c.text,c.x,c.y)}e.restore()}function Lu(e){return e.endsWith("l")?"start":e.endsWith("r")?"end":"center"}function Pu(e){return e.startsWith("t")?"hanging":e.startsWith("b")?"alphabetic":"middle"}function Fu(e){const{ctx:t,displaySelection:r,elements:o,activeArtboardElementIds:s,stateMachine:i,multiSelectionOBB:a,isRotating:c,currentRotation:d,isMarqueeSelecting:u,zoom:h=1}=e,f=r.filter(q=>s.has(q));if(f.length===0)return{updatedOBB:null,groupBounds:null};const p=i._multiSelectionDragContext,g=i.getMode()==="drag"&&p;f.forEach(q=>{let ae=o.find(Le=>Le.id===q);if(g&&p.currentElements){const Le=p.currentElements.get(q);Le&&(ae=Le)}if(ae){const Le=ae.getVisualBoundingBox(),pe=ae.getRotationAnchor();t.save(),ae.rotation!==0&&(t.translate(pe.x,pe.y),t.rotate(-ae.rotation*Math.PI/180),t.translate(-pe.x,-pe.y)),t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=rt.getLineWidth(h),t.strokeRect(Le.x,Le.y,Le.width,Le.height),t.restore()}});let b=f.map(q=>o.find(ae=>ae.id===q)).filter(q=>q!==void 0);if(g&&p.currentElements&&(b=b.map(q=>p.currentElements.get(q.id)||q)),b.length===0)return{updatedOBB:null,groupBounds:null};let x=1/0,y=1/0,v=-1/0,w=-1/0;b.forEach(q=>{const ae=q.getVisualBoundingBox(),Le=[{x:ae.x,y:ae.y},{x:ae.x+ae.width,y:ae.y},{x:ae.x,y:ae.y+ae.height},{x:ae.x+ae.width,y:ae.y+ae.height}];if(q.rotation!==0){const pe=q.getRotationAnchor(),U=-q.rotation*Math.PI/180,W=Math.cos(U),Ie=Math.sin(U);Le.forEach(ke=>{const Ke=ke.x-pe.x,re=ke.y-pe.y;ke.x=pe.x+(Ke*W-re*Ie),ke.y=pe.y+(Ke*Ie+re*W)})}Le.forEach(pe=>{x=Math.min(x,pe.x),y=Math.min(y,pe.y),v=Math.max(v,pe.x),w=Math.max(w,pe.y)})});const C=v-x,j=w-y,M=(x+v)/2,S=(y+w)/2;let R=a;if((!R||R.width===0||R.height===0)&&(R={centerX:M,centerY:S,width:C,height:j,rotation:0}),i.getMode()==="drag"&&i._multiSelectionDragContext){const q=i._multiSelectionDragContext;if(q!=null&&q.startOBB&&(q!=null&&q.currentDelta)){const{dx:ae,dy:Le}=q.currentDelta;R={...R,centerX:q.startOBB.centerX+ae,centerY:q.startOBB.centerY+Le}}else R={...R,centerX:M,centerY:S}}const E=c&&i.getMode()==="rotate"?R.rotation+d:R.rotation,O=R.width,z=R.height,_=R.centerX,k=R.centerY,Y=_-O/2,B=k-z/2,G=_+O/2,se=k+z/2;let A=_,Z=se+T.ROTATION_HANDLE_DISTANCE;if(E!==0){const q=-E*Math.PI/180,ae=Math.cos(q),Le=Math.sin(q),pe=A-_,U=Z-k;A=_+(pe*ae-U*Le),Z=k+(pe*Le+U*ae)}const J={minX:Y,minY:B,maxX:G,maxY:se,centerX:_,centerY:k,rotationHandleX:A,rotationHandleY:Z,rotation:E};return t.save(),t.translate(_,k),t.rotate(-E*Math.PI/180),t.translate(-_,-k),t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=rt.getLineWidth(h),t.setLineDash(rt.getDashPattern(h)),t.strokeRect(Y,B,O,z),t.restore(),u||zu(t,{renderMinX:Y,renderMinY:B,renderMaxX:G,renderMaxY:se,renderCenterX:_,renderCenterY:k,renderWidth:O,renderHeight:z,groupRotation:E,rotationHandleX:A,rotationHandleY:Z,stateMachine:i,zoom:h}),{updatedOBB:R,groupBounds:J}}function zu(e,t){var C;const{renderMinX:r,renderMinY:o,renderMaxX:s,renderMaxY:i,renderCenterX:a,renderCenterY:c,renderWidth:d,renderHeight:u,groupRotation:h,rotationHandleX:f,rotationHandleY:p,stateMachine:g,zoom:b}=t,x=rt.getHandleRadius(b),y=[{x:r,y:o,anchor:"top-left"},{x:s,y:o,anchor:"top-right"},{x:r,y:i,anchor:"bottom-left"},{x:s,y:i,anchor:"bottom-right"}],v=g.getMode()==="resize",w=v?(C=g._multiSelectionResizeContext)==null?void 0:C.anchor:null;y.forEach(j=>{if(v&&w&&j.anchor!==w)return;let M=j.x,S=j.y;if(h!==0){const R=-h*Math.PI/180,I=Math.cos(R),D=Math.sin(R),E=j.x-a,O=j.y-c;M=a+(E*I-O*D),S=c+(E*D+O*I)}e.save(),e.beginPath(),e.arc(M,S,x,0,Math.PI*2),e.fillStyle="#fff",e.fill(),e.strokeStyle=T.getThemeAccentColor(),e.lineWidth=v&&w&&j.anchor===w?rt.getLineWidth(b)*1.25:rt.getLineWidth(b),e.stroke(),e.restore()}),v||rt.renderRotationHandle(e,f,p,b,T.getThemeAccentColor()),g.getMode()==="resize"&&Ou(e,a,i,d,u)}function Ou(e,t,r,o,s){const i=`${Math.round(o)} × ${Math.round(s)}`,a=t,c=r+30;e.save(),e.font="10px system-ui, -apple-system, sans-serif";const u=e.measureText(i).width+12,h=18;e.shadowColor="rgba(0,0,0,0.2)",e.shadowBlur=4,e.shadowOffsetY=1,e.fillStyle="#333",e.beginPath(),e.roundRect(a-u/2,c-h/2,u,h,3),e.fill(),e.shadowColor="transparent",e.shadowBlur=0,e.shadowOffsetY=0,e.fillStyle="#fff",e.textAlign="center",e.textBaseline="middle",e.fillText(i,a,c+.5),e.restore()}function Bu(e){const{ctx:t,marqueeStart:r,marqueeEnd:o,zoom:s=1}=e,i=Math.min(r.x,o.x),a=Math.max(r.x,o.x),c=Math.min(r.y,o.y),d=Math.max(r.y,o.y);t.save(),t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=rt.getLineWidth(s),t.strokeRect(i,c,a-i,d-c),t.fillStyle=T.getThemeAccentColorWithAlpha(.1),t.fillRect(i,c,a-i,d-c),t.restore()}function _u(e){const{ctx:t,hoveredChild:r,zoom:o=1}=e,s=r.getVisualBoundingBox();t.save(),t.translate(s.x+s.width/2,s.y+s.height/2),t.rotate(-r.rotation*Math.PI/180),t.translate(-(s.x+s.width/2),-(s.y+s.height/2)),t.strokeStyle=T.getThemeHoverBorderColor(),t.lineWidth=rt.getLineWidth(o),t.setLineDash([]),t.strokeRect(s.x,s.y,s.width,s.height),t.restore()}const Hu=60;class xr{constructor(){this.frameTimes=[],this.metrics={frameTime:0,frameCount:0,elementCount:0,cacheHitRate:0,lastExportDuration:0}}static getInstance(){return xr.instance||(xr.instance=new xr),xr.instance}recordFrameTime(t){this.frameTimes.push(t),this.frameTimes.length>Hu&&this.frameTimes.shift(),this.metrics.frameCount++,this.metrics.frameTime=this._average(this.frameTimes)}recordExportDuration(t){this.metrics.lastExportDuration=t}setElementCount(t){this.metrics.elementCount=t}setCacheHitRate(t){this.metrics.cacheHitRate=t}getMetrics(){return{...this.metrics}}reset(){this.frameTimes=[],this.metrics={frameTime:0,frameCount:0,elementCount:0,cacheHitRate:0,lastExportDuration:0}}_average(t){if(t.length===0)return 0;let r=0;for(let o=0;o<t.length;o++)r+=t[o];return r/t.length}}function $u(e,t,r){if(e.length===0||!e.every(a=>{var d;const c=(d=t==null?void 0:t[a.id])==null?void 0:d.boundary;return c&&typeof c=="object"&&c.kind==="path"&&typeof c.d=="string"}))return;const s=r?e.filter(a=>a.id===r):e;return{type:"composite-path",pieces:(s.length>0?s:e).map(a=>{var h;const c=(h=t==null?void 0:t[a.id])==null?void 0:h.boundary,d=(a.rotation??0)%360,u=d===90||d===270;return{d:c.d,x:a.x,y:a.y,rotation:d,baseWidth:u?a.height:a.width,baseHeight:u?a.width:a.height}})}}function Uu(e){const t=l.useRef(e);t.current=e;const r=l.useRef(!0),o=l.useRef(null),s=l.useRef("#0a0a0a");l.useEffect(()=>{const i=t.current.canvasRef.current??document.documentElement,a=getComputedStyle(i).getPropertyValue("--color-canvas-bg").trim();s.current=a||"#0a0a0a"},[e.resolvedTheme]),l.useEffect(()=>{r.current=!0},[e.elementsByArtboard,e.artboards,e.selectedId,e.selectedElement,e.activeChildElement,e.canvasSize,e.zoom,e.renderVersion,e.resolvedTheme,e.pieceGuides]),l.useEffect(()=>{r.current=!0},[e.transformHandles,e.currentRotation,e.isRotating,e.hoverState,e.isEditing,e.editText,e.editRichText,e.cursorPosition,e.selectionStart,e.selectionEnd,e.stateMachine,e.snapGuides,e.spacingIndicators,e.handlesVersion,e.multiSelection,e.isMarqueeSelecting,e.marqueeStart,e.marqueeEnd,e.marqueePreviewSelection,e.isAltKeyPressed,e.penTool,e.cursorAnimationFrame]),l.useEffect(()=>{let i;const c=()=>{const{hoverState:d}=t.current;if(d.startTime!==null&&d.type!==null&&performance.now()-d.startTime<150&&(r.current=!0),r.current){r.current=!1;const u=performance.now();Yu(t.current,s,o),xr.getInstance().recordFrameTime(performance.now()-u)}i=requestAnimationFrame(c)};return i=requestAnimationFrame(c),()=>cancelAnimationFrame(i)},[])}function Yu(e,t,r){var $t,Ot,De;const{canvasRef:o,elements:s,elementsByArtboard:i,artboards:a,artboardManager:c,artboardRenderer:d,selectedId:u,selectedElement:h,activeChildElement:f,editingChildIdRef:p,transformHandles:g,stateMachine:b,paddedCanvasWidth:x,paddedCanvasHeight:y,paddingOffsetX:v,paddingOffsetY:w,zoom:C,zoomInvariantBorderRadius:j,effectiveViewPadding:M,showRotationHandle:S,isRotating:R,currentRotation:I,hoverState:D,isEditing:E,editText:O,editRichText:z,cursorPosition:_,selectionStart:k,selectionEnd:Y,cursorOpacityRef:B,cursorStartTimeRef:G,isTouchDevice:se,selectionHandlePositionsRef:A,multiClickSelectionRef:Z,lastMultiClickTimeRef:J,MULTI_CLICK_DEBOUNCE:q,snapGuides:ae,spacingIndicators:Le,isAltKeyPressed:pe,multiSelection:U,multiSelectionOBBRef:W,multiSelectionGroupBoundsRef:Ie,isMarqueeSelecting:ke,marqueeStart:Ke,marqueeEnd:re,marqueePreviewSelection:te,penTool:he,hideHandles:ye,pieceGuides:we}=e,Pe=o.current;if(!Pe)return;const me=Pe.getContext("2d");if(!me)return;if(E){const Ee=Ue=>Ue<.5?4*Ue*Ue*Ue:1-Math.pow(-2*Ue+2,3)/2,Qe=(performance.now()-G.current)%1060/1060,Fe=Qe<.5?1-Ee(Qe*2):Ee((Qe-.5)*2);B.current=Fe}else B.current=1;const N=window.devicePixelRatio||1,ce=x*C,le=y*C;if(ce<=0||le<=0)return;const Me=4096,ge=ce*N,L=le*N,ve=Math.max(ge,L),tt=ve>Me?Me/ve:1,Ve=N*tt;Pe.width=ce*Ve,Pe.height=le*Ve,me.setTransform(1,0,0,1,0,0),me.clearRect(0,0,Pe.width,Pe.height);const oe=t.current;me.scale(Ve,Ve),C!==1&&me.scale(C,C),(v!==0||w!==0)&&me.translate(v,w);const ie=a.find(je=>je.id===c.getActiveArtboardId()),pt=(ie==null?void 0:ie.id)??null,st=we&&ie?$u(we.pieces,we.guides,e.focusedPieceId??null):void 0;let ht=we?0:j;if(we&&we.pieces.length===1&&ie){const je=we.pieces[0].id,$e=($t=we.guides)==null?void 0:$t[je],Qe=$e==null?void 0:$e.outerRadius,Fe=$e==null?void 0:$e.boundary,Ue=Fe&&typeof Fe=="object"&&Fe.kind==="roundedRect"?Fe.rx??Fe.ry:void 0,Xe=typeof Qe=="number"&&Qe>0?Qe:typeof Ue=="number"&&Ue>0?Ue:0;Xe>0&&(ht=Xe)}if(ie&&!we)if(me.fillStyle=oe,st&&typeof st=="object"&&st.type==="path")try{const je=new Path2D(st.d);me.save(),me.translate(ie.x,ie.y),me.fill(je),me.restore()}catch{me.fillRect(ie.x,ie.y,ie.width,ie.height)}else ht>0?(me.beginPath(),me.roundRect(ie.x,ie.y,ie.width,ie.height,ht),me.fill()):me.fillRect(ie.x,ie.y,ie.width,ie.height);ie&&!we&&d.render(me,ie,!0);let bt=f||h,yt=i.get(pt)||[];if(b.getMode()==="drag"&&h){const Ee=b.getContext()._cachedElement;Ee&&Ee[h.id]&&(yt=yt.map($e=>$e.id===h.id?Ee[h.id]:$e),f||(bt=Ee[h.id]))}if(E&&h){const je=p.current??null,Ee=r.current;if(!(Ee!==null&&Ee.elementId===h.id&&Ee.childId===je&&Ee.editRichText===z)){let Qe=null;if(je&&h instanceof T.GroupElement){const Fe=yt.find(Ue=>Ue.id===h.id&&Ue instanceof T.GroupElement);if(Fe){const Ue=Fe.clone();Ue.children=Ue.children.map(Xe=>{if(Xe.id===je&&z&&Xe instanceof T.TextElement){const dt=Xe.clone();return dt.setRichText(z),dt}return Xe}),Qe=Ue}}else if(z&&h instanceof T.TextElement){const Fe=h.clone();Fe.setRichText(z),Qe=Fe}Qe?r.current={elementId:h.id,childId:je,editRichText:z,clonedElement:Qe}:r.current=null}if(r.current){const{clonedElement:Qe}=r.current;yt=yt.map(Fe=>Fe.id===h.id?Qe:Fe)}}else r.current=null;const Tt=ye||he.isActive()&&h instanceof T.PathElement||E;if(rt.CanvasRenderer.render({ctx:me,elements:yt,selectedId:u,selectedElement:bt||null,transformHandles:g,currentRotation:I,isRotating:R,hoverState:D,isEditing:E,stateMachine:b,snapGuides:ae,spacingIndicators:Le,hideHandles:Tt,isAltKeyPressed:pe,artboardBackgroundColor:ie==null?void 0:ie.backgroundColor,distressTexture:ie==null?void 0:ie.distressTexture,imageMask:ie==null?void 0:ie.imageMask,artboard:ie?{x:ie.x,y:ie.y,width:ie.width,height:ie.height,borderRadius:ht,clipShape:st??ie.clipShape}:void 0,zoom:C,paddingOffset:{x:v,y:w},showOverflowDimmed:M<1,suppressOverflowDim:!1,showRotationHandle:S,editModeData:E?(()=>{const je=Z.current,Ee=Date.now()-J.current<q,$e=je&&Ee;return{cursorPosition:$e?je.cursor:_,selectionStart:$e?je.start:k,selectionEnd:$e?je.end:Y,editText:O,editRichText:z,cursorOpacity:B.current,isTouchDevice:se,selectionHandlePositionsRef:A}})():void 0}),we&&we.pieces.length>0&&ie){let je=!1;const Ee=bt??null;if(Ee&&we){const Fe=Ee.getVisualBoundingBox();e:for(const Ue of we.pieces){const Xe=((De=(Ot=we.guides)==null?void 0:Ot[Ue.id])==null?void 0:De.zones)??[];for(const dt of Xe){if(dt.kind!=="dieCut")continue;const Ye=dt.path;if(Ye.kind!=="rect"&&Ye.kind!=="roundedRect"){je=!0;break e}const vt=Ue.x+(Ye.x??0),gt=Ue.y+(Ye.y??0),Nt=Ye.width??0,Ft=Ye.height??0;if(Fe.x<vt+Nt&&Fe.x+Fe.width>vt&&Fe.y<gt+Ft&&Fe.y+Fe.height>gt){je=!0;break e}}}}const $e=je,Qe=ht>0&&ie!==void 0;if(Qe&&(me.save(),me.beginPath(),me.roundRect(ie.x,ie.y,ie.width,ie.height,ht),me.clip()),al({ctx:me,artboardOrigin:{x:ie.x,y:ie.y},artboardWidth:ie.width,artboardHeight:ie.height,pieces:we.pieces,pieceGuides:we.guides,show:we.show,style:we.style,zoom:C,interacting:$e,focusedPieceId:e.focusedPieceId??null}),Qe&&me.restore(),e.focusedPieceId&&we.pieces.length>1){const Fe=e.focusedPieceRect??we.pieces.find(Ue=>Ue.id===e.focusedPieceId)??null;if(Fe){me.save(),me.translate(ie.x,ie.y),me.globalCompositeOperation="destination-out";const Ue=!!h;me.globalAlpha=Ue?1-.3:1,me.fillStyle="#000",me.beginPath();const Xe=1e7;me.rect(-Xe,-Xe,2*Xe,2*Xe),me.rect(Fe.x,Fe.y,Fe.width,Fe.height),me.fill("evenodd"),me.restore()}}}ie&&rt.CanvasRenderer.renderInteractionChromeLayer({ctx:me,selectedElement:bt||null,transformHandles:g,stateMachine:b,currentRotation:I,isRotating:R,hoverState:D,selectedId:u,hideHandles:Tt,isEditing:E,isAltKeyPressed:pe,artboardBackgroundColor:ie.backgroundColor,hoverClipArtboard:{x:ie.x,y:ie.y,width:ie.width,height:ie.height,borderRadius:ht,clipShape:ie.clipShape},showRotationHandle:S,zoom:C,paddingOffset:{x:v,y:w}});const Rt=ke?te:U,jt=new Set(yt.map(je=>je.id)),{updatedOBB:kt,groupBounds:Kt}=Fu({ctx:me,displaySelection:Rt,elements:s,activeArtboardElementIds:jt,stateMachine:b,multiSelectionOBB:W.current,isRotating:R,currentRotation:I,isMarqueeSelecting:ke,zoom:C});kt&&W.current!==kt&&(W.current=kt),Ie.current=Kt,ke&&Bu({ctx:me,marqueeStart:Ke,marqueeEnd:re,zoom:C}),D.type==="group-sibling"&&D.data&&_u({ctx:me,hoveredChild:D.data,zoom:C}),he.isActive()&&h instanceof T.PathElement&&he.renderPreview(me,h)}class Wu{static calculatePinch({element:t,startData:r,scale:o,rotationDelta:s,startCentroid:i,currentCentroid:a,snapRotation:c}){const d=r.width??0,u=r.height??0,h=Math.max(1,d*o),f=Math.max(1,u*o);t.resize("bottom-right",h,f,r);const p=r.x-i.x,g=r.y-i.y,b=Math.cos(s),x=Math.sin(s),y=o*p,v=o*g;t.x=a.x+y*b-v*x,t.y=a.y+y*x+v*b;let w=r.rotation-s*180/Math.PI;return w=(w%360+360)%360,w>180&&(w-=360),c&&(w=c(w,t)),t.setRotation(w),t}}class Xu{constructor(){this.isProtectedFlag=!1,this.timeout=null,this.timeoutDuration=5e3}protectNextClick(){this.isProtectedFlag=!0,this.timeout&&clearTimeout(this.timeout),this.timeout=setTimeout(()=>{this.isProtectedFlag=!1,this.timeout=null},this.timeoutDuration)}shouldProtectClick(){const t=this.isProtectedFlag;return this.isProtectedFlag&&(this.isProtectedFlag=!1,this.timeout&&(clearTimeout(this.timeout),this.timeout=null)),t}clearProtection(){this.isProtectedFlag=!1,this.timeout&&(clearTimeout(this.timeout),this.timeout=null)}isProtected(){return this.isProtectedFlag}}const ti=new Xu;function Vu(e){const{x:t,y:r,bounds:o,zoom:s=1}=e,i=T.CORNER_HANDLE_HIT_RADIUS/s,a=o.rotation||0,d=[{x:o.minX,y:o.minY,anchor:"top-left"},{x:o.maxX,y:o.minY,anchor:"top-right"},{x:o.minX,y:o.maxY,anchor:"bottom-left"},{x:o.maxX,y:o.maxY,anchor:"bottom-right"}].map(g=>{if(a!==0){const b=-a*Math.PI/180,x=Math.cos(b),y=Math.sin(b),v=g.x-o.centerX,w=g.y-o.centerY;return{x:o.centerX+(v*x-w*y),y:o.centerY+(v*y+w*x),anchor:g.anchor}}return g});for(const g of d){const b=t-g.x,x=r-g.y;if(Math.sqrt(b*b+x*x)<=i)return{type:"corner-handle",anchor:g.anchor,corner:g}}const u=18/s;if(Math.sqrt(Math.pow(t-o.rotationHandleX,2)+Math.pow(r-o.rotationHandleY,2))<=u)return{type:"rotation-handle"};let f=t,p=r;if(a!==0){const g=a*Math.PI/180,b=Math.cos(g),x=Math.sin(g),y=t-o.centerX,v=r-o.centerY;f=o.centerX+(y*b-v*x),p=o.centerY+(y*x+v*b)}return f>=o.minX&&f<=o.maxX&&p>=o.minY&&p<=o.maxY?{type:"bounds-drag"}:{type:"none"}}function Gu(e){const{multiSelection:t,elements:r,bounds:o,anchor:s,corner:i,x:a,y:c,stateMachine:d}=e,u=t.map(h=>r.find(f=>f.id===h)).filter(h=>h!==void 0&&!h.locked);return u.length===0?!1:(d._multiSelectionResizeContext={anchor:s,startBounds:{...o},elementsStartData:u.map(h=>({element:h,startData:h.getTransformStartData()}))},d.startResize(u[0],{anchor:s,x:i.x,y:i.y,cursor:"nwse-resize",type:"corner"},a,c,{x:o.minX,y:o.minY,width:o.maxX-o.minX,height:o.maxY-o.minY},{x:o.minX,y:o.minY,width:o.maxX-o.minX,height:o.maxY-o.minY}),!0)}function Ku(e){const{multiSelection:t,elements:r,bounds:o,x:s,y:i,stateMachine:a,setIsRotating:c,setRotationStartAngle:d,setCurrentRotation:u}=e,h=t.map(p=>r.find(g=>g.id===p)).filter(p=>p!==void 0&&!p.locked);if(h.length===0)return!1;const f=T.calculateAngle(o.centerX,o.centerY,s,i);return a._multiSelectionRotationContext={startBounds:{...o},elementsStartData:h.map(p=>({element:p,startData:p.getTransformStartData()}))},c(!0),d(f),u(0),a.startRotate(h[0],s,i,f,0),!0}function qu(e){const{multiSelection:t,elements:r,x:o,y:s,stateMachine:i,dragOriginalElementsRef:a,setHoverState:c}=e,d=t.map(u=>r.find(h=>h.id===u)).filter(u=>u!==void 0&&!u.locked);return d.length===0?!1:(i._multiSelectionDragContext={startX:o,startY:s,elementsStartData:d.map(u=>({element:u,startData:u.getTransformStartData()})),currentElements:new Map},a.current=new Map,d.forEach(u=>{a.current.set(u.id,u.clone())}),i.startDrag(d[0],o,s),c({type:null,data:null}),!0)}function Zu(e){const{selectedElement:t,activeChildElement:r}=e;let o=null,s=-1;if(r instanceof T.ImageElement&&r.isCropping)o=r,t instanceof T.GroupElement&&(s=t.children.findIndex(a=>a.id===r.id));else if(t instanceof T.GroupElement)for(let a=0;a<t.children.length;a++){const c=t.children[a];if(c.visible!==!1&&c instanceof T.ImageElement&&c.isCropping){o=c,s=a;break}}const i=o||(t instanceof T.ImageElement&&t.isCropping?t:null);return i?{croppingImage:i,croppingChild:o,croppingChildIndex:s,isChildInGroup:o!==null}:null}function Ju(e){const{x:t,y:r,cropContext:o,transformHandles:s,zoom:i=1}=e,{croppingImage:a}=o,c=a.hitTestCropHandle(t,r,i);if(c)return{type:"crop-handle",handle:c};const d=s.hitTestResize(t,r,i);return d?{type:"image-handle",handle:d}:a.hitTest(t,r)?{type:"image-drag"}:{type:"exit-crop"}}function Qu(e){const{cropContext:t,cropHandle:r,x:o,y:s,selectedElement:i,activeChildElement:a,stateMachine:c}=e,{croppingImage:d,croppingChild:u,croppingChildIndex:h}=t,f=d.getCropBoxBounds();f&&(c.startResize(d,{anchor:"crop-"+r.anchor,x:0,y:0,cursor:"grab",type:r.type},o,s,f,f),u&&(a&&a.id===u.id?c._activeChildContext={group:i,childId:u.id}:c._cropGroupContext={group:i,childIndex:h}))}function eh(e){const{cropContext:t,imageHandle:r,x:o,y:s,selectedElement:i,activeChildElement:a,stateMachine:c}=e,{croppingImage:d,croppingChild:u,croppingChildIndex:h}=t,f=d.getBoundingBox(),p=d.getVisualBoundingBox();c.startResize(d,r,o,s,f,p),u&&(a&&a.id===u.id?c._activeChildContext={group:i,childId:u.id}:c._cropGroupContext={group:i,childIndex:h})}function th(e){const{cropContext:t,x:r,y:o,selectedElement:s,activeChildElement:i,stateMachine:a,dragOriginalElementsRef:c,setHoverState:d}=e,{croppingImage:u,croppingChild:h,croppingChildIndex:f}=t;c.current=new Map,h&&s?c.current.set(s.id,s.clone()):c.current.set(u.id,u.clone()),a.startDrag(u,r,o,"crop-image-drag"),d({type:null,data:null}),h&&(i&&i.id===h.id?a._activeChildContext={group:s,childId:h.id}:a._cropGroupContext={group:s,childIndex:f})}function nh(e){const{cropContext:t,selectedElement:r,onElementUpdate:o,transformHandles:s,updateActiveChild:i,zoom:a}=e,{croppingImage:c,croppingChild:d,croppingChildIndex:u}=t;if(d&&r instanceof T.GroupElement){const h=d.clone();h.exitCropMode();const f=r.clone();f.children[u]=h,o(f),s.update(f,a),i(null)}else{const h=c.clone();h.exitCropMode(),o(h),s.update(h,a)}}function rh(e){const{x:t,y:r,activeChildElement:o,selectedElement:s,updateActiveChild:i,transformHandles:a,setHandlesVersion:c,stateMachine:d,dragOriginalElementsRef:u,setHoverState:h,forceUpdate:f,zoom:p}=e;for(let g=s.children.length-1;g>=0;g--){const b=s.children[g];if(!(b.visible===!1||b.id===o.id)&&b.hitTest(t,r))return i(b),a.update(b,p),c(x=>x+1),d.startDrag(b,t,r),u.current=new Map,u.current.set(b.id,b.clone()),h({type:null,data:null}),d._activeChildContext={group:s,childId:b.id},f({}),!0}return!1}function ea(e){const{updateActiveChild:t,selectedElement:r,transformHandles:o,setHandlesVersion:s,zoom:i}=e;t(null),r&&(o.update(r,i),s(a=>a+1))}function oh(e){const{x:t,y:r,shiftKey:o,activeArtboardElements:s,selectedElement:i,multiSelection:a,onSelectionChange:c,onMultiSelectionChange:d,stateMachine:u,dragOriginalElementsRef:h,setHoverState:f,forceUpdate:p}=e;for(let g=s.length-1;g>=0;g--)if(s[g].visible!==!1&&s[g].hitTest(t,r)){const b=s[g].id;if(o){if(i&&a.length===0)d([i.id,b]),c(null);else if(a.includes(b)){const x=a.filter(y=>y!==b);d(x)}else d([...a,b]);return!0}if(a.length>0&&a.includes(b)){const x=a.map(y=>s.find(v=>v.id===y)).filter(y=>y!==void 0&&!y.locked);if(x.length>0)return u._multiSelectionDragContext={startX:t,startY:r,elementsStartData:x.map(y=>({element:y,startData:y.getTransformStartData()})),currentElements:new Map},h.current=new Map,x.forEach(y=>{h.current.set(y.id,y.clone())}),u.startDrag(x[0],t,r),f({type:null,data:null}),p({}),!0}return c(b),d([]),h.current=new Map,h.current.set(b,s[g].clone()),u.startDrag(s[g],t,r),f({type:null,data:null}),s[g]instanceof T.GroupElement&&(u._groupDragOriginalElement=s[g].clone()),p({}),!0}return!1}const sh=900;function os(e,t,r,o){if(!o)return!0;const s=e.getVisualBoundingBox(),i=Math.max(s.x,o.x),a=Math.max(s.y,o.y),c=Math.min(s.x+s.width,o.x+o.width),d=Math.min(s.y+s.height,o.y+o.height);return Math.max(0,c-i)*Math.max(0,d-a)<sh?!0:t>=o.x&&t<=o.x+o.width&&r>=o.y&&r<=o.y+o.height}function ih(e){const{canvasRef:t,inputRef:r,repositioningCursorRef:o,lastClickTimeRef:s,clickCountRef:i,lastProcessedClickTimeRef:a,lastMultiClickTimeRef:c,multiClickSelectionRef:d,skipDragSelectionRef:u,draggingSelectionHandleRef:h,selectionHandlePositionsRef:f,lastMousePosRef:p,dragOriginalElementsRef:g,rotatingElementRef:b,editingChildIdRef:x,editRichTextRef:y,editModeEnteredAtRef:v,multiSelectionGroupBoundsRef:w,MULTI_CLICK_THRESHOLD:C,MULTI_CLICK_DEBOUNCE:j,CLICK_DEDUP_THRESHOLD:M,isEditing:S,editText:R,isTouchDevice:I,selectionStart:D,selectionEnd:E,isRotating:O,isMarqueeSelecting:z,isAltKeyPressed:_,selectedElement:k,activeChildElement:Y,elements:B,multiSelection:G,multiSelectionOBBRef:se,zoom:A,paddingOffsetX:Z,paddingOffsetY:J,spacingIndicators:q,focusedPieceRect:ae,setCursorPosition:Le,setSelectionStart:pe,setSelectionEnd:U,setIsRotating:W,setRotationStartAngle:Ie,setCurrentRotation:ke,setRotatingElementVersion:Ke,setIsAltKeyPressed:re,setSnapGuides:te,setSpacingIndicators:he,setHandlesVersion:ye,setHoverState:we,setElements:Pe,forceUpdate:me,stateMachine:N,transformHandles:ce,snapSystem:le,spacingSystem:Me,penTool:ge,cropController:L,onElementUpdate:ve,executeElementUpdate:tt,onSelectionChange:Ve,onMultiSelectionChange:oe,onRotationStateChange:ie,onCropModeEnter:pt,updateActiveChild:st,getActiveArtboardElements:ht,startMarqueeSelection:bt,updateMarqueeSelection:yt,finishMarqueeSelection:Tt,enterTextEditMode:Rt,setEditPosition:jt,setEditText:kt,setEditRichText:Kt,setIsEditing:$t,setCurrentFormattingStyle:Ot,getWrappedTextForEditing:De}=e,je=l.useRef(null),Ee=l.useRef(new Map),$e=l.useRef(null),Qe=l.useRef(null),Fe=l.useRef(null),Ue=l.useRef(null),Xe=l.useRef(null),dt=l.useRef(null),Ye=l.useRef(null),{userZoom:vt,setUserZoom:gt,panOffset:Nt,setPanOffset:Ft}=Yt.useViewportContext(),$=l.useRef(vt);$.current=vt;const ee=l.useRef(Nt);ee.current=Nt,l.useEffect(()=>{const Q=t.current;if(!Q)return;const ze=()=>{je.current=Q.getBoundingClientRect()};return ze(),window.addEventListener("scroll",ze,{passive:!0,capture:!0}),window.addEventListener("resize",ze,{passive:!0}),()=>{window.removeEventListener("scroll",ze,{capture:!0}),window.removeEventListener("resize",ze)}},[t]),l.useEffect(()=>{const Q=t.current;Q&&(je.current=Q.getBoundingClientRect())},[A,t]);const Je=l.useCallback(Q=>{var Ne,He,Se,Be,Ae;const ze=t.current;if(!ze)return;const nt=ze.getBoundingClientRect();je.current=nt;const Ce=(Q.clientX-nt.left)/A-Z,X=(Q.clientY-nt.top)/A-J;Ee.current.size===0&&(Fe.current=(k==null?void 0:k.id)??null),Ee.current.set(Q.pointerId,{x:Ce,y:X,clientX:Q.clientX,clientY:Q.clientY});const Mt=S||k instanceof T.ImageElement&&k.isCropping||ge.isActive();if(Ee.current.size===2&&!Mt){const V=Array.from(Ee.current.keys()),xe=Ee.current.get(V[0]),ne=Ee.current.get(V[1]),fe=Fe.current!==null;if(!(fe&&k&&!k.locked&&(k.hitTest(xe.x,xe.y)||k.hitTest(ne.x,ne.y)))){if(g.current&&g.current.size>0){const _t=g.current;Pe(At=>At.map(Dt=>{const rn=_t.get(Dt.id);return rn?rn.clone():Dt})),g.current=null}!fe&&k&&Ve(null),N.isInteracting()&&N.end(),Ye.current=null,Ue.current=null,Xe.current=null,delete N._pendingTextEditMode,delete N._pendingChildSelection;const Oe=ne.clientX-xe.clientX,ot=ne.clientY-xe.clientY,mt=Math.hypot(Oe,ot),Wt=(((Ne=ze.parentElement)==null?void 0:Ne.parentElement)??ze).getBoundingClientRect();dt.current={pointerA:V[0],pointerB:V[1],startUserZoom:$.current,startPanOffset:{...ee.current},startCentroidClient:{x:(xe.clientX+ne.clientX)/2,y:(xe.clientY+ne.clientY)/2},startDistance:Math.max(mt,1),containerRect:{left:Wt.left,top:Wt.top}};try{ze.setPointerCapture(Q.pointerId)}catch{}Q.preventDefault();return}}if(Ee.current.size===2&&k&&!k.locked&&!Mt){if(N.isInteracting()){const fe=N.getContext();if(fe.element){const _e=ht().find(Oe=>Oe.id===fe.element.id);tt(_e,fe.element)}N.end()}const V=Array.from(Ee.current.keys());$e.current={a:V[0],b:V[1]};const xe=Ee.current.get(V[0]),ne=Ee.current.get(V[1]);Ue.current=null,Xe.current=null,Ye.current=null,Qe.current=k.clone(),N.startPinch(k,xe,ne);try{ze.setPointerCapture(Q.pointerId)}catch{}Q.preventDefault();return}if(S&&k instanceof T.TextElement){if(I&&D!==E){const V=f.current;if(V.start||V.end){const xe=T.RotationUtils.toRadiansInverse(k.rotation),ne=k.getRotationAnchor(),fe=Ce-ne.x,_e=X-ne.y,Oe=Math.cos(xe),ot=Math.sin(xe),mt=fe*Oe-_e*ot,Bt=fe*ot+_e*Oe,Wt=mt,_t=Bt,At=44/A;if(V.start&&Math.sqrt(Math.pow(Wt-V.start.center.x,2)+Math.pow(_t-V.start.center.y,2))<=At){Q.preventDefault(),h.current="start",(He=r.current)==null||He.focus();return}if(V.end&&Math.sqrt(Math.pow(Wt-V.end.center.x,2)+Math.pow(_t-V.end.center.y,2))<=At){Q.preventDefault(),h.current="end",(Se=r.current)==null||Se.focus();return}}}if(k.hitTest(Ce,X)){Q.preventDefault(),o.current=!0;const V=k.getVisualBoundingBox(),xe=T.RotationUtils.toRadiansInverse(k.rotation),ne=k.getRotationAnchor(),fe=Ce-ne.x,_e=X-ne.y,Oe=Math.cos(xe),ot=Math.sin(xe),mt=fe*Oe-_e*ot,Bt=fe*ot+_e*Oe,Wt=mt+V.width/2,_t=Bt+V.height/2,At=Xn(k,{x:Wt,y:_t}),Dt=Date.now();if(Dt-a.current<M){(Be=r.current)==null||Be.focus();return}a.current=Dt,Dt-c.current>=j&&(d.current=null),Dt-s.current<C?i.current+=1:i.current=1,s.current=Dt;const Lt=R;if(i.current>=3)Q.preventDefault(),c.current=Dt,d.current={start:0,end:Lt.length,cursor:Lt.length},u.current=!0,i.current=0,Le(Lt.length),pe(0),U(Lt.length),r.current&&(r.current.focus(),r.current.setSelectionRange(0,Lt.length));else if(i.current===2){Q.preventDefault(),c.current=Dt,u.current=!0;const Ut=sl(Lt,At);d.current={start:Ut.start,end:Ut.end,cursor:Ut.end},Le(Ut.end),pe(Ut.start),U(Ut.end),r.current&&(r.current.focus(),r.current.setSelectionRange(Ut.start,Ut.end))}else d.current=null,Le(At),pe(At),U(At),r.current&&(r.current.focus(),r.current.setSelectionRange(At,At)),u.current=!1;return}d.current=null,(Ae=r.current)==null||Ae.blur();return}if(S)return;if(Q.target.setPointerCapture(Q.pointerId),ge.isActive()&&k instanceof T.PathElement){const V=Ce-k.x,xe=X-k.y;if(ge.canClosePath(V,xe,15)){ge.startClosing(V,xe),ge.startDraggingHandle(),ye(ne=>ne+1);return}ge.addPoint(V,xe),ge.startDraggingHandle(),ye(ne=>ne+1);return}if(G.length>0&&w.current){const V=w.current,xe=Vu({x:Ce,y:X,bounds:V,zoom:A});if(xe.type==="corner-handle"){if(Gu({multiSelection:G,elements:B,bounds:V,anchor:xe.anchor,corner:xe.corner,x:Ce,y:X,stateMachine:N})){me({});return}}else if(xe.type==="rotation-handle"){if(Ku({multiSelection:G,elements:B,bounds:V,x:Ce,y:X,stateMachine:N,setIsRotating:W,setRotationStartAngle:Ie,setCurrentRotation:ke})){me({});return}}else if(xe.type==="bounds-drag"&&qu({multiSelection:G,elements:B,x:Ce,y:X,stateMachine:N,dragOriginalElementsRef:g,setHoverState:we})){me({});return}}const ue=Y||k;if(ue&&ue.visible!==!1&&!ue.locked&&(G.length===0||Y)){const V=Zu({selectedElement:k||null,activeChildElement:Y});if(V){const ne=Ju({x:Ce,y:X,cropContext:V,transformHandles:ce,zoom:A});if(ne.type==="crop-handle"){Qu({cropContext:V,cropHandle:ne.handle,x:Ce,y:X,selectedElement:k||null,activeChildElement:Y,stateMachine:N}),me({});return}else if(ne.type==="image-handle"){eh({cropContext:V,imageHandle:ne.handle,x:Ce,y:X,selectedElement:k||null,activeChildElement:Y,stateMachine:N}),me({});return}else if(ne.type==="image-drag"){th({cropContext:V,x:Ce,y:X,selectedElement:k||null,activeChildElement:Y,stateMachine:N,dragOriginalElementsRef:g,setHoverState:we}),me({});return}else if(ne.type==="exit-crop"){nh({cropContext:V,selectedElement:k||null,onElementUpdate:ve,transformHandles:ce,updateActiveChild:st,zoom:A}),ye(fe=>fe+1);return}}if(ce.hitTestRotation(Ce,X,A)){if(ue.locked)return;const ne=ue.getBoundingBox(),fe=T.getBoundingBoxCenter(ne),_e=T.calculateAngle(fe.x,fe.y,Ce,X);W(!0),Ie(_e),ke(ue.rotation),N.startRotate(ue,Ce,X,_e,ue.rotation),Y&&k instanceof T.GroupElement&&(N._activeChildContext={group:k,childId:Y.id}),Ue.current=ue.id,Xe.current={x:Ce,y:X},me({});return}const xe=ce.hitTestResize(Ce,X,A);if(xe){if(ue.locked)return;const ne=ue.getBoundingBox(),fe=ue.getVisualBoundingBox();N.startResize(ue,xe,Ce,X,ne,fe),Ue.current=ue.id,Xe.current={x:Ce,y:X},Y&&k instanceof T.GroupElement&&(N._activeChildContext={group:k,childId:Y.id}),me({});return}if(ue.hitTest(Ce,X)){if(ue.locked)return;if(k instanceof T.GroupElement&&!Y){const ne=k.hitTestChild(Ce,X);ne&&(N._pendingChildSelection=ne)}k&&ue.id===k.id&&!(ue instanceof T.TextElement)&&(Ue.current=ue.id,Xe.current={x:Ce,y:X}),ue instanceof T.TextElement&&!(ue instanceof T.GroupElement)&&k&&ue.id===k.id&&!S&&(N._pendingTextEditMode={elementId:ue.id,originalX:ue.x,originalY:ue.y,clickX:Ce,clickY:X}),N.startDrag(ue,Ce,X),g.current=new Map,g.current.set(ue.id,ue.clone()),we({type:null,data:null}),ue instanceof T.GroupElement&&(N._groupDragOriginalElement=ue.clone()),Y&&k instanceof T.GroupElement&&(N._activeChildContext={group:k,childId:Y.id}),me({});return}}if(Y&&k instanceof T.GroupElement){if(rh({x:Ce,y:X,activeChildElement:Y,selectedElement:k,updateActiveChild:st,transformHandles:ce,setHandlesVersion:ye,stateMachine:N,dragOriginalElementsRef:g,setHoverState:we,forceUpdate:me,zoom:A}))return;ea({updateActiveChild:st,selectedElement:k||null,transformHandles:ce,setHandlesVersion:ye,zoom:A});return}if(Y){ea({updateActiveChild:st,selectedElement:k||null,transformHandles:ce,setHandlesVersion:ye,zoom:A});return}if(!Q.shiftKey){const V=ht(),xe=[];for(let fe=V.length-1;fe>=0;fe--){const _e=V[fe];_e.visible!==!1&&_e.hitTest(Ce,X)&&os(_e,Ce,X,ae)&&xe.push(_e)}let ne=null;if(xe.length===0)k&&(ne={kind:"deselect"});else{const fe=k?xe.findIndex(_e=>_e.id===k.id):-1;fe===-1?ne={kind:"select-element",elementId:xe[0].id,x:Ce,y:X,shiftKey:Q.shiftKey}:fe+1<xe.length?ne={kind:"select-element",elementId:xe[fe+1].id,x:Ce,y:X,shiftKey:Q.shiftKey}:ne={kind:"deselect"}}Ye.current={pointerId:Q.pointerId,startClientX:Q.clientX,startClientY:Q.clientY,startPanOffset:{...ee.current},movedPastThreshold:!1,pendingTap:ne};try{ze.setPointerCapture(Q.pointerId)}catch{}Q.preventDefault();return}const et=ht();if(oh({x:Ce,y:X,shiftKey:Q.shiftKey,activeArtboardElements:et,selectedElement:k||null,multiSelection:G,onSelectionChange:Ve,onMultiSelectionChange:oe,stateMachine:N,dragOriginalElementsRef:g,setHoverState:we,forceUpdate:me}))return;const be=ti.shouldProtectClick(),Te=Yt.shouldPreserveSelection(Q.target);if(!be&&!Te)if($.current>1.001){Ye.current={pointerId:Q.pointerId,startClientX:Q.clientX,startClientY:Q.clientY,startPanOffset:{...ee.current},movedPastThreshold:!1,pendingTap:null};try{ze.setPointerCapture(Q.pointerId)}catch{}Q.preventDefault()}else Ve(null),oe([]),bt(Ce,X)},[S,k,ht,Ve,oe,ce,Y,G,N,ge,tt,ye,A,Le,pe,U,t,Pe,ae]),it=l.useCallback(Q=>{var Mt;const ze=t.current;if(!ze)return;const nt=je.current??ze.getBoundingClientRect(),Ce=(Q.clientX-nt.left)/A-Z,X=(Q.clientY-nt.top)/A-J;if(p.current={x:Ce,y:X},Ee.current.has(Q.pointerId)&&Ee.current.set(Q.pointerId,{x:Ce,y:X,clientX:Q.clientX,clientY:Q.clientY}),dt.current){const ue=dt.current,et=Ee.current.get(ue.pointerA),K=Ee.current.get(ue.pointerB);if(et&&K){const be=K.clientX-et.clientX,Te=K.clientY-et.clientY,He=Math.hypot(be,Te)/ue.startDistance,Se=Math.min(Math.max(ue.startUserZoom*He,.25),8),Be=ue.startCentroidClient.x-ue.containerRect.left,Ae=ue.startCentroidClient.y-ue.containerRect.top,V=(et.clientX+K.clientX)/2-ue.containerRect.left,xe=(et.clientY+K.clientY)/2-ue.containerRect.top,ne=Se/ue.startUserZoom,fe=V-(Be-ue.startPanOffset.x)*ne,_e=xe-(Ae-ue.startPanOffset.y)*ne,Oe=t.current;if(Oe){const ot=Oe.getBoundingClientRect(),mt=(Mt=Oe.parentElement)==null?void 0:Mt.parentElement,Bt=(mt==null?void 0:mt.clientWidth)??ot.width,Wt=(mt==null?void 0:mt.clientHeight)??ot.height,_t=80,At=Se/Math.max($.current,1e-4),Dt=ot.width*At,rn=ot.height*At,Lt=ee.current.x,Ut=ee.current.y,an=ot.left-ue.containerRect.left,un=ot.top-ue.containerRect.top,Zt=an+(fe-Lt),Qt=un+(_e-Ut),hn=Math.min(Math.max(Zt,-Dt+_t),Bt-_t),en=Math.min(Math.max(Qt,-rn+_t),Wt-_t);gt(Se),Ft({x:fe+(hn-Zt),y:_e+(en-Qt)})}else gt(Se),Ft({x:fe,y:_e})}return}if(Ye.current&&Ye.current.pointerId===Q.pointerId){const ue=Ye.current,et=Q.clientX-ue.startClientX,K=Q.clientY-ue.startClientY;if(!ue.movedPastThreshold)if(Math.hypot(et,K)>5)ue.movedPastThreshold=!0,ue.pendingTap=null;else return;if($.current<=1.001)return;Ft({x:ue.startPanOffset.x+et,y:ue.startPanOffset.y+K});return}if(N.getMode()==="pinch"&&$e.current){const{a:ue,b:et}=$e.current,K=Ee.current.get(ue),be=Ee.current.get(et);if(K&&be){const Te=N.updatePinch(K,be),{element:Ne,startData:He}=N.getPinchContext();Wu.calculatePinch({element:Ne,startData:He,scale:Te.scale,rotationDelta:Te.rotationDelta,startCentroid:Te.startCentroid,currentCentroid:Te.currentCentroid,snapRotation:le?(Se,Be)=>le.snapRotation(Se,Be):void 0}),Pe(Se=>Se.map(Be=>Be.id===Ne.id?Ne:Be))}Q.preventDefault();return}if(h.current&&k instanceof T.TextElement){const ue=k.getVisualBoundingBox(),et=k.getRotationAnchor(),K=T.RotationUtils.toRadiansInverse(k.rotation),be=Ce-et.x,Te=X-et.y,Ne=Math.cos(K),He=Math.sin(K),Se=be*Ne-Te*He,Be=be*He+Te*Ne,Ae=f.current;let V=0;h.current==="start"&&(Ae!=null&&Ae.start)?V=Ae.start.textEdge.y-Ae.start.center.y:h.current==="end"&&(Ae!=null&&Ae.end)&&(V=Ae.end.textEdge.y-Ae.end.center.y);const xe=Se+ue.width/2,ne=Be+V+ue.height/2,fe=Xn(k,{x:xe,y:ne});if(h.current==="start"?fe<=E?(pe(fe),Le(fe)):(pe(E),U(fe),Le(fe),h.current="end"):fe>=D?(U(fe),Le(fe)):(U(D),pe(fe),Le(fe),h.current="start"),r.current){const _e=Math.min(D,E),Oe=Math.max(D,E);r.current.setSelectionRange(_e,Oe)}return}if(ge.isActive()&&k instanceof T.PathElement){ge.isDraggingHandle()?(ge.updateHandle(Ce-k.x,X-k.y),ye(ue=>ue+1)):(ge.setPreviewPoint(Ce-k.x,X-k.y),ye(ue=>ue+1));return}if(Q.altKey!==_&&re(Q.altKey),z){yt(Ce,X,B);return}if(N.getMode()==="drag"){const ue=N._multiSelectionDragContext;if(ue&&G.length>0){const et=Ce-ue.startX,K=X-ue.startY;ue.currentElements||(ue.currentElements=new Map);const be=[];ue.elementsStartData.forEach(Te=>{const Ne=Te.element,He=Te.startData,Se=Ne.clone();Se.x=He.x+et,Se.y=He.y+K,ue.currentElements.set(Se.id,Se),be.push(Se)}),Pe(Te=>Te.map(Ne=>be.find(He=>He.id===Ne.id)||Ne)),ue.currentDelta={dx:et,dy:K},!ue.startOBB&&se.current&&(ue.startOBB={...se.current}),ye(Te=>Te+1),me({});return}}if(N.getMode()==="drag"&&k){if(N.getDragMode()==="crop-image-drag"){const Se=N.getContext(),Be=Se.element;if(Be instanceof T.ImageElement&&Be.isCropping){const Ae=L.handleCropImageDrag(Be,Se,Ce,X),V=N._cropGroupContext,xe=N._activeChildContext,ne=V||xe;if(ne&&k instanceof T.GroupElement){const fe=Be.clone();fe.x=Ae.x,fe.y=Ae.y,fe.updateCrop(Ae.cropX,Ae.cropY,Ae.cropWidth,Ae.cropHeight,!1);const _e=k.clone(),Oe=V?V.childIndex:_e.children.findIndex(mt=>mt.id===ne.childId);Oe>=0&&(_e.children[Oe]=fe,_e.updateBoundsFromChildren(!0)),Pe(mt=>mt.map(Bt=>Bt.id===_e.id?_e:Bt));const ot=N.getContext();ot._cachedElement||(ot._cachedElement={}),ot._cachedElement[_e.id]=_e,xe&&Oe>=0&&(st(_e.children[Oe]),ce.update(fe,A)),ye(mt=>mt+1)}else{const fe=Be.clone();fe.x=Ae.x,fe.y=Ae.y,fe.updateCrop(Ae.cropX,Ae.cropY,Ae.cropWidth,Ae.cropHeight,!1),Pe(Oe=>Oe.map(ot=>ot.id===fe.id?fe:ot));const _e=N.getContext();_e._cachedElement||(_e._cachedElement={}),_e._cachedElement[fe.id]=fe,ce.update(fe,A),ye(Oe=>Oe+1)}return}}const et=N._activeChildContext,K=ht(),be=[];K.forEach(Se=>{Se instanceof T.GroupElement?be.push(...Se.children):be.push(Se)});let Te=N.updateDrag(Ce,X,be);const Ne=et&&k instanceof T.GroupElement?k.children.find(Se=>Se.id===et.childId):k;if(Ne&&(Te=Me.snapToSpacing(Te,Ne,be)),et&&k instanceof T.GroupElement){const Se=k.clone(),Be=Se.children.findIndex(V=>V.id===et.childId);if(Be>=0){const V=Se.children[Be].clone();V.x=Te.x,V.y=Te.y,Se.children[Be]=V,Se.updateBoundsFromChildren(!0)}Pe(V=>V.map(xe=>xe.id===Se.id?Se:xe));const Ae=N.getContext();if(Ae._cachedElement||(Ae._cachedElement={}),Ae._cachedElement[Se.id]=Se,Be>=0){const V=Se.children[Be];st(V),ce.update(V,A)}ye(V=>V+1),me({})}else{const Se=N._groupDragOriginalElement,Be=k instanceof T.GroupElement&&Se?Se.clone():k.clone();if(Be instanceof T.GroupElement){const xe=N.getContext().startData,ne=Te.x-xe.x,fe=Te.y-xe.y;Be.move(ne,fe)}else Be.x=Te.x,Be.y=Te.y;Pe(V=>V.map(xe=>xe.id===Be.id?Be:xe)),ce.update(Be,A);const Ae=N.getContext();Ae._cachedElement||(Ae._cachedElement={}),Ae._cachedElement[Be.id]=Be}ye(Se=>Se+1),te(le.getGuides());let He;if(et&&k instanceof T.GroupElement)He=k.children.find(Se=>Se.id===et.childId);else{const Se=N.getContext();Se._cachedElement&&k?He=Se._cachedElement[k.id]:He=k||void 0}if(He){const Se=Me.detectSpacing(He,be,_);he(Se)}}else if(N.getMode()==="resize"){const{dx:ue,dy:et}=N.updateResize(Ce,X),K=N.getResizeContext(),be=N._multiSelectionResizeContext;if(be&&G.length>0){const V=be.startBounds,xe=be.anchor;let ne,fe,_e,Oe;switch(xe){case"top-left":ne=V.maxX,fe=V.maxY,_e=V.minX,Oe=V.minY;break;case"top-right":ne=V.minX,fe=V.maxY,_e=V.maxX,Oe=V.minY;break;case"bottom-left":ne=V.maxX,fe=V.minY,_e=V.minX,Oe=V.maxY;break;case"bottom-right":ne=V.minX,fe=V.minY,_e=V.maxX,Oe=V.maxY;break;default:ne=V.minX,fe=V.minY,_e=V.maxX,Oe=V.maxY}const ot=_e+ue,mt=Oe+et,Bt=Math.abs(_e-ne),Wt=Math.abs(Oe-fe),_t=Math.abs(ot-ne),At=Math.abs(mt-fe),Dt=Bt>0?_t/Bt:1,rn=Wt>0?At/Wt:1,Lt=(Dt+rn)/2,Ut=V.maxX-V.minX,an=V.maxY-V.minY,un=Ut*Lt,Zt=an*Lt;let Qt=ne,hn=fe,en=ne,xn=fe;switch(xe){case"top-left":en=ne,xn=fe,Qt=ne-un,hn=fe-Zt;break;case"top-right":Qt=ne,xn=fe,en=ne+un,hn=fe-Zt;break;case"bottom-left":en=ne,hn=fe,Qt=ne-un,xn=fe+Zt;break;case"bottom-right":Qt=ne,hn=fe,en=ne+un,xn=fe+Zt;break}if(be.elementsStartData.forEach(Yn=>{const er=Yn.element,wn=Yn.startData,cr=wn.x-ne,dr=wn.y-fe,Gn=ne+cr*Lt,tr=fe+dr*Lt,ln=er.clone();if(ln instanceof T.ImageElement){ln.x=Gn,ln.y=tr;const Hn=ln.transformData,$n=wn.transformData;Hn.width=$n.width*Lt,Hn.height=$n.height*Lt}else if(ln instanceof T.GroupElement){ln.x=Gn,ln.y=tr;const Hn=wn.width*Lt,$n=wn.height*Lt;ln.resize(xe,Hn,$n,wn)}else{const Hn=wn.width*Lt,$n=wn.height*Lt;ln.resize(xe,Hn,$n,wn),ln.x=Gn,ln.y=tr}ve(ln)}),se.current){const Yn=(Qt+en)/2,er=(hn+xn)/2;se.current={centerX:Yn,centerY:er,width:en-Qt,height:xn-hn,rotation:se.current.rotation}}return}const Te=K.element;if(Te instanceof T.ImageElement&&Te.isCropping&&K.handle.anchor&&K.handle.anchor.startsWith("crop-")){const V=K.handle.anchor.replace("crop-",""),xe=N.getContext(),ne=L.handleCropBoxResize(Te,V,K,xe,Ce,X);ze.style.cursor=ne.cursor;const fe=N._cropGroupContext,_e=N._activeChildContext,Oe=fe||_e;if(Oe&&k instanceof T.GroupElement){const ot=Te.clone();ot.x=ne.x,ot.y=ne.y,ot.rotation=ne.rotation,ot.transformData.width=ne.width,ot.transformData.height=ne.height,ot.updateCrop(ne.cropX,ne.cropY,ne.cropWidth,ne.cropHeight,!1);const mt=k.clone(),Bt=fe?fe.childIndex:mt.children.findIndex(Wt=>Wt.id===Oe.childId);Bt>=0&&(mt.children[Bt]=ot,mt.updateBoundsFromChildren(!0)),ve(mt),_e&&Bt>=0&&st(mt.children[Bt])}else{const ot=Te.clone();ot.x=ne.x,ot.y=ne.y,ot.rotation=ne.rotation,ot.transformData.width=ne.width,ot.transformData.height=ne.height,ot.updateCrop(ne.cropX,ne.cropY,ne.cropWidth,ne.cropHeight,!1),ve(ot)}return}if(!k)return;const Ne=N._activeChildContext,He=Ne&&k instanceof T.GroupElement,Se=[];B.forEach(V=>{V instanceof T.GroupElement?Se.push(...V.children):Se.push(V)});let Ae=rt.globalResizePipeline.executeResize({element:K.element,handle:K.handle,dx:ue,dy:et,startData:K.startData,allElements:Se,snapSystem:le}).element;if(N.updateResizeElement(Ae),He){const V=k.clone(),xe=V.children.findIndex(ne=>ne.id===Ne.childId);xe>=0&&(V.children[xe]=Ae,V.updateBoundsFromChildren(!0)),ve(V),xe>=0&&(st(V.children[xe]),ce.update(V.children[xe],A))}else ve(Ae),ce.update(Ae,A);ye(V=>V+1),te(le.getGuides())}else if(N.getMode()==="rotate"){ze.style.cursor="grabbing",O||(W(!0),ie==null||ie(!0));const ue=N._multiSelectionRotationContext;if(ue&&G.length>0){const Ae=ue.startBounds,V=N.updateRotate(Ce,X,Ae.centerX,Ae.centerY);ke(V),ue.elementsStartData.forEach(xe=>{const ne=xe.element,fe=xe.startData,_e=T.Transform.rotatePointAroundAnchor(fe.x,fe.y,Ae.centerX,Ae.centerY,V),Oe=ne.clone();Oe.x=_e.x,Oe.y=_e.y,Oe.setRotation(fe.rotation+V),ve(Oe)});return}const et=N._activeChildContext,K=et?Y:k;if(!K)return;const be=K.getBoundingBox(),Te=T.getBoundingBoxCenter(be),Ne=Te.x,He=Te.y,Se=N.updateRotate(Ce,X,Te.x,Te.y),Be=K.clone();if(Be.setRotation(Se),!(Be instanceof T.GroupElement)){const Ae=Be.getBoundingBox(),V=T.getBoundingBoxCenter(Ae),xe=Ne-V.x,ne=He-V.y;Be.x+=xe,Be.y+=ne}if(b.current=Be,ke(Be.rotation),Ke(Ae=>Ae+1),et&&k instanceof T.GroupElement){const Ae=k.clone(),V=Ae.children.findIndex(xe=>xe.id===et.childId);V>=0&&(Ae.children[V]=Be,Ae.updateBoundsFromChildren(!0)),ve(Ae),V>=0&&(st(Ae.children[V]),ce.update(Ae.children[V],A))}else ve(Be),ce.update(Be,A);ye(Ae=>Ae+1)}else{if(G.length>0&&w.current){const K=w.current,be=16/A,Te=[{x:K.minX,y:K.minY,anchor:"top-left",cursor:"nwse-resize"},{x:K.maxX,y:K.minY,anchor:"top-right",cursor:"nesw-resize"},{x:K.minX,y:K.maxY,anchor:"bottom-left",cursor:"nesw-resize"},{x:K.maxX,y:K.maxY,anchor:"bottom-right",cursor:"nwse-resize"}],Ne=K.rotation||0,He=Te.map(xe=>{if(Ne!==0){const ne=-Ne*Math.PI/180,fe=Math.cos(ne),_e=Math.sin(ne),Oe=xe.x-K.centerX,ot=xe.y-K.centerY;return{x:K.centerX+(Oe*fe-ot*_e),y:K.centerY+(Oe*_e+ot*fe),anchor:xe.anchor,cursor:xe.cursor}}return xe});for(const xe of He){const ne=Ce-xe.x,fe=X-xe.y;if(Math.sqrt(ne*ne+fe*fe)<=be){ze.style.cursor=xe.cursor,we({type:"multi-selection-handle",data:xe});return}}const Se=18/A;if(Math.sqrt(Math.pow(Ce-K.rotationHandleX,2)+Math.pow(X-K.rotationHandleY,2))<=Se){ze.style.cursor="grab",we({type:"multi-selection-rotation-handle",data:null});return}let Ae=Ce,V=X;if(Ne!==0){const xe=Ne*Math.PI/180,ne=Math.cos(xe),fe=Math.sin(xe),_e=Ce-K.centerX,Oe=X-K.centerY;Ae=K.centerX+(_e*ne-Oe*fe),V=K.centerY+(_e*fe+Oe*ne)}if(Ae>=K.minX&&Ae<=K.maxX&&V>=K.minY&&V<=K.maxY){ze.style.cursor="move",we({type:"multi-selection-bounds",data:K});return}}if(Q.altKey){let K=null;const be=ht();for(let Te=be.length-1;Te>=0;Te--){const Ne=be[Te];if(Ne.visible!==!1){if(Ne instanceof T.GroupElement)for(let He=Ne.children.length-1;He>=0;He--){const Se=Ne.children[He];if(Se.visible===!1)continue;const Be=Se.getVisualBoundingBox();if(Ce>=Be.x&&Ce<=Be.x+Be.width&&X>=Be.y&&X<=Be.y+Be.height){K=Se;break}}else{const He=Ne.getVisualBoundingBox();if(Ce>=He.x&&Ce<=He.x+He.width&&X>=He.y&&X<=He.y+He.height){K=Ne;break}}if(K)break}}if(K){const Te=[];be.forEach(He=>{He instanceof T.GroupElement?Te.push(...He.children):Te.push(He)});const Ne=Me.detectSpacing(K,Te,!0);he(Ne)}else he([])}else q.length>0&&he([]);const ue=Y||k;if(ue&&ue.visible!==!1)if(ue instanceof T.ImageElement&&ue.isCropping){const K=ue.hitTestCropHandle(Ce,X,A);if(K){const Te=T.getCursorForWorldPosition(K.worldX,K.worldY,ue.x,ue.y,K.type,ue.rotation,K.anchor);ze.style.cursor=Te,we({type:"crop-handle",data:K});return}const be=ce.hitTestResize(Ce,X,A);if(be){ze.style.cursor=be.cursor,we({type:"resize-handle",data:be});return}if(ue.hitTest(Ce,X)){ze.style.cursor="move",we({type:"element",data:ue});return}}else{if(ce.hitTestRotation(Ce,X,A)){ze.style.cursor="grab",we({type:"rotation-handle",data:null});return}const K=ce.hitTestResize(Ce,X,A);if(K){ze.style.cursor=K.cursor,we({type:"resize-handle",data:K});return}if(ue.hitTest(Ce,X)){ze.style.cursor="move",we({type:"element",data:ue});return}}if(Y&&k instanceof T.GroupElement)for(let K=k.children.length-1;K>=0;K--){const be=k.children[K];if(!(be.visible===!1||be.id===Y.id)&&be.hitTest(Ce,X)){ze.style.cursor="pointer",we({type:"group-sibling",data:be});return}}const et=ht();for(let K=et.length-1;K>=0;K--)if(et[K].visible!==!1&&!et[K].locked&&et[K].hitTest(Ce,X)){if(!os(et[K],Ce,X,ae))continue;ze.style.cursor="pointer",we({type:"element",data:et[K]});return}ze.style.cursor="default",we({type:null,data:null})}},[N,k,ht,ve,ce,z,le,G,se,Y,ge,ye,A,Z,J,we,Me,he,q,L,gt,Ft]),F=l.useCallback(Q=>{var Ce,X,Mt,ue,et;if(Q.target.releasePointerCapture(Q.pointerId),Ee.current.delete(Q.pointerId),dt.current&&(Q.pointerId===dt.current.pointerA||Q.pointerId===dt.current.pointerB)){dt.current=null,Ee.current.clear();return}if(Ye.current&&Ye.current.pointerId===Q.pointerId){const K=Ye.current;Ye.current=null,K.movedPastThreshold||(((Ce=K.pendingTap)==null?void 0:Ce.kind)==="select-element"?(Ve(K.pendingTap.elementId),oe([])):((X=K.pendingTap)==null?void 0:X.kind)==="deselect"&&(Ve(null),oe([])));return}if(N.getMode()==="pinch"&&$e.current){const{a:K,b:be}=$e.current;if(Q.pointerId===K||Q.pointerId===be){const Ne=N.getContext().element,He=Qe.current??void 0;Ne&&tt(He,Ne),N.end(),$e.current=null,Qe.current=null,Ee.current.clear();return}}if(h.current&&(h.current=null),ge.isActive()&&ge.isDraggingHandle()){const K=ge.isClosingPath();if(ge.finishDraggingHandle(),K&&k instanceof T.PathElement){const be=k.clone();tt(k,be)}ye(be=>be+1);return}if(z){Tt(oe);return}g.current&&N.getMode()==="drag"&&(g.current.forEach((be,Te)=>{const Ne=B.find(He=>He.id===Te);Ne&&(be.x!==Ne.x||be.y!==Ne.y||be instanceof T.GroupElement&&Ne instanceof T.GroupElement&&JSON.stringify(be.children.map(Se=>({x:Se.x,y:Se.y})))!==JSON.stringify(Ne.children.map(Se=>({x:Se.x,y:Se.y}))))&&tt(be,Ne)}),g.current=null);const ze=t.current;if(ze&&(ze.style.cursor="default"),le.clearGuides(),le.clearSnapState(),te([]),Me.clearIndicators(),he([]),N._cropGroupContext&&delete N._cropGroupContext,N._activeChildContext){if(Y&&k instanceof T.GroupElement){const K=N.getContext(),Ne=(K._cachedElement&&K._cachedElement[k.id]||k).children.find(He=>He.id===Y.id);Ne&&(st(Ne),ce.update(Ne,A))}delete N._activeChildContext}if(N._multiSelectionResizeContext&&delete N._multiSelectionResizeContext,B.forEach(K=>{if(K instanceof T.CustomTransform&&K._lockedLineCount!==void 0){const be=K.clone();be._lockedLineCount=void 0,ve(be)}}),N._multiSelectionDragContext){const K=N._multiSelectionDragContext;if(K.startOBB&&K.currentDelta){const{dx:be,dy:Te}=K.currentDelta,Ne=K.startOBB;se.current={...Ne,centerX:Ne.centerX+be,centerY:Ne.centerY+Te}}delete N._multiSelectionDragContext}if(N._multiSelectionRotationContext){if(N.getMode()==="rotate"&&G.length>0&&se.current){const K=se.current;se.current={...K,rotation:K.rotation+N._multiSelectionRotationContext.currentRotation||K.rotation}}delete N._multiSelectionRotationContext}const nt=N.getContext();if(nt._cachedElement&&delete nt._cachedElement,N._pendingChildSelection){const K=N._pendingChildSelection;let be=!0;if(k instanceof T.GroupElement){const Te=N._groupDragOriginalElement;Te&&(be=!(Math.abs(k.x-Te.x)>.1||Math.abs(k.y-Te.y)>.1))}be&&(st(K),ce.update(K,A),ye(Te=>Te+1)),delete N._pendingChildSelection}if(N._pendingTextEditMode){const K=N._pendingTextEditMode,be=B.find(Ne=>Ne.id===K.elementId);!(be&&(Math.abs(be.x-K.originalX)>.1||Math.abs(be.y-K.originalY)>.1))&&be instanceof T.TextElement&&!(be instanceof T.ImageElement)&&!(be instanceof T.ShapeElement)&&Rt(be,K.clickX,K.clickY),delete N._pendingTextEditMode}if(Ue.current){const K=Ue.current,be=Xe.current,Te=B.find(Be=>Be.id===K),Ne=(Mt=g.current)==null?void 0:Mt.get(K),He=!!(Te&&Ne&&(Math.abs(Te.x-Ne.x)>.1||Math.abs(Te.y-Ne.y)>.1)),Se=be?Math.hypot((Q.clientX-(((ue=je.current)==null?void 0:ue.left)??0))/A-Z-be.x,(Q.clientY-(((et=je.current)==null?void 0:et.top)??0))/A-J-be.y)>4/Math.max(A,1e-4):!1;if(!He&&!Se&&K===(k==null?void 0:k.id)&&be){const Be=ht(),Ae=[];for(let xe=Be.length-1;xe>=0;xe--){const ne=Be[xe];ne.visible!==!1&&ne.hitTest(be.x,be.y)&&os(ne,be.x,be.y,ae)&&Ae.push(ne)}const V=Ae.findIndex(xe=>xe.id===K);V!==-1&&V+1<Ae.length?Ve(Ae[V+1].id):Ve(null)}Ue.current=null,Xe.current=null}N._groupDragOriginalElement&&delete N._groupDragOriginalElement,N.end(),W(!1),ie==null||ie(!1),b.current=null,Ke(0),me({})},[N,le,z,oe,G,se,Y,k,st,ce,t,ge,ye,A,Z,J,ie,Rt,B,Ve,tt,ae]),ft=l.useCallback(Q=>{if(!k)return;const ze=t.current;if(!ze)return;const nt=je.current??ze.getBoundingClientRect(),Ce=(Q.clientX-nt.left)/A-Z,X=(Q.clientY-nt.top)/A-J;if(k.hitTest(Ce,X)){if(k instanceof T.GroupElement){const Oe=k.hitTestChild(Ce,X);if(Oe){if(!(Y&&Y.id===Oe.id))return;if(Oe instanceof T.TextElement&&!(Oe instanceof T.GroupElement)&&!(Oe instanceof T.ShapeElement)){const mt=Oe.getVisualBoundingBox(),Bt=T.RotationUtils.toRadiansInverse(Oe.rotation),Wt=Oe.getRotationAnchor(),_t=Ce-Wt.x,At=X-Wt.y,Dt=Math.cos(Bt),rn=Math.sin(Bt),Lt=_t*Dt-At*rn,Ut=_t*rn+At*Dt,an=Lt+mt.width/2,un=Ut+mt.height/2,Zt=Xn(Oe,{x:an,y:un}),Qt=mt.height+16,hn=6;jt({x:nt.left+(mt.x+Z)*A-hn,y:nt.top+(mt.y+J)*A-hn,width:Math.max(20,mt.width*A),height:Math.max(Qt*A,50)}),kt(De(Oe));const en=Oe.getRichText().clone();y.current=en,Kt(en);const xn=Oe.getRichText().getStyleAt(Math.max(0,Oe.text.length-1));Ot({...Oe.getDefaultStyle(),...xn}),Le(Zt),pe(Zt),U(Zt),$t(!0),v.current=Date.now(),x.current=Oe.id;return}}return}if(k instanceof T.PathElement){ge.editPath(k),ye(Oe=>Oe+1);return}if(k instanceof T.ShapeElement||!(k instanceof T.TextElement))return;const Mt=k.getVisualBoundingBox(),ue=T.RotationUtils.toRadiansInverse(k.rotation),et=k.getRotationAnchor(),K=Ce-et.x,be=X-et.y,Te=Math.cos(ue),Ne=Math.sin(ue),He=K*Te-be*Ne,Se=K*Ne+be*Te,Be=He+Mt.width/2,Ae=Se+Mt.height/2,V=Xn(k,{x:Be,y:Ae}),xe=Mt.height+16,ne=6;jt({x:nt.left+(Mt.x+Z)*A-ne,y:nt.top+(Mt.y+J)*A-ne,width:Math.max(20,Mt.width*A),height:Math.max(xe*A,50)}),kt(De(k));const fe=k.getRichText().clone();y.current=fe,Kt(fe);const _e=k.getRichText().getStyleAt(Math.max(0,k.text.length-1));Ot({...k.getDefaultStyle(),..._e}),Le(V),pe(V),U(V),$t(!0),v.current=Date.now()}},[k,ve,Y,ce,ge,ye,A,Z,J,jt,kt,Kt,Ot,Le,pe,U,$t,st,pt,De]),at=l.useCallback(Q=>{const ze=t.current;if(!ze||N.getMode()==="idle")return;const Ce=je.current??ze.getBoundingClientRect();if(Q.clientX>=Ce.left&&Q.clientX<=Ce.right&&Q.clientY>=Ce.top&&Q.clientY<=Ce.bottom)return;const Mt={clientX:Q.clientX,clientY:Q.clientY,altKey:Q.altKey,shiftKey:Q.shiftKey,ctrlKey:Q.ctrlKey,metaKey:Q.metaKey,bubbles:!0,cancelable:!0,currentTarget:ze,target:ze,nativeEvent:Q,type:"pointermove",pointerId:Q.pointerId||0,pointerType:Q.pointerType||"mouse",preventDefault:()=>Q.preventDefault(),stopPropagation:()=>Q.stopPropagation(),isPropagationStopped:()=>!1,isDefaultPrevented:()=>Q.defaultPrevented};it(Mt)},[it,t,N]),xt=l.useCallback(Q=>{const ze=t.current;if(!ze)return;const nt=Q.target,Ce=nt?ze.contains(nt):!1,X=Ee.current.has(Q.pointerId)||dt.current!==null||Ye.current!==null||$e.current!==null||N.isInteracting();if(!Ce&&!X)return;const Mt={clientX:Q.clientX,clientY:Q.clientY,currentTarget:ze,target:ze,pointerId:Q.pointerId||0,pointerType:Q.pointerType||"mouse"};F(Mt)},[F,t,N]);return l.useEffect(()=>(document.addEventListener("pointermove",at),document.addEventListener("pointerup",xt),()=>{document.removeEventListener("pointermove",at),document.removeEventListener("pointerup",xt)}),[at,xt]),{handlePointerDown:Je,handlePointerMove:it,handlePointerUp:F,handleDoubleClick:ft}}function po(e){if(e.transformType!=="custom")return e.text;const r=e.getVisualBoundingBox().width,o=e.getText();return T.wrapText(o,r,e.fontSize,e.fontFamily,e.bold,e.italic).join(`
13
- `)}function ah(e){const{canvasRef:t,inputRef:r,editingChildIdRef:o,editRichTextRef:s,selectionAnchorRef:i,cursorStartTimeRef:a,lastMultiClickTimeRef:c,multiClickSelectionRef:d,editPositionUpdateTimerRef:u,draggingSelectionHandleRef:h,repositioningCursorRef:f,editModeEnteredAtRef:p,lastTouchTargetRef:g,MULTI_CLICK_DEBOUNCE:b,EDIT_MODE_BLUR_DEBOUNCE:x,isEditing:y,editText:v,editRichText:w,cursorPosition:C,selectionStart:j,selectionEnd:M,selectedId:S,selectedElement:R,activeChildElement:I,elements:D,zoom:E,paddingOffsetX:O,paddingOffsetY:z,setIsEditing:_,setEditText:k,setEditRichText:Y,setCursorPosition:B,setSelectionStart:G,setSelectionEnd:se,setEditPosition:A,setCurrentFormattingStyle:Z,setCursorAnimationFrame:J,setHandlesVersion:q,setElements:ae,onElementUpdate:Le,onTextSelectionChange:pe,transformHandles:U,updateActiveChild:W}=e,Ie=l.useCallback((N,ce,le)=>{const Me=t.current;if(!Me)return;const ge=Me.getBoundingClientRect(),L=N.getVisualBoundingBox(),ve=T.RotationUtils.toRadiansInverse(N.rotation),tt=N.getRotationAnchor(),Ve=ce-tt.x,oe=le-tt.y,ie=Math.cos(ve),pt=Math.sin(ve),st=Ve*ie-oe*pt,ht=Ve*pt+oe*ie,bt=st+L.width/2,yt=ht+L.height/2,Tt=Xn(N,{x:bt,y:yt}),Rt=L.height+16,jt=6;A({x:ge.left+(L.x+O)*E-jt,y:ge.top+(L.y+z)*E-jt,width:Math.max(20,L.width*E),height:Math.max(Rt*E,50)}),k(po(N));const kt=N.getRichText().clone();s.current=kt,Y(kt);const Kt=N.getRichText().getStyleAt(Math.max(0,N.text.length-1));Z({...N.getDefaultStyle(),...Kt}),B(Tt),G(Tt),se(Tt),_(!0),p.current=Date.now()},[E,A,k,Y,Z,B,G,se,_]),ke=l.useCallback(N=>{if(!y||!w)return;const ce=Math.min(j,M),le=Math.max(j,M);if(ce===le){const Me=w.clone(),ge=Me.getText().length;Me.applyStyle(0,ge,N),s.current=Me,Y(Me),k(Me.getText()),Z(L=>({...L,...N}))}else{const Me=w.clone();Me.applyStyle(ce,le,N),s.current=Me,Y(Me),k(Me.getText()),Z(ge=>({...ge,...N}))}},[y,w,j,M]),Ke=l.useCallback(()=>{if(!y||!w||!R)return null;const N=Math.min(j,M),ce=Math.max(j,M);return N===ce?N===0?R instanceof T.TextElement?R.getDefaultStyle():{}:w.getStyleAt(Math.max(0,N-1)):w.getStyleAt(N)},[y,w,j,M,R]),re=l.useCallback(N=>{if(!y||!w||!R)return;const ce=Ke(),ge=!{...R instanceof T.TextElement?R.getDefaultStyle():{},...ce}[N];ke({[N]:ge})},[y,w,R,Ke,ke]),te=l.useCallback(()=>{if(!y)return;const N=s.current||w;if(R&&N){const ce=o.current;if(ce&&R instanceof T.GroupElement){const le=R.clone(),Me=le.children.findIndex(L=>L.id===ce);if(Me>=0){const L=le.children[Me];L instanceof T.TextElement&&L.setRichText(N),le.updateBoundsFromChildren(!0)}Le(le);const ge=le.children[Me];ge&&(W(ge),U.update(ge,E),q(L=>L+1))}else if(R instanceof T.TextElement){const le=R.clone();le.setRichText(N),Le(le),U.update(le,E),q(Me=>Me+1)}}d.current=null,_(!1),k(""),Y(null),s.current=null,Z(null),o.current=null},[y,v,w,s,R,Le,U,W,E]),he=l.useCallback(()=>{if(Date.now()-c.current<b){if(r.current){r.current.focus();const le=d.current;le&&r.current.setSelectionRange(le.start,le.end)}return}setTimeout(()=>{var ve,tt,Ve;if(Date.now()-p.current<x){(ve=r.current)==null||ve.focus();return}if(f.current){f.current=!1,(tt=r.current)==null||tt.focus(),r.current&&r.current.setSelectionRange(j,M);return}let ge=document.activeElement,L=!1;for(;ge;){const oe=ge.classList,ie=ge.getAttribute("data-slot");if(ie&&(ie.includes("popover")||ie.includes("dialog"))){L=!0;break}if(ge.hasAttribute("data-preserve-selection")){L=!0;break}if(oe&&(oe.contains("toolbar")||oe.contains("toolbar-items")||oe.contains("toolbar-btn")||oe.contains("toolbar-btn-sm")||oe.contains("toolbar-btn-icon")||oe.contains("toolbar-color")||oe.contains("toolbar-label")||oe.contains("toolbar-select")||oe.contains("toolbar-select-sm")||oe.contains("toolbar-group")||oe.contains("toolbar-scroll")||oe.contains("toolbar-color-label")||oe.contains("toolbar-color-square")||oe.contains("color-picker-dropdown")||oe.contains("text-color-panel")||oe.contains("tooltip-wrapper")||oe.contains("font-dropdown-with-label")||oe.contains("font-family-select-button")||oe.contains("more-menu-btn")||oe.contains("more-menu-toolbar")||oe.contains("font-drawer-overlay")||oe.contains("font-drawer-content")||oe.contains("font-drawer-handle")||oe.contains("font-drawer-handle-bar")||oe.contains("font-dropdown-list-container")||oe.contains("font-dropdown-search")||oe.contains("font-search-input")||oe.contains("font-category-filters")||oe.contains("font-category-btn")||oe.contains("font-grid-option")||oe.contains("font-section")||oe.contains("font-section-header")||oe.contains("font-section-used")||oe.contains("font-section-header-used")||oe.contains("font-dropdown-list-grid")||oe.contains("font-dropdown-list-grid-used")||oe.contains("font-preview")||oe.contains("font-name-label")||oe.contains("font-size-slider-container")||oe.contains("font-size-slider")||oe.contains("font-size-icon-small")||oe.contains("font-size-icon-large")||oe.contains("font-icon-toggle")||oe.contains("font-dropdown-empty")||oe.contains("vaul-drawer-wrapper")||oe.contains("vaul-overlay"))){L=!0;break}ge=ge.parentElement}if(!L&&g.current)for(ge=g.current;ge;){const oe=ge.classList,ie=ge.getAttribute("data-slot");if(ie&&(ie.includes("popover")||ie.includes("dialog"))){L=!0;break}if(ge.hasAttribute("data-preserve-selection")){L=!0;break}if(oe&&(oe.contains("toolbar")||oe.contains("toolbar-items")||oe.contains("toolbar-btn")||oe.contains("toolbar-btn-sm")||oe.contains("toolbar-btn-icon")||oe.contains("toolbar-color")||oe.contains("toolbar-label")||oe.contains("toolbar-select")||oe.contains("toolbar-select-sm")||oe.contains("toolbar-group")||oe.contains("toolbar-scroll")||oe.contains("toolbar-color-label")||oe.contains("toolbar-color-square")||oe.contains("color-picker-dropdown")||oe.contains("text-color-panel")||oe.contains("tooltip-wrapper")||oe.contains("font-dropdown-with-label")||oe.contains("font-family-select-button")||oe.contains("more-menu-btn")||oe.contains("more-menu-toolbar")||oe.contains("vaul-drawer-wrapper")||oe.contains("vaul-overlay"))){L=!0;break}ge=ge.parentElement}if(!L)te();else{const oe=j,ie=M;(Ve=r.current)==null||Ve.focus(),r.current&&r.current.setSelectionRange(oe,ie)}},0)},[te,j,M]),ye=l.useCallback(N=>{const ce=N.currentTarget;if(N.key==="Enter"&&(N.metaKey||N.ctrlKey))N.preventDefault(),te();else if(N.key==="Escape")N.preventDefault(),N.stopPropagation(),_(!1),k(""),Y(null),s.current=null,Z(null),o.current=null;else if((N.metaKey||N.ctrlKey)&&N.key.toLowerCase()==="b")N.preventDefault(),re("bold");else if((N.metaKey||N.ctrlKey)&&N.key.toLowerCase()==="i")N.preventDefault(),re("italic");else if((N.metaKey||N.ctrlKey)&&N.key.toLowerCase()==="u")N.preventDefault(),re("underline");else if(N.key==="ArrowLeft"||N.key==="ArrowRight")setTimeout(()=>{const le=ce.selectionStart;B(le),G(le),se(ce.selectionEnd),i.current=le},0);else if(N.key==="ArrowUp"||N.key==="ArrowDown"){if(R&&R instanceof T.TextElement){N.preventDefault();const le=N.key==="ArrowUp"?"up":"down",Me=lu(R,C,le);B(Me),G(Me),se(Me),i.current=Me,ce.setSelectionRange(Me,Me)}}else(N.key==="Home"||N.key==="End")&&setTimeout(()=>{const le=ce.selectionStart;B(le),G(le),se(ce.selectionEnd),i.current=le},0)},[te,re,B,G,se,i,C,R]);l.useEffect(()=>{y&&(a.current=performance.now())},[y,C,a]),l.useEffect(()=>{if(!y)return;let N,ce=0;const le=33,Me=ge=>{ge-ce>=le&&(J(L=>(L+1)%1e3),ce=ge),N=requestAnimationFrame(Me)};return N=requestAnimationFrame(Me),()=>cancelAnimationFrame(N)},[y]);const we=l.useRef(!1);l.useEffect(()=>{if(y&&!we.current&&r.current){r.current.focus();const N=v.length;B(N),G(N),se(N),r.current.setSelectionRange(N,N)}we.current=y},[y,v]);const Pe=l.useRef(null),me=(N,ce)=>N===ce?!0:!N||!ce?!1:N.color===ce.color&&N.fontFamily===ce.fontFamily&&N.fontSize===ce.fontSize&&N.bold===ce.bold&&N.italic===ce.italic&&N.underline===ce.underline&&N.strikethrough===ce.strikethrough;return l.useEffect(()=>{if(!y||!w)return;const N=Math.min(j,M),ce=Math.max(j,M);if(N===ce){let le=null;if(N>0)le=w.getStyleAt(N-1);else{const Me=D.find(ge=>ge.id===S);Me instanceof T.TextElement&&(le=Me.getDefaultStyle())}le&&!me(le,Pe.current)&&(Pe.current=le,Z(le))}},[y,w,j,M,S]),l.useEffect(()=>{if(!y||!r.current)return;const N=r.current;(N.selectionStart!==j||N.selectionEnd!==M)&&(j!==M?N.setSelectionRange(j,M):N.setSelectionRange(C,C))},[v,y,C,j,M]),l.useEffect(()=>{const N=D.find(ce=>ce.id===S);if(!(!y||!N||!t.current||!r.current))return u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{let ce=N;if(o.current&&N instanceof T.GroupElement){const tt=N.children.find(Ve=>Ve.id===o.current);tt&&(ce=tt)}if(!(ce instanceof T.TextElement))return;const le=ce.clone();w&&le.setRichText(w);const Me=le.getVisualBoundingBox(),ge=t.current.getBoundingClientRect(),L=Me.height+16,ve=6;if(A({x:ge.left+(Me.x+O)*E-ve,y:ge.top+(Me.y+z)*E-ve,width:Math.max(20,Me.width*E),height:Math.max(L*E,50)}),o.current&&N instanceof T.GroupElement){const tt=N.clone(),Ve=tt.children.findIndex(oe=>oe.id===o.current);Ve>=0&&(tt.children[Ve]=le,tt.updateBoundsFromChildren(!0)),ae(oe=>oe.map(ie=>ie.id===tt.id?tt:ie)),U.update(le,E)}else ae(tt=>tt.map(Ve=>Ve.id===le.id?le:Ve)),U.update(le,E);q(tt=>tt+1)},50),()=>{u.current&&clearTimeout(u.current)}},[v,w,y,S,E]),l.useEffect(()=>{if(!y||!r.current)return;const N=r.current,ce=()=>{if(h.current||Date.now()-c.current<b)return;const ge=N.selectionStart||0,L=N.selectionEnd||0;B(ve=>ve===L?ve:L),G(ve=>ve===ge?ve:ge),se(ve=>ve===L?ve:L),pe==null||pe()};N.addEventListener("click",ce),N.addEventListener("keyup",ce),N.addEventListener("select",ce),N.addEventListener("mouseup",ce);const le=()=>{document.activeElement===N&&ce()};return document.addEventListener("selectionchange",le),ce(),()=>{N.removeEventListener("click",ce),N.removeEventListener("keyup",ce),N.removeEventListener("select",ce),N.removeEventListener("mouseup",ce),document.removeEventListener("selectionchange",le)}},[y]),l.useEffect(()=>{const N=ce=>{const le=ce.target;if(le.tagName==="INPUT"||le.tagName==="TEXTAREA"||ce.key!=="Enter"||y||!t.current)return;const Me=t.current.getBoundingClientRect();if(I&&I instanceof T.TextElement&&!(I instanceof T.GroupElement)&&!(I instanceof T.ImageElement)&&!(I instanceof T.ShapeElement)){ce.preventDefault();const ge=I.getVisualBoundingBox(),L=ge.height+16,ve=6;A({x:Me.left+(ge.x+O)*E-ve,y:Me.top+(ge.y+z)*E-ve,width:Math.max(200,ge.width*E),height:Math.max(L*E,50)}),k(po(I)),_(!0),p.current=Date.now(),o.current=I.id;return}if(R&&R instanceof T.TextElement&&!(R instanceof T.GroupElement)&&!(R instanceof T.ImageElement)&&!(R instanceof T.ShapeElement)){ce.preventDefault();const ge=R.getVisualBoundingBox(),L=ge.height+16,ve=6;A({x:Me.left+(ge.x+O)*E-ve,y:Me.top+(ge.y+z)*E-ve,width:Math.max(200,ge.width*E),height:Math.max(L*E,50)}),k(po(R)),_(!0),p.current=Date.now()}};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[R,I,y]),{handleTextEditComplete:te,handleTextEditBlur:he,handleTextKeyDown:ye,applyFormattingToSelection:ke,getSelectionStyle:Ke,toggleFormattingProperty:re,enterTextEditMode:Ie,getWrappedTextForEditing:po}}const ll=l.forwardRef(({elements:e,artboards:t,artboardManager:r,selectedId:o,multiSelection:s,onElementUpdate:i,setElements:a,executeElementUpdate:c,onSelectionChange:d,onMultiSelectionChange:u,onActiveChildChange:h,onTextSelectionChange:f,onHoverChange:p,onRotationStateChange:g,onCropModeEnter:b,hideHandles:x=!1,canvasRef:y,width:v,height:w,zoom:C=1,offsetX:j=0,offsetY:M=0,viewPadding:S=1,artboardBorderRadius:R=0,fixedMargin:I,fixedMarginX:D,fixedMarginY:E,showRotationHandle:O=!0,canvasCutouts:z,pieceGuides:_,pieceFocus:k,focusedPieceRect:Y},B)=>{const{resolvedTheme:G}=Yt.useTheme(),se=l.useRef(null),A=y||se,Z=l.useRef(null),J=l.useRef(!1),q=l.useRef(0),ae=l.useRef(0),Le=l.useRef(0),pe=l.useRef(!1),U=l.useRef(0),W=l.useRef(null),Ie=l.useRef(0),ke=l.useRef(null),Ke=l.useRef({start:null,end:null}),re=l.useRef(null),te=l.useRef(null),he=l.useRef(null),ye=l.useRef(null),we=400,Pe=300,me=50,N=200,ce=l.useMemo(()=>{if(!k||k==="spread")return null;const Ze=(_==null?void 0:_.pieces)??[];if(Ze.length<=1)return null;const We=Ze.find(Ct=>Ct.id===k.pieceId);return We?{x:We.x,y:We.y,width:We.width,height:We.height}:null},[k,_]),le=Y!==void 0?Y:ce,Me=l.useMemo(()=>{if(le)return le;const Ze=(_==null?void 0:_.pieces)??[];if(Ze.length===1){const We=Ze[0];return{x:We.x,y:We.y,width:We.width,height:We.height}}return null},[le,_]),{isTouchDevice:ge,canvasSize:L,lastTouchTargetRef:ve,effectiveViewPadding:tt,paddedCanvasWidth:Ve,paddedCanvasHeight:oe,paddingOffsetX:ie,paddingOffsetY:pt,zoomInvariantBorderRadius:st}=yu({width:v,height:w,zoom:C,viewPadding:S,artboardBorderRadius:R,fixedMargin:I,fixedMarginX:D,fixedMarginY:E,artboards:t,artboardManager:r,focusedPieceRect:le}),{snapGuides:ht,setSnapGuides:bt,spacingIndicators:yt,setSpacingIndicators:Tt,isAltKeyPressed:Rt,setIsAltKeyPressed:jt,isRotating:kt,setIsRotating:Kt,setRotationStartAngle:$t,currentRotation:Ot,setCurrentRotation:De,setRotatingElementVersion:je}=vu(),{renderVersion:Ee,forceRender:$e,handlesVersion:Qe,setHandlesVersion:Fe,forceUpdate:Ue,cursorAnimationFrame:Xe,setCursorAnimationFrame:dt}=wu({elements:e}),[Ye]=l.useState(()=>new rt.TransformHandles),[vt]=l.useState(()=>new rt.ArtboardRenderer({showBorder:!1,showLabel:!1})),[gt]=l.useState(()=>new rt.AlignmentSnapSystem({enabled:!0,showGuides:!0})),[Nt]=l.useState(()=>new rt.SpacingSystem({enabled:!0,showLabels:!0})),[Ft]=l.useState(()=>{const Ze=new rt.InteractionStateMachine;return Ze.setResizePipeline(rt.globalResizePipeline),Ze.setSnapHandler(gt),Ze});l.useEffect(()=>{vt.setOptions({borderRadius:st})},[st,vt]),l.useEffect(()=>{const Ze=Y!==void 0?Y:ce;gt.setExtraSnapRects(Ze?[{id:"focused-piece",...Ze}]:[])},[gt,Y,ce]);const $=l.useRef(e);$.current=e;const ee=e.find(Ze=>Ze.id===o),Je=l.useRef(ee);Je.current=ee;const[it,F]=l.useState("");l.useEffect(()=>{var We;if(!o)return;const Ze=e.find(Ct=>Ct.id===o);if(Ze)if(Ze instanceof T.TextElement){const Ct=((We=Ze.text)==null?void 0:We.slice(0,40))||"empty";F(`Selected text element: ${Ct}`)}else Ze instanceof T.ImageElement?F("Selected image element"):Ze instanceof T.GroupElement?F("Selected group"):F("Selected element")},[o,e]);const ft=l.useRef(r);ft.current=r;const at=l.useRef(new Map);l.useEffect(()=>{const Ze=We=>{const Ct=We,Et=ft.current.getActiveArtboardId(),It=at.current.get(Et)||[],Ht=[];return It.forEach(qt=>{qt instanceof T.GroupElement?Ht.push(...qt.children):Ht.push(qt)}),gt.snapDimensions(Ct,Ht,Ct.startData)};return rt.globalResizePipeline.addHook("afterResize",Ze),()=>{rt.globalResizePipeline.removeHook("afterResize",Ze)}},[gt]);const{cropController:xt}=gu(),{penTool:Q,penCursor:ze}=hu({selectedElement:ee}),{isEditing:nt,setIsEditing:Ce,editText:X,setEditText:Mt,editPosition:ue,setEditPosition:et,cursorPosition:K,setCursorPosition:be,selectionStart:Te,setSelectionStart:Ne,selectionEnd:He,setSelectionEnd:Se,cursorOpacityRef:Be,cursorStartTimeRef:Ae,selectionAnchorRef:V,didDragSelectRef:xe,editRichText:ne,setEditRichText:fe,editRichTextRef:_e,currentFormattingStyle:Oe,setCurrentFormattingStyle:ot}=bu({selectedElement:ee,ref:B});l.useEffect(()=>{const Ze=Date.now()-U.current,We=W.current;We&&Ze<Pe?(Te!==We.start||He!==We.end)&&(be(We.cursor),Ne(We.start),Se(We.end),Z.current&&Z.current.setSelectionRange(We.start,We.end)):We&&Ze>=Pe&&(W.current=null)},[Te,He,K]);const{isMarqueeSelecting:mt,marqueeStart:Bt,marqueeEnd:Wt,marqueePreviewSelection:_t,startMarqueeSelection:At,updateMarqueeSelection:Dt,finishMarqueeSelection:rn}=cu(),{multiSelectionGroupBoundsRef:Lt,multiSelectionOBBRef:Ut}=xu(s),{activeChildElement:an,updateActiveChild:un,editingChildIdRef:Zt}=fu({elements:e,selectedElement:ee,transformHandles:Ye,onActiveChildChange:h}),{hoverState:Qt,setHoverState:hn}=pu({onHoverChange:p}),en=l.useMemo(()=>{const Ze=new Map;return e.forEach(We=>{const Ct=r.getArtboardIdForElement(We.id);Ze.has(Ct)||Ze.set(Ct,[]),Ze.get(Ct).push(We)}),Ze},[e,r]);at.current=en;const xn=l.useCallback(()=>{const Ze=r.getActiveArtboardId();return en.get(Ze)||[]},[en,r]);l.useEffect(()=>{const Ze=Et=>{if(!nt){if(Q.isActive()&&ee instanceof T.PathElement){if(Et.key==="Escape"){Et.preventDefault(),Q.finishPath();const It=ee.clone();c(ee,It),Fe(Ht=>Ht+1);return}else if(Et.key==="Backspace"||Et.key==="Delete"){Et.preventDefault(),Q.deleteLastPoint(),Fe(It=>It+1);return}}Et.altKey&&jt(!0)}},We=Et=>{Et.altKey||jt(!1)},Ct=Et=>{(!Et.relatedTarget||!Et.relatedTarget.ownerDocument)&&jt(!1)};return window.addEventListener("keydown",Ze),window.addEventListener("keyup",We),window.addEventListener("blur",Ct),()=>{window.removeEventListener("keydown",Ze),window.removeEventListener("keyup",We),window.removeEventListener("blur",Ct)}},[Q,ee,c,Fe,nt]),l.useEffect(()=>{if(!A.current||!re.current||Ft.getMode()==="drag"||Ft.getMode()==="resize")return;const{x:We,y:Ct}=re.current;if(Rt){let Et=null;const It=xn();for(let Ht=It.length-1;Ht>=0;Ht--){const qt=It[Ht];if(qt.visible!==!1){if(qt instanceof T.GroupElement)for(let Pt=qt.children.length-1;Pt>=0;Pt--){const St=qt.children[Pt];if(St.visible===!1)continue;const lt=St.getVisualBoundingBox();if(We>=lt.x&&We<=lt.x+lt.width&&Ct>=lt.y&&Ct<=lt.y+lt.height){Et=St;break}}else{const Pt=qt.getVisualBoundingBox();if(We>=Pt.x&&We<=Pt.x+Pt.width&&Ct>=Pt.y&&Ct<=Pt.y+Pt.height){Et=qt;break}}if(Et)break}}if(Et){const Ht=[];It.forEach(Pt=>{Pt instanceof T.GroupElement?Ht.push(...Pt.children):Ht.push(Pt)});const qt=Nt.detectSpacing(Et,Ht,!0);Tt(qt)}}else Tt([])},[Rt,xn,Nt,Ft]);const Yn=l.useRef(null);l.useEffect(()=>{const Ze=e.find(Ct=>Ct.id===o),We=an||Ze;if(We){const Ct=We.getBoundingBox(),Et=`${We.id}-${Ct.x}-${Ct.y}-${Ct.width}-${Ct.height}-${We.rotation}`;Yn.current!==Et&&(Yn.current=Et,Ye.update(We,C),Fe(It=>It+1))}},[o,an,Ye,C,e]);const{handleTextEditBlur:er,handleTextKeyDown:wn,applyFormattingToSelection:cr,getSelectionStyle:dr,toggleFormattingProperty:Gn,enterTextEditMode:tr,getWrappedTextForEditing:ln}=ah({canvasRef:A,inputRef:Z,editingChildIdRef:Zt,editRichTextRef:_e,selectionAnchorRef:V,cursorStartTimeRef:Ae,lastMultiClickTimeRef:U,multiClickSelectionRef:W,editPositionUpdateTimerRef:ye,draggingSelectionHandleRef:ke,repositioningCursorRef:J,editModeEnteredAtRef:Le,lastTouchTargetRef:ve,MULTI_CLICK_DEBOUNCE:Pe,EDIT_MODE_BLUR_DEBOUNCE:N,isEditing:nt,editText:X,editRichText:ne,cursorPosition:K,selectionStart:Te,selectionEnd:He,selectedId:o,selectedElement:ee,activeChildElement:an,elements:e,zoom:C,paddingOffsetX:ie,paddingOffsetY:pt,setIsEditing:Ce,setEditText:Mt,setEditRichText:fe,setCursorPosition:be,setSelectionStart:Ne,setSelectionEnd:Se,setEditPosition:et,setCurrentFormattingStyle:ot,setCursorAnimationFrame:dt,setHandlesVersion:Fe,setElements:a,onElementUpdate:i,onTextSelectionChange:f,transformHandles:Ye,updateActiveChild:un}),{handlePointerDown:Hn,handlePointerMove:$n,handlePointerUp:so,handleDoubleClick:Yo}=ih({canvasRef:A,inputRef:Z,repositioningCursorRef:J,lastClickTimeRef:q,clickCountRef:ae,lastProcessedClickTimeRef:Ie,lastMultiClickTimeRef:U,multiClickSelectionRef:W,skipDragSelectionRef:pe,draggingSelectionHandleRef:ke,selectionHandlePositionsRef:Ke,lastMousePosRef:re,dragOriginalElementsRef:te,rotatingElementRef:he,editingChildIdRef:Zt,editRichTextRef:_e,editModeEnteredAtRef:Le,multiSelectionGroupBoundsRef:Lt,MULTI_CLICK_THRESHOLD:we,MULTI_CLICK_DEBOUNCE:Pe,CLICK_DEDUP_THRESHOLD:me,isEditing:nt,editText:X,isTouchDevice:ge,selectionStart:Te,selectionEnd:He,isRotating:kt,isMarqueeSelecting:mt,isAltKeyPressed:Rt,selectedElement:ee,activeChildElement:an,elements:e,multiSelection:s,multiSelectionOBBRef:Ut,zoom:C,paddingOffsetX:ie,paddingOffsetY:pt,spacingIndicators:yt,focusedPieceRect:Me,setCursorPosition:be,setSelectionStart:Ne,setSelectionEnd:Se,setIsRotating:Kt,setRotationStartAngle:$t,setCurrentRotation:De,setRotatingElementVersion:je,setIsAltKeyPressed:jt,setSnapGuides:bt,setSpacingIndicators:Tt,setHandlesVersion:Fe,setHoverState:hn,setElements:a,forceUpdate:Ue,stateMachine:Ft,transformHandles:Ye,snapSystem:gt,spacingSystem:Nt,penTool:Q,cropController:xt,onElementUpdate:i,executeElementUpdate:c,onSelectionChange:d,onMultiSelectionChange:u,onRotationStateChange:g,onCropModeEnter:b,updateActiveChild:un,getActiveArtboardElements:xn,startMarqueeSelection:At,updateMarqueeSelection:Dt,finishMarqueeSelection:rn,enterTextEditMode:tr,setEditPosition:et,setEditText:Mt,setEditRichText:fe,setIsEditing:Ce,setCurrentFormattingStyle:ot,getWrappedTextForEditing:ln});Uu({canvasRef:A,elements:e,elementsByArtboard:en,artboards:t,artboardManager:r,artboardRenderer:vt,selectedId:o,selectedElement:ee,activeChildElement:an,editingChildIdRef:Zt,transformHandles:Ye,stateMachine:Ft,canvasSize:L,paddedCanvasWidth:Ve,paddedCanvasHeight:oe,paddingOffsetX:ie,paddingOffsetY:pt,zoom:C,zoomInvariantBorderRadius:st,effectiveViewPadding:tt,showRotationHandle:O,isRotating:kt,currentRotation:Ot,hoverState:Qt,isEditing:nt,editText:X,editRichText:ne,cursorPosition:K,selectionStart:Te,selectionEnd:He,cursorOpacityRef:Be,cursorStartTimeRef:Ae,isTouchDevice:ge,selectionHandlePositionsRef:Ke,multiClickSelectionRef:W,lastMultiClickTimeRef:U,MULTI_CLICK_DEBOUNCE:Pe,snapGuides:ht,spacingIndicators:yt,isAltKeyPressed:Rt,multiSelection:s,multiSelectionOBBRef:Ut,multiSelectionGroupBoundsRef:Lt,isMarqueeSelecting:mt,marqueeStart:Bt,marqueeEnd:Wt,marqueePreviewSelection:_t,penTool:Q,handlesVersion:Qe,hideHandles:x,resolvedTheme:G,cursorAnimationFrame:Xe,renderVersion:Ee,pieceGuides:_,focusedPieceId:k&&k!=="spread"?k.pieceId:null,focusedPieceRect:le}),l.useImperativeHandle(B,()=>({applyTextFormatting:Ze=>{cr(Ze)},toggleFormattingProperty:Ze=>{Gn(Ze)},isEditingText:()=>nt,isRotating:()=>kt,getSelectionStyle:()=>dr(),getZoom:()=>C,forceRender:$e,getEditingState:()=>({isEditing:nt,editText:X,cursorPosition:K,selectionStart:Te,selectionEnd:He}),getCropState:()=>({isCropping:ee instanceof T.ImageElement&&ee.isCropping,elementId:(ee==null?void 0:ee.id)||null}),getPaddingOffset:()=>({x:ie,y:pt})}),[cr,Gn,nt,kt,dr,C,$e,X,K,Te,He,ee,ie,pt]);const Wo=l.useMemo(()=>{if(!z||z.length===0)return;const Ze=Ve*C,We=oe*C,Ct=`M 0 0 h ${Ze} v ${We} h ${-Ze} Z`,Et=z.map(It=>{if(It.kind==="rect"||It.kind==="roundedRect"){const Ht=(ie+It.x)*C,qt=(pt+It.y)*C,Pt=It.width*C,St=It.height*C;if(It.kind==="roundedRect"){const lt=(It.rx??It.ry??0)*C,zt=(It.ry??It.rx??0)*C;if(lt>0||zt>0)return[`M ${Ht+lt} ${qt}`,`h ${Pt-2*lt}`,`a ${lt} ${zt} 0 0 1 ${lt} ${zt}`,`v ${St-2*zt}`,`a ${lt} ${zt} 0 0 1 ${-lt} ${zt}`,`h ${-(Pt-2*lt)}`,`a ${lt} ${zt} 0 0 1 ${-lt} ${-zt}`,`v ${-(St-2*zt)}`,`a ${lt} ${zt} 0 0 1 ${lt} ${-zt}`,"Z"].join(" ")}return`M ${Ht} ${qt} h ${Pt} v ${St} h ${-Pt} Z`}return""}).filter(Boolean);if(Et.length!==0)return`path(evenodd, "${Ct} ${Et.join(" ")}")`},[z,Ve,oe,ie,pt,C]);return n.jsxs(n.Fragment,{children:[n.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",style:{position:"absolute",width:1,height:1,margin:-1,padding:0,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",borderWidth:0},children:it}),n.jsx("canvas",{role:"application","aria-label":"Design editor canvas. Use mouse or touch to select, move, and resize elements.",ref:A,onPointerDown:Hn,onPointerMove:$n,onPointerUp:so,onPointerCancel:so,onDoubleClick:Yo,style:{display:"block",background:_?"transparent":"var(--color-canvas-bg)",width:`${Ve*C}px`,height:`${oe*C}px`,cursor:Q.isActive()&&ee instanceof T.PathElement?ze:void 0,position:"absolute",left:`${j}px`,top:`${M}px`,touchAction:"none",clipPath:Wo}}),nt&&(()=>{let Ze=ee;if(Zt.current&&ee instanceof T.GroupElement){const St=ee.children.find(lt=>lt.id===Zt.current);St&&(Ze=St)}const We=Ze instanceof T.TextElement?Ze:null,Ct=(We==null?void 0:We.fontSize)||24,Et=(We==null?void 0:We.fontFamily)||"Arial",It=(We==null?void 0:We.bold)||!1,Ht=(We==null?void 0:We.italic)||!1,qt=(We==null?void 0:We.textAlign)||"center",Pt=n.jsx("textarea",{ref:Z,"data-preserve-selection":"",value:X,onChange:St=>{const lt=St.target.value;if(!ne){const dn=T.RichText.fromPlainText(lt,{});_e.current=dn,fe(dn),Mt(lt);const Kn=St.target.selectionEnd;be(Kn),Ne(St.target.selectionStart),Se(St.target.selectionEnd);return}const zt=X,Pn=ne.clone();let ut=0;for(;ut<zt.length&&ut<lt.length&&zt[ut]===lt[ut];)ut++;let cn=0;for(;cn<zt.length-ut&&cn<lt.length-ut&&zt[zt.length-1-cn]===lt[lt.length-1-cn];)cn++;const fn=ut,jn=zt.length-cn,Fn=lt.substring(ut,lt.length-cn);if(jn>fn&&Pn.delete(fn,jn),Fn.length>0){let dn;Oe?dn=Oe:fn>0?dn=Pn.getStyleAt(fn-1):ee instanceof T.TextElement?dn=ee.getDefaultStyle():dn={},Pn.insert(fn,Fn,dn)}_e.current=Pn,fe(Pn),Mt(lt);const Cn=St.target.selectionEnd;be(Cn),Ne(St.target.selectionStart),Se(St.target.selectionEnd),V.current=Cn;const En=St.target;setTimeout(()=>{En&&document.activeElement===En&&En.setSelectionRange(Cn,Cn)},0)},onBlur:er,onKeyDown:wn,onPointerDown:St=>{if(St.preventDefault(),!ee||!(ee instanceof T.TextElement)||!A.current)return;const lt=Date.now();if(lt-Ie.current<me)return;Ie.current=lt,lt-U.current>=Pe&&(W.current=null);const zt=A.current.getBoundingClientRect(),Pn=(St.clientX-zt.left)/C-ie,ut=(St.clientY-zt.top)/C-pt,cn=ee.getVisualBoundingBox(),fn=ee.getRotationAnchor(),jn=T.RotationUtils.toRadiansInverse(ee.rotation),Fn=Pn-fn.x,Cn=ut-fn.y,En=Math.cos(jn),dn=Math.sin(jn),Kn=Fn*En-Cn*dn,ur=Fn*dn+Cn*En,hr=Kn+cn.width/2,Un=ur+cn.height/2,pn=Xn(ee,{x:hr,y:Un});lt-q.current<we?ae.current+=1:ae.current=1,q.current=lt;const Sn=X;if(xe.current=!1,ae.current>=3)St.preventDefault(),U.current=lt,W.current={start:0,end:Sn.length,cursor:Sn.length},pe.current=!0,ae.current=0,V.current=0,be(Sn.length),Ne(0),Se(Sn.length),Z.current&&(Z.current.focus(),Z.current.setSelectionRange(0,Sn.length));else if(ae.current===2){St.preventDefault();const bn=sl(Sn,pn);U.current=lt,W.current={start:bn.start,end:bn.end,cursor:bn.end},pe.current=!0,V.current=bn.start,be(bn.end),Ne(bn.start),Se(bn.end),Z.current&&(Z.current.focus(),Z.current.setSelectionRange(bn.start,bn.end))}else W.current=null,V.current=pn,Ne(pn),be(pn),Se(pn),Z.current&&(Z.current.focus(),Z.current.setSelectionRange(pn,pn)),pe.current=!1},onPointerMove:St=>{if(St.buttons!==1)return;if(ke.current&&ee instanceof T.TextElement&&A.current){const qn=A.current.getBoundingClientRect(),Sn=(St.clientX-qn.left)/C-ie,bn=(St.clientY-qn.top)/C-pt,Sr=ee.getVisualBoundingBox(),kr=ee.getRotationAnchor(),jr=T.RotationUtils.toRadiansInverse(ee.rotation),io=Sn-kr.x,ao=bn-kr.y,lo=Math.cos(jr),co=Math.sin(jr),Xo=io*lo-ao*co,Vo=io*co+ao*lo,Tn=Ke.current;let Er=0;ke.current==="start"&&(Tn!=null&&Tn.start)?Er=Tn.start.textEdge.y-Tn.start.center.y:ke.current==="end"&&(Tn!=null&&Tn.end)&&(Er=Tn.end.textEdge.y-Tn.end.center.y);const Go=Xo+Sr.width/2,Ko=Vo+Er+Sr.height/2,Rn=Xn(ee,{x:Go,y:Ko});if(ke.current==="start"?Rn<=He?(Ne(Rn),be(Rn)):(Ne(He),Se(Rn),be(Rn),ke.current="end"):Rn>=Te?(Se(Rn),be(Rn)):(Se(Te),Ne(Rn),be(Rn),ke.current="start"),Z.current){const qo=Math.min(Te,He),Zo=Math.max(Te,He);Z.current.setSelectionRange(qo,Zo)}return}if(pe.current||!ee||!(ee instanceof T.TextElement)||!A.current)return;const lt=A.current.getBoundingClientRect(),zt=(St.clientX-lt.left)/C-ie,Pn=(St.clientY-lt.top)/C-pt,ut=ee.getVisualBoundingBox(),cn=ee.getRotationAnchor(),fn=T.RotationUtils.toRadiansInverse(ee.rotation),jn=zt-cn.x,Fn=Pn-cn.y,Cn=Math.cos(fn),En=Math.sin(fn),dn=jn*Cn-Fn*En,Kn=jn*En+Fn*Cn,ur=dn+ut.width/2,hr=Kn+ut.height/2,Un=Xn(ee,{x:ur,y:hr}),pn=V.current;if(pn!==Un&&(xe.current=!0),Se(Un),be(Un),Ne(pn),Z.current){const qn=Math.min(pn,Un),Sn=Math.max(pn,Un);Z.current.setSelectionRange(qn,Sn)}},onPointerUp:()=>{ke.current&&(ke.current=null)},onClick:()=>{xe.current=!1,pe.current=!1},onSelect:()=>{},autoFocus:!0,spellCheck:!1,style:{position:"fixed",left:`${ue.x}px`,top:`${ue.y}px`,width:`${ue.width}px`,height:`${ue.height||50}px`,fontSize:`${Ct*C}px`,fontFamily:`"${Et}", Arial, sans-serif`,fontWeight:It?700:400,fontStyle:Ht?"italic":"normal",textAlign:qt,lineHeight:1.2,opacity:0,zIndex:1001,resize:"none",border:"2px solid transparent",outline:"none",padding:"4px",margin:"0",overflow:"hidden",color:"transparent",background:"transparent",caretColor:"transparent",whiteSpace:"pre-wrap",wordBreak:"normal",overflowWrap:"normal"}});return Qn.createPortal(Pt,document.body)})()]})});ll.displayName="CanvasEditor";const lh=.25,ch=8,dh=.1,uh=4,hh=.001,fh=({className:e,style:t,width:r,height:o,zoom:s,fitPadding:i=.95,interactive:a=!1,artboardBorderRadius:c=0,fixedMargin:d,maxHeight:u,showRotationHandle:h=!0,enableShortcuts:f=!0,canvasCutouts:p,pieceGuides:g,pieceFocus:b})=>{var Ot;const{canvasEditorRef:x,canvasRef:y,elements:v,artboards:w,artboardManager:C,handleElementUpdate:j,setElements:M,executeElementUpdate:S}=Yt.useEditor(),{zoom:R,setZoom:I,panOffset:D,setPanOffset:E,isPanning:O,setIsPanning:z,userZoom:_,setUserZoom:k,resetUserView:Y}=Yt.useViewportContext(),{selectedId:B,multiSelection:G,handleSelectionChange:se,setMultiSelection:A,handleActiveChildChange:Z,setHoveredElementId:J,hideHandles:q}=Yt.useSelectionContext(),{setTextSelectionVersion:ae,setExpandedPanelType:Le}=Yt.useToolStateContext(),pe=l.useCallback(()=>{Le("crop")},[Le]),U=l.useRef(null),[W,Ie]=l.useState(0),[ke,Ke]=l.useState(0),[re,te]=l.useState(!1),he=l.useRef(0),ye=l.useRef(!1),[we,Pe]=l.useState(!1),me=l.useRef(null);ru({enabled:f});const N=C.getActiveArtboard(),ce=l.useCallback(De=>{if(!(a||De.ctrlKey||De.metaKey))return;De.preventDefault();const Ee=U.current;if(!Ee)return;const $e=Ee.getBoundingClientRect(),Qe=De.clientX-$e.left,Fe=De.clientY-$e.top,Ue=-De.deltaY*hh;if(a){const Xe=W,dt=Math.min(Math.max(Xe*(1+Ue),dh),uh);if(dt===Xe)return;const Ye=dt/Xe,vt=Qe-(Qe-D.x)*Ye,gt=Fe-(Fe-D.y)*Ye;Ie(dt),E({x:vt,y:gt})}else{const Xe=_,dt=Math.min(Math.max(Xe*(1+Ue),lh),ch);if(dt===Xe)return;const Ye=dt/Xe,vt=Qe-(Qe-D.x)*Ye,gt=Fe-(Fe-D.y)*Ye;k(dt),E({x:vt,y:gt})}},[a,W,D,E,_,k]);l.useEffect(()=>{const De=U.current;if(De)return De.addEventListener("wheel",ce,{passive:!1}),()=>De.removeEventListener("wheel",ce)},[ce]),l.useEffect(()=>{if(!a)return;const De=Ee=>{Ee.code==="Space"&&!Ee.repeat&&Pe(!0)},je=Ee=>{Ee.code==="Space"&&(Pe(!1),me.current=null)};return window.addEventListener("keydown",De),window.addEventListener("keyup",je),()=>{window.removeEventListener("keydown",De),window.removeEventListener("keyup",je)}},[a]);const le=l.useCallback(De=>{if(!a)return;const je=De.button===1,Ee=we&&De.button===0;(je||Ee)&&(De.preventDefault(),De.target.setPointerCapture(De.pointerId),z(!0),me.current={x:De.clientX,y:De.clientY,panX:D.x,panY:D.y})},[a,we,D,z]),Me=l.useCallback(De=>{if(!O||!me.current)return;const je=De.clientX-me.current.x,Ee=De.clientY-me.current.y;E({x:me.current.panX+je,y:me.current.panY+Ee})},[O,E]),ge=l.useCallback(De=>{O&&(De&&De.target.releasePointerCapture(De.pointerId),z(!1),me.current=null)},[O,z]);l.useEffect(()=>{if(!a||!O)return;const De=()=>{z(!1),me.current=null};return window.addEventListener("pointerup",De),()=>window.removeEventListener("pointerup",De)},[a,O,z]);const L=l.useMemo(()=>{if(!b||!g)return null;const De=g.pieces??[];if(De.length<=1)return null;if(b==="spread")return N?{x:0,y:0,width:N.width,height:N.height}:null;const je=De.find(Ee=>Ee.id===b.pieceId);return je?{x:je.x,y:je.y,width:je.width,height:je.height}:null},[b,g,N]),ve=iu(L);l.useEffect(()=>{if(s!==void 0){Ie(s);return}if(!U.current||!N)return;let De=0;const je=()=>{if(!U.current||!N)return;const Qe=U.current.clientWidth;if(Qe===0)return;let Fe=N.width,Ue=N.height;if(b&&b!=="spread"&&g){const Ye=g.pieces??[];if(Ye.length>1){const vt=Ye.find(gt=>gt.id===b.pieceId);vt&&(Fe=vt.width,Ue=vt.height)}}let Xe,dt=!1;if(d!==void 0){const Ye=Qe-d*2,vt=Math.min(Ye/Fe,1);if(ve&&u!==void 0){const gt=u-d*2,Nt=Math.min(gt/Ue,1);Xe=Math.min(vt,Nt),dt=Nt<=vt}else if(Xe=vt,u!==void 0&&Ue*Xe+d*2>u){const $=(u-d*2)/Ue;Xe=Math.min(Xe,$,1),dt=!0}}else Xe=Math.min(Qe*i/Fe,1);Ie(Xe),Ke(Qe),te(dt)};let Ee=!1;ye.current?je():De=requestAnimationFrame(()=>{De=requestAnimationFrame(()=>{Ee||(je(),ye.current=!0)})});const $e=new ResizeObserver(()=>{je()});return $e.observe(U.current),()=>{Ee=!0,cancelAnimationFrame(De),$e.disconnect()}},[s,N,i,d,u,b,g,ve]);const tt=W>0&&_>0?W*_:W;l.useEffect(()=>{he.current=tt,I(tt)},[tt,I]);const Ve=l.useRef(null);l.useEffect(()=>{const De=ve&&"id"in ve?ve.id??null:null;De!==Ve.current&&(Ve.current!==null&&Y(),Ve.current=De)},[ve,Y]),l.useEffect(()=>{a&&R!==he.current&&R>0&&(Ie(R),he.current=R)},[a,R]);const oe=ve?ve.width:(N==null?void 0:N.width)??0,ie=ve?ve.height:(N==null?void 0:N.height)??0,pt=oe*tt,st=ie*tt,ht=oe*W;let bt=N?d!==void 0?st+d*2:st/i:0;u!==void 0&&bt>u&&(bt=u);let yt=d,Tt=d;const Rt=((Ot=U.current)==null?void 0:Ot.clientWidth)||ke;d!==void 0&&re&&Rt>0&&ht>0&&(yt=(Rt-ht)/2);const jt=bt,kt=l.useRef({w:0,h:0});l.useEffect(()=>{const De=U.current;if(!De)return;kt.current={w:De.clientWidth,h:De.clientHeight};const je=new ResizeObserver(Ee=>{const $e=Ee[0];$e&&(kt.current={w:$e.contentRect.width,h:$e.contentRect.height})});return je.observe(De),()=>je.disconnect()},[]),l.useEffect(()=>{if(a)return;if(_<=1.001){(D.x!==0||D.y!==0)&&E({x:0,y:0});return}const De=kt.current.w,je=kt.current.h;if(De===0||je===0||pt===0||st===0)return;const Ee=.25*Math.min(pt,De),$e=.25*Math.min(st,je),Qe=Ee-(yt??0)-pt,Fe=De-Ee-(yt??0),Ue=$e-(Tt??0)-st,Xe=je-$e-(Tt??0),dt=Math.max(Qe,Math.min(Fe,D.x)),Ye=Math.max(Ue,Math.min(Xe,D.y));(dt!==D.x||Ye!==D.y)&&E({x:dt,y:Ye})},[a,_,D,pt,st,yt,Tt,E]);const Kt=a?{position:"relative",width:r?`${r}px`:"100%",height:o?`${o}px`:"100%",overflow:"hidden",cursor:O?"grabbing":we?"grab":"default",touchAction:"none",overscrollBehaviorX:"none",...t}:{position:"relative",width:r?`${r}px`:"100%",height:o?`${o}px`:jt>0?`${jt}px`:"auto",overflow:"hidden",touchAction:"none",overscrollBehaviorX:"none",...t},$t=a?{position:"absolute",left:0,top:0,transform:`translate(${D.x}px, ${D.y}px)`,transformOrigin:"0 0",pointerEvents:O?"none":"auto"}:{transform:D.x!==0||D.y!==0?`translate(${D.x}px, ${D.y}px)`:void 0,transformOrigin:"0 0",willChange:D.x!==0||D.y!==0?"transform":void 0};return n.jsxs("div",{ref:U,className:e,style:Kt,onPointerDown:a?le:void 0,onPointerMove:a?Me:void 0,onPointerUp:a?ge:void 0,onPointerLeave:a?ge:void 0,onPointerCancel:a?ge:void 0,children:[n.jsx("div",{style:$t,children:n.jsx(ll,{ref:x,elements:v,artboards:w,artboardManager:C,selectedId:B,multiSelection:G,onElementUpdate:j,setElements:M,executeElementUpdate:S,onSelectionChange:se,onMultiSelectionChange:A,onActiveChildChange:Z,onTextSelectionChange:()=>ae(De=>De+1),onHoverChange:J,onCropModeEnter:pe,hideHandles:q,canvasRef:y,width:N==null?void 0:N.width,height:N==null?void 0:N.height,zoom:tt,viewPadding:i,artboardBorderRadius:c,fixedMargin:d,fixedMarginX:yt,fixedMarginY:Tt,showRotationHandle:h,canvasCutouts:p,pieceGuides:g,pieceFocus:b,focusedPieceRect:ve})}),!a&&(_<.999||_>1.001)&&n.jsx(mh,{userZoom:_,onSetZoom:De=>{if(De<=1.001){Y();return}const je=U.current;if(!je){k(De);return}const Ee=je.getBoundingClientRect(),$e=Ee.width/2,Qe=Ee.height/2,Fe=De/Math.max(_,1e-4);k(De),E({x:$e-($e-D.x)*Fe,y:Qe-(Qe-D.y)*Fe})}})]})},ph=[1,2,4,8];function mh({userZoom:e,onSetZoom:t}){const r=Math.round(e*100),[o,s]=l.useState(!1);return n.jsxs("div",{style:{position:"absolute",bottom:12,right:12,zIndex:30,pointerEvents:"auto"},"data-preserve-selection":!0,children:[o&&n.jsxs(n.Fragment,{children:[n.jsx("div",{onClick:()=>s(!1),style:{position:"fixed",inset:0,zIndex:29}}),n.jsx("div",{role:"menu",style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:31,minWidth:96,backdropFilter:"blur(6px)"},className:"flex flex-col rounded-2xl border border-border/40 bg-popover/95 p-1 shadow-lg",children:ph.map(i=>{const a=i*100,c=Math.abs(e-i)<.05;return n.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{s(!1),t(i)},className:c?"rounded-xl bg-foreground/10 px-4 py-2 text-base font-medium tabular-nums text-foreground text-right":"rounded-xl px-4 py-2 text-base font-medium tabular-nums text-foreground/80 hover:bg-foreground/5 hover:text-foreground text-right",children:[a,"%"]},i)})})]}),n.jsx("div",{className:"flex items-center gap-1 rounded-full border border-border/40 bg-popover/85 p-1 shadow-sm",style:{backdropFilter:"blur(6px)"},children:n.jsxs("button",{type:"button",onClick:()=>s(i=>!i),"aria-haspopup":"menu","aria-expanded":o,"aria-label":"Zoom level",className:"rounded-full px-4 py-1.5 text-base font-medium tabular-nums text-foreground/80 hover:text-foreground",style:{minWidth:72},children:[r,"%"]})})]})}const Jr=new Map;function Gt(e,t){Jr.set(e,t)}function gh(e){return Jr.get(e)}function xh(){return Array.from(Jr.keys())}function bh(){return Array.from(Jr.entries())}function yh(e){Jr.delete(e)}let jo=!1;async function vh(){if(jo)return;jo=!0;const[{LayersPanel:e},{EffectsPanel:t},{ExportPanel:r},{ImagePanel:o},{GlyphPanel:s},{ArtboardTabs:i},{ContextualToolbars:a},{ZoomControls:c},{MenuButton:d},{CropPanel:u}]=await Promise.all([Promise.resolve().then(()=>bp),Promise.resolve().then(()=>cm),Promise.resolve().then(()=>um),Promise.resolve().then(()=>Em),Promise.resolve().then(()=>Nm),Promise.resolve().then(()=>Mm),Promise.resolve().then(()=>Ag),Promise.resolve().then(()=>Dg),Promise.resolve().then(()=>Lg),Promise.resolve().then(()=>Jm)]);Gt("layers-panel",{component:e,label:"Layers",icon:"gravity-ui:layers",position:"left"}),Gt("effects-panel",{component:t,label:"Effects",icon:"gravity-ui:sparkles",position:"right"}),Gt("export-panel",{component:r,label:"Export",icon:"gravity-ui:arrow-down-to-square",position:"right"}),Gt("images-panel",{component:o,label:"Images",icon:"gravity-ui:picture",position:"right"}),Gt("glyph-panel",{component:s,label:"Glyphs",icon:"gravity-ui:text",position:"right"}),Gt("artboard-tabs",{component:i,label:"Artboards",icon:"gravity-ui:copy",position:"topbar"}),Gt("contextual-toolbar",{component:a,label:"Contextual Toolbar",position:"topbar"}),Gt("zoom-controls",{component:c,label:"Zoom",icon:"gravity-ui:magnifier",position:"bottombar"}),Gt("menu-button",{component:d,label:"Menu",icon:"gravity-ui:bars",position:"topbar"}),Gt("crop-panel",{component:u,label:"Crop",icon:"gravity-ui:scissors",position:"right"})}function wh(e){jo||(jo=!0,Gt("layers-panel",{component:e.LayersPanel,label:"Layers",icon:"gravity-ui:layers",position:"left"}),Gt("effects-panel",{component:e.EffectsPanel,label:"Effects",icon:"gravity-ui:sparkles",position:"right"}),Gt("export-panel",{component:e.ExportPanel,label:"Export",icon:"gravity-ui:arrow-down-to-square",position:"right"}),Gt("images-panel",{component:e.ImagePanel,label:"Images",icon:"gravity-ui:picture",position:"right"}),Gt("glyph-panel",{component:e.GlyphPanel,label:"Glyphs",icon:"gravity-ui:text",position:"right"}),Gt("artboard-tabs",{component:e.ArtboardTabs,label:"Artboards",icon:"gravity-ui:copy",position:"topbar"}),Gt("contextual-toolbar",{component:e.ContextualToolbars,label:"Contextual Toolbar",position:"topbar"}),Gt("zoom-controls",{component:e.ZoomControls,label:"Zoom",icon:"gravity-ui:magnifier",position:"bottombar"}),Gt("menu-button",{component:e.MenuButton,label:"Menu",icon:"gravity-ui:bars",position:"topbar"}),Gt("crop-panel",{component:e.CropPanel,label:"Crop",icon:"gravity-ui:scissors",position:"right"}))}const ss=T.createLogger("useArtboards"),Qr=()=>{const{artboards:e,artboardManager:t,refreshArtboards:r,setSelectedId:o,setMultiSelection:s}=Yt.useEditor(),i=t.getActiveArtboardId(),a=t.getActiveArtboard(),c=l.useMemo(()=>e.map(y=>{const w=t.getElementsOnArtboard(y.id).length;return{id:y.id,name:y.name,x:y.x,y:y.y,width:y.width,height:y.height,backgroundColor:y.backgroundColor,clipShape:y.clipShape,isActive:y.id===i,elementCount:w}}),[e,t,i]),d=l.useMemo(()=>{if(!a)return null;const v=t.getElementsOnArtboard(a.id).length;return{id:a.id,name:a.name,x:a.x,y:a.y,width:a.width,height:a.height,backgroundColor:a.backgroundColor,clipShape:a.clipShape,isActive:!0,elementCount:v}},[a,t]),u=l.useCallback((y=1200,v=1200,w)=>{const C={width:y,height:v,...w};t.createArtboard(C),r()},[t,r]),h=l.useCallback(y=>{t.deleteArtboard(y),r()},[t,r]),f=l.useCallback(y=>{const v=e.find(w=>w.id===y);if(!v){ss.warn(`[useArtboards] Artboard ${y} not found`);return}t.createArtboard({width:v.width,height:v.height,name:`${v.name} Copy`,backgroundColor:v.backgroundColor,clipShape:v.clipShape}),r()},[e,t,r]),p=l.useCallback((y,v)=>{const w=e.find(C=>C.id===y);if(!w){ss.warn(`[useArtboards] Artboard ${y} not found`);return}w.name=v,r()},[e,r]),g=l.useCallback((y,v)=>{const w=e.find(C=>C.id===y);if(!w){ss.warn(`[useArtboards] Artboard ${y} not found`);return}v.name!==void 0&&(w.name=v.name),v.width!==void 0&&(w.width=v.width),v.height!==void 0&&(w.height=v.height),v.backgroundColor!==void 0&&(w.backgroundColor=v.backgroundColor),v.clipShape!==void 0&&(w.clipShape=v.clipShape),"distressTexture"in v&&(w.distressTexture=v.distressTexture?{...v.distressTexture}:void 0),r()},[e,r]),b=l.useCallback(y=>{o(null),s([]),t.setActiveArtboard(y),r()},[t,r,o,s]),x=l.useCallback((y,v)=>{y!==v&&(y<0||y>=e.length||v<0||v>=e.length||([...e],t.reorderArtboards(y,v),r()))},[e,t,r]);return{artboards:e,artboardsInfo:c,activeArtboard:a,activeArtboardId:i,activeArtboardInfo:d,createArtboard:u,deleteArtboard:h,duplicateArtboard:f,renameArtboard:p,updateArtboard:g,selectArtboard:b,reorderArtboards:x,count:e.length}},Lo=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function wr(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function ni(e){return"nodeType"in e}function gn(e){var t,r;return e?wr(e)?e:ni(e)&&(t=(r=e.ownerDocument)==null?void 0:r.defaultView)!=null?t:window:window}function ri(e){const{Document:t}=gn(e);return e instanceof t}function eo(e){return wr(e)?!1:e instanceof gn(e).HTMLElement}function cl(e){return e instanceof gn(e).SVGElement}function Cr(e){return e?wr(e)?e.document:ni(e)?ri(e)?e:eo(e)||cl(e)?e.ownerDocument:document:document:document}const Vn=Lo?l.useLayoutEffect:l.useEffect;function Po(e){const t=l.useRef(e);return Vn(()=>{t.current=e}),l.useCallback(function(){for(var r=arguments.length,o=new Array(r),s=0;s<r;s++)o[s]=arguments[s];return t.current==null?void 0:t.current(...o)},[])}function Ch(){const e=l.useRef(null),t=l.useCallback((o,s)=>{e.current=setInterval(o,s)},[]),r=l.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,r]}function Wr(e,t){t===void 0&&(t=[e]);const r=l.useRef(e);return Vn(()=>{r.current!==e&&(r.current=e)},t),r}function to(e,t){const r=l.useRef();return l.useMemo(()=>{const o=e(r.current);return r.current=o,o},[...t])}function Eo(e){const t=Po(e),r=l.useRef(null),o=l.useCallback(s=>{s!==r.current&&(t==null||t(s,r.current)),r.current=s},[]);return[r,o]}function To(e){const t=l.useRef();return l.useEffect(()=>{t.current=e},[e]),t.current}let is={};function Fo(e,t){return l.useMemo(()=>{if(t)return t;const r=is[e]==null?0:is[e]+1;return is[e]=r,e+"-"+r},[e,t])}function dl(e){return function(t){for(var r=arguments.length,o=new Array(r>1?r-1:0),s=1;s<r;s++)o[s-1]=arguments[s];return o.reduce((i,a)=>{const c=Object.entries(a);for(const[d,u]of c){const h=i[d];h!=null&&(i[d]=h+e*u)}return i},{...t})}}const yr=dl(1),Xr=dl(-1);function Sh(e){return"clientX"in e&&"clientY"in e}function oi(e){if(!e)return!1;const{KeyboardEvent:t}=gn(e.target);return t&&e instanceof t}function kh(e){if(!e)return!1;const{TouchEvent:t}=gn(e.target);return t&&e instanceof t}function Ro(e){if(kh(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:r}=e.touches[0];return{x:t,y:r}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:r}=e.changedTouches[0];return{x:t,y:r}}}return Sh(e)?{x:e.clientX,y:e.clientY}:null}const Vr=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:r}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(r?Math.round(r):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:r}=e;return"scaleX("+t+") scaleY("+r+")"}},Transform:{toString(e){if(e)return[Vr.Translate.toString(e),Vr.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:r,easing:o}=e;return t+" "+r+"ms "+o}}}),ta="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function jh(e){return e.matches(ta)?e:e.querySelector(ta)}const Eh={display:"none"};function Th(e){let{id:t,value:r}=e;return l.createElement("div",{id:t,style:Eh},r)}function Rh(e){let{id:t,announcement:r,ariaLiveType:o="assertive"}=e;const s={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return l.createElement("div",{id:t,style:s,role:"status","aria-live":o,"aria-atomic":!0},r)}function Nh(){const[e,t]=l.useState("");return{announce:l.useCallback(o=>{o!=null&&t(o)},[]),announcement:e}}const ul=l.createContext(null);function Mh(e){const t=l.useContext(ul);l.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function Ih(){const[e]=l.useState(()=>new Set),t=l.useCallback(o=>(e.add(o),()=>e.delete(o)),[e]);return[l.useCallback(o=>{let{type:s,event:i}=o;e.forEach(a=>{var c;return(c=a[s])==null?void 0:c.call(a,i)})},[e]),t]}const Ah={draggable:`
12
+ `.trim(),c=`data:image/svg+xml,${encodeURIComponent(i)}`;o(`url('${c}') 0 0, crosshair`)}catch(s){fu.error("Failed to create pen cursor:",s),o("crosshair")}},[]),l.useEffect(()=>{e instanceof T.PathElement&&e.transformData.points.length===0&&!t.isActive()&&t.startPath(e)},[e,t]),{penTool:t,penCursor:r}}function mu({elements:e,selectedElement:t,transformHandles:r,onActiveChildChange:o}){const[s,i]=l.useState(null),a=l.useRef(null),c=l.useCallback(d=>{i(d),o==null||o(d)},[o]);return l.useEffect(()=>{if(s&&t instanceof T.GroupElement){const d=t.children.find(u=>u.id===s.id);d&&d!==s&&(d instanceof T.GroupElement||(i(d),o==null||o(d),r.update(d)))}},[e,s,t,r,o]),{activeChildElement:s,setActiveChildElement:i,updateActiveChild:c,editingChildIdRef:a}}function gu({onHoverChange:e}){const[t,r]=l.useState({type:null,data:null,startTime:null}),o=l.useCallback(s=>{r(i=>{var c,d,u,h;const a=s.type!==i.type||s.type==="element"&&((c=s.data)==null?void 0:c.id)!==((d=i.data)==null?void 0:d.id)||s.type==="group-sibling"&&((u=s.data)==null?void 0:u.id)!==((h=i.data)==null?void 0:h.id);return{...s,startTime:a&&s.type!==null?performance.now():i.startTime}})},[]);return l.useEffect(()=>{if(!e)return;let s=null;if(t.type==="element"||t.type==="group-sibling"){const i=t.data;s=(i==null?void 0:i.id)??null}e(s)},[t,e]),{hoverState:t,setHoverState:o}}class ni{constructor(t,r,o,s,i){this.x=t,this.y=r,this.rotation=o,this.flipH=s,this.flipV=i}worldToLocal(t,r){const o=t-this.x,s=r-this.y,i=T.RotationUtils.toRadiansInverse(this.rotation),a=Math.cos(i),c=Math.sin(i);let d=o*a+s*c,u=-o*c+s*a;return this.flipH&&(d=-d),this.flipV&&(u=-u),{x:d,y:u}}localToWorld(t,r){let o=this.flipH?-t:t,s=this.flipV?-r:r;const i=T.RotationUtils.toRadians(this.rotation),a=Math.cos(i),c=Math.sin(i),d=o*a-s*c,u=o*c+s*a;return{x:d+this.x,y:u+this.y}}transformVector(t,r,o=!1){let s=this.flipH?-t:t,i=this.flipV?-r:r;const a=o?T.RotationUtils.toRadiansInverse(this.rotation):T.RotationUtils.toRadians(this.rotation),c=Math.cos(a),d=Math.sin(a);return o?{dx:s*c+i*d,dy:-s*d+i*c}:{dx:s*c-i*d,dy:s*d+i*c}}static fromElement(t){return new ni(t.x,t.y,t.rotation||0,t.flipH||!1,t.flipV||!1)}}class xu{handleCropImageDrag(t,r,o,s){const i=o-r.startX,a=s-r.startY,c=r.startData.x,d=r.startData.y,u=r.startData.transformData,h=u.width,f=u.height,p=r.startData.cropX??0,g=r.startData.cropY??0,b=r.startData.cropWidth??1,x=r.startData.cropHeight??1,v=T.Transform.fromSnapshot(r.startData).worldDeltaToLocal(i,a);let w=v.dx,C=v.dy;const j=u.flipHorizontal?-1:1,M=u.flipVertical?-1:1;w*=j,C*=M;const S=-w/h,R=-C/f;let I=p+S,D=g+R;const E=1-b,O=1-x;return I=Math.max(0,Math.min(E,I)),D=Math.max(0,Math.min(O,D)),{cropX:I,cropY:D,cropWidth:b,cropHeight:x,x:c,y:d}}handleCropBoxResize(t,r,o,s,i,a){const c=o.startData.transformData,d=c.flipHorizontal,u=c.flipVertical,h=this._getCropResizeCursor(r,!!d,!!u),f=o.startData.rotation,p=o.startData.x,g=o.startData.y,b=T.Transform.fromSnapshot(o.startData),{cos:x,sin:y}=b.getInverseCosSin(),v=d?-1:1,w=u?-1:1,C=i-p,j=a-g;let M=C*x-j*y,S=C*y+j*x;M*=v,S*=w;const R=s.startX-p,I=s.startY-g;let D=R*x-I*y,E=R*y+I*x;D*=v,E*=w;const O=M-D,z=S-E,B=c.cropX,k=c.cropY,Y=c.cropWidth,_=c.cropHeight,G=c.width,se=c.height,A=O/G,Z=z/se,J=this._calculateNewCropValues(r,B,k,Y,_,A,Z),q=this._calculateCropCenterOffset(B,k,Y,_,J.cropX,J.cropY,J.cropWidth,J.cropHeight,G,se,f,v,w);return{...J,x:p+q.worldOffsetX,y:g+q.worldOffsetY,rotation:f,width:G,height:se,cursor:h}}_getCropResizeCursor(t,r,o){let s=t;return r&&(s.includes("left")?s=s.replace("left","right"):s.includes("right")&&(s=s.replace("right","left"))),o&&(s.includes("top")?s=s.replace("top","bottom"):s.includes("bottom")&&(s=s.replace("bottom","top"))),s==="top-left"||s==="bottom-right"?"nwse-resize":s==="top-right"||s==="bottom-left"?"nesw-resize":s==="top"||s==="bottom"?"ns-resize":s==="left"||s==="right"?"ew-resize":"default"}_calculateNewCropValues(t,r,o,s,i,a,c){const d=T.MIN_CROP_SIZE;let u=r,h=o,f=s,p=i;return t==="top-left"?(u=r+a,h=o+c,f=s-a,p=i-c):t==="top-right"?(h=o+c,f=s+a,p=i-c):t==="bottom-left"?(u=r+a,f=s-a,p=i+c):t==="bottom-right"?(f=s+a,p=i+c):t==="top"?(h=o+c,p=i-c):t==="bottom"?p=i+c:t==="left"?(u=r+a,f=s-a):t==="right"&&(f=s+a),this._constrainCropValues(t,u,h,f,p,r,o,s,i,d)}_constrainCropValues(t,r,o,s,i,a,c,d,u,h){let f=r,p=o,g=s,b=i;return g<h&&(g=h,t.includes("left")&&(f=a+d-h)),f+g>1&&(t.includes("left")?f=1-g:g=1-f),f<0&&(g=g+f,f=0),b<h&&(b=h,t.includes("top")&&(p=c+u-h)),p+b>1&&(t.includes("top")?p=1-b:b=1-p),p<0&&(b=b+p,p=0),{cropX:f,cropY:p,cropWidth:g,cropHeight:b}}_calculateCropCenterOffset(t,r,o,s,i,a,c,d,u,h,f,p,g){const b=t*u+o*u/2,x=r*h+s*h/2,y=i*u+c*u/2,v=a*h+d*h/2;let w=y-b,C=v-x;w*=p,C*=g;const M=new T.Transform({rotation:f,x:0,y:0}).localDeltaToWorld(w,C),S=M.dx,R=M.dy;return{worldOffsetX:S,worldOffsetY:R}}getCropBoxHandlePosition(t,r){const o=ni.fromElement(t),s=t.transformData,i=s.width,a=s.height,c=s.cropX||0,d=s.cropY||0,u=s.cropWidth||1,h=s.cropHeight||1;let f=0,p=0;return r.includes("left")?f=(c-.5)*i:r.includes("right")?f=(c+u-.5)*i:f=(c+u/2-.5)*i,r.includes("top")?p=(d-.5)*a:r.includes("bottom")?p=(d+h-.5)*a:p=(d+h/2-.5)*a,o.localToWorld(f,p)}}function bu(){const[e]=l.useState(()=>new xu);return{cropController:e}}function yu(e){const t=l.useRef(null),r=l.useRef(null);return l.useEffect(()=>{r.current=null},[e]),{multiSelectionGroupBoundsRef:t,multiSelectionOBBRef:r}}function qi(e){return e!=null&&e instanceof T.TextElement}function vu({selectedElement:e,ref:t}){const[r,o]=l.useState(!1),[s,i]=l.useState(""),[a,c]=l.useState({x:0,y:0,width:200,height:50}),[d,u]=l.useState(0),[h,f]=l.useState(0),[p,g]=l.useState(0),b=l.useRef(1),x=l.useRef(performance.now()),y=l.useRef(0),v=l.useRef(!1),[w,C]=l.useState(null),[j,M]=l.useState(null),S=l.useRef(null),R=l.useCallback(E=>{if(!r||!w)return;const O=Math.min(h,p),z=Math.max(h,p);if(O===z){const B=w.clone(),k=B.getText().length;B.applyStyle(0,k,E),S.current=B,C(B),i(B.getText()),M(Y=>({...Y,...E}))}else{const B=w.clone();B.applyStyle(O,z,E),S.current=B,C(B),i(B.getText()),M(k=>({...k,...E}))}},[r,w,h,p]),I=l.useCallback(()=>{if(!r||!w||!e)return null;const E=Math.min(h,p),O=Math.max(h,p);return E===O?E===0?qi(e)?e.getDefaultStyle():{}:w.getStyleAt(Math.max(0,E-1)):w.getStyleAt(E)},[r,w,h,p,e]),D=l.useCallback(E=>{if(!r||!w||!e)return;const O=I(),k=!{...qi(e)?e.getDefaultStyle():{},...O}[E];R({[E]:k})},[r,w,e,I,R]);return l.useImperativeHandle(t,()=>({applyTextFormatting:E=>{R(E)},toggleFormattingProperty:E=>{D(E)},isEditingText:()=>r,getSelectionStyle:()=>I()}),[R,D,r,I]),{isEditing:r,setIsEditing:o,editText:s,setEditText:i,editPosition:a,setEditPosition:c,cursorPosition:d,setCursorPosition:u,selectionStart:h,setSelectionStart:f,selectionEnd:p,setSelectionEnd:g,cursorOpacityRef:b,cursorStartTimeRef:x,selectionAnchorRef:y,didDragSelectRef:v,editRichText:w,setEditRichText:C,editRichTextRef:S,currentFormattingStyle:j,setCurrentFormattingStyle:M,applyFormattingToSelection:R,getSelectionStyle:I,toggleFormattingProperty:D}}function wu({width:e,height:t,zoom:r,viewPadding:o,artboardBorderRadius:s,fixedMargin:i,fixedMarginX:a,fixedMarginY:c,artboards:d,artboardManager:u,focusedPieceRect:h}){const[f,p]=l.useState(!1);l.useEffect(()=>{const z="ontouchstart"in window||navigator.maxTouchPoints>0;p(z)},[]);const g=l.useRef(null);l.useEffect(()=>{const z=B=>{g.current=B.target,setTimeout(()=>{g.current=null},500)};return document.addEventListener("touchstart",z,{capture:!0,passive:!0}),document.addEventListener("pointerdown",z,{capture:!0,passive:!0}),()=>{document.removeEventListener("touchstart",z,{capture:!0}),document.removeEventListener("pointerdown",z,{capture:!0})}},[]);const[b,x]=l.useState({width:e??window.innerWidth,height:t??window.innerHeight});l.useEffect(()=>{if(h){x({width:h.width,height:h.height});return}if(e!==void 0&&t!==void 0){x({width:e,height:t});return}const z=u.getActiveArtboard();z&&x({width:z.width,height:z.height})},[e,t,d,u,h]),l.useEffect(()=>{const z=()=>{if(h){x({width:h.width,height:h.height});return}if(e===void 0&&t===void 0){const B=u.getActiveArtboard();x(B?{width:B.width,height:B.height}:{width:window.innerWidth,height:window.innerHeight})}};return window.addEventListener("resize",z),()=>window.removeEventListener("resize",z)},[e,t,u,h]);const y=Math.max(.1,Math.min(1,o)),v=a??i,w=c??i,C=v!==void 0&&r>0?v/r:0,j=w!==void 0&&r>0?w/r:0,M=v!==void 0?b.width+C*2:b.width/y,S=w!==void 0?b.height+j*2:b.height/y,R=v!==void 0?C:(M-b.width)/2,I=w!==void 0?j:(S-b.height)/2,D=h?R-h.x:R,E=h?I-h.y:I,O=r>0?s/r:s;return{isTouchDevice:f,canvasSize:b,lastTouchTargetRef:g,effectiveViewPadding:y,paddedCanvasWidth:M,paddedCanvasHeight:S,paddingOffsetX:D,paddingOffsetY:E,zoomInvariantBorderRadius:O}}function Cu(){const[e,t]=l.useState([]),[r,o]=l.useState([]),[s,i]=l.useState(!1),[a,c]=l.useState(!1),[d,u]=l.useState(0),[h,f]=l.useState(0),[,p]=l.useState(0);return{snapGuides:e,setSnapGuides:t,spacingIndicators:r,setSpacingIndicators:o,isAltKeyPressed:s,setIsAltKeyPressed:i,isRotating:a,setIsRotating:c,setRotationStartAngle:u,currentRotation:h,setCurrentRotation:f,setRotatingElementVersion:p}}function Su({elements:e}){const[,t]=l.useState({}),[r,o]=l.useState(0),[s,i]=l.useState(0),[a,c]=l.useState(0),d=l.useCallback(()=>{i(u=>u+1)},[]);return l.useEffect(()=>T.subscribeToImageLoads(h=>{e.some(p=>p.id===h)&&i(p=>p+1)}),[e]),{renderVersion:s,forceRender:d,handlesVersion:r,setHandlesVersion:o,forceUpdate:t,cursorAnimationFrame:a,setCursorAnimationFrame:c}}const Ir={bleedMode:"gradient",bleedInnerEdge:"boundary",bleedFill:"#000000",bleedOpacity:1,dieCutMode:"blur-tint",dieCutTint:"#333",dieCutTintAlpha:.7,dieCutBlurPx:4,dieCutStroke:"",dieCutStrokeWidthPx:1,bleedBlurScale:.04,boundaryStroke:"",boundaryStrokeWidthPx:1,safeAreaStroke:"",safeAreaStrokeWidthPx:1.5,safeAreaDashPx:[6,4],zoneFill:{wrap:"rgba(148, 163, 184, 0.25)",binding:"rgba(234, 88, 12, 0.20)",dieCut:"rgba(0, 0, 0, 0.7)",warning:"rgba(245, 158, 11, 0.25)",custom:"rgba(100, 100, 100, 0.15)"},zoneStroke:{wrap:"#64748b",binding:"#ea580c",dieCut:"#ffffff",warning:"#f59e0b",custom:"#6b7280"},labelColor:"#111827",labelFontSizePx:14,labelFontFamily:"ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, sans-serif",labelHaloColor:"#ffffff"};let Zn=null;function ku(e){const t=e.width,r=e.height;if(t<=0||r<=0)return null;Zn||(Zn=document.createElement("canvas")),Zn.width!==t&&(Zn.width=t),Zn.height!==r&&(Zn.height=r);const o=Zn.getContext("2d");return o?(o.setTransform(1,0,0,1,0,0),o.clearRect(0,0,t,r),o.drawImage(e,0,0),Zn):null}function os(e,t){const r=e.trim();if(!r.startsWith("var("))return r;const o=r.slice(4,-1),[s,...i]=o.split(","),a=s.trim(),c=i.length>0?i.join(",").trim():"",d=t??document.documentElement;return getComputedStyle(d).getPropertyValue(a).trim()||c||"#333"}function ju(e){if(typeof document>"u")return!1;const t=document.documentElement;return!!(t.classList.contains("dark")||t.getAttribute("data-theme")==="dark")}function Zi(e){const t=hl(e);return t!==null&&t<.5}function Ji(e){const t=hl(e);return t!==null&&t>=.5}function hl(e){const t=e.trim();if(t.startsWith("#")){const o=t.slice(1);let s,i,a;if(o.length===3)s=parseInt(o[0]+o[0],16),i=parseInt(o[1]+o[1],16),a=parseInt(o[2]+o[2],16);else if(o.length===6)s=parseInt(o.slice(0,2),16),i=parseInt(o.slice(2,4),16),a=parseInt(o.slice(4,6),16);else return null;return Number.isNaN(s)||Number.isNaN(i)||Number.isNaN(a)?null:Qi(s,i,a)}const r=t.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/);return r?Qi(Number(r[1]),Number(r[2]),Number(r[3])):null}function Qi(e,t,r){const o=s=>{const i=s/255;return i<=.03928?i/12.92:Math.pow((i+.055)/1.055,2.4)};return .2126*o(e)+.7152*o(t)+.0722*o(r)}function Zr(e,t){if(t.kind==="rect"){e.rect(t.x,t.y,t.width,t.height);return}if(t.kind==="roundedRect"){const o=t.rx??t.ry??0,s=t.ry??t.rx??0;if(o<=0&&s<=0){e.rect(t.x,t.y,t.width,t.height);return}o===s?e.roundRect(t.x,t.y,t.width,t.height,o):e.roundRect(t.x,t.y,t.width,t.height,[{x:o,y:s}]);return}const r=new Path2D(t.d);e.__pieceGuidePath2D=r}function Yr(e,t,r){if(t.kind==="path"){const o=new Path2D(t.d);e.fill(o);return}e.beginPath(),Zr(e,t),e.fill()}function Fr(e,t){if(t.kind==="path"){const r=new Path2D(t.d);e.stroke(r);return}e.beginPath(),Zr(e,t),e.stroke()}function Eu(e,t){t.kind!=="path"&&Zr(e,t)}function ko(e,t){if(t.kind==="rect"){e.rect(t.x,t.y,t.width,t.height);return}if(t.kind==="roundedRect"){const r=t.rx??t.ry??0,o=t.ry??t.rx??0;if(r<=0&&o<=0){e.rect(t.x,t.y,t.width,t.height);return}r===o?e.roundRect(t.x,t.y,t.width,t.height,r):e.roundRect(t.x,t.y,t.width,t.height,[{x:r,y:o}]);return}e.addPath(new Path2D(t.d))}function Tu(e,t,r){return(e==null?void 0:e.boundary)??{kind:"rect",x:0,y:0,width:t,height:r}}function Ru(e,t,r,o){if(e!=null&&e.safeArea)return e.safeArea;if(t.safeAreaInsetPx&&t.safeAreaInsetPx>0){const s=t.safeAreaInsetPx;return{kind:"rect",x:s,y:s,width:Math.max(0,r-s*2),height:Math.max(0,o-s*2)}}return null}function fl(e){var v,w,C,j,M,S,R;const{ctx:t,pieces:r,pieceGuides:o,artboardOrigin:s,zoom:i}=e;if(!r.length)return;const a={bleed:((v=e.show)==null?void 0:v.bleed)??!0,zones:((w=e.show)==null?void 0:w.zones)??!0,boundary:((C=e.show)==null?void 0:C.boundary)??!0,safeArea:((j=e.show)==null?void 0:j.safeArea)??!0,labels:((M=e.show)==null?void 0:M.labels)??!0},c=t.canvas,d=c instanceof HTMLCanvasElement?c:null,u=ju(),f={...{...Ir,bleedFill:u?"#ffffff":"#000000"},...e.style};f.zoneFill={...Ir.zoneFill,...((S=e.style)==null?void 0:S.zoneFill)??{}},f.zoneStroke={...Ir.zoneStroke,...((R=e.style)==null?void 0:R.zoneStroke)??{}};let p=os(f.bleedFill,d);const g=os(f.dieCutTint,d);let b=os(f.boundaryStroke,d);u&&Zi(p)?p="#ffffff":!u&&Ji(p)&&(p="#000000"),u&&Zi(b)?b="#ffffff":!u&&Ji(b)&&(b="#000000");const y=r.some(I=>{var D;return(((D=o==null?void 0:o[I.id])==null?void 0:D.zones)??[]).some(E=>E.kind==="dieCut")})&&d?ku(d):null;t.save(),t.translate(s.x,s.y);for(const I of r){if(e.focusedPieceId!=null&&I.id!==e.focusedPieceId)continue;const D=o==null?void 0:o[I.id],E=(D==null?void 0:D.zones)??[],O=(D==null?void 0:D.labels)??[];t.save(),t.translate(I.x,I.y);const z=I.rotation??0;z===90?(t.translate(I.width,0),t.rotate(Math.PI/2)):z===180?(t.translate(I.width,I.height),t.rotate(Math.PI)):z===270&&(t.translate(0,I.height),t.rotate(3*Math.PI/2));const B=z===90||z===270,k=B?I.height:I.width,Y=B?I.width:I.height,_=Tu(D,k,Y),G=Ru(D,I,k,Y),se=!0,A=Math.max(0,(D==null?void 0:D.outerRadius)??0),Z=A>0?{kind:"roundedRect",x:0,y:0,width:k,height:Y,rx:A,ry:A}:{kind:"rect",x:0,y:0,width:k,height:Y};if(A>0&&(t.save(),t.beginPath(),Eu(t,Z),t.clip()),a.bleed&&f.bleedOpacity>0){const J=f.bleedInnerEdge==="safeArea"&&G?G:_;if(J){const q=u?"screen":"multiply",ae=f.bleedOpacity;f.bleedMode==="solid"?Mu(t,Z,J,p,ae,q):Nu(t,k,Y,Z,J,p,ae,f.bleedBlurScale,i,q)}}if(a.zones)for(const J of E)J.kind!=="dieCut"&&(t.save(),t.fillStyle=f.zoneFill[J.kind]??Ir.zoneFill[J.kind],Yr(t,J.path),t.strokeStyle=f.zoneStroke[J.kind]??Ir.zoneStroke[J.kind],T.setZoomInvariantStroke(t,1.5,J.kind==="wrap"?[4,3]:[]),Fr(t,J.path),t.setLineDash([]),t.restore());if(a.zones)for(const J of E)J.kind==="dieCut"&&(f.dieCutMode==="knockout"?Lu(t,J,f.dieCutStroke,f.dieCutStrokeWidthPx,e.interacting===!0,se,y,f.dieCutBlurPx):Au(t,J,y,g,f.dieCutTintAlpha,f.dieCutBlurPx,f.dieCutStroke,f.dieCutStrokeWidthPx));a.boundary&&b&&f.boundaryStrokeWidthPx>0&&(t.save(),t.strokeStyle=b,T.setZoomInvariantStroke(t,f.boundaryStrokeWidthPx),Fr(t,_),t.restore()),a.safeArea&&G&&f.safeAreaStroke&&(t.save(),t.strokeStyle=f.safeAreaStroke,T.setZoomInvariantStroke(t,f.safeAreaStrokeWidthPx,f.safeAreaDashPx),Fr(t,G),t.setLineDash([]),t.restore()),a.labels&&O.length>0&&Pu(t,O,f,i),A>0&&t.restore(),t.restore()}t.restore()}function Nu(e,t,r,o,s,i,a,c,d,u="source-over"){const h=Math.max(6,Math.round(Math.min(t,r)*c)),f=d>0?h*d:h,p=typeof window<"u"&&window.devicePixelRatio||1,g=h,b=t+2*g,x=r+2*g,y=Math.max(1,Math.ceil(b*d*p)),v=Math.max(1,Math.ceil(x*d*p)),w=Iu(y,v);if(!w)return;const C=w.getContext("2d");if(!C)return;C.setTransform(1,0,0,1,0,0),C.clearRect(0,0,y,v),C.scale(d*p,d*p),C.translate(g,g),C.fillStyle=i,C.globalAlpha=a;const j=new Path2D;ko(j,o),C.fill(j),C.globalAlpha=1,C.filter=`blur(${f*p}px)`,C.globalCompositeOperation="destination-out",C.fillStyle="#000";const M=new Path2D;ko(M,s),C.fill(M),C.filter="none",C.globalCompositeOperation="source-over";const S=e.globalCompositeOperation;e.globalCompositeOperation=u,e.drawImage(w,-g,-g,b,x),e.globalCompositeOperation=S}function Mu(e,t,r,o,s,i="source-over"){e.save(),e.globalAlpha=e.globalAlpha*s,e.globalCompositeOperation=i,e.fillStyle=o;const a=new Path2D;ko(a,t),ko(a,r),e.fill(a,"evenodd"),e.restore()}let or=null;function Iu(e,t){return typeof document>"u"?null:(or||(or=document.createElement("canvas")),or.width!==e&&(or.width=e),or.height!==t&&(or.height=t),or)}function Au(e,t,r,o,s,i,a,c){const d=t.path;if(e.save(),e.beginPath(),Zr(e,d),e.clip(),r&&(e.save(),e.globalCompositeOperation="destination-out",e.fillStyle="#000",d.kind==="path"?Yr(e,d):e.fillRect(d.x,d.y,d.width,d.height),e.restore(),i>0)){const u=e.globalAlpha,h=e.getTransform();e.save(),e.setTransform(1,0,0,1,0,0),e.filter=`blur(${i}px)`,e.globalAlpha=u*.4,e.drawImage(r,0,0),e.filter="none",e.globalAlpha=u,e.setTransform(h),e.restore()}if(s>0){const u=e.globalAlpha;e.fillStyle=o,e.globalAlpha=u*s,d.kind==="path"?Yr(e,d):e.fillRect(d.x,d.y,d.width,d.height),e.globalAlpha=u}e.restore(),a&&(e.save(),e.strokeStyle=a,T.setZoomInvariantStroke(e,c),Fr(e,d),e.restore())}const Du=.3;function Lu(e,t,r,o,s,i=!0,a,c=0){const d=t.path;if(i)if(s&&a&&c>0){e.save(),e.beginPath(),Zr(e,d),e.clip(),e.save(),e.globalCompositeOperation="destination-out",e.fillStyle="#000",d.kind==="path"||d.kind==="roundedRect"?Yr(e,d):e.fillRect(d.x,d.y,d.width,d.height),e.restore();const u=e.globalAlpha,h=e.getTransform();e.save(),e.setTransform(1,0,0,1,0,0),e.filter=`blur(${c}px)`,e.globalAlpha=u*.4,e.drawImage(a,0,0),e.filter="none",e.globalAlpha=u,e.setTransform(h),e.restore(),e.restore()}else e.save(),e.globalCompositeOperation="destination-out",e.globalAlpha=s?1-Du:1,e.fillStyle="#000",d.kind==="path"||d.kind==="roundedRect"?Yr(e,d):e.fillRect(d.x,d.y,d.width,d.height),e.restore();r&&(e.save(),e.strokeStyle=r,T.setZoomInvariantStroke(e,o),Fr(e,d),e.restore())}function Pu(e,t,r,o){const s=o>0?r.labelFontSizePx/o:r.labelFontSizePx,i=Math.max(2,r.labelFontSizePx*.25),a=o>0?i/o:i;e.save(),e.font=`${s}px ${r.labelFontFamily}`;for(const c of t){const d=c.anchor??"c";e.textAlign=Fu(d),e.textBaseline=zu(d),e.lineJoin="round",e.strokeStyle=r.labelHaloColor,e.lineWidth=a,e.strokeText(c.text,c.x,c.y),e.fillStyle=r.labelColor,e.fillText(c.text,c.x,c.y)}e.restore()}function Fu(e){return e.endsWith("l")?"start":e.endsWith("r")?"end":"center"}function zu(e){return e.startsWith("t")?"hanging":e.startsWith("b")?"alphabetic":"middle"}function Ou(e){const{ctx:t,displaySelection:r,elements:o,activeArtboardElementIds:s,stateMachine:i,multiSelectionOBB:a,isRotating:c,currentRotation:d,isMarqueeSelecting:u,zoom:h=1}=e,f=r.filter(q=>s.has(q));if(f.length===0)return{updatedOBB:null,groupBounds:null};const p=i._multiSelectionDragContext,g=i.getMode()==="drag"&&p;f.forEach(q=>{let ae=o.find(Le=>Le.id===q);if(g&&p.currentElements){const Le=p.currentElements.get(q);Le&&(ae=Le)}if(ae){const Le=ae.getVisualBoundingBox(),pe=ae.getRotationAnchor();t.save(),ae.rotation!==0&&(t.translate(pe.x,pe.y),t.rotate(-ae.rotation*Math.PI/180),t.translate(-pe.x,-pe.y)),t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=rt.getLineWidth(h),t.strokeRect(Le.x,Le.y,Le.width,Le.height),t.restore()}});let b=f.map(q=>o.find(ae=>ae.id===q)).filter(q=>q!==void 0);if(g&&p.currentElements&&(b=b.map(q=>p.currentElements.get(q.id)||q)),b.length===0)return{updatedOBB:null,groupBounds:null};let x=1/0,y=1/0,v=-1/0,w=-1/0;b.forEach(q=>{const ae=q.getVisualBoundingBox(),Le=[{x:ae.x,y:ae.y},{x:ae.x+ae.width,y:ae.y},{x:ae.x,y:ae.y+ae.height},{x:ae.x+ae.width,y:ae.y+ae.height}];if(q.rotation!==0){const pe=q.getRotationAnchor(),U=-q.rotation*Math.PI/180,W=Math.cos(U),Ie=Math.sin(U);Le.forEach(ke=>{const Ke=ke.x-pe.x,re=ke.y-pe.y;ke.x=pe.x+(Ke*W-re*Ie),ke.y=pe.y+(Ke*Ie+re*W)})}Le.forEach(pe=>{x=Math.min(x,pe.x),y=Math.min(y,pe.y),v=Math.max(v,pe.x),w=Math.max(w,pe.y)})});const C=v-x,j=w-y,M=(x+v)/2,S=(y+w)/2;let R=a;if((!R||R.width===0||R.height===0)&&(R={centerX:M,centerY:S,width:C,height:j,rotation:0}),i.getMode()==="drag"&&i._multiSelectionDragContext){const q=i._multiSelectionDragContext;if(q!=null&&q.startOBB&&(q!=null&&q.currentDelta)){const{dx:ae,dy:Le}=q.currentDelta;R={...R,centerX:q.startOBB.centerX+ae,centerY:q.startOBB.centerY+Le}}else R={...R,centerX:M,centerY:S}}const E=c&&i.getMode()==="rotate"?R.rotation+d:R.rotation,O=R.width,z=R.height,B=R.centerX,k=R.centerY,Y=B-O/2,_=k-z/2,G=B+O/2,se=k+z/2;let A=B,Z=se+T.ROTATION_HANDLE_DISTANCE;if(E!==0){const q=-E*Math.PI/180,ae=Math.cos(q),Le=Math.sin(q),pe=A-B,U=Z-k;A=B+(pe*ae-U*Le),Z=k+(pe*Le+U*ae)}const J={minX:Y,minY:_,maxX:G,maxY:se,centerX:B,centerY:k,rotationHandleX:A,rotationHandleY:Z,rotation:E};return t.save(),t.translate(B,k),t.rotate(-E*Math.PI/180),t.translate(-B,-k),t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=rt.getLineWidth(h),t.setLineDash(rt.getDashPattern(h)),t.strokeRect(Y,_,O,z),t.restore(),u||_u(t,{renderMinX:Y,renderMinY:_,renderMaxX:G,renderMaxY:se,renderCenterX:B,renderCenterY:k,renderWidth:O,renderHeight:z,groupRotation:E,rotationHandleX:A,rotationHandleY:Z,stateMachine:i,zoom:h}),{updatedOBB:R,groupBounds:J}}function _u(e,t){var C;const{renderMinX:r,renderMinY:o,renderMaxX:s,renderMaxY:i,renderCenterX:a,renderCenterY:c,renderWidth:d,renderHeight:u,groupRotation:h,rotationHandleX:f,rotationHandleY:p,stateMachine:g,zoom:b}=t,x=rt.getHandleRadius(b),y=[{x:r,y:o,anchor:"top-left"},{x:s,y:o,anchor:"top-right"},{x:r,y:i,anchor:"bottom-left"},{x:s,y:i,anchor:"bottom-right"}],v=g.getMode()==="resize",w=v?(C=g._multiSelectionResizeContext)==null?void 0:C.anchor:null;y.forEach(j=>{if(v&&w&&j.anchor!==w)return;let M=j.x,S=j.y;if(h!==0){const R=-h*Math.PI/180,I=Math.cos(R),D=Math.sin(R),E=j.x-a,O=j.y-c;M=a+(E*I-O*D),S=c+(E*D+O*I)}e.save(),e.beginPath(),e.arc(M,S,x,0,Math.PI*2),e.fillStyle="#fff",e.fill(),e.strokeStyle=T.getThemeAccentColor(),e.lineWidth=v&&w&&j.anchor===w?rt.getLineWidth(b)*1.25:rt.getLineWidth(b),e.stroke(),e.restore()}),v||rt.renderRotationHandle(e,f,p,b,T.getThemeAccentColor()),g.getMode()==="resize"&&Bu(e,a,i,d,u)}function Bu(e,t,r,o,s){const i=`${Math.round(o)} × ${Math.round(s)}`,a=t,c=r+30;e.save(),e.font="10px system-ui, -apple-system, sans-serif";const u=e.measureText(i).width+12,h=18;e.shadowColor="rgba(0,0,0,0.2)",e.shadowBlur=4,e.shadowOffsetY=1,e.fillStyle="#333",e.beginPath(),e.roundRect(a-u/2,c-h/2,u,h,3),e.fill(),e.shadowColor="transparent",e.shadowBlur=0,e.shadowOffsetY=0,e.fillStyle="#fff",e.textAlign="center",e.textBaseline="middle",e.fillText(i,a,c+.5),e.restore()}function Hu(e){const{ctx:t,marqueeStart:r,marqueeEnd:o,zoom:s=1}=e,i=Math.min(r.x,o.x),a=Math.max(r.x,o.x),c=Math.min(r.y,o.y),d=Math.max(r.y,o.y);t.save(),t.strokeStyle=T.getThemeAccentColor(),t.lineWidth=rt.getLineWidth(s),t.strokeRect(i,c,a-i,d-c),t.fillStyle=T.getThemeAccentColorWithAlpha(.1),t.fillRect(i,c,a-i,d-c),t.restore()}function $u(e){const{ctx:t,hoveredChild:r,zoom:o=1}=e,s=r.getVisualBoundingBox();t.save(),t.translate(s.x+s.width/2,s.y+s.height/2),t.rotate(-r.rotation*Math.PI/180),t.translate(-(s.x+s.width/2),-(s.y+s.height/2)),t.strokeStyle=T.getThemeHoverBorderColor(),t.lineWidth=rt.getLineWidth(o),t.setLineDash([]),t.strokeRect(s.x,s.y,s.width,s.height),t.restore()}const Uu=60;class xr{constructor(){this.frameTimes=[],this.metrics={frameTime:0,frameCount:0,elementCount:0,cacheHitRate:0,lastExportDuration:0}}static getInstance(){return xr.instance||(xr.instance=new xr),xr.instance}recordFrameTime(t){this.frameTimes.push(t),this.frameTimes.length>Uu&&this.frameTimes.shift(),this.metrics.frameCount++,this.metrics.frameTime=this._average(this.frameTimes)}recordExportDuration(t){this.metrics.lastExportDuration=t}setElementCount(t){this.metrics.elementCount=t}setCacheHitRate(t){this.metrics.cacheHitRate=t}getMetrics(){return{...this.metrics}}reset(){this.frameTimes=[],this.metrics={frameTime:0,frameCount:0,elementCount:0,cacheHitRate:0,lastExportDuration:0}}_average(t){if(t.length===0)return 0;let r=0;for(let o=0;o<t.length;o++)r+=t[o];return r/t.length}}function Yu(e,t,r){if(e.length===0||!e.every(a=>{var d;const c=(d=t==null?void 0:t[a.id])==null?void 0:d.boundary;return c&&typeof c=="object"&&c.kind==="path"&&typeof c.d=="string"}))return;const s=r?e.filter(a=>a.id===r):e;return{type:"composite-path",pieces:(s.length>0?s:e).map(a=>{var h;const c=(h=t==null?void 0:t[a.id])==null?void 0:h.boundary,d=(a.rotation??0)%360,u=d===90||d===270;return{d:c.d,x:a.x,y:a.y,rotation:d,baseWidth:u?a.height:a.width,baseHeight:u?a.width:a.height}})}}function Wu(e){const t=l.useRef(e);t.current=e;const r=l.useRef(!0),o=l.useRef(null),s=l.useRef("#0a0a0a");l.useEffect(()=>{const i=t.current.canvasRef.current??document.documentElement,a=getComputedStyle(i).getPropertyValue("--color-canvas-bg").trim();s.current=a||"#0a0a0a"},[e.resolvedTheme]),l.useEffect(()=>{r.current=!0},[e.elementsByArtboard,e.artboards,e.selectedId,e.selectedElement,e.activeChildElement,e.canvasSize,e.zoom,e.renderVersion,e.resolvedTheme,e.pieceGuides]),l.useEffect(()=>{r.current=!0},[e.transformHandles,e.currentRotation,e.isRotating,e.hoverState,e.isEditing,e.editText,e.editRichText,e.cursorPosition,e.selectionStart,e.selectionEnd,e.stateMachine,e.snapGuides,e.spacingIndicators,e.handlesVersion,e.multiSelection,e.isMarqueeSelecting,e.marqueeStart,e.marqueeEnd,e.marqueePreviewSelection,e.isAltKeyPressed,e.penTool,e.cursorAnimationFrame]),l.useEffect(()=>{let i;const c=()=>{const{hoverState:d}=t.current;if(d.startTime!==null&&d.type!==null&&performance.now()-d.startTime<150&&(r.current=!0),r.current){r.current=!1;const u=performance.now();Xu(t.current,s,o),xr.getInstance().recordFrameTime(performance.now()-u)}i=requestAnimationFrame(c)};return i=requestAnimationFrame(c),()=>cancelAnimationFrame(i)},[])}function Xu(e,t,r){var $t,Ot,De;const{canvasRef:o,elements:s,elementsByArtboard:i,artboards:a,artboardManager:c,artboardRenderer:d,selectedId:u,selectedElement:h,activeChildElement:f,editingChildIdRef:p,transformHandles:g,stateMachine:b,paddedCanvasWidth:x,paddedCanvasHeight:y,paddingOffsetX:v,paddingOffsetY:w,zoom:C,zoomInvariantBorderRadius:j,effectiveViewPadding:M,showRotationHandle:S,isRotating:R,currentRotation:I,hoverState:D,isEditing:E,editText:O,editRichText:z,cursorPosition:B,selectionStart:k,selectionEnd:Y,cursorOpacityRef:_,cursorStartTimeRef:G,isTouchDevice:se,selectionHandlePositionsRef:A,multiClickSelectionRef:Z,lastMultiClickTimeRef:J,MULTI_CLICK_DEBOUNCE:q,snapGuides:ae,spacingIndicators:Le,isAltKeyPressed:pe,multiSelection:U,multiSelectionOBBRef:W,multiSelectionGroupBoundsRef:Ie,isMarqueeSelecting:ke,marqueeStart:Ke,marqueeEnd:re,marqueePreviewSelection:te,penTool:he,hideHandles:ye,pieceGuides:we}=e,Pe=o.current;if(!Pe)return;const me=Pe.getContext("2d");if(!me)return;if(E){const Ee=Ue=>Ue<.5?4*Ue*Ue*Ue:1-Math.pow(-2*Ue+2,3)/2,Qe=(performance.now()-G.current)%1060/1060,Fe=Qe<.5?1-Ee(Qe*2):Ee((Qe-.5)*2);_.current=Fe}else _.current=1;const N=window.devicePixelRatio||1,ce=x*C,le=y*C;if(ce<=0||le<=0)return;const Me=4096,ge=ce*N,L=le*N,ve=Math.max(ge,L),tt=ve>Me?Me/ve:1,Ve=N*tt;Pe.width=ce*Ve,Pe.height=le*Ve,me.setTransform(1,0,0,1,0,0),me.clearRect(0,0,Pe.width,Pe.height);const oe=t.current;me.scale(Ve,Ve),C!==1&&me.scale(C,C),(v!==0||w!==0)&&me.translate(v,w);const ie=a.find(je=>je.id===c.getActiveArtboardId()),pt=(ie==null?void 0:ie.id)??null,st=we&&ie?Yu(we.pieces,we.guides,e.focusedPieceId??null):void 0;let ht=we?0:j;if(we&&we.pieces.length===1&&ie){const je=we.pieces[0].id,$e=($t=we.guides)==null?void 0:$t[je],Qe=$e==null?void 0:$e.outerRadius,Fe=$e==null?void 0:$e.boundary,Ue=Fe&&typeof Fe=="object"&&Fe.kind==="roundedRect"?Fe.rx??Fe.ry:void 0,Xe=typeof Qe=="number"&&Qe>0?Qe:typeof Ue=="number"&&Ue>0?Ue:0;Xe>0&&(ht=Xe)}if(ie&&!we)if(me.fillStyle=oe,st&&typeof st=="object"&&st.type==="path")try{const je=new Path2D(st.d);me.save(),me.translate(ie.x,ie.y),me.fill(je),me.restore()}catch{me.fillRect(ie.x,ie.y,ie.width,ie.height)}else ht>0?(me.beginPath(),me.roundRect(ie.x,ie.y,ie.width,ie.height,ht),me.fill()):me.fillRect(ie.x,ie.y,ie.width,ie.height);ie&&!we&&d.render(me,ie,!0);let bt=f||h,yt=i.get(pt)||[];if(b.getMode()==="drag"&&h){const Ee=b.getContext()._cachedElement;Ee&&Ee[h.id]&&(yt=yt.map($e=>$e.id===h.id?Ee[h.id]:$e),f||(bt=Ee[h.id]))}if(E&&h){const je=p.current??null,Ee=r.current;if(!(Ee!==null&&Ee.elementId===h.id&&Ee.childId===je&&Ee.editRichText===z)){let Qe=null;if(je&&h instanceof T.GroupElement){const Fe=yt.find(Ue=>Ue.id===h.id&&Ue instanceof T.GroupElement);if(Fe){const Ue=Fe.clone();Ue.children=Ue.children.map(Xe=>{if(Xe.id===je&&z&&Xe instanceof T.TextElement){const dt=Xe.clone();return dt.setRichText(z),dt}return Xe}),Qe=Ue}}else if(z&&h instanceof T.TextElement){const Fe=h.clone();Fe.setRichText(z),Qe=Fe}Qe?r.current={elementId:h.id,childId:je,editRichText:z,clonedElement:Qe}:r.current=null}if(r.current){const{clonedElement:Qe}=r.current;yt=yt.map(Fe=>Fe.id===h.id?Qe:Fe)}}else r.current=null;const Tt=ye||he.isActive()&&h instanceof T.PathElement||E;if(rt.CanvasRenderer.render({ctx:me,elements:yt,selectedId:u,selectedElement:bt||null,transformHandles:g,currentRotation:I,isRotating:R,hoverState:D,isEditing:E,stateMachine:b,snapGuides:ae,spacingIndicators:Le,hideHandles:Tt,isAltKeyPressed:pe,artboardBackgroundColor:ie==null?void 0:ie.backgroundColor,distressTexture:ie==null?void 0:ie.distressTexture,imageMask:ie==null?void 0:ie.imageMask,artboard:ie?{x:ie.x,y:ie.y,width:ie.width,height:ie.height,borderRadius:ht,clipShape:st??ie.clipShape}:void 0,zoom:C,paddingOffset:{x:v,y:w},showOverflowDimmed:M<1,suppressOverflowDim:!1,showRotationHandle:S,editModeData:E?(()=>{const je=Z.current,Ee=Date.now()-J.current<q,$e=je&&Ee;return{cursorPosition:$e?je.cursor:B,selectionStart:$e?je.start:k,selectionEnd:$e?je.end:Y,editText:O,editRichText:z,cursorOpacity:_.current,isTouchDevice:se,selectionHandlePositionsRef:A}})():void 0}),we&&we.pieces.length>0&&ie){let je=!1;const Ee=bt??null;if(Ee&&we){const Fe=Ee.getVisualBoundingBox();e:for(const Ue of we.pieces){const Xe=((De=(Ot=we.guides)==null?void 0:Ot[Ue.id])==null?void 0:De.zones)??[];for(const dt of Xe){if(dt.kind!=="dieCut")continue;const Ye=dt.path;if(Ye.kind!=="rect"&&Ye.kind!=="roundedRect"){je=!0;break e}const vt=Ue.x+(Ye.x??0),gt=Ue.y+(Ye.y??0),Nt=Ye.width??0,Ft=Ye.height??0;if(Fe.x<vt+Nt&&Fe.x+Fe.width>vt&&Fe.y<gt+Ft&&Fe.y+Fe.height>gt){je=!0;break e}}}}const $e=je,Qe=ht>0&&ie!==void 0;if(Qe&&(me.save(),me.beginPath(),me.roundRect(ie.x,ie.y,ie.width,ie.height,ht),me.clip()),fl({ctx:me,artboardOrigin:{x:ie.x,y:ie.y},artboardWidth:ie.width,artboardHeight:ie.height,pieces:we.pieces,pieceGuides:we.guides,show:we.show,style:we.style,zoom:C,interacting:$e,focusedPieceId:e.focusedPieceId??null}),Qe&&me.restore(),e.focusedPieceId&&we.pieces.length>1){const Fe=e.focusedPieceRect??we.pieces.find(Ue=>Ue.id===e.focusedPieceId)??null;if(Fe){me.save(),me.translate(ie.x,ie.y),me.globalCompositeOperation="destination-out";const Ue=!!h;me.globalAlpha=Ue?1-.3:1,me.fillStyle="#000",me.beginPath();const Xe=1e7;me.rect(-Xe,-Xe,2*Xe,2*Xe),me.rect(Fe.x,Fe.y,Fe.width,Fe.height),me.fill("evenodd"),me.restore()}}}ie&&rt.CanvasRenderer.renderInteractionChromeLayer({ctx:me,selectedElement:bt||null,transformHandles:g,stateMachine:b,currentRotation:I,isRotating:R,hoverState:D,selectedId:u,hideHandles:Tt,isEditing:E,isAltKeyPressed:pe,artboardBackgroundColor:ie.backgroundColor,hoverClipArtboard:{x:ie.x,y:ie.y,width:ie.width,height:ie.height,borderRadius:ht,clipShape:ie.clipShape},showRotationHandle:S,zoom:C,paddingOffset:{x:v,y:w}});const Rt=ke?te:U,jt=new Set(yt.map(je=>je.id)),{updatedOBB:kt,groupBounds:Kt}=Ou({ctx:me,displaySelection:Rt,elements:s,activeArtboardElementIds:jt,stateMachine:b,multiSelectionOBB:W.current,isRotating:R,currentRotation:I,isMarqueeSelecting:ke,zoom:C});kt&&W.current!==kt&&(W.current=kt),Ie.current=Kt,ke&&Hu({ctx:me,marqueeStart:Ke,marqueeEnd:re,zoom:C}),D.type==="group-sibling"&&D.data&&$u({ctx:me,hoveredChild:D.data,zoom:C}),he.isActive()&&h instanceof T.PathElement&&he.renderPreview(me,h)}class Vu{static calculatePinch({element:t,startData:r,scale:o,rotationDelta:s,startCentroid:i,currentCentroid:a,snapRotation:c}){const d=r.width??0,u=r.height??0,h=Math.max(1,d*o),f=Math.max(1,u*o);t.resize("bottom-right",h,f,r);const p=r.x-i.x,g=r.y-i.y,b=Math.cos(s),x=Math.sin(s),y=o*p,v=o*g;t.x=a.x+y*b-v*x,t.y=a.y+y*x+v*b;let w=r.rotation-s*180/Math.PI;return w=(w%360+360)%360,w>180&&(w-=360),c&&(w=c(w,t)),t.setRotation(w),t}}class Gu{constructor(){this.isProtectedFlag=!1,this.timeout=null,this.timeoutDuration=5e3}protectNextClick(){this.isProtectedFlag=!0,this.timeout&&clearTimeout(this.timeout),this.timeout=setTimeout(()=>{this.isProtectedFlag=!1,this.timeout=null},this.timeoutDuration)}shouldProtectClick(){const t=this.isProtectedFlag;return this.isProtectedFlag&&(this.isProtectedFlag=!1,this.timeout&&(clearTimeout(this.timeout),this.timeout=null)),t}clearProtection(){this.isProtectedFlag=!1,this.timeout&&(clearTimeout(this.timeout),this.timeout=null)}isProtected(){return this.isProtectedFlag}}const ri=new Gu;function Ku(e){const{x:t,y:r,bounds:o,zoom:s=1}=e,i=T.CORNER_HANDLE_HIT_RADIUS/s,a=o.rotation||0,d=[{x:o.minX,y:o.minY,anchor:"top-left"},{x:o.maxX,y:o.minY,anchor:"top-right"},{x:o.minX,y:o.maxY,anchor:"bottom-left"},{x:o.maxX,y:o.maxY,anchor:"bottom-right"}].map(g=>{if(a!==0){const b=-a*Math.PI/180,x=Math.cos(b),y=Math.sin(b),v=g.x-o.centerX,w=g.y-o.centerY;return{x:o.centerX+(v*x-w*y),y:o.centerY+(v*y+w*x),anchor:g.anchor}}return g});for(const g of d){const b=t-g.x,x=r-g.y;if(Math.sqrt(b*b+x*x)<=i)return{type:"corner-handle",anchor:g.anchor,corner:g}}const u=18/s;if(Math.sqrt(Math.pow(t-o.rotationHandleX,2)+Math.pow(r-o.rotationHandleY,2))<=u)return{type:"rotation-handle"};let f=t,p=r;if(a!==0){const g=a*Math.PI/180,b=Math.cos(g),x=Math.sin(g),y=t-o.centerX,v=r-o.centerY;f=o.centerX+(y*b-v*x),p=o.centerY+(y*x+v*b)}return f>=o.minX&&f<=o.maxX&&p>=o.minY&&p<=o.maxY?{type:"bounds-drag"}:{type:"none"}}function qu(e){const{multiSelection:t,elements:r,bounds:o,anchor:s,corner:i,x:a,y:c,stateMachine:d}=e,u=t.map(h=>r.find(f=>f.id===h)).filter(h=>h!==void 0&&!h.locked);return u.length===0?!1:(d._multiSelectionResizeContext={anchor:s,startBounds:{...o},elementsStartData:u.map(h=>({element:h,startData:h.getTransformStartData()}))},d.startResize(u[0],{anchor:s,x:i.x,y:i.y,cursor:"nwse-resize",type:"corner"},a,c,{x:o.minX,y:o.minY,width:o.maxX-o.minX,height:o.maxY-o.minY},{x:o.minX,y:o.minY,width:o.maxX-o.minX,height:o.maxY-o.minY}),!0)}function Zu(e){const{multiSelection:t,elements:r,bounds:o,x:s,y:i,stateMachine:a,setIsRotating:c,setRotationStartAngle:d,setCurrentRotation:u}=e,h=t.map(p=>r.find(g=>g.id===p)).filter(p=>p!==void 0&&!p.locked);if(h.length===0)return!1;const f=T.calculateAngle(o.centerX,o.centerY,s,i);return a._multiSelectionRotationContext={startBounds:{...o},elementsStartData:h.map(p=>({element:p,startData:p.getTransformStartData()}))},c(!0),d(f),u(0),a.startRotate(h[0],s,i,f,0),!0}function Ju(e){const{multiSelection:t,elements:r,x:o,y:s,stateMachine:i,dragOriginalElementsRef:a,setHoverState:c}=e,d=t.map(u=>r.find(h=>h.id===u)).filter(u=>u!==void 0&&!u.locked);return d.length===0?!1:(i._multiSelectionDragContext={startX:o,startY:s,elementsStartData:d.map(u=>({element:u,startData:u.getTransformStartData()})),currentElements:new Map},a.current=new Map,d.forEach(u=>{a.current.set(u.id,u.clone())}),i.startDrag(d[0],o,s),c({type:null,data:null}),!0)}function Qu(e){const{selectedElement:t,activeChildElement:r}=e;let o=null,s=-1;if(r instanceof T.ImageElement&&r.isCropping)o=r,t instanceof T.GroupElement&&(s=t.children.findIndex(a=>a.id===r.id));else if(t instanceof T.GroupElement)for(let a=0;a<t.children.length;a++){const c=t.children[a];if(c.visible!==!1&&c instanceof T.ImageElement&&c.isCropping){o=c,s=a;break}}const i=o||(t instanceof T.ImageElement&&t.isCropping?t:null);return i?{croppingImage:i,croppingChild:o,croppingChildIndex:s,isChildInGroup:o!==null}:null}function eh(e){const{x:t,y:r,cropContext:o,transformHandles:s,zoom:i=1}=e,{croppingImage:a}=o,c=a.hitTestCropHandle(t,r,i);if(c)return{type:"crop-handle",handle:c};const d=s.hitTestResize(t,r,i);return d?{type:"image-handle",handle:d}:a.hitTest(t,r)?{type:"image-drag"}:{type:"exit-crop"}}function th(e){const{cropContext:t,cropHandle:r,x:o,y:s,selectedElement:i,activeChildElement:a,stateMachine:c}=e,{croppingImage:d,croppingChild:u,croppingChildIndex:h}=t,f=d.getCropBoxBounds();f&&(c.startResize(d,{anchor:"crop-"+r.anchor,x:0,y:0,cursor:"grab",type:r.type},o,s,f,f),u&&(a&&a.id===u.id?c._activeChildContext={group:i,childId:u.id}:c._cropGroupContext={group:i,childIndex:h}))}function nh(e){const{cropContext:t,imageHandle:r,x:o,y:s,selectedElement:i,activeChildElement:a,stateMachine:c}=e,{croppingImage:d,croppingChild:u,croppingChildIndex:h}=t,f=d.getBoundingBox(),p=d.getVisualBoundingBox();c.startResize(d,r,o,s,f,p),u&&(a&&a.id===u.id?c._activeChildContext={group:i,childId:u.id}:c._cropGroupContext={group:i,childIndex:h})}function rh(e){const{cropContext:t,x:r,y:o,selectedElement:s,activeChildElement:i,stateMachine:a,dragOriginalElementsRef:c,setHoverState:d}=e,{croppingImage:u,croppingChild:h,croppingChildIndex:f}=t;c.current=new Map,h&&s?c.current.set(s.id,s.clone()):c.current.set(u.id,u.clone()),a.startDrag(u,r,o,"crop-image-drag"),d({type:null,data:null}),h&&(i&&i.id===h.id?a._activeChildContext={group:s,childId:h.id}:a._cropGroupContext={group:s,childIndex:f})}function oh(e){const{cropContext:t,selectedElement:r,onElementUpdate:o,transformHandles:s,updateActiveChild:i,zoom:a}=e,{croppingImage:c,croppingChild:d,croppingChildIndex:u}=t;if(d&&r instanceof T.GroupElement){const h=d.clone();h.exitCropMode();const f=r.clone();f.children[u]=h,o(f),s.update(f,a),i(null)}else{const h=c.clone();h.exitCropMode(),o(h),s.update(h,a)}}function sh(e){const{x:t,y:r,activeChildElement:o,selectedElement:s,updateActiveChild:i,transformHandles:a,setHandlesVersion:c,stateMachine:d,dragOriginalElementsRef:u,setHoverState:h,forceUpdate:f,zoom:p}=e;for(let g=s.children.length-1;g>=0;g--){const b=s.children[g];if(!(b.visible===!1||b.id===o.id)&&b.hitTest(t,r))return i(b),a.update(b,p),c(x=>x+1),d.startDrag(b,t,r),u.current=new Map,u.current.set(b.id,b.clone()),h({type:null,data:null}),d._activeChildContext={group:s,childId:b.id},f({}),!0}return!1}function ea(e){const{updateActiveChild:t,selectedElement:r,transformHandles:o,setHandlesVersion:s,zoom:i}=e;t(null),r&&(o.update(r,i),s(a=>a+1))}function ih(e){const{x:t,y:r,shiftKey:o,activeArtboardElements:s,selectedElement:i,multiSelection:a,onSelectionChange:c,onMultiSelectionChange:d,stateMachine:u,dragOriginalElementsRef:h,setHoverState:f,forceUpdate:p}=e;for(let g=s.length-1;g>=0;g--)if(s[g].visible!==!1&&s[g].hitTest(t,r)){const b=s[g].id;if(o){if(i&&a.length===0)d([i.id,b]),c(null);else if(a.includes(b)){const x=a.filter(y=>y!==b);d(x)}else d([...a,b]);return!0}if(a.length>0&&a.includes(b)){const x=a.map(y=>s.find(v=>v.id===y)).filter(y=>y!==void 0&&!y.locked);if(x.length>0)return u._multiSelectionDragContext={startX:t,startY:r,elementsStartData:x.map(y=>({element:y,startData:y.getTransformStartData()})),currentElements:new Map},h.current=new Map,x.forEach(y=>{h.current.set(y.id,y.clone())}),u.startDrag(x[0],t,r),f({type:null,data:null}),p({}),!0}return c(b),d([]),h.current=new Map,h.current.set(b,s[g].clone()),u.startDrag(s[g],t,r),f({type:null,data:null}),s[g]instanceof T.GroupElement&&(u._groupDragOriginalElement=s[g].clone()),p({}),!0}return!1}const ah=900;function ss(e,t,r,o){if(!o)return!0;const s=e.getVisualBoundingBox(),i=Math.max(s.x,o.x),a=Math.max(s.y,o.y),c=Math.min(s.x+s.width,o.x+o.width),d=Math.min(s.y+s.height,o.y+o.height);return Math.max(0,c-i)*Math.max(0,d-a)<ah?!0:t>=o.x&&t<=o.x+o.width&&r>=o.y&&r<=o.y+o.height}function lh(e){const{canvasRef:t,inputRef:r,repositioningCursorRef:o,lastClickTimeRef:s,clickCountRef:i,lastProcessedClickTimeRef:a,lastMultiClickTimeRef:c,multiClickSelectionRef:d,skipDragSelectionRef:u,draggingSelectionHandleRef:h,selectionHandlePositionsRef:f,lastMousePosRef:p,dragOriginalElementsRef:g,rotatingElementRef:b,editingChildIdRef:x,editRichTextRef:y,editModeEnteredAtRef:v,multiSelectionGroupBoundsRef:w,MULTI_CLICK_THRESHOLD:C,MULTI_CLICK_DEBOUNCE:j,CLICK_DEDUP_THRESHOLD:M,isEditing:S,editText:R,isTouchDevice:I,selectionStart:D,selectionEnd:E,isRotating:O,isMarqueeSelecting:z,isAltKeyPressed:B,selectedElement:k,activeChildElement:Y,elements:_,multiSelection:G,multiSelectionOBBRef:se,zoom:A,paddingOffsetX:Z,paddingOffsetY:J,spacingIndicators:q,focusedPieceRect:ae,setCursorPosition:Le,setSelectionStart:pe,setSelectionEnd:U,setIsRotating:W,setRotationStartAngle:Ie,setCurrentRotation:ke,setRotatingElementVersion:Ke,setIsAltKeyPressed:re,setSnapGuides:te,setSpacingIndicators:he,setHandlesVersion:ye,setHoverState:we,setElements:Pe,forceUpdate:me,stateMachine:N,transformHandles:ce,snapSystem:le,spacingSystem:Me,penTool:ge,cropController:L,onElementUpdate:ve,executeElementUpdate:tt,onSelectionChange:Ve,onMultiSelectionChange:oe,onRotationStateChange:ie,onCropModeEnter:pt,updateActiveChild:st,getActiveArtboardElements:ht,startMarqueeSelection:bt,updateMarqueeSelection:yt,finishMarqueeSelection:Tt,enterTextEditMode:Rt,setEditPosition:jt,setEditText:kt,setEditRichText:Kt,setIsEditing:$t,setCurrentFormattingStyle:Ot,getWrappedTextForEditing:De}=e,je=l.useRef(null),Ee=l.useRef(new Map),$e=l.useRef(null),Qe=l.useRef(null),Fe=l.useRef(null),Ue=l.useRef(null),Xe=l.useRef(null),dt=l.useRef(null),Ye=l.useRef(null),{userZoom:vt,setUserZoom:gt,panOffset:Nt,setPanOffset:Ft}=Yt.useViewportContext(),$=l.useRef(vt);$.current=vt;const ee=l.useRef(Nt);ee.current=Nt,l.useEffect(()=>{const Q=t.current;if(!Q)return;const ze=()=>{je.current=Q.getBoundingClientRect()};return ze(),window.addEventListener("scroll",ze,{passive:!0,capture:!0}),window.addEventListener("resize",ze,{passive:!0}),()=>{window.removeEventListener("scroll",ze,{capture:!0}),window.removeEventListener("resize",ze)}},[t]),l.useEffect(()=>{const Q=t.current;Q&&(je.current=Q.getBoundingClientRect())},[A,t]);const Je=l.useCallback(Q=>{var Ne,He,Se,_e,Ae;const ze=t.current;if(!ze)return;const nt=ze.getBoundingClientRect();je.current=nt;const Ce=(Q.clientX-nt.left)/A-Z,X=(Q.clientY-nt.top)/A-J;Ee.current.size===0&&(Fe.current=(k==null?void 0:k.id)??null),Ee.current.set(Q.pointerId,{x:Ce,y:X,clientX:Q.clientX,clientY:Q.clientY});const Mt=S||k instanceof T.ImageElement&&k.isCropping||ge.isActive();if(Ee.current.size===2&&!Mt){const V=Array.from(Ee.current.keys()),xe=Ee.current.get(V[0]),ne=Ee.current.get(V[1]),fe=Fe.current!==null;if(!(fe&&k&&!k.locked&&(k.hitTest(xe.x,xe.y)||k.hitTest(ne.x,ne.y)))){if(g.current&&g.current.size>0){const Bt=g.current;Pe(At=>At.map(Dt=>{const rn=Bt.get(Dt.id);return rn?rn.clone():Dt})),g.current=null}!fe&&k&&Ve(null),N.isInteracting()&&N.end(),Ye.current=null,Ue.current=null,Xe.current=null,delete N._pendingTextEditMode,delete N._pendingChildSelection;const Oe=ne.clientX-xe.clientX,ot=ne.clientY-xe.clientY,mt=Math.hypot(Oe,ot),Wt=(((Ne=ze.parentElement)==null?void 0:Ne.parentElement)??ze).getBoundingClientRect();dt.current={pointerA:V[0],pointerB:V[1],startUserZoom:$.current,startPanOffset:{...ee.current},startCentroidClient:{x:(xe.clientX+ne.clientX)/2,y:(xe.clientY+ne.clientY)/2},startDistance:Math.max(mt,1),containerRect:{left:Wt.left,top:Wt.top}};try{ze.setPointerCapture(Q.pointerId)}catch{}Q.preventDefault();return}}if(Ee.current.size===2&&k&&!k.locked&&!Mt){if(N.isInteracting()){const fe=N.getContext();if(fe.element){const Be=ht().find(Oe=>Oe.id===fe.element.id);tt(Be,fe.element)}N.end()}const V=Array.from(Ee.current.keys());$e.current={a:V[0],b:V[1]};const xe=Ee.current.get(V[0]),ne=Ee.current.get(V[1]);Ue.current=null,Xe.current=null,Ye.current=null,Qe.current=k.clone(),N.startPinch(k,xe,ne);try{ze.setPointerCapture(Q.pointerId)}catch{}Q.preventDefault();return}if(S&&k instanceof T.TextElement){if(I&&D!==E){const V=f.current;if(V.start||V.end){const xe=T.RotationUtils.toRadiansInverse(k.rotation),ne=k.getRotationAnchor(),fe=Ce-ne.x,Be=X-ne.y,Oe=Math.cos(xe),ot=Math.sin(xe),mt=fe*Oe-Be*ot,_t=fe*ot+Be*Oe,Wt=mt,Bt=_t,At=44/A;if(V.start&&Math.sqrt(Math.pow(Wt-V.start.center.x,2)+Math.pow(Bt-V.start.center.y,2))<=At){Q.preventDefault(),h.current="start",(He=r.current)==null||He.focus();return}if(V.end&&Math.sqrt(Math.pow(Wt-V.end.center.x,2)+Math.pow(Bt-V.end.center.y,2))<=At){Q.preventDefault(),h.current="end",(Se=r.current)==null||Se.focus();return}}}if(k.hitTest(Ce,X)){Q.preventDefault(),o.current=!0;const V=k.getVisualBoundingBox(),xe=T.RotationUtils.toRadiansInverse(k.rotation),ne=k.getRotationAnchor(),fe=Ce-ne.x,Be=X-ne.y,Oe=Math.cos(xe),ot=Math.sin(xe),mt=fe*Oe-Be*ot,_t=fe*ot+Be*Oe,Wt=mt+V.width/2,Bt=_t+V.height/2,At=Xn(k,{x:Wt,y:Bt}),Dt=Date.now();if(Dt-a.current<M){(_e=r.current)==null||_e.focus();return}a.current=Dt,Dt-c.current>=j&&(d.current=null),Dt-s.current<C?i.current+=1:i.current=1,s.current=Dt;const Lt=R;if(i.current>=3)Q.preventDefault(),c.current=Dt,d.current={start:0,end:Lt.length,cursor:Lt.length},u.current=!0,i.current=0,Le(Lt.length),pe(0),U(Lt.length),r.current&&(r.current.focus(),r.current.setSelectionRange(0,Lt.length));else if(i.current===2){Q.preventDefault(),c.current=Dt,u.current=!0;const Ut=Xa(Lt,At);d.current={start:Ut.start,end:Ut.end,cursor:Ut.end},Le(Ut.end),pe(Ut.start),U(Ut.end),r.current&&(r.current.focus(),r.current.setSelectionRange(Ut.start,Ut.end))}else d.current=null,Le(At),pe(At),U(At),r.current&&(r.current.focus(),r.current.setSelectionRange(At,At)),u.current=!1;return}d.current=null,(Ae=r.current)==null||Ae.blur();return}if(S)return;if(Q.target.setPointerCapture(Q.pointerId),ge.isActive()&&k instanceof T.PathElement){const V=Ce-k.x,xe=X-k.y;if(ge.canClosePath(V,xe,15)){ge.startClosing(V,xe),ge.startDraggingHandle(),ye(ne=>ne+1);return}ge.addPoint(V,xe),ge.startDraggingHandle(),ye(ne=>ne+1);return}if(G.length>0&&w.current){const V=w.current,xe=Ku({x:Ce,y:X,bounds:V,zoom:A});if(xe.type==="corner-handle"){if(qu({multiSelection:G,elements:_,bounds:V,anchor:xe.anchor,corner:xe.corner,x:Ce,y:X,stateMachine:N})){me({});return}}else if(xe.type==="rotation-handle"){if(Zu({multiSelection:G,elements:_,bounds:V,x:Ce,y:X,stateMachine:N,setIsRotating:W,setRotationStartAngle:Ie,setCurrentRotation:ke})){me({});return}}else if(xe.type==="bounds-drag"&&Ju({multiSelection:G,elements:_,x:Ce,y:X,stateMachine:N,dragOriginalElementsRef:g,setHoverState:we})){me({});return}}const ue=Y||k;if(ue&&ue.visible!==!1&&!ue.locked&&(G.length===0||Y)){const V=Qu({selectedElement:k||null,activeChildElement:Y});if(V){const ne=eh({x:Ce,y:X,cropContext:V,transformHandles:ce,zoom:A});if(ne.type==="crop-handle"){th({cropContext:V,cropHandle:ne.handle,x:Ce,y:X,selectedElement:k||null,activeChildElement:Y,stateMachine:N}),me({});return}else if(ne.type==="image-handle"){nh({cropContext:V,imageHandle:ne.handle,x:Ce,y:X,selectedElement:k||null,activeChildElement:Y,stateMachine:N}),me({});return}else if(ne.type==="image-drag"){rh({cropContext:V,x:Ce,y:X,selectedElement:k||null,activeChildElement:Y,stateMachine:N,dragOriginalElementsRef:g,setHoverState:we}),me({});return}else if(ne.type==="exit-crop"){oh({cropContext:V,selectedElement:k||null,onElementUpdate:ve,transformHandles:ce,updateActiveChild:st,zoom:A}),ye(fe=>fe+1);return}}if(ce.hitTestRotation(Ce,X,A)){if(ue.locked)return;const ne=ue.getBoundingBox(),fe=T.getBoundingBoxCenter(ne),Be=T.calculateAngle(fe.x,fe.y,Ce,X);W(!0),Ie(Be),ke(ue.rotation),N.startRotate(ue,Ce,X,Be,ue.rotation),Y&&k instanceof T.GroupElement&&(N._activeChildContext={group:k,childId:Y.id}),Ue.current=ue.id,Xe.current={x:Ce,y:X},me({});return}const xe=ce.hitTestResize(Ce,X,A);if(xe){if(ue.locked)return;const ne=ue.getBoundingBox(),fe=ue.getVisualBoundingBox();N.startResize(ue,xe,Ce,X,ne,fe),Ue.current=ue.id,Xe.current={x:Ce,y:X},Y&&k instanceof T.GroupElement&&(N._activeChildContext={group:k,childId:Y.id}),me({});return}if(ue.hitTest(Ce,X)){if(ue.locked)return;if(k instanceof T.GroupElement&&!Y){const ne=k.hitTestChild(Ce,X);ne&&(N._pendingChildSelection=ne)}k&&ue.id===k.id&&!(ue instanceof T.TextElement)&&(Ue.current=ue.id,Xe.current={x:Ce,y:X}),ue instanceof T.TextElement&&!(ue instanceof T.GroupElement)&&k&&ue.id===k.id&&!S&&(N._pendingTextEditMode={elementId:ue.id,originalX:ue.x,originalY:ue.y,clickX:Ce,clickY:X}),N.startDrag(ue,Ce,X),g.current=new Map,g.current.set(ue.id,ue.clone()),we({type:null,data:null}),ue instanceof T.GroupElement&&(N._groupDragOriginalElement=ue.clone()),Y&&k instanceof T.GroupElement&&(N._activeChildContext={group:k,childId:Y.id}),me({});return}}if(Y&&k instanceof T.GroupElement){if(sh({x:Ce,y:X,activeChildElement:Y,selectedElement:k,updateActiveChild:st,transformHandles:ce,setHandlesVersion:ye,stateMachine:N,dragOriginalElementsRef:g,setHoverState:we,forceUpdate:me,zoom:A}))return;ea({updateActiveChild:st,selectedElement:k||null,transformHandles:ce,setHandlesVersion:ye,zoom:A});return}if(Y){ea({updateActiveChild:st,selectedElement:k||null,transformHandles:ce,setHandlesVersion:ye,zoom:A});return}if(!Q.shiftKey){const V=ht(),xe=[];for(let fe=V.length-1;fe>=0;fe--){const Be=V[fe];Be.visible!==!1&&Be.hitTest(Ce,X)&&ss(Be,Ce,X,ae)&&xe.push(Be)}let ne=null;if(xe.length===0)k&&(ne={kind:"deselect"});else{const fe=k?xe.findIndex(Be=>Be.id===k.id):-1;fe===-1?ne={kind:"select-element",elementId:xe[0].id,x:Ce,y:X,shiftKey:Q.shiftKey}:fe+1<xe.length?ne={kind:"select-element",elementId:xe[fe+1].id,x:Ce,y:X,shiftKey:Q.shiftKey}:ne={kind:"deselect"}}Ye.current={pointerId:Q.pointerId,startClientX:Q.clientX,startClientY:Q.clientY,startPanOffset:{...ee.current},movedPastThreshold:!1,pendingTap:ne};try{ze.setPointerCapture(Q.pointerId)}catch{}Q.preventDefault();return}const et=ht();if(ih({x:Ce,y:X,shiftKey:Q.shiftKey,activeArtboardElements:et,selectedElement:k||null,multiSelection:G,onSelectionChange:Ve,onMultiSelectionChange:oe,stateMachine:N,dragOriginalElementsRef:g,setHoverState:we,forceUpdate:me}))return;const be=ri.shouldProtectClick(),Te=Yt.shouldPreserveSelection(Q.target);if(!be&&!Te)if($.current>1.001){Ye.current={pointerId:Q.pointerId,startClientX:Q.clientX,startClientY:Q.clientY,startPanOffset:{...ee.current},movedPastThreshold:!1,pendingTap:null};try{ze.setPointerCapture(Q.pointerId)}catch{}Q.preventDefault()}else Ve(null),oe([]),bt(Ce,X)},[S,k,ht,Ve,oe,ce,Y,G,N,ge,tt,ye,A,Le,pe,U,t,Pe,ae]),it=l.useCallback(Q=>{var Mt;const ze=t.current;if(!ze)return;const nt=je.current??ze.getBoundingClientRect(),Ce=(Q.clientX-nt.left)/A-Z,X=(Q.clientY-nt.top)/A-J;if(p.current={x:Ce,y:X},Ee.current.has(Q.pointerId)&&Ee.current.set(Q.pointerId,{x:Ce,y:X,clientX:Q.clientX,clientY:Q.clientY}),dt.current){const ue=dt.current,et=Ee.current.get(ue.pointerA),K=Ee.current.get(ue.pointerB);if(et&&K){const be=K.clientX-et.clientX,Te=K.clientY-et.clientY,He=Math.hypot(be,Te)/ue.startDistance,Se=Math.min(Math.max(ue.startUserZoom*He,.25),8),_e=ue.startCentroidClient.x-ue.containerRect.left,Ae=ue.startCentroidClient.y-ue.containerRect.top,V=(et.clientX+K.clientX)/2-ue.containerRect.left,xe=(et.clientY+K.clientY)/2-ue.containerRect.top,ne=Se/ue.startUserZoom,fe=V-(_e-ue.startPanOffset.x)*ne,Be=xe-(Ae-ue.startPanOffset.y)*ne,Oe=t.current;if(Oe){const ot=Oe.getBoundingClientRect(),mt=(Mt=Oe.parentElement)==null?void 0:Mt.parentElement,_t=(mt==null?void 0:mt.clientWidth)??ot.width,Wt=(mt==null?void 0:mt.clientHeight)??ot.height,Bt=80,At=Se/Math.max($.current,1e-4),Dt=ot.width*At,rn=ot.height*At,Lt=ee.current.x,Ut=ee.current.y,an=ot.left-ue.containerRect.left,un=ot.top-ue.containerRect.top,Zt=an+(fe-Lt),Qt=un+(Be-Ut),hn=Math.min(Math.max(Zt,-Dt+Bt),_t-Bt),en=Math.min(Math.max(Qt,-rn+Bt),Wt-Bt);gt(Se),Ft({x:fe+(hn-Zt),y:Be+(en-Qt)})}else gt(Se),Ft({x:fe,y:Be})}return}if(Ye.current&&Ye.current.pointerId===Q.pointerId){const ue=Ye.current,et=Q.clientX-ue.startClientX,K=Q.clientY-ue.startClientY;if(!ue.movedPastThreshold)if(Math.hypot(et,K)>5)ue.movedPastThreshold=!0,ue.pendingTap=null;else return;if($.current<=1.001)return;Ft({x:ue.startPanOffset.x+et,y:ue.startPanOffset.y+K});return}if(N.getMode()==="pinch"&&$e.current){const{a:ue,b:et}=$e.current,K=Ee.current.get(ue),be=Ee.current.get(et);if(K&&be){const Te=N.updatePinch(K,be),{element:Ne,startData:He}=N.getPinchContext();Vu.calculatePinch({element:Ne,startData:He,scale:Te.scale,rotationDelta:Te.rotationDelta,startCentroid:Te.startCentroid,currentCentroid:Te.currentCentroid,snapRotation:le?(Se,_e)=>le.snapRotation(Se,_e):void 0}),Pe(Se=>Se.map(_e=>_e.id===Ne.id?Ne:_e))}Q.preventDefault();return}if(h.current&&k instanceof T.TextElement){const ue=k.getVisualBoundingBox(),et=k.getRotationAnchor(),K=T.RotationUtils.toRadiansInverse(k.rotation),be=Ce-et.x,Te=X-et.y,Ne=Math.cos(K),He=Math.sin(K),Se=be*Ne-Te*He,_e=be*He+Te*Ne,Ae=f.current;let V=0;h.current==="start"&&(Ae!=null&&Ae.start)?V=Ae.start.textEdge.y-Ae.start.center.y:h.current==="end"&&(Ae!=null&&Ae.end)&&(V=Ae.end.textEdge.y-Ae.end.center.y);const xe=Se+ue.width/2,ne=_e+V+ue.height/2,fe=Xn(k,{x:xe,y:ne});if(h.current==="start"?fe<=E?(pe(fe),Le(fe)):(pe(E),U(fe),Le(fe),h.current="end"):fe>=D?(U(fe),Le(fe)):(U(D),pe(fe),Le(fe),h.current="start"),r.current){const Be=Math.min(D,E),Oe=Math.max(D,E);r.current.setSelectionRange(Be,Oe)}return}if(ge.isActive()&&k instanceof T.PathElement){ge.isDraggingHandle()?(ge.updateHandle(Ce-k.x,X-k.y),ye(ue=>ue+1)):(ge.setPreviewPoint(Ce-k.x,X-k.y),ye(ue=>ue+1));return}if(Q.altKey!==B&&re(Q.altKey),z){yt(Ce,X,_);return}if(N.getMode()==="drag"){const ue=N._multiSelectionDragContext;if(ue&&G.length>0){const et=Ce-ue.startX,K=X-ue.startY;ue.currentElements||(ue.currentElements=new Map);const be=[];ue.elementsStartData.forEach(Te=>{const Ne=Te.element,He=Te.startData,Se=Ne.clone();Se.x=He.x+et,Se.y=He.y+K,ue.currentElements.set(Se.id,Se),be.push(Se)}),Pe(Te=>Te.map(Ne=>be.find(He=>He.id===Ne.id)||Ne)),ue.currentDelta={dx:et,dy:K},!ue.startOBB&&se.current&&(ue.startOBB={...se.current}),ye(Te=>Te+1),me({});return}}if(N.getMode()==="drag"&&k){if(N.getDragMode()==="crop-image-drag"){const Se=N.getContext(),_e=Se.element;if(_e instanceof T.ImageElement&&_e.isCropping){const Ae=L.handleCropImageDrag(_e,Se,Ce,X),V=N._cropGroupContext,xe=N._activeChildContext,ne=V||xe;if(ne&&k instanceof T.GroupElement){const fe=_e.clone();fe.x=Ae.x,fe.y=Ae.y,fe.updateCrop(Ae.cropX,Ae.cropY,Ae.cropWidth,Ae.cropHeight,!1);const Be=k.clone(),Oe=V?V.childIndex:Be.children.findIndex(mt=>mt.id===ne.childId);Oe>=0&&(Be.children[Oe]=fe,Be.updateBoundsFromChildren(!0)),Pe(mt=>mt.map(_t=>_t.id===Be.id?Be:_t));const ot=N.getContext();ot._cachedElement||(ot._cachedElement={}),ot._cachedElement[Be.id]=Be,xe&&Oe>=0&&(st(Be.children[Oe]),ce.update(fe,A)),ye(mt=>mt+1)}else{const fe=_e.clone();fe.x=Ae.x,fe.y=Ae.y,fe.updateCrop(Ae.cropX,Ae.cropY,Ae.cropWidth,Ae.cropHeight,!1),Pe(Oe=>Oe.map(ot=>ot.id===fe.id?fe:ot));const Be=N.getContext();Be._cachedElement||(Be._cachedElement={}),Be._cachedElement[fe.id]=fe,ce.update(fe,A),ye(Oe=>Oe+1)}return}}const et=N._activeChildContext,K=ht(),be=[];K.forEach(Se=>{Se instanceof T.GroupElement?be.push(...Se.children):be.push(Se)});let Te=N.updateDrag(Ce,X,be);const Ne=et&&k instanceof T.GroupElement?k.children.find(Se=>Se.id===et.childId):k;if(Ne&&(Te=Me.snapToSpacing(Te,Ne,be)),et&&k instanceof T.GroupElement){const Se=k.clone(),_e=Se.children.findIndex(V=>V.id===et.childId);if(_e>=0){const V=Se.children[_e].clone();V.x=Te.x,V.y=Te.y,Se.children[_e]=V,Se.updateBoundsFromChildren(!0)}Pe(V=>V.map(xe=>xe.id===Se.id?Se:xe));const Ae=N.getContext();if(Ae._cachedElement||(Ae._cachedElement={}),Ae._cachedElement[Se.id]=Se,_e>=0){const V=Se.children[_e];st(V),ce.update(V,A)}ye(V=>V+1),me({})}else{const Se=N._groupDragOriginalElement,_e=k instanceof T.GroupElement&&Se?Se.clone():k.clone();if(_e instanceof T.GroupElement){const xe=N.getContext().startData,ne=Te.x-xe.x,fe=Te.y-xe.y;_e.move(ne,fe)}else _e.x=Te.x,_e.y=Te.y;Pe(V=>V.map(xe=>xe.id===_e.id?_e:xe)),ce.update(_e,A);const Ae=N.getContext();Ae._cachedElement||(Ae._cachedElement={}),Ae._cachedElement[_e.id]=_e}ye(Se=>Se+1),te(le.getGuides());let He;if(et&&k instanceof T.GroupElement)He=k.children.find(Se=>Se.id===et.childId);else{const Se=N.getContext();Se._cachedElement&&k?He=Se._cachedElement[k.id]:He=k||void 0}if(He){const Se=Me.detectSpacing(He,be,B);he(Se)}}else if(N.getMode()==="resize"){const{dx:ue,dy:et}=N.updateResize(Ce,X),K=N.getResizeContext(),be=N._multiSelectionResizeContext;if(be&&G.length>0){const V=be.startBounds,xe=be.anchor;let ne,fe,Be,Oe;switch(xe){case"top-left":ne=V.maxX,fe=V.maxY,Be=V.minX,Oe=V.minY;break;case"top-right":ne=V.minX,fe=V.maxY,Be=V.maxX,Oe=V.minY;break;case"bottom-left":ne=V.maxX,fe=V.minY,Be=V.minX,Oe=V.maxY;break;case"bottom-right":ne=V.minX,fe=V.minY,Be=V.maxX,Oe=V.maxY;break;default:ne=V.minX,fe=V.minY,Be=V.maxX,Oe=V.maxY}const ot=Be+ue,mt=Oe+et,_t=Math.abs(Be-ne),Wt=Math.abs(Oe-fe),Bt=Math.abs(ot-ne),At=Math.abs(mt-fe),Dt=_t>0?Bt/_t:1,rn=Wt>0?At/Wt:1,Lt=(Dt+rn)/2,Ut=V.maxX-V.minX,an=V.maxY-V.minY,un=Ut*Lt,Zt=an*Lt;let Qt=ne,hn=fe,en=ne,xn=fe;switch(xe){case"top-left":en=ne,xn=fe,Qt=ne-un,hn=fe-Zt;break;case"top-right":Qt=ne,xn=fe,en=ne+un,hn=fe-Zt;break;case"bottom-left":en=ne,hn=fe,Qt=ne-un,xn=fe+Zt;break;case"bottom-right":Qt=ne,hn=fe,en=ne+un,xn=fe+Zt;break}if(be.elementsStartData.forEach(Yn=>{const er=Yn.element,wn=Yn.startData,cr=wn.x-ne,dr=wn.y-fe,Gn=ne+cr*Lt,tr=fe+dr*Lt,ln=er.clone();if(ln instanceof T.ImageElement){ln.x=Gn,ln.y=tr;const Hn=ln.transformData,$n=wn.transformData;Hn.width=$n.width*Lt,Hn.height=$n.height*Lt}else if(ln instanceof T.GroupElement){ln.x=Gn,ln.y=tr;const Hn=wn.width*Lt,$n=wn.height*Lt;ln.resize(xe,Hn,$n,wn)}else{const Hn=wn.width*Lt,$n=wn.height*Lt;ln.resize(xe,Hn,$n,wn),ln.x=Gn,ln.y=tr}ve(ln)}),se.current){const Yn=(Qt+en)/2,er=(hn+xn)/2;se.current={centerX:Yn,centerY:er,width:en-Qt,height:xn-hn,rotation:se.current.rotation}}return}const Te=K.element;if(Te instanceof T.ImageElement&&Te.isCropping&&K.handle.anchor&&K.handle.anchor.startsWith("crop-")){const V=K.handle.anchor.replace("crop-",""),xe=N.getContext(),ne=L.handleCropBoxResize(Te,V,K,xe,Ce,X);ze.style.cursor=ne.cursor;const fe=N._cropGroupContext,Be=N._activeChildContext,Oe=fe||Be;if(Oe&&k instanceof T.GroupElement){const ot=Te.clone();ot.x=ne.x,ot.y=ne.y,ot.rotation=ne.rotation,ot.transformData.width=ne.width,ot.transformData.height=ne.height,ot.updateCrop(ne.cropX,ne.cropY,ne.cropWidth,ne.cropHeight,!1);const mt=k.clone(),_t=fe?fe.childIndex:mt.children.findIndex(Wt=>Wt.id===Oe.childId);_t>=0&&(mt.children[_t]=ot,mt.updateBoundsFromChildren(!0)),ve(mt),Be&&_t>=0&&st(mt.children[_t])}else{const ot=Te.clone();ot.x=ne.x,ot.y=ne.y,ot.rotation=ne.rotation,ot.transformData.width=ne.width,ot.transformData.height=ne.height,ot.updateCrop(ne.cropX,ne.cropY,ne.cropWidth,ne.cropHeight,!1),ve(ot)}return}if(!k)return;const Ne=N._activeChildContext,He=Ne&&k instanceof T.GroupElement,Se=[];_.forEach(V=>{V instanceof T.GroupElement?Se.push(...V.children):Se.push(V)});let Ae=rt.globalResizePipeline.executeResize({element:K.element,handle:K.handle,dx:ue,dy:et,startData:K.startData,allElements:Se,snapSystem:le}).element;if(N.updateResizeElement(Ae),He){const V=k.clone(),xe=V.children.findIndex(ne=>ne.id===Ne.childId);xe>=0&&(V.children[xe]=Ae,V.updateBoundsFromChildren(!0)),ve(V),xe>=0&&(st(V.children[xe]),ce.update(V.children[xe],A))}else ve(Ae),ce.update(Ae,A);ye(V=>V+1),te(le.getGuides())}else if(N.getMode()==="rotate"){ze.style.cursor="grabbing",O||(W(!0),ie==null||ie(!0));const ue=N._multiSelectionRotationContext;if(ue&&G.length>0){const Ae=ue.startBounds,V=N.updateRotate(Ce,X,Ae.centerX,Ae.centerY);ke(V),ue.elementsStartData.forEach(xe=>{const ne=xe.element,fe=xe.startData,Be=T.Transform.rotatePointAroundAnchor(fe.x,fe.y,Ae.centerX,Ae.centerY,V),Oe=ne.clone();Oe.x=Be.x,Oe.y=Be.y,Oe.setRotation(fe.rotation+V),ve(Oe)});return}const et=N._activeChildContext,K=et?Y:k;if(!K)return;const be=K.getBoundingBox(),Te=T.getBoundingBoxCenter(be),Ne=Te.x,He=Te.y,Se=N.updateRotate(Ce,X,Te.x,Te.y),_e=K.clone();if(_e.setRotation(Se),!(_e instanceof T.GroupElement)){const Ae=_e.getBoundingBox(),V=T.getBoundingBoxCenter(Ae),xe=Ne-V.x,ne=He-V.y;_e.x+=xe,_e.y+=ne}if(b.current=_e,ke(_e.rotation),Ke(Ae=>Ae+1),et&&k instanceof T.GroupElement){const Ae=k.clone(),V=Ae.children.findIndex(xe=>xe.id===et.childId);V>=0&&(Ae.children[V]=_e,Ae.updateBoundsFromChildren(!0)),ve(Ae),V>=0&&(st(Ae.children[V]),ce.update(Ae.children[V],A))}else ve(_e),ce.update(_e,A);ye(Ae=>Ae+1)}else{if(G.length>0&&w.current){const K=w.current,be=16/A,Te=[{x:K.minX,y:K.minY,anchor:"top-left",cursor:"nwse-resize"},{x:K.maxX,y:K.minY,anchor:"top-right",cursor:"nesw-resize"},{x:K.minX,y:K.maxY,anchor:"bottom-left",cursor:"nesw-resize"},{x:K.maxX,y:K.maxY,anchor:"bottom-right",cursor:"nwse-resize"}],Ne=K.rotation||0,He=Te.map(xe=>{if(Ne!==0){const ne=-Ne*Math.PI/180,fe=Math.cos(ne),Be=Math.sin(ne),Oe=xe.x-K.centerX,ot=xe.y-K.centerY;return{x:K.centerX+(Oe*fe-ot*Be),y:K.centerY+(Oe*Be+ot*fe),anchor:xe.anchor,cursor:xe.cursor}}return xe});for(const xe of He){const ne=Ce-xe.x,fe=X-xe.y;if(Math.sqrt(ne*ne+fe*fe)<=be){ze.style.cursor=xe.cursor,we({type:"multi-selection-handle",data:xe});return}}const Se=18/A;if(Math.sqrt(Math.pow(Ce-K.rotationHandleX,2)+Math.pow(X-K.rotationHandleY,2))<=Se){ze.style.cursor="grab",we({type:"multi-selection-rotation-handle",data:null});return}let Ae=Ce,V=X;if(Ne!==0){const xe=Ne*Math.PI/180,ne=Math.cos(xe),fe=Math.sin(xe),Be=Ce-K.centerX,Oe=X-K.centerY;Ae=K.centerX+(Be*ne-Oe*fe),V=K.centerY+(Be*fe+Oe*ne)}if(Ae>=K.minX&&Ae<=K.maxX&&V>=K.minY&&V<=K.maxY){ze.style.cursor="move",we({type:"multi-selection-bounds",data:K});return}}if(Q.altKey){let K=null;const be=ht();for(let Te=be.length-1;Te>=0;Te--){const Ne=be[Te];if(Ne.visible!==!1){if(Ne instanceof T.GroupElement)for(let He=Ne.children.length-1;He>=0;He--){const Se=Ne.children[He];if(Se.visible===!1)continue;const _e=Se.getVisualBoundingBox();if(Ce>=_e.x&&Ce<=_e.x+_e.width&&X>=_e.y&&X<=_e.y+_e.height){K=Se;break}}else{const He=Ne.getVisualBoundingBox();if(Ce>=He.x&&Ce<=He.x+He.width&&X>=He.y&&X<=He.y+He.height){K=Ne;break}}if(K)break}}if(K){const Te=[];be.forEach(He=>{He instanceof T.GroupElement?Te.push(...He.children):Te.push(He)});const Ne=Me.detectSpacing(K,Te,!0);he(Ne)}else he([])}else q.length>0&&he([]);const ue=Y||k;if(ue&&ue.visible!==!1)if(ue instanceof T.ImageElement&&ue.isCropping){const K=ue.hitTestCropHandle(Ce,X,A);if(K){const Te=T.getCursorForWorldPosition(K.worldX,K.worldY,ue.x,ue.y,K.type,ue.rotation,K.anchor);ze.style.cursor=Te,we({type:"crop-handle",data:K});return}const be=ce.hitTestResize(Ce,X,A);if(be){ze.style.cursor=be.cursor,we({type:"resize-handle",data:be});return}if(ue.hitTest(Ce,X)){ze.style.cursor="move",we({type:"element",data:ue});return}}else{if(ce.hitTestRotation(Ce,X,A)){ze.style.cursor="grab",we({type:"rotation-handle",data:null});return}const K=ce.hitTestResize(Ce,X,A);if(K){ze.style.cursor=K.cursor,we({type:"resize-handle",data:K});return}if(ue.hitTest(Ce,X)){ze.style.cursor="move",we({type:"element",data:ue});return}}if(Y&&k instanceof T.GroupElement)for(let K=k.children.length-1;K>=0;K--){const be=k.children[K];if(!(be.visible===!1||be.id===Y.id)&&be.hitTest(Ce,X)){ze.style.cursor="pointer",we({type:"group-sibling",data:be});return}}const et=ht();for(let K=et.length-1;K>=0;K--)if(et[K].visible!==!1&&!et[K].locked&&et[K].hitTest(Ce,X)){if(!ss(et[K],Ce,X,ae))continue;ze.style.cursor="pointer",we({type:"element",data:et[K]});return}ze.style.cursor="default",we({type:null,data:null})}},[N,k,ht,ve,ce,z,le,G,se,Y,ge,ye,A,Z,J,we,Me,he,q,L,gt,Ft]),F=l.useCallback(Q=>{var Ce,X,Mt,ue,et;if(Q.target.releasePointerCapture(Q.pointerId),Ee.current.delete(Q.pointerId),dt.current&&(Q.pointerId===dt.current.pointerA||Q.pointerId===dt.current.pointerB)){dt.current=null,Ee.current.clear();return}if(Ye.current&&Ye.current.pointerId===Q.pointerId){const K=Ye.current;Ye.current=null,K.movedPastThreshold||(((Ce=K.pendingTap)==null?void 0:Ce.kind)==="select-element"?(Ve(K.pendingTap.elementId),oe([])):((X=K.pendingTap)==null?void 0:X.kind)==="deselect"&&(Ve(null),oe([])));return}if(N.getMode()==="pinch"&&$e.current){const{a:K,b:be}=$e.current;if(Q.pointerId===K||Q.pointerId===be){const Ne=N.getContext().element,He=Qe.current??void 0;Ne&&tt(He,Ne),N.end(),$e.current=null,Qe.current=null,Ee.current.clear();return}}if(h.current&&(h.current=null),ge.isActive()&&ge.isDraggingHandle()){const K=ge.isClosingPath();if(ge.finishDraggingHandle(),K&&k instanceof T.PathElement){const be=k.clone();tt(k,be)}ye(be=>be+1);return}if(z){Tt(oe);return}g.current&&N.getMode()==="drag"&&(g.current.forEach((be,Te)=>{const Ne=_.find(He=>He.id===Te);Ne&&(be.x!==Ne.x||be.y!==Ne.y||be instanceof T.GroupElement&&Ne instanceof T.GroupElement&&JSON.stringify(be.children.map(Se=>({x:Se.x,y:Se.y})))!==JSON.stringify(Ne.children.map(Se=>({x:Se.x,y:Se.y}))))&&tt(be,Ne)}),g.current=null);const ze=t.current;if(ze&&(ze.style.cursor="default"),le.clearGuides(),le.clearSnapState(),te([]),Me.clearIndicators(),he([]),N._cropGroupContext&&delete N._cropGroupContext,N._activeChildContext){if(Y&&k instanceof T.GroupElement){const K=N.getContext(),Ne=(K._cachedElement&&K._cachedElement[k.id]||k).children.find(He=>He.id===Y.id);Ne&&(st(Ne),ce.update(Ne,A))}delete N._activeChildContext}if(N._multiSelectionResizeContext&&delete N._multiSelectionResizeContext,_.forEach(K=>{if(K instanceof T.CustomTransform&&K._lockedLineCount!==void 0){const be=K.clone();be._lockedLineCount=void 0,ve(be)}}),N._multiSelectionDragContext){const K=N._multiSelectionDragContext;if(K.startOBB&&K.currentDelta){const{dx:be,dy:Te}=K.currentDelta,Ne=K.startOBB;se.current={...Ne,centerX:Ne.centerX+be,centerY:Ne.centerY+Te}}delete N._multiSelectionDragContext}if(N._multiSelectionRotationContext){if(N.getMode()==="rotate"&&G.length>0&&se.current){const K=se.current;se.current={...K,rotation:K.rotation+N._multiSelectionRotationContext.currentRotation||K.rotation}}delete N._multiSelectionRotationContext}const nt=N.getContext();if(nt._cachedElement&&delete nt._cachedElement,N._pendingChildSelection){const K=N._pendingChildSelection;let be=!0;if(k instanceof T.GroupElement){const Te=N._groupDragOriginalElement;Te&&(be=!(Math.abs(k.x-Te.x)>.1||Math.abs(k.y-Te.y)>.1))}be&&(st(K),ce.update(K,A),ye(Te=>Te+1)),delete N._pendingChildSelection}if(N._pendingTextEditMode){const K=N._pendingTextEditMode,be=_.find(Ne=>Ne.id===K.elementId);!(be&&(Math.abs(be.x-K.originalX)>.1||Math.abs(be.y-K.originalY)>.1))&&be instanceof T.TextElement&&!(be instanceof T.ImageElement)&&!(be instanceof T.ShapeElement)&&Rt(be,K.clickX,K.clickY),delete N._pendingTextEditMode}if(Ue.current){const K=Ue.current,be=Xe.current,Te=_.find(_e=>_e.id===K),Ne=(Mt=g.current)==null?void 0:Mt.get(K),He=!!(Te&&Ne&&(Math.abs(Te.x-Ne.x)>.1||Math.abs(Te.y-Ne.y)>.1)),Se=be?Math.hypot((Q.clientX-(((ue=je.current)==null?void 0:ue.left)??0))/A-Z-be.x,(Q.clientY-(((et=je.current)==null?void 0:et.top)??0))/A-J-be.y)>4/Math.max(A,1e-4):!1;if(!He&&!Se&&K===(k==null?void 0:k.id)&&be){const _e=ht(),Ae=[];for(let xe=_e.length-1;xe>=0;xe--){const ne=_e[xe];ne.visible!==!1&&ne.hitTest(be.x,be.y)&&ss(ne,be.x,be.y,ae)&&Ae.push(ne)}const V=Ae.findIndex(xe=>xe.id===K);V!==-1&&V+1<Ae.length?Ve(Ae[V+1].id):Ve(null)}Ue.current=null,Xe.current=null}N._groupDragOriginalElement&&delete N._groupDragOriginalElement,N.end(),W(!1),ie==null||ie(!1),b.current=null,Ke(0),me({})},[N,le,z,oe,G,se,Y,k,st,ce,t,ge,ye,A,Z,J,ie,Rt,_,Ve,tt,ae]),ft=l.useCallback(Q=>{if(!k)return;const ze=t.current;if(!ze)return;const nt=je.current??ze.getBoundingClientRect(),Ce=(Q.clientX-nt.left)/A-Z,X=(Q.clientY-nt.top)/A-J;if(k.hitTest(Ce,X)){if(k instanceof T.GroupElement){const Oe=k.hitTestChild(Ce,X);if(Oe){if(!(Y&&Y.id===Oe.id))return;if(Oe instanceof T.TextElement&&!(Oe instanceof T.GroupElement)&&!(Oe instanceof T.ShapeElement)){const mt=Oe.getVisualBoundingBox(),_t=T.RotationUtils.toRadiansInverse(Oe.rotation),Wt=Oe.getRotationAnchor(),Bt=Ce-Wt.x,At=X-Wt.y,Dt=Math.cos(_t),rn=Math.sin(_t),Lt=Bt*Dt-At*rn,Ut=Bt*rn+At*Dt,an=Lt+mt.width/2,un=Ut+mt.height/2,Zt=Xn(Oe,{x:an,y:un}),Qt=mt.height+16,hn=6;jt({x:nt.left+(mt.x+Z)*A-hn,y:nt.top+(mt.y+J)*A-hn,width:Math.max(20,mt.width*A),height:Math.max(Qt*A,50)}),kt(De(Oe));const en=Oe.getRichText().clone();y.current=en,Kt(en);const xn=Oe.getRichText().getStyleAt(Math.max(0,Oe.text.length-1));Ot({...Oe.getDefaultStyle(),...xn}),Le(Zt),pe(Zt),U(Zt),$t(!0),v.current=Date.now(),x.current=Oe.id;return}}return}if(k instanceof T.PathElement){ge.editPath(k),ye(Oe=>Oe+1);return}if(k instanceof T.ShapeElement||!(k instanceof T.TextElement))return;const Mt=k.getVisualBoundingBox(),ue=T.RotationUtils.toRadiansInverse(k.rotation),et=k.getRotationAnchor(),K=Ce-et.x,be=X-et.y,Te=Math.cos(ue),Ne=Math.sin(ue),He=K*Te-be*Ne,Se=K*Ne+be*Te,_e=He+Mt.width/2,Ae=Se+Mt.height/2,V=Xn(k,{x:_e,y:Ae}),xe=Mt.height+16,ne=6;jt({x:nt.left+(Mt.x+Z)*A-ne,y:nt.top+(Mt.y+J)*A-ne,width:Math.max(20,Mt.width*A),height:Math.max(xe*A,50)}),kt(De(k));const fe=k.getRichText().clone();y.current=fe,Kt(fe);const Be=k.getRichText().getStyleAt(Math.max(0,k.text.length-1));Ot({...k.getDefaultStyle(),...Be}),Le(V),pe(V),U(V),$t(!0),v.current=Date.now()}},[k,ve,Y,ce,ge,ye,A,Z,J,jt,kt,Kt,Ot,Le,pe,U,$t,st,pt,De]),at=l.useCallback(Q=>{const ze=t.current;if(!ze||N.getMode()==="idle")return;const Ce=je.current??ze.getBoundingClientRect();if(Q.clientX>=Ce.left&&Q.clientX<=Ce.right&&Q.clientY>=Ce.top&&Q.clientY<=Ce.bottom)return;const Mt={clientX:Q.clientX,clientY:Q.clientY,altKey:Q.altKey,shiftKey:Q.shiftKey,ctrlKey:Q.ctrlKey,metaKey:Q.metaKey,bubbles:!0,cancelable:!0,currentTarget:ze,target:ze,nativeEvent:Q,type:"pointermove",pointerId:Q.pointerId||0,pointerType:Q.pointerType||"mouse",preventDefault:()=>Q.preventDefault(),stopPropagation:()=>Q.stopPropagation(),isPropagationStopped:()=>!1,isDefaultPrevented:()=>Q.defaultPrevented};it(Mt)},[it,t,N]),xt=l.useCallback(Q=>{const ze=t.current;if(!ze)return;const nt=Q.target,Ce=nt?ze.contains(nt):!1,X=Ee.current.has(Q.pointerId)||dt.current!==null||Ye.current!==null||$e.current!==null||N.isInteracting();if(!Ce&&!X)return;const Mt={clientX:Q.clientX,clientY:Q.clientY,currentTarget:ze,target:ze,pointerId:Q.pointerId||0,pointerType:Q.pointerType||"mouse"};F(Mt)},[F,t,N]);return l.useEffect(()=>(document.addEventListener("pointermove",at),document.addEventListener("pointerup",xt),()=>{document.removeEventListener("pointermove",at),document.removeEventListener("pointerup",xt)}),[at,xt]),{handlePointerDown:Je,handlePointerMove:it,handlePointerUp:F,handleDoubleClick:ft}}function po(e){if(e.transformType!=="custom")return e.text;const r=e.getVisualBoundingBox().width,o=e.getText();return T.wrapText(o,r,e.fontSize,e.fontFamily,e.bold,e.italic).join(`
13
+ `)}function ch(e){const{canvasRef:t,inputRef:r,editingChildIdRef:o,editRichTextRef:s,selectionAnchorRef:i,cursorStartTimeRef:a,lastMultiClickTimeRef:c,multiClickSelectionRef:d,editPositionUpdateTimerRef:u,draggingSelectionHandleRef:h,repositioningCursorRef:f,editModeEnteredAtRef:p,lastTouchTargetRef:g,MULTI_CLICK_DEBOUNCE:b,EDIT_MODE_BLUR_DEBOUNCE:x,isEditing:y,editText:v,editRichText:w,cursorPosition:C,selectionStart:j,selectionEnd:M,selectedId:S,selectedElement:R,activeChildElement:I,elements:D,zoom:E,paddingOffsetX:O,paddingOffsetY:z,setIsEditing:B,setEditText:k,setEditRichText:Y,setCursorPosition:_,setSelectionStart:G,setSelectionEnd:se,setEditPosition:A,setCurrentFormattingStyle:Z,setCursorAnimationFrame:J,setHandlesVersion:q,setElements:ae,onElementUpdate:Le,onTextSelectionChange:pe,transformHandles:U,updateActiveChild:W}=e,Ie=l.useCallback((N,ce,le)=>{const Me=t.current;if(!Me)return;const ge=Me.getBoundingClientRect(),L=N.getVisualBoundingBox(),ve=T.RotationUtils.toRadiansInverse(N.rotation),tt=N.getRotationAnchor(),Ve=ce-tt.x,oe=le-tt.y,ie=Math.cos(ve),pt=Math.sin(ve),st=Ve*ie-oe*pt,ht=Ve*pt+oe*ie,bt=st+L.width/2,yt=ht+L.height/2,Tt=Xn(N,{x:bt,y:yt}),Rt=L.height+16,jt=6;A({x:ge.left+(L.x+O)*E-jt,y:ge.top+(L.y+z)*E-jt,width:Math.max(20,L.width*E),height:Math.max(Rt*E,50)}),k(po(N));const kt=N.getRichText().clone();s.current=kt,Y(kt);const Kt=N.getRichText().getStyleAt(Math.max(0,N.text.length-1));Z({...N.getDefaultStyle(),...Kt}),_(Tt),G(Tt),se(Tt),B(!0),p.current=Date.now()},[E,A,k,Y,Z,_,G,se,B]),ke=l.useCallback(N=>{if(!y||!w)return;const ce=Math.min(j,M),le=Math.max(j,M);if(ce===le){const Me=w.clone(),ge=Me.getText().length;Me.applyStyle(0,ge,N),s.current=Me,Y(Me),k(Me.getText()),Z(L=>({...L,...N}))}else{const Me=w.clone();Me.applyStyle(ce,le,N),s.current=Me,Y(Me),k(Me.getText()),Z(ge=>({...ge,...N}))}},[y,w,j,M]),Ke=l.useCallback(()=>{if(!y||!w||!R)return null;const N=Math.min(j,M),ce=Math.max(j,M);return N===ce?N===0?R instanceof T.TextElement?R.getDefaultStyle():{}:w.getStyleAt(Math.max(0,N-1)):w.getStyleAt(N)},[y,w,j,M,R]),re=l.useCallback(N=>{if(!y||!w||!R)return;const ce=Ke(),ge=!{...R instanceof T.TextElement?R.getDefaultStyle():{},...ce}[N];ke({[N]:ge})},[y,w,R,Ke,ke]),te=l.useCallback(()=>{if(!y)return;const N=s.current||w;if(R&&N){const ce=o.current;if(ce&&R instanceof T.GroupElement){const le=R.clone(),Me=le.children.findIndex(L=>L.id===ce);if(Me>=0){const L=le.children[Me];L instanceof T.TextElement&&L.setRichText(N),le.updateBoundsFromChildren(!0)}Le(le);const ge=le.children[Me];ge&&(W(ge),U.update(ge,E),q(L=>L+1))}else if(R instanceof T.TextElement){const le=R.clone();le.setRichText(N),Le(le),U.update(le,E),q(Me=>Me+1)}}d.current=null,B(!1),k(""),Y(null),s.current=null,Z(null),o.current=null},[y,v,w,s,R,Le,U,W,E]),he=l.useCallback(()=>{if(Date.now()-c.current<b){if(r.current){r.current.focus();const le=d.current;le&&r.current.setSelectionRange(le.start,le.end)}return}setTimeout(()=>{var ve,tt,Ve;if(Date.now()-p.current<x){(ve=r.current)==null||ve.focus();return}if(f.current){f.current=!1,(tt=r.current)==null||tt.focus(),r.current&&r.current.setSelectionRange(j,M);return}let ge=document.activeElement,L=!1;for(;ge;){const oe=ge.classList,ie=ge.getAttribute("data-slot");if(ie&&(ie.includes("popover")||ie.includes("dialog"))){L=!0;break}if(ge.hasAttribute("data-preserve-selection")){L=!0;break}if(oe&&(oe.contains("toolbar")||oe.contains("toolbar-items")||oe.contains("toolbar-btn")||oe.contains("toolbar-btn-sm")||oe.contains("toolbar-btn-icon")||oe.contains("toolbar-color")||oe.contains("toolbar-label")||oe.contains("toolbar-select")||oe.contains("toolbar-select-sm")||oe.contains("toolbar-group")||oe.contains("toolbar-scroll")||oe.contains("toolbar-color-label")||oe.contains("toolbar-color-square")||oe.contains("color-picker-dropdown")||oe.contains("text-color-panel")||oe.contains("tooltip-wrapper")||oe.contains("font-dropdown-with-label")||oe.contains("font-family-select-button")||oe.contains("more-menu-btn")||oe.contains("more-menu-toolbar")||oe.contains("font-drawer-overlay")||oe.contains("font-drawer-content")||oe.contains("font-drawer-handle")||oe.contains("font-drawer-handle-bar")||oe.contains("font-dropdown-list-container")||oe.contains("font-dropdown-search")||oe.contains("font-search-input")||oe.contains("font-category-filters")||oe.contains("font-category-btn")||oe.contains("font-grid-option")||oe.contains("font-section")||oe.contains("font-section-header")||oe.contains("font-section-used")||oe.contains("font-section-header-used")||oe.contains("font-dropdown-list-grid")||oe.contains("font-dropdown-list-grid-used")||oe.contains("font-preview")||oe.contains("font-name-label")||oe.contains("font-size-slider-container")||oe.contains("font-size-slider")||oe.contains("font-size-icon-small")||oe.contains("font-size-icon-large")||oe.contains("font-icon-toggle")||oe.contains("font-dropdown-empty")||oe.contains("vaul-drawer-wrapper")||oe.contains("vaul-overlay"))){L=!0;break}ge=ge.parentElement}if(!L&&g.current)for(ge=g.current;ge;){const oe=ge.classList,ie=ge.getAttribute("data-slot");if(ie&&(ie.includes("popover")||ie.includes("dialog"))){L=!0;break}if(ge.hasAttribute("data-preserve-selection")){L=!0;break}if(oe&&(oe.contains("toolbar")||oe.contains("toolbar-items")||oe.contains("toolbar-btn")||oe.contains("toolbar-btn-sm")||oe.contains("toolbar-btn-icon")||oe.contains("toolbar-color")||oe.contains("toolbar-label")||oe.contains("toolbar-select")||oe.contains("toolbar-select-sm")||oe.contains("toolbar-group")||oe.contains("toolbar-scroll")||oe.contains("toolbar-color-label")||oe.contains("toolbar-color-square")||oe.contains("color-picker-dropdown")||oe.contains("text-color-panel")||oe.contains("tooltip-wrapper")||oe.contains("font-dropdown-with-label")||oe.contains("font-family-select-button")||oe.contains("more-menu-btn")||oe.contains("more-menu-toolbar")||oe.contains("vaul-drawer-wrapper")||oe.contains("vaul-overlay"))){L=!0;break}ge=ge.parentElement}if(!L)te();else{const oe=j,ie=M;(Ve=r.current)==null||Ve.focus(),r.current&&r.current.setSelectionRange(oe,ie)}},0)},[te,j,M]),ye=l.useCallback(N=>{const ce=N.currentTarget;if(N.key==="Enter"&&(N.metaKey||N.ctrlKey))N.preventDefault(),te();else if(N.key==="Escape")N.preventDefault(),N.stopPropagation(),B(!1),k(""),Y(null),s.current=null,Z(null),o.current=null;else if((N.metaKey||N.ctrlKey)&&N.key.toLowerCase()==="b")N.preventDefault(),re("bold");else if((N.metaKey||N.ctrlKey)&&N.key.toLowerCase()==="i")N.preventDefault(),re("italic");else if((N.metaKey||N.ctrlKey)&&N.key.toLowerCase()==="u")N.preventDefault(),re("underline");else if(N.key==="ArrowLeft"||N.key==="ArrowRight")setTimeout(()=>{const le=ce.selectionStart;_(le),G(le),se(ce.selectionEnd),i.current=le},0);else if(N.key==="ArrowUp"||N.key==="ArrowDown"){if(R&&R instanceof T.TextElement){N.preventDefault();const le=N.key==="ArrowUp"?"up":"down",Me=pd(R,C,le);_(Me),G(Me),se(Me),i.current=Me,ce.setSelectionRange(Me,Me)}}else(N.key==="Home"||N.key==="End")&&setTimeout(()=>{const le=ce.selectionStart;_(le),G(le),se(ce.selectionEnd),i.current=le},0)},[te,re,_,G,se,i,C,R]);l.useEffect(()=>{y&&(a.current=performance.now())},[y,C,a]),l.useEffect(()=>{if(!y)return;let N,ce=0;const le=33,Me=ge=>{ge-ce>=le&&(J(L=>(L+1)%1e3),ce=ge),N=requestAnimationFrame(Me)};return N=requestAnimationFrame(Me),()=>cancelAnimationFrame(N)},[y]);const we=l.useRef(!1);l.useEffect(()=>{if(y&&!we.current&&r.current){r.current.focus();const N=v.length;_(N),G(N),se(N),r.current.setSelectionRange(N,N)}we.current=y},[y,v]);const Pe=l.useRef(null),me=(N,ce)=>N===ce?!0:!N||!ce?!1:N.color===ce.color&&N.fontFamily===ce.fontFamily&&N.fontSize===ce.fontSize&&N.bold===ce.bold&&N.italic===ce.italic&&N.underline===ce.underline&&N.strikethrough===ce.strikethrough;return l.useEffect(()=>{if(!y||!w)return;const N=Math.min(j,M),ce=Math.max(j,M);if(N===ce){let le=null;if(N>0)le=w.getStyleAt(N-1);else{const Me=D.find(ge=>ge.id===S);Me instanceof T.TextElement&&(le=Me.getDefaultStyle())}le&&!me(le,Pe.current)&&(Pe.current=le,Z(le))}},[y,w,j,M,S]),l.useEffect(()=>{if(!y||!r.current)return;const N=r.current;(N.selectionStart!==j||N.selectionEnd!==M)&&(j!==M?N.setSelectionRange(j,M):N.setSelectionRange(C,C))},[v,y,C,j,M]),l.useEffect(()=>{const N=D.find(ce=>ce.id===S);if(!(!y||!N||!t.current||!r.current))return u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{let ce=N;if(o.current&&N instanceof T.GroupElement){const tt=N.children.find(Ve=>Ve.id===o.current);tt&&(ce=tt)}if(!(ce instanceof T.TextElement))return;const le=ce.clone();w&&le.setRichText(w);const Me=le.getVisualBoundingBox(),ge=t.current.getBoundingClientRect(),L=Me.height+16,ve=6;if(A({x:ge.left+(Me.x+O)*E-ve,y:ge.top+(Me.y+z)*E-ve,width:Math.max(20,Me.width*E),height:Math.max(L*E,50)}),o.current&&N instanceof T.GroupElement){const tt=N.clone(),Ve=tt.children.findIndex(oe=>oe.id===o.current);Ve>=0&&(tt.children[Ve]=le,tt.updateBoundsFromChildren(!0)),ae(oe=>oe.map(ie=>ie.id===tt.id?tt:ie)),U.update(le,E)}else ae(tt=>tt.map(Ve=>Ve.id===le.id?le:Ve)),U.update(le,E);q(tt=>tt+1)},50),()=>{u.current&&clearTimeout(u.current)}},[v,w,y,S,E]),l.useEffect(()=>{if(!y||!r.current)return;const N=r.current,ce=()=>{if(h.current||Date.now()-c.current<b)return;const ge=N.selectionStart||0,L=N.selectionEnd||0;_(ve=>ve===L?ve:L),G(ve=>ve===ge?ve:ge),se(ve=>ve===L?ve:L),pe==null||pe()};N.addEventListener("click",ce),N.addEventListener("keyup",ce),N.addEventListener("select",ce),N.addEventListener("mouseup",ce);const le=()=>{document.activeElement===N&&ce()};return document.addEventListener("selectionchange",le),ce(),()=>{N.removeEventListener("click",ce),N.removeEventListener("keyup",ce),N.removeEventListener("select",ce),N.removeEventListener("mouseup",ce),document.removeEventListener("selectionchange",le)}},[y]),l.useEffect(()=>{const N=ce=>{const le=ce.target;if(le.tagName==="INPUT"||le.tagName==="TEXTAREA"||ce.key!=="Enter"||y||!t.current)return;const Me=t.current.getBoundingClientRect();if(I&&I instanceof T.TextElement&&!(I instanceof T.GroupElement)&&!(I instanceof T.ImageElement)&&!(I instanceof T.ShapeElement)){ce.preventDefault();const ge=I.getVisualBoundingBox(),L=ge.height+16,ve=6;A({x:Me.left+(ge.x+O)*E-ve,y:Me.top+(ge.y+z)*E-ve,width:Math.max(200,ge.width*E),height:Math.max(L*E,50)}),k(po(I)),B(!0),p.current=Date.now(),o.current=I.id;return}if(R&&R instanceof T.TextElement&&!(R instanceof T.GroupElement)&&!(R instanceof T.ImageElement)&&!(R instanceof T.ShapeElement)){ce.preventDefault();const ge=R.getVisualBoundingBox(),L=ge.height+16,ve=6;A({x:Me.left+(ge.x+O)*E-ve,y:Me.top+(ge.y+z)*E-ve,width:Math.max(200,ge.width*E),height:Math.max(L*E,50)}),k(po(R)),B(!0),p.current=Date.now()}};return window.addEventListener("keydown",N),()=>window.removeEventListener("keydown",N)},[R,I,y]),{handleTextEditComplete:te,handleTextEditBlur:he,handleTextKeyDown:ye,applyFormattingToSelection:ke,getSelectionStyle:Ke,toggleFormattingProperty:re,enterTextEditMode:Ie,getWrappedTextForEditing:po}}const pl=l.forwardRef(({elements:e,artboards:t,artboardManager:r,selectedId:o,multiSelection:s,onElementUpdate:i,setElements:a,executeElementUpdate:c,onSelectionChange:d,onMultiSelectionChange:u,onActiveChildChange:h,onTextSelectionChange:f,onHoverChange:p,onRotationStateChange:g,onCropModeEnter:b,hideHandles:x=!1,canvasRef:y,width:v,height:w,zoom:C=1,offsetX:j=0,offsetY:M=0,viewPadding:S=1,artboardBorderRadius:R=0,fixedMargin:I,fixedMarginX:D,fixedMarginY:E,showRotationHandle:O=!0,canvasCutouts:z,pieceGuides:B,pieceFocus:k,focusedPieceRect:Y},_)=>{const{resolvedTheme:G}=Yt.useTheme(),se=l.useRef(null),A=y||se,Z=l.useRef(null),J=l.useRef(!1),q=l.useRef(0),ae=l.useRef(0),Le=l.useRef(0),pe=l.useRef(!1),U=l.useRef(0),W=l.useRef(null),Ie=l.useRef(0),ke=l.useRef(null),Ke=l.useRef({start:null,end:null}),re=l.useRef(null),te=l.useRef(null),he=l.useRef(null),ye=l.useRef(null),we=400,Pe=300,me=50,N=200,ce=l.useMemo(()=>{if(!k||k==="spread")return null;const Ze=(B==null?void 0:B.pieces)??[];if(Ze.length<=1)return null;const We=Ze.find(Ct=>Ct.id===k.pieceId);return We?{x:We.x,y:We.y,width:We.width,height:We.height}:null},[k,B]),le=Y!==void 0?Y:ce,Me=l.useMemo(()=>{if(le)return le;const Ze=(B==null?void 0:B.pieces)??[];if(Ze.length===1){const We=Ze[0];return{x:We.x,y:We.y,width:We.width,height:We.height}}return null},[le,B]),{isTouchDevice:ge,canvasSize:L,lastTouchTargetRef:ve,effectiveViewPadding:tt,paddedCanvasWidth:Ve,paddedCanvasHeight:oe,paddingOffsetX:ie,paddingOffsetY:pt,zoomInvariantBorderRadius:st}=wu({width:v,height:w,zoom:C,viewPadding:S,artboardBorderRadius:R,fixedMargin:I,fixedMarginX:D,fixedMarginY:E,artboards:t,artboardManager:r,focusedPieceRect:le}),{snapGuides:ht,setSnapGuides:bt,spacingIndicators:yt,setSpacingIndicators:Tt,isAltKeyPressed:Rt,setIsAltKeyPressed:jt,isRotating:kt,setIsRotating:Kt,setRotationStartAngle:$t,currentRotation:Ot,setCurrentRotation:De,setRotatingElementVersion:je}=Cu(),{renderVersion:Ee,forceRender:$e,handlesVersion:Qe,setHandlesVersion:Fe,forceUpdate:Ue,cursorAnimationFrame:Xe,setCursorAnimationFrame:dt}=Su({elements:e}),[Ye]=l.useState(()=>new rt.TransformHandles),[vt]=l.useState(()=>new rt.ArtboardRenderer({showBorder:!1,showLabel:!1})),[gt]=l.useState(()=>new rt.AlignmentSnapSystem({enabled:!0,showGuides:!0})),[Nt]=l.useState(()=>new rt.SpacingSystem({enabled:!0,showLabels:!0})),[Ft]=l.useState(()=>{const Ze=new rt.InteractionStateMachine;return Ze.setResizePipeline(rt.globalResizePipeline),Ze.setSnapHandler(gt),Ze});l.useEffect(()=>{vt.setOptions({borderRadius:st})},[st,vt]),l.useEffect(()=>{const Ze=Y!==void 0?Y:ce;gt.setExtraSnapRects(Ze?[{id:"focused-piece",...Ze}]:[])},[gt,Y,ce]);const $=l.useRef(e);$.current=e;const ee=e.find(Ze=>Ze.id===o),Je=l.useRef(ee);Je.current=ee;const[it,F]=l.useState("");l.useEffect(()=>{var We;if(!o)return;const Ze=e.find(Ct=>Ct.id===o);if(Ze)if(Ze instanceof T.TextElement){const Ct=((We=Ze.text)==null?void 0:We.slice(0,40))||"empty";F(`Selected text element: ${Ct}`)}else Ze instanceof T.ImageElement?F("Selected image element"):Ze instanceof T.GroupElement?F("Selected group"):F("Selected element")},[o,e]);const ft=l.useRef(r);ft.current=r;const at=l.useRef(new Map);l.useEffect(()=>{const Ze=We=>{const Ct=We,Et=ft.current.getActiveArtboardId(),It=at.current.get(Et)||[],Ht=[];return It.forEach(qt=>{qt instanceof T.GroupElement?Ht.push(...qt.children):Ht.push(qt)}),gt.snapDimensions(Ct,Ht,Ct.startData)};return rt.globalResizePipeline.addHook("afterResize",Ze),()=>{rt.globalResizePipeline.removeHook("afterResize",Ze)}},[gt]);const{cropController:xt}=bu(),{penTool:Q,penCursor:ze}=pu({selectedElement:ee}),{isEditing:nt,setIsEditing:Ce,editText:X,setEditText:Mt,editPosition:ue,setEditPosition:et,cursorPosition:K,setCursorPosition:be,selectionStart:Te,setSelectionStart:Ne,selectionEnd:He,setSelectionEnd:Se,cursorOpacityRef:_e,cursorStartTimeRef:Ae,selectionAnchorRef:V,didDragSelectRef:xe,editRichText:ne,setEditRichText:fe,editRichTextRef:Be,currentFormattingStyle:Oe,setCurrentFormattingStyle:ot}=vu({selectedElement:ee,ref:_});l.useEffect(()=>{const Ze=Date.now()-U.current,We=W.current;We&&Ze<Pe?(Te!==We.start||He!==We.end)&&(be(We.cursor),Ne(We.start),Se(We.end),Z.current&&Z.current.setSelectionRange(We.start,We.end)):We&&Ze>=Pe&&(W.current=null)},[Te,He,K]);const{isMarqueeSelecting:mt,marqueeStart:_t,marqueeEnd:Wt,marqueePreviewSelection:Bt,startMarqueeSelection:At,updateMarqueeSelection:Dt,finishMarqueeSelection:rn}=md(),{multiSelectionGroupBoundsRef:Lt,multiSelectionOBBRef:Ut}=yu(s),{activeChildElement:an,updateActiveChild:un,editingChildIdRef:Zt}=mu({elements:e,selectedElement:ee,transformHandles:Ye,onActiveChildChange:h}),{hoverState:Qt,setHoverState:hn}=gu({onHoverChange:p}),en=l.useMemo(()=>{const Ze=new Map;return e.forEach(We=>{const Ct=r.getArtboardIdForElement(We.id);Ze.has(Ct)||Ze.set(Ct,[]),Ze.get(Ct).push(We)}),Ze},[e,r]);at.current=en;const xn=l.useCallback(()=>{const Ze=r.getActiveArtboardId();return en.get(Ze)||[]},[en,r]);l.useEffect(()=>{const Ze=Et=>{if(!nt){if(Q.isActive()&&ee instanceof T.PathElement){if(Et.key==="Escape"){Et.preventDefault(),Q.finishPath();const It=ee.clone();c(ee,It),Fe(Ht=>Ht+1);return}else if(Et.key==="Backspace"||Et.key==="Delete"){Et.preventDefault(),Q.deleteLastPoint(),Fe(It=>It+1);return}}Et.altKey&&jt(!0)}},We=Et=>{Et.altKey||jt(!1)},Ct=Et=>{(!Et.relatedTarget||!Et.relatedTarget.ownerDocument)&&jt(!1)};return window.addEventListener("keydown",Ze),window.addEventListener("keyup",We),window.addEventListener("blur",Ct),()=>{window.removeEventListener("keydown",Ze),window.removeEventListener("keyup",We),window.removeEventListener("blur",Ct)}},[Q,ee,c,Fe,nt]),l.useEffect(()=>{if(!A.current||!re.current||Ft.getMode()==="drag"||Ft.getMode()==="resize")return;const{x:We,y:Ct}=re.current;if(Rt){let Et=null;const It=xn();for(let Ht=It.length-1;Ht>=0;Ht--){const qt=It[Ht];if(qt.visible!==!1){if(qt instanceof T.GroupElement)for(let Pt=qt.children.length-1;Pt>=0;Pt--){const St=qt.children[Pt];if(St.visible===!1)continue;const lt=St.getVisualBoundingBox();if(We>=lt.x&&We<=lt.x+lt.width&&Ct>=lt.y&&Ct<=lt.y+lt.height){Et=St;break}}else{const Pt=qt.getVisualBoundingBox();if(We>=Pt.x&&We<=Pt.x+Pt.width&&Ct>=Pt.y&&Ct<=Pt.y+Pt.height){Et=qt;break}}if(Et)break}}if(Et){const Ht=[];It.forEach(Pt=>{Pt instanceof T.GroupElement?Ht.push(...Pt.children):Ht.push(Pt)});const qt=Nt.detectSpacing(Et,Ht,!0);Tt(qt)}}else Tt([])},[Rt,xn,Nt,Ft]);const Yn=l.useRef(null);l.useEffect(()=>{const Ze=e.find(Ct=>Ct.id===o),We=an||Ze;if(We){const Ct=We.getBoundingBox(),Et=`${We.id}-${Ct.x}-${Ct.y}-${Ct.width}-${Ct.height}-${We.rotation}`;Yn.current!==Et&&(Yn.current=Et,Ye.update(We,C),Fe(It=>It+1))}},[o,an,Ye,C,e]);const{handleTextEditBlur:er,handleTextKeyDown:wn,applyFormattingToSelection:cr,getSelectionStyle:dr,toggleFormattingProperty:Gn,enterTextEditMode:tr,getWrappedTextForEditing:ln}=ch({canvasRef:A,inputRef:Z,editingChildIdRef:Zt,editRichTextRef:Be,selectionAnchorRef:V,cursorStartTimeRef:Ae,lastMultiClickTimeRef:U,multiClickSelectionRef:W,editPositionUpdateTimerRef:ye,draggingSelectionHandleRef:ke,repositioningCursorRef:J,editModeEnteredAtRef:Le,lastTouchTargetRef:ve,MULTI_CLICK_DEBOUNCE:Pe,EDIT_MODE_BLUR_DEBOUNCE:N,isEditing:nt,editText:X,editRichText:ne,cursorPosition:K,selectionStart:Te,selectionEnd:He,selectedId:o,selectedElement:ee,activeChildElement:an,elements:e,zoom:C,paddingOffsetX:ie,paddingOffsetY:pt,setIsEditing:Ce,setEditText:Mt,setEditRichText:fe,setCursorPosition:be,setSelectionStart:Ne,setSelectionEnd:Se,setEditPosition:et,setCurrentFormattingStyle:ot,setCursorAnimationFrame:dt,setHandlesVersion:Fe,setElements:a,onElementUpdate:i,onTextSelectionChange:f,transformHandles:Ye,updateActiveChild:un}),{handlePointerDown:Hn,handlePointerMove:$n,handlePointerUp:so,handleDoubleClick:Yo}=lh({canvasRef:A,inputRef:Z,repositioningCursorRef:J,lastClickTimeRef:q,clickCountRef:ae,lastProcessedClickTimeRef:Ie,lastMultiClickTimeRef:U,multiClickSelectionRef:W,skipDragSelectionRef:pe,draggingSelectionHandleRef:ke,selectionHandlePositionsRef:Ke,lastMousePosRef:re,dragOriginalElementsRef:te,rotatingElementRef:he,editingChildIdRef:Zt,editRichTextRef:Be,editModeEnteredAtRef:Le,multiSelectionGroupBoundsRef:Lt,MULTI_CLICK_THRESHOLD:we,MULTI_CLICK_DEBOUNCE:Pe,CLICK_DEDUP_THRESHOLD:me,isEditing:nt,editText:X,isTouchDevice:ge,selectionStart:Te,selectionEnd:He,isRotating:kt,isMarqueeSelecting:mt,isAltKeyPressed:Rt,selectedElement:ee,activeChildElement:an,elements:e,multiSelection:s,multiSelectionOBBRef:Ut,zoom:C,paddingOffsetX:ie,paddingOffsetY:pt,spacingIndicators:yt,focusedPieceRect:Me,setCursorPosition:be,setSelectionStart:Ne,setSelectionEnd:Se,setIsRotating:Kt,setRotationStartAngle:$t,setCurrentRotation:De,setRotatingElementVersion:je,setIsAltKeyPressed:jt,setSnapGuides:bt,setSpacingIndicators:Tt,setHandlesVersion:Fe,setHoverState:hn,setElements:a,forceUpdate:Ue,stateMachine:Ft,transformHandles:Ye,snapSystem:gt,spacingSystem:Nt,penTool:Q,cropController:xt,onElementUpdate:i,executeElementUpdate:c,onSelectionChange:d,onMultiSelectionChange:u,onRotationStateChange:g,onCropModeEnter:b,updateActiveChild:un,getActiveArtboardElements:xn,startMarqueeSelection:At,updateMarqueeSelection:Dt,finishMarqueeSelection:rn,enterTextEditMode:tr,setEditPosition:et,setEditText:Mt,setEditRichText:fe,setIsEditing:Ce,setCurrentFormattingStyle:ot,getWrappedTextForEditing:ln});Wu({canvasRef:A,elements:e,elementsByArtboard:en,artboards:t,artboardManager:r,artboardRenderer:vt,selectedId:o,selectedElement:ee,activeChildElement:an,editingChildIdRef:Zt,transformHandles:Ye,stateMachine:Ft,canvasSize:L,paddedCanvasWidth:Ve,paddedCanvasHeight:oe,paddingOffsetX:ie,paddingOffsetY:pt,zoom:C,zoomInvariantBorderRadius:st,effectiveViewPadding:tt,showRotationHandle:O,isRotating:kt,currentRotation:Ot,hoverState:Qt,isEditing:nt,editText:X,editRichText:ne,cursorPosition:K,selectionStart:Te,selectionEnd:He,cursorOpacityRef:_e,cursorStartTimeRef:Ae,isTouchDevice:ge,selectionHandlePositionsRef:Ke,multiClickSelectionRef:W,lastMultiClickTimeRef:U,MULTI_CLICK_DEBOUNCE:Pe,snapGuides:ht,spacingIndicators:yt,isAltKeyPressed:Rt,multiSelection:s,multiSelectionOBBRef:Ut,multiSelectionGroupBoundsRef:Lt,isMarqueeSelecting:mt,marqueeStart:_t,marqueeEnd:Wt,marqueePreviewSelection:Bt,penTool:Q,handlesVersion:Qe,hideHandles:x,resolvedTheme:G,cursorAnimationFrame:Xe,renderVersion:Ee,pieceGuides:B,focusedPieceId:k&&k!=="spread"?k.pieceId:null,focusedPieceRect:le}),l.useImperativeHandle(_,()=>({applyTextFormatting:Ze=>{cr(Ze)},toggleFormattingProperty:Ze=>{Gn(Ze)},isEditingText:()=>nt,isRotating:()=>kt,getSelectionStyle:()=>dr(),getZoom:()=>C,forceRender:$e,getEditingState:()=>({isEditing:nt,editText:X,cursorPosition:K,selectionStart:Te,selectionEnd:He}),getCropState:()=>({isCropping:ee instanceof T.ImageElement&&ee.isCropping,elementId:(ee==null?void 0:ee.id)||null}),getPaddingOffset:()=>({x:ie,y:pt})}),[cr,Gn,nt,kt,dr,C,$e,X,K,Te,He,ee,ie,pt]);const Wo=l.useMemo(()=>{if(!z||z.length===0)return;const Ze=Ve*C,We=oe*C,Ct=`M 0 0 h ${Ze} v ${We} h ${-Ze} Z`,Et=z.map(It=>{if(It.kind==="rect"||It.kind==="roundedRect"){const Ht=(ie+It.x)*C,qt=(pt+It.y)*C,Pt=It.width*C,St=It.height*C;if(It.kind==="roundedRect"){const lt=(It.rx??It.ry??0)*C,zt=(It.ry??It.rx??0)*C;if(lt>0||zt>0)return[`M ${Ht+lt} ${qt}`,`h ${Pt-2*lt}`,`a ${lt} ${zt} 0 0 1 ${lt} ${zt}`,`v ${St-2*zt}`,`a ${lt} ${zt} 0 0 1 ${-lt} ${zt}`,`h ${-(Pt-2*lt)}`,`a ${lt} ${zt} 0 0 1 ${-lt} ${-zt}`,`v ${-(St-2*zt)}`,`a ${lt} ${zt} 0 0 1 ${lt} ${-zt}`,"Z"].join(" ")}return`M ${Ht} ${qt} h ${Pt} v ${St} h ${-Pt} Z`}return""}).filter(Boolean);if(Et.length!==0)return`path(evenodd, "${Ct} ${Et.join(" ")}")`},[z,Ve,oe,ie,pt,C]);return n.jsxs(n.Fragment,{children:[n.jsx("div",{role:"status","aria-live":"polite","aria-atomic":"true",style:{position:"absolute",width:1,height:1,margin:-1,padding:0,overflow:"hidden",clip:"rect(0,0,0,0)",whiteSpace:"nowrap",borderWidth:0},children:it}),n.jsx("canvas",{role:"application","aria-label":"Design editor canvas. Use mouse or touch to select, move, and resize elements.",ref:A,onPointerDown:Hn,onPointerMove:$n,onPointerUp:so,onPointerCancel:so,onDoubleClick:Yo,style:{display:"block",background:B?"transparent":"var(--color-canvas-bg)",width:`${Ve*C}px`,height:`${oe*C}px`,cursor:Q.isActive()&&ee instanceof T.PathElement?ze:void 0,position:"absolute",left:`${j}px`,top:`${M}px`,touchAction:"none",clipPath:Wo}}),nt&&(()=>{let Ze=ee;if(Zt.current&&ee instanceof T.GroupElement){const St=ee.children.find(lt=>lt.id===Zt.current);St&&(Ze=St)}const We=Ze instanceof T.TextElement?Ze:null,Ct=(We==null?void 0:We.fontSize)||24,Et=(We==null?void 0:We.fontFamily)||"Arial",It=(We==null?void 0:We.bold)||!1,Ht=(We==null?void 0:We.italic)||!1,qt=(We==null?void 0:We.textAlign)||"center",Pt=n.jsx("textarea",{ref:Z,"data-preserve-selection":"",value:X,onChange:St=>{const lt=St.target.value;if(!ne){const dn=T.RichText.fromPlainText(lt,{});Be.current=dn,fe(dn),Mt(lt);const Kn=St.target.selectionEnd;be(Kn),Ne(St.target.selectionStart),Se(St.target.selectionEnd);return}const zt=X,Pn=ne.clone();let ut=0;for(;ut<zt.length&&ut<lt.length&&zt[ut]===lt[ut];)ut++;let cn=0;for(;cn<zt.length-ut&&cn<lt.length-ut&&zt[zt.length-1-cn]===lt[lt.length-1-cn];)cn++;const fn=ut,jn=zt.length-cn,Fn=lt.substring(ut,lt.length-cn);if(jn>fn&&Pn.delete(fn,jn),Fn.length>0){let dn;Oe?dn=Oe:fn>0?dn=Pn.getStyleAt(fn-1):ee instanceof T.TextElement?dn=ee.getDefaultStyle():dn={},Pn.insert(fn,Fn,dn)}Be.current=Pn,fe(Pn),Mt(lt);const Cn=St.target.selectionEnd;be(Cn),Ne(St.target.selectionStart),Se(St.target.selectionEnd),V.current=Cn;const En=St.target;setTimeout(()=>{En&&document.activeElement===En&&En.setSelectionRange(Cn,Cn)},0)},onBlur:er,onKeyDown:wn,onPointerDown:St=>{if(St.preventDefault(),!ee||!(ee instanceof T.TextElement)||!A.current)return;const lt=Date.now();if(lt-Ie.current<me)return;Ie.current=lt,lt-U.current>=Pe&&(W.current=null);const zt=A.current.getBoundingClientRect(),Pn=(St.clientX-zt.left)/C-ie,ut=(St.clientY-zt.top)/C-pt,cn=ee.getVisualBoundingBox(),fn=ee.getRotationAnchor(),jn=T.RotationUtils.toRadiansInverse(ee.rotation),Fn=Pn-fn.x,Cn=ut-fn.y,En=Math.cos(jn),dn=Math.sin(jn),Kn=Fn*En-Cn*dn,ur=Fn*dn+Cn*En,hr=Kn+cn.width/2,Un=ur+cn.height/2,pn=Xn(ee,{x:hr,y:Un});lt-q.current<we?ae.current+=1:ae.current=1,q.current=lt;const Sn=X;if(xe.current=!1,ae.current>=3)St.preventDefault(),U.current=lt,W.current={start:0,end:Sn.length,cursor:Sn.length},pe.current=!0,ae.current=0,V.current=0,be(Sn.length),Ne(0),Se(Sn.length),Z.current&&(Z.current.focus(),Z.current.setSelectionRange(0,Sn.length));else if(ae.current===2){St.preventDefault();const bn=Xa(Sn,pn);U.current=lt,W.current={start:bn.start,end:bn.end,cursor:bn.end},pe.current=!0,V.current=bn.start,be(bn.end),Ne(bn.start),Se(bn.end),Z.current&&(Z.current.focus(),Z.current.setSelectionRange(bn.start,bn.end))}else W.current=null,V.current=pn,Ne(pn),be(pn),Se(pn),Z.current&&(Z.current.focus(),Z.current.setSelectionRange(pn,pn)),pe.current=!1},onPointerMove:St=>{if(St.buttons!==1)return;if(ke.current&&ee instanceof T.TextElement&&A.current){const qn=A.current.getBoundingClientRect(),Sn=(St.clientX-qn.left)/C-ie,bn=(St.clientY-qn.top)/C-pt,Sr=ee.getVisualBoundingBox(),kr=ee.getRotationAnchor(),jr=T.RotationUtils.toRadiansInverse(ee.rotation),io=Sn-kr.x,ao=bn-kr.y,lo=Math.cos(jr),co=Math.sin(jr),Xo=io*lo-ao*co,Vo=io*co+ao*lo,Tn=Ke.current;let Er=0;ke.current==="start"&&(Tn!=null&&Tn.start)?Er=Tn.start.textEdge.y-Tn.start.center.y:ke.current==="end"&&(Tn!=null&&Tn.end)&&(Er=Tn.end.textEdge.y-Tn.end.center.y);const Go=Xo+Sr.width/2,Ko=Vo+Er+Sr.height/2,Rn=Xn(ee,{x:Go,y:Ko});if(ke.current==="start"?Rn<=He?(Ne(Rn),be(Rn)):(Ne(He),Se(Rn),be(Rn),ke.current="end"):Rn>=Te?(Se(Rn),be(Rn)):(Se(Te),Ne(Rn),be(Rn),ke.current="start"),Z.current){const qo=Math.min(Te,He),Zo=Math.max(Te,He);Z.current.setSelectionRange(qo,Zo)}return}if(pe.current||!ee||!(ee instanceof T.TextElement)||!A.current)return;const lt=A.current.getBoundingClientRect(),zt=(St.clientX-lt.left)/C-ie,Pn=(St.clientY-lt.top)/C-pt,ut=ee.getVisualBoundingBox(),cn=ee.getRotationAnchor(),fn=T.RotationUtils.toRadiansInverse(ee.rotation),jn=zt-cn.x,Fn=Pn-cn.y,Cn=Math.cos(fn),En=Math.sin(fn),dn=jn*Cn-Fn*En,Kn=jn*En+Fn*Cn,ur=dn+ut.width/2,hr=Kn+ut.height/2,Un=Xn(ee,{x:ur,y:hr}),pn=V.current;if(pn!==Un&&(xe.current=!0),Se(Un),be(Un),Ne(pn),Z.current){const qn=Math.min(pn,Un),Sn=Math.max(pn,Un);Z.current.setSelectionRange(qn,Sn)}},onPointerUp:()=>{ke.current&&(ke.current=null)},onClick:()=>{xe.current=!1,pe.current=!1},onSelect:()=>{},autoFocus:!0,spellCheck:!1,style:{position:"fixed",left:`${ue.x}px`,top:`${ue.y}px`,width:`${ue.width}px`,height:`${ue.height||50}px`,fontSize:`${Ct*C}px`,fontFamily:`"${Et}", Arial, sans-serif`,fontWeight:It?700:400,fontStyle:Ht?"italic":"normal",textAlign:qt,lineHeight:1.2,opacity:0,zIndex:1001,resize:"none",border:"2px solid transparent",outline:"none",padding:"4px",margin:"0",overflow:"hidden",color:"transparent",background:"transparent",caretColor:"transparent",whiteSpace:"pre-wrap",wordBreak:"normal",overflowWrap:"normal"}});return Qn.createPortal(Pt,document.body)})()]})});pl.displayName="CanvasEditor";const dh=.25,uh=8,hh=.1,fh=4,ph=.001,mh=({className:e,style:t,width:r,height:o,zoom:s,fitPadding:i=.95,interactive:a=!1,artboardBorderRadius:c=0,fixedMargin:d,maxHeight:u,showRotationHandle:h=!0,enableShortcuts:f=!0,canvasCutouts:p,pieceGuides:g,pieceFocus:b})=>{var Ot;const{canvasEditorRef:x,canvasRef:y,elements:v,artboards:w,artboardManager:C,handleElementUpdate:j,setElements:M,executeElementUpdate:S}=Yt.useEditor(),{zoom:R,setZoom:I,panOffset:D,setPanOffset:E,isPanning:O,setIsPanning:z,userZoom:B,setUserZoom:k,resetUserView:Y}=Yt.useViewportContext(),{selectedId:_,multiSelection:G,handleSelectionChange:se,setMultiSelection:A,handleActiveChildChange:Z,setHoveredElementId:J,hideHandles:q}=Yt.useSelectionContext(),{setTextSelectionVersion:ae,setExpandedPanelType:Le}=Yt.useToolStateContext(),pe=l.useCallback(()=>{Le("crop")},[Le]),U=l.useRef(null),[W,Ie]=l.useState(0),[ke,Ke]=l.useState(0),[re,te]=l.useState(!1),he=l.useRef(0),ye=l.useRef(!1),[we,Pe]=l.useState(!1),me=l.useRef(null);cd({enabled:f});const N=C.getActiveArtboard(),ce=l.useCallback(De=>{if(!(a||De.ctrlKey||De.metaKey))return;De.preventDefault();const Ee=U.current;if(!Ee)return;const $e=Ee.getBoundingClientRect(),Qe=De.clientX-$e.left,Fe=De.clientY-$e.top,Ue=-De.deltaY*ph;if(a){const Xe=W,dt=Math.min(Math.max(Xe*(1+Ue),hh),fh);if(dt===Xe)return;const Ye=dt/Xe,vt=Qe-(Qe-D.x)*Ye,gt=Fe-(Fe-D.y)*Ye;Ie(dt),E({x:vt,y:gt})}else{const Xe=B,dt=Math.min(Math.max(Xe*(1+Ue),dh),uh);if(dt===Xe)return;const Ye=dt/Xe,vt=Qe-(Qe-D.x)*Ye,gt=Fe-(Fe-D.y)*Ye;k(dt),E({x:vt,y:gt})}},[a,W,D,E,B,k]);l.useEffect(()=>{const De=U.current;if(De)return De.addEventListener("wheel",ce,{passive:!1}),()=>De.removeEventListener("wheel",ce)},[ce]),l.useEffect(()=>{if(!a)return;const De=Ee=>{Ee.code==="Space"&&!Ee.repeat&&Pe(!0)},je=Ee=>{Ee.code==="Space"&&(Pe(!1),me.current=null)};return window.addEventListener("keydown",De),window.addEventListener("keyup",je),()=>{window.removeEventListener("keydown",De),window.removeEventListener("keyup",je)}},[a]);const le=l.useCallback(De=>{if(!a)return;const je=De.button===1,Ee=we&&De.button===0;(je||Ee)&&(De.preventDefault(),De.target.setPointerCapture(De.pointerId),z(!0),me.current={x:De.clientX,y:De.clientY,panX:D.x,panY:D.y})},[a,we,D,z]),Me=l.useCallback(De=>{if(!O||!me.current)return;const je=De.clientX-me.current.x,Ee=De.clientY-me.current.y;E({x:me.current.panX+je,y:me.current.panY+Ee})},[O,E]),ge=l.useCallback(De=>{O&&(De&&De.target.releasePointerCapture(De.pointerId),z(!1),me.current=null)},[O,z]);l.useEffect(()=>{if(!a||!O)return;const De=()=>{z(!1),me.current=null};return window.addEventListener("pointerup",De),()=>window.removeEventListener("pointerup",De)},[a,O,z]);const L=l.useMemo(()=>{if(!b||!g)return null;const De=g.pieces??[];if(De.length<=1)return null;if(b==="spread")return N?{x:0,y:0,width:N.width,height:N.height}:null;const je=De.find(Ee=>Ee.id===b.pieceId);return je?{x:je.x,y:je.y,width:je.width,height:je.height}:null},[b,g,N]),ve=hd(L);l.useEffect(()=>{if(s!==void 0){Ie(s);return}if(!U.current||!N)return;let De=0;const je=()=>{if(!U.current||!N)return;const Qe=U.current.clientWidth;if(Qe===0)return;let Fe=N.width,Ue=N.height;if(b&&b!=="spread"&&g){const Ye=g.pieces??[];if(Ye.length>1){const vt=Ye.find(gt=>gt.id===b.pieceId);vt&&(Fe=vt.width,Ue=vt.height)}}let Xe,dt=!1;if(d!==void 0){const Ye=Qe-d*2,vt=Math.min(Ye/Fe,1);if(ve&&u!==void 0){const gt=u-d*2,Nt=Math.min(gt/Ue,1);Xe=Math.min(vt,Nt),dt=Nt<=vt}else if(Xe=vt,u!==void 0&&Ue*Xe+d*2>u){const $=(u-d*2)/Ue;Xe=Math.min(Xe,$,1),dt=!0}}else Xe=Math.min(Qe*i/Fe,1);Ie(Xe),Ke(Qe),te(dt)};let Ee=!1;ye.current?je():De=requestAnimationFrame(()=>{De=requestAnimationFrame(()=>{Ee||(je(),ye.current=!0)})});const $e=new ResizeObserver(()=>{je()});return $e.observe(U.current),()=>{Ee=!0,cancelAnimationFrame(De),$e.disconnect()}},[s,N,i,d,u,b,g,ve]);const tt=W>0&&B>0?W*B:W;l.useEffect(()=>{he.current=tt,I(tt)},[tt,I]);const Ve=l.useRef(null);l.useEffect(()=>{const De=ve&&"id"in ve?ve.id??null:null;De!==Ve.current&&(Ve.current!==null&&Y(),Ve.current=De)},[ve,Y]),l.useEffect(()=>{a&&R!==he.current&&R>0&&(Ie(R),he.current=R)},[a,R]);const oe=ve?ve.width:(N==null?void 0:N.width)??0,ie=ve?ve.height:(N==null?void 0:N.height)??0,pt=oe*tt,st=ie*tt,ht=oe*W;let bt=N?d!==void 0?st+d*2:st/i:0;u!==void 0&&bt>u&&(bt=u);let yt=d,Tt=d;const Rt=((Ot=U.current)==null?void 0:Ot.clientWidth)||ke;d!==void 0&&re&&Rt>0&&ht>0&&(yt=(Rt-ht)/2);const jt=bt,kt=l.useRef({w:0,h:0});l.useEffect(()=>{const De=U.current;if(!De)return;kt.current={w:De.clientWidth,h:De.clientHeight};const je=new ResizeObserver(Ee=>{const $e=Ee[0];$e&&(kt.current={w:$e.contentRect.width,h:$e.contentRect.height})});return je.observe(De),()=>je.disconnect()},[]),l.useEffect(()=>{if(a)return;if(B<=1.001){(D.x!==0||D.y!==0)&&E({x:0,y:0});return}const De=kt.current.w,je=kt.current.h;if(De===0||je===0||pt===0||st===0)return;const Ee=.25*Math.min(pt,De),$e=.25*Math.min(st,je),Qe=Ee-(yt??0)-pt,Fe=De-Ee-(yt??0),Ue=$e-(Tt??0)-st,Xe=je-$e-(Tt??0),dt=Math.max(Qe,Math.min(Fe,D.x)),Ye=Math.max(Ue,Math.min(Xe,D.y));(dt!==D.x||Ye!==D.y)&&E({x:dt,y:Ye})},[a,B,D,pt,st,yt,Tt,E]);const Kt=a?{position:"relative",width:r?`${r}px`:"100%",height:o?`${o}px`:"100%",overflow:"hidden",cursor:O?"grabbing":we?"grab":"default",touchAction:"none",overscrollBehaviorX:"none",...t}:{position:"relative",width:r?`${r}px`:"100%",height:o?`${o}px`:jt>0?`${jt}px`:"auto",overflow:"hidden",touchAction:"none",overscrollBehaviorX:"none",...t},$t=a?{position:"absolute",left:0,top:0,transform:`translate(${D.x}px, ${D.y}px)`,transformOrigin:"0 0",pointerEvents:O?"none":"auto"}:{transform:D.x!==0||D.y!==0?`translate(${D.x}px, ${D.y}px)`:void 0,transformOrigin:"0 0",willChange:D.x!==0||D.y!==0?"transform":void 0};return n.jsxs("div",{ref:U,className:e,style:Kt,onPointerDown:a?le:void 0,onPointerMove:a?Me:void 0,onPointerUp:a?ge:void 0,onPointerLeave:a?ge:void 0,onPointerCancel:a?ge:void 0,children:[n.jsx("div",{style:$t,children:n.jsx(pl,{ref:x,elements:v,artboards:w,artboardManager:C,selectedId:_,multiSelection:G,onElementUpdate:j,setElements:M,executeElementUpdate:S,onSelectionChange:se,onMultiSelectionChange:A,onActiveChildChange:Z,onTextSelectionChange:()=>ae(De=>De+1),onHoverChange:J,onCropModeEnter:pe,hideHandles:q,canvasRef:y,width:N==null?void 0:N.width,height:N==null?void 0:N.height,zoom:tt,viewPadding:i,artboardBorderRadius:c,fixedMargin:d,fixedMarginX:yt,fixedMarginY:Tt,showRotationHandle:h,canvasCutouts:p,pieceGuides:g,pieceFocus:b,focusedPieceRect:ve})}),!a&&(B<.999||B>1.001)&&n.jsx(xh,{userZoom:B,onSetZoom:De=>{if(De<=1.001){Y();return}const je=U.current;if(!je){k(De);return}const Ee=je.getBoundingClientRect(),$e=Ee.width/2,Qe=Ee.height/2,Fe=De/Math.max(B,1e-4);k(De),E({x:$e-($e-D.x)*Fe,y:Qe-(Qe-D.y)*Fe})}})]})},gh=[1,2,4,8];function xh({userZoom:e,onSetZoom:t}){const r=Math.round(e*100),[o,s]=l.useState(!1);return n.jsxs("div",{style:{position:"absolute",bottom:12,right:12,zIndex:30,pointerEvents:"auto"},"data-preserve-selection":!0,children:[o&&n.jsxs(n.Fragment,{children:[n.jsx("div",{onClick:()=>s(!1),style:{position:"fixed",inset:0,zIndex:29}}),n.jsx("div",{role:"menu",style:{position:"absolute",bottom:"calc(100% + 6px)",right:0,zIndex:31,minWidth:96,backdropFilter:"blur(6px)"},className:"flex flex-col rounded-2xl border border-border/40 bg-popover/95 p-1 shadow-lg",children:gh.map(i=>{const a=i*100,c=Math.abs(e-i)<.05;return n.jsxs("button",{type:"button",role:"menuitem",onClick:()=>{s(!1),t(i)},className:c?"rounded-xl bg-foreground/10 px-4 py-2 text-base font-medium tabular-nums text-foreground text-right":"rounded-xl px-4 py-2 text-base font-medium tabular-nums text-foreground/80 hover:bg-foreground/5 hover:text-foreground text-right",children:[a,"%"]},i)})})]}),n.jsx("div",{className:"flex items-center gap-1 rounded-full border border-border/40 bg-popover/85 p-1 shadow-sm",style:{backdropFilter:"blur(6px)"},children:n.jsxs("button",{type:"button",onClick:()=>s(i=>!i),"aria-haspopup":"menu","aria-expanded":o,"aria-label":"Zoom level",className:"rounded-full px-4 py-1.5 text-base font-medium tabular-nums text-foreground/80 hover:text-foreground",style:{minWidth:72},children:[r,"%"]})})]})}const Jr=new Map;function Gt(e,t){Jr.set(e,t)}function bh(e){return Jr.get(e)}function yh(){return Array.from(Jr.keys())}function vh(){return Array.from(Jr.entries())}function wh(e){Jr.delete(e)}let jo=!1;async function Ch(){if(jo)return;jo=!0;const[{LayersPanel:e},{EffectsPanel:t},{ExportPanel:r},{ImagePanel:o},{GlyphPanel:s},{ArtboardTabs:i},{ContextualToolbars:a},{ZoomControls:c},{MenuButton:d},{CropPanel:u}]=await Promise.all([Promise.resolve().then(()=>vp),Promise.resolve().then(()=>um),Promise.resolve().then(()=>fm),Promise.resolve().then(()=>Rm),Promise.resolve().then(()=>Im),Promise.resolve().then(()=>Am),Promise.resolve().then(()=>Lg),Promise.resolve().then(()=>Pg),Promise.resolve().then(()=>Fg),Promise.resolve().then(()=>eg)]);Gt("layers-panel",{component:e,label:"Layers",icon:"gravity-ui:layers",position:"left"}),Gt("effects-panel",{component:t,label:"Effects",icon:"gravity-ui:sparkles",position:"right"}),Gt("export-panel",{component:r,label:"Export",icon:"gravity-ui:arrow-down-to-square",position:"right"}),Gt("images-panel",{component:o,label:"Images",icon:"gravity-ui:picture",position:"right"}),Gt("glyph-panel",{component:s,label:"Glyphs",icon:"gravity-ui:text",position:"right"}),Gt("artboard-tabs",{component:i,label:"Artboards",icon:"gravity-ui:copy",position:"topbar"}),Gt("contextual-toolbar",{component:a,label:"Contextual Toolbar",position:"topbar"}),Gt("zoom-controls",{component:c,label:"Zoom",icon:"gravity-ui:magnifier",position:"bottombar"}),Gt("menu-button",{component:d,label:"Menu",icon:"gravity-ui:bars",position:"topbar"}),Gt("crop-panel",{component:u,label:"Crop",icon:"gravity-ui:scissors",position:"right"})}function Sh(e){jo||(jo=!0,Gt("layers-panel",{component:e.LayersPanel,label:"Layers",icon:"gravity-ui:layers",position:"left"}),Gt("effects-panel",{component:e.EffectsPanel,label:"Effects",icon:"gravity-ui:sparkles",position:"right"}),Gt("export-panel",{component:e.ExportPanel,label:"Export",icon:"gravity-ui:arrow-down-to-square",position:"right"}),Gt("images-panel",{component:e.ImagePanel,label:"Images",icon:"gravity-ui:picture",position:"right"}),Gt("glyph-panel",{component:e.GlyphPanel,label:"Glyphs",icon:"gravity-ui:text",position:"right"}),Gt("artboard-tabs",{component:e.ArtboardTabs,label:"Artboards",icon:"gravity-ui:copy",position:"topbar"}),Gt("contextual-toolbar",{component:e.ContextualToolbars,label:"Contextual Toolbar",position:"topbar"}),Gt("zoom-controls",{component:e.ZoomControls,label:"Zoom",icon:"gravity-ui:magnifier",position:"bottombar"}),Gt("menu-button",{component:e.MenuButton,label:"Menu",icon:"gravity-ui:bars",position:"topbar"}),Gt("crop-panel",{component:e.CropPanel,label:"Crop",icon:"gravity-ui:scissors",position:"right"}))}const is=T.createLogger("useArtboards"),Qr=()=>{const{artboards:e,artboardManager:t,refreshArtboards:r,setSelectedId:o,setMultiSelection:s}=Yt.useEditor(),i=t.getActiveArtboardId(),a=t.getActiveArtboard(),c=l.useMemo(()=>e.map(y=>{const w=t.getElementsOnArtboard(y.id).length;return{id:y.id,name:y.name,x:y.x,y:y.y,width:y.width,height:y.height,backgroundColor:y.backgroundColor,clipShape:y.clipShape,isActive:y.id===i,elementCount:w}}),[e,t,i]),d=l.useMemo(()=>{if(!a)return null;const v=t.getElementsOnArtboard(a.id).length;return{id:a.id,name:a.name,x:a.x,y:a.y,width:a.width,height:a.height,backgroundColor:a.backgroundColor,clipShape:a.clipShape,isActive:!0,elementCount:v}},[a,t]),u=l.useCallback((y=1200,v=1200,w)=>{const C={width:y,height:v,...w};t.createArtboard(C),r()},[t,r]),h=l.useCallback(y=>{t.deleteArtboard(y),r()},[t,r]),f=l.useCallback(y=>{const v=e.find(w=>w.id===y);if(!v){is.warn(`[useArtboards] Artboard ${y} not found`);return}t.createArtboard({width:v.width,height:v.height,name:`${v.name} Copy`,backgroundColor:v.backgroundColor,clipShape:v.clipShape}),r()},[e,t,r]),p=l.useCallback((y,v)=>{const w=e.find(C=>C.id===y);if(!w){is.warn(`[useArtboards] Artboard ${y} not found`);return}w.name=v,r()},[e,r]),g=l.useCallback((y,v)=>{const w=e.find(C=>C.id===y);if(!w){is.warn(`[useArtboards] Artboard ${y} not found`);return}v.name!==void 0&&(w.name=v.name),v.width!==void 0&&(w.width=v.width),v.height!==void 0&&(w.height=v.height),v.backgroundColor!==void 0&&(w.backgroundColor=v.backgroundColor),v.clipShape!==void 0&&(w.clipShape=v.clipShape),"distressTexture"in v&&(w.distressTexture=v.distressTexture?{...v.distressTexture}:void 0),r()},[e,r]),b=l.useCallback(y=>{o(null),s([]),t.setActiveArtboard(y),r()},[t,r,o,s]),x=l.useCallback((y,v)=>{y!==v&&(y<0||y>=e.length||v<0||v>=e.length||([...e],t.reorderArtboards(y,v),r()))},[e,t,r]);return{artboards:e,artboardsInfo:c,activeArtboard:a,activeArtboardId:i,activeArtboardInfo:d,createArtboard:u,deleteArtboard:h,duplicateArtboard:f,renameArtboard:p,updateArtboard:g,selectArtboard:b,reorderArtboards:x,count:e.length}},Lo=typeof window<"u"&&typeof window.document<"u"&&typeof window.document.createElement<"u";function wr(e){const t=Object.prototype.toString.call(e);return t==="[object Window]"||t==="[object global]"}function oi(e){return"nodeType"in e}function gn(e){var t,r;return e?wr(e)?e:oi(e)&&(t=(r=e.ownerDocument)==null?void 0:r.defaultView)!=null?t:window:window}function si(e){const{Document:t}=gn(e);return e instanceof t}function eo(e){return wr(e)?!1:e instanceof gn(e).HTMLElement}function ml(e){return e instanceof gn(e).SVGElement}function Cr(e){return e?wr(e)?e.document:oi(e)?si(e)?e:eo(e)||ml(e)?e.ownerDocument:document:document:document}const Vn=Lo?l.useLayoutEffect:l.useEffect;function Po(e){const t=l.useRef(e);return Vn(()=>{t.current=e}),l.useCallback(function(){for(var r=arguments.length,o=new Array(r),s=0;s<r;s++)o[s]=arguments[s];return t.current==null?void 0:t.current(...o)},[])}function kh(){const e=l.useRef(null),t=l.useCallback((o,s)=>{e.current=setInterval(o,s)},[]),r=l.useCallback(()=>{e.current!==null&&(clearInterval(e.current),e.current=null)},[]);return[t,r]}function Wr(e,t){t===void 0&&(t=[e]);const r=l.useRef(e);return Vn(()=>{r.current!==e&&(r.current=e)},t),r}function to(e,t){const r=l.useRef();return l.useMemo(()=>{const o=e(r.current);return r.current=o,o},[...t])}function Eo(e){const t=Po(e),r=l.useRef(null),o=l.useCallback(s=>{s!==r.current&&(t==null||t(s,r.current)),r.current=s},[]);return[r,o]}function To(e){const t=l.useRef();return l.useEffect(()=>{t.current=e},[e]),t.current}let as={};function Fo(e,t){return l.useMemo(()=>{if(t)return t;const r=as[e]==null?0:as[e]+1;return as[e]=r,e+"-"+r},[e,t])}function gl(e){return function(t){for(var r=arguments.length,o=new Array(r>1?r-1:0),s=1;s<r;s++)o[s-1]=arguments[s];return o.reduce((i,a)=>{const c=Object.entries(a);for(const[d,u]of c){const h=i[d];h!=null&&(i[d]=h+e*u)}return i},{...t})}}const yr=gl(1),Xr=gl(-1);function jh(e){return"clientX"in e&&"clientY"in e}function ii(e){if(!e)return!1;const{KeyboardEvent:t}=gn(e.target);return t&&e instanceof t}function Eh(e){if(!e)return!1;const{TouchEvent:t}=gn(e.target);return t&&e instanceof t}function Ro(e){if(Eh(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:r}=e.touches[0];return{x:t,y:r}}else if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:r}=e.changedTouches[0];return{x:t,y:r}}}return jh(e)?{x:e.clientX,y:e.clientY}:null}const Vr=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:r}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(r?Math.round(r):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:r}=e;return"scaleX("+t+") scaleY("+r+")"}},Transform:{toString(e){if(e)return[Vr.Translate.toString(e),Vr.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:r,easing:o}=e;return t+" "+r+"ms "+o}}}),ta="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";function Th(e){return e.matches(ta)?e:e.querySelector(ta)}const Rh={display:"none"};function Nh(e){let{id:t,value:r}=e;return l.createElement("div",{id:t,style:Rh},r)}function Mh(e){let{id:t,announcement:r,ariaLiveType:o="assertive"}=e;const s={position:"fixed",top:0,left:0,width:1,height:1,margin:-1,border:0,padding:0,overflow:"hidden",clip:"rect(0 0 0 0)",clipPath:"inset(100%)",whiteSpace:"nowrap"};return l.createElement("div",{id:t,style:s,role:"status","aria-live":o,"aria-atomic":!0},r)}function Ih(){const[e,t]=l.useState("");return{announce:l.useCallback(o=>{o!=null&&t(o)},[]),announcement:e}}const xl=l.createContext(null);function Ah(e){const t=l.useContext(xl);l.useEffect(()=>{if(!t)throw new Error("useDndMonitor must be used within a children of <DndContext>");return t(e)},[e,t])}function Dh(){const[e]=l.useState(()=>new Set),t=l.useCallback(o=>(e.add(o),()=>e.delete(o)),[e]);return[l.useCallback(o=>{let{type:s,event:i}=o;e.forEach(a=>{var c;return(c=a[s])==null?void 0:c.call(a,i)})},[e]),t]}const Lh={draggable:`
14
14
  To pick up a draggable item, press the space bar.
15
15
  While dragging, use the arrow keys to move the item.
16
16
  Press space again to drop the item in its new position, or press escape to cancel.
17
- `},Dh={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:r}=e;return r?"Draggable item "+t.id+" was moved over droppable area "+r.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:r}=e;return r?"Draggable item "+t.id+" was dropped over droppable area "+r.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function Lh(e){let{announcements:t=Dh,container:r,hiddenTextDescribedById:o,screenReaderInstructions:s=Ah}=e;const{announce:i,announcement:a}=Nh(),c=Fo("DndLiveRegion"),[d,u]=l.useState(!1);if(l.useEffect(()=>{u(!0)},[]),Mh(l.useMemo(()=>({onDragStart(f){let{active:p}=f;i(t.onDragStart({active:p}))},onDragMove(f){let{active:p,over:g}=f;t.onDragMove&&i(t.onDragMove({active:p,over:g}))},onDragOver(f){let{active:p,over:g}=f;i(t.onDragOver({active:p,over:g}))},onDragEnd(f){let{active:p,over:g}=f;i(t.onDragEnd({active:p,over:g}))},onDragCancel(f){let{active:p,over:g}=f;i(t.onDragCancel({active:p,over:g}))}}),[i,t])),!d)return null;const h=l.createElement(l.Fragment,null,l.createElement(Th,{id:o,value:s.draggable}),l.createElement(Rh,{id:c,announcement:a}));return r?Qn.createPortal(h,r):h}var Jt;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(Jt||(Jt={}));function No(){}function na(e,t){return l.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function Ph(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return l.useMemo(()=>[...t].filter(o=>o!=null),[...t])}const _n=Object.freeze({x:0,y:0});function si(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function Fh(e,t){const r=Ro(e);if(!r)return"0 0";const o={x:(r.x-t.left)/t.width*100,y:(r.y-t.top)/t.height*100};return o.x+"% "+o.y+"%"}function ii(e,t){let{data:{value:r}}=e,{data:{value:o}}=t;return r-o}function zh(e,t){let{data:{value:r}}=e,{data:{value:o}}=t;return o-r}function Is(e){let{left:t,top:r,height:o,width:s}=e;return[{x:t,y:r},{x:t+s,y:r},{x:t,y:r+o},{x:t+s,y:r+o}]}function hl(e,t){if(!e||e.length===0)return null;const[r]=e;return r[t]}function ra(e,t,r){return t===void 0&&(t=e.left),r===void 0&&(r=e.top),{x:t+e.width*.5,y:r+e.height*.5}}const Oh=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:o}=e;const s=ra(t,t.left,t.top),i=[];for(const a of o){const{id:c}=a,d=r.get(c);if(d){const u=si(ra(d),s);i.push({id:c,data:{droppableContainer:a,value:u}})}}return i.sort(ii)},Bh=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:o}=e;const s=Is(t),i=[];for(const a of o){const{id:c}=a,d=r.get(c);if(d){const u=Is(d),h=s.reduce((p,g,b)=>p+si(u[b],g),0),f=Number((h/4).toFixed(4));i.push({id:c,data:{droppableContainer:a,value:f}})}}return i.sort(ii)};function _h(e,t){const r=Math.max(t.top,e.top),o=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),i=Math.min(t.top+t.height,e.top+e.height),a=s-o,c=i-r;if(o<s&&r<i){const d=t.width*t.height,u=e.width*e.height,h=a*c,f=h/(d+u-h);return Number(f.toFixed(4))}return 0}const Hh=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:o}=e;const s=[];for(const i of o){const{id:a}=i,c=r.get(a);if(c){const d=_h(c,t);d>0&&s.push({id:a,data:{droppableContainer:i,value:d}})}}return s.sort(zh)};function $h(e,t){const{top:r,left:o,bottom:s,right:i}=t;return r<=e.y&&e.y<=s&&o<=e.x&&e.x<=i}const Uh=e=>{let{droppableContainers:t,droppableRects:r,pointerCoordinates:o}=e;if(!o)return[];const s=[];for(const i of t){const{id:a}=i,c=r.get(a);if(c&&$h(o,c)){const u=Is(c).reduce((f,p)=>f+si(o,p),0),h=Number((u/4).toFixed(4));s.push({id:a,data:{droppableContainer:i,value:h}})}}return s.sort(ii)};function Yh(e,t,r){return{...e,scaleX:t&&r?t.width/r.width:1,scaleY:t&&r?t.height/r.height:1}}function fl(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:_n}function Wh(e){return function(r){for(var o=arguments.length,s=new Array(o>1?o-1:0),i=1;i<o;i++)s[i-1]=arguments[i];return s.reduce((a,c)=>({...a,top:a.top+e*c.y,bottom:a.bottom+e*c.y,left:a.left+e*c.x,right:a.right+e*c.x}),{...r})}}const Xh=Wh(1);function pl(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function Vh(e,t,r){const o=pl(t);if(!o)return e;const{scaleX:s,scaleY:i,x:a,y:c}=o,d=e.left-a-(1-s)*parseFloat(r),u=e.top-c-(1-i)*parseFloat(r.slice(r.indexOf(" ")+1)),h=s?e.width/s:e.width,f=i?e.height/i:e.height;return{width:h,height:f,top:u,right:d+h,bottom:u+f,left:d}}const Gh={ignoreTransform:!1};function no(e,t){t===void 0&&(t=Gh);let r=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:u,transformOrigin:h}=gn(e).getComputedStyle(e);u&&(r=Vh(r,u,h))}const{top:o,left:s,width:i,height:a,bottom:c,right:d}=r;return{top:o,left:s,width:i,height:a,bottom:c,right:d}}function oa(e){return no(e,{ignoreTransform:!0})}function Kh(e){const t=e.innerWidth,r=e.innerHeight;return{top:0,left:0,right:t,bottom:r,width:t,height:r}}function qh(e,t){return t===void 0&&(t=gn(e).getComputedStyle(e)),t.position==="fixed"}function Zh(e,t){t===void 0&&(t=gn(e).getComputedStyle(e));const r=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const i=t[s];return typeof i=="string"?r.test(i):!1})}function zo(e,t){const r=[];function o(s){if(t!=null&&r.length>=t||!s)return r;if(ri(s)&&s.scrollingElement!=null&&!r.includes(s.scrollingElement))return r.push(s.scrollingElement),r;if(!eo(s)||cl(s)||r.includes(s))return r;const i=gn(e).getComputedStyle(s);return s!==e&&Zh(s,i)&&r.push(s),qh(s,i)?r:o(s.parentNode)}return e?o(e):r}function ml(e){const[t]=zo(e,1);return t??null}function as(e){return!Lo||!e?null:wr(e)?e:ni(e)?ri(e)||e===Cr(e).scrollingElement?window:eo(e)?e:null:null}function gl(e){return wr(e)?e.scrollX:e.scrollLeft}function xl(e){return wr(e)?e.scrollY:e.scrollTop}function As(e){return{x:gl(e),y:xl(e)}}var nn;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(nn||(nn={}));function bl(e){return!Lo||!e?!1:e===document.scrollingElement}function yl(e){const t={x:0,y:0},r=bl(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},o={x:e.scrollWidth-r.width,y:e.scrollHeight-r.height},s=e.scrollTop<=t.y,i=e.scrollLeft<=t.x,a=e.scrollTop>=o.y,c=e.scrollLeft>=o.x;return{isTop:s,isLeft:i,isBottom:a,isRight:c,maxScroll:o,minScroll:t}}const Jh={x:.2,y:.2};function Qh(e,t,r,o,s){let{top:i,left:a,right:c,bottom:d}=r;o===void 0&&(o=10),s===void 0&&(s=Jh);const{isTop:u,isBottom:h,isLeft:f,isRight:p}=yl(e),g={x:0,y:0},b={x:0,y:0},x={height:t.height*s.y,width:t.width*s.x};return!u&&i<=t.top+x.height?(g.y=nn.Backward,b.y=o*Math.abs((t.top+x.height-i)/x.height)):!h&&d>=t.bottom-x.height&&(g.y=nn.Forward,b.y=o*Math.abs((t.bottom-x.height-d)/x.height)),!p&&c>=t.right-x.width?(g.x=nn.Forward,b.x=o*Math.abs((t.right-x.width-c)/x.width)):!f&&a<=t.left+x.width&&(g.x=nn.Backward,b.x=o*Math.abs((t.left+x.width-a)/x.width)),{direction:g,speed:b}}function ef(e){if(e===document.scrollingElement){const{innerWidth:i,innerHeight:a}=window;return{top:0,left:0,right:i,bottom:a,width:i,height:a}}const{top:t,left:r,right:o,bottom:s}=e.getBoundingClientRect();return{top:t,left:r,right:o,bottom:s,width:e.clientWidth,height:e.clientHeight}}function vl(e){return e.reduce((t,r)=>yr(t,As(r)),_n)}function tf(e){return e.reduce((t,r)=>t+gl(r),0)}function nf(e){return e.reduce((t,r)=>t+xl(r),0)}function wl(e,t){if(t===void 0&&(t=no),!e)return;const{top:r,left:o,bottom:s,right:i}=t(e);ml(e)&&(s<=0||i<=0||r>=window.innerHeight||o>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const rf=[["x",["left","right"],tf],["y",["top","bottom"],nf]];class ai{constructor(t,r){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const o=zo(r),s=vl(o);this.rect={...t},this.width=t.width,this.height=t.height;for(const[i,a,c]of rf)for(const d of a)Object.defineProperty(this,d,{get:()=>{const u=c(o),h=s[i]-u;return this.rect[d]+h},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class zr{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(r=>{var o;return(o=this.target)==null?void 0:o.removeEventListener(...r)})},this.target=t}add(t,r,o){var s;(s=this.target)==null||s.addEventListener(t,r,o),this.listeners.push([t,r,o])}}function of(e){const{EventTarget:t}=gn(e);return e instanceof t?e:Cr(e)}function ls(e,t){const r=Math.abs(e.x),o=Math.abs(e.y);return typeof t=="number"?Math.sqrt(r**2+o**2)>t:"x"in t&&"y"in t?r>t.x&&o>t.y:"x"in t?r>t.x:"y"in t?o>t.y:!1}var Ln;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(Ln||(Ln={}));function sa(e){e.preventDefault()}function sf(e){e.stopPropagation()}var wt;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(wt||(wt={}));const Cl={start:[wt.Space,wt.Enter],cancel:[wt.Esc],end:[wt.Space,wt.Enter,wt.Tab]},af=(e,t)=>{let{currentCoordinates:r}=t;switch(e.code){case wt.Right:return{...r,x:r.x+25};case wt.Left:return{...r,x:r.x-25};case wt.Down:return{...r,y:r.y+25};case wt.Up:return{...r,y:r.y-25}}};class li{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:r}}=t;this.props=t,this.listeners=new zr(Cr(r)),this.windowListeners=new zr(gn(r)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Ln.Resize,this.handleCancel),this.windowListeners.add(Ln.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Ln.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:r}=this.props,o=t.node.current;o&&wl(o),r(_n)}handleKeyDown(t){if(oi(t)){const{active:r,context:o,options:s}=this.props,{keyboardCodes:i=Cl,coordinateGetter:a=af,scrollBehavior:c="smooth"}=s,{code:d}=t;if(i.end.includes(d)){this.handleEnd(t);return}if(i.cancel.includes(d)){this.handleCancel(t);return}const{collisionRect:u}=o.current,h=u?{x:u.left,y:u.top}:_n;this.referenceCoordinates||(this.referenceCoordinates=h);const f=a(t,{active:r,context:o.current,currentCoordinates:h});if(f){const p=Xr(f,h),g={x:0,y:0},{scrollableAncestors:b}=o.current;for(const x of b){const y=t.code,{isTop:v,isRight:w,isLeft:C,isBottom:j,maxScroll:M,minScroll:S}=yl(x),R=ef(x),I={x:Math.min(y===wt.Right?R.right-R.width/2:R.right,Math.max(y===wt.Right?R.left:R.left+R.width/2,f.x)),y:Math.min(y===wt.Down?R.bottom-R.height/2:R.bottom,Math.max(y===wt.Down?R.top:R.top+R.height/2,f.y))},D=y===wt.Right&&!w||y===wt.Left&&!C,E=y===wt.Down&&!j||y===wt.Up&&!v;if(D&&I.x!==f.x){const O=x.scrollLeft+p.x,z=y===wt.Right&&O<=M.x||y===wt.Left&&O>=S.x;if(z&&!p.y){x.scrollTo({left:O,behavior:c});return}z?g.x=x.scrollLeft-O:g.x=y===wt.Right?x.scrollLeft-M.x:x.scrollLeft-S.x,g.x&&x.scrollBy({left:-g.x,behavior:c});break}else if(E&&I.y!==f.y){const O=x.scrollTop+p.y,z=y===wt.Down&&O<=M.y||y===wt.Up&&O>=S.y;if(z&&!p.x){x.scrollTo({top:O,behavior:c});return}z?g.y=x.scrollTop-O:g.y=y===wt.Down?x.scrollTop-M.y:x.scrollTop-S.y,g.y&&x.scrollBy({top:-g.y,behavior:c});break}}this.handleMove(t,yr(Xr(f,this.referenceCoordinates),g))}}}handleMove(t,r){const{onMove:o}=this.props;t.preventDefault(),o(r)}handleEnd(t){const{onEnd:r}=this.props;t.preventDefault(),this.detach(),r()}handleCancel(t){const{onCancel:r}=this.props;t.preventDefault(),this.detach(),r()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}li.activators=[{eventName:"onKeyDown",handler:(e,t,r)=>{let{keyboardCodes:o=Cl,onActivation:s}=t,{active:i}=r;const{code:a}=e.nativeEvent;if(o.start.includes(a)){const c=i.activatorNode.current;return c&&e.target!==c?!1:(e.preventDefault(),s==null||s({event:e.nativeEvent}),!0)}return!1}}];function ia(e){return!!(e&&"distance"in e)}function aa(e){return!!(e&&"delay"in e)}class ci{constructor(t,r,o){var s;o===void 0&&(o=of(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=r;const{event:i}=t,{target:a}=i;this.props=t,this.events=r,this.document=Cr(a),this.documentListeners=new zr(this.document),this.listeners=new zr(o),this.windowListeners=new zr(gn(a)),this.initialCoordinates=(s=Ro(i))!=null?s:_n,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:r,bypassActivationConstraint:o}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(Ln.Resize,this.handleCancel),this.windowListeners.add(Ln.DragStart,sa),this.windowListeners.add(Ln.VisibilityChange,this.handleCancel),this.windowListeners.add(Ln.ContextMenu,sa),this.documentListeners.add(Ln.Keydown,this.handleKeydown),r){if(o!=null&&o({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(aa(r)){this.timeoutId=setTimeout(this.handleStart,r.delay),this.handlePending(r);return}if(ia(r)){this.handlePending(r);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,r){const{active:o,onPending:s}=this.props;s(o,t,this.initialCoordinates,r)}handleStart(){const{initialCoordinates:t}=this,{onStart:r}=this.props;t&&(this.activated=!0,this.documentListeners.add(Ln.Click,sf,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Ln.SelectionChange,this.removeTextSelection),r(t))}handleMove(t){var r;const{activated:o,initialCoordinates:s,props:i}=this,{onMove:a,options:{activationConstraint:c}}=i;if(!s)return;const d=(r=Ro(t))!=null?r:_n,u=Xr(s,d);if(!o&&c){if(ia(c)){if(c.tolerance!=null&&ls(u,c.tolerance))return this.handleCancel();if(ls(u,c.distance))return this.handleStart()}if(aa(c)&&ls(u,c.tolerance))return this.handleCancel();this.handlePending(c,u);return}t.cancelable&&t.preventDefault(),a(d)}handleEnd(){const{onAbort:t,onEnd:r}=this.props;this.detach(),this.activated||t(this.props.active),r()}handleCancel(){const{onAbort:t,onCancel:r}=this.props;this.detach(),this.activated||t(this.props.active),r()}handleKeydown(t){t.code===wt.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const lf={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class di extends ci{constructor(t){const{event:r}=t,o=Cr(r.target);super(t,lf,o)}}di.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:o}=t;return!r.isPrimary||r.button!==0?!1:(o==null||o({event:r}),!0)}}];const cf={move:{name:"mousemove"},end:{name:"mouseup"}};var Ds;(function(e){e[e.RightClick=2]="RightClick"})(Ds||(Ds={}));class df extends ci{constructor(t){super(t,cf,Cr(t.event.target))}}df.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:o}=t;return r.button===Ds.RightClick?!1:(o==null||o({event:r}),!0)}}];const cs={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class uf extends ci{constructor(t){super(t,cs)}static setup(){return window.addEventListener(cs.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(cs.move.name,t)};function t(){}}}uf.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:o}=t;const{touches:s}=r;return s.length>1?!1:(o==null||o({event:r}),!0)}}];var Or;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Or||(Or={}));var Mo;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(Mo||(Mo={}));function hf(e){let{acceleration:t,activator:r=Or.Pointer,canScroll:o,draggingRect:s,enabled:i,interval:a=5,order:c=Mo.TreeOrder,pointerCoordinates:d,scrollableAncestors:u,scrollableAncestorRects:h,delta:f,threshold:p}=e;const g=pf({delta:f,disabled:!i}),[b,x]=Ch(),y=l.useRef({x:0,y:0}),v=l.useRef({x:0,y:0}),w=l.useMemo(()=>{switch(r){case Or.Pointer:return d?{top:d.y,bottom:d.y,left:d.x,right:d.x}:null;case Or.DraggableRect:return s}},[r,s,d]),C=l.useRef(null),j=l.useCallback(()=>{const S=C.current;if(!S)return;const R=y.current.x*v.current.x,I=y.current.y*v.current.y;S.scrollBy(R,I)},[]),M=l.useMemo(()=>c===Mo.TreeOrder?[...u].reverse():u,[c,u]);l.useEffect(()=>{if(!i||!u.length||!w){x();return}for(const S of M){if((o==null?void 0:o(S))===!1)continue;const R=u.indexOf(S),I=h[R];if(!I)continue;const{direction:D,speed:E}=Qh(S,I,w,t,p);for(const O of["x","y"])g[O][D[O]]||(E[O]=0,D[O]=0);if(E.x>0||E.y>0){x(),C.current=S,b(j,a),y.current=E,v.current=D;return}}y.current={x:0,y:0},v.current={x:0,y:0},x()},[t,j,o,x,i,a,JSON.stringify(w),JSON.stringify(g),b,u,M,h,JSON.stringify(p)])}const ff={x:{[nn.Backward]:!1,[nn.Forward]:!1},y:{[nn.Backward]:!1,[nn.Forward]:!1}};function pf(e){let{delta:t,disabled:r}=e;const o=To(t);return to(s=>{if(r||!o||!s)return ff;const i={x:Math.sign(t.x-o.x),y:Math.sign(t.y-o.y)};return{x:{[nn.Backward]:s.x[nn.Backward]||i.x===-1,[nn.Forward]:s.x[nn.Forward]||i.x===1},y:{[nn.Backward]:s.y[nn.Backward]||i.y===-1,[nn.Forward]:s.y[nn.Forward]||i.y===1}}},[r,t,o])}function mf(e,t){const r=t!=null?e.get(t):void 0,o=r?r.node.current:null;return to(s=>{var i;return t==null?null:(i=o??s)!=null?i:null},[o,t])}function gf(e,t){return l.useMemo(()=>e.reduce((r,o)=>{const{sensor:s}=o,i=s.activators.map(a=>({eventName:a.eventName,handler:t(a.handler,o)}));return[...r,...i]},[]),[e,t])}var Gr;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Gr||(Gr={}));var Ls;(function(e){e.Optimized="optimized"})(Ls||(Ls={}));const la=new Map;function xf(e,t){let{dragging:r,dependencies:o,config:s}=t;const[i,a]=l.useState(null),{frequency:c,measure:d,strategy:u}=s,h=l.useRef(e),f=y(),p=Wr(f),g=l.useCallback(function(v){v===void 0&&(v=[]),!p.current&&a(w=>w===null?v:w.concat(v.filter(C=>!w.includes(C))))},[p]),b=l.useRef(null),x=to(v=>{if(f&&!r)return la;if(!v||v===la||h.current!==e||i!=null){const w=new Map;for(let C of e){if(!C)continue;if(i&&i.length>0&&!i.includes(C.id)&&C.rect.current){w.set(C.id,C.rect.current);continue}const j=C.node.current,M=j?new ai(d(j),j):null;C.rect.current=M,M&&w.set(C.id,M)}return w}return v},[e,i,r,f,d]);return l.useEffect(()=>{h.current=e},[e]),l.useEffect(()=>{f||g()},[r,f]),l.useEffect(()=>{i&&i.length>0&&a(null)},[JSON.stringify(i)]),l.useEffect(()=>{f||typeof c!="number"||b.current!==null||(b.current=setTimeout(()=>{g(),b.current=null},c))},[c,f,g,...o]),{droppableRects:x,measureDroppableContainers:g,measuringScheduled:i!=null};function y(){switch(u){case Gr.Always:return!1;case Gr.BeforeDragging:return r;default:return!r}}}function ui(e,t){return to(r=>e?r||(typeof t=="function"?t(e):e):null,[t,e])}function bf(e,t){return ui(e,t)}function yf(e){let{callback:t,disabled:r}=e;const o=Po(t),s=l.useMemo(()=>{if(r||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:i}=window;return new i(o)},[o,r]);return l.useEffect(()=>()=>s==null?void 0:s.disconnect(),[s]),s}function Oo(e){let{callback:t,disabled:r}=e;const o=Po(t),s=l.useMemo(()=>{if(r||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:i}=window;return new i(o)},[r]);return l.useEffect(()=>()=>s==null?void 0:s.disconnect(),[s]),s}function vf(e){return new ai(no(e),e)}function ca(e,t,r){t===void 0&&(t=vf);const[o,s]=l.useState(null);function i(){s(d=>{if(!e)return null;if(e.isConnected===!1){var u;return(u=d??r)!=null?u:null}const h=t(e);return JSON.stringify(d)===JSON.stringify(h)?d:h})}const a=yf({callback(d){if(e)for(const u of d){const{type:h,target:f}=u;if(h==="childList"&&f instanceof HTMLElement&&f.contains(e)){i();break}}}}),c=Oo({callback:i});return Vn(()=>{i(),e?(c==null||c.observe(e),a==null||a.observe(document.body,{childList:!0,subtree:!0})):(c==null||c.disconnect(),a==null||a.disconnect())},[e]),o}function wf(e){const t=ui(e);return fl(e,t)}const da=[];function Cf(e){const t=l.useRef(e),r=to(o=>e?o&&o!==da&&e&&t.current&&e.parentNode===t.current.parentNode?o:zo(e):da,[e]);return l.useEffect(()=>{t.current=e},[e]),r}function Sf(e){const[t,r]=l.useState(null),o=l.useRef(e),s=l.useCallback(i=>{const a=as(i.target);a&&r(c=>c?(c.set(a,As(a)),new Map(c)):null)},[]);return l.useEffect(()=>{const i=o.current;if(e!==i){a(i);const c=e.map(d=>{const u=as(d);return u?(u.addEventListener("scroll",s,{passive:!0}),[u,As(u)]):null}).filter(d=>d!=null);r(c.length?new Map(c):null),o.current=e}return()=>{a(e),a(i)};function a(c){c.forEach(d=>{const u=as(d);u==null||u.removeEventListener("scroll",s)})}},[s,e]),l.useMemo(()=>e.length?t?Array.from(t.values()).reduce((i,a)=>yr(i,a),_n):vl(e):_n,[e,t])}function ua(e,t){t===void 0&&(t=[]);const r=l.useRef(null);return l.useEffect(()=>{r.current=null},t),l.useEffect(()=>{const o=e!==_n;o&&!r.current&&(r.current=e),!o&&r.current&&(r.current=null)},[e]),r.current?Xr(e,r.current):_n}function kf(e){l.useEffect(()=>{if(!Lo)return;const t=e.map(r=>{let{sensor:o}=r;return o.setup==null?void 0:o.setup()});return()=>{for(const r of t)r==null||r()}},e.map(t=>{let{sensor:r}=t;return r}))}function jf(e,t){return l.useMemo(()=>e.reduce((r,o)=>{let{eventName:s,handler:i}=o;return r[s]=a=>{i(a,t)},r},{}),[e,t])}function Sl(e){return l.useMemo(()=>e?Kh(e):null,[e])}const ha=[];function Ef(e,t){t===void 0&&(t=no);const[r]=e,o=Sl(r?gn(r):null),[s,i]=l.useState(ha);function a(){i(()=>e.length?e.map(d=>bl(d)?o:new ai(t(d),d)):ha)}const c=Oo({callback:a});return Vn(()=>{c==null||c.disconnect(),a(),e.forEach(d=>c==null?void 0:c.observe(d))},[e]),s}function kl(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return eo(t)?t:e}function Tf(e){let{measure:t}=e;const[r,o]=l.useState(null),s=l.useCallback(u=>{for(const{target:h}of u)if(eo(h)){o(f=>{const p=t(h);return f?{...f,width:p.width,height:p.height}:p});break}},[t]),i=Oo({callback:s}),a=l.useCallback(u=>{const h=kl(u);i==null||i.disconnect(),h&&(i==null||i.observe(h)),o(h?t(h):null)},[t,i]),[c,d]=Eo(a);return l.useMemo(()=>({nodeRef:c,rect:r,setRef:d}),[r,c,d])}const Rf=[{sensor:di,options:{}},{sensor:li,options:{}}],Nf={current:{}},vo={draggable:{measure:oa},droppable:{measure:oa,strategy:Gr.WhileDragging,frequency:Ls.Optimized},dragOverlay:{measure:no}};class Br extends Map{get(t){var r;return t!=null&&(r=super.get(t))!=null?r:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:r}=t;return!r})}getNodeFor(t){var r,o;return(r=(o=this.get(t))==null?void 0:o.node.current)!=null?r:void 0}}const Mf={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new Br,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:No},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:vo,measureDroppableContainers:No,windowRect:null,measuringScheduled:!1},jl={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:No,draggableNodes:new Map,over:null,measureDroppableContainers:No},ro=l.createContext(jl),El=l.createContext(Mf);function If(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new Br}}}function Af(e,t){switch(t.type){case Jt.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Jt.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case Jt.DragEnd:case Jt.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Jt.RegisterDroppable:{const{element:r}=t,{id:o}=r,s=new Br(e.droppable.containers);return s.set(o,r),{...e,droppable:{...e.droppable,containers:s}}}case Jt.SetDroppableDisabled:{const{id:r,key:o,disabled:s}=t,i=e.droppable.containers.get(r);if(!i||o!==i.key)return e;const a=new Br(e.droppable.containers);return a.set(r,{...i,disabled:s}),{...e,droppable:{...e.droppable,containers:a}}}case Jt.UnregisterDroppable:{const{id:r,key:o}=t,s=e.droppable.containers.get(r);if(!s||o!==s.key)return e;const i=new Br(e.droppable.containers);return i.delete(r),{...e,droppable:{...e.droppable,containers:i}}}default:return e}}function Df(e){let{disabled:t}=e;const{active:r,activatorEvent:o,draggableNodes:s}=l.useContext(ro),i=To(o),a=To(r==null?void 0:r.id);return l.useEffect(()=>{if(!t&&!o&&i&&a!=null){if(!oi(i)||document.activeElement===i.target)return;const c=s.get(a);if(!c)return;const{activatorNode:d,node:u}=c;if(!d.current&&!u.current)return;requestAnimationFrame(()=>{for(const h of[d.current,u.current]){if(!h)continue;const f=jh(h);if(f){f.focus();break}}})}},[o,t,s,a,i]),null}function Tl(e,t){let{transform:r,...o}=t;return e!=null&&e.length?e.reduce((s,i)=>i({transform:s,...o}),r):r}function Lf(e){return l.useMemo(()=>({draggable:{...vo.draggable,...e==null?void 0:e.draggable},droppable:{...vo.droppable,...e==null?void 0:e.droppable},dragOverlay:{...vo.dragOverlay,...e==null?void 0:e.dragOverlay}}),[e==null?void 0:e.draggable,e==null?void 0:e.droppable,e==null?void 0:e.dragOverlay])}function Pf(e){let{activeNode:t,measure:r,initialRect:o,config:s=!0}=e;const i=l.useRef(!1),{x:a,y:c}=typeof s=="boolean"?{x:s,y:s}:s;Vn(()=>{if(!a&&!c||!t){i.current=!1;return}if(i.current||!o)return;const u=t==null?void 0:t.node.current;if(!u||u.isConnected===!1)return;const h=r(u),f=fl(h,o);if(a||(f.x=0),c||(f.y=0),i.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const p=ml(u);p&&p.scrollBy({top:f.y,left:f.x})}},[t,a,c,o,r])}const Bo=l.createContext({..._n,scaleX:1,scaleY:1});var Jn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(Jn||(Jn={}));const Ff=l.memo(function(t){var r,o,s,i;let{id:a,accessibility:c,autoScroll:d=!0,children:u,sensors:h=Rf,collisionDetection:f=Hh,measuring:p,modifiers:g,...b}=t;const x=l.useReducer(Af,void 0,If),[y,v]=x,[w,C]=Ih(),[j,M]=l.useState(Jn.Uninitialized),S=j===Jn.Initialized,{draggable:{active:R,nodes:I,translate:D},droppable:{containers:E}}=y,O=R!=null?I.get(R):null,z=l.useRef({initial:null,translated:null}),_=l.useMemo(()=>{var je;return R!=null?{id:R,data:(je=O==null?void 0:O.data)!=null?je:Nf,rect:z}:null},[R,O]),k=l.useRef(null),[Y,B]=l.useState(null),[G,se]=l.useState(null),A=Wr(b,Object.values(b)),Z=Fo("DndDescribedBy",a),J=l.useMemo(()=>E.getEnabled(),[E]),q=Lf(p),{droppableRects:ae,measureDroppableContainers:Le,measuringScheduled:pe}=xf(J,{dragging:S,dependencies:[D.x,D.y],config:q.droppable}),U=mf(I,R),W=l.useMemo(()=>G?Ro(G):null,[G]),Ie=De(),ke=bf(U,q.draggable.measure);Pf({activeNode:R!=null?I.get(R):null,config:Ie.layoutShiftCompensation,initialRect:ke,measure:q.draggable.measure});const Ke=ca(U,q.draggable.measure,ke),re=ca(U?U.parentElement:null),te=l.useRef({activatorEvent:null,active:null,activeNode:U,collisionRect:null,collisions:null,droppableRects:ae,draggableNodes:I,draggingNode:null,draggingNodeRect:null,droppableContainers:E,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),he=E.getNodeFor((r=te.current.over)==null?void 0:r.id),ye=Tf({measure:q.dragOverlay.measure}),we=(o=ye.nodeRef.current)!=null?o:U,Pe=S?(s=ye.rect)!=null?s:Ke:null,me=!!(ye.nodeRef.current&&ye.rect),N=wf(me?null:Ke),ce=Sl(we?gn(we):null),le=Cf(S?he??U:null),Me=Ef(le),ge=Tl(g,{transform:{x:D.x-N.x,y:D.y-N.y,scaleX:1,scaleY:1},activatorEvent:G,active:_,activeNodeRect:Ke,containerNodeRect:re,draggingNodeRect:Pe,over:te.current.over,overlayNodeRect:ye.rect,scrollableAncestors:le,scrollableAncestorRects:Me,windowRect:ce}),L=W?yr(W,D):null,ve=Sf(le),tt=ua(ve),Ve=ua(ve,[Ke]),oe=yr(ge,tt),ie=Pe?Xh(Pe,ge):null,pt=_&&ie?f({active:_,collisionRect:ie,droppableRects:ae,droppableContainers:J,pointerCoordinates:L}):null,st=hl(pt,"id"),[ht,bt]=l.useState(null),yt=me?ge:yr(ge,Ve),Tt=Yh(yt,(i=ht==null?void 0:ht.rect)!=null?i:null,Ke),Rt=l.useRef(null),jt=l.useCallback((je,Ee)=>{let{sensor:$e,options:Qe}=Ee;if(k.current==null)return;const Fe=I.get(k.current);if(!Fe)return;const Ue=je.nativeEvent,Xe=new $e({active:k.current,activeNode:Fe,event:Ue,options:Qe,context:te,onAbort(Ye){if(!I.get(Ye))return;const{onDragAbort:gt}=A.current,Nt={id:Ye};gt==null||gt(Nt),w({type:"onDragAbort",event:Nt})},onPending(Ye,vt,gt,Nt){if(!I.get(Ye))return;const{onDragPending:$}=A.current,ee={id:Ye,constraint:vt,initialCoordinates:gt,offset:Nt};$==null||$(ee),w({type:"onDragPending",event:ee})},onStart(Ye){const vt=k.current;if(vt==null)return;const gt=I.get(vt);if(!gt)return;const{onDragStart:Nt}=A.current,Ft={activatorEvent:Ue,active:{id:vt,data:gt.data,rect:z}};Qn.unstable_batchedUpdates(()=>{Nt==null||Nt(Ft),M(Jn.Initializing),v({type:Jt.DragStart,initialCoordinates:Ye,active:vt}),w({type:"onDragStart",event:Ft}),B(Rt.current),se(Ue)})},onMove(Ye){v({type:Jt.DragMove,coordinates:Ye})},onEnd:dt(Jt.DragEnd),onCancel:dt(Jt.DragCancel)});Rt.current=Xe;function dt(Ye){return async function(){const{active:gt,collisions:Nt,over:Ft,scrollAdjustedTranslate:$}=te.current;let ee=null;if(gt&&$){const{cancelDrop:Je}=A.current;ee={activatorEvent:Ue,active:gt,collisions:Nt,delta:$,over:Ft},Ye===Jt.DragEnd&&typeof Je=="function"&&await Promise.resolve(Je(ee))&&(Ye=Jt.DragCancel)}k.current=null,Qn.unstable_batchedUpdates(()=>{v({type:Ye}),M(Jn.Uninitialized),bt(null),B(null),se(null),Rt.current=null;const Je=Ye===Jt.DragEnd?"onDragEnd":"onDragCancel";if(ee){const it=A.current[Je];it==null||it(ee),w({type:Je,event:ee})}})}}},[I]),kt=l.useCallback((je,Ee)=>($e,Qe)=>{const Fe=$e.nativeEvent,Ue=I.get(Qe);if(k.current!==null||!Ue||Fe.dndKit||Fe.defaultPrevented)return;const Xe={active:Ue};je($e,Ee.options,Xe)===!0&&(Fe.dndKit={capturedBy:Ee.sensor},k.current=Qe,jt($e,Ee))},[I,jt]),Kt=gf(h,kt);kf(h),Vn(()=>{Ke&&j===Jn.Initializing&&M(Jn.Initialized)},[Ke,j]),l.useEffect(()=>{const{onDragMove:je}=A.current,{active:Ee,activatorEvent:$e,collisions:Qe,over:Fe}=te.current;if(!Ee||!$e)return;const Ue={active:Ee,activatorEvent:$e,collisions:Qe,delta:{x:oe.x,y:oe.y},over:Fe};Qn.unstable_batchedUpdates(()=>{je==null||je(Ue),w({type:"onDragMove",event:Ue})})},[oe.x,oe.y]),l.useEffect(()=>{const{active:je,activatorEvent:Ee,collisions:$e,droppableContainers:Qe,scrollAdjustedTranslate:Fe}=te.current;if(!je||k.current==null||!Ee||!Fe)return;const{onDragOver:Ue}=A.current,Xe=Qe.get(st),dt=Xe&&Xe.rect.current?{id:Xe.id,rect:Xe.rect.current,data:Xe.data,disabled:Xe.disabled}:null,Ye={active:je,activatorEvent:Ee,collisions:$e,delta:{x:Fe.x,y:Fe.y},over:dt};Qn.unstable_batchedUpdates(()=>{bt(dt),Ue==null||Ue(Ye),w({type:"onDragOver",event:Ye})})},[st]),Vn(()=>{te.current={activatorEvent:G,active:_,activeNode:U,collisionRect:ie,collisions:pt,droppableRects:ae,draggableNodes:I,draggingNode:we,draggingNodeRect:Pe,droppableContainers:E,over:ht,scrollableAncestors:le,scrollAdjustedTranslate:oe},z.current={initial:Pe,translated:ie}},[_,U,pt,ie,I,we,Pe,ae,E,ht,le,oe]),hf({...Ie,delta:D,draggingRect:ie,pointerCoordinates:L,scrollableAncestors:le,scrollableAncestorRects:Me});const $t=l.useMemo(()=>({active:_,activeNode:U,activeNodeRect:Ke,activatorEvent:G,collisions:pt,containerNodeRect:re,dragOverlay:ye,draggableNodes:I,droppableContainers:E,droppableRects:ae,over:ht,measureDroppableContainers:Le,scrollableAncestors:le,scrollableAncestorRects:Me,measuringConfiguration:q,measuringScheduled:pe,windowRect:ce}),[_,U,Ke,G,pt,re,ye,I,E,ae,ht,Le,le,Me,q,pe,ce]),Ot=l.useMemo(()=>({activatorEvent:G,activators:Kt,active:_,activeNodeRect:Ke,ariaDescribedById:{draggable:Z},dispatch:v,draggableNodes:I,over:ht,measureDroppableContainers:Le}),[G,Kt,_,Ke,v,Z,I,ht,Le]);return l.createElement(ul.Provider,{value:C},l.createElement(ro.Provider,{value:Ot},l.createElement(El.Provider,{value:$t},l.createElement(Bo.Provider,{value:Tt},u)),l.createElement(Df,{disabled:(c==null?void 0:c.restoreFocus)===!1})),l.createElement(Lh,{...c,hiddenTextDescribedById:Z}));function De(){const je=(Y==null?void 0:Y.autoScrollEnabled)===!1,Ee=typeof d=="object"?d.enabled===!1:d===!1,$e=S&&!je&&!Ee;return typeof d=="object"?{...d,enabled:$e}:{enabled:$e}}}),zf=l.createContext(null),fa="button",Of="Draggable";function Bf(e){let{id:t,data:r,disabled:o=!1,attributes:s}=e;const i=Fo(Of),{activators:a,activatorEvent:c,active:d,activeNodeRect:u,ariaDescribedById:h,draggableNodes:f,over:p}=l.useContext(ro),{role:g=fa,roleDescription:b="draggable",tabIndex:x=0}=s??{},y=(d==null?void 0:d.id)===t,v=l.useContext(y?Bo:zf),[w,C]=Eo(),[j,M]=Eo(),S=jf(a,t),R=Wr(r);Vn(()=>(f.set(t,{id:t,key:i,node:w,activatorNode:j,data:R}),()=>{const D=f.get(t);D&&D.key===i&&f.delete(t)}),[f,t]);const I=l.useMemo(()=>({role:g,tabIndex:x,"aria-disabled":o,"aria-pressed":y&&g===fa?!0:void 0,"aria-roledescription":b,"aria-describedby":h.draggable}),[o,g,x,y,b,h.draggable]);return{active:d,activatorEvent:c,activeNodeRect:u,attributes:I,isDragging:y,listeners:o?void 0:S,node:w,over:p,setNodeRef:C,setActivatorNodeRef:M,transform:v}}function _f(){return l.useContext(El)}const Hf="Droppable",$f={timeout:25};function Rl(e){let{data:t,disabled:r=!1,id:o,resizeObserverConfig:s}=e;const i=Fo(Hf),{active:a,dispatch:c,over:d,measureDroppableContainers:u}=l.useContext(ro),h=l.useRef({disabled:r}),f=l.useRef(!1),p=l.useRef(null),g=l.useRef(null),{disabled:b,updateMeasurementsFor:x,timeout:y}={...$f,...s},v=Wr(x??o),w=l.useCallback(()=>{if(!f.current){f.current=!0;return}g.current!=null&&clearTimeout(g.current),g.current=setTimeout(()=>{u(Array.isArray(v.current)?v.current:[v.current]),g.current=null},y)},[y]),C=Oo({callback:w,disabled:b||!a}),j=l.useCallback((I,D)=>{C&&(D&&(C.unobserve(D),f.current=!1),I&&C.observe(I))},[C]),[M,S]=Eo(j),R=Wr(t);return l.useEffect(()=>{!C||!M.current||(C.disconnect(),f.current=!1,C.observe(M.current))},[M,C]),l.useEffect(()=>(c({type:Jt.RegisterDroppable,element:{id:o,key:i,disabled:r,node:M,rect:p,data:R}}),()=>c({type:Jt.UnregisterDroppable,key:i,id:o})),[o]),l.useEffect(()=>{r!==h.current.disabled&&(c({type:Jt.SetDroppableDisabled,id:o,key:i,disabled:r}),h.current.disabled=r)},[o,i,r,c]),{active:a,rect:p,isOver:(d==null?void 0:d.id)===o,node:M,over:d,setNodeRef:S}}function Uf(e){let{animation:t,children:r}=e;const[o,s]=l.useState(null),[i,a]=l.useState(null),c=To(r);return!r&&!o&&c&&s(c),Vn(()=>{if(!i)return;const d=o==null?void 0:o.key,u=o==null?void 0:o.props.id;if(d==null||u==null){s(null);return}Promise.resolve(t(u,i)).then(()=>{s(null)})},[t,o,i]),l.createElement(l.Fragment,null,r,o?l.cloneElement(o,{ref:a}):null)}const Yf={x:0,y:0,scaleX:1,scaleY:1};function Wf(e){let{children:t}=e;return l.createElement(ro.Provider,{value:jl},l.createElement(Bo.Provider,{value:Yf},t))}const Xf={position:"fixed",touchAction:"none"},Vf=e=>oi(e)?"transform 250ms ease":void 0,Gf=l.forwardRef((e,t)=>{let{as:r,activatorEvent:o,adjustScale:s,children:i,className:a,rect:c,style:d,transform:u,transition:h=Vf}=e;if(!c)return null;const f=s?u:{...u,scaleX:1,scaleY:1},p={...Xf,width:c.width,height:c.height,top:c.top,left:c.left,transform:Vr.Transform.toString(f),transformOrigin:s&&o?Fh(o,c):void 0,transition:typeof h=="function"?h(o):h,...d};return l.createElement(r,{className:a,style:p,ref:t},i)}),Kf=e=>t=>{let{active:r,dragOverlay:o}=t;const s={},{styles:i,className:a}=e;if(i!=null&&i.active)for(const[c,d]of Object.entries(i.active))d!==void 0&&(s[c]=r.node.style.getPropertyValue(c),r.node.style.setProperty(c,d));if(i!=null&&i.dragOverlay)for(const[c,d]of Object.entries(i.dragOverlay))d!==void 0&&o.node.style.setProperty(c,d);return a!=null&&a.active&&r.node.classList.add(a.active),a!=null&&a.dragOverlay&&o.node.classList.add(a.dragOverlay),function(){for(const[d,u]of Object.entries(s))r.node.style.setProperty(d,u);a!=null&&a.active&&r.node.classList.remove(a.active)}},qf=e=>{let{transform:{initial:t,final:r}}=e;return[{transform:Vr.Transform.toString(t)},{transform:Vr.Transform.toString(r)}]},Zf={duration:250,easing:"ease",keyframes:qf,sideEffects:Kf({styles:{active:{opacity:"0"}}})};function Jf(e){let{config:t,draggableNodes:r,droppableContainers:o,measuringConfiguration:s}=e;return Po((i,a)=>{if(t===null)return;const c=r.get(i);if(!c)return;const d=c.node.current;if(!d)return;const u=kl(a);if(!u)return;const{transform:h}=gn(a).getComputedStyle(a),f=pl(h);if(!f)return;const p=typeof t=="function"?t:Qf(t);return wl(d,s.draggable.measure),p({active:{id:i,data:c.data,node:d,rect:s.draggable.measure(d)},draggableNodes:r,dragOverlay:{node:a,rect:s.dragOverlay.measure(u)},droppableContainers:o,measuringConfiguration:s,transform:f})})}function Qf(e){const{duration:t,easing:r,sideEffects:o,keyframes:s}={...Zf,...e};return i=>{let{active:a,dragOverlay:c,transform:d,...u}=i;if(!t)return;const h={x:c.rect.left-a.rect.left,y:c.rect.top-a.rect.top},f={scaleX:d.scaleX!==1?a.rect.width*d.scaleX/c.rect.width:1,scaleY:d.scaleY!==1?a.rect.height*d.scaleY/c.rect.height:1},p={x:d.x-h.x,y:d.y-h.y,...f},g=s({...u,active:a,dragOverlay:c,transform:{initial:d,final:p}}),[b]=g,x=g[g.length-1];if(JSON.stringify(b)===JSON.stringify(x))return;const y=o==null?void 0:o({active:a,dragOverlay:c,...u}),v=c.node.animate(g,{duration:t,easing:r,fill:"forwards"});return new Promise(w=>{v.onfinish=()=>{y==null||y(),w()}})}}let pa=0;function ep(e){return l.useMemo(()=>{if(e!=null)return pa++,pa},[e])}const tp=l.memo(e=>{let{adjustScale:t=!1,children:r,dropAnimation:o,style:s,transition:i,modifiers:a,wrapperElement:c="div",className:d,zIndex:u=999}=e;const{activatorEvent:h,active:f,activeNodeRect:p,containerNodeRect:g,draggableNodes:b,droppableContainers:x,dragOverlay:y,over:v,measuringConfiguration:w,scrollableAncestors:C,scrollableAncestorRects:j,windowRect:M}=_f(),S=l.useContext(Bo),R=ep(f==null?void 0:f.id),I=Tl(a,{activatorEvent:h,active:f,activeNodeRect:p,containerNodeRect:g,draggingNodeRect:y.rect,over:v,overlayNodeRect:y.rect,scrollableAncestors:C,scrollableAncestorRects:j,transform:S,windowRect:M}),D=ui(p),E=Jf({config:o,draggableNodes:b,droppableContainers:x,measuringConfiguration:w}),O=D?y.setRef:void 0;return l.createElement(Wf,null,l.createElement(Uf,{animation:E},f&&R?l.createElement(Gf,{key:R,id:f.id,ref:O,as:c,activatorEvent:h,adjustScale:t,className:d,transition:i,rect:D,style:{zIndex:u,...s},transform:I},r):null))});function Io(e){if(!e)return!1;const t=e.data.current;return!!(t&&"sortable"in t&&typeof t.sortable=="object"&&"containerId"in t.sortable&&"items"in t.sortable&&"index"in t.sortable)}const np=[wt.Down,wt.Right,wt.Up,wt.Left],rp=(e,t)=>{let{context:{active:r,collisionRect:o,droppableRects:s,droppableContainers:i,over:a,scrollableAncestors:c}}=t;if(np.includes(e.code)){if(e.preventDefault(),!r||!o)return;const d=[];i.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const p=s.get(f.id);if(p)switch(e.code){case wt.Down:o.top<p.top&&d.push(f);break;case wt.Up:o.top>p.top&&d.push(f);break;case wt.Left:o.left>p.left&&d.push(f);break;case wt.Right:o.left<p.left&&d.push(f);break}});const u=Bh({collisionRect:o,droppableRects:s,droppableContainers:d});let h=hl(u,"id");if(h===(a==null?void 0:a.id)&&u.length>1&&(h=u[1].id),h!=null){const f=i.get(r.id),p=i.get(h),g=p?s.get(p.id):null,b=p==null?void 0:p.node.current;if(b&&g&&f&&p){const y=zo(b).some((S,R)=>c[R]!==S),v=Nl(f,p),w=op(f,p),C=y||!v?{x:0,y:0}:{x:w?o.width-g.width:0,y:w?o.height-g.height:0},j={x:g.left,y:g.top};return C.x&&C.y?j:Xr(j,C)}}}};function Nl(e,t){return!Io(e)||!Io(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function op(e,t){return!Io(e)||!Io(t)||!Nl(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}function ma(e){var r;if(!e||e.length===0)return null;const t=(r=e[0].data)==null?void 0:r.zone;return t==="before"||t==="after"||t==="into"?t:null}function sp(e){const{onReorder:t,onGroupReorder:r,onDropIntoGroup:o,onDropIntoGroupAtPosition:s,onRemoveFromGroup:i,findParentGroup:a}=e,[c,d]=l.useState(null),[u,h]=l.useState(null),[f,p]=l.useState(null),g=l.useRef(null),b=Ph(na(di,{activationConstraint:{distance:5}}),na(li,{coordinateGetter:rp})),x=l.useCallback(M=>{d(String(M.active.id))},[]),y=l.useCallback(M=>{const{over:S,collisions:R}=M;h(S?String(S.id):null);const I=ma(R);g.current=I,p(I)},[]),v=l.useCallback(M=>{const{collisions:S}=M,R=ma(S);g.current=R,p(R)},[]),w=l.useCallback(()=>{g.current=null,d(null),h(null),p(null)},[]),C=l.useCallback(M=>{const{active:S,over:R}=M,I=g.current;if(!R||S.id===R.id||!I){w();return}const D=String(S.id),E=String(R.id);if(E.startsWith("group-footer::")){const O=E.replace("group-footer::",""),z=a==null?void 0:a(D);z&&z.id===O?i==null||i(D):t(D,O,"before"),w();return}if(I==="into")o==null||o(D,E);else{const O=I==="before"?"after":"before",z=a==null?void 0:a(D),_=a==null?void 0:a(E);z&&_&&z.id===_.id?r==null||r(D,E,O,z.id):!z&&_&&s?s(D,_.id,E,O):t(D,E,O)}w()},[t,r,o,s,i,a,w]),j=l.useCallback(()=>{w()},[w]);return{activeId:c,overId:u,dropPosition:f,sensors:b,onDragStart:x,onDragMove:v,onDragOver:y,onDragEnd:C,onDragCancel:j}}function Bn(...e){return Wc.twMerge(Yc.clsx(e))}const ip={"gravity-ui":1.2,lucide:1,hugeicons:1.05,mdi:.95,"fa6-solid":.7,heroicons:1,ph:1,"radix-icons":1,"material-symbols":.9,"simple-icons":.95,"eos-icons":1},ap=1,lp={"gravity-ui:arrow-rotate-left":{x:4,y:4},"gravity-ui:arrow-rotate-right":{x:-4,y:4},"gravity-ui:sparkles":{x:2,y:-2}},cp={xs:12,sm:16,md:20,lg:24,xl:32,toolbar:{mobile:24,desktop:20}};function dp(e){const t=e.indexOf(":");return t===-1?"":e.substring(0,t)}function up(e){return ip[e]??ap}function hp(e){return lp[e]??null}function ds(e,t){const r=up(t);return Math.round(e*r)}const Ml=({icon:e,size:t="md",className:r})=>{const o=dp(e),s=cp[t],i=hp(e);if(typeof s=="object"){const d=ds(s.mobile,o),u=ds(s.desktop,o),h=i?{x:i.x*d/20,y:i.y*d/20}:null;return n.jsx("span",{className:Bn("normalized-icon-responsive inline-flex",r),style:{"--icon-size-mobile":`${d}px`,"--icon-size-desktop":`${u}px`,width:`${d}px`,height:`${d}px`},children:n.jsx(de,{icon:e,width:"100%",height:"100%",style:h?{transform:`translate(${h.x}px, ${h.y}px)`}:void 0})})}const a=ds(s,o),c=i?{x:i.x*a/20,y:i.y*a/20}:null;return n.jsx("span",{className:Bn("inline-flex",r),style:{width:`${a}px`,height:`${a}px`},children:n.jsx(de,{icon:e,width:"100%",height:"100%",style:c?{transform:`translate(${c.x}px, ${c.y}px)`}:void 0})})};Ml.displayName="NormalizedIcon";const ct=l.forwardRef(({icon:e,onClick:t,active:r=!1,tooltip:o,tooltipDelay:s=300,tooltipDisabled:i=!1,"aria-label":a,disabled:c=!1,className:d,onMouseLeave:u},h)=>{const f=n.jsx(m.Button,{ref:h,variant:"ghost",size:"toolbar",onClick:t,disabled:c,"aria-label":a||o,"aria-pressed":r,"data-active":r,onMouseLeave:u,className:Bn(d),children:typeof e=="string"?n.jsx(Ml,{icon:e,size:"toolbar"}):e});return!o||i?f:n.jsxs(m.Tooltip,{delay:s,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:f}),n.jsx(m.TooltipContent,{children:o})]})});ct.displayName="ToolbarButton";const _o=({className:e,size:t=24})=>n.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",width:t,height:t,className:Bn("inline-block iconify",e),children:[n.jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),n.jsx("path",{d:"M3 3v5h5"})]}),Ao=({className:e,size:t=24})=>n.jsx("svg",{viewBox:"0 0 28 28",fill:"currentColor",width:t,height:t,className:Bn("inline-block",e),children:n.jsx("path",{d:"M10.06 18.701a1.628 1.628 0 0 0 2.43-.676l.77-2.34a3.82 3.82 0 0 1 2.416-2.418l2.238-.727a1.6 1.6 0 0 0 .786-.595a1.62 1.62 0 0 0-.849-2.489l-2.215-.72a3.82 3.82 0 0 1-2.42-2.414l-.727-2.237a1.62 1.62 0 0 0-.594-.785a1.655 1.655 0 0 0-1.879 0a1.63 1.63 0 0 0-.6.8L8.68 6.365a3.82 3.82 0 0 1-2.359 2.37l-2.24.726a1.626 1.626 0 0 0 .02 3.073l2.216.72a3.86 3.86 0 0 1 1.816 1.286c.266.343.471.728.606 1.14l.728 2.234c.112.318.32.593.595.787m-3.273-6.873l-2.22-.72s-.085-.038-.085-.108a.14.14 0 0 1 .084-.115L6.8 10.16a5.34 5.34 0 0 0 3.32-3.375l.721-2.219s.043-.084.114-.084s.113.084.113.084l.723 2.223a5.32 5.32 0 0 0 3.377 3.372l2.27.735a.13.13 0 0 1 .078.11a.15.15 0 0 1-.083.113l-2.225.722a5.32 5.32 0 0 0-3.374 3.374l-.715 2.2a.11.11 0 0 1-.115.093c-.104 0-.118-.075-.118-.075l-.723-2.22a5.32 5.32 0 0 0-3.376-3.385m13.017 12.954A1.2 1.2 0 0 0 20.5 25a1.2 1.2 0 0 0 .692-.216a1.2 1.2 0 0 0 .446-.6l.372-1.143a1.61 1.61 0 0 1 1.017-1.02l1.166-.378A1.21 1.21 0 0 0 25 20.505a1.2 1.2 0 0 0-.844-1.146l-1.144-.37a1.61 1.61 0 0 1-1.02-1.018l-.38-1.163a1.2 1.2 0 0 0-2.274.016l-.374 1.146a1.61 1.61 0 0 1-.993 1.017l-1.166.378a1.21 1.21 0 0 0-.807 1.139a1.2 1.2 0 0 0 .823 1.138l1.144.372a1.6 1.6 0 0 1 1.02 1.023l.379 1.163a1.2 1.2 0 0 0 .44.582m-1.371-4.194l-.27-.088l.283-.096a3.12 3.12 0 0 0 1.943-1.974l.088-.27l.089.272a3.11 3.11 0 0 0 1.974 1.975l.293.1l-.271.087a3.12 3.12 0 0 0-1.974 1.977l-.088.27l-.088-.272a3.12 3.12 0 0 0-1.98-1.98"})}),Re={plus:"lucide:plus",minus:"lucide:minus",close:"lucide:x",check:"lucide:check",menu:"lucide:menu",moreHorizontal:"lucide:ellipsis",text:"lucide:type",image:"lucide:image",layers:"lucide:layers",shapes:"lucide:shapes",trash:"lucide:trash-2",copy:"lucide:copy",pencil:"lucide:pencil",scissors:"lucide:scissors",save:"lucide:save",folderOpen:"lucide:folder-open",download:"lucide:download",eye:"lucide:eye",eyeOff:"lucide:eye-off",lock:"lucide:lock",lockOpen:"lucide:lock-open",search:"lucide:search",link:"lucide:link",palette:"lucide:palette",rotateLeft:"lucide:rotate-ccw",rotateCcwSquare:"lucide:rotate-ccw-square",bold:"lucide:bold",italic:"lucide:italic",underline:"lucide:underline",alignLeft:"lucide:align-left",alignCenter:"lucide:align-center",alignRight:"lucide:align-right",play:"lucide:play",pause:"lucide:pause",grip:"lucide:grip-vertical",fileText:"lucide:file-text",group:"lucide:group",undo:"lucide:undo-2",redo:"lucide:redo-2",fitScreen:"lucide:scan",maximize:"lucide:maximize",alertCircle:"lucide:alert-circle",wand:"lucide:wand-2"},Ps=({icon:e,label:t,onClose:r,className:o,closeButtonStyle:s="icon"})=>{const i=l.useRef(null),a=l.useRef({x:0,y:0});return l.useEffect(()=>{const c=i.current;if(!c)return;const d=h=>{a.current={x:h.touches[0].clientX,y:h.touches[0].clientY}},u=h=>{const f=Math.abs(h.touches[0].clientX-a.current.x),p=Math.abs(h.touches[0].clientY-a.current.y);f>10&&f>p&&h.preventDefault()};return c.addEventListener("touchstart",d,{passive:!0}),c.addEventListener("touchmove",u,{passive:!1}),()=>{c.removeEventListener("touchstart",d),c.removeEventListener("touchmove",u)}},[]),n.jsxs("div",{ref:i,className:Bn("flex w-full items-center justify-between",o),style:{touchAction:"pan-y"},children:[n.jsxs("div",{className:"flex items-center gap-3 md:gap-2",children:[typeof e=="string"?n.jsx(de,{icon:e,className:"text-primary size-7 md:size-5"}):e,n.jsx("span",{className:"text-foreground text-lg font-semibold md:text-sm md:font-medium",children:t})]}),s==="done"?n.jsx("button",{onClick:r,className:"bg-primary text-primary-foreground rounded-xl hover:bg-primary/90 shadow-sm px-8 py-3.5 text-xl font-bold transition-colors md:rounded-button md:shadow-none md:px-4 md:py-2 md:text-sm md:font-medium","aria-label":"Done",children:"Done"}):n.jsx("button",{onClick:r,className:"hover:bg-muted text-foreground/70 hover:text-foreground flex size-11 items-center justify-center rounded-md transition-colors md:size-7","aria-label":"Close panel",children:n.jsx(de,{icon:Re.close,className:"size-7 md:size-4"})})]})};Ps.displayName="CollapsedToolbarHeader";function ga({children:e,className:t}){const r=l.useRef(null);return l.useEffect(()=>{const o=r.current;if(!o)return;const s=a=>{a.stopPropagation()},i=a=>{a.preventDefault(),a.stopPropagation()};return o.addEventListener("touchstart",s,{passive:!1}),o.addEventListener("touchmove",i,{passive:!1}),()=>{o.removeEventListener("touchstart",s),o.removeEventListener("touchmove",i)}},[]),n.jsx("div",{ref:r,className:t,style:{touchAction:"none"},children:e})}const sn=({label:e,value:t,onChange:r,min:o,max:s,step:i=1,unit:a="",showInput:c=!1,inputWidth:d="56px",className:u,variant:h="inline"})=>{const f=Math.round(t);return h==="stacked"?n.jsxs("div",{className:Bn("flex flex-col gap-2.5 md:gap-1.5",u),children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-foreground/60 text-base md:text-xs",children:e}),c&&n.jsx("input",{type:"number",value:f,onChange:p=>r(Math.max(o,Math.min(s,Number(p.target.value)))),min:o,max:s,"aria-label":`${e} value`,className:"bg-transparent text-foreground w-14 rounded-md border-none px-2.5 py-2 text-right text-base md:w-14 md:rounded md:px-1.5 md:py-1 md:text-[13px]",style:{width:d}})]}),n.jsx(ga,{children:n.jsxs(m.Slider,{value:[t],onValueChange:p=>r(p[0]),min:o,max:s,step:i,children:[n.jsx(m.Slider.Track,{className:"bg-foreground/10 h-2.5 md:h-2",children:n.jsx(m.Slider.Fill,{className:"bg-primary"})}),n.jsx(m.Slider.Thumb,{className:"size-7 md:size-6"})]})})]}):n.jsxs("div",{className:Bn("flex items-center gap-3",u),children:[n.jsx("span",{className:"text-foreground/70 text-base md:text-[13px] whitespace-nowrap",children:e}),c?n.jsx("input",{type:"number",value:f,onChange:p=>r(Math.max(o,Math.min(s,Number(p.target.value)))),min:o,max:s,"aria-label":`${e} value`,className:"bg-transparent text-foreground rounded-md border-none px-2 py-2 text-right text-base md:py-1.5 md:text-[13px]",style:{width:d}}):null,n.jsx(ga,{className:"flex-1",children:n.jsxs(m.Slider,{value:[t],onValueChange:p=>r(p[0]),min:o,max:s,step:i,children:[n.jsx(m.Slider.Track,{className:"bg-foreground/10 h-2.5 md:h-2",children:n.jsx(m.Slider.Fill,{className:"bg-primary"})}),n.jsx(m.Slider.Thumb,{className:"size-7 md:size-6"})]})}),n.jsxs("span",{className:"text-foreground text-base md:text-[13px] min-w-[44px] md:min-w-[32px] text-right",children:[f,a]})]})},xa="border-2 border-primary overflow-hidden",ba="border-2 border-border-primary hover:border-border-focus overflow-hidden",Ho=({presets:e,selectedId:t,onSelect:r,showOff:o=!0,size:s=40,ariaLabel:i="Preset options"})=>{const a=l.useRef(null),c=l.useCallback(f=>{f.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})},[]),d=l.useCallback(f=>{if(f.key!=="ArrowLeft"&&f.key!=="ArrowRight")return;f.preventDefault(),f.stopPropagation();const p=a.current;if(!p)return;const g=Array.from(p.querySelectorAll("button[data-preset-id]")),b=document.activeElement;let x=g.indexOf(b);x===-1&&(x=g.findIndex(C=>C.getAttribute("aria-selected")==="true"),x===-1&&(x=0));let y;f.key==="ArrowRight"?y=x<g.length-1?x+1:0:y=x>0?x-1:g.length-1;const v=g[y];v.focus(),c(v);const w=v.getAttribute("data-preset-id");w!==null&&r(w)},[c,r]),u=o&&!t,h=o?!0:e.some(f=>f.id===t);return n.jsxs("div",{ref:a,className:"flex gap-1.5 overflow-x-auto p-1 -m-1",style:{flexWrap:"nowrap"},role:"listbox","aria-label":i,onKeyDown:d,children:[o&&n.jsx("button",{"data-preset-id":"",role:"option","aria-selected":u,tabIndex:u||!h?0:-1,onClick:()=>r(""),className:`shrink-0 rounded-md transition-all flex items-center justify-center ${u?xa:ba}`,style:{width:s,height:s},title:"None",children:n.jsx("span",{className:"text-xs text-muted-foreground",children:"Off"})}),e.map((f,p)=>{const g=t===f.id,b=g||!o&&!h&&p===0;return n.jsx("button",{"data-preset-id":f.id,role:"option","aria-selected":g,tabIndex:b?0:-1,onClick:()=>r(f.id),className:`shrink-0 rounded-md transition-all ${g?xa:ba}`,style:{width:s,height:s},title:f.name,children:f.thumbnailUrl&&n.jsx("img",{src:f.thumbnailUrl,alt:f.name,className:"w-full h-full object-cover",loading:"lazy"})},f.id)})]})},fp=e=>{var p,g;const{pointerCoordinates:t,droppableContainers:r,droppableRects:o}=e;let s=Uh(e);if(s.length===0&&(s=Oh(e)),s.length===0||!t)return s;const i=s[0];if(String(i.id).startsWith("group-footer::"))return[{...i,data:{...i.data,zone:"after"}}];const a=o.get(i.id);if(!a)return s;const c=t.y-a.top,d=a.height,u=r.find(b=>b.id===i.id),h=((g=(p=u==null?void 0:u.data)==null?void 0:p.current)==null?void 0:g.isGroup)===!0;let f;return h?c<d*.25?f="before":c>d*.75?f="after":f="into":f=c<d/2?"before":"after",[{...i,data:{...i.data,zone:f}}]},pp=({layer:e,isOver:t,dropPosition:r,isDragActive:o,showPreviewImages:s,previewDisplaySize:i,onSelect:a,onToggleVisibility:c,onToggleLock:d,onDuplicate:u,onDelete:h})=>{const{attributes:f,listeners:p,setNodeRef:g,isDragging:b}=Bf({id:e.id}),{setNodeRef:x}=Rl({id:e.id,data:{isGroup:!!e.isGroup}}),y=l.useCallback(I=>{g(I),x(I)},[g,x]),v=e.isGroup,w=e.depth>0,C=w?e.depth*24:0,j={opacity:b?.3:1,paddingLeft:C+8,paddingRight:8,paddingTop:v?6:8,paddingBottom:v?6:8,minHeight:v?32:36,display:"flex",alignItems:"center",gap:8,cursor:"pointer",position:"relative",touchAction:"manipulation"};(w||v)&&(j.backgroundColor="var(--surface-secondary, rgba(0,0,0,0.04))"),t&&!b&&(r==="before"?j.borderTop="2px solid var(--primary, var(--accent-primary, #007AFF))":r==="after"?j.borderBottom="2px solid var(--primary, var(--accent-primary, #007AFF))":r==="into"&&(j.outline="2px solid var(--primary, var(--accent-primary, #007AFF))",j.outlineOffset="-2px",j.backgroundColor="var(--accent-primary-alpha, rgba(0, 122, 255, 0.08))"));const M=e.isSelected?{outline:"3px solid var(--primary, var(--accent-primary, #007AFF))",outlineOffset:"2px"}:{},S=()=>a(e.id),R=n.jsx("span",{...p,"aria-label":"Drag to reorder",title:"Drag to reorder",style:{touchAction:"none",cursor:"grab",display:"flex",alignItems:"center",justifyContent:"center",width:36,alignSelf:"stretch",marginLeft:-4,marginRight:4,flexShrink:0,color:"var(--text-secondary, #888)",opacity:.6},children:n.jsx(de,{icon:"lucide:grip-vertical",style:{fontSize:24}})});return v?n.jsxs("div",{ref:y,style:j,...f,children:[R,n.jsx(de,{icon:"lucide:folder-open",style:{fontSize:18,color:"var(--text-secondary, #888)",flexShrink:0}}),n.jsx("span",{onClick:S,style:{fontSize:13,fontWeight:600,color:"var(--foreground, #333)",flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),!o&&(!e.children||e.children.length===0)&&n.jsx("div",{style:{display:"flex",gap:4,flexShrink:0},children:n.jsx(Wn,{title:"Delete Group",onClick:()=>h(e.id),style:{color:"var(--error, #ef4444)"},children:n.jsx(de,{icon:Re.trash,className:"size-6"})})})]}):n.jsxs("div",{ref:y,style:j,...f,children:[R,s&&e.previewUrl?n.jsx("img",{src:e.previewUrl,alt:e.name,onClick:S,style:{width:i,height:i,objectFit:"contain",borderRadius:4,border:"1px solid var(--border-primary, #e5e5e5)",cursor:"pointer",flexShrink:0,...M}}):n.jsx("div",{style:{width:i,height:i,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,opacity:.6,border:"1px solid var(--border-primary, #e5e5e5)",borderRadius:4,cursor:"pointer",flexShrink:0,...M},onClick:S,children:n.jsx(de,{icon:Re.fileText})}),n.jsx("div",{style:{flex:1,minWidth:0},onClick:S}),!o&&n.jsxs("div",{style:{display:"flex",gap:4,flexShrink:0},children:[n.jsx(Wn,{title:e.visible?"Hide":"Show",onClick:()=>c(e.id),style:{opacity:e.visible?1:.4},children:n.jsx(de,{icon:e.visible?Re.eye:Re.eyeOff,className:"size-6"})}),n.jsx(Wn,{title:e.locked?"Unlock":"Lock",onClick:()=>d(e.id),style:{opacity:e.locked?1:.4},children:n.jsx(de,{icon:e.locked?Re.lock:Re.lockOpen,className:"size-6"})}),n.jsx(Wn,{title:"Duplicate",onClick:()=>u(e.id),children:n.jsx(de,{icon:Re.copy,className:"size-6"})}),n.jsx(Wn,{title:"Delete",onClick:()=>h(e.id),style:{color:"var(--error, #ef4444)"},children:n.jsx(de,{icon:Re.trash,className:"size-6"})})]})]})},Wn=({title:e,onClick:t,style:r,children:o})=>n.jsx("button",{onClick:s=>{s.stopPropagation(),t()},style:{background:"none",border:"none",cursor:"pointer",padding:4,opacity:.6,...r},title:e,children:o}),mp=({groupId:e,isOver:t,depth:r})=>{const{setNodeRef:o}=Rl({id:`group-footer::${e}`}),s=(r+1)*24;return n.jsx("div",{ref:o,style:{height:8,marginLeft:s,position:"relative",...t?{borderBottom:"2px solid var(--primary, var(--accent-primary, #007AFF))"}:{}}})},gp=({layer:e,showPreviewImages:t,previewDisplaySize:r})=>n.jsxs("div",{style:{paddingLeft:8,paddingRight:8,paddingTop:8,paddingBottom:8,display:"flex",alignItems:"center",gap:8,backgroundColor:"var(--surface, #fff)",borderRadius:8,boxShadow:"0 4px 16px rgba(0,0,0,0.15)",opacity:.9},children:[e.isGroup?n.jsx(de,{icon:"lucide:folder-open",style:{fontSize:18,color:"var(--text-secondary, #888)"}}):t&&e.previewUrl?n.jsx("img",{src:e.previewUrl,alt:e.name,style:{width:r,height:r,objectFit:"contain",borderRadius:4,border:"1px solid var(--border-primary, #e5e5e5)"}}):n.jsx("div",{style:{width:r,height:r,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,opacity:.6,border:"1px solid var(--border-primary, #e5e5e5)",borderRadius:4},children:n.jsx(de,{icon:Re.fileText})}),n.jsx("span",{style:{fontSize:13,color:"var(--foreground, #333)"},children:e.name})]}),Il=({width:e=250,height:t,showPreviewImages:r=!0,enableDragReorder:o=!1,enableGrouping:s=!1,style:i={},className:a="",showHeader:c=!0,...d})=>{const{activeArtboard:u}=Qr(),h=(u==null?void 0:u.previewBackgroundColor)||(u==null?void 0:u.backgroundColor)||"transparent",f=80,p=160,{layers:g,flatLayers:b,selectLayer:x,toggleVisibility:y,toggleLock:v,deleteLayer:w,duplicateLayer:C,reorderById:j,reorderWithinGroup:M,addToGroup:S,removeFromGroup:R,createEmptyGroup:I,findElementById:D,findParentGroup:E,generateAllPreviews:O}=Qs({...d,previewSize:p,previewBackgroundColor:h});l.useEffect(()=>{r&&b.length>0&&O()},[r,b.length,h,O]);const z=l.useMemo(()=>{const U=new Map,W=Ie=>{for(const ke of Ie)U.set(ke.id,ke),ke.children&&W(ke.children)};return W(g),U},[g]),_=l.useCallback((U,W,Ie)=>{const ke=E(U),Ke=E(W);ke&&!Ke?R(U,W,Ie):j(U,W,Ie)},[E,R,j]),k=sp({onReorder:_,onDropIntoGroup:S,onDropIntoGroupAtPosition:(U,W)=>S(U,W),onGroupReorder:M,onRemoveFromGroup:R,findParentGroup:E}),Y=U=>[...U].reverse().map(Ie=>n.jsxs(l.Fragment,{children:[n.jsx(pp,{layer:Ie,isOver:k.overId===Ie.id,dropPosition:k.overId===Ie.id?k.dropPosition:null,isDragActive:!!k.activeId,showPreviewImages:r,previewDisplaySize:f,onSelect:x,onToggleVisibility:y,onToggleLock:v,onDuplicate:C,onDelete:w}),Ie.children&&Y(Ie.children),Ie.isGroup&&n.jsx(mp,{groupId:Ie.id,isOver:k.overId===`group-footer::${Ie.id}`,depth:Ie.depth})]},Ie.id)),B=U=>[...U].reverse().map(Ie=>n.jsxs(l.Fragment,{children:[n.jsx(xp,{layer:Ie,showPreviewImages:r,previewDisplaySize:f,onSelect:x,onToggleVisibility:y,onToggleLock:v,onDuplicate:C,onDelete:w}),Ie.children&&B(Ie.children)]},Ie.id)),G=k.activeId?z.get(k.activeId):null,{width:se,height:A,flex:Z,...J}=i,q=se||(a.includes("w-full")?"100%":e?`${e}px`:void 0),ae=t||A||void 0,pe=Z!==void 0?Z:ae==="100%"||ae==="100vh"?1:void 0;return n.jsxs("div",{className:`layers-panel ${a}`,style:{width:q,height:ae,flex:pe,display:"flex",flexDirection:"column",backgroundColor:"transparent",minHeight:0,...J},children:[(c||s)&&n.jsxs("div",{style:{padding:"10px 16px",borderBottom:"1px solid var(--border-primary, #e5e5e5)",fontWeight:500,fontSize:13,color:"var(--text-secondary, #666)",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[c&&n.jsxs("span",{children:["Layers (",b.length,")"]}),!c&&n.jsx("span",{}),s&&n.jsxs("button",{onClick:I,style:{background:"none",border:"none",cursor:"pointer",fontSize:13,fontWeight:500,color:"var(--primary, var(--accent-primary, #007AFF))",display:"flex",alignItems:"center",gap:4},children:[n.jsx(de,{icon:"lucide:folder-plus",style:{fontSize:16}}),"Add Group"]})]}),n.jsxs("div",{style:{flex:1,overflow:"auto",minHeight:0},children:[g.length>0?o?n.jsxs(Ff,{sensors:k.sensors,collisionDetection:fp,onDragStart:k.onDragStart,onDragMove:k.onDragMove,onDragOver:k.onDragOver,onDragEnd:k.onDragEnd,onDragCancel:k.onDragCancel,children:[Y(g),n.jsx(tp,{dropAnimation:null,children:G?n.jsx(gp,{layer:G,showPreviewImages:r,previewDisplaySize:f}):null})]}):B(g):n.jsx("div",{style:{padding:24,textAlign:"center",color:"var(--text-secondary, #999)",fontSize:12},children:"No layers"}),o&&g.length>1&&n.jsx("div",{style:{padding:"12px 16px",textAlign:"center",color:"var(--text-secondary, #aaa)",fontSize:12},children:"Drag to reorder"})]})]})},xp=({layer:e,showPreviewImages:t,previewDisplaySize:r,onSelect:o,onToggleVisibility:s,onToggleLock:i,onDuplicate:a,onDelete:c})=>{const d=e.depth>0,u=d?e.depth*24:0,h=e.isSelected?{outline:"3px solid var(--primary, var(--accent-primary, #007AFF))",outlineOffset:"2px"}:{},f={paddingLeft:u+8,paddingRight:8,paddingTop:e.isGroup?6:8,paddingBottom:e.isGroup?6:8,minHeight:e.isGroup?32:36,display:"flex",alignItems:"center",gap:8,cursor:"pointer"};return(d||e.isGroup)&&(f.backgroundColor="var(--surface-secondary, rgba(0,0,0,0.04))"),e.isGroup?n.jsxs("div",{style:f,children:[n.jsx(de,{icon:"lucide:folder-open",style:{fontSize:18,color:"var(--text-secondary, #888)"}}),n.jsx("span",{onClick:()=>o(e.id),style:{fontSize:13,fontWeight:600,flex:1},children:e.name})]},e.id):n.jsxs("div",{style:f,children:[t&&e.previewUrl?n.jsx("img",{src:e.previewUrl,alt:e.name,onClick:()=>o(e.id),style:{width:r,height:r,objectFit:"contain",borderRadius:4,border:"1px solid var(--border-primary, #e5e5e5)",cursor:"pointer",...h}}):n.jsx("div",{style:{width:r,height:r,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,opacity:.6,border:"1px solid var(--border-primary, #e5e5e5)",borderRadius:4,cursor:"pointer",...h},onClick:()=>o(e.id),children:n.jsx(de,{icon:Re.fileText})}),n.jsx("div",{style:{flex:1},onClick:()=>o(e.id)}),n.jsxs("div",{style:{display:"flex",gap:4},children:[n.jsx(Wn,{title:e.visible?"Hide":"Show",onClick:()=>s(e.id),style:{opacity:e.visible?1:.4},children:n.jsx(de,{icon:e.visible?Re.eye:Re.eyeOff,className:"size-6"})}),n.jsx(Wn,{title:e.locked?"Unlock":"Lock",onClick:()=>i(e.id),style:{opacity:e.locked?1:.4},children:n.jsx(de,{icon:e.locked?Re.lock:Re.lockOpen,className:"size-6"})}),n.jsx(Wn,{title:"Duplicate",onClick:()=>a(e.id),children:n.jsx(de,{icon:Re.copy,className:"size-6"})}),n.jsx(Wn,{title:"Delete",onClick:()=>c(e.id),style:{color:"var(--error, #ef4444)"},children:n.jsx(de,{icon:Re.trash,className:"size-6"})})]})]},e.id)},bp=Object.freeze(Object.defineProperty({__proto__:null,LayersPanel:Il},Symbol.toStringTag,{value:"Module"}));function yp(){const[e,t]=l.useState(!1);return l.useEffect(()=>{if(typeof document>"u")return;const r=()=>t(document.documentElement.classList.contains("dark"));r();const o=new MutationObserver(r);return o.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>o.disconnect()},[]),e}const oo=({isOpen:e,onClose:t,title:r,description:o,children:s,placement:i="bottom",height:a,maxHeight:c="70vh",width:d,maxWidth:u="400px",showCloseButton:h=!0,headerActions:f,hideVisibleTitle:p=!1,hideHandle:g=!1,disableScrollWrapper:b=!1,disableOverflowHidden:x=!1,"data-testid":y})=>{const v=i==="bottom"?a||c:void 0,C=yp()?.65:.4;return n.jsx(m.Drawer,{open:e,onOpenChange:j=>!j&&t(),children:n.jsxs(m.DrawerContent,{placement:i,width:d,maxWidth:u,hideHandle:g||i!=="bottom",showOverlay:!0,overlayOpacity:C,className:x?"":"overflow-hidden",style:{...v&&i==="bottom"?{height:v}:{},zIndex:"var(--z-drawer, 10002)"},"data-testid":y,"data-preserve-selection":!0,children:[n.jsx(m.DrawerTitle,{className:"sr-only",children:r}),o&&n.jsx(m.DrawerDescription,{className:"sr-only",children:o}),b?n.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[(!p||f||h)&&n.jsxs("div",{className:"border-border-primary flex shrink-0 items-center justify-between gap-4 border-b px-6 py-4",children:[!p&&n.jsx("h2",{className:"text-foreground text-lg font-semibold",children:r}),n.jsxs("div",{className:"flex items-center gap-2",children:[f,h&&n.jsx(m.Button,{variant:"ghost",size:"sm",onClick:t,className:"min-w-8 px-2","aria-label":"Close drawer",children:n.jsx(de,{icon:Re.close,className:"size-6"})})]})]}),s]}):n.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[(!p||f||h)&&n.jsxs("div",{className:"border-border-primary flex shrink-0 items-center justify-between gap-4 border-b px-6 py-4",children:[!p&&n.jsx("h2",{className:"text-foreground text-lg font-semibold",children:r}),n.jsxs("div",{className:"flex items-center gap-2",children:[f,h&&n.jsx(m.Button,{variant:"ghost",size:"sm",onClick:t,className:"min-w-8 px-2","aria-label":"Close drawer",children:n.jsx(de,{icon:Re.close,className:"size-6"})})]})]}),s]})]})})};function $o(){return($o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e}).apply(this,arguments)}function Al(e,t){if(e==null)return{};var r,o,s={},i=Object.keys(e);for(o=0;o<i.length;o++)t.indexOf(r=i[o])>=0||(s[r]=e[r]);return s}function _r(e){var t=l.useRef(e),r=l.useRef(function(o){t.current&&t.current(o)});return t.current=e,r.current}var Kr=function(e,t,r){return t===void 0&&(t=0),r===void 0&&(r=1),e>r?r:e<t?t:e},Hr=function(e){return"touches"in e},Fs=function(e){return e&&e.ownerDocument.defaultView||self},ya=function(e,t,r){var o=e.getBoundingClientRect(),s=Hr(t)?function(i,a){for(var c=0;c<i.length;c++)if(i[c].identifier===a)return i[c];return i[0]}(t.touches,r):t;return{left:Kr((s.pageX-(o.left+Fs(e).pageXOffset))/o.width),top:Kr((s.pageY-(o.top+Fs(e).pageYOffset))/o.height)}},va=function(e){!Hr(e)&&e.preventDefault()},Dl=l.memo(function(e){var t=e.onMove,r=e.onKey,o=e.onEnd,s=Al(e,["onMove","onKey","onEnd"]),i=l.useRef(null),a=_r(t),c=_r(r),d=_r(o),u=l.useRef(null),h=l.useRef(!1),f=l.useMemo(function(){var y=function(C){va(C),(Hr(C)?C.touches.length>0:C.buttons>0)&&i.current?a(ya(i.current,C,u.current)):(w(!1),d())},v=function(){w(!1),d()};function w(C){var j=h.current,M=Fs(i.current),S=C?M.addEventListener:M.removeEventListener;S(j?"touchmove":"mousemove",y),S(j?"touchend":"mouseup",v)}return[function(C){var j=C.nativeEvent,M=i.current;if(M&&(va(j),!function(R,I){return I&&!Hr(R)}(j,h.current)&&M)){if(Hr(j)){h.current=!0;var S=j.changedTouches||[];S.length&&(u.current=S[0].identifier)}M.focus(),a(ya(M,j,u.current)),w(!0)}},function(C){var j=C.which||C.keyCode;j<37||j>40||(C.preventDefault(),c({left:j===39?.05:j===37?-.05:0,top:j===40?.05:j===38?-.05:0}))},function(C){var j=C.which||C.keyCode;j>=37&&j<=40&&d()},w]},[c,a,d]),p=f[0],g=f[1],b=f[2],x=f[3];return l.useEffect(function(){return x},[x]),l.createElement("div",$o({},s,{onTouchStart:p,onMouseDown:p,className:"react-colorful__interactive",ref:i,onKeyDown:g,onKeyUp:b,tabIndex:0,role:"slider"}))}),hi=function(e){return e.filter(Boolean).join(" ")},Ll=function(e){var t=e.color,r=e.left,o=e.top,s=o===void 0?.5:o,i=hi(["react-colorful__pointer",e.className]);return l.createElement("div",{className:i,style:{top:100*s+"%",left:100*r+"%"}},l.createElement("div",{className:"react-colorful__pointer-fill",style:{backgroundColor:t}}))},on=function(e,t,r){return t===void 0&&(t=0),r===void 0&&(r=Math.pow(10,t)),Math.round(r*e)/r},vp=function(e){return jp(zs(e))},zs=function(e){return e[0]==="#"&&(e=e.substring(1)),e.length<6?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:e.length===4?on(parseInt(e[3]+e[3],16)/255,2):1}:{r:parseInt(e.substring(0,2),16),g:parseInt(e.substring(2,4),16),b:parseInt(e.substring(4,6),16),a:e.length===8?on(parseInt(e.substring(6,8),16)/255,2):1}},wp=function(e){return kp(Sp(e))},Cp=function(e){var t=e.s,r=e.v,o=e.a,s=(200-t)*r/100;return{h:on(e.h),s:on(s>0&&s<200?t*r/100/(s<=100?s:200-s)*100:0),l:on(s/2),a:on(o,2)}},Os=function(e){var t=Cp(e);return"hsl("+t.h+", "+t.s+"%, "+t.l+"%)"},Sp=function(e){var t=e.h,r=e.s,o=e.v,s=e.a;t=t/360*6,r/=100,o/=100;var i=Math.floor(t),a=o*(1-r),c=o*(1-(t-i)*r),d=o*(1-(1-t+i)*r),u=i%6;return{r:on(255*[o,c,a,a,d,o][u]),g:on(255*[d,o,o,c,a,a][u]),b:on(255*[a,a,d,o,o,c][u]),a:on(s,2)}},mo=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},kp=function(e){var t=e.r,r=e.g,o=e.b,s=e.a,i=s<1?mo(on(255*s)):"";return"#"+mo(t)+mo(r)+mo(o)+i},jp=function(e){var t=e.r,r=e.g,o=e.b,s=e.a,i=Math.max(t,r,o),a=i-Math.min(t,r,o),c=a?i===t?(r-o)/a:i===r?2+(o-t)/a:4+(t-r)/a:0;return{h:on(60*(c<0?c+6:c)),s:on(i?a/i*100:0),v:on(i/255*100),a:s}},Ep=l.memo(function(e){var t=e.hue,r=e.onChange,o=e.onChangeEnd,s=hi(["react-colorful__hue",e.className]);return l.createElement("div",{className:s},l.createElement(Dl,{onMove:function(i){r({h:360*i.left})},onKey:function(i){r({h:Kr(t+360*i.left,0,360)})},onEnd:o,"aria-label":"Hue","aria-valuenow":on(t),"aria-valuemax":"360","aria-valuemin":"0"},l.createElement(Ll,{className:"react-colorful__hue-pointer",left:t/360,color:Os({h:t,s:100,v:100,a:1})})))}),Tp=l.memo(function(e){var t=e.hsva,r=e.onChange,o=e.onChangeEnd,s={backgroundColor:Os({h:t.h,s:100,v:100,a:1})};return l.createElement("div",{className:"react-colorful__saturation",style:s},l.createElement(Dl,{onMove:function(i){r({s:100*i.left,v:100-100*i.top})},onKey:function(i){r({s:Kr(t.s+100*i.left,0,100),v:Kr(t.v-100*i.top,0,100)})},onEnd:o,"aria-label":"Color","aria-valuetext":"Saturation "+on(t.s)+"%, Brightness "+on(t.v)+"%"},l.createElement(Ll,{className:"react-colorful__saturation-pointer",top:1-t.v/100,left:t.s/100,color:Os(t)})))}),Pl=function(e,t){if(e===t)return!0;for(var r in e)if(e[r]!==t[r])return!1;return!0},Rp=function(e,t){return e.toLowerCase()===t.toLowerCase()||Pl(zs(e),zs(t))};function Np(e,t,r,o){var s=_r(r),i=_r(o),a=l.useState(function(){return e.toHsva(t)}),c=a[0],d=a[1],u=l.useRef({color:t,hsva:c}),h=l.useRef(!1);l.useEffect(function(){if(!e.equal(t,u.current.color)){var g=e.toHsva(t);u.current={hsva:g,color:t},d(g),h.current=!1}},[t,e]),l.useEffect(function(){var g;Pl(c,u.current.hsva)||e.equal(g=e.fromHsva(c),u.current.color)||(u.current={hsva:c,color:g},s(g),h.current=!0)},[c,e,s]);var f=l.useCallback(function(g){d(function(b){return Object.assign({},b,g)})},[]),p=l.useCallback(function(){h.current&&(h.current=!1,i(u.current.color))},[i]);return[c,f,p]}var Mp=typeof window<"u"?l.useLayoutEffect:l.useEffect,Ip=function(){return typeof __webpack_nonce__<"u"?__webpack_nonce__:void 0},wa=new Map,Ap=function(e){Mp(function(){var t=e.current?e.current.ownerDocument:document;if(t!==void 0&&!wa.has(t)){var r=t.createElement("style");r.innerHTML=`.react-colorful{position:relative;display:flex;flex-direction:column;width:200px;height:200px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.react-colorful__saturation{position:relative;flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(0deg,#000,transparent),linear-gradient(90deg,#fff,hsla(0,0%,100%,0))}.react-colorful__alpha-gradient,.react-colorful__pointer-fill{content:"";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;border-radius:inherit}.react-colorful__alpha-gradient,.react-colorful__saturation{box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}.react-colorful__alpha,.react-colorful__hue{position:relative;height:24px}.react-colorful__hue{background:linear-gradient(90deg,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red)}.react-colorful__last-control{border-radius:0 0 8px 8px}.react-colorful__interactive{position:absolute;left:0;top:0;right:0;bottom:0;border-radius:inherit;outline:none;touch-action:none}.react-colorful__pointer{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}.react-colorful__interactive:focus .react-colorful__pointer{transform:translate(-50%,-50%) scale(1.1)}.react-colorful__alpha,.react-colorful__alpha-pointer{background-color:#fff;background-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><path d="M8 0h8v8H8zM0 8h8v8H0z"/></svg>')}.react-colorful__saturation-pointer{z-index:3}.react-colorful__hue-pointer{z-index:2}`,wa.set(t,r);var o=Ip();o&&r.setAttribute("nonce",o),t.head.appendChild(r)}},[])},Dp=function(e){var t=e.className,r=e.colorModel,o=e.color,s=o===void 0?r.defaultColor:o,i=e.onChange,a=e.onChangeEnd,c=Al(e,["className","colorModel","color","onChange","onChangeEnd"]),d=l.useRef(null);Ap(d);var u=Np(r,s,i,a),h=u[0],f=u[1],p=u[2],g=hi(["react-colorful",t]);return l.createElement("div",$o({},c,{ref:d,className:g}),l.createElement(Tp,{hsva:h,onChange:f,onChangeEnd:p}),l.createElement(Ep,{hue:h.h,onChange:f,onChangeEnd:p,className:"react-colorful__last-control"}))},Lp={defaultColor:"000",toHsva:vp,fromHsva:function(e){return wp({h:e.h,s:e.s,v:e.v,a:1})},equal:Rp},Fl=function(e){return l.createElement(Dp,$o({},e,{colorModel:Lp}))};const lr=l.memo(({value:e,onChange:t,documentColors:r=[],imageColors:o=[],icon:s,showSquare:i=!1,allowTransparent:a=!1,isOpen:c,onOpenChange:d,embedded:u=!1})=>{const[h,f]=l.useState(!1),[p,g]=l.useState(e),[b,x]=l.useState(e),y=l.useRef(0),v=l.useRef(null),w=l.useRef(!1),C=l.useRef(t);C.current=t;const j=c!==void 0?c:h,M=d||f;l.useEffect(()=>{!w.current&&e!=="transparent"&&(g(e),x(e))},[e]);const S=k=>{w.current=!0,x(k),g(k);const Y=Date.now(),B=Y-y.current;B>=16?(C.current({target:{value:k}}),y.current=Y,v.current&&(clearTimeout(v.current),v.current=null)):(v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{C.current({target:{value:k}}),y.current=Date.now(),v.current=null,w.current=!1},16-B))},R=l.useRef(b);R.current=b,l.useEffect(()=>{const k=()=>{v.current&&(clearTimeout(v.current),v.current=null,C.current({target:{value:R.current}})),setTimeout(()=>{w.current=!1},50)};return window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k),()=>{window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k)}},[]),l.useEffect(()=>()=>{v.current&&clearTimeout(v.current)},[]);const I=k=>{const Y=k.target.value;g(Y);const B=/^#?([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})$/,G=Y.startsWith("#")?Y:`#${Y}`;B.test(G)&&C.current({target:{value:G}})},D=k=>{S(k)},E=()=>{C.current({target:{value:"transparent"}})},O=e==="transparent",z=i?n.jsx("div",{className:`size-8 md:size-6 rounded-md border border-border-primary ${O?"transparent-pattern-small":""}`,style:O?{}:{backgroundColor:e}}):n.jsxs("div",{className:"relative flex items-center justify-center h-5 w-5",children:[s?n.jsx("span",{className:"flex items-center -translate-y-0.5",children:s}):n.jsx("span",{className:"font-bold text-lg leading-none -translate-y-0.5",children:"A"}),n.jsx("div",{className:`absolute bottom-0 left-1/2 -translate-x-1/2 h-[3px] w-4 rounded-sm ${O?"transparent-pattern-small":""}`,style:O?{}:{backgroundColor:e}})]}),_=n.jsxs("div",{className:"space-y-4 min-w-[232px]",children:[a&&n.jsxs(m.Button,{variant:"ghost",className:`flex w-full cursor-pointer items-center justify-start gap-2 rounded-lg ${O?"bg-primary/10":""}`,onClick:E,children:[n.jsx("div",{className:"transparent-pattern-small h-6 w-6 rounded"}),n.jsx("span",{className:"text-sm font-medium",children:"Transparent"})]}),n.jsx("div",{className:"w-[200px]",children:n.jsx(Fl,{color:O?"#ffffff":b,onChange:S})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("label",{htmlFor:"hex-input",className:"text-sm font-medium uppercase text-foreground/60",children:"HEX"}),n.jsx("input",{id:"hex-input",type:"text",className:"w-24 rounded-lg border border-divider bg-field px-2 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none",value:p,onChange:I,placeholder:"#000000",maxLength:7})]}),r.length>0&&n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsx("div",{className:"text-sm font-medium text-foreground/60",children:"Document colors"}),n.jsx("div",{className:"grid grid-cols-8 gap-1",children:r.map((k,Y)=>n.jsx("button",{className:`h-6 w-6 cursor-pointer rounded border-2 transition-all duration-150 hover:scale-110 ${k===e?"border-primary":"border-transparent"}`,style:{backgroundColor:k},onClick:()=>D(k),"aria-label":k},Y))})]}),o.length>0&&n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsx("div",{className:"text-sm font-medium text-foreground/60",children:"Image colors"}),n.jsx("div",{className:"grid grid-cols-8 gap-1",children:o.map((k,Y)=>n.jsx("button",{className:`h-6 w-6 cursor-pointer rounded border-2 transition-all duration-150 hover:scale-110 ${k===e?"border-primary":"border-transparent"}`,style:{backgroundColor:k},onClick:()=>D(k),"aria-label":k},`img-${Y}`))})]})]});return u?_:n.jsxs(m.Popover,{open:j,onOpenChange:M,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:i?"flex items-center justify-center bg-transparent border-0 p-0 cursor-pointer rounded-md hover:opacity-80 transition-opacity":"toolbar-btn","aria-label":"Color Picker",children:z})}),n.jsx(m.PopoverContent,{className:"w-auto",maxZIndex:!0,children:_})]})});lr.displayName="ColorPickerDropdown";const Pp=({stroke:e,onChange:t})=>{const[r,o]=l.useState((e==null?void 0:e.enabled)||!1),s=(e==null?void 0:e.enabled)||!1,i=(e==null?void 0:e.color)||"#000000",a=(e==null?void 0:e.width)||5,c=(e==null?void 0:e.lineCap)||"butt",d=(e==null?void 0:e.lineJoin)||"miter",u=(e==null?void 0:e.opacity)!==void 0?e.opacity:1,h=y=>{t(y?{enabled:!0,color:i,width:a,lineCap:c,lineJoin:d,opacity:u}:void 0),o(y)},f=y=>{e&&t({...e,color:y.target.value})},p=y=>{e&&t({...e,width:y[0]})},g=y=>{e&&t({...e,opacity:y[0]})},b=y=>{e&&t({...e,lineCap:y})},x=y=>{e&&t({...e,lineJoin:y})};return n.jsxs(m.Disclosure,{open:r,onOpenChange:o,className:"mb-xl",children:[n.jsx(m.DisclosureTrigger,{className:"w-full",children:n.jsxs("div",{className:"flex items-center justify-between w-full",children:[n.jsx(m.Label,{children:"Stroke"}),n.jsx(m.Switch,{checked:s,onCheckedChange:h})]})}),n.jsxs(m.DisclosureContent,{className:"flex flex-col gap-lg pt-lg",children:[n.jsx(m.Fieldset,{className:"flex flex-col gap-sm",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(m.Label,{children:"Color"}),n.jsx(lr,{value:i,onChange:f})]})}),n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Width"}),n.jsx(m.Slider,{value:[a],onValueChange:p,min:1,max:50,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[a,"px"]})]}),n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Opacity"}),n.jsx(m.Slider,{value:[u],onValueChange:g,min:0,max:1,step:.01}),n.jsxs("div",{className:"text-sm text-text-muted",children:[Math.round(u*100),"%"]})]}),n.jsxs(m.TooltipProvider,{delayDuration:300,children:[n.jsxs(m.Fieldset,{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Line Cap"}),n.jsxs(m.RadioGroup,{value:c,onValueChange:b,orientation:"horizontal",children:[n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"butt",id:"cap-butt",children:"Butt"})})}),n.jsx(m.TooltipContent,{children:"Butt - Flat edges"})]}),n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"round",id:"cap-round",children:"Round"})})}),n.jsx(m.TooltipContent,{children:"Round - Rounded edges"})]}),n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"square",id:"cap-square",children:"Square"})})}),n.jsx(m.TooltipContent,{children:"Square - Extended square edges"})]})]})]}),n.jsxs(m.Fieldset,{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Line Join"}),n.jsxs(m.RadioGroup,{value:d,onValueChange:x,orientation:"horizontal",children:[n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"miter",id:"join-miter",children:"Miter"})})}),n.jsx(m.TooltipContent,{children:"Miter - Sharp corners"})]}),n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"round",id:"join-round",children:"Round"})})}),n.jsx(m.TooltipContent,{children:"Round - Rounded corners"})]}),n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"bevel",id:"join-bevel",children:"Bevel"})})}),n.jsx(m.TooltipContent,{children:"Bevel - Beveled corners"})]})]})]})]})]})]})},Fp=({mask:e,index:t,isFirst:r,isLast:o,onUpdate:s,onRemove:i,onReorder:a})=>{var j;const[c,d]=l.useState(!1),u=M=>{switch(M){case"clip":return"🎭";case"alpha":return"🌫️";case"luma":return"🌗";case"distress":return"⚡";default:return"🎭"}},h=M=>{switch(M){case"clip":return"Clip Mask";case"alpha":return"Alpha Mask";case"luma":return"Luma Mask";case"distress":return"Distress Mask";default:return"Unknown Mask"}},f=M=>{s({opacity:M})},p=M=>{s({feather:M})},g=()=>{s({inverted:!e.inverted})},b=M=>{const S=M.target.value;if(S==="image"){const R=e.maskElement.transformType==="image"&&e.maskElement.imageUrl||"";s({maskElement:{transformType:"image",imageUrl:R,x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:{type:"image",width:200,height:200,cropX:0,cropY:0,cropWidth:1,cropHeight:1,flipHorizontal:!1,flipVertical:!1,borderRadius:0}}})}else s(S==="shape"?{maskElement:{transformType:"shape",x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:{type:"shape",shapeType:"star",width:200,height:200,fillColor:"#000000",fillOpacity:1,points:5,innerRadius:.4}}}:{maskElement:{transformType:"custom",x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,text:"MASK",fontSize:80,fontFamily:"Anton",color:"#000000"}})},x=M=>{const S=M.target.value;e.maskElement.transformType==="shape"&&s({maskElement:{transformType:"shape",x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:{...e.maskElement.transformData,shapeType:S}}})},y=M=>{if(e.maskElement.transformType!=="shape"){const S=e.maskElement;s({maskElement:{transformType:e.maskElement.transformType,x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,text:M.target.value,fontSize:S.fontSize||80,fontFamily:S.fontFamily||"Anton",color:S.color||"#000000"}})}},v=M=>{if(e.maskElement.transformType==="image"){const S=e.maskElement;s({maskElement:{transformType:"image",imageUrl:M.target.value,x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:S.transformData||{type:"image",width:200,height:200,cropX:0,cropY:0,cropWidth:1,cropHeight:1,flipHorizontal:!1,flipVertical:!1,borderRadius:0}}})}},w=M=>{if(e.maskElement.transformType==="image"){const S=e.maskElement;s({maskElement:{transformType:"image",imageUrl:S.imageUrl||"",x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:{...S.transformData,width:M,height:M}}})}else if(e.maskElement.transformType==="shape")s({maskElement:{transformType:"shape",x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:{...e.maskElement.transformData,width:M,height:M}}});else{const S=e.maskElement;s({maskElement:{transformType:e.maskElement.transformType,x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,text:S.text||"MASK",fontSize:M,fontFamily:S.fontFamily||"Anton",color:S.color||"#000000"}})}},C=()=>{var M,S;return e.maskElement.transformType==="image"?((M=e.maskElement.transformData)==null?void 0:M.width)||200:e.maskElement.transformType==="shape"?((S=e.maskElement.transformData)==null?void 0:S.width)||200:e.maskElement.fontSize||80};return n.jsxs("div",{className:"rounded-md border border-border-secondary bg-bg-tertiary p-lg",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-lg",children:[n.jsx("span",{className:"text-lg",children:u(e.type)}),n.jsxs("div",{className:"flex flex-col gap-xs",children:[n.jsx("strong",{className:"text-lg text-text-primary",children:h(e.type)}),n.jsxs("small",{className:"text-sm text-text-muted",children:["#",t+1]})]})]}),n.jsx("div",{className:"flex gap-1",children:n.jsxs(m.Tooltip,{delay:0,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{size:"icon",variant:"ghost","aria-label":"Toggle mask details","aria-expanded":c,onClick:()=>d(!c),children:c?"▼":"▶"})}),n.jsx(m.TooltipContent,{children:n.jsx("p",{children:c?"Collapse":"Expand"})})]})})]}),c&&n.jsxs("div",{className:"mt-xl flex flex-col gap-xl border-t border-border-secondary pt-xl",children:[n.jsxs(m.Slider,{className:"slider-no-fill",value:[e.opacity||1],onValueChange:M=>f(M[0]),min:0,max:1,step:.01,children:[n.jsx(m.Label,{children:"Opacity"}),n.jsx(m.Slider.Output,{children:({state:M})=>`${Math.round(M.values[0]*100)}%`}),n.jsx(m.Slider.Track,{}),n.jsx(m.Slider.Thumb,{})]}),n.jsxs(m.Slider,{className:"slider-no-fill",value:[e.feather||0],onValueChange:M=>p(M[0]),min:0,max:50,step:1,children:[n.jsx(m.Label,{children:"Feather"}),n.jsx(m.Slider.Output,{children:({state:M})=>`${M.values[0]}px`}),n.jsx(m.Slider.Track,{}),n.jsx(m.Slider.Thumb,{})]}),n.jsxs("label",{className:"flex cursor-pointer items-center gap-md text-base text-text-secondary",children:[n.jsx("input",{type:"checkbox",checked:e.inverted||!1,onChange:g,className:"h-4 w-4 cursor-pointer"}),n.jsx("span",{children:"Invert Mask"})]}),n.jsxs("div",{className:"flex flex-col gap-lg rounded-md border border-border-dark bg-bg-secondary p-xl",children:[n.jsx("div",{className:"mb-xs text-md font-semibold uppercase tracking-wide text-accent-primary",children:"Mask Shape"}),n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx("label",{htmlFor:`mask-type-${e.id}`,className:"text-base text-text-secondary",children:"Type"}),n.jsxs("select",{id:`mask-type-${e.id}`,value:e.maskElement.transformType==="shape"?"shape":e.maskElement.transformType==="image"?"image":"custom",onChange:b,className:"w-full cursor-pointer rounded-md border border-border-dark bg-bg-tertiary px-md py-sm text-base text-text-primary transition-all duration-base hover:border-accent-primary focus:border-accent-primary focus:outline-none",children:[n.jsx("option",{value:"custom",children:"Text"}),n.jsx("option",{value:"shape",children:"Shape"}),n.jsx("option",{value:"image",children:"Image"})]})]}),e.maskElement.transformType==="shape"&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx("label",{htmlFor:`mask-shape-${e.id}`,className:"text-base text-text-secondary",children:"Shape"}),n.jsxs("select",{id:`mask-shape-${e.id}`,value:((j=e.maskElement.transformData)==null?void 0:j.shapeType)||"star",onChange:x,className:"w-full cursor-pointer rounded-md border border-border-dark bg-bg-tertiary px-md py-sm text-base text-text-primary transition-all duration-base hover:border-accent-primary focus:border-accent-primary focus:outline-none",children:[n.jsx("option",{value:"rectangle",children:"Rectangle"}),n.jsx("option",{value:"circle",children:"Circle"}),n.jsx("option",{value:"ellipse",children:"Ellipse"}),n.jsx("option",{value:"star",children:"Star"})]})]}),e.maskElement.transformType==="image"&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx("label",{htmlFor:`mask-image-${e.id}`,className:"text-base text-text-secondary",children:"Image URL"}),n.jsx("input",{id:`mask-image-${e.id}`,type:"text",value:e.maskElement.imageUrl||"",onChange:v,className:"w-full rounded-md border border-border-dark bg-bg-tertiary px-md py-sm text-base text-text-primary transition-all duration-base hover:border-accent-primary focus:border-accent-primary focus:outline-none",placeholder:"https://... or data:image/..."})]}),e.maskElement.transformType!=="shape"&&e.maskElement.transformType!=="image"&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx("label",{htmlFor:`mask-text-${e.id}`,className:"text-base text-text-secondary",children:"Text"}),n.jsx("input",{id:`mask-text-${e.id}`,type:"text",value:e.maskElement.text||"MASK",onChange:y,className:"w-full rounded-md border border-border-dark bg-bg-tertiary px-md py-sm text-base text-text-primary transition-all duration-base hover:border-accent-primary focus:border-accent-primary focus:outline-none",placeholder:"Mask text"})]}),n.jsxs(m.Slider,{className:"slider-no-fill",value:[C()],onValueChange:M=>w(M[0]),min:20,max:500,step:10,children:[n.jsx(m.Label,{children:"Size"}),n.jsx(m.Slider.Output,{}),n.jsx(m.Slider.Track,{}),n.jsx(m.Slider.Thumb,{})]})]}),n.jsxs("div",{className:"mt-md flex gap-sm",children:[n.jsx("button",{onClick:()=>a("up"),disabled:r,title:"Move Up","aria-label":"Move mask up",className:"flex-1 cursor-pointer rounded-md border border-border-dark bg-bg-hover px-md py-sm text-xl text-text-secondary transition-all duration-slow hover:border-accent-primary hover:bg-bg-dark-hover hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-disabled",children:"↑"}),n.jsx("button",{onClick:()=>a("down"),disabled:o,title:"Move Down","aria-label":"Move mask down",className:"flex-1 cursor-pointer rounded-md border border-border-dark bg-bg-hover px-md py-sm text-xl text-text-secondary transition-all duration-slow hover:border-accent-primary hover:bg-bg-dark-hover hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-disabled",children:"↓"}),n.jsx("button",{onClick:i,title:"Remove Mask","aria-label":"Remove mask",className:"flex-[2] cursor-pointer rounded-md border border-error-light bg-error px-md py-sm text-base font-semibold text-text-on-dark transition-all duration-slow hover:bg-error-light",children:"✕ Remove"})]})]})]})},zp=({masks:e=[],onChange:t})=>{const[r,o]=l.useState(e.length>0),[s,i]=l.useState(!1),a=h=>{const f={id:`mask-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,type:h,maskElement:Op(h),inverted:!1,feather:0,opacity:1};t([...e,f]),i(!1)},c=h=>{t(e.filter(f=>f.id!==h))},d=(h,f)=>{t(e.map(p=>p.id===h?{...p,...f}:p))},u=(h,f)=>{const p=e.findIndex(b=>b.id===h);if(p===-1)return;const g=[...e];f==="up"&&p>0?[g[p],g[p-1]]=[g[p-1],g[p]]:f==="down"&&p<e.length-1&&([g[p],g[p+1]]=[g[p+1],g[p]]),t(g)};return n.jsxs("div",{className:"mb-xl rounded-xl border border-border-primary bg-bg-secondary p-xl",children:[n.jsxs("div",{className:"mb-md flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-md text-xl font-semibold text-text-primary",children:[n.jsxs("span",{children:["Masks (",e.length,")"]}),e.length>0&&n.jsx("button",{onClick:()=>o(!r),className:"rounded-lg border-none bg-transparent px-md py-xs text-base text-text-muted transition-colors duration-fast hover:text-text-primary",title:r?"Collapse":"Expand",children:r?"▼":"▶"})]}),n.jsx("div",{className:"flex gap-sm",children:n.jsx(m.Button,{variant:"default",onClick:()=>i(!s),className:"rounded-lg bg-accent px-xl py-sm font-semibold text-text-on-accent transition-all duration-medium hover:bg-accent-medium",children:"+ Add"})})]}),s&&n.jsxs("div",{className:"mb-md mt-md flex flex-col gap-sm rounded-lg border border-border-medium bg-surface p-md",children:[n.jsxs("button",{onClick:()=>a("clip"),className:"flex cursor-pointer items-center gap-xl rounded-lg border border-border-light bg-bg-secondary p-lg text-left text-text-primary transition-all duration-medium hover:border-accent hover:bg-bg-hover",children:[n.jsx("span",{className:"shrink-0 text-xl",children:"🎭"}),n.jsxs("div",{className:"flex flex-col gap-xs",children:[n.jsx("strong",{className:"text-lg text-text-primary",children:"Clip Mask"}),n.jsx("small",{className:"text-base text-text-secondary",children:"Hard edge clipping (text, shapes)"})]})]}),n.jsxs("button",{onClick:()=>a("alpha"),className:"flex cursor-pointer items-center gap-xl rounded-lg border border-border-light bg-bg-secondary p-lg text-left text-text-primary transition-all duration-medium hover:border-accent hover:bg-bg-hover",children:[n.jsx("span",{className:"shrink-0 text-xl",children:"🌫️"}),n.jsxs("div",{className:"flex flex-col gap-xs",children:[n.jsx("strong",{className:"text-lg text-text-primary",children:"Alpha Mask"}),n.jsx("small",{className:"text-base text-text-secondary",children:"Transparency-based masking"})]})]}),n.jsxs("button",{onClick:()=>a("luma"),className:"flex cursor-pointer items-center gap-xl rounded-lg border border-border-light bg-bg-secondary p-lg text-left text-text-primary transition-all duration-medium hover:border-accent hover:bg-bg-hover",children:[n.jsx("span",{className:"shrink-0 text-xl",children:"🌗"}),n.jsxs("div",{className:"flex flex-col gap-xs",children:[n.jsx("strong",{className:"text-lg text-text-primary",children:"Luma Mask"}),n.jsx("small",{className:"text-base text-text-secondary",children:"Luminosity-based masking"})]})]}),n.jsxs("button",{onClick:()=>a("distress"),className:"flex cursor-pointer items-center gap-xl rounded-lg border border-border-light bg-bg-secondary p-lg text-left text-text-primary transition-all duration-medium hover:border-accent hover:bg-bg-hover",children:[n.jsx("span",{className:"shrink-0 text-xl",children:"⚡"}),n.jsxs("div",{className:"flex flex-col gap-xs",children:[n.jsx("strong",{className:"text-lg text-text-primary",children:"Distress Mask"}),n.jsx("small",{className:"text-base text-text-secondary",children:"Vintage/grunge texture effects"})]})]})]}),r&&e.length>0&&n.jsx("div",{className:"mt-xl flex flex-col gap-md",children:e.map((h,f)=>n.jsx(Fp,{mask:h,index:f,isFirst:f===0,isLast:f===e.length-1,onUpdate:p=>d(h.id,p),onRemove:()=>c(h.id),onReorder:p=>u(h.id,p)},h.id))}),e.length===0&&n.jsxs("div",{className:"p-3xl text-center text-text-secondary",children:[n.jsx("p",{className:"mb-xs text-lg",children:"No masks applied"}),n.jsx("small",{className:"text-base text-border-medium",children:'Click "+ Add" to add a mask'})]})]})};function Op(e){switch(e){case"clip":return{transformType:"custom",text:"MASK",fontSize:80,fontFamily:"Anton",x:0,y:0,rotation:0,color:"#000000"};case"alpha":case"luma":return{transformType:"custom",text:"FADE",fontSize:100,fontFamily:"Arial",x:0,y:0,rotation:0,color:"#888888"};case"distress":return{transformType:"image",imageUrl:"",x:0,y:0,rotation:0,transformData:{type:"image",width:500,height:500,cropX:0,cropY:0,cropWidth:1,cropHeight:1,flipHorizontal:!1,flipVertical:!1,borderRadius:0}};default:return{transformType:"custom",text:"MASK",fontSize:80,x:0,y:0,rotation:0,color:"#000000"}}}const Bp={enabled:!0,style:"worn",intensity:30,fadeAmount:20,grainAmount:15,edgeWear:40,seed:void 0},_p={enabled:!0,style:"worn",intensity:55,fadeAmount:35,grainAmount:25,edgeWear:60,seed:void 0},Hp={enabled:!0,style:"worn",intensity:75,fadeAmount:50,grainAmount:40,edgeWear:80,seed:void 0},$p={enabled:!0,style:"cracked",intensity:25,scratchAmount:30,edgeWear:20,seed:void 0},Up={enabled:!0,style:"cracked",intensity:50,scratchAmount:50,edgeWear:35,seed:void 0},Yp={enabled:!0,style:"cracked",intensity:80,scratchAmount:75,edgeWear:60,seed:void 0},Wp={enabled:!0,style:"grunge",intensity:35,grainAmount:40,fadeAmount:25,seed:void 0},Xp={enabled:!0,style:"grunge",intensity:60,grainAmount:60,fadeAmount:40,seed:void 0},Vp={enabled:!0,style:"grunge",intensity:85,grainAmount:80,fadeAmount:55,seed:void 0},Gp={enabled:!0,style:"retro",intensity:30,fadeAmount:30,grainAmount:25,seed:void 0},Kp={enabled:!0,style:"retro",intensity:55,fadeAmount:45,grainAmount:40,seed:void 0},qp={enabled:!0,style:"retro",intensity:75,fadeAmount:60,grainAmount:55,seed:void 0},Zp={worn:{light:Bp,medium:_p,heavy:Hp},cracked:{light:$p,medium:Up,heavy:Yp},grunge:{light:Wp,medium:Xp,heavy:Vp},retro:{light:Gp,medium:Kp,heavy:qp}};function Jp(e,t){const r={...Zp[e][t]};return r.seed=Date.now(),r}const Qp=({distressEffect:e,onChange:t})=>{rt.ensureBuiltinTexturesReady();const[r,o]=l.useState(!1),s=(e==null?void 0:e.enabled)||!1,i=(e==null?void 0:e.style)||"worn",a=(e==null?void 0:e.intensity)||50,c=(e==null?void 0:e.fadeAmount)||30,d=(e==null?void 0:e.grainAmount)||30,u=(e==null?void 0:e.scratchAmount)||30,h=(e==null?void 0:e.edgeWear)||40,f=S=>{t(S?{enabled:!0,style:i,intensity:a,fadeAmount:c,grainAmount:d,scratchAmount:u,edgeWear:h,seed:Date.now()}:void 0)},p=(S,R)=>{const I=Jp(S,R);t(I),o(!1)},g=S=>{if(e)if(S==="custom"){const R=e.textureUrl||rt.DISTRESS_TEXTURE_PRESETS[0].textureUrl;rt.preloadTexture(R),t({...e,style:"custom",textureUrl:R,textureOpacity:e.textureOpacity??e.intensity/100})}else t({...e,style:S,seed:Date.now()})},b=S=>{e&&(rt.preloadTexture(S),t({...e,style:"custom",textureUrl:S}))},x=S=>{e&&t({...e,textureOpacity:S[0]/100})},y=S=>{e&&t({...e,intensity:S[0]})},v=S=>{e&&t({...e,fadeAmount:S[0]})},w=S=>{e&&t({...e,grainAmount:S[0]})},C=S=>{e&&t({...e,scratchAmount:S[0]})},j=S=>{e&&t({...e,edgeWear:S[0]})},M=()=>{e&&t({...e,seed:Date.now()})};return n.jsxs(m.Disclosure,{open:s,onOpenChange:f,className:"mb-xl",children:[n.jsx(m.DisclosureTrigger,{className:"w-full",children:n.jsxs("div",{className:"flex items-center justify-between w-full",children:[n.jsx(m.Label,{children:"Distress Effect"}),n.jsx(m.Switch,{checked:s,onCheckedChange:f,onClick:S=>S.stopPropagation()})]})}),n.jsxs(m.DisclosureContent,{className:"flex flex-col gap-lg pt-lg",children:[n.jsx("div",{className:"flex gap-sm",children:n.jsx(m.Button,{variant:"outline",onClick:()=>o(!r),className:"flex-1",children:"Presets"})}),r&&n.jsxs("div",{className:"flex flex-col gap-xl rounded-md border border-border-primary bg-bg-tertiary p-xl",children:[n.jsxs("div",{children:[n.jsx("h4",{className:"mb-sm text-base font-semibold text-accent-primary",children:"Vintage Worn"}),n.jsxs("div",{className:"flex gap-sm",children:[n.jsx(m.Button,{variant:"outline",onClick:()=>p("worn","light"),className:"flex-1",children:"Light"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("worn","medium"),className:"flex-1",children:"Medium"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("worn","heavy"),className:"flex-1",children:"Heavy"})]})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"mb-sm text-base font-semibold text-accent-primary",children:"Cracked"}),n.jsxs("div",{className:"flex gap-sm",children:[n.jsx(m.Button,{variant:"outline",onClick:()=>p("cracked","light"),className:"flex-1",children:"Light"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("cracked","medium"),className:"flex-1",children:"Medium"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("cracked","heavy"),className:"flex-1",children:"Heavy"})]})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"mb-sm text-base font-semibold text-accent-primary",children:"Grunge"}),n.jsxs("div",{className:"flex gap-sm",children:[n.jsx(m.Button,{variant:"outline",onClick:()=>p("grunge","light"),className:"flex-1",children:"Light"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("grunge","medium"),className:"flex-1",children:"Medium"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("grunge","heavy"),className:"flex-1",children:"Heavy"})]})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"mb-sm text-base font-semibold text-accent-primary",children:"Retro Halftone"}),n.jsxs("div",{className:"flex gap-sm",children:[n.jsx(m.Button,{variant:"outline",onClick:()=>p("retro","light"),className:"flex-1",children:"Light"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("retro","medium"),className:"flex-1",children:"Medium"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("retro","heavy"),className:"flex-1",children:"Heavy"})]})]})]}),n.jsxs(m.Fieldset,{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Style"}),n.jsxs(m.RadioGroup,{value:i,onValueChange:g,orientation:"horizontal",children:[n.jsx(m.Radio,{value:"worn",id:"style-worn",children:"Worn"}),n.jsx(m.Radio,{value:"cracked",id:"style-cracked",children:"Cracked"}),n.jsx(m.Radio,{value:"grunge",id:"style-grunge",children:"Grunge"}),n.jsx(m.Radio,{value:"retro",id:"style-retro",children:"Retro"}),n.jsx(m.Radio,{value:"custom",id:"style-custom",children:"Custom"})]})]}),i==="custom"&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:rt.DISTRESS_TEXTURE_PRESETS.map(S=>n.jsx("button",{onClick:()=>b(S.textureUrl),className:`aspect-square rounded-md border-2 overflow-hidden transition-colors ${(e==null?void 0:e.textureUrl)===S.textureUrl?"border-accent-primary":"border-border-primary hover:border-border-focus"}`,title:S.name,children:n.jsx("img",{src:S.thumbnailUrl,alt:S.name,className:"w-full h-full object-cover",loading:"lazy"})},S.id))}),n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Texture Opacity"}),n.jsx(m.Slider,{value:[Math.round(((e==null?void 0:e.textureOpacity)??.5)*100)],onValueChange:x,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[Math.round(((e==null?void 0:e.textureOpacity)??.5)*100),"%"]})]})]}),i!=="custom"&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Intensity"}),n.jsx(m.Slider,{value:[a],onValueChange:y,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[a,"%"]})]}),(i==="worn"||i==="grunge"||i==="retro")&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Fade"}),n.jsx(m.Slider,{value:[c],onValueChange:v,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[c,"%"]})]}),(i==="worn"||i==="grunge"||i==="retro")&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Grain"}),n.jsx(m.Slider,{value:[d],onValueChange:w,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[d,"%"]})]}),i==="cracked"&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Scratches"}),n.jsx(m.Slider,{value:[u],onValueChange:C,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[u,"%"]})]}),(i==="worn"||i==="cracked")&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Edge Wear"}),n.jsx(m.Slider,{value:[h],onValueChange:j,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[h,"%"]})]}),n.jsx(m.Button,{variant:"outline",onClick:M,className:"w-full",children:"Randomize Pattern"})]})]})};function zl(e){return e?!!(e.fill||e.stroke):!1}function em(e){if(!e)return[];const t=[];return e.fill&&t.push("fill"),e.stroke&&t.push("stroke"),t}function tm(e,t="knockout"){if(!e||!zl(e))return"No compositing";const r=em(e),o=e.scope||"group",s=t==="clip"?"clip":"knockout";return r.length===0?"No compositing":r.length===1?`${r[0]} ${s} (${o})`:`${r.slice(0,-1).join(", ")+" & "+r[r.length-1]} ${s} (${o})`}function nm(e){return!e||!zl(e)?"No knockout":tm(e,"knockout")}const rm=({blendMode:e="normal",knockoutParts:t,onChange:r})=>{const o=e==="knockout"||e==="clip",[s,i]=l.useState(o),a=o,c=(t==null?void 0:t.fill)||!1,d=(t==null?void 0:t.stroke)||!1,u=(t==null?void 0:t.scope)||"group",h=b=>{b==="knockout"||b==="clip"?(r(b,{fill:!1,stroke:!0,scope:"artboard"}),i(!0)):(r(b,void 0),i(!1))},f=()=>{t&&r(e,{...t,fill:!c})},p=()=>{t&&r(e,{...t,stroke:!d})},g=b=>{t&&r(e,{...t,scope:b})};return n.jsxs(m.Disclosure,{open:s,onOpenChange:a?i:void 0,className:"mb-xl",children:[n.jsx(m.DisclosureTrigger,{className:"w-full",children:n.jsx("div",{className:"flex items-center justify-between w-full",children:n.jsx(m.Label,{children:"Compositing"})})}),n.jsxs(m.DisclosureContent,{className:"flex flex-col gap-lg pt-lg",children:[n.jsxs(m.Fieldset,{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Blend Mode"}),n.jsxs(m.RadioGroup,{value:e,onValueChange:h,orientation:"horizontal",children:[n.jsx(m.Radio,{value:"normal",id:"blend-normal",children:"Normal"}),n.jsx(m.Radio,{value:"knockout",id:"blend-knockout",children:"Knockout"})]})]}),a&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex flex-col gap-md border-t border-border-primary pt-2xl",children:[n.jsx("label",{className:"text-base font-medium text-text-secondary",children:"Knockout Parts"}),n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsxs("label",{className:"flex cursor-pointer flex-col gap-xs rounded-lg border border-border-primary bg-bg-tertiary p-md transition-all duration-fast hover:border-border-secondary hover:bg-bg-hover",onClick:f,children:[n.jsxs("span",{className:"flex items-center gap-sm text-lg font-semibold text-text-primary",children:[n.jsx("span",{className:"text-base",children:c?"☑":"☐"}),"Fill"]}),n.jsx("small",{className:"ml-[22px] text-sm text-text-muted",children:"Element content cuts through"})]}),n.jsxs("label",{className:"flex cursor-pointer flex-col gap-xs rounded-lg border border-border-primary bg-bg-tertiary p-md transition-all duration-fast hover:border-border-secondary hover:bg-bg-hover",onClick:p,children:[n.jsxs("span",{className:"flex items-center gap-sm text-lg font-semibold text-text-primary",children:[n.jsx("span",{className:"text-base",children:d?"☑":"☐"}),"Stroke"]}),n.jsx("small",{className:"ml-[22px] text-sm text-text-muted",children:"Border/outline cuts through"})]})]})]}),n.jsxs(m.Fieldset,{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Knockout Scope"}),n.jsxs("div",{className:"flex gap-sm",children:[n.jsxs("button",{className:`flex flex-1 cursor-pointer flex-col gap-xs rounded-lg border p-lg text-center transition-all duration-fast ${u==="group"?"border-accent-primary bg-accent-primary":"border-border-primary bg-bg-tertiary hover:border-border-secondary hover:bg-bg-hover"}`,onClick:()=>g("group"),title:"Knockout within group siblings only",children:[n.jsx("strong",{className:`text-lg ${u==="group"?"text-text-on-accent":"text-text-primary"}`,children:"Group"}),n.jsx("small",{className:`text-sm ${u==="group"?"text-bg-tertiary":"text-text-muted"}`,children:"Affects siblings in group"})]}),n.jsxs("button",{className:`flex flex-1 cursor-pointer flex-col gap-xs rounded-lg border p-lg text-center transition-all duration-fast ${u==="artboard"?"border-accent-primary bg-accent-primary":"border-border-primary bg-bg-tertiary hover:border-border-secondary hover:bg-bg-hover"}`,onClick:()=>g("artboard"),title:"Knockout cuts through to artboard",children:[n.jsx("strong",{className:`text-lg ${u==="artboard"?"text-text-on-accent":"text-text-primary"}`,children:"Artboard"}),n.jsx("small",{className:`text-sm ${u==="artboard"?"text-bg-tertiary":"text-text-muted"}`,children:"Cuts to transparent background"})]})]})]}),n.jsxs("div",{className:"flex flex-col gap-md",children:[n.jsxs("div",{className:"rounded-lg border border-border-primary bg-bg-tertiary p-md",children:[n.jsx("strong",{className:"text-sm font-semibold uppercase tracking-wide text-accent-primary",children:"Effect:"}),n.jsx("p",{className:"mt-xs text-base text-text-secondary",children:nm(t)})]}),n.jsx("div",{className:"rounded-sm border-l-2 border-accent-primary bg-accent-light p-md",children:n.jsxs("small",{className:"text-sm leading-relaxed text-text-secondary",children:[n.jsx("strong",{children:"Tip:"})," Use ",n.jsx("em",{className:"font-semibold not-italic text-accent-primary",children:"Artboard"})," ","scope for t-shirt designs, ",n.jsx("em",{className:"font-semibold not-italic text-accent-primary",children:"Group"})," scope for pillow patterns."]})})]})]})]})]})},om=T.createLogger("GlyphPicker"),sm=({isOpen:e,onClose:t,character:r,charIndex:o,fontFamily:s,fontWeight:i=400,currentGlyphOverride:a,onSelectGlyph:c,browseAll:d=!1})=>{const[u,h]=l.useState([]),[f,p]=l.useState(!1),[g,b]=l.useState(null);l.useEffect(()=>{if(!e)return;p(!0),b(null),(d?T.FontAnalyzer.getAllGlyphs(s,i):T.FontAnalyzer.getGlyphAlternates(s,r,i)).then(w=>{w.length===0&&b(d?`No glyphs found in ${s}`:`No alternates found for "${r}" in ${s}`),h(w),p(!1)}).catch(w=>{om.error("Error loading glyphs:",w),b(d?"Failed to load glyphs":"Failed to load glyph alternates"),p(!1)})},[e,r,s,i,d]);const x=v=>{!d&&v.category==="default"?c(null):c({charIndex:o,glyphIndex:v.glyphIndex,unicode:d?v.unicode:r,alternateName:v.name}),t()},y=d?`Browse All Glyphs - ${s}`:`Alternates for "${r}"`;return n.jsx(m.Drawer,{open:e,onOpenChange:v=>!v&&t(),children:n.jsxs(m.DrawerContent,{placement:"bottom",overlayOpacity:.4,className:"flex flex-col overflow-hidden",style:{zIndex:"var(--z-drawer, 10002)"},children:[n.jsx(m.DrawerTitle,{className:"sr-only",children:y}),n.jsxs("div",{className:"flex items-center justify-between px-3xl pb-2xl pt-2xl border-b border-border-primary",children:[n.jsxs("div",{className:"flex items-center gap-md",children:[n.jsx(Ao,{size:24,className:"text-text-muted"}),n.jsx("h3",{className:"m-0 text-3xl font-semibold text-text-primary",children:y})]}),n.jsx(m.Button,{size:"icon",variant:"ghost",onClick:t,children:n.jsx(de,{icon:Re.close,className:"size-6"})})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto p-3xl",children:[f&&n.jsx("div",{className:"text-center py-6xl text-text-muted",children:"Loading alternates..."}),g&&n.jsxs("div",{className:"text-center px-3xl py-6xl text-text-placeholder text-xl",children:[g,n.jsx("div",{className:"mt-md text-base",children:"This font may not have alternate glyphs for this character."})]}),!f&&!g&&u.length>0&&n.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(100px,1fr))] gap-xl",children:u.map((v,w)=>{const C=(a==null?void 0:a.glyphIndex)===v.glyphIndex,j=v.category==="default";return n.jsxs("button",{onClick:()=>x(v),className:`
17
+ `},Ph={onDragStart(e){let{active:t}=e;return"Picked up draggable item "+t.id+"."},onDragOver(e){let{active:t,over:r}=e;return r?"Draggable item "+t.id+" was moved over droppable area "+r.id+".":"Draggable item "+t.id+" is no longer over a droppable area."},onDragEnd(e){let{active:t,over:r}=e;return r?"Draggable item "+t.id+" was dropped over droppable area "+r.id:"Draggable item "+t.id+" was dropped."},onDragCancel(e){let{active:t}=e;return"Dragging was cancelled. Draggable item "+t.id+" was dropped."}};function Fh(e){let{announcements:t=Ph,container:r,hiddenTextDescribedById:o,screenReaderInstructions:s=Lh}=e;const{announce:i,announcement:a}=Ih(),c=Fo("DndLiveRegion"),[d,u]=l.useState(!1);if(l.useEffect(()=>{u(!0)},[]),Ah(l.useMemo(()=>({onDragStart(f){let{active:p}=f;i(t.onDragStart({active:p}))},onDragMove(f){let{active:p,over:g}=f;t.onDragMove&&i(t.onDragMove({active:p,over:g}))},onDragOver(f){let{active:p,over:g}=f;i(t.onDragOver({active:p,over:g}))},onDragEnd(f){let{active:p,over:g}=f;i(t.onDragEnd({active:p,over:g}))},onDragCancel(f){let{active:p,over:g}=f;i(t.onDragCancel({active:p,over:g}))}}),[i,t])),!d)return null;const h=l.createElement(l.Fragment,null,l.createElement(Nh,{id:o,value:s.draggable}),l.createElement(Mh,{id:c,announcement:a}));return r?Qn.createPortal(h,r):h}var Jt;(function(e){e.DragStart="dragStart",e.DragMove="dragMove",e.DragEnd="dragEnd",e.DragCancel="dragCancel",e.DragOver="dragOver",e.RegisterDroppable="registerDroppable",e.SetDroppableDisabled="setDroppableDisabled",e.UnregisterDroppable="unregisterDroppable"})(Jt||(Jt={}));function No(){}function na(e,t){return l.useMemo(()=>({sensor:e,options:t??{}}),[e,t])}function zh(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return l.useMemo(()=>[...t].filter(o=>o!=null),[...t])}const Bn=Object.freeze({x:0,y:0});function ai(e,t){return Math.sqrt(Math.pow(e.x-t.x,2)+Math.pow(e.y-t.y,2))}function Oh(e,t){const r=Ro(e);if(!r)return"0 0";const o={x:(r.x-t.left)/t.width*100,y:(r.y-t.top)/t.height*100};return o.x+"% "+o.y+"%"}function li(e,t){let{data:{value:r}}=e,{data:{value:o}}=t;return r-o}function _h(e,t){let{data:{value:r}}=e,{data:{value:o}}=t;return o-r}function Ds(e){let{left:t,top:r,height:o,width:s}=e;return[{x:t,y:r},{x:t+s,y:r},{x:t,y:r+o},{x:t+s,y:r+o}]}function bl(e,t){if(!e||e.length===0)return null;const[r]=e;return r[t]}function ra(e,t,r){return t===void 0&&(t=e.left),r===void 0&&(r=e.top),{x:t+e.width*.5,y:r+e.height*.5}}const Bh=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:o}=e;const s=ra(t,t.left,t.top),i=[];for(const a of o){const{id:c}=a,d=r.get(c);if(d){const u=ai(ra(d),s);i.push({id:c,data:{droppableContainer:a,value:u}})}}return i.sort(li)},Hh=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:o}=e;const s=Ds(t),i=[];for(const a of o){const{id:c}=a,d=r.get(c);if(d){const u=Ds(d),h=s.reduce((p,g,b)=>p+ai(u[b],g),0),f=Number((h/4).toFixed(4));i.push({id:c,data:{droppableContainer:a,value:f}})}}return i.sort(li)};function $h(e,t){const r=Math.max(t.top,e.top),o=Math.max(t.left,e.left),s=Math.min(t.left+t.width,e.left+e.width),i=Math.min(t.top+t.height,e.top+e.height),a=s-o,c=i-r;if(o<s&&r<i){const d=t.width*t.height,u=e.width*e.height,h=a*c,f=h/(d+u-h);return Number(f.toFixed(4))}return 0}const Uh=e=>{let{collisionRect:t,droppableRects:r,droppableContainers:o}=e;const s=[];for(const i of o){const{id:a}=i,c=r.get(a);if(c){const d=$h(c,t);d>0&&s.push({id:a,data:{droppableContainer:i,value:d}})}}return s.sort(_h)};function Yh(e,t){const{top:r,left:o,bottom:s,right:i}=t;return r<=e.y&&e.y<=s&&o<=e.x&&e.x<=i}const Wh=e=>{let{droppableContainers:t,droppableRects:r,pointerCoordinates:o}=e;if(!o)return[];const s=[];for(const i of t){const{id:a}=i,c=r.get(a);if(c&&Yh(o,c)){const u=Ds(c).reduce((f,p)=>f+ai(o,p),0),h=Number((u/4).toFixed(4));s.push({id:a,data:{droppableContainer:i,value:h}})}}return s.sort(li)};function Xh(e,t,r){return{...e,scaleX:t&&r?t.width/r.width:1,scaleY:t&&r?t.height/r.height:1}}function yl(e,t){return e&&t?{x:e.left-t.left,y:e.top-t.top}:Bn}function Vh(e){return function(r){for(var o=arguments.length,s=new Array(o>1?o-1:0),i=1;i<o;i++)s[i-1]=arguments[i];return s.reduce((a,c)=>({...a,top:a.top+e*c.y,bottom:a.bottom+e*c.y,left:a.left+e*c.x,right:a.right+e*c.x}),{...r})}}const Gh=Vh(1);function vl(e){if(e.startsWith("matrix3d(")){const t=e.slice(9,-1).split(/, /);return{x:+t[12],y:+t[13],scaleX:+t[0],scaleY:+t[5]}}else if(e.startsWith("matrix(")){const t=e.slice(7,-1).split(/, /);return{x:+t[4],y:+t[5],scaleX:+t[0],scaleY:+t[3]}}return null}function Kh(e,t,r){const o=vl(t);if(!o)return e;const{scaleX:s,scaleY:i,x:a,y:c}=o,d=e.left-a-(1-s)*parseFloat(r),u=e.top-c-(1-i)*parseFloat(r.slice(r.indexOf(" ")+1)),h=s?e.width/s:e.width,f=i?e.height/i:e.height;return{width:h,height:f,top:u,right:d+h,bottom:u+f,left:d}}const qh={ignoreTransform:!1};function no(e,t){t===void 0&&(t=qh);let r=e.getBoundingClientRect();if(t.ignoreTransform){const{transform:u,transformOrigin:h}=gn(e).getComputedStyle(e);u&&(r=Kh(r,u,h))}const{top:o,left:s,width:i,height:a,bottom:c,right:d}=r;return{top:o,left:s,width:i,height:a,bottom:c,right:d}}function oa(e){return no(e,{ignoreTransform:!0})}function Zh(e){const t=e.innerWidth,r=e.innerHeight;return{top:0,left:0,right:t,bottom:r,width:t,height:r}}function Jh(e,t){return t===void 0&&(t=gn(e).getComputedStyle(e)),t.position==="fixed"}function Qh(e,t){t===void 0&&(t=gn(e).getComputedStyle(e));const r=/(auto|scroll|overlay)/;return["overflow","overflowX","overflowY"].some(s=>{const i=t[s];return typeof i=="string"?r.test(i):!1})}function zo(e,t){const r=[];function o(s){if(t!=null&&r.length>=t||!s)return r;if(si(s)&&s.scrollingElement!=null&&!r.includes(s.scrollingElement))return r.push(s.scrollingElement),r;if(!eo(s)||ml(s)||r.includes(s))return r;const i=gn(e).getComputedStyle(s);return s!==e&&Qh(s,i)&&r.push(s),Jh(s,i)?r:o(s.parentNode)}return e?o(e):r}function wl(e){const[t]=zo(e,1);return t??null}function ls(e){return!Lo||!e?null:wr(e)?e:oi(e)?si(e)||e===Cr(e).scrollingElement?window:eo(e)?e:null:null}function Cl(e){return wr(e)?e.scrollX:e.scrollLeft}function Sl(e){return wr(e)?e.scrollY:e.scrollTop}function Ls(e){return{x:Cl(e),y:Sl(e)}}var nn;(function(e){e[e.Forward=1]="Forward",e[e.Backward=-1]="Backward"})(nn||(nn={}));function kl(e){return!Lo||!e?!1:e===document.scrollingElement}function jl(e){const t={x:0,y:0},r=kl(e)?{height:window.innerHeight,width:window.innerWidth}:{height:e.clientHeight,width:e.clientWidth},o={x:e.scrollWidth-r.width,y:e.scrollHeight-r.height},s=e.scrollTop<=t.y,i=e.scrollLeft<=t.x,a=e.scrollTop>=o.y,c=e.scrollLeft>=o.x;return{isTop:s,isLeft:i,isBottom:a,isRight:c,maxScroll:o,minScroll:t}}const ef={x:.2,y:.2};function tf(e,t,r,o,s){let{top:i,left:a,right:c,bottom:d}=r;o===void 0&&(o=10),s===void 0&&(s=ef);const{isTop:u,isBottom:h,isLeft:f,isRight:p}=jl(e),g={x:0,y:0},b={x:0,y:0},x={height:t.height*s.y,width:t.width*s.x};return!u&&i<=t.top+x.height?(g.y=nn.Backward,b.y=o*Math.abs((t.top+x.height-i)/x.height)):!h&&d>=t.bottom-x.height&&(g.y=nn.Forward,b.y=o*Math.abs((t.bottom-x.height-d)/x.height)),!p&&c>=t.right-x.width?(g.x=nn.Forward,b.x=o*Math.abs((t.right-x.width-c)/x.width)):!f&&a<=t.left+x.width&&(g.x=nn.Backward,b.x=o*Math.abs((t.left+x.width-a)/x.width)),{direction:g,speed:b}}function nf(e){if(e===document.scrollingElement){const{innerWidth:i,innerHeight:a}=window;return{top:0,left:0,right:i,bottom:a,width:i,height:a}}const{top:t,left:r,right:o,bottom:s}=e.getBoundingClientRect();return{top:t,left:r,right:o,bottom:s,width:e.clientWidth,height:e.clientHeight}}function El(e){return e.reduce((t,r)=>yr(t,Ls(r)),Bn)}function rf(e){return e.reduce((t,r)=>t+Cl(r),0)}function of(e){return e.reduce((t,r)=>t+Sl(r),0)}function Tl(e,t){if(t===void 0&&(t=no),!e)return;const{top:r,left:o,bottom:s,right:i}=t(e);wl(e)&&(s<=0||i<=0||r>=window.innerHeight||o>=window.innerWidth)&&e.scrollIntoView({block:"center",inline:"center"})}const sf=[["x",["left","right"],rf],["y",["top","bottom"],of]];class ci{constructor(t,r){this.rect=void 0,this.width=void 0,this.height=void 0,this.top=void 0,this.bottom=void 0,this.right=void 0,this.left=void 0;const o=zo(r),s=El(o);this.rect={...t},this.width=t.width,this.height=t.height;for(const[i,a,c]of sf)for(const d of a)Object.defineProperty(this,d,{get:()=>{const u=c(o),h=s[i]-u;return this.rect[d]+h},enumerable:!0});Object.defineProperty(this,"rect",{enumerable:!1})}}class zr{constructor(t){this.target=void 0,this.listeners=[],this.removeAll=()=>{this.listeners.forEach(r=>{var o;return(o=this.target)==null?void 0:o.removeEventListener(...r)})},this.target=t}add(t,r,o){var s;(s=this.target)==null||s.addEventListener(t,r,o),this.listeners.push([t,r,o])}}function af(e){const{EventTarget:t}=gn(e);return e instanceof t?e:Cr(e)}function cs(e,t){const r=Math.abs(e.x),o=Math.abs(e.y);return typeof t=="number"?Math.sqrt(r**2+o**2)>t:"x"in t&&"y"in t?r>t.x&&o>t.y:"x"in t?r>t.x:"y"in t?o>t.y:!1}var Ln;(function(e){e.Click="click",e.DragStart="dragstart",e.Keydown="keydown",e.ContextMenu="contextmenu",e.Resize="resize",e.SelectionChange="selectionchange",e.VisibilityChange="visibilitychange"})(Ln||(Ln={}));function sa(e){e.preventDefault()}function lf(e){e.stopPropagation()}var wt;(function(e){e.Space="Space",e.Down="ArrowDown",e.Right="ArrowRight",e.Left="ArrowLeft",e.Up="ArrowUp",e.Esc="Escape",e.Enter="Enter",e.Tab="Tab"})(wt||(wt={}));const Rl={start:[wt.Space,wt.Enter],cancel:[wt.Esc],end:[wt.Space,wt.Enter,wt.Tab]},cf=(e,t)=>{let{currentCoordinates:r}=t;switch(e.code){case wt.Right:return{...r,x:r.x+25};case wt.Left:return{...r,x:r.x-25};case wt.Down:return{...r,y:r.y+25};case wt.Up:return{...r,y:r.y-25}}};class di{constructor(t){this.props=void 0,this.autoScrollEnabled=!1,this.referenceCoordinates=void 0,this.listeners=void 0,this.windowListeners=void 0,this.props=t;const{event:{target:r}}=t;this.props=t,this.listeners=new zr(Cr(r)),this.windowListeners=new zr(gn(r)),this.handleKeyDown=this.handleKeyDown.bind(this),this.handleCancel=this.handleCancel.bind(this),this.attach()}attach(){this.handleStart(),this.windowListeners.add(Ln.Resize,this.handleCancel),this.windowListeners.add(Ln.VisibilityChange,this.handleCancel),setTimeout(()=>this.listeners.add(Ln.Keydown,this.handleKeyDown))}handleStart(){const{activeNode:t,onStart:r}=this.props,o=t.node.current;o&&Tl(o),r(Bn)}handleKeyDown(t){if(ii(t)){const{active:r,context:o,options:s}=this.props,{keyboardCodes:i=Rl,coordinateGetter:a=cf,scrollBehavior:c="smooth"}=s,{code:d}=t;if(i.end.includes(d)){this.handleEnd(t);return}if(i.cancel.includes(d)){this.handleCancel(t);return}const{collisionRect:u}=o.current,h=u?{x:u.left,y:u.top}:Bn;this.referenceCoordinates||(this.referenceCoordinates=h);const f=a(t,{active:r,context:o.current,currentCoordinates:h});if(f){const p=Xr(f,h),g={x:0,y:0},{scrollableAncestors:b}=o.current;for(const x of b){const y=t.code,{isTop:v,isRight:w,isLeft:C,isBottom:j,maxScroll:M,minScroll:S}=jl(x),R=nf(x),I={x:Math.min(y===wt.Right?R.right-R.width/2:R.right,Math.max(y===wt.Right?R.left:R.left+R.width/2,f.x)),y:Math.min(y===wt.Down?R.bottom-R.height/2:R.bottom,Math.max(y===wt.Down?R.top:R.top+R.height/2,f.y))},D=y===wt.Right&&!w||y===wt.Left&&!C,E=y===wt.Down&&!j||y===wt.Up&&!v;if(D&&I.x!==f.x){const O=x.scrollLeft+p.x,z=y===wt.Right&&O<=M.x||y===wt.Left&&O>=S.x;if(z&&!p.y){x.scrollTo({left:O,behavior:c});return}z?g.x=x.scrollLeft-O:g.x=y===wt.Right?x.scrollLeft-M.x:x.scrollLeft-S.x,g.x&&x.scrollBy({left:-g.x,behavior:c});break}else if(E&&I.y!==f.y){const O=x.scrollTop+p.y,z=y===wt.Down&&O<=M.y||y===wt.Up&&O>=S.y;if(z&&!p.x){x.scrollTo({top:O,behavior:c});return}z?g.y=x.scrollTop-O:g.y=y===wt.Down?x.scrollTop-M.y:x.scrollTop-S.y,g.y&&x.scrollBy({top:-g.y,behavior:c});break}}this.handleMove(t,yr(Xr(f,this.referenceCoordinates),g))}}}handleMove(t,r){const{onMove:o}=this.props;t.preventDefault(),o(r)}handleEnd(t){const{onEnd:r}=this.props;t.preventDefault(),this.detach(),r()}handleCancel(t){const{onCancel:r}=this.props;t.preventDefault(),this.detach(),r()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll()}}di.activators=[{eventName:"onKeyDown",handler:(e,t,r)=>{let{keyboardCodes:o=Rl,onActivation:s}=t,{active:i}=r;const{code:a}=e.nativeEvent;if(o.start.includes(a)){const c=i.activatorNode.current;return c&&e.target!==c?!1:(e.preventDefault(),s==null||s({event:e.nativeEvent}),!0)}return!1}}];function ia(e){return!!(e&&"distance"in e)}function aa(e){return!!(e&&"delay"in e)}class ui{constructor(t,r,o){var s;o===void 0&&(o=af(t.event.target)),this.props=void 0,this.events=void 0,this.autoScrollEnabled=!0,this.document=void 0,this.activated=!1,this.initialCoordinates=void 0,this.timeoutId=null,this.listeners=void 0,this.documentListeners=void 0,this.windowListeners=void 0,this.props=t,this.events=r;const{event:i}=t,{target:a}=i;this.props=t,this.events=r,this.document=Cr(a),this.documentListeners=new zr(this.document),this.listeners=new zr(o),this.windowListeners=new zr(gn(a)),this.initialCoordinates=(s=Ro(i))!=null?s:Bn,this.handleStart=this.handleStart.bind(this),this.handleMove=this.handleMove.bind(this),this.handleEnd=this.handleEnd.bind(this),this.handleCancel=this.handleCancel.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.removeTextSelection=this.removeTextSelection.bind(this),this.attach()}attach(){const{events:t,props:{options:{activationConstraint:r,bypassActivationConstraint:o}}}=this;if(this.listeners.add(t.move.name,this.handleMove,{passive:!1}),this.listeners.add(t.end.name,this.handleEnd),t.cancel&&this.listeners.add(t.cancel.name,this.handleCancel),this.windowListeners.add(Ln.Resize,this.handleCancel),this.windowListeners.add(Ln.DragStart,sa),this.windowListeners.add(Ln.VisibilityChange,this.handleCancel),this.windowListeners.add(Ln.ContextMenu,sa),this.documentListeners.add(Ln.Keydown,this.handleKeydown),r){if(o!=null&&o({event:this.props.event,activeNode:this.props.activeNode,options:this.props.options}))return this.handleStart();if(aa(r)){this.timeoutId=setTimeout(this.handleStart,r.delay),this.handlePending(r);return}if(ia(r)){this.handlePending(r);return}}this.handleStart()}detach(){this.listeners.removeAll(),this.windowListeners.removeAll(),setTimeout(this.documentListeners.removeAll,50),this.timeoutId!==null&&(clearTimeout(this.timeoutId),this.timeoutId=null)}handlePending(t,r){const{active:o,onPending:s}=this.props;s(o,t,this.initialCoordinates,r)}handleStart(){const{initialCoordinates:t}=this,{onStart:r}=this.props;t&&(this.activated=!0,this.documentListeners.add(Ln.Click,lf,{capture:!0}),this.removeTextSelection(),this.documentListeners.add(Ln.SelectionChange,this.removeTextSelection),r(t))}handleMove(t){var r;const{activated:o,initialCoordinates:s,props:i}=this,{onMove:a,options:{activationConstraint:c}}=i;if(!s)return;const d=(r=Ro(t))!=null?r:Bn,u=Xr(s,d);if(!o&&c){if(ia(c)){if(c.tolerance!=null&&cs(u,c.tolerance))return this.handleCancel();if(cs(u,c.distance))return this.handleStart()}if(aa(c)&&cs(u,c.tolerance))return this.handleCancel();this.handlePending(c,u);return}t.cancelable&&t.preventDefault(),a(d)}handleEnd(){const{onAbort:t,onEnd:r}=this.props;this.detach(),this.activated||t(this.props.active),r()}handleCancel(){const{onAbort:t,onCancel:r}=this.props;this.detach(),this.activated||t(this.props.active),r()}handleKeydown(t){t.code===wt.Esc&&this.handleCancel()}removeTextSelection(){var t;(t=this.document.getSelection())==null||t.removeAllRanges()}}const df={cancel:{name:"pointercancel"},move:{name:"pointermove"},end:{name:"pointerup"}};class hi extends ui{constructor(t){const{event:r}=t,o=Cr(r.target);super(t,df,o)}}hi.activators=[{eventName:"onPointerDown",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:o}=t;return!r.isPrimary||r.button!==0?!1:(o==null||o({event:r}),!0)}}];const uf={move:{name:"mousemove"},end:{name:"mouseup"}};var Ps;(function(e){e[e.RightClick=2]="RightClick"})(Ps||(Ps={}));class hf extends ui{constructor(t){super(t,uf,Cr(t.event.target))}}hf.activators=[{eventName:"onMouseDown",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:o}=t;return r.button===Ps.RightClick?!1:(o==null||o({event:r}),!0)}}];const ds={cancel:{name:"touchcancel"},move:{name:"touchmove"},end:{name:"touchend"}};class ff extends ui{constructor(t){super(t,ds)}static setup(){return window.addEventListener(ds.move.name,t,{capture:!1,passive:!1}),function(){window.removeEventListener(ds.move.name,t)};function t(){}}}ff.activators=[{eventName:"onTouchStart",handler:(e,t)=>{let{nativeEvent:r}=e,{onActivation:o}=t;const{touches:s}=r;return s.length>1?!1:(o==null||o({event:r}),!0)}}];var Or;(function(e){e[e.Pointer=0]="Pointer",e[e.DraggableRect=1]="DraggableRect"})(Or||(Or={}));var Mo;(function(e){e[e.TreeOrder=0]="TreeOrder",e[e.ReversedTreeOrder=1]="ReversedTreeOrder"})(Mo||(Mo={}));function pf(e){let{acceleration:t,activator:r=Or.Pointer,canScroll:o,draggingRect:s,enabled:i,interval:a=5,order:c=Mo.TreeOrder,pointerCoordinates:d,scrollableAncestors:u,scrollableAncestorRects:h,delta:f,threshold:p}=e;const g=gf({delta:f,disabled:!i}),[b,x]=kh(),y=l.useRef({x:0,y:0}),v=l.useRef({x:0,y:0}),w=l.useMemo(()=>{switch(r){case Or.Pointer:return d?{top:d.y,bottom:d.y,left:d.x,right:d.x}:null;case Or.DraggableRect:return s}},[r,s,d]),C=l.useRef(null),j=l.useCallback(()=>{const S=C.current;if(!S)return;const R=y.current.x*v.current.x,I=y.current.y*v.current.y;S.scrollBy(R,I)},[]),M=l.useMemo(()=>c===Mo.TreeOrder?[...u].reverse():u,[c,u]);l.useEffect(()=>{if(!i||!u.length||!w){x();return}for(const S of M){if((o==null?void 0:o(S))===!1)continue;const R=u.indexOf(S),I=h[R];if(!I)continue;const{direction:D,speed:E}=tf(S,I,w,t,p);for(const O of["x","y"])g[O][D[O]]||(E[O]=0,D[O]=0);if(E.x>0||E.y>0){x(),C.current=S,b(j,a),y.current=E,v.current=D;return}}y.current={x:0,y:0},v.current={x:0,y:0},x()},[t,j,o,x,i,a,JSON.stringify(w),JSON.stringify(g),b,u,M,h,JSON.stringify(p)])}const mf={x:{[nn.Backward]:!1,[nn.Forward]:!1},y:{[nn.Backward]:!1,[nn.Forward]:!1}};function gf(e){let{delta:t,disabled:r}=e;const o=To(t);return to(s=>{if(r||!o||!s)return mf;const i={x:Math.sign(t.x-o.x),y:Math.sign(t.y-o.y)};return{x:{[nn.Backward]:s.x[nn.Backward]||i.x===-1,[nn.Forward]:s.x[nn.Forward]||i.x===1},y:{[nn.Backward]:s.y[nn.Backward]||i.y===-1,[nn.Forward]:s.y[nn.Forward]||i.y===1}}},[r,t,o])}function xf(e,t){const r=t!=null?e.get(t):void 0,o=r?r.node.current:null;return to(s=>{var i;return t==null?null:(i=o??s)!=null?i:null},[o,t])}function bf(e,t){return l.useMemo(()=>e.reduce((r,o)=>{const{sensor:s}=o,i=s.activators.map(a=>({eventName:a.eventName,handler:t(a.handler,o)}));return[...r,...i]},[]),[e,t])}var Gr;(function(e){e[e.Always=0]="Always",e[e.BeforeDragging=1]="BeforeDragging",e[e.WhileDragging=2]="WhileDragging"})(Gr||(Gr={}));var Fs;(function(e){e.Optimized="optimized"})(Fs||(Fs={}));const la=new Map;function yf(e,t){let{dragging:r,dependencies:o,config:s}=t;const[i,a]=l.useState(null),{frequency:c,measure:d,strategy:u}=s,h=l.useRef(e),f=y(),p=Wr(f),g=l.useCallback(function(v){v===void 0&&(v=[]),!p.current&&a(w=>w===null?v:w.concat(v.filter(C=>!w.includes(C))))},[p]),b=l.useRef(null),x=to(v=>{if(f&&!r)return la;if(!v||v===la||h.current!==e||i!=null){const w=new Map;for(let C of e){if(!C)continue;if(i&&i.length>0&&!i.includes(C.id)&&C.rect.current){w.set(C.id,C.rect.current);continue}const j=C.node.current,M=j?new ci(d(j),j):null;C.rect.current=M,M&&w.set(C.id,M)}return w}return v},[e,i,r,f,d]);return l.useEffect(()=>{h.current=e},[e]),l.useEffect(()=>{f||g()},[r,f]),l.useEffect(()=>{i&&i.length>0&&a(null)},[JSON.stringify(i)]),l.useEffect(()=>{f||typeof c!="number"||b.current!==null||(b.current=setTimeout(()=>{g(),b.current=null},c))},[c,f,g,...o]),{droppableRects:x,measureDroppableContainers:g,measuringScheduled:i!=null};function y(){switch(u){case Gr.Always:return!1;case Gr.BeforeDragging:return r;default:return!r}}}function fi(e,t){return to(r=>e?r||(typeof t=="function"?t(e):e):null,[t,e])}function vf(e,t){return fi(e,t)}function wf(e){let{callback:t,disabled:r}=e;const o=Po(t),s=l.useMemo(()=>{if(r||typeof window>"u"||typeof window.MutationObserver>"u")return;const{MutationObserver:i}=window;return new i(o)},[o,r]);return l.useEffect(()=>()=>s==null?void 0:s.disconnect(),[s]),s}function Oo(e){let{callback:t,disabled:r}=e;const o=Po(t),s=l.useMemo(()=>{if(r||typeof window>"u"||typeof window.ResizeObserver>"u")return;const{ResizeObserver:i}=window;return new i(o)},[r]);return l.useEffect(()=>()=>s==null?void 0:s.disconnect(),[s]),s}function Cf(e){return new ci(no(e),e)}function ca(e,t,r){t===void 0&&(t=Cf);const[o,s]=l.useState(null);function i(){s(d=>{if(!e)return null;if(e.isConnected===!1){var u;return(u=d??r)!=null?u:null}const h=t(e);return JSON.stringify(d)===JSON.stringify(h)?d:h})}const a=wf({callback(d){if(e)for(const u of d){const{type:h,target:f}=u;if(h==="childList"&&f instanceof HTMLElement&&f.contains(e)){i();break}}}}),c=Oo({callback:i});return Vn(()=>{i(),e?(c==null||c.observe(e),a==null||a.observe(document.body,{childList:!0,subtree:!0})):(c==null||c.disconnect(),a==null||a.disconnect())},[e]),o}function Sf(e){const t=fi(e);return yl(e,t)}const da=[];function kf(e){const t=l.useRef(e),r=to(o=>e?o&&o!==da&&e&&t.current&&e.parentNode===t.current.parentNode?o:zo(e):da,[e]);return l.useEffect(()=>{t.current=e},[e]),r}function jf(e){const[t,r]=l.useState(null),o=l.useRef(e),s=l.useCallback(i=>{const a=ls(i.target);a&&r(c=>c?(c.set(a,Ls(a)),new Map(c)):null)},[]);return l.useEffect(()=>{const i=o.current;if(e!==i){a(i);const c=e.map(d=>{const u=ls(d);return u?(u.addEventListener("scroll",s,{passive:!0}),[u,Ls(u)]):null}).filter(d=>d!=null);r(c.length?new Map(c):null),o.current=e}return()=>{a(e),a(i)};function a(c){c.forEach(d=>{const u=ls(d);u==null||u.removeEventListener("scroll",s)})}},[s,e]),l.useMemo(()=>e.length?t?Array.from(t.values()).reduce((i,a)=>yr(i,a),Bn):El(e):Bn,[e,t])}function ua(e,t){t===void 0&&(t=[]);const r=l.useRef(null);return l.useEffect(()=>{r.current=null},t),l.useEffect(()=>{const o=e!==Bn;o&&!r.current&&(r.current=e),!o&&r.current&&(r.current=null)},[e]),r.current?Xr(e,r.current):Bn}function Ef(e){l.useEffect(()=>{if(!Lo)return;const t=e.map(r=>{let{sensor:o}=r;return o.setup==null?void 0:o.setup()});return()=>{for(const r of t)r==null||r()}},e.map(t=>{let{sensor:r}=t;return r}))}function Tf(e,t){return l.useMemo(()=>e.reduce((r,o)=>{let{eventName:s,handler:i}=o;return r[s]=a=>{i(a,t)},r},{}),[e,t])}function Nl(e){return l.useMemo(()=>e?Zh(e):null,[e])}const ha=[];function Rf(e,t){t===void 0&&(t=no);const[r]=e,o=Nl(r?gn(r):null),[s,i]=l.useState(ha);function a(){i(()=>e.length?e.map(d=>kl(d)?o:new ci(t(d),d)):ha)}const c=Oo({callback:a});return Vn(()=>{c==null||c.disconnect(),a(),e.forEach(d=>c==null?void 0:c.observe(d))},[e]),s}function Ml(e){if(!e)return null;if(e.children.length>1)return e;const t=e.children[0];return eo(t)?t:e}function Nf(e){let{measure:t}=e;const[r,o]=l.useState(null),s=l.useCallback(u=>{for(const{target:h}of u)if(eo(h)){o(f=>{const p=t(h);return f?{...f,width:p.width,height:p.height}:p});break}},[t]),i=Oo({callback:s}),a=l.useCallback(u=>{const h=Ml(u);i==null||i.disconnect(),h&&(i==null||i.observe(h)),o(h?t(h):null)},[t,i]),[c,d]=Eo(a);return l.useMemo(()=>({nodeRef:c,rect:r,setRef:d}),[r,c,d])}const Mf=[{sensor:hi,options:{}},{sensor:di,options:{}}],If={current:{}},vo={draggable:{measure:oa},droppable:{measure:oa,strategy:Gr.WhileDragging,frequency:Fs.Optimized},dragOverlay:{measure:no}};class _r extends Map{get(t){var r;return t!=null&&(r=super.get(t))!=null?r:void 0}toArray(){return Array.from(this.values())}getEnabled(){return this.toArray().filter(t=>{let{disabled:r}=t;return!r})}getNodeFor(t){var r,o;return(r=(o=this.get(t))==null?void 0:o.node.current)!=null?r:void 0}}const Af={activatorEvent:null,active:null,activeNode:null,activeNodeRect:null,collisions:null,containerNodeRect:null,draggableNodes:new Map,droppableRects:new Map,droppableContainers:new _r,over:null,dragOverlay:{nodeRef:{current:null},rect:null,setRef:No},scrollableAncestors:[],scrollableAncestorRects:[],measuringConfiguration:vo,measureDroppableContainers:No,windowRect:null,measuringScheduled:!1},Il={activatorEvent:null,activators:[],active:null,activeNodeRect:null,ariaDescribedById:{draggable:""},dispatch:No,draggableNodes:new Map,over:null,measureDroppableContainers:No},ro=l.createContext(Il),Al=l.createContext(Af);function Df(){return{draggable:{active:null,initialCoordinates:{x:0,y:0},nodes:new Map,translate:{x:0,y:0}},droppable:{containers:new _r}}}function Lf(e,t){switch(t.type){case Jt.DragStart:return{...e,draggable:{...e.draggable,initialCoordinates:t.initialCoordinates,active:t.active}};case Jt.DragMove:return e.draggable.active==null?e:{...e,draggable:{...e.draggable,translate:{x:t.coordinates.x-e.draggable.initialCoordinates.x,y:t.coordinates.y-e.draggable.initialCoordinates.y}}};case Jt.DragEnd:case Jt.DragCancel:return{...e,draggable:{...e.draggable,active:null,initialCoordinates:{x:0,y:0},translate:{x:0,y:0}}};case Jt.RegisterDroppable:{const{element:r}=t,{id:o}=r,s=new _r(e.droppable.containers);return s.set(o,r),{...e,droppable:{...e.droppable,containers:s}}}case Jt.SetDroppableDisabled:{const{id:r,key:o,disabled:s}=t,i=e.droppable.containers.get(r);if(!i||o!==i.key)return e;const a=new _r(e.droppable.containers);return a.set(r,{...i,disabled:s}),{...e,droppable:{...e.droppable,containers:a}}}case Jt.UnregisterDroppable:{const{id:r,key:o}=t,s=e.droppable.containers.get(r);if(!s||o!==s.key)return e;const i=new _r(e.droppable.containers);return i.delete(r),{...e,droppable:{...e.droppable,containers:i}}}default:return e}}function Pf(e){let{disabled:t}=e;const{active:r,activatorEvent:o,draggableNodes:s}=l.useContext(ro),i=To(o),a=To(r==null?void 0:r.id);return l.useEffect(()=>{if(!t&&!o&&i&&a!=null){if(!ii(i)||document.activeElement===i.target)return;const c=s.get(a);if(!c)return;const{activatorNode:d,node:u}=c;if(!d.current&&!u.current)return;requestAnimationFrame(()=>{for(const h of[d.current,u.current]){if(!h)continue;const f=Th(h);if(f){f.focus();break}}})}},[o,t,s,a,i]),null}function Dl(e,t){let{transform:r,...o}=t;return e!=null&&e.length?e.reduce((s,i)=>i({transform:s,...o}),r):r}function Ff(e){return l.useMemo(()=>({draggable:{...vo.draggable,...e==null?void 0:e.draggable},droppable:{...vo.droppable,...e==null?void 0:e.droppable},dragOverlay:{...vo.dragOverlay,...e==null?void 0:e.dragOverlay}}),[e==null?void 0:e.draggable,e==null?void 0:e.droppable,e==null?void 0:e.dragOverlay])}function zf(e){let{activeNode:t,measure:r,initialRect:o,config:s=!0}=e;const i=l.useRef(!1),{x:a,y:c}=typeof s=="boolean"?{x:s,y:s}:s;Vn(()=>{if(!a&&!c||!t){i.current=!1;return}if(i.current||!o)return;const u=t==null?void 0:t.node.current;if(!u||u.isConnected===!1)return;const h=r(u),f=yl(h,o);if(a||(f.x=0),c||(f.y=0),i.current=!0,Math.abs(f.x)>0||Math.abs(f.y)>0){const p=wl(u);p&&p.scrollBy({top:f.y,left:f.x})}},[t,a,c,o,r])}const _o=l.createContext({...Bn,scaleX:1,scaleY:1});var Jn;(function(e){e[e.Uninitialized=0]="Uninitialized",e[e.Initializing=1]="Initializing",e[e.Initialized=2]="Initialized"})(Jn||(Jn={}));const Of=l.memo(function(t){var r,o,s,i;let{id:a,accessibility:c,autoScroll:d=!0,children:u,sensors:h=Mf,collisionDetection:f=Uh,measuring:p,modifiers:g,...b}=t;const x=l.useReducer(Lf,void 0,Df),[y,v]=x,[w,C]=Dh(),[j,M]=l.useState(Jn.Uninitialized),S=j===Jn.Initialized,{draggable:{active:R,nodes:I,translate:D},droppable:{containers:E}}=y,O=R!=null?I.get(R):null,z=l.useRef({initial:null,translated:null}),B=l.useMemo(()=>{var je;return R!=null?{id:R,data:(je=O==null?void 0:O.data)!=null?je:If,rect:z}:null},[R,O]),k=l.useRef(null),[Y,_]=l.useState(null),[G,se]=l.useState(null),A=Wr(b,Object.values(b)),Z=Fo("DndDescribedBy",a),J=l.useMemo(()=>E.getEnabled(),[E]),q=Ff(p),{droppableRects:ae,measureDroppableContainers:Le,measuringScheduled:pe}=yf(J,{dragging:S,dependencies:[D.x,D.y],config:q.droppable}),U=xf(I,R),W=l.useMemo(()=>G?Ro(G):null,[G]),Ie=De(),ke=vf(U,q.draggable.measure);zf({activeNode:R!=null?I.get(R):null,config:Ie.layoutShiftCompensation,initialRect:ke,measure:q.draggable.measure});const Ke=ca(U,q.draggable.measure,ke),re=ca(U?U.parentElement:null),te=l.useRef({activatorEvent:null,active:null,activeNode:U,collisionRect:null,collisions:null,droppableRects:ae,draggableNodes:I,draggingNode:null,draggingNodeRect:null,droppableContainers:E,over:null,scrollableAncestors:[],scrollAdjustedTranslate:null}),he=E.getNodeFor((r=te.current.over)==null?void 0:r.id),ye=Nf({measure:q.dragOverlay.measure}),we=(o=ye.nodeRef.current)!=null?o:U,Pe=S?(s=ye.rect)!=null?s:Ke:null,me=!!(ye.nodeRef.current&&ye.rect),N=Sf(me?null:Ke),ce=Nl(we?gn(we):null),le=kf(S?he??U:null),Me=Rf(le),ge=Dl(g,{transform:{x:D.x-N.x,y:D.y-N.y,scaleX:1,scaleY:1},activatorEvent:G,active:B,activeNodeRect:Ke,containerNodeRect:re,draggingNodeRect:Pe,over:te.current.over,overlayNodeRect:ye.rect,scrollableAncestors:le,scrollableAncestorRects:Me,windowRect:ce}),L=W?yr(W,D):null,ve=jf(le),tt=ua(ve),Ve=ua(ve,[Ke]),oe=yr(ge,tt),ie=Pe?Gh(Pe,ge):null,pt=B&&ie?f({active:B,collisionRect:ie,droppableRects:ae,droppableContainers:J,pointerCoordinates:L}):null,st=bl(pt,"id"),[ht,bt]=l.useState(null),yt=me?ge:yr(ge,Ve),Tt=Xh(yt,(i=ht==null?void 0:ht.rect)!=null?i:null,Ke),Rt=l.useRef(null),jt=l.useCallback((je,Ee)=>{let{sensor:$e,options:Qe}=Ee;if(k.current==null)return;const Fe=I.get(k.current);if(!Fe)return;const Ue=je.nativeEvent,Xe=new $e({active:k.current,activeNode:Fe,event:Ue,options:Qe,context:te,onAbort(Ye){if(!I.get(Ye))return;const{onDragAbort:gt}=A.current,Nt={id:Ye};gt==null||gt(Nt),w({type:"onDragAbort",event:Nt})},onPending(Ye,vt,gt,Nt){if(!I.get(Ye))return;const{onDragPending:$}=A.current,ee={id:Ye,constraint:vt,initialCoordinates:gt,offset:Nt};$==null||$(ee),w({type:"onDragPending",event:ee})},onStart(Ye){const vt=k.current;if(vt==null)return;const gt=I.get(vt);if(!gt)return;const{onDragStart:Nt}=A.current,Ft={activatorEvent:Ue,active:{id:vt,data:gt.data,rect:z}};Qn.unstable_batchedUpdates(()=>{Nt==null||Nt(Ft),M(Jn.Initializing),v({type:Jt.DragStart,initialCoordinates:Ye,active:vt}),w({type:"onDragStart",event:Ft}),_(Rt.current),se(Ue)})},onMove(Ye){v({type:Jt.DragMove,coordinates:Ye})},onEnd:dt(Jt.DragEnd),onCancel:dt(Jt.DragCancel)});Rt.current=Xe;function dt(Ye){return async function(){const{active:gt,collisions:Nt,over:Ft,scrollAdjustedTranslate:$}=te.current;let ee=null;if(gt&&$){const{cancelDrop:Je}=A.current;ee={activatorEvent:Ue,active:gt,collisions:Nt,delta:$,over:Ft},Ye===Jt.DragEnd&&typeof Je=="function"&&await Promise.resolve(Je(ee))&&(Ye=Jt.DragCancel)}k.current=null,Qn.unstable_batchedUpdates(()=>{v({type:Ye}),M(Jn.Uninitialized),bt(null),_(null),se(null),Rt.current=null;const Je=Ye===Jt.DragEnd?"onDragEnd":"onDragCancel";if(ee){const it=A.current[Je];it==null||it(ee),w({type:Je,event:ee})}})}}},[I]),kt=l.useCallback((je,Ee)=>($e,Qe)=>{const Fe=$e.nativeEvent,Ue=I.get(Qe);if(k.current!==null||!Ue||Fe.dndKit||Fe.defaultPrevented)return;const Xe={active:Ue};je($e,Ee.options,Xe)===!0&&(Fe.dndKit={capturedBy:Ee.sensor},k.current=Qe,jt($e,Ee))},[I,jt]),Kt=bf(h,kt);Ef(h),Vn(()=>{Ke&&j===Jn.Initializing&&M(Jn.Initialized)},[Ke,j]),l.useEffect(()=>{const{onDragMove:je}=A.current,{active:Ee,activatorEvent:$e,collisions:Qe,over:Fe}=te.current;if(!Ee||!$e)return;const Ue={active:Ee,activatorEvent:$e,collisions:Qe,delta:{x:oe.x,y:oe.y},over:Fe};Qn.unstable_batchedUpdates(()=>{je==null||je(Ue),w({type:"onDragMove",event:Ue})})},[oe.x,oe.y]),l.useEffect(()=>{const{active:je,activatorEvent:Ee,collisions:$e,droppableContainers:Qe,scrollAdjustedTranslate:Fe}=te.current;if(!je||k.current==null||!Ee||!Fe)return;const{onDragOver:Ue}=A.current,Xe=Qe.get(st),dt=Xe&&Xe.rect.current?{id:Xe.id,rect:Xe.rect.current,data:Xe.data,disabled:Xe.disabled}:null,Ye={active:je,activatorEvent:Ee,collisions:$e,delta:{x:Fe.x,y:Fe.y},over:dt};Qn.unstable_batchedUpdates(()=>{bt(dt),Ue==null||Ue(Ye),w({type:"onDragOver",event:Ye})})},[st]),Vn(()=>{te.current={activatorEvent:G,active:B,activeNode:U,collisionRect:ie,collisions:pt,droppableRects:ae,draggableNodes:I,draggingNode:we,draggingNodeRect:Pe,droppableContainers:E,over:ht,scrollableAncestors:le,scrollAdjustedTranslate:oe},z.current={initial:Pe,translated:ie}},[B,U,pt,ie,I,we,Pe,ae,E,ht,le,oe]),pf({...Ie,delta:D,draggingRect:ie,pointerCoordinates:L,scrollableAncestors:le,scrollableAncestorRects:Me});const $t=l.useMemo(()=>({active:B,activeNode:U,activeNodeRect:Ke,activatorEvent:G,collisions:pt,containerNodeRect:re,dragOverlay:ye,draggableNodes:I,droppableContainers:E,droppableRects:ae,over:ht,measureDroppableContainers:Le,scrollableAncestors:le,scrollableAncestorRects:Me,measuringConfiguration:q,measuringScheduled:pe,windowRect:ce}),[B,U,Ke,G,pt,re,ye,I,E,ae,ht,Le,le,Me,q,pe,ce]),Ot=l.useMemo(()=>({activatorEvent:G,activators:Kt,active:B,activeNodeRect:Ke,ariaDescribedById:{draggable:Z},dispatch:v,draggableNodes:I,over:ht,measureDroppableContainers:Le}),[G,Kt,B,Ke,v,Z,I,ht,Le]);return l.createElement(xl.Provider,{value:C},l.createElement(ro.Provider,{value:Ot},l.createElement(Al.Provider,{value:$t},l.createElement(_o.Provider,{value:Tt},u)),l.createElement(Pf,{disabled:(c==null?void 0:c.restoreFocus)===!1})),l.createElement(Fh,{...c,hiddenTextDescribedById:Z}));function De(){const je=(Y==null?void 0:Y.autoScrollEnabled)===!1,Ee=typeof d=="object"?d.enabled===!1:d===!1,$e=S&&!je&&!Ee;return typeof d=="object"?{...d,enabled:$e}:{enabled:$e}}}),_f=l.createContext(null),fa="button",Bf="Draggable";function Hf(e){let{id:t,data:r,disabled:o=!1,attributes:s}=e;const i=Fo(Bf),{activators:a,activatorEvent:c,active:d,activeNodeRect:u,ariaDescribedById:h,draggableNodes:f,over:p}=l.useContext(ro),{role:g=fa,roleDescription:b="draggable",tabIndex:x=0}=s??{},y=(d==null?void 0:d.id)===t,v=l.useContext(y?_o:_f),[w,C]=Eo(),[j,M]=Eo(),S=Tf(a,t),R=Wr(r);Vn(()=>(f.set(t,{id:t,key:i,node:w,activatorNode:j,data:R}),()=>{const D=f.get(t);D&&D.key===i&&f.delete(t)}),[f,t]);const I=l.useMemo(()=>({role:g,tabIndex:x,"aria-disabled":o,"aria-pressed":y&&g===fa?!0:void 0,"aria-roledescription":b,"aria-describedby":h.draggable}),[o,g,x,y,b,h.draggable]);return{active:d,activatorEvent:c,activeNodeRect:u,attributes:I,isDragging:y,listeners:o?void 0:S,node:w,over:p,setNodeRef:C,setActivatorNodeRef:M,transform:v}}function $f(){return l.useContext(Al)}const Uf="Droppable",Yf={timeout:25};function Ll(e){let{data:t,disabled:r=!1,id:o,resizeObserverConfig:s}=e;const i=Fo(Uf),{active:a,dispatch:c,over:d,measureDroppableContainers:u}=l.useContext(ro),h=l.useRef({disabled:r}),f=l.useRef(!1),p=l.useRef(null),g=l.useRef(null),{disabled:b,updateMeasurementsFor:x,timeout:y}={...Yf,...s},v=Wr(x??o),w=l.useCallback(()=>{if(!f.current){f.current=!0;return}g.current!=null&&clearTimeout(g.current),g.current=setTimeout(()=>{u(Array.isArray(v.current)?v.current:[v.current]),g.current=null},y)},[y]),C=Oo({callback:w,disabled:b||!a}),j=l.useCallback((I,D)=>{C&&(D&&(C.unobserve(D),f.current=!1),I&&C.observe(I))},[C]),[M,S]=Eo(j),R=Wr(t);return l.useEffect(()=>{!C||!M.current||(C.disconnect(),f.current=!1,C.observe(M.current))},[M,C]),l.useEffect(()=>(c({type:Jt.RegisterDroppable,element:{id:o,key:i,disabled:r,node:M,rect:p,data:R}}),()=>c({type:Jt.UnregisterDroppable,key:i,id:o})),[o]),l.useEffect(()=>{r!==h.current.disabled&&(c({type:Jt.SetDroppableDisabled,id:o,key:i,disabled:r}),h.current.disabled=r)},[o,i,r,c]),{active:a,rect:p,isOver:(d==null?void 0:d.id)===o,node:M,over:d,setNodeRef:S}}function Wf(e){let{animation:t,children:r}=e;const[o,s]=l.useState(null),[i,a]=l.useState(null),c=To(r);return!r&&!o&&c&&s(c),Vn(()=>{if(!i)return;const d=o==null?void 0:o.key,u=o==null?void 0:o.props.id;if(d==null||u==null){s(null);return}Promise.resolve(t(u,i)).then(()=>{s(null)})},[t,o,i]),l.createElement(l.Fragment,null,r,o?l.cloneElement(o,{ref:a}):null)}const Xf={x:0,y:0,scaleX:1,scaleY:1};function Vf(e){let{children:t}=e;return l.createElement(ro.Provider,{value:Il},l.createElement(_o.Provider,{value:Xf},t))}const Gf={position:"fixed",touchAction:"none"},Kf=e=>ii(e)?"transform 250ms ease":void 0,qf=l.forwardRef((e,t)=>{let{as:r,activatorEvent:o,adjustScale:s,children:i,className:a,rect:c,style:d,transform:u,transition:h=Kf}=e;if(!c)return null;const f=s?u:{...u,scaleX:1,scaleY:1},p={...Gf,width:c.width,height:c.height,top:c.top,left:c.left,transform:Vr.Transform.toString(f),transformOrigin:s&&o?Oh(o,c):void 0,transition:typeof h=="function"?h(o):h,...d};return l.createElement(r,{className:a,style:p,ref:t},i)}),Zf=e=>t=>{let{active:r,dragOverlay:o}=t;const s={},{styles:i,className:a}=e;if(i!=null&&i.active)for(const[c,d]of Object.entries(i.active))d!==void 0&&(s[c]=r.node.style.getPropertyValue(c),r.node.style.setProperty(c,d));if(i!=null&&i.dragOverlay)for(const[c,d]of Object.entries(i.dragOverlay))d!==void 0&&o.node.style.setProperty(c,d);return a!=null&&a.active&&r.node.classList.add(a.active),a!=null&&a.dragOverlay&&o.node.classList.add(a.dragOverlay),function(){for(const[d,u]of Object.entries(s))r.node.style.setProperty(d,u);a!=null&&a.active&&r.node.classList.remove(a.active)}},Jf=e=>{let{transform:{initial:t,final:r}}=e;return[{transform:Vr.Transform.toString(t)},{transform:Vr.Transform.toString(r)}]},Qf={duration:250,easing:"ease",keyframes:Jf,sideEffects:Zf({styles:{active:{opacity:"0"}}})};function ep(e){let{config:t,draggableNodes:r,droppableContainers:o,measuringConfiguration:s}=e;return Po((i,a)=>{if(t===null)return;const c=r.get(i);if(!c)return;const d=c.node.current;if(!d)return;const u=Ml(a);if(!u)return;const{transform:h}=gn(a).getComputedStyle(a),f=vl(h);if(!f)return;const p=typeof t=="function"?t:tp(t);return Tl(d,s.draggable.measure),p({active:{id:i,data:c.data,node:d,rect:s.draggable.measure(d)},draggableNodes:r,dragOverlay:{node:a,rect:s.dragOverlay.measure(u)},droppableContainers:o,measuringConfiguration:s,transform:f})})}function tp(e){const{duration:t,easing:r,sideEffects:o,keyframes:s}={...Qf,...e};return i=>{let{active:a,dragOverlay:c,transform:d,...u}=i;if(!t)return;const h={x:c.rect.left-a.rect.left,y:c.rect.top-a.rect.top},f={scaleX:d.scaleX!==1?a.rect.width*d.scaleX/c.rect.width:1,scaleY:d.scaleY!==1?a.rect.height*d.scaleY/c.rect.height:1},p={x:d.x-h.x,y:d.y-h.y,...f},g=s({...u,active:a,dragOverlay:c,transform:{initial:d,final:p}}),[b]=g,x=g[g.length-1];if(JSON.stringify(b)===JSON.stringify(x))return;const y=o==null?void 0:o({active:a,dragOverlay:c,...u}),v=c.node.animate(g,{duration:t,easing:r,fill:"forwards"});return new Promise(w=>{v.onfinish=()=>{y==null||y(),w()}})}}let pa=0;function np(e){return l.useMemo(()=>{if(e!=null)return pa++,pa},[e])}const rp=l.memo(e=>{let{adjustScale:t=!1,children:r,dropAnimation:o,style:s,transition:i,modifiers:a,wrapperElement:c="div",className:d,zIndex:u=999}=e;const{activatorEvent:h,active:f,activeNodeRect:p,containerNodeRect:g,draggableNodes:b,droppableContainers:x,dragOverlay:y,over:v,measuringConfiguration:w,scrollableAncestors:C,scrollableAncestorRects:j,windowRect:M}=$f(),S=l.useContext(_o),R=np(f==null?void 0:f.id),I=Dl(a,{activatorEvent:h,active:f,activeNodeRect:p,containerNodeRect:g,draggingNodeRect:y.rect,over:v,overlayNodeRect:y.rect,scrollableAncestors:C,scrollableAncestorRects:j,transform:S,windowRect:M}),D=fi(p),E=ep({config:o,draggableNodes:b,droppableContainers:x,measuringConfiguration:w}),O=D?y.setRef:void 0;return l.createElement(Vf,null,l.createElement(Wf,{animation:E},f&&R?l.createElement(qf,{key:R,id:f.id,ref:O,as:c,activatorEvent:h,adjustScale:t,className:d,transition:i,rect:D,style:{zIndex:u,...s},transform:I},r):null))});function Io(e){if(!e)return!1;const t=e.data.current;return!!(t&&"sortable"in t&&typeof t.sortable=="object"&&"containerId"in t.sortable&&"items"in t.sortable&&"index"in t.sortable)}const op=[wt.Down,wt.Right,wt.Up,wt.Left],sp=(e,t)=>{let{context:{active:r,collisionRect:o,droppableRects:s,droppableContainers:i,over:a,scrollableAncestors:c}}=t;if(op.includes(e.code)){if(e.preventDefault(),!r||!o)return;const d=[];i.getEnabled().forEach(f=>{if(!f||f!=null&&f.disabled)return;const p=s.get(f.id);if(p)switch(e.code){case wt.Down:o.top<p.top&&d.push(f);break;case wt.Up:o.top>p.top&&d.push(f);break;case wt.Left:o.left>p.left&&d.push(f);break;case wt.Right:o.left<p.left&&d.push(f);break}});const u=Hh({collisionRect:o,droppableRects:s,droppableContainers:d});let h=bl(u,"id");if(h===(a==null?void 0:a.id)&&u.length>1&&(h=u[1].id),h!=null){const f=i.get(r.id),p=i.get(h),g=p?s.get(p.id):null,b=p==null?void 0:p.node.current;if(b&&g&&f&&p){const y=zo(b).some((S,R)=>c[R]!==S),v=Pl(f,p),w=ip(f,p),C=y||!v?{x:0,y:0}:{x:w?o.width-g.width:0,y:w?o.height-g.height:0},j={x:g.left,y:g.top};return C.x&&C.y?j:Xr(j,C)}}}};function Pl(e,t){return!Io(e)||!Io(t)?!1:e.data.current.sortable.containerId===t.data.current.sortable.containerId}function ip(e,t){return!Io(e)||!Io(t)||!Pl(e,t)?!1:e.data.current.sortable.index<t.data.current.sortable.index}function ma(e){var r;if(!e||e.length===0)return null;const t=(r=e[0].data)==null?void 0:r.zone;return t==="before"||t==="after"||t==="into"?t:null}function ap(e){const{onReorder:t,onGroupReorder:r,onDropIntoGroup:o,onDropIntoGroupAtPosition:s,onRemoveFromGroup:i,findParentGroup:a}=e,[c,d]=l.useState(null),[u,h]=l.useState(null),[f,p]=l.useState(null),g=l.useRef(null),b=zh(na(hi,{activationConstraint:{distance:5}}),na(di,{coordinateGetter:sp})),x=l.useCallback(M=>{d(String(M.active.id))},[]),y=l.useCallback(M=>{const{over:S,collisions:R}=M;h(S?String(S.id):null);const I=ma(R);g.current=I,p(I)},[]),v=l.useCallback(M=>{const{collisions:S}=M,R=ma(S);g.current=R,p(R)},[]),w=l.useCallback(()=>{g.current=null,d(null),h(null),p(null)},[]),C=l.useCallback(M=>{const{active:S,over:R}=M,I=g.current;if(!R||S.id===R.id||!I){w();return}const D=String(S.id),E=String(R.id);if(E.startsWith("group-footer::")){const O=E.replace("group-footer::",""),z=a==null?void 0:a(D);z&&z.id===O?i==null||i(D):t(D,O,"before"),w();return}if(I==="into")o==null||o(D,E);else{const O=I==="before"?"after":"before",z=a==null?void 0:a(D),B=a==null?void 0:a(E);z&&B&&z.id===B.id?r==null||r(D,E,O,z.id):!z&&B&&s?s(D,B.id,E,O):t(D,E,O)}w()},[t,r,o,s,i,a,w]),j=l.useCallback(()=>{w()},[w]);return{activeId:c,overId:u,dropPosition:f,sensors:b,onDragStart:x,onDragMove:v,onDragOver:y,onDragEnd:C,onDragCancel:j}}function _n(...e){return Zc.twMerge(qc.clsx(e))}const lp={"gravity-ui":1.2,lucide:1,hugeicons:1.05,mdi:.95,"fa6-solid":.7,heroicons:1,ph:1,"radix-icons":1,"material-symbols":.9,"simple-icons":.95,"eos-icons":1},cp=1,dp={"gravity-ui:arrow-rotate-left":{x:4,y:4},"gravity-ui:arrow-rotate-right":{x:-4,y:4},"gravity-ui:sparkles":{x:2,y:-2}},up={xs:12,sm:16,md:20,lg:24,xl:32,toolbar:{mobile:24,desktop:20}};function hp(e){const t=e.indexOf(":");return t===-1?"":e.substring(0,t)}function fp(e){return lp[e]??cp}function pp(e){return dp[e]??null}function us(e,t){const r=fp(t);return Math.round(e*r)}const Fl=({icon:e,size:t="md",className:r})=>{const o=hp(e),s=up[t],i=pp(e);if(typeof s=="object"){const d=us(s.mobile,o),u=us(s.desktop,o),h=i?{x:i.x*d/20,y:i.y*d/20}:null;return n.jsx("span",{className:_n("normalized-icon-responsive inline-flex",r),style:{"--icon-size-mobile":`${d}px`,"--icon-size-desktop":`${u}px`,width:`${d}px`,height:`${d}px`},children:n.jsx(de,{icon:e,width:"100%",height:"100%",style:h?{transform:`translate(${h.x}px, ${h.y}px)`}:void 0})})}const a=us(s,o),c=i?{x:i.x*a/20,y:i.y*a/20}:null;return n.jsx("span",{className:_n("inline-flex",r),style:{width:`${a}px`,height:`${a}px`},children:n.jsx(de,{icon:e,width:"100%",height:"100%",style:c?{transform:`translate(${c.x}px, ${c.y}px)`}:void 0})})};Fl.displayName="NormalizedIcon";const ct=l.forwardRef(({icon:e,onClick:t,active:r=!1,tooltip:o,tooltipDelay:s=300,tooltipDisabled:i=!1,"aria-label":a,disabled:c=!1,className:d,onMouseLeave:u},h)=>{const f=n.jsx(m.Button,{ref:h,variant:"ghost",size:"toolbar",onClick:t,disabled:c,"aria-label":a||o,"aria-pressed":r,"data-active":r,onMouseLeave:u,className:_n(d),children:typeof e=="string"?n.jsx(Fl,{icon:e,size:"toolbar"}):e});return!o||i?f:n.jsxs(m.Tooltip,{delay:s,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:f}),n.jsx(m.TooltipContent,{children:o})]})});ct.displayName="ToolbarButton";const Bo=({className:e,size:t=24})=>n.jsxs("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",width:t,height:t,className:_n("inline-block iconify",e),children:[n.jsx("path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"}),n.jsx("path",{d:"M3 3v5h5"})]}),Ao=({className:e,size:t=24})=>n.jsx("svg",{viewBox:"0 0 28 28",fill:"currentColor",width:t,height:t,className:_n("inline-block",e),children:n.jsx("path",{d:"M10.06 18.701a1.628 1.628 0 0 0 2.43-.676l.77-2.34a3.82 3.82 0 0 1 2.416-2.418l2.238-.727a1.6 1.6 0 0 0 .786-.595a1.62 1.62 0 0 0-.849-2.489l-2.215-.72a3.82 3.82 0 0 1-2.42-2.414l-.727-2.237a1.62 1.62 0 0 0-.594-.785a1.655 1.655 0 0 0-1.879 0a1.63 1.63 0 0 0-.6.8L8.68 6.365a3.82 3.82 0 0 1-2.359 2.37l-2.24.726a1.626 1.626 0 0 0 .02 3.073l2.216.72a3.86 3.86 0 0 1 1.816 1.286c.266.343.471.728.606 1.14l.728 2.234c.112.318.32.593.595.787m-3.273-6.873l-2.22-.72s-.085-.038-.085-.108a.14.14 0 0 1 .084-.115L6.8 10.16a5.34 5.34 0 0 0 3.32-3.375l.721-2.219s.043-.084.114-.084s.113.084.113.084l.723 2.223a5.32 5.32 0 0 0 3.377 3.372l2.27.735a.13.13 0 0 1 .078.11a.15.15 0 0 1-.083.113l-2.225.722a5.32 5.32 0 0 0-3.374 3.374l-.715 2.2a.11.11 0 0 1-.115.093c-.104 0-.118-.075-.118-.075l-.723-2.22a5.32 5.32 0 0 0-3.376-3.385m13.017 12.954A1.2 1.2 0 0 0 20.5 25a1.2 1.2 0 0 0 .692-.216a1.2 1.2 0 0 0 .446-.6l.372-1.143a1.61 1.61 0 0 1 1.017-1.02l1.166-.378A1.21 1.21 0 0 0 25 20.505a1.2 1.2 0 0 0-.844-1.146l-1.144-.37a1.61 1.61 0 0 1-1.02-1.018l-.38-1.163a1.2 1.2 0 0 0-2.274.016l-.374 1.146a1.61 1.61 0 0 1-.993 1.017l-1.166.378a1.21 1.21 0 0 0-.807 1.139a1.2 1.2 0 0 0 .823 1.138l1.144.372a1.6 1.6 0 0 1 1.02 1.023l.379 1.163a1.2 1.2 0 0 0 .44.582m-1.371-4.194l-.27-.088l.283-.096a3.12 3.12 0 0 0 1.943-1.974l.088-.27l.089.272a3.11 3.11 0 0 0 1.974 1.975l.293.1l-.271.087a3.12 3.12 0 0 0-1.974 1.977l-.088.27l-.088-.272a3.12 3.12 0 0 0-1.98-1.98"})}),Re={plus:"lucide:plus",minus:"lucide:minus",close:"lucide:x",check:"lucide:check",menu:"lucide:menu",moreHorizontal:"lucide:ellipsis",text:"lucide:type",image:"lucide:image",layers:"lucide:layers",shapes:"lucide:shapes",trash:"lucide:trash-2",copy:"lucide:copy",pencil:"lucide:pencil",scissors:"lucide:scissors",save:"lucide:save",folderOpen:"lucide:folder-open",download:"lucide:download",eye:"lucide:eye",eyeOff:"lucide:eye-off",lock:"lucide:lock",lockOpen:"lucide:lock-open",search:"lucide:search",link:"lucide:link",palette:"lucide:palette",rotateLeft:"lucide:rotate-ccw",rotateCcwSquare:"lucide:rotate-ccw-square",bold:"lucide:bold",italic:"lucide:italic",underline:"lucide:underline",alignLeft:"lucide:align-left",alignCenter:"lucide:align-center",alignRight:"lucide:align-right",play:"lucide:play",pause:"lucide:pause",grip:"lucide:grip-vertical",fileText:"lucide:file-text",group:"lucide:group",undo:"lucide:undo-2",redo:"lucide:redo-2",fitScreen:"lucide:scan",maximize:"lucide:maximize",alertCircle:"lucide:alert-circle",wand:"lucide:wand-2"},zs=({icon:e,label:t,onClose:r,className:o,closeButtonStyle:s="icon"})=>{const i=l.useRef(null),a=l.useRef({x:0,y:0});return l.useEffect(()=>{const c=i.current;if(!c)return;const d=h=>{a.current={x:h.touches[0].clientX,y:h.touches[0].clientY}},u=h=>{const f=Math.abs(h.touches[0].clientX-a.current.x),p=Math.abs(h.touches[0].clientY-a.current.y);f>10&&f>p&&h.preventDefault()};return c.addEventListener("touchstart",d,{passive:!0}),c.addEventListener("touchmove",u,{passive:!1}),()=>{c.removeEventListener("touchstart",d),c.removeEventListener("touchmove",u)}},[]),n.jsxs("div",{ref:i,className:_n("flex w-full items-center justify-between",o),style:{touchAction:"pan-y"},children:[n.jsxs("div",{className:"flex items-center gap-3 md:gap-2",children:[typeof e=="string"?n.jsx(de,{icon:e,className:"text-primary size-7 md:size-5"}):e,n.jsx("span",{className:"text-foreground text-lg font-semibold md:text-sm md:font-medium",children:t})]}),s==="done"?n.jsx("button",{onClick:r,className:"bg-primary text-primary-foreground rounded-xl hover:bg-primary/90 shadow-sm px-8 py-3.5 text-xl font-bold transition-colors md:rounded-button md:shadow-none md:px-4 md:py-2 md:text-sm md:font-medium","aria-label":"Done",children:"Done"}):n.jsx("button",{onClick:r,className:"hover:bg-muted text-foreground/70 hover:text-foreground flex size-11 items-center justify-center rounded-md transition-colors md:size-7","aria-label":"Close panel",children:n.jsx(de,{icon:Re.close,className:"size-7 md:size-4"})})]})};zs.displayName="CollapsedToolbarHeader";function ga({children:e,className:t}){const r=l.useRef(null);return l.useEffect(()=>{const o=r.current;if(!o)return;const s=a=>{a.stopPropagation()},i=a=>{a.preventDefault(),a.stopPropagation()};return o.addEventListener("touchstart",s,{passive:!1}),o.addEventListener("touchmove",i,{passive:!1}),()=>{o.removeEventListener("touchstart",s),o.removeEventListener("touchmove",i)}},[]),n.jsx("div",{ref:r,className:t,style:{touchAction:"none"},children:e})}const sn=({label:e,value:t,onChange:r,min:o,max:s,step:i=1,unit:a="",showInput:c=!1,inputWidth:d="56px",className:u,variant:h="inline"})=>{const f=Math.round(t);return h==="stacked"?n.jsxs("div",{className:_n("flex flex-col gap-2.5 md:gap-1.5",u),children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-foreground/60 text-base md:text-xs",children:e}),c&&n.jsx("input",{type:"number",value:f,onChange:p=>r(Math.max(o,Math.min(s,Number(p.target.value)))),min:o,max:s,"aria-label":`${e} value`,className:"bg-transparent text-foreground w-14 rounded-md border-none px-2.5 py-2 text-right text-base md:w-14 md:rounded md:px-1.5 md:py-1 md:text-[13px]",style:{width:d}})]}),n.jsx(ga,{children:n.jsxs(m.Slider,{value:[t],onValueChange:p=>r(p[0]),min:o,max:s,step:i,children:[n.jsx(m.Slider.Track,{className:"bg-foreground/10 h-2.5 md:h-2",children:n.jsx(m.Slider.Fill,{className:"bg-primary"})}),n.jsx(m.Slider.Thumb,{className:"size-7 md:size-6"})]})})]}):n.jsxs("div",{className:_n("flex items-center gap-3",u),children:[n.jsx("span",{className:"text-foreground/70 text-base md:text-[13px] whitespace-nowrap",children:e}),c?n.jsx("input",{type:"number",value:f,onChange:p=>r(Math.max(o,Math.min(s,Number(p.target.value)))),min:o,max:s,"aria-label":`${e} value`,className:"bg-transparent text-foreground rounded-md border-none px-2 py-2 text-right text-base md:py-1.5 md:text-[13px]",style:{width:d}}):null,n.jsx(ga,{className:"flex-1",children:n.jsxs(m.Slider,{value:[t],onValueChange:p=>r(p[0]),min:o,max:s,step:i,children:[n.jsx(m.Slider.Track,{className:"bg-foreground/10 h-2.5 md:h-2",children:n.jsx(m.Slider.Fill,{className:"bg-primary"})}),n.jsx(m.Slider.Thumb,{className:"size-7 md:size-6"})]})}),n.jsxs("span",{className:"text-foreground text-base md:text-[13px] min-w-[44px] md:min-w-[32px] text-right",children:[f,a]})]})},xa="border-2 border-primary overflow-hidden",ba="border-2 border-border-primary hover:border-border-focus overflow-hidden",Ho=({presets:e,selectedId:t,onSelect:r,showOff:o=!0,size:s=40,ariaLabel:i="Preset options"})=>{const a=l.useRef(null),c=l.useCallback(f=>{f.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})},[]),d=l.useCallback(f=>{if(f.key!=="ArrowLeft"&&f.key!=="ArrowRight")return;f.preventDefault(),f.stopPropagation();const p=a.current;if(!p)return;const g=Array.from(p.querySelectorAll("button[data-preset-id]")),b=document.activeElement;let x=g.indexOf(b);x===-1&&(x=g.findIndex(C=>C.getAttribute("aria-selected")==="true"),x===-1&&(x=0));let y;f.key==="ArrowRight"?y=x<g.length-1?x+1:0:y=x>0?x-1:g.length-1;const v=g[y];v.focus(),c(v);const w=v.getAttribute("data-preset-id");w!==null&&r(w)},[c,r]),u=o&&!t,h=o?!0:e.some(f=>f.id===t);return n.jsxs("div",{ref:a,className:"flex gap-1.5 overflow-x-auto p-1 -m-1",style:{flexWrap:"nowrap"},role:"listbox","aria-label":i,onKeyDown:d,children:[o&&n.jsx("button",{"data-preset-id":"",role:"option","aria-selected":u,tabIndex:u||!h?0:-1,onClick:()=>r(""),className:`shrink-0 rounded-md transition-all flex items-center justify-center ${u?xa:ba}`,style:{width:s,height:s},title:"None",children:n.jsx("span",{className:"text-xs text-muted-foreground",children:"Off"})}),e.map((f,p)=>{const g=t===f.id,b=g||!o&&!h&&p===0;return n.jsx("button",{"data-preset-id":f.id,role:"option","aria-selected":g,tabIndex:b?0:-1,onClick:()=>r(f.id),className:`shrink-0 rounded-md transition-all ${g?xa:ba}`,style:{width:s,height:s},title:f.name,children:f.thumbnailUrl&&n.jsx("img",{src:f.thumbnailUrl,alt:f.name,className:"w-full h-full object-cover",loading:"lazy"})},f.id)})]})},mp=e=>{var p,g;const{pointerCoordinates:t,droppableContainers:r,droppableRects:o}=e;let s=Wh(e);if(s.length===0&&(s=Bh(e)),s.length===0||!t)return s;const i=s[0];if(String(i.id).startsWith("group-footer::"))return[{...i,data:{...i.data,zone:"after"}}];const a=o.get(i.id);if(!a)return s;const c=t.y-a.top,d=a.height,u=r.find(b=>b.id===i.id),h=((g=(p=u==null?void 0:u.data)==null?void 0:p.current)==null?void 0:g.isGroup)===!0;let f;return h?c<d*.25?f="before":c>d*.75?f="after":f="into":f=c<d/2?"before":"after",[{...i,data:{...i.data,zone:f}}]},gp=({layer:e,isOver:t,dropPosition:r,isDragActive:o,showPreviewImages:s,previewDisplaySize:i,onSelect:a,onToggleVisibility:c,onToggleLock:d,onDuplicate:u,onDelete:h})=>{const{attributes:f,listeners:p,setNodeRef:g,isDragging:b}=Hf({id:e.id}),{setNodeRef:x}=Ll({id:e.id,data:{isGroup:!!e.isGroup}}),y=l.useCallback(I=>{g(I),x(I)},[g,x]),v=e.isGroup,w=e.depth>0,C=w?e.depth*24:0,j={opacity:b?.3:1,paddingLeft:C+8,paddingRight:8,paddingTop:v?6:8,paddingBottom:v?6:8,minHeight:v?32:36,display:"flex",alignItems:"center",gap:8,cursor:"pointer",position:"relative",touchAction:"manipulation"};(w||v)&&(j.backgroundColor="var(--surface-secondary, rgba(0,0,0,0.04))"),t&&!b&&(r==="before"?j.borderTop="2px solid var(--primary, var(--accent-primary, #007AFF))":r==="after"?j.borderBottom="2px solid var(--primary, var(--accent-primary, #007AFF))":r==="into"&&(j.outline="2px solid var(--primary, var(--accent-primary, #007AFF))",j.outlineOffset="-2px",j.backgroundColor="var(--accent-primary-alpha, rgba(0, 122, 255, 0.08))"));const M=e.isSelected?{outline:"3px solid var(--primary, var(--accent-primary, #007AFF))",outlineOffset:"2px"}:{},S=()=>a(e.id),R=n.jsx("span",{...p,"aria-label":"Drag to reorder",title:"Drag to reorder",style:{touchAction:"none",cursor:"grab",display:"flex",alignItems:"center",justifyContent:"center",width:36,alignSelf:"stretch",marginLeft:-4,marginRight:4,flexShrink:0,color:"var(--text-secondary, #888)",opacity:.6},children:n.jsx(de,{icon:"lucide:grip-vertical",style:{fontSize:24}})});return v?n.jsxs("div",{ref:y,style:j,...f,children:[R,n.jsx(de,{icon:"lucide:folder-open",style:{fontSize:18,color:"var(--text-secondary, #888)",flexShrink:0}}),n.jsx("span",{onClick:S,style:{fontSize:13,fontWeight:600,color:"var(--foreground, #333)",flex:1,minWidth:0,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.name}),!o&&(!e.children||e.children.length===0)&&n.jsx("div",{style:{display:"flex",gap:4,flexShrink:0},children:n.jsx(Wn,{title:"Delete Group",onClick:()=>h(e.id),style:{color:"var(--error, #ef4444)"},children:n.jsx(de,{icon:Re.trash,className:"size-6"})})})]}):n.jsxs("div",{ref:y,style:j,...f,children:[R,s&&e.previewUrl?n.jsx("img",{src:e.previewUrl,alt:e.name,onClick:S,style:{width:i,height:i,objectFit:"contain",borderRadius:4,border:"1px solid var(--border-primary, #e5e5e5)",cursor:"pointer",flexShrink:0,...M}}):n.jsx("div",{style:{width:i,height:i,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,opacity:.6,border:"1px solid var(--border-primary, #e5e5e5)",borderRadius:4,cursor:"pointer",flexShrink:0,...M},onClick:S,children:n.jsx(de,{icon:Re.fileText})}),n.jsx("div",{style:{flex:1,minWidth:0},onClick:S}),!o&&n.jsxs("div",{style:{display:"flex",gap:4,flexShrink:0},children:[n.jsx(Wn,{title:e.visible?"Hide":"Show",onClick:()=>c(e.id),style:{opacity:e.visible?1:.4},children:n.jsx(de,{icon:e.visible?Re.eye:Re.eyeOff,className:"size-6"})}),n.jsx(Wn,{title:e.locked?"Unlock":"Lock",onClick:()=>d(e.id),style:{opacity:e.locked?1:.4},children:n.jsx(de,{icon:e.locked?Re.lock:Re.lockOpen,className:"size-6"})}),n.jsx(Wn,{title:"Duplicate",onClick:()=>u(e.id),children:n.jsx(de,{icon:Re.copy,className:"size-6"})}),n.jsx(Wn,{title:"Delete",onClick:()=>h(e.id),style:{color:"var(--error, #ef4444)"},children:n.jsx(de,{icon:Re.trash,className:"size-6"})})]})]})},Wn=({title:e,onClick:t,style:r,children:o})=>n.jsx("button",{onClick:s=>{s.stopPropagation(),t()},style:{background:"none",border:"none",cursor:"pointer",padding:4,opacity:.6,...r},title:e,children:o}),xp=({groupId:e,isOver:t,depth:r})=>{const{setNodeRef:o}=Ll({id:`group-footer::${e}`}),s=(r+1)*24;return n.jsx("div",{ref:o,style:{height:8,marginLeft:s,position:"relative",...t?{borderBottom:"2px solid var(--primary, var(--accent-primary, #007AFF))"}:{}}})},bp=({layer:e,showPreviewImages:t,previewDisplaySize:r})=>n.jsxs("div",{style:{paddingLeft:8,paddingRight:8,paddingTop:8,paddingBottom:8,display:"flex",alignItems:"center",gap:8,backgroundColor:"var(--surface, #fff)",borderRadius:8,boxShadow:"0 4px 16px rgba(0,0,0,0.15)",opacity:.9},children:[e.isGroup?n.jsx(de,{icon:"lucide:folder-open",style:{fontSize:18,color:"var(--text-secondary, #888)"}}):t&&e.previewUrl?n.jsx("img",{src:e.previewUrl,alt:e.name,style:{width:r,height:r,objectFit:"contain",borderRadius:4,border:"1px solid var(--border-primary, #e5e5e5)"}}):n.jsx("div",{style:{width:r,height:r,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,opacity:.6,border:"1px solid var(--border-primary, #e5e5e5)",borderRadius:4},children:n.jsx(de,{icon:Re.fileText})}),n.jsx("span",{style:{fontSize:13,color:"var(--foreground, #333)"},children:e.name})]}),zl=({width:e=250,height:t,showPreviewImages:r=!0,enableDragReorder:o=!1,enableGrouping:s=!1,style:i={},className:a="",showHeader:c=!0,...d})=>{const{activeArtboard:u}=Qr(),h=(u==null?void 0:u.previewBackgroundColor)||(u==null?void 0:u.backgroundColor)||"transparent",f=80,p=160,{layers:g,flatLayers:b,selectLayer:x,toggleVisibility:y,toggleLock:v,deleteLayer:w,duplicateLayer:C,reorderById:j,reorderWithinGroup:M,addToGroup:S,removeFromGroup:R,createEmptyGroup:I,findElementById:D,findParentGroup:E,generateAllPreviews:O}=Zs({...d,previewSize:p,previewBackgroundColor:h});l.useEffect(()=>{r&&b.length>0&&O()},[r,b.length,h,O]);const z=l.useMemo(()=>{const U=new Map,W=Ie=>{for(const ke of Ie)U.set(ke.id,ke),ke.children&&W(ke.children)};return W(g),U},[g]),B=l.useCallback((U,W,Ie)=>{const ke=E(U),Ke=E(W);ke&&!Ke?R(U,W,Ie):j(U,W,Ie)},[E,R,j]),k=ap({onReorder:B,onDropIntoGroup:S,onDropIntoGroupAtPosition:(U,W)=>S(U,W),onGroupReorder:M,onRemoveFromGroup:R,findParentGroup:E}),Y=U=>[...U].reverse().map(Ie=>n.jsxs(l.Fragment,{children:[n.jsx(gp,{layer:Ie,isOver:k.overId===Ie.id,dropPosition:k.overId===Ie.id?k.dropPosition:null,isDragActive:!!k.activeId,showPreviewImages:r,previewDisplaySize:f,onSelect:x,onToggleVisibility:y,onToggleLock:v,onDuplicate:C,onDelete:w}),Ie.children&&Y(Ie.children),Ie.isGroup&&n.jsx(xp,{groupId:Ie.id,isOver:k.overId===`group-footer::${Ie.id}`,depth:Ie.depth})]},Ie.id)),_=U=>[...U].reverse().map(Ie=>n.jsxs(l.Fragment,{children:[n.jsx(yp,{layer:Ie,showPreviewImages:r,previewDisplaySize:f,onSelect:x,onToggleVisibility:y,onToggleLock:v,onDuplicate:C,onDelete:w}),Ie.children&&_(Ie.children)]},Ie.id)),G=k.activeId?z.get(k.activeId):null,{width:se,height:A,flex:Z,...J}=i,q=se||(a.includes("w-full")?"100%":e?`${e}px`:void 0),ae=t||A||void 0,pe=Z!==void 0?Z:ae==="100%"||ae==="100vh"?1:void 0;return n.jsxs("div",{className:`layers-panel ${a}`,style:{width:q,height:ae,flex:pe,display:"flex",flexDirection:"column",backgroundColor:"transparent",minHeight:0,...J},children:[(c||s)&&n.jsxs("div",{style:{padding:"10px 16px",borderBottom:"1px solid var(--border-primary, #e5e5e5)",fontWeight:500,fontSize:13,color:"var(--text-secondary, #666)",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"space-between"},children:[c&&n.jsxs("span",{children:["Layers (",b.length,")"]}),!c&&n.jsx("span",{}),s&&n.jsxs("button",{onClick:I,style:{background:"none",border:"none",cursor:"pointer",fontSize:13,fontWeight:500,color:"var(--primary, var(--accent-primary, #007AFF))",display:"flex",alignItems:"center",gap:4},children:[n.jsx(de,{icon:"lucide:folder-plus",style:{fontSize:16}}),"Add Group"]})]}),n.jsxs("div",{style:{flex:1,overflow:"auto",minHeight:0},children:[g.length>0?o?n.jsxs(Of,{sensors:k.sensors,collisionDetection:mp,onDragStart:k.onDragStart,onDragMove:k.onDragMove,onDragOver:k.onDragOver,onDragEnd:k.onDragEnd,onDragCancel:k.onDragCancel,children:[Y(g),n.jsx(rp,{dropAnimation:null,children:G?n.jsx(bp,{layer:G,showPreviewImages:r,previewDisplaySize:f}):null})]}):_(g):n.jsx("div",{style:{padding:24,textAlign:"center",color:"var(--text-secondary, #999)",fontSize:12},children:"No layers"}),o&&g.length>1&&n.jsx("div",{style:{padding:"12px 16px",textAlign:"center",color:"var(--text-secondary, #aaa)",fontSize:12},children:"Drag to reorder"})]})]})},yp=({layer:e,showPreviewImages:t,previewDisplaySize:r,onSelect:o,onToggleVisibility:s,onToggleLock:i,onDuplicate:a,onDelete:c})=>{const d=e.depth>0,u=d?e.depth*24:0,h=e.isSelected?{outline:"3px solid var(--primary, var(--accent-primary, #007AFF))",outlineOffset:"2px"}:{},f={paddingLeft:u+8,paddingRight:8,paddingTop:e.isGroup?6:8,paddingBottom:e.isGroup?6:8,minHeight:e.isGroup?32:36,display:"flex",alignItems:"center",gap:8,cursor:"pointer"};return(d||e.isGroup)&&(f.backgroundColor="var(--surface-secondary, rgba(0,0,0,0.04))"),e.isGroup?n.jsxs("div",{style:f,children:[n.jsx(de,{icon:"lucide:folder-open",style:{fontSize:18,color:"var(--text-secondary, #888)"}}),n.jsx("span",{onClick:()=>o(e.id),style:{fontSize:13,fontWeight:600,flex:1},children:e.name})]},e.id):n.jsxs("div",{style:f,children:[t&&e.previewUrl?n.jsx("img",{src:e.previewUrl,alt:e.name,onClick:()=>o(e.id),style:{width:r,height:r,objectFit:"contain",borderRadius:4,border:"1px solid var(--border-primary, #e5e5e5)",cursor:"pointer",...h}}):n.jsx("div",{style:{width:r,height:r,display:"flex",alignItems:"center",justifyContent:"center",fontSize:24,opacity:.6,border:"1px solid var(--border-primary, #e5e5e5)",borderRadius:4,cursor:"pointer",...h},onClick:()=>o(e.id),children:n.jsx(de,{icon:Re.fileText})}),n.jsx("div",{style:{flex:1},onClick:()=>o(e.id)}),n.jsxs("div",{style:{display:"flex",gap:4},children:[n.jsx(Wn,{title:e.visible?"Hide":"Show",onClick:()=>s(e.id),style:{opacity:e.visible?1:.4},children:n.jsx(de,{icon:e.visible?Re.eye:Re.eyeOff,className:"size-6"})}),n.jsx(Wn,{title:e.locked?"Unlock":"Lock",onClick:()=>i(e.id),style:{opacity:e.locked?1:.4},children:n.jsx(de,{icon:e.locked?Re.lock:Re.lockOpen,className:"size-6"})}),n.jsx(Wn,{title:"Duplicate",onClick:()=>a(e.id),children:n.jsx(de,{icon:Re.copy,className:"size-6"})}),n.jsx(Wn,{title:"Delete",onClick:()=>c(e.id),style:{color:"var(--error, #ef4444)"},children:n.jsx(de,{icon:Re.trash,className:"size-6"})})]})]},e.id)},vp=Object.freeze(Object.defineProperty({__proto__:null,LayersPanel:zl},Symbol.toStringTag,{value:"Module"}));function wp(){const[e,t]=l.useState(!1);return l.useEffect(()=>{if(typeof document>"u")return;const r=()=>t(document.documentElement.classList.contains("dark"));r();const o=new MutationObserver(r);return o.observe(document.documentElement,{attributes:!0,attributeFilter:["class"]}),()=>o.disconnect()},[]),e}const oo=({isOpen:e,onClose:t,title:r,description:o,children:s,placement:i="bottom",height:a,maxHeight:c="70vh",width:d,maxWidth:u="400px",showCloseButton:h=!0,headerActions:f,hideVisibleTitle:p=!1,hideHandle:g=!1,disableScrollWrapper:b=!1,disableOverflowHidden:x=!1,"data-testid":y})=>{const v=i==="bottom"?a||c:void 0,C=wp()?.65:.4;return n.jsx(m.Drawer,{open:e,onOpenChange:j=>!j&&t(),children:n.jsxs(m.DrawerContent,{placement:i,width:d,maxWidth:u,hideHandle:g||i!=="bottom",showOverlay:!0,overlayOpacity:C,className:x?"":"overflow-hidden",style:{...v&&i==="bottom"?{height:v}:{},zIndex:"var(--z-drawer, 10002)"},"data-testid":y,"data-preserve-selection":!0,children:[n.jsx(m.DrawerTitle,{className:"sr-only",children:r}),o&&n.jsx(m.DrawerDescription,{className:"sr-only",children:o}),b?n.jsxs("div",{className:"flex flex-col flex-1 min-h-0",children:[(!p||f||h)&&n.jsxs("div",{className:"border-border-primary flex shrink-0 items-center justify-between gap-4 border-b px-6 py-4",children:[!p&&n.jsx("h2",{className:"text-foreground text-lg font-semibold",children:r}),n.jsxs("div",{className:"flex items-center gap-2",children:[f,h&&n.jsx(m.Button,{variant:"ghost",size:"sm",onClick:t,className:"min-w-8 px-2","aria-label":"Close drawer",children:n.jsx(de,{icon:Re.close,className:"size-6"})})]})]}),s]}):n.jsxs("div",{className:"flex-1 overflow-y-auto min-h-0",children:[(!p||f||h)&&n.jsxs("div",{className:"border-border-primary flex shrink-0 items-center justify-between gap-4 border-b px-6 py-4",children:[!p&&n.jsx("h2",{className:"text-foreground text-lg font-semibold",children:r}),n.jsxs("div",{className:"flex items-center gap-2",children:[f,h&&n.jsx(m.Button,{variant:"ghost",size:"sm",onClick:t,className:"min-w-8 px-2","aria-label":"Close drawer",children:n.jsx(de,{icon:Re.close,className:"size-6"})})]})]}),s]})]})})};function $o(){return($o=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(e[o]=r[o])}return e}).apply(this,arguments)}function Ol(e,t){if(e==null)return{};var r,o,s={},i=Object.keys(e);for(o=0;o<i.length;o++)t.indexOf(r=i[o])>=0||(s[r]=e[r]);return s}function Br(e){var t=l.useRef(e),r=l.useRef(function(o){t.current&&t.current(o)});return t.current=e,r.current}var Kr=function(e,t,r){return t===void 0&&(t=0),r===void 0&&(r=1),e>r?r:e<t?t:e},Hr=function(e){return"touches"in e},Os=function(e){return e&&e.ownerDocument.defaultView||self},ya=function(e,t,r){var o=e.getBoundingClientRect(),s=Hr(t)?function(i,a){for(var c=0;c<i.length;c++)if(i[c].identifier===a)return i[c];return i[0]}(t.touches,r):t;return{left:Kr((s.pageX-(o.left+Os(e).pageXOffset))/o.width),top:Kr((s.pageY-(o.top+Os(e).pageYOffset))/o.height)}},va=function(e){!Hr(e)&&e.preventDefault()},_l=l.memo(function(e){var t=e.onMove,r=e.onKey,o=e.onEnd,s=Ol(e,["onMove","onKey","onEnd"]),i=l.useRef(null),a=Br(t),c=Br(r),d=Br(o),u=l.useRef(null),h=l.useRef(!1),f=l.useMemo(function(){var y=function(C){va(C),(Hr(C)?C.touches.length>0:C.buttons>0)&&i.current?a(ya(i.current,C,u.current)):(w(!1),d())},v=function(){w(!1),d()};function w(C){var j=h.current,M=Os(i.current),S=C?M.addEventListener:M.removeEventListener;S(j?"touchmove":"mousemove",y),S(j?"touchend":"mouseup",v)}return[function(C){var j=C.nativeEvent,M=i.current;if(M&&(va(j),!function(R,I){return I&&!Hr(R)}(j,h.current)&&M)){if(Hr(j)){h.current=!0;var S=j.changedTouches||[];S.length&&(u.current=S[0].identifier)}M.focus(),a(ya(M,j,u.current)),w(!0)}},function(C){var j=C.which||C.keyCode;j<37||j>40||(C.preventDefault(),c({left:j===39?.05:j===37?-.05:0,top:j===40?.05:j===38?-.05:0}))},function(C){var j=C.which||C.keyCode;j>=37&&j<=40&&d()},w]},[c,a,d]),p=f[0],g=f[1],b=f[2],x=f[3];return l.useEffect(function(){return x},[x]),l.createElement("div",$o({},s,{onTouchStart:p,onMouseDown:p,className:"react-colorful__interactive",ref:i,onKeyDown:g,onKeyUp:b,tabIndex:0,role:"slider"}))}),pi=function(e){return e.filter(Boolean).join(" ")},Bl=function(e){var t=e.color,r=e.left,o=e.top,s=o===void 0?.5:o,i=pi(["react-colorful__pointer",e.className]);return l.createElement("div",{className:i,style:{top:100*s+"%",left:100*r+"%"}},l.createElement("div",{className:"react-colorful__pointer-fill",style:{backgroundColor:t}}))},on=function(e,t,r){return t===void 0&&(t=0),r===void 0&&(r=Math.pow(10,t)),Math.round(r*e)/r},Cp=function(e){return Tp(_s(e))},_s=function(e){return e[0]==="#"&&(e=e.substring(1)),e.length<6?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:e.length===4?on(parseInt(e[3]+e[3],16)/255,2):1}:{r:parseInt(e.substring(0,2),16),g:parseInt(e.substring(2,4),16),b:parseInt(e.substring(4,6),16),a:e.length===8?on(parseInt(e.substring(6,8),16)/255,2):1}},Sp=function(e){return Ep(jp(e))},kp=function(e){var t=e.s,r=e.v,o=e.a,s=(200-t)*r/100;return{h:on(e.h),s:on(s>0&&s<200?t*r/100/(s<=100?s:200-s)*100:0),l:on(s/2),a:on(o,2)}},Bs=function(e){var t=kp(e);return"hsl("+t.h+", "+t.s+"%, "+t.l+"%)"},jp=function(e){var t=e.h,r=e.s,o=e.v,s=e.a;t=t/360*6,r/=100,o/=100;var i=Math.floor(t),a=o*(1-r),c=o*(1-(t-i)*r),d=o*(1-(1-t+i)*r),u=i%6;return{r:on(255*[o,c,a,a,d,o][u]),g:on(255*[d,o,o,c,a,a][u]),b:on(255*[a,a,d,o,o,c][u]),a:on(s,2)}},mo=function(e){var t=e.toString(16);return t.length<2?"0"+t:t},Ep=function(e){var t=e.r,r=e.g,o=e.b,s=e.a,i=s<1?mo(on(255*s)):"";return"#"+mo(t)+mo(r)+mo(o)+i},Tp=function(e){var t=e.r,r=e.g,o=e.b,s=e.a,i=Math.max(t,r,o),a=i-Math.min(t,r,o),c=a?i===t?(r-o)/a:i===r?2+(o-t)/a:4+(t-r)/a:0;return{h:on(60*(c<0?c+6:c)),s:on(i?a/i*100:0),v:on(i/255*100),a:s}},Rp=l.memo(function(e){var t=e.hue,r=e.onChange,o=e.onChangeEnd,s=pi(["react-colorful__hue",e.className]);return l.createElement("div",{className:s},l.createElement(_l,{onMove:function(i){r({h:360*i.left})},onKey:function(i){r({h:Kr(t+360*i.left,0,360)})},onEnd:o,"aria-label":"Hue","aria-valuenow":on(t),"aria-valuemax":"360","aria-valuemin":"0"},l.createElement(Bl,{className:"react-colorful__hue-pointer",left:t/360,color:Bs({h:t,s:100,v:100,a:1})})))}),Np=l.memo(function(e){var t=e.hsva,r=e.onChange,o=e.onChangeEnd,s={backgroundColor:Bs({h:t.h,s:100,v:100,a:1})};return l.createElement("div",{className:"react-colorful__saturation",style:s},l.createElement(_l,{onMove:function(i){r({s:100*i.left,v:100-100*i.top})},onKey:function(i){r({s:Kr(t.s+100*i.left,0,100),v:Kr(t.v-100*i.top,0,100)})},onEnd:o,"aria-label":"Color","aria-valuetext":"Saturation "+on(t.s)+"%, Brightness "+on(t.v)+"%"},l.createElement(Bl,{className:"react-colorful__saturation-pointer",top:1-t.v/100,left:t.s/100,color:Bs(t)})))}),Hl=function(e,t){if(e===t)return!0;for(var r in e)if(e[r]!==t[r])return!1;return!0},Mp=function(e,t){return e.toLowerCase()===t.toLowerCase()||Hl(_s(e),_s(t))};function Ip(e,t,r,o){var s=Br(r),i=Br(o),a=l.useState(function(){return e.toHsva(t)}),c=a[0],d=a[1],u=l.useRef({color:t,hsva:c}),h=l.useRef(!1);l.useEffect(function(){if(!e.equal(t,u.current.color)){var g=e.toHsva(t);u.current={hsva:g,color:t},d(g),h.current=!1}},[t,e]),l.useEffect(function(){var g;Hl(c,u.current.hsva)||e.equal(g=e.fromHsva(c),u.current.color)||(u.current={hsva:c,color:g},s(g),h.current=!0)},[c,e,s]);var f=l.useCallback(function(g){d(function(b){return Object.assign({},b,g)})},[]),p=l.useCallback(function(){h.current&&(h.current=!1,i(u.current.color))},[i]);return[c,f,p]}var Ap=typeof window<"u"?l.useLayoutEffect:l.useEffect,Dp=function(){return typeof __webpack_nonce__<"u"?__webpack_nonce__:void 0},wa=new Map,Lp=function(e){Ap(function(){var t=e.current?e.current.ownerDocument:document;if(t!==void 0&&!wa.has(t)){var r=t.createElement("style");r.innerHTML=`.react-colorful{position:relative;display:flex;flex-direction:column;width:200px;height:200px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;cursor:default}.react-colorful__saturation{position:relative;flex-grow:1;border-color:transparent;border-bottom:12px solid #000;border-radius:8px 8px 0 0;background-image:linear-gradient(0deg,#000,transparent),linear-gradient(90deg,#fff,hsla(0,0%,100%,0))}.react-colorful__alpha-gradient,.react-colorful__pointer-fill{content:"";position:absolute;left:0;top:0;right:0;bottom:0;pointer-events:none;border-radius:inherit}.react-colorful__alpha-gradient,.react-colorful__saturation{box-shadow:inset 0 0 0 1px rgba(0,0,0,.05)}.react-colorful__alpha,.react-colorful__hue{position:relative;height:24px}.react-colorful__hue{background:linear-gradient(90deg,red 0,#ff0 17%,#0f0 33%,#0ff 50%,#00f 67%,#f0f 83%,red)}.react-colorful__last-control{border-radius:0 0 8px 8px}.react-colorful__interactive{position:absolute;left:0;top:0;right:0;bottom:0;border-radius:inherit;outline:none;touch-action:none}.react-colorful__pointer{position:absolute;z-index:1;box-sizing:border-box;width:28px;height:28px;transform:translate(-50%,-50%);background-color:#fff;border:2px solid #fff;border-radius:50%;box-shadow:0 2px 4px rgba(0,0,0,.2)}.react-colorful__interactive:focus .react-colorful__pointer{transform:translate(-50%,-50%) scale(1.1)}.react-colorful__alpha,.react-colorful__alpha-pointer{background-color:#fff;background-image:url('data:image/svg+xml;charset=utf-8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill-opacity=".05"><path d="M8 0h8v8H8zM0 8h8v8H0z"/></svg>')}.react-colorful__saturation-pointer{z-index:3}.react-colorful__hue-pointer{z-index:2}`,wa.set(t,r);var o=Dp();o&&r.setAttribute("nonce",o),t.head.appendChild(r)}},[])},Pp=function(e){var t=e.className,r=e.colorModel,o=e.color,s=o===void 0?r.defaultColor:o,i=e.onChange,a=e.onChangeEnd,c=Ol(e,["className","colorModel","color","onChange","onChangeEnd"]),d=l.useRef(null);Lp(d);var u=Ip(r,s,i,a),h=u[0],f=u[1],p=u[2],g=pi(["react-colorful",t]);return l.createElement("div",$o({},c,{ref:d,className:g}),l.createElement(Np,{hsva:h,onChange:f,onChangeEnd:p}),l.createElement(Rp,{hue:h.h,onChange:f,onChangeEnd:p,className:"react-colorful__last-control"}))},Fp={defaultColor:"000",toHsva:Cp,fromHsva:function(e){return Sp({h:e.h,s:e.s,v:e.v,a:1})},equal:Mp},$l=function(e){return l.createElement(Pp,$o({},e,{colorModel:Fp}))};const lr=l.memo(({value:e,onChange:t,documentColors:r=[],imageColors:o=[],icon:s,showSquare:i=!1,allowTransparent:a=!1,isOpen:c,onOpenChange:d,embedded:u=!1})=>{const[h,f]=l.useState(!1),[p,g]=l.useState(e),[b,x]=l.useState(e),y=l.useRef(0),v=l.useRef(null),w=l.useRef(!1),C=l.useRef(t);C.current=t;const j=c!==void 0?c:h,M=d||f;l.useEffect(()=>{!w.current&&e!=="transparent"&&(g(e),x(e))},[e]);const S=k=>{w.current=!0,x(k),g(k);const Y=Date.now(),_=Y-y.current;_>=16?(C.current({target:{value:k}}),y.current=Y,v.current&&(clearTimeout(v.current),v.current=null)):(v.current&&clearTimeout(v.current),v.current=setTimeout(()=>{C.current({target:{value:k}}),y.current=Date.now(),v.current=null,w.current=!1},16-_))},R=l.useRef(b);R.current=b,l.useEffect(()=>{const k=()=>{v.current&&(clearTimeout(v.current),v.current=null,C.current({target:{value:R.current}})),setTimeout(()=>{w.current=!1},50)};return window.addEventListener("pointerup",k),window.addEventListener("pointercancel",k),()=>{window.removeEventListener("pointerup",k),window.removeEventListener("pointercancel",k)}},[]),l.useEffect(()=>()=>{v.current&&clearTimeout(v.current)},[]);const I=k=>{const Y=k.target.value;g(Y);const _=/^#?([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})$/,G=Y.startsWith("#")?Y:`#${Y}`;_.test(G)&&C.current({target:{value:G}})},D=k=>{S(k)},E=()=>{C.current({target:{value:"transparent"}})},O=e==="transparent",z=i?n.jsx("div",{className:`size-8 md:size-6 rounded-md border border-border-primary ${O?"transparent-pattern-small":""}`,style:O?{}:{backgroundColor:e}}):n.jsxs("div",{className:"relative flex items-center justify-center h-5 w-5",children:[s?n.jsx("span",{className:"flex items-center -translate-y-0.5",children:s}):n.jsx("span",{className:"font-bold text-lg leading-none -translate-y-0.5",children:"A"}),n.jsx("div",{className:`absolute bottom-0 left-1/2 -translate-x-1/2 h-[3px] w-4 rounded-sm ${O?"transparent-pattern-small":""}`,style:O?{}:{backgroundColor:e}})]}),B=n.jsxs("div",{className:"space-y-4 min-w-[232px]",children:[a&&n.jsxs(m.Button,{variant:"ghost",className:`flex w-full cursor-pointer items-center justify-start gap-2 rounded-lg ${O?"bg-primary/10":""}`,onClick:E,children:[n.jsx("div",{className:"transparent-pattern-small h-6 w-6 rounded"}),n.jsx("span",{className:"text-sm font-medium",children:"Transparent"})]}),n.jsx("div",{className:"w-[200px]",children:n.jsx($l,{color:O?"#ffffff":b,onChange:S})}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("label",{htmlFor:"hex-input",className:"text-sm font-medium uppercase text-foreground/60",children:"HEX"}),n.jsx("input",{id:"hex-input",type:"text",className:"w-24 rounded-lg border border-divider bg-field px-2 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none",value:p,onChange:I,placeholder:"#000000",maxLength:7})]}),r.length>0&&n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsx("div",{className:"text-sm font-medium text-foreground/60",children:"Document colors"}),n.jsx("div",{className:"grid grid-cols-8 gap-1",children:r.map((k,Y)=>n.jsx("button",{className:`h-6 w-6 cursor-pointer rounded border-2 transition-all duration-150 hover:scale-110 ${k===e?"border-primary":"border-transparent"}`,style:{backgroundColor:k},onClick:()=>D(k),"aria-label":k},Y))})]}),o.length>0&&n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsx("div",{className:"text-sm font-medium text-foreground/60",children:"Image colors"}),n.jsx("div",{className:"grid grid-cols-8 gap-1",children:o.map((k,Y)=>n.jsx("button",{className:`h-6 w-6 cursor-pointer rounded border-2 transition-all duration-150 hover:scale-110 ${k===e?"border-primary":"border-transparent"}`,style:{backgroundColor:k},onClick:()=>D(k),"aria-label":k},`img-${Y}`))})]})]});return u?B:n.jsxs(m.Popover,{open:j,onOpenChange:M,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:i?"flex items-center justify-center bg-transparent border-0 p-0 cursor-pointer rounded-md hover:opacity-80 transition-opacity":"toolbar-btn","aria-label":"Color Picker",children:z})}),n.jsx(m.PopoverContent,{className:"w-auto",maxZIndex:!0,children:B})]})});lr.displayName="ColorPickerDropdown";const zp=({stroke:e,onChange:t})=>{const[r,o]=l.useState((e==null?void 0:e.enabled)||!1),s=(e==null?void 0:e.enabled)||!1,i=(e==null?void 0:e.color)||"#000000",a=(e==null?void 0:e.width)||5,c=(e==null?void 0:e.lineCap)||"butt",d=(e==null?void 0:e.lineJoin)||"miter",u=(e==null?void 0:e.opacity)!==void 0?e.opacity:1,h=y=>{t(y?{enabled:!0,color:i,width:a,lineCap:c,lineJoin:d,opacity:u}:void 0),o(y)},f=y=>{e&&t({...e,color:y.target.value})},p=y=>{e&&t({...e,width:y[0]})},g=y=>{e&&t({...e,opacity:y[0]})},b=y=>{e&&t({...e,lineCap:y})},x=y=>{e&&t({...e,lineJoin:y})};return n.jsxs(m.Disclosure,{open:r,onOpenChange:o,className:"mb-xl",children:[n.jsx(m.DisclosureTrigger,{className:"w-full",children:n.jsxs("div",{className:"flex items-center justify-between w-full",children:[n.jsx(m.Label,{children:"Stroke"}),n.jsx(m.Switch,{checked:s,onCheckedChange:h})]})}),n.jsxs(m.DisclosureContent,{className:"flex flex-col gap-lg pt-lg",children:[n.jsx(m.Fieldset,{className:"flex flex-col gap-sm",children:n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(m.Label,{children:"Color"}),n.jsx(lr,{value:i,onChange:f})]})}),n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Width"}),n.jsx(m.Slider,{value:[a],onValueChange:p,min:1,max:50,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[a,"px"]})]}),n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Opacity"}),n.jsx(m.Slider,{value:[u],onValueChange:g,min:0,max:1,step:.01}),n.jsxs("div",{className:"text-sm text-text-muted",children:[Math.round(u*100),"%"]})]}),n.jsxs(m.TooltipProvider,{delayDuration:300,children:[n.jsxs(m.Fieldset,{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Line Cap"}),n.jsxs(m.RadioGroup,{value:c,onValueChange:b,orientation:"horizontal",children:[n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"butt",id:"cap-butt",children:"Butt"})})}),n.jsx(m.TooltipContent,{children:"Butt - Flat edges"})]}),n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"round",id:"cap-round",children:"Round"})})}),n.jsx(m.TooltipContent,{children:"Round - Rounded edges"})]}),n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"square",id:"cap-square",children:"Square"})})}),n.jsx(m.TooltipContent,{children:"Square - Extended square edges"})]})]})]}),n.jsxs(m.Fieldset,{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Line Join"}),n.jsxs(m.RadioGroup,{value:d,onValueChange:x,orientation:"horizontal",children:[n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"miter",id:"join-miter",children:"Miter"})})}),n.jsx(m.TooltipContent,{children:"Miter - Sharp corners"})]}),n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"round",id:"join-round",children:"Round"})})}),n.jsx(m.TooltipContent,{children:"Round - Rounded corners"})]}),n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(m.Radio,{value:"bevel",id:"join-bevel",children:"Bevel"})})}),n.jsx(m.TooltipContent,{children:"Bevel - Beveled corners"})]})]})]})]})]})]})},Op=({mask:e,index:t,isFirst:r,isLast:o,onUpdate:s,onRemove:i,onReorder:a})=>{var j;const[c,d]=l.useState(!1),u=M=>{switch(M){case"clip":return"🎭";case"alpha":return"🌫️";case"luma":return"🌗";case"distress":return"⚡";default:return"🎭"}},h=M=>{switch(M){case"clip":return"Clip Mask";case"alpha":return"Alpha Mask";case"luma":return"Luma Mask";case"distress":return"Distress Mask";default:return"Unknown Mask"}},f=M=>{s({opacity:M})},p=M=>{s({feather:M})},g=()=>{s({inverted:!e.inverted})},b=M=>{const S=M.target.value;if(S==="image"){const R=e.maskElement.transformType==="image"&&e.maskElement.imageUrl||"";s({maskElement:{transformType:"image",imageUrl:R,x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:{type:"image",width:200,height:200,cropX:0,cropY:0,cropWidth:1,cropHeight:1,flipHorizontal:!1,flipVertical:!1,borderRadius:0}}})}else s(S==="shape"?{maskElement:{transformType:"shape",x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:{type:"shape",shapeType:"star",width:200,height:200,fillColor:"#000000",fillOpacity:1,points:5,innerRadius:.4}}}:{maskElement:{transformType:"custom",x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,text:"MASK",fontSize:80,fontFamily:"Anton",color:"#000000"}})},x=M=>{const S=M.target.value;e.maskElement.transformType==="shape"&&s({maskElement:{transformType:"shape",x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:{...e.maskElement.transformData,shapeType:S}}})},y=M=>{if(e.maskElement.transformType!=="shape"){const S=e.maskElement;s({maskElement:{transformType:e.maskElement.transformType,x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,text:M.target.value,fontSize:S.fontSize||80,fontFamily:S.fontFamily||"Anton",color:S.color||"#000000"}})}},v=M=>{if(e.maskElement.transformType==="image"){const S=e.maskElement;s({maskElement:{transformType:"image",imageUrl:M.target.value,x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:S.transformData||{type:"image",width:200,height:200,cropX:0,cropY:0,cropWidth:1,cropHeight:1,flipHorizontal:!1,flipVertical:!1,borderRadius:0}}})}},w=M=>{if(e.maskElement.transformType==="image"){const S=e.maskElement;s({maskElement:{transformType:"image",imageUrl:S.imageUrl||"",x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:{...S.transformData,width:M,height:M}}})}else if(e.maskElement.transformType==="shape")s({maskElement:{transformType:"shape",x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,transformData:{...e.maskElement.transformData,width:M,height:M}}});else{const S=e.maskElement;s({maskElement:{transformType:e.maskElement.transformType,x:e.maskElement.x||0,y:e.maskElement.y||0,rotation:e.maskElement.rotation||0,text:S.text||"MASK",fontSize:M,fontFamily:S.fontFamily||"Anton",color:S.color||"#000000"}})}},C=()=>{var M,S;return e.maskElement.transformType==="image"?((M=e.maskElement.transformData)==null?void 0:M.width)||200:e.maskElement.transformType==="shape"?((S=e.maskElement.transformData)==null?void 0:S.width)||200:e.maskElement.fontSize||80};return n.jsxs("div",{className:"rounded-md border border-border-secondary bg-bg-tertiary p-lg",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-lg",children:[n.jsx("span",{className:"text-lg",children:u(e.type)}),n.jsxs("div",{className:"flex flex-col gap-xs",children:[n.jsx("strong",{className:"text-lg text-text-primary",children:h(e.type)}),n.jsxs("small",{className:"text-sm text-text-muted",children:["#",t+1]})]})]}),n.jsx("div",{className:"flex gap-1",children:n.jsxs(m.Tooltip,{delay:0,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{size:"icon",variant:"ghost","aria-label":"Toggle mask details","aria-expanded":c,onClick:()=>d(!c),children:c?"▼":"▶"})}),n.jsx(m.TooltipContent,{children:n.jsx("p",{children:c?"Collapse":"Expand"})})]})})]}),c&&n.jsxs("div",{className:"mt-xl flex flex-col gap-xl border-t border-border-secondary pt-xl",children:[n.jsxs(m.Slider,{className:"slider-no-fill",value:[e.opacity||1],onValueChange:M=>f(M[0]),min:0,max:1,step:.01,children:[n.jsx(m.Label,{children:"Opacity"}),n.jsx(m.Slider.Output,{children:({state:M})=>`${Math.round(M.values[0]*100)}%`}),n.jsx(m.Slider.Track,{}),n.jsx(m.Slider.Thumb,{})]}),n.jsxs(m.Slider,{className:"slider-no-fill",value:[e.feather||0],onValueChange:M=>p(M[0]),min:0,max:50,step:1,children:[n.jsx(m.Label,{children:"Feather"}),n.jsx(m.Slider.Output,{children:({state:M})=>`${M.values[0]}px`}),n.jsx(m.Slider.Track,{}),n.jsx(m.Slider.Thumb,{})]}),n.jsxs("label",{className:"flex cursor-pointer items-center gap-md text-base text-text-secondary",children:[n.jsx("input",{type:"checkbox",checked:e.inverted||!1,onChange:g,className:"h-4 w-4 cursor-pointer"}),n.jsx("span",{children:"Invert Mask"})]}),n.jsxs("div",{className:"flex flex-col gap-lg rounded-md border border-border-dark bg-bg-secondary p-xl",children:[n.jsx("div",{className:"mb-xs text-md font-semibold uppercase tracking-wide text-accent-primary",children:"Mask Shape"}),n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx("label",{htmlFor:`mask-type-${e.id}`,className:"text-base text-text-secondary",children:"Type"}),n.jsxs("select",{id:`mask-type-${e.id}`,value:e.maskElement.transformType==="shape"?"shape":e.maskElement.transformType==="image"?"image":"custom",onChange:b,className:"w-full cursor-pointer rounded-md border border-border-dark bg-bg-tertiary px-md py-sm text-base text-text-primary transition-all duration-base hover:border-accent-primary focus:border-accent-primary focus:outline-none",children:[n.jsx("option",{value:"custom",children:"Text"}),n.jsx("option",{value:"shape",children:"Shape"}),n.jsx("option",{value:"image",children:"Image"})]})]}),e.maskElement.transformType==="shape"&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx("label",{htmlFor:`mask-shape-${e.id}`,className:"text-base text-text-secondary",children:"Shape"}),n.jsxs("select",{id:`mask-shape-${e.id}`,value:((j=e.maskElement.transformData)==null?void 0:j.shapeType)||"star",onChange:x,className:"w-full cursor-pointer rounded-md border border-border-dark bg-bg-tertiary px-md py-sm text-base text-text-primary transition-all duration-base hover:border-accent-primary focus:border-accent-primary focus:outline-none",children:[n.jsx("option",{value:"rectangle",children:"Rectangle"}),n.jsx("option",{value:"circle",children:"Circle"}),n.jsx("option",{value:"ellipse",children:"Ellipse"}),n.jsx("option",{value:"star",children:"Star"})]})]}),e.maskElement.transformType==="image"&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx("label",{htmlFor:`mask-image-${e.id}`,className:"text-base text-text-secondary",children:"Image URL"}),n.jsx("input",{id:`mask-image-${e.id}`,type:"text",value:e.maskElement.imageUrl||"",onChange:v,className:"w-full rounded-md border border-border-dark bg-bg-tertiary px-md py-sm text-base text-text-primary transition-all duration-base hover:border-accent-primary focus:border-accent-primary focus:outline-none",placeholder:"https://... or data:image/..."})]}),e.maskElement.transformType!=="shape"&&e.maskElement.transformType!=="image"&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx("label",{htmlFor:`mask-text-${e.id}`,className:"text-base text-text-secondary",children:"Text"}),n.jsx("input",{id:`mask-text-${e.id}`,type:"text",value:e.maskElement.text||"MASK",onChange:y,className:"w-full rounded-md border border-border-dark bg-bg-tertiary px-md py-sm text-base text-text-primary transition-all duration-base hover:border-accent-primary focus:border-accent-primary focus:outline-none",placeholder:"Mask text"})]}),n.jsxs(m.Slider,{className:"slider-no-fill",value:[C()],onValueChange:M=>w(M[0]),min:20,max:500,step:10,children:[n.jsx(m.Label,{children:"Size"}),n.jsx(m.Slider.Output,{}),n.jsx(m.Slider.Track,{}),n.jsx(m.Slider.Thumb,{})]})]}),n.jsxs("div",{className:"mt-md flex gap-sm",children:[n.jsx("button",{onClick:()=>a("up"),disabled:r,title:"Move Up","aria-label":"Move mask up",className:"flex-1 cursor-pointer rounded-md border border-border-dark bg-bg-hover px-md py-sm text-xl text-text-secondary transition-all duration-slow hover:border-accent-primary hover:bg-bg-dark-hover hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-disabled",children:"↑"}),n.jsx("button",{onClick:()=>a("down"),disabled:o,title:"Move Down","aria-label":"Move mask down",className:"flex-1 cursor-pointer rounded-md border border-border-dark bg-bg-hover px-md py-sm text-xl text-text-secondary transition-all duration-slow hover:border-accent-primary hover:bg-bg-dark-hover hover:text-text-primary disabled:cursor-not-allowed disabled:opacity-disabled",children:"↓"}),n.jsx("button",{onClick:i,title:"Remove Mask","aria-label":"Remove mask",className:"flex-[2] cursor-pointer rounded-md border border-error-light bg-error px-md py-sm text-base font-semibold text-text-on-dark transition-all duration-slow hover:bg-error-light",children:"✕ Remove"})]})]})]})},_p=({masks:e=[],onChange:t})=>{const[r,o]=l.useState(e.length>0),[s,i]=l.useState(!1),a=h=>{const f={id:`mask-${Date.now()}-${Math.random().toString(36).substr(2,9)}`,type:h,maskElement:Bp(h),inverted:!1,feather:0,opacity:1};t([...e,f]),i(!1)},c=h=>{t(e.filter(f=>f.id!==h))},d=(h,f)=>{t(e.map(p=>p.id===h?{...p,...f}:p))},u=(h,f)=>{const p=e.findIndex(b=>b.id===h);if(p===-1)return;const g=[...e];f==="up"&&p>0?[g[p],g[p-1]]=[g[p-1],g[p]]:f==="down"&&p<e.length-1&&([g[p],g[p+1]]=[g[p+1],g[p]]),t(g)};return n.jsxs("div",{className:"mb-xl rounded-xl border border-border-primary bg-bg-secondary p-xl",children:[n.jsxs("div",{className:"mb-md flex items-center justify-between",children:[n.jsxs("div",{className:"flex items-center gap-md text-xl font-semibold text-text-primary",children:[n.jsxs("span",{children:["Masks (",e.length,")"]}),e.length>0&&n.jsx("button",{onClick:()=>o(!r),className:"rounded-lg border-none bg-transparent px-md py-xs text-base text-text-muted transition-colors duration-fast hover:text-text-primary",title:r?"Collapse":"Expand",children:r?"▼":"▶"})]}),n.jsx("div",{className:"flex gap-sm",children:n.jsx(m.Button,{variant:"default",onClick:()=>i(!s),className:"rounded-lg bg-accent px-xl py-sm font-semibold text-text-on-accent transition-all duration-medium hover:bg-accent-medium",children:"+ Add"})})]}),s&&n.jsxs("div",{className:"mb-md mt-md flex flex-col gap-sm rounded-lg border border-border-medium bg-surface p-md",children:[n.jsxs("button",{onClick:()=>a("clip"),className:"flex cursor-pointer items-center gap-xl rounded-lg border border-border-light bg-bg-secondary p-lg text-left text-text-primary transition-all duration-medium hover:border-accent hover:bg-bg-hover",children:[n.jsx("span",{className:"shrink-0 text-xl",children:"🎭"}),n.jsxs("div",{className:"flex flex-col gap-xs",children:[n.jsx("strong",{className:"text-lg text-text-primary",children:"Clip Mask"}),n.jsx("small",{className:"text-base text-text-secondary",children:"Hard edge clipping (text, shapes)"})]})]}),n.jsxs("button",{onClick:()=>a("alpha"),className:"flex cursor-pointer items-center gap-xl rounded-lg border border-border-light bg-bg-secondary p-lg text-left text-text-primary transition-all duration-medium hover:border-accent hover:bg-bg-hover",children:[n.jsx("span",{className:"shrink-0 text-xl",children:"🌫️"}),n.jsxs("div",{className:"flex flex-col gap-xs",children:[n.jsx("strong",{className:"text-lg text-text-primary",children:"Alpha Mask"}),n.jsx("small",{className:"text-base text-text-secondary",children:"Transparency-based masking"})]})]}),n.jsxs("button",{onClick:()=>a("luma"),className:"flex cursor-pointer items-center gap-xl rounded-lg border border-border-light bg-bg-secondary p-lg text-left text-text-primary transition-all duration-medium hover:border-accent hover:bg-bg-hover",children:[n.jsx("span",{className:"shrink-0 text-xl",children:"🌗"}),n.jsxs("div",{className:"flex flex-col gap-xs",children:[n.jsx("strong",{className:"text-lg text-text-primary",children:"Luma Mask"}),n.jsx("small",{className:"text-base text-text-secondary",children:"Luminosity-based masking"})]})]}),n.jsxs("button",{onClick:()=>a("distress"),className:"flex cursor-pointer items-center gap-xl rounded-lg border border-border-light bg-bg-secondary p-lg text-left text-text-primary transition-all duration-medium hover:border-accent hover:bg-bg-hover",children:[n.jsx("span",{className:"shrink-0 text-xl",children:"⚡"}),n.jsxs("div",{className:"flex flex-col gap-xs",children:[n.jsx("strong",{className:"text-lg text-text-primary",children:"Distress Mask"}),n.jsx("small",{className:"text-base text-text-secondary",children:"Vintage/grunge texture effects"})]})]})]}),r&&e.length>0&&n.jsx("div",{className:"mt-xl flex flex-col gap-md",children:e.map((h,f)=>n.jsx(Op,{mask:h,index:f,isFirst:f===0,isLast:f===e.length-1,onUpdate:p=>d(h.id,p),onRemove:()=>c(h.id),onReorder:p=>u(h.id,p)},h.id))}),e.length===0&&n.jsxs("div",{className:"p-3xl text-center text-text-secondary",children:[n.jsx("p",{className:"mb-xs text-lg",children:"No masks applied"}),n.jsx("small",{className:"text-base text-border-medium",children:'Click "+ Add" to add a mask'})]})]})};function Bp(e){switch(e){case"clip":return{transformType:"custom",text:"MASK",fontSize:80,fontFamily:"Anton",x:0,y:0,rotation:0,color:"#000000"};case"alpha":case"luma":return{transformType:"custom",text:"FADE",fontSize:100,fontFamily:"Arial",x:0,y:0,rotation:0,color:"#888888"};case"distress":return{transformType:"image",imageUrl:"",x:0,y:0,rotation:0,transformData:{type:"image",width:500,height:500,cropX:0,cropY:0,cropWidth:1,cropHeight:1,flipHorizontal:!1,flipVertical:!1,borderRadius:0}};default:return{transformType:"custom",text:"MASK",fontSize:80,x:0,y:0,rotation:0,color:"#000000"}}}const Hp={enabled:!0,style:"worn",intensity:30,fadeAmount:20,grainAmount:15,edgeWear:40,seed:void 0},$p={enabled:!0,style:"worn",intensity:55,fadeAmount:35,grainAmount:25,edgeWear:60,seed:void 0},Up={enabled:!0,style:"worn",intensity:75,fadeAmount:50,grainAmount:40,edgeWear:80,seed:void 0},Yp={enabled:!0,style:"cracked",intensity:25,scratchAmount:30,edgeWear:20,seed:void 0},Wp={enabled:!0,style:"cracked",intensity:50,scratchAmount:50,edgeWear:35,seed:void 0},Xp={enabled:!0,style:"cracked",intensity:80,scratchAmount:75,edgeWear:60,seed:void 0},Vp={enabled:!0,style:"grunge",intensity:35,grainAmount:40,fadeAmount:25,seed:void 0},Gp={enabled:!0,style:"grunge",intensity:60,grainAmount:60,fadeAmount:40,seed:void 0},Kp={enabled:!0,style:"grunge",intensity:85,grainAmount:80,fadeAmount:55,seed:void 0},qp={enabled:!0,style:"retro",intensity:30,fadeAmount:30,grainAmount:25,seed:void 0},Zp={enabled:!0,style:"retro",intensity:55,fadeAmount:45,grainAmount:40,seed:void 0},Jp={enabled:!0,style:"retro",intensity:75,fadeAmount:60,grainAmount:55,seed:void 0},Qp={worn:{light:Hp,medium:$p,heavy:Up},cracked:{light:Yp,medium:Wp,heavy:Xp},grunge:{light:Vp,medium:Gp,heavy:Kp},retro:{light:qp,medium:Zp,heavy:Jp}};function em(e,t){const r={...Qp[e][t]};return r.seed=Date.now(),r}const tm=({distressEffect:e,onChange:t})=>{rt.ensureBuiltinTexturesReady();const[r,o]=l.useState(!1),s=(e==null?void 0:e.enabled)||!1,i=(e==null?void 0:e.style)||"worn",a=(e==null?void 0:e.intensity)||50,c=(e==null?void 0:e.fadeAmount)||30,d=(e==null?void 0:e.grainAmount)||30,u=(e==null?void 0:e.scratchAmount)||30,h=(e==null?void 0:e.edgeWear)||40,f=S=>{t(S?{enabled:!0,style:i,intensity:a,fadeAmount:c,grainAmount:d,scratchAmount:u,edgeWear:h,seed:Date.now()}:void 0)},p=(S,R)=>{const I=em(S,R);t(I),o(!1)},g=S=>{if(e)if(S==="custom"){const R=e.textureUrl||rt.DISTRESS_TEXTURE_PRESETS[0].textureUrl;rt.preloadTexture(R),t({...e,style:"custom",textureUrl:R,textureOpacity:e.textureOpacity??e.intensity/100})}else t({...e,style:S,seed:Date.now()})},b=S=>{e&&(rt.preloadTexture(S),t({...e,style:"custom",textureUrl:S}))},x=S=>{e&&t({...e,textureOpacity:S[0]/100})},y=S=>{e&&t({...e,intensity:S[0]})},v=S=>{e&&t({...e,fadeAmount:S[0]})},w=S=>{e&&t({...e,grainAmount:S[0]})},C=S=>{e&&t({...e,scratchAmount:S[0]})},j=S=>{e&&t({...e,edgeWear:S[0]})},M=()=>{e&&t({...e,seed:Date.now()})};return n.jsxs(m.Disclosure,{open:s,onOpenChange:f,className:"mb-xl",children:[n.jsx(m.DisclosureTrigger,{className:"w-full",children:n.jsxs("div",{className:"flex items-center justify-between w-full",children:[n.jsx(m.Label,{children:"Distress Effect"}),n.jsx(m.Switch,{checked:s,onCheckedChange:f,onClick:S=>S.stopPropagation()})]})}),n.jsxs(m.DisclosureContent,{className:"flex flex-col gap-lg pt-lg",children:[n.jsx("div",{className:"flex gap-sm",children:n.jsx(m.Button,{variant:"outline",onClick:()=>o(!r),className:"flex-1",children:"Presets"})}),r&&n.jsxs("div",{className:"flex flex-col gap-xl rounded-md border border-border-primary bg-bg-tertiary p-xl",children:[n.jsxs("div",{children:[n.jsx("h4",{className:"mb-sm text-base font-semibold text-accent-primary",children:"Vintage Worn"}),n.jsxs("div",{className:"flex gap-sm",children:[n.jsx(m.Button,{variant:"outline",onClick:()=>p("worn","light"),className:"flex-1",children:"Light"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("worn","medium"),className:"flex-1",children:"Medium"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("worn","heavy"),className:"flex-1",children:"Heavy"})]})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"mb-sm text-base font-semibold text-accent-primary",children:"Cracked"}),n.jsxs("div",{className:"flex gap-sm",children:[n.jsx(m.Button,{variant:"outline",onClick:()=>p("cracked","light"),className:"flex-1",children:"Light"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("cracked","medium"),className:"flex-1",children:"Medium"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("cracked","heavy"),className:"flex-1",children:"Heavy"})]})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"mb-sm text-base font-semibold text-accent-primary",children:"Grunge"}),n.jsxs("div",{className:"flex gap-sm",children:[n.jsx(m.Button,{variant:"outline",onClick:()=>p("grunge","light"),className:"flex-1",children:"Light"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("grunge","medium"),className:"flex-1",children:"Medium"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("grunge","heavy"),className:"flex-1",children:"Heavy"})]})]}),n.jsxs("div",{children:[n.jsx("h4",{className:"mb-sm text-base font-semibold text-accent-primary",children:"Retro Halftone"}),n.jsxs("div",{className:"flex gap-sm",children:[n.jsx(m.Button,{variant:"outline",onClick:()=>p("retro","light"),className:"flex-1",children:"Light"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("retro","medium"),className:"flex-1",children:"Medium"}),n.jsx(m.Button,{variant:"outline",onClick:()=>p("retro","heavy"),className:"flex-1",children:"Heavy"})]})]})]}),n.jsxs(m.Fieldset,{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Style"}),n.jsxs(m.RadioGroup,{value:i,onValueChange:g,orientation:"horizontal",children:[n.jsx(m.Radio,{value:"worn",id:"style-worn",children:"Worn"}),n.jsx(m.Radio,{value:"cracked",id:"style-cracked",children:"Cracked"}),n.jsx(m.Radio,{value:"grunge",id:"style-grunge",children:"Grunge"}),n.jsx(m.Radio,{value:"retro",id:"style-retro",children:"Retro"}),n.jsx(m.Radio,{value:"custom",id:"style-custom",children:"Custom"})]})]}),i==="custom"&&n.jsxs(n.Fragment,{children:[n.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:rt.DISTRESS_TEXTURE_PRESETS.map(S=>n.jsx("button",{onClick:()=>b(S.textureUrl),className:`aspect-square rounded-md border-2 overflow-hidden transition-colors ${(e==null?void 0:e.textureUrl)===S.textureUrl?"border-accent-primary":"border-border-primary hover:border-border-focus"}`,title:S.name,children:n.jsx("img",{src:S.thumbnailUrl,alt:S.name,className:"w-full h-full object-cover",loading:"lazy"})},S.id))}),n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Texture Opacity"}),n.jsx(m.Slider,{value:[Math.round(((e==null?void 0:e.textureOpacity)??.5)*100)],onValueChange:x,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[Math.round(((e==null?void 0:e.textureOpacity)??.5)*100),"%"]})]})]}),i!=="custom"&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Intensity"}),n.jsx(m.Slider,{value:[a],onValueChange:y,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[a,"%"]})]}),(i==="worn"||i==="grunge"||i==="retro")&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Fade"}),n.jsx(m.Slider,{value:[c],onValueChange:v,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[c,"%"]})]}),(i==="worn"||i==="grunge"||i==="retro")&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Grain"}),n.jsx(m.Slider,{value:[d],onValueChange:w,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[d,"%"]})]}),i==="cracked"&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Scratches"}),n.jsx(m.Slider,{value:[u],onValueChange:C,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[u,"%"]})]}),(i==="worn"||i==="cracked")&&n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Edge Wear"}),n.jsx(m.Slider,{value:[h],onValueChange:j,min:0,max:100,step:1}),n.jsxs("div",{className:"text-sm text-text-muted",children:[h,"%"]})]}),n.jsx(m.Button,{variant:"outline",onClick:M,className:"w-full",children:"Randomize Pattern"})]})]})};function Ul(e){return e?!!(e.fill||e.stroke):!1}function nm(e){if(!e)return[];const t=[];return e.fill&&t.push("fill"),e.stroke&&t.push("stroke"),t}function rm(e,t="knockout"){if(!e||!Ul(e))return"No compositing";const r=nm(e),o=e.scope||"group",s=t==="clip"?"clip":"knockout";return r.length===0?"No compositing":r.length===1?`${r[0]} ${s} (${o})`:`${r.slice(0,-1).join(", ")+" & "+r[r.length-1]} ${s} (${o})`}function om(e){return!e||!Ul(e)?"No knockout":rm(e,"knockout")}const sm=({blendMode:e="normal",knockoutParts:t,onChange:r})=>{const o=e==="knockout"||e==="clip",[s,i]=l.useState(o),a=o,c=(t==null?void 0:t.fill)||!1,d=(t==null?void 0:t.stroke)||!1,u=(t==null?void 0:t.scope)||"group",h=b=>{b==="knockout"||b==="clip"?(r(b,{fill:!1,stroke:!0,scope:"artboard"}),i(!0)):(r(b,void 0),i(!1))},f=()=>{t&&r(e,{...t,fill:!c})},p=()=>{t&&r(e,{...t,stroke:!d})},g=b=>{t&&r(e,{...t,scope:b})};return n.jsxs(m.Disclosure,{open:s,onOpenChange:a?i:void 0,className:"mb-xl",children:[n.jsx(m.DisclosureTrigger,{className:"w-full",children:n.jsx("div",{className:"flex items-center justify-between w-full",children:n.jsx(m.Label,{children:"Compositing"})})}),n.jsxs(m.DisclosureContent,{className:"flex flex-col gap-lg pt-lg",children:[n.jsxs(m.Fieldset,{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Blend Mode"}),n.jsxs(m.RadioGroup,{value:e,onValueChange:h,orientation:"horizontal",children:[n.jsx(m.Radio,{value:"normal",id:"blend-normal",children:"Normal"}),n.jsx(m.Radio,{value:"knockout",id:"blend-knockout",children:"Knockout"})]})]}),a&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex flex-col gap-md border-t border-border-primary pt-2xl",children:[n.jsx("label",{className:"text-base font-medium text-text-secondary",children:"Knockout Parts"}),n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsxs("label",{className:"flex cursor-pointer flex-col gap-xs rounded-lg border border-border-primary bg-bg-tertiary p-md transition-all duration-fast hover:border-border-secondary hover:bg-bg-hover",onClick:f,children:[n.jsxs("span",{className:"flex items-center gap-sm text-lg font-semibold text-text-primary",children:[n.jsx("span",{className:"text-base",children:c?"☑":"☐"}),"Fill"]}),n.jsx("small",{className:"ml-[22px] text-sm text-text-muted",children:"Element content cuts through"})]}),n.jsxs("label",{className:"flex cursor-pointer flex-col gap-xs rounded-lg border border-border-primary bg-bg-tertiary p-md transition-all duration-fast hover:border-border-secondary hover:bg-bg-hover",onClick:p,children:[n.jsxs("span",{className:"flex items-center gap-sm text-lg font-semibold text-text-primary",children:[n.jsx("span",{className:"text-base",children:d?"☑":"☐"}),"Stroke"]}),n.jsx("small",{className:"ml-[22px] text-sm text-text-muted",children:"Border/outline cuts through"})]})]})]}),n.jsxs(m.Fieldset,{className:"flex flex-col gap-sm",children:[n.jsx(m.Label,{children:"Knockout Scope"}),n.jsxs("div",{className:"flex gap-sm",children:[n.jsxs("button",{className:`flex flex-1 cursor-pointer flex-col gap-xs rounded-lg border p-lg text-center transition-all duration-fast ${u==="group"?"border-accent-primary bg-accent-primary":"border-border-primary bg-bg-tertiary hover:border-border-secondary hover:bg-bg-hover"}`,onClick:()=>g("group"),title:"Knockout within group siblings only",children:[n.jsx("strong",{className:`text-lg ${u==="group"?"text-text-on-accent":"text-text-primary"}`,children:"Group"}),n.jsx("small",{className:`text-sm ${u==="group"?"text-bg-tertiary":"text-text-muted"}`,children:"Affects siblings in group"})]}),n.jsxs("button",{className:`flex flex-1 cursor-pointer flex-col gap-xs rounded-lg border p-lg text-center transition-all duration-fast ${u==="artboard"?"border-accent-primary bg-accent-primary":"border-border-primary bg-bg-tertiary hover:border-border-secondary hover:bg-bg-hover"}`,onClick:()=>g("artboard"),title:"Knockout cuts through to artboard",children:[n.jsx("strong",{className:`text-lg ${u==="artboard"?"text-text-on-accent":"text-text-primary"}`,children:"Artboard"}),n.jsx("small",{className:`text-sm ${u==="artboard"?"text-bg-tertiary":"text-text-muted"}`,children:"Cuts to transparent background"})]})]})]}),n.jsxs("div",{className:"flex flex-col gap-md",children:[n.jsxs("div",{className:"rounded-lg border border-border-primary bg-bg-tertiary p-md",children:[n.jsx("strong",{className:"text-sm font-semibold uppercase tracking-wide text-accent-primary",children:"Effect:"}),n.jsx("p",{className:"mt-xs text-base text-text-secondary",children:om(t)})]}),n.jsx("div",{className:"rounded-sm border-l-2 border-accent-primary bg-accent-light p-md",children:n.jsxs("small",{className:"text-sm leading-relaxed text-text-secondary",children:[n.jsx("strong",{children:"Tip:"})," Use ",n.jsx("em",{className:"font-semibold not-italic text-accent-primary",children:"Artboard"})," ","scope for t-shirt designs, ",n.jsx("em",{className:"font-semibold not-italic text-accent-primary",children:"Group"})," scope for pillow patterns."]})})]})]})]})]})},im=T.createLogger("GlyphPicker"),am=({isOpen:e,onClose:t,character:r,charIndex:o,fontFamily:s,fontWeight:i=400,currentGlyphOverride:a,onSelectGlyph:c,browseAll:d=!1})=>{const[u,h]=l.useState([]),[f,p]=l.useState(!1),[g,b]=l.useState(null);l.useEffect(()=>{if(!e)return;p(!0),b(null),(d?T.FontAnalyzer.getAllGlyphs(s,i):T.FontAnalyzer.getGlyphAlternates(s,r,i)).then(w=>{w.length===0&&b(d?`No glyphs found in ${s}`:`No alternates found for "${r}" in ${s}`),h(w),p(!1)}).catch(w=>{im.error("Error loading glyphs:",w),b(d?"Failed to load glyphs":"Failed to load glyph alternates"),p(!1)})},[e,r,s,i,d]);const x=v=>{!d&&v.category==="default"?c(null):c({charIndex:o,glyphIndex:v.glyphIndex,unicode:d?v.unicode:r,alternateName:v.name}),t()},y=d?`Browse All Glyphs - ${s}`:`Alternates for "${r}"`;return n.jsx(m.Drawer,{open:e,onOpenChange:v=>!v&&t(),children:n.jsxs(m.DrawerContent,{placement:"bottom",overlayOpacity:.4,className:"flex flex-col overflow-hidden",style:{zIndex:"var(--z-drawer, 10002)"},children:[n.jsx(m.DrawerTitle,{className:"sr-only",children:y}),n.jsxs("div",{className:"flex items-center justify-between px-3xl pb-2xl pt-2xl border-b border-border-primary",children:[n.jsxs("div",{className:"flex items-center gap-md",children:[n.jsx(Ao,{size:24,className:"text-text-muted"}),n.jsx("h3",{className:"m-0 text-3xl font-semibold text-text-primary",children:y})]}),n.jsx(m.Button,{size:"icon",variant:"ghost",onClick:t,children:n.jsx(de,{icon:Re.close,className:"size-6"})})]}),n.jsxs("div",{className:"flex-1 overflow-y-auto p-3xl",children:[f&&n.jsx("div",{className:"text-center py-6xl text-text-muted",children:"Loading alternates..."}),g&&n.jsxs("div",{className:"text-center px-3xl py-6xl text-text-placeholder text-xl",children:[g,n.jsx("div",{className:"mt-md text-base",children:"This font may not have alternate glyphs for this character."})]}),!f&&!g&&u.length>0&&n.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(100px,1fr))] gap-xl",children:u.map((v,w)=>{const C=(a==null?void 0:a.glyphIndex)===v.glyphIndex,j=v.category==="default";return n.jsxs("button",{onClick:()=>x(v),className:`
18
18
  flex flex-col items-center gap-md p-xl rounded-xl
19
19
  border-2 cursor-pointer transition-all duration-base
20
20
  relative aspect-square
@@ -23,38 +23,38 @@
23
23
  text-sm text-center whitespace-nowrap overflow-hidden
24
24
  text-ellipsis w-full
25
25
  ${C?"text-text-on-dark":"text-text-muted"}
26
- `.trim(),children:j?"Default":v.name}),j&&n.jsx("div",{className:"absolute top-xs right-xs bg-accent-primary text-text-on-dark text-xs px-sm py-[2px] rounded-md font-semibold",children:"DEFAULT"})]},`${v.glyphIndex}-${w}`)})})]}),!f&&!g&&u.length>1&&n.jsxs("div",{className:"px-3xl py-xl border-t border-border-primary bg-bg-secondary text-base text-text-muted text-center",children:[u.length," alternate",u.length!==1?"s":""," available"]})]})})},us=T.createLogger("OpenTypeFeaturesPanel"),im=[{tag:"liga",label:"Standard Ligatures",description:"Common ligatures like fi, fl",category:"ligatures"},{tag:"dlig",label:"Discretionary Ligatures",description:"Optional ligatures like ct, st",category:"ligatures"},{tag:"calt",label:"Contextual Alternates",description:"Context-aware glyph substitution",category:"ligatures"},{tag:"ccmp",label:"Glyph Composition",description:"Combine glyphs for proper display",category:"ligatures"},{tag:"locl",label:"Localized Forms",description:"Language-specific glyph variants",category:"ligatures"},{tag:"swsh",label:"Swashes",description:"Decorative flourishes",category:"alternates"},{tag:"smcp",label:"Small Caps",description:"Small capital letters",category:"alternates"},{tag:"c2sc",label:"Caps to Small Caps",description:"Convert caps to small caps",category:"alternates"},{tag:"onum",label:"Old Style Figures",description:"Varying height numbers",category:"numerals"},{tag:"lnum",label:"Lining Figures",description:"Uniform height numbers",category:"numerals"},{tag:"tnum",label:"Tabular Figures",description:"Fixed-width numbers",category:"numerals"},{tag:"pnum",label:"Proportional Figures",description:"Variable-width numbers",category:"numerals"},{tag:"ss01",label:"Stylistic Set 1",description:"Alternate character set 1",category:"stylistic"},{tag:"ss02",label:"Stylistic Set 2",description:"Alternate character set 2",category:"stylistic"},{tag:"ss03",label:"Stylistic Set 3",description:"Alternate character set 3",category:"stylistic"},{tag:"ss04",label:"Stylistic Set 4",description:"Alternate character set 4",category:"stylistic"},{tag:"ss05",label:"Stylistic Set 5",description:"Alternate character set 5",category:"stylistic"},{tag:"ss06",label:"Stylistic Set 6",description:"Alternate character set 6",category:"stylistic"},{tag:"ss07",label:"Stylistic Set 7",description:"Alternate character set 7",category:"stylistic"},{tag:"ss08",label:"Stylistic Set 8",description:"Alternate character set 8",category:"stylistic"},{tag:"ss09",label:"Stylistic Set 9",description:"Alternate character set 9",category:"stylistic"},{tag:"ss10",label:"Stylistic Set 10",description:"Alternate character set 10",category:"stylistic"},{tag:"kern",label:"Kerning",description:"Adjust spacing between letter pairs",category:"stylistic"},{tag:"mark",label:"Mark Positioning",description:"Position diacritical marks",category:"stylistic"},{tag:"mkmk",label:"Mark to Mark",description:"Position marks relative to marks",category:"stylistic"}],am=({fontFamily:e,fontWeight:t=400,text:r="",openTypeFeatures:o,glyphOverrides:s=[],onChange:i,onGlyphOverridesChange:a})=>{const[c,d]=l.useState(!1),[u,h]=l.useState([]),[f,p]=l.useState(!1),[g,b]=l.useState(!1),[x,y]=l.useState(0),[v,w]=l.useState(""),[C,j]=l.useState(!1),[M,S]=l.useState(new Map),[R,I]=l.useState(!1);l.useEffect(()=>{if(!e){h([]);return}p(!0),T.FontAnalyzer.getAvailableFeatures(e,t).then(B=>{h(B),p(!1)}).catch(B=>{us.error("Error loading OpenType features:",B),h([]),p(!1)})},[e,t]),l.useEffect(()=>{if(!r||!e){S(new Map);return}const B=Array.from(new Set(Array.from(r).filter(se=>se!==" ")));if(B.length===0){S(new Map);return}I(!0),(async()=>{const se=new Map;for(const A of B)try{const Z=await T.FontAnalyzer.getGlyphAlternates(e,A,t),J=Z.length>0?Z.length-1:0;se.set(A,J)}catch(Z){us.error(`Error loading alternates for '${A}':`,Z),se.set(A,0)}S(se),I(!1)})()},[r,e,t]);const D=B=>{const G=o==null?void 0:o[B],se={...o,[B]:!G};Object.keys(se).forEach(A=>{se[A]||delete se[A]}),e&&Object.keys(se).length>0&&T.FontAnalyzer.loadFont(e,t).catch(A=>{us.error("Error pre-loading font for OpenType features:",A)}),i(Object.keys(se).length>0?se:void 0)},E=(B,G)=>{y(B),w(G),j(!1),b(!0)},O=()=>{j(!0),b(!0)},z=B=>{if(!a)return;let G=[...s];if(B){const se=G.findIndex(A=>A.charIndex===B.charIndex);se>=0?G[se]=B:G.push(B)}else G=G.filter(se=>se.charIndex!==x);a(G.length>0?G:void 0)},_=o?Object.values(o).filter(Boolean).length:0,k=s.length,Y=im.reduce((B,G)=>(B[G.category]||(B[G.category]=[]),B[G.category].push(G),B),{});return n.jsxs("div",{className:"mb-lg",children:[n.jsxs("div",{className:`flex cursor-pointer items-center justify-between py-sm ${c?"border-b border-border-light":""}`,onClick:()=>d(!c),children:[n.jsxs("div",{className:"flex items-center gap-sm",children:[n.jsx(de,{icon:Re.text,className:"size-4"}),n.jsx("span",{className:"text-xl font-medium",children:"OpenType Features"}),_>0&&n.jsx("span",{className:"rounded-full bg-info px-xs py-[2px] text-2xs font-semibold text-info-foreground",children:_})]}),n.jsx("button",{className:"cursor-pointer border-none bg-transparent p-xs text-xs",children:c?"▼":"▶"})]}),c&&n.jsxs("div",{className:"py-md",children:[f&&n.jsx("div",{className:"py-md text-sm text-text-secondary",children:"Loading available features..."}),!f&&!e&&n.jsx("div",{className:"py-md text-sm text-text-muted",children:"Select a text element to configure OpenType features"}),!f&&e&&u.length===0&&n.jsx("div",{className:"py-md text-sm text-text-muted",children:"This font does not support advanced OpenType features"}),!f&&e&&r&&a&&n.jsxs("div",{className:"mb-lg border-b border-border-light pb-lg",children:[n.jsx("div",{className:"mb-md flex items-center justify-between",children:n.jsxs("div",{className:"flex items-center gap-sm",children:[n.jsx(Ao,{size:14,className:"text-text-secondary"}),n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wide text-text-secondary",children:"Alternate Glyphs"}),k>0&&n.jsx("span",{className:"rounded-full bg-success px-xs py-[2px] text-3xs font-semibold text-success-foreground",children:k})]})}),n.jsxs("div",{className:"mb-md flex items-center justify-between gap-md",children:[n.jsx("div",{className:"text-xs text-text-secondary",children:"Click on any letter to pick alternate glyphs"}),n.jsx(m.Button,{variant:"ghost",onClick:O,className:"whitespace-nowrap rounded-md border border-info bg-info/10 px-md py-xs text-xs font-medium text-info transition-all duration-fast hover:bg-info hover:text-info-foreground",children:"Browse All Glyphs"})]}),n.jsx("div",{className:"flex flex-wrap gap-xs rounded-md border border-border-medium bg-surface p-md",children:Array.from(r).map((B,G)=>{const se=s.some(J=>J.charIndex===G);if(B===" ")return n.jsx("div",{className:"h-4xl w-sm"},G);const Z=M.get(B)||0;return n.jsxs("button",{onClick:()=>E(G,B),className:`
26
+ `.trim(),children:j?"Default":v.name}),j&&n.jsx("div",{className:"absolute top-xs right-xs bg-accent-primary text-text-on-dark text-xs px-sm py-[2px] rounded-md font-semibold",children:"DEFAULT"})]},`${v.glyphIndex}-${w}`)})})]}),!f&&!g&&u.length>1&&n.jsxs("div",{className:"px-3xl py-xl border-t border-border-primary bg-bg-secondary text-base text-text-muted text-center",children:[u.length," alternate",u.length!==1?"s":""," available"]})]})})},hs=T.createLogger("OpenTypeFeaturesPanel"),lm=[{tag:"liga",label:"Standard Ligatures",description:"Common ligatures like fi, fl",category:"ligatures"},{tag:"dlig",label:"Discretionary Ligatures",description:"Optional ligatures like ct, st",category:"ligatures"},{tag:"calt",label:"Contextual Alternates",description:"Context-aware glyph substitution",category:"ligatures"},{tag:"ccmp",label:"Glyph Composition",description:"Combine glyphs for proper display",category:"ligatures"},{tag:"locl",label:"Localized Forms",description:"Language-specific glyph variants",category:"ligatures"},{tag:"swsh",label:"Swashes",description:"Decorative flourishes",category:"alternates"},{tag:"smcp",label:"Small Caps",description:"Small capital letters",category:"alternates"},{tag:"c2sc",label:"Caps to Small Caps",description:"Convert caps to small caps",category:"alternates"},{tag:"onum",label:"Old Style Figures",description:"Varying height numbers",category:"numerals"},{tag:"lnum",label:"Lining Figures",description:"Uniform height numbers",category:"numerals"},{tag:"tnum",label:"Tabular Figures",description:"Fixed-width numbers",category:"numerals"},{tag:"pnum",label:"Proportional Figures",description:"Variable-width numbers",category:"numerals"},{tag:"ss01",label:"Stylistic Set 1",description:"Alternate character set 1",category:"stylistic"},{tag:"ss02",label:"Stylistic Set 2",description:"Alternate character set 2",category:"stylistic"},{tag:"ss03",label:"Stylistic Set 3",description:"Alternate character set 3",category:"stylistic"},{tag:"ss04",label:"Stylistic Set 4",description:"Alternate character set 4",category:"stylistic"},{tag:"ss05",label:"Stylistic Set 5",description:"Alternate character set 5",category:"stylistic"},{tag:"ss06",label:"Stylistic Set 6",description:"Alternate character set 6",category:"stylistic"},{tag:"ss07",label:"Stylistic Set 7",description:"Alternate character set 7",category:"stylistic"},{tag:"ss08",label:"Stylistic Set 8",description:"Alternate character set 8",category:"stylistic"},{tag:"ss09",label:"Stylistic Set 9",description:"Alternate character set 9",category:"stylistic"},{tag:"ss10",label:"Stylistic Set 10",description:"Alternate character set 10",category:"stylistic"},{tag:"kern",label:"Kerning",description:"Adjust spacing between letter pairs",category:"stylistic"},{tag:"mark",label:"Mark Positioning",description:"Position diacritical marks",category:"stylistic"},{tag:"mkmk",label:"Mark to Mark",description:"Position marks relative to marks",category:"stylistic"}],cm=({fontFamily:e,fontWeight:t=400,text:r="",openTypeFeatures:o,glyphOverrides:s=[],onChange:i,onGlyphOverridesChange:a})=>{const[c,d]=l.useState(!1),[u,h]=l.useState([]),[f,p]=l.useState(!1),[g,b]=l.useState(!1),[x,y]=l.useState(0),[v,w]=l.useState(""),[C,j]=l.useState(!1),[M,S]=l.useState(new Map),[R,I]=l.useState(!1);l.useEffect(()=>{if(!e){h([]);return}p(!0),T.FontAnalyzer.getAvailableFeatures(e,t).then(_=>{h(_),p(!1)}).catch(_=>{hs.error("Error loading OpenType features:",_),h([]),p(!1)})},[e,t]),l.useEffect(()=>{if(!r||!e){S(new Map);return}const _=Array.from(new Set(Array.from(r).filter(se=>se!==" ")));if(_.length===0){S(new Map);return}I(!0),(async()=>{const se=new Map;for(const A of _)try{const Z=await T.FontAnalyzer.getGlyphAlternates(e,A,t),J=Z.length>0?Z.length-1:0;se.set(A,J)}catch(Z){hs.error(`Error loading alternates for '${A}':`,Z),se.set(A,0)}S(se),I(!1)})()},[r,e,t]);const D=_=>{const G=o==null?void 0:o[_],se={...o,[_]:!G};Object.keys(se).forEach(A=>{se[A]||delete se[A]}),e&&Object.keys(se).length>0&&T.FontAnalyzer.loadFont(e,t).catch(A=>{hs.error("Error pre-loading font for OpenType features:",A)}),i(Object.keys(se).length>0?se:void 0)},E=(_,G)=>{y(_),w(G),j(!1),b(!0)},O=()=>{j(!0),b(!0)},z=_=>{if(!a)return;let G=[...s];if(_){const se=G.findIndex(A=>A.charIndex===_.charIndex);se>=0?G[se]=_:G.push(_)}else G=G.filter(se=>se.charIndex!==x);a(G.length>0?G:void 0)},B=o?Object.values(o).filter(Boolean).length:0,k=s.length,Y=lm.reduce((_,G)=>(_[G.category]||(_[G.category]=[]),_[G.category].push(G),_),{});return n.jsxs("div",{className:"mb-lg",children:[n.jsxs("div",{className:`flex cursor-pointer items-center justify-between py-sm ${c?"border-b border-border-light":""}`,onClick:()=>d(!c),children:[n.jsxs("div",{className:"flex items-center gap-sm",children:[n.jsx(de,{icon:Re.text,className:"size-4"}),n.jsx("span",{className:"text-xl font-medium",children:"OpenType Features"}),B>0&&n.jsx("span",{className:"rounded-full bg-info px-xs py-[2px] text-2xs font-semibold text-info-foreground",children:B})]}),n.jsx("button",{className:"cursor-pointer border-none bg-transparent p-xs text-xs",children:c?"▼":"▶"})]}),c&&n.jsxs("div",{className:"py-md",children:[f&&n.jsx("div",{className:"py-md text-sm text-text-secondary",children:"Loading available features..."}),!f&&!e&&n.jsx("div",{className:"py-md text-sm text-text-muted",children:"Select a text element to configure OpenType features"}),!f&&e&&u.length===0&&n.jsx("div",{className:"py-md text-sm text-text-muted",children:"This font does not support advanced OpenType features"}),!f&&e&&r&&a&&n.jsxs("div",{className:"mb-lg border-b border-border-light pb-lg",children:[n.jsx("div",{className:"mb-md flex items-center justify-between",children:n.jsxs("div",{className:"flex items-center gap-sm",children:[n.jsx(Ao,{size:14,className:"text-text-secondary"}),n.jsx("span",{className:"text-2xs font-semibold uppercase tracking-wide text-text-secondary",children:"Alternate Glyphs"}),k>0&&n.jsx("span",{className:"rounded-full bg-success px-xs py-[2px] text-3xs font-semibold text-success-foreground",children:k})]})}),n.jsxs("div",{className:"mb-md flex items-center justify-between gap-md",children:[n.jsx("div",{className:"text-xs text-text-secondary",children:"Click on any letter to pick alternate glyphs"}),n.jsx(m.Button,{variant:"ghost",onClick:O,className:"whitespace-nowrap rounded-md border border-info bg-info/10 px-md py-xs text-xs font-medium text-info transition-all duration-fast hover:bg-info hover:text-info-foreground",children:"Browse All Glyphs"})]}),n.jsx("div",{className:"flex flex-wrap gap-xs rounded-md border border-border-medium bg-surface p-md",children:Array.from(r).map((_,G)=>{const se=s.some(J=>J.charIndex===G);if(_===" ")return n.jsx("div",{className:"h-4xl w-sm"},G);const Z=M.get(_)||0;return n.jsxs("button",{onClick:()=>E(G,_),className:`
27
27
  relative min-w-4xl cursor-pointer rounded border-2 p-xs text-center text-3xl transition-all duration-fast
28
28
  ${se?"border-success bg-success text-success-foreground":"border-border-medium bg-surface text-text-primary hover:border-info hover:bg-info/10"}
29
- `,style:{fontFamily:e},children:[B,Z>0&&n.jsx("span",{className:`absolute -right-[4px] -top-[4px] min-w-lg rounded-full border-2 border-surface px-xs py-[2px] text-center text-3xs font-semibold leading-none shadow-md ${se?"bg-success text-success-foreground":"bg-info text-info-foreground"}`,children:Z})]},G)})})]}),!f&&e&&u.length>0&&n.jsx(n.Fragment,{children:Object.entries(Y).map(([B,G])=>{const se=G.filter(A=>u.includes(A.tag));return se.length===0?null:n.jsxs("div",{className:"mb-lg",children:[n.jsx("div",{className:"mb-sm text-2xs font-semibold uppercase tracking-wide text-text-secondary",children:B}),n.jsx("div",{className:"flex flex-col gap-sm",children:se.map(A=>n.jsxs("label",{className:"flex cursor-pointer items-start gap-sm rounded p-xs transition-colors duration-fast hover:bg-surface",children:[n.jsx("input",{type:"checkbox",checked:(o==null?void 0:o[A.tag])||!1,onChange:()=>D(A.tag),className:"mt-[2px] h-4 w-4 cursor-pointer rounded border-border-primary bg-bg-input accent-accent-primary"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("div",{className:"text-sm font-medium",children:A.label}),n.jsx("div",{className:"mt-[2px] text-2xs text-text-secondary",children:A.description})]})]},A.tag))})]},B)})})]}),e&&n.jsx(sm,{isOpen:g,onClose:()=>b(!1),character:v,charIndex:x,fontFamily:e,fontWeight:t,currentGlyphOverride:s.find(B=>B.charIndex===x),onSelectGlyph:z,browseAll:C})]})},lm=({element:e,onElementUpdate:t,isOpen:r,onClose:o})=>{var p,g;const[s,i]=l.useState("stroke");if(!e)return null;const a=(p=e.stroke)==null?void 0:p.enabled,c=e.masks&&e.masks.length>0,d=(g=e.distressEffect)==null?void 0:g.enabled,u=e.blendMode==="knockout"||e.blendMode==="clip",h=e instanceof T.TextElement,f=h&&(e.glyphOverrides&&e.glyphOverrides.length>0||e.openTypeFeatures&&Object.keys(e.openTypeFeatures).length>0);return n.jsx(oo,{isOpen:r,onClose:o,title:"Layer Effects",description:"Configure stroke, masks, distress, and knockout effects",maxHeight:"90vh",placement:"right",maxWidth:"600px",children:n.jsxs(m.Tabs,{value:s,onValueChange:b=>i(b),className:"flex flex-col h-full",children:[n.jsx(m.Tabs.ListContainer,{className:"px-6",children:n.jsxs(m.Tabs.List,{"aria-label":"Effect types",children:[n.jsxs(m.Tabs.Tab,{id:"stroke",children:[n.jsx(de,{icon:Re.minus,className:"size-4"}),"Stroke",a&&n.jsx(m.Badge,{variant:"default",className:"ml-2 size-2 rounded-full p-0"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"masks",children:[n.jsx(de,{icon:Re.group,className:"size-4"}),"Masks",c&&n.jsx(m.Badge,{variant:"default",className:"ml-2 size-2 rounded-full p-0"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"distress",children:[n.jsx(de,{icon:"lucide:cloud",className:"size-4"}),"Distress",d&&n.jsx(m.Badge,{variant:"default",className:"ml-2 size-2 rounded-full p-0"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"compositing",children:[n.jsx(de,{icon:Re.scissors,className:"size-4"}),"Knockout",u&&n.jsx(m.Badge,{variant:"default",className:"ml-2 size-2 rounded-full p-0"}),n.jsx(m.Tabs.Indicator,{})]}),h&&n.jsxs(m.Tabs.Tab,{id:"typography",children:[n.jsx(de,{icon:Re.text,className:"size-4"}),"Typography",f&&n.jsx(m.Badge,{variant:"default",className:"ml-2 size-2 rounded-full p-0"}),n.jsx(m.Tabs.Indicator,{})]})]})}),n.jsxs(m.Tabs.Panel,{id:"stroke",className:"flex-1 overflow-y-auto p-6",children:[n.jsx(Pp,{stroke:e.stroke,onChange:b=>{const x=e.clone();x.stroke=b,t(x)}}),n.jsx("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted",children:[n.jsx(de,{icon:"lucide:lightbulb",className:"size-4 shrink-0 mt-0.5"}),n.jsx("span",{children:"Add outlines to text and shapes"})]})})]}),n.jsxs(m.Tabs.Panel,{id:"masks",className:"flex-1 overflow-y-auto p-6",children:[n.jsx(zp,{masks:e.masks,onChange:b=>{const x=e.clone();x.masks=b,t(x)}}),n.jsx("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted",children:[n.jsx(de,{icon:"lucide:lightbulb",className:"size-4 shrink-0 mt-0.5"}),n.jsx("span",{children:"Use masks to control visibility"})]})})]}),n.jsxs(m.Tabs.Panel,{id:"distress",className:"flex-1 overflow-y-auto p-6",children:[n.jsx(Qp,{distressEffect:e.distressEffect,onChange:b=>{const x=e.clone();x.distressEffect=b,t(x)}}),n.jsx("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted",children:[n.jsx(de,{icon:"lucide:lightbulb",className:"size-4 shrink-0 mt-0.5"}),n.jsx("span",{children:"Add vintage/grunge effects for t-shirt designs"})]})})]}),n.jsxs(m.Tabs.Panel,{id:"compositing",className:"flex-1 overflow-y-auto p-6",children:[n.jsx(rm,{blendMode:e.blendMode,knockoutParts:e.knockoutParts,onChange:(b,x)=>{const y=e.clone();y.blendMode=b,y.knockoutParts=x,t(y)}}),n.jsx("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted",children:[n.jsx(de,{icon:"lucide:lightbulb",className:"size-4 shrink-0 mt-0.5"}),n.jsx("span",{children:"Use Artboard scope for t-shirts, Group scope for patterns"})]})})]}),h&&n.jsxs(m.Tabs.Panel,{id:"typography",className:"flex-1 overflow-y-auto p-6",children:[n.jsx(am,{fontFamily:e.fontFamily,fontWeight:e.bold?700:400,text:e.text,openTypeFeatures:e.openTypeFeatures,glyphOverrides:e.glyphOverrides,onChange:b=>{const x=e.clone();x.openTypeFeatures=b,t(x)},onGlyphOverridesChange:b=>{const x=e.clone();x.glyphOverrides=b,t(x)}}),n.jsx("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted",children:[n.jsx(de,{icon:"lucide:lightbulb",className:"size-4 shrink-0 mt-0.5"}),n.jsx("span",{children:"Enable advanced OpenType features like ligatures and stylistic sets"})]})})]})]})})},Ol=({isOpen:e,onClose:t,element:r,onElementUpdate:o,style:s,className:i})=>{const{selectedElement:a,executeElementUpdate:c}=Yt.useEditor(),d=r!==void 0?r:a||null,u=l.useCallback(h=>{o?o(h):d&&c(d,h)},[o,c,d]);return n.jsx("div",{style:s,className:i,children:n.jsx(lm,{element:d,onElementUpdate:u,isOpen:e,onClose:t})})},cm=Object.freeze(Object.defineProperty({__proto__:null,EffectsPanel:Ol},Symbol.toStringTag,{value:"Module"})),dm=T.createLogger("useExport");function Bl(){const{artboards:e,artboardManager:t,elements:r,canvasRef:o}=Yt.useEditor(),[s,i]=l.useState(!1),[a,c]=l.useState(!1),[d,u]=l.useState([]),[h,f]=l.useState({}),[p,g]=l.useState({totalExports:0,avgExportTime:0,isWorkerActive:!1}),b=l.useRef(0),x=l.useRef(null),y=rt.ExportManager.supportsWorkerExport(),v=l.useCallback(async(I,D={})=>{const E=e.find(z=>z.id===I);if(!E)throw new Error(`[useExport] Artboard ${I} not found`);if(!o.current)throw new Error("[useExport] Canvas ref not available");i(!0);const O={artboardId:I,artboardName:E.name,status:"rendering",progress:0,timestamp:Date.now()};u(z=>[...z,O]);try{const z=Date.now(),_=C.current,k=t.getElementsOnArtboard(I),Y=_.filter(se=>k.includes(se.id)),B=await rt.ExportManager.exportArtboardToDataURL(E,Y,o.current,{format:D.format||"png",scale:D.scale||3,transparentBackground:D.transparentBackground??!0,...D}),G=Date.now()-z;return u(se=>se.map(A=>A.artboardId===I?{...A,status:"complete",progress:100,dataUrl:B,timestamp:Date.now()}:A)),f(se=>({...se,[I]:B})),g(se=>({totalExports:se.totalExports+1,avgExportTime:(se.avgExportTime*se.totalExports+G)/(se.totalExports+1),isWorkerActive:y})),B}catch(z){throw u(_=>_.map(k=>k.artboardId===I?{...k,status:"error",error:z,timestamp:Date.now()}:k)),z}finally{i(!1)}},[e,t,r,o,y]),w=l.useCallback(async(I={})=>{i(!0);try{const D=e.map(async z=>{const _=await v(z.id,I);return{id:z.id,dataUrl:_}}),E=await Promise.all(D),O={};for(const{id:z,dataUrl:_}of E)O[z]=_;return O}finally{i(!1)}},[e,v]),C=l.useRef(r);C.current=r;const j=l.useCallback(async(I,D={})=>{const E=e.find(O=>O.id===I);if(!E)throw new Error(`[useExport] Artboard ${I} not found`);if(!o.current)throw new Error("[useExport] Canvas ref not available");i(!0);try{const O=C.current,z=t.getElementsOnArtboard(I),_=O.filter(Y=>z.includes(Y.id));return await rt.ExportManager.exportArtboardToBlob(E,_,o.current,{format:D.format||"png",scale:D.scale||3,transparentBackground:D.transparentBackground??!0,...D})}finally{i(!1)}},[e,t,r,o]),M=l.useCallback(async(I={})=>{i(!0);try{const D=e.map(async z=>{const _=await j(z.id,I);return{id:z.id,blob:_}}),E=await Promise.all(D),O={};for(const{id:z,blob:_}of E)O[z]=_;return O}finally{i(!1)}},[e,j]),S=l.useCallback(()=>{b.current++,c(!1),x.current=null},[]),R=l.useCallback(I=>{b.current++;const D=b.current;x.current=I,c(!0);const{artboardIds:E,interval:O=500,scale:z=3,format:_="png",onChange:k}=I,Y=E?e.filter(A=>E.includes(A.id)):e,B=()=>b.current===D,G=async()=>{try{const A=Y.map(async q=>{const ae=await v(q.id,{scale:z,format:_,transparentBackground:!0});return{id:q.id,dataUrl:ae}}),Z=await Promise.all(A),J={};for(const{id:q,dataUrl:ae}of Z)J[q]=ae;f(q=>({...q,...J})),k&&k(J)}catch(A){dm.error("[useExport] Continuous export error:",A)}};(async()=>{for(await G();B()&&(await new Promise(A=>setTimeout(A,O)),!!B());)await G()})()},[e,v]);return l.useEffect(()=>()=>{S()},[S]),{exportArtboard:v,exportArtboardAsBlob:j,exportAllArtboards:w,exportAllArtboardsAsBlobs:M,startContinuousExport:R,stopContinuousExport:S,isExporting:s,isContinuousExporting:a,progress:d,latestExports:h,supportsWorkerExport:y,workerStats:p}}const Ca=T.createLogger("ExportPanel"),_l=({showContinuousExport:e=!0,defaultScale:t=3,defaultFormat:r="png",onExportComplete:o,style:s={},className:i=""})=>{const{exportArtboard:a,exportAllArtboards:c,startContinuousExport:d,stopContinuousExport:u,isExporting:h,isContinuousExporting:f,progress:p,supportsWorkerExport:g,workerStats:b}=Bl(),{artboardsInfo:x,activeArtboardId:y}=Qr(),[v,w]=l.useState(t),[C,j]=l.useState(r),[M,S]=l.useState(500),R=async()=>{if(y)try{const E=await a(y,{scale:v,format:C}),O=document.createElement("a"),z=x.find(Y=>Y.id===y),_=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),k=(z==null?void 0:z.name)||"artboard";O.download=`${k}-${_}.${C}`,O.href=E,O.click(),o&&o({[y]:E})}catch(E){Ca.error("Export failed:",E),alert("Export failed. Please try again.")}},I=async()=>{try{const E=await c({scale:v,format:C}),O=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);Object.entries(E).forEach(([z,_])=>{const k=x.find(G=>G.id===z),Y=(k==null?void 0:k.name)||z,B=document.createElement("a");B.download=`${Y}-${O}.${C}`,B.href=_,B.click()}),o&&o(E)}catch(E){Ca.error("Export all failed:",E),alert("Export failed. Please try again.")}},D=()=>{f?u():d({interval:M,scale:v,format:C,onChange:E=>{o&&o(E)}})};return n.jsxs("div",{className:`export-panel ${i}`,style:{width:300,padding:16,backgroundColor:"var(--bg-primary)",border:"1px solid var(--border-primary)",borderRadius:8,...s},children:[n.jsx("h3",{style:{margin:"0 0 16px 0",fontSize:16,fontWeight:600},children:"Export Settings"}),n.jsxs("div",{style:{marginBottom:16},children:[n.jsx("label",{htmlFor:"export-scale",style:{display:"block",fontSize:13,marginBottom:4,fontWeight:500},children:"Scale"}),n.jsxs("select",{id:"export-scale",value:v,onChange:E=>w(Number(E.target.value)),style:{width:"100%",padding:8,fontSize:13,border:"1px solid var(--border-primary)",borderRadius:4,marginBottom:12},children:[n.jsx("option",{value:1,children:"1x (Original)"}),n.jsx("option",{value:2,children:"2x (Retina)"}),n.jsx("option",{value:3,children:"3x (High-Res)"}),n.jsx("option",{value:4,children:"4x (Ultra)"})]}),n.jsx("label",{htmlFor:"export-format",style:{display:"block",fontSize:13,marginBottom:4,fontWeight:500},children:"Format"}),n.jsxs("select",{id:"export-format",value:C,onChange:E=>j(E.target.value),style:{width:"100%",padding:8,fontSize:13,border:"1px solid var(--border-primary)",borderRadius:4,marginBottom:12},children:[n.jsx("option",{value:"png",children:"PNG (Transparent)"}),n.jsx("option",{value:"jpg",children:"JPEG (Smaller)"})]}),e&&n.jsxs(n.Fragment,{children:[n.jsx("label",{htmlFor:"export-interval",style:{display:"block",fontSize:13,marginBottom:4,fontWeight:500},children:"Continuous Export Interval"}),n.jsxs("select",{id:"export-interval",value:M,onChange:E=>S(Number(E.target.value)),style:{width:"100%",padding:8,fontSize:13,border:"1px solid var(--border-primary)",borderRadius:4,marginBottom:12},children:[n.jsx("option",{value:250,children:"250ms (Fast)"}),n.jsx("option",{value:500,children:"500ms (Recommended)"}),n.jsx("option",{value:1e3,children:"1s (Slow)"}),n.jsx("option",{value:2e3,children:"2s (Very Slow)"})]})]})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:16},children:[n.jsxs("button",{onClick:R,disabled:h||!y,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:12,backgroundColor:"var(--accent-primary)",color:"var(--primary-foreground)",border:"none",borderRadius:6,cursor:h||!y?"not-allowed":"pointer",fontSize:14,fontWeight:500,opacity:h||!y?.5:1},children:[n.jsx(de,{icon:Re.download,className:"size-4"}),h?"Exporting...":"Export Active Artboard"]}),n.jsxs("button",{onClick:I,disabled:h||x.length===0,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:12,backgroundColor:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border-primary)",borderRadius:6,cursor:h||x.length===0?"not-allowed":"pointer",fontSize:14,fontWeight:500,opacity:h||x.length===0?.5:1},children:[n.jsx(de,{icon:Re.image,className:"size-4"}),h?"Exporting...":"Export All Artboards"]}),e&&n.jsxs("button",{onClick:D,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:12,backgroundColor:f?"var(--danger)":"var(--success)",color:f?"var(--danger-foreground)":"var(--success-foreground)",border:"none",borderRadius:6,cursor:"pointer",fontSize:14,fontWeight:500},children:[f?n.jsx(de,{icon:Re.pause,className:"size-4"}):n.jsx(de,{icon:Re.play,className:"size-4"}),f?"Stop Continuous Export":"Start Continuous Export"]})]}),p.length>0&&n.jsxs("div",{style:{padding:12,backgroundColor:"var(--bg-secondary)",borderRadius:6,fontSize:12,marginBottom:16},children:[n.jsx("div",{style:{fontWeight:600,marginBottom:8},children:"Export Progress"}),p.slice(-3).map(E=>n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:4},children:[n.jsx("span",{children:E.artboardName}),n.jsx("span",{style:{color:E.status==="complete"?"var(--success)":"var(--text-secondary)"},children:E.status==="complete"?"✓":E.status==="error"?"✗":"..."})]},E.artboardId))]}),g&&n.jsxs("div",{style:{padding:12,backgroundColor:"var(--bg-secondary)",borderRadius:6,fontSize:11},children:[n.jsx("div",{style:{fontWeight:600,marginBottom:4},children:"Worker Export Enabled ✓"}),n.jsxs("div",{style:{opacity:.7},children:["Total Exports: ",b.totalExports,n.jsx("br",{}),"Avg Time: ",b.avgExportTime.toFixed(0),"ms"]})]})]})},um=Object.freeze(Object.defineProperty({__proto__:null,ExportPanel:_l},Symbol.toStringTag,{value:"Module"})),hs={},hm=T.createLogger("nounProjectApi"),fm=(hs==null?void 0:hs.VITE_NOUN_PROJECT_PROXY_URL)||"http://localhost:3001",pm=fm,wo=()=>!0,mm=e=>{var o,s,i;const t=(o=e.icon_url)==null?void 0:o.includes(".svg"),r=t?e.icon_url:void 0;return{id:`noun-${e.id}`,urls:{svg:r,png:e.icon_url&&!t?e.icon_url:e.thumbnail_url,preview:e.preview_url_200||e.preview_url_84||e.thumbnail_url,thumbnail:e.thumbnail_url},term:e.term,attribution:e.attribution||null,uploader:{name:((s=e.creator)==null?void 0:s.name)||"Unknown",username:((i=e.creator)==null?void 0:i.username)||"unknown"},source:"noun-project"}},Dr=async(e,t={})=>{if(!wo())throw new Error("Noun Project API keys not configured");const{limit:r=30,includeSvg:o=!0,limitToPublicDomain:s=!0,nextPage:i}=t,a={query:e,limit:r.toString()};o&&(a.include_svg="1"),s&&(a.limit_to_public_domain="1"),i&&(a.next_page=i);const c=`${pm}/v2/icon`,d=Object.keys(a).map(p=>`${encodeURIComponent(p)}=${encodeURIComponent(a[p])}`).join("&"),u=`${c}?${d}`;let h;if(h=await fetch(u,{method:"GET",headers:{Accept:"application/json"}}),!h.ok){const p=await h.text();throw hm.error("Noun Project API error:",p),new Error(`Failed to search icons: ${h.status} ${h.statusText}`)}const f=await h.json();return{results:f.icons.map(mm),nextPage:f.next_page||null}},gm=async e=>{const t=["design","business","technology","nature","food"],r=t[Math.floor(Math.random()*t.length)],{results:o}=await Dr(r,e);return o},fs={},Hl=T.createLogger("recraftApi"),Sa=[{value:"realistic_image",label:"Realistic Image",substyles:["b_and_w","enterprise","evening_light","faded_nostalgia","forest_life","hard_flash","hdr","motion_blur","mystic_naturalism","natural_light","natural_tones","organic_calm","real_life_glow","retro_realism","retro_snapshot","studio_portrait","urban_drama","village_realism","warm_folk"]},{value:"digital_illustration",label:"Digital Illustration",substyles:["2d_art_poster","2d_art_poster_2","antiquarian","bold_fantasy","child_book","cover","crosshatch","digital_engraving","engraving_color","expressionism","freehand_details","grain","grain_20","graphic_intensity","hand_drawn","hand_drawn_outline","handmade_3d","hard_comics","infantile_sketch","long_shadow","modern_folk","multicolor","neon_calm","noir","nostalgic_pastel","outline_details","pastel_gradient","pastel_sketch","pixel_art","plastic","pop_art","pop_renaissance","seamless","street_art","tablet_sketch","urban_glow","urban_sketching","young_adult_book","young_adult_book_2"]},{value:"vector_illustration",label:"Vector Illustration",substyles:["bold_stroke","chemistry","colored_stencil","cosmics","cutout","depressive","editorial","emotional_flat","engraving","line_art","line_circuit","linocut","marker_outline","mosaic","naivector","roundish_flat","seamless","segmented_colors","sharp_contrast","thin","vector_photo","vivid_shapes"]}],xm="https://external.api.recraft.ai/v1";function Co(){const e=(fs==null?void 0:fs.VITE_RECRAFT_API_TOKEN)||"";return e!==""&&e!=="YOUR_API_TOKEN_HERE"}async function bm(e,t,r,o={}){if(!Co())throw new Error("Recraft API token not configured. Set VITE_RECRAFT_API_TOKEN in your .env file.");const s=void 0,i={prompt:e.trim(),style:t,model:"recraftv3"};r&&(i.substyle=r),o.size&&(i.size=o.size),o.n&&(i.n=o.n);try{const a=await fetch(`${xm}/images/generations`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify(i)});if(!a.ok){const h=await a.text();throw new Error(`Recraft API error (${a.status}): ${h}`)}const c=await a.json();if(!c.data||c.data.length===0)throw new Error("No images returned from Recraft API");const d=c.data[0],u=t==="vector_illustration"||t==="digital_illustration"?"svg":"png";return{id:c.id,url:d.url,prompt:e,style:t,format:u,created:c.created}}catch(a){throw Hl.error("Error generating image with Recraft:",a),a}}async function ym(e){try{const t=await fetch(e);if(!t.ok)throw new Error(`Failed to download image: ${t.status}`);if((t.headers.get("content-type")||"").includes("svg")){const o=await t.text();return`data:image/svg+xml;base64,${btoa(o)}`}else{const o=await t.blob();return URL.createObjectURL(o)}}catch(t){throw Hl.error("Error downloading Recraft image:",t),t}}const ps={},Bs=(ps==null?void 0:ps.VITE_FAL_API_KEY)||"";function Lr(){return Bs!==""&&Bs!=="YOUR_FAL_KEY_HERE"}async function ka(e,t={}){if(!Lr())throw new Error("fal.ai API key not configured. Set VITE_FAL_API_KEY in your .env file.");const r={image_url:e,sync_mode:t.syncMode??!1};try{const o=await fetch("https://fal.run/fal-ai/bria/background/remove",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Key ${Bs}`},body:JSON.stringify(r)});if(!o.ok){const i=await o.text();throw new Error(`fal.ai API error (${o.status}): ${i}`)}const s=await o.json();if(!s.image||!s.image.url)throw new Error("Invalid response from fal.ai API");return s}catch(o){throw o instanceof Error?o:new Error("Failed to remove background")}}async function ja(e){const r=await(await fetch(e)).blob();return new Promise((o,s)=>{const i=new FileReader;i.onloadend=()=>o(i.result),i.onerror=s,i.readAsDataURL(r)})}function Ea(e){if(e.startsWith("data:"))return e.startsWith("data:image/svg+xml");const t=e.toLowerCase();return t.endsWith(".svg")||t.includes(".svg?")||t.includes(".svg#")}async function Ta(e,t=2048){return new Promise((r,o)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>{try{let i=s.width||s.naturalWidth,a=s.height||s.naturalHeight;if((i===0||a===0)&&(i=1024,a=1024),i>t){const h=t/i;i=t,a=a*h}const c=document.createElement("canvas");c.width=i,c.height=a;const d=c.getContext("2d");if(!d){o(new Error("Failed to get canvas context"));return}d.clearRect(0,0,i,a),d.drawImage(s,0,0,i,a);const u=c.toDataURL("image/png");r(u)}catch(i){o(i)}},s.onerror=()=>{o(new Error("Failed to load SVG image"))},s.src=e})}const ms={},vm=T.createLogger("runwareApi"),_s=(ms==null?void 0:ms.VITE_RUNWARE_API_KEY)||"",Hs=[{id:"runware:101@1",name:"Flux Dev",description:"High-quality generation with excellent detail and composition",supportsSteps:!0,supportsCFGScale:!0,supportsNegativePrompt:!0},{id:"google:4@2",name:"Nano Banana 2 Pro",description:"Advanced Google model for controlled visual creation",supportsSteps:!1,supportsCFGScale:!1,supportsNegativePrompt:!1}];let gs=null;function $r(){return _s!==""&&_s!=="YOUR_RUNWARE_KEY_HERE"}async function wm(){if(!gs){if(!$r())throw new Error("Runware API key not configured. Set VITE_RUNWARE_API_KEY in your .env file.");gs=await Xc.Runware.initialize({apiKey:_s,timeoutDuration:6e4})}return gs}async function Cm(e){var t;if(!$r())throw new Error("Runware API key not configured. Set VITE_RUNWARE_API_KEY in your .env file.");try{const r=await wm(),o=Hs.find(u=>u.id===e.model),s=(o==null?void 0:o.supportsSteps)??!0,i=(o==null?void 0:o.supportsCFGScale)??!0,a=(o==null?void 0:o.supportsNegativePrompt)??!0,c={positivePrompt:e.prompt,model:e.model,width:e.width||1024,height:e.height||1024,numberResults:1,outputFormat:"PNG"};s&&(c.steps=e.steps||25),i&&(c.CFGScale=e.cfgScale||7),a&&e.negativePrompt&&(c.negativePrompt=e.negativePrompt);const d=await r.requestImages(c);if(!d||d.length===0)throw new Error("No images generated from Runware API");return{images:d.map(u=>({imageURL:u.imageURL||"",imageUUID:u.imageUUID||"",width:e.width||1024,height:e.height||1024})),taskUUID:((t=d[0])==null?void 0:t.taskUUID)||""}}catch(r){throw vm.error("Runware API error:",r),r instanceof Error?new Error(`Runware API error: ${r.message}`):new Error("Failed to generate image with Runware")}}async function Sm(e){const r=await(await fetch(e)).blob();return new Promise((o,s)=>{const i=new FileReader;i.onloadend=()=>o(i.result),i.onerror=s,i.readAsDataURL(r)})}const mr={},sr=T.createLogger("ImageBrowser"),km="1px",xs="1px",Ra=l.memo(function({image:t,onImageSelect:r,fixedHeight:o=!1}){const[s,i]=l.useState(!1),[a,c]=l.useState(!1),[d,u]=l.useState("top"),h=l.useRef(null),f=l.useRef(null),p=l.useRef(null),g=l.useRef(!0),[b,x]=l.useState(!1),y=l.useRef(null),v=()=>{a||r(t)},w=z=>{if(!p.current)return"top";const _=p.current.getBoundingClientRect(),k=z.clientX-_.left,Y=z.clientY-_.top,B=_.width,G=_.height,se={top:Y,bottom:G-Y,left:k,right:B-k},A=Math.min(se.top,se.bottom,se.left,se.right);return A===se.top?"top":A===se.bottom?"bottom":A===se.left?"left":"right"},C=z=>{const _=w(z);y.current&&(cancelAnimationFrame(y.current),y.current=null),_!==d?(x(!0),u(_),y.current=requestAnimationFrame(()=>{y.current=requestAnimationFrame(()=>{x(!1),i(!0),y.current=null})})):(u(_),i(!0)),g.current=!1},j=z=>{y.current&&(cancelAnimationFrame(y.current),y.current=null);const _=w(z);u(_),x(!1),i(!1)},M=()=>{f.current&&(clearTimeout(f.current),f.current=null),h.current=setTimeout(()=>{c(!0)},400)},S=()=>{h.current&&(clearTimeout(h.current),h.current=null),c(!1)},R=()=>{h.current&&(clearTimeout(h.current),h.current=null),f.current&&(clearTimeout(f.current),f.current=null)},I=()=>{c(!1)},D=t.source==="unsplash"?"Unsplash":"Pixabay",E=s||a,O=()=>{if(!s)return`scale(${1.12})`;switch(d){case"top":return`scale(${1.12}) translateY(5%)`;case"bottom":return`scale(${1.12}) translateY(-5%)`;case"left":return`scale(${1.12}) translateX(5%)`;case"right":return`scale(${1.12}) translateX(-5%)`;default:return`scale(${1.12})`}};return n.jsxs("div",{ref:p,onClick:v,onMouseEnter:C,onMouseLeave:j,className:`group relative cursor-pointer overflow-hidden ${o?"h-full rounded-xs":"break-inside-avoid rounded-lg"}`,children:[n.jsx("img",{src:t.urls.small,alt:t.alt_description||"Image",className:`duration-500 ease-out ${b?"transition-none":"transition-transform"} ${o?"h-full w-full object-cover":"w-full object-cover"}`,style:{transform:O(),filter:s?"brightness(1)":"brightness(0.95)"}}),n.jsx("div",{className:"absolute top-2 right-2 z-10",children:n.jsx("button",{className:`relative flex h-6 w-6 items-center justify-center rounded-full bg-black/30 backdrop-blur-sm transition-all duration-300 ease-in-out hover:scale-110 ${E?"opacity-100":"pointer-events-none opacity-0"}`,"aria-label":"Image info",onMouseEnter:M,onMouseLeave:S,children:n.jsx(de,{icon:"lucide:aperture",className:"size-4 text-white/80"})})}),n.jsx("div",{className:`absolute inset-x-0 bottom-0 z-0 bg-linear-to-t from-black/80 via-black/60 to-transparent px-3 py-3 pt-8 transition-transform duration-300 ease-out ${a?"translate-y-0":"translate-y-full"}`,onMouseEnter:R,onMouseLeave:I,children:n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(de,{icon:t.source==="unsplash"?"simple-icons:unsplash":"simple-icons:pixabay",className:"size-3 text-white/80"}),n.jsx("span",{className:"text-xs font-medium text-white/80",children:D})]}),n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsx("span",{className:"text-xs text-white/60",children:"Photo by"}),n.jsx("span",{className:"text-sm font-medium text-white",children:t.user.name})]})]})})]})}),Na=l.memo(function({vector:t,onVectorSelect:r,fixedHeight:o=!1}){const[s,i]=l.useState(!1),[a,c]=l.useState(!1),d=l.useRef(null),u=l.useRef(null),h=()=>{a||r(t)},f=()=>{u.current&&(clearTimeout(u.current),u.current=null),d.current=setTimeout(()=>{c(!0)},400)},p=()=>{d.current&&(clearTimeout(d.current),d.current=null),c(!1)},g=()=>{d.current&&(clearTimeout(d.current),d.current=null),u.current&&(clearTimeout(u.current),u.current=null)},b=()=>{c(!1)},x=s||a;return n.jsxs("div",{onClick:h,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),className:`group relative cursor-pointer overflow-hidden bg-white/10 transition-all duration-300 ${o?"h-full rounded-xs":"break-inside-avoid rounded-lg"} ${s?"scale-105 bg-white/20":""}`,children:[n.jsx("div",{className:`flex items-center justify-center p-6 transition-all duration-300 ${o?"h-full w-full":"aspect-square w-full"}`,children:n.jsx("img",{src:t.urls.preview,alt:t.term,className:`max-h-full max-w-full object-contain transition-all duration-300 ${s?"scale-110":"scale-100"}`,style:{filter:s?"brightness(1.1)":"brightness(0.95)"}})}),n.jsxs("div",{className:"absolute top-2 right-2 z-10 flex items-center gap-2",children:[!t.urls.svg&&n.jsx("span",{className:`rounded-xs bg-amber-500/90 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-white shadow-sm transition-all duration-300 ease-in-out ${x?"opacity-100":"pointer-events-none opacity-0"}`,children:"PNG"}),n.jsx("button",{className:`relative flex h-6 w-6 items-center justify-center rounded-full bg-black/30 backdrop-blur-sm transition-all duration-300 ease-in-out hover:scale-110 ${x?"opacity-100":"pointer-events-none opacity-0"}`,"aria-label":"Vector info",onMouseEnter:f,onMouseLeave:p,children:n.jsx(de,{icon:"lucide:aperture",className:"size-4 text-white/80"})})]}),n.jsxs("div",{className:`absolute inset-x-0 bottom-0 z-0 bg-linear-to-t from-black/80 via-black/60 to-transparent px-3 py-3 pt-8 transition-transform duration-300 ease-out ${a?"translate-y-0":"translate-y-full"}`,onMouseEnter:g,onMouseLeave:b,children:[n.jsxs("div",{className:"mb-1",children:[n.jsx(de,{icon:"mdi:cube-outline",className:"mr-2 inline-block size-3 text-white/80"}),n.jsx("span",{className:"text-xs font-medium text-white/80",children:"Noun Project"})]}),n.jsx("div",{className:"text-xs text-white/60",children:"Icon by"}),n.jsx("div",{className:"text-sm font-medium text-white",children:t.uploader.name})]})]})}),jm=({isOpen:e,onToggle:t,onImageSelect:r,currentImageUrl:o,placement:s="bottom"})=>{var Ft;const[i,a]=l.useState(""),[c,d]=l.useState(""),[u,h]=l.useState([]),[f,p]=l.useState(!1),[g,b]=l.useState(null),[x,y]=l.useState("search"),[v,w]=l.useState(1),[C,j]=l.useState(1),[M,S]=l.useState(!0),[R,I]=l.useState([]),[D,E]=l.useState("masonry"),[O,z]=l.useState(""),[_,k]=l.useState([]),[Y,B]=l.useState(!1),[G,se]=l.useState(null),[A,Z]=l.useState(null),[J,q]=l.useState(!0),[ae,Le]=l.useState("grid"),[pe,U]=l.useState(!1),[W,Ie]=l.useState("runware"),[ke,Ke]=l.useState(""),[re,te]=l.useState("vector_illustration"),[he,ye]=l.useState(""),[we,Pe]=l.useState("runware:101@1"),[me,N]=l.useState(!1),[ce,le]=l.useState(null),[Me,ge]=l.useState(null),[L,ve]=l.useState(null),[tt,Ve]=l.useState(!1),[oe,ie]=l.useState(null),pt=l.useRef(null),st=l.useRef(null),ht=l.useRef(null),bt=(mr==null?void 0:mr.VITE_UNSPLASH_ACCESS_KEY)||(typeof T.process$1<"u"?T.process$1.env.NEXT_PUBLIC_UNSPLASH_ACCESS_KEY:void 0)||"YOUR_ACCESS_KEY_HERE",yt=(mr==null?void 0:mr.VITE_PIXABAY_API_KEY)||(typeof T.process$1<"u"?T.process$1.env.NEXT_PUBLIC_PIXABAY_API_KEY:void 0)||"YOUR_ACCESS_KEY_HERE",Tt=["907841","LZDKIWvumJc","19740055","iTaneIvWKvE","8354123","2538204","8262349","6714897","uYpFBR3_CTc"],Rt=$=>({id:`pixabay-${$.id}`,urls:{raw:$.largeImageURL,full:$.largeImageURL,regular:$.largeImageURL,small:$.webformatURL,thumb:$.previewURL},alt_description:$.tags,user:{name:$.user,username:$.user},width:$.imageWidth,height:$.imageHeight,source:"pixabay"}),jt=$=>({id:`unsplash-${$.id}`,urls:$.urls,alt_description:$.alt_description,user:$.user,width:$.width,height:$.height,source:"unsplash"});l.useEffect(()=>{e&&o&&(d(o),y("url"))},[e,o]),l.useEffect(()=>{e||(a(""),d(""),h([]),b(null),w(1),j(1),S(!0),I([]),z(""),k([]),se(null),Z(null),q(!0))},[e]),l.useEffect(()=>{e&&!i&&x==="search"&&u.length===0&&kt()},[e,x]);const kt=async()=>{p(!0),b(null);try{const $=[];if(bt!=="YOUR_ACCESS_KEY_HERE"){const ft=Tt.filter(ze=>!R.includes(ze)),Q=[...ft.length>=2?ft:Tt].sort(()=>Math.random()-.5).slice(0,2);Q.forEach(ze=>{$.push(fetch(`https://api.unsplash.com/collections/${ze}/photos?per_page=30`,{headers:{Authorization:`Client-ID ${bt}`}}))}),I(ze=>{const nt=[...ze,...Q];return nt.length>=Tt.length?Q:nt})}if(yt!=="YOUR_ACCESS_KEY_HERE"&&$.push(fetch(`https://pixabay.com/api/?key=${yt}&per_page=30&image_type=photo&order=popular`)),$.length===0)throw new Error("No API keys configured. Please set VITE_UNSPLASH_ACCESS_KEY or VITE_PIXABAY_API_KEY.");const ee=await Promise.all($);if(ee.filter(ft=>!ft.ok).length===ee.length)throw new Error("Failed to load images from all sources");const it=[];for(let ft=0;ft<ee.length;ft++){if(!ee[ft].ok)continue;const at=await ee[ft].json();if("hits"in at){const xt=at.hits.map(Rt);it.push(...xt)}else{const xt=at.map(jt);it.push(...xt)}}const F=it.sort(()=>Math.random()-.5);h(F),S(!0)}catch($){b($ instanceof Error?$.message:"Failed to load images"),sr.error("Error loading featured images:",$)}finally{p(!1)}},Kt=async($,ee=1,Je=1)=>{if(!$.trim()){kt();return}p(!0),b(null);try{if(ee===1&&Je===1){const it=[];if(bt!=="YOUR_ACCESS_KEY_HERE"&&it.push(fetch(`https://api.unsplash.com/search/photos?query=${encodeURIComponent($)}&page=1&per_page=30`,{headers:{Authorization:`Client-ID ${bt}`}}),fetch(`https://api.unsplash.com/search/photos?query=${encodeURIComponent($)}&page=2&per_page=30`,{headers:{Authorization:`Client-ID ${bt}`}})),yt!=="YOUR_ACCESS_KEY_HERE"&&it.push(fetch(`https://pixabay.com/api/?key=${yt}&q=${encodeURIComponent($)}&page=1&per_page=30&image_type=photo`)),it.length===0)throw new Error("No API keys configured. Please set VITE_UNSPLASH_ACCESS_KEY or VITE_PIXABAY_API_KEY.");const F=await Promise.all(it);if(F.filter(Q=>!Q.ok).length===F.length)throw new Error("Failed to search images from all sources");const at=[];for(let Q=0;Q<F.length;Q++){if(!F[Q].ok)continue;const ze=await F[Q].json();if("hits"in ze){const nt=ze.hits.map(Rt);at.push(...nt)}else{const nt=ze.results.map(jt);at.push(...nt)}}const xt=at.sort(()=>Math.random()-.5);h(xt),S(at.length>0)}else{const it=[];bt!=="YOUR_ACCESS_KEY_HERE"&&it.push(fetch(`https://api.unsplash.com/search/photos?query=${encodeURIComponent($)}&page=${ee+2}&per_page=30`,{headers:{Authorization:`Client-ID ${bt}`}})),yt!=="YOUR_ACCESS_KEY_HERE"&&it.push(fetch(`https://pixabay.com/api/?key=${yt}&q=${encodeURIComponent($)}&page=${Je+1}&per_page=30&image_type=photo`));const F=await Promise.all(it),ft=[];for(let xt=0;xt<F.length;xt++){if(!F[xt].ok)continue;const Q=await F[xt].json();if("hits"in Q){const ze=Q.hits.map(Rt);ft.push(...ze)}else{const ze=Q.results.map(jt);ft.push(...ze)}}const at=ft.sort(()=>Math.random()-.5);h(xt=>[...xt,...at]),S(ft.length>0)}}catch(it){b(it instanceof Error?it.message:"Failed to search images"),sr.error("Error searching images:",it)}finally{p(!1)}},$t=$=>{$.preventDefault(),w(1),j(1),Kt(i,1,1)},Ot=l.useCallback(async()=>{if(!(f||!M)){if(i.trim()){const $=v+1,ee=C+1;w($),j(ee),Kt(i,$,ee);return}p(!0),b(null);try{const $=[];if(bt!=="YOUR_ACCESS_KEY_HERE"){const F=Tt.filter(Q=>!R.includes(Q)),xt=[...F.length>=2?F:Tt].sort(()=>Math.random()-.5).slice(0,2);xt.forEach(Q=>{$.push(fetch(`https://api.unsplash.com/collections/${Q}/photos?per_page=30`,{headers:{Authorization:`Client-ID ${bt}`}}))}),I(Q=>{const ze=[...Q,...xt];return ze.length>=Tt.length?xt:ze})}if(yt!=="YOUR_ACCESS_KEY_HERE"){const F=C+1;$.push(fetch(`https://pixabay.com/api/?key=${yt}&page=${F}&per_page=30&image_type=photo&order=popular`)),j(F)}const ee=await Promise.all($),Je=[];for(let F=0;F<ee.length;F++){if(!ee[F].ok)continue;const ft=await ee[F].json();if("hits"in ft){const at=ft.hits.map(Rt);Je.push(...at)}else{const at=ft.map(jt);Je.push(...at)}}const it=Je.sort(()=>Math.random()-.5);h(F=>[...F,...it]),S(Je.length>0)}catch($){b($ instanceof Error?$.message:"Failed to load more images"),sr.error("Error loading more images:",$)}finally{p(!1)}}},[f,M,i,v,C,R,bt,yt]);l.useEffect(()=>{const $=pt.current;if(!$||!e||x!=="search")return;const ee=new IntersectionObserver(Je=>{Je[0].isIntersecting&&M&&!f&&Ot()},{root:null,rootMargin:"200px",threshold:0});return ee.observe($),()=>{ee.disconnect()}},[e,x,M,f,Ot]),l.useEffect(()=>{e&&!O&&x==="vector"&&_.length===0&&wo()&&De()},[e,x]);const De=async()=>{B(!0),se(null);try{const $=await gm({limit:30,includeSvg:!0});k($),q(!0)}catch($){const ee=$ instanceof Error?$.message:"Failed to load vectors";ee.includes("Failed to fetch")||ee.includes("NetworkError")?se('Cannot connect to proxy server. Make sure to run "npm run dev:proxy" in a separate terminal.'):se(ee),sr.error("Error loading featured vectors:",$)}finally{B(!1)}},je=async($,ee)=>{if(!$.trim()&&!ee){De();return}B(!0),se(null);try{const Je=!pe,{results:it,nextPage:F}=await Dr($,{limit:30,includeSvg:!0,limitToPublicDomain:Je,nextPage:ee});if(it.length>0){if(ee?k(ft=>{const at=new Set(ft.map(Q=>Q.id)),xt=it.filter(Q=>!at.has(Q.id));return[...ft,...xt]}):(k(it),U(!1)),Z(F),q(F!==null),!ee&&Je&&!F&&it.length<30){U(!0);const{results:ft,nextPage:at}=await Dr($,{limit:30,includeSvg:!0,limitToPublicDomain:!1});k(xt=>{const Q=new Set(xt.map(nt=>nt.id)),ze=ft.filter(nt=>!Q.has(nt.id));return[...xt,...ze]}),Z(at),q(at!==null)}}else if(!pe&&!ee){U(!0);const{results:ft,nextPage:at}=await Dr($,{limit:30,includeSvg:!0,limitToPublicDomain:!1});k(ft),Z(at),q(at!==null)}else if(Je&&ee&&!F){U(!0);const{results:ft,nextPage:at}=await Dr($,{limit:30,includeSvg:!0,limitToPublicDomain:!1});k(xt=>{const Q=new Set(xt.map(nt=>nt.id)),ze=ft.filter(nt=>!Q.has(nt.id));return[...xt,...ze]}),Z(at),q(at!==null)}else q(!1),Z(null)}catch(Je){const it=Je instanceof Error?Je.message:"Failed to search vectors";it.includes("Failed to fetch")||it.includes("NetworkError")?se('Cannot connect to proxy server. Make sure to run "npm run dev:proxy" in a separate terminal.'):se(it),sr.error("Error searching vectors:",Je)}finally{B(!1)}},Ee=$=>{$.preventDefault(),je(O)},$e=l.useCallback(async()=>{Y||!J||!A||(O.trim()?je(O,A):De())},[Y,J,A,O]);l.useEffect(()=>{const $=st.current;if(!$||!e||x!=="vector")return;const ee=new IntersectionObserver(Je=>{Je[0].isIntersecting&&J&&!Y&&$e()},{root:null,rootMargin:"200px",threshold:0});return ee.observe($),()=>{ee.disconnect()}},[e,x,J,Y,$e]);const Qe=$=>{let ee=$.urls.svg||$.urls.png;const it=ee.startsWith("http://localhost:3001")?ee:`http://localhost:3001/proxy-image?url=${encodeURIComponent(ee)}`;r(it),t(!1)},Fe=$=>{r($.urls.regular),t(!1)},Ue=$=>{$.preventDefault(),c.trim()&&(r(c.trim()),t(!1))},Xe=$=>{var Je;const ee=(Je=$.target.files)==null?void 0:Je[0];if(ee&&ee.type.startsWith("image/")){const it=new FileReader;it.onload=F=>{var at;const ft=(at=F.target)==null?void 0:at.result;d(ft)},it.readAsDataURL(ee)}},dt=()=>{var $;($=ht.current)==null||$.click()},Ye=async()=>{if(!c.trim()){ie("No image URL provided");return}if(!Lr()){ie("fal.ai API key not configured. Set VITE_FAL_API_KEY in your .env file.");return}Ve(!0),ie(null);try{let $=c;Ea(c)&&($=await Ta(c));const ee=await ka($,{syncMode:!1}),Je=await ja(ee.image.url);d(Je)}catch($){const ee=$ instanceof Error?$.message:"Failed to remove background";ie(ee),sr.error("Error removing background:",$)}finally{Ve(!1)}},vt=async $=>{if($.preventDefault(),!ke.trim()){le("Please enter a prompt");return}if(W==="recraft"&&!Co()){le("Recraft API token not configured. Set VITE_RECRAFT_API_TOKEN in your .env file.");return}if(W==="runware"&&!$r()){le("Runware API key not configured. Set VITE_RUNWARE_API_KEY in your .env file.");return}N(!0),le(null),ge(null),ve(null);try{if(W==="recraft"){const ee=await bm(ke,re,he||void 0);ge(ee);const Je=await ym(ee.url);ve(Je)}else{const ee=await Cm({prompt:ke,model:we,width:1024,height:1024,steps:25,cfgScale:7}),Je=await Sm(ee.images[0].imageURL);ve(Je)}}catch(ee){const Je=ee instanceof Error?ee.message:"Failed to generate image";le(Je),sr.error("Error generating AI image:",ee)}finally{N(!1)}},gt=()=>{L&&(r(L),t(!1))},Nt=($,ee)=>{const Je=$.width/$.height;return ee%12===0&&Je>.8&&Je<1.2?"col-span-2 row-span-2":Je<.75?"row-span-2":Je>1.5?"col-span-2":""};return n.jsx(oo,{isOpen:e,onClose:()=>t(!1),title:"Image Browser",description:"Browse Unsplash images or enter a custom image URL",placement:s,height:s==="bottom"?"90vh":void 0,width:s!=="bottom"?"500px":void 0,hideHandle:!0,hideVisibleTitle:!0,showCloseButton:!1,"data-testid":"image-browser-drawer",children:n.jsxs(m.Tabs,{value:x,onValueChange:$=>y($),className:"flex flex-col","data-testid":"image-browser-container",children:[n.jsx(m.Tabs.ListContainer,{className:"flex justify-center pt-4 pb-2",children:n.jsxs(m.Tabs.List,{className:"h-14 gap-1 px-1.5 md:h-12","aria-label":"Image source",children:[n.jsxs(m.Tabs.Tab,{id:"search",className:"h-11 w-14 px-0 md:h-9 md:w-11","data-testid":"image-tab-search",children:[n.jsx(de,{icon:Re.image,className:"size-6"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"url",className:"h-11 w-14 px-0 md:h-9 md:w-11","data-testid":"image-tab-url",children:[n.jsx(de,{icon:Re.link,className:"size-6"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"vector",className:"h-11 w-14 px-0 md:h-9 md:w-11","data-testid":"image-tab-vector",children:[n.jsx(de,{icon:"fa6-solid:icons",className:"size-5"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"ai",className:"h-11 w-14 px-0 md:h-9 md:w-11","data-testid":"image-tab-ai",children:[n.jsx(Ao,{size:24}),n.jsx(m.Tabs.Indicator,{})]})]})}),n.jsxs(m.Tabs.Panel,{id:"search",className:"flex flex-col",children:[n.jsxs("form",{onSubmit:$t,className:"sticky top-0 z-9 flex gap-2 bg-surface px-6 pt-4 pb-3",children:[n.jsx(m.TextField,{className:"flex-1","aria-label":"Search for images",children:n.jsx(m.Input,{type:"text",placeholder:"Search for images...",value:i,onChange:$=>a($.target.value),variant:"subtle","data-testid":"image-search-input"})}),n.jsx(m.Button,{type:"submit",size:"icon",variant:"secondary",disabled:f,"aria-label":"Search",children:n.jsx(de,{icon:Re.search,className:"size-5"})}),n.jsx(m.Button,{size:"icon",variant:"secondary",onClick:()=>E(D==="grid"?"masonry":"grid"),"aria-label":D==="grid"?"Switch to masonry view":"Switch to grid view",children:D==="grid"?n.jsx(de,{icon:"lucide:layout-grid",className:"size-5"}):n.jsx(de,{icon:Re.grip,className:"size-5"})})]}),g&&n.jsxs("div",{className:"border-danger bg-danger/10 text-danger mx-6 mb-3 rounded-2xl border-2 px-4 py-3 text-sm",children:[g,g.includes("Failed")&&bt==="YOUR_ACCESS_KEY_HERE"&&n.jsx("div",{className:"mt-2 text-sm opacity-75",children:"Set VITE_UNSPLASH_ACCESS_KEY in your .env file to enable Unsplash search"})]}),f&&u.length===0&&n.jsx("div",{className:"text-muted px-6 py-8 text-center text-sm",children:"Loading images..."}),u.length>0&&n.jsxs("div",{className:"mx-6 overflow-hidden rounded-t-2xl",children:[D==="masonry"?n.jsx("div",{className:"grid grid-flow-dense pb-4",style:{display:"grid",gridTemplateColumns:s==="bottom"?"repeat(auto-fill, minmax(200px, 1fr))":"repeat(3, 1fr)",gridAutoRows:s==="bottom"?"200px":"120px",gap:km},children:u.map(($,ee)=>n.jsx("div",{className:Nt($,ee),children:n.jsx(Ra,{image:$,onImageSelect:Fe,fixedHeight:!0})},$.id))}):n.jsx("div",{className:"pb-4",style:{display:"grid",gridTemplateColumns:s==="bottom"?"repeat(auto-fill, minmax(150px, 1fr))":"repeat(auto-fill, minmax(120px, 1fr))",gap:xs},children:u.map($=>n.jsx("div",{style:{aspectRatio:"1 / 1"},children:n.jsx(Ra,{image:$,onImageSelect:Fe,fixedHeight:!0})},$.id))}),M&&n.jsx("div",{ref:pt,className:"h-px"}),f&&n.jsx("div",{className:"text-muted py-4 text-center text-sm",children:"Loading more..."}),!M&&!f&&n.jsx("div",{className:"text-muted py-6 text-center text-sm",children:"No more images"})]}),!f&&u.length===0&&i&&n.jsxs("div",{className:"text-muted px-6 py-12 text-center text-sm",children:['No images found for "',i,'"']})]}),n.jsxs(m.Tabs.Panel,{id:"url",className:"flex flex-col gap-5 p-6",children:[n.jsx("input",{ref:ht,type:"file",accept:"image/*",onChange:Xe,className:"hidden"}),n.jsxs("button",{type:"button",onClick:dt,className:"flex flex-col items-center justify-center gap-3 rounded-2xl border-2 border-dashed border-divider bg-muted/30 px-6 py-10 transition-colors hover:bg-muted/50 active:bg-muted/60","data-testid":"image-upload-btn",children:[n.jsx(de,{icon:"lucide:upload-cloud",className:"size-10 text-foreground/60"}),n.jsxs("div",{className:"flex flex-col items-center gap-1",children:[n.jsx("span",{className:"text-base font-medium text-foreground",children:"Upload from device"}),n.jsx("span",{className:"text-xs text-muted-foreground",children:"PNG · JPG · SVG · GIF"})]})]}),n.jsxs("div",{className:"relative flex items-center gap-3",children:[n.jsx("div",{className:"h-px flex-1 bg-divider"}),n.jsx("span",{className:"text-muted-foreground text-xs uppercase tracking-wider",children:"or paste a link"}),n.jsx("div",{className:"h-px flex-1 bg-divider"})]}),n.jsxs("form",{onSubmit:Ue,className:"flex flex-col gap-3",children:[n.jsxs(m.TextField,{children:[n.jsx(m.Label,{className:"sr-only",children:"Image URL"}),n.jsx(m.Input,{type:"url",placeholder:"https://example.com/image.jpg",value:c,onChange:$=>d($.target.value),variant:"subtle","data-testid":"image-url-input"})]}),n.jsx(m.Button,{type:"submit",variant:"default",disabled:!c.trim(),className:"w-full","data-testid":"image-url-submit-btn",children:"Use This Image"})]}),c.trim()&&n.jsxs("div",{className:"flex flex-col gap-3 rounded-2xl border border-divider bg-muted/30 p-4",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("span",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Preview"}),Lr()&&n.jsx(m.Button,{onClick:Ye,disabled:tt||!c.trim(),variant:"secondary",size:"sm",className:"gap-2","data-testid":"remove-background-btn",children:tt?n.jsxs(n.Fragment,{children:[n.jsx(de,{icon:"eos-icons:loading",className:"size-4 animate-spin"}),"Removing…"]}):n.jsxs(n.Fragment,{children:[n.jsx(de,{icon:"mdi:image-remove",className:"size-4"}),"Remove BG"]})})]}),oe&&n.jsx("div",{className:"rounded-lg border border-danger bg-danger/10 px-3 py-2 text-xs text-danger",children:oe}),n.jsx("img",{src:c,alt:"Preview",className:"max-h-[280px] w-full rounded-lg object-contain",onError:$=>{$.target.style.display="none"},onLoad:$=>{$.target.style.display="block"}}),!Lr()&&n.jsx("div",{className:"rounded-lg border border-warning bg-warning/10 px-3 py-2 text-xs text-warning",children:"Set VITE_FAL_API_KEY in your .env file to enable background removal."})]})]}),n.jsxs(m.Tabs.Panel,{id:"vector",className:"flex flex-col",children:[n.jsxs("form",{onSubmit:Ee,className:"sticky top-0 z-9 flex gap-2 bg-surface px-6 pt-4 pb-3",children:[n.jsx(m.TextField,{className:"flex-1","aria-label":"Search for vector graphics",children:n.jsx(m.Input,{type:"text",placeholder:"Search for icons...",value:O,onChange:$=>z($.target.value),variant:"subtle","data-testid":"vector-search-input"})}),n.jsx(m.Button,{type:"submit",size:"icon",variant:"secondary",disabled:Y,"aria-label":"Search",children:n.jsx(de,{icon:Re.search,className:"size-5"})}),n.jsx(m.Button,{size:"icon",variant:"secondary",onClick:()=>Le(ae==="grid"?"masonry":"grid"),"aria-label":ae==="grid"?"Switch to masonry view":"Switch to grid view",children:ae==="grid"?n.jsx(de,{icon:"lucide:layout-grid",className:"size-5"}):n.jsx(de,{icon:Re.grip,className:"size-5"})})]}),G&&n.jsx("div",{className:"border-danger bg-danger/10 text-danger mx-6 mb-3 rounded-2xl border-2 px-4 py-3 text-sm",children:G}),!wo()&&n.jsx("div",{className:"bg-warning/10 text-warning mx-6 mb-3 rounded-2xl border-2 border-warning px-4 py-3 text-sm",children:"Noun Project API keys not configured. Set VITE_NOUN_PROJECT_API_KEY and VITE_NOUN_PROJECT_API_SECRET in your .env file."}),Y&&_.length===0&&n.jsx("div",{className:"text-muted px-6 py-8 text-center text-sm",children:"Loading vectors..."}),_.length>0&&n.jsxs("div",{className:"mx-6 overflow-hidden rounded-t-2xl",children:[ae==="masonry"?n.jsx("div",{className:"grid grid-flow-dense pb-4",style:{display:"grid",gridTemplateColumns:s==="bottom"?"repeat(auto-fill, minmax(150px, 1fr))":"repeat(3, 1fr)",gridAutoRows:s==="bottom"?"150px":"120px",gap:xs},children:_.map($=>n.jsx("div",{children:n.jsx(Na,{vector:$,onVectorSelect:Qe,fixedHeight:!0})},$.id))}):n.jsx("div",{className:"pb-4",style:{display:"grid",gridTemplateColumns:s==="bottom"?"repeat(auto-fill, minmax(120px, 1fr))":"repeat(auto-fill, minmax(100px, 1fr))",gap:xs},children:_.map($=>n.jsx("div",{style:{aspectRatio:"1 / 1"},children:n.jsx(Na,{vector:$,onVectorSelect:Qe,fixedHeight:!0})},$.id))}),J&&n.jsx("div",{ref:st,className:"h-px"}),Y&&n.jsx("div",{className:"text-muted py-4 text-center text-sm",children:"Loading more..."}),!J&&!Y&&n.jsx("div",{className:"text-muted py-6 text-center text-sm",children:"No more vectors"})]}),!Y&&_.length===0&&O&&wo()&&n.jsxs("div",{className:"text-muted px-6 py-12 text-center text-sm",children:['No vectors found for "',O,'"']})]}),n.jsxs(m.Tabs.Panel,{id:"ai",className:"flex flex-col gap-6 p-6",children:[n.jsxs(m.TextField,{children:[n.jsx(m.Label,{children:"AI Provider"}),n.jsxs("select",{value:W,onChange:$=>Ie($.target.value),className:"w-full rounded-xl border border-divider bg-field text-foreground px-4 py-3 text-sm",children:[n.jsx("option",{value:"runware",children:"Runware (Flux Dev / Nano Banana 2 Pro)"}),n.jsx("option",{value:"recraft",children:"Recraft (Vector Illustrations)"})]})]}),W==="runware"&&n.jsxs(m.TextField,{children:[n.jsx(m.Label,{children:"Model"}),n.jsx("select",{value:we,onChange:$=>Pe($.target.value),className:"w-full rounded-xl border border-divider bg-field text-foreground px-4 py-3 text-sm",children:Hs.map($=>n.jsxs("option",{value:$.id,children:[$.name," - ",$.description]},$.id))})]}),W==="recraft"&&n.jsxs(m.TextField,{children:[n.jsx(m.Label,{children:"Style"}),n.jsx("select",{value:re,onChange:$=>{te($.target.value),ye("")},className:"w-full rounded-xl border border-divider bg-field text-foreground px-4 py-3 text-sm",children:Sa.map($=>n.jsx("option",{value:$.value,children:$.label},$.value))})]}),W==="recraft"&&(()=>{const $=Sa.find(ee=>ee.value===re);return $&&$.substyles.length>0?n.jsxs(m.TextField,{children:[n.jsx(m.Label,{children:"Substyle (Optional)"}),n.jsxs("select",{value:he,onChange:ee=>ye(ee.target.value),className:"w-full rounded-xl border border-divider bg-field text-foreground px-4 py-3 text-sm",children:[n.jsx("option",{value:"",children:"None (Default)"}),$.substyles.map(ee=>n.jsx("option",{value:ee,children:ee.replace(/_/g," ")},ee))]})]}):null})(),n.jsxs("form",{onSubmit:vt,className:"flex flex-col gap-6",children:[n.jsxs(m.TextField,{children:[n.jsx(m.Label,{children:"Prompt"}),n.jsx(m.TextArea,{placeholder:"Describe the image you want to generate... (e.g., 'avocado, transparent background')",value:ke,onChange:$=>Ke($.target.value),className:"min-h-[100px] resize-y",rows:4,"data-testid":"ai-prompt-input",disabled:me})]}),n.jsx(m.Button,{type:"submit",variant:"default",disabled:!ke.trim()||me||W==="recraft"&&!Co()||W==="runware"&&!$r(),className:"w-full","data-testid":"ai-generate-btn",children:me?n.jsxs(n.Fragment,{children:[n.jsx(de,{icon:"eos-icons:loading",className:"size-5 animate-spin"}),"Generating..."]}):n.jsxs(n.Fragment,{children:[n.jsx(Ao,{size:24}),"Generate Image"]})})]}),W==="recraft"&&!Co()&&n.jsx("div",{className:"bg-warning/10 text-warning rounded-2xl border-2 border-warning px-4 py-3 text-sm",children:"Recraft API token not configured. Set VITE_RECRAFT_API_TOKEN in your .env file to enable AI generation."}),W==="runware"&&!$r()&&n.jsx("div",{className:"bg-warning/10 text-warning rounded-2xl border-2 border-warning px-4 py-3 text-sm",children:"Runware API key not configured. Set VITE_RUNWARE_API_KEY in your .env file to enable AI generation."}),ce&&n.jsx("div",{className:"border-danger bg-danger/10 text-danger rounded-2xl border-2 px-4 py-3 text-sm",children:ce}),L&&n.jsxs("div",{className:"flex flex-col gap-4 rounded-2xl border border-divider bg-muted/40 p-6",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(m.Label,{className:"text-muted text-xs uppercase tracking-wide",children:"Generated Image"}),W==="recraft"&&Me&&n.jsx("span",{className:"rounded-xs bg-muted px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-foreground/80",children:Me.format.toUpperCase()}),W==="runware"&&n.jsx("span",{className:"rounded-xs bg-muted px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-foreground/80",children:(Ft=Hs.find($=>$.id===we))==null?void 0:Ft.name})]}),n.jsx("div",{className:"flex w-fit items-center justify-center overflow-hidden rounded-lg bg-white/50 dark:bg-black/50",style:{maxHeight:"500px",maxWidth:"100%"},children:n.jsx("img",{src:L,alt:ke,className:"max-h-full max-w-full object-contain"})}),n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsx(m.Label,{className:"text-muted text-xs",children:"Prompt"}),n.jsx("p",{className:"text-sm",children:W==="recraft"&&Me?Me.prompt:ke})]}),n.jsxs("div",{className:"flex flex-col gap-3",children:[Lr()&&n.jsx(m.Button,{onClick:async()=>{if(L){Ve(!0),ie(null);try{let $=L;Ea(L)&&($=await Ta(L));const ee=await ka($,{syncMode:!1}),Je=await ja(ee.image.url);ve(Je)}catch($){ie($ instanceof Error?$.message:"Failed to remove background")}finally{Ve(!1)}}},disabled:tt||!L,variant:"secondary",size:"sm",className:"w-full gap-2","data-testid":"ai-remove-background-btn",children:tt?n.jsxs(n.Fragment,{children:[n.jsx(de,{icon:"eos-icons:loading",className:"size-4 animate-spin"}),"Removing..."]}):n.jsxs(n.Fragment,{children:[n.jsx(de,{icon:"mdi:image-remove",className:"size-4"}),"Remove Background"]})}),oe&&n.jsx("div",{className:"border-danger bg-danger/10 text-danger rounded-xl border-2 px-3 py-2 text-xs",children:oe}),n.jsx(m.Button,{onClick:gt,variant:"default",className:"w-full","data-testid":"ai-use-image-btn",children:"Use This Image"})]})]})]})]})})},$l=({isOpen:e,onOpenChange:t,onImageAdded:r,onImageChanged:o,changingElementId:s,onChangingElementIdChange:i})=>{var I;const{elements:a,setElements:c,canvasEditorRef:d,artboardManager:u,executeAddElement:h,executeElementUpdate:f}=Yt.useEditor(),{selectedId:p,setSelectedId:g}=Yt.useSelectionContext(),{activeArtboardId:b}=Qr(),x=l.useRef(a);x.current=a;const y=l.useRef(p);y.current=p;const[v,w]=l.useState(null),C=s??v,j=i??w,M=l.useCallback(D=>{var se,A;const E=x.current,O=y.current;if(C){const Z=E.find(J=>J.id===C);if(Z&&rt.isImageElement(Z)){const J=Z,q=Z.clone(),ae=((se=d.current)==null?void 0:se.getZoom())||1;q.imageUrl=D,q.transformData.width=300/ae,q.transformData.height=300/ae,q.transformData.cropX=0,q.transformData.cropY=0,q.transformData.cropWidth=1,q.transformData.cropHeight=1,q.transformData.flipHorizontal=!1,q.transformData.flipVertical=!1,q.transformData.borderRadius=0,q.imageLoaded=!1,q.imageElement=null,q.isCropping=!1,q.onLoadCallback=Le=>{const pe=Le;c(U=>U.map(W=>W.id===pe.id?pe:W))},q.loadImage(D),f(J,q),o&&o(q)}j(null);return}if(!b){alert("Please create or select an artboard first");return}const z=`element-${Date.now()}`,_=u.getActiveArtboard(),k=_?_.x+_.width/2:window.innerWidth/2,Y=_?_.y+_.height/2:window.innerHeight/2,B=((A=d.current)==null?void 0:A.getZoom())||1,G=new T.ImageElement({id:z,x:k,y:Y,imageUrl:D,transformData:{width:300/B,height:300/B},onLoadCallback:Z=>{const J=Z;c(q=>q.map(ae=>ae.id===J.id?J:ae))}});u.addElementToArtboard(z,b),h(G,b,O||void 0),g(z),r&&r(G)},[C,u,h,f,b,d,c,g,j,r,o]),S=l.useCallback(D=>{t(D),D||j(null)},[t,j]),R=C?(I=a.find(D=>D.id===C))==null?void 0:I.imageUrl:void 0;return n.jsx(jm,{isOpen:e,onToggle:S,onImageSelect:M,currentImageUrl:R})},Em=Object.freeze(Object.defineProperty({__proto__:null,ImagePanel:$l},Symbol.toStringTag,{value:"Module"})),Tm=T.createLogger("GlyphBrowserDrawer"),Rm=({isOpen:e,onClose:t,fontFamily:r,fontWeight:o=400,onInsertGlyph:s})=>{const[i,a]=l.useState([]),[c,d]=l.useState(!1),[u,h]=l.useState(null),[f,p]=l.useState("");l.useEffect(()=>{e&&(d(!0),h(null),p(""),T.FontAnalyzer.getAllGlyphs(r,o).then(x=>{x.length===0&&h(`No alternate glyphs found in ${r}`),a(x),d(!1)}).catch(x=>{Tm.error("Error loading glyphs:",x),h("Failed to load glyphs"),d(!1)}))},[e,r,o]);const g=x=>{let y=x.unicode;if(!y||y.length===0)y=String.fromCodePoint(983040+x.glyphIndex);else{const v=y.codePointAt(0);v&&v<57344&&(y=String.fromCodePoint(983040+x.glyphIndex))}s(y)},b=f?i.filter(x=>x.name.toLowerCase().includes(f.toLowerCase())||x.unicode.toLowerCase().includes(f.toLowerCase())):i;return n.jsxs(oo,{isOpen:e,onClose:t,title:`Browse Glyphs - ${r}`,description:`Browse and select alternate glyphs for the ${r} font`,maxHeight:"75vh",showCloseButton:!0,children:[n.jsx("div",{className:"px-6 py-4 border-b border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"relative",children:[n.jsx(de,{icon:Re.search,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted pointer-events-none size-4 z-10"}),n.jsx(m.Input,{type:"text",placeholder:"Search glyphs...",value:f,onChange:x=>p(x.target.value),className:"pl-10"})]})}),n.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[c&&n.jsxs("div",{className:"py-12 text-center text-muted",children:[n.jsx(m.Spinner,{size:"lg",className:"mx-auto mb-4"}),n.jsx("div",{className:"text-sm",children:"Loading glyphs..."})]}),u&&n.jsxs("div",{className:"py-12 text-center",children:[n.jsx(de,{icon:Re.alertCircle,className:"size-12 mx-auto mb-4 text-danger"}),n.jsx("div",{className:"text-base font-medium mb-2",children:u}),n.jsx("div",{className:"text-sm text-muted",children:"This font may not have alternate glyphs."})]}),!c&&!u&&b.length===0&&f&&n.jsxs("div",{className:"py-12 text-center",children:[n.jsx(de,{icon:Re.search,className:"size-12 mx-auto mb-4 text-muted"}),n.jsxs("div",{className:"text-base font-medium",children:['No glyphs found matching "',f,'"']})]}),!c&&!u&&b.length>0&&n.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(100px,1fr))] gap-4",children:b.map((x,y)=>n.jsxs("button",{onClick:()=>g(x),className:"group relative flex aspect-square cursor-pointer flex-col items-center gap-2 rounded-xl border-2 border-black/10 bg-black/5 p-3 transition-all hover:border-accent hover:bg-black/10 hover:shadow-lg dark:border-white/10 dark:bg-white/5 dark:hover:border-accent dark:hover:bg-white/10",children:[x.previewDataUrl?n.jsx("img",{src:x.previewDataUrl,alt:x.name,className:"h-auto w-full object-contain"}):n.jsx("div",{className:"text-5xl leading-none",style:{fontFamily:r},children:x.unicode}),n.jsx("div",{className:"w-full overflow-hidden text-ellipsis whitespace-nowrap text-center text-xs text-muted",children:x.name}),x.category!=="default"&&n.jsx(m.Badge,{size:"sm",color:x.category==="swash"?"warning":x.category==="stylistic"?"primary":"success",className:"absolute right-1 top-1 text-[10px] font-semibold uppercase",children:x.category==="swash"?"SW":x.category==="stylistic"?"ALT":x.category==="ligature"?"LIG":""})]},`${x.glyphIndex}-${y}`))}),!c&&!u&&b.length>0&&n.jsxs("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10 text-center text-sm text-muted",children:[b.length," glyph",b.length!==1?"s":""," available",f&&` matching "${f}"`]})]})]})},Ma=T.createLogger("GlyphPanel"),Ul=({isOpen:e,onClose:t,fontFamily:r,fontWeight:o,onInsertGlyph:s,element:i})=>{const{selectedElement:a,executeElementUpdate:c}=Yt.useEditor(),d=i!==void 0?i:a||null,u=r||(d instanceof T.TextElement?d.fontFamily:"Arial"),h=o||(d instanceof T.TextElement&&d.bold?700:400),f=l.useCallback(async p=>{if(s){s(p);return}if(!d||!(d instanceof T.TextElement)){Ma.warn("No text element selected for glyph insertion");return}try{await T.FontAnalyzer.loadFont(u,h)}catch(b){Ma.error("Error pre-loading font for glyph rendering:",b)}const g=d.clone();g.text=g.text+p,c(d,g)},[s,d,u,h,c]);return n.jsx(Rm,{isOpen:e,onClose:t,fontFamily:u,fontWeight:h,onInsertGlyph:f})},Nm=Object.freeze(Object.defineProperty({__proto__:null,GlyphPanel:Ul},Symbol.toStringTag,{value:"Module"})),Yl=({orientation:e="horizontal",showAddButton:t=!0,showCloseButtons:r=!1,maxTabWidth:o=200,style:s={},className:i="",onArtboardCreate:a,onArtboardDelete:c})=>{const{artboardsInfo:d,selectArtboard:u,createArtboard:h,deleteArtboard:f,renameArtboard:p}=Qr(),[g,b]=l.useState(null),[x,y]=l.useState(""),v=(I,D)=>{b(I),y(D)},w=()=>{g&&x.trim()&&p(g,x.trim()),b(null),y("")},C=()=>{b(null),y("")},j=()=>{h(1200,1200,{name:`Artboard ${d.length+1}`}),a&&setTimeout(()=>{const I=d[d.length];I&&a(I.id)},10)},M=(I,D)=>{if(D.stopPropagation(),d.length<=1){alert("Cannot delete the last artboard");return}confirm("Delete this artboard?")&&(f(I),c&&c(I))},S=e==="horizontal"?{display:"flex",flexDirection:"row",gap:4,padding:8,backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border-primary)",overflowX:"auto",overflowY:"hidden",...s}:{display:"flex",flexDirection:"column",gap:4,padding:8,backgroundColor:"var(--bg-secondary)",borderRight:"1px solid var(--border-primary)",overflowY:"auto",overflowX:"hidden",minWidth:200,...s},R=I=>({display:"flex",alignItems:"center",gap:8,padding:"8px 12px",backgroundColor:I?"var(--accent-primary)":"var(--bg-primary)",color:I?"var(--primary-foreground)":"var(--text-primary)",border:I?"none":"1px solid var(--border-primary)",borderRadius:6,cursor:"pointer",fontSize:13,fontWeight:I?600:400,whiteSpace:"nowrap",maxWidth:e==="horizontal"?o:void 0,minWidth:e==="horizontal"?120:void 0,transition:"all 0.2s"});return n.jsxs("div",{className:`artboard-tabs ${i}`,style:S,children:[d.map(I=>{const D=g===I.id;return n.jsxs("div",{style:R(I.isActive),onClick:()=>!D&&u(I.id),onDoubleClick:()=>v(I.id,I.name),children:[D?n.jsx("input",{type:"text",value:x,onChange:E=>y(E.target.value),onBlur:w,onKeyDown:E=>{E.key==="Enter"&&w(),E.key==="Escape"&&C()},autoFocus:!0,onClick:E=>E.stopPropagation(),style:{flex:1,padding:"2px 4px",border:"1px solid var(--border-primary)",borderRadius:4,fontSize:13,minWidth:80}}):n.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis"},children:I.name}),n.jsx("span",{style:{fontSize:11,opacity:.7,padding:"2px 6px",borderRadius:10,backgroundColor:I.isActive?"color-mix(in srgb, var(--primary-foreground) 20%, transparent)":"var(--bg-secondary)"},children:I.elementCount}),r&&n.jsx("button",{onClick:E=>M(I.id,E),style:{background:"none",border:"none",cursor:"pointer",padding:2,display:"flex",alignItems:"center",opacity:.7,transition:"opacity 0.2s"},onMouseEnter:E=>E.currentTarget.style.opacity="1",onMouseLeave:E=>E.currentTarget.style.opacity="0.7",title:"Delete artboard",children:n.jsx(de,{icon:Re.close,className:"size-3.5"})})]},I.id)}),t&&n.jsxs("button",{onClick:j,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:"8px 12px",backgroundColor:"var(--bg-primary)",border:"1px dashed var(--border-primary)",borderRadius:6,cursor:"pointer",fontSize:13,color:"var(--text-secondary)",minWidth:e==="horizontal"?120:void 0,transition:"all 0.2s"},onMouseEnter:I=>{I.currentTarget.style.backgroundColor="var(--bg-tertiary)",I.currentTarget.style.borderColor="var(--accent-primary)"},onMouseLeave:I=>{I.currentTarget.style.backgroundColor="var(--bg-primary)",I.currentTarget.style.borderColor="var(--border-primary)"},title:"Add new artboard",children:[n.jsx(de,{icon:Re.plus,className:"size-3.5"}),n.jsx("span",{children:"New Artboard"})]})]})},Mm=Object.freeze(Object.defineProperty({__proto__:null,ArtboardTabs:Yl},Symbol.toStringTag,{value:"Module"})),Im=()=>n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"shrink-0",children:n.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})});function Am({onClick:e}){return n.jsx(m.TooltipProvider,{delayDuration:300,children:n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"outline",onClick:e,className:"mr-sm border-r-border-primary pr-md","aria-label":"Back",children:n.jsx(Im,{})})}),n.jsx(m.TooltipContent,{children:"Back"})]})})}const bs=.001;function Uo(e){var r,o;if(!e)return{rotation:!1,opacity:!1,stroke:!1,knockout:!1,distress:!1,imageMask:!1,cornerRadius:!1,shapeTransparency:!1};const t=e.transformData;return{rotation:Math.abs(e.rotation??0)>bs,opacity:(e.opacity??1)<1-bs,stroke:((r=e.stroke)==null?void 0:r.enabled)===!0,knockout:e.blendMode==="knockout"||e.blendMode==="clip",distress:((o=e.distressEffect)==null?void 0:o.enabled)===!0,imageMask:!!e.masks&&e.masks.length>0,cornerRadius:((t==null?void 0:t.borderRadius)??0)>0,shapeTransparency:((t==null?void 0:t.fillOpacity)??1)<1-bs}}const Wl=({element:e,onElementUpdate:t,showUngroupButton:r=!1,onUngroup:o,onMoveForward:s,onMoveBackward:i,onChangeImage:a,onDelete:c,cornerRadiusExpanded:d=!1,onCornerRadiusToggle:u,cropExpanded:h=!1,onCropToggle:f,rotationExpanded:p=!1,onRotationToggle:g,opacityExpanded:b=!1,onOpacityToggle:x,strokeExpanded:y=!1,onStrokeToggle:v,knockoutExpanded:w=!1,onKnockoutToggle:C,distressTextureExpanded:j=!1,onDistressTextureToggle:M,imageMaskExpanded:S=!1,onImageMaskToggle:R})=>{const[I,D]=l.useState(!1),[E,O]=l.useState(!1),[z,_]=l.useState(!1),[k,Y]=l.useState(!1),[B,G]=l.useState(!1),[se,A]=l.useState(!1),[Z,J]=l.useState(!1),[q,ae]=l.useState(!1),[Le,pe]=l.useState(!1),[U,W]=l.useState(!1),Ie=e.isCropping,ke=Uo(e),Ke=()=>{if(Y(!0),Ie){const he=e.clone();he.exitCropMode(),t(he)}else{const he=e.clone();he.enterCropMode(),t(he)}f==null||f()},re=()=>{const he=e.clone();he.transformData.flipHorizontal=!he.transformData.flipHorizontal,t(he)},te=()=>{const he=e.clone();he.transformData.flipVertical=!he.transformData.flipVertical,t(he)};return n.jsxs("div",{className:"toolbar-items",children:[a&&n.jsx(ct,{icon:"lucide:image",onClick:()=>{O(!0),a()},onMouseLeave:()=>O(!1),tooltip:"Change Image",tooltipDisabled:E}),n.jsx(ct,{icon:"lucide:crop",onClick:Ke,onMouseLeave:()=>Y(!1),tooltip:Ie?"Exit Crop Mode":"Crop",tooltipDisabled:k||h,active:Ie||h}),n.jsx(ct,{icon:"lucide:flip-horizontal-2",onClick:re,tooltip:"Flip Horizontal"}),n.jsx(ct,{icon:"lucide:flip-vertical-2",onClick:te,tooltip:"Flip Vertical"}),n.jsx(ct,{icon:n.jsx(_o,{size:20,className:"md:size-5"}),onClick:()=>{G(!0),g==null||g()},onMouseLeave:()=>G(!1),tooltip:"Rotate",tooltipDisabled:B||p,active:p||ke.rotation}),n.jsx(ct,{icon:"lucide:blend",onClick:()=>{A(!0),x==null||x()},onMouseLeave:()=>A(!1),tooltip:"Transparency",tooltipDisabled:se||b,active:b||ke.opacity}),n.jsx(ct,{icon:"lucide:square-round-corner",onClick:()=>{_(!0),u==null||u()},onMouseLeave:()=>_(!1),tooltip:"Corner Radius",tooltipDisabled:z||d,active:d||ke.cornerRadius}),C&&n.jsx(ct,{icon:"lucide:scissors",onClick:()=>{ae(!0),C()},onMouseLeave:()=>ae(!1),tooltip:"Clip / Knockout",tooltipDisabled:q||w,active:w||ke.knockout}),M&&n.jsx(ct,{icon:"lucide:stamp",onClick:()=>{pe(!0),M()},onMouseLeave:()=>pe(!1),tooltip:"Distress Texture",tooltipDisabled:Le||j,active:j||ke.distress}),R&&n.jsx(ct,{icon:"lucide:venetian-mask",onClick:()=>{W(!0),R()},onMouseLeave:()=>W(!1),tooltip:"Image Mask",tooltipDisabled:U||S,active:S||ke.imageMask}),v&&n.jsx(ct,{icon:"lucide:pen-line",onClick:()=>{J(!0),v()},onMouseLeave:()=>J(!1),tooltip:"Stroke",tooltipDisabled:Z||y,active:y||ke.stroke}),(s||i||c)&&n.jsxs(m.Popover,{open:I,onOpenChange:D,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn","aria-label":"More options",children:n.jsx(de,{icon:"lucide:ellipsis-vertical",className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"end",className:"w-auto p-1",maxZIndex:!0,children:n.jsxs("div",{className:"flex items-center gap-1",children:[s&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{s(),D(!1)},"aria-label":"Move Forward",children:n.jsx(de,{icon:"hugeicons:layer-bring-forward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Forward"})]}),i&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{i(),D(!1)},"aria-label":"Move Backward",children:n.jsx(de,{icon:"hugeicons:layer-send-backward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Backward"})]}),c&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{D(!1),c()},"aria-label":"Delete",children:n.jsx(de,{icon:Re.trash,className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Delete"})]})]})})]}),r&&o&&n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"sm",onClick:o,children:"Ungroup"})}),n.jsx(m.TooltipContent,{children:"Ungroup this group"})]})]})},$s=[{id:"white",name:"White",color:"#FFFFFF"},{id:"light-gray",name:"Light Gray",color:"#E5E5E5"},{id:"medium-gray",name:"Medium Gray",color:"#999999"},{id:"dark-gray",name:"Dark Gray",color:"#333333"},{id:"black",name:"Black",color:"#000000"},{id:"orange",name:"Orange",color:"#FF8800"},{id:"blue",name:"Blue",color:"#0074D9"},{id:"indigo",name:"Indigo",color:"#4B0082"},{id:"teal",name:"Teal",color:"#39CCCC"},{id:"coral",name:"Coral",color:"#FF6B6B"}],Xl=({element:e,onElementUpdate:t,documentColors:r,imageColors:o,showUngroupButton:s=!1,onUngroup:i,onMoveForward:a,onMoveBackward:c,onOpenShapeTypeDrawer:d,onDelete:u,rotationExpanded:h=!1,onRotationToggle:f,cornerRadiusExpanded:p=!1,onCornerRadiusToggle:g,transparencyExpanded:b=!1,onTransparencyToggle:x,sidesExpanded:y=!1,onSidesToggle:v,pointsExpanded:w=!1,onPointsToggle:C,innerRadiusExpanded:j=!1,onInnerRadiusToggle:M,colorExpanded:S=!1,onColorToggle:R,strokeExpanded:I=!1,onStrokeToggle:D,knockoutExpanded:E=!1,onKnockoutToggle:O,distressTextureExpanded:z=!1,onDistressTextureToggle:_,imageMaskExpanded:k=!1,onImageMaskToggle:Y})=>{const[B,G]=l.useState(!1),[se,A]=l.useState(!1),[Z,J]=l.useState(!1),[q,ae]=l.useState(!1),[Le,pe]=l.useState(!1),[U,W]=l.useState(!1),[Ie,ke]=l.useState(!1),[Ke,re]=l.useState(!1),[te,he]=l.useState(!1),[ye,we]=l.useState(!1),[Pe,me]=l.useState(!1),[N,ce]=l.useState(!1),[le,Me]=l.useState(!1),ge=l.useMemo(()=>$s.map(pt=>pt.color),[]),L=l.useMemo(()=>r&&r.length>0?r:ge,[r,ge]),ve=Uo(e),tt=pt=>{const st=e.clone();st.transformData.fillColor=pt.target.value,t(st)},Ve={rectangle:"Rectangle",circle:"Circle",ellipse:"Ellipse",triangle:"Triangle",polygon:"Polygon",star:"Star",line:"Line"},oe=e.transformData.shapeType,ie=Ve[oe]||"Shape";return n.jsxs("div",{className:"toolbar-items",children:[d&&n.jsx(ct,{icon:Re.shapes,onClick:()=>{A(!0),d()},onMouseLeave:()=>A(!1),tooltip:`Change Shape (${ie})`,tooltipDisabled:se}),R?n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn",onClick:()=>{he(!0),R()},onMouseLeave:()=>he(!1),"aria-label":"Fill Color","data-active":S,children:n.jsx("div",{className:"h-6 w-6 rounded-md border border-border-primary",style:{backgroundColor:e.transformData.fillColor||"#3b82f6"}})})}),!te&&!S&&n.jsx(m.TooltipContent,{children:"Fill Color"})]}):n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(lr,{value:e.transformData.fillColor||"#3b82f6",onChange:tt,documentColors:L,imageColors:o,showSquare:!0})})}),n.jsx(m.TooltipContent,{children:"Fill Color"})]}),e.transformData.shapeType==="rectangle"&&g&&n.jsx(ct,{icon:"lucide:square-round-corner",onClick:()=>{ae(!0),g()},onMouseLeave:()=>ae(!1),tooltip:"Corner Radius",tooltipDisabled:q||p,active:p||ve.cornerRadius}),e.transformData.shapeType==="polygon"&&v&&n.jsx(ct,{icon:"healthicons:polygon",onClick:()=>{W(!0),v()},onMouseLeave:()=>W(!1),tooltip:"Sides",tooltipDisabled:U||y,active:y}),e.transformData.shapeType==="star"&&C&&n.jsx(ct,{icon:"material-symbols:award-star-outline",onClick:()=>{ke(!0),C()},onMouseLeave:()=>ke(!1),tooltip:"Points",tooltipDisabled:Ie||w,active:w}),e.transformData.shapeType==="star"&&M&&n.jsx(ct,{icon:"lucide:circle-dashed",onClick:()=>{re(!0),M()},onMouseLeave:()=>re(!1),tooltip:"Inner Radius",tooltipDisabled:Ke||j,active:j}),x&&n.jsx(ct,{icon:"lucide:blend",onClick:()=>{pe(!0),x()},onMouseLeave:()=>pe(!1),tooltip:"Transparency",tooltipDisabled:Le||b,active:b||ve.shapeTransparency}),f&&n.jsx(ct,{icon:n.jsx(_o,{size:20,className:"md:size-5"}),onClick:()=>{J(!0),f()},onMouseLeave:()=>J(!1),tooltip:"Rotate",tooltipDisabled:Z||h,active:h||ve.rotation}),O&&n.jsx(ct,{icon:"lucide:scissors",onClick:()=>{me(!0),O()},onMouseLeave:()=>me(!1),tooltip:"Clip / Knockout",tooltipDisabled:Pe||E,active:E||ve.knockout}),_&&n.jsx(ct,{icon:"lucide:stamp",onClick:()=>{ce(!0),_()},onMouseLeave:()=>ce(!1),tooltip:"Distress Texture",tooltipDisabled:N||z,active:z||ve.distress}),Y&&n.jsx(ct,{icon:"lucide:venetian-mask",onClick:()=>{Me(!0),Y()},onMouseLeave:()=>Me(!1),tooltip:"Image Mask",tooltipDisabled:le||k,active:k||ve.imageMask}),D&&n.jsx(ct,{icon:"lucide:pen-line",onClick:()=>{we(!0),D()},onMouseLeave:()=>we(!1),tooltip:"Stroke",tooltipDisabled:ye||I,active:I||ve.stroke}),(a||c||u)&&n.jsxs(m.Popover,{open:B,onOpenChange:G,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn","aria-label":"More options",children:n.jsx(de,{icon:"lucide:ellipsis-vertical",className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"end",className:"w-auto p-1",maxZIndex:!0,children:n.jsxs("div",{className:"flex items-center gap-1",children:[a&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{a(),G(!1)},"aria-label":"Move Forward",children:n.jsx(de,{icon:"hugeicons:layer-bring-forward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Forward"})]}),c&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{c(),G(!1)},"aria-label":"Move Backward",children:n.jsx(de,{icon:"hugeicons:layer-send-backward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Backward"})]}),u&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{G(!1),u()},"aria-label":"Delete",children:n.jsx(de,{icon:Re.trash,className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Delete"})]})]})})]}),s&&i&&n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"sm",onClick:i,children:"Ungroup"})}),n.jsx(m.TooltipContent,{children:"Ungroup this group"})]})]})},Dm=({className:e})=>n.jsx("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:n.jsx("path",{d:"M12 2L21 8L18 19L6 19L3 8L12 2Z"})}),Lm=({className:e})=>n.jsx("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":!0,children:n.jsx("ellipse",{cx:"12",cy:"12",rx:"9",ry:"6"})}),Us="size-10",Pm=[{id:"rectangle",label:"Rectangle",icon:"lucide:square"},{id:"circle",label:"Circle",icon:"lucide:circle"},{id:"ellipse",label:"Ellipse",reactIcon:n.jsx(Lm,{className:Us})},{id:"triangle",label:"Triangle",icon:"lucide:triangle"},{id:"polygon",label:"Polygon",reactIcon:n.jsx(Dm,{className:Us})},{id:"star",label:"Star",icon:"lucide:star"},{id:"line",label:"Line",icon:"lucide:minus"}],fi=({isOpen:e,onClose:t,onSelectType:r,currentType:o})=>{const s=o?"Change Shape":"Select Shape",i=o?"Select a new shape type":"Choose a shape to add",a=c=>{r(c),t()};return n.jsxs(oo,{isOpen:e,onClose:t,title:s,description:i,placement:"bottom",height:"auto",hideVisibleTitle:!0,showCloseButton:!1,"data-testid":"shape-type-drawer",children:[n.jsxs("div",{className:"px-6 pt-1 pb-2 flex items-center justify-between",children:[n.jsx("h3",{className:"text-lg font-semibold tracking-tight text-foreground",children:s}),n.jsx("button",{onClick:t,className:"size-11 rounded-full hover:bg-foreground/[0.06] flex items-center justify-center text-foreground/70 -mr-2","aria-label":"Close",children:n.jsx(de,{icon:Re.close,className:"size-5"})})]}),n.jsx("div",{className:"grid grid-cols-3 gap-2 p-4","data-testid":"shape-type-list",children:Pm.map(c=>{const d=c.id===o;return n.jsxs("button",{type:"button",onClick:()=>a(c.id),"aria-pressed":d,"data-testid":`shape-type-${c.id}`,className:`aspect-square flex flex-col items-center justify-center gap-2.5 rounded-xl border transition-colors ${d?"bg-primary/10 border-primary/40":"bg-transparent border-transparent hover:bg-foreground/[0.04] active:bg-foreground/[0.06]"}`,children:[n.jsx("span",{className:d?"text-primary":"text-foreground/85",children:c.reactIcon?c.reactIcon:n.jsx(de,{icon:c.icon,className:Us})}),n.jsx("span",{className:`text-xs ${d?"text-primary font-medium":"text-foreground/70"}`,children:c.label})]},c.id)})})]})},Vl=({element:e,onElementUpdate:t,onMoveForward:r,onMoveBackward:o})=>{const[s,i]=l.useState(!1),[a,c]=l.useState(!1),[d,u]=l.useState(!1),h=S=>{const R=e.clone();R.transformData.strokeColor=S,t(R),i(!1)},f=S=>{const R=e.clone();R.transformData.fillColor=S,t(R),c(!1)},p=()=>{const S=e.clone();S.transformData.strokeEnabled=!S.transformData.strokeEnabled,t(S)},g=()=>{const S=e.clone();S.transformData.fillEnabled=!S.transformData.fillEnabled,t(S)},b=S=>{const R=e.clone();R.transformData.strokeWidth=S,t(R)},x=e.transformData.strokeColor||"#000000",y=e.transformData.fillColor||"#3b82f6",v=e.transformData.strokeEnabled??!0,w=e.transformData.fillEnabled??!1,C=e.transformData.strokeWidth??2,j=e.transformData.closed,M=e.transformData.points.length;return n.jsxs("div",{className:"fixed top-3xl left-1/2 -translate-x-1/2 flex items-center gap-md px-xl py-md bg-bg-primary rounded-xl shadow-md",style:{zIndex:"var(--z-dropdown)"},children:[n.jsxs("div",{className:"px-xl text-base text-text-muted border-r border-border-primary",children:[n.jsx("span",{className:"font-semibold",children:"Path"}),n.jsxs("span",{className:"ml-md text-text-placeholder",children:[M," ",M===1?"point":"points",j&&" • Closed"]})]}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:v?"default":"ghost",onClick:p,className:"px-xl text-base",children:"Stroke"})}),n.jsx(m.TooltipContent,{children:v?"Disable Stroke":"Enable Stroke"})]}),v&&n.jsxs(m.Popover,{open:s,onOpenChange:i,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"w-8 h-8 p-xs rounded-md border-2 border-border-primary cursor-pointer transition-transform hover:scale-105",style:{background:x},title:"Stroke Color"})}),n.jsx(m.PopoverContent,{align:"start",className:"p-0",children:n.jsxs("div",{className:"bg-bg-primary rounded-xl shadow-lg p-6 min-w-[240px]",children:[n.jsx("div",{className:"grid grid-cols-6 gap-sm mb-md",children:$s.map(S=>n.jsx(m.Button,{onClick:()=>h(S.color),"aria-label":S.name,className:`w-8 h-8 rounded-md cursor-pointer transition-all min-h-0 min-w-0 p-0 ${x===S.color?"border-2 border-accent-primary scale-110":"border border-border-primary hover:scale-105"}`,style:{background:S.color}},S.color))}),n.jsx("input",{type:"color",value:x,onChange:S=>h(S.target.value),className:"w-full h-8 cursor-pointer rounded-md border border-border-primary"})]})})]}),v&&n.jsxs(m.Popover,{open:d,onOpenChange:u,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsxs(m.Button,{variant:"ghost",className:"px-xl text-base",children:[C,"px"]})}),n.jsx(m.PopoverContent,{align:"start",className:"p-0",children:n.jsx("div",{className:"bg-bg-primary rounded-xl shadow-lg p-6 min-w-[200px]",children:n.jsxs(m.Slider,{value:[C],onValueChange:S=>b(S[0]),min:1,max:20,step:.5,className:"slider-no-fill w-full",children:[n.jsx(m.Label,{children:"Width (px)"}),n.jsx(m.Slider.Output,{}),n.jsx(m.Slider.Track,{}),n.jsx(m.Slider.Thumb,{})]})})})]}),n.jsx("div",{className:"w-px h-6 bg-border-primary mx-xs"}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:w?"default":"ghost",onClick:g,className:"px-xl text-base",children:"Fill"})}),n.jsx(m.TooltipContent,{children:w?"Disable Fill":"Enable Fill"})]}),w&&n.jsxs(m.Popover,{open:a,onOpenChange:c,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"w-8 h-8 p-xs rounded-md border-2 border-border-primary cursor-pointer transition-transform hover:scale-105",style:{background:y},title:"Fill Color"})}),n.jsx(m.PopoverContent,{align:"start",className:"p-0",children:n.jsxs("div",{className:"bg-bg-primary rounded-xl shadow-lg p-6 min-w-[240px]",children:[n.jsx("div",{className:"grid grid-cols-6 gap-sm mb-md",children:$s.map(S=>n.jsx(m.Button,{onClick:()=>f(S.color),"aria-label":S.name,className:`w-8 h-8 rounded-md cursor-pointer transition-all min-h-0 min-w-0 p-0 ${y===S.color?"border-2 border-accent-primary scale-110":"border border-border-primary hover:scale-105"}`,style:{background:S.color}},S.color))}),n.jsx("input",{type:"color",value:y,onChange:S=>f(S.target.value),className:"w-full h-8 cursor-pointer rounded-md border border-border-primary"})]})})]}),n.jsx("div",{className:"w-px h-6 bg-border-primary mx-xs"}),r&&n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:r,children:n.jsx(de,{icon:"hugeicons:layer-bring-forward",className:"size-[18px]"})})}),n.jsx(m.TooltipContent,{children:"Move Forward"})]}),o&&n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:o,children:n.jsx(de,{icon:"hugeicons:layer-send-backward",className:"size-[18px]"})})}),n.jsx(m.TooltipContent,{children:"Move Backward"})]})]})},pi=l.memo(({backgroundType:e,backgroundColor:t,backgroundTexture:r,onBackgroundTypeChange:o,onColorChange:s,onTextureChange:i})=>{const[a,c]=l.useState(!1),[d,u]=l.useState("color"),[h,f]=l.useState(t);l.useEffect(()=>{u(e==="texture"?"texture":"color")},[e]),l.useEffect(()=>{t!=="transparent"&&f(t)},[t]);const p=w=>{f(w),s(w),o("color")},g=w=>{const C=w.target.value;f(C);const j=/^#?([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})$/,M=C.startsWith("#")?C:`#${C}`;j.test(M)&&(s(M),o("color"))},b=()=>{s("transparent"),o("transparent")},x=w=>{i(w),o("texture")},y=w=>{if(u(w),w==="color")o(t==="transparent"?"transparent":"color");else if(w==="texture"){if(!r){const C=rt.TextureManager.getAllTextures()[0];C&&i(C.id)}o("texture")}},v=t==="transparent";return n.jsxs(m.Popover,{open:a,onOpenChange:c,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:a?"default":"ghost","aria-label":"Background",children:n.jsx(de,{icon:Re.palette,className:"size-[18px]"})})}),n.jsx(m.PopoverContent,{className:"w-auto p-3",children:n.jsxs("div",{className:"flex min-w-[220px] flex-col gap-3",children:[n.jsxs("div",{className:"flex gap-1 border-b border-divider pb-3",children:[n.jsx(m.Button,{variant:"ghost",size:"sm",className:`flex-1 ${d==="color"?"bg-primary text-primary-foreground":""}`,onClick:()=>y("color"),children:"Color"}),n.jsx(m.Button,{variant:"ghost",size:"sm",className:`flex-1 ${d==="texture"?"bg-primary text-primary-foreground":""}`,onClick:()=>y("texture"),children:"Texture"}),n.jsx(m.Button,{variant:"ghost",size:"sm",className:"flex-1 cursor-not-allowed opacity-50",disabled:!0,"aria-label":"Gradient (Coming soon)",children:"Gradient"})]}),d==="color"&&n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsxs(m.Button,{variant:"ghost",className:`flex w-full cursor-pointer items-center justify-start gap-2 rounded-lg ${v?"bg-primary/10":""}`,onClick:b,children:[n.jsx("div",{className:"transparent-pattern-small h-6 w-6 rounded"}),n.jsx("span",{className:"text-sm font-medium",children:"Transparent"})]}),n.jsx(Fl,{color:v?"#ffffff":t,onChange:p}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("label",{htmlFor:"bg-hex-input",className:"text-sm font-medium uppercase text-foreground/60",children:"HEX"}),n.jsx("input",{id:"bg-hex-input",type:"text",className:"flex-1 rounded-lg border border-divider bg-field px-2 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none",value:h,onChange:g,placeholder:"#000000",maxLength:7})]})]}),d==="texture"&&n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("div",{className:"text-sm font-medium text-foreground/60",children:"Select a texture"}),n.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:rt.TextureManager.getAllTextures().map(w=>n.jsx("button",{className:`flex items-center justify-center p-1 rounded-lg cursor-pointer transition-all border-2 ${r===w.id?"border-primary":"border-transparent hover:border-primary/50"}`,onClick:()=>x(w.id),"aria-label":w.name,children:n.jsx("img",{src:w.url,alt:w.name,className:"w-full h-full rounded"})},w.id))})]}),d==="gradient"&&n.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-8 text-foreground/60",children:[n.jsx("div",{className:"text-sm",children:"Gradient backgrounds"}),n.jsx("div",{className:"text-xs",children:"Coming soon"})]})]})})]})});pi.displayName="BackgroundPickerDropdown";const Gl=({distressTexture:e,onChange:t})=>{rt.ensureBuiltinTexturesReady();const r=(e==null?void 0:e.enabled)||!1,o=(e==null?void 0:e.textureUrl)||"",s=(e==null?void 0:e.intensity)??50,i=rt.DISTRESS_TEXTURE_PRESETS.map(u=>({id:u.textureUrl,name:u.name,thumbnailUrl:u.thumbnailUrl})),a=u=>{if(u){const h=o||rt.DISTRESS_TEXTURE_PRESETS[0].textureUrl;rt.preloadTexture(h),t({enabled:!0,textureUrl:h,intensity:s})}else t(void 0)},c=l.useCallback(u=>{rt.preloadTexture(u),t({enabled:!0,textureUrl:u,intensity:s})},[t,s]),d=u=>{e&&t({...e,intensity:u[0]})};return n.jsxs(m.Disclosure,{open:r,onOpenChange:a,className:"mb-xl",children:[n.jsx(m.DisclosureTrigger,{className:"w-full",children:n.jsxs("div",{className:"flex items-center justify-between w-full",children:[n.jsx(m.Label,{children:"Distress Texture"}),n.jsx(m.Switch,{checked:r,onCheckedChange:a,onClick:u=>u.stopPropagation()})]})}),n.jsxs(m.DisclosureContent,{className:"flex flex-col gap-lg py-lg",children:[n.jsx(Ho,{presets:i,selectedId:o,onSelect:c,showOff:!1,ariaLabel:"Distress texture presets"}),n.jsx(sn,{label:"Intensity",value:s,onChange:u=>d([u]),min:0,max:100,step:1,unit:"%"})]})]})},Kl=({imageMask:e,onChange:t})=>{rt.ensureMaskPresetsReady();const r=(e==null?void 0:e.enabled)||!1,o=(e==null?void 0:e.imageUrl)||"",s=(e==null?void 0:e.maskType)||"clip",i=(e==null?void 0:e.opacity)??100,a=(e==null?void 0:e.inverted)??!1,c=rt.MASK_IMAGE_PRESETS.map(g=>({id:g.imageUrl,name:g.name,thumbnailUrl:g.thumbnailUrl})),d=g=>{if(g){const b=o||rt.MASK_IMAGE_PRESETS[0].imageUrl;t({enabled:!0,imageUrl:b,maskType:s,opacity:i,inverted:a})}else t(void 0)},u=l.useCallback(g=>{t({enabled:!0,imageUrl:g,maskType:s,opacity:i,inverted:a})},[t,s,i,a]),h=g=>{e&&t({...e,maskType:g})},f=g=>{e&&t({...e,opacity:g[0]})},p=g=>{e&&t({...e,inverted:g})};return n.jsxs(m.Disclosure,{open:r,onOpenChange:d,className:"mb-xl",children:[n.jsx(m.DisclosureTrigger,{className:"w-full",children:n.jsxs("div",{className:"flex items-center justify-between w-full",children:[n.jsx(m.Label,{children:"Image Mask"}),n.jsx(m.Switch,{checked:r,onCheckedChange:d,onClick:g=>g.stopPropagation()})]})}),n.jsxs(m.DisclosureContent,{className:"flex flex-col gap-lg py-lg",children:[n.jsx(Ho,{presets:c,selectedId:o,onSelect:u,showOff:!1,ariaLabel:"Image mask presets"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(m.Label,{className:"text-sm",children:"Type"}),n.jsx("div",{className:"flex rounded-md border border-divider overflow-hidden",children:["clip","alpha","luma"].map(g=>n.jsx("button",{className:`px-3 py-1 text-xs capitalize transition-colors ${s===g?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>h(g),children:g},g))})]}),n.jsx(sn,{label:"Opacity",value:i,onChange:g=>f([g]),min:0,max:100,step:1,unit:"%"}),n.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[n.jsx(m.Checkbox,{checked:a,onCheckedChange:g=>p(g===!0)}),"Invert Mask"]})]})]})},ql=({artboard:e,artboards:t,onArtboardUpdate:r,onRenameArtboard:o,onDeleteArtboard:s,artboardScreenBounds:i})=>{const[a,c]=l.useState(!1),[d,u]=l.useState(""),[h,f]=l.useState(!1),p=l.useRef(null),g=I=>{const D=e.clone();D.backgroundType=I,r(D)},b=I=>{const D=e.clone();D.backgroundColor=I,r(D)},x=I=>{const D=e.clone();D.backgroundTexture=I,r(D)},y=I=>{const D=e.clone();D.exportBackground=I,r(D)},v=I=>{const D=e.clone();D.distressTexture=I,r(D)},w=I=>{const D=e.clone();D.imageMask=I,r(D)},C=()=>{c(!0),u(e.name)},j=()=>{d.trim()&&o(e.id,d.trim()),c(!1),u("")},M=()=>{c(!1),u("")},S=I=>{I.key==="Enter"?j():I.key==="Escape"&&M()},R=()=>{if(t.length<=1){alert("Cannot delete the last artboard");return}e.getElementCount()>0&&!confirm(`Delete "${e.name}" with ${e.getElementCount()} element(s)?`)||s(e.id)};return l.useEffect(()=>{a&&p.current&&(p.current.focus(),p.current.select())},[a]),n.jsxs(m.Surface,{className:"absolute px-4 py-2 flex items-center gap-2 shadow-lg z-50 rounded-full bg-bg-primary border border-border-primary",style:{left:"50%",top:i?`${i.top-68}px`:"32px",transform:"translateX(-50%)"},children:[a?n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{ref:p,type:"text",value:d,onChange:I=>u(I.target.value),onKeyDown:S,className:"px-3 py-1 border border-border-primary rounded-lg text-base text-text-primary bg-bg-primary outline-none min-w-[120px] transition-colors focus:border-border-focus"}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:j,"aria-label":"Save",children:n.jsx(de,{icon:Re.check,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Save"})]}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:M,"aria-label":"Cancel",children:n.jsx(de,{icon:Re.close,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Cancel"})]})]}):n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xl font-semibold text-text-primary",children:e.name}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:C,"aria-label":"Rename",children:n.jsx(de,{icon:Re.pencil,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Rename"})]}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:R,disabled:t.length<=1,"aria-label":"Delete",children:n.jsx(de,{icon:Re.trash,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Delete"})]})]}),n.jsx(m.Separator,{orientation:"vertical",className:"h-6"}),n.jsx(pi,{backgroundType:e.backgroundType,backgroundColor:e.backgroundColor,backgroundTexture:e.backgroundTexture,onBackgroundTypeChange:g,onColorChange:b,onTextureChange:x}),n.jsx(m.Separator,{orientation:"vertical",className:"h-6"}),n.jsxs("div",{className:"text-base font-mono text-text-muted uppercase",children:[Math.round(e.width)," × ",Math.round(e.height)]}),n.jsx(m.Separator,{orientation:"vertical",className:"h-6"}),n.jsxs(m.Popover,{open:h,onOpenChange:f,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:h?"default":"ghost","aria-label":"More options",children:n.jsx(de,{icon:Re.menu,className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"end",children:n.jsxs("div",{className:"flex flex-col gap-2 min-w-[240px]",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(m.Switch,{checked:e.exportBackground,onCheckedChange:y}),n.jsx(m.Label,{children:"Export Background"})]}),n.jsx(m.Separator,{}),n.jsx(Gl,{distressTexture:e.distressTexture,onChange:v}),n.jsx(Kl,{imageMask:e.imageMask,onChange:w})]})})]})]})},Ia=T.createLogger("GoogleFontsService");let br=[],Ar=null;async function Fm(){return br.length>0?br:Ar||(Ar=fetch("/google-fonts.json").then(e=>{if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);return e.json()}).then(e=>(Array.isArray(e)?br=e.map(t=>({family:t.family,category:t.category||"sans-serif",subsets:t.subsets||[],variants:t.variants||[],popularity:t.popularity})):Ia.error("Unexpected API response structure:",e),br)).catch(e=>(Ia.error("Error fetching Google Fonts:",e),Ar=null,[])),Ar)}function ys(){return br}function zm(){return br.length>0}function Aa(e){return{"sans serif":"sans-serif",serif:"serif",display:"display",handwriting:"script",monospace:"monospace"}[e.toLowerCase()]||"display"}const Zl=[{canonical:"slab-serif",monotypeClassifications:["SLAB SERIF","CLARENDON SERIF"],googleCategory:"serif",displayName:"Slab Serif",description:"Bold, chunky serifs perfect for t-shirt designs"},{canonical:"decorative",monotypeClassifications:["BLACKLETTER","SPECIALIZED","DESIGN","DINGBATS","SYMBOL","ORNATE"],googleCategory:"display",displayName:"Decorative",description:"Artistic and ornate fonts for special effects"},{canonical:"display",monotypeClassifications:["DISPLAY","HIGH CONTRAST","GRAPHIC STYLE"],googleCategory:"display",displayName:"Display",description:"Eye-catching fonts for headlines and logos"},{canonical:"script",monotypeClassifications:["SCRIPT","FORMAL SCRIPT","INFORMAL SCRIPT","CASUAL SCRIPT","HANDWRITING"],googleCategory:"handwriting",displayName:"Script & Handwriting",description:"Calligraphy and handwritten styles"},{canonical:"monospace",monotypeClassifications:["MONOSPACED"],googleCategory:"monospace",displayName:"Monospace",description:"Fixed-width fonts for coding and technical text"},{canonical:"serif",monotypeClassifications:["SERIF","OLD STYLE SERIF","TRANSITIONAL SERIF","MODERN SERIF","NEOCLASSICAL","TRANSITIONAL"],googleCategory:"serif",displayName:"Serif",description:"Traditional fonts with decorative strokes at letter ends"},{canonical:"sans-serif",monotypeClassifications:["SANS SERIF","GEOMETRIC SANS","HUMANIST SANS","GROTESQUE SANS"],googleCategory:"sans-serif",displayName:"Sans Serif",description:"Clean, modern fonts without decorative strokes"}];function Om(e){const t=["slab-serif","decorative","display","script","monospace","serif","sans-serif"];for(const r of t){const o=Zl.find(s=>s.canonical===r);if(o&&e.some(i=>o.monotypeClassifications.includes(i)))return r}return"sans-serif"}function Jl(e){return Zl.find(t=>t.canonical===e)}function Bm(e){const t=Jl(e);return(t==null?void 0:t.monotypeClassifications)||[]}const yn=T.createLogger("Monotype");class _m{constructor(){this.accessToken=null,this.tokenExpiry=0,this.fonts=new Map,this.fontsLoaded=!1,this.webfontKits=new Map,this.searchCache=new Map,this.API_BASE="https://api.monotype.com",this.CACHE_TTL=24*60*60*1e3,this.monotypeEnabled=!1,this.loadCachesFromStorage(),this.monotypeEnabled=this.checkMonotypeEnabled()}checkMonotypeEnabled(){return!1}isMonotypeEnabled(){return this.monotypeEnabled}async authenticate(){}isAuthenticated(){return this.accessToken!==null&&Date.now()<this.tokenExpiry}async fetchAllFonts(){if(!this.monotypeEnabled){this.fontsLoaded=!0;return}const t=localStorage.getItem("monotype_fonts_cache");if(t)try{const{data:s,timestamp:i}=JSON.parse(t);if(Date.now()-i<this.CACHE_TTL){this.fonts=new Map(s),this.fontsLoaded=!0;return}}catch(s){yn.error("Failed to parse font cache:",s)}try{await this.authenticate()}catch(s){throw yn.error("Authentication failed, cannot fetch fonts:",s),s}if(!this.accessToken){const s=new Error("No access token available after authentication");throw yn.error(s.message),s}const r=["SANS SERIF","SERIF","SCRIPT","DISPLAY","SLAB SERIF","MONOSPACED","HANDWRITING","BLACKLETTER"],o=new Map;for(const s of r)try{let i=null,a=0;do{const c=await this.searchFontsRaw({classification:[s],pageSize:50,pageId:i||void 0});c.fonts.forEach(d=>{o.has(d.fontId)||o.set(d.fontId,d)}),i=c.nextPageId||null,a++}while(i)}catch(i){yn.error(`Failed to fetch ${s} fonts:`,i)}this.fonts=o,this.fontsLoaded=!0;try{localStorage.setItem("monotype_fonts_cache",JSON.stringify({data:Array.from(o.entries()),timestamp:Date.now()}))}catch(s){yn.error("Failed to cache fonts:",s)}}getAllFonts(){return Array.from(this.fonts.values())}isFontsLoaded(){return this.fontsLoaded}async searchFontsRaw(t){if(await this.authenticate(),!this.accessToken)return yn.warn("Cannot search fonts: No access token available"),{fonts:[]};try{const r=await fetch(`${this.API_BASE}/v1/fonts/search`,{method:"POST",headers:{Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const s=await r.text();let i;try{i=JSON.parse(s)}catch{i=s}throw yn.error("Font search failed:",{status:r.status,statusText:r.statusText,error:i,params:t}),new Error(`Search failed: ${r.status} ${r.statusText}`)}const o=await r.json();return{fonts:o.fonts||[],nextPageId:o.nextPageId,totalCount:o.totalCount}}catch(r){return yn.error("Font search failed:",r),{fonts:[]}}}async searchFonts(t){const r=JSON.stringify(t);if(this.searchCache.has(r))return this.searchCache.get(r);const o=await this.searchFontsRaw(t),s=this.groupMonotypeFontsByFamily(o.fonts);return this.searchCache.set(r,s),s}async searchFontsByName(t){return t.trim()?this.searchFonts({name:t,searchSettings:{fuzzy:["name"]},pageSize:50}):this.groupMonotypeFontsByFamily(this.getAllFonts())}async filterFontsByCategory(t){if(t==="system")return[];const r=Bm(t);return r.length===0?[]:this.searchFonts({classification:r,pageSize:50})}groupMonotypeFontsByFamily(t){const r=new Map;return t.forEach(o=>{const s=o.family||o.name;r.has(s)||r.set(s,[]),r.get(s).push(o)}),Array.from(r.entries()).map(([o,s])=>{const i=s[0];return{name:o.replace(/[™®]/g,"").trim(),category:Om(i.classification||[]),monotypeFont:!0,googleFont:!1,monotypeId:i.fontId,source:"monotype",foundry:i.foundry,weights:this.extractWeights(s),tags:i.tag||[],preview:i.sample}})}extractWeights(t){const r=new Set;return t.forEach(o=>{o.weightCSS&&r.add(o.weightCSS)}),Array.from(r).sort()}async getWebFontKit(t,r){var s;if(this.webfontKits.has(t))return this.webfontKits.get(t);const o=localStorage.getItem("monotype_webfont_kits");if(o)try{const i=new Map(JSON.parse(o));if(i.has(t)){const a=i.get(t);return this.webfontKits.set(t,a),a}}catch(i){yn.error("Failed to parse webfont kit cache:",i)}if(await this.authenticate(),!this.accessToken)throw new Error("Not authenticated - no access token available");try{const i=await fetch(`${this.API_BASE}/v1/webfonts/kit`,{method:"POST",headers:{Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify({kitName:`MonotypeFontKit_${t.substring(0,8)}`,kitType:"Embed",fontFormats:["WOFF2","WOFF"],fonts:[{fontId:t}],includeDefaultWordpressFiles:!1})});if(!i.ok){const d=await i.text();let u;try{u=JSON.parse(d)}catch{u=d}throw yn.error("WebFont kit generation failed:",{status:i.status,statusText:i.statusText,error:u,fontId:t,fontFamily:r}),new Error(`Kit generation failed: ${i.status} ${i.statusText}`)}const a=await i.json(),c={fontFamily:((s=a.webFonts[0])==null?void 0:s.fontFamily)||r,cssUrl:a.kitUrl,timestamp:Date.now()};return this.webfontKits.set(t,c),this.saveCachesToStorage(),c}catch(i){throw yn.error("Failed to generate WebFont kit:",i),i}}async loadMonotypeFont(t,r){try{const o=await this.getWebFontKit(t,r),s=`monotype-font-${t}`;if(document.getElementById(s))return;const i=document.createElement("link");i.id=s,i.rel="stylesheet",i.href=o.cssUrl,document.head.appendChild(i),await document.fonts.ready}catch(o){throw yn.error(`Failed to load Monotype font ${r}:`,o),o}}loadCachesFromStorage(){if(!(typeof window>"u"))try{const t=localStorage.getItem("monotype_webfont_kits");t&&(this.webfontKits=new Map(JSON.parse(t)))}catch(t){yn.error("Failed to load caches:",t)}}saveCachesToStorage(){if(!(typeof window>"u"))try{localStorage.setItem("monotype_webfont_kits",JSON.stringify(Array.from(this.webfontKits.entries())))}catch(t){yn.error("Failed to save caches:",t)}}clearCaches(){this.fonts.clear(),this.webfontKits.clear(),this.searchCache.clear(),this.fontsLoaded=!1,this.accessToken=null,this.tokenExpiry=0,localStorage.removeItem("monotype_fonts_cache"),localStorage.removeItem("monotype_webfont_kits")}getStats(){return{monotypeEnabled:this.monotypeEnabled,authenticated:this.isAuthenticated(),hasAccessToken:!!this.accessToken,tokenExpiry:this.tokenExpiry>0?new Date(this.tokenExpiry).toISOString():null,fontsLoaded:this.fontsLoaded,fontCount:this.fonts.size,familyCount:this.groupMonotypeFontsByFamily(this.getAllFonts()).length,webfontKitCount:this.webfontKits.size,searchCacheSize:this.searchCache.size}}}const Dn=new _m,vs=T.createLogger("UnifiedFontService");class Hm{constructor(){this.searchCache=new Map,this.previewFontLinks=new Set}async initialize(){try{if(await Fm(),Dn.isMonotypeEnabled())try{await Dn.authenticate(),await Dn.fetchAllFonts()}catch(t){vs.warn("Monotype fonts failed to load (continuing with Google Fonts only):",t)}}catch(t){vs.error("Failed to initialize UnifiedFontService:",t)}}isFontsLoaded(){return zm()||Dn.isFontsLoaded()}isMonotypeEnabled(){return Dn.isMonotypeEnabled()}getAllFonts(){const t=T.TSHIRT_FONTS.filter(s=>!s.googleFont&&!s.monotypeFont),r=this.mapGoogleFonts(ys()),o=Dn.groupMonotypeFontsByFamily(Dn.getAllFonts());return this.mergeFonts([...t,...r,...o])}getRecommendedFonts(){return T.TSHIRT_FONTS}async searchFontsByName(t){if(!t.trim())return this.getAllFonts();const r=`search:${t.toLowerCase()}`;if(this.searchCache.has(r))return this.searchCache.get(r);const o=t.toLowerCase().trim(),s=ys().filter(c=>c.family.toLowerCase().includes(o)).map(c=>this.mapGoogleFont(c)),i=await Dn.searchFontsByName(t),a=this.mergeFonts([...s,...i]);return this.searchCache.set(r,a),a}async filterFontsByCategory(t){if(t==="system")return T.TSHIRT_FONTS.filter(c=>!c.googleFont&&!c.monotypeFont);const r=`category:${t}`;if(this.searchCache.has(r))return this.searchCache.get(r);if(!Jl(t))return[];const s=ys().filter(c=>Aa(c.category)===t).map(c=>this.mapGoogleFont(c)),i=await Dn.filterFontsByCategory(t),a=this.mergeFonts([...s,...i]);return this.searchCache.set(r,a),a}async searchAndFilterFonts(t,r){return t.trim()?this.searchFontsByName(t):r!=="all"?this.filterFontsByCategory(r):this.getAllFonts()}async loadFont(t){try{t.googleFont&&!t.monotypeFont?this.loadGoogleFont(t.name):t.monotypeFont&&t.monotypeId&&await Dn.loadMonotypeFont(t.monotypeId,t.name)}catch(r){vs.error(`Failed to load font ${t.name}:`,r)}}loadGoogleFont(t){const r=`font-${t.replace(/\s+/g,"-").toLowerCase()}`;if(document.getElementById(r))return;const o=document.createElement("link");o.id=r,o.rel="stylesheet",o.href=`https://fonts.googleapis.com/css2?family=${t.replace(/\s+/g,"+")}:wght@400;700&display=swap`,document.head.appendChild(o)}loadGoogleFontForPreview(t,r){const o=encodeURIComponent(r),s=`font-preview-${t.replace(/\s+/g,"-").toLowerCase()}`;if(document.getElementById(s))return;const i=document.createElement("link");i.id=s,i.rel="stylesheet",i.href=`https://fonts.googleapis.com/css2?family=${t.replace(/\s+/g,"+")}&display=swap&text=${o}`,document.head.appendChild(i),this.previewFontLinks.add(s)}clearPreviewFonts(){this.previewFontLinks.forEach(t=>{const r=document.getElementById(t);r&&r.remove()}),this.previewFontLinks.clear()}getPreviewFontCount(){return this.previewFontLinks.size}mapGoogleFont(t){var r;return{name:t.family,category:Aa(t.category),googleFont:!0,monotypeFont:!1,source:"google",weights:((r=t.variants)==null?void 0:r.map(o=>{const s=o.match(/\d+/);return s?parseInt(s[0],10):o==="regular"?400:null}).filter(o=>o!==null))||[400]}}mapGoogleFonts(t){return t.map(r=>this.mapGoogleFont(r))}mergeFonts(t){const r=new Map;return t.forEach(o=>{const s=o.name.toLowerCase().trim();if(!r.has(s))r.set(s,o);else{const i=r.get(s);o.monotypeFont&&!i.monotypeFont&&r.set(s,o)}}),Array.from(r.values()).sort((o,s)=>o.name.localeCompare(s.name))}clearSearchCache(){this.searchCache.clear()}clearAllCaches(){this.clearSearchCache(),Dn.clearCaches()}getStats(){const t=this.getAllFonts(),r=t.filter(i=>i.googleFont&&!i.monotypeFont),o=t.filter(i=>i.monotypeFont),s=t.filter(i=>!i.googleFont&&!i.monotypeFont);return{initialized:this.isFontsLoaded(),monotypeEnabled:this.isMonotypeEnabled(),totalFonts:t.length,googleFontsCount:r.length,monotopeFontsCount:o.length,systemFontsCount:s.length,searchCacheSize:this.searchCache.size,monotypeStats:Dn.getStats()}}}const On=new Hm;function $m(e){return Array.from(e).filter(t=>{const r=t.codePointAt(0);return!r||r<983040||r>1048573}).join("")}const ws=T.createLogger("FontBrowserDrawer"),Ql=({value:e,onChange:t,fontFamilies:r,isOpen:o,onToggle:s,showLabel:i,previewText:a,elements:c})=>{const d=l.useRef(null),[u,h]=l.useState(""),[f,p]=l.useState("all"),[g,b]=l.useState(0),[x,y]=l.useState("name"),[v,w]=l.useState("medium"),[C,j]=l.useState("masonry"),[M,S]=l.useState(new Set),R=l.useRef([]),I=l.useRef(!1),E=(A=>{switch(A){case"small":return 1;case"medium":return 1.8;case"large":return 3}})(v);l.useEffect(()=>{const A="font-preview-style";if(!document.getElementById(A)){const Z=document.createElement("style");Z.id=A,Z.textContent=".font-preview { font-family: var(--font-preview) !important; }",document.head.appendChild(Z)}},[]),l.useEffect(()=>{On.isFontsLoaded()||On.initialize().then(()=>{b(A=>A+1)}).catch(A=>{ws.error("Failed to load fonts:",A)})},[]);const O=async(A,Z=!1)=>{try{if(Z)await On.loadFont(A);else if(A.googleFont&&!A.monotypeFont){const J=a?`${a}${A.name}`:A.name;On.loadGoogleFontForPreview(A.name,J)}else await On.loadFont(A);S(J=>new Set(J).add(A.name))}catch(J){ws.error(`Failed to load font ${A.name}:`,J)}};l.useEffect(()=>{(async()=>{if(I.current||R.current.length===0)return;I.current=!0;const Z=[...R.current];R.current=[];const J=On.getAllFonts();await Promise.all(Z.map(async q=>{const ae=J.find(Le=>Le.name===q);ae&&!M.has(q)&&await O(ae)})),I.current=!1})()},[M]);const z=A=>{const Z=M.has(A),J=R.current.includes(A);!Z&&!J&&(R.current.push(A),!I.current&&R.current.length===1&&S(q=>new Set(q)))};l.useEffect(()=>{o&&setTimeout(()=>{d.current&&d.current.scrollIntoView({behavior:"smooth",block:"center"})},150),o||(h(""),p("all"),On.clearPreviewFonts(),S(new Set))},[o,e]),l.useEffect(()=>{if(e&&!M.has(e)){const Z=On.getAllFonts().find(J=>J.name===e);Z&&O(Z,!0)}},[e,M,g]),l.useEffect(()=>{u.trim()&&p("all")},[u]);const _=async A=>{const J=On.getAllFonts().find(q=>q.name===A);if(J)try{await O(J,!0)}catch{ws.warn(`Failed to load font ${A}, will use fallback`)}t({target:{value:A}}),setTimeout(()=>s(!1),0)},k=l.memo(({font:A,isUsedInDocument:Z=!1})=>{const J=l.useRef(null),q=e===A.name,ae=M.has(A.name),Le=A.monotypeFont===!0;l.useEffect(()=>{if(!J.current)return;const ke=new IntersectionObserver(Ke=>{Ke.forEach(re=>{re.isIntersecting&&!ae&&z(A.name)})},{rootMargin:"600px"});return ke.observe(J.current),()=>ke.disconnect()},[A.name,ae]);let pe="",U=!1;x==="name"?(pe=A.name,U=!1):x==="preview"?(pe=a||A.name,U=Z):(pe=a||A.name,U=!0);const W=x==="preview"&&!U,Ie=n.jsxs(m.Surface,{ref:ke=>{q&&d&&(d.current=ke),J.current=ke},className:`relative flex cursor-pointer flex-col justify-center rounded-lg border-2 text-left ${C==="masonry"?"w-fit":"min-w-0"} ${q?"border-accent":"hover:border-muted border-transparent"}`,onClick:W?void 0:()=>_(A.name),role:W?void 0:"button","aria-label":W?void 0:`Select ${A.name} font`,tabIndex:W?void 0:0,onKeyDown:W?void 0:ke=>{(ke.key==="Enter"||ke.key===" ")&&(ke.preventDefault(),_(A.name))},style:{minHeight:`${U?48*E:36*E}px`,padding:`${6*E}px ${10*E}px`,gap:`${2*E}px`},children:[!ae&&n.jsx("div",{className:"absolute inset-0 rounded-lg bg-gray-100",style:{opacity:.5}}),n.jsx("div",{className:"font-preview text-foreground overflow-hidden leading-[1.1] font-medium text-ellipsis whitespace-nowrap",style:{"--font-preview":ae?`"${A.name}", sans-serif`:"sans-serif",fontSize:`${15*E}px`,opacity:ae?1:.4},children:pe}),U&&n.jsx("div",{className:"text-muted overflow-hidden font-sans leading-[1.1] font-normal text-ellipsis whitespace-nowrap",style:{fontSize:`${7*E}px`,opacity:ae?1:.4},children:A.name}),Le&&n.jsx("div",{className:"absolute rounded-full bg-orange-500",style:{top:`${4*E}px`,right:`${4*E}px`,width:`${6*E}px`,height:`${6*E}px`},title:"Premium Monotype Font"})]});return W?n.jsxs(m.Tooltip,{delayDuration:200,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{className:"m-0 inline-block h-auto min-h-0 border-0 bg-transparent p-0 hover:bg-transparent",style:{width:C==="masonry"?"auto":"100%"},onClick:()=>_(A.name),"aria-label":`Select ${A.name} font`,children:n.jsxs(m.Surface,{ref:ke=>{q&&d&&(d.current=ke),J.current=ke},className:`relative flex cursor-pointer flex-col justify-center rounded-lg border-2 text-left ${C==="masonry"?"w-fit":"min-w-0"} ${q?"border-accent":"hover:border-muted border-transparent"}`,style:{minHeight:`${U?48*E:36*E}px`,padding:`${6*E}px ${10*E}px`,gap:`${2*E}px`},children:[!ae&&n.jsx("div",{className:"absolute inset-0 rounded-lg bg-gray-100",style:{opacity:.5}}),n.jsx("div",{className:"font-preview text-foreground overflow-hidden leading-[1.1] font-medium text-ellipsis whitespace-nowrap",style:{"--font-preview":ae?`"${A.name}", sans-serif`:"sans-serif",fontSize:`${15*E}px`,opacity:ae?1:.4},children:pe}),U&&n.jsx("div",{className:"text-muted overflow-hidden font-sans leading-[1.1] font-normal text-ellipsis whitespace-nowrap",style:{fontSize:`${7*E}px`,opacity:ae?1:.4},children:A.name}),Le&&n.jsx("div",{className:"absolute rounded-full bg-orange-500",style:{top:`${4*E}px`,right:`${4*E}px`,width:`${6*E}px`,height:`${6*E}px`},title:"Premium Monotype Font"})]})})}),n.jsx(m.TooltipContent,{side:"top",children:n.jsx("p",{children:A.name})})]},A.name):n.jsx(l.Fragment,{children:Ie},A.name)},(A,Z)=>A.font.name===Z.font.name&&A.isUsedInDocument===Z.isUsedInDocument),Y=l.useMemo(()=>{if(!c)return new Set;const A=new Set,Z=J=>{const q=J.fontFamily,ae=J.text;q&&ae&&$m(ae).trim().length>0&&A.add(q)};return c.forEach(J=>{Z(J),J.children&&Array.isArray(J.children)&&J.children.forEach(q=>{Z(q)})}),A},[c]),B=l.useMemo(()=>{const A=On.isFontsLoaded()?On.getAllFonts():T.TSHIRT_FONTS,Z=new Set(T.TSHIRT_FONTS.map(pe=>pe.name)),J=[];A.forEach(pe=>{if(Y.has(pe.name))if(u){const U=u.toLowerCase();pe.name.toLowerCase().includes(U)&&J.push(pe)}else J.push(pe)});let q=A.filter(pe=>!Y.has(pe.name));if(f!=="all"&&(q=q.filter(pe=>pe.category===f)),u){const pe=u.toLowerCase();q=q.filter(U=>U.name.toLowerCase().includes(pe))}const ae=[],Le=[];return q.forEach(pe=>{Z.has(pe.name)?ae.push(pe):Le.push(pe)}),J.sort((pe,U)=>pe.name.localeCompare(U.name)),ae.sort((pe,U)=>pe.name.localeCompare(U.name)),Le.sort((pe,U)=>pe.name.localeCompare(U.name)),{usedFonts:J,recommendedFonts:ae,otherFonts:Le}},[u,f,g,Y]),G=(A,Z=!1)=>C==="masonry"?n.jsx("div",{className:"flex flex-wrap content-start items-start gap-2 px-4 pb-4",children:A.map(J=>n.jsx(k,{font:J,isUsedInDocument:Z},J.name))}):n.jsx("div",{className:"px-4 pb-4",style:{display:"grid",gridTemplateColumns:`repeat(auto-fill, minmax(${140*E}px, 1fr))`,gap:"8px"},children:A.map(J=>n.jsx(k,{font:J,isUsedInDocument:Z},J.name))}),se=["all","system","display","sans-serif","script","serif","slab-serif","vintage","decorative","monospace"];return n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>s(!o),className:`h-11 md:h-9 w-[132px] md:w-[108px] flex items-center justify-center px-2 text-foreground cursor-pointer rounded-lg border border-transparent text-base font-medium transition-all hover:bg-black/5 dark:hover:bg-white/5 ${o?"bg-black/10 dark:bg-white/10":"bg-transparent"}`,"aria-label":o?"Close font browser":"Open font browser",title:e,children:n.jsx("span",{className:"font-preview overflow-hidden text-ellipsis whitespace-nowrap min-w-0",style:{"--font-preview":`"${e}", sans-serif`,fontWeight:400},children:e})}),n.jsx(oo,{isOpen:o,onClose:()=>s(!1),title:"Fonts",description:"",height:"85vh",placement:"bottom",showCloseButton:!1,hideVisibleTitle:!0,hideHandle:!0,disableScrollWrapper:!0,children:n.jsx("div",{className:"relative flex-1 overflow-hidden",children:n.jsx("div",{className:"h-full bg-white",children:n.jsxs("div",{className:"h-full overflow-y-auto",children:[n.jsx("div",{className:"px-4 pt-5",children:n.jsxs(m.Surface,{className:"flex gap-2",children:[n.jsx(m.TextField,{className:"flex-1","aria-label":"Search fonts",children:n.jsx(m.Input,{type:"text",className:"rounded-2xl pt-[10px] pb-[9px]",placeholder:"Search fonts...",value:u,onChange:A=>h(A.target.value),autoFocus:!0,"aria-label":"Search fonts"})}),n.jsx(m.Tabs,{value:v,onValueChange:A=>w(A),children:n.jsx(m.Tabs.ListContainer,{children:n.jsxs(m.Tabs.List,{"aria-label":"Card size",children:[n.jsxs(m.Tabs.Tab,{id:"small",className:"text-xs font-semibold","aria-label":"Small card size",children:["A",n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"medium",className:"text-base font-semibold","aria-label":"Medium card size",children:["A",n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"large",className:"text-xl font-semibold","aria-label":"Large card size",children:["A",n.jsx(m.Tabs.Indicator,{})]})]})})}),n.jsx(m.Button,{variant:"secondary",onClick:()=>{y(A=>A==="both"?"name":A==="name"?"preview":"both")},"aria-label":x==="both"?"Show font name only":x==="name"?"Show preview only":"Show preview with font name",className:"h-10 w-10 p-0",children:x==="both"?n.jsx(de,{icon:"lucide:credit-card",className:"size-[22px]"}):x==="name"?n.jsx(de,{icon:"lucide:type",className:"size-[22px]"}):n.jsx(de,{icon:"lucide:text-cursor",className:"size-[22px]"})}),n.jsx(m.Button,{variant:"secondary",onClick:()=>j(C==="grid"?"masonry":"grid"),"aria-label":C==="grid"?"Switch to masonry view":"Switch to grid view",className:"h-10 w-10 p-0",children:C==="grid"?n.jsx(de,{icon:"lucide:grid-2x2",className:"size-[22px]"}):n.jsx(de,{icon:"lucide:grid-3x3",className:"size-[22px]"})})]})}),n.jsxs("div",{className:"sticky top-0 z-20 shrink-0",children:[n.jsx("div",{className:"pointer-events-none absolute top-0 right-0 left-0",style:{height:"64px",background:"linear-gradient(to bottom, var(--background) 0%, color-mix(in srgb, var(--background) 80%, transparent) 40%, transparent 100%)",zIndex:16}}),n.jsx("div",{className:"relative z-20 px-4 py-4 pt-3",children:n.jsx("div",{className:"flex gap-2 overflow-x-auto",children:se.map(A=>{const Z=A==="all"?"All":T.CATEGORY_LABELS[A];return n.jsx(m.Button,{size:"sm",variant:f===A?"default":"secondary",onClick:()=>p(A),className:`shrink-0 ${f===A?"":"hover:brightness-95"}`,children:Z},A)})})})]}),n.jsxs("div",{className:"flex-1",children:[B.usedFonts.length>0&&n.jsxs("div",{className:"shrink-0 p-0",children:[n.jsx("div",{className:"text-muted bg-white px-4 pt-2 pb-2 text-xs font-bold tracking-wider uppercase",children:"Used in Document"}),G(B.usedFonts,!0)]}),B.recommendedFonts.length===0&&B.otherFonts.length===0?n.jsx("div",{className:"text-muted col-span-full px-4 py-8 text-center text-sm",children:"No fonts found"}):n.jsxs(n.Fragment,{children:[B.recommendedFonts.length>0&&n.jsxs("div",{className:"p-0",children:[n.jsx("div",{className:"text-muted bg-white px-4 pt-2 pb-2 text-xs font-bold tracking-wider uppercase",children:"Recommended"}),G(B.recommendedFonts)]}),B.otherFonts.length>0&&n.jsxs("div",{className:"p-0",children:[n.jsx("div",{className:"text-muted bg-white px-4 pt-4 pb-2 text-xs font-bold tracking-wider uppercase",children:"All Fonts"}),G(B.otherFonts)]})]})]})]})})})})]})},Um=T.createLogger("TransformControlPanel"),ec=({element:e,controls:t,onUpdate:r})=>{const[o,s]=l.useState({});return n.jsx("div",{className:"w-full space-y-4",children:t.map(i=>{const a=e.transformData[i.key]??i.defaultInternalValue??i.defaultValue;if(i.type==="checkbox")return n.jsxs("div",{className:"flex items-center space-x-2",children:[n.jsx(m.Switch,{id:`control-${i.key}`,checked:a,onCheckedChange:f=>{const p=e.clone();p.transformData[i.key]=f,r(p)}}),n.jsx(m.Label,{htmlFor:`control-${i.key}`,children:i.label})]},i.key);const c=typeof a=="number"&&!isNaN(a)?a:i.defaultInternalValue??0,d=o[i.key]!==void 0?o[i.key]:c,u=i.toSlider?i.toSlider(d):d,h=f=>{const p=i.fromSlider?i.fromSlider(f):f;return typeof p!="number"||isNaN(p)?(Um.warn("Invalid internalValue:",p,"for control:",i.key),"0"):i.toDisplay?i.toDisplay(p):"isPercentage"in i&&i.isPercentage?`${(p*100).toFixed(0)}%`:p.toFixed(1)};return n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsxs("div",{className:"flex justify-between",children:[n.jsx(m.Label,{children:i.label}),n.jsx("span",{className:"text-sm text-foreground/60",children:h(u)})]}),n.jsx(m.Slider,{value:[u],onValueChange:f=>{const p=f[0],g=i.fromSlider?i.fromSlider(p):p;s(b=>({...b,[i.key]:g}))},onChangeEnd:f=>{const p=f[0],g=e.clone();g.transformData[i.key]=i.fromSlider?i.fromSlider(p):p,r(g),s(b=>{const x={...b};return delete x[i.key],x})},min:0,max:100,step:i.step??1,className:"slider-no-fill"})]},i.key)})})},Ym=({element:e,onTransformTypeChange:t,onElementUpdate:r,isOpen:o,onOpenChange:s})=>{const[i,a]=l.useState(!1),c=o!==void 0?o:i,d=s||a,u=e.transformType,h=T.getTransformControls(u),f=T.TRANSFORM_TYPES.filter(g=>g.Component&&g.id!=="image"&&g.id!=="group"&&g.id!=="shape"&&g.id!=="path"),p=g=>{g!==u&&t(g)};return n.jsxs(m.Popover,{open:c,onOpenChange:d,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn","aria-label":"Text Effects",children:n.jsx(de,{icon:Re.wand,className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"start",className:"w-[280px] p-0",maxZIndex:!0,children:n.jsxs("div",{className:"space-y-4 p-6",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(m.Label,{children:"Text Effect"}),n.jsxs(m.Select,{value:u,onValueChange:p,children:[n.jsx(m.SelectTrigger,{children:n.jsx(m.SelectValue,{placeholder:"Select effect"})}),n.jsx(m.SelectContent,{style:{zIndex:2147483647},children:f.map(g=>n.jsx(m.SelectItem,{value:g.id,children:g.label},g.id))})]})]}),h.length>0&&n.jsx(ec,{element:e,controls:h,onUpdate:r})]})})]})},tc=({items:e})=>{const[t,r]=l.useState(!1);return n.jsxs(m.Popover,{open:t,onOpenChange:r,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn","aria-label":"More options",children:n.jsx(de,{icon:Re.moreHorizontal,className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"start",className:"w-auto p-1",maxZIndex:!0,children:n.jsx("div",{className:"flex items-center gap-1",children:e.map((o,s)=>n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:o.active?"default":"ghost",size:"icon",onClick:()=>{o.onClick(),r(!1)},"aria-label":o.label,children:o.icon})}),n.jsx(m.TooltipContent,{children:o.label})]},s))})})]})};function nc({colorPickerValue:e,isActive:t,onClick:r}){return n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn",onClick:r,"aria-label":"Font Color","data-active":t,children:n.jsxs("div",{className:"relative flex h-5 w-5 items-center justify-center",children:[n.jsx("span",{className:"-translate-y-0.5 text-lg leading-none font-bold",children:"A"}),n.jsx("div",{className:"absolute bottom-0 left-1/2 h-[3px] w-4 -translate-x-1/2 rounded-sm",style:{backgroundColor:e}})]})})}),!t&&n.jsx(m.TooltipContent,{children:"Font Color"})]})}function rc({toolbar:e}){return n.jsx(ct,{icon:Re.bold,onClick:e.handleBoldToggle,active:e.getEffectiveStyle().bold,tooltip:"Bold"})}function oc({toolbar:e}){return n.jsx(ct,{icon:Re.italic,onClick:e.handleItalicToggle,active:e.getEffectiveStyle().italic,tooltip:"Italic"})}function sc({toolbar:e}){return n.jsx(ct,{icon:Re.underline,onClick:e.handleUnderlineToggle,active:e.getEffectiveStyle().underline,tooltip:"Underline"})}function ic({toolbar:e}){return n.jsx(ct,{icon:"lucide:case-upper",onClick:e.handleLetterCaseToggle,active:e.isLetterCaseActive(),tooltip:"Uppercase"})}function ac({toolbar:e}){const{textAlign:t,handleTextAlignToggle:r}=e,o=t==="left"?Re.alignLeft:t==="center"?Re.alignCenter:Re.alignRight;return n.jsx(ct,{icon:o,onClick:r,tooltip:`Align ${t.charAt(0).toUpperCase()+t.slice(1)}`})}function lc({onMoveForward:e,onMoveBackward:t,onDelete:r,onOpenChange:o}){const[s,i]=l.useState(!1),a=c=>{i(c),o==null||o(c)};return n.jsxs(m.Popover,{open:s,onOpenChange:a,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn","aria-label":"More options",children:n.jsx(de,{icon:"lucide:ellipsis-vertical",className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"end",className:"w-auto p-1",maxZIndex:!0,children:n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{e(),a(!1)},"aria-label":"Move Forward",children:n.jsx(de,{icon:"hugeicons:layer-bring-forward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Forward"})]}),n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{t(),a(!1)},"aria-label":"Move Backward",children:n.jsx(de,{icon:"hugeicons:layer-send-backward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Backward"})]}),n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{a(!1),r()},"aria-label":"Delete",children:n.jsx(de,{icon:Re.trash,className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Delete"})]})]})})]})}function cc({toolbar:e,stableElementId:t,viewportWidth:r=window.innerWidth,colorPickerValue:o,isColorActive:s,onColorToggle:i,onOpenGlyphBrowser:a,hasGlyphs:c=!1,expandedPanel:d,onRotationToggle:u,onOpacityToggle:h,onFontSizeToggle:f,strokeExpanded:p=!1,onStrokeToggle:g,knockoutExpanded:b=!1,onKnockoutToggle:x,distressTextureExpanded:y=!1,onDistressTextureToggle:v,imageMaskExpanded:w=!1,onImageMaskToggle:C,getMoreMenuItems:j,onMoveForward:M,onMoveBackward:S,onDelete:R,elementForProperties:I,elements:D,isTransformMenuOpen:E,onTransformMenuOpenChange:O,elementUpdateHandler:z,showUngroupButton:_=!1,onUngroup:k,isFontBrowserOpen:Y=!1,onFontBrowserToggle:B,onTextMoreMenuOpenChange:G}){const[se,A]=l.useState(!1),[Z,J]=l.useState(!1),[q,ae]=l.useState(!1),[Le,pe]=l.useState(!1),U=Uo(I),[W,Ie]=l.useState(!1),[ke,Ke]=l.useState(!1),[re,te]=l.useState(!1),[he,ye]=l.useState(!1);return n.jsxs("div",{className:"toolbar-items",children:[n.jsx(Ql,{value:e.getEffectiveStyle().fontFamily||e.fontFamily,onChange:we=>e.handleFontFamilyChange(we.target.value),fontFamilies:T.FONT_FAMILIES,isOpen:Y,onToggle:B,showLabel:r>700,previewText:"text"in I?I.text:void 0,elements:D}),n.jsx(ct,{icon:"lucide:a-large-small",onClick:()=>{pe(!0),f()},onMouseLeave:()=>pe(!1),tooltip:`Font Size · ${Math.round(e.fontSize)}`,tooltipDisabled:Le||(d==null?void 0:d.type)==="fontSize",active:(d==null?void 0:d.type)==="fontSize"}),n.jsx(nc,{colorPickerValue:o,isActive:s,onClick:i}),n.jsx(rc,{toolbar:e}),n.jsx(oc,{toolbar:e}),n.jsx(sc,{toolbar:e}),n.jsx(ic,{toolbar:e}),n.jsx(ac,{toolbar:e}),n.jsx(Ym,{element:I,onTransformTypeChange:e.handleTransformTypeChange,onElementUpdate:z,isOpen:E,onOpenChange:O}),g&&n.jsx(ct,{icon:"lucide:pen-line",onClick:()=>{A(!0),g()},onMouseLeave:()=>A(!1),tooltip:"Stroke",tooltipDisabled:se||p,active:p||U.stroke}),n.jsx(ct,{icon:n.jsx(_o,{size:20,className:"md:size-5"}),onClick:()=>{ae(!0),u()},onMouseLeave:()=>ae(!1),tooltip:"Rotate",tooltipDisabled:q||(d==null?void 0:d.type)==="rotation",active:(d==null?void 0:d.type)==="rotation"||U.rotation}),n.jsx(ct,{icon:"lucide:blend",onClick:()=>{Ie(!0),h()},onMouseLeave:()=>Ie(!1),tooltip:"Transparency",tooltipDisabled:W||(d==null?void 0:d.type)==="opacity",active:(d==null?void 0:d.type)==="opacity"||U.opacity}),x&&n.jsx(ct,{icon:"lucide:scissors",onClick:()=>{Ke(!0),x()},onMouseLeave:()=>Ke(!1),tooltip:"Clip / Knockout",tooltipDisabled:ke||b,active:b||U.knockout}),v&&n.jsx(ct,{icon:"lucide:stamp",onClick:()=>{te(!0),v()},onMouseLeave:()=>te(!1),tooltip:"Distress Texture",tooltipDisabled:re||y,active:y||U.distress}),C&&n.jsx(ct,{icon:"lucide:venetian-mask",onClick:()=>{ye(!0),C()},onMouseLeave:()=>ye(!1),tooltip:"Image Mask",tooltipDisabled:he||w,active:w||U.imageMask}),n.jsx(ct,{icon:"lucide:flag",onClick:()=>{J(!0),a==null||a()},onMouseLeave:()=>J(!1),tooltip:c?"Browse All Glyphs":"No alternate glyphs available",tooltipDisabled:Z,disabled:!c,className:c?"":"opacity-50"}),j&&n.jsx(tc,{items:j()}),n.jsx(lc,{onMoveForward:M,onMoveBackward:S,onDelete:R,onOpenChange:G}),_&&n.jsx("button",{className:"toolbar-btn",onClick:k,children:"Ungroup"})]},`text-toolbar-${t}`)}function Wm(e,t,r){const o=e.getRotationAnchor();let s;e.transformType==="circle"&&"getEffectiveFontSize"in e?s=e.getEffectiveFontSize():s=e.fontSize;const i=Xm(e,t,s,o);return new r({id:e.id,text:e.text,x:i.x,y:i.y,rotation:e.rotation,fontSize:i.fontSize,fontFamily:e.fontFamily,color:e.color,textAlign:e.textAlign,transformData:i.transformData})}function Xm(e,t,r,o){let s,i,a;const c=r;switch(t){case"circle":s={radius:r*1.2*2,scale:1},i=o.x,a=o.y;break;case"custom":const h=200,f=r*e.text.length*.6,p=Math.max(f,h);s={width:p};const g=r*1.2;i=o.x-p/2,a=o.y-g/2;break;case"arch":const b=200,x=r*e.text.length*.6;s={width:Math.max(x,b),archHeight:T.ARCH_DEFAULTS.archHeight},i=o.x,a=o.y;break;case"wave":const y=200,v=r*e.text.length*.6;s={width:Math.max(v,y),amplitude:T.WAVE_DEFAULTS.amplitude,frequency:T.WAVE_DEFAULTS.frequency},i=o.x,a=o.y;break;case"flag":const w=200,C=r*e.text.length*.6;s={width:Math.max(C,w),amplitude:T.FLAG_DEFAULTS.amplitude,frequency:T.FLAG_DEFAULTS.frequency},i=o.x,a=o.y;break;case"lean":const j=200,M=r*e.text.length*.6;s={width:Math.max(M,j),leanAmount:T.LEAN_DEFAULTS.leanAmount},i=o.x,a=o.y;break;default:s={width:200},i=o.x,a=o.y}return{x:i,y:a,fontSize:c,transformData:s}}function dc(e={}){const{canvasEditorRef:t}=e,{selectedElement:r,activeChildElement:o,handleElementUpdate:s}=Yt.useEditor(),i=o||r,a=l.useCallback(U=>{if(r)if(o){if(!(r instanceof T.GroupElement))return;const W=r.clone(),Ie=W.children.findIndex(ke=>ke.id===o.id);Ie!==-1&&(W.children[Ie]=U,s(W))}else s(U)},[r,o,s]),c=i==null?void 0:i.id,d=l.useRef(void 0),[u,h]=l.useState(32),[f,p]=l.useState("#333333"),[g,b]=l.useState("Arial"),[x,y]=l.useState("center");l.useEffect(()=>{c!==d.current&&(d.current=c,i&&i instanceof T.TextElement&&(i.transformType==="circle"&&"getEffectiveFontSize"in i?h(Math.round(i.getEffectiveFontSize())):i.fontSize!==void 0&&h(Math.round(i.fontSize)),i.color!==void 0&&p(i.color),i.fontFamily!==void 0&&b(i.fontFamily),y(i.textAlign||"center")))},[c,i]);const v=u,w=f,C=g,j=x,M=i instanceof T.TextElement?i:null,S=(M==null?void 0:M.bold)??!1,R=(M==null?void 0:M.italic)??!1,I=(M==null?void 0:M.underline)??!1,D=(M==null?void 0:M.letterCase)??"none",E=l.useCallback(U=>{if(h(U),!i||!(i instanceof T.TextElement))return;const W=i.clone();W.transformType==="circle"&&"setEffectiveFontSize"in W?W.setEffectiveFontSize(U):W.setFontSize(U),W.richText&&W.richText.clearStyleProperty("fontSize"),a(W)},[i,a]),O=l.useCallback(U=>{if(b(U),!i||!(i instanceof T.TextElement))return;const W=i.clone();W.fontFamily=U,W.richText&&W.richText.clearStyleProperty("fontFamily"),a(W)},[i,a]),z=l.useCallback(U=>{if(p(U),!i||!(i instanceof T.TextElement))return;const W=i.clone();W.color=U,W.richText&&W.richText.clearStyleProperty("color"),a(W)},[i,a]),_=l.useCallback(U=>{if(y(U),!i||!(i instanceof T.TextElement))return;const W=i.clone();W.textAlign=U,a(W)},[i,a]),k=l.useCallback(U=>{var W;(W=t==null?void 0:t.current)!=null&&W.isEditingText()?t.current.applyTextFormatting({fontSize:U}):E(U)},[E,t]),Y=l.useCallback(U=>{const W=v+U;W>=8&&W<=500&&k(W)},[v,k]),B=l.useCallback(U=>{var W;(W=t==null?void 0:t.current)!=null&&W.isEditingText()?t.current.applyTextFormatting({fontFamily:U}):O(U)},[O,t]),G=l.useCallback(U=>{var ke;const W=U.target.value;((ke=t==null?void 0:t.current)==null?void 0:ke.isEditingText())&&(t!=null&&t.current)?t.current.applyTextFormatting({color:W}):z(W)},[z,t]),se=l.useCallback(()=>{var U;if((U=t==null?void 0:t.current)!=null&&U.isEditingText())t.current.toggleFormattingProperty("bold");else{if(!i||!(i instanceof T.TextElement))return;const W=i.clone();W.bold=!S,W.richText&&W.richText.clearStyleProperty("bold"),a(W)}},[S,i,a,t]),A=l.useCallback(()=>{var U;if((U=t==null?void 0:t.current)!=null&&U.isEditingText())t.current.toggleFormattingProperty("italic");else{if(!i||!(i instanceof T.TextElement))return;const W=i.clone();W.italic=!R,W.richText&&W.richText.clearStyleProperty("italic"),a(W)}},[R,i,a,t]),Z=l.useCallback(()=>{var U;if((U=t==null?void 0:t.current)!=null&&U.isEditingText())t.current.toggleFormattingProperty("underline");else{if(!i||!(i instanceof T.TextElement))return;const W=i.clone();W.underline=!I,W.richText&&W.richText.clearStyleProperty("underline"),a(W)}},[I,i,a,t]),J=l.useCallback(()=>{if(!i)return;const U=D==="uppercase"?"none":"uppercase",W=i.clone();W.letterCase=U,a(W)},[D,i,a]),q=l.useCallback(()=>D==="uppercase",[D]),ae=l.useCallback(()=>{const U=["left","center","right"],W=U.indexOf(j),Ie=U[(W+1)%U.length];_(Ie)},[j,_]),Le=l.useCallback(()=>{var U,W,Ie,ke;if((W=(U=t==null?void 0:t.current)==null?void 0:U.isEditingText)!=null&&W.call(U)){const Ke=(ke=(Ie=t.current).getSelectionStyle)==null?void 0:ke.call(Ie);if(Ke)return{fontFamily:Ke.fontFamily??C,fontSize:Ke.fontSize??v,color:Ke.color??w,bold:Ke.bold??S,italic:Ke.italic??R,underline:Ke.underline??I}}return{fontFamily:C,fontSize:v,color:w,bold:S,italic:R,underline:I}},[t,C,v,w,S,R,I]),pe=l.useCallback(U=>{if(!i)return;const W=T.getTransformById(U);if(!(W!=null&&W.Component))return;const Ie=Wm(i,U,W.Component);a(Ie)},[i,a]);return{fontSize:v,fontColor:w,fontFamily:C,textAlign:j,bold:S,italic:R,underline:I,letterCase:D,handleFontSizeChange:k,handleFontSizeIncrement:Y,handleFontFamilyChange:B,handleFontColorChange:G,handleBoldToggle:se,handleItalicToggle:A,handleUnderlineToggle:Z,handleLetterCaseToggle:J,isLetterCaseActive:q,handleTextAlignToggle:ae,getEffectiveStyle:Le,handleTransformTypeChange:pe}}const Vm=T.createLogger("useLayerPreview");function uc(e){var h,f,p,g;const{element:t,size:r=148,backgroundColor:o="transparent",enabled:s=!0}=e,[i,a]=l.useState(null),[c,d]=l.useState(!1),u=l.useRef(null);return l.useEffect(()=>{if(!s){a(null),d(!1);return}let b=!0;return d(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{(async()=>{try{if(t instanceof T.ImageElement&&t.imageUrl){const v=new Image;if(v.crossOrigin="anonymous",await new Promise((w,C)=>{v.onload=()=>w(),v.onerror=()=>C(new Error("Failed to load image")),v.src=t.imageUrl}),!b)return}const y=Ms(t,{width:r,height:r,padding:8,backgroundColor:o});b&&(a(y),d(!1))}catch(y){if(Vm.warn("Failed to generate preview:",y),b){const v=Ms(t,{width:r,height:r,padding:8,backgroundColor:o});a(v),d(!1)}}})()},50),()=>{b=!1,u.current&&clearTimeout(u.current)}},[t.id,o,r,s,t.x,t.y,t.rotation,t.transformData,t instanceof T.TextElement?t.text:null,t instanceof T.TextElement?t.fontSize:null,t instanceof T.TextElement?t.fontFamily:null,t instanceof T.TextElement?t.color:null,t instanceof T.ImageElement?t.imageUrl:null,t instanceof T.ImageElement?t.imageLoaded:null,t instanceof T.ImageElement?t.isCropping:null,t instanceof T.ShapeElement?(h=t.transformData)==null?void 0:h.fillColor:null,t instanceof T.PathElement?(p=(f=t.transformData)==null?void 0:f.points)==null?void 0:p.length:null,t instanceof T.GroupElement?(g=t.children)==null?void 0:g.length:null]),{previewUrl:i,isLoading:c}}function Gm({element:e,onToggleLock:t,onThumbnailClick:r}){if(!e)return null;const o=e.locked===!0;return n.jsxs(n.Fragment,{children:[n.jsx(Km,{element:e,onClick:r}),n.jsx(ct,{icon:n.jsx(qm,{locked:o}),onClick:t,active:o,tooltip:o?"Unlock layer":"Lock layer","aria-label":o?"Unlock layer":"Lock layer"})]})}function Km({element:e,onClick:t}){const{previewUrl:r}=uc({element:e,size:64,backgroundColor:"transparent"}),o=n.jsx("span",{className:"size-6 md:size-5 rounded-md shrink-0 flex items-center justify-center overflow-hidden",style:{background:"var(--color-muted, rgba(120,120,120,0.18))"},children:r?n.jsx("img",{src:r,alt:"",style:{width:"100%",height:"100%",objectFit:"contain"}}):null});return t?n.jsx("button",{type:"button",onClick:t,onPointerDown:s=>s.stopPropagation(),onPointerUp:s=>s.stopPropagation(),"aria-label":"Manage layers",title:"Manage layers",className:"size-11 md:size-9 shrink-0 flex items-center justify-center",children:o}):n.jsx("span",{"aria-hidden":!0,className:"size-11 md:size-9 shrink-0 flex items-center justify-center",children:o})}function qm({locked:e}){return n.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,children:[n.jsx("rect",{x:"4",y:"9",width:"12",height:"8.5",rx:"1.6",stroke:"currentColor",strokeWidth:"1.6",fill:e?"currentColor":"none",fillOpacity:e?.18:0}),e?n.jsx("path",{d:"M6.5 9V6.25a3.5 3.5 0 0 1 7 0V9",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}):n.jsx("path",{d:"M6.5 9V6.25a3.5 3.5 0 0 1 7 0",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})}const Zm=({element:e,rotationExpanded:t=!1,onRotationToggle:r,opacityExpanded:o=!1,onOpacityToggle:s,strokeExpanded:i=!1,onStrokeToggle:a,knockoutExpanded:c=!1,onKnockoutToggle:d,distressTextureExpanded:u=!1,onDistressTextureToggle:h,imageMaskExpanded:f=!1,onImageMaskToggle:p,onUngroup:g})=>{const[b,x]=l.useState(!1),[y,v]=l.useState(!1),[w,C]=l.useState(!1),[j,M]=l.useState(!1),[S,R]=l.useState(!1),[I,D]=l.useState(!1),E=Uo(e??null);return n.jsxs("div",{className:"toolbar-items",children:[n.jsx(ct,{icon:n.jsx(_o,{size:20,className:"md:size-5"}),onClick:()=>{x(!0),r()},onMouseLeave:()=>x(!1),tooltip:"Rotate",tooltipDisabled:b||t,active:t||E.rotation}),n.jsx(ct,{icon:"lucide:blend",onClick:()=>{v(!0),s()},onMouseLeave:()=>v(!1),tooltip:"Transparency",tooltipDisabled:y||o,active:o||E.opacity}),a&&n.jsx(ct,{icon:"lucide:pen-line",onClick:()=>{C(!0),a()},onMouseLeave:()=>C(!1),tooltip:"Stroke",tooltipDisabled:w||i,active:i||E.stroke}),d&&n.jsx(ct,{icon:"lucide:scissors",onClick:()=>{M(!0),d()},onMouseLeave:()=>M(!1),tooltip:"Knockout",tooltipDisabled:j||c,active:c||E.knockout}),h&&n.jsx(ct,{icon:"lucide:stamp",onClick:()=>{R(!0),h()},onMouseLeave:()=>R(!1),tooltip:"Distress Texture",tooltipDisabled:S||u,active:u||E.distress}),p&&n.jsx(ct,{icon:"lucide:venetian-mask",onClick:()=>{D(!0),p()},onMouseLeave:()=>D(!1),tooltip:"Image Mask",tooltipDisabled:I||f,active:f||E.imageMask}),n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"sm",onClick:g,children:"Ungroup"})}),n.jsx(m.TooltipContent,{children:"Ungroup this group"})]})]})};function Da({children:e,className:t}){const r=l.useRef(null);return l.useEffect(()=>{const o=r.current;if(!o)return;const s=a=>{a.stopPropagation()},i=a=>{a.preventDefault(),a.stopPropagation()};return o.addEventListener("touchstart",s,{passive:!1}),o.addEventListener("touchmove",i,{passive:!1}),()=>{o.removeEventListener("touchstart",s),o.removeEventListener("touchmove",i)}},[]),n.jsx("div",{ref:r,className:t,style:{touchAction:"none"},children:e})}const qr=({element:e,onElementUpdate:t,className:r})=>{var g,b;const[o,s]=l.useState("center"),i=l.useRef(null),a=l.useRef({x:0,y:0});l.useEffect(()=>{const x=i.current;if(!x)return;const y=w=>{a.current={x:w.touches[0].clientX,y:w.touches[0].clientY}},v=w=>{const C=Math.abs(w.touches[0].clientX-a.current.x),j=Math.abs(w.touches[0].clientY-a.current.y);C>10&&C>j&&w.preventDefault()};return x.addEventListener("touchstart",y,{passive:!0}),x.addEventListener("touchmove",v,{passive:!1}),()=>{x.removeEventListener("touchstart",y),x.removeEventListener("touchmove",v)}},[]);const c=((g=e.transformData)==null?void 0:g.cropWidth)||1,d=((b=e.transformData)==null?void 0:b.cropHeight)||1,u=l.useCallback((x,y,v,w)=>{const C=e.clone();C.updateCrop(x,y,v,w,!0),t(C)},[e,t]),h=l.useCallback((x,y=o)=>{const v=e.transformData.cropWidth,w=e.transformData.cropX,C=x-v;let j=w;y.includes("center")?j=w-C/2:y.includes("right")&&(j=w-C),j=Math.max(0,Math.min(1-x,j)),u(j,e.transformData.cropY,x,e.transformData.cropHeight)},[e,u,o]),f=l.useCallback((x,y=o)=>{const v=e.transformData.cropHeight,w=e.transformData.cropY,C=x-v;let j=w;y.includes("middle")||y==="center"?j=w-C/2:y.includes("bottom")&&(j=w-C),j=Math.max(0,Math.min(1-x,j)),u(e.transformData.cropX,j,e.transformData.cropWidth,x)},[e,u,o]),p=["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"];return n.jsx("div",{ref:i,"data-preserve-selection":!0,className:Bn("flex min-h-0 flex-1 flex-col",r),style:{touchAction:"pan-y"},children:n.jsx("div",{className:"flex flex-col gap-5 px-5 pt-1 pb-[calc(env(safe-area-inset-bottom,0px)+20px)] md:gap-4 md:px-4 md:pt-0 md:pb-[calc(env(safe-area-inset-bottom,0px)+16px)]",children:n.jsxs("div",{className:"flex items-start gap-6 md:gap-5",children:[n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("span",{className:"text-foreground/60 text-sm md:text-xs",children:"Anchor"}),n.jsx("div",{className:"grid grid-cols-3 gap-0.5 rounded-md p-1",children:p.map(x=>n.jsx("button",{onClick:()=>s(x),className:Bn("crop-anchor-btn size-8 rounded-md md:size-6 md:rounded",o===x&&"active"),title:x.replace("-"," "),children:n.jsx("div",{className:Bn("crop-anchor-dot size-2 md:size-1.5",o===x&&"active size-2.5 md:size-2")})},x))})]}),n.jsxs("div",{className:"flex flex-1 flex-col gap-4 md:gap-3",children:[n.jsxs("div",{className:"flex flex-col gap-2.5 md:gap-1.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-foreground/60 text-sm md:text-xs",children:"Width"}),n.jsx("input",{type:"number",value:Math.round(c*100),onChange:x=>h(Math.max(10,Math.min(100,Number(x.target.value)))/100),min:10,max:100,className:"bg-transparent text-foreground w-14 rounded-md border-none px-2.5 py-2 text-right text-base md:w-14 md:rounded md:px-1.5 md:py-1 md:text-[13px]"})]}),n.jsx(Da,{children:n.jsxs(m.Slider,{value:[c*100],onValueChange:x=>h(x[0]/100),min:10,max:100,step:1,children:[n.jsx(m.Slider.Track,{className:"bg-foreground/10 h-2",children:n.jsx(m.Slider.Fill,{className:"bg-primary"})}),n.jsx(m.Slider.Thumb,{})]})})]}),n.jsxs("div",{className:"flex flex-col gap-2.5 md:gap-1.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-foreground/60 text-sm md:text-xs",children:"Height"}),n.jsx("input",{type:"number",value:Math.round(d*100),onChange:x=>f(Math.max(10,Math.min(100,Number(x.target.value)))/100),min:10,max:100,className:"bg-transparent text-foreground w-14 rounded-md border-none px-2.5 py-2 text-right text-base md:w-14 md:rounded md:px-1.5 md:py-1 md:text-[13px]"})]}),n.jsx(Da,{children:n.jsxs(m.Slider,{value:[d*100],onValueChange:x=>f(x[0]/100),min:10,max:100,step:1,children:[n.jsx(m.Slider.Track,{className:"bg-foreground/10 h-2",children:n.jsx(m.Slider.Fill,{className:"bg-primary"})}),n.jsx(m.Slider.Thumb,{})]})})]})]})]})})})},Jm=Object.freeze(Object.defineProperty({__proto__:null,CropPanel:qr,default:qr},Symbol.toStringTag,{value:"Module"})),kn="flex flex-col gap-5 px-5 pt-4 pb-4 md:gap-4 md:px-4 md:pt-3 md:pb-3",hc="flex flex-col gap-5 px-5 pt-4 pb-[calc(env(safe-area-inset-bottom,0px)+20px)] md:gap-4 md:px-4 md:pt-2 md:pb-[calc(env(safe-area-inset-bottom,0px)+16px)]",Qm=({value:e,onChange:t})=>n.jsx("div",{className:"corner-radius-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Radius",value:e,onChange:t,min:0,max:50,unit:"%"})})}),eg=({value:e,onChange:t,onRotate90:r})=>n.jsx("div",{className:"rotation-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsxs("div",{className:"flex items-end gap-3",children:[n.jsx(sn,{label:"Rotation",value:e,onChange:t,min:-180,max:180,unit:"°",showInput:!0,inputWidth:"56px",variant:"stacked",className:"flex-1"}),n.jsx("div",{className:"pb-0.5",children:n.jsx(ct,{icon:Re.rotateCcwSquare,onClick:r,tooltip:"Rotate 90° CCW"})})]})})}),tg=({value:e,onChange:t,widthValue:r,onWidthChange:o})=>n.jsx("div",{className:"font-size-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsxs("div",{className:kn,children:[n.jsx(sn,{label:"Font Size",value:Math.round(e),onChange:t,min:8,max:256,step:1,unit:"px",showInput:!0,inputWidth:"64px"}),r!=null&&o&&n.jsx(sn,{label:"Width",value:Math.round(r),onChange:o,min:50,max:4e3,step:1,unit:"px",showInput:!0,inputWidth:"64px"})]})}),ng=({value:e,onChange:t})=>n.jsx("div",{className:"opacity-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Opacity",value:Math.round(e*100),onChange:r=>t(r/100),min:0,max:100,unit:"%"})})}),rg=({value:e,onChange:t})=>n.jsx("div",{className:"shape-corner-radius-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Radius",value:e,onChange:t,min:0,max:50,unit:"%"})})}),og=({value:e,onChange:t})=>n.jsx("div",{className:"shape-transparency-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Opacity",value:Math.round(e*100),onChange:r=>t(r/100),min:0,max:100,unit:"%"})})}),sg=({value:e,onChange:t})=>n.jsx("div",{className:"shape-sides-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Sides",value:e,onChange:t,min:3,max:20})})}),ig=({value:e,onChange:t})=>n.jsx("div",{className:"shape-points-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Points",value:e,onChange:t,min:3,max:20})})}),ag=({value:e,onChange:t})=>n.jsx("div",{className:"shape-inner-radius-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Inner Radius",value:Math.round(e*100),onChange:r=>t(r/100),min:10,max:90,unit:"%"})})}),lg=({value:e,onChange:t,documentColors:r,imageColors:o})=>n.jsx("div",{className:"shape-color-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:hc,children:n.jsx(lr,{value:e,onChange:s=>t(s.target.value),documentColors:r,imageColors:o,showSquare:!0,embedded:!0})})}),cg=({value:e,onChange:t,documentColors:r,imageColors:o})=>n.jsx("div",{className:"text-color-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:hc,children:n.jsx(lr,{value:e,onChange:t,documentColors:r,imageColors:o,embedded:!0})})}),dg=({mode:e,fill:t,stroke:r,scope:o,onModeChange:s,onFillChange:i,onStrokeChange:a,onScopeChange:c})=>n.jsx("div",{className:"knockout-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsxs("div",{className:kn,children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(m.Label,{className:"text-base md:text-sm font-medium",children:"Mode"}),n.jsxs("div",{className:"flex rounded-md border border-divider overflow-hidden",children:[n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm transition-colors ${e==="clip"?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>s("clip"),children:"Clip"}),n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm transition-colors ${e==="knockout"?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>s("knockout"),children:"Knockout"})]})]}),n.jsxs("div",{className:"flex items-center gap-5",children:[n.jsxs("label",{className:"flex items-center gap-2 text-base md:text-sm text-foreground",children:[n.jsx(m.Checkbox,{checked:t,onCheckedChange:d=>i(d===!0)}),"Fill"]}),n.jsxs("label",{className:"flex items-center gap-2 text-base md:text-sm text-foreground",children:[n.jsx(m.Checkbox,{checked:r,onCheckedChange:d=>a(d===!0)}),"Stroke"]})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(m.Label,{className:"text-base md:text-sm font-medium",children:"Scope"}),n.jsxs("div",{className:"flex rounded-md border border-divider overflow-hidden",children:[n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm transition-colors ${o==="group"?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>c("group"),children:"Group"}),n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm transition-colors ${o==="artboard"?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>c("artboard"),children:"Artboard"})]})]})]})}),ug=({textureUrl:e,opacity:t,onTextureChange:r,onOpacityChange:o})=>{rt.ensureBuiltinTexturesReady();const s=rt.DISTRESS_TEXTURE_PRESETS.map(a=>({id:a.textureUrl,name:a.name,thumbnailUrl:a.thumbnailUrl})),i=l.useCallback(a=>{a&&rt.preloadTexture(a),r(a)},[r]);return n.jsx("div",{className:"distress-texture-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsxs("div",{className:kn,children:[n.jsx(Ho,{presets:s,selectedId:e,onSelect:i,ariaLabel:"Distress texture presets"}),n.jsx(sn,{label:"Opacity",value:t,onChange:o,min:0,max:100,unit:"%"})]})})},hg=({imageUrl:e,maskType:t,opacity:r,inverted:o,onImageChange:s,onMaskTypeChange:i,onOpacityChange:a,onInvertedChange:c})=>{rt.ensureMaskPresetsReady();const d=rt.MASK_IMAGE_PRESETS.map(u=>({id:u.imageUrl,name:u.name,thumbnailUrl:u.thumbnailUrl}));return n.jsx("div",{className:"image-mask-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsxs("div",{className:kn,children:[n.jsx(Ho,{presets:d,selectedId:e,onSelect:s,ariaLabel:"Image mask presets"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(m.Label,{className:"text-base md:text-sm font-medium",children:"Type"}),n.jsx("div",{className:"flex rounded-md border border-divider overflow-hidden",children:["clip","alpha","luma"].map(u=>n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm capitalize transition-colors ${t===u?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>i(u),children:u},u))})]}),n.jsx(sn,{label:"Opacity",value:r,onChange:a,min:0,max:100,unit:"%"}),n.jsxs("label",{className:"flex items-center gap-2 text-base md:text-sm text-foreground",children:[n.jsx(m.Checkbox,{checked:o,onCheckedChange:u=>c(u===!0)}),"Invert Mask"]})]})})},fg=({stroke:e,onChange:t,documentColors:r,imageColors:o})=>{const[s,i]=l.useState(!1),a=(e==null?void 0:e.enabled)??!1,c=(e==null?void 0:e.color)??"#000000",d=(e==null?void 0:e.width)??5,u=(e==null?void 0:e.opacity)??1,h=(e==null?void 0:e.lineCap)??"butt",f=(e==null?void 0:e.lineJoin)??"miter",p=l.useCallback(b=>{t(b?{enabled:!0,color:c,width:d,lineCap:h,lineJoin:f,opacity:u}:void 0)},[t,c,d,h,f,u]),g=l.useCallback(b=>{e&&t({...e,...b})},[e,t]);return n.jsx("div",{className:"stroke-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsxs("div",{className:kn,children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(m.Label,{className:"text-foreground/70 text-base md:text-[13px]",children:"Stroke"}),n.jsx(m.Switch,{checked:a,onCheckedChange:p})]}),a&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(m.Label,{className:"text-foreground/70 text-base md:text-[13px]",children:"Color"}),n.jsx(lr,{value:c,onChange:b=>g({color:b.target.value}),documentColors:r,imageColors:o,showSquare:!0})]}),n.jsx(sn,{label:"Width",value:d,onChange:b=>g({width:b}),min:1,max:50,unit:"px"}),n.jsx(sn,{label:"Opacity",value:Math.round(u*100),onChange:b=>g({opacity:b/100}),min:0,max:100,unit:"%"}),n.jsxs("button",{className:"flex items-center gap-1 text-base md:text-sm text-muted-foreground hover:text-foreground transition-colors py-1.5 md:py-0",onClick:()=>i(b=>!b),children:[s?"Hide":"Show"," Advanced"]}),s&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(m.Label,{className:"text-foreground/70 text-base md:text-[13px]",children:"Line Cap"}),n.jsx("div",{className:"flex rounded-md border border-divider overflow-hidden",children:["butt","round","square"].map(b=>n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm capitalize transition-colors ${h===b?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>g({lineCap:b}),children:b},b))})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(m.Label,{className:"text-foreground/70 text-base md:text-[13px]",children:"Line Join"}),n.jsx("div",{className:"flex rounded-md border border-divider overflow-hidden",children:["miter","round","bevel"].map(b=>n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm capitalize transition-colors ${f===b?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>g({lineJoin:b}),children:b},b))})]})]})]})]})})},pg=({element:e,onElementUpdate:t})=>n.jsx(qr,{element:e,onElementUpdate:t}),mg=({panelType:e,defaultIcon:t,textColorValue:r,shapeFillColor:o})=>e==="textColor"?n.jsxs("div",{className:"relative flex size-6 items-center justify-center md:size-5",children:[n.jsx("span",{className:"text-primary text-xl leading-none font-bold md:text-lg",children:"A"}),n.jsx("div",{className:"absolute bottom-0 left-1/2 h-[3px] w-4 -translate-x-1/2 rounded-sm",style:{backgroundColor:r}})]}):e==="shapeColor"?n.jsxs("div",{className:"relative flex size-6 items-center justify-center md:size-5",children:[n.jsx(de,{icon:"mdi:format-color-fill",className:"text-primary size-5 md:size-4"}),n.jsx("div",{className:"absolute -bottom-0.5 left-1/2 h-[3px] w-4 -translate-x-1/2 rounded-sm",style:{backgroundColor:o||"#3b82f6"}})]}):typeof t=="string"?n.jsx(de,{icon:t,className:"text-primary size-6 md:size-5"}):n.jsx(n.Fragment,{children:t}),vn=({isOpen:e,children:t})=>n.jsx("div",{className:"secondary-toolbar-panel-wrapper",style:{display:"flex",flexDirection:"column",flex:e?1:0,minHeight:e?0:void 0,transition:"flex 300ms cubic-bezier(0.32, 0.72, 0, 1)"},children:n.jsx("div",{className:e?"secondary-panel-scroll-container":"",style:{flex:1,display:"flex",flexDirection:"column",overflowY:e?"auto":"hidden",overscrollBehaviorY:"contain",WebkitOverflowScrolling:"touch",transform:e?"translateY(0)":"translateY(100%)",opacity:e?1:0,transition:"transform 300ms cubic-bezier(0.32, 0.72, 0, 1), opacity 200ms ease-out"},children:t})}),La=({isOpen:e,children:t})=>n.jsx("div",{className:"secondary-toolbar-panel-wrapper",style:{display:"flex",flexDirection:"column",flex:e?1:0,minHeight:e?0:void 0,transition:"flex 300ms cubic-bezier(0.32, 0.72, 0, 1)"},children:n.jsx("div",{className:e?"secondary-panel-scroll-container":"",style:{flex:1,minHeight:0,overflowY:e?void 0:"hidden",overscrollBehaviorY:"contain",WebkitOverflowScrolling:"touch",transform:e?"translateY(0)":"translateY(100%)",opacity:e?1:0,transition:"transform 300ms cubic-bezier(0.32, 0.72, 0, 1), opacity 200ms ease-out"},children:t})}),gg=({toolbarContent:e,innerContentRef:t,shouldRender:r,isExiting:o,transitionHeight:s,emptyStateContent:i,isCornerRadiusPanelOpen:a,isCropPanelOpen:c,isRotationPanelOpen:d,isOpacityPanelOpen:u,isFontSizePanelOpen:h,isShapeCornerRadiusPanelOpen:f,isShapeTransparencyPanelOpen:p,isShapeSidesPanelOpen:g,isShapePointsPanelOpen:b,isShapeInnerRadiusPanelOpen:x,isShapeColorPanelOpen:y,isTextColorPanelOpen:v,isStrokePanelOpen:w,isKnockoutPanelOpen:C,isDistressTexturePanelOpen:j,isImageMaskPanelOpen:M,cornerRadiusPanel:S,cropPanelContent:R,rotationPanel:I,opacityPanel:D,fontSizePanel:E,shapeCornerRadiusPanel:O,shapeTransparencyPanel:z,shapeSidesPanel:_,shapePointsPanel:k,shapeInnerRadiusPanel:Y,shapeColorPanel:B,textColorPanel:G,strokePanel:se,knockoutPanel:A,distressTexturePanel:Z,imageMaskPanel:J})=>n.jsxs("div",{className:"toolbar-embedded-wrapper",style:{display:"flex",flexDirection:"column",flex:1,minHeight:0,overscrollBehaviorY:"contain"},children:[i,n.jsx("div",{className:"toolbar-height-wrapper",style:s!==null?{height:s,overflow:"hidden",transition:"height 200ms cubic-bezier(0.22, 1, 0.36, 1)"}:{display:"grid",gridTemplateRows:r&&!o?"1fr":"0fr",transition:"grid-template-rows 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:n.jsx("div",{ref:t,children:e})}),n.jsx(vn,{isOpen:a,children:S}),n.jsx(vn,{isOpen:c,children:R}),n.jsx(vn,{isOpen:d,children:I}),n.jsx(vn,{isOpen:u,children:D}),n.jsx(vn,{isOpen:h,children:E}),n.jsx(vn,{isOpen:f,children:O}),n.jsx(vn,{isOpen:p,children:z}),n.jsx(vn,{isOpen:g,children:_}),n.jsx(vn,{isOpen:b,children:k}),n.jsx(vn,{isOpen:x,children:Y}),n.jsx(La,{isOpen:y,children:B}),n.jsx(La,{isOpen:v,children:G}),n.jsx(vn,{isOpen:w,children:se}),n.jsx(vn,{isOpen:C,children:A}),n.jsx(vn,{isOpen:j,children:Z}),n.jsx(vn,{isOpen:M,children:J})]}),xg=({toolbarPosition:e,toolbarHeight:t,panelWidth:r,value:o,onChange:s})=>n.jsx("div",{className:"corner-radius-panel",style:{position:"fixed",top:`${e.top+t+8}px`,left:`${e.left}px`,transform:"translateX(-50%)",padding:"12px 24px",marginTop:"-12px",borderRadius:0,border:"1px solid var(--divider)",boxShadow:"0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)",zIndex:"var(--z-tooltip)",width:`${r}px`,boxSizing:"border-box"},children:n.jsx(sn,{label:"Radius",value:o,onChange:s,min:0,max:50,unit:"%"})}),bg=({toolbarPosition:e,toolbarHeight:t,element:r,onElementUpdate:o})=>n.jsx("div",{className:"crop-panel",style:{position:"fixed",top:`${e.top+t+8}px`,left:`${e.left}px`,transform:"translateX(-50%)",background:"var(--background)",border:"1px solid var(--divider)",borderRadius:"12px",boxShadow:"0 4px 12px 0 rgb(0 0 0 / 0.15)",zIndex:"var(--z-tooltip)",minWidth:"300px"},children:n.jsx(qr,{element:r,onElementUpdate:o})}),ir=e=>typeof e=="string"&&e.length>0&&e!=="transparent";function fc(e,t){var o;const r=e.stroke;if(r!=null&&r.enabled&&ir(r.color)&&t.add(r.color),e instanceof T.TextElement){ir(e.color)&&t.add(e.color);const s=e.richText;if(s!=null&&s.spans)for(const i of s.spans)ir((o=i.style)==null?void 0:o.color)&&t.add(i.style.color);return}if(e instanceof T.ShapeElement){const s=e.transformData.fillColor;ir(s)&&t.add(s);return}if(e instanceof T.PathElement){const s=e.transformData;s.fillEnabled&&ir(s.fillColor)&&t.add(s.fillColor),s.strokeEnabled&&ir(s.strokeColor)&&t.add(s.strokeColor);return}if(e instanceof T.GroupElement){for(const s of e.children)fc(s,t);return}}function yg(e,t){const r=new Set;for(const o of e)fc(o,r);if(t)for(const o of t){const s=o.backgroundColor;ir(s)&&r.add(s)}return r}const go=new Map,Cs=new Map;function Ys(e){if(e.length===0)return{rRange:0,gRange:0,bRange:0};let t=255,r=0,o=255,s=0,i=255,a=0;for(const c of e)c.r<t&&(t=c.r),c.r>r&&(r=c.r),c.g<o&&(o=c.g),c.g>s&&(s=c.g),c.b<i&&(i=c.b),c.b>a&&(a=c.b);return{rRange:r-t,gRange:s-o,bRange:a-i}}function vg(e){const t=Math.max(e.rRange,e.gRange,e.bRange);return e.rRange===t?"r":e.gRange===t?"g":"b"}function wg(e){return Math.max(e.rRange,e.gRange,e.bRange)}function Cg(e){const t=vg(e),r=e.pixels.slice().sort((a,c)=>a[t]-c[t]),o=r.length>>1,s=r.slice(0,o),i=r.slice(o);return[{pixels:s,...Ys(s)},{pixels:i,...Ys(i)}]}function Sg(e){let t=0,r=0,o=0;for(const i of e)t+=i.r,r+=i.g,o+=i.b;const s=e.length;return{r:Math.round(t/s),g:Math.round(r/s),b:Math.round(o/s)}}function kg(e,t){if(e.length===0)return[];const r=[{pixels:e,...Ys(e)}];for(;r.length<t;){let o=-1,s=0;for(let a=0;a<r.length;a++){const c=wg(r[a]);c>s&&r[a].pixels.length>=2&&(s=c,o=a)}if(o===-1)break;const i=r[o];r.splice(o,1),r.push(...Cg(i))}return r}function jg(e,t){const r=(e.r+t.r)/2,o=e.r-t.r,s=e.g-t.g,i=e.b-t.b;return Math.sqrt((2+r/256)*o*o+4*s*s+(2+(255-r)/256)*i*i)}function Eg(e,t,r){if(e.length===0||t<=0)return[];const o=[e[0]],s=new Set([0]);for(;o.length<t;){let i=-1,a=-1;for(let c=1;c<e.length;c++){if(s.has(c))continue;let d=1/0;for(const u of o){const h=jg(e[c],u);h<d&&(d=h)}d>a&&(a=d,i=c)}if(i===-1||a<=r)break;o.push(e[i]),s.add(i)}return o}const Ss=e=>e.toString(16).padStart(2,"0");function Tg(e){return`#${Ss(e.r)}${Ss(e.g)}${Ss(e.b)}`}async function Rg(e,t=5){if(!e)return[];const r=go.get(e);if(r)return r;const o=Cs.get(e);if(o)return o;const s=(async()=>{try{const i=await Ng(e),a=48,d=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(a,a):(()=>{const x=document.createElement("canvas");return x.width=a,x.height=a,x})()).getContext("2d");if(!d)return[];d.drawImage(i,0,0,a,a);const{data:u}=d.getImageData(0,0,a,a),h=[];for(let x=0;x<u.length;x+=4){if(u[x+3]<128)continue;const v=u[x],w=u[x+1],C=u[x+2];v>240&&w>240&&C>240||h.push({r:v,g:w,b:C})}if(h.length===0)return go.set(e,[]),[];const f=Math.max(t*4,16),p=kg(h,f);p.sort((x,y)=>y.pixels.length-x.pixels.length);const g=p.map(x=>Sg(x.pixels)),b=Eg(g,t,50).map(Tg);return go.set(e,b),b}catch{return go.set(e,[]),[]}finally{Cs.delete(e)}})();return Cs.set(e,s),s}function Ng(e){return new Promise((t,r)=>{const o=new Image;o.crossOrigin="anonymous",o.onload=()=>t(o),o.onerror=()=>r(new Error(`Failed to load image: ${e}`)),o.src=e})}async function Mg(e,t=5){const r=[],o=new Set,s=d=>{if(d instanceof T.ImageElement){const u=d.imageUrl;u&&!o.has(u)&&(o.add(u),r.push(u))}else if(d instanceof T.GroupElement)for(const u of d.children)s(u)};for(const d of e)s(d);if(r.length===0)return[];const i=await Promise.all(r.map(d=>Rg(d,t))),a=[],c=new Set;for(const d of i)for(const u of d)c.has(u)||(c.add(u),a.push(u));return a}const Ig=T.createLogger("ContextualToolbars"),Ws=({mode:e="floating",onOpenGlyphBrowser:t,onChangeImage:r,onOpenShapeTypeDrawer:o,documentColors:s=new Set,viewportWidth:i=window.innerWidth,breakpoints:a={},hasGlyphs:c=!1,getMoreMenuItems:d,onArtboardUpdate:u,artboardScreenBounds:h,maxWidth:f,transparent:p=!1,onPanelExpandChange:g,defaultExpandedPanel:b,onExpandedPanelTypeChange:x,onOpenCropDrawer:y,onOpenCornerRadiusDrawer:v,closeButtonStyle:w="icon",emptyStateMessage:C="Tap an element to select and edit",emptyStateRender:j,editArtboardMode:M=!1,onEditArtboardModeChange:S,onLayerThumbnailClick:R})=>{var mi,gi,xi,bi,yi,vi,wi,Ci,Si,ki,ji,Ei,Ti,Ri,Ni,Mi;const{panOffset:I}=Yt.useViewportContext(),{multiSelection:D,setSelectedId:E}=Yt.useSelectionContext(),{expandedPanelType:O,setExpandedPanelType:z,setIsToolbarMenuOpen:_,isRotating:k}=Yt.useToolStateContext(),{elements:Y,selectedElement:B,activeChildElement:G,handleElementUpdate:se,artboardManager:A,artboards:Z,canvasEditorRef:J,canvasRef:q,executeRemoveElement:ae,executeAddElement:Le,executeReorderElement:pe,refreshArtboards:U}=Yt.useEditor(),W=dc({canvasEditorRef:J}),[Ie,ke]=l.useState("root"),[Ke,re]=l.useState(null),[te,he]=l.useState(null),[ye,we]=l.useState(!1),[Pe,me]=l.useState(!1),[N]=l.useState(!1),[ce,le]=l.useState(!1),[Me,ge]=l.useState(!1),[L,ve]=l.useState(()=>b&&{cornerRadius:{type:"cornerRadius",icon:"lucide:square-round-corner",label:"Corner Radius"},crop:{type:"crop",icon:"lucide:crop",label:"Crop"},rotation:{type:"rotation",icon:Re.rotateLeft,label:"Rotate"},opacity:{type:"opacity",icon:"lucide:blend",label:"Transparency"},effects:{type:"effects",icon:"lucide:sparkles",label:"Effects"}}[b]||null),[tt,Ve]=l.useState(!1),[oe,ie]=l.useState(!1),[pt,st]=l.useState(!1),[ht,bt]=l.useState(!1),[yt,Tt]=l.useState(null),[Rt,jt]=l.useState(null),[kt,Kt]=l.useState({width:0,height:0}),$t=l.useRef(null),Ot=l.useRef(null),De=l.useRef(0),je=l.useRef(!1),Ee=l.useRef(!1),$e=l.useRef(null),Qe=l.useRef(void 0),Fe=l.useRef(null),Ue=l.useRef(O),Xe=l.useRef(void 0),dt=l.useRef(void 0),Ye=l.useRef(!1),vt=l.useRef(!1),gt=l.useRef(!!b),Nt=l.useRef(!1),Ft=l.useRef(L),$=l.useRef(null),ee=l.useRef(()=>{}),Je=l.useRef(void 0),it=l.useRef(void 0);vt.current=k;const F=G||B,ft=F==null?void 0:F.id,at=B==null?void 0:B.id,xt=F==null?void 0:F.transformType,{fontColor:Q,getEffectiveStyle:ze,handleFontColorChange:nt}=W,Ce=!!(B&&!k),X=l.useCallback(P=>{if(B)if(G){const qe=B.clone(),Ge=qe.children.findIndex(Xt=>Xt.id===G.id);Ge!==-1&&(qe.children[Ge]=P,se(qe))}else se(P)},[B,G,se]),Mt=l.useCallback(P=>{if(!F||F.transformType!=="image")return;const H=F.clone();H.transformData.borderRadius=P,X(H)},[F,X]),ue=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.borderRadius=P,X(H)},[F,X]),et=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.fillOpacity=P,X(H)},[F,X]),K=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.sides=P,X(H)},[F,X]),be=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.points=P,X(H)},[F,X]),Te=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.innerRadius=P,X(H)},[F,X]),Ne=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.fillColor=P,X(H)},[F,X]),He=l.useCallback(()=>{v?v():ve(P=>(P==null?void 0:P.type)==="cornerRadius"?null:{type:"cornerRadius",icon:"lucide:square-round-corner",label:"Corner Radius"})},[v]),Se=l.useCallback(()=>{y?y():ve(P=>(P==null?void 0:P.type)==="crop"?null:{type:"crop",icon:"lucide:crop",label:"Crop"})},[y]),Be=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="rotation"?null:{type:"rotation",icon:Re.rotateLeft,label:"Rotate"})},[]),Ae=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="opacity"?null:{type:"opacity",icon:"lucide:blend",label:"Transparency"})},[]),V=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="fontSize"?null:{type:"fontSize",icon:"lucide:type",label:"Font Size"})},[]),xe=l.useCallback(P=>{if(!F)return;const H=F.transformData;if(!H||H.width===void 0)return;const qe=F.clone();qe.transformData.width=P,X(qe)},[F,X]),ne=((mi=F==null?void 0:F.transformData)==null?void 0:mi.width)??null,fe=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapeCornerRadius"?null:{type:"shapeCornerRadius",icon:"lucide:square-round-corner",label:"Corner Radius"})},[]),_e=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapeTransparency"?null:{type:"shapeTransparency",icon:"lucide:blend",label:"Transparency"})},[]),Oe=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapeSides"?null:{type:"shapeSides",icon:"lucide:hexagon",label:"Sides"})},[]),ot=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapePoints"?null:{type:"shapePoints",icon:"lucide:star",label:"Points"})},[]),mt=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapeInnerRadius"?null:{type:"shapeInnerRadius",icon:"lucide:circle-dashed",label:"Inner Radius"})},[]),Bt=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapeColor"?null:{type:"shapeColor",icon:"lucide:paint-bucket",label:"Fill Color"})},[]),Wt=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="textColor"?null:{type:"textColor",icon:Re.palette,label:"Font Color"})},[]),_t=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="compositing"?null:{type:"compositing",icon:"lucide:scissors",label:"Clip / Knockout"})},[]),At=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="distressTexture"?null:{type:"distressTexture",icon:"lucide:stamp",label:"Distress Texture"})},[]),Dt=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="imageMask"?null:{type:"imageMask",icon:"lucide:venetian-mask",label:"Image Mask"})},[]),rn=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="stroke"?null:{type:"stroke",icon:"lucide:pen-line",label:"Stroke"})},[]),Lt=l.useCallback(()=>{if((L==null?void 0:L.type)==="crop"&&(F==null?void 0:F.transformType)==="image"){const P=F;if(P.isCropping){const H=P.clone();H.exitCropMode(),X(H)}}ve(null)},[L,F,X]),Ut=l.useCallback(()=>{if(!B)return;const P=Y.findIndex(H=>H.id===B.id);if(P<Y.length-1){const H=Y[P+1];pe(B.id,H.id,"after")}},[B,Y,pe]),an=l.useCallback(()=>{if(!B)return;const P=Y.findIndex(H=>H.id===B.id);if(P>0){const H=Y[P-1];pe(B.id,H.id,"before")}},[B,Y,pe]),un=l.useCallback(()=>{const P=G||B;P&&(ae(P),E(null))},[G,B,ae,E]),Zt=l.useCallback(()=>{if(!F)return;const P=F.clone();P.locked=!F.locked,X(P)},[F,X]),Qt=l.useCallback(()=>{if(!B||B.transformType!=="group")return;const P=B;if(!P.children||P.children.length===0)return;const H=A.getArtboardIdForElement(P.id);if(!H)return;const qe=P.children.map(Ge=>{const Xt=Ge.clone();return Xt.x=Ge.x+P.x,Xt.y=Ge.y+P.y,Xt});ae(P),qe.forEach(Ge=>Le(Ge,H)),E(qe.length>0?qe[0].id:null)},[B,A,ae,Le,E]),hn=l.useCallback(P=>{if(!F)return;const H=F.clone();H.rotation=P,X(H)},[F,X]),en=l.useCallback(()=>{if(!F)return;const P=F.clone();let H=Math.floor(P.rotation/90)*90+90;H=(H%360+360)%360,H>180&&(H-=360),P.rotation=H,X(P)},[F,X]),xn=l.useCallback(P=>{if(!F)return;const H=F.clone();H.opacity=P,X(H)},[F,X]),Yn=l.useCallback(P=>{if(!F)return;const H=F.clone();H.blendMode=P,H.knockoutParts||(H.knockoutParts={fill:!0,scope:"group"}),X(H)},[F,X]),er=l.useCallback(P=>{if(!F)return;const H=F.clone(),qe=H.blendMode==="clip"?"clip":"knockout",Ge={...H.knockoutParts,fill:P};H.knockoutParts=Ge,H.blendMode=Ge.fill||Ge.stroke?qe:"normal",X(H)},[F,X]),wn=l.useCallback(P=>{if(!F)return;const H=F.clone(),qe=H.blendMode==="clip"?"clip":"knockout",Ge={...H.knockoutParts,stroke:P};H.knockoutParts=Ge,H.blendMode=Ge.fill||Ge.stroke?qe:"normal",X(H)},[F,X]),cr=l.useCallback(P=>{if(!F)return;const H=F.clone();H.knockoutParts={...H.knockoutParts,scope:P},X(H)},[F,X]),dr=l.useCallback(P=>{var qe,Ge;if(!F)return;const H=F.clone();P?H.distressEffect={enabled:!0,style:"custom",intensity:((qe=H.distressEffect)==null?void 0:qe.intensity)??50,textureUrl:P,textureOpacity:((Ge=H.distressEffect)==null?void 0:Ge.textureOpacity)??.5}:H.distressEffect=void 0,X(H)},[F,X]),Gn=l.useCallback(P=>{if(!F)return;const H=F.clone();H.distressEffect&&(H.distressEffect={...H.distressEffect,textureOpacity:P/100}),X(H)},[F,X]),tr=l.useCallback(P=>{if(!F)return;const H=F.clone();if(!P)H.masks=(H.masks||[]).filter(qe=>qe.id!=="quick-image-mask");else{const Ge=()=>({transformType:"image",imageUrl:P,x:0,y:0,rotation:0,transformData:{type:"image",width:512,height:512,cropX:0,cropY:0,cropWidth:1,cropHeight:1,flipHorizontal:!1,flipVertical:!1,borderRadius:0}});if("transformData"in H&&H.transformData){const tn=H.transformData;tn.cropX=0,tn.cropY=0,tn.cropWidth=1,tn.cropHeight=1}const Xt=(H.masks||[]).find(tn=>tn.id==="quick-image-mask");if(Xt)Xt.maskElement=Ge();else{const tn=H.masks||[];tn.push({id:"quick-image-mask",type:"clip",maskElement:Ge(),opacity:1,inverted:!1}),H.masks=tn}}X(H)},[F,X]),ln=l.useCallback(P=>{if(!F)return;const H=F.clone(),qe=(H.masks||[]).find(Ge=>Ge.id==="quick-image-mask");qe&&(qe.type=P,X(H))},[F,X]),Hn=l.useCallback(P=>{if(!F)return;const H=F.clone(),qe=(H.masks||[]).find(Ge=>Ge.id==="quick-image-mask");qe&&(qe.opacity=P/100,X(H))},[F,X]),$n=l.useCallback(P=>{if(!F)return;const H=F.clone(),qe=(H.masks||[]).find(Ge=>Ge.id==="quick-image-mask");qe&&(qe.inverted=P,X(H))},[F,X]),so=l.useCallback(P=>{if(!F)return;const H=F.clone();H.stroke=P,X(H)},[F,X]),Yo=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const qe=F.clone();qe.transformData.shapeType=P,X(qe),ge(!1)},[F,X]),Wo=l.useCallback(()=>{o?o():ge(!0)},[o]);l.useEffect(()=>{g==null||g(L!==null),x==null||x((L==null?void 0:L.type)??null)},[L,g,x]),l.useEffect(()=>{const P=(L==null?void 0:L.type)??null;P!==Fe.current&&(Fe.current=P,z(P))},[L,z]),l.useEffect(()=>{const P=Ue.current,H=O;if(P!==H){if(Ue.current=H,P!==null&&H===null&&L!==null){Fe.current=null,ve(null);return}if(H!==null&&(L==null?void 0:L.type)!==H){const Ge={crop:{type:"crop",icon:"lucide:crop",label:"Crop"},cornerRadius:{type:"cornerRadius",icon:"lucide:square-round-corner",label:"Corner Radius"},rotation:{type:"rotation",icon:Re.rotateLeft,label:"Rotate"},opacity:{type:"opacity",icon:"lucide:blend",label:"Transparency"},fontSize:{type:"fontSize",icon:"lucide:type",label:"Font Size"},effects:{type:"effects",icon:"lucide:sparkles",label:"Effects"},shapeCornerRadius:{type:"shapeCornerRadius",icon:"lucide:square-round-corner",label:"Corner Radius"},shapeTransparency:{type:"shapeTransparency",icon:Re.eye,label:"Transparency"},shapeSides:{type:"shapeSides",icon:"lucide:triangle",label:"Sides"},shapePoints:{type:"shapePoints",icon:"lucide:star",label:"Points"},shapeInnerRadius:{type:"shapeInnerRadius",icon:"lucide:circle-dashed",label:"Inner Radius"},shapeColor:{type:"shapeColor",icon:Re.palette,label:"Color"},textColor:{type:"textColor",icon:Re.palette,label:"Color"},stroke:{type:"stroke",icon:"lucide:pen-line",label:"Stroke"},compositing:{type:"compositing",icon:"lucide:scissors",label:"Clip / Knockout"},distressTexture:{type:"distressTexture",icon:"lucide:stamp",label:"Distress Texture"},imageMask:{type:"imageMask",icon:"lucide:venetian-mask",label:"Image Mask"}}[H];Ge&&(Fe.current=H,ve(Ge))}}},[O,L]),l.useEffect(()=>{_(L!==null||Ke!==null||Pe||N||ce||Ie!=="root")},[L,Ke,Pe,N,ce,Ie,_]),l.useEffect(()=>{b||(Je.current!==void 0&&Je.current!==at&&ve(null),Je.current=at)},[at,b]),l.useEffect(()=>{M&&B&&(S==null||S(!1))},[M,B,S]),l.useEffect(()=>{const P=(F==null?void 0:F.transformType)==="image"?F.isCropping:!1;(L==null?void 0:L.type)==="crop"&&it.current===!0&&P===!1&&ve(null),it.current=P},[F,L==null?void 0:L.type]),l.useEffect(()=>{Ft.current=L,$.current=F??null,ee.current=X}),l.useEffect(()=>{const P=setTimeout(()=>{Nt.current=!0},0);return()=>{clearTimeout(P)}},[]),l.useEffect(()=>()=>{var P;if(Nt.current&&gt.current&&((P=Ft.current)==null?void 0:P.type)==="crop"){const H=$.current;if((H==null?void 0:H.transformType)==="image"){const qe=H;if(qe.isCropping){const Ge=qe.clone();Ge.exitCropMode(),ee.current(Ge)}}}},[]),l.useEffect(()=>{let P=null,H=!1;const qe=3,Ge=mn=>{var zn;const Mn=mn.target;(zn=$t.current)!=null&&zn.contains(Mn)||Mn.closest('[data-slot="popover-content"]')||Mn.closest('[data-slot="dialog"]')||Mn.closest('[role="dialog"]')||Mn.closest(".popover-content")||Mn.closest("[data-slot]")||(Ee.current=!0,P={x:mn.clientX,y:mn.clientY},H=!1)},Xt=mn=>{if(P&&!H&&!vt.current){const Mn=mn.clientX-P.x,zn=mn.clientY-P.y;Math.sqrt(Mn*Mn+zn*zn)>qe&&(H=!0,we(!0))}},tn=()=>{Ee.current=!1,P=null,H=!1,we(!1)};return window.addEventListener("mousedown",Ge),window.addEventListener("mousemove",Xt),window.addEventListener("mouseup",tn),()=>{window.removeEventListener("mousedown",Ge),window.removeEventListener("mousemove",Xt),window.removeEventListener("mouseup",tn)}},[]),l.useEffect(()=>{if(!$t.current)return;let P=null;const H=new ResizeObserver(qe=>{P!==null&&clearTimeout(P),P=window.setTimeout(()=>{for(const Ge of qe){const Xt=Ge.contentRect.width,tn=Ge.contentRect.height;Kt(mn=>mn.width===Xt&&mn.height===tn?mn:{width:Xt,height:tn})}},50)});return H.observe($t.current),()=>{H.disconnect(),P!==null&&clearTimeout(P)}},[B]),l.useEffect(()=>{var qe;if(e==="embedded"||oe)return;const P=(qe=G||B)==null?void 0:qe.rotation;if(Qe.current=P,!B){he(null);return}const H=()=>{var Ge,Xt,tn,mn,Mn;try{const zn=((Ge=$t.current)==null?void 0:Ge.offsetWidth)||kt.width||0,Jo=((Xt=$t.current)==null?void 0:Xt.offsetHeight)||kt.height||48,Ii=q==null?void 0:q.current,nr=G||B,fr=nr.transformData,In=((tn=nr.getBoundingBox)==null?void 0:tn.call(nr))||{x:nr.x,y:nr.y,width:(fr==null?void 0:fr.width)||100,height:(fr==null?void 0:fr.height)||50},pr=A.getActiveArtboard(),Ai=(pr==null?void 0:pr.x)||0,Di=(pr==null?void 0:pr.y)||0,An=((Mn=(mn=J==null?void 0:J.current)==null?void 0:mn.getZoom)==null?void 0:Mn.call(mn))||1;let uo,Tr,ho,fo;if(Ii){const Rr=Ii.getBoundingClientRect();uo=Rr.left+(In.x-Ai)*An,Tr=Rr.top+(In.y-Di)*An,ho=In.width*An,fo=In.height*An}else if(h)uo=h.left+(In.x-Ai)*An,Tr=h.top+(In.y-Di)*An,ho=In.width*An,fo=In.height*An;else{const Rr=window.innerWidth/2,es=window.innerHeight/2;uo=Rr-In.width*An/2,Tr=es-In.height*An/2,ho=In.width*An,fo=In.height*An}const Li=12,Bc=Tr,_c=uo+ho/2;let rr=Bc-Jo-Li,Qo=_c;if(zn>0){const es=zn/2+20,$c=window.innerWidth-zn/2-20;Qo=Math.max(es,Math.min($c,Qo))}rr<10&&(rr=Tr+fo+Li);const Hc=window.innerHeight-Jo-10;rr=Math.min(rr,Hc),rr=Math.max(10,rr),he({top:rr,left:Qo}),Tt(nr.id)}catch(zn){Ig.error("Error calculating toolbar position:",zn),he(null)}};return H(),window.addEventListener("resize",H),()=>{window.removeEventListener("resize",H)}},[e,B,G,q,A,J,h,kt,oe,I]);const Ze=ze().color||Q,We=l.useCallback(P=>nt(P),[nt]),Ct=l.useMemo(()=>yg(Y,Z),[Y,Z]),Et=l.useMemo(()=>{const P=new Set(Ct);for(const H of s)P.add(H);return P},[Ct,s]),It=Array.from(Et).sort().join(","),Ht=l.useMemo(()=>Array.from(Et),[It]),qt=l.useMemo(()=>{const P=[],H=new Set,qe=Ge=>{if(Ge instanceof T.ImageElement)Ge.imageUrl&&!H.has(Ge.imageUrl)&&(H.add(Ge.imageUrl),P.push(Ge.imageUrl));else if(Ge instanceof T.GroupElement)for(const Xt of Ge.children)qe(Xt)};for(const Ge of Y)qe(Ge);return P.sort(),P.join("|")},[Y]),[Pt,St]=l.useState([]);l.useEffect(()=>{if(!qt){St([]);return}let P=!1;return Mg(Y).then(H=>{P||St(H)}),()=>{P=!0}},[qt]);const lt=l.useCallback(P=>{if($t&&($t.current=P,P)){const{width:H,height:qe}=P.getBoundingClientRect();H>0&&qe>0&&Kt({width:H,height:qe})}},[]);l.useEffect(()=>{const P=Ye.current,H=k;!P&&H&&te&&($e.current={...te}),P&&!H&&($e.current=null),Ye.current=k},[k,te]),l.useEffect(()=>{const P=je.current,H=Xe.current;if(je.current=Ce,Xe.current=at,!P&&Ce){if(st(!0),e==="embedded"){bt(!1),Ve(!0),ie(!1);const qe=setTimeout(()=>{Ve(!1)},200);return()=>clearTimeout(qe)}bt(!0),Ve(!1),ie(!1);return}if(P&&Ce&&H!==at&&at!==void 0){if(e==="embedded"){Ve(!1);return}bt(!0),Ve(!1),ie(!1);return}if(P&&!Ce){if(k){st(!1),Ve(!1),ie(!1),bt(!1);return}if(e==="embedded"){if(ie(!0),Ve(!1),Ot.current){const Xt=Ot.current.offsetHeight;jt(Xt),requestAnimationFrame(()=>{jt(0)})}const Ge=setTimeout(()=>{st(!1),ie(!1),jt(null)},200);return()=>clearTimeout(Ge)}ie(!0),Ve(!1),bt(!1);const qe=setTimeout(()=>{st(!1),ie(!1),he(null),Tt(null)},150);return()=>clearTimeout(qe)}},[Ce,k,at,e,xt]),l.useEffect(()=>{if(ht&&te&&yt===ft){bt(!1),Ve(!0);const P=setTimeout(()=>{Ve(!1)},200);return()=>clearTimeout(P)}},[ht,te,yt,ft]),l.useLayoutEffect(()=>{if(e!=="embedded")return;const P=dt.current;if(P!==void 0&&xt!==void 0&&P!==xt&&De.current>0&&Rt===null){const qe=De.current;jt(qe),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(Ot.current){const Ge=Ot.current.scrollHeight;jt(Ge),setTimeout(()=>{jt(null)},200)}})})}Ot.current&&Rt===null&&!tt&&!oe&&(De.current=Ot.current.offsetHeight),dt.current=xt},[e,xt,Rt,tt,oe]);const zt=l.useMemo(()=>{const P=f?typeof f=="number"?`${f}px`:f:void 0;if(e==="embedded")return{borderRadius:f?"16px":"9999px",visibility:"visible",position:"static",maxWidth:P,display:"flex",justifyContent:"flex-start"};const H=$e.current||te;return H&&!ht?{top:`${H.top}px`,left:`${H.left}px`,position:"fixed",transform:"translateX(-50%)",borderRadius:f?"16px":"9999px",visibility:"visible",maxWidth:P,zIndex:"var(--z-tooltip)"}:{borderRadius:f?"16px":"9999px",visibility:"hidden",maxWidth:P,position:"fixed",top:"-9999px",left:"-9999px",zIndex:"var(--z-tooltip)"}},[e,te,ht,f]);if(D.length>0)return null;const Pn=n.jsxs(n.Fragment,{children:[Ie==="root"&&F&&n.jsx(Gm,{element:F,onToggleLock:Zt,onThumbnailClick:R}),Ie==="root"&&(F==null?void 0:F.transformType)==="image"&&n.jsx(Wl,{element:F,onElementUpdate:X,showUngroupButton:!!G&&(B==null?void 0:B.transformType)==="group",onUngroup:Qt,onMoveForward:Ut,onMoveBackward:an,onChangeImage:r,onDelete:un,cornerRadiusExpanded:(L==null?void 0:L.type)==="cornerRadius",onCornerRadiusToggle:He,cropExpanded:(L==null?void 0:L.type)==="crop",onCropToggle:Se,rotationExpanded:(L==null?void 0:L.type)==="rotation",onRotationToggle:Be,opacityExpanded:(L==null?void 0:L.type)==="opacity",onOpacityToggle:Ae,strokeExpanded:(L==null?void 0:L.type)==="stroke",onStrokeToggle:rn,knockoutExpanded:(L==null?void 0:L.type)==="compositing",onKnockoutToggle:_t,distressTextureExpanded:(L==null?void 0:L.type)==="distressTexture",onDistressTextureToggle:At,imageMaskExpanded:(L==null?void 0:L.type)==="imageMask",onImageMaskToggle:Dt}),Ie==="root"&&(B==null?void 0:B.transformType)==="group"&&!G&&n.jsx(Zm,{element:B,rotationExpanded:(L==null?void 0:L.type)==="rotation",onRotationToggle:Be,opacityExpanded:(L==null?void 0:L.type)==="opacity",onOpacityToggle:Ae,strokeExpanded:(L==null?void 0:L.type)==="stroke",onStrokeToggle:rn,knockoutExpanded:(L==null?void 0:L.type)==="compositing",onKnockoutToggle:_t,distressTextureExpanded:(L==null?void 0:L.type)==="distressTexture",onDistressTextureToggle:At,imageMaskExpanded:(L==null?void 0:L.type)==="imageMask",onImageMaskToggle:Dt,onUngroup:Qt}),Ie==="root"&&(F==null?void 0:F.transformType)==="shape"&&n.jsx(Xl,{element:F,onElementUpdate:X,documentColors:Ht,imageColors:Pt,showUngroupButton:!!G&&(B==null?void 0:B.transformType)==="group",onUngroup:Qt,onMoveForward:Ut,onMoveBackward:an,onOpenShapeTypeDrawer:Wo,onDelete:un,rotationExpanded:(L==null?void 0:L.type)==="rotation",onRotationToggle:Be,cornerRadiusExpanded:(L==null?void 0:L.type)==="shapeCornerRadius",onCornerRadiusToggle:fe,transparencyExpanded:(L==null?void 0:L.type)==="shapeTransparency",onTransparencyToggle:_e,sidesExpanded:(L==null?void 0:L.type)==="shapeSides",onSidesToggle:Oe,pointsExpanded:(L==null?void 0:L.type)==="shapePoints",onPointsToggle:ot,innerRadiusExpanded:(L==null?void 0:L.type)==="shapeInnerRadius",onInnerRadiusToggle:mt,colorExpanded:(L==null?void 0:L.type)==="shapeColor",onColorToggle:Bt,strokeExpanded:(L==null?void 0:L.type)==="stroke",onStrokeToggle:rn,knockoutExpanded:(L==null?void 0:L.type)==="compositing",onKnockoutToggle:_t,distressTextureExpanded:(L==null?void 0:L.type)==="distressTexture",onDistressTextureToggle:At,imageMaskExpanded:(L==null?void 0:L.type)==="imageMask",onImageMaskToggle:Dt}),Ie==="root"&&(F==null?void 0:F.transformType)==="path"&&n.jsx(Vl,{element:F,onElementUpdate:X,onMoveForward:Ut,onMoveBackward:an}),Ie==="root"&&F&&F.transformType!=="image"&&F.transformType!=="group"&&F.transformType!=="shape"&&F.transformType!=="path"&&n.jsx(cc,{toolbar:W,stableElementId:ft,viewportWidth:i,colorPickerValue:Ze,isColorActive:(L==null?void 0:L.type)==="textColor",onColorToggle:Wt,onOpenGlyphBrowser:t,strokeExpanded:(L==null?void 0:L.type)==="stroke",onStrokeToggle:rn,hasGlyphs:c,expandedPanel:L,onRotationToggle:Be,onOpacityToggle:Ae,onFontSizeToggle:V,knockoutExpanded:(L==null?void 0:L.type)==="compositing",onKnockoutToggle:_t,distressTextureExpanded:(L==null?void 0:L.type)==="distressTexture",onDistressTextureToggle:At,imageMaskExpanded:(L==null?void 0:L.type)==="imageMask",onImageMaskToggle:Dt,getMoreMenuItems:d,onMoveForward:Ut,onMoveBackward:an,onDelete:un,elementForProperties:F,elements:Y,isTransformMenuOpen:Pe,onTransformMenuOpenChange:me,elementUpdateHandler:X,showUngroupButton:!!G&&(B==null?void 0:B.transformType)==="group",onUngroup:Qt,isFontBrowserOpen:Ke==="fontFamily",onFontBrowserToggle:P=>re(P?"fontFamily":null),onTextMoreMenuOpenChange:le}),Ie==="color"&&n.jsxs("div",{className:"toolbar-items",children:[n.jsx(Am,{onClick:()=>ke("root")}),n.jsxs("div",{className:"toolbar-scroll",children:[n.jsx("input",{className:"toolbar-color",type:"color",value:Q,onChange:P=>{nt(P)}}),n.jsx("span",{className:"toolbar-label",children:Q})]})]})]}),ut=(F==null?void 0:F.transformType)==="shape"?F:null,cn=pt?n.jsx("div",{ref:lt,className:"toolbar","data-mode":e,"data-wrap":f?"":void 0,"data-transparent":p?"":void 0,"data-panel-expanded":L?"":void 0,"data-preserve-selection":!0,style:{...zt,opacity:k?0:1,pointerEvents:k?"none":"auto",transition:"opacity 0.05s ease-out"},"data-entering":tt?"":void 0,"data-exiting":oe?"":void 0,children:n.jsxs("div",{className:"toolbar-slide-container",children:[n.jsx("div",{className:"toolbar-regular-content","data-hidden":L?"":void 0,children:Pn}),n.jsx("div",{className:"toolbar-collapsed-header","data-visible":L?"":void 0,children:L&&n.jsx(Ps,{icon:n.jsx(mg,{panelType:L.type,defaultIcon:L.icon,textColorValue:Ze,shapeFillColor:(gi=ut==null?void 0:ut.transformData)==null?void 0:gi.fillColor}),label:L.label,onClose:Lt,closeButtonStyle:w})})]})}):null,fn=(L==null?void 0:L.type)==="cornerRadius",jn=(L==null?void 0:L.type)==="crop",Fn=(L==null?void 0:L.type)==="rotation",Cn=(L==null?void 0:L.type)==="opacity",En=(L==null?void 0:L.type)==="fontSize",dn=(L==null?void 0:L.type)==="shapeCornerRadius",Kn=(L==null?void 0:L.type)==="shapeTransparency",ur=(L==null?void 0:L.type)==="shapeSides",hr=(L==null?void 0:L.type)==="shapePoints",Un=(L==null?void 0:L.type)==="shapeInnerRadius",pn=(L==null?void 0:L.type)==="shapeColor",qn=(L==null?void 0:L.type)==="textColor",Sn=(L==null?void 0:L.type)==="compositing",bn=(L==null?void 0:L.type)==="distressTexture",Sr=(L==null?void 0:L.type)==="stroke",kr=(L==null?void 0:L.type)==="imageMask",jr=(F==null?void 0:F.transformType)==="image"&&((xi=F.transformData)==null?void 0:xi.borderRadius)||0,io=(F==null?void 0:F.rotation)||0,ao=(F==null?void 0:F.opacity)??1,lo=((bi=ut==null?void 0:ut.transformData)==null?void 0:bi.borderRadius)||0,co=((yi=ut==null?void 0:ut.transformData)==null?void 0:yi.fillOpacity)??1,Xo=((vi=ut==null?void 0:ut.transformData)==null?void 0:vi.sides)||5,Vo=((wi=ut==null?void 0:ut.transformData)==null?void 0:wi.points)||5,Tn=((Ci=ut==null?void 0:ut.transformData)==null?void 0:Ci.innerRadius)||.4,Er=((Si=ut==null?void 0:ut.transformData)==null?void 0:Si.fillColor)||"#3b82f6",Go=((ki=F==null?void 0:F.knockoutParts)==null?void 0:ki.fill)??!1,Ko=((ji=F==null?void 0:F.knockoutParts)==null?void 0:ji.stroke)??!1,Rn=((Ei=F==null?void 0:F.knockoutParts)==null?void 0:Ei.scope)??"group",qo=(F==null?void 0:F.blendMode)==="clip"?"clip":"knockout",Zo=fn&&(F==null?void 0:F.transformType)==="image"?n.jsx(Qm,{value:jr,onChange:Mt}):null,bc=jn&&(F==null?void 0:F.transformType)==="image"?n.jsx(pg,{element:F,onElementUpdate:X}):null,yc=Fn&&F?n.jsx(eg,{value:io,onChange:hn,onRotate90:en}):null,vc=Cn&&F?n.jsx(ng,{value:ao,onChange:xn}):null,wc=En?n.jsx(tg,{value:W.fontSize,onChange:W.handleFontSizeChange,widthValue:ne,onWidthChange:xe}):null,Cc=dn&&ut?n.jsx(rg,{value:lo,onChange:ue}):null,Sc=Kn&&ut?n.jsx(og,{value:co,onChange:et}):null,kc=ur&&ut?n.jsx(sg,{value:Xo,onChange:K}):null,jc=hr&&ut?n.jsx(ig,{value:Vo,onChange:be}):null,Ec=Un&&ut?n.jsx(ag,{value:Tn,onChange:Te}):null,Tc=pn&&ut?n.jsx(lg,{value:Er,onChange:Ne,documentColors:Ht,imageColors:Pt}):null,Rc=qn&&F?n.jsx(cg,{value:Ze,onChange:We,documentColors:Ht,imageColors:Pt}):null,Nc=Sn&&F?n.jsx(dg,{mode:qo,fill:Go,stroke:Ko,scope:Rn,onModeChange:Yn,onFillChange:er,onStrokeChange:wn,onScopeChange:cr}):null,Mc=Sr&&F?n.jsx(fg,{stroke:F.stroke,onChange:so,documentColors:Ht,imageColors:Pt}):null,Ic=bn&&F?n.jsx(ug,{textureUrl:((Ti=F.distressEffect)==null?void 0:Ti.textureUrl)??"",opacity:Math.round((((Ri=F.distressEffect)==null?void 0:Ri.textureOpacity)??.5)*100),onTextureChange:dr,onOpacityChange:Gn}):null,Nn=(Ni=F==null?void 0:F.masks)==null?void 0:Ni.find(P=>P.id==="quick-image-mask"),Ac=kr&&F?n.jsx(hg,{imageUrl:((Mi=Nn==null?void 0:Nn.maskElement)==null?void 0:Mi.imageUrl)??"",maskType:(Nn==null?void 0:Nn.type)??"clip",opacity:Math.round(((Nn==null?void 0:Nn.opacity)??1)*100),inverted:(Nn==null?void 0:Nn.inverted)??!1,onImageChange:tr,onMaskTypeChange:ln,onOpacityChange:Hn,onInvertedChange:$n}):null,Dc=e==="embedded"&&!B&&!M?j?n.jsx("div",{className:"toolbar-empty-state",children:j}):C!==null?n.jsx("div",{className:"toolbar-empty-state",style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"16px 24px",color:"var(--foreground)",opacity:.5,fontSize:"14px",textAlign:"center"},children:C}):null:null,Lc=e==="embedded"&&M&&!B&&A.getActiveArtboard()?n.jsxs("div",{className:"px-4 py-3 flex flex-col gap-3",children:[n.jsx(Ps,{icon:"lucide:palette",label:"Artboard Properties",onClose:()=>S==null?void 0:S(!1),closeButtonStyle:"done"}),n.jsx(Gl,{distressTexture:A.getActiveArtboard().distressTexture,onChange:P=>{const H=A.getActiveArtboard();u?u(H.id,{distressTexture:H.distressTexture},{distressTexture:P}):(A.updateArtboard(H.id,{distressTexture:P}),U())}}),n.jsx(Kl,{imageMask:A.getActiveArtboard().imageMask,onChange:P=>{const H=A.getActiveArtboard();u?u(H.id,{imageMask:H.imageMask},{imageMask:P}):(A.updateArtboard(H.id,{imageMask:P}),U())}})]}):null,Pc=e==="embedded"?n.jsx(gg,{toolbarContent:cn,innerContentRef:Ot,shouldRender:pt,isExiting:oe,transitionHeight:Rt,emptyStateContent:Lc||Dc,isCornerRadiusPanelOpen:fn,isCropPanelOpen:jn,isRotationPanelOpen:Fn,isOpacityPanelOpen:Cn,isFontSizePanelOpen:En,isShapeCornerRadiusPanelOpen:dn,isShapeTransparencyPanelOpen:Kn,isShapeSidesPanelOpen:ur,isShapePointsPanelOpen:hr,isShapeInnerRadiusPanelOpen:Un,isShapeColorPanelOpen:pn,isTextColorPanelOpen:qn,isStrokePanelOpen:Sr,isKnockoutPanelOpen:Sn,isDistressTexturePanelOpen:bn,isImageMaskPanelOpen:kr,cornerRadiusPanel:Zo,cropPanelContent:bc,rotationPanel:yc,opacityPanel:vc,fontSizePanel:wc,shapeCornerRadiusPanel:Cc,shapeTransparencyPanel:Sc,shapeSidesPanel:kc,shapePointsPanel:jc,shapeInnerRadiusPanel:Ec,shapeColorPanel:Tc,textColorPanel:Rc,strokePanel:Mc,knockoutPanel:Nc,distressTexturePanel:Ic,imageMaskPanel:Ac}):null,Fc=kt.width>0?Math.max(kt.width,200):280,zc=e==="floating"&&fn&&(F==null?void 0:F.transformType)==="image"&&te?n.jsx(xg,{toolbarPosition:te,toolbarHeight:kt.height||56,panelWidth:Fc,value:jr,onChange:Mt}):null,Oc=e==="floating"&&jn&&(F==null?void 0:F.transformType)==="image"&&te?n.jsx(bg,{toolbarPosition:te,toolbarHeight:kt.height||56,element:F,onElementUpdate:X}):null;return n.jsxs(n.Fragment,{children:[e==="floating"&&typeof document<"u"?Qn.createPortal(n.jsxs(n.Fragment,{children:[cn,zc,Oc]}),document.body):Pc,e!=="embedded"&&!B&&A.getActiveArtboard()&&u&&n.jsx(ql,{artboard:A.getActiveArtboard(),artboards:Z,onArtboardUpdate:P=>{const H=A.getActiveArtboard();u(H.id,{backgroundColor:H.backgroundColor,backgroundType:H.backgroundType,backgroundTexture:H.backgroundTexture,exportBackground:H.exportBackground},{backgroundColor:P.backgroundColor,backgroundType:P.backgroundType,backgroundTexture:P.backgroundTexture,exportBackground:P.exportBackground})},onRenameArtboard:(P,H)=>{A.renameArtboard(P,H),U()},onDeleteArtboard:P=>{A.deleteArtboard(P),U()},artboardScreenBounds:h}),!o&&(F==null?void 0:F.transformType)==="shape"&&n.jsx(fi,{isOpen:Me,onClose:()=>ge(!1),onSelectType:Yo,currentType:F.transformData.shapeType})]})},Ag=Object.freeze(Object.defineProperty({__proto__:null,ContextualToolbars:Ws,default:Ws},Symbol.toStringTag,{value:"Module"})),Xs=({className:e,position:t="bottom-right",showFitButton:r=!0,showResetButton:o=!0})=>{const{zoom:s,zoomIn:i,zoomOut:a,zoomToFit:c,resetView:d}=Yt.useViewportContext(),u=Math.round(s*100),h={"bottom-left":{bottom:16,left:16},"bottom-right":{bottom:16,right:16},"top-left":{top:16,left:16},"top-right":{top:16,right:16}};return n.jsxs("div",{className:e,style:{position:"absolute",...h[t],display:"flex",alignItems:"center",gap:4,padding:4,backgroundColor:"var(--surface)",borderRadius:"var(--radius-lg)",boxShadow:"var(--shadow-md)",zIndex:"var(--z-sticky)"},children:[n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:a,disabled:s<=.1,"aria-label":"Zoom out",children:n.jsx(de,{icon:Re.minus,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Zoom out"})]}),n.jsxs("div",{style:{minWidth:48,textAlign:"center",fontSize:13,fontWeight:500,color:"var(--foreground)",fontVariantNumeric:"tabular-nums"},children:[u,"%"]}),n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:i,disabled:s>=4,"aria-label":"Zoom in",children:n.jsx(de,{icon:Re.plus,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Zoom in"})]}),(r||o)&&n.jsx("div",{style:{width:1,height:20,backgroundColor:"var(--divider)",margin:"0 4px"}}),r&&n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:c,"aria-label":"Fit to screen",children:n.jsx(de,{icon:Re.fitScreen,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Fit to screen"})]}),o&&n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:d,"aria-label":"Reset to 100%",children:n.jsx(de,{icon:Re.maximize,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Reset to 100%"})]})]})},Dg=Object.freeze(Object.defineProperty({__proto__:null,ZoomControls:Xs,default:Xs},Symbol.toStringTag,{value:"Module"})),pc=({trigger:e,children:t,isOpen:r,onToggle:o,position:s="bottom",align:i="start",offset:a=8,protectClick:c=!0,className:d="",contentClassName:u=""})=>{const h=l.useRef(null),f=l.useRef(null),p=l.useRef(null),[g,b]=l.useState({}),[x,y]=l.useState(!1),v=C=>{C.stopPropagation(),!r&&c&&ti.protectNextClick(),o(!r)};l.useEffect(()=>{if(!r)return;let C=()=>{};const j=setTimeout(()=>{const M=S=>{var E,O;const R=S.target,I=(E=h.current)==null?void 0:E.contains(R),D=(O=p.current)==null?void 0:O.contains(R);!I&&!D&&o(!1)};document.addEventListener("mousedown",M),C=()=>document.removeEventListener("mousedown",M)},0);return()=>{clearTimeout(j),C()}},[r,o]),l.useEffect(()=>{if(!r)return;const C=j=>{var M;if(j.key==="Escape"){j.stopPropagation(),j.preventDefault(),o(!1);const S=(M=f.current)==null?void 0:M.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');S==null||S.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[r,o]),l.useEffect(()=>{r||y(!1)},[r]),l.useEffect(()=>{if(!r||!f.current||!p.current)return;requestAnimationFrame(()=>{const j=f.current,M=p.current;if(!j||!M)return;const S=j.getBoundingClientRect(),R=M.getBoundingClientRect(),I=window.innerWidth,D=window.innerHeight,E=16;let O=0,z=0;if(s==="bottom"||s==="top"?(s==="bottom"?O=S.bottom+a:O=S.top-R.height-a,i==="start"?z=S.left:i==="end"?z=S.right-R.width:i==="center"&&(z=S.left+(S.width-R.width)/2)):(s==="left"||s==="right")&&(s==="left"?z=S.left-R.width-a:z=S.right+a,i==="start"?O=S.top:i==="end"?O=S.bottom-R.height:i==="center"&&(O=S.top+(S.height-R.height)/2)),i!=="end"&&z+R.width>I-E&&(z=I-R.width-E),z<E&&(z=E),O+R.height>D-E){const k=S.top,Y=D-S.bottom;k>Y&&(O=S.top-R.height-a)}O<E&&(O=E);const _=I-E*2;y(!0),b({position:"fixed",top:`${O}px`,left:`${z}px`,maxWidth:`${_}px`,visibility:"visible"})})},[r,s,i,a]);const w=r&&n.jsx("div",{ref:p,className:`z-dropdown ${u}`.trim(),"data-preserve-selection":!0,style:x?g:{position:"fixed",visibility:"hidden",top:0,left:0},children:t});return n.jsxs("div",{className:`relative inline-flex ${d}`.trim(),ref:h,children:[n.jsx("div",{ref:f,onClick:v,children:e}),w&&Qn.createPortal(w,document.body)]})},Vs=({children:e,className:t="",minWidth:r="160px",maxHeight:o})=>{const s=o?`max-h-[${o}]`:"",i={minWidth:r};return n.jsx("div",{role:"menu",className:`flex flex-col gap-px rounded-xl border border-border-primary bg-surface p-xs shadow-md ${s} ${t}`.trim(),style:i,children:e})},ar=({icon:e,label:t,shortcut:r,active:o=!1,disabled:s=!1,onClick:i,className:a="",children:c,...d})=>{const u=["flex items-center gap-md","px-lg py-md","bg-transparent border-none","rounded-lg","text-text-primary text-base font-normal","cursor-pointer","transition-all duration-fast","text-left w-full"],h=[o?"bg-accent-light font-medium":"",s?"opacity-disabled cursor-not-allowed":"hover:bg-bg-hover"],f=[...u,...h,a].filter(Boolean).join(" "),p=()=>{!s&&i&&i()};return n.jsxs("button",{role:"menuitem",className:f,onClick:p,disabled:s,type:"button",...d,children:[e&&n.jsx("span",{className:"flex shrink-0 items-center",children:e}),n.jsx("span",{className:"flex-1",children:c||t}),r&&n.jsx("span",{className:"ml-auto text-sm text-text-muted",children:r}),o&&!r&&n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:"ml-auto shrink-0",children:n.jsx("path",{d:"M13 4L6 11L3 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})]})},ks=T.createLogger("MenuButton"),mc=({isLayersPanelOpen:e=!1,onToggleLayersPanel:t,onOpenImageBrowser:r,additionalItems:o,icon:s=n.jsx(de,{icon:Re.menu,className:"size-6"}),tooltip:i="Menu",className:a})=>{const{artboardManager:c,elements:d,canvasRef:u,handleLoadWorkspace:h,handleAddElement:f}=Yt.useEditor(),[p,g]=l.useState(!1),[b,x]=l.useState(!1),[y,v]=l.useState(!1),w=l.useRef(null),C=()=>{try{const O=c.getAllArtboards();rt.ExportManager.exportToJSON(O,d,c),g(!1)}catch(O){ks.error("Failed to save workspace:",O),alert("Failed to save workspace. Please try again.")}},j=()=>{var O;(O=w.current)==null||O.click(),g(!1)},M=async O=>{var _;const z=(_=O.target.files)==null?void 0:_[0];if(z){try{const k=await rt.ImportManager.importFromJSON(z);if(k.success&&k.artboards&&k.elements){const Y=rt.ImportManager.validateImportedData(k.artboards,k.elements);if(!Y.valid&&!confirm(`Found ${Y.errors.length} issue(s) in the file:
29
+ `,style:{fontFamily:e},children:[_,Z>0&&n.jsx("span",{className:`absolute -right-[4px] -top-[4px] min-w-lg rounded-full border-2 border-surface px-xs py-[2px] text-center text-3xs font-semibold leading-none shadow-md ${se?"bg-success text-success-foreground":"bg-info text-info-foreground"}`,children:Z})]},G)})})]}),!f&&e&&u.length>0&&n.jsx(n.Fragment,{children:Object.entries(Y).map(([_,G])=>{const se=G.filter(A=>u.includes(A.tag));return se.length===0?null:n.jsxs("div",{className:"mb-lg",children:[n.jsx("div",{className:"mb-sm text-2xs font-semibold uppercase tracking-wide text-text-secondary",children:_}),n.jsx("div",{className:"flex flex-col gap-sm",children:se.map(A=>n.jsxs("label",{className:"flex cursor-pointer items-start gap-sm rounded p-xs transition-colors duration-fast hover:bg-surface",children:[n.jsx("input",{type:"checkbox",checked:(o==null?void 0:o[A.tag])||!1,onChange:()=>D(A.tag),className:"mt-[2px] h-4 w-4 cursor-pointer rounded border-border-primary bg-bg-input accent-accent-primary"}),n.jsxs("div",{className:"flex-1",children:[n.jsx("div",{className:"text-sm font-medium",children:A.label}),n.jsx("div",{className:"mt-[2px] text-2xs text-text-secondary",children:A.description})]})]},A.tag))})]},_)})})]}),e&&n.jsx(am,{isOpen:g,onClose:()=>b(!1),character:v,charIndex:x,fontFamily:e,fontWeight:t,currentGlyphOverride:s.find(_=>_.charIndex===x),onSelectGlyph:z,browseAll:C})]})},dm=({element:e,onElementUpdate:t,isOpen:r,onClose:o})=>{var p,g;const[s,i]=l.useState("stroke");if(!e)return null;const a=(p=e.stroke)==null?void 0:p.enabled,c=e.masks&&e.masks.length>0,d=(g=e.distressEffect)==null?void 0:g.enabled,u=e.blendMode==="knockout"||e.blendMode==="clip",h=e instanceof T.TextElement,f=h&&(e.glyphOverrides&&e.glyphOverrides.length>0||e.openTypeFeatures&&Object.keys(e.openTypeFeatures).length>0);return n.jsx(oo,{isOpen:r,onClose:o,title:"Layer Effects",description:"Configure stroke, masks, distress, and knockout effects",maxHeight:"90vh",placement:"right",maxWidth:"600px",children:n.jsxs(m.Tabs,{value:s,onValueChange:b=>i(b),className:"flex flex-col h-full",children:[n.jsx(m.Tabs.ListContainer,{className:"px-6",children:n.jsxs(m.Tabs.List,{"aria-label":"Effect types",children:[n.jsxs(m.Tabs.Tab,{id:"stroke",children:[n.jsx(de,{icon:Re.minus,className:"size-4"}),"Stroke",a&&n.jsx(m.Badge,{variant:"default",className:"ml-2 size-2 rounded-full p-0"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"masks",children:[n.jsx(de,{icon:Re.group,className:"size-4"}),"Masks",c&&n.jsx(m.Badge,{variant:"default",className:"ml-2 size-2 rounded-full p-0"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"distress",children:[n.jsx(de,{icon:"lucide:cloud",className:"size-4"}),"Distress",d&&n.jsx(m.Badge,{variant:"default",className:"ml-2 size-2 rounded-full p-0"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"compositing",children:[n.jsx(de,{icon:Re.scissors,className:"size-4"}),"Knockout",u&&n.jsx(m.Badge,{variant:"default",className:"ml-2 size-2 rounded-full p-0"}),n.jsx(m.Tabs.Indicator,{})]}),h&&n.jsxs(m.Tabs.Tab,{id:"typography",children:[n.jsx(de,{icon:Re.text,className:"size-4"}),"Typography",f&&n.jsx(m.Badge,{variant:"default",className:"ml-2 size-2 rounded-full p-0"}),n.jsx(m.Tabs.Indicator,{})]})]})}),n.jsxs(m.Tabs.Panel,{id:"stroke",className:"flex-1 overflow-y-auto p-6",children:[n.jsx(zp,{stroke:e.stroke,onChange:b=>{const x=e.clone();x.stroke=b,t(x)}}),n.jsx("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted",children:[n.jsx(de,{icon:"lucide:lightbulb",className:"size-4 shrink-0 mt-0.5"}),n.jsx("span",{children:"Add outlines to text and shapes"})]})})]}),n.jsxs(m.Tabs.Panel,{id:"masks",className:"flex-1 overflow-y-auto p-6",children:[n.jsx(_p,{masks:e.masks,onChange:b=>{const x=e.clone();x.masks=b,t(x)}}),n.jsx("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted",children:[n.jsx(de,{icon:"lucide:lightbulb",className:"size-4 shrink-0 mt-0.5"}),n.jsx("span",{children:"Use masks to control visibility"})]})})]}),n.jsxs(m.Tabs.Panel,{id:"distress",className:"flex-1 overflow-y-auto p-6",children:[n.jsx(tm,{distressEffect:e.distressEffect,onChange:b=>{const x=e.clone();x.distressEffect=b,t(x)}}),n.jsx("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted",children:[n.jsx(de,{icon:"lucide:lightbulb",className:"size-4 shrink-0 mt-0.5"}),n.jsx("span",{children:"Add vintage/grunge effects for t-shirt designs"})]})})]}),n.jsxs(m.Tabs.Panel,{id:"compositing",className:"flex-1 overflow-y-auto p-6",children:[n.jsx(sm,{blendMode:e.blendMode,knockoutParts:e.knockoutParts,onChange:(b,x)=>{const y=e.clone();y.blendMode=b,y.knockoutParts=x,t(y)}}),n.jsx("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted",children:[n.jsx(de,{icon:"lucide:lightbulb",className:"size-4 shrink-0 mt-0.5"}),n.jsx("span",{children:"Use Artboard scope for t-shirts, Group scope for patterns"})]})})]}),h&&n.jsxs(m.Tabs.Panel,{id:"typography",className:"flex-1 overflow-y-auto p-6",children:[n.jsx(cm,{fontFamily:e.fontFamily,fontWeight:e.bold?700:400,text:e.text,openTypeFeatures:e.openTypeFeatures,glyphOverrides:e.glyphOverrides,onChange:b=>{const x=e.clone();x.openTypeFeatures=b,t(x)},onGlyphOverridesChange:b=>{const x=e.clone();x.glyphOverrides=b,t(x)}}),n.jsx("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"flex items-start gap-2 text-xs text-muted",children:[n.jsx(de,{icon:"lucide:lightbulb",className:"size-4 shrink-0 mt-0.5"}),n.jsx("span",{children:"Enable advanced OpenType features like ligatures and stylistic sets"})]})})]})]})})},Yl=({isOpen:e,onClose:t,element:r,onElementUpdate:o,style:s,className:i})=>{const{selectedElement:a,executeElementUpdate:c}=Yt.useEditor(),d=r!==void 0?r:a||null,u=l.useCallback(h=>{o?o(h):d&&c(d,h)},[o,c,d]);return n.jsx("div",{style:s,className:i,children:n.jsx(dm,{element:d,onElementUpdate:u,isOpen:e,onClose:t})})},um=Object.freeze(Object.defineProperty({__proto__:null,EffectsPanel:Yl},Symbol.toStringTag,{value:"Module"})),hm=T.createLogger("useExport");function Wl(){const{artboards:e,artboardManager:t,elements:r,canvasRef:o}=Yt.useEditor(),[s,i]=l.useState(!1),[a,c]=l.useState(!1),[d,u]=l.useState([]),[h,f]=l.useState({}),[p,g]=l.useState({totalExports:0,avgExportTime:0,isWorkerActive:!1}),b=l.useRef(0),x=l.useRef(null),y=rt.ExportManager.supportsWorkerExport(),v=l.useCallback(async(I,D={})=>{const E=e.find(z=>z.id===I);if(!E)throw new Error(`[useExport] Artboard ${I} not found`);if(!o.current)throw new Error("[useExport] Canvas ref not available");i(!0);const O={artboardId:I,artboardName:E.name,status:"rendering",progress:0,timestamp:Date.now()};u(z=>[...z,O]);try{const z=Date.now(),B=C.current,k=t.getElementsOnArtboard(I),Y=B.filter(se=>k.includes(se.id)),_=await rt.ExportManager.exportArtboardToDataURL(E,Y,o.current,{format:D.format||"png",scale:D.scale||3,transparentBackground:D.transparentBackground??!0,...D}),G=Date.now()-z;return u(se=>se.map(A=>A.artboardId===I?{...A,status:"complete",progress:100,dataUrl:_,timestamp:Date.now()}:A)),f(se=>({...se,[I]:_})),g(se=>({totalExports:se.totalExports+1,avgExportTime:(se.avgExportTime*se.totalExports+G)/(se.totalExports+1),isWorkerActive:y})),_}catch(z){throw u(B=>B.map(k=>k.artboardId===I?{...k,status:"error",error:z,timestamp:Date.now()}:k)),z}finally{i(!1)}},[e,t,r,o,y]),w=l.useCallback(async(I={})=>{i(!0);try{const D=e.map(async z=>{const B=await v(z.id,I);return{id:z.id,dataUrl:B}}),E=await Promise.all(D),O={};for(const{id:z,dataUrl:B}of E)O[z]=B;return O}finally{i(!1)}},[e,v]),C=l.useRef(r);C.current=r;const j=l.useCallback(async(I,D={})=>{const E=e.find(O=>O.id===I);if(!E)throw new Error(`[useExport] Artboard ${I} not found`);if(!o.current)throw new Error("[useExport] Canvas ref not available");i(!0);try{const O=C.current,z=t.getElementsOnArtboard(I),B=O.filter(Y=>z.includes(Y.id));return await rt.ExportManager.exportArtboardToBlob(E,B,o.current,{format:D.format||"png",scale:D.scale||3,transparentBackground:D.transparentBackground??!0,...D})}finally{i(!1)}},[e,t,r,o]),M=l.useCallback(async(I={})=>{i(!0);try{const D=e.map(async z=>{const B=await j(z.id,I);return{id:z.id,blob:B}}),E=await Promise.all(D),O={};for(const{id:z,blob:B}of E)O[z]=B;return O}finally{i(!1)}},[e,j]),S=l.useCallback(()=>{b.current++,c(!1),x.current=null},[]),R=l.useCallback(I=>{b.current++;const D=b.current;x.current=I,c(!0);const{artboardIds:E,interval:O=500,scale:z=3,format:B="png",onChange:k}=I,Y=E?e.filter(A=>E.includes(A.id)):e,_=()=>b.current===D,G=async()=>{try{const A=Y.map(async q=>{const ae=await v(q.id,{scale:z,format:B,transparentBackground:!0});return{id:q.id,dataUrl:ae}}),Z=await Promise.all(A),J={};for(const{id:q,dataUrl:ae}of Z)J[q]=ae;f(q=>({...q,...J})),k&&k(J)}catch(A){hm.error("[useExport] Continuous export error:",A)}};(async()=>{for(await G();_()&&(await new Promise(A=>setTimeout(A,O)),!!_());)await G()})()},[e,v]);return l.useEffect(()=>()=>{S()},[S]),{exportArtboard:v,exportArtboardAsBlob:j,exportAllArtboards:w,exportAllArtboardsAsBlobs:M,startContinuousExport:R,stopContinuousExport:S,isExporting:s,isContinuousExporting:a,progress:d,latestExports:h,supportsWorkerExport:y,workerStats:p}}const Ca=T.createLogger("ExportPanel"),Xl=({showContinuousExport:e=!0,defaultScale:t=3,defaultFormat:r="png",onExportComplete:o,style:s={},className:i=""})=>{const{exportArtboard:a,exportAllArtboards:c,startContinuousExport:d,stopContinuousExport:u,isExporting:h,isContinuousExporting:f,progress:p,supportsWorkerExport:g,workerStats:b}=Wl(),{artboardsInfo:x,activeArtboardId:y}=Qr(),[v,w]=l.useState(t),[C,j]=l.useState(r),[M,S]=l.useState(500),R=async()=>{if(y)try{const E=await a(y,{scale:v,format:C}),O=document.createElement("a"),z=x.find(Y=>Y.id===y),B=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19),k=(z==null?void 0:z.name)||"artboard";O.download=`${k}-${B}.${C}`,O.href=E,O.click(),o&&o({[y]:E})}catch(E){Ca.error("Export failed:",E),alert("Export failed. Please try again.")}},I=async()=>{try{const E=await c({scale:v,format:C}),O=new Date().toISOString().replace(/[:.]/g,"-").slice(0,19);Object.entries(E).forEach(([z,B])=>{const k=x.find(G=>G.id===z),Y=(k==null?void 0:k.name)||z,_=document.createElement("a");_.download=`${Y}-${O}.${C}`,_.href=B,_.click()}),o&&o(E)}catch(E){Ca.error("Export all failed:",E),alert("Export failed. Please try again.")}},D=()=>{f?u():d({interval:M,scale:v,format:C,onChange:E=>{o&&o(E)}})};return n.jsxs("div",{className:`export-panel ${i}`,style:{width:300,padding:16,backgroundColor:"var(--bg-primary)",border:"1px solid var(--border-primary)",borderRadius:8,...s},children:[n.jsx("h3",{style:{margin:"0 0 16px 0",fontSize:16,fontWeight:600},children:"Export Settings"}),n.jsxs("div",{style:{marginBottom:16},children:[n.jsx("label",{htmlFor:"export-scale",style:{display:"block",fontSize:13,marginBottom:4,fontWeight:500},children:"Scale"}),n.jsxs("select",{id:"export-scale",value:v,onChange:E=>w(Number(E.target.value)),style:{width:"100%",padding:8,fontSize:13,border:"1px solid var(--border-primary)",borderRadius:4,marginBottom:12},children:[n.jsx("option",{value:1,children:"1x (Original)"}),n.jsx("option",{value:2,children:"2x (Retina)"}),n.jsx("option",{value:3,children:"3x (High-Res)"}),n.jsx("option",{value:4,children:"4x (Ultra)"})]}),n.jsx("label",{htmlFor:"export-format",style:{display:"block",fontSize:13,marginBottom:4,fontWeight:500},children:"Format"}),n.jsxs("select",{id:"export-format",value:C,onChange:E=>j(E.target.value),style:{width:"100%",padding:8,fontSize:13,border:"1px solid var(--border-primary)",borderRadius:4,marginBottom:12},children:[n.jsx("option",{value:"png",children:"PNG (Transparent)"}),n.jsx("option",{value:"jpg",children:"JPEG (Smaller)"})]}),e&&n.jsxs(n.Fragment,{children:[n.jsx("label",{htmlFor:"export-interval",style:{display:"block",fontSize:13,marginBottom:4,fontWeight:500},children:"Continuous Export Interval"}),n.jsxs("select",{id:"export-interval",value:M,onChange:E=>S(Number(E.target.value)),style:{width:"100%",padding:8,fontSize:13,border:"1px solid var(--border-primary)",borderRadius:4,marginBottom:12},children:[n.jsx("option",{value:250,children:"250ms (Fast)"}),n.jsx("option",{value:500,children:"500ms (Recommended)"}),n.jsx("option",{value:1e3,children:"1s (Slow)"}),n.jsx("option",{value:2e3,children:"2s (Very Slow)"})]})]})]}),n.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:8,marginBottom:16},children:[n.jsxs("button",{onClick:R,disabled:h||!y,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:12,backgroundColor:"var(--accent-primary)",color:"var(--primary-foreground)",border:"none",borderRadius:6,cursor:h||!y?"not-allowed":"pointer",fontSize:14,fontWeight:500,opacity:h||!y?.5:1},children:[n.jsx(de,{icon:Re.download,className:"size-4"}),h?"Exporting...":"Export Active Artboard"]}),n.jsxs("button",{onClick:I,disabled:h||x.length===0,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:12,backgroundColor:"var(--bg-secondary)",color:"var(--text-primary)",border:"1px solid var(--border-primary)",borderRadius:6,cursor:h||x.length===0?"not-allowed":"pointer",fontSize:14,fontWeight:500,opacity:h||x.length===0?.5:1},children:[n.jsx(de,{icon:Re.image,className:"size-4"}),h?"Exporting...":"Export All Artboards"]}),e&&n.jsxs("button",{onClick:D,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:8,padding:12,backgroundColor:f?"var(--danger)":"var(--success)",color:f?"var(--danger-foreground)":"var(--success-foreground)",border:"none",borderRadius:6,cursor:"pointer",fontSize:14,fontWeight:500},children:[f?n.jsx(de,{icon:Re.pause,className:"size-4"}):n.jsx(de,{icon:Re.play,className:"size-4"}),f?"Stop Continuous Export":"Start Continuous Export"]})]}),p.length>0&&n.jsxs("div",{style:{padding:12,backgroundColor:"var(--bg-secondary)",borderRadius:6,fontSize:12,marginBottom:16},children:[n.jsx("div",{style:{fontWeight:600,marginBottom:8},children:"Export Progress"}),p.slice(-3).map(E=>n.jsxs("div",{style:{display:"flex",justifyContent:"space-between",marginBottom:4},children:[n.jsx("span",{children:E.artboardName}),n.jsx("span",{style:{color:E.status==="complete"?"var(--success)":"var(--text-secondary)"},children:E.status==="complete"?"✓":E.status==="error"?"✗":"..."})]},E.artboardId))]}),g&&n.jsxs("div",{style:{padding:12,backgroundColor:"var(--bg-secondary)",borderRadius:6,fontSize:11},children:[n.jsx("div",{style:{fontWeight:600,marginBottom:4},children:"Worker Export Enabled ✓"}),n.jsxs("div",{style:{opacity:.7},children:["Total Exports: ",b.totalExports,n.jsx("br",{}),"Avg Time: ",b.avgExportTime.toFixed(0),"ms"]})]})]})},fm=Object.freeze(Object.defineProperty({__proto__:null,ExportPanel:Xl},Symbol.toStringTag,{value:"Module"})),fs={},pm=T.createLogger("nounProjectApi"),mm=(fs==null?void 0:fs.VITE_NOUN_PROJECT_PROXY_URL)||"http://localhost:3001",gm=mm,wo=()=>!0,xm=e=>{var o,s,i;const t=(o=e.icon_url)==null?void 0:o.includes(".svg"),r=t?e.icon_url:void 0;return{id:`noun-${e.id}`,urls:{svg:r,png:e.icon_url&&!t?e.icon_url:e.thumbnail_url,preview:e.preview_url_200||e.preview_url_84||e.thumbnail_url,thumbnail:e.thumbnail_url},term:e.term,attribution:e.attribution||null,uploader:{name:((s=e.creator)==null?void 0:s.name)||"Unknown",username:((i=e.creator)==null?void 0:i.username)||"unknown"},source:"noun-project"}},Dr=async(e,t={})=>{if(!wo())throw new Error("Noun Project API keys not configured");const{limit:r=30,includeSvg:o=!0,limitToPublicDomain:s=!0,nextPage:i}=t,a={query:e,limit:r.toString()};o&&(a.include_svg="1"),s&&(a.limit_to_public_domain="1"),i&&(a.next_page=i);const c=`${gm}/v2/icon`,d=Object.keys(a).map(p=>`${encodeURIComponent(p)}=${encodeURIComponent(a[p])}`).join("&"),u=`${c}?${d}`;let h;if(h=await fetch(u,{method:"GET",headers:{Accept:"application/json"}}),!h.ok){const p=await h.text();throw pm.error("Noun Project API error:",p),new Error(`Failed to search icons: ${h.status} ${h.statusText}`)}const f=await h.json();return{results:f.icons.map(xm),nextPage:f.next_page||null}},bm=async e=>{const t=["design","business","technology","nature","food"],r=t[Math.floor(Math.random()*t.length)],{results:o}=await Dr(r,e);return o},ps={},Vl=T.createLogger("recraftApi"),Sa=[{value:"realistic_image",label:"Realistic Image",substyles:["b_and_w","enterprise","evening_light","faded_nostalgia","forest_life","hard_flash","hdr","motion_blur","mystic_naturalism","natural_light","natural_tones","organic_calm","real_life_glow","retro_realism","retro_snapshot","studio_portrait","urban_drama","village_realism","warm_folk"]},{value:"digital_illustration",label:"Digital Illustration",substyles:["2d_art_poster","2d_art_poster_2","antiquarian","bold_fantasy","child_book","cover","crosshatch","digital_engraving","engraving_color","expressionism","freehand_details","grain","grain_20","graphic_intensity","hand_drawn","hand_drawn_outline","handmade_3d","hard_comics","infantile_sketch","long_shadow","modern_folk","multicolor","neon_calm","noir","nostalgic_pastel","outline_details","pastel_gradient","pastel_sketch","pixel_art","plastic","pop_art","pop_renaissance","seamless","street_art","tablet_sketch","urban_glow","urban_sketching","young_adult_book","young_adult_book_2"]},{value:"vector_illustration",label:"Vector Illustration",substyles:["bold_stroke","chemistry","colored_stencil","cosmics","cutout","depressive","editorial","emotional_flat","engraving","line_art","line_circuit","linocut","marker_outline","mosaic","naivector","roundish_flat","seamless","segmented_colors","sharp_contrast","thin","vector_photo","vivid_shapes"]}],ym="https://external.api.recraft.ai/v1";function Co(){const e=(ps==null?void 0:ps.VITE_RECRAFT_API_TOKEN)||"";return e!==""&&e!=="YOUR_API_TOKEN_HERE"}async function vm(e,t,r,o={}){if(!Co())throw new Error("Recraft API token not configured. Set VITE_RECRAFT_API_TOKEN in your .env file.");const s=void 0,i={prompt:e.trim(),style:t,model:"recraftv3"};r&&(i.substyle=r),o.size&&(i.size=o.size),o.n&&(i.n=o.n);try{const a=await fetch(`${ym}/images/generations`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${s}`},body:JSON.stringify(i)});if(!a.ok){const h=await a.text();throw new Error(`Recraft API error (${a.status}): ${h}`)}const c=await a.json();if(!c.data||c.data.length===0)throw new Error("No images returned from Recraft API");const d=c.data[0],u=t==="vector_illustration"||t==="digital_illustration"?"svg":"png";return{id:c.id,url:d.url,prompt:e,style:t,format:u,created:c.created}}catch(a){throw Vl.error("Error generating image with Recraft:",a),a}}async function wm(e){try{const t=await fetch(e);if(!t.ok)throw new Error(`Failed to download image: ${t.status}`);if((t.headers.get("content-type")||"").includes("svg")){const o=await t.text();return`data:image/svg+xml;base64,${btoa(o)}`}else{const o=await t.blob();return URL.createObjectURL(o)}}catch(t){throw Vl.error("Error downloading Recraft image:",t),t}}const ms={},Hs=(ms==null?void 0:ms.VITE_FAL_API_KEY)||"";function Lr(){return Hs!==""&&Hs!=="YOUR_FAL_KEY_HERE"}async function ka(e,t={}){if(!Lr())throw new Error("fal.ai API key not configured. Set VITE_FAL_API_KEY in your .env file.");const r={image_url:e,sync_mode:t.syncMode??!1};try{const o=await fetch("https://fal.run/fal-ai/bria/background/remove",{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Key ${Hs}`},body:JSON.stringify(r)});if(!o.ok){const i=await o.text();throw new Error(`fal.ai API error (${o.status}): ${i}`)}const s=await o.json();if(!s.image||!s.image.url)throw new Error("Invalid response from fal.ai API");return s}catch(o){throw o instanceof Error?o:new Error("Failed to remove background")}}async function ja(e){const r=await(await fetch(e)).blob();return new Promise((o,s)=>{const i=new FileReader;i.onloadend=()=>o(i.result),i.onerror=s,i.readAsDataURL(r)})}function Ea(e){if(e.startsWith("data:"))return e.startsWith("data:image/svg+xml");const t=e.toLowerCase();return t.endsWith(".svg")||t.includes(".svg?")||t.includes(".svg#")}async function Ta(e,t=2048){return new Promise((r,o)=>{const s=new Image;s.crossOrigin="anonymous",s.onload=()=>{try{let i=s.width||s.naturalWidth,a=s.height||s.naturalHeight;if((i===0||a===0)&&(i=1024,a=1024),i>t){const h=t/i;i=t,a=a*h}const c=document.createElement("canvas");c.width=i,c.height=a;const d=c.getContext("2d");if(!d){o(new Error("Failed to get canvas context"));return}d.clearRect(0,0,i,a),d.drawImage(s,0,0,i,a);const u=c.toDataURL("image/png");r(u)}catch(i){o(i)}},s.onerror=()=>{o(new Error("Failed to load SVG image"))},s.src=e})}const gs={},Cm=T.createLogger("runwareApi"),$s=(gs==null?void 0:gs.VITE_RUNWARE_API_KEY)||"",Us=[{id:"runware:101@1",name:"Flux Dev",description:"High-quality generation with excellent detail and composition",supportsSteps:!0,supportsCFGScale:!0,supportsNegativePrompt:!0},{id:"google:4@2",name:"Nano Banana 2 Pro",description:"Advanced Google model for controlled visual creation",supportsSteps:!1,supportsCFGScale:!1,supportsNegativePrompt:!1}];let xs=null;function $r(){return $s!==""&&$s!=="YOUR_RUNWARE_KEY_HERE"}async function Sm(){if(!xs){if(!$r())throw new Error("Runware API key not configured. Set VITE_RUNWARE_API_KEY in your .env file.");xs=await Jc.Runware.initialize({apiKey:$s,timeoutDuration:6e4})}return xs}async function km(e){var t;if(!$r())throw new Error("Runware API key not configured. Set VITE_RUNWARE_API_KEY in your .env file.");try{const r=await Sm(),o=Us.find(u=>u.id===e.model),s=(o==null?void 0:o.supportsSteps)??!0,i=(o==null?void 0:o.supportsCFGScale)??!0,a=(o==null?void 0:o.supportsNegativePrompt)??!0,c={positivePrompt:e.prompt,model:e.model,width:e.width||1024,height:e.height||1024,numberResults:1,outputFormat:"PNG"};s&&(c.steps=e.steps||25),i&&(c.CFGScale=e.cfgScale||7),a&&e.negativePrompt&&(c.negativePrompt=e.negativePrompt);const d=await r.requestImages(c);if(!d||d.length===0)throw new Error("No images generated from Runware API");return{images:d.map(u=>({imageURL:u.imageURL||"",imageUUID:u.imageUUID||"",width:e.width||1024,height:e.height||1024})),taskUUID:((t=d[0])==null?void 0:t.taskUUID)||""}}catch(r){throw Cm.error("Runware API error:",r),r instanceof Error?new Error(`Runware API error: ${r.message}`):new Error("Failed to generate image with Runware")}}async function jm(e){const r=await(await fetch(e)).blob();return new Promise((o,s)=>{const i=new FileReader;i.onloadend=()=>o(i.result),i.onerror=s,i.readAsDataURL(r)})}const mr={},sr=T.createLogger("ImageBrowser"),Em="1px",bs="1px",Ra=l.memo(function({image:t,onImageSelect:r,fixedHeight:o=!1}){const[s,i]=l.useState(!1),[a,c]=l.useState(!1),[d,u]=l.useState("top"),h=l.useRef(null),f=l.useRef(null),p=l.useRef(null),g=l.useRef(!0),[b,x]=l.useState(!1),y=l.useRef(null),v=()=>{a||r(t)},w=z=>{if(!p.current)return"top";const B=p.current.getBoundingClientRect(),k=z.clientX-B.left,Y=z.clientY-B.top,_=B.width,G=B.height,se={top:Y,bottom:G-Y,left:k,right:_-k},A=Math.min(se.top,se.bottom,se.left,se.right);return A===se.top?"top":A===se.bottom?"bottom":A===se.left?"left":"right"},C=z=>{const B=w(z);y.current&&(cancelAnimationFrame(y.current),y.current=null),B!==d?(x(!0),u(B),y.current=requestAnimationFrame(()=>{y.current=requestAnimationFrame(()=>{x(!1),i(!0),y.current=null})})):(u(B),i(!0)),g.current=!1},j=z=>{y.current&&(cancelAnimationFrame(y.current),y.current=null);const B=w(z);u(B),x(!1),i(!1)},M=()=>{f.current&&(clearTimeout(f.current),f.current=null),h.current=setTimeout(()=>{c(!0)},400)},S=()=>{h.current&&(clearTimeout(h.current),h.current=null),c(!1)},R=()=>{h.current&&(clearTimeout(h.current),h.current=null),f.current&&(clearTimeout(f.current),f.current=null)},I=()=>{c(!1)},D=t.source==="unsplash"?"Unsplash":"Pixabay",E=s||a,O=()=>{if(!s)return`scale(${1.12})`;switch(d){case"top":return`scale(${1.12}) translateY(5%)`;case"bottom":return`scale(${1.12}) translateY(-5%)`;case"left":return`scale(${1.12}) translateX(5%)`;case"right":return`scale(${1.12}) translateX(-5%)`;default:return`scale(${1.12})`}};return n.jsxs("div",{ref:p,onClick:v,onMouseEnter:C,onMouseLeave:j,className:`group relative cursor-pointer overflow-hidden ${o?"h-full rounded-xs":"break-inside-avoid rounded-lg"}`,children:[n.jsx("img",{src:t.urls.small,alt:t.alt_description||"Image",className:`duration-500 ease-out ${b?"transition-none":"transition-transform"} ${o?"h-full w-full object-cover":"w-full object-cover"}`,style:{transform:O(),filter:s?"brightness(1)":"brightness(0.95)"}}),n.jsx("div",{className:"absolute top-2 right-2 z-10",children:n.jsx("button",{className:`relative flex h-6 w-6 items-center justify-center rounded-full bg-black/30 backdrop-blur-sm transition-all duration-300 ease-in-out hover:scale-110 ${E?"opacity-100":"pointer-events-none opacity-0"}`,"aria-label":"Image info",onMouseEnter:M,onMouseLeave:S,children:n.jsx(de,{icon:"lucide:aperture",className:"size-4 text-white/80"})})}),n.jsx("div",{className:`absolute inset-x-0 bottom-0 z-0 bg-linear-to-t from-black/80 via-black/60 to-transparent px-3 py-3 pt-8 transition-transform duration-300 ease-out ${a?"translate-y-0":"translate-y-full"}`,onMouseEnter:R,onMouseLeave:I,children:n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(de,{icon:t.source==="unsplash"?"simple-icons:unsplash":"simple-icons:pixabay",className:"size-3 text-white/80"}),n.jsx("span",{className:"text-xs font-medium text-white/80",children:D})]}),n.jsxs("div",{className:"flex flex-col gap-0.5",children:[n.jsx("span",{className:"text-xs text-white/60",children:"Photo by"}),n.jsx("span",{className:"text-sm font-medium text-white",children:t.user.name})]})]})})]})}),Na=l.memo(function({vector:t,onVectorSelect:r,fixedHeight:o=!1}){const[s,i]=l.useState(!1),[a,c]=l.useState(!1),d=l.useRef(null),u=l.useRef(null),h=()=>{a||r(t)},f=()=>{u.current&&(clearTimeout(u.current),u.current=null),d.current=setTimeout(()=>{c(!0)},400)},p=()=>{d.current&&(clearTimeout(d.current),d.current=null),c(!1)},g=()=>{d.current&&(clearTimeout(d.current),d.current=null),u.current&&(clearTimeout(u.current),u.current=null)},b=()=>{c(!1)},x=s||a;return n.jsxs("div",{onClick:h,onMouseEnter:()=>i(!0),onMouseLeave:()=>i(!1),className:`group relative cursor-pointer overflow-hidden bg-white/10 transition-all duration-300 ${o?"h-full rounded-xs":"break-inside-avoid rounded-lg"} ${s?"scale-105 bg-white/20":""}`,children:[n.jsx("div",{className:`flex items-center justify-center p-6 transition-all duration-300 ${o?"h-full w-full":"aspect-square w-full"}`,children:n.jsx("img",{src:t.urls.preview,alt:t.term,className:`max-h-full max-w-full object-contain transition-all duration-300 ${s?"scale-110":"scale-100"}`,style:{filter:s?"brightness(1.1)":"brightness(0.95)"}})}),n.jsxs("div",{className:"absolute top-2 right-2 z-10 flex items-center gap-2",children:[!t.urls.svg&&n.jsx("span",{className:`rounded-xs bg-amber-500/90 px-1.5 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-white shadow-sm transition-all duration-300 ease-in-out ${x?"opacity-100":"pointer-events-none opacity-0"}`,children:"PNG"}),n.jsx("button",{className:`relative flex h-6 w-6 items-center justify-center rounded-full bg-black/30 backdrop-blur-sm transition-all duration-300 ease-in-out hover:scale-110 ${x?"opacity-100":"pointer-events-none opacity-0"}`,"aria-label":"Vector info",onMouseEnter:f,onMouseLeave:p,children:n.jsx(de,{icon:"lucide:aperture",className:"size-4 text-white/80"})})]}),n.jsxs("div",{className:`absolute inset-x-0 bottom-0 z-0 bg-linear-to-t from-black/80 via-black/60 to-transparent px-3 py-3 pt-8 transition-transform duration-300 ease-out ${a?"translate-y-0":"translate-y-full"}`,onMouseEnter:g,onMouseLeave:b,children:[n.jsxs("div",{className:"mb-1",children:[n.jsx(de,{icon:"mdi:cube-outline",className:"mr-2 inline-block size-3 text-white/80"}),n.jsx("span",{className:"text-xs font-medium text-white/80",children:"Noun Project"})]}),n.jsx("div",{className:"text-xs text-white/60",children:"Icon by"}),n.jsx("div",{className:"text-sm font-medium text-white",children:t.uploader.name})]})]})}),Tm=({isOpen:e,onToggle:t,onImageSelect:r,currentImageUrl:o,placement:s="bottom"})=>{var Ft;const[i,a]=l.useState(""),[c,d]=l.useState(""),[u,h]=l.useState([]),[f,p]=l.useState(!1),[g,b]=l.useState(null),[x,y]=l.useState("search"),[v,w]=l.useState(1),[C,j]=l.useState(1),[M,S]=l.useState(!0),[R,I]=l.useState([]),[D,E]=l.useState("masonry"),[O,z]=l.useState(""),[B,k]=l.useState([]),[Y,_]=l.useState(!1),[G,se]=l.useState(null),[A,Z]=l.useState(null),[J,q]=l.useState(!0),[ae,Le]=l.useState("grid"),[pe,U]=l.useState(!1),[W,Ie]=l.useState("runware"),[ke,Ke]=l.useState(""),[re,te]=l.useState("vector_illustration"),[he,ye]=l.useState(""),[we,Pe]=l.useState("runware:101@1"),[me,N]=l.useState(!1),[ce,le]=l.useState(null),[Me,ge]=l.useState(null),[L,ve]=l.useState(null),[tt,Ve]=l.useState(!1),[oe,ie]=l.useState(null),pt=l.useRef(null),st=l.useRef(null),ht=l.useRef(null),bt=(mr==null?void 0:mr.VITE_UNSPLASH_ACCESS_KEY)||(typeof T.process$1<"u"?T.process$1.env.NEXT_PUBLIC_UNSPLASH_ACCESS_KEY:void 0)||"YOUR_ACCESS_KEY_HERE",yt=(mr==null?void 0:mr.VITE_PIXABAY_API_KEY)||(typeof T.process$1<"u"?T.process$1.env.NEXT_PUBLIC_PIXABAY_API_KEY:void 0)||"YOUR_ACCESS_KEY_HERE",Tt=["907841","LZDKIWvumJc","19740055","iTaneIvWKvE","8354123","2538204","8262349","6714897","uYpFBR3_CTc"],Rt=$=>({id:`pixabay-${$.id}`,urls:{raw:$.largeImageURL,full:$.largeImageURL,regular:$.largeImageURL,small:$.webformatURL,thumb:$.previewURL},alt_description:$.tags,user:{name:$.user,username:$.user},width:$.imageWidth,height:$.imageHeight,source:"pixabay"}),jt=$=>({id:`unsplash-${$.id}`,urls:$.urls,alt_description:$.alt_description,user:$.user,width:$.width,height:$.height,source:"unsplash"});l.useEffect(()=>{e&&o&&(d(o),y("url"))},[e,o]),l.useEffect(()=>{e||(a(""),d(""),h([]),b(null),w(1),j(1),S(!0),I([]),z(""),k([]),se(null),Z(null),q(!0))},[e]),l.useEffect(()=>{e&&!i&&x==="search"&&u.length===0&&kt()},[e,x]);const kt=async()=>{p(!0),b(null);try{const $=[];if(bt!=="YOUR_ACCESS_KEY_HERE"){const ft=Tt.filter(ze=>!R.includes(ze)),Q=[...ft.length>=2?ft:Tt].sort(()=>Math.random()-.5).slice(0,2);Q.forEach(ze=>{$.push(fetch(`https://api.unsplash.com/collections/${ze}/photos?per_page=30`,{headers:{Authorization:`Client-ID ${bt}`}}))}),I(ze=>{const nt=[...ze,...Q];return nt.length>=Tt.length?Q:nt})}if(yt!=="YOUR_ACCESS_KEY_HERE"&&$.push(fetch(`https://pixabay.com/api/?key=${yt}&per_page=30&image_type=photo&order=popular`)),$.length===0)throw new Error("No API keys configured. Please set VITE_UNSPLASH_ACCESS_KEY or VITE_PIXABAY_API_KEY.");const ee=await Promise.all($);if(ee.filter(ft=>!ft.ok).length===ee.length)throw new Error("Failed to load images from all sources");const it=[];for(let ft=0;ft<ee.length;ft++){if(!ee[ft].ok)continue;const at=await ee[ft].json();if("hits"in at){const xt=at.hits.map(Rt);it.push(...xt)}else{const xt=at.map(jt);it.push(...xt)}}const F=it.sort(()=>Math.random()-.5);h(F),S(!0)}catch($){b($ instanceof Error?$.message:"Failed to load images"),sr.error("Error loading featured images:",$)}finally{p(!1)}},Kt=async($,ee=1,Je=1)=>{if(!$.trim()){kt();return}p(!0),b(null);try{if(ee===1&&Je===1){const it=[];if(bt!=="YOUR_ACCESS_KEY_HERE"&&it.push(fetch(`https://api.unsplash.com/search/photos?query=${encodeURIComponent($)}&page=1&per_page=30`,{headers:{Authorization:`Client-ID ${bt}`}}),fetch(`https://api.unsplash.com/search/photos?query=${encodeURIComponent($)}&page=2&per_page=30`,{headers:{Authorization:`Client-ID ${bt}`}})),yt!=="YOUR_ACCESS_KEY_HERE"&&it.push(fetch(`https://pixabay.com/api/?key=${yt}&q=${encodeURIComponent($)}&page=1&per_page=30&image_type=photo`)),it.length===0)throw new Error("No API keys configured. Please set VITE_UNSPLASH_ACCESS_KEY or VITE_PIXABAY_API_KEY.");const F=await Promise.all(it);if(F.filter(Q=>!Q.ok).length===F.length)throw new Error("Failed to search images from all sources");const at=[];for(let Q=0;Q<F.length;Q++){if(!F[Q].ok)continue;const ze=await F[Q].json();if("hits"in ze){const nt=ze.hits.map(Rt);at.push(...nt)}else{const nt=ze.results.map(jt);at.push(...nt)}}const xt=at.sort(()=>Math.random()-.5);h(xt),S(at.length>0)}else{const it=[];bt!=="YOUR_ACCESS_KEY_HERE"&&it.push(fetch(`https://api.unsplash.com/search/photos?query=${encodeURIComponent($)}&page=${ee+2}&per_page=30`,{headers:{Authorization:`Client-ID ${bt}`}})),yt!=="YOUR_ACCESS_KEY_HERE"&&it.push(fetch(`https://pixabay.com/api/?key=${yt}&q=${encodeURIComponent($)}&page=${Je+1}&per_page=30&image_type=photo`));const F=await Promise.all(it),ft=[];for(let xt=0;xt<F.length;xt++){if(!F[xt].ok)continue;const Q=await F[xt].json();if("hits"in Q){const ze=Q.hits.map(Rt);ft.push(...ze)}else{const ze=Q.results.map(jt);ft.push(...ze)}}const at=ft.sort(()=>Math.random()-.5);h(xt=>[...xt,...at]),S(ft.length>0)}}catch(it){b(it instanceof Error?it.message:"Failed to search images"),sr.error("Error searching images:",it)}finally{p(!1)}},$t=$=>{$.preventDefault(),w(1),j(1),Kt(i,1,1)},Ot=l.useCallback(async()=>{if(!(f||!M)){if(i.trim()){const $=v+1,ee=C+1;w($),j(ee),Kt(i,$,ee);return}p(!0),b(null);try{const $=[];if(bt!=="YOUR_ACCESS_KEY_HERE"){const F=Tt.filter(Q=>!R.includes(Q)),xt=[...F.length>=2?F:Tt].sort(()=>Math.random()-.5).slice(0,2);xt.forEach(Q=>{$.push(fetch(`https://api.unsplash.com/collections/${Q}/photos?per_page=30`,{headers:{Authorization:`Client-ID ${bt}`}}))}),I(Q=>{const ze=[...Q,...xt];return ze.length>=Tt.length?xt:ze})}if(yt!=="YOUR_ACCESS_KEY_HERE"){const F=C+1;$.push(fetch(`https://pixabay.com/api/?key=${yt}&page=${F}&per_page=30&image_type=photo&order=popular`)),j(F)}const ee=await Promise.all($),Je=[];for(let F=0;F<ee.length;F++){if(!ee[F].ok)continue;const ft=await ee[F].json();if("hits"in ft){const at=ft.hits.map(Rt);Je.push(...at)}else{const at=ft.map(jt);Je.push(...at)}}const it=Je.sort(()=>Math.random()-.5);h(F=>[...F,...it]),S(Je.length>0)}catch($){b($ instanceof Error?$.message:"Failed to load more images"),sr.error("Error loading more images:",$)}finally{p(!1)}}},[f,M,i,v,C,R,bt,yt]);l.useEffect(()=>{const $=pt.current;if(!$||!e||x!=="search")return;const ee=new IntersectionObserver(Je=>{Je[0].isIntersecting&&M&&!f&&Ot()},{root:null,rootMargin:"200px",threshold:0});return ee.observe($),()=>{ee.disconnect()}},[e,x,M,f,Ot]),l.useEffect(()=>{e&&!O&&x==="vector"&&B.length===0&&wo()&&De()},[e,x]);const De=async()=>{_(!0),se(null);try{const $=await bm({limit:30,includeSvg:!0});k($),q(!0)}catch($){const ee=$ instanceof Error?$.message:"Failed to load vectors";ee.includes("Failed to fetch")||ee.includes("NetworkError")?se('Cannot connect to proxy server. Make sure to run "npm run dev:proxy" in a separate terminal.'):se(ee),sr.error("Error loading featured vectors:",$)}finally{_(!1)}},je=async($,ee)=>{if(!$.trim()&&!ee){De();return}_(!0),se(null);try{const Je=!pe,{results:it,nextPage:F}=await Dr($,{limit:30,includeSvg:!0,limitToPublicDomain:Je,nextPage:ee});if(it.length>0){if(ee?k(ft=>{const at=new Set(ft.map(Q=>Q.id)),xt=it.filter(Q=>!at.has(Q.id));return[...ft,...xt]}):(k(it),U(!1)),Z(F),q(F!==null),!ee&&Je&&!F&&it.length<30){U(!0);const{results:ft,nextPage:at}=await Dr($,{limit:30,includeSvg:!0,limitToPublicDomain:!1});k(xt=>{const Q=new Set(xt.map(nt=>nt.id)),ze=ft.filter(nt=>!Q.has(nt.id));return[...xt,...ze]}),Z(at),q(at!==null)}}else if(!pe&&!ee){U(!0);const{results:ft,nextPage:at}=await Dr($,{limit:30,includeSvg:!0,limitToPublicDomain:!1});k(ft),Z(at),q(at!==null)}else if(Je&&ee&&!F){U(!0);const{results:ft,nextPage:at}=await Dr($,{limit:30,includeSvg:!0,limitToPublicDomain:!1});k(xt=>{const Q=new Set(xt.map(nt=>nt.id)),ze=ft.filter(nt=>!Q.has(nt.id));return[...xt,...ze]}),Z(at),q(at!==null)}else q(!1),Z(null)}catch(Je){const it=Je instanceof Error?Je.message:"Failed to search vectors";it.includes("Failed to fetch")||it.includes("NetworkError")?se('Cannot connect to proxy server. Make sure to run "npm run dev:proxy" in a separate terminal.'):se(it),sr.error("Error searching vectors:",Je)}finally{_(!1)}},Ee=$=>{$.preventDefault(),je(O)},$e=l.useCallback(async()=>{Y||!J||!A||(O.trim()?je(O,A):De())},[Y,J,A,O]);l.useEffect(()=>{const $=st.current;if(!$||!e||x!=="vector")return;const ee=new IntersectionObserver(Je=>{Je[0].isIntersecting&&J&&!Y&&$e()},{root:null,rootMargin:"200px",threshold:0});return ee.observe($),()=>{ee.disconnect()}},[e,x,J,Y,$e]);const Qe=$=>{let ee=$.urls.svg||$.urls.png;const it=ee.startsWith("http://localhost:3001")?ee:`http://localhost:3001/proxy-image?url=${encodeURIComponent(ee)}`;r(it),t(!1)},Fe=$=>{r($.urls.regular),t(!1)},Ue=$=>{$.preventDefault(),c.trim()&&(r(c.trim()),t(!1))},Xe=$=>{var Je;const ee=(Je=$.target.files)==null?void 0:Je[0];if(ee&&ee.type.startsWith("image/")){const it=new FileReader;it.onload=F=>{var at;const ft=(at=F.target)==null?void 0:at.result;d(ft)},it.readAsDataURL(ee)}},dt=()=>{var $;($=ht.current)==null||$.click()},Ye=async()=>{if(!c.trim()){ie("No image URL provided");return}if(!Lr()){ie("fal.ai API key not configured. Set VITE_FAL_API_KEY in your .env file.");return}Ve(!0),ie(null);try{let $=c;Ea(c)&&($=await Ta(c));const ee=await ka($,{syncMode:!1}),Je=await ja(ee.image.url);d(Je)}catch($){const ee=$ instanceof Error?$.message:"Failed to remove background";ie(ee),sr.error("Error removing background:",$)}finally{Ve(!1)}},vt=async $=>{if($.preventDefault(),!ke.trim()){le("Please enter a prompt");return}if(W==="recraft"&&!Co()){le("Recraft API token not configured. Set VITE_RECRAFT_API_TOKEN in your .env file.");return}if(W==="runware"&&!$r()){le("Runware API key not configured. Set VITE_RUNWARE_API_KEY in your .env file.");return}N(!0),le(null),ge(null),ve(null);try{if(W==="recraft"){const ee=await vm(ke,re,he||void 0);ge(ee);const Je=await wm(ee.url);ve(Je)}else{const ee=await km({prompt:ke,model:we,width:1024,height:1024,steps:25,cfgScale:7}),Je=await jm(ee.images[0].imageURL);ve(Je)}}catch(ee){const Je=ee instanceof Error?ee.message:"Failed to generate image";le(Je),sr.error("Error generating AI image:",ee)}finally{N(!1)}},gt=()=>{L&&(r(L),t(!1))},Nt=($,ee)=>{const Je=$.width/$.height;return ee%12===0&&Je>.8&&Je<1.2?"col-span-2 row-span-2":Je<.75?"row-span-2":Je>1.5?"col-span-2":""};return n.jsx(oo,{isOpen:e,onClose:()=>t(!1),title:"Image Browser",description:"Browse Unsplash images or enter a custom image URL",placement:s,height:s==="bottom"?"90vh":void 0,width:s!=="bottom"?"500px":void 0,hideHandle:!0,hideVisibleTitle:!0,showCloseButton:!1,"data-testid":"image-browser-drawer",children:n.jsxs(m.Tabs,{value:x,onValueChange:$=>y($),className:"flex flex-col","data-testid":"image-browser-container",children:[n.jsx(m.Tabs.ListContainer,{className:"flex justify-center pt-4 pb-2",children:n.jsxs(m.Tabs.List,{className:"h-14 gap-1 px-1.5 md:h-12","aria-label":"Image source",children:[n.jsxs(m.Tabs.Tab,{id:"search",className:"h-11 w-14 px-0 md:h-9 md:w-11","data-testid":"image-tab-search",children:[n.jsx(de,{icon:Re.image,className:"size-6"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"url",className:"h-11 w-14 px-0 md:h-9 md:w-11","data-testid":"image-tab-url",children:[n.jsx(de,{icon:Re.link,className:"size-6"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"vector",className:"h-11 w-14 px-0 md:h-9 md:w-11","data-testid":"image-tab-vector",children:[n.jsx(de,{icon:"fa6-solid:icons",className:"size-5"}),n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"ai",className:"h-11 w-14 px-0 md:h-9 md:w-11","data-testid":"image-tab-ai",children:[n.jsx(Ao,{size:24}),n.jsx(m.Tabs.Indicator,{})]})]})}),n.jsxs(m.Tabs.Panel,{id:"search",className:"flex flex-col",children:[n.jsxs("form",{onSubmit:$t,className:"sticky top-0 z-9 flex gap-2 bg-surface px-6 pt-4 pb-3",children:[n.jsx(m.TextField,{className:"flex-1","aria-label":"Search for images",children:n.jsx(m.Input,{type:"text",placeholder:"Search for images...",value:i,onChange:$=>a($.target.value),variant:"subtle","data-testid":"image-search-input"})}),n.jsx(m.Button,{type:"submit",size:"icon",variant:"secondary",disabled:f,"aria-label":"Search",children:n.jsx(de,{icon:Re.search,className:"size-5"})}),n.jsx(m.Button,{size:"icon",variant:"secondary",onClick:()=>E(D==="grid"?"masonry":"grid"),"aria-label":D==="grid"?"Switch to masonry view":"Switch to grid view",children:D==="grid"?n.jsx(de,{icon:"lucide:layout-grid",className:"size-5"}):n.jsx(de,{icon:Re.grip,className:"size-5"})})]}),g&&n.jsxs("div",{className:"border-danger bg-danger/10 text-danger mx-6 mb-3 rounded-2xl border-2 px-4 py-3 text-sm",children:[g,g.includes("Failed")&&bt==="YOUR_ACCESS_KEY_HERE"&&n.jsx("div",{className:"mt-2 text-sm opacity-75",children:"Set VITE_UNSPLASH_ACCESS_KEY in your .env file to enable Unsplash search"})]}),f&&u.length===0&&n.jsx("div",{className:"text-muted px-6 py-8 text-center text-sm",children:"Loading images..."}),u.length>0&&n.jsxs("div",{className:"mx-6 overflow-hidden rounded-t-2xl",children:[D==="masonry"?n.jsx("div",{className:"grid grid-flow-dense pb-4",style:{display:"grid",gridTemplateColumns:s==="bottom"?"repeat(auto-fill, minmax(200px, 1fr))":"repeat(3, 1fr)",gridAutoRows:s==="bottom"?"200px":"120px",gap:Em},children:u.map(($,ee)=>n.jsx("div",{className:Nt($,ee),children:n.jsx(Ra,{image:$,onImageSelect:Fe,fixedHeight:!0})},$.id))}):n.jsx("div",{className:"pb-4",style:{display:"grid",gridTemplateColumns:s==="bottom"?"repeat(auto-fill, minmax(150px, 1fr))":"repeat(auto-fill, minmax(120px, 1fr))",gap:bs},children:u.map($=>n.jsx("div",{style:{aspectRatio:"1 / 1"},children:n.jsx(Ra,{image:$,onImageSelect:Fe,fixedHeight:!0})},$.id))}),M&&n.jsx("div",{ref:pt,className:"h-px"}),f&&n.jsx("div",{className:"text-muted py-4 text-center text-sm",children:"Loading more..."}),!M&&!f&&n.jsx("div",{className:"text-muted py-6 text-center text-sm",children:"No more images"})]}),!f&&u.length===0&&i&&n.jsxs("div",{className:"text-muted px-6 py-12 text-center text-sm",children:['No images found for "',i,'"']})]}),n.jsxs(m.Tabs.Panel,{id:"url",className:"flex flex-col gap-5 p-6",children:[n.jsx("input",{ref:ht,type:"file",accept:"image/*",onChange:Xe,className:"hidden"}),n.jsxs("button",{type:"button",onClick:dt,className:"flex flex-col items-center justify-center gap-3 rounded-2xl border-2 border-dashed border-divider bg-muted/30 px-6 py-10 transition-colors hover:bg-muted/50 active:bg-muted/60","data-testid":"image-upload-btn",children:[n.jsx(de,{icon:"lucide:upload-cloud",className:"size-10 text-foreground/60"}),n.jsxs("div",{className:"flex flex-col items-center gap-1",children:[n.jsx("span",{className:"text-base font-medium text-foreground",children:"Upload from device"}),n.jsx("span",{className:"text-xs text-muted-foreground",children:"PNG · JPG · SVG · GIF"})]})]}),n.jsxs("div",{className:"relative flex items-center gap-3",children:[n.jsx("div",{className:"h-px flex-1 bg-divider"}),n.jsx("span",{className:"text-muted-foreground text-xs uppercase tracking-wider",children:"or paste a link"}),n.jsx("div",{className:"h-px flex-1 bg-divider"})]}),n.jsxs("form",{onSubmit:Ue,className:"flex flex-col gap-3",children:[n.jsxs(m.TextField,{children:[n.jsx(m.Label,{className:"sr-only",children:"Image URL"}),n.jsx(m.Input,{type:"url",placeholder:"https://example.com/image.jpg",value:c,onChange:$=>d($.target.value),variant:"subtle","data-testid":"image-url-input"})]}),n.jsx(m.Button,{type:"submit",variant:"default",disabled:!c.trim(),className:"w-full","data-testid":"image-url-submit-btn",children:"Use This Image"})]}),c.trim()&&n.jsxs("div",{className:"flex flex-col gap-3 rounded-2xl border border-divider bg-muted/30 p-4",children:[n.jsxs("div",{className:"flex items-center justify-between gap-3",children:[n.jsx("span",{className:"text-xs font-medium uppercase tracking-wider text-muted-foreground",children:"Preview"}),Lr()&&n.jsx(m.Button,{onClick:Ye,disabled:tt||!c.trim(),variant:"secondary",size:"sm",className:"gap-2","data-testid":"remove-background-btn",children:tt?n.jsxs(n.Fragment,{children:[n.jsx(de,{icon:"eos-icons:loading",className:"size-4 animate-spin"}),"Removing…"]}):n.jsxs(n.Fragment,{children:[n.jsx(de,{icon:"mdi:image-remove",className:"size-4"}),"Remove BG"]})})]}),oe&&n.jsx("div",{className:"rounded-lg border border-danger bg-danger/10 px-3 py-2 text-xs text-danger",children:oe}),n.jsx("img",{src:c,alt:"Preview",className:"max-h-[280px] w-full rounded-lg object-contain",onError:$=>{$.target.style.display="none"},onLoad:$=>{$.target.style.display="block"}}),!Lr()&&n.jsx("div",{className:"rounded-lg border border-warning bg-warning/10 px-3 py-2 text-xs text-warning",children:"Set VITE_FAL_API_KEY in your .env file to enable background removal."})]})]}),n.jsxs(m.Tabs.Panel,{id:"vector",className:"flex flex-col",children:[n.jsxs("form",{onSubmit:Ee,className:"sticky top-0 z-9 flex gap-2 bg-surface px-6 pt-4 pb-3",children:[n.jsx(m.TextField,{className:"flex-1","aria-label":"Search for vector graphics",children:n.jsx(m.Input,{type:"text",placeholder:"Search for icons...",value:O,onChange:$=>z($.target.value),variant:"subtle","data-testid":"vector-search-input"})}),n.jsx(m.Button,{type:"submit",size:"icon",variant:"secondary",disabled:Y,"aria-label":"Search",children:n.jsx(de,{icon:Re.search,className:"size-5"})}),n.jsx(m.Button,{size:"icon",variant:"secondary",onClick:()=>Le(ae==="grid"?"masonry":"grid"),"aria-label":ae==="grid"?"Switch to masonry view":"Switch to grid view",children:ae==="grid"?n.jsx(de,{icon:"lucide:layout-grid",className:"size-5"}):n.jsx(de,{icon:Re.grip,className:"size-5"})})]}),G&&n.jsx("div",{className:"border-danger bg-danger/10 text-danger mx-6 mb-3 rounded-2xl border-2 px-4 py-3 text-sm",children:G}),!wo()&&n.jsx("div",{className:"bg-warning/10 text-warning mx-6 mb-3 rounded-2xl border-2 border-warning px-4 py-3 text-sm",children:"Noun Project API keys not configured. Set VITE_NOUN_PROJECT_API_KEY and VITE_NOUN_PROJECT_API_SECRET in your .env file."}),Y&&B.length===0&&n.jsx("div",{className:"text-muted px-6 py-8 text-center text-sm",children:"Loading vectors..."}),B.length>0&&n.jsxs("div",{className:"mx-6 overflow-hidden rounded-t-2xl",children:[ae==="masonry"?n.jsx("div",{className:"grid grid-flow-dense pb-4",style:{display:"grid",gridTemplateColumns:s==="bottom"?"repeat(auto-fill, minmax(150px, 1fr))":"repeat(3, 1fr)",gridAutoRows:s==="bottom"?"150px":"120px",gap:bs},children:B.map($=>n.jsx("div",{children:n.jsx(Na,{vector:$,onVectorSelect:Qe,fixedHeight:!0})},$.id))}):n.jsx("div",{className:"pb-4",style:{display:"grid",gridTemplateColumns:s==="bottom"?"repeat(auto-fill, minmax(120px, 1fr))":"repeat(auto-fill, minmax(100px, 1fr))",gap:bs},children:B.map($=>n.jsx("div",{style:{aspectRatio:"1 / 1"},children:n.jsx(Na,{vector:$,onVectorSelect:Qe,fixedHeight:!0})},$.id))}),J&&n.jsx("div",{ref:st,className:"h-px"}),Y&&n.jsx("div",{className:"text-muted py-4 text-center text-sm",children:"Loading more..."}),!J&&!Y&&n.jsx("div",{className:"text-muted py-6 text-center text-sm",children:"No more vectors"})]}),!Y&&B.length===0&&O&&wo()&&n.jsxs("div",{className:"text-muted px-6 py-12 text-center text-sm",children:['No vectors found for "',O,'"']})]}),n.jsxs(m.Tabs.Panel,{id:"ai",className:"flex flex-col gap-6 p-6",children:[n.jsxs(m.TextField,{children:[n.jsx(m.Label,{children:"AI Provider"}),n.jsxs("select",{value:W,onChange:$=>Ie($.target.value),className:"w-full rounded-xl border border-divider bg-field text-foreground px-4 py-3 text-sm",children:[n.jsx("option",{value:"runware",children:"Runware (Flux Dev / Nano Banana 2 Pro)"}),n.jsx("option",{value:"recraft",children:"Recraft (Vector Illustrations)"})]})]}),W==="runware"&&n.jsxs(m.TextField,{children:[n.jsx(m.Label,{children:"Model"}),n.jsx("select",{value:we,onChange:$=>Pe($.target.value),className:"w-full rounded-xl border border-divider bg-field text-foreground px-4 py-3 text-sm",children:Us.map($=>n.jsxs("option",{value:$.id,children:[$.name," - ",$.description]},$.id))})]}),W==="recraft"&&n.jsxs(m.TextField,{children:[n.jsx(m.Label,{children:"Style"}),n.jsx("select",{value:re,onChange:$=>{te($.target.value),ye("")},className:"w-full rounded-xl border border-divider bg-field text-foreground px-4 py-3 text-sm",children:Sa.map($=>n.jsx("option",{value:$.value,children:$.label},$.value))})]}),W==="recraft"&&(()=>{const $=Sa.find(ee=>ee.value===re);return $&&$.substyles.length>0?n.jsxs(m.TextField,{children:[n.jsx(m.Label,{children:"Substyle (Optional)"}),n.jsxs("select",{value:he,onChange:ee=>ye(ee.target.value),className:"w-full rounded-xl border border-divider bg-field text-foreground px-4 py-3 text-sm",children:[n.jsx("option",{value:"",children:"None (Default)"}),$.substyles.map(ee=>n.jsx("option",{value:ee,children:ee.replace(/_/g," ")},ee))]})]}):null})(),n.jsxs("form",{onSubmit:vt,className:"flex flex-col gap-6",children:[n.jsxs(m.TextField,{children:[n.jsx(m.Label,{children:"Prompt"}),n.jsx(m.TextArea,{placeholder:"Describe the image you want to generate... (e.g., 'avocado, transparent background')",value:ke,onChange:$=>Ke($.target.value),className:"min-h-[100px] resize-y",rows:4,"data-testid":"ai-prompt-input",disabled:me})]}),n.jsx(m.Button,{type:"submit",variant:"default",disabled:!ke.trim()||me||W==="recraft"&&!Co()||W==="runware"&&!$r(),className:"w-full","data-testid":"ai-generate-btn",children:me?n.jsxs(n.Fragment,{children:[n.jsx(de,{icon:"eos-icons:loading",className:"size-5 animate-spin"}),"Generating..."]}):n.jsxs(n.Fragment,{children:[n.jsx(Ao,{size:24}),"Generate Image"]})})]}),W==="recraft"&&!Co()&&n.jsx("div",{className:"bg-warning/10 text-warning rounded-2xl border-2 border-warning px-4 py-3 text-sm",children:"Recraft API token not configured. Set VITE_RECRAFT_API_TOKEN in your .env file to enable AI generation."}),W==="runware"&&!$r()&&n.jsx("div",{className:"bg-warning/10 text-warning rounded-2xl border-2 border-warning px-4 py-3 text-sm",children:"Runware API key not configured. Set VITE_RUNWARE_API_KEY in your .env file to enable AI generation."}),ce&&n.jsx("div",{className:"border-danger bg-danger/10 text-danger rounded-2xl border-2 px-4 py-3 text-sm",children:ce}),L&&n.jsxs("div",{className:"flex flex-col gap-4 rounded-2xl border border-divider bg-muted/40 p-6",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(m.Label,{className:"text-muted text-xs uppercase tracking-wide",children:"Generated Image"}),W==="recraft"&&Me&&n.jsx("span",{className:"rounded-xs bg-muted px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-foreground/80",children:Me.format.toUpperCase()}),W==="runware"&&n.jsx("span",{className:"rounded-xs bg-muted px-2 py-1 text-[10px] font-semibold uppercase tracking-wide text-foreground/80",children:(Ft=Us.find($=>$.id===we))==null?void 0:Ft.name})]}),n.jsx("div",{className:"flex w-fit items-center justify-center overflow-hidden rounded-lg bg-white/50 dark:bg-black/50",style:{maxHeight:"500px",maxWidth:"100%"},children:n.jsx("img",{src:L,alt:ke,className:"max-h-full max-w-full object-contain"})}),n.jsxs("div",{className:"flex flex-col gap-1",children:[n.jsx(m.Label,{className:"text-muted text-xs",children:"Prompt"}),n.jsx("p",{className:"text-sm",children:W==="recraft"&&Me?Me.prompt:ke})]}),n.jsxs("div",{className:"flex flex-col gap-3",children:[Lr()&&n.jsx(m.Button,{onClick:async()=>{if(L){Ve(!0),ie(null);try{let $=L;Ea(L)&&($=await Ta(L));const ee=await ka($,{syncMode:!1}),Je=await ja(ee.image.url);ve(Je)}catch($){ie($ instanceof Error?$.message:"Failed to remove background")}finally{Ve(!1)}}},disabled:tt||!L,variant:"secondary",size:"sm",className:"w-full gap-2","data-testid":"ai-remove-background-btn",children:tt?n.jsxs(n.Fragment,{children:[n.jsx(de,{icon:"eos-icons:loading",className:"size-4 animate-spin"}),"Removing..."]}):n.jsxs(n.Fragment,{children:[n.jsx(de,{icon:"mdi:image-remove",className:"size-4"}),"Remove Background"]})}),oe&&n.jsx("div",{className:"border-danger bg-danger/10 text-danger rounded-xl border-2 px-3 py-2 text-xs",children:oe}),n.jsx(m.Button,{onClick:gt,variant:"default",className:"w-full","data-testid":"ai-use-image-btn",children:"Use This Image"})]})]})]})]})})},Gl=({isOpen:e,onOpenChange:t,onImageAdded:r,onImageChanged:o,changingElementId:s,onChangingElementIdChange:i})=>{var I;const{elements:a,setElements:c,canvasEditorRef:d,artboardManager:u,executeAddElement:h,executeElementUpdate:f}=Yt.useEditor(),{selectedId:p,setSelectedId:g}=Yt.useSelectionContext(),{activeArtboardId:b}=Qr(),x=l.useRef(a);x.current=a;const y=l.useRef(p);y.current=p;const[v,w]=l.useState(null),C=s??v,j=i??w,M=l.useCallback(D=>{var se,A;const E=x.current,O=y.current;if(C){const Z=E.find(J=>J.id===C);if(Z&&rt.isImageElement(Z)){const J=Z,q=Z.clone(),ae=((se=d.current)==null?void 0:se.getZoom())||1;q.imageUrl=D,q.transformData.width=300/ae,q.transformData.height=300/ae,q.transformData.cropX=0,q.transformData.cropY=0,q.transformData.cropWidth=1,q.transformData.cropHeight=1,q.transformData.flipHorizontal=!1,q.transformData.flipVertical=!1,q.transformData.borderRadius=0,q.imageLoaded=!1,q.imageElement=null,q.isCropping=!1,q.onLoadCallback=Le=>{const pe=Le;c(U=>U.map(W=>W.id===pe.id?pe:W))},q.loadImage(D),f(J,q),o&&o(q)}j(null);return}if(!b){alert("Please create or select an artboard first");return}const z=`element-${Date.now()}`,B=u.getActiveArtboard(),k=B?B.x+B.width/2:window.innerWidth/2,Y=B?B.y+B.height/2:window.innerHeight/2,_=((A=d.current)==null?void 0:A.getZoom())||1,G=new T.ImageElement({id:z,x:k,y:Y,imageUrl:D,transformData:{width:300/_,height:300/_},onLoadCallback:Z=>{const J=Z;c(q=>q.map(ae=>ae.id===J.id?J:ae))}});u.addElementToArtboard(z,b),h(G,b,O||void 0),g(z),r&&r(G)},[C,u,h,f,b,d,c,g,j,r,o]),S=l.useCallback(D=>{t(D),D||j(null)},[t,j]),R=C?(I=a.find(D=>D.id===C))==null?void 0:I.imageUrl:void 0;return n.jsx(Tm,{isOpen:e,onToggle:S,onImageSelect:M,currentImageUrl:R})},Rm=Object.freeze(Object.defineProperty({__proto__:null,ImagePanel:Gl},Symbol.toStringTag,{value:"Module"})),Nm=T.createLogger("GlyphBrowserDrawer"),Mm=({isOpen:e,onClose:t,fontFamily:r,fontWeight:o=400,onInsertGlyph:s})=>{const[i,a]=l.useState([]),[c,d]=l.useState(!1),[u,h]=l.useState(null),[f,p]=l.useState("");l.useEffect(()=>{e&&(d(!0),h(null),p(""),T.FontAnalyzer.getAllGlyphs(r,o).then(x=>{x.length===0&&h(`No alternate glyphs found in ${r}`),a(x),d(!1)}).catch(x=>{Nm.error("Error loading glyphs:",x),h("Failed to load glyphs"),d(!1)}))},[e,r,o]);const g=x=>{let y=x.unicode;if(!y||y.length===0)y=String.fromCodePoint(983040+x.glyphIndex);else{const v=y.codePointAt(0);v&&v<57344&&(y=String.fromCodePoint(983040+x.glyphIndex))}s(y)},b=f?i.filter(x=>x.name.toLowerCase().includes(f.toLowerCase())||x.unicode.toLowerCase().includes(f.toLowerCase())):i;return n.jsxs(oo,{isOpen:e,onClose:t,title:`Browse Glyphs - ${r}`,description:`Browse and select alternate glyphs for the ${r} font`,maxHeight:"75vh",showCloseButton:!0,children:[n.jsx("div",{className:"px-6 py-4 border-b border-black/10 dark:border-white/10",children:n.jsxs("div",{className:"relative",children:[n.jsx(de,{icon:Re.search,className:"absolute left-3 top-1/2 -translate-y-1/2 text-muted pointer-events-none size-4 z-10"}),n.jsx(m.Input,{type:"text",placeholder:"Search glyphs...",value:f,onChange:x=>p(x.target.value),className:"pl-10"})]})}),n.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[c&&n.jsxs("div",{className:"py-12 text-center text-muted",children:[n.jsx(m.Spinner,{size:"lg",className:"mx-auto mb-4"}),n.jsx("div",{className:"text-sm",children:"Loading glyphs..."})]}),u&&n.jsxs("div",{className:"py-12 text-center",children:[n.jsx(de,{icon:Re.alertCircle,className:"size-12 mx-auto mb-4 text-danger"}),n.jsx("div",{className:"text-base font-medium mb-2",children:u}),n.jsx("div",{className:"text-sm text-muted",children:"This font may not have alternate glyphs."})]}),!c&&!u&&b.length===0&&f&&n.jsxs("div",{className:"py-12 text-center",children:[n.jsx(de,{icon:Re.search,className:"size-12 mx-auto mb-4 text-muted"}),n.jsxs("div",{className:"text-base font-medium",children:['No glyphs found matching "',f,'"']})]}),!c&&!u&&b.length>0&&n.jsx("div",{className:"grid grid-cols-[repeat(auto-fill,minmax(100px,1fr))] gap-4",children:b.map((x,y)=>n.jsxs("button",{onClick:()=>g(x),className:"group relative flex aspect-square cursor-pointer flex-col items-center gap-2 rounded-xl border-2 border-black/10 bg-black/5 p-3 transition-all hover:border-accent hover:bg-black/10 hover:shadow-lg dark:border-white/10 dark:bg-white/5 dark:hover:border-accent dark:hover:bg-white/10",children:[x.previewDataUrl?n.jsx("img",{src:x.previewDataUrl,alt:x.name,className:"h-auto w-full object-contain"}):n.jsx("div",{className:"text-5xl leading-none",style:{fontFamily:r},children:x.unicode}),n.jsx("div",{className:"w-full overflow-hidden text-ellipsis whitespace-nowrap text-center text-xs text-muted",children:x.name}),x.category!=="default"&&n.jsx(m.Badge,{size:"sm",color:x.category==="swash"?"warning":x.category==="stylistic"?"primary":"success",className:"absolute right-1 top-1 text-[10px] font-semibold uppercase",children:x.category==="swash"?"SW":x.category==="stylistic"?"ALT":x.category==="ligature"?"LIG":""})]},`${x.glyphIndex}-${y}`))}),!c&&!u&&b.length>0&&n.jsxs("div",{className:"mt-6 pt-4 border-t border-black/10 dark:border-white/10 text-center text-sm text-muted",children:[b.length," glyph",b.length!==1?"s":""," available",f&&` matching "${f}"`]})]})]})},Ma=T.createLogger("GlyphPanel"),Kl=({isOpen:e,onClose:t,fontFamily:r,fontWeight:o,onInsertGlyph:s,element:i})=>{const{selectedElement:a,executeElementUpdate:c}=Yt.useEditor(),d=i!==void 0?i:a||null,u=r||(d instanceof T.TextElement?d.fontFamily:"Arial"),h=o||(d instanceof T.TextElement&&d.bold?700:400),f=l.useCallback(async p=>{if(s){s(p);return}if(!d||!(d instanceof T.TextElement)){Ma.warn("No text element selected for glyph insertion");return}try{await T.FontAnalyzer.loadFont(u,h)}catch(b){Ma.error("Error pre-loading font for glyph rendering:",b)}const g=d.clone();g.text=g.text+p,c(d,g)},[s,d,u,h,c]);return n.jsx(Mm,{isOpen:e,onClose:t,fontFamily:u,fontWeight:h,onInsertGlyph:f})},Im=Object.freeze(Object.defineProperty({__proto__:null,GlyphPanel:Kl},Symbol.toStringTag,{value:"Module"})),ql=({orientation:e="horizontal",showAddButton:t=!0,showCloseButtons:r=!1,maxTabWidth:o=200,style:s={},className:i="",onArtboardCreate:a,onArtboardDelete:c})=>{const{artboardsInfo:d,selectArtboard:u,createArtboard:h,deleteArtboard:f,renameArtboard:p}=Qr(),[g,b]=l.useState(null),[x,y]=l.useState(""),v=(I,D)=>{b(I),y(D)},w=()=>{g&&x.trim()&&p(g,x.trim()),b(null),y("")},C=()=>{b(null),y("")},j=()=>{h(1200,1200,{name:`Artboard ${d.length+1}`}),a&&setTimeout(()=>{const I=d[d.length];I&&a(I.id)},10)},M=(I,D)=>{if(D.stopPropagation(),d.length<=1){alert("Cannot delete the last artboard");return}confirm("Delete this artboard?")&&(f(I),c&&c(I))},S=e==="horizontal"?{display:"flex",flexDirection:"row",gap:4,padding:8,backgroundColor:"var(--bg-secondary)",borderBottom:"1px solid var(--border-primary)",overflowX:"auto",overflowY:"hidden",...s}:{display:"flex",flexDirection:"column",gap:4,padding:8,backgroundColor:"var(--bg-secondary)",borderRight:"1px solid var(--border-primary)",overflowY:"auto",overflowX:"hidden",minWidth:200,...s},R=I=>({display:"flex",alignItems:"center",gap:8,padding:"8px 12px",backgroundColor:I?"var(--accent-primary)":"var(--bg-primary)",color:I?"var(--primary-foreground)":"var(--text-primary)",border:I?"none":"1px solid var(--border-primary)",borderRadius:6,cursor:"pointer",fontSize:13,fontWeight:I?600:400,whiteSpace:"nowrap",maxWidth:e==="horizontal"?o:void 0,minWidth:e==="horizontal"?120:void 0,transition:"all 0.2s"});return n.jsxs("div",{className:`artboard-tabs ${i}`,style:S,children:[d.map(I=>{const D=g===I.id;return n.jsxs("div",{style:R(I.isActive),onClick:()=>!D&&u(I.id),onDoubleClick:()=>v(I.id,I.name),children:[D?n.jsx("input",{type:"text",value:x,onChange:E=>y(E.target.value),onBlur:w,onKeyDown:E=>{E.key==="Enter"&&w(),E.key==="Escape"&&C()},autoFocus:!0,onClick:E=>E.stopPropagation(),style:{flex:1,padding:"2px 4px",border:"1px solid var(--border-primary)",borderRadius:4,fontSize:13,minWidth:80}}):n.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis"},children:I.name}),n.jsx("span",{style:{fontSize:11,opacity:.7,padding:"2px 6px",borderRadius:10,backgroundColor:I.isActive?"color-mix(in srgb, var(--primary-foreground) 20%, transparent)":"var(--bg-secondary)"},children:I.elementCount}),r&&n.jsx("button",{onClick:E=>M(I.id,E),style:{background:"none",border:"none",cursor:"pointer",padding:2,display:"flex",alignItems:"center",opacity:.7,transition:"opacity 0.2s"},onMouseEnter:E=>E.currentTarget.style.opacity="1",onMouseLeave:E=>E.currentTarget.style.opacity="0.7",title:"Delete artboard",children:n.jsx(de,{icon:Re.close,className:"size-3.5"})})]},I.id)}),t&&n.jsxs("button",{onClick:j,style:{display:"flex",alignItems:"center",justifyContent:"center",gap:6,padding:"8px 12px",backgroundColor:"var(--bg-primary)",border:"1px dashed var(--border-primary)",borderRadius:6,cursor:"pointer",fontSize:13,color:"var(--text-secondary)",minWidth:e==="horizontal"?120:void 0,transition:"all 0.2s"},onMouseEnter:I=>{I.currentTarget.style.backgroundColor="var(--bg-tertiary)",I.currentTarget.style.borderColor="var(--accent-primary)"},onMouseLeave:I=>{I.currentTarget.style.backgroundColor="var(--bg-primary)",I.currentTarget.style.borderColor="var(--border-primary)"},title:"Add new artboard",children:[n.jsx(de,{icon:Re.plus,className:"size-3.5"}),n.jsx("span",{children:"New Artboard"})]})]})},Am=Object.freeze(Object.defineProperty({__proto__:null,ArtboardTabs:ql},Symbol.toStringTag,{value:"Module"})),Dm=()=>n.jsx("svg",{width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"shrink-0",children:n.jsx("path",{d:"M19 12H5M12 19l-7-7 7-7"})});function Lm({onClick:e}){return n.jsx(m.TooltipProvider,{delayDuration:300,children:n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"outline",onClick:e,className:"mr-sm border-r-border-primary pr-md","aria-label":"Back",children:n.jsx(Dm,{})})}),n.jsx(m.TooltipContent,{children:"Back"})]})})}const ys=.001;function Uo(e){var r,o;if(!e)return{rotation:!1,opacity:!1,stroke:!1,knockout:!1,distress:!1,imageMask:!1,cornerRadius:!1,shapeTransparency:!1};const t=e.transformData;return{rotation:Math.abs(e.rotation??0)>ys,opacity:(e.opacity??1)<1-ys,stroke:((r=e.stroke)==null?void 0:r.enabled)===!0,knockout:e.blendMode==="knockout"||e.blendMode==="clip",distress:((o=e.distressEffect)==null?void 0:o.enabled)===!0,imageMask:!!e.masks&&e.masks.length>0,cornerRadius:((t==null?void 0:t.borderRadius)??0)>0,shapeTransparency:((t==null?void 0:t.fillOpacity)??1)<1-ys}}const Zl=({element:e,onElementUpdate:t,showUngroupButton:r=!1,onUngroup:o,onMoveForward:s,onMoveBackward:i,onChangeImage:a,onDelete:c,cornerRadiusExpanded:d=!1,onCornerRadiusToggle:u,cropExpanded:h=!1,onCropToggle:f,rotationExpanded:p=!1,onRotationToggle:g,opacityExpanded:b=!1,onOpacityToggle:x,strokeExpanded:y=!1,onStrokeToggle:v,knockoutExpanded:w=!1,onKnockoutToggle:C,distressTextureExpanded:j=!1,onDistressTextureToggle:M,imageMaskExpanded:S=!1,onImageMaskToggle:R})=>{const[I,D]=l.useState(!1),[E,O]=l.useState(!1),[z,B]=l.useState(!1),[k,Y]=l.useState(!1),[_,G]=l.useState(!1),[se,A]=l.useState(!1),[Z,J]=l.useState(!1),[q,ae]=l.useState(!1),[Le,pe]=l.useState(!1),[U,W]=l.useState(!1),Ie=e.isCropping,ke=Uo(e),Ke=()=>{if(Y(!0),Ie){const he=e.clone();he.exitCropMode(),t(he)}else{const he=e.clone();he.enterCropMode(),t(he)}f==null||f()},re=()=>{const he=e.clone();he.transformData.flipHorizontal=!he.transformData.flipHorizontal,t(he)},te=()=>{const he=e.clone();he.transformData.flipVertical=!he.transformData.flipVertical,t(he)};return n.jsxs("div",{className:"toolbar-items",children:[a&&n.jsx(ct,{icon:"lucide:image",onClick:()=>{O(!0),a()},onMouseLeave:()=>O(!1),tooltip:"Change Image",tooltipDisabled:E}),n.jsx(ct,{icon:"lucide:crop",onClick:Ke,onMouseLeave:()=>Y(!1),tooltip:Ie?"Exit Crop Mode":"Crop",tooltipDisabled:k||h,active:Ie||h}),n.jsx(ct,{icon:"lucide:flip-horizontal-2",onClick:re,tooltip:"Flip Horizontal"}),n.jsx(ct,{icon:"lucide:flip-vertical-2",onClick:te,tooltip:"Flip Vertical"}),n.jsx(ct,{icon:n.jsx(Bo,{size:20,className:"md:size-5"}),onClick:()=>{G(!0),g==null||g()},onMouseLeave:()=>G(!1),tooltip:"Rotate",tooltipDisabled:_||p,active:p||ke.rotation}),n.jsx(ct,{icon:"lucide:blend",onClick:()=>{A(!0),x==null||x()},onMouseLeave:()=>A(!1),tooltip:"Transparency",tooltipDisabled:se||b,active:b||ke.opacity}),n.jsx(ct,{icon:"lucide:square-round-corner",onClick:()=>{B(!0),u==null||u()},onMouseLeave:()=>B(!1),tooltip:"Corner Radius",tooltipDisabled:z||d,active:d||ke.cornerRadius}),C&&n.jsx(ct,{icon:"lucide:scissors",onClick:()=>{ae(!0),C()},onMouseLeave:()=>ae(!1),tooltip:"Clip / Knockout",tooltipDisabled:q||w,active:w||ke.knockout}),M&&n.jsx(ct,{icon:"lucide:stamp",onClick:()=>{pe(!0),M()},onMouseLeave:()=>pe(!1),tooltip:"Distress Texture",tooltipDisabled:Le||j,active:j||ke.distress}),R&&n.jsx(ct,{icon:"lucide:venetian-mask",onClick:()=>{W(!0),R()},onMouseLeave:()=>W(!1),tooltip:"Image Mask",tooltipDisabled:U||S,active:S||ke.imageMask}),v&&n.jsx(ct,{icon:"lucide:pen-line",onClick:()=>{J(!0),v()},onMouseLeave:()=>J(!1),tooltip:"Stroke",tooltipDisabled:Z||y,active:y||ke.stroke}),(s||i||c)&&n.jsxs(m.Popover,{open:I,onOpenChange:D,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn","aria-label":"More options",children:n.jsx(de,{icon:"lucide:ellipsis-vertical",className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"end",className:"w-auto p-1",maxZIndex:!0,children:n.jsxs("div",{className:"flex items-center gap-1",children:[s&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{s(),D(!1)},"aria-label":"Move Forward",children:n.jsx(de,{icon:"hugeicons:layer-bring-forward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Forward"})]}),i&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{i(),D(!1)},"aria-label":"Move Backward",children:n.jsx(de,{icon:"hugeicons:layer-send-backward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Backward"})]}),c&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{D(!1),c()},"aria-label":"Delete",children:n.jsx(de,{icon:Re.trash,className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Delete"})]})]})})]}),r&&o&&n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"sm",onClick:o,children:"Ungroup"})}),n.jsx(m.TooltipContent,{children:"Ungroup this group"})]})]})},Ys=[{id:"white",name:"White",color:"#FFFFFF"},{id:"light-gray",name:"Light Gray",color:"#E5E5E5"},{id:"medium-gray",name:"Medium Gray",color:"#999999"},{id:"dark-gray",name:"Dark Gray",color:"#333333"},{id:"black",name:"Black",color:"#000000"},{id:"orange",name:"Orange",color:"#FF8800"},{id:"blue",name:"Blue",color:"#0074D9"},{id:"indigo",name:"Indigo",color:"#4B0082"},{id:"teal",name:"Teal",color:"#39CCCC"},{id:"coral",name:"Coral",color:"#FF6B6B"}],Jl=({element:e,onElementUpdate:t,documentColors:r,imageColors:o,showUngroupButton:s=!1,onUngroup:i,onMoveForward:a,onMoveBackward:c,onOpenShapeTypeDrawer:d,onDelete:u,rotationExpanded:h=!1,onRotationToggle:f,cornerRadiusExpanded:p=!1,onCornerRadiusToggle:g,transparencyExpanded:b=!1,onTransparencyToggle:x,sidesExpanded:y=!1,onSidesToggle:v,pointsExpanded:w=!1,onPointsToggle:C,innerRadiusExpanded:j=!1,onInnerRadiusToggle:M,colorExpanded:S=!1,onColorToggle:R,strokeExpanded:I=!1,onStrokeToggle:D,knockoutExpanded:E=!1,onKnockoutToggle:O,distressTextureExpanded:z=!1,onDistressTextureToggle:B,imageMaskExpanded:k=!1,onImageMaskToggle:Y})=>{const[_,G]=l.useState(!1),[se,A]=l.useState(!1),[Z,J]=l.useState(!1),[q,ae]=l.useState(!1),[Le,pe]=l.useState(!1),[U,W]=l.useState(!1),[Ie,ke]=l.useState(!1),[Ke,re]=l.useState(!1),[te,he]=l.useState(!1),[ye,we]=l.useState(!1),[Pe,me]=l.useState(!1),[N,ce]=l.useState(!1),[le,Me]=l.useState(!1),ge=l.useMemo(()=>Ys.map(pt=>pt.color),[]),L=l.useMemo(()=>r&&r.length>0?r:ge,[r,ge]),ve=Uo(e),tt=pt=>{const st=e.clone();st.transformData.fillColor=pt.target.value,t(st)},Ve={rectangle:"Rectangle",circle:"Circle",ellipse:"Ellipse",triangle:"Triangle",polygon:"Polygon",star:"Star",line:"Line"},oe=e.transformData.shapeType,ie=Ve[oe]||"Shape";return n.jsxs("div",{className:"toolbar-items",children:[d&&n.jsx(ct,{icon:Re.shapes,onClick:()=>{A(!0),d()},onMouseLeave:()=>A(!1),tooltip:`Change Shape (${ie})`,tooltipDisabled:se}),R?n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn",onClick:()=>{he(!0),R()},onMouseLeave:()=>he(!1),"aria-label":"Fill Color","data-active":S,children:n.jsx("div",{className:"h-6 w-6 rounded-md border border-border-primary",style:{backgroundColor:e.transformData.fillColor||"#3b82f6"}})})}),!te&&!S&&n.jsx(m.TooltipContent,{children:"Fill Color"})]}):n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("div",{children:n.jsx(lr,{value:e.transformData.fillColor||"#3b82f6",onChange:tt,documentColors:L,imageColors:o,showSquare:!0})})}),n.jsx(m.TooltipContent,{children:"Fill Color"})]}),e.transformData.shapeType==="rectangle"&&g&&n.jsx(ct,{icon:"lucide:square-round-corner",onClick:()=>{ae(!0),g()},onMouseLeave:()=>ae(!1),tooltip:"Corner Radius",tooltipDisabled:q||p,active:p||ve.cornerRadius}),e.transformData.shapeType==="polygon"&&v&&n.jsx(ct,{icon:"healthicons:polygon",onClick:()=>{W(!0),v()},onMouseLeave:()=>W(!1),tooltip:"Sides",tooltipDisabled:U||y,active:y}),e.transformData.shapeType==="star"&&C&&n.jsx(ct,{icon:"material-symbols:award-star-outline",onClick:()=>{ke(!0),C()},onMouseLeave:()=>ke(!1),tooltip:"Points",tooltipDisabled:Ie||w,active:w}),e.transformData.shapeType==="star"&&M&&n.jsx(ct,{icon:"lucide:circle-dashed",onClick:()=>{re(!0),M()},onMouseLeave:()=>re(!1),tooltip:"Inner Radius",tooltipDisabled:Ke||j,active:j}),x&&n.jsx(ct,{icon:"lucide:blend",onClick:()=>{pe(!0),x()},onMouseLeave:()=>pe(!1),tooltip:"Transparency",tooltipDisabled:Le||b,active:b||ve.shapeTransparency}),f&&n.jsx(ct,{icon:n.jsx(Bo,{size:20,className:"md:size-5"}),onClick:()=>{J(!0),f()},onMouseLeave:()=>J(!1),tooltip:"Rotate",tooltipDisabled:Z||h,active:h||ve.rotation}),O&&n.jsx(ct,{icon:"lucide:scissors",onClick:()=>{me(!0),O()},onMouseLeave:()=>me(!1),tooltip:"Clip / Knockout",tooltipDisabled:Pe||E,active:E||ve.knockout}),B&&n.jsx(ct,{icon:"lucide:stamp",onClick:()=>{ce(!0),B()},onMouseLeave:()=>ce(!1),tooltip:"Distress Texture",tooltipDisabled:N||z,active:z||ve.distress}),Y&&n.jsx(ct,{icon:"lucide:venetian-mask",onClick:()=>{Me(!0),Y()},onMouseLeave:()=>Me(!1),tooltip:"Image Mask",tooltipDisabled:le||k,active:k||ve.imageMask}),D&&n.jsx(ct,{icon:"lucide:pen-line",onClick:()=>{we(!0),D()},onMouseLeave:()=>we(!1),tooltip:"Stroke",tooltipDisabled:ye||I,active:I||ve.stroke}),(a||c||u)&&n.jsxs(m.Popover,{open:_,onOpenChange:G,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn","aria-label":"More options",children:n.jsx(de,{icon:"lucide:ellipsis-vertical",className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"end",className:"w-auto p-1",maxZIndex:!0,children:n.jsxs("div",{className:"flex items-center gap-1",children:[a&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{a(),G(!1)},"aria-label":"Move Forward",children:n.jsx(de,{icon:"hugeicons:layer-bring-forward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Forward"})]}),c&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{c(),G(!1)},"aria-label":"Move Backward",children:n.jsx(de,{icon:"hugeicons:layer-send-backward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Backward"})]}),u&&n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{G(!1),u()},"aria-label":"Delete",children:n.jsx(de,{icon:Re.trash,className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Delete"})]})]})})]}),s&&i&&n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"sm",onClick:i,children:"Ungroup"})}),n.jsx(m.TooltipContent,{children:"Ungroup this group"})]})]})},Pm=({className:e})=>n.jsx("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:n.jsx("path",{d:"M12 2L21 8L18 19L6 19L3 8L12 2Z"})}),Fm=({className:e})=>n.jsx("svg",{className:e,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2","aria-hidden":!0,children:n.jsx("ellipse",{cx:"12",cy:"12",rx:"9",ry:"6"})}),Ws="size-10",zm=[{id:"rectangle",label:"Rectangle",icon:"lucide:square"},{id:"circle",label:"Circle",icon:"lucide:circle"},{id:"ellipse",label:"Ellipse",reactIcon:n.jsx(Fm,{className:Ws})},{id:"triangle",label:"Triangle",icon:"lucide:triangle"},{id:"polygon",label:"Polygon",reactIcon:n.jsx(Pm,{className:Ws})},{id:"star",label:"Star",icon:"lucide:star"},{id:"line",label:"Line",icon:"lucide:minus"}],mi=({isOpen:e,onClose:t,onSelectType:r,currentType:o})=>{const s=o?"Change Shape":"Select Shape",i=o?"Select a new shape type":"Choose a shape to add",a=c=>{r(c),t()};return n.jsxs(oo,{isOpen:e,onClose:t,title:s,description:i,placement:"bottom",height:"auto",hideVisibleTitle:!0,showCloseButton:!1,"data-testid":"shape-type-drawer",children:[n.jsxs("div",{className:"px-6 pt-1 pb-2 flex items-center justify-between",children:[n.jsx("h3",{className:"text-lg font-semibold tracking-tight text-foreground",children:s}),n.jsx("button",{onClick:t,className:"size-11 rounded-full hover:bg-foreground/[0.06] flex items-center justify-center text-foreground/70 -mr-2","aria-label":"Close",children:n.jsx(de,{icon:Re.close,className:"size-5"})})]}),n.jsx("div",{className:"grid grid-cols-3 gap-2 p-4","data-testid":"shape-type-list",children:zm.map(c=>{const d=c.id===o;return n.jsxs("button",{type:"button",onClick:()=>a(c.id),"aria-pressed":d,"data-testid":`shape-type-${c.id}`,className:`aspect-square flex flex-col items-center justify-center gap-2.5 rounded-xl border transition-colors ${d?"bg-primary/10 border-primary/40":"bg-transparent border-transparent hover:bg-foreground/[0.04] active:bg-foreground/[0.06]"}`,children:[n.jsx("span",{className:d?"text-primary":"text-foreground/85",children:c.reactIcon?c.reactIcon:n.jsx(de,{icon:c.icon,className:Ws})}),n.jsx("span",{className:`text-xs ${d?"text-primary font-medium":"text-foreground/70"}`,children:c.label})]},c.id)})})]})},Ql=({element:e,onElementUpdate:t,onMoveForward:r,onMoveBackward:o})=>{const[s,i]=l.useState(!1),[a,c]=l.useState(!1),[d,u]=l.useState(!1),h=S=>{const R=e.clone();R.transformData.strokeColor=S,t(R),i(!1)},f=S=>{const R=e.clone();R.transformData.fillColor=S,t(R),c(!1)},p=()=>{const S=e.clone();S.transformData.strokeEnabled=!S.transformData.strokeEnabled,t(S)},g=()=>{const S=e.clone();S.transformData.fillEnabled=!S.transformData.fillEnabled,t(S)},b=S=>{const R=e.clone();R.transformData.strokeWidth=S,t(R)},x=e.transformData.strokeColor||"#000000",y=e.transformData.fillColor||"#3b82f6",v=e.transformData.strokeEnabled??!0,w=e.transformData.fillEnabled??!1,C=e.transformData.strokeWidth??2,j=e.transformData.closed,M=e.transformData.points.length;return n.jsxs("div",{className:"fixed top-3xl left-1/2 -translate-x-1/2 flex items-center gap-md px-xl py-md bg-bg-primary rounded-xl shadow-md",style:{zIndex:"var(--z-dropdown)"},children:[n.jsxs("div",{className:"px-xl text-base text-text-muted border-r border-border-primary",children:[n.jsx("span",{className:"font-semibold",children:"Path"}),n.jsxs("span",{className:"ml-md text-text-placeholder",children:[M," ",M===1?"point":"points",j&&" • Closed"]})]}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:v?"default":"ghost",onClick:p,className:"px-xl text-base",children:"Stroke"})}),n.jsx(m.TooltipContent,{children:v?"Disable Stroke":"Enable Stroke"})]}),v&&n.jsxs(m.Popover,{open:s,onOpenChange:i,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"w-8 h-8 p-xs rounded-md border-2 border-border-primary cursor-pointer transition-transform hover:scale-105",style:{background:x},title:"Stroke Color"})}),n.jsx(m.PopoverContent,{align:"start",className:"p-0",children:n.jsxs("div",{className:"bg-bg-primary rounded-xl shadow-lg p-6 min-w-[240px]",children:[n.jsx("div",{className:"grid grid-cols-6 gap-sm mb-md",children:Ys.map(S=>n.jsx(m.Button,{onClick:()=>h(S.color),"aria-label":S.name,className:`w-8 h-8 rounded-md cursor-pointer transition-all min-h-0 min-w-0 p-0 ${x===S.color?"border-2 border-accent-primary scale-110":"border border-border-primary hover:scale-105"}`,style:{background:S.color}},S.color))}),n.jsx("input",{type:"color",value:x,onChange:S=>h(S.target.value),className:"w-full h-8 cursor-pointer rounded-md border border-border-primary"})]})})]}),v&&n.jsxs(m.Popover,{open:d,onOpenChange:u,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsxs(m.Button,{variant:"ghost",className:"px-xl text-base",children:[C,"px"]})}),n.jsx(m.PopoverContent,{align:"start",className:"p-0",children:n.jsx("div",{className:"bg-bg-primary rounded-xl shadow-lg p-6 min-w-[200px]",children:n.jsxs(m.Slider,{value:[C],onValueChange:S=>b(S[0]),min:1,max:20,step:.5,className:"slider-no-fill w-full",children:[n.jsx(m.Label,{children:"Width (px)"}),n.jsx(m.Slider.Output,{}),n.jsx(m.Slider.Track,{}),n.jsx(m.Slider.Thumb,{})]})})})]}),n.jsx("div",{className:"w-px h-6 bg-border-primary mx-xs"}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:w?"default":"ghost",onClick:g,className:"px-xl text-base",children:"Fill"})}),n.jsx(m.TooltipContent,{children:w?"Disable Fill":"Enable Fill"})]}),w&&n.jsxs(m.Popover,{open:a,onOpenChange:c,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"w-8 h-8 p-xs rounded-md border-2 border-border-primary cursor-pointer transition-transform hover:scale-105",style:{background:y},title:"Fill Color"})}),n.jsx(m.PopoverContent,{align:"start",className:"p-0",children:n.jsxs("div",{className:"bg-bg-primary rounded-xl shadow-lg p-6 min-w-[240px]",children:[n.jsx("div",{className:"grid grid-cols-6 gap-sm mb-md",children:Ys.map(S=>n.jsx(m.Button,{onClick:()=>f(S.color),"aria-label":S.name,className:`w-8 h-8 rounded-md cursor-pointer transition-all min-h-0 min-w-0 p-0 ${y===S.color?"border-2 border-accent-primary scale-110":"border border-border-primary hover:scale-105"}`,style:{background:S.color}},S.color))}),n.jsx("input",{type:"color",value:y,onChange:S=>f(S.target.value),className:"w-full h-8 cursor-pointer rounded-md border border-border-primary"})]})})]}),n.jsx("div",{className:"w-px h-6 bg-border-primary mx-xs"}),r&&n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:r,children:n.jsx(de,{icon:"hugeicons:layer-bring-forward",className:"size-[18px]"})})}),n.jsx(m.TooltipContent,{children:"Move Forward"})]}),o&&n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:o,children:n.jsx(de,{icon:"hugeicons:layer-send-backward",className:"size-[18px]"})})}),n.jsx(m.TooltipContent,{children:"Move Backward"})]})]})},gi=l.memo(({backgroundType:e,backgroundColor:t,backgroundTexture:r,onBackgroundTypeChange:o,onColorChange:s,onTextureChange:i})=>{const[a,c]=l.useState(!1),[d,u]=l.useState("color"),[h,f]=l.useState(t);l.useEffect(()=>{u(e==="texture"?"texture":"color")},[e]),l.useEffect(()=>{t!=="transparent"&&f(t)},[t]);const p=w=>{f(w),s(w),o("color")},g=w=>{const C=w.target.value;f(C);const j=/^#?([0-9A-Fa-f]{6}|[0-9A-Fa-f]{3})$/,M=C.startsWith("#")?C:`#${C}`;j.test(M)&&(s(M),o("color"))},b=()=>{s("transparent"),o("transparent")},x=w=>{i(w),o("texture")},y=w=>{if(u(w),w==="color")o(t==="transparent"?"transparent":"color");else if(w==="texture"){if(!r){const C=rt.TextureManager.getAllTextures()[0];C&&i(C.id)}o("texture")}},v=t==="transparent";return n.jsxs(m.Popover,{open:a,onOpenChange:c,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:a?"default":"ghost","aria-label":"Background",children:n.jsx(de,{icon:Re.palette,className:"size-[18px]"})})}),n.jsx(m.PopoverContent,{className:"w-auto p-3",children:n.jsxs("div",{className:"flex min-w-[220px] flex-col gap-3",children:[n.jsxs("div",{className:"flex gap-1 border-b border-divider pb-3",children:[n.jsx(m.Button,{variant:"ghost",size:"sm",className:`flex-1 ${d==="color"?"bg-primary text-primary-foreground":""}`,onClick:()=>y("color"),children:"Color"}),n.jsx(m.Button,{variant:"ghost",size:"sm",className:`flex-1 ${d==="texture"?"bg-primary text-primary-foreground":""}`,onClick:()=>y("texture"),children:"Texture"}),n.jsx(m.Button,{variant:"ghost",size:"sm",className:"flex-1 cursor-not-allowed opacity-50",disabled:!0,"aria-label":"Gradient (Coming soon)",children:"Gradient"})]}),d==="color"&&n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsxs(m.Button,{variant:"ghost",className:`flex w-full cursor-pointer items-center justify-start gap-2 rounded-lg ${v?"bg-primary/10":""}`,onClick:b,children:[n.jsx("div",{className:"transparent-pattern-small h-6 w-6 rounded"}),n.jsx("span",{className:"text-sm font-medium",children:"Transparent"})]}),n.jsx($l,{color:v?"#ffffff":t,onChange:p}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("label",{htmlFor:"bg-hex-input",className:"text-sm font-medium uppercase text-foreground/60",children:"HEX"}),n.jsx("input",{id:"bg-hex-input",type:"text",className:"flex-1 rounded-lg border border-divider bg-field px-2 py-1.5 text-sm text-foreground focus:border-primary focus:outline-none",value:h,onChange:g,placeholder:"#000000",maxLength:7})]})]}),d==="texture"&&n.jsxs("div",{className:"flex flex-col gap-3",children:[n.jsx("div",{className:"text-sm font-medium text-foreground/60",children:"Select a texture"}),n.jsx("div",{className:"grid grid-cols-4 gap-1.5",children:rt.TextureManager.getAllTextures().map(w=>n.jsx("button",{className:`flex items-center justify-center p-1 rounded-lg cursor-pointer transition-all border-2 ${r===w.id?"border-primary":"border-transparent hover:border-primary/50"}`,onClick:()=>x(w.id),"aria-label":w.name,children:n.jsx("img",{src:w.url,alt:w.name,className:"w-full h-full rounded"})},w.id))})]}),d==="gradient"&&n.jsxs("div",{className:"flex flex-col items-center justify-center gap-3 py-8 text-foreground/60",children:[n.jsx("div",{className:"text-sm",children:"Gradient backgrounds"}),n.jsx("div",{className:"text-xs",children:"Coming soon"})]})]})})]})});gi.displayName="BackgroundPickerDropdown";const ec=({distressTexture:e,onChange:t})=>{rt.ensureBuiltinTexturesReady();const r=(e==null?void 0:e.enabled)||!1,o=(e==null?void 0:e.textureUrl)||"",s=(e==null?void 0:e.intensity)??50,i=rt.DISTRESS_TEXTURE_PRESETS.map(u=>({id:u.textureUrl,name:u.name,thumbnailUrl:u.thumbnailUrl})),a=u=>{if(u){const h=o||rt.DISTRESS_TEXTURE_PRESETS[0].textureUrl;rt.preloadTexture(h),t({enabled:!0,textureUrl:h,intensity:s})}else t(void 0)},c=l.useCallback(u=>{rt.preloadTexture(u),t({enabled:!0,textureUrl:u,intensity:s})},[t,s]),d=u=>{e&&t({...e,intensity:u[0]})};return n.jsxs(m.Disclosure,{open:r,onOpenChange:a,className:"mb-xl",children:[n.jsx(m.DisclosureTrigger,{className:"w-full",children:n.jsxs("div",{className:"flex items-center justify-between w-full",children:[n.jsx(m.Label,{children:"Distress Texture"}),n.jsx(m.Switch,{checked:r,onCheckedChange:a,onClick:u=>u.stopPropagation()})]})}),n.jsxs(m.DisclosureContent,{className:"flex flex-col gap-lg py-lg",children:[n.jsx(Ho,{presets:i,selectedId:o,onSelect:c,showOff:!1,ariaLabel:"Distress texture presets"}),n.jsx(sn,{label:"Intensity",value:s,onChange:u=>d([u]),min:0,max:100,step:1,unit:"%"})]})]})},tc=({imageMask:e,onChange:t})=>{rt.ensureMaskPresetsReady();const r=(e==null?void 0:e.enabled)||!1,o=(e==null?void 0:e.imageUrl)||"",s=(e==null?void 0:e.maskType)||"clip",i=(e==null?void 0:e.opacity)??100,a=(e==null?void 0:e.inverted)??!1,c=rt.MASK_IMAGE_PRESETS.map(g=>({id:g.imageUrl,name:g.name,thumbnailUrl:g.thumbnailUrl})),d=g=>{if(g){const b=o||rt.MASK_IMAGE_PRESETS[0].imageUrl;t({enabled:!0,imageUrl:b,maskType:s,opacity:i,inverted:a})}else t(void 0)},u=l.useCallback(g=>{t({enabled:!0,imageUrl:g,maskType:s,opacity:i,inverted:a})},[t,s,i,a]),h=g=>{e&&t({...e,maskType:g})},f=g=>{e&&t({...e,opacity:g[0]})},p=g=>{e&&t({...e,inverted:g})};return n.jsxs(m.Disclosure,{open:r,onOpenChange:d,className:"mb-xl",children:[n.jsx(m.DisclosureTrigger,{className:"w-full",children:n.jsxs("div",{className:"flex items-center justify-between w-full",children:[n.jsx(m.Label,{children:"Image Mask"}),n.jsx(m.Switch,{checked:r,onCheckedChange:d,onClick:g=>g.stopPropagation()})]})}),n.jsxs(m.DisclosureContent,{className:"flex flex-col gap-lg py-lg",children:[n.jsx(Ho,{presets:c,selectedId:o,onSelect:u,showOff:!1,ariaLabel:"Image mask presets"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(m.Label,{className:"text-sm",children:"Type"}),n.jsx("div",{className:"flex rounded-md border border-divider overflow-hidden",children:["clip","alpha","luma"].map(g=>n.jsx("button",{className:`px-3 py-1 text-xs capitalize transition-colors ${s===g?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>h(g),children:g},g))})]}),n.jsx(sn,{label:"Opacity",value:i,onChange:g=>f([g]),min:0,max:100,step:1,unit:"%"}),n.jsxs("label",{className:"flex items-center gap-2 text-sm text-foreground",children:[n.jsx(m.Checkbox,{checked:a,onCheckedChange:g=>p(g===!0)}),"Invert Mask"]})]})]})},nc=({artboard:e,artboards:t,onArtboardUpdate:r,onRenameArtboard:o,onDeleteArtboard:s,artboardScreenBounds:i})=>{const[a,c]=l.useState(!1),[d,u]=l.useState(""),[h,f]=l.useState(!1),p=l.useRef(null),g=I=>{const D=e.clone();D.backgroundType=I,r(D)},b=I=>{const D=e.clone();D.backgroundColor=I,r(D)},x=I=>{const D=e.clone();D.backgroundTexture=I,r(D)},y=I=>{const D=e.clone();D.exportBackground=I,r(D)},v=I=>{const D=e.clone();D.distressTexture=I,r(D)},w=I=>{const D=e.clone();D.imageMask=I,r(D)},C=()=>{c(!0),u(e.name)},j=()=>{d.trim()&&o(e.id,d.trim()),c(!1),u("")},M=()=>{c(!1),u("")},S=I=>{I.key==="Enter"?j():I.key==="Escape"&&M()},R=()=>{if(t.length<=1){alert("Cannot delete the last artboard");return}e.getElementCount()>0&&!confirm(`Delete "${e.name}" with ${e.getElementCount()} element(s)?`)||s(e.id)};return l.useEffect(()=>{a&&p.current&&(p.current.focus(),p.current.select())},[a]),n.jsxs(m.Surface,{className:"absolute px-4 py-2 flex items-center gap-2 shadow-lg z-50 rounded-full bg-bg-primary border border-border-primary",style:{left:"50%",top:i?`${i.top-68}px`:"32px",transform:"translateX(-50%)"},children:[a?n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("input",{ref:p,type:"text",value:d,onChange:I=>u(I.target.value),onKeyDown:S,className:"px-3 py-1 border border-border-primary rounded-lg text-base text-text-primary bg-bg-primary outline-none min-w-[120px] transition-colors focus:border-border-focus"}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:j,"aria-label":"Save",children:n.jsx(de,{icon:Re.check,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Save"})]}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:M,"aria-label":"Cancel",children:n.jsx(de,{icon:Re.close,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Cancel"})]})]}):n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx("span",{className:"text-xl font-semibold text-text-primary",children:e.name}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:C,"aria-label":"Rename",children:n.jsx(de,{icon:Re.pencil,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Rename"})]}),n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",onClick:R,disabled:t.length<=1,"aria-label":"Delete",children:n.jsx(de,{icon:Re.trash,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Delete"})]})]}),n.jsx(m.Separator,{orientation:"vertical",className:"h-6"}),n.jsx(gi,{backgroundType:e.backgroundType,backgroundColor:e.backgroundColor,backgroundTexture:e.backgroundTexture,onBackgroundTypeChange:g,onColorChange:b,onTextureChange:x}),n.jsx(m.Separator,{orientation:"vertical",className:"h-6"}),n.jsxs("div",{className:"text-base font-mono text-text-muted uppercase",children:[Math.round(e.width)," × ",Math.round(e.height)]}),n.jsx(m.Separator,{orientation:"vertical",className:"h-6"}),n.jsxs(m.Popover,{open:h,onOpenChange:f,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:h?"default":"ghost","aria-label":"More options",children:n.jsx(de,{icon:Re.menu,className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"end",children:n.jsxs("div",{className:"flex flex-col gap-2 min-w-[240px]",children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(m.Switch,{checked:e.exportBackground,onCheckedChange:y}),n.jsx(m.Label,{children:"Export Background"})]}),n.jsx(m.Separator,{}),n.jsx(ec,{distressTexture:e.distressTexture,onChange:v}),n.jsx(tc,{imageMask:e.imageMask,onChange:w})]})})]})]})},Ia=T.createLogger("GoogleFontsService");let br=[],Ar=null;async function Om(){return br.length>0?br:Ar||(Ar=fetch("/google-fonts.json").then(e=>{if(!e.ok)throw new Error(`HTTP error! status: ${e.status}`);return e.json()}).then(e=>(Array.isArray(e)?br=e.map(t=>({family:t.family,category:t.category||"sans-serif",subsets:t.subsets||[],variants:t.variants||[],popularity:t.popularity})):Ia.error("Unexpected API response structure:",e),br)).catch(e=>(Ia.error("Error fetching Google Fonts:",e),Ar=null,[])),Ar)}function vs(){return br}function _m(){return br.length>0}function Aa(e){return{"sans serif":"sans-serif",serif:"serif",display:"display",handwriting:"script",monospace:"monospace"}[e.toLowerCase()]||"display"}const rc=[{canonical:"slab-serif",monotypeClassifications:["SLAB SERIF","CLARENDON SERIF"],googleCategory:"serif",displayName:"Slab Serif",description:"Bold, chunky serifs perfect for t-shirt designs"},{canonical:"decorative",monotypeClassifications:["BLACKLETTER","SPECIALIZED","DESIGN","DINGBATS","SYMBOL","ORNATE"],googleCategory:"display",displayName:"Decorative",description:"Artistic and ornate fonts for special effects"},{canonical:"display",monotypeClassifications:["DISPLAY","HIGH CONTRAST","GRAPHIC STYLE"],googleCategory:"display",displayName:"Display",description:"Eye-catching fonts for headlines and logos"},{canonical:"script",monotypeClassifications:["SCRIPT","FORMAL SCRIPT","INFORMAL SCRIPT","CASUAL SCRIPT","HANDWRITING"],googleCategory:"handwriting",displayName:"Script & Handwriting",description:"Calligraphy and handwritten styles"},{canonical:"monospace",monotypeClassifications:["MONOSPACED"],googleCategory:"monospace",displayName:"Monospace",description:"Fixed-width fonts for coding and technical text"},{canonical:"serif",monotypeClassifications:["SERIF","OLD STYLE SERIF","TRANSITIONAL SERIF","MODERN SERIF","NEOCLASSICAL","TRANSITIONAL"],googleCategory:"serif",displayName:"Serif",description:"Traditional fonts with decorative strokes at letter ends"},{canonical:"sans-serif",monotypeClassifications:["SANS SERIF","GEOMETRIC SANS","HUMANIST SANS","GROTESQUE SANS"],googleCategory:"sans-serif",displayName:"Sans Serif",description:"Clean, modern fonts without decorative strokes"}];function Bm(e){const t=["slab-serif","decorative","display","script","monospace","serif","sans-serif"];for(const r of t){const o=rc.find(s=>s.canonical===r);if(o&&e.some(i=>o.monotypeClassifications.includes(i)))return r}return"sans-serif"}function oc(e){return rc.find(t=>t.canonical===e)}function Hm(e){const t=oc(e);return(t==null?void 0:t.monotypeClassifications)||[]}const yn=T.createLogger("Monotype");class $m{constructor(){this.accessToken=null,this.tokenExpiry=0,this.fonts=new Map,this.fontsLoaded=!1,this.webfontKits=new Map,this.searchCache=new Map,this.API_BASE="https://api.monotype.com",this.CACHE_TTL=24*60*60*1e3,this.monotypeEnabled=!1,this.loadCachesFromStorage(),this.monotypeEnabled=this.checkMonotypeEnabled()}checkMonotypeEnabled(){return!1}isMonotypeEnabled(){return this.monotypeEnabled}async authenticate(){}isAuthenticated(){return this.accessToken!==null&&Date.now()<this.tokenExpiry}async fetchAllFonts(){if(!this.monotypeEnabled){this.fontsLoaded=!0;return}const t=localStorage.getItem("monotype_fonts_cache");if(t)try{const{data:s,timestamp:i}=JSON.parse(t);if(Date.now()-i<this.CACHE_TTL){this.fonts=new Map(s),this.fontsLoaded=!0;return}}catch(s){yn.error("Failed to parse font cache:",s)}try{await this.authenticate()}catch(s){throw yn.error("Authentication failed, cannot fetch fonts:",s),s}if(!this.accessToken){const s=new Error("No access token available after authentication");throw yn.error(s.message),s}const r=["SANS SERIF","SERIF","SCRIPT","DISPLAY","SLAB SERIF","MONOSPACED","HANDWRITING","BLACKLETTER"],o=new Map;for(const s of r)try{let i=null,a=0;do{const c=await this.searchFontsRaw({classification:[s],pageSize:50,pageId:i||void 0});c.fonts.forEach(d=>{o.has(d.fontId)||o.set(d.fontId,d)}),i=c.nextPageId||null,a++}while(i)}catch(i){yn.error(`Failed to fetch ${s} fonts:`,i)}this.fonts=o,this.fontsLoaded=!0;try{localStorage.setItem("monotype_fonts_cache",JSON.stringify({data:Array.from(o.entries()),timestamp:Date.now()}))}catch(s){yn.error("Failed to cache fonts:",s)}}getAllFonts(){return Array.from(this.fonts.values())}isFontsLoaded(){return this.fontsLoaded}async searchFontsRaw(t){if(await this.authenticate(),!this.accessToken)return yn.warn("Cannot search fonts: No access token available"),{fonts:[]};try{const r=await fetch(`${this.API_BASE}/v1/fonts/search`,{method:"POST",headers:{Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify(t)});if(!r.ok){const s=await r.text();let i;try{i=JSON.parse(s)}catch{i=s}throw yn.error("Font search failed:",{status:r.status,statusText:r.statusText,error:i,params:t}),new Error(`Search failed: ${r.status} ${r.statusText}`)}const o=await r.json();return{fonts:o.fonts||[],nextPageId:o.nextPageId,totalCount:o.totalCount}}catch(r){return yn.error("Font search failed:",r),{fonts:[]}}}async searchFonts(t){const r=JSON.stringify(t);if(this.searchCache.has(r))return this.searchCache.get(r);const o=await this.searchFontsRaw(t),s=this.groupMonotypeFontsByFamily(o.fonts);return this.searchCache.set(r,s),s}async searchFontsByName(t){return t.trim()?this.searchFonts({name:t,searchSettings:{fuzzy:["name"]},pageSize:50}):this.groupMonotypeFontsByFamily(this.getAllFonts())}async filterFontsByCategory(t){if(t==="system")return[];const r=Hm(t);return r.length===0?[]:this.searchFonts({classification:r,pageSize:50})}groupMonotypeFontsByFamily(t){const r=new Map;return t.forEach(o=>{const s=o.family||o.name;r.has(s)||r.set(s,[]),r.get(s).push(o)}),Array.from(r.entries()).map(([o,s])=>{const i=s[0];return{name:o.replace(/[™®]/g,"").trim(),category:Bm(i.classification||[]),monotypeFont:!0,googleFont:!1,monotypeId:i.fontId,source:"monotype",foundry:i.foundry,weights:this.extractWeights(s),tags:i.tag||[],preview:i.sample}})}extractWeights(t){const r=new Set;return t.forEach(o=>{o.weightCSS&&r.add(o.weightCSS)}),Array.from(r).sort()}async getWebFontKit(t,r){var s;if(this.webfontKits.has(t))return this.webfontKits.get(t);const o=localStorage.getItem("monotype_webfont_kits");if(o)try{const i=new Map(JSON.parse(o));if(i.has(t)){const a=i.get(t);return this.webfontKits.set(t,a),a}}catch(i){yn.error("Failed to parse webfont kit cache:",i)}if(await this.authenticate(),!this.accessToken)throw new Error("Not authenticated - no access token available");try{const i=await fetch(`${this.API_BASE}/v1/webfonts/kit`,{method:"POST",headers:{Authorization:`Bearer ${this.accessToken}`,"Content-Type":"application/json"},body:JSON.stringify({kitName:`MonotypeFontKit_${t.substring(0,8)}`,kitType:"Embed",fontFormats:["WOFF2","WOFF"],fonts:[{fontId:t}],includeDefaultWordpressFiles:!1})});if(!i.ok){const d=await i.text();let u;try{u=JSON.parse(d)}catch{u=d}throw yn.error("WebFont kit generation failed:",{status:i.status,statusText:i.statusText,error:u,fontId:t,fontFamily:r}),new Error(`Kit generation failed: ${i.status} ${i.statusText}`)}const a=await i.json(),c={fontFamily:((s=a.webFonts[0])==null?void 0:s.fontFamily)||r,cssUrl:a.kitUrl,timestamp:Date.now()};return this.webfontKits.set(t,c),this.saveCachesToStorage(),c}catch(i){throw yn.error("Failed to generate WebFont kit:",i),i}}async loadMonotypeFont(t,r){try{const o=await this.getWebFontKit(t,r),s=`monotype-font-${t}`;if(document.getElementById(s))return;const i=document.createElement("link");i.id=s,i.rel="stylesheet",i.href=o.cssUrl,document.head.appendChild(i),await document.fonts.ready}catch(o){throw yn.error(`Failed to load Monotype font ${r}:`,o),o}}loadCachesFromStorage(){if(!(typeof window>"u"))try{const t=localStorage.getItem("monotype_webfont_kits");t&&(this.webfontKits=new Map(JSON.parse(t)))}catch(t){yn.error("Failed to load caches:",t)}}saveCachesToStorage(){if(!(typeof window>"u"))try{localStorage.setItem("monotype_webfont_kits",JSON.stringify(Array.from(this.webfontKits.entries())))}catch(t){yn.error("Failed to save caches:",t)}}clearCaches(){this.fonts.clear(),this.webfontKits.clear(),this.searchCache.clear(),this.fontsLoaded=!1,this.accessToken=null,this.tokenExpiry=0,localStorage.removeItem("monotype_fonts_cache"),localStorage.removeItem("monotype_webfont_kits")}getStats(){return{monotypeEnabled:this.monotypeEnabled,authenticated:this.isAuthenticated(),hasAccessToken:!!this.accessToken,tokenExpiry:this.tokenExpiry>0?new Date(this.tokenExpiry).toISOString():null,fontsLoaded:this.fontsLoaded,fontCount:this.fonts.size,familyCount:this.groupMonotypeFontsByFamily(this.getAllFonts()).length,webfontKitCount:this.webfontKits.size,searchCacheSize:this.searchCache.size}}}const Dn=new $m,ws=T.createLogger("UnifiedFontService");class Um{constructor(){this.searchCache=new Map,this.previewFontLinks=new Set}async initialize(){try{if(await Om(),Dn.isMonotypeEnabled())try{await Dn.authenticate(),await Dn.fetchAllFonts()}catch(t){ws.warn("Monotype fonts failed to load (continuing with Google Fonts only):",t)}}catch(t){ws.error("Failed to initialize UnifiedFontService:",t)}}isFontsLoaded(){return _m()||Dn.isFontsLoaded()}isMonotypeEnabled(){return Dn.isMonotypeEnabled()}getAllFonts(){const t=T.TSHIRT_FONTS.filter(s=>!s.googleFont&&!s.monotypeFont),r=this.mapGoogleFonts(vs()),o=Dn.groupMonotypeFontsByFamily(Dn.getAllFonts());return this.mergeFonts([...t,...r,...o])}getRecommendedFonts(){return T.TSHIRT_FONTS}async searchFontsByName(t){if(!t.trim())return this.getAllFonts();const r=`search:${t.toLowerCase()}`;if(this.searchCache.has(r))return this.searchCache.get(r);const o=t.toLowerCase().trim(),s=vs().filter(c=>c.family.toLowerCase().includes(o)).map(c=>this.mapGoogleFont(c)),i=await Dn.searchFontsByName(t),a=this.mergeFonts([...s,...i]);return this.searchCache.set(r,a),a}async filterFontsByCategory(t){if(t==="system")return T.TSHIRT_FONTS.filter(c=>!c.googleFont&&!c.monotypeFont);const r=`category:${t}`;if(this.searchCache.has(r))return this.searchCache.get(r);if(!oc(t))return[];const s=vs().filter(c=>Aa(c.category)===t).map(c=>this.mapGoogleFont(c)),i=await Dn.filterFontsByCategory(t),a=this.mergeFonts([...s,...i]);return this.searchCache.set(r,a),a}async searchAndFilterFonts(t,r){return t.trim()?this.searchFontsByName(t):r!=="all"?this.filterFontsByCategory(r):this.getAllFonts()}async loadFont(t){try{t.googleFont&&!t.monotypeFont?this.loadGoogleFont(t.name):t.monotypeFont&&t.monotypeId&&await Dn.loadMonotypeFont(t.monotypeId,t.name)}catch(r){ws.error(`Failed to load font ${t.name}:`,r)}}loadGoogleFont(t){const r=`font-${t.replace(/\s+/g,"-").toLowerCase()}`;if(document.getElementById(r))return;const o=document.createElement("link");o.id=r,o.rel="stylesheet",o.href=`https://fonts.googleapis.com/css2?family=${t.replace(/\s+/g,"+")}:wght@400;700&display=swap`,document.head.appendChild(o)}loadGoogleFontForPreview(t,r){const o=encodeURIComponent(r),s=`font-preview-${t.replace(/\s+/g,"-").toLowerCase()}`;if(document.getElementById(s))return;const i=document.createElement("link");i.id=s,i.rel="stylesheet",i.href=`https://fonts.googleapis.com/css2?family=${t.replace(/\s+/g,"+")}&display=swap&text=${o}`,document.head.appendChild(i),this.previewFontLinks.add(s)}clearPreviewFonts(){this.previewFontLinks.forEach(t=>{const r=document.getElementById(t);r&&r.remove()}),this.previewFontLinks.clear()}getPreviewFontCount(){return this.previewFontLinks.size}mapGoogleFont(t){var r;return{name:t.family,category:Aa(t.category),googleFont:!0,monotypeFont:!1,source:"google",weights:((r=t.variants)==null?void 0:r.map(o=>{const s=o.match(/\d+/);return s?parseInt(s[0],10):o==="regular"?400:null}).filter(o=>o!==null))||[400]}}mapGoogleFonts(t){return t.map(r=>this.mapGoogleFont(r))}mergeFonts(t){const r=new Map;return t.forEach(o=>{const s=o.name.toLowerCase().trim();if(!r.has(s))r.set(s,o);else{const i=r.get(s);o.monotypeFont&&!i.monotypeFont&&r.set(s,o)}}),Array.from(r.values()).sort((o,s)=>o.name.localeCompare(s.name))}clearSearchCache(){this.searchCache.clear()}clearAllCaches(){this.clearSearchCache(),Dn.clearCaches()}getStats(){const t=this.getAllFonts(),r=t.filter(i=>i.googleFont&&!i.monotypeFont),o=t.filter(i=>i.monotypeFont),s=t.filter(i=>!i.googleFont&&!i.monotypeFont);return{initialized:this.isFontsLoaded(),monotypeEnabled:this.isMonotypeEnabled(),totalFonts:t.length,googleFontsCount:r.length,monotopeFontsCount:o.length,systemFontsCount:s.length,searchCacheSize:this.searchCache.size,monotypeStats:Dn.getStats()}}}const On=new Um;function Ym(e){return Array.from(e).filter(t=>{const r=t.codePointAt(0);return!r||r<983040||r>1048573}).join("")}const Cs=T.createLogger("FontBrowserDrawer"),sc=({value:e,onChange:t,fontFamilies:r,isOpen:o,onToggle:s,showLabel:i,previewText:a,elements:c})=>{const d=l.useRef(null),[u,h]=l.useState(""),[f,p]=l.useState("all"),[g,b]=l.useState(0),[x,y]=l.useState("name"),[v,w]=l.useState("medium"),[C,j]=l.useState("masonry"),[M,S]=l.useState(new Set),R=l.useRef([]),I=l.useRef(!1),E=(A=>{switch(A){case"small":return 1;case"medium":return 1.8;case"large":return 3}})(v);l.useEffect(()=>{const A="font-preview-style";if(!document.getElementById(A)){const Z=document.createElement("style");Z.id=A,Z.textContent=".font-preview { font-family: var(--font-preview) !important; }",document.head.appendChild(Z)}},[]),l.useEffect(()=>{On.isFontsLoaded()||On.initialize().then(()=>{b(A=>A+1)}).catch(A=>{Cs.error("Failed to load fonts:",A)})},[]);const O=async(A,Z=!1)=>{try{if(Z)await On.loadFont(A);else if(A.googleFont&&!A.monotypeFont){const J=a?`${a}${A.name}`:A.name;On.loadGoogleFontForPreview(A.name,J)}else await On.loadFont(A);S(J=>new Set(J).add(A.name))}catch(J){Cs.error(`Failed to load font ${A.name}:`,J)}};l.useEffect(()=>{(async()=>{if(I.current||R.current.length===0)return;I.current=!0;const Z=[...R.current];R.current=[];const J=On.getAllFonts();await Promise.all(Z.map(async q=>{const ae=J.find(Le=>Le.name===q);ae&&!M.has(q)&&await O(ae)})),I.current=!1})()},[M]);const z=A=>{const Z=M.has(A),J=R.current.includes(A);!Z&&!J&&(R.current.push(A),!I.current&&R.current.length===1&&S(q=>new Set(q)))};l.useEffect(()=>{o&&setTimeout(()=>{d.current&&d.current.scrollIntoView({behavior:"smooth",block:"center"})},150),o||(h(""),p("all"),On.clearPreviewFonts(),S(new Set))},[o,e]),l.useEffect(()=>{if(e&&!M.has(e)){const Z=On.getAllFonts().find(J=>J.name===e);Z&&O(Z,!0)}},[e,M,g]),l.useEffect(()=>{u.trim()&&p("all")},[u]);const B=async A=>{const J=On.getAllFonts().find(q=>q.name===A);if(J)try{await O(J,!0)}catch{Cs.warn(`Failed to load font ${A}, will use fallback`)}t({target:{value:A}}),setTimeout(()=>s(!1),0)},k=l.memo(({font:A,isUsedInDocument:Z=!1})=>{const J=l.useRef(null),q=e===A.name,ae=M.has(A.name),Le=A.monotypeFont===!0;l.useEffect(()=>{if(!J.current)return;const ke=new IntersectionObserver(Ke=>{Ke.forEach(re=>{re.isIntersecting&&!ae&&z(A.name)})},{rootMargin:"600px"});return ke.observe(J.current),()=>ke.disconnect()},[A.name,ae]);let pe="",U=!1;x==="name"?(pe=A.name,U=!1):x==="preview"?(pe=a||A.name,U=Z):(pe=a||A.name,U=!0);const W=x==="preview"&&!U,Ie=n.jsxs(m.Surface,{ref:ke=>{q&&d&&(d.current=ke),J.current=ke},className:`relative flex cursor-pointer flex-col justify-center rounded-lg border-2 text-left ${C==="masonry"?"w-fit":"min-w-0"} ${q?"border-accent":"hover:border-muted border-transparent"}`,onClick:W?void 0:()=>B(A.name),role:W?void 0:"button","aria-label":W?void 0:`Select ${A.name} font`,tabIndex:W?void 0:0,onKeyDown:W?void 0:ke=>{(ke.key==="Enter"||ke.key===" ")&&(ke.preventDefault(),B(A.name))},style:{minHeight:`${U?48*E:36*E}px`,padding:`${6*E}px ${10*E}px`,gap:`${2*E}px`},children:[!ae&&n.jsx("div",{className:"absolute inset-0 rounded-lg bg-gray-100",style:{opacity:.5}}),n.jsx("div",{className:"font-preview text-foreground overflow-hidden leading-[1.1] font-medium text-ellipsis whitespace-nowrap",style:{"--font-preview":ae?`"${A.name}", sans-serif`:"sans-serif",fontSize:`${15*E}px`,opacity:ae?1:.4},children:pe}),U&&n.jsx("div",{className:"text-muted overflow-hidden font-sans leading-[1.1] font-normal text-ellipsis whitespace-nowrap",style:{fontSize:`${7*E}px`,opacity:ae?1:.4},children:A.name}),Le&&n.jsx("div",{className:"absolute rounded-full bg-orange-500",style:{top:`${4*E}px`,right:`${4*E}px`,width:`${6*E}px`,height:`${6*E}px`},title:"Premium Monotype Font"})]});return W?n.jsxs(m.Tooltip,{delayDuration:200,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{className:"m-0 inline-block h-auto min-h-0 border-0 bg-transparent p-0 hover:bg-transparent",style:{width:C==="masonry"?"auto":"100%"},onClick:()=>B(A.name),"aria-label":`Select ${A.name} font`,children:n.jsxs(m.Surface,{ref:ke=>{q&&d&&(d.current=ke),J.current=ke},className:`relative flex cursor-pointer flex-col justify-center rounded-lg border-2 text-left ${C==="masonry"?"w-fit":"min-w-0"} ${q?"border-accent":"hover:border-muted border-transparent"}`,style:{minHeight:`${U?48*E:36*E}px`,padding:`${6*E}px ${10*E}px`,gap:`${2*E}px`},children:[!ae&&n.jsx("div",{className:"absolute inset-0 rounded-lg bg-gray-100",style:{opacity:.5}}),n.jsx("div",{className:"font-preview text-foreground overflow-hidden leading-[1.1] font-medium text-ellipsis whitespace-nowrap",style:{"--font-preview":ae?`"${A.name}", sans-serif`:"sans-serif",fontSize:`${15*E}px`,opacity:ae?1:.4},children:pe}),U&&n.jsx("div",{className:"text-muted overflow-hidden font-sans leading-[1.1] font-normal text-ellipsis whitespace-nowrap",style:{fontSize:`${7*E}px`,opacity:ae?1:.4},children:A.name}),Le&&n.jsx("div",{className:"absolute rounded-full bg-orange-500",style:{top:`${4*E}px`,right:`${4*E}px`,width:`${6*E}px`,height:`${6*E}px`},title:"Premium Monotype Font"})]})})}),n.jsx(m.TooltipContent,{side:"top",children:n.jsx("p",{children:A.name})})]},A.name):n.jsx(l.Fragment,{children:Ie},A.name)},(A,Z)=>A.font.name===Z.font.name&&A.isUsedInDocument===Z.isUsedInDocument),Y=l.useMemo(()=>{if(!c)return new Set;const A=new Set,Z=J=>{const q=J.fontFamily,ae=J.text;q&&ae&&Ym(ae).trim().length>0&&A.add(q)};return c.forEach(J=>{Z(J),J.children&&Array.isArray(J.children)&&J.children.forEach(q=>{Z(q)})}),A},[c]),_=l.useMemo(()=>{const A=On.isFontsLoaded()?On.getAllFonts():T.TSHIRT_FONTS,Z=new Set(T.TSHIRT_FONTS.map(pe=>pe.name)),J=[];A.forEach(pe=>{if(Y.has(pe.name))if(u){const U=u.toLowerCase();pe.name.toLowerCase().includes(U)&&J.push(pe)}else J.push(pe)});let q=A.filter(pe=>!Y.has(pe.name));if(f!=="all"&&(q=q.filter(pe=>pe.category===f)),u){const pe=u.toLowerCase();q=q.filter(U=>U.name.toLowerCase().includes(pe))}const ae=[],Le=[];return q.forEach(pe=>{Z.has(pe.name)?ae.push(pe):Le.push(pe)}),J.sort((pe,U)=>pe.name.localeCompare(U.name)),ae.sort((pe,U)=>pe.name.localeCompare(U.name)),Le.sort((pe,U)=>pe.name.localeCompare(U.name)),{usedFonts:J,recommendedFonts:ae,otherFonts:Le}},[u,f,g,Y]),G=(A,Z=!1)=>C==="masonry"?n.jsx("div",{className:"flex flex-wrap content-start items-start gap-2 px-4 pb-4",children:A.map(J=>n.jsx(k,{font:J,isUsedInDocument:Z},J.name))}):n.jsx("div",{className:"px-4 pb-4",style:{display:"grid",gridTemplateColumns:`repeat(auto-fill, minmax(${140*E}px, 1fr))`,gap:"8px"},children:A.map(J=>n.jsx(k,{font:J,isUsedInDocument:Z},J.name))}),se=["all","system","display","sans-serif","script","serif","slab-serif","vintage","decorative","monospace"];return n.jsxs(n.Fragment,{children:[n.jsx("button",{onClick:()=>s(!o),className:`h-11 md:h-9 w-[132px] md:w-[108px] flex items-center justify-center px-2 text-foreground cursor-pointer rounded-lg border border-transparent text-base font-medium transition-all hover:bg-black/5 dark:hover:bg-white/5 ${o?"bg-black/10 dark:bg-white/10":"bg-transparent"}`,"aria-label":o?"Close font browser":"Open font browser",title:e,children:n.jsx("span",{className:"font-preview overflow-hidden text-ellipsis whitespace-nowrap min-w-0",style:{"--font-preview":`"${e}", sans-serif`,fontWeight:400},children:e})}),n.jsx(oo,{isOpen:o,onClose:()=>s(!1),title:"Fonts",description:"",height:"85vh",placement:"bottom",showCloseButton:!1,hideVisibleTitle:!0,hideHandle:!0,disableScrollWrapper:!0,children:n.jsx("div",{className:"relative flex-1 overflow-hidden",children:n.jsx("div",{className:"h-full bg-white",children:n.jsxs("div",{className:"h-full overflow-y-auto",children:[n.jsx("div",{className:"px-4 pt-5",children:n.jsxs(m.Surface,{className:"flex gap-2",children:[n.jsx(m.TextField,{className:"flex-1","aria-label":"Search fonts",children:n.jsx(m.Input,{type:"text",className:"rounded-2xl pt-[10px] pb-[9px]",placeholder:"Search fonts...",value:u,onChange:A=>h(A.target.value),autoFocus:!0,"aria-label":"Search fonts"})}),n.jsx(m.Tabs,{value:v,onValueChange:A=>w(A),children:n.jsx(m.Tabs.ListContainer,{children:n.jsxs(m.Tabs.List,{"aria-label":"Card size",children:[n.jsxs(m.Tabs.Tab,{id:"small",className:"text-xs font-semibold","aria-label":"Small card size",children:["A",n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"medium",className:"text-base font-semibold","aria-label":"Medium card size",children:["A",n.jsx(m.Tabs.Indicator,{})]}),n.jsxs(m.Tabs.Tab,{id:"large",className:"text-xl font-semibold","aria-label":"Large card size",children:["A",n.jsx(m.Tabs.Indicator,{})]})]})})}),n.jsx(m.Button,{variant:"secondary",onClick:()=>{y(A=>A==="both"?"name":A==="name"?"preview":"both")},"aria-label":x==="both"?"Show font name only":x==="name"?"Show preview only":"Show preview with font name",className:"h-10 w-10 p-0",children:x==="both"?n.jsx(de,{icon:"lucide:credit-card",className:"size-[22px]"}):x==="name"?n.jsx(de,{icon:"lucide:type",className:"size-[22px]"}):n.jsx(de,{icon:"lucide:text-cursor",className:"size-[22px]"})}),n.jsx(m.Button,{variant:"secondary",onClick:()=>j(C==="grid"?"masonry":"grid"),"aria-label":C==="grid"?"Switch to masonry view":"Switch to grid view",className:"h-10 w-10 p-0",children:C==="grid"?n.jsx(de,{icon:"lucide:grid-2x2",className:"size-[22px]"}):n.jsx(de,{icon:"lucide:grid-3x3",className:"size-[22px]"})})]})}),n.jsxs("div",{className:"sticky top-0 z-20 shrink-0",children:[n.jsx("div",{className:"pointer-events-none absolute top-0 right-0 left-0",style:{height:"64px",background:"linear-gradient(to bottom, var(--background) 0%, color-mix(in srgb, var(--background) 80%, transparent) 40%, transparent 100%)",zIndex:16}}),n.jsx("div",{className:"relative z-20 px-4 py-4 pt-3",children:n.jsx("div",{className:"flex gap-2 overflow-x-auto",children:se.map(A=>{const Z=A==="all"?"All":T.CATEGORY_LABELS[A];return n.jsx(m.Button,{size:"sm",variant:f===A?"default":"secondary",onClick:()=>p(A),className:`shrink-0 ${f===A?"":"hover:brightness-95"}`,children:Z},A)})})})]}),n.jsxs("div",{className:"flex-1",children:[_.usedFonts.length>0&&n.jsxs("div",{className:"shrink-0 p-0",children:[n.jsx("div",{className:"text-muted bg-white px-4 pt-2 pb-2 text-xs font-bold tracking-wider uppercase",children:"Used in Document"}),G(_.usedFonts,!0)]}),_.recommendedFonts.length===0&&_.otherFonts.length===0?n.jsx("div",{className:"text-muted col-span-full px-4 py-8 text-center text-sm",children:"No fonts found"}):n.jsxs(n.Fragment,{children:[_.recommendedFonts.length>0&&n.jsxs("div",{className:"p-0",children:[n.jsx("div",{className:"text-muted bg-white px-4 pt-2 pb-2 text-xs font-bold tracking-wider uppercase",children:"Recommended"}),G(_.recommendedFonts)]}),_.otherFonts.length>0&&n.jsxs("div",{className:"p-0",children:[n.jsx("div",{className:"text-muted bg-white px-4 pt-4 pb-2 text-xs font-bold tracking-wider uppercase",children:"All Fonts"}),G(_.otherFonts)]})]})]})]})})})})]})},Wm=T.createLogger("TransformControlPanel"),ic=({element:e,controls:t,onUpdate:r})=>{const[o,s]=l.useState({});return n.jsx("div",{className:"w-full space-y-4",children:t.map(i=>{const a=e.transformData[i.key]??i.defaultInternalValue??i.defaultValue;if(i.type==="checkbox")return n.jsxs("div",{className:"flex items-center space-x-2",children:[n.jsx(m.Switch,{id:`control-${i.key}`,checked:a,onCheckedChange:f=>{const p=e.clone();p.transformData[i.key]=f,r(p)}}),n.jsx(m.Label,{htmlFor:`control-${i.key}`,children:i.label})]},i.key);const c=typeof a=="number"&&!isNaN(a)?a:i.defaultInternalValue??0,d=o[i.key]!==void 0?o[i.key]:c,u=i.toSlider?i.toSlider(d):d,h=f=>{const p=i.fromSlider?i.fromSlider(f):f;return typeof p!="number"||isNaN(p)?(Wm.warn("Invalid internalValue:",p,"for control:",i.key),"0"):i.toDisplay?i.toDisplay(p):"isPercentage"in i&&i.isPercentage?`${(p*100).toFixed(0)}%`:p.toFixed(1)};return n.jsxs("div",{className:"flex flex-col gap-sm",children:[n.jsxs("div",{className:"flex justify-between",children:[n.jsx(m.Label,{children:i.label}),n.jsx("span",{className:"text-sm text-foreground/60",children:h(u)})]}),n.jsx(m.Slider,{value:[u],onValueChange:f=>{const p=f[0],g=i.fromSlider?i.fromSlider(p):p;s(b=>({...b,[i.key]:g}))},onChangeEnd:f=>{const p=f[0],g=e.clone();g.transformData[i.key]=i.fromSlider?i.fromSlider(p):p,r(g),s(b=>{const x={...b};return delete x[i.key],x})},min:0,max:100,step:i.step??1,className:"slider-no-fill"})]},i.key)})})},Xm=({element:e,onTransformTypeChange:t,onElementUpdate:r,isOpen:o,onOpenChange:s})=>{const[i,a]=l.useState(!1),c=o!==void 0?o:i,d=s||a,u=e.transformType,h=T.getTransformControls(u),f=T.TRANSFORM_TYPES.filter(g=>g.Component&&g.id!=="image"&&g.id!=="group"&&g.id!=="shape"&&g.id!=="path"),p=g=>{g!==u&&t(g)};return n.jsxs(m.Popover,{open:c,onOpenChange:d,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn","aria-label":"Text Effects",children:n.jsx(de,{icon:Re.wand,className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"start",className:"w-[280px] p-0",maxZIndex:!0,children:n.jsxs("div",{className:"space-y-4 p-6",children:[n.jsxs("div",{className:"space-y-2",children:[n.jsx(m.Label,{children:"Text Effect"}),n.jsxs(m.Select,{value:u,onValueChange:p,children:[n.jsx(m.SelectTrigger,{children:n.jsx(m.SelectValue,{placeholder:"Select effect"})}),n.jsx(m.SelectContent,{style:{zIndex:2147483647},children:f.map(g=>n.jsx(m.SelectItem,{value:g.id,children:g.label},g.id))})]})]}),h.length>0&&n.jsx(ic,{element:e,controls:h,onUpdate:r})]})})]})},ac=({items:e})=>{const[t,r]=l.useState(!1);return n.jsxs(m.Popover,{open:t,onOpenChange:r,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn","aria-label":"More options",children:n.jsx(de,{icon:Re.moreHorizontal,className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"start",className:"w-auto p-1",maxZIndex:!0,children:n.jsx("div",{className:"flex items-center gap-1",children:e.map((o,s)=>n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:o.active?"default":"ghost",size:"icon",onClick:()=>{o.onClick(),r(!1)},"aria-label":o.label,children:o.icon})}),n.jsx(m.TooltipContent,{children:o.label})]},s))})})]})};function lc({colorPickerValue:e,isActive:t,onClick:r}){return n.jsxs(m.Tooltip,{delay:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn",onClick:r,"aria-label":"Font Color","data-active":t,children:n.jsxs("div",{className:"relative flex h-5 w-5 items-center justify-center",children:[n.jsx("span",{className:"-translate-y-0.5 text-lg leading-none font-bold",children:"A"}),n.jsx("div",{className:"absolute bottom-0 left-1/2 h-[3px] w-4 -translate-x-1/2 rounded-sm",style:{backgroundColor:e}})]})})}),!t&&n.jsx(m.TooltipContent,{children:"Font Color"})]})}function cc({toolbar:e}){return n.jsx(ct,{icon:Re.bold,onClick:e.handleBoldToggle,active:e.getEffectiveStyle().bold,tooltip:"Bold"})}function dc({toolbar:e}){return n.jsx(ct,{icon:Re.italic,onClick:e.handleItalicToggle,active:e.getEffectiveStyle().italic,tooltip:"Italic"})}function uc({toolbar:e}){return n.jsx(ct,{icon:Re.underline,onClick:e.handleUnderlineToggle,active:e.getEffectiveStyle().underline,tooltip:"Underline"})}function hc({toolbar:e}){return n.jsx(ct,{icon:"lucide:case-upper",onClick:e.handleLetterCaseToggle,active:e.isLetterCaseActive(),tooltip:"Uppercase"})}function fc({toolbar:e}){const{textAlign:t,handleTextAlignToggle:r}=e,o=t==="left"?Re.alignLeft:t==="center"?Re.alignCenter:Re.alignRight;return n.jsx(ct,{icon:o,onClick:r,tooltip:`Align ${t.charAt(0).toUpperCase()+t.slice(1)}`})}function pc({onMoveForward:e,onMoveBackward:t,onDelete:r,onOpenChange:o}){const[s,i]=l.useState(!1),a=c=>{i(c),o==null||o(c)};return n.jsxs(m.Popover,{open:s,onOpenChange:a,children:[n.jsx(m.PopoverTrigger,{asChild:!0,children:n.jsx("button",{className:"toolbar-btn","aria-label":"More options",children:n.jsx(de,{icon:"lucide:ellipsis-vertical",className:"size-6"})})}),n.jsx(m.PopoverContent,{align:"end",className:"w-auto p-1",maxZIndex:!0,children:n.jsxs("div",{className:"flex items-center gap-1",children:[n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{e(),a(!1)},"aria-label":"Move Forward",children:n.jsx(de,{icon:"hugeicons:layer-bring-forward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Forward"})]}),n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{t(),a(!1)},"aria-label":"Move Backward",children:n.jsx(de,{icon:"hugeicons:layer-send-backward",className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Move Backward"})]}),n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:()=>{a(!1),r()},"aria-label":"Delete",children:n.jsx(de,{icon:Re.trash,className:"size-5"})})}),n.jsx(m.TooltipContent,{children:"Delete"})]})]})})]})}function mc({toolbar:e,stableElementId:t,viewportWidth:r=window.innerWidth,colorPickerValue:o,isColorActive:s,onColorToggle:i,onOpenGlyphBrowser:a,hasGlyphs:c=!1,expandedPanel:d,onRotationToggle:u,onOpacityToggle:h,onFontSizeToggle:f,strokeExpanded:p=!1,onStrokeToggle:g,knockoutExpanded:b=!1,onKnockoutToggle:x,distressTextureExpanded:y=!1,onDistressTextureToggle:v,imageMaskExpanded:w=!1,onImageMaskToggle:C,getMoreMenuItems:j,onMoveForward:M,onMoveBackward:S,onDelete:R,elementForProperties:I,elements:D,isTransformMenuOpen:E,onTransformMenuOpenChange:O,elementUpdateHandler:z,showUngroupButton:B=!1,onUngroup:k,isFontBrowserOpen:Y=!1,onFontBrowserToggle:_,onTextMoreMenuOpenChange:G}){const[se,A]=l.useState(!1),[Z,J]=l.useState(!1),[q,ae]=l.useState(!1),[Le,pe]=l.useState(!1),U=Uo(I),[W,Ie]=l.useState(!1),[ke,Ke]=l.useState(!1),[re,te]=l.useState(!1),[he,ye]=l.useState(!1);return n.jsxs("div",{className:"toolbar-items",children:[n.jsx(sc,{value:e.getEffectiveStyle().fontFamily||e.fontFamily,onChange:we=>e.handleFontFamilyChange(we.target.value),fontFamilies:T.FONT_FAMILIES,isOpen:Y,onToggle:_,showLabel:r>700,previewText:"text"in I?I.text:void 0,elements:D}),n.jsx(ct,{icon:"lucide:a-large-small",onClick:()=>{pe(!0),f()},onMouseLeave:()=>pe(!1),tooltip:`Font Size · ${Math.round(e.fontSize)}`,tooltipDisabled:Le||(d==null?void 0:d.type)==="fontSize",active:(d==null?void 0:d.type)==="fontSize"}),n.jsx(lc,{colorPickerValue:o,isActive:s,onClick:i}),n.jsx(cc,{toolbar:e}),n.jsx(dc,{toolbar:e}),n.jsx(uc,{toolbar:e}),n.jsx(hc,{toolbar:e}),n.jsx(fc,{toolbar:e}),n.jsx(Xm,{element:I,onTransformTypeChange:e.handleTransformTypeChange,onElementUpdate:z,isOpen:E,onOpenChange:O}),g&&n.jsx(ct,{icon:"lucide:pen-line",onClick:()=>{A(!0),g()},onMouseLeave:()=>A(!1),tooltip:"Stroke",tooltipDisabled:se||p,active:p||U.stroke}),n.jsx(ct,{icon:n.jsx(Bo,{size:20,className:"md:size-5"}),onClick:()=>{ae(!0),u()},onMouseLeave:()=>ae(!1),tooltip:"Rotate",tooltipDisabled:q||(d==null?void 0:d.type)==="rotation",active:(d==null?void 0:d.type)==="rotation"||U.rotation}),n.jsx(ct,{icon:"lucide:blend",onClick:()=>{Ie(!0),h()},onMouseLeave:()=>Ie(!1),tooltip:"Transparency",tooltipDisabled:W||(d==null?void 0:d.type)==="opacity",active:(d==null?void 0:d.type)==="opacity"||U.opacity}),x&&n.jsx(ct,{icon:"lucide:scissors",onClick:()=>{Ke(!0),x()},onMouseLeave:()=>Ke(!1),tooltip:"Clip / Knockout",tooltipDisabled:ke||b,active:b||U.knockout}),v&&n.jsx(ct,{icon:"lucide:stamp",onClick:()=>{te(!0),v()},onMouseLeave:()=>te(!1),tooltip:"Distress Texture",tooltipDisabled:re||y,active:y||U.distress}),C&&n.jsx(ct,{icon:"lucide:venetian-mask",onClick:()=>{ye(!0),C()},onMouseLeave:()=>ye(!1),tooltip:"Image Mask",tooltipDisabled:he||w,active:w||U.imageMask}),n.jsx(ct,{icon:"lucide:flag",onClick:()=>{J(!0),a==null||a()},onMouseLeave:()=>J(!1),tooltip:c?"Browse All Glyphs":"No alternate glyphs available",tooltipDisabled:Z,disabled:!c,className:c?"":"opacity-50"}),j&&n.jsx(ac,{items:j()}),n.jsx(pc,{onMoveForward:M,onMoveBackward:S,onDelete:R,onOpenChange:G}),B&&n.jsx("button",{className:"toolbar-btn",onClick:k,children:"Ungroup"})]},`text-toolbar-${t}`)}function Vm(e,t,r){const o=e.getRotationAnchor();let s;e.transformType==="circle"&&"getEffectiveFontSize"in e?s=e.getEffectiveFontSize():s=e.fontSize;const i=Gm(e,t,s,o);return new r({id:e.id,text:e.text,x:i.x,y:i.y,rotation:e.rotation,fontSize:i.fontSize,fontFamily:e.fontFamily,color:e.color,textAlign:e.textAlign,transformData:i.transformData})}function Gm(e,t,r,o){let s,i,a;const c=r;switch(t){case"circle":s={radius:r*1.2*2,scale:1},i=o.x,a=o.y;break;case"custom":const h=200,f=r*e.text.length*.6,p=Math.max(f,h);s={width:p};const g=r*1.2;i=o.x-p/2,a=o.y-g/2;break;case"arch":const b=200,x=r*e.text.length*.6;s={width:Math.max(x,b),archHeight:T.ARCH_DEFAULTS.archHeight},i=o.x,a=o.y;break;case"wave":const y=200,v=r*e.text.length*.6;s={width:Math.max(v,y),amplitude:T.WAVE_DEFAULTS.amplitude,frequency:T.WAVE_DEFAULTS.frequency},i=o.x,a=o.y;break;case"flag":const w=200,C=r*e.text.length*.6;s={width:Math.max(C,w),amplitude:T.FLAG_DEFAULTS.amplitude,frequency:T.FLAG_DEFAULTS.frequency},i=o.x,a=o.y;break;case"lean":const j=200,M=r*e.text.length*.6;s={width:Math.max(M,j),leanAmount:T.LEAN_DEFAULTS.leanAmount},i=o.x,a=o.y;break;default:s={width:200},i=o.x,a=o.y}return{x:i,y:a,fontSize:c,transformData:s}}function gc(e={}){const{canvasEditorRef:t}=e,{selectedElement:r,activeChildElement:o,handleElementUpdate:s}=Yt.useEditor(),i=o||r,a=l.useCallback(U=>{if(r)if(o){if(!(r instanceof T.GroupElement))return;const W=r.clone(),Ie=W.children.findIndex(ke=>ke.id===o.id);Ie!==-1&&(W.children[Ie]=U,s(W))}else s(U)},[r,o,s]),c=i==null?void 0:i.id,d=l.useRef(void 0),[u,h]=l.useState(32),[f,p]=l.useState("#333333"),[g,b]=l.useState("Arial"),[x,y]=l.useState("center");l.useEffect(()=>{c!==d.current&&(d.current=c,i&&i instanceof T.TextElement&&(i.transformType==="circle"&&"getEffectiveFontSize"in i?h(Math.round(i.getEffectiveFontSize())):i.fontSize!==void 0&&h(Math.round(i.fontSize)),i.color!==void 0&&p(i.color),i.fontFamily!==void 0&&b(i.fontFamily),y(i.textAlign||"center")))},[c,i]);const v=u,w=f,C=g,j=x,M=i instanceof T.TextElement?i:null,S=(M==null?void 0:M.bold)??!1,R=(M==null?void 0:M.italic)??!1,I=(M==null?void 0:M.underline)??!1,D=(M==null?void 0:M.letterCase)??"none",E=l.useCallback(U=>{if(h(U),!i||!(i instanceof T.TextElement))return;const W=i.clone();W.transformType==="circle"&&"setEffectiveFontSize"in W?W.setEffectiveFontSize(U):W.setFontSize(U),W.richText&&W.richText.clearStyleProperty("fontSize"),a(W)},[i,a]),O=l.useCallback(U=>{if(b(U),!i||!(i instanceof T.TextElement))return;const W=i.clone();W.fontFamily=U,W.richText&&W.richText.clearStyleProperty("fontFamily"),a(W)},[i,a]),z=l.useCallback(U=>{if(p(U),!i||!(i instanceof T.TextElement))return;const W=i.clone();W.color=U,W.richText&&W.richText.clearStyleProperty("color"),a(W)},[i,a]),B=l.useCallback(U=>{if(y(U),!i||!(i instanceof T.TextElement))return;const W=i.clone();W.textAlign=U,a(W)},[i,a]),k=l.useCallback(U=>{var W;(W=t==null?void 0:t.current)!=null&&W.isEditingText()?t.current.applyTextFormatting({fontSize:U}):E(U)},[E,t]),Y=l.useCallback(U=>{const W=v+U;W>=8&&W<=500&&k(W)},[v,k]),_=l.useCallback(U=>{var W;(W=t==null?void 0:t.current)!=null&&W.isEditingText()?t.current.applyTextFormatting({fontFamily:U}):O(U)},[O,t]),G=l.useCallback(U=>{var ke;const W=U.target.value;((ke=t==null?void 0:t.current)==null?void 0:ke.isEditingText())&&(t!=null&&t.current)?t.current.applyTextFormatting({color:W}):z(W)},[z,t]),se=l.useCallback(()=>{var U;if((U=t==null?void 0:t.current)!=null&&U.isEditingText())t.current.toggleFormattingProperty("bold");else{if(!i||!(i instanceof T.TextElement))return;const W=i.clone();W.bold=!S,W.richText&&W.richText.clearStyleProperty("bold"),a(W)}},[S,i,a,t]),A=l.useCallback(()=>{var U;if((U=t==null?void 0:t.current)!=null&&U.isEditingText())t.current.toggleFormattingProperty("italic");else{if(!i||!(i instanceof T.TextElement))return;const W=i.clone();W.italic=!R,W.richText&&W.richText.clearStyleProperty("italic"),a(W)}},[R,i,a,t]),Z=l.useCallback(()=>{var U;if((U=t==null?void 0:t.current)!=null&&U.isEditingText())t.current.toggleFormattingProperty("underline");else{if(!i||!(i instanceof T.TextElement))return;const W=i.clone();W.underline=!I,W.richText&&W.richText.clearStyleProperty("underline"),a(W)}},[I,i,a,t]),J=l.useCallback(()=>{if(!i)return;const U=D==="uppercase"?"none":"uppercase",W=i.clone();W.letterCase=U,a(W)},[D,i,a]),q=l.useCallback(()=>D==="uppercase",[D]),ae=l.useCallback(()=>{const U=["left","center","right"],W=U.indexOf(j),Ie=U[(W+1)%U.length];B(Ie)},[j,B]),Le=l.useCallback(()=>{var U,W,Ie,ke;if((W=(U=t==null?void 0:t.current)==null?void 0:U.isEditingText)!=null&&W.call(U)){const Ke=(ke=(Ie=t.current).getSelectionStyle)==null?void 0:ke.call(Ie);if(Ke)return{fontFamily:Ke.fontFamily??C,fontSize:Ke.fontSize??v,color:Ke.color??w,bold:Ke.bold??S,italic:Ke.italic??R,underline:Ke.underline??I}}return{fontFamily:C,fontSize:v,color:w,bold:S,italic:R,underline:I}},[t,C,v,w,S,R,I]),pe=l.useCallback(U=>{if(!i)return;const W=T.getTransformById(U);if(!(W!=null&&W.Component))return;const Ie=Vm(i,U,W.Component);a(Ie)},[i,a]);return{fontSize:v,fontColor:w,fontFamily:C,textAlign:j,bold:S,italic:R,underline:I,letterCase:D,handleFontSizeChange:k,handleFontSizeIncrement:Y,handleFontFamilyChange:_,handleFontColorChange:G,handleBoldToggle:se,handleItalicToggle:A,handleUnderlineToggle:Z,handleLetterCaseToggle:J,isLetterCaseActive:q,handleTextAlignToggle:ae,getEffectiveStyle:Le,handleTransformTypeChange:pe}}const Km=T.createLogger("useLayerPreview");function xc(e){var h,f,p,g;const{element:t,size:r=148,backgroundColor:o="transparent",enabled:s=!0}=e,[i,a]=l.useState(null),[c,d]=l.useState(!1),u=l.useRef(null);return l.useEffect(()=>{if(!s){a(null),d(!1);return}let b=!0;return d(!0),u.current&&clearTimeout(u.current),u.current=setTimeout(()=>{(async()=>{try{if(t instanceof T.ImageElement&&t.imageUrl){const v=new Image;if(v.crossOrigin="anonymous",await new Promise((w,C)=>{v.onload=()=>w(),v.onerror=()=>C(new Error("Failed to load image")),v.src=t.imageUrl}),!b)return}const y=Ts(t,{width:r,height:r,padding:8,backgroundColor:o});b&&(a(y),d(!1))}catch(y){if(Km.warn("Failed to generate preview:",y),b){const v=Ts(t,{width:r,height:r,padding:8,backgroundColor:o});a(v),d(!1)}}})()},50),()=>{b=!1,u.current&&clearTimeout(u.current)}},[t.id,o,r,s,t.x,t.y,t.rotation,t.transformData,t instanceof T.TextElement?t.text:null,t instanceof T.TextElement?t.fontSize:null,t instanceof T.TextElement?t.fontFamily:null,t instanceof T.TextElement?t.color:null,t instanceof T.ImageElement?t.imageUrl:null,t instanceof T.ImageElement?t.imageLoaded:null,t instanceof T.ImageElement?t.isCropping:null,t instanceof T.ShapeElement?(h=t.transformData)==null?void 0:h.fillColor:null,t instanceof T.PathElement?(p=(f=t.transformData)==null?void 0:f.points)==null?void 0:p.length:null,t instanceof T.GroupElement?(g=t.children)==null?void 0:g.length:null]),{previewUrl:i,isLoading:c}}function qm({element:e,onToggleLock:t,onThumbnailClick:r}){if(!e)return null;const o=e.locked===!0;return n.jsxs(n.Fragment,{children:[n.jsx(Zm,{element:e,onClick:r}),n.jsx(ct,{icon:n.jsx(Jm,{locked:o}),onClick:t,active:o,tooltip:o?"Unlock layer":"Lock layer","aria-label":o?"Unlock layer":"Lock layer"})]})}function Zm({element:e,onClick:t}){const{previewUrl:r}=xc({element:e,size:64,backgroundColor:"transparent"}),o=n.jsx("span",{className:"size-6 md:size-5 rounded-md shrink-0 flex items-center justify-center overflow-hidden",style:{background:"var(--color-muted, rgba(120,120,120,0.18))"},children:r?n.jsx("img",{src:r,alt:"",style:{width:"100%",height:"100%",objectFit:"contain"}}):null});return t?n.jsx("button",{type:"button",onClick:t,onPointerDown:s=>s.stopPropagation(),onPointerUp:s=>s.stopPropagation(),"aria-label":"Manage layers",title:"Manage layers",className:"size-11 md:size-9 shrink-0 flex items-center justify-center",children:o}):n.jsx("span",{"aria-hidden":!0,className:"size-11 md:size-9 shrink-0 flex items-center justify-center",children:o})}function Jm({locked:e}){return n.jsxs("svg",{width:"20",height:"20",viewBox:"0 0 20 20",fill:"none","aria-hidden":!0,children:[n.jsx("rect",{x:"4",y:"9",width:"12",height:"8.5",rx:"1.6",stroke:"currentColor",strokeWidth:"1.6",fill:e?"currentColor":"none",fillOpacity:e?.18:0}),e?n.jsx("path",{d:"M6.5 9V6.25a3.5 3.5 0 0 1 7 0V9",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"}):n.jsx("path",{d:"M6.5 9V6.25a3.5 3.5 0 0 1 7 0",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round"})]})}const Qm=({element:e,rotationExpanded:t=!1,onRotationToggle:r,opacityExpanded:o=!1,onOpacityToggle:s,strokeExpanded:i=!1,onStrokeToggle:a,knockoutExpanded:c=!1,onKnockoutToggle:d,distressTextureExpanded:u=!1,onDistressTextureToggle:h,imageMaskExpanded:f=!1,onImageMaskToggle:p,onUngroup:g})=>{const[b,x]=l.useState(!1),[y,v]=l.useState(!1),[w,C]=l.useState(!1),[j,M]=l.useState(!1),[S,R]=l.useState(!1),[I,D]=l.useState(!1),E=Uo(e??null);return n.jsxs("div",{className:"toolbar-items",children:[n.jsx(ct,{icon:n.jsx(Bo,{size:20,className:"md:size-5"}),onClick:()=>{x(!0),r()},onMouseLeave:()=>x(!1),tooltip:"Rotate",tooltipDisabled:b||t,active:t||E.rotation}),n.jsx(ct,{icon:"lucide:blend",onClick:()=>{v(!0),s()},onMouseLeave:()=>v(!1),tooltip:"Transparency",tooltipDisabled:y||o,active:o||E.opacity}),a&&n.jsx(ct,{icon:"lucide:pen-line",onClick:()=>{C(!0),a()},onMouseLeave:()=>C(!1),tooltip:"Stroke",tooltipDisabled:w||i,active:i||E.stroke}),d&&n.jsx(ct,{icon:"lucide:scissors",onClick:()=>{M(!0),d()},onMouseLeave:()=>M(!1),tooltip:"Knockout",tooltipDisabled:j||c,active:c||E.knockout}),h&&n.jsx(ct,{icon:"lucide:stamp",onClick:()=>{R(!0),h()},onMouseLeave:()=>R(!1),tooltip:"Distress Texture",tooltipDisabled:S||u,active:u||E.distress}),p&&n.jsx(ct,{icon:"lucide:venetian-mask",onClick:()=>{D(!0),p()},onMouseLeave:()=>D(!1),tooltip:"Image Mask",tooltipDisabled:I||f,active:f||E.imageMask}),n.jsxs(m.Tooltip,{delayDuration:300,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"sm",onClick:g,children:"Ungroup"})}),n.jsx(m.TooltipContent,{children:"Ungroup this group"})]})]})};function Da({children:e,className:t}){const r=l.useRef(null);return l.useEffect(()=>{const o=r.current;if(!o)return;const s=a=>{a.stopPropagation()},i=a=>{a.preventDefault(),a.stopPropagation()};return o.addEventListener("touchstart",s,{passive:!1}),o.addEventListener("touchmove",i,{passive:!1}),()=>{o.removeEventListener("touchstart",s),o.removeEventListener("touchmove",i)}},[]),n.jsx("div",{ref:r,className:t,style:{touchAction:"none"},children:e})}const qr=({element:e,onElementUpdate:t,className:r})=>{var g,b;const[o,s]=l.useState("center"),i=l.useRef(null),a=l.useRef({x:0,y:0});l.useEffect(()=>{const x=i.current;if(!x)return;const y=w=>{a.current={x:w.touches[0].clientX,y:w.touches[0].clientY}},v=w=>{const C=Math.abs(w.touches[0].clientX-a.current.x),j=Math.abs(w.touches[0].clientY-a.current.y);C>10&&C>j&&w.preventDefault()};return x.addEventListener("touchstart",y,{passive:!0}),x.addEventListener("touchmove",v,{passive:!1}),()=>{x.removeEventListener("touchstart",y),x.removeEventListener("touchmove",v)}},[]);const c=((g=e.transformData)==null?void 0:g.cropWidth)||1,d=((b=e.transformData)==null?void 0:b.cropHeight)||1,u=l.useCallback((x,y,v,w)=>{const C=e.clone();C.updateCrop(x,y,v,w,!0),t(C)},[e,t]),h=l.useCallback((x,y=o)=>{const v=e.transformData.cropWidth,w=e.transformData.cropX,C=x-v;let j=w;y.includes("center")?j=w-C/2:y.includes("right")&&(j=w-C),j=Math.max(0,Math.min(1-x,j)),u(j,e.transformData.cropY,x,e.transformData.cropHeight)},[e,u,o]),f=l.useCallback((x,y=o)=>{const v=e.transformData.cropHeight,w=e.transformData.cropY,C=x-v;let j=w;y.includes("middle")||y==="center"?j=w-C/2:y.includes("bottom")&&(j=w-C),j=Math.max(0,Math.min(1-x,j)),u(e.transformData.cropX,j,e.transformData.cropWidth,x)},[e,u,o]),p=["top-left","top-center","top-right","middle-left","center","middle-right","bottom-left","bottom-center","bottom-right"];return n.jsx("div",{ref:i,"data-preserve-selection":!0,className:_n("flex min-h-0 flex-1 flex-col",r),style:{touchAction:"pan-y"},children:n.jsx("div",{className:"flex flex-col gap-5 px-5 pt-1 pb-[calc(env(safe-area-inset-bottom,0px)+20px)] md:gap-4 md:px-4 md:pt-0 md:pb-[calc(env(safe-area-inset-bottom,0px)+16px)]",children:n.jsxs("div",{className:"flex items-start gap-6 md:gap-5",children:[n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx("span",{className:"text-foreground/60 text-sm md:text-xs",children:"Anchor"}),n.jsx("div",{className:"grid grid-cols-3 gap-0.5 rounded-md p-1",children:p.map(x=>n.jsx("button",{onClick:()=>s(x),className:_n("crop-anchor-btn size-8 rounded-md md:size-6 md:rounded",o===x&&"active"),title:x.replace("-"," "),children:n.jsx("div",{className:_n("crop-anchor-dot size-2 md:size-1.5",o===x&&"active size-2.5 md:size-2")})},x))})]}),n.jsxs("div",{className:"flex flex-1 flex-col gap-4 md:gap-3",children:[n.jsxs("div",{className:"flex flex-col gap-2.5 md:gap-1.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-foreground/60 text-sm md:text-xs",children:"Width"}),n.jsx("input",{type:"number",value:Math.round(c*100),onChange:x=>h(Math.max(10,Math.min(100,Number(x.target.value)))/100),min:10,max:100,className:"bg-transparent text-foreground w-14 rounded-md border-none px-2.5 py-2 text-right text-base md:w-14 md:rounded md:px-1.5 md:py-1 md:text-[13px]"})]}),n.jsx(Da,{children:n.jsxs(m.Slider,{value:[c*100],onValueChange:x=>h(x[0]/100),min:10,max:100,step:1,children:[n.jsx(m.Slider.Track,{className:"bg-foreground/10 h-2",children:n.jsx(m.Slider.Fill,{className:"bg-primary"})}),n.jsx(m.Slider.Thumb,{})]})})]}),n.jsxs("div",{className:"flex flex-col gap-2.5 md:gap-1.5",children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx("span",{className:"text-foreground/60 text-sm md:text-xs",children:"Height"}),n.jsx("input",{type:"number",value:Math.round(d*100),onChange:x=>f(Math.max(10,Math.min(100,Number(x.target.value)))/100),min:10,max:100,className:"bg-transparent text-foreground w-14 rounded-md border-none px-2.5 py-2 text-right text-base md:w-14 md:rounded md:px-1.5 md:py-1 md:text-[13px]"})]}),n.jsx(Da,{children:n.jsxs(m.Slider,{value:[d*100],onValueChange:x=>f(x[0]/100),min:10,max:100,step:1,children:[n.jsx(m.Slider.Track,{className:"bg-foreground/10 h-2",children:n.jsx(m.Slider.Fill,{className:"bg-primary"})}),n.jsx(m.Slider.Thumb,{})]})})]})]})]})})})},eg=Object.freeze(Object.defineProperty({__proto__:null,CropPanel:qr,default:qr},Symbol.toStringTag,{value:"Module"})),kn="flex flex-col gap-5 px-5 pt-4 pb-4 md:gap-4 md:px-4 md:pt-3 md:pb-3",bc="flex flex-col gap-5 px-5 pt-4 pb-[calc(env(safe-area-inset-bottom,0px)+20px)] md:gap-4 md:px-4 md:pt-2 md:pb-[calc(env(safe-area-inset-bottom,0px)+16px)]",tg=({value:e,onChange:t})=>n.jsx("div",{className:"corner-radius-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Radius",value:e,onChange:t,min:0,max:50,unit:"%"})})}),ng=({value:e,onChange:t,onRotate90:r})=>n.jsx("div",{className:"rotation-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsxs("div",{className:"flex items-end gap-3",children:[n.jsx(sn,{label:"Rotation",value:e,onChange:t,min:-180,max:180,unit:"°",showInput:!0,inputWidth:"56px",variant:"stacked",className:"flex-1"}),n.jsx("div",{className:"pb-0.5",children:n.jsx(ct,{icon:Re.rotateCcwSquare,onClick:r,tooltip:"Rotate 90° CCW"})})]})})}),rg=({value:e,onChange:t,widthValue:r,onWidthChange:o})=>n.jsx("div",{className:"font-size-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsxs("div",{className:kn,children:[n.jsx(sn,{label:"Font Size",value:Math.round(e),onChange:t,min:8,max:256,step:1,unit:"px",showInput:!0,inputWidth:"64px"}),r!=null&&o&&n.jsx(sn,{label:"Width",value:Math.round(r),onChange:o,min:50,max:4e3,step:1,unit:"px",showInput:!0,inputWidth:"64px"})]})}),og=({value:e,onChange:t})=>n.jsx("div",{className:"opacity-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Opacity",value:Math.round(e*100),onChange:r=>t(r/100),min:0,max:100,unit:"%"})})}),sg=({value:e,onChange:t})=>n.jsx("div",{className:"shape-corner-radius-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Radius",value:e,onChange:t,min:0,max:50,unit:"%"})})}),ig=({value:e,onChange:t})=>n.jsx("div",{className:"shape-transparency-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Opacity",value:Math.round(e*100),onChange:r=>t(r/100),min:0,max:100,unit:"%"})})}),ag=({value:e,onChange:t})=>n.jsx("div",{className:"shape-sides-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Sides",value:e,onChange:t,min:3,max:20})})}),lg=({value:e,onChange:t})=>n.jsx("div",{className:"shape-points-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Points",value:e,onChange:t,min:3,max:20})})}),cg=({value:e,onChange:t})=>n.jsx("div",{className:"shape-inner-radius-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:kn,children:n.jsx(sn,{label:"Inner Radius",value:Math.round(e*100),onChange:r=>t(r/100),min:10,max:90,unit:"%"})})}),dg=({value:e,onChange:t,documentColors:r,imageColors:o})=>n.jsx("div",{className:"shape-color-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:bc,children:n.jsx(lr,{value:e,onChange:s=>t(s.target.value),documentColors:r,imageColors:o,showSquare:!0,embedded:!0})})}),ug=({value:e,onChange:t,documentColors:r,imageColors:o})=>n.jsx("div",{className:"text-color-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsx("div",{className:bc,children:n.jsx(lr,{value:e,onChange:t,documentColors:r,imageColors:o,embedded:!0})})}),hg=({mode:e,fill:t,stroke:r,scope:o,onModeChange:s,onFillChange:i,onStrokeChange:a,onScopeChange:c})=>n.jsx("div",{className:"knockout-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsxs("div",{className:kn,children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(m.Label,{className:"text-base md:text-sm font-medium",children:"Mode"}),n.jsxs("div",{className:"flex rounded-md border border-divider overflow-hidden",children:[n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm transition-colors ${e==="clip"?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>s("clip"),children:"Clip"}),n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm transition-colors ${e==="knockout"?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>s("knockout"),children:"Knockout"})]})]}),n.jsxs("div",{className:"flex items-center gap-5",children:[n.jsxs("label",{className:"flex items-center gap-2 text-base md:text-sm text-foreground",children:[n.jsx(m.Checkbox,{checked:t,onCheckedChange:d=>i(d===!0)}),"Fill"]}),n.jsxs("label",{className:"flex items-center gap-2 text-base md:text-sm text-foreground",children:[n.jsx(m.Checkbox,{checked:r,onCheckedChange:d=>a(d===!0)}),"Stroke"]})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(m.Label,{className:"text-base md:text-sm font-medium",children:"Scope"}),n.jsxs("div",{className:"flex rounded-md border border-divider overflow-hidden",children:[n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm transition-colors ${o==="group"?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>c("group"),children:"Group"}),n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm transition-colors ${o==="artboard"?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>c("artboard"),children:"Artboard"})]})]})]})}),fg=({textureUrl:e,opacity:t,onTextureChange:r,onOpacityChange:o})=>{rt.ensureBuiltinTexturesReady();const s=rt.DISTRESS_TEXTURE_PRESETS.map(a=>({id:a.textureUrl,name:a.name,thumbnailUrl:a.thumbnailUrl})),i=l.useCallback(a=>{a&&rt.preloadTexture(a),r(a)},[r]);return n.jsx("div",{className:"distress-texture-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsxs("div",{className:kn,children:[n.jsx(Ho,{presets:s,selectedId:e,onSelect:i,ariaLabel:"Distress texture presets"}),n.jsx(sn,{label:"Opacity",value:t,onChange:o,min:0,max:100,unit:"%"})]})})},pg=({imageUrl:e,maskType:t,opacity:r,inverted:o,onImageChange:s,onMaskTypeChange:i,onOpacityChange:a,onInvertedChange:c})=>{rt.ensureMaskPresetsReady();const d=rt.MASK_IMAGE_PRESETS.map(u=>({id:u.imageUrl,name:u.name,thumbnailUrl:u.thumbnailUrl}));return n.jsx("div",{className:"image-mask-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsxs("div",{className:kn,children:[n.jsx(Ho,{presets:d,selectedId:e,onSelect:s,ariaLabel:"Image mask presets"}),n.jsxs("div",{className:"flex items-center gap-2",children:[n.jsx(m.Label,{className:"text-base md:text-sm font-medium",children:"Type"}),n.jsx("div",{className:"flex rounded-md border border-divider overflow-hidden",children:["clip","alpha","luma"].map(u=>n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm capitalize transition-colors ${t===u?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>i(u),children:u},u))})]}),n.jsx(sn,{label:"Opacity",value:r,onChange:a,min:0,max:100,unit:"%"}),n.jsxs("label",{className:"flex items-center gap-2 text-base md:text-sm text-foreground",children:[n.jsx(m.Checkbox,{checked:o,onCheckedChange:u=>c(u===!0)}),"Invert Mask"]})]})})},mg=({stroke:e,onChange:t,documentColors:r,imageColors:o})=>{const[s,i]=l.useState(!1),a=(e==null?void 0:e.enabled)??!1,c=(e==null?void 0:e.color)??"#000000",d=(e==null?void 0:e.width)??5,u=(e==null?void 0:e.opacity)??1,h=(e==null?void 0:e.lineCap)??"butt",f=(e==null?void 0:e.lineJoin)??"miter",p=l.useCallback(b=>{t(b?{enabled:!0,color:c,width:d,lineCap:h,lineJoin:f,opacity:u}:void 0)},[t,c,d,h,f,u]),g=l.useCallback(b=>{e&&t({...e,...b})},[e,t]);return n.jsx("div",{className:"stroke-panel flex flex-col","data-preserve-selection":!0,style:{touchAction:"pan-y"},children:n.jsxs("div",{className:kn,children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(m.Label,{className:"text-foreground/70 text-base md:text-[13px]",children:"Stroke"}),n.jsx(m.Switch,{checked:a,onCheckedChange:p})]}),a&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center justify-between",children:[n.jsx(m.Label,{className:"text-foreground/70 text-base md:text-[13px]",children:"Color"}),n.jsx(lr,{value:c,onChange:b=>g({color:b.target.value}),documentColors:r,imageColors:o,showSquare:!0})]}),n.jsx(sn,{label:"Width",value:d,onChange:b=>g({width:b}),min:1,max:50,unit:"px"}),n.jsx(sn,{label:"Opacity",value:Math.round(u*100),onChange:b=>g({opacity:b/100}),min:0,max:100,unit:"%"}),n.jsxs("button",{className:"flex items-center gap-1 text-base md:text-sm text-muted-foreground hover:text-foreground transition-colors py-1.5 md:py-0",onClick:()=>i(b=>!b),children:[s?"Hide":"Show"," Advanced"]}),s&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(m.Label,{className:"text-foreground/70 text-base md:text-[13px]",children:"Line Cap"}),n.jsx("div",{className:"flex rounded-md border border-divider overflow-hidden",children:["butt","round","square"].map(b=>n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm capitalize transition-colors ${h===b?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>g({lineCap:b}),children:b},b))})]}),n.jsxs("div",{className:"flex items-center gap-3",children:[n.jsx(m.Label,{className:"text-foreground/70 text-base md:text-[13px]",children:"Line Join"}),n.jsx("div",{className:"flex rounded-md border border-divider overflow-hidden",children:["miter","round","bevel"].map(b=>n.jsx("button",{className:`px-4 py-2.5 text-base md:px-3 md:py-1.5 md:text-sm capitalize transition-colors ${f===b?"bg-primary text-primary-foreground":"text-foreground hover:bg-muted"}`,onClick:()=>g({lineJoin:b}),children:b},b))})]})]})]})]})})},gg=({element:e,onElementUpdate:t})=>n.jsx(qr,{element:e,onElementUpdate:t}),xg=({panelType:e,defaultIcon:t,textColorValue:r,shapeFillColor:o})=>e==="textColor"?n.jsxs("div",{className:"relative flex size-6 items-center justify-center md:size-5",children:[n.jsx("span",{className:"text-primary text-xl leading-none font-bold md:text-lg",children:"A"}),n.jsx("div",{className:"absolute bottom-0 left-1/2 h-[3px] w-4 -translate-x-1/2 rounded-sm",style:{backgroundColor:r}})]}):e==="shapeColor"?n.jsxs("div",{className:"relative flex size-6 items-center justify-center md:size-5",children:[n.jsx(de,{icon:"mdi:format-color-fill",className:"text-primary size-5 md:size-4"}),n.jsx("div",{className:"absolute -bottom-0.5 left-1/2 h-[3px] w-4 -translate-x-1/2 rounded-sm",style:{backgroundColor:o||"#3b82f6"}})]}):typeof t=="string"?n.jsx(de,{icon:t,className:"text-primary size-6 md:size-5"}):n.jsx(n.Fragment,{children:t}),vn=({isOpen:e,children:t})=>n.jsx("div",{className:"secondary-toolbar-panel-wrapper",style:{display:"flex",flexDirection:"column",flex:e?1:0,minHeight:e?0:void 0,transition:"flex 300ms cubic-bezier(0.32, 0.72, 0, 1)"},children:n.jsx("div",{className:e?"secondary-panel-scroll-container":"",style:{flex:1,display:"flex",flexDirection:"column",overflowY:e?"auto":"hidden",overscrollBehaviorY:"contain",WebkitOverflowScrolling:"touch",transform:e?"translateY(0)":"translateY(100%)",opacity:e?1:0,transition:"transform 300ms cubic-bezier(0.32, 0.72, 0, 1), opacity 200ms ease-out"},children:t})}),La=({isOpen:e,children:t})=>n.jsx("div",{className:"secondary-toolbar-panel-wrapper",style:{display:"flex",flexDirection:"column",flex:e?1:0,minHeight:e?0:void 0,transition:"flex 300ms cubic-bezier(0.32, 0.72, 0, 1)"},children:n.jsx("div",{className:e?"secondary-panel-scroll-container":"",style:{flex:1,minHeight:0,overflowY:e?void 0:"hidden",overscrollBehaviorY:"contain",WebkitOverflowScrolling:"touch",transform:e?"translateY(0)":"translateY(100%)",opacity:e?1:0,transition:"transform 300ms cubic-bezier(0.32, 0.72, 0, 1), opacity 200ms ease-out"},children:t})}),bg=({toolbarContent:e,innerContentRef:t,shouldRender:r,isExiting:o,transitionHeight:s,emptyStateContent:i,isCornerRadiusPanelOpen:a,isCropPanelOpen:c,isRotationPanelOpen:d,isOpacityPanelOpen:u,isFontSizePanelOpen:h,isShapeCornerRadiusPanelOpen:f,isShapeTransparencyPanelOpen:p,isShapeSidesPanelOpen:g,isShapePointsPanelOpen:b,isShapeInnerRadiusPanelOpen:x,isShapeColorPanelOpen:y,isTextColorPanelOpen:v,isStrokePanelOpen:w,isKnockoutPanelOpen:C,isDistressTexturePanelOpen:j,isImageMaskPanelOpen:M,cornerRadiusPanel:S,cropPanelContent:R,rotationPanel:I,opacityPanel:D,fontSizePanel:E,shapeCornerRadiusPanel:O,shapeTransparencyPanel:z,shapeSidesPanel:B,shapePointsPanel:k,shapeInnerRadiusPanel:Y,shapeColorPanel:_,textColorPanel:G,strokePanel:se,knockoutPanel:A,distressTexturePanel:Z,imageMaskPanel:J})=>n.jsxs("div",{className:"toolbar-embedded-wrapper",style:{display:"flex",flexDirection:"column",flex:1,minHeight:0,overscrollBehaviorY:"contain"},children:[i,n.jsx("div",{className:"toolbar-height-wrapper",style:s!==null?{height:s,overflow:"hidden",transition:"height 200ms cubic-bezier(0.22, 1, 0.36, 1)"}:{display:"grid",gridTemplateRows:r&&!o?"1fr":"0fr",transition:"grid-template-rows 200ms cubic-bezier(0.22, 1, 0.36, 1)"},children:n.jsx("div",{ref:t,children:e})}),n.jsx(vn,{isOpen:a,children:S}),n.jsx(vn,{isOpen:c,children:R}),n.jsx(vn,{isOpen:d,children:I}),n.jsx(vn,{isOpen:u,children:D}),n.jsx(vn,{isOpen:h,children:E}),n.jsx(vn,{isOpen:f,children:O}),n.jsx(vn,{isOpen:p,children:z}),n.jsx(vn,{isOpen:g,children:B}),n.jsx(vn,{isOpen:b,children:k}),n.jsx(vn,{isOpen:x,children:Y}),n.jsx(La,{isOpen:y,children:_}),n.jsx(La,{isOpen:v,children:G}),n.jsx(vn,{isOpen:w,children:se}),n.jsx(vn,{isOpen:C,children:A}),n.jsx(vn,{isOpen:j,children:Z}),n.jsx(vn,{isOpen:M,children:J})]}),yg=({toolbarPosition:e,toolbarHeight:t,panelWidth:r,value:o,onChange:s})=>n.jsx("div",{className:"corner-radius-panel",style:{position:"fixed",top:`${e.top+t+8}px`,left:`${e.left}px`,transform:"translateX(-50%)",padding:"12px 24px",marginTop:"-12px",borderRadius:0,border:"1px solid var(--divider)",boxShadow:"0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1)",zIndex:"var(--z-tooltip)",width:`${r}px`,boxSizing:"border-box"},children:n.jsx(sn,{label:"Radius",value:o,onChange:s,min:0,max:50,unit:"%"})}),vg=({toolbarPosition:e,toolbarHeight:t,element:r,onElementUpdate:o})=>n.jsx("div",{className:"crop-panel",style:{position:"fixed",top:`${e.top+t+8}px`,left:`${e.left}px`,transform:"translateX(-50%)",background:"var(--background)",border:"1px solid var(--divider)",borderRadius:"12px",boxShadow:"0 4px 12px 0 rgb(0 0 0 / 0.15)",zIndex:"var(--z-tooltip)",minWidth:"300px"},children:n.jsx(qr,{element:r,onElementUpdate:o})}),ir=e=>typeof e=="string"&&e.length>0&&e!=="transparent";function yc(e,t){var o;const r=e.stroke;if(r!=null&&r.enabled&&ir(r.color)&&t.add(r.color),e instanceof T.TextElement){ir(e.color)&&t.add(e.color);const s=e.richText;if(s!=null&&s.spans)for(const i of s.spans)ir((o=i.style)==null?void 0:o.color)&&t.add(i.style.color);return}if(e instanceof T.ShapeElement){const s=e.transformData.fillColor;ir(s)&&t.add(s);return}if(e instanceof T.PathElement){const s=e.transformData;s.fillEnabled&&ir(s.fillColor)&&t.add(s.fillColor),s.strokeEnabled&&ir(s.strokeColor)&&t.add(s.strokeColor);return}if(e instanceof T.GroupElement){for(const s of e.children)yc(s,t);return}}function wg(e,t){const r=new Set;for(const o of e)yc(o,r);if(t)for(const o of t){const s=o.backgroundColor;ir(s)&&r.add(s)}return r}const go=new Map,Ss=new Map;function Xs(e){if(e.length===0)return{rRange:0,gRange:0,bRange:0};let t=255,r=0,o=255,s=0,i=255,a=0;for(const c of e)c.r<t&&(t=c.r),c.r>r&&(r=c.r),c.g<o&&(o=c.g),c.g>s&&(s=c.g),c.b<i&&(i=c.b),c.b>a&&(a=c.b);return{rRange:r-t,gRange:s-o,bRange:a-i}}function Cg(e){const t=Math.max(e.rRange,e.gRange,e.bRange);return e.rRange===t?"r":e.gRange===t?"g":"b"}function Sg(e){return Math.max(e.rRange,e.gRange,e.bRange)}function kg(e){const t=Cg(e),r=e.pixels.slice().sort((a,c)=>a[t]-c[t]),o=r.length>>1,s=r.slice(0,o),i=r.slice(o);return[{pixels:s,...Xs(s)},{pixels:i,...Xs(i)}]}function jg(e){let t=0,r=0,o=0;for(const i of e)t+=i.r,r+=i.g,o+=i.b;const s=e.length;return{r:Math.round(t/s),g:Math.round(r/s),b:Math.round(o/s)}}function Eg(e,t){if(e.length===0)return[];const r=[{pixels:e,...Xs(e)}];for(;r.length<t;){let o=-1,s=0;for(let a=0;a<r.length;a++){const c=Sg(r[a]);c>s&&r[a].pixels.length>=2&&(s=c,o=a)}if(o===-1)break;const i=r[o];r.splice(o,1),r.push(...kg(i))}return r}function Tg(e,t){const r=(e.r+t.r)/2,o=e.r-t.r,s=e.g-t.g,i=e.b-t.b;return Math.sqrt((2+r/256)*o*o+4*s*s+(2+(255-r)/256)*i*i)}function Rg(e,t,r){if(e.length===0||t<=0)return[];const o=[e[0]],s=new Set([0]);for(;o.length<t;){let i=-1,a=-1;for(let c=1;c<e.length;c++){if(s.has(c))continue;let d=1/0;for(const u of o){const h=Tg(e[c],u);h<d&&(d=h)}d>a&&(a=d,i=c)}if(i===-1||a<=r)break;o.push(e[i]),s.add(i)}return o}const ks=e=>e.toString(16).padStart(2,"0");function Ng(e){return`#${ks(e.r)}${ks(e.g)}${ks(e.b)}`}async function Mg(e,t=5){if(!e)return[];const r=go.get(e);if(r)return r;const o=Ss.get(e);if(o)return o;const s=(async()=>{try{const i=await Ig(e),a=48,d=(typeof OffscreenCanvas<"u"?new OffscreenCanvas(a,a):(()=>{const x=document.createElement("canvas");return x.width=a,x.height=a,x})()).getContext("2d");if(!d)return[];d.drawImage(i,0,0,a,a);const{data:u}=d.getImageData(0,0,a,a),h=[];for(let x=0;x<u.length;x+=4){if(u[x+3]<128)continue;const v=u[x],w=u[x+1],C=u[x+2];v>240&&w>240&&C>240||h.push({r:v,g:w,b:C})}if(h.length===0)return go.set(e,[]),[];const f=Math.max(t*4,16),p=Eg(h,f);p.sort((x,y)=>y.pixels.length-x.pixels.length);const g=p.map(x=>jg(x.pixels)),b=Rg(g,t,50).map(Ng);return go.set(e,b),b}catch{return go.set(e,[]),[]}finally{Ss.delete(e)}})();return Ss.set(e,s),s}function Ig(e){return new Promise((t,r)=>{const o=new Image;o.crossOrigin="anonymous",o.onload=()=>t(o),o.onerror=()=>r(new Error(`Failed to load image: ${e}`)),o.src=e})}async function Ag(e,t=5){const r=[],o=new Set,s=d=>{if(d instanceof T.ImageElement){const u=d.imageUrl;u&&!o.has(u)&&(o.add(u),r.push(u))}else if(d instanceof T.GroupElement)for(const u of d.children)s(u)};for(const d of e)s(d);if(r.length===0)return[];const i=await Promise.all(r.map(d=>Mg(d,t))),a=[],c=new Set;for(const d of i)for(const u of d)c.has(u)||(c.add(u),a.push(u));return a}const Dg=T.createLogger("ContextualToolbars"),Vs=({mode:e="floating",onOpenGlyphBrowser:t,onChangeImage:r,onOpenShapeTypeDrawer:o,documentColors:s=new Set,viewportWidth:i=window.innerWidth,breakpoints:a={},hasGlyphs:c=!1,getMoreMenuItems:d,onArtboardUpdate:u,artboardScreenBounds:h,maxWidth:f,transparent:p=!1,onPanelExpandChange:g,defaultExpandedPanel:b,onExpandedPanelTypeChange:x,onOpenCropDrawer:y,onOpenCornerRadiusDrawer:v,closeButtonStyle:w="icon",emptyStateMessage:C="Tap an element to select and edit",emptyStateRender:j,editArtboardMode:M=!1,onEditArtboardModeChange:S,onLayerThumbnailClick:R})=>{var xi,bi,yi,vi,wi,Ci,Si,ki,ji,Ei,Ti,Ri,Ni,Mi,Ii,Ai;const{panOffset:I}=Yt.useViewportContext(),{multiSelection:D,setSelectedId:E}=Yt.useSelectionContext(),{expandedPanelType:O,setExpandedPanelType:z,setIsToolbarMenuOpen:B,isRotating:k}=Yt.useToolStateContext(),{elements:Y,selectedElement:_,activeChildElement:G,handleElementUpdate:se,artboardManager:A,artboards:Z,canvasEditorRef:J,canvasRef:q,executeRemoveElement:ae,executeAddElement:Le,executeReorderElement:pe,refreshArtboards:U}=Yt.useEditor(),W=gc({canvasEditorRef:J}),[Ie,ke]=l.useState("root"),[Ke,re]=l.useState(null),[te,he]=l.useState(null),[ye,we]=l.useState(!1),[Pe,me]=l.useState(!1),[N]=l.useState(!1),[ce,le]=l.useState(!1),[Me,ge]=l.useState(!1),[L,ve]=l.useState(()=>b&&{cornerRadius:{type:"cornerRadius",icon:"lucide:square-round-corner",label:"Corner Radius"},crop:{type:"crop",icon:"lucide:crop",label:"Crop"},rotation:{type:"rotation",icon:Re.rotateLeft,label:"Rotate"},opacity:{type:"opacity",icon:"lucide:blend",label:"Transparency"},effects:{type:"effects",icon:"lucide:sparkles",label:"Effects"}}[b]||null),[tt,Ve]=l.useState(!1),[oe,ie]=l.useState(!1),[pt,st]=l.useState(!1),[ht,bt]=l.useState(!1),[yt,Tt]=l.useState(null),[Rt,jt]=l.useState(null),[kt,Kt]=l.useState({width:0,height:0}),$t=l.useRef(null),Ot=l.useRef(null),De=l.useRef(0),je=l.useRef(!1),Ee=l.useRef(!1),$e=l.useRef(null),Qe=l.useRef(void 0),Fe=l.useRef(null),Ue=l.useRef(O),Xe=l.useRef(void 0),dt=l.useRef(void 0),Ye=l.useRef(!1),vt=l.useRef(!1),gt=l.useRef(!!b),Nt=l.useRef(!1),Ft=l.useRef(L),$=l.useRef(null),ee=l.useRef(()=>{}),Je=l.useRef(void 0),it=l.useRef(void 0);vt.current=k;const F=G||_,ft=F==null?void 0:F.id,at=_==null?void 0:_.id,xt=F==null?void 0:F.transformType,{fontColor:Q,getEffectiveStyle:ze,handleFontColorChange:nt}=W,Ce=!!(_&&!k),X=l.useCallback(P=>{if(_)if(G){const qe=_.clone(),Ge=qe.children.findIndex(Xt=>Xt.id===G.id);Ge!==-1&&(qe.children[Ge]=P,se(qe))}else se(P)},[_,G,se]),Mt=l.useCallback(P=>{if(!F||F.transformType!=="image")return;const H=F.clone();H.transformData.borderRadius=P,X(H)},[F,X]),ue=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.borderRadius=P,X(H)},[F,X]),et=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.fillOpacity=P,X(H)},[F,X]),K=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.sides=P,X(H)},[F,X]),be=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.points=P,X(H)},[F,X]),Te=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.innerRadius=P,X(H)},[F,X]),Ne=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const H=F.clone();H.transformData.fillColor=P,X(H)},[F,X]),He=l.useCallback(()=>{v?v():ve(P=>(P==null?void 0:P.type)==="cornerRadius"?null:{type:"cornerRadius",icon:"lucide:square-round-corner",label:"Corner Radius"})},[v]),Se=l.useCallback(()=>{y?y():ve(P=>(P==null?void 0:P.type)==="crop"?null:{type:"crop",icon:"lucide:crop",label:"Crop"})},[y]),_e=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="rotation"?null:{type:"rotation",icon:Re.rotateLeft,label:"Rotate"})},[]),Ae=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="opacity"?null:{type:"opacity",icon:"lucide:blend",label:"Transparency"})},[]),V=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="fontSize"?null:{type:"fontSize",icon:"lucide:type",label:"Font Size"})},[]),xe=l.useCallback(P=>{if(!F)return;const H=F.transformData;if(!H||H.width===void 0)return;const qe=F.clone();qe.transformData.width=P,X(qe)},[F,X]),ne=((xi=F==null?void 0:F.transformData)==null?void 0:xi.width)??null,fe=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapeCornerRadius"?null:{type:"shapeCornerRadius",icon:"lucide:square-round-corner",label:"Corner Radius"})},[]),Be=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapeTransparency"?null:{type:"shapeTransparency",icon:"lucide:blend",label:"Transparency"})},[]),Oe=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapeSides"?null:{type:"shapeSides",icon:"lucide:hexagon",label:"Sides"})},[]),ot=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapePoints"?null:{type:"shapePoints",icon:"lucide:star",label:"Points"})},[]),mt=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapeInnerRadius"?null:{type:"shapeInnerRadius",icon:"lucide:circle-dashed",label:"Inner Radius"})},[]),_t=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="shapeColor"?null:{type:"shapeColor",icon:"lucide:paint-bucket",label:"Fill Color"})},[]),Wt=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="textColor"?null:{type:"textColor",icon:Re.palette,label:"Font Color"})},[]),Bt=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="compositing"?null:{type:"compositing",icon:"lucide:scissors",label:"Clip / Knockout"})},[]),At=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="distressTexture"?null:{type:"distressTexture",icon:"lucide:stamp",label:"Distress Texture"})},[]),Dt=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="imageMask"?null:{type:"imageMask",icon:"lucide:venetian-mask",label:"Image Mask"})},[]),rn=l.useCallback(()=>{ve(P=>(P==null?void 0:P.type)==="stroke"?null:{type:"stroke",icon:"lucide:pen-line",label:"Stroke"})},[]),Lt=l.useCallback(()=>{if((L==null?void 0:L.type)==="crop"&&(F==null?void 0:F.transformType)==="image"){const P=F;if(P.isCropping){const H=P.clone();H.exitCropMode(),X(H)}}ve(null)},[L,F,X]),Ut=l.useCallback(()=>{if(!_)return;const P=Y.findIndex(H=>H.id===_.id);if(P<Y.length-1){const H=Y[P+1];pe(_.id,H.id,"after")}},[_,Y,pe]),an=l.useCallback(()=>{if(!_)return;const P=Y.findIndex(H=>H.id===_.id);if(P>0){const H=Y[P-1];pe(_.id,H.id,"before")}},[_,Y,pe]),un=l.useCallback(()=>{const P=G||_;P&&(ae(P),E(null))},[G,_,ae,E]),Zt=l.useCallback(()=>{if(!F)return;const P=F.clone();P.locked=!F.locked,X(P)},[F,X]),Qt=l.useCallback(()=>{if(!_||_.transformType!=="group")return;const P=_;if(!P.children||P.children.length===0)return;const H=A.getArtboardIdForElement(P.id);if(!H)return;const qe=P.children.map(Ge=>{const Xt=Ge.clone();return Xt.x=Ge.x+P.x,Xt.y=Ge.y+P.y,Xt});ae(P),qe.forEach(Ge=>Le(Ge,H)),E(qe.length>0?qe[0].id:null)},[_,A,ae,Le,E]),hn=l.useCallback(P=>{if(!F)return;const H=F.clone();H.rotation=P,X(H)},[F,X]),en=l.useCallback(()=>{if(!F)return;const P=F.clone();let H=Math.floor(P.rotation/90)*90+90;H=(H%360+360)%360,H>180&&(H-=360),P.rotation=H,X(P)},[F,X]),xn=l.useCallback(P=>{if(!F)return;const H=F.clone();H.opacity=P,X(H)},[F,X]),Yn=l.useCallback(P=>{if(!F)return;const H=F.clone();H.blendMode=P,H.knockoutParts||(H.knockoutParts={fill:!0,scope:"group"}),X(H)},[F,X]),er=l.useCallback(P=>{if(!F)return;const H=F.clone(),qe=H.blendMode==="clip"?"clip":"knockout",Ge={...H.knockoutParts,fill:P};H.knockoutParts=Ge,H.blendMode=Ge.fill||Ge.stroke?qe:"normal",X(H)},[F,X]),wn=l.useCallback(P=>{if(!F)return;const H=F.clone(),qe=H.blendMode==="clip"?"clip":"knockout",Ge={...H.knockoutParts,stroke:P};H.knockoutParts=Ge,H.blendMode=Ge.fill||Ge.stroke?qe:"normal",X(H)},[F,X]),cr=l.useCallback(P=>{if(!F)return;const H=F.clone();H.knockoutParts={...H.knockoutParts,scope:P},X(H)},[F,X]),dr=l.useCallback(P=>{var qe,Ge;if(!F)return;const H=F.clone();P?H.distressEffect={enabled:!0,style:"custom",intensity:((qe=H.distressEffect)==null?void 0:qe.intensity)??50,textureUrl:P,textureOpacity:((Ge=H.distressEffect)==null?void 0:Ge.textureOpacity)??.5}:H.distressEffect=void 0,X(H)},[F,X]),Gn=l.useCallback(P=>{if(!F)return;const H=F.clone();H.distressEffect&&(H.distressEffect={...H.distressEffect,textureOpacity:P/100}),X(H)},[F,X]),tr=l.useCallback(P=>{if(!F)return;const H=F.clone();if(!P)H.masks=(H.masks||[]).filter(qe=>qe.id!=="quick-image-mask");else{const Ge=()=>({transformType:"image",imageUrl:P,x:0,y:0,rotation:0,transformData:{type:"image",width:512,height:512,cropX:0,cropY:0,cropWidth:1,cropHeight:1,flipHorizontal:!1,flipVertical:!1,borderRadius:0}});if("transformData"in H&&H.transformData){const tn=H.transformData;tn.cropX=0,tn.cropY=0,tn.cropWidth=1,tn.cropHeight=1}const Xt=(H.masks||[]).find(tn=>tn.id==="quick-image-mask");if(Xt)Xt.maskElement=Ge();else{const tn=H.masks||[];tn.push({id:"quick-image-mask",type:"clip",maskElement:Ge(),opacity:1,inverted:!1}),H.masks=tn}}X(H)},[F,X]),ln=l.useCallback(P=>{if(!F)return;const H=F.clone(),qe=(H.masks||[]).find(Ge=>Ge.id==="quick-image-mask");qe&&(qe.type=P,X(H))},[F,X]),Hn=l.useCallback(P=>{if(!F)return;const H=F.clone(),qe=(H.masks||[]).find(Ge=>Ge.id==="quick-image-mask");qe&&(qe.opacity=P/100,X(H))},[F,X]),$n=l.useCallback(P=>{if(!F)return;const H=F.clone(),qe=(H.masks||[]).find(Ge=>Ge.id==="quick-image-mask");qe&&(qe.inverted=P,X(H))},[F,X]),so=l.useCallback(P=>{if(!F)return;const H=F.clone();H.stroke=P,X(H)},[F,X]),Yo=l.useCallback(P=>{if(!F||F.transformType!=="shape")return;const qe=F.clone();qe.transformData.shapeType=P,X(qe),ge(!1)},[F,X]),Wo=l.useCallback(()=>{o?o():ge(!0)},[o]);l.useEffect(()=>{g==null||g(L!==null),x==null||x((L==null?void 0:L.type)??null)},[L,g,x]),l.useEffect(()=>{const P=(L==null?void 0:L.type)??null;P!==Fe.current&&(Fe.current=P,z(P))},[L,z]),l.useEffect(()=>{const P=Ue.current,H=O;if(P!==H){if(Ue.current=H,P!==null&&H===null&&L!==null){Fe.current=null,ve(null);return}if(H!==null&&(L==null?void 0:L.type)!==H){const Ge={crop:{type:"crop",icon:"lucide:crop",label:"Crop"},cornerRadius:{type:"cornerRadius",icon:"lucide:square-round-corner",label:"Corner Radius"},rotation:{type:"rotation",icon:Re.rotateLeft,label:"Rotate"},opacity:{type:"opacity",icon:"lucide:blend",label:"Transparency"},fontSize:{type:"fontSize",icon:"lucide:type",label:"Font Size"},effects:{type:"effects",icon:"lucide:sparkles",label:"Effects"},shapeCornerRadius:{type:"shapeCornerRadius",icon:"lucide:square-round-corner",label:"Corner Radius"},shapeTransparency:{type:"shapeTransparency",icon:Re.eye,label:"Transparency"},shapeSides:{type:"shapeSides",icon:"lucide:triangle",label:"Sides"},shapePoints:{type:"shapePoints",icon:"lucide:star",label:"Points"},shapeInnerRadius:{type:"shapeInnerRadius",icon:"lucide:circle-dashed",label:"Inner Radius"},shapeColor:{type:"shapeColor",icon:Re.palette,label:"Color"},textColor:{type:"textColor",icon:Re.palette,label:"Color"},stroke:{type:"stroke",icon:"lucide:pen-line",label:"Stroke"},compositing:{type:"compositing",icon:"lucide:scissors",label:"Clip / Knockout"},distressTexture:{type:"distressTexture",icon:"lucide:stamp",label:"Distress Texture"},imageMask:{type:"imageMask",icon:"lucide:venetian-mask",label:"Image Mask"}}[H];Ge&&(Fe.current=H,ve(Ge))}}},[O,L]),l.useEffect(()=>{B(L!==null||Ke!==null||Pe||N||ce||Ie!=="root")},[L,Ke,Pe,N,ce,Ie,B]),l.useEffect(()=>{b||(Je.current!==void 0&&Je.current!==at&&ve(null),Je.current=at)},[at,b]),l.useEffect(()=>{M&&_&&(S==null||S(!1))},[M,_,S]),l.useEffect(()=>{const P=(F==null?void 0:F.transformType)==="image"?F.isCropping:!1;(L==null?void 0:L.type)==="crop"&&it.current===!0&&P===!1&&ve(null),it.current=P},[F,L==null?void 0:L.type]),l.useEffect(()=>{Ft.current=L,$.current=F??null,ee.current=X}),l.useEffect(()=>{const P=setTimeout(()=>{Nt.current=!0},0);return()=>{clearTimeout(P)}},[]),l.useEffect(()=>()=>{var P;if(Nt.current&&gt.current&&((P=Ft.current)==null?void 0:P.type)==="crop"){const H=$.current;if((H==null?void 0:H.transformType)==="image"){const qe=H;if(qe.isCropping){const Ge=qe.clone();Ge.exitCropMode(),ee.current(Ge)}}}},[]),l.useEffect(()=>{let P=null,H=!1;const qe=3,Ge=mn=>{var zn;const Mn=mn.target;(zn=$t.current)!=null&&zn.contains(Mn)||Mn.closest('[data-slot="popover-content"]')||Mn.closest('[data-slot="dialog"]')||Mn.closest('[role="dialog"]')||Mn.closest(".popover-content")||Mn.closest("[data-slot]")||(Ee.current=!0,P={x:mn.clientX,y:mn.clientY},H=!1)},Xt=mn=>{if(P&&!H&&!vt.current){const Mn=mn.clientX-P.x,zn=mn.clientY-P.y;Math.sqrt(Mn*Mn+zn*zn)>qe&&(H=!0,we(!0))}},tn=()=>{Ee.current=!1,P=null,H=!1,we(!1)};return window.addEventListener("mousedown",Ge),window.addEventListener("mousemove",Xt),window.addEventListener("mouseup",tn),()=>{window.removeEventListener("mousedown",Ge),window.removeEventListener("mousemove",Xt),window.removeEventListener("mouseup",tn)}},[]),l.useEffect(()=>{if(!$t.current)return;let P=null;const H=new ResizeObserver(qe=>{P!==null&&clearTimeout(P),P=window.setTimeout(()=>{for(const Ge of qe){const Xt=Ge.contentRect.width,tn=Ge.contentRect.height;Kt(mn=>mn.width===Xt&&mn.height===tn?mn:{width:Xt,height:tn})}},50)});return H.observe($t.current),()=>{H.disconnect(),P!==null&&clearTimeout(P)}},[_]),l.useEffect(()=>{var qe;if(e==="embedded"||oe)return;const P=(qe=G||_)==null?void 0:qe.rotation;if(Qe.current=P,!_){he(null);return}const H=()=>{var Ge,Xt,tn,mn,Mn;try{const zn=((Ge=$t.current)==null?void 0:Ge.offsetWidth)||kt.width||0,Jo=((Xt=$t.current)==null?void 0:Xt.offsetHeight)||kt.height||48,Di=q==null?void 0:q.current,nr=G||_,fr=nr.transformData,In=((tn=nr.getBoundingBox)==null?void 0:tn.call(nr))||{x:nr.x,y:nr.y,width:(fr==null?void 0:fr.width)||100,height:(fr==null?void 0:fr.height)||50},pr=A.getActiveArtboard(),Li=(pr==null?void 0:pr.x)||0,Pi=(pr==null?void 0:pr.y)||0,An=((Mn=(mn=J==null?void 0:J.current)==null?void 0:mn.getZoom)==null?void 0:Mn.call(mn))||1;let uo,Tr,ho,fo;if(Di){const Rr=Di.getBoundingClientRect();uo=Rr.left+(In.x-Li)*An,Tr=Rr.top+(In.y-Pi)*An,ho=In.width*An,fo=In.height*An}else if(h)uo=h.left+(In.x-Li)*An,Tr=h.top+(In.y-Pi)*An,ho=In.width*An,fo=In.height*An;else{const Rr=window.innerWidth/2,es=window.innerHeight/2;uo=Rr-In.width*An/2,Tr=es-In.height*An/2,ho=In.width*An,fo=In.height*An}const Fi=12,Wc=Tr,Xc=uo+ho/2;let rr=Wc-Jo-Fi,Qo=Xc;if(zn>0){const es=zn/2+20,Gc=window.innerWidth-zn/2-20;Qo=Math.max(es,Math.min(Gc,Qo))}rr<10&&(rr=Tr+fo+Fi);const Vc=window.innerHeight-Jo-10;rr=Math.min(rr,Vc),rr=Math.max(10,rr),he({top:rr,left:Qo}),Tt(nr.id)}catch(zn){Dg.error("Error calculating toolbar position:",zn),he(null)}};return H(),window.addEventListener("resize",H),()=>{window.removeEventListener("resize",H)}},[e,_,G,q,A,J,h,kt,oe,I]);const Ze=ze().color||Q,We=l.useCallback(P=>nt(P),[nt]),Ct=l.useMemo(()=>wg(Y,Z),[Y,Z]),Et=l.useMemo(()=>{const P=new Set(Ct);for(const H of s)P.add(H);return P},[Ct,s]),It=Array.from(Et).sort().join(","),Ht=l.useMemo(()=>Array.from(Et),[It]),qt=l.useMemo(()=>{const P=[],H=new Set,qe=Ge=>{if(Ge instanceof T.ImageElement)Ge.imageUrl&&!H.has(Ge.imageUrl)&&(H.add(Ge.imageUrl),P.push(Ge.imageUrl));else if(Ge instanceof T.GroupElement)for(const Xt of Ge.children)qe(Xt)};for(const Ge of Y)qe(Ge);return P.sort(),P.join("|")},[Y]),[Pt,St]=l.useState([]);l.useEffect(()=>{if(!qt){St([]);return}let P=!1;return Ag(Y).then(H=>{P||St(H)}),()=>{P=!0}},[qt]);const lt=l.useCallback(P=>{if($t&&($t.current=P,P)){const{width:H,height:qe}=P.getBoundingClientRect();H>0&&qe>0&&Kt({width:H,height:qe})}},[]);l.useEffect(()=>{const P=Ye.current,H=k;!P&&H&&te&&($e.current={...te}),P&&!H&&($e.current=null),Ye.current=k},[k,te]),l.useEffect(()=>{const P=je.current,H=Xe.current;if(je.current=Ce,Xe.current=at,!P&&Ce){if(st(!0),e==="embedded"){bt(!1),Ve(!0),ie(!1);const qe=setTimeout(()=>{Ve(!1)},200);return()=>clearTimeout(qe)}bt(!0),Ve(!1),ie(!1);return}if(P&&Ce&&H!==at&&at!==void 0){if(e==="embedded"){Ve(!1);return}bt(!0),Ve(!1),ie(!1);return}if(P&&!Ce){if(k){st(!1),Ve(!1),ie(!1),bt(!1);return}if(e==="embedded"){if(ie(!0),Ve(!1),Ot.current){const Xt=Ot.current.offsetHeight;jt(Xt),requestAnimationFrame(()=>{jt(0)})}const Ge=setTimeout(()=>{st(!1),ie(!1),jt(null)},200);return()=>clearTimeout(Ge)}ie(!0),Ve(!1),bt(!1);const qe=setTimeout(()=>{st(!1),ie(!1),he(null),Tt(null)},150);return()=>clearTimeout(qe)}},[Ce,k,at,e,xt]),l.useEffect(()=>{if(ht&&te&&yt===ft){bt(!1),Ve(!0);const P=setTimeout(()=>{Ve(!1)},200);return()=>clearTimeout(P)}},[ht,te,yt,ft]),l.useLayoutEffect(()=>{if(e!=="embedded")return;const P=dt.current;if(P!==void 0&&xt!==void 0&&P!==xt&&De.current>0&&Rt===null){const qe=De.current;jt(qe),requestAnimationFrame(()=>{requestAnimationFrame(()=>{if(Ot.current){const Ge=Ot.current.scrollHeight;jt(Ge),setTimeout(()=>{jt(null)},200)}})})}Ot.current&&Rt===null&&!tt&&!oe&&(De.current=Ot.current.offsetHeight),dt.current=xt},[e,xt,Rt,tt,oe]);const zt=l.useMemo(()=>{const P=f?typeof f=="number"?`${f}px`:f:void 0;if(e==="embedded")return{borderRadius:f?"16px":"9999px",visibility:"visible",position:"static",maxWidth:P,display:"flex",justifyContent:"flex-start"};const H=$e.current||te;return H&&!ht?{top:`${H.top}px`,left:`${H.left}px`,position:"fixed",transform:"translateX(-50%)",borderRadius:f?"16px":"9999px",visibility:"visible",maxWidth:P,zIndex:"var(--z-tooltip)"}:{borderRadius:f?"16px":"9999px",visibility:"hidden",maxWidth:P,position:"fixed",top:"-9999px",left:"-9999px",zIndex:"var(--z-tooltip)"}},[e,te,ht,f]);if(D.length>0)return null;const Pn=n.jsxs(n.Fragment,{children:[Ie==="root"&&F&&n.jsx(qm,{element:F,onToggleLock:Zt,onThumbnailClick:R}),Ie==="root"&&(F==null?void 0:F.transformType)==="image"&&n.jsx(Zl,{element:F,onElementUpdate:X,showUngroupButton:!!G&&(_==null?void 0:_.transformType)==="group",onUngroup:Qt,onMoveForward:Ut,onMoveBackward:an,onChangeImage:r,onDelete:un,cornerRadiusExpanded:(L==null?void 0:L.type)==="cornerRadius",onCornerRadiusToggle:He,cropExpanded:(L==null?void 0:L.type)==="crop",onCropToggle:Se,rotationExpanded:(L==null?void 0:L.type)==="rotation",onRotationToggle:_e,opacityExpanded:(L==null?void 0:L.type)==="opacity",onOpacityToggle:Ae,strokeExpanded:(L==null?void 0:L.type)==="stroke",onStrokeToggle:rn,knockoutExpanded:(L==null?void 0:L.type)==="compositing",onKnockoutToggle:Bt,distressTextureExpanded:(L==null?void 0:L.type)==="distressTexture",onDistressTextureToggle:At,imageMaskExpanded:(L==null?void 0:L.type)==="imageMask",onImageMaskToggle:Dt}),Ie==="root"&&(_==null?void 0:_.transformType)==="group"&&!G&&n.jsx(Qm,{element:_,rotationExpanded:(L==null?void 0:L.type)==="rotation",onRotationToggle:_e,opacityExpanded:(L==null?void 0:L.type)==="opacity",onOpacityToggle:Ae,strokeExpanded:(L==null?void 0:L.type)==="stroke",onStrokeToggle:rn,knockoutExpanded:(L==null?void 0:L.type)==="compositing",onKnockoutToggle:Bt,distressTextureExpanded:(L==null?void 0:L.type)==="distressTexture",onDistressTextureToggle:At,imageMaskExpanded:(L==null?void 0:L.type)==="imageMask",onImageMaskToggle:Dt,onUngroup:Qt}),Ie==="root"&&(F==null?void 0:F.transformType)==="shape"&&n.jsx(Jl,{element:F,onElementUpdate:X,documentColors:Ht,imageColors:Pt,showUngroupButton:!!G&&(_==null?void 0:_.transformType)==="group",onUngroup:Qt,onMoveForward:Ut,onMoveBackward:an,onOpenShapeTypeDrawer:Wo,onDelete:un,rotationExpanded:(L==null?void 0:L.type)==="rotation",onRotationToggle:_e,cornerRadiusExpanded:(L==null?void 0:L.type)==="shapeCornerRadius",onCornerRadiusToggle:fe,transparencyExpanded:(L==null?void 0:L.type)==="shapeTransparency",onTransparencyToggle:Be,sidesExpanded:(L==null?void 0:L.type)==="shapeSides",onSidesToggle:Oe,pointsExpanded:(L==null?void 0:L.type)==="shapePoints",onPointsToggle:ot,innerRadiusExpanded:(L==null?void 0:L.type)==="shapeInnerRadius",onInnerRadiusToggle:mt,colorExpanded:(L==null?void 0:L.type)==="shapeColor",onColorToggle:_t,strokeExpanded:(L==null?void 0:L.type)==="stroke",onStrokeToggle:rn,knockoutExpanded:(L==null?void 0:L.type)==="compositing",onKnockoutToggle:Bt,distressTextureExpanded:(L==null?void 0:L.type)==="distressTexture",onDistressTextureToggle:At,imageMaskExpanded:(L==null?void 0:L.type)==="imageMask",onImageMaskToggle:Dt}),Ie==="root"&&(F==null?void 0:F.transformType)==="path"&&n.jsx(Ql,{element:F,onElementUpdate:X,onMoveForward:Ut,onMoveBackward:an}),Ie==="root"&&F&&F.transformType!=="image"&&F.transformType!=="group"&&F.transformType!=="shape"&&F.transformType!=="path"&&n.jsx(mc,{toolbar:W,stableElementId:ft,viewportWidth:i,colorPickerValue:Ze,isColorActive:(L==null?void 0:L.type)==="textColor",onColorToggle:Wt,onOpenGlyphBrowser:t,strokeExpanded:(L==null?void 0:L.type)==="stroke",onStrokeToggle:rn,hasGlyphs:c,expandedPanel:L,onRotationToggle:_e,onOpacityToggle:Ae,onFontSizeToggle:V,knockoutExpanded:(L==null?void 0:L.type)==="compositing",onKnockoutToggle:Bt,distressTextureExpanded:(L==null?void 0:L.type)==="distressTexture",onDistressTextureToggle:At,imageMaskExpanded:(L==null?void 0:L.type)==="imageMask",onImageMaskToggle:Dt,getMoreMenuItems:d,onMoveForward:Ut,onMoveBackward:an,onDelete:un,elementForProperties:F,elements:Y,isTransformMenuOpen:Pe,onTransformMenuOpenChange:me,elementUpdateHandler:X,showUngroupButton:!!G&&(_==null?void 0:_.transformType)==="group",onUngroup:Qt,isFontBrowserOpen:Ke==="fontFamily",onFontBrowserToggle:P=>re(P?"fontFamily":null),onTextMoreMenuOpenChange:le}),Ie==="color"&&n.jsxs("div",{className:"toolbar-items",children:[n.jsx(Lm,{onClick:()=>ke("root")}),n.jsxs("div",{className:"toolbar-scroll",children:[n.jsx("input",{className:"toolbar-color",type:"color",value:Q,onChange:P=>{nt(P)}}),n.jsx("span",{className:"toolbar-label",children:Q})]})]})]}),ut=(F==null?void 0:F.transformType)==="shape"?F:null,cn=pt?n.jsx("div",{ref:lt,className:"toolbar","data-mode":e,"data-wrap":f?"":void 0,"data-transparent":p?"":void 0,"data-panel-expanded":L?"":void 0,"data-preserve-selection":!0,style:{...zt,opacity:k?0:1,pointerEvents:k?"none":"auto",transition:"opacity 0.05s ease-out"},"data-entering":tt?"":void 0,"data-exiting":oe?"":void 0,children:n.jsxs("div",{className:"toolbar-slide-container",children:[n.jsx("div",{className:"toolbar-regular-content","data-hidden":L?"":void 0,children:Pn}),n.jsx("div",{className:"toolbar-collapsed-header","data-visible":L?"":void 0,children:L&&n.jsx(zs,{icon:n.jsx(xg,{panelType:L.type,defaultIcon:L.icon,textColorValue:Ze,shapeFillColor:(bi=ut==null?void 0:ut.transformData)==null?void 0:bi.fillColor}),label:L.label,onClose:Lt,closeButtonStyle:w})})]})}):null,fn=(L==null?void 0:L.type)==="cornerRadius",jn=(L==null?void 0:L.type)==="crop",Fn=(L==null?void 0:L.type)==="rotation",Cn=(L==null?void 0:L.type)==="opacity",En=(L==null?void 0:L.type)==="fontSize",dn=(L==null?void 0:L.type)==="shapeCornerRadius",Kn=(L==null?void 0:L.type)==="shapeTransparency",ur=(L==null?void 0:L.type)==="shapeSides",hr=(L==null?void 0:L.type)==="shapePoints",Un=(L==null?void 0:L.type)==="shapeInnerRadius",pn=(L==null?void 0:L.type)==="shapeColor",qn=(L==null?void 0:L.type)==="textColor",Sn=(L==null?void 0:L.type)==="compositing",bn=(L==null?void 0:L.type)==="distressTexture",Sr=(L==null?void 0:L.type)==="stroke",kr=(L==null?void 0:L.type)==="imageMask",jr=(F==null?void 0:F.transformType)==="image"&&((yi=F.transformData)==null?void 0:yi.borderRadius)||0,io=(F==null?void 0:F.rotation)||0,ao=(F==null?void 0:F.opacity)??1,lo=((vi=ut==null?void 0:ut.transformData)==null?void 0:vi.borderRadius)||0,co=((wi=ut==null?void 0:ut.transformData)==null?void 0:wi.fillOpacity)??1,Xo=((Ci=ut==null?void 0:ut.transformData)==null?void 0:Ci.sides)||5,Vo=((Si=ut==null?void 0:ut.transformData)==null?void 0:Si.points)||5,Tn=((ki=ut==null?void 0:ut.transformData)==null?void 0:ki.innerRadius)||.4,Er=((ji=ut==null?void 0:ut.transformData)==null?void 0:ji.fillColor)||"#3b82f6",Go=((Ei=F==null?void 0:F.knockoutParts)==null?void 0:Ei.fill)??!1,Ko=((Ti=F==null?void 0:F.knockoutParts)==null?void 0:Ti.stroke)??!1,Rn=((Ri=F==null?void 0:F.knockoutParts)==null?void 0:Ri.scope)??"group",qo=(F==null?void 0:F.blendMode)==="clip"?"clip":"knockout",Zo=fn&&(F==null?void 0:F.transformType)==="image"?n.jsx(tg,{value:jr,onChange:Mt}):null,kc=jn&&(F==null?void 0:F.transformType)==="image"?n.jsx(gg,{element:F,onElementUpdate:X}):null,jc=Fn&&F?n.jsx(ng,{value:io,onChange:hn,onRotate90:en}):null,Ec=Cn&&F?n.jsx(og,{value:ao,onChange:xn}):null,Tc=En?n.jsx(rg,{value:W.fontSize,onChange:W.handleFontSizeChange,widthValue:ne,onWidthChange:xe}):null,Rc=dn&&ut?n.jsx(sg,{value:lo,onChange:ue}):null,Nc=Kn&&ut?n.jsx(ig,{value:co,onChange:et}):null,Mc=ur&&ut?n.jsx(ag,{value:Xo,onChange:K}):null,Ic=hr&&ut?n.jsx(lg,{value:Vo,onChange:be}):null,Ac=Un&&ut?n.jsx(cg,{value:Tn,onChange:Te}):null,Dc=pn&&ut?n.jsx(dg,{value:Er,onChange:Ne,documentColors:Ht,imageColors:Pt}):null,Lc=qn&&F?n.jsx(ug,{value:Ze,onChange:We,documentColors:Ht,imageColors:Pt}):null,Pc=Sn&&F?n.jsx(hg,{mode:qo,fill:Go,stroke:Ko,scope:Rn,onModeChange:Yn,onFillChange:er,onStrokeChange:wn,onScopeChange:cr}):null,Fc=Sr&&F?n.jsx(mg,{stroke:F.stroke,onChange:so,documentColors:Ht,imageColors:Pt}):null,zc=bn&&F?n.jsx(fg,{textureUrl:((Ni=F.distressEffect)==null?void 0:Ni.textureUrl)??"",opacity:Math.round((((Mi=F.distressEffect)==null?void 0:Mi.textureOpacity)??.5)*100),onTextureChange:dr,onOpacityChange:Gn}):null,Nn=(Ii=F==null?void 0:F.masks)==null?void 0:Ii.find(P=>P.id==="quick-image-mask"),Oc=kr&&F?n.jsx(pg,{imageUrl:((Ai=Nn==null?void 0:Nn.maskElement)==null?void 0:Ai.imageUrl)??"",maskType:(Nn==null?void 0:Nn.type)??"clip",opacity:Math.round(((Nn==null?void 0:Nn.opacity)??1)*100),inverted:(Nn==null?void 0:Nn.inverted)??!1,onImageChange:tr,onMaskTypeChange:ln,onOpacityChange:Hn,onInvertedChange:$n}):null,_c=e==="embedded"&&!_&&!M?j?n.jsx("div",{className:"toolbar-empty-state",children:j}):C!==null?n.jsx("div",{className:"toolbar-empty-state",style:{display:"flex",alignItems:"center",justifyContent:"center",padding:"16px 24px",color:"var(--foreground)",opacity:.5,fontSize:"14px",textAlign:"center"},children:C}):null:null,Bc=e==="embedded"&&M&&!_&&A.getActiveArtboard()?n.jsxs("div",{className:"px-4 py-3 flex flex-col gap-3",children:[n.jsx(zs,{icon:"lucide:palette",label:"Artboard Properties",onClose:()=>S==null?void 0:S(!1),closeButtonStyle:"done"}),n.jsx(ec,{distressTexture:A.getActiveArtboard().distressTexture,onChange:P=>{const H=A.getActiveArtboard();u?u(H.id,{distressTexture:H.distressTexture},{distressTexture:P}):(A.updateArtboard(H.id,{distressTexture:P}),U())}}),n.jsx(tc,{imageMask:A.getActiveArtboard().imageMask,onChange:P=>{const H=A.getActiveArtboard();u?u(H.id,{imageMask:H.imageMask},{imageMask:P}):(A.updateArtboard(H.id,{imageMask:P}),U())}})]}):null,Hc=e==="embedded"?n.jsx(bg,{toolbarContent:cn,innerContentRef:Ot,shouldRender:pt,isExiting:oe,transitionHeight:Rt,emptyStateContent:Bc||_c,isCornerRadiusPanelOpen:fn,isCropPanelOpen:jn,isRotationPanelOpen:Fn,isOpacityPanelOpen:Cn,isFontSizePanelOpen:En,isShapeCornerRadiusPanelOpen:dn,isShapeTransparencyPanelOpen:Kn,isShapeSidesPanelOpen:ur,isShapePointsPanelOpen:hr,isShapeInnerRadiusPanelOpen:Un,isShapeColorPanelOpen:pn,isTextColorPanelOpen:qn,isStrokePanelOpen:Sr,isKnockoutPanelOpen:Sn,isDistressTexturePanelOpen:bn,isImageMaskPanelOpen:kr,cornerRadiusPanel:Zo,cropPanelContent:kc,rotationPanel:jc,opacityPanel:Ec,fontSizePanel:Tc,shapeCornerRadiusPanel:Rc,shapeTransparencyPanel:Nc,shapeSidesPanel:Mc,shapePointsPanel:Ic,shapeInnerRadiusPanel:Ac,shapeColorPanel:Dc,textColorPanel:Lc,strokePanel:Fc,knockoutPanel:Pc,distressTexturePanel:zc,imageMaskPanel:Oc}):null,$c=kt.width>0?Math.max(kt.width,200):280,Uc=e==="floating"&&fn&&(F==null?void 0:F.transformType)==="image"&&te?n.jsx(yg,{toolbarPosition:te,toolbarHeight:kt.height||56,panelWidth:$c,value:jr,onChange:Mt}):null,Yc=e==="floating"&&jn&&(F==null?void 0:F.transformType)==="image"&&te?n.jsx(vg,{toolbarPosition:te,toolbarHeight:kt.height||56,element:F,onElementUpdate:X}):null;return n.jsxs(n.Fragment,{children:[e==="floating"&&typeof document<"u"?Qn.createPortal(n.jsxs(n.Fragment,{children:[cn,Uc,Yc]}),document.body):Hc,e!=="embedded"&&!_&&A.getActiveArtboard()&&u&&n.jsx(nc,{artboard:A.getActiveArtboard(),artboards:Z,onArtboardUpdate:P=>{const H=A.getActiveArtboard();u(H.id,{backgroundColor:H.backgroundColor,backgroundType:H.backgroundType,backgroundTexture:H.backgroundTexture,exportBackground:H.exportBackground},{backgroundColor:P.backgroundColor,backgroundType:P.backgroundType,backgroundTexture:P.backgroundTexture,exportBackground:P.exportBackground})},onRenameArtboard:(P,H)=>{A.renameArtboard(P,H),U()},onDeleteArtboard:P=>{A.deleteArtboard(P),U()},artboardScreenBounds:h}),!o&&(F==null?void 0:F.transformType)==="shape"&&n.jsx(mi,{isOpen:Me,onClose:()=>ge(!1),onSelectType:Yo,currentType:F.transformData.shapeType})]})},Lg=Object.freeze(Object.defineProperty({__proto__:null,ContextualToolbars:Vs,default:Vs},Symbol.toStringTag,{value:"Module"})),Gs=({className:e,position:t="bottom-right",showFitButton:r=!0,showResetButton:o=!0})=>{const{zoom:s,zoomIn:i,zoomOut:a,zoomToFit:c,resetView:d}=Yt.useViewportContext(),u=Math.round(s*100),h={"bottom-left":{bottom:16,left:16},"bottom-right":{bottom:16,right:16},"top-left":{top:16,left:16},"top-right":{top:16,right:16}};return n.jsxs("div",{className:e,style:{position:"absolute",...h[t],display:"flex",alignItems:"center",gap:4,padding:4,backgroundColor:"var(--surface)",borderRadius:"var(--radius-lg)",boxShadow:"var(--shadow-md)",zIndex:"var(--z-sticky)"},children:[n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:a,disabled:s<=.1,"aria-label":"Zoom out",children:n.jsx(de,{icon:Re.minus,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Zoom out"})]}),n.jsxs("div",{style:{minWidth:48,textAlign:"center",fontSize:13,fontWeight:500,color:"var(--foreground)",fontVariantNumeric:"tabular-nums"},children:[u,"%"]}),n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:i,disabled:s>=4,"aria-label":"Zoom in",children:n.jsx(de,{icon:Re.plus,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Zoom in"})]}),(r||o)&&n.jsx("div",{style:{width:1,height:20,backgroundColor:"var(--divider)",margin:"0 4px"}}),r&&n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:c,"aria-label":"Fit to screen",children:n.jsx(de,{icon:Re.fitScreen,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Fit to screen"})]}),o&&n.jsxs(m.Tooltip,{children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon",onClick:d,"aria-label":"Reset to 100%",children:n.jsx(de,{icon:Re.maximize,className:"size-4"})})}),n.jsx(m.TooltipContent,{children:"Reset to 100%"})]})]})},Pg=Object.freeze(Object.defineProperty({__proto__:null,ZoomControls:Gs,default:Gs},Symbol.toStringTag,{value:"Module"})),vc=({trigger:e,children:t,isOpen:r,onToggle:o,position:s="bottom",align:i="start",offset:a=8,protectClick:c=!0,className:d="",contentClassName:u=""})=>{const h=l.useRef(null),f=l.useRef(null),p=l.useRef(null),[g,b]=l.useState({}),[x,y]=l.useState(!1),v=C=>{C.stopPropagation(),!r&&c&&ri.protectNextClick(),o(!r)};l.useEffect(()=>{if(!r)return;let C=()=>{};const j=setTimeout(()=>{const M=S=>{var E,O;const R=S.target,I=(E=h.current)==null?void 0:E.contains(R),D=(O=p.current)==null?void 0:O.contains(R);!I&&!D&&o(!1)};document.addEventListener("mousedown",M),C=()=>document.removeEventListener("mousedown",M)},0);return()=>{clearTimeout(j),C()}},[r,o]),l.useEffect(()=>{if(!r)return;const C=j=>{var M;if(j.key==="Escape"){j.stopPropagation(),j.preventDefault(),o(!1);const S=(M=f.current)==null?void 0:M.querySelector('button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])');S==null||S.focus()}};return document.addEventListener("keydown",C),()=>document.removeEventListener("keydown",C)},[r,o]),l.useEffect(()=>{r||y(!1)},[r]),l.useEffect(()=>{if(!r||!f.current||!p.current)return;requestAnimationFrame(()=>{const j=f.current,M=p.current;if(!j||!M)return;const S=j.getBoundingClientRect(),R=M.getBoundingClientRect(),I=window.innerWidth,D=window.innerHeight,E=16;let O=0,z=0;if(s==="bottom"||s==="top"?(s==="bottom"?O=S.bottom+a:O=S.top-R.height-a,i==="start"?z=S.left:i==="end"?z=S.right-R.width:i==="center"&&(z=S.left+(S.width-R.width)/2)):(s==="left"||s==="right")&&(s==="left"?z=S.left-R.width-a:z=S.right+a,i==="start"?O=S.top:i==="end"?O=S.bottom-R.height:i==="center"&&(O=S.top+(S.height-R.height)/2)),i!=="end"&&z+R.width>I-E&&(z=I-R.width-E),z<E&&(z=E),O+R.height>D-E){const k=S.top,Y=D-S.bottom;k>Y&&(O=S.top-R.height-a)}O<E&&(O=E);const B=I-E*2;y(!0),b({position:"fixed",top:`${O}px`,left:`${z}px`,maxWidth:`${B}px`,visibility:"visible"})})},[r,s,i,a]);const w=r&&n.jsx("div",{ref:p,className:`z-dropdown ${u}`.trim(),"data-preserve-selection":!0,style:x?g:{position:"fixed",visibility:"hidden",top:0,left:0},children:t});return n.jsxs("div",{className:`relative inline-flex ${d}`.trim(),ref:h,children:[n.jsx("div",{ref:f,onClick:v,children:e}),w&&Qn.createPortal(w,document.body)]})},Ks=({children:e,className:t="",minWidth:r="160px",maxHeight:o})=>{const s=o?`max-h-[${o}]`:"",i={minWidth:r};return n.jsx("div",{role:"menu",className:`flex flex-col gap-px rounded-xl border border-border-primary bg-surface p-xs shadow-md ${s} ${t}`.trim(),style:i,children:e})},ar=({icon:e,label:t,shortcut:r,active:o=!1,disabled:s=!1,onClick:i,className:a="",children:c,...d})=>{const u=["flex items-center gap-md","px-lg py-md","bg-transparent border-none","rounded-lg","text-text-primary text-base font-normal","cursor-pointer","transition-all duration-fast","text-left w-full"],h=[o?"bg-accent-light font-medium":"",s?"opacity-disabled cursor-not-allowed":"hover:bg-bg-hover"],f=[...u,...h,a].filter(Boolean).join(" "),p=()=>{!s&&i&&i()};return n.jsxs("button",{role:"menuitem",className:f,onClick:p,disabled:s,type:"button",...d,children:[e&&n.jsx("span",{className:"flex shrink-0 items-center",children:e}),n.jsx("span",{className:"flex-1",children:c||t}),r&&n.jsx("span",{className:"ml-auto text-sm text-text-muted",children:r}),o&&!r&&n.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",className:"ml-auto shrink-0",children:n.jsx("path",{d:"M13 4L6 11L3 8",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})]})},js=T.createLogger("MenuButton"),wc=({isLayersPanelOpen:e=!1,onToggleLayersPanel:t,onOpenImageBrowser:r,additionalItems:o,icon:s=n.jsx(de,{icon:Re.menu,className:"size-6"}),tooltip:i="Menu",className:a})=>{const{artboardManager:c,elements:d,canvasRef:u,handleLoadWorkspace:h,handleAddElement:f}=Yt.useEditor(),[p,g]=l.useState(!1),[b,x]=l.useState(!1),[y,v]=l.useState(!1),w=l.useRef(null),C=()=>{try{const O=c.getAllArtboards();rt.ExportManager.exportToJSON(O,d,c),g(!1)}catch(O){js.error("Failed to save workspace:",O),alert("Failed to save workspace. Please try again.")}},j=()=>{var O;(O=w.current)==null||O.click(),g(!1)},M=async O=>{var B;const z=(B=O.target.files)==null?void 0:B[0];if(z){try{const k=await rt.ImportManager.importFromJSON(z);if(k.success&&k.artboards&&k.elements){const Y=rt.ImportManager.validateImportedData(k.artboards,k.elements);if(!Y.valid&&!confirm(`Found ${Y.errors.length} issue(s) in the file:
30
30
 
31
31
  `+Y.errors.slice(0,3).join(`
32
32
  `)+(Y.errors.length>3?`
33
33
  ...and ${Y.errors.length-3} more`:"")+`
34
34
 
35
- Do you want to load anyway?`))return;const B=rt.ImportManager.getImportSummary(k.artboards,k.elements);confirm(`Load workspace with:
35
+ Do you want to load anyway?`))return;const _=rt.ImportManager.getImportSummary(k.artboards,k.elements);confirm(`Load workspace with:
36
36
 
37
- • ${B.artboardCount} artboard(s): ${B.artboardNames.join(", ")}
38
- • ${B.elementCount} element(s)
37
+ • ${_.artboardCount} artboard(s): ${_.artboardNames.join(", ")}
38
+ • ${_.elementCount} element(s)
39
39
 
40
- This will replace your current workspace. Continue?`)&&h(k.artboards,k.elements,k.activeArtboardId||null)}else alert(`Failed to load: ${k.error||"Unknown error"}`)}catch(k){ks.error("Failed to load workspace:",k),alert("Failed to load workspace. Please check the file and try again.")}w.current&&(w.current.value="")}},S=async()=>{if(!(u!=null&&u.current)){alert("Canvas not available for export");return}const O=c.getActiveArtboard();if(!O){alert("No active artboard to export");return}try{await rt.ExportManager.exportArtboardToImage(O,d,u.current,{format:"png",scale:2,transparentBackground:!1}),g(!1)}catch(z){ks.error("Failed to export artboard:",z),alert("Failed to export artboard. Please try again.")}},R=async O=>{if(O==="image"&&r){r(),g(!1),x(!1);return}if(O==="shape"){g(!1),x(!1),v(!0);return}await f(O),g(!1),x(!1)},I=async O=>{v(!1),await f("shape",{shapeType:O})},D=[{type:"custom",label:"Text",icon:n.jsx(de,{icon:Re.text,className:"size-[18px]"})},{type:"image",label:"Image",icon:n.jsx(de,{icon:Re.image,className:"size-[18px]"})},{type:"shape",label:"Shape",icon:n.jsx(de,{icon:Re.shapes,className:"size-[18px]"})},{type:"circle",label:"Circle Text",icon:n.jsx(de,{icon:"lucide:circle",className:"size-[18px]"})},{type:"wave",label:"Wave Text",icon:n.jsx(de,{icon:"lucide:waves",className:"size-[18px]"})},{type:"arch",label:"Arch Text",icon:n.jsx(de,{icon:"lucide:arrow-up-from-dot",className:"size-[18px]"})}],E=()=>n.jsx("div",{className:"my-xs h-px bg-border-primary"});return n.jsxs(n.Fragment,{children:[n.jsx(pc,{trigger:n.jsxs(m.Tooltip,{delayDuration:0,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon","aria-label":i,className:a,children:s})}),n.jsx(m.TooltipContent,{children:n.jsx("p",{children:i})})]}),isOpen:p,onToggle:g,position:"bottom",align:"end",children:n.jsxs(Vs,{minWidth:"200px",children:[n.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),children:[n.jsx(ar,{icon:n.jsx(de,{icon:Re.plus,className:"size-[18px]"}),label:"Add Element"}),b&&n.jsx("div",{style:{position:"absolute",left:"100%",top:0,zIndex:"var(--z-sticky)"},children:n.jsx(Vs,{minWidth:"180px",children:D.map(O=>n.jsx(ar,{icon:O.icon,label:O.label,onClick:()=>R(O.type)},O.type))})})]}),n.jsx(E,{}),n.jsx(ar,{icon:n.jsx(de,{icon:Re.save,className:"size-[18px]"}),label:"Save",onClick:C}),n.jsx(ar,{icon:n.jsx(de,{icon:Re.folderOpen,className:"size-[18px]"}),label:"Open",onClick:j}),n.jsx(ar,{icon:n.jsx(de,{icon:Re.download,className:"size-[18px]"}),label:"Export Image",onClick:S,disabled:!(u!=null&&u.current)}),t&&n.jsxs(n.Fragment,{children:[n.jsx(E,{}),n.jsx(ar,{icon:n.jsx(de,{icon:Re.layers,className:"size-[18px]"}),label:`${e?"Hide":"Show"} Layers`,onClick:()=>{t(),g(!1)}})]}),o&&n.jsxs(n.Fragment,{children:[n.jsx(E,{}),o]})]})}),n.jsx("input",{ref:w,type:"file",accept:".json",style:{display:"none"},onChange:M}),n.jsx(fi,{isOpen:y,onClose:()=>v(!1),onSelectType:I})]})},Lg=Object.freeze(Object.defineProperty({__proto__:null,MenuButton:mc},Symbol.toStringTag,{value:"Module"})),Pa=T.createLogger("AutoExportManager"),gc={enabled:!0,debounceMs:100,maxWaitMs:1e3};class Pg{constructor(t={}){this.onExportCallback=null,this.onExportScheduledCallback=null,this.revision=0,this.lastExportedRevision=-1,this.stats={totalExports:0,skippedExports:0,lastExportTime:null,avgExportInterval:0},this.exportTimestamps=[],this.config={...gc,...t},this.debouncedExport=Pi.debounce(()=>this.performExport(),this.config.debounceMs,{maxWait:this.config.maxWaitMs,leading:!1,trailing:!0})}scheduleExport(){const t=Date.now();!this.config.enabled||(this.revision++,(this.stats.lastExportTime?t-this.stats.lastExportTime:1/0)<200)||(this.onExportScheduledCallback&&this.onExportScheduledCallback(),this.debouncedExport())}async forceExport(){this.debouncedExport.cancel(),this.revision++,await this.performExport()}async performExport(){if(!this.config.enabled)return;if(this.revision===this.lastExportedRevision){this.stats.skippedExports++;return}const t=this.revision,r=Date.now();if(this.exportTimestamps.push(r),this.exportTimestamps.length>10&&this.exportTimestamps.shift(),this.exportTimestamps.length>1){const o=[];for(let s=1;s<this.exportTimestamps.length;s++)o.push(this.exportTimestamps[s]-this.exportTimestamps[s-1]);this.stats.avgExportInterval=o.reduce((s,i)=>s+i,0)/o.length}this.stats.totalExports++,this.stats.lastExportTime=r,this.onExportCallback?setTimeout(async()=>{const o=this.onExportCallback;if(o){try{await o()}catch(s){Pa.error("Export failed:",s)}this.lastExportedRevision=t,this.revision>t&&this.config.enabled&&this.debouncedExport()}},0):Pa.warn("No export callback registered")}onExport(t){this.onExportCallback=t}onExportScheduled(t){this.onExportScheduledCallback=t}updateConfig(t){const r={...this.config};r.enabled&&t.enabled===!1&&this.debouncedExport.flush(),this.config={...this.config,...t},(r.debounceMs!==this.config.debounceMs||r.maxWaitMs!==this.config.maxWaitMs)&&(this.debouncedExport.cancel(),this.debouncedExport=Pi.debounce(()=>this.performExport(),this.config.debounceMs,{maxWait:this.config.maxWaitMs,leading:!1,trailing:!0}))}getStats(){return{...this.stats}}resetStats(){this.stats={totalExports:0,skippedExports:0,lastExportTime:null,avgExportInterval:0},this.exportTimestamps=[]}resetChangeDetection(){this.lastExportedRevision=-1}destroy(){this.debouncedExport.cancel(),this.onExportCallback=null,this.onExportScheduledCallback=null,this.lastExportedRevision=-1}}function Fg({width:e=800,height:t=600,style:r}){return n.jsxs("div",{className:"canvas-skeleton",style:{width:e,height:t,backgroundColor:"var(--divider)",borderRadius:"8px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative",overflow:"hidden",...r},children:[n.jsx("div",{style:{position:"absolute",top:0,left:"-100%",width:"100%",height:"100%",background:"linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent)",animation:"shimmer 2s infinite"}}),n.jsx("div",{style:{fontSize:"14px",color:"var(--muted)",fontFamily:"system-ui, sans-serif"},children:"Loading canvas..."}),n.jsx("style",{children:`
40
+ This will replace your current workspace. Continue?`)&&h(k.artboards,k.elements,k.activeArtboardId||null)}else alert(`Failed to load: ${k.error||"Unknown error"}`)}catch(k){js.error("Failed to load workspace:",k),alert("Failed to load workspace. Please check the file and try again.")}w.current&&(w.current.value="")}},S=async()=>{if(!(u!=null&&u.current)){alert("Canvas not available for export");return}const O=c.getActiveArtboard();if(!O){alert("No active artboard to export");return}try{await rt.ExportManager.exportArtboardToImage(O,d,u.current,{format:"png",scale:2,transparentBackground:!1}),g(!1)}catch(z){js.error("Failed to export artboard:",z),alert("Failed to export artboard. Please try again.")}},R=async O=>{if(O==="image"&&r){r(),g(!1),x(!1);return}if(O==="shape"){g(!1),x(!1),v(!0);return}await f(O),g(!1),x(!1)},I=async O=>{v(!1),await f("shape",{shapeType:O})},D=[{type:"custom",label:"Text",icon:n.jsx(de,{icon:Re.text,className:"size-[18px]"})},{type:"image",label:"Image",icon:n.jsx(de,{icon:Re.image,className:"size-[18px]"})},{type:"shape",label:"Shape",icon:n.jsx(de,{icon:Re.shapes,className:"size-[18px]"})},{type:"circle",label:"Circle Text",icon:n.jsx(de,{icon:"lucide:circle",className:"size-[18px]"})},{type:"wave",label:"Wave Text",icon:n.jsx(de,{icon:"lucide:waves",className:"size-[18px]"})},{type:"arch",label:"Arch Text",icon:n.jsx(de,{icon:"lucide:arrow-up-from-dot",className:"size-[18px]"})}],E=()=>n.jsx("div",{className:"my-xs h-px bg-border-primary"});return n.jsxs(n.Fragment,{children:[n.jsx(vc,{trigger:n.jsxs(m.Tooltip,{delayDuration:0,children:[n.jsx(m.TooltipTrigger,{asChild:!0,children:n.jsx(m.Button,{variant:"ghost",size:"icon","aria-label":i,className:a,children:s})}),n.jsx(m.TooltipContent,{children:n.jsx("p",{children:i})})]}),isOpen:p,onToggle:g,position:"bottom",align:"end",children:n.jsxs(Ks,{minWidth:"200px",children:[n.jsxs("div",{style:{position:"relative"},onMouseEnter:()=>x(!0),onMouseLeave:()=>x(!1),children:[n.jsx(ar,{icon:n.jsx(de,{icon:Re.plus,className:"size-[18px]"}),label:"Add Element"}),b&&n.jsx("div",{style:{position:"absolute",left:"100%",top:0,zIndex:"var(--z-sticky)"},children:n.jsx(Ks,{minWidth:"180px",children:D.map(O=>n.jsx(ar,{icon:O.icon,label:O.label,onClick:()=>R(O.type)},O.type))})})]}),n.jsx(E,{}),n.jsx(ar,{icon:n.jsx(de,{icon:Re.save,className:"size-[18px]"}),label:"Save",onClick:C}),n.jsx(ar,{icon:n.jsx(de,{icon:Re.folderOpen,className:"size-[18px]"}),label:"Open",onClick:j}),n.jsx(ar,{icon:n.jsx(de,{icon:Re.download,className:"size-[18px]"}),label:"Export Image",onClick:S,disabled:!(u!=null&&u.current)}),t&&n.jsxs(n.Fragment,{children:[n.jsx(E,{}),n.jsx(ar,{icon:n.jsx(de,{icon:Re.layers,className:"size-[18px]"}),label:`${e?"Hide":"Show"} Layers`,onClick:()=>{t(),g(!1)}})]}),o&&n.jsxs(n.Fragment,{children:[n.jsx(E,{}),o]})]})}),n.jsx("input",{ref:w,type:"file",accept:".json",style:{display:"none"},onChange:M}),n.jsx(mi,{isOpen:y,onClose:()=>v(!1),onSelectType:I})]})},Fg=Object.freeze(Object.defineProperty({__proto__:null,MenuButton:wc},Symbol.toStringTag,{value:"Module"})),Pa=T.createLogger("AutoExportManager"),Cc={enabled:!0,debounceMs:100,maxWaitMs:1e3};class zg{constructor(t={}){this.onExportCallback=null,this.onExportScheduledCallback=null,this.revision=0,this.lastExportedRevision=-1,this.stats={totalExports:0,skippedExports:0,lastExportTime:null,avgExportInterval:0},this.exportTimestamps=[],this.config={...Cc,...t},this.debouncedExport=zi.debounce(()=>this.performExport(),this.config.debounceMs,{maxWait:this.config.maxWaitMs,leading:!1,trailing:!0})}scheduleExport(){const t=Date.now();!this.config.enabled||(this.revision++,(this.stats.lastExportTime?t-this.stats.lastExportTime:1/0)<200)||(this.onExportScheduledCallback&&this.onExportScheduledCallback(),this.debouncedExport())}async forceExport(){this.debouncedExport.cancel(),this.revision++,await this.performExport()}async performExport(){if(!this.config.enabled)return;if(this.revision===this.lastExportedRevision){this.stats.skippedExports++;return}const t=this.revision,r=Date.now();if(this.exportTimestamps.push(r),this.exportTimestamps.length>10&&this.exportTimestamps.shift(),this.exportTimestamps.length>1){const o=[];for(let s=1;s<this.exportTimestamps.length;s++)o.push(this.exportTimestamps[s]-this.exportTimestamps[s-1]);this.stats.avgExportInterval=o.reduce((s,i)=>s+i,0)/o.length}this.stats.totalExports++,this.stats.lastExportTime=r,this.onExportCallback?setTimeout(async()=>{const o=this.onExportCallback;if(o){try{await o()}catch(s){Pa.error("Export failed:",s)}this.lastExportedRevision=t,this.revision>t&&this.config.enabled&&this.debouncedExport()}},0):Pa.warn("No export callback registered")}onExport(t){this.onExportCallback=t}onExportScheduled(t){this.onExportScheduledCallback=t}updateConfig(t){const r={...this.config};r.enabled&&t.enabled===!1&&this.debouncedExport.flush(),this.config={...this.config,...t},(r.debounceMs!==this.config.debounceMs||r.maxWaitMs!==this.config.maxWaitMs)&&(this.debouncedExport.cancel(),this.debouncedExport=zi.debounce(()=>this.performExport(),this.config.debounceMs,{maxWait:this.config.maxWaitMs,leading:!1,trailing:!0}))}getStats(){return{...this.stats}}resetStats(){this.stats={totalExports:0,skippedExports:0,lastExportTime:null,avgExportInterval:0},this.exportTimestamps=[]}resetChangeDetection(){this.lastExportedRevision=-1}destroy(){this.debouncedExport.cancel(),this.onExportCallback=null,this.onExportScheduledCallback=null,this.lastExportedRevision=-1}}function Og({width:e=800,height:t=600,style:r}){return n.jsxs("div",{className:"canvas-skeleton",style:{width:e,height:t,backgroundColor:"var(--divider)",borderRadius:"8px",display:"flex",alignItems:"center",justifyContent:"center",position:"relative",overflow:"hidden",...r},children:[n.jsx("div",{style:{position:"absolute",top:0,left:"-100%",width:"100%",height:"100%",background:"linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent)",animation:"shimmer 2s infinite"}}),n.jsx("div",{style:{fontSize:"14px",color:"var(--muted)",fontFamily:"system-ui, sans-serif"},children:"Loading canvas..."}),n.jsx("style",{children:`
41
41
  @keyframes shimmer {
42
42
  0% { transform: translateX(0); }
43
43
  100% { transform: translateX(200%); }
44
44
  }
45
- `})]})}function zg({itemCount:e=5,style:t}){return n.jsxs("div",{className:"layers-panel-skeleton",style:{width:"100%",padding:"16px",backgroundColor:"var(--surface)",borderRadius:"8px",...t},children:[Array.from({length:e}).map((r,o)=>n.jsx("div",{className:"layer-item-skeleton",style:{height:"48px",backgroundColor:"var(--divider)",borderRadius:"6px",marginBottom:o<e-1?"8px":0,position:"relative",overflow:"hidden"},children:n.jsx("div",{style:{position:"absolute",top:0,left:"-100%",width:"100%",height:"100%",background:"linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent)",animation:"shimmer 2s infinite",animationDelay:`${o*.1}s`}})},o)),n.jsx("style",{children:`
45
+ `})]})}function _g({itemCount:e=5,style:t}){return n.jsxs("div",{className:"layers-panel-skeleton",style:{width:"100%",padding:"16px",backgroundColor:"var(--surface)",borderRadius:"8px",...t},children:[Array.from({length:e}).map((r,o)=>n.jsx("div",{className:"layer-item-skeleton",style:{height:"48px",backgroundColor:"var(--divider)",borderRadius:"6px",marginBottom:o<e-1?"8px":0,position:"relative",overflow:"hidden"},children:n.jsx("div",{style:{position:"absolute",top:0,left:"-100%",width:"100%",height:"100%",background:"linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent)",animation:"shimmer 2s infinite",animationDelay:`${o*.1}s`}})},o)),n.jsx("style",{children:`
46
46
  @keyframes shimmer {
47
47
  0% { transform: translateX(0); }
48
48
  100% { transform: translateX(200%); }
49
49
  }
50
- `})]})}function Og({style:e}){return n.jsxs("div",{className:"toolbar-skeleton",style:{height:"56px",display:"flex",alignItems:"center",gap:"8px",padding:"0 16px",backgroundColor:"var(--surface)",borderBottom:"1px solid var(--divider)",...e},children:[[40,60,80,100,60,40].map((t,r)=>n.jsx("div",{style:{width:`${t}px`,height:"32px",backgroundColor:"var(--divider)",borderRadius:"6px",position:"relative",overflow:"hidden"},children:n.jsx("div",{style:{position:"absolute",top:0,left:"-100%",width:"100%",height:"100%",background:"linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent)",animation:"shimmer 2s infinite",animationDelay:`${r*.15}s`}})},r)),n.jsx("style",{children:`
50
+ `})]})}function Bg({style:e}){return n.jsxs("div",{className:"toolbar-skeleton",style:{height:"56px",display:"flex",alignItems:"center",gap:"8px",padding:"0 16px",backgroundColor:"var(--surface)",borderBottom:"1px solid var(--divider)",...e},children:[[40,60,80,100,60,40].map((t,r)=>n.jsx("div",{style:{width:`${t}px`,height:"32px",backgroundColor:"var(--divider)",borderRadius:"6px",position:"relative",overflow:"hidden"},children:n.jsx("div",{style:{position:"absolute",top:0,left:"-100%",width:"100%",height:"100%",background:"linear-gradient(90deg, transparent, rgba(255,255,255,0.5), transparent)",animation:"shimmer 2s infinite",animationDelay:`${r*.15}s`}})},r)),n.jsx("style",{children:`
51
51
  @keyframes shimmer {
52
52
  0% { transform: translateX(0); }
53
53
  100% { transform: translateX(200%); }
54
54
  }
55
- `})]})}function Bg({size:e=32,color:t="var(--primary)"}){return n.jsx("div",{className:"spinner",style:{width:`${e}px`,height:`${e}px`,border:"3px solid var(--divider)",borderTopColor:t,borderRadius:"50%",animation:"spin 0.8s linear infinite"},children:n.jsx("style",{children:`
55
+ `})]})}function Hg({size:e=32,color:t="var(--primary)"}){return n.jsx("div",{className:"spinner",style:{width:`${e}px`,height:`${e}px`,border:"3px solid var(--divider)",borderTopColor:t,borderRadius:"50%",animation:"spin 0.8s linear infinite"},children:n.jsx("style",{children:`
56
56
  @keyframes spin {
57
57
  to { transform: rotate(360deg); }
58
58
  }
59
- `})})}function _g(e){var i;const t=[],r=[];(!e.name||e.name.trim()==="")&&t.push("Kit name is required"),e.behavior.toolbar==="none"&&((i=e.layout.slots.topbar)!=null&&i.length)&&r.push('Toolbar mode is "none" but topbar has sections — topbar sections will be ignored'),e.behavior.selection==="multi"&&!e.capabilities.tools.includes("select")&&r.push('Multi-selection enabled but "select" tool not in capabilities'),e.capabilities.elements.length===0&&t.push("At least one element type must be enabled in capabilities.elements"),e.capabilities.transforms.length===0&&t.push("At least one transform type must be enabled in capabilities.transforms"),e.behavior.autoExport&&!e.capabilities.features.export&&r.push("autoExport is enabled but features.export is false — exports will not be produced");const o=[...e.layout.slots.left??[],...e.layout.slots.right??[]],s=["layers-panel","effects-panel","export-panel","images-panel","artboard-tabs"];for(const a of o)if(s.includes(a)){const d={"layers-panel":"layers","effects-panel":"effects","export-panel":"export","images-panel":"images","artboard-tabs":"artboards"}[a];d&&!e.capabilities.panels.includes(d)&&r.push(`Layout references "${a}" but "${d}" is not in capabilities.panels`)}return{valid:t.length===0,errors:t,warnings:r}}function gr(e,t){const r=new Set(e),o=[...e];for(const s of t)r.has(s)||(r.add(s),o.push(s));return o}function xo(e,t){return{...e,...t}}const Hg=["topbar","left","canvas","right","bottombar"];function xc(e,t){var g;const r=t.name??e.name,o=e.layout.slots,s=(g=t.layout)==null?void 0:g.slots,i={};for(const b of Hg){const x=o[b],y=s==null?void 0:s[b];x&&y?i[b]=gr(x,y):y?i[b]=[...y]:x&&(i[b]=[...x])}const a=e.capabilities,c=t.capabilities,d={elements:a.elements,transforms:a.transforms,effects:a.effects,panels:a.panels,tools:a.tools,features:{...a.features}};c&&(c.elements&&(d.elements=gr(a.elements,c.elements)),c.transforms&&(d.transforms=gr(a.transforms,c.transforms)),c.effects&&(d.effects=gr(a.effects,c.effects)),c.panels&&(d.panels=gr(a.panels,c.panels)),c.tools&&(d.tools=gr(a.tools,c.tools)),c.features&&(d.features=xo(a.features,c.features)));const u=t.behavior?xo(e.behavior,t.behavior):{...e.behavior},h=t.style?xo(e.style,t.style):{...e.style},f=e.content??{},p=t.content?xo(f,t.content):{...f};return{name:r,layout:{slots:i},capabilities:d,behavior:u,style:h,content:p}}const $g={layout:{slots:{canvas:["canvas"]}},capabilities:{elements:["text","image"],transforms:["custom","image"],effects:[],panels:[],tools:["select"],features:{export:!0,multiArtboard:!1,richText:!1,undo:!0,keyboardShortcuts:!0}},behavior:{toolbar:"contextual",selection:"single",panelMode:"drawer",onEmptyClick:"deselect",autoExport:!1},style:{density:"compact",toolbarVariant:"pill",panelVariant:"floating"},content:{sampleText:"Your Text",defaultFontFamily:"Poppins"}};function Ug(e){const{name:t,...r}=e,o={name:t,...$g};return xc(o,r)}exports.ALL_CAPABILITIES=qa;exports.ArtboardPropertiesToolbar=ql;exports.ArtboardTabs=Yl;exports.AutoExportManager=Pg;exports.BackgroundPickerDropdown=pi;exports.BoldButton=rc;exports.COMPACT_CUSTOMIZER=Za;exports.Canvas=fh;exports.CanvasSkeleton=Fg;exports.ColorPickerDropdown=lr;exports.ContextualToolbars=Ws;exports.CropPanel=qr;exports.DEFAULT_AUTO_EXPORT_CONFIG=gc;exports.Dropdown=pc;exports.DropdownMenu=Vs;exports.EMBED_ONLY=Qa;exports.EffectsPanel=Ol;exports.ExportPanel=_l;exports.FontBrowserDrawer=Ql;exports.FontColorButton=nc;exports.GlyphPanel=Ul;exports.Icon=de;exports.ImagePanel=$l;exports.ImageToolbar=Wl;exports.ItalicButton=oc;exports.KIT_PRESETS=Ns;exports.KitProvider=qd;exports.LayersPanel=Il;exports.LayersPanelSkeleton=zg;exports.MINIMAL_CAPABILITIES=Js;exports.MenuButton=mc;exports.MenuItem=ar;exports.MoreMenu=tc;exports.PRO_STUDIO=Ja;exports.PathToolbar=Vl;exports.ShapeToolbar=Xl;exports.ShapeTypeDrawer=fi;exports.Spinner=Bg;exports.TextAlignButton=ac;exports.TextMoreMenu=lc;exports.TextToolbar=cc;exports.ToolbarButton=ct;exports.ToolbarSkeleton=Og;exports.TransformControlPanel=ec;exports.UnderlineButton=sc;exports.UppercaseButton=ic;exports.ZoomControls=Xs;exports.clickProtection=ti;exports.createKit=Ug;exports.ensureIconsRegistered=Kd;exports.extendKit=xc;exports.getAllSections=bh;exports.getSection=gh;exports.getSectionIds=xh;exports.icons=Re;exports.registerBuiltinSections=vh;exports.registerBuiltinSectionsSync=wh;exports.registerSection=Gt;exports.renderPieceGuides=al;exports.resolveKit=el;exports.unregisterSection=yh;exports.useArtboards=Qr;exports.useCapabilities=Zd;exports.useExport=Bl;exports.useKit=nl;exports.useLayerPreview=uc;exports.useLayers=Qs;exports.useTextToolbar=dc;exports.validateKit=_g;
60
- //# sourceMappingURL=compose-HDJp4Z_d.cjs.map
59
+ `})})}function $g(e){var i;const t=[],r=[];(!e.name||e.name.trim()==="")&&t.push("Kit name is required"),e.behavior.toolbar==="none"&&((i=e.layout.slots.topbar)!=null&&i.length)&&r.push('Toolbar mode is "none" but topbar has sections — topbar sections will be ignored'),e.behavior.selection==="multi"&&!e.capabilities.tools.includes("select")&&r.push('Multi-selection enabled but "select" tool not in capabilities'),e.capabilities.elements.length===0&&t.push("At least one element type must be enabled in capabilities.elements"),e.capabilities.transforms.length===0&&t.push("At least one transform type must be enabled in capabilities.transforms"),e.behavior.autoExport&&!e.capabilities.features.export&&r.push("autoExport is enabled but features.export is false — exports will not be produced");const o=[...e.layout.slots.left??[],...e.layout.slots.right??[]],s=["layers-panel","effects-panel","export-panel","images-panel","artboard-tabs"];for(const a of o)if(s.includes(a)){const d={"layers-panel":"layers","effects-panel":"effects","export-panel":"export","images-panel":"images","artboard-tabs":"artboards"}[a];d&&!e.capabilities.panels.includes(d)&&r.push(`Layout references "${a}" but "${d}" is not in capabilities.panels`)}return{valid:t.length===0,errors:t,warnings:r}}function gr(e,t){const r=new Set(e),o=[...e];for(const s of t)r.has(s)||(r.add(s),o.push(s));return o}function xo(e,t){return{...e,...t}}const Ug=["topbar","left","canvas","right","bottombar"];function Sc(e,t){var g;const r=t.name??e.name,o=e.layout.slots,s=(g=t.layout)==null?void 0:g.slots,i={};for(const b of Ug){const x=o[b],y=s==null?void 0:s[b];x&&y?i[b]=gr(x,y):y?i[b]=[...y]:x&&(i[b]=[...x])}const a=e.capabilities,c=t.capabilities,d={elements:a.elements,transforms:a.transforms,effects:a.effects,panels:a.panels,tools:a.tools,features:{...a.features}};c&&(c.elements&&(d.elements=gr(a.elements,c.elements)),c.transforms&&(d.transforms=gr(a.transforms,c.transforms)),c.effects&&(d.effects=gr(a.effects,c.effects)),c.panels&&(d.panels=gr(a.panels,c.panels)),c.tools&&(d.tools=gr(a.tools,c.tools)),c.features&&(d.features=xo(a.features,c.features)));const u=t.behavior?xo(e.behavior,t.behavior):{...e.behavior},h=t.style?xo(e.style,t.style):{...e.style},f=e.content??{},p=t.content?xo(f,t.content):{...f};return{name:r,layout:{slots:i},capabilities:d,behavior:u,style:h,content:p}}const Yg={layout:{slots:{canvas:["canvas"]}},capabilities:{elements:["text","image"],transforms:["custom","image"],effects:[],panels:[],tools:["select"],features:{export:!0,multiArtboard:!1,richText:!1,undo:!0,keyboardShortcuts:!0}},behavior:{toolbar:"contextual",selection:"single",panelMode:"drawer",onEmptyClick:"deselect",autoExport:!1},style:{density:"compact",toolbarVariant:"pill",panelVariant:"floating"},content:{sampleText:"Your Text",defaultFontFamily:"Poppins"}};function Wg(e){const{name:t,...r}=e,o={name:t,...Yg};return Sc(o,r)}exports.ALL_CAPABILITIES=za;exports.ArtboardPropertiesToolbar=nc;exports.ArtboardTabs=ql;exports.AutoExportManager=zg;exports.BackgroundPickerDropdown=gi;exports.BoldButton=cc;exports.COMPACT_CUSTOMIZER=Oa;exports.Canvas=mh;exports.CanvasSkeleton=Og;exports.ColorPickerDropdown=lr;exports.ContextualToolbars=Vs;exports.CropPanel=qr;exports.DEFAULT_AUTO_EXPORT_CONFIG=Cc;exports.Dropdown=vc;exports.DropdownMenu=Ks;exports.EMBED_ONLY=Ba;exports.EffectsPanel=Yl;exports.ExportPanel=Xl;exports.FontBrowserDrawer=sc;exports.FontColorButton=lc;exports.GlyphPanel=Kl;exports.Icon=de;exports.ImagePanel=Gl;exports.ImageToolbar=Zl;exports.ItalicButton=dc;exports.KIT_PRESETS=Es;exports.KitProvider=nd;exports.LayersPanel=zl;exports.LayersPanelSkeleton=_g;exports.MINIMAL_CAPABILITIES=qs;exports.MenuButton=wc;exports.MenuItem=ar;exports.MoreMenu=ac;exports.PRO_STUDIO=_a;exports.PathToolbar=Ql;exports.ShapeToolbar=Jl;exports.ShapeTypeDrawer=mi;exports.Spinner=Hg;exports.TextAlignButton=fc;exports.TextMoreMenu=pc;exports.TextToolbar=mc;exports.ToolbarButton=ct;exports.ToolbarSkeleton=Bg;exports.TransformControlPanel=ic;exports.UnderlineButton=uc;exports.UppercaseButton=hc;exports.ZoomControls=Gs;exports.clickProtection=ri;exports.createKit=Wg;exports.ensureIconsRegistered=td;exports.extendKit=Sc;exports.getAllSections=vh;exports.getSection=bh;exports.getSectionIds=yh;exports.icons=Re;exports.registerBuiltinSections=Ch;exports.registerBuiltinSectionsSync=Sh;exports.registerSection=Gt;exports.renderPieceGuides=fl;exports.resolveKit=Ha;exports.unregisterSection=wh;exports.useArtboards=Qr;exports.useCapabilities=rd;exports.useExport=Wl;exports.useKit=Ua;exports.useLayerPreview=xc;exports.useLayers=Zs;exports.useTextToolbar=gc;exports.validateKit=$g;
60
+ //# sourceMappingURL=compose-qXEnDNMp.cjs.map