@woven-canvas/vue 1.7.1 → 1.7.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.umd.cjs
CHANGED
|
@@ -103,7 +103,7 @@ ${y}
|
|
|
103
103
|
`,a2="️",c2="",ra="";let Rs=null,Ps=null;function d2(n=[]){const e={};je.groups=e;const t=new je;Rs==null&&(Rs=Ah(n2)),Ps==null&&(Ps=Ah(o2)),V(t,"'",Cs),V(t,"{",Xo),V(t,"}",Qo),V(t,"[",as),V(t,"]",cs),V(t,"(",ds),V(t,")",us),V(t,"<",fs),V(t,">",hs),V(t,"(",ps),V(t,")",ms),V(t,"「",gs),V(t,"」",ys),V(t,"『",ks),V(t,"』",ws),V(t,"<",bs),V(t,">",Ss),V(t,"&",xs),V(t,"*",Es),V(t,"@",on),V(t,"`",Ms),V(t,"^",Ts),V(t,":",rn),V(t,",",Xl),V(t,"$",Ns),V(t,".",gt),V(t,"=",As),V(t,"!",Ql),V(t,"-",et),V(t,"%",Zo),V(t,"|",Bs),V(t,"+",Is),V(t,"#",Os),V(t,"?",er),V(t,'"',Zl),V(t,"/",yt),V(t,";",ea),V(t,"~",tr),V(t,"_",_s),V(t,"\\",vs),V(t,"・",Eh);const o=me(t,$t,Jl,{[zl]:!0});me(o,$t,o);const r=me(o,Vt,xh,{[Jo]:!0}),s=me(o,nr,Ch,{[Go]:!0}),i=me(t,Vt,Lt,{[Fl]:!0});me(i,$t,r),me(i,Vt,i),me(r,$t,r),me(r,Vt,r);const l=me(t,nr,Wl,{[Hl]:!0});me(l,Vt),me(l,$t,s),me(l,nr,l),me(s,$t,s),me(s,Vt),me(s,nr,s);const c=V(t,oa,Yl,{[Ul]:!0}),d=V(t,Th,Gl,{[Ul]:!0}),u=me(t,na,Gl,{[Ul]:!0});V(t,ra,u),V(d,oa,c),V(d,ra,u),me(d,na,u),V(u,Th),V(u,oa),me(u,na,u),V(u,ra,u);const f=me(t,ta,vh,{[bh]:!0});V(f,"#"),me(f,ta,f),V(f,a2,f);const h=V(f,c2);V(h,"#"),me(h,ta,f);const p=[[Vt,i],[$t,r]],m=[[Vt,null],[nr,l],[$t,s]];for(let g=0;g<Rs.length;g++)sn(t,Rs[g],Kl,Lt,p);for(let g=0;g<Ps.length;g++)sn(t,Ps[g],ql,Wl,m);_n(Kl,{tld:!0,ascii:!0},e),_n(ql,{utld:!0,alpha:!0},e),sn(t,"file",ls,Lt,p),sn(t,"mailto",ls,Lt,p),sn(t,"http",lo,Lt,p),sn(t,"https",lo,Lt,p),sn(t,"ftp",lo,Lt,p),sn(t,"ftps",lo,Lt,p),_n(ls,{scheme:!0,ascii:!0},e),_n(lo,{slashscheme:!0,ascii:!0},e),n=n.sort((g,y)=>g[0]>y[0]?1:-1);for(let g=0;g<n.length;g++){const y=n[g][0],x=n[g][1]?{[r2]:!0}:{[s2]:!0};y.indexOf("-")>=0?x[jl]=!0:Vt.test(y)?$t.test(y)?x[Jo]=!0:x[Fl]=!0:x[zl]=!0,Sh(t,y,y,x)}return Sh(t,"localhost",Yo,{ascii:!0}),t.jd=new je(Ds),{start:t,tokens:Object.assign({groups:e},Mh)}}function Nh(n,e){const t=u2(e.replace(/[A-Z]/g,l=>l.toLowerCase())),o=t.length,r=[];let s=0,i=0;for(;i<o;){let l=n,c=null,d=0,u=null,f=-1,h=-1;for(;i<o&&(c=l.go(t[i]));)l=c,l.accepts()?(f=0,h=0,u=l):f>=0&&(f+=t[i].length,h++),d+=t[i].length,s+=t[i].length,i++;s-=f,i-=h,d-=f,r.push({t:u.t,v:e.slice(s-d,s),s:s-d,e:s})}return r}function u2(n){const e=[],t=n.length;let o=0;for(;o<t;){let r=n.charCodeAt(o),s,i=r<55296||r>56319||o+1===t||(s=n.charCodeAt(o+1))<56320||s>57343?n[o]:n.slice(o,o+2);e.push(i),o+=i.length}return e}function sn(n,e,t,o,r){let s;const i=e.length;for(let l=0;l<i-1;l++){const c=e[l];n.j[c]?s=n.j[c]:(s=new je(o),s.jr=r.slice(),n.j[c]=s),n=s}return s=new je(t),s.jr=r.slice(),n.j[e[i-1]]=s,s}function Ah(n){const e=[],t=[];let o=0,r="0123456789";for(;o<n.length;){let s=0;for(;r.indexOf(n[o+s])>=0;)s++;if(s>0){e.push(t.join(""));for(let i=parseInt(n.substring(o,o+s),10);i>0;i--)t.pop();o+=s}else t.push(n[o]),o++}return e}const or={defaultProtocol:"http",events:null,format:Bh,formatHref:Bh,nl2br:!1,tagName:"a",target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function sa(n,e=null){let t=Object.assign({},or);n&&(t=Object.assign(t,n instanceof sa?n.o:n));const o=t.ignoreTags,r=[];for(let s=0;s<o.length;s++)r.push(o[s].toUpperCase());this.o=t,e&&(this.defaultRender=e),this.ignoreTags=r}sa.prototype={o:or,ignoreTags:[],defaultRender(n){return n},check(n){return this.get("validate",n.toString(),n)},get(n,e,t){const o=e!=null;let r=this.o[n];return r&&(typeof r=="object"?(r=t.t in r?r[t.t]:or[n],typeof r=="function"&&o&&(r=r(e,t))):typeof r=="function"&&o&&(r=r(e,t.t,t)),r)},getObj(n,e,t){let o=this.o[n];return typeof o=="function"&&e!=null&&(o=o(e,t.t,t)),o},render(n){const e=n.render(this);return(this.get("render",null,n)||this.defaultRender)(e,n.t,n)}};function Bh(n){return n}function Ih(n,e){this.t="token",this.v=n,this.tk=e}Ih.prototype={isLink:!1,toString(){return this.v},toHref(n){return this.toString()},toFormattedString(n){const e=this.toString(),t=n.get("truncate",e,this),o=n.get("format",e,this);return t&&o.length>t?o.substring(0,t)+"…":o},toFormattedHref(n){return n.get("formatHref",this.toHref(n.get("defaultProtocol")),this)},startIndex(){return this.tk[0].s},endIndex(){return this.tk[this.tk.length-1].e},toObject(n=or.defaultProtocol){return{type:this.t,value:this.toString(),isLink:this.isLink,href:this.toHref(n),start:this.startIndex(),end:this.endIndex()}},toFormattedObject(n){return{type:this.t,value:this.toFormattedString(n),isLink:this.isLink,href:this.toFormattedHref(n),start:this.startIndex(),end:this.endIndex()}},validate(n){return n.get("validate",this.toString(),this)},render(n){const e=this,t=this.toHref(n.get("defaultProtocol")),o=n.get("formatHref",t,this),r=n.get("tagName",t,e),s=this.toFormattedString(n),i={},l=n.get("className",t,e),c=n.get("target",t,e),d=n.get("rel",t,e),u=n.getObj("attributes",t,e),f=n.getObj("events",t,e);return i.href=o,l&&(i.class=l),c&&(i.target=c),d&&(i.rel=d),u&&Object.assign(i,u),{tagName:r,attributes:i,content:s,eventListeners:f}}};function Ls(n,e){class t extends Ih{constructor(r,s){super(r,s),this.t=n}}for(const o in e)t.prototype[o]=e[o];return t.t=n,t}const Oh=Ls("email",{isLink:!0,toHref(){return"mailto:"+this.toString()}}),_h=Ls("text"),f2=Ls("nl"),Vs=Ls("url",{isLink:!0,toHref(n=or.defaultProtocol){return this.hasProtocol()?this.v:`${n}://${this.v}`},hasProtocol(){const n=this.tk;return n.length>=2&&n[0].t!==Yo&&n[1].t===rn}}),tt=n=>new je(n);function h2({groups:n}){const e=n.domain.concat([xs,Es,on,vs,Ms,Ts,Ns,As,et,Jl,Zo,Bs,Is,Os,yt,Ds,tr,_s]),t=[Cs,rn,Xl,gt,Ql,Zo,er,Zl,ea,fs,hs,Xo,Qo,cs,as,ds,us,ps,ms,gs,ys,ks,ws,bs,Ss],o=[xs,Cs,Es,vs,Ms,Ts,Ns,As,et,Xo,Qo,Zo,Bs,Is,Os,er,yt,Ds,tr,_s],r=tt(),s=V(r,tr);Z(s,o,s),Z(s,n.domain,s);const i=tt(),l=tt(),c=tt();Z(r,n.domain,i),Z(r,n.scheme,l),Z(r,n.slashscheme,c),Z(i,o,s),Z(i,n.domain,i);const d=V(i,on);V(s,on,d),V(l,on,d),V(c,on,d);const u=V(s,gt);Z(u,o,s),Z(u,n.domain,s);const f=tt();Z(d,n.domain,f),Z(f,n.domain,f);const h=V(f,gt);Z(h,n.domain,f);const p=tt(Oh);Z(h,n.tld,p),Z(h,n.utld,p),V(d,Yo,p);const m=V(f,et);V(m,et,m),Z(m,n.domain,f),Z(p,n.domain,f),V(p,gt,h),V(p,et,m);const g=V(p,rn);Z(g,n.numeric,Oh);const y=V(i,et),k=V(i,gt);V(y,et,y),Z(y,n.domain,i),Z(k,o,s),Z(k,n.domain,i);const x=tt(Vs);Z(k,n.tld,x),Z(k,n.utld,x),Z(x,n.domain,i),Z(x,o,s),V(x,gt,k),V(x,et,y),V(x,on,d);const b=V(x,rn),S=tt(Vs);Z(b,n.numeric,S);const C=tt(Vs),v=tt();Z(C,e,C),Z(C,t,v),Z(v,e,C),Z(v,t,v),V(x,yt,C),V(S,yt,C);const E=V(l,rn),M=V(c,rn),T=V(M,yt),A=V(T,yt);Z(l,n.domain,i),V(l,gt,k),V(l,et,y),Z(c,n.domain,i),V(c,gt,k),V(c,et,y),Z(E,n.domain,C),V(E,yt,C),V(E,er,C),Z(A,n.domain,C),Z(A,e,C),V(A,yt,C);const B=[[Xo,Qo],[as,cs],[ds,us],[fs,hs],[ps,ms],[gs,ys],[ks,ws],[bs,Ss]];for(let I=0;I<B.length;I++){const[O,z]=B[I],$=V(C,O);V(v,O,$),V($,z,C);const J=tt(Vs);Z($,e,J);const j=tt();Z($,t),Z(J,e,J),Z(J,t,j),Z(j,e,J),Z(j,t,j),V(J,z,C),V(j,z,C)}return V(r,Yo,x),V(r,Yl,f2),{start:r,tokens:Mh}}function p2(n,e,t){let o=t.length,r=0,s=[],i=[];for(;r<o;){let l=n,c=null,d=null,u=0,f=null,h=-1;for(;r<o&&!(c=l.go(t[r].t));)i.push(t[r++]);for(;r<o&&(d=c||l.go(t[r].t));)c=null,l=d,l.accepts()?(h=0,f=l):h>=0&&h++,r++,u++;if(h<0)r-=u,r<o&&(i.push(t[r]),r++);else{i.length>0&&(s.push(ia(_h,e,i)),i=[]),r-=h,u-=h;const p=f.t,m=t.slice(r-u,r);s.push(ia(p,e,m))}}return i.length>0&&s.push(ia(_h,e,i)),s}function ia(n,e,t){const o=t[0].s,r=t[t.length-1].e,s=e.slice(o,r);return new n(s,t)}const m2=typeof console<"u"&&console&&console.warn||(()=>{}),g2="until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.",ue={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function y2(){return je.groups={},ue.scanner=null,ue.parser=null,ue.tokenQueue=[],ue.pluginQueue=[],ue.customSchemes=[],ue.initialized=!1,ue}function Dh(n,e=!1){if(ue.initialized&&m2(`linkifyjs: already initialized - will not register custom scheme "${n}" ${g2}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(n))throw new Error(`linkifyjs: incorrect scheme format.
|
|
104
104
|
1. Must only contain digits, lowercase ASCII letters or "-"
|
|
105
105
|
2. Cannot start or end with "-"
|
|
106
|
-
3. "-" cannot repeat`);ue.customSchemes.push([n,e])}function k2(){ue.scanner=d2(ue.customSchemes);for(let n=0;n<ue.tokenQueue.length;n++)ue.tokenQueue[n][1]({scanner:ue.scanner});ue.parser=h2(ue.scanner.tokens);for(let n=0;n<ue.pluginQueue.length;n++)ue.pluginQueue[n][1]({scanner:ue.scanner,parser:ue.parser});return ue.initialized=!0,ue}function la(n){return ue.initialized||k2(),p2(ue.parser.start,n,Nh(ue.scanner.start,n))}la.scan=Nh;function Rh(n,e=null,t=null){if(e&&typeof e=="object"){if(t)throw Error(`linkifyjs: Invalid link type ${e}; must be a string`);t=e,e=null}const o=new sa(t),r=la(n),s=[];for(let i=0;i<r.length;i++){const l=r[i];l.isLink&&(!e||l.t===e)&&o.check(l)&&s.push(l.toFormattedObject(o))}return s}var aa="[\0- -\u2029 ]",w2=new RegExp(aa),b2=new RegExp(`${aa}$`),S2=new RegExp(aa,"g");function x2(n){return n.length===1?n[0].isLink:n.length===3&&n[1].isLink?["()","[]"].includes(n[0].value+n[2].value):!1}function C2(n){return new pe({key:new Ce("autolink"),appendTransaction:(e,t,o)=>{const r=e.some(d=>d.docChanged)&&!t.doc.eq(o.doc),s=e.some(d=>d.getMeta("preventAutolink"));if(!r||s)return;const{tr:i}=o,l=Lf(t.doc,[...e]);if(Jf(l).forEach(({newRange:d})=>{const u=Iw(o.doc,d,p=>p.isTextblock);let f,h;if(u.length>1)f=u[0],h=o.doc.textBetween(f.pos,f.pos+f.node.nodeSize,void 0," ");else if(u.length){const p=o.doc.textBetween(d.from,d.to," "," ");if(!b2.test(p))return;f=u[0],h=o.doc.textBetween(f.pos,d.to,void 0," ")}if(f&&h){const p=h.split(w2).filter(Boolean);if(p.length<=0)return!1;const m=p[p.length-1],g=f.pos+h.lastIndexOf(m);if(!m)return!1;const y=la(m).map(k=>k.toObject(n.defaultProtocol));if(!x2(y))return!1;y.filter(k=>k.isLink).map(k=>({...k,from:g+k.start+1,to:g+k.end+1})).filter(k=>o.schema.marks.code?!o.doc.rangeHasMark(k.from,k.to,o.schema.marks.code):!0).filter(k=>n.validate(k.value)).filter(k=>n.shouldAutoLink(k.value)).forEach(k=>{Ol(k.from,k.to,o.doc).some(x=>x.mark.type===n.type)||i.addMark(k.from,k.to,n.type.create({href:k.href}))})}}),!!i.steps.length)return i}})}function E2(n){return new pe({key:new Ce("handleClickLink"),props:{handleClick:(e,t,o)=>{var r,s;if(o.button!==0||!e.editable)return!1;let i=null;if(o.target instanceof HTMLAnchorElement)i=o.target;else{const c=o.target;if(!c)return!1;const d=n.editor.view.dom;i=c.closest("a"),i&&!d.contains(i)&&(i=null)}if(!i)return!1;let l=!1;if(n.enableClickSelection&&(l=n.editor.commands.extendMarkRange(n.type.name)),n.openOnClick){const c=qf(e.state,n.type.name),d=(r=i.href)!=null?r:c.href,u=(s=i.target)!=null?s:c.target;d&&(window.open(d,u),l=!0)}return l}}})}function v2(n){return new pe({key:new Ce("handlePasteLink"),props:{handlePaste:(e,t,o)=>{const{shouldAutoLink:r}=n,{state:s}=e,{selection:i}=s,{empty:l}=i;if(l)return!1;let c="";o.content.forEach(u=>{c+=u.textContent});const d=Rh(c,{defaultProtocol:n.defaultProtocol}).find(u=>u.isLink&&u.value===c);return!c||!d||r!==void 0&&!r(d.value)?!1:n.editor.commands.setMark(n.type,{href:d.href})}}})}function Dn(n,e){const t=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"];return e&&e.forEach(o=>{const r=typeof o=="string"?o:o.scheme;r&&t.push(r)}),!n||n.replace(S2,"").match(new RegExp(`^(?:(?:${t.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}var M2=io.create({name:"link",priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(n=>{if(typeof n=="string"){Dh(n);return}Dh(n.scheme,n.optionalSlashes)})},onDestroy(){y2()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:"http",HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},isAllowedUri:(n,e)=>!!Dn(n,e.protocols),validate:n=>!!n,shouldAutoLink:n=>{const e=/^[a-z][a-z0-9+.-]*:\/\//i.test(n),t=/^[a-z][a-z0-9+.-]*:/i.test(n);if(e||t&&!n.includes("@"))return!0;const r=(n.includes("@")?n.split("@").pop():n).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(n){return n.getAttribute("href")}},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class},title:{default:null}}},parseHTML(){return[{tag:"a[href]",getAttrs:n=>{const e=n.getAttribute("href");return!e||!this.options.isAllowedUri(e,{defaultValidate:t=>!!Dn(t,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:n}){return this.options.isAllowedUri(n.href,{defaultValidate:e=>!!Dn(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",nn(this.options.HTMLAttributes,n),0]:["a",nn(this.options.HTMLAttributes,{...n,href:""}),0]},markdownTokenName:"link",parseMarkdown:(n,e)=>e.applyMark("link",e.parseInline(n.tokens||[]),{href:n.href,title:n.title||null}),renderMarkdown:(n,e)=>{var t,o,r,s;const i=(o=(t=n.attrs)==null?void 0:t.href)!=null?o:"",l=(s=(r=n.attrs)==null?void 0:r.title)!=null?s:"",c=e.renderChildren(n);return l?`[${c}](${i} "${l}")`:`[${c}](${i})`},addCommands(){return{setLink:n=>({chain:e})=>{const{href:t}=n;return this.options.isAllowedUri(t,{defaultValidate:o=>!!Dn(o,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?e().setMark(this.name,n).setMeta("preventAutolink",!0).run():!1},toggleLink:n=>({chain:e})=>{const{href:t}=n||{};return t&&!this.options.isAllowedUri(t,{defaultValidate:o=>!!Dn(o,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:e().toggleMark(this.name,n,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()},unsetLink:()=>({chain:n})=>n().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addPasteRules(){return[qo({find:n=>{const e=[];if(n){const{protocols:t,defaultProtocol:o}=this.options,r=Rh(n).filter(s=>s.isLink&&this.options.isAllowedUri(s.value,{defaultValidate:i=>!!Dn(i,t),protocols:t,defaultProtocol:o}));r.length&&r.forEach(s=>{this.options.shouldAutoLink(s.value)&&e.push({text:s.value,data:{href:s.href},index:s.start})})}return e},type:this.type,getAttributes:n=>{var e;return{href:(e=n.data)==null?void 0:e.href}}})]},addProseMirrorPlugins(){const n=[],{protocols:e,defaultProtocol:t}=this.options;return this.options.autolink&&n.push(C2({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:o=>this.options.isAllowedUri(o,{defaultValidate:r=>!!Dn(r,e),protocols:e,defaultProtocol:t}),shouldAutoLink:this.options.shouldAutoLink})),n.push(E2({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick==="whenNotEditable"?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&n.push(v2({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),n}}),Ph=M2,T2=de.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:n=>{const e=n.style.textAlign;return this.options.alignments.includes(e)?e:this.options.defaultAlignment},renderHTML:n=>n.textAlign?{style:`text-align: ${n.textAlign}`}:{}}}}]},addCommands(){return{setTextAlign:n=>({commands:e})=>this.options.alignments.includes(n)?this.options.types.map(t=>e.updateAttributes(t,{textAlign:n})).some(t=>t):!1,unsetTextAlign:()=>({commands:n})=>this.options.types.map(e=>n.resetAttributes(e,"textAlign")).some(e=>e),toggleTextAlign:n=>({editor:e,commands:t})=>this.options.alignments.includes(n)?e.isActive({textAlign:n})?t.unsetTextAlign():t.setTextAlign(n):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),Lh=T2,N2=20,Vh=(n,e=0)=>{const t=[];return!n.children.length||e>N2||Array.from(n.children).forEach(o=>{o.tagName==="SPAN"?t.push(o):o.children.length&&t.push(...Vh(o,e+1))}),t},A2=n=>{if(!n.children.length)return;const e=Vh(n);e&&e.forEach(t=>{var o,r;const s=t.getAttribute("style"),i=(r=(o=t.parentElement)==null?void 0:o.closest("span"))==null?void 0:r.getAttribute("style");t.setAttribute("style",`${i};${s}`)})},ca=io.create({name:"textStyle",priority:101,addOptions(){return{HTMLAttributes:{},mergeNestedSpanStyles:!0}},parseHTML(){return[{tag:"span",consuming:!1,getAttrs:n=>n.hasAttribute("style")?(this.options.mergeNestedSpanStyles&&A2(n),{}):!1}]},renderHTML({HTMLAttributes:n}){return["span",nn(this.options.HTMLAttributes,n),0]},addCommands(){return{toggleTextStyle:n=>({commands:e})=>e.toggleMark(this.name,n),removeEmptyTextStyle:()=>({tr:n})=>{const{selection:e}=n;return n.doc.nodesBetween(e.from,e.to,(t,o)=>{if(t.isTextblock)return!0;t.marks.filter(r=>r.type===this.type).some(r=>Object.values(r.attrs).some(s=>!!s))||n.removeMark(o,o+t.nodeSize,this.type)}),!0}}}}),B2=de.create({name:"backgroundColor",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{backgroundColor:{default:null,parseHTML:n=>{var e;const t=n.getAttribute("style");if(t){const o=t.split(";").map(r=>r.trim()).filter(Boolean);for(let r=o.length-1;r>=0;r-=1){const s=o[r].split(":");if(s.length>=2){const i=s[0].trim().toLowerCase(),l=s.slice(1).join(":").trim();if(i==="background-color")return l.replace(/['"]+/g,"")}}}return(e=n.style.backgroundColor)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:n=>n.backgroundColor?{style:`background-color: ${n.backgroundColor}`}:{}}}}]},addCommands(){return{setBackgroundColor:n=>({chain:e})=>e().setMark("textStyle",{backgroundColor:n}).run(),unsetBackgroundColor:()=>({chain:n})=>n().setMark("textStyle",{backgroundColor:null}).removeEmptyTextStyle().run()}}}),$h=de.create({name:"color",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:n=>{var e;const t=n.getAttribute("style");if(t){const o=t.split(";").map(r=>r.trim()).filter(Boolean);for(let r=o.length-1;r>=0;r-=1){const s=o[r].split(":");if(s.length>=2){const i=s[0].trim().toLowerCase(),l=s.slice(1).join(":").trim();if(i==="color")return l.replace(/['"]+/g,"")}}}return(e=n.style.color)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:n=>n.color?{style:`color: ${n.color}`}:{}}}}]},addCommands(){return{setColor:n=>({chain:e})=>e().setMark("textStyle",{color:n}).run(),unsetColor:()=>({chain:n})=>n().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()}}}),I2=de.create({name:"fontFamily",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontFamily:{default:null,parseHTML:n=>n.style.fontFamily,renderHTML:n=>n.fontFamily?{style:`font-family: ${n.fontFamily}`}:{}}}}]},addCommands(){return{setFontFamily:n=>({chain:e})=>e().setMark("textStyle",{fontFamily:n}).run(),unsetFontFamily:()=>({chain:n})=>n().setMark("textStyle",{fontFamily:null}).removeEmptyTextStyle().run()}}}),O2=de.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:n=>n.style.fontSize,renderHTML:n=>n.fontSize?{style:`font-size: ${n.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:n=>({chain:e})=>e().setMark("textStyle",{fontSize:n}).run(),unsetFontSize:()=>({chain:n})=>n().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),_2=de.create({name:"lineHeight",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{lineHeight:{default:null,parseHTML:n=>n.style.lineHeight,renderHTML:n=>n.lineHeight?{style:`line-height: ${n.lineHeight}`}:{}}}}]},addCommands(){return{setLineHeight:n=>({chain:e})=>e().setMark("textStyle",{lineHeight:n}).run(),unsetLineHeight:()=>({chain:n})=>n().setMark("textStyle",{lineHeight:null}).removeEmptyTextStyle().run()}}});de.create({name:"textStyleKit",addExtensions(){const n=[];return this.options.backgroundColor!==!1&&n.push(B2.configure(this.options.backgroundColor)),this.options.color!==!1&&n.push($h.configure(this.options.color)),this.options.fontFamily!==!1&&n.push(I2.configure(this.options.fontFamily)),this.options.fontSize!==!1&&n.push(O2.configure(this.options.fontSize)),this.options.lineHeight!==!1&&n.push(_2.configure(this.options.lineHeight)),this.options.textStyle!==!1&&n.push(ca.configure(this.options.textStyle)),n}});var zh=$h;function D2(n={}){return new pe({view(e){return new R2(e,n)}})}class R2{constructor(e,t){var o;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(o=t.width)!==null&&o!==void 0?o:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(r=>{let s=i=>{this[r](i)};return e.dom.addEventListener(r,s),{name:r,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,o,r=this.editorView.dom,s=r.getBoundingClientRect(),i=s.width/r.offsetWidth,l=s.height/r.offsetHeight;if(t){let f=e.nodeBefore,h=e.nodeAfter;if(f||h){let p=this.editorView.nodeDOM(this.cursorPos-(f?f.nodeSize:0));if(p){let m=p.getBoundingClientRect(),g=f?m.bottom:m.top;f&&h&&(g=(g+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let y=this.width/2*l;o={left:m.left,right:m.right,top:g-y,bottom:g+y}}}}if(!o){let f=this.editorView.coordsAtPos(this.cursorPos),h=this.width/2*i;o={left:f.left-h,right:f.left+h,top:f.top,bottom:f.bottom}}let c=this.editorView.dom.offsetParent;this.element||(this.element=c.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let d,u;if(!c||c==document.body&&getComputedStyle(c).position=="static")d=-pageXOffset,u=-pageYOffset;else{let f=c.getBoundingClientRect(),h=f.width/c.offsetWidth,p=f.height/c.offsetHeight;d=f.left-c.scrollLeft*h,u=f.top-c.scrollTop*p}this.element.style.left=(o.left-d)/i+"px",this.element.style.top=(o.top-u)/l+"px",this.element.style.width=(o.right-o.left)/i+"px",this.element.style.height=(o.bottom-o.top)/l+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),o=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=o&&o.type.spec.disableDropCursor,s=typeof r=="function"?r(this.editorView,t,e):r;if(t&&!s){let i=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=Vd(this.editorView.state.doc,i,this.editorView.dragging.slice);l!=null&&(i=l)}this.setCursor(i),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class ge extends ee{constructor(e){super(e,e)}map(e,t){let o=e.resolve(t.map(this.head));return ge.valid(o)?new ge(o):ee.near(o)}content(){return U.empty}eq(e){return e instanceof ge&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new ge(e.resolve(t.pos))}getBookmark(){return new da(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!P2(e)||!L2(e))return!1;let o=t.type.spec.allowGapCursor;if(o!=null)return o;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(e,t,o=!1){e:for(;;){if(!o&&ge.valid(e))return e;let r=e.pos,s=null;for(let i=e.depth;;i--){let l=e.node(i);if(t>0?e.indexAfter(i)<l.childCount:e.index(i)>0){s=l.child(t>0?e.indexAfter(i):e.index(i)-1);break}else if(i==0)return null;r+=t;let c=e.doc.resolve(r);if(ge.valid(c))return c}for(;;){let i=t>0?s.firstChild:s.lastChild;if(!i){if(s.isAtom&&!s.isText&&!Y.isSelectable(s)){e=e.doc.resolve(r+s.nodeSize*t),o=!1;continue e}break}s=i,r+=t;let l=e.doc.resolve(r);if(ge.valid(l))return l}return null}}}ge.prototype.visible=!1,ge.findFrom=ge.findGapCursorFrom,ee.jsonID("gapcursor",ge);class da{constructor(e){this.pos=e}map(e){return new da(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return ge.valid(t)?new ge(t):ee.near(t)}}function Fh(n){return n.isAtom||n.spec.isolating||n.spec.createGapCursor}function P2(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),o=n.node(e);if(t==0){if(o.type.spec.isolating)return!0;continue}for(let r=o.child(t-1);;r=r.lastChild){if(r.childCount==0&&!r.inlineContent||Fh(r.type))return!0;if(r.inlineContent)return!1}}return!0}function L2(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),o=n.node(e);if(t==o.childCount){if(o.type.spec.isolating)return!0;continue}for(let r=o.child(t);;r=r.firstChild){if(r.childCount==0&&!r.inlineContent||Fh(r.type))return!0;if(r.inlineContent)return!1}}return!0}function V2(){return new pe({props:{decorations:H2,createSelectionBetween(n,e,t){return e.pos==t.pos&&ge.valid(t)?new ge(t):null},handleClick:z2,handleKeyDown:$2,handleDOMEvents:{beforeinput:F2}}})}const $2=Mf({ArrowLeft:$s("horiz",-1),ArrowRight:$s("horiz",1),ArrowUp:$s("vert",-1),ArrowDown:$s("vert",1)});function $s(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(o,r,s){let i=o.selection,l=e>0?i.$to:i.$from,c=i.empty;if(i instanceof Q){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=o.doc.resolve(e>0?l.after():l.before())}let d=ge.findGapCursorFrom(l,e,c);return d?(r&&r(o.tr.setSelection(new ge(d))),!0):!1}}function z2(n,e,t){if(!n||!n.editable)return!1;let o=n.state.doc.resolve(e);if(!ge.valid(o))return!1;let r=n.posAtCoords({left:t.clientX,top:t.clientY});return r&&r.inside>-1&&Y.isSelectable(n.state.doc.nodeAt(r.inside))?!1:(n.dispatch(n.state.tr.setSelection(new ge(o))),!0)}function F2(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof ge))return!1;let{$from:t}=n.state.selection,o=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!o)return!1;let r=P.empty;for(let i=o.length-1;i>=0;i--)r=P.from(o[i].createAndFill(null,r));let s=n.state.tr.replace(t.pos,t.pos,new U(r,0,0));return s.setSelection(Q.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function H2(n){if(!(n.selection instanceof ge))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",he.create(n.doc,[Fe.widget(n.selection.head,e,{key:"gapcursor"})])}var zs=200,ve=function(){};ve.prototype.append=function(e){return e.length?(e=ve.from(e),!this.length&&e||e.length<zs&&this.leafAppend(e)||this.length<zs&&e.leafPrepend(this)||this.appendInner(e)):this},ve.prototype.prepend=function(e){return e.length?ve.from(e).append(this):this},ve.prototype.appendInner=function(e){return new j2(this,e)},ve.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?ve.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},ve.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},ve.prototype.forEach=function(e,t,o){t===void 0&&(t=0),o===void 0&&(o=this.length),t<=o?this.forEachInner(e,t,o,0):this.forEachInvertedInner(e,t,o,0)},ve.prototype.map=function(e,t,o){t===void 0&&(t=0),o===void 0&&(o=this.length);var r=[];return this.forEach(function(s,i){return r.push(e(s,i))},t,o),r},ve.from=function(e){return e instanceof ve?e:e&&e.length?new Hh(e):ve.empty};var Hh=function(n){function e(o){n.call(this),this.values=o}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(r,s){return r==0&&s==this.length?this:new e(this.values.slice(r,s))},e.prototype.getInner=function(r){return this.values[r]},e.prototype.forEachInner=function(r,s,i,l){for(var c=s;c<i;c++)if(r(this.values[c],l+c)===!1)return!1},e.prototype.forEachInvertedInner=function(r,s,i,l){for(var c=s-1;c>=i;c--)if(r(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(r){if(this.length+r.length<=zs)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=zs)return new e(r.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(ve);ve.empty=new Hh([]);var j2=function(n){function e(t,o){n.call(this),this.left=t,this.right=o,this.length=t.length+o.length,this.depth=Math.max(t.depth,o.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(o){return o<this.left.length?this.left.get(o):this.right.get(o-this.left.length)},e.prototype.forEachInner=function(o,r,s,i){var l=this.left.length;if(r<l&&this.left.forEachInner(o,r,Math.min(s,l),i)===!1||s>l&&this.right.forEachInner(o,Math.max(r-l,0),Math.min(this.length,s)-l,i+l)===!1)return!1},e.prototype.forEachInvertedInner=function(o,r,s,i){var l=this.left.length;if(r>l&&this.right.forEachInvertedInner(o,r-l,Math.max(s,l)-l,i+l)===!1||s<l&&this.left.forEachInvertedInner(o,Math.min(r,l),s,i)===!1)return!1},e.prototype.sliceInner=function(o,r){if(o==0&&r==this.length)return this;var s=this.left.length;return r<=s?this.left.slice(o,r):o>=s?this.right.slice(o-s,r-s):this.left.slice(o,s).append(this.right.slice(0,r-s))},e.prototype.leafAppend=function(o){var r=this.right.leafAppend(o);if(r)return new e(this.left,r)},e.prototype.leafPrepend=function(o){var r=this.left.leafPrepend(o);if(r)return new e(r,this.right)},e.prototype.appendInner=function(o){return this.left.depth>=Math.max(this.right.depth,o.depth)+1?new e(this.left,new e(this.right,o)):new e(this,o)},e}(ve);const U2=500;class st{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let o=this.items.length;for(;;o--)if(this.items.get(o-1).selection){--o;break}let r,s;t&&(r=this.remapping(o,this.items.length),s=r.maps.length);let i=e.tr,l,c,d=[],u=[];return this.items.forEach((f,h)=>{if(!f.step){r||(r=this.remapping(o,h+1),s=r.maps.length),s--,u.push(f);return}if(r){u.push(new kt(f.map));let p=f.step.map(r.slice(s)),m;p&&i.maybeStep(p).doc&&(m=i.mapping.maps[i.mapping.maps.length-1],d.push(new kt(m,void 0,void 0,d.length+u.length))),s--,m&&r.appendMap(m,s)}else i.maybeStep(f.step);if(f.selection)return l=r?f.selection.map(r.slice(s)):f.selection,c=new st(this.items.slice(0,o).append(u.reverse().concat(d)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:i,selection:l}}addTransform(e,t,o,r){let s=[],i=this.eventCount,l=this.items,c=!r&&l.length?l.get(l.length-1):null;for(let u=0;u<e.steps.length;u++){let f=e.steps[u].invert(e.docs[u]),h=new kt(e.mapping.maps[u],f,t),p;(p=c&&c.merge(h))&&(h=p,u?s.pop():l=l.slice(0,l.length-1)),s.push(h),t&&(i++,t=void 0),r||(c=h)}let d=i-o.depth;return d>K2&&(l=W2(l,d),i-=d),new st(l.append(s),i)}remapping(e,t){let o=new No;return this.items.forEach((r,s)=>{let i=r.mirrorOffset!=null&&s-r.mirrorOffset>=e?o.maps.length-r.mirrorOffset:void 0;o.appendMap(r.map,i)},e,t),o}addMaps(e){return this.eventCount==0?this:new st(this.items.append(e.map(t=>new kt(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let o=[],r=Math.max(0,this.items.length-t),s=e.mapping,i=e.steps.length,l=this.eventCount;this.items.forEach(h=>{h.selection&&l--},r);let c=t;this.items.forEach(h=>{let p=s.getMirror(--c);if(p==null)return;i=Math.min(i,p);let m=s.maps[p];if(h.step){let g=e.steps[p].invert(e.docs[p]),y=h.selection&&h.selection.map(s.slice(c+1,p));y&&l++,o.push(new kt(m,g,y))}else o.push(new kt(m))},r);let d=[];for(let h=t;h<i;h++)d.push(new kt(s.maps[h]));let u=this.items.slice(0,r).append(d).append(o),f=new st(u,l);return f.emptyItemCount()>U2&&(f=f.compress(this.items.length-o.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),o=t.maps.length,r=[],s=0;return this.items.forEach((i,l)=>{if(l>=e)r.push(i),i.selection&&s++;else if(i.step){let c=i.step.map(t.slice(o)),d=c&&c.getMap();if(o--,d&&t.appendMap(d,o),c){let u=i.selection&&i.selection.map(t.slice(o));u&&s++;let f=new kt(d.invert(),c,u),h,p=r.length-1;(h=r.length&&r[p].merge(f))?r[p]=h:r.push(f)}}else i.map&&o--},this.items.length,0),new st(ve.from(r.reverse()),s)}}st.empty=new st(ve.empty,0);function W2(n,e){let t;return n.forEach((o,r)=>{if(o.selection&&e--==0)return t=r,!1}),n.slice(t)}class kt{constructor(e,t,o,r){this.map=e,this.step=t,this.selection=o,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new kt(t.getMap().invert(),t,this.selection)}}}class ln{constructor(e,t,o,r,s){this.done=e,this.undone=t,this.prevRanges=o,this.prevTime=r,this.prevComposition=s}}const K2=20;function q2(n,e,t,o){let r=t.getMeta(Rn),s;if(r)return r.historyState;t.getMeta(Y2)&&(n=new ln(n.done,n.undone,null,0,-1));let i=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(i&&i.getMeta(Rn))return i.getMeta(Rn).redo?new ln(n.done.addTransform(t,void 0,o,Fs(e)),n.undone,jh(t.mapping.maps),n.prevTime,n.prevComposition):new ln(n.done,n.undone.addTransform(t,void 0,o,Fs(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(i&&i.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),c=n.prevTime==0||!i&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-o.newGroupDelay||!J2(t,n.prevRanges)),d=i?ua(n.prevRanges,t.mapping):jh(t.mapping.maps);return new ln(n.done.addTransform(t,c?e.selection.getBookmark():void 0,o,Fs(e)),st.empty,d,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new ln(n.done.rebased(t,s),n.undone.rebased(t,s),ua(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new ln(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),ua(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function J2(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((o,r)=>{for(let s=0;s<e.length;s+=2)o<=e[s+1]&&r>=e[s]&&(t=!0)}),t}function jh(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((o,r,s,i)=>e.push(s,i));return e}function ua(n,e){if(!n)return null;let t=[];for(let o=0;o<n.length;o+=2){let r=e.map(n[o],1),s=e.map(n[o+1],-1);r<=s&&t.push(r,s)}return t}function G2(n,e,t){let o=Fs(e),r=Rn.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,o);if(!s)return null;let i=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),r,o),c=new ln(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(i).setMeta(Rn,{redo:t,historyState:c})}let fa=!1,Uh=null;function Fs(n){let e=n.plugins;if(Uh!=e){fa=!1,Uh=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){fa=!0;break}}return fa}const Rn=new Ce("history"),Y2=new Ce("closeHistory");function X2(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new pe({key:Rn,state:{init(){return new ln(st.empty,st.empty,null,0,-1)},apply(e,t,o){return q2(t,o,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let o=t.inputType,r=o=="historyUndo"?Kh:o=="historyRedo"?qh:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function Wh(n,e){return(t,o)=>{let r=Rn.getState(t);if(!r||(n?r.undone:r.done).eventCount==0)return!1;if(o){let s=G2(r,t,n);s&&o(e?s.scrollIntoView():s)}return!0}}const Kh=Wh(!1,!0),qh=Wh(!0,!0);de.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:n=>n.length,wordCounter:n=>n.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=n=>{const e=(n==null?void 0:n.node)||this.editor.state.doc;if(((n==null?void 0:n.mode)||this.options.mode)==="textSize"){const o=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(o)}return e.nodeSize},this.storage.words=n=>{const e=(n==null?void 0:n.node)||this.editor.state.doc,t=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(t)}},addProseMirrorPlugins(){let n=!1;return[new pe({key:new Ce("characterCount"),appendTransaction:(e,t,o)=>{if(n)return;const r=this.options.limit;if(r==null||r===0){n=!0;return}const s=this.storage.characters({node:o.doc});if(s>r){const i=s-r,l=0,c=i;console.warn(`[CharacterCount] Initial content exceeded limit of ${r} characters. Content was automatically trimmed.`);const d=o.tr.deleteRange(l,c);return n=!0,d}n=!0},filterTransaction:(e,t)=>{const o=this.options.limit;if(!e.docChanged||o===0||o===null||o===void 0)return!0;const r=this.storage.characters({node:t.doc}),s=this.storage.characters({node:e.doc});if(s<=o||r>o&&s>o&&s<=r)return!0;if(r>o&&s>o&&s>r||!e.getMeta("paste"))return!1;const l=e.selection.$head.pos,c=s-o,d=l-c,u=l;return e.deleteRange(d,u),!(this.storage.characters({node:e.doc})>o)}})]}}),de.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[D2(this.options)]}}),de.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new pe({key:new Ce("focus"),props:{decorations:({doc:n,selection:e})=>{const{isEditable:t,isFocused:o}=this.editor,{anchor:r}=e,s=[];if(!t||!o)return he.create(n,[]);let i=0;this.options.mode==="deepest"&&n.descendants((c,d)=>{if(c.isText)return;if(!(r>=d&&r<=d+c.nodeSize-1))return!1;i+=1});let l=0;return n.descendants((c,d)=>{if(c.isText||!(r>=d&&r<=d+c.nodeSize-1))return!1;if(l+=1,this.options.mode==="deepest"&&i-l>0||this.options.mode==="shallowest"&&l>1)return this.options.mode==="deepest";s.push(Fe.node(d,d+c.nodeSize,{class:this.options.className}))}),he.create(n,s)}}})]}}),de.create({name:"gapCursor",addProseMirrorPlugins(){return[V2()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=ae(q(n,"allowGapCursor",t)))!=null?e:null}}});var Jh="placeholder";function Q2(n){return n.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}de.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:Jh,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){const n=this.options.dataAttribute?`data-${Q2(this.options.dataAttribute)}`:`data-${Jh}`;return[new pe({key:new Ce("placeholder"),props:{decorations:({doc:e,selection:t})=>{const o=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=t,s=[];if(!o)return null;const i=this.editor.isEmpty;return e.descendants((l,c)=>{const d=r>=c&&r<=c+l.nodeSize,u=!l.isLeaf&&es(l);if((d||!this.options.showOnlyCurrent)&&u){const f=[this.options.emptyNodeClass];i&&f.push(this.options.emptyEditorClass);const h=Fe.node(c,c+l.nodeSize,{class:f.join(" "),[n]:typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:l,pos:c,hasAnchor:d}):this.options.placeholder});s.push(h)}return this.options.includeChildren}),he.create(e,s)}}})]}}),de.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:n,options:e}=this;return[new pe({key:new Ce("selection"),props:{decorations(t){return t.selection.empty||n.isFocused||!n.isEditable||Uw(t.selection)||n.view.dragging?null:he.create(t.doc,[Fe.inline(t.selection.from,t.selection.to,{class:e.className})])}}})]}});function Gh({types:n,node:e}){return e&&Array.isArray(n)&&n.includes(e.type)||(e==null?void 0:e.type)===n}de.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var n;const e=new Ce(this.name),t=this.options.node||((n=this.editor.schema.topNodeType.contentMatch.defaultType)==null?void 0:n.name)||"paragraph",o=Object.entries(this.editor.schema.nodes).map(([,r])=>r).filter(r=>(this.options.notAfter||[]).concat(t).includes(r.name));return[new pe({key:e,appendTransaction:(r,s,i)=>{const{doc:l,tr:c,schema:d}=i,u=e.getState(i),f=l.content.size,h=d.nodes[t];if(u)return c.insert(f,h.create())},state:{init:(r,s)=>{const i=s.tr.doc.lastChild;return!Gh({node:i,types:o})},apply:(r,s)=>{if(!r.docChanged||r.getMeta("__uniqueIDTransaction"))return s;const i=r.doc.lastChild;return!Gh({node:i,types:o})}}})]}});var Z2=de.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>Kh(n,e),redo:()=>({state:n,dispatch:e})=>qh(n,e)}},addProseMirrorPlugins(){return[X2(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}});const an="editing",ha=50,Hs=1e3;function Yh(n,e){if(!e)return n;let t=null;for(const o of Object.keys(n)){if(o==="block")continue;const r=e(o);!r||Object.keys(r).length===0||(t??(t={...n}),t[o]={...r,...n[o]})}return t??n}function pa(n){var e;if(!n)return null;try{const t=JSON.parse(n);return(e=t.block)!=null&&e.tag?t:(console.warn("Block snapshot missing required tag:",t),null)}catch{return console.warn("Invalid block snapshot JSON:",n),null}}function rr(n,e,t){const o=w.getBlockDef(n,e.block.tag);if(!o)throw new Error(`Block placement: block definition for tag "${e.block.tag}" not found`);const r=e.block.size??[100,100],s=[t[0]-r[0]/2,t[1]-r[1]/2];w.Grid.snapPosition(n,s);const[i,l]=s,c=e.block.rank??w.RankBounds.genNext(n),d=w.createEntity(n);"synced"in e||w.addComponent(n,d,w.Synced,{id:crypto.randomUUID()});const u=Object.assign({},e.block,{position:[i,l],size:r,rank:c});w.addComponent(n,d,w.Block,u);for(const f of o.components)if(!(f.name in e))w.addComponent(n,d,f);else{const h=e[f.name];w.addComponent(n,d,f,h)}return d}function eS(n){return n.trimEnd().split(/\r?\n/).map(e=>`<p>${e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")||""}</p>`).join("")}function Xh(n){if(n.startsWith("#"))return n.toUpperCase();const e=n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(e){const t=parseInt(e[1],10).toString(16).padStart(2,"0"),o=parseInt(e[2],10).toString(16).padStart(2,"0"),r=parseInt(e[3],10).toString(16).padStart(2,"0");return`#${t}${o}${r}`.toUpperCase()}return n}function sr(n){const e=Math.round(n.red),t=Math.round(n.green),o=Math.round(n.blue),r=Math.round(n.alpha);return r<255?"#"+[e,t,o,r].map(s=>{const i=s.toString(16);return i.length===1?`0${i}`:i}).join(""):"#"+[e,t,o].map(s=>{const i=s.toString(16);return i.length===1?`0${i}`:i}).join("")}function ma(n){n=n.replace(/^#/,"");let e,t,o,r=255;if(n.length===6)e=parseInt(n.slice(0,2),16),t=parseInt(n.slice(2,4),16),o=parseInt(n.slice(4,6),16);else if(n.length===8)e=parseInt(n.slice(0,2),16),t=parseInt(n.slice(2,4),16),o=parseInt(n.slice(4,6),16),r=parseInt(n.slice(6,8),16);else return null;return{red:e,green:t,blue:o,alpha:r}}function Qh(n){const e=ma(n);if(!e)return{h:0,s:100,v:100,a:255};const t=e.red/255,o=e.green/255,r=e.blue/255,s=Math.max(t,o,r),i=Math.min(t,o,r),l=s-i;let c=0;const d=s===0?0:l/s*100,u=s*100;if(l!==0)switch(s){case t:c=((o-r)/l+(o<r?6:0))*60;break;case o:c=((r-t)/l+2)*60;break;case r:c=((t-o)/l+4)*60;break}return{h:c,s:d,v:u,a:e.alpha}}function Zh(n){const e=n.h/360,t=n.s/100,o=n.v/100;let r=0,s=0,i=0;const l=Math.floor(e*6),c=e*6-l,d=o*(1-t),u=o*(1-c*t),f=o*(1-(1-c)*t);switch(l%6){case 0:r=o,s=f,i=d;break;case 1:r=u,s=o,i=d;break;case 2:r=d,s=o,i=f;break;case 3:r=d,s=u,i=o;break;case 4:r=f,s=d,i=o;break;case 5:r=o,s=d,i=u;break}const h=p=>Math.round(p*255).toString(16).padStart(2,"0");return`#${h(r)}${h(s)}${h(i)}`}function ep(n){const e=n.h/360,t=n.s/100,o=n.v/100;let r=0,s=0,i=0;const l=Math.floor(e*6),c=e*6-l,d=o*(1-t),u=o*(1-c*t),f=o*(1-(1-c)*t);switch(l%6){case 0:r=o,s=f,i=d;break;case 1:r=u,s=o,i=d;break;case 2:r=d,s=o,i=f;break;case 3:r=d,s=u,i=o;break;case 4:r=f,s=d,i=o;break;case 5:r=o,s=d,i=u;break}const h=m=>Math.round(m*255).toString(16).padStart(2,"0"),p=Math.round(n.a).toString(16).padStart(2,"0");return n.a<255?`#${h(r)}${h(s)}${h(i)}${p}`:`#${h(r)}${h(s)}${h(i)}`}const ke=a.shallowRef(null),ga=a.shallowRef(null),ya=a.shallowRef(null),it=a.ref(0);function Pn(){const n={hasEditor:a.computed(()=>ke.value!==null),isBold:a.computed(()=>{var i;return it.value,((i=ke.value)==null?void 0:i.isActive("bold"))??!1}),isItalic:a.computed(()=>{var i;return it.value,((i=ke.value)==null?void 0:i.isActive("italic"))??!1}),isUnderline:a.computed(()=>{var i;return it.value,((i=ke.value)==null?void 0:i.isActive("underline"))??!1}),alignment:a.computed(()=>{it.value;const i=ke.value;return i?i.isActive({textAlign:"center"})?"center":i.isActive({textAlign:"right"})?"right":i.isActive({textAlign:"justify"})?"justify":"left":"left"}),color:a.computed(()=>{it.value;const i=ke.value;if(!i)return null;const c=i.getAttributes("textStyle").color??null;return c?Xh(c):null}),linkHref:a.computed(()=>{it.value;const i=ke.value;return i?i.getAttributes("link").href??null:null})},e={toggleBold(){const i=ke.value;if(!i)return;const{from:l,to:c}=i.state.selection,d=l===c;let u=i.chain().focus();d&&(u=u.selectAll()),u=u.toggleBold(),d&&(u=u.setTextSelection(c)),u.run()},toggleItalic(){const i=ke.value;if(!i)return;const{from:l,to:c}=i.state.selection,d=l===c;let u=i.chain().focus();d&&(u=u.selectAll()),u=u.toggleItalic(),d&&(u=u.setTextSelection(c)),u.run()},toggleUnderline(){const i=ke.value;if(!i)return;const{from:l,to:c}=i.state.selection,d=l===c;let u=i.chain().focus();d&&(u=u.selectAll()),u=u.toggleUnderline(),d&&(u=u.setTextSelection(c)),u.run()},setAlignment(i){const l=ke.value;l&&l.chain().selectAll().setTextAlign(i).run()},setColor(i){const l=ke.value;if(!l)return;const{from:c,to:d}=l.state.selection;c===d?l.chain().focus().selectAll().setColor(i).setTextSelection(d).run():l.chain().focus().setColor(i).run()},setMark(i,l){const c=ke.value;if(!c)return;const{from:d,to:u}=c.state.selection;d===u?c.chain().focus().selectAll().setMark(i,l).setTextSelection(u).run():c.chain().focus().setMark(i,l).run()},unsetMark(i){const l=ke.value;if(!l)return;const{from:c,to:d}=l.state.selection;c===d?l.chain().focus().selectAll().unsetMark(i).setTextSelection(d).run():l.chain().focus().unsetMark(i).run()},setLink(i){const l=ke.value;if(!l)return;const{from:c,to:d}=l.state.selection;c===d?l.chain().focus().selectAll().setLink({href:i}).setTextSelection(d).run():l.chain().focus().setLink({href:i}).run()},removeLink(){const i=ke.value;if(!i)return;const{from:l,to:c}=i.state.selection;l===c?i.chain().focus().selectAll().unsetLink().setTextSelection(c).run():i.chain().focus().unsetLink().run()}};function t(i,l,c){ke.value=i,ya.value=l,ga.value=c,i.on("selectionUpdate",()=>{it.value++}),i.on("transaction",()=>{it.value++})}function o(){ke.value=null,ya.value=null,ga.value=null}function r(){requestAnimationFrame(()=>{requestAnimationFrame(()=>{it.value++})})}function s(i){it.value;const l=ke.value;return l&&l.isActive(i)?l.getAttributes(i):null}return{editor:ke,blockElement:ga,textElement:ya,state:n,commands:e,updateCounter:it,register:t,unregister:o,repositionMenu:r,getMarkAttrs:s}}const tp=1,np="Synced",op="application/x-woven-canvas",rp=w.defineQuery(n=>n.with(w.Block,w.Selected));function tS(n){let e=[...rp.current(n)];if(e.length===0)return null;const t=new Set(e);for(const f of e)for(const h of w.getDescendants(n,f))t.add(h);e=[...t];const{componentsById:o}=w.getResources(n),r=new Map([...o].filter(([,f])=>f.sync==="document")),s=w.Synced._getComponentId(n),i=new Set;for(const f of e)w.hasComponent(n,f,w.Synced)&&i.add(w.Synced.read(n,f).id);const l=new Set(e),c=[],d=ie.Aabb.zero();let u=!1;for(const f of e){const h={};w.hasComponent(n,f,w.Synced)&&(h[np]=w.Synced.snapshot(n,f));for(const p of n.entityBuffer.getComponentIds(f)){if(p===s)continue;const m=r.get(p);if(m){const g=m.snapshot(n,f),y=oS(n,m.schema,g);if(m.name==="block"&&y.parentId!=null){const k=w.Block.read(n,f).parentId;if(k!==null&&!l.has(k)){const x=w.Block.getWorldPosition(n,f);y.position=[x[0],x[1]],y.parentId=null}}h[m.name]=y}}if(c.push(h),w.hasComponent(n,f,w.Aabb)){const{value:p}=w.Aabb.read(n,f);u?ie.Aabb.union(d,p):(ie.Aabb.copy(d,p),u=!0)}}return{version:tp,center:ie.Aabb.center(d),entities:c}}function nS(n,e){let t;try{t=JSON.parse(e)}catch{return null}if(!t||t.version!==tp||!Array.isArray(t.entities)||t.entities.length===0)return null;const{componentsByName:o}=w.getResources(n),r=w.Synced._getComponentId(n),s=[];for(const i of t.entities){const l=new Map;for(const[c,d]of Object.entries(i)){if(c===np){l.set(r,d);continue}const u=o.get(c);u&&u.sync==="document"&&l.set(u._getComponentId(n),d)}s.push(l)}return{entities:s,center:t.center}}function oS(n,e,t){var r;const o={...t};for(const[s,i]of Object.entries(e))if(((r=i==null?void 0:i.def)==null?void 0:r.type)==="ref"){const l=t[s];o[s]=l!=null&&w.hasComponent(n,l,w.Synced)?w.Synced.read(n,l).id:null}return o}function rS(n){var t;const e=[];for(const[o,r]of Object.entries(n))((t=r==null?void 0:r.def)==null?void 0:t.type)==="ref"&&e.push(o);return e}function sS(n,e,t,o,r){var i;const s=t.write(n,e);for(const[l,c]of Object.entries(t.schema))if(((i=c==null?void 0:c.def)==null?void 0:i.type)==="ref"){const d=o[l];d!=null&&(s[l]=r.get(d)??null)}}function sp(n,e,t,o){if(e.length===0)return;const{componentsById:r}=w.getResources(n),s=new Map([...r].filter(([,p])=>p.sync==="document")),i=w.Synced._getComponentId(n),l=w.Block._getComponentId(n);let c;if(o)c=ie.Vec2.clone(o),ie.Vec2.sub(c,t);else{const p=w.Camera.getWorldCenter(n);c=ie.Vec2.clone(p),ie.Vec2.sub(c,t),w.Grid.snapPosition(n,c)}const d=[...e].sort((p,m)=>{var k,x;const g=((k=p.get(l))==null?void 0:k.rank)??"",y=((x=m.get(l))==null?void 0:x.rank)??"";return g<y?-1:g>y?1:0});w.deselectAll(n);const u=new Map,f=[];for(const p of d){const m=w.createEntity(n),g=p.get(i);g!=null&&g.id&&u.set(g.id,m),w.addComponent(n,m,w.Synced,{id:crypto.randomUUID()});for(const[y,k]of p){if(y===i)continue;const x=s.get(y);if(!x)continue;const b={...k};if(y===l){if(!(k.parentId!=null)){const E=ie.Vec2.clone(b.position);ie.Vec2.add(E,c),b.position=E}b.rank=w.RankBounds.genNext(n)}const S=rS(x.schema);if(S.length>0){for(const C of S)delete b[C];f.push({entityId:m,componentDef:x,componentData:k})}w.addComponent(n,m,x,b)}w.selectBlock(n,m)}for(const{entityId:p,componentDef:m,componentData:g}of f)sS(n,p,m,g,u);const h=[];for(const p of d){const m=p.get(i);if(!(m!=null&&m.id))continue;const g=u.get(m.id);if(!g||!w.hasComponent(n,g,w.Block)||w.Block.read(n,g).parentId!==null)continue;const k=w.Block.getCenter(n,g),x=w.findFrameAtPoint(n,k,g);x!==null&&h.push({entityId:g,frameId:x})}h.length>0&&w.AssignFrameChildren.spawn(n,{assignments:h})}function iS(n,e,t,o){const r=w.Text.default(),s=document.createElement("div");if(s.style.position="absolute",s.style.visibility="hidden",s.style.fontFamily=r.fontFamily,s.style.fontSize=`${r.fontSizePx}px`,s.style.lineHeight=`${r.lineHeight}`,s.style.letterSpacing=`${r.letterSpacingEm}em`,s.style.width="fit-content",s.style.wordBreak="break-word",s.style.minWidth="2px",e){const c=o/t,d=Math.min(Hs,c/2);s.style.maxWidth=`${d}px`,s.style.whiteSpace="pre-wrap"}else s.style.whiteSpace="pre";s.classList.add("wov-editable-text"),s.innerHTML=n,document.body.appendChild(s);const i=s.offsetWidth,l=s.offsetHeight;return document.body.removeChild(s),{width:i,height:l}}function lS(n,e={}){const t=e.enabled??!0,o=e.canPasteTextAsBlock??!0;if(!t)return;const{getEditor:r,nextEditorTick:s}=le(),i=a.inject(we),l=Pn();let c=null;function d(){const m=document.activeElement;return m instanceof HTMLInputElement||m instanceof HTMLTextAreaElement||!!(m!=null&&m.isContentEditable)}a.watch(()=>l.editor.value,m=>{if(!m||!c)return;const{plainText:g,html:y}=c;c=null;const k=new DataTransfer;k.setData("text/plain",g),y&&k.setData("text/html",y);const x=new ClipboardEvent("paste",{clipboardData:k,bubbles:!0,cancelable:!0});m.view.dom.dispatchEvent(x),s(b=>{w.DeselectAll.spawn(b)})});function u(m){if(l.editor.value||!m.clipboardData||d())return!1;const g=r();if(!g)return!1;const y=g._getContext(),k=tS(y);return k?(m.clipboardData.setData(op,JSON.stringify(k)),m.clipboardData.setData("text/plain",`${k.entities.length} block${k.entities.length===1?"":"s"}`),m.preventDefault(),!0):!1}function f(m){u(m)}function h(m){u(m)&&s(g=>{for(const y of rp.current(g))w.isAlive(g,y)&&w.cascadeDelete(g,y)})}async function p(m){var B,I,O,z;if(l.editor.value||d())return;const g=((B=m.clipboardData)==null?void 0:B.getData(op))??"",y=((I=m.clipboardData)==null?void 0:I.getData("text/html"))??"",k=((O=m.clipboardData)==null?void 0:O.getData("text/plain"))??"";if(g){m.preventDefault();const $=await s(),J=nS($,g);if(J){const j=w.Mouse.read($);if(j.position[0]!==0||j.position[1]!==0){const W=w.Camera.read($),X=[W.left+j.position[0]/W.zoom,W.top+j.position[1]/W.zoom];sp($,J.entities,J.center,X)}else sp($,J.entities,J.center)}return}if(!o||!k.trim())return;const x=await s();c={plainText:k,html:y};const b=w.Mouse.read(x),S=w.Camera.read(x),C=[S.left+b.position[0]/S.zoom,S.top+b.position[1]/S.zoom],v=eS(k),E=k.length>ha,M=((z=n.value)==null?void 0:z.clientWidth)??Hs,T=iS(v,E,S.zoom,M),A=rr(x,{block:{tag:"text",size:[T.width,T.height]},text:{constrainWidth:E,fontSizePx:24,...i.getDefaults("text")}},C);w.canBlockEdit(x,"text")&&w.addComponent(x,A,w.EditAfterPlacing,{}),w.SelectBlock.spawn(x,{entityId:A,deselectOthers:!0})}a.onMounted(()=>{const m=n.value;m&&(m.addEventListener("paste",p),m.addEventListener("copy",f),m.addEventListener("cut",h))}),a.onUnmounted(()=>{const m=n.value;m&&(m.removeEventListener("paste",p),m.removeEventListener("copy",f),m.removeEventListener("cut",h))})}function wt(n,e){const t=a.inject(we);if(!t)throw new Error("useComponents must be used within a WovenCanvas component");const o=a.shallowRef(new Map),r=new Map;function s(l){if(r.has(l))return;const c=t.getEditor();if(c){const u=c._getContext();if(w.hasComponent(u,l,e)){const f=new Map(o.value);f.set(l,e.snapshot(u,l)),o.value=f}else{const f=new Map(o.value);f.set(l,null),o.value=f}}const d=t.subscribeComponent(l,e.name,u=>{const f=new Map(o.value);f.set(l,u),o.value=f});r.set(l,d)}function i(l){const c=r.get(l);if(c){c(),r.delete(l);const d=new Map(o.value);d.delete(l),o.value=d}}return a.watch(()=>a.toValue(n),(l,c)=>{const d=new Set(l),u=new Set(c??[]);for(const f of u)d.has(f)||i(f);for(const f of d)u.has(f)||s(f)},{immediate:!0}),a.onUnmounted(()=>{for(const l of r.values())l();r.clear()}),o}function ka(){const n=a.inject(we);if(!n)throw new Error("useImageCreation must be used within a WovenCanvas component");const{nextEditorTick:e}=le();function t(s){return new Promise((i,l)=>{const c=new window.Image;c.onload=()=>{i({width:c.naturalWidth,height:c.naturalHeight}),URL.revokeObjectURL(c.src)},c.onerror=()=>{l(new Error("Failed to load image")),URL.revokeObjectURL(c.src)},c.src=URL.createObjectURL(s)})}async function o(s,i,l,c={}){const{maxSize:d=400}=c,u=await t(s),f=await e(),h=Math.min(1,d/Math.max(u.width,u.height));let p=Math.round(u.width*h),m=Math.round(u.height*h);const g=w.Grid.read(f);g.enabled&&(p=Math.max(g.colWidth,Math.round(p/g.colWidth)*g.colWidth),m=Math.max(g.rowHeight,Math.round(m/g.rowHeight)*g.rowHeight));const y=w.createEntity(f);w.addComponent(f,y,w.Block);const k=w.Block.write(f,y);k.tag="image",k.position[0]=i-p/2,k.position[1]=l-m/2,k.size[0]=p,k.size[1]=m,w.Grid.snapPosition(f,k.position);const x=crypto.randomUUID();w.addComponent(f,y,w.Asset);const b=w.Asset.write(f,y);b.identifier=x,b.uploadState=w.UploadState.Pending,w.addComponent(f,y,w.Image);const S=w.Image.write(f,y);return S.width=u.width,S.height=u.height,S.alt=s.name,w.addComponent(f,y,Ve.Synced,{id:crypto.randomUUID()}),(n==null?void 0:n.getAssetManager())&&r(y,x,s),y}function r(s,i,l){const c=n==null?void 0:n.getAssetManager();c&&c.upload(i,l,{filename:l.name,mimeType:l.type}).catch(d=>{console.error("Asset upload failed:",d)})}return{getImageDimensions:t,createImageBlock:o}}const aS=w.defineQuery(n=>n.with(w.Block,w.Edited,w.Text));function cS(n){const e=typeof window<"u"?window.visualViewport:null;if(!e)return;const t=Pn();let o=null,r=!1;const s=40,i=.2;function l(){return e?window.innerHeight-e.height>window.innerHeight*i:!1}function c(){if(e){if(!l()){if(o&&r){const d=o;o=null,r=!1,n(u=>{const f=w.Camera.write(u);f.left=d.left,f.top=d.top}),t.repositionMenu()}return}n(d=>{const f=aS.current(d)[Symbol.iterator]().next().value;if(!f)return;const h=w.Block.read(d,f),p=w.Camera.read(d);if(!h||!p)return;const m=p.zoom,g=(h.position[1]-p.top)*m,y=(h.position[1]+h.size[1]-p.top)*m,k=e.height,x=e.offsetTop,b=x,S=x+k;if(y+s<=S&&g>=b)return;o||(o={left:p.left,top:p.top});const C=h.position[1]+h.size[1]/2,v=x+k/2,E=C-v/m,M=w.Camera.write(d);M.top=E,r=!0,t.repositionMenu()})}}e.addEventListener("resize",c),a.onUnmounted(()=>{if(e.removeEventListener("resize",c),o&&r){const d=o;o=null,r=!1,n(u=>{const f=w.Camera.write(u);f.left=d.left,f.top=d.top})}})}function ip(n){const e=a.inject(we);if(!e)throw new Error("useQuery must be used within a WovenCanvas component");const t=a.shallowRef([]),o=w.defineQuery(f=>f.with(...n)),r=new Map;let s=!1;function i(f){const h=e.getEditor();if(!h)return{refs:{},unsubscribes:[]};const p=h._getContext(),m={},g=[];for(const y of n){const k=a.shallowRef(y.snapshot(p,f));m[y.name]=k;const x=e.subscribeComponent(f,y.name,b=>{k.value=b});g.push(x)}return{refs:m,unsubscribes:g}}function l(f){const h=r.get(f);if(h){for(const p of h.unsubscribes)p();r.delete(f)}}function c(){const f=[];for(const[h,p]of r)f.push({entityId:h,...p.refs});return f}function d(f){if(!s){const g=o.current(f);for(const y of g)r.set(y,i(y));t.value=c(),s=!0;return}const h=o.added(f),p=o.removed(f);let m=!1;for(const g of p)l(g),m=!0;for(const g of h)r.has(g)||(r.set(g,i(g)),m=!0);m&&(t.value=c())}const u=e.registerTickCallback(d);return a.onUnmounted(()=>{u();for(const f of r.keys())l(f)}),t}function Me(n){const e=a.inject(we);if(!e)throw new Error("useSingleton must be used within a WovenCanvas component");const t=a.shallowRef(n.default()),o=e.getEditor();if(o){const i=o._getContext();t.value=n.snapshot(i)}const r=e.subscribeSingleton(n.name,i=>{t.value=i??{}});let s=null;return o||(s=e.registerTickCallback(()=>{const i=e.getEditor();if(i){const l=i._getContext();t.value=n.snapshot(l),s==null||s(),s=null}})),a.onUnmounted(()=>{r(),s==null||s()}),t}function wa(n,e,t){if(!n.closest(".wov-block")){const p=n.getBoundingClientRect();return{width:p.width,height:p.height,left:0,top:0}}const r=n.getBoundingClientRect(),s=t.value.left,i=t.value.top,l=new DOMPoint(r.left+r.width/2-s,r.top+r.height/2-i),c=e.value.zoom,d=new DOMMatrix;d.translateSelf(-e.value.left*c,-e.value.top*c),d.scaleSelf(c,c),d.invertSelf();const u=d.transformPoint(l),f=n.offsetWidth,h=n.offsetHeight;return{width:f,height:h,left:u.x-f/2,top:u.y-h/2}}const lp=[fh,ph,mh,ca,zh,yh,kh,wh,Ph.configure({openOnClick:!1}),Lh.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:"left"})];function dS(n){return n.type==="text"&&typeof n.text=="string"}function bt(n,e){if(dS(n)){e(n);return}if(n.content)for(const t of n.content)bt(t,e)}function ba(n,e){if(n.type==="paragraph"){e(n);return}if(n.content)for(const t of n.content)ba(t,e)}function uS(n,e){var t;return((t=n.marks)==null?void 0:t.some(o=>o.type===e))??!1}function fS(n){var o,r;const e=(o=n.marks)==null?void 0:o.find(s=>s.type==="textStyle"),t=((r=e==null?void 0:e.attrs)==null?void 0:r.color)??null;return t?Xh(t):null}function hS(n,e){let t=!1,o=!0,r=0;return bt(n,s=>{r++,uS(s,e)?t=!0:o=!1}),r===0?!1:o?!0:t?null:!1}function pS(n){let e="left";return ba(n,t=>{var r;const o=(r=t.attrs)==null?void 0:r.textAlign;o&&(e=o)}),e}function mS(n){let e=null;return bt(n,t=>{e===null&&(e=fS(t))}),e}function Sa(n,e){bt(n,t=>{const o=t.marks??[];o.findIndex(r=>r.type===e)===-1&&(t.marks=[...o,{type:e}])})}function ir(n,e){bt(n,t=>{t.marks=(t.marks??[]).filter(o=>o.type!==e)})}function gS(n,e){ba(n,t=>{t.attrs={...t.attrs,textAlign:e}})}function ap(n,e,t){bt(n,o=>{const r=o.marks??[],s=r.findIndex(i=>i.type===e);s!==-1?(r[s]={...r[s],attrs:{...r[s].attrs,...t}},o.marks=r):o.marks=[...r,{type:e,attrs:t}]})}function yS(n,e){let t=null;return bt(n,o=>{var r;if(t===null){const s=(r=o.marks)==null?void 0:r.find(i=>i.type===e);s&&(t=s.attrs??{})}}),t}function kS(n){let e=null;return bt(n,t=>{var o,r;if(e===null){const s=(o=t.marks)==null?void 0:o.find(i=>i.type==="link");(r=s==null?void 0:s.attrs)!=null&&r.href&&(e=s.attrs.href)}}),e}function wS(n,e){bt(n,t=>{const o=t.marks??[],r=o.findIndex(s=>s.type==="link");r!==-1?(o[r]={...o[r],attrs:{...o[r].attrs,href:e}},t.marks=o):t.marks=[...o,{type:"link",attrs:{href:e,target:"_blank",rel:"noopener noreferrer"}}]})}function cp(n){const e=document.querySelector(`[data-entity-id="${n}"]`);if(!e)return null;const t=e.firstElementChild;return t||e.querySelector(".wov-editable-text")}function dp(n){const e=w.TransformBoxStateSingleton.read(n);e.transformBoxId!==null&&e.state===w.TransformBoxState.Idle&&w.UpdateTransformBox.spawn(n,{transformBoxId:e.transformBoxId})}function up(n,e,t,o){var c;const r=n.cloneNode(!0);r.style.position="absolute",r.style.visibility="hidden",r.style.pointerEvents="none",r.style.top="0",r.style.left="0";const s=r.classList.contains("wov-editable-text")?r:r.querySelector(".wov-editable-text");s&&(s.style.fontSize=`${o.fontSizePx}px`,s.style.fontFamily=o.fontFamily,s.style.lineHeight=String(o.lineHeight),s.style.letterSpacing=`${o.letterSpacingEm}em`);const i=r.querySelector(".ProseMirror, .tiptap");i?i.innerHTML=o.content:s?s.innerHTML=o.content:r.innerHTML=o.content,(c=n.parentElement)==null||c.appendChild(r);const l=wa(r,e,t);return r.remove(),l}function fp(n){const{nextEditorTick:e}=le(),t=a.inject(we),o=wt(n,w.Text),r=Me(w.Camera),s=Me(w.Screen),i=Pn(),l=a.inject(vi,void 0),c=a.computed(()=>{const b=l==null?void 0:l.value.extensions;return b&&b.length>0?[...lp,...b]:lp}),d=b=>Lw(b,c.value),u=b=>Pw(b,c.value),f=(b,S)=>{if(!b.trim())return b;const C=d(b);return S(C),u(C)},h={hasTextEntities:a.computed(()=>{for(const b of o.value.values())if(b)return!0;return!1}),hasTextContent:a.computed(()=>{for(const b of o.value.values()){if(!b)continue;const S=b.content?d(b.content):null;if(S){let C=!1;if(bt(S,v=>{var E;(E=v.text)!=null&&E.trim()&&(C=!0)}),C)return!0}}return!1}),isBold:a.computed(()=>p("bold")),isItalic:a.computed(()=>p("italic")),isUnderline:a.computed(()=>p("underline")),alignment:a.computed(()=>{let b=null;for(const S of o.value.values()){if(!S)continue;const C=S.content?pS(d(S.content)):"left";if(b===null)b=C;else if(b!==C)return null}return b??"left"}),color:a.computed(()=>{let b=null,S=!1;for(const C of o.value.values()){if(!C)continue;const v=C.content?mS(d(C.content)):null;if(!S)b=v,S=!0;else if(b!==v)return null}return b}),fontSize:a.computed(()=>{let b=null,S=!1;for(const C of o.value.values())if(C){if(!S)b=C.fontSizePx,S=!0;else if(b!==C.fontSizePx)return null}return b}),fontFamily:a.computed(()=>{let b=null,S=!1;for(const C of o.value.values())if(C){if(!S)b=C.fontFamily,S=!0;else if(b!==C.fontFamily)return null}return b}),linkHref:a.computed(()=>{let b=null,S=!1;for(const C of o.value.values()){if(!C)continue;const v=C.content?kS(d(C.content)):null;if(!S)b=v,S=!0;else if(b!==v)return null}return b})};function p(b){let S=null,C=!1;for(const v of o.value.values()){if(!v)continue;const E=v.content?hS(d(v.content),b):!1;if(!C)S=E,C=!0;else if(S!==E)return null}return S}function m(b){let S=null,C=!1;for(const v of o.value.values()){if(!v)continue;const E=v.content?yS(d(v.content),b):null;if(!C)S=E,C=!0;else if(JSON.stringify(S)!==JSON.stringify(E))return null}return S}const g={toggleBold(){k(b=>f(b,S=>h.isBold.value?ir(S,"bold"):Sa(S,"bold")))},toggleItalic(){k(b=>f(b,S=>h.isItalic.value?ir(S,"italic"):Sa(S,"italic")))},toggleUnderline(){k(b=>f(b,S=>h.isUnderline.value?ir(S,"underline"):Sa(S,"underline")))},setAlignment(b){x(S=>f(S,C=>gS(C,b)))},setColor(b){x(S=>f(S,C=>ap(C,"textStyle",{color:b})))},setMark(b,S={}){k(C=>f(C,v=>ap(v,b,S)))},unsetMark(b){k(S=>f(S,C=>ir(C,b)))},setFontSize(b){t.setDefaults("text",{fontSizePx:b}),y(S=>({...S,fontSizePx:b}),S=>{S.fontSizePx=b})},setFontFamily(b){t.setDefaults("text",{fontFamily:b}),y(S=>({...S,fontFamily:b}),S=>{S.fontFamily=b})},setTextStyle(b){const S={};b.fontFamily!==void 0&&(S.fontFamily=b.fontFamily),b.fontSizePx!==void 0&&(S.fontSizePx=b.fontSizePx),b.lineHeight!==void 0&&(S.lineHeight=b.lineHeight),b.letterSpacingEm!==void 0&&(S.letterSpacingEm=b.letterSpacingEm),Object.keys(S).length>0&&t.setDefaults("text",S),y(C=>({...C,fontFamily:b.fontFamily??C.fontFamily,fontSizePx:b.fontSizePx??C.fontSizePx,lineHeight:b.lineHeight??C.lineHeight,letterSpacingEm:b.letterSpacingEm??C.letterSpacingEm}),C=>{b.fontFamily!==void 0&&(C.fontFamily=b.fontFamily),b.fontSizePx!==void 0&&(C.fontSizePx=b.fontSizePx),b.lineHeight!==void 0&&(C.lineHeight=b.lineHeight),b.letterSpacingEm!==void 0&&(C.letterSpacingEm=b.letterSpacingEm)})},setLink(b){x(S=>f(S,C=>wS(C,b)))},removeLink(){x(b=>f(b,S=>ir(S,"link")))}};function y(b,S){const C=a.toValue(n),v=[];for(const E of C){const M=o.value.get(E);if(!M)continue;const T=cp(E);if(T){const A=up(T,r,s,b(M));v.push({entityId:E,...A})}}e(E=>{for(const M of C)S(w.Text.write(E,M));for(const{entityId:M,width:T,height:A,left:B,top:I}of v){const O=w.Block.write(E,M);O.size=[T,A],w.Block.setWorldPosition(E,M,[B,I])}dp(E),a.nextTick(()=>{var M;i.updateCounter.value++,(M=i.editor.value)==null||M.commands.focus()})})}function k(b){const S=a.toValue(n),C=[];for(const v of S){const E=o.value.get(v);if(!E)continue;const M=b(E.content),T=cp(v);if(T){const A=up(T,r,s,{...E,content:M});C.push({entityId:v,content:M,...A})}else C.push({entityId:v,content:M,width:0,height:0,left:0,top:0})}e(v=>{for(const{entityId:E,content:M,width:T,height:A,left:B,top:I}of C){const O=w.Text.write(v,E);if(O.content=M,T>0&&A>0){const z=w.Block.write(v,E);z.size=[T,A],w.Block.setWorldPosition(v,E,[B,I])}}dp(v)})}function x(b){const S=a.toValue(n);e(C=>{for(const v of S){const E=w.Text.write(C,v);E.content=b(E.content)}})}return{state:h,commands:g,getMarkAttrs:m}}function lt(n){const e=Pn(),t=fp(n),o=e.state.hasEditor,r=a.reactive({hasTextToFormat:a.computed(()=>o.value||t.state.hasTextEntities.value),hasEditor:o,hasTextContent:a.computed(()=>t.state.hasTextContent.value),showTextMenuButtons:a.computed(()=>o.value||t.state.hasTextContent.value),isBold:a.computed(()=>o.value?e.state.isBold.value:t.state.isBold.value===!0),isItalic:a.computed(()=>o.value?e.state.isItalic.value:t.state.isItalic.value===!0),isUnderline:a.computed(()=>o.value?e.state.isUnderline.value:t.state.isUnderline.value===!0),alignment:a.computed(()=>o.value?e.state.alignment.value:t.state.alignment.value??"left"),color:a.computed(()=>o.value?e.state.color.value:t.state.color.value),fontSize:a.computed(()=>t.state.fontSize.value),fontFamily:a.computed(()=>t.state.fontFamily.value),linkHref:a.computed(()=>o.value?e.state.linkHref.value:t.state.linkHref.value)}),s={toggleBold(){o.value?e.commands.toggleBold():t.commands.toggleBold()},toggleItalic(){o.value?e.commands.toggleItalic():t.commands.toggleItalic()},toggleUnderline(){o.value?e.commands.toggleUnderline():t.commands.toggleUnderline()},setAlignment(l){o.value?e.commands.setAlignment(l):t.commands.setAlignment(l)},setColor(l){o.value?e.commands.setColor(l):t.commands.setColor(l)},setMark(l,c){o.value?e.commands.setMark(l,c):t.commands.setMark(l,c)},unsetMark(l){o.value?e.commands.unsetMark(l):t.commands.unsetMark(l)},setFontSize(l){t.commands.setFontSize(l)},setFontFamily(l){t.commands.setFontFamily(l)},setTextStyle(l){t.commands.setTextStyle(l)},setLink(l){o.value?e.commands.setLink(l):t.commands.setLink(l)},removeLink(){o.value?e.commands.removeLink():t.commands.removeLink()}};function i(l){return o.value?e.getMarkAttrs(l):t.getMarkAttrs(l)}return{state:r,commands:s,getMarkAttrs:i}}function xa(n){const e=Me(w.Camera),t=Me(w.Screen),o=Me(w.TransformBoxStateSingleton),r=Me(w.SelectionStateSingleton),{nextEditorTick:s}=le();let i=!1,l=null;function c(u,f){const{entityId:h}=a.toValue(n.blockData),p=a.toValue(n.minWidth)??0,m=a.toValue(n.minHeight)??0,g=Math.max(f.width,p),y=Math.max(f.height,m),k=w.Block.read(u,h),x=Math.abs(k.size[0]-g)>.5,b=Math.abs(k.size[1]-y)>.5;if(!x&&!b)return;const S=w.Block.write(u,h);S.size=[g,y],w.Block.setWorldPosition(u,h,[f.left,f.top]),o.value.transformBoxId!==null&&w.UpdateTransformBox.spawn(u,{transformBoxId:o.value.transformBoxId})}a.watch(()=>r.value,()=>{s(u=>{const f=bS(u);if(i&&!f){const h=n.containerRef.value;if(!h)return;l=wa(h,e,t),c(u,l),l=null}i=f})},{flush:"sync"});function d(u){const{content:f,...h}=u;s(p=>{const{entityId:m}=a.toValue(n.blockData);if(w.Text.read(p,m).content!==f){const y=w.Text.write(p,m);y.content=f}c(p,h)})}return{handleEditEnd:d}}function bS(n){const e=w.SelectionStateSingleton.read(n);return e.state===w.SelectionState.Dragging&&e.draggedEntity!==null&&w.hasComponent(n,e.draggedEntity,w.TransformHandle)&&w.TransformHandle.read(n,e.draggedEntity).kind===w.TransformHandleKind.Stretch}function js(){const n=a.inject(Mi);if(!n)throw new Error("useToolbar must be used within a Toolbar component");return{activeTool:n.activeTool,heldTool:n.heldTool,setTool:n.setTool,dragOutTool:n.dragOutTool,onToolPointerDown:n.onToolPointerDown,onToolPointerUp:n.onToolPointerUp,isActive:e=>a.computed(()=>n.activeTool.value===e)}}const SS=500,xS=1500,Us=a.ref(null),lr=a.ref(!1),ao=a.ref(!1);let ar=null,cr=null,dr=null;function Ca(){ar&&(clearTimeout(ar),ar=null),cr&&(clearTimeout(cr),cr=null)}function Ea(){dr&&(dr.disconnect(),dr=null)}function CS(n){Ea(),!(typeof MutationObserver>"u"||typeof document>"u")&&(dr=new MutationObserver(()=>{n.isConnected||hp()}),dr.observe(document.body,{childList:!0,subtree:!0}))}function ES(n,e,t){Ca(),Us.value={text:n,anchor:e,placement:t},CS(e),ao.value?lr.value=!0:ar=setTimeout(()=>{lr.value=!0,ao.value=!0,ar=null},SS)}function vS(){Ca(),Ea(),lr.value=!1,Us.value=null,ao.value&&(cr=setTimeout(()=>{ao.value=!1,cr=null},xS))}function hp(){Ca(),Ea(),lr.value=!1,Us.value=null,ao.value=!1}const MS={activeTooltip:a.readonly(Us),isVisible:a.readonly(lr),isWarmedUp:a.readonly(ao),show:ES,hide:vS,reset:hp},Ws=a.ref([]);function zt(){return MS}const TS={key:1},NS=["innerHTML"],Ks=a.defineComponent({__name:"EditableText",props:{blockElement:{},entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},emits:["editEnd"],setup(n,{expose:e,emit:t}){var T;const o=n,r=t,s=fe(o.entityId,w.Text),i=Me(w.Camera),l=Me(w.Screen),c=Pn(),{nextEditorTick:d,getEditor:u}=le(),f=Me(w.Mouse),h=a.inject(vi,void 0),p=a.ref(null);e({editableTextRef:p});const m=a.ref(((T=s.value)==null?void 0:T.content)??""),g=a.shallowRef(null);a.watch(()=>{var A;return(A=s.value)==null?void 0:A.fontFamily},A=>{var B;A&&((B=u())==null||B.loadFont(A))},{immediate:!0});async function y(){var j,K;p.value&&(p.value.style.opacity="0");const A=await d(),B=w.Block.read(A,o.entityId),I=(((j=l.value)==null?void 0:j.width)??Hs)/(((K=i.value)==null?void 0:K.zoom)??1),O=Math.min(Hs,I/2),z=Math.max(B.size[0],O),$=w.Block.write(A,o.entityId);$.size=[z,B.size[1]];const J=w.Text.write(A,o.entityId);J.constrainWidth=!0,w.ResetKeyboard.spawn(A),requestAnimationFrame(()=>{p.value&&(p.value.style.opacity=""),requestAnimationFrame(()=>{c.updateCounter.value++})})}function k(A,B){var J,j,K;const I=s.value;if(!I)return!1;const O=((J=B.clipboardData)==null?void 0:J.getData("text/html"))??"",z=((j=B.clipboardData)==null?void 0:j.getData("text/plain"))??"";if(!/<[^>]+data-pm-slice=/.test(O)){B.preventDefault();const W=z.trimEnd().split(/\r?\n/).map(X=>({type:"paragraph",content:X?[{type:"text",text:X}]:[]}));return(K=g.value)==null||K.commands.insertContent(W),!I.constrainWidth&&z.length>ha&&y(),!0}return!I.constrainWidth&&z.length>ha&&y(),!1}function x(){var O,z,$;const A=((O=u())==null?void 0:O.readonly)===!0,B=(h==null?void 0:h.value.links)!==!1,I=(h==null?void 0:h.value.underline)!==!1;return new $b({extensions:[fh,ph,mh,ca,zh,yh,kh,...I?[wh]:[],Ph.configure({openOnClick:!1,autolink:B,linkOnPaste:B,HTMLAttributes:{rel:"noopener noreferrer",target:"_blank"}}),Lh.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:((z=s.value)==null?void 0:z.defaultAlignment)??"left"}),...(h==null?void 0:h.value.extensions)??[],Z2],content:(($=s.value)==null?void 0:$.content)??"",editable:!A,parseOptions:{preserveWhitespace:!0},editorProps:{handlePaste:k}})}a.watch(()=>o.edited,async A=>{if(A){if(p.value||await a.nextTick(),!p.value||(g.value=x(),await b(g.value),!o.blockElement))return;c.register(g.value,p.value,o.blockElement)}else g.value&&(c.unregister(),S(g.value),g.value.destroy(),g.value=null)},{immediate:!0});async function b(A){var z;const B=(z=f.value)==null?void 0:z.position,I=l.value;await a.nextTick(),await new Promise($=>requestAnimationFrame($));const O=p.value;if(B&&I&&O){const $=B[0]+I.left,J=B[1]+I.top,j=A.view.posAtCoords({left:$,top:J});if(j){A.chain().focus().setTextSelection(j.pos).run();return}}A.commands.focus("start")}function S(A){let B=A.getHTML();const O=B.replace(/<[^>]*>/g,"").trim().length>0;O||(B=""),m.value=B,d(z=>{var W,X;const $=w.getBlockDef(z,o.block.tag);if(!O&&((W=$.editOptions)!=null&&W.removeWhenTextEmpty)){w.removeEntity(z,o.entityId);return}const J=(X=p.value)==null?void 0:X.closest(".wov-block"),j=(J==null?void 0:J.firstElementChild)??p.value;if(!j){console.warn("EditableText: no element to measure");return}const K=wa(j,i,l);r("editEnd",{content:B,...K})})}a.watch(()=>{var A;return(A=s.value)==null?void 0:A.content},A=>{A!==void 0&&(g.value?g.value.getHTML()!==A&&g.value.commands.setContent(A,{emitUpdate:!1}):m.value=A)});const C=a.computed(()=>{const A=s.value;if(!A)return{};const[B,I]=o.block.flip,O=B?-1:1,z=I?-1:1,$=B||I;return{fontFamily:A.fontFamily,fontSize:`${A.fontSizePx}px`,lineHeight:A.lineHeight,letterSpacing:`${A.letterSpacingEm}em`,width:A.constrainWidth?"100%":"fit-content",whiteSpace:A.constrainWidth?"pre-wrap":"pre",minWidth:"2px",wordBreak:"break-word",pointerEvents:o.edited?"auto":"none",userSelect:o.edited?"auto":"none",transform:$?`scale(${O}, ${z})`:void 0}});function v(A){A.key==="Control"||A.key==="Meta"||A.stopPropagation()}function E(A){o.edited&&A.stopPropagation()}function M(A){if(o.edited)return;const B=A.target.closest("a");if(!B)return;const I=B.getAttribute("href");I&&(A.preventDefault(),A.stopPropagation(),window.open(I,"_blank","noopener,noreferrer"))}return a.onUnmounted(()=>{g.value&&(c.unregister(),g.value.destroy(),g.value=null)}),(A,B)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"editableTextRef",ref:p,class:"wov-editable-text",style:a.normalizeStyle(C.value),onKeydown:v,onPointerdown:E,onPointermove:E,onPointerup:E,onClick:M},[g.value?(a.openBlock(),a.createBlock(a.unref(zb),{key:0,editor:g.value},null,8,["editor"])):(a.openBlock(),a.createElementBlock("div",TS,[a.createElementVNode("div",{class:"tiptap ProseMirror",innerHTML:m.value},null,8,NS)]))],36))}}),AS={class:"wov-shape-svg",viewBox:"0 0 100 100",preserveAspectRatio:"none"},BS=["d","fill","stroke","stroke-width","stroke-dasharray"],pp=a.defineComponent({__name:"ShapeBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=fe(e.entityId,w.Shape),o=fe(e.entityId,w.VerticalAlign),r=a.ref(null),s={[w.VerticalAlignment.Top]:"flex-start",[w.VerticalAlignment.Center]:"center",[w.VerticalAlignment.Bottom]:"flex-end"},i=a.computed(()=>t.value?`rgba(${t.value.fillRed}, ${t.value.fillGreen}, ${t.value.fillBlue}, ${(t.value.fillAlpha??255)/255})`:"rgba(0, 0, 0, 0)"),l=a.computed(()=>t.value?t.value.strokeKind===w.StrokeKind.None?"none":`rgba(${t.value.strokeRed}, ${t.value.strokeGreen}, ${t.value.strokeBlue}, ${t.value.strokeAlpha/255})`:"rgba(0, 0, 0, 1)"),c=a.computed(()=>{var g;return((g=t.value)==null?void 0:g.strokeWidth)??2}),d=a.computed(()=>{var g;return((g=t.value)==null?void 0:g.strokeKind)??w.StrokeKind.Solid}),u=a.computed(()=>{var g;return Co[((g=t.value)==null?void 0:g.kind)??"rectangle"]??Co.rectangle}),f=a.computed(()=>{const g=c.value;switch(d.value){case w.StrokeKind.Dashed:return`${g*3} ${g*3}`;case w.StrokeKind.None:return"";default:return""}}),h=a.computed(()=>{var g;return{overflow:e.edited?"visible":"hidden",alignItems:s[((g=o.value)==null?void 0:g.value)??w.VerticalAlignment.Top]}}),{nextEditorTick:p}=le();function m(g){p(y=>{if(w.Text.read(y,e.entityId).content===g.content)return;const x=w.Text.write(y,e.entityId);x.content=g.content})}return(g,y)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:r,class:"wov-shape-block"},[(a.openBlock(),a.createElementBlock("svg",AS,[a.createElementVNode("path",{d:u.value,fill:i.value,stroke:l.value,"stroke-width":c.value,"stroke-dasharray":f.value,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":"non-scaling-stroke"},null,8,BS)])),a.createElementVNode("div",{class:"wov-shape-content",style:a.normalizeStyle(h.value)},[a.createVNode(Ks,a.mergeProps(e,{"block-element":r.value,onEditEnd:m}),null,16,["block-element"])],4)],512))}}),IS={class:"wov-tape-block"},OS={key:0,class:"wov-tape-placeholder"},mp=a.defineComponent({__name:"TapeBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},async setup(n){let e,t;const o=n,r=a.inject(we);if(!r)throw new Error("TapeBlock must be used within a WovenCanvas component");const s=r,i=fe(o.entityId,w.Asset),l=fe(o.entityId,w.Image);function c(){var C,v;const x=((C=l.value)==null?void 0:C.width)??0,b=((v=l.value)==null?void 0:v.height)??0,S=xr(o.block.size[1],b);return x<=0||b<=0?{width:xr(o.block.size[0]),height:S}:{width:Math.ceil(S*(x/b)),height:S}}const d=s.getAssetManager(),u=i.value;let f=null;d&&(u!=null&&u.identifier)&&(f=([e,t]=a.withAsyncContext(()=>d.getDisplayUrl(u.identifier,c())),e=await e,t(),e));let h=c().height;const p=a.ref(f),m=a.ref(!f),g=a.ref(!1);let y=!0;a.onUnmounted(()=>{y=!1});async function k(){const x=s.getAssetManager();if(!x)return;const b=i.value;if(!b||!b.identifier){m.value=!1;return}try{m.value=!0,g.value=!1;const S=c();h=S.height;const C=await x.getDisplayUrl(b.identifier,S);if(!y)return;C?(p.value=C,m.value=!1):b.uploadState===w.UploadState.Failed&&(g.value=!0,m.value=!1)}catch(S){if(!y)return;console.error("Failed to get tape display URL:",S),g.value=!0,m.value=!1}}return a.watch(()=>i.value,()=>{k()},{immediate:!0}),a.onMounted(()=>{k()}),a.watch(()=>o.block.size[1],()=>{c().height>h&&k()}),(x,b)=>(a.openBlock(),a.createElementBlock("div",IS,[m.value&&!p.value?(a.openBlock(),a.createElementBlock("div",OS)):p.value?(a.openBlock(),a.createElementBlock("div",{key:1,class:"wov-tape-image",style:a.normalizeStyle({backgroundImage:`url(${p.value})`})},null,4)):a.createCommentVNode("",!0)]))}}),_S=["data-text-empty"],gp=a.defineComponent({__name:"TextBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=a.ref(null),o=fe(e.entityId,w.Text),r=a.computed(()=>{var d;return(((d=o.value)==null?void 0:d.content)??"").replace(/<[^>]*>/g,"").trim().length===0}),s=a.computed(()=>{var l;return((l=o.value)==null?void 0:l.constrainWidth)??!1}),{handleEditEnd:i}=xa({blockData:e,containerRef:t});return(l,c)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-text-block","data-text-empty":r.value||void 0,style:a.normalizeStyle({width:s.value?"100%":"fit-content"})},[a.createVNode(Ks,a.mergeProps(e,{"block-element":t.value,onEditEnd:a.unref(i)}),null,16,["block-element","onEditEnd"])],12,_S))}}),DS={class:"wov-transform-box"},yp=a.defineComponent({__name:"TransformBox",setup(n){return(e,t)=>(a.openBlock(),a.createElementBlock("div",DS))}}),RS={},PS={class:"wov-transform-handle"};function LS(n,e){return a.openBlock(),a.createElementBlock("div",PS)}const kp=kn(RS,[["render",LS]]),qs=Math.min,Ln=Math.max,Js=Math.round,Gs=Math.floor,St=n=>({x:n,y:n}),VS={left:"right",right:"left",bottom:"top",top:"bottom"},$S={start:"end",end:"start"};function wp(n,e,t){return Ln(n,qs(e,t))}function Ys(n,e){return typeof n=="function"?n(e):n}function Vn(n){return n.split("-")[0]}function Xs(n){return n.split("-")[1]}function bp(n){return n==="x"?"y":"x"}function Sp(n){return n==="y"?"height":"width"}const zS=new Set(["top","bottom"]);function cn(n){return zS.has(Vn(n))?"y":"x"}function xp(n){return bp(cn(n))}function FS(n,e,t){t===void 0&&(t=!1);const o=Xs(n),r=xp(n),s=Sp(r);let i=r==="x"?o===(t?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=Qs(i)),[i,Qs(i)]}function HS(n){const e=Qs(n);return[va(n),e,va(e)]}function va(n){return n.replace(/start|end/g,e=>$S[e])}const Cp=["left","right"],Ep=["right","left"],jS=["top","bottom"],US=["bottom","top"];function WS(n,e,t){switch(n){case"top":case"bottom":return t?e?Ep:Cp:e?Cp:Ep;case"left":case"right":return e?jS:US;default:return[]}}function KS(n,e,t,o){const r=Xs(n);let s=WS(Vn(n),t==="start",o);return r&&(s=s.map(i=>i+"-"+r),e&&(s=s.concat(s.map(va)))),s}function Qs(n){return n.replace(/left|right|bottom|top/g,e=>VS[e])}function qS(n){return{top:0,right:0,bottom:0,left:0,...n}}function JS(n){return typeof n!="number"?qS(n):{top:n,right:n,bottom:n,left:n}}function Zs(n){const{x:e,y:t,width:o,height:r}=n;return{width:o,height:r,top:t,left:e,right:e+o,bottom:t+r,x:e,y:t}}function vp(n,e,t){let{reference:o,floating:r}=n;const s=cn(e),i=xp(e),l=Sp(i),c=Vn(e),d=s==="y",u=o.x+o.width/2-r.width/2,f=o.y+o.height/2-r.height/2,h=o[l]/2-r[l]/2;let p;switch(c){case"top":p={x:u,y:o.y-r.height};break;case"bottom":p={x:u,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:f};break;case"left":p={x:o.x-r.width,y:f};break;default:p={x:o.x,y:o.y}}switch(Xs(e)){case"start":p[i]-=h*(t&&d?-1:1);break;case"end":p[i]+=h*(t&&d?-1:1);break}return p}async function GS(n,e){var t;e===void 0&&(e={});const{x:o,y:r,platform:s,rects:i,elements:l,strategy:c}=n,{boundary:d="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=Ys(e,n),m=JS(p),y=l[h?f==="floating"?"reference":"floating":f],k=Zs(await s.getClippingRect({element:(t=await(s.isElement==null?void 0:s.isElement(y)))==null||t?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:u,strategy:c})),x=f==="floating"?{x:o,y:r,width:i.floating.width,height:i.floating.height}:i.reference,b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),S=await(s.isElement==null?void 0:s.isElement(b))?await(s.getScale==null?void 0:s.getScale(b))||{x:1,y:1}:{x:1,y:1},C=Zs(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:x,offsetParent:b,strategy:c}):x);return{top:(k.top-C.top+m.top)/S.y,bottom:(C.bottom-k.bottom+m.bottom)/S.y,left:(k.left-C.left+m.left)/S.x,right:(C.right-k.right+m.right)/S.x}}const YS=async(n,e,t)=>{const{placement:o="bottom",strategy:r="absolute",middleware:s=[],platform:i}=t,l=s.filter(Boolean),c=await(i.isRTL==null?void 0:i.isRTL(e));let d=await i.getElementRects({reference:n,floating:e,strategy:r}),{x:u,y:f}=vp(d,o,c),h=o,p={},m=0;for(let y=0;y<l.length;y++){var g;const{name:k,fn:x}=l[y],{x:b,y:S,data:C,reset:v}=await x({x:u,y:f,initialPlacement:o,placement:h,strategy:r,middlewareData:p,rects:d,platform:{...i,detectOverflow:(g=i.detectOverflow)!=null?g:GS},elements:{reference:n,floating:e}});u=b??u,f=S??f,p={...p,[k]:{...p[k],...C}},v&&m<=50&&(m++,typeof v=="object"&&(v.placement&&(h=v.placement),v.rects&&(d=v.rects===!0?await i.getElementRects({reference:n,floating:e,strategy:r}):v.rects),{x:u,y:f}=vp(d,h,c)),y=-1)}return{x:u,y:f,placement:h,strategy:r,middlewareData:p}},XS=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(e){var t,o;const{placement:r,middlewareData:s,rects:i,initialPlacement:l,platform:c,elements:d}=e,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...y}=Ys(n,e);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const k=Vn(r),x=cn(l),b=Vn(l)===l,S=await(c.isRTL==null?void 0:c.isRTL(d.floating)),C=h||(b||!g?[Qs(l)]:HS(l)),v=m!=="none";!h&&v&&C.push(...KS(l,g,m,S));const E=[l,...C],M=await c.detectOverflow(e,y),T=[];let A=((o=s.flip)==null?void 0:o.overflows)||[];if(u&&T.push(M[k]),f){const z=FS(r,i,S);T.push(M[z[0]],M[z[1]])}if(A=[...A,{placement:r,overflows:T}],!T.every(z=>z<=0)){var B,I;const z=(((B=s.flip)==null?void 0:B.index)||0)+1,$=E[z];if($&&(!(f==="alignment"?x!==cn($):!1)||A.every(K=>cn(K.placement)===x?K.overflows[0]>0:!0)))return{data:{index:z,overflows:A},reset:{placement:$}};let J=(I=A.filter(j=>j.overflows[0]<=0).sort((j,K)=>j.overflows[1]-K.overflows[1])[0])==null?void 0:I.placement;if(!J)switch(p){case"bestFit":{var O;const j=(O=A.filter(K=>{if(v){const W=cn(K.placement);return W===x||W==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(W=>W>0).reduce((W,X)=>W+X,0)]).sort((K,W)=>K[1]-W[1])[0])==null?void 0:O[0];j&&(J=j);break}case"initialPlacement":J=l;break}if(r!==J)return{reset:{placement:J}}}return{}}}},QS=new Set(["left","top"]);async function ZS(n,e){const{placement:t,platform:o,elements:r}=n,s=await(o.isRTL==null?void 0:o.isRTL(r.floating)),i=Vn(t),l=Xs(t),c=cn(t)==="y",d=QS.has(i)?-1:1,u=s&&c?-1:1,f=Ys(e,n);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return l&&typeof m=="number"&&(p=l==="end"?m*-1:m),c?{x:p*u,y:h*d}:{x:h*d,y:p*u}}const ex=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(e){var t,o;const{x:r,y:s,placement:i,middlewareData:l}=e,c=await ZS(e,n);return i===((t=l.offset)==null?void 0:t.placement)&&(o=l.arrow)!=null&&o.alignmentOffset?{}:{x:r+c.x,y:s+c.y,data:{...c,placement:i}}}}},tx=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(e){const{x:t,y:o,placement:r,platform:s}=e,{mainAxis:i=!0,crossAxis:l=!1,limiter:c={fn:k=>{let{x,y:b}=k;return{x,y:b}}},...d}=Ys(n,e),u={x:t,y:o},f=await s.detectOverflow(e,d),h=cn(Vn(r)),p=bp(h);let m=u[p],g=u[h];if(i){const k=p==="y"?"top":"left",x=p==="y"?"bottom":"right",b=m+f[k],S=m-f[x];m=wp(b,m,S)}if(l){const k=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=g+f[k],S=g-f[x];g=wp(b,g,S)}const y=c.fn({...e,[p]:m,[h]:g});return{...y,data:{x:y.x-t,y:y.y-o,enabled:{[p]:i,[h]:l}}}}}};function ei(){return typeof window<"u"}function $n(n){return Ma(n)?(n.nodeName||"").toLowerCase():"#document"}function Je(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function xt(n){var e;return(e=(Ma(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function Ma(n){return ei()?n instanceof Node||n instanceof Je(n).Node:!1}function at(n){return ei()?n instanceof Element||n instanceof Je(n).Element:!1}function Ct(n){return ei()?n instanceof HTMLElement||n instanceof Je(n).HTMLElement:!1}function Mp(n){return!ei()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof Je(n).ShadowRoot}const nx=new Set(["inline","contents"]);function ur(n){const{overflow:e,overflowX:t,overflowY:o,display:r}=ct(n);return/auto|scroll|overlay|hidden|clip/.test(e+o+t)&&!nx.has(r)}const ox=new Set(["table","td","th"]);function rx(n){return ox.has($n(n))}const sx=[":popover-open",":modal"];function ti(n){return sx.some(e=>{try{return n.matches(e)}catch{return!1}})}const ix=["transform","translate","scale","rotate","perspective"],lx=["transform","translate","scale","rotate","perspective","filter"],ax=["paint","layout","strict","content"];function Ta(n){const e=Na(),t=at(n)?ct(n):n;return ix.some(o=>t[o]?t[o]!=="none":!1)||(t.containerType?t.containerType!=="normal":!1)||!e&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!e&&(t.filter?t.filter!=="none":!1)||lx.some(o=>(t.willChange||"").includes(o))||ax.some(o=>(t.contain||"").includes(o))}function cx(n){let e=dn(n);for(;Ct(e)&&!co(e);){if(Ta(e))return e;if(ti(e))return null;e=dn(e)}return null}function Na(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const dx=new Set(["html","body","#document"]);function co(n){return dx.has($n(n))}function ct(n){return Je(n).getComputedStyle(n)}function ni(n){return at(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function dn(n){if($n(n)==="html")return n;const e=n.assignedSlot||n.parentNode||Mp(n)&&n.host||xt(n);return Mp(e)?e.host:e}function Tp(n){const e=dn(n);return co(e)?n.ownerDocument?n.ownerDocument.body:n.body:Ct(e)&&ur(e)?e:Tp(e)}function fr(n,e,t){var o;e===void 0&&(e=[]),t===void 0&&(t=!0);const r=Tp(n),s=r===((o=n.ownerDocument)==null?void 0:o.body),i=Je(r);if(s){const l=Aa(i);return e.concat(i,i.visualViewport||[],ur(r)?r:[],l&&t?fr(l):[])}return e.concat(r,fr(r,[],t))}function Aa(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function Np(n){const e=ct(n);let t=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=Ct(n),s=r?n.offsetWidth:t,i=r?n.offsetHeight:o,l=Js(t)!==s||Js(o)!==i;return l&&(t=s,o=i),{width:t,height:o,$:l}}function Ba(n){return at(n)?n:n.contextElement}function uo(n){const e=Ba(n);if(!Ct(e))return St(1);const t=e.getBoundingClientRect(),{width:o,height:r,$:s}=Np(e);let i=(s?Js(t.width):t.width)/o,l=(s?Js(t.height):t.height)/r;return(!i||!Number.isFinite(i))&&(i=1),(!l||!Number.isFinite(l))&&(l=1),{x:i,y:l}}const ux=St(0);function Ap(n){const e=Je(n);return!Na()||!e.visualViewport?ux:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function fx(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==Je(n)?!1:e}function zn(n,e,t,o){e===void 0&&(e=!1),t===void 0&&(t=!1);const r=n.getBoundingClientRect(),s=Ba(n);let i=St(1);e&&(o?at(o)&&(i=uo(o)):i=uo(n));const l=fx(s,t,o)?Ap(s):St(0);let c=(r.left+l.x)/i.x,d=(r.top+l.y)/i.y,u=r.width/i.x,f=r.height/i.y;if(s){const h=Je(s),p=o&&at(o)?Je(o):o;let m=h,g=Aa(m);for(;g&&o&&p!==m;){const y=uo(g),k=g.getBoundingClientRect(),x=ct(g),b=k.left+(g.clientLeft+parseFloat(x.paddingLeft))*y.x,S=k.top+(g.clientTop+parseFloat(x.paddingTop))*y.y;c*=y.x,d*=y.y,u*=y.x,f*=y.y,c+=b,d+=S,m=Je(g),g=Aa(m)}}return Zs({width:u,height:f,x:c,y:d})}function oi(n,e){const t=ni(n).scrollLeft;return e?e.left+t:zn(xt(n)).left+t}function Bp(n,e){const t=n.getBoundingClientRect(),o=t.left+e.scrollLeft-oi(n,t),r=t.top+e.scrollTop;return{x:o,y:r}}function hx(n){let{elements:e,rect:t,offsetParent:o,strategy:r}=n;const s=r==="fixed",i=xt(o),l=e?ti(e.floating):!1;if(o===i||l&&s)return t;let c={scrollLeft:0,scrollTop:0},d=St(1);const u=St(0),f=Ct(o);if((f||!f&&!s)&&(($n(o)!=="body"||ur(i))&&(c=ni(o)),Ct(o))){const p=zn(o);d=uo(o),u.x=p.x+o.clientLeft,u.y=p.y+o.clientTop}const h=i&&!f&&!s?Bp(i,c):St(0);return{width:t.width*d.x,height:t.height*d.y,x:t.x*d.x-c.scrollLeft*d.x+u.x+h.x,y:t.y*d.y-c.scrollTop*d.y+u.y+h.y}}function px(n){return Array.from(n.getClientRects())}function mx(n){const e=xt(n),t=ni(n),o=n.ownerDocument.body,r=Ln(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),s=Ln(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let i=-t.scrollLeft+oi(n);const l=-t.scrollTop;return ct(o).direction==="rtl"&&(i+=Ln(e.clientWidth,o.clientWidth)-r),{width:r,height:s,x:i,y:l}}const Ip=25;function gx(n,e){const t=Je(n),o=xt(n),r=t.visualViewport;let s=o.clientWidth,i=o.clientHeight,l=0,c=0;if(r){s=r.width,i=r.height;const u=Na();(!u||u&&e==="fixed")&&(l=r.offsetLeft,c=r.offsetTop)}const d=oi(o);if(d<=0){const u=o.ownerDocument,f=u.body,h=getComputedStyle(f),p=u.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(o.clientWidth-f.clientWidth-p);m<=Ip&&(s-=m)}else d<=Ip&&(s+=d);return{width:s,height:i,x:l,y:c}}const yx=new Set(["absolute","fixed"]);function kx(n,e){const t=zn(n,!0,e==="fixed"),o=t.top+n.clientTop,r=t.left+n.clientLeft,s=Ct(n)?uo(n):St(1),i=n.clientWidth*s.x,l=n.clientHeight*s.y,c=r*s.x,d=o*s.y;return{width:i,height:l,x:c,y:d}}function Op(n,e,t){let o;if(e==="viewport")o=gx(n,t);else if(e==="document")o=mx(xt(n));else if(at(e))o=kx(e,t);else{const r=Ap(n);o={x:e.x-r.x,y:e.y-r.y,width:e.width,height:e.height}}return Zs(o)}function _p(n,e){const t=dn(n);return t===e||!at(t)||co(t)?!1:ct(t).position==="fixed"||_p(t,e)}function wx(n,e){const t=e.get(n);if(t)return t;let o=fr(n,[],!1).filter(l=>at(l)&&$n(l)!=="body"),r=null;const s=ct(n).position==="fixed";let i=s?dn(n):n;for(;at(i)&&!co(i);){const l=ct(i),c=Ta(i);!c&&l.position==="fixed"&&(r=null),(s?!c&&!r:!c&&l.position==="static"&&!!r&&yx.has(r.position)||ur(i)&&!c&&_p(n,i))?o=o.filter(u=>u!==i):r=l,i=dn(i)}return e.set(n,o),o}function bx(n){let{element:e,boundary:t,rootBoundary:o,strategy:r}=n;const i=[...t==="clippingAncestors"?ti(e)?[]:wx(e,this._c):[].concat(t),o],l=i[0],c=i.reduce((d,u)=>{const f=Op(e,u,r);return d.top=Ln(f.top,d.top),d.right=qs(f.right,d.right),d.bottom=qs(f.bottom,d.bottom),d.left=Ln(f.left,d.left),d},Op(e,l,r));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Sx(n){const{width:e,height:t}=Np(n);return{width:e,height:t}}function xx(n,e,t){const o=Ct(e),r=xt(e),s=t==="fixed",i=zn(n,!0,s,e);let l={scrollLeft:0,scrollTop:0};const c=St(0);function d(){c.x=oi(r)}if(o||!o&&!s)if(($n(e)!=="body"||ur(r))&&(l=ni(e)),o){const p=zn(e,!0,s,e);c.x=p.x+e.clientLeft,c.y=p.y+e.clientTop}else r&&d();s&&!o&&r&&d();const u=r&&!o&&!s?Bp(r,l):St(0),f=i.left+l.scrollLeft-c.x-u.x,h=i.top+l.scrollTop-c.y-u.y;return{x:f,y:h,width:i.width,height:i.height}}function Ia(n){return ct(n).position==="static"}function Dp(n,e){if(!Ct(n)||ct(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return xt(n)===t&&(t=t.ownerDocument.body),t}function Rp(n,e){const t=Je(n);if(ti(n))return t;if(!Ct(n)){let r=dn(n);for(;r&&!co(r);){if(at(r)&&!Ia(r))return r;r=dn(r)}return t}let o=Dp(n,e);for(;o&&rx(o)&&Ia(o);)o=Dp(o,e);return o&&co(o)&&Ia(o)&&!Ta(o)?t:o||cx(n)||t}const Cx=async function(n){const e=this.getOffsetParent||Rp,t=this.getDimensions,o=await t(n.floating);return{reference:xx(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function Ex(n){return ct(n).direction==="rtl"}const vx={convertOffsetParentRelativeRectToViewportRelativeRect:hx,getDocumentElement:xt,getClippingRect:bx,getOffsetParent:Rp,getElementRects:Cx,getClientRects:px,getDimensions:Sx,getScale:uo,isElement:at,isRTL:Ex};function Pp(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function Mx(n,e){let t=null,o;const r=xt(n);function s(){var l;clearTimeout(o),(l=t)==null||l.disconnect(),t=null}function i(l,c){l===void 0&&(l=!1),c===void 0&&(c=1),s();const d=n.getBoundingClientRect(),{left:u,top:f,width:h,height:p}=d;if(l||e(),!h||!p)return;const m=Gs(f),g=Gs(r.clientWidth-(u+h)),y=Gs(r.clientHeight-(f+p)),k=Gs(u),b={rootMargin:-m+"px "+-g+"px "+-y+"px "+-k+"px",threshold:Ln(0,qs(1,c))||1};let S=!0;function C(v){const E=v[0].intersectionRatio;if(E!==c){if(!S)return i();E?i(!1,E):o=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Pp(d,n.getBoundingClientRect())&&i(),S=!1}try{t=new IntersectionObserver(C,{...b,root:r.ownerDocument})}catch{t=new IntersectionObserver(C,b)}t.observe(n)}return i(!0),s}function ri(n,e,t,o){o===void 0&&(o={});const{ancestorScroll:r=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:c=!1}=o,d=Ba(n),u=r||s?[...d?fr(d):[],...fr(e)]:[];u.forEach(k=>{r&&k.addEventListener("scroll",t,{passive:!0}),s&&k.addEventListener("resize",t)});const f=d&&l?Mx(d,t):null;let h=-1,p=null;i&&(p=new ResizeObserver(k=>{let[x]=k;x&&x.target===d&&p&&(p.unobserve(e),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var b;(b=p)==null||b.observe(e)})),t()}),d&&!c&&p.observe(d),p.observe(e));let m,g=c?zn(n):null;c&&y();function y(){const k=zn(n);g&&!Pp(g,k)&&t(),g=k,m=requestAnimationFrame(y)}return t(),()=>{var k;u.forEach(x=>{r&&x.removeEventListener("scroll",t),s&&x.removeEventListener("resize",t)}),f==null||f(),(k=p)==null||k.disconnect(),p=null,c&&cancelAnimationFrame(m)}}const fo=ex,ho=tx,po=XS,Tx=(n,e,t)=>{const o=new Map,r={platform:vx,...t},s={...r.platform,_c:o};return YS(n,e,{...r,platform:s})};function Nx(n){return n!=null&&typeof n=="object"&&"$el"in n}function Lp(n){if(Nx(n)){const e=n.$el;return Ma(e)&&$n(e)==="#comment"?null:e}return n}function hr(n){return typeof n=="function"?n():a.unref(n)}function Vp(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function $p(n,e){const t=Vp(n);return Math.round(e*t)/t}function mo(n,e,t){t===void 0&&(t={});const o=t.whileElementsMounted,r=a.computed(()=>{var E;return(E=hr(t.open))!=null?E:!0}),s=a.computed(()=>hr(t.middleware)),i=a.computed(()=>{var E;return(E=hr(t.placement))!=null?E:"bottom"}),l=a.computed(()=>{var E;return(E=hr(t.strategy))!=null?E:"absolute"}),c=a.computed(()=>{var E;return(E=hr(t.transform))!=null?E:!0}),d=a.computed(()=>Lp(n.value)),u=a.computed(()=>Lp(e.value)),f=a.ref(0),h=a.ref(0),p=a.ref(l.value),m=a.ref(i.value),g=a.shallowRef({}),y=a.ref(!1),k=a.computed(()=>{const E={position:p.value,left:"0",top:"0"};if(!u.value)return E;const M=$p(u.value,f.value),T=$p(u.value,h.value);return c.value?{...E,transform:"translate("+M+"px, "+T+"px)",...Vp(u.value)>=1.5&&{willChange:"transform"}}:{position:p.value,left:M+"px",top:T+"px"}});let x;function b(){if(d.value==null||u.value==null)return;const E=r.value;Tx(d.value,u.value,{middleware:s.value,placement:i.value,strategy:l.value}).then(M=>{f.value=M.x,h.value=M.y,p.value=M.strategy,m.value=M.placement,g.value=M.middlewareData,y.value=E!==!1})}function S(){typeof x=="function"&&(x(),x=void 0)}function C(){if(S(),o===void 0){b();return}if(d.value!=null&&u.value!=null){x=o(d.value,u.value,b);return}}function v(){r.value||(y.value=!1)}return a.watch([s,i,l,r],b,{flush:"sync"}),a.watch([d,u],C,{flush:"sync"}),a.watch(r,v,{flush:"sync"}),a.getCurrentScope()&&a.onScopeDispose(S),{x:a.shallowReadonly(f),y:a.shallowReadonly(h),strategy:a.shallowReadonly(p),placement:a.shallowReadonly(m),middlewareData:a.shallowReadonly(g),isPositioned:a.shallowReadonly(y),floatingStyles:k,update:b}}const Ax=["menu-open"],Ue=a.defineComponent({__name:"MenuDropdown",props:{title:{},disabled:{type:Boolean},placement:{default:"top"},offsetPx:{default:8}},emits:["open","close"],setup(n,{emit:e}){const t=n,o=e,r=a.inject("containerRef"),s=a.inject(Ec,null),i=a.inject(vc,0),l=Math.random().toString(36).slice(2);a.provide(vc,i+1);const{show:c,hide:d}=zt(),u=a.ref(!1);s&&a.watch(()=>s.value.get(i),b=>{b!==void 0&&b!==l&&u.value&&(u.value=!1)});const f=a.ref(null),h=a.ref(null),{floatingStyles:p}=mo(f,h,{placement:t.placement,middleware:[fo(t.offsetPx),po(),ho({padding:8})],whileElementsMounted:ri});function m(){t.disabled||(u.value=!u.value)}function g(){u.value=!1}function y(b){var M,T,A;const S=b.target,C=(M=f.value)==null?void 0:M.contains(S),v=(T=h.value)==null?void 0:T.contains(S),E=(A=S.closest)==null?void 0:A.call(S,".wov-menu-dropdown");!C&&!v&&!E&&g()}function k(){t.title&&f.value&&!u.value&&c(t.title,f.value)}function x(){d()}return a.watch(u,b=>{b?(d(),document.addEventListener("click",y,!0),s&&(s.value.set(i,l),s.value=new Map(s.value)),o("open")):(document.removeEventListener("click",y,!0),(s==null?void 0:s.value.get(i))===l&&(s.value.delete(i),s.value=new Map(s.value)),o("close"))}),a.onUnmounted(()=>{document.removeEventListener("click",y,!0)}),(b,S)=>(a.openBlock(),a.createElementBlock(a.Fragment,null,[a.createElementVNode("div",{ref_key:"buttonRef",ref:f,class:a.normalizeClass(["wov-menu-dropdown-trigger",{"is-open":u.value}]),"menu-open":u.value||void 0,onMousedown:S[0]||(S[0]=a.withModifiers(()=>{},["prevent"])),onClick:m,onMouseenter:k,onMouseleave:x},[a.renderSlot(b.$slots,"button",{isOpen:u.value})],42,Ax),a.unref(r)?(a.openBlock(),a.createBlock(a.Teleport,{key:0,to:a.unref(r)},[u.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"dropdownRef",ref:h,class:"wov-menu-dropdown",style:a.normalizeStyle(a.unref(p))},[a.renderSlot(b.$slots,"dropdown",{close:g})],4)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)],64))}}),Bx={},Ix={viewBox:"0 0 512 320",fill:"currentColor",style:{width:"7px",color:"var(--wov-gray-300)"}};function Ox(n,e){return a.openBlock(),a.createElementBlock("svg",Ix,[...e[0]||(e[0]=[a.createElementVNode("path",{d:"M233.4 278.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 210.7 86.6 41.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"},null,-1)])])}const Ge=kn(Bx,[["render",Ox]]),_x={class:"wov-menu-button"},Dx=["innerHTML"],Rx=["onClick"],Px=["innerHTML"],Oa=a.defineComponent({__name:"ArrowHeadButton",props:{entityIds:{},side:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=a.shallowRef(null),r=a.computed(()=>{const l=o.value??(e.side==="start"?te.ArrowHeadKind.None:te.ArrowHeadKind.V);return Kn(l)});t(l=>{let c=null;for(const d of e.entityIds){if(w.hasComponent(l,d,te.ElbowArrow)){const u=te.ElbowArrow.read(l,d),f=e.side==="start"?u.startArrowHead:u.endArrowHead;if(c===null)c=f;else if(f!==c){o.value=e.side==="start"?te.ArrowHeadKind.None:te.ArrowHeadKind.V;return}}if(w.hasComponent(l,d,te.ArcArrow)){const u=te.ArcArrow.read(l,d),f=e.side==="start"?u.startArrowHead:u.endArrowHead;if(c===null)c=f;else if(f!==c){o.value=e.side==="start"?te.ArrowHeadKind.None:te.ArrowHeadKind.V;return}}}o.value=c});function s(l){o.value=l,t(c=>{for(const d of e.entityIds){if(w.hasComponent(c,d,te.ElbowArrow)){const u=te.ElbowArrow.write(c,d);e.side==="start"?u.startArrowHead=l:u.endArrowHead=l}if(w.hasComponent(c,d,te.ArcArrow)){const u=te.ArcArrow.write(c,d);e.side==="start"?u.startArrowHead=l:u.endArrowHead=l}}})}function i(l){if(!l)return"";const c=e.side==="start";return`<line x1="${c?8:4}" y1="12" x2="${c?20:16}" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round" /><g transform="${`translate(${c?4:20}, 12) scale(${c?"-0.8, 0.8":"0.8"})`}">${l.svg}</g>`}return(l,c)=>(a.openBlock(),a.createBlock(Ue,{title:n.side==="start"?"Start Arrow Head":"End Arrow Head"},{button:a.withCtx(()=>[a.createElementVNode("div",_x,[(a.openBlock(),a.createElementBlock("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",innerHTML:i(r.value)},null,8,Dx)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(a.unref(Ei),d=>(a.openBlock(),a.createElementBlock("button",{key:d.kind,class:a.normalizeClass(["wov-menu-option",{"is-active":o.value===d.kind}]),onClick:u=>s(d.kind)},[(a.openBlock(),a.createElementBlock("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",innerHTML:i(d)},null,8,Px))],10,Rx))),128))]),_:1},8,["title"]))}}),Lx={class:"wov-menu-button"},Vx=["onClick"],zp=a.defineComponent({__name:"ArrowThicknessButton",props:{entityIds:{}},setup(n){const e=[{label:"S",value:2},{label:"M",value:4},{label:"L",value:8}],t=n,{nextEditorTick:o}=le(),r=a.shallowRef(null);o(i=>{let l=null;for(const c of t.entityIds){if(w.hasComponent(i,c,te.ElbowArrow)){const d=te.ElbowArrow.read(i,c);if(l===null)l=d.thickness;else if(d.thickness!==l){r.value=null;return}}if(w.hasComponent(i,c,te.ArcArrow)){const d=te.ArcArrow.getThickness(i,c);if(l===null)l=d;else if(d!==l){r.value=null;return}}}r.value=l});function s(i){r.value=i,o(l=>{for(const c of t.entityIds){if(w.hasComponent(l,c,te.ElbowArrow)){const d=te.ElbowArrow.write(l,c);d.thickness=i}w.hasComponent(l,c,te.ArcArrow)&&te.ArcArrow.setThickness(l,c,i)}})}return(i,l)=>(a.openBlock(),a.createBlock(Ue,{title:"Thickness"},{button:a.withCtx(()=>[a.createElementVNode("div",Lx,[l[0]||(l[0]=a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-linecap":"round"},[a.createElementVNode("line",{x1:"4",y1:"5",x2:"20",y2:"5","stroke-width":"1"}),a.createElementVNode("line",{x1:"4",y1:"11",x2:"20",y2:"11","stroke-width":"2.5"}),a.createElementVNode("line",{x1:"4",y1:"19",x2:"20",y2:"19","stroke-width":"4"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(e,c=>a.createElementVNode("button",{key:c.value,class:a.normalizeClass(["wov-menu-option wov-arrow-thickness-option",{"is-active":r.value===c.value}]),onClick:d=>s(c.value)},a.toDisplayString(c.label),11,Vx)),64))]),_:1}))}}),un=a.defineComponent({__name:"MenuButton",props:{title:{}},emits:["click"],setup(n,{emit:e}){const t=n,o=e,r=a.ref(null),s=a.ref(!1),{show:i,hide:l}=zt();function c(f){o("click",f)}function d(){s.value=!0,t.title&&r.value&&i(t.title,r.value)}function u(){s.value=!1,l()}return a.watch(()=>t.title,f=>{!s.value||!f||!r.value||i(f,r.value)}),(f,h)=>(a.openBlock(),a.createElementBlock("button",{ref_key:"buttonRef",ref:r,class:"wov-menu-button",onClick:c,onMouseenter:d,onMouseleave:u},[a.renderSlot(f.$slots,"default")],544))}}),$x={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},Fp=a.defineComponent({__name:"AspectLockButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=Me(w.TransformBoxStateSingleton),r=wt(()=>e.entityIds,w.Block),s=a.computed(()=>{for(const l of r.value.values())if((l==null?void 0:l.resizeMode)===w.ResizeMode.Free)return!1;return!0});function i(){const l=s.value?w.ResizeMode.Free:w.ResizeMode.Default;t(c=>{for(const u of e.entityIds){const f=w.Block.write(c,u);f.resizeMode=l}const{transformBoxId:d}=o.value;d!==null&&w.UpdateTransformBox.spawn(c,{transformBoxId:d})})}return(l,c)=>(a.openBlock(),a.createBlock(un,{title:s.value?"Unlock aspect ratio":"Lock aspect ratio",onClick:i},{default:a.withCtx(()=>[(a.openBlock(),a.createElementBlock("svg",$x,[c[12]||(c[12]=a.createElementVNode("rect",{x:"7",y:"8",width:"10",height:"8",rx:"1"},null,-1)),s.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:0},[c[0]||(c[0]=a.createElementVNode("path",{d:"M3 7V5a2 2 0 0 1 2-2h2"},null,-1)),c[1]||(c[1]=a.createElementVNode("path",{d:"M17 3h2a2 2 0 0 1 2 2v2"},null,-1)),c[2]||(c[2]=a.createElementVNode("path",{d:"M21 17v2a2 2 0 0 1-2 2h-2"},null,-1)),c[3]||(c[3]=a.createElementVNode("path",{d:"M7 21H5a2 2 0 0 1-2-2v-2"},null,-1))],64)):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[c[4]||(c[4]=a.createElementVNode("path",{d:"M3 6V3h3"},null,-1)),c[5]||(c[5]=a.createElementVNode("path",{d:"m6 6-3-3"},null,-1)),c[6]||(c[6]=a.createElementVNode("path",{d:"M21 6V3h-3"},null,-1)),c[7]||(c[7]=a.createElementVNode("path",{d:"m18 6 3-3"},null,-1)),c[8]||(c[8]=a.createElementVNode("path",{d:"M3 18v3h3"},null,-1)),c[9]||(c[9]=a.createElementVNode("path",{d:"m6 18-3 3"},null,-1)),c[10]||(c[10]=a.createElementVNode("path",{d:"M21 18v3h-3"},null,-1)),c[11]||(c[11]=a.createElementVNode("path",{d:"m18 18 3 3"},null,-1))],64))]))]),_:1},8,["title"]))}}),zx={class:"wov-block-operations-dropdown"},Fx=["onClick"],Hx={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},jx=["d"],Hp=a.defineComponent({__name:"BlockOperationsButton",setup(n){const e=[{label:"Duplicate",command:w.DuplicateSelected,iconPaths:["M10 8h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2z","M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"]},{label:"Bring forward",command:w.BringForwardSelected,iconPaths:["M5 3h14","m18 13-6-6-6 6","M12 7v14"]},{label:"Send backward",command:w.SendBackwardSelected,iconPaths:["M12 17V3","m6 11 6 6 6-6","M19 21H5"]},{label:"Delete",command:w.RemoveSelected,iconPaths:["M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6","M3 6h18","M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"],danger:!0}],{getEditor:t}=le();function o(r,s){var i;(i=t())==null||i.command(r.command),s()}return(r,s)=>(a.openBlock(),a.createBlock(Ue,{title:"More"},{button:a.withCtx(()=>[...s[0]||(s[0]=[a.createElementVNode("div",{class:"wov-block-operations-button"},[a.createElementVNode("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("circle",{cx:"5",cy:"12",r:"1"}),a.createElementVNode("circle",{cx:"12",cy:"12",r:"1"}),a.createElementVNode("circle",{cx:"19",cy:"12",r:"1"})])],-1)])]),dropdown:a.withCtx(({close:i})=>[a.createElementVNode("div",zx,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(e,l=>a.createElementVNode("button",{key:l.label,class:a.normalizeClass(["wov-block-operations-option",{"is-danger":l.danger}]),onClick:c=>o(l,i)},[(a.openBlock(),a.createElementBlock("svg",Hx,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(l.iconPaths,c=>(a.openBlock(),a.createElementBlock("path",{key:c,d:c},null,8,jx))),128))])),a.createElementVNode("span",null,a.toDisplayString(l.label),1)],10,Fx)),64))])]),_:1}))}}),Ux=["value"],Wx=a.defineComponent({__name:"ColorInput",props:{modelValue:{}},emits:["update:modelValue"],setup(n,{emit:e}){const t=n,o=e,r=a.ref(t.modelValue??"");a.watch(()=>t.modelValue,u=>{u&&u!==r.value&&(r.value=u)});function s(u){const f=u.startsWith("#")?u:`#${u}`;return/^#[0-9A-Fa-f]{6}$/.test(f)}function i(u){return(u.startsWith("#")?u:`#${u}`).toLowerCase()}function l(u){let h=u.target.value;if((h.length===6||h.length===7)&&s(h)){const p=i(h);r.value=p,o("update:modelValue",p)}}function c(u){const h=u.target.value;if(h&&s(h)){const p=i(h);r.value=p,o("update:modelValue",p)}else t.modelValue&&(r.value=t.modelValue)}function d(u){if(u.stopPropagation(),u.key==="Enter"){const f=u.target,h=f.value;if(h&&s(h)){const p=i(h);r.value=p,o("update:modelValue",p),setTimeout(()=>f.select())}}}return(u,f)=>(a.openBlock(),a.createElementBlock("input",{id:"wov-color-input",class:"wov-color-input",type:"text",size:"1","aria-label":"Hex color value",autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",value:r.value,onInput:l,onChange:c,onKeydown:d},null,40,Ux))}}),jp=a.defineComponent({__name:"ColorSlider",props:{modelValue:{},thumbColor:{},background:{}},emits:["update:modelValue"],setup(n,{expose:e,emit:t}){const o=t,r=a.ref(null),s=a.ref(!1);function i(d){s.value=!0,l(d),window.addEventListener("pointermove",l),window.addEventListener("pointerup",c)}function l(d){if(!r.value)return;const u=r.value.getBoundingClientRect(),f=Math.max(0,Math.min(100,(d.clientY-u.top)/u.height*100));o("update:modelValue",f)}function c(){s.value=!1,window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",c)}return e({isDragging:s}),(d,u)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"sliderRef",ref:r,class:"wov-color-slider",onPointerdown:a.withModifiers(i,["prevent"])},[n.background?(a.openBlock(),a.createElementBlock("div",{key:0,class:"wov-color-slider-gradient",style:a.normalizeStyle({background:n.background})},null,4)):a.createCommentVNode("",!0),a.createElementVNode("div",{class:"wov-color-slider-thumb",style:a.normalizeStyle({top:`${n.modelValue}%`,backgroundColor:n.thumbColor})},null,4)],544))}}),Kx={class:"wov-color-picker"},qx={class:"wov-color-picker-area"},Jx={class:"wov-color-picker-selector-gradient"},Gx="linear-gradient(to bottom, red 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%)",Up=a.defineComponent({__name:"ColorPicker",props:{modelValue:{},withOpacity:{type:Boolean}},emits:["update:modelValue"],setup(n,{emit:e}){const t=n,o=e,r=a.ref(null),s=a.ref(null),i=a.ref(null),l=a.ref({x:100,y:0}),c=a.ref(0),d=a.ref(0),u=a.ref(!1),f=a.computed(()=>{var v,E;return u.value||((v=r.value)==null?void 0:v.isDragging)||((E=s.value)==null?void 0:E.isDragging)}),h=a.computed(()=>({h:c.value/100*360,s:l.value.x,v:100-l.value.y,a:(100-d.value)/100*255})),p=a.computed(()=>Zh({h:h.value.h,s:100,v:100})),m=a.computed(()=>Zh({h:h.value.h,s:h.value.s,v:h.value.v})),g=a.computed(()=>t.withOpacity?ep(h.value):m.value),y=a.computed(()=>`linear-gradient(to top, transparent 0%, ${m.value} 100%)`);function k(v){if(v){const E=Qh(v);l.value={x:E.s,y:100-E.v},c.value=E.h/360*100,d.value=100-E.a/255*100}}function x(v){k(v),o("update:modelValue",t.withOpacity?ep(Qh(v)):v)}k(t.modelValue),a.watch(()=>t.modelValue,v=>{f.value||k(v)}),a.watch([l,c,d],()=>{f.value&&o("update:modelValue",g.value)});function b(v){u.value=!0,S(v),window.addEventListener("pointermove",S),window.addEventListener("pointerup",C)}function S(v){if(!i.value)return;const E=i.value.getBoundingClientRect(),M=Math.max(0,Math.min(100,(v.clientX-E.left)/E.width*100)),T=Math.max(0,Math.min(100,(v.clientY-E.top)/E.height*100));l.value={x:M,y:T}}function C(){u.value=!1,window.removeEventListener("pointermove",S),window.removeEventListener("pointerup",C)}return(v,E)=>(a.openBlock(),a.createElementBlock("div",Kx,[a.createVNode(Wx,{modelValue:g.value,"onUpdate:modelValue":x},null,8,["modelValue"]),a.createElementVNode("div",qx,[a.createElementVNode("div",{ref_key:"selectorRef",ref:i,class:"wov-color-picker-selector",style:a.normalizeStyle({backgroundColor:p.value}),onPointerdown:a.withModifiers(b,["prevent"])},[a.createElementVNode("div",Jx,[a.createElementVNode("div",{class:"wov-color-picker-selector-thumb",style:a.normalizeStyle({left:`${l.value.x}%`,top:`${l.value.y}%`,backgroundColor:m.value})},null,4)])],36),a.createVNode(jp,{ref_key:"hueSliderRef",ref:r,modelValue:c.value,"onUpdate:modelValue":E[0]||(E[0]=M=>c.value=M),thumbColor:p.value,background:Gx},null,8,["modelValue","thumbColor"]),n.withOpacity?(a.openBlock(),a.createBlock(jp,{key:0,ref_key:"opacitySliderRef",ref:s,modelValue:d.value,"onUpdate:modelValue":E[1]||(E[1]=M=>d.value=M),thumbColor:m.value,background:y.value,class:"wov-color-picker-opacity"},null,8,["modelValue","thumbColor","background"])):a.createCommentVNode("",!0)])]))}}),Yx={class:"wov-color-bubbles-container"},Xx={key:1,class:"wov-color-bubbles"},Qx=["onClick"],si=a.defineComponent({__name:"ColorBubbles",props:{currentColor:{},palette:{},hideHighlight:{type:Boolean},withPicker:{type:Boolean},withOpacity:{type:Boolean}},emits:["change","picker-open"],setup(n,{emit:e}){const t=n,o=e,r=["#000000","#374151","#6B7280","#9CA3AF","#D1D5DB","#FFFFFF","#EF4444","#F97316","#EAB308","#22C55E","#14B8A6","#3B82F6","#8B5CF6","#EC4899"],s=a.computed(()=>{const m=t.palette??r,g=t.withPicker,y=m.length%2===1;return g&&!y||!g&&y?m.slice(0,-1):m}),i=a.ref(!1),l=a.ref(t.currentColor??"#ff0000");function c(m,g){const y=k=>{const x=k.replace(/^#/,"").toLowerCase();return x.length===6?`${x}ff`:x};return y(m)===y(g)}function d(m){return t.hideHighlight||!t.currentColor?!1:c(t.currentColor,m)}function u(){return t.hideHighlight||!t.currentColor?!1:!s.value.some(m=>c(t.currentColor,m))}function f(m){const g=ma(m);g&&o("change",g)}function h(){!i.value&&t.currentColor&&(l.value=t.currentColor),i.value=!i.value,o("picker-open",i.value)}function p(m){l.value=m;const g=ma(m);g&&o("change",g)}return(m,g)=>(a.openBlock(),a.createElementBlock("div",Yx,[i.value?(a.openBlock(),a.createBlock(Up,{key:0,modelValue:l.value,"onUpdate:modelValue":[g[0]||(g[0]=y=>l.value=y),p],withOpacity:n.withOpacity},null,8,["modelValue","withOpacity"])):(a.openBlock(),a.createElementBlock("div",Xx,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(s.value,y=>(a.openBlock(),a.createElementBlock("div",{key:y,class:a.normalizeClass(["wov-color-bubble",{selected:d(y)}]),style:a.normalizeStyle({backgroundColor:y}),onMousedown:g[1]||(g[1]=a.withModifiers(()=>{},["prevent"])),onClick:k=>f(y)},null,46,Qx))),128)),n.withPicker?(a.openBlock(),a.createElementBlock("div",{key:0,class:a.normalizeClass(["wov-color-bubble wov-rainbow-bubble",{selected:u()}]),onMousedown:g[2]||(g[2]=a.withModifiers(()=>{},["prevent"])),onClick:h},null,34)):a.createCommentVNode("",!0)]))]))}}),Zx={class:"wov-color-button"},eC={class:"wov-color-swatch"},Wp=a.defineComponent({__name:"ColorButton",props:{entityIds:{},withOpacity:{type:Boolean}},setup(n){const e=n,{nextEditorTick:t}=le(),o=wt(()=>e.entityIds,w.Color),r=a.computed(()=>{const d=new Set;for(const u of o.value.values())if(u){const f=sr(u);d.add(f)}return Array.from(d)}),s=a.computed(()=>r.value.length>1),i=a.computed(()=>r.value[0]??null),l=a.computed(()=>{if(r.value.length===0)return{backgroundColor:"#000"};if(r.value.length>=2){const d=r.value[0],u=r.value[1];return{background:`linear-gradient(45deg, ${d} 0%, ${d} 50%, ${u} 50%, ${u} 100%)`}}return{backgroundColor:r.value[0]}});function c(d){const u=sr(d);t(f=>{for(const h of e.entityIds)w.Color.fromHex(f,h,u)})}return(d,u)=>(a.openBlock(),a.createBlock(Ue,{title:"Color"},{button:a.withCtx(()=>[a.createElementVNode("div",Zx,[a.createElementVNode("div",eC,[a.createElementVNode("div",{class:"wov-color-swatch-fill",style:a.normalizeStyle(l.value)},null,4)]),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createVNode(si,{currentColor:i.value??void 0,hideHighlight:s.value,withPicker:!0,withOpacity:n.withOpacity,onChange:c},null,8,["currentColor","hideHighlight","withOpacity"])]),_:1}))}}),Kp=a.defineComponent({__name:"MenuTooltip",setup(n){const{activeTooltip:e,isVisible:t}=zt(),o=a.ref(null),r=a.computed(()=>{var u;return((u=e.value)==null?void 0:u.anchor)??null}),s=a.computed(()=>{var u;return((u=e.value)==null?void 0:u.placement)??"top"}),{floatingStyles:i}=mo(r,o,{placement:s,middleware:[fo(8),po(),ho({padding:8})]}),l=Symbol("menu-tooltip"),c=a.computed(()=>Ws.value[0]===l);a.onMounted(()=>{Ws.value.push(l)}),a.onUnmounted(()=>{Ws.value=Ws.value.filter(u=>u!==l)});const d=a.computed(()=>{var u;return c.value&&t.value&&((u=e.value)==null?void 0:u.text)});return(u,f)=>(a.openBlock(),a.createBlock(a.Teleport,{to:"body"},[a.createVNode(a.Transition,{name:"wov-tooltip-fade"},{default:a.withCtx(()=>{var h;return[d.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"tooltipRef",ref:o,class:"wov-menu-tooltip",style:a.normalizeStyle(a.unref(i))},a.toDisplayString((h=a.unref(e))==null?void 0:h.text),5)):a.createCommentVNode("",!0)]}),_:1})]))}}),tC={class:"wov-menu-button"},nC=["onClick"],qp=a.defineComponent({__name:"PenStrokeThicknessButton",props:{entityIds:{}},setup(n){const e=[{label:"S",value:4},{label:"M",value:8},{label:"L",value:16}],t=n,{nextEditorTick:o}=le(),r=wt(()=>t.entityIds,yn.PenStroke),s=a.computed(()=>{let c=!1;for(const d of r.value.values())if(d){if(d.kind===yn.PenStrokeKind.Fill)return!1;c=!0}return c}),i=a.computed(()=>{let c=null;for(const d of r.value.values())if(d){if(c===null)c=d.thickness;else if(d.thickness!==c)return null}return c});function l(c){o(d=>{for(const u of t.entityIds){const f=yn.PenStroke.write(d,u);f.thickness=c}})}return(c,d)=>s.value?(a.openBlock(),a.createBlock(Ue,{key:0,title:"Thickness"},{button:a.withCtx(()=>[a.createElementVNode("div",tC,[d[0]||(d[0]=a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-linecap":"round"},[a.createElementVNode("line",{x1:"4",y1:"5",x2:"20",y2:"5","stroke-width":"1"}),a.createElementVNode("line",{x1:"4",y1:"11",x2:"20",y2:"11","stroke-width":"2.5"}),a.createElementVNode("line",{x1:"4",y1:"19",x2:"20",y2:"19","stroke-width":"4"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(e,u=>a.createElementVNode("button",{key:u.value,class:a.normalizeClass(["wov-menu-option wov-pen-thickness-option",{"is-active":i.value===u.value}]),onClick:f=>l(u.value)},a.toDisplayString(u.label),11,nC)),64))]),_:1})):a.createCommentVNode("",!0)}}),oC={class:"wov-fill-color-button"},rC={class:"wov-fill-dropdown"},sC={key:0,class:"wov-fill-mode-section"},iC=["title","onClick"],lC={viewBox:"0 0 24 24",fill:"none"},aC=["fill","fill-opacity","stroke","stroke-width","stroke-dasharray"],Jp=a.defineComponent({__name:"ShapeFillColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t,setDefaults:o}=le(),r=wt(()=>e.entityIds,w.Shape),s=[{mode:"solid",label:"Solid",alpha:255},{mode:"faded",label:"Faded",alpha:128},{mode:"none",label:"None",alpha:0}],i=a.computed(()=>{const m=r.value.values().next().value,g=(m==null?void 0:m.fillAlpha)??255;return g===0?"none":g<200?"faded":"solid"}),l=a.computed(()=>{const m=new Set;for(const g of r.value.values())if(g){const y=g.fillAlpha??255;y===0?m.add("none"):y<200?m.add("faded"):m.add("solid")}return m.size>1});function c(m){o("shape",{fillAlpha:m}),t(g=>{for(const y of e.entityIds){const k=w.Shape.write(g,y);k.fillAlpha=m}})}const d=a.computed(()=>{const m=new Set;for(const g of r.value.values())if(g){const y=sr({red:g.fillRed,green:g.fillGreen,blue:g.fillBlue,alpha:g.fillAlpha??255});m.add(y)}return Array.from(m)}),u=a.computed(()=>d.value.length>1),f=a.computed(()=>d.value[0]??"#4a90d9");function h(m){o("shape",{fillRed:m.red,fillGreen:m.green,fillBlue:m.blue,fillAlpha:m.alpha}),t(g=>{for(const y of e.entityIds){const k=w.Shape.write(g,y);k.fillRed=m.red,k.fillGreen=m.green,k.fillBlue=m.blue,k.fillAlpha=m.alpha}})}const p=a.ref(!1);return(m,g)=>(a.openBlock(),a.createBlock(Ue,{title:"Fill Color"},{button:a.withCtx(()=>[a.createElementVNode("div",oC,[g[1]||(g[1]=a.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-fill-color-icon",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("path",{d:"M5.879,2.625L14.121,2.625C15.906,2.625 17.375,4.094 17.375,5.879L17.375,14.121C17.375,15.906 15.906,17.375 14.121,17.375L5.88,17.375C4.095,17.375 2.626,15.906 2.626,14.121L2.626,5.88C2.626,4.095 4.095,2.626 5.88,2.626L5.879,2.625Z","stroke-width":"1.25"}),a.createElementVNode("path",{d:"M2.779,14.655L14.543,2.871M10.238,17.308L17.318,10.229M2.876,9.577L9.853,2.6M5.397,17.239L17.16,5.476","stroke-width":"1.25"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",rC,[p.value?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",sC,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(s,y=>a.createElementVNode("button",{key:y.mode,class:a.normalizeClass(["wov-fill-mode-option",{"is-active":!l.value&&y.mode===i.value}]),title:y.label,onClick:k=>c(y.alpha)},[(a.openBlock(),a.createElementBlock("svg",lC,[a.createElementVNode("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",fill:y.mode==="none"?"none":"currentColor","fill-opacity":y.mode==="faded"?.4:1,stroke:y.mode==="none"?"currentColor":"none","stroke-width":y.mode==="none"?1.5:0,"stroke-dasharray":y.mode==="none"?"3 3":""},null,8,aC)])),a.createElementVNode("span",null,a.toDisplayString(y.label),1)],10,iC)),64))])),a.createVNode(si,{currentColor:f.value,hideHighlight:u.value,withPicker:!0,withOpacity:!0,onChange:h,onPickerOpen:g[0]||(g[0]=y=>p.value=y)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),cC={class:"wov-shape-kind-button"},dC={class:"wov-shape-kind-dropdown"},uC=["onClick"],fC={viewBox:"0 0 20 20",class:"wov-shape-option-icon",fill:"none",stroke:"currentColor","stroke-width":"4"},hC=["d"],Gp=a.defineComponent({__name:"ShapeKindButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t,setDefaults:o}=le(),r=wt(()=>e.entityIds,w.Shape),s=a.computed(()=>{const d=r.value.values().next().value;return(d==null?void 0:d.kind)??"rectangle"}),i=a.computed(()=>{const d=new Set;for(const u of r.value.values())u&&d.add(u.kind);return d.size>1}),l=a.computed(()=>Object.keys(Co).map(d=>({kind:d,label:d.charAt(0).toUpperCase()+d.slice(1)})));function c(d){o("shape",{kind:d}),t(u=>{for(const f of e.entityIds){const h=w.Shape.write(u,f);h.kind=d}})}return(d,u)=>(a.openBlock(),a.createBlock(Ue,{title:"Shape Type"},{button:a.withCtx(()=>[a.createElementVNode("div",cC,[u[0]||(u[0]=a.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-shape-kind-icon",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[a.createElementVNode("circle",{cx:"6",cy:"6",r:"5"}),a.createElementVNode("rect",{x:"6",y:"6",width:"10",height:"10",fill:"var(--wov-gray-600)"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",dC,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(l.value,f=>(a.openBlock(),a.createElementBlock("button",{key:f.kind,class:a.normalizeClass(["wov-shape-kind-option",{"is-selected":!i.value&&f.kind===s.value}]),onClick:h=>c(f.kind)},[(a.openBlock(),a.createElementBlock("svg",fC,[a.createElementVNode("path",{d:a.unref(Co)[f.kind],transform:"translate(2, 2) scale(0.16)"},null,8,hC)])),a.createElementVNode("span",null,a.toDisplayString(f.label),1)],10,uC))),128))])]),_:1}))}}),pC={class:"wov-stroke-style-section"},mC=["title","onClick"],gC={viewBox:"0 0 24 8",fill:"none",stroke:"currentColor","stroke-width":"2"},yC=["stroke-dasharray","stroke-opacity"],kC=a.defineComponent({__name:"StrokeStyleOptions",props:{currentStyle:{},hasMultipleStyles:{type:Boolean}},emits:["change"],setup(n,{emit:e}){const t=e,o=[{kind:w.StrokeKind.Solid,label:"Solid"},{kind:w.StrokeKind.Dashed,label:"Dashed"},{kind:w.StrokeKind.None,label:"None"}];function r(i){switch(i){case w.StrokeKind.Dashed:return"6 6";case w.StrokeKind.None:return"";default:return""}}function s(i){t("change",i)}return(i,l)=>(a.openBlock(),a.createElementBlock("div",pC,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(o,c=>a.createElementVNode("button",{key:c.kind,class:a.normalizeClass(["wov-stroke-style-option",{"is-active":!n.hasMultipleStyles&&c.kind===n.currentStyle}]),title:c.label,onClick:d=>s(c.kind)},[(a.openBlock(),a.createElementBlock("svg",gC,[a.createElementVNode("line",{x1:"2",y1:"4",x2:"22",y2:"4","stroke-linecap":"round","stroke-dasharray":r(c.kind),"stroke-opacity":c.kind===a.unref(w.StrokeKind).None?.3:1},null,8,yC)])),a.createElementVNode("span",null,a.toDisplayString(c.label),1)],10,mC)),64))]))}}),wC={class:"wov-stroke-color-button"},bC={class:"wov-stroke-dropdown"},SC={key:1,class:"wov-stroke-thickness"},xC=["value"],CC={class:"wov-stroke-thickness-value"},EC={key:2,class:"wov-stroke-divider"},Yp=a.defineComponent({__name:"ShapeStrokeColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t,setDefaults:o}=le(),r=wt(()=>e.entityIds,w.Shape),s=a.ref(!1),i=a.computed(()=>{const g=new Set;for(const y of r.value.values())if(y){const k=sr({red:y.strokeRed,green:y.strokeGreen,blue:y.strokeBlue,alpha:255});g.add(k)}return Array.from(g)}),l=a.computed(()=>i.value.length>1),c=a.computed(()=>i.value[0]??"#000000"),d=a.computed(()=>{const g=r.value.values().next().value;return(g==null?void 0:g.strokeKind)??w.StrokeKind.Solid}),u=a.computed(()=>{const g=new Set;for(const y of r.value.values())y&&g.add(y.strokeKind);return g.size>1});function f(g){o("shape",{strokeRed:g.red,strokeGreen:g.green,strokeBlue:g.blue}),t(y=>{for(const k of e.entityIds){const x=w.Shape.write(y,k);x.strokeRed=g.red,x.strokeGreen=g.green,x.strokeBlue=g.blue}})}function h(g){o("shape",{strokeKind:g}),t(y=>{for(const k of e.entityIds){const x=w.Shape.write(y,k);x.strokeKind=g}})}const p=a.computed(()=>{const g=r.value.values().next().value;return(g==null?void 0:g.strokeWidth)??2});function m(g){const y=g.target,k=parseInt(y.value,10);o("shape",{strokeWidth:k}),t(x=>{for(const b of e.entityIds){const S=w.Shape.write(x,b);S.strokeWidth=k}})}return(g,y)=>(a.openBlock(),a.createBlock(Ue,{title:"Stroke Color"},{button:a.withCtx(()=>[a.createElementVNode("div",wC,[y[1]||(y[1]=a.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-stroke-color-icon",fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("path",{d:"M2.5 12.563c1.655-.886 5.9-3.293 8.568-4.355 2.668-1.062.101 2.822 1.32 3.105 1.218.283 5.112-1.814 5.112-1.814m-13.469 2.23c2.963-1.586 6.13-5.62 7.468-4.998 1.338.623-1.153 4.11-.132 5.595 1.02 1.487 6.133-1.43 6.133-1.43","stroke-width":"1.25"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",bC,[s.value?a.createCommentVNode("",!0):(a.openBlock(),a.createBlock(kC,{key:0,currentStyle:d.value,hasMultipleStyles:u.value,onChange:h},null,8,["currentStyle","hasMultipleStyles"])),s.value?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",SC,[a.createElementVNode("input",{type:"range",min:"1",max:"20",value:p.value,class:"wov-stroke-thickness-slider","aria-label":"Stroke thickness",onInput:m},null,40,xC),a.createElementVNode("span",CC,a.toDisplayString(p.value)+"px",1)])),s.value?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",EC)),a.createVNode(si,{currentColor:c.value,hideHighlight:l.value,withPicker:!0,onChange:f,onPickerOpen:y[0]||(y[0]=k=>s.value=k)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),vC={class:"wov-tape-image-button"},MC={class:"wov-tape-image-bubbles"},TC=["onClick"],Xp=a.defineComponent({__name:"TapeImageButton",props:{entityIds:{}},setup(n){const e=[{name:"Masking Tape",url:"https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F7e3b7dde-927d-4b09-aeb4-d49eac36d4ea.png?generation=1715183194653465&alt=media"},{name:"Transparent",url:"https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F522899b7-0ae9-4303-bdca-71105d835210.png?generation=1715183195130528&alt=media"},{name:"Arabic",url:"https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F3658d208-67e9-48a4-865b-44842187b523.png?generation=1715183192038109&alt=media"},{name:"Balloons",url:"https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F7d836c56-ae9a-44e6-a624-e6a49286dcde.png?generation=1715183193267076&alt=media"},{name:"Flowers",url:"https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2Fc1a1b89a-543f-4817-8afa-76544e94d776.png?generation=1715183194007112&alt=media"}],t=n,{nextEditorTick:o}=le(),r=wt(()=>t.entityIds,w.Asset),s=a.computed(()=>{for(const l of r.value.values())if(l!=null&&l.identifier)return l.identifier;return null});function i(l){o(c=>{for(const d of t.entityIds){const u=w.Asset.write(c,d);u.identifier=l}})}return(l,c)=>(a.openBlock(),a.createBlock(Ue,{title:"Tape Style"},{button:a.withCtx(()=>[a.createElementVNode("div",vC,[a.createElementVNode("div",{class:"wov-tape-image-swatch",style:a.normalizeStyle(s.value?{backgroundImage:`url(${s.value})`}:{})},null,4),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",MC,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(e,d=>a.createElementVNode("div",{key:d.url,class:a.normalizeClass(["wov-tape-image-bubble",{selected:s.value===d.url}]),style:a.normalizeStyle({backgroundImage:`url(${d.url})`}),onMousedown:c[0]||(c[0]=a.withModifiers(()=>{},["prevent"])),onClick:u=>i(d.url)},null,46,TC)),64))])]),_:1}))}}),Qp=[{label:"Small",value:16},{label:"Medium",value:24},{label:"Large",value:40},{label:"Huge",value:96}],_a=10,Zp=20;function NC(n){const e=n.map(s=>s.value).filter(s=>s>0),t=Math.min(...e),o=Math.max(...e),r=(_a+Zp)/2;return n.map(s=>{if(!(s.value>0)||o<=t)return r;const i=(Math.log(s.value)-Math.log(t))/(Math.log(o)-Math.log(t));return Math.round(_a+i*(Zp-_a))})}const AC={key:0,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},BC={key:1,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},IC={key:2,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},OC={key:3,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},Da=a.defineComponent({__name:"TextAlignmentButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds),r=[w.TextAlignment.Left,w.TextAlignment.Center,w.TextAlignment.Right,w.TextAlignment.Justify];function s(){const i=r.indexOf(t.alignment),l=r[(i+1)%r.length];o.setAlignment(l)}return(i,l)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Text Align",onClick:s},{default:a.withCtx(()=>[a.unref(t).alignment===a.unref(w.TextAlignment).Left?(a.openBlock(),a.createElementBlock("svg",AC,[...l[0]||(l[0]=[a.createElementVNode("path",{d:"M288 64c0 17.7-14.3 32-32 32L32 96C14.3 96 0 81.7 0 64S14.3 32 32 32l224 0c17.7 0 32 14.3 32 32zm0 256c0 17.7-14.3 32-32 32L32 352c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zM0 192c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 224c-17.7 0-32-14.3-32-32zM448 448c0 17.7-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"},null,-1)])])):a.unref(t).alignment===a.unref(w.TextAlignment).Center?(a.openBlock(),a.createElementBlock("svg",BC,[...l[1]||(l[1]=[a.createElementVNode("path",{d:"M352 64c0-17.7-14.3-32-32-32L128 32c-17.7 0-32 14.3-32 32s14.3 32 32 32l192 0c17.7 0 32-14.3 32-32zm96 128c0-17.7-14.3-32-32-32L32 160c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32zM0 448c0 17.7 14.3 32 32 32l384 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 416c-17.7 0-32 14.3-32 32zM352 320c0-17.7-14.3-32-32-32l-192 0c-17.7 0-32 14.3-32 32s14.3 32 32 32l192 0c17.7 0 32-14.3 32-32z"},null,-1)])])):a.unref(t).alignment===a.unref(w.TextAlignment).Right?(a.openBlock(),a.createElementBlock("svg",IC,[...l[2]||(l[2]=[a.createElementVNode("path",{d:"M448 64c0 17.7-14.3 32-32 32L192 96c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zm0 256c0 17.7-14.3 32-32 32l-224 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zM0 192c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 224c-17.7 0-32-14.3-32-32zM448 448c0 17.7-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"},null,-1)])])):(a.openBlock(),a.createElementBlock("svg",OC,[...l[3]||(l[3]=[a.createElementVNode("path",{d:"M448 64c0-17.7-14.3-32-32-32L32 32C14.3 32 0 46.3 0 64S14.3 96 32 96l384 0c17.7 0 32-14.3 32-32zm0 256c0-17.7-14.3-32-32-32L32 288c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32zM0 192c0 17.7 14.3 32 32 32l384 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 160c-17.7 0-32 14.3-32 32zM448 448c0-17.7-14.3-32-32-32L32 416c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32z"},null,-1)])]))]),_:1})):a.createCommentVNode("",!0)}}),Ra=a.defineComponent({__name:"TextBoldButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Bold",class:a.normalizeClass({"wov-active":a.unref(t).isBold}),onClick:a.unref(o).toggleBold},{default:a.withCtx(()=>[...s[0]||(s[0]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M0 64C0 46.3 14.3 32 32 32l48 0 16 0 128 0c70.7 0 128 57.3 128 128c0 31.3-11.3 60.1-30 82.3c37.1 22.4 62 63.1 62 109.7c0 70.7-57.3 128-128 128L96 480l-16 0-48 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l16 0 0-160L48 96 32 96C14.3 96 0 81.7 0 64zM224 224c35.3 0 64-28.7 64-64s-28.7-64-64-64L112 96l0 128 112 0zM112 288l0 128 144 0c35.3 0 64-28.7 64-64s-28.7-64-64-64l-32 0-112 0z"})],-1)])]),_:1},8,["class","onClick"])):a.createCommentVNode("",!0)}});function _C(n,e){return a.getCurrentScope()?(a.onScopeDispose(n,e),!0):!1}const DC=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const RC=Object.prototype.toString,PC=n=>RC.call(n)==="[object Object]",ii=()=>{};function li(n){return Array.isArray(n)?n:[n]}function LC(n){return a.getCurrentInstance()}function VC(n,e=!0,t){LC()?a.onMounted(n,t):e?n():a.nextTick(n)}function $C(n,e,t){return a.watch(n,e,{...t,immediate:!0})}const ai=DC?window:void 0;function dt(n){var e;const t=a.toValue(n);return(e=t==null?void 0:t.$el)!==null&&e!==void 0?e:t}function Pa(...n){const e=(o,r,s,i)=>(o.addEventListener(r,s,i),()=>o.removeEventListener(r,s,i)),t=a.computed(()=>{const o=li(a.toValue(n[0])).filter(r=>r!=null);return o.every(r=>typeof r!="string")?o:void 0});return $C(()=>{var o,r;return[(o=(r=t.value)===null||r===void 0?void 0:r.map(s=>dt(s)))!==null&&o!==void 0?o:[ai].filter(s=>s!=null),li(a.toValue(t.value?n[1]:n[0])),li(a.unref(t.value?n[2]:n[1])),a.toValue(t.value?n[3]:n[2])]},([o,r,s,i],l,c)=>{if(!(o!=null&&o.length)||!(r!=null&&r.length)||!(s!=null&&s.length))return;const d=PC(i)?{...i}:i,u=o.flatMap(f=>r.flatMap(h=>s.map(p=>e(f,h,p,d))));c(()=>{u.forEach(f=>f())})},{flush:"post"})}function zC(n,e,t={}){const{window:o=ai,ignore:r=[],capture:s=!0,detectIframe:i=!1,controls:l=!1}=t;if(!o)return l?{stop:ii,cancel:ii,trigger:ii}:ii;let c=!0;const d=y=>a.toValue(r).some(k=>{if(typeof k=="string")return Array.from(o.document.querySelectorAll(k)).some(x=>x===y.target||y.composedPath().includes(x));{const x=dt(k);return x&&(y.target===x||y.composedPath().includes(x))}});function u(y){const k=a.toValue(y);return k&&k.$.subTree.shapeFlag===16}function f(y,k){const x=a.toValue(y),b=x.$.subTree&&x.$.subTree.children;return b==null||!Array.isArray(b)?!1:b.some(S=>S.el===k.target||k.composedPath().includes(S.el))}const h=y=>{const k=dt(n);if(y.target!=null&&!(!(k instanceof Element)&&u(n)&&f(n,y))&&!(!k||k===y.target||y.composedPath().includes(k))){if("detail"in y&&y.detail===0&&(c=!d(y)),!c){c=!0;return}e(y)}};let p=!1;const m=[Pa(o,"click",y=>{p||(p=!0,setTimeout(()=>{p=!1},0),h(y))},{passive:!0,capture:s}),Pa(o,"pointerdown",y=>{const k=dt(n);c=!d(y)&&!!(k&&!y.composedPath().includes(k))},{passive:!0}),i&&Pa(o,"blur",y=>{setTimeout(()=>{var k;const x=dt(n);((k=o.document.activeElement)===null||k===void 0?void 0:k.tagName)==="IFRAME"&&!(x!=null&&x.contains(o.document.activeElement))&&e(y)},0)},{passive:!0})].filter(Boolean),g=()=>m.forEach(y=>y());return l?{stop:g,cancel:()=>{c=!1},trigger:y=>{c=!0,h(y),c=!1}}:g}function FC(){const n=a.shallowRef(!1),e=a.getCurrentInstance();return e&&a.onMounted(()=>{n.value=!0},e),n}function HC(n){const e=FC();return a.computed(()=>(e.value,!!n()))}function jC(n,e,t={}){const{window:o=ai,...r}=t;let s;const i=HC(()=>o&&"ResizeObserver"in o),l=()=>{s&&(s.disconnect(),s=void 0)},c=a.watch(a.computed(()=>{const u=a.toValue(n);return Array.isArray(u)?u.map(f=>dt(f)):[dt(u)]}),u=>{if(l(),i.value&&o){s=new ResizeObserver(e);for(const f of u)f&&s.observe(f,r)}},{immediate:!0,flush:"post"}),d=()=>{l(),c()};return _C(d),{isSupported:i,stop:d}}function em(n,e={width:0,height:0},t={}){const{window:o=ai,box:r="content-box"}=t,s=a.computed(()=>{var f;return(f=dt(n))===null||f===void 0||(f=f.namespaceURI)===null||f===void 0?void 0:f.includes("svg")}),i=a.shallowRef(e.width),l=a.shallowRef(e.height),{stop:c}=jC(n,([f])=>{const h=r==="border-box"?f.borderBoxSize:r==="content-box"?f.contentBoxSize:f.devicePixelContentBoxSize;if(o&&s.value){const p=dt(n);if(p){const m=p.getBoundingClientRect();i.value=m.width,l.value=m.height}}else if(h){const p=li(h);i.value=p.reduce((m,{inlineSize:g})=>m+g,0),l.value=p.reduce((m,{blockSize:g})=>m+g,0)}else i.value=f.contentRect.width,l.value=f.contentRect.height},t);VC(()=>{const f=dt(n);f&&(i.value="offsetWidth"in f?f.offsetWidth:e.width,l.value="offsetHeight"in f?f.offsetHeight:e.height)});const d=a.watch(()=>dt(n),f=>{i.value=f?e.width:0,l.value=f?e.height:0});function u(){c(),d()}return{width:i,height:l,stop:u}}function tm(){const n=a.inject(we);if(!n)throw new Error("useFonts must be used within a WovenCanvas component");return a.computed(()=>{const e=n.getEditor();return e?e.fonts.filter(t=>t.selectable):[]})}const UC={class:"wov-font-family-button"},WC={class:"wov-font-family-label"},KC={class:"wov-font-list"},qC=["onClick"],JC=["src","alt"],La=a.defineComponent({__name:"TextFontFamilyButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds),r=tm(),s=a.computed(()=>r.value.map(u=>({name:u.name,displayName:u.displayName,previewImage:u.previewImage}))),i=a.computed(()=>t.fontFamily),l=a.computed(()=>{const u=i.value;if(u===null)return"Mixed";const f=s.value.find(h=>h.name===u);return(f==null?void 0:f.displayName)??u});function c(u){o.setFontFamily(u)}function d(u){u.stopPropagation()}return(u,f)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Ue,{key:0,title:"Font Family"},{button:a.withCtx(()=>[a.createElementVNode("div",UC,[a.createElementVNode("span",WC,a.toDisplayString(l.value),1),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",{class:"wov-font-family-menu",onWheel:d,onClick:f[0]||(f[0]=a.withModifiers(()=>{},["stop"]))},[a.createElementVNode("div",KC,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(s.value,h=>(a.openBlock(),a.createElementBlock("div",{key:h.name,class:a.normalizeClass(["wov-font-item",{active:i.value===h.name}]),onClick:p=>c(h.name)},[h.previewImage?(a.openBlock(),a.createElementBlock("img",{key:0,class:"wov-font-preview",src:h.previewImage,alt:h.name,loading:"lazy",decoding:"async"},null,8,JC)):(a.openBlock(),a.createElementBlock("span",{key:1,class:"wov-font-name",style:a.normalizeStyle({fontFamily:h.name})},a.toDisplayString(h.displayName),5))],10,qC))),128))])],32)]),_:1})):a.createCommentVNode("",!0)}}),GC={class:"wov-font-size-button"},YC={class:"wov-font-size-label"},XC=["onClick"],QC={key:0,class:"wov-check-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},ZC={class:"wov-input-container"},eE=["value"],tE={class:"wov-size-stepper"},nE=1,Va=a.defineComponent({__name:"TextFontSizeButton",props:{entityIds:{},sizeOptions:{default:()=>Qp},pxPerUnit:{default:1}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds),r=a.ref(null),s=a.computed(()=>NC(e.sizeOptions));function i(y){return+(y/e.pxPerUnit).toFixed(1)}const l=a.computed(()=>{const y=t.fontSize;return y===null?null:i(y)});function c(y){const k=l.value;return k!==null&&Math.abs(y.value-k)<.05}const d=a.computed(()=>{const y=l.value;if(y===null)return"Mixed";const k=e.sizeOptions.find(c);return k?k.label:`${y} px`}),u=a.computed(()=>{const y=l.value;return y===null?"":String(y)});function f(y){o.setFontSize(y*e.pxPerUnit)}function h(y){const k=y.target,x=Number.parseFloat(k.value);if(Number.isNaN(x)||x<=0){k.value=u.value;return}f(x)}function p(y){var S;const k=Number.parseFloat(((S=r.value)==null?void 0:S.value)??""),x=Number.isNaN(k)?l.value:k;if(x===null)return;const b=Math.max(+(x+y).toFixed(1),nE);r.value&&(r.value.value=String(b)),f(b)}function m(y){y.key==="Enter"?y.target.blur():y.key==="ArrowUp"?(y.preventDefault(),p(1)):y.key==="ArrowDown"&&(y.preventDefault(),p(-1))}function g(y){y.stopPropagation()}return(y,k)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Ue,{key:0,title:"Font Size"},{button:a.withCtx(()=>[a.createElementVNode("div",GC,[a.createElementVNode("span",YC,a.toDisplayString(d.value),1),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",{class:"wov-font-size-menu",onWheel:g,onClick:k[4]||(k[4]=a.withModifiers(()=>{},["stop"])),onKeydown:k[5]||(k[5]=a.withModifiers(()=>{},["stop"]))},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(n.sizeOptions,(x,b)=>(a.openBlock(),a.createElementBlock("div",{key:x.value,class:a.normalizeClass(["wov-font-size-option",{active:c(x)}]),onClick:S=>f(x.value)},[c(x)?(a.openBlock(),a.createElementBlock("svg",QC,[...k[6]||(k[6]=[a.createElementVNode("path",{d:"M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"},null,-1)])])):a.createCommentVNode("",!0),a.createElementVNode("span",{class:"wov-option-label",style:a.normalizeStyle({fontSize:`${s.value[b]}px`})},a.toDisplayString(x.label),5)],10,XC))),128)),k[10]||(k[10]=a.createElementVNode("div",{class:"wov-separator"},null,-1)),a.createElementVNode("div",ZC,[a.createElementVNode("input",{ref_key:"inputRef",ref:r,class:"wov-custom-input",value:u.value,onChange:h,onKeydown:m,placeholder:"Custom size"},null,40,eE),k[9]||(k[9]=a.createElementVNode("span",{class:"wov-px-suffix"},"px",-1)),a.createElementVNode("div",tE,[a.createElementVNode("button",{class:"wov-size-stepper-button",title:"Increase size",onMousedown:k[0]||(k[0]=a.withModifiers(()=>{},["prevent"])),onClick:k[1]||(k[1]=x=>p(1))},[...k[7]||(k[7]=[a.createElementVNode("svg",{class:"wov-size-stepper-icon up",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 320",fill:"currentColor"},[a.createElementVNode("path",{d:"M233.4 278.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 210.7 86.6 41.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"})],-1)])],32),a.createElementVNode("button",{class:"wov-size-stepper-button",title:"Decrease size",onMousedown:k[2]||(k[2]=a.withModifiers(()=>{},["prevent"])),onClick:k[3]||(k[3]=x=>p(-1))},[...k[8]||(k[8]=[a.createElementVNode("svg",{class:"wov-size-stepper-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 320",fill:"currentColor"},[a.createElementVNode("path",{d:"M233.4 278.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 210.7 86.6 41.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"})],-1)])],32)])])],32)]),_:1})):a.createCommentVNode("",!0)}}),$a=a.defineComponent({__name:"TextItalicButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Italic",class:a.normalizeClass({"wov-active":a.unref(t).isItalic}),onClick:a.unref(o).toggleItalic},{default:a.withCtx(()=>[...s[0]||(s[0]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M128 64c0-17.7 14.3-32 32-32l192 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-58.7 0L160 416l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l58.7 0L224 96l-64 0c-17.7 0-32-14.3-32-32z"})],-1)])]),_:1},8,["class","onClick"])):a.createCommentVNode("",!0)}}),za=a.defineComponent({__name:"TextUnderlineButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Underline",class:a.normalizeClass({"wov-active":a.unref(t).isUnderline}),onClick:a.unref(o).toggleUnderline},{default:a.withCtx(()=>[...s[0]||(s[0]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M16 64c0-17.7 14.3-32 32-32l96 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-16 0 0 128c0 53 43 96 96 96s96-43 96-96l0-128-16 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l96 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-16 0 0 128c0 88.4-71.6 160-160 160s-160-71.6-160-160L64 96 48 96C30.3 96 16 81.7 16 64zM0 448c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32z"})],-1)])]),_:1},8,["class","onClick"])):a.createCommentVNode("",!0)}}),oE={class:"wov-link-input-container"},rE=["onKeydown"],Fa=a.defineComponent({__name:"TextLinkButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds),r=a.ref(!1),s=a.ref(""),i=a.ref(null),l=a.ref(null),c=a.ref(null),d=a.inject("containerRef"),{floatingStyles:u}=mo(l,c,{placement:"top",middleware:[fo(8),po(),ho({padding:8})],whileElementsMounted:ri});function f(){s.value=t.linkHref??"",r.value=!0,a.nextTick(()=>{var g,y;(g=i.value)==null||g.focus(),(y=i.value)==null||y.select()})}function h(){const g=s.value.trim();g?o.setLink(g):o.removeLink(),r.value=!1}function p(){o.removeLink(),s.value="",r.value=!1}function m(g){var k,x;const y=g.target;!((k=l.value)!=null&&k.contains(y))&&!((x=c.value)!=null&&x.contains(y))&&(r.value=!1)}return a.watch(r,g=>{g?document.addEventListener("click",m,!0):document.removeEventListener("click",m,!0)}),(g,y)=>(a.openBlock(),a.createElementBlock(a.Fragment,null,[a.createElementVNode("div",{ref_key:"buttonRef",ref:l},[a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Link",class:a.normalizeClass({"wov-active":a.unref(t).linkHref!==null}),onClick:f},{default:a.withCtx(()=>[...y[3]||(y[3]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 7-34.4-7.4-44.6s-34.4-7-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372.1 74 321.1 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.8l-1.1 1.6c-10.3 14.4-7 34.4 7.4 44.6s34.4 7 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"})],-1)])]),_:1},8,["class"])):a.createCommentVNode("",!0)],512),a.unref(d)?(a.openBlock(),a.createBlock(a.Teleport,{key:0,to:a.unref(d)},[r.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"dropdownRef",ref:c,class:"wov-link-input-dropdown",style:a.normalizeStyle(a.unref(u)),onKeydown:y[2]||(y[2]=a.withModifiers(()=>{},["stop"]))},[a.createElementVNode("div",oE,[a.withDirectives(a.createElementVNode("input",{ref_key:"inputRef",ref:i,"onUpdate:modelValue":y[0]||(y[0]=k=>s.value=k),class:"wov-link-input",placeholder:"Paste or type URL",onKeydown:[a.withKeys(a.withModifiers(h,["prevent"]),["enter"]),y[1]||(y[1]=a.withKeys(a.withModifiers(k=>r.value=!1,["prevent"]),["esc"]))]},null,40,rE),[[a.vModelText,s.value]]),s.value||a.unref(t).linkHref?(a.openBlock(),a.createElementBlock("button",{key:0,class:"wov-link-action-button",title:"Remove link",onClick:p},[...y[4]||(y[4]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 12.5 32.8 0 45.3s32.8 12.5 45.3 0L237.3 256 342.6 150.6z"})],-1)])])):a.createCommentVNode("",!0),a.createElementVNode("button",{class:"wov-link-action-button",title:"Apply link",onClick:h},[...y[5]||(y[5]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"})],-1)])])])],36)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)],64))}}),sE={class:"wov-text-color-button"},iE={class:"wov-text-icon-container"},Ha=a.defineComponent({__name:"TextColorButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds),r=a.computed(()=>t.color??"#000000"),s=a.computed(()=>({backgroundColor:r.value}));function i(l){o.setColor(sr(l))}return(l,c)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Ue,{key:0,title:"Text Color"},{button:a.withCtx(()=>[a.createElementVNode("div",sE,[a.createElementVNode("div",iE,[c[0]||(c[0]=a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor",class:"wov-text-icon"},[a.createElementVNode("path",{d:"M349.1 114.7C343.9 103.3 332.5 96 320 96C307.5 96 296.1 103.3 290.9 114.7L123.5 480L112 480C94.3 480 80 494.3 80 512C80 529.7 94.3 544 112 544L200 544C217.7 544 232 529.7 232 512C232 494.3 217.7 480 200 480L193.9 480L215.9 432L424.2 432L446.2 480L440.1 480C422.4 480 408.1 494.3 408.1 512C408.1 529.7 422.4 544 440.1 544L528.1 544C545.8 544 560.1 529.7 560.1 512C560.1 494.3 545.8 480 528.1 480L516.6 480L349.2 114.7zM394.8 368L245.2 368L320 204.8L394.8 368z"})],-1)),a.createElementVNode("div",{class:"wov-color-underline",style:a.normalizeStyle(s.value)},null,4)]),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createVNode(si,{currentColor:r.value,withPicker:!0,onChange:i},null,8,["currentColor"])]),_:1})):a.createCommentVNode("",!0)}}),lE={key:0,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-start-icon lucide-align-vertical-justify-start"},aE={key:1,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-center-icon lucide-align-vertical-justify-center"},cE={key:2,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-end-icon lucide-align-vertical-justify-end"},nm=a.defineComponent({__name:"VerticalAlignButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),{state:o}=lt(()=>e.entityIds),r=[w.VerticalAlignment.Top,w.VerticalAlignment.Center,w.VerticalAlignment.Bottom],s=wt(()=>e.entityIds,w.VerticalAlign),i=a.computed(()=>{let c=null;for(const d of s.value.values()){const u=(d==null?void 0:d.value)??w.VerticalAlignment.Top;if(c===null)c=u;else if(c!==u)return null}return c});function l(){const c=i.value??w.VerticalAlignment.Top,d=r.indexOf(c),u=r[(d+1)%r.length];t(f=>{for(const h of e.entityIds){const p=w.VerticalAlign.write(f,h);p.value=u}})}return(c,d)=>a.unref(o).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Vertical Align",onClick:l},{default:a.withCtx(()=>[i.value===a.unref(w.VerticalAlignment).Top||i.value===null?(a.openBlock(),a.createElementBlock("svg",lE,[...d[0]||(d[0]=[a.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"},null,-1),a.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"6",rx:"2"},null,-1),a.createElementVNode("path",{d:"M2 2h20"},null,-1)])])):i.value===a.unref(w.VerticalAlignment).Center?(a.openBlock(),a.createElementBlock("svg",aE,[...d[1]||(d[1]=[a.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"},null,-1),a.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"},null,-1),a.createElementVNode("path",{d:"M2 12h20"},null,-1)])])):(a.openBlock(),a.createElementBlock("svg",cE,[...d[2]||(d[2]=[a.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"12",rx:"2"},null,-1),a.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"},null,-1),a.createElementVNode("path",{d:"M2 22h20"},null,-1)])]))]),_:1})):a.createCommentVNode("",!0)}}),dE={class:"wov-text-group-button"},uE={class:"wov-text-group-dropdown"},fE={class:"wov-text-group-row wov-text-group-row-full"},hE={class:"wov-text-group-row"},om=a.defineComponent({__name:"TextButtonGroup",props:{entityIds:{},showVerticalAlign:{type:Boolean},pxPerUnit:{}},setup(n){const e=n,{state:t}=lt(()=>e.entityIds),o=a.inject("containerRef"),{width:r}=em(o),s=a.computed(()=>r.value>0&&r.value<600),i=a.ref(new Map);return a.provide(Ec,i),(l,c)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createElementBlock(a.Fragment,{key:0},[s.value?(a.openBlock(),a.createBlock(Ue,{key:0,title:"Text Formatting",placement:"top"},{button:a.withCtx(()=>[a.createElementVNode("div",dE,[c[0]||(c[0]=a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor",class:"wov-text-group-icon"},[a.createElementVNode("path",{d:"M349.1 114.7C343.9 103.3 332.5 96 320 96C307.5 96 296.1 103.3 290.9 114.7L123.5 480L112 480C94.3 480 80 494.3 80 512C80 529.7 94.3 544 112 544L200 544C217.7 544 232 529.7 232 512C232 494.3 217.7 480 200 480L193.9 480L215.9 432L424.2 432L446.2 480L440.1 480C422.4 480 408.1 494.3 408.1 512C408.1 529.7 422.4 544 440.1 544L528.1 544C545.8 544 560.1 529.7 560.1 512C560.1 494.3 545.8 480 528.1 480L516.6 480L349.2 114.7zM394.8 368L245.2 368L320 204.8L394.8 368z"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",uE,[a.createElementVNode("div",fE,[a.createVNode(La,{entityIds:n.entityIds},null,8,["entityIds"]),c[1]||(c[1]=a.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),a.createVNode(Va,{entityIds:n.entityIds,"px-per-unit":n.pxPerUnit},null,8,["entityIds","px-per-unit"])]),a.createElementVNode("div",hE,[a.createVNode(Ra,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode($a,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(za,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Fa,{entityIds:n.entityIds},null,8,["entityIds"]),c[2]||(c[2]=a.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),a.createVNode(Ha,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Da,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(a.openBlock(),a.createBlock(nm,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):a.createCommentVNode("",!0)])])]),_:1})):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[a.createVNode(La,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Va,{entityIds:n.entityIds,"px-per-unit":n.pxPerUnit},null,8,["entityIds","px-per-unit"]),c[3]||(c[3]=a.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),a.createVNode(Ra,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode($a,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(za,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Fa,{entityIds:n.entityIds},null,8,["entityIds"]),c[4]||(c[4]=a.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),a.createVNode(Ha,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Da,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(a.openBlock(),a.createBlock(nm,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):a.createCommentVNode("",!0)],64))],64)):a.createCommentVNode("",!0)}}),rm=a.defineComponent({__name:"CanvasBackground",props:{background:{}},setup(n){const e=n,t={kind:"none",color:"#f4f4f4",strokeColor:"#a1a1a1",subdivisionStep:5},o=a.computed(()=>({...t,...e.background})),r=Me(w.Camera),s=Me(w.Grid),i=a.inject("containerRef"),l=a.ref({width:0,height:0});let c=null;const d=a.ref(null);let u=null;typeof document<"u"&&(u=document.createElement("canvas"));function f(x,b,S,C){const v=C/2;x.beginPath(),x.arc(b,S,v,0,Math.PI*2),x.fill()}function h(x,b,S){if(!u)return null;const C=S.dotSize??2,v=x*S.subdivisionStep,E=b*S.subdivisionStep;if(v<=0||E<=0)return null;u.width=v,u.height=E;const M=u.getContext("2d");if(!M)return null;if(M.clearRect(0,0,v,E),M.fillStyle=S.strokeColor,S.subdivisionStep===1)f(M,v/2,E/2,C);else for(let T=0;T<S.subdivisionStep;T++)for(let A=0;A<S.subdivisionStep;A++){const B=(T+.5)*(v/S.subdivisionStep),I=(A+.5)*(E/S.subdivisionStep),z=T===0&&A===0?2*C:C;f(M,B,I,z)}return M.createPattern(u,"repeat")}function p(x,b,S,C,v,E){x.lineWidth=E,x.beginPath(),x.moveTo(b,S),x.lineTo(C,v),x.stroke()}function m(x,b,S){if(!u)return null;const C=S.gridSize??1,v=x*S.subdivisionStep,E=b*S.subdivisionStep;if(v<=0||E<=0)return null;u.width=v,u.height=E;const M=u.getContext("2d");if(!M)return null;if(M.clearRect(0,0,v,E),M.strokeStyle=S.strokeColor,S.subdivisionStep===1)p(M,0,0,v,0,C),p(M,0,0,0,E,C);else{const T=v/S.subdivisionStep,A=E/S.subdivisionStep;for(let B=0;B<=S.subdivisionStep;B++){const I=B*T,O=B%S.subdivisionStep===0;p(M,I,0,I,E,O?2*C:C)}for(let B=0;B<=S.subdivisionStep;B++){const I=B*A,O=B%S.subdivisionStep===0;p(M,0,I,v,I,O?2*C:C)}}return M.createPattern(u,"repeat")}function g(x){let b=s.value.colWidth,S=s.value.rowHeight;const C=o.value.subdivisionStep,v=l.value.width,E=l.value.height,M=r.value.left,T=r.value.top,A=M+v/r.value.zoom,B=T+E/r.value.zoom;let I=b*C,O=S*C,z=0,$=0,J=Number.POSITIVE_INFINITY,j=Number.POSITIVE_INFINITY;for(;;){I=C*b,O=C*S,z=Math.floor(M/I)*I,$=Math.floor(T/O)*O;const ot=Math.ceil(A/I)*I,ft=Math.ceil(B/O)*O;if(j=Math.round((ot-z)/b),J=Math.round((ft-$)/S),Math.max(j,J)>125)b*=2,S*=2;else break}const K=b*r.value.zoom,W=S*r.value.zoom,X=Math.max(1,Math.round(K)),ne=Math.max(1,Math.round(W)),ce=h(X,ne,o.value);if(!ce)return;ce.setTransform(new DOMMatrix().scale(K/X,W/ne));const be=(z-M-b/2)*r.value.zoom,Oe=($-T-S/2)*r.value.zoom;x.save(),x.translate(be,Oe),x.fillStyle=ce,x.fillRect(0,0,v+I*r.value.zoom,E+O*r.value.zoom),x.restore()}function y(x){let b=s.value.colWidth,S=s.value.rowHeight;const C=o.value.subdivisionStep,v=l.value.width,E=l.value.height,M=r.value.left,T=r.value.top,A=M+v/r.value.zoom,B=T+E/r.value.zoom;let I=b*C,O=S*C,z=0,$=0,J=Number.POSITIVE_INFINITY,j=Number.POSITIVE_INFINITY;for(;;){I=C*b,O=C*S,z=Math.floor(M/I)*I,$=Math.floor(T/O)*O;const ot=Math.ceil(A/I)*I,ft=Math.ceil(B/O)*O;if(j=Math.round((ot-z)/b),J=Math.round((ft-$)/S),Math.max(j,J)>200)b*=2,S*=2;else break}const K=b*r.value.zoom,W=S*r.value.zoom,X=Math.max(1,Math.round(K)),ne=Math.max(1,Math.round(W)),ce=m(X,ne,o.value);if(!ce)return;ce.setTransform(new DOMMatrix().scale(K/X,W/ne));const be=(z-M)*r.value.zoom,Oe=($-T)*r.value.zoom;x.save(),x.translate(be,Oe),x.fillStyle=ce,x.fillRect(0,0,v+I*r.value.zoom,E+O*r.value.zoom),x.restore()}function k(){const x=d.value;if(!x)return;const b=x.getContext("2d");if(!b)return;const{width:S,height:C}=l.value;S===0||C===0||(x.width=S,x.height=C,b.clearRect(0,0,S,C),b.fillStyle=o.value.color,b.fillRect(0,0,S,C),o.value.kind==="dots"?g(b):o.value.kind==="grid"&&y(b))}return a.watch(()=>[o.value,r.value,s.value,l.value],()=>{k()},{deep:!0}),a.onMounted(()=>{const x=i==null?void 0:i.value;if(x){const b=()=>{l.value={width:x.clientWidth,height:x.clientHeight}};b(),c=new ResizeObserver(b),c.observe(x)}k()}),a.onUnmounted(()=>{c==null||c.disconnect()}),(x,b)=>(a.openBlock(),a.createElementBlock("canvas",{ref_key:"canvasRef",ref:d,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none"}},null,512))}}),sm=a.defineComponent({__name:"FileDropZone",props:{maxSize:{default:400}},setup(n){const e=n,{nextEditorTick:t,getEditor:o}=le(),{createImageBlock:r}=ka(),s=a.ref(!1);let i=0;function l(){var S;return((S=o())==null?void 0:S.readonly)===!0}const c=a.inject("containerRef");function d(S){var C;l()||(C=S.dataTransfer)!=null&&C.types.some(v=>v==="Files"||v==="text/uri-list"||v==="text/html")&&(i++,i===1&&(s.value=!0))}function u(){i--,i===0&&(s.value=!1)}function f(){i=0,s.value=!1}a.onMounted(()=>{const S=c==null?void 0:c.value;S&&(S.addEventListener("dragenter",d),S.addEventListener("dragleave",u),S.addEventListener("drop",f))}),a.onUnmounted(()=>{const S=c==null?void 0:c.value;S&&(S.removeEventListener("dragenter",d),S.removeEventListener("dragleave",u),S.removeEventListener("drop",f))});function h(S){S.preventDefault(),S.dataTransfer&&(S.dataTransfer.dropEffect="copy")}function p(S){S.preventDefault()}function m(S){S.preventDefault()}async function g(S){if(S.preventDefault(),l()||!S.dataTransfer)return;const C=S.clientX,v=S.clientY,E=Array.from(S.dataTransfer.files).filter(T=>T.type.startsWith("image/"));if(E.length>0){for(const T of E)await x(T,C,v);return}const M=y(S.dataTransfer);M&&await b(M,C,v)}function y(S){const C=S.getData("text/uri-list");if(C){const T=C.split(`
|
|
106
|
+
3. "-" cannot repeat`);ue.customSchemes.push([n,e])}function k2(){ue.scanner=d2(ue.customSchemes);for(let n=0;n<ue.tokenQueue.length;n++)ue.tokenQueue[n][1]({scanner:ue.scanner});ue.parser=h2(ue.scanner.tokens);for(let n=0;n<ue.pluginQueue.length;n++)ue.pluginQueue[n][1]({scanner:ue.scanner,parser:ue.parser});return ue.initialized=!0,ue}function la(n){return ue.initialized||k2(),p2(ue.parser.start,n,Nh(ue.scanner.start,n))}la.scan=Nh;function Rh(n,e=null,t=null){if(e&&typeof e=="object"){if(t)throw Error(`linkifyjs: Invalid link type ${e}; must be a string`);t=e,e=null}const o=new sa(t),r=la(n),s=[];for(let i=0;i<r.length;i++){const l=r[i];l.isLink&&(!e||l.t===e)&&o.check(l)&&s.push(l.toFormattedObject(o))}return s}var aa="[\0- -\u2029 ]",w2=new RegExp(aa),b2=new RegExp(`${aa}$`),S2=new RegExp(aa,"g");function x2(n){return n.length===1?n[0].isLink:n.length===3&&n[1].isLink?["()","[]"].includes(n[0].value+n[2].value):!1}function C2(n){return new pe({key:new Ce("autolink"),appendTransaction:(e,t,o)=>{const r=e.some(d=>d.docChanged)&&!t.doc.eq(o.doc),s=e.some(d=>d.getMeta("preventAutolink"));if(!r||s)return;const{tr:i}=o,l=Lf(t.doc,[...e]);if(Jf(l).forEach(({newRange:d})=>{const u=Iw(o.doc,d,p=>p.isTextblock);let f,h;if(u.length>1)f=u[0],h=o.doc.textBetween(f.pos,f.pos+f.node.nodeSize,void 0," ");else if(u.length){const p=o.doc.textBetween(d.from,d.to," "," ");if(!b2.test(p))return;f=u[0],h=o.doc.textBetween(f.pos,d.to,void 0," ")}if(f&&h){const p=h.split(w2).filter(Boolean);if(p.length<=0)return!1;const m=p[p.length-1],g=f.pos+h.lastIndexOf(m);if(!m)return!1;const y=la(m).map(k=>k.toObject(n.defaultProtocol));if(!x2(y))return!1;y.filter(k=>k.isLink).map(k=>({...k,from:g+k.start+1,to:g+k.end+1})).filter(k=>o.schema.marks.code?!o.doc.rangeHasMark(k.from,k.to,o.schema.marks.code):!0).filter(k=>n.validate(k.value)).filter(k=>n.shouldAutoLink(k.value)).forEach(k=>{Ol(k.from,k.to,o.doc).some(x=>x.mark.type===n.type)||i.addMark(k.from,k.to,n.type.create({href:k.href}))})}}),!!i.steps.length)return i}})}function E2(n){return new pe({key:new Ce("handleClickLink"),props:{handleClick:(e,t,o)=>{var r,s;if(o.button!==0||!e.editable)return!1;let i=null;if(o.target instanceof HTMLAnchorElement)i=o.target;else{const c=o.target;if(!c)return!1;const d=n.editor.view.dom;i=c.closest("a"),i&&!d.contains(i)&&(i=null)}if(!i)return!1;let l=!1;if(n.enableClickSelection&&(l=n.editor.commands.extendMarkRange(n.type.name)),n.openOnClick){const c=qf(e.state,n.type.name),d=(r=i.href)!=null?r:c.href,u=(s=i.target)!=null?s:c.target;d&&(window.open(d,u),l=!0)}return l}}})}function v2(n){return new pe({key:new Ce("handlePasteLink"),props:{handlePaste:(e,t,o)=>{const{shouldAutoLink:r}=n,{state:s}=e,{selection:i}=s,{empty:l}=i;if(l)return!1;let c="";o.content.forEach(u=>{c+=u.textContent});const d=Rh(c,{defaultProtocol:n.defaultProtocol}).find(u=>u.isLink&&u.value===c);return!c||!d||r!==void 0&&!r(d.value)?!1:n.editor.commands.setMark(n.type,{href:d.href})}}})}function Dn(n,e){const t=["http","https","ftp","ftps","mailto","tel","callto","sms","cid","xmpp"];return e&&e.forEach(o=>{const r=typeof o=="string"?o:o.scheme;r&&t.push(r)}),!n||n.replace(S2,"").match(new RegExp(`^(?:(?:${t.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}var M2=io.create({name:"link",priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(n=>{if(typeof n=="string"){Dh(n);return}Dh(n.scheme,n.optionalSlashes)})},onDestroy(){y2()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,autolink:!0,protocols:[],defaultProtocol:"http",HTMLAttributes:{target:"_blank",rel:"noopener noreferrer nofollow",class:null},isAllowedUri:(n,e)=>!!Dn(n,e.protocols),validate:n=>!!n,shouldAutoLink:n=>{const e=/^[a-z][a-z0-9+.-]*:\/\//i.test(n),t=/^[a-z][a-z0-9+.-]*:/i.test(n);if(e||t&&!n.includes("@"))return!0;const r=(n.includes("@")?n.split("@").pop():n).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){return{href:{default:null,parseHTML(n){return n.getAttribute("href")}},target:{default:this.options.HTMLAttributes.target},rel:{default:this.options.HTMLAttributes.rel},class:{default:this.options.HTMLAttributes.class},title:{default:null}}},parseHTML(){return[{tag:"a[href]",getAttrs:n=>{const e=n.getAttribute("href");return!e||!this.options.isAllowedUri(e,{defaultValidate:t=>!!Dn(t,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:n}){return this.options.isAllowedUri(n.href,{defaultValidate:e=>!!Dn(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",nn(this.options.HTMLAttributes,n),0]:["a",nn(this.options.HTMLAttributes,{...n,href:""}),0]},markdownTokenName:"link",parseMarkdown:(n,e)=>e.applyMark("link",e.parseInline(n.tokens||[]),{href:n.href,title:n.title||null}),renderMarkdown:(n,e)=>{var t,o,r,s;const i=(o=(t=n.attrs)==null?void 0:t.href)!=null?o:"",l=(s=(r=n.attrs)==null?void 0:r.title)!=null?s:"",c=e.renderChildren(n);return l?`[${c}](${i} "${l}")`:`[${c}](${i})`},addCommands(){return{setLink:n=>({chain:e})=>{const{href:t}=n;return this.options.isAllowedUri(t,{defaultValidate:o=>!!Dn(o,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?e().setMark(this.name,n).setMeta("preventAutolink",!0).run():!1},toggleLink:n=>({chain:e})=>{const{href:t}=n||{};return t&&!this.options.isAllowedUri(t,{defaultValidate:o=>!!Dn(o,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:e().toggleMark(this.name,n,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()},unsetLink:()=>({chain:n})=>n().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta("preventAutolink",!0).run()}},addPasteRules(){return[qo({find:n=>{const e=[];if(n){const{protocols:t,defaultProtocol:o}=this.options,r=Rh(n).filter(s=>s.isLink&&this.options.isAllowedUri(s.value,{defaultValidate:i=>!!Dn(i,t),protocols:t,defaultProtocol:o}));r.length&&r.forEach(s=>{this.options.shouldAutoLink(s.value)&&e.push({text:s.value,data:{href:s.href},index:s.start})})}return e},type:this.type,getAttributes:n=>{var e;return{href:(e=n.data)==null?void 0:e.href}}})]},addProseMirrorPlugins(){const n=[],{protocols:e,defaultProtocol:t}=this.options;return this.options.autolink&&n.push(C2({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:o=>this.options.isAllowedUri(o,{defaultValidate:r=>!!Dn(r,e),protocols:e,defaultProtocol:t}),shouldAutoLink:this.options.shouldAutoLink})),n.push(E2({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick==="whenNotEditable"?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&n.push(v2({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),n}}),Ph=M2,T2=de.create({name:"textAlign",addOptions(){return{types:[],alignments:["left","center","right","justify"],defaultAlignment:null}},addGlobalAttributes(){return[{types:this.options.types,attributes:{textAlign:{default:this.options.defaultAlignment,parseHTML:n=>{const e=n.style.textAlign;return this.options.alignments.includes(e)?e:this.options.defaultAlignment},renderHTML:n=>n.textAlign?{style:`text-align: ${n.textAlign}`}:{}}}}]},addCommands(){return{setTextAlign:n=>({commands:e})=>this.options.alignments.includes(n)?this.options.types.map(t=>e.updateAttributes(t,{textAlign:n})).some(t=>t):!1,unsetTextAlign:()=>({commands:n})=>this.options.types.map(e=>n.resetAttributes(e,"textAlign")).some(e=>e),toggleTextAlign:n=>({editor:e,commands:t})=>this.options.alignments.includes(n)?e.isActive({textAlign:n})?t.unsetTextAlign():t.setTextAlign(n):!1}},addKeyboardShortcuts(){return{"Mod-Shift-l":()=>this.editor.commands.setTextAlign("left"),"Mod-Shift-e":()=>this.editor.commands.setTextAlign("center"),"Mod-Shift-r":()=>this.editor.commands.setTextAlign("right"),"Mod-Shift-j":()=>this.editor.commands.setTextAlign("justify")}}}),Lh=T2,N2=20,Vh=(n,e=0)=>{const t=[];return!n.children.length||e>N2||Array.from(n.children).forEach(o=>{o.tagName==="SPAN"?t.push(o):o.children.length&&t.push(...Vh(o,e+1))}),t},A2=n=>{if(!n.children.length)return;const e=Vh(n);e&&e.forEach(t=>{var o,r;const s=t.getAttribute("style"),i=(r=(o=t.parentElement)==null?void 0:o.closest("span"))==null?void 0:r.getAttribute("style");t.setAttribute("style",`${i};${s}`)})},ca=io.create({name:"textStyle",priority:101,addOptions(){return{HTMLAttributes:{},mergeNestedSpanStyles:!0}},parseHTML(){return[{tag:"span",consuming:!1,getAttrs:n=>n.hasAttribute("style")?(this.options.mergeNestedSpanStyles&&A2(n),{}):!1}]},renderHTML({HTMLAttributes:n}){return["span",nn(this.options.HTMLAttributes,n),0]},addCommands(){return{toggleTextStyle:n=>({commands:e})=>e.toggleMark(this.name,n),removeEmptyTextStyle:()=>({tr:n})=>{const{selection:e}=n;return n.doc.nodesBetween(e.from,e.to,(t,o)=>{if(t.isTextblock)return!0;t.marks.filter(r=>r.type===this.type).some(r=>Object.values(r.attrs).some(s=>!!s))||n.removeMark(o,o+t.nodeSize,this.type)}),!0}}}}),B2=de.create({name:"backgroundColor",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{backgroundColor:{default:null,parseHTML:n=>{var e;const t=n.getAttribute("style");if(t){const o=t.split(";").map(r=>r.trim()).filter(Boolean);for(let r=o.length-1;r>=0;r-=1){const s=o[r].split(":");if(s.length>=2){const i=s[0].trim().toLowerCase(),l=s.slice(1).join(":").trim();if(i==="background-color")return l.replace(/['"]+/g,"")}}}return(e=n.style.backgroundColor)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:n=>n.backgroundColor?{style:`background-color: ${n.backgroundColor}`}:{}}}}]},addCommands(){return{setBackgroundColor:n=>({chain:e})=>e().setMark("textStyle",{backgroundColor:n}).run(),unsetBackgroundColor:()=>({chain:n})=>n().setMark("textStyle",{backgroundColor:null}).removeEmptyTextStyle().run()}}}),$h=de.create({name:"color",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{color:{default:null,parseHTML:n=>{var e;const t=n.getAttribute("style");if(t){const o=t.split(";").map(r=>r.trim()).filter(Boolean);for(let r=o.length-1;r>=0;r-=1){const s=o[r].split(":");if(s.length>=2){const i=s[0].trim().toLowerCase(),l=s.slice(1).join(":").trim();if(i==="color")return l.replace(/['"]+/g,"")}}}return(e=n.style.color)==null?void 0:e.replace(/['"]+/g,"")},renderHTML:n=>n.color?{style:`color: ${n.color}`}:{}}}}]},addCommands(){return{setColor:n=>({chain:e})=>e().setMark("textStyle",{color:n}).run(),unsetColor:()=>({chain:n})=>n().setMark("textStyle",{color:null}).removeEmptyTextStyle().run()}}}),I2=de.create({name:"fontFamily",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontFamily:{default:null,parseHTML:n=>n.style.fontFamily,renderHTML:n=>n.fontFamily?{style:`font-family: ${n.fontFamily}`}:{}}}}]},addCommands(){return{setFontFamily:n=>({chain:e})=>e().setMark("textStyle",{fontFamily:n}).run(),unsetFontFamily:()=>({chain:n})=>n().setMark("textStyle",{fontFamily:null}).removeEmptyTextStyle().run()}}}),O2=de.create({name:"fontSize",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{fontSize:{default:null,parseHTML:n=>n.style.fontSize,renderHTML:n=>n.fontSize?{style:`font-size: ${n.fontSize}`}:{}}}}]},addCommands(){return{setFontSize:n=>({chain:e})=>e().setMark("textStyle",{fontSize:n}).run(),unsetFontSize:()=>({chain:n})=>n().setMark("textStyle",{fontSize:null}).removeEmptyTextStyle().run()}}}),_2=de.create({name:"lineHeight",addOptions(){return{types:["textStyle"]}},addGlobalAttributes(){return[{types:this.options.types,attributes:{lineHeight:{default:null,parseHTML:n=>n.style.lineHeight,renderHTML:n=>n.lineHeight?{style:`line-height: ${n.lineHeight}`}:{}}}}]},addCommands(){return{setLineHeight:n=>({chain:e})=>e().setMark("textStyle",{lineHeight:n}).run(),unsetLineHeight:()=>({chain:n})=>n().setMark("textStyle",{lineHeight:null}).removeEmptyTextStyle().run()}}});de.create({name:"textStyleKit",addExtensions(){const n=[];return this.options.backgroundColor!==!1&&n.push(B2.configure(this.options.backgroundColor)),this.options.color!==!1&&n.push($h.configure(this.options.color)),this.options.fontFamily!==!1&&n.push(I2.configure(this.options.fontFamily)),this.options.fontSize!==!1&&n.push(O2.configure(this.options.fontSize)),this.options.lineHeight!==!1&&n.push(_2.configure(this.options.lineHeight)),this.options.textStyle!==!1&&n.push(ca.configure(this.options.textStyle)),n}});var zh=$h;function D2(n={}){return new pe({view(e){return new R2(e,n)}})}class R2{constructor(e,t){var o;this.editorView=e,this.cursorPos=null,this.element=null,this.timeout=-1,this.width=(o=t.width)!==null&&o!==void 0?o:1,this.color=t.color===!1?void 0:t.color||"black",this.class=t.class,this.handlers=["dragover","dragend","drop","dragleave"].map(r=>{let s=i=>{this[r](i)};return e.dom.addEventListener(r,s),{name:r,handler:s}})}destroy(){this.handlers.forEach(({name:e,handler:t})=>this.editorView.dom.removeEventListener(e,t))}update(e,t){this.cursorPos!=null&&t.doc!=e.state.doc&&(this.cursorPos>e.state.doc.content.size?this.setCursor(null):this.updateOverlay())}setCursor(e){e!=this.cursorPos&&(this.cursorPos=e,e==null?(this.element.parentNode.removeChild(this.element),this.element=null):this.updateOverlay())}updateOverlay(){let e=this.editorView.state.doc.resolve(this.cursorPos),t=!e.parent.inlineContent,o,r=this.editorView.dom,s=r.getBoundingClientRect(),i=s.width/r.offsetWidth,l=s.height/r.offsetHeight;if(t){let f=e.nodeBefore,h=e.nodeAfter;if(f||h){let p=this.editorView.nodeDOM(this.cursorPos-(f?f.nodeSize:0));if(p){let m=p.getBoundingClientRect(),g=f?m.bottom:m.top;f&&h&&(g=(g+this.editorView.nodeDOM(this.cursorPos).getBoundingClientRect().top)/2);let y=this.width/2*l;o={left:m.left,right:m.right,top:g-y,bottom:g+y}}}}if(!o){let f=this.editorView.coordsAtPos(this.cursorPos),h=this.width/2*i;o={left:f.left-h,right:f.left+h,top:f.top,bottom:f.bottom}}let c=this.editorView.dom.offsetParent;this.element||(this.element=c.appendChild(document.createElement("div")),this.class&&(this.element.className=this.class),this.element.style.cssText="position: absolute; z-index: 50; pointer-events: none;",this.color&&(this.element.style.backgroundColor=this.color)),this.element.classList.toggle("prosemirror-dropcursor-block",t),this.element.classList.toggle("prosemirror-dropcursor-inline",!t);let d,u;if(!c||c==document.body&&getComputedStyle(c).position=="static")d=-pageXOffset,u=-pageYOffset;else{let f=c.getBoundingClientRect(),h=f.width/c.offsetWidth,p=f.height/c.offsetHeight;d=f.left-c.scrollLeft*h,u=f.top-c.scrollTop*p}this.element.style.left=(o.left-d)/i+"px",this.element.style.top=(o.top-u)/l+"px",this.element.style.width=(o.right-o.left)/i+"px",this.element.style.height=(o.bottom-o.top)/l+"px"}scheduleRemoval(e){clearTimeout(this.timeout),this.timeout=setTimeout(()=>this.setCursor(null),e)}dragover(e){if(!this.editorView.editable)return;let t=this.editorView.posAtCoords({left:e.clientX,top:e.clientY}),o=t&&t.inside>=0&&this.editorView.state.doc.nodeAt(t.inside),r=o&&o.type.spec.disableDropCursor,s=typeof r=="function"?r(this.editorView,t,e):r;if(t&&!s){let i=t.pos;if(this.editorView.dragging&&this.editorView.dragging.slice){let l=Vd(this.editorView.state.doc,i,this.editorView.dragging.slice);l!=null&&(i=l)}this.setCursor(i),this.scheduleRemoval(5e3)}}dragend(){this.scheduleRemoval(20)}drop(){this.scheduleRemoval(20)}dragleave(e){this.editorView.dom.contains(e.relatedTarget)||this.setCursor(null)}}class ge extends ee{constructor(e){super(e,e)}map(e,t){let o=e.resolve(t.map(this.head));return ge.valid(o)?new ge(o):ee.near(o)}content(){return U.empty}eq(e){return e instanceof ge&&e.head==this.head}toJSON(){return{type:"gapcursor",pos:this.head}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for GapCursor.fromJSON");return new ge(e.resolve(t.pos))}getBookmark(){return new da(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!P2(e)||!L2(e))return!1;let o=t.type.spec.allowGapCursor;if(o!=null)return o;let r=t.contentMatchAt(e.index()).defaultType;return r&&r.isTextblock}static findGapCursorFrom(e,t,o=!1){e:for(;;){if(!o&&ge.valid(e))return e;let r=e.pos,s=null;for(let i=e.depth;;i--){let l=e.node(i);if(t>0?e.indexAfter(i)<l.childCount:e.index(i)>0){s=l.child(t>0?e.indexAfter(i):e.index(i)-1);break}else if(i==0)return null;r+=t;let c=e.doc.resolve(r);if(ge.valid(c))return c}for(;;){let i=t>0?s.firstChild:s.lastChild;if(!i){if(s.isAtom&&!s.isText&&!Y.isSelectable(s)){e=e.doc.resolve(r+s.nodeSize*t),o=!1;continue e}break}s=i,r+=t;let l=e.doc.resolve(r);if(ge.valid(l))return l}return null}}}ge.prototype.visible=!1,ge.findFrom=ge.findGapCursorFrom,ee.jsonID("gapcursor",ge);class da{constructor(e){this.pos=e}map(e){return new da(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return ge.valid(t)?new ge(t):ee.near(t)}}function Fh(n){return n.isAtom||n.spec.isolating||n.spec.createGapCursor}function P2(n){for(let e=n.depth;e>=0;e--){let t=n.index(e),o=n.node(e);if(t==0){if(o.type.spec.isolating)return!0;continue}for(let r=o.child(t-1);;r=r.lastChild){if(r.childCount==0&&!r.inlineContent||Fh(r.type))return!0;if(r.inlineContent)return!1}}return!0}function L2(n){for(let e=n.depth;e>=0;e--){let t=n.indexAfter(e),o=n.node(e);if(t==o.childCount){if(o.type.spec.isolating)return!0;continue}for(let r=o.child(t);;r=r.firstChild){if(r.childCount==0&&!r.inlineContent||Fh(r.type))return!0;if(r.inlineContent)return!1}}return!0}function V2(){return new pe({props:{decorations:H2,createSelectionBetween(n,e,t){return e.pos==t.pos&&ge.valid(t)?new ge(t):null},handleClick:z2,handleKeyDown:$2,handleDOMEvents:{beforeinput:F2}}})}const $2=Mf({ArrowLeft:$s("horiz",-1),ArrowRight:$s("horiz",1),ArrowUp:$s("vert",-1),ArrowDown:$s("vert",1)});function $s(n,e){const t=n=="vert"?e>0?"down":"up":e>0?"right":"left";return function(o,r,s){let i=o.selection,l=e>0?i.$to:i.$from,c=i.empty;if(i instanceof Q){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=o.doc.resolve(e>0?l.after():l.before())}let d=ge.findGapCursorFrom(l,e,c);return d?(r&&r(o.tr.setSelection(new ge(d))),!0):!1}}function z2(n,e,t){if(!n||!n.editable)return!1;let o=n.state.doc.resolve(e);if(!ge.valid(o))return!1;let r=n.posAtCoords({left:t.clientX,top:t.clientY});return r&&r.inside>-1&&Y.isSelectable(n.state.doc.nodeAt(r.inside))?!1:(n.dispatch(n.state.tr.setSelection(new ge(o))),!0)}function F2(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof ge))return!1;let{$from:t}=n.state.selection,o=t.parent.contentMatchAt(t.index()).findWrapping(n.state.schema.nodes.text);if(!o)return!1;let r=P.empty;for(let i=o.length-1;i>=0;i--)r=P.from(o[i].createAndFill(null,r));let s=n.state.tr.replace(t.pos,t.pos,new U(r,0,0));return s.setSelection(Q.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function H2(n){if(!(n.selection instanceof ge))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",he.create(n.doc,[Fe.widget(n.selection.head,e,{key:"gapcursor"})])}var zs=200,ve=function(){};ve.prototype.append=function(e){return e.length?(e=ve.from(e),!this.length&&e||e.length<zs&&this.leafAppend(e)||this.length<zs&&e.leafPrepend(this)||this.appendInner(e)):this},ve.prototype.prepend=function(e){return e.length?ve.from(e).append(this):this},ve.prototype.appendInner=function(e){return new j2(this,e)},ve.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?ve.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},ve.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},ve.prototype.forEach=function(e,t,o){t===void 0&&(t=0),o===void 0&&(o=this.length),t<=o?this.forEachInner(e,t,o,0):this.forEachInvertedInner(e,t,o,0)},ve.prototype.map=function(e,t,o){t===void 0&&(t=0),o===void 0&&(o=this.length);var r=[];return this.forEach(function(s,i){return r.push(e(s,i))},t,o),r},ve.from=function(e){return e instanceof ve?e:e&&e.length?new Hh(e):ve.empty};var Hh=function(n){function e(o){n.call(this),this.values=o}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(r,s){return r==0&&s==this.length?this:new e(this.values.slice(r,s))},e.prototype.getInner=function(r){return this.values[r]},e.prototype.forEachInner=function(r,s,i,l){for(var c=s;c<i;c++)if(r(this.values[c],l+c)===!1)return!1},e.prototype.forEachInvertedInner=function(r,s,i,l){for(var c=s-1;c>=i;c--)if(r(this.values[c],l+c)===!1)return!1},e.prototype.leafAppend=function(r){if(this.length+r.length<=zs)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=zs)return new e(r.flatten().concat(this.values))},t.length.get=function(){return this.values.length},t.depth.get=function(){return 0},Object.defineProperties(e.prototype,t),e}(ve);ve.empty=new Hh([]);var j2=function(n){function e(t,o){n.call(this),this.left=t,this.right=o,this.length=t.length+o.length,this.depth=Math.max(t.depth,o.depth)+1}return n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e,e.prototype.flatten=function(){return this.left.flatten().concat(this.right.flatten())},e.prototype.getInner=function(o){return o<this.left.length?this.left.get(o):this.right.get(o-this.left.length)},e.prototype.forEachInner=function(o,r,s,i){var l=this.left.length;if(r<l&&this.left.forEachInner(o,r,Math.min(s,l),i)===!1||s>l&&this.right.forEachInner(o,Math.max(r-l,0),Math.min(this.length,s)-l,i+l)===!1)return!1},e.prototype.forEachInvertedInner=function(o,r,s,i){var l=this.left.length;if(r>l&&this.right.forEachInvertedInner(o,r-l,Math.max(s,l)-l,i+l)===!1||s<l&&this.left.forEachInvertedInner(o,Math.min(r,l),s,i)===!1)return!1},e.prototype.sliceInner=function(o,r){if(o==0&&r==this.length)return this;var s=this.left.length;return r<=s?this.left.slice(o,r):o>=s?this.right.slice(o-s,r-s):this.left.slice(o,s).append(this.right.slice(0,r-s))},e.prototype.leafAppend=function(o){var r=this.right.leafAppend(o);if(r)return new e(this.left,r)},e.prototype.leafPrepend=function(o){var r=this.left.leafPrepend(o);if(r)return new e(r,this.right)},e.prototype.appendInner=function(o){return this.left.depth>=Math.max(this.right.depth,o.depth)+1?new e(this.left,new e(this.right,o)):new e(this,o)},e}(ve);const U2=500;class st{constructor(e,t){this.items=e,this.eventCount=t}popEvent(e,t){if(this.eventCount==0)return null;let o=this.items.length;for(;;o--)if(this.items.get(o-1).selection){--o;break}let r,s;t&&(r=this.remapping(o,this.items.length),s=r.maps.length);let i=e.tr,l,c,d=[],u=[];return this.items.forEach((f,h)=>{if(!f.step){r||(r=this.remapping(o,h+1),s=r.maps.length),s--,u.push(f);return}if(r){u.push(new kt(f.map));let p=f.step.map(r.slice(s)),m;p&&i.maybeStep(p).doc&&(m=i.mapping.maps[i.mapping.maps.length-1],d.push(new kt(m,void 0,void 0,d.length+u.length))),s--,m&&r.appendMap(m,s)}else i.maybeStep(f.step);if(f.selection)return l=r?f.selection.map(r.slice(s)):f.selection,c=new st(this.items.slice(0,o).append(u.reverse().concat(d)),this.eventCount-1),!1},this.items.length,0),{remaining:c,transform:i,selection:l}}addTransform(e,t,o,r){let s=[],i=this.eventCount,l=this.items,c=!r&&l.length?l.get(l.length-1):null;for(let u=0;u<e.steps.length;u++){let f=e.steps[u].invert(e.docs[u]),h=new kt(e.mapping.maps[u],f,t),p;(p=c&&c.merge(h))&&(h=p,u?s.pop():l=l.slice(0,l.length-1)),s.push(h),t&&(i++,t=void 0),r||(c=h)}let d=i-o.depth;return d>K2&&(l=W2(l,d),i-=d),new st(l.append(s),i)}remapping(e,t){let o=new No;return this.items.forEach((r,s)=>{let i=r.mirrorOffset!=null&&s-r.mirrorOffset>=e?o.maps.length-r.mirrorOffset:void 0;o.appendMap(r.map,i)},e,t),o}addMaps(e){return this.eventCount==0?this:new st(this.items.append(e.map(t=>new kt(t))),this.eventCount)}rebased(e,t){if(!this.eventCount)return this;let o=[],r=Math.max(0,this.items.length-t),s=e.mapping,i=e.steps.length,l=this.eventCount;this.items.forEach(h=>{h.selection&&l--},r);let c=t;this.items.forEach(h=>{let p=s.getMirror(--c);if(p==null)return;i=Math.min(i,p);let m=s.maps[p];if(h.step){let g=e.steps[p].invert(e.docs[p]),y=h.selection&&h.selection.map(s.slice(c+1,p));y&&l++,o.push(new kt(m,g,y))}else o.push(new kt(m))},r);let d=[];for(let h=t;h<i;h++)d.push(new kt(s.maps[h]));let u=this.items.slice(0,r).append(d).append(o),f=new st(u,l);return f.emptyItemCount()>U2&&(f=f.compress(this.items.length-o.length)),f}emptyItemCount(){let e=0;return this.items.forEach(t=>{t.step||e++}),e}compress(e=this.items.length){let t=this.remapping(0,e),o=t.maps.length,r=[],s=0;return this.items.forEach((i,l)=>{if(l>=e)r.push(i),i.selection&&s++;else if(i.step){let c=i.step.map(t.slice(o)),d=c&&c.getMap();if(o--,d&&t.appendMap(d,o),c){let u=i.selection&&i.selection.map(t.slice(o));u&&s++;let f=new kt(d.invert(),c,u),h,p=r.length-1;(h=r.length&&r[p].merge(f))?r[p]=h:r.push(f)}}else i.map&&o--},this.items.length,0),new st(ve.from(r.reverse()),s)}}st.empty=new st(ve.empty,0);function W2(n,e){let t;return n.forEach((o,r)=>{if(o.selection&&e--==0)return t=r,!1}),n.slice(t)}class kt{constructor(e,t,o,r){this.map=e,this.step=t,this.selection=o,this.mirrorOffset=r}merge(e){if(this.step&&e.step&&!e.selection){let t=e.step.merge(this.step);if(t)return new kt(t.getMap().invert(),t,this.selection)}}}class ln{constructor(e,t,o,r,s){this.done=e,this.undone=t,this.prevRanges=o,this.prevTime=r,this.prevComposition=s}}const K2=20;function q2(n,e,t,o){let r=t.getMeta(Rn),s;if(r)return r.historyState;t.getMeta(Y2)&&(n=new ln(n.done,n.undone,null,0,-1));let i=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(i&&i.getMeta(Rn))return i.getMeta(Rn).redo?new ln(n.done.addTransform(t,void 0,o,Fs(e)),n.undone,jh(t.mapping.maps),n.prevTime,n.prevComposition):new ln(n.done,n.undone.addTransform(t,void 0,o,Fs(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(i&&i.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),c=n.prevTime==0||!i&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-o.newGroupDelay||!J2(t,n.prevRanges)),d=i?ua(n.prevRanges,t.mapping):jh(t.mapping.maps);return new ln(n.done.addTransform(t,c?e.selection.getBookmark():void 0,o,Fs(e)),st.empty,d,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new ln(n.done.rebased(t,s),n.undone.rebased(t,s),ua(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new ln(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),ua(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function J2(n,e){if(!e)return!1;if(!n.docChanged)return!0;let t=!1;return n.mapping.maps[0].forEach((o,r)=>{for(let s=0;s<e.length;s+=2)o<=e[s+1]&&r>=e[s]&&(t=!0)}),t}function jh(n){let e=[];for(let t=n.length-1;t>=0&&e.length==0;t--)n[t].forEach((o,r,s,i)=>e.push(s,i));return e}function ua(n,e){if(!n)return null;let t=[];for(let o=0;o<n.length;o+=2){let r=e.map(n[o],1),s=e.map(n[o+1],-1);r<=s&&t.push(r,s)}return t}function G2(n,e,t){let o=Fs(e),r=Rn.get(e).spec.config,s=(t?n.undone:n.done).popEvent(e,o);if(!s)return null;let i=s.selection.resolve(s.transform.doc),l=(t?n.done:n.undone).addTransform(s.transform,e.selection.getBookmark(),r,o),c=new ln(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(i).setMeta(Rn,{redo:t,historyState:c})}let fa=!1,Uh=null;function Fs(n){let e=n.plugins;if(Uh!=e){fa=!1,Uh=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){fa=!0;break}}return fa}const Rn=new Ce("history"),Y2=new Ce("closeHistory");function X2(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new pe({key:Rn,state:{init(){return new ln(st.empty,st.empty,null,0,-1)},apply(e,t,o){return q2(t,o,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let o=t.inputType,r=o=="historyUndo"?Kh:o=="historyRedo"?qh:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function Wh(n,e){return(t,o)=>{let r=Rn.getState(t);if(!r||(n?r.undone:r.done).eventCount==0)return!1;if(o){let s=G2(r,t,n);s&&o(e?s.scrollIntoView():s)}return!0}}const Kh=Wh(!1,!0),qh=Wh(!0,!0);de.create({name:"characterCount",addOptions(){return{limit:null,mode:"textSize",textCounter:n=>n.length,wordCounter:n=>n.split(" ").filter(e=>e!=="").length}},addStorage(){return{characters:()=>0,words:()=>0}},onBeforeCreate(){this.storage.characters=n=>{const e=(n==null?void 0:n.node)||this.editor.state.doc;if(((n==null?void 0:n.mode)||this.options.mode)==="textSize"){const o=e.textBetween(0,e.content.size,void 0," ");return this.options.textCounter(o)}return e.nodeSize},this.storage.words=n=>{const e=(n==null?void 0:n.node)||this.editor.state.doc,t=e.textBetween(0,e.content.size," "," ");return this.options.wordCounter(t)}},addProseMirrorPlugins(){let n=!1;return[new pe({key:new Ce("characterCount"),appendTransaction:(e,t,o)=>{if(n)return;const r=this.options.limit;if(r==null||r===0){n=!0;return}const s=this.storage.characters({node:o.doc});if(s>r){const i=s-r,l=0,c=i;console.warn(`[CharacterCount] Initial content exceeded limit of ${r} characters. Content was automatically trimmed.`);const d=o.tr.deleteRange(l,c);return n=!0,d}n=!0},filterTransaction:(e,t)=>{const o=this.options.limit;if(!e.docChanged||o===0||o===null||o===void 0)return!0;const r=this.storage.characters({node:t.doc}),s=this.storage.characters({node:e.doc});if(s<=o||r>o&&s>o&&s<=r)return!0;if(r>o&&s>o&&s>r||!e.getMeta("paste"))return!1;const l=e.selection.$head.pos,c=s-o,d=l-c,u=l;return e.deleteRange(d,u),!(this.storage.characters({node:e.doc})>o)}})]}}),de.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[D2(this.options)]}}),de.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new pe({key:new Ce("focus"),props:{decorations:({doc:n,selection:e})=>{const{isEditable:t,isFocused:o}=this.editor,{anchor:r}=e,s=[];if(!t||!o)return he.create(n,[]);let i=0;this.options.mode==="deepest"&&n.descendants((c,d)=>{if(c.isText)return;if(!(r>=d&&r<=d+c.nodeSize-1))return!1;i+=1});let l=0;return n.descendants((c,d)=>{if(c.isText||!(r>=d&&r<=d+c.nodeSize-1))return!1;if(l+=1,this.options.mode==="deepest"&&i-l>0||this.options.mode==="shallowest"&&l>1)return this.options.mode==="deepest";s.push(Fe.node(d,d+c.nodeSize,{class:this.options.className}))}),he.create(n,s)}}})]}}),de.create({name:"gapCursor",addProseMirrorPlugins(){return[V2()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=ae(q(n,"allowGapCursor",t)))!=null?e:null}}});var Jh="placeholder";function Q2(n){return n.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}de.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:Jh,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){const n=this.options.dataAttribute?`data-${Q2(this.options.dataAttribute)}`:`data-${Jh}`;return[new pe({key:new Ce("placeholder"),props:{decorations:({doc:e,selection:t})=>{const o=this.editor.isEditable||!this.options.showOnlyWhenEditable,{anchor:r}=t,s=[];if(!o)return null;const i=this.editor.isEmpty;return e.descendants((l,c)=>{const d=r>=c&&r<=c+l.nodeSize,u=!l.isLeaf&&es(l);if((d||!this.options.showOnlyCurrent)&&u){const f=[this.options.emptyNodeClass];i&&f.push(this.options.emptyEditorClass);const h=Fe.node(c,c+l.nodeSize,{class:f.join(" "),[n]:typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:l,pos:c,hasAnchor:d}):this.options.placeholder});s.push(h)}return this.options.includeChildren}),he.create(e,s)}}})]}}),de.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:n,options:e}=this;return[new pe({key:new Ce("selection"),props:{decorations(t){return t.selection.empty||n.isFocused||!n.isEditable||Uw(t.selection)||n.view.dragging?null:he.create(t.doc,[Fe.inline(t.selection.from,t.selection.to,{class:e.className})])}}})]}});function Gh({types:n,node:e}){return e&&Array.isArray(n)&&n.includes(e.type)||(e==null?void 0:e.type)===n}de.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var n;const e=new Ce(this.name),t=this.options.node||((n=this.editor.schema.topNodeType.contentMatch.defaultType)==null?void 0:n.name)||"paragraph",o=Object.entries(this.editor.schema.nodes).map(([,r])=>r).filter(r=>(this.options.notAfter||[]).concat(t).includes(r.name));return[new pe({key:e,appendTransaction:(r,s,i)=>{const{doc:l,tr:c,schema:d}=i,u=e.getState(i),f=l.content.size,h=d.nodes[t];if(u)return c.insert(f,h.create())},state:{init:(r,s)=>{const i=s.tr.doc.lastChild;return!Gh({node:i,types:o})},apply:(r,s)=>{if(!r.docChanged||r.getMeta("__uniqueIDTransaction"))return s;const i=r.doc.lastChild;return!Gh({node:i,types:o})}}})]}});var Z2=de.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>Kh(n,e),redo:()=>({state:n,dispatch:e})=>qh(n,e)}},addProseMirrorPlugins(){return[X2(this.options)]},addKeyboardShortcuts(){return{"Mod-z":()=>this.editor.commands.undo(),"Shift-Mod-z":()=>this.editor.commands.redo(),"Mod-y":()=>this.editor.commands.redo(),"Mod-я":()=>this.editor.commands.undo(),"Shift-Mod-я":()=>this.editor.commands.redo()}}});const an="editing",ha=50,Hs=1e3;function Yh(n,e){if(!e)return n;let t=null;for(const o of Object.keys(n)){if(o==="block")continue;const r=e(o);!r||Object.keys(r).length===0||(t??(t={...n}),t[o]={...r,...n[o]})}return t??n}function pa(n){var e;if(!n)return null;try{const t=JSON.parse(n);return(e=t.block)!=null&&e.tag?t:(console.warn("Block snapshot missing required tag:",t),null)}catch{return console.warn("Invalid block snapshot JSON:",n),null}}function rr(n,e,t){const o=w.getBlockDef(n,e.block.tag);if(!o)throw new Error(`Block placement: block definition for tag "${e.block.tag}" not found`);const r=e.block.size??[100,100],s=[t[0]-r[0]/2,t[1]-r[1]/2];w.Grid.snapPosition(n,s);const[i,l]=s,c=e.block.rank??w.RankBounds.genNext(n),d=w.createEntity(n);"synced"in e||w.addComponent(n,d,w.Synced,{id:crypto.randomUUID()});const u=Object.assign({},e.block,{position:[i,l],size:r,rank:c});w.addComponent(n,d,w.Block,u);for(const f of o.components)if(!(f.name in e))w.addComponent(n,d,f);else{const h=e[f.name];w.addComponent(n,d,f,h)}return d}function eS(n){return n.trimEnd().split(/\r?\n/).map(e=>`<p>${e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")||""}</p>`).join("")}function Xh(n){if(n.startsWith("#"))return n.toUpperCase();const e=n.match(/rgba?\((\d+),\s*(\d+),\s*(\d+)/);if(e){const t=parseInt(e[1],10).toString(16).padStart(2,"0"),o=parseInt(e[2],10).toString(16).padStart(2,"0"),r=parseInt(e[3],10).toString(16).padStart(2,"0");return`#${t}${o}${r}`.toUpperCase()}return n}function sr(n){const e=Math.round(n.red),t=Math.round(n.green),o=Math.round(n.blue),r=Math.round(n.alpha);return r<255?"#"+[e,t,o,r].map(s=>{const i=s.toString(16);return i.length===1?`0${i}`:i}).join(""):"#"+[e,t,o].map(s=>{const i=s.toString(16);return i.length===1?`0${i}`:i}).join("")}function ma(n){n=n.replace(/^#/,"");let e,t,o,r=255;if(n.length===6)e=parseInt(n.slice(0,2),16),t=parseInt(n.slice(2,4),16),o=parseInt(n.slice(4,6),16);else if(n.length===8)e=parseInt(n.slice(0,2),16),t=parseInt(n.slice(2,4),16),o=parseInt(n.slice(4,6),16),r=parseInt(n.slice(6,8),16);else return null;return{red:e,green:t,blue:o,alpha:r}}function Qh(n){const e=ma(n);if(!e)return{h:0,s:100,v:100,a:255};const t=e.red/255,o=e.green/255,r=e.blue/255,s=Math.max(t,o,r),i=Math.min(t,o,r),l=s-i;let c=0;const d=s===0?0:l/s*100,u=s*100;if(l!==0)switch(s){case t:c=((o-r)/l+(o<r?6:0))*60;break;case o:c=((r-t)/l+2)*60;break;case r:c=((t-o)/l+4)*60;break}return{h:c,s:d,v:u,a:e.alpha}}function Zh(n){const e=n.h/360,t=n.s/100,o=n.v/100;let r=0,s=0,i=0;const l=Math.floor(e*6),c=e*6-l,d=o*(1-t),u=o*(1-c*t),f=o*(1-(1-c)*t);switch(l%6){case 0:r=o,s=f,i=d;break;case 1:r=u,s=o,i=d;break;case 2:r=d,s=o,i=f;break;case 3:r=d,s=u,i=o;break;case 4:r=f,s=d,i=o;break;case 5:r=o,s=d,i=u;break}const h=p=>Math.round(p*255).toString(16).padStart(2,"0");return`#${h(r)}${h(s)}${h(i)}`}function ep(n){const e=n.h/360,t=n.s/100,o=n.v/100;let r=0,s=0,i=0;const l=Math.floor(e*6),c=e*6-l,d=o*(1-t),u=o*(1-c*t),f=o*(1-(1-c)*t);switch(l%6){case 0:r=o,s=f,i=d;break;case 1:r=u,s=o,i=d;break;case 2:r=d,s=o,i=f;break;case 3:r=d,s=u,i=o;break;case 4:r=f,s=d,i=o;break;case 5:r=o,s=d,i=u;break}const h=m=>Math.round(m*255).toString(16).padStart(2,"0"),p=Math.round(n.a).toString(16).padStart(2,"0");return n.a<255?`#${h(r)}${h(s)}${h(i)}${p}`:`#${h(r)}${h(s)}${h(i)}`}const ke=a.shallowRef(null),ga=a.shallowRef(null),ya=a.shallowRef(null),it=a.ref(0);function Pn(){const n={hasEditor:a.computed(()=>ke.value!==null),isBold:a.computed(()=>{var i;return it.value,((i=ke.value)==null?void 0:i.isActive("bold"))??!1}),isItalic:a.computed(()=>{var i;return it.value,((i=ke.value)==null?void 0:i.isActive("italic"))??!1}),isUnderline:a.computed(()=>{var i;return it.value,((i=ke.value)==null?void 0:i.isActive("underline"))??!1}),alignment:a.computed(()=>{it.value;const i=ke.value;return i?i.isActive({textAlign:"center"})?"center":i.isActive({textAlign:"right"})?"right":i.isActive({textAlign:"justify"})?"justify":"left":"left"}),color:a.computed(()=>{it.value;const i=ke.value;if(!i)return null;const c=i.getAttributes("textStyle").color??null;return c?Xh(c):null}),linkHref:a.computed(()=>{it.value;const i=ke.value;return i?i.getAttributes("link").href??null:null})},e={toggleBold(){const i=ke.value;if(!i)return;const{from:l,to:c}=i.state.selection,d=l===c;let u=i.chain().focus();d&&(u=u.selectAll()),u=u.toggleBold(),d&&(u=u.setTextSelection(c)),u.run()},toggleItalic(){const i=ke.value;if(!i)return;const{from:l,to:c}=i.state.selection,d=l===c;let u=i.chain().focus();d&&(u=u.selectAll()),u=u.toggleItalic(),d&&(u=u.setTextSelection(c)),u.run()},toggleUnderline(){const i=ke.value;if(!i)return;const{from:l,to:c}=i.state.selection,d=l===c;let u=i.chain().focus();d&&(u=u.selectAll()),u=u.toggleUnderline(),d&&(u=u.setTextSelection(c)),u.run()},setAlignment(i){const l=ke.value;l&&l.chain().selectAll().setTextAlign(i).run()},setColor(i){const l=ke.value;if(!l)return;const{from:c,to:d}=l.state.selection;c===d?l.chain().focus().selectAll().setColor(i).setTextSelection(d).run():l.chain().focus().setColor(i).run()},setMark(i,l){const c=ke.value;if(!c)return;const{from:d,to:u}=c.state.selection;d===u?c.chain().focus().selectAll().setMark(i,l).setTextSelection(u).run():c.chain().focus().setMark(i,l).run()},unsetMark(i){const l=ke.value;if(!l)return;const{from:c,to:d}=l.state.selection;c===d?l.chain().focus().selectAll().unsetMark(i).setTextSelection(d).run():l.chain().focus().unsetMark(i).run()},setLink(i){const l=ke.value;if(!l)return;const{from:c,to:d}=l.state.selection;c===d?l.chain().focus().selectAll().setLink({href:i}).setTextSelection(d).run():l.chain().focus().setLink({href:i}).run()},removeLink(){const i=ke.value;if(!i)return;const{from:l,to:c}=i.state.selection;l===c?i.chain().focus().selectAll().unsetLink().setTextSelection(c).run():i.chain().focus().unsetLink().run()}};function t(i,l,c){ke.value=i,ya.value=l,ga.value=c,i.on("selectionUpdate",()=>{it.value++}),i.on("transaction",()=>{it.value++})}function o(){ke.value=null,ya.value=null,ga.value=null}function r(){requestAnimationFrame(()=>{requestAnimationFrame(()=>{it.value++})})}function s(i){it.value;const l=ke.value;return l&&l.isActive(i)?l.getAttributes(i):null}return{editor:ke,blockElement:ga,textElement:ya,state:n,commands:e,updateCounter:it,register:t,unregister:o,repositionMenu:r,getMarkAttrs:s}}const tp=1,np="Synced",op="application/x-woven-canvas",rp=w.defineQuery(n=>n.with(w.Block,w.Selected));function tS(n){let e=[...rp.current(n)];if(e.length===0)return null;const t=new Set(e);for(const f of e)for(const h of w.getDescendants(n,f))t.add(h);e=[...t];const{componentsById:o}=w.getResources(n),r=new Map([...o].filter(([,f])=>f.sync==="document")),s=w.Synced._getComponentId(n),i=new Set;for(const f of e)w.hasComponent(n,f,w.Synced)&&i.add(w.Synced.read(n,f).id);const l=new Set(e),c=[],d=ie.Aabb.zero();let u=!1;for(const f of e){const h={};w.hasComponent(n,f,w.Synced)&&(h[np]=w.Synced.snapshot(n,f));for(const p of n.entityBuffer.getComponentIds(f)){if(p===s)continue;const m=r.get(p);if(m){const g=m.snapshot(n,f),y=oS(n,m.schema,g);if(m.name==="block"&&y.parentId!=null){const k=w.Block.read(n,f).parentId;if(k!==null&&!l.has(k)){const x=w.Block.getWorldPosition(n,f);y.position=[x[0],x[1]],y.parentId=null}}h[m.name]=y}}if(c.push(h),w.hasComponent(n,f,w.Aabb)){const{value:p}=w.Aabb.read(n,f);u?ie.Aabb.union(d,p):(ie.Aabb.copy(d,p),u=!0)}}return{version:tp,center:ie.Aabb.center(d),entities:c}}function nS(n,e){let t;try{t=JSON.parse(e)}catch{return null}if(!t||t.version!==tp||!Array.isArray(t.entities)||t.entities.length===0)return null;const{componentsByName:o}=w.getResources(n),r=w.Synced._getComponentId(n),s=[];for(const i of t.entities){const l=new Map;for(const[c,d]of Object.entries(i)){if(c===np){l.set(r,d);continue}const u=o.get(c);u&&u.sync==="document"&&l.set(u._getComponentId(n),d)}s.push(l)}return{entities:s,center:t.center}}function oS(n,e,t){var r;const o={...t};for(const[s,i]of Object.entries(e))if(((r=i==null?void 0:i.def)==null?void 0:r.type)==="ref"){const l=t[s];o[s]=l!=null&&w.hasComponent(n,l,w.Synced)?w.Synced.read(n,l).id:null}return o}function rS(n){var t;const e=[];for(const[o,r]of Object.entries(n))((t=r==null?void 0:r.def)==null?void 0:t.type)==="ref"&&e.push(o);return e}function sS(n,e,t,o,r){var i;const s=t.write(n,e);for(const[l,c]of Object.entries(t.schema))if(((i=c==null?void 0:c.def)==null?void 0:i.type)==="ref"){const d=o[l];d!=null&&(s[l]=r.get(d)??null)}}function sp(n,e,t,o){if(e.length===0)return;const{componentsById:r}=w.getResources(n),s=new Map([...r].filter(([,p])=>p.sync==="document")),i=w.Synced._getComponentId(n),l=w.Block._getComponentId(n);let c;if(o)c=ie.Vec2.clone(o),ie.Vec2.sub(c,t);else{const p=w.Camera.getWorldCenter(n);c=ie.Vec2.clone(p),ie.Vec2.sub(c,t),w.Grid.snapPosition(n,c)}const d=[...e].sort((p,m)=>{var k,x;const g=((k=p.get(l))==null?void 0:k.rank)??"",y=((x=m.get(l))==null?void 0:x.rank)??"";return g<y?-1:g>y?1:0});w.deselectAll(n);const u=new Map,f=[];for(const p of d){const m=w.createEntity(n),g=p.get(i);g!=null&&g.id&&u.set(g.id,m),w.addComponent(n,m,w.Synced,{id:crypto.randomUUID()});for(const[y,k]of p){if(y===i)continue;const x=s.get(y);if(!x)continue;const b={...k};if(y===l){if(!(k.parentId!=null)){const E=ie.Vec2.clone(b.position);ie.Vec2.add(E,c),b.position=E}b.rank=w.RankBounds.genNext(n)}const S=rS(x.schema);if(S.length>0){for(const C of S)delete b[C];f.push({entityId:m,componentDef:x,componentData:k})}w.addComponent(n,m,x,b)}w.selectBlock(n,m)}for(const{entityId:p,componentDef:m,componentData:g}of f)sS(n,p,m,g,u);const h=[];for(const p of d){const m=p.get(i);if(!(m!=null&&m.id))continue;const g=u.get(m.id);if(!g||!w.hasComponent(n,g,w.Block)||w.Block.read(n,g).parentId!==null)continue;const k=w.Block.getCenter(n,g),x=w.findFrameAtPoint(n,k,g);x!==null&&h.push({entityId:g,frameId:x})}h.length>0&&w.AssignFrameChildren.spawn(n,{assignments:h})}function iS(n,e,t,o){const r=w.Text.default(),s=document.createElement("div");if(s.style.position="absolute",s.style.visibility="hidden",s.style.fontFamily=r.fontFamily,s.style.fontSize=`${r.fontSizePx}px`,s.style.lineHeight=`${r.lineHeight}`,s.style.letterSpacing=`${r.letterSpacingEm}em`,s.style.width="fit-content",s.style.wordBreak="break-word",s.style.minWidth="2px",e){const c=o/t,d=Math.min(Hs,c/2);s.style.maxWidth=`${d}px`,s.style.whiteSpace="pre-wrap"}else s.style.whiteSpace="pre";s.classList.add("wov-editable-text"),s.innerHTML=n,document.body.appendChild(s);const i=s.offsetWidth,l=s.offsetHeight;return document.body.removeChild(s),{width:i,height:l}}function lS(n,e={}){const t=e.enabled??!0,o=e.canPasteTextAsBlock??!0;if(!t)return;const{getEditor:r,nextEditorTick:s}=le(),i=a.inject(we),l=Pn();let c=null;function d(){const m=document.activeElement;return m instanceof HTMLInputElement||m instanceof HTMLTextAreaElement||!!(m!=null&&m.isContentEditable)}a.watch(()=>l.editor.value,m=>{if(!m||!c)return;const{plainText:g,html:y}=c;c=null;const k=new DataTransfer;k.setData("text/plain",g),y&&k.setData("text/html",y);const x=new ClipboardEvent("paste",{clipboardData:k,bubbles:!0,cancelable:!0});m.view.dom.dispatchEvent(x),s(b=>{w.DeselectAll.spawn(b)})});function u(m){if(l.editor.value||!m.clipboardData||d())return!1;const g=r();if(!g)return!1;const y=g._getContext(),k=tS(y);return k?(m.clipboardData.setData(op,JSON.stringify(k)),m.clipboardData.setData("text/plain",`${k.entities.length} block${k.entities.length===1?"":"s"}`),m.preventDefault(),!0):!1}function f(m){u(m)}function h(m){u(m)&&s(g=>{for(const y of rp.current(g))w.isAlive(g,y)&&w.cascadeDelete(g,y)})}async function p(m){var B,I,O,z;if(l.editor.value||d())return;const g=((B=m.clipboardData)==null?void 0:B.getData(op))??"",y=((I=m.clipboardData)==null?void 0:I.getData("text/html"))??"",k=((O=m.clipboardData)==null?void 0:O.getData("text/plain"))??"";if(g){m.preventDefault();const $=await s(),J=nS($,g);if(J){const j=w.Mouse.read($);if(j.position[0]!==0||j.position[1]!==0){const W=w.Camera.read($),X=[W.left+j.position[0]/W.zoom,W.top+j.position[1]/W.zoom];sp($,J.entities,J.center,X)}else sp($,J.entities,J.center)}return}if(!o||!k.trim())return;const x=await s();c={plainText:k,html:y};const b=w.Mouse.read(x),S=w.Camera.read(x),C=[S.left+b.position[0]/S.zoom,S.top+b.position[1]/S.zoom],v=eS(k),E=k.length>ha,M=((z=n.value)==null?void 0:z.clientWidth)??Hs,T=iS(v,E,S.zoom,M),A=rr(x,{block:{tag:"text",size:[T.width,T.height]},text:{constrainWidth:E,fontSizePx:24,...i.getDefaults("text")}},C);w.canBlockEdit(x,"text")&&w.addComponent(x,A,w.EditAfterPlacing,{}),w.SelectBlock.spawn(x,{entityId:A,deselectOthers:!0})}a.onMounted(()=>{const m=n.value;m&&(m.addEventListener("paste",p),m.addEventListener("copy",f),m.addEventListener("cut",h))}),a.onUnmounted(()=>{const m=n.value;m&&(m.removeEventListener("paste",p),m.removeEventListener("copy",f),m.removeEventListener("cut",h))})}function wt(n,e){const t=a.inject(we);if(!t)throw new Error("useComponents must be used within a WovenCanvas component");const o=a.shallowRef(new Map),r=new Map;function s(l){if(r.has(l))return;const c=t.getEditor();if(c){const u=c._getContext();if(w.hasComponent(u,l,e)){const f=new Map(o.value);f.set(l,e.snapshot(u,l)),o.value=f}else{const f=new Map(o.value);f.set(l,null),o.value=f}}const d=t.subscribeComponent(l,e.name,u=>{const f=new Map(o.value);f.set(l,u),o.value=f});r.set(l,d)}function i(l){const c=r.get(l);if(c){c(),r.delete(l);const d=new Map(o.value);d.delete(l),o.value=d}}return a.watch(()=>a.toValue(n),(l,c)=>{const d=new Set(l),u=new Set(c??[]);for(const f of u)d.has(f)||i(f);for(const f of d)u.has(f)||s(f)},{immediate:!0}),a.onUnmounted(()=>{for(const l of r.values())l();r.clear()}),o}function ka(){const n=a.inject(we);if(!n)throw new Error("useImageCreation must be used within a WovenCanvas component");const{nextEditorTick:e}=le();function t(s){return new Promise((i,l)=>{const c=new window.Image;c.onload=()=>{i({width:c.naturalWidth,height:c.naturalHeight}),URL.revokeObjectURL(c.src)},c.onerror=()=>{l(new Error("Failed to load image")),URL.revokeObjectURL(c.src)},c.src=URL.createObjectURL(s)})}async function o(s,i,l,c={}){const{maxSize:d=400}=c,u=await t(s),f=await e(),h=Math.min(1,d/Math.max(u.width,u.height));let p=Math.round(u.width*h),m=Math.round(u.height*h);const g=w.Grid.read(f);g.enabled&&(p=Math.max(g.colWidth,Math.round(p/g.colWidth)*g.colWidth),m=Math.max(g.rowHeight,Math.round(m/g.rowHeight)*g.rowHeight));const y=w.createEntity(f);w.addComponent(f,y,w.Block);const k=w.Block.write(f,y);k.tag="image",k.position[0]=i-p/2,k.position[1]=l-m/2,k.size[0]=p,k.size[1]=m,w.Grid.snapPosition(f,k.position);const x=crypto.randomUUID();w.addComponent(f,y,w.Asset);const b=w.Asset.write(f,y);b.identifier=x,b.uploadState=w.UploadState.Pending,w.addComponent(f,y,w.Image);const S=w.Image.write(f,y);return S.width=u.width,S.height=u.height,S.alt=s.name,w.addComponent(f,y,Ve.Synced,{id:crypto.randomUUID()}),(n==null?void 0:n.getAssetManager())&&r(y,x,s),y}function r(s,i,l){const c=n==null?void 0:n.getAssetManager();c&&c.upload(i,l,{filename:l.name,mimeType:l.type}).catch(d=>{console.error("Asset upload failed:",d)})}return{getImageDimensions:t,createImageBlock:o}}const aS=w.defineQuery(n=>n.with(w.Block,w.Edited,w.Text));function cS(n){const e=typeof window<"u"?window.visualViewport:null;if(!e)return;const t=Pn();let o=null,r=!1;const s=40,i=.2;function l(){return e?window.innerHeight-e.height>window.innerHeight*i:!1}function c(){if(e){if(!l()){if(o&&r){const d=o;o=null,r=!1,n(u=>{const f=w.Camera.write(u);f.left=d.left,f.top=d.top}),t.repositionMenu()}return}n(d=>{const f=aS.current(d)[Symbol.iterator]().next().value;if(!f)return;const h=w.Block.read(d,f),p=w.Camera.read(d);if(!h||!p)return;const m=p.zoom,g=(h.position[1]-p.top)*m,y=(h.position[1]+h.size[1]-p.top)*m,k=e.height,x=e.offsetTop,b=x,S=x+k;if(y+s<=S&&g>=b)return;o||(o={left:p.left,top:p.top});const C=h.position[1]+h.size[1]/2,v=x+k/2,E=C-v/m,M=w.Camera.write(d);M.top=E,r=!0,t.repositionMenu()})}}e.addEventListener("resize",c),a.onUnmounted(()=>{if(e.removeEventListener("resize",c),o&&r){const d=o;o=null,r=!1,n(u=>{const f=w.Camera.write(u);f.left=d.left,f.top=d.top})}})}function ip(n){const e=a.inject(we);if(!e)throw new Error("useQuery must be used within a WovenCanvas component");const t=a.shallowRef([]),o=w.defineQuery(f=>f.with(...n)),r=new Map;let s=!1;function i(f){const h=e.getEditor();if(!h)return{refs:{},unsubscribes:[]};const p=h._getContext(),m={},g=[];for(const y of n){const k=a.shallowRef(y.snapshot(p,f));m[y.name]=k;const x=e.subscribeComponent(f,y.name,b=>{k.value=b});g.push(x)}return{refs:m,unsubscribes:g}}function l(f){const h=r.get(f);if(h){for(const p of h.unsubscribes)p();r.delete(f)}}function c(){const f=[];for(const[h,p]of r)f.push({entityId:h,...p.refs});return f}function d(f){if(!s){const g=o.current(f);for(const y of g)r.set(y,i(y));t.value=c(),s=!0;return}const h=o.added(f),p=o.removed(f);let m=!1;for(const g of p)l(g),m=!0;for(const g of h)r.has(g)||(r.set(g,i(g)),m=!0);m&&(t.value=c())}const u=e.registerTickCallback(d);return a.onUnmounted(()=>{u();for(const f of r.keys())l(f)}),t}function Me(n){const e=a.inject(we);if(!e)throw new Error("useSingleton must be used within a WovenCanvas component");const t=a.shallowRef(n.default()),o=e.getEditor();if(o){const i=o._getContext();t.value=n.snapshot(i)}const r=e.subscribeSingleton(n.name,i=>{t.value=i??{}});let s=null;return o||(s=e.registerTickCallback(()=>{const i=e.getEditor();if(i){const l=i._getContext();t.value=n.snapshot(l),s==null||s(),s=null}})),a.onUnmounted(()=>{r(),s==null||s()}),t}function wa(n,e,t){if(!n.closest(".wov-block")){const m=n.getBoundingClientRect();return{width:m.width,height:m.height,left:0,top:0}}const r=n.getBoundingClientRect(),s=t.value.left,i=t.value.top,l=new DOMPoint(r.left+r.width/2-s,r.top+r.height/2-i),c=e.value.zoom,d=new DOMMatrix;d.translateSelf(-e.value.left*c,-e.value.top*c),d.scaleSelf(c,c),d.invertSelf();const u=d.transformPoint(l),f=getComputedStyle(n),h=parseFloat(f.width)||n.offsetWidth,p=parseFloat(f.height)||n.offsetHeight;return{width:h,height:p,left:u.x-h/2,top:u.y-p/2}}const lp=[fh,ph,mh,ca,zh,yh,kh,wh,Ph.configure({openOnClick:!1}),Lh.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:"left"})];function dS(n){return n.type==="text"&&typeof n.text=="string"}function bt(n,e){if(dS(n)){e(n);return}if(n.content)for(const t of n.content)bt(t,e)}function ba(n,e){if(n.type==="paragraph"){e(n);return}if(n.content)for(const t of n.content)ba(t,e)}function uS(n,e){var t;return((t=n.marks)==null?void 0:t.some(o=>o.type===e))??!1}function fS(n){var o,r;const e=(o=n.marks)==null?void 0:o.find(s=>s.type==="textStyle"),t=((r=e==null?void 0:e.attrs)==null?void 0:r.color)??null;return t?Xh(t):null}function hS(n,e){let t=!1,o=!0,r=0;return bt(n,s=>{r++,uS(s,e)?t=!0:o=!1}),r===0?!1:o?!0:t?null:!1}function pS(n){let e="left";return ba(n,t=>{var r;const o=(r=t.attrs)==null?void 0:r.textAlign;o&&(e=o)}),e}function mS(n){let e=null;return bt(n,t=>{e===null&&(e=fS(t))}),e}function Sa(n,e){bt(n,t=>{const o=t.marks??[];o.findIndex(r=>r.type===e)===-1&&(t.marks=[...o,{type:e}])})}function ir(n,e){bt(n,t=>{t.marks=(t.marks??[]).filter(o=>o.type!==e)})}function gS(n,e){ba(n,t=>{t.attrs={...t.attrs,textAlign:e}})}function ap(n,e,t){bt(n,o=>{const r=o.marks??[],s=r.findIndex(i=>i.type===e);s!==-1?(r[s]={...r[s],attrs:{...r[s].attrs,...t}},o.marks=r):o.marks=[...r,{type:e,attrs:t}]})}function yS(n,e){let t=null;return bt(n,o=>{var r;if(t===null){const s=(r=o.marks)==null?void 0:r.find(i=>i.type===e);s&&(t=s.attrs??{})}}),t}function kS(n){let e=null;return bt(n,t=>{var o,r;if(e===null){const s=(o=t.marks)==null?void 0:o.find(i=>i.type==="link");(r=s==null?void 0:s.attrs)!=null&&r.href&&(e=s.attrs.href)}}),e}function wS(n,e){bt(n,t=>{const o=t.marks??[],r=o.findIndex(s=>s.type==="link");r!==-1?(o[r]={...o[r],attrs:{...o[r].attrs,href:e}},t.marks=o):t.marks=[...o,{type:"link",attrs:{href:e,target:"_blank",rel:"noopener noreferrer"}}]})}function cp(n){const e=document.querySelector(`[data-entity-id="${n}"]`);if(!e)return null;const t=e.firstElementChild;return t||e.querySelector(".wov-editable-text")}function dp(n){const e=w.TransformBoxStateSingleton.read(n);e.transformBoxId!==null&&e.state===w.TransformBoxState.Idle&&w.UpdateTransformBox.spawn(n,{transformBoxId:e.transformBoxId})}function up(n,e,t,o){var c;const r=n.cloneNode(!0);r.style.position="absolute",r.style.visibility="hidden",r.style.pointerEvents="none",r.style.top="0",r.style.left="0";const s=r.classList.contains("wov-editable-text")?r:r.querySelector(".wov-editable-text");s&&(s.style.fontSize=`${o.fontSizePx}px`,s.style.fontFamily=o.fontFamily,s.style.lineHeight=String(o.lineHeight),s.style.letterSpacing=`${o.letterSpacingEm}em`);const i=r.querySelector(".ProseMirror, .tiptap");i?i.innerHTML=o.content:s?s.innerHTML=o.content:r.innerHTML=o.content,(c=n.parentElement)==null||c.appendChild(r);const l=wa(r,e,t);return r.remove(),l}function fp(n){const{nextEditorTick:e}=le(),t=a.inject(we),o=wt(n,w.Text),r=Me(w.Camera),s=Me(w.Screen),i=Pn(),l=a.inject(vi,void 0),c=a.computed(()=>{const b=l==null?void 0:l.value.extensions;return b&&b.length>0?[...lp,...b]:lp}),d=b=>Lw(b,c.value),u=b=>Pw(b,c.value),f=(b,S)=>{if(!b.trim())return b;const C=d(b);return S(C),u(C)},h={hasTextEntities:a.computed(()=>{for(const b of o.value.values())if(b)return!0;return!1}),hasTextContent:a.computed(()=>{for(const b of o.value.values()){if(!b)continue;const S=b.content?d(b.content):null;if(S){let C=!1;if(bt(S,v=>{var E;(E=v.text)!=null&&E.trim()&&(C=!0)}),C)return!0}}return!1}),isBold:a.computed(()=>p("bold")),isItalic:a.computed(()=>p("italic")),isUnderline:a.computed(()=>p("underline")),alignment:a.computed(()=>{let b=null;for(const S of o.value.values()){if(!S)continue;const C=S.content?pS(d(S.content)):"left";if(b===null)b=C;else if(b!==C)return null}return b??"left"}),color:a.computed(()=>{let b=null,S=!1;for(const C of o.value.values()){if(!C)continue;const v=C.content?mS(d(C.content)):null;if(!S)b=v,S=!0;else if(b!==v)return null}return b}),fontSize:a.computed(()=>{let b=null,S=!1;for(const C of o.value.values())if(C){if(!S)b=C.fontSizePx,S=!0;else if(b!==C.fontSizePx)return null}return b}),fontFamily:a.computed(()=>{let b=null,S=!1;for(const C of o.value.values())if(C){if(!S)b=C.fontFamily,S=!0;else if(b!==C.fontFamily)return null}return b}),linkHref:a.computed(()=>{let b=null,S=!1;for(const C of o.value.values()){if(!C)continue;const v=C.content?kS(d(C.content)):null;if(!S)b=v,S=!0;else if(b!==v)return null}return b})};function p(b){let S=null,C=!1;for(const v of o.value.values()){if(!v)continue;const E=v.content?hS(d(v.content),b):!1;if(!C)S=E,C=!0;else if(S!==E)return null}return S}function m(b){let S=null,C=!1;for(const v of o.value.values()){if(!v)continue;const E=v.content?yS(d(v.content),b):null;if(!C)S=E,C=!0;else if(JSON.stringify(S)!==JSON.stringify(E))return null}return S}const g={toggleBold(){k(b=>f(b,S=>h.isBold.value?ir(S,"bold"):Sa(S,"bold")))},toggleItalic(){k(b=>f(b,S=>h.isItalic.value?ir(S,"italic"):Sa(S,"italic")))},toggleUnderline(){k(b=>f(b,S=>h.isUnderline.value?ir(S,"underline"):Sa(S,"underline")))},setAlignment(b){x(S=>f(S,C=>gS(C,b)))},setColor(b){x(S=>f(S,C=>ap(C,"textStyle",{color:b})))},setMark(b,S={}){k(C=>f(C,v=>ap(v,b,S)))},unsetMark(b){k(S=>f(S,C=>ir(C,b)))},setFontSize(b){t.setDefaults("text",{fontSizePx:b}),y(S=>({...S,fontSizePx:b}),S=>{S.fontSizePx=b})},setFontFamily(b){t.setDefaults("text",{fontFamily:b}),y(S=>({...S,fontFamily:b}),S=>{S.fontFamily=b})},setTextStyle(b){const S={};b.fontFamily!==void 0&&(S.fontFamily=b.fontFamily),b.fontSizePx!==void 0&&(S.fontSizePx=b.fontSizePx),b.lineHeight!==void 0&&(S.lineHeight=b.lineHeight),b.letterSpacingEm!==void 0&&(S.letterSpacingEm=b.letterSpacingEm),Object.keys(S).length>0&&t.setDefaults("text",S),y(C=>({...C,fontFamily:b.fontFamily??C.fontFamily,fontSizePx:b.fontSizePx??C.fontSizePx,lineHeight:b.lineHeight??C.lineHeight,letterSpacingEm:b.letterSpacingEm??C.letterSpacingEm}),C=>{b.fontFamily!==void 0&&(C.fontFamily=b.fontFamily),b.fontSizePx!==void 0&&(C.fontSizePx=b.fontSizePx),b.lineHeight!==void 0&&(C.lineHeight=b.lineHeight),b.letterSpacingEm!==void 0&&(C.letterSpacingEm=b.letterSpacingEm)})},setLink(b){x(S=>f(S,C=>wS(C,b)))},removeLink(){x(b=>f(b,S=>ir(S,"link")))}};function y(b,S){const C=a.toValue(n),v=[];for(const E of C){const M=o.value.get(E);if(!M)continue;const T=cp(E);if(T){const A=up(T,r,s,b(M));v.push({entityId:E,...A})}}e(E=>{for(const M of C)S(w.Text.write(E,M));for(const{entityId:M,width:T,height:A,left:B,top:I}of v){const O=w.Block.write(E,M);O.size=[T,A],w.Block.setWorldPosition(E,M,[B,I])}dp(E),a.nextTick(()=>{var M;i.updateCounter.value++,(M=i.editor.value)==null||M.commands.focus()})})}function k(b){const S=a.toValue(n),C=[];for(const v of S){const E=o.value.get(v);if(!E)continue;const M=b(E.content),T=cp(v);if(T){const A=up(T,r,s,{...E,content:M});C.push({entityId:v,content:M,...A})}else C.push({entityId:v,content:M,width:0,height:0,left:0,top:0})}e(v=>{for(const{entityId:E,content:M,width:T,height:A,left:B,top:I}of C){const O=w.Text.write(v,E);if(O.content=M,T>0&&A>0){const z=w.Block.write(v,E);z.size=[T,A],w.Block.setWorldPosition(v,E,[B,I])}}dp(v)})}function x(b){const S=a.toValue(n);e(C=>{for(const v of S){const E=w.Text.write(C,v);E.content=b(E.content)}})}return{state:h,commands:g,getMarkAttrs:m}}function lt(n){const e=Pn(),t=fp(n),o=e.state.hasEditor,r=a.reactive({hasTextToFormat:a.computed(()=>o.value||t.state.hasTextEntities.value),hasEditor:o,hasTextContent:a.computed(()=>t.state.hasTextContent.value),showTextMenuButtons:a.computed(()=>o.value||t.state.hasTextContent.value),isBold:a.computed(()=>o.value?e.state.isBold.value:t.state.isBold.value===!0),isItalic:a.computed(()=>o.value?e.state.isItalic.value:t.state.isItalic.value===!0),isUnderline:a.computed(()=>o.value?e.state.isUnderline.value:t.state.isUnderline.value===!0),alignment:a.computed(()=>o.value?e.state.alignment.value:t.state.alignment.value??"left"),color:a.computed(()=>o.value?e.state.color.value:t.state.color.value),fontSize:a.computed(()=>t.state.fontSize.value),fontFamily:a.computed(()=>t.state.fontFamily.value),linkHref:a.computed(()=>o.value?e.state.linkHref.value:t.state.linkHref.value)}),s={toggleBold(){o.value?e.commands.toggleBold():t.commands.toggleBold()},toggleItalic(){o.value?e.commands.toggleItalic():t.commands.toggleItalic()},toggleUnderline(){o.value?e.commands.toggleUnderline():t.commands.toggleUnderline()},setAlignment(l){o.value?e.commands.setAlignment(l):t.commands.setAlignment(l)},setColor(l){o.value?e.commands.setColor(l):t.commands.setColor(l)},setMark(l,c){o.value?e.commands.setMark(l,c):t.commands.setMark(l,c)},unsetMark(l){o.value?e.commands.unsetMark(l):t.commands.unsetMark(l)},setFontSize(l){t.commands.setFontSize(l)},setFontFamily(l){t.commands.setFontFamily(l)},setTextStyle(l){t.commands.setTextStyle(l)},setLink(l){o.value?e.commands.setLink(l):t.commands.setLink(l)},removeLink(){o.value?e.commands.removeLink():t.commands.removeLink()}};function i(l){return o.value?e.getMarkAttrs(l):t.getMarkAttrs(l)}return{state:r,commands:s,getMarkAttrs:i}}function xa(n){const e=Me(w.Camera),t=Me(w.Screen),o=Me(w.TransformBoxStateSingleton),r=Me(w.SelectionStateSingleton),{nextEditorTick:s}=le();let i=!1,l=null;function c(u,f){const{entityId:h}=a.toValue(n.blockData),p=a.toValue(n.minWidth)??0,m=a.toValue(n.minHeight)??0,g=Math.max(f.width,p),y=Math.max(f.height,m),k=w.Block.read(u,h),x=Math.abs(k.size[0]-g)>.5,b=Math.abs(k.size[1]-y)>.5;if(!x&&!b)return;const S=w.Block.write(u,h);S.size=[g,y],w.Block.setWorldPosition(u,h,[f.left,f.top]),o.value.transformBoxId!==null&&w.UpdateTransformBox.spawn(u,{transformBoxId:o.value.transformBoxId})}a.watch(()=>r.value,()=>{s(u=>{const f=bS(u);if(i&&!f){const h=n.containerRef.value;if(!h)return;l=wa(h,e,t),c(u,l),l=null}i=f})},{flush:"sync"});function d(u){const{content:f,...h}=u;s(p=>{const{entityId:m}=a.toValue(n.blockData);if(w.Text.read(p,m).content!==f){const y=w.Text.write(p,m);y.content=f}c(p,h)})}return{handleEditEnd:d}}function bS(n){const e=w.SelectionStateSingleton.read(n);return e.state===w.SelectionState.Dragging&&e.draggedEntity!==null&&w.hasComponent(n,e.draggedEntity,w.TransformHandle)&&w.TransformHandle.read(n,e.draggedEntity).kind===w.TransformHandleKind.Stretch}function js(){const n=a.inject(Mi);if(!n)throw new Error("useToolbar must be used within a Toolbar component");return{activeTool:n.activeTool,heldTool:n.heldTool,setTool:n.setTool,dragOutTool:n.dragOutTool,onToolPointerDown:n.onToolPointerDown,onToolPointerUp:n.onToolPointerUp,isActive:e=>a.computed(()=>n.activeTool.value===e)}}const SS=500,xS=1500,Us=a.ref(null),lr=a.ref(!1),ao=a.ref(!1);let ar=null,cr=null,dr=null;function Ca(){ar&&(clearTimeout(ar),ar=null),cr&&(clearTimeout(cr),cr=null)}function Ea(){dr&&(dr.disconnect(),dr=null)}function CS(n){Ea(),!(typeof MutationObserver>"u"||typeof document>"u")&&(dr=new MutationObserver(()=>{n.isConnected||hp()}),dr.observe(document.body,{childList:!0,subtree:!0}))}function ES(n,e,t){Ca(),Us.value={text:n,anchor:e,placement:t},CS(e),ao.value?lr.value=!0:ar=setTimeout(()=>{lr.value=!0,ao.value=!0,ar=null},SS)}function vS(){Ca(),Ea(),lr.value=!1,Us.value=null,ao.value&&(cr=setTimeout(()=>{ao.value=!1,cr=null},xS))}function hp(){Ca(),Ea(),lr.value=!1,Us.value=null,ao.value=!1}const MS={activeTooltip:a.readonly(Us),isVisible:a.readonly(lr),isWarmedUp:a.readonly(ao),show:ES,hide:vS,reset:hp},Ws=a.ref([]);function zt(){return MS}const TS={key:1},NS=["innerHTML"],Ks=a.defineComponent({__name:"EditableText",props:{blockElement:{},entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},emits:["editEnd"],setup(n,{expose:e,emit:t}){var T;const o=n,r=t,s=fe(o.entityId,w.Text),i=Me(w.Camera),l=Me(w.Screen),c=Pn(),{nextEditorTick:d,getEditor:u}=le(),f=Me(w.Mouse),h=a.inject(vi,void 0),p=a.ref(null);e({editableTextRef:p});const m=a.ref(((T=s.value)==null?void 0:T.content)??""),g=a.shallowRef(null);a.watch(()=>{var A;return(A=s.value)==null?void 0:A.fontFamily},A=>{var B;A&&((B=u())==null||B.loadFont(A))},{immediate:!0});async function y(){var j,K;p.value&&(p.value.style.opacity="0");const A=await d(),B=w.Block.read(A,o.entityId),I=(((j=l.value)==null?void 0:j.width)??Hs)/(((K=i.value)==null?void 0:K.zoom)??1),O=Math.min(Hs,I/2),z=Math.max(B.size[0],O),$=w.Block.write(A,o.entityId);$.size=[z,B.size[1]];const J=w.Text.write(A,o.entityId);J.constrainWidth=!0,w.ResetKeyboard.spawn(A),requestAnimationFrame(()=>{p.value&&(p.value.style.opacity=""),requestAnimationFrame(()=>{c.updateCounter.value++})})}function k(A,B){var J,j,K;const I=s.value;if(!I)return!1;const O=((J=B.clipboardData)==null?void 0:J.getData("text/html"))??"",z=((j=B.clipboardData)==null?void 0:j.getData("text/plain"))??"";if(!/<[^>]+data-pm-slice=/.test(O)){B.preventDefault();const W=z.trimEnd().split(/\r?\n/).map(X=>({type:"paragraph",content:X?[{type:"text",text:X}]:[]}));return(K=g.value)==null||K.commands.insertContent(W),!I.constrainWidth&&z.length>ha&&y(),!0}return!I.constrainWidth&&z.length>ha&&y(),!1}function x(){var O,z,$;const A=((O=u())==null?void 0:O.readonly)===!0,B=(h==null?void 0:h.value.links)!==!1,I=(h==null?void 0:h.value.underline)!==!1;return new $b({extensions:[fh,ph,mh,ca,zh,yh,kh,...I?[wh]:[],Ph.configure({openOnClick:!1,autolink:B,linkOnPaste:B,HTMLAttributes:{rel:"noopener noreferrer",target:"_blank"}}),Lh.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:((z=s.value)==null?void 0:z.defaultAlignment)??"left"}),...(h==null?void 0:h.value.extensions)??[],Z2],content:(($=s.value)==null?void 0:$.content)??"",editable:!A,parseOptions:{preserveWhitespace:!0},editorProps:{handlePaste:k}})}a.watch(()=>o.edited,async A=>{if(A){if(p.value||await a.nextTick(),!p.value||(g.value=x(),await b(g.value),!o.blockElement))return;c.register(g.value,p.value,o.blockElement)}else g.value&&(c.unregister(),S(g.value),g.value.destroy(),g.value=null)},{immediate:!0});async function b(A){var z;const B=(z=f.value)==null?void 0:z.position,I=l.value;await a.nextTick(),await new Promise($=>requestAnimationFrame($));const O=p.value;if(B&&I&&O){const $=B[0]+I.left,J=B[1]+I.top,j=A.view.posAtCoords({left:$,top:J});if(j){A.chain().focus().setTextSelection(j.pos).run();return}}A.commands.focus("start")}function S(A){let B=A.getHTML();const O=B.replace(/<[^>]*>/g,"").trim().length>0;O||(B=""),m.value=B,d(z=>{var W,X;const $=w.getBlockDef(z,o.block.tag);if(!O&&((W=$.editOptions)!=null&&W.removeWhenTextEmpty)){w.removeEntity(z,o.entityId);return}const J=(X=p.value)==null?void 0:X.closest(".wov-block"),j=(J==null?void 0:J.firstElementChild)??p.value;if(!j){console.warn("EditableText: no element to measure");return}const K=wa(j,i,l);r("editEnd",{content:B,...K})})}a.watch(()=>{var A;return(A=s.value)==null?void 0:A.content},A=>{A!==void 0&&(g.value?g.value.getHTML()!==A&&g.value.commands.setContent(A,{emitUpdate:!1}):m.value=A)});const C=a.computed(()=>{const A=s.value;if(!A)return{};const[B,I]=o.block.flip,O=B?-1:1,z=I?-1:1,$=B||I;return{fontFamily:A.fontFamily,fontSize:`${A.fontSizePx}px`,lineHeight:A.lineHeight,letterSpacing:`${A.letterSpacingEm}em`,width:A.constrainWidth?"100%":"fit-content",whiteSpace:A.constrainWidth?"pre-wrap":"pre",minWidth:"2px",wordBreak:"break-word",pointerEvents:o.edited?"auto":"none",userSelect:o.edited?"auto":"none",transform:$?`scale(${O}, ${z})`:void 0}});function v(A){A.key==="Control"||A.key==="Meta"||A.stopPropagation()}function E(A){o.edited&&A.stopPropagation()}function M(A){if(o.edited)return;const B=A.target.closest("a");if(!B)return;const I=B.getAttribute("href");I&&(A.preventDefault(),A.stopPropagation(),window.open(I,"_blank","noopener,noreferrer"))}return a.onUnmounted(()=>{g.value&&(c.unregister(),g.value.destroy(),g.value=null)}),(A,B)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"editableTextRef",ref:p,class:"wov-editable-text",style:a.normalizeStyle(C.value),onKeydown:v,onPointerdown:E,onPointermove:E,onPointerup:E,onClick:M},[g.value?(a.openBlock(),a.createBlock(a.unref(zb),{key:0,editor:g.value},null,8,["editor"])):(a.openBlock(),a.createElementBlock("div",TS,[a.createElementVNode("div",{class:"tiptap ProseMirror",innerHTML:m.value},null,8,NS)]))],36))}}),AS={class:"wov-shape-svg",viewBox:"0 0 100 100",preserveAspectRatio:"none"},BS=["d","fill","stroke","stroke-width","stroke-dasharray"],pp=a.defineComponent({__name:"ShapeBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=fe(e.entityId,w.Shape),o=fe(e.entityId,w.VerticalAlign),r=a.ref(null),s={[w.VerticalAlignment.Top]:"flex-start",[w.VerticalAlignment.Center]:"center",[w.VerticalAlignment.Bottom]:"flex-end"},i=a.computed(()=>t.value?`rgba(${t.value.fillRed}, ${t.value.fillGreen}, ${t.value.fillBlue}, ${(t.value.fillAlpha??255)/255})`:"rgba(0, 0, 0, 0)"),l=a.computed(()=>t.value?t.value.strokeKind===w.StrokeKind.None?"none":`rgba(${t.value.strokeRed}, ${t.value.strokeGreen}, ${t.value.strokeBlue}, ${t.value.strokeAlpha/255})`:"rgba(0, 0, 0, 1)"),c=a.computed(()=>{var g;return((g=t.value)==null?void 0:g.strokeWidth)??2}),d=a.computed(()=>{var g;return((g=t.value)==null?void 0:g.strokeKind)??w.StrokeKind.Solid}),u=a.computed(()=>{var g;return Co[((g=t.value)==null?void 0:g.kind)??"rectangle"]??Co.rectangle}),f=a.computed(()=>{const g=c.value;switch(d.value){case w.StrokeKind.Dashed:return`${g*3} ${g*3}`;case w.StrokeKind.None:return"";default:return""}}),h=a.computed(()=>{var g;return{overflow:e.edited?"visible":"hidden",alignItems:s[((g=o.value)==null?void 0:g.value)??w.VerticalAlignment.Top]}}),{nextEditorTick:p}=le();function m(g){p(y=>{if(w.Text.read(y,e.entityId).content===g.content)return;const x=w.Text.write(y,e.entityId);x.content=g.content})}return(g,y)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:r,class:"wov-shape-block"},[(a.openBlock(),a.createElementBlock("svg",AS,[a.createElementVNode("path",{d:u.value,fill:i.value,stroke:l.value,"stroke-width":c.value,"stroke-dasharray":f.value,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":"non-scaling-stroke"},null,8,BS)])),a.createElementVNode("div",{class:"wov-shape-content",style:a.normalizeStyle(h.value)},[a.createVNode(Ks,a.mergeProps(e,{"block-element":r.value,onEditEnd:m}),null,16,["block-element"])],4)],512))}}),IS={class:"wov-tape-block"},OS={key:0,class:"wov-tape-placeholder"},mp=a.defineComponent({__name:"TapeBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},async setup(n){let e,t;const o=n,r=a.inject(we);if(!r)throw new Error("TapeBlock must be used within a WovenCanvas component");const s=r,i=fe(o.entityId,w.Asset),l=fe(o.entityId,w.Image);function c(){var C,v;const x=((C=l.value)==null?void 0:C.width)??0,b=((v=l.value)==null?void 0:v.height)??0,S=xr(o.block.size[1],b);return x<=0||b<=0?{width:xr(o.block.size[0]),height:S}:{width:Math.ceil(S*(x/b)),height:S}}const d=s.getAssetManager(),u=i.value;let f=null;d&&(u!=null&&u.identifier)&&(f=([e,t]=a.withAsyncContext(()=>d.getDisplayUrl(u.identifier,c())),e=await e,t(),e));let h=c().height;const p=a.ref(f),m=a.ref(!f),g=a.ref(!1);let y=!0;a.onUnmounted(()=>{y=!1});async function k(){const x=s.getAssetManager();if(!x)return;const b=i.value;if(!b||!b.identifier){m.value=!1;return}try{m.value=!0,g.value=!1;const S=c();h=S.height;const C=await x.getDisplayUrl(b.identifier,S);if(!y)return;C?(p.value=C,m.value=!1):b.uploadState===w.UploadState.Failed&&(g.value=!0,m.value=!1)}catch(S){if(!y)return;console.error("Failed to get tape display URL:",S),g.value=!0,m.value=!1}}return a.watch(()=>i.value,()=>{k()},{immediate:!0}),a.onMounted(()=>{k()}),a.watch(()=>o.block.size[1],()=>{c().height>h&&k()}),(x,b)=>(a.openBlock(),a.createElementBlock("div",IS,[m.value&&!p.value?(a.openBlock(),a.createElementBlock("div",OS)):p.value?(a.openBlock(),a.createElementBlock("div",{key:1,class:"wov-tape-image",style:a.normalizeStyle({backgroundImage:`url(${p.value})`})},null,4)):a.createCommentVNode("",!0)]))}}),_S=["data-text-empty"],gp=a.defineComponent({__name:"TextBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=a.ref(null),o=fe(e.entityId,w.Text),r=a.computed(()=>{var d;return(((d=o.value)==null?void 0:d.content)??"").replace(/<[^>]*>/g,"").trim().length===0}),s=a.computed(()=>{var l;return((l=o.value)==null?void 0:l.constrainWidth)??!1}),{handleEditEnd:i}=xa({blockData:e,containerRef:t});return(l,c)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-text-block","data-text-empty":r.value||void 0,style:a.normalizeStyle({width:s.value?"100%":"fit-content"})},[a.createVNode(Ks,a.mergeProps(e,{"block-element":t.value,onEditEnd:a.unref(i)}),null,16,["block-element","onEditEnd"])],12,_S))}}),DS={class:"wov-transform-box"},yp=a.defineComponent({__name:"TransformBox",setup(n){return(e,t)=>(a.openBlock(),a.createElementBlock("div",DS))}}),RS={},PS={class:"wov-transform-handle"};function LS(n,e){return a.openBlock(),a.createElementBlock("div",PS)}const kp=kn(RS,[["render",LS]]),qs=Math.min,Ln=Math.max,Js=Math.round,Gs=Math.floor,St=n=>({x:n,y:n}),VS={left:"right",right:"left",bottom:"top",top:"bottom"},$S={start:"end",end:"start"};function wp(n,e,t){return Ln(n,qs(e,t))}function Ys(n,e){return typeof n=="function"?n(e):n}function Vn(n){return n.split("-")[0]}function Xs(n){return n.split("-")[1]}function bp(n){return n==="x"?"y":"x"}function Sp(n){return n==="y"?"height":"width"}const zS=new Set(["top","bottom"]);function cn(n){return zS.has(Vn(n))?"y":"x"}function xp(n){return bp(cn(n))}function FS(n,e,t){t===void 0&&(t=!1);const o=Xs(n),r=xp(n),s=Sp(r);let i=r==="x"?o===(t?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=Qs(i)),[i,Qs(i)]}function HS(n){const e=Qs(n);return[va(n),e,va(e)]}function va(n){return n.replace(/start|end/g,e=>$S[e])}const Cp=["left","right"],Ep=["right","left"],jS=["top","bottom"],US=["bottom","top"];function WS(n,e,t){switch(n){case"top":case"bottom":return t?e?Ep:Cp:e?Cp:Ep;case"left":case"right":return e?jS:US;default:return[]}}function KS(n,e,t,o){const r=Xs(n);let s=WS(Vn(n),t==="start",o);return r&&(s=s.map(i=>i+"-"+r),e&&(s=s.concat(s.map(va)))),s}function Qs(n){return n.replace(/left|right|bottom|top/g,e=>VS[e])}function qS(n){return{top:0,right:0,bottom:0,left:0,...n}}function JS(n){return typeof n!="number"?qS(n):{top:n,right:n,bottom:n,left:n}}function Zs(n){const{x:e,y:t,width:o,height:r}=n;return{width:o,height:r,top:t,left:e,right:e+o,bottom:t+r,x:e,y:t}}function vp(n,e,t){let{reference:o,floating:r}=n;const s=cn(e),i=xp(e),l=Sp(i),c=Vn(e),d=s==="y",u=o.x+o.width/2-r.width/2,f=o.y+o.height/2-r.height/2,h=o[l]/2-r[l]/2;let p;switch(c){case"top":p={x:u,y:o.y-r.height};break;case"bottom":p={x:u,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:f};break;case"left":p={x:o.x-r.width,y:f};break;default:p={x:o.x,y:o.y}}switch(Xs(e)){case"start":p[i]-=h*(t&&d?-1:1);break;case"end":p[i]+=h*(t&&d?-1:1);break}return p}async function GS(n,e){var t;e===void 0&&(e={});const{x:o,y:r,platform:s,rects:i,elements:l,strategy:c}=n,{boundary:d="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:h=!1,padding:p=0}=Ys(e,n),m=JS(p),y=l[h?f==="floating"?"reference":"floating":f],k=Zs(await s.getClippingRect({element:(t=await(s.isElement==null?void 0:s.isElement(y)))==null||t?y:y.contextElement||await(s.getDocumentElement==null?void 0:s.getDocumentElement(l.floating)),boundary:d,rootBoundary:u,strategy:c})),x=f==="floating"?{x:o,y:r,width:i.floating.width,height:i.floating.height}:i.reference,b=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),S=await(s.isElement==null?void 0:s.isElement(b))?await(s.getScale==null?void 0:s.getScale(b))||{x:1,y:1}:{x:1,y:1},C=Zs(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:x,offsetParent:b,strategy:c}):x);return{top:(k.top-C.top+m.top)/S.y,bottom:(C.bottom-k.bottom+m.bottom)/S.y,left:(k.left-C.left+m.left)/S.x,right:(C.right-k.right+m.right)/S.x}}const YS=async(n,e,t)=>{const{placement:o="bottom",strategy:r="absolute",middleware:s=[],platform:i}=t,l=s.filter(Boolean),c=await(i.isRTL==null?void 0:i.isRTL(e));let d=await i.getElementRects({reference:n,floating:e,strategy:r}),{x:u,y:f}=vp(d,o,c),h=o,p={},m=0;for(let y=0;y<l.length;y++){var g;const{name:k,fn:x}=l[y],{x:b,y:S,data:C,reset:v}=await x({x:u,y:f,initialPlacement:o,placement:h,strategy:r,middlewareData:p,rects:d,platform:{...i,detectOverflow:(g=i.detectOverflow)!=null?g:GS},elements:{reference:n,floating:e}});u=b??u,f=S??f,p={...p,[k]:{...p[k],...C}},v&&m<=50&&(m++,typeof v=="object"&&(v.placement&&(h=v.placement),v.rects&&(d=v.rects===!0?await i.getElementRects({reference:n,floating:e,strategy:r}):v.rects),{x:u,y:f}=vp(d,h,c)),y=-1)}return{x:u,y:f,placement:h,strategy:r,middlewareData:p}},XS=function(n){return n===void 0&&(n={}),{name:"flip",options:n,async fn(e){var t,o;const{placement:r,middlewareData:s,rects:i,initialPlacement:l,platform:c,elements:d}=e,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:h,fallbackStrategy:p="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...y}=Ys(n,e);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const k=Vn(r),x=cn(l),b=Vn(l)===l,S=await(c.isRTL==null?void 0:c.isRTL(d.floating)),C=h||(b||!g?[Qs(l)]:HS(l)),v=m!=="none";!h&&v&&C.push(...KS(l,g,m,S));const E=[l,...C],M=await c.detectOverflow(e,y),T=[];let A=((o=s.flip)==null?void 0:o.overflows)||[];if(u&&T.push(M[k]),f){const z=FS(r,i,S);T.push(M[z[0]],M[z[1]])}if(A=[...A,{placement:r,overflows:T}],!T.every(z=>z<=0)){var B,I;const z=(((B=s.flip)==null?void 0:B.index)||0)+1,$=E[z];if($&&(!(f==="alignment"?x!==cn($):!1)||A.every(K=>cn(K.placement)===x?K.overflows[0]>0:!0)))return{data:{index:z,overflows:A},reset:{placement:$}};let J=(I=A.filter(j=>j.overflows[0]<=0).sort((j,K)=>j.overflows[1]-K.overflows[1])[0])==null?void 0:I.placement;if(!J)switch(p){case"bestFit":{var O;const j=(O=A.filter(K=>{if(v){const W=cn(K.placement);return W===x||W==="y"}return!0}).map(K=>[K.placement,K.overflows.filter(W=>W>0).reduce((W,X)=>W+X,0)]).sort((K,W)=>K[1]-W[1])[0])==null?void 0:O[0];j&&(J=j);break}case"initialPlacement":J=l;break}if(r!==J)return{reset:{placement:J}}}return{}}}},QS=new Set(["left","top"]);async function ZS(n,e){const{placement:t,platform:o,elements:r}=n,s=await(o.isRTL==null?void 0:o.isRTL(r.floating)),i=Vn(t),l=Xs(t),c=cn(t)==="y",d=QS.has(i)?-1:1,u=s&&c?-1:1,f=Ys(e,n);let{mainAxis:h,crossAxis:p,alignmentAxis:m}=typeof f=="number"?{mainAxis:f,crossAxis:0,alignmentAxis:null}:{mainAxis:f.mainAxis||0,crossAxis:f.crossAxis||0,alignmentAxis:f.alignmentAxis};return l&&typeof m=="number"&&(p=l==="end"?m*-1:m),c?{x:p*u,y:h*d}:{x:h*d,y:p*u}}const ex=function(n){return n===void 0&&(n=0),{name:"offset",options:n,async fn(e){var t,o;const{x:r,y:s,placement:i,middlewareData:l}=e,c=await ZS(e,n);return i===((t=l.offset)==null?void 0:t.placement)&&(o=l.arrow)!=null&&o.alignmentOffset?{}:{x:r+c.x,y:s+c.y,data:{...c,placement:i}}}}},tx=function(n){return n===void 0&&(n={}),{name:"shift",options:n,async fn(e){const{x:t,y:o,placement:r,platform:s}=e,{mainAxis:i=!0,crossAxis:l=!1,limiter:c={fn:k=>{let{x,y:b}=k;return{x,y:b}}},...d}=Ys(n,e),u={x:t,y:o},f=await s.detectOverflow(e,d),h=cn(Vn(r)),p=bp(h);let m=u[p],g=u[h];if(i){const k=p==="y"?"top":"left",x=p==="y"?"bottom":"right",b=m+f[k],S=m-f[x];m=wp(b,m,S)}if(l){const k=h==="y"?"top":"left",x=h==="y"?"bottom":"right",b=g+f[k],S=g-f[x];g=wp(b,g,S)}const y=c.fn({...e,[p]:m,[h]:g});return{...y,data:{x:y.x-t,y:y.y-o,enabled:{[p]:i,[h]:l}}}}}};function ei(){return typeof window<"u"}function $n(n){return Ma(n)?(n.nodeName||"").toLowerCase():"#document"}function Je(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function xt(n){var e;return(e=(Ma(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function Ma(n){return ei()?n instanceof Node||n instanceof Je(n).Node:!1}function at(n){return ei()?n instanceof Element||n instanceof Je(n).Element:!1}function Ct(n){return ei()?n instanceof HTMLElement||n instanceof Je(n).HTMLElement:!1}function Mp(n){return!ei()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof Je(n).ShadowRoot}const nx=new Set(["inline","contents"]);function ur(n){const{overflow:e,overflowX:t,overflowY:o,display:r}=ct(n);return/auto|scroll|overlay|hidden|clip/.test(e+o+t)&&!nx.has(r)}const ox=new Set(["table","td","th"]);function rx(n){return ox.has($n(n))}const sx=[":popover-open",":modal"];function ti(n){return sx.some(e=>{try{return n.matches(e)}catch{return!1}})}const ix=["transform","translate","scale","rotate","perspective"],lx=["transform","translate","scale","rotate","perspective","filter"],ax=["paint","layout","strict","content"];function Ta(n){const e=Na(),t=at(n)?ct(n):n;return ix.some(o=>t[o]?t[o]!=="none":!1)||(t.containerType?t.containerType!=="normal":!1)||!e&&(t.backdropFilter?t.backdropFilter!=="none":!1)||!e&&(t.filter?t.filter!=="none":!1)||lx.some(o=>(t.willChange||"").includes(o))||ax.some(o=>(t.contain||"").includes(o))}function cx(n){let e=dn(n);for(;Ct(e)&&!co(e);){if(Ta(e))return e;if(ti(e))return null;e=dn(e)}return null}function Na(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const dx=new Set(["html","body","#document"]);function co(n){return dx.has($n(n))}function ct(n){return Je(n).getComputedStyle(n)}function ni(n){return at(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function dn(n){if($n(n)==="html")return n;const e=n.assignedSlot||n.parentNode||Mp(n)&&n.host||xt(n);return Mp(e)?e.host:e}function Tp(n){const e=dn(n);return co(e)?n.ownerDocument?n.ownerDocument.body:n.body:Ct(e)&&ur(e)?e:Tp(e)}function fr(n,e,t){var o;e===void 0&&(e=[]),t===void 0&&(t=!0);const r=Tp(n),s=r===((o=n.ownerDocument)==null?void 0:o.body),i=Je(r);if(s){const l=Aa(i);return e.concat(i,i.visualViewport||[],ur(r)?r:[],l&&t?fr(l):[])}return e.concat(r,fr(r,[],t))}function Aa(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function Np(n){const e=ct(n);let t=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=Ct(n),s=r?n.offsetWidth:t,i=r?n.offsetHeight:o,l=Js(t)!==s||Js(o)!==i;return l&&(t=s,o=i),{width:t,height:o,$:l}}function Ba(n){return at(n)?n:n.contextElement}function uo(n){const e=Ba(n);if(!Ct(e))return St(1);const t=e.getBoundingClientRect(),{width:o,height:r,$:s}=Np(e);let i=(s?Js(t.width):t.width)/o,l=(s?Js(t.height):t.height)/r;return(!i||!Number.isFinite(i))&&(i=1),(!l||!Number.isFinite(l))&&(l=1),{x:i,y:l}}const ux=St(0);function Ap(n){const e=Je(n);return!Na()||!e.visualViewport?ux:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function fx(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==Je(n)?!1:e}function zn(n,e,t,o){e===void 0&&(e=!1),t===void 0&&(t=!1);const r=n.getBoundingClientRect(),s=Ba(n);let i=St(1);e&&(o?at(o)&&(i=uo(o)):i=uo(n));const l=fx(s,t,o)?Ap(s):St(0);let c=(r.left+l.x)/i.x,d=(r.top+l.y)/i.y,u=r.width/i.x,f=r.height/i.y;if(s){const h=Je(s),p=o&&at(o)?Je(o):o;let m=h,g=Aa(m);for(;g&&o&&p!==m;){const y=uo(g),k=g.getBoundingClientRect(),x=ct(g),b=k.left+(g.clientLeft+parseFloat(x.paddingLeft))*y.x,S=k.top+(g.clientTop+parseFloat(x.paddingTop))*y.y;c*=y.x,d*=y.y,u*=y.x,f*=y.y,c+=b,d+=S,m=Je(g),g=Aa(m)}}return Zs({width:u,height:f,x:c,y:d})}function oi(n,e){const t=ni(n).scrollLeft;return e?e.left+t:zn(xt(n)).left+t}function Bp(n,e){const t=n.getBoundingClientRect(),o=t.left+e.scrollLeft-oi(n,t),r=t.top+e.scrollTop;return{x:o,y:r}}function hx(n){let{elements:e,rect:t,offsetParent:o,strategy:r}=n;const s=r==="fixed",i=xt(o),l=e?ti(e.floating):!1;if(o===i||l&&s)return t;let c={scrollLeft:0,scrollTop:0},d=St(1);const u=St(0),f=Ct(o);if((f||!f&&!s)&&(($n(o)!=="body"||ur(i))&&(c=ni(o)),Ct(o))){const p=zn(o);d=uo(o),u.x=p.x+o.clientLeft,u.y=p.y+o.clientTop}const h=i&&!f&&!s?Bp(i,c):St(0);return{width:t.width*d.x,height:t.height*d.y,x:t.x*d.x-c.scrollLeft*d.x+u.x+h.x,y:t.y*d.y-c.scrollTop*d.y+u.y+h.y}}function px(n){return Array.from(n.getClientRects())}function mx(n){const e=xt(n),t=ni(n),o=n.ownerDocument.body,r=Ln(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),s=Ln(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let i=-t.scrollLeft+oi(n);const l=-t.scrollTop;return ct(o).direction==="rtl"&&(i+=Ln(e.clientWidth,o.clientWidth)-r),{width:r,height:s,x:i,y:l}}const Ip=25;function gx(n,e){const t=Je(n),o=xt(n),r=t.visualViewport;let s=o.clientWidth,i=o.clientHeight,l=0,c=0;if(r){s=r.width,i=r.height;const u=Na();(!u||u&&e==="fixed")&&(l=r.offsetLeft,c=r.offsetTop)}const d=oi(o);if(d<=0){const u=o.ownerDocument,f=u.body,h=getComputedStyle(f),p=u.compatMode==="CSS1Compat"&&parseFloat(h.marginLeft)+parseFloat(h.marginRight)||0,m=Math.abs(o.clientWidth-f.clientWidth-p);m<=Ip&&(s-=m)}else d<=Ip&&(s+=d);return{width:s,height:i,x:l,y:c}}const yx=new Set(["absolute","fixed"]);function kx(n,e){const t=zn(n,!0,e==="fixed"),o=t.top+n.clientTop,r=t.left+n.clientLeft,s=Ct(n)?uo(n):St(1),i=n.clientWidth*s.x,l=n.clientHeight*s.y,c=r*s.x,d=o*s.y;return{width:i,height:l,x:c,y:d}}function Op(n,e,t){let o;if(e==="viewport")o=gx(n,t);else if(e==="document")o=mx(xt(n));else if(at(e))o=kx(e,t);else{const r=Ap(n);o={x:e.x-r.x,y:e.y-r.y,width:e.width,height:e.height}}return Zs(o)}function _p(n,e){const t=dn(n);return t===e||!at(t)||co(t)?!1:ct(t).position==="fixed"||_p(t,e)}function wx(n,e){const t=e.get(n);if(t)return t;let o=fr(n,[],!1).filter(l=>at(l)&&$n(l)!=="body"),r=null;const s=ct(n).position==="fixed";let i=s?dn(n):n;for(;at(i)&&!co(i);){const l=ct(i),c=Ta(i);!c&&l.position==="fixed"&&(r=null),(s?!c&&!r:!c&&l.position==="static"&&!!r&&yx.has(r.position)||ur(i)&&!c&&_p(n,i))?o=o.filter(u=>u!==i):r=l,i=dn(i)}return e.set(n,o),o}function bx(n){let{element:e,boundary:t,rootBoundary:o,strategy:r}=n;const i=[...t==="clippingAncestors"?ti(e)?[]:wx(e,this._c):[].concat(t),o],l=i[0],c=i.reduce((d,u)=>{const f=Op(e,u,r);return d.top=Ln(f.top,d.top),d.right=qs(f.right,d.right),d.bottom=qs(f.bottom,d.bottom),d.left=Ln(f.left,d.left),d},Op(e,l,r));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Sx(n){const{width:e,height:t}=Np(n);return{width:e,height:t}}function xx(n,e,t){const o=Ct(e),r=xt(e),s=t==="fixed",i=zn(n,!0,s,e);let l={scrollLeft:0,scrollTop:0};const c=St(0);function d(){c.x=oi(r)}if(o||!o&&!s)if(($n(e)!=="body"||ur(r))&&(l=ni(e)),o){const p=zn(e,!0,s,e);c.x=p.x+e.clientLeft,c.y=p.y+e.clientTop}else r&&d();s&&!o&&r&&d();const u=r&&!o&&!s?Bp(r,l):St(0),f=i.left+l.scrollLeft-c.x-u.x,h=i.top+l.scrollTop-c.y-u.y;return{x:f,y:h,width:i.width,height:i.height}}function Ia(n){return ct(n).position==="static"}function Dp(n,e){if(!Ct(n)||ct(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return xt(n)===t&&(t=t.ownerDocument.body),t}function Rp(n,e){const t=Je(n);if(ti(n))return t;if(!Ct(n)){let r=dn(n);for(;r&&!co(r);){if(at(r)&&!Ia(r))return r;r=dn(r)}return t}let o=Dp(n,e);for(;o&&rx(o)&&Ia(o);)o=Dp(o,e);return o&&co(o)&&Ia(o)&&!Ta(o)?t:o||cx(n)||t}const Cx=async function(n){const e=this.getOffsetParent||Rp,t=this.getDimensions,o=await t(n.floating);return{reference:xx(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function Ex(n){return ct(n).direction==="rtl"}const vx={convertOffsetParentRelativeRectToViewportRelativeRect:hx,getDocumentElement:xt,getClippingRect:bx,getOffsetParent:Rp,getElementRects:Cx,getClientRects:px,getDimensions:Sx,getScale:uo,isElement:at,isRTL:Ex};function Pp(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function Mx(n,e){let t=null,o;const r=xt(n);function s(){var l;clearTimeout(o),(l=t)==null||l.disconnect(),t=null}function i(l,c){l===void 0&&(l=!1),c===void 0&&(c=1),s();const d=n.getBoundingClientRect(),{left:u,top:f,width:h,height:p}=d;if(l||e(),!h||!p)return;const m=Gs(f),g=Gs(r.clientWidth-(u+h)),y=Gs(r.clientHeight-(f+p)),k=Gs(u),b={rootMargin:-m+"px "+-g+"px "+-y+"px "+-k+"px",threshold:Ln(0,qs(1,c))||1};let S=!0;function C(v){const E=v[0].intersectionRatio;if(E!==c){if(!S)return i();E?i(!1,E):o=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!Pp(d,n.getBoundingClientRect())&&i(),S=!1}try{t=new IntersectionObserver(C,{...b,root:r.ownerDocument})}catch{t=new IntersectionObserver(C,b)}t.observe(n)}return i(!0),s}function ri(n,e,t,o){o===void 0&&(o={});const{ancestorScroll:r=!0,ancestorResize:s=!0,elementResize:i=typeof ResizeObserver=="function",layoutShift:l=typeof IntersectionObserver=="function",animationFrame:c=!1}=o,d=Ba(n),u=r||s?[...d?fr(d):[],...fr(e)]:[];u.forEach(k=>{r&&k.addEventListener("scroll",t,{passive:!0}),s&&k.addEventListener("resize",t)});const f=d&&l?Mx(d,t):null;let h=-1,p=null;i&&(p=new ResizeObserver(k=>{let[x]=k;x&&x.target===d&&p&&(p.unobserve(e),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var b;(b=p)==null||b.observe(e)})),t()}),d&&!c&&p.observe(d),p.observe(e));let m,g=c?zn(n):null;c&&y();function y(){const k=zn(n);g&&!Pp(g,k)&&t(),g=k,m=requestAnimationFrame(y)}return t(),()=>{var k;u.forEach(x=>{r&&x.removeEventListener("scroll",t),s&&x.removeEventListener("resize",t)}),f==null||f(),(k=p)==null||k.disconnect(),p=null,c&&cancelAnimationFrame(m)}}const fo=ex,ho=tx,po=XS,Tx=(n,e,t)=>{const o=new Map,r={platform:vx,...t},s={...r.platform,_c:o};return YS(n,e,{...r,platform:s})};function Nx(n){return n!=null&&typeof n=="object"&&"$el"in n}function Lp(n){if(Nx(n)){const e=n.$el;return Ma(e)&&$n(e)==="#comment"?null:e}return n}function hr(n){return typeof n=="function"?n():a.unref(n)}function Vp(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function $p(n,e){const t=Vp(n);return Math.round(e*t)/t}function mo(n,e,t){t===void 0&&(t={});const o=t.whileElementsMounted,r=a.computed(()=>{var E;return(E=hr(t.open))!=null?E:!0}),s=a.computed(()=>hr(t.middleware)),i=a.computed(()=>{var E;return(E=hr(t.placement))!=null?E:"bottom"}),l=a.computed(()=>{var E;return(E=hr(t.strategy))!=null?E:"absolute"}),c=a.computed(()=>{var E;return(E=hr(t.transform))!=null?E:!0}),d=a.computed(()=>Lp(n.value)),u=a.computed(()=>Lp(e.value)),f=a.ref(0),h=a.ref(0),p=a.ref(l.value),m=a.ref(i.value),g=a.shallowRef({}),y=a.ref(!1),k=a.computed(()=>{const E={position:p.value,left:"0",top:"0"};if(!u.value)return E;const M=$p(u.value,f.value),T=$p(u.value,h.value);return c.value?{...E,transform:"translate("+M+"px, "+T+"px)",...Vp(u.value)>=1.5&&{willChange:"transform"}}:{position:p.value,left:M+"px",top:T+"px"}});let x;function b(){if(d.value==null||u.value==null)return;const E=r.value;Tx(d.value,u.value,{middleware:s.value,placement:i.value,strategy:l.value}).then(M=>{f.value=M.x,h.value=M.y,p.value=M.strategy,m.value=M.placement,g.value=M.middlewareData,y.value=E!==!1})}function S(){typeof x=="function"&&(x(),x=void 0)}function C(){if(S(),o===void 0){b();return}if(d.value!=null&&u.value!=null){x=o(d.value,u.value,b);return}}function v(){r.value||(y.value=!1)}return a.watch([s,i,l,r],b,{flush:"sync"}),a.watch([d,u],C,{flush:"sync"}),a.watch(r,v,{flush:"sync"}),a.getCurrentScope()&&a.onScopeDispose(S),{x:a.shallowReadonly(f),y:a.shallowReadonly(h),strategy:a.shallowReadonly(p),placement:a.shallowReadonly(m),middlewareData:a.shallowReadonly(g),isPositioned:a.shallowReadonly(y),floatingStyles:k,update:b}}const Ax=["menu-open"],Ue=a.defineComponent({__name:"MenuDropdown",props:{title:{},disabled:{type:Boolean},placement:{default:"top"},offsetPx:{default:8}},emits:["open","close"],setup(n,{emit:e}){const t=n,o=e,r=a.inject("containerRef"),s=a.inject(Ec,null),i=a.inject(vc,0),l=Math.random().toString(36).slice(2);a.provide(vc,i+1);const{show:c,hide:d}=zt(),u=a.ref(!1);s&&a.watch(()=>s.value.get(i),b=>{b!==void 0&&b!==l&&u.value&&(u.value=!1)});const f=a.ref(null),h=a.ref(null),{floatingStyles:p}=mo(f,h,{placement:t.placement,middleware:[fo(t.offsetPx),po(),ho({padding:8})],whileElementsMounted:ri});function m(){t.disabled||(u.value=!u.value)}function g(){u.value=!1}function y(b){var M,T,A;const S=b.target,C=(M=f.value)==null?void 0:M.contains(S),v=(T=h.value)==null?void 0:T.contains(S),E=(A=S.closest)==null?void 0:A.call(S,".wov-menu-dropdown");!C&&!v&&!E&&g()}function k(){t.title&&f.value&&!u.value&&c(t.title,f.value)}function x(){d()}return a.watch(u,b=>{b?(d(),document.addEventListener("click",y,!0),s&&(s.value.set(i,l),s.value=new Map(s.value)),o("open")):(document.removeEventListener("click",y,!0),(s==null?void 0:s.value.get(i))===l&&(s.value.delete(i),s.value=new Map(s.value)),o("close"))}),a.onUnmounted(()=>{document.removeEventListener("click",y,!0)}),(b,S)=>(a.openBlock(),a.createElementBlock(a.Fragment,null,[a.createElementVNode("div",{ref_key:"buttonRef",ref:f,class:a.normalizeClass(["wov-menu-dropdown-trigger",{"is-open":u.value}]),"menu-open":u.value||void 0,onMousedown:S[0]||(S[0]=a.withModifiers(()=>{},["prevent"])),onClick:m,onMouseenter:k,onMouseleave:x},[a.renderSlot(b.$slots,"button",{isOpen:u.value})],42,Ax),a.unref(r)?(a.openBlock(),a.createBlock(a.Teleport,{key:0,to:a.unref(r)},[u.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"dropdownRef",ref:h,class:"wov-menu-dropdown",style:a.normalizeStyle(a.unref(p))},[a.renderSlot(b.$slots,"dropdown",{close:g})],4)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)],64))}}),Bx={},Ix={viewBox:"0 0 512 320",fill:"currentColor",style:{width:"7px",color:"var(--wov-gray-300)"}};function Ox(n,e){return a.openBlock(),a.createElementBlock("svg",Ix,[...e[0]||(e[0]=[a.createElementVNode("path",{d:"M233.4 278.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 210.7 86.6 41.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"},null,-1)])])}const Ge=kn(Bx,[["render",Ox]]),_x={class:"wov-menu-button"},Dx=["innerHTML"],Rx=["onClick"],Px=["innerHTML"],Oa=a.defineComponent({__name:"ArrowHeadButton",props:{entityIds:{},side:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=a.shallowRef(null),r=a.computed(()=>{const l=o.value??(e.side==="start"?te.ArrowHeadKind.None:te.ArrowHeadKind.V);return Kn(l)});t(l=>{let c=null;for(const d of e.entityIds){if(w.hasComponent(l,d,te.ElbowArrow)){const u=te.ElbowArrow.read(l,d),f=e.side==="start"?u.startArrowHead:u.endArrowHead;if(c===null)c=f;else if(f!==c){o.value=e.side==="start"?te.ArrowHeadKind.None:te.ArrowHeadKind.V;return}}if(w.hasComponent(l,d,te.ArcArrow)){const u=te.ArcArrow.read(l,d),f=e.side==="start"?u.startArrowHead:u.endArrowHead;if(c===null)c=f;else if(f!==c){o.value=e.side==="start"?te.ArrowHeadKind.None:te.ArrowHeadKind.V;return}}}o.value=c});function s(l){o.value=l,t(c=>{for(const d of e.entityIds){if(w.hasComponent(c,d,te.ElbowArrow)){const u=te.ElbowArrow.write(c,d);e.side==="start"?u.startArrowHead=l:u.endArrowHead=l}if(w.hasComponent(c,d,te.ArcArrow)){const u=te.ArcArrow.write(c,d);e.side==="start"?u.startArrowHead=l:u.endArrowHead=l}}})}function i(l){if(!l)return"";const c=e.side==="start";return`<line x1="${c?8:4}" y1="12" x2="${c?20:16}" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round" /><g transform="${`translate(${c?4:20}, 12) scale(${c?"-0.8, 0.8":"0.8"})`}">${l.svg}</g>`}return(l,c)=>(a.openBlock(),a.createBlock(Ue,{title:n.side==="start"?"Start Arrow Head":"End Arrow Head"},{button:a.withCtx(()=>[a.createElementVNode("div",_x,[(a.openBlock(),a.createElementBlock("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",innerHTML:i(r.value)},null,8,Dx)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(a.unref(Ei),d=>(a.openBlock(),a.createElementBlock("button",{key:d.kind,class:a.normalizeClass(["wov-menu-option",{"is-active":o.value===d.kind}]),onClick:u=>s(d.kind)},[(a.openBlock(),a.createElementBlock("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",innerHTML:i(d)},null,8,Px))],10,Rx))),128))]),_:1},8,["title"]))}}),Lx={class:"wov-menu-button"},Vx=["onClick"],zp=a.defineComponent({__name:"ArrowThicknessButton",props:{entityIds:{}},setup(n){const e=[{label:"S",value:2},{label:"M",value:4},{label:"L",value:8}],t=n,{nextEditorTick:o}=le(),r=a.shallowRef(null);o(i=>{let l=null;for(const c of t.entityIds){if(w.hasComponent(i,c,te.ElbowArrow)){const d=te.ElbowArrow.read(i,c);if(l===null)l=d.thickness;else if(d.thickness!==l){r.value=null;return}}if(w.hasComponent(i,c,te.ArcArrow)){const d=te.ArcArrow.getThickness(i,c);if(l===null)l=d;else if(d!==l){r.value=null;return}}}r.value=l});function s(i){r.value=i,o(l=>{for(const c of t.entityIds){if(w.hasComponent(l,c,te.ElbowArrow)){const d=te.ElbowArrow.write(l,c);d.thickness=i}w.hasComponent(l,c,te.ArcArrow)&&te.ArcArrow.setThickness(l,c,i)}})}return(i,l)=>(a.openBlock(),a.createBlock(Ue,{title:"Thickness"},{button:a.withCtx(()=>[a.createElementVNode("div",Lx,[l[0]||(l[0]=a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-linecap":"round"},[a.createElementVNode("line",{x1:"4",y1:"5",x2:"20",y2:"5","stroke-width":"1"}),a.createElementVNode("line",{x1:"4",y1:"11",x2:"20",y2:"11","stroke-width":"2.5"}),a.createElementVNode("line",{x1:"4",y1:"19",x2:"20",y2:"19","stroke-width":"4"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(e,c=>a.createElementVNode("button",{key:c.value,class:a.normalizeClass(["wov-menu-option wov-arrow-thickness-option",{"is-active":r.value===c.value}]),onClick:d=>s(c.value)},a.toDisplayString(c.label),11,Vx)),64))]),_:1}))}}),un=a.defineComponent({__name:"MenuButton",props:{title:{}},emits:["click"],setup(n,{emit:e}){const t=n,o=e,r=a.ref(null),s=a.ref(!1),{show:i,hide:l}=zt();function c(f){o("click",f)}function d(){s.value=!0,t.title&&r.value&&i(t.title,r.value)}function u(){s.value=!1,l()}return a.watch(()=>t.title,f=>{!s.value||!f||!r.value||i(f,r.value)}),(f,h)=>(a.openBlock(),a.createElementBlock("button",{ref_key:"buttonRef",ref:r,class:"wov-menu-button",onClick:c,onMouseenter:d,onMouseleave:u},[a.renderSlot(f.$slots,"default")],544))}}),$x={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},Fp=a.defineComponent({__name:"AspectLockButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=Me(w.TransformBoxStateSingleton),r=wt(()=>e.entityIds,w.Block),s=a.computed(()=>{for(const l of r.value.values())if((l==null?void 0:l.resizeMode)===w.ResizeMode.Free)return!1;return!0});function i(){const l=s.value?w.ResizeMode.Free:w.ResizeMode.Default;t(c=>{for(const u of e.entityIds){const f=w.Block.write(c,u);f.resizeMode=l}const{transformBoxId:d}=o.value;d!==null&&w.UpdateTransformBox.spawn(c,{transformBoxId:d})})}return(l,c)=>(a.openBlock(),a.createBlock(un,{title:s.value?"Unlock aspect ratio":"Lock aspect ratio",onClick:i},{default:a.withCtx(()=>[(a.openBlock(),a.createElementBlock("svg",$x,[c[12]||(c[12]=a.createElementVNode("rect",{x:"7",y:"8",width:"10",height:"8",rx:"1"},null,-1)),s.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:0},[c[0]||(c[0]=a.createElementVNode("path",{d:"M3 7V5a2 2 0 0 1 2-2h2"},null,-1)),c[1]||(c[1]=a.createElementVNode("path",{d:"M17 3h2a2 2 0 0 1 2 2v2"},null,-1)),c[2]||(c[2]=a.createElementVNode("path",{d:"M21 17v2a2 2 0 0 1-2 2h-2"},null,-1)),c[3]||(c[3]=a.createElementVNode("path",{d:"M7 21H5a2 2 0 0 1-2-2v-2"},null,-1))],64)):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[c[4]||(c[4]=a.createElementVNode("path",{d:"M3 6V3h3"},null,-1)),c[5]||(c[5]=a.createElementVNode("path",{d:"m6 6-3-3"},null,-1)),c[6]||(c[6]=a.createElementVNode("path",{d:"M21 6V3h-3"},null,-1)),c[7]||(c[7]=a.createElementVNode("path",{d:"m18 6 3-3"},null,-1)),c[8]||(c[8]=a.createElementVNode("path",{d:"M3 18v3h3"},null,-1)),c[9]||(c[9]=a.createElementVNode("path",{d:"m6 18-3 3"},null,-1)),c[10]||(c[10]=a.createElementVNode("path",{d:"M21 18v3h-3"},null,-1)),c[11]||(c[11]=a.createElementVNode("path",{d:"m18 18 3 3"},null,-1))],64))]))]),_:1},8,["title"]))}}),zx={class:"wov-block-operations-dropdown"},Fx=["onClick"],Hx={viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},jx=["d"],Hp=a.defineComponent({__name:"BlockOperationsButton",setup(n){const e=[{label:"Duplicate",command:w.DuplicateSelected,iconPaths:["M10 8h10a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H10a2 2 0 0 1-2-2V10a2 2 0 0 1 2-2z","M4 16c-1.1 0-2-.9-2-2V4c0-1.1.9-2 2-2h10c1.1 0 2 .9 2 2"]},{label:"Bring forward",command:w.BringForwardSelected,iconPaths:["M5 3h14","m18 13-6-6-6 6","M12 7v14"]},{label:"Send backward",command:w.SendBackwardSelected,iconPaths:["M12 17V3","m6 11 6 6 6-6","M19 21H5"]},{label:"Delete",command:w.RemoveSelected,iconPaths:["M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6","M3 6h18","M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"],danger:!0}],{getEditor:t}=le();function o(r,s){var i;(i=t())==null||i.command(r.command),s()}return(r,s)=>(a.openBlock(),a.createBlock(Ue,{title:"More"},{button:a.withCtx(()=>[...s[0]||(s[0]=[a.createElementVNode("div",{class:"wov-block-operations-button"},[a.createElementVNode("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("circle",{cx:"5",cy:"12",r:"1"}),a.createElementVNode("circle",{cx:"12",cy:"12",r:"1"}),a.createElementVNode("circle",{cx:"19",cy:"12",r:"1"})])],-1)])]),dropdown:a.withCtx(({close:i})=>[a.createElementVNode("div",zx,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(e,l=>a.createElementVNode("button",{key:l.label,class:a.normalizeClass(["wov-block-operations-option",{"is-danger":l.danger}]),onClick:c=>o(l,i)},[(a.openBlock(),a.createElementBlock("svg",Hx,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(l.iconPaths,c=>(a.openBlock(),a.createElementBlock("path",{key:c,d:c},null,8,jx))),128))])),a.createElementVNode("span",null,a.toDisplayString(l.label),1)],10,Fx)),64))])]),_:1}))}}),Ux=["value"],Wx=a.defineComponent({__name:"ColorInput",props:{modelValue:{}},emits:["update:modelValue"],setup(n,{emit:e}){const t=n,o=e,r=a.ref(t.modelValue??"");a.watch(()=>t.modelValue,u=>{u&&u!==r.value&&(r.value=u)});function s(u){const f=u.startsWith("#")?u:`#${u}`;return/^#[0-9A-Fa-f]{6}$/.test(f)}function i(u){return(u.startsWith("#")?u:`#${u}`).toLowerCase()}function l(u){let h=u.target.value;if((h.length===6||h.length===7)&&s(h)){const p=i(h);r.value=p,o("update:modelValue",p)}}function c(u){const h=u.target.value;if(h&&s(h)){const p=i(h);r.value=p,o("update:modelValue",p)}else t.modelValue&&(r.value=t.modelValue)}function d(u){if(u.stopPropagation(),u.key==="Enter"){const f=u.target,h=f.value;if(h&&s(h)){const p=i(h);r.value=p,o("update:modelValue",p),setTimeout(()=>f.select())}}}return(u,f)=>(a.openBlock(),a.createElementBlock("input",{id:"wov-color-input",class:"wov-color-input",type:"text",size:"1","aria-label":"Hex color value",autocomplete:"off",autocorrect:"off",autocapitalize:"off",spellcheck:"false",value:r.value,onInput:l,onChange:c,onKeydown:d},null,40,Ux))}}),jp=a.defineComponent({__name:"ColorSlider",props:{modelValue:{},thumbColor:{},background:{}},emits:["update:modelValue"],setup(n,{expose:e,emit:t}){const o=t,r=a.ref(null),s=a.ref(!1);function i(d){s.value=!0,l(d),window.addEventListener("pointermove",l),window.addEventListener("pointerup",c)}function l(d){if(!r.value)return;const u=r.value.getBoundingClientRect(),f=Math.max(0,Math.min(100,(d.clientY-u.top)/u.height*100));o("update:modelValue",f)}function c(){s.value=!1,window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",c)}return e({isDragging:s}),(d,u)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"sliderRef",ref:r,class:"wov-color-slider",onPointerdown:a.withModifiers(i,["prevent"])},[n.background?(a.openBlock(),a.createElementBlock("div",{key:0,class:"wov-color-slider-gradient",style:a.normalizeStyle({background:n.background})},null,4)):a.createCommentVNode("",!0),a.createElementVNode("div",{class:"wov-color-slider-thumb",style:a.normalizeStyle({top:`${n.modelValue}%`,backgroundColor:n.thumbColor})},null,4)],544))}}),Kx={class:"wov-color-picker"},qx={class:"wov-color-picker-area"},Jx={class:"wov-color-picker-selector-gradient"},Gx="linear-gradient(to bottom, red 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%)",Up=a.defineComponent({__name:"ColorPicker",props:{modelValue:{},withOpacity:{type:Boolean}},emits:["update:modelValue"],setup(n,{emit:e}){const t=n,o=e,r=a.ref(null),s=a.ref(null),i=a.ref(null),l=a.ref({x:100,y:0}),c=a.ref(0),d=a.ref(0),u=a.ref(!1),f=a.computed(()=>{var v,E;return u.value||((v=r.value)==null?void 0:v.isDragging)||((E=s.value)==null?void 0:E.isDragging)}),h=a.computed(()=>({h:c.value/100*360,s:l.value.x,v:100-l.value.y,a:(100-d.value)/100*255})),p=a.computed(()=>Zh({h:h.value.h,s:100,v:100})),m=a.computed(()=>Zh({h:h.value.h,s:h.value.s,v:h.value.v})),g=a.computed(()=>t.withOpacity?ep(h.value):m.value),y=a.computed(()=>`linear-gradient(to top, transparent 0%, ${m.value} 100%)`);function k(v){if(v){const E=Qh(v);l.value={x:E.s,y:100-E.v},c.value=E.h/360*100,d.value=100-E.a/255*100}}function x(v){k(v),o("update:modelValue",t.withOpacity?ep(Qh(v)):v)}k(t.modelValue),a.watch(()=>t.modelValue,v=>{f.value||k(v)}),a.watch([l,c,d],()=>{f.value&&o("update:modelValue",g.value)});function b(v){u.value=!0,S(v),window.addEventListener("pointermove",S),window.addEventListener("pointerup",C)}function S(v){if(!i.value)return;const E=i.value.getBoundingClientRect(),M=Math.max(0,Math.min(100,(v.clientX-E.left)/E.width*100)),T=Math.max(0,Math.min(100,(v.clientY-E.top)/E.height*100));l.value={x:M,y:T}}function C(){u.value=!1,window.removeEventListener("pointermove",S),window.removeEventListener("pointerup",C)}return(v,E)=>(a.openBlock(),a.createElementBlock("div",Kx,[a.createVNode(Wx,{modelValue:g.value,"onUpdate:modelValue":x},null,8,["modelValue"]),a.createElementVNode("div",qx,[a.createElementVNode("div",{ref_key:"selectorRef",ref:i,class:"wov-color-picker-selector",style:a.normalizeStyle({backgroundColor:p.value}),onPointerdown:a.withModifiers(b,["prevent"])},[a.createElementVNode("div",Jx,[a.createElementVNode("div",{class:"wov-color-picker-selector-thumb",style:a.normalizeStyle({left:`${l.value.x}%`,top:`${l.value.y}%`,backgroundColor:m.value})},null,4)])],36),a.createVNode(jp,{ref_key:"hueSliderRef",ref:r,modelValue:c.value,"onUpdate:modelValue":E[0]||(E[0]=M=>c.value=M),thumbColor:p.value,background:Gx},null,8,["modelValue","thumbColor"]),n.withOpacity?(a.openBlock(),a.createBlock(jp,{key:0,ref_key:"opacitySliderRef",ref:s,modelValue:d.value,"onUpdate:modelValue":E[1]||(E[1]=M=>d.value=M),thumbColor:m.value,background:y.value,class:"wov-color-picker-opacity"},null,8,["modelValue","thumbColor","background"])):a.createCommentVNode("",!0)])]))}}),Yx={class:"wov-color-bubbles-container"},Xx={key:1,class:"wov-color-bubbles"},Qx=["onClick"],si=a.defineComponent({__name:"ColorBubbles",props:{currentColor:{},palette:{},hideHighlight:{type:Boolean},withPicker:{type:Boolean},withOpacity:{type:Boolean}},emits:["change","picker-open"],setup(n,{emit:e}){const t=n,o=e,r=["#000000","#374151","#6B7280","#9CA3AF","#D1D5DB","#FFFFFF","#EF4444","#F97316","#EAB308","#22C55E","#14B8A6","#3B82F6","#8B5CF6","#EC4899"],s=a.computed(()=>{const m=t.palette??r,g=t.withPicker,y=m.length%2===1;return g&&!y||!g&&y?m.slice(0,-1):m}),i=a.ref(!1),l=a.ref(t.currentColor??"#ff0000");function c(m,g){const y=k=>{const x=k.replace(/^#/,"").toLowerCase();return x.length===6?`${x}ff`:x};return y(m)===y(g)}function d(m){return t.hideHighlight||!t.currentColor?!1:c(t.currentColor,m)}function u(){return t.hideHighlight||!t.currentColor?!1:!s.value.some(m=>c(t.currentColor,m))}function f(m){const g=ma(m);g&&o("change",g)}function h(){!i.value&&t.currentColor&&(l.value=t.currentColor),i.value=!i.value,o("picker-open",i.value)}function p(m){l.value=m;const g=ma(m);g&&o("change",g)}return(m,g)=>(a.openBlock(),a.createElementBlock("div",Yx,[i.value?(a.openBlock(),a.createBlock(Up,{key:0,modelValue:l.value,"onUpdate:modelValue":[g[0]||(g[0]=y=>l.value=y),p],withOpacity:n.withOpacity},null,8,["modelValue","withOpacity"])):(a.openBlock(),a.createElementBlock("div",Xx,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(s.value,y=>(a.openBlock(),a.createElementBlock("div",{key:y,class:a.normalizeClass(["wov-color-bubble",{selected:d(y)}]),style:a.normalizeStyle({backgroundColor:y}),onMousedown:g[1]||(g[1]=a.withModifiers(()=>{},["prevent"])),onClick:k=>f(y)},null,46,Qx))),128)),n.withPicker?(a.openBlock(),a.createElementBlock("div",{key:0,class:a.normalizeClass(["wov-color-bubble wov-rainbow-bubble",{selected:u()}]),onMousedown:g[2]||(g[2]=a.withModifiers(()=>{},["prevent"])),onClick:h},null,34)):a.createCommentVNode("",!0)]))]))}}),Zx={class:"wov-color-button"},eC={class:"wov-color-swatch"},Wp=a.defineComponent({__name:"ColorButton",props:{entityIds:{},withOpacity:{type:Boolean}},setup(n){const e=n,{nextEditorTick:t}=le(),o=wt(()=>e.entityIds,w.Color),r=a.computed(()=>{const d=new Set;for(const u of o.value.values())if(u){const f=sr(u);d.add(f)}return Array.from(d)}),s=a.computed(()=>r.value.length>1),i=a.computed(()=>r.value[0]??null),l=a.computed(()=>{if(r.value.length===0)return{backgroundColor:"#000"};if(r.value.length>=2){const d=r.value[0],u=r.value[1];return{background:`linear-gradient(45deg, ${d} 0%, ${d} 50%, ${u} 50%, ${u} 100%)`}}return{backgroundColor:r.value[0]}});function c(d){const u=sr(d);t(f=>{for(const h of e.entityIds)w.Color.fromHex(f,h,u)})}return(d,u)=>(a.openBlock(),a.createBlock(Ue,{title:"Color"},{button:a.withCtx(()=>[a.createElementVNode("div",Zx,[a.createElementVNode("div",eC,[a.createElementVNode("div",{class:"wov-color-swatch-fill",style:a.normalizeStyle(l.value)},null,4)]),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createVNode(si,{currentColor:i.value??void 0,hideHighlight:s.value,withPicker:!0,withOpacity:n.withOpacity,onChange:c},null,8,["currentColor","hideHighlight","withOpacity"])]),_:1}))}}),Kp=a.defineComponent({__name:"MenuTooltip",setup(n){const{activeTooltip:e,isVisible:t}=zt(),o=a.ref(null),r=a.computed(()=>{var u;return((u=e.value)==null?void 0:u.anchor)??null}),s=a.computed(()=>{var u;return((u=e.value)==null?void 0:u.placement)??"top"}),{floatingStyles:i}=mo(r,o,{placement:s,middleware:[fo(8),po(),ho({padding:8})]}),l=Symbol("menu-tooltip"),c=a.computed(()=>Ws.value[0]===l);a.onMounted(()=>{Ws.value.push(l)}),a.onUnmounted(()=>{Ws.value=Ws.value.filter(u=>u!==l)});const d=a.computed(()=>{var u;return c.value&&t.value&&((u=e.value)==null?void 0:u.text)});return(u,f)=>(a.openBlock(),a.createBlock(a.Teleport,{to:"body"},[a.createVNode(a.Transition,{name:"wov-tooltip-fade"},{default:a.withCtx(()=>{var h;return[d.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"tooltipRef",ref:o,class:"wov-menu-tooltip",style:a.normalizeStyle(a.unref(i))},a.toDisplayString((h=a.unref(e))==null?void 0:h.text),5)):a.createCommentVNode("",!0)]}),_:1})]))}}),tC={class:"wov-menu-button"},nC=["onClick"],qp=a.defineComponent({__name:"PenStrokeThicknessButton",props:{entityIds:{}},setup(n){const e=[{label:"S",value:4},{label:"M",value:8},{label:"L",value:16}],t=n,{nextEditorTick:o}=le(),r=wt(()=>t.entityIds,yn.PenStroke),s=a.computed(()=>{let c=!1;for(const d of r.value.values())if(d){if(d.kind===yn.PenStrokeKind.Fill)return!1;c=!0}return c}),i=a.computed(()=>{let c=null;for(const d of r.value.values())if(d){if(c===null)c=d.thickness;else if(d.thickness!==c)return null}return c});function l(c){o(d=>{for(const u of t.entityIds){const f=yn.PenStroke.write(d,u);f.thickness=c}})}return(c,d)=>s.value?(a.openBlock(),a.createBlock(Ue,{key:0,title:"Thickness"},{button:a.withCtx(()=>[a.createElementVNode("div",tC,[d[0]||(d[0]=a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-linecap":"round"},[a.createElementVNode("line",{x1:"4",y1:"5",x2:"20",y2:"5","stroke-width":"1"}),a.createElementVNode("line",{x1:"4",y1:"11",x2:"20",y2:"11","stroke-width":"2.5"}),a.createElementVNode("line",{x1:"4",y1:"19",x2:"20",y2:"19","stroke-width":"4"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(e,u=>a.createElementVNode("button",{key:u.value,class:a.normalizeClass(["wov-menu-option wov-pen-thickness-option",{"is-active":i.value===u.value}]),onClick:f=>l(u.value)},a.toDisplayString(u.label),11,nC)),64))]),_:1})):a.createCommentVNode("",!0)}}),oC={class:"wov-fill-color-button"},rC={class:"wov-fill-dropdown"},sC={key:0,class:"wov-fill-mode-section"},iC=["title","onClick"],lC={viewBox:"0 0 24 24",fill:"none"},aC=["fill","fill-opacity","stroke","stroke-width","stroke-dasharray"],Jp=a.defineComponent({__name:"ShapeFillColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t,setDefaults:o}=le(),r=wt(()=>e.entityIds,w.Shape),s=[{mode:"solid",label:"Solid",alpha:255},{mode:"faded",label:"Faded",alpha:128},{mode:"none",label:"None",alpha:0}],i=a.computed(()=>{const m=r.value.values().next().value,g=(m==null?void 0:m.fillAlpha)??255;return g===0?"none":g<200?"faded":"solid"}),l=a.computed(()=>{const m=new Set;for(const g of r.value.values())if(g){const y=g.fillAlpha??255;y===0?m.add("none"):y<200?m.add("faded"):m.add("solid")}return m.size>1});function c(m){o("shape",{fillAlpha:m}),t(g=>{for(const y of e.entityIds){const k=w.Shape.write(g,y);k.fillAlpha=m}})}const d=a.computed(()=>{const m=new Set;for(const g of r.value.values())if(g){const y=sr({red:g.fillRed,green:g.fillGreen,blue:g.fillBlue,alpha:g.fillAlpha??255});m.add(y)}return Array.from(m)}),u=a.computed(()=>d.value.length>1),f=a.computed(()=>d.value[0]??"#4a90d9");function h(m){o("shape",{fillRed:m.red,fillGreen:m.green,fillBlue:m.blue,fillAlpha:m.alpha}),t(g=>{for(const y of e.entityIds){const k=w.Shape.write(g,y);k.fillRed=m.red,k.fillGreen=m.green,k.fillBlue=m.blue,k.fillAlpha=m.alpha}})}const p=a.ref(!1);return(m,g)=>(a.openBlock(),a.createBlock(Ue,{title:"Fill Color"},{button:a.withCtx(()=>[a.createElementVNode("div",oC,[g[1]||(g[1]=a.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-fill-color-icon",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("path",{d:"M5.879,2.625L14.121,2.625C15.906,2.625 17.375,4.094 17.375,5.879L17.375,14.121C17.375,15.906 15.906,17.375 14.121,17.375L5.88,17.375C4.095,17.375 2.626,15.906 2.626,14.121L2.626,5.88C2.626,4.095 4.095,2.626 5.88,2.626L5.879,2.625Z","stroke-width":"1.25"}),a.createElementVNode("path",{d:"M2.779,14.655L14.543,2.871M10.238,17.308L17.318,10.229M2.876,9.577L9.853,2.6M5.397,17.239L17.16,5.476","stroke-width":"1.25"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",rC,[p.value?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",sC,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(s,y=>a.createElementVNode("button",{key:y.mode,class:a.normalizeClass(["wov-fill-mode-option",{"is-active":!l.value&&y.mode===i.value}]),title:y.label,onClick:k=>c(y.alpha)},[(a.openBlock(),a.createElementBlock("svg",lC,[a.createElementVNode("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",fill:y.mode==="none"?"none":"currentColor","fill-opacity":y.mode==="faded"?.4:1,stroke:y.mode==="none"?"currentColor":"none","stroke-width":y.mode==="none"?1.5:0,"stroke-dasharray":y.mode==="none"?"3 3":""},null,8,aC)])),a.createElementVNode("span",null,a.toDisplayString(y.label),1)],10,iC)),64))])),a.createVNode(si,{currentColor:f.value,hideHighlight:u.value,withPicker:!0,withOpacity:!0,onChange:h,onPickerOpen:g[0]||(g[0]=y=>p.value=y)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),cC={class:"wov-shape-kind-button"},dC={class:"wov-shape-kind-dropdown"},uC=["onClick"],fC={viewBox:"0 0 20 20",class:"wov-shape-option-icon",fill:"none",stroke:"currentColor","stroke-width":"4"},hC=["d"],Gp=a.defineComponent({__name:"ShapeKindButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t,setDefaults:o}=le(),r=wt(()=>e.entityIds,w.Shape),s=a.computed(()=>{const d=r.value.values().next().value;return(d==null?void 0:d.kind)??"rectangle"}),i=a.computed(()=>{const d=new Set;for(const u of r.value.values())u&&d.add(u.kind);return d.size>1}),l=a.computed(()=>Object.keys(Co).map(d=>({kind:d,label:d.charAt(0).toUpperCase()+d.slice(1)})));function c(d){o("shape",{kind:d}),t(u=>{for(const f of e.entityIds){const h=w.Shape.write(u,f);h.kind=d}})}return(d,u)=>(a.openBlock(),a.createBlock(Ue,{title:"Shape Type"},{button:a.withCtx(()=>[a.createElementVNode("div",cC,[u[0]||(u[0]=a.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-shape-kind-icon",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[a.createElementVNode("circle",{cx:"6",cy:"6",r:"5"}),a.createElementVNode("rect",{x:"6",y:"6",width:"10",height:"10",fill:"var(--wov-gray-600)"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",dC,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(l.value,f=>(a.openBlock(),a.createElementBlock("button",{key:f.kind,class:a.normalizeClass(["wov-shape-kind-option",{"is-selected":!i.value&&f.kind===s.value}]),onClick:h=>c(f.kind)},[(a.openBlock(),a.createElementBlock("svg",fC,[a.createElementVNode("path",{d:a.unref(Co)[f.kind],transform:"translate(2, 2) scale(0.16)"},null,8,hC)])),a.createElementVNode("span",null,a.toDisplayString(f.label),1)],10,uC))),128))])]),_:1}))}}),pC={class:"wov-stroke-style-section"},mC=["title","onClick"],gC={viewBox:"0 0 24 8",fill:"none",stroke:"currentColor","stroke-width":"2"},yC=["stroke-dasharray","stroke-opacity"],kC=a.defineComponent({__name:"StrokeStyleOptions",props:{currentStyle:{},hasMultipleStyles:{type:Boolean}},emits:["change"],setup(n,{emit:e}){const t=e,o=[{kind:w.StrokeKind.Solid,label:"Solid"},{kind:w.StrokeKind.Dashed,label:"Dashed"},{kind:w.StrokeKind.None,label:"None"}];function r(i){switch(i){case w.StrokeKind.Dashed:return"6 6";case w.StrokeKind.None:return"";default:return""}}function s(i){t("change",i)}return(i,l)=>(a.openBlock(),a.createElementBlock("div",pC,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(o,c=>a.createElementVNode("button",{key:c.kind,class:a.normalizeClass(["wov-stroke-style-option",{"is-active":!n.hasMultipleStyles&&c.kind===n.currentStyle}]),title:c.label,onClick:d=>s(c.kind)},[(a.openBlock(),a.createElementBlock("svg",gC,[a.createElementVNode("line",{x1:"2",y1:"4",x2:"22",y2:"4","stroke-linecap":"round","stroke-dasharray":r(c.kind),"stroke-opacity":c.kind===a.unref(w.StrokeKind).None?.3:1},null,8,yC)])),a.createElementVNode("span",null,a.toDisplayString(c.label),1)],10,mC)),64))]))}}),wC={class:"wov-stroke-color-button"},bC={class:"wov-stroke-dropdown"},SC={key:1,class:"wov-stroke-thickness"},xC=["value"],CC={class:"wov-stroke-thickness-value"},EC={key:2,class:"wov-stroke-divider"},Yp=a.defineComponent({__name:"ShapeStrokeColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t,setDefaults:o}=le(),r=wt(()=>e.entityIds,w.Shape),s=a.ref(!1),i=a.computed(()=>{const g=new Set;for(const y of r.value.values())if(y){const k=sr({red:y.strokeRed,green:y.strokeGreen,blue:y.strokeBlue,alpha:255});g.add(k)}return Array.from(g)}),l=a.computed(()=>i.value.length>1),c=a.computed(()=>i.value[0]??"#000000"),d=a.computed(()=>{const g=r.value.values().next().value;return(g==null?void 0:g.strokeKind)??w.StrokeKind.Solid}),u=a.computed(()=>{const g=new Set;for(const y of r.value.values())y&&g.add(y.strokeKind);return g.size>1});function f(g){o("shape",{strokeRed:g.red,strokeGreen:g.green,strokeBlue:g.blue}),t(y=>{for(const k of e.entityIds){const x=w.Shape.write(y,k);x.strokeRed=g.red,x.strokeGreen=g.green,x.strokeBlue=g.blue}})}function h(g){o("shape",{strokeKind:g}),t(y=>{for(const k of e.entityIds){const x=w.Shape.write(y,k);x.strokeKind=g}})}const p=a.computed(()=>{const g=r.value.values().next().value;return(g==null?void 0:g.strokeWidth)??2});function m(g){const y=g.target,k=parseInt(y.value,10);o("shape",{strokeWidth:k}),t(x=>{for(const b of e.entityIds){const S=w.Shape.write(x,b);S.strokeWidth=k}})}return(g,y)=>(a.openBlock(),a.createBlock(Ue,{title:"Stroke Color"},{button:a.withCtx(()=>[a.createElementVNode("div",wC,[y[1]||(y[1]=a.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-stroke-color-icon",fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("path",{d:"M2.5 12.563c1.655-.886 5.9-3.293 8.568-4.355 2.668-1.062.101 2.822 1.32 3.105 1.218.283 5.112-1.814 5.112-1.814m-13.469 2.23c2.963-1.586 6.13-5.62 7.468-4.998 1.338.623-1.153 4.11-.132 5.595 1.02 1.487 6.133-1.43 6.133-1.43","stroke-width":"1.25"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",bC,[s.value?a.createCommentVNode("",!0):(a.openBlock(),a.createBlock(kC,{key:0,currentStyle:d.value,hasMultipleStyles:u.value,onChange:h},null,8,["currentStyle","hasMultipleStyles"])),s.value?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",SC,[a.createElementVNode("input",{type:"range",min:"1",max:"20",value:p.value,class:"wov-stroke-thickness-slider","aria-label":"Stroke thickness",onInput:m},null,40,xC),a.createElementVNode("span",CC,a.toDisplayString(p.value)+"px",1)])),s.value?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",EC)),a.createVNode(si,{currentColor:c.value,hideHighlight:l.value,withPicker:!0,onChange:f,onPickerOpen:y[0]||(y[0]=k=>s.value=k)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),vC={class:"wov-tape-image-button"},MC={class:"wov-tape-image-bubbles"},TC=["onClick"],Xp=a.defineComponent({__name:"TapeImageButton",props:{entityIds:{}},setup(n){const e=[{name:"Masking Tape",url:"https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F7e3b7dde-927d-4b09-aeb4-d49eac36d4ea.png?generation=1715183194653465&alt=media"},{name:"Transparent",url:"https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F522899b7-0ae9-4303-bdca-71105d835210.png?generation=1715183195130528&alt=media"},{name:"Arabic",url:"https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F3658d208-67e9-48a4-865b-44842187b523.png?generation=1715183192038109&alt=media"},{name:"Balloons",url:"https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F7d836c56-ae9a-44e6-a624-e6a49286dcde.png?generation=1715183193267076&alt=media"},{name:"Flowers",url:"https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2Fc1a1b89a-543f-4817-8afa-76544e94d776.png?generation=1715183194007112&alt=media"}],t=n,{nextEditorTick:o}=le(),r=wt(()=>t.entityIds,w.Asset),s=a.computed(()=>{for(const l of r.value.values())if(l!=null&&l.identifier)return l.identifier;return null});function i(l){o(c=>{for(const d of t.entityIds){const u=w.Asset.write(c,d);u.identifier=l}})}return(l,c)=>(a.openBlock(),a.createBlock(Ue,{title:"Tape Style"},{button:a.withCtx(()=>[a.createElementVNode("div",vC,[a.createElementVNode("div",{class:"wov-tape-image-swatch",style:a.normalizeStyle(s.value?{backgroundImage:`url(${s.value})`}:{})},null,4),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",MC,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(e,d=>a.createElementVNode("div",{key:d.url,class:a.normalizeClass(["wov-tape-image-bubble",{selected:s.value===d.url}]),style:a.normalizeStyle({backgroundImage:`url(${d.url})`}),onMousedown:c[0]||(c[0]=a.withModifiers(()=>{},["prevent"])),onClick:u=>i(d.url)},null,46,TC)),64))])]),_:1}))}}),Qp=[{label:"Small",value:16},{label:"Medium",value:24},{label:"Large",value:40},{label:"Huge",value:96}],_a=10,Zp=20;function NC(n){const e=n.map(s=>s.value).filter(s=>s>0),t=Math.min(...e),o=Math.max(...e),r=(_a+Zp)/2;return n.map(s=>{if(!(s.value>0)||o<=t)return r;const i=(Math.log(s.value)-Math.log(t))/(Math.log(o)-Math.log(t));return Math.round(_a+i*(Zp-_a))})}const AC={key:0,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},BC={key:1,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},IC={key:2,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},OC={key:3,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},Da=a.defineComponent({__name:"TextAlignmentButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds),r=[w.TextAlignment.Left,w.TextAlignment.Center,w.TextAlignment.Right,w.TextAlignment.Justify];function s(){const i=r.indexOf(t.alignment),l=r[(i+1)%r.length];o.setAlignment(l)}return(i,l)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Text Align",onClick:s},{default:a.withCtx(()=>[a.unref(t).alignment===a.unref(w.TextAlignment).Left?(a.openBlock(),a.createElementBlock("svg",AC,[...l[0]||(l[0]=[a.createElementVNode("path",{d:"M288 64c0 17.7-14.3 32-32 32L32 96C14.3 96 0 81.7 0 64S14.3 32 32 32l224 0c17.7 0 32 14.3 32 32zm0 256c0 17.7-14.3 32-32 32L32 352c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zM0 192c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 224c-17.7 0-32-14.3-32-32zM448 448c0 17.7-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"},null,-1)])])):a.unref(t).alignment===a.unref(w.TextAlignment).Center?(a.openBlock(),a.createElementBlock("svg",BC,[...l[1]||(l[1]=[a.createElementVNode("path",{d:"M352 64c0-17.7-14.3-32-32-32L128 32c-17.7 0-32 14.3-32 32s14.3 32 32 32l192 0c17.7 0 32-14.3 32-32zm96 128c0-17.7-14.3-32-32-32L32 160c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32zM0 448c0 17.7 14.3 32 32 32l384 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 416c-17.7 0-32 14.3-32 32zM352 320c0-17.7-14.3-32-32-32l-192 0c-17.7 0-32 14.3-32 32s14.3 32 32 32l192 0c17.7 0 32-14.3 32-32z"},null,-1)])])):a.unref(t).alignment===a.unref(w.TextAlignment).Right?(a.openBlock(),a.createElementBlock("svg",IC,[...l[2]||(l[2]=[a.createElementVNode("path",{d:"M448 64c0 17.7-14.3 32-32 32L192 96c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zm0 256c0 17.7-14.3 32-32 32l-224 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l224 0c17.7 0 32 14.3 32 32zM0 192c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 224c-17.7 0-32-14.3-32-32zM448 448c0 17.7-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l384 0c17.7 0 32 14.3 32 32z"},null,-1)])])):(a.openBlock(),a.createElementBlock("svg",OC,[...l[3]||(l[3]=[a.createElementVNode("path",{d:"M448 64c0-17.7-14.3-32-32-32L32 32C14.3 32 0 46.3 0 64S14.3 96 32 96l384 0c17.7 0 32-14.3 32-32zm0 256c0-17.7-14.3-32-32-32L32 288c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32zM0 192c0 17.7 14.3 32 32 32l384 0c17.7 0 32-14.3 32-32s-14.3-32-32-32L32 160c-17.7 0-32 14.3-32 32zM448 448c0-17.7-14.3-32-32-32L32 416c-17.7 0-32 14.3-32 32s14.3 32 32 32l384 0c17.7 0 32-14.3 32-32z"},null,-1)])]))]),_:1})):a.createCommentVNode("",!0)}}),Ra=a.defineComponent({__name:"TextBoldButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Bold",class:a.normalizeClass({"wov-active":a.unref(t).isBold}),onClick:a.unref(o).toggleBold},{default:a.withCtx(()=>[...s[0]||(s[0]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M0 64C0 46.3 14.3 32 32 32l48 0 16 0 128 0c70.7 0 128 57.3 128 128c0 31.3-11.3 60.1-30 82.3c37.1 22.4 62 63.1 62 109.7c0 70.7-57.3 128-128 128L96 480l-16 0-48 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l16 0 0-160L48 96 32 96C14.3 96 0 81.7 0 64zM224 224c35.3 0 64-28.7 64-64s-28.7-64-64-64L112 96l0 128 112 0zM112 288l0 128 144 0c35.3 0 64-28.7 64-64s-28.7-64-64-64l-32 0-112 0z"})],-1)])]),_:1},8,["class","onClick"])):a.createCommentVNode("",!0)}});function _C(n,e){return a.getCurrentScope()?(a.onScopeDispose(n,e),!0):!1}const DC=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const RC=Object.prototype.toString,PC=n=>RC.call(n)==="[object Object]",ii=()=>{};function li(n){return Array.isArray(n)?n:[n]}function LC(n){return a.getCurrentInstance()}function VC(n,e=!0,t){LC()?a.onMounted(n,t):e?n():a.nextTick(n)}function $C(n,e,t){return a.watch(n,e,{...t,immediate:!0})}const ai=DC?window:void 0;function dt(n){var e;const t=a.toValue(n);return(e=t==null?void 0:t.$el)!==null&&e!==void 0?e:t}function Pa(...n){const e=(o,r,s,i)=>(o.addEventListener(r,s,i),()=>o.removeEventListener(r,s,i)),t=a.computed(()=>{const o=li(a.toValue(n[0])).filter(r=>r!=null);return o.every(r=>typeof r!="string")?o:void 0});return $C(()=>{var o,r;return[(o=(r=t.value)===null||r===void 0?void 0:r.map(s=>dt(s)))!==null&&o!==void 0?o:[ai].filter(s=>s!=null),li(a.toValue(t.value?n[1]:n[0])),li(a.unref(t.value?n[2]:n[1])),a.toValue(t.value?n[3]:n[2])]},([o,r,s,i],l,c)=>{if(!(o!=null&&o.length)||!(r!=null&&r.length)||!(s!=null&&s.length))return;const d=PC(i)?{...i}:i,u=o.flatMap(f=>r.flatMap(h=>s.map(p=>e(f,h,p,d))));c(()=>{u.forEach(f=>f())})},{flush:"post"})}function zC(n,e,t={}){const{window:o=ai,ignore:r=[],capture:s=!0,detectIframe:i=!1,controls:l=!1}=t;if(!o)return l?{stop:ii,cancel:ii,trigger:ii}:ii;let c=!0;const d=y=>a.toValue(r).some(k=>{if(typeof k=="string")return Array.from(o.document.querySelectorAll(k)).some(x=>x===y.target||y.composedPath().includes(x));{const x=dt(k);return x&&(y.target===x||y.composedPath().includes(x))}});function u(y){const k=a.toValue(y);return k&&k.$.subTree.shapeFlag===16}function f(y,k){const x=a.toValue(y),b=x.$.subTree&&x.$.subTree.children;return b==null||!Array.isArray(b)?!1:b.some(S=>S.el===k.target||k.composedPath().includes(S.el))}const h=y=>{const k=dt(n);if(y.target!=null&&!(!(k instanceof Element)&&u(n)&&f(n,y))&&!(!k||k===y.target||y.composedPath().includes(k))){if("detail"in y&&y.detail===0&&(c=!d(y)),!c){c=!0;return}e(y)}};let p=!1;const m=[Pa(o,"click",y=>{p||(p=!0,setTimeout(()=>{p=!1},0),h(y))},{passive:!0,capture:s}),Pa(o,"pointerdown",y=>{const k=dt(n);c=!d(y)&&!!(k&&!y.composedPath().includes(k))},{passive:!0}),i&&Pa(o,"blur",y=>{setTimeout(()=>{var k;const x=dt(n);((k=o.document.activeElement)===null||k===void 0?void 0:k.tagName)==="IFRAME"&&!(x!=null&&x.contains(o.document.activeElement))&&e(y)},0)},{passive:!0})].filter(Boolean),g=()=>m.forEach(y=>y());return l?{stop:g,cancel:()=>{c=!1},trigger:y=>{c=!0,h(y),c=!1}}:g}function FC(){const n=a.shallowRef(!1),e=a.getCurrentInstance();return e&&a.onMounted(()=>{n.value=!0},e),n}function HC(n){const e=FC();return a.computed(()=>(e.value,!!n()))}function jC(n,e,t={}){const{window:o=ai,...r}=t;let s;const i=HC(()=>o&&"ResizeObserver"in o),l=()=>{s&&(s.disconnect(),s=void 0)},c=a.watch(a.computed(()=>{const u=a.toValue(n);return Array.isArray(u)?u.map(f=>dt(f)):[dt(u)]}),u=>{if(l(),i.value&&o){s=new ResizeObserver(e);for(const f of u)f&&s.observe(f,r)}},{immediate:!0,flush:"post"}),d=()=>{l(),c()};return _C(d),{isSupported:i,stop:d}}function em(n,e={width:0,height:0},t={}){const{window:o=ai,box:r="content-box"}=t,s=a.computed(()=>{var f;return(f=dt(n))===null||f===void 0||(f=f.namespaceURI)===null||f===void 0?void 0:f.includes("svg")}),i=a.shallowRef(e.width),l=a.shallowRef(e.height),{stop:c}=jC(n,([f])=>{const h=r==="border-box"?f.borderBoxSize:r==="content-box"?f.contentBoxSize:f.devicePixelContentBoxSize;if(o&&s.value){const p=dt(n);if(p){const m=p.getBoundingClientRect();i.value=m.width,l.value=m.height}}else if(h){const p=li(h);i.value=p.reduce((m,{inlineSize:g})=>m+g,0),l.value=p.reduce((m,{blockSize:g})=>m+g,0)}else i.value=f.contentRect.width,l.value=f.contentRect.height},t);VC(()=>{const f=dt(n);f&&(i.value="offsetWidth"in f?f.offsetWidth:e.width,l.value="offsetHeight"in f?f.offsetHeight:e.height)});const d=a.watch(()=>dt(n),f=>{i.value=f?e.width:0,l.value=f?e.height:0});function u(){c(),d()}return{width:i,height:l,stop:u}}function tm(){const n=a.inject(we);if(!n)throw new Error("useFonts must be used within a WovenCanvas component");return a.computed(()=>{const e=n.getEditor();return e?e.fonts.filter(t=>t.selectable):[]})}const UC={class:"wov-font-family-button"},WC={class:"wov-font-family-label"},KC={class:"wov-font-list"},qC=["onClick"],JC=["src","alt"],La=a.defineComponent({__name:"TextFontFamilyButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds),r=tm(),s=a.computed(()=>r.value.map(u=>({name:u.name,displayName:u.displayName,previewImage:u.previewImage}))),i=a.computed(()=>t.fontFamily),l=a.computed(()=>{const u=i.value;if(u===null)return"Mixed";const f=s.value.find(h=>h.name===u);return(f==null?void 0:f.displayName)??u});function c(u){o.setFontFamily(u)}function d(u){u.stopPropagation()}return(u,f)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Ue,{key:0,title:"Font Family"},{button:a.withCtx(()=>[a.createElementVNode("div",UC,[a.createElementVNode("span",WC,a.toDisplayString(l.value),1),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",{class:"wov-font-family-menu",onWheel:d,onClick:f[0]||(f[0]=a.withModifiers(()=>{},["stop"]))},[a.createElementVNode("div",KC,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(s.value,h=>(a.openBlock(),a.createElementBlock("div",{key:h.name,class:a.normalizeClass(["wov-font-item",{active:i.value===h.name}]),onClick:p=>c(h.name)},[h.previewImage?(a.openBlock(),a.createElementBlock("img",{key:0,class:"wov-font-preview",src:h.previewImage,alt:h.name,loading:"lazy",decoding:"async"},null,8,JC)):(a.openBlock(),a.createElementBlock("span",{key:1,class:"wov-font-name",style:a.normalizeStyle({fontFamily:h.name})},a.toDisplayString(h.displayName),5))],10,qC))),128))])],32)]),_:1})):a.createCommentVNode("",!0)}}),GC={class:"wov-font-size-button"},YC={class:"wov-font-size-label"},XC=["onClick"],QC={key:0,class:"wov-check-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},ZC={class:"wov-input-container"},eE=["value"],tE={class:"wov-size-stepper"},nE=1,Va=a.defineComponent({__name:"TextFontSizeButton",props:{entityIds:{},sizeOptions:{default:()=>Qp},pxPerUnit:{default:1}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds),r=a.ref(null),s=a.computed(()=>NC(e.sizeOptions));function i(y){return+(y/e.pxPerUnit).toFixed(1)}const l=a.computed(()=>{const y=t.fontSize;return y===null?null:i(y)});function c(y){const k=l.value;return k!==null&&Math.abs(y.value-k)<.05}const d=a.computed(()=>{const y=l.value;if(y===null)return"Mixed";const k=e.sizeOptions.find(c);return k?k.label:`${y} px`}),u=a.computed(()=>{const y=l.value;return y===null?"":String(y)});function f(y){o.setFontSize(y*e.pxPerUnit)}function h(y){const k=y.target,x=Number.parseFloat(k.value);if(Number.isNaN(x)||x<=0){k.value=u.value;return}f(x)}function p(y){var S;const k=Number.parseFloat(((S=r.value)==null?void 0:S.value)??""),x=Number.isNaN(k)?l.value:k;if(x===null)return;const b=Math.max(+(x+y).toFixed(1),nE);r.value&&(r.value.value=String(b)),f(b)}function m(y){y.key==="Enter"?y.target.blur():y.key==="ArrowUp"?(y.preventDefault(),p(1)):y.key==="ArrowDown"&&(y.preventDefault(),p(-1))}function g(y){y.stopPropagation()}return(y,k)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Ue,{key:0,title:"Font Size"},{button:a.withCtx(()=>[a.createElementVNode("div",GC,[a.createElementVNode("span",YC,a.toDisplayString(d.value),1),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",{class:"wov-font-size-menu",onWheel:g,onClick:k[4]||(k[4]=a.withModifiers(()=>{},["stop"])),onKeydown:k[5]||(k[5]=a.withModifiers(()=>{},["stop"]))},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(n.sizeOptions,(x,b)=>(a.openBlock(),a.createElementBlock("div",{key:x.value,class:a.normalizeClass(["wov-font-size-option",{active:c(x)}]),onClick:S=>f(x.value)},[c(x)?(a.openBlock(),a.createElementBlock("svg",QC,[...k[6]||(k[6]=[a.createElementVNode("path",{d:"M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"},null,-1)])])):a.createCommentVNode("",!0),a.createElementVNode("span",{class:"wov-option-label",style:a.normalizeStyle({fontSize:`${s.value[b]}px`})},a.toDisplayString(x.label),5)],10,XC))),128)),k[10]||(k[10]=a.createElementVNode("div",{class:"wov-separator"},null,-1)),a.createElementVNode("div",ZC,[a.createElementVNode("input",{ref_key:"inputRef",ref:r,class:"wov-custom-input",value:u.value,onChange:h,onKeydown:m,placeholder:"Custom size"},null,40,eE),k[9]||(k[9]=a.createElementVNode("span",{class:"wov-px-suffix"},"px",-1)),a.createElementVNode("div",tE,[a.createElementVNode("button",{class:"wov-size-stepper-button",title:"Increase size",onMousedown:k[0]||(k[0]=a.withModifiers(()=>{},["prevent"])),onClick:k[1]||(k[1]=x=>p(1))},[...k[7]||(k[7]=[a.createElementVNode("svg",{class:"wov-size-stepper-icon up",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 320",fill:"currentColor"},[a.createElementVNode("path",{d:"M233.4 278.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 210.7 86.6 41.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"})],-1)])],32),a.createElementVNode("button",{class:"wov-size-stepper-button",title:"Decrease size",onMousedown:k[2]||(k[2]=a.withModifiers(()=>{},["prevent"])),onClick:k[3]||(k[3]=x=>p(-1))},[...k[8]||(k[8]=[a.createElementVNode("svg",{class:"wov-size-stepper-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 320",fill:"currentColor"},[a.createElementVNode("path",{d:"M233.4 278.6c12.5 12.5 32.8 12.5 45.3 0l192-192c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L256 210.7 86.6 41.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3l192 192z"})],-1)])],32)])])],32)]),_:1})):a.createCommentVNode("",!0)}}),$a=a.defineComponent({__name:"TextItalicButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Italic",class:a.normalizeClass({"wov-active":a.unref(t).isItalic}),onClick:a.unref(o).toggleItalic},{default:a.withCtx(()=>[...s[0]||(s[0]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M128 64c0-17.7 14.3-32 32-32l192 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-58.7 0L160 416l64 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32s14.3-32 32-32l58.7 0L224 96l-64 0c-17.7 0-32-14.3-32-32z"})],-1)])]),_:1},8,["class","onClick"])):a.createCommentVNode("",!0)}}),za=a.defineComponent({__name:"TextUnderlineButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Underline",class:a.normalizeClass({"wov-active":a.unref(t).isUnderline}),onClick:a.unref(o).toggleUnderline},{default:a.withCtx(()=>[...s[0]||(s[0]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M16 64c0-17.7 14.3-32 32-32l96 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-16 0 0 128c0 53 43 96 96 96s96-43 96-96l0-128-16 0c-17.7 0-32-14.3-32-32s14.3-32 32-32l96 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-16 0 0 128c0 88.4-71.6 160-160 160s-160-71.6-160-160L64 96 48 96C30.3 96 16 81.7 16 64zM0 448c0-17.7 14.3-32 32-32l384 0c17.7 0 32 14.3 32 32s-14.3 32-32 32L32 480c-17.7 0-32-14.3-32-32z"})],-1)])]),_:1},8,["class","onClick"])):a.createCommentVNode("",!0)}}),oE={class:"wov-link-input-container"},rE=["onKeydown"],Fa=a.defineComponent({__name:"TextLinkButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds),r=a.ref(!1),s=a.ref(""),i=a.ref(null),l=a.ref(null),c=a.ref(null),d=a.inject("containerRef"),{floatingStyles:u}=mo(l,c,{placement:"top",middleware:[fo(8),po(),ho({padding:8})],whileElementsMounted:ri});function f(){s.value=t.linkHref??"",r.value=!0,a.nextTick(()=>{var g,y;(g=i.value)==null||g.focus(),(y=i.value)==null||y.select()})}function h(){const g=s.value.trim();g?o.setLink(g):o.removeLink(),r.value=!1}function p(){o.removeLink(),s.value="",r.value=!1}function m(g){var k,x;const y=g.target;!((k=l.value)!=null&&k.contains(y))&&!((x=c.value)!=null&&x.contains(y))&&(r.value=!1)}return a.watch(r,g=>{g?document.addEventListener("click",m,!0):document.removeEventListener("click",m,!0)}),(g,y)=>(a.openBlock(),a.createElementBlock(a.Fragment,null,[a.createElementVNode("div",{ref_key:"buttonRef",ref:l},[a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Link",class:a.normalizeClass({"wov-active":a.unref(t).linkHref!==null}),onClick:f},{default:a.withCtx(()=>[...y[3]||(y[3]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M579.8 267.7c56.5-56.5 56.5-148 0-204.5c-50-50-128.8-56.5-186.3-15.4l-1.6 1.1c-14.4 10.3-17.7 30.3-7.4 44.6s30.3 17.7 44.6 7.4l1.6-1.1c32.1-22.9 76-19.3 103.8 8.6c31.5 31.5 31.5 82.5 0 114L422.3 334.8c-31.5 31.5-82.5 31.5-114 0c-27.9-27.9-31.5-71.8-8.6-103.8l1.1-1.6c10.3-14.4 7-34.4-7.4-44.6s-34.4-7-44.6 7.4l-1.1 1.6C206.5 251.2 213 330 263 380c56.5 56.5 148 56.5 204.5 0L579.8 267.7zM60.2 244.3c-56.5 56.5-56.5 148 0 204.5c50 50 128.8 56.5 186.3 15.4l1.6-1.1c14.4-10.3 17.7-30.3 7.4-44.6s-30.3-17.7-44.6-7.4l-1.6 1.1c-32.1 22.9-76 19.3-103.8-8.6C74 372.1 74 321.1 105.5 289.5L217.7 177.2c31.5-31.5 82.5-31.5 114 0c27.9 27.9 31.5 71.8 8.6 103.8l-1.1 1.6c-10.3 14.4-7 34.4 7.4 44.6s34.4 7 44.6-7.4l1.1-1.6C433.5 260.8 427 182 377 132c-56.5-56.5-148-56.5-204.5 0L60.2 244.3z"})],-1)])]),_:1},8,["class"])):a.createCommentVNode("",!0)],512),a.unref(d)?(a.openBlock(),a.createBlock(a.Teleport,{key:0,to:a.unref(d)},[r.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"dropdownRef",ref:c,class:"wov-link-input-dropdown",style:a.normalizeStyle(a.unref(u)),onKeydown:y[2]||(y[2]=a.withModifiers(()=>{},["stop"]))},[a.createElementVNode("div",oE,[a.withDirectives(a.createElementVNode("input",{ref_key:"inputRef",ref:i,"onUpdate:modelValue":y[0]||(y[0]=k=>s.value=k),class:"wov-link-input",placeholder:"Paste or type URL",onKeydown:[a.withKeys(a.withModifiers(h,["prevent"]),["enter"]),y[1]||(y[1]=a.withKeys(a.withModifiers(k=>r.value=!1,["prevent"]),["esc"]))]},null,40,rE),[[a.vModelText,s.value]]),s.value||a.unref(t).linkHref?(a.openBlock(),a.createElementBlock("button",{key:0,class:"wov-link-action-button",title:"Remove link",onClick:p},[...y[4]||(y[4]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M342.6 150.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0L192 210.7 86.6 105.4c-12.5-12.5-32.8-12.5-45.3 0s-12.5 32.8 0 45.3L146.7 256 41.4 361.4c-12.5 12.5-12.5 32.8 0 45.3s32.8 12.5 45.3 0L192 301.3 297.4 406.6c12.5 12.5 12.5 32.8 0 45.3s32.8 12.5 45.3 0L237.3 256 342.6 150.6z"})],-1)])])):a.createCommentVNode("",!0),a.createElementVNode("button",{class:"wov-link-action-button",title:"Apply link",onClick:h},[...y[5]||(y[5]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},[a.createElementVNode("path",{d:"M438.6 105.4c12.5 12.5 12.5 32.8 0 45.3l-256 256c-12.5 12.5-32.8 12.5-45.3 0l-128-128c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0L160 338.7 393.4 105.4c12.5-12.5 32.8-12.5 45.3 0z"})],-1)])])])],36)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)],64))}}),sE={class:"wov-text-color-button"},iE={class:"wov-text-icon-container"},Ha=a.defineComponent({__name:"TextColorButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=lt(()=>e.entityIds),r=a.computed(()=>t.color??"#000000"),s=a.computed(()=>({backgroundColor:r.value}));function i(l){o.setColor(sr(l))}return(l,c)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Ue,{key:0,title:"Text Color"},{button:a.withCtx(()=>[a.createElementVNode("div",sE,[a.createElementVNode("div",iE,[c[0]||(c[0]=a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor",class:"wov-text-icon"},[a.createElementVNode("path",{d:"M349.1 114.7C343.9 103.3 332.5 96 320 96C307.5 96 296.1 103.3 290.9 114.7L123.5 480L112 480C94.3 480 80 494.3 80 512C80 529.7 94.3 544 112 544L200 544C217.7 544 232 529.7 232 512C232 494.3 217.7 480 200 480L193.9 480L215.9 432L424.2 432L446.2 480L440.1 480C422.4 480 408.1 494.3 408.1 512C408.1 529.7 422.4 544 440.1 544L528.1 544C545.8 544 560.1 529.7 560.1 512C560.1 494.3 545.8 480 528.1 480L516.6 480L349.2 114.7zM394.8 368L245.2 368L320 204.8L394.8 368z"})],-1)),a.createElementVNode("div",{class:"wov-color-underline",style:a.normalizeStyle(s.value)},null,4)]),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createVNode(si,{currentColor:r.value,withPicker:!0,onChange:i},null,8,["currentColor"])]),_:1})):a.createCommentVNode("",!0)}}),lE={key:0,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-start-icon lucide-align-vertical-justify-start"},aE={key:1,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-center-icon lucide-align-vertical-justify-center"},cE={key:2,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-align-vertical-justify-end-icon lucide-align-vertical-justify-end"},nm=a.defineComponent({__name:"VerticalAlignButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),{state:o}=lt(()=>e.entityIds),r=[w.VerticalAlignment.Top,w.VerticalAlignment.Center,w.VerticalAlignment.Bottom],s=wt(()=>e.entityIds,w.VerticalAlign),i=a.computed(()=>{let c=null;for(const d of s.value.values()){const u=(d==null?void 0:d.value)??w.VerticalAlignment.Top;if(c===null)c=u;else if(c!==u)return null}return c});function l(){const c=i.value??w.VerticalAlignment.Top,d=r.indexOf(c),u=r[(d+1)%r.length];t(f=>{for(const h of e.entityIds){const p=w.VerticalAlign.write(f,h);p.value=u}})}return(c,d)=>a.unref(o).showTextMenuButtons?(a.openBlock(),a.createBlock(un,{key:0,title:"Vertical Align",onClick:l},{default:a.withCtx(()=>[i.value===a.unref(w.VerticalAlignment).Top||i.value===null?(a.openBlock(),a.createElementBlock("svg",lE,[...d[0]||(d[0]=[a.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"},null,-1),a.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"6",rx:"2"},null,-1),a.createElementVNode("path",{d:"M2 2h20"},null,-1)])])):i.value===a.unref(w.VerticalAlignment).Center?(a.openBlock(),a.createElementBlock("svg",aE,[...d[1]||(d[1]=[a.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"},null,-1),a.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"},null,-1),a.createElementVNode("path",{d:"M2 12h20"},null,-1)])])):(a.openBlock(),a.createElementBlock("svg",cE,[...d[2]||(d[2]=[a.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"12",rx:"2"},null,-1),a.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"},null,-1),a.createElementVNode("path",{d:"M2 22h20"},null,-1)])]))]),_:1})):a.createCommentVNode("",!0)}}),dE={class:"wov-text-group-button"},uE={class:"wov-text-group-dropdown"},fE={class:"wov-text-group-row wov-text-group-row-full"},hE={class:"wov-text-group-row"},om=a.defineComponent({__name:"TextButtonGroup",props:{entityIds:{},showVerticalAlign:{type:Boolean},pxPerUnit:{}},setup(n){const e=n,{state:t}=lt(()=>e.entityIds),o=a.inject("containerRef"),{width:r}=em(o),s=a.computed(()=>r.value>0&&r.value<600),i=a.ref(new Map);return a.provide(Ec,i),(l,c)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createElementBlock(a.Fragment,{key:0},[s.value?(a.openBlock(),a.createBlock(Ue,{key:0,title:"Text Formatting",placement:"top"},{button:a.withCtx(()=>[a.createElementVNode("div",dE,[c[0]||(c[0]=a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor",class:"wov-text-group-icon"},[a.createElementVNode("path",{d:"M349.1 114.7C343.9 103.3 332.5 96 320 96C307.5 96 296.1 103.3 290.9 114.7L123.5 480L112 480C94.3 480 80 494.3 80 512C80 529.7 94.3 544 112 544L200 544C217.7 544 232 529.7 232 512C232 494.3 217.7 480 200 480L193.9 480L215.9 432L424.2 432L446.2 480L440.1 480C422.4 480 408.1 494.3 408.1 512C408.1 529.7 422.4 544 440.1 544L528.1 544C545.8 544 560.1 529.7 560.1 512C560.1 494.3 545.8 480 528.1 480L516.6 480L349.2 114.7zM394.8 368L245.2 368L320 204.8L394.8 368z"})],-1)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",uE,[a.createElementVNode("div",fE,[a.createVNode(La,{entityIds:n.entityIds},null,8,["entityIds"]),c[1]||(c[1]=a.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),a.createVNode(Va,{entityIds:n.entityIds,"px-per-unit":n.pxPerUnit},null,8,["entityIds","px-per-unit"])]),a.createElementVNode("div",hE,[a.createVNode(Ra,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode($a,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(za,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Fa,{entityIds:n.entityIds},null,8,["entityIds"]),c[2]||(c[2]=a.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),a.createVNode(Ha,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Da,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(a.openBlock(),a.createBlock(nm,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):a.createCommentVNode("",!0)])])]),_:1})):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[a.createVNode(La,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Va,{entityIds:n.entityIds,"px-per-unit":n.pxPerUnit},null,8,["entityIds","px-per-unit"]),c[3]||(c[3]=a.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),a.createVNode(Ra,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode($a,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(za,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Fa,{entityIds:n.entityIds},null,8,["entityIds"]),c[4]||(c[4]=a.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),a.createVNode(Ha,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Da,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(a.openBlock(),a.createBlock(nm,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):a.createCommentVNode("",!0)],64))],64)):a.createCommentVNode("",!0)}}),rm=a.defineComponent({__name:"CanvasBackground",props:{background:{}},setup(n){const e=n,t={kind:"none",color:"#f4f4f4",strokeColor:"#a1a1a1",subdivisionStep:5},o=a.computed(()=>({...t,...e.background})),r=Me(w.Camera),s=Me(w.Grid),i=a.inject("containerRef"),l=a.ref({width:0,height:0});let c=null;const d=a.ref(null);let u=null;typeof document<"u"&&(u=document.createElement("canvas"));function f(x,b,S,C){const v=C/2;x.beginPath(),x.arc(b,S,v,0,Math.PI*2),x.fill()}function h(x,b,S){if(!u)return null;const C=S.dotSize??2,v=x*S.subdivisionStep,E=b*S.subdivisionStep;if(v<=0||E<=0)return null;u.width=v,u.height=E;const M=u.getContext("2d");if(!M)return null;if(M.clearRect(0,0,v,E),M.fillStyle=S.strokeColor,S.subdivisionStep===1)f(M,v/2,E/2,C);else for(let T=0;T<S.subdivisionStep;T++)for(let A=0;A<S.subdivisionStep;A++){const B=(T+.5)*(v/S.subdivisionStep),I=(A+.5)*(E/S.subdivisionStep),z=T===0&&A===0?2*C:C;f(M,B,I,z)}return M.createPattern(u,"repeat")}function p(x,b,S,C,v,E){x.lineWidth=E,x.beginPath(),x.moveTo(b,S),x.lineTo(C,v),x.stroke()}function m(x,b,S){if(!u)return null;const C=S.gridSize??1,v=x*S.subdivisionStep,E=b*S.subdivisionStep;if(v<=0||E<=0)return null;u.width=v,u.height=E;const M=u.getContext("2d");if(!M)return null;if(M.clearRect(0,0,v,E),M.strokeStyle=S.strokeColor,S.subdivisionStep===1)p(M,0,0,v,0,C),p(M,0,0,0,E,C);else{const T=v/S.subdivisionStep,A=E/S.subdivisionStep;for(let B=0;B<=S.subdivisionStep;B++){const I=B*T,O=B%S.subdivisionStep===0;p(M,I,0,I,E,O?2*C:C)}for(let B=0;B<=S.subdivisionStep;B++){const I=B*A,O=B%S.subdivisionStep===0;p(M,0,I,v,I,O?2*C:C)}}return M.createPattern(u,"repeat")}function g(x){let b=s.value.colWidth,S=s.value.rowHeight;const C=o.value.subdivisionStep,v=l.value.width,E=l.value.height,M=r.value.left,T=r.value.top,A=M+v/r.value.zoom,B=T+E/r.value.zoom;let I=b*C,O=S*C,z=0,$=0,J=Number.POSITIVE_INFINITY,j=Number.POSITIVE_INFINITY;for(;;){I=C*b,O=C*S,z=Math.floor(M/I)*I,$=Math.floor(T/O)*O;const ot=Math.ceil(A/I)*I,ft=Math.ceil(B/O)*O;if(j=Math.round((ot-z)/b),J=Math.round((ft-$)/S),Math.max(j,J)>125)b*=2,S*=2;else break}const K=b*r.value.zoom,W=S*r.value.zoom,X=Math.max(1,Math.round(K)),ne=Math.max(1,Math.round(W)),ce=h(X,ne,o.value);if(!ce)return;ce.setTransform(new DOMMatrix().scale(K/X,W/ne));const be=(z-M-b/2)*r.value.zoom,Oe=($-T-S/2)*r.value.zoom;x.save(),x.translate(be,Oe),x.fillStyle=ce,x.fillRect(0,0,v+I*r.value.zoom,E+O*r.value.zoom),x.restore()}function y(x){let b=s.value.colWidth,S=s.value.rowHeight;const C=o.value.subdivisionStep,v=l.value.width,E=l.value.height,M=r.value.left,T=r.value.top,A=M+v/r.value.zoom,B=T+E/r.value.zoom;let I=b*C,O=S*C,z=0,$=0,J=Number.POSITIVE_INFINITY,j=Number.POSITIVE_INFINITY;for(;;){I=C*b,O=C*S,z=Math.floor(M/I)*I,$=Math.floor(T/O)*O;const ot=Math.ceil(A/I)*I,ft=Math.ceil(B/O)*O;if(j=Math.round((ot-z)/b),J=Math.round((ft-$)/S),Math.max(j,J)>200)b*=2,S*=2;else break}const K=b*r.value.zoom,W=S*r.value.zoom,X=Math.max(1,Math.round(K)),ne=Math.max(1,Math.round(W)),ce=m(X,ne,o.value);if(!ce)return;ce.setTransform(new DOMMatrix().scale(K/X,W/ne));const be=(z-M)*r.value.zoom,Oe=($-T)*r.value.zoom;x.save(),x.translate(be,Oe),x.fillStyle=ce,x.fillRect(0,0,v+I*r.value.zoom,E+O*r.value.zoom),x.restore()}function k(){const x=d.value;if(!x)return;const b=x.getContext("2d");if(!b)return;const{width:S,height:C}=l.value;S===0||C===0||(x.width=S,x.height=C,b.clearRect(0,0,S,C),b.fillStyle=o.value.color,b.fillRect(0,0,S,C),o.value.kind==="dots"?g(b):o.value.kind==="grid"&&y(b))}return a.watch(()=>[o.value,r.value,s.value,l.value],()=>{k()},{deep:!0}),a.onMounted(()=>{const x=i==null?void 0:i.value;if(x){const b=()=>{l.value={width:x.clientWidth,height:x.clientHeight}};b(),c=new ResizeObserver(b),c.observe(x)}k()}),a.onUnmounted(()=>{c==null||c.disconnect()}),(x,b)=>(a.openBlock(),a.createElementBlock("canvas",{ref_key:"canvasRef",ref:d,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none"}},null,512))}}),sm=a.defineComponent({__name:"FileDropZone",props:{maxSize:{default:400}},setup(n){const e=n,{nextEditorTick:t,getEditor:o}=le(),{createImageBlock:r}=ka(),s=a.ref(!1);let i=0;function l(){var S;return((S=o())==null?void 0:S.readonly)===!0}const c=a.inject("containerRef");function d(S){var C;l()||(C=S.dataTransfer)!=null&&C.types.some(v=>v==="Files"||v==="text/uri-list"||v==="text/html")&&(i++,i===1&&(s.value=!0))}function u(){i--,i===0&&(s.value=!1)}function f(){i=0,s.value=!1}a.onMounted(()=>{const S=c==null?void 0:c.value;S&&(S.addEventListener("dragenter",d),S.addEventListener("dragleave",u),S.addEventListener("drop",f))}),a.onUnmounted(()=>{const S=c==null?void 0:c.value;S&&(S.removeEventListener("dragenter",d),S.removeEventListener("dragleave",u),S.removeEventListener("drop",f))});function h(S){S.preventDefault(),S.dataTransfer&&(S.dataTransfer.dropEffect="copy")}function p(S){S.preventDefault()}function m(S){S.preventDefault()}async function g(S){if(S.preventDefault(),l()||!S.dataTransfer)return;const C=S.clientX,v=S.clientY,E=Array.from(S.dataTransfer.files).filter(T=>T.type.startsWith("image/"));if(E.length>0){for(const T of E)await x(T,C,v);return}const M=y(S.dataTransfer);M&&await b(M,C,v)}function y(S){const C=S.getData("text/uri-list");if(C){const T=C.split(`
|
|
107
107
|
`).filter(A=>!A.startsWith("#")).find(A=>k(A));if(T)return T}const v=S.getData("text/html");if(v){const M=v.match(/<img[^>]+src=["']([^"']+)["']/i);if(M!=null&&M[1])return M[1]}const E=S.getData("text/plain");return E&&k(E)?E:null}function k(S){try{const v=new URL(S).pathname.toLowerCase();return/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i.test(v)||S.startsWith("data:image/"),!0}catch{return!1}}async function x(S,C,v){const E=await t(),M=w.Camera.read(E),T=w.Screen.read(E),A=M.left+(C-T.left)/M.zoom,B=M.top+(v-T.top)/M.zoom;await r(S,A,B,{maxSize:e.maxSize})}async function b(S,C,v){try{const E=await fetch(S);if(!E.ok){console.warn("Failed to fetch image from URL:",S);return}const M=await E.blob();if(!M.type.startsWith("image/")){console.warn("URL did not return an image:",S);return}const A=new URL(S).pathname.split("/").pop()||"image",B=new File([M],A,{type:M.type});await x(B,C,v)}catch(E){console.warn("Failed to load image from URL:",S,E)}}return(S,C)=>(a.openBlock(),a.createElementBlock("div",{class:a.normalizeClass(["wov-image-drop-zone",{"wov-drag-over":s.value}]),onDragover:h,onDragenter:p,onDragleave:m,onDrop:g},null,34))}});function im(n,e){if(e.length===0)return new Set;const t=e[0].tag,o=n.blockDefs[t];if(!o)return new Set;const r=new Set(o.components.map(s=>s.name));for(let s=1;s<e.length;s++){const i=e[s].tag,l=n.blockDefs[i];if(!l){r.clear();break}const c=new Set(l.components.map(d=>d.name));for(const d of r)c.has(d)||r.delete(d)}return r}function lm(n,e){return e.length===0?!1:e.every(({tag:t})=>{var o;return((o=n.blockDefs[t])==null?void 0:o.showOperations)??!0})}const am=a.defineComponent({__name:"FloatingMenuBar",setup(n){const e=a.useSlots(),{reset:t}=zt(),o=a.inject(Mc),{selectedIds:r,commonComponents:s,showOperations:i}=o,l=new Set(["color","text","verticalAlign","penStroke","elbowArrow","arcArrow","shape","tape","image"]),c=a.computed(()=>{const u=[];for(const f of s.value){const h=`button:${f}`;!l.has(f)&&e[h]&&u.push(f)}return u});function d(){t()}return a.onUnmounted(()=>{t()}),(u,f)=>(a.openBlock(),a.createElementBlock("div",{class:"wov-floating-menu-bar",onMouseleave:d},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(c.value,h=>a.renderSlot(u.$slots,`button:${h}`,{key:h,entityIds:a.unref(r)})),128)),a.unref(s).has("color")?a.renderSlot(u.$slots,"button:color",{key:0,entityIds:a.unref(r)},()=>[a.createVNode(Wp,{entityIds:a.unref(r)},null,8,["entityIds"])]):a.createCommentVNode("",!0),a.unref(s).has("shape")?a.renderSlot(u.$slots,"button:shape",{key:1,entityIds:a.unref(r)},()=>[a.createVNode(Gp,{entityIds:a.unref(r)},null,8,["entityIds"]),a.createVNode(Jp,{entityIds:a.unref(r)},null,8,["entityIds"]),a.createVNode(Yp,{entityIds:a.unref(r)},null,8,["entityIds"])]):a.createCommentVNode("",!0),a.unref(s).has("penStroke")?a.renderSlot(u.$slots,"button:penStroke",{key:2,entityIds:a.unref(r)},()=>[a.createVNode(qp,{entityIds:a.unref(r)},null,8,["entityIds"])]):a.createCommentVNode("",!0),a.unref(s).has("elbowArrow")||a.unref(s).has("arcArrow")?(a.openBlock(),a.createElementBlock(a.Fragment,{key:3},[a.renderSlot(u.$slots,"button:arrowThickness",{entityIds:a.unref(r)},()=>[a.createVNode(zp,{entityIds:a.unref(r)},null,8,["entityIds"])]),a.renderSlot(u.$slots,"button:arrowHeadStart",{entityIds:a.unref(r)},()=>[a.createVNode(Oa,{entityIds:a.unref(r),side:"start"},null,8,["entityIds"])]),a.renderSlot(u.$slots,"button:arrowHeadEnd",{entityIds:a.unref(r)},()=>[a.createVNode(Oa,{entityIds:a.unref(r),side:"end"},null,8,["entityIds"])])],64)):a.createCommentVNode("",!0),a.unref(s).has("image")?a.renderSlot(u.$slots,"button:image",{key:4,entityIds:a.unref(r)},()=>[a.createVNode(Fp,{entityIds:a.unref(r)},null,8,["entityIds"])]):a.createCommentVNode("",!0),a.unref(s).has("tape")?a.renderSlot(u.$slots,"button:tape",{key:5,entityIds:a.unref(r)},()=>[a.createVNode(Xp,{entityIds:a.unref(r)},null,8,["entityIds"])]):a.createCommentVNode("",!0),a.unref(s).has("text")?a.renderSlot(u.$slots,"button:text",{key:6,entityIds:a.unref(r),showVerticalAlign:a.unref(s).has("verticalAlign")},()=>[a.createVNode(om,{entityIds:a.unref(r),showVerticalAlign:a.unref(s).has("verticalAlign")},null,8,["entityIds","showVerticalAlign"])]):a.createCommentVNode("",!0),a.unref(i)?(a.openBlock(),a.createElementBlock(a.Fragment,{key:7},[f[0]||(f[0]=a.createElementVNode("div",{class:"wov-divider",divider:""},null,-1)),a.renderSlot(u.$slots,"button:operations",{entityIds:a.unref(r)},()=>[a.createVNode(Hp)])],64)):a.createCommentVNode("",!0)],32))}}),pE={class:"wov-floating-menu-inner"},cm=a.defineComponent({__name:"FloatingMenu",setup(n){const e=a.inject(we),t=ip([w.Block,w.Selected]),o=Me(w.Camera),r=Me(w.Screen),s=Me(w.SelectionStateSingleton),i=Pn(),l=a.computed(()=>t.value.map(M=>M.entityId)),c=a.computed(()=>t.value.map(M=>({tag:M.block.value.tag}))),d=a.computed(()=>{const M=e==null?void 0:e.getEditor();return M?im(M,c.value):new Set}),u=a.computed(()=>{const M=e==null?void 0:e.getEditor();return M?lm(M,c.value):!1});a.provide(Mc,{selectedIds:l,commonComponents:d,showOperations:u});const f=[0,0,0,0];function h(...M){let T=1/0,A=1/0,B=-1/0,I=-1/0,O=!1;for(const z of M){if(!z)continue;const $=z.getBoundingClientRect();$.width<=0||(O=!0,T=Math.min(T,$.left),A=Math.min(A,$.top),B=Math.max(B,$.right),I=Math.max(I,$.bottom))}return O?{x:T,y:A,left:T,top:A,right:B,bottom:I,width:B-T,height:I-A,toJSON:()=>({})}:null}const p=a.computed(()=>{if(t.value.length===0)return null;const M=o.value;if(!M)return null;let T=null;const A=e==null?void 0:e.getEditor(),B=A==null?void 0:A._getContext();for(const I of t.value){const O=I.block.value,z=B?w.Block.getWorldPosition(B,I.entityId):O.position;ie.Rect.getAabb(z,O.size,O.rotateZ,f),ie.Aabb.translate(f,[-M.left,-M.top]),ie.Aabb.scale(f,M.zoom),T===null?T=ie.Aabb.clone(f):ie.Aabb.union(T,f)}return T}),m=a.inject("containerRef"),g=a.computed(()=>{const M=m==null?void 0:m.value;if(!M)return null;o.value,i.updateCounter.value;const T=i.blockElement.value,A=i.textElement.value,B=h(T,A);if(B)return{getBoundingClientRect:()=>B};const I=p.value;if(!I)return null;const O=M.getBoundingClientRect();return{getBoundingClientRect(){return{x:O.left+I[0],y:O.top+I[1],width:I[2]-I[0],height:I[3]-I[1],top:O.top+I[1],left:O.left+I[0],right:O.left+I[2],bottom:O.top+I[3]}}}}),y=a.ref(null),k={name:"clampToViewport",fn({y:M,rects:T}){const I=window.innerHeight-T.floating.height-8;return{y:Math.max(8,Math.min(M,I))}}},{floatingStyles:x}=mo(g,y,{placement:"top",middleware:[fo(12),po({fallbackPlacements:["bottom"]}),ho({padding:8}),k]}),b=a.computed(()=>{const M=p.value,T=r.value;return!M||!T?!0:M[2]<0||M[0]>T.width||M[3]<0||M[1]>T.height}),S=[w.SelectionState.Dragging,w.SelectionState.SelectionBoxDragging],C=a.computed(()=>t.value.length>0&&!b.value&&!S.includes(s.value.state)),v=a.ref(!1);let E;return a.watch(C,M=>{clearTimeout(E),M?E=setTimeout(()=>{v.value=!0},40):v.value=!1},{immediate:!0}),(M,T)=>(a.openBlock(),a.createBlock(a.Transition,{name:"wov-fade"},{default:a.withCtx(()=>[v.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"floatingRef",ref:y,class:"wov-floating-menu",style:a.normalizeStyle(a.unref(x))},[a.createElementVNode("div",pE,[a.renderSlot(M.$slots,"default",{},()=>[a.createVNode(am)])])],4)):a.createCommentVNode("",!0)]),_:3}))}}),mE={key:0,class:"wov-loading-overlay"},gE={class:"wov-loading-spinner"},dm=a.defineComponent({__name:"LoadingOverlay",props:{isLoading:{type:Boolean}},setup(n){const e=a.ref("|"),t=["|","/","-","\\"];let o=null;return a.onMounted(()=>{o=setInterval(()=>{const r=t.indexOf(e.value);e.value=t[(r+1)%t.length]},100)}),a.onUnmounted(()=>{o!==null&&clearInterval(o)}),(r,s)=>(a.openBlock(),a.createBlock(a.Transition,{name:"wov-loading-fade"},{default:a.withCtx(()=>[n.isLoading?(a.openBlock(),a.createElementBlock("div",mE,[a.createElementVNode("div",gE,a.toDisplayString(e.value),1)])):a.createCommentVNode("",!0)]),_:1}))}}),yE={class:"wov-action-bar"},kE=a.defineComponent({__name:"ActionBar",setup(n){const{getEditor:e}=le(),t=a.inject(we),o=a.ref(!1),r=a.ref(!1);if(t){const c=t.registerTickCallback(d=>{const{store:u}=w.getPluginResources(d,an);o.value=u.canUndo(),r.value=u.canRedo()});a.onUnmounted(c)}function s(){const c=e();c==null||c.command(w.Undo)}function i(){const c=e();c==null||c.command(w.Redo)}function l(){const c=e();c==null||c.command(w.RemoveSelected)}return(c,d)=>(a.openBlock(),a.createElementBlock("div",yE,[a.createElementVNode("button",{class:"wov-action-button",onClick:s,"aria-label":"Undo"},[...d[0]||(d[0]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-undo-icon lucide-undo"},[a.createElementVNode("path",{d:"M3 7v6h6"}),a.createElementVNode("path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"})],-1)])]),a.createElementVNode("button",{class:"wov-action-button",onClick:i,"aria-label":"Redo"},[...d[1]||(d[1]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-redo-icon lucide-redo"},[a.createElementVNode("path",{d:"M21 7v6h-6"}),a.createElementVNode("path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7"})],-1)])]),a.createElementVNode("button",{class:"wov-action-button",onClick:l,"aria-label":"Delete"},[...d[2]||(d[2]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-trash-icon lucide-trash"},[a.createElementVNode("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}),a.createElementVNode("path",{d:"M3 6h18"}),a.createElementVNode("path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})],-1)])])]))}}),nt=a.defineComponent({__name:"ToolbarButton",props:{name:{},tooltip:{},dragOutSnapshot:{},placementSnapshot:{},drawSnapshot:{},cursor:{default:"crosshair"}},setup(n){const e=n,t=a.inject(Mi);if(!t)throw new Error("ToolbarButton must be used within a Toolbar component");const o=t,r=a.ref(null),{show:s,hide:i}=zt(),l=a.computed(()=>o.activeTool.value===e.name);function c(){o.setTool(e.name,{snapshot:e.placementSnapshot,drawSnapshot:e.drawSnapshot,cursor:e.cursor})}function d(){o.onToolPointerDown(e.name,e.dragOutSnapshot)}function u(){o.onToolPointerUp()}function f(){e.tooltip&&r.value&&s(e.tooltip,r.value)}function h(){i()}return(p,m)=>(a.openBlock(),a.createElementBlock("button",{ref_key:"buttonRef",ref:r,class:a.normalizeClass(["wov-toolbar-button",{selected:l.value}]),onClick:c,onPointerdown:d,onPointerup:u,onMouseenter:f,onMouseleave:h},[a.renderSlot(p.$slots,"default")],34))}}),wE='<?xml version="1.0" encoding="UTF-8"?><svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4.35 4.75" width="20" height="20"><defs><style>.cls-1{stroke:#fff;stroke-miterlimit:10;stroke-width:.25px;}</style></defs><path class="cls-1" d="M2.39,2.88s-.04.01-.05.02c-.01,0-.02.01-.03.02,0,.01-.02.02-.03.05l-.77,1.44c-.07.13-.1.19-.14.2-.03.01-.07,0-.1-.01-.03-.02-.05-.09-.09-.23L.16.41c-.03-.13-.05-.19-.03-.23.02-.03.04-.05.08-.06.04,0,.1.02.21.08l3.59,1.94c.13.07.19.1.2.14.01.03,0,.07-.01.1-.02.03-.09.05-.23.09l-1.58.4Z"/></svg>',bE='<?xml version="1.0" encoding="UTF-8"?><svg id="Layer_1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 4.08 4.75" width="24" height="24"><defs><style>.cls-1{fill:#fff;stroke:#000;stroke-linecap:round;stroke-linejoin:round;stroke-width:.25px;}.cls-2{fill:none;stroke:#fff;stroke-miterlimit:10;stroke-width:.51px;}.cls-0{fill:none;stroke:#fff;stroke-linecap:round;stroke-linejoin:round;stroke-width:.6px;}</style></defs><path class="cls-0" d="M.89,2.25v.63M.89,2.25V.75c0-.21.17-.38.38-.38s.38.17.38.38M.89,2.25c0-.21-.17-.37-.38-.37s-.38.17-.38.37v.5c0,1.04.86,1.87,1.91,1.87s1.91-.84,1.91-1.87v-1.25c0-.21-.17-.38-.38-.38s-.38.17.38.38M1.66.75v1.38M1.66.75v-.25c0-.21.17-.38.38-.38s.38.17.38.38v.25M2.42.75v1.38M2.42.75c0-.21.17-.38.38-.38s.38.17.38.38v.75M3.19,1.5v.63"/><path class="cls-1" d="M.89,2.25v.63M.89,2.25V.75c0-.21.17-.38.38-.38s.38.17.38.38M.89,2.25c0-.21-.17-.37-.38-.37s-.38.17-.38.37v.5c0,1.04.86,1.87,1.91,1.87s1.91-.84,1.91-1.87v-1.25c0-.21-.17-.38-.38-.38s-.38.17.38.38M1.66.75v1.38M1.66.75v-.25c0-.21.17-.38.38-.38s.38.17.38.38v.25M2.42.75v1.38M2.42.75c0-.21.17-.38.38-.38s.38.17.38.38v.75M3.19,1.5v.63"/><line class="cls-2" x1="2.8" y1=".77" x2="2.8" y2="2.03"/><line class="cls-2" x1="2.04" y1=".64" x2="2.04" y2="2.02"/><line class="cls-2" x1="1.27" y1=".84" x2="1.27" y2="2.29"/></svg>',SE='<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke-linecap="round" stroke-linejoin="round"><defs><g id="a"><path d="M4 8v-2a2 2 0 0 1 2 -2h2" /><path d="M4 16v2a2 2 0 0 0 2 2h2" /><path d="M16 4h2a2 2 0 0 1 2 2v2" /><path d="M16 20h2a2 2 0 0 0 2 -2v-2" /><path d="M9 12l6 0" /><path d="M12 9l0 6" /></g></defs><use href="#a" stroke="#fff" stroke-width="4.5"/><use href="#a" stroke="#000" stroke-width="2"/></svg>',fn={Select:"select",Hand:"hand",Crosshair:"crosshair"},um={[fn.Select]:{makeSvg:()=>wE,hotspot:[1,0],rotationOffset:0},[fn.Hand]:{makeSvg:()=>bE,hotspot:[12,12],rotationOffset:0},[fn.Crosshair]:{makeSvg:()=>SE,hotspot:[12,12],rotationOffset:0}},xE={viewBox:"0 0 20 20",style:{"fill-rule":"evenodd","clip-rule":"evenodd","stroke-miterlimit":"10"}},fm=a.defineComponent({__name:"SelectTool",setup(n){const{nextEditorTick:e}=le(),{activeTool:t}=js();return a.watch(t,(o,r)=>{r==="select"&&e(s=>{w.DeselectAll.spawn(s)})}),(o,r)=>(a.openBlock(),a.createBlock(nt,{name:"select",tooltip:"Select",cursor:a.unref(fn).Select},{default:a.withCtx(()=>[(a.openBlock(),a.createElementBlock("svg",xE,[...r[0]||(r[0]=[a.createElementVNode("g",{transform:"matrix(4.21053,0,0,4.21053,0.842105,0)"},[a.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-width":"0.5",d:"M2.39,2.88C2.38,2.885 2.34,2.9 2.33,2.91C2.32,2.91 2.298,2.939 2.28,2.97L1.51,4.41C1.44,4.54 1.41,4.6 1.37,4.61C1.34,4.62 1.3,4.61 1.27,4.6C1.24,4.58 1.22,4.51 1.18,4.37L0.16,0.41C0.13,0.28 0.11,0.22 0.13,0.18C0.15,0.15 0.17,0.13 0.21,0.12C0.25,0.12 0.31,0.14 0.42,0.2L4.01,2.14C4.14,2.21 4.2,2.24 4.21,2.28C4.22,2.31 4.21,2.35 4.2,2.38C4.18,2.41 4.11,2.43 3.97,2.47L2.39,2.88Z"})],-1)])]))]),_:1},8,["cursor"]))}}),hm=a.defineComponent({__name:"HandTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(nt,{name:"hand",tooltip:"Hand",cursor:a.unref(fn).Hand},{default:a.withCtx(()=>[...t[0]||(t[0]=[a.createElementVNode("svg",{viewBox:"0 0 20.56 24"},[a.createElementVNode("path",{fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"2",d:"M4.47,11.39v3.18M4.47,11.39V3.81c0-1.06.86-1.92,1.92-1.92s1.92.86,1.92,1.92M4.47,11.39c0-1.06-.86-1.87-1.92-1.87s-1.92.86-1.92,1.87v2.53c0,5.25,4.35,9.45,9.65,9.45s9.65-4.24,9.65-9.45v-6.32c0-1.06-.86-1.92-1.92-1.92s-1.92.86-1.92,1.92M8.36,3.81v6.97M8.36,3.81v-1.26c0-1.06.86-1.92,1.92-1.92s1.92.86,1.92,1.92v1.26M12.2,3.81v6.97M12.2,3.81c0-1.06.86-1.92,1.92-1.92s1.92.86,1.92,1.92v3.79M16.09,7.6v3.18"})],-1)])]),_:1},8,["cursor"]))}}),pm=a.defineComponent({__name:"StickyNoteTool",setup(n){const e=a.inject(we),t=a.computed(()=>JSON.stringify({block:{tag:"sticky-note",size:[200,200]},color:{red:255,green:242,blue:117},text:{defaultAlignment:w.TextAlignment.Center,...e.getDefaults("text")},verticalAlign:{value:w.VerticalAlignment.Center}}));return(o,r)=>(a.openBlock(),a.createBlock(nt,{name:"sticky-note",tooltip:"Sticky Note","drag-out-snapshot":t.value,"placement-snapshot":t.value},{default:a.withCtx(()=>[...r[0]||(r[0]=[a.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[a.createElementVNode("path",{d:"M4 4h12v12H4z"}),a.createElementVNode("path",{d:"M7 8h6M7 11h4"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),mm=a.defineComponent({__name:"ShapeTool",setup(n){const e=a.inject(we),t=a.computed(()=>JSON.stringify({block:{tag:"shape",size:[200,200]},shape:{kind:"rectangle",strokeKind:w.StrokeKind.Solid,strokeWidth:2,strokeRed:0,strokeGreen:0,strokeBlue:0,strokeAlpha:255,fillRed:255,fillGreen:255,fillBlue:255,fillAlpha:0},text:{defaultAlignment:w.TextAlignment.Center,...e.getDefaults("text")},verticalAlign:{value:w.VerticalAlignment.Center}}));return(o,r)=>(a.openBlock(),a.createBlock(nt,{name:"shape",tooltip:"Shape","drag-out-snapshot":t.value,"draw-snapshot":t.value},{default:a.withCtx(()=>[...r[0]||(r[0]=[a.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[a.createElementVNode("rect",{x:"3",y:"3",width:"14",height:"14",rx:"2"})],-1)])]),_:1},8,["drag-out-snapshot","draw-snapshot"]))}}),gm=a.defineComponent({__name:"EraserTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(nt,{name:"eraser",tooltip:"Eraser"},{default:a.withCtx(()=>[...t[0]||(t[0]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor"},[a.createElementVNode("path",{d:"M210.5 480L333.5 480L398.8 414.7L225.3 241.2L98.6 367.9L210.6 479.9zM256 544L210.5 544C193.5 544 177.2 537.3 165.2 525.3L49 409C38.1 398.1 32 383.4 32 368C32 352.6 38.1 337.9 49 327L295 81C305.9 70.1 320.6 64 336 64C351.4 64 366.1 70.1 377 81L559 263C569.9 273.9 576 288.6 576 304C576 319.4 569.9 334.1 559 345L424 480L544 480C561.7 480 576 494.3 576 512C576 529.7 561.7 544 544 544L256 544z"})],-1)])]),_:1}))}}),ym=a.defineComponent({__name:"PenTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(nt,{name:"pen",tooltip:"Pen"},{default:a.withCtx(()=>[...t[0]||(t[0]=[a.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[a.createElementVNode("path",{d:"M13.586 3.586a2 2 0 1 1 2.828 2.828l-8.793 8.793-3.536.707.707-3.536 8.794-8.792Z","stroke-linecap":"round","stroke-linejoin":"round"}),a.createElementVNode("path",{d:"M12 5l3 3","stroke-linecap":"round"})],-1)])]),_:1}))}}),km=a.defineComponent({__name:"TextTool",setup(n){const e=a.inject(we),t=a.computed(()=>JSON.stringify({block:{tag:"text",size:[10,29]},text:{constrainWidth:!1,fontSizePx:24,...e.getDefaults("text")}})),o=a.computed(()=>JSON.stringify({block:{tag:"text",size:[36,29]},text:{content:"text",constrainWidth:!1,fontSizePx:24,...e.getDefaults("text")}}));return(r,s)=>(a.openBlock(),a.createBlock(nt,{name:"text",tooltip:"Text","drag-out-snapshot":o.value,"placement-snapshot":t.value},{default:a.withCtx(()=>[...s[0]||(s[0]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",class:"lucide lucide-type-icon lucide-type"},[a.createElementVNode("path",{d:"M12 4v16"}),a.createElementVNode("path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2"}),a.createElementVNode("path",{d:"M9 20h6"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),wm=a.defineComponent({__name:"ElbowArrowTool",setup(n){const e=JSON.stringify({block:{tag:"elbow-arrow",size:[200,200]},elbowArrow:{points:[0,0,.5,0,.5,1,1,1],pointCount:4,startArrowHead:te.ArrowHeadKind.None,endArrowHead:te.ArrowHeadKind.V},connector:{}});return(t,o)=>(a.openBlock(),a.createBlock(nt,{name:"elbow-arrow",tooltip:"Elbow Arrow",cursor:"crosshair","drag-out-snapshot":a.unref(e)},{default:a.withCtx(()=>[...o[0]||(o[0]=[a.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("path",{d:"M4 6 L10 6 L10 14 L16 14"}),a.createElementVNode("path",{d:"M13 11 L16 14 L13 17"})],-1)])]),_:1},8,["drag-out-snapshot"]))}}),bm=a.defineComponent({__name:"ImageTool",setup(n){const{nextEditorTick:e}=le(),{show:t,hide:o}=zt(),{setTool:r}=js(),{createImageBlock:s}=ka(),i=a.ref(null),l=a.ref(null);function c(){var h;(h=l.value)==null||h.click()}async function d(h){var S;const p=h.target,m=(S=p.files)==null?void 0:S[0];if(!m)return;if(p.value="",!m.type.startsWith("image/")){console.warn("Selected file is not an image");return}const g=await e(),y=w.Camera.read(g),k=w.Screen.read(g),x=y.left+k.width/y.zoom/2,b=y.top+k.height/y.zoom/2;await s(m,x,b),r("select",{cursor:fn.Select})}function u(){i.value&&t("Image",i.value)}function f(){o()}return(h,p)=>(a.openBlock(),a.createElementBlock("button",{ref_key:"buttonRef",ref:i,class:"wov-toolbar-button",onClick:c,onMouseenter:u,onMouseleave:f},[p[0]||(p[0]=a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),a.createElementVNode("circle",{cx:"9",cy:"9",r:"2"}),a.createElementVNode("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})],-1)),a.createElementVNode("input",{ref_key:"fileInputRef",ref:l,type:"file",accept:"image/*",style:{display:"none"},onChange:d},null,544)],544))}}),CE={class:"wov-embed-provider-grid"},EE=["onClick"],vE={class:"wov-embed-provider-icon"},ME={key:0,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},TE={key:1,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},NE={key:2,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},AE={key:3,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},BE={key:4,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},IE={key:5,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},OE={key:6,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},_E={key:7,xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24"},DE={class:"wov-embed-provider-label"},RE={class:"wov-embed-panel-header"},PE={class:"wov-embed-url-form"},LE=["placeholder"],VE={key:0,class:"wov-embed-url-error"},Sm=a.defineComponent({__name:"EmbedTool",setup(n){const{nextEditorTick:e}=le(),{show:t,hide:o}=zt(),{setTool:r}=js(),s=a.ref(null),i=a.ref(null),l=a.ref(null),c=a.ref(!1),d=a.ref(null),u=a.ref(""),f=a.ref(""),h=a.inject("containerRef"),{floatingStyles:p}=mo(s,i,{placement:"top",middleware:[fo(16),po(),ho({padding:8})],whileElementsMounted:ri}),m=[{value:w.EmbedProvider.Youtube,label:"YouTube",icon:"youtube"},{value:w.EmbedProvider.Spotify,label:"Spotify",icon:"spotify"},{value:w.EmbedProvider.GoogleMaps,label:"Google Maps",icon:"map"},{value:w.EmbedProvider.GoogleCalendar,label:"Google Calendar",icon:"calendar"},{value:w.EmbedProvider.GoogleSlides,label:"Google Slides",icon:"slides"},{value:w.EmbedProvider.Figma,label:"Figma",icon:"figma"},{value:w.EmbedProvider.GithubGist,label:"GitHub Gist",icon:"gist"},{value:w.EmbedProvider.Tldraw,label:"tldraw",icon:"tldraw"}],g=a.computed(()=>{if(!d.value)return"Paste a URL...";switch(d.value){case w.EmbedProvider.Youtube:return"https://www.youtube.com/watch?v=...";case w.EmbedProvider.Spotify:return"https://open.spotify.com/track/...";case w.EmbedProvider.GoogleMaps:return"https://www.google.com/maps/...";case w.EmbedProvider.GoogleCalendar:return"https://calendar.google.com/...";case w.EmbedProvider.GoogleSlides:return"https://docs.google.com/presentation/...";case w.EmbedProvider.Figma:return"https://www.figma.com/...";case w.EmbedProvider.GithubGist:return"https://gist.github.com/...";case w.EmbedProvider.Tldraw:return"https://www.tldraw.com/...";default:return"Paste a URL..."}});function y(){c.value=!c.value,d.value=null,u.value="",f.value=""}function k(M){d.value=M,u.value="",f.value="",a.nextTick(()=>{var T;(T=l.value)==null||T.focus()})}function x(){d.value=null,u.value="",f.value=""}async function b(){const M=u.value.trim();if(!M){f.value="Please enter a URL";return}try{new URL(M)}catch{f.value="Please enter a valid URL";return}const T=d.value??w.detectEmbedProvider(M),A=w.validateEmbedUrl(M,T);if(A){f.value=A;return}const B=w.resolveEmbedUrl(M,T);let I=480,O=320;switch(T){case w.EmbedProvider.Youtube:I=560,O=315;break;case w.EmbedProvider.Spotify:I=352,O=152;break;case w.EmbedProvider.GoogleMaps:I=600,O=450;break;case w.EmbedProvider.GoogleCalendar:I=600,O=500;break;case w.EmbedProvider.GoogleSlides:I=640,O=389;break;case w.EmbedProvider.Figma:I=600,O=400;break;case w.EmbedProvider.GithubGist:I=500,O=300;break;case w.EmbedProvider.Tldraw:I=600,O=400;break}const z=await e(),$=w.Camera.read(z),J=w.Screen.read(z),j=$.left+J.width/$.zoom/2,K=$.top+J.height/$.zoom/2,W=w.Grid.read(z);W.enabled&&(I=Math.max(W.colWidth,Math.round(I/W.colWidth)*W.colWidth),O=Math.max(W.rowHeight,Math.round(O/W.rowHeight)*W.rowHeight));const X=w.createEntity(z);w.addComponent(z,X,w.Block);const ne=w.Block.write(z,X);ne.tag="embed",ne.position[0]=j-I/2,ne.position[1]=K-O/2,ne.size[0]=I,ne.size[1]=O,w.Grid.snapPosition(z,ne.position),w.addComponent(z,X,w.Embed);const ce=w.Embed.write(z,X);ce.url=M,ce.embedUrl=B,ce.provider=T,w.addComponent(z,X,Ve.Synced,{id:crypto.randomUUID()}),c.value=!1,d.value=null,u.value="",r("select",{cursor:fn.Select})}function S(M){M.key==="Enter"?(M.preventDefault(),b()):M.key==="Escape"&&(M.preventDefault(),d.value?x():c.value=!1)}function C(M){const T=M.target;s.value&&!s.value.contains(T)&&i.value&&!i.value.contains(T)&&(c.value=!1)}a.watch(c,M=>{M?document.addEventListener("click",C,!0):document.removeEventListener("click",C,!0)});function v(){s.value&&t("Embed",s.value)}function E(){o()}return(M,T)=>{var A;return a.openBlock(),a.createElementBlock(a.Fragment,null,[a.createElementVNode("button",{ref_key:"buttonRef",ref:s,class:a.normalizeClass(["wov-toolbar-button",{"menu-open":c.value}]),onClick:y,onMouseenter:v,onMouseleave:E},[...T[1]||(T[1]=[a.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("path",{d:"M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"}),a.createElementVNode("path",{d:"M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"})],-1)])],34),a.unref(h)?(a.openBlock(),a.createBlock(a.Teleport,{key:0,to:a.unref(h)},[c.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"panelRef",ref:i,class:"wov-embed-panel",style:a.normalizeStyle(a.unref(p))},[d.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[a.createElementVNode("div",RE,[a.createElementVNode("button",{class:"wov-embed-back-button",onClick:x},[...T[11]||(T[11]=[a.createElementVNode("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("polyline",{points:"15 18 9 12 15 6"})],-1)])]),a.createElementVNode("span",null,a.toDisplayString((A=m.find(B=>B.value===d.value))==null?void 0:A.label),1)]),a.createElementVNode("div",PE,[a.withDirectives(a.createElementVNode("input",{ref_key:"urlInputRef",ref:l,"onUpdate:modelValue":T[0]||(T[0]=B=>u.value=B),type:"text",placeholder:g.value,class:"wov-embed-url-input",onKeydown:S},null,40,LE),[[a.vModelText,u.value]]),f.value?(a.openBlock(),a.createElementBlock("div",VE,a.toDisplayString(f.value),1)):a.createCommentVNode("",!0),a.createElementVNode("button",{class:"wov-embed-submit-button",onClick:b}," Embed ")])],64)):(a.openBlock(),a.createElementBlock(a.Fragment,{key:0},[T[10]||(T[10]=a.createElementVNode("div",{class:"wov-embed-panel-header"},"Add embed",-1)),a.createElementVNode("div",CE,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(m,B=>a.createElementVNode("button",{key:B.value,class:"wov-embed-provider-button",onClick:I=>k(B.value)},[a.createElementVNode("span",vE,[B.icon==="youtube"?(a.openBlock(),a.createElementBlock("svg",ME,[...T[2]||(T[2]=[a.createElementVNode("path",{d:"M2.5 17V7a2 2 0 0 1 2-2h15a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2h-15a2 2 0 0 1-2-2z"},null,-1),a.createElementVNode("path",{d:"m10 15 5-3-5-3z"},null,-1)])])):B.icon==="spotify"?(a.openBlock(),a.createElementBlock("svg",TE,[...T[3]||(T[3]=[a.createElementVNode("circle",{cx:"12",cy:"12",r:"10"},null,-1),a.createElementVNode("path",{d:"M8 11.973c2.5-1.473 5.5-.973 7.5.527"},null,-1),a.createElementVNode("path",{d:"M9 15c1.5-1 4-.5 5.5.5"},null,-1),a.createElementVNode("path",{d:"M7 9c3-2 7-1 10 1"},null,-1)])])):B.icon==="map"?(a.openBlock(),a.createElementBlock("svg",NE,[...T[4]||(T[4]=[a.createElementVNode("path",{d:"M12 2C8.13 2 5 5.13 5 9c0 5.25 7 13 7 13s7-7.75 7-13c0-3.87-3.13-7-7-7z"},null,-1),a.createElementVNode("circle",{cx:"12",cy:"9",r:"2.5"},null,-1)])])):B.icon==="calendar"?(a.openBlock(),a.createElementBlock("svg",AE,[...T[5]||(T[5]=[a.createElementVNode("rect",{x:"3",y:"4",width:"18",height:"18",rx:"2",ry:"2"},null,-1),a.createElementVNode("line",{x1:"16",y1:"2",x2:"16",y2:"6"},null,-1),a.createElementVNode("line",{x1:"8",y1:"2",x2:"8",y2:"6"},null,-1),a.createElementVNode("line",{x1:"3",y1:"10",x2:"21",y2:"10"},null,-1)])])):B.icon==="slides"?(a.openBlock(),a.createElementBlock("svg",BE,[...T[6]||(T[6]=[a.createElementVNode("rect",{x:"2",y:"3",width:"20",height:"14",rx:"2",ry:"2"},null,-1),a.createElementVNode("line",{x1:"8",y1:"21",x2:"16",y2:"21"},null,-1),a.createElementVNode("line",{x1:"12",y1:"17",x2:"12",y2:"21"},null,-1)])])):B.icon==="figma"?(a.openBlock(),a.createElementBlock("svg",IE,[...T[7]||(T[7]=[a.createElementVNode("path",{d:"M5 5.5A3.5 3.5 0 0 1 8.5 2H12v7H8.5A3.5 3.5 0 0 1 5 5.5z"},null,-1),a.createElementVNode("path",{d:"M12 2h3.5a3.5 3.5 0 1 1 0 7H12V2z"},null,-1),a.createElementVNode("path",{d:"M12 12.5a3.5 3.5 0 1 1 7 0 3.5 3.5 0 1 1-7 0z"},null,-1),a.createElementVNode("path",{d:"M5 19.5A3.5 3.5 0 0 1 8.5 16H12v3.5a3.5 3.5 0 1 1-7 0z"},null,-1),a.createElementVNode("path",{d:"M5 12.5A3.5 3.5 0 0 1 8.5 9H12v7H8.5A3.5 3.5 0 0 1 5 12.5z"},null,-1)])])):B.icon==="gist"?(a.openBlock(),a.createElementBlock("svg",OE,[...T[8]||(T[8]=[a.createElementVNode("polyline",{points:"16 18 22 12 16 6"},null,-1),a.createElementVNode("polyline",{points:"8 6 2 12 8 18"},null,-1)])])):B.icon==="tldraw"?(a.openBlock(),a.createElementBlock("svg",_E,[...T[9]||(T[9]=[a.createElementVNode("path",{fill:"currentColor",d:"M21.474 0H2.526C1.131 0 0 1.18 0 2.637v18.726C0 22.819 1.131 24 2.526 24h18.948C22.869 24 24 22.82 24 21.363V2.637C24 1.181 22.869 0 21.474 0m-11.01 5.388q.595-.607 1.474-.607q.854 0 1.448.607q.595.606.595 1.476c0 .87-.198 1.072-.595 1.476a1.95 1.95 0 0 1-1.448.607q-.879 0-1.474-.607q-.594-.606-.594-1.476c0-.87.198-1.072.594-1.476m3.13 11.49a4.9 4.9 0 0 1-2.018 2.136q-.724.422-1.19-.026q-.438-.422.26-1.002q.387-.29.646-.738q.258-.449.336-.923q.026-.21-.181-.21q-.517-.027-1.06-.581t-.543-1.37q0-.87.594-1.477a2.02 2.02 0 0 1 1.5-.633q.828 0 1.448.633q.62.605.724 1.37q.207 1.424-.517 2.822z"},null,-1)])])):a.createCommentVNode("",!0)]),a.createElementVNode("span",DE,a.toDisplayString(B.label),1)],8,EE)),64))])],64))],4)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)],64)}}}),$E="https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F7e3b7dde-927d-4b09-aeb4-d49eac36d4ea.png?generation=1715183194653465&alt=media",xm=a.defineComponent({__name:"TapeTool",setup(n){const e=JSON.stringify({block:{tag:"tape",size:[200,30]},tape:{thickness:30},asset:{identifier:$E,uploadState:"complete"}});return(t,o)=>(a.openBlock(),a.createBlock(nt,{name:"tape",tooltip:"Tape","drag-out-snapshot":a.unref(e)},{default:a.withCtx(()=>[...o[0]||(o[0]=[a.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[a.createElementVNode("rect",{x:"1",y:"7",width:"18",height:"6",rx:"1",fill:"none",stroke:"currentColor"}),a.createElementVNode("line",{x1:"5",y1:"7",x2:"3",y2:"13",opacity:"0.4"}),a.createElementVNode("line",{x1:"9",y1:"7",x2:"7",y2:"13",opacity:"0.4"}),a.createElementVNode("line",{x1:"13",y1:"7",x2:"11",y2:"13",opacity:"0.4"}),a.createElementVNode("line",{x1:"17",y1:"7",x2:"15",y2:"13",opacity:"0.4"})],-1)])]),_:1},8,["drag-out-snapshot"]))}}),zE=a.defineComponent({__name:"FrameTool",setup(n){const e=a.computed(()=>JSON.stringify({block:{tag:"frame",size:[400,300]},frame:{label:"Frame"}}));return(t,o)=>(a.openBlock(),a.createBlock(nt,{name:"frame",tooltip:"Frame","drag-out-snapshot":e.value,"draw-snapshot":e.value},{default:a.withCtx(()=>[...o[0]||(o[0]=[a.createElementVNode("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("path",{d:"M3 7V5a2 2 0 0 1 2-2h2"}),a.createElementVNode("path",{d:"M17 3h2a2 2 0 0 1 2 2v2"}),a.createElementVNode("path",{d:"M21 17v2a2 2 0 0 1-2 2h-2"}),a.createElementVNode("path",{d:"M7 21H5a2 2 0 0 1-2-2v-2"})],-1)])]),_:1},8,["drag-out-snapshot","draw-snapshot"]))}}),FE={class:"wov-toolbar-container"},Cm=a.defineComponent({__name:"Toolbar",setup(n){const e=a.useSlots(),{reset:t}=zt(),{nextEditorTick:o}=le(),r=a.ref(null),s=a.ref(null),i=Me(w.Controls),l=a.computed(()=>i.value.activeToolName),c=[fm,hm,km,bm,Sm,mm,zE,wm,pm,xm,ym,gm],d=a.inject("containerRef"),u=a.ref(null),f=a.ref(!1),h=a.ref(null),p=a.ref(null),m=a.ref(1/0),g=a.ref(0),y=a.ref([]),k=a.ref(8),x=a.ref(48),{width:b}=em(d);function S(){return h.value?Array.from(h.value.children).filter(K=>!K.classList.contains("wov-overflow-button")&&!K.classList.contains("wov-menu-tooltip")):[]}function C(){var ne;const K=S();if(K.length===0)return;g.value=K.length;const W=getComputedStyle(h.value);k.value=parseFloat(W.gap)||8;const X=((ne=p.value)==null?void 0:ne.offsetWidth)||40;x.value=X+k.value,y.value=K.map(ce=>ce.offsetWidth)}function v(){if(y.value.length===0)return;const X=b.value-40-20,ne=k.value,ce=x.value;let be=0,Oe=0;for(let ot=0;ot<y.value.length;ot++){const ft=y.value[ot],gn=be>0?ft+ne:ft,vt=y.value.length-ot-1>0?ce:0;if(be+gn+vt<=X)be+=gn,Oe++;else break}m.value=Math.max(1,Oe)}a.watch(b,()=>{y.value.length>0&&v()}),a.onMounted(()=>{a.nextTick(()=>{C(),v()})});const E=a.computed(()=>m.value<g.value);a.watchEffect(()=>{S().forEach((W,X)=>{W.style.display=X<m.value?"":"none"})}),a.watchEffect(()=>{if(!u.value)return;Array.from(u.value.children).forEach((W,X)=>{W.style.display=X>=m.value?"":"none"})});const{floatingStyles:M}=mo(p,u,{placement:"top",middleware:[fo(16),po(),ho({padding:8})],whileElementsMounted:ri});function T(){f.value=!f.value}function A(){f.value=!1}function B(K){const W=K.target;p.value&&!p.value.contains(W)&&u.value&&!u.value.contains(W)&&A()}a.watch(f,K=>{K?document.addEventListener("click",B,!0):document.removeEventListener("click",B,!0)}),a.watch(E,K=>{K||A()});function I(K,W){const{snapshot:X,drawSnapshot:ne,cursor:ce}=W??{};s.value=X??ne??null,o(be=>{const Oe=w.Controls.write(be);Oe.activeToolName=K,ne?(Oe.leftMouseTool="draw",Oe.heldSnapshot=ne):(Oe.leftMouseTool=K,Oe.heldSnapshot=X??""),ce&&w.Cursor.setCursor(be,ce)})}function O(K){o(W=>{const X=w.Controls.write(W);X.leftMouseTool="drag-out",X.heldSnapshot=K})}function z(K,W){r.value=K,s.value=W??null}function $(){r.value=null,s.value=null}function J(){t(),r.value&&s.value&&O(s.value),r.value=null,s.value=null}const j={activeTool:l,heldTool:r,setTool:I,dragOutTool:O,onToolPointerDown:z,onToolPointerUp:$};return a.provide(Mi,j),(K,W)=>(a.openBlock(),a.createElementBlock("div",FE,[a.createVNode(kE),a.createElementVNode("div",{ref_key:"toolsContainerRef",ref:h,class:"wov-toolbar",onMouseleave:J},[a.unref(e).default?a.renderSlot(K.$slots,"default",{key:0}):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},a.renderList(c,(X,ne)=>a.createVNode(a.resolveDynamicComponent(X),{key:ne})),64)),E.value?(a.openBlock(),a.createElementBlock("button",{key:2,ref_key:"overflowBtnRef",ref:p,class:a.normalizeClass(["wov-toolbar-button wov-overflow-button",{"menu-open":f.value}]),onClick:T},[...W[0]||(W[0]=[a.createElementVNode("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[a.createElementVNode("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),a.createElementVNode("line",{x1:"5",y1:"12",x2:"19",y2:"12"})],-1)])],2)):a.createCommentVNode("",!0)],544),a.unref(d)?(a.openBlock(),a.createBlock(a.Teleport,{key:0,to:a.unref(d)},[f.value&&E.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"overflowMenuRef",ref:u,class:"wov-toolbar-overflow-menu",style:a.normalizeStyle(a.unref(M))},[a.unref(e).default?a.renderSlot(K.$slots,"default",{key:0}):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},a.renderList(c,(X,ne)=>a.createVNode(a.resolveDynamicComponent(X),{key:ne})),64))],4)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)]))}}),HE=a.defineComponent({__name:"ArcArrowTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(nt,{name:"arc-arrow",tooltip:"Arc Arrow",cursor:"crosshair"},{default:a.withCtx(()=>[...t[0]||(t[0]=[a.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},[a.createElementVNode("path",{d:"M4 14 Q 10 4, 16 14"}),a.createElementVNode("path",{d:"M13 11 L16 14 L12.5 15.5"})],-1)])]),_:1}))}}),jE={class:"wov-user-presence-avatars"},UE=["src","alt"],WE={class:"wov-user-presence-list"},KE=["src","alt"],qE={class:"wov-user-presence-name"},JE=4,Em=a.defineComponent({__name:"UserPresence",props:{users:{}},setup(n){const e=n,t=a.ref(!1),o=a.ref(null);zC(o,()=>{t.value=!1});function r(l){if(!l)return"?";const c=l.trim().split(/\s+/);return c.length>=2?(c[0][0]+c[1][0]).toUpperCase():l.slice(0,2).toUpperCase()}const s=a.computed(()=>e.users.map(l=>({sessionId:l.sessionId,name:l.name,color:l.color,avatar:l.avatar,initials:r(l.name)}))),i=a.computed(()=>s.value.slice(0,JE));return(l,c)=>n.users.length>1?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"containerRef",ref:o,class:"wov-user-presence"},[a.createElementVNode("button",{class:a.normalizeClass(["wov-user-presence-trigger",{"is-open":t.value}]),onClick:c[0]||(c[0]=d=>t.value=!t.value)},[a.createElementVNode("div",jE,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(i.value,d=>(a.openBlock(),a.createElementBlock("div",{key:d.sessionId,class:"wov-user-avatar",style:a.normalizeStyle({backgroundColor:d.avatar?"transparent":d.color})},[d.avatar?(a.openBlock(),a.createElementBlock("img",{key:0,src:d.avatar,alt:d.name,class:"wov-user-avatar-img"},null,8,UE)):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[a.createTextVNode(a.toDisplayString(d.initials),1)],64))],4))),128))])],2),t.value?(a.openBlock(),a.createElementBlock("div",{key:0,class:"wov-user-presence-dropdown",onWheel:c[1]||(c[1]=a.withModifiers(()=>{},["stop"]))},[a.createElementVNode("div",WE,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(s.value,d=>(a.openBlock(),a.createElementBlock("div",{key:d.sessionId,class:"wov-user-presence-item"},[a.createElementVNode("div",{class:"wov-user-avatar wov-user-avatar-small",style:a.normalizeStyle({backgroundColor:d.avatar?"transparent":d.color})},[d.avatar?(a.openBlock(),a.createElementBlock("img",{key:0,src:d.avatar,alt:d.name,class:"wov-user-avatar-img"},null,8,KE)):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[a.createTextVNode(a.toDisplayString(d.initials),1)],64))],4),a.createElementVNode("span",qE,a.toDisplayString(d.name),1)]))),128))])],32)):a.createCommentVNode("",!0)],512)):a.createCommentVNode("",!0)}}),ja=(n,e)=>e.some(t=>n instanceof t);let vm,Mm;function GE(){return vm||(vm=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function YE(){return Mm||(Mm=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const Ua=new WeakMap,Wa=new WeakMap,ci=new WeakMap;function XE(n){const e=new Promise((t,o)=>{const r=()=>{n.removeEventListener("success",s),n.removeEventListener("error",i)},s=()=>{t(Fn(n.result)),r()},i=()=>{o(n.error),r()};n.addEventListener("success",s),n.addEventListener("error",i)});return ci.set(e,n),e}function QE(n){if(Ua.has(n))return;const e=new Promise((t,o)=>{const r=()=>{n.removeEventListener("complete",s),n.removeEventListener("error",i),n.removeEventListener("abort",i)},s=()=>{t(),r()},i=()=>{o(n.error||new DOMException("AbortError","AbortError")),r()};n.addEventListener("complete",s),n.addEventListener("error",i),n.addEventListener("abort",i)});Ua.set(n,e)}let Ka={get(n,e,t){if(n instanceof IDBTransaction){if(e==="done")return Ua.get(n);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return Fn(n[e])},set(n,e,t){return n[e]=t,!0},has(n,e){return n instanceof IDBTransaction&&(e==="done"||e==="store")?!0:e in n}};function Tm(n){Ka=n(Ka)}function ZE(n){return YE().includes(n)?function(...e){return n.apply(qa(this),e),Fn(this.request)}:function(...e){return Fn(n.apply(qa(this),e))}}function ev(n){return typeof n=="function"?ZE(n):(n instanceof IDBTransaction&&QE(n),ja(n,GE())?new Proxy(n,Ka):n)}function Fn(n){if(n instanceof IDBRequest)return XE(n);if(Wa.has(n))return Wa.get(n);const e=ev(n);return e!==n&&(Wa.set(n,e),ci.set(e,n)),e}const qa=n=>ci.get(n);function tv(n,e,{blocked:t,upgrade:o,blocking:r,terminated:s}={}){const i=indexedDB.open(n,e),l=Fn(i);return o&&i.addEventListener("upgradeneeded",c=>{o(Fn(i.result),c.oldVersion,c.newVersion,Fn(i.transaction),c)}),t&&i.addEventListener("blocked",c=>t(c.oldVersion,c.newVersion,c)),l.then(c=>{s&&c.addEventListener("close",()=>s()),r&&c.addEventListener("versionchange",d=>r(d.oldVersion,d.newVersion,d))}).catch(()=>{}),l}const nv=["get","getKey","getAll","getAllKeys","count"],ov=["put","add","delete","clear"],Ja=new Map;function Nm(n,e){if(!(n instanceof IDBDatabase&&!(e in n)&&typeof e=="string"))return;if(Ja.get(e))return Ja.get(e);const t=e.replace(/FromIndex$/,""),o=e!==t,r=ov.includes(t);if(!(t in(o?IDBIndex:IDBObjectStore).prototype)||!(r||nv.includes(t)))return;const s=async function(i,...l){const c=this.transaction(i,r?"readwrite":"readonly");let d=c.store;return o&&(d=d.index(l.shift())),(await Promise.all([d[t](...l),r&&c.done]))[0]};return Ja.set(e,s),s}Tm(n=>({...n,get:(e,t,o)=>Nm(e,t)||n.get(e,t,o),has:(e,t)=>!!Nm(e,t)||n.has(e,t)}));const rv=["continue","continuePrimaryKey","advance"],Am={},Ga=new WeakMap,Bm=new WeakMap,sv={get(n,e){if(!rv.includes(e))return n[e];let t=Am[e];return t||(t=Am[e]=function(...o){Ga.set(this,Bm.get(this)[e](...o))}),t}};async function*iv(...n){let e=this;if(e instanceof IDBCursor||(e=await e.openCursor(...n)),!e)return;e=e;const t=new Proxy(e,sv);for(Bm.set(t,e),ci.set(t,qa(e));e;)yield t,e=await(Ga.get(t)||e.continue()),Ga.delete(t)}function Im(n,e){return e===Symbol.asyncIterator&&ja(n,[IDBIndex,IDBObjectStore,IDBCursor])||e==="iterate"&&ja(n,[IDBIndex,IDBObjectStore])}Tm(n=>({...n,get(e,t,o){return Im(e,t)?iv:n.get(e,t,o)},has(e,t){return Im(e,t)||n.has(e,t)}}));async function Ya(n,e){const t=await tv(n,1,{upgrade(o){o.objectStoreNames.contains(e)||o.createObjectStore(e)}});return new lv(t,e)}var lv=class{constructor(n,e){this.db=n,this.storeName=e}async get(n){return this.db.get(this.storeName,n)}async put(n,e){await this.db.put(this.storeName,e,n)}async delete(n){await this.db.delete(this.storeName,n)}async getAllEntries(){const e=this.db.transaction(this.storeName,"readonly").objectStore(this.storeName),t=await e.getAllKeys(),o=await e.getAll(),r=[];for(let s=0;s<t.length;s++)r.push([t[s],o[s]]);return r}async clear(){const n=this.db.transaction(this.storeName,"readwrite");n.objectStore(this.storeName).clear(),await n.done}close(){this.db.close()}},av=class{constructor(n){this.jobsStore=null,this.binariesStore=null,this.blobUrls=new Map,this.uploading=new Set,this.uploadPromises=new Map,this.startListeners=new Set,this.completeListeners=new Set,this.errorListeners=new Set,this.persisting=new Set,this.persistStartListeners=new Set,this.persistEndListeners=new Set,this.provider=n.provider,this.documentId=n.documentId,this.maxRetries=n.provider.maxRetries??3,this.retryDelay=n.provider.retryDelay??5e3}onUploadStart(n){return this.startListeners.add(n),()=>{this.startListeners.delete(n)}}onUploadComplete(n){return this.completeListeners.add(n),()=>{this.completeListeners.delete(n)}}onUploadError(n){return this.errorListeners.add(n),()=>{this.errorListeners.delete(n)}}onPersistStart(n){return this.persistStartListeners.add(n),()=>{this.persistStartListeners.delete(n)}}onPersistEnd(n){return this.persistEndListeners.add(n),()=>{this.persistEndListeners.delete(n)}}async init(){const n=`wovencanvas-assets-${this.documentId}`,[e,t]=await Promise.all([Ya(`${n}-jobs`,"jobs"),Ya(`${n}-binaries`,"binaries")]);this.jobsStore=e,this.binariesStore=t}async upload(n,e,t){if(!this.jobsStore||!this.binariesStore)throw new Error("AssetManager not initialized");const o=URL.createObjectURL(e);this.blobUrls.set(n,o),this.persisting.add(n);for(const r of this.persistStartListeners)r(n);try{await this.binariesStore.put(n,e);const r={identifier:n,metadata:t,createdAt:Date.now(),retryCount:0};await this.jobsStore.put(n,r)}finally{this.persisting.delete(n);for(const r of this.persistEndListeners)r(n)}return new Promise((r,s)=>{this.uploadPromises.set(n,{resolve:r,reject:s}),this.startUpload(n)})}async getDisplayUrl(n,e){if(!n)return null;const t=this.blobUrls.get(n);if(t)return t;try{return await this.provider.resolveUrl(n,e)}catch(o){return console.error(`Failed to resolve URL for ${n}:`,o),null}}async resumePendingUploads(){if(!this.jobsStore||!this.binariesStore)throw new Error("AssetManager not initialized");const n=await this.jobsStore.getAllEntries();for(const[e,t]of n){if(this.uploading.has(e))continue;if(!this.blobUrls.has(e)){const r=await this.binariesStore.get(e);r&&this.blobUrls.set(e,URL.createObjectURL(r))}const o=t;o!=null&&o.retryCount&&await this.jobsStore.put(e,{...o,retryCount:0}),this.startUpload(e)}}hasPendingUpload(n){return this.blobUrls.has(n)}isUploading(n){return this.uploading.has(n)}isPersisting(n){return this.persisting.has(n)}get persistingCount(){return this.persisting.size}async cancelUpload(n){if(!this.jobsStore||!this.binariesStore)return;const e=this.blobUrls.get(n);e&&(URL.revokeObjectURL(e),this.blobUrls.delete(n)),await this.jobsStore.delete(n),await this.binariesStore.delete(n),this.uploading.delete(n);const t=this.uploadPromises.get(n);t&&(t.reject(new Error("Upload cancelled")),this.uploadPromises.delete(n))}close(){var n,e;for(const t of this.blobUrls.values())URL.revokeObjectURL(t);this.blobUrls.clear(),(n=this.jobsStore)==null||n.close(),(e=this.binariesStore)==null||e.close(),this.jobsStore=null,this.binariesStore=null}async startUpload(n){if(!this.jobsStore||!this.binariesStore||this.uploading.has(n))return;this.uploading.add(n);const e=await this.jobsStore.get(n),t=await this.binariesStore.get(n);if(!e||!t){this.uploading.delete(n);return}for(const o of this.startListeners)o(n);try{await this.provider.upload(t,n,e.metadata),await this.handleUploadSuccess(n)}catch(o){await this.handleUploadError(n,e,o)}}async handleUploadSuccess(n){if(!this.jobsStore||!this.binariesStore)return;const e=this.blobUrls.get(n);e&&(URL.revokeObjectURL(e),this.blobUrls.delete(n)),await this.jobsStore.delete(n),await this.binariesStore.delete(n),this.uploading.delete(n);for(const o of this.completeListeners)o(n);const t=this.uploadPromises.get(n);t&&(t.resolve(),this.uploadPromises.delete(n))}async handleUploadError(n,e,t){if(!this.jobsStore)return;const o=t instanceof Error?t.message:"Unknown error";if(console.error(`Upload failed for ${n}:`,o),this.uploading.delete(n),e.retryCount<this.maxRetries){const r={...e,retryCount:e.retryCount+1};await this.jobsStore.put(n,r),setTimeout(()=>{this.startUpload(n)},this.retryDelay*2**e.retryCount)}else{const r=t instanceof Error?t:new Error(o);for(const i of this.errorListeners)i(n,r);const s=this.uploadPromises.get(n);s&&(s.reject(r),this.uploadPromises.delete(n))}}},cv="wovencanvas-assets",dv="blobs",uv=class{constructor(){this.store=null,this.initPromise=null,this.maxRetries=3,this.retryDelay=5e3}async upload(n,e,t){return await(await this.getStore()).put(e,{blob:n,metadata:t}),{}}async resolveUrl(n,e){if(n.startsWith("http://")||n.startsWith("https://")||n.startsWith("/"))return n;const o=await(await this.getStore()).get(n);if(!o)throw new Error(`Asset not found: ${n}`);return URL.createObjectURL(o.blob)}async delete(n){await(await this.getStore()).delete(n)}close(){this.store&&(this.store.close(),this.store=null,this.initPromise=null)}getStore(){return this.store?Promise.resolve(this.store):(this.initPromise||(this.initPromise=Ya(cv,dv).then(n=>(this.store=n,n))),this.initPromise)}};const fv=a.defineComponent({__name:"StickyNote",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=fe(e.entityId,w.Color),o=fe(e.entityId,w.VerticalAlign),r=a.ref(null),s={[w.VerticalAlignment.Top]:"flex-start",[w.VerticalAlignment.Center]:"center",[w.VerticalAlignment.Bottom]:"flex-end"},i=a.computed(()=>{var c;return{backgroundColor:t.value?`rgb(${t.value.red}, ${t.value.green}, ${t.value.blue})`:void 0,minHeight:`${e.block.size[0]}px`,alignItems:s[((c=o.value)==null?void 0:c.value)??w.VerticalAlignment.Top]}}),{handleEditEnd:l}=xa({blockData:e,containerRef:r,minWidth:()=>e.block.size[0],minHeight:()=>e.block.size[0]});return(c,d)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:r,class:"wov-sticky-note",style:a.normalizeStyle(i.value)},[a.createVNode(Ks,a.mergeProps(e,{"block-element":r.value,onEditEnd:a.unref(l)}),null,16,["block-element","onEditEnd"])],4))}}),di=Ve.defineCanvasSingleton({name:"blockPlacementState"},{editedCheckpoint:w.field.string().default("").max(36)}),hv=JSON.stringify({block:{tag:"text",size:[10,29]},text:{constrainWidth:!1,fontSizePx:24}}),pr=Ve.defineCanvasSingleton({name:"doubleClickState"},{snapshot:w.field.string().max(1024).default(hv),lastClickTime:w.field.float64().default(0),lastClickWorldX:w.field.float64().default(0),lastClickWorldY:w.field.float64().default(0)}),ut={Idle:"idle",Pointing:"pointing",Drawing:"drawing"},Om=w.defineEditorState("placementDrawState",{state:w.field.string().max(16).default(ut.Idle),activeEntity:w.field.ref(),pointingStartWorld:w.field.tuple(w.field.float64(),2).default([0,0])}),_m=w.defineQuery(n=>n.with(w.Edited));function Dm(n,e,t,o,r){const s=rr(n,e,t);w.PlaceBlockEvent.spawn(n,{entityId:s});const{sessionId:i}=w.getResources(n);w.addComponent(n,s,w.Held,{sessionId:i});const l=w.Block.getWorldPosition(n,s);if(w.canBlockEdit(n,e.block.tag)&&(w.addComponent(n,s,w.EditAfterPlacing,{}),r==="placement")){const{store:f}=w.getPluginResources(n,an),h=f.createCheckpoint();if(h){const p=di.write(n);p.editedCheckpoint=h}}const c=w.SelectionStateSingleton.write(n);c.state=r==="dragOut"?w.SelectionState.Dragging:w.SelectionState.Pointing,c.dragStart=t,c.draggedEntity=s,c.draggedEntityStart=l,c.pointingStartClient=o,c.pointingStartWorld=t,c.isCloning=!1;const d=w.Controls.write(n);d.leftMouseTool="select",d.activeToolName="select",d.heldSnapshot="";const u=w.Cursor.write(n);u.cursorKind="select",u.rotation=0}function pv(n){const e=di.read(n);if(e.editedCheckpoint){const t=e.editedCheckpoint;di.write(n).editedCheckpoint="";const{store:o}=w.getPluginResources(n,an);o.onSettled(()=>o.squashToCheckpoint(t),{frames:5})}}const mv=w.defineEditorSystem({phase:"capture"},n=>{if(w.isReadonly(n))return;_m.removed(n).length>0&&_m.current(n).length===0&&pv(n);const e=w.Controls.read(n);if(!e.heldSnapshot||e.leftMouseTool==="draw")return;const t=w.getPointerInput(n,[w.PointerButton.Left]);if(t.length===0)return;const o=pa(e.heldSnapshot);if(!o)return;const{getDefaults:r}=w.getPluginResources(n,an),s=Yh(o,r);if(e.leftMouseTool==="drag-out"){const l=t.find(c=>c.type==="pointerMove"&&!c.obscured);if(!l)return;Dm(n,s,l.worldPosition,l.screenPosition,"dragOut")}else{const l=t.find(c=>c.type==="pointerDown"&&!c.obscured);if(!l)return;Dm(n,s,l.worldPosition,l.screenPosition,"placement")}}),gv=400,yv=10,kv=w.defineEditorSystem({phase:"capture"},n=>{var f,h;if(w.isReadonly(n))return;const e=pr.read(n);if(!e.snapshot)return;const t=w.Controls.read(n);if(t.leftMouseTool!=="select"||t.heldSnapshot)return;const o=w.getPointerInput(n,[w.PointerButton.Left]);if(o.length===0)return;const r=o.find(p=>p.type==="click"&&!p.obscured);if(!r||r.intersects.some(p=>!w.hasComponent(n,p,w.Frame)))return;const i=performance.now(),l=i-e.lastClickTime,c=r.worldPosition[0]-e.lastClickWorldX,d=r.worldPosition[1]-e.lastClickWorldY,u=Math.sqrt(c*c+d*d);if(l<gv&&u<yv){let p;try{p=JSON.parse(e.snapshot)}catch{return}if(!((f=p.block)!=null&&f.tag))return;const{getDefaults:m}=w.getPluginResources(n,an),g=Yh(p,m),{editor:y}=w.getResources(n);if(!(g.block.tag in y.blockDefs))return;const k=rr(n,g,r.worldPosition);if(w.PlaceBlockEvent.spawn(n,{entityId:k}),w.hasComponent(n,k,w.Text)&&!w.Text.read(n,k).fontFamily){const S=(h=y.fonts[0])==null?void 0:h.name;S&&(w.Text.write(n,k).fontFamily=S)}w.addComponent(n,k,w.Selected,{}),w.canBlockEdit(n,g.block.tag)&&w.addComponent(n,k,w.EditAfterPlacing,{});const x=pr.write(n);x.lastClickTime=0,x.lastClickWorldX=0,x.lastClickWorldY=0}else{const p=pr.write(n);p.lastClickTime=i,p.lastClickWorldX=r.worldPosition[0],p.lastClickWorldY=r.worldPosition[1]}});function wv(){if(typeof globalThis<"u")return globalThis;if(typeof self<"u")return self;if(typeof window<"u")return window;if(typeof global<"u")return global}function bv(){const n=wv();if(n.__xstate__)return n.__xstate__}const Sv=n=>{if(typeof window>"u")return;const e=bv();e&&e.register(n)};class Rm{constructor(e){this._process=e,this._active=!1,this._current=null,this._last=null}start(){this._active=!0,this.flush()}clear(){this._current&&(this._current.next=null,this._last=this._current)}enqueue(e){const t={value:e,next:null};if(this._current){this._last.next=t,this._last=t;return}this._current=t,this._last=t,this._active&&this.flush()}flush(){for(;this._current;){const e=this._current;this._process(e.value),this._current=e.next}this._last=null}}const Pm=".",xv="",Lm="",Cv="#",Ev="*",Vm="xstate.init",vv="xstate.error",Xa="xstate.stop";function Mv(n,e){return{type:`xstate.after.${n}.${e}`}}function Qa(n,e){return{type:`xstate.done.state.${n}`,output:e}}function Tv(n,e){return{type:`xstate.done.actor.${n}`,output:e,actorId:n}}function $m(n,e){return{type:`xstate.error.actor.${n}`,error:e,actorId:n}}function zm(n){return{type:Vm,input:n}}function Et(n){setTimeout(()=>{throw n})}const Nv=typeof Symbol=="function"&&Symbol.observable||"@@observable";function Fm(n,e){const t=Hm(n),o=Hm(e);return typeof o=="string"?typeof t=="string"?o===t:!1:typeof t=="string"?t in o:Object.keys(t).every(r=>r in o?Fm(t[r],o[r]):!1)}function Za(n){if(Wm(n))return n;const e=[];let t="";for(let o=0;o<n.length;o++){switch(n.charCodeAt(o)){case 92:t+=n[o+1],o++;continue;case 46:e.push(t),t="";continue}t+=n[o]}return e.push(t),e}function Hm(n){if(cM(n))return n.value;if(typeof n!="string")return n;const e=Za(n);return Av(e)}function Av(n){if(n.length===1)return n[0];const e={};let t=e;for(let o=0;o<n.length-1;o++)if(o===n.length-2)t[n[o]]=n[o+1];else{const r=t;t={},r[n[o]]=t}return e}function jm(n,e){const t={},o=Object.keys(n);for(let r=0;r<o.length;r++){const s=o[r];t[s]=e(n[s],s,n,r)}return t}function Um(n){return Wm(n)?n:[n]}function hn(n){return n===void 0?[]:Um(n)}function ec(n,e,t,o){return typeof n=="function"?n({context:e,event:t,self:o}):n}function Wm(n){return Array.isArray(n)}function Bv(n){return n.type.startsWith("xstate.error.actor")}function go(n){return Um(n).map(e=>typeof e>"u"||typeof e=="string"?{target:e}:e)}function Km(n){if(!(n===void 0||n===xv))return hn(n)}function tc(n,e,t){var s,i,l;const o=typeof n=="object",r=o?n:void 0;return{next:(s=o?n.next:n)==null?void 0:s.bind(r),error:(i=o?n.error:e)==null?void 0:i.bind(r),complete:(l=o?n.complete:t)==null?void 0:l.bind(r)}}function qm(n,e){return`${e}.${n}`}function nc(n,e){const t=e.match(/^xstate\.invoke\.(\d+)\.(.*)/);if(!t)return n.implementations.actors[e];const[,o,r]=t,i=n.getStateNodeById(r).config.invoke;return(Array.isArray(i)?i[o]:i).src}function Iv(n,e){if(e===n||e===Ev)return!0;if(!e.endsWith(".*"))return!1;const t=e.split("."),o=n.split(".");for(let r=0;r<t.length;r++){const s=t[r],i=o[r];if(s==="*")return r===t.length-1;if(s!==i)return!1}return!0}function Jm(n,e){return`${n.sessionId}.${e}`}let Ov=0;function _v(n,e){const t=new Map,o=new Map,r=new WeakMap,s=new Set,i={},{clock:l,logger:c}=e,d={schedule:(h,p,m,g,y=Math.random().toString(36).slice(2))=>{const k={source:h,target:p,event:m,delay:g,id:y,startedAt:Date.now()},x=Jm(h,y);f._snapshot._scheduledEvents[x]=k;const b=l.setTimeout(()=>{delete i[x],delete f._snapshot._scheduledEvents[x],f._relay(h,p,m)},g);i[x]=b},cancel:(h,p)=>{const m=Jm(h,p),g=i[m];delete i[m],delete f._snapshot._scheduledEvents[m],g!==void 0&&l.clearTimeout(g)},cancelAll:h=>{for(const p in f._snapshot._scheduledEvents){const m=f._snapshot._scheduledEvents[p];m.source===h&&d.cancel(h,m.id)}}},u=h=>{if(!s.size)return;const p={...h,rootId:n.sessionId};s.forEach(m=>{var g;return(g=m.next)==null?void 0:g.call(m,p)})},f={_snapshot:{_scheduledEvents:((e==null?void 0:e.snapshot)&&e.snapshot.scheduler)??{}},_bookId:()=>`x:${Ov++}`,_register:(h,p)=>(t.set(h,p),h),_unregister:h=>{t.delete(h.sessionId);const p=r.get(h);p!==void 0&&(o.delete(p),r.delete(h))},get:h=>o.get(h),getAll:()=>Object.fromEntries(o.entries()),_set:(h,p)=>{const m=o.get(h);if(m&&m!==p)throw new Error(`Actor with system ID '${h}' already exists.`);o.set(h,p),r.set(p,h)},inspect:h=>{const p=tc(h);return s.add(p),{unsubscribe(){s.delete(p)}}},_sendInspectionEvent:u,_relay:(h,p,m)=>{f._sendInspectionEvent({type:"@xstate.event",sourceRef:h,actorRef:p,event:m}),p._send(m)},scheduler:d,getSnapshot:()=>({_scheduledEvents:{...f._snapshot._scheduledEvents}}),start:()=>{const h=f._snapshot._scheduledEvents;f._snapshot._scheduledEvents={};for(const p in h){const{source:m,target:g,event:y,delay:k,id:x}=h[p];d.schedule(m,g,y,k,x)}},_clock:l,_logger:c};return f}let oc=!1;const rc=1;let We=function(n){return n[n.NotStarted=0]="NotStarted",n[n.Running=1]="Running",n[n.Stopped=2]="Stopped",n}({});const Dv={clock:{setTimeout:(n,e)=>setTimeout(n,e),clearTimeout:n=>clearTimeout(n)},logger:console.log.bind(console),devTools:!1};class Rv{constructor(e,t){this.logic=e,this._snapshot=void 0,this.clock=void 0,this.options=void 0,this.id=void 0,this.mailbox=new Rm(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=We.NotStarted,this._parent=void 0,this._syncSnapshot=void 0,this.ref=void 0,this._actorScope=void 0,this.systemId=void 0,this.sessionId=void 0,this.system=void 0,this._doneEvent=void 0,this.src=void 0,this._deferred=[];const o={...Dv,...t},{clock:r,logger:s,parent:i,syncSnapshot:l,id:c,systemId:d,inspect:u}=o;this.system=i?i.system:_v(this,{clock:r,logger:s}),u&&!i&&this.system.inspect(tc(u)),this.sessionId=this.system._bookId(),this.id=c??this.sessionId,this.logger=(t==null?void 0:t.logger)??this.system._logger,this.clock=(t==null?void 0:t.clock)??this.system._clock,this._parent=i,this._syncSnapshot=l,this.options=o,this.src=o.src??e,this.ref=this,this._actorScope={self:this,id:this.id,sessionId:this.sessionId,logger:this.logger,defer:f=>{this._deferred.push(f)},system:this.system,stopChild:f=>{if(f._parent!==this)throw new Error(`Cannot stop child actor ${f.id} of ${this.id} because it is not a child`);f._stop()},emit:f=>{const h=this.eventListeners.get(f.type),p=this.eventListeners.get("*");if(!h&&!p)return;const m=[...h?h.values():[],...p?p.values():[]];for(const g of m)try{g(f)}catch(y){Et(y)}},actionExecutor:f=>{const h=()=>{if(this._actorScope.system._sendInspectionEvent({type:"@xstate.action",actorRef:this,action:{type:f.type,params:f.params}}),!f.exec)return;const p=oc;try{oc=!0,f.exec(f.info,f.params)}finally{oc=p}};this._processingStatus===We.Running?h():this._deferred.push(h)}},this.send=this.send.bind(this),this.system._sendInspectionEvent({type:"@xstate.actor",actorRef:this}),d&&(this.systemId=d,this.system._set(d,this)),this._initState((t==null?void 0:t.snapshot)??(t==null?void 0:t.state)),d&&this._snapshot.status!=="active"&&this.system._unregister(this)}_initState(e){var t;try{this._snapshot=e?this.logic.restoreSnapshot?this.logic.restoreSnapshot(e,this._actorScope):e:this.logic.getInitialSnapshot(this._actorScope,(t=this.options)==null?void 0:t.input)}catch(o){this._snapshot={status:"error",output:void 0,error:o}}}update(e,t){var r,s;this._snapshot=e;let o;for(;o=this._deferred.shift();)try{o()}catch(i){this._deferred.length=0,this._snapshot={...e,status:"error",error:i}}switch(this._snapshot.status){case"active":for(const i of this.observers)try{(r=i.next)==null||r.call(i,e)}catch(l){Et(l)}break;case"done":for(const i of this.observers)try{(s=i.next)==null||s.call(i,e)}catch(l){Et(l)}this._stopProcedure(),this._complete(),this._doneEvent=Tv(this.id,this._snapshot.output),this._parent&&this.system._relay(this,this._parent,this._doneEvent);break;case"error":this._error(this._snapshot.error);break}this.system._sendInspectionEvent({type:"@xstate.snapshot",actorRef:this,event:t,snapshot:e})}subscribe(e,t,o){var s;const r=tc(e,t,o);if(this._processingStatus!==We.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{(s=r.complete)==null||s.call(r)}catch(i){Et(i)}break;case"error":{const i=this._snapshot.error;if(!r.error)Et(i);else try{r.error(i)}catch(l){Et(l)}break}}return{unsubscribe:()=>{this.observers.delete(r)}}}on(e,t){let o=this.eventListeners.get(e);o||(o=new Set,this.eventListeners.set(e,o));const r=t.bind(void 0);return o.add(r),{unsubscribe:()=>{o.delete(r)}}}start(){if(this._processingStatus===We.Running)return this;this._syncSnapshot&&this.subscribe({next:o=>{o.status==="active"&&this.system._relay(this,this._parent,{type:`xstate.snapshot.${this.id}`,snapshot:o})},error:()=>{}}),this.system._register(this.sessionId,this),this.systemId&&this.system._set(this.systemId,this),this._processingStatus=We.Running;const e=zm(this.options.input);switch(this.system._sendInspectionEvent({type:"@xstate.event",sourceRef:this._parent,actorRef:this,event:e}),this._snapshot.status){case"done":return this.update(this._snapshot,e),this;case"error":return this._error(this._snapshot.error),this}if(this._parent||this.system.start(),this.logic.start)try{this.logic.start(this._snapshot,this._actorScope)}catch(o){return this._snapshot={...this._snapshot,status:"error",error:o},this._error(o),this}return this.update(this._snapshot,e),this.options.devTools&&this.attachDevTools(),this.mailbox.start(),this}_process(e){let t,o;try{t=this.logic.transition(this._snapshot,e,this._actorScope)}catch(r){o={err:r}}if(o){const{err:r}=o;this._snapshot={...this._snapshot,status:"error",error:r},this._error(r);return}this.update(t,e),e.type===Xa&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===We.Stopped?this:(this.mailbox.clear(),this._processingStatus===We.NotStarted?(this._processingStatus=We.Stopped,this):(this.mailbox.enqueue({type:Xa}),this))}stop(){if(this._parent)throw new Error("A non-root actor cannot be stopped directly.");return this._stop()}_complete(){var e;for(const t of this.observers)try{(e=t.complete)==null||e.call(t)}catch(o){Et(o)}this.observers.clear(),this.eventListeners.clear()}_reportError(e){if(!this.observers.size){this._parent||Et(e),this.eventListeners.clear();return}let t=!1;for(const o of this.observers){const r=o.error;t||(t=!r);try{r==null||r(e)}catch(s){Et(s)}}this.observers.clear(),this.eventListeners.clear(),t&&Et(e)}_error(e){this._stopProcedure(),this._reportError(e),this._parent&&this.system._relay(this,this._parent,$m(this.id,e))}_stopProcedure(){return this._processingStatus!==We.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new Rm(this._process.bind(this)),this._processingStatus=We.Stopped,this.system._unregister(this),this)}_send(e){this._processingStatus!==We.Stopped&&this.mailbox.enqueue(e)}send(e){this.system._relay(void 0,this,e)}attachDevTools(){const{devTools:e}=this.options;e&&(typeof e=="function"?e:Sv)(this)}toJSON(){return{xstate$$type:rc,id:this.id}}getPersistedSnapshot(e){return this.logic.getPersistedSnapshot(this._snapshot,e)}[Nv](){return this}getSnapshot(){return this._snapshot}}function ui(n,...[e]){return new Rv(n,e)}function Pv(n,e,t,o,{sendId:r}){const s=typeof r=="function"?r(t,o):r;return[e,{sendId:s},void 0]}function Lv(n,e){n.defer(()=>{n.system.scheduler.cancel(n.self,e.sendId)})}function sc(n){function e(t,o){}return e.type="xstate.cancel",e.sendId=n,e.resolve=Pv,e.execute=Lv,e}function Vv(n,e,t,o,{id:r,systemId:s,src:i,input:l,syncSnapshot:c}){const d=typeof i=="string"?nc(e.machine,i):i,u=typeof r=="function"?r(t):r;let f,h;return d&&(h=typeof l=="function"?l({context:e.context,event:t.event,self:n.self}):l,f=ui(d,{id:u,src:i,parent:n.self,syncSnapshot:c,systemId:s,input:h})),[jn(e,{children:{...e.children,[u]:f}}),{id:r,systemId:s,actorRef:f,src:i,input:h},void 0]}function $v(n,{actorRef:e}){e&&n.defer(()=>{e._processingStatus!==We.Stopped&&e.start()})}function ic(...[n,{id:e,systemId:t,input:o,syncSnapshot:r=!1}={}]){function s(i,l){}return s.type="xstate.spawnChild",s.id=e,s.systemId=t,s.src=n,s.input=o,s.syncSnapshot=r,s.resolve=Vv,s.execute=$v,s}function zv(n,e,t,o,{actorRef:r}){const s=typeof r=="function"?r(t,o):r,i=typeof s=="string"?e.children[s]:s;let l=e.children;return i&&(l={...l},delete l[i.id]),[jn(e,{children:l}),i,void 0]}function Gm(n,e){const t=e.getSnapshot();if(t&&"children"in t)for(const o of Object.values(t.children))Gm(n,o);n.system._unregister(e)}function Fv(n,e){if(e){if(Gm(n,e),e._processingStatus!==We.Running){n.stopChild(e);return}n.defer(()=>{n.stopChild(e)})}}function fi(n){function e(t,o){}return e.type="xstate.stopChild",e.actorRef=n,e.resolve=zv,e.execute=Fv,e}function hi(n,e,t,o){const{machine:r}=o,s=typeof n=="function",i=s?n:r.implementations.guards[typeof n=="string"?n:n.type];if(!s&&!i)throw new Error(`Guard '${typeof n=="string"?n:n.type}' is not implemented.'.`);if(typeof i!="function")return hi(i,e,t,o);const l={context:e,event:t},c=s||typeof n=="string"?void 0:"params"in n?typeof n.params=="function"?n.params({context:e,event:t}):n.params:void 0;return"check"in i?i.check(o,l,i):i(l,c)}function lc(n){return n.type==="atomic"||n.type==="final"}function yo(n){return Object.values(n.states).filter(e=>e.type!=="history")}function mr(n,e){const t=[];if(e===n)return t;let o=n.parent;for(;o&&o!==e;)t.push(o),o=o.parent;return t}function pi(n){const e=new Set(n),t=Xm(e);for(const o of e)if(o.type==="compound"&&(!t.get(o)||!t.get(o).length))eg(o).forEach(r=>e.add(r));else if(o.type==="parallel"){for(const r of yo(o))if(r.type!=="history"&&!e.has(r)){const s=eg(r);for(const i of s)e.add(i)}}for(const o of e){let r=o.parent;for(;r;)e.add(r),r=r.parent}return e}function Ym(n,e){const t=e.get(n);if(!t)return{};if(n.type==="compound"){const r=t[0];if(r){if(lc(r))return r.key}else return{}}const o={};for(const r of t)o[r.key]=Ym(r,e);return o}function Xm(n){const e=new Map;for(const t of n)e.has(t)||e.set(t,[]),t.parent&&(e.has(t.parent)||e.set(t.parent,[]),e.get(t.parent).push(t));return e}function Qm(n,e){const t=pi(e);return Ym(n,Xm(t))}function ac(n,e){return e.type==="compound"?yo(e).some(t=>t.type==="final"&&n.has(t)):e.type==="parallel"?yo(e).every(t=>ac(n,t)):e.type==="final"}const mi=n=>n[0]===Cv;function Hv(n,e){return n.transitions.get(e)||[...n.transitions.keys()].filter(o=>Iv(e,o)).sort((o,r)=>r.length-o.length).flatMap(o=>n.transitions.get(o))}function jv(n){const e=n.config.after;if(!e)return[];const t=r=>{const s=Mv(r,n.id),i=s.type;return n.entry.push(mc(s,{id:i,delay:r})),n.exit.push(sc(i)),i};return Object.keys(e).flatMap(r=>{const s=e[r],i=typeof s=="string"?{target:s}:s,l=Number.isNaN(+r)?r:+r,c=t(l);return hn(i).map(d=>({...d,event:c,delay:l}))}).map(r=>{const{delay:s}=r;return{...pn(n,r.event,r),delay:s}})}function pn(n,e,t){const o=Km(t.target),r=t.reenter??!1,s=qv(n,o),i={...t,actions:hn(t.actions),guard:t.guard,target:s,source:n,reenter:r,eventType:e,toJSON:()=>({...i,source:`#${n.id}`,target:s?s.map(l=>`#${l.id}`):void 0})};return i}function Uv(n){const e=new Map;if(n.config.on)for(const t of Object.keys(n.config.on)){if(t===Lm)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const o=n.config.on[t];e.set(t,go(o).map(r=>pn(n,t,r)))}if(n.config.onDone){const t=`xstate.done.state.${n.id}`;e.set(t,go(n.config.onDone).map(o=>pn(n,t,o)))}for(const t of n.invoke){if(t.onDone){const o=`xstate.done.actor.${t.id}`;e.set(o,go(t.onDone).map(r=>pn(n,o,r)))}if(t.onError){const o=`xstate.error.actor.${t.id}`;e.set(o,go(t.onError).map(r=>pn(n,o,r)))}if(t.onSnapshot){const o=`xstate.snapshot.${t.id}`;e.set(o,go(t.onSnapshot).map(r=>pn(n,o,r)))}}for(const t of n.after){let o=e.get(t.eventType);o||(o=[],e.set(t.eventType,o)),o.push(t)}return e}function Wv(n){const e=[],t=o=>{Object.values(o).forEach(r=>{if(r.config.route&&r.config.id){const s=r.config.id,i=r.config.route.guard,l=(d,u)=>d.event.to!==`#${s}`?!1:i&&typeof i=="function"?i(d,u):!0,c={...r.config.route,guard:l,target:`#${s}`};e.push(pn(n,"xstate.route",c))}r.states&&t(r.states)})};t(n.states),e.length>0&&n.transitions.set("xstate.route",e)}function Kv(n,e){const t=typeof e=="string"?n.states[e]:e?n.states[e.target]:void 0;if(!t&&e)throw new Error(`Initial state node "${e}" not found on parent state node #${n.id}`);const o={source:n,actions:!e||typeof e=="string"?[]:hn(e.actions),eventType:null,reenter:!1,target:t?[t]:[],toJSON:()=>({...o,source:`#${n.id}`,target:t?[`#${t.id}`]:[]})};return o}function qv(n,e){if(e!==void 0)return e.map(t=>{if(typeof t!="string")return t;if(mi(t))return n.machine.getStateNodeById(t);const o=t[0]===Pm;if(o&&!n.parent)return gi(n,t.slice(1));const r=o?n.key+t:t;if(n.parent)try{return gi(n.parent,r)}catch(s){throw new Error(`Invalid transition definition for state node '${n.id}':
|
|
108
108
|
${s.message}`)}else throw new Error(`Invalid target: "${t}" is not a valid target from the root node. Did you mean ".${t}"?`)})}function Zm(n){const e=Km(n.config.target);return e?{target:e.map(t=>typeof t=="string"?gi(n.parent,t):t)}:n.parent.initial}function Hn(n){return n.type==="history"}function eg(n){const e=tg(n);for(const t of e)for(const o of mr(t,n))e.add(o);return e}function tg(n){const e=new Set;function t(o){if(!e.has(o)){if(e.add(o),o.type==="compound")t(o.initial.target[0]);else if(o.type==="parallel")for(const r of yo(o))t(r)}}return t(n),e}function ko(n,e){if(mi(e))return n.machine.getStateNodeById(e);if(!n.states)throw new Error(`Unable to retrieve child state '${e}' from '${n.id}'; no child states exist.`);const t=n.states[e];if(!t)throw new Error(`Child state '${e}' does not exist on '${n.id}'`);return t}function gi(n,e){if(typeof e=="string"&&mi(e))try{return n.machine.getStateNodeById(e)}catch{}const t=Za(e).slice();let o=n;for(;t.length;){const r=t.shift();if(!r.length)break;o=ko(o,r)}return o}function yi(n,e){if(typeof e=="string"){const r=n.states[e];if(!r)throw new Error(`State '${e}' does not exist on '${n.id}'`);return[n,r]}const t=Object.keys(e),o=t.map(r=>ko(n,r)).filter(Boolean);return[n.machine.root,n].concat(o,t.reduce((r,s)=>{const i=ko(n,s);if(!i)return r;const l=yi(i,e[s]);return r.concat(l)},[]))}function Jv(n,e,t,o){const s=ko(n,e).next(t,o);return!s||!s.length?n.next(t,o):s}function Gv(n,e,t,o){const r=Object.keys(e),s=ko(n,r[0]),i=cc(s,e[r[0]],t,o);return!i||!i.length?n.next(t,o):i}function Yv(n,e,t,o){const r=[];for(const s of Object.keys(e)){const i=e[s];if(!i)continue;const l=ko(n,s),c=cc(l,i,t,o);c&&r.push(...c)}return r.length?r:n.next(t,o)}function cc(n,e,t,o){return typeof e=="string"?Jv(n,e,t,o):Object.keys(e).length===1?Gv(n,e,t,o):Yv(n,e,t,o)}function Xv(n){return Object.keys(n.states).map(e=>n.states[e]).filter(e=>e.type==="history")}function mn(n,e){let t=n;for(;t.parent&&t.parent!==e;)t=t.parent;return t.parent===e}function Qv(n,e){const t=new Set(n),o=new Set(e);for(const r of t)if(o.has(r))return!0;for(const r of o)if(t.has(r))return!0;return!1}function ng(n,e,t){const o=new Set;for(const r of n){let s=!1;const i=new Set;for(const l of o)if(Qv(uc([r],e,t),uc([l],e,t)))if(mn(r.source,l.source))i.add(l);else{s=!0;break}if(!s){for(const l of i)o.delete(l);o.add(r)}}return Array.from(o)}function Zv(n){const[e,...t]=n;for(const o of mr(e,void 0))if(t.every(r=>mn(r,o)))return o}function dc(n,e){if(!n.target)return[];const t=new Set;for(const o of n.target)if(Hn(o))if(e[o.id])for(const r of e[o.id])t.add(r);else for(const r of dc(Zm(o),e))t.add(r);else t.add(o);return[...t]}function og(n,e){const t=dc(n,e);if(!t)return;if(!n.reenter&&t.every(r=>r===n.source||mn(r,n.source)))return n.source;const o=Zv(t.concat(n.source));if(o)return o;if(!n.reenter)return n.source.machine.root}function uc(n,e,t){var r;const o=new Set;for(const s of n)if((r=s.target)!=null&&r.length){const i=og(s,t);s.reenter&&s.source===i&&o.add(i);for(const l of e)mn(l,i)&&o.add(l)}return[...o]}function eM(n,e){if(n.length!==e.size)return!1;for(const t of n)if(!e.has(t))return!1;return!0}function tM(n,e,t,o,r){return fc([{target:[...tg(n)],source:n,reenter:!0,actions:[],eventType:null,toJSON:null}],e,t,o,!0,r)}function fc(n,e,t,o,r,s){const i=[];if(!n.length)return[e,i];const l=t.actionExecutor;t.actionExecutor=c=>{i.push(c),l(c)};try{const c=new Set(e._nodes);let d=e.historyValue;const u=ng(n,c,d);let f=e;r||([f,d]=sM(f,o,t,u,c,d,s,t.actionExecutor)),f=bo(f,o,t,u.flatMap(p=>p.actions),s,void 0),f=oM(f,o,t,u,c,s,d,r);const h=[...c];f.status==="done"&&(f=bo(f,o,t,h.sort((p,m)=>m.order-p.order).flatMap(p=>p.exit),s,void 0));try{return d===e.historyValue&&eM(e._nodes,c)?[f,i]:[jn(f,{_nodes:h,historyValue:d}),i]}catch(p){throw p}}finally{t.actionExecutor=l}}function nM(n,e,t,o,r){if(o.output===void 0)return;const s=Qa(r.id,r.output!==void 0&&r.parent?ec(r.output,n.context,e,t.self):void 0);return ec(o.output,n.context,s,t.self)}function oM(n,e,t,o,r,s,i,l){let c=n;const d=new Set,u=new Set;rM(o,i,u,d),l&&u.add(n.machine.root);const f=new Set;for(const h of[...d].sort((p,m)=>p.order-m.order)){r.add(h);const p=[];p.push(...h.entry);for(const m of h.invoke)p.push(ic(m.src,{...m,syncSnapshot:!!m.onSnapshot}));if(u.has(h)){const m=h.initial.actions;p.push(...m)}if(c=bo(c,e,t,p,s,h.invoke.map(m=>m.id)),h.type==="final"){const m=h.parent;let g=(m==null?void 0:m.type)==="parallel"?m:m==null?void 0:m.parent,y=g||h;for((m==null?void 0:m.type)==="compound"&&s.push(Qa(m.id,h.output!==void 0?ec(h.output,c.context,e,t.self):void 0));(g==null?void 0:g.type)==="parallel"&&!f.has(g)&&ac(r,g);)f.add(g),s.push(Qa(g.id)),y=g,g=g.parent;if(g)continue;c=jn(c,{status:"done",output:nM(c,e,t,c.machine.root,y)})}}return c}function rM(n,e,t,o){for(const r of n){const s=og(r,e);for(const l of r.target||[])!Hn(l)&&(r.source!==l||r.source!==s||r.reenter)&&(o.add(l),t.add(l)),wo(l,e,t,o);const i=dc(r,e);for(const l of i){const c=mr(l,s);(s==null?void 0:s.type)==="parallel"&&c.push(s),rg(o,e,t,c,!r.source.parent&&r.reenter?void 0:s)}}}function wo(n,e,t,o){var r;if(Hn(n))if(e[n.id]){const s=e[n.id];for(const i of s)o.add(i),wo(i,e,t,o);for(const i of s)hc(i,n.parent,o,e,t)}else{const s=Zm(n);for(const i of s.target)o.add(i),s===((r=n.parent)==null?void 0:r.initial)&&t.add(n.parent),wo(i,e,t,o);for(const i of s.target)hc(i,n.parent,o,e,t)}else if(n.type==="compound"){const[s]=n.initial.target;Hn(s)||(o.add(s),t.add(s)),wo(s,e,t,o),hc(s,n,o,e,t)}else if(n.type==="parallel")for(const s of yo(n).filter(i=>!Hn(i)))[...o].some(i=>mn(i,s))||(Hn(s)||(o.add(s),t.add(s)),wo(s,e,t,o))}function rg(n,e,t,o,r){for(const s of o)if((!r||mn(s,r))&&n.add(s),s.type==="parallel")for(const i of yo(s).filter(l=>!Hn(l)))[...n].some(l=>mn(l,i))||(n.add(i),wo(i,e,t,n))}function hc(n,e,t,o,r){rg(t,o,r,mr(n,e))}function sM(n,e,t,o,r,s,i,l){let c=n;const d=uc(o,r,s);d.sort((f,h)=>h.order-f.order);let u;for(const f of d)for(const h of Xv(f)){let p;h.history==="deep"?p=m=>lc(m)&&mn(m,f):p=m=>m.parent===f,u??(u={...s}),u[h.id]=Array.from(r).filter(p)}for(const f of d)c=bo(c,e,t,[...f.exit,...f.invoke.map(h=>fi(h.id))],i,void 0),r.delete(f);return[c,u||s]}function iM(n,e){return n.implementations.actions[e]}function sg(n,e,t,o,r,s){const{machine:i}=n;let l=n;for(const c of o){const d=typeof c=="function",u=d?c:iM(i,typeof c=="string"?c:c.type),f={context:l.context,event:e,self:t.self,system:t.system},h=d||typeof c=="string"?void 0:"params"in c?typeof c.params=="function"?c.params({context:l.context,event:e}):c.params:void 0;if(!u||!("resolve"in u)){t.actionExecutor({type:typeof c=="string"?c:typeof c=="object"?c.type:c.name||"(anonymous)",info:f,params:h,exec:u});continue}const p=u,[m,g,y]=p.resolve(t,l,f,h,u,r);l=m,"retryResolve"in p&&(s==null||s.push([p,g])),"execute"in p&&t.actionExecutor({type:p.type,info:f,params:g,exec:p.execute.bind(null,t,g)}),y&&(l=sg(l,e,t,y,r,s))}return l}function bo(n,e,t,o,r,s){const i=s?[]:void 0,l=sg(n,e,t,o,{internalQueue:r,deferredActorIds:s},i);return i==null||i.forEach(([c,d])=>{c.retryResolve(t,l,d)}),l}function pc(n,e,t,o){let r=n;const s=[];function i(d,u,f){t.system._sendInspectionEvent({type:"@xstate.microstep",actorRef:t.self,event:u,snapshot:d[0],_transitions:f}),s.push(d)}if(e.type===Xa)return r=jn(ig(r,e,t),{status:"stopped"}),i([r,[]],e,[]),{snapshot:r,microsteps:s};let l=e;if(l.type!==Vm){const d=l,u=Bv(d),f=lg(d,r);if(u&&!f.length)return r=jn(n,{status:"error",error:d.error}),i([r,[]],d,[]),{snapshot:r,microsteps:s};const h=fc(f,n,t,l,!1,o);r=h[0],i(h,d,f)}let c=!0;for(;r.status==="active";){let d=c?lM(r,l):[];const u=d.length?r:void 0;if(!d.length){if(!o.length)break;l=o.shift(),d=lg(l,r)}const f=fc(d,r,t,l,!1,o);r=f[0],c=r!==u,i(f,l,d)}return r.status!=="active"&&ig(r,l,t),{snapshot:r,microsteps:s}}function ig(n,e,t){return bo(n,e,t,Object.values(n.children).map(o=>fi(o)),[],void 0)}function lg(n,e){return e.machine.getTransitionData(e,n)}function lM(n,e){const t=new Set,o=n._nodes.filter(lc);for(const r of o)e:for(const s of[r].concat(mr(r,void 0)))if(s.always){for(const i of s.always)if(i.guard===void 0||hi(i.guard,n.context,e,n)){t.add(i);break e}}return ng(Array.from(t),new Set(n._nodes),n.historyValue)}function aM(n,e){const t=pi(yi(n,e));return Qm(n,[...t])}function cM(n){return!!n&&typeof n=="object"&&"machine"in n&&"value"in n}const dM=function(e){return Fm(e,this.value)},uM=function(e){return this.tags.has(e)},fM=function(e){const t=this.machine.getTransitionData(this,e);return!!(t!=null&&t.length)&&t.some(o=>o.target!==void 0||o.actions.length)},hM=function(){const{_nodes:e,tags:t,machine:o,getMeta:r,toJSON:s,can:i,hasTag:l,matches:c,...d}=this;return{...d,tags:Array.from(t)}},pM=function(){return this._nodes.reduce((e,t)=>(t.meta!==void 0&&(e[t.id]=t.meta),e),{})};function ki(n,e){return{status:n.status,output:n.output,error:n.error,machine:e,context:n.context,_nodes:n._nodes,value:Qm(e.root,n._nodes),tags:new Set(n._nodes.flatMap(t=>t.tags)),children:n.children,historyValue:n.historyValue||{},matches:dM,hasTag:uM,can:fM,getMeta:pM,toJSON:hM}}function jn(n,e={}){return ki({...n,...e},n.machine)}function mM(n){if(typeof n!="object"||n===null)return{};const e={};for(const t in n){const o=n[t];Array.isArray(o)&&(e[t]=o.map(r=>({id:r.id})))}return e}function gM(n,e){const{_nodes:t,tags:o,machine:r,children:s,context:i,can:l,hasTag:c,matches:d,getMeta:u,toJSON:f,...h}=n,p={};for(const g in s){const y=s[g];p[g]={snapshot:y.getPersistedSnapshot(e),src:y.src,systemId:y.systemId,syncSnapshot:y._syncSnapshot}}return{...h,context:ag(i),children:p,historyValue:mM(h.historyValue)}}function ag(n){let e;for(const t in n){const o=n[t];if(o&&typeof o=="object")if("sessionId"in o&&"send"in o&&"ref"in o)e??(e=Array.isArray(n)?n.slice():{...n}),e[t]={xstate$$type:rc,id:o.id};else{const r=ag(o);r!==o&&(e??(e=Array.isArray(n)?n.slice():{...n}),e[t]=r)}}return e??n}function yM(n,e,t,o,{event:r,id:s,delay:i},{internalQueue:l}){const c=e.machine.implementations.delays;if(typeof r=="string")throw new Error(`Only event objects may be used with raise; use raise({ type: "${r}" }) instead`);const d=typeof r=="function"?r(t,o):r;let u;if(typeof i=="string"){const f=c&&c[i];u=typeof f=="function"?f(t,o):f}else u=typeof i=="function"?i(t,o):i;return typeof u!="number"&&l.push(d),[e,{event:d,id:s,delay:u},void 0]}function kM(n,e){const{event:t,delay:o,id:r}=e;if(typeof o=="number"){n.defer(()=>{const s=n.self;n.system.scheduler.schedule(s,s,t,o,r)});return}}function mc(n,e){function t(o,r){}return t.type="xstate.raise",t.event=n,t.id=e==null?void 0:e.id,t.delay=e==null?void 0:e.delay,t.resolve=yM,t.execute=kM,t}function wM(n,{machine:e,context:t},o,r){const s=(i,l)=>{if(typeof i=="string"){const c=nc(e,i);if(!c)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const d=ui(c,{id:l==null?void 0:l.id,parent:n.self,syncSnapshot:l==null?void 0:l.syncSnapshot,input:typeof(l==null?void 0:l.input)=="function"?l.input({context:t,event:o,self:n.self}):l==null?void 0:l.input,src:i,systemId:l==null?void 0:l.systemId});return r[d.id]=d,d}else return ui(i,{id:l==null?void 0:l.id,parent:n.self,syncSnapshot:l==null?void 0:l.syncSnapshot,input:l==null?void 0:l.input,src:i,systemId:l==null?void 0:l.systemId})};return(i,l)=>{const c=s(i,l);return r[c.id]=c,n.defer(()=>{c._processingStatus!==We.Stopped&&c.start()}),c}}function bM(n,e,t,o,{assignment:r}){if(!e.context)throw new Error("Cannot assign to undefined `context`. Ensure that `context` is defined in the machine config.");const s={},i={context:e.context,event:t.event,spawn:wM(n,e,t.event,s),self:n.self,system:n.system};let l={};if(typeof r=="function")l=r(i,o);else for(const d of Object.keys(r)){const u=r[d];l[d]=typeof u=="function"?u(i,o):u}const c=Object.assign({},e.context,l);return[jn(e,{context:c,children:Object.keys(s).length?{...e.children,...s}:e.children}),void 0,void 0]}function Un(n){function e(t,o){}return e.type="xstate.assign",e.assignment=n,e.resolve=bM,e}const cg=new WeakMap;function So(n,e,t){let o=cg.get(n);return o?e in o||(o[e]=t()):(o={[e]:t()},cg.set(n,o)),o[e]}const SM={},gr=n=>typeof n=="string"?{type:n}:typeof n=="function"?"resolve"in n?{type:n.type}:{type:n.name}:n;class wi{constructor(e,t){if(this.config=e,this.key=void 0,this.id=void 0,this.type=void 0,this.path=void 0,this.states=void 0,this.history=void 0,this.entry=void 0,this.exit=void 0,this.parent=void 0,this.machine=void 0,this.meta=void 0,this.output=void 0,this.order=-1,this.description=void 0,this.tags=[],this.transitions=void 0,this.always=void 0,this.parent=t._parent,this.key=t._key,this.machine=t._machine,this.path=this.parent?this.parent.path.concat(this.key):[],this.id=this.config.id||[this.machine.id,...this.path].join(Pm),this.type=this.config.type||(this.config.states&&Object.keys(this.config.states).length?"compound":this.config.history?"history":"atomic"),this.description=this.config.description,this.order=this.machine.idMap.size,this.machine.idMap.set(this.id,this),this.states=this.config.states?jm(this.config.states,(o,r)=>new wi(o,{_parent:this,_key:r,_machine:this.machine})):SM,this.type==="compound"&&!this.config.initial)throw new Error(`No initial state specified for compound state node "#${this.id}". Try adding { initial: "${Object.keys(this.states)[0]}" } to the state config.`);this.history=this.config.history===!0?"shallow":this.config.history||!1,this.entry=hn(this.config.entry).slice(),this.exit=hn(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=hn(e.tags).slice()}_initialize(){this.transitions=Uv(this),this.config.always&&(this.always=go(this.config.always).map(e=>pn(this,Lm,e))),Object.keys(this.states).forEach(e=>{this.states[e]._initialize()})}get definition(){return{id:this.id,key:this.key,version:this.machine.version,type:this.type,initial:this.initial?{target:this.initial.target,source:this,actions:this.initial.actions.map(gr),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(e=>`#${e.id}`),source:`#${this.id}`,actions:this.initial.actions.map(gr),eventType:null})}:void 0,history:this.history,states:jm(this.states,e=>e.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(e=>({...e,actions:e.actions.map(gr)})),entry:this.entry.map(gr),exit:this.exit.map(gr),meta:this.meta,order:this.order||-1,output:this.output,invoke:this.invoke,description:this.description,tags:this.tags}}toJSON(){return this.definition}get invoke(){return So(this,"invoke",()=>hn(this.config.invoke).map((e,t)=>{const{src:o,systemId:r}=e,s=e.id??qm(this.id,t),i=typeof o=="string"?o:`xstate.invoke.${qm(this.id,t)}`;return{...e,src:i,id:s,systemId:r,toJSON(){const{onDone:l,onError:c,...d}=e;return{...d,type:"xstate.invoke",src:i,id:s}}}}))}get on(){return So(this,"on",()=>[...this.transitions].flatMap(([t,o])=>o.map(r=>[t,r])).reduce((t,[o,r])=>(t[o]=t[o]||[],t[o].push(r),t),{}))}get after(){return So(this,"delayedTransitions",()=>jv(this))}get initial(){return So(this,"initial",()=>Kv(this,this.config.initial))}next(e,t){const o=t.type,r=[];let s;const i=So(this,`candidates-${o}`,()=>Hv(this,o));for(const l of i){const{guard:c}=l,d=e.context;let u=!1;try{u=!c||hi(c,d,t,e)}catch(f){const h=typeof c=="string"?c:typeof c=="object"?c.type:void 0;throw new Error(`Unable to evaluate guard ${h?`'${h}' `:""}in transition for event '${o}' in state node '${this.id}':
|
|
109
109
|
${f.message}`)}if(u){r.push(...l.actions),s=l;break}}return s?[s]:void 0}get events(){return So(this,"events",()=>{const{states:e}=this,t=new Set(this.ownEvents);if(e)for(const o of Object.keys(e)){const r=e[o];if(r.states)for(const s of r.events)t.add(`${s}`)}return Array.from(t)})}get ownEvents(){const e=Object.keys(Object.fromEntries(this.transitions)),t=new Set(e.filter(o=>this.transitions.get(o).some(r=>!(!r.target&&!r.actions.length&&!r.reenter))));return Array.from(t)}}const xM="#";class gc{constructor(e,t){this.config=e,this.version=void 0,this.schemas=void 0,this.implementations=void 0,this.__xstatenode=!0,this.idMap=new Map,this.root=void 0,this.id=void 0,this.states=void 0,this.events=void 0,this.id=e.id||"(machine)",this.implementations={actors:(t==null?void 0:t.actors)??{},actions:(t==null?void 0:t.actions)??{},delays:(t==null?void 0:t.delays)??{},guards:(t==null?void 0:t.guards)??{}},this.version=this.config.version,this.schemas=this.config.schemas,this.transition=this.transition.bind(this),this.getInitialSnapshot=this.getInitialSnapshot.bind(this),this.getPersistedSnapshot=this.getPersistedSnapshot.bind(this),this.restoreSnapshot=this.restoreSnapshot.bind(this),this.start=this.start.bind(this),this.root=new wi(e,{_key:this.id,_machine:this}),this.root._initialize(),Wv(this.root),this.states=this.root.states,this.events=this.root.events}provide(e){const{actions:t,guards:o,actors:r,delays:s}=this.implementations;return new gc(this.config,{actions:{...t,...e.actions},guards:{...o,...e.guards},actors:{...r,...e.actors},delays:{...s,...e.delays}})}resolveState(e){const t=aM(this.root,e.value),o=pi(yi(this.root,t));return ki({_nodes:[...o],context:e.context||{},children:{},status:ac(o,this.root)?"done":e.status||"active",output:e.output,error:e.error,historyValue:e.historyValue},this)}transition(e,t,o){return pc(e,t,o,[]).snapshot}microstep(e,t,o){return pc(e,t,o,[]).microsteps.map(([r])=>r)}getTransitionData(e,t){return cc(this.root,e.value,e,t)||[]}_getPreInitialState(e,t,o){const{context:r}=this.config,s=ki({context:typeof r!="function"&&r?r:{},_nodes:[this.root],children:{},status:"active"},this);return typeof r=="function"?bo(s,t,e,[Un(({spawn:l,event:c,self:d})=>r({spawn:l,input:c.input,self:d}))],o,void 0):s}getInitialSnapshot(e,t){const o=zm(t),r=[],s=this._getPreInitialState(e,o,r),[i]=tM(this.root,s,e,o,r),{snapshot:l}=pc(i,o,e,r);return l}start(e){Object.values(e.children).forEach(t=>{t.getSnapshot().status==="active"&&t.start()})}getStateNodeById(e){const t=Za(e),o=t.slice(1),r=mi(t[0])?t[0].slice(xM.length):t[0],s=this.idMap.get(r);if(!s)throw new Error(`Child state node '#${r}' does not exist on machine '${this.id}'`);return gi(s,o)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(e,t){return gM(e,t)}restoreSnapshot(e,t){const o={},r=e.children;Object.keys(r).forEach(f=>{const h=r[f],p=h.snapshot,m=h.src,g=typeof m=="string"?nc(this,m):m;if(!g)return;const y=ui(g,{id:f,parent:t.self,syncSnapshot:h.syncSnapshot,snapshot:p,src:m,systemId:h.systemId});o[f]=y});function s(f,h){if(h instanceof wi)return h;try{return f.machine.getStateNodeById(h.id)}catch{}}function i(f,h){if(!h||typeof h!="object")return{};const p={};for(const m in h){const g=h[m];for(const y of g){const k=s(f,y);k&&(p[m]??(p[m]=[]),p[m].push(k))}}return p}const l=i(this.root,e.historyValue),c=ki({...e,children:o,_nodes:Array.from(pi(yi(this.root,e.value))),historyValue:l},this),d=new Set;function u(f,h){if(!d.has(f)){d.add(f);for(const p in f){const m=f[p];if(m&&typeof m=="object"){if("xstate$$type"in m&&m.xstate$$type===rc){f[p]=h[m.id];continue}u(m,h)}}}}return u(c.context,o),c}}function CM(n,e,t,o,{event:r}){const s=typeof r=="function"?r(t,o):r;return[e,{event:s},void 0]}function EM(n,{event:e}){n.defer(()=>n.emit(e))}function dg(n){function e(t,o){}return e.type="xstate.emit",e.event=n,e.resolve=CM,e.execute=EM,e}let yc=function(n){return n.Parent="#_parent",n.Internal="#_internal",n}({});function vM(n,e,t,o,{to:r,event:s,id:i,delay:l},c){var m;const d=e.machine.implementations.delays;if(typeof s=="string")throw new Error(`Only event objects may be used with sendTo; use sendTo({ type: "${s}" }) instead`);const u=typeof s=="function"?s(t,o):s;let f;if(typeof l=="string"){const g=d&&d[l];f=typeof g=="function"?g(t,o):g}else f=typeof l=="function"?l(t,o):l;const h=typeof r=="function"?r(t,o):r;let p;if(typeof h=="string"){if(h===yc.Parent?p=n.self._parent:h===yc.Internal?p=n.self:h.startsWith("#_")?p=e.children[h.slice(2)]:p=(m=c.deferredActorIds)!=null&&m.includes(h)?h:e.children[h],!p)throw new Error(`Unable to send event to actor '${h}' from machine '${e.machine.id}'.`)}else p=h||n.self;return[e,{to:p,targetId:typeof h=="string"?h:void 0,event:u,id:i,delay:f},void 0]}function MM(n,e,t){typeof t.to=="string"&&(t.to=e.children[t.to])}function TM(n,e){n.defer(()=>{const{to:t,event:o,delay:r,id:s}=e;if(typeof r=="number"){n.system.scheduler.schedule(n.self,t,o,r,s);return}n.system._relay(n.self,t,o.type===vv?$m(n.self.id,o.data):o)})}function kc(n,e,t){function o(r,s){}return o.type="xstate.sendTo",o.to=n,o.event=e,o.id=t==null?void 0:t.id,o.delay=t==null?void 0:t.delay,o.resolve=vM,o.retryResolve=MM,o.execute=TM,o}function NM(n,e){return kc(yc.Parent,n,e)}function AM(n,e,t,o,{collect:r}){const s=[],i=function(c){s.push(c)};return i.assign=(...l)=>{s.push(Un(...l))},i.cancel=(...l)=>{s.push(sc(...l))},i.raise=(...l)=>{s.push(mc(...l))},i.sendTo=(...l)=>{s.push(kc(...l))},i.sendParent=(...l)=>{s.push(NM(...l))},i.spawnChild=(...l)=>{s.push(ic(...l))},i.stopChild=(...l)=>{s.push(fi(...l))},i.emit=(...l)=>{s.push(dg(...l))},r({context:t.context,event:t.event,enqueue:i,check:l=>hi(l,e.context,t.event,e),self:n.self,system:n.system},o),[e,void 0,s]}function BM(n){function e(t,o){}return e.type="xstate.enqueueActions",e.collect=n,e.resolve=AM,e}function IM(n,e,t,o,{value:r,label:s}){return[e,{value:typeof r=="function"?r(t,o):r,label:s},void 0]}function OM({logger:n},{value:e,label:t}){t?n(t,e):n(e)}function _M(n=({context:t,event:o})=>({context:t,event:o}),e){function t(o,r){}return t.type="xstate.log",t.value=n,t.label=e,t.resolve=IM,t.execute=OM,t}function DM(n,e){return new gc(n,e)}function ug({schemas:n,actors:e,actions:t,guards:o,delays:r}){return{assign:Un,sendTo:kc,raise:mc,log:_M,cancel:sc,stopChild:fi,enqueueActions:BM,emit:dg,spawnChild:ic,createStateConfig:s=>s,createAction:s=>s,createMachine:s=>DM({...s,schemas:n},{actors:e,actions:t,guards:o,delays:r}),extend:s=>ug({schemas:n,actors:e,actions:{...t,...s.actions},guards:{...o,...s.guards},delays:{...r,...s.delays}})}}const RM=4,fg=1,hg="draw",PM=ug({guards:{isThresholdReached:({context:n,event:e})=>ie.Vec2.distance(n.pointingStartWorld,e.worldPosition)*e.cameraZoom>=RM},actions:{setPointingStart:Un({pointingStartWorld:({event:n})=>[n.worldPosition[0],n.worldPosition[1]]}),resetContext:Un({pointingStartWorld:()=>[0,0],activeEntity:()=>null}),addEntity:Un({activeEntity:({context:n,event:e})=>{const t=pa(w.Controls.read(e.ctx).heldSnapshot);if(!t)return null;const o={...t,block:{...t.block,size:[1,1]}},r=rr(e.ctx,o,n.pointingStartWorld);return w.PlaceBlockEvent.spawn(e.ctx,{entityId:r}),r}}),drawEntity:({context:n,event:e})=>{if(!n.activeEntity)return;const t=[n.pointingStartWorld[0],n.pointingStartWorld[1]],o=[e.worldPosition[0],e.worldPosition[1]];w.Grid.snapPosition(e.ctx,t),w.Grid.snapPosition(e.ctx,o);const r=Math.min(t[0],o[0]),s=Math.min(t[1],o[1]),i=Math.max(Math.abs(o[0]-t[0]),1),l=Math.max(Math.abs(o[1]-t[1]),1),c=w.Block.write(e.ctx,n.activeEntity);c.size=[i,l],w.Block.setWorldPosition(e.ctx,n.activeEntity,[r,s])},completeEntity:({context:n,event:e})=>{if(!n.activeEntity)return;const t=w.Block.read(e.ctx,n.activeEntity);if(t.size[0]<fg||t.size[1]<fg){w.removeEntity(e.ctx,n.activeEntity);return}w.selectBlock(e.ctx,n.activeEntity)},removeEntity:Un({activeEntity:({context:n,event:e})=>(n.activeEntity&&w.removeEntity(e.ctx,n.activeEntity),null)}),placeEntity:({context:n,event:e})=>{const t=pa(w.Controls.read(e.ctx).heldSnapshot);if(!t)return;const o=rr(e.ctx,t,n.pointingStartWorld);w.PlaceBlockEvent.spawn(e.ctx,{entityId:o}),w.selectBlock(e.ctx,o)},exitToSelect:({event:n})=>{const e=w.Controls.write(n.ctx);e.leftMouseTool="select",e.activeToolName="select",e.heldSnapshot="";const t=w.Cursor.write(n.ctx);t.cursorKind="select"},deselectAll:({event:n})=>{w.DeselectAll.spawn(n.ctx)}}}).createMachine({id:"drawPlacement",initial:ut.Idle,context:{activeEntity:null,pointingStartWorld:[0,0]},states:{[ut.Idle]:{entry:"resetContext",on:{pointerDown:{actions:"deselectAll",target:ut.Pointing}}},[ut.Pointing]:{entry:"setPointingStart",on:{pointerMove:{guard:"isThresholdReached",target:ut.Drawing},pointerUp:{actions:["placeEntity","exitToSelect"],target:ut.Idle},cancel:{target:ut.Idle}}},[ut.Drawing]:{entry:"addEntity",on:{pointerMove:{actions:"drawEntity"},pointerUp:{actions:["completeEntity","exitToSelect"],target:ut.Idle},cancel:{actions:"removeEntity",target:ut.Idle}}}}}),LM=w.defineEditorSystem({phase:"capture",priority:100},n=>{if(w.isReadonly(n))return;const e=w.Controls.read(n);if(e.leftMouseTool!==hg||!e.heldSnapshot)return;const t=w.Controls.getButtons(n,hg);if(t.length===0)return;const o=w.getPointerInput(n,t);o.length!==0&&Om.run(n,PM,o)}),VM=w.defineEditorSystem({phase:"update"},n=>{if(w.isReadonly(n))return;const{store:e}=w.getPluginResources(n,an);w.on(n,w.Undo,()=>{e.canUndo()&&(w.deselectAll(n),e.undo())}),w.on(n,w.Redo,()=>{e.canRedo()&&(w.deselectAll(n),e.redo())})}),$M=[{name:"Figtree",displayName:"Figtree",url:"https://fonts.googleapis.com/css2?family=Figtree",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/Figtree.png"},{name:"Shantell Sans",displayName:"Shantell Sans",url:"https://fonts.googleapis.com/css2?family=Shantell+Sans",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/ShantellSans.png"},{name:"Courier Prime",displayName:"Courier Prime",url:"https://fonts.googleapis.com/css2?family=Courier+Prime",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/CourierPrime.png"},{name:"EB Garamond",displayName:"EB Garamond",url:"https://fonts.googleapis.com/css2?family=EB+Garamond",previewImage:"https://storage.googleapis.com/scrolly-page-fonts/EBGaramond.png"}];function pg(n){return{name:an,resources:{store:n.store,getDefaults:n.getDefaults},singletons:[di,pr,Om],systems:[mv,LM,kv,VM],setup(e){n.doubleClickSnapshot&&(pr.write(e).snapshot=n.doubleClickSnapshot)},cursors:um,fonts:$M,keybinds:[{command:w.Undo.name,key:w.Key.Z,mod:!0},{command:w.Redo.name,key:w.Key.Y,mod:!0},{command:w.Redo.name,key:w.Key.Z,mod:!0,shift:!0}]}}const zM=a.defineComponent({__name:"ClipboardHandler",props:{options:{}},setup(n){const e=n,t=a.inject("containerRef",a.ref(null));return lS(t,e.options),(o,r)=>a.renderSlot(o.$slots,"default")}}),FM={class:"wov-user-cursors"},HM={class:"wov-cursor-svg",viewBox:"0 0 4.35 4.75",width:"20",height:"20"},jM=["fill"],UM="M2.39,2.88s-.04.01-.05.02c-.01,0-.02.01-.03.02,0,.01-.02.02-.03.05l-.77,1.44c-.07.13-.1.19-.14.2-.03.01-.07,0-.1-.01-.03-.02-.05-.09-.09-.23L.16.41c-.03-.13-.05-.19-.03-.23.02-.03.04-.05.08-.06.04,0,.1.02.21.08l3.59,1.94c.13.07.19.1.2.14.01.03,0,.07-.01.1-.02.03-.09.05-.23.09l-1.58.4Z",WM=a.defineComponent({__name:"UserCursors",props:{users:{},currentSessionId:{},camera:{}},setup(n){const e=n,t=a.computed(()=>e.users.filter(o=>o.sessionId!==e.currentSessionId).map(o=>({...o,screenX:(o.position[0]-e.camera.left)*e.camera.zoom,screenY:(o.position[1]-e.camera.top)*e.camera.zoom})));return(o,r)=>(a.openBlock(),a.createElementBlock("div",FM,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(t.value,s=>(a.openBlock(),a.createElementBlock("div",{key:s.sessionId,class:"wov-user-cursor",style:a.normalizeStyle({transform:`translate(${s.screenX}px, ${s.screenY}px)`})},[(a.openBlock(),a.createElementBlock("svg",HM,[a.createElementVNode("path",{fill:s.color,stroke:"#fff","stroke-miterlimit":"10","stroke-width":".25",d:UM},null,8,jM)])),a.createElementVNode("span",{class:"wov-cursor-label",style:a.normalizeStyle({backgroundColor:s.color})},a.toDisplayString(s.name),5)],4))),128))]))}}),KM={key:0,class:"wov-offline-indicator"},qM=a.defineComponent({__name:"OfflineIndicator",props:{isOnline:{type:Boolean}},setup(n){return(e,t)=>n.isOnline?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",KM,"Working Offline"))}}),JM={key:0,class:"wov-version-mismatch-overlay"},GM=a.defineComponent({__name:"VersionMismatch",props:{versionMismatch:{type:Boolean}},setup(n){function e(){window.location.reload()}return(t,o)=>n.versionMismatch?(a.openBlock(),a.createElementBlock("div",JM,[a.createElementVNode("div",{class:"wov-version-mismatch-dialog"},[o[0]||(o[0]=a.createElementVNode("p",null,"A new version is available.",-1)),o[1]||(o[1]=a.createElementVNode("p",null,"Please refresh the page to continue.",-1)),a.createElementVNode("button",{onClick:e},"Refresh")])])):a.createCommentVNode("",!0)}}),YM=a.defineComponent({__name:"BackToContentButton",setup(n){const{nextEditorTick:e}=le(),t=Me(w.Camera),o=w.defineQuery(d=>d.with(w.Synced,w.Block,w.Aabb)),r=a.ref(0),s=a.inject(we);if(s){const d=s.registerTickCallback(u=>{o.addedOrRemoved(u).length>0&&(r.value=o.current(u).length)});a.onUnmounted(d)}const i=a.ref(!1);a.watchEffect(()=>{i.value=!t.value.canSeeBlocks&&r.value>0});function l(d,u,f,h,p){const m=u+h,g=f+p;return d[0]<m&&d[2]>u&&d[1]<g&&d[3]>f}function c(){e(d=>{const u=o.current(d);if(u.length===0)return;let f=Number.POSITIVE_INFINITY,h=Number.POSITIVE_INFINITY,p=Number.NEGATIVE_INFINITY,m=Number.NEGATIVE_INFINITY;for(const B of u){const I=w.Aabb.read(d,B);f=Math.min(f,I.value[0]),h=Math.min(h,I.value[1]),p=Math.max(p,I.value[2]),m=Math.max(m,I.value[3])}const g=w.Screen.read(d),y=w.Camera.read(d),k=w.getPluginResources(d,Ci.CONTROLS_PLUGIN_NAME)??Ci.DEFAULT_CONTROLS_OPTIONS;let x=Math.min(g.width/(p-f),g.height/(m-h));x/=1.1,x=Math.min(x,y.zoom),x=Math.max(k.minZoom,Math.min(k.maxZoom,x));const b=(f+p)/2,S=(h+m)/2;let C=b-g.width/x/2,v=S-g.height/x/2;const E=g.width/x,M=g.height/x;let T=!1;for(const B of u){const I=w.Aabb.read(d,B);if(l(I.value,C,v,E,M)){T=!0;break}}if(!T){const B=Math.floor(Math.random()*u.length),I=u[B],O=w.Aabb.read(d,I),z=(O.value[0]+O.value[2])/2,$=(O.value[1]+O.value[3])/2;C=z-E/2,v=$-M/2}const A=w.Camera.write(d);A.left=C,A.top=v,A.zoom=x})}return(d,u)=>i.value?(a.openBlock(),a.createElementBlock("button",{key:0,class:"wov-back-to-content",onClick:c},[...u[0]||(u[0]=[a.createElementVNode("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[a.createElementVNode("path",{d:"M10 12L6 8L10 4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1),a.createTextVNode(" Back to content ",-1)])])):a.createCommentVNode("",!0)}}),XM=["data-entity-id","data-selected","data-held-by-other","data-hovered","data-edited"],QM=a.defineComponent({__name:"WovenCanvasCore",props:{store:{},editor:{},background:{},assetProvider:{},pluginOptions:{},controls:{},doubleClickSnapshot:{},copyPaste:{},initialState:{},omitBlockTags:{},textOptions:{},autoRender:{type:Boolean,default:!0}},emits:["ready"],async setup(n,{expose:e,emit:t}){var kg,wg,bg;let o,r;const s={"selection-box":Qc,"transform-box":yp,"transform-handle":kp,"arrow-handle":Nc,"arrow-terminal":Ac,"sticky-note":fv,eraser:qc,"pen-stroke":Xc,"arc-arrow":Tc,"elbow-arrow":Bc,text:gp,image:Yc,shape:pp,embed:Ic,tape:mp,frame:Jc},i=w.defineQuery(N=>N.tracking(w.Block)),l=w.defineQuery(N=>N.with(w.Asset)),c=w.defineQuery(N=>N.with(w.Block).tracking(w.Connector)),d=w.defineQuery(N=>N.with(w.Block).tracking(w.Selected)),u=w.defineQuery(N=>N.with(w.Block).tracking(w.Held)),f=w.defineQuery(N=>N.with(w.Block).tracking(w.Hovered)),h=w.defineQuery(N=>N.with(w.Block).tracking(w.Edited)),p=w.defineQuery(N=>N.with(w.Block).tracking(w.Opacity)),m=w.defineQuery(N=>N.tracking(w.User)),g=w.defineQuery(N=>N.tracking(w.Layer)),y=n,k=a.computed(()=>new Set(y.omitBlockTags??[])),x=[{stratum:"background",class:"wov-canvas-background"},{stratum:"content",class:"wov-canvas-content"},{stratum:"overlay",class:"wov-canvas-overlay"}],b=t,S=a.ref(null),C=a.shallowRef(null),v=w.UserData.parse(((kg=y.editor)==null?void 0:kg.user)??{}),E=new Set,M=new Map,T=a.shallowRef([]),A=new Map,B=new Map,I=new Set,O=new Map,z=a.shallowRef([]),$=a.ref(!0),J=a.ref(!1),j=a.ref(!1);function K(){var N;if(typeof navigator<"u"&&!navigator.onLine){$.value=!1;return}if(!((N=y.store)!=null&&N.websocket)){$.value=!0;return}if(!j.value){$.value=!0;return}$.value=J.value}const W=a.ref(!1),X=a.ref(!y.initialState);a.watch($,N=>{N||(X.value=!1)});const ne=a.shallowRef(w.Camera.default());function ce(N,F,D){let H=A.get(N);H||(H=new Map,A.set(N,H));let L=H.get(F);return L||(L=new Set,H.set(F,L)),L.add(D),()=>{L.delete(D),L.size===0&&(H.delete(F),H.size===0&&A.delete(N))}}function be(N,F,D,H=!1){const L=A.get(F);if(!L)return;const R=L.get(D.name);if(!R||R.size===0)return;let G=null;H||(G=D.snapshot(N,F));for(const oe of R)oe(G)}function Oe(N,F){let D=B.get(N);return D||(D=new Set,B.set(N,D)),D.add(F),()=>{D.delete(F),D.size===0&&B.delete(N)}}function ot(N,F){const D=B.get(F.name);if(!D||D.size===0)return;const H=F.snapshot(N);for(const L of D)L(H)}function ft(N){return I.add(N),()=>{I.delete(N)}}function gn(){return v.sessionId}function yr(N){return M.get(N)??null}const Wn={hasEntity:N=>E.has(N),getEditor:()=>C.value,getAssetManager:()=>De,getSessionId:gn,getUserBySessionId:yr,subscribeComponent:ce,subscribeSingleton:Oe,registerTickCallback:ft,defaults:a.reactive({}),setDefaults(N,F){this.defaults[N]={...this.defaults[N],...F}},getDefaults(N){return this.defaults[N]??{}}};a.provide(we,Wn),a.provide("containerRef",S),a.provide(vi,a.computed(()=>y.textOptions??{})),cS(N=>{var F;(F=C.value)==null||F.nextTick(N)});let vt=0,Mt=null,_e=null;const eT=((bg=(wg=y.store)==null?void 0:wg.persistence)==null?void 0:bg.documentId)??"default";let De=new av({provider:y.assetProvider??new uv,documentId:eT});function tT(N){var H;const F=[],D=y.pluginOptions;return(D==null?void 0:D.controls)!==!1&&F.push(Ci.CanvasControlsPlugin((D==null?void 0:D.controls)??{})),(D==null?void 0:D.eraser)!==!1&&F.push(Sr.createEraserPlugin((D==null?void 0:D.eraser)||void 0)),(D==null?void 0:D.pen)!==!1&&F.push(yn.createPenPlugin()),(D==null?void 0:D.arrows)!==!1&&F.push(te.createArrowsPlugin((D==null?void 0:D.arrows)||void 0)),(D==null?void 0:D.tapes)!==!1&&F.push(Bg.createTapesPlugin()),F.push(pg({store:N,doubleClickSnapshot:y.doubleClickSnapshot,getDefaults:L=>Wn.getDefaults(L)})),(H=y.editor)!=null&&H.plugins&&F.push(...y.editor.plugins),F}function nT(){const N=y.store??{},F={history:!0,...N};return N.websocket&&(F.websocket={...N.websocket,onVersionMismatch:D=>{var H,L;W.value=!0,(L=(H=N.websocket)==null?void 0:H.onVersionMismatch)==null||L.call(H,D)},onConnectivityChange:D=>{var H,L;J.value=D,K(),(L=(H=N.websocket)==null?void 0:H.onConnectivityChange)==null||L.call(H,D)},onSync:()=>{var D,H;X.value=!1,(H=(D=N.websocket)==null?void 0:D.onSync)==null||H.call(D)}}),F}async function mg(N,F){const D=nT();N||(delete D.persistence,delete D.websocket),F&&(D.initialState=F),_e=new Ve.CanvasStore(D);const H={...y.editor,user:v,plugins:tT(_e),controls:y.controls},L=new w.Editor(N,H);return await L.initialize(),await _e.initialize({components:L.components,singletons:L.singletons}),L}async function bi(N){N.nextTick(F=>{_e&&_e.sync(F),rT(F),sT(F);for(const D of I)D(F)}),await N.tick()}async function wc(){!C.value||!_e||(await bi(C.value),y.autoRender!==!1?Mt=requestAnimationFrame(wc):Mt=null)}async function oT(){!C.value||!_e||await bi(C.value)}if(e({render:oT}),a.watch(()=>y.autoRender,N=>{N===!1?Mt!==null&&(cancelAnimationFrame(Mt),Mt=null):Mt===null&&C.value&&_e&&(Mt=requestAnimationFrame(wc))}),Oe(w.Camera.name,N=>{N&&(ne.value=N)}),y.initialState&&typeof window>"u"){const N=([o,r]=a.withAsyncContext(()=>mg(null,y.initialState)),o=await o,r(),o);[o,r]=a.withAsyncContext(()=>bi(N)),await o,r(),[o,r]=a.withAsyncContext(()=>bi(N)),await o,r(),C.value=N}let gg=null;const Si=()=>{K()};let bc=null;a.onMounted(async()=>{var D,H,L;if(!S.value)return;K(),window.addEventListener("online",Si),window.addEventListener("offline",Si),gg=()=>{var R;(R=S.value)==null||R.scrollTo(0,0)},S.value.addEventListener("scroll",gg),C.value&&(C.value.dispose(),_e==null||_e.close(),_e=null,vt=0);const N=await mg(S.value,y.initialState);if(C.value=N,_e.isSynced&&(X.value=!1),await(De==null?void 0:De.init()),De){const R=(G,oe)=>{N.nextTick(re=>{for(const Tt of l.current(re))w.Asset.read(re,Tt).identifier===G&&w.Asset.patch(re,Tt,{uploadState:oe})})};De.onUploadStart(G=>R(G,w.UploadState.Uploading)),De.onUploadComplete(G=>R(G,w.UploadState.Complete)),De.onUploadError(G=>R(G,w.UploadState.Failed))}await(De==null?void 0:De.resumePendingUploads()),a.watch($,(R,G)=>{R&&!G&&(De==null||De.resumePendingUploads().catch(oe=>console.error("Failed to resume uploads:",oe)))}),bc=setTimeout(()=>{j.value=!0,K()},3e3),y.autoRender!==!1&&(Mt=requestAnimationFrame(wc));const F=(L=(H=(D=C.value)==null?void 0:D.fonts)==null?void 0:H[0])==null?void 0:L.name;F&&Wn.setDefaults("text",{fontFamily:F}),b("ready",C.value,_e)}),a.onUnmounted(()=>{var N;Mt!==null&&cancelAnimationFrame(Mt),bc!==null&&clearTimeout(bc),window.removeEventListener("online",Si),window.removeEventListener("offline",Si),De==null||De.close(),_e==null||_e.close(),(N=C.value)==null||N.dispose()});function rT(N){const{events:F,newIndex:D}=N.eventBuffer.readEvents(vt);if(vt=D,F.length===0)return;const{componentsById:H,singletonsById:L}=w.getResources(N);for(const{entityId:R,eventType:G,componentId:oe}of F){if(R===w.SINGLETON_ENTITY_ID){if(G===w.EventType.CHANGED){const re=L.get(oe);re&&ot(N,re)}continue}if(G===w.EventType.ADDED)E.add(R);else if(G===w.EventType.REMOVED)E.delete(R),A.delete(R);else if(G===w.EventType.COMPONENT_ADDED){E.add(R);const re=H.get(oe);re&&be(N,R,re)}else if(G===w.EventType.COMPONENT_REMOVED){const re=H.get(oe);re&&be(N,R,re,!0)}else if(G===w.EventType.CHANGED){const re=H.get(oe);re&&be(N,R,re)}}}function sT(N){var H;let F=!1;for(const L of i.added(N)){const R=w.Block.snapshot(N,L),G=(H=C.value)==null?void 0:H.blockDefs[R.tag],oe=(G==null?void 0:G.stratum)??"content";O.set(L,a.ref({entityId:L,block:R,stratum:oe,selected:!1,held:null,hovered:!1,edited:!1,opacity:null,connector:null})),F=!0}for(const L of i.removed(N))O.delete(L),F=!0;for(const L of i.changed(N)){const R=O.get(L);if(R){const G=w.Block.snapshot(N,L);(R.value.block.rank!==G.rank||R.value.block.parentId!==G.parentId||R.value.block.layerId!==G.layerId)&&(F=!0),R.value.block=G}}(g.addedOrChanged(N).length>0||g.removed(N).length>0)&&(F=!0);let D=!1;for(const L of m.addedOrChanged(N)){const R=w.User.snapshot(N,L);M.set(R.sessionId,R),D=!0}for(const L of m.removed(N)){const R=w.User.read(N,L);M.delete(R.sessionId),D=!0}D&&(T.value=Array.from(M.values()));for(const L of d.added(N)){const R=O.get(L);R&&!R.value.selected&&(R.value.selected=!0)}for(const L of d.removed(N)){const R=O.get(L);R!=null&&R.value.selected&&(R.value.selected=!1)}for(const L of u.addedOrChanged(N)){const R=O.get(L);R&&(R.value.held=w.Held.snapshot(N,L))}for(const L of u.removed(N)){const R=O.get(L);R&&R.value.held!==null&&(R.value.held=null)}for(const L of f.added(N)){const R=O.get(L);R&&!R.value.hovered&&(R.value.hovered=!0)}for(const L of f.removed(N)){const R=O.get(L);R!=null&&R.value.hovered&&(R.value.hovered=!1)}for(const L of h.added(N)){const R=O.get(L);R&&!R.value.edited&&(R.value.edited=!0)}for(const L of h.removed(N)){const R=O.get(L);R!=null&&R.value.edited&&(R.value.edited=!1)}for(const L of p.addedOrChanged(N)){const R=O.get(L);R&&(R.value.opacity=w.Opacity.snapshot(N,L))}for(const L of p.removed(N)){const R=O.get(L);R&&R.value.opacity!==null&&(R.value.opacity=null)}for(const L of c.addedOrChanged(N)){const R=O.get(L);R&&(R.value.connector=w.Connector.snapshot(N,L))}for(const L of c.removed(N)){const R=O.get(L);R&&R.value.connector!==null&&(R.value.connector=null)}if(F){const L=Array.from(O.values()),R=G=>{const oe=O.get(G);if(!oe)return null;const re=oe.value;return{rank:re.block.rank,stratum:re.stratum,parentId:re.block.parentId}};L.sort((G,oe)=>{const re={rank:G.value.block.rank,stratum:G.value.stratum,parentId:G.value.block.parentId,layerRank:w.resolveLayerRank(N,G.value.entityId)},Tt={rank:oe.value.block.rank,stratum:oe.value.stratum,parentId:oe.value.block.parentId,layerRank:w.resolveLayerRank(N,oe.value.entityId)};return w.compareBlockOrder(R,re,Tt)}),z.value=L}}function iT(N){const F=N.rotateZ!==0,D=N.flip[0],H=N.flip[1];if(!F&&!D&&!H)return;const L=[];return F&&L.push(`rotate(${N.rotateZ}rad)`),D&&L.push("scaleX(-1)"),H&&L.push("scaleY(-1)"),L.join(" ")}function yg(N){const{held:F}=N;if(!F||!F.sessionId||F.sessionId===v.sessionId)return null;const D=yr(F.sessionId);return(D==null?void 0:D.color)??null}function xi(N,F,D,H){const L=N-H[0],R=F-H[1];if(D.rotateZ===0)return[L,R];const G=D.size[0]/2,oe=D.size[1]/2,re=L-G,Tt=R-oe,kr=Math.cos(-D.rotateZ),wr=Math.sin(-D.rotateZ);return[re*kr-Tt*wr+G,re*wr+Tt*kr+oe]}function Sc(N){let F=N.block.position[0],D=N.block.position[1],H=N.block.parentId;const L=new Set;for(;H!==null&&!L.has(H);){L.add(H);const R=O.get(H);if(!R)break;F+=R.value.block.position[0],D+=R.value.block.position[1],H=R.value.block.parentId}return[F,D]}function lT(N){var D,H;const F=(D=C.value)==null?void 0:D.blockDefs[N];return((H=F==null?void 0:F.components)==null?void 0:H.some(L=>L===w.Frame))??!1}function aT(N){let F=-1/0,D=-1/0,H=1/0,L=1/0,R=N.block.parentId;for(;R!==null;){const G=O.get(R);if(!G)break;if(lT(G.value.block.tag)){const oe=G.value.block,re=Sc(G.value);F=Math.max(F,re[0]),D=Math.max(D,re[1]),H=Math.min(H,re[0]+oe.size[0]),L=Math.min(L,re[1]+oe.size[1])}R=G.value.block.parentId}return F===-1/0?null:[F,D,H,L]}function cT(N){const F=aT(N);if(!F)return;const[D,H,L,R]=F,G=N.block,oe=Sc(N);if(G.rotateZ===0){const Sg=H-oe[1],xg=D-oe[0],Cg=oe[1]+G.size[1]-R,Eg=oe[0]+G.size[0]-L;return Sg<=0&&xg<=0&&Cg<=0&&Eg<=0?void 0:`inset(${Sg}px ${Eg}px ${Cg}px ${xg}px)`}const re=xi(D,H,G,oe),Tt=xi(L,H,G,oe),kr=xi(L,R,G,oe),wr=xi(D,R,G,oe);return`polygon(${re[0]}px ${re[1]}px, ${Tt[0]}px ${Tt[1]}px, ${kr[0]}px ${kr[1]}px, ${wr[0]}px ${wr[1]}px)`}function dT(N){const{block:F,opacity:D}=N,H=yg(N),L=D!==null?D.value/255:1,R=N.edited?void 0:cT(N),G=Sc(N);return{position:"absolute",left:`${G[0]}px`,top:`${G[1]}px`,width:`${F.size[0]}px`,height:`${F.size[1]}px`,transform:iT(F),opacity:L,pointerEvents:"none",userSelect:"none","--wov-held-by-color":H??void 0,transition:L===1?"opacity 0ms 32ms":void 0,clipPath:R}}return(N,F)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:S,class:"wov-root",style:{position:"relative",width:"100%",height:"100%",overflow:"hidden"}},[n.background?a.renderSlot(N.$slots,"background",{key:0,background:n.background},()=>[a.createVNode(rm,{background:n.background},null,8,["background"])]):a.createCommentVNode("",!0),(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(x,D=>(a.openBlock(),a.createElementBlock(a.Fragment,{key:D.class},[D.stratum==="content"?a.renderSlot(N.$slots,"render-layer",{key:0}):a.createCommentVNode("",!0),a.createElementVNode("div",{class:a.normalizeClass(D.class),style:a.normalizeStyle({position:"absolute",transformOrigin:"0 0",transform:`scale(${ne.value.zoom}) translate(${-ne.value.left}px, ${-ne.value.top}px)`,"--wov-zoom":ne.value.zoom})},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(z.value,H=>(a.openBlock(),a.createElementBlock(a.Fragment,{key:H.value.entityId},[H.value.stratum===D.stratum&&!k.value.has(H.value.block.tag)?(a.openBlock(),a.createElementBlock("div",{key:0,"data-entity-id":H.value.entityId,style:a.normalizeStyle(dT(H.value)),"data-selected":H.value.selected||void 0,"data-held-by-other":yg(H.value)!==null||void 0,"data-hovered":H.value.hovered||void 0,"data-edited":H.value.edited||void 0,class:"wov-block"},[a.renderSlot(N.$slots,`block:${H.value.block.tag}`,a.mergeProps({ref_for:!0},H.value),()=>[s[H.value.block.tag]?(a.openBlock(),a.createBlock(a.resolveDynamicComponent(s[H.value.block.tag]),a.mergeProps({key:0,ref_for:!0},H.value),null,16)):a.createCommentVNode("",!0)])],12,XM)):a.createCommentVNode("",!0)],64))),128))],6)],64))),64)),C.value?a.renderSlot(N.$slots,"user-cursors",{key:1,users:T.value,currentSessionId:a.unref(v).sessionId,camera:ne.value},()=>[a.createVNode(WM,{users:T.value,"current-session-id":a.unref(v).sessionId,camera:ne.value},null,8,["users","current-session-id","camera"])]):a.createCommentVNode("",!0),C.value?(a.openBlock(),a.createBlock(cm,{key:2},{default:a.withCtx(D=>[a.renderSlot(N.$slots,"floating-menu",a.normalizeProps(a.guardReactiveProps(D)))]),_:3})):a.createCommentVNode("",!0),C.value?a.renderSlot(N.$slots,"user-presence",{key:3,users:T.value},()=>[a.createVNode(Em,{users:T.value},null,8,["users"])]):a.createCommentVNode("",!0),C.value?a.renderSlot(N.$slots,"toolbar",{key:4},()=>[a.createVNode(Cm)]):a.createCommentVNode("",!0),C.value?a.renderSlot(N.$slots,"default",{key:5}):a.createCommentVNode("",!0),a.renderSlot(N.$slots,"offline-indicator",{isOnline:$.value},()=>[a.createVNode(qM,{"is-online":$.value},null,8,["is-online"])]),a.renderSlot(N.$slots,"version-mismatch",{versionMismatch:W.value},()=>[a.createVNode(GM,{"version-mismatch":W.value},null,8,["version-mismatch"])]),a.renderSlot(N.$slots,"back-to-content",{},()=>[a.createVNode(YM)]),a.renderSlot(N.$slots,"loading",{isLoading:X.value},()=>[a.createVNode(dm,{"is-loading":X.value},null,8,["is-loading"])]),C.value?a.renderSlot(N.$slots,"file-drop-zone",{key:6},()=>[a.createVNode(sm)]):a.createCommentVNode("",!0),C.value?(a.openBlock(),a.createBlock(zM,{key:7,options:y.copyPaste},null,8,["options"])):a.createCommentVNode("",!0),a.createVNode(Kp)],512))}}),ZM=a.defineComponent({inheritAttrs:!1,__name:"WovenCanvas",setup(n,{expose:e}){const t=a.ref(null);return e({render:()=>{var o;return(o=t.value)==null?void 0:o.render()}}),(o,r)=>(a.openBlock(),a.createBlock(a.Suspense,null,{default:a.withCtx(()=>[a.createVNode(QM,a.mergeProps({ref_key:"core",ref:t},o.$attrs),a.createSlots({_:2},[a.renderList(o.$slots,(s,i)=>({name:i,fn:a.withCtx(l=>[a.renderSlot(o.$slots,i,a.normalizeProps(a.guardReactiveProps(l??{})))])}))]),1040)]),_:3}))}});Object.defineProperty(_,"CanvasComponentDef",{enumerable:!0,get:()=>Ve.CanvasComponentDef}),Object.defineProperty(_,"CanvasSingletonDef",{enumerable:!0,get:()=>Ve.CanvasSingletonDef}),Object.defineProperty(_,"CanvasStore",{enumerable:!0,get:()=>Ve.CanvasStore}),Object.defineProperty(_,"Synced",{enumerable:!0,get:()=>Ve.Synced}),Object.defineProperty(_,"defineCanvasComponent",{enumerable:!0,get:()=>Ve.defineCanvasComponent}),Object.defineProperty(_,"defineCanvasSingleton",{enumerable:!0,get:()=>Ve.defineCanvasSingleton}),_.ARROW_HEADS=Ei,_.ArcArrow=Tc,_.ArcArrowTool=HE,_.ArrowHandle=Nc,_.ArrowHead=Nt,_.ArrowHeadButton=Oa,_.ArrowTerminal=Ac,_.ArrowThicknessButton=zp,_.AspectLockButton=Fp,_.BlockOperationsButton=Hp,_.CURSORS=um,_.CanvasBackground=rm,_.ColorButton=Wp,_.ColorPicker=Up,_.CursorKind=fn,_.DEFAULT_FONT_SIZE_OPTIONS=Qp,_.EDITING_PLUGIN_NAME=an,_.EditableText=Ks,_.EditingPlugin=pg,_.ElbowArrow=Bc,_.ElbowArrowTool=wm,_.EmbedBlock=Ic,_.EmbedTool=Sm,_.Eraser=qc,_.EraserTool=gm,_.FileDropZone=sm,_.FloatingMenu=cm,_.FloatingMenuBar=am,_.FrameBlock=Jc,_.HandTool=hm,_.IconChevronDown=Ge,_.ImageBlock=Yc,_.ImageTool=bm,_.LoadingOverlay=dm,_.MenuButton=un,_.MenuDropdown=Ue,_.MenuTooltip=Kp,_.PenStroke=Xc,_.PenStrokeThicknessButton=qp,_.PenTool=ym,_.SHAPES=Co,_.SelectTool=fm,_.SelectionBox=Qc,_.ShapeBlock=pp,_.ShapeFillColorButton=Jp,_.ShapeKindButton=Gp,_.ShapeStrokeColorButton=Yp,_.ShapeTool=mm,_.StickyNoteTool=pm,_.TapeBlock=mp,_.TapeImageButton=Xp,_.TapeTool=xm,_.TextAlignmentButton=Da,_.TextBlock=gp,_.TextBoldButton=Ra,_.TextButtonGroup=om,_.TextColorButton=Ha,_.TextFontFamilyButton=La,_.TextFontSizeButton=Va,_.TextItalicButton=$a,_.TextLinkButton=Fa,_.TextTool=km,_.TextUnderlineButton=za,_.Toolbar=Cm,_.ToolbarButton=nt,_.TransformBox=yp,_.TransformHandle=kp,_.UserPresence=Em,_.WOVEN_CANVAS_KEY=we,_.WovenCanvas=ZM,_.computeCommonComponents=im,_.computeShowOperations=lm,_.getArrowHead=Kn,_.useComponent=fe,_.useComponents=wt,_.useEditorContext=le,_.useFonts=tm,_.useImageCreation=ka,_.useQuery=ip,_.useSingleton=Me,_.useTextBatchController=fp,_.useTextEditorController=Pn,_.useTextFormatting=lt,_.useTextStretchBehavior=xa,_.useToolbar=js,_.useTooltipSingleton=zt,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
|