@woven-canvas/vue 1.0.2 → 1.0.3

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.
Files changed (37) hide show
  1. package/build/components/EditableText.vue.d.ts.map +1 -1
  2. package/build/components/FloatingMenuBar.vue.d.ts +5 -1
  3. package/build/components/FloatingMenuBar.vue.d.ts.map +1 -1
  4. package/build/components/Toolbar.vue.d.ts.map +1 -1
  5. package/build/components/WovenCanvas.vue.d.ts +4 -61
  6. package/build/components/WovenCanvas.vue.d.ts.map +1 -1
  7. package/build/components/WovenCanvasCore.vue.d.ts +72 -0
  8. package/build/components/WovenCanvasCore.vue.d.ts.map +1 -0
  9. package/build/components/blocks/EmbedBlock.vue.d.ts +4 -0
  10. package/build/components/blocks/EmbedBlock.vue.d.ts.map +1 -0
  11. package/build/components/blocks/TapeBlock.vue.d.ts +4 -0
  12. package/build/components/blocks/TapeBlock.vue.d.ts.map +1 -0
  13. package/build/components/buttons/TapeImageButton.vue.d.ts +7 -0
  14. package/build/components/buttons/TapeImageButton.vue.d.ts.map +1 -0
  15. package/build/components/buttons/text/TextButtonGroup.vue.d.ts.map +1 -1
  16. package/build/components/buttons/text/TextLinkButton.vue.d.ts +7 -0
  17. package/build/components/buttons/text/TextLinkButton.vue.d.ts.map +1 -0
  18. package/build/components/buttons/text/index.d.ts +1 -0
  19. package/build/components/buttons/text/index.d.ts.map +1 -1
  20. package/build/components/tools/EmbedTool.vue.d.ts +3 -0
  21. package/build/components/tools/EmbedTool.vue.d.ts.map +1 -0
  22. package/build/components/tools/TapeTool.vue.d.ts +3 -0
  23. package/build/components/tools/TapeTool.vue.d.ts.map +1 -0
  24. package/build/composables/useTextBatchController.d.ts +3 -0
  25. package/build/composables/useTextBatchController.d.ts.map +1 -1
  26. package/build/composables/useTextEditorController.d.ts +3 -0
  27. package/build/composables/useTextEditorController.d.ts.map +1 -1
  28. package/build/composables/useTextFormatting.d.ts +3 -0
  29. package/build/composables/useTextFormatting.d.ts.map +1 -1
  30. package/build/index.d.ts +7 -2
  31. package/build/index.d.ts.map +1 -1
  32. package/build/index.js +13731 -9251
  33. package/build/index.umd.cjs +33 -27
  34. package/build/style.css +1 -1
  35. package/build/systems/blockPlacementSystem.d.ts.map +1 -1
  36. package/package.json +13 -11
  37. package/src/theme.css +1 -0
@@ -1,16 +1,16 @@
1
- (function(I,Re){typeof exports=="object"&&typeof module<"u"?Re(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-selection"),require("@woven-canvas/plugin-canvas-controls")):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-selection","@woven-canvas/plugin-canvas-controls"],Re):(I=typeof globalThis<"u"?globalThis:I||self,Re(I.Vue={},I.WovenEcsCanvasStore,I.WovenCanvasPluginArrows,I.Vue,I.WovenCanvasCore,I.WovenCanvasMath,I.WovenCanvasPluginEraser,I.WovenCanvasPluginPen,I.WovenCanvasPluginSelection,I.WovenCanvasPluginCanvasControls))})(this,function(I,Re,Y,c,x,Me,mo,go,oe,Nr){"use strict";const Br=[{kind:Y.ArrowHeadKind.None,label:"None",gap:0,svg:""},{kind:Y.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:Y.ArrowHeadKind.Delta,label:"Triangle",gap:20,svg:'<polygon points="-1,0 -12,-7 -12,7" fill="currentColor" />'},{kind:Y.ArrowHeadKind.Circle,label:"Circle",gap:0,svg:'<circle cx="-6" cy="0" r="6" fill="currentColor" />'},{kind:Y.ArrowHeadKind.Diamond,label:"Diamond",gap:0,svg:'<polygon points="0,0 -7,-6 -14,0 -7,6" fill="currentColor" />'}];function pn(n){return Br.find(e=>e.kind===n)}const Ii=Symbol.for("__woven_canvas_dropdown_active__"),Oi=Symbol.for("__woven_canvas_dropdown_level__"),Di=Symbol.for("__woven_canvas_floating_menu__"),Ar=Symbol.for("__woven_canvas_toolbar__"),Ri=Symbol.for("__woven_canvas_tooltip__"),$e=Symbol.for("__woven_canvas__");function fe(n,e){const t=c.inject($e);if(!t)throw new Error("useComponent must be used within a WovenCanvas component");const o=c.shallowRef(null),r=t.getEditor();if(r){const i=r._getContext();x.hasComponent(i,n,e)&&(o.value=e.snapshot(i,n))}const s=t.subscribeComponent(n,e.name,i=>{o.value=i});return c.onUnmounted(()=>{s()}),o}const sf={key:0},lf=["x1","y1","x2","y2","stroke","stroke-width"],af=["x1","y1","x2","y2","stroke","stroke-width"],cf=["points","fill"],df=["cx","cy","r","fill"],uf=["points","fill"],ff=15,hf=2,at=c.defineComponent({__name:"ArrowHead",props:{position:{},direction:{},thickness:{},color:{},arrowThickness:{},kind:{}},setup(n){const e=n,t=c.computed(()=>{const l=Math.hypot(e.direction[0],e.direction[1]);if(l===0)return null;const a=(e.arrowThickness/hf)**.33,d=ff*a,u=[e.direction[0]/l,e.direction[1]/l],f=[-u[1],u[0]];return{unitDir:u,perpDir:f,size:d}}),o=c.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:a,size:d}=t.value,u=d,f=d,p=[e.position[0]-l[0]*u+a[0]*(f/2),e.position[1]-l[1]*u+a[1]*(f/2)],h=[e.position[0]-l[0]*u-a[0]*(f/2),e.position[1]-l[1]*u-a[1]*(f/2)];return{p1:p,p2:h}}),r=c.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:a,size:d}=t.value,u=d,f=d,p=[l[0]*(d*.4),l[1]*(d*.4)],h=[e.position[0]-l[0]*u+p[0],e.position[1]-l[1]*u+p[1]],m=[h[0]+a[0]*(f/2),h[1]+a[1]*(f/2)],g=[h[0]-a[0]*(f/2),h[1]-a[1]*(f/2)],y=[e.position[0]+p[0],e.position[1]+p[1]];return`${y[0]},${y[1]} ${m[0]},${m[1]} ${g[0]},${g[1]}`}),s=c.computed(()=>{if(!t.value)return null;const{unitDir:l,size:a}=t.value,d=a*.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=c.computed(()=>{if(!t.value)return null;const{unitDir:l,perpDir:a,size:d}=t.value,u=1.6*d,f=1.6*d,p=[l[0]*(d*.8),l[1]*(d*.8)],h=[e.position[0]-l[0]*(u/2)+p[0],e.position[1]-l[1]*(u/2)+p[1]],m=[e.position[0]-l[0]*u+p[0],e.position[1]-l[1]*u+p[1]],g=[h[0]+a[0]*(f/2),h[1]+a[1]*(f/2)],y=[h[0]-a[0]*(f/2),h[1]-a[1]*(f/2)],k=[e.position[0]+p[0],e.position[1]+p[1]];return`${k[0]},${k[1]} ${g[0]},${g[1]} ${m[0]},${m[1]} ${y[0]},${y[1]}`});return(l,a)=>t.value?(c.openBlock(),c.createElementBlock("g",sf,[n.kind===c.unref(Y.ArrowHeadKind).V&&o.value?(c.openBlock(),c.createElementBlock(c.Fragment,{key:0},[c.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,lf),c.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,af)],64)):n.kind===c.unref(Y.ArrowHeadKind).Delta&&r.value?(c.openBlock(),c.createElementBlock("polygon",{key:1,points:r.value,fill:n.color},null,8,cf)):n.kind===c.unref(Y.ArrowHeadKind).Circle&&s.value?(c.openBlock(),c.createElementBlock("circle",{key:2,cx:s.value.center[0],cy:s.value.center[1],r:s.value.radius,fill:n.color},null,8,df)):n.kind===c.unref(Y.ArrowHeadKind).Diamond&&i.value?(c.openBlock(),c.createElementBlock("polygon",{key:3,points:i.value,fill:n.color},null,8,uf)):c.createCommentVNode("",!0)])):c.createCommentVNode("",!0)}}),pf={class:"arrow-svg",preserveAspectRatio:"none"},mf=["d","stroke","stroke-width"],gf=["x1","y1","x2","y2","stroke","stroke-width"],yf=["d"],kf=["x1","y1","x2","y2"],wf=c.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=c.ref(null),o=c.ref(0),r=c.ref(0),s=fe(e.entityId,x.Color),i=fe(e.entityId,Y.ArcArrow);let l=null;c.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)}),c.onUnmounted(()=>{l==null||l.disconnect()});const a=c.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=c.computed(()=>{var b;return((b=i.value)==null?void 0:b.value[6])??2}),u=c.computed(()=>`${d.value}px`),f=c.computed(()=>e.hovered||e.selected),p=c.computed(()=>{if(!i.value)return!1;const b=i.value.value,S=Me.Arc.create(b[0],b[1],b[2],b[3],b[4],b[5],b[6]);return!Me.Arc.isCollinear(S)}),h=c.computed(()=>{if(!i.value)return null;const b=i.value.value,S=o.value,C=r.value;return Me.Arc.create(b[0]*S,b[1]*C,b[2]*S,b[3]*C,b[4]*S,b[5]*C,b[6])}),m=c.computed(()=>!h.value||!p.value?null:Me.Arc.compute(h.value)),g=c.computed(()=>{var j,K,Z,U;if(!i.value||!h.value)return null;const b=h.value,S=i.value.startArrowHead,C=i.value.endArrowHead,M=Me.Arc.length(b);let v=i.value.trimStart;if((j=e.connector)!=null&&j.startBlock&&S!=="none"){const L=((K=pn(S))==null?void 0:K.gap)??0,W=M>0?L/M:0;v+=W}let E=i.value.trimEnd;if((Z=e.connector)!=null&&Z.endBlock&&C!=="none"){const L=((U=pn(C))==null?void 0:U.gap)??0,W=M>0?L/M:0;E+=W}const T=1-E,A=Me.Arc.parametricToPoint(b,v),R=Me.Arc.parametricToPoint(b,T),$=w(Me.Arc.directionAt(b,v)),z=Me.Arc.directionAt(b,T);return{start:A,end:R,startDir:$,endDir:z,tStart:v,tEnd:T,startHead:S,endHead:C}}),y=c.computed(()=>{if(!g.value||!m.value||!p.value)return"";const{start:b,end:S,tStart:C,tEnd:M}=g.value,{radius:v,clockwise:E,arcAngle:T}=m.value,R=T*(M-C)>Math.PI?1:0,$=E?0:1;return`M ${b[0]} ${b[1]} A ${v} ${v} 0 ${R} ${$} ${S[0]} ${S[1]}`}),k=c.computed(()=>!g.value||p.value?null:{x1:g.value.start[0],y1:g.value.start[1],x2:g.value.end[0],y2:g.value.end[1]});function w(b){return[-b[0],-b[1]]}return(b,S)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-arc-arrow"},[(c.openBlock(),c.createElementBlock("svg",pf,[p.value&&y.value?(c.openBlock(),c.createElementBlock("path",{key:0,d:y.value,stroke:a.value,fill:"none","stroke-width":u.value,"stroke-linecap":"round"},null,8,mf)):k.value?(c.openBlock(),c.createElementBlock("line",{key:1,x1:k.value.x1,y1:k.value.y1,x2:k.value.x2,y2:k.value.y2,stroke:a.value,fill:"none","stroke-width":u.value,"stroke-linecap":"round"},null,8,gf)):c.createCommentVNode("",!0),g.value?(c.openBlock(),c.createElementBlock(c.Fragment,{key:2},[g.value.startHead!=="none"?(c.openBlock(),c.createBlock(at,{key:0,position:g.value.start,direction:g.value.startDir,thickness:u.value,"arrow-thickness":d.value,color:a.value,kind:g.value.startHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):c.createCommentVNode("",!0),g.value.endHead!=="none"?(c.openBlock(),c.createBlock(at,{key:1,position:g.value.end,direction:g.value.endDir,thickness:u.value,"arrow-thickness":d.value,color:a.value,kind:g.value.endHead},null,8,["position","direction","thickness","arrow-thickness","color","kind"])):c.createCommentVNode("",!0),f.value?(c.openBlock(),c.createElementBlock(c.Fragment,{key:2},[p.value&&y.value?(c.openBlock(),c.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,yf)):k.value?(c.openBlock(),c.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,kf)):c.createCommentVNode("",!0),g.value.startHead!=="none"?(c.openBlock(),c.createBlock(at,{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"])):c.createCommentVNode("",!0),g.value.endHead!=="none"?(c.openBlock(),c.createBlock(at,{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"])):c.createCommentVNode("",!0)],64)):c.createCommentVNode("",!0)],64)):c.createCommentVNode("",!0)]))],512))}}),Ht=(n,e)=>{const t=n.__vccOpts||n;for(const[o,r]of e)t[o]=r;return t},_i=Ht(wf,[["__scopeId","data-v-bcf5b4f3"]]),bf={},xf={class:"wov-arrow-handle"};function Sf(n,e){return c.openBlock(),c.createElementBlock("div",xf,[...e[0]||(e[0]=[c.createElementVNode("div",{class:"wov-arrow-handle-inner"},null,-1)])])}const Pi=Ht(bf,[["render",Sf]]),Cf={},vf={class:"wov-arrow-terminal"};function Ef(n,e){return c.openBlock(),c.createElementBlock("div",vf,[...e[0]||(e[0]=[c.createElementVNode("div",{class:"wov-arrow-terminal-ring"},[c.createElementVNode("div",{class:"wov-arrow-terminal-fill"})],-1)])])}const Vi=Ht(Cf,[["render",Ef]]),Mf={class:"arrow-svg",preserveAspectRatio:"none"},Tf=["x1","y1","x2","y2"],Nf=["x1","y1","x2","y2","stroke","stroke-width"],Bf=["x1","y1","x2","y2"],$i=Ht(c.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=c.ref(null),o=c.ref(0),r=c.ref(0),s=fe(e.entityId,x.Color),i=fe(e.entityId,Y.ElbowArrow),l=c.computed(()=>e.hovered||e.selected);let a=null;c.onMounted(()=>{t.value&&(a=new ResizeObserver(()=>{t.value&&(o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),a.observe(t.value),o.value=t.value.clientWidth,r.value=t.value.clientHeight)}),c.onUnmounted(()=>{a==null||a.disconnect()});const d=c.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=c.computed(()=>{var g;return((g=i.value)==null?void 0:g.thickness)??2}),f=c.computed(()=>`${u.value}px`),p=c.computed(()=>{if(!i.value)return[];const g=i.value,y=o.value,k=r.value,w=[];for(let b=0;b<g.pointCount;b++){const S=g.points[b*2]*y,C=g.points[b*2+1]*k;w.push([S,C])}return w}),h=c.computed(()=>{const g=p.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=c.computed(()=>{var T,A,R,$;if(!i.value||p.value.length<2)return null;const g=i.value,y=[...p.value.map(z=>[...z])],k=g.startArrowHead,w=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((T=e.connector)!=null&&T.startBlock&&k!=="none"){const z=Math.hypot(b[0],b[1]),j=((A=pn(k))==null?void 0:A.gap)??0,K=z>0?j/z:0;C+=K}let M=g.trimEnd;if((R=e.connector)!=null&&R.endBlock&&w!=="none"){const z=Math.hypot(S[0],S[1]),j=(($=pn(w))==null?void 0:$.gap)??0,K=z>0?j/z:0;M+=K}y[0]=[y[0][0]+(y[1][0]-y[0][0])*C,y[0][1]+(y[1][1]-y[0][1])*C];const v=y.length-1;y[v]=[y[v-1][0]+(y[v][0]-y[v-1][0])*(1-M),y[v-1][1]+(y[v][1]-y[v-1][1])*(1-M)];const E=[];for(let z=0;z<y.length-1;z++)E.push({start:y[z],end:y[z+1]});return Me.Vec2.scale(b,-1),{points:y,lines:E,startPos:y[0],endPos:y[y.length-1],startDir:b,endDir:S,startHead:k,endHead:w}});return(g,y)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-elbow-arrow"},[(c.openBlock(),c.createElementBlock("svg",Mf,[l.value&&h.value.length>0?(c.openBlock(!0),c.createElementBlock(c.Fragment,{key:0},c.renderList(h.value,(k,w)=>(c.openBlock(),c.createElementBlock("line",{key:"bg-"+w,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,Tf))),128)):c.createCommentVNode("",!0),m.value?(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(m.value.lines,(k,w)=>(c.openBlock(),c.createElementBlock("line",{key:w,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,Nf))),128)),m.value.startHead!=="none"?(c.openBlock(),c.createBlock(at,{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"])):c.createCommentVNode("",!0),m.value.endHead!=="none"?(c.openBlock(),c.createBlock(at,{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"])):c.createCommentVNode("",!0),l.value?(c.openBlock(),c.createElementBlock(c.Fragment,{key:2},[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(m.value.lines,(k,w)=>(c.openBlock(),c.createElementBlock("line",{key:"hl-"+w,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,Bf))),128)),m.value.startHead!=="none"?(c.openBlock(),c.createBlock(at,{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"])):c.createCommentVNode("",!0),m.value.endHead!=="none"?(c.openBlock(),c.createBlock(at,{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"])):c.createCommentVNode("",!0)],64)):c.createCommentVNode("",!0)],64)):c.createCommentVNode("",!0)]))],512))}}),[["__scopeId","data-v-b2719db1"]]),{PI:Af}=Math,_n=Af+1e-4,Li=.5,zi=[1,1];function Fi(n,e,t,o=r=>r){return n*o(.5-e*(.5-t))}const{min:Ir}=Math;function Hi(n,e,t){let o=Ir(1,e/t);return Ir(1,n+(Ir(1,1-o)-n)*(o*.275))}function If(n){return[-n[0],-n[1]]}function Qe(n,e){return[n[0]+e[0],n[1]+e[1]]}function Wi(n,e,t){return n[0]=e[0]+t[0],n[1]=e[1]+t[1],n}function kt(n,e){return[n[0]-e[0],n[1]-e[1]]}function Or(n,e,t){return n[0]=e[0]-t[0],n[1]=e[1]-t[1],n}function wt(n,e){return[n[0]*e,n[1]*e]}function Dr(n,e,t){return n[0]=e[0]*t,n[1]=e[1]*t,n}function Of(n,e){return[n[0]/e,n[1]/e]}function ji(n){return[n[1],-n[0]]}function Rr(n,e){let t=e[0];return n[0]=e[1],n[1]=-t,n}function Ui(n,e){return n[0]*e[0]+n[1]*e[1]}function Df(n,e){return n[0]===e[0]&&n[1]===e[1]}function Rf(n){return Math.hypot(n[0],n[1])}function Ki(n,e){let t=n[0]-e[0],o=n[1]-e[1];return t*t+o*o}function qi(n){return Of(n,Rf(n))}function _f(n,e){return Math.hypot(n[1]-e[1],n[0]-e[0])}function _r(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,a=s*o+i*r;return[l+e[0],a+e[1]]}function Ji(n,e,t,o){let r=Math.sin(o),s=Math.cos(o),i=e[0]-t[0],l=e[1]-t[1],a=i*s-l*r,d=i*r+l*s;return n[0]=a+t[0],n[1]=d+t[1],n}function Gi(n,e,t){return Qe(n,wt(kt(e,n),t))}function Pf(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 Yi(n,e,t){return Qe(n,wt(e,t))}const ye=[0,0],bt=[0,0],xt=[0,0];function Vf(n,e){let t=Yi(n,qi(ji(kt(n,Qe(n,[1,1])))),-e),o=[],r=1/13;for(let s=r;s<=1;s+=r)o.push(_r(t,n,_n*2*s));return o}function $f(n,e,t){let o=[],r=1/t;for(let s=r;s<=1;s+=r)o.push(_r(e,n,_n*s));return o}function Lf(n,e,t){let o=kt(e,t),r=wt(o,.5),s=wt(o,.51);return[kt(n,r),kt(n,s),Qe(n,s),Qe(n,r)]}function zf(n,e,t,o){let r=[],s=Yi(n,e,t),i=1/o;for(let l=i;l<1;l+=i)r.push(_r(s,n,_n*3*l));return r}function Ff(n,e,t){return[Qe(n,wt(e,t)),Qe(n,wt(e,t*.99)),kt(n,wt(e,t*.99)),kt(n,wt(e,t))]}function Xi(n,e,t){return n===!1||n===void 0?0:n===!0?Math.max(e,t):n}function Hf(n,e,t){return n.slice(0,10).reduce((o,r)=>{let s=r.pressure;return e&&(s=Hi(o,r.distance,t)),(o+s)/2},n[0].pressure)}function Wf(n,e={}){let{size:t=16,smoothing:o=.5,thinning:r=.5,simulatePressure:s=!0,easing:i=U=>U,start:l={},end:a={},last:d=!1}=e,{cap:u=!0,easing:f=U=>U*(2-U)}=l,{cap:p=!0,easing:h=U=>--U*U*U+1}=a;if(n.length===0||t<=0)return[];let m=n[n.length-1].runningLength,g=Xi(l.taper,t,m),y=Xi(a.taper,t,m),k=(t*o)**2,w=[],b=[],S=Hf(n,s,t),C=Fi(t,r,n[n.length-1].pressure,i),M,v=n[0].vector,E=n[0].point,T=E,A=E,R=T,$=!1;for(let U=0;U<n.length;U++){let{pressure:L}=n[U],{point:W,vector:X,distance:ie,runningLength:ee}=n[U],ce=U===n.length-1;if(!ce&&m-ee<3)continue;r?(s&&(L=Hi(S,ie,t)),C=Fi(t,r,L,i)):C=t/2,M===void 0&&(M=C);let Xe=ee<g?f(ee/g):1,gt=m-ee<y?h((m-ee)/y):1;C=Math.max(.01,C*Math.min(Xe,gt));let fn=(ce?n[U]:n[U+1]).vector,zt=ce?1:Ui(X,fn),Tr=Ui(X,v)<0&&!$,Rn=zt!==null&&zt<0;if(Tr||Rn){Rr(ye,v),Dr(ye,ye,C);for(let Ft=0;Ft<=1;Ft+=.07692307692307693)Or(bt,W,ye),Ji(bt,bt,W,_n*Ft),A=[bt[0],bt[1]],w.push(A),Wi(xt,W,ye),Ji(xt,xt,W,_n*-Ft),R=[xt[0],xt[1]],b.push(R);E=A,T=R,Rn&&($=!0);continue}if($=!1,ce){Rr(ye,X),Dr(ye,ye,C),w.push(kt(W,ye)),b.push(Qe(W,ye));continue}Pf(ye,fn,X,zt),Rr(ye,ye),Dr(ye,ye,C),Or(bt,W,ye),A=[bt[0],bt[1]],(U<=1||Ki(E,A)>k)&&(w.push(A),E=A),Wi(xt,W,ye),R=[xt[0],xt[1]],(U<=1||Ki(T,R)>k)&&(b.push(R),T=R),S=L,v=X}let z=[n[0].point[0],n[0].point[1]],j=n.length>1?[n[n.length-1].point[0],n[n.length-1].point[1]]:Qe(n[0].point,[1,1]),K=[],Z=[];if(n.length===1){if(!(g||y)||d)return Vf(z,M||C)}else{g||y&&n.length===1||(u?K.push(...$f(z,b[0],13)):K.push(...Lf(z,w[0],b[0])));let U=ji(If(n[n.length-1].vector));y||g&&n.length===1?Z.push(j):p?Z.push(...zf(j,U,C,29)):Z.push(...Ff(j,U,C))}return w.concat(Z,b.reverse(),K)}const Zi=[0,0];function Qi(n){return n!=null&&n>=0}function jf(n,e={}){var p;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:h,y:m,pressure:g=Li})=>[h,m,g]);if(i.length===2){let h=i[1];i=i.slice(0,-1);for(let m=1;m<5;m++)i.push(Gi(i[0],h,m/4))}i.length===1&&(i=[...i,[...Qe(i[0],zi),...i[0].slice(2)]]);let l=[{point:[i[0][0],i[0][1]],pressure:Qi(i[0][2])?i[0][2]:.25,vector:[...zi],distance:0,runningLength:0}],a=!1,d=0,u=l[0],f=i.length-1;for(let h=1;h<i.length;h++){let m=r&&h===f?[i[h][0],i[h][1]]:Gi(u.point,i[h],s);if(Df(u.point,m))continue;let g=_f(m,u.point);if(d+=g,h<f&&!a){if(d<o)continue;a=!0}Or(Zi,u.point,m),u={point:m,pressure:Qi(i[h][2])?i[h][2]:Li,vector:qi(Zi),distance:g,runningLength:d},l.push(u)}return l[0].vector=((p=l[1])==null?void 0:p.vector)||[0,0],l}function Pr(n,e={}){return Wf(jf(n,e),e)}const Uf={class:"wov-eraser-stroke"},Kf={preserveAspectRatio:"none"},qf=["d"],Jf="#88888833",el=c.defineComponent({__name:"Eraser",props:{entityId:{}},setup(n){const e=n,t=fe(e.entityId,mo.EraserStroke),o=fe(e.entityId,x.Block),r=c.shallowRef("");function s(l,a){return(l+a)/2}function i(l,a,d,u,f,p){if(l<=4)return"";const h=[],m=Math.min(l,mo.POINTS_CAPACITY);for(let S=0;S<m;S++){const C=(a+S)%mo.POINTS_CAPACITY*2;h.push([d[C]-f,d[C+1]-p])}const g=Pr(h,{size:u,start:{taper:66,cap:!0}});if(g.length<3)return"";let y=g[0],k=g[1];const w=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],w[0]).toFixed(2)},${s(k[1],w[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 c.watch([t,o],([l,a])=>{if(!l||!a){r.value="";return}const d=l.radius??8,[u,f]=a.position;r.value=i(l.pointCount,l.firstPointIndex,l.points,2*d,u,f)},{immediate:!0}),(l,a)=>(c.openBlock(),c.createElementBlock("div",Uf,[(c.openBlock(),c.createElementBlock("svg",Kf,[c.createElementVNode("path",{d:r.value,fill:Jf},null,8,qf)]))]))}}),Gf={class:"wov-image-block"},Yf={key:0,class:"wov-image-placeholder"},Xf={key:1,class:"wov-image-placeholder wov-image-error"},Zf=["src","alt"],Qf={key:3,class:"wov-image-upload-overlay"},eh={class:"wov-image-upload-status"},tl=c.defineComponent({__name:"ImageBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=c.inject($e);if(!t)throw new Error("ImageBlock must be used within a WovenCanvas component");const o=t,r=fe(e.entityId,x.Asset),s=fe(e.entityId,x.Image),i=c.ref(null),l=c.ref(!0),a=c.ref(!1);let d=!0;c.onUnmounted(()=>{d=!1});async function u(){const h=o.getAssetManager();if(!h){l.value=!1,a.value=!0;return}const m=r.value;if(!m){l.value=!1;return}try{l.value=!0,a.value=!1;const g=await h.getDisplayUrl(m.identifier);if(!d)return;g?(i.value=g,l.value=!1):m.uploadState===x.UploadState.Failed&&(a.value=!0,l.value=!1)}catch(g){if(!d)return;console.error("Failed to get display URL:",g),a.value=!0,l.value=!1}}c.watch(()=>r.value,()=>{u()},{immediate:!0}),c.onMounted(()=>{u()});const f=c.computed(()=>{const h=r.value;if(!h)return null;switch(h.uploadState){case x.UploadState.Pending:return"Loading...";case x.UploadState.Uploading:return"Loading...";case x.UploadState.Failed:return"Failed";default:return null}}),p=c.computed(()=>({width:"100%",height:"100%",objectFit:"fill"}));return(h,m)=>{var g;return c.openBlock(),c.createElementBlock("div",Gf,[l.value&&!i.value?(c.openBlock(),c.createElementBlock("div",Yf,[...m[0]||(m[0]=[c.createElementVNode("span",null,"Loading...",-1)])])):a.value?(c.openBlock(),c.createElementBlock("div",Xf,[...m[1]||(m[1]=[c.createElementVNode("span",null,"Failed to load image",-1)])])):i.value?(c.openBlock(),c.createElementBlock("img",{key:2,src:i.value,alt:((g=c.unref(s))==null?void 0:g.alt)||"",style:c.normalizeStyle(p.value),draggable:"false"},null,12,Zf)):c.createCommentVNode("",!0),f.value?(c.openBlock(),c.createElementBlock("div",Qf,[c.createElementVNode("span",eh,c.toDisplayString(f.value),1)])):c.createCommentVNode("",!0)])}}}),th=["data-complete"],nh={preserveAspectRatio:"none"},oh=["d","fill"],rh={key:0,class:"highlight",preserveAspectRatio:"none"},sh=["d"],nl=Ht(c.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,go.PenStroke),o=fe(e.entityId,x.Block),r=fe(e.entityId,x.Color),s=c.shallowRef(""),i=c.shallowRef("");function l(f,p){return(f+p)/2}function a(f,p,h){if(p<=4||f.length<3){const w=h/2;return`M ${w},0 a ${w},${w} 0 1 0 0.0001 0`}let m=f[0],g=f[1];const y=f[2];let k=`M${m[0].toFixed(2)},${m[1].toFixed(2)} Q${g[0].toFixed(2)},${g[1].toFixed(2)} ${l(g[0],y[0]).toFixed(2)},${l(g[1],y[1]).toFixed(2)} T`;for(let w=2;w<f.length-1;w++)m=f[w],g=f[w+1],k+=`${l(m[0],g[0]).toFixed(2)},${l(m[1],g[1]).toFixed(2)} `;return k+=`${g[0].toFixed(2)},${g[1].toFixed(2)} `,k+="Z",k}c.watch([t,o],([f,p])=>{if(!f||!p){s.value="",i.value="";return}if(!f.originalWidth||!f.originalHeight){s.value="",i.value="";return}const h=p.size[0]/f.originalWidth,m=p.size[1]/f.originalHeight,g=[];for(let k=0;k<f.pointCount;k++){const w=f.points[k*2],b=f.points[k*2+1],S=(w-f.originalLeft)*h,C=(b-f.originalTop)*m;f.hasPressure?g.push([S,C,f.pressures[k]]):g.push([S,C])}const y=Pr(g,{last:f.isComplete,size:f.thickness,simulatePressure:!f.hasPressure});if(s.value=a(y,f.pointCount,f.thickness),f.isComplete){const k=g.length===1?f.thickness:1,w=Pr(g,{last:!0,size:k,simulatePressure:!f.hasPressure});i.value=a(w,f.pointCount,k)}},{immediate:!0});const d=c.computed(()=>r.value?`rgb(${r.value.red}, ${r.value.green}, ${r.value.blue})`:"#000000"),u=c.computed(()=>e.selected||e.hovered);return(f,p)=>{var h;return c.openBlock(),c.createElementBlock("div",{class:"wov-pen-stroke","data-complete":((h=c.unref(t))==null?void 0:h.isComplete)||void 0},[(c.openBlock(),c.createElementBlock("svg",nh,[c.createElementVNode("path",{d:s.value,fill:d.value},null,8,oh)])),u.value?(c.openBlock(),c.createElementBlock("svg",rh,[c.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,sh)])):c.createCommentVNode("",!0)],8,th)}}}),[["__scopeId","data-v-9b41c649"]]);function le(){const n=c.inject($e);if(!n)throw new Error("useEditorContext must be used within a WovenCanvas component");return{getEditor:()=>n.getEditor(),nextEditorTick(e){return new Promise(t=>{const o=n.getEditor();o&&o.nextTick(r=>{e==null||e(r),t(r)})})}}}const Pn={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 ke(n){this.content=n}ke.prototype={constructor:ke,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 ke(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 ke(t)},addToStart:function(n,e){return new ke([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new ke(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 ke(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=ke.from(n),n.size?new ke(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=ke.from(n),n.size?new ke(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=ke.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}},ke.from=function(n){if(n instanceof ke)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new ke(e)};function ol(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=ol(r.content,s.content,t+1);if(i!=null)return i}t+=r.nodeSize}}function rl(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),a=i.nodeSize;if(i==l){t-=a,o-=a;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=rl(i.content,l.content,t-1,o-1);if(d)return d}t-=a,o-=a}}class B{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 a=this.content[i],d=l+a.nodeSize;if(d>e&&o(a,r+l,s||null,i)!==!1&&a.content.size){let u=l+1;a.nodesBetween(Math.max(0,e-u),Math.min(a.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,a)=>{let d=l.isText?l.text.slice(Math.max(e,a)-a,t-a):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 B(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],a=i+l.nodeSize;a>e&&((i<e||a>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=a}return new B(o,r)}cutByIndex(e,t){return e==t?B.empty:e==0&&t==this.content.length?this:new B(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 B(r,s)}addToStart(e){return new B([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new B(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 ol(this,e,t)}findDiffEnd(e,t=this.size,o=e.size){return rl(this,e,t,o)}findIndex(e){if(e==0)return yo(0,e);if(e==this.size)return yo(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?yo(t+1,s):yo(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 B.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new B(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return B.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 B(t||e,o)}static from(e){if(!e)return B.empty;if(e instanceof B)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new B([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}B.empty=new B([],0);const Vr={index:0,offset:0};function yo(n,e){return Vr.index=n,Vr.offset=e,Vr}function ko(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(!ko(n[o],e[o]))return!1}else{for(let o in n)if(!(o in e)||!ko(n[o],e[o]))return!1;for(let o in e)if(!(o in n))return!1}return!0}let Q=class Ni{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&&ko(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 Ni.none;if(e instanceof Ni)return[e];let t=e.slice();return t.sort((o,r)=>o.type.rank-r.type.rank),t}};Q.none=[];class wo extends Error{}class _{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=il(this.content,e+this.openStart,t);return o&&new _(o,this.openStart,this.openEnd)}removeBetween(e,t){return new _(sl(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 _.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 _(B.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 _(e,o,r)}}_.empty=new _(B.empty,0,0);function sl(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(sl(s.content,e-r-1,t-r-1)))}function il(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=il(i.content,e-s-1,t,i);return l&&n.replaceChild(r,i.copy(l))}function ih(n,e,t){if(t.openStart>n.depth)throw new wo("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new wo("Inconsistent open depths");return ll(n,e,t,0)}function ll(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=ll(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 jt(i,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:i,end:l}=lh(t,n);return jt(s,cl(n,i,l,e,o))}else return jt(s,bo(n,e,o))}function al(n,e){if(!e.type.compatibleContent(n.type))throw new wo("Cannot join "+e.type.name+" onto "+n.type.name)}function $r(n,e,t){let o=n.node(t);return al(o,e.node(t)),o}function Wt(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 Vn(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&&(Wt(n.nodeAfter,o),s++));for(let l=s;l<i;l++)Wt(r.child(l),o);e&&e.depth==t&&e.textOffset&&Wt(e.nodeBefore,o)}function jt(n,e){return n.type.checkContent(e),n.copy(e)}function cl(n,e,t,o,r){let s=n.depth>r&&$r(n,e,r+1),i=o.depth>r&&$r(t,o,r+1),l=[];return Vn(null,n,r,l),s&&i&&e.index(r)==t.index(r)?(al(s,i),Wt(jt(s,cl(n,e,t,o,r+1)),l)):(s&&Wt(jt(s,bo(n,e,r+1)),l),Vn(e,t,r,l),i&&Wt(jt(i,bo(t,o,r+1)),l)),Vn(o,null,r,l),new B(l)}function bo(n,e,t){let o=[];if(Vn(null,n,t,o),n.depth>t){let r=$r(n,e,t+1);Wt(jt(r,bo(n,e,t+1)),o)}return Vn(e,null,t,o),new B(o)}function lh(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(B.from(r));return{start:r.resolveNoCache(n.openStart+t),end:r.resolveNoCache(r.content.size-n.openEnd-t)}}class $n{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 Q.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 xo(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:a}=i.content.findIndex(s),d=s-a;if(o.push(i,l,r+a),!d||(i=i.child(l),i.isText))break;s=d-1,r+=a+1}return new $n(t,o,s)}static resolveCached(e,t){let o=dl.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 dl.set(e,o=new ah);let r=o.elts[o.i]=$n.resolve(e,t);return o.i=(o.i+1)%ch,r}}class ah{constructor(){this.elts=[],this.i=0}}const ch=12,dl=new WeakMap;class xo{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 dh=Object.create(null);let ct=class Bi{constructor(e,t,o,r=Q.none){this.type=e,this.attrs=t,this.marks=r,this.content=o||B.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&&ko(this.attrs,t||e.defaultAttrs||dh)&&Q.sameSet(this.marks,o||Q.none)}copy(e=null){return e==this.content?this:new Bi(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new Bi(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 _.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 _(d,r.depth-i,s.depth-i)}replace(e,t,o){return ih(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 $n.resolveCached(this,e)}resolveNoCache(e){return $n.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()+")"),ul(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=B.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 a=r;a<s;a++)if(!this.type.allowsMarks(o.child(a).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=Q.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(!Q.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=B.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,r,o);return s.type.checkAttrs(s.attrs),s}};ct.prototype.text=void 0;class So extends ct{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):ul(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 So(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new So(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 ul(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class Ut{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let o=new uh(e,t);if(o.next==null)return Ut.empty;let r=fl(o);o.next&&o.err("Unexpected trailing text");let s=kh(yh(r));return wh(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 a=i.matchFragment(e,o);if(a&&(!t||a.validEnd))return B.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 p=s(f,l.concat(u));if(p)return p}}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:a}=s.next[i];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!r.type||a.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
- `)}}Ut.empty=new Ut(!0);class uh{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 fl(n){let e=[];do e.push(fh(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function fh(n){let e=[];do e.push(hh(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function hh(n){let e=gh(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=ph(n,e);else break;return e}function hl(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function ph(n,e){let t=hl(n),o=t;return n.eat(",")&&(n.next!="}"?o=hl(n):o=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:o,expr:e}}function mh(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 gh(n){if(n.eat("(")){let e=fl(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=mh(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 yh(n){let e=[[]];return r(s(n,0),t()),e;function t(){return e.push([])-1}function o(i,l,a){let d={term:a,to:l};return e[i].push(d),d}function r(i,l){i.forEach(a=>a.to=l)}function s(i,l){if(i.type=="choice")return i.exprs.reduce((a,d)=>a.concat(s(d,l)),[]);if(i.type=="seq")for(let a=0;;a++){let d=s(i.exprs[a],l);if(a==i.exprs.length-1)return d;r(d,l=t())}else if(i.type=="star"){let a=t();return o(l,a),r(s(i.expr,a),a),[o(a)]}else if(i.type=="plus"){let a=t();return r(s(i.expr,l),a),r(s(i.expr,a),a),[o(a)]}else{if(i.type=="opt")return[o(l)].concat(s(i.expr,l));if(i.type=="range"){let a=l;for(let d=0;d<i.min;d++){let u=t();r(s(i.expr,a),u),a=u}if(i.max==-1)r(s(i.expr,a),a);else for(let d=i.min;d<i.max;d++){let u=t();o(a,u),r(s(i.expr,a),u),a=u}return[o(a)]}else{if(i.type=="name")return[o(l,void 0,i.value)];throw new Error("Unknown expr type")}}}}function pl(n,e){return e-n}function ml(n,e){let t=[];return o(e),t.sort(pl);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:a}=s[i];!l&&t.indexOf(a)==-1&&o(a)}}}function kh(n){let e=Object.create(null);return t(ml(n,0));function t(o){let r=[];o.forEach(i=>{n[i].forEach(({term:l,to:a})=>{if(!l)return;let d;for(let u=0;u<r.length;u++)r[u][0]==l&&(d=r[u][1]);ml(n,a).forEach(u=>{d||r.push([l,d=[]]),d.indexOf(u)==-1&&d.push(u)})})});let s=e[o.join(",")]=new Ut(o.indexOf(n.length-1)>-1);for(let i=0;i<r.length;i++){let l=r[i][1].sort(pl);s.next.push({type:r[i][0],next:e[l.join(",")]||t(l)})}return s}}function wh(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:a,next:d}=r.next[l];i.push(a.name),s&&!(a.isText||a.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 gl(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 yl(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 kl(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 wl(n,e){let t=Object.create(null);if(e)for(let o in e)t[o]=new xh(n,o,e[o]);return t}let bl=class ef{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=wl(e,o.attrs),this.defaultAttrs=gl(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==Ut.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:yl(this.attrs,e)}create(e=null,t,o){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new ct(this,this.computeAttrs(e),B.from(t),Q.setFrom(o))}createChecked(e=null,t,o){return t=B.from(t),this.checkContent(t),new ct(this,this.computeAttrs(e),t,Q.setFrom(o))}createAndFill(e=null,t,o){if(e=this.computeAttrs(e),t=B.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(B.empty,!0);return s?new ct(this,e,t.append(s),Q.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){kl(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:Q.none:e}static compile(e,t){let o=Object.create(null);e.forEach((s,i)=>o[s]=new ef(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 bh(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 xh{constructor(e,t,o){this.hasDefault=Object.prototype.hasOwnProperty.call(o,"default"),this.default=o.default,this.validate=typeof o.validate=="string"?bh(e,t,o.validate):o.validate}get isRequired(){return!this.hasDefault}}class Co{constructor(e,t,o,r){this.name=e,this.rank=t,this.schema=o,this.spec=r,this.attrs=wl(e,r.attrs),this.excluded=null;let s=gl(this.attrs);this.instance=s?new Q(this,s):null}create(e=null){return!e&&this.instance?this.instance:new Q(this,yl(this.attrs,e))}static compile(e,t){let o=Object.create(null),r=0;return e.forEach((s,i)=>o[s]=new Co(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){kl(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class xl{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=ke.from(e.nodes),t.marks=ke.from(e.marks||{}),this.nodes=bl.compile(this.spec.nodes,this),this.marks=Co.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]=Ut.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?Sl(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==""?[]:Sl(this,i.split(" "))}this.nodeFromJSON=r=>ct.fromJSON(this,r),this.markFromJSON=r=>Q.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 bl){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 So(o,o.defaultAttrs,e,Q.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 Sl(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 a=n.marks[l];(r=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(r)>-1)&&t.push(i=a)}if(!i)throw new SyntaxError("Unknown mark type: '"+e[o]+"'")}return t}function Sh(n){return n.tag!=null}function Ch(n){return n.style!=null}let mn=class Ai{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let o=this.matchedStyles=[];t.forEach(r=>{if(Sh(r))this.tags.push(r);else if(Ch(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 Ml(this,t,!1);return o.addAll(e,Q.none,t.from,t.to),o.finish()}parseSlice(e,t={}){let o=new Ml(this,t,!0);return o.addAll(e,Q.none,t.from,t.to),_.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(Mh(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 a=i.getAttrs(t);if(a===!1)continue;i.attrs=a||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=Tl(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=Tl(i)),i.node||i.ignore||i.mark||(i.node=r)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Ai(e,Ai.schemaRules(e)))}};const Cl={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},vh={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},vl={ol:!0,ul:!0},Ln=1,Lr=2,zn=4;function El(n,e,t){return e!=null?(e?Ln:0)|(e==="full"?Lr:0):n&&n.whitespace=="pre"?Ln|Lr:t&~zn}class vo{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=Q.none,this.match=s||(i&zn?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(B.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&Ln)){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=B.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(B.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&&!Cl.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Ml{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=El(null,t.preserveWhitespace,0)|(o?zn:0);r?s=new vo(r.type,r.attrs,Q.none,!0,t.topMatch||r.type.contentMatch,i):o?s=new vo(null,null,Q.none,!0,null,i):s=new vo(e.schema.topNodeType,null,Q.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&Lr?"full":this.localPreserveWS||(r.options&Ln)>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
- `);else if(i.linebreakReplacement&&/[\r\n]/.test(o)&&this.top.findWrapping(i.linebreakReplacement.create())){let l=o.split(/\r?\n|\r/);for(let a=0;a<l.length;a++)a&&this.insertNode(i.linebreakReplacement.create(),t,!0),l[a]&&this.insertNode(i.text(l[a]),t,!/\S/.test(l[a]));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],a=e.previousSibling;(!l||a&&a.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;vl.hasOwnProperty(i)&&this.parser.normalizeLists&&Eh(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,o));e:if(a?a.ignore:vh.hasOwnProperty(i))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let d,u=this.needsBlock;if(Cl.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=a&&a.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,a,d,a.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 a=this.parser.matchStyle(s,i,this,l);if(!a)break;if(a.ignore)return null;if(a.clearMark?t=t.filter(d=>!a.clearMark(d)):t=t.concat(this.parser.schema.marks[a.mark].create(a.attrs)),a.consuming===!1)l=a;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 a=this.enter(i,t.attrs||null,o,t.preserveWhitespace);a&&(s=!0,o=a)}else{let a=this.parser.schema.marks[t.mark];o=o.concat(a.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(a=>this.insertNode(a,o,!1));else{let a=e;typeof t.contentElement=="string"?a=e.querySelector(t.contentElement):typeof t.contentElement=="function"?a=t.contentElement(e):t.contentElement&&(a=t.contentElement),this.findAround(e,a,!0),this.addAll(a,o),this.findAround(e,a,!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 a=this.nodes[i],d=a.findWrapping(e);if(d&&(!r||r.length>d.length+l)&&(r=d,s=a,!d.length))break;if(a.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=Q.none;for(let l of r.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):Nl(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=El(e,s,i.options);i.options&zn&&i.content.length==0&&(l|=zn);let a=Q.none;return o=o.filter(d=>(i.type?i.type.allowsMarkType(d.type):Nl(d.type,e))?(a=d.addToSet(a),!1):!0),this.nodes.push(new vo(e,t,a,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|=Ln)}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,a)=>{for(;l>=0;l--){let d=t[l];if(d==""){if(l==t.length-1||l==0)continue;for(;a>=s;a--)if(i(l-1,a))return!0;return!1}else{let u=a>0||a==0&&r?this.nodes[a].type:o&&a>=s?o.node(a-s).type:null;if(!u||u.name!=d&&!u.isInGroup(d))return!1;a--}}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 Eh(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let o=e.nodeType==1?e.nodeName.toLowerCase():null;o&&vl.hasOwnProperty(o)&&t?(t.appendChild(e),e=t):o=="li"?t=e:o&&(t=null)}}function Mh(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function Tl(n){let e={};for(let t in n)e[t]=n[t];return e}function Nl(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 a=0;a<l.edgeCount;a++){let{type:d,next:u}=l.edge(a);if(d==e||s.indexOf(u)<0&&i(u))return!0}};if(i(r.contentMatch))return!0}}class Kt{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},o){o||(o=zr(t).createDocumentFragment());let r=o,s=[];return e.forEach(i=>{if(s.length||i.marks.length){let l=0,a=0;for(;l<s.length&&a<i.marks.length;){let d=i.marks[a];if(!this.marks[d.type.name]){a++;continue}if(!d.eq(s[l][0])||d.type.spec.spanning===!1)break;l++,a++}for(;l<s.length;)r=s.pop()[1];for(;a<i.marks.length;){let d=i.marks[a++],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}=Eo(zr(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&&Eo(zr(o),r(e,t),null,e.attrs)}static renderSpec(e,t,o=null,r){return Eo(e,t,o,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new Kt(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Bl(e.nodes);return t.text||(t.text=o=>o.text),t}static marksFromSchema(e){return Bl(e.marks)}}function Bl(n){let e={};for(let t in n){let o=n[t].spec.toDOM;o&&(e[t]=o)}return e}function zr(n){return n.document||window.document}const Al=new WeakMap;function Th(n){let e=Al.get(n);return e===void 0&&Al.set(n,e=Nh(n)),e}function Nh(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 Eo(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=Th(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,a=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 p=f.indexOf(" ");p>0?a.setAttributeNS(f.slice(0,p),f.slice(p+1),d[f]):f=="style"&&a.style?a.style.cssText=d[f]:a.setAttribute(f,d[f])}}for(let f=u;f<e.length;f++){let p=e[f];if(p===0){if(f<e.length-1||f>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:h,contentDOM:m}=Eo(n,p,t,o);if(a.appendChild(h),m){if(l)throw new RangeError("Multiple content holes");l=m}}}return{dom:a,contentDOM:l}}const Il=65535,Ol=Math.pow(2,16);function Bh(n,e){return n+e*Ol}function Dl(n){return n&Il}function Ah(n){return(n-(n&Il))/Ol}const Rl=1,_l=2,Mo=4,Pl=8;class Fr{constructor(e,t,o){this.pos=e,this.delInfo=t,this.recover=o}get deleted(){return(this.delInfo&Pl)>0}get deletedBefore(){return(this.delInfo&(Rl|Mo))>0}get deletedAfter(){return(this.delInfo&(_l|Mo))>0}get deletedAcross(){return(this.delInfo&Mo)>0}}class _e{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&_e.empty)return _e.empty}recover(e){let t=0,o=Dl(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+Ah(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 a=this.ranges[l]-(this.inverted?r:0);if(a>e)break;let d=this.ranges[l+s],u=this.ranges[l+i],f=a+d;if(e<=f){let p=d?e==a?-1:e==f?1:t:t,h=a+r+(p<0?0:u);if(o)return h;let m=e==(t<0?a:f)?null:Bh(l/3,e-a),g=e==a?_l:e==f?Rl:Mo;return(t<0?e!=a:e!=f)&&(g|=Pl),new Fr(h,g,m)}r+=u-d}return o?e+r:new Fr(e+r,0,null)}touches(e,t){let o=0,r=Dl(t),s=this.inverted?2:1,i=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?o:0);if(a>e)break;let d=this.ranges[l+s],u=a+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),a=i+(this.inverted?0:s),d=this.ranges[r+t],u=this.ranges[r+o];e(l,l+d,a,a+u),s+=u-d}}invert(){return new _e(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?_e.empty:new _e(e<0?[0,-e,0]:[0,0,e])}}_e.empty=new _e([]);class Fn{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 Fn(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 Fn;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 a=this.getMirror(s);if(a!=null&&a>s&&a<this.to){s=a,e=this._maps[a].recover(l.recover);continue}}r|=l.delInfo,e=l.pos}return o?e:new Fr(e,r,null)}}const Hr=Object.create(null);class Ce{getMap(){return _e.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let o=Hr[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 Hr)throw new RangeError("Duplicate use of step JSON ID "+e);return Hr[e]=t,t.prototype.jsonID=e,t}}class ae{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new ae(e,null)}static fail(e){return new ae(null,e)}static fromReplace(e,t,o,r){try{return ae.ok(e.replace(t,o,r))}catch(s){if(s instanceof wo)return ae.fail(s.message);throw s}}}function Wr(n,e,t){let o=[];for(let r=0;r<n.childCount;r++){let s=n.child(r);s.content.size&&(s=s.copy(Wr(s.content,e,s))),s.isInline&&(s=e(s,t,r)),o.push(s)}return B.fromArray(o)}class St extends Ce{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 _(Wr(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 ae.fromReplace(e,this.from,this.to,s)}invert(){return new Ke(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 St(t.pos,o.pos,this.mark)}merge(e){return e instanceof St&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new St(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 St(t.from,t.to,e.markFromJSON(t.mark))}}Ce.jsonID("addMark",St);class Ke extends Ce{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 _(Wr(t.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),t.openStart,t.openEnd);return ae.fromReplace(e,this.from,this.to,o)}invert(){return new St(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 Ke(t.pos,o.pos,this.mark)}merge(e){return e instanceof Ke&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ke(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 Ke(t.from,t.to,e.markFromJSON(t.mark))}}Ce.jsonID("removeMark",Ke);class Ct extends Ce{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ae.fail("No node at mark step's position");let o=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return ae.fromReplace(e,this.pos,this.pos+1,new _(B.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 Ct(this.pos,t.marks[r]);return new Ct(this.pos,this.mark)}}return new qt(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ct(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 Ct(t.pos,e.markFromJSON(t.mark))}}Ce.jsonID("addNodeMark",Ct);class qt extends Ce{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return ae.fail("No node at mark step's position");let o=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return ae.fromReplace(e,this.pos,this.pos+1,new _(B.from(o),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Ct(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new qt(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 qt(t.pos,e.markFromJSON(t.mark))}}Ce.jsonID("removeNodeMark",qt);class he extends Ce{constructor(e,t,o,r=!1){super(),this.from=e,this.to=t,this.slice=o,this.structure=r}apply(e){return this.structure&&jr(e,this.from,this.to)?ae.fail("Structure replace would overwrite content"):ae.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new _e([this.from,this.to-this.from,this.slice.size])}invert(e){return new he(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 he(t.pos,Math.max(t.pos,o.pos),this.slice,this.structure)}merge(e){if(!(e instanceof he)||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?_.empty:new _(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new he(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?_.empty:new _(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new he(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 he(t.from,t.to,_.fromJSON(e,t.slice),!!t.structure)}}Ce.jsonID("replace",he);class pe extends Ce{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&&(jr(e,this.from,this.gapFrom)||jr(e,this.gapTo,this.to)))return ae.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return ae.fail("Gap is not a flat range");let o=this.slice.insertAt(this.insert,t.content);return o?ae.fromReplace(e,this.from,this.to,o):ae.fail("Content does not fit in gap")}getMap(){return new _e([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 pe(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 pe(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 pe(t.from,t.to,t.gapFrom,t.gapTo,_.fromJSON(e,t.slice),t.insert,!!t.structure)}}Ce.jsonID("replaceAround",pe);function jr(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 Ih(n,e,t,o){let r=[],s=[],i,l;n.doc.nodesBetween(e,t,(a,d,u)=>{if(!a.isInline)return;let f=a.marks;if(!o.isInSet(f)&&u.type.allowsMarkType(o.type)){let p=Math.max(d,e),h=Math.min(d+a.nodeSize,t),m=o.addToSet(f);for(let g=0;g<f.length;g++)f[g].isInSet(m)||(i&&i.to==p&&i.mark.eq(f[g])?i.to=h:r.push(i=new Ke(p,h,f[g])));l&&l.to==p?l.to=h:s.push(l=new St(p,h,o))}}),r.forEach(a=>n.step(a)),s.forEach(a=>n.step(a))}function Oh(n,e,t,o){let r=[],s=0;n.doc.nodesBetween(e,t,(i,l)=>{if(!i.isInline)return;s++;let a=null;if(o instanceof Co){let d=i.marks,u;for(;u=o.isInSet(d);)(a||(a=[])).push(u),d=u.removeFromSet(d)}else o?o.isInSet(i.marks)&&(a=[o]):a=i.marks;if(a&&a.length){let d=Math.min(l+i.nodeSize,t);for(let u=0;u<a.length;u++){let f=a[u],p;for(let h=0;h<r.length;h++){let m=r[h];m.step==s-1&&f.eq(r[h].style)&&(p=m)}p?(p.to=d,p.step=s):r.push({style:f,from:Math.max(l,e),to:d,step:s})}}}),r.forEach(i=>n.step(new Ke(i.from,i.to,i.style)))}function Ur(n,e,t,o=t.contentMatch,r=!0){let s=n.doc.nodeAt(e),i=[],l=e+1;for(let a=0;a<s.childCount;a++){let d=s.child(a),u=l+d.nodeSize,f=o.matchType(d.type);if(!f)i.push(new he(l,u,_.empty));else{o=f;for(let p=0;p<d.marks.length;p++)t.allowsMarkType(d.marks[p].type)||n.step(new Ke(l,u,d.marks[p]));if(r&&d.isText&&t.whitespace!="pre"){let p,h=/\r?\n|\r/g,m;for(;p=h.exec(d.text);)m||(m=new _(B.from(t.schema.text(" ",t.allowedMarks(d.marks))),0,0)),i.push(new he(l+p.index,l+p.index+p[0].length,m))}}l=u}if(!o.validEnd){let a=o.fillBefore(B.empty,!0);n.replace(l,l,new _(a,0,0))}for(let a=i.length-1;a>=0;a--)n.step(i[a])}function Dh(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function gn(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,a=n.$to.indexAfter(o)-s;if(o<n.depth&&i.canReplace(l,a,t))return o;if(o==0||i.type.spec.isolating||!Dh(i,l,a))break;l&&(r=1),a<i.childCount&&(s=1)}return null}function Rh(n,e,t){let{$from:o,$to:r,depth:s}=e,i=o.before(s+1),l=r.after(s+1),a=i,d=l,u=B.empty,f=0;for(let m=s,g=!1;m>t;m--)g||o.index(m)>0?(g=!0,u=B.from(o.node(m).copy(u)),f++):a--;let p=B.empty,h=0;for(let m=s,g=!1;m>t;m--)g||r.after(m+1)<r.end(m)?(g=!0,p=B.from(r.node(m).copy(p)),h++):d++;n.step(new pe(a,d,i,l,new _(u.append(p),f,h),u.size-f,!0))}function Vl(n,e,t=null,o=n){let r=_h(n,e),s=r&&Ph(o,e);return s?r.map($l).concat({type:e,attrs:t}).concat(s.map($l)):null}function $l(n){return{type:n,attrs:null}}function _h(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 Ph(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 a=(i.length?i[i.length-1]:e).contentMatch;for(let d=o;a&&d<r;d++)a=a.matchType(t.child(d).type);return!a||!a.validEnd?null:i}function Vh(n,e,t){let o=B.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=B.from(t[i].type.create(t[i].attrs,o))}let r=e.start,s=e.end;n.step(new pe(r,s,r,s,new _(o,0,0),t.length,!0))}function $h(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 a=typeof r=="function"?r(i):r;if(i.isTextblock&&!i.hasMarkup(o,a)&&Lh(n.doc,n.mapping.slice(s).map(l),o)){let d=null;if(o.schema.linebreakReplacement){let h=o.whitespace=="pre",m=!!o.contentMatch.matchType(o.schema.linebreakReplacement);h&&!m?d=!1:!h&&m&&(d=!0)}d===!1&&zl(n,i,l,s),Ur(n,n.mapping.slice(s).map(l,1),o,void 0,d===null);let u=n.mapping.slice(s),f=u.map(l,1),p=u.map(l+i.nodeSize,1);return n.step(new pe(f,p,f+1,p-1,new _(B.from(o.create(a,null,i.marks)),0,0),1,!0)),d===!0&&Ll(n,i,l,s),!1}})}function Ll(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 a=n.mapping.slice(o).map(t+1+s+i.index);n.replaceWith(a,a+1,e.type.schema.linebreakReplacement.create())}}})}function zl(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 Lh(n,e,t){let o=n.resolve(e),r=o.index();return o.parent.canReplaceWith(r,r+1,t)}function zh(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 pe(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new _(B.from(i),0,0),1,!0))}function dt(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),p=r.index(d);if(f.type.spec.isolating)return!1;let h=f.content.cutByIndex(p,f.childCount),m=o&&o[u+1];m&&(h=h.replaceChild(0,m.type.create(m.attrs)));let g=o&&o[u]||f;if(!f.canReplace(p+1,f.childCount)||!g.type.validContent(h))return!1}let l=r.indexAfter(s),a=o&&o[0];return r.node(s).canReplaceWith(l,l,a?a.type:r.node(s+1).type)}function Fh(n,e,t=1,o){let r=n.doc.resolve(e),s=B.empty,i=B.empty;for(let l=r.depth,a=r.depth-t,d=t-1;l>a;l--,d--){s=B.from(r.node(l).copy(s));let u=o&&o[d];i=B.from(u?u.type.create(u.attrs,i):r.node(l).copy(i))}n.step(new he(e,e,new _(s.append(i),t,t),!0))}function Jt(n,e){let t=n.resolve(e),o=t.index();return Fl(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(o,o+1)}function Hh(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 Fl(n,e){return!!(n&&e&&!n.isLeaf&&Hh(n,e))}function To(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&&Fl(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 Wh(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);zl(n,u.node(),u.before(),l)}i.inlineContent&&Ur(n,e+t-1,i,s.node().contentMatchAt(s.index()),o==null);let a=n.mapping.slice(l),d=a.map(e-t);if(n.step(new he(d,a.map(e+t,-1),_.empty,!0)),o===!0){let u=n.doc.resolve(d);Ll(n,u.node(),u.before(),n.steps.length)}return n}function jh(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 Hl(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,a=o.index(i)+(l>0?1:0),d=o.node(i),u=!1;if(s==1)u=d.canReplace(a,a,r);else{let f=d.contentMatchAt(a).findWrapping(r.firstChild.type);u=f&&d.canReplaceWith(a,a,f[0])}if(u)return l==0?o.pos:l<0?o.before(i+1):o.after(i+1)}return null}function No(n,e,t=e,o=_.empty){if(e==t&&!o.size)return null;let r=n.resolve(e),s=n.resolve(t);return Wl(r,s,o)?new he(e,t,o):new Uh(r,s,o).fit()}function Wl(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class Uh{constructor(e,t,o){this.$from=e,this.$to=t,this.unplaced=o,this.frontier=[],this.placed=B.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=B.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 a=new _(s,i,l);return e>-1?new pe(o.pos,e,this.$to.pos,this.$to.end(),a,t):a.size||o.pos!=this.$to.pos?new he(o.pos,r.pos,a):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=Kr(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:a,match:d}=this.frontier[l],u,f=null;if(t==1&&(i?d.matchType(i.type)||(f=d.fillBefore(B.from(i),!1)):s&&a.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=Kr(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new _(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=Kr(e,t);if(r.childCount<=1&&t>0){let s=e.size-t<=t+r.size;this.unplaced=new _(Hn(e,t-1,1),t-1,s?t-1:o)}else this.unplaced=new _(Hn(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,a=i.openStart-e,d=0,u=[],{match:f,type:p}=this.frontier[t];if(r){for(let g=0;g<r.childCount;g++)u.push(r.child(g));f=f.matchFragment(r)}let h=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||a==0||g.content.size)&&(f=y,u.push(jl(g.mark(p.allowedMarks(g.marks)),d==1?a:0,d==l.childCount?h:-1)))}let m=d==l.childCount;m||(h=-1),this.placed=Wn(this.placed,t,B.from(u)),this.frontier[t].match=f,m&&h<0&&o&&o.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let g=0,y=l;g<h;g++){let k=y.lastChild;this.frontier.push({type:k.type,match:k.contentMatchAt(k.childCount)}),y=k.content}this.unplaced=m?e==0?_.empty:new _(Hn(i.content,e-1,1),e-1,h<0?i.openEnd:e-1):new _(Hn(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||!qr(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=qr(e,t,r,o,s);if(i){for(let l=t-1;l>=0;l--){let{match:a,type:d}=this.frontier[l],u=qr(e,l,d,a,!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=Wn(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=Wn(this.placed,this.depth,B.from(e.create(t,o))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(B.empty,!0);t.childCount&&(this.placed=Wn(this.placed,this.frontier.length,t))}}function Hn(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Hn(n.firstChild.content,e-1,t)))}function Wn(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Wn(n.lastChild.content,e-1,t)))}function Kr(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function jl(n,e,t){if(e<=0)return n;let o=n.content;return e>1&&(o=o.replaceChild(0,jl(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(B.empty,!0)))),n.copy(o)}function qr(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&&!Kh(t,s.content,i)?l:null}function Kh(n,e,t){for(let o=t;o<e.childCount;o++)if(!n.allowsMarks(e.child(o).marks))return!0;return!1}function qh(n){return n.spec.defining||n.spec.definingForContent}function Jh(n,e,t,o){if(!o.size)return n.deleteRange(e,t);let r=n.doc.resolve(e),s=n.doc.resolve(t);if(Wl(r,s,o))return n.step(new he(e,t,o));let i=Kl(r,s);i[i.length-1]==0&&i.pop();let l=-(r.depth+1);i.unshift(l);for(let p=r.depth,h=r.pos-1;p>0;p--,h--){let m=r.node(p).type.spec;if(m.defining||m.definingAsContext||m.isolating)break;i.indexOf(p)>-1?l=p:r.before(p)==h&&i.splice(1,0,-p)}let a=i.indexOf(l),d=[],u=o.openStart;for(let p=o.content,h=0;;h++){let m=p.firstChild;if(d.push(m),h==o.openStart)break;p=m.content}for(let p=u-1;p>=0;p--){let h=d[p],m=qh(h.type);if(m&&!h.sameMarkup(r.node(Math.abs(l)-1)))u=p;else if(m||!h.type.isTextblock)break}for(let p=o.openStart;p>=0;p--){let h=(p+u+1)%(o.openStart+1),m=d[h];if(m)for(let g=0;g<i.length;g++){let y=i[(g+a)%i.length],k=!0;y<0&&(k=!1,y=-y);let w=r.node(y-1),b=r.index(y-1);if(w.canReplaceWith(b,b,m.type,m.marks))return n.replace(r.before(y),k?s.after(y):t,new _(Ul(o.content,0,o.openStart,h),h,o.openEnd))}}let f=n.steps.length;for(let p=i.length-1;p>=0&&(n.replace(e,t,o),!(n.steps.length>f));p--){let h=i[p];h<0||(e=r.before(h),t=s.after(h))}}function Ul(n,e,t,o,r){if(e<t){let s=n.firstChild;n=n.replaceChild(0,s.copy(Ul(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(B.empty,!0))}return n}function Gh(n,e,t,o){if(!o.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let r=jh(n.doc,e,o.type);r!=null&&(e=t=r)}n.replaceRange(e,t,new _(B.from(o),0,0))}function Yh(n,e,t){let o=n.doc.resolve(e),r=n.doc.resolve(t),s=Kl(o,r);for(let i=0;i<s.length;i++){let l=s[i],a=i==s.length-1;if(a&&l==0||o.node(l).type.contentMatch.validEnd)return n.delete(o.start(l),r.end(l));if(l>0&&(a||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 Kl(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 yn extends Ce{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 ae.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 ae.fromReplace(e,this.pos,this.pos+1,new _(B.from(r),0,t.isLeaf?0:1))}getMap(){return _e.empty}invert(e){return new yn(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 yn(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 yn(t.pos,t.attr,t.value)}}Ce.jsonID("attr",yn);class jn extends Ce{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 ae.ok(o)}getMap(){return _e.empty}invert(e){return new jn(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 jn(t.attr,t.value)}}Ce.jsonID("docAttr",jn);let kn=class extends Error{};kn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t},kn.prototype=Object.create(Error.prototype),kn.prototype.constructor=kn,kn.prototype.name="TransformError";class ql{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Fn}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new kn(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,a)=>{e=Math.min(e,l),t=Math.max(t,a)})}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=_.empty){let r=No(this.doc,e,t,o);return r&&this.step(r),this}replaceWith(e,t,o){return this.replace(e,t,new _(B.from(o),0,0))}delete(e,t){return this.replace(e,t,_.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,o){return Jh(this,e,t,o),this}replaceRangeWith(e,t,o){return Gh(this,e,t,o),this}deleteRange(e,t){return Yh(this,e,t),this}lift(e,t){return Rh(this,e,t),this}join(e,t=1){return Wh(this,e,t),this}wrap(e,t){return Vh(this,e,t),this}setBlockType(e,t=e,o,r=null){return $h(this,e,t,o,r),this}setNodeMarkup(e,t,o=null,r){return zh(this,e,t,o,r),this}setNodeAttribute(e,t,o){return this.step(new yn(e,t,o)),this}setDocAttribute(e,t){return this.step(new jn(e,t)),this}addNodeMark(e,t){return this.step(new Ct(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 Q)t.isInSet(o.marks)&&this.step(new qt(e,t));else{let r=o.marks,s,i=[];for(;s=t.isInSet(r);)i.push(new qt(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 Fh(this,e,t,o),this}addMark(e,t,o){return Ih(this,e,t,o),this}removeMark(e,t,o){return Oh(this,e,t,o),this}clearIncompatible(e,t,o){return Ur(this,e,t,o),this}}const Jr=Object.create(null);class G{constructor(e,t,o){this.$anchor=e,this.$head=t,this.ranges=o||[new Xh(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=_.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:a,$to:d}=i[l],u=e.mapping.slice(s);e.replaceRange(u.map(a.pos),u.map(d.pos),l?_.empty:t),l==0&&Yl(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],a=e.mapping.slice(o),d=a.map(i.pos),u=a.map(l.pos);s?e.deleteRange(d,u):(e.replaceRangeWith(d,u,t),Yl(e,o,t.isInline?-1:1))}}static findFrom(e,t,o=!1){let r=e.parent.inlineContent?new q(e):wn(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?wn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,o):wn(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 Pe(e.node(0))}static atStart(e){return wn(e,e,0,0,1)||new Pe(e)}static atEnd(e){return wn(e,e,e.content.size,e.childCount,-1)||new Pe(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let o=Jr[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 Jr)throw new RangeError("Duplicate use of selection JSON ID "+e);return Jr[e]=t,t.prototype.jsonID=e,t}getBookmark(){return q.between(this.$anchor,this.$head).getBookmark()}}G.prototype.visible=!0;class Xh{constructor(e,t){this.$from=e,this.$to=t}}let Jl=!1;function Gl(n){!Jl&&!n.parent.inlineContent&&(Jl=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class q extends G{constructor(e,t=e){Gl(e),Gl(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 G.near(o);let r=e.resolve(t.map(this.anchor));return new q(r.parent.inlineContent?r:o,o)}replace(e,t=_.empty){if(super.replace(e,t),t==_.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 Bo(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=G.findFrom(t,o,!0)||G.findFrom(t,-o,!0);if(s)t=s.$head;else return G.near(t,o)}return e.parent.inlineContent||(r==0?e=t:(e=(G.findFrom(e,-o,!0)||G.findFrom(e,o,!0)).$anchor,e.pos<t.pos!=r<0&&(e=t))),new q(e,t)}}G.jsonID("text",q);class Bo{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Bo(e.map(this.anchor),e.map(this.head))}resolve(e){return q.between(e.resolve(this.anchor),e.resolve(this.head))}}class F extends G{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?G.near(s):new F(s)}content(){return new _(B.from(this.node),0,0)}eq(e){return e instanceof F&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Gr(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new F(e.resolve(t.anchor))}static create(e,t){return new F(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}F.prototype.visible=!1,G.jsonID("node",F);class Gr{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:o}=e.mapResult(this.anchor);return t?new Bo(o,o):new Gr(o)}resolve(e){let t=e.resolve(this.anchor),o=t.nodeAfter;return o&&F.isSelectable(o)?new F(t):G.near(t)}}class Pe extends G{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=_.empty){if(t==_.empty){e.delete(0,e.doc.content.size);let o=G.atStart(e.doc);o.eq(e.selection)||e.setSelection(o)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new Pe(e)}map(e){return new Pe(e)}eq(e){return e instanceof Pe}getBookmark(){return Zh}}G.jsonID("all",Pe);const Zh={map(){return this},resolve(n){return new Pe(n)}};function wn(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&&F.isSelectable(l))return F.create(n,t-(r<0?l.nodeSize:0))}else{let a=wn(n,l,t+r,r<0?l.childCount:0,r,s);if(a)return a}t+=l.nodeSize*r}return null}function Yl(n,e,t){let o=n.steps.length-1;if(o<e)return;let r=n.steps[o];if(!(r instanceof he||r instanceof pe))return;let s=n.mapping.maps[o],i;s.forEach((l,a,d,u)=>{i==null&&(i=u)}),n.setSelection(G.near(n.doc.resolve(i),t))}const Xl=1,Ao=2,Zl=4;class Qh extends ql{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|Xl)&~Ao,this.storedMarks=null,this}get selectionSet(){return(this.updated&Xl)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Ao,this}ensureMarks(e){return Q.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&Ao)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Ao,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)||Q.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(G.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|=Zl,this}get scrolledIntoView(){return(this.updated&Zl)>0}}function Ql(n,e){return!e||!n?n:n.bind(e)}class Un{constructor(e,t,o){this.name=e,this.init=Ql(t.init,o),this.apply=Ql(t.apply,o)}}const ep=[new Un("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Un("selection",{init(n,e){return n.selection||G.atStart(e.doc)},apply(n){return n.selection}}),new Un("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,o){return o.selection.$cursor?n.storedMarks:null}}),new Un("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Yr{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=ep.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 Un(o.key,o.spec.state,o))})}}class bn{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 a=r?r[i].n:0,d=r?r[i].state:this,u=a<t.length&&l.spec.appendTransaction.call(l,a?t.slice(a):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 bn(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 Qh(this)}static create(e){let t=new Yr(e.doc?e.doc.type.schema:e.schema,e.plugins),o=new bn(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 Yr(this.schema,e.plugins),o=t.fields,r=new bn(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 Yr(e.schema,e.plugins),s=new bn(r);return r.fields.forEach(i=>{if(i.name=="doc")s.doc=ct.fromJSON(e.schema,t.doc);else if(i.name=="selection")s.selection=G.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 a=o[l],d=a.spec.state;if(a.key==i.name&&d&&d.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[i.name]=d.fromJSON.call(a,e,t[l],s);return}}s[i.name]=i.init(e,s)}}),s}}function ea(n,e,t){for(let o in n){let r=n[o];r instanceof Function?r=r.bind(e):o=="handleDOMEvents"&&(r=ea(r,e,{})),t[o]=r}return t}class ue{constructor(e){this.spec=e,this.props={},e.props&&ea(e.props,this,this.props),this.key=e.key?e.key.key:ta("plugin")}getState(e){return e[this.key]}}const Xr=Object.create(null);function ta(n){return n in Xr?n+"$"+ ++Xr[n]:(Xr[n]=0,n+"$")}class Te{constructor(e="key"){this.key=ta(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Zr=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function na(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const oa=(n,e,t)=>{let o=na(n,t);if(!o)return!1;let r=Qr(o);if(!r){let i=o.blockRange(),l=i&&gn(i);return l==null?!1:(e&&e(n.tr.lift(i,l).scrollIntoView()),!0)}let s=r.nodeBefore;if(fa(n,r,e,-1))return!0;if(o.parent.content.size==0&&(xn(s,"end")||F.isSelectable(s)))for(let i=o.depth;;i--){let l=No(n.doc,o.before(i),o.after(i),_.empty);if(l&&l.slice.size<l.to-l.from){if(e){let a=n.tr.step(l);a.setSelection(xn(s,"end")?G.findFrom(a.doc.resolve(a.mapping.map(r.pos,-1)),-1):F.create(a.doc,r.pos-s.nodeSize)),e(a.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},tp=(n,e,t)=>{let o=na(n,t);if(!o)return!1;let r=Qr(o);return r?ra(n,r,e):!1},np=(n,e,t)=>{let o=ia(n,t);if(!o)return!1;let r=es(o);return r?ra(n,r,e):!1};function ra(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,a=e.pos+1;for(;!l.isTextblock;a++){if(l.type.spec.isolating)return!1;let u=l.firstChild;if(!u)return!1;l=u}let d=No(n.doc,s,a,_.empty);if(!d||d.from!=s||d instanceof he&&d.slice.size>=a-s)return!1;if(t){let u=n.tr.step(d);u.setSelection(q.create(u.doc,s)),t(u.scrollIntoView())}return!0}function xn(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 sa=(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=Qr(o)}let i=s&&s.nodeBefore;return!i||!F.isSelectable(i)?!1:(e&&e(n.tr.setSelection(F.create(n.doc,s.pos-i.nodeSize)).scrollIntoView()),!0)};function Qr(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 ia(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const la=(n,e,t)=>{let o=ia(n,t);if(!o)return!1;let r=es(o);if(!r)return!1;let s=r.nodeAfter;if(fa(n,r,e,1))return!0;if(o.parent.content.size==0&&(xn(s,"start")||F.isSelectable(s))){let i=No(n.doc,o.before(),o.after(),_.empty);if(i&&i.slice.size<i.to-i.from){if(e){let l=n.tr.step(i);l.setSelection(xn(s,"start")?G.findFrom(l.doc.resolve(l.mapping.map(r.pos)),1):F.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},aa=(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=es(o)}let i=s&&s.nodeAfter;return!i||!F.isSelectable(i)?!1:(e&&e(n.tr.setSelection(F.create(n.doc,s.pos)).scrollIntoView()),!0)};function es(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 op=(n,e)=>{let t=n.selection,o=t instanceof F,r;if(o){if(t.node.isTextblock||!Jt(n.doc,t.from))return!1;r=t.from}else if(r=To(n.doc,t.from,-1),r==null)return!1;if(e){let s=n.tr.join(r);o&&s.setSelection(F.create(s.doc,r-n.doc.resolve(r).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},rp=(n,e)=>{let t=n.selection,o;if(t instanceof F){if(t.node.isTextblock||!Jt(n.doc,t.to))return!1;o=t.to}else if(o=To(n.doc,t.to,1),o==null)return!1;return e&&e(n.tr.join(o).scrollIntoView()),!0},sp=(n,e)=>{let{$from:t,$to:o}=n.selection,r=t.blockRange(o),s=r&&gn(r);return s==null?!1:(e&&e(n.tr.lift(r,s).scrollIntoView()),!0)},ca=(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 ts(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 ip=(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=ts(r.contentMatchAt(s));if(!i||!r.canReplaceWith(s,s,i))return!1;if(e){let l=t.after(),a=n.tr.replaceWith(l,l,i.createAndFill());a.setSelection(G.near(a.doc.resolve(l),1)),e(a.scrollIntoView())}return!0},da=(n,e)=>{let t=n.selection,{$from:o,$to:r}=t;if(t instanceof Pe||o.parent.inlineContent||r.parent.inlineContent)return!1;let s=ts(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},ua=(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(dt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let o=t.blockRange(),r=o&&gn(o);return r==null?!1:(e&&e(n.tr.lift(o,r).scrollIntoView()),!0)};function lp(n){return(e,t)=>{let{$from:o,$to:r}=e.selection;if(e.selection instanceof F&&e.selection.node.isBlock)return!o.parentOffset||!dt(e.doc,o.pos)?!1:(t&&t(e.tr.split(o.pos).scrollIntoView()),!0);if(!o.depth)return!1;let s=[],i,l,a=!1,d=!1;for(let h=o.depth;;h--)if(o.node(h).isBlock){a=o.end(h)==o.pos+(o.depth-h),d=o.start(h)==o.pos-(o.depth-h),l=ts(o.node(h-1).contentMatchAt(o.indexAfter(h-1))),s.unshift(a&&l?{type:l}:null),i=h;break}else{if(h==1)return!1;s.unshift(null)}let u=e.tr;(e.selection instanceof q||e.selection instanceof Pe)&&u.deleteSelection();let f=u.mapping.map(o.pos),p=dt(u.doc,f,s.length,s);if(p||(s[0]=l?{type:l}:null,p=dt(u.doc,f,s.length,s)),!p)return!1;if(u.split(f,s.length,s),!a&&d&&o.node(i).type!=l){let h=u.mapping.map(o.before(i)),m=u.doc.resolve(h);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 ap=lp(),cp=(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(F.create(n.doc,r))),!0)};function dp(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||Jt(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function fa(n,e,t,o){let r=e.nodeBefore,s=e.nodeAfter,i,l,a=r.type.spec.isolating||s.type.spec.isolating;if(!a&&dp(n,e,t))return!0;let d=!a&&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 h=e.pos+s.nodeSize,m=B.empty;for(let k=i.length-1;k>=0;k--)m=B.from(i[k].create(null,m));m=B.from(r.copy(m));let g=n.tr.step(new pe(e.pos-1,h,e.pos,h,new _(m,1,0),i.length,!0)),y=g.doc.resolve(h+2*i.length);y.nodeAfter&&y.nodeAfter.type==r.type&&Jt(g.doc,y.pos)&&g.join(y.pos),t(g.scrollIntoView())}return!0}let u=s.type.spec.isolating||o>0&&a?null:G.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),p=f&&gn(f);if(p!=null&&p>=e.depth)return t&&t(n.tr.lift(f,p).scrollIntoView()),!0;if(d&&xn(s,"start",!0)&&xn(r,"end")){let h=r,m=[];for(;m.push(h),!h.isTextblock;)h=h.lastChild;let g=s,y=1;for(;!g.isTextblock;g=g.firstChild)y++;if(h.canReplace(h.childCount,h.childCount,g.content)){if(t){let k=B.empty;for(let b=m.length-1;b>=0;b--)k=B.from(m[b].copy(k));let w=n.tr.step(new pe(e.pos-m.length,e.pos+s.nodeSize,e.pos+y,e.pos+s.nodeSize-y,new _(k,m.length,0),0,!0));t(w.scrollIntoView())}return!0}}return!1}function ha(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 up=ha(-1),fp=ha(1);function hp(n,e=null){return function(t,o){let{$from:r,$to:s}=t.selection,i=r.blockRange(s),l=i&&Vl(i,n,e);return l?(o&&o(t.tr.wrap(i,l).scrollIntoView()),!0):!1}}function pa(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,(a,d)=>{if(r)return!1;if(!(!a.isTextblock||a.hasMarkup(n,e)))if(a.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:a}}=t.selection.ranges[i];s.setBlockType(l,a,n,e)}o(s.scrollIntoView())}return!0}}function ns(...n){return function(e,t,o){for(let r=0;r<n.length;r++)if(n[r](e,t,o))return!0;return!1}}ns(Zr,oa,sa),ns(Zr,la,aa),ns(ca,da,ua,ap),typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function pp(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 mp(l,i,n,e)?(o&&o(l.scrollIntoView()),!0):!1}}function mp(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 a=i.resolve(e.start-2);s=new xo(a,a,e.depth),e.endIndex<e.parent.childCount&&(e=new xo(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),r=!0}let l=Vl(s,t,o,e);return l?(n&&gp(n,e,l,r,t),!0):!1}function gp(n,e,t,o,r){let s=B.empty;for(let u=t.length-1;u>=0;u--)s=B.from(t[u].type.create(t[u].attrs,s));n.step(new pe(e.start-(o?2:0),e.end,e.start,e.end,new _(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,a=e.start+t.length-(o?2:0),d=e.parent;for(let u=e.startIndex,f=e.endIndex,p=!0;u<f;u++,p=!1)!p&&dt(n.doc,a,l)&&(n.split(a,l),a+=2*l),a+=d.child(u).nodeSize;return n}function yp(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?kp(e,t,n,s):wp(e,t,s):!0:!1}}function kp(n,e,t,o){let r=n.tr,s=o.end,i=o.$to.end(o.depth);s<i&&(r.step(new pe(s-1,i,s,i,new _(B.from(t.create(null,o.parent.copy())),1,0),1,!0)),o=new xo(r.doc.resolve(o.$from.pos),r.doc.resolve(i),o.depth));const l=gn(o);if(l==null)return!1;r.lift(o,l);let a=r.doc.resolve(r.mapping.map(s,-1)-1);return Jt(r.doc,a.pos)&&a.nodeBefore.type==a.nodeAfter.type&&r.join(a.pos),e(r.scrollIntoView()),!0}function wp(n,e,t){let o=n.tr,r=t.parent;for(let h=t.end,m=t.endIndex-1,g=t.startIndex;m>g;m--)h-=r.child(m).nodeSize,o.delete(h-1,h+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,a=t.endIndex==r.childCount,d=s.node(-1),u=s.index(-1);if(!d.canReplace(u+(l?0:1),u+1,i.content.append(a?B.empty:B.from(r))))return!1;let f=s.pos,p=f+i.nodeSize;return o.step(new pe(f-(l?1:0),p+(a?1:0),f+1,p-1,new _((l?B.empty:B.from(r.copy(B.empty))).append(a?B.empty:B.from(r.copy(B.empty))),l?0:1,a?0:1),l?0:1)),e(o.scrollIntoView()),!0}function bp(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,a=l.child(i-1);if(a.type!=n)return!1;if(t){let d=a.lastChild&&a.lastChild.type==l.type,u=B.from(d?n.create():null),f=new _(B.from(n.create(null,B.from(l.type.create(null,u)))),d?3:1,0),p=s.start,h=s.end;t(e.tr.step(new pe(p-(d?3:1),h,p,h,f,1,!0)).scrollIntoView())}return!0}}const we=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Sn=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let rs=null;const ut=function(n,e,t){let o=rs||(rs=document.createRange());return o.setEnd(n,t??n.nodeValue.length),o.setStart(n,e||0),o},xp=function(){rs=null},Gt=function(n,e,t,o){return t&&(ma(n,e,t,o,-1)||ma(n,e,t,o,1))},Sp=/^(img|br|input|textarea|hr)$/i;function ma(n,e,t,o,r){for(var s;;){if(n==t&&e==o)return!0;if(e==(r<0?0:Le(n))){let i=n.parentNode;if(!i||i.nodeType!=1||Kn(n)||Sp.test(n.nodeName)||n.contentEditable=="false")return!1;e=we(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?Le(n):0}else return!1}}function Le(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Cp(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=Le(n)}else if(n.parentNode&&!Kn(n))e=we(n),n=n.parentNode;else return null}}function vp(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&&!Kn(n))e=we(n)+1,n=n.parentNode;else return null}}function Ep(n,e,t){for(let o=e==0,r=e==Le(n);o||r;){if(n==t)return!0;let s=we(n);if(n=n.parentNode,!n)return!1;o=o&&s==0,r=r&&s==Le(n)}}function Kn(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 Io=function(n){return n.focusNode&&Gt(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function Yt(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function Mp(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Tp(n,e,t){if(n.caretPositionFromPoint)try{let o=n.caretPositionFromPoint(e,t);if(o)return{node:o.offsetNode,offset:Math.min(Le(o.offsetNode),o.offset)}}catch{}if(n.caretRangeFromPoint){let o=n.caretRangeFromPoint(e,t);if(o)return{node:o.startContainer,offset:Math.min(Le(o.startContainer),o.startOffset)}}}const et=typeof navigator<"u"?navigator:null,ga=typeof document<"u"?document:null,vt=et&&et.userAgent||"",ss=/Edge\/(\d+)/.exec(vt),ya=/MSIE \d/.exec(vt),is=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(vt),Ie=!!(ya||is||ss),Et=ya?document.documentMode:is?+is[1]:ss?+ss[1]:0,ze=!Ie&&/gecko\/(\d+)/i.test(vt);ze&&+(/Firefox\/(\d+)/.exec(vt)||[0,0])[1];const ls=!Ie&&/Chrome\/(\d+)/.exec(vt),be=!!ls,ka=ls?+ls[1]:0,ve=!Ie&&!!et&&/Apple Computer/.test(et.vendor),Cn=ve&&(/Mobile\/\w+/.test(vt)||!!et&&et.maxTouchPoints>2),Fe=Cn||(et?/Mac/.test(et.platform):!1),wa=et?/Win/.test(et.platform):!1,ft=/Android \d/.test(vt),qn=!!ga&&"webkitFontSmoothing"in ga.documentElement.style,Np=qn?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Bp(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 ht(n,e){return typeof n=="number"?n:n[e]}function Ap(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 ba(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=Sn(i);continue}let l=i,a=l==s.body,d=a?Bp(s):Ap(l),u=0,f=0;if(e.top<d.top+ht(o,"top")?f=-(d.top-e.top+ht(r,"top")):e.bottom>d.bottom-ht(o,"bottom")&&(f=e.bottom-e.top>d.bottom-d.top?e.top+ht(r,"top")-d.top:e.bottom-d.bottom+ht(r,"bottom")),e.left<d.left+ht(o,"left")?u=-(d.left-e.left+ht(r,"left")):e.right>d.right-ht(o,"right")&&(u=e.right-d.right+ht(r,"right")),u||f)if(a)s.defaultView.scrollBy(u,f);else{let h=l.scrollLeft,m=l.scrollTop;f&&(l.scrollTop+=f),u&&(l.scrollLeft+=u);let g=l.scrollLeft-h,y=l.scrollTop-m;e={left:e.left-g,top:e.top-y,right:e.right-g,bottom:e.bottom-y}}let p=a?"fixed":getComputedStyle(i).position;if(/^(fixed|sticky)$/.test(p))break;i=p=="absolute"?i.offsetParent:Sn(i)}}function Ip(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 a=l.getBoundingClientRect();if(a.top>=t-20){o=l,r=a.top;break}}return{refDOM:o,refTop:r,stack:xa(n.dom)}}function xa(n){let e=[],t=n.ownerDocument;for(let o=n;o&&(e.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),n!=t);o=Sn(o));return e}function Op({refDOM:n,refTop:e,stack:t}){let o=n?n.getBoundingClientRect().top:0;Sa(t,o==0?0:o-e)}function Sa(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 vn=null;function Dp(n){if(n.setActive)return n.setActive();if(vn)return n.focus(vn);let e=xa(n);n.focus(vn==null?{get preventScroll(){return vn={preventScroll:!0},!0}}:void 0),vn||(vn=!1,Sa(e,0))}function Ca(n,e){let t,o=2e8,r,s=0,i=e.top,l=e.top,a,d;for(let u=n.firstChild,f=0;u;u=u.nextSibling,f++){let p;if(u.nodeType==1)p=u.getClientRects();else if(u.nodeType==3)p=ut(u).getClientRects();else continue;for(let h=0;h<p.length;h++){let m=p[h];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&&!a&&m.left<=e.left&&m.right>=e.left&&(a=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&&a&&(t=a,r=d,o=0),t&&t.nodeType==3?Rp(t,r):!t||o&&t.nodeType==1?{node:n,offset:s}:Ca(t,r)}function Rp(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=Mt(o,1);if(i.top!=i.bottom&&as(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 as(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function _p(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function Pp(n,e,t){let{node:o,offset:r}=Ca(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 Vp(n,e,t,o){let r=-1;for(let s=e,i=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0),a;if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent||!l.contentDOM)&&((a=l.dom.getBoundingClientRect()).width||a.height)&&(l.node.isBlock&&l.parent&&!/^T(R|BODY|HEAD|FOOT)$/.test(l.dom.nodeName)&&(!i&&a.left>o.left||a.top>o.top?r=l.posBefore:(!i&&a.right<o.left||a.bottom<o.top)&&(r=l.posAfter),i=!0),!l.contentDOM&&r<0&&!l.node.isText))return(l.node.isBlock?o.top<(a.top+a.bottom)/2:o.left<(a.left+a.right)/2)?l.posBefore:l.posAfter;s=l.dom.parentNode}return r>-1?r:n.docView.posFromDOM(e,t,-1)}function va(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 a=0;a<l.length;a++){let d=l[a];if(as(e,d))return va(i,e,d)}}if((s=(s+1)%o)==r)break}return n}function $p(n,e){let t=n.dom.ownerDocument,o,r=0,s=Tp(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(!as(e,d)||(i=va(n.dom,e,d),!i))return null}if(ve)for(let d=i;o&&d;d=Sn(d))d.draggable&&(o=void 0);if(i=_p(i,e),o){if(ze&&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;qn&&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=Vp(n,o,r,e))}l==null&&(l=Pp(n,i,e));let a=n.docView.nearestDesc(i,!0);return{pos:l,inside:a?a.posAtStart-a.border:-1}}function Ea(n){return n.top<n.bottom||n.left<n.right}function Mt(n,e){let t=n.getClientRects();if(t.length){let o=t[e<0?0:t.length-1];if(Ea(o))return o}return Array.prototype.find.call(t,Ea)||n.getBoundingClientRect()}const Lp=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Ma(n,e,t){let{node:o,offset:r,atom:s}=n.docView.domFromPos(e,t<0?-1:1),i=qn||ze;if(o.nodeType==3)if(i&&(Lp.test(o.nodeValue)||(t<0?!r:r==o.nodeValue.length))){let a=Mt(ut(o,r,r),t);if(ze&&r&&/\s/.test(o.nodeValue[r-1])&&r<o.nodeValue.length){let d=Mt(ut(o,r-1,r-1),-1);if(d.top==a.top){let u=Mt(ut(o,r,r+1),-1);if(u.top!=a.top)return Jn(u,u.left<d.left)}}return a}else{let a=r,d=r,u=t<0?1:-1;return t<0&&!r?(d++,u=-1):t>=0&&r==o.nodeValue.length?(a--,u=1):t<0?a--:d++,Jn(Mt(ut(o,a,d),u),u<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&r&&(t<0||r==Le(o))){let a=o.childNodes[r-1];if(a.nodeType==1)return cs(a.getBoundingClientRect(),!1)}if(s==null&&r<Le(o)){let a=o.childNodes[r];if(a.nodeType==1)return cs(a.getBoundingClientRect(),!0)}return cs(o.getBoundingClientRect(),t>=0)}if(s==null&&r&&(t<0||r==Le(o))){let a=o.childNodes[r-1],d=a.nodeType==3?ut(a,Le(a)-(i?0:1)):a.nodeType==1&&(a.nodeName!="BR"||!a.nextSibling)?a:null;if(d)return Jn(Mt(d,1),!1)}if(s==null&&r<Le(o)){let a=o.childNodes[r];for(;a.pmViewDesc&&a.pmViewDesc.ignoreForCoords;)a=a.nextSibling;let d=a?a.nodeType==3?ut(a,0,i?0:1):a.nodeType==1?a:null:null;if(d)return Jn(Mt(d,-1),!0)}return Jn(Mt(o.nodeType==3?ut(o):o,-t),t>=0)}function Jn(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 cs(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 Ta(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 zp(n,e,t){let o=e.selection,r=t=="up"?o.$from:o.$to;return Ta(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=Ma(n,r.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let a;if(l.nodeType==1)a=l.getClientRects();else if(l.nodeType==3)a=ut(l,0,l.nodeValue.length).getClientRects();else continue;for(let d=0;d<a.length;d++){let u=a[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 Fp=/[\u0590-\u08ac]/;function Hp(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?!Fp.test(o.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:i:Ta(n,e,()=>{let{focusNode:a,focusOffset:d,anchorNode:u,anchorOffset:f}=n.domSelectionRange(),p=l.caretBidiLevel;l.modify("move",t,"character");let h=o.depth?n.docView.domAfterPos(o.before()):n.dom,{focusNode:m,focusOffset:g}=n.domSelectionRange(),y=m&&!h.contains(m.nodeType==1?m:m.parentNode)||a==m&&d==g;try{l.collapse(u,f),a&&(a!=u||d!=f)&&l.extend&&l.extend(a,d)}catch{}return p!=null&&(l.caretBidiLevel=p),y}):o.pos==o.start()||o.pos==o.end()}let Na=null,Ba=null,Aa=!1;function Wp(n,e,t){return Na==e&&Ba==t?Aa:(Na=e,Ba=t,Aa=t=="up"||t=="down"?zp(n,e,t):Hp(n,e,t))}const He=0,Ia=1,Xt=2,tt=3;class Gn{constructor(e,t,o,r){this.parent=e,this.children=t,this.dom=o,this.contentDOM=r,this.dirty=He,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>we(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 Ra){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 Oa&&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?we(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?we(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 a=this.children[l],d=i+a.size;if(r==-1&&e<=d){let u=i+a.border;if(e>=u&&t<=d-a.border&&a.node&&a.contentDOM&&this.contentDOM.contains(a.contentDOM))return a.parseRange(e,t,u);e=i;for(let f=l;f>0;f--){let p=this.children[f-1];if(p.size&&p.dom.parentNode==this.contentDOM&&!p.emptyChildAt(1)){r=we(p.dom)+1;break}e-=p.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=we(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 h=0,m=0;h<this.children.length;h++){let g=this.children[h],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),a=t==e?l:this.domFromPos(t,t?-1:1),d=o.root.getSelection(),u=o.domSelectionRange(),f=!1;if((ze||ve)&&e==t){let{node:h,offset:m}=l;if(h.nodeType==3){if(f=!!(m&&h.nodeValue[m-1]==`
7
- `),f&&m==h.nodeValue.length)for(let g=h,y;g;g=g.parentNode){if(y=g.nextSibling){y.nodeName=="BR"&&(l=a={node:y.parentNode,offset:we(y)+1});break}let k=g.pmViewDesc;if(k&&k.node&&k.node.isBlock)break}}else{let g=h.childNodes[m-1];f=g&&(g.nodeName=="BR"||g.contentEditable=="false")}}if(ze&&u.focusNode&&u.focusNode!=a.node&&u.focusNode.nodeType==1){let h=u.focusNode.childNodes[u.focusOffset];h&&h.contentEditable=="false"&&(r=!0)}if(!(r||f&&ve)&&Gt(l.node,l.offset,u.anchorNode,u.anchorOffset)&&Gt(a.node,a.offset,u.focusNode,u.focusOffset))return;let p=!1;if((d.extend||e==t)&&!(f&&ze)){d.collapse(l.node,l.offset);try{e!=t&&d.extend(a.node,a.offset),p=!0}catch{}}if(!p){if(e>t){let m=l;l=a,a=m}let h=document.createRange();h.setEnd(a.node,a.offset),h.setStart(l.node,l.offset),d.removeAllRanges(),d.addRange(h)}}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,a=i-s.border;if(e>=l&&t<=a){this.dirty=e==o||t==i?Xt:Ia,e==l&&t==a&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=tt:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Xt:tt}o=i}this.dirty=Xt}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let o=e==1?Xt:Ia;t.dirty<o&&(t.dirty=o)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class Oa extends Gn{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==He&&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 jp extends Gn{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 Zt extends Gn{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=Kt.renderSpec(document,t.type.spec.toDOM(t,o),null,t.attrs)),new Zt(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return this.dirty&tt||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=tt&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=He){let o=this.parent;for(;!o.node;)o=o.parent;o.dirty<this.dirty&&(o.dirty=this.dirty),this.dirty=He}}slice(e,t,o){let r=Zt.create(this.parent,this.mark,!0,o),s=this.children,i=this.size;t<i&&(s=us(s,t,i,o)),e>0&&(s=us(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 Tt extends Gn{constructor(e,t,o,r,s,i,l,a,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],a,d=l&&l(t,s,()=>{if(!a)return i;if(a.parent)return a.parent.posBeforeChild(a)},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}=Kt.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 p=u;return u=Va(u,o,t),d?a=new Up(e,t,o,r,u,f||null,p,d,s,i+1):t.isText?new Oo(e,t,o,r,u,p,s):new Tt(e,t,o,r,u,f||null,p,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=()=>B.empty)}return e}matchesNode(e,t,o){return this.dirty==He&&e.eq(this.node)&&Do(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,a=new qp(this,i&&i.node,e);Yp(this.node,this.innerDeco,(d,u,f)=>{d.spec.marks?a.syncToMarks(d.spec.marks,o,e,u):d.type.side>=0&&!f&&a.syncToMarks(u==this.node.childCount?Q.none:this.node.child(u).marks,o,e,u),a.placeWidget(d,e,r)},(d,u,f,p)=>{a.syncToMarks(d.marks,o,e,p);let h;a.findNodeMatch(d,u,f,p)||l&&e.state.selection.from>r&&e.state.selection.to<r+d.nodeSize&&(h=a.findIndexWithChild(s.node))>-1&&a.updateNodeAt(d,u,f,h,e)||a.updateNextNode(d,u,f,e,p,r)||a.addNode(d,u,f,e,r),r+=d.nodeSize}),a.syncToMarks([],o,e,0),this.node.isTextblock&&a.addTextblockHacks(),a.destroyRest(),(a.changed||this.dirty==Xt)&&(i&&this.protectLocalComposition(e,i),_a(this.contentDOM,this.children,e),Cn&&Xp(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=Zp(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 jp(this,s,t,r);e.input.compositionNodes.push(i),this.children=us(this.children,o,o+r.length,e,i)}update(e,t,o,r){return this.dirty==tt||!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=He}updateOuterDeco(e){if(Do(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,o=this.dom;this.dom=Pa(this.dom,this.nodeDOM,ds(this.outerDeco,this.node,t),ds(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 Da(n,e,t,o,r){Va(o,e,n);let s=new Tt(void 0,n,e,t,o,o,o,r,0);return s.contentDOM&&s.updateChildren(r,0),s}class Oo extends Tt{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==tt||this.dirty!=He&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=He||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=He,!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 Oo(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=tt)}get domAtom(){return!1}isText(e){return this.node.text==e}}class Ra extends Gn{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==He&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class Up extends Tt{constructor(e,t,o,r,s,i,l,a,d,u){super(e,t,o,r,s,i,l,d,u),this.spec=a}update(e,t,o,r){if(this.dirty==tt)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 _a(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=$a(o),r=!0;o=o.nextSibling}else r=!0,n.insertBefore(l,o);if(i instanceof Zt){let a=o?o.previousSibling:n.lastChild;_a(i.contentDOM,i.children,t),o=a?a.nextSibling:n.firstChild}}for(;o;)o=$a(o),r=!0;r&&t.trackWrites==n&&(t.trackWrites=null)}const Yn=function(n){n&&(this.nodeName=n)};Yn.prototype=Object.create(null);const Qt=[new Yn];function ds(n,e,t){if(n.length==0)return Qt;let o=t?Qt[0]:new Yn,r=[o];for(let s=0;s<n.length;s++){let i=n[s].type.attrs;if(i){i.nodeName&&r.push(o=new Yn(i.nodeName));for(let l in i){let a=i[l];a!=null&&(t&&r.length==1&&r.push(o=new Yn(e.isInline?"span":"div")),l=="class"?o.class=(o.class?o.class+" ":"")+a:l=="style"?o.style=(o.style?o.style+";":"")+a:l!="nodeName"&&(o[l]=a))}}}return r}function Pa(n,e,t,o){if(t==Qt&&o==Qt)return e;let r=e;for(let s=0;s<o.length;s++){let i=o[s],l=t[s];if(s){let a;l&&l.nodeName==i.nodeName&&r!=n&&(a=r.parentNode)&&a.nodeName.toLowerCase()==i.nodeName||(a=document.createElement(i.nodeName),a.pmIsDeco=!0,a.appendChild(r),l=Qt[0]),r=a}Kp(r,l||Qt[0],i)}return r}function Kp(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 Va(n,e,t){return Pa(n,n,Qt,ds(e,t,n.nodeType!=1))}function Do(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 $a(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class qp{constructor(e,t,o){this.lock=t,this.view=o,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=Jp(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=He,this.index=this.stack.pop(),this.top=this.stack.pop(),i--;for(;i<e.length;){this.stack.push(this.top,this.index+1);let a=-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)){a=u;break}}if(a>-1)a>this.index&&(this.changed=!0,this.destroyBetween(this.index,a)),this.top=this.top.children[this.index];else{let u=Zt.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,a=Math.min(this.top.children.length,l+5);l<a;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==tt&&i.dom==i.contentDOM&&(i.dirty=Xt),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 a=this.top.children[l];if(a instanceof Tt){let d=this.preMatch.matched.get(a);if(d!=null&&d!=s)return!1;let u=a.dom,f,p=this.isLocked(u)&&!(e.isText&&a.node&&a.node.isText&&a.nodeDOM.nodeValue==e.text&&a.dirty!=tt&&Do(t,a.outerDeco));if(!p&&a.update(e,t,o,r))return this.destroyBetween(this.index,l),a.dom!=u&&(this.changed=!0),this.index++,!0;if(!p&&(f=this.recreateWrapper(a,e,t,o,r,i)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=Xt,f.updateChildren(r,i+1),f.dirty=He),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)||!Do(o,e.outerDeco)||!r.eq(e.innerDeco))return null;let l=Tt.create(this.top,t,o,r,s,i);if(l.contentDOM){l.children=e.children,e.children=[];for(let a of l.children)a.parent=l}return e.destroy(),l}addNode(e,t,o,r,s){let i=Tt.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 Oa(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 Zt;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Oo)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((ve||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 Ra(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 Jp(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 Zt)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 a=l.node;if(a){if(a!=n.child(r-1))break;--r,s.set(l,r),i.push(l)}}return{index:r,matched:s,matches:i.reverse()}}function Gp(n,e){return n.type.side-e.type.side}function Yp(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=[],a=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(Gp);for(let y=0;y<f.length;y++)t(f[y],d,!!a)}else t(u,d,!!a);let p,h;if(a)h=-1,p=a,a=null;else if(d<n.childCount)h=d,p=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+p.nodeSize;if(p.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&&(a=p.cut(y-s),p=p.cut(0,y-s),m=y,h=-1)}else for(;i<r.length&&r[i].to<m;)i++;let g=p.isInline&&!p.isLeaf?l.filter(y=>!y.inline):l.slice();o(p,g,e.forChild(s,p),h),s=m}}function Xp(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 Zp(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 a=i.text;for(;r<n.childCount;){let d=n.child(r++);if(s+=d.nodeSize,!d.isText)break;a+=d.text}if(s>=t){if(s>=o&&a.slice(o-e.length-l,o-l)==e)return o-e.length;let d=l<o?a.lastIndexOf(e,o-l-1):-1;if(d>=0&&d+e.length+l>=t)return l+d;if(t==o&&a.length>=o+e.length-l&&a.slice(o-l,o-l+e.length)==e)return o}}return-1}function us(n,e,t,o,r){let s=[];for(let i=0,l=0;i<n.length;i++){let a=n[i],d=l,u=l+=a.size;d>=t||u<=e?s.push(a):(d<e&&s.push(a.slice(0,e-d,o)),r&&(s.push(r),r=void 0),u>t&&s.push(a.slice(t-d,a.size,o)))}return s}function fs(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),a,d;if(Io(t)){for(a=i;r&&!r.node;)r=r.parent;let f=r.node;if(r&&f.isAtom&&F.isSelectable(f)&&r.parent&&!(f.isInline&&Ep(t.focusNode,t.focusOffset,r.dom))){let p=r.posBefore;d=new F(i==p?l:o.resolve(p))}}else{if(t instanceof n.dom.ownerDocument.defaultView.Selection&&t.rangeCount>1){let f=i,p=i;for(let h=0;h<t.rangeCount;h++){let m=t.getRangeAt(h);f=Math.min(f,n.docView.posFromDOM(m.startContainer,m.startOffset,1)),p=Math.max(p,n.docView.posFromDOM(m.endContainer,m.endOffset,-1))}if(f<0)return null;[a,i]=p==n.state.selection.anchor?[p,f]:[f,p],l=o.resolve(i)}else a=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(a<0)return null}let u=o.resolve(a);if(!d){let f=e=="pointer"||n.state.selection.head<l.pos&&!s?1:-1;d=ps(n,u,l,f)}return d}function La(n){return n.editable?n.hasFocus():Ka(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function pt(n,e=!1){let t=n.state.selection;if(Wa(n,t),!!La(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&be){let o=n.domSelectionRange(),r=n.domObserver.currentSelection;if(o.anchorNode&&r.anchorNode&&Gt(o.anchorNode,o.anchorOffset,r.anchorNode,r.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)em(n);else{let{anchor:o,head:r}=t,s,i;za&&!(t instanceof q)&&(t.$from.parent.inlineContent||(s=Fa(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(i=Fa(n,t.to))),n.docView.setSelection(o,r,n,e),za&&(s&&Ha(s),i&&Ha(i)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&Qp(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const za=ve||be&&ka<63;function Fa(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(ve&&r&&r.contentEditable=="false")return hs(r);if((!r||r.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(r)return hs(r);if(s)return hs(s)}}function hs(n){return n.contentEditable="true",ve&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function Ha(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function Qp(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(()=>{(!La(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function em(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,o=t.nodeName=="IMG";o?e.collapse(t.parentNode,we(t)+1):e.collapse(t,0),!o&&!n.state.selection.visible&&Ie&&Et<=11&&(t.disabled=!0,t.disabled=!1)}function Wa(n,e){if(e instanceof F){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(ja(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else ja(n)}function ja(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function ps(n,e,t,o){return n.someProp("createSelectionBetween",r=>r(n,e,t))||q.between(e,t,o)}function Ua(n){return n.editable&&!n.hasFocus()?!1:Ka(n)}function Ka(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 tm(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return Gt(e.node,e.offset,t.anchorNode,t.anchorOffset)}function ms(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&&G.findFrom(s,e)}function Nt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function qa(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 Nt(n,new q(o.$anchor,i))}else if(o.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let r=ms(n.state,e);return r&&r instanceof F?Nt(n,r):!1}else if(!(Fe&&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?F.isSelectable(s)?Nt(n,new F(e<0?n.state.doc.resolve(r.pos-s.nodeSize):r)):qn?Nt(n,new q(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(o instanceof F&&o.node.isInline)return Nt(n,new q(e>0?o.$to:o.$from));{let r=ms(n.state,e);return r?Nt(n,r):!1}}}function Ro(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Xn(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function En(n,e){return e<0?nm(n):om(n)}function nm(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r,s,i=!1;for(ze&&t.nodeType==1&&o<Ro(t)&&Xn(t.childNodes[o],-1)&&(i=!0);;)if(o>0){if(t.nodeType!=1)break;{let l=t.childNodes[o-1];if(Xn(l,-1))r=t,s=--o;else if(l.nodeType==3)t=l,o=t.nodeValue.length;else break}}else{if(Ja(t))break;{let l=t.previousSibling;for(;l&&Xn(l,-1);)r=t.parentNode,s=we(l),l=l.previousSibling;if(l)t=l,o=Ro(t);else{if(t=t.parentNode,t==n.dom)break;o=0}}}i?gs(n,t,o):r&&gs(n,r,s)}function om(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r=Ro(t),s,i;for(;;)if(o<r){if(t.nodeType!=1)break;let l=t.childNodes[o];if(Xn(l,1))s=t,i=++o;else break}else{if(Ja(t))break;{let l=t.nextSibling;for(;l&&Xn(l,1);)s=l.parentNode,i=we(l)+1,l=l.nextSibling;if(l)t=l,o=0,r=Ro(t);else{if(t=t.parentNode,t==n.dom)break;o=r=0}}}s&&gs(n,s,i)}function Ja(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function rm(n,e){for(;n&&e==n.childNodes.length&&!Kn(n);)e=we(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 sm(n,e){for(;n&&!e&&!Kn(n);)e=we(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 gs(n,e,t){if(e.nodeType!=3){let s,i;(i=rm(e,t))?(e=i,t=0):(s=sm(e,t))&&(e=s,t=s.nodeValue.length)}let o=n.domSelection();if(!o)return;if(Io(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&&pt(n)},50)}function Ga(n,e){let t=n.state.doc.resolve(e);if(!(be||wa)&&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 Ya(n,e,t){let o=n.state.selection;if(o instanceof q&&!o.empty||t.indexOf("s")>-1||Fe&&t.indexOf("m")>-1)return!1;let{$from:r,$to:s}=o;if(!r.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let i=ms(n.state,e);if(i&&i instanceof F)return Nt(n,i)}if(!r.parent.inlineContent){let i=e<0?r:s,l=o instanceof Pe?G.near(i,e):G.findFrom(i,e);return l?Nt(n,l):!1}return!1}function Xa(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 Za(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function im(n){if(!ve||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;Za(n,o,"true"),setTimeout(()=>Za(n,o,"false"),20)}return!1}function lm(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function am(n,e){let t=e.keyCode,o=lm(e);if(t==8||Fe&&t==72&&o=="c")return Xa(n,-1)||En(n,-1);if(t==46&&!e.shiftKey||Fe&&t==68&&o=="c")return Xa(n,1)||En(n,1);if(t==13||t==27)return!0;if(t==37||Fe&&t==66&&o=="c"){let r=t==37?Ga(n,n.state.selection.from)=="ltr"?-1:1:-1;return qa(n,r,o)||En(n,r)}else if(t==39||Fe&&t==70&&o=="c"){let r=t==39?Ga(n,n.state.selection.from)=="ltr"?1:-1:1;return qa(n,r,o)||En(n,r)}else{if(t==38||Fe&&t==80&&o=="c")return Ya(n,-1,o)||En(n,-1);if(t==40||Fe&&t==78&&o=="c")return im(n)||Ya(n,1,o)||En(n,1);if(o==(Fe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function ys(n,e){n.someProp("transformCopied",h=>{e=h(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 h=o.firstChild;t.push(h.type.name,h.attrs!=h.type.defaultAttrs?h.attrs:null),o=h.content}let i=n.someProp("clipboardSerializer")||Kt.fromSchema(n.state.schema),l=ic(),a=l.createElement("div");a.appendChild(i.serializeFragment(o,{document:l}));let d=a.firstChild,u,f=0;for(;d&&d.nodeType==1&&(u=rc[d.nodeName.toLowerCase()]);){for(let h=u.length-1;h>=0;h--){let m=l.createElement(u[h]);for(;a.firstChild;)m.appendChild(a.firstChild);a.appendChild(m),f++}d=a.firstChild}d&&d.nodeType==1&&d.setAttribute("data-pm-slice",`${r} ${s}${f?` -${f}`:""} ${JSON.stringify(t)}`);let p=n.someProp("clipboardTextSerializer",h=>h(e,n))||e.content.textBetween(0,e.content.size,`
8
-
9
- `);return{dom:a,text:p,slice:e}}function Qa(n,e,t,o,r){let s=r.parent.type.spec.code,i,l;if(!t&&!e)return null;let a=!!e&&(o||s||!t);if(a){if(n.someProp("transformPastedText",p=>{e=p(e,s||o,n)}),s)return l=new _(B.from(n.state.schema.text(e.replace(/\r\n?/g,`
10
- `))),0,0),n.someProp("transformPasted",p=>{l=p(l,n,!0)}),l;let f=n.someProp("clipboardTextParser",p=>p(e,r,o,n));if(f)l=f;else{let p=r.marks(),{schema:h}=n.state,m=Kt.fromSchema(h);i=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(g=>{let y=i.appendChild(document.createElement("p"));g&&y.appendChild(m.serializeNode(h.text(g,p)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),i=fm(t),qn&&hm(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 p=i.firstChild;for(;p&&p.nodeType!=1;)p=p.nextSibling;if(!p)break;i=p}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||mn.fromSchema(n.state.schema)).parseSlice(i,{preserveWhitespace:!!(a||u),context:r,ruleFromNode(p){return p.nodeName=="BR"&&!p.nextSibling&&p.parentNode&&!cm.test(p.parentNode.nodeName)?{ignore:!0}:null}})),u)l=pm(oc(l,+u[1],+u[2]),u[4]);else if(l=_.maxOpen(dm(l.content,r),!0),l.openStart||l.openEnd){let f=0,p=0;for(let h=l.content.firstChild;f<l.openStart&&!h.type.spec.isolating;f++,h=h.firstChild);for(let h=l.content.lastChild;p<l.openEnd&&!h.type.spec.isolating;p++,h=h.lastChild);l=oc(l,f,p)}return n.someProp("transformPasted",f=>{l=f(l,n,a)}),l}const cm=/^(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 dm(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 a=r.findWrapping(l.type),d;if(!a)return i=null;if(d=i.length&&s.length&&tc(a,s,l,i[i.length-1],0))i[i.length-1]=d;else{i.length&&(i[i.length-1]=nc(i[i.length-1],s.length));let u=ec(l,a);i.push(u),r=r.matchType(u.type),s=a}}),i)return B.from(i)}return n}function ec(n,e,t=0){for(let o=e.length-1;o>=t;o--)n=e[o].create(null,B.from(n));return n}function tc(n,e,t,o,r){if(r<n.length&&r<e.length&&n[r]==e[r]){let s=tc(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(B.from(ec(t,n,r+1))))}}function nc(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,nc(n.lastChild,e-1)),o=n.contentMatchAt(n.childCount).fillBefore(B.empty,!0);return n.copy(t.append(o))}function ks(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=ks(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(B.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,i.copy(l))}function oc(n,e,t){return e<n.openStart&&(n=new _(ks(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new _(ks(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const rc={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 sc=null;function ic(){return sc||(sc=document.implementation.createHTMLDocument("title"))}let ws=null;function um(n){let e=window.trustedTypes;return e?(ws||(ws=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),ws.createHTML(n)):n}function fm(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=ic().createElement("div"),o=/<([a-z][^>\s]+)/i.exec(n),r;if((r=o&&rc[o[1].toLowerCase()])&&(n=r.map(s=>"<"+s+">").join("")+n+r.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=um(n),r)for(let s=0;s<r.length;s++)t=t.querySelector(r[s])||t;return t}function hm(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 pm(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 a=t.nodes[o[l]];if(!a||a.hasRequiredAttrs())break;r=B.from(a.create(o[l+1],r)),s++,i++}return new _(r,s,i)}const Ne={},Be={},mm={touchstart:!0,touchmove:!0};class gm{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 ym(n){for(let e in Ne){let t=Ne[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=o=>{wm(n,o)&&!xs(n,o)&&(n.editable||!(o.type in Be))&&t(n,o)},mm[e]?{passive:!0}:void 0)}ve&&n.dom.addEventListener("input",()=>null),bs(n)}function Bt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function km(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 bs(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=o=>xs(n,o))})}function xs(n,e){return n.someProp("handleDOMEvents",t=>{let o=t[e.type];return o?o(n,e)||e.defaultPrevented:!1})}function wm(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 bm(n,e){!xs(n,e)&&Ne[e.type]&&(n.editable||!(e.type in Be))&&Ne[e.type](n,e)}Be.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!ac(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(ft&&be&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),Cn&&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,Yt(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",o=>o(n,t))||am(n,t)?t.preventDefault():Bt(n,"key")},Be.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)},Be.keypress=(n,e)=>{let t=e;if(ac(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Fe&&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 _o(n){return{left:n.clientX,top:n.clientY}}function xm(n,e){let t=e.x-n.clientX,o=e.y-n.clientY;return t*t+o*o<100}function Ss(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 Mn(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 Sm(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),o=t.nodeAfter;return o&&o.isAtom&&F.isSelectable(o)?(Mn(n,new F(t)),!0):!1}function Cm(n,e){if(e==-1)return!1;let t=n.state.selection,o,r;t instanceof F&&(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(F.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?(Mn(n,F.create(n.state.doc,r)),!0):!1}function vm(n,e,t,o,r){return Ss(n,"handleClickOn",e,t,o)||n.someProp("handleClick",s=>s(n,e,o))||(r?Cm(n,t):Sm(n,t))}function Em(n,e,t,o){return Ss(n,"handleDoubleClickOn",e,t,o)||n.someProp("handleDoubleClick",r=>r(n,e,o))}function Mm(n,e,t,o){return Ss(n,"handleTripleClickOn",e,t,o)||n.someProp("handleTripleClick",r=>r(n,e,o))||Tm(n,t,o)}function Tm(n,e,t){if(t.button!=0)return!1;let o=n.state.doc;if(e==-1)return o.inlineContent?(Mn(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)Mn(n,q.create(o,l+1,l+1+i.content.size));else if(F.isSelectable(i))Mn(n,F.create(o,l));else continue;return!0}}function Cs(n){return Po(n)}const lc=Fe?"metaKey":"ctrlKey";Ne.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let o=Cs(n),r=Date.now(),s="singleClick";r-n.input.lastClick.time<500&&xm(t,n.input.lastClick)&&!t[lc]&&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(_o(t));i&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new Nm(n,i,t,!!o)):(s=="doubleClick"?Em:Mm)(n,i.pos,i.inside,t)?t.preventDefault():Bt(n,"pointer"))};class Nm{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[lc],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,a=l?e.docView.nearestDesc(l,!0):null;this.target=a&&a.nodeDOM.nodeType==1?a.nodeDOM:null;let{selection:d}=e.state;(o.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||d instanceof F&&d.from<=i&&d.to>i)&&(this.mightDrag={node:s,pos:i,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ze&&!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)),Bt(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(()=>pt(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(_o(e))),this.updateAllowDefault(e),this.allowDefault||!t?Bt(this.view,"pointer"):vm(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||ve&&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)?(Mn(this.view,G.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Bt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Bt(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)}}Ne.touchstart=n=>{n.input.lastTouch=Date.now(),Cs(n),Bt(n,"pointer")},Ne.touchmove=n=>{n.input.lastTouch=Date.now(),Bt(n,"pointer")},Ne.contextmenu=n=>Cs(n);function ac(n,e){return n.composing?!0:ve&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const Bm=ft?5e3:-1;Be.compositionstart=Be.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&&wa&&Am(n)))n.markCursor=n.state.storedMarks||t.marks(),Po(n,!0),n.markCursor=null;else if(Po(n,!e.selection.empty),ze&&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}cc(n,Bm)};function Am(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"}Be.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++,cc(n,20))};function cc(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Po(n),e))}function dc(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=Om());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function Im(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=Cp(e.focusNode,e.focusOffset),o=vp(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 Om(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Po(n,e=!1){if(!(ft&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),dc(n),e||n.docView&&n.docView.dirty){let t=fs(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 Dm(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 Zn=Ie&&Et<15||Cn&&Np<604;Ne.copy=Be.cut=(n,e)=>{let t=e,o=n.state.selection,r=t.type=="cut";if(o.empty)return;let s=Zn?null:t.clipboardData,i=o.content(),{dom:l,text:a}=ys(n,i);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",a)):Dm(n,l),r&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function Rm(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function _m(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?Qn(n,o.value,null,r,e):Qn(n,o.textContent,o.innerHTML,r,e)},50)}function Qn(n,e,t,o,r){let s=Qa(n,e,t,o,n.state.selection.$from);if(n.someProp("handlePaste",a=>a(n,r,s||_.empty)))return!0;if(!s)return!1;let i=Rm(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 uc(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," "):""}Be.paste=(n,e)=>{let t=e;if(n.composing&&!ft)return;let o=Zn?null:t.clipboardData,r=n.input.shiftKey&&n.input.lastKeyCode!=45;o&&Qn(n,uc(o),o.getData("text/html"),r,t)?t.preventDefault():_m(n,t)};class fc{constructor(e,t,o){this.slice=e,this.move=t,this.node=o}}const Pm=Fe?"altKey":"ctrlKey";function hc(n,e){let t=n.someProp("dragCopies",o=>!o(e));return t??!e[Pm]}Ne.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(_o(t)),i;if(!(s&&s.pos>=r.from&&s.pos<=(r instanceof F?r.to-1:r.to))){if(o&&o.mightDrag)i=F.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=F.create(n.state.doc,f.posBefore))}}let l=(i||n.state.selection).content(),{dom:a,text:d,slice:u}=ys(n,l);(!t.dataTransfer.files.length||!be||ka>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Zn?"Text":"text/html",a.innerHTML),t.dataTransfer.effectAllowed="copyMove",Zn||t.dataTransfer.setData("text/plain",d),n.dragging=new fc(u,hc(n,t),i)},Ne.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)},Be.dragover=Be.dragenter=(n,e)=>e.preventDefault(),Be.drop=(n,e)=>{try{Vm(n,e,n.dragging)}finally{n.dragging=null}};function Vm(n,e,t){if(!e.dataTransfer)return;let o=n.posAtCoords(_o(e));if(!o)return;let r=n.state.doc.resolve(o.pos),s=t&&t.slice;s?n.someProp("transformPasted",h=>{s=h(s,n,!1)}):s=Qa(n,uc(e.dataTransfer),Zn?null:e.dataTransfer.getData("text/html"),!1,r);let i=!!(t&&hc(n,e));if(n.someProp("handleDrop",h=>h(n,e,s||_.empty,i))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Hl(n.state.doc,r.pos,s):r.pos;l==null&&(l=r.pos);let a=n.state.tr;if(i){let{node:h}=t;h?h.replace(a):a.deleteSelection()}let d=a.mapping.map(l),u=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=a.doc;if(u?a.replaceRangeWith(d,d,s.content.firstChild):a.replaceRange(d,d,s),a.doc.eq(f))return;let p=a.doc.resolve(d);if(u&&F.isSelectable(s.content.firstChild)&&p.nodeAfter&&p.nodeAfter.sameMarkup(s.content.firstChild))a.setSelection(new F(p));else{let h=a.mapping.map(l);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,y,k)=>h=k),a.setSelection(ps(n,p,a.doc.resolve(h)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))}Ne.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())&&pt(n)},20))},Ne.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)},Ne.beforeinput=(n,e)=>{if(be&&ft&&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,Yt(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 Be)Ne[n]=Be[n];function eo(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 Vo{constructor(e,t){this.toDOM=e,this.spec=t||en,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 Ae(s-o,s-o,this)}valid(){return!0}eq(e){return this==e||e instanceof Vo&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&eo(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class At{constructor(e,t){this.attrs=e,this.spec=t||en}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 Ae(s,i,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof At&&eo(this.attrs,e.attrs)&&eo(this.spec,e.spec)}static is(e){return e.type instanceof At}destroy(){}}class vs{constructor(e,t){this.attrs=e,this.spec=t||en}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 Ae(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 vs&&eo(this.attrs,e.attrs)&&eo(this.spec,e.spec)}destroy(){}}class Ae{constructor(e,t,o){this.from=e,this.to=t,this.type=o}copy(e,t){return new Ae(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 Ae(e,e,new Vo(t,o))}static inline(e,t,o,r){return new Ae(e,t,new At(o,r))}static node(e,t,o,r){return new Ae(e,t,new vs(o,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof At}get widget(){return this.type instanceof Vo}}const Tn=[],en={};class re{constructor(e,t){this.local=e.length?e:Tn,this.children=t.length?t:Tn}static create(e,t){return t.length?$o(t,e,0,en):Ee}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==Ee||e.maps.length==0?this:this.mapInner(e,t,0,0,o||en)}mapInner(e,t,o,r,s){let i;for(let l=0;l<this.local.length;l++){let a=this.local[l].map(e,o,r);a&&a.type.valid(t,a)?(i||(i=[])).push(a):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?$m(this.children,i||[],e,t,o,r,s):i?new re(i.sort(tn),Tn):Ee}add(e,t){return t.length?this==Ee?re.create(e,t):this.addInner(e,t,0):this}addInner(e,t,o){let r,s=0;e.forEach((l,a)=>{let d=a+o,u;if(u=mc(t,l,d)){for(r||(r=this.children.slice());s<r.length&&r[s]<a;)s+=3;r[s]==a?r[s+2]=r[s+2].addInner(l,u,d+1):r.splice(s,0,a,a+l.nodeSize,$o(u,l,d+1,en)),s+=3}});let i=pc(s?gc(t):t,-o);for(let l=0;l<i.length;l++)i[l].type.valid(e,i[l])||i.splice(l--,1);return new re(i.length?this.local.concat(i).sort(tn):this.local,r||this.children)}remove(e){return e.length==0||this==Ee?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,a=o[s+1]+t;for(let u=0,f;u<e.length;u++)(f=e[u])&&f.from>l&&f.to<a&&(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!=Ee?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 re(r,o):Ee}forChild(e,t){if(this==Ee)return this;if(t.isLeaf)return re.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 a=this.local[l];if(a.from<i&&a.to>s&&a.type instanceof At){let d=Math.max(s,a.from)-s,u=Math.min(i,a.to)-s;d<u&&(r||(r=[])).push(a.copy(d,u))}}if(r){let l=new re(r.sort(tn),Tn);return o?new It([l,o]):l}return o||Ee}eq(e){if(this==e)return!0;if(!(e instanceof re)||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 Es(this.localsInner(e))}localsInner(e){if(this==Ee)return Tn;if(e.inlineContent||!this.local.some(At.is))return this.local;let t=[];for(let o=0;o<this.local.length;o++)this.local[o].type instanceof At||t.push(this.local[o]);return t}forEachSet(e){e(this)}}re.empty=new re([],[]),re.removeOverlap=Es;const Ee=re.empty;class It{constructor(e){this.members=e}map(e,t){const o=this.members.map(r=>r.map(e,t,en));return It.from(o)}forChild(e,t){if(t.isLeaf)return re.empty;let o=[];for(let r=0;r<this.members.length;r++){let s=this.members[r].forChild(e,t);s!=Ee&&(s instanceof It?o=o.concat(s.members):o.push(s))}return It.from(o)}eq(e){if(!(e instanceof It)||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?Es(o?t:t.sort(tn)):Tn}static from(e){switch(e.length){case 0:return Ee;case 1:return e[0];default:return new It(e.every(t=>t instanceof re)?e:e.reduce((t,o)=>t.concat(o instanceof re?o:o.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function $m(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((p,h,m,g)=>{let y=g-m-(h-p);for(let k=0;k<l.length;k+=3){let w=l[k+1];if(w<0||p>w+u-f)continue;let b=l[k]+u-f;h>=b?l[k+1]=p<=b?-2:-1:p>=u&&y&&(l[k]+=y,l[k+1]+=y)}f+=y}),u=t.maps[d].map(u,-1)}let a=!1;for(let d=0;d<l.length;d+=3)if(l[d+1]<0){if(l[d+1]==-2){a=!0,l[d+1]=-1;continue}let u=t.map(n[d]+s),f=u-r;if(f<0||f>=o.content.size){a=!0;continue}let p=t.map(n[d+1]+s,-1),h=p-r,{index:m,offset:g}=o.content.findIndex(f),y=o.maybeChild(m);if(y&&g==f&&g+y.nodeSize==h){let k=l[d+2].mapInner(t,y,u+1,n[d]+s+1,i);k!=Ee?(l[d]=f,l[d+1]=h,l[d+2]=k):(l[d+1]=-2,a=!0)}else a=!0}if(a){let d=Lm(l,n,e,t,r,s,i),u=$o(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,p=0;f<u.children.length;f+=3){let h=u.children[f];for(;p<l.length&&l[p]<h;)p+=3;l.splice(p,0,u.children[f],u.children[f+1],u.children[f+2])}}return new re(e.sort(tn),l)}function pc(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 Ae(r.from+e,r.to+e,r.type))}return t}function Lm(n,e,t,o,r,s,i){function l(a,d){for(let u=0;u<a.local.length;u++){let f=a.local[u].map(o,r,d);f?t.push(f):i.onRemove&&i.onRemove(a.local[u].spec)}for(let u=0;u<a.children.length;u+=3)l(a.children[u+2],a.children[u]+d+1)}for(let a=0;a<n.length;a+=3)n[a+1]==-1&&l(n[a+2],e[a]+s+1);return t}function mc(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 gc(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function $o(n,e,t,o){let r=[],s=!1;e.forEach((l,a)=>{let d=mc(n,l,a+t);if(d){s=!0;let u=$o(d,l,t+a+1,o);u!=Ee&&r.push(a,a+l.nodeSize,u)}});let i=pc(s?gc(n):n,-t).sort(tn);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 re(i,r):Ee}function tn(n,e){return n.from-e.from||n.to-e.to}function Es(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),yc(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),yc(e,r,o.copy(s.from,o.to)));break}}}return e}function yc(n,e,t){for(;e<n.length&&tn(t,n[e])>0;)e++;n.splice(e,0,t)}function Ms(n){let e=[];return n.someProp("decorations",t=>{let o=t(n.state);o&&o!=Ee&&e.push(o)}),n.cursorWrapper&&e.push(re.create(n.state.doc,[n.cursorWrapper.deco])),It.from(e)}const zm={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},Fm=Ie&&Et<=11;class Hm{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 Wm{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Hm,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]);Ie&&Et<=11&&o.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():ve&&e.composing&&o.some(r=>r.type=="childList"&&r.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),Fm&&(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,zm)),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(Ua(this.view)){if(this.suppressingSelectionUpdates)return pt(this.view);if(Ie&&Et<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Gt(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=Sn(s))t.add(s);for(let s=e.anchorNode;s;s=Sn(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)&&Ua(e)&&!this.ignoreSelectionChange(o),s=-1,i=-1,l=!1,a=[];if(e.editable)for(let u=0;u<t.length;u++){let f=this.registerMutation(t[u],a);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(a.some(u=>u.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46)){for(let u of a)if(u.nodeName=="BR"&&u.parentNode){let f=u.nextSibling;f&&f.nodeType==1&&f.contentEditable=="false"&&u.parentNode.removeChild(u)}}else if(ze&&a.length){let u=a.filter(f=>f.nodeName=="BR");if(u.length==2){let[f,p]=u;f.parentNode&&f.parentNode.parentNode==p.parentNode?p.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let p of u){let h=p.parentNode;h&&h.nodeName=="LI"&&(!f||Km(e,f)!=h)&&p.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&&Io(o)&&(d=fs(e))&&d.eq(G.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,pt(e),this.currentSelection.set(o),e.scrollToSelection()):(s>-1||r)&&(s>-1&&(e.docView.markDirty(s,i),jm(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,qm(e,a)),this.handleDOMChange(s,i,l,a),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(o)||pt(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(Ie&&Et<=11&&e.addedNodes.length)for(let u=0;u<e.addedNodes.length;u++){let{previousSibling:f,nextSibling:p}=e.addedNodes[u];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(r=f),(!p||Array.prototype.indexOf.call(e.addedNodes,p)<0)&&(s=p)}let i=r&&r.parentNode==e.target?we(r)+1:0,l=o.localPosFromDOM(e.target,i,-1),a=s&&s.parentNode==e.target?we(s):e.target.childNodes.length,d=o.localPosFromDOM(e.target,a,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 kc=new WeakMap,wc=!1;function jm(n){if(!kc.has(n)&&(kc.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=ze,wc)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."),wc=!0}}function bc(n,e){let t=e.startContainer,o=e.startOffset,r=e.endContainer,s=e.endOffset,i=n.domAtPos(n.state.selection.anchor);return Gt(i.node,i.offset,r,s)&&([t,o,r,s]=[r,s,t,o]),{anchorNode:t,anchorOffset:o,focusNode:r,focusOffset:s}}function Um(n,e){if(e.getComposedRanges){let r=e.getComposedRanges(n.root)[0];if(r)return bc(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?bc(n,t):null}function Km(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 qm(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 a=l.firstChild;if(!a||a.nodeType!=1||a.contentEditable=="false"||/^(BR|IMG)$/.test(a.nodeName))break;l=a}l.insertBefore(s,l.firstChild),o==s&&n.domSelection().collapse(s,r)}else s.parentNode.removeChild(s)}}function Jm(n,e,t){let{node:o,fromOffset:r,toOffset:s,from:i,to:l}=n.docView.parseRange(e,t),a=n.domSelectionRange(),d,u=a.anchorNode;if(u&&n.dom.contains(u.nodeType==1?u:u.parentNode)&&(d=[{node:u,offset:a.anchorOffset}],Io(a)||d.push({node:a.focusNode,offset:a.focusOffset})),be&&n.input.lastKeyCode===8)for(let y=s;y>r;y--){let k=o.childNodes[y-1],w=k.pmViewDesc;if(k.nodeName=="BR"&&!w){s=y;break}if(!w||w.size)break}let f=n.state.doc,p=n.someProp("domParser")||mn.fromSchema(n.state.schema),h=f.resolve(i),m=null,g=p.parse(o,{topNode:h.parent,topMatch:h.parent.contentMatchAt(h.index()),topOpen:!0,from:r,to:s,preserveWhitespace:h.parent.type.whitespace=="pre"?"full":!0,findPositions:d,ruleFromNode:Gm,context:h});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 Gm(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(ve&&/^(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||ve&&/^(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 Ym=/^(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 Xm(n,e,t,o,r){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let v=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,E=fs(n,v);if(E&&!n.state.selection.eq(E)){if(be&&ft&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",A=>A(n,Yt(13,"Enter"))))return;let T=n.state.tr.setSelection(E);v=="pointer"?T.setMeta("pointer",!0):v=="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 a=n.state.selection,d=Jm(n,e,t),u=n.state.doc,f=u.slice(d.from,d.to),p,h;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(p=n.state.selection.to,h="end"):(p=n.state.selection.from,h="start"),n.input.lastKeyCode=null;let m=eg(f.content,d.doc.content,d.from,p,h);if(m&&n.input.domChangeCount++,(Cn&&n.input.lastIOSEnter>Date.now()-225||ft)&&r.some(v=>v.nodeType==1&&!Ym.test(v.nodeName))&&(!m||m.endA>=m.endB)&&n.someProp("handleKeyDown",v=>v(n,Yt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!m)if(o&&a instanceof q&&!a.empty&&a.$head.sameParent(a.$anchor)&&!n.composing&&!(d.sel&&d.sel.anchor!=d.sel.head))m={start:a.from,endA:a.to,endB:a.to};else{if(d.sel){let v=xc(n,n.state.doc,d.sel);if(v&&!v.eq(n.state.selection)){let E=n.state.tr.setSelection(v);s&&E.setMeta("composition",s),n.dispatch(E)}}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)),Ie&&Et<=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),w=g.sameParent(y)&&g.parent.inlineContent&&k.end()>=m.endA;if((Cn&&n.input.lastIOSEnter>Date.now()-225&&(!w||r.some(v=>v.nodeName=="DIV"||v.nodeName=="P"))||!w&&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",v=>v(n,Yt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>m.start&&Qm(u,m.start,m.endA,g,y)&&n.someProp("handleKeyDown",v=>v(n,Yt(8,"Backspace")))){ft&&be&&n.domObserver.suppressSelectionUpdates();return}be&&m.endB==m.start&&(n.input.lastChromeDelete=Date.now()),ft&&!w&&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(v){return v(n,Yt(13,"Enter"))})},20));let b=m.start,S=m.endA,C=v=>{let E=v||n.state.tr.replace(b,S,d.doc.slice(m.start-d.from,m.endB-d.from));if(d.sel){let T=xc(n,E.doc,d.sel);T&&!(be&&n.composing&&T.empty&&(m.start!=m.endB||n.input.lastChromeDelete<Date.now()-100)&&(T.head==b||T.head==E.mapping.map(S)-1)||Ie&&T.empty&&T.head==b)&&E.setSelection(T)}return s&&E.setMeta("composition",s),E.scrollIntoView()},M;if(w)if(g.pos==y.pos){Ie&&Et<=11&&g.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>pt(n),20));let v=C(n.state.tr.delete(b,S)),E=u.resolve(m.start).marksAcross(u.resolve(m.endA));E&&v.ensureMarks(E),n.dispatch(v)}else if(m.endA==m.endB&&(M=Zm(g.parent.content.cut(g.parentOffset,y.parentOffset),k.parent.content.cut(k.parentOffset,m.endA-k.start())))){let v=C(n.state.tr);M.type=="add"?v.addMark(b,S,M.mark):v.removeMark(b,S,M.mark),n.dispatch(v)}else if(g.parent.child(g.index()).isText&&g.index()==y.index()-(y.textOffset?0:1)){let v=g.parent.textBetween(g.parentOffset,y.parentOffset),E=()=>C(n.state.tr.insertText(v,b,S));n.someProp("handleTextInput",T=>T(n,b,S,v,E))||n.dispatch(E())}else n.dispatch(C());else n.dispatch(C())}function xc(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:ps(n,e.resolve(t.anchor),e.resolve(t.head))}function Zm(n,e){let t=n.firstChild.marks,o=e.firstChild.marks,r=t,s=o,i,l,a;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",a=u=>u.mark(l.addToSet(u.marks));else if(r.length==0&&s.length==1)l=s[0],i="remove",a=u=>u.mark(l.removeFromSet(u.marks));else return null;let d=[];for(let u=0;u<e.childCount;u++)d.push(a(e.child(u)));if(B.from(d).eq(n))return{mark:l,type:i}}function Qm(n,e,t,o,r){if(t-e<=r.pos-o.pos||Ts(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(Ts(s,!0,!0));return!i.parent.isTextblock||i.pos>t||Ts(i,!0,!1)<t?!1:o.parent.content.cut(o.parentOffset).eq(i.parent.content)}function Ts(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 eg(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 a=Math.max(0,s-Math.min(i,l));o-=i+a-s}if(i<s&&n.size<e.size){let a=o<=s&&o>=i?s-o:0;s-=a,s&&s<e.size&&Sc(e.textBetween(s-1,s+1))&&(s+=a?1:-1),l=s+(l-i),i=s}else if(l<s){let a=o<=s&&o>=l?s-o:0;s-=a,s&&s<n.size&&Sc(n.textBetween(s-1,s+1))&&(s+=a?1:-1),i=s+(i-l),l=s}return{start:s,endA:i,endB:l}}function Sc(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 Cc{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 gm,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Nc),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=Mc(this),Ec(this),this.nodeViews=Tc(this),this.docView=Da(this.state.doc,vc(this),Ms(this),this.dom,this),this.domObserver=new Wm(this,(o,r,s,i)=>Xm(this,o,r,s,i)),this.domObserver.start(),ym(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&&bs(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Nc),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&&(dc(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 h=Tc(this);ng(h,this.nodeViews)&&(this.nodeViews=h,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&bs(this),this.editable=Mc(this),Ec(this);let a=Ms(this),d=vc(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,a);(f||!e.selection.eq(r.selection))&&(i=!0);let p=u=="preserve"&&i&&this.dom.style.overflowAnchor==null&&Ip(this);if(i){this.domObserver.stop();let h=f&&(Ie||be)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&tg(r.selection,e.selection);if(f){let m=be?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=Im(this)),(s||!this.docView.update(e.doc,d,a,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=Da(e.doc,d,a,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(h=!0)}h||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&tm(this))?pt(this,h):(Wa(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():p&&Op(p)}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 F){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&ba(this,t.getBoundingClientRect(),e)}else ba(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 fc(e.slice,e.move,r<0?void 0:F.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(Ie){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&&Dp(this.dom),pt(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 $p(this,e)}coordsAtPos(e,t=1){return Ma(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 Wp(this,t||this.state,e)}pasteHTML(e,t){return Qn(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Qn(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return ys(this,e)}destroy(){this.docView&&(km(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ms(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,xp())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return bm(this,e)}domSelectionRange(){let e=this.domSelection();return e?ve&&this.root.nodeType===11&&Mp(this.dom.ownerDocument)==this.dom&&Um(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}Cc.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function vc(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"),[Ae.node(0,n.state.doc.content.size,e)]}function Ec(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:Ae.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Mc(n){return!n.someProp("editable",e=>e(n.state)===!1)}function tg(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 Tc(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 ng(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 Nc(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 Ot={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:"'"},Lo={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},og=typeof navigator<"u"&&/Mac/.test(navigator.platform),rg=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),xe=0;xe<10;xe++)Ot[48+xe]=Ot[96+xe]=String(xe);for(var xe=1;xe<=24;xe++)Ot[xe+111]="F"+xe;for(var xe=65;xe<=90;xe++)Ot[xe]=String.fromCharCode(xe+32),Lo[xe]=String.fromCharCode(xe);for(var Ns in Ot)Lo.hasOwnProperty(Ns)||(Lo[Ns]=Ot[Ns]);function sg(n){var e=og&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||rg&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Lo:Ot)[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 ig=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),lg=typeof navigator<"u"&&/Win/.test(navigator.platform);function ag(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 a=e[l];if(/^(cmd|meta|m)$/i.test(a))i=!0;else if(/^a(lt)?$/i.test(a))o=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))ig?i=!0:r=!0;else throw new Error("Unrecognized modifier name: "+a)}return o&&(t="Alt-"+t),r&&(t="Ctrl-"+t),i&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function cg(n){let e=Object.create(null);for(let t in n)e[ag(t)]=n[t];return e}function Bs(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 dg(n){return new ue({props:{handleKeyDown:Bc(n)}})}function Bc(n){let e=cg(n);return function(t,o){let r=sg(o),s,i=e[Bs(r,o)];if(i&&i(t.state,t.dispatch,t))return!0;if(r.length==1&&r!=" "){if(o.shiftKey){let l=e[Bs(r,o,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((o.altKey||o.metaKey||o.ctrlKey)&&!(lg&&o.ctrlKey&&o.altKey)&&(s=Ot[o.keyCode])&&s!=r){let l=e[Bs(s,o)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var ug=Object.defineProperty,As=(n,e)=>{for(var t in e)ug(n,t,{get:e[t],enumerable:!0})};function zo(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 Fo=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,a=n||r.tr,d=()=>(!l&&e&&!a.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(a),i.every(f=>f===!0)),u={...Object.fromEntries(Object.entries(t).map(([f,p])=>[f,(...m)=>{const g=this.buildProps(a,e),y=p(...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,a])=>[l,(...d)=>a(...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:zo({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,a])=>[l,(...d)=>a(...d)(i)]))}};return i}},Ac={};As(Ac,{blur:()=>fg,clearContent:()=>hg,clearNodes:()=>pg,command:()=>mg,createParagraphNear:()=>gg,cut:()=>yg,deleteCurrentNode:()=>kg,deleteNode:()=>wg,deleteRange:()=>bg,deleteSelection:()=>xg,enter:()=>Sg,exitCode:()=>Cg,extendMarkRange:()=>vg,first:()=>Eg,focus:()=>Tg,forEach:()=>Ng,insertContent:()=>Bg,insertContentAt:()=>Og,joinBackward:()=>_g,joinDown:()=>Rg,joinForward:()=>Pg,joinItemBackward:()=>Vg,joinItemForward:()=>$g,joinTextblockBackward:()=>Lg,joinTextblockForward:()=>zg,joinUp:()=>Dg,keyboardShortcut:()=>Hg,lift:()=>Wg,liftEmptyBlock:()=>jg,liftListItem:()=>Ug,newlineInCode:()=>Kg,resetAttributes:()=>qg,scrollIntoView:()=>Jg,selectAll:()=>Gg,selectNodeBackward:()=>Yg,selectNodeForward:()=>Xg,selectParentNode:()=>Zg,selectTextblockEnd:()=>Qg,selectTextblockStart:()=>e0,setContent:()=>t0,setMark:()=>b0,setMeta:()=>x0,setNode:()=>S0,setNodeSelection:()=>C0,setTextDirection:()=>v0,setTextSelection:()=>E0,sinkListItem:()=>M0,splitBlock:()=>T0,splitListItem:()=>N0,toggleList:()=>B0,toggleMark:()=>A0,toggleNode:()=>I0,toggleWrap:()=>O0,undoInputRule:()=>D0,unsetAllMarks:()=>R0,unsetMark:()=>_0,unsetTextDirection:()=>P0,updateAttributes:()=>V0,wrapIn:()=>$0,wrapInList:()=>L0});var fg=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())==null||t.removeAllRanges())}),!0),hg=(n=!0)=>({commands:e})=>e.setContent("",{emitUpdate:n}),pg=()=>({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,a)=>{if(l.type.isText)return;const{doc:d,mapping:u}=e,f=d.resolve(u.map(a)),p=d.resolve(u.map(a+l.nodeSize)),h=f.blockRange(p);if(!h)return;const m=gn(h);if(l.type.isTextblock){const{defaultType:g}=f.parent.contentMatchAt(f.index());e.setNodeMarkup(h.start,g)}(m||m===0)&&e.lift(h,m)})}),!0},mg=n=>e=>n(e),gg=()=>({state:n,dispatch:e})=>da(n,e),yg=(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},kg=()=>({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),a=r.after(s);n.delete(l,a).scrollIntoView()}return!0}return!1};function me(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 wg=n=>({tr:e,state:t,dispatch:o})=>{const r=me(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 a=s.before(i),d=s.after(i);e.delete(a,d).scrollIntoView()}return!0}return!1},bg=n=>({tr:e,dispatch:t})=>{const{from:o,to:r}=n;return t&&e.delete(o,r),!0},xg=()=>({state:n,dispatch:e})=>Zr(n,e),Sg=()=>({commands:n})=>n.keyboardShortcut("Enter"),Cg=()=>({state:n,dispatch:e})=>ip(n,e);function Is(n){return Object.prototype.toString.call(n)==="[object RegExp]"}function Ho(n,e,t={strict:!0}){const o=Object.keys(e);return o.length?o.every(r=>t.strict?e[r]===n[r]:Is(e[r])?e[r].test(n[r]):e[r]===n[r]):!0}function Ic(n,e,t={}){return n.find(o=>o.type===e&&Ho(Object.fromEntries(Object.keys(t).map(r=>[r,o.attrs[r]])),t))}function Oc(n,e,t={}){return!!Ic(n,e,t)}function Os(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),!Ic([...r.node.marks],e,t)))return;let i=r.index,l=n.start()+r.offset,a=i+1,d=l+r.node.nodeSize;for(;i>0&&Oc([...n.parent.child(i-1).marks],e,t);)i-=1,l-=n.parent.child(i).nodeSize;for(;a<n.parent.childCount&&Oc([...n.parent.child(a).marks],e,t);)d+=n.parent.child(a).nodeSize,a+=1;return{from:l,to:d}}function mt(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 vg=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const s=mt(n,o.schema),{doc:i,selection:l}=t,{$from:a,from:d,to:u}=l;if(r){const f=Os(a,s,e);if(f&&f.from<=d&&f.to>=u){const p=q.create(i,f.from,f.to);t.setSelection(p)}}return!0},Eg=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 Dc(n){return n instanceof q}function nn(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function Rc(n,e=null){if(!e)return null;const t=G.atStart(n),o=G.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,nn(0,r,s),nn(n.content.size,r,s)):q.create(n,nn(e,r,s),nn(e,r,s))}function _c(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function Wo(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}function Mg(){return typeof navigator<"u"?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var Tg=(n=null,e={})=>({editor:t,view:o,tr:r,dispatch:s})=>{e={scrollIntoView:!0,...e};const i=()=>{(Wo()||_c())&&o.dom.focus(),Mg()&&!Wo()&&!_c()&&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&&!Dc(t.state.selection))return i(),!0;const l=Rc(r.doc,n)||t.state.selection,a=t.state.selection.eq(l);return s&&(a||r.setSelection(l),a&&r.storedMarks&&r.setStoredMarks(r.storedMarks),i()),!0},Ng=(n,e)=>t=>n.every((o,r)=>e(o,{...t,index:r})),Bg=(n,e)=>({tr:t,commands:o})=>o.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),Pc=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&&Pc(o)}return n};function to(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 Pc(t)}function no(n,e,t){if(n instanceof ct||n instanceof B)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 B.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),no("",e,t)}if(r){if(t.errorOnInvalidContent){let i=!1,l="";const a=new xl({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?mn.fromSchema(a).parseSlice(to(n),t.parseOptions):mn.fromSchema(a).parse(to(n),t.parseOptions),t.errorOnInvalidContent&&i)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=mn.fromSchema(e);return t.slice?s.parseSlice(to(n),t.parseOptions).content:s.parse(to(n),t.parseOptions)}return no("",e,t)}function Ag(n,e,t){const o=n.steps.length-1;if(o<e)return;const r=n.steps[o];if(!(r instanceof he||r instanceof pe))return;const s=n.mapping.maps[o];let i=0;s.forEach((l,a,d,u)=>{i===0&&(i=u)}),n.setSelection(G.near(n.doc.resolve(i),t))}var Ig=n=>!("type"in n),Og=(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 a=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{no(e,s.schema,{parseOptions:d,errorOnInvalidContent:!0})}catch(y){a(y)}try{l=no(e,s.schema,{parseOptions:d,errorOnInvalidContent:(i=t.errorOnInvalidContent)!=null?i:s.options.enableContentCheck})}catch(y){return a(y),!1}let{from:u,to:f}=typeof n=="number"?{from:n,to:n}:{from:n.from,to:n.to},p=!0,h=!0;if((Ig(l)?l:[l]).forEach(y=>{y.check(),p=p?y.isText&&y.marks.length===0:!1,h=h?y.isBlock:!1}),u===f&&h){const{parent:y}=o.doc.resolve(u);y.isTextblock&&!y.type.spec.code&&!y.childCount&&(u-=1,f+=1)}let g;if(p){if(Array.isArray(e))g=e.map(y=>y.text||"").join("");else if(e instanceof B){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(),w=y.parentOffset===0,b=k.isText||k.isTextblock,S=k.content.size>0;w&&b&&S&&(u=Math.max(0,u-1)),o.replaceWith(u,f,g)}t.updateSelection&&Ag(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},Dg=()=>({state:n,dispatch:e})=>op(n,e),Rg=()=>({state:n,dispatch:e})=>rp(n,e),_g=()=>({state:n,dispatch:e})=>oa(n,e),Pg=()=>({state:n,dispatch:e})=>la(n,e),Vg=()=>({state:n,dispatch:e,tr:t})=>{try{const o=To(n.doc,n.selection.$from.pos,-1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},$g=()=>({state:n,dispatch:e,tr:t})=>{try{const o=To(n.doc,n.selection.$from.pos,1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},Lg=()=>({state:n,dispatch:e})=>tp(n,e),zg=()=>({state:n,dispatch:e})=>np(n,e);function Vc(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Fg(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 a=e[l];if(/^(cmd|meta|m)$/i.test(a))i=!0;else if(/^a(lt)?$/i.test(a))o=!0;else if(/^(c|ctrl|control)$/i.test(a))r=!0;else if(/^s(hift)?$/i.test(a))s=!0;else if(/^mod$/i.test(a))Wo()||Vc()?i=!0:r=!0;else throw new Error(`Unrecognized modifier name: ${a}`)}return o&&(t=`Alt-${t}`),r&&(t=`Ctrl-${t}`),i&&(t=`Meta-${t}`),s&&(t=`Shift-${t}`),t}var Hg=n=>({editor:e,view:t,tr:o,dispatch:r})=>{const s=Fg(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}),a=e.captureTransaction(()=>{t.someProp("handleKeyDown",d=>d(t,l))});return a==null||a.steps.forEach(d=>{const u=d.map(o.mapping);u&&r&&o.maybeStep(u)}),!0};function oo(n,e,t={}){const{from:o,to:r,empty:s}=n.selection,i=e?me(e,n.schema):null,l=[];n.doc.nodesBetween(o,r,(f,p)=>{if(f.isText)return;const h=Math.max(o,p),m=Math.min(r,p+f.nodeSize);l.push({node:f,from:h,to:m})});const a=r-o,d=l.filter(f=>i?i.name===f.node.type.name:!0).filter(f=>Ho(f.node.attrs,t,{strict:!1}));return s?!!d.length:d.reduce((f,p)=>f+p.to-p.from,0)>=a}var Wg=(n,e={})=>({state:t,dispatch:o})=>{const r=me(n,t.schema);return oo(t,r,e)?sp(t,o):!1},jg=()=>({state:n,dispatch:e})=>ua(n,e),Ug=n=>({state:e,dispatch:t})=>{const o=me(n,e.schema);return yp(o)(e,t)},Kg=()=>({state:n,dispatch:e})=>ca(n,e);function jo(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function $c(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 qg=(n,e)=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=jo(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=me(n,o.schema)),l==="mark"&&(i=mt(n,o.schema));let a=!1;return t.selection.ranges.forEach(d=>{o.doc.nodesBetween(d.$from.pos,d.$to.pos,(u,f)=>{s&&s===u.type&&(a=!0,r&&t.setNodeMarkup(f,void 0,$c(u.attrs,e))),i&&u.marks.length&&u.marks.forEach(p=>{i===p.type&&(a=!0,r&&t.addMark(f,f+u.nodeSize,i.create($c(p.attrs,e))))})})}),a},Jg=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),Gg=()=>({tr:n,dispatch:e})=>{if(e){const t=new Pe(n.doc);n.setSelection(t)}return!0},Yg=()=>({state:n,dispatch:e})=>sa(n,e),Xg=()=>({state:n,dispatch:e})=>aa(n,e),Zg=()=>({state:n,dispatch:e})=>cp(n,e),Qg=()=>({state:n,dispatch:e})=>fp(n,e),e0=()=>({state:n,dispatch:e})=>up(n,e);function Ds(n,e,t={},o={}){return no(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:o.errorOnInvalidContent})}var t0=(n,{errorOnInvalidContent:e,emitUpdate:t=!0,parseOptions:o={}}={})=>({editor:r,tr:s,dispatch:i,commands:l})=>{const{doc:a}=s;if(o.preserveWhitespace!=="full"){const d=Ds(n,r.schema,o,{errorOnInvalidContent:e??r.options.enableContentCheck});return i&&s.replaceWith(0,a.content.size,d).setMeta("preventUpdate",!t),!0}return i&&s.setMeta("preventUpdate",!t),l.insertContentAt({from:0,to:a.content.size},n,{parseOptions:o,errorOnInvalidContent:e??r.options.enableContentCheck})};function Lc(n,e){const t=mt(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,a=>{i.push(...a.marks)});const l=i.find(a=>a.type.name===t.name);return l?{...l.attrs}:{}}function n0(n,e){const t=new ql(n);return e.forEach(o=>{o.steps.forEach(r=>{t.step(r)})}),t}function o0(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 r0(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 Rs(n){return e=>r0(e.$from,n)}function V(n,e,t){return n.config[e]===void 0&&n.parent?V(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?V(n.parent,e,t):null}):n.config[e]}function _s(n){return n.map(e=>{const t={name:e.name,options:e.options,storage:e.storage},o=V(e,"addExtensions",t);return o?[e,..._s(o())]:e}).flat(10)}function Uo(n,e){const t=Kt.fromSchema(e).serializeFragment(n),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(t),r.innerHTML}function zc(n){return typeof n=="function"}function te(n,e=void 0,...t){return zc(n)?e?n.bind(e)(...t):n(...t):n}function s0(n={}){return Object.keys(n).length===0&&n.constructor===Object}function Nn(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 Fc(n){const e=[],{nodeExtensions:t,markExtensions:o}=Nn(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),a=[...i,...l];return n.forEach(d=>{const u={name:d.name,options:d.options,storage:d.storage,extensions:r},f=V(d,"addGlobalAttributes",u);if(!f)return;f().forEach(h=>{let m;Array.isArray(h.types)?m=h.types:h.types==="*"?m=a:h.types==="nodes"?m=i:h.types==="marks"?m=l:m=[],m.forEach(g=>{Object.entries(h.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=V(d,"addAttributes",u);if(!f)return;const p=f();Object.entries(p).forEach(([h,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:h,attribute:g})})}),e}function Bn(...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(" "):[],a=o[r]?o[r].split(" "):[],d=l.filter(u=>!a.includes(u));o[r]=[...a,...d].join(" ")}else if(r==="style"){const l=s?s.split(";").map(u=>u.trim()).filter(Boolean):[],a=o[r]?o[r].split(";").map(u=>u.trim()).filter(Boolean):[],d=new Map;a.forEach(u=>{const[f,p]=u.split(":").map(h=>h.trim());d.set(f,p)}),l.forEach(u=>{const[f,p]=u.split(":").map(h=>h.trim());d.set(f,p)}),o[r]=Array.from(d.entries()).map(([u,f])=>`${u}: ${f}`).join("; ")}else o[r]=s}),o},{})}function Ko(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)=>Bn(t,o),{})}function i0(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function Hc(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):i0(t.getAttribute(i.name));return l==null?s:{...s,[i.name]:l}},{});return{...o,...r}}}}function Wc(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&s0(t)?!1:t!=null))}function jc(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 Uc(n,e){var t;const o=Fc(n),{nodeExtensions:r,markExtensions:s}=Nn(n),i=(t=r.find(d=>V(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},p=n.reduce((k,w)=>{const b=V(w,"extendNodeSchema",f);return{...k,...b?b(d):{}}},{}),h=Wc({...p,content:te(V(d,"content",f)),marks:te(V(d,"marks",f)),group:te(V(d,"group",f)),inline:te(V(d,"inline",f)),atom:te(V(d,"atom",f)),selectable:te(V(d,"selectable",f)),draggable:te(V(d,"draggable",f)),code:te(V(d,"code",f)),whitespace:te(V(d,"whitespace",f)),linebreakReplacement:te(V(d,"linebreakReplacement",f)),defining:te(V(d,"defining",f)),isolating:te(V(d,"isolating",f)),attrs:Object.fromEntries(u.map(jc))}),m=te(V(d,"parseHTML",f));m&&(h.parseDOM=m.map(k=>Hc(k,u)));const g=V(d,"renderHTML",f);g&&(h.toDOM=k=>g({node:k,HTMLAttributes:Ko(k,u)}));const y=V(d,"renderText",f);return y&&(h.toText=y),[d.name,h]})),a=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},p=n.reduce((y,k)=>{const w=V(k,"extendMarkSchema",f);return{...y,...w?w(d):{}}},{}),h=Wc({...p,inclusive:te(V(d,"inclusive",f)),excludes:te(V(d,"excludes",f)),group:te(V(d,"group",f)),spanning:te(V(d,"spanning",f)),code:te(V(d,"code",f)),attrs:Object.fromEntries(u.map(jc))}),m=te(V(d,"parseHTML",f));m&&(h.parseDOM=m.map(y=>Hc(y,u)));const g=V(d,"renderHTML",f);return g&&(h.toDOM=y=>g({mark:y,HTMLAttributes:Ko(y,u)})),[d.name,h]}));return new xl({topNode:i,nodes:l,marks:a})}function l0(n){const e=n.filter((t,o)=>n.indexOf(t)!==o);return Array.from(new Set(e))}function ro(n){return n.sort((t,o)=>{const r=V(t,"priority")||100,s=V(o,"priority")||100;return r>s?-1:r<s?1:0})}function Ps(n){const e=ro(_s(n)),t=l0(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 Kc(n,e){const t=Ps(n);return Uc(t,e)}function qo(n,e){const t=Kc(e),o=ct.fromJSON(t,n);return Uo(o.content,t)}function Dt(n,e){const t=Kc(e),o=to(n);return mn.fromSchema(t).parse(o).toJSON()}function qc(n,e,t){const{from:o,to:r}=e,{blockSeparator:s=`
11
-
12
- `,textSerializers:i={}}=t||{};let l="";return n.nodesBetween(o,r,(a,d,u,f)=>{var p;a.isBlock&&d>o&&(l+=s);const h=i==null?void 0:i[a.type.name];if(h)return u&&(l+=h({node:a,pos:d,parent:u,index:f,range:e})),!1;a.isText&&(l+=(p=a==null?void 0:a.text)==null?void 0:p.slice(Math.max(o,d)-d,r-d))}),l}function a0(n,e){const t={from:0,to:n.content.size};return qc(n,t,e)}function Jc(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function c0(n,e){const t=me(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 d0(n,e){const t=jo(typeof e=="string"?e:e.name,n.schema);return t==="node"?c0(n,e):t==="mark"?Lc(n,e):{}}function u0(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 f0(n){const e=u0(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 h0(n){const{mapping:e,steps:t}=n,o=[];return e.maps.forEach((r,s)=>{const i=[];if(r.ranges.length)r.forEach((l,a)=>{i.push({from:l,to:a})});else{const{from:l,to:a}=t[s];if(l===void 0||a===void 0)return;i.push({from:l,to:a})}i.forEach(({from:l,to:a})=>{const d=e.slice(s).map(l,-1),u=e.slice(s).map(a),f=e.invert().map(d,-1),p=e.invert().map(u);o.push({oldRange:{from:f,to:p},newRange:{from:d,to:u}})})}),f0(o)}function Gc(n,e,t){const o=[];return n===e?t.resolve(n).marks().forEach(r=>{const s=t.resolve(n),i=Os(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 so(n,e){return e.nodes[n]||e.marks[n]||null}function Jo(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 p0=(n,e=500)=>{let t="";const o=n.parentOffset;return n.parent.nodesBetween(Math.max(0,o-e),o,(r,s,i,l)=>{var a,d;const u=((d=(a=r.type.spec).toText)==null?void 0:d.call(a,{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 Vs(n,e,t={}){const{empty:o,ranges:r}=n.selection,s=e?mt(e,n.schema):null;if(o)return!!(n.storedMarks||n.selection.$from.marks()).filter(f=>s?s.name===f.type.name:!0).find(f=>Ho(f.attrs,t,{strict:!1}));let i=0;const l=[];if(r.forEach(({$from:f,$to:p})=>{const h=f.pos,m=p.pos;n.doc.nodesBetween(h,m,(g,y)=>{if(s&&g.inlineContent&&!g.type.allowsMarkType(s))return!1;if(!g.isText&&!g.marks.length)return;const k=Math.max(h,y),w=Math.min(m,y+g.nodeSize),b=w-k;i+=b,l.push(...g.marks.map(S=>({mark:S,from:k,to:w})))})}),i===0)return!1;const a=l.filter(f=>s?s.name===f.mark.type.name:!0).filter(f=>Ho(f.mark.attrs,t,{strict:!1})).reduce((f,p)=>f+p.to-p.from,0),d=l.filter(f=>s?f.mark.type!==s&&f.mark.type.excludes(s):!0).reduce((f,p)=>f+p.to-p.from,0);return(a>0?a+d:a)>=i}function m0(n,e,t={}){if(!e)return oo(n,null,t)||Vs(n,null,t);const o=jo(e,n.schema);return o==="node"?oo(n,e,t):o==="mark"?Vs(n,e,t):!1}function Yc(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function Xc(n,e){const{nodeExtensions:t}=Nn(e),o=t.find(i=>i.name===n);if(!o)return!1;const r={name:o.name,options:o.options,storage:o.storage},s=te(V(o,"group",r));return typeof s!="string"?!1:s.split(" ").includes("list")}function Go(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&&(Go(s,{ignoreWhitespace:t,checkChildren:e})||(r=!1))}),r}return!1}function g0(n){return n instanceof F}var Zc=class tf{constructor(e){this.position=e}static fromJSON(e){return new tf(e.position)}toJSON(){return{position:this.position}}};function y0(n,e){const t=e.mapping.mapResult(n.position);return{position:new Zc(t.pos),mapResult:t}}function k0(n){return new Zc(n)}function w0(n,e,t){var o;const{selection:r}=e;let s=null;if(Dc(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:a})=>{let d=l.depth===0?n.doc.inlineContent&&n.doc.type.allowsMarkType(t):!1;return n.doc.nodesBetween(l.pos,a.pos,(u,f,p)=>{if(d)return!1;if(u.isInline){const h=!p||p.type.allowsMarkType(t),m=!!t.isInSet(u.marks)||!u.marks.some(g=>g.type.excludes(t));d=h&&m}return!d}),d})}var b0=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const{selection:s}=t,{empty:i,ranges:l}=s,a=mt(n,o.schema);if(r)if(i){const d=Lc(o,a);t.addStoredMark(a.create({...d,...e}))}else l.forEach(d=>{const u=d.$from.pos,f=d.$to.pos;o.doc.nodesBetween(u,f,(p,h)=>{const m=Math.max(h,u),g=Math.min(h+p.nodeSize,f);p.marks.find(k=>k.type===a)?p.marks.forEach(k=>{a===k.type&&t.addMark(m,g,a.create({...k.attrs,...e}))}):t.addMark(m,g,a.create(e))})});return w0(o,t,a)},x0=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),S0=(n,e={})=>({state:t,dispatch:o,chain:r})=>{const s=me(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})=>pa(s,{...i,...e})(t)?!0:l.clearNodes()).command(({state:l})=>pa(s,{...i,...e})(l,o)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},C0=n=>({tr:e,dispatch:t})=>{if(t){const{doc:o}=e,r=nn(n,0,o.content.size),s=F.create(o,r);e.setSelection(s)}return!0},v0=(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,(a,d)=>{a.isText||t.setNodeMarkup(d,void 0,{...a.attrs,dir:n})}),!0},E0=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,a=nn(r,i,l),d=nn(s,i,l),u=q.create(o,a,d);e.setSelection(u)}return!0},M0=n=>({state:e,dispatch:t})=>{const o=me(n,e.schema);return bp(o)(e,t)};function Qc(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 T0=({keepMarks:n=!0}={})=>({tr:e,state:t,dispatch:o,editor:r})=>{const{selection:s,doc:i}=e,{$from:l,$to:a}=s,d=r.extensionManager.attributes,u=Jo(d,l.node().type.name,l.node().attrs);if(s instanceof F&&s.node.isBlock)return!l.parentOffset||!dt(i,l.pos)?!1:(o&&(n&&Qc(t,r.extensionManager.splittableMarks),e.split(l.pos).scrollIntoView()),!0);if(!l.parent.isBlock)return!1;const f=a.parentOffset===a.parent.content.size,p=l.depth===0?void 0:o0(l.node(-1).contentMatchAt(l.indexAfter(-1)));let h=f&&p?[{type:p,attrs:u}]:void 0,m=dt(e.doc,e.mapping.map(l.pos),1,h);if(!h&&!m&&dt(e.doc,e.mapping.map(l.pos),1,p?[{type:p}]:void 0)&&(m=!0,h=p?[{type:p,attrs:u}]:void 0),o){if(m&&(s instanceof q&&e.deleteSelection(),e.split(e.mapping.map(l.pos),1,h),p&&!f&&!l.parentOffset&&l.parent.type!==p)){const g=e.mapping.map(l.before()),y=e.doc.resolve(g);l.node(-1).canReplaceWith(y.index(),y.index()+1,p)&&e.setNodeMarkup(e.mapping.map(l.before()),p)}n&&Qc(t,r.extensionManager.splittableMarks),e.scrollIntoView()}return m},N0=(n,e={})=>({tr:t,state:o,dispatch:r,editor:s})=>{var i;const l=me(n,o.schema),{$from:a,$to:d}=o.selection,u=o.selection.node;if(u&&u.isBlock||a.depth<2||!a.sameParent(d))return!1;const f=a.node(-1);if(f.type!==l)return!1;const p=s.extensionManager.attributes;if(a.parent.content.size===0&&a.node(-1).childCount===a.indexAfter(-1)){if(a.depth===2||a.node(-3).type!==l||a.index(-2)!==a.node(-2).childCount-1)return!1;if(r){let k=B.empty;const w=a.index(-1)?1:a.index(-2)?2:3;for(let E=a.depth-w;E>=a.depth-3;E-=1)k=B.from(a.node(E).copy(k));const b=a.indexAfter(-1)<a.node(-2).childCount?1:a.indexAfter(-2)<a.node(-3).childCount?2:3,S={...Jo(p,a.node().type.name,a.node().attrs),...e},C=((i=l.contentMatch.defaultType)==null?void 0:i.createAndFill(S))||void 0;k=k.append(B.from(l.createAndFill(null,C)||void 0));const M=a.before(a.depth-(w-1));t.replace(M,a.after(-b),new _(k,4-w,0));let v=-1;t.doc.nodesBetween(M,t.doc.content.size,(E,T)=>{if(v>-1)return!1;E.isTextblock&&E.content.size===0&&(v=T+1)}),v>-1&&t.setSelection(q.near(t.doc.resolve(v))),t.scrollIntoView()}return!0}const h=d.pos===a.end()?f.contentMatchAt(0).defaultType:null,m={...Jo(p,f.type.name,f.attrs),...e},g={...Jo(p,a.node().type.name,a.node().attrs),...e};t.delete(a.pos,d.pos);const y=h?[{type:l,attrs:m},{type:h,attrs:g}]:[{type:l,attrs:m}];if(!dt(t.doc,a.pos,2))return!1;if(r){const{selection:k,storedMarks:w}=o,{splittableMarks:b}=s.extensionManager,S=w||k.$to.parentOffset&&k.$from.marks();if(t.split(a.pos,2,y).scrollIntoView(),!S||!r)return!0;const C=S.filter(M=>b.includes(M.type.name));t.ensureMarks(C)}return!0},$s=(n,e)=>{const t=Rs(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)&&Jt(n.doc,t.pos)&&n.join(t.pos),!0},Ls=(n,e)=>{const t=Rs(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)&&Jt(n.doc,o)&&n.join(o),!0},B0=(n,e,t,o={})=>({editor:r,tr:s,state:i,dispatch:l,chain:a,commands:d,can:u})=>{const{extensions:f,splittableMarks:p}=r.extensionManager,h=me(n,i.schema),m=me(e,i.schema),{selection:g,storedMarks:y}=i,{$from:k,$to:w}=g,b=k.blockRange(w),S=y||g.$to.parentOffset&&g.$from.marks();if(!b)return!1;const C=Rs(M=>Xc(M.type.name,f))(g);if(b.depth>=1&&C&&b.depth-C.depth<=1){if(C.node.type===h)return d.liftListItem(m);if(Xc(C.node.type.name,f)&&h.validContent(C.node.content)&&l)return a().command(()=>(s.setNodeMarkup(C.pos,h),!0)).command(()=>$s(s,h)).command(()=>Ls(s,h)).run()}return!t||!S||!l?a().command(()=>u().wrapInList(h,o)?!0:d.clearNodes()).wrapInList(h,o).command(()=>$s(s,h)).command(()=>Ls(s,h)).run():a().command(()=>{const M=u().wrapInList(h,o),v=S.filter(E=>p.includes(E.type.name));return s.ensureMarks(v),M?!0:d.clearNodes()}).wrapInList(h,o).command(()=>$s(s,h)).command(()=>Ls(s,h)).run()},A0=(n,e={},t={})=>({state:o,commands:r})=>{const{extendEmptyMarkRange:s=!1}=t,i=mt(n,o.schema);return Vs(o,i,e)?r.unsetMark(i,{extendEmptyMarkRange:s}):r.setMark(i,e)},I0=(n,e,t={})=>({state:o,commands:r})=>{const s=me(n,o.schema),i=me(e,o.schema),l=oo(o,s,t);let a;return o.selection.$anchor.sameParent(o.selection.$head)&&(a=o.selection.$anchor.parent.attrs),l?r.setNode(i,a):r.setNode(s,{...a,...t})},O0=(n,e={})=>({state:t,commands:o})=>{const r=me(n,t.schema);return oo(t,r,e)?o.lift(r):o.wrapIn(r,e)},D0=()=>({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 a=l.steps.length-1;a>=0;a-=1)i.step(l.steps[a].invert(l.docs[a]));if(s.text){const a=i.doc.resolve(s.from).marks();i.replaceWith(s.from,s.to,n.schema.text(s.text,a))}else i.delete(s.from,s.to)}return!0}}return!1},R0=()=>({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},_0=(n,e={})=>({tr:t,state:o,dispatch:r})=>{var s;const{extendEmptyMarkRange:i=!1}=e,{selection:l}=t,a=mt(n,o.schema),{$from:d,empty:u,ranges:f}=l;if(!r)return!0;if(u&&i){let{from:p,to:h}=l;const m=(s=d.marks().find(y=>y.type===a))==null?void 0:s.attrs,g=Os(d,a,m);g&&(p=g.from,h=g.to),t.removeMark(p,h,a)}else f.forEach(p=>{t.removeMark(p.$from.pos,p.$to.pos,a)});return t.removeStoredMark(a),!0},P0=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,a)=>{if(l.isText)return;const d={...l.attrs};delete d.dir,e.setNodeMarkup(a,void 0,d)}),!0},V0=(n,e={})=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=jo(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=me(n,o.schema)),l==="mark"&&(i=mt(n,o.schema));let a=!1;return t.selection.ranges.forEach(d=>{const u=d.$from.pos,f=d.$to.pos;let p,h,m,g;t.selection.empty?o.doc.nodesBetween(u,f,(y,k)=>{s&&s===y.type&&(a=!0,m=Math.max(k,u),g=Math.min(k+y.nodeSize,f),p=k,h=y)}):o.doc.nodesBetween(u,f,(y,k)=>{k<u&&s&&s===y.type&&(a=!0,m=Math.max(k,u),g=Math.min(k+y.nodeSize,f),p=k,h=y),k>=u&&k<=f&&(s&&s===y.type&&(a=!0,r&&t.setNodeMarkup(k,void 0,{...y.attrs,...e})),i&&y.marks.length&&y.marks.forEach(w=>{if(i===w.type&&(a=!0,r)){const b=Math.max(k,u),S=Math.min(k+y.nodeSize,f);t.addMark(b,S,i.create({...w.attrs,...e}))}}))}),h&&(p!==void 0&&r&&t.setNodeMarkup(p,void 0,{...h.attrs,...e}),i&&h.marks.length&&h.marks.forEach(y=>{i===y.type&&r&&t.addMark(m,g,i.create({...y.attrs,...e}))}))}),a},$0=(n,e={})=>({state:t,dispatch:o})=>{const r=me(n,t.schema);return hp(r,e)(t,o)},L0=(n,e={})=>({state:t,dispatch:o})=>{const r=me(n,t.schema);return pp(r,e)(t,o)},z0=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={}}},F0=class{constructor(n){var e;this.find=n.find,this.handler=n.handler,this.undoable=(e=n.undoable)!=null?e:!0}},H0=(n,e)=>{if(Is(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 Yo(n){var e;const{editor:t,from:o,to:r,text:s,rules:i,plugin:l}=n,{view:a}=t;if(a.composing)return!1;const d=a.state.doc.resolve(o);if(d.parent.type.spec.code||(e=d.nodeBefore||d.nodeAfter)!=null&&e.marks.find(p=>p.type.spec.code))return!1;let u=!1;const f=p0(d)+s;return i.forEach(p=>{if(u)return;const h=H0(f,p.find);if(!h)return;const m=a.state.tr,g=zo({state:a.state,transaction:m}),y={from:o-(h[0].length-s.length),to:r},{commands:k,chain:w,can:b}=new Fo({editor:t,state:g});p.handler({state:g,range:y,match:h,commands:k,chain:w,can:b})===null||!m.steps.length||(p.undoable&&m.setMeta(l,{transform:m,from:o,to:r,text:s}),a.dispatch(m),u=!0)}),u}function W0(n){const{editor:e,rules:t}=n,o=new ue({state:{init(){return null},apply(r,s,i){const l=r.getMeta(o);if(l)return l;const a=r.getMeta("applyInputRules");return!!a&&setTimeout(()=>{let{text:u}=a;typeof u=="string"?u=u:u=Uo(B.from(u),i.schema);const{from:f}=a,p=f+u.length;Yo({editor:e,from:f,to:p,text:u,rules:t,plugin:o})}),r.selectionSet||r.docChanged?null:s}},props:{handleTextInput(r,s,i,l){return Yo({editor:e,from:s,to:i,text:l,rules:t,plugin:o})},handleDOMEvents:{compositionend:r=>(setTimeout(()=>{const{$cursor:s}=r.state.selection;s&&Yo({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?Yo({editor:e,from:i.pos,to:i.pos,text:`
13
- `,rules:t,plugin:o}):!1}},isInputRules:!0});return o}function j0(n){return Object.prototype.toString.call(n).slice(8,-1)}function Xo(n){return j0(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function ed(n,e){const t={...n};return Xo(n)&&Xo(e)&&Object.keys(e).forEach(o=>{Xo(e[o])&&Xo(n[o])?t[o]=ed(n[o],e[o]):t[o]=e[o]}),t}var zs=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{...te(V(this,"addOptions",{name:this.name}))||{}}}get storage(){return{...te(V(this,"addStorage",{name:this.name,options:this.options}))||{}}}configure(n={}){const e=this.extend({...this.config,addOptions:()=>ed(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 nf extends zs{constructor(){super(...arguments),this.type="mark"}static create(e={}){const t=typeof e=="function"?e():e;return new nf(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 a=i.find(d=>(d==null?void 0:d.type.name)===t.name);return a&&o.removeStoredMark(a),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 U0(n){return typeof n=="number"}var K0=class{constructor(n){this.find=n.find,this.handler=n.handler}},q0=(n,e,t)=>{if(Is(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 J0(n){const{editor:e,state:t,from:o,to:r,rule:s,pasteEvent:i,dropEvent:l}=n,{commands:a,chain:d,can:u}=new Fo({editor:e,state:t}),f=[];return t.doc.nodesBetween(o,r,(h,m)=>{var g,y,k,w,b;if((y=(g=h.type)==null?void 0:g.spec)!=null&&y.code||!(h.isText||h.isTextblock||h.isInline))return;const S=(b=(w=(k=h.content)==null?void 0:k.size)!=null?w:h.nodeSize)!=null?b:0,C=Math.max(o,m),M=Math.min(r,m+S);if(C>=M)return;const v=h.isText?h.text||"":h.textBetween(C-m,M-m,void 0,"");q0(v,s.find,i).forEach(T=>{if(T.index===void 0)return;const A=C+T.index+1,R=A+T[0].length,$={from:t.tr.mapping.map(A),to:t.tr.mapping.map(R)},z=s.handler({state:t,range:$,match:T,commands:a,chain:d,can:u,pasteEvent:i,dropEvent:l});f.push(z)})}),f.every(h=>h!==null)}var Zo=null,G0=n=>{var e;const t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)==null||e.setData("text/html",n),t};function Y0(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 a=({state:u,from:f,to:p,rule:h,pasteEvt:m})=>{const g=u.tr,y=zo({state:u,transaction:g});if(!(!J0({editor:e,state:y,from:Math.max(f-1,0),to:p.b-1,rule:h,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 ue({view(f){const p=m=>{var g;o=(g=f.dom.parentElement)!=null&&g.contains(m.target)?f.dom.parentElement:null,o&&(Zo=e)},h=()=>{Zo&&(Zo=null)};return window.addEventListener("dragstart",p),window.addEventListener("dragend",h),{destroy(){window.removeEventListener("dragstart",p),window.removeEventListener("dragend",h)}}},props:{handleDOMEvents:{drop:(f,p)=>{if(s=o===f.dom.parentElement,l=p,!s){const h=Zo;h!=null&&h.isEditable&&setTimeout(()=>{const m=h.state.selection;m&&h.commands.deleteRange({from:m.from,to:m.to})},10)}return!1},paste:(f,p)=>{var h;const m=(h=p.clipboardData)==null?void 0:h.getData("text/html");return i=p,r=!!(m!=null&&m.includes("data-pm-slice")),!1}}},appendTransaction:(f,p,h)=>{const m=f[0],g=m.getMeta("uiEvent")==="paste"&&!r,y=m.getMeta("uiEvent")==="drop"&&!s,k=m.getMeta("applyPasteRules"),w=!!k;if(!g&&!y&&!w)return;if(w){let{text:C}=k;typeof C=="string"?C=C:C=Uo(B.from(C),h.schema);const{from:M}=k,v=M+C.length,E=G0(C);return a({rule:u,state:h,from:M,to:{b:v},pasteEvt:E})}const b=p.doc.content.findDiffStart(h.doc.content),S=p.doc.content.findDiffEnd(h.doc.content);if(!(!U0(b)||!S||b===S.b))return a({rule:u,state:h,from:b,to:S,pasteEvt:i})}}))}var Qo=class{constructor(n,e){this.splittableMarks=[],this.editor=e,this.baseExtensions=n,this.extensions=Ps(n),this.schema=Uc(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:so(e.name,this.schema)},o=V(e,"addCommands",t);return o?{...n,...o()}:n},{})}get plugins(){const{editor:n}=this;return ro([...this.extensions].reverse()).flatMap(o=>{const r={name:o.name,options:o.options,storage:this.editor.extensionStorage[o.name],editor:n,type:so(o.name,this.schema)},s=[],i=V(o,"addKeyboardShortcuts",r);let l={};if(o.type==="mark"&&V(o,"exitable",r)&&(l.ArrowRight=()=>io.handleExit({editor:n,mark:o})),i){const p=Object.fromEntries(Object.entries(i()).map(([h,m])=>[h,()=>m({editor:n})]));l={...l,...p}}const a=dg(l);s.push(a);const d=V(o,"addInputRules",r);if(Yc(o,n.options.enableInputRules)&&d){const p=d();if(p&&p.length){const h=W0({editor:n,rules:p}),m=Array.isArray(h)?h:[h];s.push(...m)}}const u=V(o,"addPasteRules",r);if(Yc(o,n.options.enablePasteRules)&&u){const p=u();if(p&&p.length){const h=Y0({editor:n,rules:p});s.push(...h)}}const f=V(o,"addProseMirrorPlugins",r);if(f){const p=f();s.push(...p)}return s})}get attributes(){return Fc(this.extensions)}get nodeViews(){const{editor:n}=this,{nodeExtensions:e}=Nn(this.extensions);return Object.fromEntries(e.filter(t=>!!V(t,"addNodeView")).map(t=>{const o=this.attributes.filter(a=>a.type===t.name),r={name:t.name,options:t.options,storage:this.editor.extensionStorage[t.name],editor:n,type:me(t.name,this.schema)},s=V(t,"addNodeView",r);if(!s)return[];const i=s();if(!i)return[];const l=(a,d,u,f,p)=>{const h=Ko(a,o);return i({node:a,view:d,getPos:u,decorations:f,innerDecorations:p,editor:n,extension:t,HTMLAttributes:h})};return[t.name,l]}))}dispatchTransaction(n){const{editor:e}=this;return ro([...this.extensions].reverse()).reduceRight((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:so(r.name,this.schema)},i=V(r,"dispatchTransaction",s);return i?l=>{i.call(s,{transaction:l,next:o})}:o},n)}transformPastedHTML(n){const{editor:e}=this;return ro([...this.extensions]).reduce((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:so(r.name,this.schema)},i=V(r,"transformPastedHTML",s);return i?(l,a)=>{const d=o(l,a);return i.call(s,d)}:o},n||(o=>o))}get markViews(){const{editor:n}=this,{markExtensions:e}=Nn(this.extensions);return Object.fromEntries(e.filter(t=>!!V(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:mt(t.name,this.schema)},s=V(t,"addMarkView",r);if(!s)return[];const i=(l,a,d)=>{const u=Ko(l,o);return s()({mark:l,view:a,inline:d,editor:n,extension:t,HTMLAttributes:u,updateAttributes:f=>{dy(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:so(e.name,this.schema)};e.type==="mark"&&((t=te(V(e,"keepOnSplit",o)))==null||t)&&this.splittableMarks.push(e.name);const r=V(e,"onBeforeCreate",o),s=V(e,"onCreate",o),i=V(e,"onUpdate",o),l=V(e,"onSelectionUpdate",o),a=V(e,"onTransaction",o),d=V(e,"onFocus",o),u=V(e,"onBlur",o),f=V(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),a&&this.editor.on("transaction",a),d&&this.editor.on("focus",d),u&&this.editor.on("blur",u),f&&this.editor.on("destroy",f)})}};Qo.resolve=Ps,Qo.sort=ro,Qo.flatten=_s;var X0={};As(X0,{ClipboardTextSerializer:()=>td,Commands:()=>nd,Delete:()=>od,Drop:()=>rd,Editable:()=>sd,FocusEvents:()=>ld,Keymap:()=>ad,Paste:()=>cd,Tabindex:()=>dd,TextDirection:()=>ud,focusEventsPluginKey:()=>id});var ne=class of extends zs{constructor(){super(...arguments),this.type="extension"}static create(e={}){const t=typeof e=="function"?e():e;return new of(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}},td=ne.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new ue({key:new Te("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)),a=Jc(t);return qc(o,{from:i,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:a})}}})]}}),nd=ne.create({name:"commands",addCommands(){return{...Ac}}}),od=ne.create({name:"delete",onUpdate({transaction:n,appendedTransactions:e}){var t,o,r;const s=()=>{var i,l,a,d;if((d=(a=(l=(i=this.editor.options.coreExtensionOptions)==null?void 0:i.delete)==null?void 0:l.filterTransaction)==null?void 0:a.call(l,n))!=null?d:n.getMeta("y-sync$"))return;const u=n0(n.before,[n,...e]);h0(u).forEach(h=>{u.mapping.mapResult(h.oldRange.from).deletedAfter&&u.mapping.mapResult(h.oldRange.to).deletedBefore&&u.before.nodesBetween(h.oldRange.from,h.oldRange.to,(m,g)=>{const y=g+m.nodeSize-2,k=h.oldRange.from<=g&&y<=h.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:h.oldRange,newRange:h.newRange,partial:!k,editor:this.editor,transaction:n,combinedTransform:u})})});const p=u.mapping;u.steps.forEach((h,m)=>{var g,y;if(h instanceof Ke){const k=p.slice(m).map(h.from,-1),w=p.slice(m).map(h.to),b=p.invert().map(k,-1),S=p.invert().map(w),C=(g=u.doc.nodeAt(k-1))==null?void 0:g.marks.some(v=>v.eq(h.mark)),M=(y=u.doc.nodeAt(w))==null?void 0:y.marks.some(v=>v.eq(h.mark));this.editor.emit("delete",{type:"mark",mark:h.mark,from:h.from,to:h.to,deletedRange:{from:b,to:S},newRange:{from:k,to:w},partial:!!(M||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()}}),rd=ne.create({name:"drop",addProseMirrorPlugins(){return[new ue({key:new Te("tiptapDrop"),props:{handleDrop:(n,e,t,o)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:o})}}})]}}),sd=ne.create({name:"editable",addProseMirrorPlugins(){return[new ue({key:new Te("editable"),props:{editable:()=>this.editor.options.editable}})]}}),id=new Te("focusEvents"),ld=ne.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new ue({key:id,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}}}})]}}),ad=ne.create({name:"keymap",addKeyboardShortcuts(){const n=()=>this.editor.commands.first(({commands:i})=>[()=>i.undoInputRule(),()=>i.command(({tr:l})=>{const{selection:a,doc:d}=l,{empty:u,$anchor:f}=a,{pos:p,parent:h}=f,m=f.parent.isTextblock&&p>0?l.doc.resolve(p-1):f,g=m.parent.type.spec.isolating,y=f.pos-f.parentOffset,k=g&&m.parent.childCount===1?y===f.pos:G.atStart(d).from===p;return!u||!h.type.isTextblock||h.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 Wo()||Vc()?s:r},addProseMirrorPlugins(){return[new ue({key:new Te("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,a=G.atStart(e.doc).from,d=G.atEnd(e.doc).to;if(s||!(i===a&&l===d)||!Go(t.doc))return;const p=t.tr,h=zo({state:t,transaction:p}),{commands:m}=new Fo({editor:this.editor,state:h});if(m.clearNodes(),!!p.steps.length)return p}})]}}),cd=ne.create({name:"paste",addProseMirrorPlugins(){return[new ue({key:new Te("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),dd=ne.create({name:"tabindex",addProseMirrorPlugins(){return[new ue({key:new Te("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}}),ud=ne.create({name:"textDirection",addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];const{nodeExtensions:n}=Nn(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 ue({key:new Te("textDirection"),props:{attributes:()=>{const n=this.options.direction;return n?{dir:n}:{}}}})]}}),Z0=class po{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 po(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 po(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 po(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 a=this.resolvedPos.doc.resolve(l);if(!r&&!i&&a.depth<=this.depth)return;const d=new po(a,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 a=i[l];if(s[a]!==t[a])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(a=>t[a]===i.node.attrs[a])&&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)}},Q0=`.ProseMirror {
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-selection"),require("@woven-canvas/plugin-canvas-controls")):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-selection","@woven-canvas/plugin-canvas-controls"],Ve):(_=typeof globalThis<"u"?globalThis:_||self,Ve(_.Vue={},_.WovenEcsCanvasStore,_.WovenCanvasPluginArrows,_.Vue,_.WovenCanvasCore,_.WovenCanvasMath,_.WovenCanvasPluginEraser,_.WovenCanvasPluginPen,_.WovenCanvasPluginSelection,_.WovenCanvasPluginCanvasControls))})(this,function(_,Ve,ee,a,w,Ie,ur,fr,ne,ai){"use strict";const ci=[{kind:ee.ArrowHeadKind.None,label:"None",gap:0,svg:""},{kind:ee.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:ee.ArrowHeadKind.Delta,label:"Triangle",gap:20,svg:'<polygon points="-1,0 -12,-7 -12,7" fill="currentColor" />'},{kind:ee.ArrowHeadKind.Circle,label:"Circle",gap:0,svg:'<circle cx="-6" cy="0" r="6" fill="currentColor" />'},{kind:ee.ArrowHeadKind.Diamond,label:"Diamond",gap:0,svg:'<polygon points="0,0 -7,-6 -14,0 -7,6" fill="currentColor" />'}];function Fn(n){return ci.find(e=>e.kind===n)}const oc=Symbol.for("__woven_canvas_dropdown_active__"),rc=Symbol.for("__woven_canvas_dropdown_level__"),sc=Symbol.for("__woven_canvas_floating_menu__"),di=Symbol.for("__woven_canvas_toolbar__"),ic=Symbol.for("__woven_canvas_tooltip__"),je=Symbol.for("__woven_canvas__");function pe(n,e){const t=a.inject(je);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 Wm={key:0},Km=["x1","y1","x2","y2","stroke","stroke-width"],qm=["x1","y1","x2","y2","stroke","stroke-width"],Gm=["points","fill"],Jm=["cx","cy","r","fill"],Ym=["points","fill"],Xm=15,Qm=2,xt=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/Qm)**.33,d=Xm*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",Wm,[n.kind===a.unref(ee.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,Km),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,qm)],64)):n.kind===a.unref(ee.ArrowHeadKind).Delta&&r.value?(a.openBlock(),a.createElementBlock("polygon",{key:1,points:r.value,fill:n.color},null,8,Gm)):n.kind===a.unref(ee.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,Jm)):n.kind===a.unref(ee.ArrowHeadKind).Diamond&&i.value?(a.openBlock(),a.createElementBlock("polygon",{key:3,points:i.value,fill:n.color},null,8,Ym)):a.createCommentVNode("",!0)])):a.createCommentVNode("",!0)}}),Zm={class:"arrow-svg",preserveAspectRatio:"none"},eg=["d","stroke","stroke-width"],tg=["x1","y1","x2","y2","stroke","stroke-width"],ng=["d"],og=["x1","y1","x2","y2"],rg=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=pe(e.entityId,w.Color),i=pe(e.entityId,ee.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 S=s.value.red.toString(16).padStart(2,"0"),x=s.value.green.toString(16).padStart(2,"0"),C=s.value.blue.toString(16).padStart(2,"0");return`#${S}${x}${C}`}),d=a.computed(()=>{var S;return((S=i.value)==null?void 0:S.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 S=i.value.value,x=Ie.Arc.create(S[0],S[1],S[2],S[3],S[4],S[5],S[6]);return!Ie.Arc.isCollinear(x)}),p=a.computed(()=>{if(!i.value)return null;const S=i.value.value,x=o.value,C=r.value;return Ie.Arc.create(S[0]*x,S[1]*C,S[2]*x,S[3]*C,S[4]*x,S[5]*C,S[6])}),m=a.computed(()=>!p.value||!h.value?null:Ie.Arc.compute(p.value)),g=a.computed(()=>{var z,W,G,K;if(!i.value||!p.value)return null;const S=p.value,x=i.value.startArrowHead,C=i.value.endArrowHead,T=Ie.Arc.length(S);let E=i.value.trimStart;if((z=e.connector)!=null&&z.startBlock&&x!=="none"){const j=((W=Fn(x))==null?void 0:W.gap)??0,F=T>0?j/T:0;E+=F}let M=i.value.trimEnd;if((G=e.connector)!=null&&G.endBlock&&C!=="none"){const j=((K=Fn(C))==null?void 0:K.gap)??0,F=T>0?j/T:0;M+=F}const v=1-M,B=Ie.Arc.parametricToPoint(S,E),I=Ie.Arc.parametricToPoint(S,v),P=b(Ie.Arc.directionAt(S,E)),V=Ie.Arc.directionAt(S,v);return{start:B,end:I,startDir:P,endDir:V,tStart:E,tEnd:v,startHead:x,endHead:C}}),y=a.computed(()=>{if(!g.value||!m.value||!h.value)return"";const{start:S,end:x,tStart:C,tEnd:T}=g.value,{radius:E,clockwise:M,arcAngle:v}=m.value,I=v*(T-C)>Math.PI?1:0,P=M?0:1;return`M ${S[0]} ${S[1]} A ${E} ${E} 0 ${I} ${P} ${x[0]} ${x[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 b(S){return[-S[0],-S[1]]}return(S,x)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-arc-arrow"},[(a.openBlock(),a.createElementBlock("svg",Zm,[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,eg)):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,tg)):a.createCommentVNode("",!0),g.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:2},[g.value.startHead!=="none"?(a.openBlock(),a.createBlock(xt,{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(xt,{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,ng)):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,og)):a.createCommentVNode("",!0),g.value.startHead!=="none"?(a.openBlock(),a.createBlock(xt,{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(xt,{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))}}),fn=(n,e)=>{const t=n.__vccOpts||n;for(const[o,r]of e)t[o]=r;return t},lc=fn(rg,[["__scopeId","data-v-bcf5b4f3"]]),sg={},ig={class:"wov-arrow-handle"};function lg(n,e){return a.openBlock(),a.createElementBlock("div",ig,[...e[0]||(e[0]=[a.createElementVNode("div",{class:"wov-arrow-handle-inner"},null,-1)])])}const ac=fn(sg,[["render",lg]]),ag={},cg={class:"wov-arrow-terminal"};function dg(n,e){return a.openBlock(),a.createElementBlock("div",cg,[...e[0]||(e[0]=[a.createElementVNode("div",{class:"wov-arrow-terminal-ring"},[a.createElementVNode("div",{class:"wov-arrow-terminal-fill"})],-1)])])}const cc=fn(ag,[["render",dg]]),ug={class:"arrow-svg",preserveAspectRatio:"none"},fg=["x1","y1","x2","y2"],hg=["x1","y1","x2","y2","stroke","stroke-width"],pg=["x1","y1","x2","y2"],dc=fn(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=pe(e.entityId,w.Color),i=pe(e.entityId,ee.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,b=[];for(let S=0;S<g.pointCount;S++){const x=g.points[S*2]*y,C=g.points[S*2+1]*k;b.push([x,C])}return b}),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 v,B,I,P;if(!i.value||h.value.length<2)return null;const g=i.value,y=[...h.value.map(V=>[...V])],k=g.startArrowHead,b=g.endArrowHead,S=[y[1][0]-y[0][0],y[1][1]-y[0][1]],x=[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((v=e.connector)!=null&&v.startBlock&&k!=="none"){const V=Math.hypot(S[0],S[1]),z=((B=Fn(k))==null?void 0:B.gap)??0,W=V>0?z/V:0;C+=W}let T=g.trimEnd;if((I=e.connector)!=null&&I.endBlock&&b!=="none"){const V=Math.hypot(x[0],x[1]),z=((P=Fn(b))==null?void 0:P.gap)??0,W=V>0?z/V:0;T+=W}y[0]=[y[0][0]+(y[1][0]-y[0][0])*C,y[0][1]+(y[1][1]-y[0][1])*C];const E=y.length-1;y[E]=[y[E-1][0]+(y[E][0]-y[E-1][0])*(1-T),y[E-1][1]+(y[E][1]-y[E-1][1])*(1-T)];const M=[];for(let V=0;V<y.length-1;V++)M.push({start:y[V],end:y[V+1]});return Ie.Vec2.scale(S,-1),{points:y,lines:M,startPos:y[0],endPos:y[y.length-1],startDir:S,endDir:x,startHead:k,endHead:b}});return(g,y)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-elbow-arrow"},[(a.openBlock(),a.createElementBlock("svg",ug,[l.value&&p.value.length>0?(a.openBlock(!0),a.createElementBlock(a.Fragment,{key:0},a.renderList(p.value,(k,b)=>(a.openBlock(),a.createElementBlock("line",{key:"bg-"+b,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,fg))),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,b)=>(a.openBlock(),a.createElementBlock("line",{key:b,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,hg))),128)),m.value.startHead!=="none"?(a.openBlock(),a.createBlock(xt,{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(xt,{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,b)=>(a.openBlock(),a.createElementBlock("line",{key:"hl-"+b,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,pg))),128)),m.value.startHead!=="none"?(a.openBlock(),a.createBlock(xt,{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(xt,{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-b2719db1"]]),mg={class:"wov-embed-block"},gg={key:0,class:"wov-embed-placeholder"},yg=["src","allow"],uc=a.defineComponent({__name:"EmbedBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const t=pe(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",mg,[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,yg)):(a.openBlock(),a.createElementBlock("div",gg,[a.createElementVNode("span",null,a.toDisplayString(s.value),1)]))]))}}),{PI:kg}=Math,wo=kg+1e-4,fc=.5,hc=[1,1];function pc(n,e,t,o=r=>r){return n*o(.5-e*(.5-t))}const{min:ui}=Math;function mc(n,e,t){let o=ui(1,e/t);return ui(1,n+(ui(1,1-o)-n)*(o*.275))}function wg(n){return[-n[0],-n[1]]}function ut(n,e){return[n[0]+e[0],n[1]+e[1]]}function gc(n,e,t){return n[0]=e[0]+t[0],n[1]=e[1]+t[1],n}function Lt(n,e){return[n[0]-e[0],n[1]-e[1]]}function fi(n,e,t){return n[0]=e[0]-t[0],n[1]=e[1]-t[1],n}function Vt(n,e){return[n[0]*e,n[1]*e]}function hi(n,e,t){return n[0]=e[0]*t,n[1]=e[1]*t,n}function bg(n,e){return[n[0]/e,n[1]/e]}function yc(n){return[n[1],-n[0]]}function pi(n,e){let t=e[0];return n[0]=e[1],n[1]=-t,n}function kc(n,e){return n[0]*e[0]+n[1]*e[1]}function Sg(n,e){return n[0]===e[0]&&n[1]===e[1]}function xg(n){return Math.hypot(n[0],n[1])}function wc(n,e){let t=n[0]-e[0],o=n[1]-e[1];return t*t+o*o}function bc(n){return bg(n,xg(n))}function Cg(n,e){return Math.hypot(n[1]-e[1],n[0]-e[0])}function mi(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 Sc(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 xc(n,e,t){return ut(n,Vt(Lt(e,n),t))}function Eg(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 Cc(n,e,t){return ut(n,Vt(e,t))}const xe=[0,0],$t=[0,0],zt=[0,0];function vg(n,e){let t=Cc(n,bc(yc(Lt(n,ut(n,[1,1])))),-e),o=[],r=1/13;for(let s=r;s<=1;s+=r)o.push(mi(t,n,wo*2*s));return o}function Tg(n,e,t){let o=[],r=1/t;for(let s=r;s<=1;s+=r)o.push(mi(e,n,wo*s));return o}function Mg(n,e,t){let o=Lt(e,t),r=Vt(o,.5),s=Vt(o,.51);return[Lt(n,r),Lt(n,s),ut(n,s),ut(n,r)]}function Ag(n,e,t,o){let r=[],s=Cc(n,e,t),i=1/o;for(let l=i;l<1;l+=i)r.push(mi(s,n,wo*3*l));return r}function Ng(n,e,t){return[ut(n,Vt(e,t)),ut(n,Vt(e,t*.99)),Lt(n,Vt(e,t*.99)),Lt(n,Vt(e,t))]}function Ec(n,e,t){return n===!1||n===void 0?0:n===!0?Math.max(e,t):n}function Bg(n,e,t){return n.slice(0,10).reduce((o,r)=>{let s=r.pressure;return e&&(s=mc(o,r.distance,t)),(o+s)/2},n[0].pressure)}function Ig(n,e={}){let{size:t=16,smoothing:o=.5,thinning:r=.5,simulatePressure:s=!0,easing:i=K=>K,start:l={},end:c={},last:d=!1}=e,{cap:u=!0,easing:f=K=>K*(2-K)}=l,{cap:h=!0,easing:p=K=>--K*K*K+1}=c;if(n.length===0||t<=0)return[];let m=n[n.length-1].runningLength,g=Ec(l.taper,t,m),y=Ec(c.taper,t,m),k=(t*o)**2,b=[],S=[],x=Bg(n,s,t),C=pc(t,r,n[n.length-1].pressure,i),T,E=n[0].vector,M=n[0].point,v=M,B=M,I=v,P=!1;for(let K=0;K<n.length;K++){let{pressure:j}=n[K],{point:F,vector:X,distance:re,runningLength:le}=n[K],Be=K===n.length-1;if(!Be&&m-le<3)continue;r?(s&&(j=mc(x,re,t)),C=pc(t,r,j,i)):C=t/2,T===void 0&&(T=C);let ce=le<g?f(le/g):1,He=m-le<y?p((m-le)/y):1;C=Math.max(.01,C*Math.min(ce,He));let $n=(Be?n[K]:n[K+1]).vector,dn=Be?1:kc(X,$n),cr=kc(X,E)<0&&!P,zn=dn!==null&&dn<0;if(cr||zn){pi(xe,E),hi(xe,xe,C);for(let Dt=0;Dt<=1;Dt+=.07692307692307693)fi($t,F,xe),Sc($t,$t,F,wo*Dt),B=[$t[0],$t[1]],b.push(B),gc(zt,F,xe),Sc(zt,zt,F,wo*-Dt),I=[zt[0],zt[1]],S.push(I);M=B,v=I,zn&&(P=!0);continue}if(P=!1,Be){pi(xe,X),hi(xe,xe,C),b.push(Lt(F,xe)),S.push(ut(F,xe));continue}Eg(xe,$n,X,dn),pi(xe,xe),hi(xe,xe,C),fi($t,F,xe),B=[$t[0],$t[1]],(K<=1||wc(M,B)>k)&&(b.push(B),M=B),gc(zt,F,xe),I=[zt[0],zt[1]],(K<=1||wc(v,I)>k)&&(S.push(I),v=I),x=j,E=X}let V=[n[0].point[0],n[0].point[1]],z=n.length>1?[n[n.length-1].point[0],n[n.length-1].point[1]]:ut(n[0].point,[1,1]),W=[],G=[];if(n.length===1){if(!(g||y)||d)return vg(V,T||C)}else{g||y&&n.length===1||(u?W.push(...Tg(V,S[0],13)):W.push(...Mg(V,b[0],S[0])));let K=yc(wg(n[n.length-1].vector));y||g&&n.length===1?G.push(z):h?G.push(...Ag(z,K,C,29)):G.push(...Ng(z,K,C))}return b.concat(G,S.reverse(),W)}const vc=[0,0];function Tc(n){return n!=null&&n>=0}function Og(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=fc})=>[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(xc(i[0],p,m/4))}i.length===1&&(i=[...i,[...ut(i[0],hc),...i[0].slice(2)]]);let l=[{point:[i[0][0],i[0][1]],pressure:Tc(i[0][2])?i[0][2]:.25,vector:[...hc],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]]:xc(u.point,i[p],s);if(Sg(u.point,m))continue;let g=Cg(m,u.point);if(d+=g,p<f&&!c){if(d<o)continue;c=!0}fi(vc,u.point,m),u={point:m,pressure:Tc(i[p][2])?i[p][2]:fc,vector:bc(vc),distance:g,runningLength:d},l.push(u)}return l[0].vector=((h=l[1])==null?void 0:h.vector)||[0,0],l}function gi(n,e={}){return Ig(Og(n,e),e)}const _g={class:"wov-eraser-stroke"},Rg={preserveAspectRatio:"none"},Pg=["d"],Dg="#88888833",Mc=a.defineComponent({__name:"Eraser",props:{entityId:{}},setup(n){const e=n,t=pe(e.entityId,ur.EraserStroke),o=pe(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,ur.POINTS_CAPACITY);for(let x=0;x<m;x++){const C=(c+x)%ur.POINTS_CAPACITY*2;p.push([d[C]-f,d[C+1]-h])}const g=gi(p,{size:u,start:{taper:66,cap:!0}});if(g.length<3)return"";let y=g[0],k=g[1];const b=g[2];let S=`M${y[0].toFixed(2)},${y[1].toFixed(2)} Q${k[0].toFixed(2)},${k[1].toFixed(2)} ${s(k[0],b[0]).toFixed(2)},${s(k[1],b[1]).toFixed(2)} T`;for(let x=2;x<g.length-1;x++)y=g[x],k=g[x+1],S+=`${s(y[0],k[0]).toFixed(2)},${s(y[1],k[1]).toFixed(2)} `;return S+=`${k[0].toFixed(2)},${k[1].toFixed(2)} `,S+="Z",S}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",_g,[(a.openBlock(),a.createElementBlock("svg",Rg,[a.createElementVNode("path",{d:r.value,fill:Dg},null,8,Pg)]))]))}}),Lg={class:"wov-image-block"},Vg={key:0,class:"wov-image-placeholder"},$g={key:1,class:"wov-image-placeholder wov-image-error"},zg=["src","alt"],Fg={key:3,class:"wov-image-upload-overlay"},Hg={class:"wov-image-upload-status"},Ac=a.defineComponent({__name:"ImageBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=a.inject(je);if(!t)throw new Error("ImageBlock must be used within a WovenCanvas component");const o=t,r=pe(e.entityId,w.Asset),s=pe(e.entityId,w.Image),i=a.ref(null),l=a.ref(!0),c=a.ref(!1);let d=!0;a.onUnmounted(()=>{d=!1});async function u(){const p=o.getAssetManager();if(!p){l.value=!1,c.value=!0;return}const m=r.value;if(!m){l.value=!1;return}try{l.value=!0,c.value=!1;const g=await p.getDisplayUrl(m.identifier);if(!d)return;g?(i.value=g,l.value=!1):m.uploadState===w.UploadState.Failed&&(c.value=!0,l.value=!1)}catch(g){if(!d)return;console.error("Failed to get display URL:",g),c.value=!0,l.value=!1}}a.watch(()=>r.value,()=>{u()},{immediate:!0}),a.onMounted(()=>{u()});const f=a.computed(()=>{const p=r.value;if(!p)return null;switch(p.uploadState){case w.UploadState.Pending:return"Loading...";case w.UploadState.Uploading:return"Loading...";case w.UploadState.Failed:return"Failed";default:return null}}),h=a.computed(()=>({width:"100%",height:"100%",objectFit:"fill"}));return(p,m)=>{var g;return a.openBlock(),a.createElementBlock("div",Lg,[l.value&&!i.value?(a.openBlock(),a.createElementBlock("div",Vg,[...m[0]||(m[0]=[a.createElementVNode("span",null,"Loading...",-1)])])):c.value?(a.openBlock(),a.createElementBlock("div",$g,[...m[1]||(m[1]=[a.createElementVNode("span",null,"Failed to load image",-1)])])):i.value?(a.openBlock(),a.createElementBlock("img",{key:2,src:i.value,alt:((g=a.unref(s))==null?void 0:g.alt)||"",style:a.normalizeStyle(h.value),draggable:"false"},null,12,zg)):a.createCommentVNode("",!0),f.value?(a.openBlock(),a.createElementBlock("div",Fg,[a.createElementVNode("span",Hg,a.toDisplayString(f.value),1)])):a.createCommentVNode("",!0)])}}}),jg=["data-complete"],Ug={preserveAspectRatio:"none"},Wg=["d","fill"],Kg={key:0,class:"highlight",preserveAspectRatio:"none"},qg=["d"],Nc=fn(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=pe(e.entityId,fr.PenStroke),o=pe(e.entityId,w.Block),r=pe(e.entityId,w.Color),s=a.shallowRef(""),i=a.shallowRef("");function l(f,h){return(f+h)/2}function c(f,h,p){if(h<=4||f.length<3){const b=p/2;return`M ${b},0 a ${b},${b} 0 1 0 0.0001 0`}let m=f[0],g=f[1];const y=f[2];let k=`M${m[0].toFixed(2)},${m[1].toFixed(2)} Q${g[0].toFixed(2)},${g[1].toFixed(2)} ${l(g[0],y[0]).toFixed(2)},${l(g[1],y[1]).toFixed(2)} T`;for(let b=2;b<f.length-1;b++)m=f[b],g=f[b+1],k+=`${l(m[0],g[0]).toFixed(2)},${l(m[1],g[1]).toFixed(2)} `;return k+=`${g[0].toFixed(2)},${g[1].toFixed(2)} `,k+="Z",k}a.watch([t,o],([f,h])=>{if(!f||!h){s.value="",i.value="";return}if(!f.originalWidth||!f.originalHeight){s.value="",i.value="";return}const p=h.size[0]/f.originalWidth,m=h.size[1]/f.originalHeight,g=[];for(let k=0;k<f.pointCount;k++){const b=f.points[k*2],S=f.points[k*2+1],x=(b-f.originalLeft)*p,C=(S-f.originalTop)*m;f.hasPressure?g.push([x,C,f.pressures[k]]):g.push([x,C])}const y=gi(g,{last:f.isComplete,size:f.thickness,simulatePressure:!f.hasPressure});if(s.value=c(y,f.pointCount,f.thickness),f.isComplete){const k=g.length===1?f.thickness:1,b=gi(g,{last:!0,size:k,simulatePressure:!f.hasPressure});i.value=c(b,f.pointCount,k)}},{immediate:!0});const d=a.computed(()=>r.value?`rgb(${r.value.red}, ${r.value.green}, ${r.value.blue})`:"#000000"),u=a.computed(()=>e.selected||e.hovered);return(f,h)=>{var p;return a.openBlock(),a.createElementBlock("div",{class:"wov-pen-stroke","data-complete":((p=a.unref(t))==null?void 0:p.isComplete)||void 0},[(a.openBlock(),a.createElementBlock("svg",Ug,[a.createElementVNode("path",{d:s.value,fill:d.value},null,8,Wg)])),u.value?(a.openBlock(),a.createElementBlock("svg",Kg,[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,qg)])):a.createCommentVNode("",!0)],8,jg)}}}),[["__scopeId","data-v-9b41c649"]]);function de(){const n=a.inject(je);if(!n)throw new Error("useEditorContext must be used within a WovenCanvas component");return{getEditor:()=>n.getEditor(),nextEditorTick(e){return new Promise(t=>{const o=n.getEditor();o&&o.nextTick(r=>{e==null||e(r),t(r)})})}}}const bo={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 Ce(n){this.content=n}Ce.prototype={constructor:Ce,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 Ce(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 Ce(t)},addToStart:function(n,e){return new Ce([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Ce(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 Ce(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=Ce.from(n),n.size?new Ce(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Ce.from(n),n.size?new Ce(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Ce.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}},Ce.from=function(n){if(n instanceof Ce)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Ce(e)};function Bc(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=Bc(r.content,s.content,t+1);if(i!=null)return i}t+=r.nodeSize}}function Ic(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=Ic(i.content,l.content,t-1,o-1);if(d)return d}t-=c,o-=c}}class O{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 O(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 O(o,r)}cutByIndex(e,t){return e==t?O.empty:e==0&&t==this.content.length?this:new O(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 O(r,s)}addToStart(e){return new O([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new O(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 Bc(this,e,t)}findDiffEnd(e,t=this.size,o=e.size){return Ic(this,e,t,o)}findIndex(e){if(e==0)return hr(0,e);if(e==this.size)return hr(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?hr(t+1,s):hr(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 O.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new O(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return O.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 O(t||e,o)}static from(e){if(!e)return O.empty;if(e instanceof O)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new O([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}O.empty=new O([],0);const yi={index:0,offset:0};function hr(n,e){return yi.index=n,yi.offset=e,yi}function pr(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(!pr(n[o],e[o]))return!1}else{for(let o in n)if(!(o in e)||!pr(n[o],e[o]))return!1;for(let o in e)if(!(o in n))return!1}return!0}let te=class ec{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&&pr(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 ec.none;if(e instanceof ec)return[e];let t=e.slice();return t.sort((o,r)=>o.type.rank-r.type.rank),t}};te.none=[];class mr extends Error{}class ${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=_c(this.content,e+this.openStart,t);return o&&new $(o,this.openStart,this.openEnd)}removeBetween(e,t){return new $(Oc(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 $.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 $(O.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 $(e,o,r)}}$.empty=new $(O.empty,0,0);function Oc(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(Oc(s.content,e-r-1,t-r-1)))}function _c(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=_c(i.content,e-s-1,t,i);return l&&n.replaceChild(r,i.copy(l))}function Gg(n,e,t){if(t.openStart>n.depth)throw new mr("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new mr("Inconsistent open depths");return Rc(n,e,t,0)}function Rc(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=Rc(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 pn(i,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:i,end:l}=Jg(t,n);return pn(s,Dc(n,i,l,e,o))}else return pn(s,gr(n,e,o))}function Pc(n,e){if(!e.type.compatibleContent(n.type))throw new mr("Cannot join "+e.type.name+" onto "+n.type.name)}function ki(n,e,t){let o=n.node(t);return Pc(o,e.node(t)),o}function hn(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 So(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&&(hn(n.nodeAfter,o),s++));for(let l=s;l<i;l++)hn(r.child(l),o);e&&e.depth==t&&e.textOffset&&hn(e.nodeBefore,o)}function pn(n,e){return n.type.checkContent(e),n.copy(e)}function Dc(n,e,t,o,r){let s=n.depth>r&&ki(n,e,r+1),i=o.depth>r&&ki(t,o,r+1),l=[];return So(null,n,r,l),s&&i&&e.index(r)==t.index(r)?(Pc(s,i),hn(pn(s,Dc(n,e,t,o,r+1)),l)):(s&&hn(pn(s,gr(n,e,r+1)),l),So(e,t,r,l),i&&hn(pn(i,gr(t,o,r+1)),l)),So(o,null,r,l),new O(l)}function gr(n,e,t){let o=[];if(So(null,n,t,o),n.depth>t){let r=ki(n,e,t+1);hn(pn(r,gr(n,e,t+1)),o)}return So(e,null,t,o),new O(o)}function Jg(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(O.from(r));return{start:r.resolveNoCache(n.openStart+t),end:r.resolveNoCache(r.content.size-n.openEnd-t)}}class xo{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 te.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 yr(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 xo(t,o,s)}static resolveCached(e,t){let o=Lc.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 Lc.set(e,o=new Yg);let r=o.elts[o.i]=xo.resolve(e,t);return o.i=(o.i+1)%Xg,r}}class Yg{constructor(){this.elts=[],this.i=0}}const Xg=12,Lc=new WeakMap;class yr{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 Qg=Object.create(null);let Ct=class tc{constructor(e,t,o,r=te.none){this.type=e,this.attrs=t,this.marks=r,this.content=o||O.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&&pr(this.attrs,t||e.defaultAttrs||Qg)&&te.sameSet(this.marks,o||te.none)}copy(e=null){return e==this.content?this:new tc(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new tc(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 $.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 $(d,r.depth-i,s.depth-i)}replace(e,t,o){return Gg(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 xo.resolveCached(this,e)}resolveNoCache(e){return xo.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()+")"),Vc(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=O.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=te.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(!te.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=O.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,r,o);return s.type.checkAttrs(s.attrs),s}};Ct.prototype.text=void 0;class kr extends Ct{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):Vc(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 kr(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new kr(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 Vc(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class mn{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let o=new Zg(e,t);if(o.next==null)return mn.empty;let r=$c(o);o.next&&o.err("Unexpected trailing text");let s=i0(s0(r));return l0(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 O.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
+ `)}}mn.empty=new mn(!0);class Zg{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 $c(n){let e=[];do e.push(e0(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function e0(n){let e=[];do e.push(t0(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function t0(n){let e=r0(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=n0(n,e);else break;return e}function zc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function n0(n,e){let t=zc(n),o=t;return n.eat(",")&&(n.next!="}"?o=zc(n):o=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:o,expr:e}}function o0(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 r0(n){if(n.eat("(")){let e=$c(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=o0(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 s0(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 Fc(n,e){return e-n}function Hc(n,e){let t=[];return o(e),t.sort(Fc);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 i0(n){let e=Object.create(null);return t(Hc(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]);Hc(n,c).forEach(u=>{d||r.push([l,d=[]]),d.indexOf(u)==-1&&d.push(u)})})});let s=e[o.join(",")]=new mn(o.indexOf(n.length-1)>-1);for(let i=0;i<r.length;i++){let l=r[i][1].sort(Fc);s.next.push({type:r[i][0],next:e[l.join(",")]||t(l)})}return s}}function l0(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 jc(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 Uc(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 Wc(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 Kc(n,e){let t=Object.create(null);if(e)for(let o in e)t[o]=new c0(n,o,e[o]);return t}let qc=class zm{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=Kc(e,o.attrs),this.defaultAttrs=jc(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==mn.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:Uc(this.attrs,e)}create(e=null,t,o){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new Ct(this,this.computeAttrs(e),O.from(t),te.setFrom(o))}createChecked(e=null,t,o){return t=O.from(t),this.checkContent(t),new Ct(this,this.computeAttrs(e),t,te.setFrom(o))}createAndFill(e=null,t,o){if(e=this.computeAttrs(e),t=O.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(O.empty,!0);return s?new Ct(this,e,t.append(s),te.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){Wc(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:te.none:e}static compile(e,t){let o=Object.create(null);e.forEach((s,i)=>o[s]=new zm(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 a0(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 c0{constructor(e,t,o){this.hasDefault=Object.prototype.hasOwnProperty.call(o,"default"),this.default=o.default,this.validate=typeof o.validate=="string"?a0(e,t,o.validate):o.validate}get isRequired(){return!this.hasDefault}}class wr{constructor(e,t,o,r){this.name=e,this.rank=t,this.schema=o,this.spec=r,this.attrs=Kc(e,r.attrs),this.excluded=null;let s=jc(this.attrs);this.instance=s?new te(this,s):null}create(e=null){return!e&&this.instance?this.instance:new te(this,Uc(this.attrs,e))}static compile(e,t){let o=Object.create(null),r=0;return e.forEach((s,i)=>o[s]=new wr(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){Wc(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class Gc{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=Ce.from(e.nodes),t.marks=Ce.from(e.marks||{}),this.nodes=qc.compile(this.spec.nodes,this),this.marks=wr.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]=mn.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?Jc(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==""?[]:Jc(this,i.split(" "))}this.nodeFromJSON=r=>Ct.fromJSON(this,r),this.markFromJSON=r=>te.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 qc){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 kr(o,o.defaultAttrs,e,te.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 Jc(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 d0(n){return n.tag!=null}function u0(n){return n.style!=null}let Hn=class nc{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let o=this.matchedStyles=[];t.forEach(r=>{if(d0(r))this.tags.push(r);else if(u0(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 Zc(this,t,!1);return o.addAll(e,te.none,t.from,t.to),o.finish()}parseSlice(e,t={}){let o=new Zc(this,t,!0);return o.addAll(e,te.none,t.from,t.to),$.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(p0(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=ed(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=ed(i)),i.node||i.ignore||i.mark||(i.node=r)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new nc(e,nc.schemaRules(e)))}};const Yc={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},f0={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Xc={ol:!0,ul:!0},Co=1,wi=2,Eo=4;function Qc(n,e,t){return e!=null?(e?Co:0)|(e==="full"?wi:0):n&&n.whitespace=="pre"?Co|wi:t&~Eo}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=te.none,this.match=s||(i&Eo?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(O.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&Co)){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=O.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(O.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&&!Yc.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Zc{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=Qc(null,t.preserveWhitespace,0)|(o?Eo:0);r?s=new br(r.type,r.attrs,te.none,!0,t.topMatch||r.type.contentMatch,i):o?s=new br(null,null,te.none,!0,null,i):s=new br(e.schema.topNodeType,null,te.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&wi?"full":this.localPreserveWS||(r.options&Co)>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
+ `);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;Xc.hasOwnProperty(i)&&this.parser.normalizeLists&&h0(e);let c=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,o));e:if(c?c.ignore:f0.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(Yc.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=te.none;for(let l of r.concat(e.marks))(s.type?s.type.allowsMarkType(l.type):td(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=Qc(e,s,i.options);i.options&Eo&&i.content.length==0&&(l|=Eo);let c=te.none;return o=o.filter(d=>(i.type?i.type.allowsMarkType(d.type):td(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|=Co)}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 h0(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let o=e.nodeType==1?e.nodeName.toLowerCase():null;o&&Xc.hasOwnProperty(o)&&t?(t.appendChild(e),e=t):o=="li"?t=e:o&&(t=null)}}function p0(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function ed(n){let e={};for(let t in n)e[t]=n[t];return e}function td(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 gn{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},o){o||(o=bi(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}=Sr(bi(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&&Sr(bi(o),r(e,t),null,e.attrs)}static renderSpec(e,t,o=null,r){return Sr(e,t,o,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new gn(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=nd(e.nodes);return t.text||(t.text=o=>o.text),t}static marksFromSchema(e){return nd(e.marks)}}function nd(n){let e={};for(let t in n){let o=n[t].spec.toDOM;o&&(e[t]=o)}return e}function bi(n){return n.document||window.document}const od=new WeakMap;function m0(n){let e=od.get(n);return e===void 0&&od.set(n,e=g0(n)),e}function g0(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 Sr(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=m0(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}=Sr(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 rd=65535,sd=Math.pow(2,16);function y0(n,e){return n+e*sd}function id(n){return n&rd}function k0(n){return(n-(n&rd))/sd}const ld=1,ad=2,xr=4,cd=8;class Si{constructor(e,t,o){this.pos=e,this.delInfo=t,this.recover=o}get deleted(){return(this.delInfo&cd)>0}get deletedBefore(){return(this.delInfo&(ld|xr))>0}get deletedAfter(){return(this.delInfo&(ad|xr))>0}get deletedAcross(){return(this.delInfo&xr)>0}}class Ue{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&Ue.empty)return Ue.empty}recover(e){let t=0,o=id(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+k0(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:y0(l/3,e-c),g=e==c?ad:e==f?ld:xr;return(t<0?e!=c:e!=f)&&(g|=cd),new Si(p,g,m)}r+=u-d}return o?e+r:new Si(e+r,0,null)}touches(e,t){let o=0,r=id(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 Ue(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?Ue.empty:new Ue(e<0?[0,-e,0]:[0,0,e])}}Ue.empty=new Ue([]);class vo{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 vo(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 vo;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 Si(e,r,null)}}const xi=Object.create(null);class Oe{getMap(){return Ue.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let o=xi[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 xi)throw new RangeError("Duplicate use of step JSON ID "+e);return xi[e]=t,t.prototype.jsonID=e,t}}class me{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new me(e,null)}static fail(e){return new me(null,e)}static fromReplace(e,t,o,r){try{return me.ok(e.replace(t,o,r))}catch(s){if(s instanceof mr)return me.fail(s.message);throw s}}}function Ci(n,e,t){let o=[];for(let r=0;r<n.childCount;r++){let s=n.child(r);s.content.size&&(s=s.copy(Ci(s.content,e,s))),s.isInline&&(s=e(s,t,r)),o.push(s)}return O.fromArray(o)}class Ft extends Oe{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 $(Ci(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 me.fromReplace(e,this.from,this.to,s)}invert(){return new tt(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 Ft(t.pos,o.pos,this.mark)}merge(e){return e instanceof Ft&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Ft(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 Ft(t.from,t.to,e.markFromJSON(t.mark))}}Oe.jsonID("addMark",Ft);class tt extends Oe{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 $(Ci(t.content,r=>r.mark(this.mark.removeFromSet(r.marks)),e),t.openStart,t.openEnd);return me.fromReplace(e,this.from,this.to,o)}invert(){return new Ft(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 tt(t.pos,o.pos,this.mark)}merge(e){return e instanceof tt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new tt(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 tt(t.from,t.to,e.markFromJSON(t.mark))}}Oe.jsonID("removeMark",tt);class Ht extends Oe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return me.fail("No node at mark step's position");let o=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return me.fromReplace(e,this.pos,this.pos+1,new $(O.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 Ht(this.pos,t.marks[r]);return new Ht(this.pos,this.mark)}}return new yn(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new Ht(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 Ht(t.pos,e.markFromJSON(t.mark))}}Oe.jsonID("addNodeMark",Ht);class yn extends Oe{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return me.fail("No node at mark step's position");let o=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return me.fromReplace(e,this.pos,this.pos+1,new $(O.from(o),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new Ht(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new yn(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 yn(t.pos,e.markFromJSON(t.mark))}}Oe.jsonID("removeNodeMark",yn);class ge extends Oe{constructor(e,t,o,r=!1){super(),this.from=e,this.to=t,this.slice=o,this.structure=r}apply(e){return this.structure&&Ei(e,this.from,this.to)?me.fail("Structure replace would overwrite content"):me.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new Ue([this.from,this.to-this.from,this.slice.size])}invert(e){return new ge(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 ge(t.pos,Math.max(t.pos,o.pos),this.slice,this.structure)}merge(e){if(!(e instanceof ge)||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?$.empty:new $(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new ge(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?$.empty:new $(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new ge(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 ge(t.from,t.to,$.fromJSON(e,t.slice),!!t.structure)}}Oe.jsonID("replace",ge);class ye extends Oe{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&&(Ei(e,this.from,this.gapFrom)||Ei(e,this.gapTo,this.to)))return me.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return me.fail("Gap is not a flat range");let o=this.slice.insertAt(this.insert,t.content);return o?me.fromReplace(e,this.from,this.to,o):me.fail("Content does not fit in gap")}getMap(){return new Ue([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 ye(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 ye(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 ye(t.from,t.to,t.gapFrom,t.gapTo,$.fromJSON(e,t.slice),t.insert,!!t.structure)}}Oe.jsonID("replaceAround",ye);function Ei(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 w0(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 tt(h,p,f[g])));l&&l.to==h?l.to=p:s.push(l=new Ft(h,p,o))}}),r.forEach(c=>n.step(c)),s.forEach(c=>n.step(c))}function b0(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 wr){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 tt(i.from,i.to,i.style)))}function vi(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 ge(l,u,$.empty));else{o=f;for(let h=0;h<d.marks.length;h++)t.allowsMarkType(d.marks[h].type)||n.step(new tt(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 $(O.from(t.schema.text(" ",t.allowedMarks(d.marks))),0,0)),i.push(new ge(l+h.index,l+h.index+h[0].length,m))}}l=u}if(!o.validEnd){let c=o.fillBefore(O.empty,!0);n.replace(l,l,new $(c,0,0))}for(let c=i.length-1;c>=0;c--)n.step(i[c])}function S0(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function jn(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||!S0(i,l,c))break;l&&(r=1),c<i.childCount&&(s=1)}return null}function x0(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=O.empty,f=0;for(let m=s,g=!1;m>t;m--)g||o.index(m)>0?(g=!0,u=O.from(o.node(m).copy(u)),f++):c--;let h=O.empty,p=0;for(let m=s,g=!1;m>t;m--)g||r.after(m+1)<r.end(m)?(g=!0,h=O.from(r.node(m).copy(h)),p++):d++;n.step(new ye(c,d,i,l,new $(u.append(h),f,p),u.size-f,!0))}function dd(n,e,t=null,o=n){let r=C0(n,e),s=r&&E0(o,e);return s?r.map(ud).concat({type:e,attrs:t}).concat(s.map(ud)):null}function ud(n){return{type:n,attrs:null}}function C0(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 E0(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 v0(n,e,t){let o=O.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=O.from(t[i].type.create(t[i].attrs,o))}let r=e.start,s=e.end;n.step(new ye(r,s,r,s,new $(o,0,0),t.length,!0))}function T0(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)&&M0(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&&hd(n,i,l,s),vi(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 ye(f,h,f+1,h-1,new $(O.from(o.create(c,null,i.marks)),0,0),1,!0)),d===!0&&fd(n,i,l,s),!1}})}function fd(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 hd(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 M0(n,e,t){let o=n.resolve(e),r=o.index();return o.parent.canReplaceWith(r,r+1,t)}function A0(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 ye(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new $(O.from(i),0,0),1,!0))}function Et(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 N0(n,e,t=1,o){let r=n.doc.resolve(e),s=O.empty,i=O.empty;for(let l=r.depth,c=r.depth-t,d=t-1;l>c;l--,d--){s=O.from(r.node(l).copy(s));let u=o&&o[d];i=O.from(u?u.type.create(u.attrs,i):r.node(l).copy(i))}n.step(new ge(e,e,new $(s.append(i),t,t),!0))}function kn(n,e){let t=n.resolve(e),o=t.index();return pd(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(o,o+1)}function B0(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 pd(n,e){return!!(n&&e&&!n.isLeaf&&B0(n,e))}function Cr(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&&pd(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 I0(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);hd(n,u.node(),u.before(),l)}i.inlineContent&&vi(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 ge(d,c.map(e+t,-1),$.empty,!0)),o===!0){let u=n.doc.resolve(d);fd(n,u.node(),u.before(),n.steps.length)}return n}function O0(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 md(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 Er(n,e,t=e,o=$.empty){if(e==t&&!o.size)return null;let r=n.resolve(e),s=n.resolve(t);return gd(r,s,o)?new ge(e,t,o):new _0(r,s,o).fit()}function gd(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class _0{constructor(e,t,o){this.$from=e,this.$to=t,this.unplaced=o,this.frontier=[],this.placed=O.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=O.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 $(s,i,l);return e>-1?new ye(o.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||o.pos!=this.$to.pos?new ge(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=Ti(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(O.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=Ti(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new $(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=Ti(e,t);if(r.childCount<=1&&t>0){let s=e.size-t<=t+r.size;this.unplaced=new $(To(e,t-1,1),t-1,s?t-1:o)}else this.unplaced=new $(To(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(yd(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=Mo(this.placed,t,O.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?$.empty:new $(To(i.content,e-1,1),e-1,p<0?i.openEnd:e-1):new $(To(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||!Mi(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=Mi(e,t,r,o,s);if(i){for(let l=t-1;l>=0;l--){let{match:c,type:d}=this.frontier[l],u=Mi(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=Mo(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=Mo(this.placed,this.depth,O.from(e.create(t,o))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(O.empty,!0);t.childCount&&(this.placed=Mo(this.placed,this.frontier.length,t))}}function To(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(To(n.firstChild.content,e-1,t)))}function Mo(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Mo(n.lastChild.content,e-1,t)))}function Ti(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function yd(n,e,t){if(e<=0)return n;let o=n.content;return e>1&&(o=o.replaceChild(0,yd(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(O.empty,!0)))),n.copy(o)}function Mi(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&&!R0(t,s.content,i)?l:null}function R0(n,e,t){for(let o=t;o<e.childCount;o++)if(!n.allowsMarks(e.child(o).marks))return!0;return!1}function P0(n){return n.spec.defining||n.spec.definingForContent}function D0(n,e,t,o){if(!o.size)return n.deleteRange(e,t);let r=n.doc.resolve(e),s=n.doc.resolve(t);if(gd(r,s,o))return n.step(new ge(e,t,o));let i=wd(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=P0(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 b=r.node(y-1),S=r.index(y-1);if(b.canReplaceWith(S,S,m.type,m.marks))return n.replace(r.before(y),k?s.after(y):t,new $(kd(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 kd(n,e,t,o,r){if(e<t){let s=n.firstChild;n=n.replaceChild(0,s.copy(kd(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(O.empty,!0))}return n}function L0(n,e,t,o){if(!o.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let r=O0(n.doc,e,o.type);r!=null&&(e=t=r)}n.replaceRange(e,t,new $(O.from(o),0,0))}function V0(n,e,t){let o=n.doc.resolve(e),r=n.doc.resolve(t),s=wd(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 wd(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 Un extends Oe{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 me.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 me.fromReplace(e,this.pos,this.pos+1,new $(O.from(r),0,t.isLeaf?0:1))}getMap(){return Ue.empty}invert(e){return new Un(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 Un(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 Un(t.pos,t.attr,t.value)}}Oe.jsonID("attr",Un);class Ao extends Oe{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 me.ok(o)}getMap(){return Ue.empty}invert(e){return new Ao(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 Ao(t.attr,t.value)}}Oe.jsonID("docAttr",Ao);let Wn=class extends Error{};Wn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t},Wn.prototype=Object.create(Error.prototype),Wn.prototype.constructor=Wn,Wn.prototype.name="TransformError";class bd{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new vo}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Wn(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=$.empty){let r=Er(this.doc,e,t,o);return r&&this.step(r),this}replaceWith(e,t,o){return this.replace(e,t,new $(O.from(o),0,0))}delete(e,t){return this.replace(e,t,$.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,o){return D0(this,e,t,o),this}replaceRangeWith(e,t,o){return L0(this,e,t,o),this}deleteRange(e,t){return V0(this,e,t),this}lift(e,t){return x0(this,e,t),this}join(e,t=1){return I0(this,e,t),this}wrap(e,t){return v0(this,e,t),this}setBlockType(e,t=e,o,r=null){return T0(this,e,t,o,r),this}setNodeMarkup(e,t,o=null,r){return A0(this,e,t,o,r),this}setNodeAttribute(e,t,o){return this.step(new Un(e,t,o)),this}setDocAttribute(e,t){return this.step(new Ao(e,t)),this}addNodeMark(e,t){return this.step(new Ht(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 te)t.isInSet(o.marks)&&this.step(new yn(e,t));else{let r=o.marks,s,i=[];for(;s=t.isInSet(r);)i.push(new yn(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 N0(this,e,t,o),this}addMark(e,t,o){return w0(this,e,t,o),this}removeMark(e,t,o){return b0(this,e,t,o),this}clearIncompatible(e,t,o){return vi(this,e,t,o),this}}const Ai=Object.create(null);class Z{constructor(e,t,o){this.$anchor=e,this.$head=t,this.ranges=o||[new $0(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=$.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?$.empty:t),l==0&&Cd(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),Cd(e,o,t.isInline?-1:1))}}static findFrom(e,t,o=!1){let r=e.parent.inlineContent?new Y(e):Kn(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?Kn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,o):Kn(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 We(e.node(0))}static atStart(e){return Kn(e,e,0,0,1)||new We(e)}static atEnd(e){return Kn(e,e,e.content.size,e.childCount,-1)||new We(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let o=Ai[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 Ai)throw new RangeError("Duplicate use of selection JSON ID "+e);return Ai[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Y.between(this.$anchor,this.$head).getBookmark()}}Z.prototype.visible=!0;class $0{constructor(e,t){this.$from=e,this.$to=t}}let Sd=!1;function xd(n){!Sd&&!n.parent.inlineContent&&(Sd=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}class Y extends Z{constructor(e,t=e){xd(e),xd(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 Z.near(o);let r=e.resolve(t.map(this.anchor));return new Y(r.parent.inlineContent?r:o,o)}replace(e,t=$.empty){if(super.replace(e,t),t==$.empty){let o=this.$from.marksAcross(this.$to);o&&e.ensureMarks(o)}}eq(e){return e instanceof Y&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new vr(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 Y(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=Z.findFrom(t,o,!0)||Z.findFrom(t,-o,!0);if(s)t=s.$head;else return Z.near(t,o)}return e.parent.inlineContent||(r==0?e=t:(e=(Z.findFrom(e,-o,!0)||Z.findFrom(e,o,!0)).$anchor,e.pos<t.pos!=r<0&&(e=t))),new Y(e,t)}}Z.jsonID("text",Y);class vr{constructor(e,t){this.anchor=e,this.head=t}map(e){return new vr(e.map(this.anchor),e.map(this.head))}resolve(e){return Y.between(e.resolve(this.anchor),e.resolve(this.head))}}class q extends Z{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?Z.near(s):new q(s)}content(){return new $(O.from(this.node),0,0)}eq(e){return e instanceof q&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new Ni(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new q(e.resolve(t.anchor))}static create(e,t){return new q(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}}q.prototype.visible=!1,Z.jsonID("node",q);class Ni{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:o}=e.mapResult(this.anchor);return t?new vr(o,o):new Ni(o)}resolve(e){let t=e.resolve(this.anchor),o=t.nodeAfter;return o&&q.isSelectable(o)?new q(t):Z.near(t)}}class We extends Z{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=$.empty){if(t==$.empty){e.delete(0,e.doc.content.size);let o=Z.atStart(e.doc);o.eq(e.selection)||e.setSelection(o)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new We(e)}map(e){return new We(e)}eq(e){return e instanceof We}getBookmark(){return z0}}Z.jsonID("all",We);const z0={map(){return this},resolve(n){return new We(n)}};function Kn(n,e,t,o,r,s=!1){if(e.inlineContent)return Y.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&&q.isSelectable(l))return q.create(n,t-(r<0?l.nodeSize:0))}else{let c=Kn(n,l,t+r,r<0?l.childCount:0,r,s);if(c)return c}t+=l.nodeSize*r}return null}function Cd(n,e,t){let o=n.steps.length-1;if(o<e)return;let r=n.steps[o];if(!(r instanceof ge||r instanceof ye))return;let s=n.mapping.maps[o],i;s.forEach((l,c,d,u)=>{i==null&&(i=u)}),n.setSelection(Z.near(n.doc.resolve(i),t))}const Ed=1,Tr=2,vd=4;class F0 extends bd{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|Ed)&~Tr,this.storedMarks=null,this}get selectionSet(){return(this.updated&Ed)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Tr,this}ensureMarks(e){return te.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&Tr)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Tr,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)||te.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(Z.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|=vd,this}get scrolledIntoView(){return(this.updated&vd)>0}}function Td(n,e){return!e||!n?n:n.bind(e)}class No{constructor(e,t,o){this.name=e,this.init=Td(t.init,o),this.apply=Td(t.apply,o)}}const H0=[new No("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new No("selection",{init(n,e){return n.selection||Z.atStart(e.doc)},apply(n){return n.selection}}),new No("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,o){return o.selection.$cursor?n.storedMarks:null}}),new No("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class Bi{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=H0.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 No(o.key,o.spec.state,o))})}}class qn{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 qn(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 F0(this)}static create(e){let t=new Bi(e.doc?e.doc.type.schema:e.schema,e.plugins),o=new qn(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 Bi(this.schema,e.plugins),o=t.fields,r=new qn(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 Bi(e.schema,e.plugins),s=new qn(r);return r.fields.forEach(i=>{if(i.name=="doc")s.doc=Ct.fromJSON(e.schema,t.doc);else if(i.name=="selection")s.selection=Z.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 Md(n,e,t){for(let o in n){let r=n[o];r instanceof Function?r=r.bind(e):o=="handleDOMEvents"&&(r=Md(r,e,{})),t[o]=r}return t}class ue{constructor(e){this.spec=e,this.props={},e.props&&Md(e.props,this,this.props),this.key=e.key?e.key.key:Ad("plugin")}getState(e){return e[this.key]}}const Ii=Object.create(null);function Ad(n){return n in Ii?n+"$"+ ++Ii[n]:(Ii[n]=0,n+"$")}class ke{constructor(e="key"){this.key=Ad(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const Oi=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Nd(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Bd=(n,e,t)=>{let o=Nd(n,t);if(!o)return!1;let r=_i(o);if(!r){let i=o.blockRange(),l=i&&jn(i);return l==null?!1:(e&&e(n.tr.lift(i,l).scrollIntoView()),!0)}let s=r.nodeBefore;if($d(n,r,e,-1))return!0;if(o.parent.content.size==0&&(Gn(s,"end")||q.isSelectable(s)))for(let i=o.depth;;i--){let l=Er(n.doc,o.before(i),o.after(i),$.empty);if(l&&l.slice.size<l.to-l.from){if(e){let c=n.tr.step(l);c.setSelection(Gn(s,"end")?Z.findFrom(c.doc.resolve(c.mapping.map(r.pos,-1)),-1):q.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},j0=(n,e,t)=>{let o=Nd(n,t);if(!o)return!1;let r=_i(o);return r?Id(n,r,e):!1},U0=(n,e,t)=>{let o=_d(n,t);if(!o)return!1;let r=Ri(o);return r?Id(n,r,e):!1};function Id(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=Er(n.doc,s,c,$.empty);if(!d||d.from!=s||d instanceof ge&&d.slice.size>=c-s)return!1;if(t){let u=n.tr.step(d);u.setSelection(Y.create(u.doc,s)),t(u.scrollIntoView())}return!0}function Gn(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 Od=(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=_i(o)}let i=s&&s.nodeBefore;return!i||!q.isSelectable(i)?!1:(e&&e(n.tr.setSelection(q.create(n.doc,s.pos-i.nodeSize)).scrollIntoView()),!0)};function _i(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 _d(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const Rd=(n,e,t)=>{let o=_d(n,t);if(!o)return!1;let r=Ri(o);if(!r)return!1;let s=r.nodeAfter;if($d(n,r,e,1))return!0;if(o.parent.content.size==0&&(Gn(s,"start")||q.isSelectable(s))){let i=Er(n.doc,o.before(),o.after(),$.empty);if(i&&i.slice.size<i.to-i.from){if(e){let l=n.tr.step(i);l.setSelection(Gn(s,"start")?Z.findFrom(l.doc.resolve(l.mapping.map(r.pos)),1):q.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},Pd=(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=Ri(o)}let i=s&&s.nodeAfter;return!i||!q.isSelectable(i)?!1:(e&&e(n.tr.setSelection(q.create(n.doc,s.pos)).scrollIntoView()),!0)};function Ri(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 W0=(n,e)=>{let t=n.selection,o=t instanceof q,r;if(o){if(t.node.isTextblock||!kn(n.doc,t.from))return!1;r=t.from}else if(r=Cr(n.doc,t.from,-1),r==null)return!1;if(e){let s=n.tr.join(r);o&&s.setSelection(q.create(s.doc,r-n.doc.resolve(r).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},K0=(n,e)=>{let t=n.selection,o;if(t instanceof q){if(t.node.isTextblock||!kn(n.doc,t.to))return!1;o=t.to}else if(o=Cr(n.doc,t.to,1),o==null)return!1;return e&&e(n.tr.join(o).scrollIntoView()),!0},q0=(n,e)=>{let{$from:t,$to:o}=n.selection,r=t.blockRange(o),s=r&&jn(r);return s==null?!1:(e&&e(n.tr.lift(r,s).scrollIntoView()),!0)},Dd=(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 Pi(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 G0=(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=Pi(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(Z.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Ld=(n,e)=>{let t=n.selection,{$from:o,$to:r}=t;if(t instanceof We||o.parent.inlineContent||r.parent.inlineContent)return!1;let s=Pi(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(Y.create(l.doc,i+1)),e(l.scrollIntoView())}return!0},Vd=(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(Et(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let o=t.blockRange(),r=o&&jn(o);return r==null?!1:(e&&e(n.tr.lift(o,r).scrollIntoView()),!0)};function J0(n){return(e,t)=>{let{$from:o,$to:r}=e.selection;if(e.selection instanceof q&&e.selection.node.isBlock)return!o.parentOffset||!Et(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=Pi(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 Y||e.selection instanceof We)&&u.deleteSelection();let f=u.mapping.map(o.pos),h=Et(u.doc,f,s.length,s);if(h||(s[0]=l?{type:l}:null,h=Et(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 Y0=J0(),X0=(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(q.create(n.doc,r))),!0)};function Q0(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||kn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function $d(n,e,t,o){let r=e.nodeBefore,s=e.nodeAfter,i,l,c=r.type.spec.isolating||s.type.spec.isolating;if(!c&&Q0(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=O.empty;for(let k=i.length-1;k>=0;k--)m=O.from(i[k].create(null,m));m=O.from(r.copy(m));let g=n.tr.step(new ye(e.pos-1,p,e.pos,p,new $(m,1,0),i.length,!0)),y=g.doc.resolve(p+2*i.length);y.nodeAfter&&y.nodeAfter.type==r.type&&kn(g.doc,y.pos)&&g.join(y.pos),t(g.scrollIntoView())}return!0}let u=s.type.spec.isolating||o>0&&c?null:Z.findFrom(e,1),f=u&&u.$from.blockRange(u.$to),h=f&&jn(f);if(h!=null&&h>=e.depth)return t&&t(n.tr.lift(f,h).scrollIntoView()),!0;if(d&&Gn(s,"start",!0)&&Gn(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=O.empty;for(let S=m.length-1;S>=0;S--)k=O.from(m[S].copy(k));let b=n.tr.step(new ye(e.pos-m.length,e.pos+s.nodeSize,e.pos+y,e.pos+s.nodeSize-y,new $(k,m.length,0),0,!0));t(b.scrollIntoView())}return!0}}return!1}function zd(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(Y.create(e.doc,n<0?r.start(s):r.end(s)))),!0):!1}}const Z0=zd(-1),ey=zd(1);function ty(n,e=null){return function(t,o){let{$from:r,$to:s}=t.selection,i=r.blockRange(s),l=i&&dd(i,n,e);return l?(o&&o(t.tr.wrap(i,l).scrollIntoView()),!0):!1}}function Fd(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 Di(...n){return function(e,t,o){for(let r=0;r<n.length;r++)if(n[r](e,t,o))return!0;return!1}}Di(Oi,Bd,Od),Di(Oi,Rd,Pd),Di(Dd,Ld,Vd,Y0),typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function ny(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 oy(l,i,n,e)?(o&&o(l.scrollIntoView()),!0):!1}}function oy(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 yr(c,c,e.depth),e.endIndex<e.parent.childCount&&(e=new yr(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),r=!0}let l=dd(s,t,o,e);return l?(n&&ry(n,e,l,r,t),!0):!1}function ry(n,e,t,o,r){let s=O.empty;for(let u=t.length-1;u>=0;u--)s=O.from(t[u].type.create(t[u].attrs,s));n.step(new ye(e.start-(o?2:0),e.end,e.start,e.end,new $(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&&Et(n.doc,c,l)&&(n.split(c,l),c+=2*l),c+=d.child(u).nodeSize;return n}function sy(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?iy(e,t,n,s):ly(e,t,s):!0:!1}}function iy(n,e,t,o){let r=n.tr,s=o.end,i=o.$to.end(o.depth);s<i&&(r.step(new ye(s-1,i,s,i,new $(O.from(t.create(null,o.parent.copy())),1,0),1,!0)),o=new yr(r.doc.resolve(o.$from.pos),r.doc.resolve(i),o.depth));const l=jn(o);if(l==null)return!1;r.lift(o,l);let c=r.doc.resolve(r.mapping.map(s,-1)-1);return kn(r.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&r.join(c.pos),e(r.scrollIntoView()),!0}function ly(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?O.empty:O.from(r))))return!1;let f=s.pos,h=f+i.nodeSize;return o.step(new ye(f-(l?1:0),h+(c?1:0),f+1,h-1,new $((l?O.empty:O.from(r.copy(O.empty))).append(c?O.empty:O.from(r.copy(O.empty))),l?0:1,c?0:1),l?0:1)),e(o.scrollIntoView()),!0}function ay(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=O.from(d?n.create():null),f=new $(O.from(n.create(null,O.from(l.type.create(null,u)))),d?3:1,0),h=s.start,p=s.end;t(e.tr.step(new ye(h-(d?3:1),p,h,p,f,1,!0)).scrollIntoView())}return!0}}const Ee=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Jn=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let Li=null;const vt=function(n,e,t){let o=Li||(Li=document.createRange());return o.setEnd(n,t??n.nodeValue.length),o.setStart(n,e||0),o},cy=function(){Li=null},wn=function(n,e,t,o){return t&&(Hd(n,e,t,o,-1)||Hd(n,e,t,o,1))},dy=/^(img|br|input|textarea|hr)$/i;function Hd(n,e,t,o,r){for(var s;;){if(n==t&&e==o)return!0;if(e==(r<0?0:Je(n))){let i=n.parentNode;if(!i||i.nodeType!=1||Bo(n)||dy.test(n.nodeName)||n.contentEditable=="false")return!1;e=Ee(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?Je(n):0}else return!1}}function Je(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function uy(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=Je(n)}else if(n.parentNode&&!Bo(n))e=Ee(n),n=n.parentNode;else return null}}function fy(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&&!Bo(n))e=Ee(n)+1,n=n.parentNode;else return null}}function hy(n,e,t){for(let o=e==0,r=e==Je(n);o||r;){if(n==t)return!0;let s=Ee(n);if(n=n.parentNode,!n)return!1;o=o&&s==0,r=r&&s==Je(n)}}function Bo(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 Mr=function(n){return n.focusNode&&wn(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function bn(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function py(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function my(n,e,t){if(n.caretPositionFromPoint)try{let o=n.caretPositionFromPoint(e,t);if(o)return{node:o.offsetNode,offset:Math.min(Je(o.offsetNode),o.offset)}}catch{}if(n.caretRangeFromPoint){let o=n.caretRangeFromPoint(e,t);if(o)return{node:o.startContainer,offset:Math.min(Je(o.startContainer),o.startOffset)}}}const ft=typeof navigator<"u"?navigator:null,jd=typeof document<"u"?document:null,jt=ft&&ft.userAgent||"",Vi=/Edge\/(\d+)/.exec(jt),Ud=/MSIE \d/.exec(jt),$i=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(jt),$e=!!(Ud||$i||Vi),Ut=Ud?document.documentMode:$i?+$i[1]:Vi?+Vi[1]:0,Ye=!$e&&/gecko\/(\d+)/i.test(jt);Ye&&+(/Firefox\/(\d+)/.exec(jt)||[0,0])[1];const zi=!$e&&/Chrome\/(\d+)/.exec(jt),ve=!!zi,Wd=zi?+zi[1]:0,_e=!$e&&!!ft&&/Apple Computer/.test(ft.vendor),Yn=_e&&(/Mobile\/\w+/.test(jt)||!!ft&&ft.maxTouchPoints>2),Xe=Yn||(ft?/Mac/.test(ft.platform):!1),Kd=ft?/Win/.test(ft.platform):!1,Tt=/Android \d/.test(jt),Io=!!jd&&"webkitFontSmoothing"in jd.documentElement.style,gy=Io?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function yy(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 Mt(n,e){return typeof n=="number"?n:n[e]}function ky(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 qd(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=Jn(i);continue}let l=i,c=l==s.body,d=c?yy(s):ky(l),u=0,f=0;if(e.top<d.top+Mt(o,"top")?f=-(d.top-e.top+Mt(r,"top")):e.bottom>d.bottom-Mt(o,"bottom")&&(f=e.bottom-e.top>d.bottom-d.top?e.top+Mt(r,"top")-d.top:e.bottom-d.bottom+Mt(r,"bottom")),e.left<d.left+Mt(o,"left")?u=-(d.left-e.left+Mt(r,"left")):e.right>d.right-Mt(o,"right")&&(u=e.right-d.right+Mt(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:Jn(i)}}function wy(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:Gd(n.dom)}}function Gd(n){let e=[],t=n.ownerDocument;for(let o=n;o&&(e.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),n!=t);o=Jn(o));return e}function by({refDOM:n,refTop:e,stack:t}){let o=n?n.getBoundingClientRect().top:0;Jd(t,o==0?0:o-e)}function Jd(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 Xn=null;function Sy(n){if(n.setActive)return n.setActive();if(Xn)return n.focus(Xn);let e=Gd(n);n.focus(Xn==null?{get preventScroll(){return Xn={preventScroll:!0},!0}}:void 0),Xn||(Xn=!1,Jd(e,0))}function Yd(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=vt(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?xy(t,r):!t||o&&t.nodeType==1?{node:n,offset:s}:Yd(t,r)}function xy(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=Wt(o,1);if(i.top!=i.bottom&&Fi(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 Fi(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function Cy(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function Ey(n,e,t){let{node:o,offset:r}=Yd(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 vy(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 Xd(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(Fi(e,d))return Xd(i,e,d)}}if((s=(s+1)%o)==r)break}return n}function Ty(n,e){let t=n.dom.ownerDocument,o,r=0,s=my(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(!Fi(e,d)||(i=Xd(n.dom,e,d),!i))return null}if(_e)for(let d=i;o&&d;d=Jn(d))d.draggable&&(o=void 0);if(i=Cy(i,e),o){if(Ye&&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;Io&&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=vy(n,o,r,e))}l==null&&(l=Ey(n,i,e));let c=n.docView.nearestDesc(i,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Qd(n){return n.top<n.bottom||n.left<n.right}function Wt(n,e){let t=n.getClientRects();if(t.length){let o=t[e<0?0:t.length-1];if(Qd(o))return o}return Array.prototype.find.call(t,Qd)||n.getBoundingClientRect()}const My=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function Zd(n,e,t){let{node:o,offset:r,atom:s}=n.docView.domFromPos(e,t<0?-1:1),i=Io||Ye;if(o.nodeType==3)if(i&&(My.test(o.nodeValue)||(t<0?!r:r==o.nodeValue.length))){let c=Wt(vt(o,r,r),t);if(Ye&&r&&/\s/.test(o.nodeValue[r-1])&&r<o.nodeValue.length){let d=Wt(vt(o,r-1,r-1),-1);if(d.top==c.top){let u=Wt(vt(o,r,r+1),-1);if(u.top!=c.top)return Oo(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++,Oo(Wt(vt(o,c,d),u),u<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&r&&(t<0||r==Je(o))){let c=o.childNodes[r-1];if(c.nodeType==1)return Hi(c.getBoundingClientRect(),!1)}if(s==null&&r<Je(o)){let c=o.childNodes[r];if(c.nodeType==1)return Hi(c.getBoundingClientRect(),!0)}return Hi(o.getBoundingClientRect(),t>=0)}if(s==null&&r&&(t<0||r==Je(o))){let c=o.childNodes[r-1],d=c.nodeType==3?vt(c,Je(c)-(i?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(d)return Oo(Wt(d,1),!1)}if(s==null&&r<Je(o)){let c=o.childNodes[r];for(;c.pmViewDesc&&c.pmViewDesc.ignoreForCoords;)c=c.nextSibling;let d=c?c.nodeType==3?vt(c,0,i?0:1):c.nodeType==1?c:null:null;if(d)return Oo(Wt(d,-1),!0)}return Oo(Wt(o.nodeType==3?vt(o):o,-t),t>=0)}function Oo(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 Hi(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 eu(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 Ay(n,e,t){let o=e.selection,r=t=="up"?o.$from:o.$to;return eu(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=Zd(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=vt(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 Ny=/[\u0590-\u08ac]/;function By(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?!Ny.test(o.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:i:eu(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 tu=null,nu=null,ou=!1;function Iy(n,e,t){return tu==e&&nu==t?ou:(tu=e,nu=t,ou=t=="up"||t=="down"?Ay(n,e,t):By(n,e,t))}const Qe=0,ru=1,Sn=2,ht=3;class _o{constructor(e,t,o,r){this.parent=e,this.children=t,this.dom=o,this.contentDOM=r,this.dirty=Qe,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>Ee(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 lu){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 su&&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?Ee(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?Ee(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=Ee(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=Ee(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((Ye||_e)&&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:Ee(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(Ye&&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&&_e)&&wn(l.node,l.offset,u.anchorNode,u.anchorOffset)&&wn(c.node,c.offset,u.focusNode,u.focusOffset))return;let h=!1;if((d.extend||e==t)&&!(f&&Ye)){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?Sn:ru,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=ht:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?Sn:ht}o=i}this.dirty=Sn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let o=e==1?Sn:ru;t.dirty<o&&(t.dirty=o)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class su extends _o{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==Qe&&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 Oy extends _o{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 xn extends _o{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=gn.renderSpec(document,t.type.spec.toDOM(t,o),null,t.attrs)),new xn(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return this.dirty&ht||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ht&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Qe){let o=this.parent;for(;!o.node;)o=o.parent;o.dirty<this.dirty&&(o.dirty=this.dirty),this.dirty=Qe}}slice(e,t,o){let r=xn.create(this.parent,this.mark,!0,o),s=this.children,i=this.size;t<i&&(s=Ui(s,t,i,o)),e>0&&(s=Ui(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 Kt extends _o{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}=gn.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=du(u,o,t),d?c=new _y(e,t,o,r,u,f||null,h,d,s,i+1):t.isText?new Ar(e,t,o,r,u,h,s):new Kt(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=()=>O.empty)}return e}matchesNode(e,t,o){return this.dirty==Qe&&e.eq(this.node)&&Nr(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 Py(this,i&&i.node,e);Vy(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?te.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==Sn)&&(i&&this.protectLocalComposition(e,i),au(this.contentDOM,this.children,e),Yn&&$y(this.dom))}localCompositionInfo(e,t){let{from:o,to:r}=e.state.selection;if(!(e.state.selection instanceof Y)||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=zy(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 Oy(this,s,t,r);e.input.compositionNodes.push(i),this.children=Ui(this.children,o,o+r.length,e,i)}update(e,t,o,r){return this.dirty==ht||!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=Qe}updateOuterDeco(e){if(Nr(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,o=this.dom;this.dom=cu(this.dom,this.nodeDOM,ji(this.outerDeco,this.node,t),ji(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 iu(n,e,t,o,r){du(o,e,n);let s=new Kt(void 0,n,e,t,o,o,o,r,0);return s.contentDOM&&s.updateChildren(r,0),s}class Ar extends Kt{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==ht||this.dirty!=Qe&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Qe||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=Qe,!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 Ar(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=ht)}get domAtom(){return!1}isText(e){return this.node.text==e}}class lu extends _o{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Qe&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class _y extends Kt{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==ht)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 au(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=uu(o),r=!0;o=o.nextSibling}else r=!0,n.insertBefore(l,o);if(i instanceof xn){let c=o?o.previousSibling:n.lastChild;au(i.contentDOM,i.children,t),o=c?c.nextSibling:n.firstChild}}for(;o;)o=uu(o),r=!0;r&&t.trackWrites==n&&(t.trackWrites=null)}const Ro=function(n){n&&(this.nodeName=n)};Ro.prototype=Object.create(null);const Cn=[new Ro];function ji(n,e,t){if(n.length==0)return Cn;let o=t?Cn[0]:new Ro,r=[o];for(let s=0;s<n.length;s++){let i=n[s].type.attrs;if(i){i.nodeName&&r.push(o=new Ro(i.nodeName));for(let l in i){let c=i[l];c!=null&&(t&&r.length==1&&r.push(o=new Ro(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 cu(n,e,t,o){if(t==Cn&&o==Cn)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=Cn[0]),r=c}Ry(r,l||Cn[0],i)}return r}function Ry(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 du(n,e,t){return cu(n,n,Cn,ji(e,t,n.nodeType!=1))}function Nr(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 uu(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class Py{constructor(e,t,o){this.lock=t,this.view=o,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=Dy(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=Qe,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=xn.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==ht&&i.dom==i.contentDOM&&(i.dirty=Sn),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 Kt){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!=ht&&Nr(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=Sn,f.updateChildren(r,i+1),f.dirty=Qe),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)||!Nr(o,e.outerDeco)||!r.eq(e.innerDeco))return null;let l=Kt.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=Kt.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 su(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 xn;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof Ar)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((_e||ve)&&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 lu(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 Dy(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 xn)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 Ly(n,e){return n.type.side-e.type.side}function Vy(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(Ly);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 $y(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 zy(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 Ui(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 Wi(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(Mr(t)){for(c=i;r&&!r.node;)r=r.parent;let f=r.node;if(r&&f.isAtom&&q.isSelectable(f)&&r.parent&&!(f.isInline&&hy(t.focusNode,t.focusOffset,r.dom))){let h=r.posBefore;d=new q(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=qi(n,u,l,f)}return d}function fu(n){return n.editable?n.hasFocus():wu(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function At(n,e=!1){let t=n.state.selection;if(gu(n,t),!!fu(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&ve){let o=n.domSelectionRange(),r=n.domObserver.currentSelection;if(o.anchorNode&&r.anchorNode&&wn(o.anchorNode,o.anchorOffset,r.anchorNode,r.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)Hy(n);else{let{anchor:o,head:r}=t,s,i;hu&&!(t instanceof Y)&&(t.$from.parent.inlineContent||(s=pu(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(i=pu(n,t.to))),n.docView.setSelection(o,r,n,e),hu&&(s&&mu(s),i&&mu(i)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&Fy(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const hu=_e||ve&&Wd<63;function pu(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(_e&&r&&r.contentEditable=="false")return Ki(r);if((!r||r.contentEditable=="false")&&(!s||s.contentEditable=="false")){if(r)return Ki(r);if(s)return Ki(s)}}function Ki(n){return n.contentEditable="true",_e&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function mu(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function Fy(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(()=>{(!fu(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Hy(n){let e=n.domSelection();if(!e)return;let t=n.cursorWrapper.dom,o=t.nodeName=="IMG";o?e.collapse(t.parentNode,Ee(t)+1):e.collapse(t,0),!o&&!n.state.selection.visible&&$e&&Ut<=11&&(t.disabled=!0,t.disabled=!1)}function gu(n,e){if(e instanceof q){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(yu(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else yu(n)}function yu(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function qi(n,e,t,o){return n.someProp("createSelectionBetween",r=>r(n,e,t))||Y.between(e,t,o)}function ku(n){return n.editable&&!n.hasFocus()?!1:wu(n)}function wu(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 jy(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return wn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Gi(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&&Z.findFrom(s,e)}function qt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function bu(n,e,t){let o=n.state.selection;if(o instanceof Y)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 qt(n,new Y(o.$anchor,i))}else if(o.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let r=Gi(n.state,e);return r&&r instanceof q?qt(n,r):!1}else if(!(Xe&&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?q.isSelectable(s)?qt(n,new q(e<0?n.state.doc.resolve(r.pos-s.nodeSize):r)):Io?qt(n,new Y(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(o instanceof q&&o.node.isInline)return qt(n,new Y(e>0?o.$to:o.$from));{let r=Gi(n.state,e);return r?qt(n,r):!1}}}function Br(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Po(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Qn(n,e){return e<0?Uy(n):Wy(n)}function Uy(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r,s,i=!1;for(Ye&&t.nodeType==1&&o<Br(t)&&Po(t.childNodes[o],-1)&&(i=!0);;)if(o>0){if(t.nodeType!=1)break;{let l=t.childNodes[o-1];if(Po(l,-1))r=t,s=--o;else if(l.nodeType==3)t=l,o=t.nodeValue.length;else break}}else{if(Su(t))break;{let l=t.previousSibling;for(;l&&Po(l,-1);)r=t.parentNode,s=Ee(l),l=l.previousSibling;if(l)t=l,o=Br(t);else{if(t=t.parentNode,t==n.dom)break;o=0}}}i?Ji(n,t,o):r&&Ji(n,r,s)}function Wy(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r=Br(t),s,i;for(;;)if(o<r){if(t.nodeType!=1)break;let l=t.childNodes[o];if(Po(l,1))s=t,i=++o;else break}else{if(Su(t))break;{let l=t.nextSibling;for(;l&&Po(l,1);)s=l.parentNode,i=Ee(l)+1,l=l.nextSibling;if(l)t=l,o=0,r=Br(t);else{if(t=t.parentNode,t==n.dom)break;o=r=0}}}s&&Ji(n,s,i)}function Su(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function Ky(n,e){for(;n&&e==n.childNodes.length&&!Bo(n);)e=Ee(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 qy(n,e){for(;n&&!e&&!Bo(n);)e=Ee(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 Ji(n,e,t){if(e.nodeType!=3){let s,i;(i=Ky(e,t))?(e=i,t=0):(s=qy(e,t))&&(e=s,t=s.nodeValue.length)}let o=n.domSelection();if(!o)return;if(Mr(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&&At(n)},50)}function xu(n,e){let t=n.state.doc.resolve(e);if(!(ve||Kd)&&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 Cu(n,e,t){let o=n.state.selection;if(o instanceof Y&&!o.empty||t.indexOf("s")>-1||Xe&&t.indexOf("m")>-1)return!1;let{$from:r,$to:s}=o;if(!r.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let i=Gi(n.state,e);if(i&&i instanceof q)return qt(n,i)}if(!r.parent.inlineContent){let i=e<0?r:s,l=o instanceof We?Z.near(i,e):Z.findFrom(i,e);return l?qt(n,l):!1}return!1}function Eu(n,e){if(!(n.state.selection instanceof Y))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 vu(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Gy(n){if(!_e||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;vu(n,o,"true"),setTimeout(()=>vu(n,o,"false"),20)}return!1}function Jy(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Yy(n,e){let t=e.keyCode,o=Jy(e);if(t==8||Xe&&t==72&&o=="c")return Eu(n,-1)||Qn(n,-1);if(t==46&&!e.shiftKey||Xe&&t==68&&o=="c")return Eu(n,1)||Qn(n,1);if(t==13||t==27)return!0;if(t==37||Xe&&t==66&&o=="c"){let r=t==37?xu(n,n.state.selection.from)=="ltr"?-1:1:-1;return bu(n,r,o)||Qn(n,r)}else if(t==39||Xe&&t==70&&o=="c"){let r=t==39?xu(n,n.state.selection.from)=="ltr"?1:-1:1;return bu(n,r,o)||Qn(n,r)}else{if(t==38||Xe&&t==80&&o=="c")return Cu(n,-1,o)||Qn(n,-1);if(t==40||Xe&&t==78&&o=="c")return Gy(n)||Cu(n,1,o)||Qn(n,1);if(o==(Xe?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Yi(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")||gn.fromSchema(n.state.schema),l=_u(),c=l.createElement("div");c.appendChild(i.serializeFragment(o,{document:l}));let d=c.firstChild,u,f=0;for(;d&&d.nodeType==1&&(u=Iu[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
+
9
+ `);return{dom:c,text:h,slice:e}}function Tu(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 $(O.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=gn.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=e1(t),Io&&t1(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")||Hn.fromSchema(n.state.schema)).parseSlice(i,{preserveWhitespace:!!(c||u),context:r,ruleFromNode(h){return h.nodeName=="BR"&&!h.nextSibling&&h.parentNode&&!Xy.test(h.parentNode.nodeName)?{ignore:!0}:null}})),u)l=n1(Bu(l,+u[1],+u[2]),u[4]);else if(l=$.maxOpen(Qy(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=Bu(l,f,h)}return n.someProp("transformPasted",f=>{l=f(l,n,c)}),l}const Xy=/^(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 Qy(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&&Au(c,s,l,i[i.length-1],0))i[i.length-1]=d;else{i.length&&(i[i.length-1]=Nu(i[i.length-1],s.length));let u=Mu(l,c);i.push(u),r=r.matchType(u.type),s=c}}),i)return O.from(i)}return n}function Mu(n,e,t=0){for(let o=e.length-1;o>=t;o--)n=e[o].create(null,O.from(n));return n}function Au(n,e,t,o,r){if(r<n.length&&r<e.length&&n[r]==e[r]){let s=Au(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(O.from(Mu(t,n,r+1))))}}function Nu(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,Nu(n.lastChild,e-1)),o=n.contentMatchAt(n.childCount).fillBefore(O.empty,!0);return n.copy(t.append(o))}function Xi(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=Xi(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(O.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,i.copy(l))}function Bu(n,e,t){return e<n.openStart&&(n=new $(Xi(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new $(Xi(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const Iu={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 Ou=null;function _u(){return Ou||(Ou=document.implementation.createHTMLDocument("title"))}let Qi=null;function Zy(n){let e=window.trustedTypes;return e?(Qi||(Qi=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),Qi.createHTML(n)):n}function e1(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=_u().createElement("div"),o=/<([a-z][^>\s]+)/i.exec(n),r;if((r=o&&Iu[o[1].toLowerCase()])&&(n=r.map(s=>"<"+s+">").join("")+n+r.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=Zy(n),r)for(let s=0;s<r.length;s++)t=t.querySelector(r[s])||t;return t}function t1(n){let e=n.querySelectorAll(ve?"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 n1(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=O.from(c.create(o[l+1],r)),s++,i++}return new $(r,s,i)}const Pe={},De={},o1={touchstart:!0,touchmove:!0};class r1{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 s1(n){for(let e in Pe){let t=Pe[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=o=>{l1(n,o)&&!el(n,o)&&(n.editable||!(o.type in De))&&t(n,o)},o1[e]?{passive:!0}:void 0)}_e&&n.dom.addEventListener("input",()=>null),Zi(n)}function Gt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function i1(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 Zi(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=o=>el(n,o))})}function el(n,e){return n.someProp("handleDOMEvents",t=>{let o=t[e.type];return o?o(n,e)||e.defaultPrevented:!1})}function l1(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 a1(n,e){!el(n,e)&&Pe[e.type]&&(n.editable||!(e.type in De))&&Pe[e.type](n,e)}De.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Pu(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Tt&&ve&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),Yn&&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,bn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",o=>o(n,t))||Yy(n,t)?t.preventDefault():Gt(n,"key")},De.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)},De.keypress=(n,e)=>{let t=e;if(Pu(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Xe&&t.metaKey)return;if(n.someProp("handleKeyPress",r=>r(n,t))){t.preventDefault();return}let o=n.state.selection;if(!(o instanceof Y)||!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 Ir(n){return{left:n.clientX,top:n.clientY}}function c1(n,e){let t=e.x-n.clientX,o=e.y-n.clientY;return t*t+o*o<100}function tl(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 Zn(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 d1(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),o=t.nodeAfter;return o&&o.isAtom&&q.isSelectable(o)?(Zn(n,new q(t)),!0):!1}function u1(n,e){if(e==-1)return!1;let t=n.state.selection,o,r;t instanceof q&&(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(q.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?(Zn(n,q.create(n.state.doc,r)),!0):!1}function f1(n,e,t,o,r){return tl(n,"handleClickOn",e,t,o)||n.someProp("handleClick",s=>s(n,e,o))||(r?u1(n,t):d1(n,t))}function h1(n,e,t,o){return tl(n,"handleDoubleClickOn",e,t,o)||n.someProp("handleDoubleClick",r=>r(n,e,o))}function p1(n,e,t,o){return tl(n,"handleTripleClickOn",e,t,o)||n.someProp("handleTripleClick",r=>r(n,e,o))||m1(n,t,o)}function m1(n,e,t){if(t.button!=0)return!1;let o=n.state.doc;if(e==-1)return o.inlineContent?(Zn(n,Y.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)Zn(n,Y.create(o,l+1,l+1+i.content.size));else if(q.isSelectable(i))Zn(n,q.create(o,l));else continue;return!0}}function nl(n){return Or(n)}const Ru=Xe?"metaKey":"ctrlKey";Pe.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let o=nl(n),r=Date.now(),s="singleClick";r-n.input.lastClick.time<500&&c1(t,n.input.lastClick)&&!t[Ru]&&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(Ir(t));i&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new g1(n,i,t,!!o)):(s=="doubleClick"?h1:p1)(n,i.pos,i.inside,t)?t.preventDefault():Gt(n,"pointer"))};class g1{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[Ru],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 q&&d.from<=i&&d.to>i)&&(this.mightDrag={node:s,pos:i,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&Ye&&!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)),Gt(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(()=>At(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(Ir(e))),this.updateAllowDefault(e),this.allowDefault||!t?Gt(this.view,"pointer"):f1(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||_e&&this.mightDrag&&!this.mightDrag.node.isAtom||ve&&!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)?(Zn(this.view,Z.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Gt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Gt(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)}}Pe.touchstart=n=>{n.input.lastTouch=Date.now(),nl(n),Gt(n,"pointer")},Pe.touchmove=n=>{n.input.lastTouch=Date.now(),Gt(n,"pointer")},Pe.contextmenu=n=>nl(n);function Pu(n,e){return n.composing?!0:_e&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const y1=Tt?5e3:-1;De.compositionstart=De.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof Y&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(o=>o.type.spec.inclusive===!1)||ve&&Kd&&k1(n)))n.markCursor=n.state.storedMarks||t.marks(),Or(n,!0),n.markCursor=null;else if(Or(n,!e.selection.empty),Ye&&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}Du(n,y1)};function k1(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"}De.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++,Du(n,20))};function Du(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Or(n),e))}function Lu(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=b1());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function w1(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=uy(e.focusNode,e.focusOffset),o=fy(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 b1(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function Or(n,e=!1){if(!(Tt&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Lu(n),e||n.docView&&n.docView.dirty){let t=Wi(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 S1(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 Do=$e&&Ut<15||Yn&&gy<604;Pe.copy=De.cut=(n,e)=>{let t=e,o=n.state.selection,r=t.type=="cut";if(o.empty)return;let s=Do?null:t.clipboardData,i=o.content(),{dom:l,text:c}=Yi(n,i);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):S1(n,l),r&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function x1(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function C1(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?Lo(n,o.value,null,r,e):Lo(n,o.textContent,o.innerHTML,r,e)},50)}function Lo(n,e,t,o,r){let s=Tu(n,e,t,o,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,r,s||$.empty)))return!0;if(!s)return!1;let i=x1(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 Vu(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," "):""}De.paste=(n,e)=>{let t=e;if(n.composing&&!Tt)return;let o=Do?null:t.clipboardData,r=n.input.shiftKey&&n.input.lastKeyCode!=45;o&&Lo(n,Vu(o),o.getData("text/html"),r,t)?t.preventDefault():C1(n,t)};class $u{constructor(e,t,o){this.slice=e,this.move=t,this.node=o}}const E1=Xe?"altKey":"ctrlKey";function zu(n,e){let t=n.someProp("dragCopies",o=>!o(e));return t??!e[E1]}Pe.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(Ir(t)),i;if(!(s&&s.pos>=r.from&&s.pos<=(r instanceof q?r.to-1:r.to))){if(o&&o.mightDrag)i=q.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=q.create(n.state.doc,f.posBefore))}}let l=(i||n.state.selection).content(),{dom:c,text:d,slice:u}=Yi(n,l);(!t.dataTransfer.files.length||!ve||Wd>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Do?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",Do||t.dataTransfer.setData("text/plain",d),n.dragging=new $u(u,zu(n,t),i)},Pe.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)},De.dragover=De.dragenter=(n,e)=>e.preventDefault(),De.drop=(n,e)=>{try{v1(n,e,n.dragging)}finally{n.dragging=null}};function v1(n,e,t){if(!e.dataTransfer)return;let o=n.posAtCoords(Ir(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=Tu(n,Vu(e.dataTransfer),Do?null:e.dataTransfer.getData("text/html"),!1,r);let i=!!(t&&zu(n,e));if(n.someProp("handleDrop",p=>p(n,e,s||$.empty,i))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?md(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&&q.isSelectable(s.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new q(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(qi(n,h,c.doc.resolve(p)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))}Pe.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())&&At(n)},20))},Pe.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)},Pe.beforeinput=(n,e)=>{if(ve&&Tt&&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,bn(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 De)Pe[n]=De[n];function Vo(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 _r{constructor(e,t){this.toDOM=e,this.spec=t||En,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 Le(s-o,s-o,this)}valid(){return!0}eq(e){return this==e||e instanceof _r&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Vo(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Jt{constructor(e,t){this.attrs=e,this.spec=t||En}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 Le(s,i,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof Jt&&Vo(this.attrs,e.attrs)&&Vo(this.spec,e.spec)}static is(e){return e.type instanceof Jt}destroy(){}}class ol{constructor(e,t){this.attrs=e,this.spec=t||En}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 Le(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 ol&&Vo(this.attrs,e.attrs)&&Vo(this.spec,e.spec)}destroy(){}}class Le{constructor(e,t,o){this.from=e,this.to=t,this.type=o}copy(e,t){return new Le(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 Le(e,e,new _r(t,o))}static inline(e,t,o,r){return new Le(e,t,new Jt(o,r))}static node(e,t,o,r){return new Le(e,t,new ol(o,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof Jt}get widget(){return this.type instanceof _r}}const eo=[],En={};class ae{constructor(e,t){this.local=e.length?e:eo,this.children=t.length?t:eo}static create(e,t){return t.length?Rr(t,e,0,En):Re}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==Re||e.maps.length==0?this:this.mapInner(e,t,0,0,o||En)}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?T1(this.children,i||[],e,t,o,r,s):i?new ae(i.sort(vn),eo):Re}add(e,t){return t.length?this==Re?ae.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=Hu(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,Rr(u,l,d+1,En)),s+=3}});let i=Fu(s?ju(t):t,-o);for(let l=0;l<i.length;l++)i[l].type.valid(e,i[l])||i.splice(l--,1);return new ae(i.length?this.local.concat(i).sort(vn):this.local,r||this.children)}remove(e){return e.length==0||this==Re?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!=Re?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 ae(r,o):Re}forChild(e,t){if(this==Re)return this;if(t.isLeaf)return ae.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 Jt){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 ae(r.sort(vn),eo);return o?new Yt([l,o]):l}return o||Re}eq(e){if(this==e)return!0;if(!(e instanceof ae)||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 rl(this.localsInner(e))}localsInner(e){if(this==Re)return eo;if(e.inlineContent||!this.local.some(Jt.is))return this.local;let t=[];for(let o=0;o<this.local.length;o++)this.local[o].type instanceof Jt||t.push(this.local[o]);return t}forEachSet(e){e(this)}}ae.empty=new ae([],[]),ae.removeOverlap=rl;const Re=ae.empty;class Yt{constructor(e){this.members=e}map(e,t){const o=this.members.map(r=>r.map(e,t,En));return Yt.from(o)}forChild(e,t){if(t.isLeaf)return ae.empty;let o=[];for(let r=0;r<this.members.length;r++){let s=this.members[r].forChild(e,t);s!=Re&&(s instanceof Yt?o=o.concat(s.members):o.push(s))}return Yt.from(o)}eq(e){if(!(e instanceof Yt)||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?rl(o?t:t.sort(vn)):eo}static from(e){switch(e.length){case 0:return Re;case 1:return e[0];default:return new Yt(e.every(t=>t instanceof ae)?e:e.reduce((t,o)=>t.concat(o instanceof ae?o:o.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}}function T1(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 b=l[k+1];if(b<0||h>b+u-f)continue;let S=l[k]+u-f;p>=S?l[k+1]=h<=S?-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!=Re?(l[d]=f,l[d+1]=p,l[d+2]=k):(l[d+1]=-2,c=!0)}else c=!0}if(c){let d=M1(l,n,e,t,r,s,i),u=Rr(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 ae(e.sort(vn),l)}function Fu(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 Le(r.from+e,r.to+e,r.type))}return t}function M1(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 Hu(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 ju(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function Rr(n,e,t,o){let r=[],s=!1;e.forEach((l,c)=>{let d=Hu(n,l,c+t);if(d){s=!0;let u=Rr(d,l,t+c+1,o);u!=Re&&r.push(c,c+l.nodeSize,u)}});let i=Fu(s?ju(n):n,-t).sort(vn);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 ae(i,r):Re}function vn(n,e){return n.from-e.from||n.to-e.to}function rl(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),Uu(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),Uu(e,r,o.copy(s.from,o.to)));break}}}return e}function Uu(n,e,t){for(;e<n.length&&vn(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!=Re&&e.push(o)}),n.cursorWrapper&&e.push(ae.create(n.state.doc,[n.cursorWrapper.deco])),Yt.from(e)}const A1={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},N1=$e&&Ut<=11;class B1{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 I1{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new B1,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]);$e&&Ut<=11&&o.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():_e&&e.composing&&o.some(r=>r.type=="childList"&&r.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),N1&&(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,A1)),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(ku(this.view)){if(this.suppressingSelectionUpdates)return At(this.view);if($e&&Ut<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&wn(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=Jn(s))t.add(s);for(let s=e.anchorNode;s;s=Jn(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)&&ku(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(Ye&&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||R1(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&&Mr(o)&&(d=Wi(e))&&d.eq(Z.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,At(e),this.currentSelection.set(o),e.scrollToSelection()):(s>-1||r)&&(s>-1&&(e.docView.markDirty(s,i),O1(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,P1(e,c)),this.handleDOMChange(s,i,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(o)||At(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($e&&Ut<=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?Ee(r)+1:0,l=o.localPosFromDOM(e.target,i,-1),c=s&&s.parentNode==e.target?Ee(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 Wu=new WeakMap,Ku=!1;function O1(n){if(!Wu.has(n)&&(Wu.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=Ye,Ku)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."),Ku=!0}}function qu(n,e){let t=e.startContainer,o=e.startOffset,r=e.endContainer,s=e.endOffset,i=n.domAtPos(n.state.selection.anchor);return wn(i.node,i.offset,r,s)&&([t,o,r,s]=[r,s,t,o]),{anchorNode:t,anchorOffset:o,focusNode:r,focusOffset:s}}function _1(n,e){if(e.getComposedRanges){let r=e.getComposedRanges(n.root)[0];if(r)return qu(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?qu(n,t):null}function R1(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 P1(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 D1(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}],Mr(c)||d.push({node:c.focusNode,offset:c.focusOffset})),ve&&n.input.lastKeyCode===8)for(let y=s;y>r;y--){let k=o.childNodes[y-1],b=k.pmViewDesc;if(k.nodeName=="BR"&&!b){s=y;break}if(!b||b.size)break}let f=n.state.doc,h=n.someProp("domParser")||Hn.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:L1,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 L1(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(_e&&/^(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||_e&&/^(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 V1=/^(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 $1(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=Wi(n,E);if(M&&!n.state.selection.eq(M)){if(ve&&Tt&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",B=>B(n,bn(13,"Enter"))))return;let v=n.state.tr.setSelection(M);E=="pointer"?v.setMeta("pointer",!0):E=="key"&&v.scrollIntoView(),s&&v.setMeta("composition",s),n.dispatch(v)}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=D1(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=H1(f.content,d.doc.content,d.from,h,p);if(m&&n.input.domChangeCount++,(Yn&&n.input.lastIOSEnter>Date.now()-225||Tt)&&r.some(E=>E.nodeType==1&&!V1.test(E.nodeName))&&(!m||m.endA>=m.endB)&&n.someProp("handleKeyDown",E=>E(n,bn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!m)if(o&&c instanceof Y&&!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=Gu(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 Y&&(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)),$e&&Ut<=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),b=g.sameParent(y)&&g.parent.inlineContent&&k.end()>=m.endA;if((Yn&&n.input.lastIOSEnter>Date.now()-225&&(!b||r.some(E=>E.nodeName=="DIV"||E.nodeName=="P"))||!b&&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,bn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>m.start&&F1(u,m.start,m.endA,g,y)&&n.someProp("handleKeyDown",E=>E(n,bn(8,"Backspace")))){Tt&&ve&&n.domObserver.suppressSelectionUpdates();return}ve&&m.endB==m.start&&(n.input.lastChromeDelete=Date.now()),Tt&&!b&&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,bn(13,"Enter"))})},20));let S=m.start,x=m.endA,C=E=>{let M=E||n.state.tr.replace(S,x,d.doc.slice(m.start-d.from,m.endB-d.from));if(d.sel){let v=Gu(n,M.doc,d.sel);v&&!(ve&&n.composing&&v.empty&&(m.start!=m.endB||n.input.lastChromeDelete<Date.now()-100)&&(v.head==S||v.head==M.mapping.map(x)-1)||$e&&v.empty&&v.head==S)&&M.setSelection(v)}return s&&M.setMeta("composition",s),M.scrollIntoView()},T;if(b)if(g.pos==y.pos){$e&&Ut<=11&&g.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>At(n),20));let E=C(n.state.tr.delete(S,x)),M=u.resolve(m.start).marksAcross(u.resolve(m.endA));M&&E.ensureMarks(M),n.dispatch(E)}else if(m.endA==m.endB&&(T=z1(g.parent.content.cut(g.parentOffset,y.parentOffset),k.parent.content.cut(k.parentOffset,m.endA-k.start())))){let E=C(n.state.tr);T.type=="add"?E.addMark(S,x,T.mark):E.removeMark(S,x,T.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,S,x));n.someProp("handleTextInput",v=>v(n,S,x,E,M))||n.dispatch(M())}else n.dispatch(C());else n.dispatch(C())}function Gu(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:qi(n,e.resolve(t.anchor),e.resolve(t.head))}function z1(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(O.from(d).eq(n))return{mark:l,type:i}}function F1(n,e,t,o,r){if(t-e<=r.pos-o.pos||il(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(il(s,!0,!0));return!i.parent.isTextblock||i.pos>t||il(i,!0,!1)<t?!1:o.parent.content.cut(o.parentOffset).eq(i.parent.content)}function il(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 H1(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&&Ju(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&&Ju(n.textBetween(s-1,s+1))&&(s+=c?1:-1),i=s+(i-l),l=s}return{start:s,endA:i,endB:l}}function Ju(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 Yu{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 r1,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(tf),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=Zu(this),Qu(this),this.nodeViews=ef(this),this.docView=iu(this.state.doc,Xu(this),sl(this),this.dom,this),this.domObserver=new I1(this,(o,r,s,i)=>$1(this,o,r,s,i)),this.domObserver.start(),s1(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&&Zi(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(tf),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&&(Lu(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);U1(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Zi(this),this.editable=Zu(this),Qu(this);let c=sl(this),d=Xu(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&&wy(this);if(i){this.domObserver.stop();let p=f&&($e||ve)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&j1(r.selection,e.selection);if(f){let m=ve?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=w1(this)),(s||!this.docView.update(e.doc,d,c,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=iu(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())&&jy(this))?At(this,p):(gu(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&&by(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 q){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&qd(this,t.getBoundingClientRect(),e)}else qd(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 $u(e.slice,e.move,r<0?void 0:q.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($e){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&&Sy(this.dom),At(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 Ty(this,e)}coordsAtPos(e,t=1){return Zd(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 Iy(this,t||this.state,e)}pasteHTML(e,t){return Lo(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Lo(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return Yi(this,e)}destroy(){this.docView&&(i1(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,cy())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return a1(this,e)}domSelectionRange(){let e=this.domSelection();return e?_e&&this.root.nodeType===11&&py(this.dom.ownerDocument)==this.dom&&_1(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}Yu.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function Xu(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"),[Le.node(0,n.state.doc.content.size,e)]}function Qu(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:Le.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Zu(n){return!n.someProp("editable",e=>e(n.state)===!1)}function j1(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 U1(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 tf(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 Xt={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:"'"},Pr={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},W1=typeof navigator<"u"&&/Mac/.test(navigator.platform),K1=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Te=0;Te<10;Te++)Xt[48+Te]=Xt[96+Te]=String(Te);for(var Te=1;Te<=24;Te++)Xt[Te+111]="F"+Te;for(var Te=65;Te<=90;Te++)Xt[Te]=String.fromCharCode(Te+32),Pr[Te]=String.fromCharCode(Te);for(var ll in Xt)Pr.hasOwnProperty(ll)||(Pr[ll]=Xt[ll]);function q1(n){var e=W1&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||K1&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Pr:Xt)[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 G1=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),J1=typeof navigator<"u"&&/Win/.test(navigator.platform);function Y1(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))G1?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 X1(n){let e=Object.create(null);for(let t in n)e[Y1(t)]=n[t];return e}function al(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 Q1(n){return new ue({props:{handleKeyDown:nf(n)}})}function nf(n){let e=X1(n);return function(t,o){let r=q1(o),s,i=e[al(r,o)];if(i&&i(t.state,t.dispatch,t))return!0;if(r.length==1&&r!=" "){if(o.shiftKey){let l=e[al(r,o,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((o.altKey||o.metaKey||o.ctrlKey)&&!(J1&&o.ctrlKey&&o.altKey)&&(s=Xt[o.keyCode])&&s!=r){let l=e[al(s,o)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var Z1=Object.defineProperty,cl=(n,e)=>{for(var t in e)Z1(n,t,{get:e[t],enumerable:!0})};function Dr(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 Lr=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:Dr({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}},of={};cl(of,{blur:()=>ek,clearContent:()=>tk,clearNodes:()=>nk,command:()=>ok,createParagraphNear:()=>rk,cut:()=>sk,deleteCurrentNode:()=>ik,deleteNode:()=>lk,deleteRange:()=>ak,deleteSelection:()=>ck,enter:()=>dk,exitCode:()=>uk,extendMarkRange:()=>fk,first:()=>hk,focus:()=>mk,forEach:()=>gk,insertContent:()=>yk,insertContentAt:()=>bk,joinBackward:()=>Ck,joinDown:()=>xk,joinForward:()=>Ek,joinItemBackward:()=>vk,joinItemForward:()=>Tk,joinTextblockBackward:()=>Mk,joinTextblockForward:()=>Ak,joinUp:()=>Sk,keyboardShortcut:()=>Bk,lift:()=>Ik,liftEmptyBlock:()=>Ok,liftListItem:()=>_k,newlineInCode:()=>Rk,resetAttributes:()=>Pk,scrollIntoView:()=>Dk,selectAll:()=>Lk,selectNodeBackward:()=>Vk,selectNodeForward:()=>$k,selectParentNode:()=>zk,selectTextblockEnd:()=>Fk,selectTextblockStart:()=>Hk,setContent:()=>jk,setMark:()=>iw,setMeta:()=>lw,setNode:()=>aw,setNodeSelection:()=>cw,setTextDirection:()=>dw,setTextSelection:()=>uw,sinkListItem:()=>fw,splitBlock:()=>hw,splitListItem:()=>pw,toggleList:()=>mw,toggleMark:()=>gw,toggleNode:()=>yw,toggleWrap:()=>kw,undoInputRule:()=>ww,unsetAllMarks:()=>bw,unsetMark:()=>Sw,unsetTextDirection:()=>xw,updateAttributes:()=>Cw,wrapIn:()=>Ew,wrapInList:()=>vw});var ek=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())==null||t.removeAllRanges())}),!0),tk=(n=!0)=>({commands:e})=>e.setContent("",{emitUpdate:n}),nk=()=>({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=jn(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},ok=n=>e=>n(e),rk=()=>({state:n,dispatch:e})=>Ld(n,e),sk=(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 Y(o.doc.resolve(Math.max(i-1,0)))),!0},ik=()=>({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 we(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 lk=n=>({tr:e,state:t,dispatch:o})=>{const r=we(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},ak=n=>({tr:e,dispatch:t})=>{const{from:o,to:r}=n;return t&&e.delete(o,r),!0},ck=()=>({state:n,dispatch:e})=>Oi(n,e),dk=()=>({commands:n})=>n.keyboardShortcut("Enter"),uk=()=>({state:n,dispatch:e})=>G0(n,e);function dl(n){return Object.prototype.toString.call(n)==="[object RegExp]"}function Vr(n,e,t={strict:!0}){const o=Object.keys(e);return o.length?o.every(r=>t.strict?e[r]===n[r]:dl(e[r])?e[r].test(n[r]):e[r]===n[r]):!0}function rf(n,e,t={}){return n.find(o=>o.type===e&&Vr(Object.fromEntries(Object.keys(t).map(r=>[r,o.attrs[r]])),t))}function sf(n,e,t={}){return!!rf(n,e,t)}function ul(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),!rf([...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&&sf([...n.parent.child(i-1).marks],e,t);)i-=1,l-=n.parent.child(i).nodeSize;for(;c<n.parent.childCount&&sf([...n.parent.child(c).marks],e,t);)d+=n.parent.child(c).nodeSize,c+=1;return{from:l,to:d}}function Nt(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 fk=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const s=Nt(n,o.schema),{doc:i,selection:l}=t,{$from:c,from:d,to:u}=l;if(r){const f=ul(c,s,e);if(f&&f.from<=d&&f.to>=u){const h=Y.create(i,f.from,f.to);t.setSelection(h)}}return!0},hk=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 lf(n){return n instanceof Y}function Tn(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function af(n,e=null){if(!e)return null;const t=Z.atStart(n),o=Z.atEnd(n);if(e==="start"||e===!0)return t;if(e==="end")return o;const r=t.from,s=o.to;return e==="all"?Y.create(n,Tn(0,r,s),Tn(n.content.size,r,s)):Y.create(n,Tn(e,r,s),Tn(e,r,s))}function cf(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function $r(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}function pk(){return typeof navigator<"u"?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var mk=(n=null,e={})=>({editor:t,view:o,tr:r,dispatch:s})=>{e={scrollIntoView:!0,...e};const i=()=>{($r()||cf())&&o.dom.focus(),pk()&&!$r()&&!cf()&&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&&!lf(t.state.selection))return i(),!0;const l=af(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},gk=(n,e)=>t=>n.every((o,r)=>e(o,{...t,index:r})),yk=(n,e)=>({tr:t,commands:o})=>o.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),df=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&&df(o)}return n};function $o(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 df(t)}function zo(n,e,t){if(n instanceof Ct||n instanceof O)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 O.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),zo("",e,t)}if(r){if(t.errorOnInvalidContent){let i=!1,l="";const c=new Gc({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?Hn.fromSchema(c).parseSlice($o(n),t.parseOptions):Hn.fromSchema(c).parse($o(n),t.parseOptions),t.errorOnInvalidContent&&i)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=Hn.fromSchema(e);return t.slice?s.parseSlice($o(n),t.parseOptions).content:s.parse($o(n),t.parseOptions)}return zo("",e,t)}function kk(n,e,t){const o=n.steps.length-1;if(o<e)return;const r=n.steps[o];if(!(r instanceof ge||r instanceof ye))return;const s=n.mapping.maps[o];let i=0;s.forEach((l,c,d,u)=>{i===0&&(i=u)}),n.setSelection(Z.near(n.doc.resolve(i),t))}var wk=n=>!("type"in n),bk=(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{zo(e,s.schema,{parseOptions:d,errorOnInvalidContent:!0})}catch(y){c(y)}try{l=zo(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((wk(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 O){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(),b=y.parentOffset===0,S=k.isText||k.isTextblock,x=k.content.size>0;b&&S&&x&&(u=Math.max(0,u-1)),o.replaceWith(u,f,g)}t.updateSelection&&kk(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},Sk=()=>({state:n,dispatch:e})=>W0(n,e),xk=()=>({state:n,dispatch:e})=>K0(n,e),Ck=()=>({state:n,dispatch:e})=>Bd(n,e),Ek=()=>({state:n,dispatch:e})=>Rd(n,e),vk=()=>({state:n,dispatch:e,tr:t})=>{try{const o=Cr(n.doc,n.selection.$from.pos,-1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},Tk=()=>({state:n,dispatch:e,tr:t})=>{try{const o=Cr(n.doc,n.selection.$from.pos,1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},Mk=()=>({state:n,dispatch:e})=>j0(n,e),Ak=()=>({state:n,dispatch:e})=>U0(n,e);function uf(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function Nk(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))$r()||uf()?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 Bk=n=>({editor:e,view:t,tr:o,dispatch:r})=>{const s=Nk(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 Fo(n,e,t={}){const{from:o,to:r,empty:s}=n.selection,i=e?we(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=>Vr(f.node.attrs,t,{strict:!1}));return s?!!d.length:d.reduce((f,h)=>f+h.to-h.from,0)>=c}var Ik=(n,e={})=>({state:t,dispatch:o})=>{const r=we(n,t.schema);return Fo(t,r,e)?q0(t,o):!1},Ok=()=>({state:n,dispatch:e})=>Vd(n,e),_k=n=>({state:e,dispatch:t})=>{const o=we(n,e.schema);return sy(o)(e,t)},Rk=()=>({state:n,dispatch:e})=>Dd(n,e);function zr(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function ff(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 Pk=(n,e)=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=zr(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=we(n,o.schema)),l==="mark"&&(i=Nt(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,ff(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(ff(h.attrs,e))))})})}),c},Dk=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),Lk=()=>({tr:n,dispatch:e})=>{if(e){const t=new We(n.doc);n.setSelection(t)}return!0},Vk=()=>({state:n,dispatch:e})=>Od(n,e),$k=()=>({state:n,dispatch:e})=>Pd(n,e),zk=()=>({state:n,dispatch:e})=>X0(n,e),Fk=()=>({state:n,dispatch:e})=>ey(n,e),Hk=()=>({state:n,dispatch:e})=>Z0(n,e);function fl(n,e,t={},o={}){return zo(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:o.errorOnInvalidContent})}var jk=(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=fl(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 hf(n,e){const t=Nt(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 pf(n,e){const t=new bd(n);return e.forEach(o=>{o.steps.forEach(r=>{t.step(r)})}),t}function Uk(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 Wk(n,e,t){const o=[];return n.nodesBetween(e.from,e.to,(r,s)=>{t(r)&&o.push({node:r,pos:s})}),o}function Kk(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 hl(n){return e=>Kk(e.$from,n)}function H(n,e,t){return n.config[e]===void 0&&n.parent?H(n.parent,e,t):typeof n.config[e]=="function"?n.config[e].bind({...t,parent:n.parent?H(n.parent,e,t):null}):n.config[e]}function pl(n){return n.map(e=>{const t={name:e.name,options:e.options,storage:e.storage},o=H(e,"addExtensions",t);return o?[e,...pl(o())]:e}).flat(10)}function Fr(n,e){const t=gn.fromSchema(e).serializeFragment(n),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(t),r.innerHTML}function mf(n){return typeof n=="function"}function oe(n,e=void 0,...t){return mf(n)?e?n.bind(e)(...t):n(...t):n}function qk(n={}){return Object.keys(n).length===0&&n.constructor===Object}function to(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 gf(n){const e=[],{nodeExtensions:t,markExtensions:o}=to(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=H(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=H(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 Qt(...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 Hr(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)=>Qt(t,o),{})}function Gk(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function yf(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):Gk(t.getAttribute(i.name));return l==null?s:{...s,[i.name]:l}},{});return{...o,...r}}}}function kf(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&qk(t)?!1:t!=null))}function wf(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 bf(n,e){var t;const o=gf(n),{nodeExtensions:r,markExtensions:s}=to(n),i=(t=r.find(d=>H(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,b)=>{const S=H(b,"extendNodeSchema",f);return{...k,...S?S(d):{}}},{}),p=kf({...h,content:oe(H(d,"content",f)),marks:oe(H(d,"marks",f)),group:oe(H(d,"group",f)),inline:oe(H(d,"inline",f)),atom:oe(H(d,"atom",f)),selectable:oe(H(d,"selectable",f)),draggable:oe(H(d,"draggable",f)),code:oe(H(d,"code",f)),whitespace:oe(H(d,"whitespace",f)),linebreakReplacement:oe(H(d,"linebreakReplacement",f)),defining:oe(H(d,"defining",f)),isolating:oe(H(d,"isolating",f)),attrs:Object.fromEntries(u.map(wf))}),m=oe(H(d,"parseHTML",f));m&&(p.parseDOM=m.map(k=>yf(k,u)));const g=H(d,"renderHTML",f);g&&(p.toDOM=k=>g({node:k,HTMLAttributes:Hr(k,u)}));const y=H(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 b=H(k,"extendMarkSchema",f);return{...y,...b?b(d):{}}},{}),p=kf({...h,inclusive:oe(H(d,"inclusive",f)),excludes:oe(H(d,"excludes",f)),group:oe(H(d,"group",f)),spanning:oe(H(d,"spanning",f)),code:oe(H(d,"code",f)),attrs:Object.fromEntries(u.map(wf))}),m=oe(H(d,"parseHTML",f));m&&(p.parseDOM=m.map(y=>yf(y,u)));const g=H(d,"renderHTML",f);return g&&(p.toDOM=y=>g({mark:y,HTMLAttributes:Hr(y,u)})),[d.name,p]}));return new Gc({topNode:i,nodes:l,marks:c})}function Jk(n){const e=n.filter((t,o)=>n.indexOf(t)!==o);return Array.from(new Set(e))}function Ho(n){return n.sort((t,o)=>{const r=H(t,"priority")||100,s=H(o,"priority")||100;return r>s?-1:r<s?1:0})}function ml(n){const e=Ho(pl(n)),t=Jk(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 Sf(n,e){const t=ml(n);return bf(t,e)}function no(n,e){const t=Sf(e),o=Ct.fromJSON(t,n);return Fr(o.content,t)}function nt(n,e){const t=Sf(e),o=$o(n);return Hn.fromSchema(t).parse(o).toJSON()}function xf(n,e,t){const{from:o,to:r}=e,{blockSeparator:s=`
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 Yk(n,e){const t={from:0,to:n.content.size};return xf(n,t,e)}function Cf(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function Xk(n,e){const t=we(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 Ef(n,e){const t=zr(typeof e=="string"?e:e.name,n.schema);return t==="node"?Xk(n,e):t==="mark"?hf(n,e):{}}function Qk(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 Zk(n){const e=Qk(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 vf(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}})})}),Zk(o)}function gl(n,e,t){const o=[];return n===e?t.resolve(n).marks().forEach(r=>{const s=t.resolve(n),i=ul(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 jo(n,e){return e.nodes[n]||e.marks[n]||null}function jr(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 ew=(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 yl(n,e,t={}){const{empty:o,ranges:r}=n.selection,s=e?Nt(e,n.schema):null;if(o)return!!(n.storedMarks||n.selection.$from.marks()).filter(f=>s?s.name===f.type.name:!0).find(f=>Vr(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),b=Math.min(m,y+g.nodeSize),S=b-k;i+=S,l.push(...g.marks.map(x=>({mark:x,from:k,to:b})))})}),i===0)return!1;const c=l.filter(f=>s?s.name===f.mark.type.name:!0).filter(f=>Vr(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 tw(n,e,t={}){if(!e)return Fo(n,null,t)||yl(n,null,t);const o=zr(e,n.schema);return o==="node"?Fo(n,e,t):o==="mark"?yl(n,e,t):!1}function Tf(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function Mf(n,e){const{nodeExtensions:t}=to(e),o=t.find(i=>i.name===n);if(!o)return!1;const r={name:o.name,options:o.options,storage:o.storage},s=oe(H(o,"group",r));return typeof s!="string"?!1:s.split(" ").includes("list")}function Ur(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&&(Ur(s,{ignoreWhitespace:t,checkChildren:e})||(r=!1))}),r}return!1}function nw(n){return n instanceof q}var Af=class Fm{constructor(e){this.position=e}static fromJSON(e){return new Fm(e.position)}toJSON(){return{position:this.position}}};function ow(n,e){const t=e.mapping.mapResult(n.position);return{position:new Af(t.pos),mapResult:t}}function rw(n){return new Af(n)}function sw(n,e,t){var o;const{selection:r}=e;let s=null;if(lf(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 iw=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const{selection:s}=t,{empty:i,ranges:l}=s,c=Nt(n,o.schema);if(r)if(i){const d=hf(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 sw(o,t,c)},lw=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),aw=(n,e={})=>({state:t,dispatch:o,chain:r})=>{const s=we(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})=>Fd(s,{...i,...e})(t)?!0:l.clearNodes()).command(({state:l})=>Fd(s,{...i,...e})(l,o)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},cw=n=>({tr:e,dispatch:t})=>{if(t){const{doc:o}=e,r=Tn(n,0,o.content.size),s=q.create(o,r);e.setSelection(s)}return!0},dw=(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},uw=n=>({tr:e,dispatch:t})=>{if(t){const{doc:o}=e,{from:r,to:s}=typeof n=="number"?{from:n,to:n}:n,i=Y.atStart(o).from,l=Y.atEnd(o).to,c=Tn(r,i,l),d=Tn(s,i,l),u=Y.create(o,c,d);e.setSelection(u)}return!0},fw=n=>({state:e,dispatch:t})=>{const o=we(n,e.schema);return ay(o)(e,t)};function Nf(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 hw=({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=jr(d,l.node().type.name,l.node().attrs);if(s instanceof q&&s.node.isBlock)return!l.parentOffset||!Et(i,l.pos)?!1:(o&&(n&&Nf(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:Uk(l.node(-1).contentMatchAt(l.indexAfter(-1)));let p=f&&h?[{type:h,attrs:u}]:void 0,m=Et(e.doc,e.mapping.map(l.pos),1,p);if(!p&&!m&&Et(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 Y&&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&&Nf(t,r.extensionManager.splittableMarks),e.scrollIntoView()}return m},pw=(n,e={})=>({tr:t,state:o,dispatch:r,editor:s})=>{var i;const l=we(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=O.empty;const b=c.index(-1)?1:c.index(-2)?2:3;for(let M=c.depth-b;M>=c.depth-3;M-=1)k=O.from(c.node(M).copy(k));const S=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,x={...jr(h,c.node().type.name,c.node().attrs),...e},C=((i=l.contentMatch.defaultType)==null?void 0:i.createAndFill(x))||void 0;k=k.append(O.from(l.createAndFill(null,C)||void 0));const T=c.before(c.depth-(b-1));t.replace(T,c.after(-S),new $(k,4-b,0));let E=-1;t.doc.nodesBetween(T,t.doc.content.size,(M,v)=>{if(E>-1)return!1;M.isTextblock&&M.content.size===0&&(E=v+1)}),E>-1&&t.setSelection(Y.near(t.doc.resolve(E))),t.scrollIntoView()}return!0}const p=d.pos===c.end()?f.contentMatchAt(0).defaultType:null,m={...jr(h,f.type.name,f.attrs),...e},g={...jr(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(!Et(t.doc,c.pos,2))return!1;if(r){const{selection:k,storedMarks:b}=o,{splittableMarks:S}=s.extensionManager,x=b||k.$to.parentOffset&&k.$from.marks();if(t.split(c.pos,2,y).scrollIntoView(),!x||!r)return!0;const C=x.filter(T=>S.includes(T.type.name));t.ensureMarks(C)}return!0},kl=(n,e)=>{const t=hl(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)&&kn(n.doc,t.pos)&&n.join(t.pos),!0},wl=(n,e)=>{const t=hl(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)&&kn(n.doc,o)&&n.join(o),!0},mw=(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=we(n,i.schema),m=we(e,i.schema),{selection:g,storedMarks:y}=i,{$from:k,$to:b}=g,S=k.blockRange(b),x=y||g.$to.parentOffset&&g.$from.marks();if(!S)return!1;const C=hl(T=>Mf(T.type.name,f))(g);if(S.depth>=1&&C&&S.depth-C.depth<=1){if(C.node.type===p)return d.liftListItem(m);if(Mf(C.node.type.name,f)&&p.validContent(C.node.content)&&l)return c().command(()=>(s.setNodeMarkup(C.pos,p),!0)).command(()=>kl(s,p)).command(()=>wl(s,p)).run()}return!t||!x||!l?c().command(()=>u().wrapInList(p,o)?!0:d.clearNodes()).wrapInList(p,o).command(()=>kl(s,p)).command(()=>wl(s,p)).run():c().command(()=>{const T=u().wrapInList(p,o),E=x.filter(M=>h.includes(M.type.name));return s.ensureMarks(E),T?!0:d.clearNodes()}).wrapInList(p,o).command(()=>kl(s,p)).command(()=>wl(s,p)).run()},gw=(n,e={},t={})=>({state:o,commands:r})=>{const{extendEmptyMarkRange:s=!1}=t,i=Nt(n,o.schema);return yl(o,i,e)?r.unsetMark(i,{extendEmptyMarkRange:s}):r.setMark(i,e)},yw=(n,e,t={})=>({state:o,commands:r})=>{const s=we(n,o.schema),i=we(e,o.schema),l=Fo(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})},kw=(n,e={})=>({state:t,commands:o})=>{const r=we(n,t.schema);return Fo(t,r,e)?o.lift(r):o.wrapIn(r,e)},ww=()=>({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},bw=()=>({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},Sw=(n,e={})=>({tr:t,state:o,dispatch:r})=>{var s;const{extendEmptyMarkRange:i=!1}=e,{selection:l}=t,c=Nt(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=ul(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},xw=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},Cw=(n,e={})=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=zr(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=we(n,o.schema)),l==="mark"&&(i=Nt(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(b=>{if(i===b.type&&(c=!0,r)){const S=Math.max(k,u),x=Math.min(k+y.nodeSize,f);t.addMark(S,x,i.create({...b.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},Ew=(n,e={})=>({state:t,dispatch:o})=>{const r=we(n,t.schema);return ty(r,e)(t,o)},vw=(n,e={})=>({state:t,dispatch:o})=>{const r=we(n,t.schema);return ny(r,e)(t,o)},Tw=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={}}},Mw=class{constructor(n){var e;this.find=n.find,this.handler=n.handler,this.undoable=(e=n.undoable)!=null?e:!0}},Aw=(n,e)=>{if(dl(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 Wr(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=ew(d)+s;return i.forEach(h=>{if(u)return;const p=Aw(f,h.find);if(!p)return;const m=c.state.tr,g=Dr({state:c.state,transaction:m}),y={from:o-(p[0].length-s.length),to:r},{commands:k,chain:b,can:S}=new Lr({editor:t,state:g});h.handler({state:g,range:y,match:p,commands:k,chain:b,can:S})===null||!m.steps.length||(h.undoable&&m.setMeta(l,{transform:m,from:o,to:r,text:s}),c.dispatch(m),u=!0)}),u}function Nw(n){const{editor:e,rules:t}=n,o=new ue({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=Fr(O.from(u),i.schema);const{from:f}=c,h=f+u.length;Wr({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 Wr({editor:e,from:s,to:i,text:l,rules:t,plugin:o})},handleDOMEvents:{compositionend:r=>(setTimeout(()=>{const{$cursor:s}=r.state.selection;s&&Wr({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?Wr({editor:e,from:i.pos,to:i.pos,text:`
13
+ `,rules:t,plugin:o}):!1}},isInputRules:!0});return o}function Bw(n){return Object.prototype.toString.call(n).slice(8,-1)}function Kr(n){return Bw(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function Bf(n,e){const t={...n};return Kr(n)&&Kr(e)&&Object.keys(e).forEach(o=>{Kr(e[o])&&Kr(n[o])?t[o]=Bf(n[o],e[o]):t[o]=e[o]}),t}var bl=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{...oe(H(this,"addOptions",{name:this.name}))||{}}}get storage(){return{...oe(H(this,"addStorage",{name:this.name,options:this.options}))||{}}}configure(n={}){const e=this.extend({...this.config,addOptions:()=>Bf(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}},oo=class Hm extends bl{constructor(){super(...arguments),this.type="mark"}static create(e={}){const t=typeof e=="function"?e():e;return new Hm(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 Iw(n){return typeof n=="number"}var Ow=class{constructor(n){this.find=n.find,this.handler=n.handler}},_w=(n,e,t)=>{if(dl(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 Rw(n){const{editor:e,state:t,from:o,to:r,rule:s,pasteEvent:i,dropEvent:l}=n,{commands:c,chain:d,can:u}=new Lr({editor:e,state:t}),f=[];return t.doc.nodesBetween(o,r,(p,m)=>{var g,y,k,b,S;if((y=(g=p.type)==null?void 0:g.spec)!=null&&y.code||!(p.isText||p.isTextblock||p.isInline))return;const x=(S=(b=(k=p.content)==null?void 0:k.size)!=null?b:p.nodeSize)!=null?S:0,C=Math.max(o,m),T=Math.min(r,m+x);if(C>=T)return;const E=p.isText?p.text||"":p.textBetween(C-m,T-m,void 0,"");_w(E,s.find,i).forEach(v=>{if(v.index===void 0)return;const B=C+v.index+1,I=B+v[0].length,P={from:t.tr.mapping.map(B),to:t.tr.mapping.map(I)},V=s.handler({state:t,range:P,match:v,commands:c,chain:d,can:u,pasteEvent:i,dropEvent:l});f.push(V)})}),f.every(p=>p!==null)}var qr=null,Pw=n=>{var e;const t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)==null||e.setData("text/html",n),t};function Dw(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=Dr({state:u,transaction:g});if(!(!Rw({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 ue({view(f){const h=m=>{var g;o=(g=f.dom.parentElement)!=null&&g.contains(m.target)?f.dom.parentElement:null,o&&(qr=e)},p=()=>{qr&&(qr=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=qr;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"),b=!!k;if(!g&&!y&&!b)return;if(b){let{text:C}=k;typeof C=="string"?C=C:C=Fr(O.from(C),p.schema);const{from:T}=k,E=T+C.length,M=Pw(C);return c({rule:u,state:p,from:T,to:{b:E},pasteEvt:M})}const S=h.doc.content.findDiffStart(p.doc.content),x=h.doc.content.findDiffEnd(p.doc.content);if(!(!Iw(S)||!x||S===x.b))return c({rule:u,state:p,from:S,to:x,pasteEvt:i})}}))}var Gr=class{constructor(n,e){this.splittableMarks=[],this.editor=e,this.baseExtensions=n,this.extensions=ml(n),this.schema=bf(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:jo(e.name,this.schema)},o=H(e,"addCommands",t);return o?{...n,...o()}:n},{})}get plugins(){const{editor:n}=this;return Ho([...this.extensions].reverse()).flatMap(o=>{const r={name:o.name,options:o.options,storage:this.editor.extensionStorage[o.name],editor:n,type:jo(o.name,this.schema)},s=[],i=H(o,"addKeyboardShortcuts",r);let l={};if(o.type==="mark"&&H(o,"exitable",r)&&(l.ArrowRight=()=>oo.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=Q1(l);s.push(c);const d=H(o,"addInputRules",r);if(Tf(o,n.options.enableInputRules)&&d){const h=d();if(h&&h.length){const p=Nw({editor:n,rules:h}),m=Array.isArray(p)?p:[p];s.push(...m)}}const u=H(o,"addPasteRules",r);if(Tf(o,n.options.enablePasteRules)&&u){const h=u();if(h&&h.length){const p=Dw({editor:n,rules:h});s.push(...p)}}const f=H(o,"addProseMirrorPlugins",r);if(f){const h=f();s.push(...h)}return s})}get attributes(){return gf(this.extensions)}get nodeViews(){const{editor:n}=this,{nodeExtensions:e}=to(this.extensions);return Object.fromEntries(e.filter(t=>!!H(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:we(t.name,this.schema)},s=H(t,"addNodeView",r);if(!s)return[];const i=s();if(!i)return[];const l=(c,d,u,f,h)=>{const p=Hr(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 Ho([...this.extensions].reverse()).reduceRight((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:jo(r.name,this.schema)},i=H(r,"dispatchTransaction",s);return i?l=>{i.call(s,{transaction:l,next:o})}:o},n)}transformPastedHTML(n){const{editor:e}=this;return Ho([...this.extensions]).reduce((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:jo(r.name,this.schema)},i=H(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}=to(this.extensions);return Object.fromEntries(e.filter(t=>!!H(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:Nt(t.name,this.schema)},s=H(t,"addMarkView",r);if(!s)return[];const i=(l,c,d)=>{const u=Hr(l,o);return s()({mark:l,view:c,inline:d,editor:n,extension:t,HTMLAttributes:u,updateAttributes:f=>{Yw(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:jo(e.name,this.schema)};e.type==="mark"&&((t=oe(H(e,"keepOnSplit",o)))==null||t)&&this.splittableMarks.push(e.name);const r=H(e,"onBeforeCreate",o),s=H(e,"onCreate",o),i=H(e,"onUpdate",o),l=H(e,"onSelectionUpdate",o),c=H(e,"onTransaction",o),d=H(e,"onFocus",o),u=H(e,"onBlur",o),f=H(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)})}};Gr.resolve=ml,Gr.sort=Ho,Gr.flatten=pl;var Lw={};cl(Lw,{ClipboardTextSerializer:()=>If,Commands:()=>Of,Delete:()=>_f,Drop:()=>Rf,Editable:()=>Pf,FocusEvents:()=>Lf,Keymap:()=>Vf,Paste:()=>$f,Tabindex:()=>zf,TextDirection:()=>Ff,focusEventsPluginKey:()=>Df});var se=class jm extends bl{constructor(){super(...arguments),this.type="extension"}static create(e={}){const t=typeof e=="function"?e():e;return new jm(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}},If=se.create({name:"clipboardTextSerializer",addOptions(){return{blockSeparator:void 0}},addProseMirrorPlugins(){return[new ue({key:new ke("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=Cf(t);return xf(o,{from:i,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:c})}}})]}}),Of=se.create({name:"commands",addCommands(){return{...of}}}),_f=se.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=pf(n.before,[n,...e]);vf(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 tt){const k=h.slice(m).map(p.from,-1),b=h.slice(m).map(p.to),S=h.invert().map(k,-1),x=h.invert().map(b),C=(g=u.doc.nodeAt(k-1))==null?void 0:g.marks.some(E=>E.eq(p.mark)),T=(y=u.doc.nodeAt(b))==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:S,to:x},newRange:{from:k,to:b},partial:!!(T||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()}}),Rf=se.create({name:"drop",addProseMirrorPlugins(){return[new ue({key:new ke("tiptapDrop"),props:{handleDrop:(n,e,t,o)=>{this.editor.emit("drop",{editor:this.editor,event:e,slice:t,moved:o})}}})]}}),Pf=se.create({name:"editable",addProseMirrorPlugins(){return[new ue({key:new ke("editable"),props:{editable:()=>this.editor.options.editable}})]}}),Df=new ke("focusEvents"),Lf=se.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new ue({key:Df,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}}}})]}}),Vf=se.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:Z.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 $r()||uf()?s:r},addProseMirrorPlugins(){return[new ue({key:new ke("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=Z.atStart(e.doc).from,d=Z.atEnd(e.doc).to;if(s||!(i===c&&l===d)||!Ur(t.doc))return;const h=t.tr,p=Dr({state:t,transaction:h}),{commands:m}=new Lr({editor:this.editor,state:p});if(m.clearNodes(),!!h.steps.length)return h}})]}}),$f=se.create({name:"paste",addProseMirrorPlugins(){return[new ue({key:new ke("tiptapPaste"),props:{handlePaste:(n,e,t)=>{this.editor.emit("paste",{editor:this.editor,event:e,slice:t})}}})]}}),zf=se.create({name:"tabindex",addProseMirrorPlugins(){return[new ue({key:new ke("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}}),Ff=se.create({name:"textDirection",addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];const{nodeExtensions:n}=to(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 ue({key:new ke("textDirection"),props:{attributes:()=>{const n=this.options.direction;return n?{dir:n}:{}}}})]}}),Vw=class dr{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 dr(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 dr(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 dr(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 dr(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)}},$w=`.ProseMirror {
14
14
  position: relative;
15
15
  }
16
16
 
@@ -80,24 +80,30 @@ img.ProseMirror-separator {
80
80
 
81
81
  .ProseMirror-focused .ProseMirror-gapcursor {
82
82
  display: block;
83
- }`;function ey(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 ty=class extends z0{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:y0,createMappablePosition:k0},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=Rc(t,this.options.autofocus);this.editorState=bn.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=ey(Q0,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=zc(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?[sd,td.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)==null?void 0:e.clipboardTextSerializer)==null?void 0:t.blockSeparator}),nd,ld,ad,dd,rd,cd,od,ud.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 Qo(r,this)}createCommandManager(){this.commandManager=new Fo({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=Ds(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=Ds(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 Cc(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 a=this.state.reconfigure({plugins:this.extensionManager.plugins});this.view.updateState(a),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")),a=l==null?void 0:l.getMeta("focus"),d=l==null?void 0:l.getMeta("blur");a&&this.emit("focus",{editor:this,event:a.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 d0(this.state,e)}isActive(e,t){const o=typeof e=="string"?e:null,r=typeof e=="string"?t:e;return m0(this.state,o,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return Uo(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=`
83
+ }`;function zw(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 Fw=class extends Tw{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:ow,createMappablePosition:rw},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=af(t,this.options.autofocus);this.editorState=qn.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=zw($w,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=mf(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?[Pf,If.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)==null?void 0:e.clipboardTextSerializer)==null?void 0:t.blockSeparator}),Of,Lf,Vf,zf,Rf,$f,_f,Ff.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 Gr(r,this)}createCommandManager(){this.commandManager=new Lr({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=fl(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=fl(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 Yu(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 Ef(this.state,e)}isActive(e,t){const o=typeof e=="string"?e:null,r=typeof e=="string"?t:e;return tw(this.state,o,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return Fr(this.state.doc.content,this.schema)}getText(e){const{blockSeparator:t=`
84
84
 
85
- `,textSerializers:o={}}=e||{};return a0(this.state.doc,{blockSeparator:t,textSerializers:{...Jc(this.schema),...o}})}get isEmpty(){return Go(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 Z0(t,this)}get $doc(){return this.$pos(0)}};function er(n){return new F0({find:n.find,handler:({state:e,range:t,match:o})=>{const r=te(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 a=l.search(/\S/),d=t.from+l.indexOf(i),u=d+i.length;if(Gc(t.from,t.to,e.doc).filter(h=>h.mark.type.excluded.find(g=>g===n.type&&g!==h.mark.type)).filter(h=>h.to>d).length)return null;u<t.to&&s.delete(u,t.to),d>t.from&&s.delete(t.from+a,d);const p=t.from+a+i.length;s.addMark(t.from+a,p,n.type.create(r||{})),s.removeStoredMark(n.type)}},undoable:n.undoable})}var ny={};As(ny,{createAtomBlockMarkdownSpec:()=>oy,createBlockMarkdownSpec:()=>ry,createInlineMarkdownSpec:()=>ly,parseAttributes:()=>Fs,parseIndentedBlocks:()=>ay,renderNestedMarkdownContent:()=>cy,serializeAttributes:()=>Hs});function Fs(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 p=parseInt(((f=u.match(/__QUOTED_(\d+)__/))==null?void 0:f[1])||"0",10),h=t[p];h&&(e[d]=h.slice(1,-1))});const a=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 a&&a.split(/\s+/).filter(Boolean).forEach(u=>{u.match(/^[a-zA-Z][\w-]*$/)&&(e[u]=!0)}),e}function Hs(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 oy(n){const{nodeName:e,name:t,parseAttributes:o=Fs,serializeAttributes:r=Hs,defaultAttributes:s={},requiredAttributes:i=[],allowedAttributes:l}=n,a=t||e,d=u=>{if(!l)return u;const f={};return l.forEach(p=>{p in u&&(f[p]=u[p])}),f};return{parseMarkdown:(u,f)=>{const p={...s,...u.attributes};return f.createNode(e,p,[])},markdownTokenizer:{name:e,level:"block",start(u){var f;const p=new RegExp(`^:::${a}(?:\\s|$)`,"m"),h=(f=u.match(p))==null?void 0:f.index;return h!==void 0?h:-1},tokenize(u,f,p){const h=new RegExp(`^:::${a}(?:\\s+\\{([^}]*)\\})?\\s*:::(?:\\n|$)`),m=u.match(h);if(!m)return;const g=m[1]||"",y=o(g);if(!i.find(w=>!(w in y)))return{type:e,raw:m[0],attributes:y}}},renderMarkdown:u=>{const f=d(u.attrs||{}),p=r(f),h=p?` {${p}}`:"";return`:::${a}${h} :::`}}}function ry(n){const{nodeName:e,name:t,getContent:o,parseAttributes:r=Fs,serializeAttributes:s=Hs,defaultAttributes:i={},content:l="block",allowedAttributes:a}=n,d=t||e,u=f=>{if(!a)return f;const p={};return a.forEach(h=>{h in f&&(p[h]=f[h])}),p};return{parseMarkdown:(f,p)=>{let h;if(o){const g=o(f);h=typeof g=="string"?[{type:"text",text:g}]:g}else l==="block"?h=p.parseChildren(f.tokens||[]):h=p.parseInline(f.tokens||[]);const m={...i,...f.attributes};return p.createNode(e,m,h)},markdownTokenizer:{name:e,level:"block",start(f){var p;const h=new RegExp(`^:::${d}`,"m"),m=(p=f.match(h))==null?void 0:p.index;return m!==void 0?m:-1},tokenize(f,p,h){var m;const g=new RegExp(`^:::${d}(?:\\s+\\{([^}]*)\\})?\\s*\\n`),y=f.match(g);if(!y)return;const[k,w=""]=y,b=r(w);let S=1;const C=k.length;let M="";const v=/^:::([\w-]*)(\s.*)?/gm,E=f.slice(C);for(v.lastIndex=0;;){const T=v.exec(E);if(T===null)break;const A=T.index,R=T[1];if(!((m=T[2])!=null&&m.endsWith(":::"))){if(R)S+=1;else if(S-=1,S===0){const $=E.slice(0,A);M=$.trim();const z=f.slice(0,C+A+T[0].length);let j=[];if(M)if(l==="block")for(j=h.blockTokens($),j.forEach(K=>{K.text&&(!K.tokens||K.tokens.length===0)&&(K.tokens=h.inlineTokens(K.text))});j.length>0;){const K=j[j.length-1];if(K.type==="paragraph"&&(!K.text||K.text.trim()===""))j.pop();else break}else j=h.inlineTokens(M);return{type:e,raw:z,attributes:b,content:M,tokens:j}}}}}},renderMarkdown:(f,p)=>{const h=u(f.attrs||{}),m=s(h),g=m?` {${m}}`:"",y=p.renderChildren(f.content||[],`
85
+ `,textSerializers:o={}}=e||{};return Yk(this.state.doc,{blockSeparator:t,textSerializers:{...Cf(this.schema),...o}})}get isEmpty(){return Ur(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 Vw(t,this)}get $doc(){return this.$pos(0)}};function Jr(n){return new Mw({find:n.find,handler:({state:e,range:t,match:o})=>{const r=oe(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(gl(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 Hw={};cl(Hw,{createAtomBlockMarkdownSpec:()=>jw,createBlockMarkdownSpec:()=>Uw,createInlineMarkdownSpec:()=>qw,parseAttributes:()=>Sl,parseIndentedBlocks:()=>Gw,renderNestedMarkdownContent:()=>Jw,serializeAttributes:()=>xl});function Sl(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 xl(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 jw(n){const{nodeName:e,name:t,parseAttributes:o=Sl,serializeAttributes:r=xl,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(b=>!(b 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 Uw(n){const{nodeName:e,name:t,getContent:o,parseAttributes:r=Sl,serializeAttributes:s=xl,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,b=""]=y,S=r(b);let x=1;const C=k.length;let T="";const E=/^:::([\w-]*)(\s.*)?/gm,M=f.slice(C);for(E.lastIndex=0;;){const v=E.exec(M);if(v===null)break;const B=v.index,I=v[1];if(!((m=v[2])!=null&&m.endsWith(":::"))){if(I)x+=1;else if(x-=1,x===0){const P=M.slice(0,B);T=P.trim();const V=f.slice(0,C+B+v[0].length);let z=[];if(T)if(l==="block")for(z=p.blockTokens(P),z.forEach(W=>{W.text&&(!W.tokens||W.tokens.length===0)&&(W.tokens=p.inlineTokens(W.text))});z.length>0;){const W=z[z.length-1];if(W.type==="paragraph"&&(!W.text||W.text.trim()===""))z.pop();else break}else z=p.inlineTokens(T);return{type:e,raw:V,attributes:S,content:T,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
 
89
89
  ${y}
90
90
 
91
- :::`}}}function sy(n){if(!n.trim())return{};const e={},t=/(\w+)=(?:"([^"]*)"|'([^']*)')/g;let o=t.exec(n);for(;o!==null;){const[,r,s,i]=o;e[r]=s||i,o=t.exec(n)}return e}function iy(n){return Object.entries(n).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(" ")}function ly(n){const{nodeName:e,name:t,getContent:o,parseAttributes:r=sy,serializeAttributes:s=iy,defaultAttributes:i={},selfClosing:l=!1,allowedAttributes:a}=n,d=t||e,u=p=>{if(!a)return p;const h={};return a.forEach(m=>{const g=typeof m=="string"?m:m.name,y=typeof m=="string"?void 0:m.skipIfDefault;if(g in p){const k=p[g];if(y!==void 0&&k===y)return;h[g]=k}}),h},f=d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return{parseMarkdown:(p,h)=>{const m={...i,...p.attributes};if(l)return h.createNode(e,m);const g=o?o(p):p.content||"";return g?h.createNode(e,m,[h.createTextNode(g)]):h.createNode(e,m,[])},markdownTokenizer:{name:e,level:"inline",start(p){const h=l?new RegExp(`\\[${f}\\s*[^\\]]*\\]`):new RegExp(`\\[${f}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${f}\\]`),m=p.match(h),g=m==null?void 0:m.index;return g!==void 0?g:-1},tokenize(p,h,m){const g=l?new RegExp(`^\\[${f}\\s*([^\\]]*)\\]`):new RegExp(`^\\[${f}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${f}\\]`),y=p.match(g);if(!y)return;let k="",w="";if(l){const[,S]=y;w=S}else{const[,S,C]=y;w=S,k=C||""}const b=r(w.trim());return{type:e,raw:y[0],content:k.trim(),attributes:b}}},renderMarkdown:p=>{let h="";o?h=o(p):p.content&&p.content.length>0&&(h=p.content.filter(k=>k.type==="text").map(k=>k.text).join(""));const m=u(p.attrs||{}),g=s(m),y=g?` ${g}`:"";return l?`[${d}${y}]`:`[${d}${y}]${h}[/${d}]`}}}function ay(n,e,t){var o,r,s,i;const l=n.split(`
92
- `),a=[];let d="",u=0;const f=e.baseIndentSize||2;for(;u<l.length;){const p=l[u],h=p.match(e.itemPattern);if(!h){if(a.length>0)break;if(p.trim()===""){u+=1,d=`${d}${p}
93
- `;continue}else return}const m=e.extractItemData(h),{indentLevel:g,mainContent:y}=m;d=`${d}${p}
94
- `;const k=[y];for(u+=1;u<l.length;){const C=l[u];if(C.trim()===""){const v=l.slice(u+1).findIndex(A=>A.trim()!=="");if(v===-1)break;if((((r=(o=l[u+1+v].match(/^(\s*)/))==null?void 0:o[1])==null?void 0:r.length)||0)>g){k.push(C),d=`${d}${C}
91
+ :::`}}}function Ww(n){if(!n.trim())return{};const e={},t=/(\w+)=(?:"([^"]*)"|'([^']*)')/g;let o=t.exec(n);for(;o!==null;){const[,r,s,i]=o;e[r]=s||i,o=t.exec(n)}return e}function Kw(n){return Object.entries(n).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(" ")}function qw(n){const{nodeName:e,name:t,getContent:o,parseAttributes:r=Ww,serializeAttributes:s=Kw,defaultAttributes:i={},selfClosing:l=!1,allowedAttributes:c}=n,d=t||e,u=h=>{if(!c)return h;const p={};return c.forEach(m=>{const g=typeof m=="string"?m:m.name,y=typeof m=="string"?void 0:m.skipIfDefault;if(g in h){const k=h[g];if(y!==void 0&&k===y)return;p[g]=k}}),p},f=d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");return{parseMarkdown:(h,p)=>{const m={...i,...h.attributes};if(l)return p.createNode(e,m);const g=o?o(h):h.content||"";return g?p.createNode(e,m,[p.createTextNode(g)]):p.createNode(e,m,[])},markdownTokenizer:{name:e,level:"inline",start(h){const p=l?new RegExp(`\\[${f}\\s*[^\\]]*\\]`):new RegExp(`\\[${f}\\s*[^\\]]*\\][\\s\\S]*?\\[\\/${f}\\]`),m=h.match(p),g=m==null?void 0:m.index;return g!==void 0?g:-1},tokenize(h,p,m){const g=l?new RegExp(`^\\[${f}\\s*([^\\]]*)\\]`):new RegExp(`^\\[${f}\\s*([^\\]]*)\\]([\\s\\S]*?)\\[\\/${f}\\]`),y=h.match(g);if(!y)return;let k="",b="";if(l){const[,x]=y;b=x}else{const[,x,C]=y;b=x,k=C||""}const S=r(b.trim());return{type:e,raw:y[0],content:k.trim(),attributes:S}}},renderMarkdown:h=>{let p="";o?p=o(h):h.content&&h.content.length>0&&(p=h.content.filter(k=>k.type==="text").map(k=>k.text).join(""));const m=u(h.attrs||{}),g=s(m),y=g?` ${g}`:"";return l?`[${d}${y}]`:`[${d}${y}]${p}[/${d}]`}}}function Gw(n,e,t){var o,r,s,i;const l=n.split(`
92
+ `),c=[];let d="",u=0;const f=e.baseIndentSize||2;for(;u<l.length;){const h=l[u],p=h.match(e.itemPattern);if(!p){if(c.length>0)break;if(h.trim()===""){u+=1,d=`${d}${h}
93
+ `;continue}else return}const m=e.extractItemData(p),{indentLevel:g,mainContent:y}=m;d=`${d}${h}
94
+ `;const k=[y];for(u+=1;u<l.length;){const C=l[u];if(C.trim()===""){const E=l.slice(u+1).findIndex(B=>B.trim()!=="");if(E===-1)break;if((((r=(o=l[u+1+E].match(/^(\s*)/))==null?void 0:o[1])==null?void 0:r.length)||0)>g){k.push(C),d=`${d}${C}
95
95
  `,u+=1;continue}else break}if((((i=(s=C.match(/^(\s*)/))==null?void 0:s[1])==null?void 0:i.length)||0)>g)k.push(C),d=`${d}${C}
96
- `,u+=1;else break}let w;const b=k.slice(1);if(b.length>0){const C=b.map(M=>M.slice(g+f)).join(`
97
- `);C.trim()&&(e.customNestedParser?w=e.customNestedParser(C):w=t.blockTokens(C))}const S=e.createToken(m,w);a.push(S)}if(a.length!==0)return{items:a,raw:d}}function cy(n,e,t,o){if(!n||!Array.isArray(n.content))return"";const r=typeof t=="function"?t(o):t,[s,...i]=n.content,l=e.renderChildren([s]),a=[`${r}${l}`];return i&&i.length>0&&i.forEach(d=>{const u=e.renderChildren([d]);if(u){const f=u.split(`
98
- `).map(p=>p?e.indent(p):"").join(`
99
- `);a.push(f)}}),a.join(`
100
- `)}function dy(n,e,t={}){const{state:o}=e,{doc:r,tr:s}=o,i=n;r.descendants((l,a)=>{const d=s.mapping.map(a),u=s.mapping.map(a)+l.nodeSize;let f=null;if(l.marks.forEach(h=>{if(h!==i)return!1;f=h}),!f)return;let p=!1;if(Object.keys(t).forEach(h=>{t[h]!==f.attrs[h]&&(p=!0)}),p){const h=n.type.create({...n.attrs,...t});s.removeMark(d,u,n.type),s.addMark(d,u,h)}}),s.docChanged&&e.view.dispatch(s)}var Ws=class rf extends zs{constructor(){super(...arguments),this.type="node"}static create(e={}){const t=typeof e=="function"?e():e;return new rf(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}};function tr(n){return new K0({find:n.find,handler:({state:e,range:t,match:o,pasteEvent:r})=>{const s=te(n.getAttributes,void 0,o,r);if(s===!1||s===null)return null;const{tr:i}=e,l=o[o.length-1],a=o[0];let d=t.to;if(l){const u=a.search(/\S/),f=t.from+a.indexOf(l),p=f+l.length;if(Gc(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;p<t.to&&i.delete(p,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 fd(n){return c.customRef((e,t)=>({get(){return e(),n},set(o){n=o,requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})}}))}var uy=class extends ty{constructor(n={}){return super(n),this.contentComponent=null,this.appContext=null,this.reactiveState=fd(this.view.state),this.reactiveExtensionStorage=fd(this.extensionStorage),this.on("beforeTransaction",({nextState:e})=>{this.reactiveState.value=e,this.reactiveExtensionStorage.value=this.extensionStorage}),c.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}},fy=c.defineComponent({name:"EditorContent",props:{editor:{default:null,type:Object}},setup(n){const e=c.ref(),t=c.getCurrentInstance();return c.watchEffect(()=>{const o=n.editor;o&&o.options.element&&e.value&&c.nextTick(()=>{var r;if(!e.value||!((r=o.view.dom)!=null&&r.parentNode))return;const s=c.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()})}),c.onBeforeUnmount(()=>{const o=n.editor;o&&(o.contentComponent=null,o.appContext=null)}),{rootEl:e}},render(){return c.h("div",{ref:n=>{this.rootEl=n}})}});c.defineComponent({name:"NodeViewContent",props:{as:{type:String,default:"div"}},render(){return c.h(this.as,{style:{whiteSpace:"pre-wrap"},"data-node-view-content":""})}}),c.defineComponent({name:"NodeViewWrapper",props:{as:{type:String,default:"div"}},inject:["onDragStart","decorationClasses"],render(){var n,e;return c.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))}}),c.defineComponent({name:"MarkViewContent",props:{as:{type:String,default:"span"}},render(){return c.h(this.as,{style:{whiteSpace:"inherit"},"data-mark-view-content":""})}});var hy=Ws.create({name:"doc",topNode:!0,content:"block+",renderMarkdown:(n,e)=>n.content?e.renderChildren(n.content,`
101
-
102
- `):""}),hd=hy,pd="&nbsp;",py=" ",my=Ws.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",Bn(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===pd||o[0].text===py)?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?pd:e.renderChildren(t)},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),md=my,gy=Ws.create({name:"text",group:"inline",parseMarkdown:n=>({type:"text",text:n.text||""}),renderMarkdown:n=>n.text||""}),gd=gy,yd=(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]},yy=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,ky=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,wy=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,by=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,xy=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 yd("strong",{...Bn(this.options.HTMLAttributes,n),children:yd("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[er({find:yy,type:this.type}),er({find:wy,type:this.type})]},addPasteRules(){return[tr({find:ky,type:this.type}),tr({find:by,type:this.type})]}}),kd=xy,Sy=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,Cy=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,vy=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,Ey=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,My=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",Bn(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[er({find:Sy,type:this.type}),er({find:vy,type:this.type})]},addPasteRules(){return[tr({find:Cy,type:this.type}),tr({find:Ey,type:this.type})]}}),wd=My,Ty=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",Bn(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()}}}),bd=Ty,Ny=ne.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")}}}),xd=Ny,By=20,Sd=(n,e=0)=>{const t=[];return!n.children.length||e>By||Array.from(n.children).forEach(o=>{o.tagName==="SPAN"?t.push(o):o.children.length&&t.push(...Sd(o,e+1))}),t},Ay=n=>{if(!n.children.length)return;const e=Sd(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}`)})},js=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&&Ay(n),{}):!1}]},renderHTML({HTMLAttributes:n}){return["span",Bn(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}}}}),Iy=ne.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()}}}),Cd=ne.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()}}}),Oy=ne.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()}}}),Dy=ne.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()}}}),Ry=ne.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()}}});ne.create({name:"textStyleKit",addExtensions(){const n=[];return this.options.backgroundColor!==!1&&n.push(Iy.configure(this.options.backgroundColor)),this.options.color!==!1&&n.push(Cd.configure(this.options.color)),this.options.fontFamily!==!1&&n.push(Oy.configure(this.options.fontFamily)),this.options.fontSize!==!1&&n.push(Dy.configure(this.options.fontSize)),this.options.lineHeight!==!1&&n.push(Ry.configure(this.options.lineHeight)),this.options.textStyle!==!1&&n.push(js.configure(this.options.textStyle)),n}});var vd=Cd;function _y(n={}){return new ue({view(e){return new Py(e,n)}})}class Py{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,p=e.nodeAfter;if(f||p){let h=this.editorView.nodeDOM(this.cursorPos-(f?f.nodeSize:0));if(h){let m=h.getBoundingClientRect(),g=f?m.bottom:m.top;f&&p&&(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),p=this.width/2*i;o={left:f.left-p,right:f.left+p,top:f.top,bottom:f.bottom}}let a=this.editorView.dom.offsetParent;this.element||(this.element=a.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(!a||a==document.body&&getComputedStyle(a).position=="static")d=-pageXOffset,u=-pageYOffset;else{let f=a.getBoundingClientRect(),p=f.width/a.offsetWidth,h=f.height/a.offsetHeight;d=f.left-a.scrollLeft*p,u=f.top-a.scrollTop*h}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=Hl(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 se extends G{constructor(e){super(e,e)}map(e,t){let o=e.resolve(t.map(this.head));return se.valid(o)?new se(o):G.near(o)}content(){return _.empty}eq(e){return e instanceof se&&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 se(e.resolve(t.pos))}getBookmark(){return new Us(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Vy(e)||!$y(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&&se.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 a=e.doc.resolve(r);if(se.valid(a))return a}for(;;){let i=t>0?s.firstChild:s.lastChild;if(!i){if(s.isAtom&&!s.isText&&!F.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(se.valid(l))return l}return null}}}se.prototype.visible=!1,se.findFrom=se.findGapCursorFrom,G.jsonID("gapcursor",se);class Us{constructor(e){this.pos=e}map(e){return new Us(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return se.valid(t)?new se(t):G.near(t)}}function Ed(n){return n.isAtom||n.spec.isolating||n.spec.createGapCursor}function Vy(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||Ed(r.type))return!0;if(r.inlineContent)return!1}}return!0}function $y(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||Ed(r.type))return!0;if(r.inlineContent)return!1}}return!0}function Ly(){return new ue({props:{decorations:Wy,createSelectionBetween(n,e,t){return e.pos==t.pos&&se.valid(t)?new se(t):null},handleClick:Fy,handleKeyDown:zy,handleDOMEvents:{beforeinput:Hy}}})}const zy=Bc({ArrowLeft:nr("horiz",-1),ArrowRight:nr("horiz",1),ArrowUp:nr("vert",-1),ArrowDown:nr("vert",1)});function nr(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,a=i.empty;if(i instanceof q){if(!s.endOfTextblock(t)||l.depth==0)return!1;a=!1,l=o.doc.resolve(e>0?l.after():l.before())}let d=se.findGapCursorFrom(l,e,a);return d?(r&&r(o.tr.setSelection(new se(d))),!0):!1}}function Fy(n,e,t){if(!n||!n.editable)return!1;let o=n.state.doc.resolve(e);if(!se.valid(o))return!1;let r=n.posAtCoords({left:t.clientX,top:t.clientY});return r&&r.inside>-1&&F.isSelectable(n.state.doc.nodeAt(r.inside))?!1:(n.dispatch(n.state.tr.setSelection(new se(o))),!0)}function Hy(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof se))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=B.empty;for(let i=o.length-1;i>=0;i--)r=B.from(o[i].createAndFill(null,r));let s=n.state.tr.replace(t.pos,t.pos,new _(r,0,0));return s.setSelection(q.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function Wy(n){if(!(n.selection instanceof se))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",re.create(n.doc,[Ae.widget(n.selection.head,e,{key:"gapcursor"})])}var or=200,ge=function(){};ge.prototype.append=function(e){return e.length?(e=ge.from(e),!this.length&&e||e.length<or&&this.leafAppend(e)||this.length<or&&e.leafPrepend(this)||this.appendInner(e)):this},ge.prototype.prepend=function(e){return e.length?ge.from(e).append(this):this},ge.prototype.appendInner=function(e){return new jy(this,e)},ge.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?ge.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},ge.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},ge.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)},ge.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},ge.from=function(e){return e instanceof ge?e:e&&e.length?new Md(e):ge.empty};var Md=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 a=s;a<i;a++)if(r(this.values[a],l+a)===!1)return!1},e.prototype.forEachInvertedInner=function(r,s,i,l){for(var a=s-1;a>=i;a--)if(r(this.values[a],l+a)===!1)return!1},e.prototype.leafAppend=function(r){if(this.length+r.length<=or)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=or)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}(ge);ge.empty=new Md([]);var jy=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}(ge);const Uy=500;class qe{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,a,d=[],u=[];return this.items.forEach((f,p)=>{if(!f.step){r||(r=this.remapping(o,p+1),s=r.maps.length),s--,u.push(f);return}if(r){u.push(new nt(f.map));let h=f.step.map(r.slice(s)),m;h&&i.maybeStep(h).doc&&(m=i.mapping.maps[i.mapping.maps.length-1],d.push(new nt(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,a=new qe(this.items.slice(0,o).append(u.reverse().concat(d)),this.eventCount-1),!1},this.items.length,0),{remaining:a,transform:i,selection:l}}addTransform(e,t,o,r){let s=[],i=this.eventCount,l=this.items,a=!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]),p=new nt(e.mapping.maps[u],f,t),h;(h=a&&a.merge(p))&&(p=h,u?s.pop():l=l.slice(0,l.length-1)),s.push(p),t&&(i++,t=void 0),r||(a=p)}let d=i-o.depth;return d>qy&&(l=Ky(l,d),i-=d),new qe(l.append(s),i)}remapping(e,t){let o=new Fn;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 qe(this.items.append(e.map(t=>new nt(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(p=>{p.selection&&l--},r);let a=t;this.items.forEach(p=>{let h=s.getMirror(--a);if(h==null)return;i=Math.min(i,h);let m=s.maps[h];if(p.step){let g=e.steps[h].invert(e.docs[h]),y=p.selection&&p.selection.map(s.slice(a+1,h));y&&l++,o.push(new nt(m,g,y))}else o.push(new nt(m))},r);let d=[];for(let p=t;p<i;p++)d.push(new nt(s.maps[p]));let u=this.items.slice(0,r).append(d).append(o),f=new qe(u,l);return f.emptyItemCount()>Uy&&(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 a=i.step.map(t.slice(o)),d=a&&a.getMap();if(o--,d&&t.appendMap(d,o),a){let u=i.selection&&i.selection.map(t.slice(o));u&&s++;let f=new nt(d.invert(),a,u),p,h=r.length-1;(p=r.length&&r[h].merge(f))?r[h]=p:r.push(f)}}else i.map&&o--},this.items.length,0),new qe(ge.from(r.reverse()),s)}}qe.empty=new qe(ge.empty,0);function Ky(n,e){let t;return n.forEach((o,r)=>{if(o.selection&&e--==0)return t=r,!1}),n.slice(t)}class nt{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 nt(t.getMap().invert(),t,this.selection)}}}class Rt{constructor(e,t,o,r,s){this.done=e,this.undone=t,this.prevRanges=o,this.prevTime=r,this.prevComposition=s}}const qy=20;function Jy(n,e,t,o){let r=t.getMeta(on),s;if(r)return r.historyState;t.getMeta(Xy)&&(n=new Rt(n.done,n.undone,null,0,-1));let i=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(i&&i.getMeta(on))return i.getMeta(on).redo?new Rt(n.done.addTransform(t,void 0,o,rr(e)),n.undone,Td(t.mapping.maps),n.prevTime,n.prevComposition):new Rt(n.done,n.undone.addTransform(t,void 0,o,rr(e)),null,n.prevTime,n.prevComposition);if(t.getMeta("addToHistory")!==!1&&!(i&&i.getMeta("addToHistory")===!1)){let l=t.getMeta("composition"),a=n.prevTime==0||!i&&n.prevComposition!=l&&(n.prevTime<(t.time||0)-o.newGroupDelay||!Gy(t,n.prevRanges)),d=i?Ks(n.prevRanges,t.mapping):Td(t.mapping.maps);return new Rt(n.done.addTransform(t,a?e.selection.getBookmark():void 0,o,rr(e)),qe.empty,d,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new Rt(n.done.rebased(t,s),n.undone.rebased(t,s),Ks(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new Rt(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),Ks(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function Gy(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 Td(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 Ks(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 Yy(n,e,t){let o=rr(e),r=on.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),a=new Rt(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(i).setMeta(on,{redo:t,historyState:a})}let qs=!1,Nd=null;function rr(n){let e=n.plugins;if(Nd!=e){qs=!1,Nd=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){qs=!0;break}}return qs}const on=new Te("history"),Xy=new Te("closeHistory");function Zy(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new ue({key:on,state:{init(){return new Rt(qe.empty,qe.empty,null,0,-1)},apply(e,t,o){return Jy(t,o,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let o=t.inputType,r=o=="historyUndo"?Ad:o=="historyRedo"?Id:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function Bd(n,e){return(t,o)=>{let r=on.getState(t);if(!r||(n?r.undone:r.done).eventCount==0)return!1;if(o){let s=Yy(r,t,n);s&&o(e?s.scrollIntoView():s)}return!0}}const Ad=Bd(!1,!0),Id=Bd(!0,!0);ne.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 ue({key:new Te("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,a=i;console.warn(`[CharacterCount] Initial content exceeded limit of ${r} characters. Content was automatically trimmed.`);const d=o.tr.deleteRange(l,a);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,a=s-o,d=l-a,u=l;return e.deleteRange(d,u),!(this.storage.characters({node:e.doc})>o)}})]}}),ne.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[_y(this.options)]}}),ne.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new ue({key:new Te("focus"),props:{decorations:({doc:n,selection:e})=>{const{isEditable:t,isFocused:o}=this.editor,{anchor:r}=e,s=[];if(!t||!o)return re.create(n,[]);let i=0;this.options.mode==="deepest"&&n.descendants((a,d)=>{if(a.isText)return;if(!(r>=d&&r<=d+a.nodeSize-1))return!1;i+=1});let l=0;return n.descendants((a,d)=>{if(a.isText||!(r>=d&&r<=d+a.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(Ae.node(d,d+a.nodeSize,{class:this.options.className}))}),re.create(n,s)}}})]}}),ne.create({name:"gapCursor",addProseMirrorPlugins(){return[Ly()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=te(V(n,"allowGapCursor",t)))!=null?e:null}}});var Od="placeholder";function Qy(n){return n.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}ne.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:Od,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){const n=this.options.dataAttribute?`data-${Qy(this.options.dataAttribute)}`:`data-${Od}`;return[new ue({key:new Te("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,a)=>{const d=r>=a&&r<=a+l.nodeSize,u=!l.isLeaf&&Go(l);if((d||!this.options.showOnlyCurrent)&&u){const f=[this.options.emptyNodeClass];i&&f.push(this.options.emptyEditorClass);const p=Ae.node(a,a+l.nodeSize,{class:f.join(" "),[n]:typeof this.options.placeholder=="function"?this.options.placeholder({editor:this.editor,node:l,pos:a,hasAnchor:d}):this.options.placeholder});s.push(p)}return this.options.includeChildren}),re.create(e,s)}}})]}}),ne.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:n,options:e}=this;return[new ue({key:new Te("selection"),props:{decorations(t){return t.selection.empty||n.isFocused||!n.isEditable||g0(t.selection)||n.view.dragging?null:re.create(t.doc,[Ae.inline(t.selection.from,t.selection.to,{class:e.className})])}}})]}});function Dd({types:n,node:e}){return e&&Array.isArray(n)&&n.includes(e.type)||(e==null?void 0:e.type)===n}ne.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var n;const e=new Te(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 ue({key:e,appendTransaction:(r,s,i)=>{const{doc:l,tr:a,schema:d}=i,u=e.getState(i),f=l.content.size,p=d.nodes[t];if(u)return a.insert(f,p.create())},state:{init:(r,s)=>{const i=s.tr.doc.lastChild;return!Dd({node:i,types:o})},apply:(r,s)=>{if(!r.docChanged||r.getMeta("__uniqueIDTransaction"))return s;const i=r.doc.lastChild;return!Dd({node:i,types:o})}}})]}});var e1=ne.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>Ad(n,e),redo:()=>({state:n,dispatch:e})=>Id(n,e)}},addProseMirrorPlugins(){return[Zy(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()}}});function _t(n,e){const t=c.inject($e);if(!t)throw new Error("useComponents must be used within a WovenCanvas component");const o=c.shallowRef(new Map),r=new Map;function s(l){if(r.has(l))return;const a=t.getEditor();if(a){const u=a._getContext();if(x.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 a=r.get(l);if(a){a(),r.delete(l);const d=new Map(o.value);d.delete(l),o.value=d}}return c.watch(()=>c.toValue(n),(l,a)=>{const d=new Set(l),u=new Set(a??[]);for(const f of u)d.has(f)||i(f);for(const f of d)u.has(f)||s(f)},{immediate:!0}),c.onUnmounted(()=>{for(const l of r.values())l();r.clear()}),o}function Rd(){const n=c.inject($e);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 a=new window.Image;a.onload=()=>{i({width:a.naturalWidth,height:a.naturalHeight}),URL.revokeObjectURL(a.src)},a.onerror=()=>{l(new Error("Failed to load image")),URL.revokeObjectURL(a.src)},a.src=URL.createObjectURL(s)})}async function o(s,i,l,a={}){const{maxSize:d=400}=a,u=await t(s),f=await e(),p=Math.min(1,d/Math.max(u.width,u.height));let h=Math.round(u.width*p),m=Math.round(u.height*p);const g=x.Grid.read(f);g.enabled&&(h=Math.max(g.colWidth,Math.round(h/g.colWidth)*g.colWidth),m=Math.max(g.rowHeight,Math.round(m/g.rowHeight)*g.rowHeight));const y=x.createEntity(f);x.addComponent(f,y,x.Block);const k=x.Block.write(f,y);k.tag="image",k.position[0]=i-h/2,k.position[1]=l-m/2,k.size[0]=h,k.size[1]=m,x.Grid.snapPosition(f,k.position);const w=crypto.randomUUID();x.addComponent(f,y,x.Asset);const b=x.Asset.write(f,y);b.identifier=w,b.uploadState=x.UploadState.Pending,x.addComponent(f,y,x.Image);const S=x.Image.write(f,y);return S.width=u.width,S.height=u.height,S.alt=s.name,x.addComponent(f,y,Re.Synced,{id:crypto.randomUUID()}),(n==null?void 0:n.getAssetManager())&&r(y,w,s),y}async function r(s,i,l){const a=n==null?void 0:n.getAssetManager();if(a)try{await a.upload(i,l,{filename:l.name,mimeType:l.type});const d=await e(),u=x.Asset.write(d,s);u.uploadState=x.UploadState.Complete}catch{const d=await e(),u=x.Asset.write(d,s);u.uploadState=x.UploadState.Failed}}return{getImageDimensions:t,createImageBlock:o}}function _d(n){const e=c.inject($e);if(!e)throw new Error("useQuery must be used within a WovenCanvas component");const t=c.shallowRef([]),o=x.defineQuery(f=>f.with(...n)),r=new Map;let s=!1;function i(f){const p=e.getEditor();if(!p)return{refs:{},unsubscribes:[]};const h=p._getContext(),m={},g=[];for(const y of n){const k=c.shallowRef(y.snapshot(h,f));m[y.name]=k;const w=e.subscribeComponent(f,y.name,b=>{k.value=b});g.push(w)}return{refs:m,unsubscribes:g}}function l(f){const p=r.get(f);if(p){for(const h of p.unsubscribes)h();r.delete(f)}}function a(){const f=[];for(const[p,h]of r)f.push({entityId:p,...h.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=a(),s=!0;return}const p=o.added(f),h=o.removed(f);let m=!1;for(const g of h)l(g),m=!0;for(const g of p)r.has(g)||(r.set(g,i(g)),m=!0);m&&(t.value=a())}const u=e.registerTickCallback(d);return c.onUnmounted(()=>{u();for(const f of r.keys())l(f)}),t}function Se(n){const e=c.inject($e);if(!e)throw new Error("useSingleton must be used within a WovenCanvas component");const t=c.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}})),c.onUnmounted(()=>{r(),s==null||s()}),t}function Js(n,e,t){if(!n.closest(".wov-block")){const h=n.getBoundingClientRect();return{width:h.width,height:h.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),a=e.value.zoom,d=new DOMMatrix;d.translateSelf(-e.value.left*a,-e.value.top*a),d.scaleSelf(a,a),d.invertSelf();const u=d.transformPoint(l),f=n.offsetWidth,p=n.offsetHeight;return{width:f,height:p,left:u.x-f/2,top:u.y-p/2}}function Pd(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 lo(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 Gs(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 Vd(n){const e=Gs(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 a=0;const d=s===0?0:l/s*100,u=s*100;if(l!==0)switch(s){case t:a=((o-r)/l+(o<r?6:0))*60;break;case o:a=((r-t)/l+2)*60;break;case r:a=((t-o)/l+4)*60;break}return{h:a,s:d,v:u,a:e.alpha}}function $d(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),a=e*6-l,d=o*(1-t),u=o*(1-a*t),f=o*(1-(1-a)*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 p=h=>Math.round(h*255).toString(16).padStart(2,"0");return`#${p(r)}${p(s)}${p(i)}`}function Ld(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),a=e*6-l,d=o*(1-t),u=o*(1-a*t),f=o*(1-(1-a)*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 p=m=>Math.round(m*255).toString(16).padStart(2,"0"),h=Math.round(n.a).toString(16).padStart(2,"0");return n.a<255?`#${p(r)}${p(s)}${p(i)}${h}`:`#${p(r)}${p(s)}${p(i)}`}const Oe=c.shallowRef(null),Ys=c.shallowRef(null),Xs=c.shallowRef(null),Pt=c.ref(0);function ao(){const n={hasEditor:c.computed(()=>Oe.value!==null),isBold:c.computed(()=>{var r;return Pt.value,((r=Oe.value)==null?void 0:r.isActive("bold"))??!1}),isItalic:c.computed(()=>{var r;return Pt.value,((r=Oe.value)==null?void 0:r.isActive("italic"))??!1}),isUnderline:c.computed(()=>{var r;return Pt.value,((r=Oe.value)==null?void 0:r.isActive("underline"))??!1}),alignment:c.computed(()=>{Pt.value;const r=Oe.value;return r?r.isActive({textAlign:"center"})?"center":r.isActive({textAlign:"right"})?"right":r.isActive({textAlign:"justify"})?"justify":"left":"left"}),color:c.computed(()=>{Pt.value;const r=Oe.value;if(!r)return null;const i=r.getAttributes("textStyle").color??null;return i?Pd(i):null})},e={toggleBold(){const r=Oe.value;if(!r)return;const{from:s,to:i}=r.state.selection,l=s===i;let a=r.chain().focus();l&&(a=a.selectAll()),a=a.toggleBold(),l&&(a=a.setTextSelection(i)),a.run()},toggleItalic(){const r=Oe.value;if(!r)return;const{from:s,to:i}=r.state.selection,l=s===i;let a=r.chain().focus();l&&(a=a.selectAll()),a=a.toggleItalic(),l&&(a=a.setTextSelection(i)),a.run()},toggleUnderline(){const r=Oe.value;if(!r)return;const{from:s,to:i}=r.state.selection,l=s===i;let a=r.chain().focus();l&&(a=a.selectAll()),a=a.toggleUnderline(),l&&(a=a.setTextSelection(i)),a.run()},setAlignment(r){const s=Oe.value;s&&s.chain().selectAll().setTextAlign(r).run()},setColor(r){const s=Oe.value;if(!s)return;const{from:i,to:l}=s.state.selection;i===l?s.chain().focus().selectAll().setColor(r).setTextSelection(l).run():s.chain().focus().setColor(r).run()}};function t(r,s,i){Oe.value=r,Xs.value=s,Ys.value=i,r.on("selectionUpdate",()=>{Pt.value++}),r.on("transaction",()=>{Pt.value++})}function o(){Oe.value=null,Xs.value=null,Ys.value=null}return{editor:Oe,blockElement:Ys,textElement:Xs,state:n,commands:e,updateCounter:Pt,register:t,unregister:o}}const We=[hd,md,gd,js,vd,kd,wd,bd,xd.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:"left"})];function t1(n){return n.type==="text"&&typeof n.text=="string"}function rn(n,e){if(t1(n)){e(n);return}if(n.content)for(const t of n.content)rn(t,e)}function Zs(n,e){if(n.type==="paragraph"){e(n);return}if(n.content)for(const t of n.content)Zs(t,e)}function n1(n,e){var t;return((t=n.marks)==null?void 0:t.some(o=>o.type===e))??!1}function o1(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?Pd(t):null}function r1(n,e){if(!n.trim())return!1;const t=Dt(n,We);let o=!1,r=!0,s=0;return rn(t,i=>{s++,n1(i,e)?o=!0:r=!1}),s===0?!1:r?!0:o?null:!1}function s1(n){if(!n.trim())return"left";const e=Dt(n,We);let t="left";return Zs(e,o=>{var s;const r=(s=o.attrs)==null?void 0:s.textAlign;r&&(t=r)}),t}function i1(n){if(!n.trim())return null;const e=Dt(n,We);let t=null;return rn(e,o=>{t===null&&(t=o1(o))}),t}function Qs(n,e){if(!n.trim())return n;const t=Dt(n,We);return rn(t,o=>{const r=o.marks??[];r.findIndex(i=>i.type===e)===-1&&(o.marks=[...r,{type:e}])}),qo(t,We)}function ei(n,e){if(!n.trim())return n;const t=Dt(n,We);return rn(t,o=>{const r=o.marks??[];o.marks=r.filter(s=>s.type!==e)}),qo(t,We)}function l1(n,e){if(!n.trim())return n;const t=Dt(n,We);return Zs(t,o=>{o.attrs={...o.attrs,textAlign:e}}),qo(t,We)}function a1(n,e){if(!n.trim())return n;const t=Dt(n,We);return rn(t,o=>{const r=o.marks??[],s=r.findIndex(i=>i.type==="textStyle");s!==-1?(r[s]={...r[s],attrs:{...r[s].attrs,color:e}},o.marks=r):o.marks=[...r,{type:"textStyle",attrs:{color:e}}]}),qo(t,We)}function zd(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 Fd(n,e,t,o){var a;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,(a=n.parentElement)==null||a.appendChild(r);const l=Js(r,e,t);return r.remove(),l}function Hd(n){const{nextEditorTick:e}=le(),t=_t(n,x.Text),o=Se(x.Camera),r=Se(x.Screen),s=ao(),i={hasTextEntities:c.computed(()=>{for(const p of t.value.values())if(p)return!0;return!1}),hasTextContent:c.computed(()=>{for(const p of t.value.values()){if(!p)continue;const h=p.content?Dt(p.content,We):null;if(h){let m=!1;if(rn(h,g=>{var y;(y=g.text)!=null&&y.trim()&&(m=!0)}),m)return!0}}return!1}),isBold:c.computed(()=>l("bold")),isItalic:c.computed(()=>l("italic")),isUnderline:c.computed(()=>l("underline")),alignment:c.computed(()=>{let p=null;for(const h of t.value.values()){if(!h)continue;const m=s1(h.content);if(p===null)p=m;else if(p!==m)return null}return p??"left"}),color:c.computed(()=>{let p=null,h=!1;for(const m of t.value.values()){if(!m)continue;const g=i1(m.content);if(!h)p=g,h=!0;else if(p!==g)return null}return p}),fontSize:c.computed(()=>{let p=null,h=!1;for(const m of t.value.values())if(m){if(!h)p=m.fontSizePx,h=!0;else if(p!==m.fontSizePx)return null}return p}),fontFamily:c.computed(()=>{let p=null,h=!1;for(const m of t.value.values())if(m){if(!h)p=m.fontFamily,h=!0;else if(p!==m.fontFamily)return null}return p})};function l(p){let h=null,m=!1;for(const g of t.value.values()){if(!g)continue;const y=r1(g.content,p);if(!m)h=y,m=!0;else if(h!==y)return null}return h}const a={toggleBold(){u(p=>i.isBold.value?ei(p,"bold"):Qs(p,"bold"))},toggleItalic(){u(p=>i.isItalic.value?ei(p,"italic"):Qs(p,"italic"))},toggleUnderline(){u(p=>i.isUnderline.value?ei(p,"underline"):Qs(p,"underline"))},setAlignment(p){f(h=>l1(h,p))},setColor(p){f(h=>a1(h,p))},setFontSize(p){d(h=>({...h,fontSizePx:p}),h=>{h.fontSizePx=p})},setFontFamily(p){d(h=>({...h,fontFamily:p}),h=>{h.fontFamily=p})},setTextStyle(p){d(h=>({...h,fontFamily:p.fontFamily??h.fontFamily,fontSizePx:p.fontSizePx??h.fontSizePx,lineHeight:p.lineHeight??h.lineHeight,letterSpacingEm:p.letterSpacingEm??h.letterSpacingEm}),h=>{p.fontFamily!==void 0&&(h.fontFamily=p.fontFamily),p.fontSizePx!==void 0&&(h.fontSizePx=p.fontSizePx),p.lineHeight!==void 0&&(h.lineHeight=p.lineHeight),p.letterSpacingEm!==void 0&&(h.letterSpacingEm=p.letterSpacingEm)})}};function d(p,h){const m=c.toValue(n),g=[];for(const y of m){const k=t.value.get(y);if(!k)continue;const w=zd(y);if(w){const b=Fd(w,o,r,p(k));g.push({entityId:y,...b})}}e(y=>{for(const k of m)h(x.Text.write(y,k));for(const{entityId:k,width:w,height:b,left:S,top:C}of g){const M=x.Block.write(y,k);M.size=[w,b],M.position=[S,C]}c.nextTick(()=>{var k;s.updateCounter.value++,(k=s.editor.value)==null||k.commands.focus()})})}function u(p){const h=c.toValue(n),m=[];for(const g of h){const y=t.value.get(g);if(!y)continue;const k=p(y.content),w=zd(g);if(w){const b=Fd(w,o,r,{...y,content:k});m.push({entityId:g,content:k,...b})}else m.push({entityId:g,content:k,width:0,height:0,left:0,top:0})}e(g=>{for(const{entityId:y,content:k,width:w,height:b,left:S,top:C}of m){const M=x.Text.write(g,y);if(M.content=k,w>0&&b>0){const v=x.Block.write(g,y);v.size=[w,b],v.position=[S,C]}}})}function f(p){const h=c.toValue(n);e(m=>{for(const g of h){const y=x.Text.write(m,g);y.content=p(y.content)}})}return{state:i,commands:a}}function ot(n){const e=ao(),t=Hd(n),o=e.state.hasEditor;return{state:c.reactive({hasTextToFormat:c.computed(()=>o.value||t.state.hasTextEntities.value),hasEditor:o,hasTextContent:c.computed(()=>t.state.hasTextContent.value),showTextMenuButtons:c.computed(()=>o.value||t.state.hasTextContent.value),isBold:c.computed(()=>o.value?e.state.isBold.value:t.state.isBold.value===!0),isItalic:c.computed(()=>o.value?e.state.isItalic.value:t.state.isItalic.value===!0),isUnderline:c.computed(()=>o.value?e.state.isUnderline.value:t.state.isUnderline.value===!0),alignment:c.computed(()=>o.value?e.state.alignment.value:t.state.alignment.value??"left"),color:c.computed(()=>o.value?e.state.color.value:t.state.color.value),fontSize:c.computed(()=>t.state.fontSize.value),fontFamily:c.computed(()=>t.state.fontFamily.value)}),commands:{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(i){o.value?e.commands.setAlignment(i):t.commands.setAlignment(i)},setColor(i){o.value?e.commands.setColor(i):t.commands.setColor(i)},setFontSize(i){t.commands.setFontSize(i)},setFontFamily(i){t.commands.setFontFamily(i)},setTextStyle(i){t.commands.setTextStyle(i)}}}}function ti(n){const e=Se(x.Camera),t=Se(x.Screen),o=Se(oe.TransformBoxStateSingleton),r=Se(oe.SelectionStateSingleton),{nextEditorTick:s}=le();let i=!1,l=null;function a(u,f){const{entityId:p}=c.toValue(n.blockData),h=c.toValue(n.minWidth)??0,m=c.toValue(n.minHeight)??0,g=Math.max(f.width,h),y=Math.max(f.height,m),k=x.Block.read(u,p),w=Math.abs(k.size[0]-g)>.5,b=Math.abs(k.size[1]-y)>.5;if(!w&&!b)return;const S=x.Block.write(u,p);S.size=[g,y],S.position=[f.left,f.top],o.value.transformBoxId!==null&&oe.UpdateTransformBox.spawn(u,{transformBoxId:o.value.transformBoxId})}c.watch(()=>r.value,()=>{s(u=>{const f=c1(u);if(i&&!f){const p=n.containerRef.value;if(!p)return;l=Js(p,e,t),a(u,l),l=null}i=f})},{flush:"sync"});function d(u){const{content:f,...p}=u;s(h=>{const{entityId:m}=c.toValue(n.blockData);if(x.Text.read(h,m).content!==f){const y=x.Text.write(h,m);y.content=f}a(h,p)})}return{handleEditEnd:d}}function c1(n){const e=oe.SelectionStateSingleton.read(n);return e.state===oe.SelectionState.Dragging&&e.draggedEntity!==null&&x.hasComponent(n,e.draggedEntity,oe.TransformHandle)&&oe.TransformHandle.read(n,e.draggedEntity).kind===oe.TransformHandleKind.Stretch}function ni(){const n=c.inject(Ar);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=>c.computed(()=>n.activeTool.value===e)}}const d1=500,u1=1500;function Wd(){const n=c.ref(null),e=c.ref(!1),t=c.ref(!1);let o=null,r=null;function s(){o&&(clearTimeout(o),o=null),r&&(clearTimeout(r),r=null)}function i(d,u){s(),n.value={text:d,anchor:u},t.value?e.value=!0:o=setTimeout(()=>{e.value=!0,t.value=!0,o=null},d1)}function l(){s(),e.value=!1,n.value=null,t.value&&(r=setTimeout(()=>{t.value=!1,r=null},u1))}function a(){s(),e.value=!1,n.value=null,t.value=!1}return{activeTooltip:c.readonly(n),isVisible:c.readonly(e),isWarmedUp:c.readonly(t),show:i,hide:l,reset:a}}function Vt(){const n=c.inject(Ri);if(!n)throw new Error("useTooltipSingleton must be used within a WovenCanvas component");return n}const f1={key:1},h1=["innerHTML"],jd=50,p1=300,sr=c.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 v;const o=n,r=t,s=fe(o.entityId,x.Text),i=Se(x.Camera),l=Se(x.Screen),a=ao(),{nextEditorTick:d}=le(),u=Se(x.Mouse),f=c.ref(null);e({editableTextRef:f});const p=c.ref(((v=s.value)==null?void 0:v.content)??""),h=c.shallowRef(null);function m(E){const A=new DOMParser().parseFromString(E,"text/html");return A.body.querySelectorAll("[style], [class]").forEach(R=>{R.removeAttribute("style"),R.removeAttribute("class")}),A.body.innerHTML}function g(){d(E=>{const T=x.Text.write(E,o.entityId);T.constrainWidth=!0;const A=x.Block.read(E,o.entityId),R=Math.max(A.size[0],p1),$=x.Block.write(E,o.entityId);$.size=[R,A.size[1]],x.ResetKeyboard.spawn(E),oe.DeselectAll.spawn(E)})}function y(E,T){var j,K,Z;const A=s.value;if(!A)return!1;const R=((j=T.clipboardData)==null?void 0:j.getData("text/html"))??"",$=((K=T.clipboardData)==null?void 0:K.getData("text/plain"))??"";return!R.includes("data-pm-slice")&&R?(T.preventDefault(),(Z=h.value)==null||Z.commands.insertContent(m(R),{parseOptions:{preserveWhitespace:!0}}),!A.constrainWidth&&$.length>jd&&g(),!0):(!A.constrainWidth&&$.length>jd&&g(),!1)}function k(){var E,T;return new uy({extensions:[hd,md,gd,js,vd,kd,wd,bd,xd.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:((E=s.value)==null?void 0:E.defaultAlignment)??"left"}),e1],content:((T=s.value)==null?void 0:T.content)??"",editable:!0,parseOptions:{preserveWhitespace:!0},editorProps:{handlePaste:y}})}c.watch(()=>o.edited,async E=>{if(E&&f.value){if(h.value=k(),await w(h.value),!o.blockElement)return;a.register(h.value,f.value,o.blockElement)}else h.value&&(a.unregister(),b(h.value),h.value.destroy(),h.value=null)},{immediate:!0});async function w(E){var $;const T=($=u.value)==null?void 0:$.position,A=l.value;await c.nextTick(),await new Promise(z=>requestAnimationFrame(z));const R=f.value;if(T&&A&&R){const z=T[0]+A.left,j=T[1]+A.top,K=E.view.posAtCoords({left:z,top:j});if(K){E.chain().focus().setTextSelection(K.pos).run();return}}E.commands.focus("start")}function b(E){let T=E.getHTML();const R=T.replace(/<[^>]*>/g,"").trim().length>0;R||(T=""),p.value=T,d($=>{var U,L;const z=x.getBlockDef($,o.block.tag);if(!R&&((U=z.editOptions)!=null&&U.removeWhenTextEmpty)){x.removeEntity($,o.entityId);return}const j=(L=f.value)==null?void 0:L.closest(".wov-block"),K=(j==null?void 0:j.firstElementChild)??f.value;if(!K){console.warn("EditableText: no element to measure");return}const Z=Js(K,i,l);r("editEnd",{content:T,...Z})})}c.watch(()=>{var E;return(E=s.value)==null?void 0:E.content},E=>{E!==void 0&&(h.value?h.value.getHTML()!==E&&h.value.commands.setContent(E,{emitUpdate:!1}):p.value=E)});const S=c.computed(()=>{const E=s.value;if(!E)return{};const[T,A]=o.block.flip,R=T?-1:1,$=A?-1:1,z=T||A;return{fontFamily:E.fontFamily,fontSize:`${E.fontSizePx}px`,lineHeight:E.lineHeight,letterSpacing:`${E.letterSpacingEm}em`,width:E.constrainWidth?"100%":"fit-content",whiteSpace:E.constrainWidth?"pre-wrap":"pre",minWidth:"2px",wordBreak:"break-word",pointerEvents:o.edited?"auto":"none",userSelect:o.edited?"auto":"none",transform:z?`scale(${R}, ${$})`:void 0}});function C(E){E.key==="Control"||E.key==="Meta"||E.stopPropagation()}function M(E){o.edited&&E.stopPropagation()}return c.onUnmounted(()=>{h.value&&(a.unregister(),h.value.destroy(),h.value=null)}),(E,T)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"editableTextRef",ref:f,class:"wov-editable-text",style:c.normalizeStyle(S.value),onKeydown:C,onPointerdown:M,onPointermove:M,onPointerup:M},[h.value?(c.openBlock(),c.createBlock(c.unref(fy),{key:0,editor:h.value},null,8,["editor"])):(c.openBlock(),c.createElementBlock("div",f1,[c.createElementVNode("div",{class:"tiptap ProseMirror",innerHTML:p.value},null,8,h1)]))],36))}}),m1={class:"wov-shape-svg",viewBox:"0 0 100 100",preserveAspectRatio:"none"},g1=["d","fill","stroke","stroke-width","stroke-dasharray"],Ud=c.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,x.Shape),o=fe(e.entityId,x.VerticalAlign),r=c.ref(null),s={[x.VerticalAlignment.Top]:"flex-start",[x.VerticalAlignment.Center]:"center",[x.VerticalAlignment.Bottom]:"flex-end"},i=c.computed(()=>t.value?`rgba(${t.value.fillRed}, ${t.value.fillGreen}, ${t.value.fillBlue}, ${(t.value.fillAlpha??255)/255})`:"rgba(0, 0, 0, 0)"),l=c.computed(()=>t.value?t.value.strokeKind===x.StrokeKind.None?"none":`rgba(${t.value.strokeRed}, ${t.value.strokeGreen}, ${t.value.strokeBlue}, ${t.value.strokeAlpha/255})`:"rgba(0, 0, 0, 1)"),a=c.computed(()=>{var g;return((g=t.value)==null?void 0:g.strokeWidth)??2}),d=c.computed(()=>{var g;return((g=t.value)==null?void 0:g.strokeKind)??x.StrokeKind.Solid}),u=c.computed(()=>{var g;return Pn[((g=t.value)==null?void 0:g.kind)??"rectangle"]??Pn.rectangle}),f=c.computed(()=>{const g=a.value;switch(d.value){case x.StrokeKind.Dashed:return`${g*3} ${g*3}`;case x.StrokeKind.None:return"";case x.StrokeKind.Solid:default:return""}}),p=c.computed(()=>{var g;return{overflow:e.edited?"visible":"hidden",alignItems:s[((g=o.value)==null?void 0:g.value)??x.VerticalAlignment.Top]}}),{nextEditorTick:h}=le();function m(g){h(y=>{if(x.Text.read(y,e.entityId).content===g.content)return;const w=x.Text.write(y,e.entityId);w.content=g.content})}return(g,y)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:r,class:"wov-shape-block"},[(c.openBlock(),c.createElementBlock("svg",m1,[c.createElementVNode("path",{d:u.value,fill:i.value,stroke:l.value,"stroke-width":a.value,"stroke-dasharray":f.value,"stroke-linecap":"round","stroke-linejoin":"round","vector-effect":"non-scaling-stroke"},null,8,g1)])),c.createElementVNode("div",{class:"wov-shape-content",style:c.normalizeStyle(p.value)},[c.createVNode(sr,c.mergeProps(e,{"block-element":r.value,onEditEnd:m}),null,16,["block-element"])],4)],512))}}),y1=["data-text-empty"],Kd=c.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=c.ref(null),o=fe(e.entityId,x.Text),r=c.computed(()=>{var d;return(((d=o.value)==null?void 0:d.content)??"").replace(/<[^>]*>/g,"").trim().length===0}),s=c.computed(()=>{var l;return((l=o.value)==null?void 0:l.constrainWidth)??!1}),{handleEditEnd:i}=ti({blockData:e,containerRef:t});return(l,a)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-text-block","data-text-empty":r.value||void 0,style:c.normalizeStyle({width:s.value?"100%":"fit-content"})},[c.createVNode(sr,c.mergeProps(e,{"block-element":t.value,onEditEnd:c.unref(i)}),null,16,["block-element","onEditEnd"])],12,y1))}}),ir=Math.min,sn=Math.max,lr=Math.round,ar=Math.floor,rt=n=>({x:n,y:n}),k1={left:"right",right:"left",bottom:"top",top:"bottom"},w1={start:"end",end:"start"};function qd(n,e,t){return sn(n,ir(e,t))}function cr(n,e){return typeof n=="function"?n(e):n}function ln(n){return n.split("-")[0]}function dr(n){return n.split("-")[1]}function Jd(n){return n==="x"?"y":"x"}function Gd(n){return n==="y"?"height":"width"}const b1=new Set(["top","bottom"]);function $t(n){return b1.has(ln(n))?"y":"x"}function Yd(n){return Jd($t(n))}function x1(n,e,t){t===void 0&&(t=!1);const o=dr(n),r=Yd(n),s=Gd(r);let i=r==="x"?o===(t?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=ur(i)),[i,ur(i)]}function S1(n){const e=ur(n);return[oi(n),e,oi(e)]}function oi(n){return n.replace(/start|end/g,e=>w1[e])}const Xd=["left","right"],Zd=["right","left"],C1=["top","bottom"],v1=["bottom","top"];function E1(n,e,t){switch(n){case"top":case"bottom":return t?e?Zd:Xd:e?Xd:Zd;case"left":case"right":return e?C1:v1;default:return[]}}function M1(n,e,t,o){const r=dr(n);let s=E1(ln(n),t==="start",o);return r&&(s=s.map(i=>i+"-"+r),e&&(s=s.concat(s.map(oi)))),s}function ur(n){return n.replace(/left|right|bottom|top/g,e=>k1[e])}function T1(n){return{top:0,right:0,bottom:0,left:0,...n}}function N1(n){return typeof n!="number"?T1(n):{top:n,right:n,bottom:n,left:n}}function fr(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 Qd(n,e,t){let{reference:o,floating:r}=n;const s=$t(e),i=Yd(e),l=Gd(i),a=ln(e),d=s==="y",u=o.x+o.width/2-r.width/2,f=o.y+o.height/2-r.height/2,p=o[l]/2-r[l]/2;let h;switch(a){case"top":h={x:u,y:o.y-r.height};break;case"bottom":h={x:u,y:o.y+o.height};break;case"right":h={x:o.x+o.width,y:f};break;case"left":h={x:o.x-r.width,y:f};break;default:h={x:o.x,y:o.y}}switch(dr(e)){case"start":h[i]-=p*(t&&d?-1:1);break;case"end":h[i]+=p*(t&&d?-1:1);break}return h}async function B1(n,e){var t;e===void 0&&(e={});const{x:o,y:r,platform:s,rects:i,elements:l,strategy:a}=n,{boundary:d="clippingAncestors",rootBoundary:u="viewport",elementContext:f="floating",altBoundary:p=!1,padding:h=0}=cr(e,n),m=N1(h),y=l[p?f==="floating"?"reference":"floating":f],k=fr(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:a})),w=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=fr(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:w,offsetParent:b,strategy:a}):w);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 A1=async(n,e,t)=>{const{placement:o="bottom",strategy:r="absolute",middleware:s=[],platform:i}=t,l=s.filter(Boolean),a=await(i.isRTL==null?void 0:i.isRTL(e));let d=await i.getElementRects({reference:n,floating:e,strategy:r}),{x:u,y:f}=Qd(d,o,a),p=o,h={},m=0;for(let y=0;y<l.length;y++){var g;const{name:k,fn:w}=l[y],{x:b,y:S,data:C,reset:M}=await w({x:u,y:f,initialPlacement:o,placement:p,strategy:r,middlewareData:h,rects:d,platform:{...i,detectOverflow:(g=i.detectOverflow)!=null?g:B1},elements:{reference:n,floating:e}});u=b??u,f=S??f,h={...h,[k]:{...h[k],...C}},M&&m<=50&&(m++,typeof M=="object"&&(M.placement&&(p=M.placement),M.rects&&(d=M.rects===!0?await i.getElementRects({reference:n,floating:e,strategy:r}):M.rects),{x:u,y:f}=Qd(d,p,a)),y=-1)}return{x:u,y:f,placement:p,strategy:r,middlewareData:h}},I1=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:a,elements:d}=e,{mainAxis:u=!0,crossAxis:f=!0,fallbackPlacements:p,fallbackStrategy:h="bestFit",fallbackAxisSideDirection:m="none",flipAlignment:g=!0,...y}=cr(n,e);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const k=ln(r),w=$t(l),b=ln(l)===l,S=await(a.isRTL==null?void 0:a.isRTL(d.floating)),C=p||(b||!g?[ur(l)]:S1(l)),M=m!=="none";!p&&M&&C.push(...M1(l,g,m,S));const v=[l,...C],E=await a.detectOverflow(e,y),T=[];let A=((o=s.flip)==null?void 0:o.overflows)||[];if(u&&T.push(E[k]),f){const j=x1(r,i,S);T.push(E[j[0]],E[j[1]])}if(A=[...A,{placement:r,overflows:T}],!T.every(j=>j<=0)){var R,$;const j=(((R=s.flip)==null?void 0:R.index)||0)+1,K=v[j];if(K&&(!(f==="alignment"?w!==$t(K):!1)||A.every(L=>$t(L.placement)===w?L.overflows[0]>0:!0)))return{data:{index:j,overflows:A},reset:{placement:K}};let Z=($=A.filter(U=>U.overflows[0]<=0).sort((U,L)=>U.overflows[1]-L.overflows[1])[0])==null?void 0:$.placement;if(!Z)switch(h){case"bestFit":{var z;const U=(z=A.filter(L=>{if(M){const W=$t(L.placement);return W===w||W==="y"}return!0}).map(L=>[L.placement,L.overflows.filter(W=>W>0).reduce((W,X)=>W+X,0)]).sort((L,W)=>L[1]-W[1])[0])==null?void 0:z[0];U&&(Z=U);break}case"initialPlacement":Z=l;break}if(r!==Z)return{reset:{placement:Z}}}return{}}}},O1=new Set(["left","top"]);async function D1(n,e){const{placement:t,platform:o,elements:r}=n,s=await(o.isRTL==null?void 0:o.isRTL(r.floating)),i=ln(t),l=dr(t),a=$t(t)==="y",d=O1.has(i)?-1:1,u=s&&a?-1:1,f=cr(e,n);let{mainAxis:p,crossAxis:h,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"&&(h=l==="end"?m*-1:m),a?{x:h*u,y:p*d}:{x:p*d,y:h*u}}const R1=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,a=await D1(e,n);return i===((t=l.offset)==null?void 0:t.placement)&&(o=l.arrow)!=null&&o.alignmentOffset?{}:{x:r+a.x,y:s+a.y,data:{...a,placement:i}}}}},_1=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:a={fn:k=>{let{x:w,y:b}=k;return{x:w,y:b}}},...d}=cr(n,e),u={x:t,y:o},f=await s.detectOverflow(e,d),p=$t(ln(r)),h=Jd(p);let m=u[h],g=u[p];if(i){const k=h==="y"?"top":"left",w=h==="y"?"bottom":"right",b=m+f[k],S=m-f[w];m=qd(b,m,S)}if(l){const k=p==="y"?"top":"left",w=p==="y"?"bottom":"right",b=g+f[k],S=g-f[w];g=qd(b,g,S)}const y=a.fn({...e,[h]:m,[p]:g});return{...y,data:{x:y.x-t,y:y.y-o,enabled:{[h]:i,[p]:l}}}}}};function hr(){return typeof window<"u"}function an(n){return ri(n)?(n.nodeName||"").toLowerCase():"#document"}function Ve(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function st(n){var e;return(e=(ri(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function ri(n){return hr()?n instanceof Node||n instanceof Ve(n).Node:!1}function Je(n){return hr()?n instanceof Element||n instanceof Ve(n).Element:!1}function it(n){return hr()?n instanceof HTMLElement||n instanceof Ve(n).HTMLElement:!1}function eu(n){return!hr()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof Ve(n).ShadowRoot}const P1=new Set(["inline","contents"]);function co(n){const{overflow:e,overflowX:t,overflowY:o,display:r}=Ge(n);return/auto|scroll|overlay|hidden|clip/.test(e+o+t)&&!P1.has(r)}const V1=new Set(["table","td","th"]);function $1(n){return V1.has(an(n))}const L1=[":popover-open",":modal"];function pr(n){return L1.some(e=>{try{return n.matches(e)}catch{return!1}})}const z1=["transform","translate","scale","rotate","perspective"],F1=["transform","translate","scale","rotate","perspective","filter"],H1=["paint","layout","strict","content"];function si(n){const e=ii(),t=Je(n)?Ge(n):n;return z1.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)||F1.some(o=>(t.willChange||"").includes(o))||H1.some(o=>(t.contain||"").includes(o))}function W1(n){let e=Lt(n);for(;it(e)&&!An(e);){if(si(e))return e;if(pr(e))return null;e=Lt(e)}return null}function ii(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const j1=new Set(["html","body","#document"]);function An(n){return j1.has(an(n))}function Ge(n){return Ve(n).getComputedStyle(n)}function mr(n){return Je(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function Lt(n){if(an(n)==="html")return n;const e=n.assignedSlot||n.parentNode||eu(n)&&n.host||st(n);return eu(e)?e.host:e}function tu(n){const e=Lt(n);return An(e)?n.ownerDocument?n.ownerDocument.body:n.body:it(e)&&co(e)?e:tu(e)}function uo(n,e,t){var o;e===void 0&&(e=[]),t===void 0&&(t=!0);const r=tu(n),s=r===((o=n.ownerDocument)==null?void 0:o.body),i=Ve(r);if(s){const l=li(i);return e.concat(i,i.visualViewport||[],co(r)?r:[],l&&t?uo(l):[])}return e.concat(r,uo(r,[],t))}function li(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function nu(n){const e=Ge(n);let t=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=it(n),s=r?n.offsetWidth:t,i=r?n.offsetHeight:o,l=lr(t)!==s||lr(o)!==i;return l&&(t=s,o=i),{width:t,height:o,$:l}}function ai(n){return Je(n)?n:n.contextElement}function In(n){const e=ai(n);if(!it(e))return rt(1);const t=e.getBoundingClientRect(),{width:o,height:r,$:s}=nu(e);let i=(s?lr(t.width):t.width)/o,l=(s?lr(t.height):t.height)/r;return(!i||!Number.isFinite(i))&&(i=1),(!l||!Number.isFinite(l))&&(l=1),{x:i,y:l}}const U1=rt(0);function ou(n){const e=Ve(n);return!ii()||!e.visualViewport?U1:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function K1(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==Ve(n)?!1:e}function cn(n,e,t,o){e===void 0&&(e=!1),t===void 0&&(t=!1);const r=n.getBoundingClientRect(),s=ai(n);let i=rt(1);e&&(o?Je(o)&&(i=In(o)):i=In(n));const l=K1(s,t,o)?ou(s):rt(0);let a=(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 p=Ve(s),h=o&&Je(o)?Ve(o):o;let m=p,g=li(m);for(;g&&o&&h!==m;){const y=In(g),k=g.getBoundingClientRect(),w=Ge(g),b=k.left+(g.clientLeft+parseFloat(w.paddingLeft))*y.x,S=k.top+(g.clientTop+parseFloat(w.paddingTop))*y.y;a*=y.x,d*=y.y,u*=y.x,f*=y.y,a+=b,d+=S,m=Ve(g),g=li(m)}}return fr({width:u,height:f,x:a,y:d})}function gr(n,e){const t=mr(n).scrollLeft;return e?e.left+t:cn(st(n)).left+t}function ru(n,e){const t=n.getBoundingClientRect(),o=t.left+e.scrollLeft-gr(n,t),r=t.top+e.scrollTop;return{x:o,y:r}}function q1(n){let{elements:e,rect:t,offsetParent:o,strategy:r}=n;const s=r==="fixed",i=st(o),l=e?pr(e.floating):!1;if(o===i||l&&s)return t;let a={scrollLeft:0,scrollTop:0},d=rt(1);const u=rt(0),f=it(o);if((f||!f&&!s)&&((an(o)!=="body"||co(i))&&(a=mr(o)),it(o))){const h=cn(o);d=In(o),u.x=h.x+o.clientLeft,u.y=h.y+o.clientTop}const p=i&&!f&&!s?ru(i,a):rt(0);return{width:t.width*d.x,height:t.height*d.y,x:t.x*d.x-a.scrollLeft*d.x+u.x+p.x,y:t.y*d.y-a.scrollTop*d.y+u.y+p.y}}function J1(n){return Array.from(n.getClientRects())}function G1(n){const e=st(n),t=mr(n),o=n.ownerDocument.body,r=sn(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),s=sn(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let i=-t.scrollLeft+gr(n);const l=-t.scrollTop;return Ge(o).direction==="rtl"&&(i+=sn(e.clientWidth,o.clientWidth)-r),{width:r,height:s,x:i,y:l}}const su=25;function Y1(n,e){const t=Ve(n),o=st(n),r=t.visualViewport;let s=o.clientWidth,i=o.clientHeight,l=0,a=0;if(r){s=r.width,i=r.height;const u=ii();(!u||u&&e==="fixed")&&(l=r.offsetLeft,a=r.offsetTop)}const d=gr(o);if(d<=0){const u=o.ownerDocument,f=u.body,p=getComputedStyle(f),h=u.compatMode==="CSS1Compat"&&parseFloat(p.marginLeft)+parseFloat(p.marginRight)||0,m=Math.abs(o.clientWidth-f.clientWidth-h);m<=su&&(s-=m)}else d<=su&&(s+=d);return{width:s,height:i,x:l,y:a}}const X1=new Set(["absolute","fixed"]);function Z1(n,e){const t=cn(n,!0,e==="fixed"),o=t.top+n.clientTop,r=t.left+n.clientLeft,s=it(n)?In(n):rt(1),i=n.clientWidth*s.x,l=n.clientHeight*s.y,a=r*s.x,d=o*s.y;return{width:i,height:l,x:a,y:d}}function iu(n,e,t){let o;if(e==="viewport")o=Y1(n,t);else if(e==="document")o=G1(st(n));else if(Je(e))o=Z1(e,t);else{const r=ou(n);o={x:e.x-r.x,y:e.y-r.y,width:e.width,height:e.height}}return fr(o)}function lu(n,e){const t=Lt(n);return t===e||!Je(t)||An(t)?!1:Ge(t).position==="fixed"||lu(t,e)}function Q1(n,e){const t=e.get(n);if(t)return t;let o=uo(n,[],!1).filter(l=>Je(l)&&an(l)!=="body"),r=null;const s=Ge(n).position==="fixed";let i=s?Lt(n):n;for(;Je(i)&&!An(i);){const l=Ge(i),a=si(i);!a&&l.position==="fixed"&&(r=null),(s?!a&&!r:!a&&l.position==="static"&&!!r&&X1.has(r.position)||co(i)&&!a&&lu(n,i))?o=o.filter(u=>u!==i):r=l,i=Lt(i)}return e.set(n,o),o}function ek(n){let{element:e,boundary:t,rootBoundary:o,strategy:r}=n;const i=[...t==="clippingAncestors"?pr(e)?[]:Q1(e,this._c):[].concat(t),o],l=i[0],a=i.reduce((d,u)=>{const f=iu(e,u,r);return d.top=sn(f.top,d.top),d.right=ir(f.right,d.right),d.bottom=ir(f.bottom,d.bottom),d.left=sn(f.left,d.left),d},iu(e,l,r));return{width:a.right-a.left,height:a.bottom-a.top,x:a.left,y:a.top}}function tk(n){const{width:e,height:t}=nu(n);return{width:e,height:t}}function nk(n,e,t){const o=it(e),r=st(e),s=t==="fixed",i=cn(n,!0,s,e);let l={scrollLeft:0,scrollTop:0};const a=rt(0);function d(){a.x=gr(r)}if(o||!o&&!s)if((an(e)!=="body"||co(r))&&(l=mr(e)),o){const h=cn(e,!0,s,e);a.x=h.x+e.clientLeft,a.y=h.y+e.clientTop}else r&&d();s&&!o&&r&&d();const u=r&&!o&&!s?ru(r,l):rt(0),f=i.left+l.scrollLeft-a.x-u.x,p=i.top+l.scrollTop-a.y-u.y;return{x:f,y:p,width:i.width,height:i.height}}function ci(n){return Ge(n).position==="static"}function au(n,e){if(!it(n)||Ge(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return st(n)===t&&(t=t.ownerDocument.body),t}function cu(n,e){const t=Ve(n);if(pr(n))return t;if(!it(n)){let r=Lt(n);for(;r&&!An(r);){if(Je(r)&&!ci(r))return r;r=Lt(r)}return t}let o=au(n,e);for(;o&&$1(o)&&ci(o);)o=au(o,e);return o&&An(o)&&ci(o)&&!si(o)?t:o||W1(n)||t}const ok=async function(n){const e=this.getOffsetParent||cu,t=this.getDimensions,o=await t(n.floating);return{reference:nk(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function rk(n){return Ge(n).direction==="rtl"}const sk={convertOffsetParentRelativeRectToViewportRelativeRect:q1,getDocumentElement:st,getClippingRect:ek,getOffsetParent:cu,getElementRects:ok,getClientRects:J1,getDimensions:tk,getScale:In,isElement:Je,isRTL:rk};function du(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function ik(n,e){let t=null,o;const r=st(n);function s(){var l;clearTimeout(o),(l=t)==null||l.disconnect(),t=null}function i(l,a){l===void 0&&(l=!1),a===void 0&&(a=1),s();const d=n.getBoundingClientRect(),{left:u,top:f,width:p,height:h}=d;if(l||e(),!p||!h)return;const m=ar(f),g=ar(r.clientWidth-(u+p)),y=ar(r.clientHeight-(f+h)),k=ar(u),b={rootMargin:-m+"px "+-g+"px "+-y+"px "+-k+"px",threshold:sn(0,ir(1,a))||1};let S=!0;function C(M){const v=M[0].intersectionRatio;if(v!==a){if(!S)return i();v?i(!1,v):o=setTimeout(()=>{i(!1,1e-7)},1e3)}v===1&&!du(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 uu(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:a=!1}=o,d=ai(n),u=r||s?[...d?uo(d):[],...uo(e)]:[];u.forEach(k=>{r&&k.addEventListener("scroll",t,{passive:!0}),s&&k.addEventListener("resize",t)});const f=d&&l?ik(d,t):null;let p=-1,h=null;i&&(h=new ResizeObserver(k=>{let[w]=k;w&&w.target===d&&h&&(h.unobserve(e),cancelAnimationFrame(p),p=requestAnimationFrame(()=>{var b;(b=h)==null||b.observe(e)})),t()}),d&&!a&&h.observe(d),h.observe(e));let m,g=a?cn(n):null;a&&y();function y(){const k=cn(n);g&&!du(g,k)&&t(),g=k,m=requestAnimationFrame(y)}return t(),()=>{var k;u.forEach(w=>{r&&w.removeEventListener("scroll",t),s&&w.removeEventListener("resize",t)}),f==null||f(),(k=h)==null||k.disconnect(),h=null,a&&cancelAnimationFrame(m)}}const yr=R1,kr=_1,wr=I1,lk=(n,e,t)=>{const o=new Map,r={platform:sk,...t},s={...r.platform,_c:o};return A1(n,e,{...r,platform:s})};function ak(n){return n!=null&&typeof n=="object"&&"$el"in n}function fu(n){if(ak(n)){const e=n.$el;return ri(e)&&an(e)==="#comment"?null:e}return n}function fo(n){return typeof n=="function"?n():c.unref(n)}function hu(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function pu(n,e){const t=hu(n);return Math.round(e*t)/t}function br(n,e,t){t===void 0&&(t={});const o=t.whileElementsMounted,r=c.computed(()=>{var v;return(v=fo(t.open))!=null?v:!0}),s=c.computed(()=>fo(t.middleware)),i=c.computed(()=>{var v;return(v=fo(t.placement))!=null?v:"bottom"}),l=c.computed(()=>{var v;return(v=fo(t.strategy))!=null?v:"absolute"}),a=c.computed(()=>{var v;return(v=fo(t.transform))!=null?v:!0}),d=c.computed(()=>fu(n.value)),u=c.computed(()=>fu(e.value)),f=c.ref(0),p=c.ref(0),h=c.ref(l.value),m=c.ref(i.value),g=c.shallowRef({}),y=c.ref(!1),k=c.computed(()=>{const v={position:h.value,left:"0",top:"0"};if(!u.value)return v;const E=pu(u.value,f.value),T=pu(u.value,p.value);return a.value?{...v,transform:"translate("+E+"px, "+T+"px)",...hu(u.value)>=1.5&&{willChange:"transform"}}:{position:h.value,left:E+"px",top:T+"px"}});let w;function b(){if(d.value==null||u.value==null)return;const v=r.value;lk(d.value,u.value,{middleware:s.value,placement:i.value,strategy:l.value}).then(E=>{f.value=E.x,p.value=E.y,h.value=E.strategy,m.value=E.placement,g.value=E.middlewareData,y.value=v!==!1})}function S(){typeof w=="function"&&(w(),w=void 0)}function C(){if(S(),o===void 0){b();return}if(d.value!=null&&u.value!=null){w=o(d.value,u.value,b);return}}function M(){r.value||(y.value=!1)}return c.watch([s,i,l,r],b,{flush:"sync"}),c.watch([d,u],C,{flush:"sync"}),c.watch(r,M,{flush:"sync"}),c.getCurrentScope()&&c.onScopeDispose(S),{x:c.shallowReadonly(f),y:c.shallowReadonly(p),strategy:c.shallowReadonly(h),placement:c.shallowReadonly(m),middlewareData:c.shallowReadonly(g),isPositioned:c.shallowReadonly(y),floatingStyles:k,update:b}}const ck=["menu-open"],je=c.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=c.inject("containerRef"),s=c.inject(Ii,null),i=c.inject(Oi,0),l=Math.random().toString(36).slice(2);c.provide(Oi,i+1);const{show:a,hide:d}=Vt(),u=c.ref(!1);s&&c.watch(()=>s.value.get(i),b=>{b!==void 0&&b!==l&&u.value&&(u.value=!1)});const f=c.ref(null),p=c.ref(null),{floatingStyles:h}=br(f,p,{placement:t.placement,middleware:[yr(t.offsetPx),wr(),kr({padding:8})],whileElementsMounted:uu});function m(){t.disabled||(u.value=!u.value)}function g(){u.value=!1}function y(b){var E,T,A;const S=b.target,C=(E=f.value)==null?void 0:E.contains(S),M=(T=p.value)==null?void 0:T.contains(S),v=(A=S.closest)==null?void 0:A.call(S,".wov-menu-dropdown");!C&&!M&&!v&&g()}function k(){t.title&&f.value&&!u.value&&a(t.title,f.value)}function w(){d()}return c.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"))}),c.onUnmounted(()=>{document.removeEventListener("click",y,!0)}),(b,S)=>(c.openBlock(),c.createElementBlock(c.Fragment,null,[c.createElementVNode("div",{ref_key:"buttonRef",ref:f,class:c.normalizeClass(["wov-menu-dropdown-trigger",{"is-open":u.value}]),"menu-open":u.value||void 0,onMousedown:S[0]||(S[0]=c.withModifiers(()=>{},["prevent"])),onClick:m,onMouseenter:k,onMouseleave:w},[c.renderSlot(b.$slots,"button",{isOpen:u.value})],42,ck),c.unref(r)?(c.openBlock(),c.createBlock(c.Teleport,{key:0,to:c.unref(r)},[u.value?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"dropdownRef",ref:p,class:"wov-menu-dropdown",style:c.normalizeStyle(c.unref(h))},[c.renderSlot(b.$slots,"dropdown",{close:g})],4)):c.createCommentVNode("",!0)],8,["to"])):c.createCommentVNode("",!0)],64))}}),dk={},uk={viewBox:"0 0 512 320",fill:"currentColor",style:{width:"7px",color:"var(--wov-gray-300)"}};function fk(n,e){return c.openBlock(),c.createElementBlock("svg",uk,[...e[0]||(e[0]=[c.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 Ue=Ht(dk,[["render",fk]]),hk={class:"wov-menu-button"},pk=["innerHTML"],mk=["onClick"],gk=["innerHTML"],di=c.defineComponent({__name:"ArrowHeadButton",props:{entityIds:{},side:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=c.shallowRef(null),r=c.computed(()=>{const l=o.value??(e.side==="start"?Y.ArrowHeadKind.None:Y.ArrowHeadKind.V);return pn(l)});t(l=>{let a=null;for(const d of e.entityIds){if(x.hasComponent(l,d,Y.ElbowArrow)){const u=Y.ElbowArrow.read(l,d),f=e.side==="start"?u.startArrowHead:u.endArrowHead;if(a===null)a=f;else if(f!==a){o.value=e.side==="start"?Y.ArrowHeadKind.None:Y.ArrowHeadKind.V;return}}if(x.hasComponent(l,d,Y.ArcArrow)){const u=Y.ArcArrow.read(l,d),f=e.side==="start"?u.startArrowHead:u.endArrowHead;if(a===null)a=f;else if(f!==a){o.value=e.side==="start"?Y.ArrowHeadKind.None:Y.ArrowHeadKind.V;return}}}o.value=a});function s(l){o.value=l,t(a=>{for(const d of e.entityIds){if(x.hasComponent(a,d,Y.ElbowArrow)){const u=Y.ElbowArrow.write(a,d);e.side==="start"?u.startArrowHead=l:u.endArrowHead=l}if(x.hasComponent(a,d,Y.ArcArrow)){const u=Y.ArcArrow.write(a,d);e.side==="start"?u.startArrowHead=l:u.endArrowHead=l}}})}function i(l){if(!l)return"";const a=e.side==="start";return`<line x1="${a?8:4}" y1="12" x2="${a?20:16}" y2="12" stroke="currentColor" stroke-width="2" stroke-linecap="round" /><g transform="${`translate(${a?4:20}, 12) scale(${a?"-0.8, 0.8":"0.8"})`}">${l.svg}</g>`}return(l,a)=>(c.openBlock(),c.createBlock(je,{title:n.side==="start"?"Start Arrow Head":"End Arrow Head"},{button:c.withCtx(()=>[c.createElementVNode("div",hk,[(c.openBlock(),c.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,pk)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(c.unref(Br),d=>(c.openBlock(),c.createElementBlock("button",{key:d.kind,class:c.normalizeClass(["wov-menu-option",{"is-active":o.value===d.kind}]),onClick:u=>s(d.kind)},[(c.openBlock(),c.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,gk))],10,mk))),128))]),_:1},8,["title"]))}}),yk={class:"wov-menu-button"},kk=["onClick"],mu=c.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=c.shallowRef(null);o(i=>{let l=null;for(const a of t.entityIds){if(x.hasComponent(i,a,Y.ElbowArrow)){const d=Y.ElbowArrow.read(i,a);if(l===null)l=d.thickness;else if(d.thickness!==l){r.value=null;return}}if(x.hasComponent(i,a,Y.ArcArrow)){const d=Y.ArcArrow.getThickness(i,a);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 a of t.entityIds){if(x.hasComponent(l,a,Y.ElbowArrow)){const d=Y.ElbowArrow.write(l,a);d.thickness=i}x.hasComponent(l,a,Y.ArcArrow)&&Y.ArcArrow.setThickness(l,a,i)}})}return(i,l)=>(c.openBlock(),c.createBlock(je,{title:"Thickness"},{button:c.withCtx(()=>[c.createElementVNode("div",yk,[l[0]||(l[0]=c.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"},[c.createElementVNode("line",{x1:"4",y1:"5",x2:"20",y2:"5","stroke-width":"1"}),c.createElementVNode("line",{x1:"4",y1:"11",x2:"20",y2:"11","stroke-width":"2.5"}),c.createElementVNode("line",{x1:"4",y1:"19",x2:"20",y2:"19","stroke-width":"4"})],-1)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[(c.openBlock(),c.createElementBlock(c.Fragment,null,c.renderList(e,a=>c.createElementVNode("button",{key:a.value,class:c.normalizeClass(["wov-menu-option wov-arrow-thickness-option",{"is-active":r.value===a.value}]),onClick:d=>s(a.value)},c.toDisplayString(a.label),11,kk)),64))]),_:1}))}}),wk=["value"],bk=c.defineComponent({__name:"ColorInput",props:{modelValue:{}},emits:["update:modelValue"],setup(n,{emit:e}){const t=n,o=e,r=c.ref(t.modelValue??"");c.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 p=u.target.value;if((p.length===6||p.length===7)&&s(p)){const h=i(p);r.value=h,o("update:modelValue",h)}}function a(u){const p=u.target.value;if(p&&s(p)){const h=i(p);r.value=h,o("update:modelValue",h)}else t.modelValue&&(r.value=t.modelValue)}function d(u){if(u.stopPropagation(),u.key==="Enter"){const f=u.target,p=f.value;if(p&&s(p)){const h=i(p);r.value=h,o("update:modelValue",h),setTimeout(()=>f.select())}}}return(u,f)=>(c.openBlock(),c.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:a,onKeydown:d},null,40,wk))}}),gu=c.defineComponent({__name:"ColorSlider",props:{modelValue:{},thumbColor:{},background:{}},emits:["update:modelValue"],setup(n,{expose:e,emit:t}){const o=t,r=c.ref(null),s=c.ref(!1);function i(d){s.value=!0,l(d),window.addEventListener("pointermove",l),window.addEventListener("pointerup",a)}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 a(){s.value=!1,window.removeEventListener("pointermove",l),window.removeEventListener("pointerup",a)}return e({isDragging:s}),(d,u)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"sliderRef",ref:r,class:"wov-color-slider",onPointerdown:c.withModifiers(i,["prevent"])},[n.background?(c.openBlock(),c.createElementBlock("div",{key:0,class:"wov-color-slider-gradient",style:c.normalizeStyle({background:n.background})},null,4)):c.createCommentVNode("",!0),c.createElementVNode("div",{class:"wov-color-slider-thumb",style:c.normalizeStyle({top:`${n.modelValue}%`,backgroundColor:n.thumbColor})},null,4)],544))}}),xk={class:"wov-color-picker"},Sk={class:"wov-color-picker-area"},Ck={class:"wov-color-picker-selector-gradient"},vk="linear-gradient(to bottom, red 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%)",yu=c.defineComponent({__name:"ColorPicker",props:{modelValue:{},withOpacity:{type:Boolean}},emits:["update:modelValue"],setup(n,{emit:e}){const t=n,o=e,r=c.ref(null),s=c.ref(null),i=c.ref(null),l=c.ref({x:100,y:0}),a=c.ref(0),d=c.ref(0),u=c.ref(!1),f=c.computed(()=>{var M,v;return u.value||((M=r.value)==null?void 0:M.isDragging)||((v=s.value)==null?void 0:v.isDragging)}),p=c.computed(()=>({h:a.value/100*360,s:l.value.x,v:100-l.value.y,a:(100-d.value)/100*255})),h=c.computed(()=>$d({h:p.value.h,s:100,v:100})),m=c.computed(()=>$d({h:p.value.h,s:p.value.s,v:p.value.v})),g=c.computed(()=>t.withOpacity?Ld(p.value):m.value),y=c.computed(()=>`linear-gradient(to top, transparent 0%, ${m.value} 100%)`);function k(M){if(M){const v=Vd(M);l.value={x:v.s,y:100-v.v},a.value=v.h/360*100,d.value=100-v.a/255*100}}function w(M){k(M),o("update:modelValue",t.withOpacity?Ld(Vd(M)):M)}k(t.modelValue),c.watch(()=>t.modelValue,M=>{f.value||k(M)}),c.watch([l,a,d],()=>{f.value&&o("update:modelValue",g.value)});function b(M){u.value=!0,S(M),window.addEventListener("pointermove",S),window.addEventListener("pointerup",C)}function S(M){if(!i.value)return;const v=i.value.getBoundingClientRect(),E=Math.max(0,Math.min(100,(M.clientX-v.left)/v.width*100)),T=Math.max(0,Math.min(100,(M.clientY-v.top)/v.height*100));l.value={x:E,y:T}}function C(){u.value=!1,window.removeEventListener("pointermove",S),window.removeEventListener("pointerup",C)}return(M,v)=>(c.openBlock(),c.createElementBlock("div",xk,[c.createVNode(bk,{modelValue:g.value,"onUpdate:modelValue":w},null,8,["modelValue"]),c.createElementVNode("div",Sk,[c.createElementVNode("div",{ref_key:"selectorRef",ref:i,class:"wov-color-picker-selector",style:c.normalizeStyle({backgroundColor:h.value}),onPointerdown:c.withModifiers(b,["prevent"])},[c.createElementVNode("div",Ck,[c.createElementVNode("div",{class:"wov-color-picker-selector-thumb",style:c.normalizeStyle({left:`${l.value.x}%`,top:`${l.value.y}%`,backgroundColor:m.value})},null,4)])],36),c.createVNode(gu,{ref_key:"hueSliderRef",ref:r,modelValue:a.value,"onUpdate:modelValue":v[0]||(v[0]=E=>a.value=E),thumbColor:h.value,background:vk},null,8,["modelValue","thumbColor"]),n.withOpacity?(c.openBlock(),c.createBlock(gu,{key:0,ref_key:"opacitySliderRef",ref:s,modelValue:d.value,"onUpdate:modelValue":v[1]||(v[1]=E=>d.value=E),thumbColor:m.value,background:y.value,class:"wov-color-picker-opacity"},null,8,["modelValue","thumbColor","background"])):c.createCommentVNode("",!0)])]))}}),Ek={class:"wov-color-bubbles-container"},Mk={key:1,class:"wov-color-bubbles"},Tk=["onClick"],xr=c.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=c.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=c.ref(!1),l=c.ref(t.currentColor??"#ff0000");function a(m,g){const y=k=>{const w=k.replace(/^#/,"").toLowerCase();return w.length===6?w+"ff":w};return y(m)===y(g)}function d(m){return t.hideHighlight||!t.currentColor?!1:a(t.currentColor,m)}function u(){return t.hideHighlight||!t.currentColor?!1:!s.value.some(m=>a(t.currentColor,m))}function f(m){const g=Gs(m);g&&o("change",g)}function p(){!i.value&&t.currentColor&&(l.value=t.currentColor),i.value=!i.value,o("picker-open",i.value)}function h(m){l.value=m;const g=Gs(m);g&&o("change",g)}return(m,g)=>(c.openBlock(),c.createElementBlock("div",Ek,[i.value?(c.openBlock(),c.createBlock(yu,{key:0,modelValue:l.value,"onUpdate:modelValue":[g[0]||(g[0]=y=>l.value=y),h],withOpacity:n.withOpacity},null,8,["modelValue","withOpacity"])):(c.openBlock(),c.createElementBlock("div",Mk,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(s.value,y=>(c.openBlock(),c.createElementBlock("div",{key:y,class:c.normalizeClass(["wov-color-bubble",{selected:d(y)}]),style:c.normalizeStyle({backgroundColor:y}),onMousedown:g[1]||(g[1]=c.withModifiers(()=>{},["prevent"])),onClick:k=>f(y)},null,46,Tk))),128)),n.withPicker?(c.openBlock(),c.createElementBlock("div",{key:0,class:c.normalizeClass(["wov-color-bubble wov-rainbow-bubble",{selected:u()}]),onMousedown:g[2]||(g[2]=c.withModifiers(()=>{},["prevent"])),onClick:p},null,34)):c.createCommentVNode("",!0)]))]))}}),Nk={class:"wov-color-button"},ku=c.defineComponent({__name:"ColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=_t(()=>e.entityIds,x.Color),r=c.computed(()=>{const d=new Set;for(const u of o.value.values())if(u){const f=lo(u);d.add(f)}return Array.from(d)}),s=c.computed(()=>r.value.length>1),i=c.computed(()=>r.value[0]??null),l=c.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 a(d){const u=lo(d);t(f=>{for(const p of e.entityIds)x.Color.fromHex(f,p,u)})}return(d,u)=>(c.openBlock(),c.createBlock(je,{title:"Color"},{button:c.withCtx(()=>[c.createElementVNode("div",Nk,[c.createElementVNode("div",{class:"wov-color-swatch",style:c.normalizeStyle(l.value)},null,4),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createVNode(xr,{currentColor:i.value??void 0,hideHighlight:s.value,withPicker:!0,onChange:a},null,8,["currentColor","hideHighlight"])]),_:1}))}}),On=c.defineComponent({__name:"MenuButton",props:{title:{}},emits:["click"],setup(n,{emit:e}){const t=n,o=e,r=c.ref(null),{show:s,hide:i}=Vt();function l(u){o("click",u)}function a(){t.title&&r.value&&s(t.title,r.value)}function d(){i()}return(u,f)=>(c.openBlock(),c.createElementBlock("button",{ref_key:"buttonRef",ref:r,class:"wov-menu-button",onClick:l,onMouseenter:a,onMouseleave:d},[c.renderSlot(u.$slots,"default")],544))}}),ui=c.defineComponent({__name:"MenuTooltip",setup(n){const{activeTooltip:e,isVisible:t}=Vt(),o=c.inject("containerRef"),r=c.ref(null),s=c.computed(()=>{var a;return((a=e.value)==null?void 0:a.anchor)??null}),{floatingStyles:i}=br(s,r,{placement:"top",middleware:[yr(8),wr({fallbackPlacements:["bottom"]}),kr({padding:8})]}),l=c.computed(()=>{var a;return t.value&&((a=e.value)==null?void 0:a.text)});return(a,d)=>c.unref(o)?(c.openBlock(),c.createBlock(c.Teleport,{key:0,to:c.unref(o)},[c.createVNode(c.Transition,{name:"wov-tooltip-fade"},{default:c.withCtx(()=>{var u;return[l.value?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"tooltipRef",ref:r,class:"wov-menu-tooltip",style:c.normalizeStyle(c.unref(i))},c.toDisplayString((u=c.unref(e))==null?void 0:u.text),5)):c.createCommentVNode("",!0)]}),_:1})],8,["to"])):c.createCommentVNode("",!0)}}),Bk={class:"wov-menu-button"},Ak=["onClick"],wu=c.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=_t(()=>t.entityIds,go.PenStroke),s=c.computed(()=>{let l=null;for(const a of r.value.values())if(a){if(l===null)l=a.thickness;else if(a.thickness!==l)return null}return l});function i(l){o(a=>{for(const d of t.entityIds){const u=go.PenStroke.write(a,d);u.thickness=l}})}return(l,a)=>(c.openBlock(),c.createBlock(je,{title:"Thickness"},{button:c.withCtx(()=>[c.createElementVNode("div",Bk,[a[0]||(a[0]=c.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"},[c.createElementVNode("line",{x1:"4",y1:"5",x2:"20",y2:"5","stroke-width":"1"}),c.createElementVNode("line",{x1:"4",y1:"11",x2:"20",y2:"11","stroke-width":"2.5"}),c.createElementVNode("line",{x1:"4",y1:"19",x2:"20",y2:"19","stroke-width":"4"})],-1)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[(c.openBlock(),c.createElementBlock(c.Fragment,null,c.renderList(e,d=>c.createElementVNode("button",{key:d.value,class:c.normalizeClass(["wov-menu-option wov-pen-thickness-option",{"is-active":s.value===d.value}]),onClick:u=>i(d.value)},c.toDisplayString(d.label),11,Ak)),64))]),_:1}))}}),Ik={class:"wov-fill-color-button"},Ok={class:"wov-fill-dropdown"},Dk={key:0,class:"wov-fill-mode-section"},Rk=["title","onClick"],_k={viewBox:"0 0 24 24",fill:"none"},Pk=["fill","fill-opacity","stroke","stroke-width","stroke-dasharray"],bu=c.defineComponent({__name:"ShapeFillColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=_t(()=>e.entityIds,x.Shape),r=[{mode:"solid",label:"Solid",alpha:255},{mode:"faded",label:"Faded",alpha:128},{mode:"none",label:"None",alpha:0}],s=c.computed(()=>{const h=o.value.values().next().value,m=(h==null?void 0:h.fillAlpha)??255;return m===0?"none":m<200?"faded":"solid"}),i=c.computed(()=>{const h=new Set;for(const m of o.value.values())if(m){const g=m.fillAlpha??255;g===0?h.add("none"):g<200?h.add("faded"):h.add("solid")}return h.size>1});function l(h){t(m=>{for(const g of e.entityIds){const y=x.Shape.write(m,g);y.fillAlpha=h}})}const a=c.computed(()=>{const h=new Set;for(const m of o.value.values())if(m){const g=lo({red:m.fillRed,green:m.fillGreen,blue:m.fillBlue,alpha:m.fillAlpha??255});h.add(g)}return Array.from(h)}),d=c.computed(()=>a.value.length>1),u=c.computed(()=>a.value[0]??"#4a90d9");function f(h){t(m=>{for(const g of e.entityIds){const y=x.Shape.write(m,g);y.fillRed=h.red,y.fillGreen=h.green,y.fillBlue=h.blue,y.fillAlpha=h.alpha}})}const p=c.ref(!1);return(h,m)=>(c.openBlock(),c.createBlock(je,{title:"Fill Color"},{button:c.withCtx(()=>[c.createElementVNode("div",Ik,[m[1]||(m[1]=c.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-fill-color-icon",stroke:"currentColor",fill:"none","stroke-linecap":"round","stroke-linejoin":"round"},[c.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"}),c.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)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",Ok,[p.value?c.createCommentVNode("",!0):(c.openBlock(),c.createElementBlock("div",Dk,[(c.openBlock(),c.createElementBlock(c.Fragment,null,c.renderList(r,g=>c.createElementVNode("button",{key:g.mode,class:c.normalizeClass(["wov-fill-mode-option",{"is-active":!i.value&&g.mode===s.value}]),title:g.label,onClick:y=>l(g.alpha)},[(c.openBlock(),c.createElementBlock("svg",_k,[c.createElementVNode("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",fill:g.mode==="none"?"none":"currentColor","fill-opacity":g.mode==="faded"?.4:1,stroke:g.mode==="none"?"currentColor":"none","stroke-width":g.mode==="none"?1.5:0,"stroke-dasharray":g.mode==="none"?"3 3":""},null,8,Pk)])),c.createElementVNode("span",null,c.toDisplayString(g.label),1)],10,Rk)),64))])),c.createVNode(xr,{currentColor:u.value,hideHighlight:d.value,withPicker:!0,withOpacity:!0,onChange:f,onPickerOpen:m[0]||(m[0]=g=>p.value=g)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),Vk={class:"wov-shape-kind-button"},$k={class:"wov-shape-kind-dropdown"},Lk=["onClick"],zk={viewBox:"0 0 20 20",class:"wov-shape-option-icon",fill:"none",stroke:"currentColor","stroke-width":"4"},Fk=["d"],xu=c.defineComponent({__name:"ShapeKindButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=_t(()=>e.entityIds,x.Shape),r=c.computed(()=>{const a=o.value.values().next().value;return(a==null?void 0:a.kind)??"rectangle"}),s=c.computed(()=>{const a=new Set;for(const d of o.value.values())d&&a.add(d.kind);return a.size>1}),i=c.computed(()=>Object.keys(Pn).map(a=>({kind:a,label:a.charAt(0).toUpperCase()+a.slice(1)})));function l(a){t(d=>{for(const u of e.entityIds){const f=x.Shape.write(d,u);f.kind=a}})}return(a,d)=>(c.openBlock(),c.createBlock(je,{title:"Shape Type"},{button:c.withCtx(()=>[c.createElementVNode("div",Vk,[d[0]||(d[0]=c.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-shape-kind-icon",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[c.createElementVNode("circle",{cx:"6",cy:"6",r:"5"}),c.createElementVNode("rect",{x:"6",y:"6",width:"10",height:"10",fill:"var(--wov-gray-600)"})],-1)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",$k,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(i.value,u=>(c.openBlock(),c.createElementBlock("button",{key:u.kind,class:c.normalizeClass(["wov-shape-kind-option",{"is-selected":!s.value&&u.kind===r.value}]),onClick:f=>l(u.kind)},[(c.openBlock(),c.createElementBlock("svg",zk,[c.createElementVNode("path",{d:c.unref(Pn)[u.kind],transform:"translate(2, 2) scale(0.16)"},null,8,Fk)])),c.createElementVNode("span",null,c.toDisplayString(u.label),1)],10,Lk))),128))])]),_:1}))}}),Hk={class:"wov-stroke-style-section"},Wk=["title","onClick"],jk={viewBox:"0 0 24 8",fill:"none",stroke:"currentColor","stroke-width":"2"},Uk=["stroke-dasharray","stroke-opacity"],Kk=c.defineComponent({__name:"StrokeStyleOptions",props:{currentStyle:{},hasMultipleStyles:{type:Boolean}},emits:["change"],setup(n,{emit:e}){const t=e,o=[{kind:x.StrokeKind.Solid,label:"Solid"},{kind:x.StrokeKind.Dashed,label:"Dashed"},{kind:x.StrokeKind.None,label:"None"}];function r(i){switch(i){case x.StrokeKind.Dashed:return"6 6";case x.StrokeKind.None:return"";case x.StrokeKind.Solid:default:return""}}function s(i){t("change",i)}return(i,l)=>(c.openBlock(),c.createElementBlock("div",Hk,[(c.openBlock(),c.createElementBlock(c.Fragment,null,c.renderList(o,a=>c.createElementVNode("button",{key:a.kind,class:c.normalizeClass(["wov-stroke-style-option",{"is-active":!n.hasMultipleStyles&&a.kind===n.currentStyle}]),title:a.label,onClick:d=>s(a.kind)},[(c.openBlock(),c.createElementBlock("svg",jk,[c.createElementVNode("line",{x1:"2",y1:"4",x2:"22",y2:"4","stroke-linecap":"round","stroke-dasharray":r(a.kind),"stroke-opacity":a.kind===c.unref(x.StrokeKind).None?.3:1},null,8,Uk)])),c.createElementVNode("span",null,c.toDisplayString(a.label),1)],10,Wk)),64))]))}}),qk={class:"wov-stroke-color-button"},Jk={class:"wov-stroke-dropdown"},Gk={key:1,class:"wov-stroke-divider"},Su=c.defineComponent({__name:"ShapeStrokeColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),o=_t(()=>e.entityIds,x.Shape),r=c.ref(!1),s=c.computed(()=>{const p=new Set;for(const h of o.value.values())if(h){const m=lo({red:h.strokeRed,green:h.strokeGreen,blue:h.strokeBlue,alpha:255});p.add(m)}return Array.from(p)}),i=c.computed(()=>s.value.length>1),l=c.computed(()=>s.value[0]??"#000000"),a=c.computed(()=>{const p=o.value.values().next().value;return(p==null?void 0:p.strokeKind)??x.StrokeKind.Solid}),d=c.computed(()=>{const p=new Set;for(const h of o.value.values())h&&p.add(h.strokeKind);return p.size>1});function u(p){t(h=>{for(const m of e.entityIds){const g=x.Shape.write(h,m);g.strokeRed=p.red,g.strokeGreen=p.green,g.strokeBlue=p.blue}})}function f(p){t(h=>{for(const m of e.entityIds){const g=x.Shape.write(h,m);g.strokeKind=p}})}return(p,h)=>(c.openBlock(),c.createBlock(je,{title:"Stroke Color"},{button:c.withCtx(()=>[c.createElementVNode("div",qk,[h[1]||(h[1]=c.createElementVNode("svg",{viewBox:"0 0 20 20",class:"wov-stroke-color-icon",fill:"none",stroke:"currentColor","stroke-linecap":"round","stroke-linejoin":"round"},[c.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)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",Jk,[r.value?c.createCommentVNode("",!0):(c.openBlock(),c.createBlock(Kk,{key:0,currentStyle:a.value,hasMultipleStyles:d.value,onChange:f},null,8,["currentStyle","hasMultipleStyles"])),r.value?c.createCommentVNode("",!0):(c.openBlock(),c.createElementBlock("div",Gk)),c.createVNode(xr,{currentColor:l.value,hideHighlight:i.value,withPicker:!0,onChange:u,onPickerOpen:h[0]||(h[0]=m=>r.value=m)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),Yk={key:0,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},Xk={key:1,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},Zk={key:2,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},Qk={key:3,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},fi=c.defineComponent({__name:"TextAlignmentButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=[x.TextAlignment.Left,x.TextAlignment.Center,x.TextAlignment.Right,x.TextAlignment.Justify];function s(){const i=r.indexOf(t.alignment),l=r[(i+1)%r.length];o.setAlignment(l)}return(i,l)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(On,{key:0,title:"Text Align",onClick:s},{default:c.withCtx(()=>[c.unref(t).alignment===c.unref(x.TextAlignment).Left?(c.openBlock(),c.createElementBlock("svg",Yk,[...l[0]||(l[0]=[c.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)])])):c.unref(t).alignment===c.unref(x.TextAlignment).Center?(c.openBlock(),c.createElementBlock("svg",Xk,[...l[1]||(l[1]=[c.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)])])):c.unref(t).alignment===c.unref(x.TextAlignment).Right?(c.openBlock(),c.createElementBlock("svg",Zk,[...l[2]||(l[2]=[c.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)])])):(c.openBlock(),c.createElementBlock("svg",Qk,[...l[3]||(l[3]=[c.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})):c.createCommentVNode("",!0)}}),hi=c.defineComponent({__name:"TextBoldButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds);return(r,s)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(On,{key:0,title:"Bold",class:c.normalizeClass({"wov-active":c.unref(t).isBold}),onClick:c.unref(o).toggleBold},{default:c.withCtx(()=>[...s[0]||(s[0]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[c.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"])):c.createCommentVNode("",!0)}});function ew(n,e){return c.getCurrentScope()?(c.onScopeDispose(n,e),!0):!1}const tw=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const nw=Object.prototype.toString,ow=n=>nw.call(n)==="[object Object]",Sr=()=>{};function Cr(n){return Array.isArray(n)?n:[n]}function rw(n){return c.getCurrentInstance()}function sw(n,e=!0,t){rw()?c.onMounted(n,t):e?n():c.nextTick(n)}function iw(n,e,t){return c.watch(n,e,{...t,immediate:!0})}const vr=tw?window:void 0;function Ye(n){var e;const t=c.toValue(n);return(e=t==null?void 0:t.$el)!==null&&e!==void 0?e:t}function pi(...n){const e=(o,r,s,i)=>(o.addEventListener(r,s,i),()=>o.removeEventListener(r,s,i)),t=c.computed(()=>{const o=Cr(c.toValue(n[0])).filter(r=>r!=null);return o.every(r=>typeof r!="string")?o:void 0});return iw(()=>{var o,r;return[(o=(r=t.value)===null||r===void 0?void 0:r.map(s=>Ye(s)))!==null&&o!==void 0?o:[vr].filter(s=>s!=null),Cr(c.toValue(t.value?n[1]:n[0])),Cr(c.unref(t.value?n[2]:n[1])),c.toValue(t.value?n[3]:n[2])]},([o,r,s,i],l,a)=>{if(!(o!=null&&o.length)||!(r!=null&&r.length)||!(s!=null&&s.length))return;const d=ow(i)?{...i}:i,u=o.flatMap(f=>r.flatMap(p=>s.map(h=>e(f,p,h,d))));a(()=>{u.forEach(f=>f())})},{flush:"post"})}function lw(n,e,t={}){const{window:o=vr,ignore:r=[],capture:s=!0,detectIframe:i=!1,controls:l=!1}=t;if(!o)return l?{stop:Sr,cancel:Sr,trigger:Sr}:Sr;let a=!0;const d=y=>c.toValue(r).some(k=>{if(typeof k=="string")return Array.from(o.document.querySelectorAll(k)).some(w=>w===y.target||y.composedPath().includes(w));{const w=Ye(k);return w&&(y.target===w||y.composedPath().includes(w))}});function u(y){const k=c.toValue(y);return k&&k.$.subTree.shapeFlag===16}function f(y,k){const w=c.toValue(y),b=w.$.subTree&&w.$.subTree.children;return b==null||!Array.isArray(b)?!1:b.some(S=>S.el===k.target||k.composedPath().includes(S.el))}const p=y=>{const k=Ye(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&&(a=!d(y)),!a){a=!0;return}e(y)}};let h=!1;const m=[pi(o,"click",y=>{h||(h=!0,setTimeout(()=>{h=!1},0),p(y))},{passive:!0,capture:s}),pi(o,"pointerdown",y=>{const k=Ye(n);a=!d(y)&&!!(k&&!y.composedPath().includes(k))},{passive:!0}),i&&pi(o,"blur",y=>{setTimeout(()=>{var k;const w=Ye(n);((k=o.document.activeElement)===null||k===void 0?void 0:k.tagName)==="IFRAME"&&!(w!=null&&w.contains(o.document.activeElement))&&e(y)},0)},{passive:!0})].filter(Boolean),g=()=>m.forEach(y=>y());return l?{stop:g,cancel:()=>{a=!1},trigger:y=>{a=!0,p(y),a=!1}}:g}function aw(){const n=c.shallowRef(!1),e=c.getCurrentInstance();return e&&c.onMounted(()=>{n.value=!0},e),n}function cw(n){const e=aw();return c.computed(()=>(e.value,!!n()))}function dw(n,e,t={}){const{window:o=vr,...r}=t;let s;const i=cw(()=>o&&"ResizeObserver"in o),l=()=>{s&&(s.disconnect(),s=void 0)},a=c.watch(c.computed(()=>{const u=c.toValue(n);return Array.isArray(u)?u.map(f=>Ye(f)):[Ye(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(),a()};return ew(d),{isSupported:i,stop:d}}function Cu(n,e={width:0,height:0},t={}){const{window:o=vr,box:r="content-box"}=t,s=c.computed(()=>{var f;return(f=Ye(n))===null||f===void 0||(f=f.namespaceURI)===null||f===void 0?void 0:f.includes("svg")}),i=c.shallowRef(e.width),l=c.shallowRef(e.height),{stop:a}=dw(n,([f])=>{const p=r==="border-box"?f.borderBoxSize:r==="content-box"?f.contentBoxSize:f.devicePixelContentBoxSize;if(o&&s.value){const h=Ye(n);if(h){const m=h.getBoundingClientRect();i.value=m.width,l.value=m.height}}else if(p){const h=Cr(p);i.value=h.reduce((m,{inlineSize:g})=>m+g,0),l.value=h.reduce((m,{blockSize:g})=>m+g,0)}else i.value=f.contentRect.width,l.value=f.contentRect.height},t);sw(()=>{const f=Ye(n);f&&(i.value="offsetWidth"in f?f.offsetWidth:e.width,l.value="offsetHeight"in f?f.offsetHeight:e.height)});const d=c.watch(()=>Ye(n),f=>{i.value=f?e.width:0,l.value=f?e.height:0});function u(){a(),d()}return{width:i,height:l,stop:u}}function vu(){const n=c.inject($e);if(!n)throw new Error("useFonts must be used within a WovenCanvas component");return c.computed(()=>{const e=n.getEditor();return e?e.fonts.filter(t=>t.selectable):[]})}const uw={class:"wov-font-family-button"},fw={class:"wov-font-family-label"},hw={class:"wov-font-list"},pw=["onClick"],mw=["src","alt"],mi=c.defineComponent({__name:"TextFontFamilyButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=vu(),s=c.computed(()=>r.value.map(u=>({name:u.name,displayName:u.displayName,previewImage:u.previewImage}))),i=c.computed(()=>t.fontFamily),l=c.computed(()=>{const u=i.value;if(u===null)return"Mixed";const f=s.value.find(p=>p.name===u);return(f==null?void 0:f.displayName)??u});function a(u){o.setFontFamily(u)}function d(u){u.stopPropagation()}return(u,f)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(je,{key:0,title:"Font Family"},{button:c.withCtx(()=>[c.createElementVNode("div",uw,[c.createElementVNode("span",fw,c.toDisplayString(l.value),1),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",{class:"wov-font-family-menu",onWheel:d,onClick:f[0]||(f[0]=c.withModifiers(()=>{},["stop"]))},[c.createElementVNode("div",hw,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(s.value,p=>(c.openBlock(),c.createElementBlock("div",{key:p.name,class:c.normalizeClass(["wov-font-item",{active:i.value===p.name}]),onClick:h=>a(p.name)},[p.previewImage?(c.openBlock(),c.createElementBlock("img",{key:0,class:"wov-font-preview",src:p.previewImage,alt:p.name},null,8,mw)):(c.openBlock(),c.createElementBlock("span",{key:1,class:"wov-font-name",style:c.normalizeStyle({fontFamily:p.name})},c.toDisplayString(p.displayName),5))],10,pw))),128))])],32)]),_:1})):c.createCommentVNode("",!0)}}),gw={class:"wov-font-size-button"},yw={class:"wov-font-size-label"},kw=["onClick"],ww={key:0,class:"wov-check-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},bw={class:"wov-input-container"},xw=["value"],gi=c.defineComponent({__name:"TextFontSizeButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=[{label:"Small",value:16,displayValue:10},{label:"Medium",value:24,displayValue:12},{label:"Large",value:40,displayValue:16},{label:"Huge",value:96,displayValue:20}],s=c.computed(()=>t.fontSize),i=c.computed(()=>{const p=s.value;if(p===null)return"Mixed";const h=r.find(m=>m.value===p);return h?h.label:`${+p.toFixed(1)} px`}),l=c.computed(()=>{const p=s.value;return p===null?"":String(+p.toFixed(1))});function a(p){o.setFontSize(p)}function d(p){const h=p.target,m=Number.parseFloat(h.value);!Number.isNaN(m)&&m>0&&a(m)}function u(p){p.key==="Enter"&&p.target.blur()}function f(p){p.stopPropagation()}return(p,h)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(je,{key:0,title:"Font Size"},{button:c.withCtx(()=>[c.createElementVNode("div",gw,[c.createElementVNode("span",yw,c.toDisplayString(i.value),1),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",{class:"wov-font-size-menu",onWheel:f,onClick:h[0]||(h[0]=c.withModifiers(()=>{},["stop"]))},[(c.openBlock(),c.createElementBlock(c.Fragment,null,c.renderList(r,m=>c.createElementVNode("div",{key:m.value,class:c.normalizeClass(["wov-font-size-option",{active:s.value===m.value}]),onClick:g=>a(m.value)},[s.value===m.value?(c.openBlock(),c.createElementBlock("svg",ww,[...h[1]||(h[1]=[c.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)])])):c.createCommentVNode("",!0),c.createElementVNode("span",{class:"wov-option-label",style:c.normalizeStyle({fontSize:`${m.displayValue}px`})},c.toDisplayString(m.label),5)],10,kw)),64)),h[3]||(h[3]=c.createElementVNode("div",{class:"wov-separator"},null,-1)),c.createElementVNode("div",bw,[c.createElementVNode("input",{class:"wov-custom-input",value:l.value,onInput:d,onKeydown:u,placeholder:"Custom size"},null,40,xw),h[2]||(h[2]=c.createElementVNode("span",{class:"wov-px-suffix"},"px",-1))])],32)]),_:1})):c.createCommentVNode("",!0)}}),yi=c.defineComponent({__name:"TextItalicButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds);return(r,s)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(On,{key:0,title:"Italic",class:c.normalizeClass({"wov-active":c.unref(t).isItalic}),onClick:c.unref(o).toggleItalic},{default:c.withCtx(()=>[...s[0]||(s[0]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 384 512",fill:"currentColor"},[c.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"])):c.createCommentVNode("",!0)}}),ki=c.defineComponent({__name:"TextUnderlineButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds);return(r,s)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(On,{key:0,title:"Underline",class:c.normalizeClass({"wov-active":c.unref(t).isUnderline}),onClick:c.unref(o).toggleUnderline},{default:c.withCtx(()=>[...s[0]||(s[0]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},[c.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"])):c.createCommentVNode("",!0)}}),Sw={class:"wov-text-color-button"},Cw={class:"wov-text-icon-container"},wi=c.defineComponent({__name:"TextColorButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=c.computed(()=>t.color??"#000000"),s=c.computed(()=>({backgroundColor:r.value}));function i(l){o.setColor(lo(l))}return(l,a)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createBlock(je,{key:0,title:"Text Color"},{button:c.withCtx(()=>[c.createElementVNode("div",Sw,[c.createElementVNode("div",Cw,[a[0]||(a[0]=c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor",class:"wov-text-icon"},[c.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)),c.createElementVNode("div",{class:"wov-color-underline",style:c.normalizeStyle(s.value)},null,4)]),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createVNode(xr,{currentColor:r.value,withPicker:!0,onChange:i},null,8,["currentColor"])]),_:1})):c.createCommentVNode("",!0)}}),vw={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"},Ew={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"},Mw={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"},Eu=c.defineComponent({__name:"VerticalAlignButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=le(),{state:o}=ot(()=>e.entityIds),r=[x.VerticalAlignment.Top,x.VerticalAlignment.Center,x.VerticalAlignment.Bottom],s=_t(()=>e.entityIds,x.VerticalAlign),i=c.computed(()=>{let a=null;for(const d of s.value.values()){const u=(d==null?void 0:d.value)??x.VerticalAlignment.Top;if(a===null)a=u;else if(a!==u)return null}return a});function l(){const a=i.value??x.VerticalAlignment.Top,d=r.indexOf(a),u=r[(d+1)%r.length];t(f=>{for(const p of e.entityIds){const h=x.VerticalAlign.write(f,p);h.value=u}})}return(a,d)=>c.unref(o).showTextMenuButtons?(c.openBlock(),c.createBlock(On,{key:0,title:"Vertical Align",onClick:l},{default:c.withCtx(()=>[i.value===c.unref(x.VerticalAlignment).Top||i.value===null?(c.openBlock(),c.createElementBlock("svg",vw,[...d[0]||(d[0]=[c.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"},null,-1),c.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"6",rx:"2"},null,-1),c.createElementVNode("path",{d:"M2 2h20"},null,-1)])])):i.value===c.unref(x.VerticalAlignment).Center?(c.openBlock(),c.createElementBlock("svg",Ew,[...d[1]||(d[1]=[c.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"16",rx:"2"},null,-1),c.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"},null,-1),c.createElementVNode("path",{d:"M2 12h20"},null,-1)])])):(c.openBlock(),c.createElementBlock("svg",Mw,[...d[2]||(d[2]=[c.createElementVNode("rect",{width:"14",height:"6",x:"5",y:"12",rx:"2"},null,-1),c.createElementVNode("rect",{width:"10",height:"6",x:"7",y:"2",rx:"2"},null,-1),c.createElementVNode("path",{d:"M2 22h20"},null,-1)])]))]),_:1})):c.createCommentVNode("",!0)}}),Tw={class:"wov-text-group-button"},Nw={class:"wov-text-group-dropdown"},Bw={class:"wov-text-group-row wov-text-group-row-full"},Aw={class:"wov-text-group-row"},Iw=c.defineComponent({__name:"TextButtonGroup",props:{entityIds:{},showVerticalAlign:{type:Boolean}},setup(n){const e=n,{state:t}=ot(()=>e.entityIds),o=c.inject("containerRef"),{width:r}=Cu(o),s=c.computed(()=>r.value>0&&r.value<600),i=c.ref(new Map);return c.provide(Ii,i),(l,a)=>c.unref(t).showTextMenuButtons?(c.openBlock(),c.createElementBlock(c.Fragment,{key:0},[s.value?(c.openBlock(),c.createBlock(je,{key:0,title:"Text Formatting",placement:"top"},{button:c.withCtx(()=>[c.createElementVNode("div",Tw,[a[0]||(a[0]=c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor",class:"wov-text-group-icon"},[c.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)),c.createVNode(Ue,{class:"wov-chevron-down"})])]),dropdown:c.withCtx(()=>[c.createElementVNode("div",Nw,[c.createElementVNode("div",Bw,[c.createVNode(mi,{entityIds:n.entityIds},null,8,["entityIds"]),a[1]||(a[1]=c.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),c.createVNode(gi,{entityIds:n.entityIds},null,8,["entityIds"])]),c.createElementVNode("div",Aw,[c.createVNode(hi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(yi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(ki,{entityIds:n.entityIds},null,8,["entityIds"]),a[2]||(a[2]=c.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),c.createVNode(wi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(fi,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(c.openBlock(),c.createBlock(Eu,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):c.createCommentVNode("",!0)])])]),_:1})):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},[c.createVNode(mi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(gi,{entityIds:n.entityIds},null,8,["entityIds"]),a[3]||(a[3]=c.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),c.createVNode(hi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(yi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(ki,{entityIds:n.entityIds},null,8,["entityIds"]),a[4]||(a[4]=c.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),c.createVNode(wi,{entityIds:n.entityIds},null,8,["entityIds"]),c.createVNode(fi,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(c.openBlock(),c.createBlock(Eu,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):c.createCommentVNode("",!0)],64))],64)):c.createCommentVNode("",!0)}}),Mu=c.defineComponent({__name:"CanvasBackground",props:{background:{}},setup(n){const e=n,t=Se(x.Camera),o=Se(x.Grid),r=c.inject("containerRef"),s=c.ref({width:0,height:0});let i=null;const l=c.ref(null);let a=null;typeof document<"u"&&(a=document.createElement("canvas"));function d(y,k,w,b){const S=b/2;y.beginPath(),y.arc(k,w,S,0,Math.PI*2),y.fill()}function u(y,k,w){if(!a)return null;const b=w.dotSize??2,S=y*w.subdivisionStep,C=k*w.subdivisionStep;if(S<=0||C<=0)return null;a.width=S,a.height=C;const M=a.getContext("2d");if(!M)return null;if(M.clearRect(0,0,S,C),M.fillStyle=w.strokeColor,w.subdivisionStep===1)d(M,S/2,C/2,b);else for(let v=0;v<w.subdivisionStep;v++)for(let E=0;E<w.subdivisionStep;E++){const T=(v+.5)*(S/w.subdivisionStep),A=(E+.5)*(C/w.subdivisionStep),$=v===0&&E===0?2*b:b;d(M,T,A,$)}return M.createPattern(a,"repeat")}function f(y,k,w,b,S,C){y.lineWidth=C,y.beginPath(),y.moveTo(k,w),y.lineTo(b,S),y.stroke()}function p(y,k,w){if(!a)return null;const b=w.gridSize??1,S=y*w.subdivisionStep,C=k*w.subdivisionStep;if(S<=0||C<=0)return null;a.width=S,a.height=C;const M=a.getContext("2d");if(!M)return null;if(M.clearRect(0,0,S,C),M.strokeStyle=w.strokeColor,w.subdivisionStep===1)f(M,0,0,S,0,b),f(M,0,0,0,C,b);else{const v=S/w.subdivisionStep,E=C/w.subdivisionStep;for(let T=0;T<=w.subdivisionStep;T++){const A=T*v,R=T%w.subdivisionStep===0;f(M,A,0,A,C,R?3*b:b)}for(let T=0;T<=w.subdivisionStep;T++){const A=T*E,R=T%w.subdivisionStep===0;f(M,0,A,S,A,R?3*b:b)}}return M.createPattern(a,"repeat")}function h(y){let k=o.value.colWidth,w=o.value.rowHeight;const b=e.background.subdivisionStep,S=s.value.width,C=s.value.height,M=t.value.left,v=t.value.top,E=M+S/t.value.zoom,T=v+C/t.value.zoom;let A=k*b,R=w*b,$=0,z=0,j=Number.POSITIVE_INFINITY,K=Number.POSITIVE_INFINITY;for(;;){A=b*k,R=b*w,$=Math.floor(M/A)*A,z=Math.floor(v/R)*R;const ce=Math.ceil(E/A)*A,Xe=Math.ceil(T/R)*R;if(K=Math.round((ce-$)/k),j=Math.round((Xe-z)/w),Math.max(K,j)>200)k*=2,w*=2;else break}const Z=k*t.value.zoom,U=w*t.value.zoom,L=Math.round(Z),W=Math.round(U),X=u(L,W,e.background);if(!X)return;X.setTransform(new DOMMatrix().scale(Z/L,U/W));const ie=($-M-k/2)*t.value.zoom,ee=(z-v-w/2)*t.value.zoom;y.save(),y.translate(ie,ee),y.fillStyle=X,y.fillRect(0,0,S+A*t.value.zoom,C+R*t.value.zoom),y.restore()}function m(y){let k=o.value.colWidth,w=o.value.rowHeight;const b=e.background.subdivisionStep,S=s.value.width,C=s.value.height,M=t.value.left,v=t.value.top,E=M+S/t.value.zoom,T=v+C/t.value.zoom;let A=k*b,R=w*b,$=0,z=0,j=Number.POSITIVE_INFINITY,K=Number.POSITIVE_INFINITY;for(;;){A=b*k,R=b*w,$=Math.floor(M/A)*A,z=Math.floor(v/R)*R;const ce=Math.ceil(E/A)*A,Xe=Math.ceil(T/R)*R;if(K=Math.round((ce-$)/k),j=Math.round((Xe-z)/w),Math.max(K,j)>200)k*=2,w*=2;else break}const Z=k*t.value.zoom,U=w*t.value.zoom,L=Math.round(Z),W=Math.round(U),X=p(L,W,e.background);if(!X)return;X.setTransform(new DOMMatrix().scale(Z/L,U/W));const ie=($-M)*t.value.zoom,ee=(z-v)*t.value.zoom;y.save(),y.translate(ie,ee),y.fillStyle=X,y.fillRect(0,0,S+A*t.value.zoom,C+R*t.value.zoom),y.restore()}function g(){const y=l.value;if(!y)return;const k=y.getContext("2d");if(!k)return;const{width:w,height:b}=s.value;w===0||b===0||(y.width=w,y.height=b,k.clearRect(0,0,w,b),k.fillStyle=e.background.color,k.fillRect(0,0,w,b),e.background.kind==="dots"?h(k):e.background.kind==="grid"&&m(k))}return c.watch(()=>[e.background,t.value,o.value,s.value],()=>{g()},{deep:!0}),c.onMounted(()=>{const y=r==null?void 0:r.value;if(y){const k=()=>{s.value={width:y.clientWidth,height:y.clientHeight}};k(),i=new ResizeObserver(k),i.observe(y)}g()}),c.onUnmounted(()=>{i==null||i.disconnect()}),(y,k)=>(c.openBlock(),c.createElementBlock("canvas",{ref_key:"canvasRef",ref:l,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none"}},null,512))}});function Tu(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 a=new Set(l.components.map(d=>d.name));for(const d of r)a.has(d)||r.delete(d)}return r}const Nu=c.defineComponent({__name:"FloatingMenuBar",setup(n){const e=c.useSlots(),{reset:t}=Vt(),o=c.inject(Di),{selectedIds:r,commonComponents:s}=o,i=new Set(["color","text","verticalAlign","penStroke","elbowArrow","arcArrow","shape"]),l=c.computed(()=>{const d=[];for(const u of s.value){const f=`button:${u}`;!i.has(u)&&e[f]&&d.push(u)}return d});function a(){t()}return c.onUnmounted(()=>{t()}),(d,u)=>(c.openBlock(),c.createElementBlock("div",{class:"wov-floating-menu-bar",onMouseleave:a},[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(l.value,f=>c.renderSlot(d.$slots,`button:${f}`,{key:f,entityIds:c.unref(r)})),128)),c.unref(s).has("color")?c.renderSlot(d.$slots,"button:color",{key:0,entityIds:c.unref(r)},()=>[c.createVNode(ku,{entityIds:c.unref(r)},null,8,["entityIds"])]):c.createCommentVNode("",!0),c.unref(s).has("shape")?c.renderSlot(d.$slots,"button:shape",{key:1,entityIds:c.unref(r)},()=>[c.createVNode(xu,{entityIds:c.unref(r)},null,8,["entityIds"]),c.createVNode(bu,{entityIds:c.unref(r)},null,8,["entityIds"]),c.createVNode(Su,{entityIds:c.unref(r)},null,8,["entityIds"])]):c.createCommentVNode("",!0),c.unref(s).has("penStroke")?c.renderSlot(d.$slots,"button:penStroke",{key:2,entityIds:c.unref(r)},()=>[c.createVNode(wu,{entityIds:c.unref(r)},null,8,["entityIds"])]):c.createCommentVNode("",!0),c.unref(s).has("elbowArrow")||c.unref(s).has("arcArrow")?(c.openBlock(),c.createElementBlock(c.Fragment,{key:3},[c.renderSlot(d.$slots,"button:arrowThickness",{entityIds:c.unref(r)},()=>[c.createVNode(mu,{entityIds:c.unref(r)},null,8,["entityIds"])]),c.renderSlot(d.$slots,"button:arrowHeadStart",{entityIds:c.unref(r)},()=>[c.createVNode(di,{entityIds:c.unref(r),side:"start"},null,8,["entityIds"])]),c.renderSlot(d.$slots,"button:arrowHeadEnd",{entityIds:c.unref(r)},()=>[c.createVNode(di,{entityIds:c.unref(r),side:"end"},null,8,["entityIds"])])],64)):c.createCommentVNode("",!0),c.unref(s).has("text")?c.renderSlot(d.$slots,"button:text",{key:4,entityIds:c.unref(r)},()=>[c.createVNode(Iw,{entityIds:c.unref(r),showVerticalAlign:c.unref(s).has("verticalAlign")},null,8,["entityIds","showVerticalAlign"])]):c.createCommentVNode("",!0),c.createVNode(ui)],32))}}),Ow={class:"wov-floating-menu-inner"},Bu=c.defineComponent({__name:"FloatingMenu",setup(n){const e=c.inject($e),t=_d([x.Block,oe.Selected]),o=Se(x.Camera),r=Se(x.Screen),s=Se(oe.SelectionStateSingleton),i=ao(),l=c.computed(()=>t.value.map(S=>S.entityId)),a=c.computed(()=>{const S=e==null?void 0:e.getEditor();if(!S||t.value.length===0)return new Set;const C=t.value.map(M=>({tag:M.block.value.tag}));return Tu(S,C)});c.provide(Di,{selectedIds:l,commonComponents:a});const d=[0,0,0,0];function u(...S){let C=1/0,M=1/0,v=-1/0,E=-1/0,T=!1;for(const A of S){if(!A)continue;const R=A.getBoundingClientRect();R.width<=0||(T=!0,C=Math.min(C,R.left),M=Math.min(M,R.top),v=Math.max(v,R.right),E=Math.max(E,R.bottom))}return T?{x:C,y:M,left:C,top:M,right:v,bottom:E,width:v-C,height:E-M,toJSON:()=>({})}:null}const f=c.computed(()=>{if(t.value.length===0)return null;const S=o.value;if(!S)return null;let C=null;for(const M of t.value){const v=M.block.value;Me.Rect.getAabb(v.position,v.size,v.rotateZ,d),Me.Aabb.translate(d,[-S.left,-S.top]),Me.Aabb.scale(d,S.zoom),C===null?C=Me.Aabb.clone(d):Me.Aabb.union(C,d)}return C}),p=c.inject("containerRef"),h=c.computed(()=>{const S=p==null?void 0:p.value;if(!S)return null;o.value,i.updateCounter.value;const C=i.blockElement.value,M=i.textElement.value,v=u(C,M);if(v)return{getBoundingClientRect:()=>v};const E=f.value;if(!E)return null;const T=S.getBoundingClientRect();return{getBoundingClientRect(){return{x:T.left+E[0],y:T.top+E[1],width:E[2]-E[0],height:E[3]-E[1],top:T.top+E[1],left:T.left+E[0],right:T.left+E[2],bottom:T.top+E[3]}}}}),m=c.ref(null),g={name:"clampToViewport",fn({y:S,rects:C}){const E=window.innerHeight-C.floating.height-8;return{y:Math.max(8,Math.min(S,E))}}},{floatingStyles:y}=br(h,m,{placement:"top",middleware:[yr(12),wr({fallbackPlacements:["bottom"]}),kr({padding:8}),g]}),k=c.computed(()=>{const S=f.value,C=r.value;return!S||!C?!0:S[2]<0||S[0]>C.width||S[3]<0||S[1]>C.height}),w=[oe.SelectionState.Dragging,oe.SelectionState.SelectionBoxDragging],b=c.computed(()=>t.value.length>0&&!k.value&&!w.includes(s.value.state));return(S,C)=>(c.openBlock(),c.createBlock(c.Transition,{name:"wov-fade"},{default:c.withCtx(()=>[b.value?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"floatingRef",ref:m,class:"wov-floating-menu",style:c.normalizeStyle(c.unref(y))},[c.createElementVNode("div",Ow,[c.renderSlot(S.$slots,"default",{},()=>[c.createVNode(Nu)])])],4)):c.createCommentVNode("",!0)]),_:3}))}}),Dw={key:0,class:"wov-loading-overlay"},Rw={class:"wov-loading-spinner"},Au=c.defineComponent({__name:"LoadingOverlay",props:{isLoading:{type:Boolean}},setup(n){const e=c.ref("|"),t=["|","/","-","\\"];let o=null;return c.onMounted(()=>{o=setInterval(()=>{const r=t.indexOf(e.value);e.value=t[(r+1)%t.length]},100)}),c.onUnmounted(()=>{o!==null&&clearInterval(o)}),(r,s)=>(c.openBlock(),c.createBlock(c.Transition,{name:"wov-loading-fade"},{default:c.withCtx(()=>[n.isLoading?(c.openBlock(),c.createElementBlock("div",Dw,[c.createElementVNode("div",Rw,c.toDisplayString(e.value),1)])):c.createCommentVNode("",!0)]),_:1}))}}),Dn="editing",_w={class:"wov-action-bar"},Pw=c.defineComponent({__name:"ActionBar",setup(n){const{getEditor:e}=le(),t=c.inject($e),o=c.ref(!1),r=c.ref(!1);if(t){const a=t.registerTickCallback(d=>{const{store:u}=x.getPluginResources(d,Dn);o.value=u.canUndo(),r.value=u.canRedo()});c.onUnmounted(a)}function s(){const a=e();a==null||a.command(x.Undo)}function i(){const a=e();a==null||a.command(x.Redo)}function l(){const a=e();a==null||a.command(oe.RemoveSelected)}return(a,d)=>(c.openBlock(),c.createElementBlock("div",_w,[c.createElementVNode("button",{class:"wov-action-button",onClick:s,"aria-label":"Undo"},[...d[0]||(d[0]=[c.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"},[c.createElementVNode("path",{d:"M3 7v6h6"}),c.createElementVNode("path",{d:"M21 17a9 9 0 0 0-9-9 9 9 0 0 0-6 2.3L3 13"})],-1)])]),c.createElementVNode("button",{class:"wov-action-button",onClick:i,"aria-label":"Redo"},[...d[1]||(d[1]=[c.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"},[c.createElementVNode("path",{d:"M21 7v6h-6"}),c.createElementVNode("path",{d:"M3 17a9 9 0 0 1 9-9 9 9 0 0 1 6 2.3l3 2.7"})],-1)])]),c.createElementVNode("button",{class:"wov-action-button",onClick:l,"aria-label":"Delete"},[...d[2]||(d[2]=[c.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"},[c.createElementVNode("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6"}),c.createElementVNode("path",{d:"M3 6h18"}),c.createElementVNode("path",{d:"M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"})],-1)])])]))}}),lt=c.defineComponent({__name:"ToolbarButton",props:{name:{},tooltip:{},dragOutSnapshot:{},placementSnapshot:{},cursor:{default:"crosshair"}},setup(n){const e=n,t=c.inject(Ar);if(!t)throw new Error("ToolbarButton must be used within a Toolbar component");const o=t,r=c.ref(null),{show:s,hide:i}=Vt(),l=c.computed(()=>o.activeTool.value===e.name);function a(){o.setTool(e.name,e.placementSnapshot,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 p(){i()}return(h,m)=>(c.openBlock(),c.createElementBlock("button",{ref_key:"buttonRef",ref:r,class:c.normalizeClass(["wov-toolbar-button",{selected:l.value}]),onClick:a,onPointerdown:d,onPointerup:u,onMouseenter:f,onMouseleave:p},[c.renderSlot(h.$slots,"default")],34))}}),Vw='<?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>',$w='<?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>',Lw='<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>',dn={Select:"select",Hand:"hand",Crosshair:"crosshair"},Iu={[dn.Select]:{makeSvg:()=>Vw,hotspot:[1,0],rotationOffset:0},[dn.Hand]:{makeSvg:()=>$w,hotspot:[12,12],rotationOffset:0},[dn.Crosshair]:{makeSvg:()=>Lw,hotspot:[12,12],rotationOffset:0}},zw={viewBox:"0 0 20 20",style:{"fill-rule":"evenodd","clip-rule":"evenodd","stroke-miterlimit":"10"}},Ou=c.defineComponent({__name:"SelectTool",setup(n){const{nextEditorTick:e}=le(),{activeTool:t}=ni();return c.watch(t,(o,r)=>{r==="select"&&e(s=>{oe.DeselectAll.spawn(s)})}),(o,r)=>(c.openBlock(),c.createBlock(lt,{name:"select",tooltip:"Select",cursor:c.unref(dn).Select},{default:c.withCtx(()=>[(c.openBlock(),c.createElementBlock("svg",zw,[...r[0]||(r[0]=[c.createElementVNode("g",{transform:"matrix(4.21053,0,0,4.21053,0.842105,0)"},[c.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"]))}}),Du=c.defineComponent({__name:"HandTool",setup(n){return(e,t)=>(c.openBlock(),c.createBlock(lt,{name:"hand",tooltip:"Hand",cursor:c.unref(dn).Hand},{default:c.withCtx(()=>[...t[0]||(t[0]=[c.createElementVNode("svg",{viewBox:"0 0 20.56 24"},[c.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"]))}}),Ru=c.defineComponent({__name:"StickyNoteTool",setup(n){const e=JSON.stringify({block:{tag:"sticky-note",size:[200,200]},color:{red:255,green:242,blue:117},text:{defaultAlignment:x.TextAlignment.Center},verticalAlign:{value:x.VerticalAlignment.Center}});return(t,o)=>(c.openBlock(),c.createBlock(lt,{name:"sticky-note",tooltip:"Sticky Note","drag-out-snapshot":c.unref(e),"placement-snapshot":c.unref(e)},{default:c.withCtx(()=>[...o[0]||(o[0]=[c.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[c.createElementVNode("path",{d:"M4 4h12v12H4z"}),c.createElementVNode("path",{d:"M7 8h6M7 11h4"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),_u=c.defineComponent({__name:"ShapeTool",setup(n){const e=JSON.stringify({block:{tag:"shape",size:[200,200]},shape:{kind:"rectangle",strokeKind:x.StrokeKind.Solid,strokeWidth:2,strokeRed:0,strokeGreen:0,strokeBlue:0,strokeAlpha:255,fillRed:255,fillGreen:255,fillBlue:255,fillAlpha:0},text:{defaultAlignment:x.TextAlignment.Center},verticalAlign:{value:x.VerticalAlignment.Center}});return(t,o)=>(c.openBlock(),c.createBlock(lt,{name:"shape",tooltip:"Shape","drag-out-snapshot":c.unref(e),"placement-snapshot":c.unref(e)},{default:c.withCtx(()=>[...o[0]||(o[0]=[c.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[c.createElementVNode("rect",{x:"3",y:"3",width:"14",height:"14",rx:"2"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),Pu=c.defineComponent({__name:"EraserTool",setup(n){return(e,t)=>(c.openBlock(),c.createBlock(lt,{name:"eraser",tooltip:"Eraser"},{default:c.withCtx(()=>[...t[0]||(t[0]=[c.createElementVNode("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 640 640",fill:"currentColor"},[c.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}))}}),Vu=c.defineComponent({__name:"PenTool",setup(n){return(e,t)=>(c.openBlock(),c.createBlock(lt,{name:"pen",tooltip:"Pen"},{default:c.withCtx(()=>[...t[0]||(t[0]=[c.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5"},[c.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"}),c.createElementVNode("path",{d:"M12 5l3 3","stroke-linecap":"round"})],-1)])]),_:1}))}}),$u=c.defineComponent({__name:"TextTool",setup(n){const e=JSON.stringify({block:{tag:"text",size:[10,29]},text:{constrainWidth:!1,fontSizePx:24}}),t=JSON.stringify({block:{tag:"text",size:[36,29]},text:{content:"text",constrainWidth:!1,fontSizePx:24}});return(o,r)=>(c.openBlock(),c.createBlock(lt,{name:"text",tooltip:"Text","drag-out-snapshot":c.unref(t),"placement-snapshot":c.unref(e)},{default:c.withCtx(()=>[...r[0]||(r[0]=[c.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"},[c.createElementVNode("path",{d:"M12 4v16"}),c.createElementVNode("path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2"}),c.createElementVNode("path",{d:"M9 20h6"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),Lu=c.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:Y.ArrowHeadKind.None,endArrowHead:Y.ArrowHeadKind.V},connector:{}});return(t,o)=>(c.openBlock(),c.createBlock(lt,{name:"elbow-arrow",tooltip:"Elbow Arrow",cursor:"crosshair","drag-out-snapshot":c.unref(e)},{default:c.withCtx(()=>[...o[0]||(o[0]=[c.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},[c.createElementVNode("path",{d:"M4 6 L10 6 L10 14 L16 14"}),c.createElementVNode("path",{d:"M13 11 L16 14 L13 17"})],-1)])]),_:1},8,["drag-out-snapshot"]))}}),zu=c.defineComponent({__name:"ImageTool",setup(n){const{nextEditorTick:e}=le(),{show:t,hide:o}=Vt(),{setTool:r}=ni(),{createImageBlock:s}=Rd(),i=c.ref(null),l=c.ref(null);function a(){var p;(p=l.value)==null||p.click()}async function d(p){var S;const h=p.target,m=(S=h.files)==null?void 0:S[0];if(!m)return;if(h.value="",!m.type.startsWith("image/")){console.warn("Selected file is not an image");return}const g=await e(),y=x.Camera.read(g),k=x.Screen.read(g),w=y.left+k.width/y.zoom/2,b=y.top+k.height/y.zoom/2;await s(m,w,b),r("select",void 0,dn.Select)}function u(){i.value&&t("Image",i.value)}function f(){o()}return(p,h)=>(c.openBlock(),c.createElementBlock("button",{ref_key:"buttonRef",ref:i,class:"wov-toolbar-button",onClick:a,onMouseenter:u,onMouseleave:f},[h[0]||(h[0]=c.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"},[c.createElementVNode("rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2"}),c.createElementVNode("circle",{cx:"9",cy:"9",r:"2"}),c.createElementVNode("path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21"})],-1)),c.createElementVNode("input",{ref_key:"fileInputRef",ref:l,type:"file",accept:"image/*",style:{display:"none"},onChange:d},null,544)],544))}}),Fw={class:"wov-toolbar-container"},Fu=c.defineComponent({__name:"Toolbar",setup(n){const e=c.useSlots(),{reset:t}=Vt(),{nextEditorTick:o}=le(),r=c.ref(null),s=c.ref(null),i=Se(x.Controls),l=c.computed(()=>i.value.leftMouseTool),a=[Ou,Du,$u,zu,_u,Lu,Ru,Vu,Pu],d=c.inject("containerRef"),u=c.ref(null),f=c.ref(!1),p=c.ref(null),h=c.ref(null),m=c.ref(1/0),g=c.ref(0),y=c.ref([]),k=c.ref(8),w=c.ref(48),{width:b}=Cu(d);function S(){return p.value?Array.from(p.value.children).filter(L=>!L.classList.contains("wov-overflow-button")&&!L.classList.contains("wov-menu-tooltip")):[]}function C(){var ie;const L=S();if(L.length===0)return;g.value=L.length;const W=getComputedStyle(p.value);k.value=parseFloat(W.gap)||8;const X=((ie=h.value)==null?void 0:ie.offsetWidth)||40;w.value=X+k.value,y.value=L.map(ee=>ee.offsetWidth)}function M(){if(y.value.length===0)return;const X=b.value-40-20,ie=k.value,ee=w.value;let ce=0,Xe=0;for(let gt=0;gt<y.value.length;gt++){const fn=y.value[gt],zt=ce>0?fn+ie:fn,Ft=y.value.length-gt-1>0?ee:0;if(ce+zt+Ft<=X)ce+=zt,Xe++;else break}m.value=Math.max(1,Xe)}c.watch(b,()=>{y.value.length>0&&M()}),c.onMounted(()=>{c.nextTick(()=>{C(),M()})});const v=c.computed(()=>m.value<g.value);c.watchEffect(()=>{S().forEach((W,X)=>{W.style.display=X<m.value?"":"none"})}),c.watchEffect(()=>{if(!u.value)return;Array.from(u.value.children).forEach((W,X)=>{W.style.display=X>=m.value?"":"none"})});const{floatingStyles:E}=br(h,u,{placement:"top",middleware:[yr(16),wr(),kr({padding:8})],whileElementsMounted:uu});function T(){f.value=!f.value}function A(){f.value=!1}function R(L){const W=L.target;h.value&&!h.value.contains(W)&&u.value&&!u.value.contains(W)&&A()}c.watch(f,L=>{L?document.addEventListener("click",R,!0):document.removeEventListener("click",R,!0)}),c.watch(v,L=>{L||A()});function $(L,W,X){s.value=W??null,o(ie=>{const ee=x.Controls.write(ie);ee.leftMouseTool=L,ee.heldSnapshot=W??"",X&&x.Cursor.setCursor(ie,X)})}function z(L){o(W=>{const X=x.Controls.write(W);X.leftMouseTool="drag-out",X.heldSnapshot=L})}function j(L,W){r.value=L,s.value=W??null}function K(){r.value=null,s.value=null}function Z(){t(),r.value&&s.value&&z(s.value),r.value=null,s.value=null}const U={activeTool:l,heldTool:r,setTool:$,dragOutTool:z,onToolPointerDown:j,onToolPointerUp:K};return c.provide(Ar,U),(L,W)=>(c.openBlock(),c.createElementBlock("div",Fw,[c.createVNode(Pw),c.createElementVNode("div",{ref_key:"toolsContainerRef",ref:p,class:"wov-toolbar",onMouseleave:Z},[c.unref(e).default?c.renderSlot(L.$slots,"default",{key:0}):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},c.renderList(a,(X,ie)=>c.createVNode(c.resolveDynamicComponent(X),{key:ie})),64)),v.value?(c.openBlock(),c.createElementBlock("button",{key:2,ref_key:"overflowBtnRef",ref:h,class:c.normalizeClass(["wov-toolbar-button wov-overflow-button",{"menu-open":f.value}]),onClick:T},[...W[0]||(W[0]=[c.createElementVNode("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2"},[c.createElementVNode("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),c.createElementVNode("line",{x1:"5",y1:"12",x2:"19",y2:"12"})],-1)])],2)):c.createCommentVNode("",!0),c.createVNode(ui)],544),c.unref(d)?(c.openBlock(),c.createBlock(c.Teleport,{key:0,to:c.unref(d)},[f.value&&v.value?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"overflowMenuRef",ref:u,class:"wov-toolbar-overflow-menu",style:c.normalizeStyle(c.unref(E))},[c.unref(e).default?c.renderSlot(L.$slots,"default",{key:0}):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},c.renderList(a,(X,ie)=>c.createVNode(c.resolveDynamicComponent(X),{key:ie})),64))],4)):c.createCommentVNode("",!0)],8,["to"])):c.createCommentVNode("",!0)]))}}),Hw=c.defineComponent({__name:"ArcArrowTool",setup(n){return(e,t)=>(c.openBlock(),c.createBlock(lt,{name:"arc-arrow",tooltip:"Arc Arrow",cursor:"crosshair"},{default:c.withCtx(()=>[...t[0]||(t[0]=[c.createElementVNode("svg",{viewBox:"0 0 20 20",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},[c.createElementVNode("path",{d:"M4 14 Q 10 4, 16 14"}),c.createElementVNode("path",{d:"M13 11 L16 14 L12.5 15.5"})],-1)])]),_:1}))}}),Ww={class:"wov-user-presence-avatars"},jw=["src","alt"],Uw={class:"wov-user-presence-list"},Kw=["src","alt"],qw={class:"wov-user-presence-name"},Jw=4,Hu=c.defineComponent({__name:"UserPresence",props:{users:{}},setup(n){const e=n,t=c.ref(!1),o=c.ref(null);lw(o,()=>{t.value=!1});function r(l){if(!l)return"?";const a=l.trim().split(/\s+/);return a.length>=2?(a[0][0]+a[1][0]).toUpperCase():l.slice(0,2).toUpperCase()}const s=c.computed(()=>e.users.map(l=>({sessionId:l.sessionId,name:l.name,color:l.color,avatar:l.avatar,initials:r(l.name)}))),i=c.computed(()=>s.value.slice(0,Jw));return(l,a)=>n.users.length>1?(c.openBlock(),c.createElementBlock("div",{key:0,ref_key:"containerRef",ref:o,class:"wov-user-presence"},[c.createElementVNode("button",{class:c.normalizeClass(["wov-user-presence-trigger",{"is-open":t.value}]),onClick:a[0]||(a[0]=d=>t.value=!t.value)},[c.createElementVNode("div",Ww,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(i.value,d=>(c.openBlock(),c.createElementBlock("div",{key:d.sessionId,class:"wov-user-avatar",style:c.normalizeStyle({backgroundColor:d.avatar?"transparent":d.color})},[d.avatar?(c.openBlock(),c.createElementBlock("img",{key:0,src:d.avatar,alt:d.name,class:"wov-user-avatar-img"},null,8,jw)):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},[c.createTextVNode(c.toDisplayString(d.initials),1)],64))],4))),128))])],2),t.value?(c.openBlock(),c.createElementBlock("div",{key:0,class:"wov-user-presence-dropdown",onWheel:a[1]||(a[1]=c.withModifiers(()=>{},["stop"]))},[c.createElementVNode("div",Uw,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(s.value,d=>(c.openBlock(),c.createElementBlock("div",{key:d.sessionId,class:"wov-user-presence-item"},[c.createElementVNode("div",{class:"wov-user-avatar wov-user-avatar-small",style:c.normalizeStyle({backgroundColor:d.avatar?"transparent":d.color})},[d.avatar?(c.openBlock(),c.createElementBlock("img",{key:0,src:d.avatar,alt:d.name,class:"wov-user-avatar-img"},null,8,Kw)):(c.openBlock(),c.createElementBlock(c.Fragment,{key:1},[c.createTextVNode(c.toDisplayString(d.initials),1)],64))],4),c.createElementVNode("span",qw,c.toDisplayString(d.name),1)]))),128))])],32)):c.createCommentVNode("",!0)],512)):c.createCommentVNode("",!0)}}),bi=(n,e)=>e.some(t=>n instanceof t);let Wu,ju;function Gw(){return Wu||(Wu=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function Yw(){return ju||(ju=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const xi=new WeakMap,Si=new WeakMap,Er=new WeakMap;function Xw(n){const e=new Promise((t,o)=>{const r=()=>{n.removeEventListener("success",s),n.removeEventListener("error",i)},s=()=>{t(un(n.result)),r()},i=()=>{o(n.error),r()};n.addEventListener("success",s),n.addEventListener("error",i)});return Er.set(e,n),e}function Zw(n){if(xi.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)});xi.set(n,e)}let Ci={get(n,e,t){if(n instanceof IDBTransaction){if(e==="done")return xi.get(n);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return un(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 Uu(n){Ci=n(Ci)}function Qw(n){return Yw().includes(n)?function(...e){return n.apply(vi(this),e),un(this.request)}:function(...e){return un(n.apply(vi(this),e))}}function eb(n){return typeof n=="function"?Qw(n):(n instanceof IDBTransaction&&Zw(n),bi(n,Gw())?new Proxy(n,Ci):n)}function un(n){if(n instanceof IDBRequest)return Xw(n);if(Si.has(n))return Si.get(n);const e=eb(n);return e!==n&&(Si.set(n,e),Er.set(e,n)),e}const vi=n=>Er.get(n);function tb(n,e,{blocked:t,upgrade:o,blocking:r,terminated:s}={}){const i=indexedDB.open(n,e),l=un(i);return o&&i.addEventListener("upgradeneeded",a=>{o(un(i.result),a.oldVersion,a.newVersion,un(i.transaction),a)}),t&&i.addEventListener("blocked",a=>t(a.oldVersion,a.newVersion,a)),l.then(a=>{s&&a.addEventListener("close",()=>s()),r&&a.addEventListener("versionchange",d=>r(d.oldVersion,d.newVersion,d))}).catch(()=>{}),l}const nb=["get","getKey","getAll","getAllKeys","count"],ob=["put","add","delete","clear"],Ei=new Map;function Ku(n,e){if(!(n instanceof IDBDatabase&&!(e in n)&&typeof e=="string"))return;if(Ei.get(e))return Ei.get(e);const t=e.replace(/FromIndex$/,""),o=e!==t,r=ob.includes(t);if(!(t in(o?IDBIndex:IDBObjectStore).prototype)||!(r||nb.includes(t)))return;const s=async function(i,...l){const a=this.transaction(i,r?"readwrite":"readonly");let d=a.store;return o&&(d=d.index(l.shift())),(await Promise.all([d[t](...l),r&&a.done]))[0]};return Ei.set(e,s),s}Uu(n=>({...n,get:(e,t,o)=>Ku(e,t)||n.get(e,t,o),has:(e,t)=>!!Ku(e,t)||n.has(e,t)}));const rb=["continue","continuePrimaryKey","advance"],qu={},Mi=new WeakMap,Ju=new WeakMap,sb={get(n,e){if(!rb.includes(e))return n[e];let t=qu[e];return t||(t=qu[e]=function(...o){Mi.set(this,Ju.get(this)[e](...o))}),t}};async function*ib(...n){let e=this;if(e instanceof IDBCursor||(e=await e.openCursor(...n)),!e)return;e=e;const t=new Proxy(e,sb);for(Ju.set(t,e),Er.set(t,vi(e));e;)yield t,e=await(Mi.get(t)||e.continue()),Mi.delete(t)}function Gu(n,e){return e===Symbol.asyncIterator&&bi(n,[IDBIndex,IDBObjectStore,IDBCursor])||e==="iterate"&&bi(n,[IDBIndex,IDBObjectStore])}Uu(n=>({...n,get(e,t,o){return Gu(e,t)?ib:n.get(e,t,o)},has(e,t){return Gu(e,t)||n.has(e,t)}}));async function Ti(n,e){const t=await tb(n,1,{upgrade(o){o.objectStoreNames.contains(e)||o.createObjectStore(e)}});return new lb(t,e)}var lb=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()}},ab=class{constructor(n){this.jobsStore=null,this.binariesStore=null,this.blobUrls=new Map,this.uploading=new Set,this.uploadPromises=new Map,this.provider=n.provider,this.documentId=n.documentId,this.maxRetries=n.provider.maxRetries??3,this.retryDelay=n.provider.retryDelay??5e3}async init(){const n=`wovencanvas-assets-${this.documentId}`,[e,t]=await Promise.all([Ti(`${n}-jobs`,"jobs"),Ti(`${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");await this.binariesStore.put(n,e);const o={identifier:n,metadata:t,createdAt:Date.now(),retryCount:0};await this.jobsStore.put(n,o);const r=URL.createObjectURL(e);return this.blobUrls.set(n,r),new Promise((s,i)=>{this.uploadPromises.set(n,{resolve:s,reject:i}),this.startUpload(n)})}async getDisplayUrl(n){const e=this.blobUrls.get(n);if(e)return e;try{return await this.provider.resolveUrl(n)}catch(t){return console.error(`Failed to resolve URL for ${n}:`,t),null}}async resumePendingUploads(){if(!this.jobsStore||!this.binariesStore)throw new Error("AssetManager not initialized");const n=await this.jobsStore.getAllEntries();for(const[e]of n){const t=await this.binariesStore.get(e);if(t){const o=URL.createObjectURL(t);this.blobUrls.set(e,o)}this.startUpload(e)}}hasPendingUpload(n){return this.blobUrls.has(n)}isUploading(n){return this.uploading.has(n)}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}try{await this.provider.upload(t,n,e.metadata),await this.onUploadSuccess(n)}catch(o){await this.onUploadError(n,e,o)}}async onUploadSuccess(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.resolve(),this.uploadPromises.delete(n))}async onUploadError(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=this.uploadPromises.get(n);r&&(r.reject(new Error(o)),this.uploadPromises.delete(n))}}},cb="wovencanvas-assets",db="blobs",ub=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){const t=await(await this.getStore()).get(n);if(!t)throw new Error(`Asset not found: ${n}`);return URL.createObjectURL(t.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=Ti(cb,db).then(n=>(this.store=n,n))),this.initPromise)}};const fb={class:"wov-selection-box"},hb=c.defineComponent({__name:"SelectionBox",setup(n){return(e,t)=>(c.openBlock(),c.createElementBlock("div",fb))}}),pb={class:"wov-transform-box"},mb=c.defineComponent({__name:"TransformBox",setup(n){return(e,t)=>(c.openBlock(),c.createElementBlock("div",pb))}}),gb={},yb={class:"wov-transform-handle"};function kb(n,e){return c.openBlock(),c.createElementBlock("div",yb)}const wb=Ht(gb,[["render",kb]]),bb=c.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,x.Color),o=fe(e.entityId,x.VerticalAlign),r=c.ref(null),s={[x.VerticalAlignment.Top]:"flex-start",[x.VerticalAlignment.Center]:"center",[x.VerticalAlignment.Bottom]:"flex-end"},i=c.computed(()=>{var a;return{backgroundColor:t.value?`rgb(${t.value.red}, ${t.value.green}, ${t.value.blue})`:void 0,minHeight:`${e.block.size[0]}px`,alignItems:s[((a=o.value)==null?void 0:a.value)??x.VerticalAlignment.Top]}}),{handleEditEnd:l}=ti({blockData:e,containerRef:r,minWidth:()=>e.block.size[0],minHeight:()=>e.block.size[0]});return(a,d)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:r,class:"wov-sticky-note",style:c.normalizeStyle(i.value)},[c.createVNode(sr,c.mergeProps(e,{"block-element":r.value,onEditEnd:c.unref(l)}),null,16,["block-element","onEditEnd"])],4))}}),Mr=Re.defineCanvasSingleton({name:"blockPlacementState"},{editedCheckpoint:x.field.string().default("").max(36)}),Yu=x.defineQuery(n=>n.with(x.Edited));function xb(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 Sb(n,e,t){const o=x.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,i=t[1]-r[1]/2,l=e.block.rank??x.RankBounds.genNext(n),a=x.createEntity(n);"synced"in e||x.addComponent(n,a,x.Synced,{id:crypto.randomUUID()});const d=Object.assign({},e.block,{position:[s,i],size:r,rank:l});x.addComponent(n,a,x.Block,d);for(const f of o.components)if(!(f.name in e))x.addComponent(n,a,f);else{const p=e[f.name];x.addComponent(n,a,f,p)}const{sessionId:u}=x.getResources(n);return x.addComponent(n,a,x.Held,{sessionId:u}),a}function Xu(n,e,t,o,r){const s=Sb(n,e,t),i=x.Block.read(n,s);if(x.canBlockEdit(n,e.block.tag)&&(x.addComponent(n,s,oe.EditAfterPlacing,{}),r==="placement")){const{store:u}=x.getPluginResources(n,Dn),f=u.createCheckpoint();if(f){const p=Mr.write(n);p.editedCheckpoint=f}}const l=oe.SelectionStateSingleton.write(n);l.state=r==="dragOut"?oe.SelectionState.Dragging:oe.SelectionState.Pointing,l.dragStart=t,l.draggedEntity=s,l.draggedEntityStart=i.position,l.pointingStartClient=o,l.pointingStartWorld=t,l.isCloning=!1;const a=x.Controls.write(n);a.leftMouseTool="select",a.heldSnapshot="";const d=x.Cursor.write(n);d.cursorKind="select",d.rotation=0}function Cb(n){const e=Mr.read(n);if(e.editedCheckpoint){const t=e.editedCheckpoint;Mr.write(n).editedCheckpoint="";const{store:o}=x.getPluginResources(n,Dn);o.onSettled(()=>o.squashToCheckpoint(t),{frames:5})}}const vb=x.defineEditorSystem({phase:"capture"},n=>{Yu.removed(n).length>0&&Yu.current(n).length===0&&Cb(n);const e=x.Controls.read(n);if(!e.heldSnapshot)return;const t=x.getPointerInput(n,[x.PointerButton.Left]);if(t.length===0)return;const o=xb(e.heldSnapshot);if(!o)return;if(e.leftMouseTool==="drag-out"){const s=t.find(i=>i.type==="pointerMove"&&!i.obscured);if(!s)return;Xu(n,o,s.worldPosition,s.screenPosition,"dragOut")}else{const s=t.find(i=>i.type==="pointerDown"&&!i.obscured);if(!s)return;Xu(n,o,s.worldPosition,s.screenPosition,"placement")}}),Eb=x.defineEditorSystem({phase:"update"},n=>{const{store:e}=x.getPluginResources(n,Dn);x.on(n,x.Undo,()=>{e.canUndo()&&(oe.deselectAll(n),e.undo())}),x.on(n,x.Redo,()=>{e.canRedo()&&(oe.deselectAll(n),e.redo())})}),Mb=[{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 Zu(n){return{name:Dn,resources:{store:n.store},singletons:[Mr],systems:[vb,Eb],cursors:Iu,fonts:Mb,keybinds:[{command:x.Undo.name,key:x.Key.Z,mod:!0},{command:x.Redo.name,key:x.Key.Y,mod:!0},{command:x.Redo.name,key:x.Key.Z,mod:!0,shift:!0}]}}const Tb=c.defineComponent({__name:"FileDropZone",props:{maxSize:{default:400}},setup(n){const e=n,{nextEditorTick:t}=le(),{createImageBlock:o}=Rd(),r=c.ref(!1);let s=0;const i=c.inject("containerRef");function l(w){var b;(b=w.dataTransfer)!=null&&b.types.some(S=>S==="Files"||S==="text/uri-list"||S==="text/html")&&(s++,s===1&&(r.value=!0))}function a(){s--,s===0&&(r.value=!1)}function d(){s=0,r.value=!1}c.onMounted(()=>{const w=i==null?void 0:i.value;w&&(w.addEventListener("dragenter",l),w.addEventListener("dragleave",a),w.addEventListener("drop",d))}),c.onUnmounted(()=>{const w=i==null?void 0:i.value;w&&(w.removeEventListener("dragenter",l),w.removeEventListener("dragleave",a),w.removeEventListener("drop",d))});function u(w){w.preventDefault(),w.dataTransfer&&(w.dataTransfer.dropEffect="copy")}function f(w){w.preventDefault()}function p(w){w.preventDefault()}async function h(w){if(w.preventDefault(),!w.dataTransfer)return;const b=w.clientX,S=w.clientY,C=Array.from(w.dataTransfer.files).filter(v=>v.type.startsWith("image/"));if(C.length>0){for(const v of C)await y(v,b,S);return}const M=m(w.dataTransfer);M&&await k(M,b,S)}function m(w){const b=w.getData("text/uri-list");if(b){const v=b.split(`
103
- `).filter(E=>!E.startsWith("#")).find(E=>g(E));if(v)return v}const S=w.getData("text/html");if(S){const M=S.match(/<img[^>]+src=["']([^"']+)["']/i);if(M!=null&&M[1])return M[1]}const C=w.getData("text/plain");return C&&g(C)?C:null}function g(w){try{const S=new URL(w).pathname.toLowerCase();return/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i.test(S)||w.startsWith("data:image/"),!0}catch{return!1}}async function y(w,b,S){const C=await t(),M=x.Camera.read(C),v=x.Screen.read(C),E=M.left+(b-v.left)/M.zoom,T=M.top+(S-v.top)/M.zoom;await o(w,E,T,{maxSize:e.maxSize})}async function k(w,b,S){try{const C=await fetch(w);if(!C.ok){console.warn("Failed to fetch image from URL:",w);return}const M=await C.blob();if(!M.type.startsWith("image/")){console.warn("URL did not return an image:",w);return}const E=new URL(w).pathname.split("/").pop()||"image",T=new File([M],E,{type:M.type});await y(T,b,S)}catch(C){console.warn("Failed to load image from URL:",w,C)}}return(w,b)=>(c.openBlock(),c.createElementBlock("div",{class:c.normalizeClass(["wov-image-drop-zone",{"wov-drag-over":r.value}]),onDragover:u,onDragenter:f,onDragleave:p,onDrop:h},null,34))}}),Nb={class:"wov-user-cursors"},Bb={class:"wov-cursor-svg",viewBox:"0 0 4.35 4.75",width:"20",height:"20"},Ab=["fill"],Ib="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",Ob=c.defineComponent({__name:"UserCursors",props:{users:{},currentSessionId:{},camera:{}},setup(n){const e=n,t=c.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)=>(c.openBlock(),c.createElementBlock("div",Nb,[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(t.value,s=>(c.openBlock(),c.createElementBlock("div",{key:s.sessionId,class:"wov-user-cursor",style:c.normalizeStyle({transform:`translate(${s.screenX}px, ${s.screenY}px)`})},[(c.openBlock(),c.createElementBlock("svg",Bb,[c.createElementVNode("path",{fill:s.color,stroke:"#fff","stroke-miterlimit":"10","stroke-width":".25",d:Ib},null,8,Ab)])),c.createElementVNode("span",{class:"wov-cursor-label",style:c.normalizeStyle({backgroundColor:s.color})},c.toDisplayString(s.name),5)],4))),128))]))}}),Db={key:0,class:"wov-offline-indicator"},Rb=c.defineComponent({__name:"OfflineIndicator",props:{isOnline:{type:Boolean}},setup(n){return(e,t)=>n.isOnline?c.createCommentVNode("",!0):(c.openBlock(),c.createElementBlock("div",Db,"Working Offline"))}}),_b={key:0,class:"wov-version-mismatch-overlay"},Pb=c.defineComponent({__name:"VersionMismatch",props:{versionMismatch:{type:Boolean}},setup(n){function e(){window.location.reload()}return(t,o)=>n.versionMismatch?(c.openBlock(),c.createElementBlock("div",_b,[c.createElementVNode("div",{class:"wov-version-mismatch-dialog"},[o[0]||(o[0]=c.createElementVNode("p",null,"A new version is available.",-1)),o[1]||(o[1]=c.createElementVNode("p",null,"Please refresh the page to continue.",-1)),c.createElementVNode("button",{onClick:e},"Refresh")])])):c.createCommentVNode("",!0)}}),Vb=c.defineComponent({__name:"BackToContentButton",setup(n){const{nextEditorTick:e}=le(),t=Se(x.Camera),o=x.defineQuery(d=>d.with(x.Synced,x.Block,x.Aabb)),r=c.ref(0),s=c.inject($e);if(s){const d=s.registerTickCallback(u=>{o.addedOrRemoved(u).length>0&&(r.value=o.current(u).length)});c.onUnmounted(d)}const i=c.ref(!1);c.watchEffect(()=>{i.value=!t.value.canSeeBlocks&&r.value>0});function l(d,u,f,p,h){const m=u+p,g=f+h;return d[0]<m&&d[2]>u&&d[1]<g&&d[3]>f}function a(){e(d=>{const u=o.current(d);if(u.length===0)return;let f=Number.POSITIVE_INFINITY,p=Number.POSITIVE_INFINITY,h=Number.NEGATIVE_INFINITY,m=Number.NEGATIVE_INFINITY;for(const R of u){const $=x.Aabb.read(d,R);f=Math.min(f,$.value[0]),p=Math.min(p,$.value[1]),h=Math.max(h,$.value[2]),m=Math.max(m,$.value[3])}const g=x.Screen.read(d),y=x.Camera.read(d),k=x.getPluginResources(d,Nr.CONTROLS_PLUGIN_NAME)??Nr.DEFAULT_CONTROLS_OPTIONS;let w=Math.min(g.width/(h-f),g.height/(m-p));w/=1.1,w=Math.min(w,y.zoom),w=Math.max(k.minZoom,Math.min(k.maxZoom,w));const b=(f+h)/2,S=(p+m)/2;let C=b-g.width/w/2,M=S-g.height/w/2;const v=g.width/w,E=g.height/w;let T=!1;for(const R of u){const $=x.Aabb.read(d,R);if(l($.value,C,M,v,E)){T=!0;break}}if(!T){const R=Math.floor(Math.random()*u.length),$=u[R],z=x.Aabb.read(d,$),j=(z.value[0]+z.value[2])/2,K=(z.value[1]+z.value[3])/2;C=j-v/2,M=K-E/2}const A=x.Camera.write(d);A.left=C,A.top=M,A.zoom=w})}return(d,u)=>i.value?(c.openBlock(),c.createElementBlock("button",{key:0,class:"wov-back-to-content",onClick:a},[...u[0]||(u[0]=[c.createElementVNode("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg"},[c.createElementVNode("path",{d:"M10 12L6 8L10 4",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round"})],-1),c.createTextVNode(" Back to content ",-1)])])):c.createCommentVNode("",!0)}}),$b=["data-entity-id","data-selected","data-held-by-other","data-hovered"],Lb=c.defineComponent({__name:"WovenCanvas",props:{store:{},editor:{},background:{},assetProvider:{},pluginOptions:{},controls:{}},emits:["ready"],setup(n,{emit:e}){var Qu;const t=x.defineQuery(N=>N.tracking(x.Block)),o=x.defineQuery(N=>N.with(x.Block).tracking(x.Connector)),r=x.defineQuery(N=>N.with(x.Block).tracking(oe.Selected)),s=x.defineQuery(N=>N.with(x.Block).tracking(x.Held)),i=x.defineQuery(N=>N.with(x.Block).tracking(x.Hovered)),l=x.defineQuery(N=>N.with(x.Block).tracking(x.Edited)),a=x.defineQuery(N=>N.with(x.Block).tracking(x.Opacity)),d=x.defineQuery(N=>N.tracking(x.User)),u=n,f=e,p=c.ref(null),h=c.shallowRef(null),m=x.UserData.parse(((Qu=u.editor)==null?void 0:Qu.user)??{}),g=new Set,y=new Map,k=c.shallowRef([]),w=new Map,b=new Map,S=new Set,C=new Map,M=c.shallowRef([]),v=c.ref(!0),E=c.ref(!1),T=c.ref(!0),A=c.shallowRef(x.Camera.default());function R(N,J,D){let H=w.get(N);H||(H=new Map,w.set(N,H));let P=H.get(J);return P||(P=new Set,H.set(J,P)),P.add(D),()=>{P.delete(D),P.size===0&&(H.delete(J),H.size===0&&w.delete(N))}}function $(N,J,D,H=!1){const P=w.get(J);if(!P)return;const O=P.get(D.name);if(!O||O.size===0)return;let de=null;H||(de=D.snapshot(N,J));for(const Ze of O)Ze(de)}function z(N,J){let D=b.get(N);return D||(D=new Set,b.set(N,D)),D.add(J),()=>{D.delete(J),D.size===0&&b.delete(N)}}function j(N,J){const D=b.get(J.name);if(!D||D.size===0)return;const H=J.snapshot(N);for(const P of D)P(H)}function K(N){return S.add(N),()=>{S.delete(N)}}function Z(){return m.sessionId}function U(N){return y.get(N)??null}const L={hasEntity:N=>g.has(N),getEditor:()=>h.value,getAssetManager:()=>ce,getSessionId:Z,getUserBySessionId:U,subscribeComponent:R,subscribeSingleton:z,registerTickCallback:K};c.provide($e,L),c.provide("containerRef",p);const W=Wd();c.provide(Ri,W);let X=0,ie=null,ee=null,ce=null;async function Xe(){!h.value||!ee||(h.value.nextTick(N=>{fn(N),zt(N);for(const J of S)J(N);ee&&ee.sync(N)}),await h.value.tick(),ie=requestAnimationFrame(Xe))}let gt=null;c.onMounted(async()=>{var Ze,De;if(!p.value)return;gt=()=>{var hn;(hn=p.value)==null||hn.scrollTo(0,0)},p.value.addEventListener("scroll",gt);const N=u.store??{},J={history:!0,...N};N.websocket&&(J.websocket={...N.websocket,onVersionMismatch:hn=>{var yt,ho;E.value=!0,(ho=(yt=N.websocket)==null?void 0:yt.onVersionMismatch)==null||ho.call(yt,hn)},onConnectivityChange:hn=>{var yt,ho;v.value=hn,(ho=(yt=N.websocket)==null?void 0:yt.onConnectivityChange)==null||ho.call(yt,hn)}}),ee=new Re.CanvasStore(J);const D=[],H=u.pluginOptions;(H==null?void 0:H.controls)!==!1&&D.push(Nr.CanvasControlsPlugin((H==null?void 0:H.controls)??{})),(H==null?void 0:H.selection)!==!1&&D.push(oe.createSelectionPlugin((H==null?void 0:H.selection)||void 0)),(H==null?void 0:H.eraser)!==!1&&D.push(mo.createEraserPlugin((H==null?void 0:H.eraser)||void 0)),(H==null?void 0:H.pen)!==!1&&D.push(go.createPenPlugin()),(H==null?void 0:H.arrows)!==!1&&D.push(Y.createArrowsPlugin((H==null?void 0:H.arrows)||void 0)),D.push(Zu({store:ee})),(Ze=u.editor)!=null&&Ze.plugins&&D.push(...u.editor.plugins);const P={...u.editor,user:m,plugins:D,controls:u.controls},O=new x.Editor(p.value,P);await O.initialize(),await ee.initialize({components:O.components,singletons:O.singletons});const de=((De=N.persistence)==null?void 0:De.documentId)??"default";ce=new ab({provider:u.assetProvider??new ub,documentId:de}),await ce.init(),await ce.resumePendingUploads(),h.value=O,ie=requestAnimationFrame(Xe),T.value=!1,f("ready",O,ee)}),c.onUnmounted(()=>{var N;ie!==null&&cancelAnimationFrame(ie),ce==null||ce.close(),ee==null||ee.close(),(N=h.value)==null||N.dispose()});function fn(N){const{events:J,newIndex:D}=N.eventBuffer.readEvents(X);if(X=D,J.length===0)return;const{componentsById:H,singletonsById:P}=x.getResources(N);for(const{entityId:O,eventType:de,componentId:Ze}of J){if(O===x.SINGLETON_ENTITY_ID){if(de===x.EventType.CHANGED){const De=P.get(Ze);De&&j(N,De)}continue}if(de===x.EventType.ADDED)g.add(O);else if(de===x.EventType.REMOVED)g.delete(O),w.delete(O);else if(de===x.EventType.COMPONENT_ADDED){g.add(O);const De=H.get(Ze);De&&$(N,O,De)}else if(de===x.EventType.COMPONENT_REMOVED){const De=H.get(Ze);De&&$(N,O,De,!0)}else if(de===x.EventType.CHANGED){const De=H.get(Ze);De&&$(N,O,De)}}}function zt(N){var H;let J=!1;for(const P of t.added(N)){const O=x.Block.snapshot(N,P),de=(H=h.value)==null?void 0:H.blockDefs[O.tag],Ze=(de==null?void 0:de.stratum)??"content";C.set(P,c.ref({entityId:P,block:O,stratum:Ze,selected:!1,held:null,hovered:!1,edited:!1,opacity:null,connector:null})),J=!0}for(const P of t.removed(N))C.delete(P),J=!0;for(const P of t.changed(N)){const O=C.get(P);if(O){const de=x.Block.snapshot(N,P);O.value.block.rank!==de.rank&&(J=!0),O.value.block=de}}let D=!1;for(const P of d.addedOrChanged(N)){const O=x.User.snapshot(N,P);y.set(O.sessionId,O),D=!0}for(const P of d.removed(N)){const O=x.User.read(N,P);y.delete(O.sessionId),D=!0}D&&(k.value=Array.from(y.values()));for(const P of r.added(N)){const O=C.get(P);O&&!O.value.selected&&(O.value.selected=!0)}for(const P of r.removed(N)){const O=C.get(P);O&&O.value.selected&&(O.value.selected=!1)}for(const P of s.addedOrChanged(N)){const O=C.get(P);O&&(O.value.held=x.Held.snapshot(N,P))}for(const P of s.removed(N)){const O=C.get(P);O&&O.value.held!==null&&(O.value.held=null)}for(const P of i.added(N)){const O=C.get(P);O&&!O.value.hovered&&(O.value.hovered=!0)}for(const P of i.removed(N)){const O=C.get(P);O&&O.value.hovered&&(O.value.hovered=!1)}for(const P of l.added(N)){const O=C.get(P);O&&!O.value.edited&&(O.value.edited=!0)}for(const P of l.removed(N)){const O=C.get(P);O&&O.value.edited&&(O.value.edited=!1)}for(const P of a.addedOrChanged(N)){const O=C.get(P);O&&(O.value.opacity=x.Opacity.snapshot(N,P))}for(const P of a.removed(N)){const O=C.get(P);O&&O.value.opacity!==null&&(O.value.opacity=null)}for(const P of o.addedOrChanged(N)){const O=C.get(P);O&&(O.value.connector=x.Connector.snapshot(N,P))}for(const P of o.removed(N)){const O=C.get(P);O&&O.value.connector!==null&&(O.value.connector=null)}if(J){const P=Array.from(C.values());P.sort((O,de)=>O.value.block.rank>de.value.block.rank?1:-1),M.value=P}}z(x.Camera.name,N=>{N&&(A.value=N)});function Tr(N){const J=N.rotateZ!==0,D=N.flip[0],H=N.flip[1];if(!J&&!D&&!H)return;const P=[];return J&&P.push(`rotate(${N.rotateZ}rad)`),D&&P.push("scaleX(-1)"),H&&P.push("scaleY(-1)"),P.join(" ")}function Rn(N){const{held:J}=N;if(!J||!J.sessionId||J.sessionId===m.sessionId)return null;const D=U(J.sessionId);return(D==null?void 0:D.color)??null}function Ft(N){const{block:J,stratum:D,opacity:H}=N,P=Rn(N),O=H!==null?H.value/255:1;return{position:"absolute",left:`${J.position[0]}px`,top:`${J.position[1]}px`,width:`${J.size[0]}px`,height:`${J.size[1]}px`,zIndex:x.STRATUM_ORDER[D]*1e3,transform:Tr(J),opacity:O,pointerEvents:"none",userSelect:"none","--wov-held-by-color":P??void 0,transition:O===1?"opacity 0ms 32ms":void 0}}return(N,J)=>(c.openBlock(),c.createElementBlock("div",{ref_key:"containerRef",ref:p,class:"wov-root",style:{position:"relative",width:"100%",height:"100%",overflow:"hidden"}},[n.background?c.renderSlot(N.$slots,"background",{key:0,background:n.background},()=>[c.createVNode(Mu,{background:n.background},null,8,["background"])]):c.createCommentVNode("",!0),c.createElementVNode("div",{class:"wov-canvas",style:c.normalizeStyle({position:"absolute",transformOrigin:"0 0",transform:`scale(${A.value.zoom}) translate(${-A.value.left}px, ${-A.value.top}px)`,"--wov-zoom":A.value.zoom})},[(c.openBlock(!0),c.createElementBlock(c.Fragment,null,c.renderList(M.value,D=>(c.openBlock(),c.createElementBlock("div",{key:D.value.entityId,"data-entity-id":D.value.entityId,style:c.normalizeStyle(Ft(D.value)),"data-selected":D.value.selected||void 0,"data-held-by-other":Rn(D.value)!==null||void 0,"data-hovered":D.value.hovered||void 0,class:"wov-block"},[c.renderSlot(N.$slots,`block:${D.value.block.tag}`,c.mergeProps({ref_for:!0},D.value),()=>[D.value.block.tag==="selection-box"?(c.openBlock(),c.createBlock(hb,c.mergeProps({key:0,ref_for:!0},D.value),null,16)):D.value.block.tag==="transform-box"?(c.openBlock(),c.createBlock(mb,c.mergeProps({key:1,ref_for:!0},D.value),null,16)):D.value.block.tag==="transform-handle"?(c.openBlock(),c.createBlock(wb,c.mergeProps({key:2,ref_for:!0},D.value),null,16)):D.value.block.tag==="arrow-handle"?(c.openBlock(),c.createBlock(Pi,c.mergeProps({key:3,ref_for:!0},D.value),null,16)):D.value.block.tag==="arrow-terminal"?(c.openBlock(),c.createBlock(Vi,c.mergeProps({key:4,ref_for:!0},D.value),null,16)):D.value.block.tag==="sticky-note"?(c.openBlock(),c.createBlock(bb,c.mergeProps({key:5,ref_for:!0},D.value),null,16)):D.value.block.tag==="eraser"?(c.openBlock(),c.createBlock(el,c.mergeProps({key:6,ref_for:!0},D.value),null,16)):D.value.block.tag==="pen-stroke"?(c.openBlock(),c.createBlock(nl,c.mergeProps({key:7,ref_for:!0},D.value),null,16)):D.value.block.tag==="arc-arrow"?(c.openBlock(),c.createBlock(_i,c.mergeProps({key:8,ref_for:!0},D.value),null,16)):D.value.block.tag==="elbow-arrow"?(c.openBlock(),c.createBlock($i,c.mergeProps({key:9,ref_for:!0},D.value),null,16)):D.value.block.tag==="text"?(c.openBlock(),c.createBlock(Kd,c.mergeProps({key:10,ref_for:!0},D.value),null,16)):D.value.block.tag==="image"?(c.openBlock(),c.createBlock(tl,c.mergeProps({key:11,ref_for:!0},D.value),null,16)):D.value.block.tag==="shape"?(c.openBlock(),c.createBlock(Ud,c.mergeProps({key:12,ref_for:!0},D.value),null,16)):c.createCommentVNode("",!0)])],12,$b))),128))],4),h.value?c.renderSlot(N.$slots,"user-cursors",{key:1,users:k.value,currentSessionId:c.unref(m).sessionId,camera:A.value},()=>[c.createVNode(Ob,{users:k.value,"current-session-id":c.unref(m).sessionId,camera:A.value},null,8,["users","current-session-id","camera"])]):c.createCommentVNode("",!0),h.value?(c.openBlock(),c.createBlock(Bu,{key:2},{default:c.withCtx(D=>[c.renderSlot(N.$slots,"floating-menu",c.normalizeProps(c.guardReactiveProps(D)))]),_:3})):c.createCommentVNode("",!0),h.value?c.renderSlot(N.$slots,"user-presence",{key:3,users:k.value},()=>[c.createVNode(Hu,{users:k.value},null,8,["users"])]):c.createCommentVNode("",!0),h.value?c.renderSlot(N.$slots,"toolbar",{key:4},()=>[c.createVNode(Fu)]):c.createCommentVNode("",!0),h.value?c.renderSlot(N.$slots,"default",{key:5}):c.createCommentVNode("",!0),c.renderSlot(N.$slots,"offline-indicator",{isOnline:v.value},()=>[c.createVNode(Rb,{"is-online":v.value},null,8,["is-online"])]),c.renderSlot(N.$slots,"version-mismatch",{versionMismatch:E.value},()=>[c.createVNode(Pb,{"version-mismatch":E.value},null,8,["version-mismatch"])]),c.renderSlot(N.$slots,"back-to-content",{},()=>[c.createVNode(Vb)]),c.renderSlot(N.$slots,"loading",{isLoading:T.value},()=>[c.createVNode(Au,{"is-loading":T.value},null,8,["is-loading"])]),h.value?c.renderSlot(N.$slots,"file-drop-zone",{key:6},()=>[c.createVNode(Tb)]):c.createCommentVNode("",!0)],512))}});Object.defineProperty(I,"CanvasComponentDef",{enumerable:!0,get:()=>Re.CanvasComponentDef}),Object.defineProperty(I,"CanvasSingletonDef",{enumerable:!0,get:()=>Re.CanvasSingletonDef}),Object.defineProperty(I,"CanvasStore",{enumerable:!0,get:()=>Re.CanvasStore}),Object.defineProperty(I,"Synced",{enumerable:!0,get:()=>Re.Synced}),Object.defineProperty(I,"defineCanvasComponent",{enumerable:!0,get:()=>Re.defineCanvasComponent}),Object.defineProperty(I,"defineCanvasSingleton",{enumerable:!0,get:()=>Re.defineCanvasSingleton}),I.ARROW_HEADS=Br,I.ArcArrow=_i,I.ArcArrowTool=Hw,I.ArrowHandle=Pi,I.ArrowHead=at,I.ArrowHeadButton=di,I.ArrowTerminal=Vi,I.ArrowThicknessButton=mu,I.CURSORS=Iu,I.CanvasBackground=Mu,I.ColorButton=ku,I.ColorPicker=yu,I.CursorKind=dn,I.EDITING_PLUGIN_NAME=Dn,I.EditableText=sr,I.EditingPlugin=Zu,I.ElbowArrow=$i,I.ElbowArrowTool=Lu,I.Eraser=el,I.EraserTool=Pu,I.FloatingMenu=Bu,I.FloatingMenuBar=Nu,I.HandTool=Du,I.IconChevronDown=Ue,I.ImageBlock=tl,I.ImageTool=zu,I.LoadingOverlay=Au,I.MenuButton=On,I.MenuDropdown=je,I.MenuTooltip=ui,I.PenStroke=nl,I.PenStrokeThicknessButton=wu,I.PenTool=Vu,I.SHAPES=Pn,I.SelectTool=Ou,I.ShapeBlock=Ud,I.ShapeFillColorButton=bu,I.ShapeKindButton=xu,I.ShapeStrokeColorButton=Su,I.ShapeTool=_u,I.StickyNoteTool=Ru,I.TextAlignmentButton=fi,I.TextBlock=Kd,I.TextBoldButton=hi,I.TextColorButton=wi,I.TextFontFamilyButton=mi,I.TextFontSizeButton=gi,I.TextItalicButton=yi,I.TextTool=$u,I.TextUnderlineButton=ki,I.Toolbar=Fu,I.ToolbarButton=lt,I.UserPresence=Hu,I.WovenCanvas=Lb,I.computeCommonComponents=Tu,I.createTooltipContext=Wd,I.getArrowHead=pn,I.useComponent=fe,I.useComponents=_t,I.useEditorContext=le,I.useFonts=vu,I.useQuery=_d,I.useSingleton=Se,I.useTextBatchController=Hd,I.useTextEditorController=ao,I.useTextFormatting=ot,I.useTextStretchBehavior=ti,I.useToolbar=ni,I.useTooltipSingleton=Vt,Object.defineProperty(I,Symbol.toStringTag,{value:"Module"})});
96
+ `,u+=1;else break}let b;const S=k.slice(1);if(S.length>0){const C=S.map(T=>T.slice(g+f)).join(`
97
+ `);C.trim()&&(e.customNestedParser?b=e.customNestedParser(C):b=t.blockTokens(C))}const x=e.createToken(m,b);c.push(x)}if(c.length!==0)return{items:c,raw:d}}function Jw(n,e,t,o){if(!n||!Array.isArray(n.content))return"";const r=typeof t=="function"?t(o):t,[s,...i]=n.content,l=e.renderChildren([s]),c=[`${r}${l}`];return i&&i.length>0&&i.forEach(d=>{const u=e.renderChildren([d]);if(u){const f=u.split(`
98
+ `).map(h=>h?e.indent(h):"").join(`
99
+ `);c.push(f)}}),c.join(`
100
+ `)}function Yw(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 Cl=class Um extends bl{constructor(){super(...arguments),this.type="node"}static create(e={}){const t=typeof e=="function"?e():e;return new Um(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}};function Uo(n){return new Ow({find:n.find,handler:({state:e,range:t,match:o,pasteEvent:r})=>{const s=oe(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(gl(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 Hf(n){return a.customRef((e,t)=>({get(){return e(),n},set(o){n=o,requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})}}))}var Xw=class extends Fw{constructor(n={}){return super(n),this.contentComponent=null,this.appContext=null,this.reactiveState=Hf(this.view.state),this.reactiveExtensionStorage=Hf(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}},Qw=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 Zw=Cl.create({name:"doc",topNode:!0,content:"block+",renderMarkdown:(n,e)=>n.content?e.renderChildren(n.content,`
101
+
102
+ `):""}),jf=Zw,Uf="&nbsp;",eb=" ",tb=Cl.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",Qt(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===Uf||o[0].text===eb)?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?Uf:e.renderChildren(t)},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),Wf=tb,nb=Cl.create({name:"text",group:"inline",parseMarkdown:n=>({type:"text",text:n.text||""}),renderMarkdown:n=>n.text||""}),Kf=nb,qf=(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]},ob=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,rb=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,sb=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,ib=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,lb=oo.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 qf("strong",{...Qt(this.options.HTMLAttributes,n),children:qf("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[Jr({find:ob,type:this.type}),Jr({find:sb,type:this.type})]},addPasteRules(){return[Uo({find:rb,type:this.type}),Uo({find:ib,type:this.type})]}}),Gf=lb,ab=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,cb=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,db=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,ub=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,fb=oo.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",Qt(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[Jr({find:ab,type:this.type}),Jr({find:db,type:this.type})]},addPasteRules(){return[Uo({find:cb,type:this.type}),Uo({find:ub,type:this.type})]}}),Jf=fb,hb=oo.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",Qt(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()}}}),Yf=hb;const pb="aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2",mb="ελ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",El="numeric",vl="ascii",Tl="alpha",Wo="asciinumeric",Ko="alphanumeric",Ml="domain",Xf="emoji",gb="scheme",yb="slashscheme",Al="whitespace";function kb(n,e){return n in e||(e[n]=[]),e[n]}function Mn(n,e,t){e[El]&&(e[Wo]=!0,e[Ko]=!0),e[vl]&&(e[Wo]=!0,e[Tl]=!0),e[Wo]&&(e[Ko]=!0),e[Tl]&&(e[Ko]=!0),e[Ko]&&(e[Ml]=!0),e[Xf]&&(e[Ml]=!0);for(const o in e){const r=kb(o,t);r.indexOf(n)<0&&r.push(n)}}function wb(n,e){const t={};for(const o in e)e[o].indexOf(n)>=0&&(t[o]=!0);return t}function ze(n=null){this.j={},this.jr=[],this.jd=null,this.t=n}ze.groups={},ze.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||ze.groups;let r;return e&&e.j?r=e:(r=new ze(e),t&&o&&Mn(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||ze.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 ze,Object.assign(i.j,l.j),i.jr.push.apply(i.jr,l.jr),i.jd=l.jd,i.t=l.t):i=new ze,s){if(o)if(i.t&&typeof i.t=="string"){const c=Object.assign(wb(i.t,o),t);Mn(s,c,o)}else t&&Mn(s,t,o);i.t=s}return r.j[n]=i,i}};const Q=(n,e,t,o,r)=>n.ta(e,t,o,r),fe=(n,e,t,o,r)=>n.tr(e,t,o,r),Qf=(n,e,t,o,r)=>n.ts(e,t,o,r),R=(n,e,t,o,r)=>n.tt(e,t,o,r),Bt="WORD",Nl="UWORD",Zf="ASCIINUMERICAL",eh="ALPHANUMERICAL",qo="LOCALHOST",Bl="TLD",Il="UTLD",Yr="SCHEME",ro="SLASH_SCHEME",Ol="NUM",_l="WS",Rl="NL",Go="OPENBRACE",Jo="CLOSEBRACE",Xr="OPENBRACKET",Qr="CLOSEBRACKET",Zr="OPENPAREN",es="CLOSEPAREN",ts="OPENANGLEBRACKET",ns="CLOSEANGLEBRACKET",rs="FULLWIDTHLEFTPAREN",ss="FULLWIDTHRIGHTPAREN",is="LEFTCORNERBRACKET",ls="RIGHTCORNERBRACKET",as="LEFTWHITECORNERBRACKET",cs="RIGHTWHITECORNERBRACKET",ds="FULLWIDTHLESSTHAN",us="FULLWIDTHGREATERTHAN",fs="AMPERSAND",hs="APOSTROPHE",ps="ASTERISK",Zt="AT",ms="BACKSLASH",gs="BACKTICK",ys="CARET",en="COLON",Pl="COMMA",ks="DOLLAR",pt="DOT",ws="EQUALS",Dl="EXCLAMATION",Ze="HYPHEN",Yo="PERCENT",bs="PIPE",Ss="PLUS",xs="POUND",Xo="QUERY",Ll="QUOTE",th="FULLWIDTHMIDDLEDOT",Vl="SEMI",mt="SLASH",Qo="TILDE",Cs="UNDERSCORE",nh="EMOJI",Es="SYM";var oh=Object.freeze({__proto__:null,ALPHANUMERICAL:eh,AMPERSAND:fs,APOSTROPHE:hs,ASCIINUMERICAL:Zf,ASTERISK:ps,AT:Zt,BACKSLASH:ms,BACKTICK:gs,CARET:ys,CLOSEANGLEBRACKET:ns,CLOSEBRACE:Jo,CLOSEBRACKET:Qr,CLOSEPAREN:es,COLON:en,COMMA:Pl,DOLLAR:ks,DOT:pt,EMOJI:nh,EQUALS:ws,EXCLAMATION:Dl,FULLWIDTHGREATERTHAN:us,FULLWIDTHLEFTPAREN:rs,FULLWIDTHLESSTHAN:ds,FULLWIDTHMIDDLEDOT:th,FULLWIDTHRIGHTPAREN:ss,HYPHEN:Ze,LEFTCORNERBRACKET:is,LEFTWHITECORNERBRACKET:as,LOCALHOST:qo,NL:Rl,NUM:Ol,OPENANGLEBRACKET:ts,OPENBRACE:Go,OPENBRACKET:Xr,OPENPAREN:Zr,PERCENT:Yo,PIPE:bs,PLUS:Ss,POUND:xs,QUERY:Xo,QUOTE:Ll,RIGHTCORNERBRACKET:ls,RIGHTWHITECORNERBRACKET:cs,SCHEME:Yr,SEMI:Vl,SLASH:mt,SLASH_SCHEME:ro,SYM:Es,TILDE:Qo,TLD:Bl,UNDERSCORE:Cs,UTLD:Il,UWORD:Nl,WORD:Bt,WS:_l});const It=/[a-z]/,Zo=new RegExp("\\p{L}","u"),$l=new RegExp("\\p{Emoji}","u"),Ot=/\d/,zl=/\s/,rh="\r",Fl=`
103
+ `,bb="️",Sb="‍",Hl="";let vs=null,Ts=null;function xb(n=[]){const e={};ze.groups=e;const t=new ze;vs==null&&(vs=ih(pb)),Ts==null&&(Ts=ih(mb)),R(t,"'",hs),R(t,"{",Go),R(t,"}",Jo),R(t,"[",Xr),R(t,"]",Qr),R(t,"(",Zr),R(t,")",es),R(t,"<",ts),R(t,">",ns),R(t,"(",rs),R(t,")",ss),R(t,"「",is),R(t,"」",ls),R(t,"『",as),R(t,"』",cs),R(t,"<",ds),R(t,">",us),R(t,"&",fs),R(t,"*",ps),R(t,"@",Zt),R(t,"`",gs),R(t,"^",ys),R(t,":",en),R(t,",",Pl),R(t,"$",ks),R(t,".",pt),R(t,"=",ws),R(t,"!",Dl),R(t,"-",Ze),R(t,"%",Yo),R(t,"|",bs),R(t,"+",Ss),R(t,"#",xs),R(t,"?",Xo),R(t,'"',Ll),R(t,"/",mt),R(t,";",Vl),R(t,"~",Qo),R(t,"_",Cs),R(t,"\\",ms),R(t,"・",th);const o=fe(t,Ot,Ol,{[El]:!0});fe(o,Ot,o);const r=fe(o,It,Zf,{[Wo]:!0}),s=fe(o,Zo,eh,{[Ko]:!0}),i=fe(t,It,Bt,{[vl]:!0});fe(i,Ot,r),fe(i,It,i),fe(r,Ot,r),fe(r,It,r);const l=fe(t,Zo,Nl,{[Tl]:!0});fe(l,It),fe(l,Ot,s),fe(l,Zo,l),fe(s,Ot,s),fe(s,It),fe(s,Zo,s);const c=R(t,Fl,Rl,{[Al]:!0}),d=R(t,rh,_l,{[Al]:!0}),u=fe(t,zl,_l,{[Al]:!0});R(t,Hl,u),R(d,Fl,c),R(d,Hl,u),fe(d,zl,u),R(u,rh),R(u,Fl),fe(u,zl,u),R(u,Hl,u);const f=fe(t,$l,nh,{[Xf]:!0});R(f,"#"),fe(f,$l,f),R(f,bb,f);const h=R(f,Sb);R(h,"#"),fe(h,$l,f);const p=[[It,i],[Ot,r]],m=[[It,null],[Zo,l],[Ot,s]];for(let g=0;g<vs.length;g++)tn(t,vs[g],Bl,Bt,p);for(let g=0;g<Ts.length;g++)tn(t,Ts[g],Il,Nl,m);Mn(Bl,{tld:!0,ascii:!0},e),Mn(Il,{utld:!0,alpha:!0},e),tn(t,"file",Yr,Bt,p),tn(t,"mailto",Yr,Bt,p),tn(t,"http",ro,Bt,p),tn(t,"https",ro,Bt,p),tn(t,"ftp",ro,Bt,p),tn(t,"ftps",ro,Bt,p),Mn(Yr,{scheme:!0,ascii:!0},e),Mn(ro,{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],b=n[g][1]?{[gb]:!0}:{[yb]:!0};y.indexOf("-")>=0?b[Ml]=!0:It.test(y)?Ot.test(y)?b[Wo]=!0:b[vl]=!0:b[El]=!0,Qf(t,y,y,b)}return Qf(t,"localhost",qo,{ascii:!0}),t.jd=new ze(Es),{start:t,tokens:Object.assign({groups:e},oh)}}function sh(n,e){const t=Cb(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 Cb(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 tn(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 ze(o),s.jr=r.slice(),n.j[c]=s),n=s}return s=new ze(t),s.jr=r.slice(),n.j[e[i-1]]=s,s}function ih(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 er={defaultProtocol:"http",events:null,format:lh,formatHref:lh,nl2br:!1,tagName:"a",target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function jl(n,e=null){let t=Object.assign({},er);n&&(t=Object.assign(t,n instanceof jl?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}jl.prototype={o:er,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]:er[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 lh(n){return n}function ah(n,e){this.t="token",this.v=n,this.tk=e}ah.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=er.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 Ms(n,e){class t extends ah{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 ch=Ms("email",{isLink:!0,toHref(){return"mailto:"+this.toString()}}),dh=Ms("text"),Eb=Ms("nl"),As=Ms("url",{isLink:!0,toHref(n=er.defaultProtocol){return this.hasProtocol()?this.v:`${n}://${this.v}`},hasProtocol(){const n=this.tk;return n.length>=2&&n[0].t!==qo&&n[1].t===en}}),et=n=>new ze(n);function vb({groups:n}){const e=n.domain.concat([fs,ps,Zt,ms,gs,ys,ks,ws,Ze,Ol,Yo,bs,Ss,xs,mt,Es,Qo,Cs]),t=[hs,en,Pl,pt,Dl,Yo,Xo,Ll,Vl,ts,ns,Go,Jo,Qr,Xr,Zr,es,rs,ss,is,ls,as,cs,ds,us],o=[fs,hs,ps,ms,gs,ys,ks,ws,Ze,Go,Jo,Yo,bs,Ss,xs,Xo,mt,Es,Qo,Cs],r=et(),s=R(r,Qo);Q(s,o,s),Q(s,n.domain,s);const i=et(),l=et(),c=et();Q(r,n.domain,i),Q(r,n.scheme,l),Q(r,n.slashscheme,c),Q(i,o,s),Q(i,n.domain,i);const d=R(i,Zt);R(s,Zt,d),R(l,Zt,d),R(c,Zt,d);const u=R(s,pt);Q(u,o,s),Q(u,n.domain,s);const f=et();Q(d,n.domain,f),Q(f,n.domain,f);const h=R(f,pt);Q(h,n.domain,f);const p=et(ch);Q(h,n.tld,p),Q(h,n.utld,p),R(d,qo,p);const m=R(f,Ze);R(m,Ze,m),Q(m,n.domain,f),Q(p,n.domain,f),R(p,pt,h),R(p,Ze,m);const g=R(p,en);Q(g,n.numeric,ch);const y=R(i,Ze),k=R(i,pt);R(y,Ze,y),Q(y,n.domain,i),Q(k,o,s),Q(k,n.domain,i);const b=et(As);Q(k,n.tld,b),Q(k,n.utld,b),Q(b,n.domain,i),Q(b,o,s),R(b,pt,k),R(b,Ze,y),R(b,Zt,d);const S=R(b,en),x=et(As);Q(S,n.numeric,x);const C=et(As),T=et();Q(C,e,C),Q(C,t,T),Q(T,e,C),Q(T,t,T),R(b,mt,C),R(x,mt,C);const E=R(l,en),M=R(c,en),v=R(M,mt),B=R(v,mt);Q(l,n.domain,i),R(l,pt,k),R(l,Ze,y),Q(c,n.domain,i),R(c,pt,k),R(c,Ze,y),Q(E,n.domain,C),R(E,mt,C),R(E,Xo,C),Q(B,n.domain,C),Q(B,e,C),R(B,mt,C);const I=[[Go,Jo],[Xr,Qr],[Zr,es],[ts,ns],[rs,ss],[is,ls],[as,cs],[ds,us]];for(let P=0;P<I.length;P++){const[V,z]=I[P],W=R(C,V);R(T,V,W),R(W,z,C);const G=et(As);Q(W,e,G);const K=et();Q(W,t),Q(G,e,G),Q(G,t,K),Q(K,e,G),Q(K,t,K),R(G,z,C),R(K,z,C)}return R(r,qo,b),R(r,Rl,Eb),{start:r,tokens:oh}}function Tb(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(Ul(dh,e,i)),i=[]),r-=h,u-=h;const p=f.t,m=t.slice(r-u,r);s.push(Ul(p,e,m))}}return i.length>0&&s.push(Ul(dh,e,i)),s}function Ul(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 Mb=typeof console<"u"&&console&&console.warn||(()=>{}),Ab="until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.",ie={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function Nb(){return ze.groups={},ie.scanner=null,ie.parser=null,ie.tokenQueue=[],ie.pluginQueue=[],ie.customSchemes=[],ie.initialized=!1,ie}function uh(n,e=!1){if(ie.initialized&&Mb(`linkifyjs: already initialized - will not register custom scheme "${n}" ${Ab}`),!/^[0-9a-z]+(-[0-9a-z]+)*$/.test(n))throw new Error(`linkifyjs: incorrect scheme format.
104
+ 1. Must only contain digits, lowercase ASCII letters or "-"
105
+ 2. Cannot start or end with "-"
106
+ 3. "-" cannot repeat`);ie.customSchemes.push([n,e])}function Bb(){ie.scanner=xb(ie.customSchemes);for(let n=0;n<ie.tokenQueue.length;n++)ie.tokenQueue[n][1]({scanner:ie.scanner});ie.parser=vb(ie.scanner.tokens);for(let n=0;n<ie.pluginQueue.length;n++)ie.pluginQueue[n][1]({scanner:ie.scanner,parser:ie.parser});return ie.initialized=!0,ie}function Wl(n){return ie.initialized||Bb(),Tb(ie.parser.start,n,sh(ie.scanner.start,n))}Wl.scan=sh;function fh(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 jl(t),r=Wl(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 Kl="[\0-   ᠎ -\u2029  ]",Ib=new RegExp(Kl),Ob=new RegExp(`${Kl}$`),_b=new RegExp(Kl,"g");function Rb(n){return n.length===1?n[0].isLink:n.length===3&&n[1].isLink?["()","[]"].includes(n[0].value+n[2].value):!1}function Pb(n){return new ue({key:new ke("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=pf(t.doc,[...e]);if(vf(l).forEach(({newRange:d})=>{const u=Wk(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(!Ob.test(p))return;f=u[0],h=o.doc.textBetween(f.pos,d.to,void 0," ")}if(f&&h){const p=h.split(Ib).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=Wl(m).map(k=>k.toObject(n.defaultProtocol));if(!Rb(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=>{gl(k.from,k.to,o.doc).some(b=>b.mark.type===n.type)||i.addMark(k.from,k.to,n.type.create({href:k.href}))})}}),!!i.steps.length)return i}})}function Db(n){return new ue({key:new ke("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=Ef(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 Lb(n){return new ue({key:new ke("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=fh(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 An(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(_b,"").match(new RegExp(`^(?:(?:${t.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}var Vb=oo.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"){uh(n);return}uh(n.scheme,n.optionalSlashes)})},onDestroy(){Nb()},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)=>!!An(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=>!!An(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=>!!An(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",Qt(this.options.HTMLAttributes,n),0]:["a",Qt(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=>!!An(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=>!!An(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[Uo({find:n=>{const e=[];if(n){const{protocols:t,defaultProtocol:o}=this.options,r=fh(n).filter(s=>s.isLink&&this.options.isAllowedUri(s.value,{defaultValidate:i=>!!An(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(Pb({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:o=>this.options.isAllowedUri(o,{defaultValidate:r=>!!An(r,e),protocols:e,defaultProtocol:t}),shouldAutoLink:this.options.shouldAutoLink})),n.push(Db({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick==="whenNotEditable"?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&n.push(Lb({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),n}}),hh=Vb,$b=se.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")}}}),ph=$b,zb=20,mh=(n,e=0)=>{const t=[];return!n.children.length||e>zb||Array.from(n.children).forEach(o=>{o.tagName==="SPAN"?t.push(o):o.children.length&&t.push(...mh(o,e+1))}),t},Fb=n=>{if(!n.children.length)return;const e=mh(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}`)})},ql=oo.create({name:"textStyle",priority:101,addOptions(){return{HTMLAttributes:{},mergeNestedSpanStyles:!0}},parseHTML(){return[{tag:"span",consuming:!1,getAttrs:n=>n.hasAttribute("style")?(this.options.mergeNestedSpanStyles&&Fb(n),{}):!1}]},renderHTML({HTMLAttributes:n}){return["span",Qt(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}}}}),Hb=se.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()}}}),gh=se.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()}}}),jb=se.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()}}}),Ub=se.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()}}}),Wb=se.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()}}});se.create({name:"textStyleKit",addExtensions(){const n=[];return this.options.backgroundColor!==!1&&n.push(Hb.configure(this.options.backgroundColor)),this.options.color!==!1&&n.push(gh.configure(this.options.color)),this.options.fontFamily!==!1&&n.push(jb.configure(this.options.fontFamily)),this.options.fontSize!==!1&&n.push(Ub.configure(this.options.fontSize)),this.options.lineHeight!==!1&&n.push(Wb.configure(this.options.lineHeight)),this.options.textStyle!==!1&&n.push(ql.configure(this.options.textStyle)),n}});var yh=gh;function Kb(n={}){return new ue({view(e){return new qb(e,n)}})}class qb{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=md(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 he extends Z{constructor(e){super(e,e)}map(e,t){let o=e.resolve(t.map(this.head));return he.valid(o)?new he(o):Z.near(o)}content(){return $.empty}eq(e){return e instanceof he&&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 he(e.resolve(t.pos))}getBookmark(){return new Gl(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!Gb(e)||!Jb(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&&he.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(he.valid(c))return c}for(;;){let i=t>0?s.firstChild:s.lastChild;if(!i){if(s.isAtom&&!s.isText&&!q.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(he.valid(l))return l}return null}}}he.prototype.visible=!1,he.findFrom=he.findGapCursorFrom,Z.jsonID("gapcursor",he);class Gl{constructor(e){this.pos=e}map(e){return new Gl(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return he.valid(t)?new he(t):Z.near(t)}}function kh(n){return n.isAtom||n.spec.isolating||n.spec.createGapCursor}function Gb(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||kh(r.type))return!0;if(r.inlineContent)return!1}}return!0}function Jb(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||kh(r.type))return!0;if(r.inlineContent)return!1}}return!0}function Yb(){return new ue({props:{decorations:eS,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:Qb,handleKeyDown:Xb,handleDOMEvents:{beforeinput:Zb}}})}const Xb=nf({ArrowLeft:Ns("horiz",-1),ArrowRight:Ns("horiz",1),ArrowUp:Ns("vert",-1),ArrowDown:Ns("vert",1)});function Ns(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 Y){if(!s.endOfTextblock(t)||l.depth==0)return!1;c=!1,l=o.doc.resolve(e>0?l.after():l.before())}let d=he.findGapCursorFrom(l,e,c);return d?(r&&r(o.tr.setSelection(new he(d))),!0):!1}}function Qb(n,e,t){if(!n||!n.editable)return!1;let o=n.state.doc.resolve(e);if(!he.valid(o))return!1;let r=n.posAtCoords({left:t.clientX,top:t.clientY});return r&&r.inside>-1&&q.isSelectable(n.state.doc.nodeAt(r.inside))?!1:(n.dispatch(n.state.tr.setSelection(new he(o))),!0)}function Zb(n,e){if(e.inputType!="insertCompositionText"||!(n.state.selection instanceof he))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=O.empty;for(let i=o.length-1;i>=0;i--)r=O.from(o[i].createAndFill(null,r));let s=n.state.tr.replace(t.pos,t.pos,new $(r,0,0));return s.setSelection(Y.near(s.doc.resolve(t.pos+1))),n.dispatch(s),!1}function eS(n){if(!(n.selection instanceof he))return null;let e=document.createElement("div");return e.className="ProseMirror-gapcursor",ae.create(n.doc,[Le.widget(n.selection.head,e,{key:"gapcursor"})])}var Bs=200,be=function(){};be.prototype.append=function(e){return e.length?(e=be.from(e),!this.length&&e||e.length<Bs&&this.leafAppend(e)||this.length<Bs&&e.leafPrepend(this)||this.appendInner(e)):this},be.prototype.prepend=function(e){return e.length?be.from(e).append(this):this},be.prototype.appendInner=function(e){return new tS(this,e)},be.prototype.slice=function(e,t){return e===void 0&&(e=0),t===void 0&&(t=this.length),e>=t?be.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))},be.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)},be.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)},be.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},be.from=function(e){return e instanceof be?e:e&&e.length?new wh(e):be.empty};var wh=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<=Bs)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=Bs)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}(be);be.empty=new wh([]);var tS=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}(be);const nS=500;class ot{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 gt(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 gt(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 ot(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 gt(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>rS&&(l=oS(l,d),i-=d),new ot(l.append(s),i)}remapping(e,t){let o=new vo;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 ot(this.items.append(e.map(t=>new gt(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 gt(m,g,y))}else o.push(new gt(m))},r);let d=[];for(let h=t;h<i;h++)d.push(new gt(s.maps[h]));let u=this.items.slice(0,r).append(d).append(o),f=new ot(u,l);return f.emptyItemCount()>nS&&(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 gt(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 ot(be.from(r.reverse()),s)}}ot.empty=new ot(be.empty,0);function oS(n,e){let t;return n.forEach((o,r)=>{if(o.selection&&e--==0)return t=r,!1}),n.slice(t)}class gt{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 gt(t.getMap().invert(),t,this.selection)}}}class nn{constructor(e,t,o,r,s){this.done=e,this.undone=t,this.prevRanges=o,this.prevTime=r,this.prevComposition=s}}const rS=20;function sS(n,e,t,o){let r=t.getMeta(Nn),s;if(r)return r.historyState;t.getMeta(aS)&&(n=new nn(n.done,n.undone,null,0,-1));let i=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(i&&i.getMeta(Nn))return i.getMeta(Nn).redo?new nn(n.done.addTransform(t,void 0,o,Is(e)),n.undone,bh(t.mapping.maps),n.prevTime,n.prevComposition):new nn(n.done,n.undone.addTransform(t,void 0,o,Is(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||!iS(t,n.prevRanges)),d=i?Jl(n.prevRanges,t.mapping):bh(t.mapping.maps);return new nn(n.done.addTransform(t,c?e.selection.getBookmark():void 0,o,Is(e)),ot.empty,d,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new nn(n.done.rebased(t,s),n.undone.rebased(t,s),Jl(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new nn(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),Jl(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function iS(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 bh(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 Jl(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 lS(n,e,t){let o=Is(e),r=Nn.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 nn(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(i).setMeta(Nn,{redo:t,historyState:c})}let Yl=!1,Sh=null;function Is(n){let e=n.plugins;if(Sh!=e){Yl=!1,Sh=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){Yl=!0;break}}return Yl}const Nn=new ke("history"),aS=new ke("closeHistory");function cS(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new ue({key:Nn,state:{init(){return new nn(ot.empty,ot.empty,null,0,-1)},apply(e,t,o){return sS(t,o,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let o=t.inputType,r=o=="historyUndo"?Ch:o=="historyRedo"?Eh:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function xh(n,e){return(t,o)=>{let r=Nn.getState(t);if(!r||(n?r.undone:r.done).eventCount==0)return!1;if(o){let s=lS(r,t,n);s&&o(e?s.scrollIntoView():s)}return!0}}const Ch=xh(!1,!0),Eh=xh(!0,!0);se.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 ue({key:new ke("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)}})]}}),se.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[Kb(this.options)]}}),se.create({name:"focus",addOptions(){return{className:"has-focus",mode:"all"}},addProseMirrorPlugins(){return[new ue({key:new ke("focus"),props:{decorations:({doc:n,selection:e})=>{const{isEditable:t,isFocused:o}=this.editor,{anchor:r}=e,s=[];if(!t||!o)return ae.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(Le.node(d,d+c.nodeSize,{class:this.options.className}))}),ae.create(n,s)}}})]}}),se.create({name:"gapCursor",addProseMirrorPlugins(){return[Yb()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=oe(H(n,"allowGapCursor",t)))!=null?e:null}}});var vh="placeholder";function dS(n){return n.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}se.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:vh,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){const n=this.options.dataAttribute?`data-${dS(this.options.dataAttribute)}`:`data-${vh}`;return[new ue({key:new ke("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&&Ur(l);if((d||!this.options.showOnlyCurrent)&&u){const f=[this.options.emptyNodeClass];i&&f.push(this.options.emptyEditorClass);const h=Le.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}),ae.create(e,s)}}})]}}),se.create({name:"selection",addOptions(){return{className:"selection"}},addProseMirrorPlugins(){const{editor:n,options:e}=this;return[new ue({key:new ke("selection"),props:{decorations(t){return t.selection.empty||n.isFocused||!n.isEditable||nw(t.selection)||n.view.dragging?null:ae.create(t.doc,[Le.inline(t.selection.from,t.selection.to,{class:e.className})])}}})]}});function Th({types:n,node:e}){return e&&Array.isArray(n)&&n.includes(e.type)||(e==null?void 0:e.type)===n}se.create({name:"trailingNode",addOptions(){return{node:void 0,notAfter:[]}},addProseMirrorPlugins(){var n;const e=new ke(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 ue({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!Th({node:i,types:o})},apply:(r,s)=>{if(!r.docChanged||r.getMeta("__uniqueIDTransaction"))return s;const i=r.doc.lastChild;return!Th({node:i,types:o})}}})]}});var uS=se.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>Ch(n,e),redo:()=>({state:n,dispatch:e})=>Eh(n,e)}},addProseMirrorPlugins(){return[cS(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()}}});function _t(n,e){const t=a.inject(je);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 Mh(){const n=a.inject(je);if(!n)throw new Error("useImageCreation must be used within a WovenCanvas component");const{nextEditorTick:e}=de();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 b=crypto.randomUUID();w.addComponent(f,y,w.Asset);const S=w.Asset.write(f,y);S.identifier=b,S.uploadState=w.UploadState.Pending,w.addComponent(f,y,w.Image);const x=w.Image.write(f,y);return x.width=u.width,x.height=u.height,x.alt=s.name,w.addComponent(f,y,Ve.Synced,{id:crypto.randomUUID()}),(n==null?void 0:n.getAssetManager())&&r(y,b,s),y}async function r(s,i,l){const c=n==null?void 0:n.getAssetManager();if(c)try{await c.upload(i,l,{filename:l.name,mimeType:l.type});const d=await e(),u=w.Asset.write(d,s);u.uploadState=w.UploadState.Complete}catch{const d=await e(),u=w.Asset.write(d,s);u.uploadState=w.UploadState.Failed}}return{getImageDimensions:t,createImageBlock:o}}function Ah(n){const e=a.inject(je);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 b=e.subscribeComponent(f,y.name,S=>{k.value=S});g.push(b)}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(je);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 Xl(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}}function Nh(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 tr(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 Ql(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 Bh(n){const e=Ql(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 Ih(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 Oh(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 Ae=a.shallowRef(null),Zl=a.shallowRef(null),ea=a.shallowRef(null),Rt=a.ref(0);function nr(){const n={hasEditor:a.computed(()=>Ae.value!==null),isBold:a.computed(()=>{var r;return Rt.value,((r=Ae.value)==null?void 0:r.isActive("bold"))??!1}),isItalic:a.computed(()=>{var r;return Rt.value,((r=Ae.value)==null?void 0:r.isActive("italic"))??!1}),isUnderline:a.computed(()=>{var r;return Rt.value,((r=Ae.value)==null?void 0:r.isActive("underline"))??!1}),alignment:a.computed(()=>{Rt.value;const r=Ae.value;return r?r.isActive({textAlign:"center"})?"center":r.isActive({textAlign:"right"})?"right":r.isActive({textAlign:"justify"})?"justify":"left":"left"}),color:a.computed(()=>{Rt.value;const r=Ae.value;if(!r)return null;const i=r.getAttributes("textStyle").color??null;return i?Nh(i):null}),linkHref:a.computed(()=>{Rt.value;const r=Ae.value;return r?r.getAttributes("link").href??null:null})},e={toggleBold(){const r=Ae.value;if(!r)return;const{from:s,to:i}=r.state.selection,l=s===i;let c=r.chain().focus();l&&(c=c.selectAll()),c=c.toggleBold(),l&&(c=c.setTextSelection(i)),c.run()},toggleItalic(){const r=Ae.value;if(!r)return;const{from:s,to:i}=r.state.selection,l=s===i;let c=r.chain().focus();l&&(c=c.selectAll()),c=c.toggleItalic(),l&&(c=c.setTextSelection(i)),c.run()},toggleUnderline(){const r=Ae.value;if(!r)return;const{from:s,to:i}=r.state.selection,l=s===i;let c=r.chain().focus();l&&(c=c.selectAll()),c=c.toggleUnderline(),l&&(c=c.setTextSelection(i)),c.run()},setAlignment(r){const s=Ae.value;s&&s.chain().selectAll().setTextAlign(r).run()},setColor(r){const s=Ae.value;if(!s)return;const{from:i,to:l}=s.state.selection;i===l?s.chain().focus().selectAll().setColor(r).setTextSelection(l).run():s.chain().focus().setColor(r).run()},setLink(r){const s=Ae.value;if(!s)return;const{from:i,to:l}=s.state.selection;i===l?s.chain().focus().selectAll().setLink({href:r}).setTextSelection(l).run():s.chain().focus().setLink({href:r}).run()},removeLink(){const r=Ae.value;if(!r)return;const{from:s,to:i}=r.state.selection;s===i?r.chain().focus().selectAll().unsetLink().setTextSelection(i).run():r.chain().focus().unsetLink().run()}};function t(r,s,i){Ae.value=r,ea.value=s,Zl.value=i,r.on("selectionUpdate",()=>{Rt.value++}),r.on("transaction",()=>{Rt.value++})}function o(){Ae.value=null,ea.value=null,Zl.value=null}return{editor:Ae,blockElement:Zl,textElement:ea,state:n,commands:e,updateCounter:Rt,register:t,unregister:o}}const Ne=[jf,Wf,Kf,ql,yh,Gf,Jf,Yf,hh.configure({openOnClick:!1}),ph.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:"left"})];function fS(n){return n.type==="text"&&typeof n.text=="string"}function yt(n,e){if(fS(n)){e(n);return}if(n.content)for(const t of n.content)yt(t,e)}function ta(n,e){if(n.type==="paragraph"){e(n);return}if(n.content)for(const t of n.content)ta(t,e)}function hS(n,e){var t;return((t=n.marks)==null?void 0:t.some(o=>o.type===e))??!1}function pS(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?Nh(t):null}function mS(n,e){if(!n.trim())return!1;const t=nt(n,Ne);let o=!1,r=!0,s=0;return yt(t,i=>{s++,hS(i,e)?o=!0:r=!1}),s===0?!1:r?!0:o?null:!1}function gS(n){if(!n.trim())return"left";const e=nt(n,Ne);let t="left";return ta(e,o=>{var s;const r=(s=o.attrs)==null?void 0:s.textAlign;r&&(t=r)}),t}function yS(n){if(!n.trim())return null;const e=nt(n,Ne);let t=null;return yt(e,o=>{t===null&&(t=pS(o))}),t}function na(n,e){if(!n.trim())return n;const t=nt(n,Ne);return yt(t,o=>{const r=o.marks??[];r.findIndex(i=>i.type===e)===-1&&(o.marks=[...r,{type:e}])}),no(t,Ne)}function oa(n,e){if(!n.trim())return n;const t=nt(n,Ne);return yt(t,o=>{const r=o.marks??[];o.marks=r.filter(s=>s.type!==e)}),no(t,Ne)}function kS(n,e){if(!n.trim())return n;const t=nt(n,Ne);return ta(t,o=>{o.attrs={...o.attrs,textAlign:e}}),no(t,Ne)}function wS(n,e){if(!n.trim())return n;const t=nt(n,Ne);return yt(t,o=>{const r=o.marks??[],s=r.findIndex(i=>i.type==="textStyle");s!==-1?(r[s]={...r[s],attrs:{...r[s].attrs,color:e}},o.marks=r):o.marks=[...r,{type:"textStyle",attrs:{color:e}}]}),no(t,Ne)}function bS(n){if(!n.trim())return null;const e=nt(n,Ne);let t=null;return yt(e,o=>{var r,s;if(t===null){const i=(r=o.marks)==null?void 0:r.find(l=>l.type==="link");(s=i==null?void 0:i.attrs)!=null&&s.href&&(t=i.attrs.href)}}),t}function SS(n,e){if(!n.trim())return n;const t=nt(n,Ne);return yt(t,o=>{const r=o.marks??[],s=r.findIndex(i=>i.type==="link");s!==-1?(r[s]={...r[s],attrs:{...r[s].attrs,href:e}},o.marks=r):o.marks=[...r,{type:"link",attrs:{href:e,target:"_blank",rel:"noopener noreferrer"}}]}),no(t,Ne)}function xS(n){if(!n.trim())return n;const e=nt(n,Ne);return yt(e,t=>{const o=t.marks??[];t.marks=o.filter(r=>r.type!=="link")}),no(e,Ne)}function _h(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 Rh(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=Xl(r,e,t);return r.remove(),l}function Ph(n){const{nextEditorTick:e}=de(),t=_t(n,w.Text),o=Me(w.Camera),r=Me(w.Screen),s=nr(),i={hasTextEntities:a.computed(()=>{for(const h of t.value.values())if(h)return!0;return!1}),hasTextContent:a.computed(()=>{for(const h of t.value.values()){if(!h)continue;const p=h.content?nt(h.content,Ne):null;if(p){let m=!1;if(yt(p,g=>{var y;(y=g.text)!=null&&y.trim()&&(m=!0)}),m)return!0}}return!1}),isBold:a.computed(()=>l("bold")),isItalic:a.computed(()=>l("italic")),isUnderline:a.computed(()=>l("underline")),alignment:a.computed(()=>{let h=null;for(const p of t.value.values()){if(!p)continue;const m=gS(p.content);if(h===null)h=m;else if(h!==m)return null}return h??"left"}),color:a.computed(()=>{let h=null,p=!1;for(const m of t.value.values()){if(!m)continue;const g=yS(m.content);if(!p)h=g,p=!0;else if(h!==g)return null}return h}),fontSize:a.computed(()=>{let h=null,p=!1;for(const m of t.value.values())if(m){if(!p)h=m.fontSizePx,p=!0;else if(h!==m.fontSizePx)return null}return h}),fontFamily:a.computed(()=>{let h=null,p=!1;for(const m of t.value.values())if(m){if(!p)h=m.fontFamily,p=!0;else if(h!==m.fontFamily)return null}return h}),linkHref:a.computed(()=>{let h=null,p=!1;for(const m of t.value.values()){if(!m)continue;const g=bS(m.content);if(!p)h=g,p=!0;else if(h!==g)return null}return h})};function l(h){let p=null,m=!1;for(const g of t.value.values()){if(!g)continue;const y=mS(g.content,h);if(!m)p=y,m=!0;else if(p!==y)return null}return p}const c={toggleBold(){u(h=>i.isBold.value?oa(h,"bold"):na(h,"bold"))},toggleItalic(){u(h=>i.isItalic.value?oa(h,"italic"):na(h,"italic"))},toggleUnderline(){u(h=>i.isUnderline.value?oa(h,"underline"):na(h,"underline"))},setAlignment(h){f(p=>kS(p,h))},setColor(h){f(p=>wS(p,h))},setFontSize(h){d(p=>({...p,fontSizePx:h}),p=>{p.fontSizePx=h})},setFontFamily(h){d(p=>({...p,fontFamily:h}),p=>{p.fontFamily=h})},setTextStyle(h){d(p=>({...p,fontFamily:h.fontFamily??p.fontFamily,fontSizePx:h.fontSizePx??p.fontSizePx,lineHeight:h.lineHeight??p.lineHeight,letterSpacingEm:h.letterSpacingEm??p.letterSpacingEm}),p=>{h.fontFamily!==void 0&&(p.fontFamily=h.fontFamily),h.fontSizePx!==void 0&&(p.fontSizePx=h.fontSizePx),h.lineHeight!==void 0&&(p.lineHeight=h.lineHeight),h.letterSpacingEm!==void 0&&(p.letterSpacingEm=h.letterSpacingEm)})},setLink(h){f(p=>SS(p,h))},removeLink(){f(h=>xS(h))}};function d(h,p){const m=a.toValue(n),g=[];for(const y of m){const k=t.value.get(y);if(!k)continue;const b=_h(y);if(b){const S=Rh(b,o,r,h(k));g.push({entityId:y,...S})}}e(y=>{for(const k of m)p(w.Text.write(y,k));for(const{entityId:k,width:b,height:S,left:x,top:C}of g){const T=w.Block.write(y,k);T.size=[b,S],T.position=[x,C]}a.nextTick(()=>{var k;s.updateCounter.value++,(k=s.editor.value)==null||k.commands.focus()})})}function u(h){const p=a.toValue(n),m=[];for(const g of p){const y=t.value.get(g);if(!y)continue;const k=h(y.content),b=_h(g);if(b){const S=Rh(b,o,r,{...y,content:k});m.push({entityId:g,content:k,...S})}else m.push({entityId:g,content:k,width:0,height:0,left:0,top:0})}e(g=>{for(const{entityId:y,content:k,width:b,height:S,left:x,top:C}of m){const T=w.Text.write(g,y);if(T.content=k,b>0&&S>0){const E=w.Block.write(g,y);E.size=[b,S],E.position=[x,C]}}})}function f(h){const p=a.toValue(n);e(m=>{for(const g of p){const y=w.Text.write(m,g);y.content=h(y.content)}})}return{state:i,commands:c}}function rt(n){const e=nr(),t=Ph(n),o=e.state.hasEditor;return{state: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)}),commands:{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(i){o.value?e.commands.setAlignment(i):t.commands.setAlignment(i)},setColor(i){o.value?e.commands.setColor(i):t.commands.setColor(i)},setFontSize(i){t.commands.setFontSize(i)},setFontFamily(i){t.commands.setFontFamily(i)},setTextStyle(i){t.commands.setTextStyle(i)},setLink(i){o.value?e.commands.setLink(i):t.commands.setLink(i)},removeLink(){o.value?e.commands.removeLink():t.commands.removeLink()}}}}function ra(n){const e=Me(w.Camera),t=Me(w.Screen),o=Me(ne.TransformBoxStateSingleton),r=Me(ne.SelectionStateSingleton),{nextEditorTick:s}=de();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),b=Math.abs(k.size[0]-g)>.5,S=Math.abs(k.size[1]-y)>.5;if(!b&&!S)return;const x=w.Block.write(u,h);x.size=[g,y],x.position=[f.left,f.top],o.value.transformBoxId!==null&&ne.UpdateTransformBox.spawn(u,{transformBoxId:o.value.transformBoxId})}a.watch(()=>r.value,()=>{s(u=>{const f=CS(u);if(i&&!f){const h=n.containerRef.value;if(!h)return;l=Xl(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 CS(n){const e=ne.SelectionStateSingleton.read(n);return e.state===ne.SelectionState.Dragging&&e.draggedEntity!==null&&w.hasComponent(n,e.draggedEntity,ne.TransformHandle)&&ne.TransformHandle.read(n,e.draggedEntity).kind===ne.TransformHandleKind.Stretch}function Os(){const n=a.inject(di);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 ES=500,vS=1500;function Dh(){const n=a.ref(null),e=a.ref(!1),t=a.ref(!1);let o=null,r=null;function s(){o&&(clearTimeout(o),o=null),r&&(clearTimeout(r),r=null)}function i(d,u){s(),n.value={text:d,anchor:u},t.value?e.value=!0:o=setTimeout(()=>{e.value=!0,t.value=!0,o=null},ES)}function l(){s(),e.value=!1,n.value=null,t.value&&(r=setTimeout(()=>{t.value=!1,r=null},vS))}function c(){s(),e.value=!1,n.value=null,t.value=!1}return{activeTooltip:a.readonly(n),isVisible:a.readonly(e),isWarmedUp:a.readonly(t),show:i,hide:l,reset:c}}function Pt(){const n=a.inject(ic);if(!n)throw new Error("useTooltipSingleton must be used within a WovenCanvas component");return n}const TS={key:1},MS=["innerHTML"],Lh=50,AS=300,_s=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=pe(o.entityId,w.Text),i=Me(w.Camera),l=Me(w.Screen),c=nr(),{nextEditorTick:d}=de(),u=Me(w.Mouse),f=a.ref(null);e({editableTextRef:f});const h=a.ref(((M=s.value)==null?void 0:M.content)??""),p=a.shallowRef(null);function m(v){const I=new DOMParser().parseFromString(v,"text/html");return I.body.querySelectorAll("[style], [class]").forEach(P=>{P.removeAttribute("style"),P.removeAttribute("class")}),I.body.innerHTML}function g(){d(v=>{const B=w.Text.write(v,o.entityId);B.constrainWidth=!0;const I=w.Block.read(v,o.entityId),P=Math.max(I.size[0],AS),V=w.Block.write(v,o.entityId);V.size=[P,I.size[1]],w.ResetKeyboard.spawn(v),ne.DeselectAll.spawn(v)})}function y(v,B){var W,G,K;const I=s.value;if(!I)return!1;const P=((W=B.clipboardData)==null?void 0:W.getData("text/html"))??"",V=((G=B.clipboardData)==null?void 0:G.getData("text/plain"))??"";return!P.includes("data-pm-slice")&&P?(B.preventDefault(),(K=p.value)==null||K.commands.insertContent(m(P),{parseOptions:{preserveWhitespace:!0}}),!I.constrainWidth&&V.length>Lh&&g(),!0):(!I.constrainWidth&&V.length>Lh&&g(),!1)}function k(){var v,B;return new Xw({extensions:[jf,Wf,Kf,ql,yh,Gf,Jf,Yf,hh.configure({openOnClick:!1,HTMLAttributes:{rel:"noopener noreferrer",target:"_blank"}}),ph.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:((v=s.value)==null?void 0:v.defaultAlignment)??"left"}),uS],content:((B=s.value)==null?void 0:B.content)??"",editable:!0,parseOptions:{preserveWhitespace:!0},editorProps:{handlePaste:y}})}a.watch(()=>o.edited,async v=>{if(v&&f.value){if(p.value=k(),await b(p.value),!o.blockElement)return;c.register(p.value,f.value,o.blockElement)}else p.value&&(c.unregister(),S(p.value),p.value.destroy(),p.value=null)},{immediate:!0});async function b(v){var V;const B=(V=u.value)==null?void 0:V.position,I=l.value;await a.nextTick(),await new Promise(z=>requestAnimationFrame(z));const P=f.value;if(B&&I&&P){const z=B[0]+I.left,W=B[1]+I.top,G=v.view.posAtCoords({left:z,top:W});if(G){v.chain().focus().setTextSelection(G.pos).run();return}}v.commands.focus("start")}function S(v){let B=v.getHTML();const P=B.replace(/<[^>]*>/g,"").trim().length>0;P||(B=""),h.value=B,d(V=>{var j,F;const z=w.getBlockDef(V,o.block.tag);if(!P&&((j=z.editOptions)!=null&&j.removeWhenTextEmpty)){w.removeEntity(V,o.entityId);return}const W=(F=f.value)==null?void 0:F.closest(".wov-block"),G=(W==null?void 0:W.firstElementChild)??f.value;if(!G){console.warn("EditableText: no element to measure");return}const K=Xl(G,i,l);r("editEnd",{content:B,...K})})}a.watch(()=>{var v;return(v=s.value)==null?void 0:v.content},v=>{v!==void 0&&(p.value?p.value.getHTML()!==v&&p.value.commands.setContent(v,{emitUpdate:!1}):h.value=v)});const x=a.computed(()=>{const v=s.value;if(!v)return{};const[B,I]=o.block.flip,P=B?-1:1,V=I?-1:1,z=B||I;return{fontFamily:v.fontFamily,fontSize:`${v.fontSizePx}px`,lineHeight:v.lineHeight,letterSpacing:`${v.letterSpacingEm}em`,width:v.constrainWidth?"100%":"fit-content",whiteSpace:v.constrainWidth?"pre-wrap":"pre",minWidth:"2px",wordBreak:"break-word",pointerEvents:o.edited?"auto":"none",userSelect:o.edited?"auto":"none",transform:z?`scale(${P}, ${V})`:void 0}});function C(v){v.key==="Control"||v.key==="Meta"||v.stopPropagation()}function T(v){o.edited&&v.stopPropagation()}function E(v){if(o.edited)return;const B=v.target.closest("a");if(!B)return;const I=B.getAttribute("href");I&&(v.preventDefault(),v.stopPropagation(),window.open(I,"_blank","noopener,noreferrer"))}return a.onUnmounted(()=>{p.value&&(c.unregister(),p.value.destroy(),p.value=null)}),(v,B)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"editableTextRef",ref:f,class:"wov-editable-text",style:a.normalizeStyle(x.value),onKeydown:C,onPointerdown:T,onPointermove:T,onPointerup:T,onClick:E},[p.value?(a.openBlock(),a.createBlock(a.unref(Qw),{key:0,editor:p.value},null,8,["editor"])):(a.openBlock(),a.createElementBlock("div",TS,[a.createElementVNode("div",{class:"tiptap ProseMirror",innerHTML:h.value},null,8,MS)]))],36))}}),NS={class:"wov-shape-svg",viewBox:"0 0 100 100",preserveAspectRatio:"none"},BS=["d","fill","stroke","stroke-width","stroke-dasharray"],Vh=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=pe(e.entityId,w.Shape),o=pe(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 bo[((g=t.value)==null?void 0:g.kind)??"rectangle"]??bo.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"";case w.StrokeKind.Solid: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}=de();function m(g){p(y=>{if(w.Text.read(y,e.entityId).content===g.content)return;const b=w.Text.write(y,e.entityId);b.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",NS,[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(_s,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"},$h=a.defineComponent({__name:"TapeBlock",props:{entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},setup(n){const e=n,t=a.inject(je);if(!t)throw new Error("TapeBlock must be used within a WovenCanvas component");const o=t,r=pe(e.entityId,w.Asset),s=a.ref(null),i=a.ref(!0),l=a.ref(!1);let c=!0;a.onUnmounted(()=>{c=!1});async function d(){const u=o.getAssetManager();if(!u){i.value=!1,l.value=!0;return}const f=r.value;if(!f||!f.identifier){i.value=!1;return}try{i.value=!0,l.value=!1;const h=await u.getDisplayUrl(f.identifier);if(!c)return;h?(s.value=h,i.value=!1):f.uploadState===w.UploadState.Failed&&(l.value=!0,i.value=!1)}catch(h){if(!c)return;console.error("Failed to get tape display URL:",h),l.value=!0,i.value=!1}}return a.watch(()=>r.value,()=>{d()},{immediate:!0}),a.onMounted(()=>{d()}),(u,f)=>(a.openBlock(),a.createElementBlock("div",IS,[i.value&&!s.value?(a.openBlock(),a.createElementBlock("div",OS)):s.value?(a.openBlock(),a.createElementBlock("div",{key:1,class:"wov-tape-image",style:a.normalizeStyle({backgroundImage:`url(${s.value})`})},null,4)):a.createCommentVNode("",!0)]))}}),_S=["data-text-empty"],zh=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=pe(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}=ra({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(_s,a.mergeProps(e,{"block-element":t.value,onEditEnd:a.unref(i)}),null,16,["block-element","onEditEnd"])],12,_S))}}),Rs=Math.min,Bn=Math.max,Ps=Math.round,Ds=Math.floor,kt=n=>({x:n,y:n}),RS={left:"right",right:"left",bottom:"top",top:"bottom"},PS={start:"end",end:"start"};function Fh(n,e,t){return Bn(n,Rs(e,t))}function Ls(n,e){return typeof n=="function"?n(e):n}function In(n){return n.split("-")[0]}function Vs(n){return n.split("-")[1]}function Hh(n){return n==="x"?"y":"x"}function jh(n){return n==="y"?"height":"width"}const DS=new Set(["top","bottom"]);function on(n){return DS.has(In(n))?"y":"x"}function Uh(n){return Hh(on(n))}function LS(n,e,t){t===void 0&&(t=!1);const o=Vs(n),r=Uh(n),s=jh(r);let i=r==="x"?o===(t?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=$s(i)),[i,$s(i)]}function VS(n){const e=$s(n);return[sa(n),e,sa(e)]}function sa(n){return n.replace(/start|end/g,e=>PS[e])}const Wh=["left","right"],Kh=["right","left"],$S=["top","bottom"],zS=["bottom","top"];function FS(n,e,t){switch(n){case"top":case"bottom":return t?e?Kh:Wh:e?Wh:Kh;case"left":case"right":return e?$S:zS;default:return[]}}function HS(n,e,t,o){const r=Vs(n);let s=FS(In(n),t==="start",o);return r&&(s=s.map(i=>i+"-"+r),e&&(s=s.concat(s.map(sa)))),s}function $s(n){return n.replace(/left|right|bottom|top/g,e=>RS[e])}function jS(n){return{top:0,right:0,bottom:0,left:0,...n}}function US(n){return typeof n!="number"?jS(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 qh(n,e,t){let{reference:o,floating:r}=n;const s=on(e),i=Uh(e),l=jh(i),c=In(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(Vs(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 WS(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}=Ls(e,n),m=US(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})),b=f==="floating"?{x:o,y:r,width:i.floating.width,height:i.floating.height}:i.reference,S=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),x=await(s.isElement==null?void 0:s.isElement(S))?await(s.getScale==null?void 0:s.getScale(S))||{x:1,y:1}:{x:1,y:1},C=zs(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:b,offsetParent:S,strategy:c}):b);return{top:(k.top-C.top+m.top)/x.y,bottom:(C.bottom-k.bottom+m.bottom)/x.y,left:(k.left-C.left+m.left)/x.x,right:(C.right-k.right+m.right)/x.x}}const KS=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}=qh(d,o,c),h=o,p={},m=0;for(let y=0;y<l.length;y++){var g;const{name:k,fn:b}=l[y],{x:S,y:x,data:C,reset:T}=await b({x:u,y:f,initialPlacement:o,placement:h,strategy:r,middlewareData:p,rects:d,platform:{...i,detectOverflow:(g=i.detectOverflow)!=null?g:WS},elements:{reference:n,floating:e}});u=S??u,f=x??f,p={...p,[k]:{...p[k],...C}},T&&m<=50&&(m++,typeof T=="object"&&(T.placement&&(h=T.placement),T.rects&&(d=T.rects===!0?await i.getElementRects({reference:n,floating:e,strategy:r}):T.rects),{x:u,y:f}=qh(d,h,c)),y=-1)}return{x:u,y:f,placement:h,strategy:r,middlewareData:p}},qS=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}=Ls(n,e);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const k=In(r),b=on(l),S=In(l)===l,x=await(c.isRTL==null?void 0:c.isRTL(d.floating)),C=h||(S||!g?[$s(l)]:VS(l)),T=m!=="none";!h&&T&&C.push(...HS(l,g,m,x));const E=[l,...C],M=await c.detectOverflow(e,y),v=[];let B=((o=s.flip)==null?void 0:o.overflows)||[];if(u&&v.push(M[k]),f){const z=LS(r,i,x);v.push(M[z[0]],M[z[1]])}if(B=[...B,{placement:r,overflows:v}],!v.every(z=>z<=0)){var I,P;const z=(((I=s.flip)==null?void 0:I.index)||0)+1,W=E[z];if(W&&(!(f==="alignment"?b!==on(W):!1)||B.every(j=>on(j.placement)===b?j.overflows[0]>0:!0)))return{data:{index:z,overflows:B},reset:{placement:W}};let G=(P=B.filter(K=>K.overflows[0]<=0).sort((K,j)=>K.overflows[1]-j.overflows[1])[0])==null?void 0:P.placement;if(!G)switch(p){case"bestFit":{var V;const K=(V=B.filter(j=>{if(T){const F=on(j.placement);return F===b||F==="y"}return!0}).map(j=>[j.placement,j.overflows.filter(F=>F>0).reduce((F,X)=>F+X,0)]).sort((j,F)=>j[1]-F[1])[0])==null?void 0:V[0];K&&(G=K);break}case"initialPlacement":G=l;break}if(r!==G)return{reset:{placement:G}}}return{}}}},GS=new Set(["left","top"]);async function JS(n,e){const{placement:t,platform:o,elements:r}=n,s=await(o.isRTL==null?void 0:o.isRTL(r.floating)),i=In(t),l=Vs(t),c=on(t)==="y",d=GS.has(i)?-1:1,u=s&&c?-1:1,f=Ls(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 YS=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 JS(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}}}}},XS=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:b,y:S}=k;return{x:b,y:S}}},...d}=Ls(n,e),u={x:t,y:o},f=await s.detectOverflow(e,d),h=on(In(r)),p=Hh(h);let m=u[p],g=u[h];if(i){const k=p==="y"?"top":"left",b=p==="y"?"bottom":"right",S=m+f[k],x=m-f[b];m=Fh(S,m,x)}if(l){const k=h==="y"?"top":"left",b=h==="y"?"bottom":"right",S=g+f[k],x=g-f[b];g=Fh(S,g,x)}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 Fs(){return typeof window<"u"}function On(n){return ia(n)?(n.nodeName||"").toLowerCase():"#document"}function Ke(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function wt(n){var e;return(e=(ia(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function ia(n){return Fs()?n instanceof Node||n instanceof Ke(n).Node:!1}function st(n){return Fs()?n instanceof Element||n instanceof Ke(n).Element:!1}function bt(n){return Fs()?n instanceof HTMLElement||n instanceof Ke(n).HTMLElement:!1}function Gh(n){return!Fs()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof Ke(n).ShadowRoot}const QS=new Set(["inline","contents"]);function or(n){const{overflow:e,overflowX:t,overflowY:o,display:r}=it(n);return/auto|scroll|overlay|hidden|clip/.test(e+o+t)&&!QS.has(r)}const ZS=new Set(["table","td","th"]);function ex(n){return ZS.has(On(n))}const tx=[":popover-open",":modal"];function Hs(n){return tx.some(e=>{try{return n.matches(e)}catch{return!1}})}const nx=["transform","translate","scale","rotate","perspective"],ox=["transform","translate","scale","rotate","perspective","filter"],rx=["paint","layout","strict","content"];function la(n){const e=aa(),t=st(n)?it(n):n;return nx.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)||ox.some(o=>(t.willChange||"").includes(o))||rx.some(o=>(t.contain||"").includes(o))}function sx(n){let e=rn(n);for(;bt(e)&&!so(e);){if(la(e))return e;if(Hs(e))return null;e=rn(e)}return null}function aa(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const ix=new Set(["html","body","#document"]);function so(n){return ix.has(On(n))}function it(n){return Ke(n).getComputedStyle(n)}function js(n){return st(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function rn(n){if(On(n)==="html")return n;const e=n.assignedSlot||n.parentNode||Gh(n)&&n.host||wt(n);return Gh(e)?e.host:e}function Jh(n){const e=rn(n);return so(e)?n.ownerDocument?n.ownerDocument.body:n.body:bt(e)&&or(e)?e:Jh(e)}function rr(n,e,t){var o;e===void 0&&(e=[]),t===void 0&&(t=!0);const r=Jh(n),s=r===((o=n.ownerDocument)==null?void 0:o.body),i=Ke(r);if(s){const l=ca(i);return e.concat(i,i.visualViewport||[],or(r)?r:[],l&&t?rr(l):[])}return e.concat(r,rr(r,[],t))}function ca(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function Yh(n){const e=it(n);let t=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=bt(n),s=r?n.offsetWidth:t,i=r?n.offsetHeight:o,l=Ps(t)!==s||Ps(o)!==i;return l&&(t=s,o=i),{width:t,height:o,$:l}}function da(n){return st(n)?n:n.contextElement}function io(n){const e=da(n);if(!bt(e))return kt(1);const t=e.getBoundingClientRect(),{width:o,height:r,$:s}=Yh(e);let i=(s?Ps(t.width):t.width)/o,l=(s?Ps(t.height):t.height)/r;return(!i||!Number.isFinite(i))&&(i=1),(!l||!Number.isFinite(l))&&(l=1),{x:i,y:l}}const lx=kt(0);function Xh(n){const e=Ke(n);return!aa()||!e.visualViewport?lx:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function ax(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==Ke(n)?!1:e}function _n(n,e,t,o){e===void 0&&(e=!1),t===void 0&&(t=!1);const r=n.getBoundingClientRect(),s=da(n);let i=kt(1);e&&(o?st(o)&&(i=io(o)):i=io(n));const l=ax(s,t,o)?Xh(s):kt(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=Ke(s),p=o&&st(o)?Ke(o):o;let m=h,g=ca(m);for(;g&&o&&p!==m;){const y=io(g),k=g.getBoundingClientRect(),b=it(g),S=k.left+(g.clientLeft+parseFloat(b.paddingLeft))*y.x,x=k.top+(g.clientTop+parseFloat(b.paddingTop))*y.y;c*=y.x,d*=y.y,u*=y.x,f*=y.y,c+=S,d+=x,m=Ke(g),g=ca(m)}}return zs({width:u,height:f,x:c,y:d})}function Us(n,e){const t=js(n).scrollLeft;return e?e.left+t:_n(wt(n)).left+t}function Qh(n,e){const t=n.getBoundingClientRect(),o=t.left+e.scrollLeft-Us(n,t),r=t.top+e.scrollTop;return{x:o,y:r}}function cx(n){let{elements:e,rect:t,offsetParent:o,strategy:r}=n;const s=r==="fixed",i=wt(o),l=e?Hs(e.floating):!1;if(o===i||l&&s)return t;let c={scrollLeft:0,scrollTop:0},d=kt(1);const u=kt(0),f=bt(o);if((f||!f&&!s)&&((On(o)!=="body"||or(i))&&(c=js(o)),bt(o))){const p=_n(o);d=io(o),u.x=p.x+o.clientLeft,u.y=p.y+o.clientTop}const h=i&&!f&&!s?Qh(i,c):kt(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 dx(n){return Array.from(n.getClientRects())}function ux(n){const e=wt(n),t=js(n),o=n.ownerDocument.body,r=Bn(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),s=Bn(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let i=-t.scrollLeft+Us(n);const l=-t.scrollTop;return it(o).direction==="rtl"&&(i+=Bn(e.clientWidth,o.clientWidth)-r),{width:r,height:s,x:i,y:l}}const Zh=25;function fx(n,e){const t=Ke(n),o=wt(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=aa();(!u||u&&e==="fixed")&&(l=r.offsetLeft,c=r.offsetTop)}const d=Us(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<=Zh&&(s-=m)}else d<=Zh&&(s+=d);return{width:s,height:i,x:l,y:c}}const hx=new Set(["absolute","fixed"]);function px(n,e){const t=_n(n,!0,e==="fixed"),o=t.top+n.clientTop,r=t.left+n.clientLeft,s=bt(n)?io(n):kt(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 ep(n,e,t){let o;if(e==="viewport")o=fx(n,t);else if(e==="document")o=ux(wt(n));else if(st(e))o=px(e,t);else{const r=Xh(n);o={x:e.x-r.x,y:e.y-r.y,width:e.width,height:e.height}}return zs(o)}function tp(n,e){const t=rn(n);return t===e||!st(t)||so(t)?!1:it(t).position==="fixed"||tp(t,e)}function mx(n,e){const t=e.get(n);if(t)return t;let o=rr(n,[],!1).filter(l=>st(l)&&On(l)!=="body"),r=null;const s=it(n).position==="fixed";let i=s?rn(n):n;for(;st(i)&&!so(i);){const l=it(i),c=la(i);!c&&l.position==="fixed"&&(r=null),(s?!c&&!r:!c&&l.position==="static"&&!!r&&hx.has(r.position)||or(i)&&!c&&tp(n,i))?o=o.filter(u=>u!==i):r=l,i=rn(i)}return e.set(n,o),o}function gx(n){let{element:e,boundary:t,rootBoundary:o,strategy:r}=n;const i=[...t==="clippingAncestors"?Hs(e)?[]:mx(e,this._c):[].concat(t),o],l=i[0],c=i.reduce((d,u)=>{const f=ep(e,u,r);return d.top=Bn(f.top,d.top),d.right=Rs(f.right,d.right),d.bottom=Rs(f.bottom,d.bottom),d.left=Bn(f.left,d.left),d},ep(e,l,r));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function yx(n){const{width:e,height:t}=Yh(n);return{width:e,height:t}}function kx(n,e,t){const o=bt(e),r=wt(e),s=t==="fixed",i=_n(n,!0,s,e);let l={scrollLeft:0,scrollTop:0};const c=kt(0);function d(){c.x=Us(r)}if(o||!o&&!s)if((On(e)!=="body"||or(r))&&(l=js(e)),o){const p=_n(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?Qh(r,l):kt(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 ua(n){return it(n).position==="static"}function np(n,e){if(!bt(n)||it(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return wt(n)===t&&(t=t.ownerDocument.body),t}function op(n,e){const t=Ke(n);if(Hs(n))return t;if(!bt(n)){let r=rn(n);for(;r&&!so(r);){if(st(r)&&!ua(r))return r;r=rn(r)}return t}let o=np(n,e);for(;o&&ex(o)&&ua(o);)o=np(o,e);return o&&so(o)&&ua(o)&&!la(o)?t:o||sx(n)||t}const wx=async function(n){const e=this.getOffsetParent||op,t=this.getDimensions,o=await t(n.floating);return{reference:kx(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function bx(n){return it(n).direction==="rtl"}const Sx={convertOffsetParentRelativeRectToViewportRelativeRect:cx,getDocumentElement:wt,getClippingRect:gx,getOffsetParent:op,getElementRects:wx,getClientRects:dx,getDimensions:yx,getScale:io,isElement:st,isRTL:bx};function rp(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function xx(n,e){let t=null,o;const r=wt(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=Ds(f),g=Ds(r.clientWidth-(u+h)),y=Ds(r.clientHeight-(f+p)),k=Ds(u),S={rootMargin:-m+"px "+-g+"px "+-y+"px "+-k+"px",threshold:Bn(0,Rs(1,c))||1};let x=!0;function C(T){const E=T[0].intersectionRatio;if(E!==c){if(!x)return i();E?i(!1,E):o=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!rp(d,n.getBoundingClientRect())&&i(),x=!1}try{t=new IntersectionObserver(C,{...S,root:r.ownerDocument})}catch{t=new IntersectionObserver(C,S)}t.observe(n)}return i(!0),s}function Ws(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=da(n),u=r||s?[...d?rr(d):[],...rr(e)]:[];u.forEach(k=>{r&&k.addEventListener("scroll",t,{passive:!0}),s&&k.addEventListener("resize",t)});const f=d&&l?xx(d,t):null;let h=-1,p=null;i&&(p=new ResizeObserver(k=>{let[b]=k;b&&b.target===d&&p&&(p.unobserve(e),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var S;(S=p)==null||S.observe(e)})),t()}),d&&!c&&p.observe(d),p.observe(e));let m,g=c?_n(n):null;c&&y();function y(){const k=_n(n);g&&!rp(g,k)&&t(),g=k,m=requestAnimationFrame(y)}return t(),()=>{var k;u.forEach(b=>{r&&b.removeEventListener("scroll",t),s&&b.removeEventListener("resize",t)}),f==null||f(),(k=p)==null||k.disconnect(),p=null,c&&cancelAnimationFrame(m)}}const lo=YS,ao=XS,co=qS,Cx=(n,e,t)=>{const o=new Map,r={platform:Sx,...t},s={...r.platform,_c:o};return KS(n,e,{...r,platform:s})};function Ex(n){return n!=null&&typeof n=="object"&&"$el"in n}function sp(n){if(Ex(n)){const e=n.$el;return ia(e)&&On(e)==="#comment"?null:e}return n}function sr(n){return typeof n=="function"?n():a.unref(n)}function ip(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function lp(n,e){const t=ip(n);return Math.round(e*t)/t}function uo(n,e,t){t===void 0&&(t={});const o=t.whileElementsMounted,r=a.computed(()=>{var E;return(E=sr(t.open))!=null?E:!0}),s=a.computed(()=>sr(t.middleware)),i=a.computed(()=>{var E;return(E=sr(t.placement))!=null?E:"bottom"}),l=a.computed(()=>{var E;return(E=sr(t.strategy))!=null?E:"absolute"}),c=a.computed(()=>{var E;return(E=sr(t.transform))!=null?E:!0}),d=a.computed(()=>sp(n.value)),u=a.computed(()=>sp(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=lp(u.value,f.value),v=lp(u.value,h.value);return c.value?{...E,transform:"translate("+M+"px, "+v+"px)",...ip(u.value)>=1.5&&{willChange:"transform"}}:{position:p.value,left:M+"px",top:v+"px"}});let b;function S(){if(d.value==null||u.value==null)return;const E=r.value;Cx(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 x(){typeof b=="function"&&(b(),b=void 0)}function C(){if(x(),o===void 0){S();return}if(d.value!=null&&u.value!=null){b=o(d.value,u.value,S);return}}function T(){r.value||(y.value=!1)}return a.watch([s,i,l,r],S,{flush:"sync"}),a.watch([d,u],C,{flush:"sync"}),a.watch(r,T,{flush:"sync"}),a.getCurrentScope()&&a.onScopeDispose(x),{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:S}}const vx=["menu-open"],qe=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(oc,null),i=a.inject(rc,0),l=Math.random().toString(36).slice(2);a.provide(rc,i+1);const{show:c,hide:d}=Pt(),u=a.ref(!1);s&&a.watch(()=>s.value.get(i),S=>{S!==void 0&&S!==l&&u.value&&(u.value=!1)});const f=a.ref(null),h=a.ref(null),{floatingStyles:p}=uo(f,h,{placement:t.placement,middleware:[lo(t.offsetPx),co(),ao({padding:8})],whileElementsMounted:Ws});function m(){t.disabled||(u.value=!u.value)}function g(){u.value=!1}function y(S){var M,v,B;const x=S.target,C=(M=f.value)==null?void 0:M.contains(x),T=(v=h.value)==null?void 0:v.contains(x),E=(B=x.closest)==null?void 0:B.call(x,".wov-menu-dropdown");!C&&!T&&!E&&g()}function k(){t.title&&f.value&&!u.value&&c(t.title,f.value)}function b(){d()}return a.watch(u,S=>{S?(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)}),(S,x)=>(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:x[0]||(x[0]=a.withModifiers(()=>{},["prevent"])),onClick:m,onMouseenter:k,onMouseleave:b},[a.renderSlot(S.$slots,"button",{isOpen:u.value})],42,vx),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(S.$slots,"dropdown",{close:g})],4)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)],64))}}),Tx={},Mx={viewBox:"0 0 512 320",fill:"currentColor",style:{width:"7px",color:"var(--wov-gray-300)"}};function Ax(n,e){return a.openBlock(),a.createElementBlock("svg",Mx,[...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=fn(Tx,[["render",Ax]]),Nx={class:"wov-menu-button"},Bx=["innerHTML"],Ix=["onClick"],Ox=["innerHTML"],fa=a.defineComponent({__name:"ArrowHeadButton",props:{entityIds:{},side:{}},setup(n){const e=n,{nextEditorTick:t}=de(),o=a.shallowRef(null),r=a.computed(()=>{const l=o.value??(e.side==="start"?ee.ArrowHeadKind.None:ee.ArrowHeadKind.V);return Fn(l)});t(l=>{let c=null;for(const d of e.entityIds){if(w.hasComponent(l,d,ee.ElbowArrow)){const u=ee.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"?ee.ArrowHeadKind.None:ee.ArrowHeadKind.V;return}}if(w.hasComponent(l,d,ee.ArcArrow)){const u=ee.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"?ee.ArrowHeadKind.None:ee.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,ee.ElbowArrow)){const u=ee.ElbowArrow.write(c,d);e.side==="start"?u.startArrowHead=l:u.endArrowHead=l}if(w.hasComponent(c,d,ee.ArcArrow)){const u=ee.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(qe,{title:n.side==="start"?"Start Arrow Head":"End Arrow Head"},{button:a.withCtx(()=>[a.createElementVNode("div",Nx,[(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,Bx)),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(a.unref(ci),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,Ox))],10,Ix))),128))]),_:1},8,["title"]))}}),_x={class:"wov-menu-button"},Rx=["onClick"],ap=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}=de(),r=a.shallowRef(null);o(i=>{let l=null;for(const c of t.entityIds){if(w.hasComponent(i,c,ee.ElbowArrow)){const d=ee.ElbowArrow.read(i,c);if(l===null)l=d.thickness;else if(d.thickness!==l){r.value=null;return}}if(w.hasComponent(i,c,ee.ArcArrow)){const d=ee.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,ee.ElbowArrow)){const d=ee.ElbowArrow.write(l,c);d.thickness=i}w.hasComponent(l,c,ee.ArcArrow)&&ee.ArcArrow.setThickness(l,c,i)}})}return(i,l)=>(a.openBlock(),a.createBlock(qe,{title:"Thickness"},{button:a.withCtx(()=>[a.createElementVNode("div",_x,[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,Rx)),64))]),_:1}))}}),Px=["value"],Dx=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,Px))}}),cp=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))}}),Lx={class:"wov-color-picker"},Vx={class:"wov-color-picker-area"},$x={class:"wov-color-picker-selector-gradient"},zx="linear-gradient(to bottom, red 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%)",dp=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 T,E;return u.value||((T=r.value)==null?void 0:T.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(()=>Ih({h:h.value.h,s:100,v:100})),m=a.computed(()=>Ih({h:h.value.h,s:h.value.s,v:h.value.v})),g=a.computed(()=>t.withOpacity?Oh(h.value):m.value),y=a.computed(()=>`linear-gradient(to top, transparent 0%, ${m.value} 100%)`);function k(T){if(T){const E=Bh(T);l.value={x:E.s,y:100-E.v},c.value=E.h/360*100,d.value=100-E.a/255*100}}function b(T){k(T),o("update:modelValue",t.withOpacity?Oh(Bh(T)):T)}k(t.modelValue),a.watch(()=>t.modelValue,T=>{f.value||k(T)}),a.watch([l,c,d],()=>{f.value&&o("update:modelValue",g.value)});function S(T){u.value=!0,x(T),window.addEventListener("pointermove",x),window.addEventListener("pointerup",C)}function x(T){if(!i.value)return;const E=i.value.getBoundingClientRect(),M=Math.max(0,Math.min(100,(T.clientX-E.left)/E.width*100)),v=Math.max(0,Math.min(100,(T.clientY-E.top)/E.height*100));l.value={x:M,y:v}}function C(){u.value=!1,window.removeEventListener("pointermove",x),window.removeEventListener("pointerup",C)}return(T,E)=>(a.openBlock(),a.createElementBlock("div",Lx,[a.createVNode(Dx,{modelValue:g.value,"onUpdate:modelValue":b},null,8,["modelValue"]),a.createElementVNode("div",Vx,[a.createElementVNode("div",{ref_key:"selectorRef",ref:i,class:"wov-color-picker-selector",style:a.normalizeStyle({backgroundColor:p.value}),onPointerdown:a.withModifiers(S,["prevent"])},[a.createElementVNode("div",$x,[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(cp,{ref_key:"hueSliderRef",ref:r,modelValue:c.value,"onUpdate:modelValue":E[0]||(E[0]=M=>c.value=M),thumbColor:p.value,background:zx},null,8,["modelValue","thumbColor"]),n.withOpacity?(a.openBlock(),a.createBlock(cp,{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)])]))}}),Fx={class:"wov-color-bubbles-container"},Hx={key:1,class:"wov-color-bubbles"},jx=["onClick"],Ks=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 b=k.replace(/^#/,"").toLowerCase();return b.length===6?b+"ff":b};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=Ql(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=Ql(m);g&&o("change",g)}return(m,g)=>(a.openBlock(),a.createElementBlock("div",Fx,[i.value?(a.openBlock(),a.createBlock(dp,{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",Hx,[(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,jx))),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)]))]))}}),Ux={class:"wov-color-button"},up=a.defineComponent({__name:"ColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=de(),o=_t(()=>e.entityIds,w.Color),r=a.computed(()=>{const d=new Set;for(const u of o.value.values())if(u){const f=tr(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=tr(d);t(f=>{for(const h of e.entityIds)w.Color.fromHex(f,h,u)})}return(d,u)=>(a.openBlock(),a.createBlock(qe,{title:"Color"},{button:a.withCtx(()=>[a.createElementVNode("div",Ux,[a.createElementVNode("div",{class:"wov-color-swatch",style:a.normalizeStyle(l.value)},null,4),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createVNode(Ks,{currentColor:i.value??void 0,hideHighlight:s.value,withPicker:!0,onChange:c},null,8,["currentColor","hideHighlight"])]),_:1}))}}),Rn=a.defineComponent({__name:"MenuButton",props:{title:{}},emits:["click"],setup(n,{emit:e}){const t=n,o=e,r=a.ref(null),{show:s,hide:i}=Pt();function l(u){o("click",u)}function c(){t.title&&r.value&&s(t.title,r.value)}function d(){i()}return(u,f)=>(a.openBlock(),a.createElementBlock("button",{ref_key:"buttonRef",ref:r,class:"wov-menu-button",onClick:l,onMouseenter:c,onMouseleave:d},[a.renderSlot(u.$slots,"default")],544))}}),ha=a.defineComponent({__name:"MenuTooltip",setup(n){const{activeTooltip:e,isVisible:t}=Pt(),o=a.inject("containerRef"),r=a.ref(null),s=a.computed(()=>{var c;return((c=e.value)==null?void 0:c.anchor)??null}),{floatingStyles:i}=uo(s,r,{placement:"top",middleware:[lo(8),co({fallbackPlacements:["bottom"]}),ao({padding:8})]}),l=a.computed(()=>{var c;return t.value&&((c=e.value)==null?void 0:c.text)});return(c,d)=>a.unref(o)?(a.openBlock(),a.createBlock(a.Teleport,{key:0,to:a.unref(o)},[a.createVNode(a.Transition,{name:"wov-tooltip-fade"},{default:a.withCtx(()=>{var u;return[l.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"tooltipRef",ref:r,class:"wov-menu-tooltip",style:a.normalizeStyle(a.unref(i))},a.toDisplayString((u=a.unref(e))==null?void 0:u.text),5)):a.createCommentVNode("",!0)]}),_:1})],8,["to"])):a.createCommentVNode("",!0)}}),Wx={class:"wov-menu-button"},Kx=["onClick"],fp=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}=de(),r=_t(()=>t.entityIds,fr.PenStroke),s=a.computed(()=>{let l=null;for(const c of r.value.values())if(c){if(l===null)l=c.thickness;else if(c.thickness!==l)return null}return l});function i(l){o(c=>{for(const d of t.entityIds){const u=fr.PenStroke.write(c,d);u.thickness=l}})}return(l,c)=>(a.openBlock(),a.createBlock(qe,{title:"Thickness"},{button:a.withCtx(()=>[a.createElementVNode("div",Wx,[c[0]||(c[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,d=>a.createElementVNode("button",{key:d.value,class:a.normalizeClass(["wov-menu-option wov-pen-thickness-option",{"is-active":s.value===d.value}]),onClick:u=>i(d.value)},a.toDisplayString(d.label),11,Kx)),64))]),_:1}))}}),qx={class:"wov-fill-color-button"},Gx={class:"wov-fill-dropdown"},Jx={key:0,class:"wov-fill-mode-section"},Yx=["title","onClick"],Xx={viewBox:"0 0 24 24",fill:"none"},Qx=["fill","fill-opacity","stroke","stroke-width","stroke-dasharray"],hp=a.defineComponent({__name:"ShapeFillColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=de(),o=_t(()=>e.entityIds,w.Shape),r=[{mode:"solid",label:"Solid",alpha:255},{mode:"faded",label:"Faded",alpha:128},{mode:"none",label:"None",alpha:0}],s=a.computed(()=>{const p=o.value.values().next().value,m=(p==null?void 0:p.fillAlpha)??255;return m===0?"none":m<200?"faded":"solid"}),i=a.computed(()=>{const p=new Set;for(const m of o.value.values())if(m){const g=m.fillAlpha??255;g===0?p.add("none"):g<200?p.add("faded"):p.add("solid")}return p.size>1});function l(p){t(m=>{for(const g of e.entityIds){const y=w.Shape.write(m,g);y.fillAlpha=p}})}const c=a.computed(()=>{const p=new Set;for(const m of o.value.values())if(m){const g=tr({red:m.fillRed,green:m.fillGreen,blue:m.fillBlue,alpha:m.fillAlpha??255});p.add(g)}return Array.from(p)}),d=a.computed(()=>c.value.length>1),u=a.computed(()=>c.value[0]??"#4a90d9");function f(p){t(m=>{for(const g of e.entityIds){const y=w.Shape.write(m,g);y.fillRed=p.red,y.fillGreen=p.green,y.fillBlue=p.blue,y.fillAlpha=p.alpha}})}const h=a.ref(!1);return(p,m)=>(a.openBlock(),a.createBlock(qe,{title:"Fill Color"},{button:a.withCtx(()=>[a.createElementVNode("div",qx,[m[1]||(m[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",Gx,[h.value?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",Jx,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(r,g=>a.createElementVNode("button",{key:g.mode,class:a.normalizeClass(["wov-fill-mode-option",{"is-active":!i.value&&g.mode===s.value}]),title:g.label,onClick:y=>l(g.alpha)},[(a.openBlock(),a.createElementBlock("svg",Xx,[a.createElementVNode("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2",fill:g.mode==="none"?"none":"currentColor","fill-opacity":g.mode==="faded"?.4:1,stroke:g.mode==="none"?"currentColor":"none","stroke-width":g.mode==="none"?1.5:0,"stroke-dasharray":g.mode==="none"?"3 3":""},null,8,Qx)])),a.createElementVNode("span",null,a.toDisplayString(g.label),1)],10,Yx)),64))])),a.createVNode(Ks,{currentColor:u.value,hideHighlight:d.value,withPicker:!0,withOpacity:!0,onChange:f,onPickerOpen:m[0]||(m[0]=g=>h.value=g)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),Zx={class:"wov-shape-kind-button"},e2={class:"wov-shape-kind-dropdown"},t2=["onClick"],n2={viewBox:"0 0 20 20",class:"wov-shape-option-icon",fill:"none",stroke:"currentColor","stroke-width":"4"},o2=["d"],pp=a.defineComponent({__name:"ShapeKindButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=de(),o=_t(()=>e.entityIds,w.Shape),r=a.computed(()=>{const c=o.value.values().next().value;return(c==null?void 0:c.kind)??"rectangle"}),s=a.computed(()=>{const c=new Set;for(const d of o.value.values())d&&c.add(d.kind);return c.size>1}),i=a.computed(()=>Object.keys(bo).map(c=>({kind:c,label:c.charAt(0).toUpperCase()+c.slice(1)})));function l(c){t(d=>{for(const u of e.entityIds){const f=w.Shape.write(d,u);f.kind=c}})}return(c,d)=>(a.openBlock(),a.createBlock(qe,{title:"Shape Type"},{button:a.withCtx(()=>[a.createElementVNode("div",Zx,[d[0]||(d[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",e2,[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(i.value,u=>(a.openBlock(),a.createElementBlock("button",{key:u.kind,class:a.normalizeClass(["wov-shape-kind-option",{"is-selected":!s.value&&u.kind===r.value}]),onClick:f=>l(u.kind)},[(a.openBlock(),a.createElementBlock("svg",n2,[a.createElementVNode("path",{d:a.unref(bo)[u.kind],transform:"translate(2, 2) scale(0.16)"},null,8,o2)])),a.createElementVNode("span",null,a.toDisplayString(u.label),1)],10,t2))),128))])]),_:1}))}}),r2={class:"wov-stroke-style-section"},s2=["title","onClick"],i2={viewBox:"0 0 24 8",fill:"none",stroke:"currentColor","stroke-width":"2"},l2=["stroke-dasharray","stroke-opacity"],a2=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"";case w.StrokeKind.Solid:default:return""}}function s(i){t("change",i)}return(i,l)=>(a.openBlock(),a.createElementBlock("div",r2,[(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",i2,[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,l2)])),a.createElementVNode("span",null,a.toDisplayString(c.label),1)],10,s2)),64))]))}}),c2={class:"wov-stroke-color-button"},d2={class:"wov-stroke-dropdown"},u2={key:1,class:"wov-stroke-divider"},mp=a.defineComponent({__name:"ShapeStrokeColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=de(),o=_t(()=>e.entityIds,w.Shape),r=a.ref(!1),s=a.computed(()=>{const h=new Set;for(const p of o.value.values())if(p){const m=tr({red:p.strokeRed,green:p.strokeGreen,blue:p.strokeBlue,alpha:255});h.add(m)}return Array.from(h)}),i=a.computed(()=>s.value.length>1),l=a.computed(()=>s.value[0]??"#000000"),c=a.computed(()=>{const h=o.value.values().next().value;return(h==null?void 0:h.strokeKind)??w.StrokeKind.Solid}),d=a.computed(()=>{const h=new Set;for(const p of o.value.values())p&&h.add(p.strokeKind);return h.size>1});function u(h){t(p=>{for(const m of e.entityIds){const g=w.Shape.write(p,m);g.strokeRed=h.red,g.strokeGreen=h.green,g.strokeBlue=h.blue}})}function f(h){t(p=>{for(const m of e.entityIds){const g=w.Shape.write(p,m);g.strokeKind=h}})}return(h,p)=>(a.openBlock(),a.createBlock(qe,{title:"Stroke Color"},{button:a.withCtx(()=>[a.createElementVNode("div",c2,[p[1]||(p[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",d2,[r.value?a.createCommentVNode("",!0):(a.openBlock(),a.createBlock(a2,{key:0,currentStyle:c.value,hasMultipleStyles:d.value,onChange:f},null,8,["currentStyle","hasMultipleStyles"])),r.value?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",u2)),a.createVNode(Ks,{currentColor:l.value,hideHighlight:i.value,withPicker:!0,onChange:u,onPickerOpen:p[0]||(p[0]=m=>r.value=m)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),f2={class:"wov-tape-image-button"},h2={class:"wov-tape-image-bubbles"},p2=["onClick"],gp=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}=de(),r=_t(()=>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(qe,{title:"Tape Style"},{button:a.withCtx(()=>[a.createElementVNode("div",f2,[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",h2,[(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,p2)),64))])]),_:1}))}}),m2={key:0,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},g2={key:1,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},y2={key:2,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},k2={key:3,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},pa=a.defineComponent({__name:"TextAlignmentButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=rt(()=>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(Rn,{key:0,title:"Text Align",onClick:s},{default:a.withCtx(()=>[a.unref(t).alignment===a.unref(w.TextAlignment).Left?(a.openBlock(),a.createElementBlock("svg",m2,[...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",g2,[...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",y2,[...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",k2,[...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)}}),ma=a.defineComponent({__name:"TextBoldButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=rt(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Rn,{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 w2(n,e){return a.getCurrentScope()?(a.onScopeDispose(n,e),!0):!1}const b2=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const S2=Object.prototype.toString,x2=n=>S2.call(n)==="[object Object]",qs=()=>{};function Gs(n){return Array.isArray(n)?n:[n]}function C2(n){return a.getCurrentInstance()}function E2(n,e=!0,t){C2()?a.onMounted(n,t):e?n():a.nextTick(n)}function v2(n,e,t){return a.watch(n,e,{...t,immediate:!0})}const Js=b2?window:void 0;function lt(n){var e;const t=a.toValue(n);return(e=t==null?void 0:t.$el)!==null&&e!==void 0?e:t}function ga(...n){const e=(o,r,s,i)=>(o.addEventListener(r,s,i),()=>o.removeEventListener(r,s,i)),t=a.computed(()=>{const o=Gs(a.toValue(n[0])).filter(r=>r!=null);return o.every(r=>typeof r!="string")?o:void 0});return v2(()=>{var o,r;return[(o=(r=t.value)===null||r===void 0?void 0:r.map(s=>lt(s)))!==null&&o!==void 0?o:[Js].filter(s=>s!=null),Gs(a.toValue(t.value?n[1]:n[0])),Gs(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=x2(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 T2(n,e,t={}){const{window:o=Js,ignore:r=[],capture:s=!0,detectIframe:i=!1,controls:l=!1}=t;if(!o)return l?{stop:qs,cancel:qs,trigger:qs}:qs;let c=!0;const d=y=>a.toValue(r).some(k=>{if(typeof k=="string")return Array.from(o.document.querySelectorAll(k)).some(b=>b===y.target||y.composedPath().includes(b));{const b=lt(k);return b&&(y.target===b||y.composedPath().includes(b))}});function u(y){const k=a.toValue(y);return k&&k.$.subTree.shapeFlag===16}function f(y,k){const b=a.toValue(y),S=b.$.subTree&&b.$.subTree.children;return S==null||!Array.isArray(S)?!1:S.some(x=>x.el===k.target||k.composedPath().includes(x.el))}const h=y=>{const k=lt(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=[ga(o,"click",y=>{p||(p=!0,setTimeout(()=>{p=!1},0),h(y))},{passive:!0,capture:s}),ga(o,"pointerdown",y=>{const k=lt(n);c=!d(y)&&!!(k&&!y.composedPath().includes(k))},{passive:!0}),i&&ga(o,"blur",y=>{setTimeout(()=>{var k;const b=lt(n);((k=o.document.activeElement)===null||k===void 0?void 0:k.tagName)==="IFRAME"&&!(b!=null&&b.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 M2(){const n=a.shallowRef(!1),e=a.getCurrentInstance();return e&&a.onMounted(()=>{n.value=!0},e),n}function A2(n){const e=M2();return a.computed(()=>(e.value,!!n()))}function N2(n,e,t={}){const{window:o=Js,...r}=t;let s;const i=A2(()=>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=>lt(f)):[lt(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 w2(d),{isSupported:i,stop:d}}function yp(n,e={width:0,height:0},t={}){const{window:o=Js,box:r="content-box"}=t,s=a.computed(()=>{var f;return(f=lt(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}=N2(n,([f])=>{const h=r==="border-box"?f.borderBoxSize:r==="content-box"?f.contentBoxSize:f.devicePixelContentBoxSize;if(o&&s.value){const p=lt(n);if(p){const m=p.getBoundingClientRect();i.value=m.width,l.value=m.height}}else if(h){const p=Gs(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);E2(()=>{const f=lt(n);f&&(i.value="offsetWidth"in f?f.offsetWidth:e.width,l.value="offsetHeight"in f?f.offsetHeight:e.height)});const d=a.watch(()=>lt(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 kp(){const n=a.inject(je);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 B2={class:"wov-font-family-button"},I2={class:"wov-font-family-label"},O2={class:"wov-font-list"},_2=["onClick"],R2=["src","alt"],ya=a.defineComponent({__name:"TextFontFamilyButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=rt(()=>e.entityIds),r=kp(),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(qe,{key:0,title:"Font Family"},{button:a.withCtx(()=>[a.createElementVNode("div",B2,[a.createElementVNode("span",I2,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",O2,[(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},null,8,R2)):(a.openBlock(),a.createElementBlock("span",{key:1,class:"wov-font-name",style:a.normalizeStyle({fontFamily:h.name})},a.toDisplayString(h.displayName),5))],10,_2))),128))])],32)]),_:1})):a.createCommentVNode("",!0)}}),P2={class:"wov-font-size-button"},D2={class:"wov-font-size-label"},L2=["onClick"],V2={key:0,class:"wov-check-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},$2={class:"wov-input-container"},z2=["value"],ka=a.defineComponent({__name:"TextFontSizeButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=rt(()=>e.entityIds),r=[{label:"Small",value:16,displayValue:10},{label:"Medium",value:24,displayValue:12},{label:"Large",value:40,displayValue:16},{label:"Huge",value:96,displayValue:20}],s=a.computed(()=>t.fontSize),i=a.computed(()=>{const h=s.value;if(h===null)return"Mixed";const p=r.find(m=>m.value===h);return p?p.label:`${+h.toFixed(1)} px`}),l=a.computed(()=>{const h=s.value;return h===null?"":String(+h.toFixed(1))});function c(h){o.setFontSize(h)}function d(h){const p=h.target,m=Number.parseFloat(p.value);!Number.isNaN(m)&&m>0&&c(m)}function u(h){h.key==="Enter"&&h.target.blur()}function f(h){h.stopPropagation()}return(h,p)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(qe,{key:0,title:"Font Size"},{button:a.withCtx(()=>[a.createElementVNode("div",P2,[a.createElementVNode("span",D2,a.toDisplayString(i.value),1),a.createVNode(Ge,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",{class:"wov-font-size-menu",onWheel:f,onClick:p[0]||(p[0]=a.withModifiers(()=>{},["stop"]))},[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(r,m=>a.createElementVNode("div",{key:m.value,class:a.normalizeClass(["wov-font-size-option",{active:s.value===m.value}]),onClick:g=>c(m.value)},[s.value===m.value?(a.openBlock(),a.createElementBlock("svg",V2,[...p[1]||(p[1]=[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:`${m.displayValue}px`})},a.toDisplayString(m.label),5)],10,L2)),64)),p[3]||(p[3]=a.createElementVNode("div",{class:"wov-separator"},null,-1)),a.createElementVNode("div",$2,[a.createElementVNode("input",{class:"wov-custom-input",value:l.value,onInput:d,onKeydown:u,placeholder:"Custom size"},null,40,z2),p[2]||(p[2]=a.createElementVNode("span",{class:"wov-px-suffix"},"px",-1))])],32)]),_:1})):a.createCommentVNode("",!0)}}),wa=a.defineComponent({__name:"TextItalicButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=rt(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Rn,{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)}}),ba=a.defineComponent({__name:"TextUnderlineButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=rt(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Rn,{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)}}),F2={class:"wov-link-input-container"},H2=["onKeydown"],Sa=a.defineComponent({__name:"TextLinkButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=rt(()=>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}=uo(l,c,{placement:"top",middleware:[lo(8),co(),ao({padding:8})],whileElementsMounted:Ws});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,b;const y=g.target;!((k=l.value)!=null&&k.contains(y))&&!((b=c.value)!=null&&b.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(Rn,{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",F2,[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,H2),[[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))}}),j2={class:"wov-text-color-button"},U2={class:"wov-text-icon-container"},xa=a.defineComponent({__name:"TextColorButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=rt(()=>e.entityIds),r=a.computed(()=>t.color??"#000000"),s=a.computed(()=>({backgroundColor:r.value}));function i(l){o.setColor(tr(l))}return(l,c)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(qe,{key:0,title:"Text Color"},{button:a.withCtx(()=>[a.createElementVNode("div",j2,[a.createElementVNode("div",U2,[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(Ks,{currentColor:r.value,withPicker:!0,onChange:i},null,8,["currentColor"])]),_:1})):a.createCommentVNode("",!0)}}),W2={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"},K2={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"},q2={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"},wp=a.defineComponent({__name:"VerticalAlignButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=de(),{state:o}=rt(()=>e.entityIds),r=[w.VerticalAlignment.Top,w.VerticalAlignment.Center,w.VerticalAlignment.Bottom],s=_t(()=>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(Rn,{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",W2,[...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",K2,[...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",q2,[...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)}}),G2={class:"wov-text-group-button"},J2={class:"wov-text-group-dropdown"},Y2={class:"wov-text-group-row wov-text-group-row-full"},X2={class:"wov-text-group-row"},Q2=a.defineComponent({__name:"TextButtonGroup",props:{entityIds:{},showVerticalAlign:{type:Boolean}},setup(n){const e=n,{state:t}=rt(()=>e.entityIds),o=a.inject("containerRef"),{width:r}=yp(o),s=a.computed(()=>r.value>0&&r.value<600),i=a.ref(new Map);return a.provide(oc,i),(l,c)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createElementBlock(a.Fragment,{key:0},[s.value?(a.openBlock(),a.createBlock(qe,{key:0,title:"Text Formatting",placement:"top"},{button:a.withCtx(()=>[a.createElementVNode("div",G2,[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",J2,[a.createElementVNode("div",Y2,[a.createVNode(ya,{entityIds:n.entityIds},null,8,["entityIds"]),c[1]||(c[1]=a.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),a.createVNode(ka,{entityIds:n.entityIds},null,8,["entityIds"])]),a.createElementVNode("div",X2,[a.createVNode(ma,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(wa,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(ba,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Sa,{entityIds:n.entityIds},null,8,["entityIds"]),c[2]||(c[2]=a.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),a.createVNode(xa,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(pa,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(a.openBlock(),a.createBlock(wp,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):a.createCommentVNode("",!0)])])]),_:1})):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[a.createVNode(ya,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(ka,{entityIds:n.entityIds},null,8,["entityIds"]),c[3]||(c[3]=a.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),a.createVNode(ma,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(wa,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(ba,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Sa,{entityIds:n.entityIds},null,8,["entityIds"]),c[4]||(c[4]=a.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),a.createVNode(xa,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(pa,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(a.openBlock(),a.createBlock(wp,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):a.createCommentVNode("",!0)],64))],64)):a.createCommentVNode("",!0)}}),bp=a.defineComponent({__name:"CanvasBackground",props:{background:{}},setup(n){const e=n,t=Me(w.Camera),o=Me(w.Grid),r=a.inject("containerRef"),s=a.ref({width:0,height:0});let i=null;const l=a.ref(null);let c=null;typeof document<"u"&&(c=document.createElement("canvas"));function d(y,k,b,S){const x=S/2;y.beginPath(),y.arc(k,b,x,0,Math.PI*2),y.fill()}function u(y,k,b){if(!c)return null;const S=b.dotSize??2,x=y*b.subdivisionStep,C=k*b.subdivisionStep;if(x<=0||C<=0)return null;c.width=x,c.height=C;const T=c.getContext("2d");if(!T)return null;if(T.clearRect(0,0,x,C),T.fillStyle=b.strokeColor,b.subdivisionStep===1)d(T,x/2,C/2,S);else for(let E=0;E<b.subdivisionStep;E++)for(let M=0;M<b.subdivisionStep;M++){const v=(E+.5)*(x/b.subdivisionStep),B=(M+.5)*(C/b.subdivisionStep),P=E===0&&M===0?2*S:S;d(T,v,B,P)}return T.createPattern(c,"repeat")}function f(y,k,b,S,x,C){y.lineWidth=C,y.beginPath(),y.moveTo(k,b),y.lineTo(S,x),y.stroke()}function h(y,k,b){if(!c)return null;const S=b.gridSize??1,x=y*b.subdivisionStep,C=k*b.subdivisionStep;if(x<=0||C<=0)return null;c.width=x,c.height=C;const T=c.getContext("2d");if(!T)return null;if(T.clearRect(0,0,x,C),T.strokeStyle=b.strokeColor,b.subdivisionStep===1)f(T,0,0,x,0,S),f(T,0,0,0,C,S);else{const E=x/b.subdivisionStep,M=C/b.subdivisionStep;for(let v=0;v<=b.subdivisionStep;v++){const B=v*E,I=v%b.subdivisionStep===0;f(T,B,0,B,C,I?3*S:S)}for(let v=0;v<=b.subdivisionStep;v++){const B=v*M,I=v%b.subdivisionStep===0;f(T,0,B,x,B,I?3*S:S)}}return T.createPattern(c,"repeat")}function p(y){let k=o.value.colWidth,b=o.value.rowHeight;const S=e.background.subdivisionStep,x=s.value.width,C=s.value.height,T=t.value.left,E=t.value.top,M=T+x/t.value.zoom,v=E+C/t.value.zoom;let B=k*S,I=b*S,P=0,V=0,z=Number.POSITIVE_INFINITY,W=Number.POSITIVE_INFINITY;for(;;){B=S*k,I=S*b,P=Math.floor(T/B)*B,V=Math.floor(E/I)*I;const Be=Math.ceil(M/B)*B,ce=Math.ceil(v/I)*I;if(W=Math.round((Be-P)/k),z=Math.round((ce-V)/b),Math.max(W,z)>200)k*=2,b*=2;else break}const G=k*t.value.zoom,K=b*t.value.zoom,j=Math.round(G),F=Math.round(K),X=u(j,F,e.background);if(!X)return;X.setTransform(new DOMMatrix().scale(G/j,K/F));const re=(P-T-k/2)*t.value.zoom,le=(V-E-b/2)*t.value.zoom;y.save(),y.translate(re,le),y.fillStyle=X,y.fillRect(0,0,x+B*t.value.zoom,C+I*t.value.zoom),y.restore()}function m(y){let k=o.value.colWidth,b=o.value.rowHeight;const S=e.background.subdivisionStep,x=s.value.width,C=s.value.height,T=t.value.left,E=t.value.top,M=T+x/t.value.zoom,v=E+C/t.value.zoom;let B=k*S,I=b*S,P=0,V=0,z=Number.POSITIVE_INFINITY,W=Number.POSITIVE_INFINITY;for(;;){B=S*k,I=S*b,P=Math.floor(T/B)*B,V=Math.floor(E/I)*I;const Be=Math.ceil(M/B)*B,ce=Math.ceil(v/I)*I;if(W=Math.round((Be-P)/k),z=Math.round((ce-V)/b),Math.max(W,z)>200)k*=2,b*=2;else break}const G=k*t.value.zoom,K=b*t.value.zoom,j=Math.round(G),F=Math.round(K),X=h(j,F,e.background);if(!X)return;X.setTransform(new DOMMatrix().scale(G/j,K/F));const re=(P-T)*t.value.zoom,le=(V-E)*t.value.zoom;y.save(),y.translate(re,le),y.fillStyle=X,y.fillRect(0,0,x+B*t.value.zoom,C+I*t.value.zoom),y.restore()}function g(){const y=l.value;if(!y)return;const k=y.getContext("2d");if(!k)return;const{width:b,height:S}=s.value;b===0||S===0||(y.width=b,y.height=S,k.clearRect(0,0,b,S),k.fillStyle=e.background.color,k.fillRect(0,0,b,S),e.background.kind==="dots"?p(k):e.background.kind==="grid"&&m(k))}return a.watch(()=>[e.background,t.value,o.value,s.value],()=>{g()},{deep:!0}),a.onMounted(()=>{const y=r==null?void 0:r.value;if(y){const k=()=>{s.value={width:y.clientWidth,height:y.clientHeight}};k(),i=new ResizeObserver(k),i.observe(y)}g()}),a.onUnmounted(()=>{i==null||i.disconnect()}),(y,k)=>(a.openBlock(),a.createElementBlock("canvas",{ref_key:"canvasRef",ref:l,style:{position:"absolute",top:0,left:0,width:"100%",height:"100%",pointerEvents:"none"}},null,512))}});function Sp(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}const xp=a.defineComponent({__name:"FloatingMenuBar",setup(n){const e=a.useSlots(),{reset:t}=Pt(),o=a.inject(sc),{selectedIds:r,commonComponents:s}=o,i=new Set(["color","text","verticalAlign","penStroke","elbowArrow","arcArrow","shape","tape"]),l=a.computed(()=>{const d=[];for(const u of s.value){const f=`button:${u}`;!i.has(u)&&e[f]&&d.push(u)}return d});function c(){t()}return a.onUnmounted(()=>{t()}),(d,u)=>(a.openBlock(),a.createElementBlock("div",{class:"wov-floating-menu-bar",onMouseleave:c},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(l.value,f=>a.renderSlot(d.$slots,`button:${f}`,{key:f,entityIds:a.unref(r)})),128)),a.unref(s).has("color")?a.renderSlot(d.$slots,"button:color",{key:0,entityIds:a.unref(r)},()=>[a.createVNode(up,{entityIds:a.unref(r)},null,8,["entityIds"])]):a.createCommentVNode("",!0),a.unref(s).has("shape")?a.renderSlot(d.$slots,"button:shape",{key:1,entityIds:a.unref(r)},()=>[a.createVNode(pp,{entityIds:a.unref(r)},null,8,["entityIds"]),a.createVNode(hp,{entityIds:a.unref(r)},null,8,["entityIds"]),a.createVNode(mp,{entityIds:a.unref(r)},null,8,["entityIds"])]):a.createCommentVNode("",!0),a.unref(s).has("penStroke")?a.renderSlot(d.$slots,"button:penStroke",{key:2,entityIds:a.unref(r)},()=>[a.createVNode(fp,{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(d.$slots,"button:arrowThickness",{entityIds:a.unref(r)},()=>[a.createVNode(ap,{entityIds:a.unref(r)},null,8,["entityIds"])]),a.renderSlot(d.$slots,"button:arrowHeadStart",{entityIds:a.unref(r)},()=>[a.createVNode(fa,{entityIds:a.unref(r),side:"start"},null,8,["entityIds"])]),a.renderSlot(d.$slots,"button:arrowHeadEnd",{entityIds:a.unref(r)},()=>[a.createVNode(fa,{entityIds:a.unref(r),side:"end"},null,8,["entityIds"])])],64)):a.createCommentVNode("",!0),a.unref(s).has("tape")?a.renderSlot(d.$slots,"button:tape",{key:4,entityIds:a.unref(r)},()=>[a.createVNode(gp,{entityIds:a.unref(r)},null,8,["entityIds"])]):a.createCommentVNode("",!0),a.unref(s).has("text")?a.renderSlot(d.$slots,"button:text",{key:5,entityIds:a.unref(r)},()=>[a.createVNode(Q2,{entityIds:a.unref(r),showVerticalAlign:a.unref(s).has("verticalAlign")},null,8,["entityIds","showVerticalAlign"])]):a.createCommentVNode("",!0),a.createVNode(ha)],32))}}),Z2={class:"wov-floating-menu-inner"},Cp=a.defineComponent({__name:"FloatingMenu",setup(n){const e=a.inject(je),t=Ah([w.Block,ne.Selected]),o=Me(w.Camera),r=Me(w.Screen),s=Me(ne.SelectionStateSingleton),i=nr(),l=a.computed(()=>t.value.map(x=>x.entityId)),c=a.computed(()=>{const x=e==null?void 0:e.getEditor();if(!x||t.value.length===0)return new Set;const C=t.value.map(T=>({tag:T.block.value.tag}));return Sp(x,C)});a.provide(sc,{selectedIds:l,commonComponents:c});const d=[0,0,0,0];function u(...x){let C=1/0,T=1/0,E=-1/0,M=-1/0,v=!1;for(const B of x){if(!B)continue;const I=B.getBoundingClientRect();I.width<=0||(v=!0,C=Math.min(C,I.left),T=Math.min(T,I.top),E=Math.max(E,I.right),M=Math.max(M,I.bottom))}return v?{x:C,y:T,left:C,top:T,right:E,bottom:M,width:E-C,height:M-T,toJSON:()=>({})}:null}const f=a.computed(()=>{if(t.value.length===0)return null;const x=o.value;if(!x)return null;let C=null;for(const T of t.value){const E=T.block.value;Ie.Rect.getAabb(E.position,E.size,E.rotateZ,d),Ie.Aabb.translate(d,[-x.left,-x.top]),Ie.Aabb.scale(d,x.zoom),C===null?C=Ie.Aabb.clone(d):Ie.Aabb.union(C,d)}return C}),h=a.inject("containerRef"),p=a.computed(()=>{const x=h==null?void 0:h.value;if(!x)return null;o.value,i.updateCounter.value;const C=i.blockElement.value,T=i.textElement.value,E=u(C,T);if(E)return{getBoundingClientRect:()=>E};const M=f.value;if(!M)return null;const v=x.getBoundingClientRect();return{getBoundingClientRect(){return{x:v.left+M[0],y:v.top+M[1],width:M[2]-M[0],height:M[3]-M[1],top:v.top+M[1],left:v.left+M[0],right:v.left+M[2],bottom:v.top+M[3]}}}}),m=a.ref(null),g={name:"clampToViewport",fn({y:x,rects:C}){const M=window.innerHeight-C.floating.height-8;return{y:Math.max(8,Math.min(x,M))}}},{floatingStyles:y}=uo(p,m,{placement:"top",middleware:[lo(12),co({fallbackPlacements:["bottom"]}),ao({padding:8}),g]}),k=a.computed(()=>{const x=f.value,C=r.value;return!x||!C?!0:x[2]<0||x[0]>C.width||x[3]<0||x[1]>C.height}),b=[ne.SelectionState.Dragging,ne.SelectionState.SelectionBoxDragging],S=a.computed(()=>t.value.length>0&&!k.value&&!b.includes(s.value.state));return(x,C)=>(a.openBlock(),a.createBlock(a.Transition,{name:"wov-fade"},{default:a.withCtx(()=>[S.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"floatingRef",ref:m,class:"wov-floating-menu",style:a.normalizeStyle(a.unref(y))},[a.createElementVNode("div",Z2,[a.renderSlot(x.$slots,"default",{},()=>[a.createVNode(xp)])])],4)):a.createCommentVNode("",!0)]),_:3}))}}),eC={key:0,class:"wov-loading-overlay"},tC={class:"wov-loading-spinner"},Ep=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",eC,[a.createElementVNode("div",tC,a.toDisplayString(e.value),1)])):a.createCommentVNode("",!0)]),_:1}))}}),fo="editing",nC={class:"wov-action-bar"},oC=a.defineComponent({__name:"ActionBar",setup(n){const{getEditor:e}=de(),t=a.inject(je),o=a.ref(!1),r=a.ref(!1);if(t){const c=t.registerTickCallback(d=>{const{store:u}=w.getPluginResources(d,fo);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(ne.RemoveSelected)}return(c,d)=>(a.openBlock(),a.createElementBlock("div",nC,[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)])])]))}}),at=a.defineComponent({__name:"ToolbarButton",props:{name:{},tooltip:{},dragOutSnapshot:{},placementSnapshot:{},cursor:{default:"crosshair"}},setup(n){const e=n,t=a.inject(di);if(!t)throw new Error("ToolbarButton must be used within a Toolbar component");const o=t,r=a.ref(null),{show:s,hide:i}=Pt(),l=a.computed(()=>o.activeTool.value===e.name);function c(){o.setTool(e.name,e.placementSnapshot,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))}}),rC='<?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>',sC='<?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>',iC='<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>',sn={Select:"select",Hand:"hand",Crosshair:"crosshair"},vp={[sn.Select]:{makeSvg:()=>rC,hotspot:[1,0],rotationOffset:0},[sn.Hand]:{makeSvg:()=>sC,hotspot:[12,12],rotationOffset:0},[sn.Crosshair]:{makeSvg:()=>iC,hotspot:[12,12],rotationOffset:0}},lC={viewBox:"0 0 20 20",style:{"fill-rule":"evenodd","clip-rule":"evenodd","stroke-miterlimit":"10"}},Tp=a.defineComponent({__name:"SelectTool",setup(n){const{nextEditorTick:e}=de(),{activeTool:t}=Os();return a.watch(t,(o,r)=>{r==="select"&&e(s=>{ne.DeselectAll.spawn(s)})}),(o,r)=>(a.openBlock(),a.createBlock(at,{name:"select",tooltip:"Select",cursor:a.unref(sn).Select},{default:a.withCtx(()=>[(a.openBlock(),a.createElementBlock("svg",lC,[...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"]))}}),Mp=a.defineComponent({__name:"HandTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(at,{name:"hand",tooltip:"Hand",cursor:a.unref(sn).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"]))}}),Ap=a.defineComponent({__name:"StickyNoteTool",setup(n){const e=JSON.stringify({block:{tag:"sticky-note",size:[200,200]},color:{red:255,green:242,blue:117},text:{defaultAlignment:w.TextAlignment.Center},verticalAlign:{value:w.VerticalAlignment.Center}});return(t,o)=>(a.openBlock(),a.createBlock(at,{name:"sticky-note",tooltip:"Sticky Note","drag-out-snapshot":a.unref(e),"placement-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("path",{d:"M4 4h12v12H4z"}),a.createElementVNode("path",{d:"M7 8h6M7 11h4"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),Np=a.defineComponent({__name:"ShapeTool",setup(n){const e=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},verticalAlign:{value:w.VerticalAlignment.Center}});return(t,o)=>(a.openBlock(),a.createBlock(at,{name:"shape",tooltip:"Shape","drag-out-snapshot":a.unref(e),"placement-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:"3",y:"3",width:"14",height:"14",rx:"2"})],-1)])]),_:1},8,["drag-out-snapshot","placement-snapshot"]))}}),Bp=a.defineComponent({__name:"EraserTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(at,{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}))}}),Ip=a.defineComponent({__name:"PenTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(at,{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}))}}),Op=a.defineComponent({__name:"TextTool",setup(n){const e=JSON.stringify({block:{tag:"text",size:[10,29]},text:{constrainWidth:!1,fontSizePx:24}}),t=JSON.stringify({block:{tag:"text",size:[36,29]},text:{content:"text",constrainWidth:!1,fontSizePx:24}});return(o,r)=>(a.openBlock(),a.createBlock(at,{name:"text",tooltip:"Text","drag-out-snapshot":a.unref(t),"placement-snapshot":a.unref(e)},{default:a.withCtx(()=>[...r[0]||(r[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"]))}}),_p=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:ee.ArrowHeadKind.None,endArrowHead:ee.ArrowHeadKind.V},connector:{}});return(t,o)=>(a.openBlock(),a.createBlock(at,{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"]))}}),Rp=a.defineComponent({__name:"ImageTool",setup(n){const{nextEditorTick:e}=de(),{show:t,hide:o}=Pt(),{setTool:r}=Os(),{createImageBlock:s}=Mh(),i=a.ref(null),l=a.ref(null);function c(){var h;(h=l.value)==null||h.click()}async function d(h){var x;const p=h.target,m=(x=p.files)==null?void 0:x[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),b=y.left+k.width/y.zoom/2,S=y.top+k.height/y.zoom/2;await s(m,b,S),r("select",void 0,sn.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))}}),aC={class:"wov-embed-provider-grid"},cC=["onClick"],dC={class:"wov-embed-provider-icon"},uC={key:0,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},fC={key:1,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},hC={key:2,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},pC={key:3,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},mC={key:4,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},gC={key:5,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},yC={key:6,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},kC={key:7,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},wC={class:"wov-embed-provider-label"},bC={class:"wov-embed-panel-header"},SC={class:"wov-embed-url-form"},xC=["placeholder"],CC={key:0,class:"wov-embed-url-error"},Pp=a.defineComponent({__name:"EmbedTool",setup(n){const{nextEditorTick:e}=de(),{show:t,hide:o}=Pt(),{setTool:r}=Os(),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}=uo(s,i,{placement:"top",middleware:[lo(16),co(),ao({padding:8})],whileElementsMounted:Ws}),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 v;(v=l.value)==null||v.focus()})}function b(){d.value=null,u.value="",f.value=""}async function S(){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 v=d.value??w.detectEmbedProvider(M),B=w.validateEmbedUrl(M,v);if(B){f.value=B;return}const I=w.resolveEmbedUrl(M,v);let P=480,V=320;switch(v){case w.EmbedProvider.Youtube:P=560,V=315;break;case w.EmbedProvider.Spotify:P=352,V=152;break;case w.EmbedProvider.GoogleMaps:P=600,V=450;break;case w.EmbedProvider.GoogleCalendar:P=600,V=500;break;case w.EmbedProvider.GoogleSlides:P=640,V=389;break;case w.EmbedProvider.Figma:P=600,V=400;break;case w.EmbedProvider.GithubGist:P=500,V=300;break;case w.EmbedProvider.Tldraw:P=600,V=400;break}const z=await e(),W=w.Camera.read(z),G=w.Screen.read(z),K=W.left+G.width/W.zoom/2,j=W.top+G.height/W.zoom/2,F=w.Grid.read(z);F.enabled&&(P=Math.max(F.colWidth,Math.round(P/F.colWidth)*F.colWidth),V=Math.max(F.rowHeight,Math.round(V/F.rowHeight)*F.rowHeight));const X=w.createEntity(z);w.addComponent(z,X,w.Block);const re=w.Block.write(z,X);re.tag="embed",re.position[0]=K-P/2,re.position[1]=j-V/2,re.size[0]=P,re.size[1]=V,w.Grid.snapPosition(z,re.position),w.addComponent(z,X,w.Embed);const le=w.Embed.write(z,X);le.url=M,le.embedUrl=I,le.provider=v,w.addComponent(z,X,Ve.Synced,{id:crypto.randomUUID()}),c.value=!1,d.value=null,u.value="",r("select",void 0,sn.Select)}function x(M){M.key==="Enter"?(M.preventDefault(),S()):M.key==="Escape"&&(M.preventDefault(),d.value?b():c.value=!1)}function C(M){const v=M.target;s.value&&!s.value.contains(v)&&i.value&&!i.value.contains(v)&&(c.value=!1)}a.watch(c,M=>{M?document.addEventListener("click",C,!0):document.removeEventListener("click",C,!0)});function T(){s.value&&t("Embed",s.value)}function E(){o()}return(M,v)=>{var B;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:T,onMouseleave:E},[...v[1]||(v[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",bC,[a.createElementVNode("button",{class:"wov-embed-back-button",onClick:b},[...v[11]||(v[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((B=m.find(I=>I.value===d.value))==null?void 0:B.label),1)]),a.createElementVNode("div",SC,[a.withDirectives(a.createElementVNode("input",{ref_key:"urlInputRef",ref:l,"onUpdate:modelValue":v[0]||(v[0]=I=>u.value=I),type:"text",placeholder:g.value,class:"wov-embed-url-input",onKeydown:x},null,40,xC),[[a.vModelText,u.value]]),f.value?(a.openBlock(),a.createElementBlock("div",CC,a.toDisplayString(f.value),1)):a.createCommentVNode("",!0),a.createElementVNode("button",{class:"wov-embed-submit-button",onClick:S}," Embed ")])],64)):(a.openBlock(),a.createElementBlock(a.Fragment,{key:0},[v[10]||(v[10]=a.createElementVNode("div",{class:"wov-embed-panel-header"},"Add embed",-1)),a.createElementVNode("div",aC,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(m,I=>a.createElementVNode("button",{key:I.value,class:"wov-embed-provider-button",onClick:P=>k(I.value)},[a.createElementVNode("span",dC,[I.icon==="youtube"?(a.openBlock(),a.createElementBlock("svg",uC,[...v[2]||(v[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)])])):I.icon==="spotify"?(a.openBlock(),a.createElementBlock("svg",fC,[...v[3]||(v[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)])])):I.icon==="map"?(a.openBlock(),a.createElementBlock("svg",hC,[...v[4]||(v[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)])])):I.icon==="calendar"?(a.openBlock(),a.createElementBlock("svg",pC,[...v[5]||(v[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)])])):I.icon==="slides"?(a.openBlock(),a.createElementBlock("svg",mC,[...v[6]||(v[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)])])):I.icon==="figma"?(a.openBlock(),a.createElementBlock("svg",gC,[...v[7]||(v[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)])])):I.icon==="gist"?(a.openBlock(),a.createElementBlock("svg",yC,[...v[8]||(v[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)])])):I.icon==="tldraw"?(a.openBlock(),a.createElementBlock("svg",kC,[...v[9]||(v[9]=[a.createElementVNode("path",{d:"M12 19l7-7 3 3-7 7-3-3z"},null,-1),a.createElementVNode("path",{d:"m18 13-1.5-7.5L2 2l3.5 14.5L13 18l5-5z"},null,-1),a.createElementVNode("path",{d:"m2 2 7.586 7.586"},null,-1),a.createElementVNode("circle",{cx:"11",cy:"11",r:"2"},null,-1)])])):a.createCommentVNode("",!0)]),a.createElementVNode("span",wC,a.toDisplayString(I.label),1)],8,cC)),64))])],64))],4)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)],64)}}}),EC="https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F7e3b7dde-927d-4b09-aeb4-d49eac36d4ea.png?generation=1715183194653465&alt=media",Dp=a.defineComponent({__name:"TapeTool",setup(n){const e=JSON.stringify({block:{tag:"tape",size:[200,30]},tape:{thickness:30},asset:{identifier:EC,uploadState:"complete"}});return(t,o)=>(a.openBlock(),a.createBlock(at,{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"]))}}),vC={class:"wov-toolbar-container"},Lp=a.defineComponent({__name:"Toolbar",setup(n){const e=a.useSlots(),{reset:t}=Pt(),{nextEditorTick:o}=de(),r=a.ref(null),s=a.ref(null),i=Me(w.Controls),l=a.computed(()=>i.value.leftMouseTool),c=[Tp,Mp,Op,Rp,Pp,Np,_p,Ap,Dp,Ip,Bp],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),b=a.ref(48),{width:S}=yp(d);function x(){return h.value?Array.from(h.value.children).filter(j=>!j.classList.contains("wov-overflow-button")&&!j.classList.contains("wov-menu-tooltip")):[]}function C(){var re;const j=x();if(j.length===0)return;g.value=j.length;const F=getComputedStyle(h.value);k.value=parseFloat(F.gap)||8;const X=((re=p.value)==null?void 0:re.offsetWidth)||40;b.value=X+k.value,y.value=j.map(le=>le.offsetWidth)}function T(){if(y.value.length===0)return;const X=S.value-40-20,re=k.value,le=b.value;let Be=0,ce=0;for(let He=0;He<y.value.length;He++){const $n=y.value[He],dn=Be>0?$n+re:$n,Dt=y.value.length-He-1>0?le:0;if(Be+dn+Dt<=X)Be+=dn,ce++;else break}m.value=Math.max(1,ce)}a.watch(S,()=>{y.value.length>0&&T()}),a.onMounted(()=>{a.nextTick(()=>{C(),T()})});const E=a.computed(()=>m.value<g.value);a.watchEffect(()=>{x().forEach((F,X)=>{F.style.display=X<m.value?"":"none"})}),a.watchEffect(()=>{if(!u.value)return;Array.from(u.value.children).forEach((F,X)=>{F.style.display=X>=m.value?"":"none"})});const{floatingStyles:M}=uo(p,u,{placement:"top",middleware:[lo(16),co(),ao({padding:8})],whileElementsMounted:Ws});function v(){f.value=!f.value}function B(){f.value=!1}function I(j){const F=j.target;p.value&&!p.value.contains(F)&&u.value&&!u.value.contains(F)&&B()}a.watch(f,j=>{j?document.addEventListener("click",I,!0):document.removeEventListener("click",I,!0)}),a.watch(E,j=>{j||B()});function P(j,F,X){s.value=F??null,o(re=>{const le=w.Controls.write(re);le.leftMouseTool=j,le.heldSnapshot=F??"",X&&w.Cursor.setCursor(re,X)})}function V(j){o(F=>{const X=w.Controls.write(F);X.leftMouseTool="drag-out",X.heldSnapshot=j})}function z(j,F){r.value=j,s.value=F??null}function W(){r.value=null,s.value=null}function G(){t(),r.value&&s.value&&V(s.value),r.value=null,s.value=null}const K={activeTool:l,heldTool:r,setTool:P,dragOutTool:V,onToolPointerDown:z,onToolPointerUp:W};return a.provide(di,K),(j,F)=>(a.openBlock(),a.createElementBlock("div",vC,[a.createVNode(oC),a.createElementVNode("div",{ref_key:"toolsContainerRef",ref:h,class:"wov-toolbar",onMouseleave:G},[a.unref(e).default?a.renderSlot(j.$slots,"default",{key:0}):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},a.renderList(c,(X,re)=>a.createVNode(a.resolveDynamicComponent(X),{key:re})),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:v},[...F[0]||(F[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),a.createVNode(ha)],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(j.$slots,"default",{key:0}):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},a.renderList(c,(X,re)=>a.createVNode(a.resolveDynamicComponent(X),{key:re})),64))],4)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)]))}}),TC=a.defineComponent({__name:"ArcArrowTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(at,{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}))}}),MC={class:"wov-user-presence-avatars"},AC=["src","alt"],NC={class:"wov-user-presence-list"},BC=["src","alt"],IC={class:"wov-user-presence-name"},OC=4,Vp=a.defineComponent({__name:"UserPresence",props:{users:{}},setup(n){const e=n,t=a.ref(!1),o=a.ref(null);T2(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,OC));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",MC,[(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,AC)):(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",NC,[(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,BC)):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[a.createTextVNode(a.toDisplayString(d.initials),1)],64))],4),a.createElementVNode("span",IC,a.toDisplayString(d.name),1)]))),128))])],32)):a.createCommentVNode("",!0)],512)):a.createCommentVNode("",!0)}}),Ca=(n,e)=>e.some(t=>n instanceof t);let $p,zp;function _C(){return $p||($p=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function RC(){return zp||(zp=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const Ea=new WeakMap,va=new WeakMap,Ys=new WeakMap;function PC(n){const e=new Promise((t,o)=>{const r=()=>{n.removeEventListener("success",s),n.removeEventListener("error",i)},s=()=>{t(Pn(n.result)),r()},i=()=>{o(n.error),r()};n.addEventListener("success",s),n.addEventListener("error",i)});return Ys.set(e,n),e}function DC(n){if(Ea.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)});Ea.set(n,e)}let Ta={get(n,e,t){if(n instanceof IDBTransaction){if(e==="done")return Ea.get(n);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return Pn(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 Fp(n){Ta=n(Ta)}function LC(n){return RC().includes(n)?function(...e){return n.apply(Ma(this),e),Pn(this.request)}:function(...e){return Pn(n.apply(Ma(this),e))}}function VC(n){return typeof n=="function"?LC(n):(n instanceof IDBTransaction&&DC(n),Ca(n,_C())?new Proxy(n,Ta):n)}function Pn(n){if(n instanceof IDBRequest)return PC(n);if(va.has(n))return va.get(n);const e=VC(n);return e!==n&&(va.set(n,e),Ys.set(e,n)),e}const Ma=n=>Ys.get(n);function $C(n,e,{blocked:t,upgrade:o,blocking:r,terminated:s}={}){const i=indexedDB.open(n,e),l=Pn(i);return o&&i.addEventListener("upgradeneeded",c=>{o(Pn(i.result),c.oldVersion,c.newVersion,Pn(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 zC=["get","getKey","getAll","getAllKeys","count"],FC=["put","add","delete","clear"],Aa=new Map;function Hp(n,e){if(!(n instanceof IDBDatabase&&!(e in n)&&typeof e=="string"))return;if(Aa.get(e))return Aa.get(e);const t=e.replace(/FromIndex$/,""),o=e!==t,r=FC.includes(t);if(!(t in(o?IDBIndex:IDBObjectStore).prototype)||!(r||zC.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 Aa.set(e,s),s}Fp(n=>({...n,get:(e,t,o)=>Hp(e,t)||n.get(e,t,o),has:(e,t)=>!!Hp(e,t)||n.has(e,t)}));const HC=["continue","continuePrimaryKey","advance"],jp={},Na=new WeakMap,Up=new WeakMap,jC={get(n,e){if(!HC.includes(e))return n[e];let t=jp[e];return t||(t=jp[e]=function(...o){Na.set(this,Up.get(this)[e](...o))}),t}};async function*UC(...n){let e=this;if(e instanceof IDBCursor||(e=await e.openCursor(...n)),!e)return;e=e;const t=new Proxy(e,jC);for(Up.set(t,e),Ys.set(t,Ma(e));e;)yield t,e=await(Na.get(t)||e.continue()),Na.delete(t)}function Wp(n,e){return e===Symbol.asyncIterator&&Ca(n,[IDBIndex,IDBObjectStore,IDBCursor])||e==="iterate"&&Ca(n,[IDBIndex,IDBObjectStore])}Fp(n=>({...n,get(e,t,o){return Wp(e,t)?UC:n.get(e,t,o)},has(e,t){return Wp(e,t)||n.has(e,t)}}));async function Ba(n,e){const t=await $C(n,1,{upgrade(o){o.objectStoreNames.contains(e)||o.createObjectStore(e)}});return new WC(t,e)}var WC=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()}},KC=class{constructor(n){this.jobsStore=null,this.binariesStore=null,this.blobUrls=new Map,this.uploading=new Set,this.uploadPromises=new Map,this.provider=n.provider,this.documentId=n.documentId,this.maxRetries=n.provider.maxRetries??3,this.retryDelay=n.provider.retryDelay??5e3}async init(){const n=`wovencanvas-assets-${this.documentId}`,[e,t]=await Promise.all([Ba(`${n}-jobs`,"jobs"),Ba(`${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");await this.binariesStore.put(n,e);const o={identifier:n,metadata:t,createdAt:Date.now(),retryCount:0};await this.jobsStore.put(n,o);const r=URL.createObjectURL(e);return this.blobUrls.set(n,r),new Promise((s,i)=>{this.uploadPromises.set(n,{resolve:s,reject:i}),this.startUpload(n)})}async getDisplayUrl(n){if(!n)return null;if(n.startsWith("http://")||n.startsWith("https://"))return n;const e=this.blobUrls.get(n);if(e)return e;try{return await this.provider.resolveUrl(n)}catch(t){return console.error(`Failed to resolve URL for ${n}:`,t),null}}async resumePendingUploads(){if(!this.jobsStore||!this.binariesStore)throw new Error("AssetManager not initialized");const n=await this.jobsStore.getAllEntries();for(const[e]of n){const t=await this.binariesStore.get(e);if(t){const o=URL.createObjectURL(t);this.blobUrls.set(e,o)}this.startUpload(e)}}hasPendingUpload(n){return this.blobUrls.has(n)}isUploading(n){return this.uploading.has(n)}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}try{await this.provider.upload(t,n,e.metadata),await this.onUploadSuccess(n)}catch(o){await this.onUploadError(n,e,o)}}async onUploadSuccess(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.resolve(),this.uploadPromises.delete(n))}async onUploadError(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=this.uploadPromises.get(n);r&&(r.reject(new Error(o)),this.uploadPromises.delete(n))}}},qC="wovencanvas-assets",GC="blobs",JC=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){const t=await(await this.getStore()).get(n);if(!t)throw new Error(`Asset not found: ${n}`);return URL.createObjectURL(t.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=Ba(qC,GC).then(n=>(this.store=n,n))),this.initPromise)}};function YC(){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 XC(){const n=YC();if(n.__xstate__)return n.__xstate__}const QC=n=>{if(typeof window>"u")return;const e=XC();e&&e.register(n)};class Kp{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 qp=".",ZC="",Gp="",eE="#",tE="*",Jp="xstate.init",nE="xstate.error",Ia="xstate.stop";function oE(n,e){return{type:`xstate.after.${n}.${e}`}}function Oa(n,e){return{type:`xstate.done.state.${n}`,output:e}}function rE(n,e){return{type:`xstate.done.actor.${n}`,output:e,actorId:n}}function Yp(n,e){return{type:`xstate.error.actor.${n}`,error:e,actorId:n}}function Xp(n){return{type:Jp,input:n}}function St(n){setTimeout(()=>{throw n})}const sE=typeof Symbol=="function"&&Symbol.observable||"@@observable";function Qp(n,e){const t=Zp(n),o=Zp(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?Qp(t[r],o[r]):!1)}function _a(n){if(nm(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 Zp(n){if(zE(n))return n.value;if(typeof n!="string")return n;const e=_a(n);return iE(e)}function iE(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 em(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 tm(n){return nm(n)?n:[n]}function ln(n){return n===void 0?[]:tm(n)}function Ra(n,e,t,o){return typeof n=="function"?n({context:e,event:t,self:o}):n}function nm(n){return Array.isArray(n)}function lE(n){return n.type.startsWith("xstate.error.actor")}function ho(n){return tm(n).map(e=>typeof e>"u"||typeof e=="string"?{target:e}:e)}function om(n){if(!(n===void 0||n===ZC))return ln(n)}function Pa(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 rm(n,e){return`${e}.${n}`}function Da(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 aE(n,e){if(e===n||e===tE)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 sm(n,e){return`${n.sessionId}.${e}`}let cE=0;function dE(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()},b=sm(h,y);f._snapshot._scheduledEvents[b]=k;const S=l.setTimeout(()=>{delete i[b],delete f._snapshot._scheduledEvents[b],f._relay(h,p,m)},g);i[b]=S},cancel:(h,p)=>{const m=sm(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:${cE++}`,_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=Pa(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:b}=h[p];d.schedule(m,g,y,k,b)}},_clock:l,_logger:c};return f}let La=!1;const Va=1;let Fe=function(n){return n[n.NotStarted=0]="NotStarted",n[n.Running=1]="Running",n[n.Stopped=2]="Stopped",n}({});const uE={clock:{setTimeout:(n,e)=>setTimeout(n,e),clearTimeout:n=>clearTimeout(n)},logger:console.log.bind(console),devTools:!1};class fE{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 Kp(this._process.bind(this)),this.observers=new Set,this.eventListeners=new Map,this.logger=void 0,this._processingStatus=Fe.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={...uE,...t},{clock:r,logger:s,parent:i,syncSnapshot:l,id:c,systemId:d,inspect:u}=o;this.system=i?i.system:dE(this,{clock:r,logger:s}),u&&!i&&this.system.inspect(Pa(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){St(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=La;try{La=!0,f.exec(f.info,f.params)}finally{La=p}};this._processingStatus===Fe.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){St(l)}break;case"done":for(const i of this.observers)try{(s=i.next)==null||s.call(i,e)}catch(l){St(l)}this._stopProcedure(),this._complete(),this._doneEvent=rE(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=Pa(e,t,o);if(this._processingStatus!==Fe.Stopped)this.observers.add(r);else switch(this._snapshot.status){case"done":try{(s=r.complete)==null||s.call(r)}catch(i){St(i)}break;case"error":{const i=this._snapshot.error;if(!r.error)St(i);else try{r.error(i)}catch(l){St(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===Fe.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=Fe.Running;const e=Xp(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===Ia&&(this._stopProcedure(),this._complete())}_stop(){return this._processingStatus===Fe.Stopped?this:(this.mailbox.clear(),this._processingStatus===Fe.NotStarted?(this._processingStatus=Fe.Stopped,this):(this.mailbox.enqueue({type:Ia}),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){St(o)}this.observers.clear(),this.eventListeners.clear()}_reportError(e){if(!this.observers.size){this._parent||St(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){St(s)}}this.observers.clear(),this.eventListeners.clear(),t&&St(e)}_error(e){this._stopProcedure(),this._reportError(e),this._parent&&this.system._relay(this,this._parent,Yp(this.id,e))}_stopProcedure(){return this._processingStatus!==Fe.Running?this:(this.system.scheduler.cancelAll(this),this.mailbox.clear(),this.mailbox=new Kp(this._process.bind(this)),this._processingStatus=Fe.Stopped,this.system._unregister(this),this)}_send(e){this._processingStatus!==Fe.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:QC)(this)}toJSON(){return{xstate$$type:Va,id:this.id}}getPersistedSnapshot(e){return this.logic.getPersistedSnapshot(this._snapshot,e)}[sE](){return this}getSnapshot(){return this._snapshot}}function Xs(n,...[e]){return new fE(n,e)}function hE(n,e,t,o,{sendId:r}){const s=typeof r=="function"?r(t,o):r;return[e,{sendId:s},void 0]}function pE(n,e){n.defer(()=>{n.system.scheduler.cancel(n.self,e.sendId)})}function $a(n){function e(t,o){}return e.type="xstate.cancel",e.sendId=n,e.resolve=hE,e.execute=pE,e}function mE(n,e,t,o,{id:r,systemId:s,src:i,input:l,syncSnapshot:c}){const d=typeof i=="string"?Da(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=Xs(d,{id:u,src:i,parent:n.self,syncSnapshot:c,systemId:s,input:h})),[Ln(e,{children:{...e.children,[u]:f}}),{id:r,systemId:s,actorRef:f,src:i,input:h},void 0]}function gE(n,{actorRef:e}){e&&n.defer(()=>{e._processingStatus!==Fe.Stopped&&e.start()})}function za(...[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=mE,s.execute=gE,s}function yE(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]),[Ln(e,{children:l}),i,void 0]}function im(n,e){const t=e.getSnapshot();if(t&&"children"in t)for(const o of Object.values(t.children))im(n,o);n.system._unregister(e)}function kE(n,e){if(e){if(im(n,e),e._processingStatus!==Fe.Running){n.stopChild(e);return}n.defer(()=>{n.stopChild(e)})}}function Qs(n){function e(t,o){}return e.type="xstate.stopChild",e.actorRef=n,e.resolve=yE,e.execute=kE,e}function Zs(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 Zs(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 Fa(n){return n.type==="atomic"||n.type==="final"}function po(n){return Object.values(n.states).filter(e=>e.type!=="history")}function ir(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 ei(n){const e=new Set(n),t=am(e);for(const o of e)if(o.type==="compound"&&(!t.get(o)||!t.get(o).length))um(o).forEach(r=>e.add(r));else if(o.type==="parallel"){for(const r of po(o))if(r.type!=="history"&&!e.has(r)){const s=um(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 lm(n,e){const t=e.get(n);if(!t)return{};if(n.type==="compound"){const r=t[0];if(r){if(Fa(r))return r.key}else return{}}const o={};for(const r of t)o[r.key]=lm(r,e);return o}function am(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 cm(n,e){const t=ei(e);return lm(n,am(t))}function Ha(n,e){return e.type==="compound"?po(e).some(t=>t.type==="final"&&n.has(t)):e.type==="parallel"?po(e).every(t=>Ha(n,t)):e.type==="final"}const ti=n=>n[0]===eE;function wE(n,e){return n.transitions.get(e)||[...n.transitions.keys()].filter(o=>aE(e,o)).sort((o,r)=>r.length-o.length).flatMap(o=>n.transitions.get(o))}function bE(n){const e=n.config.after;if(!e)return[];const t=r=>{const s=oE(r,n.id),i=s.type;return n.entry.push(Ja(s,{id:i,delay:r})),n.exit.push($a(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 ln(i).map(d=>({...d,event:c,delay:l}))}).map(r=>{const{delay:s}=r;return{...an(n,r.event,r),delay:s}})}function an(n,e,t){const o=om(t.target),r=t.reenter??!1,s=EE(n,o),i={...t,actions:ln(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 SE(n){const e=new Map;if(n.config.on)for(const t of Object.keys(n.config.on)){if(t===Gp)throw new Error('Null events ("") cannot be specified as a transition key. Use `always: { ... }` instead.');const o=n.config.on[t];e.set(t,ho(o).map(r=>an(n,t,r)))}if(n.config.onDone){const t=`xstate.done.state.${n.id}`;e.set(t,ho(n.config.onDone).map(o=>an(n,t,o)))}for(const t of n.invoke){if(t.onDone){const o=`xstate.done.actor.${t.id}`;e.set(o,ho(t.onDone).map(r=>an(n,o,r)))}if(t.onError){const o=`xstate.error.actor.${t.id}`;e.set(o,ho(t.onError).map(r=>an(n,o,r)))}if(t.onSnapshot){const o=`xstate.snapshot.${t.id}`;e.set(o,ho(t.onSnapshot).map(r=>an(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 xE(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(an(n,"xstate.route",c))}r.states&&t(r.states)})};t(n.states),e.length>0&&n.transitions.set("xstate.route",e)}function CE(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"?[]:ln(e.actions),eventType:null,reenter:!1,target:t?[t]:[],toJSON:()=>({...o,source:`#${n.id}`,target:t?[`#${t.id}`]:[]})};return o}function EE(n,e){if(e!==void 0)return e.map(t=>{if(typeof t!="string")return t;if(ti(t))return n.machine.getStateNodeById(t);const o=t[0]===qp;if(o&&!n.parent)return ni(n,t.slice(1));const r=o?n.key+t:t;if(n.parent)try{return ni(n.parent,r)}catch(s){throw new Error(`Invalid transition definition for state node '${n.id}':
107
+ ${s.message}`)}else throw new Error(`Invalid target: "${t}" is not a valid target from the root node. Did you mean ".${t}"?`)})}function dm(n){const e=om(n.config.target);return e?{target:e.map(t=>typeof t=="string"?ni(n.parent,t):t)}:n.parent.initial}function Dn(n){return n.type==="history"}function um(n){const e=fm(n);for(const t of e)for(const o of ir(t,n))e.add(o);return e}function fm(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 po(o))t(r)}}return t(n),e}function mo(n,e){if(ti(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 ni(n,e){if(typeof e=="string"&&ti(e))try{return n.machine.getStateNodeById(e)}catch{}const t=_a(e).slice();let o=n;for(;t.length;){const r=t.shift();if(!r.length)break;o=mo(o,r)}return o}function oi(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=>mo(n,r)).filter(Boolean);return[n.machine.root,n].concat(o,t.reduce((r,s)=>{const i=mo(n,s);if(!i)return r;const l=oi(i,e[s]);return r.concat(l)},[]))}function vE(n,e,t,o){const s=mo(n,e).next(t,o);return!s||!s.length?n.next(t,o):s}function TE(n,e,t,o){const r=Object.keys(e),s=mo(n,r[0]),i=ja(s,e[r[0]],t,o);return!i||!i.length?n.next(t,o):i}function ME(n,e,t,o){const r=[];for(const s of Object.keys(e)){const i=e[s];if(!i)continue;const l=mo(n,s),c=ja(l,i,t,o);c&&r.push(...c)}return r.length?r:n.next(t,o)}function ja(n,e,t,o){return typeof e=="string"?vE(n,e,t,o):Object.keys(e).length===1?TE(n,e,t,o):ME(n,e,t,o)}function AE(n){return Object.keys(n.states).map(e=>n.states[e]).filter(e=>e.type==="history")}function cn(n,e){let t=n;for(;t.parent&&t.parent!==e;)t=t.parent;return t.parent===e}function NE(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 hm(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(NE(Wa([r],e,t),Wa([l],e,t)))if(cn(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 BE(n){const[e,...t]=n;for(const o of ir(e,void 0))if(t.every(r=>cn(r,o)))return o}function Ua(n,e){if(!n.target)return[];const t=new Set;for(const o of n.target)if(Dn(o))if(e[o.id])for(const r of e[o.id])t.add(r);else for(const r of Ua(dm(o),e))t.add(r);else t.add(o);return[...t]}function pm(n,e){const t=Ua(n,e);if(!t)return;if(!n.reenter&&t.every(r=>r===n.source||cn(r,n.source)))return n.source;const o=BE(t.concat(n.source));if(o)return o;if(!n.reenter)return n.source.machine.root}function Wa(n,e,t){var r;const o=new Set;for(const s of n)if((r=s.target)!=null&&r.length){const i=pm(s,t);s.reenter&&s.source===i&&o.add(i);for(const l of e)cn(l,i)&&o.add(l)}return[...o]}function IE(n,e){if(n.length!==e.size)return!1;for(const t of n)if(!e.has(t))return!1;return!0}function OE(n,e,t,o,r){return Ka([{target:[...fm(n)],source:n,reenter:!0,actions:[],eventType:null,toJSON:null}],e,t,o,!0,r)}function Ka(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=hm(n,c,d);let f=e;r||([f,d]=DE(f,o,t,u,c,d,s,t.actionExecutor)),f=yo(f,o,t,u.flatMap(p=>p.actions),s,void 0),f=RE(f,o,t,u,c,s,d,r);const h=[...c];f.status==="done"&&(f=yo(f,o,t,h.sort((p,m)=>m.order-p.order).flatMap(p=>p.exit),s,void 0));try{return d===e.historyValue&&IE(e._nodes,c)?[f,i]:[Ln(f,{_nodes:h,historyValue:d}),i]}catch(p){throw p}}finally{t.actionExecutor=l}}function _E(n,e,t,o,r){if(o.output===void 0)return;const s=Oa(r.id,r.output!==void 0&&r.parent?Ra(r.output,n.context,e,t.self):void 0);return Ra(o.output,n.context,s,t.self)}function RE(n,e,t,o,r,s,i,l){let c=n;const d=new Set,u=new Set;PE(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(za(m.src,{...m,syncSnapshot:!!m.onSnapshot}));if(u.has(h)){const m=h.initial.actions;p.push(...m)}if(c=yo(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(Oa(m.id,h.output!==void 0?Ra(h.output,c.context,e,t.self):void 0));(g==null?void 0:g.type)==="parallel"&&!f.has(g)&&Ha(r,g);)f.add(g),s.push(Oa(g.id)),y=g,g=g.parent;if(g)continue;c=Ln(c,{status:"done",output:_E(c,e,t,c.machine.root,y)})}}return c}function PE(n,e,t,o){for(const r of n){const s=pm(r,e);for(const l of r.target||[])!Dn(l)&&(r.source!==l||r.source!==s||r.reenter)&&(o.add(l),t.add(l)),go(l,e,t,o);const i=Ua(r,e);for(const l of i){const c=ir(l,s);(s==null?void 0:s.type)==="parallel"&&c.push(s),mm(o,e,t,c,!r.source.parent&&r.reenter?void 0:s)}}}function go(n,e,t,o){var r;if(Dn(n))if(e[n.id]){const s=e[n.id];for(const i of s)o.add(i),go(i,e,t,o);for(const i of s)qa(i,n.parent,o,e,t)}else{const s=dm(n);for(const i of s.target)o.add(i),s===((r=n.parent)==null?void 0:r.initial)&&t.add(n.parent),go(i,e,t,o);for(const i of s.target)qa(i,n.parent,o,e,t)}else if(n.type==="compound"){const[s]=n.initial.target;Dn(s)||(o.add(s),t.add(s)),go(s,e,t,o),qa(s,n,o,e,t)}else if(n.type==="parallel")for(const s of po(n).filter(i=>!Dn(i)))[...o].some(i=>cn(i,s))||(Dn(s)||(o.add(s),t.add(s)),go(s,e,t,o))}function mm(n,e,t,o,r){for(const s of o)if((!r||cn(s,r))&&n.add(s),s.type==="parallel")for(const i of po(s).filter(l=>!Dn(l)))[...n].some(l=>cn(l,i))||(n.add(i),go(i,e,t,n))}function qa(n,e,t,o,r){mm(t,o,r,ir(n,e))}function DE(n,e,t,o,r,s,i,l){let c=n;const d=Wa(o,r,s);d.sort((f,h)=>h.order-f.order);let u;for(const f of d)for(const h of AE(f)){let p;h.history==="deep"?p=m=>Fa(m)&&cn(m,f):p=m=>m.parent===f,u??(u={...s}),u[h.id]=Array.from(r).filter(p)}for(const f of d)c=yo(c,e,t,[...f.exit,...f.invoke.map(h=>Qs(h.id))],i,void 0),r.delete(f);return[c,u||s]}function LE(n,e){return n.implementations.actions[e]}function gm(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:LE(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=gm(l,e,t,y,r,s))}return l}function yo(n,e,t,o,r,s){const i=s?[]:void 0,l=gm(n,e,t,o,{internalQueue:r,deferredActorIds:s},i);return i==null||i.forEach(([c,d])=>{c.retryResolve(t,l,d)}),l}function Ga(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===Ia)return r=Ln(ym(r,e,t),{status:"stopped"}),i([r,[]],e,[]),{snapshot:r,microsteps:s};let l=e;if(l.type!==Jp){const d=l,u=lE(d),f=km(d,r);if(u&&!f.length)return r=Ln(n,{status:"error",error:d.error}),i([r,[]],d,[]),{snapshot:r,microsteps:s};const h=Ka(f,n,t,l,!1,o);r=h[0],i(h,d,f)}let c=!0;for(;r.status==="active";){let d=c?VE(r,l):[];const u=d.length?r:void 0;if(!d.length){if(!o.length)break;l=o.shift(),d=km(l,r)}const f=Ka(d,r,t,l,!1,o);r=f[0],c=r!==u,i(f,l,d)}return r.status!=="active"&&ym(r,l,t),{snapshot:r,microsteps:s}}function ym(n,e,t){return yo(n,e,t,Object.values(n.children).map(o=>Qs(o)),[],void 0)}function km(n,e){return e.machine.getTransitionData(e,n)}function VE(n,e){const t=new Set,o=n._nodes.filter(Fa);for(const r of o)e:for(const s of[r].concat(ir(r,void 0)))if(s.always){for(const i of s.always)if(i.guard===void 0||Zs(i.guard,n.context,e,n)){t.add(i);break e}}return hm(Array.from(t),new Set(n._nodes),n.historyValue)}function $E(n,e){const t=ei(oi(n,e));return cm(n,[...t])}function zE(n){return!!n&&typeof n=="object"&&"machine"in n&&"value"in n}const FE=function(e){return Qp(e,this.value)},HE=function(e){return this.tags.has(e)},jE=function(e){const t=this.machine.getTransitionData(this,e);return!!(t!=null&&t.length)&&t.some(o=>o.target!==void 0||o.actions.length)},UE=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)}},WE=function(){return this._nodes.reduce((e,t)=>(t.meta!==void 0&&(e[t.id]=t.meta),e),{})};function ri(n,e){return{status:n.status,output:n.output,error:n.error,machine:e,context:n.context,_nodes:n._nodes,value:cm(e.root,n._nodes),tags:new Set(n._nodes.flatMap(t=>t.tags)),children:n.children,historyValue:n.historyValue||{},matches:FE,hasTag:HE,can:jE,getMeta:WE,toJSON:UE}}function Ln(n,e={}){return ri({...n,...e},n.machine)}function KE(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 qE(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:wm(i),children:p,historyValue:KE(h.historyValue)}}function wm(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:Va,id:o.id};else{const r=wm(o);r!==o&&(e??(e=Array.isArray(n)?n.slice():{...n}),e[t]=r)}}return e??n}function GE(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 JE(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 Ja(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=GE,t.execute=JE,t}function YE(n,{machine:e,context:t},o,r){const s=(i,l)=>{if(typeof i=="string"){const c=Da(e,i);if(!c)throw new Error(`Actor logic '${i}' not implemented in machine '${e.id}'`);const d=Xs(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 Xs(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!==Fe.Stopped&&c.start()}),c}}function XE(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:YE(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[Ln(e,{context:c,children:Object.keys(s).length?{...e.children,...s}:e.children}),void 0,void 0]}function Vn(n){function e(t,o){}return e.type="xstate.assign",e.assignment=n,e.resolve=XE,e}const bm=new WeakMap;function ko(n,e,t){let o=bm.get(n);return o?e in o||(o[e]=t()):(o={[e]:t()},bm.set(n,o)),o[e]}const QE={},lr=n=>typeof n=="string"?{type:n}:typeof n=="function"?"resolve"in n?{type:n.type}:{type:n.name}:n;class si{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(qp),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?em(this.config.states,(o,r)=>new si(o,{_parent:this,_key:r,_machine:this.machine})):QE,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=ln(this.config.entry).slice(),this.exit=ln(this.config.exit).slice(),this.meta=this.config.meta,this.output=this.type==="final"||!this.parent?this.config.output:void 0,this.tags=ln(e.tags).slice()}_initialize(){this.transitions=SE(this),this.config.always&&(this.always=ho(this.config.always).map(e=>an(this,Gp,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(lr),eventType:null,reenter:!1,toJSON:()=>({target:this.initial.target.map(e=>`#${e.id}`),source:`#${this.id}`,actions:this.initial.actions.map(lr),eventType:null})}:void 0,history:this.history,states:em(this.states,e=>e.definition),on:this.on,transitions:[...this.transitions.values()].flat().map(e=>({...e,actions:e.actions.map(lr)})),entry:this.entry.map(lr),exit:this.exit.map(lr),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 ko(this,"invoke",()=>ln(this.config.invoke).map((e,t)=>{const{src:o,systemId:r}=e,s=e.id??rm(this.id,t),i=typeof o=="string"?o:`xstate.invoke.${rm(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 ko(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 ko(this,"delayedTransitions",()=>bE(this))}get initial(){return ko(this,"initial",()=>CE(this,this.config.initial))}next(e,t){const o=t.type,r=[];let s;const i=ko(this,`candidates-${o}`,()=>wE(this,o));for(const l of i){const{guard:c}=l,d=e.context;let u=!1;try{u=!c||Zs(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}':
108
+ ${f.message}`)}if(u){r.push(...l.actions),s=l;break}}return s?[s]:void 0}get events(){return ko(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 ZE="#";class Ya{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 si(e,{_key:this.id,_machine:this}),this.root._initialize(),xE(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 Ya(this.config,{actions:{...t,...e.actions},guards:{...o,...e.guards},actors:{...r,...e.actors},delays:{...s,...e.delays}})}resolveState(e){const t=$E(this.root,e.value),o=ei(oi(this.root,t));return ri({_nodes:[...o],context:e.context||{},children:{},status:Ha(o,this.root)?"done":e.status||"active",output:e.output,error:e.error,historyValue:e.historyValue},this)}transition(e,t,o){return Ga(e,t,o,[]).snapshot}microstep(e,t,o){return Ga(e,t,o,[]).microsteps.map(([r])=>r)}getTransitionData(e,t){return ja(this.root,e.value,e,t)||[]}_getPreInitialState(e,t,o){const{context:r}=this.config,s=ri({context:typeof r!="function"&&r?r:{},_nodes:[this.root],children:{},status:"active"},this);return typeof r=="function"?yo(s,t,e,[Vn(({spawn:l,event:c,self:d})=>r({spawn:l,input:c.input,self:d}))],o,void 0):s}getInitialSnapshot(e,t){const o=Xp(t),r=[],s=this._getPreInitialState(e,o,r),[i]=OE(this.root,s,e,o,r),{snapshot:l}=Ga(i,o,e,r);return l}start(e){Object.values(e.children).forEach(t=>{t.getSnapshot().status==="active"&&t.start()})}getStateNodeById(e){const t=_a(e),o=t.slice(1),r=ti(t[0])?t[0].slice(ZE.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 ni(s,o)}get definition(){return this.root.definition}toJSON(){return this.definition}getPersistedSnapshot(e,t){return qE(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"?Da(this,m):m;if(!g)return;const y=Xs(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 si)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=ri({...e,children:o,_nodes:Array.from(ei(oi(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===Va){f[p]=h[m.id];continue}u(m,h)}}}}return u(c.context,o),c}}function ev(n,e,t,o,{event:r}){const s=typeof r=="function"?r(t,o):r;return[e,{event:s},void 0]}function tv(n,{event:e}){n.defer(()=>n.emit(e))}function Sm(n){function e(t,o){}return e.type="xstate.emit",e.event=n,e.resolve=ev,e.execute=tv,e}let Xa=function(n){return n.Parent="#_parent",n.Internal="#_internal",n}({});function nv(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===Xa.Parent?p=n.self._parent:h===Xa.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 ov(n,e,t){typeof t.to=="string"&&(t.to=e.children[t.to])}function rv(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===nE?Yp(n.self.id,o.data):o)})}function Qa(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=nv,o.retryResolve=ov,o.execute=rv,o}function sv(n,e){return Qa(Xa.Parent,n,e)}function iv(n,e,t,o,{collect:r}){const s=[],i=function(c){s.push(c)};return i.assign=(...l)=>{s.push(Vn(...l))},i.cancel=(...l)=>{s.push($a(...l))},i.raise=(...l)=>{s.push(Ja(...l))},i.sendTo=(...l)=>{s.push(Qa(...l))},i.sendParent=(...l)=>{s.push(sv(...l))},i.spawnChild=(...l)=>{s.push(za(...l))},i.stopChild=(...l)=>{s.push(Qs(...l))},i.emit=(...l)=>{s.push(Sm(...l))},r({context:t.context,event:t.event,enqueue:i,check:l=>Zs(l,e.context,t.event,e),self:n.self,system:n.system},o),[e,void 0,s]}function lv(n){function e(t,o){}return e.type="xstate.enqueueActions",e.collect=n,e.resolve=iv,e}function av(n,e,t,o,{value:r,label:s}){return[e,{value:typeof r=="function"?r(t,o):r,label:s},void 0]}function cv({logger:n},{value:e,label:t}){t?n(t,e):n(e)}function dv(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=av,t.execute=cv,t}function uv(n,e){return new Ya(n,e)}function xm({schemas:n,actors:e,actions:t,guards:o,delays:r}){return{assign:Vn,sendTo:Qa,raise:Ja,log:dv,cancel:$a,stopChild:Qs,enqueueActions:lv,emit:Sm,spawnChild:za,createStateConfig:s=>s,createAction:s=>s,createMachine:s=>uv({...s,schemas:n},{actors:e,actions:t,guards:o,delays:r}),extend:s=>xm({schemas:n,actors:e,actions:{...t,...s.actions},guards:{...o,...s.guards},delays:{...r,...s.delays}})}}var fv=Object.defineProperty,Za=(n,e)=>{for(var t in e)fv(n,t,{get:e[t],enumerable:!0})},Cm=w.defineCommand("tape-add"),Em=w.defineCommand("tape-draw"),vm=w.defineCommand("tape-remove"),Tm=w.defineCommand("tape-complete"),Mm=w.defineCommand("tape-place"),Am={};Za(Am,{Tape:()=>ar});var ar=w.defineCanvasComponent({name:"tape",sync:"document"},{thickness:w.field.float64().default(30)}),hv="tapes",ii=30,Nm=200,pv=4,Bm="https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F7e3b7dde-927d-4b09-aeb4-d49eac36d4ea.png?generation=1715183194653465&alt=media",Im={};Za(Im,{TapeDrawState:()=>Om});var ct={Idle:"idle",Pointing:"pointing",Drawing:"drawing"},Om=w.defineEditorState("tapeDrawState",{state:w.field.string().max(16).default(ct.Idle),activeTape:w.field.ref(),pointingStartClient:w.field.tuple(w.field.int32(),2).default([0,0]),pointingStartWorld:w.field.tuple(w.field.float64(),2).default([0,0])}),_m={};Za(_m,{captureTapeDrawSystem:()=>gv,updateTapeDrawSystem:()=>yv});var mv=xm({guards:{isThresholdReached:({context:n,event:e})=>Ie.Vec2.distance(n.pointingStartClient,e.screenPosition)>=pv},actions:{setPointingStart:Vn({pointingStartClient:({event:n})=>[n.screenPosition[0],n.screenPosition[1]],pointingStartWorld:({event:n})=>[n.worldPosition[0],n.worldPosition[1]]}),resetContext:Vn({pointingStartClient:()=>[0,0],pointingStartWorld:()=>[0,0],activeTape:()=>null}),addTape:Vn({activeTape:({context:n,event:e})=>{const t=n.pointingStartWorld,o=w.createEntity(e.ctx);return Cm.spawn(e.ctx,{entityId:o,position:t}),o}}),drawTape:({context:n,event:e})=>{if(!n.activeTape)return;const t=n.pointingStartWorld;Em.spawn(e.ctx,{entityId:n.activeTape,start:t,end:e.worldPosition})},completeTape:({context:n,event:e})=>{n.activeTape&&Tm.spawn(e.ctx,{entityId:n.activeTape})},removeTape:Vn({activeTape:({context:n,event:e})=>(n.activeTape&&vm.spawn(e.ctx,{entityId:n.activeTape}),null)}),placeTape:({context:n,event:e})=>{const t=n.pointingStartWorld,o=w.createEntity(e.ctx);Mm.spawn(e.ctx,{entityId:o,position:t})},exitTapeControl:({event:n})=>{const e=w.Controls.write(n.ctx);e.leftMouseTool="select";const t=w.Cursor.write(n.ctx);t.cursorKind="select"},deselectAll:({event:n})=>{ne.DeselectAll.spawn(n.ctx)}}}).createMachine({id:"tapeDraw",initial:ct.Idle,context:{activeTape:null,pointingStartClient:[0,0],pointingStartWorld:[0,0]},states:{[ct.Idle]:{entry:"resetContext",on:{pointerDown:[{actions:"deselectAll",target:ct.Pointing}]}},[ct.Pointing]:{entry:"setPointingStart",on:{pointerMove:{guard:"isThresholdReached",target:ct.Drawing},pointerUp:{actions:["placeTape","exitTapeControl"],target:ct.Idle},cancel:{target:ct.Idle}}},[ct.Drawing]:{entry:"addTape",exit:"exitTapeControl",on:{pointerMove:{actions:"drawTape"},pointerUp:{actions:"completeTape",target:ct.Idle},cancel:{actions:"removeTape",target:ct.Idle}}}}}),gv=w.defineEditorSystem({phase:"capture",priority:100},n=>{const e=w.Controls.getButtons(n,"tape");if(e.length===0)return;const t=w.getPointerInput(n,e);t.length!==0&&Om.run(n,mv,t)}),yv=w.defineEditorSystem({phase:"update"},n=>{w.on(n,Cm,(e,{entityId:t,position:o})=>{kv(e,t,o)}),w.on(n,Em,(e,{entityId:t,start:o,end:r})=>{wv(e,t,o,r)}),w.on(n,vm,(e,{entityId:t})=>{w.removeEntity(e,t)}),w.on(n,Tm,(e,{entityId:t})=>{Sv(e,t)}),w.on(n,Mm,(e,{entityId:t,position:o})=>{bv(e,t,o)})});function kv(n,e,t){const o=[t[0],t[1]];w.Grid.snapPosition(n,o),w.addComponent(n,e,w.Block,{tag:"tape",rank:w.RankBounds.genNext(n),position:[o[0],o[1]-ii/2],size:[1,ii]}),w.addComponent(n,e,w.Synced,{id:crypto.randomUUID()}),w.addComponent(n,e,ar),w.addComponent(n,e,w.Image,{}),w.addComponent(n,e,w.Asset,{identifier:Bm,uploadState:w.UploadState.Complete})}function wv(n,e,t,o){const r=[t[0],t[1]],s=[o[0],o[1]];w.Grid.snapPosition(n,r),w.Grid.snapPosition(n,s);const i=s[0]-r[0],l=s[1]-r[1],c=Math.sqrt(i*i+l*l),d=Math.atan2(l,i),u=(r[0]+s[0])/2,f=(r[1]+s[1])/2,h=w.Block.write(n,e),m=ar.read(n,e).thickness;h.position=[u-c/2,f-m/2],h.size=[Math.max(c,1),m],h.rotateZ=d}function bv(n,e,t){const o=[t[0],t[1]];w.Grid.snapPosition(n,o),w.addComponent(n,e,w.Block,{tag:"tape",rank:w.RankBounds.genNext(n),position:[o[0]-Nm/2,o[1]-ii/2],size:[Nm,ii]}),w.addComponent(n,e,w.Synced,{id:crypto.randomUUID()}),w.addComponent(n,e,ar),w.addComponent(n,e,w.Image,{}),w.addComponent(n,e,w.Asset,{identifier:Bm,uploadState:w.UploadState.Complete}),ne.selectBlock(n,e)}function Sv(n,e){if(w.Block.read(n,e).size[0]<=1){w.removeEntity(n,e);return}ne.selectBlock(n,e)}var xv=n=>Object.values(n).filter(e=>typeof e=="object"&&e!==null&&"_system"in e&&"phase"in e);function Cv(){return{name:hv,dependencies:["selection"],components:Object.values(Am).filter(n=>n instanceof w.CanvasComponentDef),singletons:Object.values(Im).filter(n=>n instanceof w.CanvasSingletonDef),blockDefs:[{tag:"tape",components:[ar,w.Image,w.Asset],resizeMode:w.ResizeMode.Scale,connectors:{enabled:!1}}],systems:xv(_m)}}const Ev={class:"wov-selection-box"},vv=a.defineComponent({__name:"SelectionBox",setup(n){return(e,t)=>(a.openBlock(),a.createElementBlock("div",Ev))}}),Tv={class:"wov-transform-box"},Mv=a.defineComponent({__name:"TransformBox",setup(n){return(e,t)=>(a.openBlock(),a.createElementBlock("div",Tv))}}),Av={},Nv={class:"wov-transform-handle"};function Bv(n,e){return a.openBlock(),a.createElementBlock("div",Nv)}const Iv=fn(Av,[["render",Bv]]),Ov=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=pe(e.entityId,w.Color),o=pe(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}=ra({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(_s,a.mergeProps(e,{"block-element":r.value,onEditEnd:a.unref(l)}),null,16,["block-element","onEditEnd"])],4))}}),li=Ve.defineCanvasSingleton({name:"blockPlacementState"},{editedCheckpoint:w.field.string().default("").max(36)}),Rm=w.defineQuery(n=>n.with(w.Edited));function _v(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 Rv(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 h of o.components)if(!(h.name in e))w.addComponent(n,d,h);else{const p=e[h.name];w.addComponent(n,d,h,p)}const{sessionId:f}=w.getResources(n);return w.addComponent(n,d,w.Held,{sessionId:f}),d}function Pm(n,e,t,o,r){const s=Rv(n,e,t),i=w.Block.read(n,s);if(w.canBlockEdit(n,e.block.tag)&&(w.addComponent(n,s,ne.EditAfterPlacing,{}),r==="placement")){const{store:u}=w.getPluginResources(n,fo),f=u.createCheckpoint();if(f){const h=li.write(n);h.editedCheckpoint=f}}const l=ne.SelectionStateSingleton.write(n);l.state=r==="dragOut"?ne.SelectionState.Dragging:ne.SelectionState.Pointing,l.dragStart=t,l.draggedEntity=s,l.draggedEntityStart=i.position,l.pointingStartClient=o,l.pointingStartWorld=t,l.isCloning=!1;const c=w.Controls.write(n);c.leftMouseTool="select",c.heldSnapshot="";const d=w.Cursor.write(n);d.cursorKind="select",d.rotation=0}function Pv(n){const e=li.read(n);if(e.editedCheckpoint){const t=e.editedCheckpoint;li.write(n).editedCheckpoint="";const{store:o}=w.getPluginResources(n,fo);o.onSettled(()=>o.squashToCheckpoint(t),{frames:5})}}const Dv=w.defineEditorSystem({phase:"capture"},n=>{Rm.removed(n).length>0&&Rm.current(n).length===0&&Pv(n);const e=w.Controls.read(n);if(!e.heldSnapshot)return;const t=w.getPointerInput(n,[w.PointerButton.Left]);if(t.length===0)return;const o=_v(e.heldSnapshot);if(!o)return;if(e.leftMouseTool==="drag-out"){const s=t.find(i=>i.type==="pointerMove"&&!i.obscured);if(!s)return;Pm(n,o,s.worldPosition,s.screenPosition,"dragOut")}else{const s=t.find(i=>i.type==="pointerDown"&&!i.obscured);if(!s)return;Pm(n,o,s.worldPosition,s.screenPosition,"placement")}}),Lv=w.defineEditorSystem({phase:"update"},n=>{const{store:e}=w.getPluginResources(n,fo);w.on(n,w.Undo,()=>{e.canUndo()&&(ne.deselectAll(n),e.undo())}),w.on(n,w.Redo,()=>{e.canRedo()&&(ne.deselectAll(n),e.redo())})}),Vv=[{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 Dm(n){return{name:fo,resources:{store:n.store},singletons:[li],systems:[Dv,Lv],cursors:vp,fonts:Vv,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 $v=a.defineComponent({__name:"FileDropZone",props:{maxSize:{default:400}},setup(n){const e=n,{nextEditorTick:t}=de(),{createImageBlock:o}=Mh(),r=a.ref(!1);let s=0;const i=a.inject("containerRef");function l(b){var S;(S=b.dataTransfer)!=null&&S.types.some(x=>x==="Files"||x==="text/uri-list"||x==="text/html")&&(s++,s===1&&(r.value=!0))}function c(){s--,s===0&&(r.value=!1)}function d(){s=0,r.value=!1}a.onMounted(()=>{const b=i==null?void 0:i.value;b&&(b.addEventListener("dragenter",l),b.addEventListener("dragleave",c),b.addEventListener("drop",d))}),a.onUnmounted(()=>{const b=i==null?void 0:i.value;b&&(b.removeEventListener("dragenter",l),b.removeEventListener("dragleave",c),b.removeEventListener("drop",d))});function u(b){b.preventDefault(),b.dataTransfer&&(b.dataTransfer.dropEffect="copy")}function f(b){b.preventDefault()}function h(b){b.preventDefault()}async function p(b){if(b.preventDefault(),!b.dataTransfer)return;const S=b.clientX,x=b.clientY,C=Array.from(b.dataTransfer.files).filter(E=>E.type.startsWith("image/"));if(C.length>0){for(const E of C)await y(E,S,x);return}const T=m(b.dataTransfer);T&&await k(T,S,x)}function m(b){const S=b.getData("text/uri-list");if(S){const E=S.split(`
109
+ `).filter(M=>!M.startsWith("#")).find(M=>g(M));if(E)return E}const x=b.getData("text/html");if(x){const T=x.match(/<img[^>]+src=["']([^"']+)["']/i);if(T!=null&&T[1])return T[1]}const C=b.getData("text/plain");return C&&g(C)?C:null}function g(b){try{const x=new URL(b).pathname.toLowerCase();return/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i.test(x)||b.startsWith("data:image/"),!0}catch{return!1}}async function y(b,S,x){const C=await t(),T=w.Camera.read(C),E=w.Screen.read(C),M=T.left+(S-E.left)/T.zoom,v=T.top+(x-E.top)/T.zoom;await o(b,M,v,{maxSize:e.maxSize})}async function k(b,S,x){try{const C=await fetch(b);if(!C.ok){console.warn("Failed to fetch image from URL:",b);return}const T=await C.blob();if(!T.type.startsWith("image/")){console.warn("URL did not return an image:",b);return}const M=new URL(b).pathname.split("/").pop()||"image",v=new File([T],M,{type:T.type});await y(v,S,x)}catch(C){console.warn("Failed to load image from URL:",b,C)}}return(b,S)=>(a.openBlock(),a.createElementBlock("div",{class:a.normalizeClass(["wov-image-drop-zone",{"wov-drag-over":r.value}]),onDragover:u,onDragenter:f,onDragleave:h,onDrop:p},null,34))}}),zv={class:"wov-user-cursors"},Fv={class:"wov-cursor-svg",viewBox:"0 0 4.35 4.75",width:"20",height:"20"},Hv=["fill"],jv="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",Uv=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",zv,[(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",Fv,[a.createElementVNode("path",{fill:s.color,stroke:"#fff","stroke-miterlimit":"10","stroke-width":".25",d:jv},null,8,Hv)])),a.createElementVNode("span",{class:"wov-cursor-label",style:a.normalizeStyle({backgroundColor:s.color})},a.toDisplayString(s.name),5)],4))),128))]))}}),Wv={key:0,class:"wov-offline-indicator"},Kv=a.defineComponent({__name:"OfflineIndicator",props:{isOnline:{type:Boolean}},setup(n){return(e,t)=>n.isOnline?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",Wv,"Working Offline"))}}),qv={key:0,class:"wov-version-mismatch-overlay"},Gv=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",qv,[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)}}),Jv=a.defineComponent({__name:"BackToContentButton",setup(n){const{nextEditorTick:e}=de(),t=Me(w.Camera),o=w.defineQuery(d=>d.with(w.Synced,w.Block,w.Aabb)),r=a.ref(0),s=a.inject(je);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 I of u){const P=w.Aabb.read(d,I);f=Math.min(f,P.value[0]),h=Math.min(h,P.value[1]),p=Math.max(p,P.value[2]),m=Math.max(m,P.value[3])}const g=w.Screen.read(d),y=w.Camera.read(d),k=w.getPluginResources(d,ai.CONTROLS_PLUGIN_NAME)??ai.DEFAULT_CONTROLS_OPTIONS;let b=Math.min(g.width/(p-f),g.height/(m-h));b/=1.1,b=Math.min(b,y.zoom),b=Math.max(k.minZoom,Math.min(k.maxZoom,b));const S=(f+p)/2,x=(h+m)/2;let C=S-g.width/b/2,T=x-g.height/b/2;const E=g.width/b,M=g.height/b;let v=!1;for(const I of u){const P=w.Aabb.read(d,I);if(l(P.value,C,T,E,M)){v=!0;break}}if(!v){const I=Math.floor(Math.random()*u.length),P=u[I],V=w.Aabb.read(d,P),z=(V.value[0]+V.value[2])/2,W=(V.value[1]+V.value[3])/2;C=z-E/2,T=W-M/2}const B=w.Camera.write(d);B.left=C,B.top=T,B.zoom=b})}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)}}),Yv=["data-entity-id","data-selected","data-held-by-other","data-hovered"],Xv=a.defineComponent({__name:"WovenCanvasCore",props:{store:{},editor:{},background:{},assetProvider:{},pluginOptions:{},controls:{},initialState:{}},emits:["ready"],async setup(n,{emit:e}){var $m;let t,o;const r=w.defineQuery(N=>N.tracking(w.Block)),s=w.defineQuery(N=>N.with(w.Block).tracking(w.Connector)),i=w.defineQuery(N=>N.with(w.Block).tracking(ne.Selected)),l=w.defineQuery(N=>N.with(w.Block).tracking(w.Held)),c=w.defineQuery(N=>N.with(w.Block).tracking(w.Hovered)),d=w.defineQuery(N=>N.with(w.Block).tracking(w.Edited)),u=w.defineQuery(N=>N.with(w.Block).tracking(w.Opacity)),f=w.defineQuery(N=>N.tracking(w.User)),h=n,p=e,m=a.ref(null),g=a.shallowRef(null),y=w.UserData.parse((($m=h.editor)==null?void 0:$m.user)??{}),k=new Set,b=new Map,S=a.shallowRef([]),x=new Map,C=new Map,T=new Set,E=new Map,M=a.shallowRef([]),v=a.ref(!0),B=a.ref(!1),I=a.ref(!h.initialState),P=a.shallowRef(w.Camera.default());function V(N,U,A){let J=x.get(N);J||(J=new Map,x.set(N,J));let D=J.get(U);return D||(D=new Set,J.set(U,D)),D.add(A),()=>{D.delete(A),D.size===0&&(J.delete(U),J.size===0&&x.delete(N))}}function z(N,U,A,J=!1){const D=x.get(U);if(!D)return;const L=D.get(A.name);if(!L||L.size===0)return;let Se=null;J||(Se=A.snapshot(N,U));for(const un of L)un(Se)}function W(N,U){let A=C.get(N);return A||(A=new Set,C.set(N,A)),A.add(U),()=>{A.delete(U),A.size===0&&C.delete(N)}}function G(N,U){const A=C.get(U.name);if(!A||A.size===0)return;const J=U.snapshot(N);for(const D of A)D(J)}function K(N){return T.add(N),()=>{T.delete(N)}}function j(){return y.sessionId}function F(N){return b.get(N)??null}const X={hasEntity:N=>k.has(N),getEditor:()=>g.value,getAssetManager:()=>He,getSessionId:j,getUserBySessionId:F,subscribeComponent:V,subscribeSingleton:W,registerTickCallback:K};a.provide(je,X),a.provide("containerRef",m);const re=Dh();a.provide(ic,re);let le=0,Be=null,ce=null,He=null;function $n(N){var J;const U=[],A=h.pluginOptions;return(A==null?void 0:A.controls)!==!1&&U.push(ai.CanvasControlsPlugin((A==null?void 0:A.controls)??{})),(A==null?void 0:A.selection)!==!1&&U.push(ne.createSelectionPlugin((A==null?void 0:A.selection)||void 0)),(A==null?void 0:A.eraser)!==!1&&U.push(ur.createEraserPlugin((A==null?void 0:A.eraser)||void 0)),(A==null?void 0:A.pen)!==!1&&U.push(fr.createPenPlugin()),(A==null?void 0:A.arrows)!==!1&&U.push(ee.createArrowsPlugin((A==null?void 0:A.arrows)||void 0)),(A==null?void 0:A.tapes)!==!1&&U.push(Cv()),U.push(Dm({store:N})),(J=h.editor)!=null&&J.plugins&&U.push(...h.editor.plugins),U}function dn(){const N=h.store??{},U={history:!0,...N};return N.websocket&&(U.websocket={...N.websocket,onVersionMismatch:A=>{var J,D;B.value=!0,(D=(J=N.websocket)==null?void 0:J.onVersionMismatch)==null||D.call(J,A)},onConnectivityChange:A=>{var J,D;v.value=A,(D=(J=N.websocket)==null?void 0:J.onConnectivityChange)==null||D.call(J,A)}}),U}async function cr(N,U){const A=dn();N||(delete A.persistence,delete A.websocket),U&&(A.initialState=U),ce=new Ve.CanvasStore(A);const J={...h.editor,user:y,plugins:$n(ce),controls:h.controls},D=new w.Editor(N,J);return await D.initialize(),await ce.initialize({components:D.components,singletons:D.singletons}),D}async function zn(N){N.nextTick(U=>{ce&&ce.sync(U),Zv(U),eT(U);for(const A of T)A(U)}),await N.tick()}async function Dt(){!g.value||!ce||(await zn(g.value),Be=requestAnimationFrame(Dt))}if(W(w.Camera.name,N=>{N&&(P.value=N)}),h.initialState){const N=([t,o]=a.withAsyncContext(()=>cr(null,h.initialState)),t=await t,o(),t);[t,o]=a.withAsyncContext(()=>zn(N)),await t,o(),[t,o]=a.withAsyncContext(()=>zn(N)),await t,o(),g.value=N}let Lm=null;a.onMounted(async()=>{var J;if(!m.value)return;Lm=()=>{var D;(D=m.value)==null||D.scrollTo(0,0)},m.value.addEventListener("scroll",Lm),g.value&&(g.value.dispose(),ce==null||ce.close(),ce=null,le=0);const N=await cr(m.value,h.initialState);g.value=N,I.value=!1;const A=((J=(h.store??{}).persistence)==null?void 0:J.documentId)??"default";He=new KC({provider:h.assetProvider??new JC,documentId:A}),await He.init(),await He.resumePendingUploads(),Be=requestAnimationFrame(Dt),p("ready",g.value,ce)}),a.onUnmounted(()=>{var N;Be!==null&&cancelAnimationFrame(Be),He==null||He.close(),ce==null||ce.close(),(N=g.value)==null||N.dispose()});function Zv(N){const{events:U,newIndex:A}=N.eventBuffer.readEvents(le);if(le=A,U.length===0)return;const{componentsById:J,singletonsById:D}=w.getResources(N);for(const{entityId:L,eventType:Se,componentId:un}of U){if(L===w.SINGLETON_ENTITY_ID){if(Se===w.EventType.CHANGED){const dt=D.get(un);dt&&G(N,dt)}continue}if(Se===w.EventType.ADDED)k.add(L);else if(Se===w.EventType.REMOVED)k.delete(L),x.delete(L);else if(Se===w.EventType.COMPONENT_ADDED){k.add(L);const dt=J.get(un);dt&&z(N,L,dt)}else if(Se===w.EventType.COMPONENT_REMOVED){const dt=J.get(un);dt&&z(N,L,dt,!0)}else if(Se===w.EventType.CHANGED){const dt=J.get(un);dt&&z(N,L,dt)}}}function eT(N){var J;let U=!1;for(const D of r.added(N)){const L=w.Block.snapshot(N,D),Se=(J=g.value)==null?void 0:J.blockDefs[L.tag],un=(Se==null?void 0:Se.stratum)??"content";E.set(D,a.ref({entityId:D,block:L,stratum:un,selected:!1,held:null,hovered:!1,edited:!1,opacity:null,connector:null})),U=!0}for(const D of r.removed(N))E.delete(D),U=!0;for(const D of r.changed(N)){const L=E.get(D);if(L){const Se=w.Block.snapshot(N,D);L.value.block.rank!==Se.rank&&(U=!0),L.value.block=Se}}let A=!1;for(const D of f.addedOrChanged(N)){const L=w.User.snapshot(N,D);b.set(L.sessionId,L),A=!0}for(const D of f.removed(N)){const L=w.User.read(N,D);b.delete(L.sessionId),A=!0}A&&(S.value=Array.from(b.values()));for(const D of i.added(N)){const L=E.get(D);L&&!L.value.selected&&(L.value.selected=!0)}for(const D of i.removed(N)){const L=E.get(D);L&&L.value.selected&&(L.value.selected=!1)}for(const D of l.addedOrChanged(N)){const L=E.get(D);L&&(L.value.held=w.Held.snapshot(N,D))}for(const D of l.removed(N)){const L=E.get(D);L&&L.value.held!==null&&(L.value.held=null)}for(const D of c.added(N)){const L=E.get(D);L&&!L.value.hovered&&(L.value.hovered=!0)}for(const D of c.removed(N)){const L=E.get(D);L&&L.value.hovered&&(L.value.hovered=!1)}for(const D of d.added(N)){const L=E.get(D);L&&!L.value.edited&&(L.value.edited=!0)}for(const D of d.removed(N)){const L=E.get(D);L&&L.value.edited&&(L.value.edited=!1)}for(const D of u.addedOrChanged(N)){const L=E.get(D);L&&(L.value.opacity=w.Opacity.snapshot(N,D))}for(const D of u.removed(N)){const L=E.get(D);L&&L.value.opacity!==null&&(L.value.opacity=null)}for(const D of s.addedOrChanged(N)){const L=E.get(D);L&&(L.value.connector=w.Connector.snapshot(N,D))}for(const D of s.removed(N)){const L=E.get(D);L&&L.value.connector!==null&&(L.value.connector=null)}if(U){const D=Array.from(E.values());D.sort((L,Se)=>L.value.block.rank>Se.value.block.rank?1:-1),M.value=D}}function tT(N){const U=N.rotateZ!==0,A=N.flip[0],J=N.flip[1];if(!U&&!A&&!J)return;const D=[];return U&&D.push(`rotate(${N.rotateZ}rad)`),A&&D.push("scaleX(-1)"),J&&D.push("scaleY(-1)"),D.join(" ")}function Vm(N){const{held:U}=N;if(!U||!U.sessionId||U.sessionId===y.sessionId)return null;const A=F(U.sessionId);return(A==null?void 0:A.color)??null}function nT(N){const{block:U,stratum:A,opacity:J}=N,D=Vm(N),L=J!==null?J.value/255:1;return{position:"absolute",left:`${U.position[0]}px`,top:`${U.position[1]}px`,width:`${U.size[0]}px`,height:`${U.size[1]}px`,zIndex:w.STRATUM_ORDER[A]*1e3,transform:tT(U),opacity:L,pointerEvents:"none",userSelect:"none","--wov-held-by-color":D??void 0,transition:L===1?"opacity 0ms 32ms":void 0}}return(N,U)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:m,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(bp,{background:n.background},null,8,["background"])]):a.createCommentVNode("",!0),a.createElementVNode("div",{class:"wov-canvas",style:a.normalizeStyle({position:"absolute",transformOrigin:"0 0",transform:`scale(${P.value.zoom}) translate(${-P.value.left}px, ${-P.value.top}px)`,"--wov-zoom":P.value.zoom})},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(M.value,A=>(a.openBlock(),a.createElementBlock("div",{key:A.value.entityId,"data-entity-id":A.value.entityId,style:a.normalizeStyle(nT(A.value)),"data-selected":A.value.selected||void 0,"data-held-by-other":Vm(A.value)!==null||void 0,"data-hovered":A.value.hovered||void 0,class:"wov-block"},[a.renderSlot(N.$slots,`block:${A.value.block.tag}`,a.mergeProps({ref_for:!0},A.value),()=>[A.value.block.tag==="selection-box"?(a.openBlock(),a.createBlock(vv,a.mergeProps({key:0,ref_for:!0},A.value),null,16)):A.value.block.tag==="transform-box"?(a.openBlock(),a.createBlock(Mv,a.mergeProps({key:1,ref_for:!0},A.value),null,16)):A.value.block.tag==="transform-handle"?(a.openBlock(),a.createBlock(Iv,a.mergeProps({key:2,ref_for:!0},A.value),null,16)):A.value.block.tag==="arrow-handle"?(a.openBlock(),a.createBlock(ac,a.mergeProps({key:3,ref_for:!0},A.value),null,16)):A.value.block.tag==="arrow-terminal"?(a.openBlock(),a.createBlock(cc,a.mergeProps({key:4,ref_for:!0},A.value),null,16)):A.value.block.tag==="sticky-note"?(a.openBlock(),a.createBlock(Ov,a.mergeProps({key:5,ref_for:!0},A.value),null,16)):A.value.block.tag==="eraser"?(a.openBlock(),a.createBlock(Mc,a.mergeProps({key:6,ref_for:!0},A.value),null,16)):A.value.block.tag==="pen-stroke"?(a.openBlock(),a.createBlock(Nc,a.mergeProps({key:7,ref_for:!0},A.value),null,16)):A.value.block.tag==="arc-arrow"?(a.openBlock(),a.createBlock(lc,a.mergeProps({key:8,ref_for:!0},A.value),null,16)):A.value.block.tag==="elbow-arrow"?(a.openBlock(),a.createBlock(dc,a.mergeProps({key:9,ref_for:!0},A.value),null,16)):A.value.block.tag==="text"?(a.openBlock(),a.createBlock(zh,a.mergeProps({key:10,ref_for:!0},A.value),null,16)):A.value.block.tag==="image"?(a.openBlock(),a.createBlock(Ac,a.mergeProps({key:11,ref_for:!0},A.value),null,16)):A.value.block.tag==="shape"?(a.openBlock(),a.createBlock(Vh,a.mergeProps({key:12,ref_for:!0},A.value),null,16)):A.value.block.tag==="embed"?(a.openBlock(),a.createBlock(uc,a.mergeProps({key:13,ref_for:!0},A.value),null,16)):A.value.block.tag==="tape"?(a.openBlock(),a.createBlock($h,a.mergeProps({key:14,ref_for:!0},A.value),null,16)):a.createCommentVNode("",!0)])],12,Yv))),128))],4),g.value?a.renderSlot(N.$slots,"user-cursors",{key:1,users:S.value,currentSessionId:a.unref(y).sessionId,camera:P.value},()=>[a.createVNode(Uv,{users:S.value,"current-session-id":a.unref(y).sessionId,camera:P.value},null,8,["users","current-session-id","camera"])]):a.createCommentVNode("",!0),g.value?(a.openBlock(),a.createBlock(Cp,{key:2},{default:a.withCtx(A=>[a.renderSlot(N.$slots,"floating-menu",a.normalizeProps(a.guardReactiveProps(A)))]),_:3})):a.createCommentVNode("",!0),g.value?a.renderSlot(N.$slots,"user-presence",{key:3,users:S.value},()=>[a.createVNode(Vp,{users:S.value},null,8,["users"])]):a.createCommentVNode("",!0),g.value?a.renderSlot(N.$slots,"toolbar",{key:4},()=>[a.createVNode(Lp)]):a.createCommentVNode("",!0),g.value?a.renderSlot(N.$slots,"default",{key:5}):a.createCommentVNode("",!0),a.renderSlot(N.$slots,"offline-indicator",{isOnline:v.value},()=>[a.createVNode(Kv,{"is-online":v.value},null,8,["is-online"])]),a.renderSlot(N.$slots,"version-mismatch",{versionMismatch:B.value},()=>[a.createVNode(Gv,{"version-mismatch":B.value},null,8,["version-mismatch"])]),a.renderSlot(N.$slots,"back-to-content",{},()=>[a.createVNode(Jv)]),a.renderSlot(N.$slots,"loading",{isLoading:I.value},()=>[a.createVNode(Ep,{"is-loading":I.value},null,8,["is-loading"])]),g.value?a.renderSlot(N.$slots,"file-drop-zone",{key:6},()=>[a.createVNode($v)]):a.createCommentVNode("",!0)],512))}}),Qv=a.defineComponent({inheritAttrs:!1,__name:"WovenCanvas",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(a.Suspense,null,{default:a.withCtx(()=>[a.createVNode(Xv,a.normalizeProps(a.guardReactiveProps(e.$attrs)),a.createSlots({_:2},[a.renderList(e.$slots,(o,r)=>({name:r,fn:a.withCtx(s=>[a.renderSlot(e.$slots,r,a.normalizeProps(a.guardReactiveProps(s??{})))])}))]),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=ci,_.ArcArrow=lc,_.ArcArrowTool=TC,_.ArrowHandle=ac,_.ArrowHead=xt,_.ArrowHeadButton=fa,_.ArrowTerminal=cc,_.ArrowThicknessButton=ap,_.CURSORS=vp,_.CanvasBackground=bp,_.ColorButton=up,_.ColorPicker=dp,_.CursorKind=sn,_.EDITING_PLUGIN_NAME=fo,_.EditableText=_s,_.EditingPlugin=Dm,_.ElbowArrow=dc,_.ElbowArrowTool=_p,_.EmbedBlock=uc,_.EmbedTool=Pp,_.Eraser=Mc,_.EraserTool=Bp,_.FloatingMenu=Cp,_.FloatingMenuBar=xp,_.HandTool=Mp,_.IconChevronDown=Ge,_.ImageBlock=Ac,_.ImageTool=Rp,_.LoadingOverlay=Ep,_.MenuButton=Rn,_.MenuDropdown=qe,_.MenuTooltip=ha,_.PenStroke=Nc,_.PenStrokeThicknessButton=fp,_.PenTool=Ip,_.SHAPES=bo,_.SelectTool=Tp,_.ShapeBlock=Vh,_.ShapeFillColorButton=hp,_.ShapeKindButton=pp,_.ShapeStrokeColorButton=mp,_.ShapeTool=Np,_.StickyNoteTool=Ap,_.TapeBlock=$h,_.TapeImageButton=gp,_.TapeTool=Dp,_.TextAlignmentButton=pa,_.TextBlock=zh,_.TextBoldButton=ma,_.TextColorButton=xa,_.TextFontFamilyButton=ya,_.TextFontSizeButton=ka,_.TextItalicButton=wa,_.TextLinkButton=Sa,_.TextTool=Op,_.TextUnderlineButton=ba,_.Toolbar=Lp,_.ToolbarButton=at,_.UserPresence=Vp,_.WovenCanvas=Qv,_.computeCommonComponents=Sp,_.createTooltipContext=Dh,_.getArrowHead=Fn,_.useComponent=pe,_.useComponents=_t,_.useEditorContext=de,_.useFonts=kp,_.useQuery=Ah,_.useSingleton=Me,_.useTextBatchController=Ph,_.useTextEditorController=nr,_.useTextFormatting=rt,_.useTextStretchBehavior=ra,_.useToolbar=Os,_.useTooltipSingleton=Pt,Object.defineProperty(_,Symbol.toStringTag,{value:"Module"})});