@woven-canvas/vue 1.7.0 → 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/cursors.d.ts.map +1 -1
- package/build/index.js +8 -8
- package/build/index.umd.cjs +17 -17
- package/build/utils/blockDimensions.d.ts.map +1 -1
- package/package.json +4 -4
package/build/index.umd.cjs
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
(function(_,Ve){typeof exports=="object"&&typeof module<"u"?Ve(exports,require("@woven-ecs/canvas-store"),require("@woven-canvas/plugin-arrows"),require("vue"),require("@woven-canvas/core"),require("@woven-canvas/math"),require("@woven-canvas/plugin-eraser"),require("@woven-canvas/plugin-pen"),require("@woven-canvas/plugin-canvas-controls"),require("@woven-canvas/plugin-tapes")):typeof define=="function"&&define.amd?define(["exports","@woven-ecs/canvas-store","@woven-canvas/plugin-arrows","vue","@woven-canvas/core","@woven-canvas/math","@woven-canvas/plugin-eraser","@woven-canvas/plugin-pen","@woven-canvas/plugin-canvas-controls","@woven-canvas/plugin-tapes"],Ve):(_=typeof globalThis<"u"?globalThis:_||self,Ve(_.Vue={},_.WovenEcsCanvasStore,_.WovenCanvasPluginArrows,_.Vue,_.WovenCanvasCore,_.WovenCanvasMath,_.WovenCanvasPluginEraser,_.WovenCanvasPluginPen,_.WovenCanvasPluginCanvasControls,_.WovenCanvasPluginTapes))})(this,function(_,Ve,te,a,w,ie,Sr,yn,Ci,Bg){"use strict";const Ei=[{kind:te.ArrowHeadKind.None,label:"None",gap:0,svg:""},{kind:te.ArrowHeadKind.V,label:"Arrow",gap:15,svg:'<polyline points="-10,-7 -1,0 -10,7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />'},{kind:te.ArrowHeadKind.Delta,label:"Triangle",gap:20,svg:'<polygon points="-1,0 -12,-7 -12,7" fill="currentColor" />'},{kind:te.ArrowHeadKind.Circle,label:"Circle",gap:0,svg:'<circle cx="-6" cy="0" r="6" fill="currentColor" />'},{kind:te.ArrowHeadKind.Diamond,label:"Diamond",gap:0,svg:'<polygon points="0,0 -7,-6 -14,0 -7,6" fill="currentColor" />'}];function Kn(n){return Ei.find(e=>e.kind===n)}const Ec=Symbol.for("__woven_canvas_dropdown_active__"),vc=Symbol.for("__woven_canvas_dropdown_level__"),Tc=Symbol.for("__woven_canvas_floating_menu__"),vi=Symbol.for("__woven_canvas_text_editing_options__"),Ti=Symbol.for("__woven_canvas_toolbar__"),we=Symbol.for("__woven_canvas__");function fe(n,e){const t=a.inject(we);if(!t)throw new Error("useComponent must be used within a WovenCanvas component");const o=a.shallowRef(null),r=t.getEditor();if(r){const i=r._getContext();w.hasComponent(i,n,e)&&(o.value=e.snapshot(i,n))}const s=t.subscribeComponent(n,e.name,i=>{o.value=i});return a.onUnmounted(()=>{s()}),o}const Ig={key:0},Og=["x1","y1","x2","y2","stroke","stroke-width"],_g=["x1","y1","x2","y2","stroke","stroke-width"],Dg=["points","fill"],Rg=["cx","cy","r","fill"],Pg=["points","fill"],Lg=15,Vg=2,Nt=a.defineComponent({__name:"ArrowHead",props:{position:{},direction:{},thickness:{},color:{},arrowThickness:{},kind:{}},setup(n){const e=n,t=a.computed(()=>{const l=Math.hypot(e.direction[0],e.direction[1]);if(l===0)return null;const c=(e.arrowThickness/Vg)**.33,d=Lg*c,u=[e.direction[0]/l,e.direction[1]/l],f=[-u[1],u[0]];return{unitDir:u,perpDir:f,size:d}}),o=a.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:c,size:d}=t.value,u=d,f=d,h=[e.position[0]-l[0]*u+c[0]*(f/2),e.position[1]-l[1]*u+c[1]*(f/2)],p=[e.position[0]-l[0]*u-c[0]*(f/2),e.position[1]-l[1]*u-c[1]*(f/2)];return{p1:h,p2:p}}),r=a.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:c,size:d}=t.value,u=d,f=d,h=[l[0]*(d*.4),l[1]*(d*.4)],p=[e.position[0]-l[0]*u+h[0],e.position[1]-l[1]*u+h[1]],m=[p[0]+c[0]*(f/2),p[1]+c[1]*(f/2)],g=[p[0]-c[0]*(f/2),p[1]-c[1]*(f/2)],y=[e.position[0]+h[0],e.position[1]+h[1]];return`${y[0]},${y[1]} ${m[0]},${m[1]} ${g[0]},${g[1]}`}),s=a.computed(()=>{if(!t.value)return null;const{unitDir:l,size:c}=t.value,d=c*.8,u=[l[0]*d,l[1]*d];return{center:[e.position[0]-l[0]*d+u[0],e.position[1]-l[1]*d+u[1]],radius:d}}),i=a.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:c,size:d}=t.value,u=1.6*d,f=1.6*d,h=[l[0]*(d*.8),l[1]*(d*.8)],p=[e.position[0]-l[0]*(u/2)+h[0],e.position[1]-l[1]*(u/2)+h[1]],m=[e.position[0]-l[0]*u+h[0],e.position[1]-l[1]*u+h[1]],g=[p[0]+c[0]*(f/2),p[1]+c[1]*(f/2)],y=[p[0]-c[0]*(f/2),p[1]-c[1]*(f/2)],k=[e.position[0]+h[0],e.position[1]+h[1]];return`${k[0]},${k[1]} ${g[0]},${g[1]} ${m[0]},${m[1]} ${y[0]},${y[1]}`});return(l,c)=>t.value?(a.openBlock(),a.createElementBlock("g",Ig,[n.kind===a.unref(te.ArrowHeadKind).V&&o.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:0},[a.createElementVNode("line",{x1:o.value.p1[0],y1:o.value.p1[1],x2:n.position[0],y2:n.position[1],stroke:n.color,"stroke-width":n.thickness,"stroke-linecap":"round"},null,8,Og),a.createElementVNode("line",{x1:o.value.p2[0],y1:o.value.p2[1],x2:n.position[0],y2:n.position[1],stroke:n.color,"stroke-width":n.thickness,"stroke-linecap":"round"},null,8,_g)],64)):n.kind===a.unref(te.ArrowHeadKind).Delta&&r.value?(a.openBlock(),a.createElementBlock("polygon",{key:1,points:r.value,fill:n.color},null,8,Dg)):n.kind===a.unref(te.ArrowHeadKind).Circle&&s.value?(a.openBlock(),a.createElementBlock("circle",{key:2,cx:s.value.center[0],cy:s.value.center[1],r:s.value.radius,fill:n.color},null,8,Rg)):n.kind===a.unref(te.ArrowHeadKind).Diamond&&i.value?(a.openBlock(),a.createElementBlock("polygon",{key:3,points:i.value,fill:n.color},null,8,Pg)):a.createCommentVNode("",!0)])):a.createCommentVNode("",!0)}}),$g={class:"arrow-svg",preserveAspectRatio:"none"},zg=["d","stroke","stroke-width"],Fg=["x1","y1","x2","y2","stroke","stroke-width"],Hg=["d"],jg=["x1","y1","x2","y2"],Ug=a.defineComponent({__name:"ArcArrow",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=a.ref(0),r=a.ref(0),s=fe(e.entityId,w.Color),i=fe(e.entityId,te.ArcArrow);let l=null;a.onMounted(()=>{t.value&&(l=new ResizeObserver(()=>{t.value&&(o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),l.observe(t.value),o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),a.onUnmounted(()=>{l==null||l.disconnect()});const c=a.computed(()=>{if(!s.value)return"#000000";const b=s.value.red.toString(16).padStart(2,"0"),S=s.value.green.toString(16).padStart(2,"0"),C=s.value.blue.toString(16).padStart(2,"0");return`#${b}${S}${C}`}),d=a.computed(()=>{var b;return((b=i.value)==null?void 0:b.value[6])??2}),u=a.computed(()=>`${d.value}px`),f=a.computed(()=>e.hovered||e.selected),h=a.computed(()=>{if(!i.value)return!1;const b=i.value.value,S=ie.Arc.create(b[0],b[1],b[2],b[3],b[4],b[5],b[6]);return!ie.Arc.isCollinear(S)}),p=a.computed(()=>{if(!i.value)return null;const b=i.value.value,S=o.value,C=r.value;return ie.Arc.create(b[0]*S,b[1]*C,b[2]*S,b[3]*C,b[4]*S,b[5]*C,b[6])}),m=a.computed(()=>!p.value||!h.value?null:ie.Arc.compute(p.value)),g=a.computed(()=>{var z,$,J,j;if(!i.value||!p.value)return null;const b=p.value,S=i.value.startArrowHead,C=i.value.endArrowHead,v=ie.Arc.length(b);let E=i.value.trimStart;if((z=e.connector)!=null&&z.startBlock&&S!=="none"){const K=(($=Kn(S))==null?void 0:$.gap)??0,W=v>0?K/v:0;E+=W}let T=i.value.trimEnd;if((J=e.connector)!=null&&J.endBlock&&C!=="none"){const K=((j=Kn(C))==null?void 0:j.gap)??0,W=v>0?K/v:0;T+=W}const M=1-T,A=ie.Arc.parametricToPoint(b,E),B=ie.Arc.parametricToPoint(b,M),I=x(ie.Arc.directionAt(b,E)),O=ie.Arc.directionAt(b,M);return{start:A,end:B,startDir:I,endDir:O,tStart:E,tEnd:M,startHead:S,endHead:C}}),y=a.computed(()=>{if(!g.value||!m.value||!h.value)return"";const{start:b,end:S,tStart:C,tEnd:v}=g.value,{radius:E,clockwise:T,arcAngle:M}=m.value,B=M*(v-C)>Math.PI?1:0,I=T?0:1;return`M ${b[0]} ${b[1]} A ${E} ${E} 0 ${B} ${I} ${S[0]} ${S[1]}`}),k=a.computed(()=>!g.value||h.value?null:{x1:g.value.start[0],y1:g.value.start[1],x2:g.value.end[0],y2:g.value.end[1]});function x(b){return[-b[0],-b[1]]}return(b,S)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-arc-arrow"},[(a.openBlock(),a.createElementBlock("svg",$g,[h.value&&y.value?(a.openBlock(),a.createElementBlock("path",{key:0,d:y.value,stroke:c.value,fill:"none","stroke-width":u.value,"stroke-linecap":"round"},null,8,zg)):k.value?(a.openBlock(),a.createElementBlock("line",{key:1,x1:k.value.x1,y1:k.value.y1,x2:k.value.x2,y2:k.value.y2,stroke:c.value,fill:"none","stroke-width":u.value,"stroke-linecap":"round"},null,8,Fg)):a.createCommentVNode("",!0),g.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:2},[g.value.startHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:0,position:g.value.start,direction:g.value.startDir,thickness:u.value,"arrow-thickness":d.value,color:c.value,kind:g.value.startHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):a.createCommentVNode("",!0),g.value.endHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:1,position:g.value.end,direction:g.value.endDir,thickness:u.value,"arrow-thickness":d.value,color:c.value,kind:g.value.endHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):a.createCommentVNode("",!0),f.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:2},[h.value&&y.value?(a.openBlock(),a.createElementBlock("path",{key:0,d:y.value,class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,Hg)):k.value?(a.openBlock(),a.createElementBlock("line",{key:1,x1:k.value.x1,y1:k.value.y1,x2:k.value.x2,y2:k.value.y2,class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,jg)):a.createCommentVNode("",!0),g.value.startHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:2,position:g.value.start,direction:g.value.startDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":d.value,color:"var(--wov-highlighted-block-outline-color)",kind:g.value.startHead},null,8,["position","direction","arrow-thickness","kind"])):a.createCommentVNode("",!0),g.value.endHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:3,position:g.value.end,direction:g.value.endDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":d.value,color:"var(--wov-highlighted-block-outline-color)",kind:g.value.endHead},null,8,["position","direction","arrow-thickness","kind"])):a.createCommentVNode("",!0)],64)):a.createCommentVNode("",!0)],64)):a.createCommentVNode("",!0)]))],512))}}),kn=(n,e)=>{const t=n.__vccOpts||n;for(const[o,r]of e)t[o]=r;return t},Mc=kn(Ug,[["__scopeId","data-v-de24f4c2"]]),Wg={},Kg={class:"wov-arrow-handle"};function qg(n,e){return a.openBlock(),a.createElementBlock("div",Kg,[...e[0]||(e[0]=[a.createElementVNode("div",{class:"wov-arrow-handle-inner"},null,-1)])])}const Nc=kn(Wg,[["render",qg]]),Jg={},Gg={class:"wov-arrow-terminal"};function Yg(n,e){return a.openBlock(),a.createElementBlock("div",Gg,[...e[0]||(e[0]=[a.createElementVNode("div",{class:"wov-arrow-terminal-ring"},[a.createElementVNode("div",{class:"wov-arrow-terminal-fill"})],-1)])])}const Ac=kn(Jg,[["render",Yg]]),Xg={class:"arrow-svg",preserveAspectRatio:"none"},Qg=["x1","y1","x2","y2"],Zg=["x1","y1","x2","y2","stroke","stroke-width"],e0=["x1","y1","x2","y2"],Bc=kn(a.defineComponent({__name:"ElbowArrow",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=a.ref(0),r=a.ref(0),s=fe(e.entityId,w.Color),i=fe(e.entityId,te.ElbowArrow),l=a.computed(()=>e.hovered||e.selected);let c=null;a.onMounted(()=>{t.value&&(c=new ResizeObserver(()=>{t.value&&(o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),c.observe(t.value),o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),a.onUnmounted(()=>{c==null||c.disconnect()});const d=a.computed(()=>{if(!s.value)return"#000000";const g=s.value.red.toString(16).padStart(2,"0"),y=s.value.green.toString(16).padStart(2,"0"),k=s.value.blue.toString(16).padStart(2,"0");return`#${g}${y}${k}`}),u=a.computed(()=>{var g;return((g=i.value)==null?void 0:g.thickness)??2}),f=a.computed(()=>`${u.value}px`),h=a.computed(()=>{if(!i.value)return[];const g=i.value,y=o.value,k=r.value,x=[];for(let b=0;b<g.pointCount;b++){const S=g.points[b*2]*y,C=g.points[b*2+1]*k;x.push([S,C])}return x}),p=a.computed(()=>{const g=h.value;if(g.length<2)return[];const y=[];for(let k=0;k<g.length-1;k++)y.push({start:g[k],end:g[k+1]});return y}),m=a.computed(()=>{var B,I,O,z;if(!i.value||h.value.length<2)return null;const g=i.value,y=[...h.value.map($=>[...$])],k=g.startArrowHead,x=g.endArrowHead,b=[y[1][0]-y[0][0],y[1][1]-y[0][1]],S=[y[y.length-1][0]-y[y.length-2][0],y[y.length-1][1]-y[y.length-2][1]];let C=g.trimStart;if((B=e.connector)!=null&&B.startBlock&&k!=="none"){const $=Math.hypot(b[0],b[1]),J=((I=Kn(k))==null?void 0:I.gap)??0,j=$>0?J/$:0;C+=j}let v=g.trimEnd;if((O=e.connector)!=null&&O.endBlock&&x!=="none"){const $=Math.hypot(S[0],S[1]),J=((z=Kn(x))==null?void 0:z.gap)??0,j=$>0?J/$:0;v+=j}const E=y.length-1,T=[y[0][0]+(y[1][0]-y[0][0])*C,y[0][1]+(y[1][1]-y[0][1])*C],M=[y[E-1][0]+(y[E][0]-y[E-1][0])*(1-v),y[E-1][1]+(y[E][1]-y[E-1][1])*(1-v)];y[0]=T,y[E]=M;const A=[];for(let $=0;$<y.length-1;$++)A.push({start:y[$],end:y[$+1]});return ie.Vec2.scale(b,-1),{points:y,lines:A,startPos:y[0],endPos:y[y.length-1],startDir:b,endDir:S,startHead:k,endHead:x}});return(g,y)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-elbow-arrow"},[(a.openBlock(),a.createElementBlock("svg",Xg,[l.value&&p.value.length>0?(a.openBlock(!0),a.createElementBlock(a.Fragment,{key:0},a.renderList(p.value,(k,x)=>(a.openBlock(),a.createElementBlock("line",{key:"bg-"+x,x1:k.start[0],y1:k.start[1],x2:k.end[0],y2:k.end[1],class:"highlight-bg",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))","stroke-dasharray":"calc(12px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,Qg))),128)):a.createCommentVNode("",!0),m.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(m.value.lines,(k,x)=>(a.openBlock(),a.createElementBlock("line",{key:x,x1:k.start[0],y1:k.start[1],x2:k.end[0],y2:k.end[1],stroke:d.value,fill:"none","stroke-width":f.value,"stroke-linecap":"round"},null,8,Zg))),128)),m.value.startHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:0,position:m.value.startPos,direction:m.value.startDir,thickness:f.value,"arrow-thickness":u.value,color:d.value,kind:m.value.startHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):a.createCommentVNode("",!0),m.value.endHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:1,position:m.value.endPos,direction:m.value.endDir,thickness:f.value,"arrow-thickness":u.value,color:d.value,kind:m.value.endHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):a.createCommentVNode("",!0),l.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:2},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(m.value.lines,(k,x)=>(a.openBlock(),a.createElementBlock("line",{key:"hl-"+x,x1:k.start[0],y1:k.start[1],x2:k.end[0],y2:k.end[1],class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,e0))),128)),m.value.startHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:0,position:m.value.startPos,direction:m.value.startDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":u.value,color:"var(--wov-highlighted-block-outline-color)",kind:m.value.startHead},null,8,["position","direction","arrow-thickness","kind"])):a.createCommentVNode("",!0),m.value.endHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:1,position:m.value.endPos,direction:m.value.endDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":u.value,color:"var(--wov-highlighted-block-outline-color)",kind:m.value.endHead},null,8,["position","direction","arrow-thickness","kind"])):a.createCommentVNode("",!0)],64)):a.createCommentVNode("",!0)],64)):a.createCommentVNode("",!0)]))],512))}}),[["__scopeId","data-v-fab98224"]]),t0={class:"wov-embed-block"},n0={key:0,class:"wov-embed-placeholder"},o0=["src","allow"],Ic=a.defineComponent({__name:"EmbedBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const t=fe(n.entityId,w.Embed),o=a.computed(()=>t.value&&(t.value.embedUrl||t.value.url)||null),r=a.computed(()=>{if(!t.value)return"";switch(t.value.provider){case w.EmbedProvider.Youtube:return"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";case w.EmbedProvider.Spotify:return"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture";case w.EmbedProvider.GoogleMaps:return"fullscreen";case w.EmbedProvider.GoogleCalendar:return"fullscreen";case w.EmbedProvider.GoogleSlides:return"fullscreen";case w.EmbedProvider.Figma:return"fullscreen";default:return"fullscreen"}}),s=a.computed(()=>{if(!t.value)return"Embed";switch(t.value.provider){case w.EmbedProvider.Youtube:return"YouTube";case w.EmbedProvider.Spotify:return"Spotify";case w.EmbedProvider.GoogleMaps:return"Google Maps";case w.EmbedProvider.GoogleCalendar:return"Google Calendar";case w.EmbedProvider.GoogleSlides:return"Google Slides";case w.EmbedProvider.Figma:return"Figma";case w.EmbedProvider.GithubGist:return"GitHub Gist";case w.EmbedProvider.Tldraw:return"tldraw";default:return"Embed"}});return(i,l)=>(a.openBlock(),a.createElementBlock("div",t0,[o.value?(a.openBlock(),a.createElementBlock("iframe",{key:1,src:o.value,allow:r.value,allowfullscreen:"",frameborder:"0",class:"wov-embed-iframe",style:a.normalizeStyle({pointerEvents:n.edited?"auto":"none"})},null,12,o0)):(a.openBlock(),a.createElementBlock("div",n0,[a.createElementVNode("span",null,a.toDisplayString(s.value),1)]))]))}}),{PI:r0}=Math,xo=r0+1e-4,Oc=.5,_c=[1,1];function Dc(n,e,t,o=r=>r){return n*o(.5-e*(.5-t))}const{min:Mi}=Math;function Rc(n,e,t){let o=Mi(1,e/t);return Mi(1,n+(Mi(1,1-o)-n)*(o*.275))}function s0(n){return[-n[0],-n[1]]}function ht(n,e){return[n[0]+e[0],n[1]+e[1]]}function Pc(n,e,t){return n[0]=e[0]+t[0],n[1]=e[1]+t[1],n}function Ft(n,e){return[n[0]-e[0],n[1]-e[1]]}function Ni(n,e,t){return n[0]=e[0]-t[0],n[1]=e[1]-t[1],n}function Ht(n,e){return[n[0]*e,n[1]*e]}function Ai(n,e,t){return n[0]=e[0]*t,n[1]=e[1]*t,n}function i0(n,e){return[n[0]/e,n[1]/e]}function Lc(n){return[n[1],-n[0]]}function Bi(n,e){let t=e[0];return n[0]=e[1],n[1]=-t,n}function Vc(n,e){return n[0]*e[0]+n[1]*e[1]}function l0(n,e){return n[0]===e[0]&&n[1]===e[1]}function a0(n){return Math.hypot(n[0],n[1])}function $c(n,e){let t=n[0]-e[0],o=n[1]-e[1];return t*t+o*o}function zc(n){return i0(n,a0(n))}function c0(n,e){return Math.hypot(n[1]-e[1],n[0]-e[0])}function Ii(n,e,t){let o=Math.sin(t),r=Math.cos(t),s=n[0]-e[0],i=n[1]-e[1],l=s*r-i*o,c=s*o+i*r;return[l+e[0],c+e[1]]}function Fc(n,e,t,o){let r=Math.sin(o),s=Math.cos(o),i=e[0]-t[0],l=e[1]-t[1],c=i*s-l*r,d=i*r+l*s;return n[0]=c+t[0],n[1]=d+t[1],n}function Hc(n,e,t){return ht(n,Ht(Ft(e,n),t))}function d0(n,e,t,o){let r=t[0]-e[0],s=t[1]-e[1];return n[0]=e[0]+r*o,n[1]=e[1]+s*o,n}function jc(n,e,t){return ht(n,Ht(e,t))}const Me=[0,0],jt=[0,0],Ut=[0,0];function u0(n,e){let t=jc(n,zc(Lc(Ft(n,ht(n,[1,1])))),-e),o=[],r=1/13;for(let s=r;s<=1;s+=r)o.push(Ii(t,n,xo*2*s));return o}function f0(n,e,t){let o=[],r=1/t;for(let s=r;s<=1;s+=r)o.push(Ii(e,n,xo*s));return o}function h0(n,e,t){let o=Ft(e,t),r=Ht(o,.5),s=Ht(o,.51);return[Ft(n,r),Ft(n,s),ht(n,s),ht(n,r)]}function p0(n,e,t,o){let r=[],s=jc(n,e,t),i=1/o;for(let l=i;l<1;l+=i)r.push(Ii(s,n,xo*3*l));return r}function m0(n,e,t){return[ht(n,Ht(e,t)),ht(n,Ht(e,t*.99)),Ft(n,Ht(e,t*.99)),Ft(n,Ht(e,t))]}function Uc(n,e,t){return n===!1||n===void 0?0:n===!0?Math.max(e,t):n}function g0(n,e,t){return n.slice(0,10).reduce((o,r)=>{let s=r.pressure;return e&&(s=Rc(o,r.distance,t)),(o+s)/2},n[0].pressure)}function y0(n,e={}){let{size:t=16,smoothing:o=.5,thinning:r=.5,simulatePressure:s=!0,easing:i=j=>j,start:l={},end:c={},last:d=!1}=e,{cap:u=!0,easing:f=j=>j*(2-j)}=l,{cap:h=!0,easing:p=j=>--j*j*j+1}=c;if(n.length===0||t<=0)return[];let m=n[n.length-1].runningLength,g=Uc(l.taper,t,m),y=Uc(c.taper,t,m),k=(t*o)**2,x=[],b=[],S=g0(n,s,t),C=Dc(t,r,n[n.length-1].pressure,i),v,E=n[0].vector,T=n[0].point,M=T,A=T,B=M,I=!1;for(let j=0;j<n.length;j++){let{pressure:K}=n[j],{point:W,vector:X,distance:ne,runningLength:ce}=n[j],be=j===n.length-1;if(!be&&m-ce<3)continue;r?(s&&(K=Rc(S,ne,t)),C=Dc(t,r,K,i)):C=t/2,v===void 0&&(v=C);let Oe=ce<g?f(ce/g):1,ot=m-ce<y?p((m-ce)/y):1;C=Math.max(.01,C*Math.min(Oe,ot));let ft=(be?n[j]:n[j+1]).vector,gn=be?1:Vc(X,ft),yr=Vc(X,E)<0&&!I,Wn=gn!==null&&gn<0;if(yr||Wn){Bi(Me,E),Ai(Me,Me,C);for(let vt=0;vt<=1;vt+=.07692307692307693)Ni(jt,W,Me),Fc(jt,jt,W,xo*vt),A=[jt[0],jt[1]],x.push(A),Pc(Ut,W,Me),Fc(Ut,Ut,W,xo*-vt),B=[Ut[0],Ut[1]],b.push(B);T=A,M=B,Wn&&(I=!0);continue}if(I=!1,be){Bi(Me,X),Ai(Me,Me,C),x.push(Ft(W,Me)),b.push(ht(W,Me));continue}d0(Me,ft,X,gn),Bi(Me,Me),Ai(Me,Me,C),Ni(jt,W,Me),A=[jt[0],jt[1]],(j<=1||$c(T,A)>k)&&(x.push(A),T=A),Pc(Ut,W,Me),B=[Ut[0],Ut[1]],(j<=1||$c(M,B)>k)&&(b.push(B),M=B),S=K,E=X}let O=[n[0].point[0],n[0].point[1]],z=n.length>1?[n[n.length-1].point[0],n[n.length-1].point[1]]:ht(n[0].point,[1,1]),$=[],J=[];if(n.length===1){if(!(g||y)||d)return u0(O,v||C)}else{g||y&&n.length===1||(u?$.push(...f0(O,b[0],13)):$.push(...h0(O,x[0],b[0])));let j=Lc(s0(n[n.length-1].vector));y||g&&n.length===1?J.push(z):h?J.push(...p0(z,j,C,29)):J.push(...m0(z,j,C))}return x.concat(J,b.reverse(),$)}const Wc=[0,0];function Kc(n){return n!=null&&n>=0}function k0(n,e={}){var h;let{streamline:t=.5,size:o=16,last:r=!1}=e;if(n.length===0)return[];let s=.15+(1-t)*.85,i=Array.isArray(n[0])?n:n.map(({x:p,y:m,pressure:g=Oc})=>[p,m,g]);if(i.length===2){let p=i[1];i=i.slice(0,-1);for(let m=1;m<5;m++)i.push(Hc(i[0],p,m/4))}i.length===1&&(i=[...i,[...ht(i[0],_c),...i[0].slice(2)]]);let l=[{point:[i[0][0],i[0][1]],pressure:Kc(i[0][2])?i[0][2]:.25,vector:[..._c],distance:0,runningLength:0}],c=!1,d=0,u=l[0],f=i.length-1;for(let p=1;p<i.length;p++){let m=r&&p===f?[i[p][0],i[p][1]]:Hc(u.point,i[p],s);if(l0(u.point,m))continue;let g=c0(m,u.point);if(d+=g,p<f&&!c){if(d<o)continue;c=!0}Ni(Wc,u.point,m),u={point:m,pressure:Kc(i[p][2])?i[p][2]:Oc,vector:zc(Wc),distance:g,runningLength:d},l.push(u)}return l[0].vector=((h=l[1])==null?void 0:h.vector)||[0,0],l}function Oi(n,e={}){return y0(k0(n,e),e)}const w0={class:"wov-eraser-stroke"},b0={preserveAspectRatio:"none"},S0=["d"],x0="#88888833",qc=a.defineComponent({__name:"Eraser",props:{entityId:{}},setup(n){const e=n,t=fe(e.entityId,Sr.EraserStroke),o=fe(e.entityId,w.Block),r=a.shallowRef("");function s(l,c){return(l+c)/2}function i(l,c,d,u,f,h){if(l<=4)return"";const p=[],m=Math.min(l,Sr.POINTS_CAPACITY);for(let S=0;S<m;S++){const C=(c+S)%Sr.POINTS_CAPACITY*2;p.push([d[C]-f,d[C+1]-h])}const g=Oi(p,{size:u,start:{taper:66,cap:!0}});if(g.length<3)return"";let y=g[0],k=g[1];const x=g[2];let b=`M${y[0].toFixed(2)},${y[1].toFixed(2)} Q${k[0].toFixed(2)},${k[1].toFixed(2)} ${s(k[0],x[0]).toFixed(2)},${s(k[1],x[1]).toFixed(2)} T`;for(let S=2;S<g.length-1;S++)y=g[S],k=g[S+1],b+=`${s(y[0],k[0]).toFixed(2)},${s(y[1],k[1]).toFixed(2)} `;return b+=`${k[0].toFixed(2)},${k[1].toFixed(2)} `,b+="Z",b}return a.watch([t,o],([l,c])=>{if(!l||!c){r.value="";return}const d=l.radius??8,[u,f]=c.position;r.value=i(l.pointCount,l.firstPointIndex,l.points,2*d,u,f)},{immediate:!0}),(l,c)=>(a.openBlock(),a.createElementBlock("div",w0,[(a.openBlock(),a.createElementBlock("svg",b0,[a.createElementVNode("path",{d:r.value,fill:x0},null,8,S0)]))]))}});function le(){const n=a.inject(we);if(!n)throw new Error("useEditorContext must be used within a WovenCanvas component");return{getEditor:()=>n.getEditor(),setDefaults:(e,t)=>n.setDefaults(e,t),getDefaults:e=>n.getDefaults(e),nextEditorTick(e){return new Promise(t=>{const o=n.getEditor();o&&o.nextTick(r=>{e==null||e(r),t(r)})})}}}const Jc=a.defineComponent({__name:"FrameBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=fe(e.entityId,w.Frame),r=fe(e.entityId,w.FrameDropTarget),s=a.computed(()=>r.value!==null),i=a.computed(()=>{var f;return((f=o.value)==null?void 0:f.label)??"Frame"}),l=a.computed(()=>{const[f,h]=e.block.flip;if(!(!f&&!h))return{transform:`scale(${f?-1:1}, ${h?-1:1})`}}),c=a.ref(null);function d(){var h,p;const f=((p=(h=c.value)==null?void 0:h.textContent)==null?void 0:p.trim())||"Frame";f!==i.value&&t(m=>{const g=w.Frame.write(m,e.entityId);g.label=f})}function u(f){var h;(f.key==="Enter"||f.key==="Escape")&&(f.preventDefault(),(h=c.value)==null||h.blur()),f.stopPropagation()}return(f,h)=>(a.openBlock(),a.createElementBlock("div",{class:"wov-frame-block",style:a.normalizeStyle(l.value)},[a.createElementVNode("div",{class:a.normalizeClass(["wov-frame-border",{"wov-frame-border--hovered":e.hovered,"wov-frame-border--selected":e.selected,"wov-frame-border--drop-target":s.value}])},null,2),a.createElementVNode("div",{ref_key:"labelRef",ref:c,class:"wov-frame-label",contenteditable:"true",onBlur:d,onKeydown:u},a.toDisplayString(i.value),545)],4))}}),Gc=256;function xr(n,e=0){const t=typeof window<"u"&&window.devicePixelRatio||1;let o=Math.ceil(n*t/Gc)*Gc;return e>0&&(o=Math.min(o,e)),o}const C0={class:"wov-image-block"},E0={key:0,class:"wov-image-placeholder wov-image-loading"},v0={key:1,class:"wov-image-placeholder"},T0={key:2,class:"wov-image-placeholder wov-image-error"},M0=["src","alt"],Yc=a.defineComponent({__name:"ImageBlock",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("ImageBlock must be used within a WovenCanvas component");const s=r,i=fe(o.entityId,w.Asset),l=fe(o.entityId,w.Image),c=s.getAssetManager(),d=a.computed(()=>{const C=i.value;return!(C!=null&&C.identifier)||C.uploadState!==w.UploadState.Pending&&C.uploadState!==w.UploadState.Uploading?!1:!(c!=null&&c.hasPendingUpload(C.identifier))});function u(){var E,T;const[C,v]=o.block.size;return{width:xr(C,((E=l.value)==null?void 0:E.width)??0),height:xr(v,((T=l.value)==null?void 0:T.height)??0)}}const f={width:0,height:0},h=i.value;let p=null;if(c&&(h!=null&&h.identifier)&&!d.value){const C=u();f.width=C.width,f.height=C.height,p=([e,t]=a.withAsyncContext(()=>c.getDisplayUrl(h.identifier,C)),e=await e,t(),e)}const m=a.ref(p),g=a.ref(!p),y=a.ref(!1);let k=!0;a.onUnmounted(()=>{k=!1});function x(C){if(typeof window>"u"||!m.value){m.value=C,g.value=!1;return}const v=new window.Image;v.onload=()=>{k&&(m.value=C,g.value=!1)},v.onerror=()=>{k&&(g.value=!1)},v.src=C}async function b(){const C=i.value;if(!C){g.value=!1;return}if(d.value){m.value=null,g.value=!0,y.value=!1;return}try{g.value=!0,y.value=!1;const v=u();f.width=v.width,f.height=v.height;const E=await(c==null?void 0:c.getDisplayUrl(C.identifier,v));if(!k)return;E?x(E):C.uploadState===w.UploadState.Failed&&(y.value=!0,g.value=!1)}catch(v){if(!k)return;console.error("Failed to get display URL:",v),y.value=!0,g.value=!1}}a.watch(()=>i.value,()=>{b()},{immediate:!0}),a.onMounted(()=>{b()}),a.watch(()=>[o.block.size[0],o.block.size[1]],()=>{const C=u();(C.width>f.width||C.height>f.height)&&b()});const S=a.computed(()=>({width:"100%",height:"100%",objectFit:"fill"}));return(C,v)=>{var E;return a.openBlock(),a.createElementBlock("div",C0,[d.value?(a.openBlock(),a.createElementBlock("div",E0,[...v[0]||(v[0]=[a.createElementVNode("div",{class:"wov-image-spinner","aria-label":"Loading image"},null,-1)])])):g.value&&!m.value?(a.openBlock(),a.createElementBlock("div",v0)):y.value?(a.openBlock(),a.createElementBlock("div",T0,[...v[1]||(v[1]=[a.createElementVNode("span",null,"Failed to save image",-1)])])):m.value?(a.openBlock(),a.createElementBlock("img",{key:3,src:m.value,alt:((E=a.unref(l))==null?void 0:E.alt)||"",style:a.normalizeStyle(S.value),draggable:"false"},null,12,M0)):a.createCommentVNode("",!0)])}}}),N0=["data-complete"],A0={preserveAspectRatio:"none"},B0=["d","fill","fill-rule"],I0={key:0,class:"highlight",preserveAspectRatio:"none"},O0=["d"],Xc=kn(a.defineComponent({__name:"PenStroke",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,yn.PenStroke),o=fe(e.entityId,w.Block),r=fe(e.entityId,w.Color),s=a.shallowRef(""),i=a.shallowRef(""),l=a.shallowRef([]);function c(m,g){return(m+g)/2}function d(m,g,y){if(g<=1||m.length<3){const C=y/2;return`M ${C},0 a ${C},${C} 0 1 0 0.0001 0`}let k=m[0],x=m[1];const b=m[2];let S=`M${k[0].toFixed(2)},${k[1].toFixed(2)} Q${x[0].toFixed(2)},${x[1].toFixed(2)} ${c(x[0],b[0]).toFixed(2)},${c(x[1],b[1]).toFixed(2)} T`;for(let C=2;C<m.length-1;C++)k=m[C],x=m[C+1],S+=`${c(k[0],x[0]).toFixed(2)},${c(k[1],x[1]).toFixed(2)} `;return S+=`${x[0].toFixed(2)},${x[1].toFixed(2)} `,S+="Z",S}function u(m){if(m.length<3)return"";let g=`M${m[0][0].toFixed(2)},${m[0][1].toFixed(2)} `;for(let k=1;k<m.length-1;k++){const x=c(m[k][0],m[k+1][0]),b=c(m[k][1],m[k+1][1]);g+=`Q${m[k][0].toFixed(2)},${m[k][1].toFixed(2)} ${x.toFixed(2)},${b.toFixed(2)} `}const y=m[m.length-1];return g+=`L${y[0].toFixed(2)},${y[1].toFixed(2)} `,g+="Z",g}a.watch([t,o],([m,g])=>{if(!m||!g){s.value="",i.value="",l.value=[];return}if(!m.originalWidth||!m.originalHeight){s.value="",i.value="",l.value=[];return}const y=g.size[0]/m.originalWidth,k=g.size[1]/m.originalHeight,x=[];for(let S=0;S<m.pointCount;S++){const C=m.points[S*2],v=m.points[S*2+1],E=(C-m.originalLeft)*y,T=(v-m.originalTop)*k;m.hasPressure?x.push([E,T,m.pressures[S]]):x.push([E,T])}if(l.value=[],m.kind===yn.PenStrokeKind.Fill){const S=u(x);s.value=S,m.isComplete&&(i.value=S);return}const b=Oi(x,{last:m.isComplete,size:m.thickness,simulatePressure:!m.hasPressure});if(s.value=d(b,m.pointCount,m.thickness),m.isComplete){const S=x.length===1?m.thickness:1,C=Oi(x,{last:!0,size:S,simulatePressure:!m.hasPressure});i.value=d(C,m.pointCount,S)}},{immediate:!0});const f=a.computed(()=>{var m;return((m=t.value)==null?void 0:m.kind)===yn.PenStrokeKind.Fill?"evenodd":"nonzero"}),h=a.computed(()=>{if(!r.value)return"#000000";const{red:m,green:g,blue:y,alpha:k}=r.value;return`rgba(${m}, ${g}, ${y}, ${(k??255)/255})`}),p=a.computed(()=>e.selected||e.hovered);return(m,g)=>{var y;return a.openBlock(),a.createElementBlock("div",{class:"wov-pen-stroke","data-complete":((y=a.unref(t))==null?void 0:y.isComplete)||void 0},[(a.openBlock(),a.createElementBlock("svg",A0,[a.createElementVNode("path",{d:s.value,fill:h.value,"fill-rule":f.value},null,8,B0)])),p.value?(a.openBlock(),a.createElementBlock("svg",I0,[a.createElementVNode("path",{d:i.value,stroke:"var(--wov-highlighted-block-outline-color)",style:{"stroke-width":"calc(1px / var(--wov-zoom))"},fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},null,8,O0)])):a.createCommentVNode("",!0),a.createCommentVNode("",!0)],8,N0)}}}),[["__scopeId","data-v-bfbffe8c"]]),_0={class:"wov-selection-box"},Qc=a.defineComponent({__name:"SelectionBox",setup(n){return(e,t)=>(a.openBlock(),a.createElementBlock("div",_0))}}),Co={rectangle:"M0,0 L100,0 L100,100 L0,100 Z",ellipse:"M50,0 A50,50 0 1,1 50,100 A50,50 0 1,1 50,0",triangle:"M50,0 L100,100 L0,100 Z",diamond:"M50,0 L100,50 L50,100 L0,50 Z",pentagon:"M50,0 L100,38.2 L80.9,100 L19.1,100 L0,38.2 Z",hexagon:"M50,0 L100,25 L100,75 L50,100 L0,75 L0,25 Z",star:"M50,0 L61.8,38.2 L100,38.2 L69.1,61.8 L80.9,100 L50,76.4 L19.1,100 L30.9,61.8 L0,38.2 L38.2,38.2 Z",heart:"M50,16 C44,7 37,0 26,0 11,0 0,12 0,28 0,60 16,65 50,100 84,65 100,60 100,28 100,12 89,0 74,0 63,0 56,7 50,16 Z",arrow:"M0,35 L60,35 L60,0 L100,50 L60,100 L60,65 L0,65 Z"};function Ne(n){this.content=n}Ne.prototype={constructor:Ne,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var o=t&&t!=n?this.remove(t):this,r=o.find(n),s=o.content.slice();return r==-1?s.push(t||n,e):(s[r+1]=e,t&&(s[r]=t)),new Ne(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new Ne(t)},addToStart:function(n,e){return new Ne([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Ne(t)},addBefore:function(n,e,t){var o=this.remove(e),r=o.content.slice(),s=o.find(n);return r.splice(s==-1?r.length:s,0,e,t),new Ne(r)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=Ne.from(n),n.size?new Ne(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Ne.from(n),n.size?new Ne(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Ne.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}},Ne.from=function(n){if(n instanceof Ne)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Ne(e)};function Zc(n,e,t){for(let o=0;;o++){if(o==n.childCount||o==e.childCount)return n.childCount==e.childCount?null:t;let r=n.child(o),s=e.child(o);if(r==s){t+=r.nodeSize;continue}if(!r.sameMarkup(s))return t;if(r.isText&&r.text!=s.text){for(let i=0;r.text[i]==s.text[i];i++)t++;return t}if(r.content.size||s.content.size){let i=Zc(r.content,s.content,t+1);if(i!=null)return i}t+=r.nodeSize}}function ed(n,e,t,o){for(let r=n.childCount,s=e.childCount;;){if(r==0||s==0)return r==s?null:{a:t,b:o};let i=n.child(--r),l=e.child(--s),c=i.nodeSize;if(i==l){t-=c,o-=c;continue}if(!i.sameMarkup(l))return{a:t,b:o};if(i.isText&&i.text!=l.text){let d=0,u=Math.min(i.text.length,l.text.length);for(;d<u&&i.text[i.text.length-d-1]==l.text[l.text.length-d-1];)d++,t--,o--;return{a:t,b:o}}if(i.content.size||l.content.size){let d=ed(i.content,l.content,t-1,o-1);if(d)return d}t-=c,o-=c}}class P{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let o=0;o<e.length;o++)this.size+=e[o].nodeSize}nodesBetween(e,t,o,r=0,s){for(let i=0,l=0;l<t;i++){let c=this.content[i],d=l+c.nodeSize;if(d>e&&o(c,r+l,s||null,i)!==!1&&c.content.size){let u=l+1;c.nodesBetween(Math.max(0,e-u),Math.min(c.content.size,t-u),o,r+u)}l=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,o,r){let s="",i=!0;return this.nodesBetween(e,t,(l,c)=>{let d=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?r?typeof r=="function"?r(l):r:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&d||l.isTextblock)&&o&&(i?i=!1:s+=o),s+=d},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,o=e.firstChild,r=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(o)&&(r[r.length-1]=t.withText(t.text+o.text),s=1);s<e.content.length;s++)r.push(e.content[s]);return new P(r,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let o=[],r=0;if(t>e)for(let s=0,i=0;i<t;s++){let l=this.content[s],c=i+l.nodeSize;c>e&&((i<e||c>t)&&(l.isText?l=l.cut(Math.max(0,e-i),Math.min(l.text.length,t-i)):l=l.cut(Math.max(0,e-i-1),Math.min(l.content.size,t-i-1))),o.push(l),r+=l.nodeSize),i=c}return new P(o,r)}cutByIndex(e,t){return e==t?P.empty:e==0&&t==this.content.length?this:new P(this.content.slice(e,t))}replaceChild(e,t){let o=this.content[e];if(o==t)return this;let r=this.content.slice(),s=this.size+t.nodeSize-o.nodeSize;return r[e]=t,new P(r,s)}addToStart(e){return new P([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new P(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,o=0;t<this.content.length;t++){let r=this.content[t];e(r,o,t),o+=r.nodeSize}}findDiffStart(e,t=0){return Zc(this,e,t)}findDiffEnd(e,t=this.size,o=e.size){return ed(this,e,t,o)}findIndex(e){if(e==0)return Cr(0,e);if(e==this.size)return Cr(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,o=0;;t++){let r=this.child(t),s=o+r.nodeSize;if(s>=e)return s==e?Cr(t+1,s):Cr(t,o);o=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return P.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new P(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return P.empty;let t,o=0;for(let r=0;r<e.length;r++){let s=e[r];o+=s.nodeSize,r&&s.isText&&e[r-1].sameMarkup(s)?(t||(t=e.slice(0,r)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new P(t||e,o)}static from(e){if(!e)return P.empty;if(e instanceof P)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new P([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}P.empty=new P([],0);const _i={index:0,offset:0};function Cr(n,e){return _i.index=n,_i.offset=e,_i}function Er(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let o=0;o<n.length;o++)if(!Er(n[o],e[o]))return!1}else{for(let o in n)if(!(o in e)||!Er(n[o],e[o]))return!1;for(let o in e)if(!(o in n))return!1}return!0}let se=class xc{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,o=!1;for(let r=0;r<e.length;r++){let s=e[r];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,r));else{if(s.type.excludes(this.type))return e;!o&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),o=!0),t&&t.push(s)}}return t||(t=e.slice()),o||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Er(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let o=e.marks[t.type];if(!o)throw new RangeError(`There is no mark type ${t.type} in this schema`);let r=o.create(t.attrs);return o.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let o=0;o<e.length;o++)if(!e[o].eq(t[o]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return xc.none;if(e instanceof xc)return[e];let t=e.slice();return t.sort((o,r)=>o.type.rank-r.type.rank),t}};se.none=[];class vr extends Error{}class U{constructor(e,t,o){this.content=e,this.openStart=t,this.openEnd=o}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let o=nd(this.content,e+this.openStart,t);return o&&new U(o,this.openStart,this.openEnd)}removeBetween(e,t){return new U(td(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return U.empty;let o=t.openStart||0,r=t.openEnd||0;if(typeof o!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new U(P.fromJSON(e,t.content),o,r)}static maxOpen(e,t=!0){let o=0,r=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)o++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)r++;return new U(e,o,r)}}U.empty=new U(P.empty,0,0);function td(n,e,t){let{index:o,offset:r}=n.findIndex(e),s=n.maybeChild(o),{index:i,offset:l}=n.findIndex(t);if(r==e||s.isText){if(l!=t&&!n.child(i).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(o!=i)throw new RangeError("Removing non-flat range");return n.replaceChild(o,s.copy(td(s.content,e-r-1,t-r-1)))}function nd(n,e,t,o){let{index:r,offset:s}=n.findIndex(e),i=n.maybeChild(r);if(s==e||i.isText)return o&&!o.canReplace(r,r,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=nd(i.content,e-s-1,t,i);return l&&n.replaceChild(r,i.copy(l))}function D0(n,e,t){if(t.openStart>n.depth)throw new vr("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new vr("Inconsistent open depths");return od(n,e,t,0)}function od(n,e,t,o){let r=n.index(o),s=n.node(o);if(r==e.index(o)&&o<n.depth-t.openStart){let i=od(n,e,t,o+1);return s.copy(s.content.replaceChild(r,i))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==o&&e.depth==o){let i=n.parent,l=i.content;return bn(i,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:i,end:l}=R0(t,n);return bn(s,sd(n,i,l,e,o))}else return bn(s,Tr(n,e,o))}function rd(n,e){if(!e.type.compatibleContent(n.type))throw new vr("Cannot join "+e.type.name+" onto "+n.type.name)}function Di(n,e,t){let o=n.node(t);return rd(o,e.node(t)),o}function wn(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Eo(n,e,t,o){let r=(e||n).node(t),s=0,i=e?e.index(t):r.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(wn(n.nodeAfter,o),s++));for(let l=s;l<i;l++)wn(r.child(l),o);e&&e.depth==t&&e.textOffset&&wn(e.nodeBefore,o)}function bn(n,e){return n.type.checkContent(e),n.copy(e)}function sd(n,e,t,o,r){let s=n.depth>r&&Di(n,e,r+1),i=o.depth>r&&Di(t,o,r+1),l=[];return Eo(null,n,r,l),s&&i&&e.index(r)==t.index(r)?(rd(s,i),wn(bn(s,sd(n,e,t,o,r+1)),l)):(s&&wn(bn(s,Tr(n,e,r+1)),l),Eo(e,t,r,l),i&&wn(bn(i,Tr(t,o,r+1)),l)),Eo(o,null,r,l),new P(l)}function Tr(n,e,t){let o=[];if(Eo(null,n,t,o),n.depth>t){let r=Di(n,e,t+1);wn(bn(r,Tr(n,e,t+1)),o)}return Eo(e,null,t,o),new P(o)}function R0(n,e){let t=e.depth-n.openStart,r=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)r=e.node(s).copy(P.from(r));return{start:r.resolveNoCache(n.openStart+t),end:r.resolveNoCache(r.content.size-n.openEnd-t)}}class vo{constructor(e,t,o){this.pos=e,this.path=t,this.parentOffset=o,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let o=this.pos-this.path[this.path.length-1],r=e.child(t);return o?e.child(t).cut(o):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let o=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)r+=o.child(s).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return se.none;if(this.textOffset)return e.child(t).marks;let o=e.maybeChild(t-1),r=e.maybeChild(t);if(!o){let l=o;o=r,r=l}let s=o.marks;for(var i=0;i<s.length;i++)s[i].type.spec.inclusive===!1&&(!r||!s[i].isInSet(r.marks))&&(s=s[i--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let o=t.marks,r=e.parent.maybeChild(e.index());for(var s=0;s<o.length;s++)o[s].type.spec.inclusive===!1&&(!r||!o[s].isInSet(r.marks))&&(o=o[s--].removeFromSet(o));return o}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let o=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);o>=0;o--)if(e.pos<=this.end(o)&&(!t||t(this.node(o))))return new Mr(this,e,o);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let o=[],r=0,s=t;for(let i=e;;){let{index:l,offset:c}=i.content.findIndex(s),d=s-c;if(o.push(i,l,r+c),!d||(i=i.child(l),i.isText))break;s=d-1,r+=c+1}return new vo(t,o,s)}static resolveCached(e,t){let o=id.get(e);if(o)for(let s=0;s<o.elts.length;s++){let i=o.elts[s];if(i.pos==t)return i}else id.set(e,o=new P0);let r=o.elts[o.i]=vo.resolve(e,t);return o.i=(o.i+1)%L0,r}}class P0{constructor(){this.elts=[],this.i=0}}const L0=12,id=new WeakMap;class Mr{constructor(e,t,o){this.$from=e,this.$to=t,this.depth=o}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const V0=Object.create(null);let At=class Cc{constructor(e,t,o,r=se.none){this.type=e,this.attrs=t,this.marks=r,this.content=o||P.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,o,r=0){this.content.nodesBetween(e,t,o,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,o,r){return this.content.textBetween(e,t,o,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,o){return this.type==e&&Er(this.attrs,t||e.defaultAttrs||V0)&&se.sameSet(this.marks,o||se.none)}copy(e=null){return e==this.content?this:new Cc(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Cc(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,o=!1){if(e==t)return U.empty;let r=this.resolve(e),s=this.resolve(t),i=o?0:r.sharedDepth(t),l=r.start(i),d=r.node(i).content.cut(r.pos-l,s.pos-l);return new U(d,r.depth-i,s.depth-i)}replace(e,t,o){return D0(this.resolve(e),this.resolve(t),o)}nodeAt(e){for(let t=this;;){let{index:o,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(o),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:o}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:o}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:o}=this.content.findIndex(e);if(o<e)return{node:this.content.child(t),index:t,offset:o};let r=this.content.child(t-1);return{node:r,index:t-1,offset:o-r.nodeSize}}resolve(e){return vo.resolveCached(this,e)}resolveNoCache(e){return vo.resolve(this,e)}rangeHasMark(e,t,o){let r=!1;return t>e&&this.nodesBetween(e,t,s=>(o.isInSet(s.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),ld(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,o=P.empty,r=0,s=o.childCount){let i=this.contentMatchAt(e).matchFragment(o,r,s),l=i&&i.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=r;c<s;c++)if(!this.type.allowsMarks(o.child(c).marks))return!1;return!0}canReplaceWith(e,t,o,r){if(r&&!this.type.allowsMarks(r))return!1;let s=this.contentMatchAt(e).matchType(o),i=s&&s.matchFragment(this.content,t);return i?i.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=se.none;for(let t=0;t<this.marks.length;t++){let o=this.marks[t];o.type.checkAttrs(o.attrs),e=o.addToSet(e)}if(!se.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let o;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");o=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,o)}let r=P.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,r,o);return s.type.checkAttrs(s.attrs),s}};At.prototype.text=void 0;class Nr extends At{constructor(e,t,o,r){if(super(e,t,null,r),!o)throw new RangeError("Empty text nodes are not allowed");this.text=o}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ld(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Nr(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Nr(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function ld(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class Sn{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let o=new $0(e,t);if(o.next==null)return Sn.empty;let r=ad(o);o.next&&o.err("Unexpected trailing text");let s=K0(W0(r));return q0(s,o),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,o=e.childCount){let r=this;for(let s=t;r&&s<o;s++)r=r.matchType(e.child(s).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let o=0;o<e.next.length;o++)if(this.next[t].type==e.next[o].type)return!0;return!1}fillBefore(e,t=!1,o=0){let r=[this];function s(i,l){let c=i.matchFragment(e,o);if(c&&(!t||c.validEnd))return P.from(l.map(d=>d.createAndFill()));for(let d=0;d<i.next.length;d++){let{type:u,next:f}=i.next[d];if(!(u.isText||u.hasRequiredAttrs())&&r.indexOf(f)==-1){r.push(f);let h=s(f,l.concat(u));if(h)return h}}return null}return s(this,[])}findWrapping(e){for(let o=0;o<this.wrapCache.length;o+=2)if(this.wrapCache[o]==e)return this.wrapCache[o+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),o=[{match:this,type:null,via:null}];for(;o.length;){let r=o.shift(),s=r.match;if(s.matchType(e)){let i=[];for(let l=r;l.type;l=l.via)i.push(l.type);return i.reverse()}for(let i=0;i<s.next.length;i++){let{type:l,next:c}=s.next[i];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!r.type||c.validEnd)&&(o.push({match:l.contentMatch,type:l,via:r}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(o){e.push(o);for(let r=0;r<o.next.length;r++)e.indexOf(o.next[r].next)==-1&&t(o.next[r].next)}return t(this),e.map((o,r)=>{let s=r+(o.validEnd?"*":" ")+" ";for(let i=0;i<o.next.length;i++)s+=(i?", ":"")+o.next[i].type.name+"->"+e.indexOf(o.next[i].next);return s}).join(`
|
|
2
|
-
`)}}Sn.empty=new Sn(!0);class $0{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function ad(n){let e=[];do e.push(z0(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function z0(n){let e=[];do e.push(F0(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function F0(n){let e=U0(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=H0(n,e);else break;return e}function cd(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function H0(n,e){let t=cd(n),o=t;return n.eat(",")&&(n.next!="}"?o=cd(n):o=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:o,expr:e}}function j0(n,e){let t=n.nodeTypes,o=t[e];if(o)return[o];let r=[];for(let s in t){let i=t[s];i.isInGroup(e)&&r.push(i)}return r.length==0&&n.err("No node type or group '"+e+"' found"),r}function U0(n){if(n.eat("(")){let e=ad(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=j0(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function W0(n){let e=[[]];return r(s(n,0),t()),e;function t(){return e.push([])-1}function o(i,l,c){let d={term:c,to:l};return e[i].push(d),d}function r(i,l){i.forEach(c=>c.to=l)}function s(i,l){if(i.type=="choice")return i.exprs.reduce((c,d)=>c.concat(s(d,l)),[]);if(i.type=="seq")for(let c=0;;c++){let d=s(i.exprs[c],l);if(c==i.exprs.length-1)return d;r(d,l=t())}else if(i.type=="star"){let c=t();return o(l,c),r(s(i.expr,c),c),[o(c)]}else if(i.type=="plus"){let c=t();return r(s(i.expr,l),c),r(s(i.expr,c),c),[o(c)]}else{if(i.type=="opt")return[o(l)].concat(s(i.expr,l));if(i.type=="range"){let c=l;for(let d=0;d<i.min;d++){let u=t();r(s(i.expr,c),u),c=u}if(i.max==-1)r(s(i.expr,c),c);else for(let d=i.min;d<i.max;d++){let u=t();o(c,u),r(s(i.expr,c),u),c=u}return[o(c)]}else{if(i.type=="name")return[o(l,void 0,i.value)];throw new Error("Unknown expr type")}}}}function dd(n,e){return e-n}function ud(n,e){let t=[];return o(e),t.sort(dd);function o(r){let s=n[r];if(s.length==1&&!s[0].term)return o(s[0].to);t.push(r);for(let i=0;i<s.length;i++){let{term:l,to:c}=s[i];!l&&t.indexOf(c)==-1&&o(c)}}}function K0(n){let e=Object.create(null);return t(ud(n,0));function t(o){let r=[];o.forEach(i=>{n[i].forEach(({term:l,to:c})=>{if(!l)return;let d;for(let u=0;u<r.length;u++)r[u][0]==l&&(d=r[u][1]);ud(n,c).forEach(u=>{d||r.push([l,d=[]]),d.indexOf(u)==-1&&d.push(u)})})});let s=e[o.join(",")]=new Sn(o.indexOf(n.length-1)>-1);for(let i=0;i<r.length;i++){let l=r[i][1].sort(dd);s.next.push({type:r[i][0],next:e[l.join(",")]||t(l)})}return s}}function q0(n,e){for(let t=0,o=[n];t<o.length;t++){let r=o[t],s=!r.validEnd,i=[];for(let l=0;l<r.next.length;l++){let{type:c,next:d}=r.next[l];i.push(c.name),s&&!(c.isText||c.hasRequiredAttrs())&&(s=!1),o.indexOf(d)==-1&&o.push(d)}s&&e.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function fd(n){let e=Object.create(null);for(let t in n){let o=n[t];if(!o.hasDefault)return null;e[t]=o.default}return e}function hd(n,e){let t=Object.create(null);for(let o in n){let r=e&&e[o];if(r===void 0){let s=n[o];if(s.hasDefault)r=s.default;else throw new RangeError("No value supplied for attribute "+o)}t[o]=r}return t}function pd(n,e,t,o){for(let r in e)if(!(r in n))throw new RangeError(`Unsupported attribute ${r} for ${t} of type ${r}`);for(let r in n){let s=n[r];s.validate&&s.validate(e[r])}}function md(n,e){let t=Object.create(null);if(e)for(let o in e)t[o]=new G0(n,o,e[o]);return t}let gd=class vg{constructor(e,t,o){this.name=e,this.schema=t,this.spec=o,this.markSet=null,this.groups=o.group?o.group.split(" "):[],this.attrs=md(e,o.attrs),this.defaultAttrs=fd(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(o.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==Sn.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:hd(this.attrs,e)}create(e=null,t,o){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new At(this,this.computeAttrs(e),P.from(t),se.setFrom(o))}createChecked(e=null,t,o){return t=P.from(t),this.checkContent(t),new At(this,this.computeAttrs(e),t,se.setFrom(o))}createAndFill(e=null,t,o){if(e=this.computeAttrs(e),t=P.from(t),t.size){let i=this.contentMatch.fillBefore(t);if(!i)return null;t=i.append(t)}let r=this.contentMatch.matchFragment(t),s=r&&r.fillBefore(P.empty,!0);return s?new At(this,e,t.append(s),se.setFrom(o)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let o=0;o<e.childCount;o++)if(!this.allowsMarks(e.child(o).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){pd(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let o=0;o<e.length;o++)this.allowsMarkType(e[o].type)?t&&t.push(e[o]):t||(t=e.slice(0,o));return t?t.length?t:se.none:e}static compile(e,t){let o=Object.create(null);e.forEach((s,i)=>o[s]=new vg(s,t,i));let r=t.spec.topNode||"doc";if(!o[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!o.text)throw new RangeError("Every schema needs a 'text' type");for(let s in o.text.attrs)throw new RangeError("The text node type should not have attributes");return o}};function J0(n,e,t){let o=t.split("|");return r=>{let s=r===null?"null":typeof r;if(o.indexOf(s)<0)throw new RangeError(`Expected value of type ${o} for attribute ${e} on type ${n}, got ${s}`)}}class G0{constructor(e,t,o){this.hasDefault=Object.prototype.hasOwnProperty.call(o,"default"),this.default=o.default,this.validate=typeof o.validate=="string"?J0(e,t,o.validate):o.validate}get isRequired(){return!this.hasDefault}}class Ar{constructor(e,t,o,r){this.name=e,this.rank=t,this.schema=o,this.spec=r,this.attrs=md(e,r.attrs),this.excluded=null;let s=fd(this.attrs);this.instance=s?new se(this,s):null}create(e=null){return!e&&this.instance?this.instance:new se(this,hd(this.attrs,e))}static compile(e,t){let o=Object.create(null),r=0;return e.forEach((s,i)=>o[s]=new Ar(s,r++,t,i)),o}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){pd(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class yd{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let r in e)t[r]=e[r];t.nodes=Ne.from(e.nodes),t.marks=Ne.from(e.marks||{}),this.nodes=gd.compile(this.spec.nodes,this),this.marks=Ar.compile(this.spec.marks,this);let o=Object.create(null);for(let r in this.nodes){if(r in this.marks)throw new RangeError(r+" can not be both a node and a mark");let s=this.nodes[r],i=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=o[i]||(o[i]=Sn.parse(i,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?kd(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let r in this.marks){let s=this.marks[r],i=s.spec.excludes;s.excluded=i==null?[s]:i==""?[]:kd(this,i.split(" "))}this.nodeFromJSON=r=>At.fromJSON(this,r),this.markFromJSON=r=>se.fromJSON(this,r),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,o,r){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof gd){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,o,r)}text(e,t){let o=this.nodes.text;return new Nr(o,o.defaultAttrs,e,se.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function kd(n,e){let t=[];for(let o=0;o<e.length;o++){let r=e[o],s=n.marks[r],i=s;if(s)t.push(s);else for(let l in n.marks){let c=n.marks[l];(r=="_"||c.spec.group&&c.spec.group.split(" ").indexOf(r)>-1)&&t.push(i=c)}if(!i)throw new SyntaxError("Unknown mark type: '"+e[o]+"'")}return t}function Y0(n){return n.tag!=null}function X0(n){return n.style!=null}class Bt{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let o=this.matchedStyles=[];t.forEach(r=>{if(Y0(r))this.tags.push(r);else if(X0(r)){let s=/[^=]*/.exec(r.style)[0];o.indexOf(s)<0&&o.push(s),this.styles.push(r)}}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let s=e.nodes[r.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let o=new xd(this,t,!1);return o.addAll(e,se.none,t.from,t.to),o.finish()}parseSlice(e,t={}){let o=new xd(this,t,!0);return o.addAll(e,se.none,t.from,t.to),U.maxOpen(o.finish())}matchTag(e,t,o){for(let r=o?this.tags.indexOf(o)+1:0;r<this.tags.length;r++){let s=this.tags[r];if(ey(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let i=s.getAttrs(e);if(i===!1)continue;s.attrs=i||void 0}return s}}}matchStyle(e,t,o,r){for(let s=r?this.styles.indexOf(r)+1:0;s<this.styles.length;s++){let i=this.styles[s],l=i.style;if(!(l.indexOf(e)!=0||i.context&&!o.matchesContext(i.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(i.getAttrs){let c=i.getAttrs(t);if(c===!1)continue;i.attrs=c||void 0}return i}}}static schemaRules(e){let t=[];function o(r){let s=r.priority==null?50:r.priority,i=0;for(;i<t.length;i++){let l=t[i];if((l.priority==null?50:l.priority)<s)break}t.splice(i,0,r)}for(let r in e.marks){let s=e.marks[r].spec.parseDOM;s&&s.forEach(i=>{o(i=Cd(i)),i.mark||i.ignore||i.clearMark||(i.mark=r)})}for(let r in e.nodes){let s=e.nodes[r].spec.parseDOM;s&&s.forEach(i=>{o(i=Cd(i)),i.node||i.ignore||i.mark||(i.node=r)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Bt(e,Bt.schemaRules(e)))}}const wd={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Q0={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},bd={ol:!0,ul:!0},To=1,Ri=2,Mo=4;function Sd(n,e,t){return e!=null?(e?To:0)|(e==="full"?Ri:0):n&&n.whitespace=="pre"?To|Ri:t&~Mo}class Br{constructor(e,t,o,r,s,i){this.type=e,this.attrs=t,this.marks=o,this.solid=r,this.options=i,this.content=[],this.activeMarks=se.none,this.match=s||(i&Mo?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(P.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let o=this.type.contentMatch,r;return(r=o.findWrapping(e.type))?(this.match=o,r):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&To)){let o=this.content[this.content.length-1],r;if(o&&o.isText&&(r=/[ \t\r\n\u000c]+$/.exec(o.text))){let s=o;o.text.length==r[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-r[0].length))}}let t=P.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(P.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!wd.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class xd{constructor(e,t,o){this.parser=e,this.options=t,this.isOpen=o,this.open=0,this.localPreserveWS=!1;let r=t.topNode,s,i=Sd(null,t.preserveWhitespace,0)|(o?Mo:0);r?s=new Br(r.type,r.attrs,se.none,!0,t.topMatch||r.type.contentMatch,i):o?s=new Br(null,null,se.none,!0,null,i):s=new Br(e.schema.topNodeType,null,se.none,!0,null,i),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let o=e.nodeValue,r=this.top,s=r.options&Ri?"full":this.localPreserveWS||(r.options&To)>0,{schema:i}=this.parser;if(s==="full"||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(o)){if(s)if(s==="full")o=o.replace(/\r\n?/g,`
|
|
1
|
+
(function(_,Ve){typeof exports=="object"&&typeof module<"u"?Ve(exports,require("@woven-ecs/canvas-store"),require("@woven-canvas/plugin-arrows"),require("vue"),require("@woven-canvas/core"),require("@woven-canvas/math"),require("@woven-canvas/plugin-eraser"),require("@woven-canvas/plugin-pen"),require("@woven-canvas/plugin-canvas-controls"),require("@woven-canvas/plugin-tapes")):typeof define=="function"&&define.amd?define(["exports","@woven-ecs/canvas-store","@woven-canvas/plugin-arrows","vue","@woven-canvas/core","@woven-canvas/math","@woven-canvas/plugin-eraser","@woven-canvas/plugin-pen","@woven-canvas/plugin-canvas-controls","@woven-canvas/plugin-tapes"],Ve):(_=typeof globalThis<"u"?globalThis:_||self,Ve(_.Vue={},_.WovenEcsCanvasStore,_.WovenCanvasPluginArrows,_.Vue,_.WovenCanvasCore,_.WovenCanvasMath,_.WovenCanvasPluginEraser,_.WovenCanvasPluginPen,_.WovenCanvasPluginCanvasControls,_.WovenCanvasPluginTapes))})(this,function(_,Ve,te,a,w,ie,Sr,yn,Ci,Bg){"use strict";const Ei=[{kind:te.ArrowHeadKind.None,label:"None",gap:0,svg:""},{kind:te.ArrowHeadKind.V,label:"Arrow",gap:15,svg:'<polyline points="-10,-7 -1,0 -10,7" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" />'},{kind:te.ArrowHeadKind.Delta,label:"Triangle",gap:20,svg:'<polygon points="-1,0 -12,-7 -12,7" fill="currentColor" />'},{kind:te.ArrowHeadKind.Circle,label:"Circle",gap:0,svg:'<circle cx="-6" cy="0" r="6" fill="currentColor" />'},{kind:te.ArrowHeadKind.Diamond,label:"Diamond",gap:0,svg:'<polygon points="0,0 -7,-6 -14,0 -7,6" fill="currentColor" />'}];function Kn(n){return Ei.find(e=>e.kind===n)}const Ec=Symbol.for("__woven_canvas_dropdown_active__"),vc=Symbol.for("__woven_canvas_dropdown_level__"),Mc=Symbol.for("__woven_canvas_floating_menu__"),vi=Symbol.for("__woven_canvas_text_editing_options__"),Mi=Symbol.for("__woven_canvas_toolbar__"),we=Symbol.for("__woven_canvas__");function fe(n,e){const t=a.inject(we);if(!t)throw new Error("useComponent must be used within a WovenCanvas component");const o=a.shallowRef(null),r=t.getEditor();if(r){const i=r._getContext();w.hasComponent(i,n,e)&&(o.value=e.snapshot(i,n))}const s=t.subscribeComponent(n,e.name,i=>{o.value=i});return a.onUnmounted(()=>{s()}),o}const Ig={key:0},Og=["x1","y1","x2","y2","stroke","stroke-width"],_g=["x1","y1","x2","y2","stroke","stroke-width"],Dg=["points","fill"],Rg=["cx","cy","r","fill"],Pg=["points","fill"],Lg=15,Vg=2,Nt=a.defineComponent({__name:"ArrowHead",props:{position:{},direction:{},thickness:{},color:{},arrowThickness:{},kind:{}},setup(n){const e=n,t=a.computed(()=>{const l=Math.hypot(e.direction[0],e.direction[1]);if(l===0)return null;const c=(e.arrowThickness/Vg)**.33,d=Lg*c,u=[e.direction[0]/l,e.direction[1]/l],f=[-u[1],u[0]];return{unitDir:u,perpDir:f,size:d}}),o=a.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:c,size:d}=t.value,u=d,f=d,h=[e.position[0]-l[0]*u+c[0]*(f/2),e.position[1]-l[1]*u+c[1]*(f/2)],p=[e.position[0]-l[0]*u-c[0]*(f/2),e.position[1]-l[1]*u-c[1]*(f/2)];return{p1:h,p2:p}}),r=a.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:c,size:d}=t.value,u=d,f=d,h=[l[0]*(d*.4),l[1]*(d*.4)],p=[e.position[0]-l[0]*u+h[0],e.position[1]-l[1]*u+h[1]],m=[p[0]+c[0]*(f/2),p[1]+c[1]*(f/2)],g=[p[0]-c[0]*(f/2),p[1]-c[1]*(f/2)],y=[e.position[0]+h[0],e.position[1]+h[1]];return`${y[0]},${y[1]} ${m[0]},${m[1]} ${g[0]},${g[1]}`}),s=a.computed(()=>{if(!t.value)return null;const{unitDir:l,size:c}=t.value,d=c*.8,u=[l[0]*d,l[1]*d];return{center:[e.position[0]-l[0]*d+u[0],e.position[1]-l[1]*d+u[1]],radius:d}}),i=a.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:c,size:d}=t.value,u=1.6*d,f=1.6*d,h=[l[0]*(d*.8),l[1]*(d*.8)],p=[e.position[0]-l[0]*(u/2)+h[0],e.position[1]-l[1]*(u/2)+h[1]],m=[e.position[0]-l[0]*u+h[0],e.position[1]-l[1]*u+h[1]],g=[p[0]+c[0]*(f/2),p[1]+c[1]*(f/2)],y=[p[0]-c[0]*(f/2),p[1]-c[1]*(f/2)],k=[e.position[0]+h[0],e.position[1]+h[1]];return`${k[0]},${k[1]} ${g[0]},${g[1]} ${m[0]},${m[1]} ${y[0]},${y[1]}`});return(l,c)=>t.value?(a.openBlock(),a.createElementBlock("g",Ig,[n.kind===a.unref(te.ArrowHeadKind).V&&o.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:0},[a.createElementVNode("line",{x1:o.value.p1[0],y1:o.value.p1[1],x2:n.position[0],y2:n.position[1],stroke:n.color,"stroke-width":n.thickness,"stroke-linecap":"round"},null,8,Og),a.createElementVNode("line",{x1:o.value.p2[0],y1:o.value.p2[1],x2:n.position[0],y2:n.position[1],stroke:n.color,"stroke-width":n.thickness,"stroke-linecap":"round"},null,8,_g)],64)):n.kind===a.unref(te.ArrowHeadKind).Delta&&r.value?(a.openBlock(),a.createElementBlock("polygon",{key:1,points:r.value,fill:n.color},null,8,Dg)):n.kind===a.unref(te.ArrowHeadKind).Circle&&s.value?(a.openBlock(),a.createElementBlock("circle",{key:2,cx:s.value.center[0],cy:s.value.center[1],r:s.value.radius,fill:n.color},null,8,Rg)):n.kind===a.unref(te.ArrowHeadKind).Diamond&&i.value?(a.openBlock(),a.createElementBlock("polygon",{key:3,points:i.value,fill:n.color},null,8,Pg)):a.createCommentVNode("",!0)])):a.createCommentVNode("",!0)}}),$g={class:"arrow-svg",preserveAspectRatio:"none"},zg=["d","stroke","stroke-width"],Fg=["x1","y1","x2","y2","stroke","stroke-width"],Hg=["d"],jg=["x1","y1","x2","y2"],Ug=a.defineComponent({__name:"ArcArrow",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=a.ref(0),r=a.ref(0),s=fe(e.entityId,w.Color),i=fe(e.entityId,te.ArcArrow);let l=null;a.onMounted(()=>{t.value&&(l=new ResizeObserver(()=>{t.value&&(o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),l.observe(t.value),o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),a.onUnmounted(()=>{l==null||l.disconnect()});const c=a.computed(()=>{if(!s.value)return"#000000";const b=s.value.red.toString(16).padStart(2,"0"),S=s.value.green.toString(16).padStart(2,"0"),C=s.value.blue.toString(16).padStart(2,"0");return`#${b}${S}${C}`}),d=a.computed(()=>{var b;return((b=i.value)==null?void 0:b.value[6])??2}),u=a.computed(()=>`${d.value}px`),f=a.computed(()=>e.hovered||e.selected),h=a.computed(()=>{if(!i.value)return!1;const b=i.value.value,S=ie.Arc.create(b[0],b[1],b[2],b[3],b[4],b[5],b[6]);return!ie.Arc.isCollinear(S)}),p=a.computed(()=>{if(!i.value)return null;const b=i.value.value,S=o.value,C=r.value;return ie.Arc.create(b[0]*S,b[1]*C,b[2]*S,b[3]*C,b[4]*S,b[5]*C,b[6])}),m=a.computed(()=>!p.value||!h.value?null:ie.Arc.compute(p.value)),g=a.computed(()=>{var z,$,J,j;if(!i.value||!p.value)return null;const b=p.value,S=i.value.startArrowHead,C=i.value.endArrowHead,v=ie.Arc.length(b);let E=i.value.trimStart;if((z=e.connector)!=null&&z.startBlock&&S!=="none"){const K=(($=Kn(S))==null?void 0:$.gap)??0,W=v>0?K/v:0;E+=W}let M=i.value.trimEnd;if((J=e.connector)!=null&&J.endBlock&&C!=="none"){const K=((j=Kn(C))==null?void 0:j.gap)??0,W=v>0?K/v:0;M+=W}const T=1-M,A=ie.Arc.parametricToPoint(b,E),B=ie.Arc.parametricToPoint(b,T),I=x(ie.Arc.directionAt(b,E)),O=ie.Arc.directionAt(b,T);return{start:A,end:B,startDir:I,endDir:O,tStart:E,tEnd:T,startHead:S,endHead:C}}),y=a.computed(()=>{if(!g.value||!m.value||!h.value)return"";const{start:b,end:S,tStart:C,tEnd:v}=g.value,{radius:E,clockwise:M,arcAngle:T}=m.value,B=T*(v-C)>Math.PI?1:0,I=M?0:1;return`M ${b[0]} ${b[1]} A ${E} ${E} 0 ${B} ${I} ${S[0]} ${S[1]}`}),k=a.computed(()=>!g.value||h.value?null:{x1:g.value.start[0],y1:g.value.start[1],x2:g.value.end[0],y2:g.value.end[1]});function x(b){return[-b[0],-b[1]]}return(b,S)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-arc-arrow"},[(a.openBlock(),a.createElementBlock("svg",$g,[h.value&&y.value?(a.openBlock(),a.createElementBlock("path",{key:0,d:y.value,stroke:c.value,fill:"none","stroke-width":u.value,"stroke-linecap":"round"},null,8,zg)):k.value?(a.openBlock(),a.createElementBlock("line",{key:1,x1:k.value.x1,y1:k.value.y1,x2:k.value.x2,y2:k.value.y2,stroke:c.value,fill:"none","stroke-width":u.value,"stroke-linecap":"round"},null,8,Fg)):a.createCommentVNode("",!0),g.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:2},[g.value.startHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:0,position:g.value.start,direction:g.value.startDir,thickness:u.value,"arrow-thickness":d.value,color:c.value,kind:g.value.startHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):a.createCommentVNode("",!0),g.value.endHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:1,position:g.value.end,direction:g.value.endDir,thickness:u.value,"arrow-thickness":d.value,color:c.value,kind:g.value.endHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):a.createCommentVNode("",!0),f.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:2},[h.value&&y.value?(a.openBlock(),a.createElementBlock("path",{key:0,d:y.value,class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,Hg)):k.value?(a.openBlock(),a.createElementBlock("line",{key:1,x1:k.value.x1,y1:k.value.y1,x2:k.value.x2,y2:k.value.y2,class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,jg)):a.createCommentVNode("",!0),g.value.startHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:2,position:g.value.start,direction:g.value.startDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":d.value,color:"var(--wov-highlighted-block-outline-color)",kind:g.value.startHead},null,8,["position","direction","arrow-thickness","kind"])):a.createCommentVNode("",!0),g.value.endHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:3,position:g.value.end,direction:g.value.endDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":d.value,color:"var(--wov-highlighted-block-outline-color)",kind:g.value.endHead},null,8,["position","direction","arrow-thickness","kind"])):a.createCommentVNode("",!0)],64)):a.createCommentVNode("",!0)],64)):a.createCommentVNode("",!0)]))],512))}}),kn=(n,e)=>{const t=n.__vccOpts||n;for(const[o,r]of e)t[o]=r;return t},Tc=kn(Ug,[["__scopeId","data-v-de24f4c2"]]),Wg={},Kg={class:"wov-arrow-handle"};function qg(n,e){return a.openBlock(),a.createElementBlock("div",Kg,[...e[0]||(e[0]=[a.createElementVNode("div",{class:"wov-arrow-handle-inner"},null,-1)])])}const Nc=kn(Wg,[["render",qg]]),Jg={},Gg={class:"wov-arrow-terminal"};function Yg(n,e){return a.openBlock(),a.createElementBlock("div",Gg,[...e[0]||(e[0]=[a.createElementVNode("div",{class:"wov-arrow-terminal-ring"},[a.createElementVNode("div",{class:"wov-arrow-terminal-fill"})],-1)])])}const Ac=kn(Jg,[["render",Yg]]),Xg={class:"arrow-svg",preserveAspectRatio:"none"},Qg=["x1","y1","x2","y2"],Zg=["x1","y1","x2","y2","stroke","stroke-width"],e0=["x1","y1","x2","y2"],Bc=kn(a.defineComponent({__name:"ElbowArrow",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=a.ref(0),r=a.ref(0),s=fe(e.entityId,w.Color),i=fe(e.entityId,te.ElbowArrow),l=a.computed(()=>e.hovered||e.selected);let c=null;a.onMounted(()=>{t.value&&(c=new ResizeObserver(()=>{t.value&&(o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),c.observe(t.value),o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),a.onUnmounted(()=>{c==null||c.disconnect()});const d=a.computed(()=>{if(!s.value)return"#000000";const g=s.value.red.toString(16).padStart(2,"0"),y=s.value.green.toString(16).padStart(2,"0"),k=s.value.blue.toString(16).padStart(2,"0");return`#${g}${y}${k}`}),u=a.computed(()=>{var g;return((g=i.value)==null?void 0:g.thickness)??2}),f=a.computed(()=>`${u.value}px`),h=a.computed(()=>{if(!i.value)return[];const g=i.value,y=o.value,k=r.value,x=[];for(let b=0;b<g.pointCount;b++){const S=g.points[b*2]*y,C=g.points[b*2+1]*k;x.push([S,C])}return x}),p=a.computed(()=>{const g=h.value;if(g.length<2)return[];const y=[];for(let k=0;k<g.length-1;k++)y.push({start:g[k],end:g[k+1]});return y}),m=a.computed(()=>{var B,I,O,z;if(!i.value||h.value.length<2)return null;const g=i.value,y=[...h.value.map($=>[...$])],k=g.startArrowHead,x=g.endArrowHead,b=[y[1][0]-y[0][0],y[1][1]-y[0][1]],S=[y[y.length-1][0]-y[y.length-2][0],y[y.length-1][1]-y[y.length-2][1]];let C=g.trimStart;if((B=e.connector)!=null&&B.startBlock&&k!=="none"){const $=Math.hypot(b[0],b[1]),J=((I=Kn(k))==null?void 0:I.gap)??0,j=$>0?J/$:0;C+=j}let v=g.trimEnd;if((O=e.connector)!=null&&O.endBlock&&x!=="none"){const $=Math.hypot(S[0],S[1]),J=((z=Kn(x))==null?void 0:z.gap)??0,j=$>0?J/$:0;v+=j}const E=y.length-1,M=[y[0][0]+(y[1][0]-y[0][0])*C,y[0][1]+(y[1][1]-y[0][1])*C],T=[y[E-1][0]+(y[E][0]-y[E-1][0])*(1-v),y[E-1][1]+(y[E][1]-y[E-1][1])*(1-v)];y[0]=M,y[E]=T;const A=[];for(let $=0;$<y.length-1;$++)A.push({start:y[$],end:y[$+1]});return ie.Vec2.scale(b,-1),{points:y,lines:A,startPos:y[0],endPos:y[y.length-1],startDir:b,endDir:S,startHead:k,endHead:x}});return(g,y)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-elbow-arrow"},[(a.openBlock(),a.createElementBlock("svg",Xg,[l.value&&p.value.length>0?(a.openBlock(!0),a.createElementBlock(a.Fragment,{key:0},a.renderList(p.value,(k,x)=>(a.openBlock(),a.createElementBlock("line",{key:"bg-"+x,x1:k.start[0],y1:k.start[1],x2:k.end[0],y2:k.end[1],class:"highlight-bg",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))","stroke-dasharray":"calc(12px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,Qg))),128)):a.createCommentVNode("",!0),m.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(m.value.lines,(k,x)=>(a.openBlock(),a.createElementBlock("line",{key:x,x1:k.start[0],y1:k.start[1],x2:k.end[0],y2:k.end[1],stroke:d.value,fill:"none","stroke-width":f.value,"stroke-linecap":"round"},null,8,Zg))),128)),m.value.startHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:0,position:m.value.startPos,direction:m.value.startDir,thickness:f.value,"arrow-thickness":u.value,color:d.value,kind:m.value.startHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):a.createCommentVNode("",!0),m.value.endHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:1,position:m.value.endPos,direction:m.value.endDir,thickness:f.value,"arrow-thickness":u.value,color:d.value,kind:m.value.endHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):a.createCommentVNode("",!0),l.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:2},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(m.value.lines,(k,x)=>(a.openBlock(),a.createElementBlock("line",{key:"hl-"+x,x1:k.start[0],y1:k.start[1],x2:k.end[0],y2:k.end[1],class:"highlight-overlay",fill:"none",style:{"stroke-width":"calc(2px / var(--wov-zoom))"},"stroke-linecap":"round"},null,8,e0))),128)),m.value.startHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:0,position:m.value.startPos,direction:m.value.startDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":u.value,color:"var(--wov-highlighted-block-outline-color)",kind:m.value.startHead},null,8,["position","direction","arrow-thickness","kind"])):a.createCommentVNode("",!0),m.value.endHead!=="none"?(a.openBlock(),a.createBlock(Nt,{key:1,position:m.value.endPos,direction:m.value.endDir,thickness:"calc(2px / var(--wov-zoom))","arrow-thickness":u.value,color:"var(--wov-highlighted-block-outline-color)",kind:m.value.endHead},null,8,["position","direction","arrow-thickness","kind"])):a.createCommentVNode("",!0)],64)):a.createCommentVNode("",!0)],64)):a.createCommentVNode("",!0)]))],512))}}),[["__scopeId","data-v-fab98224"]]),t0={class:"wov-embed-block"},n0={key:0,class:"wov-embed-placeholder"},o0=["src","allow"],Ic=a.defineComponent({__name:"EmbedBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const t=fe(n.entityId,w.Embed),o=a.computed(()=>t.value&&(t.value.embedUrl||t.value.url)||null),r=a.computed(()=>{if(!t.value)return"";switch(t.value.provider){case w.EmbedProvider.Youtube:return"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";case w.EmbedProvider.Spotify:return"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture";case w.EmbedProvider.GoogleMaps:return"fullscreen";case w.EmbedProvider.GoogleCalendar:return"fullscreen";case w.EmbedProvider.GoogleSlides:return"fullscreen";case w.EmbedProvider.Figma:return"fullscreen";default:return"fullscreen"}}),s=a.computed(()=>{if(!t.value)return"Embed";switch(t.value.provider){case w.EmbedProvider.Youtube:return"YouTube";case w.EmbedProvider.Spotify:return"Spotify";case w.EmbedProvider.GoogleMaps:return"Google Maps";case w.EmbedProvider.GoogleCalendar:return"Google Calendar";case w.EmbedProvider.GoogleSlides:return"Google Slides";case w.EmbedProvider.Figma:return"Figma";case w.EmbedProvider.GithubGist:return"GitHub Gist";case w.EmbedProvider.Tldraw:return"tldraw";default:return"Embed"}});return(i,l)=>(a.openBlock(),a.createElementBlock("div",t0,[o.value?(a.openBlock(),a.createElementBlock("iframe",{key:1,src:o.value,allow:r.value,allowfullscreen:"",frameborder:"0",class:"wov-embed-iframe",style:a.normalizeStyle({pointerEvents:n.edited?"auto":"none"})},null,12,o0)):(a.openBlock(),a.createElementBlock("div",n0,[a.createElementVNode("span",null,a.toDisplayString(s.value),1)]))]))}}),{PI:r0}=Math,xo=r0+1e-4,Oc=.5,_c=[1,1];function Dc(n,e,t,o=r=>r){return n*o(.5-e*(.5-t))}const{min:Ti}=Math;function Rc(n,e,t){let o=Ti(1,e/t);return Ti(1,n+(Ti(1,1-o)-n)*(o*.275))}function s0(n){return[-n[0],-n[1]]}function ht(n,e){return[n[0]+e[0],n[1]+e[1]]}function Pc(n,e,t){return n[0]=e[0]+t[0],n[1]=e[1]+t[1],n}function Ft(n,e){return[n[0]-e[0],n[1]-e[1]]}function Ni(n,e,t){return n[0]=e[0]-t[0],n[1]=e[1]-t[1],n}function Ht(n,e){return[n[0]*e,n[1]*e]}function Ai(n,e,t){return n[0]=e[0]*t,n[1]=e[1]*t,n}function i0(n,e){return[n[0]/e,n[1]/e]}function Lc(n){return[n[1],-n[0]]}function Bi(n,e){let t=e[0];return n[0]=e[1],n[1]=-t,n}function Vc(n,e){return n[0]*e[0]+n[1]*e[1]}function l0(n,e){return n[0]===e[0]&&n[1]===e[1]}function a0(n){return Math.hypot(n[0],n[1])}function $c(n,e){let t=n[0]-e[0],o=n[1]-e[1];return t*t+o*o}function zc(n){return i0(n,a0(n))}function c0(n,e){return Math.hypot(n[1]-e[1],n[0]-e[0])}function Ii(n,e,t){let o=Math.sin(t),r=Math.cos(t),s=n[0]-e[0],i=n[1]-e[1],l=s*r-i*o,c=s*o+i*r;return[l+e[0],c+e[1]]}function Fc(n,e,t,o){let r=Math.sin(o),s=Math.cos(o),i=e[0]-t[0],l=e[1]-t[1],c=i*s-l*r,d=i*r+l*s;return n[0]=c+t[0],n[1]=d+t[1],n}function Hc(n,e,t){return ht(n,Ht(Ft(e,n),t))}function d0(n,e,t,o){let r=t[0]-e[0],s=t[1]-e[1];return n[0]=e[0]+r*o,n[1]=e[1]+s*o,n}function jc(n,e,t){return ht(n,Ht(e,t))}const Te=[0,0],jt=[0,0],Ut=[0,0];function u0(n,e){let t=jc(n,zc(Lc(Ft(n,ht(n,[1,1])))),-e),o=[],r=1/13;for(let s=r;s<=1;s+=r)o.push(Ii(t,n,xo*2*s));return o}function f0(n,e,t){let o=[],r=1/t;for(let s=r;s<=1;s+=r)o.push(Ii(e,n,xo*s));return o}function h0(n,e,t){let o=Ft(e,t),r=Ht(o,.5),s=Ht(o,.51);return[Ft(n,r),Ft(n,s),ht(n,s),ht(n,r)]}function p0(n,e,t,o){let r=[],s=jc(n,e,t),i=1/o;for(let l=i;l<1;l+=i)r.push(Ii(s,n,xo*3*l));return r}function m0(n,e,t){return[ht(n,Ht(e,t)),ht(n,Ht(e,t*.99)),Ft(n,Ht(e,t*.99)),Ft(n,Ht(e,t))]}function Uc(n,e,t){return n===!1||n===void 0?0:n===!0?Math.max(e,t):n}function g0(n,e,t){return n.slice(0,10).reduce((o,r)=>{let s=r.pressure;return e&&(s=Rc(o,r.distance,t)),(o+s)/2},n[0].pressure)}function y0(n,e={}){let{size:t=16,smoothing:o=.5,thinning:r=.5,simulatePressure:s=!0,easing:i=j=>j,start:l={},end:c={},last:d=!1}=e,{cap:u=!0,easing:f=j=>j*(2-j)}=l,{cap:h=!0,easing:p=j=>--j*j*j+1}=c;if(n.length===0||t<=0)return[];let m=n[n.length-1].runningLength,g=Uc(l.taper,t,m),y=Uc(c.taper,t,m),k=(t*o)**2,x=[],b=[],S=g0(n,s,t),C=Dc(t,r,n[n.length-1].pressure,i),v,E=n[0].vector,M=n[0].point,T=M,A=M,B=T,I=!1;for(let j=0;j<n.length;j++){let{pressure:K}=n[j],{point:W,vector:X,distance:ne,runningLength:ce}=n[j],be=j===n.length-1;if(!be&&m-ce<3)continue;r?(s&&(K=Rc(S,ne,t)),C=Dc(t,r,K,i)):C=t/2,v===void 0&&(v=C);let Oe=ce<g?f(ce/g):1,ot=m-ce<y?p((m-ce)/y):1;C=Math.max(.01,C*Math.min(Oe,ot));let ft=(be?n[j]:n[j+1]).vector,gn=be?1:Vc(X,ft),yr=Vc(X,E)<0&&!I,Wn=gn!==null&&gn<0;if(yr||Wn){Bi(Te,E),Ai(Te,Te,C);for(let vt=0;vt<=1;vt+=.07692307692307693)Ni(jt,W,Te),Fc(jt,jt,W,xo*vt),A=[jt[0],jt[1]],x.push(A),Pc(Ut,W,Te),Fc(Ut,Ut,W,xo*-vt),B=[Ut[0],Ut[1]],b.push(B);M=A,T=B,Wn&&(I=!0);continue}if(I=!1,be){Bi(Te,X),Ai(Te,Te,C),x.push(Ft(W,Te)),b.push(ht(W,Te));continue}d0(Te,ft,X,gn),Bi(Te,Te),Ai(Te,Te,C),Ni(jt,W,Te),A=[jt[0],jt[1]],(j<=1||$c(M,A)>k)&&(x.push(A),M=A),Pc(Ut,W,Te),B=[Ut[0],Ut[1]],(j<=1||$c(T,B)>k)&&(b.push(B),T=B),S=K,E=X}let O=[n[0].point[0],n[0].point[1]],z=n.length>1?[n[n.length-1].point[0],n[n.length-1].point[1]]:ht(n[0].point,[1,1]),$=[],J=[];if(n.length===1){if(!(g||y)||d)return u0(O,v||C)}else{g||y&&n.length===1||(u?$.push(...f0(O,b[0],13)):$.push(...h0(O,x[0],b[0])));let j=Lc(s0(n[n.length-1].vector));y||g&&n.length===1?J.push(z):h?J.push(...p0(z,j,C,29)):J.push(...m0(z,j,C))}return x.concat(J,b.reverse(),$)}const Wc=[0,0];function Kc(n){return n!=null&&n>=0}function k0(n,e={}){var h;let{streamline:t=.5,size:o=16,last:r=!1}=e;if(n.length===0)return[];let s=.15+(1-t)*.85,i=Array.isArray(n[0])?n:n.map(({x:p,y:m,pressure:g=Oc})=>[p,m,g]);if(i.length===2){let p=i[1];i=i.slice(0,-1);for(let m=1;m<5;m++)i.push(Hc(i[0],p,m/4))}i.length===1&&(i=[...i,[...ht(i[0],_c),...i[0].slice(2)]]);let l=[{point:[i[0][0],i[0][1]],pressure:Kc(i[0][2])?i[0][2]:.25,vector:[..._c],distance:0,runningLength:0}],c=!1,d=0,u=l[0],f=i.length-1;for(let p=1;p<i.length;p++){let m=r&&p===f?[i[p][0],i[p][1]]:Hc(u.point,i[p],s);if(l0(u.point,m))continue;let g=c0(m,u.point);if(d+=g,p<f&&!c){if(d<o)continue;c=!0}Ni(Wc,u.point,m),u={point:m,pressure:Kc(i[p][2])?i[p][2]:Oc,vector:zc(Wc),distance:g,runningLength:d},l.push(u)}return l[0].vector=((h=l[1])==null?void 0:h.vector)||[0,0],l}function Oi(n,e={}){return y0(k0(n,e),e)}const w0={class:"wov-eraser-stroke"},b0={preserveAspectRatio:"none"},S0=["d"],x0="#88888833",qc=a.defineComponent({__name:"Eraser",props:{entityId:{}},setup(n){const e=n,t=fe(e.entityId,Sr.EraserStroke),o=fe(e.entityId,w.Block),r=a.shallowRef("");function s(l,c){return(l+c)/2}function i(l,c,d,u,f,h){if(l<=4)return"";const p=[],m=Math.min(l,Sr.POINTS_CAPACITY);for(let S=0;S<m;S++){const C=(c+S)%Sr.POINTS_CAPACITY*2;p.push([d[C]-f,d[C+1]-h])}const g=Oi(p,{size:u,start:{taper:66,cap:!0}});if(g.length<3)return"";let y=g[0],k=g[1];const x=g[2];let b=`M${y[0].toFixed(2)},${y[1].toFixed(2)} Q${k[0].toFixed(2)},${k[1].toFixed(2)} ${s(k[0],x[0]).toFixed(2)},${s(k[1],x[1]).toFixed(2)} T`;for(let S=2;S<g.length-1;S++)y=g[S],k=g[S+1],b+=`${s(y[0],k[0]).toFixed(2)},${s(y[1],k[1]).toFixed(2)} `;return b+=`${k[0].toFixed(2)},${k[1].toFixed(2)} `,b+="Z",b}return a.watch([t,o],([l,c])=>{if(!l||!c){r.value="";return}const d=l.radius??8,[u,f]=c.position;r.value=i(l.pointCount,l.firstPointIndex,l.points,2*d,u,f)},{immediate:!0}),(l,c)=>(a.openBlock(),a.createElementBlock("div",w0,[(a.openBlock(),a.createElementBlock("svg",b0,[a.createElementVNode("path",{d:r.value,fill:x0},null,8,S0)]))]))}});function le(){const n=a.inject(we);if(!n)throw new Error("useEditorContext must be used within a WovenCanvas component");return{getEditor:()=>n.getEditor(),setDefaults:(e,t)=>n.setDefaults(e,t),getDefaults:e=>n.getDefaults(e),nextEditorTick(e){return new Promise(t=>{const o=n.getEditor();o&&o.nextTick(r=>{e==null||e(r),t(r)})})}}}const Jc=a.defineComponent({__name:"FrameBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=fe(e.entityId,w.Frame),r=fe(e.entityId,w.FrameDropTarget),s=a.computed(()=>r.value!==null),i=a.computed(()=>{var f;return((f=o.value)==null?void 0:f.label)??"Frame"}),l=a.computed(()=>{const[f,h]=e.block.flip;if(!(!f&&!h))return{transform:`scale(${f?-1:1}, ${h?-1:1})`}}),c=a.ref(null);function d(){var h,p;const f=((p=(h=c.value)==null?void 0:h.textContent)==null?void 0:p.trim())||"Frame";f!==i.value&&t(m=>{const g=w.Frame.write(m,e.entityId);g.label=f})}function u(f){var h;(f.key==="Enter"||f.key==="Escape")&&(f.preventDefault(),(h=c.value)==null||h.blur()),f.stopPropagation()}return(f,h)=>(a.openBlock(),a.createElementBlock("div",{class:"wov-frame-block",style:a.normalizeStyle(l.value)},[a.createElementVNode("div",{class:a.normalizeClass(["wov-frame-border",{"wov-frame-border--hovered":e.hovered,"wov-frame-border--selected":e.selected,"wov-frame-border--drop-target":s.value}])},null,2),a.createElementVNode("div",{ref_key:"labelRef",ref:c,class:"wov-frame-label",contenteditable:"true",onBlur:d,onKeydown:u},a.toDisplayString(i.value),545)],4))}}),Gc=256;function xr(n,e=0){const t=typeof window<"u"&&window.devicePixelRatio||1;let o=Math.ceil(n*t/Gc)*Gc;return e>0&&(o=Math.min(o,e)),o}const C0={class:"wov-image-block"},E0={key:0,class:"wov-image-placeholder wov-image-loading"},v0={key:1,class:"wov-image-placeholder"},M0={key:2,class:"wov-image-placeholder wov-image-error"},T0=["src","alt"],Yc=a.defineComponent({__name:"ImageBlock",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("ImageBlock must be used within a WovenCanvas component");const s=r,i=fe(o.entityId,w.Asset),l=fe(o.entityId,w.Image),c=s.getAssetManager(),d=a.computed(()=>{const C=i.value;return!(C!=null&&C.identifier)||C.uploadState!==w.UploadState.Pending&&C.uploadState!==w.UploadState.Uploading?!1:!(c!=null&&c.hasPendingUpload(C.identifier))});function u(){var E,M;const[C,v]=o.block.size;return{width:xr(C,((E=l.value)==null?void 0:E.width)??0),height:xr(v,((M=l.value)==null?void 0:M.height)??0)}}const f={width:0,height:0},h=i.value;let p=null;if(c&&(h!=null&&h.identifier)&&!d.value){const C=u();f.width=C.width,f.height=C.height,p=([e,t]=a.withAsyncContext(()=>c.getDisplayUrl(h.identifier,C)),e=await e,t(),e)}const m=a.ref(p),g=a.ref(!p),y=a.ref(!1);let k=!0;a.onUnmounted(()=>{k=!1});function x(C){if(typeof window>"u"||!m.value){m.value=C,g.value=!1;return}const v=new window.Image;v.onload=()=>{k&&(m.value=C,g.value=!1)},v.onerror=()=>{k&&(g.value=!1)},v.src=C}async function b(){const C=i.value;if(!C){g.value=!1;return}if(d.value){m.value=null,g.value=!0,y.value=!1;return}try{g.value=!0,y.value=!1;const v=u();f.width=v.width,f.height=v.height;const E=await(c==null?void 0:c.getDisplayUrl(C.identifier,v));if(!k)return;E?x(E):C.uploadState===w.UploadState.Failed&&(y.value=!0,g.value=!1)}catch(v){if(!k)return;console.error("Failed to get display URL:",v),y.value=!0,g.value=!1}}a.watch(()=>i.value,()=>{b()},{immediate:!0}),a.onMounted(()=>{b()}),a.watch(()=>[o.block.size[0],o.block.size[1]],()=>{const C=u();(C.width>f.width||C.height>f.height)&&b()});const S=a.computed(()=>({width:"100%",height:"100%",objectFit:"fill"}));return(C,v)=>{var E;return a.openBlock(),a.createElementBlock("div",C0,[d.value?(a.openBlock(),a.createElementBlock("div",E0,[...v[0]||(v[0]=[a.createElementVNode("div",{class:"wov-image-spinner","aria-label":"Loading image"},null,-1)])])):g.value&&!m.value?(a.openBlock(),a.createElementBlock("div",v0)):y.value?(a.openBlock(),a.createElementBlock("div",M0,[...v[1]||(v[1]=[a.createElementVNode("span",null,"Failed to save image",-1)])])):m.value?(a.openBlock(),a.createElementBlock("img",{key:3,src:m.value,alt:((E=a.unref(l))==null?void 0:E.alt)||"",style:a.normalizeStyle(S.value),draggable:"false"},null,12,T0)):a.createCommentVNode("",!0)])}}}),N0=["data-complete"],A0={preserveAspectRatio:"none"},B0=["d","fill","fill-rule"],I0={key:0,class:"highlight",preserveAspectRatio:"none"},O0=["d"],Xc=kn(a.defineComponent({__name:"PenStroke",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,yn.PenStroke),o=fe(e.entityId,w.Block),r=fe(e.entityId,w.Color),s=a.shallowRef(""),i=a.shallowRef(""),l=a.shallowRef([]);function c(m,g){return(m+g)/2}function d(m,g,y){if(g<=1||m.length<3){const C=y/2;return`M ${C},0 a ${C},${C} 0 1 0 0.0001 0`}let k=m[0],x=m[1];const b=m[2];let S=`M${k[0].toFixed(2)},${k[1].toFixed(2)} Q${x[0].toFixed(2)},${x[1].toFixed(2)} ${c(x[0],b[0]).toFixed(2)},${c(x[1],b[1]).toFixed(2)} T`;for(let C=2;C<m.length-1;C++)k=m[C],x=m[C+1],S+=`${c(k[0],x[0]).toFixed(2)},${c(k[1],x[1]).toFixed(2)} `;return S+=`${x[0].toFixed(2)},${x[1].toFixed(2)} `,S+="Z",S}function u(m){if(m.length<3)return"";let g=`M${m[0][0].toFixed(2)},${m[0][1].toFixed(2)} `;for(let k=1;k<m.length-1;k++){const x=c(m[k][0],m[k+1][0]),b=c(m[k][1],m[k+1][1]);g+=`Q${m[k][0].toFixed(2)},${m[k][1].toFixed(2)} ${x.toFixed(2)},${b.toFixed(2)} `}const y=m[m.length-1];return g+=`L${y[0].toFixed(2)},${y[1].toFixed(2)} `,g+="Z",g}a.watch([t,o],([m,g])=>{if(!m||!g){s.value="",i.value="",l.value=[];return}if(!m.originalWidth||!m.originalHeight){s.value="",i.value="",l.value=[];return}const y=g.size[0]/m.originalWidth,k=g.size[1]/m.originalHeight,x=[];for(let S=0;S<m.pointCount;S++){const C=m.points[S*2],v=m.points[S*2+1],E=(C-m.originalLeft)*y,M=(v-m.originalTop)*k;m.hasPressure?x.push([E,M,m.pressures[S]]):x.push([E,M])}if(l.value=[],m.kind===yn.PenStrokeKind.Fill){const S=u(x);s.value=S,m.isComplete&&(i.value=S);return}const b=Oi(x,{last:m.isComplete,size:m.thickness,simulatePressure:!m.hasPressure});if(s.value=d(b,m.pointCount,m.thickness),m.isComplete){const S=x.length===1?m.thickness:1,C=Oi(x,{last:!0,size:S,simulatePressure:!m.hasPressure});i.value=d(C,m.pointCount,S)}},{immediate:!0});const f=a.computed(()=>{var m;return((m=t.value)==null?void 0:m.kind)===yn.PenStrokeKind.Fill?"evenodd":"nonzero"}),h=a.computed(()=>{if(!r.value)return"#000000";const{red:m,green:g,blue:y,alpha:k}=r.value;return`rgba(${m}, ${g}, ${y}, ${(k??255)/255})`}),p=a.computed(()=>e.selected||e.hovered);return(m,g)=>{var y;return a.openBlock(),a.createElementBlock("div",{class:"wov-pen-stroke","data-complete":((y=a.unref(t))==null?void 0:y.isComplete)||void 0},[(a.openBlock(),a.createElementBlock("svg",A0,[a.createElementVNode("path",{d:s.value,fill:h.value,"fill-rule":f.value},null,8,B0)])),p.value?(a.openBlock(),a.createElementBlock("svg",I0,[a.createElementVNode("path",{d:i.value,stroke:"var(--wov-highlighted-block-outline-color)",style:{"stroke-width":"calc(1px / var(--wov-zoom))"},fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},null,8,O0)])):a.createCommentVNode("",!0),a.createCommentVNode("",!0)],8,N0)}}}),[["__scopeId","data-v-bfbffe8c"]]),_0={class:"wov-selection-box"},Qc=a.defineComponent({__name:"SelectionBox",setup(n){return(e,t)=>(a.openBlock(),a.createElementBlock("div",_0))}}),Co={rectangle:"M0,0 L100,0 L100,100 L0,100 Z",ellipse:"M50,0 A50,50 0 1,1 50,100 A50,50 0 1,1 50,0",triangle:"M50,0 L100,100 L0,100 Z",diamond:"M50,0 L100,50 L50,100 L0,50 Z",pentagon:"M50,0 L100,38.2 L80.9,100 L19.1,100 L0,38.2 Z",hexagon:"M50,0 L100,25 L100,75 L50,100 L0,75 L0,25 Z",star:"M50,0 L61.8,38.2 L100,38.2 L69.1,61.8 L80.9,100 L50,76.4 L19.1,100 L30.9,61.8 L0,38.2 L38.2,38.2 Z",heart:"M50,16 C44,7 37,0 26,0 11,0 0,12 0,28 0,60 16,65 50,100 84,65 100,60 100,28 100,12 89,0 74,0 63,0 56,7 50,16 Z",arrow:"M0,35 L60,35 L60,0 L100,50 L60,100 L60,65 L0,65 Z"};function Ne(n){this.content=n}Ne.prototype={constructor:Ne,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var o=t&&t!=n?this.remove(t):this,r=o.find(n),s=o.content.slice();return r==-1?s.push(t||n,e):(s[r+1]=e,t&&(s[r]=t)),new Ne(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new Ne(t)},addToStart:function(n,e){return new Ne([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Ne(t)},addBefore:function(n,e,t){var o=this.remove(e),r=o.content.slice(),s=o.find(n);return r.splice(s==-1?r.length:s,0,e,t),new Ne(r)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=Ne.from(n),n.size?new Ne(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Ne.from(n),n.size?new Ne(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Ne.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}},Ne.from=function(n){if(n instanceof Ne)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Ne(e)};function Zc(n,e,t){for(let o=0;;o++){if(o==n.childCount||o==e.childCount)return n.childCount==e.childCount?null:t;let r=n.child(o),s=e.child(o);if(r==s){t+=r.nodeSize;continue}if(!r.sameMarkup(s))return t;if(r.isText&&r.text!=s.text){for(let i=0;r.text[i]==s.text[i];i++)t++;return t}if(r.content.size||s.content.size){let i=Zc(r.content,s.content,t+1);if(i!=null)return i}t+=r.nodeSize}}function ed(n,e,t,o){for(let r=n.childCount,s=e.childCount;;){if(r==0||s==0)return r==s?null:{a:t,b:o};let i=n.child(--r),l=e.child(--s),c=i.nodeSize;if(i==l){t-=c,o-=c;continue}if(!i.sameMarkup(l))return{a:t,b:o};if(i.isText&&i.text!=l.text){let d=0,u=Math.min(i.text.length,l.text.length);for(;d<u&&i.text[i.text.length-d-1]==l.text[l.text.length-d-1];)d++,t--,o--;return{a:t,b:o}}if(i.content.size||l.content.size){let d=ed(i.content,l.content,t-1,o-1);if(d)return d}t-=c,o-=c}}class P{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let o=0;o<e.length;o++)this.size+=e[o].nodeSize}nodesBetween(e,t,o,r=0,s){for(let i=0,l=0;l<t;i++){let c=this.content[i],d=l+c.nodeSize;if(d>e&&o(c,r+l,s||null,i)!==!1&&c.content.size){let u=l+1;c.nodesBetween(Math.max(0,e-u),Math.min(c.content.size,t-u),o,r+u)}l=d}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,o,r){let s="",i=!0;return this.nodesBetween(e,t,(l,c)=>{let d=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?r?typeof r=="function"?r(l):r:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&d||l.isTextblock)&&o&&(i?i=!1:s+=o),s+=d},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,o=e.firstChild,r=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(o)&&(r[r.length-1]=t.withText(t.text+o.text),s=1);s<e.content.length;s++)r.push(e.content[s]);return new P(r,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let o=[],r=0;if(t>e)for(let s=0,i=0;i<t;s++){let l=this.content[s],c=i+l.nodeSize;c>e&&((i<e||c>t)&&(l.isText?l=l.cut(Math.max(0,e-i),Math.min(l.text.length,t-i)):l=l.cut(Math.max(0,e-i-1),Math.min(l.content.size,t-i-1))),o.push(l),r+=l.nodeSize),i=c}return new P(o,r)}cutByIndex(e,t){return e==t?P.empty:e==0&&t==this.content.length?this:new P(this.content.slice(e,t))}replaceChild(e,t){let o=this.content[e];if(o==t)return this;let r=this.content.slice(),s=this.size+t.nodeSize-o.nodeSize;return r[e]=t,new P(r,s)}addToStart(e){return new P([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new P(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,o=0;t<this.content.length;t++){let r=this.content[t];e(r,o,t),o+=r.nodeSize}}findDiffStart(e,t=0){return Zc(this,e,t)}findDiffEnd(e,t=this.size,o=e.size){return ed(this,e,t,o)}findIndex(e){if(e==0)return Cr(0,e);if(e==this.size)return Cr(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,o=0;;t++){let r=this.child(t),s=o+r.nodeSize;if(s>=e)return s==e?Cr(t+1,s):Cr(t,o);o=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return P.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new P(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return P.empty;let t,o=0;for(let r=0;r<e.length;r++){let s=e[r];o+=s.nodeSize,r&&s.isText&&e[r-1].sameMarkup(s)?(t||(t=e.slice(0,r)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new P(t||e,o)}static from(e){if(!e)return P.empty;if(e instanceof P)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new P([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}P.empty=new P([],0);const _i={index:0,offset:0};function Cr(n,e){return _i.index=n,_i.offset=e,_i}function Er(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let o=0;o<n.length;o++)if(!Er(n[o],e[o]))return!1}else{for(let o in n)if(!(o in e)||!Er(n[o],e[o]))return!1;for(let o in e)if(!(o in n))return!1}return!0}let se=class xc{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,o=!1;for(let r=0;r<e.length;r++){let s=e[r];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,r));else{if(s.type.excludes(this.type))return e;!o&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,r)),t.push(this),o=!0),t&&t.push(s)}}return t||(t=e.slice()),o||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Er(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let o=e.marks[t.type];if(!o)throw new RangeError(`There is no mark type ${t.type} in this schema`);let r=o.create(t.attrs);return o.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let o=0;o<e.length;o++)if(!e[o].eq(t[o]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return xc.none;if(e instanceof xc)return[e];let t=e.slice();return t.sort((o,r)=>o.type.rank-r.type.rank),t}};se.none=[];class vr extends Error{}class U{constructor(e,t,o){this.content=e,this.openStart=t,this.openEnd=o}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let o=nd(this.content,e+this.openStart,t);return o&&new U(o,this.openStart,this.openEnd)}removeBetween(e,t){return new U(td(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return U.empty;let o=t.openStart||0,r=t.openEnd||0;if(typeof o!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new U(P.fromJSON(e,t.content),o,r)}static maxOpen(e,t=!0){let o=0,r=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)o++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)r++;return new U(e,o,r)}}U.empty=new U(P.empty,0,0);function td(n,e,t){let{index:o,offset:r}=n.findIndex(e),s=n.maybeChild(o),{index:i,offset:l}=n.findIndex(t);if(r==e||s.isText){if(l!=t&&!n.child(i).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(o!=i)throw new RangeError("Removing non-flat range");return n.replaceChild(o,s.copy(td(s.content,e-r-1,t-r-1)))}function nd(n,e,t,o){let{index:r,offset:s}=n.findIndex(e),i=n.maybeChild(r);if(s==e||i.isText)return o&&!o.canReplace(r,r,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=nd(i.content,e-s-1,t,i);return l&&n.replaceChild(r,i.copy(l))}function D0(n,e,t){if(t.openStart>n.depth)throw new vr("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new vr("Inconsistent open depths");return od(n,e,t,0)}function od(n,e,t,o){let r=n.index(o),s=n.node(o);if(r==e.index(o)&&o<n.depth-t.openStart){let i=od(n,e,t,o+1);return s.copy(s.content.replaceChild(r,i))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==o&&e.depth==o){let i=n.parent,l=i.content;return bn(i,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:i,end:l}=R0(t,n);return bn(s,sd(n,i,l,e,o))}else return bn(s,Mr(n,e,o))}function rd(n,e){if(!e.type.compatibleContent(n.type))throw new vr("Cannot join "+e.type.name+" onto "+n.type.name)}function Di(n,e,t){let o=n.node(t);return rd(o,e.node(t)),o}function wn(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Eo(n,e,t,o){let r=(e||n).node(t),s=0,i=e?e.index(t):r.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(wn(n.nodeAfter,o),s++));for(let l=s;l<i;l++)wn(r.child(l),o);e&&e.depth==t&&e.textOffset&&wn(e.nodeBefore,o)}function bn(n,e){return n.type.checkContent(e),n.copy(e)}function sd(n,e,t,o,r){let s=n.depth>r&&Di(n,e,r+1),i=o.depth>r&&Di(t,o,r+1),l=[];return Eo(null,n,r,l),s&&i&&e.index(r)==t.index(r)?(rd(s,i),wn(bn(s,sd(n,e,t,o,r+1)),l)):(s&&wn(bn(s,Mr(n,e,r+1)),l),Eo(e,t,r,l),i&&wn(bn(i,Mr(t,o,r+1)),l)),Eo(o,null,r,l),new P(l)}function Mr(n,e,t){let o=[];if(Eo(null,n,t,o),n.depth>t){let r=Di(n,e,t+1);wn(bn(r,Mr(n,e,t+1)),o)}return Eo(e,null,t,o),new P(o)}function R0(n,e){let t=e.depth-n.openStart,r=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)r=e.node(s).copy(P.from(r));return{start:r.resolveNoCache(n.openStart+t),end:r.resolveNoCache(r.content.size-n.openEnd-t)}}class vo{constructor(e,t,o){this.pos=e,this.path=t,this.parentOffset=o,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let o=this.pos-this.path[this.path.length-1],r=e.child(t);return o?e.child(t).cut(o):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let o=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)r+=o.child(s).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return se.none;if(this.textOffset)return e.child(t).marks;let o=e.maybeChild(t-1),r=e.maybeChild(t);if(!o){let l=o;o=r,r=l}let s=o.marks;for(var i=0;i<s.length;i++)s[i].type.spec.inclusive===!1&&(!r||!s[i].isInSet(r.marks))&&(s=s[i--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let o=t.marks,r=e.parent.maybeChild(e.index());for(var s=0;s<o.length;s++)o[s].type.spec.inclusive===!1&&(!r||!o[s].isInSet(r.marks))&&(o=o[s--].removeFromSet(o));return o}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let o=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);o>=0;o--)if(e.pos<=this.end(o)&&(!t||t(this.node(o))))return new Tr(this,e,o);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let o=[],r=0,s=t;for(let i=e;;){let{index:l,offset:c}=i.content.findIndex(s),d=s-c;if(o.push(i,l,r+c),!d||(i=i.child(l),i.isText))break;s=d-1,r+=c+1}return new vo(t,o,s)}static resolveCached(e,t){let o=id.get(e);if(o)for(let s=0;s<o.elts.length;s++){let i=o.elts[s];if(i.pos==t)return i}else id.set(e,o=new P0);let r=o.elts[o.i]=vo.resolve(e,t);return o.i=(o.i+1)%L0,r}}class P0{constructor(){this.elts=[],this.i=0}}const L0=12,id=new WeakMap;class Tr{constructor(e,t,o){this.$from=e,this.$to=t,this.depth=o}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}}const V0=Object.create(null);let At=class Cc{constructor(e,t,o,r=se.none){this.type=e,this.attrs=t,this.marks=r,this.content=o||P.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,o,r=0){this.content.nodesBetween(e,t,o,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,o,r){return this.content.textBetween(e,t,o,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,o){return this.type==e&&Er(this.attrs,t||e.defaultAttrs||V0)&&se.sameSet(this.marks,o||se.none)}copy(e=null){return e==this.content?this:new Cc(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Cc(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,o=!1){if(e==t)return U.empty;let r=this.resolve(e),s=this.resolve(t),i=o?0:r.sharedDepth(t),l=r.start(i),d=r.node(i).content.cut(r.pos-l,s.pos-l);return new U(d,r.depth-i,s.depth-i)}replace(e,t,o){return D0(this.resolve(e),this.resolve(t),o)}nodeAt(e){for(let t=this;;){let{index:o,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(o),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:o}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:o}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:o}=this.content.findIndex(e);if(o<e)return{node:this.content.child(t),index:t,offset:o};let r=this.content.child(t-1);return{node:r,index:t-1,offset:o-r.nodeSize}}resolve(e){return vo.resolveCached(this,e)}resolveNoCache(e){return vo.resolve(this,e)}rangeHasMark(e,t,o){let r=!1;return t>e&&this.nodesBetween(e,t,s=>(o.isInSet(s.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),ld(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,o=P.empty,r=0,s=o.childCount){let i=this.contentMatchAt(e).matchFragment(o,r,s),l=i&&i.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=r;c<s;c++)if(!this.type.allowsMarks(o.child(c).marks))return!1;return!0}canReplaceWith(e,t,o,r){if(r&&!this.type.allowsMarks(r))return!1;let s=this.contentMatchAt(e).matchType(o),i=s&&s.matchFragment(this.content,t);return i?i.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=se.none;for(let t=0;t<this.marks.length;t++){let o=this.marks[t];o.type.checkAttrs(o.attrs),e=o.addToSet(e)}if(!se.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let o;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");o=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,o)}let r=P.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,r,o);return s.type.checkAttrs(s.attrs),s}};At.prototype.text=void 0;class Nr extends At{constructor(e,t,o,r){if(super(e,t,null,r),!o)throw new RangeError("Empty text nodes are not allowed");this.text=o}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ld(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new Nr(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new Nr(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function ld(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class Sn{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let o=new $0(e,t);if(o.next==null)return Sn.empty;let r=ad(o);o.next&&o.err("Unexpected trailing text");let s=K0(W0(r));return q0(s,o),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,o=e.childCount){let r=this;for(let s=t;r&&s<o;s++)r=r.matchType(e.child(s).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let o=0;o<e.next.length;o++)if(this.next[t].type==e.next[o].type)return!0;return!1}fillBefore(e,t=!1,o=0){let r=[this];function s(i,l){let c=i.matchFragment(e,o);if(c&&(!t||c.validEnd))return P.from(l.map(d=>d.createAndFill()));for(let d=0;d<i.next.length;d++){let{type:u,next:f}=i.next[d];if(!(u.isText||u.hasRequiredAttrs())&&r.indexOf(f)==-1){r.push(f);let h=s(f,l.concat(u));if(h)return h}}return null}return s(this,[])}findWrapping(e){for(let o=0;o<this.wrapCache.length;o+=2)if(this.wrapCache[o]==e)return this.wrapCache[o+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),o=[{match:this,type:null,via:null}];for(;o.length;){let r=o.shift(),s=r.match;if(s.matchType(e)){let i=[];for(let l=r;l.type;l=l.via)i.push(l.type);return i.reverse()}for(let i=0;i<s.next.length;i++){let{type:l,next:c}=s.next[i];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!r.type||c.validEnd)&&(o.push({match:l.contentMatch,type:l,via:r}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(o){e.push(o);for(let r=0;r<o.next.length;r++)e.indexOf(o.next[r].next)==-1&&t(o.next[r].next)}return t(this),e.map((o,r)=>{let s=r+(o.validEnd?"*":" ")+" ";for(let i=0;i<o.next.length;i++)s+=(i?", ":"")+o.next[i].type.name+"->"+e.indexOf(o.next[i].next);return s}).join(`
|
|
2
|
+
`)}}Sn.empty=new Sn(!0);class $0{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function ad(n){let e=[];do e.push(z0(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function z0(n){let e=[];do e.push(F0(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function F0(n){let e=U0(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=H0(n,e);else break;return e}function cd(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function H0(n,e){let t=cd(n),o=t;return n.eat(",")&&(n.next!="}"?o=cd(n):o=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:o,expr:e}}function j0(n,e){let t=n.nodeTypes,o=t[e];if(o)return[o];let r=[];for(let s in t){let i=t[s];i.isInGroup(e)&&r.push(i)}return r.length==0&&n.err("No node type or group '"+e+"' found"),r}function U0(n){if(n.eat("(")){let e=ad(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=j0(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function W0(n){let e=[[]];return r(s(n,0),t()),e;function t(){return e.push([])-1}function o(i,l,c){let d={term:c,to:l};return e[i].push(d),d}function r(i,l){i.forEach(c=>c.to=l)}function s(i,l){if(i.type=="choice")return i.exprs.reduce((c,d)=>c.concat(s(d,l)),[]);if(i.type=="seq")for(let c=0;;c++){let d=s(i.exprs[c],l);if(c==i.exprs.length-1)return d;r(d,l=t())}else if(i.type=="star"){let c=t();return o(l,c),r(s(i.expr,c),c),[o(c)]}else if(i.type=="plus"){let c=t();return r(s(i.expr,l),c),r(s(i.expr,c),c),[o(c)]}else{if(i.type=="opt")return[o(l)].concat(s(i.expr,l));if(i.type=="range"){let c=l;for(let d=0;d<i.min;d++){let u=t();r(s(i.expr,c),u),c=u}if(i.max==-1)r(s(i.expr,c),c);else for(let d=i.min;d<i.max;d++){let u=t();o(c,u),r(s(i.expr,c),u),c=u}return[o(c)]}else{if(i.type=="name")return[o(l,void 0,i.value)];throw new Error("Unknown expr type")}}}}function dd(n,e){return e-n}function ud(n,e){let t=[];return o(e),t.sort(dd);function o(r){let s=n[r];if(s.length==1&&!s[0].term)return o(s[0].to);t.push(r);for(let i=0;i<s.length;i++){let{term:l,to:c}=s[i];!l&&t.indexOf(c)==-1&&o(c)}}}function K0(n){let e=Object.create(null);return t(ud(n,0));function t(o){let r=[];o.forEach(i=>{n[i].forEach(({term:l,to:c})=>{if(!l)return;let d;for(let u=0;u<r.length;u++)r[u][0]==l&&(d=r[u][1]);ud(n,c).forEach(u=>{d||r.push([l,d=[]]),d.indexOf(u)==-1&&d.push(u)})})});let s=e[o.join(",")]=new Sn(o.indexOf(n.length-1)>-1);for(let i=0;i<r.length;i++){let l=r[i][1].sort(dd);s.next.push({type:r[i][0],next:e[l.join(",")]||t(l)})}return s}}function q0(n,e){for(let t=0,o=[n];t<o.length;t++){let r=o[t],s=!r.validEnd,i=[];for(let l=0;l<r.next.length;l++){let{type:c,next:d}=r.next[l];i.push(c.name),s&&!(c.isText||c.hasRequiredAttrs())&&(s=!1),o.indexOf(d)==-1&&o.push(d)}s&&e.err("Only non-generatable nodes ("+i.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function fd(n){let e=Object.create(null);for(let t in n){let o=n[t];if(!o.hasDefault)return null;e[t]=o.default}return e}function hd(n,e){let t=Object.create(null);for(let o in n){let r=e&&e[o];if(r===void 0){let s=n[o];if(s.hasDefault)r=s.default;else throw new RangeError("No value supplied for attribute "+o)}t[o]=r}return t}function pd(n,e,t,o){for(let r in e)if(!(r in n))throw new RangeError(`Unsupported attribute ${r} for ${t} of type ${r}`);for(let r in n){let s=n[r];s.validate&&s.validate(e[r])}}function md(n,e){let t=Object.create(null);if(e)for(let o in e)t[o]=new G0(n,o,e[o]);return t}let gd=class vg{constructor(e,t,o){this.name=e,this.schema=t,this.spec=o,this.markSet=null,this.groups=o.group?o.group.split(" "):[],this.attrs=md(e,o.attrs),this.defaultAttrs=fd(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(o.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==Sn.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:hd(this.attrs,e)}create(e=null,t,o){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new At(this,this.computeAttrs(e),P.from(t),se.setFrom(o))}createChecked(e=null,t,o){return t=P.from(t),this.checkContent(t),new At(this,this.computeAttrs(e),t,se.setFrom(o))}createAndFill(e=null,t,o){if(e=this.computeAttrs(e),t=P.from(t),t.size){let i=this.contentMatch.fillBefore(t);if(!i)return null;t=i.append(t)}let r=this.contentMatch.matchFragment(t),s=r&&r.fillBefore(P.empty,!0);return s?new At(this,e,t.append(s),se.setFrom(o)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let o=0;o<e.childCount;o++)if(!this.allowsMarks(e.child(o).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){pd(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let o=0;o<e.length;o++)this.allowsMarkType(e[o].type)?t&&t.push(e[o]):t||(t=e.slice(0,o));return t?t.length?t:se.none:e}static compile(e,t){let o=Object.create(null);e.forEach((s,i)=>o[s]=new vg(s,t,i));let r=t.spec.topNode||"doc";if(!o[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!o.text)throw new RangeError("Every schema needs a 'text' type");for(let s in o.text.attrs)throw new RangeError("The text node type should not have attributes");return o}};function J0(n,e,t){let o=t.split("|");return r=>{let s=r===null?"null":typeof r;if(o.indexOf(s)<0)throw new RangeError(`Expected value of type ${o} for attribute ${e} on type ${n}, got ${s}`)}}class G0{constructor(e,t,o){this.hasDefault=Object.prototype.hasOwnProperty.call(o,"default"),this.default=o.default,this.validate=typeof o.validate=="string"?J0(e,t,o.validate):o.validate}get isRequired(){return!this.hasDefault}}class Ar{constructor(e,t,o,r){this.name=e,this.rank=t,this.schema=o,this.spec=r,this.attrs=md(e,r.attrs),this.excluded=null;let s=fd(this.attrs);this.instance=s?new se(this,s):null}create(e=null){return!e&&this.instance?this.instance:new se(this,hd(this.attrs,e))}static compile(e,t){let o=Object.create(null),r=0;return e.forEach((s,i)=>o[s]=new Ar(s,r++,t,i)),o}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){pd(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class yd{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let r in e)t[r]=e[r];t.nodes=Ne.from(e.nodes),t.marks=Ne.from(e.marks||{}),this.nodes=gd.compile(this.spec.nodes,this),this.marks=Ar.compile(this.spec.marks,this);let o=Object.create(null);for(let r in this.nodes){if(r in this.marks)throw new RangeError(r+" can not be both a node and a mark");let s=this.nodes[r],i=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=o[i]||(o[i]=Sn.parse(i,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?kd(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let r in this.marks){let s=this.marks[r],i=s.spec.excludes;s.excluded=i==null?[s]:i==""?[]:kd(this,i.split(" "))}this.nodeFromJSON=r=>At.fromJSON(this,r),this.markFromJSON=r=>se.fromJSON(this,r),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,o,r){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof gd){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,o,r)}text(e,t){let o=this.nodes.text;return new Nr(o,o.defaultAttrs,e,se.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function kd(n,e){let t=[];for(let o=0;o<e.length;o++){let r=e[o],s=n.marks[r],i=s;if(s)t.push(s);else for(let l in n.marks){let c=n.marks[l];(r=="_"||c.spec.group&&c.spec.group.split(" ").indexOf(r)>-1)&&t.push(i=c)}if(!i)throw new SyntaxError("Unknown mark type: '"+e[o]+"'")}return t}function Y0(n){return n.tag!=null}function X0(n){return n.style!=null}class Bt{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let o=this.matchedStyles=[];t.forEach(r=>{if(Y0(r))this.tags.push(r);else if(X0(r)){let s=/[^=]*/.exec(r.style)[0];o.indexOf(s)<0&&o.push(s),this.styles.push(r)}}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let s=e.nodes[r.node];return s.contentMatch.matchType(s)})}parse(e,t={}){let o=new xd(this,t,!1);return o.addAll(e,se.none,t.from,t.to),o.finish()}parseSlice(e,t={}){let o=new xd(this,t,!0);return o.addAll(e,se.none,t.from,t.to),U.maxOpen(o.finish())}matchTag(e,t,o){for(let r=o?this.tags.indexOf(o)+1:0;r<this.tags.length;r++){let s=this.tags[r];if(ey(e,s.tag)&&(s.namespace===void 0||e.namespaceURI==s.namespace)&&(!s.context||t.matchesContext(s.context))){if(s.getAttrs){let i=s.getAttrs(e);if(i===!1)continue;s.attrs=i||void 0}return s}}}matchStyle(e,t,o,r){for(let s=r?this.styles.indexOf(r)+1:0;s<this.styles.length;s++){let i=this.styles[s],l=i.style;if(!(l.indexOf(e)!=0||i.context&&!o.matchesContext(i.context)||l.length>e.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(i.getAttrs){let c=i.getAttrs(t);if(c===!1)continue;i.attrs=c||void 0}return i}}}static schemaRules(e){let t=[];function o(r){let s=r.priority==null?50:r.priority,i=0;for(;i<t.length;i++){let l=t[i];if((l.priority==null?50:l.priority)<s)break}t.splice(i,0,r)}for(let r in e.marks){let s=e.marks[r].spec.parseDOM;s&&s.forEach(i=>{o(i=Cd(i)),i.mark||i.ignore||i.clearMark||(i.mark=r)})}for(let r in e.nodes){let s=e.nodes[r].spec.parseDOM;s&&s.forEach(i=>{o(i=Cd(i)),i.node||i.ignore||i.mark||(i.node=r)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Bt(e,Bt.schemaRules(e)))}}const wd={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},Q0={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},bd={ol:!0,ul:!0},Mo=1,Ri=2,To=4;function Sd(n,e,t){return e!=null?(e?Mo:0)|(e==="full"?Ri:0):n&&n.whitespace=="pre"?Mo|Ri:t&~To}class Br{constructor(e,t,o,r,s,i){this.type=e,this.attrs=t,this.marks=o,this.solid=r,this.options=i,this.content=[],this.activeMarks=se.none,this.match=s||(i&To?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(P.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let o=this.type.contentMatch,r;return(r=o.findWrapping(e.type))?(this.match=o,r):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Mo)){let o=this.content[this.content.length-1],r;if(o&&o.isText&&(r=/[ \t\r\n\u000c]+$/.exec(o.text))){let s=o;o.text.length==r[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-r[0].length))}}let t=P.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(P.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!wd.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class xd{constructor(e,t,o){this.parser=e,this.options=t,this.isOpen=o,this.open=0,this.localPreserveWS=!1;let r=t.topNode,s,i=Sd(null,t.preserveWhitespace,0)|(o?To:0);r?s=new Br(r.type,r.attrs,se.none,!0,t.topMatch||r.type.contentMatch,i):o?s=new Br(null,null,se.none,!0,null,i):s=new Br(e.schema.topNodeType,null,se.none,!0,null,i),this.nodes=[s],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let o=e.nodeValue,r=this.top,s=r.options&Ri?"full":this.localPreserveWS||(r.options&Mo)>0,{schema:i}=this.parser;if(s==="full"||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(o)){if(s)if(s==="full")o=o.replace(/\r\n?/g,`
|
|
3
3
|
`);else if(i.linebreakReplacement&&/[\r\n]/.test(o)&&this.top.findWrapping(i.linebreakReplacement.create())){let l=o.split(/\r?\n|\r/);for(let c=0;c<l.length;c++)c&&this.insertNode(i.linebreakReplacement.create(),t,!0),l[c]&&this.insertNode(i.text(l[c]),t,!/\S/.test(l[c]));o=""}else o=o.replace(/\r?\n|\r/g," ");else if(o=o.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(o)&&this.open==this.nodes.length-1){let l=r.content[r.content.length-1],c=e.previousSibling;(!l||c&&c.nodeName=="BR"||l.isText&&/[ \t\r\n\u000c]$/.test(l.text))&&(o=o.slice(1))}o&&this.insertNode(i.text(o),t,!/\S/.test(o)),this.findInText(e)}else this.findInside(e)}addElement(e,t,o){let r=this.localPreserveWS,s=this.top;(e.tagName=="PRE"||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let i=e.nodeName.toLowerCase(),l;bd.hasOwnProperty(i)&&this.parser.normalizeLists&&Z0(e);let c=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,o));e:if(c?c.ignore:Q0.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!c||c.skip||c.closeParent){c&&c.closeParent?this.open=Math.max(0,this.open-1):c&&c.skip.nodeType&&(e=c.skip);let d,u=this.needsBlock;if(wd.hasOwnProperty(i))s.content.length&&s.content[0].isInline&&this.open&&(this.open--,s=this.top),d=!0,s.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let f=c&&c.skip?t:this.readStyles(e,t);f&&this.addAll(e,f),d&&this.sync(s),this.needsBlock=u}else{let d=this.readStyles(e,t);d&&this.addElementByRule(e,c,d,c.consuming===!1?l:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
|
|
4
|
-
`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let o=e.style;if(o&&o.length)for(let r=0;r<this.parser.matchedStyles.length;r++){let s=this.parser.matchedStyles[r],i=o.getPropertyValue(s);if(i)for(let l=void 0;;){let c=this.parser.matchStyle(s,i,this,l);if(!c)break;if(c.ignore)return null;if(c.clearMark?t=t.filter(d=>!c.clearMark(d)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,o,r){let s,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),o,e.nodeName=="BR")||this.leafFallback(e,o);else{let c=this.enter(i,t.attrs||null,o,t.preserveWhitespace);c&&(s=!0,o=c)}else{let c=this.parser.schema.marks[t.mark];o=o.concat(c.create(t.attrs))}let l=this.top;if(i&&i.isLeaf)this.findInside(e);else if(r)this.addElement(e,o,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,o,!1));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,o),this.findAround(e,c,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,o,r){let s=o||0;for(let i=o?e.childNodes[o]:e.firstChild,l=r==null?null:e.childNodes[r];i!=l;i=i.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(i,t);this.findAtPoint(e,s)}findPlace(e,t,o){let r,s;for(let i=this.open,l=0;i>=0;i--){let c=this.nodes[i],d=c.findWrapping(e);if(d&&(!r||r.length>d.length+l)&&(r=d,s=c,!d.length))break;if(c.solid){if(o)break;l+=2}}if(!r)return null;this.sync(s);for(let i=0;i<r.length;i++)t=this.enterInner(r[i],null,t,!1);return t}insertNode(e,t,o){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let r=this.findPlace(e,t,o);if(r){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let i=se.none;for(let l of r.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):Ed(l.type,e.type))&&(i=l.addToSet(i));return s.content.push(e.mark(i)),!0}return!1}enter(e,t,o,r){let s=this.findPlace(e.create(t),o,!1);return s&&(s=this.enterInner(e,t,o,!0,r)),s}enterInner(e,t,o,r=!1,s){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let l=Sd(e,s,i.options);i.options&Mo&&i.content.length==0&&(l|=Mo);let c=se.none;return o=o.filter(d=>(i.type?i.type.allowsMarkType(d.type):Ed(d.type,e))?(c=d.addToSet(c),!1):!0),this.nodes.push(new Br(e,t,c,r,null,l)),this.open++,o}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=To)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let o=this.nodes[t].content;for(let r=o.length-1;r>=0;r--)e+=o[r].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let o=0;o<this.find.length;o++)this.find[o].node==e&&this.find[o].offset==t&&(this.find[o].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,o){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(o?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),o=this.options.context,r=!this.isOpen&&(!o||o.parent.type==this.nodes[0].type),s=-(o?o.depth+1:0)+(r?0:1),i=(l,c)=>{for(;l>=0;l--){let d=t[l];if(d==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(i(l-1,c))return!0;return!1}else{let u=c>0||c==0&&r?this.nodes[c].type:o&&c>=s?o.node(c-s).type:null;if(!u||u.name!=d&&!u.isInGroup(d))return!1;c--}}return!0};return i(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let o=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(o&&o.isTextblock&&o.defaultAttrs)return o}for(let t in this.parser.schema.nodes){let o=this.parser.schema.nodes[t];if(o.isTextblock&&o.defaultAttrs)return o}}}function Z0(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let o=e.nodeType==1?e.nodeName.toLowerCase():null;o&&bd.hasOwnProperty(o)&&t?(t.appendChild(e),e=t):o=="li"?t=e:o&&(t=null)}}function ey(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Cd(n){let e={};for(let t in n)e[t]=n[t];return e}function Ed(n,e){let t=e.schema.nodes;for(let o in t){let r=t[o];if(!r.allowsMarkType(n))continue;let s=[],i=l=>{s.push(l);for(let c=0;c<l.edgeCount;c++){let{type:d,next:u}=l.edge(c);if(d==e||s.indexOf(u)<0&&i(u))return!0}};if(i(r.contentMatch))return!0}}class xn{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},o){o||(o=Pi(t).createDocumentFragment());let r=o,s=[];return e.forEach(i=>{if(s.length||i.marks.length){let l=0,c=0;for(;l<s.length&&c<i.marks.length;){let d=i.marks[c];if(!this.marks[d.type.name]){c++;continue}if(!d.eq(s[l][0])||d.type.spec.spanning===!1)break;l++,c++}for(;l<s.length;)r=s.pop()[1];for(;c<i.marks.length;){let d=i.marks[c++],u=this.serializeMark(d,i.isInline,t);u&&(s.push([d,r]),r.appendChild(u.dom),r=u.contentDOM||u.dom)}}r.appendChild(this.serializeNodeInner(i,t))}),o}serializeNodeInner(e,t){let{dom:o,contentDOM:r}=Ir(Pi(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return o}serializeNode(e,t={}){let o=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let s=this.serializeMark(e.marks[r],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(o),o=s.dom)}return o}serializeMark(e,t,o={}){let r=this.marks[e.type.name];return r&&Ir(Pi(o),r(e,t),null,e.attrs)}static renderSpec(e,t,o=null,r){return Ir(e,t,o,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new xn(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=vd(e.nodes);return t.text||(t.text=o=>o.text),t}static marksFromSchema(e){return vd(e.marks)}}function vd(n){let e={};for(let t in n){let o=n[t].spec.toDOM;o&&(e[t]=o)}return e}function Pi(n){return n.document||window.document}const Td=new WeakMap;function ty(n){let e=Td.get(n);return e===void 0&&Td.set(n,e=ny(n)),e}function ny(n){let e=null;function t(o){if(o&&typeof o=="object")if(Array.isArray(o))if(typeof o[0]=="string")e||(e=[]),e.push(o);else for(let r=0;r<o.length;r++)t(o[r]);else for(let r in o)t(o[r])}return t(n),e}function Ir(n,e,t,o){if(typeof e=="string")return{dom:n.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let r=e[0],s;if(typeof r!="string")throw new RangeError("Invalid array passed to renderSpec");if(o&&(s=ty(o))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let i=r.indexOf(" ");i>0&&(t=r.slice(0,i),r=r.slice(i+1));let l,c=t?n.createElementNS(t,r):n.createElement(r),d=e[1],u=1;if(d&&typeof d=="object"&&d.nodeType==null&&!Array.isArray(d)){u=2;for(let f in d)if(d[f]!=null){let h=f.indexOf(" ");h>0?c.setAttributeNS(f.slice(0,h),f.slice(h+1),d[f]):f=="style"&&c.style?c.style.cssText=d[f]:c.setAttribute(f,d[f])}}for(let f=u;f<e.length;f++){let h=e[f];if(h===0){if(f<e.length-1||f>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:p,contentDOM:m}=Ir(n,h,t,o);if(c.appendChild(p),m){if(l)throw new RangeError("Multiple content holes");l=m}}}return{dom:c,contentDOM:l}}const Md=65535,Nd=Math.pow(2,16);function oy(n,e){return n+e*Nd}function Ad(n){return n&Md}function ry(n){return(n-(n&Md))/Nd}const Bd=1,Id=2,Or=4,Od=8;class Li{constructor(e,t,o){this.pos=e,this.delInfo=t,this.recover=o}get deleted(){return(this.delInfo&Od)>0}get deletedBefore(){return(this.delInfo&(Bd|Or))>0}get deletedAfter(){return(this.delInfo&(Id|Or))>0}get deletedAcross(){return(this.delInfo&Or)>0}}class Ke{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Ke.empty)return Ke.empty}recover(e){let t=0,o=Ad(e);if(!this.inverted)for(let r=0;r<o;r++)t+=this.ranges[r*3+2]-this.ranges[r*3+1];return this.ranges[o*3]+t+ry(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,o){let r=0,s=this.inverted?2:1,i=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let c=this.ranges[l]-(this.inverted?r:0);if(c>e)break;let d=this.ranges[l+s],u=this.ranges[l+i],f=c+d;if(e<=f){let h=d?e==c?-1:e==f?1:t:t,p=c+r+(h<0?0:u);if(o)return p;let m=e==(t<0?c:f)?null:oy(l/3,e-c),g=e==c?Id:e==f?Bd:Or;return(t<0?e!=c:e!=f)&&(g|=Od),new Li(p,g,m)}r+=u-d}return o?e+r:new Li(e+r,0,null)}touches(e,t){let o=0,r=Ad(t),s=this.inverted?2:1,i=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let c=this.ranges[l]-(this.inverted?o:0);if(c>e)break;let d=this.ranges[l+s],u=c+d;if(e<=u&&l==r*3)return!0;o+=this.ranges[l+i]-d}return!1}forEach(e){let t=this.inverted?2:1,o=this.inverted?1:2;for(let r=0,s=0;r<this.ranges.length;r+=3){let i=this.ranges[r],l=i-(this.inverted?s:0),c=i+(this.inverted?0:s),d=this.ranges[r+t],u=this.ranges[r+o];e(l,l+d,c,c+u),s+=u-d}}invert(){return new Ke(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Ke.empty:new Ke(e<0?[0,-e,0]:[0,0,e])}}Ke.empty=new Ke([]);class No{constructor(e,t,o=0,r=e?e.length:0){this.mirror=t,this.from=o,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new No(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,o=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?o+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,o=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?o-r-1:void 0)}}invert(){let e=new No;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let o=this.from;o<this.to;o++)e=this._maps[o].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,o){let r=0;for(let s=this.from;s<this.to;s++){let i=this._maps[s],l=i.mapResult(e,t);if(l.recover!=null){let c=this.getMirror(s);if(c!=null&&c>s&&c<this.to){s=c,e=this._maps[c].recover(l.recover);continue}}r|=l.delInfo,e=l.pos}return o?e:new Li(e,r,null)}}const Vi=Object.create(null);class Re{getMap(){return Ke.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let o=Vi[t.stepType];if(!o)throw new RangeError(`No step type ${t.stepType} defined`);return o.fromJSON(e,t)}static jsonID(e,t){if(e in Vi)throw new RangeError("Duplicate use of step JSON ID "+e);return Vi[e]=t,t.prototype.jsonID=e,t}}class ye{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new ye(e,null)}static fail(e){return new ye(null,e)}static fromReplace(e,t,o,r){try{return ye.ok(e.replace(t,o,r))}catch(s){if(s instanceof vr)return ye.fail(s.message);throw s}}}function $i(n,e,t){let o=[];for(let r=0;r<n.childCount;r++){let s=n.child(r);s.content.size&&(s=s.copy($i(s.content,e,s))),s.isInline&&(s=e(s,t,r)),o.push(s)}return P.fromArray(o)}class Wt extends Re{constructor(e,t,o){super(),this.from=e,this.to=t,this.mark=o}apply(e){let t=e.slice(this.from,this.to),o=e.resolve(this.from),r=o.node(o.sharedDepth(this.to)),s=new U($i(t.content,(i,l)=>!i.isAtom||!l.type.allowsMarkType(this.mark.type)?i:i.mark(this.mark.addToSet(i.marks)),r),t.openStart,t.openEnd);return ye.fromReplace(e,this.from,this.to,s)}invert(){return new rt(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1);return t.deleted&&o.deleted||t.pos>=o.pos?null:new Wt(t.pos,o.pos,this.mark)}merge(e){return e instanceof Wt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Wt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Wt(t.from,t.to,e.markFromJSON(t.mark))}}Re.jsonID("addMark",Wt);class rt extends Re{constructor(e,t,o){super(),this.from=e,this.to=t,this.mark=o}apply(e){let t=e.slice(this.from,this.to),o=new U($i(t.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),t.openStart,t.openEnd);return ye.fromReplace(e,this.from,this.to,o)}invert(){return new Wt(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1);return t.deleted&&o.deleted||t.pos>=o.pos?null:new rt(t.pos,o.pos,this.mark)}merge(e){return e instanceof rt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new rt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new rt(t.from,t.to,e.markFromJSON(t.mark))}}Re.jsonID("removeMark",rt);class Kt extends Re{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ye.fail("No node at mark step's position");let o=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ye.fromReplace(e,this.pos,this.pos+1,new U(P.from(o),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let o=this.mark.addToSet(t.marks);if(o.length==t.marks.length){for(let r=0;r<t.marks.length;r++)if(!t.marks[r].isInSet(o))return new Kt(this.pos,t.marks[r]);return new Kt(this.pos,this.mark)}}return new Cn(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Kt(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Kt(t.pos,e.markFromJSON(t.mark))}}Re.jsonID("addNodeMark",Kt);class Cn extends Re{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ye.fail("No node at mark step's position");let o=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return ye.fromReplace(e,this.pos,this.pos+1,new U(P.from(o),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Kt(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Cn(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Cn(t.pos,e.markFromJSON(t.mark))}}Re.jsonID("removeNodeMark",Cn);class Se extends Re{constructor(e,t,o,r=!1){super(),this.from=e,this.to=t,this.slice=o,this.structure=r}apply(e){return this.structure&&zi(e,this.from,this.to)?ye.fail("Structure replace would overwrite content"):ye.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Ke([this.from,this.to-this.from,this.slice.size])}invert(e){return new Se(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1);return t.deletedAcross&&o.deletedAcross?null:new Se(t.pos,Math.max(t.pos,o.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Se)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?U.empty:new U(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Se(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?U.empty:new U(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Se(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Se(t.from,t.to,U.fromJSON(e,t.slice),!!t.structure)}}Re.jsonID("replace",Se);class xe extends Re{constructor(e,t,o,r,s,i,l=!1){super(),this.from=e,this.to=t,this.gapFrom=o,this.gapTo=r,this.slice=s,this.insert=i,this.structure=l}apply(e){if(this.structure&&(zi(e,this.from,this.gapFrom)||zi(e,this.gapTo,this.to)))return ye.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return ye.fail("Gap is not a flat range");let o=this.slice.insertAt(this.insert,t.content);return o?ye.fromReplace(e,this.from,this.to,o):ye.fail("Content does not fit in gap")}getMap(){return new Ke([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new xe(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?o.pos:e.map(this.gapTo,1);return t.deletedAcross&&o.deletedAcross||r<t.pos||s>o.pos?null:new xe(t.pos,o.pos,r,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new xe(t.from,t.to,t.gapFrom,t.gapTo,U.fromJSON(e,t.slice),t.insert,!!t.structure)}}Re.jsonID("replaceAround",xe);function zi(n,e,t){let o=n.resolve(e),r=t-e,s=o.depth;for(;r>0&&s>0&&o.indexAfter(s)==o.node(s).childCount;)s--,r--;if(r>0){let i=o.node(s).maybeChild(o.indexAfter(s));for(;r>0;){if(!i||i.isLeaf)return!0;i=i.firstChild,r--}}return!1}function sy(n,e,t,o){let r=[],s=[],i,l;n.doc.nodesBetween(e,t,(c,d,u)=>{if(!c.isInline)return;let f=c.marks;if(!o.isInSet(f)&&u.type.allowsMarkType(o.type)){let h=Math.max(d,e),p=Math.min(d+c.nodeSize,t),m=o.addToSet(f);for(let g=0;g<f.length;g++)f[g].isInSet(m)||(i&&i.to==h&&i.mark.eq(f[g])?i.to=p:r.push(i=new rt(h,p,f[g])));l&&l.to==h?l.to=p:s.push(l=new Wt(h,p,o))}}),r.forEach(c=>n.step(c)),s.forEach(c=>n.step(c))}function iy(n,e,t,o){let r=[],s=0;n.doc.nodesBetween(e,t,(i,l)=>{if(!i.isInline)return;s++;let c=null;if(o instanceof Ar){let d=i.marks,u;for(;u=o.isInSet(d);)(c||(c=[])).push(u),d=u.removeFromSet(d)}else o?o.isInSet(i.marks)&&(c=[o]):c=i.marks;if(c&&c.length){let d=Math.min(l+i.nodeSize,t);for(let u=0;u<c.length;u++){let f=c[u],h;for(let p=0;p<r.length;p++){let m=r[p];m.step==s-1&&f.eq(r[p].style)&&(h=m)}h?(h.to=d,h.step=s):r.push({style:f,from:Math.max(l,e),to:d,step:s})}}}),r.forEach(i=>n.step(new rt(i.from,i.to,i.style)))}function Fi(n,e,t,o=t.contentMatch,r=!0){let s=n.doc.nodeAt(e),i=[],l=e+1;for(let c=0;c<s.childCount;c++){let d=s.child(c),u=l+d.nodeSize,f=o.matchType(d.type);if(!f)i.push(new Se(l,u,U.empty));else{o=f;for(let h=0;h<d.marks.length;h++)t.allowsMarkType(d.marks[h].type)||n.step(new rt(l,u,d.marks[h]));if(r&&d.isText&&t.whitespace!="pre"){let h,p=/\r?\n|\r/g,m;for(;h=p.exec(d.text);)m||(m=new U(P.from(t.schema.text(" ",t.allowedMarks(d.marks))),0,0)),i.push(new Se(l+h.index,l+h.index+h[0].length,m))}}l=u}if(!o.validEnd){let c=o.fillBefore(P.empty,!0);n.replace(l,l,new U(c,0,0))}for(let c=i.length-1;c>=0;c--)n.step(i[c])}function ly(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function qn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let o=n.depth,r=0,s=0;;--o){let i=n.$from.node(o),l=n.$from.index(o)+r,c=n.$to.indexAfter(o)-s;if(o<n.depth&&i.canReplace(l,c,t))return o;if(o==0||i.type.spec.isolating||!ly(i,l,c))break;l&&(r=1),c<i.childCount&&(s=1)}return null}function ay(n,e,t){let{$from:o,$to:r,depth:s}=e,i=o.before(s+1),l=r.after(s+1),c=i,d=l,u=P.empty,f=0;for(let m=s,g=!1;m>t;m--)g||o.index(m)>0?(g=!0,u=P.from(o.node(m).copy(u)),f++):c--;let h=P.empty,p=0;for(let m=s,g=!1;m>t;m--)g||r.after(m+1)<r.end(m)?(g=!0,h=P.from(r.node(m).copy(h)),p++):d++;n.step(new xe(c,d,i,l,new U(u.append(h),f,p),u.size-f,!0))}function _d(n,e,t=null,o=n){let r=cy(n,e),s=r&&dy(o,e);return s?r.map(Dd).concat({type:e,attrs:t}).concat(s.map(Dd)):null}function Dd(n){return{type:n,attrs:null}}function cy(n,e){let{parent:t,startIndex:o,endIndex:r}=n,s=t.contentMatchAt(o).findWrapping(e);if(!s)return null;let i=s.length?s[0]:e;return t.canReplaceWith(o,r,i)?s:null}function dy(n,e){let{parent:t,startIndex:o,endIndex:r}=n,s=t.child(o),i=e.contentMatch.findWrapping(s.type);if(!i)return null;let c=(i.length?i[i.length-1]:e).contentMatch;for(let d=o;c&&d<r;d++)c=c.matchType(t.child(d).type);return!c||!c.validEnd?null:i}function uy(n,e,t){let o=P.empty;for(let i=t.length-1;i>=0;i--){if(o.size){let l=t[i].type.contentMatch.matchFragment(o);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}o=P.from(t[i].type.create(t[i].attrs,o))}let r=e.start,s=e.end;n.step(new xe(r,s,r,s,new U(o,0,0),t.length,!0))}function fy(n,e,t,o,r){if(!o.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(i,l)=>{let c=typeof r=="function"?r(i):r;if(i.isTextblock&&!i.hasMarkup(o,c)&&hy(n.doc,n.mapping.slice(s).map(l),o)){let d=null;if(o.schema.linebreakReplacement){let p=o.whitespace=="pre",m=!!o.contentMatch.matchType(o.schema.linebreakReplacement);p&&!m?d=!1:!p&&m&&(d=!0)}d===!1&&Pd(n,i,l,s),Fi(n,n.mapping.slice(s).map(l,1),o,void 0,d===null);let u=n.mapping.slice(s),f=u.map(l,1),h=u.map(l+i.nodeSize,1);return n.step(new xe(f,h,f+1,h-1,new U(P.from(o.create(c,null,i.marks)),0,0),1,!0)),d===!0&&Rd(n,i,l,s),!1}})}function Rd(n,e,t,o){e.forEach((r,s)=>{if(r.isText){let i,l=/\r?\n|\r/g;for(;i=l.exec(r.text);){let c=n.mapping.slice(o).map(t+1+s+i.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Pd(n,e,t,o){e.forEach((r,s)=>{if(r.type==r.type.schema.linebreakReplacement){let i=n.mapping.slice(o).map(t+1+s);n.replaceWith(i,i+1,e.type.schema.text(`
|
|
5
|
-
`))}})}function hy(n,e,t){let o=n.resolve(e),r=o.index();return o.parent.canReplaceWith(r,r+1,t)}function py(n,e,t,o,r){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let i=t.create(o,null,r||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,i);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new xe(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new U(P.from(i),0,0),1,!0))}function It(n,e,t=1,o){let r=n.resolve(e),s=r.depth-t,i=o&&o[o.length-1]||r.parent;if(s<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!i.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let d=r.depth-1,u=t-2;d>s;d--,u--){let f=r.node(d),h=r.index(d);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(h,f.childCount),m=o&&o[u+1];m&&(p=p.replaceChild(0,m.type.create(m.attrs)));let g=o&&o[u]||f;if(!f.canReplace(h+1,f.childCount)||!g.type.validContent(p))return!1}let l=r.indexAfter(s),c=o&&o[0];return r.node(s).canReplaceWith(l,l,c?c.type:r.node(s+1).type)}function my(n,e,t=1,o){let r=n.doc.resolve(e),s=P.empty,i=P.empty;for(let l=r.depth,c=r.depth-t,d=t-1;l>c;l--,d--){s=P.from(r.node(l).copy(s));let u=o&&o[d];i=P.from(u?u.type.create(u.attrs,i):r.node(l).copy(i))}n.step(new Se(e,e,new U(s.append(i),t,t),!0))}function En(n,e){let t=n.resolve(e),o=t.index();return Ld(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(o,o+1)}function gy(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:o}=n.type.schema;for(let r=0;r<e.childCount;r++){let s=e.child(r),i=s.type==o?n.type.schema.nodes.text:s.type;if(t=t.matchType(i),!t||!n.type.allowsMarks(s.marks))return!1}return t.validEnd}function Ld(n,e){return!!(n&&e&&!n.isLeaf&&gy(n,e))}function _r(n,e,t=-1){let o=n.resolve(e);for(let r=o.depth;;r--){let s,i,l=o.index(r);if(r==o.depth?(s=o.nodeBefore,i=o.nodeAfter):t>0?(s=o.node(r+1),l++,i=o.node(r).maybeChild(l)):(s=o.node(r).maybeChild(l-1),i=o.node(r+1)),s&&!s.isTextblock&&Ld(s,i)&&o.node(r).canReplace(l,l+1))return e;if(r==0)break;e=t<0?o.before(r):o.after(r)}}function yy(n,e,t){let o=null,{linebreakReplacement:r}=n.doc.type.schema,s=n.doc.resolve(e-t),i=s.node().type;if(r&&i.inlineContent){let u=i.whitespace=="pre",f=!!i.contentMatch.matchType(r);u&&!f?o=!1:!u&&f&&(o=!0)}let l=n.steps.length;if(o===!1){let u=n.doc.resolve(e+t);Pd(n,u.node(),u.before(),l)}i.inlineContent&&Fi(n,e+t-1,i,s.node().contentMatchAt(s.index()),o==null);let c=n.mapping.slice(l),d=c.map(e-t);if(n.step(new Se(d,c.map(e+t,-1),U.empty,!0)),o===!0){let u=n.doc.resolve(d);Rd(n,u.node(),u.before(),n.steps.length)}return n}function ky(n,e,t){let o=n.resolve(e);if(o.parent.canReplaceWith(o.index(),o.index(),t))return e;if(o.parentOffset==0)for(let r=o.depth-1;r>=0;r--){let s=o.index(r);if(o.node(r).canReplaceWith(s,s,t))return o.before(r+1);if(s>0)return null}if(o.parentOffset==o.parent.content.size)for(let r=o.depth-1;r>=0;r--){let s=o.indexAfter(r);if(o.node(r).canReplaceWith(s,s,t))return o.after(r+1);if(s<o.node(r).childCount)return null}return null}function Vd(n,e,t){let o=n.resolve(e);if(!t.content.size)return e;let r=t.content;for(let s=0;s<t.openStart;s++)r=r.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let i=o.depth;i>=0;i--){let l=i==o.depth?0:o.pos<=(o.start(i+1)+o.end(i+1))/2?-1:1,c=o.index(i)+(l>0?1:0),d=o.node(i),u=!1;if(s==1)u=d.canReplace(c,c,r);else{let f=d.contentMatchAt(c).findWrapping(r.firstChild.type);u=f&&d.canReplaceWith(c,c,f[0])}if(u)return l==0?o.pos:l<0?o.before(i+1):o.after(i+1)}return null}function Dr(n,e,t=e,o=U.empty){if(e==t&&!o.size)return null;let r=n.resolve(e),s=n.resolve(t);return $d(r,s,o)?new Se(e,t,o):new wy(r,s,o).fit()}function $d(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class wy{constructor(e,t,o){this.$from=e,this.$to=t,this.unplaced=o,this.frontier=[],this.placed=P.empty;for(let r=0;r<=e.depth;r++){let s=e.node(r);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(r))})}for(let r=e.depth;r>0;r--)this.placed=P.from(e.node(r).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let d=this.findFittable();d?this.placeNodes(d):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,o=this.$from,r=this.close(e<0?this.$to:o.doc.resolve(e));if(!r)return null;let s=this.placed,i=o.depth,l=r.depth;for(;i&&l&&s.childCount==1;)s=s.firstChild.content,i--,l--;let c=new U(s,i,l);return e>-1?new xe(o.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||o.pos!=this.$to.pos?new Se(o.pos,r.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,o=0,r=this.unplaced.openEnd;o<e;o++){let s=t.firstChild;if(t.childCount>1&&(r=0),s.type.spec.isolating&&r<=o){e=o;break}t=s.content}for(let t=1;t<=2;t++)for(let o=t==1?e:this.unplaced.openStart;o>=0;o--){let r,s=null;o?(s=Hi(this.unplaced.content,o-1).firstChild,r=s.content):r=this.unplaced.content;let i=r.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:d}=this.frontier[l],u,f=null;if(t==1&&(i?d.matchType(i.type)||(f=d.fillBefore(P.from(i),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:o,frontierDepth:l,parent:s,inject:f};if(t==2&&i&&(u=d.findWrapping(i.type)))return{sliceDepth:o,frontierDepth:l,parent:s,wrap:u};if(s&&d.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:o}=this.unplaced,r=Hi(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new U(e,t+1,Math.max(o,r.size+t>=e.size-o?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:o}=this.unplaced,r=Hi(e,t);if(r.childCount<=1&&t>0){let s=e.size-t<=t+r.size;this.unplaced=new U(Ao(e,t-1,1),t-1,s?t-1:o)}else this.unplaced=new U(Ao(e,t,1),t,o)}placeNodes({sliceDepth:e,frontierDepth:t,parent:o,inject:r,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let g=0;g<s.length;g++)this.openFrontierNode(s[g]);let i=this.unplaced,l=o?o.content:i.content,c=i.openStart-e,d=0,u=[],{match:f,type:h}=this.frontier[t];if(r){for(let g=0;g<r.childCount;g++)u.push(r.child(g));f=f.matchFragment(r)}let p=l.size+e-(i.content.size-i.openEnd);for(;d<l.childCount;){let g=l.child(d),y=f.matchType(g.type);if(!y)break;d++,(d>1||c==0||g.content.size)&&(f=y,u.push(zd(g.mark(h.allowedMarks(g.marks)),d==1?c:0,d==l.childCount?p:-1)))}let m=d==l.childCount;m||(p=-1),this.placed=Bo(this.placed,t,P.from(u)),this.frontier[t].match=f,m&&p<0&&o&&o.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let g=0,y=l;g<p;g++){let k=y.lastChild;this.frontier.push({type:k.type,match:k.contentMatchAt(k.childCount)}),y=k.content}this.unplaced=m?e==0?U.empty:new U(Ao(i.content,e-1,1),e-1,p<0?i.openEnd:e-1):new U(Ao(i.content,e,d),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!ji(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:o}=this.$to,r=this.$to.after(o);for(;o>1&&r==this.$to.end(--o);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:o,type:r}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),i=ji(e,t,r,o,s);if(i){for(let l=t-1;l>=0;l--){let{match:c,type:d}=this.frontier[l],u=ji(e,l,d,c,!0);if(!u||u.childCount)continue e}return{depth:t,fit:i,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Bo(this.placed,t.depth,t.fit)),e=t.move;for(let o=t.depth+1;o<=e.depth;o++){let r=e.node(o),s=r.type.contentMatch.fillBefore(r.content,!0,e.index(o));this.openFrontierNode(r.type,r.attrs,s)}return e}openFrontierNode(e,t=null,o){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=Bo(this.placed,this.depth,P.from(e.create(t,o))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(P.empty,!0);t.childCount&&(this.placed=Bo(this.placed,this.frontier.length,t))}}function Ao(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Ao(n.firstChild.content,e-1,t)))}function Bo(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Bo(n.lastChild.content,e-1,t)))}function Hi(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function zd(n,e,t){if(e<=0)return n;let o=n.content;return e>1&&(o=o.replaceChild(0,zd(o.firstChild,e-1,o.childCount==1?t-1:0))),e>0&&(o=n.type.contentMatch.fillBefore(o).append(o),t<=0&&(o=o.append(n.type.contentMatch.matchFragment(o).fillBefore(P.empty,!0)))),n.copy(o)}function ji(n,e,t,o,r){let s=n.node(e),i=r?n.indexAfter(e):n.index(e);if(i==s.childCount&&!t.compatibleContent(s.type))return null;let l=o.fillBefore(s.content,!0,i);return l&&!by(t,s.content,i)?l:null}function by(n,e,t){for(let o=t;o<e.childCount;o++)if(!n.allowsMarks(e.child(o).marks))return!0;return!1}function Sy(n){return n.spec.defining||n.spec.definingForContent}function xy(n,e,t,o){if(!o.size)return n.deleteRange(e,t);let r=n.doc.resolve(e),s=n.doc.resolve(t);if($d(r,s,o))return n.step(new Se(e,t,o));let i=Hd(r,s);i[i.length-1]==0&&i.pop();let l=-(r.depth+1);i.unshift(l);for(let h=r.depth,p=r.pos-1;h>0;h--,p--){let m=r.node(h).type.spec;if(m.defining||m.definingAsContext||m.isolating)break;i.indexOf(h)>-1?l=h:r.before(h)==p&&i.splice(1,0,-h)}let c=i.indexOf(l),d=[],u=o.openStart;for(let h=o.content,p=0;;p++){let m=h.firstChild;if(d.push(m),p==o.openStart)break;h=m.content}for(let h=u-1;h>=0;h--){let p=d[h],m=Sy(p.type);if(m&&!p.sameMarkup(r.node(Math.abs(l)-1)))u=h;else if(m||!p.type.isTextblock)break}for(let h=o.openStart;h>=0;h--){let p=(h+u+1)%(o.openStart+1),m=d[p];if(m)for(let g=0;g<i.length;g++){let y=i[(g+c)%i.length],k=!0;y<0&&(k=!1,y=-y);let x=r.node(y-1),b=r.index(y-1);if(x.canReplaceWith(b,b,m.type,m.marks))return n.replace(r.before(y),k?s.after(y):t,new U(Fd(o.content,0,o.openStart,p),p,o.openEnd))}}let f=n.steps.length;for(let h=i.length-1;h>=0&&(n.replace(e,t,o),!(n.steps.length>f));h--){let p=i[h];p<0||(e=r.before(p),t=s.after(p))}}function Fd(n,e,t,o,r){if(e<t){let s=n.firstChild;n=n.replaceChild(0,s.copy(Fd(s.content,e+1,t,o,s)))}if(e>o){let s=r.contentMatchAt(0),i=s.fillBefore(n).append(n);n=i.append(s.matchFragment(i).fillBefore(P.empty,!0))}return n}function Cy(n,e,t,o){if(!o.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let r=ky(n.doc,e,o.type);r!=null&&(e=t=r)}n.replaceRange(e,t,new U(P.from(o),0,0))}function Ey(n,e,t){let o=n.doc.resolve(e),r=n.doc.resolve(t),s=Hd(o,r);for(let i=0;i<s.length;i++){let l=s[i],c=i==s.length-1;if(c&&l==0||o.node(l).type.contentMatch.validEnd)return n.delete(o.start(l),r.end(l));if(l>0&&(c||o.node(l-1).canReplace(o.index(l-1),r.indexAfter(l-1))))return n.delete(o.before(l),r.after(l))}for(let i=1;i<=o.depth&&i<=r.depth;i++)if(e-o.start(i)==o.depth-i&&t>o.end(i)&&r.end(i)-t!=r.depth-i&&o.start(i-1)==r.start(i-1)&&o.node(i-1).canReplace(o.index(i-1),r.index(i-1)))return n.delete(o.before(i),t);n.delete(e,t)}function Hd(n,e){let t=[],o=Math.min(n.depth,e.depth);for(let r=o;r>=0;r--){let s=n.start(r);if(s<n.pos-(n.depth-r)||e.end(r)>e.pos+(e.depth-r)||n.node(r).type.spec.isolating||e.node(r).type.spec.isolating)break;(s==e.start(r)||r==n.depth&&r==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&r&&e.start(r-1)==s-1)&&t.push(r)}return t}class Jn extends Re{constructor(e,t,o){super(),this.pos=e,this.attr=t,this.value=o}apply(e){let t=e.nodeAt(this.pos);if(!t)return ye.fail("No node at attribute step's position");let o=Object.create(null);for(let s in t.attrs)o[s]=t.attrs[s];o[this.attr]=this.value;let r=t.type.create(o,null,t.marks);return ye.fromReplace(e,this.pos,this.pos+1,new U(P.from(r),0,t.isLeaf?0:1))}getMap(){return Ke.empty}invert(e){return new Jn(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Jn(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Jn(t.pos,t.attr,t.value)}}Re.jsonID("attr",Jn);class Io extends Re{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let r in e.attrs)t[r]=e.attrs[r];t[this.attr]=this.value;let o=e.type.create(t,e.content,e.marks);return ye.ok(o)}getMap(){return Ke.empty}invert(e){return new Io(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Io(t.attr,t.value)}}Re.jsonID("docAttr",Io);let Gn=class extends Error{};Gn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t},Gn.prototype=Object.create(Error.prototype),Gn.prototype.constructor=Gn,Gn.prototype.name="TransformError";class jd{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new No}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Gn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let o=0;o<this.mapping.maps.length;o++){let r=this.mapping.maps[o];o&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((s,i,l,c)=>{e=Math.min(e,l),t=Math.max(t,c)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,o=U.empty){let r=Dr(this.doc,e,t,o);return r&&this.step(r),this}replaceWith(e,t,o){return this.replace(e,t,new U(P.from(o),0,0))}delete(e,t){return this.replace(e,t,U.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,o){return xy(this,e,t,o),this}replaceRangeWith(e,t,o){return Cy(this,e,t,o),this}deleteRange(e,t){return Ey(this,e,t),this}lift(e,t){return ay(this,e,t),this}join(e,t=1){return yy(this,e,t),this}wrap(e,t){return uy(this,e,t),this}setBlockType(e,t=e,o,r=null){return fy(this,e,t,o,r),this}setNodeMarkup(e,t,o=null,r){return py(this,e,t,o,r),this}setNodeAttribute(e,t,o){return this.step(new Jn(e,t,o)),this}setDocAttribute(e,t){return this.step(new Io(e,t)),this}addNodeMark(e,t){return this.step(new Kt(e,t)),this}removeNodeMark(e,t){let o=this.doc.nodeAt(e);if(!o)throw new RangeError("No node at position "+e);if(t instanceof se)t.isInSet(o.marks)&&this.step(new Cn(e,t));else{let r=o.marks,s,i=[];for(;s=t.isInSet(r);)i.push(new Cn(e,s)),r=s.removeFromSet(r);for(let l=i.length-1;l>=0;l--)this.step(i[l])}return this}split(e,t=1,o){return my(this,e,t,o),this}addMark(e,t,o){return sy(this,e,t,o),this}removeMark(e,t,o){return iy(this,e,t,o),this}clearIncompatible(e,t,o){return Fi(this,e,t,o),this}}const Ui=Object.create(null);class ee{constructor(e,t,o){this.$anchor=e,this.$head=t,this.ranges=o||[new vy(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=U.empty){let o=t.content.lastChild,r=null;for(let l=0;l<t.openEnd;l++)r=o,o=o.lastChild;let s=e.steps.length,i=this.ranges;for(let l=0;l<i.length;l++){let{$from:c,$to:d}=i[l],u=e.mapping.slice(s);e.replaceRange(u.map(c.pos),u.map(d.pos),l?U.empty:t),l==0&&Kd(e,s,(o?o.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let o=e.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){let{$from:i,$to:l}=r[s],c=e.mapping.slice(o),d=c.map(i.pos),u=c.map(l.pos);s?e.deleteRange(d,u):(e.replaceRangeWith(d,u,t),Kd(e,o,t.isInline?-1:1))}}static findFrom(e,t,o=!1){let r=e.parent.inlineContent?new Q(e):Yn(e.node(0),e.parent,e.pos,e.index(),t,o);if(r)return r;for(let s=e.depth-1;s>=0;s--){let i=t<0?Yn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,o):Yn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,o);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new qe(e.node(0))}static atStart(e){return Yn(e,e,0,0,1)||new qe(e)}static atEnd(e){return Yn(e,e,e.content.size,e.childCount,-1)||new qe(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let o=Ui[t.type];if(!o)throw new RangeError(`No selection type ${t.type} defined`);return o.fromJSON(e,t)}static jsonID(e,t){if(e in Ui)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ui[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Q.between(this.$anchor,this.$head).getBookmark()}}ee.prototype.visible=!0;class vy{constructor(e,t){this.$from=e,this.$to=t}}let Ud=!1;function Wd(n){!Ud&&!n.parent.inlineContent&&(Ud=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class Q extends ee{constructor(e,t=e){Wd(e),Wd(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let o=e.resolve(t.map(this.head));if(!o.parent.inlineContent)return ee.near(o);let r=e.resolve(t.map(this.anchor));return new Q(r.parent.inlineContent?r:o,o)}replace(e,t=U.empty){if(super.replace(e,t),t==U.empty){let o=this.$from.marksAcross(this.$to);o&&e.ensureMarks(o)}}eq(e){return e instanceof Q&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Rr(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new Q(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,o=t){let r=e.resolve(t);return new this(r,o==t?r:e.resolve(o))}static between(e,t,o){let r=e.pos-t.pos;if((!o||r)&&(o=r>=0?1:-1),!t.parent.inlineContent){let s=ee.findFrom(t,o,!0)||ee.findFrom(t,-o,!0);if(s)t=s.$head;else return ee.near(t,o)}return e.parent.inlineContent||(r==0?e=t:(e=(ee.findFrom(e,-o,!0)||ee.findFrom(e,o,!0)).$anchor,e.pos<t.pos!=r<0&&(e=t))),new Q(e,t)}}ee.jsonID("text",Q);class Rr{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Rr(e.map(this.anchor),e.map(this.head))}resolve(e){return Q.between(e.resolve(this.anchor),e.resolve(this.head))}}class Y extends ee{constructor(e){let t=e.nodeAfter,o=e.node(0).resolve(e.pos+t.nodeSize);super(e,o),this.node=t}map(e,t){let{deleted:o,pos:r}=t.mapResult(this.anchor),s=e.resolve(r);return o?ee.near(s):new Y(s)}content(){return new U(P.from(this.node),0,0)}eq(e){return e instanceof Y&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Wi(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Y(e.resolve(t.anchor))}static create(e,t){return new Y(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}Y.prototype.visible=!1,ee.jsonID("node",Y);class Wi{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:o}=e.mapResult(this.anchor);return t?new Rr(o,o):new Wi(o)}resolve(e){let t=e.resolve(this.anchor),o=t.nodeAfter;return o&&Y.isSelectable(o)?new Y(t):ee.near(t)}}class qe extends ee{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=U.empty){if(t==U.empty){e.delete(0,e.doc.content.size);let o=ee.atStart(e.doc);o.eq(e.selection)||e.setSelection(o)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new qe(e)}map(e){return new qe(e)}eq(e){return e instanceof qe}getBookmark(){return Ty}}ee.jsonID("all",qe);const Ty={map(){return this},resolve(n){return new qe(n)}};function Yn(n,e,t,o,r,s=!1){if(e.inlineContent)return Q.create(n,t);for(let i=o-(r>0?0:1);r>0?i<e.childCount:i>=0;i+=r){let l=e.child(i);if(l.isAtom){if(!s&&Y.isSelectable(l))return Y.create(n,t-(r<0?l.nodeSize:0))}else{let c=Yn(n,l,t+r,r<0?l.childCount:0,r,s);if(c)return c}t+=l.nodeSize*r}return null}function Kd(n,e,t){let o=n.steps.length-1;if(o<e)return;let r=n.steps[o];if(!(r instanceof Se||r instanceof xe))return;let s=n.mapping.maps[o],i;s.forEach((l,c,d,u)=>{i==null&&(i=u)}),n.setSelection(ee.near(n.doc.resolve(i),t))}const qd=1,Pr=2,Jd=4;class My extends jd{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|qd)&~Pr,this.storedMarks=null,this}get selectionSet(){return(this.updated&qd)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Pr,this}ensureMarks(e){return se.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Pr)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Pr,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let o=this.selection;return t&&(e=e.mark(this.storedMarks||(o.empty?o.$from.marks():o.$from.marksAcross(o.$to)||se.none))),o.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,o){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(o==null&&(o=t),!e)return this.deleteRange(t,o);let s=this.storedMarks;if(!s){let i=this.doc.resolve(t);s=o==t?i.marks():i.marksAcross(this.doc.resolve(o))}return this.replaceRangeWith(t,o,r.text(e,s)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(ee.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Jd,this}get scrolledIntoView(){return(this.updated&Jd)>0}}function Gd(n,e){return!e||!n?n:n.bind(e)}class Oo{constructor(e,t,o){this.name=e,this.init=Gd(t.init,o),this.apply=Gd(t.apply,o)}}const Ny=[new Oo("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Oo("selection",{init(n,e){return n.selection||ee.atStart(e.doc)},apply(n){return n.selection}}),new Oo("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,o){return o.selection.$cursor?n.storedMarks:null}}),new Oo("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Ki{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ny.slice(),t&&t.forEach(o=>{if(this.pluginsByKey[o.key])throw new RangeError("Adding different instances of a keyed plugin ("+o.key+")");this.plugins.push(o),this.pluginsByKey[o.key]=o,o.spec.state&&this.fields.push(new Oo(o.key,o.spec.state,o))})}}class Xn{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let o=0;o<this.config.plugins.length;o++)if(o!=t){let r=this.config.plugins[o];if(r.spec.filterTransaction&&!r.spec.filterTransaction.call(r,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],o=this.applyInner(e),r=null;for(;;){let s=!1;for(let i=0;i<this.config.plugins.length;i++){let l=this.config.plugins[i];if(l.spec.appendTransaction){let c=r?r[i].n:0,d=r?r[i].state:this,u=c<t.length&&l.spec.appendTransaction.call(l,c?t.slice(c):t,d,o);if(u&&o.filterTransaction(u,i)){if(u.setMeta("appendedTransaction",e),!r){r=[];for(let f=0;f<this.config.plugins.length;f++)r.push(f<i?{state:o,n:t.length}:{state:this,n:0})}t.push(u),o=o.applyInner(u),s=!0}r&&(r[i]={state:o,n:t.length})}}if(!s)return{state:o,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new Xn(this.config),o=this.config.fields;for(let r=0;r<o.length;r++){let s=o[r];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new My(this)}static create(e){let t=new Ki(e.doc?e.doc.type.schema:e.schema,e.plugins),o=new Xn(t);for(let r=0;r<t.fields.length;r++)o[t.fields[r].name]=t.fields[r].init(e,o);return o}reconfigure(e){let t=new Ki(this.schema,e.plugins),o=t.fields,r=new Xn(t);for(let s=0;s<o.length;s++){let i=o[s].name;r[i]=this.hasOwnProperty(i)?this[i]:o[s].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(o=>o.toJSON())),e&&typeof e=="object")for(let o in e){if(o=="doc"||o=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[o],s=r.spec.state;s&&s.toJSON&&(t[o]=s.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,o){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let r=new Ki(e.schema,e.plugins),s=new Xn(r);return r.fields.forEach(i=>{if(i.name=="doc")s.doc=At.fromJSON(e.schema,t.doc);else if(i.name=="selection")s.selection=ee.fromJSON(s.doc,t.selection);else if(i.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(o)for(let l in o){let c=o[l],d=c.spec.state;if(c.key==i.name&&d&&d.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[i.name]=d.fromJSON.call(c,e,t[l],s);return}}s[i.name]=i.init(e,s)}}),s}}function Yd(n,e,t){for(let o in n){let r=n[o];r instanceof Function?r=r.bind(e):o=="handleDOMEvents"&&(r=Yd(r,e,{})),t[o]=r}return t}class pe{constructor(e){this.spec=e,this.props={},e.props&&Yd(e.props,this,this.props),this.key=e.key?e.key.key:Xd("plugin")}getState(e){return e[this.key]}}const qi=Object.create(null);function Xd(n){return n in qi?n+"$"+ ++qi[n]:(qi[n]=0,n+"$")}class Ce{constructor(e="key"){this.key=Xd(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Ji=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Qd(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Zd=(n,e,t)=>{let o=Qd(n,t);if(!o)return!1;let r=Gi(o);if(!r){let i=o.blockRange(),l=i&&qn(i);return l==null?!1:(e&&e(n.tr.lift(i,l).scrollIntoView()),!0)}let s=r.nodeBefore;if(au(n,r,e,-1))return!0;if(o.parent.content.size==0&&(Qn(s,"end")||Y.isSelectable(s)))for(let i=o.depth;;i--){let l=Dr(n.doc,o.before(i),o.after(i),U.empty);if(l&&l.slice.size<l.to-l.from){if(e){let c=n.tr.step(l);c.setSelection(Qn(s,"end")?ee.findFrom(c.doc.resolve(c.mapping.map(r.pos,-1)),-1):Y.create(c.doc,r.pos-s.nodeSize)),e(c.scrollIntoView())}return!0}if(i==1||o.node(i-1).childCount>1)break}return s.isAtom&&r.depth==o.depth-1?(e&&e(n.tr.delete(r.pos-s.nodeSize,r.pos).scrollIntoView()),!0):!1},Ay=(n,e,t)=>{let o=Qd(n,t);if(!o)return!1;let r=Gi(o);return r?eu(n,r,e):!1},By=(n,e,t)=>{let o=nu(n,t);if(!o)return!1;let r=Yi(o);return r?eu(n,r,e):!1};function eu(n,e,t){let o=e.nodeBefore,r=o,s=e.pos-1;for(;!r.isTextblock;s--){if(r.type.spec.isolating)return!1;let u=r.lastChild;if(!u)return!1;r=u}let i=e.nodeAfter,l=i,c=e.pos+1;for(;!l.isTextblock;c++){if(l.type.spec.isolating)return!1;let u=l.firstChild;if(!u)return!1;l=u}let d=Dr(n.doc,s,c,U.empty);if(!d||d.from!=s||d instanceof Se&&d.slice.size>=c-s)return!1;if(t){let u=n.tr.step(d);u.setSelection(Q.create(u.doc,s)),t(u.scrollIntoView())}return!0}function Qn(n,e,t=!1){for(let o=n;o;o=e=="start"?o.firstChild:o.lastChild){if(o.isTextblock)return!0;if(t&&o.childCount!=1)return!1}return!1}const tu=(n,e,t)=>{let{$head:o,empty:r}=n.selection,s=o;if(!r)return!1;if(o.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):o.parentOffset>0)return!1;s=Gi(o)}let i=s&&s.nodeBefore;return!i||!Y.isSelectable(i)?!1:(e&&e(n.tr.setSelection(Y.create(n.doc,s.pos-i.nodeSize)).scrollIntoView()),!0)};function Gi(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function nu(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const ou=(n,e,t)=>{let o=nu(n,t);if(!o)return!1;let r=Yi(o);if(!r)return!1;let s=r.nodeAfter;if(au(n,r,e,1))return!0;if(o.parent.content.size==0&&(Qn(s,"start")||Y.isSelectable(s))){let i=Dr(n.doc,o.before(),o.after(),U.empty);if(i&&i.slice.size<i.to-i.from){if(e){let l=n.tr.step(i);l.setSelection(Qn(s,"start")?ee.findFrom(l.doc.resolve(l.mapping.map(r.pos)),1):Y.create(l.doc,l.mapping.map(r.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&r.depth==o.depth-1?(e&&e(n.tr.delete(r.pos,r.pos+s.nodeSize).scrollIntoView()),!0):!1},ru=(n,e,t)=>{let{$head:o,empty:r}=n.selection,s=o;if(!r)return!1;if(o.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):o.parentOffset<o.parent.content.size)return!1;s=Yi(o)}let i=s&&s.nodeAfter;return!i||!Y.isSelectable(i)?!1:(e&&e(n.tr.setSelection(Y.create(n.doc,s.pos)).scrollIntoView()),!0)};function Yi(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){let t=n.node(e);if(n.index(e)+1<t.childCount)return n.doc.resolve(n.after(e+1));if(t.type.spec.isolating)break}return null}const Iy=(n,e)=>{let t=n.selection,o=t instanceof Y,r;if(o){if(t.node.isTextblock||!En(n.doc,t.from))return!1;r=t.from}else if(r=_r(n.doc,t.from,-1),r==null)return!1;if(e){let s=n.tr.join(r);o&&s.setSelection(Y.create(s.doc,r-n.doc.resolve(r).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},Oy=(n,e)=>{let t=n.selection,o;if(t instanceof Y){if(t.node.isTextblock||!En(n.doc,t.to))return!1;o=t.to}else if(o=_r(n.doc,t.to,1),o==null)return!1;return e&&e(n.tr.join(o).scrollIntoView()),!0},_y=(n,e)=>{let{$from:t,$to:o}=n.selection,r=t.blockRange(o),s=r&&qn(r);return s==null?!1:(e&&e(n.tr.lift(r,s).scrollIntoView()),!0)},su=(n,e)=>{let{$head:t,$anchor:o}=n.selection;return!t.parent.type.spec.code||!t.sameParent(o)?!1:(e&&e(n.tr.insertText(`
|
|
6
|
-
`).scrollIntoView()),!0)};function Xi(n){for(let e=0;e<n.edgeCount;e++){let{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}const Dy=(n,e)=>{let{$head:t,$anchor:o}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(o))return!1;let r=t.node(-1),s=t.indexAfter(-1),i=Xi(r.contentMatchAt(s));if(!i||!r.canReplaceWith(s,s,i))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,i.createAndFill());c.setSelection(ee.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},iu=(n,e)=>{let t=n.selection,{$from:o,$to:r}=t;if(t instanceof qe||o.parent.inlineContent||r.parent.inlineContent)return!1;let s=Xi(r.parent.contentMatchAt(r.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let i=(!o.parentOffset&&r.index()<r.parent.childCount?o:r).pos,l=n.tr.insert(i,s.createAndFill());l.setSelection(Q.create(l.doc,i+1)),e(l.scrollIntoView())}return!0},lu=(n,e)=>{let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(It(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let o=t.blockRange(),r=o&&qn(o);return r==null?!1:(e&&e(n.tr.lift(o,r).scrollIntoView()),!0)};function Ry(n){return(e,t)=>{let{$from:o,$to:r}=e.selection;if(e.selection instanceof Y&&e.selection.node.isBlock)return!o.parentOffset||!It(e.doc,o.pos)?!1:(t&&t(e.tr.split(o.pos).scrollIntoView()),!0);if(!o.depth)return!1;let s=[],i,l,c=!1,d=!1;for(let p=o.depth;;p--)if(o.node(p).isBlock){c=o.end(p)==o.pos+(o.depth-p),d=o.start(p)==o.pos-(o.depth-p),l=Xi(o.node(p-1).contentMatchAt(o.indexAfter(p-1))),s.unshift(c&&l?{type:l}:null),i=p;break}else{if(p==1)return!1;s.unshift(null)}let u=e.tr;(e.selection instanceof Q||e.selection instanceof qe)&&u.deleteSelection();let f=u.mapping.map(o.pos),h=It(u.doc,f,s.length,s);if(h||(s[0]=l?{type:l}:null,h=It(u.doc,f,s.length,s)),!h)return!1;if(u.split(f,s.length,s),!c&&d&&o.node(i).type!=l){let p=u.mapping.map(o.before(i)),m=u.doc.resolve(p);l&&o.node(i-1).canReplaceWith(m.index(),m.index()+1,l)&&u.setNodeMarkup(u.mapping.map(o.before(i)),l)}return t&&t(u.scrollIntoView()),!0}}const Py=Ry(),Ly=(n,e)=>{let{$from:t,to:o}=n.selection,r,s=t.sharedDepth(o);return s==0?!1:(r=t.before(s),e&&e(n.tr.setSelection(Y.create(n.doc,r))),!0)};function Vy(n,e,t){let o=e.nodeBefore,r=e.nodeAfter,s=e.index();return!o||!r||!o.type.compatibleContent(r.type)?!1:!o.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-o.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(r.isTextblock||En(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function au(n,e,t,o){let r=e.nodeBefore,s=e.nodeAfter,i,l,c=r.type.spec.isolating||s.type.spec.isolating;if(!c&&Vy(n,e,t))return!0;let d=!c&&e.parent.canReplace(e.index(),e.index()+1);if(d&&(i=(l=r.contentMatchAt(r.childCount)).findWrapping(s.type))&&l.matchType(i[0]||s.type).validEnd){if(t){let p=e.pos+s.nodeSize,m=P.empty;for(let k=i.length-1;k>=0;k--)m=P.from(i[k].create(null,m));m=P.from(r.copy(m));let g=n.tr.step(new xe(e.pos-1,p,e.pos,p,new U(m,1,0),i.length,!0)),y=g.doc.resolve(p+2*i.length);y.nodeAfter&&y.nodeAfter.type==r.type&&En(g.doc,y.pos)&&g.join(y.pos),t(g.scrollIntoView())}return!0}let u=s.type.spec.isolating||o>0&&c?null:ee.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),h=f&&qn(f);if(h!=null&&h>=e.depth)return t&&t(n.tr.lift(f,h).scrollIntoView()),!0;if(d&&Qn(s,"start",!0)&&Qn(r,"end")){let p=r,m=[];for(;m.push(p),!p.isTextblock;)p=p.lastChild;let g=s,y=1;for(;!g.isTextblock;g=g.firstChild)y++;if(p.canReplace(p.childCount,p.childCount,g.content)){if(t){let k=P.empty;for(let b=m.length-1;b>=0;b--)k=P.from(m[b].copy(k));let x=n.tr.step(new xe(e.pos-m.length,e.pos+s.nodeSize,e.pos+y,e.pos+s.nodeSize-y,new U(k,m.length,0),0,!0));t(x.scrollIntoView())}return!0}}return!1}function cu(n){return function(e,t){let o=e.selection,r=n<0?o.$from:o.$to,s=r.depth;for(;r.node(s).isInline;){if(!s)return!1;s--}return r.node(s).isTextblock?(t&&t(e.tr.setSelection(Q.create(e.doc,n<0?r.start(s):r.end(s)))),!0):!1}}const $y=cu(-1),zy=cu(1);function Fy(n,e=null){return function(t,o){let{$from:r,$to:s}=t.selection,i=r.blockRange(s),l=i&&_d(i,n,e);return l?(o&&o(t.tr.wrap(i,l).scrollIntoView()),!0):!1}}function du(n,e=null){return function(t,o){let r=!1;for(let s=0;s<t.selection.ranges.length&&!r;s++){let{$from:{pos:i},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(i,l,(c,d)=>{if(r)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)r=!0;else{let u=t.doc.resolve(d),f=u.index();r=u.parent.canReplaceWith(f,f+1,n)}})}if(!r)return!1;if(o){let s=t.tr;for(let i=0;i<t.selection.ranges.length;i++){let{$from:{pos:l},$to:{pos:c}}=t.selection.ranges[i];s.setBlockType(l,c,n,e)}o(s.scrollIntoView())}return!0}}function Qi(...n){return function(e,t,o){for(let r=0;r<n.length;r++)if(n[r](e,t,o))return!0;return!1}}Qi(Ji,Zd,tu),Qi(Ji,ou,ru),Qi(su,iu,lu,Py),typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function Hy(n,e=null){return function(t,o){let{$from:r,$to:s}=t.selection,i=r.blockRange(s);if(!i)return!1;let l=o?t.tr:null;return jy(l,i,n,e)?(o&&o(l.scrollIntoView()),!0):!1}}function jy(n,e,t,o=null){let r=!1,s=e,i=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(t)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let c=i.resolve(e.start-2);s=new Mr(c,c,e.depth),e.endIndex<e.parent.childCount&&(e=new Mr(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),r=!0}let l=_d(s,t,o,e);return l?(n&&Uy(n,e,l,r,t),!0):!1}function Uy(n,e,t,o,r){let s=P.empty;for(let u=t.length-1;u>=0;u--)s=P.from(t[u].type.create(t[u].attrs,s));n.step(new xe(e.start-(o?2:0),e.end,e.start,e.end,new U(s,0,0),t.length,!0));let i=0;for(let u=0;u<t.length;u++)t[u].type==r&&(i=u+1);let l=t.length-i,c=e.start+t.length-(o?2:0),d=e.parent;for(let u=e.startIndex,f=e.endIndex,h=!0;u<f;u++,h=!1)!h&&It(n.doc,c,l)&&(n.split(c,l),c+=2*l),c+=d.child(u).nodeSize;return n}function Wy(n){return function(e,t){let{$from:o,$to:r}=e.selection,s=o.blockRange(r,i=>i.childCount>0&&i.firstChild.type==n);return s?t?o.node(s.depth-1).type==n?Ky(e,t,n,s):qy(e,t,s):!0:!1}}function Ky(n,e,t,o){let r=n.tr,s=o.end,i=o.$to.end(o.depth);s<i&&(r.step(new xe(s-1,i,s,i,new U(P.from(t.create(null,o.parent.copy())),1,0),1,!0)),o=new Mr(r.doc.resolve(o.$from.pos),r.doc.resolve(i),o.depth));const l=qn(o);if(l==null)return!1;r.lift(o,l);let c=r.doc.resolve(r.mapping.map(s,-1)-1);return En(r.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&r.join(c.pos),e(r.scrollIntoView()),!0}function qy(n,e,t){let o=n.tr,r=t.parent;for(let p=t.end,m=t.endIndex-1,g=t.startIndex;m>g;m--)p-=r.child(m).nodeSize,o.delete(p-1,p+1);let s=o.doc.resolve(t.start),i=s.nodeAfter;if(o.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==r.childCount,d=s.node(-1),u=s.index(-1);if(!d.canReplace(u+(l?0:1),u+1,i.content.append(c?P.empty:P.from(r))))return!1;let f=s.pos,h=f+i.nodeSize;return o.step(new xe(f-(l?1:0),h+(c?1:0),f+1,h-1,new U((l?P.empty:P.from(r.copy(P.empty))).append(c?P.empty:P.from(r.copy(P.empty))),l?0:1,c?0:1),l?0:1)),e(o.scrollIntoView()),!0}function Jy(n){return function(e,t){let{$from:o,$to:r}=e.selection,s=o.blockRange(r,d=>d.childCount>0&&d.firstChild.type==n);if(!s)return!1;let i=s.startIndex;if(i==0)return!1;let l=s.parent,c=l.child(i-1);if(c.type!=n)return!1;if(t){let d=c.lastChild&&c.lastChild.type==l.type,u=P.from(d?n.create():null),f=new U(P.from(n.create(null,P.from(l.type.create(null,u)))),d?3:1,0),h=s.start,p=s.end;t(e.tr.step(new xe(h-(d?3:1),p,h,p,f,1,!0)).scrollIntoView())}return!0}}const Ae=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Zn=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Zi=null;const Ot=function(n,e,t){let o=Zi||(Zi=document.createRange());return o.setEnd(n,t??n.nodeValue.length),o.setStart(n,e||0),o},Gy=function(){Zi=null},vn=function(n,e,t,o){return t&&(uu(n,e,t,o,-1)||uu(n,e,t,o,1))},Yy=/^(img|br|input|textarea|hr)$/i;function uu(n,e,t,o,r){for(var s;;){if(n==t&&e==o)return!0;if(e==(r<0?0:Ye(n))){let i=n.parentNode;if(!i||i.nodeType!=1||_o(n)||Yy.test(n.nodeName)||n.contentEditable=="false")return!1;e=Ae(n)+(r<0?0:1),n=i}else if(n.nodeType==1){let i=n.childNodes[e+(r<0?-1:0)];if(i.nodeType==1&&i.contentEditable=="false")if(!((s=i.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=r;else return!1;else n=i,e=r<0?Ye(n):0}else return!1}}function Ye(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Xy(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=Ye(n)}else if(n.parentNode&&!_o(n))e=Ae(n),n=n.parentNode;else return null}}function Qy(n,e){for(;;){if(n.nodeType==3&&e<n.nodeValue.length)return n;if(n.nodeType==1&&e<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[e],e=0}else if(n.parentNode&&!_o(n))e=Ae(n)+1,n=n.parentNode;else return null}}function Zy(n,e,t){for(let o=e==0,r=e==Ye(n);o||r;){if(n==t)return!0;let s=Ae(n);if(n=n.parentNode,!n)return!1;o=o&&s==0,r=r&&s==Ye(n)}}function _o(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const Lr=function(n){return n.focusNode&&vn(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function Tn(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function e1(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function t1(n,e,t){if(n.caretPositionFromPoint)try{let o=n.caretPositionFromPoint(e,t);if(o)return{node:o.offsetNode,offset:Math.min(Ye(o.offsetNode),o.offset)}}catch{}if(n.caretRangeFromPoint){let o=n.caretRangeFromPoint(e,t);if(o)return{node:o.startContainer,offset:Math.min(Ye(o.startContainer),o.startOffset)}}}const pt=typeof navigator<"u"?navigator:null,fu=typeof document<"u"?document:null,qt=pt&&pt.userAgent||"",el=/Edge\/(\d+)/.exec(qt),hu=/MSIE \d/.exec(qt),tl=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(qt),He=!!(hu||tl||el),Jt=hu?document.documentMode:tl?+tl[1]:el?+el[1]:0,Xe=!He&&/gecko\/(\d+)/i.test(qt);Xe&&+(/Firefox\/(\d+)/.exec(qt)||[0,0])[1];const nl=!He&&/Chrome\/(\d+)/.exec(qt),Be=!!nl,pu=nl?+nl[1]:0,Pe=!He&&!!pt&&/Apple Computer/.test(pt.vendor),eo=Pe&&(/Mobile\/\w+/.test(qt)||!!pt&&pt.maxTouchPoints>2),Qe=eo||(pt?/Mac/.test(pt.platform):!1),mu=pt?/Win/.test(pt.platform):!1,_t=/Android \d/.test(qt),Do=!!fu&&"webkitFontSmoothing"in fu.documentElement.style,n1=Do?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function o1(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function Dt(n,e){return typeof n=="number"?n:n[e]}function r1(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,o=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*o}}function gu(n,e,t){let o=n.someProp("scrollThreshold")||0,r=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let i=t||n.dom;i;){if(i.nodeType!=1){i=Zn(i);continue}let l=i,c=l==s.body,d=c?o1(s):r1(l),u=0,f=0;if(e.top<d.top+Dt(o,"top")?f=-(d.top-e.top+Dt(r,"top")):e.bottom>d.bottom-Dt(o,"bottom")&&(f=e.bottom-e.top>d.bottom-d.top?e.top+Dt(r,"top")-d.top:e.bottom-d.bottom+Dt(r,"bottom")),e.left<d.left+Dt(o,"left")?u=-(d.left-e.left+Dt(r,"left")):e.right>d.right-Dt(o,"right")&&(u=e.right-d.right+Dt(r,"right")),u||f)if(c)s.defaultView.scrollBy(u,f);else{let p=l.scrollLeft,m=l.scrollTop;f&&(l.scrollTop+=f),u&&(l.scrollLeft+=u);let g=l.scrollLeft-p,y=l.scrollTop-m;e={left:e.left-g,top:e.top-y,right:e.right-g,bottom:e.bottom-y}}let h=c?"fixed":getComputedStyle(i).position;if(/^(fixed|sticky)$/.test(h))break;i=h=="absolute"?i.offsetParent:Zn(i)}}function s1(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),o,r;for(let s=(e.left+e.right)/2,i=t+1;i<Math.min(innerHeight,e.bottom);i+=5){let l=n.root.elementFromPoint(s,i);if(!l||l==n.dom||!n.dom.contains(l))continue;let c=l.getBoundingClientRect();if(c.top>=t-20){o=l,r=c.top;break}}return{refDOM:o,refTop:r,stack:yu(n.dom)}}function yu(n){let e=[],t=n.ownerDocument;for(let o=n;o&&(e.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),n!=t);o=Zn(o));return e}function i1({refDOM:n,refTop:e,stack:t}){let o=n?n.getBoundingClientRect().top:0;ku(t,o==0?0:o-e)}function ku(n,e){for(let t=0;t<n.length;t++){let{dom:o,top:r,left:s}=n[t];o.scrollTop!=r+e&&(o.scrollTop=r+e),o.scrollLeft!=s&&(o.scrollLeft=s)}}let to=null;function l1(n){if(n.setActive)return n.setActive();if(to)return n.focus(to);let e=yu(n);n.focus(to==null?{get preventScroll(){return to={preventScroll:!0},!0}}:void 0),to||(to=!1,ku(e,0))}function wu(n,e){let t,o=2e8,r,s=0,i=e.top,l=e.top,c,d;for(let u=n.firstChild,f=0;u;u=u.nextSibling,f++){let h;if(u.nodeType==1)h=u.getClientRects();else if(u.nodeType==3)h=Ot(u).getClientRects();else continue;for(let p=0;p<h.length;p++){let m=h[p];if(m.top<=i&&m.bottom>=l){i=Math.max(m.bottom,i),l=Math.min(m.top,l);let g=m.left>e.left?m.left-e.left:m.right<e.left?e.left-m.right:0;if(g<o){t=u,o=g,r=g&&t.nodeType==3?{left:m.right<e.left?m.right:m.left,top:e.top}:e,u.nodeType==1&&g&&(s=f+(e.left>=(m.left+m.right)/2?1:0));continue}}else m.top>e.top&&!c&&m.left<=e.left&&m.right>=e.left&&(c=u,d={left:Math.max(m.left,Math.min(m.right,e.left)),top:m.top});!t&&(e.left>=m.right&&e.top>=m.top||e.left>=m.left&&e.top>=m.bottom)&&(s=f+1)}}return!t&&c&&(t=c,r=d,o=0),t&&t.nodeType==3?a1(t,r):!t||o&&t.nodeType==1?{node:n,offset:s}:wu(t,r)}function a1(n,e){let t=n.nodeValue.length,o=document.createRange(),r;for(let s=0;s<t;s++){o.setEnd(n,s+1),o.setStart(n,s);let i=Gt(o,1);if(i.top!=i.bottom&&ol(e,i)){r={node:n,offset:s+(e.left>=(i.left+i.right)/2?1:0)};break}}return o.detach(),r||{node:n,offset:0}}function ol(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function c1(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function d1(n,e,t){let{node:o,offset:r}=wu(e,t),s=-1;if(o.nodeType==1&&!o.firstChild){let i=o.getBoundingClientRect();s=i.left!=i.right&&t.left>(i.left+i.right)/2?1:-1}return n.docView.posFromDOM(o,r,s)}function u1(n,e,t,o){let r=-1;for(let s=e,i=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0),c;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((c=l.dom.getBoundingClientRect()).width||c.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!i&&c.left>o.left||c.top>o.top?r=l.posBefore:(!i&&c.right<o.left||c.bottom<o.top)&&(r=l.posAfter),i=!0),!l.contentDOM&&r<0&&!l.node.isText))return(l.node.isBlock?o.top<(c.top+c.bottom)/2:o.left<(c.left+c.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return r>-1?r:n.docView.posFromDOM(e,t,-1)}function bu(n,e,t){let o=n.childNodes.length;if(o&&t.top<t.bottom)for(let r=Math.max(0,Math.min(o-1,Math.floor(o*(e.top-t.top)/(t.bottom-t.top))-2)),s=r;;){let i=n.childNodes[s];if(i.nodeType==1){let l=i.getClientRects();for(let c=0;c<l.length;c++){let d=l[c];if(ol(e,d))return bu(i,e,d)}}if((s=(s+1)%o)==r)break}return n}function f1(n,e){let t=n.dom.ownerDocument,o,r=0,s=t1(t,e.left,e.top);s&&({node:o,offset:r}=s);let i=(n.root.elementFromPoint?n.root:t).elementFromPoint(e.left,e.top),l;if(!i||!n.dom.contains(i.nodeType!=1?i.parentNode:i)){let d=n.dom.getBoundingClientRect();if(!ol(e,d)||(i=bu(n.dom,e,d),!i))return null}if(Pe)for(let d=i;o&&d;d=Zn(d))d.draggable&&(o=void 0);if(i=c1(i,e),o){if(Xe&&o.nodeType==1&&(r=Math.min(r,o.childNodes.length),r<o.childNodes.length)){let u=o.childNodes[r],f;u.nodeName=="IMG"&&(f=u.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&r++}let d;Do&&r&&o.nodeType==1&&(d=o.childNodes[r-1]).nodeType==1&&d.contentEditable=="false"&&d.getBoundingClientRect().top>=e.top&&r--,o==n.dom&&r==o.childNodes.length-1&&o.lastChild.nodeType==1&&e.top>o.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(r==0||o.nodeType!=1||o.childNodes[r-1].nodeName!="BR")&&(l=u1(n,o,r,e))}l==null&&(l=d1(n,i,e));let c=n.docView.nearestDesc(i,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Su(n){return n.top<n.bottom||n.left<n.right}function Gt(n,e){let t=n.getClientRects();if(t.length){let o=t[e<0?0:t.length-1];if(Su(o))return o}return Array.prototype.find.call(t,Su)||n.getBoundingClientRect()}const h1=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function xu(n,e,t){let{node:o,offset:r,atom:s}=n.docView.domFromPos(e,t<0?-1:1),i=Do||Xe;if(o.nodeType==3)if(i&&(h1.test(o.nodeValue)||(t<0?!r:r==o.nodeValue.length))){let c=Gt(Ot(o,r,r),t);if(Xe&&r&&/\s/.test(o.nodeValue[r-1])&&r<o.nodeValue.length){let d=Gt(Ot(o,r-1,r-1),-1);if(d.top==c.top){let u=Gt(Ot(o,r,r+1),-1);if(u.top!=c.top)return Ro(u,u.left<d.left)}}return c}else{let c=r,d=r,u=t<0?1:-1;return t<0&&!r?(d++,u=-1):t>=0&&r==o.nodeValue.length?(c--,u=1):t<0?c--:d++,Ro(Gt(Ot(o,c,d),u),u<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&r&&(t<0||r==Ye(o))){let c=o.childNodes[r-1];if(c.nodeType==1)return rl(c.getBoundingClientRect(),!1)}if(s==null&&r<Ye(o)){let c=o.childNodes[r];if(c.nodeType==1)return rl(c.getBoundingClientRect(),!0)}return rl(o.getBoundingClientRect(),t>=0)}if(s==null&&r&&(t<0||r==Ye(o))){let c=o.childNodes[r-1],d=c.nodeType==3?Ot(c,Ye(c)-(i?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(d)return Ro(Gt(d,1),!1)}if(s==null&&r<Ye(o)){let c=o.childNodes[r];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let d=c?c.nodeType==3?Ot(c,0,i?0:1):c.nodeType==1?c:null:null;if(d)return Ro(Gt(d,-1),!0)}return Ro(Gt(o.nodeType==3?Ot(o):o,-t),t>=0)}function Ro(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function rl(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Cu(n,e,t){let o=n.state,r=n.root.activeElement;o!=e&&n.updateState(e),r!=n.dom&&n.focus();try{return t()}finally{o!=e&&n.updateState(o),r!=n.dom&&r&&r.focus()}}function p1(n,e,t){let o=e.selection,r=t=="up"?o.$from:o.$to;return Cu(n,e,()=>{let{node:s}=n.docView.domFromPos(r.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let i=xu(n,r.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=Ot(l,0,l.nodeValue.length).getClientRects();else continue;for(let d=0;d<c.length;d++){let u=c[d];if(u.bottom>u.top+1&&(t=="up"?i.top-u.top>(u.bottom-i.top)*2:u.bottom-i.bottom>(i.bottom-u.top)*2))return!1}}return!0})}const m1=/[\u0590-\u08ac]/;function g1(n,e,t){let{$head:o}=e.selection;if(!o.parent.isTextblock)return!1;let r=o.parentOffset,s=!r,i=r==o.parent.content.size,l=n.domSelection();return l?!m1.test(o.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:i:Cu(n,e,()=>{let{focusNode:c,focusOffset:d,anchorNode:u,anchorOffset:f}=n.domSelectionRange(),h=l.caretBidiLevel;l.modify("move",t,"character");let p=o.depth?n.docView.domAfterPos(o.before()):n.dom,{focusNode:m,focusOffset:g}=n.domSelectionRange(),y=m&&!p.contains(m.nodeType==1?m:m.parentNode)||c==m&&d==g;try{l.collapse(u,f),c&&(c!=u||d!=f)&&l.extend&&l.extend(c,d)}catch{}return h!=null&&(l.caretBidiLevel=h),y}):o.pos==o.start()||o.pos==o.end()}let Eu=null,vu=null,Tu=!1;function y1(n,e,t){return Eu==e&&vu==t?Tu:(Eu=e,vu=t,Tu=t=="up"||t=="down"?p1(n,e,t):g1(n,e,t))}const Ze=0,Mu=1,Mn=2,mt=3;class Po{constructor(e,t,o,r){this.parent=e,this.children=t,this.dom=o,this.contentDOM=r,this.dirty=Ze,o.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,o){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,o=this.posAtStart;;t++){let r=this.children[t];if(r==e)return o;o+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,o){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(o<0){let s,i;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((i=s.pmViewDesc)&&i.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(i)+i.size:this.posAtStart}else{let s,i;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((i=s.pmViewDesc)&&i.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(i):this.posAtEnd}let r;if(e==this.dom&&this.contentDOM)r=t>Ae(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!1;break}if(s.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!0;break}if(s.nextSibling)break}}return r??o>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let o=!0,r=e;r;r=r.parentNode){let s=this.getDesc(r),i;if(s&&(!t||s.node))if(o&&(i=s.nodeDOM)&&!(i.nodeType==1?i.contains(e.nodeType==1?e:e.parentNode):i==e))o=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let o=t;o;o=o.parent)if(o==this)return t}posFromDOM(e,t,o){for(let r=e;r;r=r.parentNode){let s=this.getDesc(r);if(s)return s.localPosFromDOM(e,t,o)}return-1}descAt(e){for(let t=0,o=0;t<this.children.length;t++){let r=this.children[t],s=o+r.size;if(o==e&&s!=o){for(;!r.border&&r.children.length;)for(let i=0;i<r.children.length;i++){let l=r.children[i];if(l.size){r=l;break}}return r}if(e<s)return r.descAt(e-o-r.border);o=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let o=0,r=0;for(let s=0;o<this.children.length;o++){let i=this.children[o],l=s+i.size;if(l>e||i instanceof Bu){r=e-s;break}s=l}if(r)return this.children[o].domFromPos(r-this.children[o].border,t);for(let s;o&&!(s=this.children[o-1]).size&&s instanceof Nu&&s.side>=0;o--);if(t<=0){let s,i=!0;for(;s=o?this.children[o-1]:null,!(!s||s.dom.parentNode==this.contentDOM);o--,i=!1);return s&&t&&i&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?Ae(s.dom)+1:0}}else{let s,i=!0;for(;s=o<this.children.length?this.children[o]:null,!(!s||s.dom.parentNode==this.contentDOM);o++,i=!1);return s&&i&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?Ae(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,o=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,s=-1;for(let i=o,l=0;;l++){let c=this.children[l],d=i+c.size;if(r==-1&&e<=d){let u=i+c.border;if(e>=u&&t<=d-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,u);e=i;for(let f=l;f>0;f--){let h=this.children[f-1];if(h.size&&h.dom.parentNode==this.contentDOM&&!h.emptyChildAt(1)){r=Ae(h.dom)+1;break}e-=h.size}r==-1&&(r=0)}if(r>-1&&(d>t||l==this.children.length-1)){t=d;for(let u=l+1;u<this.children.length;u++){let f=this.children[u];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){s=Ae(f.dom);break}t+=f.size}s==-1&&(s=this.contentDOM.childNodes.length);break}i=d}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:o}=this.domFromPos(e,0);if(t.nodeType!=1||o==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[o]}setSelection(e,t,o,r=!1){let s=Math.min(e,t),i=Math.max(e,t);for(let p=0,m=0;p<this.children.length;p++){let g=this.children[p],y=m+g.size;if(s>m&&i<y)return g.setSelection(e-m-g.border,t-m-g.border,o,r);m=y}let l=this.domFromPos(e,e?-1:1),c=t==e?l:this.domFromPos(t,t?-1:1),d=o.root.getSelection(),u=o.domSelectionRange(),f=!1;if((Xe||Pe)&&e==t){let{node:p,offset:m}=l;if(p.nodeType==3){if(f=!!(m&&p.nodeValue[m-1]==`
|
|
7
|
-
`),f&&m==p.nodeValue.length)for(let g=p,y;g;g=g.parentNode){if(y=g.nextSibling){y.nodeName=="BR"&&(l=c={node:y.parentNode,offset:Ae(y)+1});break}let k=g.pmViewDesc;if(k&&k.node&&k.node.isBlock)break}}else{let g=p.childNodes[m-1];f=g&&(g.nodeName=="BR"||g.contentEditable=="false")}}if(Xe&&u.focusNode&&u.focusNode!=c.node&&u.focusNode.nodeType==1){let p=u.focusNode.childNodes[u.focusOffset];p&&p.contentEditable=="false"&&(r=!0)}if(!(r||f&&Pe)&&vn(l.node,l.offset,u.anchorNode,u.anchorOffset)&&vn(c.node,c.offset,u.focusNode,u.focusOffset))return;let h=!1;if((d.extend||e==t)&&!(f&&Xe)){d.collapse(l.node,l.offset);try{e!=t&&d.extend(c.node,c.offset),h=!0}catch{}}if(!h){if(e>t){let m=l;l=c,c=m}let p=document.createRange();p.setEnd(c.node,c.offset),p.setStart(l.node,l.offset),d.removeAllRanges(),d.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let o=0,r=0;r<this.children.length;r++){let s=this.children[r],i=o+s.size;if(o==i?e<=i&&t>=o:e<i&&t>o){let l=o+s.border,c=i-s.border;if(e>=l&&t<=c){this.dirty=e==o||t==i?Mn:Mu,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=mt:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Mn:mt}o=i}this.dirty=Mn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let o=e==1?Mn:Mu;t.dirty<o&&(t.dirty=o)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class Nu extends Po{constructor(e,t,o,r){let s,i=t.type.toDOM;if(typeof i=="function"&&(i=i(o,()=>{if(!s)return r;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(i.nodeType!=1){let l=document.createElement("span");l.appendChild(i),i=l}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(e,[],i,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Ze&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class k1 extends Po{constructor(e,t,o,r){super(e,[],t,null),this.textDOM=o,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Nn extends Po{constructor(e,t,o,r,s){super(e,[],o,r),this.mark=t,this.spec=s}static create(e,t,o,r){let s=r.nodeViews[t.type.name],i=s&&s(t,r,o);return(!i||!i.dom)&&(i=xn.renderSpec(document,t.type.spec.toDOM(t,o),null,t.attrs)),new Nn(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return this.dirty&mt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=mt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Ze){let o=this.parent;for(;!o.node;)o=o.parent;o.dirty<this.dirty&&(o.dirty=this.dirty),this.dirty=Ze}}slice(e,t,o){let r=Nn.create(this.parent,this.mark,!0,o),s=this.children,i=this.size;t<i&&(s=il(s,t,i,o)),e>0&&(s=il(s,0,e,o));for(let l=0;l<s.length;l++)s[l].parent=r;return r.children=s,r}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Yt extends Po{constructor(e,t,o,r,s,i,l,c,d){super(e,[],s,i),this.node=t,this.outerDeco=o,this.innerDeco=r,this.nodeDOM=l}static create(e,t,o,r,s,i){let l=s.nodeViews[t.type.name],c,d=l&&l(t,s,()=>{if(!c)return i;if(c.parent)return c.parent.posBeforeChild(c)},o,r),u=d&&d.dom,f=d&&d.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=xn.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let h=u;return u=_u(u,o,t),d?c=new w1(e,t,o,r,u,f||null,h,d,s,i+1):t.isText?new Vr(e,t,o,r,u,h,s):new Yt(e,t,o,r,u,f||null,h,s,i+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let o=this.children[t];if(this.dom.contains(o.dom.parentNode)){e.contentElement=o.dom.parentNode;break}}e.contentElement||(e.getContent=()=>P.empty)}return e}matchesNode(e,t,o){return this.dirty==Ze&&e.eq(this.node)&&$r(t,this.outerDeco)&&o.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let o=this.node.inlineContent,r=t,s=e.composing?this.localCompositionInfo(e,t):null,i=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new S1(this,i&&i.node,e);E1(this.node,this.innerDeco,(d,u,f)=>{d.spec.marks?c.syncToMarks(d.spec.marks,o,e,u):d.type.side>=0&&!f&&c.syncToMarks(u==this.node.childCount?se.none:this.node.child(u).marks,o,e,u),c.placeWidget(d,e,r)},(d,u,f,h)=>{c.syncToMarks(d.marks,o,e,h);let p;c.findNodeMatch(d,u,f,h)||l&&e.state.selection.from>r&&e.state.selection.to<r+d.nodeSize&&(p=c.findIndexWithChild(s.node))>-1&&c.updateNodeAt(d,u,f,p,e)||c.updateNextNode(d,u,f,e,h,r)||c.addNode(d,u,f,e,r),r+=d.nodeSize}),c.syncToMarks([],o,e,0),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==Mn)&&(i&&this.protectLocalComposition(e,i),Iu(this.contentDOM,this.children,e),eo&&v1(this.dom))}localCompositionInfo(e,t){let{from:o,to:r}=e.state.selection;if(!(e.state.selection instanceof Q)||o<t||r>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let i=s.nodeValue,l=T1(this.node.content,i,o-t,r-t);return l<0?null:{node:s,pos:l,text:i}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:o,text:r}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let i=new k1(this,s,t,r);e.input.compositionNodes.push(i),this.children=il(this.children,o,o+r.length,e,i)}update(e,t,o,r){return this.dirty==mt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,o,r),!0)}updateInner(e,t,o,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=o,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=Ze}updateOuterDeco(e){if($r(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,o=this.dom;this.dom=Ou(this.dom,this.nodeDOM,sl(this.outerDeco,this.node,t),sl(e,this.node,t)),this.dom!=o&&(o.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Au(n,e,t,o,r){_u(o,e,n);let s=new Yt(void 0,n,e,t,o,o,o,r,0);return s.contentDOM&&s.updateChildren(r,0),s}class Vr extends Yt{constructor(e,t,o,r,s,i,l){super(e,t,o,r,s,null,i,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,o,r){return this.dirty==mt||this.dirty!=Ze&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Ze||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=Ze,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,o){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,o)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,o){let r=this.node.cut(e,t),s=document.createTextNode(r.text);return new Vr(this.parent,r,this.outerDeco,this.innerDeco,s,s,o)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=mt)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Bu extends Po{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Ze&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class w1 extends Yt{constructor(e,t,o,r,s,i,l,c,d,u){super(e,t,o,r,s,i,l,d,u),this.spec=c}update(e,t,o,r){if(this.dirty==mt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,o);return s&&this.updateInner(e,t,o,r),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,o,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,o,r){this.spec.setSelection?this.spec.setSelection(e,t,o.root):super.setSelection(e,t,o,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Iu(n,e,t){let o=n.firstChild,r=!1;for(let s=0;s<e.length;s++){let i=e[s],l=i.dom;if(l.parentNode==n){for(;l!=o;)o=Du(o),r=!0;o=o.nextSibling}else r=!0,n.insertBefore(l,o);if(i instanceof Nn){let c=o?o.previousSibling:n.lastChild;Iu(i.contentDOM,i.children,t),o=c?c.nextSibling:n.firstChild}}for(;o;)o=Du(o),r=!0;r&&t.trackWrites==n&&(t.trackWrites=null)}const Lo=function(n){n&&(this.nodeName=n)};Lo.prototype=Object.create(null);const An=[new Lo];function sl(n,e,t){if(n.length==0)return An;let o=t?An[0]:new Lo,r=[o];for(let s=0;s<n.length;s++){let i=n[s].type.attrs;if(i){i.nodeName&&r.push(o=new Lo(i.nodeName));for(let l in i){let c=i[l];c!=null&&(t&&r.length==1&&r.push(o=new Lo(e.isInline?"span":"div")),l=="class"?o.class=(o.class?o.class+" ":"")+c:l=="style"?o.style=(o.style?o.style+";":"")+c:l!="nodeName"&&(o[l]=c))}}}return r}function Ou(n,e,t,o){if(t==An&&o==An)return e;let r=e;for(let s=0;s<o.length;s++){let i=o[s],l=t[s];if(s){let c;l&&l.nodeName==i.nodeName&&r!=n&&(c=r.parentNode)&&c.nodeName.toLowerCase()==i.nodeName||(c=document.createElement(i.nodeName),c.pmIsDeco=!0,c.appendChild(r),l=An[0]),r=c}b1(r,l||An[0],i)}return r}function b1(n,e,t){for(let o in e)o!="class"&&o!="style"&&o!="nodeName"&&!(o in t)&&n.removeAttribute(o);for(let o in t)o!="class"&&o!="style"&&o!="nodeName"&&t[o]!=e[o]&&n.setAttribute(o,t[o]);if(e.class!=t.class){let o=e.class?e.class.split(" ").filter(Boolean):[],r=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<o.length;s++)r.indexOf(o[s])==-1&&n.classList.remove(o[s]);for(let s=0;s<r.length;s++)o.indexOf(r[s])==-1&&n.classList.add(r[s]);n.classList.length==0&&n.removeAttribute("class")}if(e.style!=t.style){if(e.style){let o=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=o.exec(e.style);)n.style.removeProperty(r[1])}t.style&&(n.style.cssText+=t.style)}}function _u(n,e,t){return Ou(n,n,An,sl(e,t,n.nodeType!=1))}function $r(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].type.eq(e[t].type))return!1;return!0}function Du(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class S1{constructor(e,t,o){this.lock=t,this.view=o,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=x1(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let o=e;o<t;o++)this.top.children[o].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,o,r){let s=0,i=this.stack.length>>1,l=Math.min(i,e.length);for(;s<l&&(s==i-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<i;)this.destroyRest(),this.top.dirty=Ze,this.index=this.stack.pop(),this.top=this.stack.pop(),i--;for(;i<e.length;){this.stack.push(this.top,this.index+1);let c=-1,d=this.top.children.length;r<this.preMatch.index&&(d=Math.min(this.index+3,d));for(let u=this.index;u<d;u++){let f=this.top.children[u];if(f.matchesMark(e[i])&&!this.isLocked(f.dom)){c=u;break}}if(c>-1)c>this.index&&(this.changed=!0,this.destroyBetween(this.index,c)),this.top=this.top.children[this.index];else{let u=Nn.create(this.top,e[i],t,o);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,i++}}findNodeMatch(e,t,o,r){let s=-1,i;if(r>=this.preMatch.index&&(i=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&i.matchesNode(e,t,o))s=this.top.children.indexOf(i,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l<c;l++){let d=this.top.children[l];if(d.matchesNode(e,t,o)&&!this.preMatch.matched.has(d)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,o,r,s){let i=this.top.children[r];return i.dirty==mt&&i.dom==i.contentDOM&&(i.dirty=Mn),i.update(e,t,o,s)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let o=e.pmViewDesc;if(o){for(let r=this.index;r<this.top.children.length;r++)if(this.top.children[r]==o)return r}return-1}e=t}}updateNextNode(e,t,o,r,s,i){for(let l=this.index;l<this.top.children.length;l++){let c=this.top.children[l];if(c instanceof Yt){let d=this.preMatch.matched.get(c);if(d!=null&&d!=s)return!1;let u=c.dom,f,h=this.isLocked(u)&&!(e.isText&&c.node&&c.node.isText&&c.nodeDOM.nodeValue==e.text&&c.dirty!=mt&&$r(t,c.outerDeco));if(!h&&c.update(e,t,o,r))return this.destroyBetween(this.index,l),c.dom!=u&&(this.changed=!0),this.index++,!0;if(!h&&(f=this.recreateWrapper(c,e,t,o,r,i)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Mn,f.updateChildren(r,i+1),f.dirty=Ze),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,o,r,s,i){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!$r(o,e.outerDeco)||!r.eq(e.innerDeco))return null;let l=Yt.create(this.top,t,o,r,s,i);if(l.contentDOM){l.children=e.children,e.children=[];for(let c of l.children)c.parent=l}return e.destroy(),l}addNode(e,t,o,r,s){let i=Yt.create(this.top,e,t,o,r,s);i.contentDOM&&i.updateChildren(r,s+1),this.top.children.splice(this.index++,0,i),this.changed=!0}placeWidget(e,t,o){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let s=new Nu(this.top,e,t,o);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Nn;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Vr)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((Pe||Be)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let o=document.createElement(e);e=="IMG"&&(o.className="ProseMirror-separator",o.alt=""),e=="BR"&&(o.className="ProseMirror-trailingBreak");let r=new Bu(this.top,[],o,null);t!=this.top?t.children.push(r):t.children.splice(this.index++,0,r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}}function x1(n,e){let t=e,o=t.children.length,r=n.childCount,s=new Map,i=[];e:for(;r>0;){let l;for(;;)if(o){let d=t.children[o-1];if(d instanceof Nn)t=d,o=d.children.length;else{l=d,o--;break}}else{if(t==e)break e;o=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(r-1))break;--r,s.set(l,r),i.push(l)}}return{index:r,matched:s,matches:i.reverse()}}function C1(n,e){return n.type.side-e.type.side}function E1(n,e,t,o){let r=e.locals(n),s=0;if(r.length==0){for(let d=0;d<n.childCount;d++){let u=n.child(d);o(u,r,e.forChild(s,u),d),s+=u.nodeSize}return}let i=0,l=[],c=null;for(let d=0;;){let u,f;for(;i<r.length&&r[i].to==s;){let y=r[i++];y.widget&&(u?(f||(f=[u])).push(y):u=y)}if(u)if(f){f.sort(C1);for(let y=0;y<f.length;y++)t(f[y],d,!!c)}else t(u,d,!!c);let h,p;if(c)p=-1,h=c,c=null;else if(d<n.childCount)p=d,h=n.child(d++);else break;for(let y=0;y<l.length;y++)l[y].to<=s&&l.splice(y--,1);for(;i<r.length&&r[i].from<=s&&r[i].to>s;)l.push(r[i++]);let m=s+h.nodeSize;if(h.isText){let y=m;i<r.length&&r[i].from<y&&(y=r[i].from);for(let k=0;k<l.length;k++)l[k].to<y&&(y=l[k].to);y<m&&(c=h.cut(y-s),h=h.cut(0,y-s),m=y,p=-1)}else for(;i<r.length&&r[i].to<m;)i++;let g=h.isInline&&!h.isLeaf?l.filter(y=>!y.inline):l.slice();o(h,g,e.forChild(s,h),p),s=m}}function v1(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function T1(n,e,t,o){for(let r=0,s=0;r<n.childCount&&s<=o;){let i=n.child(r++),l=s;if(s+=i.nodeSize,!i.isText)continue;let c=i.text;for(;r<n.childCount;){let d=n.child(r++);if(s+=d.nodeSize,!d.isText)break;c+=d.text}if(s>=t){if(s>=o&&c.slice(o-e.length-l,o-l)==e)return o-e.length;let d=l<o?c.lastIndexOf(e,o-l-1):-1;if(d>=0&&d+e.length+l>=t)return l+d;if(t==o&&c.length>=o+e.length-l&&c.slice(o-l,o-l+e.length)==e)return o}}return-1}function il(n,e,t,o,r){let s=[];for(let i=0,l=0;i<n.length;i++){let c=n[i],d=l,u=l+=c.size;d>=t||u<=e?s.push(c):(d<e&&s.push(c.slice(0,e-d,o)),r&&(s.push(r),r=void 0),u>t&&s.push(c.slice(t-d,c.size,o)))}return s}function ll(n,e=null){let t=n.domSelectionRange(),o=n.state.doc;if(!t.focusNode)return null;let r=n.docView.nearestDesc(t.focusNode),s=r&&r.size==0,i=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(i<0)return null;let l=o.resolve(i),c,d;if(Lr(t)){for(c=i;r&&!r.node;)r=r.parent;let f=r.node;if(r&&f.isAtom&&Y.isSelectable(f)&&r.parent&&!(f.isInline&&Zy(t.focusNode,t.focusOffset,r.dom))){let h=r.posBefore;d=new Y(i==h?l:o.resolve(h))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=i,h=i;for(let p=0;p<t.rangeCount;p++){let m=t.getRangeAt(p);f=Math.min(f,n.docView.posFromDOM(m.startContainer,m.startOffset,1)),h=Math.max(h,n.docView.posFromDOM(m.endContainer,m.endOffset,-1))}if(f<0)return null;[c,i]=h==n.state.selection.anchor?[h,f]:[f,h],l=o.resolve(i)}else c=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null}let u=o.resolve(c);if(!d){let f=e=="pointer"||n.state.selection.head<l.pos&&!s?1:-1;d=cl(n,u,l,f)}return d}function Ru(n){return n.editable?n.hasFocus():Hu(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function Rt(n,e=!1){let t=n.state.selection;if($u(n,t),!!Ru(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&Be){let o=n.domSelectionRange(),r=n.domObserver.currentSelection;if(o.anchorNode&&r.anchorNode&&vn(o.anchorNode,o.anchorOffset,r.anchorNode,r.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)N1(n);else{let{anchor:o,head:r}=t,s,i;Pu&&!(t instanceof Q)&&(t.$from.parent.inlineContent||(s=Lu(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(i=Lu(n,t.to))),n.docView.setSelection(o,r,n,e),Pu&&(s&&Vu(s),i&&Vu(i)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&M1(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const Pu=Pe||Be&&pu<63;function Lu(n,e){let{node:t,offset:o}=n.docView.domFromPos(e,0),r=o<t.childNodes.length?t.childNodes[o]:null,s=o?t.childNodes[o-1]:null;if(Pe&&r&&r.contentEditable=="false")return al(r);if((!r||r.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(r)return al(r);if(s)return al(s)}}function al(n){return n.contentEditable="true",Pe&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function Vu(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function M1(n){let e=n.dom.ownerDocument;e.removeEventListener("selectionchange",n.input.hideSelectionGuard);let t=n.domSelectionRange(),o=t.anchorNode,r=t.anchorOffset;e.addEventListener("selectionchange",n.input.hideSelectionGuard=()=>{(t.anchorNode!=o||t.anchorOffset!=r)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Ru(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function N1(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,o=t.nodeName=="IMG";o?e.collapse(t.parentNode,Ae(t)+1):e.collapse(t,0),!o&&!n.state.selection.visible&&He&&Jt<=11&&(t.disabled=!0,t.disabled=!1)}function $u(n,e){if(e instanceof Y){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(zu(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else zu(n)}function zu(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function cl(n,e,t,o){return n.someProp("createSelectionBetween",r=>r(n,e,t))||Q.between(e,t,o)}function Fu(n){return n.editable&&!n.hasFocus()?!1:Hu(n)}function Hu(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function A1(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return vn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function dl(n,e){let{$anchor:t,$head:o}=n.selection,r=e>0?t.max(o):t.min(o),s=r.parent.inlineContent?r.depth?n.doc.resolve(e>0?r.after():r.before()):null:r;return s&&ee.findFrom(s,e)}function Xt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function ju(n,e,t){let o=n.state.selection;if(o instanceof Q)if(t.indexOf("s")>-1){let{$head:r}=o,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let i=n.state.doc.resolve(r.pos+s.nodeSize*(e<0?-1:1));return Xt(n,new Q(o.$anchor,i))}else if(o.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let r=dl(n.state,e);return r&&r instanceof Y?Xt(n,r):!1}else if(!(Qe&&t.indexOf("m")>-1)){let r=o.$head,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter,i;if(!s||s.isText)return!1;let l=e<0?r.pos-s.nodeSize:r.pos;return s.isAtom||(i=n.docView.descAt(l))&&!i.contentDOM?Y.isSelectable(s)?Xt(n,new Y(e<0?n.state.doc.resolve(r.pos-s.nodeSize):r)):Do?Xt(n,new Q(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(o instanceof Y&&o.node.isInline)return Xt(n,new Q(e>0?o.$to:o.$from));{let r=dl(n.state,e);return r?Xt(n,r):!1}}}function zr(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Vo(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function no(n,e){return e<0?B1(n):I1(n)}function B1(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r,s,i=!1;for(Xe&&t.nodeType==1&&o<zr(t)&&Vo(t.childNodes[o],-1)&&(i=!0);;)if(o>0){if(t.nodeType!=1)break;{let l=t.childNodes[o-1];if(Vo(l,-1))r=t,s=--o;else if(l.nodeType==3)t=l,o=t.nodeValue.length;else break}}else{if(Uu(t))break;{let l=t.previousSibling;for(;l&&Vo(l,-1);)r=t.parentNode,s=Ae(l),l=l.previousSibling;if(l)t=l,o=zr(t);else{if(t=t.parentNode,t==n.dom)break;o=0}}}i?ul(n,t,o):r&&ul(n,r,s)}function I1(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r=zr(t),s,i;for(;;)if(o<r){if(t.nodeType!=1)break;let l=t.childNodes[o];if(Vo(l,1))s=t,i=++o;else break}else{if(Uu(t))break;{let l=t.nextSibling;for(;l&&Vo(l,1);)s=l.parentNode,i=Ae(l)+1,l=l.nextSibling;if(l)t=l,o=0,r=zr(t);else{if(t=t.parentNode,t==n.dom)break;o=r=0}}}s&&ul(n,s,i)}function Uu(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function O1(n,e){for(;n&&e==n.childNodes.length&&!_o(n);)e=Ae(n)+1,n=n.parentNode;for(;n&&e<n.childNodes.length;){let t=n.childNodes[e];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=0}}function _1(n,e){for(;n&&!e&&!_o(n);)e=Ae(n),n=n.parentNode;for(;n&&e;){let t=n.childNodes[e-1];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=n.childNodes.length}}function ul(n,e,t){if(e.nodeType!=3){let s,i;(i=O1(e,t))?(e=i,t=0):(s=_1(e,t))&&(e=s,t=s.nodeValue.length)}let o=n.domSelection();if(!o)return;if(Lr(o)){let s=document.createRange();s.setEnd(e,t),s.setStart(e,t),o.removeAllRanges(),o.addRange(s)}else o.extend&&o.extend(e,t);n.domObserver.setCurSelection();let{state:r}=n;setTimeout(()=>{n.state==r&&Rt(n)},50)}function Wu(n,e){let t=n.state.doc.resolve(e);if(!(Be||mu)&&t.parent.inlineContent){let r=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),i=(s.top+s.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(s.left-r.left)>1)return s.left<r.left?"ltr":"rtl"}if(e<t.end()){let s=n.coordsAtPos(e+1),i=(s.top+s.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(s.left-r.left)>1)return s.left>r.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Ku(n,e,t){let o=n.state.selection;if(o instanceof Q&&!o.empty||t.indexOf("s")>-1||Qe&&t.indexOf("m")>-1)return!1;let{$from:r,$to:s}=o;if(!r.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let i=dl(n.state,e);if(i&&i instanceof Y)return Xt(n,i)}if(!r.parent.inlineContent){let i=e<0?r:s,l=o instanceof qe?ee.near(i,e):ee.findFrom(i,e);return l?Xt(n,l):!1}return!1}function qu(n,e){if(!(n.state.selection instanceof Q))return!0;let{$head:t,$anchor:o,empty:r}=n.state.selection;if(!t.sameParent(o))return!0;if(!r)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let i=n.state.tr;return e<0?i.delete(t.pos-s.nodeSize,t.pos):i.delete(t.pos,t.pos+s.nodeSize),n.dispatch(i),!0}return!1}function Ju(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function D1(n){if(!Pe||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let o=e.firstChild;Ju(n,o,"true"),setTimeout(()=>Ju(n,o,"false"),20)}return!1}function R1(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function P1(n,e){let t=e.keyCode,o=R1(e);if(t==8||Qe&&t==72&&o=="c")return qu(n,-1)||no(n,-1);if(t==46&&!e.shiftKey||Qe&&t==68&&o=="c")return qu(n,1)||no(n,1);if(t==13||t==27)return!0;if(t==37||Qe&&t==66&&o=="c"){let r=t==37?Wu(n,n.state.selection.from)=="ltr"?-1:1:-1;return ju(n,r,o)||no(n,r)}else if(t==39||Qe&&t==70&&o=="c"){let r=t==39?Wu(n,n.state.selection.from)=="ltr"?1:-1:1;return ju(n,r,o)||no(n,r)}else{if(t==38||Qe&&t==80&&o=="c")return Ku(n,-1,o)||no(n,-1);if(t==40||Qe&&t==78&&o=="c")return D1(n)||Ku(n,1,o)||no(n,1);if(o==(Qe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function fl(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:o,openStart:r,openEnd:s}=e;for(;r>1&&s>1&&o.childCount==1&&o.firstChild.childCount==1;){r--,s--;let p=o.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),o=p.content}let i=n.someProp("clipboardSerializer")||xn.fromSchema(n.state.schema),l=nf(),c=l.createElement("div");c.appendChild(i.serializeFragment(o,{document:l}));let d=c.firstChild,u,f=0;for(;d&&d.nodeType==1&&(u=ef[d.nodeName.toLowerCase()]);){for(let p=u.length-1;p>=0;p--){let m=l.createElement(u[p]);for(;c.firstChild;)m.appendChild(c.firstChild);c.appendChild(m),f++}d=c.firstChild}d&&d.nodeType==1&&d.setAttribute("data-pm-slice",`${r} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let h=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,`
|
|
4
|
+
`),t)}ignoreFallback(e,t){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"),t,!0)}readStyles(e,t){let o=e.style;if(o&&o.length)for(let r=0;r<this.parser.matchedStyles.length;r++){let s=this.parser.matchedStyles[r],i=o.getPropertyValue(s);if(i)for(let l=void 0;;){let c=this.parser.matchStyle(s,i,this,l);if(!c)break;if(c.ignore)return null;if(c.clearMark?t=t.filter(d=>!c.clearMark(d)):t=t.concat(this.parser.schema.marks[c.mark].create(c.attrs)),c.consuming===!1)l=c;else break}}return t}addElementByRule(e,t,o,r){let s,i;if(t.node)if(i=this.parser.schema.nodes[t.node],i.isLeaf)this.insertNode(i.create(t.attrs),o,e.nodeName=="BR")||this.leafFallback(e,o);else{let c=this.enter(i,t.attrs||null,o,t.preserveWhitespace);c&&(s=!0,o=c)}else{let c=this.parser.schema.marks[t.mark];o=o.concat(c.create(t.attrs))}let l=this.top;if(i&&i.isLeaf)this.findInside(e);else if(r)this.addElement(e,o,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c,o,!1));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c,o),this.findAround(e,c,!1)}s&&this.sync(l)&&this.open--}addAll(e,t,o,r){let s=o||0;for(let i=o?e.childNodes[o]:e.firstChild,l=r==null?null:e.childNodes[r];i!=l;i=i.nextSibling,++s)this.findAtPoint(e,s),this.addDOM(i,t);this.findAtPoint(e,s)}findPlace(e,t,o){let r,s;for(let i=this.open,l=0;i>=0;i--){let c=this.nodes[i],d=c.findWrapping(e);if(d&&(!r||r.length>d.length+l)&&(r=d,s=c,!d.length))break;if(c.solid){if(o)break;l+=2}}if(!r)return null;this.sync(s);for(let i=0;i<r.length;i++)t=this.enterInner(r[i],null,t,!1);return t}insertNode(e,t,o){if(e.isInline&&this.needsBlock&&!this.top.type){let s=this.textblockFromContext();s&&(t=this.enterInner(s,null,t))}let r=this.findPlace(e,t,o);if(r){this.closeExtra();let s=this.top;s.match&&(s.match=s.match.matchType(e.type));let i=se.none;for(let l of r.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):Ed(l.type,e.type))&&(i=l.addToSet(i));return s.content.push(e.mark(i)),!0}return!1}enter(e,t,o,r){let s=this.findPlace(e.create(t),o,!1);return s&&(s=this.enterInner(e,t,o,!0,r)),s}enterInner(e,t,o,r=!1,s){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(e);let l=Sd(e,s,i.options);i.options&To&&i.content.length==0&&(l|=To);let c=se.none;return o=o.filter(d=>(i.type?i.type.allowsMarkType(d.type):Ed(d.type,e))?(c=d.addToSet(c),!1):!0),this.nodes.push(new Br(e,t,c,r,null,l)),this.open++,o}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=Mo)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let o=this.nodes[t].content;for(let r=o.length-1;r>=0;r--)e+=o[r].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let o=0;o<this.find.length;o++)this.find[o].node==e&&this.find[o].offset==t&&(this.find[o].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,o){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(o?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),o=this.options.context,r=!this.isOpen&&(!o||o.parent.type==this.nodes[0].type),s=-(o?o.depth+1:0)+(r?0:1),i=(l,c)=>{for(;l>=0;l--){let d=t[l];if(d==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(i(l-1,c))return!0;return!1}else{let u=c>0||c==0&&r?this.nodes[c].type:o&&c>=s?o.node(c-s).type:null;if(!u||u.name!=d&&!u.isInGroup(d))return!1;c--}}return!0};return i(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let o=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(o&&o.isTextblock&&o.defaultAttrs)return o}for(let t in this.parser.schema.nodes){let o=this.parser.schema.nodes[t];if(o.isTextblock&&o.defaultAttrs)return o}}}function Z0(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let o=e.nodeType==1?e.nodeName.toLowerCase():null;o&&bd.hasOwnProperty(o)&&t?(t.appendChild(e),e=t):o=="li"?t=e:o&&(t=null)}}function ey(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Cd(n){let e={};for(let t in n)e[t]=n[t];return e}function Ed(n,e){let t=e.schema.nodes;for(let o in t){let r=t[o];if(!r.allowsMarkType(n))continue;let s=[],i=l=>{s.push(l);for(let c=0;c<l.edgeCount;c++){let{type:d,next:u}=l.edge(c);if(d==e||s.indexOf(u)<0&&i(u))return!0}};if(i(r.contentMatch))return!0}}class xn{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},o){o||(o=Pi(t).createDocumentFragment());let r=o,s=[];return e.forEach(i=>{if(s.length||i.marks.length){let l=0,c=0;for(;l<s.length&&c<i.marks.length;){let d=i.marks[c];if(!this.marks[d.type.name]){c++;continue}if(!d.eq(s[l][0])||d.type.spec.spanning===!1)break;l++,c++}for(;l<s.length;)r=s.pop()[1];for(;c<i.marks.length;){let d=i.marks[c++],u=this.serializeMark(d,i.isInline,t);u&&(s.push([d,r]),r.appendChild(u.dom),r=u.contentDOM||u.dom)}}r.appendChild(this.serializeNodeInner(i,t))}),o}serializeNodeInner(e,t){let{dom:o,contentDOM:r}=Ir(Pi(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,r)}return o}serializeNode(e,t={}){let o=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let s=this.serializeMark(e.marks[r],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(o),o=s.dom)}return o}serializeMark(e,t,o={}){let r=this.marks[e.type.name];return r&&Ir(Pi(o),r(e,t),null,e.attrs)}static renderSpec(e,t,o=null,r){return Ir(e,t,o,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new xn(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=vd(e.nodes);return t.text||(t.text=o=>o.text),t}static marksFromSchema(e){return vd(e.marks)}}function vd(n){let e={};for(let t in n){let o=n[t].spec.toDOM;o&&(e[t]=o)}return e}function Pi(n){return n.document||window.document}const Md=new WeakMap;function ty(n){let e=Md.get(n);return e===void 0&&Md.set(n,e=ny(n)),e}function ny(n){let e=null;function t(o){if(o&&typeof o=="object")if(Array.isArray(o))if(typeof o[0]=="string")e||(e=[]),e.push(o);else for(let r=0;r<o.length;r++)t(o[r]);else for(let r in o)t(o[r])}return t(n),e}function Ir(n,e,t,o){if(typeof e=="string")return{dom:n.createTextNode(e)};if(e.nodeType!=null)return{dom:e};if(e.dom&&e.dom.nodeType!=null)return e;let r=e[0],s;if(typeof r!="string")throw new RangeError("Invalid array passed to renderSpec");if(o&&(s=ty(o))&&s.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let i=r.indexOf(" ");i>0&&(t=r.slice(0,i),r=r.slice(i+1));let l,c=t?n.createElementNS(t,r):n.createElement(r),d=e[1],u=1;if(d&&typeof d=="object"&&d.nodeType==null&&!Array.isArray(d)){u=2;for(let f in d)if(d[f]!=null){let h=f.indexOf(" ");h>0?c.setAttributeNS(f.slice(0,h),f.slice(h+1),d[f]):f=="style"&&c.style?c.style.cssText=d[f]:c.setAttribute(f,d[f])}}for(let f=u;f<e.length;f++){let h=e[f];if(h===0){if(f<e.length-1||f>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:c,contentDOM:c}}else{let{dom:p,contentDOM:m}=Ir(n,h,t,o);if(c.appendChild(p),m){if(l)throw new RangeError("Multiple content holes");l=m}}}return{dom:c,contentDOM:l}}const Td=65535,Nd=Math.pow(2,16);function oy(n,e){return n+e*Nd}function Ad(n){return n&Td}function ry(n){return(n-(n&Td))/Nd}const Bd=1,Id=2,Or=4,Od=8;class Li{constructor(e,t,o){this.pos=e,this.delInfo=t,this.recover=o}get deleted(){return(this.delInfo&Od)>0}get deletedBefore(){return(this.delInfo&(Bd|Or))>0}get deletedAfter(){return(this.delInfo&(Id|Or))>0}get deletedAcross(){return(this.delInfo&Or)>0}}class Ke{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Ke.empty)return Ke.empty}recover(e){let t=0,o=Ad(e);if(!this.inverted)for(let r=0;r<o;r++)t+=this.ranges[r*3+2]-this.ranges[r*3+1];return this.ranges[o*3]+t+ry(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,o){let r=0,s=this.inverted?2:1,i=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let c=this.ranges[l]-(this.inverted?r:0);if(c>e)break;let d=this.ranges[l+s],u=this.ranges[l+i],f=c+d;if(e<=f){let h=d?e==c?-1:e==f?1:t:t,p=c+r+(h<0?0:u);if(o)return p;let m=e==(t<0?c:f)?null:oy(l/3,e-c),g=e==c?Id:e==f?Bd:Or;return(t<0?e!=c:e!=f)&&(g|=Od),new Li(p,g,m)}r+=u-d}return o?e+r:new Li(e+r,0,null)}touches(e,t){let o=0,r=Ad(t),s=this.inverted?2:1,i=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let c=this.ranges[l]-(this.inverted?o:0);if(c>e)break;let d=this.ranges[l+s],u=c+d;if(e<=u&&l==r*3)return!0;o+=this.ranges[l+i]-d}return!1}forEach(e){let t=this.inverted?2:1,o=this.inverted?1:2;for(let r=0,s=0;r<this.ranges.length;r+=3){let i=this.ranges[r],l=i-(this.inverted?s:0),c=i+(this.inverted?0:s),d=this.ranges[r+t],u=this.ranges[r+o];e(l,l+d,c,c+u),s+=u-d}}invert(){return new Ke(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Ke.empty:new Ke(e<0?[0,-e,0]:[0,0,e])}}Ke.empty=new Ke([]);class No{constructor(e,t,o=0,r=e?e.length:0){this.mirror=t,this.from=o,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new No(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,o=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?o+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,o=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?o-r-1:void 0)}}invert(){let e=new No;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let o=this.from;o<this.to;o++)e=this._maps[o].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,o){let r=0;for(let s=this.from;s<this.to;s++){let i=this._maps[s],l=i.mapResult(e,t);if(l.recover!=null){let c=this.getMirror(s);if(c!=null&&c>s&&c<this.to){s=c,e=this._maps[c].recover(l.recover);continue}}r|=l.delInfo,e=l.pos}return o?e:new Li(e,r,null)}}const Vi=Object.create(null);class Re{getMap(){return Ke.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let o=Vi[t.stepType];if(!o)throw new RangeError(`No step type ${t.stepType} defined`);return o.fromJSON(e,t)}static jsonID(e,t){if(e in Vi)throw new RangeError("Duplicate use of step JSON ID "+e);return Vi[e]=t,t.prototype.jsonID=e,t}}class ye{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new ye(e,null)}static fail(e){return new ye(null,e)}static fromReplace(e,t,o,r){try{return ye.ok(e.replace(t,o,r))}catch(s){if(s instanceof vr)return ye.fail(s.message);throw s}}}function $i(n,e,t){let o=[];for(let r=0;r<n.childCount;r++){let s=n.child(r);s.content.size&&(s=s.copy($i(s.content,e,s))),s.isInline&&(s=e(s,t,r)),o.push(s)}return P.fromArray(o)}class Wt extends Re{constructor(e,t,o){super(),this.from=e,this.to=t,this.mark=o}apply(e){let t=e.slice(this.from,this.to),o=e.resolve(this.from),r=o.node(o.sharedDepth(this.to)),s=new U($i(t.content,(i,l)=>!i.isAtom||!l.type.allowsMarkType(this.mark.type)?i:i.mark(this.mark.addToSet(i.marks)),r),t.openStart,t.openEnd);return ye.fromReplace(e,this.from,this.to,s)}invert(){return new rt(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1);return t.deleted&&o.deleted||t.pos>=o.pos?null:new Wt(t.pos,o.pos,this.mark)}merge(e){return e instanceof Wt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Wt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new Wt(t.from,t.to,e.markFromJSON(t.mark))}}Re.jsonID("addMark",Wt);class rt extends Re{constructor(e,t,o){super(),this.from=e,this.to=t,this.mark=o}apply(e){let t=e.slice(this.from,this.to),o=new U($i(t.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),t.openStart,t.openEnd);return ye.fromReplace(e,this.from,this.to,o)}invert(){return new Wt(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1);return t.deleted&&o.deleted||t.pos>=o.pos?null:new rt(t.pos,o.pos,this.mark)}merge(e){return e instanceof rt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new rt(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new rt(t.from,t.to,e.markFromJSON(t.mark))}}Re.jsonID("removeMark",rt);class Kt extends Re{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ye.fail("No node at mark step's position");let o=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ye.fromReplace(e,this.pos,this.pos+1,new U(P.from(o),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let o=this.mark.addToSet(t.marks);if(o.length==t.marks.length){for(let r=0;r<t.marks.length;r++)if(!t.marks[r].isInSet(o))return new Kt(this.pos,t.marks[r]);return new Kt(this.pos,this.mark)}}return new Cn(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Kt(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new Kt(t.pos,e.markFromJSON(t.mark))}}Re.jsonID("addNodeMark",Kt);class Cn extends Re{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ye.fail("No node at mark step's position");let o=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return ye.fromReplace(e,this.pos,this.pos+1,new U(P.from(o),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Kt(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Cn(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new Cn(t.pos,e.markFromJSON(t.mark))}}Re.jsonID("removeNodeMark",Cn);class Se extends Re{constructor(e,t,o,r=!1){super(),this.from=e,this.to=t,this.slice=o,this.structure=r}apply(e){return this.structure&&zi(e,this.from,this.to)?ye.fail("Structure replace would overwrite content"):ye.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Ke([this.from,this.to-this.from,this.slice.size])}invert(e){return new Se(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1);return t.deletedAcross&&o.deletedAcross?null:new Se(t.pos,Math.max(t.pos,o.pos),this.slice,this.structure)}merge(e){if(!(e instanceof Se)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?U.empty:new U(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new Se(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?U.empty:new U(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new Se(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new Se(t.from,t.to,U.fromJSON(e,t.slice),!!t.structure)}}Re.jsonID("replace",Se);class xe extends Re{constructor(e,t,o,r,s,i,l=!1){super(),this.from=e,this.to=t,this.gapFrom=o,this.gapTo=r,this.slice=s,this.insert=i,this.structure=l}apply(e){if(this.structure&&(zi(e,this.from,this.gapFrom)||zi(e,this.gapTo,this.to)))return ye.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return ye.fail("Gap is not a flat range");let o=this.slice.insertAt(this.insert,t.content);return o?ye.fromReplace(e,this.from,this.to,o):ye.fail("Content does not fit in gap")}getMap(){return new Ke([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new xe(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),o=e.mapResult(this.to,-1),r=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?o.pos:e.map(this.gapTo,1);return t.deletedAcross&&o.deletedAcross||r<t.pos||s>o.pos?null:new xe(t.pos,o.pos,r,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new xe(t.from,t.to,t.gapFrom,t.gapTo,U.fromJSON(e,t.slice),t.insert,!!t.structure)}}Re.jsonID("replaceAround",xe);function zi(n,e,t){let o=n.resolve(e),r=t-e,s=o.depth;for(;r>0&&s>0&&o.indexAfter(s)==o.node(s).childCount;)s--,r--;if(r>0){let i=o.node(s).maybeChild(o.indexAfter(s));for(;r>0;){if(!i||i.isLeaf)return!0;i=i.firstChild,r--}}return!1}function sy(n,e,t,o){let r=[],s=[],i,l;n.doc.nodesBetween(e,t,(c,d,u)=>{if(!c.isInline)return;let f=c.marks;if(!o.isInSet(f)&&u.type.allowsMarkType(o.type)){let h=Math.max(d,e),p=Math.min(d+c.nodeSize,t),m=o.addToSet(f);for(let g=0;g<f.length;g++)f[g].isInSet(m)||(i&&i.to==h&&i.mark.eq(f[g])?i.to=p:r.push(i=new rt(h,p,f[g])));l&&l.to==h?l.to=p:s.push(l=new Wt(h,p,o))}}),r.forEach(c=>n.step(c)),s.forEach(c=>n.step(c))}function iy(n,e,t,o){let r=[],s=0;n.doc.nodesBetween(e,t,(i,l)=>{if(!i.isInline)return;s++;let c=null;if(o instanceof Ar){let d=i.marks,u;for(;u=o.isInSet(d);)(c||(c=[])).push(u),d=u.removeFromSet(d)}else o?o.isInSet(i.marks)&&(c=[o]):c=i.marks;if(c&&c.length){let d=Math.min(l+i.nodeSize,t);for(let u=0;u<c.length;u++){let f=c[u],h;for(let p=0;p<r.length;p++){let m=r[p];m.step==s-1&&f.eq(r[p].style)&&(h=m)}h?(h.to=d,h.step=s):r.push({style:f,from:Math.max(l,e),to:d,step:s})}}}),r.forEach(i=>n.step(new rt(i.from,i.to,i.style)))}function Fi(n,e,t,o=t.contentMatch,r=!0){let s=n.doc.nodeAt(e),i=[],l=e+1;for(let c=0;c<s.childCount;c++){let d=s.child(c),u=l+d.nodeSize,f=o.matchType(d.type);if(!f)i.push(new Se(l,u,U.empty));else{o=f;for(let h=0;h<d.marks.length;h++)t.allowsMarkType(d.marks[h].type)||n.step(new rt(l,u,d.marks[h]));if(r&&d.isText&&t.whitespace!="pre"){let h,p=/\r?\n|\r/g,m;for(;h=p.exec(d.text);)m||(m=new U(P.from(t.schema.text(" ",t.allowedMarks(d.marks))),0,0)),i.push(new Se(l+h.index,l+h.index+h[0].length,m))}}l=u}if(!o.validEnd){let c=o.fillBefore(P.empty,!0);n.replace(l,l,new U(c,0,0))}for(let c=i.length-1;c>=0;c--)n.step(i[c])}function ly(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function qn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let o=n.depth,r=0,s=0;;--o){let i=n.$from.node(o),l=n.$from.index(o)+r,c=n.$to.indexAfter(o)-s;if(o<n.depth&&i.canReplace(l,c,t))return o;if(o==0||i.type.spec.isolating||!ly(i,l,c))break;l&&(r=1),c<i.childCount&&(s=1)}return null}function ay(n,e,t){let{$from:o,$to:r,depth:s}=e,i=o.before(s+1),l=r.after(s+1),c=i,d=l,u=P.empty,f=0;for(let m=s,g=!1;m>t;m--)g||o.index(m)>0?(g=!0,u=P.from(o.node(m).copy(u)),f++):c--;let h=P.empty,p=0;for(let m=s,g=!1;m>t;m--)g||r.after(m+1)<r.end(m)?(g=!0,h=P.from(r.node(m).copy(h)),p++):d++;n.step(new xe(c,d,i,l,new U(u.append(h),f,p),u.size-f,!0))}function _d(n,e,t=null,o=n){let r=cy(n,e),s=r&&dy(o,e);return s?r.map(Dd).concat({type:e,attrs:t}).concat(s.map(Dd)):null}function Dd(n){return{type:n,attrs:null}}function cy(n,e){let{parent:t,startIndex:o,endIndex:r}=n,s=t.contentMatchAt(o).findWrapping(e);if(!s)return null;let i=s.length?s[0]:e;return t.canReplaceWith(o,r,i)?s:null}function dy(n,e){let{parent:t,startIndex:o,endIndex:r}=n,s=t.child(o),i=e.contentMatch.findWrapping(s.type);if(!i)return null;let c=(i.length?i[i.length-1]:e).contentMatch;for(let d=o;c&&d<r;d++)c=c.matchType(t.child(d).type);return!c||!c.validEnd?null:i}function uy(n,e,t){let o=P.empty;for(let i=t.length-1;i>=0;i--){if(o.size){let l=t[i].type.contentMatch.matchFragment(o);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}o=P.from(t[i].type.create(t[i].attrs,o))}let r=e.start,s=e.end;n.step(new xe(r,s,r,s,new U(o,0,0),t.length,!0))}function fy(n,e,t,o,r){if(!o.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(i,l)=>{let c=typeof r=="function"?r(i):r;if(i.isTextblock&&!i.hasMarkup(o,c)&&hy(n.doc,n.mapping.slice(s).map(l),o)){let d=null;if(o.schema.linebreakReplacement){let p=o.whitespace=="pre",m=!!o.contentMatch.matchType(o.schema.linebreakReplacement);p&&!m?d=!1:!p&&m&&(d=!0)}d===!1&&Pd(n,i,l,s),Fi(n,n.mapping.slice(s).map(l,1),o,void 0,d===null);let u=n.mapping.slice(s),f=u.map(l,1),h=u.map(l+i.nodeSize,1);return n.step(new xe(f,h,f+1,h-1,new U(P.from(o.create(c,null,i.marks)),0,0),1,!0)),d===!0&&Rd(n,i,l,s),!1}})}function Rd(n,e,t,o){e.forEach((r,s)=>{if(r.isText){let i,l=/\r?\n|\r/g;for(;i=l.exec(r.text);){let c=n.mapping.slice(o).map(t+1+s+i.index);n.replaceWith(c,c+1,e.type.schema.linebreakReplacement.create())}}})}function Pd(n,e,t,o){e.forEach((r,s)=>{if(r.type==r.type.schema.linebreakReplacement){let i=n.mapping.slice(o).map(t+1+s);n.replaceWith(i,i+1,e.type.schema.text(`
|
|
5
|
+
`))}})}function hy(n,e,t){let o=n.resolve(e),r=o.index();return o.parent.canReplaceWith(r,r+1,t)}function py(n,e,t,o,r){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let i=t.create(o,null,r||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,i);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new xe(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new U(P.from(i),0,0),1,!0))}function It(n,e,t=1,o){let r=n.resolve(e),s=r.depth-t,i=o&&o[o.length-1]||r.parent;if(s<0||r.parent.type.spec.isolating||!r.parent.canReplace(r.index(),r.parent.childCount)||!i.type.validContent(r.parent.content.cutByIndex(r.index(),r.parent.childCount)))return!1;for(let d=r.depth-1,u=t-2;d>s;d--,u--){let f=r.node(d),h=r.index(d);if(f.type.spec.isolating)return!1;let p=f.content.cutByIndex(h,f.childCount),m=o&&o[u+1];m&&(p=p.replaceChild(0,m.type.create(m.attrs)));let g=o&&o[u]||f;if(!f.canReplace(h+1,f.childCount)||!g.type.validContent(p))return!1}let l=r.indexAfter(s),c=o&&o[0];return r.node(s).canReplaceWith(l,l,c?c.type:r.node(s+1).type)}function my(n,e,t=1,o){let r=n.doc.resolve(e),s=P.empty,i=P.empty;for(let l=r.depth,c=r.depth-t,d=t-1;l>c;l--,d--){s=P.from(r.node(l).copy(s));let u=o&&o[d];i=P.from(u?u.type.create(u.attrs,i):r.node(l).copy(i))}n.step(new Se(e,e,new U(s.append(i),t,t),!0))}function En(n,e){let t=n.resolve(e),o=t.index();return Ld(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(o,o+1)}function gy(n,e){e.content.size||n.type.compatibleContent(e.type);let t=n.contentMatchAt(n.childCount),{linebreakReplacement:o}=n.type.schema;for(let r=0;r<e.childCount;r++){let s=e.child(r),i=s.type==o?n.type.schema.nodes.text:s.type;if(t=t.matchType(i),!t||!n.type.allowsMarks(s.marks))return!1}return t.validEnd}function Ld(n,e){return!!(n&&e&&!n.isLeaf&&gy(n,e))}function _r(n,e,t=-1){let o=n.resolve(e);for(let r=o.depth;;r--){let s,i,l=o.index(r);if(r==o.depth?(s=o.nodeBefore,i=o.nodeAfter):t>0?(s=o.node(r+1),l++,i=o.node(r).maybeChild(l)):(s=o.node(r).maybeChild(l-1),i=o.node(r+1)),s&&!s.isTextblock&&Ld(s,i)&&o.node(r).canReplace(l,l+1))return e;if(r==0)break;e=t<0?o.before(r):o.after(r)}}function yy(n,e,t){let o=null,{linebreakReplacement:r}=n.doc.type.schema,s=n.doc.resolve(e-t),i=s.node().type;if(r&&i.inlineContent){let u=i.whitespace=="pre",f=!!i.contentMatch.matchType(r);u&&!f?o=!1:!u&&f&&(o=!0)}let l=n.steps.length;if(o===!1){let u=n.doc.resolve(e+t);Pd(n,u.node(),u.before(),l)}i.inlineContent&&Fi(n,e+t-1,i,s.node().contentMatchAt(s.index()),o==null);let c=n.mapping.slice(l),d=c.map(e-t);if(n.step(new Se(d,c.map(e+t,-1),U.empty,!0)),o===!0){let u=n.doc.resolve(d);Rd(n,u.node(),u.before(),n.steps.length)}return n}function ky(n,e,t){let o=n.resolve(e);if(o.parent.canReplaceWith(o.index(),o.index(),t))return e;if(o.parentOffset==0)for(let r=o.depth-1;r>=0;r--){let s=o.index(r);if(o.node(r).canReplaceWith(s,s,t))return o.before(r+1);if(s>0)return null}if(o.parentOffset==o.parent.content.size)for(let r=o.depth-1;r>=0;r--){let s=o.indexAfter(r);if(o.node(r).canReplaceWith(s,s,t))return o.after(r+1);if(s<o.node(r).childCount)return null}return null}function Vd(n,e,t){let o=n.resolve(e);if(!t.content.size)return e;let r=t.content;for(let s=0;s<t.openStart;s++)r=r.firstChild.content;for(let s=1;s<=(t.openStart==0&&t.size?2:1);s++)for(let i=o.depth;i>=0;i--){let l=i==o.depth?0:o.pos<=(o.start(i+1)+o.end(i+1))/2?-1:1,c=o.index(i)+(l>0?1:0),d=o.node(i),u=!1;if(s==1)u=d.canReplace(c,c,r);else{let f=d.contentMatchAt(c).findWrapping(r.firstChild.type);u=f&&d.canReplaceWith(c,c,f[0])}if(u)return l==0?o.pos:l<0?o.before(i+1):o.after(i+1)}return null}function Dr(n,e,t=e,o=U.empty){if(e==t&&!o.size)return null;let r=n.resolve(e),s=n.resolve(t);return $d(r,s,o)?new Se(e,t,o):new wy(r,s,o).fit()}function $d(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class wy{constructor(e,t,o){this.$from=e,this.$to=t,this.unplaced=o,this.frontier=[],this.placed=P.empty;for(let r=0;r<=e.depth;r++){let s=e.node(r);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(r))})}for(let r=e.depth;r>0;r--)this.placed=P.from(e.node(r).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let d=this.findFittable();d?this.placeNodes(d):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,o=this.$from,r=this.close(e<0?this.$to:o.doc.resolve(e));if(!r)return null;let s=this.placed,i=o.depth,l=r.depth;for(;i&&l&&s.childCount==1;)s=s.firstChild.content,i--,l--;let c=new U(s,i,l);return e>-1?new xe(o.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||o.pos!=this.$to.pos?new Se(o.pos,r.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,o=0,r=this.unplaced.openEnd;o<e;o++){let s=t.firstChild;if(t.childCount>1&&(r=0),s.type.spec.isolating&&r<=o){e=o;break}t=s.content}for(let t=1;t<=2;t++)for(let o=t==1?e:this.unplaced.openStart;o>=0;o--){let r,s=null;o?(s=Hi(this.unplaced.content,o-1).firstChild,r=s.content):r=this.unplaced.content;let i=r.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:d}=this.frontier[l],u,f=null;if(t==1&&(i?d.matchType(i.type)||(f=d.fillBefore(P.from(i),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:o,frontierDepth:l,parent:s,inject:f};if(t==2&&i&&(u=d.findWrapping(i.type)))return{sliceDepth:o,frontierDepth:l,parent:s,wrap:u};if(s&&d.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:o}=this.unplaced,r=Hi(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new U(e,t+1,Math.max(o,r.size+t>=e.size-o?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:o}=this.unplaced,r=Hi(e,t);if(r.childCount<=1&&t>0){let s=e.size-t<=t+r.size;this.unplaced=new U(Ao(e,t-1,1),t-1,s?t-1:o)}else this.unplaced=new U(Ao(e,t,1),t,o)}placeNodes({sliceDepth:e,frontierDepth:t,parent:o,inject:r,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let g=0;g<s.length;g++)this.openFrontierNode(s[g]);let i=this.unplaced,l=o?o.content:i.content,c=i.openStart-e,d=0,u=[],{match:f,type:h}=this.frontier[t];if(r){for(let g=0;g<r.childCount;g++)u.push(r.child(g));f=f.matchFragment(r)}let p=l.size+e-(i.content.size-i.openEnd);for(;d<l.childCount;){let g=l.child(d),y=f.matchType(g.type);if(!y)break;d++,(d>1||c==0||g.content.size)&&(f=y,u.push(zd(g.mark(h.allowedMarks(g.marks)),d==1?c:0,d==l.childCount?p:-1)))}let m=d==l.childCount;m||(p=-1),this.placed=Bo(this.placed,t,P.from(u)),this.frontier[t].match=f,m&&p<0&&o&&o.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let g=0,y=l;g<p;g++){let k=y.lastChild;this.frontier.push({type:k.type,match:k.contentMatchAt(k.childCount)}),y=k.content}this.unplaced=m?e==0?U.empty:new U(Ao(i.content,e-1,1),e-1,p<0?i.openEnd:e-1):new U(Ao(i.content,e,d),i.openStart,i.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!ji(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:o}=this.$to,r=this.$to.after(o);for(;o>1&&r==this.$to.end(--o);)++r;return r}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:o,type:r}=this.frontier[t],s=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),i=ji(e,t,r,o,s);if(i){for(let l=t-1;l>=0;l--){let{match:c,type:d}=this.frontier[l],u=ji(e,l,d,c,!0);if(!u||u.childCount)continue e}return{depth:t,fit:i,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Bo(this.placed,t.depth,t.fit)),e=t.move;for(let o=t.depth+1;o<=e.depth;o++){let r=e.node(o),s=r.type.contentMatch.fillBefore(r.content,!0,e.index(o));this.openFrontierNode(r.type,r.attrs,s)}return e}openFrontierNode(e,t=null,o){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=Bo(this.placed,this.depth,P.from(e.create(t,o))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(P.empty,!0);t.childCount&&(this.placed=Bo(this.placed,this.frontier.length,t))}}function Ao(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Ao(n.firstChild.content,e-1,t)))}function Bo(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Bo(n.lastChild.content,e-1,t)))}function Hi(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function zd(n,e,t){if(e<=0)return n;let o=n.content;return e>1&&(o=o.replaceChild(0,zd(o.firstChild,e-1,o.childCount==1?t-1:0))),e>0&&(o=n.type.contentMatch.fillBefore(o).append(o),t<=0&&(o=o.append(n.type.contentMatch.matchFragment(o).fillBefore(P.empty,!0)))),n.copy(o)}function ji(n,e,t,o,r){let s=n.node(e),i=r?n.indexAfter(e):n.index(e);if(i==s.childCount&&!t.compatibleContent(s.type))return null;let l=o.fillBefore(s.content,!0,i);return l&&!by(t,s.content,i)?l:null}function by(n,e,t){for(let o=t;o<e.childCount;o++)if(!n.allowsMarks(e.child(o).marks))return!0;return!1}function Sy(n){return n.spec.defining||n.spec.definingForContent}function xy(n,e,t,o){if(!o.size)return n.deleteRange(e,t);let r=n.doc.resolve(e),s=n.doc.resolve(t);if($d(r,s,o))return n.step(new Se(e,t,o));let i=Hd(r,s);i[i.length-1]==0&&i.pop();let l=-(r.depth+1);i.unshift(l);for(let h=r.depth,p=r.pos-1;h>0;h--,p--){let m=r.node(h).type.spec;if(m.defining||m.definingAsContext||m.isolating)break;i.indexOf(h)>-1?l=h:r.before(h)==p&&i.splice(1,0,-h)}let c=i.indexOf(l),d=[],u=o.openStart;for(let h=o.content,p=0;;p++){let m=h.firstChild;if(d.push(m),p==o.openStart)break;h=m.content}for(let h=u-1;h>=0;h--){let p=d[h],m=Sy(p.type);if(m&&!p.sameMarkup(r.node(Math.abs(l)-1)))u=h;else if(m||!p.type.isTextblock)break}for(let h=o.openStart;h>=0;h--){let p=(h+u+1)%(o.openStart+1),m=d[p];if(m)for(let g=0;g<i.length;g++){let y=i[(g+c)%i.length],k=!0;y<0&&(k=!1,y=-y);let x=r.node(y-1),b=r.index(y-1);if(x.canReplaceWith(b,b,m.type,m.marks))return n.replace(r.before(y),k?s.after(y):t,new U(Fd(o.content,0,o.openStart,p),p,o.openEnd))}}let f=n.steps.length;for(let h=i.length-1;h>=0&&(n.replace(e,t,o),!(n.steps.length>f));h--){let p=i[h];p<0||(e=r.before(p),t=s.after(p))}}function Fd(n,e,t,o,r){if(e<t){let s=n.firstChild;n=n.replaceChild(0,s.copy(Fd(s.content,e+1,t,o,s)))}if(e>o){let s=r.contentMatchAt(0),i=s.fillBefore(n).append(n);n=i.append(s.matchFragment(i).fillBefore(P.empty,!0))}return n}function Cy(n,e,t,o){if(!o.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let r=ky(n.doc,e,o.type);r!=null&&(e=t=r)}n.replaceRange(e,t,new U(P.from(o),0,0))}function Ey(n,e,t){let o=n.doc.resolve(e),r=n.doc.resolve(t),s=Hd(o,r);for(let i=0;i<s.length;i++){let l=s[i],c=i==s.length-1;if(c&&l==0||o.node(l).type.contentMatch.validEnd)return n.delete(o.start(l),r.end(l));if(l>0&&(c||o.node(l-1).canReplace(o.index(l-1),r.indexAfter(l-1))))return n.delete(o.before(l),r.after(l))}for(let i=1;i<=o.depth&&i<=r.depth;i++)if(e-o.start(i)==o.depth-i&&t>o.end(i)&&r.end(i)-t!=r.depth-i&&o.start(i-1)==r.start(i-1)&&o.node(i-1).canReplace(o.index(i-1),r.index(i-1)))return n.delete(o.before(i),t);n.delete(e,t)}function Hd(n,e){let t=[],o=Math.min(n.depth,e.depth);for(let r=o;r>=0;r--){let s=n.start(r);if(s<n.pos-(n.depth-r)||e.end(r)>e.pos+(e.depth-r)||n.node(r).type.spec.isolating||e.node(r).type.spec.isolating)break;(s==e.start(r)||r==n.depth&&r==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&r&&e.start(r-1)==s-1)&&t.push(r)}return t}class Jn extends Re{constructor(e,t,o){super(),this.pos=e,this.attr=t,this.value=o}apply(e){let t=e.nodeAt(this.pos);if(!t)return ye.fail("No node at attribute step's position");let o=Object.create(null);for(let s in t.attrs)o[s]=t.attrs[s];o[this.attr]=this.value;let r=t.type.create(o,null,t.marks);return ye.fromReplace(e,this.pos,this.pos+1,new U(P.from(r),0,t.isLeaf?0:1))}getMap(){return Ke.empty}invert(e){return new Jn(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Jn(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new Jn(t.pos,t.attr,t.value)}}Re.jsonID("attr",Jn);class Io extends Re{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let r in e.attrs)t[r]=e.attrs[r];t[this.attr]=this.value;let o=e.type.create(t,e.content,e.marks);return ye.ok(o)}getMap(){return Ke.empty}invert(e){return new Io(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new Io(t.attr,t.value)}}Re.jsonID("docAttr",Io);let Gn=class extends Error{};Gn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t},Gn.prototype=Object.create(Error.prototype),Gn.prototype.constructor=Gn,Gn.prototype.name="TransformError";class jd{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new No}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Gn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}changedRange(){let e=1e9,t=-1e9;for(let o=0;o<this.mapping.maps.length;o++){let r=this.mapping.maps[o];o&&(e=r.map(e,1),t=r.map(t,-1)),r.forEach((s,i,l,c)=>{e=Math.min(e,l),t=Math.max(t,c)})}return e==1e9?null:{from:e,to:t}}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,o=U.empty){let r=Dr(this.doc,e,t,o);return r&&this.step(r),this}replaceWith(e,t,o){return this.replace(e,t,new U(P.from(o),0,0))}delete(e,t){return this.replace(e,t,U.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,o){return xy(this,e,t,o),this}replaceRangeWith(e,t,o){return Cy(this,e,t,o),this}deleteRange(e,t){return Ey(this,e,t),this}lift(e,t){return ay(this,e,t),this}join(e,t=1){return yy(this,e,t),this}wrap(e,t){return uy(this,e,t),this}setBlockType(e,t=e,o,r=null){return fy(this,e,t,o,r),this}setNodeMarkup(e,t,o=null,r){return py(this,e,t,o,r),this}setNodeAttribute(e,t,o){return this.step(new Jn(e,t,o)),this}setDocAttribute(e,t){return this.step(new Io(e,t)),this}addNodeMark(e,t){return this.step(new Kt(e,t)),this}removeNodeMark(e,t){let o=this.doc.nodeAt(e);if(!o)throw new RangeError("No node at position "+e);if(t instanceof se)t.isInSet(o.marks)&&this.step(new Cn(e,t));else{let r=o.marks,s,i=[];for(;s=t.isInSet(r);)i.push(new Cn(e,s)),r=s.removeFromSet(r);for(let l=i.length-1;l>=0;l--)this.step(i[l])}return this}split(e,t=1,o){return my(this,e,t,o),this}addMark(e,t,o){return sy(this,e,t,o),this}removeMark(e,t,o){return iy(this,e,t,o),this}clearIncompatible(e,t,o){return Fi(this,e,t,o),this}}const Ui=Object.create(null);class ee{constructor(e,t,o){this.$anchor=e,this.$head=t,this.ranges=o||[new vy(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=U.empty){let o=t.content.lastChild,r=null;for(let l=0;l<t.openEnd;l++)r=o,o=o.lastChild;let s=e.steps.length,i=this.ranges;for(let l=0;l<i.length;l++){let{$from:c,$to:d}=i[l],u=e.mapping.slice(s);e.replaceRange(u.map(c.pos),u.map(d.pos),l?U.empty:t),l==0&&Kd(e,s,(o?o.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let o=e.steps.length,r=this.ranges;for(let s=0;s<r.length;s++){let{$from:i,$to:l}=r[s],c=e.mapping.slice(o),d=c.map(i.pos),u=c.map(l.pos);s?e.deleteRange(d,u):(e.replaceRangeWith(d,u,t),Kd(e,o,t.isInline?-1:1))}}static findFrom(e,t,o=!1){let r=e.parent.inlineContent?new Q(e):Yn(e.node(0),e.parent,e.pos,e.index(),t,o);if(r)return r;for(let s=e.depth-1;s>=0;s--){let i=t<0?Yn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,o):Yn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,o);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new qe(e.node(0))}static atStart(e){return Yn(e,e,0,0,1)||new qe(e)}static atEnd(e){return Yn(e,e,e.content.size,e.childCount,-1)||new qe(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let o=Ui[t.type];if(!o)throw new RangeError(`No selection type ${t.type} defined`);return o.fromJSON(e,t)}static jsonID(e,t){if(e in Ui)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ui[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Q.between(this.$anchor,this.$head).getBookmark()}}ee.prototype.visible=!0;class vy{constructor(e,t){this.$from=e,this.$to=t}}let Ud=!1;function Wd(n){!Ud&&!n.parent.inlineContent&&(Ud=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class Q extends ee{constructor(e,t=e){Wd(e),Wd(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let o=e.resolve(t.map(this.head));if(!o.parent.inlineContent)return ee.near(o);let r=e.resolve(t.map(this.anchor));return new Q(r.parent.inlineContent?r:o,o)}replace(e,t=U.empty){if(super.replace(e,t),t==U.empty){let o=this.$from.marksAcross(this.$to);o&&e.ensureMarks(o)}}eq(e){return e instanceof Q&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Rr(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new Q(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,o=t){let r=e.resolve(t);return new this(r,o==t?r:e.resolve(o))}static between(e,t,o){let r=e.pos-t.pos;if((!o||r)&&(o=r>=0?1:-1),!t.parent.inlineContent){let s=ee.findFrom(t,o,!0)||ee.findFrom(t,-o,!0);if(s)t=s.$head;else return ee.near(t,o)}return e.parent.inlineContent||(r==0?e=t:(e=(ee.findFrom(e,-o,!0)||ee.findFrom(e,o,!0)).$anchor,e.pos<t.pos!=r<0&&(e=t))),new Q(e,t)}}ee.jsonID("text",Q);class Rr{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Rr(e.map(this.anchor),e.map(this.head))}resolve(e){return Q.between(e.resolve(this.anchor),e.resolve(this.head))}}class Y extends ee{constructor(e){let t=e.nodeAfter,o=e.node(0).resolve(e.pos+t.nodeSize);super(e,o),this.node=t}map(e,t){let{deleted:o,pos:r}=t.mapResult(this.anchor),s=e.resolve(r);return o?ee.near(s):new Y(s)}content(){return new U(P.from(this.node),0,0)}eq(e){return e instanceof Y&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Wi(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new Y(e.resolve(t.anchor))}static create(e,t){return new Y(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}Y.prototype.visible=!1,ee.jsonID("node",Y);class Wi{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:o}=e.mapResult(this.anchor);return t?new Rr(o,o):new Wi(o)}resolve(e){let t=e.resolve(this.anchor),o=t.nodeAfter;return o&&Y.isSelectable(o)?new Y(t):ee.near(t)}}class qe extends ee{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=U.empty){if(t==U.empty){e.delete(0,e.doc.content.size);let o=ee.atStart(e.doc);o.eq(e.selection)||e.setSelection(o)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new qe(e)}map(e){return new qe(e)}eq(e){return e instanceof qe}getBookmark(){return My}}ee.jsonID("all",qe);const My={map(){return this},resolve(n){return new qe(n)}};function Yn(n,e,t,o,r,s=!1){if(e.inlineContent)return Q.create(n,t);for(let i=o-(r>0?0:1);r>0?i<e.childCount:i>=0;i+=r){let l=e.child(i);if(l.isAtom){if(!s&&Y.isSelectable(l))return Y.create(n,t-(r<0?l.nodeSize:0))}else{let c=Yn(n,l,t+r,r<0?l.childCount:0,r,s);if(c)return c}t+=l.nodeSize*r}return null}function Kd(n,e,t){let o=n.steps.length-1;if(o<e)return;let r=n.steps[o];if(!(r instanceof Se||r instanceof xe))return;let s=n.mapping.maps[o],i;s.forEach((l,c,d,u)=>{i==null&&(i=u)}),n.setSelection(ee.near(n.doc.resolve(i),t))}const qd=1,Pr=2,Jd=4;class Ty extends jd{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw new RangeError("Selection passed to setSelection must point at the current document");return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|qd)&~Pr,this.storedMarks=null,this}get selectionSet(){return(this.updated&qd)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Pr,this}ensureMarks(e){return se.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Pr)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Pr,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let o=this.selection;return t&&(e=e.mark(this.storedMarks||(o.empty?o.$from.marks():o.$from.marksAcross(o.$to)||se.none))),o.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,o){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(o==null&&(o=t),!e)return this.deleteRange(t,o);let s=this.storedMarks;if(!s){let i=this.doc.resolve(t);s=o==t?i.marks():i.marksAcross(this.doc.resolve(o))}return this.replaceRangeWith(t,o,r.text(e,s)),!this.selection.empty&&this.selection.to==t+e.length&&this.setSelection(ee.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Jd,this}get scrolledIntoView(){return(this.updated&Jd)>0}}function Gd(n,e){return!e||!n?n:n.bind(e)}class Oo{constructor(e,t,o){this.name=e,this.init=Gd(t.init,o),this.apply=Gd(t.apply,o)}}const Ny=[new Oo("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Oo("selection",{init(n,e){return n.selection||ee.atStart(e.doc)},apply(n){return n.selection}}),new Oo("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,o){return o.selection.$cursor?n.storedMarks:null}}),new Oo("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Ki{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=Ny.slice(),t&&t.forEach(o=>{if(this.pluginsByKey[o.key])throw new RangeError("Adding different instances of a keyed plugin ("+o.key+")");this.plugins.push(o),this.pluginsByKey[o.key]=o,o.spec.state&&this.fields.push(new Oo(o.key,o.spec.state,o))})}}class Xn{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let o=0;o<this.config.plugins.length;o++)if(o!=t){let r=this.config.plugins[o];if(r.spec.filterTransaction&&!r.spec.filterTransaction.call(r,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],o=this.applyInner(e),r=null;for(;;){let s=!1;for(let i=0;i<this.config.plugins.length;i++){let l=this.config.plugins[i];if(l.spec.appendTransaction){let c=r?r[i].n:0,d=r?r[i].state:this,u=c<t.length&&l.spec.appendTransaction.call(l,c?t.slice(c):t,d,o);if(u&&o.filterTransaction(u,i)){if(u.setMeta("appendedTransaction",e),!r){r=[];for(let f=0;f<this.config.plugins.length;f++)r.push(f<i?{state:o,n:t.length}:{state:this,n:0})}t.push(u),o=o.applyInner(u),s=!0}r&&(r[i]={state:o,n:t.length})}}if(!s)return{state:o,transactions:t}}}applyInner(e){if(!e.before.eq(this.doc))throw new RangeError("Applying a mismatched transaction");let t=new Xn(this.config),o=this.config.fields;for(let r=0;r<o.length;r++){let s=o[r];t[s.name]=s.apply(e,this[s.name],this,t)}return t}get tr(){return new Ty(this)}static create(e){let t=new Ki(e.doc?e.doc.type.schema:e.schema,e.plugins),o=new Xn(t);for(let r=0;r<t.fields.length;r++)o[t.fields[r].name]=t.fields[r].init(e,o);return o}reconfigure(e){let t=new Ki(this.schema,e.plugins),o=t.fields,r=new Xn(t);for(let s=0;s<o.length;s++){let i=o[s].name;r[i]=this.hasOwnProperty(i)?this[i]:o[s].init(e,r)}return r}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(o=>o.toJSON())),e&&typeof e=="object")for(let o in e){if(o=="doc"||o=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[o],s=r.spec.state;s&&s.toJSON&&(t[o]=s.toJSON.call(r,this[r.key]))}return t}static fromJSON(e,t,o){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let r=new Ki(e.schema,e.plugins),s=new Xn(r);return r.fields.forEach(i=>{if(i.name=="doc")s.doc=At.fromJSON(e.schema,t.doc);else if(i.name=="selection")s.selection=ee.fromJSON(s.doc,t.selection);else if(i.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(o)for(let l in o){let c=o[l],d=c.spec.state;if(c.key==i.name&&d&&d.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[i.name]=d.fromJSON.call(c,e,t[l],s);return}}s[i.name]=i.init(e,s)}}),s}}function Yd(n,e,t){for(let o in n){let r=n[o];r instanceof Function?r=r.bind(e):o=="handleDOMEvents"&&(r=Yd(r,e,{})),t[o]=r}return t}class pe{constructor(e){this.spec=e,this.props={},e.props&&Yd(e.props,this,this.props),this.key=e.key?e.key.key:Xd("plugin")}getState(e){return e[this.key]}}const qi=Object.create(null);function Xd(n){return n in qi?n+"$"+ ++qi[n]:(qi[n]=0,n+"$")}class Ce{constructor(e="key"){this.key=Xd(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Ji=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Qd(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Zd=(n,e,t)=>{let o=Qd(n,t);if(!o)return!1;let r=Gi(o);if(!r){let i=o.blockRange(),l=i&&qn(i);return l==null?!1:(e&&e(n.tr.lift(i,l).scrollIntoView()),!0)}let s=r.nodeBefore;if(au(n,r,e,-1))return!0;if(o.parent.content.size==0&&(Qn(s,"end")||Y.isSelectable(s)))for(let i=o.depth;;i--){let l=Dr(n.doc,o.before(i),o.after(i),U.empty);if(l&&l.slice.size<l.to-l.from){if(e){let c=n.tr.step(l);c.setSelection(Qn(s,"end")?ee.findFrom(c.doc.resolve(c.mapping.map(r.pos,-1)),-1):Y.create(c.doc,r.pos-s.nodeSize)),e(c.scrollIntoView())}return!0}if(i==1||o.node(i-1).childCount>1)break}return s.isAtom&&r.depth==o.depth-1?(e&&e(n.tr.delete(r.pos-s.nodeSize,r.pos).scrollIntoView()),!0):!1},Ay=(n,e,t)=>{let o=Qd(n,t);if(!o)return!1;let r=Gi(o);return r?eu(n,r,e):!1},By=(n,e,t)=>{let o=nu(n,t);if(!o)return!1;let r=Yi(o);return r?eu(n,r,e):!1};function eu(n,e,t){let o=e.nodeBefore,r=o,s=e.pos-1;for(;!r.isTextblock;s--){if(r.type.spec.isolating)return!1;let u=r.lastChild;if(!u)return!1;r=u}let i=e.nodeAfter,l=i,c=e.pos+1;for(;!l.isTextblock;c++){if(l.type.spec.isolating)return!1;let u=l.firstChild;if(!u)return!1;l=u}let d=Dr(n.doc,s,c,U.empty);if(!d||d.from!=s||d instanceof Se&&d.slice.size>=c-s)return!1;if(t){let u=n.tr.step(d);u.setSelection(Q.create(u.doc,s)),t(u.scrollIntoView())}return!0}function Qn(n,e,t=!1){for(let o=n;o;o=e=="start"?o.firstChild:o.lastChild){if(o.isTextblock)return!0;if(t&&o.childCount!=1)return!1}return!1}const tu=(n,e,t)=>{let{$head:o,empty:r}=n.selection,s=o;if(!r)return!1;if(o.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):o.parentOffset>0)return!1;s=Gi(o)}let i=s&&s.nodeBefore;return!i||!Y.isSelectable(i)?!1:(e&&e(n.tr.setSelection(Y.create(n.doc,s.pos-i.nodeSize)).scrollIntoView()),!0)};function Gi(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function nu(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const ou=(n,e,t)=>{let o=nu(n,t);if(!o)return!1;let r=Yi(o);if(!r)return!1;let s=r.nodeAfter;if(au(n,r,e,1))return!0;if(o.parent.content.size==0&&(Qn(s,"start")||Y.isSelectable(s))){let i=Dr(n.doc,o.before(),o.after(),U.empty);if(i&&i.slice.size<i.to-i.from){if(e){let l=n.tr.step(i);l.setSelection(Qn(s,"start")?ee.findFrom(l.doc.resolve(l.mapping.map(r.pos)),1):Y.create(l.doc,l.mapping.map(r.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&r.depth==o.depth-1?(e&&e(n.tr.delete(r.pos,r.pos+s.nodeSize).scrollIntoView()),!0):!1},ru=(n,e,t)=>{let{$head:o,empty:r}=n.selection,s=o;if(!r)return!1;if(o.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):o.parentOffset<o.parent.content.size)return!1;s=Yi(o)}let i=s&&s.nodeAfter;return!i||!Y.isSelectable(i)?!1:(e&&e(n.tr.setSelection(Y.create(n.doc,s.pos)).scrollIntoView()),!0)};function Yi(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){let t=n.node(e);if(n.index(e)+1<t.childCount)return n.doc.resolve(n.after(e+1));if(t.type.spec.isolating)break}return null}const Iy=(n,e)=>{let t=n.selection,o=t instanceof Y,r;if(o){if(t.node.isTextblock||!En(n.doc,t.from))return!1;r=t.from}else if(r=_r(n.doc,t.from,-1),r==null)return!1;if(e){let s=n.tr.join(r);o&&s.setSelection(Y.create(s.doc,r-n.doc.resolve(r).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},Oy=(n,e)=>{let t=n.selection,o;if(t instanceof Y){if(t.node.isTextblock||!En(n.doc,t.to))return!1;o=t.to}else if(o=_r(n.doc,t.to,1),o==null)return!1;return e&&e(n.tr.join(o).scrollIntoView()),!0},_y=(n,e)=>{let{$from:t,$to:o}=n.selection,r=t.blockRange(o),s=r&&qn(r);return s==null?!1:(e&&e(n.tr.lift(r,s).scrollIntoView()),!0)},su=(n,e)=>{let{$head:t,$anchor:o}=n.selection;return!t.parent.type.spec.code||!t.sameParent(o)?!1:(e&&e(n.tr.insertText(`
|
|
6
|
+
`).scrollIntoView()),!0)};function Xi(n){for(let e=0;e<n.edgeCount;e++){let{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}const Dy=(n,e)=>{let{$head:t,$anchor:o}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(o))return!1;let r=t.node(-1),s=t.indexAfter(-1),i=Xi(r.contentMatchAt(s));if(!i||!r.canReplaceWith(s,s,i))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,i.createAndFill());c.setSelection(ee.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},iu=(n,e)=>{let t=n.selection,{$from:o,$to:r}=t;if(t instanceof qe||o.parent.inlineContent||r.parent.inlineContent)return!1;let s=Xi(r.parent.contentMatchAt(r.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let i=(!o.parentOffset&&r.index()<r.parent.childCount?o:r).pos,l=n.tr.insert(i,s.createAndFill());l.setSelection(Q.create(l.doc,i+1)),e(l.scrollIntoView())}return!0},lu=(n,e)=>{let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(It(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let o=t.blockRange(),r=o&&qn(o);return r==null?!1:(e&&e(n.tr.lift(o,r).scrollIntoView()),!0)};function Ry(n){return(e,t)=>{let{$from:o,$to:r}=e.selection;if(e.selection instanceof Y&&e.selection.node.isBlock)return!o.parentOffset||!It(e.doc,o.pos)?!1:(t&&t(e.tr.split(o.pos).scrollIntoView()),!0);if(!o.depth)return!1;let s=[],i,l,c=!1,d=!1;for(let p=o.depth;;p--)if(o.node(p).isBlock){c=o.end(p)==o.pos+(o.depth-p),d=o.start(p)==o.pos-(o.depth-p),l=Xi(o.node(p-1).contentMatchAt(o.indexAfter(p-1))),s.unshift(c&&l?{type:l}:null),i=p;break}else{if(p==1)return!1;s.unshift(null)}let u=e.tr;(e.selection instanceof Q||e.selection instanceof qe)&&u.deleteSelection();let f=u.mapping.map(o.pos),h=It(u.doc,f,s.length,s);if(h||(s[0]=l?{type:l}:null,h=It(u.doc,f,s.length,s)),!h)return!1;if(u.split(f,s.length,s),!c&&d&&o.node(i).type!=l){let p=u.mapping.map(o.before(i)),m=u.doc.resolve(p);l&&o.node(i-1).canReplaceWith(m.index(),m.index()+1,l)&&u.setNodeMarkup(u.mapping.map(o.before(i)),l)}return t&&t(u.scrollIntoView()),!0}}const Py=Ry(),Ly=(n,e)=>{let{$from:t,to:o}=n.selection,r,s=t.sharedDepth(o);return s==0?!1:(r=t.before(s),e&&e(n.tr.setSelection(Y.create(n.doc,r))),!0)};function Vy(n,e,t){let o=e.nodeBefore,r=e.nodeAfter,s=e.index();return!o||!r||!o.type.compatibleContent(r.type)?!1:!o.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-o.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(r.isTextblock||En(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function au(n,e,t,o){let r=e.nodeBefore,s=e.nodeAfter,i,l,c=r.type.spec.isolating||s.type.spec.isolating;if(!c&&Vy(n,e,t))return!0;let d=!c&&e.parent.canReplace(e.index(),e.index()+1);if(d&&(i=(l=r.contentMatchAt(r.childCount)).findWrapping(s.type))&&l.matchType(i[0]||s.type).validEnd){if(t){let p=e.pos+s.nodeSize,m=P.empty;for(let k=i.length-1;k>=0;k--)m=P.from(i[k].create(null,m));m=P.from(r.copy(m));let g=n.tr.step(new xe(e.pos-1,p,e.pos,p,new U(m,1,0),i.length,!0)),y=g.doc.resolve(p+2*i.length);y.nodeAfter&&y.nodeAfter.type==r.type&&En(g.doc,y.pos)&&g.join(y.pos),t(g.scrollIntoView())}return!0}let u=s.type.spec.isolating||o>0&&c?null:ee.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),h=f&&qn(f);if(h!=null&&h>=e.depth)return t&&t(n.tr.lift(f,h).scrollIntoView()),!0;if(d&&Qn(s,"start",!0)&&Qn(r,"end")){let p=r,m=[];for(;m.push(p),!p.isTextblock;)p=p.lastChild;let g=s,y=1;for(;!g.isTextblock;g=g.firstChild)y++;if(p.canReplace(p.childCount,p.childCount,g.content)){if(t){let k=P.empty;for(let b=m.length-1;b>=0;b--)k=P.from(m[b].copy(k));let x=n.tr.step(new xe(e.pos-m.length,e.pos+s.nodeSize,e.pos+y,e.pos+s.nodeSize-y,new U(k,m.length,0),0,!0));t(x.scrollIntoView())}return!0}}return!1}function cu(n){return function(e,t){let o=e.selection,r=n<0?o.$from:o.$to,s=r.depth;for(;r.node(s).isInline;){if(!s)return!1;s--}return r.node(s).isTextblock?(t&&t(e.tr.setSelection(Q.create(e.doc,n<0?r.start(s):r.end(s)))),!0):!1}}const $y=cu(-1),zy=cu(1);function Fy(n,e=null){return function(t,o){let{$from:r,$to:s}=t.selection,i=r.blockRange(s),l=i&&_d(i,n,e);return l?(o&&o(t.tr.wrap(i,l).scrollIntoView()),!0):!1}}function du(n,e=null){return function(t,o){let r=!1;for(let s=0;s<t.selection.ranges.length&&!r;s++){let{$from:{pos:i},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(i,l,(c,d)=>{if(r)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)r=!0;else{let u=t.doc.resolve(d),f=u.index();r=u.parent.canReplaceWith(f,f+1,n)}})}if(!r)return!1;if(o){let s=t.tr;for(let i=0;i<t.selection.ranges.length;i++){let{$from:{pos:l},$to:{pos:c}}=t.selection.ranges[i];s.setBlockType(l,c,n,e)}o(s.scrollIntoView())}return!0}}function Qi(...n){return function(e,t,o){for(let r=0;r<n.length;r++)if(n[r](e,t,o))return!0;return!1}}Qi(Ji,Zd,tu),Qi(Ji,ou,ru),Qi(su,iu,lu,Py),typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function Hy(n,e=null){return function(t,o){let{$from:r,$to:s}=t.selection,i=r.blockRange(s);if(!i)return!1;let l=o?t.tr:null;return jy(l,i,n,e)?(o&&o(l.scrollIntoView()),!0):!1}}function jy(n,e,t,o=null){let r=!1,s=e,i=e.$from.doc;if(e.depth>=2&&e.$from.node(e.depth-1).type.compatibleContent(t)&&e.startIndex==0){if(e.$from.index(e.depth-1)==0)return!1;let c=i.resolve(e.start-2);s=new Tr(c,c,e.depth),e.endIndex<e.parent.childCount&&(e=new Tr(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),r=!0}let l=_d(s,t,o,e);return l?(n&&Uy(n,e,l,r,t),!0):!1}function Uy(n,e,t,o,r){let s=P.empty;for(let u=t.length-1;u>=0;u--)s=P.from(t[u].type.create(t[u].attrs,s));n.step(new xe(e.start-(o?2:0),e.end,e.start,e.end,new U(s,0,0),t.length,!0));let i=0;for(let u=0;u<t.length;u++)t[u].type==r&&(i=u+1);let l=t.length-i,c=e.start+t.length-(o?2:0),d=e.parent;for(let u=e.startIndex,f=e.endIndex,h=!0;u<f;u++,h=!1)!h&&It(n.doc,c,l)&&(n.split(c,l),c+=2*l),c+=d.child(u).nodeSize;return n}function Wy(n){return function(e,t){let{$from:o,$to:r}=e.selection,s=o.blockRange(r,i=>i.childCount>0&&i.firstChild.type==n);return s?t?o.node(s.depth-1).type==n?Ky(e,t,n,s):qy(e,t,s):!0:!1}}function Ky(n,e,t,o){let r=n.tr,s=o.end,i=o.$to.end(o.depth);s<i&&(r.step(new xe(s-1,i,s,i,new U(P.from(t.create(null,o.parent.copy())),1,0),1,!0)),o=new Tr(r.doc.resolve(o.$from.pos),r.doc.resolve(i),o.depth));const l=qn(o);if(l==null)return!1;r.lift(o,l);let c=r.doc.resolve(r.mapping.map(s,-1)-1);return En(r.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&r.join(c.pos),e(r.scrollIntoView()),!0}function qy(n,e,t){let o=n.tr,r=t.parent;for(let p=t.end,m=t.endIndex-1,g=t.startIndex;m>g;m--)p-=r.child(m).nodeSize,o.delete(p-1,p+1);let s=o.doc.resolve(t.start),i=s.nodeAfter;if(o.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==r.childCount,d=s.node(-1),u=s.index(-1);if(!d.canReplace(u+(l?0:1),u+1,i.content.append(c?P.empty:P.from(r))))return!1;let f=s.pos,h=f+i.nodeSize;return o.step(new xe(f-(l?1:0),h+(c?1:0),f+1,h-1,new U((l?P.empty:P.from(r.copy(P.empty))).append(c?P.empty:P.from(r.copy(P.empty))),l?0:1,c?0:1),l?0:1)),e(o.scrollIntoView()),!0}function Jy(n){return function(e,t){let{$from:o,$to:r}=e.selection,s=o.blockRange(r,d=>d.childCount>0&&d.firstChild.type==n);if(!s)return!1;let i=s.startIndex;if(i==0)return!1;let l=s.parent,c=l.child(i-1);if(c.type!=n)return!1;if(t){let d=c.lastChild&&c.lastChild.type==l.type,u=P.from(d?n.create():null),f=new U(P.from(n.create(null,P.from(l.type.create(null,u)))),d?3:1,0),h=s.start,p=s.end;t(e.tr.step(new xe(h-(d?3:1),p,h,p,f,1,!0)).scrollIntoView())}return!0}}const Ae=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Zn=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Zi=null;const Ot=function(n,e,t){let o=Zi||(Zi=document.createRange());return o.setEnd(n,t??n.nodeValue.length),o.setStart(n,e||0),o},Gy=function(){Zi=null},vn=function(n,e,t,o){return t&&(uu(n,e,t,o,-1)||uu(n,e,t,o,1))},Yy=/^(img|br|input|textarea|hr)$/i;function uu(n,e,t,o,r){for(var s;;){if(n==t&&e==o)return!0;if(e==(r<0?0:Ye(n))){let i=n.parentNode;if(!i||i.nodeType!=1||_o(n)||Yy.test(n.nodeName)||n.contentEditable=="false")return!1;e=Ae(n)+(r<0?0:1),n=i}else if(n.nodeType==1){let i=n.childNodes[e+(r<0?-1:0)];if(i.nodeType==1&&i.contentEditable=="false")if(!((s=i.pmViewDesc)===null||s===void 0)&&s.ignoreForSelection)e+=r;else return!1;else n=i,e=r<0?Ye(n):0}else return!1}}function Ye(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Xy(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=Ye(n)}else if(n.parentNode&&!_o(n))e=Ae(n),n=n.parentNode;else return null}}function Qy(n,e){for(;;){if(n.nodeType==3&&e<n.nodeValue.length)return n;if(n.nodeType==1&&e<n.childNodes.length){if(n.contentEditable=="false")return null;n=n.childNodes[e],e=0}else if(n.parentNode&&!_o(n))e=Ae(n)+1,n=n.parentNode;else return null}}function Zy(n,e,t){for(let o=e==0,r=e==Ye(n);o||r;){if(n==t)return!0;let s=Ae(n);if(n=n.parentNode,!n)return!1;o=o&&s==0,r=r&&s==Ye(n)}}function _o(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}const Lr=function(n){return n.focusNode&&vn(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function Mn(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function e1(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function t1(n,e,t){if(n.caretPositionFromPoint)try{let o=n.caretPositionFromPoint(e,t);if(o)return{node:o.offsetNode,offset:Math.min(Ye(o.offsetNode),o.offset)}}catch{}if(n.caretRangeFromPoint){let o=n.caretRangeFromPoint(e,t);if(o)return{node:o.startContainer,offset:Math.min(Ye(o.startContainer),o.startOffset)}}}const pt=typeof navigator<"u"?navigator:null,fu=typeof document<"u"?document:null,qt=pt&&pt.userAgent||"",el=/Edge\/(\d+)/.exec(qt),hu=/MSIE \d/.exec(qt),tl=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(qt),He=!!(hu||tl||el),Jt=hu?document.documentMode:tl?+tl[1]:el?+el[1]:0,Xe=!He&&/gecko\/(\d+)/i.test(qt);Xe&&+(/Firefox\/(\d+)/.exec(qt)||[0,0])[1];const nl=!He&&/Chrome\/(\d+)/.exec(qt),Be=!!nl,pu=nl?+nl[1]:0,Pe=!He&&!!pt&&/Apple Computer/.test(pt.vendor),eo=Pe&&(/Mobile\/\w+/.test(qt)||!!pt&&pt.maxTouchPoints>2),Qe=eo||(pt?/Mac/.test(pt.platform):!1),mu=pt?/Win/.test(pt.platform):!1,_t=/Android \d/.test(qt),Do=!!fu&&"webkitFontSmoothing"in fu.documentElement.style,n1=Do?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function o1(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function Dt(n,e){return typeof n=="number"?n:n[e]}function r1(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,o=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*o}}function gu(n,e,t){let o=n.someProp("scrollThreshold")||0,r=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let i=t||n.dom;i;){if(i.nodeType!=1){i=Zn(i);continue}let l=i,c=l==s.body,d=c?o1(s):r1(l),u=0,f=0;if(e.top<d.top+Dt(o,"top")?f=-(d.top-e.top+Dt(r,"top")):e.bottom>d.bottom-Dt(o,"bottom")&&(f=e.bottom-e.top>d.bottom-d.top?e.top+Dt(r,"top")-d.top:e.bottom-d.bottom+Dt(r,"bottom")),e.left<d.left+Dt(o,"left")?u=-(d.left-e.left+Dt(r,"left")):e.right>d.right-Dt(o,"right")&&(u=e.right-d.right+Dt(r,"right")),u||f)if(c)s.defaultView.scrollBy(u,f);else{let p=l.scrollLeft,m=l.scrollTop;f&&(l.scrollTop+=f),u&&(l.scrollLeft+=u);let g=l.scrollLeft-p,y=l.scrollTop-m;e={left:e.left-g,top:e.top-y,right:e.right-g,bottom:e.bottom-y}}let h=c?"fixed":getComputedStyle(i).position;if(/^(fixed|sticky)$/.test(h))break;i=h=="absolute"?i.offsetParent:Zn(i)}}function s1(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),o,r;for(let s=(e.left+e.right)/2,i=t+1;i<Math.min(innerHeight,e.bottom);i+=5){let l=n.root.elementFromPoint(s,i);if(!l||l==n.dom||!n.dom.contains(l))continue;let c=l.getBoundingClientRect();if(c.top>=t-20){o=l,r=c.top;break}}return{refDOM:o,refTop:r,stack:yu(n.dom)}}function yu(n){let e=[],t=n.ownerDocument;for(let o=n;o&&(e.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),n!=t);o=Zn(o));return e}function i1({refDOM:n,refTop:e,stack:t}){let o=n?n.getBoundingClientRect().top:0;ku(t,o==0?0:o-e)}function ku(n,e){for(let t=0;t<n.length;t++){let{dom:o,top:r,left:s}=n[t];o.scrollTop!=r+e&&(o.scrollTop=r+e),o.scrollLeft!=s&&(o.scrollLeft=s)}}let to=null;function l1(n){if(n.setActive)return n.setActive();if(to)return n.focus(to);let e=yu(n);n.focus(to==null?{get preventScroll(){return to={preventScroll:!0},!0}}:void 0),to||(to=!1,ku(e,0))}function wu(n,e){let t,o=2e8,r,s=0,i=e.top,l=e.top,c,d;for(let u=n.firstChild,f=0;u;u=u.nextSibling,f++){let h;if(u.nodeType==1)h=u.getClientRects();else if(u.nodeType==3)h=Ot(u).getClientRects();else continue;for(let p=0;p<h.length;p++){let m=h[p];if(m.top<=i&&m.bottom>=l){i=Math.max(m.bottom,i),l=Math.min(m.top,l);let g=m.left>e.left?m.left-e.left:m.right<e.left?e.left-m.right:0;if(g<o){t=u,o=g,r=g&&t.nodeType==3?{left:m.right<e.left?m.right:m.left,top:e.top}:e,u.nodeType==1&&g&&(s=f+(e.left>=(m.left+m.right)/2?1:0));continue}}else m.top>e.top&&!c&&m.left<=e.left&&m.right>=e.left&&(c=u,d={left:Math.max(m.left,Math.min(m.right,e.left)),top:m.top});!t&&(e.left>=m.right&&e.top>=m.top||e.left>=m.left&&e.top>=m.bottom)&&(s=f+1)}}return!t&&c&&(t=c,r=d,o=0),t&&t.nodeType==3?a1(t,r):!t||o&&t.nodeType==1?{node:n,offset:s}:wu(t,r)}function a1(n,e){let t=n.nodeValue.length,o=document.createRange(),r;for(let s=0;s<t;s++){o.setEnd(n,s+1),o.setStart(n,s);let i=Gt(o,1);if(i.top!=i.bottom&&ol(e,i)){r={node:n,offset:s+(e.left>=(i.left+i.right)/2?1:0)};break}}return o.detach(),r||{node:n,offset:0}}function ol(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function c1(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function d1(n,e,t){let{node:o,offset:r}=wu(e,t),s=-1;if(o.nodeType==1&&!o.firstChild){let i=o.getBoundingClientRect();s=i.left!=i.right&&t.left>(i.left+i.right)/2?1:-1}return n.docView.posFromDOM(o,r,s)}function u1(n,e,t,o){let r=-1;for(let s=e,i=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0),c;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((c=l.dom.getBoundingClientRect()).width||c.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!i&&c.left>o.left||c.top>o.top?r=l.posBefore:(!i&&c.right<o.left||c.bottom<o.top)&&(r=l.posAfter),i=!0),!l.contentDOM&&r<0&&!l.node.isText))return(l.node.isBlock?o.top<(c.top+c.bottom)/2:o.left<(c.left+c.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return r>-1?r:n.docView.posFromDOM(e,t,-1)}function bu(n,e,t){let o=n.childNodes.length;if(o&&t.top<t.bottom)for(let r=Math.max(0,Math.min(o-1,Math.floor(o*(e.top-t.top)/(t.bottom-t.top))-2)),s=r;;){let i=n.childNodes[s];if(i.nodeType==1){let l=i.getClientRects();for(let c=0;c<l.length;c++){let d=l[c];if(ol(e,d))return bu(i,e,d)}}if((s=(s+1)%o)==r)break}return n}function f1(n,e){let t=n.dom.ownerDocument,o,r=0,s=t1(t,e.left,e.top);s&&({node:o,offset:r}=s);let i=(n.root.elementFromPoint?n.root:t).elementFromPoint(e.left,e.top),l;if(!i||!n.dom.contains(i.nodeType!=1?i.parentNode:i)){let d=n.dom.getBoundingClientRect();if(!ol(e,d)||(i=bu(n.dom,e,d),!i))return null}if(Pe)for(let d=i;o&&d;d=Zn(d))d.draggable&&(o=void 0);if(i=c1(i,e),o){if(Xe&&o.nodeType==1&&(r=Math.min(r,o.childNodes.length),r<o.childNodes.length)){let u=o.childNodes[r],f;u.nodeName=="IMG"&&(f=u.getBoundingClientRect()).right<=e.left&&f.bottom>e.top&&r++}let d;Do&&r&&o.nodeType==1&&(d=o.childNodes[r-1]).nodeType==1&&d.contentEditable=="false"&&d.getBoundingClientRect().top>=e.top&&r--,o==n.dom&&r==o.childNodes.length-1&&o.lastChild.nodeType==1&&e.top>o.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(r==0||o.nodeType!=1||o.childNodes[r-1].nodeName!="BR")&&(l=u1(n,o,r,e))}l==null&&(l=d1(n,i,e));let c=n.docView.nearestDesc(i,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Su(n){return n.top<n.bottom||n.left<n.right}function Gt(n,e){let t=n.getClientRects();if(t.length){let o=t[e<0?0:t.length-1];if(Su(o))return o}return Array.prototype.find.call(t,Su)||n.getBoundingClientRect()}const h1=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function xu(n,e,t){let{node:o,offset:r,atom:s}=n.docView.domFromPos(e,t<0?-1:1),i=Do||Xe;if(o.nodeType==3)if(i&&(h1.test(o.nodeValue)||(t<0?!r:r==o.nodeValue.length))){let c=Gt(Ot(o,r,r),t);if(Xe&&r&&/\s/.test(o.nodeValue[r-1])&&r<o.nodeValue.length){let d=Gt(Ot(o,r-1,r-1),-1);if(d.top==c.top){let u=Gt(Ot(o,r,r+1),-1);if(u.top!=c.top)return Ro(u,u.left<d.left)}}return c}else{let c=r,d=r,u=t<0?1:-1;return t<0&&!r?(d++,u=-1):t>=0&&r==o.nodeValue.length?(c--,u=1):t<0?c--:d++,Ro(Gt(Ot(o,c,d),u),u<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&r&&(t<0||r==Ye(o))){let c=o.childNodes[r-1];if(c.nodeType==1)return rl(c.getBoundingClientRect(),!1)}if(s==null&&r<Ye(o)){let c=o.childNodes[r];if(c.nodeType==1)return rl(c.getBoundingClientRect(),!0)}return rl(o.getBoundingClientRect(),t>=0)}if(s==null&&r&&(t<0||r==Ye(o))){let c=o.childNodes[r-1],d=c.nodeType==3?Ot(c,Ye(c)-(i?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(d)return Ro(Gt(d,1),!1)}if(s==null&&r<Ye(o)){let c=o.childNodes[r];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let d=c?c.nodeType==3?Ot(c,0,i?0:1):c.nodeType==1?c:null:null;if(d)return Ro(Gt(d,-1),!0)}return Ro(Gt(o.nodeType==3?Ot(o):o,-t),t>=0)}function Ro(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function rl(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function Cu(n,e,t){let o=n.state,r=n.root.activeElement;o!=e&&n.updateState(e),r!=n.dom&&n.focus();try{return t()}finally{o!=e&&n.updateState(o),r!=n.dom&&r&&r.focus()}}function p1(n,e,t){let o=e.selection,r=t=="up"?o.$from:o.$to;return Cu(n,e,()=>{let{node:s}=n.docView.domFromPos(r.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let i=xu(n,r.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=Ot(l,0,l.nodeValue.length).getClientRects();else continue;for(let d=0;d<c.length;d++){let u=c[d];if(u.bottom>u.top+1&&(t=="up"?i.top-u.top>(u.bottom-i.top)*2:u.bottom-i.bottom>(i.bottom-u.top)*2))return!1}}return!0})}const m1=/[\u0590-\u08ac]/;function g1(n,e,t){let{$head:o}=e.selection;if(!o.parent.isTextblock)return!1;let r=o.parentOffset,s=!r,i=r==o.parent.content.size,l=n.domSelection();return l?!m1.test(o.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:i:Cu(n,e,()=>{let{focusNode:c,focusOffset:d,anchorNode:u,anchorOffset:f}=n.domSelectionRange(),h=l.caretBidiLevel;l.modify("move",t,"character");let p=o.depth?n.docView.domAfterPos(o.before()):n.dom,{focusNode:m,focusOffset:g}=n.domSelectionRange(),y=m&&!p.contains(m.nodeType==1?m:m.parentNode)||c==m&&d==g;try{l.collapse(u,f),c&&(c!=u||d!=f)&&l.extend&&l.extend(c,d)}catch{}return h!=null&&(l.caretBidiLevel=h),y}):o.pos==o.start()||o.pos==o.end()}let Eu=null,vu=null,Mu=!1;function y1(n,e,t){return Eu==e&&vu==t?Mu:(Eu=e,vu=t,Mu=t=="up"||t=="down"?p1(n,e,t):g1(n,e,t))}const Ze=0,Tu=1,Tn=2,mt=3;class Po{constructor(e,t,o,r){this.parent=e,this.children=t,this.dom=o,this.contentDOM=r,this.dirty=Ze,o.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,o){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,o=this.posAtStart;;t++){let r=this.children[t];if(r==e)return o;o+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,o){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(o<0){let s,i;if(e==this.contentDOM)s=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.previousSibling}for(;s&&!((i=s.pmViewDesc)&&i.parent==this);)s=s.previousSibling;return s?this.posBeforeChild(i)+i.size:this.posAtStart}else{let s,i;if(e==this.contentDOM)s=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;s=e.nextSibling}for(;s&&!((i=s.pmViewDesc)&&i.parent==this);)s=s.nextSibling;return s?this.posBeforeChild(i):this.posAtEnd}let r;if(e==this.dom&&this.contentDOM)r=t>Ae(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!1;break}if(s.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){r=!0;break}if(s.nextSibling)break}}return r??o>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let o=!0,r=e;r;r=r.parentNode){let s=this.getDesc(r),i;if(s&&(!t||s.node))if(o&&(i=s.nodeDOM)&&!(i.nodeType==1?i.contains(e.nodeType==1?e:e.parentNode):i==e))o=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let o=t;o;o=o.parent)if(o==this)return t}posFromDOM(e,t,o){for(let r=e;r;r=r.parentNode){let s=this.getDesc(r);if(s)return s.localPosFromDOM(e,t,o)}return-1}descAt(e){for(let t=0,o=0;t<this.children.length;t++){let r=this.children[t],s=o+r.size;if(o==e&&s!=o){for(;!r.border&&r.children.length;)for(let i=0;i<r.children.length;i++){let l=r.children[i];if(l.size){r=l;break}}return r}if(e<s)return r.descAt(e-o-r.border);o=s}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let o=0,r=0;for(let s=0;o<this.children.length;o++){let i=this.children[o],l=s+i.size;if(l>e||i instanceof Bu){r=e-s;break}s=l}if(r)return this.children[o].domFromPos(r-this.children[o].border,t);for(let s;o&&!(s=this.children[o-1]).size&&s instanceof Nu&&s.side>=0;o--);if(t<=0){let s,i=!0;for(;s=o?this.children[o-1]:null,!(!s||s.dom.parentNode==this.contentDOM);o--,i=!1);return s&&t&&i&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?Ae(s.dom)+1:0}}else{let s,i=!0;for(;s=o<this.children.length?this.children[o]:null,!(!s||s.dom.parentNode==this.contentDOM);o++,i=!1);return s&&i&&!s.border&&!s.domAtom?s.domFromPos(0,t):{node:this.contentDOM,offset:s?Ae(s.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,o=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,s=-1;for(let i=o,l=0;;l++){let c=this.children[l],d=i+c.size;if(r==-1&&e<=d){let u=i+c.border;if(e>=u&&t<=d-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,u);e=i;for(let f=l;f>0;f--){let h=this.children[f-1];if(h.size&&h.dom.parentNode==this.contentDOM&&!h.emptyChildAt(1)){r=Ae(h.dom)+1;break}e-=h.size}r==-1&&(r=0)}if(r>-1&&(d>t||l==this.children.length-1)){t=d;for(let u=l+1;u<this.children.length;u++){let f=this.children[u];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(-1)){s=Ae(f.dom);break}t+=f.size}s==-1&&(s=this.contentDOM.childNodes.length);break}i=d}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:s}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:o}=this.domFromPos(e,0);if(t.nodeType!=1||o==t.childNodes.length)throw new RangeError("No node after pos "+e);return t.childNodes[o]}setSelection(e,t,o,r=!1){let s=Math.min(e,t),i=Math.max(e,t);for(let p=0,m=0;p<this.children.length;p++){let g=this.children[p],y=m+g.size;if(s>m&&i<y)return g.setSelection(e-m-g.border,t-m-g.border,o,r);m=y}let l=this.domFromPos(e,e?-1:1),c=t==e?l:this.domFromPos(t,t?-1:1),d=o.root.getSelection(),u=o.domSelectionRange(),f=!1;if((Xe||Pe)&&e==t){let{node:p,offset:m}=l;if(p.nodeType==3){if(f=!!(m&&p.nodeValue[m-1]==`
|
|
7
|
+
`),f&&m==p.nodeValue.length)for(let g=p,y;g;g=g.parentNode){if(y=g.nextSibling){y.nodeName=="BR"&&(l=c={node:y.parentNode,offset:Ae(y)+1});break}let k=g.pmViewDesc;if(k&&k.node&&k.node.isBlock)break}}else{let g=p.childNodes[m-1];f=g&&(g.nodeName=="BR"||g.contentEditable=="false")}}if(Xe&&u.focusNode&&u.focusNode!=c.node&&u.focusNode.nodeType==1){let p=u.focusNode.childNodes[u.focusOffset];p&&p.contentEditable=="false"&&(r=!0)}if(!(r||f&&Pe)&&vn(l.node,l.offset,u.anchorNode,u.anchorOffset)&&vn(c.node,c.offset,u.focusNode,u.focusOffset))return;let h=!1;if((d.extend||e==t)&&!(f&&Xe)){d.collapse(l.node,l.offset);try{e!=t&&d.extend(c.node,c.offset),h=!0}catch{}}if(!h){if(e>t){let m=l;l=c,c=m}let p=document.createRange();p.setEnd(c.node,c.offset),p.setStart(l.node,l.offset),d.removeAllRanges(),d.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let o=0,r=0;r<this.children.length;r++){let s=this.children[r],i=o+s.size;if(o==i?e<=i&&t>=o:e<i&&t>o){let l=o+s.border,c=i-s.border;if(e>=l&&t<=c){this.dirty=e==o||t==i?Tn:Tu,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=mt:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Tn:mt}o=i}this.dirty=Tn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let o=e==1?Tn:Tu;t.dirty<o&&(t.dirty=o)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class Nu extends Po{constructor(e,t,o,r){let s,i=t.type.toDOM;if(typeof i=="function"&&(i=i(o,()=>{if(!s)return r;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(i.nodeType!=1){let l=document.createElement("span");l.appendChild(i),i=l}i.contentEditable="false",i.classList.add("ProseMirror-widget")}super(e,[],i,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==Ze&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}}class k1 extends Po{constructor(e,t,o,r){super(e,[],t,null),this.textDOM=o,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}}class Nn extends Po{constructor(e,t,o,r,s){super(e,[],o,r),this.mark=t,this.spec=s}static create(e,t,o,r){let s=r.nodeViews[t.type.name],i=s&&s(t,r,o);return(!i||!i.dom)&&(i=xn.renderSpec(document,t.type.spec.toDOM(t,o),null,t.attrs)),new Nn(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return this.dirty&mt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=mt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Ze){let o=this.parent;for(;!o.node;)o=o.parent;o.dirty<this.dirty&&(o.dirty=this.dirty),this.dirty=Ze}}slice(e,t,o){let r=Nn.create(this.parent,this.mark,!0,o),s=this.children,i=this.size;t<i&&(s=il(s,t,i,o)),e>0&&(s=il(s,0,e,o));for(let l=0;l<s.length;l++)s[l].parent=r;return r.children=s,r}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}}class Yt extends Po{constructor(e,t,o,r,s,i,l,c,d){super(e,[],s,i),this.node=t,this.outerDeco=o,this.innerDeco=r,this.nodeDOM=l}static create(e,t,o,r,s,i){let l=s.nodeViews[t.type.name],c,d=l&&l(t,s,()=>{if(!c)return i;if(c.parent)return c.parent.posBeforeChild(c)},o,r),u=d&&d.dom,f=d&&d.contentDOM;if(t.isText){if(!u)u=document.createTextNode(t.text);else if(u.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else u||({dom:u,contentDOM:f}=xn.renderSpec(document,t.type.spec.toDOM(t),null,t.attrs));!f&&!t.isText&&u.nodeName!="BR"&&(u.hasAttribute("contenteditable")||(u.contentEditable="false"),t.type.spec.draggable&&(u.draggable=!0));let h=u;return u=_u(u,o,t),d?c=new w1(e,t,o,r,u,f||null,h,d,s,i+1):t.isText?new Vr(e,t,o,r,u,h,s):new Yt(e,t,o,r,u,f||null,h,s,i+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let o=this.children[t];if(this.dom.contains(o.dom.parentNode)){e.contentElement=o.dom.parentNode;break}}e.contentElement||(e.getContent=()=>P.empty)}return e}matchesNode(e,t,o){return this.dirty==Ze&&e.eq(this.node)&&$r(t,this.outerDeco)&&o.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let o=this.node.inlineContent,r=t,s=e.composing?this.localCompositionInfo(e,t):null,i=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new S1(this,i&&i.node,e);E1(this.node,this.innerDeco,(d,u,f)=>{d.spec.marks?c.syncToMarks(d.spec.marks,o,e,u):d.type.side>=0&&!f&&c.syncToMarks(u==this.node.childCount?se.none:this.node.child(u).marks,o,e,u),c.placeWidget(d,e,r)},(d,u,f,h)=>{c.syncToMarks(d.marks,o,e,h);let p;c.findNodeMatch(d,u,f,h)||l&&e.state.selection.from>r&&e.state.selection.to<r+d.nodeSize&&(p=c.findIndexWithChild(s.node))>-1&&c.updateNodeAt(d,u,f,p,e)||c.updateNextNode(d,u,f,e,h,r)||c.addNode(d,u,f,e,r),r+=d.nodeSize}),c.syncToMarks([],o,e,0),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==Tn)&&(i&&this.protectLocalComposition(e,i),Iu(this.contentDOM,this.children,e),eo&&v1(this.dom))}localCompositionInfo(e,t){let{from:o,to:r}=e.state.selection;if(!(e.state.selection instanceof Q)||o<t||r>t+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let i=s.nodeValue,l=M1(this.node.content,i,o-t,r-t);return l<0?null:{node:s,pos:l,text:i}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:o,text:r}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let i=new k1(this,s,t,r);e.input.compositionNodes.push(i),this.children=il(this.children,o,o+r.length,e,i)}update(e,t,o,r){return this.dirty==mt||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,o,r),!0)}updateInner(e,t,o,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=o,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=Ze}updateOuterDeco(e){if($r(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,o=this.dom;this.dom=Ou(this.dom,this.nodeDOM,sl(this.outerDeco,this.node,t),sl(e,this.node,t)),this.dom!=o&&(o.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.nodeDOM.draggable=!0))}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.nodeDOM.removeAttribute("draggable"))}get domAtom(){return this.node.isAtom}}function Au(n,e,t,o,r){_u(o,e,n);let s=new Yt(void 0,n,e,t,o,o,o,r,0);return s.contentDOM&&s.updateChildren(r,0),s}class Vr extends Yt{constructor(e,t,o,r,s,i,l){super(e,t,o,r,s,null,i,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,o,r){return this.dirty==mt||this.dirty!=Ze&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Ze||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=Ze,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,o){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,o)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,o){let r=this.node.cut(e,t),s=document.createTextNode(r.text);return new Vr(this.parent,r,this.outerDeco,this.innerDeco,s,s,o)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=mt)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Bu extends Po{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Ze&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class w1 extends Yt{constructor(e,t,o,r,s,i,l,c,d,u){super(e,t,o,r,s,i,l,d,u),this.spec=c}update(e,t,o,r){if(this.dirty==mt)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let s=this.spec.update(e,t,o);return s&&this.updateInner(e,t,o,r),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,o,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,o,r){this.spec.setSelection?this.spec.setSelection(e,t,o.root):super.setSelection(e,t,o,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}}function Iu(n,e,t){let o=n.firstChild,r=!1;for(let s=0;s<e.length;s++){let i=e[s],l=i.dom;if(l.parentNode==n){for(;l!=o;)o=Du(o),r=!0;o=o.nextSibling}else r=!0,n.insertBefore(l,o);if(i instanceof Nn){let c=o?o.previousSibling:n.lastChild;Iu(i.contentDOM,i.children,t),o=c?c.nextSibling:n.firstChild}}for(;o;)o=Du(o),r=!0;r&&t.trackWrites==n&&(t.trackWrites=null)}const Lo=function(n){n&&(this.nodeName=n)};Lo.prototype=Object.create(null);const An=[new Lo];function sl(n,e,t){if(n.length==0)return An;let o=t?An[0]:new Lo,r=[o];for(let s=0;s<n.length;s++){let i=n[s].type.attrs;if(i){i.nodeName&&r.push(o=new Lo(i.nodeName));for(let l in i){let c=i[l];c!=null&&(t&&r.length==1&&r.push(o=new Lo(e.isInline?"span":"div")),l=="class"?o.class=(o.class?o.class+" ":"")+c:l=="style"?o.style=(o.style?o.style+";":"")+c:l!="nodeName"&&(o[l]=c))}}}return r}function Ou(n,e,t,o){if(t==An&&o==An)return e;let r=e;for(let s=0;s<o.length;s++){let i=o[s],l=t[s];if(s){let c;l&&l.nodeName==i.nodeName&&r!=n&&(c=r.parentNode)&&c.nodeName.toLowerCase()==i.nodeName||(c=document.createElement(i.nodeName),c.pmIsDeco=!0,c.appendChild(r),l=An[0]),r=c}b1(r,l||An[0],i)}return r}function b1(n,e,t){for(let o in e)o!="class"&&o!="style"&&o!="nodeName"&&!(o in t)&&n.removeAttribute(o);for(let o in t)o!="class"&&o!="style"&&o!="nodeName"&&t[o]!=e[o]&&n.setAttribute(o,t[o]);if(e.class!=t.class){let o=e.class?e.class.split(" ").filter(Boolean):[],r=t.class?t.class.split(" ").filter(Boolean):[];for(let s=0;s<o.length;s++)r.indexOf(o[s])==-1&&n.classList.remove(o[s]);for(let s=0;s<r.length;s++)o.indexOf(r[s])==-1&&n.classList.add(r[s]);n.classList.length==0&&n.removeAttribute("class")}if(e.style!=t.style){if(e.style){let o=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=o.exec(e.style);)n.style.removeProperty(r[1])}t.style&&(n.style.cssText+=t.style)}}function _u(n,e,t){return Ou(n,n,An,sl(e,t,n.nodeType!=1))}function $r(n,e){if(n.length!=e.length)return!1;for(let t=0;t<n.length;t++)if(!n[t].type.eq(e[t].type))return!1;return!0}function Du(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class S1{constructor(e,t,o){this.lock=t,this.view=o,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=x1(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let o=e;o<t;o++)this.top.children[o].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,o,r){let s=0,i=this.stack.length>>1,l=Math.min(i,e.length);for(;s<l&&(s==i-1?this.top:this.stack[s+1<<1]).matchesMark(e[s])&&e[s].type.spec.spanning!==!1;)s++;for(;s<i;)this.destroyRest(),this.top.dirty=Ze,this.index=this.stack.pop(),this.top=this.stack.pop(),i--;for(;i<e.length;){this.stack.push(this.top,this.index+1);let c=-1,d=this.top.children.length;r<this.preMatch.index&&(d=Math.min(this.index+3,d));for(let u=this.index;u<d;u++){let f=this.top.children[u];if(f.matchesMark(e[i])&&!this.isLocked(f.dom)){c=u;break}}if(c>-1)c>this.index&&(this.changed=!0,this.destroyBetween(this.index,c)),this.top=this.top.children[this.index];else{let u=Nn.create(this.top,e[i],t,o);this.top.children.splice(this.index,0,u),this.top=u,this.changed=!0}this.index=0,i++}}findNodeMatch(e,t,o,r){let s=-1,i;if(r>=this.preMatch.index&&(i=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&i.matchesNode(e,t,o))s=this.top.children.indexOf(i,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l<c;l++){let d=this.top.children[l];if(d.matchesNode(e,t,o)&&!this.preMatch.matched.has(d)){s=l;break}}return s<0?!1:(this.destroyBetween(this.index,s),this.index++,!0)}updateNodeAt(e,t,o,r,s){let i=this.top.children[r];return i.dirty==mt&&i.dom==i.contentDOM&&(i.dirty=Tn),i.update(e,t,o,s)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let o=e.pmViewDesc;if(o){for(let r=this.index;r<this.top.children.length;r++)if(this.top.children[r]==o)return r}return-1}e=t}}updateNextNode(e,t,o,r,s,i){for(let l=this.index;l<this.top.children.length;l++){let c=this.top.children[l];if(c instanceof Yt){let d=this.preMatch.matched.get(c);if(d!=null&&d!=s)return!1;let u=c.dom,f,h=this.isLocked(u)&&!(e.isText&&c.node&&c.node.isText&&c.nodeDOM.nodeValue==e.text&&c.dirty!=mt&&$r(t,c.outerDeco));if(!h&&c.update(e,t,o,r))return this.destroyBetween(this.index,l),c.dom!=u&&(this.changed=!0),this.index++,!0;if(!h&&(f=this.recreateWrapper(c,e,t,o,r,i)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Tn,f.updateChildren(r,i+1),f.dirty=Ze),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,o,r,s,i){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!$r(o,e.outerDeco)||!r.eq(e.innerDeco))return null;let l=Yt.create(this.top,t,o,r,s,i);if(l.contentDOM){l.children=e.children,e.children=[];for(let c of l.children)c.parent=l}return e.destroy(),l}addNode(e,t,o,r,s){let i=Yt.create(this.top,e,t,o,r,s);i.contentDOM&&i.updateChildren(r,s+1),this.top.children.splice(this.index++,0,i),this.changed=!0}placeWidget(e,t,o){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let s=new Nu(this.top,e,t,o);this.top.children.splice(this.index++,0,s),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof Nn;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Vr)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((Pe||Be)&&e&&e.dom.contentEditable=="false"&&this.addHackNode("IMG",t),this.addHackNode("BR",this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let o=document.createElement(e);e=="IMG"&&(o.className="ProseMirror-separator",o.alt=""),e=="BR"&&(o.className="ProseMirror-trailingBreak");let r=new Bu(this.top,[],o,null);t!=this.top?t.children.push(r):t.children.splice(this.index++,0,r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}}function x1(n,e){let t=e,o=t.children.length,r=n.childCount,s=new Map,i=[];e:for(;r>0;){let l;for(;;)if(o){let d=t.children[o-1];if(d instanceof Nn)t=d,o=d.children.length;else{l=d,o--;break}}else{if(t==e)break e;o=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(r-1))break;--r,s.set(l,r),i.push(l)}}return{index:r,matched:s,matches:i.reverse()}}function C1(n,e){return n.type.side-e.type.side}function E1(n,e,t,o){let r=e.locals(n),s=0;if(r.length==0){for(let d=0;d<n.childCount;d++){let u=n.child(d);o(u,r,e.forChild(s,u),d),s+=u.nodeSize}return}let i=0,l=[],c=null;for(let d=0;;){let u,f;for(;i<r.length&&r[i].to==s;){let y=r[i++];y.widget&&(u?(f||(f=[u])).push(y):u=y)}if(u)if(f){f.sort(C1);for(let y=0;y<f.length;y++)t(f[y],d,!!c)}else t(u,d,!!c);let h,p;if(c)p=-1,h=c,c=null;else if(d<n.childCount)p=d,h=n.child(d++);else break;for(let y=0;y<l.length;y++)l[y].to<=s&&l.splice(y--,1);for(;i<r.length&&r[i].from<=s&&r[i].to>s;)l.push(r[i++]);let m=s+h.nodeSize;if(h.isText){let y=m;i<r.length&&r[i].from<y&&(y=r[i].from);for(let k=0;k<l.length;k++)l[k].to<y&&(y=l[k].to);y<m&&(c=h.cut(y-s),h=h.cut(0,y-s),m=y,p=-1)}else for(;i<r.length&&r[i].to<m;)i++;let g=h.isInline&&!h.isLeaf?l.filter(y=>!y.inline):l.slice();o(h,g,e.forChild(s,h),p),s=m}}function v1(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function M1(n,e,t,o){for(let r=0,s=0;r<n.childCount&&s<=o;){let i=n.child(r++),l=s;if(s+=i.nodeSize,!i.isText)continue;let c=i.text;for(;r<n.childCount;){let d=n.child(r++);if(s+=d.nodeSize,!d.isText)break;c+=d.text}if(s>=t){if(s>=o&&c.slice(o-e.length-l,o-l)==e)return o-e.length;let d=l<o?c.lastIndexOf(e,o-l-1):-1;if(d>=0&&d+e.length+l>=t)return l+d;if(t==o&&c.length>=o+e.length-l&&c.slice(o-l,o-l+e.length)==e)return o}}return-1}function il(n,e,t,o,r){let s=[];for(let i=0,l=0;i<n.length;i++){let c=n[i],d=l,u=l+=c.size;d>=t||u<=e?s.push(c):(d<e&&s.push(c.slice(0,e-d,o)),r&&(s.push(r),r=void 0),u>t&&s.push(c.slice(t-d,c.size,o)))}return s}function ll(n,e=null){let t=n.domSelectionRange(),o=n.state.doc;if(!t.focusNode)return null;let r=n.docView.nearestDesc(t.focusNode),s=r&&r.size==0,i=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(i<0)return null;let l=o.resolve(i),c,d;if(Lr(t)){for(c=i;r&&!r.node;)r=r.parent;let f=r.node;if(r&&f.isAtom&&Y.isSelectable(f)&&r.parent&&!(f.isInline&&Zy(t.focusNode,t.focusOffset,r.dom))){let h=r.posBefore;d=new Y(i==h?l:o.resolve(h))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=i,h=i;for(let p=0;p<t.rangeCount;p++){let m=t.getRangeAt(p);f=Math.min(f,n.docView.posFromDOM(m.startContainer,m.startOffset,1)),h=Math.max(h,n.docView.posFromDOM(m.endContainer,m.endOffset,-1))}if(f<0)return null;[c,i]=h==n.state.selection.anchor?[h,f]:[f,h],l=o.resolve(i)}else c=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(c<0)return null}let u=o.resolve(c);if(!d){let f=e=="pointer"||n.state.selection.head<l.pos&&!s?1:-1;d=cl(n,u,l,f)}return d}function Ru(n){return n.editable?n.hasFocus():Hu(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function Rt(n,e=!1){let t=n.state.selection;if($u(n,t),!!Ru(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&Be){let o=n.domSelectionRange(),r=n.domObserver.currentSelection;if(o.anchorNode&&r.anchorNode&&vn(o.anchorNode,o.anchorOffset,r.anchorNode,r.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)N1(n);else{let{anchor:o,head:r}=t,s,i;Pu&&!(t instanceof Q)&&(t.$from.parent.inlineContent||(s=Lu(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(i=Lu(n,t.to))),n.docView.setSelection(o,r,n,e),Pu&&(s&&Vu(s),i&&Vu(i)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&T1(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const Pu=Pe||Be&&pu<63;function Lu(n,e){let{node:t,offset:o}=n.docView.domFromPos(e,0),r=o<t.childNodes.length?t.childNodes[o]:null,s=o?t.childNodes[o-1]:null;if(Pe&&r&&r.contentEditable=="false")return al(r);if((!r||r.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(r)return al(r);if(s)return al(s)}}function al(n){return n.contentEditable="true",Pe&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function Vu(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function T1(n){let e=n.dom.ownerDocument;e.removeEventListener("selectionchange",n.input.hideSelectionGuard);let t=n.domSelectionRange(),o=t.anchorNode,r=t.anchorOffset;e.addEventListener("selectionchange",n.input.hideSelectionGuard=()=>{(t.anchorNode!=o||t.anchorOffset!=r)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Ru(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function N1(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,o=t.nodeName=="IMG";o?e.collapse(t.parentNode,Ae(t)+1):e.collapse(t,0),!o&&!n.state.selection.visible&&He&&Jt<=11&&(t.disabled=!0,t.disabled=!1)}function $u(n,e){if(e instanceof Y){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(zu(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else zu(n)}function zu(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function cl(n,e,t,o){return n.someProp("createSelectionBetween",r=>r(n,e,t))||Q.between(e,t,o)}function Fu(n){return n.editable&&!n.hasFocus()?!1:Hu(n)}function Hu(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function A1(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return vn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function dl(n,e){let{$anchor:t,$head:o}=n.selection,r=e>0?t.max(o):t.min(o),s=r.parent.inlineContent?r.depth?n.doc.resolve(e>0?r.after():r.before()):null:r;return s&&ee.findFrom(s,e)}function Xt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function ju(n,e,t){let o=n.state.selection;if(o instanceof Q)if(t.indexOf("s")>-1){let{$head:r}=o,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let i=n.state.doc.resolve(r.pos+s.nodeSize*(e<0?-1:1));return Xt(n,new Q(o.$anchor,i))}else if(o.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let r=dl(n.state,e);return r&&r instanceof Y?Xt(n,r):!1}else if(!(Qe&&t.indexOf("m")>-1)){let r=o.$head,s=r.textOffset?null:e<0?r.nodeBefore:r.nodeAfter,i;if(!s||s.isText)return!1;let l=e<0?r.pos-s.nodeSize:r.pos;return s.isAtom||(i=n.docView.descAt(l))&&!i.contentDOM?Y.isSelectable(s)?Xt(n,new Y(e<0?n.state.doc.resolve(r.pos-s.nodeSize):r)):Do?Xt(n,new Q(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(o instanceof Y&&o.node.isInline)return Xt(n,new Q(e>0?o.$to:o.$from));{let r=dl(n.state,e);return r?Xt(n,r):!1}}}function zr(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Vo(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function no(n,e){return e<0?B1(n):I1(n)}function B1(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r,s,i=!1;for(Xe&&t.nodeType==1&&o<zr(t)&&Vo(t.childNodes[o],-1)&&(i=!0);;)if(o>0){if(t.nodeType!=1)break;{let l=t.childNodes[o-1];if(Vo(l,-1))r=t,s=--o;else if(l.nodeType==3)t=l,o=t.nodeValue.length;else break}}else{if(Uu(t))break;{let l=t.previousSibling;for(;l&&Vo(l,-1);)r=t.parentNode,s=Ae(l),l=l.previousSibling;if(l)t=l,o=zr(t);else{if(t=t.parentNode,t==n.dom)break;o=0}}}i?ul(n,t,o):r&&ul(n,r,s)}function I1(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r=zr(t),s,i;for(;;)if(o<r){if(t.nodeType!=1)break;let l=t.childNodes[o];if(Vo(l,1))s=t,i=++o;else break}else{if(Uu(t))break;{let l=t.nextSibling;for(;l&&Vo(l,1);)s=l.parentNode,i=Ae(l)+1,l=l.nextSibling;if(l)t=l,o=0,r=zr(t);else{if(t=t.parentNode,t==n.dom)break;o=r=0}}}s&&ul(n,s,i)}function Uu(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function O1(n,e){for(;n&&e==n.childNodes.length&&!_o(n);)e=Ae(n)+1,n=n.parentNode;for(;n&&e<n.childNodes.length;){let t=n.childNodes[e];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=0}}function _1(n,e){for(;n&&!e&&!_o(n);)e=Ae(n),n=n.parentNode;for(;n&&e;){let t=n.childNodes[e-1];if(t.nodeType==3)return t;if(t.nodeType==1&&t.contentEditable=="false")break;n=t,e=n.childNodes.length}}function ul(n,e,t){if(e.nodeType!=3){let s,i;(i=O1(e,t))?(e=i,t=0):(s=_1(e,t))&&(e=s,t=s.nodeValue.length)}let o=n.domSelection();if(!o)return;if(Lr(o)){let s=document.createRange();s.setEnd(e,t),s.setStart(e,t),o.removeAllRanges(),o.addRange(s)}else o.extend&&o.extend(e,t);n.domObserver.setCurSelection();let{state:r}=n;setTimeout(()=>{n.state==r&&Rt(n)},50)}function Wu(n,e){let t=n.state.doc.resolve(e);if(!(Be||mu)&&t.parent.inlineContent){let r=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),i=(s.top+s.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(s.left-r.left)>1)return s.left<r.left?"ltr":"rtl"}if(e<t.end()){let s=n.coordsAtPos(e+1),i=(s.top+s.bottom)/2;if(i>r.top&&i<r.bottom&&Math.abs(s.left-r.left)>1)return s.left>r.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Ku(n,e,t){let o=n.state.selection;if(o instanceof Q&&!o.empty||t.indexOf("s")>-1||Qe&&t.indexOf("m")>-1)return!1;let{$from:r,$to:s}=o;if(!r.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let i=dl(n.state,e);if(i&&i instanceof Y)return Xt(n,i)}if(!r.parent.inlineContent){let i=e<0?r:s,l=o instanceof qe?ee.near(i,e):ee.findFrom(i,e);return l?Xt(n,l):!1}return!1}function qu(n,e){if(!(n.state.selection instanceof Q))return!0;let{$head:t,$anchor:o,empty:r}=n.state.selection;if(!t.sameParent(o))return!0;if(!r)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let i=n.state.tr;return e<0?i.delete(t.pos-s.nodeSize,t.pos):i.delete(t.pos,t.pos+s.nodeSize),n.dispatch(i),!0}return!1}function Ju(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function D1(n){if(!Pe||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let o=e.firstChild;Ju(n,o,"true"),setTimeout(()=>Ju(n,o,"false"),20)}return!1}function R1(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function P1(n,e){let t=e.keyCode,o=R1(e);if(t==8||Qe&&t==72&&o=="c")return qu(n,-1)||no(n,-1);if(t==46&&!e.shiftKey||Qe&&t==68&&o=="c")return qu(n,1)||no(n,1);if(t==13||t==27)return!0;if(t==37||Qe&&t==66&&o=="c"){let r=t==37?Wu(n,n.state.selection.from)=="ltr"?-1:1:-1;return ju(n,r,o)||no(n,r)}else if(t==39||Qe&&t==70&&o=="c"){let r=t==39?Wu(n,n.state.selection.from)=="ltr"?1:-1:1;return ju(n,r,o)||no(n,r)}else{if(t==38||Qe&&t==80&&o=="c")return Ku(n,-1,o)||no(n,-1);if(t==40||Qe&&t==78&&o=="c")return D1(n)||Ku(n,1,o)||no(n,1);if(o==(Qe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function fl(n,e){n.someProp("transformCopied",p=>{e=p(e,n)});let t=[],{content:o,openStart:r,openEnd:s}=e;for(;r>1&&s>1&&o.childCount==1&&o.firstChild.childCount==1;){r--,s--;let p=o.firstChild;t.push(p.type.name,p.attrs!=p.type.defaultAttrs?p.attrs:null),o=p.content}let i=n.someProp("clipboardSerializer")||xn.fromSchema(n.state.schema),l=nf(),c=l.createElement("div");c.appendChild(i.serializeFragment(o,{document:l}));let d=c.firstChild,u,f=0;for(;d&&d.nodeType==1&&(u=ef[d.nodeName.toLowerCase()]);){for(let p=u.length-1;p>=0;p--){let m=l.createElement(u[p]);for(;c.firstChild;)m.appendChild(c.firstChild);c.appendChild(m),f++}d=c.firstChild}d&&d.nodeType==1&&d.setAttribute("data-pm-slice",`${r} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let h=n.someProp("clipboardTextSerializer",p=>p(e,n))||e.content.textBetween(0,e.content.size,`
|
|
8
8
|
|
|
9
9
|
`);return{dom:c,text:h,slice:e}}function Gu(n,e,t,o,r){let s=r.parent.type.spec.code,i,l;if(!t&&!e)return null;let c=!!e&&(o||s||!t);if(c){if(n.someProp("transformPastedText",h=>{e=h(e,s||o,n)}),s)return l=new U(P.from(n.state.schema.text(e.replace(/\r\n?/g,`
|
|
10
|
-
`))),0,0),n.someProp("transformPasted",h=>{l=h(l,n,!0)}),l;let f=n.someProp("clipboardTextParser",h=>h(e,r,o,n));if(f)l=f;else{let h=r.marks(),{schema:p}=n.state,m=xn.fromSchema(p);i=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(g=>{let y=i.appendChild(document.createElement("p"));g&&y.appendChild(m.serializeNode(p.text(g,h)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),i=z1(t),Do&&F1(i);let d=i&&i.querySelector("[data-pm-slice]"),u=d&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(d.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let f=+u[3];f>0;f--){let h=i.firstChild;for(;h&&h.nodeType!=1;)h=h.nextSibling;if(!h)break;i=h}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Bt.fromSchema(n.state.schema)).parseSlice(i,{preserveWhitespace:!!(c||u),context:r,ruleFromNode(h){return h.nodeName=="BR"&&!h.nextSibling&&h.parentNode&&!L1.test(h.parentNode.nodeName)?{ignore:!0}:null}})),u)l=H1(Zu(l,+u[1],+u[2]),u[4]);else if(l=U.maxOpen(V1(l.content,r),!0),l.openStart||l.openEnd){let f=0,h=0;for(let p=l.content.firstChild;f<l.openStart&&!p.type.spec.isolating;f++,p=p.firstChild);for(let p=l.content.lastChild;h<l.openEnd&&!p.type.spec.isolating;h++,p=p.lastChild);l=Zu(l,f,h)}return n.someProp("transformPasted",f=>{l=f(l,n,c)}),l}const L1=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function V1(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.index(t)),s,i=[];if(n.forEach(l=>{if(!i)return;let c=r.findWrapping(l.type),d;if(!c)return i=null;if(d=i.length&&s.length&&Xu(c,s,l,i[i.length-1],0))i[i.length-1]=d;else{i.length&&(i[i.length-1]=Qu(i[i.length-1],s.length));let u=Yu(l,c);i.push(u),r=r.matchType(u.type),s=c}}),i)return P.from(i)}return n}function Yu(n,e,t=0){for(let o=e.length-1;o>=t;o--)n=e[o].create(null,P.from(n));return n}function Xu(n,e,t,o,r){if(r<n.length&&r<e.length&&n[r]==e[r]){let s=Xu(n,e,t,o.lastChild,r+1);if(s)return o.copy(o.content.replaceChild(o.childCount-1,s));if(o.contentMatchAt(o.childCount).matchType(r==n.length-1?t.type:n[r+1]))return o.copy(o.content.append(P.from(Yu(t,n,r+1))))}}function Qu(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,Qu(n.lastChild,e-1)),o=n.contentMatchAt(n.childCount).fillBefore(P.empty,!0);return n.copy(t.append(o))}function hl(n,e,t,o,r,s){let i=e<0?n.firstChild:n.lastChild,l=i.content;return n.childCount>1&&(s=0),r<o-1&&(l=hl(l,e,t,o,r+1,s)),r>=t&&(l=e<0?i.contentMatchAt(0).fillBefore(l,s<=r).append(l):l.append(i.contentMatchAt(i.childCount).fillBefore(P.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,i.copy(l))}function Zu(n,e,t){return e<n.openStart&&(n=new U(hl(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new U(hl(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const ef={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let tf=null;function nf(){return tf||(tf=document.implementation.createHTMLDocument("title"))}let pl=null;function $1(n){let e=window.trustedTypes;return e?(pl||(pl=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),pl.createHTML(n)):n}function z1(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=nf().createElement("div"),o=/<([a-z][^>\s]+)/i.exec(n),r;if((r=o&&ef[o[1].toLowerCase()])&&(n=r.map(s=>"<"+s+">").join("")+n+r.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=$1(n),r)for(let s=0;s<r.length;s++)t=t.querySelector(r[s])||t;return t}function F1(n){let e=n.querySelectorAll(Be?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let o=e[t];o.childNodes.length==1&&o.textContent==" "&&o.parentNode&&o.parentNode.replaceChild(n.ownerDocument.createTextNode(" "),o)}}function H1(n,e){if(!n.size)return n;let t=n.content.firstChild.type.schema,o;try{o=JSON.parse(e)}catch{return n}let{content:r,openStart:s,openEnd:i}=n;for(let l=o.length-2;l>=0;l-=2){let c=t.nodes[o[l]];if(!c||c.hasRequiredAttrs())break;r=P.from(c.create(o[l+1],r)),s++,i++}return new U(r,s,i)}const $e={},ze={},j1={touchstart:!0,touchmove:!0};class U1{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function W1(n){for(let e in $e){let t=$e[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=o=>{q1(n,o)&&!gl(n,o)&&(n.editable||!(o.type in ze))&&t(n,o)},j1[e]?{passive:!0}:void 0)}Pe&&n.dom.addEventListener("input",()=>null),ml(n)}function Qt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function K1(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function ml(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=o=>gl(n,o))})}function gl(n,e){return n.someProp("handleDOMEvents",t=>{let o=t[e.type];return o?o(n,e)||e.defaultPrevented:!1})}function q1(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function J1(n,e){!gl(n,e)&&$e[e.type]&&(n.editable||!(e.type in ze))&&$e[e.type](n,e)}ze.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!rf(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(_t&&Be&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),eo&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let o=Date.now();n.input.lastIOSEnter=o,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==o&&(n.someProp("handleKeyDown",r=>r(n,Tn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",o=>o(n,t))||P1(n,t)?t.preventDefault():Qt(n,"key")},ze.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)},ze.keypress=(n,e)=>{let t=e;if(rf(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Qe&&t.metaKey)return;if(n.someProp("handleKeyPress",r=>r(n,t))){t.preventDefault();return}let o=n.state.selection;if(!(o instanceof Q)||!o.$from.sameParent(o.$to)){let r=String.fromCharCode(t.charCode),s=()=>n.state.tr.insertText(r).scrollIntoView();!/[\r\n]/.test(r)&&!n.someProp("handleTextInput",i=>i(n,o.$from.pos,o.$to.pos,r,s))&&n.dispatch(s()),t.preventDefault()}};function Fr(n){return{left:n.clientX,top:n.clientY}}function G1(n,e){let t=e.x-n.clientX,o=e.y-n.clientY;return t*t+o*o<100}function yl(n,e,t,o,r){if(o==-1)return!1;let s=n.state.doc.resolve(o);for(let i=s.depth+1;i>0;i--)if(n.someProp(e,l=>i>s.depth?l(n,t,s.nodeAfter,s.before(i),r,!0):l(n,t,s.node(i),s.before(i),r,!1)))return!0;return!1}function oo(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let o=n.state.tr.setSelection(e);o.setMeta("pointer",!0),n.dispatch(o)}function Y1(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),o=t.nodeAfter;return o&&o.isAtom&&Y.isSelectable(o)?(oo(n,new Y(t)),!0):!1}function X1(n,e){if(e==-1)return!1;let t=n.state.selection,o,r;t instanceof Y&&(o=t.node);let s=n.state.doc.resolve(e);for(let i=s.depth+1;i>0;i--){let l=i>s.depth?s.nodeAfter:s.node(i);if(Y.isSelectable(l)){o&&t.$from.depth>0&&i>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?r=s.before(t.$from.depth):r=s.before(i);break}}return r!=null?(oo(n,Y.create(n.state.doc,r)),!0):!1}function Q1(n,e,t,o,r){return yl(n,"handleClickOn",e,t,o)||n.someProp("handleClick",s=>s(n,e,o))||(r?X1(n,t):Y1(n,t))}function Z1(n,e,t,o){return yl(n,"handleDoubleClickOn",e,t,o)||n.someProp("handleDoubleClick",r=>r(n,e,o))}function ek(n,e,t,o){return yl(n,"handleTripleClickOn",e,t,o)||n.someProp("handleTripleClick",r=>r(n,e,o))||tk(n,t,o)}function tk(n,e,t){if(t.button!=0)return!1;let o=n.state.doc;if(e==-1)return o.inlineContent?(oo(n,Q.create(o,0,o.content.size)),!0):!1;let r=o.resolve(e);for(let s=r.depth+1;s>0;s--){let i=s>r.depth?r.nodeAfter:r.node(s),l=r.before(s);if(i.inlineContent)oo(n,Q.create(o,l+1,l+1+i.content.size));else if(Y.isSelectable(i))oo(n,Y.create(o,l));else continue;return!0}}function kl(n){return Hr(n)}const of=Qe?"metaKey":"ctrlKey";$e.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let o=kl(n),r=Date.now(),s="singleClick";r-n.input.lastClick.time<500&&G1(t,n.input.lastClick)&&!t[of]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:r,x:t.clientX,y:t.clientY,type:s,button:t.button};let i=n.posAtCoords(Fr(t));i&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new nk(n,i,t,!!o)):(s=="doubleClick"?Z1:ek)(n,i.pos,i.inside,t)?t.preventDefault():Qt(n,"pointer"))};class nk{constructor(e,t,o,r){this.view=e,this.pos=t,this.event=o,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!o[of],this.allowDefault=o.shiftKey;let s,i;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),i=t.inside;else{let u=e.state.doc.resolve(t.pos);s=u.parent,i=u.depth?u.before():0}const l=r?null:o.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.nodeDOM.nodeType==1?c.nodeDOM:null;let{selection:d}=e.state;(o.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||d instanceof Y&&d.from<=i&&d.to>i)&&(this.mightDrag={node:s,pos:i,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Xe&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),Qt(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>Rt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(Fr(e))),this.updateAllowDefault(e),this.allowDefault||!t?Qt(this.view,"pointer"):Q1(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Pe&&this.mightDrag&&!this.mightDrag.node.isAtom||Be&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(oo(this.view,ee.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Qt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Qt(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}$e.touchstart=n=>{n.input.lastTouch=Date.now(),kl(n),Qt(n,"pointer")},$e.touchmove=n=>{n.input.lastTouch=Date.now(),Qt(n,"pointer")},$e.contextmenu=n=>kl(n);function rf(n,e){return n.composing?!0:Pe&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const ok=_t?5e3:-1;ze.compositionstart=ze.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof Q&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(o=>o.type.spec.inclusive===!1)||Be&&mu&&rk(n)))n.markCursor=n.state.storedMarks||t.marks(),Hr(n,!0),n.markCursor=null;else if(Hr(n,!e.selection.empty),Xe&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let o=n.domSelectionRange();for(let r=o.focusNode,s=o.focusOffset;r&&r.nodeType==1&&s!=0;){let i=s<0?r.lastChild:r.childNodes[s-1];if(!i)break;if(i.nodeType==3){let l=n.domSelection();l&&l.collapse(i,i.nodeValue.length);break}else r=i,s=-1}}n.input.composing=!0}sf(n,ok)};function rk(n){let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let o=e.childNodes[t];return o.nodeType==1&&o.contentEditable=="false"}ze.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.badSafariComposition?n.domObserver.forceFlush():n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,sf(n,20))};function sf(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Hr(n),e))}function lf(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=ik());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function sk(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=Xy(e.focusNode,e.focusOffset),o=Qy(e.focusNode,e.focusOffset);if(t&&o&&t!=o){let r=o.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||o==s)return s;if(!r||!r.isText(o.nodeValue))return o;if(n.input.compositionNode==o){let i=t.pmViewDesc;if(!(!i||!i.isText(t.nodeValue)))return o}}return t||o}function ik(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Hr(n,e=!1){if(!(_t&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),lf(n),e||n.docView&&n.docView.dirty){let t=ll(n),o=n.state.selection;return t&&!t.eq(o)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!o.$from.node(o.$from.sharedDepth(o.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function lk(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let o=getSelection(),r=document.createRange();r.selectNodeContents(e),n.dom.blur(),o.removeAllRanges(),o.addRange(r),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const $o=He&&Jt<15||eo&&n1<604;$e.copy=ze.cut=(n,e)=>{let t=e,o=n.state.selection,r=t.type=="cut";if(o.empty)return;let s=$o?null:t.clipboardData,i=o.content(),{dom:l,text:c}=fl(n,i);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):lk(n,l),r&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function ak(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function ck(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,o=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(o.contentEditable="true"),o.style.cssText="position: fixed; left: -10000px; top: 10px",o.focus();let r=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),o.parentNode&&o.parentNode.removeChild(o),t?zo(n,o.value,null,r,e):zo(n,o.textContent,o.innerHTML,r,e)},50)}function zo(n,e,t,o,r){let s=Gu(n,e,t,o,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,r,s||U.empty)))return!0;if(!s)return!1;let i=ak(s),l=i?n.state.tr.replaceSelectionWith(i,o):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function af(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ze.paste=(n,e)=>{let t=e;if(n.composing&&!_t)return;let o=$o?null:t.clipboardData,r=n.input.shiftKey&&n.input.lastKeyCode!=45;o&&zo(n,af(o),o.getData("text/html"),r,t)?t.preventDefault():ck(n,t)};class cf{constructor(e,t,o){this.slice=e,this.move=t,this.node=o}}const dk=Qe?"altKey":"ctrlKey";function df(n,e){let t=n.someProp("dragCopies",o=>!o(e));return t??!e[dk]}$e.dragstart=(n,e)=>{let t=e,o=n.input.mouseDown;if(o&&o.done(),!t.dataTransfer)return;let r=n.state.selection,s=r.empty?null:n.posAtCoords(Fr(t)),i;if(!(s&&s.pos>=r.from&&s.pos<=(r instanceof Y?r.to-1:r.to))){if(o&&o.mightDrag)i=Y.create(n.state.doc,o.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(i=Y.create(n.state.doc,f.posBefore))}}let l=(i||n.state.selection).content(),{dom:c,text:d,slice:u}=fl(n,l);(!t.dataTransfer.files.length||!Be||pu>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData($o?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",$o||t.dataTransfer.setData("text/plain",d),n.dragging=new cf(u,df(n,t),i)},$e.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)},ze.dragover=ze.dragenter=(n,e)=>e.preventDefault(),ze.drop=(n,e)=>{try{uk(n,e,n.dragging)}finally{n.dragging=null}};function uk(n,e,t){if(!e.dataTransfer)return;let o=n.posAtCoords(Fr(e));if(!o)return;let r=n.state.doc.resolve(o.pos),s=t&&t.slice;s?n.someProp("transformPasted",p=>{s=p(s,n,!1)}):s=Gu(n,af(e.dataTransfer),$o?null:e.dataTransfer.getData("text/html"),!1,r);let i=!!(t&&df(n,e));if(n.someProp("handleDrop",p=>p(n,e,s||U.empty,i))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Vd(n.state.doc,r.pos,s):r.pos;l==null&&(l=r.pos);let c=n.state.tr;if(i){let{node:p}=t;p?p.replace(c):c.deleteSelection()}let d=c.mapping.map(l),u=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=c.doc;if(u?c.replaceRangeWith(d,d,s.content.firstChild):c.replaceRange(d,d,s),c.doc.eq(f))return;let h=c.doc.resolve(d);if(u&&Y.isSelectable(s.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new Y(h));else{let p=c.mapping.map(l);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,y,k)=>p=k),c.setSelection(cl(n,h,c.doc.resolve(p)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))}$e.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&Rt(n)},20))},$e.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)},$e.beforeinput=(n,e)=>{if(Be&&_t&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:o}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=o||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,Tn(8,"Backspace")))))return;let{$cursor:r}=n.state.selection;r&&r.pos>0&&n.dispatch(n.state.tr.delete(r.pos-1,r.pos).scrollIntoView())},50)}};for(let n in ze)$e[n]=ze[n];function Fo(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class jr{constructor(e,t){this.toDOM=e,this.spec=t||Bn,this.side=this.spec.side||0}map(e,t,o,r){let{pos:s,deleted:i}=e.mapResult(t.from+r,this.side<0?-1:1);return i?null:new Fe(s-o,s-o,this)}valid(){return!0}eq(e){return this==e||e instanceof jr&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Fo(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Zt{constructor(e,t){this.attrs=e,this.spec=t||Bn}map(e,t,o,r){let s=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-o,i=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-o;return s>=i?null:new Fe(s,i,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Zt&&Fo(this.attrs,e.attrs)&&Fo(this.spec,e.spec)}static is(e){return e.type instanceof Zt}destroy(){}}class wl{constructor(e,t){this.attrs=e,this.spec=t||Bn}map(e,t,o,r){let s=e.mapResult(t.from+r,1);if(s.deleted)return null;let i=e.mapResult(t.to+r,-1);return i.deleted||i.pos<=s.pos?null:new Fe(s.pos-o,i.pos-o,this)}valid(e,t){let{index:o,offset:r}=e.content.findIndex(t.from),s;return r==t.from&&!(s=e.child(o)).isText&&r+s.nodeSize==t.to}eq(e){return this==e||e instanceof wl&&Fo(this.attrs,e.attrs)&&Fo(this.spec,e.spec)}destroy(){}}class Fe{constructor(e,t,o){this.from=e,this.to=t,this.type=o}copy(e,t){return new Fe(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,o){return this.type.map(e,this,t,o)}static widget(e,t,o){return new Fe(e,e,new jr(t,o))}static inline(e,t,o,r){return new Fe(e,t,new Zt(o,r))}static node(e,t,o,r){return new Fe(e,t,new wl(o,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof Zt}get widget(){return this.type instanceof jr}}const ro=[],Bn={};class he{constructor(e,t){this.local=e.length?e:ro,this.children=t.length?t:ro}static create(e,t){return t.length?Ur(t,e,0,Bn):Le}find(e,t,o){let r=[];return this.findInner(e??0,t??1e9,r,0,o),r}findInner(e,t,o,r,s){for(let i=0;i<this.local.length;i++){let l=this.local[i];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&o.push(l.copy(l.from+r,l.to+r))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<t&&this.children[i+1]>e){let l=this.children[i]+1;this.children[i+2].findInner(e-l,t-l,o,r+l,s)}}map(e,t,o){return this==Le||e.maps.length==0?this:this.mapInner(e,t,0,0,o||Bn)}mapInner(e,t,o,r,s){let i;for(let l=0;l<this.local.length;l++){let c=this.local[l].map(e,o,r);c&&c.type.valid(t,c)?(i||(i=[])).push(c):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?fk(this.children,i||[],e,t,o,r,s):i?new he(i.sort(In),ro):Le}add(e,t){return t.length?this==Le?he.create(e,t):this.addInner(e,t,0):this}addInner(e,t,o){let r,s=0;e.forEach((l,c)=>{let d=c+o,u;if(u=ff(t,l,d)){for(r||(r=this.children.slice());s<r.length&&r[s]<c;)s+=3;r[s]==c?r[s+2]=r[s+2].addInner(l,u,d+1):r.splice(s,0,c,c+l.nodeSize,Ur(u,l,d+1,Bn)),s+=3}});let i=uf(s?hf(t):t,-o);for(let l=0;l<i.length;l++)i[l].type.valid(e,i[l])||i.splice(l--,1);return new he(i.length?this.local.concat(i).sort(In):this.local,r||this.children)}remove(e){return e.length==0||this==Le?this:this.removeInner(e,0)}removeInner(e,t){let o=this.children,r=this.local;for(let s=0;s<o.length;s+=3){let i,l=o[s]+t,c=o[s+1]+t;for(let u=0,f;u<e.length;u++)(f=e[u])&&f.from>l&&f.to<c&&(e[u]=null,(i||(i=[])).push(f));if(!i)continue;o==this.children&&(o=this.children.slice());let d=o[s+2].removeInner(i,l+1);d!=Le?o[s+2]=d:(o.splice(s,3),s-=3)}if(r.length){for(let s=0,i;s<e.length;s++)if(i=e[s])for(let l=0;l<r.length;l++)r[l].eq(i,t)&&(r==this.local&&(r=this.local.slice()),r.splice(l--,1))}return o==this.children&&r==this.local?this:r.length||o.length?new he(r,o):Le}forChild(e,t){if(this==Le)return this;if(t.isLeaf)return he.empty;let o,r;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(o=this.children[l+2]);break}let s=e+1,i=s+t.content.size;for(let l=0;l<this.local.length;l++){let c=this.local[l];if(c.from<i&&c.to>s&&c.type instanceof Zt){let d=Math.max(s,c.from)-s,u=Math.min(i,c.to)-s;d<u&&(r||(r=[])).push(c.copy(d,u))}}if(r){let l=new he(r.sort(In),ro);return o?new en([l,o]):l}return o||Le}eq(e){if(this==e)return!0;if(!(e instanceof he)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return bl(this.localsInner(e))}localsInner(e){if(this==Le)return ro;if(e.inlineContent||!this.local.some(Zt.is))return this.local;let t=[];for(let o=0;o<this.local.length;o++)this.local[o].type instanceof Zt||t.push(this.local[o]);return t}forEachSet(e){e(this)}}he.empty=new he([],[]),he.removeOverlap=bl;const Le=he.empty;class en{constructor(e){this.members=e}map(e,t){const o=this.members.map(r=>r.map(e,t,Bn));return en.from(o)}forChild(e,t){if(t.isLeaf)return he.empty;let o=[];for(let r=0;r<this.members.length;r++){let s=this.members[r].forChild(e,t);s!=Le&&(s instanceof en?o=o.concat(s.members):o.push(s))}return en.from(o)}eq(e){if(!(e instanceof en)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,o=!0;for(let r=0;r<this.members.length;r++){let s=this.members[r].localsInner(e);if(s.length)if(!t)t=s;else{o&&(t=t.slice(),o=!1);for(let i=0;i<s.length;i++)t.push(s[i])}}return t?bl(o?t:t.sort(In)):ro}static from(e){switch(e.length){case 0:return Le;case 1:return e[0];default:return new en(e.every(t=>t instanceof he)?e:e.reduce((t,o)=>t.concat(o instanceof he?o:o.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function fk(n,e,t,o,r,s,i){let l=n.slice();for(let d=0,u=s;d<t.maps.length;d++){let f=0;t.maps[d].forEach((h,p,m,g)=>{let y=g-m-(p-h);for(let k=0;k<l.length;k+=3){let x=l[k+1];if(x<0||h>x+u-f)continue;let b=l[k]+u-f;p>=b?l[k+1]=h<=b?-2:-1:h>=u&&y&&(l[k]+=y,l[k+1]+=y)}f+=y}),u=t.maps[d].map(u,-1)}let c=!1;for(let d=0;d<l.length;d+=3)if(l[d+1]<0){if(l[d+1]==-2){c=!0,l[d+1]=-1;continue}let u=t.map(n[d]+s),f=u-r;if(f<0||f>=o.content.size){c=!0;continue}let h=t.map(n[d+1]+s,-1),p=h-r,{index:m,offset:g}=o.content.findIndex(f),y=o.maybeChild(m);if(y&&g==f&&g+y.nodeSize==p){let k=l[d+2].mapInner(t,y,u+1,n[d]+s+1,i);k!=Le?(l[d]=f,l[d+1]=p,l[d+2]=k):(l[d+1]=-2,c=!0)}else c=!0}if(c){let d=hk(l,n,e,t,r,s,i),u=Ur(d,o,0,i);e=u.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,h=0;f<u.children.length;f+=3){let p=u.children[f];for(;h<l.length&&l[h]<p;)h+=3;l.splice(h,0,u.children[f],u.children[f+1],u.children[f+2])}}return new he(e.sort(In),l)}function uf(n,e){if(!e||!n.length)return n;let t=[];for(let o=0;o<n.length;o++){let r=n[o];t.push(new Fe(r.from+e,r.to+e,r.type))}return t}function hk(n,e,t,o,r,s,i){function l(c,d){for(let u=0;u<c.local.length;u++){let f=c.local[u].map(o,r,d);f?t.push(f):i.onRemove&&i.onRemove(c.local[u].spec)}for(let u=0;u<c.children.length;u+=3)l(c.children[u+2],c.children[u]+d+1)}for(let c=0;c<n.length;c+=3)n[c+1]==-1&&l(n[c+2],e[c]+s+1);return t}function ff(n,e,t){if(e.isLeaf)return null;let o=t+e.nodeSize,r=null;for(let s=0,i;s<n.length;s++)(i=n[s])&&i.from>t&&i.to<o&&((r||(r=[])).push(i),n[s]=null);return r}function hf(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function Ur(n,e,t,o){let r=[],s=!1;e.forEach((l,c)=>{let d=ff(n,l,c+t);if(d){s=!0;let u=Ur(d,l,t+c+1,o);u!=Le&&r.push(c,c+l.nodeSize,u)}});let i=uf(s?hf(n):n,-t).sort(In);for(let l=0;l<i.length;l++)i[l].type.valid(e,i[l])||(o.onRemove&&o.onRemove(i[l].spec),i.splice(l--,1));return i.length||r.length?new he(i,r):Le}function In(n,e){return n.from-e.from||n.to-e.to}function bl(n){let e=n;for(let t=0;t<e.length-1;t++){let o=e[t];if(o.from!=o.to)for(let r=t+1;r<e.length;r++){let s=e[r];if(s.from==o.from){s.to!=o.to&&(e==n&&(e=n.slice()),e[r]=s.copy(s.from,o.to),pf(e,r+1,s.copy(o.to,s.to)));continue}else{s.from<o.to&&(e==n&&(e=n.slice()),e[t]=o.copy(o.from,s.from),pf(e,r,o.copy(s.from,o.to)));break}}}return e}function pf(n,e,t){for(;e<n.length&&In(t,n[e])>0;)e++;n.splice(e,0,t)}function Sl(n){let e=[];return n.someProp("decorations",t=>{let o=t(n.state);o&&o!=Le&&e.push(o)}),n.cursorWrapper&&e.push(he.create(n.state.doc,[n.cursorWrapper.deco])),en.from(e)}const pk={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},mk=He&&Jt<=11;class gk{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class yk{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new gk,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(o=>{for(let r=0;r<o.length;r++)this.queue.push(o[r]);He&&Jt<=11&&o.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():Pe&&e.composing&&o.some(r=>r.type=="childList"&&r.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),mk&&(this.onCharData=o=>{this.queue.push({target:o.target,type:"characterData",oldValue:o.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,pk)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Fu(this.view)){if(this.suppressingSelectionUpdates)return Rt(this.view);if(He&&Jt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&vn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,o;for(let s=e.focusNode;s;s=Zn(s))t.add(s);for(let s=e.anchorNode;s;s=Zn(s))if(t.has(s)){o=s;break}let r=o&&this.view.docView.nearestDesc(o);if(r&&r.ignoreMutation({type:"selection",target:o.nodeType==3?o.parentNode:o}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let o=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(o)&&Fu(e)&&!this.ignoreSelectionChange(o),s=-1,i=-1,l=!1,c=[];if(e.editable)for(let u=0;u<t.length;u++){let f=this.registerMutation(t[u],c);f&&(s=s<0?f.from:Math.min(f.from,s),i=i<0?f.to:Math.max(f.to,i),f.typeOver&&(l=!0))}if(c.some(u=>u.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let u of c)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;f&&f.nodeType==1&&f.contentEditable=="false"&&u.parentNode.removeChild(u)}}else if(Xe&&c.length){let u=c.filter(f=>f.nodeName=="BR");if(u.length==2){let[f,h]=u;f.parentNode&&f.parentNode.parentNode==h.parentNode?h.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let h of u){let p=h.parentNode;p&&p.nodeName=="LI"&&(!f||bk(e,f)!=p)&&h.remove()}}}let d=null;s<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Lr(o)&&(d=ll(e))&&d.eq(ee.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,Rt(e),this.currentSelection.set(o),e.scrollToSelection()):(s>-1||r)&&(s>-1&&(e.docView.markDirty(s,i),kk(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Sk(e,c)),this.handleDOMChange(s,i,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(o)||Rt(e),this.currentSelection.set(o))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let o=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(o==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!o||o.ignoreMutation(e))return null;if(e.type=="childList"){for(let u=0;u<e.addedNodes.length;u++){let f=e.addedNodes[u];t.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}if(o.contentDOM&&o.contentDOM!=o.dom&&!o.contentDOM.contains(e.target))return{from:o.posBefore,to:o.posAfter};let r=e.previousSibling,s=e.nextSibling;if(He&&Jt<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:f,nextSibling:h}=e.addedNodes[u];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(r=f),(!h||Array.prototype.indexOf.call(e.addedNodes,h)<0)&&(s=h)}let i=r&&r.parentNode==e.target?Ae(r)+1:0,l=o.localPosFromDOM(e.target,i,-1),c=s&&s.parentNode==e.target?Ae(s):e.target.childNodes.length,d=o.localPosFromDOM(e.target,c,1);return{from:l,to:d}}else return e.type=="attributes"?{from:o.posAtStart-o.border,to:o.posAtEnd+o.border}:(this.lastChangedTextNode=e.target,{from:o.posAtStart,to:o.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let mf=new WeakMap,gf=!1;function kk(n){if(!mf.has(n)&&(mf.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=Xe,gf)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),gf=!0}}function yf(n,e){let t=e.startContainer,o=e.startOffset,r=e.endContainer,s=e.endOffset,i=n.domAtPos(n.state.selection.anchor);return vn(i.node,i.offset,r,s)&&([t,o,r,s]=[r,s,t,o]),{anchorNode:t,anchorOffset:o,focusNode:r,focusOffset:s}}function wk(n,e){if(e.getComposedRanges){let r=e.getComposedRanges(n.root)[0];if(r)return yf(n,r)}let t;function o(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return n.dom.addEventListener("beforeinput",o,!0),document.execCommand("indent"),n.dom.removeEventListener("beforeinput",o,!0),t?yf(n,t):null}function bk(n,e){for(let t=e.parentNode;t&&t!=n.dom;t=t.parentNode){let o=n.docView.nearestDesc(t,!0);if(o&&o.node.isBlock)return t}return null}function Sk(n,e){var t;let{focusNode:o,focusOffset:r}=n.domSelectionRange();for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let i=s.nextSibling;for(;i&&i.nodeName!="TD"&&i.nodeName!="TH";)i=i.nextSibling;if(i){let l=i;for(;;){let c=l.firstChild;if(!c||c.nodeType!=1||c.contentEditable=="false"||/^(BR|IMG)$/.test(c.nodeName))break;l=c}l.insertBefore(s,l.firstChild),o==s&&n.domSelection().collapse(s,r)}else s.parentNode.removeChild(s)}}function xk(n,e,t){let{node:o,fromOffset:r,toOffset:s,from:i,to:l}=n.docView.parseRange(e,t),c=n.domSelectionRange(),d,u=c.anchorNode;if(u&&n.dom.contains(u.nodeType==1?u:u.parentNode)&&(d=[{node:u,offset:c.anchorOffset}],Lr(c)||d.push({node:c.focusNode,offset:c.focusOffset})),Be&&n.input.lastKeyCode===8)for(let y=s;y>r;y--){let k=o.childNodes[y-1],x=k.pmViewDesc;if(k.nodeName=="BR"&&!x){s=y;break}if(!x||x.size)break}let f=n.state.doc,h=n.someProp("domParser")||Bt.fromSchema(n.state.schema),p=f.resolve(i),m=null,g=h.parse(o,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:r,to:s,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:d,ruleFromNode:Ck,context:p});if(d&&d[0].pos!=null){let y=d[0].pos,k=d[1]&&d[1].pos;k==null&&(k=y),m={anchor:y+i,head:k+i}}return{doc:g,sel:m,from:i,to:l}}function Ck(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(Pe&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||Pe&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const Ek=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function vk(n,e,t,o,r){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let E=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,T=ll(n,E);if(T&&!n.state.selection.eq(T)){if(Be&&_t&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",A=>A(n,Tn(13,"Enter"))))return;let M=n.state.tr.setSelection(T);E=="pointer"?M.setMeta("pointer",!0):E=="key"&&M.scrollIntoView(),s&&M.setMeta("composition",s),n.dispatch(M)}return}let i=n.state.doc.resolve(e),l=i.sharedDepth(t);e=i.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,d=xk(n,e,t),u=n.state.doc,f=u.slice(d.from,d.to),h,p;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(h=n.state.selection.to,p="end"):(h=n.state.selection.from,p="start"),n.input.lastKeyCode=null;let m=Nk(f.content,d.doc.content,d.from,h,p);if(m&&n.input.domChangeCount++,(eo&&n.input.lastIOSEnter>Date.now()-225||_t)&&r.some(E=>E.nodeType==1&&!Ek.test(E.nodeName))&&(!m||m.endA>=m.endB)&&n.someProp("handleKeyDown",E=>E(n,Tn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!m)if(o&&c instanceof Q&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(d.sel&&d.sel.anchor!=d.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(d.sel){let E=kf(n,n.state.doc,d.sel);if(E&&!E.eq(n.state.selection)){let T=n.state.tr.setSelection(E);s&&T.setMeta("composition",s),n.dispatch(T)}}return}n.state.selection.from<n.state.selection.to&&m.start==m.endB&&n.state.selection instanceof Q&&(m.start>n.state.selection.from&&m.start<=n.state.selection.from+2&&n.state.selection.from>=d.from?m.start=n.state.selection.from:m.endA<n.state.selection.to&&m.endA>=n.state.selection.to-2&&n.state.selection.to<=d.to&&(m.endB+=n.state.selection.to-m.endA,m.endA=n.state.selection.to)),He&&Jt<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>d.from&&d.doc.textBetween(m.start-d.from-1,m.start-d.from+1)==" "&&(m.start--,m.endA--,m.endB--);let g=d.doc.resolveNoCache(m.start-d.from),y=d.doc.resolveNoCache(m.endB-d.from),k=u.resolve(m.start),x=g.sameParent(y)&&g.parent.inlineContent&&k.end()>=m.endA;if((eo&&n.input.lastIOSEnter>Date.now()-225&&(!x||r.some(E=>E.nodeName=="DIV"||E.nodeName=="P"))||!x&&g.pos<d.doc.content.size&&(!g.sameParent(y)||!g.parent.inlineContent)&&g.pos<y.pos&&!/\S/.test(d.doc.textBetween(g.pos,y.pos,"","")))&&n.someProp("handleKeyDown",E=>E(n,Tn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>m.start&&Mk(u,m.start,m.endA,g,y)&&n.someProp("handleKeyDown",E=>E(n,Tn(8,"Backspace")))){_t&&Be&&n.domObserver.suppressSelectionUpdates();return}Be&&m.endB==m.start&&(n.input.lastChromeDelete=Date.now()),_t&&!x&&g.start()!=y.start()&&y.parentOffset==0&&g.depth==y.depth&&d.sel&&d.sel.anchor==d.sel.head&&d.sel.head==m.endA&&(m.endB-=2,y=d.doc.resolveNoCache(m.endB-d.from),setTimeout(()=>{n.someProp("handleKeyDown",function(E){return E(n,Tn(13,"Enter"))})},20));let b=m.start,S=m.endA,C=E=>{let T=E||n.state.tr.replace(b,S,d.doc.slice(m.start-d.from,m.endB-d.from));if(d.sel){let M=kf(n,T.doc,d.sel);M&&!(Be&&n.composing&&M.empty&&(m.start!=m.endB||n.input.lastChromeDelete<Date.now()-100)&&(M.head==b||M.head==T.mapping.map(S)-1)||He&&M.empty&&M.head==b)&&T.setSelection(M)}return s&&T.setMeta("composition",s),T.scrollIntoView()},v;if(x)if(g.pos==y.pos){He&&Jt<=11&&g.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>Rt(n),20));let E=C(n.state.tr.delete(b,S)),T=u.resolve(m.start).marksAcross(u.resolve(m.endA));T&&E.ensureMarks(T),n.dispatch(E)}else if(m.endA==m.endB&&(v=Tk(g.parent.content.cut(g.parentOffset,y.parentOffset),k.parent.content.cut(k.parentOffset,m.endA-k.start())))){let E=C(n.state.tr);v.type=="add"?E.addMark(b,S,v.mark):E.removeMark(b,S,v.mark),n.dispatch(E)}else if(g.parent.child(g.index()).isText&&g.index()==y.index()-(y.textOffset?0:1)){let E=g.parent.textBetween(g.parentOffset,y.parentOffset),T=()=>C(n.state.tr.insertText(E,b,S));n.someProp("handleTextInput",M=>M(n,b,S,E,T))||n.dispatch(T())}else n.dispatch(C());else n.dispatch(C())}function kf(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:cl(n,e.resolve(t.anchor),e.resolve(t.head))}function Tk(n,e){let t=n.firstChild.marks,o=e.firstChild.marks,r=t,s=o,i,l,c;for(let u=0;u<o.length;u++)r=o[u].removeFromSet(r);for(let u=0;u<t.length;u++)s=t[u].removeFromSet(s);if(r.length==1&&s.length==0)l=r[0],i="add",c=u=>u.mark(l.addToSet(u.marks));else if(r.length==0&&s.length==1)l=s[0],i="remove",c=u=>u.mark(l.removeFromSet(u.marks));else return null;let d=[];for(let u=0;u<e.childCount;u++)d.push(c(e.child(u)));if(P.from(d).eq(n))return{mark:l,type:i}}function Mk(n,e,t,o,r){if(t-e<=r.pos-o.pos||xl(o,!0,!1)<r.pos)return!1;let s=n.resolve(e);if(!o.parent.isTextblock){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let i=n.resolve(xl(s,!0,!0));return!i.parent.isTextblock||i.pos>t||xl(i,!0,!1)<t?!1:o.parent.content.cut(o.parentOffset).eq(i.parent.content)}function xl(n,e,t){let o=n.depth,r=e?n.end():n.pos;for(;o>0&&(e||n.indexAfter(o)==n.node(o).childCount);)o--,r++,e=!1;if(t){let s=n.node(o).maybeChild(n.indexAfter(o));for(;s&&!s.isLeaf;)s=s.firstChild,r++}return r}function Nk(n,e,t,o,r){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:i,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(r=="end"){let c=Math.max(0,s-Math.min(i,l));o-=i+c-s}if(i<s&&n.size<e.size){let c=o<=s&&o>=i?s-o:0;s-=c,s&&s<e.size&&wf(e.textBetween(s-1,s+1))&&(s+=c?1:-1),l=s+(l-i),i=s}else if(l<s){let c=o<=s&&o>=l?s-o:0;s-=c,s&&s<n.size&&wf(n.textBetween(s-1,s+1))&&(s+=c?1:-1),i=s+(i-l),l=s}return{start:s,endA:i,endB:l}}function wf(n){if(n.length!=2)return!1;let e=n.charCodeAt(0),t=n.charCodeAt(1);return e>=56320&&e<=57343&&t>=55296&&t<=56319}class bf{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new U1,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(vf),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Cf(this),xf(this),this.nodeViews=Ef(this),this.docView=Au(this.state.doc,Sf(this),Sl(this),this.dom,this),this.domObserver=new yk(this,(o,r,s,i)=>vk(this,o,r,s,i)),this.domObserver.start(),W1(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&ml(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(vf),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let o in this._props)t[o]=this._props[o];t.state=this.state;for(let o in e)t[o]=e[o];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var o;let r=this.state,s=!1,i=!1;e.storedMarks&&this.composing&&(lf(this),i=!0),this.state=e;let l=r.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=Ef(this);Bk(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&ml(this),this.editable=Cf(this),xf(this);let c=Sl(this),d=Sf(this),u=r.plugins!=e.plugins&&!r.doc.eq(e.doc)?"reset":e.scrollToSelection>r.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,d,c);(f||!e.selection.eq(r.selection))&&(i=!0);let h=u=="preserve"&&i&&this.dom.style.overflowAnchor==null&&s1(this);if(i){this.domObserver.stop();let p=f&&(He||Be)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&Ak(r.selection,e.selection);if(f){let m=Be?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=sk(this)),(s||!this.docView.update(e.doc,d,c,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=Au(e.doc,d,c,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&A1(this))?Rt(this,p):($u(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),!((o=this.dragging)===null||o===void 0)&&o.node&&!r.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,r),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():h&&i1(h)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof Y){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&gu(this,t.getBoundingClientRect(),e)}else gu(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let o=this.directPlugins[t];o.spec.view&&this.pluginViews.push(o.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let o=this.state.plugins[t];o.spec.view&&this.pluginViews.push(o.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let o=this.pluginViews[t];o.update&&o.update(this,e)}}updateDraggedNode(e,t){let o=e.node,r=-1;if(this.state.doc.nodeAt(o.from)==o.node)r=o.from;else{let s=o.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&this.state.doc.nodeAt(s))==o.node&&(r=s)}this.dragging=new cf(e.slice,e.move,r<0?void 0:Y.create(this.state.doc,r))}someProp(e,t){let o=this._props&&this._props[e],r;if(o!=null&&(r=t?t(o):o))return r;for(let i=0;i<this.directPlugins.length;i++){let l=this.directPlugins[i].props[e];if(l!=null&&(r=t?t(l):l))return r}let s=this.state.plugins;if(s)for(let i=0;i<s.length;i++){let l=s[i].props[e];if(l!=null&&(r=t?t(l):l))return r}}hasFocus(){if(He){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&l1(this.dom),Rt(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return f1(this,e)}coordsAtPos(e,t=1){return xu(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,o=-1){let r=this.docView.posFromDOM(e,t,o);if(r==null)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return y1(this,t||this.state,e)}pasteHTML(e,t){return zo(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return zo(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return fl(this,e)}destroy(){this.docView&&(K1(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Sl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Gy())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return J1(this,e)}domSelectionRange(){let e=this.domSelection();return e?Pe&&this.root.nodeType===11&&e1(this.dom.ownerDocument)==this.dom&&wk(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}bf.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function Sf(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let o in t)o=="class"?e.class+=" "+t[o]:o=="style"?e.style=(e.style?e.style+";":"")+t[o]:!e[o]&&o!="contenteditable"&&o!="nodeName"&&(e[o]=String(t[o]))}),e.translate||(e.translate="no"),[Fe.node(0,n.state.doc.content.size,e)]}function xf(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:Fe.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Cf(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Ak(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function Ef(n){let e=Object.create(null);function t(o){for(let r in o)Object.prototype.hasOwnProperty.call(e,r)||(e[r]=o[r])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Bk(n,e){let t=0,o=0;for(let r in n){if(n[r]!=e[r])return!0;t++}for(let r in e)o++;return t!=o}function vf(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}for(var tn={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Wr={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Ik=typeof navigator<"u"&&/Mac/.test(navigator.platform),Ok=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Ie=0;Ie<10;Ie++)tn[48+Ie]=tn[96+Ie]=String(Ie);for(var Ie=1;Ie<=24;Ie++)tn[Ie+111]="F"+Ie;for(var Ie=65;Ie<=90;Ie++)tn[Ie]=String.fromCharCode(Ie+32),Wr[Ie]=String.fromCharCode(Ie);for(var Cl in tn)Wr.hasOwnProperty(Cl)||(Wr[Cl]=tn[Cl]);function _k(n){var e=Ik&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Ok&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Wr:tn)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const Dk=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),Rk=typeof navigator<"u"&&/Win/.test(navigator.platform);function Pk(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let o,r,s,i;for(let l=0;l<e.length-1;l++){let c=e[l];if(/^(cmd|meta|m)$/i.test(c))i=!0;else if(/^a(lt)?$/i.test(c))o=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))s=!0;else if(/^mod$/i.test(c))Dk?i=!0:r=!0;else throw new Error("Unrecognized modifier name: "+c)}return o&&(t="Alt-"+t),r&&(t="Ctrl-"+t),i&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function Lk(n){let e=Object.create(null);for(let t in n)e[Pk(t)]=n[t];return e}function El(n,e,t=!0){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t&&e.shiftKey&&(n="Shift-"+n),n}function Vk(n){return new pe({props:{handleKeyDown:Tf(n)}})}function Tf(n){let e=Lk(n);return function(t,o){let r=_k(o),s,i=e[El(r,o)];if(i&&i(t.state,t.dispatch,t))return!0;if(r.length==1&&r!=" "){if(o.shiftKey){let l=e[El(r,o,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((o.altKey||o.metaKey||o.ctrlKey)&&!(Rk&&o.ctrlKey&&o.altKey)&&(s=tn[o.keyCode])&&s!=r){let l=e[El(s,o)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var $k=Object.defineProperty,vl=(n,e)=>{for(var t in e)$k(n,t,{get:e[t],enumerable:!0})};function Kr(n){const{state:e,transaction:t}=n;let{selection:o}=t,{doc:r}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return o},get doc(){return r},get tr(){return o=t.selection,r=t.doc,s=t.storedMarks,t}}}var qr=class{constructor(n){this.editor=n.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=n.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:n,editor:e,state:t}=this,{view:o}=e,{tr:r}=t,s=this.buildProps(r);return Object.fromEntries(Object.entries(n).map(([i,l])=>[i,(...d)=>{const u=l(...d)(s);return!r.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(r),u}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(n,e=!0){const{rawCommands:t,editor:o,state:r}=this,{view:s}=o,i=[],l=!!n,c=n||r.tr,d=()=>(!l&&e&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(c),i.every(f=>f===!0)),u={...Object.fromEntries(Object.entries(t).map(([f,h])=>[f,(...m)=>{const g=this.buildProps(c,e),y=h(...m)(g);return i.push(y),u}])),run:d};return u}createCan(n){const{rawCommands:e,state:t}=this,o=!1,r=n||t.tr,s=this.buildProps(r,o);return{...Object.fromEntries(Object.entries(e).map(([l,c])=>[l,(...d)=>c(...d)({...s,dispatch:void 0})])),chain:()=>this.createChain(r,o)}}buildProps(n,e=!0){const{rawCommands:t,editor:o,state:r}=this,{view:s}=o,i={tr:n,editor:o,view:s,state:Kr({state:r,transaction:n}),dispatch:e?()=>{}:void 0,chain:()=>this.createChain(n,e),can:()=>this.createCan(n),get commands(){return Object.fromEntries(Object.entries(t).map(([l,c])=>[l,(...d)=>c(...d)(i)]))}};return i}},Mf={};vl(Mf,{blur:()=>zk,clearContent:()=>Fk,clearNodes:()=>Hk,command:()=>jk,createParagraphNear:()=>Uk,cut:()=>Wk,deleteCurrentNode:()=>Kk,deleteNode:()=>qk,deleteRange:()=>Jk,deleteSelection:()=>Gk,enter:()=>Yk,exitCode:()=>Xk,extendMarkRange:()=>Qk,first:()=>Zk,focus:()=>tw,forEach:()=>nw,insertContent:()=>ow,insertContentAt:()=>iw,joinBackward:()=>cw,joinDown:()=>aw,joinForward:()=>dw,joinItemBackward:()=>uw,joinItemForward:()=>fw,joinTextblockBackward:()=>hw,joinTextblockForward:()=>pw,joinUp:()=>lw,keyboardShortcut:()=>gw,lift:()=>yw,liftEmptyBlock:()=>kw,liftListItem:()=>ww,newlineInCode:()=>bw,resetAttributes:()=>Sw,scrollIntoView:()=>xw,selectAll:()=>Cw,selectNodeBackward:()=>Ew,selectNodeForward:()=>vw,selectParentNode:()=>Tw,selectTextblockEnd:()=>Mw,selectTextblockStart:()=>Nw,setContent:()=>Aw,setMark:()=>Jw,setMeta:()=>Gw,setNode:()=>Yw,setNodeSelection:()=>Xw,setTextDirection:()=>Qw,setTextSelection:()=>Zw,sinkListItem:()=>eb,splitBlock:()=>tb,splitListItem:()=>nb,toggleList:()=>ob,toggleMark:()=>rb,toggleNode:()=>sb,toggleWrap:()=>ib,undoInputRule:()=>lb,unsetAllMarks:()=>ab,unsetMark:()=>cb,unsetTextDirection:()=>db,updateAttributes:()=>ub,wrapIn:()=>fb,wrapInList:()=>hb});var zk=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())==null||t.removeAllRanges())}),!0),Fk=(n=!0)=>({commands:e})=>e.setContent("",{emitUpdate:n}),Hk=()=>({state:n,tr:e,dispatch:t})=>{const{selection:o}=e,{ranges:r}=o;return t&&r.forEach(({$from:s,$to:i})=>{n.doc.nodesBetween(s.pos,i.pos,(l,c)=>{if(l.type.isText)return;const{doc:d,mapping:u}=e,f=d.resolve(u.map(c)),h=d.resolve(u.map(c+l.nodeSize)),p=f.blockRange(h);if(!p)return;const m=qn(p);if(l.type.isTextblock){const{defaultType:g}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(p.start,g)}(m||m===0)&&e.lift(p,m)})}),!0},jk=n=>e=>n(e),Uk=()=>({state:n,dispatch:e})=>iu(n,e),Wk=(n,e)=>({editor:t,tr:o})=>{const{state:r}=t,s=r.doc.slice(n.from,n.to);o.deleteRange(n.from,n.to);const i=o.mapping.map(e);return o.insert(i,s.content),o.setSelection(new Q(o.doc.resolve(Math.max(i-1,0)))),!0},Kk=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,o=t.$anchor.node();if(o.content.size>0)return!1;const r=n.selection.$anchor;for(let s=r.depth;s>0;s-=1)if(r.node(s).type===o.type){if(e){const l=r.before(s),c=r.after(s);n.delete(l,c).scrollIntoView()}return!0}return!1};function Ee(n,e){if(typeof n=="string"){if(!e.nodes[n])throw Error(`There is no node type named '${n}'. Maybe you forgot to add the extension?`);return e.nodes[n]}return n}var qk=n=>({tr:e,state:t,dispatch:o})=>{const r=Ee(n,t.schema),s=e.selection.$anchor;for(let i=s.depth;i>0;i-=1)if(s.node(i).type===r){if(o){const c=s.before(i),d=s.after(i);e.delete(c,d).scrollIntoView()}return!0}return!1},Jk=n=>({tr:e,dispatch:t})=>{const{from:o,to:r}=n;return t&&e.delete(o,r),!0},Gk=()=>({state:n,dispatch:e})=>Ji(n,e),Yk=()=>({commands:n})=>n.keyboardShortcut("Enter"),Xk=()=>({state:n,dispatch:e})=>Dy(n,e);function Tl(n){return Object.prototype.toString.call(n)==="[object RegExp]"}function Jr(n,e,t={strict:!0}){const o=Object.keys(e);return o.length?o.every(r=>t.strict?e[r]===n[r]:Tl(e[r])?e[r].test(n[r]):e[r]===n[r]):!0}function Nf(n,e,t={}){return n.find(o=>o.type===e&&Jr(Object.fromEntries(Object.keys(t).map(r=>[r,o.attrs[r]])),t))}function Af(n,e,t={}){return!!Nf(n,e,t)}function Ml(n,e,t){var o;if(!n||!e)return;let r=n.parent.childAfter(n.parentOffset);if((!r.node||!r.node.marks.some(u=>u.type===e))&&(r=n.parent.childBefore(n.parentOffset)),!r.node||!r.node.marks.some(u=>u.type===e)||(t=t||((o=r.node.marks[0])==null?void 0:o.attrs),!Nf([...r.node.marks],e,t)))return;let i=r.index,l=n.start()+r.offset,c=i+1,d=l+r.node.nodeSize;for(;i>0&&Af([...n.parent.child(i-1).marks],e,t);)i-=1,l-=n.parent.child(i).nodeSize;for(;c<n.parent.childCount&&Af([...n.parent.child(c).marks],e,t);)d+=n.parent.child(c).nodeSize,c+=1;return{from:l,to:d}}function Pt(n,e){if(typeof n=="string"){if(!e.marks[n])throw Error(`There is no mark type named '${n}'. Maybe you forgot to add the extension?`);return e.marks[n]}return n}var Qk=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const s=Pt(n,o.schema),{doc:i,selection:l}=t,{$from:c,from:d,to:u}=l;if(r){const f=Ml(c,s,e);if(f&&f.from<=d&&f.to>=u){const h=Q.create(i,f.from,f.to);t.setSelection(h)}}return!0},Zk=n=>e=>{const t=typeof n=="function"?n(e):n;for(let o=0;o<t.length;o+=1)if(t[o](e))return!0;return!1};function Bf(n){return n instanceof Q}function On(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function If(n,e=null){if(!e)return null;const t=ee.atStart(n),o=ee.atEnd(n);if(e==="start"||e===!0)return t;if(e==="end")return o;const r=t.from,s=o.to;return e==="all"?Q.create(n,On(0,r,s),On(n.content.size,r,s)):Q.create(n,On(e,r,s),On(e,r,s))}function Of(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function Gr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}function ew(){return typeof navigator<"u"?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var tw=(n=null,e={})=>({editor:t,view:o,tr:r,dispatch:s})=>{e={scrollIntoView:!0,...e};const i=()=>{(Gr()||Of())&&o.dom.focus(),ew()&&!Gr()&&!Of()&&o.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{t.isDestroyed||(o.focus(),e!=null&&e.scrollIntoView&&t.commands.scrollIntoView())})};try{if(o.hasFocus()&&n===null||n===!1)return!0}catch{return!1}if(s&&n===null&&!Bf(t.state.selection))return i(),!0;const l=If(r.doc,n)||t.state.selection,c=t.state.selection.eq(l);return s&&(c||r.setSelection(l),c&&r.storedMarks&&r.setStoredMarks(r.storedMarks),i()),!0},nw=(n,e)=>t=>n.every((o,r)=>e(o,{...t,index:r})),ow=(n,e)=>({tr:t,commands:o})=>o.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),_f=n=>{const e=n.childNodes;for(let t=e.length-1;t>=0;t-=1){const o=e[t];o.nodeType===3&&o.nodeValue&&/^(\n\s\s|\n)$/.test(o.nodeValue)?n.removeChild(o):o.nodeType===1&&_f(o)}return n};function Ho(n){if(typeof window>"u")throw new Error("[tiptap error]: there is no window object available, so this function cannot be used");const e=`<body>${n}</body>`,t=new window.DOMParser().parseFromString(e,"text/html").body;return _f(t)}function jo(n,e,t){if(n instanceof At||n instanceof P)return n;t={slice:!0,parseOptions:{},...t};const o=typeof n=="object"&&n!==null,r=typeof n=="string";if(o)try{if(Array.isArray(n)&&n.length>0)return P.fromArray(n.map(l=>e.nodeFromJSON(l)));const i=e.nodeFromJSON(n);return t.errorOnInvalidContent&&i.check(),i}catch(s){if(t.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",n,"Error:",s),jo("",e,t)}if(r){if(t.errorOnInvalidContent){let i=!1,l="";const c=new yd({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:d=>(i=!0,l=typeof d=="string"?d:d.outerHTML,null)}]}})});if(t.slice?Bt.fromSchema(c).parseSlice(Ho(n),t.parseOptions):Bt.fromSchema(c).parse(Ho(n),t.parseOptions),t.errorOnInvalidContent&&i)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=Bt.fromSchema(e);return t.slice?s.parseSlice(Ho(n),t.parseOptions).content:s.parse(Ho(n),t.parseOptions)}return jo("",e,t)}function rw(n,e,t){const o=n.steps.length-1;if(o<e)return;const r=n.steps[o];if(!(r instanceof Se||r instanceof xe))return;const s=n.mapping.maps[o];let i=0;s.forEach((l,c,d,u)=>{i===0&&(i=u)}),n.setSelection(ee.near(n.doc.resolve(i),t))}var sw=n=>!("type"in n),iw=(n,e,t)=>({tr:o,dispatch:r,editor:s})=>{var i;if(r){t={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...t};let l;const c=y=>{s.emit("contentError",{editor:s,error:y,disableCollaboration:()=>{"collaboration"in s.storage&&typeof s.storage.collaboration=="object"&&s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},d={preserveWhitespace:"full",...t.parseOptions};if(!t.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{jo(e,s.schema,{parseOptions:d,errorOnInvalidContent:!0})}catch(y){c(y)}try{l=jo(e,s.schema,{parseOptions:d,errorOnInvalidContent:(i=t.errorOnInvalidContent)!=null?i:s.options.enableContentCheck})}catch(y){return c(y),!1}let{from:u,to:f}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},h=!0,p=!0;if((sw(l)?l:[l]).forEach(y=>{y.check(),h=h?y.isText&&y.marks.length===0:!1,p=p?y.isBlock:!1}),u===f&&p){const{parent:y}=o.doc.resolve(u);y.isTextblock&&!y.type.spec.code&&!y.childCount&&(u-=1,f+=1)}let g;if(h){if(Array.isArray(e))g=e.map(y=>y.text||"").join("");else if(e instanceof P){let y="";e.forEach(k=>{k.text&&(y+=k.text)}),g=y}else typeof e=="object"&&e&&e.text?g=e.text:g=e;o.insertText(g,u,f)}else{g=l;const y=o.doc.resolve(u),k=y.node(),x=y.parentOffset===0,b=k.isText||k.isTextblock,S=k.content.size>0;x&&b&&S&&(u=Math.max(0,u-1)),o.replaceWith(u,f,g)}t.updateSelection&&rw(o,o.steps.length-1,-1),t.applyInputRules&&o.setMeta("applyInputRules",{from:u,text:g}),t.applyPasteRules&&o.setMeta("applyPasteRules",{from:u,text:g})}return!0},lw=()=>({state:n,dispatch:e})=>Iy(n,e),aw=()=>({state:n,dispatch:e})=>Oy(n,e),cw=()=>({state:n,dispatch:e})=>Zd(n,e),dw=()=>({state:n,dispatch:e})=>ou(n,e),uw=()=>({state:n,dispatch:e,tr:t})=>{try{const o=_r(n.doc,n.selection.$from.pos,-1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},fw=()=>({state:n,dispatch:e,tr:t})=>{try{const o=_r(n.doc,n.selection.$from.pos,1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},hw=()=>({state:n,dispatch:e})=>Ay(n,e),pw=()=>({state:n,dispatch:e})=>By(n,e);function Df(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function mw(n){const e=n.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let o,r,s,i;for(let l=0;l<e.length-1;l+=1){const c=e[l];if(/^(cmd|meta|m)$/i.test(c))i=!0;else if(/^a(lt)?$/i.test(c))o=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))s=!0;else if(/^mod$/i.test(c))Gr()||Df()?i=!0:r=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return o&&(t=`Alt-${t}`),r&&(t=`Ctrl-${t}`),i&&(t=`Meta-${t}`),s&&(t=`Shift-${t}`),t}var gw=n=>({editor:e,view:t,tr:o,dispatch:r})=>{const s=mw(n).split(/-(?!$)/),i=s.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),l=new KeyboardEvent("keydown",{key:i==="Space"?" ":i,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),c=e.captureTransaction(()=>{t.someProp("handleKeyDown",d=>d(t,l))});return c==null||c.steps.forEach(d=>{const u=d.map(o.mapping);u&&r&&o.maybeStep(u)}),!0};function Uo(n,e,t={}){const{from:o,to:r,empty:s}=n.selection,i=e?Ee(e,n.schema):null,l=[];n.doc.nodesBetween(o,r,(f,h)=>{if(f.isText)return;const p=Math.max(o,h),m=Math.min(r,h+f.nodeSize);l.push({node:f,from:p,to:m})});const c=r-o,d=l.filter(f=>i?i.name===f.node.type.name:!0).filter(f=>Jr(f.node.attrs,t,{strict:!1}));return s?!!d.length:d.reduce((f,h)=>f+h.to-h.from,0)>=c}var yw=(n,e={})=>({state:t,dispatch:o})=>{const r=Ee(n,t.schema);return Uo(t,r,e)?_y(t,o):!1},kw=()=>({state:n,dispatch:e})=>lu(n,e),ww=n=>({state:e,dispatch:t})=>{const o=Ee(n,e.schema);return Wy(o)(e,t)},bw=()=>({state:n,dispatch:e})=>su(n,e);function Yr(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function Rf(n,e){const t=typeof e=="string"?[e]:e;return Object.keys(n).reduce((o,r)=>(t.includes(r)||(o[r]=n[r]),o),{})}var Sw=(n,e)=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=Yr(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=Ee(n,o.schema)),l==="mark"&&(i=Pt(n,o.schema));let c=!1;return t.selection.ranges.forEach(d=>{o.doc.nodesBetween(d.$from.pos,d.$to.pos,(u,f)=>{s&&s===u.type&&(c=!0,r&&t.setNodeMarkup(f,void 0,Rf(u.attrs,e))),i&&u.marks.length&&u.marks.forEach(h=>{i===h.type&&(c=!0,r&&t.addMark(f,f+u.nodeSize,i.create(Rf(h.attrs,e))))})})}),c},xw=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),Cw=()=>({tr:n,dispatch:e})=>{if(e){const t=new qe(n.doc);n.setSelection(t)}return!0},Ew=()=>({state:n,dispatch:e})=>tu(n,e),vw=()=>({state:n,dispatch:e})=>ru(n,e),Tw=()=>({state:n,dispatch:e})=>Ly(n,e),Mw=()=>({state:n,dispatch:e})=>zy(n,e),Nw=()=>({state:n,dispatch:e})=>$y(n,e);function Nl(n,e,t={},o={}){return jo(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:o.errorOnInvalidContent})}var Aw=(n,{errorOnInvalidContent:e,emitUpdate:t=!0,parseOptions:o={}}={})=>({editor:r,tr:s,dispatch:i,commands:l})=>{const{doc:c}=s;if(o.preserveWhitespace!=="full"){const d=Nl(n,r.schema,o,{errorOnInvalidContent:e??r.options.enableContentCheck});return i&&s.replaceWith(0,c.content.size,d).setMeta("preventUpdate",!t),!0}return i&&s.setMeta("preventUpdate",!t),l.insertContentAt({from:0,to:c.content.size},n,{parseOptions:o,errorOnInvalidContent:e??r.options.enableContentCheck})};function Pf(n,e){const t=Pt(e,n.schema),{from:o,to:r,empty:s}=n.selection,i=[];s?(n.storedMarks&&i.push(...n.storedMarks),i.push(...n.selection.$head.marks())):n.doc.nodesBetween(o,r,c=>{i.push(...c.marks)});const l=i.find(c=>c.type.name===t.name);return l?{...l.attrs}:{}}function Lf(n,e){const t=new jd(n);return e.forEach(o=>{o.steps.forEach(r=>{t.step(r)})}),t}function Bw(n){for(let e=0;e<n.edgeCount;e+=1){const{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}function Iw(n,e,t){const o=[];return n.nodesBetween(e.from,e.to,(r,s)=>{t(r)&&o.push({node:r,pos:s})}),o}function Ow(n,e){for(let t=n.depth;t>0;t-=1){const o=n.node(t);if(e(o))return{pos:t>0?n.before(t):0,start:n.start(t),depth:t,node:o}}}function Al(n){return e=>Ow(e.$from,n)}function q(n,e,t){return n.config[e]===void 0&&n.parent?q(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?q(n.parent,e,t):null}):n.config[e]}function Bl(n){return n.map(e=>{const t={name:e.name,options:e.options,storage:e.storage},o=q(e,"addExtensions",t);return o?[e,...Bl(o())]:e}).flat(10)}function Xr(n,e){const t=xn.fromSchema(e).serializeFragment(n),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(t),r.innerHTML}function Vf(n){return typeof n=="function"}function ae(n,e=void 0,...t){return Vf(n)?e?n.bind(e)(...t):n(...t):n}function _w(n={}){return Object.keys(n).length===0&&n.constructor===Object}function so(n){const e=n.filter(r=>r.type==="extension"),t=n.filter(r=>r.type==="node"),o=n.filter(r=>r.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:o}}function $f(n){const e=[],{nodeExtensions:t,markExtensions:o}=so(n),r=[...t,...o],s={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},i=t.filter(d=>d.name!=="text").map(d=>d.name),l=o.map(d=>d.name),c=[...i,...l];return n.forEach(d=>{const u={name:d.name,options:d.options,storage:d.storage,extensions:r},f=q(d,"addGlobalAttributes",u);if(!f)return;f().forEach(p=>{let m;Array.isArray(p.types)?m=p.types:p.types==="*"?m=c:p.types==="nodes"?m=i:p.types==="marks"?m=l:m=[],m.forEach(g=>{Object.entries(p.attributes).forEach(([y,k])=>{e.push({type:g,name:y,attribute:{...s,...k}})})})})}),r.forEach(d=>{const u={name:d.name,options:d.options,storage:d.storage},f=q(d,"addAttributes",u);if(!f)return;const h=f();Object.entries(h).forEach(([p,m])=>{const g={...s,...m};typeof(g==null?void 0:g.default)=="function"&&(g.default=g.default()),g!=null&&g.isRequired&&(g==null?void 0:g.default)===void 0&&delete g.default,e.push({type:d.name,name:p,attribute:g})})}),e}function nn(...n){return n.filter(e=>!!e).reduce((e,t)=>{const o={...e};return Object.entries(t).forEach(([r,s])=>{if(!o[r]){o[r]=s;return}if(r==="class"){const l=s?String(s).split(" "):[],c=o[r]?o[r].split(" "):[],d=l.filter(u=>!c.includes(u));o[r]=[...c,...d].join(" ")}else if(r==="style"){const l=s?s.split(";").map(u=>u.trim()).filter(Boolean):[],c=o[r]?o[r].split(";").map(u=>u.trim()).filter(Boolean):[],d=new Map;c.forEach(u=>{const[f,h]=u.split(":").map(p=>p.trim());d.set(f,h)}),l.forEach(u=>{const[f,h]=u.split(":").map(p=>p.trim());d.set(f,h)}),o[r]=Array.from(d.entries()).map(([u,f])=>`${u}: ${f}`).join("; ")}else o[r]=s}),o},{})}function Qr(n,e){return e.filter(t=>t.type===n.type.name).filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(n.attrs)||{}:{[t.name]:n.attrs[t.name]}).reduce((t,o)=>nn(t,o),{})}function Dw(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function zf(n,e){return"style"in n?n:{...n,getAttrs:t=>{const o=n.getAttrs?n.getAttrs(t):n.attrs;if(o===!1)return!1;const r=e.reduce((s,i)=>{const l=i.attribute.parseHTML?i.attribute.parseHTML(t):Dw(t.getAttribute(i.name));return l==null?s:{...s,[i.name]:l}},{});return{...o,...r}}}}function Ff(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&_w(t)?!1:t!=null))}function Hf(n){var e,t;const o={};return!((e=n==null?void 0:n.attribute)!=null&&e.isRequired)&&"default"in((n==null?void 0:n.attribute)||{})&&(o.default=n.attribute.default),((t=n==null?void 0:n.attribute)==null?void 0:t.validate)!==void 0&&(o.validate=n.attribute.validate),[n.name,o]}function jf(n,e){var t;const o=$f(n),{nodeExtensions:r,markExtensions:s}=so(n),i=(t=r.find(d=>q(d,"topNode")))==null?void 0:t.name,l=Object.fromEntries(r.map(d=>{const u=o.filter(k=>k.type===d.name),f={name:d.name,options:d.options,storage:d.storage,editor:e},h=n.reduce((k,x)=>{const b=q(x,"extendNodeSchema",f);return{...k,...b?b(d):{}}},{}),p=Ff({...h,content:ae(q(d,"content",f)),marks:ae(q(d,"marks",f)),group:ae(q(d,"group",f)),inline:ae(q(d,"inline",f)),atom:ae(q(d,"atom",f)),selectable:ae(q(d,"selectable",f)),draggable:ae(q(d,"draggable",f)),code:ae(q(d,"code",f)),whitespace:ae(q(d,"whitespace",f)),linebreakReplacement:ae(q(d,"linebreakReplacement",f)),defining:ae(q(d,"defining",f)),isolating:ae(q(d,"isolating",f)),attrs:Object.fromEntries(u.map(Hf))}),m=ae(q(d,"parseHTML",f));m&&(p.parseDOM=m.map(k=>zf(k,u)));const g=q(d,"renderHTML",f);g&&(p.toDOM=k=>g({node:k,HTMLAttributes:Qr(k,u)}));const y=q(d,"renderText",f);return y&&(p.toText=y),[d.name,p]})),c=Object.fromEntries(s.map(d=>{const u=o.filter(y=>y.type===d.name),f={name:d.name,options:d.options,storage:d.storage,editor:e},h=n.reduce((y,k)=>{const x=q(k,"extendMarkSchema",f);return{...y,...x?x(d):{}}},{}),p=Ff({...h,inclusive:ae(q(d,"inclusive",f)),excludes:ae(q(d,"excludes",f)),group:ae(q(d,"group",f)),spanning:ae(q(d,"spanning",f)),code:ae(q(d,"code",f)),attrs:Object.fromEntries(u.map(Hf))}),m=ae(q(d,"parseHTML",f));m&&(p.parseDOM=m.map(y=>zf(y,u)));const g=q(d,"renderHTML",f);return g&&(p.toDOM=y=>g({mark:y,HTMLAttributes:Qr(y,u)})),[d.name,p]}));return new yd({topNode:i,nodes:l,marks:c})}function Rw(n){const e=n.filter((t,o)=>n.indexOf(t)!==o);return Array.from(new Set(e))}function Wo(n){return n.sort((t,o)=>{const r=q(t,"priority")||100,s=q(o,"priority")||100;return r>s?-1:r<s?1:0})}function Il(n){const e=Wo(Bl(n)),t=Rw(e.map(o=>o.name));return t.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${t.map(o=>`'${o}'`).join(", ")}]. This can lead to issues.`),e}function Uf(n,e){const t=Il(n);return jf(t,e)}function Pw(n,e){const t=Uf(e),o=At.fromJSON(t,n);return Xr(o.content,t)}function Lw(n,e){const t=Uf(e),o=Ho(n);return Bt.fromSchema(t).parse(o).toJSON()}function Wf(n,e,t){const{from:o,to:r}=e,{blockSeparator:s=`
|
|
10
|
+
`))),0,0),n.someProp("transformPasted",h=>{l=h(l,n,!0)}),l;let f=n.someProp("clipboardTextParser",h=>h(e,r,o,n));if(f)l=f;else{let h=r.marks(),{schema:p}=n.state,m=xn.fromSchema(p);i=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(g=>{let y=i.appendChild(document.createElement("p"));g&&y.appendChild(m.serializeNode(p.text(g,h)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),i=z1(t),Do&&F1(i);let d=i&&i.querySelector("[data-pm-slice]"),u=d&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(d.getAttribute("data-pm-slice")||"");if(u&&u[3])for(let f=+u[3];f>0;f--){let h=i.firstChild;for(;h&&h.nodeType!=1;)h=h.nextSibling;if(!h)break;i=h}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Bt.fromSchema(n.state.schema)).parseSlice(i,{preserveWhitespace:!!(c||u),context:r,ruleFromNode(h){return h.nodeName=="BR"&&!h.nextSibling&&h.parentNode&&!L1.test(h.parentNode.nodeName)?{ignore:!0}:null}})),u)l=H1(Zu(l,+u[1],+u[2]),u[4]);else if(l=U.maxOpen(V1(l.content,r),!0),l.openStart||l.openEnd){let f=0,h=0;for(let p=l.content.firstChild;f<l.openStart&&!p.type.spec.isolating;f++,p=p.firstChild);for(let p=l.content.lastChild;h<l.openEnd&&!p.type.spec.isolating;h++,p=p.lastChild);l=Zu(l,f,h)}return n.someProp("transformPasted",f=>{l=f(l,n,c)}),l}const L1=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function V1(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let r=e.node(t).contentMatchAt(e.index(t)),s,i=[];if(n.forEach(l=>{if(!i)return;let c=r.findWrapping(l.type),d;if(!c)return i=null;if(d=i.length&&s.length&&Xu(c,s,l,i[i.length-1],0))i[i.length-1]=d;else{i.length&&(i[i.length-1]=Qu(i[i.length-1],s.length));let u=Yu(l,c);i.push(u),r=r.matchType(u.type),s=c}}),i)return P.from(i)}return n}function Yu(n,e,t=0){for(let o=e.length-1;o>=t;o--)n=e[o].create(null,P.from(n));return n}function Xu(n,e,t,o,r){if(r<n.length&&r<e.length&&n[r]==e[r]){let s=Xu(n,e,t,o.lastChild,r+1);if(s)return o.copy(o.content.replaceChild(o.childCount-1,s));if(o.contentMatchAt(o.childCount).matchType(r==n.length-1?t.type:n[r+1]))return o.copy(o.content.append(P.from(Yu(t,n,r+1))))}}function Qu(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,Qu(n.lastChild,e-1)),o=n.contentMatchAt(n.childCount).fillBefore(P.empty,!0);return n.copy(t.append(o))}function hl(n,e,t,o,r,s){let i=e<0?n.firstChild:n.lastChild,l=i.content;return n.childCount>1&&(s=0),r<o-1&&(l=hl(l,e,t,o,r+1,s)),r>=t&&(l=e<0?i.contentMatchAt(0).fillBefore(l,s<=r).append(l):l.append(i.contentMatchAt(i.childCount).fillBefore(P.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,i.copy(l))}function Zu(n,e,t){return e<n.openStart&&(n=new U(hl(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new U(hl(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const ef={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};let tf=null;function nf(){return tf||(tf=document.implementation.createHTMLDocument("title"))}let pl=null;function $1(n){let e=window.trustedTypes;return e?(pl||(pl=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),pl.createHTML(n)):n}function z1(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=nf().createElement("div"),o=/<([a-z][^>\s]+)/i.exec(n),r;if((r=o&&ef[o[1].toLowerCase()])&&(n=r.map(s=>"<"+s+">").join("")+n+r.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=$1(n),r)for(let s=0;s<r.length;s++)t=t.querySelector(r[s])||t;return t}function F1(n){let e=n.querySelectorAll(Be?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let o=e[t];o.childNodes.length==1&&o.textContent==" "&&o.parentNode&&o.parentNode.replaceChild(n.ownerDocument.createTextNode(" "),o)}}function H1(n,e){if(!n.size)return n;let t=n.content.firstChild.type.schema,o;try{o=JSON.parse(e)}catch{return n}let{content:r,openStart:s,openEnd:i}=n;for(let l=o.length-2;l>=0;l-=2){let c=t.nodes[o[l]];if(!c||c.hasRequiredAttrs())break;r=P.from(c.create(o[l+1],r)),s++,i++}return new U(r,s,i)}const $e={},ze={},j1={touchstart:!0,touchmove:!0};class U1{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:"",button:0},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastChromeDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.badSafariComposition=!1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}}function W1(n){for(let e in $e){let t=$e[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=o=>{q1(n,o)&&!gl(n,o)&&(n.editable||!(o.type in ze))&&t(n,o)},j1[e]?{passive:!0}:void 0)}Pe&&n.dom.addEventListener("input",()=>null),ml(n)}function Qt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function K1(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function ml(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=o=>gl(n,o))})}function gl(n,e){return n.someProp("handleDOMEvents",t=>{let o=t[e.type];return o?o(n,e)||e.defaultPrevented:!1})}function q1(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function J1(n,e){!gl(n,e)&&$e[e.type]&&(n.editable||!(e.type in ze))&&$e[e.type](n,e)}ze.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!rf(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(_t&&Be&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),eo&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let o=Date.now();n.input.lastIOSEnter=o,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==o&&(n.someProp("handleKeyDown",r=>r(n,Mn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",o=>o(n,t))||P1(n,t)?t.preventDefault():Qt(n,"key")},ze.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)},ze.keypress=(n,e)=>{let t=e;if(rf(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Qe&&t.metaKey)return;if(n.someProp("handleKeyPress",r=>r(n,t))){t.preventDefault();return}let o=n.state.selection;if(!(o instanceof Q)||!o.$from.sameParent(o.$to)){let r=String.fromCharCode(t.charCode),s=()=>n.state.tr.insertText(r).scrollIntoView();!/[\r\n]/.test(r)&&!n.someProp("handleTextInput",i=>i(n,o.$from.pos,o.$to.pos,r,s))&&n.dispatch(s()),t.preventDefault()}};function Fr(n){return{left:n.clientX,top:n.clientY}}function G1(n,e){let t=e.x-n.clientX,o=e.y-n.clientY;return t*t+o*o<100}function yl(n,e,t,o,r){if(o==-1)return!1;let s=n.state.doc.resolve(o);for(let i=s.depth+1;i>0;i--)if(n.someProp(e,l=>i>s.depth?l(n,t,s.nodeAfter,s.before(i),r,!0):l(n,t,s.node(i),s.before(i),r,!1)))return!0;return!1}function oo(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let o=n.state.tr.setSelection(e);o.setMeta("pointer",!0),n.dispatch(o)}function Y1(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),o=t.nodeAfter;return o&&o.isAtom&&Y.isSelectable(o)?(oo(n,new Y(t)),!0):!1}function X1(n,e){if(e==-1)return!1;let t=n.state.selection,o,r;t instanceof Y&&(o=t.node);let s=n.state.doc.resolve(e);for(let i=s.depth+1;i>0;i--){let l=i>s.depth?s.nodeAfter:s.node(i);if(Y.isSelectable(l)){o&&t.$from.depth>0&&i>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?r=s.before(t.$from.depth):r=s.before(i);break}}return r!=null?(oo(n,Y.create(n.state.doc,r)),!0):!1}function Q1(n,e,t,o,r){return yl(n,"handleClickOn",e,t,o)||n.someProp("handleClick",s=>s(n,e,o))||(r?X1(n,t):Y1(n,t))}function Z1(n,e,t,o){return yl(n,"handleDoubleClickOn",e,t,o)||n.someProp("handleDoubleClick",r=>r(n,e,o))}function ek(n,e,t,o){return yl(n,"handleTripleClickOn",e,t,o)||n.someProp("handleTripleClick",r=>r(n,e,o))||tk(n,t,o)}function tk(n,e,t){if(t.button!=0)return!1;let o=n.state.doc;if(e==-1)return o.inlineContent?(oo(n,Q.create(o,0,o.content.size)),!0):!1;let r=o.resolve(e);for(let s=r.depth+1;s>0;s--){let i=s>r.depth?r.nodeAfter:r.node(s),l=r.before(s);if(i.inlineContent)oo(n,Q.create(o,l+1,l+1+i.content.size));else if(Y.isSelectable(i))oo(n,Y.create(o,l));else continue;return!0}}function kl(n){return Hr(n)}const of=Qe?"metaKey":"ctrlKey";$e.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let o=kl(n),r=Date.now(),s="singleClick";r-n.input.lastClick.time<500&&G1(t,n.input.lastClick)&&!t[of]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:r,x:t.clientX,y:t.clientY,type:s,button:t.button};let i=n.posAtCoords(Fr(t));i&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new nk(n,i,t,!!o)):(s=="doubleClick"?Z1:ek)(n,i.pos,i.inside,t)?t.preventDefault():Qt(n,"pointer"))};class nk{constructor(e,t,o,r){this.view=e,this.pos=t,this.event=o,this.flushed=r,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!o[of],this.allowDefault=o.shiftKey;let s,i;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),i=t.inside;else{let u=e.state.doc.resolve(t.pos);s=u.parent,i=u.depth?u.before():0}const l=r?null:o.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.nodeDOM.nodeType==1?c.nodeDOM:null;let{selection:d}=e.state;(o.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||d instanceof Y&&d.from<=i&&d.to>i)&&(this.mightDrag={node:s,pos:i,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Xe&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),Qt(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>Rt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(Fr(e))),this.updateAllowDefault(e),this.allowDefault||!t?Qt(this.view,"pointer"):Q1(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Pe&&this.mightDrag&&!this.mightDrag.node.isAtom||Be&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(oo(this.view,ee.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Qt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Qt(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}}$e.touchstart=n=>{n.input.lastTouch=Date.now(),kl(n),Qt(n,"pointer")},$e.touchmove=n=>{n.input.lastTouch=Date.now(),Qt(n,"pointer")},$e.contextmenu=n=>kl(n);function rf(n,e){return n.composing?!0:Pe&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const ok=_t?5e3:-1;ze.compositionstart=ze.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof Q&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(o=>o.type.spec.inclusive===!1)||Be&&mu&&rk(n)))n.markCursor=n.state.storedMarks||t.marks(),Hr(n,!0),n.markCursor=null;else if(Hr(n,!e.selection.empty),Xe&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let o=n.domSelectionRange();for(let r=o.focusNode,s=o.focusOffset;r&&r.nodeType==1&&s!=0;){let i=s<0?r.lastChild:r.childNodes[s-1];if(!i)break;if(i.nodeType==3){let l=n.domSelection();l&&l.collapse(i,i.nodeValue.length);break}else r=i,s=-1}}n.input.composing=!0}sf(n,ok)};function rk(n){let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let o=e.childNodes[t];return o.nodeType==1&&o.contentEditable=="false"}ze.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.badSafariComposition?n.domObserver.forceFlush():n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,sf(n,20))};function sf(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Hr(n),e))}function lf(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=ik());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function sk(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=Xy(e.focusNode,e.focusOffset),o=Qy(e.focusNode,e.focusOffset);if(t&&o&&t!=o){let r=o.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||o==s)return s;if(!r||!r.isText(o.nodeValue))return o;if(n.input.compositionNode==o){let i=t.pmViewDesc;if(!(!i||!i.isText(t.nodeValue)))return o}}return t||o}function ik(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Hr(n,e=!1){if(!(_t&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),lf(n),e||n.docView&&n.docView.dirty){let t=ll(n),o=n.state.selection;return t&&!t.eq(o)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!o.$from.node(o.$from.sharedDepth(o.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function lk(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let o=getSelection(),r=document.createRange();r.selectNodeContents(e),n.dom.blur(),o.removeAllRanges(),o.addRange(r),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}const $o=He&&Jt<15||eo&&n1<604;$e.copy=ze.cut=(n,e)=>{let t=e,o=n.state.selection,r=t.type=="cut";if(o.empty)return;let s=$o?null:t.clipboardData,i=o.content(),{dom:l,text:c}=fl(n,i);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):lk(n,l),r&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function ak(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function ck(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,o=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(o.contentEditable="true"),o.style.cssText="position: fixed; left: -10000px; top: 10px",o.focus();let r=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),o.parentNode&&o.parentNode.removeChild(o),t?zo(n,o.value,null,r,e):zo(n,o.textContent,o.innerHTML,r,e)},50)}function zo(n,e,t,o,r){let s=Gu(n,e,t,o,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,r,s||U.empty)))return!0;if(!s)return!1;let i=ak(s),l=i?n.state.tr.replaceSelectionWith(i,o):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function af(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ze.paste=(n,e)=>{let t=e;if(n.composing&&!_t)return;let o=$o?null:t.clipboardData,r=n.input.shiftKey&&n.input.lastKeyCode!=45;o&&zo(n,af(o),o.getData("text/html"),r,t)?t.preventDefault():ck(n,t)};class cf{constructor(e,t,o){this.slice=e,this.move=t,this.node=o}}const dk=Qe?"altKey":"ctrlKey";function df(n,e){let t=n.someProp("dragCopies",o=>!o(e));return t??!e[dk]}$e.dragstart=(n,e)=>{let t=e,o=n.input.mouseDown;if(o&&o.done(),!t.dataTransfer)return;let r=n.state.selection,s=r.empty?null:n.posAtCoords(Fr(t)),i;if(!(s&&s.pos>=r.from&&s.pos<=(r instanceof Y?r.to-1:r.to))){if(o&&o.mightDrag)i=Y.create(n.state.doc,o.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(i=Y.create(n.state.doc,f.posBefore))}}let l=(i||n.state.selection).content(),{dom:c,text:d,slice:u}=fl(n,l);(!t.dataTransfer.files.length||!Be||pu>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData($o?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",$o||t.dataTransfer.setData("text/plain",d),n.dragging=new cf(u,df(n,t),i)},$e.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)},ze.dragover=ze.dragenter=(n,e)=>e.preventDefault(),ze.drop=(n,e)=>{try{uk(n,e,n.dragging)}finally{n.dragging=null}};function uk(n,e,t){if(!e.dataTransfer)return;let o=n.posAtCoords(Fr(e));if(!o)return;let r=n.state.doc.resolve(o.pos),s=t&&t.slice;s?n.someProp("transformPasted",p=>{s=p(s,n,!1)}):s=Gu(n,af(e.dataTransfer),$o?null:e.dataTransfer.getData("text/html"),!1,r);let i=!!(t&&df(n,e));if(n.someProp("handleDrop",p=>p(n,e,s||U.empty,i))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Vd(n.state.doc,r.pos,s):r.pos;l==null&&(l=r.pos);let c=n.state.tr;if(i){let{node:p}=t;p?p.replace(c):c.deleteSelection()}let d=c.mapping.map(l),u=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=c.doc;if(u?c.replaceRangeWith(d,d,s.content.firstChild):c.replaceRange(d,d,s),c.doc.eq(f))return;let h=c.doc.resolve(d);if(u&&Y.isSelectable(s.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new Y(h));else{let p=c.mapping.map(l);c.mapping.maps[c.mapping.maps.length-1].forEach((m,g,y,k)=>p=k),c.setSelection(cl(n,h,c.doc.resolve(p)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))}$e.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&Rt(n)},20))},$e.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)},$e.beforeinput=(n,e)=>{if(Be&&_t&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:o}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=o||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,Mn(8,"Backspace")))))return;let{$cursor:r}=n.state.selection;r&&r.pos>0&&n.dispatch(n.state.tr.delete(r.pos-1,r.pos).scrollIntoView())},50)}};for(let n in ze)$e[n]=ze[n];function Fo(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}class jr{constructor(e,t){this.toDOM=e,this.spec=t||Bn,this.side=this.spec.side||0}map(e,t,o,r){let{pos:s,deleted:i}=e.mapResult(t.from+r,this.side<0?-1:1);return i?null:new Fe(s-o,s-o,this)}valid(){return!0}eq(e){return this==e||e instanceof jr&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Fo(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Zt{constructor(e,t){this.attrs=e,this.spec=t||Bn}map(e,t,o,r){let s=e.map(t.from+r,this.spec.inclusiveStart?-1:1)-o,i=e.map(t.to+r,this.spec.inclusiveEnd?1:-1)-o;return s>=i?null:new Fe(s,i,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Zt&&Fo(this.attrs,e.attrs)&&Fo(this.spec,e.spec)}static is(e){return e.type instanceof Zt}destroy(){}}class wl{constructor(e,t){this.attrs=e,this.spec=t||Bn}map(e,t,o,r){let s=e.mapResult(t.from+r,1);if(s.deleted)return null;let i=e.mapResult(t.to+r,-1);return i.deleted||i.pos<=s.pos?null:new Fe(s.pos-o,i.pos-o,this)}valid(e,t){let{index:o,offset:r}=e.content.findIndex(t.from),s;return r==t.from&&!(s=e.child(o)).isText&&r+s.nodeSize==t.to}eq(e){return this==e||e instanceof wl&&Fo(this.attrs,e.attrs)&&Fo(this.spec,e.spec)}destroy(){}}class Fe{constructor(e,t,o){this.from=e,this.to=t,this.type=o}copy(e,t){return new Fe(e,t,this.type)}eq(e,t=0){return this.type.eq(e.type)&&this.from+t==e.from&&this.to+t==e.to}map(e,t,o){return this.type.map(e,this,t,o)}static widget(e,t,o){return new Fe(e,e,new jr(t,o))}static inline(e,t,o,r){return new Fe(e,t,new Zt(o,r))}static node(e,t,o,r){return new Fe(e,t,new wl(o,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof Zt}get widget(){return this.type instanceof jr}}const ro=[],Bn={};class he{constructor(e,t){this.local=e.length?e:ro,this.children=t.length?t:ro}static create(e,t){return t.length?Ur(t,e,0,Bn):Le}find(e,t,o){let r=[];return this.findInner(e??0,t??1e9,r,0,o),r}findInner(e,t,o,r,s){for(let i=0;i<this.local.length;i++){let l=this.local[i];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&o.push(l.copy(l.from+r,l.to+r))}for(let i=0;i<this.children.length;i+=3)if(this.children[i]<t&&this.children[i+1]>e){let l=this.children[i]+1;this.children[i+2].findInner(e-l,t-l,o,r+l,s)}}map(e,t,o){return this==Le||e.maps.length==0?this:this.mapInner(e,t,0,0,o||Bn)}mapInner(e,t,o,r,s){let i;for(let l=0;l<this.local.length;l++){let c=this.local[l].map(e,o,r);c&&c.type.valid(t,c)?(i||(i=[])).push(c):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?fk(this.children,i||[],e,t,o,r,s):i?new he(i.sort(In),ro):Le}add(e,t){return t.length?this==Le?he.create(e,t):this.addInner(e,t,0):this}addInner(e,t,o){let r,s=0;e.forEach((l,c)=>{let d=c+o,u;if(u=ff(t,l,d)){for(r||(r=this.children.slice());s<r.length&&r[s]<c;)s+=3;r[s]==c?r[s+2]=r[s+2].addInner(l,u,d+1):r.splice(s,0,c,c+l.nodeSize,Ur(u,l,d+1,Bn)),s+=3}});let i=uf(s?hf(t):t,-o);for(let l=0;l<i.length;l++)i[l].type.valid(e,i[l])||i.splice(l--,1);return new he(i.length?this.local.concat(i).sort(In):this.local,r||this.children)}remove(e){return e.length==0||this==Le?this:this.removeInner(e,0)}removeInner(e,t){let o=this.children,r=this.local;for(let s=0;s<o.length;s+=3){let i,l=o[s]+t,c=o[s+1]+t;for(let u=0,f;u<e.length;u++)(f=e[u])&&f.from>l&&f.to<c&&(e[u]=null,(i||(i=[])).push(f));if(!i)continue;o==this.children&&(o=this.children.slice());let d=o[s+2].removeInner(i,l+1);d!=Le?o[s+2]=d:(o.splice(s,3),s-=3)}if(r.length){for(let s=0,i;s<e.length;s++)if(i=e[s])for(let l=0;l<r.length;l++)r[l].eq(i,t)&&(r==this.local&&(r=this.local.slice()),r.splice(l--,1))}return o==this.children&&r==this.local?this:r.length||o.length?new he(r,o):Le}forChild(e,t){if(this==Le)return this;if(t.isLeaf)return he.empty;let o,r;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(o=this.children[l+2]);break}let s=e+1,i=s+t.content.size;for(let l=0;l<this.local.length;l++){let c=this.local[l];if(c.from<i&&c.to>s&&c.type instanceof Zt){let d=Math.max(s,c.from)-s,u=Math.min(i,c.to)-s;d<u&&(r||(r=[])).push(c.copy(d,u))}}if(r){let l=new he(r.sort(In),ro);return o?new en([l,o]):l}return o||Le}eq(e){if(this==e)return!0;if(!(e instanceof he)||this.local.length!=e.local.length||this.children.length!=e.children.length)return!1;for(let t=0;t<this.local.length;t++)if(!this.local[t].eq(e.local[t]))return!1;for(let t=0;t<this.children.length;t+=3)if(this.children[t]!=e.children[t]||this.children[t+1]!=e.children[t+1]||!this.children[t+2].eq(e.children[t+2]))return!1;return!0}locals(e){return bl(this.localsInner(e))}localsInner(e){if(this==Le)return ro;if(e.inlineContent||!this.local.some(Zt.is))return this.local;let t=[];for(let o=0;o<this.local.length;o++)this.local[o].type instanceof Zt||t.push(this.local[o]);return t}forEachSet(e){e(this)}}he.empty=new he([],[]),he.removeOverlap=bl;const Le=he.empty;class en{constructor(e){this.members=e}map(e,t){const o=this.members.map(r=>r.map(e,t,Bn));return en.from(o)}forChild(e,t){if(t.isLeaf)return he.empty;let o=[];for(let r=0;r<this.members.length;r++){let s=this.members[r].forChild(e,t);s!=Le&&(s instanceof en?o=o.concat(s.members):o.push(s))}return en.from(o)}eq(e){if(!(e instanceof en)||e.members.length!=this.members.length)return!1;for(let t=0;t<this.members.length;t++)if(!this.members[t].eq(e.members[t]))return!1;return!0}locals(e){let t,o=!0;for(let r=0;r<this.members.length;r++){let s=this.members[r].localsInner(e);if(s.length)if(!t)t=s;else{o&&(t=t.slice(),o=!1);for(let i=0;i<s.length;i++)t.push(s[i])}}return t?bl(o?t:t.sort(In)):ro}static from(e){switch(e.length){case 0:return Le;case 1:return e[0];default:return new en(e.every(t=>t instanceof he)?e:e.reduce((t,o)=>t.concat(o instanceof he?o:o.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function fk(n,e,t,o,r,s,i){let l=n.slice();for(let d=0,u=s;d<t.maps.length;d++){let f=0;t.maps[d].forEach((h,p,m,g)=>{let y=g-m-(p-h);for(let k=0;k<l.length;k+=3){let x=l[k+1];if(x<0||h>x+u-f)continue;let b=l[k]+u-f;p>=b?l[k+1]=h<=b?-2:-1:h>=u&&y&&(l[k]+=y,l[k+1]+=y)}f+=y}),u=t.maps[d].map(u,-1)}let c=!1;for(let d=0;d<l.length;d+=3)if(l[d+1]<0){if(l[d+1]==-2){c=!0,l[d+1]=-1;continue}let u=t.map(n[d]+s),f=u-r;if(f<0||f>=o.content.size){c=!0;continue}let h=t.map(n[d+1]+s,-1),p=h-r,{index:m,offset:g}=o.content.findIndex(f),y=o.maybeChild(m);if(y&&g==f&&g+y.nodeSize==p){let k=l[d+2].mapInner(t,y,u+1,n[d]+s+1,i);k!=Le?(l[d]=f,l[d+1]=p,l[d+2]=k):(l[d+1]=-2,c=!0)}else c=!0}if(c){let d=hk(l,n,e,t,r,s,i),u=Ur(d,o,0,i);e=u.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,h=0;f<u.children.length;f+=3){let p=u.children[f];for(;h<l.length&&l[h]<p;)h+=3;l.splice(h,0,u.children[f],u.children[f+1],u.children[f+2])}}return new he(e.sort(In),l)}function uf(n,e){if(!e||!n.length)return n;let t=[];for(let o=0;o<n.length;o++){let r=n[o];t.push(new Fe(r.from+e,r.to+e,r.type))}return t}function hk(n,e,t,o,r,s,i){function l(c,d){for(let u=0;u<c.local.length;u++){let f=c.local[u].map(o,r,d);f?t.push(f):i.onRemove&&i.onRemove(c.local[u].spec)}for(let u=0;u<c.children.length;u+=3)l(c.children[u+2],c.children[u]+d+1)}for(let c=0;c<n.length;c+=3)n[c+1]==-1&&l(n[c+2],e[c]+s+1);return t}function ff(n,e,t){if(e.isLeaf)return null;let o=t+e.nodeSize,r=null;for(let s=0,i;s<n.length;s++)(i=n[s])&&i.from>t&&i.to<o&&((r||(r=[])).push(i),n[s]=null);return r}function hf(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function Ur(n,e,t,o){let r=[],s=!1;e.forEach((l,c)=>{let d=ff(n,l,c+t);if(d){s=!0;let u=Ur(d,l,t+c+1,o);u!=Le&&r.push(c,c+l.nodeSize,u)}});let i=uf(s?hf(n):n,-t).sort(In);for(let l=0;l<i.length;l++)i[l].type.valid(e,i[l])||(o.onRemove&&o.onRemove(i[l].spec),i.splice(l--,1));return i.length||r.length?new he(i,r):Le}function In(n,e){return n.from-e.from||n.to-e.to}function bl(n){let e=n;for(let t=0;t<e.length-1;t++){let o=e[t];if(o.from!=o.to)for(let r=t+1;r<e.length;r++){let s=e[r];if(s.from==o.from){s.to!=o.to&&(e==n&&(e=n.slice()),e[r]=s.copy(s.from,o.to),pf(e,r+1,s.copy(o.to,s.to)));continue}else{s.from<o.to&&(e==n&&(e=n.slice()),e[t]=o.copy(o.from,s.from),pf(e,r,o.copy(s.from,o.to)));break}}}return e}function pf(n,e,t){for(;e<n.length&&In(t,n[e])>0;)e++;n.splice(e,0,t)}function Sl(n){let e=[];return n.someProp("decorations",t=>{let o=t(n.state);o&&o!=Le&&e.push(o)}),n.cursorWrapper&&e.push(he.create(n.state.doc,[n.cursorWrapper.deco])),en.from(e)}const pk={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},mk=He&&Jt<=11;class gk{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}}class yk{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new gk,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(o=>{for(let r=0;r<o.length;r++)this.queue.push(o[r]);He&&Jt<=11&&o.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():Pe&&e.composing&&o.some(r=>r.type=="childList"&&r.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),mk&&(this.onCharData=o=>{this.queue.push({target:o.target,type:"characterData",oldValue:o.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,pk)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;t<e.length;t++)this.queue.push(e[t]);window.setTimeout(()=>this.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Fu(this.view)){if(this.suppressingSelectionUpdates)return Rt(this.view);if(He&&Jt<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&vn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,o;for(let s=e.focusNode;s;s=Zn(s))t.add(s);for(let s=e.anchorNode;s;s=Zn(s))if(t.has(s)){o=s;break}let r=o&&this.view.docView.nearestDesc(o);if(r&&r.ignoreMutation({type:"selection",target:o.nodeType==3?o.parentNode:o}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let o=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(o)&&Fu(e)&&!this.ignoreSelectionChange(o),s=-1,i=-1,l=!1,c=[];if(e.editable)for(let u=0;u<t.length;u++){let f=this.registerMutation(t[u],c);f&&(s=s<0?f.from:Math.min(f.from,s),i=i<0?f.to:Math.max(f.to,i),f.typeOver&&(l=!0))}if(c.some(u=>u.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let u of c)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;f&&f.nodeType==1&&f.contentEditable=="false"&&u.parentNode.removeChild(u)}}else if(Xe&&c.length){let u=c.filter(f=>f.nodeName=="BR");if(u.length==2){let[f,h]=u;f.parentNode&&f.parentNode.parentNode==h.parentNode?h.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let h of u){let p=h.parentNode;p&&p.nodeName=="LI"&&(!f||bk(e,f)!=p)&&h.remove()}}}let d=null;s<0&&r&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Lr(o)&&(d=ll(e))&&d.eq(ee.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,Rt(e),this.currentSelection.set(o),e.scrollToSelection()):(s>-1||r)&&(s>-1&&(e.docView.markDirty(s,i),kk(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,Sk(e,c)),this.handleDOMChange(s,i,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(o)||Rt(e),this.currentSelection.set(o))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let o=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(o==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!o||o.ignoreMutation(e))return null;if(e.type=="childList"){for(let u=0;u<e.addedNodes.length;u++){let f=e.addedNodes[u];t.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}if(o.contentDOM&&o.contentDOM!=o.dom&&!o.contentDOM.contains(e.target))return{from:o.posBefore,to:o.posAfter};let r=e.previousSibling,s=e.nextSibling;if(He&&Jt<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:f,nextSibling:h}=e.addedNodes[u];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(r=f),(!h||Array.prototype.indexOf.call(e.addedNodes,h)<0)&&(s=h)}let i=r&&r.parentNode==e.target?Ae(r)+1:0,l=o.localPosFromDOM(e.target,i,-1),c=s&&s.parentNode==e.target?Ae(s):e.target.childNodes.length,d=o.localPosFromDOM(e.target,c,1);return{from:l,to:d}}else return e.type=="attributes"?{from:o.posAtStart-o.border,to:o.posAtEnd+o.border}:(this.lastChangedTextNode=e.target,{from:o.posAtStart,to:o.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}}let mf=new WeakMap,gf=!1;function kk(n){if(!mf.has(n)&&(mf.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=Xe,gf)return;console.warn("ProseMirror expects the CSS white-space property to be set, preferably to 'pre-wrap'. It is recommended to load style/prosemirror.css from the prosemirror-view package."),gf=!0}}function yf(n,e){let t=e.startContainer,o=e.startOffset,r=e.endContainer,s=e.endOffset,i=n.domAtPos(n.state.selection.anchor);return vn(i.node,i.offset,r,s)&&([t,o,r,s]=[r,s,t,o]),{anchorNode:t,anchorOffset:o,focusNode:r,focusOffset:s}}function wk(n,e){if(e.getComposedRanges){let r=e.getComposedRanges(n.root)[0];if(r)return yf(n,r)}let t;function o(r){r.preventDefault(),r.stopImmediatePropagation(),t=r.getTargetRanges()[0]}return n.dom.addEventListener("beforeinput",o,!0),document.execCommand("indent"),n.dom.removeEventListener("beforeinput",o,!0),t?yf(n,t):null}function bk(n,e){for(let t=e.parentNode;t&&t!=n.dom;t=t.parentNode){let o=n.docView.nearestDesc(t,!0);if(o&&o.node.isBlock)return t}return null}function Sk(n,e){var t;let{focusNode:o,focusOffset:r}=n.domSelectionRange();for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let i=s.nextSibling;for(;i&&i.nodeName!="TD"&&i.nodeName!="TH";)i=i.nextSibling;if(i){let l=i;for(;;){let c=l.firstChild;if(!c||c.nodeType!=1||c.contentEditable=="false"||/^(BR|IMG)$/.test(c.nodeName))break;l=c}l.insertBefore(s,l.firstChild),o==s&&n.domSelection().collapse(s,r)}else s.parentNode.removeChild(s)}}function xk(n,e,t){let{node:o,fromOffset:r,toOffset:s,from:i,to:l}=n.docView.parseRange(e,t),c=n.domSelectionRange(),d,u=c.anchorNode;if(u&&n.dom.contains(u.nodeType==1?u:u.parentNode)&&(d=[{node:u,offset:c.anchorOffset}],Lr(c)||d.push({node:c.focusNode,offset:c.focusOffset})),Be&&n.input.lastKeyCode===8)for(let y=s;y>r;y--){let k=o.childNodes[y-1],x=k.pmViewDesc;if(k.nodeName=="BR"&&!x){s=y;break}if(!x||x.size)break}let f=n.state.doc,h=n.someProp("domParser")||Bt.fromSchema(n.state.schema),p=f.resolve(i),m=null,g=h.parse(o,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:r,to:s,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:d,ruleFromNode:Ck,context:p});if(d&&d[0].pos!=null){let y=d[0].pos,k=d[1]&&d[1].pos;k==null&&(k=y),m={anchor:y+i,head:k+i}}return{doc:g,sel:m,from:i,to:l}}function Ck(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(Pe&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||Pe&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}const Ek=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|img|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function vk(n,e,t,o,r){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let E=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,M=ll(n,E);if(M&&!n.state.selection.eq(M)){if(Be&&_t&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",A=>A(n,Mn(13,"Enter"))))return;let T=n.state.tr.setSelection(M);E=="pointer"?T.setMeta("pointer",!0):E=="key"&&T.scrollIntoView(),s&&T.setMeta("composition",s),n.dispatch(T)}return}let i=n.state.doc.resolve(e),l=i.sharedDepth(t);e=i.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,d=xk(n,e,t),u=n.state.doc,f=u.slice(d.from,d.to),h,p;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(h=n.state.selection.to,p="end"):(h=n.state.selection.from,p="start"),n.input.lastKeyCode=null;let m=Nk(f.content,d.doc.content,d.from,h,p);if(m&&n.input.domChangeCount++,(eo&&n.input.lastIOSEnter>Date.now()-225||_t)&&r.some(E=>E.nodeType==1&&!Ek.test(E.nodeName))&&(!m||m.endA>=m.endB)&&n.someProp("handleKeyDown",E=>E(n,Mn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!m)if(o&&c instanceof Q&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(d.sel&&d.sel.anchor!=d.sel.head))m={start:c.from,endA:c.to,endB:c.to};else{if(d.sel){let E=kf(n,n.state.doc,d.sel);if(E&&!E.eq(n.state.selection)){let M=n.state.tr.setSelection(E);s&&M.setMeta("composition",s),n.dispatch(M)}}return}n.state.selection.from<n.state.selection.to&&m.start==m.endB&&n.state.selection instanceof Q&&(m.start>n.state.selection.from&&m.start<=n.state.selection.from+2&&n.state.selection.from>=d.from?m.start=n.state.selection.from:m.endA<n.state.selection.to&&m.endA>=n.state.selection.to-2&&n.state.selection.to<=d.to&&(m.endB+=n.state.selection.to-m.endA,m.endA=n.state.selection.to)),He&&Jt<=11&&m.endB==m.start+1&&m.endA==m.start&&m.start>d.from&&d.doc.textBetween(m.start-d.from-1,m.start-d.from+1)==" "&&(m.start--,m.endA--,m.endB--);let g=d.doc.resolveNoCache(m.start-d.from),y=d.doc.resolveNoCache(m.endB-d.from),k=u.resolve(m.start),x=g.sameParent(y)&&g.parent.inlineContent&&k.end()>=m.endA;if((eo&&n.input.lastIOSEnter>Date.now()-225&&(!x||r.some(E=>E.nodeName=="DIV"||E.nodeName=="P"))||!x&&g.pos<d.doc.content.size&&(!g.sameParent(y)||!g.parent.inlineContent)&&g.pos<y.pos&&!/\S/.test(d.doc.textBetween(g.pos,y.pos,"","")))&&n.someProp("handleKeyDown",E=>E(n,Mn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>m.start&&Tk(u,m.start,m.endA,g,y)&&n.someProp("handleKeyDown",E=>E(n,Mn(8,"Backspace")))){_t&&Be&&n.domObserver.suppressSelectionUpdates();return}Be&&m.endB==m.start&&(n.input.lastChromeDelete=Date.now()),_t&&!x&&g.start()!=y.start()&&y.parentOffset==0&&g.depth==y.depth&&d.sel&&d.sel.anchor==d.sel.head&&d.sel.head==m.endA&&(m.endB-=2,y=d.doc.resolveNoCache(m.endB-d.from),setTimeout(()=>{n.someProp("handleKeyDown",function(E){return E(n,Mn(13,"Enter"))})},20));let b=m.start,S=m.endA,C=E=>{let M=E||n.state.tr.replace(b,S,d.doc.slice(m.start-d.from,m.endB-d.from));if(d.sel){let T=kf(n,M.doc,d.sel);T&&!(Be&&n.composing&&T.empty&&(m.start!=m.endB||n.input.lastChromeDelete<Date.now()-100)&&(T.head==b||T.head==M.mapping.map(S)-1)||He&&T.empty&&T.head==b)&&M.setSelection(T)}return s&&M.setMeta("composition",s),M.scrollIntoView()},v;if(x)if(g.pos==y.pos){He&&Jt<=11&&g.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>Rt(n),20));let E=C(n.state.tr.delete(b,S)),M=u.resolve(m.start).marksAcross(u.resolve(m.endA));M&&E.ensureMarks(M),n.dispatch(E)}else if(m.endA==m.endB&&(v=Mk(g.parent.content.cut(g.parentOffset,y.parentOffset),k.parent.content.cut(k.parentOffset,m.endA-k.start())))){let E=C(n.state.tr);v.type=="add"?E.addMark(b,S,v.mark):E.removeMark(b,S,v.mark),n.dispatch(E)}else if(g.parent.child(g.index()).isText&&g.index()==y.index()-(y.textOffset?0:1)){let E=g.parent.textBetween(g.parentOffset,y.parentOffset),M=()=>C(n.state.tr.insertText(E,b,S));n.someProp("handleTextInput",T=>T(n,b,S,E,M))||n.dispatch(M())}else n.dispatch(C());else n.dispatch(C())}function kf(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:cl(n,e.resolve(t.anchor),e.resolve(t.head))}function Mk(n,e){let t=n.firstChild.marks,o=e.firstChild.marks,r=t,s=o,i,l,c;for(let u=0;u<o.length;u++)r=o[u].removeFromSet(r);for(let u=0;u<t.length;u++)s=t[u].removeFromSet(s);if(r.length==1&&s.length==0)l=r[0],i="add",c=u=>u.mark(l.addToSet(u.marks));else if(r.length==0&&s.length==1)l=s[0],i="remove",c=u=>u.mark(l.removeFromSet(u.marks));else return null;let d=[];for(let u=0;u<e.childCount;u++)d.push(c(e.child(u)));if(P.from(d).eq(n))return{mark:l,type:i}}function Tk(n,e,t,o,r){if(t-e<=r.pos-o.pos||xl(o,!0,!1)<r.pos)return!1;let s=n.resolve(e);if(!o.parent.isTextblock){let l=s.nodeAfter;return l!=null&&t==e+l.nodeSize}if(s.parentOffset<s.parent.content.size||!s.parent.isTextblock)return!1;let i=n.resolve(xl(s,!0,!0));return!i.parent.isTextblock||i.pos>t||xl(i,!0,!1)<t?!1:o.parent.content.cut(o.parentOffset).eq(i.parent.content)}function xl(n,e,t){let o=n.depth,r=e?n.end():n.pos;for(;o>0&&(e||n.indexAfter(o)==n.node(o).childCount);)o--,r++,e=!1;if(t){let s=n.node(o).maybeChild(n.indexAfter(o));for(;s&&!s.isLeaf;)s=s.firstChild,r++}return r}function Nk(n,e,t,o,r){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:i,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(r=="end"){let c=Math.max(0,s-Math.min(i,l));o-=i+c-s}if(i<s&&n.size<e.size){let c=o<=s&&o>=i?s-o:0;s-=c,s&&s<e.size&&wf(e.textBetween(s-1,s+1))&&(s+=c?1:-1),l=s+(l-i),i=s}else if(l<s){let c=o<=s&&o>=l?s-o:0;s-=c,s&&s<n.size&&wf(n.textBetween(s-1,s+1))&&(s+=c?1:-1),i=s+(i-l),l=s}return{start:s,endA:i,endB:l}}function wf(n){if(n.length!=2)return!1;let e=n.charCodeAt(0),t=n.charCodeAt(1);return e>=56320&&e<=57343&&t>=55296&&t<=56319}class bf{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new U1,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(vf),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=Cf(this),xf(this),this.nodeViews=Ef(this),this.docView=Au(this.state.doc,Sf(this),Sl(this),this.dom,this),this.domObserver=new yk(this,(o,r,s,i)=>vk(this,o,r,s,i)),this.domObserver.start(),W1(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&ml(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(vf),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let o in this._props)t[o]=this._props[o];t.state=this.state;for(let o in e)t[o]=e[o];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var o;let r=this.state,s=!1,i=!1;e.storedMarks&&this.composing&&(lf(this),i=!0),this.state=e;let l=r.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let p=Ef(this);Bk(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&ml(this),this.editable=Cf(this),xf(this);let c=Sl(this),d=Sf(this),u=r.plugins!=e.plugins&&!r.doc.eq(e.doc)?"reset":e.scrollToSelection>r.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,d,c);(f||!e.selection.eq(r.selection))&&(i=!0);let h=u=="preserve"&&i&&this.dom.style.overflowAnchor==null&&s1(this);if(i){this.domObserver.stop();let p=f&&(He||Be)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&Ak(r.selection,e.selection);if(f){let m=Be?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=sk(this)),(s||!this.docView.update(e.doc,d,c,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=Au(e.doc,d,c,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(p=!0)}p||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&A1(this))?Rt(this,p):($u(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(r),!((o=this.dragging)===null||o===void 0)&&o.node&&!r.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,r),u=="reset"?this.dom.scrollTop=0:u=="to selection"?this.scrollToSelection():h&&i1(h)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!(!e||!this.dom.contains(e.nodeType==1?e:e.parentNode))){if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof Y){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&gu(this,t.getBoundingClientRect(),e)}else gu(this,this.coordsAtPos(this.state.selection.head,1),e)}}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t<this.directPlugins.length;t++){let o=this.directPlugins[t];o.spec.view&&this.pluginViews.push(o.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let o=this.state.plugins[t];o.spec.view&&this.pluginViews.push(o.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let o=this.pluginViews[t];o.update&&o.update(this,e)}}updateDraggedNode(e,t){let o=e.node,r=-1;if(this.state.doc.nodeAt(o.from)==o.node)r=o.from;else{let s=o.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&this.state.doc.nodeAt(s))==o.node&&(r=s)}this.dragging=new cf(e.slice,e.move,r<0?void 0:Y.create(this.state.doc,r))}someProp(e,t){let o=this._props&&this._props[e],r;if(o!=null&&(r=t?t(o):o))return r;for(let i=0;i<this.directPlugins.length;i++){let l=this.directPlugins[i].props[e];if(l!=null&&(r=t?t(l):l))return r}let s=this.state.plugins;if(s)for(let i=0;i<s.length;i++){let l=s[i].props[e];if(l!=null&&(r=t?t(l):l))return r}}hasFocus(){if(He){let e=this.root.activeElement;if(e==this.dom)return!0;if(!e||!this.dom.contains(e))return!1;for(;e&&this.dom!=e&&this.dom.contains(e);){if(e.contentEditable=="false")return!1;e=e.parentElement}return!0}return this.root.activeElement==this.dom}focus(){this.domObserver.stop(),this.editable&&l1(this.dom),Rt(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return f1(this,e)}coordsAtPos(e,t=1){return xu(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,o=-1){let r=this.docView.posFromDOM(e,t,o);if(r==null)throw new RangeError("DOM position not inside the editor");return r}endOfTextblock(e,t){return y1(this,t||this.state,e)}pasteHTML(e,t){return zo(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return zo(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return fl(this,e)}destroy(){this.docView&&(K1(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Sl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Gy())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return J1(this,e)}domSelectionRange(){let e=this.domSelection();return e?Pe&&this.root.nodeType===11&&e1(this.dom.ownerDocument)==this.dom&&wk(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}bf.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function Sf(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let o in t)o=="class"?e.class+=" "+t[o]:o=="style"?e.style=(e.style?e.style+";":"")+t[o]:!e[o]&&o!="contenteditable"&&o!="nodeName"&&(e[o]=String(t[o]))}),e.translate||(e.translate="no"),[Fe.node(0,n.state.doc.content.size,e)]}function xf(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:Fe.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Cf(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Ak(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function Ef(n){let e=Object.create(null);function t(o){for(let r in o)Object.prototype.hasOwnProperty.call(e,r)||(e[r]=o[r])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function Bk(n,e){let t=0,o=0;for(let r in n){if(n[r]!=e[r])return!0;t++}for(let r in e)o++;return t!=o}function vf(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}for(var tn={8:"Backspace",9:"Tab",10:"Enter",12:"NumLock",13:"Enter",16:"Shift",17:"Control",18:"Alt",20:"CapsLock",27:"Escape",32:" ",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"ArrowLeft",38:"ArrowUp",39:"ArrowRight",40:"ArrowDown",44:"PrintScreen",45:"Insert",46:"Delete",59:";",61:"=",91:"Meta",92:"Meta",106:"*",107:"+",108:",",109:"-",110:".",111:"/",144:"NumLock",145:"ScrollLock",160:"Shift",161:"Shift",162:"Control",163:"Control",164:"Alt",165:"Alt",173:"-",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'"},Wr={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},Ik=typeof navigator<"u"&&/Mac/.test(navigator.platform),Ok=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Ie=0;Ie<10;Ie++)tn[48+Ie]=tn[96+Ie]=String(Ie);for(var Ie=1;Ie<=24;Ie++)tn[Ie+111]="F"+Ie;for(var Ie=65;Ie<=90;Ie++)tn[Ie]=String.fromCharCode(Ie+32),Wr[Ie]=String.fromCharCode(Ie);for(var Cl in tn)Wr.hasOwnProperty(Cl)||(Wr[Cl]=tn[Cl]);function _k(n){var e=Ik&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||Ok&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Wr:tn)[n.keyCode]||n.key||"Unidentified";return t=="Esc"&&(t="Escape"),t=="Del"&&(t="Delete"),t=="Left"&&(t="ArrowLeft"),t=="Up"&&(t="ArrowUp"),t=="Right"&&(t="ArrowRight"),t=="Down"&&(t="ArrowDown"),t}const Dk=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),Rk=typeof navigator<"u"&&/Win/.test(navigator.platform);function Pk(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let o,r,s,i;for(let l=0;l<e.length-1;l++){let c=e[l];if(/^(cmd|meta|m)$/i.test(c))i=!0;else if(/^a(lt)?$/i.test(c))o=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))s=!0;else if(/^mod$/i.test(c))Dk?i=!0:r=!0;else throw new Error("Unrecognized modifier name: "+c)}return o&&(t="Alt-"+t),r&&(t="Ctrl-"+t),i&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function Lk(n){let e=Object.create(null);for(let t in n)e[Pk(t)]=n[t];return e}function El(n,e,t=!0){return e.altKey&&(n="Alt-"+n),e.ctrlKey&&(n="Ctrl-"+n),e.metaKey&&(n="Meta-"+n),t&&e.shiftKey&&(n="Shift-"+n),n}function Vk(n){return new pe({props:{handleKeyDown:Mf(n)}})}function Mf(n){let e=Lk(n);return function(t,o){let r=_k(o),s,i=e[El(r,o)];if(i&&i(t.state,t.dispatch,t))return!0;if(r.length==1&&r!=" "){if(o.shiftKey){let l=e[El(r,o,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((o.altKey||o.metaKey||o.ctrlKey)&&!(Rk&&o.ctrlKey&&o.altKey)&&(s=tn[o.keyCode])&&s!=r){let l=e[El(s,o)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var $k=Object.defineProperty,vl=(n,e)=>{for(var t in e)$k(n,t,{get:e[t],enumerable:!0})};function Kr(n){const{state:e,transaction:t}=n;let{selection:o}=t,{doc:r}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return o},get doc(){return r},get tr(){return o=t.selection,r=t.doc,s=t.storedMarks,t}}}var qr=class{constructor(n){this.editor=n.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=n.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:n,editor:e,state:t}=this,{view:o}=e,{tr:r}=t,s=this.buildProps(r);return Object.fromEntries(Object.entries(n).map(([i,l])=>[i,(...d)=>{const u=l(...d)(s);return!r.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(r),u}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(n,e=!0){const{rawCommands:t,editor:o,state:r}=this,{view:s}=o,i=[],l=!!n,c=n||r.tr,d=()=>(!l&&e&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(c),i.every(f=>f===!0)),u={...Object.fromEntries(Object.entries(t).map(([f,h])=>[f,(...m)=>{const g=this.buildProps(c,e),y=h(...m)(g);return i.push(y),u}])),run:d};return u}createCan(n){const{rawCommands:e,state:t}=this,o=!1,r=n||t.tr,s=this.buildProps(r,o);return{...Object.fromEntries(Object.entries(e).map(([l,c])=>[l,(...d)=>c(...d)({...s,dispatch:void 0})])),chain:()=>this.createChain(r,o)}}buildProps(n,e=!0){const{rawCommands:t,editor:o,state:r}=this,{view:s}=o,i={tr:n,editor:o,view:s,state:Kr({state:r,transaction:n}),dispatch:e?()=>{}:void 0,chain:()=>this.createChain(n,e),can:()=>this.createCan(n),get commands(){return Object.fromEntries(Object.entries(t).map(([l,c])=>[l,(...d)=>c(...d)(i)]))}};return i}},Tf={};vl(Tf,{blur:()=>zk,clearContent:()=>Fk,clearNodes:()=>Hk,command:()=>jk,createParagraphNear:()=>Uk,cut:()=>Wk,deleteCurrentNode:()=>Kk,deleteNode:()=>qk,deleteRange:()=>Jk,deleteSelection:()=>Gk,enter:()=>Yk,exitCode:()=>Xk,extendMarkRange:()=>Qk,first:()=>Zk,focus:()=>tw,forEach:()=>nw,insertContent:()=>ow,insertContentAt:()=>iw,joinBackward:()=>cw,joinDown:()=>aw,joinForward:()=>dw,joinItemBackward:()=>uw,joinItemForward:()=>fw,joinTextblockBackward:()=>hw,joinTextblockForward:()=>pw,joinUp:()=>lw,keyboardShortcut:()=>gw,lift:()=>yw,liftEmptyBlock:()=>kw,liftListItem:()=>ww,newlineInCode:()=>bw,resetAttributes:()=>Sw,scrollIntoView:()=>xw,selectAll:()=>Cw,selectNodeBackward:()=>Ew,selectNodeForward:()=>vw,selectParentNode:()=>Mw,selectTextblockEnd:()=>Tw,selectTextblockStart:()=>Nw,setContent:()=>Aw,setMark:()=>Jw,setMeta:()=>Gw,setNode:()=>Yw,setNodeSelection:()=>Xw,setTextDirection:()=>Qw,setTextSelection:()=>Zw,sinkListItem:()=>eb,splitBlock:()=>tb,splitListItem:()=>nb,toggleList:()=>ob,toggleMark:()=>rb,toggleNode:()=>sb,toggleWrap:()=>ib,undoInputRule:()=>lb,unsetAllMarks:()=>ab,unsetMark:()=>cb,unsetTextDirection:()=>db,updateAttributes:()=>ub,wrapIn:()=>fb,wrapInList:()=>hb});var zk=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())==null||t.removeAllRanges())}),!0),Fk=(n=!0)=>({commands:e})=>e.setContent("",{emitUpdate:n}),Hk=()=>({state:n,tr:e,dispatch:t})=>{const{selection:o}=e,{ranges:r}=o;return t&&r.forEach(({$from:s,$to:i})=>{n.doc.nodesBetween(s.pos,i.pos,(l,c)=>{if(l.type.isText)return;const{doc:d,mapping:u}=e,f=d.resolve(u.map(c)),h=d.resolve(u.map(c+l.nodeSize)),p=f.blockRange(h);if(!p)return;const m=qn(p);if(l.type.isTextblock){const{defaultType:g}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(p.start,g)}(m||m===0)&&e.lift(p,m)})}),!0},jk=n=>e=>n(e),Uk=()=>({state:n,dispatch:e})=>iu(n,e),Wk=(n,e)=>({editor:t,tr:o})=>{const{state:r}=t,s=r.doc.slice(n.from,n.to);o.deleteRange(n.from,n.to);const i=o.mapping.map(e);return o.insert(i,s.content),o.setSelection(new Q(o.doc.resolve(Math.max(i-1,0)))),!0},Kk=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,o=t.$anchor.node();if(o.content.size>0)return!1;const r=n.selection.$anchor;for(let s=r.depth;s>0;s-=1)if(r.node(s).type===o.type){if(e){const l=r.before(s),c=r.after(s);n.delete(l,c).scrollIntoView()}return!0}return!1};function Ee(n,e){if(typeof n=="string"){if(!e.nodes[n])throw Error(`There is no node type named '${n}'. Maybe you forgot to add the extension?`);return e.nodes[n]}return n}var qk=n=>({tr:e,state:t,dispatch:o})=>{const r=Ee(n,t.schema),s=e.selection.$anchor;for(let i=s.depth;i>0;i-=1)if(s.node(i).type===r){if(o){const c=s.before(i),d=s.after(i);e.delete(c,d).scrollIntoView()}return!0}return!1},Jk=n=>({tr:e,dispatch:t})=>{const{from:o,to:r}=n;return t&&e.delete(o,r),!0},Gk=()=>({state:n,dispatch:e})=>Ji(n,e),Yk=()=>({commands:n})=>n.keyboardShortcut("Enter"),Xk=()=>({state:n,dispatch:e})=>Dy(n,e);function Ml(n){return Object.prototype.toString.call(n)==="[object RegExp]"}function Jr(n,e,t={strict:!0}){const o=Object.keys(e);return o.length?o.every(r=>t.strict?e[r]===n[r]:Ml(e[r])?e[r].test(n[r]):e[r]===n[r]):!0}function Nf(n,e,t={}){return n.find(o=>o.type===e&&Jr(Object.fromEntries(Object.keys(t).map(r=>[r,o.attrs[r]])),t))}function Af(n,e,t={}){return!!Nf(n,e,t)}function Tl(n,e,t){var o;if(!n||!e)return;let r=n.parent.childAfter(n.parentOffset);if((!r.node||!r.node.marks.some(u=>u.type===e))&&(r=n.parent.childBefore(n.parentOffset)),!r.node||!r.node.marks.some(u=>u.type===e)||(t=t||((o=r.node.marks[0])==null?void 0:o.attrs),!Nf([...r.node.marks],e,t)))return;let i=r.index,l=n.start()+r.offset,c=i+1,d=l+r.node.nodeSize;for(;i>0&&Af([...n.parent.child(i-1).marks],e,t);)i-=1,l-=n.parent.child(i).nodeSize;for(;c<n.parent.childCount&&Af([...n.parent.child(c).marks],e,t);)d+=n.parent.child(c).nodeSize,c+=1;return{from:l,to:d}}function Pt(n,e){if(typeof n=="string"){if(!e.marks[n])throw Error(`There is no mark type named '${n}'. Maybe you forgot to add the extension?`);return e.marks[n]}return n}var Qk=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const s=Pt(n,o.schema),{doc:i,selection:l}=t,{$from:c,from:d,to:u}=l;if(r){const f=Tl(c,s,e);if(f&&f.from<=d&&f.to>=u){const h=Q.create(i,f.from,f.to);t.setSelection(h)}}return!0},Zk=n=>e=>{const t=typeof n=="function"?n(e):n;for(let o=0;o<t.length;o+=1)if(t[o](e))return!0;return!1};function Bf(n){return n instanceof Q}function On(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function If(n,e=null){if(!e)return null;const t=ee.atStart(n),o=ee.atEnd(n);if(e==="start"||e===!0)return t;if(e==="end")return o;const r=t.from,s=o.to;return e==="all"?Q.create(n,On(0,r,s),On(n.content.size,r,s)):Q.create(n,On(e,r,s),On(e,r,s))}function Of(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function Gr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}function ew(){return typeof navigator<"u"?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var tw=(n=null,e={})=>({editor:t,view:o,tr:r,dispatch:s})=>{e={scrollIntoView:!0,...e};const i=()=>{(Gr()||Of())&&o.dom.focus(),ew()&&!Gr()&&!Of()&&o.dom.focus({preventScroll:!0}),requestAnimationFrame(()=>{t.isDestroyed||(o.focus(),e!=null&&e.scrollIntoView&&t.commands.scrollIntoView())})};try{if(o.hasFocus()&&n===null||n===!1)return!0}catch{return!1}if(s&&n===null&&!Bf(t.state.selection))return i(),!0;const l=If(r.doc,n)||t.state.selection,c=t.state.selection.eq(l);return s&&(c||r.setSelection(l),c&&r.storedMarks&&r.setStoredMarks(r.storedMarks),i()),!0},nw=(n,e)=>t=>n.every((o,r)=>e(o,{...t,index:r})),ow=(n,e)=>({tr:t,commands:o})=>o.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),_f=n=>{const e=n.childNodes;for(let t=e.length-1;t>=0;t-=1){const o=e[t];o.nodeType===3&&o.nodeValue&&/^(\n\s\s|\n)$/.test(o.nodeValue)?n.removeChild(o):o.nodeType===1&&_f(o)}return n};function Ho(n){if(typeof window>"u")throw new Error("[tiptap error]: there is no window object available, so this function cannot be used");const e=`<body>${n}</body>`,t=new window.DOMParser().parseFromString(e,"text/html").body;return _f(t)}function jo(n,e,t){if(n instanceof At||n instanceof P)return n;t={slice:!0,parseOptions:{},...t};const o=typeof n=="object"&&n!==null,r=typeof n=="string";if(o)try{if(Array.isArray(n)&&n.length>0)return P.fromArray(n.map(l=>e.nodeFromJSON(l)));const i=e.nodeFromJSON(n);return t.errorOnInvalidContent&&i.check(),i}catch(s){if(t.errorOnInvalidContent)throw new Error("[tiptap error]: Invalid JSON content",{cause:s});return console.warn("[tiptap warn]: Invalid content.","Passed value:",n,"Error:",s),jo("",e,t)}if(r){if(t.errorOnInvalidContent){let i=!1,l="";const c=new yd({topNode:e.spec.topNode,marks:e.spec.marks,nodes:e.spec.nodes.append({__tiptap__private__unknown__catch__all__node:{content:"inline*",group:"block",parseDOM:[{tag:"*",getAttrs:d=>(i=!0,l=typeof d=="string"?d:d.outerHTML,null)}]}})});if(t.slice?Bt.fromSchema(c).parseSlice(Ho(n),t.parseOptions):Bt.fromSchema(c).parse(Ho(n),t.parseOptions),t.errorOnInvalidContent&&i)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=Bt.fromSchema(e);return t.slice?s.parseSlice(Ho(n),t.parseOptions).content:s.parse(Ho(n),t.parseOptions)}return jo("",e,t)}function rw(n,e,t){const o=n.steps.length-1;if(o<e)return;const r=n.steps[o];if(!(r instanceof Se||r instanceof xe))return;const s=n.mapping.maps[o];let i=0;s.forEach((l,c,d,u)=>{i===0&&(i=u)}),n.setSelection(ee.near(n.doc.resolve(i),t))}var sw=n=>!("type"in n),iw=(n,e,t)=>({tr:o,dispatch:r,editor:s})=>{var i;if(r){t={parseOptions:s.options.parseOptions,updateSelection:!0,applyInputRules:!1,applyPasteRules:!1,...t};let l;const c=y=>{s.emit("contentError",{editor:s,error:y,disableCollaboration:()=>{"collaboration"in s.storage&&typeof s.storage.collaboration=="object"&&s.storage.collaboration&&(s.storage.collaboration.isDisabled=!0)}})},d={preserveWhitespace:"full",...t.parseOptions};if(!t.errorOnInvalidContent&&!s.options.enableContentCheck&&s.options.emitContentError)try{jo(e,s.schema,{parseOptions:d,errorOnInvalidContent:!0})}catch(y){c(y)}try{l=jo(e,s.schema,{parseOptions:d,errorOnInvalidContent:(i=t.errorOnInvalidContent)!=null?i:s.options.enableContentCheck})}catch(y){return c(y),!1}let{from:u,to:f}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},h=!0,p=!0;if((sw(l)?l:[l]).forEach(y=>{y.check(),h=h?y.isText&&y.marks.length===0:!1,p=p?y.isBlock:!1}),u===f&&p){const{parent:y}=o.doc.resolve(u);y.isTextblock&&!y.type.spec.code&&!y.childCount&&(u-=1,f+=1)}let g;if(h){if(Array.isArray(e))g=e.map(y=>y.text||"").join("");else if(e instanceof P){let y="";e.forEach(k=>{k.text&&(y+=k.text)}),g=y}else typeof e=="object"&&e&&e.text?g=e.text:g=e;o.insertText(g,u,f)}else{g=l;const y=o.doc.resolve(u),k=y.node(),x=y.parentOffset===0,b=k.isText||k.isTextblock,S=k.content.size>0;x&&b&&S&&(u=Math.max(0,u-1)),o.replaceWith(u,f,g)}t.updateSelection&&rw(o,o.steps.length-1,-1),t.applyInputRules&&o.setMeta("applyInputRules",{from:u,text:g}),t.applyPasteRules&&o.setMeta("applyPasteRules",{from:u,text:g})}return!0},lw=()=>({state:n,dispatch:e})=>Iy(n,e),aw=()=>({state:n,dispatch:e})=>Oy(n,e),cw=()=>({state:n,dispatch:e})=>Zd(n,e),dw=()=>({state:n,dispatch:e})=>ou(n,e),uw=()=>({state:n,dispatch:e,tr:t})=>{try{const o=_r(n.doc,n.selection.$from.pos,-1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},fw=()=>({state:n,dispatch:e,tr:t})=>{try{const o=_r(n.doc,n.selection.$from.pos,1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},hw=()=>({state:n,dispatch:e})=>Ay(n,e),pw=()=>({state:n,dispatch:e})=>By(n,e);function Df(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function mw(n){const e=n.split(/-(?!$)/);let t=e[e.length-1];t==="Space"&&(t=" ");let o,r,s,i;for(let l=0;l<e.length-1;l+=1){const c=e[l];if(/^(cmd|meta|m)$/i.test(c))i=!0;else if(/^a(lt)?$/i.test(c))o=!0;else if(/^(c|ctrl|control)$/i.test(c))r=!0;else if(/^s(hift)?$/i.test(c))s=!0;else if(/^mod$/i.test(c))Gr()||Df()?i=!0:r=!0;else throw new Error(`Unrecognized modifier name: ${c}`)}return o&&(t=`Alt-${t}`),r&&(t=`Ctrl-${t}`),i&&(t=`Meta-${t}`),s&&(t=`Shift-${t}`),t}var gw=n=>({editor:e,view:t,tr:o,dispatch:r})=>{const s=mw(n).split(/-(?!$)/),i=s.find(d=>!["Alt","Ctrl","Meta","Shift"].includes(d)),l=new KeyboardEvent("keydown",{key:i==="Space"?" ":i,altKey:s.includes("Alt"),ctrlKey:s.includes("Ctrl"),metaKey:s.includes("Meta"),shiftKey:s.includes("Shift"),bubbles:!0,cancelable:!0}),c=e.captureTransaction(()=>{t.someProp("handleKeyDown",d=>d(t,l))});return c==null||c.steps.forEach(d=>{const u=d.map(o.mapping);u&&r&&o.maybeStep(u)}),!0};function Uo(n,e,t={}){const{from:o,to:r,empty:s}=n.selection,i=e?Ee(e,n.schema):null,l=[];n.doc.nodesBetween(o,r,(f,h)=>{if(f.isText)return;const p=Math.max(o,h),m=Math.min(r,h+f.nodeSize);l.push({node:f,from:p,to:m})});const c=r-o,d=l.filter(f=>i?i.name===f.node.type.name:!0).filter(f=>Jr(f.node.attrs,t,{strict:!1}));return s?!!d.length:d.reduce((f,h)=>f+h.to-h.from,0)>=c}var yw=(n,e={})=>({state:t,dispatch:o})=>{const r=Ee(n,t.schema);return Uo(t,r,e)?_y(t,o):!1},kw=()=>({state:n,dispatch:e})=>lu(n,e),ww=n=>({state:e,dispatch:t})=>{const o=Ee(n,e.schema);return Wy(o)(e,t)},bw=()=>({state:n,dispatch:e})=>su(n,e);function Yr(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function Rf(n,e){const t=typeof e=="string"?[e]:e;return Object.keys(n).reduce((o,r)=>(t.includes(r)||(o[r]=n[r]),o),{})}var Sw=(n,e)=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=Yr(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=Ee(n,o.schema)),l==="mark"&&(i=Pt(n,o.schema));let c=!1;return t.selection.ranges.forEach(d=>{o.doc.nodesBetween(d.$from.pos,d.$to.pos,(u,f)=>{s&&s===u.type&&(c=!0,r&&t.setNodeMarkup(f,void 0,Rf(u.attrs,e))),i&&u.marks.length&&u.marks.forEach(h=>{i===h.type&&(c=!0,r&&t.addMark(f,f+u.nodeSize,i.create(Rf(h.attrs,e))))})})}),c},xw=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),Cw=()=>({tr:n,dispatch:e})=>{if(e){const t=new qe(n.doc);n.setSelection(t)}return!0},Ew=()=>({state:n,dispatch:e})=>tu(n,e),vw=()=>({state:n,dispatch:e})=>ru(n,e),Mw=()=>({state:n,dispatch:e})=>Ly(n,e),Tw=()=>({state:n,dispatch:e})=>zy(n,e),Nw=()=>({state:n,dispatch:e})=>$y(n,e);function Nl(n,e,t={},o={}){return jo(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:o.errorOnInvalidContent})}var Aw=(n,{errorOnInvalidContent:e,emitUpdate:t=!0,parseOptions:o={}}={})=>({editor:r,tr:s,dispatch:i,commands:l})=>{const{doc:c}=s;if(o.preserveWhitespace!=="full"){const d=Nl(n,r.schema,o,{errorOnInvalidContent:e??r.options.enableContentCheck});return i&&s.replaceWith(0,c.content.size,d).setMeta("preventUpdate",!t),!0}return i&&s.setMeta("preventUpdate",!t),l.insertContentAt({from:0,to:c.content.size},n,{parseOptions:o,errorOnInvalidContent:e??r.options.enableContentCheck})};function Pf(n,e){const t=Pt(e,n.schema),{from:o,to:r,empty:s}=n.selection,i=[];s?(n.storedMarks&&i.push(...n.storedMarks),i.push(...n.selection.$head.marks())):n.doc.nodesBetween(o,r,c=>{i.push(...c.marks)});const l=i.find(c=>c.type.name===t.name);return l?{...l.attrs}:{}}function Lf(n,e){const t=new jd(n);return e.forEach(o=>{o.steps.forEach(r=>{t.step(r)})}),t}function Bw(n){for(let e=0;e<n.edgeCount;e+=1){const{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}function Iw(n,e,t){const o=[];return n.nodesBetween(e.from,e.to,(r,s)=>{t(r)&&o.push({node:r,pos:s})}),o}function Ow(n,e){for(let t=n.depth;t>0;t-=1){const o=n.node(t);if(e(o))return{pos:t>0?n.before(t):0,start:n.start(t),depth:t,node:o}}}function Al(n){return e=>Ow(e.$from,n)}function q(n,e,t){return n.config[e]===void 0&&n.parent?q(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?q(n.parent,e,t):null}):n.config[e]}function Bl(n){return n.map(e=>{const t={name:e.name,options:e.options,storage:e.storage},o=q(e,"addExtensions",t);return o?[e,...Bl(o())]:e}).flat(10)}function Xr(n,e){const t=xn.fromSchema(e).serializeFragment(n),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(t),r.innerHTML}function Vf(n){return typeof n=="function"}function ae(n,e=void 0,...t){return Vf(n)?e?n.bind(e)(...t):n(...t):n}function _w(n={}){return Object.keys(n).length===0&&n.constructor===Object}function so(n){const e=n.filter(r=>r.type==="extension"),t=n.filter(r=>r.type==="node"),o=n.filter(r=>r.type==="mark");return{baseExtensions:e,nodeExtensions:t,markExtensions:o}}function $f(n){const e=[],{nodeExtensions:t,markExtensions:o}=so(n),r=[...t,...o],s={default:null,validate:void 0,rendered:!0,renderHTML:null,parseHTML:null,keepOnSplit:!0,isRequired:!1},i=t.filter(d=>d.name!=="text").map(d=>d.name),l=o.map(d=>d.name),c=[...i,...l];return n.forEach(d=>{const u={name:d.name,options:d.options,storage:d.storage,extensions:r},f=q(d,"addGlobalAttributes",u);if(!f)return;f().forEach(p=>{let m;Array.isArray(p.types)?m=p.types:p.types==="*"?m=c:p.types==="nodes"?m=i:p.types==="marks"?m=l:m=[],m.forEach(g=>{Object.entries(p.attributes).forEach(([y,k])=>{e.push({type:g,name:y,attribute:{...s,...k}})})})})}),r.forEach(d=>{const u={name:d.name,options:d.options,storage:d.storage},f=q(d,"addAttributes",u);if(!f)return;const h=f();Object.entries(h).forEach(([p,m])=>{const g={...s,...m};typeof(g==null?void 0:g.default)=="function"&&(g.default=g.default()),g!=null&&g.isRequired&&(g==null?void 0:g.default)===void 0&&delete g.default,e.push({type:d.name,name:p,attribute:g})})}),e}function nn(...n){return n.filter(e=>!!e).reduce((e,t)=>{const o={...e};return Object.entries(t).forEach(([r,s])=>{if(!o[r]){o[r]=s;return}if(r==="class"){const l=s?String(s).split(" "):[],c=o[r]?o[r].split(" "):[],d=l.filter(u=>!c.includes(u));o[r]=[...c,...d].join(" ")}else if(r==="style"){const l=s?s.split(";").map(u=>u.trim()).filter(Boolean):[],c=o[r]?o[r].split(";").map(u=>u.trim()).filter(Boolean):[],d=new Map;c.forEach(u=>{const[f,h]=u.split(":").map(p=>p.trim());d.set(f,h)}),l.forEach(u=>{const[f,h]=u.split(":").map(p=>p.trim());d.set(f,h)}),o[r]=Array.from(d.entries()).map(([u,f])=>`${u}: ${f}`).join("; ")}else o[r]=s}),o},{})}function Qr(n,e){return e.filter(t=>t.type===n.type.name).filter(t=>t.attribute.rendered).map(t=>t.attribute.renderHTML?t.attribute.renderHTML(n.attrs)||{}:{[t.name]:n.attrs[t.name]}).reduce((t,o)=>nn(t,o),{})}function Dw(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function zf(n,e){return"style"in n?n:{...n,getAttrs:t=>{const o=n.getAttrs?n.getAttrs(t):n.attrs;if(o===!1)return!1;const r=e.reduce((s,i)=>{const l=i.attribute.parseHTML?i.attribute.parseHTML(t):Dw(t.getAttribute(i.name));return l==null?s:{...s,[i.name]:l}},{});return{...o,...r}}}}function Ff(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&_w(t)?!1:t!=null))}function Hf(n){var e,t;const o={};return!((e=n==null?void 0:n.attribute)!=null&&e.isRequired)&&"default"in((n==null?void 0:n.attribute)||{})&&(o.default=n.attribute.default),((t=n==null?void 0:n.attribute)==null?void 0:t.validate)!==void 0&&(o.validate=n.attribute.validate),[n.name,o]}function jf(n,e){var t;const o=$f(n),{nodeExtensions:r,markExtensions:s}=so(n),i=(t=r.find(d=>q(d,"topNode")))==null?void 0:t.name,l=Object.fromEntries(r.map(d=>{const u=o.filter(k=>k.type===d.name),f={name:d.name,options:d.options,storage:d.storage,editor:e},h=n.reduce((k,x)=>{const b=q(x,"extendNodeSchema",f);return{...k,...b?b(d):{}}},{}),p=Ff({...h,content:ae(q(d,"content",f)),marks:ae(q(d,"marks",f)),group:ae(q(d,"group",f)),inline:ae(q(d,"inline",f)),atom:ae(q(d,"atom",f)),selectable:ae(q(d,"selectable",f)),draggable:ae(q(d,"draggable",f)),code:ae(q(d,"code",f)),whitespace:ae(q(d,"whitespace",f)),linebreakReplacement:ae(q(d,"linebreakReplacement",f)),defining:ae(q(d,"defining",f)),isolating:ae(q(d,"isolating",f)),attrs:Object.fromEntries(u.map(Hf))}),m=ae(q(d,"parseHTML",f));m&&(p.parseDOM=m.map(k=>zf(k,u)));const g=q(d,"renderHTML",f);g&&(p.toDOM=k=>g({node:k,HTMLAttributes:Qr(k,u)}));const y=q(d,"renderText",f);return y&&(p.toText=y),[d.name,p]})),c=Object.fromEntries(s.map(d=>{const u=o.filter(y=>y.type===d.name),f={name:d.name,options:d.options,storage:d.storage,editor:e},h=n.reduce((y,k)=>{const x=q(k,"extendMarkSchema",f);return{...y,...x?x(d):{}}},{}),p=Ff({...h,inclusive:ae(q(d,"inclusive",f)),excludes:ae(q(d,"excludes",f)),group:ae(q(d,"group",f)),spanning:ae(q(d,"spanning",f)),code:ae(q(d,"code",f)),attrs:Object.fromEntries(u.map(Hf))}),m=ae(q(d,"parseHTML",f));m&&(p.parseDOM=m.map(y=>zf(y,u)));const g=q(d,"renderHTML",f);return g&&(p.toDOM=y=>g({mark:y,HTMLAttributes:Qr(y,u)})),[d.name,p]}));return new yd({topNode:i,nodes:l,marks:c})}function Rw(n){const e=n.filter((t,o)=>n.indexOf(t)!==o);return Array.from(new Set(e))}function Wo(n){return n.sort((t,o)=>{const r=q(t,"priority")||100,s=q(o,"priority")||100;return r>s?-1:r<s?1:0})}function Il(n){const e=Wo(Bl(n)),t=Rw(e.map(o=>o.name));return t.length&&console.warn(`[tiptap warn]: Duplicate extension names found: [${t.map(o=>`'${o}'`).join(", ")}]. This can lead to issues.`),e}function Uf(n,e){const t=Il(n);return jf(t,e)}function Pw(n,e){const t=Uf(e),o=At.fromJSON(t,n);return Xr(o.content,t)}function Lw(n,e){const t=Uf(e),o=Ho(n);return Bt.fromSchema(t).parse(o).toJSON()}function Wf(n,e,t){const{from:o,to:r}=e,{blockSeparator:s=`
|
|
11
11
|
|
|
12
|
-
`,textSerializers:i={}}=t||{};let l="";return n.nodesBetween(o,r,(c,d,u,f)=>{var h;c.isBlock&&d>o&&(l+=s);const p=i==null?void 0:i[c.type.name];if(p)return u&&(l+=p({node:c,pos:d,parent:u,index:f,range:e})),!1;c.isText&&(l+=(h=c==null?void 0:c.text)==null?void 0:h.slice(Math.max(o,d)-d,r-d))}),l}function Vw(n,e){const t={from:0,to:n.content.size};return Wf(n,t,e)}function Kf(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function $w(n,e){const t=Ee(e,n.schema),{from:o,to:r}=n.selection,s=[];n.doc.nodesBetween(o,r,l=>{s.push(l)});const i=s.reverse().find(l=>l.type.name===t.name);return i?{...i.attrs}:{}}function qf(n,e){const t=Yr(typeof e=="string"?e:e.name,n.schema);return t==="node"?$w(n,e):t==="mark"?Pf(n,e):{}}function zw(n,e=JSON.stringify){const t={};return n.filter(o=>{const r=e(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function Fw(n){const e=zw(n);return e.length===1?e:e.filter((t,o)=>!e.filter((s,i)=>i!==o).some(s=>t.oldRange.from>=s.oldRange.from&&t.oldRange.to<=s.oldRange.to&&t.newRange.from>=s.newRange.from&&t.newRange.to<=s.newRange.to))}function Jf(n){const{mapping:e,steps:t}=n,o=[];return e.maps.forEach((r,s)=>{const i=[];if(r.ranges.length)r.forEach((l,c)=>{i.push({from:l,to:c})});else{const{from:l,to:c}=t[s];if(l===void 0||c===void 0)return;i.push({from:l,to:c})}i.forEach(({from:l,to:c})=>{const d=e.slice(s).map(l,-1),u=e.slice(s).map(c),f=e.invert().map(d,-1),h=e.invert().map(u);o.push({oldRange:{from:f,to:h},newRange:{from:d,to:u}})})}),Fw(o)}function Ol(n,e,t){const o=[];return n===e?t.resolve(n).marks().forEach(r=>{const s=t.resolve(n),i=Ml(s,r.type);i&&o.push({mark:r,...i})}):t.nodesBetween(n,e,(r,s)=>{!r||(r==null?void 0:r.nodeSize)===void 0||o.push(...r.marks.map(i=>({from:s,to:s+r.nodeSize,mark:i})))}),o}function Ko(n,e){return e.nodes[n]||e.marks[n]||null}function Zr(n,e,t){return Object.fromEntries(Object.entries(t).filter(([o])=>{const r=n.find(s=>s.type===e&&s.name===o);return r?r.attribute.keepOnSplit:!1}))}var Hw=(n,e=500)=>{let t="";const o=n.parentOffset;return n.parent.nodesBetween(Math.max(0,o-e),o,(r,s,i,l)=>{var c,d;const u=((d=(c=r.type.spec).toText)==null?void 0:d.call(c,{node:r,pos:s,parent:i,index:l}))||r.textContent||"%leaf%";t+=r.isAtom&&!r.isText?u:u.slice(0,Math.max(0,o-s))}),t};function _l(n,e,t={}){const{empty:o,ranges:r}=n.selection,s=e?Pt(e,n.schema):null;if(o)return!!(n.storedMarks||n.selection.$from.marks()).filter(f=>s?s.name===f.type.name:!0).find(f=>Jr(f.attrs,t,{strict:!1}));let i=0;const l=[];if(r.forEach(({$from:f,$to:h})=>{const p=f.pos,m=h.pos;n.doc.nodesBetween(p,m,(g,y)=>{if(s&&g.inlineContent&&!g.type.allowsMarkType(s))return!1;if(!g.isText&&!g.marks.length)return;const k=Math.max(p,y),x=Math.min(m,y+g.nodeSize),b=x-k;i+=b,l.push(...g.marks.map(S=>({mark:S,from:k,to:x})))})}),i===0)return!1;const c=l.filter(f=>s?s.name===f.mark.type.name:!0).filter(f=>Jr(f.mark.attrs,t,{strict:!1})).reduce((f,h)=>f+h.to-h.from,0),d=l.filter(f=>s?f.mark.type!==s&&f.mark.type.excludes(s):!0).reduce((f,h)=>f+h.to-h.from,0);return(c>0?c+d:c)>=i}function jw(n,e,t={}){if(!e)return Uo(n,null,t)||_l(n,null,t);const o=Yr(e,n.schema);return o==="node"?Uo(n,e,t):o==="mark"?_l(n,e,t):!1}function Gf(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function Yf(n,e){const{nodeExtensions:t}=so(e),o=t.find(i=>i.name===n);if(!o)return!1;const r={name:o.name,options:o.options,storage:o.storage},s=ae(q(o,"group",r));return typeof s!="string"?!1:s.split(" ").includes("list")}function es(n,{checkChildren:e=!0,ignoreWhitespace:t=!1}={}){var o;if(t){if(n.type.name==="hardBreak")return!0;if(n.isText)return/^\s*$/m.test((o=n.text)!=null?o:"")}if(n.isText)return!n.text;if(n.isAtom||n.isLeaf)return!1;if(n.content.childCount===0)return!0;if(e){let r=!0;return n.content.forEach(s=>{r!==!1&&(es(s,{ignoreWhitespace:t,checkChildren:e})||(r=!1))}),r}return!1}function Uw(n){return n instanceof Y}var Xf=class Tg{constructor(e){this.position=e}static fromJSON(e){return new Tg(e.position)}toJSON(){return{position:this.position}}};function Ww(n,e){const t=e.mapping.mapResult(n.position);return{position:new Xf(t.pos),mapResult:t}}function Kw(n){return new Xf(n)}function qw(n,e,t){var o;const{selection:r}=e;let s=null;if(Bf(r)&&(s=r.$cursor),s){const l=(o=n.storedMarks)!=null?o:s.marks();return s.parent.type.allowsMarkType(t)&&(!!t.isInSet(l)||!l.some(d=>d.type.excludes(t)))}const{ranges:i}=r;return i.some(({$from:l,$to:c})=>{let d=l.depth===0?n.doc.inlineContent&&n.doc.type.allowsMarkType(t):!1;return n.doc.nodesBetween(l.pos,c.pos,(u,f,h)=>{if(d)return!1;if(u.isInline){const p=!h||h.type.allowsMarkType(t),m=!!t.isInSet(u.marks)||!u.marks.some(g=>g.type.excludes(t));d=p&&m}return!d}),d})}var Jw=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const{selection:s}=t,{empty:i,ranges:l}=s,c=Pt(n,o.schema);if(r)if(i){const d=Pf(o,c);t.addStoredMark(c.create({...d,...e}))}else l.forEach(d=>{const u=d.$from.pos,f=d.$to.pos;o.doc.nodesBetween(u,f,(h,p)=>{const m=Math.max(p,u),g=Math.min(p+h.nodeSize,f);h.marks.find(k=>k.type===c)?h.marks.forEach(k=>{c===k.type&&t.addMark(m,g,c.create({...k.attrs,...e}))}):t.addMark(m,g,c.create(e))})});return qw(o,t,c)},Gw=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),Yw=(n,e={})=>({state:t,dispatch:o,chain:r})=>{const s=Ee(n,t.schema);let i;return t.selection.$anchor.sameParent(t.selection.$head)&&(i=t.selection.$anchor.parent.attrs),s.isTextblock?r().command(({commands:l})=>du(s,{...i,...e})(t)?!0:l.clearNodes()).command(({state:l})=>du(s,{...i,...e})(l,o)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Xw=n=>({tr:e,dispatch:t})=>{if(t){const{doc:o}=e,r=On(n,0,o.content.size),s=Y.create(o,r);e.setSelection(s)}return!0},Qw=(n,e)=>({tr:t,state:o,dispatch:r})=>{const{selection:s}=o;let i,l;return typeof e=="number"?(i=e,l=e):e&&"from"in e&&"to"in e?(i=e.from,l=e.to):(i=s.from,l=s.to),r&&t.doc.nodesBetween(i,l,(c,d)=>{c.isText||t.setNodeMarkup(d,void 0,{...c.attrs,dir:n})}),!0},Zw=n=>({tr:e,dispatch:t})=>{if(t){const{doc:o}=e,{from:r,to:s}=typeof n=="number"?{from:n,to:n}:n,i=Q.atStart(o).from,l=Q.atEnd(o).to,c=On(r,i,l),d=On(s,i,l),u=Q.create(o,c,d);e.setSelection(u)}return!0},eb=n=>({state:e,dispatch:t})=>{const o=Ee(n,e.schema);return Jy(o)(e,t)};function Qf(n,e){const t=n.storedMarks||n.selection.$to.parentOffset&&n.selection.$from.marks();if(t){const o=t.filter(r=>e==null?void 0:e.includes(r.type.name));n.tr.ensureMarks(o)}}var tb=({keepMarks:n=!0}={})=>({tr:e,state:t,dispatch:o,editor:r})=>{const{selection:s,doc:i}=e,{$from:l,$to:c}=s,d=r.extensionManager.attributes,u=Zr(d,l.node().type.name,l.node().attrs);if(s instanceof Y&&s.node.isBlock)return!l.parentOffset||!It(i,l.pos)?!1:(o&&(n&&Qf(t,r.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const f=c.parentOffset===c.parent.content.size,h=l.depth===0?void 0:Bw(l.node(-1).contentMatchAt(l.indexAfter(-1)));let p=f&&h?[{type:h,attrs:u}]:void 0,m=It(e.doc,e.mapping.map(l.pos),1,p);if(!p&&!m&&It(e.doc,e.mapping.map(l.pos),1,h?[{type:h}]:void 0)&&(m=!0,p=h?[{type:h,attrs:u}]:void 0),o){if(m&&(s instanceof Q&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,p),h&&!f&&!l.parentOffset&&l.parent.type!==h)){const g=e.mapping.map(l.before()),y=e.doc.resolve(g);l.node(-1).canReplaceWith(y.index(),y.index()+1,h)&&e.setNodeMarkup(e.mapping.map(l.before()),h)}n&&Qf(t,r.extensionManager.splittableMarks),e.scrollIntoView()}return m},nb=(n,e={})=>({tr:t,state:o,dispatch:r,editor:s})=>{var i;const l=Ee(n,o.schema),{$from:c,$to:d}=o.selection,u=o.selection.node;if(u&&u.isBlock||c.depth<2||!c.sameParent(d))return!1;const f=c.node(-1);if(f.type!==l)return!1;const h=s.extensionManager.attributes;if(c.parent.content.size===0&&c.node(-1).childCount===c.indexAfter(-1)){if(c.depth===2||c.node(-3).type!==l||c.index(-2)!==c.node(-2).childCount-1)return!1;if(r){let k=P.empty;const x=c.index(-1)?1:c.index(-2)?2:3;for(let T=c.depth-x;T>=c.depth-3;T-=1)k=P.from(c.node(T).copy(k));const b=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,S={...Zr(h,c.node().type.name,c.node().attrs),...e},C=((i=l.contentMatch.defaultType)==null?void 0:i.createAndFill(S))||void 0;k=k.append(P.from(l.createAndFill(null,C)||void 0));const v=c.before(c.depth-(x-1));t.replace(v,c.after(-b),new U(k,4-x,0));let E=-1;t.doc.nodesBetween(v,t.doc.content.size,(T,M)=>{if(E>-1)return!1;T.isTextblock&&T.content.size===0&&(E=M+1)}),E>-1&&t.setSelection(Q.near(t.doc.resolve(E))),t.scrollIntoView()}return!0}const p=d.pos===c.end()?f.contentMatchAt(0).defaultType:null,m={...Zr(h,f.type.name,f.attrs),...e},g={...Zr(h,c.node().type.name,c.node().attrs),...e};t.delete(c.pos,d.pos);const y=p?[{type:l,attrs:m},{type:p,attrs:g}]:[{type:l,attrs:m}];if(!It(t.doc,c.pos,2))return!1;if(r){const{selection:k,storedMarks:x}=o,{splittableMarks:b}=s.extensionManager,S=x||k.$to.parentOffset&&k.$from.marks();if(t.split(c.pos,2,y).scrollIntoView(),!S||!r)return!0;const C=S.filter(v=>b.includes(v.type.name));t.ensureMarks(C)}return!0},Dl=(n,e)=>{const t=Al(i=>i.type===e)(n.selection);if(!t)return!0;const o=n.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(o===void 0)return!0;const r=n.doc.nodeAt(o);return t.node.type===(r==null?void 0:r.type)&&En(n.doc,t.pos)&&n.join(t.pos),!0},Rl=(n,e)=>{const t=Al(i=>i.type===e)(n.selection);if(!t)return!0;const o=n.doc.resolve(t.start).after(t.depth);if(o===void 0)return!0;const r=n.doc.nodeAt(o);return t.node.type===(r==null?void 0:r.type)&&En(n.doc,o)&&n.join(o),!0},ob=(n,e,t,o={})=>({editor:r,tr:s,state:i,dispatch:l,chain:c,commands:d,can:u})=>{const{extensions:f,splittableMarks:h}=r.extensionManager,p=Ee(n,i.schema),m=Ee(e,i.schema),{selection:g,storedMarks:y}=i,{$from:k,$to:x}=g,b=k.blockRange(x),S=y||g.$to.parentOffset&&g.$from.marks();if(!b)return!1;const C=Al(v=>Yf(v.type.name,f))(g);if(b.depth>=1&&C&&b.depth-C.depth<=1){if(C.node.type===p)return d.liftListItem(m);if(Yf(C.node.type.name,f)&&p.validContent(C.node.content)&&l)return c().command(()=>(s.setNodeMarkup(C.pos,p),!0)).command(()=>Dl(s,p)).command(()=>Rl(s,p)).run()}return!t||!S||!l?c().command(()=>u().wrapInList(p,o)?!0:d.clearNodes()).wrapInList(p,o).command(()=>Dl(s,p)).command(()=>Rl(s,p)).run():c().command(()=>{const v=u().wrapInList(p,o),E=S.filter(T=>h.includes(T.type.name));return s.ensureMarks(E),v?!0:d.clearNodes()}).wrapInList(p,o).command(()=>Dl(s,p)).command(()=>Rl(s,p)).run()},rb=(n,e={},t={})=>({state:o,commands:r})=>{const{extendEmptyMarkRange:s=!1}=t,i=Pt(n,o.schema);return _l(o,i,e)?r.unsetMark(i,{extendEmptyMarkRange:s}):r.setMark(i,e)},sb=(n,e,t={})=>({state:o,commands:r})=>{const s=Ee(n,o.schema),i=Ee(e,o.schema),l=Uo(o,s,t);let c;return o.selection.$anchor.sameParent(o.selection.$head)&&(c=o.selection.$anchor.parent.attrs),l?r.setNode(i,c):r.setNode(s,{...c,...t})},ib=(n,e={})=>({state:t,commands:o})=>{const r=Ee(n,t.schema);return Uo(t,r,e)?o.lift(r):o.wrapIn(r,e)},lb=()=>({state:n,dispatch:e})=>{const t=n.plugins;for(let o=0;o<t.length;o+=1){const r=t[o];let s;if(r.spec.isInputRules&&(s=r.getState(n))){if(e){const i=n.tr,l=s.transform;for(let c=l.steps.length-1;c>=0;c-=1)i.step(l.steps[c].invert(l.docs[c]));if(s.text){const c=i.doc.resolve(s.from).marks();i.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else i.delete(s.from,s.to)}return!0}}return!1},ab=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,{empty:o,ranges:r}=t;return o||e&&r.forEach(s=>{n.removeMark(s.$from.pos,s.$to.pos)}),!0},cb=(n,e={})=>({tr:t,state:o,dispatch:r})=>{var s;const{extendEmptyMarkRange:i=!1}=e,{selection:l}=t,c=Pt(n,o.schema),{$from:d,empty:u,ranges:f}=l;if(!r)return!0;if(u&&i){let{from:h,to:p}=l;const m=(s=d.marks().find(y=>y.type===c))==null?void 0:s.attrs,g=Ml(d,c,m);g&&(h=g.from,p=g.to),t.removeMark(h,p,c)}else f.forEach(h=>{t.removeMark(h.$from.pos,h.$to.pos,c)});return t.removeStoredMark(c),!0},db=n=>({tr:e,state:t,dispatch:o})=>{const{selection:r}=t;let s,i;return typeof n=="number"?(s=n,i=n):n&&"from"in n&&"to"in n?(s=n.from,i=n.to):(s=r.from,i=r.to),o&&e.doc.nodesBetween(s,i,(l,c)=>{if(l.isText)return;const d={...l.attrs};delete d.dir,e.setNodeMarkup(c,void 0,d)}),!0},ub=(n,e={})=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=Yr(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=Ee(n,o.schema)),l==="mark"&&(i=Pt(n,o.schema));let c=!1;return t.selection.ranges.forEach(d=>{const u=d.$from.pos,f=d.$to.pos;let h,p,m,g;t.selection.empty?o.doc.nodesBetween(u,f,(y,k)=>{s&&s===y.type&&(c=!0,m=Math.max(k,u),g=Math.min(k+y.nodeSize,f),h=k,p=y)}):o.doc.nodesBetween(u,f,(y,k)=>{k<u&&s&&s===y.type&&(c=!0,m=Math.max(k,u),g=Math.min(k+y.nodeSize,f),h=k,p=y),k>=u&&k<=f&&(s&&s===y.type&&(c=!0,r&&t.setNodeMarkup(k,void 0,{...y.attrs,...e})),i&&y.marks.length&&y.marks.forEach(x=>{if(i===x.type&&(c=!0,r)){const b=Math.max(k,u),S=Math.min(k+y.nodeSize,f);t.addMark(b,S,i.create({...x.attrs,...e}))}}))}),p&&(h!==void 0&&r&&t.setNodeMarkup(h,void 0,{...p.attrs,...e}),i&&p.marks.length&&p.marks.forEach(y=>{i===y.type&&r&&t.addMark(m,g,i.create({...y.attrs,...e}))}))}),c},fb=(n,e={})=>({state:t,dispatch:o})=>{const r=Ee(n,t.schema);return Fy(r,e)(t,o)},hb=(n,e={})=>({state:t,dispatch:o})=>{const r=Ee(n,t.schema);return Hy(r,e)(t,o)},pb=class{constructor(){this.callbacks={}}on(n,e){return this.callbacks[n]||(this.callbacks[n]=[]),this.callbacks[n].push(e),this}emit(n,...e){const t=this.callbacks[n];return t&&t.forEach(o=>o.apply(this,e)),this}off(n,e){const t=this.callbacks[n];return t&&(e?this.callbacks[n]=t.filter(o=>o!==e):delete this.callbacks[n]),this}once(n,e){const t=(...o)=>{this.off(n,t),e.apply(this,o)};return this.on(n,t)}removeAllListeners(){this.callbacks={}}},mb=class{constructor(n){var e;this.find=n.find,this.handler=n.handler,this.undoable=(e=n.undoable)!=null?e:!0}},gb=(n,e)=>{if(Tl(e))return e.exec(n);const t=e(n);if(!t)return null;const o=[t.text];return o.index=t.index,o.input=n,o.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),o.push(t.replaceWith)),o};function ts(n){var e;const{editor:t,from:o,to:r,text:s,rules:i,plugin:l}=n,{view:c}=t;if(c.composing)return!1;const d=c.state.doc.resolve(o);if(d.parent.type.spec.code||(e=d.nodeBefore||d.nodeAfter)!=null&&e.marks.find(h=>h.type.spec.code))return!1;let u=!1;const f=Hw(d)+s;return i.forEach(h=>{if(u)return;const p=gb(f,h.find);if(!p)return;const m=c.state.tr,g=Kr({state:c.state,transaction:m}),y={from:o-(p[0].length-s.length),to:r},{commands:k,chain:x,can:b}=new qr({editor:t,state:g});h.handler({state:g,range:y,match:p,commands:k,chain:x,can:b})===null||!m.steps.length||(h.undoable&&m.setMeta(l,{transform:m,from:o,to:r,text:s}),c.dispatch(m),u=!0)}),u}function yb(n){const{editor:e,rules:t}=n,o=new pe({state:{init(){return null},apply(r,s,i){const l=r.getMeta(o);if(l)return l;const c=r.getMeta("applyInputRules");return!!c&&setTimeout(()=>{let{text:u}=c;typeof u=="string"?u=u:u=Xr(P.from(u),i.schema);const{from:f}=c,h=f+u.length;ts({editor:e,from:f,to:h,text:u,rules:t,plugin:o})}),r.selectionSet||r.docChanged?null:s}},props:{handleTextInput(r,s,i,l){return ts({editor:e,from:s,to:i,text:l,rules:t,plugin:o})},handleDOMEvents:{compositionend:r=>(setTimeout(()=>{const{$cursor:s}=r.state.selection;s&&ts({editor:e,from:s.pos,to:s.pos,text:"",rules:t,plugin:o})}),!1)},handleKeyDown(r,s){if(s.key!=="Enter")return!1;const{$cursor:i}=r.state.selection;return i?ts({editor:e,from:i.pos,to:i.pos,text:`
|
|
13
|
-
`,rules:t,plugin:o}):!1}},isInputRules:!0});return o}function kb(n){return Object.prototype.toString.call(n).slice(8,-1)}function ns(n){return kb(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function Zf(n,e){const t={...n};return ns(n)&&ns(e)&&Object.keys(e).forEach(o=>{ns(e[o])&&ns(n[o])?t[o]=Zf(n[o],e[o]):t[o]=e[o]}),t}var Pl=class{constructor(n={}){this.type="extendable",this.parent=null,this.child=null,this.name="",this.config={name:this.name},this.config={...this.config,...n},this.name=this.config.name}get options(){return{...ae(q(this,"addOptions",{name:this.name}))||{}}}get storage(){return{...ae(q(this,"addStorage",{name:this.name,options:this.options}))||{}}}configure(n={}){const e=this.extend({...this.config,addOptions:()=>Zf(this.options,n)});return e.name=this.name,e.parent=this.parent,e}extend(n={}){const e=new this.constructor({...this.config,...n});return e.parent=this,this.child=e,e.name="name"in n?n.name:e.parent.name,e}},io=class Mg extends Pl{constructor(){super(...arguments),this.type="mark"}static create(e={}){const t=typeof e=="function"?e():e;return new Mg(t)}static handleExit({editor:e,mark:t}){const{tr:o}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){const i=r.marks();if(!!!i.find(d=>(d==null?void 0:d.type.name)===t.name))return!1;const c=i.find(d=>(d==null?void 0:d.type.name)===t.name);return c&&o.removeStoredMark(c),o.insertText(" ",r.pos),e.view.dispatch(o),!0}return!1}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}};function wb(n){return typeof n=="number"}var bb=class{constructor(n){this.find=n.find,this.handler=n.handler}},Sb=(n,e,t)=>{if(Tl(e))return[...n.matchAll(e)];const o=e(n,t);return o?o.map(r=>{const s=[r.text];return s.index=r.index,s.input=n,s.data=r.data,r.replaceWith&&(r.text.includes(r.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),s.push(r.replaceWith)),s}):[]};function xb(n){const{editor:e,state:t,from:o,to:r,rule:s,pasteEvent:i,dropEvent:l}=n,{commands:c,chain:d,can:u}=new qr({editor:e,state:t}),f=[];return t.doc.nodesBetween(o,r,(p,m)=>{var g,y,k,x,b;if((y=(g=p.type)==null?void 0:g.spec)!=null&&y.code||!(p.isText||p.isTextblock||p.isInline))return;const S=(b=(x=(k=p.content)==null?void 0:k.size)!=null?x:p.nodeSize)!=null?b:0,C=Math.max(o,m),v=Math.min(r,m+S);if(C>=v)return;const E=p.isText?p.text||"":p.textBetween(C-m,v-m,void 0,"");Sb(E,s.find,i).forEach(M=>{if(M.index===void 0)return;const A=C+M.index+1,B=A+M[0].length,I={from:t.tr.mapping.map(A),to:t.tr.mapping.map(B)},O=s.handler({state:t,range:I,match:M,commands:c,chain:d,can:u,pasteEvent:i,dropEvent:l});f.push(O)})}),f.every(p=>p!==null)}var rs=null,Cb=n=>{var e;const t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)==null||e.setData("text/html",n),t};function Eb(n){const{editor:e,rules:t}=n;let o=null,r=!1,s=!1,i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,l;try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}const c=({state:u,from:f,to:h,rule:p,pasteEvt:m})=>{const g=u.tr,y=Kr({state:u,transaction:g});if(!(!xb({editor:e,state:y,from:Math.max(f-1,0),to:h.b-1,rule:p,pasteEvent:m,dropEvent:l})||!g.steps.length)){try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}return i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,g}};return t.map(u=>new pe({view(f){const h=m=>{var g;o=(g=f.dom.parentElement)!=null&&g.contains(m.target)?f.dom.parentElement:null,o&&(rs=e)},p=()=>{rs&&(rs=null)};return window.addEventListener("dragstart",h),window.addEventListener("dragend",p),{destroy(){window.removeEventListener("dragstart",h),window.removeEventListener("dragend",p)}}},props:{handleDOMEvents:{drop:(f,h)=>{if(s=o===f.dom.parentElement,l=h,!s){const p=rs;p!=null&&p.isEditable&&setTimeout(()=>{const m=p.state.selection;m&&p.commands.deleteRange({from:m.from,to:m.to})},10)}return!1},paste:(f,h)=>{var p;const m=(p=h.clipboardData)==null?void 0:p.getData("text/html");return i=h,r=!!(m!=null&&m.includes("data-pm-slice")),!1}}},appendTransaction:(f,h,p)=>{const m=f[0],g=m.getMeta("uiEvent")==="paste"&&!r,y=m.getMeta("uiEvent")==="drop"&&!s,k=m.getMeta("applyPasteRules"),x=!!k;if(!g&&!y&&!x)return;if(x){let{text:C}=k;typeof C=="string"?C=C:C=Xr(P.from(C),p.schema);const{from:v}=k,E=v+C.length,T=Cb(C);return c({rule:u,state:p,from:v,to:{b:E},pasteEvt:T})}const b=h.doc.content.findDiffStart(p.doc.content),S=h.doc.content.findDiffEnd(p.doc.content);if(!(!wb(b)||!S||b===S.b))return c({rule:u,state:p,from:b,to:S,pasteEvt:i})}}))}var ss=class{constructor(n,e){this.splittableMarks=[],this.editor=e,this.baseExtensions=n,this.extensions=Il(n),this.schema=jf(this.extensions,e),this.setupExtensions()}get commands(){return this.extensions.reduce((n,e)=>{const t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:Ko(e.name,this.schema)},o=q(e,"addCommands",t);return o?{...n,...o()}:n},{})}get plugins(){const{editor:n}=this;return Wo([...this.extensions].reverse()).flatMap(o=>{const r={name:o.name,options:o.options,storage:this.editor.extensionStorage[o.name],editor:n,type:Ko(o.name,this.schema)},s=[],i=q(o,"addKeyboardShortcuts",r);let l={};if(o.type==="mark"&&q(o,"exitable",r)&&(l.ArrowRight=()=>io.handleExit({editor:n,mark:o})),i){const h=Object.fromEntries(Object.entries(i()).map(([p,m])=>[p,()=>m({editor:n})]));l={...l,...h}}const c=Vk(l);s.push(c);const d=q(o,"addInputRules",r);if(Gf(o,n.options.enableInputRules)&&d){const h=d();if(h&&h.length){const p=yb({editor:n,rules:h}),m=Array.isArray(p)?p:[p];s.push(...m)}}const u=q(o,"addPasteRules",r);if(Gf(o,n.options.enablePasteRules)&&u){const h=u();if(h&&h.length){const p=Eb({editor:n,rules:h});s.push(...p)}}const f=q(o,"addProseMirrorPlugins",r);if(f){const h=f();s.push(...h)}return s})}get attributes(){return $f(this.extensions)}get nodeViews(){const{editor:n}=this,{nodeExtensions:e}=so(this.extensions);return Object.fromEntries(e.filter(t=>!!q(t,"addNodeView")).map(t=>{const o=this.attributes.filter(c=>c.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:n,type:Ee(t.name,this.schema)},s=q(t,"addNodeView",r);if(!s)return[];const i=s();if(!i)return[];const l=(c,d,u,f,h)=>{const p=Qr(c,o);return i({node:c,view:d,getPos:u,decorations:f,innerDecorations:h,editor:n,extension:t,HTMLAttributes:p})};return[t.name,l]}))}dispatchTransaction(n){const{editor:e}=this;return Wo([...this.extensions].reverse()).reduceRight((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:Ko(r.name,this.schema)},i=q(r,"dispatchTransaction",s);return i?l=>{i.call(s,{transaction:l,next:o})}:o},n)}transformPastedHTML(n){const{editor:e}=this;return Wo([...this.extensions]).reduce((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:Ko(r.name,this.schema)},i=q(r,"transformPastedHTML",s);return i?(l,c)=>{const d=o(l,c);return i.call(s,d)}:o},n||(o=>o))}get markViews(){const{editor:n}=this,{markExtensions:e}=so(this.extensions);return Object.fromEntries(e.filter(t=>!!q(t,"addMarkView")).map(t=>{const o=this.attributes.filter(l=>l.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:n,type:Pt(t.name,this.schema)},s=q(t,"addMarkView",r);if(!s)return[];const i=(l,c,d)=>{const u=Qr(l,o);return s()({mark:l,view:c,inline:d,editor:n,extension:t,HTMLAttributes:u,updateAttributes:f=>{Vb(l,n,f)}})};return[t.name,i]}))}setupExtensions(){const n=this.extensions;this.editor.extensionStorage=Object.fromEntries(n.map(e=>[e.name,e.storage])),n.forEach(e=>{var t;const o={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:Ko(e.name,this.schema)};e.type==="mark"&&((t=ae(q(e,"keepOnSplit",o)))==null||t)&&this.splittableMarks.push(e.name);const r=q(e,"onBeforeCreate",o),s=q(e,"onCreate",o),i=q(e,"onUpdate",o),l=q(e,"onSelectionUpdate",o),c=q(e,"onTransaction",o),d=q(e,"onFocus",o),u=q(e,"onBlur",o),f=q(e,"onDestroy",o);r&&this.editor.on("beforeCreate",r),s&&this.editor.on("create",s),i&&this.editor.on("update",i),l&&this.editor.on("selectionUpdate",l),c&&this.editor.on("transaction",c),d&&this.editor.on("focus",d),u&&this.editor.on("blur",u),f&&this.editor.on("destroy",f)})}};ss.resolve=Il,ss.sort=Wo,ss.flatten=Bl;var vb={};vl(vb,{ClipboardTextSerializer:()=>eh,Commands:()=>th,Delete:()=>nh,Drop:()=>oh,Editable:()=>rh,FocusEvents:()=>ih,Keymap:()=>lh,Paste:()=>ah,Tabindex:()=>ch,TextDirection:()=>dh,focusEventsPluginKey:()=>sh});var de=class Ng extends Pl{constructor(){super(...arguments),this.type="extension"}static create(e={}){const t=typeof e=="function"?e():e;return new Ng(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}},eh=de.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new pe({key:new Ce("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:n}=this,{state:e,schema:t}=n,{doc:o,selection:r}=e,{ranges:s}=r,i=Math.min(...s.map(u=>u.$from.pos)),l=Math.max(...s.map(u=>u.$to.pos)),c=Kf(t);return Wf(o,{from:i,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:c})}}})]}}),th=de.create({name:"commands",addCommands(){return{...Mf}}}),nh=de.create({name:"delete",onUpdate({transaction:n,appendedTransactions:e}){var t,o,r;const s=()=>{var i,l,c,d;if((d=(c=(l=(i=this.editor.options.coreExtensionOptions)==null?void 0:i.delete)==null?void 0:l.filterTransaction)==null?void 0:c.call(l,n))!=null?d:n.getMeta("y-sync$"))return;const u=Lf(n.before,[n,...e]);Jf(u).forEach(p=>{u.mapping.mapResult(p.oldRange.from).deletedAfter&&u.mapping.mapResult(p.oldRange.to).deletedBefore&&u.before.nodesBetween(p.oldRange.from,p.oldRange.to,(m,g)=>{const y=g+m.nodeSize-2,k=p.oldRange.from<=g&&y<=p.oldRange.to;this.editor.emit("delete",{type:"node",node:m,from:g,to:y,newFrom:u.mapping.map(g),newTo:u.mapping.map(y),deletedRange:p.oldRange,newRange:p.newRange,partial:!k,editor:this.editor,transaction:n,combinedTransform:u})})});const h=u.mapping;u.steps.forEach((p,m)=>{var g,y;if(p instanceof rt){const k=h.slice(m).map(p.from,-1),x=h.slice(m).map(p.to),b=h.invert().map(k,-1),S=h.invert().map(x),C=(g=u.doc.nodeAt(k-1))==null?void 0:g.marks.some(E=>E.eq(p.mark)),v=(y=u.doc.nodeAt(x))==null?void 0:y.marks.some(E=>E.eq(p.mark));this.editor.emit("delete",{type:"mark",mark:p.mark,from:p.from,to:p.to,deletedRange:{from:b,to:S},newRange:{from:k,to:x},partial:!!(v||C),editor:this.editor,transaction:n,combinedTransform:u})}})};(r=(o=(t=this.editor.options.coreExtensionOptions)==null?void 0:t.delete)==null?void 0:o.async)==null||r?setTimeout(s,0):s()}}),oh=de.create({name:"drop",addProseMirrorPlugins(){return[new pe({key:new Ce("tiptapDrop"),props:{handleDrop:(n,e,t,o)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:o})}}})]}}),rh=de.create({name:"editable",addProseMirrorPlugins(){return[new pe({key:new Ce("editable"),props:{editable:()=>this.editor.options.editable}})]}}),sh=new Ce("focusEvents"),ih=de.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new pe({key:sh,props:{handleDOMEvents:{focus:(e,t)=>{n.isFocused=!0;const o=n.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(o),!1},blur:(e,t)=>{n.isFocused=!1;const o=n.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(o),!1}}}})]}}),lh=de.create({name:"keymap",addKeyboardShortcuts(){const n=()=>this.editor.commands.first(({commands:i})=>[()=>i.undoInputRule(),()=>i.command(({tr:l})=>{const{selection:c,doc:d}=l,{empty:u,$anchor:f}=c,{pos:h,parent:p}=f,m=f.parent.isTextblock&&h>0?l.doc.resolve(h-1):f,g=m.parent.type.spec.isolating,y=f.pos-f.parentOffset,k=g&&m.parent.childCount===1?y===f.pos:ee.atStart(d).from===h;return!u||!p.type.isTextblock||p.textContent.length||!k||k&&f.parent.type.name==="paragraph"?!1:i.clearNodes()}),()=>i.deleteSelection(),()=>i.joinBackward(),()=>i.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:i})=>[()=>i.deleteSelection(),()=>i.deleteCurrentNode(),()=>i.joinForward(),()=>i.selectNodeForward()]),o={Enter:()=>this.editor.commands.first(({commands:i})=>[()=>i.newlineInCode(),()=>i.createParagraphNear(),()=>i.liftEmptyBlock(),()=>i.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:n,"Mod-Backspace":n,"Shift-Backspace":n,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},r={...o},s={...o,"Ctrl-h":n,"Alt-Backspace":n,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Gr()||Df()?s:r},addProseMirrorPlugins(){return[new pe({key:new Ce("clearDocument"),appendTransaction:(n,e,t)=>{if(n.some(g=>g.getMeta("composition")))return;const o=n.some(g=>g.docChanged)&&!e.doc.eq(t.doc),r=n.some(g=>g.getMeta("preventClearDocument"));if(!o||r)return;const{empty:s,from:i,to:l}=e.selection,c=ee.atStart(e.doc).from,d=ee.atEnd(e.doc).to;if(s||!(i===c&&l===d)||!es(t.doc))return;const h=t.tr,p=Kr({state:t,transaction:h}),{commands:m}=new qr({editor:this.editor,state:p});if(m.clearNodes(),!!h.steps.length)return h}})]}}),ah=de.create({name:"paste",addProseMirrorPlugins(){return[new pe({key:new Ce("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),ch=de.create({name:"tabindex",addProseMirrorPlugins(){return[new pe({key:new Ce("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}}),dh=de.create({name:"textDirection",addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];const{nodeExtensions:n}=so(this.extensions);return[{types:n.filter(e=>e.name!=="text").map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{const t=e.getAttribute("dir");return t&&(t==="ltr"||t==="rtl"||t==="auto")?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new pe({key:new Ce("textDirection"),props:{attributes:()=>{const n=this.options.direction;return n?{dir:n}:{}}}})]}}),Tb=class br{constructor(e,t,o=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=o,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return(e=this.actualDepth)!=null?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,o=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,o=this.to-1}this.editor.commands.insertContentAt({from:t,to:o},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new br(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new br(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new br(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,o)=>{const r=t.isBlock&&!t.isTextblock,s=t.isAtom&&!t.isText,i=t.isInline,l=this.pos+o+(s?0:1);if(l<0||l>this.resolvedPos.doc.nodeSize-2)return;const c=this.resolvedPos.doc.resolve(l);if(!r&&!i&&c.depth<=this.depth)return;const d=new br(c,this.editor,r,r||i?t:null);r&&(d.actualDepth=this.depth+1),e.push(d)}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,t={}){let o=null,r=this.parent;for(;r&&!o;){if(r.node.type.name===e)if(Object.keys(t).length>0){const s=r.node.attrs,i=Object.keys(t);for(let l=0;l<i.length;l+=1){const c=i[l];if(s[c]!==t[c])break}}else o=r;r=r.parent}return o}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},o=!1){let r=[];if(!this.children||this.children.length===0)return r;const s=Object.keys(t);return this.children.forEach(i=>{o&&r.length>0||(i.node.type.name===e&&s.every(c=>t[c]===i.node.attrs[c])&&r.push(i),!(o&&r.length>0)&&(r=r.concat(i.querySelectorAll(e,t,o))))}),r}setAttribute(e){const{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},Mb=`.ProseMirror {
|
|
12
|
+
`,textSerializers:i={}}=t||{};let l="";return n.nodesBetween(o,r,(c,d,u,f)=>{var h;c.isBlock&&d>o&&(l+=s);const p=i==null?void 0:i[c.type.name];if(p)return u&&(l+=p({node:c,pos:d,parent:u,index:f,range:e})),!1;c.isText&&(l+=(h=c==null?void 0:c.text)==null?void 0:h.slice(Math.max(o,d)-d,r-d))}),l}function Vw(n,e){const t={from:0,to:n.content.size};return Wf(n,t,e)}function Kf(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function $w(n,e){const t=Ee(e,n.schema),{from:o,to:r}=n.selection,s=[];n.doc.nodesBetween(o,r,l=>{s.push(l)});const i=s.reverse().find(l=>l.type.name===t.name);return i?{...i.attrs}:{}}function qf(n,e){const t=Yr(typeof e=="string"?e:e.name,n.schema);return t==="node"?$w(n,e):t==="mark"?Pf(n,e):{}}function zw(n,e=JSON.stringify){const t={};return n.filter(o=>{const r=e(o);return Object.prototype.hasOwnProperty.call(t,r)?!1:t[r]=!0})}function Fw(n){const e=zw(n);return e.length===1?e:e.filter((t,o)=>!e.filter((s,i)=>i!==o).some(s=>t.oldRange.from>=s.oldRange.from&&t.oldRange.to<=s.oldRange.to&&t.newRange.from>=s.newRange.from&&t.newRange.to<=s.newRange.to))}function Jf(n){const{mapping:e,steps:t}=n,o=[];return e.maps.forEach((r,s)=>{const i=[];if(r.ranges.length)r.forEach((l,c)=>{i.push({from:l,to:c})});else{const{from:l,to:c}=t[s];if(l===void 0||c===void 0)return;i.push({from:l,to:c})}i.forEach(({from:l,to:c})=>{const d=e.slice(s).map(l,-1),u=e.slice(s).map(c),f=e.invert().map(d,-1),h=e.invert().map(u);o.push({oldRange:{from:f,to:h},newRange:{from:d,to:u}})})}),Fw(o)}function Ol(n,e,t){const o=[];return n===e?t.resolve(n).marks().forEach(r=>{const s=t.resolve(n),i=Tl(s,r.type);i&&o.push({mark:r,...i})}):t.nodesBetween(n,e,(r,s)=>{!r||(r==null?void 0:r.nodeSize)===void 0||o.push(...r.marks.map(i=>({from:s,to:s+r.nodeSize,mark:i})))}),o}function Ko(n,e){return e.nodes[n]||e.marks[n]||null}function Zr(n,e,t){return Object.fromEntries(Object.entries(t).filter(([o])=>{const r=n.find(s=>s.type===e&&s.name===o);return r?r.attribute.keepOnSplit:!1}))}var Hw=(n,e=500)=>{let t="";const o=n.parentOffset;return n.parent.nodesBetween(Math.max(0,o-e),o,(r,s,i,l)=>{var c,d;const u=((d=(c=r.type.spec).toText)==null?void 0:d.call(c,{node:r,pos:s,parent:i,index:l}))||r.textContent||"%leaf%";t+=r.isAtom&&!r.isText?u:u.slice(0,Math.max(0,o-s))}),t};function _l(n,e,t={}){const{empty:o,ranges:r}=n.selection,s=e?Pt(e,n.schema):null;if(o)return!!(n.storedMarks||n.selection.$from.marks()).filter(f=>s?s.name===f.type.name:!0).find(f=>Jr(f.attrs,t,{strict:!1}));let i=0;const l=[];if(r.forEach(({$from:f,$to:h})=>{const p=f.pos,m=h.pos;n.doc.nodesBetween(p,m,(g,y)=>{if(s&&g.inlineContent&&!g.type.allowsMarkType(s))return!1;if(!g.isText&&!g.marks.length)return;const k=Math.max(p,y),x=Math.min(m,y+g.nodeSize),b=x-k;i+=b,l.push(...g.marks.map(S=>({mark:S,from:k,to:x})))})}),i===0)return!1;const c=l.filter(f=>s?s.name===f.mark.type.name:!0).filter(f=>Jr(f.mark.attrs,t,{strict:!1})).reduce((f,h)=>f+h.to-h.from,0),d=l.filter(f=>s?f.mark.type!==s&&f.mark.type.excludes(s):!0).reduce((f,h)=>f+h.to-h.from,0);return(c>0?c+d:c)>=i}function jw(n,e,t={}){if(!e)return Uo(n,null,t)||_l(n,null,t);const o=Yr(e,n.schema);return o==="node"?Uo(n,e,t):o==="mark"?_l(n,e,t):!1}function Gf(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function Yf(n,e){const{nodeExtensions:t}=so(e),o=t.find(i=>i.name===n);if(!o)return!1;const r={name:o.name,options:o.options,storage:o.storage},s=ae(q(o,"group",r));return typeof s!="string"?!1:s.split(" ").includes("list")}function es(n,{checkChildren:e=!0,ignoreWhitespace:t=!1}={}){var o;if(t){if(n.type.name==="hardBreak")return!0;if(n.isText)return/^\s*$/m.test((o=n.text)!=null?o:"")}if(n.isText)return!n.text;if(n.isAtom||n.isLeaf)return!1;if(n.content.childCount===0)return!0;if(e){let r=!0;return n.content.forEach(s=>{r!==!1&&(es(s,{ignoreWhitespace:t,checkChildren:e})||(r=!1))}),r}return!1}function Uw(n){return n instanceof Y}var Xf=class Mg{constructor(e){this.position=e}static fromJSON(e){return new Mg(e.position)}toJSON(){return{position:this.position}}};function Ww(n,e){const t=e.mapping.mapResult(n.position);return{position:new Xf(t.pos),mapResult:t}}function Kw(n){return new Xf(n)}function qw(n,e,t){var o;const{selection:r}=e;let s=null;if(Bf(r)&&(s=r.$cursor),s){const l=(o=n.storedMarks)!=null?o:s.marks();return s.parent.type.allowsMarkType(t)&&(!!t.isInSet(l)||!l.some(d=>d.type.excludes(t)))}const{ranges:i}=r;return i.some(({$from:l,$to:c})=>{let d=l.depth===0?n.doc.inlineContent&&n.doc.type.allowsMarkType(t):!1;return n.doc.nodesBetween(l.pos,c.pos,(u,f,h)=>{if(d)return!1;if(u.isInline){const p=!h||h.type.allowsMarkType(t),m=!!t.isInSet(u.marks)||!u.marks.some(g=>g.type.excludes(t));d=p&&m}return!d}),d})}var Jw=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const{selection:s}=t,{empty:i,ranges:l}=s,c=Pt(n,o.schema);if(r)if(i){const d=Pf(o,c);t.addStoredMark(c.create({...d,...e}))}else l.forEach(d=>{const u=d.$from.pos,f=d.$to.pos;o.doc.nodesBetween(u,f,(h,p)=>{const m=Math.max(p,u),g=Math.min(p+h.nodeSize,f);h.marks.find(k=>k.type===c)?h.marks.forEach(k=>{c===k.type&&t.addMark(m,g,c.create({...k.attrs,...e}))}):t.addMark(m,g,c.create(e))})});return qw(o,t,c)},Gw=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),Yw=(n,e={})=>({state:t,dispatch:o,chain:r})=>{const s=Ee(n,t.schema);let i;return t.selection.$anchor.sameParent(t.selection.$head)&&(i=t.selection.$anchor.parent.attrs),s.isTextblock?r().command(({commands:l})=>du(s,{...i,...e})(t)?!0:l.clearNodes()).command(({state:l})=>du(s,{...i,...e})(l,o)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},Xw=n=>({tr:e,dispatch:t})=>{if(t){const{doc:o}=e,r=On(n,0,o.content.size),s=Y.create(o,r);e.setSelection(s)}return!0},Qw=(n,e)=>({tr:t,state:o,dispatch:r})=>{const{selection:s}=o;let i,l;return typeof e=="number"?(i=e,l=e):e&&"from"in e&&"to"in e?(i=e.from,l=e.to):(i=s.from,l=s.to),r&&t.doc.nodesBetween(i,l,(c,d)=>{c.isText||t.setNodeMarkup(d,void 0,{...c.attrs,dir:n})}),!0},Zw=n=>({tr:e,dispatch:t})=>{if(t){const{doc:o}=e,{from:r,to:s}=typeof n=="number"?{from:n,to:n}:n,i=Q.atStart(o).from,l=Q.atEnd(o).to,c=On(r,i,l),d=On(s,i,l),u=Q.create(o,c,d);e.setSelection(u)}return!0},eb=n=>({state:e,dispatch:t})=>{const o=Ee(n,e.schema);return Jy(o)(e,t)};function Qf(n,e){const t=n.storedMarks||n.selection.$to.parentOffset&&n.selection.$from.marks();if(t){const o=t.filter(r=>e==null?void 0:e.includes(r.type.name));n.tr.ensureMarks(o)}}var tb=({keepMarks:n=!0}={})=>({tr:e,state:t,dispatch:o,editor:r})=>{const{selection:s,doc:i}=e,{$from:l,$to:c}=s,d=r.extensionManager.attributes,u=Zr(d,l.node().type.name,l.node().attrs);if(s instanceof Y&&s.node.isBlock)return!l.parentOffset||!It(i,l.pos)?!1:(o&&(n&&Qf(t,r.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const f=c.parentOffset===c.parent.content.size,h=l.depth===0?void 0:Bw(l.node(-1).contentMatchAt(l.indexAfter(-1)));let p=f&&h?[{type:h,attrs:u}]:void 0,m=It(e.doc,e.mapping.map(l.pos),1,p);if(!p&&!m&&It(e.doc,e.mapping.map(l.pos),1,h?[{type:h}]:void 0)&&(m=!0,p=h?[{type:h,attrs:u}]:void 0),o){if(m&&(s instanceof Q&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,p),h&&!f&&!l.parentOffset&&l.parent.type!==h)){const g=e.mapping.map(l.before()),y=e.doc.resolve(g);l.node(-1).canReplaceWith(y.index(),y.index()+1,h)&&e.setNodeMarkup(e.mapping.map(l.before()),h)}n&&Qf(t,r.extensionManager.splittableMarks),e.scrollIntoView()}return m},nb=(n,e={})=>({tr:t,state:o,dispatch:r,editor:s})=>{var i;const l=Ee(n,o.schema),{$from:c,$to:d}=o.selection,u=o.selection.node;if(u&&u.isBlock||c.depth<2||!c.sameParent(d))return!1;const f=c.node(-1);if(f.type!==l)return!1;const h=s.extensionManager.attributes;if(c.parent.content.size===0&&c.node(-1).childCount===c.indexAfter(-1)){if(c.depth===2||c.node(-3).type!==l||c.index(-2)!==c.node(-2).childCount-1)return!1;if(r){let k=P.empty;const x=c.index(-1)?1:c.index(-2)?2:3;for(let M=c.depth-x;M>=c.depth-3;M-=1)k=P.from(c.node(M).copy(k));const b=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,S={...Zr(h,c.node().type.name,c.node().attrs),...e},C=((i=l.contentMatch.defaultType)==null?void 0:i.createAndFill(S))||void 0;k=k.append(P.from(l.createAndFill(null,C)||void 0));const v=c.before(c.depth-(x-1));t.replace(v,c.after(-b),new U(k,4-x,0));let E=-1;t.doc.nodesBetween(v,t.doc.content.size,(M,T)=>{if(E>-1)return!1;M.isTextblock&&M.content.size===0&&(E=T+1)}),E>-1&&t.setSelection(Q.near(t.doc.resolve(E))),t.scrollIntoView()}return!0}const p=d.pos===c.end()?f.contentMatchAt(0).defaultType:null,m={...Zr(h,f.type.name,f.attrs),...e},g={...Zr(h,c.node().type.name,c.node().attrs),...e};t.delete(c.pos,d.pos);const y=p?[{type:l,attrs:m},{type:p,attrs:g}]:[{type:l,attrs:m}];if(!It(t.doc,c.pos,2))return!1;if(r){const{selection:k,storedMarks:x}=o,{splittableMarks:b}=s.extensionManager,S=x||k.$to.parentOffset&&k.$from.marks();if(t.split(c.pos,2,y).scrollIntoView(),!S||!r)return!0;const C=S.filter(v=>b.includes(v.type.name));t.ensureMarks(C)}return!0},Dl=(n,e)=>{const t=Al(i=>i.type===e)(n.selection);if(!t)return!0;const o=n.doc.resolve(Math.max(0,t.pos-1)).before(t.depth);if(o===void 0)return!0;const r=n.doc.nodeAt(o);return t.node.type===(r==null?void 0:r.type)&&En(n.doc,t.pos)&&n.join(t.pos),!0},Rl=(n,e)=>{const t=Al(i=>i.type===e)(n.selection);if(!t)return!0;const o=n.doc.resolve(t.start).after(t.depth);if(o===void 0)return!0;const r=n.doc.nodeAt(o);return t.node.type===(r==null?void 0:r.type)&&En(n.doc,o)&&n.join(o),!0},ob=(n,e,t,o={})=>({editor:r,tr:s,state:i,dispatch:l,chain:c,commands:d,can:u})=>{const{extensions:f,splittableMarks:h}=r.extensionManager,p=Ee(n,i.schema),m=Ee(e,i.schema),{selection:g,storedMarks:y}=i,{$from:k,$to:x}=g,b=k.blockRange(x),S=y||g.$to.parentOffset&&g.$from.marks();if(!b)return!1;const C=Al(v=>Yf(v.type.name,f))(g);if(b.depth>=1&&C&&b.depth-C.depth<=1){if(C.node.type===p)return d.liftListItem(m);if(Yf(C.node.type.name,f)&&p.validContent(C.node.content)&&l)return c().command(()=>(s.setNodeMarkup(C.pos,p),!0)).command(()=>Dl(s,p)).command(()=>Rl(s,p)).run()}return!t||!S||!l?c().command(()=>u().wrapInList(p,o)?!0:d.clearNodes()).wrapInList(p,o).command(()=>Dl(s,p)).command(()=>Rl(s,p)).run():c().command(()=>{const v=u().wrapInList(p,o),E=S.filter(M=>h.includes(M.type.name));return s.ensureMarks(E),v?!0:d.clearNodes()}).wrapInList(p,o).command(()=>Dl(s,p)).command(()=>Rl(s,p)).run()},rb=(n,e={},t={})=>({state:o,commands:r})=>{const{extendEmptyMarkRange:s=!1}=t,i=Pt(n,o.schema);return _l(o,i,e)?r.unsetMark(i,{extendEmptyMarkRange:s}):r.setMark(i,e)},sb=(n,e,t={})=>({state:o,commands:r})=>{const s=Ee(n,o.schema),i=Ee(e,o.schema),l=Uo(o,s,t);let c;return o.selection.$anchor.sameParent(o.selection.$head)&&(c=o.selection.$anchor.parent.attrs),l?r.setNode(i,c):r.setNode(s,{...c,...t})},ib=(n,e={})=>({state:t,commands:o})=>{const r=Ee(n,t.schema);return Uo(t,r,e)?o.lift(r):o.wrapIn(r,e)},lb=()=>({state:n,dispatch:e})=>{const t=n.plugins;for(let o=0;o<t.length;o+=1){const r=t[o];let s;if(r.spec.isInputRules&&(s=r.getState(n))){if(e){const i=n.tr,l=s.transform;for(let c=l.steps.length-1;c>=0;c-=1)i.step(l.steps[c].invert(l.docs[c]));if(s.text){const c=i.doc.resolve(s.from).marks();i.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else i.delete(s.from,s.to)}return!0}}return!1},ab=()=>({tr:n,dispatch:e})=>{const{selection:t}=n,{empty:o,ranges:r}=t;return o||e&&r.forEach(s=>{n.removeMark(s.$from.pos,s.$to.pos)}),!0},cb=(n,e={})=>({tr:t,state:o,dispatch:r})=>{var s;const{extendEmptyMarkRange:i=!1}=e,{selection:l}=t,c=Pt(n,o.schema),{$from:d,empty:u,ranges:f}=l;if(!r)return!0;if(u&&i){let{from:h,to:p}=l;const m=(s=d.marks().find(y=>y.type===c))==null?void 0:s.attrs,g=Tl(d,c,m);g&&(h=g.from,p=g.to),t.removeMark(h,p,c)}else f.forEach(h=>{t.removeMark(h.$from.pos,h.$to.pos,c)});return t.removeStoredMark(c),!0},db=n=>({tr:e,state:t,dispatch:o})=>{const{selection:r}=t;let s,i;return typeof n=="number"?(s=n,i=n):n&&"from"in n&&"to"in n?(s=n.from,i=n.to):(s=r.from,i=r.to),o&&e.doc.nodesBetween(s,i,(l,c)=>{if(l.isText)return;const d={...l.attrs};delete d.dir,e.setNodeMarkup(c,void 0,d)}),!0},ub=(n,e={})=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=Yr(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=Ee(n,o.schema)),l==="mark"&&(i=Pt(n,o.schema));let c=!1;return t.selection.ranges.forEach(d=>{const u=d.$from.pos,f=d.$to.pos;let h,p,m,g;t.selection.empty?o.doc.nodesBetween(u,f,(y,k)=>{s&&s===y.type&&(c=!0,m=Math.max(k,u),g=Math.min(k+y.nodeSize,f),h=k,p=y)}):o.doc.nodesBetween(u,f,(y,k)=>{k<u&&s&&s===y.type&&(c=!0,m=Math.max(k,u),g=Math.min(k+y.nodeSize,f),h=k,p=y),k>=u&&k<=f&&(s&&s===y.type&&(c=!0,r&&t.setNodeMarkup(k,void 0,{...y.attrs,...e})),i&&y.marks.length&&y.marks.forEach(x=>{if(i===x.type&&(c=!0,r)){const b=Math.max(k,u),S=Math.min(k+y.nodeSize,f);t.addMark(b,S,i.create({...x.attrs,...e}))}}))}),p&&(h!==void 0&&r&&t.setNodeMarkup(h,void 0,{...p.attrs,...e}),i&&p.marks.length&&p.marks.forEach(y=>{i===y.type&&r&&t.addMark(m,g,i.create({...y.attrs,...e}))}))}),c},fb=(n,e={})=>({state:t,dispatch:o})=>{const r=Ee(n,t.schema);return Fy(r,e)(t,o)},hb=(n,e={})=>({state:t,dispatch:o})=>{const r=Ee(n,t.schema);return Hy(r,e)(t,o)},pb=class{constructor(){this.callbacks={}}on(n,e){return this.callbacks[n]||(this.callbacks[n]=[]),this.callbacks[n].push(e),this}emit(n,...e){const t=this.callbacks[n];return t&&t.forEach(o=>o.apply(this,e)),this}off(n,e){const t=this.callbacks[n];return t&&(e?this.callbacks[n]=t.filter(o=>o!==e):delete this.callbacks[n]),this}once(n,e){const t=(...o)=>{this.off(n,t),e.apply(this,o)};return this.on(n,t)}removeAllListeners(){this.callbacks={}}},mb=class{constructor(n){var e;this.find=n.find,this.handler=n.handler,this.undoable=(e=n.undoable)!=null?e:!0}},gb=(n,e)=>{if(Ml(e))return e.exec(n);const t=e(n);if(!t)return null;const o=[t.text];return o.index=t.index,o.input=n,o.data=t.data,t.replaceWith&&(t.text.includes(t.replaceWith)||console.warn('[tiptap warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'),o.push(t.replaceWith)),o};function ts(n){var e;const{editor:t,from:o,to:r,text:s,rules:i,plugin:l}=n,{view:c}=t;if(c.composing)return!1;const d=c.state.doc.resolve(o);if(d.parent.type.spec.code||(e=d.nodeBefore||d.nodeAfter)!=null&&e.marks.find(h=>h.type.spec.code))return!1;let u=!1;const f=Hw(d)+s;return i.forEach(h=>{if(u)return;const p=gb(f,h.find);if(!p)return;const m=c.state.tr,g=Kr({state:c.state,transaction:m}),y={from:o-(p[0].length-s.length),to:r},{commands:k,chain:x,can:b}=new qr({editor:t,state:g});h.handler({state:g,range:y,match:p,commands:k,chain:x,can:b})===null||!m.steps.length||(h.undoable&&m.setMeta(l,{transform:m,from:o,to:r,text:s}),c.dispatch(m),u=!0)}),u}function yb(n){const{editor:e,rules:t}=n,o=new pe({state:{init(){return null},apply(r,s,i){const l=r.getMeta(o);if(l)return l;const c=r.getMeta("applyInputRules");return!!c&&setTimeout(()=>{let{text:u}=c;typeof u=="string"?u=u:u=Xr(P.from(u),i.schema);const{from:f}=c,h=f+u.length;ts({editor:e,from:f,to:h,text:u,rules:t,plugin:o})}),r.selectionSet||r.docChanged?null:s}},props:{handleTextInput(r,s,i,l){return ts({editor:e,from:s,to:i,text:l,rules:t,plugin:o})},handleDOMEvents:{compositionend:r=>(setTimeout(()=>{const{$cursor:s}=r.state.selection;s&&ts({editor:e,from:s.pos,to:s.pos,text:"",rules:t,plugin:o})}),!1)},handleKeyDown(r,s){if(s.key!=="Enter")return!1;const{$cursor:i}=r.state.selection;return i?ts({editor:e,from:i.pos,to:i.pos,text:`
|
|
13
|
+
`,rules:t,plugin:o}):!1}},isInputRules:!0});return o}function kb(n){return Object.prototype.toString.call(n).slice(8,-1)}function ns(n){return kb(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function Zf(n,e){const t={...n};return ns(n)&&ns(e)&&Object.keys(e).forEach(o=>{ns(e[o])&&ns(n[o])?t[o]=Zf(n[o],e[o]):t[o]=e[o]}),t}var Pl=class{constructor(n={}){this.type="extendable",this.parent=null,this.child=null,this.name="",this.config={name:this.name},this.config={...this.config,...n},this.name=this.config.name}get options(){return{...ae(q(this,"addOptions",{name:this.name}))||{}}}get storage(){return{...ae(q(this,"addStorage",{name:this.name,options:this.options}))||{}}}configure(n={}){const e=this.extend({...this.config,addOptions:()=>Zf(this.options,n)});return e.name=this.name,e.parent=this.parent,e}extend(n={}){const e=new this.constructor({...this.config,...n});return e.parent=this,this.child=e,e.name="name"in n?n.name:e.parent.name,e}},io=class Tg extends Pl{constructor(){super(...arguments),this.type="mark"}static create(e={}){const t=typeof e=="function"?e():e;return new Tg(t)}static handleExit({editor:e,mark:t}){const{tr:o}=e.state,r=e.state.selection.$from;if(r.pos===r.end()){const i=r.marks();if(!!!i.find(d=>(d==null?void 0:d.type.name)===t.name))return!1;const c=i.find(d=>(d==null?void 0:d.type.name)===t.name);return c&&o.removeStoredMark(c),o.insertText(" ",r.pos),e.view.dispatch(o),!0}return!1}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}};function wb(n){return typeof n=="number"}var bb=class{constructor(n){this.find=n.find,this.handler=n.handler}},Sb=(n,e,t)=>{if(Ml(e))return[...n.matchAll(e)];const o=e(n,t);return o?o.map(r=>{const s=[r.text];return s.index=r.index,s.input=n,s.data=r.data,r.replaceWith&&(r.text.includes(r.replaceWith)||console.warn('[tiptap warn]: "pasteRuleMatch.replaceWith" must be part of "pasteRuleMatch.text".'),s.push(r.replaceWith)),s}):[]};function xb(n){const{editor:e,state:t,from:o,to:r,rule:s,pasteEvent:i,dropEvent:l}=n,{commands:c,chain:d,can:u}=new qr({editor:e,state:t}),f=[];return t.doc.nodesBetween(o,r,(p,m)=>{var g,y,k,x,b;if((y=(g=p.type)==null?void 0:g.spec)!=null&&y.code||!(p.isText||p.isTextblock||p.isInline))return;const S=(b=(x=(k=p.content)==null?void 0:k.size)!=null?x:p.nodeSize)!=null?b:0,C=Math.max(o,m),v=Math.min(r,m+S);if(C>=v)return;const E=p.isText?p.text||"":p.textBetween(C-m,v-m,void 0,"");Sb(E,s.find,i).forEach(T=>{if(T.index===void 0)return;const A=C+T.index+1,B=A+T[0].length,I={from:t.tr.mapping.map(A),to:t.tr.mapping.map(B)},O=s.handler({state:t,range:I,match:T,commands:c,chain:d,can:u,pasteEvent:i,dropEvent:l});f.push(O)})}),f.every(p=>p!==null)}var rs=null,Cb=n=>{var e;const t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)==null||e.setData("text/html",n),t};function Eb(n){const{editor:e,rules:t}=n;let o=null,r=!1,s=!1,i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,l;try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}const c=({state:u,from:f,to:h,rule:p,pasteEvt:m})=>{const g=u.tr,y=Kr({state:u,transaction:g});if(!(!xb({editor:e,state:y,from:Math.max(f-1,0),to:h.b-1,rule:p,pasteEvent:m,dropEvent:l})||!g.steps.length)){try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}return i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,g}};return t.map(u=>new pe({view(f){const h=m=>{var g;o=(g=f.dom.parentElement)!=null&&g.contains(m.target)?f.dom.parentElement:null,o&&(rs=e)},p=()=>{rs&&(rs=null)};return window.addEventListener("dragstart",h),window.addEventListener("dragend",p),{destroy(){window.removeEventListener("dragstart",h),window.removeEventListener("dragend",p)}}},props:{handleDOMEvents:{drop:(f,h)=>{if(s=o===f.dom.parentElement,l=h,!s){const p=rs;p!=null&&p.isEditable&&setTimeout(()=>{const m=p.state.selection;m&&p.commands.deleteRange({from:m.from,to:m.to})},10)}return!1},paste:(f,h)=>{var p;const m=(p=h.clipboardData)==null?void 0:p.getData("text/html");return i=h,r=!!(m!=null&&m.includes("data-pm-slice")),!1}}},appendTransaction:(f,h,p)=>{const m=f[0],g=m.getMeta("uiEvent")==="paste"&&!r,y=m.getMeta("uiEvent")==="drop"&&!s,k=m.getMeta("applyPasteRules"),x=!!k;if(!g&&!y&&!x)return;if(x){let{text:C}=k;typeof C=="string"?C=C:C=Xr(P.from(C),p.schema);const{from:v}=k,E=v+C.length,M=Cb(C);return c({rule:u,state:p,from:v,to:{b:E},pasteEvt:M})}const b=h.doc.content.findDiffStart(p.doc.content),S=h.doc.content.findDiffEnd(p.doc.content);if(!(!wb(b)||!S||b===S.b))return c({rule:u,state:p,from:b,to:S,pasteEvt:i})}}))}var ss=class{constructor(n,e){this.splittableMarks=[],this.editor=e,this.baseExtensions=n,this.extensions=Il(n),this.schema=jf(this.extensions,e),this.setupExtensions()}get commands(){return this.extensions.reduce((n,e)=>{const t={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:Ko(e.name,this.schema)},o=q(e,"addCommands",t);return o?{...n,...o()}:n},{})}get plugins(){const{editor:n}=this;return Wo([...this.extensions].reverse()).flatMap(o=>{const r={name:o.name,options:o.options,storage:this.editor.extensionStorage[o.name],editor:n,type:Ko(o.name,this.schema)},s=[],i=q(o,"addKeyboardShortcuts",r);let l={};if(o.type==="mark"&&q(o,"exitable",r)&&(l.ArrowRight=()=>io.handleExit({editor:n,mark:o})),i){const h=Object.fromEntries(Object.entries(i()).map(([p,m])=>[p,()=>m({editor:n})]));l={...l,...h}}const c=Vk(l);s.push(c);const d=q(o,"addInputRules",r);if(Gf(o,n.options.enableInputRules)&&d){const h=d();if(h&&h.length){const p=yb({editor:n,rules:h}),m=Array.isArray(p)?p:[p];s.push(...m)}}const u=q(o,"addPasteRules",r);if(Gf(o,n.options.enablePasteRules)&&u){const h=u();if(h&&h.length){const p=Eb({editor:n,rules:h});s.push(...p)}}const f=q(o,"addProseMirrorPlugins",r);if(f){const h=f();s.push(...h)}return s})}get attributes(){return $f(this.extensions)}get nodeViews(){const{editor:n}=this,{nodeExtensions:e}=so(this.extensions);return Object.fromEntries(e.filter(t=>!!q(t,"addNodeView")).map(t=>{const o=this.attributes.filter(c=>c.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:n,type:Ee(t.name,this.schema)},s=q(t,"addNodeView",r);if(!s)return[];const i=s();if(!i)return[];const l=(c,d,u,f,h)=>{const p=Qr(c,o);return i({node:c,view:d,getPos:u,decorations:f,innerDecorations:h,editor:n,extension:t,HTMLAttributes:p})};return[t.name,l]}))}dispatchTransaction(n){const{editor:e}=this;return Wo([...this.extensions].reverse()).reduceRight((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:Ko(r.name,this.schema)},i=q(r,"dispatchTransaction",s);return i?l=>{i.call(s,{transaction:l,next:o})}:o},n)}transformPastedHTML(n){const{editor:e}=this;return Wo([...this.extensions]).reduce((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:Ko(r.name,this.schema)},i=q(r,"transformPastedHTML",s);return i?(l,c)=>{const d=o(l,c);return i.call(s,d)}:o},n||(o=>o))}get markViews(){const{editor:n}=this,{markExtensions:e}=so(this.extensions);return Object.fromEntries(e.filter(t=>!!q(t,"addMarkView")).map(t=>{const o=this.attributes.filter(l=>l.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:n,type:Pt(t.name,this.schema)},s=q(t,"addMarkView",r);if(!s)return[];const i=(l,c,d)=>{const u=Qr(l,o);return s()({mark:l,view:c,inline:d,editor:n,extension:t,HTMLAttributes:u,updateAttributes:f=>{Vb(l,n,f)}})};return[t.name,i]}))}setupExtensions(){const n=this.extensions;this.editor.extensionStorage=Object.fromEntries(n.map(e=>[e.name,e.storage])),n.forEach(e=>{var t;const o={name:e.name,options:e.options,storage:this.editor.extensionStorage[e.name],editor:this.editor,type:Ko(e.name,this.schema)};e.type==="mark"&&((t=ae(q(e,"keepOnSplit",o)))==null||t)&&this.splittableMarks.push(e.name);const r=q(e,"onBeforeCreate",o),s=q(e,"onCreate",o),i=q(e,"onUpdate",o),l=q(e,"onSelectionUpdate",o),c=q(e,"onTransaction",o),d=q(e,"onFocus",o),u=q(e,"onBlur",o),f=q(e,"onDestroy",o);r&&this.editor.on("beforeCreate",r),s&&this.editor.on("create",s),i&&this.editor.on("update",i),l&&this.editor.on("selectionUpdate",l),c&&this.editor.on("transaction",c),d&&this.editor.on("focus",d),u&&this.editor.on("blur",u),f&&this.editor.on("destroy",f)})}};ss.resolve=Il,ss.sort=Wo,ss.flatten=Bl;var vb={};vl(vb,{ClipboardTextSerializer:()=>eh,Commands:()=>th,Delete:()=>nh,Drop:()=>oh,Editable:()=>rh,FocusEvents:()=>ih,Keymap:()=>lh,Paste:()=>ah,Tabindex:()=>ch,TextDirection:()=>dh,focusEventsPluginKey:()=>sh});var de=class Ng extends Pl{constructor(){super(...arguments),this.type="extension"}static create(e={}){const t=typeof e=="function"?e():e;return new Ng(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}},eh=de.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new pe({key:new Ce("clipboardTextSerializer"),props:{clipboardTextSerializer:()=>{const{editor:n}=this,{state:e,schema:t}=n,{doc:o,selection:r}=e,{ranges:s}=r,i=Math.min(...s.map(u=>u.$from.pos)),l=Math.max(...s.map(u=>u.$to.pos)),c=Kf(t);return Wf(o,{from:i,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:c})}}})]}}),th=de.create({name:"commands",addCommands(){return{...Tf}}}),nh=de.create({name:"delete",onUpdate({transaction:n,appendedTransactions:e}){var t,o,r;const s=()=>{var i,l,c,d;if((d=(c=(l=(i=this.editor.options.coreExtensionOptions)==null?void 0:i.delete)==null?void 0:l.filterTransaction)==null?void 0:c.call(l,n))!=null?d:n.getMeta("y-sync$"))return;const u=Lf(n.before,[n,...e]);Jf(u).forEach(p=>{u.mapping.mapResult(p.oldRange.from).deletedAfter&&u.mapping.mapResult(p.oldRange.to).deletedBefore&&u.before.nodesBetween(p.oldRange.from,p.oldRange.to,(m,g)=>{const y=g+m.nodeSize-2,k=p.oldRange.from<=g&&y<=p.oldRange.to;this.editor.emit("delete",{type:"node",node:m,from:g,to:y,newFrom:u.mapping.map(g),newTo:u.mapping.map(y),deletedRange:p.oldRange,newRange:p.newRange,partial:!k,editor:this.editor,transaction:n,combinedTransform:u})})});const h=u.mapping;u.steps.forEach((p,m)=>{var g,y;if(p instanceof rt){const k=h.slice(m).map(p.from,-1),x=h.slice(m).map(p.to),b=h.invert().map(k,-1),S=h.invert().map(x),C=(g=u.doc.nodeAt(k-1))==null?void 0:g.marks.some(E=>E.eq(p.mark)),v=(y=u.doc.nodeAt(x))==null?void 0:y.marks.some(E=>E.eq(p.mark));this.editor.emit("delete",{type:"mark",mark:p.mark,from:p.from,to:p.to,deletedRange:{from:b,to:S},newRange:{from:k,to:x},partial:!!(v||C),editor:this.editor,transaction:n,combinedTransform:u})}})};(r=(o=(t=this.editor.options.coreExtensionOptions)==null?void 0:t.delete)==null?void 0:o.async)==null||r?setTimeout(s,0):s()}}),oh=de.create({name:"drop",addProseMirrorPlugins(){return[new pe({key:new Ce("tiptapDrop"),props:{handleDrop:(n,e,t,o)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:o})}}})]}}),rh=de.create({name:"editable",addProseMirrorPlugins(){return[new pe({key:new Ce("editable"),props:{editable:()=>this.editor.options.editable}})]}}),sh=new Ce("focusEvents"),ih=de.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new pe({key:sh,props:{handleDOMEvents:{focus:(e,t)=>{n.isFocused=!0;const o=n.state.tr.setMeta("focus",{event:t}).setMeta("addToHistory",!1);return e.dispatch(o),!1},blur:(e,t)=>{n.isFocused=!1;const o=n.state.tr.setMeta("blur",{event:t}).setMeta("addToHistory",!1);return e.dispatch(o),!1}}}})]}}),lh=de.create({name:"keymap",addKeyboardShortcuts(){const n=()=>this.editor.commands.first(({commands:i})=>[()=>i.undoInputRule(),()=>i.command(({tr:l})=>{const{selection:c,doc:d}=l,{empty:u,$anchor:f}=c,{pos:h,parent:p}=f,m=f.parent.isTextblock&&h>0?l.doc.resolve(h-1):f,g=m.parent.type.spec.isolating,y=f.pos-f.parentOffset,k=g&&m.parent.childCount===1?y===f.pos:ee.atStart(d).from===h;return!u||!p.type.isTextblock||p.textContent.length||!k||k&&f.parent.type.name==="paragraph"?!1:i.clearNodes()}),()=>i.deleteSelection(),()=>i.joinBackward(),()=>i.selectNodeBackward()]),e=()=>this.editor.commands.first(({commands:i})=>[()=>i.deleteSelection(),()=>i.deleteCurrentNode(),()=>i.joinForward(),()=>i.selectNodeForward()]),o={Enter:()=>this.editor.commands.first(({commands:i})=>[()=>i.newlineInCode(),()=>i.createParagraphNear(),()=>i.liftEmptyBlock(),()=>i.splitBlock()]),"Mod-Enter":()=>this.editor.commands.exitCode(),Backspace:n,"Mod-Backspace":n,"Shift-Backspace":n,Delete:e,"Mod-Delete":e,"Mod-a":()=>this.editor.commands.selectAll()},r={...o},s={...o,"Ctrl-h":n,"Alt-Backspace":n,"Ctrl-d":e,"Ctrl-Alt-Backspace":e,"Alt-Delete":e,"Alt-d":e,"Ctrl-a":()=>this.editor.commands.selectTextblockStart(),"Ctrl-e":()=>this.editor.commands.selectTextblockEnd()};return Gr()||Df()?s:r},addProseMirrorPlugins(){return[new pe({key:new Ce("clearDocument"),appendTransaction:(n,e,t)=>{if(n.some(g=>g.getMeta("composition")))return;const o=n.some(g=>g.docChanged)&&!e.doc.eq(t.doc),r=n.some(g=>g.getMeta("preventClearDocument"));if(!o||r)return;const{empty:s,from:i,to:l}=e.selection,c=ee.atStart(e.doc).from,d=ee.atEnd(e.doc).to;if(s||!(i===c&&l===d)||!es(t.doc))return;const h=t.tr,p=Kr({state:t,transaction:h}),{commands:m}=new qr({editor:this.editor,state:p});if(m.clearNodes(),!!h.steps.length)return h}})]}}),ah=de.create({name:"paste",addProseMirrorPlugins(){return[new pe({key:new Ce("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),ch=de.create({name:"tabindex",addProseMirrorPlugins(){return[new pe({key:new Ce("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}}),dh=de.create({name:"textDirection",addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];const{nodeExtensions:n}=so(this.extensions);return[{types:n.filter(e=>e.name!=="text").map(e=>e.name),attributes:{dir:{default:this.options.direction,parseHTML:e=>{const t=e.getAttribute("dir");return t&&(t==="ltr"||t==="rtl"||t==="auto")?t:this.options.direction},renderHTML:e=>e.dir?{dir:e.dir}:{}}}}]},addProseMirrorPlugins(){return[new pe({key:new Ce("textDirection"),props:{attributes:()=>{const n=this.options.direction;return n?{dir:n}:{}}}})]}}),Mb=class br{constructor(e,t,o=!1,r=null){this.currentNode=null,this.actualDepth=null,this.isBlock=o,this.resolvedPos=e,this.editor=t,this.currentNode=r}get name(){return this.node.type.name}get node(){return this.currentNode||this.resolvedPos.node()}get element(){return this.editor.view.domAtPos(this.pos).node}get depth(){var e;return(e=this.actualDepth)!=null?e:this.resolvedPos.depth}get pos(){return this.resolvedPos.pos}get content(){return this.node.content}set content(e){let t=this.from,o=this.to;if(this.isBlock){if(this.content.size===0){console.error(`You can’t set content on a block node. Tried to set content on ${this.name} at ${this.pos}`);return}t=this.from+1,o=this.to-1}this.editor.commands.insertContentAt({from:t,to:o},e)}get attributes(){return this.node.attrs}get textContent(){return this.node.textContent}get size(){return this.node.nodeSize}get from(){return this.isBlock?this.pos:this.resolvedPos.start(this.resolvedPos.depth)}get range(){return{from:this.from,to:this.to}}get to(){return this.isBlock?this.pos+this.size:this.resolvedPos.end(this.resolvedPos.depth)+(this.node.isText?0:1)}get parent(){if(this.depth===0)return null;const e=this.resolvedPos.start(this.resolvedPos.depth-1),t=this.resolvedPos.doc.resolve(e);return new br(t,this.editor)}get before(){let e=this.resolvedPos.doc.resolve(this.from-(this.isBlock?1:2));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.from-3)),new br(e,this.editor)}get after(){let e=this.resolvedPos.doc.resolve(this.to+(this.isBlock?2:1));return e.depth!==this.depth&&(e=this.resolvedPos.doc.resolve(this.to+3)),new br(e,this.editor)}get children(){const e=[];return this.node.content.forEach((t,o)=>{const r=t.isBlock&&!t.isTextblock,s=t.isAtom&&!t.isText,i=t.isInline,l=this.pos+o+(s?0:1);if(l<0||l>this.resolvedPos.doc.nodeSize-2)return;const c=this.resolvedPos.doc.resolve(l);if(!r&&!i&&c.depth<=this.depth)return;const d=new br(c,this.editor,r,r||i?t:null);r&&(d.actualDepth=this.depth+1),e.push(d)}),e}get firstChild(){return this.children[0]||null}get lastChild(){const e=this.children;return e[e.length-1]||null}closest(e,t={}){let o=null,r=this.parent;for(;r&&!o;){if(r.node.type.name===e)if(Object.keys(t).length>0){const s=r.node.attrs,i=Object.keys(t);for(let l=0;l<i.length;l+=1){const c=i[l];if(s[c]!==t[c])break}}else o=r;r=r.parent}return o}querySelector(e,t={}){return this.querySelectorAll(e,t,!0)[0]||null}querySelectorAll(e,t={},o=!1){let r=[];if(!this.children||this.children.length===0)return r;const s=Object.keys(t);return this.children.forEach(i=>{o&&r.length>0||(i.node.type.name===e&&s.every(c=>t[c]===i.node.attrs[c])&&r.push(i),!(o&&r.length>0)&&(r=r.concat(i.querySelectorAll(e,t,o))))}),r}setAttribute(e){const{tr:t}=this.editor.state;t.setNodeMarkup(this.from,void 0,{...this.node.attrs,...e}),this.editor.view.dispatch(t)}},Tb=`.ProseMirror {
|
|
14
14
|
position: relative;
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -80,9 +80,9 @@ img.ProseMirror-separator {
|
|
|
80
80
|
|
|
81
81
|
.ProseMirror-focused .ProseMirror-gapcursor {
|
|
82
82
|
display: block;
|
|
83
|
-
}`;function Nb(n,e,t){const o=document.querySelector("style[data-tiptap-style]");if(o!==null)return o;const r=document.createElement("style");return e&&r.setAttribute("nonce",e),r.setAttribute("data-tiptap-style",""),r.innerHTML=n,document.getElementsByTagName("head")[0].appendChild(r),r}var Ab=class extends pb{constructor(e={}){super(),this.css=null,this.className="tiptap",this.editorView=null,this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.options={element:typeof document<"u"?document.createElement("div"):null,content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:r})=>{throw r},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:Ww,createMappablePosition:Kw},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("mount",this.options.onMount),this.on("unmount",this.options.onUnmount),this.on("contentError",this.options.onContentError),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),this.on("drop",({event:r,slice:s,moved:i})=>this.options.onDrop(r,s,i)),this.on("paste",({event:r,slice:s})=>this.options.onPaste(r,s)),this.on("delete",this.options.onDelete);const t=this.createDoc(),o=If(t,this.options.autofocus);this.editorState=Xn.create({doc:t,schema:this.schema,selection:o||void 0}),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>"u")throw new Error("[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.");this.createView(e),this.emit("mount",{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){const e=this.editorView.dom;e!=null&&e.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove=="function"?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn("Failed to remove CSS element:",e)}this.css=null,this.emit("unmount",{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&typeof document<"u"&&(this.css=Nb(
|
|
83
|
+
}`;function Nb(n,e,t){const o=document.querySelector("style[data-tiptap-style]");if(o!==null)return o;const r=document.createElement("style");return e&&r.setAttribute("nonce",e),r.setAttribute("data-tiptap-style",""),r.innerHTML=n,document.getElementsByTagName("head")[0].appendChild(r),r}var Ab=class extends pb{constructor(e={}){super(),this.css=null,this.className="tiptap",this.editorView=null,this.isFocused=!1,this.isInitialized=!1,this.extensionStorage={},this.instanceId=Math.random().toString(36).slice(2,9),this.options={element:typeof document<"u"?document.createElement("div"):null,content:"",injectCSS:!0,injectNonce:void 0,extensions:[],autofocus:!1,editable:!0,textDirection:void 0,editorProps:{},parseOptions:{},coreExtensionOptions:{},enableInputRules:!0,enablePasteRules:!0,enableCoreExtensions:!0,enableContentCheck:!1,emitContentError:!1,onBeforeCreate:()=>null,onCreate:()=>null,onMount:()=>null,onUnmount:()=>null,onUpdate:()=>null,onSelectionUpdate:()=>null,onTransaction:()=>null,onFocus:()=>null,onBlur:()=>null,onDestroy:()=>null,onContentError:({error:r})=>{throw r},onPaste:()=>null,onDrop:()=>null,onDelete:()=>null,enableExtensionDispatchTransaction:!0},this.isCapturingTransaction=!1,this.capturedTransaction=null,this.utils={getUpdatedPosition:Ww,createMappablePosition:Kw},this.setOptions(e),this.createExtensionManager(),this.createCommandManager(),this.createSchema(),this.on("beforeCreate",this.options.onBeforeCreate),this.emit("beforeCreate",{editor:this}),this.on("mount",this.options.onMount),this.on("unmount",this.options.onUnmount),this.on("contentError",this.options.onContentError),this.on("create",this.options.onCreate),this.on("update",this.options.onUpdate),this.on("selectionUpdate",this.options.onSelectionUpdate),this.on("transaction",this.options.onTransaction),this.on("focus",this.options.onFocus),this.on("blur",this.options.onBlur),this.on("destroy",this.options.onDestroy),this.on("drop",({event:r,slice:s,moved:i})=>this.options.onDrop(r,s,i)),this.on("paste",({event:r,slice:s})=>this.options.onPaste(r,s)),this.on("delete",this.options.onDelete);const t=this.createDoc(),o=If(t,this.options.autofocus);this.editorState=Xn.create({doc:t,schema:this.schema,selection:o||void 0}),this.options.element&&this.mount(this.options.element)}mount(e){if(typeof document>"u")throw new Error("[tiptap error]: The editor cannot be mounted because there is no 'document' defined in this environment.");this.createView(e),this.emit("mount",{editor:this}),this.css&&!document.head.contains(this.css)&&document.head.appendChild(this.css),window.setTimeout(()=>{this.isDestroyed||(this.options.autofocus!==!1&&this.options.autofocus!==null&&this.commands.focus(this.options.autofocus),this.emit("create",{editor:this}),this.isInitialized=!0)},0)}unmount(){if(this.editorView){const e=this.editorView.dom;e!=null&&e.editor&&delete e.editor,this.editorView.destroy()}if(this.editorView=null,this.isInitialized=!1,this.css&&!document.querySelectorAll(`.${this.className}`).length)try{typeof this.css.remove=="function"?this.css.remove():this.css.parentNode&&this.css.parentNode.removeChild(this.css)}catch(e){console.warn("Failed to remove CSS element:",e)}this.css=null,this.emit("unmount",{editor:this})}get storage(){return this.extensionStorage}get commands(){return this.commandManager.commands}chain(){return this.commandManager.chain()}can(){return this.commandManager.can()}injectCSS(){this.options.injectCSS&&typeof document<"u"&&(this.css=Nb(Tb,this.options.injectNonce))}setOptions(e={}){this.options={...this.options,...e},!(!this.editorView||!this.state||this.isDestroyed)&&(this.options.editorProps&&this.view.setProps(this.options.editorProps),this.view.updateState(this.state))}setEditable(e,t=!0){this.setOptions({editable:e}),t&&this.emit("update",{editor:this,transaction:this.state.tr,appendedTransactions:[]})}get isEditable(){return this.options.editable&&this.view&&this.view.editable}get view(){return this.editorView?this.editorView:new Proxy({state:this.editorState,updateState:e=>{this.editorState=e},dispatch:e=>{this.dispatchTransaction(e)},composing:!1,dragging:null,editable:!0,isDestroyed:!1},{get:(e,t)=>{if(this.editorView)return this.editorView[t];if(t==="state")return this.editorState;if(t in e)return Reflect.get(e,t);throw new Error(`[tiptap error]: The editor view is not available. Cannot access view['${t}']. The editor may not be mounted yet.`)}})}get state(){return this.editorView&&(this.editorState=this.view.state),this.editorState}registerPlugin(e,t){const o=Vf(t)?t(e,[...this.state.plugins]):[...this.state.plugins,e],r=this.state.reconfigure({plugins:o});return this.view.updateState(r),r}unregisterPlugin(e){if(this.isDestroyed)return;const t=this.state.plugins;let o=t;if([].concat(e).forEach(s=>{const i=typeof s=="string"?`${s}$`:s.key;o=o.filter(l=>!l.key.startsWith(i))}),t.length===o.length)return;const r=this.state.reconfigure({plugins:o});return this.view.updateState(r),r}createExtensionManager(){var e,t;const r=[...this.options.enableCoreExtensions?[rh,eh.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)==null?void 0:e.clipboardTextSerializer)==null?void 0:t.blockSeparator}),th,ih,lh,ch,oh,ah,nh,dh.configure({direction:this.options.textDirection})].filter(s=>typeof this.options.enableCoreExtensions=="object"?this.options.enableCoreExtensions[s.name]!==!1:!0):[],...this.options.extensions].filter(s=>["extension","node","mark"].includes(s==null?void 0:s.type));this.extensionManager=new ss(r,this)}createCommandManager(){this.commandManager=new qr({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=Nl(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:this.options.enableContentCheck})}catch(t){if(!(t instanceof Error)||!["[tiptap error]: Invalid JSON content","[tiptap error]: Invalid HTML content"].includes(t.message))throw t;this.emit("contentError",{editor:this,error:t,disableCollaboration:()=>{"collaboration"in this.storage&&typeof this.storage.collaboration=="object"&&this.storage.collaboration&&(this.storage.collaboration.isDisabled=!0),this.options.extensions=this.options.extensions.filter(o=>o.name!=="collaboration"),this.createExtensionManager()}}),e=Nl(this.options.content,this.schema,this.options.parseOptions,{errorOnInvalidContent:!1})}return e}createView(e){const{editorProps:t,enableExtensionDispatchTransaction:o}=this.options,r=t.dispatchTransaction||this.dispatchTransaction.bind(this),s=o?this.extensionManager.dispatchTransaction(r):r,i=t.transformPastedHTML,l=this.extensionManager.transformPastedHTML(i);this.editorView=new bf(e,{...t,attributes:{role:"textbox",...t==null?void 0:t.attributes},dispatchTransaction:s,transformPastedHTML:l,state:this.editorState,markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews});const c=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(c),this.prependClass(),this.injectCSS();const d=this.view.dom;d.editor=this}createNodeViews(){this.view.isDestroyed||this.view.setProps({markViews:this.extensionManager.markViews,nodeViews:this.extensionManager.nodeViews})}prependClass(){this.view.dom.className=`${this.className} ${this.view.dom.className}`}captureTransaction(e){this.isCapturingTransaction=!0,e(),this.isCapturingTransaction=!1;const t=this.capturedTransaction;return this.capturedTransaction=null,t}dispatchTransaction(e){if(this.view.isDestroyed)return;if(this.isCapturingTransaction){if(!this.capturedTransaction){this.capturedTransaction=e;return}e.steps.forEach(u=>{var f;return(f=this.capturedTransaction)==null?void 0:f.step(u)});return}const{state:t,transactions:o}=this.state.applyTransaction(e),r=!this.state.selection.eq(t.selection),s=o.includes(e),i=this.state;if(this.emit("beforeTransaction",{editor:this,transaction:e,nextState:t}),!s)return;this.view.updateState(t),this.emit("transaction",{editor:this,transaction:e,appendedTransactions:o.slice(1)}),r&&this.emit("selectionUpdate",{editor:this,transaction:e});const l=o.findLast(u=>u.getMeta("focus")||u.getMeta("blur")),c=l==null?void 0:l.getMeta("focus"),d=l==null?void 0:l.getMeta("blur");c&&this.emit("focus",{editor:this,event:c.event,transaction:l}),d&&this.emit("blur",{editor:this,event:d.event,transaction:l}),!(e.getMeta("preventUpdate")||!o.some(u=>u.docChanged)||i.doc.eq(t.doc))&&this.emit("update",{editor:this,transaction:e,appendedTransactions:o.slice(1)})}getAttributes(e){return qf(this.state,e)}isActive(e,t){const o=typeof e=="string"?e:null,r=typeof e=="string"?t:e;return jw(this.state,o,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return Xr(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=`
|
|
84
84
|
|
|
85
|
-
`,textSerializers:o={}}=e||{};return Vw(this.state.doc,{blockSeparator:t,textSerializers:{...Kf(this.schema),...o}})}get isEmpty(){return es(this.state.doc)}destroy(){this.emit("destroy"),this.unmount(),this.removeAllListeners()}get isDestroyed(){var e,t;return(t=(e=this.editorView)==null?void 0:e.isDestroyed)!=null?t:!0}$node(e,t){var o;return((o=this.$doc)==null?void 0:o.querySelector(e,t))||null}$nodes(e,t){var o;return((o=this.$doc)==null?void 0:o.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new
|
|
85
|
+
`,textSerializers:o={}}=e||{};return Vw(this.state.doc,{blockSeparator:t,textSerializers:{...Kf(this.schema),...o}})}get isEmpty(){return es(this.state.doc)}destroy(){this.emit("destroy"),this.unmount(),this.removeAllListeners()}get isDestroyed(){var e,t;return(t=(e=this.editorView)==null?void 0:e.isDestroyed)!=null?t:!0}$node(e,t){var o;return((o=this.$doc)==null?void 0:o.querySelector(e,t))||null}$nodes(e,t){var o;return((o=this.$doc)==null?void 0:o.querySelectorAll(e,t))||null}$pos(e){const t=this.state.doc.resolve(e);return new Mb(t,this)}get $doc(){return this.$pos(0)}};function is(n){return new mb({find:n.find,handler:({state:e,range:t,match:o})=>{const r=ae(n.getAttributes,void 0,o);if(r===!1||r===null)return null;const{tr:s}=e,i=o[o.length-1],l=o[0];if(i){const c=l.search(/\S/),d=t.from+l.indexOf(i),u=d+i.length;if(Ol(t.from,t.to,e.doc).filter(p=>p.mark.type.excluded.find(g=>g===n.type&&g!==p.mark.type)).filter(p=>p.to>d).length)return null;u<t.to&&s.delete(u,t.to),d>t.from&&s.delete(t.from+c,d);const h=t.from+c+i.length;s.addMark(t.from+c,h,n.type.create(r||{})),s.removeStoredMark(n.type)}},undoable:n.undoable})}var Bb={};vl(Bb,{createAtomBlockMarkdownSpec:()=>Ib,createBlockMarkdownSpec:()=>Ob,createInlineMarkdownSpec:()=>Rb,parseAttributes:()=>Ll,parseIndentedBlocks:()=>Pb,renderNestedMarkdownContent:()=>Lb,serializeAttributes:()=>Vl});function Ll(n){if(!(n!=null&&n.trim()))return{};const e={},t=[],o=n.replace(/["']([^"']*)["']/g,d=>(t.push(d),`__QUOTED_${t.length-1}__`)),r=o.match(/(?:^|\s)\.([a-zA-Z][\w-]*)/g);if(r){const d=r.map(u=>u.trim().slice(1));e.class=d.join(" ")}const s=o.match(/(?:^|\s)#([a-zA-Z][\w-]*)/);s&&(e.id=s[1]);const i=/([a-zA-Z][\w-]*)\s*=\s*(__QUOTED_\d+__)/g;Array.from(o.matchAll(i)).forEach(([,d,u])=>{var f;const h=parseInt(((f=u.match(/__QUOTED_(\d+)__/))==null?void 0:f[1])||"0",10),p=t[h];p&&(e[d]=p.slice(1,-1))});const c=o.replace(/(?:^|\s)\.([a-zA-Z][\w-]*)/g,"").replace(/(?:^|\s)#([a-zA-Z][\w-]*)/g,"").replace(/([a-zA-Z][\w-]*)\s*=\s*__QUOTED_\d+__/g,"").trim();return c&&c.split(/\s+/).filter(Boolean).forEach(u=>{u.match(/^[a-zA-Z][\w-]*$/)&&(e[u]=!0)}),e}function Vl(n){if(!n||Object.keys(n).length===0)return"";const e=[];return n.class&&String(n.class).split(/\s+/).filter(Boolean).forEach(o=>e.push(`.${o}`)),n.id&&e.push(`#${n.id}`),Object.entries(n).forEach(([t,o])=>{t==="class"||t==="id"||(o===!0?e.push(t):o!==!1&&o!=null&&e.push(`${t}="${String(o)}"`))}),e.join(" ")}function Ib(n){const{nodeName:e,name:t,parseAttributes:o=Ll,serializeAttributes:r=Vl,defaultAttributes:s={},requiredAttributes:i=[],allowedAttributes:l}=n,c=t||e,d=u=>{if(!l)return u;const f={};return l.forEach(h=>{h in u&&(f[h]=u[h])}),f};return{parseMarkdown:(u,f)=>{const h={...s,...u.attributes};return f.createNode(e,h,[])},markdownTokenizer:{name:e,level:"block",start(u){var f;const h=new RegExp(`^:::${c}(?:\\s|$)`,"m"),p=(f=u.match(h))==null?void 0:f.index;return p!==void 0?p:-1},tokenize(u,f,h){const p=new RegExp(`^:::${c}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`),m=u.match(p);if(!m)return;const g=m[1]||"",y=o(g);if(!i.find(x=>!(x in y)))return{type:e,raw:m[0],attributes:y}}},renderMarkdown:u=>{const f=d(u.attrs||{}),h=r(f),p=h?` {${h}}`:"";return`:::${c}${p} :::`}}}function Ob(n){const{nodeName:e,name:t,getContent:o,parseAttributes:r=Ll,serializeAttributes:s=Vl,defaultAttributes:i={},content:l="block",allowedAttributes:c}=n,d=t||e,u=f=>{if(!c)return f;const h={};return c.forEach(p=>{p in f&&(h[p]=f[p])}),h};return{parseMarkdown:(f,h)=>{let p;if(o){const g=o(f);p=typeof g=="string"?[{type:"text",text:g}]:g}else l==="block"?p=h.parseChildren(f.tokens||[]):p=h.parseInline(f.tokens||[]);const m={...i,...f.attributes};return h.createNode(e,m,p)},markdownTokenizer:{name:e,level:"block",start(f){var h;const p=new RegExp(`^:::${d}`,"m"),m=(h=f.match(p))==null?void 0:h.index;return m!==void 0?m:-1},tokenize(f,h,p){var m;const g=new RegExp(`^:::${d}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),y=f.match(g);if(!y)return;const[k,x=""]=y,b=r(x);let S=1;const C=k.length;let v="";const E=/^:::([\w-]*)(\s.*)?/gm,M=f.slice(C);for(E.lastIndex=0;;){const T=E.exec(M);if(T===null)break;const A=T.index,B=T[1];if(!((m=T[2])!=null&&m.endsWith(":::"))){if(B)S+=1;else if(S-=1,S===0){const I=M.slice(0,A);v=I.trim();const O=f.slice(0,C+A+T[0].length);let z=[];if(v)if(l==="block")for(z=p.blockTokens(I),z.forEach($=>{$.text&&(!$.tokens||$.tokens.length===0)&&($.tokens=p.inlineTokens($.text))});z.length>0;){const $=z[z.length-1];if($.type==="paragraph"&&(!$.text||$.text.trim()===""))z.pop();else break}else z=p.inlineTokens(v);return{type:e,raw:O,attributes:b,content:v,tokens:z}}}}}},renderMarkdown:(f,h)=>{const p=u(f.attrs||{}),m=s(p),g=m?` {${m}}`:"",y=h.renderChildren(f.content||[],`
|
|
86
86
|
|
|
87
87
|
`);return`:::${d}${g}
|
|
88
88
|
|
|
@@ -99,11 +99,11 @@ ${y}
|
|
|
99
99
|
`);c.push(f)}}),c.join(`
|
|
100
100
|
`)}function Vb(n,e,t={}){const{state:o}=e,{doc:r,tr:s}=o,i=n;r.descendants((l,c)=>{const d=s.mapping.map(c),u=s.mapping.map(c)+l.nodeSize;let f=null;if(l.marks.forEach(p=>{if(p!==i)return!1;f=p}),!f)return;let h=!1;if(Object.keys(t).forEach(p=>{t[p]!==f.attrs[p]&&(h=!0)}),h){const p=n.type.create({...n.attrs,...t});s.removeMark(d,u,n.type),s.addMark(d,u,p)}}),s.docChanged&&e.view.dispatch(s)}var $l=class Ag extends Pl{constructor(){super(...arguments),this.type="node"}static create(e={}){const t=typeof e=="function"?e():e;return new Ag(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}};function qo(n){return new bb({find:n.find,handler:({state:e,range:t,match:o,pasteEvent:r})=>{const s=ae(n.getAttributes,void 0,o,r);if(s===!1||s===null)return null;const{tr:i}=e,l=o[o.length-1],c=o[0];let d=t.to;if(l){const u=c.search(/\S/),f=t.from+c.indexOf(l),h=f+l.length;if(Ol(t.from,t.to,e.doc).filter(m=>m.mark.type.excluded.find(y=>y===n.type&&y!==m.mark.type)).filter(m=>m.to>f).length)return null;h<t.to&&i.delete(h,t.to),f>t.from&&i.delete(t.from+u,f),d=t.from+u+l.length,i.addMark(t.from+u,d,n.type.create(s||{})),i.removeStoredMark(n.type)}}})}function uh(n){return a.customRef((e,t)=>({get(){return e(),n},set(o){n=o,requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})}}))}var $b=class extends Ab{constructor(n={}){return super(n),this.contentComponent=null,this.appContext=null,this.reactiveState=uh(this.view.state),this.reactiveExtensionStorage=uh(this.extensionStorage),this.on("beforeTransaction",({nextState:e})=>{this.reactiveState.value=e,this.reactiveExtensionStorage.value=this.extensionStorage}),a.markRaw(this)}get state(){return this.reactiveState?this.reactiveState.value:this.view.state}get storage(){return this.reactiveExtensionStorage?this.reactiveExtensionStorage.value:super.storage}registerPlugin(n,e){const t=super.registerPlugin(n,e);return this.reactiveState&&(this.reactiveState.value=t),t}unregisterPlugin(n){const e=super.unregisterPlugin(n);return this.reactiveState&&e&&(this.reactiveState.value=e),e}},zb=a.defineComponent({name:"EditorContent",props:{editor:{default:null,type:Object}},setup(n){const e=a.ref(),t=a.getCurrentInstance();return a.watchEffect(()=>{const o=n.editor;o&&o.options.element&&e.value&&a.nextTick(()=>{var r;if(!e.value||!((r=o.view.dom)!=null&&r.parentNode))return;const s=a.unref(e.value);e.value.append(...o.view.dom.parentNode.childNodes),o.contentComponent=t.ctx._,t&&(o.appContext={...t.appContext,provides:t.provides}),o.setOptions({element:s}),o.createNodeViews()})}),a.onBeforeUnmount(()=>{const o=n.editor;o&&(o.contentComponent=null,o.appContext=null)}),{rootEl:e}},render(){return a.h("div",{ref:n=>{this.rootEl=n}})}});a.defineComponent({name:"NodeViewContent",props:{as:{type:String,default:"div"}},render(){return a.h(this.as,{style:{whiteSpace:"pre-wrap"},"data-node-view-content":""})}}),a.defineComponent({name:"NodeViewWrapper",props:{as:{type:String,default:"div"}},inject:["onDragStart","decorationClasses"],render(){var n,e;return a.h(this.as,{class:this.decorationClasses,style:{whiteSpace:"normal"},"data-node-view-wrapper":"",onDragstart:this.onDragStart},(e=(n=this.$slots).default)==null?void 0:e.call(n))}}),a.defineComponent({name:"MarkViewContent",props:{as:{type:String,default:"span"}},render(){return a.h(this.as,{style:{whiteSpace:"inherit"},"data-mark-view-content":""})}});var Fb=$l.create({name:"doc",topNode:!0,content:"block+",renderMarkdown:(n,e)=>n.content?e.renderChildren(n.content,`
|
|
101
101
|
|
|
102
|
-
`):""}),fh=Fb,hh=" ",Hb=" ",jb=$l.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",nn(this.options.HTMLAttributes,n),0]},parseMarkdown:(n,e)=>{const t=n.tokens||[];if(t.length===1&&t[0].type==="image")return e.parseChildren([t[0]]);const o=e.parseInline(t);return o.length===1&&o[0].type==="text"&&(o[0].text===hh||o[0].text===Hb)?e.createNode("paragraph",void 0,[]):e.createNode("paragraph",void 0,o)},renderMarkdown:(n,e)=>{if(!n)return"";const t=Array.isArray(n.content)?n.content:[];return t.length===0?hh:e.renderChildren(t)},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),ph=jb,Ub=$l.create({name:"text",group:"inline",parseMarkdown:n=>({type:"text",text:n.text||""}),renderMarkdown:n=>n.text||""}),mh=Ub,gh=(n,e)=>{if(n==="slot")return 0;if(n instanceof Function)return n(e);const{children:t,...o}=e??{};if(n==="svg")throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");return[n,o,t]},Wb=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,Kb=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,qb=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,Jb=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,Gb=io.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!=="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name===this.name},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}]},renderHTML({HTMLAttributes:n}){return gh("strong",{...nn(this.options.HTMLAttributes,n),children:gh("slot",{})})},markdownTokenName:"strong",parseMarkdown:(n,e)=>e.applyMark("bold",e.parseInline(n.tokens||[])),renderMarkdown:(n,e)=>`**${e.renderChildren(n)}**`,addCommands(){return{setBold:()=>({commands:n})=>n.setMark(this.name),toggleBold:()=>({commands:n})=>n.toggleMark(this.name),unsetBold:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[is({find:Wb,type:this.type}),is({find:qb,type:this.type})]},addPasteRules(){return[qo({find:Kb,type:this.type}),qo({find:Jb,type:this.type})]}}),yh=Gb,Yb=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Xb=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,Qb=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,Zb=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,e2=io.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:n=>n.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:n=>n.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:n}){return["em",nn(this.options.HTMLAttributes,n),0]},addCommands(){return{setItalic:()=>({commands:n})=>n.setMark(this.name),toggleItalic:()=>({commands:n})=>n.toggleMark(this.name),unsetItalic:()=>({commands:n})=>n.unsetMark(this.name)}},markdownTokenName:"em",parseMarkdown:(n,e)=>e.applyMark("italic",e.parseInline(n.tokens||[])),renderMarkdown:(n,e)=>`*${e.renderChildren(n)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[is({find:Yb,type:this.type}),is({find:Qb,type:this.type})]},addPasteRules(){return[qo({find:Xb,type:this.type}),qo({find:Zb,type:this.type})]}}),kh=e2,t2=io.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:n=>n.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["u",nn(this.options.HTMLAttributes,n),0]},parseMarkdown(n,e){return e.applyMark(this.name||"underline",e.parseInline(n.tokens||[]))},renderMarkdown(n,e){return`++${e.renderChildren(n)}++`},markdownTokenizer:{name:"underline",level:"inline",start(n){return n.indexOf("++")},tokenize(n,e,t){const r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(n);if(!r)return;const s=r[2].trim();return{type:"underline",raw:r[0],text:s,tokens:t.inlineTokens(s)}}},addCommands(){return{setUnderline:()=>({commands:n})=>n.setMark(this.name),toggleUnderline:()=>({commands:n})=>n.toggleMark(this.name),unsetUnderline:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),wh=t2;const n2="aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2",o2="ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2",zl="numeric",Fl="ascii",Hl="alpha",Jo="asciinumeric",Go="alphanumeric",jl="domain",bh="emoji",r2="scheme",s2="slashscheme",Ul="whitespace";function i2(n,e){return n in e||(e[n]=[]),e[n]}function _n(n,e,t){e[zl]&&(e[Jo]=!0,e[Go]=!0),e[Fl]&&(e[Jo]=!0,e[Hl]=!0),e[Jo]&&(e[Go]=!0),e[Hl]&&(e[Go]=!0),e[Go]&&(e[jl]=!0),e[bh]&&(e[jl]=!0);for(const o in e){const r=i2(o,t);r.indexOf(n)<0&&r.push(n)}}function l2(n,e){const t={};for(const o in e)e[o].indexOf(n)>=0&&(t[o]=!0);return t}function je(n=null){this.j={},this.jr=[],this.jd=null,this.t=n}je.groups={},je.prototype={accepts(){return!!this.t},go(n){const e=this,t=e.j[n];if(t)return t;for(let o=0;o<e.jr.length;o++){const r=e.jr[o][0],s=e.jr[o][1];if(s&&r.test(n))return s}return e.jd},has(n,e=!1){return e?n in this.j:!!this.go(n)},ta(n,e,t,o){for(let r=0;r<n.length;r++)this.tt(n[r],e,t,o)},tr(n,e,t,o){o=o||je.groups;let r;return e&&e.j?r=e:(r=new je(e),t&&o&&_n(e,t,o)),this.jr.push([n,r]),r},ts(n,e,t,o){let r=this;const s=n.length;if(!s)return r;for(let i=0;i<s-1;i++)r=r.tt(n[i]);return r.tt(n[s-1],e,t,o)},tt(n,e,t,o){o=o||je.groups;const r=this;if(e&&e.j)return r.j[n]=e,e;const s=e;let i,l=r.go(n);if(l?(i=new je,Object.assign(i.j,l.j),i.jr.push.apply(i.jr,l.jr),i.jd=l.jd,i.t=l.t):i=new je,s){if(o)if(i.t&&typeof i.t=="string"){const c=Object.assign(l2(i.t,o),t);_n(s,c,o)}else t&&_n(s,t,o);i.t=s}return r.j[n]=i,i}};const Z=(n,e,t,o,r)=>n.ta(e,t,o,r),me=(n,e,t,o,r)=>n.tr(e,t,o,r),Sh=(n,e,t,o,r)=>n.ts(e,t,o,r),V=(n,e,t,o,r)=>n.tt(e,t,o,r),Lt="WORD",Wl="UWORD",xh="ASCIINUMERICAL",Ch="ALPHANUMERICAL",Yo="LOCALHOST",Kl="TLD",ql="UTLD",ls="SCHEME",lo="SLASH_SCHEME",Jl="NUM",Gl="WS",Yl="NL",Xo="OPENBRACE",Qo="CLOSEBRACE",as="OPENBRACKET",cs="CLOSEBRACKET",ds="OPENPAREN",us="CLOSEPAREN",fs="OPENANGLEBRACKET",hs="CLOSEANGLEBRACKET",ps="FULLWIDTHLEFTPAREN",ms="FULLWIDTHRIGHTPAREN",gs="LEFTCORNERBRACKET",ys="RIGHTCORNERBRACKET",ks="LEFTWHITECORNERBRACKET",ws="RIGHTWHITECORNERBRACKET",bs="FULLWIDTHLESSTHAN",Ss="FULLWIDTHGREATERTHAN",xs="AMPERSAND",Cs="APOSTROPHE",Es="ASTERISK",on="AT",vs="BACKSLASH",Ts="BACKTICK",Ms="CARET",rn="COLON",Xl="COMMA",Ns="DOLLAR",gt="DOT",As="EQUALS",Ql="EXCLAMATION",et="HYPHEN",Zo="PERCENT",Bs="PIPE",Is="PLUS",Os="POUND",er="QUERY",Zl="QUOTE",Eh="FULLWIDTHMIDDLEDOT",ea="SEMI",yt="SLASH",tr="TILDE",_s="UNDERSCORE",vh="EMOJI",Ds="SYM";var Th=Object.freeze({__proto__:null,ALPHANUMERICAL:Ch,AMPERSAND:xs,APOSTROPHE:Cs,ASCIINUMERICAL:xh,ASTERISK:Es,AT:on,BACKSLASH:vs,BACKTICK:Ts,CARET:Ms,CLOSEANGLEBRACKET:hs,CLOSEBRACE:Qo,CLOSEBRACKET:cs,CLOSEPAREN:us,COLON:rn,COMMA:Xl,DOLLAR:Ns,DOT:gt,EMOJI:vh,EQUALS:As,EXCLAMATION:Ql,FULLWIDTHGREATERTHAN:Ss,FULLWIDTHLEFTPAREN:ps,FULLWIDTHLESSTHAN:bs,FULLWIDTHMIDDLEDOT:Eh,FULLWIDTHRIGHTPAREN:ms,HYPHEN:et,LEFTCORNERBRACKET:gs,LEFTWHITECORNERBRACKET:ks,LOCALHOST:Yo,NL:Yl,NUM:Jl,OPENANGLEBRACKET:fs,OPENBRACE:Xo,OPENBRACKET:as,OPENPAREN:ds,PERCENT:Zo,PIPE:Bs,PLUS:Is,POUND:Os,QUERY:er,QUOTE:Zl,RIGHTCORNERBRACKET:ys,RIGHTWHITECORNERBRACKET:ws,SCHEME:ls,SEMI:ea,SLASH:yt,SLASH_SCHEME:lo,SYM:Ds,TILDE:tr,TLD:Kl,UNDERSCORE:_s,UTLD:ql,UWORD:Wl,WORD:Lt,WS:Gl});const Vt=/[a-z]/,nr=new RegExp("\\p{L}","u"),ta=new RegExp("\\p{Emoji}","u"),$t=/\d/,na=/\s/,Mh="\r",oa=`
|
|
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,"`",
|
|
102
|
+
`):""}),fh=Fb,hh=" ",Hb=" ",jb=$l.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",nn(this.options.HTMLAttributes,n),0]},parseMarkdown:(n,e)=>{const t=n.tokens||[];if(t.length===1&&t[0].type==="image")return e.parseChildren([t[0]]);const o=e.parseInline(t);return o.length===1&&o[0].type==="text"&&(o[0].text===hh||o[0].text===Hb)?e.createNode("paragraph",void 0,[]):e.createNode("paragraph",void 0,o)},renderMarkdown:(n,e)=>{if(!n)return"";const t=Array.isArray(n.content)?n.content:[];return t.length===0?hh:e.renderChildren(t)},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),ph=jb,Ub=$l.create({name:"text",group:"inline",parseMarkdown:n=>({type:"text",text:n.text||""}),renderMarkdown:n=>n.text||""}),mh=Ub,gh=(n,e)=>{if(n==="slot")return 0;if(n instanceof Function)return n(e);const{children:t,...o}=e??{};if(n==="svg")throw new Error("SVG elements are not supported in the JSX syntax, use the array syntax instead");return[n,o,t]},Wb=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,Kb=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,qb=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,Jb=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,Gb=io.create({name:"bold",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!=="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name===this.name},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}]},renderHTML({HTMLAttributes:n}){return gh("strong",{...nn(this.options.HTMLAttributes,n),children:gh("slot",{})})},markdownTokenName:"strong",parseMarkdown:(n,e)=>e.applyMark("bold",e.parseInline(n.tokens||[])),renderMarkdown:(n,e)=>`**${e.renderChildren(n)}**`,addCommands(){return{setBold:()=>({commands:n})=>n.setMark(this.name),toggleBold:()=>({commands:n})=>n.toggleMark(this.name),unsetBold:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-b":()=>this.editor.commands.toggleBold(),"Mod-B":()=>this.editor.commands.toggleBold()}},addInputRules(){return[is({find:Wb,type:this.type}),is({find:qb,type:this.type})]},addPasteRules(){return[qo({find:Kb,type:this.type}),qo({find:Jb,type:this.type})]}}),yh=Gb,Yb=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Xb=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,Qb=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,Zb=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,e2=io.create({name:"italic",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"em"},{tag:"i",getAttrs:n=>n.style.fontStyle!=="normal"&&null},{style:"font-style=normal",clearMark:n=>n.type.name===this.name},{style:"font-style=italic"}]},renderHTML({HTMLAttributes:n}){return["em",nn(this.options.HTMLAttributes,n),0]},addCommands(){return{setItalic:()=>({commands:n})=>n.setMark(this.name),toggleItalic:()=>({commands:n})=>n.toggleMark(this.name),unsetItalic:()=>({commands:n})=>n.unsetMark(this.name)}},markdownTokenName:"em",parseMarkdown:(n,e)=>e.applyMark("italic",e.parseInline(n.tokens||[])),renderMarkdown:(n,e)=>`*${e.renderChildren(n)}*`,addKeyboardShortcuts(){return{"Mod-i":()=>this.editor.commands.toggleItalic(),"Mod-I":()=>this.editor.commands.toggleItalic()}},addInputRules(){return[is({find:Yb,type:this.type}),is({find:Qb,type:this.type})]},addPasteRules(){return[qo({find:Xb,type:this.type}),qo({find:Zb,type:this.type})]}}),kh=e2,t2=io.create({name:"underline",addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:"u"},{style:"text-decoration",consuming:!1,getAttrs:n=>n.includes("underline")?{}:!1}]},renderHTML({HTMLAttributes:n}){return["u",nn(this.options.HTMLAttributes,n),0]},parseMarkdown(n,e){return e.applyMark(this.name||"underline",e.parseInline(n.tokens||[]))},renderMarkdown(n,e){return`++${e.renderChildren(n)}++`},markdownTokenizer:{name:"underline",level:"inline",start(n){return n.indexOf("++")},tokenize(n,e,t){const r=/^(\+\+)([\s\S]+?)(\+\+)/.exec(n);if(!r)return;const s=r[2].trim();return{type:"underline",raw:r[0],text:s,tokens:t.inlineTokens(s)}}},addCommands(){return{setUnderline:()=>({commands:n})=>n.setMark(this.name),toggleUnderline:()=>({commands:n})=>n.toggleMark(this.name),unsetUnderline:()=>({commands:n})=>n.unsetMark(this.name)}},addKeyboardShortcuts(){return{"Mod-u":()=>this.editor.commands.toggleUnderline(),"Mod-U":()=>this.editor.commands.toggleUnderline()}}}),wh=t2;const n2="aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2",o2="ελ1υ2бг1ел3дети4ею2католик6ом3мкд2он1сква6онлайн5рг3рус2ф2сайт3рб3укр3қаз3հայ3ישראל5קום3ابوظبي5رامكو5لاردن4بحرين5جزائر5سعودية6عليان5مغرب5مارات5یران5بارت2زار4يتك3ھارت5تونس4سودان3رية5شبكة4عراق2ب2مان4فلسطين6قطر3كاثوليك6وم3مصر2ليسيا5وريتانيا7قع4همراه5پاکستان7ڀارت4कॉम3नेट3भारत0म्3ोत5संगठन5বাংলা5ভারত2ৰত4ਭਾਰਤ4ભારત4ଭାରତ4இந்தியா6லங்கை6சிங்கப்பூர்11భారత్5ಭಾರತ4ഭാരതം5ලංකා4คอม3ไทย3ລາວ3გე2みんな3アマゾン4クラウド4グーグル4コム2ストア3セール3ファッション6ポイント4世界2中信1国1國1文网3亚马逊3企业2佛山2信息2健康2八卦2公司1益2台湾1灣2商城1店1标2嘉里0大酒店5在线2大拿2天主教3娱乐2家電2广东2微博2慈善2我爱你3手机2招聘2政务1府2新加坡2闻2时尚2書籍2机构2淡马锡3游戏2澳門2点看2移动2组织机构4网址1店1站1络2联通2谷歌2购物2通販2集团2電訊盈科4飞利浦3食品2餐厅2香格里拉3港2닷넷1컴2삼성2한국2",zl="numeric",Fl="ascii",Hl="alpha",Jo="asciinumeric",Go="alphanumeric",jl="domain",bh="emoji",r2="scheme",s2="slashscheme",Ul="whitespace";function i2(n,e){return n in e||(e[n]=[]),e[n]}function _n(n,e,t){e[zl]&&(e[Jo]=!0,e[Go]=!0),e[Fl]&&(e[Jo]=!0,e[Hl]=!0),e[Jo]&&(e[Go]=!0),e[Hl]&&(e[Go]=!0),e[Go]&&(e[jl]=!0),e[bh]&&(e[jl]=!0);for(const o in e){const r=i2(o,t);r.indexOf(n)<0&&r.push(n)}}function l2(n,e){const t={};for(const o in e)e[o].indexOf(n)>=0&&(t[o]=!0);return t}function je(n=null){this.j={},this.jr=[],this.jd=null,this.t=n}je.groups={},je.prototype={accepts(){return!!this.t},go(n){const e=this,t=e.j[n];if(t)return t;for(let o=0;o<e.jr.length;o++){const r=e.jr[o][0],s=e.jr[o][1];if(s&&r.test(n))return s}return e.jd},has(n,e=!1){return e?n in this.j:!!this.go(n)},ta(n,e,t,o){for(let r=0;r<n.length;r++)this.tt(n[r],e,t,o)},tr(n,e,t,o){o=o||je.groups;let r;return e&&e.j?r=e:(r=new je(e),t&&o&&_n(e,t,o)),this.jr.push([n,r]),r},ts(n,e,t,o){let r=this;const s=n.length;if(!s)return r;for(let i=0;i<s-1;i++)r=r.tt(n[i]);return r.tt(n[s-1],e,t,o)},tt(n,e,t,o){o=o||je.groups;const r=this;if(e&&e.j)return r.j[n]=e,e;const s=e;let i,l=r.go(n);if(l?(i=new je,Object.assign(i.j,l.j),i.jr.push.apply(i.jr,l.jr),i.jd=l.jd,i.t=l.t):i=new je,s){if(o)if(i.t&&typeof i.t=="string"){const c=Object.assign(l2(i.t,o),t);_n(s,c,o)}else t&&_n(s,t,o);i.t=s}return r.j[n]=i,i}};const Z=(n,e,t,o,r)=>n.ta(e,t,o,r),me=(n,e,t,o,r)=>n.tr(e,t,o,r),Sh=(n,e,t,o,r)=>n.ts(e,t,o,r),V=(n,e,t,o,r)=>n.tt(e,t,o,r),Lt="WORD",Wl="UWORD",xh="ASCIINUMERICAL",Ch="ALPHANUMERICAL",Yo="LOCALHOST",Kl="TLD",ql="UTLD",ls="SCHEME",lo="SLASH_SCHEME",Jl="NUM",Gl="WS",Yl="NL",Xo="OPENBRACE",Qo="CLOSEBRACE",as="OPENBRACKET",cs="CLOSEBRACKET",ds="OPENPAREN",us="CLOSEPAREN",fs="OPENANGLEBRACKET",hs="CLOSEANGLEBRACKET",ps="FULLWIDTHLEFTPAREN",ms="FULLWIDTHRIGHTPAREN",gs="LEFTCORNERBRACKET",ys="RIGHTCORNERBRACKET",ks="LEFTWHITECORNERBRACKET",ws="RIGHTWHITECORNERBRACKET",bs="FULLWIDTHLESSTHAN",Ss="FULLWIDTHGREATERTHAN",xs="AMPERSAND",Cs="APOSTROPHE",Es="ASTERISK",on="AT",vs="BACKSLASH",Ms="BACKTICK",Ts="CARET",rn="COLON",Xl="COMMA",Ns="DOLLAR",gt="DOT",As="EQUALS",Ql="EXCLAMATION",et="HYPHEN",Zo="PERCENT",Bs="PIPE",Is="PLUS",Os="POUND",er="QUERY",Zl="QUOTE",Eh="FULLWIDTHMIDDLEDOT",ea="SEMI",yt="SLASH",tr="TILDE",_s="UNDERSCORE",vh="EMOJI",Ds="SYM";var Mh=Object.freeze({__proto__:null,ALPHANUMERICAL:Ch,AMPERSAND:xs,APOSTROPHE:Cs,ASCIINUMERICAL:xh,ASTERISK:Es,AT:on,BACKSLASH:vs,BACKTICK:Ms,CARET:Ts,CLOSEANGLEBRACKET:hs,CLOSEBRACE:Qo,CLOSEBRACKET:cs,CLOSEPAREN:us,COLON:rn,COMMA:Xl,DOLLAR:Ns,DOT:gt,EMOJI:vh,EQUALS:As,EXCLAMATION:Ql,FULLWIDTHGREATERTHAN:Ss,FULLWIDTHLEFTPAREN:ps,FULLWIDTHLESSTHAN:bs,FULLWIDTHMIDDLEDOT:Eh,FULLWIDTHRIGHTPAREN:ms,HYPHEN:et,LEFTCORNERBRACKET:gs,LEFTWHITECORNERBRACKET:ks,LOCALHOST:Yo,NL:Yl,NUM:Jl,OPENANGLEBRACKET:fs,OPENBRACE:Xo,OPENBRACKET:as,OPENPAREN:ds,PERCENT:Zo,PIPE:Bs,PLUS:Is,POUND:Os,QUERY:er,QUOTE:Zl,RIGHTCORNERBRACKET:ys,RIGHTWHITECORNERBRACKET:ws,SCHEME:ls,SEMI:ea,SLASH:yt,SLASH_SCHEME:lo,SYM:Ds,TILDE:tr,TLD:Kl,UNDERSCORE:_s,UTLD:ql,UWORD:Wl,WORD:Lt,WS:Gl});const Vt=/[a-z]/,nr=new RegExp("\\p{L}","u"),ta=new RegExp("\\p{Emoji}","u"),$t=/\d/,na=/\s/,Th="\r",oa=`
|
|
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 T2=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=T2,M2=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=M2,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=Tf({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,T=((z=n.value)==null?void 0:z.clientWidth)??Hs,M=iS(v,E,S.zoom,T),A=rr(x,{block:{tag:"text",size:[M.width,M.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,T=w.Camera.write(d);T.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 Te(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=Te(w.Camera),s=Te(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 T=o.value.get(E);if(!T)continue;const M=cp(E);if(M){const A=up(M,r,s,b(T));v.push({entityId:E,...A})}}e(E=>{for(const T of C)S(w.Text.write(E,T));for(const{entityId:T,width:M,height:A,left:B,top:I}of v){const O=w.Block.write(E,T);O.size=[M,A],w.Block.setWorldPosition(E,T,[B,I])}dp(E),a.nextTick(()=>{var T;i.updateCounter.value++,(T=i.editor.value)==null||T.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 T=b(E.content),M=cp(v);if(M){const A=up(M,r,s,{...E,content:T});C.push({entityId:v,content:T,...A})}else C.push({entityId:v,content:T,width:0,height:0,left:0,top:0})}e(v=>{for(const{entityId:E,content:T,width:M,height:A,left:B,top:I}of C){const O=w.Text.write(v,E);if(O.content=T,M>0&&A>0){const z=w.Block.write(v,E);z.size=[M,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=Te(w.Camera),t=Te(w.Screen),o=Te(w.TransformBoxStateSingleton),r=Te(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(Ti);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 TS={activeTooltip:a.readonly(Us),isVisible:a.readonly(lr),isWarmedUp:a.readonly(ao),show:ES,hide:vS,reset:hp},Ws=a.ref([]);function zt(){return TS}const MS={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 M;const o=n,r=t,s=fe(o.entityId,w.Text),i=Te(w.Camera),l=Te(w.Screen),c=Pn(),{nextEditorTick:d,getEditor:u}=le(),f=Te(w.Mouse),h=a.inject(vi,void 0),p=a.ref(null);e({editableTextRef:p});const m=a.ref(((M=s.value)==null?void 0:M.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 T(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:T},[g.value?(a.openBlock(),a.createBlock(a.unref(zb),{key:0,editor:g.value},null,8,["editor"])):(a.openBlock(),a.createElementBlock("div",MS,[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],T=await c.detectOverflow(e,y),M=[];let A=((o=s.flip)==null?void 0:o.overflows)||[];if(u&&M.push(T[k]),f){const z=FS(r,i,S);M.push(T[z[0]],T[z[1]])}if(A=[...A,{placement:r,overflows:M}],!M.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 Ta(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=(Ta(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function Ta(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 Tp(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 Ma(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(Ma(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||Tp(n)&&n.host||xt(n);return Tp(e)?e.host:e}function Mp(n){const e=dn(n);return co(e)?n.ownerDocument?n.ownerDocument.body:n.body:Ct(e)&&ur(e)?e:Mp(e)}function fr(n,e,t){var o;e===void 0&&(e=[]),t===void 0&&(t=!0);const r=Mp(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=Ma(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)&&!Ma(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 Tx(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?Tx(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,Mx=(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 Ta(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 T=$p(u.value,f.value),M=$p(u.value,h.value);return c.value?{...E,transform:"translate("+T+"px, "+M+"px)",...Vp(u.value)>=1.5&&{willChange:"transform"}}:{position:p.value,left:T+"px",top:M+"px"}});let x;function b(){if(d.value==null||u.value==null)return;const E=r.value;Mx(d.value,u.value,{middleware:s.value,placement:i.value,strategy:l.value}).then(T=>{f.value=T.x,h.value=T.y,p.value=T.strategy,m.value=T.placement,g.value=T.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 T,M,A;const S=b.target,C=(T=f.value)==null?void 0:T.contains(S),v=(M=h.value)==null?void 0:M.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=Te(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(),T=Math.max(0,Math.min(100,(v.clientX-E.left)/E.width*100)),M=Math.max(0,Math.min(100,(v.clientY-E.top)/E.height*100));l.value={x:T,y:M}}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]=T=>c.value=T),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]=T=>d.value=T),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"},TC={class:"wov-tape-image-bubbles"},MC=["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",TC,[(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,MC)),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=Te(w.Camera),s=Te(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 T=u.getContext("2d");if(!T)return null;if(T.clearRect(0,0,v,E),T.fillStyle=S.strokeColor,S.subdivisionStep===1)f(T,v/2,E/2,C);else for(let M=0;M<S.subdivisionStep;M++)for(let A=0;A<S.subdivisionStep;A++){const B=(M+.5)*(v/S.subdivisionStep),I=(A+.5)*(E/S.subdivisionStep),z=M===0&&A===0?2*C:C;f(T,B,I,z)}return T.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 T=u.getContext("2d");if(!T)return null;if(T.clearRect(0,0,v,E),T.strokeStyle=S.strokeColor,S.subdivisionStep===1)p(T,0,0,v,0,C),p(T,0,0,0,E,C);else{const M=v/S.subdivisionStep,A=E/S.subdivisionStep;for(let B=0;B<=S.subdivisionStep;B++){const I=B*M,O=B%S.subdivisionStep===0;p(T,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(T,0,I,v,I,O?2*C:C)}}return T.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,T=r.value.left,M=r.value.top,A=T+v/r.value.zoom,B=M+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(T/I)*I,$=Math.floor(M/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-T-b/2)*r.value.zoom,Oe=($-M-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,T=r.value.left,M=r.value.top,A=T+v/r.value.zoom,B=M+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(T/I)*I,$=Math.floor(M/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-T)*r.value.zoom,Oe=($-M)*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(M=>M.type.startsWith("image/"));if(E.length>0){for(const M of E)await x(M,C,v);return}const T=y(S.dataTransfer);T&&await b(T,C,v)}function y(S){const C=S.getData("text/uri-list");if(C){const M=C.split(`
|
|
107
|
-
`).filter(A=>!A.startsWith("#")).find(A=>k(A));if(M)return M}const v=S.getData("text/html");if(v){const T=v.match(/<img[^>]+src=["']([^"']+)["']/i);if(T!=null&&T[1])return T[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(),T=w.Camera.read(E),M=w.Screen.read(E),A=T.left+(C-M.left)/T.zoom,B=T.top+(v-M.top)/T.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 T=await E.blob();if(!T.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([T],A,{type:T.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(Tc),{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=Te(w.Camera),r=Te(w.Screen),s=Te(w.SelectionStateSingleton),i=Pn(),l=a.computed(()=>t.value.map(T=>T.entityId)),c=a.computed(()=>t.value.map(T=>({tag:T.block.value.tag}))),d=a.computed(()=>{const T=e==null?void 0:e.getEditor();return T?im(T,c.value):new Set}),u=a.computed(()=>{const T=e==null?void 0:e.getEditor();return T?lm(T,c.value):!1});a.provide(Tc,{selectedIds:l,commonComponents:d,showOperations:u});const f=[0,0,0,0];function h(...T){let M=1/0,A=1/0,B=-1/0,I=-1/0,O=!1;for(const z of T){if(!z)continue;const $=z.getBoundingClientRect();$.width<=0||(O=!0,M=Math.min(M,$.left),A=Math.min(A,$.top),B=Math.max(B,$.right),I=Math.max(I,$.bottom))}return O?{x:M,y:A,left:M,top:A,right:B,bottom:I,width:B-M,height:I-A,toJSON:()=>({})}:null}const p=a.computed(()=>{if(t.value.length===0)return null;const T=o.value;if(!T)return null;let M=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,[-T.left,-T.top]),ie.Aabb.scale(f,T.zoom),M===null?M=ie.Aabb.clone(f):ie.Aabb.union(M,f)}return M}),m=a.inject("containerRef"),g=a.computed(()=>{const T=m==null?void 0:m.value;if(!T)return null;o.value,i.updateCounter.value;const M=i.blockElement.value,A=i.textElement.value,B=h(M,A);if(B)return{getBoundingClientRect:()=>B};const I=p.value;if(!I)return null;const O=T.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:T,rects:M}){const I=window.innerHeight-M.floating.height-8;return{y:Math.max(8,Math.min(T,I))}}},{floatingStyles:x}=mo(g,y,{placement:"top",middleware:[fo(12),po({fallbackPlacements:["bottom"]}),ho({padding:8}),k]}),b=a.computed(()=>{const T=p.value,M=r.value;return!T||!M?!0:T[2]<0||T[0]>M.width||T[3]<0||T[1]>M.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,T=>{clearTimeout(E),T?E=setTimeout(()=>{v.value=!0},40):v.value=!1},{immediate:!0}),(T,M)=>(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(T.$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(Ti);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;}</style></defs><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="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><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" /></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"},TE={key:0,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},ME={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(T){d.value=T,u.value="",f.value="",a.nextTick(()=>{var M;(M=l.value)==null||M.focus()})}function x(){d.value=null,u.value="",f.value=""}async function b(){const T=u.value.trim();if(!T){f.value="Please enter a URL";return}try{new URL(T)}catch{f.value="Please enter a valid URL";return}const M=d.value??w.detectEmbedProvider(T),A=w.validateEmbedUrl(T,M);if(A){f.value=A;return}const B=w.resolveEmbedUrl(T,M);let I=480,O=320;switch(M){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=T,ce.embedUrl=B,ce.provider=M,w.addComponent(z,X,Ve.Synced,{id:crypto.randomUUID()}),c.value=!1,d.value=null,u.value="",r("select",{cursor:fn.Select})}function S(T){T.key==="Enter"?(T.preventDefault(),b()):T.key==="Escape"&&(T.preventDefault(),d.value?x():c.value=!1)}function C(T){const M=T.target;s.value&&!s.value.contains(M)&&i.value&&!i.value.contains(M)&&(c.value=!1)}a.watch(c,T=>{T?document.addEventListener("click",C,!0):document.removeEventListener("click",C,!0)});function v(){s.value&&t("Embed",s.value)}function E(){o()}return(T,M)=>{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},[...M[1]||(M[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},[...M[11]||(M[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":M[0]||(M[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},[M[10]||(M[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",TE,[...M[2]||(M[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",ME,[...M[3]||(M[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,[...M[4]||(M[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,[...M[5]||(M[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,[...M[6]||(M[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,[...M[7]||(M[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,[...M[8]||(M[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,[...M[9]||(M[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=Te(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:T}=mo(p,u,{placement:"top",middleware:[fo(16),po(),ho({padding:8})],whileElementsMounted:ri});function M(){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(Ti,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:M},[...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(T))},[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,Tm;function GE(){return vm||(vm=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function YE(){return Tm||(Tm=[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 Mm(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}Mm(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])}Mm(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 Tv(n,e){return{type:`xstate.after.${n}.${e}`}}function Qa(n,e){return{type:`xstate.done.state.${n}`,output:e}}function Mv(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(cT(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=Mv(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=Tv(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
|
-
${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 eT(n,e){if(n.length!==e.size)return!1;for(const t of n)if(!e.has(t))return!1;return!0}function tT(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]=sT(f,o,t,u,c,d,s,t.actionExecutor)),f=bo(f,o,t,u.flatMap(p=>p.actions),s,void 0),f=oT(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&&eT(e._nodes,c)?[f,i]:[jn(f,{_nodes:h,historyValue:d}),i]}catch(p){throw p}}finally{t.actionExecutor=l}}function nT(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 oT(n,e,t,o,r,s,i,l){let c=n;const d=new Set,u=new Set;rT(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:nT(c,e,t,c.machine.root,y)})}}return c}function rT(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 sT(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 iT(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:iT(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?lT(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 lT(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 aT(n,e){const t=pi(yi(n,e));return Qm(n,[...t])}function cT(n){return!!n&&typeof n=="object"&&"machine"in n&&"value"in n}const dT=function(e){return Fm(e,this.value)},uT=function(e){return this.tags.has(e)},fT=function(e){const t=this.machine.getTransitionData(this,e);return!!(t!=null&&t.length)&&t.some(o=>o.target!==void 0||o.actions.length)},hT=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)}},pT=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:dT,hasTag:uT,can:fT,getMeta:pT,toJSON:hT}}function jn(n,e={}){return ki({...n,...e},n.machine)}function mT(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 gT(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:mT(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 yT(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 kT(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=yT,t.execute=kT,t}function wT(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 bT(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:wT(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=bT,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 ST={},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})):ST,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
|
-
${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 xT="#";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=aT(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]=tT(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(xT.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 gT(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 CT(n,e,t,o,{event:r}){const s=typeof r=="function"?r(t,o):r;return[e,{event:s},void 0]}function ET(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=CT,e.execute=ET,e}let yc=function(n){return n.Parent="#_parent",n.Internal="#_internal",n}({});function vT(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 TT(n,e,t){typeof t.to=="string"&&(t.to=e.children[t.to])}function MT(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=vT,o.retryResolve=TT,o.execute=MT,o}function NT(n,e){return kc(yc.Parent,n,e)}function AT(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(NT(...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 BT(n){function e(t,o){}return e.type="xstate.enqueueActions",e.collect=n,e.resolve=AT,e}function IT(n,e,t,o,{value:r,label:s}){return[e,{value:typeof r=="function"?r(t,o):r,label:s},void 0]}function OT({logger:n},{value:e,label:t}){t?n(t,e):n(e)}function _T(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=IT,t.execute=OT,t}function DT(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:_T,cancel:sc,stopChild:fi,enqueueActions:BT,emit:dg,spawnChild:ic,createStateConfig:s=>s,createAction:s=>s,createMachine:s=>DT({...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 RT=4,fg=1,hg="draw",PT=ug({guards:{isThresholdReached:({context:n,event:e})=>ie.Vec2.distance(n.pointingStartWorld,e.worldPosition)*e.cameraZoom>=RT},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}}}}}),LT=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,PT,o)}),VT=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())})}),$T=[{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,LT,kv,VT],setup(e){n.doubleClickSnapshot&&(pr.write(e).snapshot=n.doubleClickSnapshot)},cursors:um,fonts:$T,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 zT=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")}}),FT={class:"wov-user-cursors"},HT={class:"wov-cursor-svg",viewBox:"0 0 4.35 4.75",width:"20",height:"20"},jT=["fill"],UT="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",WT=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",FT,[(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",HT,[a.createElementVNode("path",{fill:s.color,stroke:"#fff","stroke-miterlimit":"10","stroke-width":".25",d:UT},null,8,jT)])),a.createElementVNode("span",{class:"wov-cursor-label",style:a.normalizeStyle({backgroundColor:s.color})},a.toDisplayString(s.name),5)],4))),128))]))}}),KT={key:0,class:"wov-offline-indicator"},qT=a.defineComponent({__name:"OfflineIndicator",props:{isOnline:{type:Boolean}},setup(n){return(e,t)=>n.isOnline?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",KT,"Working Offline"))}}),JT={key:0,class:"wov-version-mismatch-overlay"},GT=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",JT,[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)}}),YT=a.defineComponent({__name:"BackToContentButton",setup(n){const{nextEditorTick:e}=le(),t=Te(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,T=g.height/x;let M=!1;for(const B of u){const I=w.Aabb.read(d,B);if(l(I.value,C,v,E,T)){M=!0;break}}if(!M){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=$-T/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)}}),XT=["data-entity-id","data-selected","data-held-by-other","data-hovered","data-edited"],QT=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":Mc,"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,T=new Map,M=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 T.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,Tt=null,_e=null;const eM=((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:eM});function tM(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 nM(){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=nM();N||(delete D.persistence,delete D.websocket),F&&(D.initialState=F),_e=new Ve.CanvasStore(D);const H={...y.editor,user:v,plugins:tM(_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),rM(F),sM(F);for(const D of I)D(F)}),await N.tick()}async function wc(){!C.value||!_e||(await bi(C.value),y.autoRender!==!1?Tt=requestAnimationFrame(wc):Tt=null)}async function oM(){!C.value||!_e||await bi(C.value)}if(e({render:oM}),a.watch(()=>y.autoRender,N=>{N===!1?Tt!==null&&(cancelAnimationFrame(Tt),Tt=null):Tt===null&&C.value&&_e&&(Tt=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 Mt of l.current(re))w.Asset.read(re,Mt).identifier===G&&w.Asset.patch(re,Mt,{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&&(Tt=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;Tt!==null&&cancelAnimationFrame(Tt),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 rM(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 sM(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);T.set(R.sessionId,R),D=!0}for(const L of m.removed(N)){const R=w.User.read(N,L);T.delete(R.sessionId),D=!0}D&&(M.value=Array.from(T.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)},Mt={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,Mt)}),z.value=L}}function iM(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,Mt=R-oe,kr=Math.cos(-D.rotateZ),wr=Math.sin(-D.rotateZ);return[re*kr-Mt*wr+G,re*wr+Mt*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 lM(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 aM(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(lM(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 cM(N){const F=aM(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),Mt=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, ${Mt[0]}px ${Mt[1]}px, ${kr[0]}px ${kr[1]}px, ${wr[0]}px ${wr[1]}px)`}function dM(N){const{block:F,opacity:D}=N,H=yg(N),L=D!==null?D.value/255:1,R=N.edited?void 0:cM(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:iM(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(dM(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,XT)):a.createCommentVNode("",!0)],64))),128))],6)],64))),64)),C.value?a.renderSlot(N.$slots,"user-cursors",{key:1,users:M.value,currentSessionId:a.unref(v).sessionId,camera:ne.value},()=>[a.createVNode(WT,{users:M.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:M.value},()=>[a.createVNode(Em,{users:M.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(qT,{"is-online":$.value},null,8,["is-online"])]),a.renderSlot(N.$slots,"version-mismatch",{versionMismatch:W.value},()=>[a.createVNode(GT,{"version-mismatch":W.value},null,8,["version-mismatch"])]),a.renderSlot(N.$slots,"back-to-content",{},()=>[a.createVNode(YT)]),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(zT,{key:7,options:y.copyPaste},null,8,["options"])):a.createCommentVNode("",!0),a.createVNode(Kp)],512))}}),ZT=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(QT,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=Mc,_.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=ZT,_.computeCommonComponents=im,_.computeShowOperations=lm,_.getArrowHead=Kn,_.useComponent=fe,_.useComponents=wt,_.useEditorContext=le,_.useFonts=tm,_.useImageCreation=ka,_.useQuery=ip,_.useSingleton=Te,_.useTextBatchController=fp,_.useTextEditorController=Pn,_.useTextFormatting=lt,_.useTextStretchBehavior=xa,_.useToolbar=js,_.useTooltipSingleton=zt,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});
|
|
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
|
+
`).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
|
+
${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
|
+
${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"})});
|