@woven-canvas/vue 1.0.2 → 1.0.4

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 +7505 -5572
  33. package/build/index.umd.cjs +32 -28
  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(R,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"),require("@woven-canvas/plugin-tapes")):typeof define=="function"&&define.amd?define(["exports","@woven-ecs/canvas-store","@woven-canvas/plugin-arrows","vue","@woven-canvas/core","@woven-canvas/math","@woven-canvas/plugin-eraser","@woven-canvas/plugin-pen","@woven-canvas/plugin-selection","@woven-canvas/plugin-canvas-controls","@woven-canvas/plugin-tapes"],Ve):(R=typeof globalThis<"u"?globalThis:R||self,Ve(R.Vue={},R.WovenEcsCanvasStore,R.WovenCanvasPluginArrows,R.Vue,R.WovenCanvasCore,R.WovenCanvasMath,R.WovenCanvasPluginEraser,R.WovenCanvasPluginPen,R.WovenCanvasPluginSelection,R.WovenCanvasPluginCanvasControls,R.WovenCanvasPluginTapes))})(this,function(R,Ve,ee,a,b,Pe,qo,Jo,le,Ps,ip){"use strict";const Ds=[{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 On(n){return Ds.find(e=>e.kind===n)}const ia=Symbol.for("__woven_canvas_dropdown_active__"),la=Symbol.for("__woven_canvas_dropdown_level__"),aa=Symbol.for("__woven_canvas_floating_menu__"),_s=Symbol.for("__woven_canvas_toolbar__"),ca=Symbol.for("__woven_canvas_tooltip__"),He=Symbol.for("__woven_canvas__");function pe(n,e){const t=a.inject(He);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();b.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 lp={key:0},ap=["x1","y1","x2","y2","stroke","stroke-width"],cp=["x1","y1","x2","y2","stroke","stroke-width"],dp=["points","fill"],up=["cx","cy","r","fill"],fp=["points","fill"],hp=15,pp=2,wt=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/pp)**.33,d=hp*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",lp,[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,ap),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,cp)],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,dp)):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,up)):n.kind===a.unref(ee.ArrowHeadKind).Diamond&&i.value?(a.openBlock(),a.createElementBlock("polygon",{key:3,points:i.value,fill:n.color},null,8,fp)):a.createCommentVNode("",!0)])):a.createCommentVNode("",!0)}}),mp={class:"arrow-svg",preserveAspectRatio:"none"},gp=["d","stroke","stroke-width"],yp=["x1","y1","x2","y2","stroke","stroke-width"],kp=["d"],wp=["x1","y1","x2","y2"],bp=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,b.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 C=s.value.red.toString(16).padStart(2,"0"),x=s.value.green.toString(16).padStart(2,"0"),S=s.value.blue.toString(16).padStart(2,"0");return`#${C}${x}${S}`}),d=a.computed(()=>{var C;return((C=i.value)==null?void 0:C.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 C=i.value.value,x=Pe.Arc.create(C[0],C[1],C[2],C[3],C[4],C[5],C[6]);return!Pe.Arc.isCollinear(x)}),p=a.computed(()=>{if(!i.value)return null;const C=i.value.value,x=o.value,S=r.value;return Pe.Arc.create(C[0]*x,C[1]*S,C[2]*x,C[3]*S,C[4]*x,C[5]*S,C[6])}),m=a.computed(()=>!p.value||!h.value?null:Pe.Arc.compute(p.value)),g=a.computed(()=>{var z,W,J,K;if(!i.value||!p.value)return null;const C=p.value,x=i.value.startArrowHead,S=i.value.endArrowHead,M=Pe.Arc.length(C);let E=i.value.trimStart;if((z=e.connector)!=null&&z.startBlock&&x!=="none"){const U=((W=On(x))==null?void 0:W.gap)??0,F=M>0?U/M:0;E+=F}let T=i.value.trimEnd;if((J=e.connector)!=null&&J.endBlock&&S!=="none"){const U=((K=On(S))==null?void 0:K.gap)??0,F=M>0?U/M:0;T+=F}const v=1-T,B=Pe.Arc.parametricToPoint(C,E),I=Pe.Arc.parametricToPoint(C,v),D=w(Pe.Arc.directionAt(C,E)),V=Pe.Arc.directionAt(C,v);return{start:B,end:I,startDir:D,endDir:V,tStart:E,tEnd:v,startHead:x,endHead:S}}),y=a.computed(()=>{if(!g.value||!m.value||!h.value)return"";const{start:C,end:x,tStart:S,tEnd:M}=g.value,{radius:E,clockwise:T,arcAngle:v}=m.value,I=v*(M-S)>Math.PI?1:0,D=T?0:1;return`M ${C[0]} ${C[1]} A ${E} ${E} 0 ${I} ${D} ${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 w(C){return[-C[0],-C[1]]}return(C,x)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-arc-arrow"},[(a.openBlock(),a.createElementBlock("svg",mp,[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,gp)):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,yp)):a.createCommentVNode("",!0),g.value?(a.openBlock(),a.createElementBlock(a.Fragment,{key:2},[g.value.startHead!=="none"?(a.openBlock(),a.createBlock(wt,{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(wt,{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,kp)):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,wp)):a.createCommentVNode("",!0),g.value.startHead!=="none"?(a.openBlock(),a.createBlock(wt,{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(wt,{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))}}),sn=(n,e)=>{const t=n.__vccOpts||n;for(const[o,r]of e)t[o]=r;return t},da=sn(bp,[["__scopeId","data-v-bcf5b4f3"]]),Cp={},xp={class:"wov-arrow-handle"};function Sp(n,e){return a.openBlock(),a.createElementBlock("div",xp,[...e[0]||(e[0]=[a.createElementVNode("div",{class:"wov-arrow-handle-inner"},null,-1)])])}const ua=sn(Cp,[["render",Sp]]),Ep={},vp={class:"wov-arrow-terminal"};function Mp(n,e){return a.openBlock(),a.createElementBlock("div",vp,[...e[0]||(e[0]=[a.createElementVNode("div",{class:"wov-arrow-terminal-ring"},[a.createElementVNode("div",{class:"wov-arrow-terminal-fill"})],-1)])])}const fa=sn(Ep,[["render",Mp]]),Tp={class:"arrow-svg",preserveAspectRatio:"none"},Np=["x1","y1","x2","y2"],Ap=["x1","y1","x2","y2","stroke","stroke-width"],Bp=["x1","y1","x2","y2"],ha=sn(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,b.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,w=[];for(let C=0;C<g.pointCount;C++){const x=g.points[C*2]*y,S=g.points[C*2+1]*k;w.push([x,S])}return w}),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,D;if(!i.value||h.value.length<2)return null;const g=i.value,y=[...h.value.map(V=>[...V])],k=g.startArrowHead,w=g.endArrowHead,C=[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 S=g.trimStart;if((v=e.connector)!=null&&v.startBlock&&k!=="none"){const V=Math.hypot(C[0],C[1]),z=((B=On(k))==null?void 0:B.gap)??0,W=V>0?z/V:0;S+=W}let M=g.trimEnd;if((I=e.connector)!=null&&I.endBlock&&w!=="none"){const V=Math.hypot(x[0],x[1]),z=((D=On(w))==null?void 0:D.gap)??0,W=V>0?z/V:0;M+=W}y[0]=[y[0][0]+(y[1][0]-y[0][0])*S,y[0][1]+(y[1][1]-y[0][1])*S];const E=y.length-1;y[E]=[y[E-1][0]+(y[E][0]-y[E-1][0])*(1-M),y[E-1][1]+(y[E][1]-y[E-1][1])*(1-M)];const T=[];for(let V=0;V<y.length-1;V++)T.push({start:y[V],end:y[V+1]});return Pe.Vec2.scale(C,-1),{points:y,lines:T,startPos:y[0],endPos:y[y.length-1],startDir:C,endDir:x,startHead:k,endHead:w}});return(g,y)=>(a.openBlock(),a.createElementBlock("div",{ref_key:"containerRef",ref:t,class:"wov-elbow-arrow"},[(a.openBlock(),a.createElementBlock("svg",Tp,[l.value&&p.value.length>0?(a.openBlock(!0),a.createElementBlock(a.Fragment,{key:0},a.renderList(p.value,(k,w)=>(a.openBlock(),a.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,Np))),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,w)=>(a.openBlock(),a.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,Ap))),128)),m.value.startHead!=="none"?(a.openBlock(),a.createBlock(wt,{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(wt,{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,w)=>(a.openBlock(),a.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,Bp))),128)),m.value.startHead!=="none"?(a.openBlock(),a.createBlock(wt,{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(wt,{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"]]),Ip={class:"wov-embed-block"},Op={key:0,class:"wov-embed-placeholder"},Rp=["src","allow"],pa=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,b.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 b.EmbedProvider.Youtube:return"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture";case b.EmbedProvider.Spotify:return"autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture";case b.EmbedProvider.GoogleMaps:return"fullscreen";case b.EmbedProvider.GoogleCalendar:return"fullscreen";case b.EmbedProvider.GoogleSlides:return"fullscreen";case b.EmbedProvider.Figma:return"fullscreen";default:return"fullscreen"}}),s=a.computed(()=>{if(!t.value)return"Embed";switch(t.value.provider){case b.EmbedProvider.Youtube:return"YouTube";case b.EmbedProvider.Spotify:return"Spotify";case b.EmbedProvider.GoogleMaps:return"Google Maps";case b.EmbedProvider.GoogleCalendar:return"Google Calendar";case b.EmbedProvider.GoogleSlides:return"Google Slides";case b.EmbedProvider.Figma:return"Figma";case b.EmbedProvider.GithubGist:return"GitHub Gist";case b.EmbedProvider.Tldraw:return"tldraw";default:return"Embed"}});return(i,l)=>(a.openBlock(),a.createElementBlock("div",Ip,[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,Rp)):(a.openBlock(),a.createElementBlock("div",Op,[a.createElementVNode("span",null,a.toDisplayString(s.value),1)]))]))}}),{PI:Pp}=Math,oo=Pp+1e-4,ma=.5,ga=[1,1];function ya(n,e,t,o=r=>r){return n*o(.5-e*(.5-t))}const{min:Ls}=Math;function ka(n,e,t){let o=Ls(1,e/t);return Ls(1,n+(Ls(1,1-o)-n)*(o*.275))}function Dp(n){return[-n[0],-n[1]]}function ct(n,e){return[n[0]+e[0],n[1]+e[1]]}function wa(n,e,t){return n[0]=e[0]+t[0],n[1]=e[1]+t[1],n}function Pt(n,e){return[n[0]-e[0],n[1]-e[1]]}function Vs(n,e,t){return n[0]=e[0]-t[0],n[1]=e[1]-t[1],n}function Dt(n,e){return[n[0]*e,n[1]*e]}function $s(n,e,t){return n[0]=e[0]*t,n[1]=e[1]*t,n}function _p(n,e){return[n[0]/e,n[1]/e]}function ba(n){return[n[1],-n[0]]}function zs(n,e){let t=e[0];return n[0]=e[1],n[1]=-t,n}function Ca(n,e){return n[0]*e[0]+n[1]*e[1]}function Lp(n,e){return n[0]===e[0]&&n[1]===e[1]}function Vp(n){return Math.hypot(n[0],n[1])}function xa(n,e){let t=n[0]-e[0],o=n[1]-e[1];return t*t+o*o}function Sa(n){return _p(n,Vp(n))}function $p(n,e){return Math.hypot(n[1]-e[1],n[0]-e[0])}function Fs(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 Ea(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 va(n,e,t){return ct(n,Dt(Pt(e,n),t))}function zp(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 Ma(n,e,t){return ct(n,Dt(e,t))}const xe=[0,0],_t=[0,0],Lt=[0,0];function Fp(n,e){let t=Ma(n,Sa(ba(Pt(n,ct(n,[1,1])))),-e),o=[],r=1/13;for(let s=r;s<=1;s+=r)o.push(Fs(t,n,oo*2*s));return o}function Hp(n,e,t){let o=[],r=1/t;for(let s=r;s<=1;s+=r)o.push(Fs(e,n,oo*s));return o}function Up(n,e,t){let o=Pt(e,t),r=Dt(o,.5),s=Dt(o,.51);return[Pt(n,r),Pt(n,s),ct(n,s),ct(n,r)]}function jp(n,e,t,o){let r=[],s=Ma(n,e,t),i=1/o;for(let l=i;l<1;l+=i)r.push(Fs(s,n,oo*3*l));return r}function Wp(n,e,t){return[ct(n,Dt(e,t)),ct(n,Dt(e,t*.99)),Pt(n,Dt(e,t*.99)),Pt(n,Dt(e,t))]}function Ta(n,e,t){return n===!1||n===void 0?0:n===!0?Math.max(e,t):n}function Kp(n,e,t){return n.slice(0,10).reduce((o,r)=>{let s=r.pressure;return e&&(s=ka(o,r.distance,t)),(o+s)/2},n[0].pressure)}function qp(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=Ta(l.taper,t,m),y=Ta(c.taper,t,m),k=(t*o)**2,w=[],C=[],x=Kp(n,s,t),S=ya(t,r,n[n.length-1].pressure,i),M,E=n[0].vector,T=n[0].point,v=T,B=T,I=v,D=!1;for(let K=0;K<n.length;K++){let{pressure:U}=n[K],{point:F,vector:X,distance:oe,runningLength:ie}=n[K],Be=K===n.length-1;if(!Be&&m-ie<3)continue;r?(s&&(U=ka(x,oe,t)),S=ya(t,r,U,i)):S=t/2,M===void 0&&(M=S);let ce=ie<g?f(ie/g):1,Fe=m-ie<y?p((m-ie)/y):1;S=Math.max(.01,S*Math.min(ce,Fe));let Bn=(Be?n[K]:n[K+1]).vector,on=Be?1:Ca(X,Bn),Wo=Ca(X,E)<0&&!D,In=on!==null&&on<0;if(Wo||In){zs(xe,E),$s(xe,xe,S);for(let Rt=0;Rt<=1;Rt+=.07692307692307693)Vs(_t,F,xe),Ea(_t,_t,F,oo*Rt),B=[_t[0],_t[1]],w.push(B),wa(Lt,F,xe),Ea(Lt,Lt,F,oo*-Rt),I=[Lt[0],Lt[1]],C.push(I);T=B,v=I,In&&(D=!0);continue}if(D=!1,Be){zs(xe,X),$s(xe,xe,S),w.push(Pt(F,xe)),C.push(ct(F,xe));continue}zp(xe,Bn,X,on),zs(xe,xe),$s(xe,xe,S),Vs(_t,F,xe),B=[_t[0],_t[1]],(K<=1||xa(T,B)>k)&&(w.push(B),T=B),wa(Lt,F,xe),I=[Lt[0],Lt[1]],(K<=1||xa(v,I)>k)&&(C.push(I),v=I),x=U,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]]:ct(n[0].point,[1,1]),W=[],J=[];if(n.length===1){if(!(g||y)||d)return Fp(V,M||S)}else{g||y&&n.length===1||(u?W.push(...Hp(V,C[0],13)):W.push(...Up(V,w[0],C[0])));let K=ba(Dp(n[n.length-1].vector));y||g&&n.length===1?J.push(z):h?J.push(...jp(z,K,S,29)):J.push(...Wp(z,K,S))}return w.concat(J,C.reverse(),W)}const Na=[0,0];function Aa(n){return n!=null&&n>=0}function Jp(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=ma})=>[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(va(i[0],p,m/4))}i.length===1&&(i=[...i,[...ct(i[0],ga),...i[0].slice(2)]]);let l=[{point:[i[0][0],i[0][1]],pressure:Aa(i[0][2])?i[0][2]:.25,vector:[...ga],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]]:va(u.point,i[p],s);if(Lp(u.point,m))continue;let g=$p(m,u.point);if(d+=g,p<f&&!c){if(d<o)continue;c=!0}Vs(Na,u.point,m),u={point:m,pressure:Aa(i[p][2])?i[p][2]:ma,vector:Sa(Na),distance:g,runningLength:d},l.push(u)}return l[0].vector=((h=l[1])==null?void 0:h.vector)||[0,0],l}function Hs(n,e={}){return qp(Jp(n,e),e)}const Gp={class:"wov-eraser-stroke"},Yp={preserveAspectRatio:"none"},Xp=["d"],Qp="#88888833",Ba=a.defineComponent({__name:"Eraser",props:{entityId:{}},setup(n){const e=n,t=pe(e.entityId,qo.EraserStroke),o=pe(e.entityId,b.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,qo.POINTS_CAPACITY);for(let x=0;x<m;x++){const S=(c+x)%qo.POINTS_CAPACITY*2;p.push([d[S]-f,d[S+1]-h])}const g=Hs(p,{size:u,start:{taper:66,cap:!0}});if(g.length<3)return"";let y=g[0],k=g[1];const w=g[2];let C=`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 x=2;x<g.length-1;x++)y=g[x],k=g[x+1],C+=`${s(y[0],k[0]).toFixed(2)},${s(y[1],k[1]).toFixed(2)} `;return C+=`${k[0].toFixed(2)},${k[1].toFixed(2)} `,C+="Z",C}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",Gp,[(a.openBlock(),a.createElementBlock("svg",Yp,[a.createElementVNode("path",{d:r.value,fill:Qp},null,8,Xp)]))]))}}),Zp={class:"wov-image-block"},em={key:0,class:"wov-image-placeholder"},tm={key:1,class:"wov-image-placeholder wov-image-error"},nm=["src","alt"],om={key:3,class:"wov-image-upload-overlay"},rm={class:"wov-image-upload-status"},Ia=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(He);if(!t)throw new Error("ImageBlock must be used within a WovenCanvas component");const o=t,r=pe(e.entityId,b.Asset),s=pe(e.entityId,b.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===b.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 b.UploadState.Pending:return"Loading...";case b.UploadState.Uploading:return"Loading...";case b.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",Zp,[l.value&&!i.value?(a.openBlock(),a.createElementBlock("div",em,[...m[0]||(m[0]=[a.createElementVNode("span",null,"Loading...",-1)])])):c.value?(a.openBlock(),a.createElementBlock("div",tm,[...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,nm)):a.createCommentVNode("",!0),f.value?(a.openBlock(),a.createElementBlock("div",om,[a.createElementVNode("span",rm,a.toDisplayString(f.value),1)])):a.createCommentVNode("",!0)])}}}),sm=["data-complete"],im={preserveAspectRatio:"none"},lm=["d","fill"],am={key:0,class:"highlight",preserveAspectRatio:"none"},cm=["d"],Oa=sn(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,Jo.PenStroke),o=pe(e.entityId,b.Block),r=pe(e.entityId,b.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 w=p/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}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 w=f.points[k*2],C=f.points[k*2+1],x=(w-f.originalLeft)*p,S=(C-f.originalTop)*m;f.hasPressure?g.push([x,S,f.pressures[k]]):g.push([x,S])}const y=Hs(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,w=Hs(g,{last:!0,size:k,simulatePressure:!f.hasPressure});i.value=c(w,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",im,[a.createElementVNode("path",{d:s.value,fill:d.value},null,8,lm)])),u.value?(a.openBlock(),a.createElementBlock("svg",am,[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,cm)])):a.createCommentVNode("",!0)],8,sm)}}}),[["__scopeId","data-v-9b41c649"]]);function de(){const n=a.inject(He);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 ro={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 Se(n){this.content=n}Se.prototype={constructor:Se,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 Se(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 Se(t)},addToStart:function(n,e){return new Se([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new Se(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 Se(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=Se.from(n),n.size?new Se(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=Se.from(n),n.size?new Se(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=Se.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}},Se.from=function(n){if(n instanceof Se)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new Se(e)};function Ra(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=Ra(r.content,s.content,t+1);if(i!=null)return i}t+=r.nodeSize}}function Pa(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=Pa(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 Ra(this,e,t)}findDiffEnd(e,t=this.size,o=e.size){return Pa(this,e,t,o)}findIndex(e){if(e==0)return Go(0,e);if(e==this.size)return Go(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?Go(t+1,s):Go(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 Us={index:0,offset:0};function Go(n,e){return Us.index=n,Us.offset=e,Us}function Yo(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(!Yo(n[o],e[o]))return!1}else{for(let o in n)if(!(o in e)||!Yo(n[o],e[o]))return!1;for(let o in e)if(!(o in n))return!1}return!0}let te=class oa{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&&Yo(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 oa.none;if(e instanceof oa)return[e];let t=e.slice();return t.sort((o,r)=>o.type.rank-r.type.rank),t}};te.none=[];class Xo 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=_a(this.content,e+this.openStart,t);return o&&new $(o,this.openStart,this.openEnd)}removeBetween(e,t){return new $(Da(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 Da(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(Da(s.content,e-r-1,t-r-1)))}function _a(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=_a(i.content,e-s-1,t,i);return l&&n.replaceChild(r,i.copy(l))}function dm(n,e,t){if(t.openStart>n.depth)throw new Xo("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Xo("Inconsistent open depths");return La(n,e,t,0)}function La(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=La(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 an(i,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:i,end:l}=um(t,n);return an(s,$a(n,i,l,e,o))}else return an(s,Qo(n,e,o))}function Va(n,e){if(!e.type.compatibleContent(n.type))throw new Xo("Cannot join "+e.type.name+" onto "+n.type.name)}function js(n,e,t){let o=n.node(t);return Va(o,e.node(t)),o}function ln(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&&(ln(n.nodeAfter,o),s++));for(let l=s;l<i;l++)ln(r.child(l),o);e&&e.depth==t&&e.textOffset&&ln(e.nodeBefore,o)}function an(n,e){return n.type.checkContent(e),n.copy(e)}function $a(n,e,t,o,r){let s=n.depth>r&&js(n,e,r+1),i=o.depth>r&&js(t,o,r+1),l=[];return so(null,n,r,l),s&&i&&e.index(r)==t.index(r)?(Va(s,i),ln(an(s,$a(n,e,t,o,r+1)),l)):(s&&ln(an(s,Qo(n,e,r+1)),l),so(e,t,r,l),i&&ln(an(i,Qo(t,o,r+1)),l)),so(o,null,r,l),new O(l)}function Qo(n,e,t){let o=[];if(so(null,n,t,o),n.depth>t){let r=js(n,e,t+1);ln(an(r,Qo(n,e,t+1)),o)}return so(e,null,t,o),new O(o)}function um(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 io{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 Zo(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 io(t,o,s)}static resolveCached(e,t){let o=za.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 za.set(e,o=new fm);let r=o.elts[o.i]=io.resolve(e,t);return o.i=(o.i+1)%hm,r}}class fm{constructor(){this.elts=[],this.i=0}}const hm=12,za=new WeakMap;class Zo{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 pm=Object.create(null);let bt=class ra{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&&Yo(this.attrs,t||e.defaultAttrs||pm)&&te.sameSet(this.marks,o||te.none)}copy(e=null){return e==this.content?this:new ra(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new ra(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 dm(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 io.resolveCached(this,e)}resolveNoCache(e){return io.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()+")"),Fa(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}};bt.prototype.text=void 0;class er extends bt{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):Fa(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 er(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new er(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 Fa(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}class cn{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let o=new mm(e,t);if(o.next==null)return cn.empty;let r=Ha(o);o.next&&o.err("Unexpected trailing text");let s=xm(Cm(r));return Sm(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
+ `)}}cn.empty=new cn(!0);class mm{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 Ha(n){let e=[];do e.push(gm(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function gm(n){let e=[];do e.push(ym(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function ym(n){let e=bm(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=km(n,e);else break;return e}function Ua(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function km(n,e){let t=Ua(n),o=t;return n.eat(",")&&(n.next!="}"?o=Ua(n):o=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:o,expr:e}}function wm(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 bm(n){if(n.eat("(")){let e=Ha(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=wm(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 Cm(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 ja(n,e){return e-n}function Wa(n,e){let t=[];return o(e),t.sort(ja);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 xm(n){let e=Object.create(null);return t(Wa(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]);Wa(n,c).forEach(u=>{d||r.push([l,d=[]]),d.indexOf(u)==-1&&d.push(u)})})});let s=e[o.join(",")]=new cn(o.indexOf(n.length-1)>-1);for(let i=0;i<r.length;i++){let l=r[i][1].sort(ja);s.next.push({type:r[i][0],next:e[l.join(",")]||t(l)})}return s}}function Sm(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 Ka(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 qa(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 Ja(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 Ga(n,e){let t=Object.create(null);if(e)for(let o in e)t[o]=new vm(n,o,e[o]);return t}let Ya=class tp{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=Ga(e,o.attrs),this.defaultAttrs=Ka(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==cn.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:qa(this.attrs,e)}create(e=null,t,o){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new bt(this,this.computeAttrs(e),O.from(t),te.setFrom(o))}createChecked(e=null,t,o){return t=O.from(t),this.checkContent(t),new bt(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 bt(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){Ja(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 tp(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 Em(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 vm{constructor(e,t,o){this.hasDefault=Object.prototype.hasOwnProperty.call(o,"default"),this.default=o.default,this.validate=typeof o.validate=="string"?Em(e,t,o.validate):o.validate}get isRequired(){return!this.hasDefault}}class tr{constructor(e,t,o,r){this.name=e,this.rank=t,this.schema=o,this.spec=r,this.attrs=Ga(e,r.attrs),this.excluded=null;let s=Ka(this.attrs);this.instance=s?new te(this,s):null}create(e=null){return!e&&this.instance?this.instance:new te(this,qa(this.attrs,e))}static compile(e,t){let o=Object.create(null),r=0;return e.forEach((s,i)=>o[s]=new tr(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){Ja(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class Xa{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=Se.from(e.nodes),t.marks=Se.from(e.marks||{}),this.nodes=Ya.compile(this.spec.nodes,this),this.marks=tr.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]=cn.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?Qa(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==""?[]:Qa(this,i.split(" "))}this.nodeFromJSON=r=>bt.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 Ya){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 er(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 Qa(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 Mm(n){return n.tag!=null}function Tm(n){return n.style!=null}let Rn=class sa{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let o=this.matchedStyles=[];t.forEach(r=>{if(Mm(r))this.tags.push(r);else if(Tm(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 nc(this,t,!1);return o.addAll(e,te.none,t.from,t.to),o.finish()}parseSlice(e,t={}){let o=new nc(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(Bm(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=oc(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=oc(i)),i.node||i.ignore||i.mark||(i.node=r)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new sa(e,sa.schemaRules(e)))}};const Za={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},Nm={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ec={ol:!0,ul:!0},lo=1,Ws=2,ao=4;function tc(n,e,t){return e!=null?(e?lo:0)|(e==="full"?Ws:0):n&&n.whitespace=="pre"?lo|Ws:t&~ao}class nr{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&ao?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&lo)){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&&!Za.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class nc{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=tc(null,t.preserveWhitespace,0)|(o?ao:0);r?s=new nr(r.type,r.attrs,te.none,!0,t.topMatch||r.type.contentMatch,i):o?s=new nr(null,null,te.none,!0,null,i):s=new nr(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&Ws?"full":this.localPreserveWS||(r.options&lo)>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;ec.hasOwnProperty(i)&&this.parser.normalizeLists&&Am(e);let c=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(l=this.parser.matchTag(e,this,o));e:if(c?c.ignore:Nm.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(Za.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):rc(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=tc(e,s,i.options);i.options&ao&&i.content.length==0&&(l|=ao);let c=te.none;return o=o.filter(d=>(i.type?i.type.allowsMarkType(d.type):rc(d.type,e))?(c=d.addToSet(c),!1):!0),this.nodes.push(new nr(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|=lo)}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 Am(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let o=e.nodeType==1?e.nodeName.toLowerCase():null;o&&ec.hasOwnProperty(o)&&t?(t.appendChild(e),e=t):o=="li"?t=e:o&&(t=null)}}function Bm(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function oc(n){let e={};for(let t in n)e[t]=n[t];return e}function rc(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 dn{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},o){o||(o=Ks(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}=or(Ks(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&&or(Ks(o),r(e,t),null,e.attrs)}static renderSpec(e,t,o=null,r){return or(e,t,o,r)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new dn(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=sc(e.nodes);return t.text||(t.text=o=>o.text),t}static marksFromSchema(e){return sc(e.marks)}}function sc(n){let e={};for(let t in n){let o=n[t].spec.toDOM;o&&(e[t]=o)}return e}function Ks(n){return n.document||window.document}const ic=new WeakMap;function Im(n){let e=ic.get(n);return e===void 0&&ic.set(n,e=Om(n)),e}function Om(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 or(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=Im(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}=or(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 lc=65535,ac=Math.pow(2,16);function Rm(n,e){return n+e*ac}function cc(n){return n&lc}function Pm(n){return(n-(n&lc))/ac}const dc=1,uc=2,rr=4,fc=8;class qs{constructor(e,t,o){this.pos=e,this.delInfo=t,this.recover=o}get deleted(){return(this.delInfo&fc)>0}get deletedBefore(){return(this.delInfo&(dc|rr))>0}get deletedAfter(){return(this.delInfo&(uc|rr))>0}get deletedAcross(){return(this.delInfo&rr)>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=cc(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+Pm(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:Rm(l/3,e-c),g=e==c?uc:e==f?dc:rr;return(t<0?e!=c:e!=f)&&(g|=fc),new qs(p,g,m)}r+=u-d}return o?e+r:new qs(e+r,0,null)}touches(e,t){let o=0,r=cc(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 co{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 co(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 co;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 qs(e,r,null)}}const Js=Object.create(null);class Ie{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=Js[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 Js)throw new RangeError("Duplicate use of step JSON ID "+e);return Js[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 Xo)return me.fail(s.message);throw s}}}function Gs(n,e,t){let o=[];for(let r=0;r<n.childCount;r++){let s=n.child(r);s.content.size&&(s=s.copy(Gs(s.content,e,s))),s.isInline&&(s=e(s,t,r)),o.push(s)}return O.fromArray(o)}class Vt extends Ie{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 $(Gs(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 et(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 Vt(t.pos,o.pos,this.mark)}merge(e){return e instanceof Vt&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Vt(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 Vt(t.from,t.to,e.markFromJSON(t.mark))}}Ie.jsonID("addMark",Vt);class et extends Ie{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 $(Gs(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 Vt(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 et(t.pos,o.pos,this.mark)}merge(e){return e instanceof et&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new et(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 et(t.from,t.to,e.markFromJSON(t.mark))}}Ie.jsonID("removeMark",et);class $t extends Ie{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 $t(this.pos,t.marks[r]);return new $t(this.pos,this.mark)}}return new un(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new $t(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 $t(t.pos,e.markFromJSON(t.mark))}}Ie.jsonID("addNodeMark",$t);class un extends Ie{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 $t(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new un(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 un(t.pos,e.markFromJSON(t.mark))}}Ie.jsonID("removeNodeMark",un);class ge extends Ie{constructor(e,t,o,r=!1){super(),this.from=e,this.to=t,this.slice=o,this.structure=r}apply(e){return this.structure&&Ys(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)}}Ie.jsonID("replace",ge);class ye extends Ie{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&&(Ys(e,this.from,this.gapFrom)||Ys(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)}}Ie.jsonID("replaceAround",ye);function Ys(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 Dm(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 et(h,p,f[g])));l&&l.to==h?l.to=p:s.push(l=new Vt(h,p,o))}}),r.forEach(c=>n.step(c)),s.forEach(c=>n.step(c))}function _m(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 tr){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 et(i.from,i.to,i.style)))}function Xs(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 et(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 Lm(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function Pn(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||!Lm(i,l,c))break;l&&(r=1),c<i.childCount&&(s=1)}return null}function Vm(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 hc(n,e,t=null,o=n){let r=$m(n,e),s=r&&zm(o,e);return s?r.map(pc).concat({type:e,attrs:t}).concat(s.map(pc)):null}function pc(n){return{type:n,attrs:null}}function $m(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 zm(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 Fm(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 Hm(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)&&Um(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&&gc(n,i,l,s),Xs(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&&mc(n,i,l,s),!1}})}function mc(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 gc(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 Um(n,e,t){let o=n.resolve(e),r=o.index();return o.parent.canReplaceWith(r,r+1,t)}function jm(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 Ct(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 Wm(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 fn(n,e){let t=n.resolve(e),o=t.index();return yc(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(o,o+1)}function Km(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 yc(n,e){return!!(n&&e&&!n.isLeaf&&Km(n,e))}function sr(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&&yc(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 qm(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);gc(n,u.node(),u.before(),l)}i.inlineContent&&Xs(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);mc(n,u.node(),u.before(),n.steps.length)}return n}function Jm(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 kc(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 ir(n,e,t=e,o=$.empty){if(e==t&&!o.size)return null;let r=n.resolve(e),s=n.resolve(t);return wc(r,s,o)?new ge(e,t,o):new Gm(r,s,o).fit()}function wc(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}class Gm{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=Qs(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=Qs(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=Qs(e,t);if(r.childCount<=1&&t>0){let s=e.size-t<=t+r.size;this.unplaced=new $(uo(e,t-1,1),t-1,s?t-1:o)}else this.unplaced=new $(uo(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(bc(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=fo(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 $(uo(i.content,e-1,1),e-1,p<0?i.openEnd:e-1):new $(uo(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||!Zs(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=Zs(e,t,r,o,s);if(i){for(let l=t-1;l>=0;l--){let{match:c,type:d}=this.frontier[l],u=Zs(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=fo(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=fo(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=fo(this.placed,this.frontier.length,t))}}function uo(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(uo(n.firstChild.content,e-1,t)))}function fo(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(fo(n.lastChild.content,e-1,t)))}function Qs(n,e){for(let t=0;t<e;t++)n=n.firstChild.content;return n}function bc(n,e,t){if(e<=0)return n;let o=n.content;return e>1&&(o=o.replaceChild(0,bc(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 Zs(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&&!Ym(t,s.content,i)?l:null}function Ym(n,e,t){for(let o=t;o<e.childCount;o++)if(!n.allowsMarks(e.child(o).marks))return!0;return!1}function Xm(n){return n.spec.defining||n.spec.definingForContent}function Qm(n,e,t,o){if(!o.size)return n.deleteRange(e,t);let r=n.doc.resolve(e),s=n.doc.resolve(t);if(wc(r,s,o))return n.step(new ge(e,t,o));let i=xc(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=Xm(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 w=r.node(y-1),C=r.index(y-1);if(w.canReplaceWith(C,C,m.type,m.marks))return n.replace(r.before(y),k?s.after(y):t,new $(Cc(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 Cc(n,e,t,o,r){if(e<t){let s=n.firstChild;n=n.replaceChild(0,s.copy(Cc(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 Zm(n,e,t,o){if(!o.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let r=Jm(n.doc,e,o.type);r!=null&&(e=t=r)}n.replaceRange(e,t,new $(O.from(o),0,0))}function eg(n,e,t){let o=n.doc.resolve(e),r=n.doc.resolve(t),s=xc(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 xc(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 Dn extends Ie{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 Dn(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 Dn(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 Dn(t.pos,t.attr,t.value)}}Ie.jsonID("attr",Dn);class ho extends Ie{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 ho(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 ho(t.attr,t.value)}}Ie.jsonID("docAttr",ho);let _n=class extends Error{};_n=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t},_n.prototype=Object.create(Error.prototype),_n.prototype.constructor=_n,_n.prototype.name="TransformError";class Sc{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new co}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new _n(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=ir(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 Qm(this,e,t,o),this}replaceRangeWith(e,t,o){return Zm(this,e,t,o),this}deleteRange(e,t){return eg(this,e,t),this}lift(e,t){return Vm(this,e,t),this}join(e,t=1){return qm(this,e,t),this}wrap(e,t){return Fm(this,e,t),this}setBlockType(e,t=e,o,r=null){return Hm(this,e,t,o,r),this}setNodeMarkup(e,t,o=null,r){return jm(this,e,t,o,r),this}setNodeAttribute(e,t,o){return this.step(new Dn(e,t,o)),this}setDocAttribute(e,t){return this.step(new ho(e,t)),this}addNodeMark(e,t){return this.step(new $t(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 un(e,t));else{let r=o.marks,s,i=[];for(;s=t.isInSet(r);)i.push(new un(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 Wm(this,e,t,o),this}addMark(e,t,o){return Dm(this,e,t,o),this}removeMark(e,t,o){return _m(this,e,t,o),this}clearIncompatible(e,t,o){return Xs(this,e,t,o),this}}const ei=Object.create(null);class Z{constructor(e,t,o){this.$anchor=e,this.$head=t,this.ranges=o||[new tg(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&&Mc(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),Mc(e,o,t.isInline?-1:1))}}static findFrom(e,t,o=!1){let r=e.parent.inlineContent?new Y(e):Ln(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?Ln(e.node(0),e.node(s),e.before(s+1),e.index(s),t,o):Ln(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 je(e.node(0))}static atStart(e){return Ln(e,e,0,0,1)||new je(e)}static atEnd(e){return Ln(e,e,e.content.size,e.childCount,-1)||new je(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let o=ei[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 ei)throw new RangeError("Duplicate use of selection JSON ID "+e);return ei[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Y.between(this.$anchor,this.$head).getBookmark()}}Z.prototype.visible=!0;class tg{constructor(e,t){this.$from=e,this.$to=t}}let Ec=!1;function vc(n){!Ec&&!n.parent.inlineContent&&(Ec=!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){vc(e),vc(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 lr(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 lr{constructor(e,t){this.anchor=e,this.head=t}map(e){return new lr(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 ti(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 ti{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:o}=e.mapResult(this.anchor);return t?new lr(o,o):new ti(o)}resolve(e){let t=e.resolve(this.anchor),o=t.nodeAfter;return o&&q.isSelectable(o)?new q(t):Z.near(t)}}class je 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 je(e)}map(e){return new je(e)}eq(e){return e instanceof je}getBookmark(){return ng}}Z.jsonID("all",je);const ng={map(){return this},resolve(n){return new je(n)}};function Ln(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=Ln(n,l,t+r,r<0?l.childCount:0,r,s);if(c)return c}t+=l.nodeSize*r}return null}function Mc(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 Tc=1,ar=2,Nc=4;class og extends Sc{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|Tc)&~ar,this.storedMarks=null,this}get selectionSet(){return(this.updated&Tc)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=ar,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&ar)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~ar,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|=Nc,this}get scrolledIntoView(){return(this.updated&Nc)>0}}function Ac(n,e){return!e||!n?n:n.bind(e)}class po{constructor(e,t,o){this.name=e,this.init=Ac(t.init,o),this.apply=Ac(t.apply,o)}}const rg=[new po("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new po("selection",{init(n,e){return n.selection||Z.atStart(e.doc)},apply(n){return n.selection}}),new po("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,o){return o.selection.$cursor?n.storedMarks:null}}),new po("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];class ni{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=rg.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 po(o.key,o.spec.state,o))})}}class Vn{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 Vn(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 og(this)}static create(e){let t=new ni(e.doc?e.doc.type.schema:e.schema,e.plugins),o=new Vn(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 ni(this.schema,e.plugins),o=t.fields,r=new Vn(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 ni(e.schema,e.plugins),s=new Vn(r);return r.fields.forEach(i=>{if(i.name=="doc")s.doc=bt.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 Bc(n,e,t){for(let o in n){let r=n[o];r instanceof Function?r=r.bind(e):o=="handleDOMEvents"&&(r=Bc(r,e,{})),t[o]=r}return t}class ue{constructor(e){this.spec=e,this.props={},e.props&&Bc(e.props,this,this.props),this.key=e.key?e.key.key:Ic("plugin")}getState(e){return e[this.key]}}const oi=Object.create(null);function Ic(n){return n in oi?n+"$"+ ++oi[n]:(oi[n]=0,n+"$")}class ke{constructor(e="key"){this.key=Ic(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}const ri=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Oc(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}const Rc=(n,e,t)=>{let o=Oc(n,t);if(!o)return!1;let r=si(o);if(!r){let i=o.blockRange(),l=i&&Pn(i);return l==null?!1:(e&&e(n.tr.lift(i,l).scrollIntoView()),!0)}let s=r.nodeBefore;if(Hc(n,r,e,-1))return!0;if(o.parent.content.size==0&&($n(s,"end")||q.isSelectable(s)))for(let i=o.depth;;i--){let l=ir(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($n(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},sg=(n,e,t)=>{let o=Oc(n,t);if(!o)return!1;let r=si(o);return r?Pc(n,r,e):!1},ig=(n,e,t)=>{let o=_c(n,t);if(!o)return!1;let r=ii(o);return r?Pc(n,r,e):!1};function Pc(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=ir(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 $n(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 Dc=(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=si(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 si(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 _c(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}const Lc=(n,e,t)=>{let o=_c(n,t);if(!o)return!1;let r=ii(o);if(!r)return!1;let s=r.nodeAfter;if(Hc(n,r,e,1))return!0;if(o.parent.content.size==0&&($n(s,"start")||q.isSelectable(s))){let i=ir(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($n(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},Vc=(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=ii(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 ii(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 lg=(n,e)=>{let t=n.selection,o=t instanceof q,r;if(o){if(t.node.isTextblock||!fn(n.doc,t.from))return!1;r=t.from}else if(r=sr(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},ag=(n,e)=>{let t=n.selection,o;if(t instanceof q){if(t.node.isTextblock||!fn(n.doc,t.to))return!1;o=t.to}else if(o=sr(n.doc,t.to,1),o==null)return!1;return e&&e(n.tr.join(o).scrollIntoView()),!0},cg=(n,e)=>{let{$from:t,$to:o}=n.selection,r=t.blockRange(o),s=r&&Pn(r);return s==null?!1:(e&&e(n.tr.lift(r,s).scrollIntoView()),!0)},$c=(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 li(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 dg=(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=li(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},zc=(n,e)=>{let t=n.selection,{$from:o,$to:r}=t;if(t instanceof je||o.parent.inlineContent||r.parent.inlineContent)return!1;let s=li(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},Fc=(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(Ct(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let o=t.blockRange(),r=o&&Pn(o);return r==null?!1:(e&&e(n.tr.lift(o,r).scrollIntoView()),!0)};function ug(n){return(e,t)=>{let{$from:o,$to:r}=e.selection;if(e.selection instanceof q&&e.selection.node.isBlock)return!o.parentOffset||!Ct(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=li(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 je)&&u.deleteSelection();let f=u.mapping.map(o.pos),h=Ct(u.doc,f,s.length,s);if(h||(s[0]=l?{type:l}:null,h=Ct(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 fg=ug(),hg=(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 pg(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||fn(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Hc(n,e,t,o){let r=e.nodeBefore,s=e.nodeAfter,i,l,c=r.type.spec.isolating||s.type.spec.isolating;if(!c&&pg(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&&fn(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&&Pn(f);if(h!=null&&h>=e.depth)return t&&t(n.tr.lift(f,h).scrollIntoView()),!0;if(d&&$n(s,"start",!0)&&$n(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 C=m.length-1;C>=0;C--)k=O.from(m[C].copy(k));let w=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(w.scrollIntoView())}return!0}}return!1}function Uc(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 mg=Uc(-1),gg=Uc(1);function yg(n,e=null){return function(t,o){let{$from:r,$to:s}=t.selection,i=r.blockRange(s),l=i&&hc(i,n,e);return l?(o&&o(t.tr.wrap(i,l).scrollIntoView()),!0):!1}}function jc(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 ai(...n){return function(e,t,o){for(let r=0;r<n.length;r++)if(n[r](e,t,o))return!0;return!1}}ai(ri,Rc,Dc),ai(ri,Lc,Vc),ai($c,zc,Fc,fg),typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform&&os.platform()=="darwin";function kg(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 wg(l,i,n,e)?(o&&o(l.scrollIntoView()),!0):!1}}function wg(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 Zo(c,c,e.depth),e.endIndex<e.parent.childCount&&(e=new Zo(e.$from,i.resolve(e.$to.end(e.depth)),e.depth)),r=!0}let l=hc(s,t,o,e);return l?(n&&bg(n,e,l,r,t),!0):!1}function bg(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&&Ct(n.doc,c,l)&&(n.split(c,l),c+=2*l),c+=d.child(u).nodeSize;return n}function Cg(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?xg(e,t,n,s):Sg(e,t,s):!0:!1}}function xg(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 Zo(r.doc.resolve(o.$from.pos),r.doc.resolve(i),o.depth));const l=Pn(o);if(l==null)return!1;r.lift(o,l);let c=r.doc.resolve(r.mapping.map(s,-1)-1);return fn(r.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&r.join(c.pos),e(r.scrollIntoView()),!0}function Sg(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 Eg(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},zn=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e};let ci=null;const xt=function(n,e,t){let o=ci||(ci=document.createRange());return o.setEnd(n,t??n.nodeValue.length),o.setStart(n,e||0),o},vg=function(){ci=null},hn=function(n,e,t,o){return t&&(Wc(n,e,t,o,-1)||Wc(n,e,t,o,1))},Mg=/^(img|br|input|textarea|hr)$/i;function Wc(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||mo(n)||Mg.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 Tg(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&&!mo(n))e=Ee(n),n=n.parentNode;else return null}}function Ng(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&&!mo(n))e=Ee(n)+1,n=n.parentNode;else return null}}function Ag(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 mo(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 cr=function(n){return n.focusNode&&hn(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function pn(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function Bg(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function Ig(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 dt=typeof navigator<"u"?navigator:null,Kc=typeof document<"u"?document:null,zt=dt&&dt.userAgent||"",di=/Edge\/(\d+)/.exec(zt),qc=/MSIE \d/.exec(zt),ui=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(zt),$e=!!(qc||ui||di),Ft=qc?document.documentMode:ui?+ui[1]:di?+di[1]:0,Ge=!$e&&/gecko\/(\d+)/i.test(zt);Ge&&+(/Firefox\/(\d+)/.exec(zt)||[0,0])[1];const fi=!$e&&/Chrome\/(\d+)/.exec(zt),ve=!!fi,Jc=fi?+fi[1]:0,Oe=!$e&&!!dt&&/Apple Computer/.test(dt.vendor),Fn=Oe&&(/Mobile\/\w+/.test(zt)||!!dt&&dt.maxTouchPoints>2),Ye=Fn||(dt?/Mac/.test(dt.platform):!1),Gc=dt?/Win/.test(dt.platform):!1,St=/Android \d/.test(zt),go=!!Kc&&"webkitFontSmoothing"in Kc.documentElement.style,Og=go?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Rg(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 Et(n,e){return typeof n=="number"?n:n[e]}function Pg(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 Yc(n,e,t){let o=n.someProp("scrollThreshold")||0,r=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let i=t||n.dom;i;){if(i.nodeType!=1){i=zn(i);continue}let l=i,c=l==s.body,d=c?Rg(s):Pg(l),u=0,f=0;if(e.top<d.top+Et(o,"top")?f=-(d.top-e.top+Et(r,"top")):e.bottom>d.bottom-Et(o,"bottom")&&(f=e.bottom-e.top>d.bottom-d.top?e.top+Et(r,"top")-d.top:e.bottom-d.bottom+Et(r,"bottom")),e.left<d.left+Et(o,"left")?u=-(d.left-e.left+Et(r,"left")):e.right>d.right-Et(o,"right")&&(u=e.right-d.right+Et(r,"right")),u||f)if(c)s.defaultView.scrollBy(u,f);else{let p=l.scrollLeft,m=l.scrollTop;f&&(l.scrollTop+=f),u&&(l.scrollLeft+=u);let g=l.scrollLeft-p,y=l.scrollTop-m;e={left:e.left-g,top:e.top-y,right:e.right-g,bottom:e.bottom-y}}let h=c?"fixed":getComputedStyle(i).position;if(/^(fixed|sticky)$/.test(h))break;i=h=="absolute"?i.offsetParent:zn(i)}}function Dg(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:Xc(n.dom)}}function Xc(n){let e=[],t=n.ownerDocument;for(let o=n;o&&(e.push({dom:o,top:o.scrollTop,left:o.scrollLeft}),n!=t);o=zn(o));return e}function _g({refDOM:n,refTop:e,stack:t}){let o=n?n.getBoundingClientRect().top:0;Qc(t,o==0?0:o-e)}function Qc(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 Hn=null;function Lg(n){if(n.setActive)return n.setActive();if(Hn)return n.focus(Hn);let e=Xc(n);n.focus(Hn==null?{get preventScroll(){return Hn={preventScroll:!0},!0}}:void 0),Hn||(Hn=!1,Qc(e,0))}function Zc(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=xt(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?Vg(t,r):!t||o&&t.nodeType==1?{node:n,offset:s}:Zc(t,r)}function Vg(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=Ht(o,1);if(i.top!=i.bottom&&hi(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 hi(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function $g(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left<n.getBoundingClientRect().left?t:n}function zg(n,e,t){let{node:o,offset:r}=Zc(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 Fg(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 ed(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(hi(e,d))return ed(i,e,d)}}if((s=(s+1)%o)==r)break}return n}function Hg(n,e){let t=n.dom.ownerDocument,o,r=0,s=Ig(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(!hi(e,d)||(i=ed(n.dom,e,d),!i))return null}if(Oe)for(let d=i;o&&d;d=zn(d))d.draggable&&(o=void 0);if(i=$g(i,e),o){if(Ge&&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;go&&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=Fg(n,o,r,e))}l==null&&(l=zg(n,i,e));let c=n.docView.nearestDesc(i,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function td(n){return n.top<n.bottom||n.left<n.right}function Ht(n,e){let t=n.getClientRects();if(t.length){let o=t[e<0?0:t.length-1];if(td(o))return o}return Array.prototype.find.call(t,td)||n.getBoundingClientRect()}const Ug=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function nd(n,e,t){let{node:o,offset:r,atom:s}=n.docView.domFromPos(e,t<0?-1:1),i=go||Ge;if(o.nodeType==3)if(i&&(Ug.test(o.nodeValue)||(t<0?!r:r==o.nodeValue.length))){let c=Ht(xt(o,r,r),t);if(Ge&&r&&/\s/.test(o.nodeValue[r-1])&&r<o.nodeValue.length){let d=Ht(xt(o,r-1,r-1),-1);if(d.top==c.top){let u=Ht(xt(o,r,r+1),-1);if(u.top!=c.top)return yo(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++,yo(Ht(xt(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 pi(c.getBoundingClientRect(),!1)}if(s==null&&r<Je(o)){let c=o.childNodes[r];if(c.nodeType==1)return pi(c.getBoundingClientRect(),!0)}return pi(o.getBoundingClientRect(),t>=0)}if(s==null&&r&&(t<0||r==Je(o))){let c=o.childNodes[r-1],d=c.nodeType==3?xt(c,Je(c)-(i?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(d)return yo(Ht(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?xt(c,0,i?0:1):c.nodeType==1?c:null:null;if(d)return yo(Ht(d,-1),!0)}return yo(Ht(o.nodeType==3?xt(o):o,-t),t>=0)}function yo(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 pi(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 od(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 jg(n,e,t){let o=e.selection,r=t=="up"?o.$from:o.$to;return od(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=nd(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=xt(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 Wg=/[\u0590-\u08ac]/;function Kg(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?!Wg.test(o.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:i:od(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 rd=null,sd=null,id=!1;function qg(n,e,t){return rd==e&&sd==t?id:(rd=e,sd=t,id=t=="up"||t=="down"?jg(n,e,t):Kg(n,e,t))}const Xe=0,ld=1,mn=2,ut=3;class ko{constructor(e,t,o,r){this.parent=e,this.children=t,this.dom=o,this.contentDOM=r,this.dirty=Xe,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 dd){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 ad&&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((Ge||Oe)&&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(Ge&&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&&Oe)&&hn(l.node,l.offset,u.anchorNode,u.anchorOffset)&&hn(c.node,c.offset,u.focusNode,u.focusOffset))return;let h=!1;if((d.extend||e==t)&&!(f&&Ge)){d.collapse(l.node,l.offset);try{e!=t&&d.extend(c.node,c.offset),h=!0}catch{}}if(!h){if(e>t){let m=l;l=c,c=m}let p=document.createRange();p.setEnd(c.node,c.offset),p.setStart(l.node,l.offset),d.removeAllRanges(),d.addRange(p)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let o=0,r=0;r<this.children.length;r++){let s=this.children[r],i=o+s.size;if(o==i?e<=i&&t>=o:e<i&&t>o){let l=o+s.border,c=i-s.border;if(e>=l&&t<=c){this.dirty=e==o||t==i?mn:ld,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=ut:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?mn:ut}o=i}this.dirty=mn}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let o=e==1?mn:ld;t.dirty<o&&(t.dirty=o)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}}class ad extends ko{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==Xe&&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 Jg extends ko{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 gn extends ko{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=dn.renderSpec(document,t.type.spec.toDOM(t,o),null,t.attrs)),new gn(e,t,i.dom,i.contentDOM||i.dom,i)}parseRule(){return this.dirty&ut||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=ut&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=Xe){let o=this.parent;for(;!o.node;)o=o.parent;o.dirty<this.dirty&&(o.dirty=this.dirty),this.dirty=Xe}}slice(e,t,o){let r=gn.create(this.parent,this.mark,!0,o),s=this.children,i=this.size;t<i&&(s=gi(s,t,i,o)),e>0&&(s=gi(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 Ut extends ko{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}=dn.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=hd(u,o,t),d?c=new Gg(e,t,o,r,u,f||null,h,d,s,i+1):t.isText?new dr(e,t,o,r,u,h,s):new Ut(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==Xe&&e.eq(this.node)&&ur(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 Xg(this,i&&i.node,e);e0(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==mn)&&(i&&this.protectLocalComposition(e,i),ud(this.contentDOM,this.children,e),Fn&&t0(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=n0(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 Jg(this,s,t,r);e.input.compositionNodes.push(i),this.children=gi(this.children,o,o+r.length,e,i)}update(e,t,o,r){return this.dirty==ut||!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=Xe}updateOuterDeco(e){if(ur(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,o=this.dom;this.dom=fd(this.dom,this.nodeDOM,mi(this.outerDeco,this.node,t),mi(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 cd(n,e,t,o,r){hd(o,e,n);let s=new Ut(void 0,n,e,t,o,o,o,r,0);return s.contentDOM&&s.updateChildren(r,0),s}class dr extends Ut{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==ut||this.dirty!=Xe&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=Xe||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=Xe,!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 dr(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=ut)}get domAtom(){return!1}isText(e){return this.node.text==e}}class dd extends ko{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==Xe&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}}class Gg extends Ut{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==ut)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 ud(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=pd(o),r=!0;o=o.nextSibling}else r=!0,n.insertBefore(l,o);if(i instanceof gn){let c=o?o.previousSibling:n.lastChild;ud(i.contentDOM,i.children,t),o=c?c.nextSibling:n.firstChild}}for(;o;)o=pd(o),r=!0;r&&t.trackWrites==n&&(t.trackWrites=null)}const wo=function(n){n&&(this.nodeName=n)};wo.prototype=Object.create(null);const yn=[new wo];function mi(n,e,t){if(n.length==0)return yn;let o=t?yn[0]:new wo,r=[o];for(let s=0;s<n.length;s++){let i=n[s].type.attrs;if(i){i.nodeName&&r.push(o=new wo(i.nodeName));for(let l in i){let c=i[l];c!=null&&(t&&r.length==1&&r.push(o=new wo(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 fd(n,e,t,o){if(t==yn&&o==yn)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=yn[0]),r=c}Yg(r,l||yn[0],i)}return r}function Yg(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 hd(n,e,t){return fd(n,n,yn,mi(e,t,n.nodeType!=1))}function ur(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 pd(n){let e=n.nextSibling;return n.parentNode.removeChild(n),e}class Xg{constructor(e,t,o){this.lock=t,this.view=o,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=Qg(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=Xe,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=gn.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==ut&&i.dom==i.contentDOM&&(i.dirty=mn),i.update(e,t,o,s)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let o=e.pmViewDesc;if(o){for(let r=this.index;r<this.top.children.length;r++)if(this.top.children[r]==o)return r}return-1}e=t}}updateNextNode(e,t,o,r,s,i){for(let l=this.index;l<this.top.children.length;l++){let c=this.top.children[l];if(c instanceof Ut){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!=ut&&ur(t,c.outerDeco));if(!h&&c.update(e,t,o,r))return this.destroyBetween(this.index,l),c.dom!=u&&(this.changed=!0),this.index++,!0;if(!h&&(f=this.recreateWrapper(c,e,t,o,r,i)))return this.destroyBetween(this.index,l),this.top.children[this.index]=f,f.contentDOM&&(f.dirty=mn,f.updateChildren(r,i+1),f.dirty=Xe),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)||!ur(o,e.outerDeco)||!r.eq(e.innerDeco))return null;let l=Ut.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=Ut.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 ad(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 gn;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof dr)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((Oe||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 dd(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 Qg(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 gn)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 Zg(n,e){return n.type.side-e.type.side}function e0(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(Zg);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 t0(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 n0(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 gi(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 yi(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(cr(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&&Ag(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=wi(n,u,l,f)}return d}function md(n){return n.editable?n.hasFocus():xd(n)&&document.activeElement&&document.activeElement.contains(n.dom)}function vt(n,e=!1){let t=n.state.selection;if(wd(n,t),!!md(n)){if(!e&&n.input.mouseDown&&n.input.mouseDown.allowDefault&&ve){let o=n.domSelectionRange(),r=n.domObserver.currentSelection;if(o.anchorNode&&r.anchorNode&&hn(o.anchorNode,o.anchorOffset,r.anchorNode,r.anchorOffset)){n.input.mouseDown.delayedSelectionSync=!0,n.domObserver.setCurSelection();return}}if(n.domObserver.disconnectSelection(),n.cursorWrapper)r0(n);else{let{anchor:o,head:r}=t,s,i;gd&&!(t instanceof Y)&&(t.$from.parent.inlineContent||(s=yd(n,t.from)),!t.empty&&!t.$from.parent.inlineContent&&(i=yd(n,t.to))),n.docView.setSelection(o,r,n,e),gd&&(s&&kd(s),i&&kd(i)),t.visible?n.dom.classList.remove("ProseMirror-hideselection"):(n.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&o0(n))}n.domObserver.setCurSelection(),n.domObserver.connectSelection()}}const gd=Oe||ve&&Jc<63;function yd(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(Oe&&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",Oe&&n.draggable&&(n.draggable=!1,n.wasDraggable=!0),n}function kd(n){n.contentEditable="false",n.wasDraggable&&(n.draggable=!0,n.wasDraggable=null)}function o0(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(()=>{(!md(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function r0(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&&Ft<=11&&(t.disabled=!0,t.disabled=!1)}function wd(n,e){if(e instanceof q){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(bd(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else bd(n)}function bd(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function wi(n,e,t,o){return n.someProp("createSelectionBetween",r=>r(n,e,t))||Y.between(e,t,o)}function Cd(n){return n.editable&&!n.hasFocus()?!1:xd(n)}function xd(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 s0(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return hn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function bi(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 jt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Sd(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 jt(n,new Y(o.$anchor,i))}else if(o.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let r=bi(n.state,e);return r&&r instanceof q?jt(n,r):!1}else if(!(Ye&&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)?jt(n,new q(e<0?n.state.doc.resolve(r.pos-s.nodeSize):r)):go?jt(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 jt(n,new Y(e>0?o.$to:o.$from));{let r=bi(n.state,e);return r?jt(n,r):!1}}}function fr(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function bo(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Un(n,e){return e<0?i0(n):l0(n)}function i0(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r,s,i=!1;for(Ge&&t.nodeType==1&&o<fr(t)&&bo(t.childNodes[o],-1)&&(i=!0);;)if(o>0){if(t.nodeType!=1)break;{let l=t.childNodes[o-1];if(bo(l,-1))r=t,s=--o;else if(l.nodeType==3)t=l,o=t.nodeValue.length;else break}}else{if(Ed(t))break;{let l=t.previousSibling;for(;l&&bo(l,-1);)r=t.parentNode,s=Ee(l),l=l.previousSibling;if(l)t=l,o=fr(t);else{if(t=t.parentNode,t==n.dom)break;o=0}}}i?Ci(n,t,o):r&&Ci(n,r,s)}function l0(n){let e=n.domSelectionRange(),t=e.focusNode,o=e.focusOffset;if(!t)return;let r=fr(t),s,i;for(;;)if(o<r){if(t.nodeType!=1)break;let l=t.childNodes[o];if(bo(l,1))s=t,i=++o;else break}else{if(Ed(t))break;{let l=t.nextSibling;for(;l&&bo(l,1);)s=l.parentNode,i=Ee(l)+1,l=l.nextSibling;if(l)t=l,o=0,r=fr(t);else{if(t=t.parentNode,t==n.dom)break;o=r=0}}}s&&Ci(n,s,i)}function Ed(n){let e=n.pmViewDesc;return e&&e.node&&e.node.isBlock}function a0(n,e){for(;n&&e==n.childNodes.length&&!mo(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 c0(n,e){for(;n&&!e&&!mo(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 Ci(n,e,t){if(e.nodeType!=3){let s,i;(i=a0(e,t))?(e=i,t=0):(s=c0(e,t))&&(e=s,t=s.nodeValue.length)}let o=n.domSelection();if(!o)return;if(cr(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&&vt(n)},50)}function vd(n,e){let t=n.state.doc.resolve(e);if(!(ve||Gc)&&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 Md(n,e,t){let o=n.state.selection;if(o instanceof Y&&!o.empty||t.indexOf("s")>-1||Ye&&t.indexOf("m")>-1)return!1;let{$from:r,$to:s}=o;if(!r.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let i=bi(n.state,e);if(i&&i instanceof q)return jt(n,i)}if(!r.parent.inlineContent){let i=e<0?r:s,l=o instanceof je?Z.near(i,e):Z.findFrom(i,e);return l?jt(n,l):!1}return!1}function Td(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 Nd(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function d0(n){if(!Oe||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;Nd(n,o,"true"),setTimeout(()=>Nd(n,o,"false"),20)}return!1}function u0(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function f0(n,e){let t=e.keyCode,o=u0(e);if(t==8||Ye&&t==72&&o=="c")return Td(n,-1)||Un(n,-1);if(t==46&&!e.shiftKey||Ye&&t==68&&o=="c")return Td(n,1)||Un(n,1);if(t==13||t==27)return!0;if(t==37||Ye&&t==66&&o=="c"){let r=t==37?vd(n,n.state.selection.from)=="ltr"?-1:1:-1;return Sd(n,r,o)||Un(n,r)}else if(t==39||Ye&&t==70&&o=="c"){let r=t==39?vd(n,n.state.selection.from)=="ltr"?1:-1:1;return Sd(n,r,o)||Un(n,r)}else{if(t==38||Ye&&t==80&&o=="c")return Md(n,-1,o)||Un(n,-1);if(t==40||Ye&&t==78&&o=="c")return d0(n)||Md(n,1,o)||Un(n,1);if(o==(Ye?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function xi(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")||dn.fromSchema(n.state.schema),l=_d(),c=l.createElement("div");c.appendChild(i.serializeFragment(o,{document:l}));let d=c.firstChild,u,f=0;for(;d&&d.nodeType==1&&(u=Pd[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 Ad(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=dn.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=g0(t),go&&y0(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")||Rn.fromSchema(n.state.schema)).parseSlice(i,{preserveWhitespace:!!(c||u),context:r,ruleFromNode(h){return h.nodeName=="BR"&&!h.nextSibling&&h.parentNode&&!h0.test(h.parentNode.nodeName)?{ignore:!0}:null}})),u)l=k0(Rd(l,+u[1],+u[2]),u[4]);else if(l=$.maxOpen(p0(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=Rd(l,f,h)}return n.someProp("transformPasted",f=>{l=f(l,n,c)}),l}const h0=/^(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 p0(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&&Id(c,s,l,i[i.length-1],0))i[i.length-1]=d;else{i.length&&(i[i.length-1]=Od(i[i.length-1],s.length));let u=Bd(l,c);i.push(u),r=r.matchType(u.type),s=c}}),i)return O.from(i)}return n}function Bd(n,e,t=0){for(let o=e.length-1;o>=t;o--)n=e[o].create(null,O.from(n));return n}function Id(n,e,t,o,r){if(r<n.length&&r<e.length&&n[r]==e[r]){let s=Id(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(Bd(t,n,r+1))))}}function Od(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,Od(n.lastChild,e-1)),o=n.contentMatchAt(n.childCount).fillBefore(O.empty,!0);return n.copy(t.append(o))}function Si(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=Si(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 Rd(n,e,t){return e<n.openStart&&(n=new $(Si(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new $(Si(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}const Pd={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 Dd=null;function _d(){return Dd||(Dd=document.implementation.createHTMLDocument("title"))}let Ei=null;function m0(n){let e=window.trustedTypes;return e?(Ei||(Ei=e.defaultPolicy||e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})),Ei.createHTML(n)):n}function g0(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=_d().createElement("div"),o=/<([a-z][^>\s]+)/i.exec(n),r;if((r=o&&Pd[o[1].toLowerCase()])&&(n=r.map(s=>"<"+s+">").join("")+n+r.map(s=>"</"+s+">").reverse().join("")),t.innerHTML=m0(n),r)for(let s=0;s<r.length;s++)t=t.querySelector(r[s])||t;return t}function y0(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 k0(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 De={},_e={},w0={touchstart:!0,touchmove:!0};class b0{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 C0(n){for(let e in De){let t=De[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=o=>{S0(n,o)&&!Mi(n,o)&&(n.editable||!(o.type in _e))&&t(n,o)},w0[e]?{passive:!0}:void 0)}Oe&&n.dom.addEventListener("input",()=>null),vi(n)}function Wt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function x0(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 vi(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=o=>Mi(n,o))})}function Mi(n,e){return n.someProp("handleDOMEvents",t=>{let o=t[e.type];return o?o(n,e)||e.defaultPrevented:!1})}function S0(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 E0(n,e){!Mi(n,e)&&De[e.type]&&(n.editable||!(e.type in _e))&&De[e.type](n,e)}_e.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Vd(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(St&&ve&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),Fn&&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,pn(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",o=>o(n,t))||f0(n,t)?t.preventDefault():Wt(n,"key")},_e.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)},_e.keypress=(n,e)=>{let t=e;if(Vd(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Ye&&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 hr(n){return{left:n.clientX,top:n.clientY}}function v0(n,e){let t=e.x-n.clientX,o=e.y-n.clientY;return t*t+o*o<100}function Ti(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 jn(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 M0(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),o=t.nodeAfter;return o&&o.isAtom&&q.isSelectable(o)?(jn(n,new q(t)),!0):!1}function T0(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?(jn(n,q.create(n.state.doc,r)),!0):!1}function N0(n,e,t,o,r){return Ti(n,"handleClickOn",e,t,o)||n.someProp("handleClick",s=>s(n,e,o))||(r?T0(n,t):M0(n,t))}function A0(n,e,t,o){return Ti(n,"handleDoubleClickOn",e,t,o)||n.someProp("handleDoubleClick",r=>r(n,e,o))}function B0(n,e,t,o){return Ti(n,"handleTripleClickOn",e,t,o)||n.someProp("handleTripleClick",r=>r(n,e,o))||I0(n,t,o)}function I0(n,e,t){if(t.button!=0)return!1;let o=n.state.doc;if(e==-1)return o.inlineContent?(jn(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)jn(n,Y.create(o,l+1,l+1+i.content.size));else if(q.isSelectable(i))jn(n,q.create(o,l));else continue;return!0}}function Ni(n){return pr(n)}const Ld=Ye?"metaKey":"ctrlKey";De.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let o=Ni(n),r=Date.now(),s="singleClick";r-n.input.lastClick.time<500&&v0(t,n.input.lastClick)&&!t[Ld]&&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(hr(t));i&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new O0(n,i,t,!!o)):(s=="doubleClick"?A0:B0)(n,i.pos,i.inside,t)?t.preventDefault():Wt(n,"pointer"))};class O0{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[Ld],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&&Ge&&!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)),Wt(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(()=>vt(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(hr(e))),this.updateAllowDefault(e),this.allowDefault||!t?Wt(this.view,"pointer"):N0(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||Oe&&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)?(jn(this.view,Z.near(this.view.state.doc.resolve(t.pos))),e.preventDefault()):Wt(this.view,"pointer")}move(e){this.updateAllowDefault(e),Wt(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)}}De.touchstart=n=>{n.input.lastTouch=Date.now(),Ni(n),Wt(n,"pointer")},De.touchmove=n=>{n.input.lastTouch=Date.now(),Wt(n,"pointer")},De.contextmenu=n=>Ni(n);function Vd(n,e){return n.composing?!0:Oe&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}const R0=St?5e3:-1;_e.compositionstart=_e.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&&Gc&&P0(n)))n.markCursor=n.state.storedMarks||t.marks(),pr(n,!0),n.markCursor=null;else if(pr(n,!e.selection.empty),Ge&&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}$d(n,R0)};function P0(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"}_e.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++,$d(n,20))};function $d(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>pr(n),e))}function zd(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=_0());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function D0(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=Tg(e.focusNode,e.focusOffset),o=Ng(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 _0(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function pr(n,e=!1){if(!(St&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),zd(n),e||n.docView&&n.docView.dirty){let t=yi(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 L0(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 Co=$e&&Ft<15||Fn&&Og<604;De.copy=_e.cut=(n,e)=>{let t=e,o=n.state.selection,r=t.type=="cut";if(o.empty)return;let s=Co?null:t.clipboardData,i=o.content(),{dom:l,text:c}=xi(n,i);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):L0(n,l),r&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function V0(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function $0(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?xo(n,o.value,null,r,e):xo(n,o.textContent,o.innerHTML,r,e)},50)}function xo(n,e,t,o,r){let s=Ad(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=V0(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 Fd(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," "):""}_e.paste=(n,e)=>{let t=e;if(n.composing&&!St)return;let o=Co?null:t.clipboardData,r=n.input.shiftKey&&n.input.lastKeyCode!=45;o&&xo(n,Fd(o),o.getData("text/html"),r,t)?t.preventDefault():$0(n,t)};class Hd{constructor(e,t,o){this.slice=e,this.move=t,this.node=o}}const z0=Ye?"altKey":"ctrlKey";function Ud(n,e){let t=n.someProp("dragCopies",o=>!o(e));return t??!e[z0]}De.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(hr(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}=xi(n,l);(!t.dataTransfer.files.length||!ve||Jc>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Co?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",Co||t.dataTransfer.setData("text/plain",d),n.dragging=new Hd(u,Ud(n,t),i)},De.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)},_e.dragover=_e.dragenter=(n,e)=>e.preventDefault(),_e.drop=(n,e)=>{try{F0(n,e,n.dragging)}finally{n.dragging=null}};function F0(n,e,t){if(!e.dataTransfer)return;let o=n.posAtCoords(hr(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=Ad(n,Fd(e.dataTransfer),Co?null:e.dataTransfer.getData("text/html"),!1,r);let i=!!(t&&Ud(n,e));if(n.someProp("handleDrop",p=>p(n,e,s||$.empty,i))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?kc(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(wi(n,h,c.doc.resolve(p)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))}De.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())&&vt(n)},20))},De.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)},De.beforeinput=(n,e)=>{if(ve&&St&&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,pn(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 _e)De[n]=_e[n];function So(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 mr{constructor(e,t){this.toDOM=e,this.spec=t||kn,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 mr&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&So(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}}class Kt{constructor(e,t){this.attrs=e,this.spec=t||kn}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 Kt&&So(this.attrs,e.attrs)&&So(this.spec,e.spec)}static is(e){return e.type instanceof Kt}destroy(){}}class Ai{constructor(e,t){this.attrs=e,this.spec=t||kn}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 Ai&&So(this.attrs,e.attrs)&&So(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 mr(t,o))}static inline(e,t,o,r){return new Le(e,t,new Kt(o,r))}static node(e,t,o,r){return new Le(e,t,new Ai(o,r))}get spec(){return this.type.spec}get inline(){return this.type instanceof Kt}get widget(){return this.type instanceof mr}}const Wn=[],kn={};class ae{constructor(e,t){this.local=e.length?e:Wn,this.children=t.length?t:Wn}static create(e,t){return t.length?gr(t,e,0,kn):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||kn)}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?H0(this.children,i||[],e,t,o,r,s):i?new ae(i.sort(wn),Wn):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=Wd(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,gr(u,l,d+1,kn)),s+=3}});let i=jd(s?Kd(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(wn):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 Kt){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(wn),Wn);return o?new qt([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 Bi(this.localsInner(e))}localsInner(e){if(this==Re)return Wn;if(e.inlineContent||!this.local.some(Kt.is))return this.local;let t=[];for(let o=0;o<this.local.length;o++)this.local[o].type instanceof Kt||t.push(this.local[o]);return t}forEachSet(e){e(this)}}ae.empty=new ae([],[]),ae.removeOverlap=Bi;const Re=ae.empty;class qt{constructor(e){this.members=e}map(e,t){const o=this.members.map(r=>r.map(e,t,kn));return qt.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 qt?o=o.concat(s.members):o.push(s))}return qt.from(o)}eq(e){if(!(e instanceof qt)||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?Bi(o?t:t.sort(wn)):Wn}static from(e){switch(e.length){case 0:return Re;case 1:return e[0];default:return new qt(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 H0(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 w=l[k+1];if(w<0||h>w+u-f)continue;let C=l[k]+u-f;p>=C?l[k+1]=h<=C?-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=U0(l,n,e,t,r,s,i),u=gr(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(wn),l)}function jd(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 U0(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 Wd(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 Kd(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function gr(n,e,t,o){let r=[],s=!1;e.forEach((l,c)=>{let d=Wd(n,l,c+t);if(d){s=!0;let u=gr(d,l,t+c+1,o);u!=Re&&r.push(c,c+l.nodeSize,u)}});let i=jd(s?Kd(n):n,-t).sort(wn);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 wn(n,e){return n.from-e.from||n.to-e.to}function Bi(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),qd(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),qd(e,r,o.copy(s.from,o.to)));break}}}return e}function qd(n,e,t){for(;e<n.length&&wn(t,n[e])>0;)e++;n.splice(e,0,t)}function Ii(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])),qt.from(e)}const j0={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},W0=$e&&Ft<=11;class K0{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 q0{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new K0,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&&Ft<=11&&o.some(r=>r.type=="childList"&&r.removedNodes.length||r.type=="characterData"&&r.oldValue.length>r.target.nodeValue.length)?this.flushSoon():Oe&&e.composing&&o.some(r=>r.type=="childList"&&r.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),W0&&(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,j0)),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(Cd(this.view)){if(this.suppressingSelectionUpdates)return vt(this.view);if($e&&Ft<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&hn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,o;for(let s=e.focusNode;s;s=zn(s))t.add(s);for(let s=e.anchorNode;s;s=zn(s))if(t.has(s)){o=s;break}let r=o&&this.view.docView.nearestDesc(o);if(r&&r.ignoreMutation({type:"selection",target:o.nodeType==3?o.parentNode:o}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let o=e.domSelectionRange(),r=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(o)&&Cd(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(Ge&&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||Y0(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&&cr(o)&&(d=yi(e))&&d.eq(Z.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,vt(e),this.currentSelection.set(o),e.scrollToSelection()):(s>-1||r)&&(s>-1&&(e.docView.markDirty(s,i),J0(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,X0(e,c)),this.handleDOMChange(s,i,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(o)||vt(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&&Ft<=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 Jd=new WeakMap,Gd=!1;function J0(n){if(!Jd.has(n)&&(Jd.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=Ge,Gd)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."),Gd=!0}}function Yd(n,e){let t=e.startContainer,o=e.startOffset,r=e.endContainer,s=e.endOffset,i=n.domAtPos(n.state.selection.anchor);return hn(i.node,i.offset,r,s)&&([t,o,r,s]=[r,s,t,o]),{anchorNode:t,anchorOffset:o,focusNode:r,focusOffset:s}}function G0(n,e){if(e.getComposedRanges){let r=e.getComposedRanges(n.root)[0];if(r)return Yd(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?Yd(n,t):null}function Y0(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 X0(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 Q0(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}],cr(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],w=k.pmViewDesc;if(k.nodeName=="BR"&&!w){s=y;break}if(!w||w.size)break}let f=n.state.doc,h=n.someProp("domParser")||Rn.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:Z0,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 Z0(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(Oe&&/^(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||Oe&&/^(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 e1=/^(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 t1(n,e,t,o,r){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let E=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,T=yi(n,E);if(T&&!n.state.selection.eq(T)){if(ve&&St&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",B=>B(n,pn(13,"Enter"))))return;let v=n.state.tr.setSelection(T);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=Q0(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=r1(f.content,d.doc.content,d.from,h,p);if(m&&n.input.domChangeCount++,(Fn&&n.input.lastIOSEnter>Date.now()-225||St)&&r.some(E=>E.nodeType==1&&!e1.test(E.nodeName))&&(!m||m.endA>=m.endB)&&n.someProp("handleKeyDown",E=>E(n,pn(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=Xd(n,n.state.doc,d.sel);if(E&&!E.eq(n.state.selection)){let T=n.state.tr.setSelection(E);s&&T.setMeta("composition",s),n.dispatch(T)}}return}n.state.selection.from<n.state.selection.to&&m.start==m.endB&&n.state.selection instanceof 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&&Ft<=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((Fn&&n.input.lastIOSEnter>Date.now()-225&&(!w||r.some(E=>E.nodeName=="DIV"||E.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",E=>E(n,pn(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>m.start&&o1(u,m.start,m.endA,g,y)&&n.someProp("handleKeyDown",E=>E(n,pn(8,"Backspace")))){St&&ve&&n.domObserver.suppressSelectionUpdates();return}ve&&m.endB==m.start&&(n.input.lastChromeDelete=Date.now()),St&&!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(E){return E(n,pn(13,"Enter"))})},20));let C=m.start,x=m.endA,S=E=>{let T=E||n.state.tr.replace(C,x,d.doc.slice(m.start-d.from,m.endB-d.from));if(d.sel){let v=Xd(n,T.doc,d.sel);v&&!(ve&&n.composing&&v.empty&&(m.start!=m.endB||n.input.lastChromeDelete<Date.now()-100)&&(v.head==C||v.head==T.mapping.map(x)-1)||$e&&v.empty&&v.head==C)&&T.setSelection(v)}return s&&T.setMeta("composition",s),T.scrollIntoView()},M;if(w)if(g.pos==y.pos){$e&&Ft<=11&&g.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>vt(n),20));let E=S(n.state.tr.delete(C,x)),T=u.resolve(m.start).marksAcross(u.resolve(m.endA));T&&E.ensureMarks(T),n.dispatch(E)}else if(m.endA==m.endB&&(M=n1(g.parent.content.cut(g.parentOffset,y.parentOffset),k.parent.content.cut(k.parentOffset,m.endA-k.start())))){let E=S(n.state.tr);M.type=="add"?E.addMark(C,x,M.mark):E.removeMark(C,x,M.mark),n.dispatch(E)}else if(g.parent.child(g.index()).isText&&g.index()==y.index()-(y.textOffset?0:1)){let E=g.parent.textBetween(g.parentOffset,y.parentOffset),T=()=>S(n.state.tr.insertText(E,C,x));n.someProp("handleTextInput",v=>v(n,C,x,E,T))||n.dispatch(T())}else n.dispatch(S());else n.dispatch(S())}function Xd(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:wi(n,e.resolve(t.anchor),e.resolve(t.head))}function n1(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 o1(n,e,t,o,r){if(t-e<=r.pos-o.pos||Oi(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(Oi(s,!0,!0));return!i.parent.isTextblock||i.pos>t||Oi(i,!0,!1)<t?!1:o.parent.content.cut(o.parentOffset).eq(i.parent.content)}function Oi(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 r1(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&&Qd(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&&Qd(n.textBetween(s-1,s+1))&&(s+=c?1:-1),i=s+(i-l),l=s}return{start:s,endA:i,endB:l}}function Qd(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 Zd{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 b0,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(ru),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=nu(this),tu(this),this.nodeViews=ou(this),this.docView=cd(this.state.doc,eu(this),Ii(this),this.dom,this),this.domObserver=new q0(this,(o,r,s,i)=>t1(this,o,r,s,i)),this.domObserver.start(),C0(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&&vi(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(ru),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&&(zd(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=ou(this);i1(p,this.nodeViews)&&(this.nodeViews=p,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&vi(this),this.editable=nu(this),tu(this);let c=Ii(this),d=eu(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&&Dg(this);if(i){this.domObserver.stop();let p=f&&($e||ve)&&!this.composing&&!r.selection.empty&&!e.selection.empty&&s1(r.selection,e.selection);if(f){let m=ve?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=D0(this)),(s||!this.docView.update(e.doc,d,c,this))&&(this.docView.updateOuterDeco(d),this.docView.destroy(),this.docView=cd(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())&&s0(this))?vt(this,p):(wd(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&&_g(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&&Yc(this,t.getBoundingClientRect(),e)}else Yc(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 Hd(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&&Lg(this.dom),vt(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 Hg(this,e)}coordsAtPos(e,t=1){return nd(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 qg(this,t||this.state,e)}pasteHTML(e,t){return xo(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return xo(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return xi(this,e)}destroy(){this.docView&&(x0(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Ii(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,vg())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return E0(this,e)}domSelectionRange(){let e=this.domSelection();return e?Oe&&this.root.nodeType===11&&Bg(this.dom.ownerDocument)==this.dom&&G0(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}}Zd.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function eu(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 tu(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 nu(n){return!n.someProp("editable",e=>e(n.state)===!1)}function s1(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 ou(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 i1(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 ru(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 Jt={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:"'"},yr={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},l1=typeof navigator<"u"&&/Mac/.test(navigator.platform),a1=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent),Me=0;Me<10;Me++)Jt[48+Me]=Jt[96+Me]=String(Me);for(var Me=1;Me<=24;Me++)Jt[Me+111]="F"+Me;for(var Me=65;Me<=90;Me++)Jt[Me]=String.fromCharCode(Me+32),yr[Me]=String.fromCharCode(Me);for(var Ri in Jt)yr.hasOwnProperty(Ri)||(yr[Ri]=Jt[Ri]);function c1(n){var e=l1&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||a1&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?yr:Jt)[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 d1=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),u1=typeof navigator<"u"&&/Win/.test(navigator.platform);function f1(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))d1?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 h1(n){let e=Object.create(null);for(let t in n)e[f1(t)]=n[t];return e}function Pi(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 p1(n){return new ue({props:{handleKeyDown:su(n)}})}function su(n){let e=h1(n);return function(t,o){let r=c1(o),s,i=e[Pi(r,o)];if(i&&i(t.state,t.dispatch,t))return!0;if(r.length==1&&r!=" "){if(o.shiftKey){let l=e[Pi(r,o,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((o.altKey||o.metaKey||o.ctrlKey)&&!(u1&&o.ctrlKey&&o.altKey)&&(s=Jt[o.keyCode])&&s!=r){let l=e[Pi(s,o)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var m1=Object.defineProperty,Di=(n,e)=>{for(var t in e)m1(n,t,{get:e[t],enumerable:!0})};function kr(n){const{state:e,transaction:t}=n;let{selection:o}=t,{doc:r}=t,{storedMarks:s}=t;return{...e,apply:e.apply.bind(e),applyTransaction:e.applyTransaction.bind(e),plugins:e.plugins,schema:e.schema,reconfigure:e.reconfigure.bind(e),toJSON:e.toJSON.bind(e),get storedMarks(){return s},get selection(){return o},get doc(){return r},get tr(){return o=t.selection,r=t.doc,s=t.storedMarks,t}}}var wr=class{constructor(n){this.editor=n.editor,this.rawCommands=this.editor.extensionManager.commands,this.customState=n.state}get hasCustomState(){return!!this.customState}get state(){return this.customState||this.editor.state}get commands(){const{rawCommands:n,editor:e,state:t}=this,{view:o}=e,{tr:r}=t,s=this.buildProps(r);return Object.fromEntries(Object.entries(n).map(([i,l])=>[i,(...d)=>{const u=l(...d)(s);return!r.getMeta("preventDispatch")&&!this.hasCustomState&&o.dispatch(r),u}]))}get chain(){return()=>this.createChain()}get can(){return()=>this.createCan()}createChain(n,e=!0){const{rawCommands:t,editor:o,state:r}=this,{view:s}=o,i=[],l=!!n,c=n||r.tr,d=()=>(!l&&e&&!c.getMeta("preventDispatch")&&!this.hasCustomState&&s.dispatch(c),i.every(f=>f===!0)),u={...Object.fromEntries(Object.entries(t).map(([f,h])=>[f,(...m)=>{const g=this.buildProps(c,e),y=h(...m)(g);return i.push(y),u}])),run:d};return u}createCan(n){const{rawCommands:e,state:t}=this,o=!1,r=n||t.tr,s=this.buildProps(r,o);return{...Object.fromEntries(Object.entries(e).map(([l,c])=>[l,(...d)=>c(...d)({...s,dispatch:void 0})])),chain:()=>this.createChain(r,o)}}buildProps(n,e=!0){const{rawCommands:t,editor:o,state:r}=this,{view:s}=o,i={tr:n,editor:o,view:s,state:kr({state:r,transaction:n}),dispatch:e?()=>{}:void 0,chain:()=>this.createChain(n,e),can:()=>this.createCan(n),get commands(){return Object.fromEntries(Object.entries(t).map(([l,c])=>[l,(...d)=>c(...d)(i)]))}};return i}},iu={};Di(iu,{blur:()=>g1,clearContent:()=>y1,clearNodes:()=>k1,command:()=>w1,createParagraphNear:()=>b1,cut:()=>C1,deleteCurrentNode:()=>x1,deleteNode:()=>S1,deleteRange:()=>E1,deleteSelection:()=>v1,enter:()=>M1,exitCode:()=>T1,extendMarkRange:()=>N1,first:()=>A1,focus:()=>I1,forEach:()=>O1,insertContent:()=>R1,insertContentAt:()=>_1,joinBackward:()=>$1,joinDown:()=>V1,joinForward:()=>z1,joinItemBackward:()=>F1,joinItemForward:()=>H1,joinTextblockBackward:()=>U1,joinTextblockForward:()=>j1,joinUp:()=>L1,keyboardShortcut:()=>K1,lift:()=>q1,liftEmptyBlock:()=>J1,liftListItem:()=>G1,newlineInCode:()=>Y1,resetAttributes:()=>X1,scrollIntoView:()=>Q1,selectAll:()=>Z1,selectNodeBackward:()=>ey,selectNodeForward:()=>ty,selectParentNode:()=>ny,selectTextblockEnd:()=>oy,selectTextblockStart:()=>ry,setContent:()=>sy,setMark:()=>xy,setMeta:()=>Sy,setNode:()=>Ey,setNodeSelection:()=>vy,setTextDirection:()=>My,setTextSelection:()=>Ty,sinkListItem:()=>Ny,splitBlock:()=>Ay,splitListItem:()=>By,toggleList:()=>Iy,toggleMark:()=>Oy,toggleNode:()=>Ry,toggleWrap:()=>Py,undoInputRule:()=>Dy,unsetAllMarks:()=>_y,unsetMark:()=>Ly,unsetTextDirection:()=>Vy,updateAttributes:()=>$y,wrapIn:()=>zy,wrapInList:()=>Fy});var g1=()=>({editor:n,view:e})=>(requestAnimationFrame(()=>{var t;n.isDestroyed||(e.dom.blur(),(t=window==null?void 0:window.getSelection())==null||t.removeAllRanges())}),!0),y1=(n=!0)=>({commands:e})=>e.setContent("",{emitUpdate:n}),k1=()=>({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=Pn(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},w1=n=>e=>n(e),b1=()=>({state:n,dispatch:e})=>zc(n,e),C1=(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},x1=()=>({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 S1=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},E1=n=>({tr:e,dispatch:t})=>{const{from:o,to:r}=n;return t&&e.delete(o,r),!0},v1=()=>({state:n,dispatch:e})=>ri(n,e),M1=()=>({commands:n})=>n.keyboardShortcut("Enter"),T1=()=>({state:n,dispatch:e})=>dg(n,e);function _i(n){return Object.prototype.toString.call(n)==="[object RegExp]"}function br(n,e,t={strict:!0}){const o=Object.keys(e);return o.length?o.every(r=>t.strict?e[r]===n[r]:_i(e[r])?e[r].test(n[r]):e[r]===n[r]):!0}function lu(n,e,t={}){return n.find(o=>o.type===e&&br(Object.fromEntries(Object.keys(t).map(r=>[r,o.attrs[r]])),t))}function au(n,e,t={}){return!!lu(n,e,t)}function Li(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),!lu([...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&&au([...n.parent.child(i-1).marks],e,t);)i-=1,l-=n.parent.child(i).nodeSize;for(;c<n.parent.childCount&&au([...n.parent.child(c).marks],e,t);)d+=n.parent.child(c).nodeSize,c+=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 N1=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const s=Mt(n,o.schema),{doc:i,selection:l}=t,{$from:c,from:d,to:u}=l;if(r){const f=Li(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},A1=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 cu(n){return n instanceof Y}function bn(n=0,e=0,t=0){return Math.min(Math.max(n,e),t)}function du(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,bn(0,r,s),bn(n.content.size,r,s)):Y.create(n,bn(e,r,s),bn(e,r,s))}function uu(){return navigator.platform==="Android"||/android/i.test(navigator.userAgent)}function Cr(){return["iPad Simulator","iPhone Simulator","iPod Simulator","iPad","iPhone","iPod"].includes(navigator.platform)||navigator.userAgent.includes("Mac")&&"ontouchend"in document}function B1(){return typeof navigator<"u"?/^((?!chrome|android).)*safari/i.test(navigator.userAgent):!1}var I1=(n=null,e={})=>({editor:t,view:o,tr:r,dispatch:s})=>{e={scrollIntoView:!0,...e};const i=()=>{(Cr()||uu())&&o.dom.focus(),B1()&&!Cr()&&!uu()&&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&&!cu(t.state.selection))return i(),!0;const l=du(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},O1=(n,e)=>t=>n.every((o,r)=>e(o,{...t,index:r})),R1=(n,e)=>({tr:t,commands:o})=>o.insertContentAt({from:t.selection.from,to:t.selection.to},n,e),fu=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&&fu(o)}return n};function Eo(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 fu(t)}function vo(n,e,t){if(n instanceof bt||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),vo("",e,t)}if(r){if(t.errorOnInvalidContent){let i=!1,l="";const c=new Xa({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?Rn.fromSchema(c).parseSlice(Eo(n),t.parseOptions):Rn.fromSchema(c).parse(Eo(n),t.parseOptions),t.errorOnInvalidContent&&i)throw new Error("[tiptap error]: Invalid HTML content",{cause:new Error(`Invalid element found: ${l}`)})}const s=Rn.fromSchema(e);return t.slice?s.parseSlice(Eo(n),t.parseOptions).content:s.parse(Eo(n),t.parseOptions)}return vo("",e,t)}function P1(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 D1=n=>!("type"in n),_1=(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{vo(e,s.schema,{parseOptions:d,errorOnInvalidContent:!0})}catch(y){c(y)}try{l=vo(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((D1(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(),w=y.parentOffset===0,C=k.isText||k.isTextblock,x=k.content.size>0;w&&C&&x&&(u=Math.max(0,u-1)),o.replaceWith(u,f,g)}t.updateSelection&&P1(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},L1=()=>({state:n,dispatch:e})=>lg(n,e),V1=()=>({state:n,dispatch:e})=>ag(n,e),$1=()=>({state:n,dispatch:e})=>Rc(n,e),z1=()=>({state:n,dispatch:e})=>Lc(n,e),F1=()=>({state:n,dispatch:e,tr:t})=>{try{const o=sr(n.doc,n.selection.$from.pos,-1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},H1=()=>({state:n,dispatch:e,tr:t})=>{try{const o=sr(n.doc,n.selection.$from.pos,1);return o==null?!1:(t.join(o,2),e&&e(t),!0)}catch{return!1}},U1=()=>({state:n,dispatch:e})=>sg(n,e),j1=()=>({state:n,dispatch:e})=>ig(n,e);function hu(){return typeof navigator<"u"?/Mac/.test(navigator.platform):!1}function W1(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))Cr()||hu()?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 K1=n=>({editor:e,view:t,tr:o,dispatch:r})=>{const s=W1(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 Mo(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=>br(f.node.attrs,t,{strict:!1}));return s?!!d.length:d.reduce((f,h)=>f+h.to-h.from,0)>=c}var q1=(n,e={})=>({state:t,dispatch:o})=>{const r=we(n,t.schema);return Mo(t,r,e)?cg(t,o):!1},J1=()=>({state:n,dispatch:e})=>Fc(n,e),G1=n=>({state:e,dispatch:t})=>{const o=we(n,e.schema);return Cg(o)(e,t)},Y1=()=>({state:n,dispatch:e})=>$c(n,e);function xr(n,e){return e.nodes[n]?"node":e.marks[n]?"mark":null}function pu(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 X1=(n,e)=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=xr(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=we(n,o.schema)),l==="mark"&&(i=Mt(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,pu(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(pu(h.attrs,e))))})})}),c},Q1=()=>({tr:n,dispatch:e})=>(e&&n.scrollIntoView(),!0),Z1=()=>({tr:n,dispatch:e})=>{if(e){const t=new je(n.doc);n.setSelection(t)}return!0},ey=()=>({state:n,dispatch:e})=>Dc(n,e),ty=()=>({state:n,dispatch:e})=>Vc(n,e),ny=()=>({state:n,dispatch:e})=>hg(n,e),oy=()=>({state:n,dispatch:e})=>gg(n,e),ry=()=>({state:n,dispatch:e})=>mg(n,e);function Vi(n,e,t={},o={}){return vo(n,e,{slice:!1,parseOptions:t,errorOnInvalidContent:o.errorOnInvalidContent})}var sy=(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=Vi(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 mu(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,c=>{i.push(...c.marks)});const l=i.find(c=>c.type.name===t.name);return l?{...l.attrs}:{}}function gu(n,e){const t=new Sc(n);return e.forEach(o=>{o.steps.forEach(r=>{t.step(r)})}),t}function iy(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 ly(n,e,t){const o=[];return n.nodesBetween(e.from,e.to,(r,s)=>{t(r)&&o.push({node:r,pos:s})}),o}function ay(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 $i(n){return e=>ay(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 zi(n){return n.map(e=>{const t={name:e.name,options:e.options,storage:e.storage},o=H(e,"addExtensions",t);return o?[e,...zi(o())]:e}).flat(10)}function Sr(n,e){const t=dn.fromSchema(e).serializeFragment(n),r=document.implementation.createHTMLDocument().createElement("div");return r.appendChild(t),r.innerHTML}function yu(n){return typeof n=="function"}function ne(n,e=void 0,...t){return yu(n)?e?n.bind(e)(...t):n(...t):n}function cy(n={}){return Object.keys(n).length===0&&n.constructor===Object}function Kn(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 ku(n){const e=[],{nodeExtensions:t,markExtensions:o}=Kn(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 Gt(...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 Er(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)=>Gt(t,o),{})}function dy(n){return typeof n!="string"?n:n.match(/^[+-]?(?:\d*\.)?\d+$/)?Number(n):n==="true"?!0:n==="false"?!1:n}function wu(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):dy(t.getAttribute(i.name));return l==null?s:{...s,[i.name]:l}},{});return{...o,...r}}}}function bu(n){return Object.fromEntries(Object.entries(n).filter(([e,t])=>e==="attrs"&&cy(t)?!1:t!=null))}function Cu(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 xu(n,e){var t;const o=ku(n),{nodeExtensions:r,markExtensions:s}=Kn(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,w)=>{const C=H(w,"extendNodeSchema",f);return{...k,...C?C(d):{}}},{}),p=bu({...h,content:ne(H(d,"content",f)),marks:ne(H(d,"marks",f)),group:ne(H(d,"group",f)),inline:ne(H(d,"inline",f)),atom:ne(H(d,"atom",f)),selectable:ne(H(d,"selectable",f)),draggable:ne(H(d,"draggable",f)),code:ne(H(d,"code",f)),whitespace:ne(H(d,"whitespace",f)),linebreakReplacement:ne(H(d,"linebreakReplacement",f)),defining:ne(H(d,"defining",f)),isolating:ne(H(d,"isolating",f)),attrs:Object.fromEntries(u.map(Cu))}),m=ne(H(d,"parseHTML",f));m&&(p.parseDOM=m.map(k=>wu(k,u)));const g=H(d,"renderHTML",f);g&&(p.toDOM=k=>g({node:k,HTMLAttributes:Er(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 w=H(k,"extendMarkSchema",f);return{...y,...w?w(d):{}}},{}),p=bu({...h,inclusive:ne(H(d,"inclusive",f)),excludes:ne(H(d,"excludes",f)),group:ne(H(d,"group",f)),spanning:ne(H(d,"spanning",f)),code:ne(H(d,"code",f)),attrs:Object.fromEntries(u.map(Cu))}),m=ne(H(d,"parseHTML",f));m&&(p.parseDOM=m.map(y=>wu(y,u)));const g=H(d,"renderHTML",f);return g&&(p.toDOM=y=>g({mark:y,HTMLAttributes:Er(y,u)})),[d.name,p]}));return new Xa({topNode:i,nodes:l,marks:c})}function uy(n){const e=n.filter((t,o)=>n.indexOf(t)!==o);return Array.from(new Set(e))}function To(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 Fi(n){const e=To(zi(n)),t=uy(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 Su(n,e){const t=Fi(n);return xu(t,e)}function qn(n,e){const t=Su(e),o=bt.fromJSON(t,n);return Sr(o.content,t)}function tt(n,e){const t=Su(e),o=Eo(n);return Rn.fromSchema(t).parse(o).toJSON()}function Eu(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 fy(n,e){const t={from:0,to:n.content.size};return Eu(n,t,e)}function vu(n){return Object.fromEntries(Object.entries(n.nodes).filter(([,e])=>e.spec.toText).map(([e,t])=>[e,t.spec.toText]))}function hy(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 Mu(n,e){const t=xr(typeof e=="string"?e:e.name,n.schema);return t==="node"?hy(n,e):t==="mark"?mu(n,e):{}}function py(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 my(n){const e=py(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 Tu(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}})})}),my(o)}function Hi(n,e,t){const o=[];return n===e?t.resolve(n).marks().forEach(r=>{const s=t.resolve(n),i=Li(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 No(n,e){return e.nodes[n]||e.marks[n]||null}function vr(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 gy=(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 Ui(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=>br(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),w=Math.min(m,y+g.nodeSize),C=w-k;i+=C,l.push(...g.marks.map(x=>({mark:x,from:k,to:w})))})}),i===0)return!1;const c=l.filter(f=>s?s.name===f.mark.type.name:!0).filter(f=>br(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 yy(n,e,t={}){if(!e)return Mo(n,null,t)||Ui(n,null,t);const o=xr(e,n.schema);return o==="node"?Mo(n,e,t):o==="mark"?Ui(n,e,t):!1}function Nu(n,e){return Array.isArray(e)?e.some(t=>(typeof t=="string"?t:t.name)===n.name):e}function Au(n,e){const{nodeExtensions:t}=Kn(e),o=t.find(i=>i.name===n);if(!o)return!1;const r={name:o.name,options:o.options,storage:o.storage},s=ne(H(o,"group",r));return typeof s!="string"?!1:s.split(" ").includes("list")}function Mr(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&&(Mr(s,{ignoreWhitespace:t,checkChildren:e})||(r=!1))}),r}return!1}function ky(n){return n instanceof q}var Bu=class np{constructor(e){this.position=e}static fromJSON(e){return new np(e.position)}toJSON(){return{position:this.position}}};function wy(n,e){const t=e.mapping.mapResult(n.position);return{position:new Bu(t.pos),mapResult:t}}function by(n){return new Bu(n)}function Cy(n,e,t){var o;const{selection:r}=e;let s=null;if(cu(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 xy=(n,e={})=>({tr:t,state:o,dispatch:r})=>{const{selection:s}=t,{empty:i,ranges:l}=s,c=Mt(n,o.schema);if(r)if(i){const d=mu(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 Cy(o,t,c)},Sy=(n,e)=>({tr:t})=>(t.setMeta(n,e),!0),Ey=(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})=>jc(s,{...i,...e})(t)?!0:l.clearNodes()).command(({state:l})=>jc(s,{...i,...e})(l,o)).run():(console.warn('[tiptap warn]: Currently "setNode()" only supports text block nodes.'),!1)},vy=n=>({tr:e,dispatch:t})=>{if(t){const{doc:o}=e,r=bn(n,0,o.content.size),s=q.create(o,r);e.setSelection(s)}return!0},My=(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},Ty=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=bn(r,i,l),d=bn(s,i,l),u=Y.create(o,c,d);e.setSelection(u)}return!0},Ny=n=>({state:e,dispatch:t})=>{const o=we(n,e.schema);return Eg(o)(e,t)};function Iu(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 Ay=({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=vr(d,l.node().type.name,l.node().attrs);if(s instanceof q&&s.node.isBlock)return!l.parentOffset||!Ct(i,l.pos)?!1:(o&&(n&&Iu(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:iy(l.node(-1).contentMatchAt(l.indexAfter(-1)));let p=f&&h?[{type:h,attrs:u}]:void 0,m=Ct(e.doc,e.mapping.map(l.pos),1,p);if(!p&&!m&&Ct(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&&Iu(t,r.extensionManager.splittableMarks),e.scrollIntoView()}return m},By=(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 w=c.index(-1)?1:c.index(-2)?2:3;for(let T=c.depth-w;T>=c.depth-3;T-=1)k=O.from(c.node(T).copy(k));const C=c.indexAfter(-1)<c.node(-2).childCount?1:c.indexAfter(-2)<c.node(-3).childCount?2:3,x={...vr(h,c.node().type.name,c.node().attrs),...e},S=((i=l.contentMatch.defaultType)==null?void 0:i.createAndFill(x))||void 0;k=k.append(O.from(l.createAndFill(null,S)||void 0));const M=c.before(c.depth-(w-1));t.replace(M,c.after(-C),new $(k,4-w,0));let E=-1;t.doc.nodesBetween(M,t.doc.content.size,(T,v)=>{if(E>-1)return!1;T.isTextblock&&T.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={...vr(h,f.type.name,f.attrs),...e},g={...vr(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(!Ct(t.doc,c.pos,2))return!1;if(r){const{selection:k,storedMarks:w}=o,{splittableMarks:C}=s.extensionManager,x=w||k.$to.parentOffset&&k.$from.marks();if(t.split(c.pos,2,y).scrollIntoView(),!x||!r)return!0;const S=x.filter(M=>C.includes(M.type.name));t.ensureMarks(S)}return!0},ji=(n,e)=>{const t=$i(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)&&fn(n.doc,t.pos)&&n.join(t.pos),!0},Wi=(n,e)=>{const t=$i(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)&&fn(n.doc,o)&&n.join(o),!0},Iy=(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:w}=g,C=k.blockRange(w),x=y||g.$to.parentOffset&&g.$from.marks();if(!C)return!1;const S=$i(M=>Au(M.type.name,f))(g);if(C.depth>=1&&S&&C.depth-S.depth<=1){if(S.node.type===p)return d.liftListItem(m);if(Au(S.node.type.name,f)&&p.validContent(S.node.content)&&l)return c().command(()=>(s.setNodeMarkup(S.pos,p),!0)).command(()=>ji(s,p)).command(()=>Wi(s,p)).run()}return!t||!x||!l?c().command(()=>u().wrapInList(p,o)?!0:d.clearNodes()).wrapInList(p,o).command(()=>ji(s,p)).command(()=>Wi(s,p)).run():c().command(()=>{const M=u().wrapInList(p,o),E=x.filter(T=>h.includes(T.type.name));return s.ensureMarks(E),M?!0:d.clearNodes()}).wrapInList(p,o).command(()=>ji(s,p)).command(()=>Wi(s,p)).run()},Oy=(n,e={},t={})=>({state:o,commands:r})=>{const{extendEmptyMarkRange:s=!1}=t,i=Mt(n,o.schema);return Ui(o,i,e)?r.unsetMark(i,{extendEmptyMarkRange:s}):r.setMark(i,e)},Ry=(n,e,t={})=>({state:o,commands:r})=>{const s=we(n,o.schema),i=we(e,o.schema),l=Mo(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})},Py=(n,e={})=>({state:t,commands:o})=>{const r=we(n,t.schema);return Mo(t,r,e)?o.lift(r):o.wrapIn(r,e)},Dy=()=>({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},_y=()=>({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},Ly=(n,e={})=>({tr:t,state:o,dispatch:r})=>{var s;const{extendEmptyMarkRange:i=!1}=e,{selection:l}=t,c=Mt(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=Li(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},Vy=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},$y=(n,e={})=>({tr:t,state:o,dispatch:r})=>{let s=null,i=null;const l=xr(typeof n=="string"?n:n.name,o.schema);if(!l)return!1;l==="node"&&(s=we(n,o.schema)),l==="mark"&&(i=Mt(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(w=>{if(i===w.type&&(c=!0,r)){const C=Math.max(k,u),x=Math.min(k+y.nodeSize,f);t.addMark(C,x,i.create({...w.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},zy=(n,e={})=>({state:t,dispatch:o})=>{const r=we(n,t.schema);return yg(r,e)(t,o)},Fy=(n,e={})=>({state:t,dispatch:o})=>{const r=we(n,t.schema);return kg(r,e)(t,o)},Hy=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={}}},Uy=class{constructor(n){var e;this.find=n.find,this.handler=n.handler,this.undoable=(e=n.undoable)!=null?e:!0}},jy=(n,e)=>{if(_i(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 Tr(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=gy(d)+s;return i.forEach(h=>{if(u)return;const p=jy(f,h.find);if(!p)return;const m=c.state.tr,g=kr({state:c.state,transaction:m}),y={from:o-(p[0].length-s.length),to:r},{commands:k,chain:w,can:C}=new wr({editor:t,state:g});h.handler({state:g,range:y,match:p,commands:k,chain:w,can:C})===null||!m.steps.length||(h.undoable&&m.setMeta(l,{transform:m,from:o,to:r,text:s}),c.dispatch(m),u=!0)}),u}function Wy(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=Sr(O.from(u),i.schema);const{from:f}=c,h=f+u.length;Tr({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 Tr({editor:e,from:s,to:i,text:l,rules:t,plugin:o})},handleDOMEvents:{compositionend:r=>(setTimeout(()=>{const{$cursor:s}=r.state.selection;s&&Tr({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?Tr({editor:e,from:i.pos,to:i.pos,text:`
13
+ `,rules:t,plugin:o}):!1}},isInputRules:!0});return o}function Ky(n){return Object.prototype.toString.call(n).slice(8,-1)}function Nr(n){return Ky(n)!=="Object"?!1:n.constructor===Object&&Object.getPrototypeOf(n)===Object.prototype}function Ou(n,e){const t={...n};return Nr(n)&&Nr(e)&&Object.keys(e).forEach(o=>{Nr(e[o])&&Nr(n[o])?t[o]=Ou(n[o],e[o]):t[o]=e[o]}),t}var Ki=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{...ne(H(this,"addOptions",{name:this.name}))||{}}}get storage(){return{...ne(H(this,"addStorage",{name:this.name,options:this.options}))||{}}}configure(n={}){const e=this.extend({...this.config,addOptions:()=>Ou(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}},Jn=class op extends Ki{constructor(){super(...arguments),this.type="mark"}static create(e={}){const t=typeof e=="function"?e():e;return new op(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 qy(n){return typeof n=="number"}var Jy=class{constructor(n){this.find=n.find,this.handler=n.handler}},Gy=(n,e,t)=>{if(_i(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 Yy(n){const{editor:e,state:t,from:o,to:r,rule:s,pasteEvent:i,dropEvent:l}=n,{commands:c,chain:d,can:u}=new wr({editor:e,state:t}),f=[];return t.doc.nodesBetween(o,r,(p,m)=>{var g,y,k,w,C;if((y=(g=p.type)==null?void 0:g.spec)!=null&&y.code||!(p.isText||p.isTextblock||p.isInline))return;const x=(C=(w=(k=p.content)==null?void 0:k.size)!=null?w:p.nodeSize)!=null?C:0,S=Math.max(o,m),M=Math.min(r,m+x);if(S>=M)return;const E=p.isText?p.text||"":p.textBetween(S-m,M-m,void 0,"");Gy(E,s.find,i).forEach(v=>{if(v.index===void 0)return;const B=S+v.index+1,I=B+v[0].length,D={from:t.tr.mapping.map(B),to:t.tr.mapping.map(I)},V=s.handler({state:t,range:D,match:v,commands:c,chain:d,can:u,pasteEvent:i,dropEvent:l});f.push(V)})}),f.every(p=>p!==null)}var Ar=null,Xy=n=>{var e;const t=new ClipboardEvent("paste",{clipboardData:new DataTransfer});return(e=t.clipboardData)==null||e.setData("text/html",n),t};function Qy(n){const{editor:e,rules:t}=n;let o=null,r=!1,s=!1,i=typeof ClipboardEvent<"u"?new ClipboardEvent("paste"):null,l;try{l=typeof DragEvent<"u"?new DragEvent("drop"):null}catch{l=null}const c=({state:u,from:f,to:h,rule:p,pasteEvt:m})=>{const g=u.tr,y=kr({state:u,transaction:g});if(!(!Yy({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&&(Ar=e)},p=()=>{Ar&&(Ar=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=Ar;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"),w=!!k;if(!g&&!y&&!w)return;if(w){let{text:S}=k;typeof S=="string"?S=S:S=Sr(O.from(S),p.schema);const{from:M}=k,E=M+S.length,T=Xy(S);return c({rule:u,state:p,from:M,to:{b:E},pasteEvt:T})}const C=h.doc.content.findDiffStart(p.doc.content),x=h.doc.content.findDiffEnd(p.doc.content);if(!(!qy(C)||!x||C===x.b))return c({rule:u,state:p,from:C,to:x,pasteEvt:i})}}))}var Br=class{constructor(n,e){this.splittableMarks=[],this.editor=e,this.baseExtensions=n,this.extensions=Fi(n),this.schema=xu(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:No(e.name,this.schema)},o=H(e,"addCommands",t);return o?{...n,...o()}:n},{})}get plugins(){const{editor:n}=this;return To([...this.extensions].reverse()).flatMap(o=>{const r={name:o.name,options:o.options,storage:this.editor.extensionStorage[o.name],editor:n,type:No(o.name,this.schema)},s=[],i=H(o,"addKeyboardShortcuts",r);let l={};if(o.type==="mark"&&H(o,"exitable",r)&&(l.ArrowRight=()=>Jn.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=p1(l);s.push(c);const d=H(o,"addInputRules",r);if(Nu(o,n.options.enableInputRules)&&d){const h=d();if(h&&h.length){const p=Wy({editor:n,rules:h}),m=Array.isArray(p)?p:[p];s.push(...m)}}const u=H(o,"addPasteRules",r);if(Nu(o,n.options.enablePasteRules)&&u){const h=u();if(h&&h.length){const p=Qy({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 ku(this.extensions)}get nodeViews(){const{editor:n}=this,{nodeExtensions:e}=Kn(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=Er(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 To([...this.extensions].reverse()).reduceRight((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:No(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 To([...this.extensions]).reduce((o,r)=>{const s={name:r.name,options:r.options,storage:this.editor.extensionStorage[r.name],editor:e,type:No(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}=Kn(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:Mt(t.name,this.schema)},s=H(t,"addMarkView",r);if(!s)return[];const i=(l,c,d)=>{const u=Er(l,o);return s()({mark:l,view:c,inline:d,editor:n,extension:t,HTMLAttributes:u,updateAttributes:f=>{fk(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:No(e.name,this.schema)};e.type==="mark"&&((t=ne(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)})}};Br.resolve=Fi,Br.sort=To,Br.flatten=zi;var Zy={};Di(Zy,{ClipboardTextSerializer:()=>Ru,Commands:()=>Pu,Delete:()=>Du,Drop:()=>_u,Editable:()=>Lu,FocusEvents:()=>$u,Keymap:()=>zu,Paste:()=>Fu,Tabindex:()=>Hu,TextDirection:()=>Uu,focusEventsPluginKey:()=>Vu});var re=class rp extends Ki{constructor(){super(...arguments),this.type="extension"}static create(e={}){const t=typeof e=="function"?e():e;return new rp(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}},Ru=re.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=vu(t);return Eu(o,{from:i,to:l},{...this.options.blockSeparator!==void 0?{blockSeparator:this.options.blockSeparator}:{},textSerializers:c})}}})]}}),Pu=re.create({name:"commands",addCommands(){return{...iu}}}),Du=re.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=gu(n.before,[n,...e]);Tu(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 et){const k=h.slice(m).map(p.from,-1),w=h.slice(m).map(p.to),C=h.invert().map(k,-1),x=h.invert().map(w),S=(g=u.doc.nodeAt(k-1))==null?void 0:g.marks.some(E=>E.eq(p.mark)),M=(y=u.doc.nodeAt(w))==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:C,to:x},newRange:{from:k,to:w},partial:!!(M||S),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()}}),_u=re.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})}}})]}}),Lu=re.create({name:"editable",addProseMirrorPlugins(){return[new ue({key:new ke("editable"),props:{editable:()=>this.editor.options.editable}})]}}),Vu=new ke("focusEvents"),$u=re.create({name:"focusEvents",addProseMirrorPlugins(){const{editor:n}=this;return[new ue({key:Vu,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}}}})]}}),zu=re.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 Cr()||hu()?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)||!Mr(t.doc))return;const h=t.tr,p=kr({state:t,transaction:h}),{commands:m}=new wr({editor:this.editor,state:p});if(m.clearNodes(),!!h.steps.length)return h}})]}}),Fu=re.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})}}})]}}),Hu=re.create({name:"tabindex",addProseMirrorPlugins(){return[new ue({key:new ke("tabindex"),props:{attributes:()=>this.editor.isEditable?{tabindex:"0"}:{}}})]}}),Uu=re.create({name:"textDirection",addOptions(){return{direction:void 0}},addGlobalAttributes(){if(!this.options.direction)return[];const{nodeExtensions:n}=Kn(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}:{}}}})]}}),ek=class Ko{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 Ko(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 Ko(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 Ko(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 Ko(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)}},tk=`.ProseMirror {
14
14
  position: relative;
15
15
  }
16
16
 
@@ -80,24 +80,28 @@ 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 nk(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 ok=class extends Hy{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:wy,createMappablePosition:by},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=du(t,this.options.autofocus);this.editorState=Vn.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=nk(tk,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=yu(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?[Lu,Ru.configure({blockSeparator:(t=(e=this.options.coreExtensionOptions)==null?void 0:e.clipboardTextSerializer)==null?void 0:t.blockSeparator}),Pu,$u,zu,Hu,_u,Fu,Du,Uu.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 Br(r,this)}createCommandManager(){this.commandManager=new wr({editor:this})}createSchema(){this.schema=this.extensionManager.schema}createDoc(){let e;try{e=Vi(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=Vi(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 Zd(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 Mu(this.state,e)}isActive(e,t){const o=typeof e=="string"?e:null,r=typeof e=="string"?t:e;return yy(this.state,o,r)}getJSON(){return this.state.doc.toJSON()}getHTML(){return Sr(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 fy(this.state.doc,{blockSeparator:t,textSerializers:{...vu(this.schema),...o}})}get isEmpty(){return Mr(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 ek(t,this)}get $doc(){return this.$pos(0)}};function Ir(n){return new Uy({find:n.find,handler:({state:e,range:t,match:o})=>{const r=ne(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(Hi(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 rk={};Di(rk,{createAtomBlockMarkdownSpec:()=>sk,createBlockMarkdownSpec:()=>ik,createInlineMarkdownSpec:()=>ck,parseAttributes:()=>qi,parseIndentedBlocks:()=>dk,renderNestedMarkdownContent:()=>uk,serializeAttributes:()=>Ji});function qi(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 Ji(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 sk(n){const{nodeName:e,name:t,parseAttributes:o=qi,serializeAttributes:r=Ji,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(w=>!(w 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 ik(n){const{nodeName:e,name:t,getContent:o,parseAttributes:r=qi,serializeAttributes:s=Ji,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,w=""]=y,C=r(w);let x=1;const S=k.length;let M="";const E=/^:::([\w-]*)(\s.*)?/gm,T=f.slice(S);for(E.lastIndex=0;;){const v=E.exec(T);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 D=T.slice(0,B);M=D.trim();const V=f.slice(0,S+B+v[0].length);let z=[];if(M)if(l==="block")for(z=p.blockTokens(D),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(M);return{type:e,raw:V,attributes:C,content:M,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}
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"})});
91
+ :::`}}}function lk(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 ak(n){return Object.entries(n).filter(([,e])=>e!=null).map(([e,t])=>`${e}="${t}"`).join(" ")}function ck(n){const{nodeName:e,name:t,getContent:o,parseAttributes:r=lk,serializeAttributes:s=ak,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="",w="";if(l){const[,x]=y;w=x}else{const[,x,S]=y;w=x,k=S||""}const C=r(w.trim());return{type:e,raw:y[0],content:k.trim(),attributes:C}}},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 dk(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 S=l[u];if(S.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(S),d=`${d}${S}
95
+ `,u+=1;continue}else break}if((((i=(s=S.match(/^(\s*)/))==null?void 0:s[1])==null?void 0:i.length)||0)>g)k.push(S),d=`${d}${S}
96
+ `,u+=1;else break}let w;const C=k.slice(1);if(C.length>0){const S=C.map(M=>M.slice(g+f)).join(`
97
+ `);S.trim()&&(e.customNestedParser?w=e.customNestedParser(S):w=t.blockTokens(S))}const x=e.createToken(m,w);c.push(x)}if(c.length!==0)return{items:c,raw:d}}function uk(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 fk(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 Gi=class sp extends Ki{constructor(){super(...arguments),this.type="node"}static create(e={}){const t=typeof e=="function"?e():e;return new sp(t)}configure(e){return super.configure(e)}extend(e){const t=typeof e=="function"?e():e;return super.extend(t)}};function Ao(n){return new Jy({find:n.find,handler:({state:e,range:t,match:o,pasteEvent:r})=>{const s=ne(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(Hi(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 ju(n){return a.customRef((e,t)=>({get(){return e(),n},set(o){n=o,requestAnimationFrame(()=>{requestAnimationFrame(()=>{t()})})}}))}var hk=class extends ok{constructor(n={}){return super(n),this.contentComponent=null,this.appContext=null,this.reactiveState=ju(this.view.state),this.reactiveExtensionStorage=ju(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}},pk=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 mk=Gi.create({name:"doc",topNode:!0,content:"block+",renderMarkdown:(n,e)=>n.content?e.renderChildren(n.content,`
101
+
102
+ `):""}),Wu=mk,Ku="&nbsp;",gk=" ",yk=Gi.create({name:"paragraph",priority:1e3,addOptions(){return{HTMLAttributes:{}}},group:"block",content:"inline*",parseHTML(){return[{tag:"p"}]},renderHTML({HTMLAttributes:n}){return["p",Gt(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===Ku||o[0].text===gk)?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?Ku:e.renderChildren(t)},addCommands(){return{setParagraph:()=>({commands:n})=>n.setNode(this.name)}},addKeyboardShortcuts(){return{"Mod-Alt-0":()=>this.editor.commands.setParagraph()}}}),qu=yk,kk=Gi.create({name:"text",group:"inline",parseMarkdown:n=>({type:"text",text:n.text||""}),renderMarkdown:n=>n.text||""}),Ju=kk,Gu=(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]},wk=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))$/,bk=/(?:^|\s)(\*\*(?!\s+\*\*)((?:[^*]+))\*\*(?!\s+\*\*))/g,Ck=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))$/,xk=/(?:^|\s)(__(?!\s+__)((?:[^_]+))__(?!\s+__))/g,Sk=Jn.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 Gu("strong",{...Gt(this.options.HTMLAttributes,n),children:Gu("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[Ir({find:wk,type:this.type}),Ir({find:Ck,type:this.type})]},addPasteRules(){return[Ao({find:bk,type:this.type}),Ao({find:xk,type:this.type})]}}),Yu=Sk,Ek=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))$/,vk=/(?:^|\s)(\*(?!\s+\*)((?:[^*]+))\*(?!\s+\*))/g,Mk=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))$/,Tk=/(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g,Nk=Jn.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",Gt(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[Ir({find:Ek,type:this.type}),Ir({find:Mk,type:this.type})]},addPasteRules(){return[Ao({find:vk,type:this.type}),Ao({find:Tk,type:this.type})]}}),Xu=Nk,Ak=Jn.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",Gt(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()}}}),Qu=Ak;const Bk="aaa1rp3bb0ott3vie4c1le2ogado5udhabi7c0ademy5centure6ountant0s9o1tor4d0s1ult4e0g1ro2tna4f0l1rica5g0akhan5ency5i0g1rbus3force5tel5kdn3l0ibaba4pay4lfinanz6state5y2sace3tom5m0azon4ericanexpress7family11x2fam3ica3sterdam8nalytics7droid5quan4z2o0l2partments8p0le4q0uarelle8r0ab1mco4chi3my2pa2t0e3s0da2ia2sociates9t0hleta5torney7u0ction5di0ble3o3spost5thor3o0s4w0s2x0a2z0ure5ba0by2idu3namex4d1k2r0celona5laycard4s5efoot5gains6seball5ketball8uhaus5yern5b0c1t1va3cg1n2d1e0ats2uty4er2rlin4st0buy5t2f1g1h0arti5i0ble3d1ke2ng0o3o1z2j1lack0friday9ockbuster8g1omberg7ue3m0s1w2n0pparibas9o0ats3ehringer8fa2m1nd2o0k0ing5sch2tik2on4t1utique6x2r0adesco6idgestone9oadway5ker3ther5ussels7s1t1uild0ers6siness6y1zz3v1w1y1z0h3ca0b1fe2l0l1vinklein9m0era3p2non3petown5ital0one8r0avan4ds2e0er0s4s2sa1e1h1ino4t0ering5holic7ba1n1re3c1d1enter4o1rn3f0a1d2g1h0anel2nel4rity4se2t2eap3intai5ristmas6ome4urch5i0priani6rcle4sco3tadel4i0c2y3k1l0aims4eaning6ick2nic1que6othing5ud3ub0med6m1n1o0ach3des3ffee4llege4ogne5m0mbank4unity6pany2re3uter5sec4ndos3struction8ulting7tact3ractors9oking4l1p2rsica5untry4pon0s4rses6pa2r0edit0card4union9icket5own3s1uise0s6u0isinella9v1w1x1y0mru3ou3z2dad1nce3ta1e1ing3sun4y2clk3ds2e0al0er2s3gree4livery5l1oitte5ta3mocrat6ntal2ist5si0gn4v2hl2iamonds6et2gital5rect0ory7scount3ver5h2y2j1k1m1np2o0cs1tor4g1mains5t1wnload7rive4tv2ubai3nlop4pont4rban5vag2r2z2earth3t2c0o2deka3u0cation8e1g1mail3erck5nergy4gineer0ing9terprises10pson4quipment8r0icsson6ni3s0q1tate5t1u0rovision8s2vents5xchange6pert3osed4ress5traspace10fage2il1rwinds6th3mily4n0s2rm0ers5shion4t3edex3edback6rrari3ero6i0delity5o2lm2nal1nce1ial7re0stone6mdale6sh0ing5t0ness6j1k1lickr3ghts4r2orist4wers5y2m1o0o0d1tball6rd1ex2sale4um3undation8x2r0ee1senius7l1ogans4ntier7tr2ujitsu5n0d2rniture7tbol5yi3ga0l0lery3o1up4me0s3p1rden4y2b0iz3d0n2e0a1nt0ing5orge5f1g0ee3h1i0ft0s3ves2ing5l0ass3e1obal2o4m0ail3bh2o1x2n1odaddy5ld0point6f2o0dyear5g0le4p1t1v2p1q1r0ainger5phics5tis4een3ipe3ocery4up4s1t1u0cci3ge2ide2tars5ru3w1y2hair2mburg5ngout5us3bo2dfc0bank7ealth0care8lp1sinki6re1mes5iphop4samitsu7tachi5v2k0t2m1n1ockey4ldings5iday5medepot5goods5s0ense7nda3rse3spital5t0ing5t0els3mail5use3w2r1sbc3t1u0ghes5yatt3undai7ibm2cbc2e1u2d1e0ee3fm2kano4l1m0amat4db2mo0bilien9n0c1dustries8finiti5o2g1k1stitute6urance4e4t0ernational10uit4vestments10o1piranga7q1r0ish4s0maili5t0anbul7t0au2v3jaguar4va3cb2e0ep2tzt3welry6io2ll2m0p2nj2o0bs1urg4t1y2p0morgan6rs3uegos4niper7kaufen5ddi3e0rryhotels6properties14fh2g1h1i0a1ds2m1ndle4tchen5wi3m1n1oeln3matsu5sher5p0mg2n2r0d1ed3uokgroup8w1y0oto4z2la0caixa5mborghini8er3nd0rover6xess5salle5t0ino3robe5w0yer5b1c1ds2ease3clerc5frak4gal2o2xus4gbt3i0dl2fe0insurance9style7ghting6ke2lly3mited4o2ncoln4k2ve1ing5k1lc1p2oan0s3cker3us3l1ndon4tte1o3ve3pl0financial11r1s1t0d0a3u0ndbeck6xe1ury5v1y2ma0drid4if1son4keup4n0agement7go3p1rket0ing3s4riott5shalls7ttel5ba2c0kinsey7d1e0d0ia3et2lbourne7me1orial6n0u2rckmsd7g1h1iami3crosoft7l1ni1t2t0subishi9k1l0b1s2m0a2n1o0bi0le4da2e1i1m1nash3ey2ster5rmon3tgage6scow4to0rcycles9v0ie4p1q1r1s0d2t0n1r2u0seum3ic4v1w1x1y1z2na0b1goya4me2vy3ba2c1e0c1t0bank4flix4work5ustar5w0s2xt0direct7us4f0l2g0o2hk2i0co2ke1on3nja3ssan1y5l1o0kia3rton4w0ruz3tv4p1r0a1w2tt2u1yc2z2obi1server7ffice5kinawa6layan0group9lo3m0ega4ne1g1l0ine5oo2pen3racle3nge4g0anic5igins6saka4tsuka4t2vh3pa0ge2nasonic7ris2s1tners4s1y3y2ccw3e0t2f0izer5g1h0armacy6d1ilips5one2to0graphy6s4ysio5ics1tet2ures6d1n0g1k2oneer5zza4k1l0ace2y0station9umbing5s3m1n0c2ohl2ker3litie5rn2st3r0axi3ess3ime3o0d0uctions8f1gressive8mo2perties3y5tection8u0dential9s1t1ub2w0c2y2qa1pon3uebec3st5racing4dio4e0ad1lestate6tor2y4cipes5d0stone5umbrella9hab3ise0n3t2liance6n0t0als5pair3ort3ublican8st0aurant8view0s5xroth6ich0ardli6oh3l1o1p2o0cks3deo3gers4om3s0vp3u0gby3hr2n2w0e2yukyu6sa0arland6fe0ty4kura4le1on3msclub4ung5ndvik0coromant12ofi4p1rl2s1ve2xo3b0i1s2c0b1haeffler7midt4olarships8ol3ule3warz5ience5ot3d1e0arch3t2cure1ity6ek2lect4ner3rvices6ven3w1x0y3fr2g1h0angrila6rp3ell3ia1ksha5oes2p0ping5uji3w3i0lk2na1gles5te3j1k0i0n2y0pe4l0ing4m0art3ile4n0cf3o0ccer3ial4ftbank4ware6hu2lar2utions7ng1y2y2pa0ce3ort2t3r0l2s1t0ada2ples4r1tebank4farm7c0group6ockholm6rage3e3ream4udio2y3yle4u0cks3pplies3y2ort5rf1gery5zuki5v1watch4iss4x1y0dney4stems6z2tab1ipei4lk2obao4rget4tamotors6r2too4x0i3c0i2d0k2eam2ch0nology8l1masek5nnis4va3f1g1h0d1eater2re6iaa2ckets5enda4ps2res2ol4j0maxx4x2k0maxx5l1m0all4n1o0day3kyo3ols3p1ray3shiba5tal3urs3wn2yota3s3r0ade1ing4ining5vel0ers0insurance16ust3v2t1ube2i1nes3shu4v0s2w1z2ua1bank3s2g1k1nicom3versity8o2ol2ps2s1y1z2va0cations7na1guard7c1e0gas3ntures6risign5mögensberater2ung14sicherung10t2g1i0ajes4deo3g1king4llas4n1p1rgin4sa1ion4va1o3laanderen9n1odka3lvo3te1ing3o2yage5u2wales2mart4ter4ng0gou5tch0es6eather0channel12bcam3er2site5d0ding5ibo2r3f1hoswho6ien2ki2lliamhill9n0dows4e1ners6me2olterskluwer11odside6rk0s2ld3w2s1tc1f3xbox3erox4ihuan4n2xx2yz3yachts4hoo3maxun5ndex5e1odobashi7ga2kohama6u0tube6t1un3za0ppos4ra3ero3ip2m1one3uerich6w2",Ik="ελ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",Yi="numeric",Xi="ascii",Qi="alpha",Bo="asciinumeric",Io="alphanumeric",Zi="domain",Zu="emoji",Ok="scheme",Rk="slashscheme",el="whitespace";function Pk(n,e){return n in e||(e[n]=[]),e[n]}function Cn(n,e,t){e[Yi]&&(e[Bo]=!0,e[Io]=!0),e[Xi]&&(e[Bo]=!0,e[Qi]=!0),e[Bo]&&(e[Io]=!0),e[Qi]&&(e[Io]=!0),e[Io]&&(e[Zi]=!0),e[Zu]&&(e[Zi]=!0);for(const o in e){const r=Pk(o,t);r.indexOf(n)<0&&r.push(n)}}function Dk(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&&Cn(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(Dk(i.t,o),t);Cn(s,c,o)}else t&&Cn(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),ef=(n,e,t,o,r)=>n.ts(e,t,o,r),P=(n,e,t,o,r)=>n.tt(e,t,o,r),Tt="WORD",tl="UWORD",tf="ASCIINUMERICAL",nf="ALPHANUMERICAL",Oo="LOCALHOST",nl="TLD",ol="UTLD",Or="SCHEME",Gn="SLASH_SCHEME",rl="NUM",sl="WS",il="NL",Ro="OPENBRACE",Po="CLOSEBRACE",Rr="OPENBRACKET",Pr="CLOSEBRACKET",Dr="OPENPAREN",_r="CLOSEPAREN",Lr="OPENANGLEBRACKET",Vr="CLOSEANGLEBRACKET",$r="FULLWIDTHLEFTPAREN",zr="FULLWIDTHRIGHTPAREN",Fr="LEFTCORNERBRACKET",Hr="RIGHTCORNERBRACKET",Ur="LEFTWHITECORNERBRACKET",jr="RIGHTWHITECORNERBRACKET",Wr="FULLWIDTHLESSTHAN",Kr="FULLWIDTHGREATERTHAN",qr="AMPERSAND",Jr="APOSTROPHE",Gr="ASTERISK",Yt="AT",Yr="BACKSLASH",Xr="BACKTICK",Qr="CARET",Xt="COLON",ll="COMMA",Zr="DOLLAR",ft="DOT",es="EQUALS",al="EXCLAMATION",Qe="HYPHEN",Do="PERCENT",ts="PIPE",ns="PLUS",rs="POUND",_o="QUERY",cl="QUOTE",of="FULLWIDTHMIDDLEDOT",dl="SEMI",ht="SLASH",Lo="TILDE",ss="UNDERSCORE",rf="EMOJI",is="SYM";var sf=Object.freeze({__proto__:null,ALPHANUMERICAL:nf,AMPERSAND:qr,APOSTROPHE:Jr,ASCIINUMERICAL:tf,ASTERISK:Gr,AT:Yt,BACKSLASH:Yr,BACKTICK:Xr,CARET:Qr,CLOSEANGLEBRACKET:Vr,CLOSEBRACE:Po,CLOSEBRACKET:Pr,CLOSEPAREN:_r,COLON:Xt,COMMA:ll,DOLLAR:Zr,DOT:ft,EMOJI:rf,EQUALS:es,EXCLAMATION:al,FULLWIDTHGREATERTHAN:Kr,FULLWIDTHLEFTPAREN:$r,FULLWIDTHLESSTHAN:Wr,FULLWIDTHMIDDLEDOT:of,FULLWIDTHRIGHTPAREN:zr,HYPHEN:Qe,LEFTCORNERBRACKET:Fr,LEFTWHITECORNERBRACKET:Ur,LOCALHOST:Oo,NL:il,NUM:rl,OPENANGLEBRACKET:Lr,OPENBRACE:Ro,OPENBRACKET:Rr,OPENPAREN:Dr,PERCENT:Do,PIPE:ts,PLUS:ns,POUND:rs,QUERY:_o,QUOTE:cl,RIGHTCORNERBRACKET:Hr,RIGHTWHITECORNERBRACKET:jr,SCHEME:Or,SEMI:dl,SLASH:ht,SLASH_SCHEME:Gn,SYM:is,TILDE:Lo,TLD:nl,UNDERSCORE:ss,UTLD:ol,UWORD:tl,WORD:Tt,WS:sl});const Nt=/[a-z]/,Vo=new RegExp("\\p{L}","u"),ul=new RegExp("\\p{Emoji}","u"),At=/\d/,fl=/\s/,lf="\r",hl=`
103
+ `,_k="️",Lk="‍",pl="";let ls=null,as=null;function Vk(n=[]){const e={};ze.groups=e;const t=new ze;ls==null&&(ls=cf(Bk)),as==null&&(as=cf(Ik)),P(t,"'",Jr),P(t,"{",Ro),P(t,"}",Po),P(t,"[",Rr),P(t,"]",Pr),P(t,"(",Dr),P(t,")",_r),P(t,"<",Lr),P(t,">",Vr),P(t,"(",$r),P(t,")",zr),P(t,"「",Fr),P(t,"」",Hr),P(t,"『",Ur),P(t,"』",jr),P(t,"<",Wr),P(t,">",Kr),P(t,"&",qr),P(t,"*",Gr),P(t,"@",Yt),P(t,"`",Xr),P(t,"^",Qr),P(t,":",Xt),P(t,",",ll),P(t,"$",Zr),P(t,".",ft),P(t,"=",es),P(t,"!",al),P(t,"-",Qe),P(t,"%",Do),P(t,"|",ts),P(t,"+",ns),P(t,"#",rs),P(t,"?",_o),P(t,'"',cl),P(t,"/",ht),P(t,";",dl),P(t,"~",Lo),P(t,"_",ss),P(t,"\\",Yr),P(t,"・",of);const o=fe(t,At,rl,{[Yi]:!0});fe(o,At,o);const r=fe(o,Nt,tf,{[Bo]:!0}),s=fe(o,Vo,nf,{[Io]:!0}),i=fe(t,Nt,Tt,{[Xi]:!0});fe(i,At,r),fe(i,Nt,i),fe(r,At,r),fe(r,Nt,r);const l=fe(t,Vo,tl,{[Qi]:!0});fe(l,Nt),fe(l,At,s),fe(l,Vo,l),fe(s,At,s),fe(s,Nt),fe(s,Vo,s);const c=P(t,hl,il,{[el]:!0}),d=P(t,lf,sl,{[el]:!0}),u=fe(t,fl,sl,{[el]:!0});P(t,pl,u),P(d,hl,c),P(d,pl,u),fe(d,fl,u),P(u,lf),P(u,hl),fe(u,fl,u),P(u,pl,u);const f=fe(t,ul,rf,{[Zu]:!0});P(f,"#"),fe(f,ul,f),P(f,_k,f);const h=P(f,Lk);P(h,"#"),fe(h,ul,f);const p=[[Nt,i],[At,r]],m=[[Nt,null],[Vo,l],[At,s]];for(let g=0;g<ls.length;g++)Qt(t,ls[g],nl,Tt,p);for(let g=0;g<as.length;g++)Qt(t,as[g],ol,tl,m);Cn(nl,{tld:!0,ascii:!0},e),Cn(ol,{utld:!0,alpha:!0},e),Qt(t,"file",Or,Tt,p),Qt(t,"mailto",Or,Tt,p),Qt(t,"http",Gn,Tt,p),Qt(t,"https",Gn,Tt,p),Qt(t,"ftp",Gn,Tt,p),Qt(t,"ftps",Gn,Tt,p),Cn(Or,{scheme:!0,ascii:!0},e),Cn(Gn,{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],w=n[g][1]?{[Ok]:!0}:{[Rk]:!0};y.indexOf("-")>=0?w[Zi]=!0:Nt.test(y)?At.test(y)?w[Bo]=!0:w[Xi]=!0:w[Yi]=!0,ef(t,y,y,w)}return ef(t,"localhost",Oo,{ascii:!0}),t.jd=new ze(is),{start:t,tokens:Object.assign({groups:e},sf)}}function af(n,e){const t=$k(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 $k(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 Qt(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 cf(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 $o={defaultProtocol:"http",events:null,format:df,formatHref:df,nl2br:!1,tagName:"a",target:null,rel:null,validate:!0,truncate:1/0,className:null,attributes:null,ignoreTags:[],render:null};function ml(n,e=null){let t=Object.assign({},$o);n&&(t=Object.assign(t,n instanceof ml?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}ml.prototype={o:$o,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]:$o[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 df(n){return n}function uf(n,e){this.t="token",this.v=n,this.tk=e}uf.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=$o.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 cs(n,e){class t extends uf{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 ff=cs("email",{isLink:!0,toHref(){return"mailto:"+this.toString()}}),hf=cs("text"),zk=cs("nl"),ds=cs("url",{isLink:!0,toHref(n=$o.defaultProtocol){return this.hasProtocol()?this.v:`${n}://${this.v}`},hasProtocol(){const n=this.tk;return n.length>=2&&n[0].t!==Oo&&n[1].t===Xt}}),Ze=n=>new ze(n);function Fk({groups:n}){const e=n.domain.concat([qr,Gr,Yt,Yr,Xr,Qr,Zr,es,Qe,rl,Do,ts,ns,rs,ht,is,Lo,ss]),t=[Jr,Xt,ll,ft,al,Do,_o,cl,dl,Lr,Vr,Ro,Po,Pr,Rr,Dr,_r,$r,zr,Fr,Hr,Ur,jr,Wr,Kr],o=[qr,Jr,Gr,Yr,Xr,Qr,Zr,es,Qe,Ro,Po,Do,ts,ns,rs,_o,ht,is,Lo,ss],r=Ze(),s=P(r,Lo);Q(s,o,s),Q(s,n.domain,s);const i=Ze(),l=Ze(),c=Ze();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=P(i,Yt);P(s,Yt,d),P(l,Yt,d),P(c,Yt,d);const u=P(s,ft);Q(u,o,s),Q(u,n.domain,s);const f=Ze();Q(d,n.domain,f),Q(f,n.domain,f);const h=P(f,ft);Q(h,n.domain,f);const p=Ze(ff);Q(h,n.tld,p),Q(h,n.utld,p),P(d,Oo,p);const m=P(f,Qe);P(m,Qe,m),Q(m,n.domain,f),Q(p,n.domain,f),P(p,ft,h),P(p,Qe,m);const g=P(p,Xt);Q(g,n.numeric,ff);const y=P(i,Qe),k=P(i,ft);P(y,Qe,y),Q(y,n.domain,i),Q(k,o,s),Q(k,n.domain,i);const w=Ze(ds);Q(k,n.tld,w),Q(k,n.utld,w),Q(w,n.domain,i),Q(w,o,s),P(w,ft,k),P(w,Qe,y),P(w,Yt,d);const C=P(w,Xt),x=Ze(ds);Q(C,n.numeric,x);const S=Ze(ds),M=Ze();Q(S,e,S),Q(S,t,M),Q(M,e,S),Q(M,t,M),P(w,ht,S),P(x,ht,S);const E=P(l,Xt),T=P(c,Xt),v=P(T,ht),B=P(v,ht);Q(l,n.domain,i),P(l,ft,k),P(l,Qe,y),Q(c,n.domain,i),P(c,ft,k),P(c,Qe,y),Q(E,n.domain,S),P(E,ht,S),P(E,_o,S),Q(B,n.domain,S),Q(B,e,S),P(B,ht,S);const I=[[Ro,Po],[Rr,Pr],[Dr,_r],[Lr,Vr],[$r,zr],[Fr,Hr],[Ur,jr],[Wr,Kr]];for(let D=0;D<I.length;D++){const[V,z]=I[D],W=P(S,V);P(M,V,W),P(W,z,S);const J=Ze(ds);Q(W,e,J);const K=Ze();Q(W,t),Q(J,e,J),Q(J,t,K),Q(K,e,J),Q(K,t,K),P(J,z,S),P(K,z,S)}return P(r,Oo,w),P(r,il,zk),{start:r,tokens:sf}}function Hk(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(gl(hf,e,i)),i=[]),r-=h,u-=h;const p=f.t,m=t.slice(r-u,r);s.push(gl(p,e,m))}}return i.length>0&&s.push(gl(hf,e,i)),s}function gl(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 Uk=typeof console<"u"&&console&&console.warn||(()=>{}),jk="until manual call of linkify.init(). Register all schemes and plugins before invoking linkify the first time.",se={scanner:null,parser:null,tokenQueue:[],pluginQueue:[],customSchemes:[],initialized:!1};function Wk(){return ze.groups={},se.scanner=null,se.parser=null,se.tokenQueue=[],se.pluginQueue=[],se.customSchemes=[],se.initialized=!1,se}function pf(n,e=!1){if(se.initialized&&Uk(`linkifyjs: already initialized - will not register custom scheme "${n}" ${jk}`),!/^[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`);se.customSchemes.push([n,e])}function Kk(){se.scanner=Vk(se.customSchemes);for(let n=0;n<se.tokenQueue.length;n++)se.tokenQueue[n][1]({scanner:se.scanner});se.parser=Fk(se.scanner.tokens);for(let n=0;n<se.pluginQueue.length;n++)se.pluginQueue[n][1]({scanner:se.scanner,parser:se.parser});return se.initialized=!0,se}function yl(n){return se.initialized||Kk(),Hk(se.parser.start,n,af(se.scanner.start,n))}yl.scan=af;function mf(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 ml(t),r=yl(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  ]",qk=new RegExp(kl),Jk=new RegExp(`${kl}$`),Gk=new RegExp(kl,"g");function Yk(n){return n.length===1?n[0].isLink:n.length===3&&n[1].isLink?["()","[]"].includes(n[0].value+n[2].value):!1}function Xk(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=gu(t.doc,[...e]);if(Tu(l).forEach(({newRange:d})=>{const u=ly(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(!Jk.test(p))return;f=u[0],h=o.doc.textBetween(f.pos,d.to,void 0," ")}if(f&&h){const p=h.split(qk).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=yl(m).map(k=>k.toObject(n.defaultProtocol));if(!Yk(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=>{Hi(k.from,k.to,o.doc).some(w=>w.mark.type===n.type)||i.addMark(k.from,k.to,n.type.create({href:k.href}))})}}),!!i.steps.length)return i}})}function Qk(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=Mu(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 Zk(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=mf(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 xn(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(Gk,"").match(new RegExp(`^(?:(?:${t.join("|")}):|[^a-z]|[a-z0-9+.-]+(?:[^a-z+.-:]|$))`,"i"))}var ew=Jn.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"){pf(n);return}pf(n.scheme,n.optionalSlashes)})},onDestroy(){Wk()},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)=>!!xn(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=>!!xn(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=>!!xn(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?["a",Gt(this.options.HTMLAttributes,n),0]:["a",Gt(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=>!!xn(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=>!!xn(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[Ao({find:n=>{const e=[];if(n){const{protocols:t,defaultProtocol:o}=this.options,r=mf(n).filter(s=>s.isLink&&this.options.isAllowedUri(s.value,{defaultValidate:i=>!!xn(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(Xk({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:o=>this.options.isAllowedUri(o,{defaultValidate:r=>!!xn(r,e),protocols:e,defaultProtocol:t}),shouldAutoLink:this.options.shouldAutoLink})),n.push(Qk({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick==="whenNotEditable"?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&n.push(Zk({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),n}}),gf=ew,tw=re.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")}}}),yf=tw,nw=20,kf=(n,e=0)=>{const t=[];return!n.children.length||e>nw||Array.from(n.children).forEach(o=>{o.tagName==="SPAN"?t.push(o):o.children.length&&t.push(...kf(o,e+1))}),t},ow=n=>{if(!n.children.length)return;const e=kf(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}`)})},wl=Jn.create({name:"textStyle",priority:101,addOptions(){return{HTMLAttributes:{},mergeNestedSpanStyles:!0}},parseHTML(){return[{tag:"span",consuming:!1,getAttrs:n=>n.hasAttribute("style")?(this.options.mergeNestedSpanStyles&&ow(n),{}):!1}]},renderHTML({HTMLAttributes:n}){return["span",Gt(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}}}}),rw=re.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()}}}),wf=re.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()}}}),sw=re.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()}}}),iw=re.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()}}}),lw=re.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()}}});re.create({name:"textStyleKit",addExtensions(){const n=[];return this.options.backgroundColor!==!1&&n.push(rw.configure(this.options.backgroundColor)),this.options.color!==!1&&n.push(wf.configure(this.options.color)),this.options.fontFamily!==!1&&n.push(sw.configure(this.options.fontFamily)),this.options.fontSize!==!1&&n.push(iw.configure(this.options.fontSize)),this.options.lineHeight!==!1&&n.push(lw.configure(this.options.lineHeight)),this.options.textStyle!==!1&&n.push(wl.configure(this.options.textStyle)),n}});var bf=wf;function aw(n={}){return new ue({view(e){return new cw(e,n)}})}class cw{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=kc(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 bl(this.anchor)}static valid(e){let t=e.parent;if(t.isTextblock||!dw(e)||!uw(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 bl{constructor(e){this.pos=e}map(e){return new bl(e.map(this.pos))}resolve(e){let t=e.resolve(this.pos);return he.valid(t)?new he(t):Z.near(t)}}function Cf(n){return n.isAtom||n.spec.isolating||n.spec.createGapCursor}function dw(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||Cf(r.type))return!0;if(r.inlineContent)return!1}}return!0}function uw(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||Cf(r.type))return!0;if(r.inlineContent)return!1}}return!0}function fw(){return new ue({props:{decorations:gw,createSelectionBetween(n,e,t){return e.pos==t.pos&&he.valid(t)?new he(t):null},handleClick:pw,handleKeyDown:hw,handleDOMEvents:{beforeinput:mw}}})}const hw=su({ArrowLeft:us("horiz",-1),ArrowRight:us("horiz",1),ArrowUp:us("vert",-1),ArrowDown:us("vert",1)});function us(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 pw(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 mw(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 gw(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 fs=200,be=function(){};be.prototype.append=function(e){return e.length?(e=be.from(e),!this.length&&e||e.length<fs&&this.leafAppend(e)||this.length<fs&&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 yw(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 xf(e):be.empty};var xf=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<=fs)return new e(this.values.concat(r.flatten()))},e.prototype.leafPrepend=function(r){if(this.length+r.length<=fs)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 xf([]);var yw=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 kw=500;class nt{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 pt(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 pt(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 nt(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 pt(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>bw&&(l=ww(l,d),i-=d),new nt(l.append(s),i)}remapping(e,t){let o=new co;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 nt(this.items.append(e.map(t=>new pt(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 pt(m,g,y))}else o.push(new pt(m))},r);let d=[];for(let h=t;h<i;h++)d.push(new pt(s.maps[h]));let u=this.items.slice(0,r).append(d).append(o),f=new nt(u,l);return f.emptyItemCount()>kw&&(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 pt(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 nt(be.from(r.reverse()),s)}}nt.empty=new nt(be.empty,0);function ww(n,e){let t;return n.forEach((o,r)=>{if(o.selection&&e--==0)return t=r,!1}),n.slice(t)}class pt{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 pt(t.getMap().invert(),t,this.selection)}}}class Zt{constructor(e,t,o,r,s){this.done=e,this.undone=t,this.prevRanges=o,this.prevTime=r,this.prevComposition=s}}const bw=20;function Cw(n,e,t,o){let r=t.getMeta(Sn),s;if(r)return r.historyState;t.getMeta(Ew)&&(n=new Zt(n.done,n.undone,null,0,-1));let i=t.getMeta("appendedTransaction");if(t.steps.length==0)return n;if(i&&i.getMeta(Sn))return i.getMeta(Sn).redo?new Zt(n.done.addTransform(t,void 0,o,hs(e)),n.undone,Sf(t.mapping.maps),n.prevTime,n.prevComposition):new Zt(n.done,n.undone.addTransform(t,void 0,o,hs(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||!xw(t,n.prevRanges)),d=i?Cl(n.prevRanges,t.mapping):Sf(t.mapping.maps);return new Zt(n.done.addTransform(t,c?e.selection.getBookmark():void 0,o,hs(e)),nt.empty,d,t.time,l??n.prevComposition)}else return(s=t.getMeta("rebased"))?new Zt(n.done.rebased(t,s),n.undone.rebased(t,s),Cl(n.prevRanges,t.mapping),n.prevTime,n.prevComposition):new Zt(n.done.addMaps(t.mapping.maps),n.undone.addMaps(t.mapping.maps),Cl(n.prevRanges,t.mapping),n.prevTime,n.prevComposition)}function xw(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 Sf(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 Cl(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 Sw(n,e,t){let o=hs(e),r=Sn.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 Zt(t?l:s.remaining,t?s.remaining:l,null,0,-1);return s.transform.setSelection(i).setMeta(Sn,{redo:t,historyState:c})}let xl=!1,Ef=null;function hs(n){let e=n.plugins;if(Ef!=e){xl=!1,Ef=e;for(let t=0;t<e.length;t++)if(e[t].spec.historyPreserveItems){xl=!0;break}}return xl}const Sn=new ke("history"),Ew=new ke("closeHistory");function vw(n={}){return n={depth:n.depth||100,newGroupDelay:n.newGroupDelay||500},new ue({key:Sn,state:{init(){return new Zt(nt.empty,nt.empty,null,0,-1)},apply(e,t,o){return Cw(t,o,e,n)}},config:n,props:{handleDOMEvents:{beforeinput(e,t){let o=t.inputType,r=o=="historyUndo"?Mf:o=="historyRedo"?Tf:null;return!r||!e.editable?!1:(t.preventDefault(),r(e.state,e.dispatch))}}}})}function vf(n,e){return(t,o)=>{let r=Sn.getState(t);if(!r||(n?r.undone:r.done).eventCount==0)return!1;if(o){let s=Sw(r,t,n);s&&o(e?s.scrollIntoView():s)}return!0}}const Mf=vf(!1,!0),Tf=vf(!0,!0);re.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)}})]}}),re.create({name:"dropCursor",addOptions(){return{color:"currentColor",width:1,class:void 0}},addProseMirrorPlugins(){return[aw(this.options)]}}),re.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)}}})]}}),re.create({name:"gapCursor",addProseMirrorPlugins(){return[fw()]},extendNodeSchema(n){var e;const t={name:n.name,options:n.options,storage:n.storage};return{allowGapCursor:(e=ne(H(n,"allowGapCursor",t)))!=null?e:null}}});var Nf="placeholder";function Mw(n){return n.replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-]/g,"").replace(/^[0-9-]+/,"").replace(/^-+/,"").toLowerCase()}re.create({name:"placeholder",addOptions(){return{emptyEditorClass:"is-editor-empty",emptyNodeClass:"is-empty",dataAttribute:Nf,placeholder:"Write something …",showOnlyWhenEditable:!0,showOnlyCurrent:!0,includeChildren:!1}},addProseMirrorPlugins(){const n=this.options.dataAttribute?`data-${Mw(this.options.dataAttribute)}`:`data-${Nf}`;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&&Mr(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)}}})]}}),re.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||ky(t.selection)||n.view.dragging?null:ae.create(t.doc,[Le.inline(t.selection.from,t.selection.to,{class:e.className})])}}})]}});function Af({types:n,node:e}){return e&&Array.isArray(n)&&n.includes(e.type)||(e==null?void 0:e.type)===n}re.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!Af({node:i,types:o})},apply:(r,s)=>{if(!r.docChanged||r.getMeta("__uniqueIDTransaction"))return s;const i=r.doc.lastChild;return!Af({node:i,types:o})}}})]}});var Tw=re.create({name:"undoRedo",addOptions(){return{depth:100,newGroupDelay:500}},addCommands(){return{undo:()=>({state:n,dispatch:e})=>Mf(n,e),redo:()=>({state:n,dispatch:e})=>Tf(n,e)}},addProseMirrorPlugins(){return[vw(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 Bt(n,e){const t=a.inject(He);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(b.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 Bf(){const n=a.inject(He);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=b.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=b.createEntity(f);b.addComponent(f,y,b.Block);const k=b.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,b.Grid.snapPosition(f,k.position);const w=crypto.randomUUID();b.addComponent(f,y,b.Asset);const C=b.Asset.write(f,y);C.identifier=w,C.uploadState=b.UploadState.Pending,b.addComponent(f,y,b.Image);const x=b.Image.write(f,y);return x.width=u.width,x.height=u.height,x.alt=s.name,b.addComponent(f,y,Ve.Synced,{id:crypto.randomUUID()}),(n==null?void 0:n.getAssetManager())&&r(y,w,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=b.Asset.write(d,s);u.uploadState=b.UploadState.Complete}catch{const d=await e(),u=b.Asset.write(d,s);u.uploadState=b.UploadState.Failed}}return{getImageDimensions:t,createImageBlock:o}}function If(n){const e=a.inject(He);if(!e)throw new Error("useQuery must be used within a WovenCanvas component");const t=a.shallowRef([]),o=b.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 w=e.subscribeComponent(f,y.name,C=>{k.value=C});g.push(w)}return{refs:m,unsubscribes:g}}function l(f){const h=r.get(f);if(h){for(const p of h.unsubscribes)p();r.delete(f)}}function c(){const f=[];for(const[h,p]of r)f.push({entityId:h,...p.refs});return f}function d(f){if(!s){const g=o.current(f);for(const y of g)r.set(y,i(y));t.value=c(),s=!0;return}const h=o.added(f),p=o.removed(f);let m=!1;for(const g of p)l(g),m=!0;for(const g of h)r.has(g)||(r.set(g,i(g)),m=!0);m&&(t.value=c())}const u=e.registerTickCallback(d);return a.onUnmounted(()=>{u();for(const f of r.keys())l(f)}),t}function Te(n){const e=a.inject(He);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 Sl(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 Of(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 zo(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 El(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 Rf(n){const e=El(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 Pf(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 Df(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 Ne=a.shallowRef(null),vl=a.shallowRef(null),Ml=a.shallowRef(null),It=a.ref(0);function Fo(){const n={hasEditor:a.computed(()=>Ne.value!==null),isBold:a.computed(()=>{var r;return It.value,((r=Ne.value)==null?void 0:r.isActive("bold"))??!1}),isItalic:a.computed(()=>{var r;return It.value,((r=Ne.value)==null?void 0:r.isActive("italic"))??!1}),isUnderline:a.computed(()=>{var r;return It.value,((r=Ne.value)==null?void 0:r.isActive("underline"))??!1}),alignment:a.computed(()=>{It.value;const r=Ne.value;return r?r.isActive({textAlign:"center"})?"center":r.isActive({textAlign:"right"})?"right":r.isActive({textAlign:"justify"})?"justify":"left":"left"}),color:a.computed(()=>{It.value;const r=Ne.value;if(!r)return null;const i=r.getAttributes("textStyle").color??null;return i?Of(i):null}),linkHref:a.computed(()=>{It.value;const r=Ne.value;return r?r.getAttributes("link").href??null:null})},e={toggleBold(){const r=Ne.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=Ne.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=Ne.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=Ne.value;s&&s.chain().selectAll().setTextAlign(r).run()},setColor(r){const s=Ne.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=Ne.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=Ne.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){Ne.value=r,Ml.value=s,vl.value=i,r.on("selectionUpdate",()=>{It.value++}),r.on("transaction",()=>{It.value++})}function o(){Ne.value=null,Ml.value=null,vl.value=null}return{editor:Ne,blockElement:vl,textElement:Ml,state:n,commands:e,updateCounter:It,register:t,unregister:o}}const Ae=[Wu,qu,Ju,wl,bf,Yu,Xu,Qu,gf.configure({openOnClick:!1}),yf.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:"left"})];function Nw(n){return n.type==="text"&&typeof n.text=="string"}function mt(n,e){if(Nw(n)){e(n);return}if(n.content)for(const t of n.content)mt(t,e)}function Tl(n,e){if(n.type==="paragraph"){e(n);return}if(n.content)for(const t of n.content)Tl(t,e)}function Aw(n,e){var t;return((t=n.marks)==null?void 0:t.some(o=>o.type===e))??!1}function Bw(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?Of(t):null}function Iw(n,e){if(!n.trim())return!1;const t=tt(n,Ae);let o=!1,r=!0,s=0;return mt(t,i=>{s++,Aw(i,e)?o=!0:r=!1}),s===0?!1:r?!0:o?null:!1}function Ow(n){if(!n.trim())return"left";const e=tt(n,Ae);let t="left";return Tl(e,o=>{var s;const r=(s=o.attrs)==null?void 0:s.textAlign;r&&(t=r)}),t}function Rw(n){if(!n.trim())return null;const e=tt(n,Ae);let t=null;return mt(e,o=>{t===null&&(t=Bw(o))}),t}function Nl(n,e){if(!n.trim())return n;const t=tt(n,Ae);return mt(t,o=>{const r=o.marks??[];r.findIndex(i=>i.type===e)===-1&&(o.marks=[...r,{type:e}])}),qn(t,Ae)}function Al(n,e){if(!n.trim())return n;const t=tt(n,Ae);return mt(t,o=>{const r=o.marks??[];o.marks=r.filter(s=>s.type!==e)}),qn(t,Ae)}function Pw(n,e){if(!n.trim())return n;const t=tt(n,Ae);return Tl(t,o=>{o.attrs={...o.attrs,textAlign:e}}),qn(t,Ae)}function Dw(n,e){if(!n.trim())return n;const t=tt(n,Ae);return mt(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}}]}),qn(t,Ae)}function _w(n){if(!n.trim())return null;const e=tt(n,Ae);let t=null;return mt(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 Lw(n,e){if(!n.trim())return n;const t=tt(n,Ae);return mt(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"}}]}),qn(t,Ae)}function Vw(n){if(!n.trim())return n;const e=tt(n,Ae);return mt(e,t=>{const o=t.marks??[];t.marks=o.filter(r=>r.type!=="link")}),qn(e,Ae)}function _f(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 Lf(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=Sl(r,e,t);return r.remove(),l}function Vf(n){const{nextEditorTick:e}=de(),t=Bt(n,b.Text),o=Te(b.Camera),r=Te(b.Screen),s=Fo(),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?tt(h.content,Ae):null;if(p){let m=!1;if(mt(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=Ow(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=Rw(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=_w(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=Iw(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?Al(h,"bold"):Nl(h,"bold"))},toggleItalic(){u(h=>i.isItalic.value?Al(h,"italic"):Nl(h,"italic"))},toggleUnderline(){u(h=>i.isUnderline.value?Al(h,"underline"):Nl(h,"underline"))},setAlignment(h){f(p=>Pw(p,h))},setColor(h){f(p=>Dw(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=>Lw(p,h))},removeLink(){f(h=>Vw(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 w=_f(y);if(w){const C=Lf(w,o,r,h(k));g.push({entityId:y,...C})}}e(y=>{for(const k of m)p(b.Text.write(y,k));for(const{entityId:k,width:w,height:C,left:x,top:S}of g){const M=b.Block.write(y,k);M.size=[w,C],M.position=[x,S]}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),w=_f(g);if(w){const C=Lf(w,o,r,{...y,content:k});m.push({entityId:g,content:k,...C})}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:C,left:x,top:S}of m){const M=b.Text.write(g,y);if(M.content=k,w>0&&C>0){const E=b.Block.write(g,y);E.size=[w,C],E.position=[x,S]}}})}function f(h){const p=a.toValue(n);e(m=>{for(const g of p){const y=b.Text.write(m,g);y.content=h(y.content)}})}return{state:i,commands:c}}function ot(n){const e=Fo(),t=Vf(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 Bl(n){const e=Te(b.Camera),t=Te(b.Screen),o=Te(le.TransformBoxStateSingleton),r=Te(le.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=b.Block.read(u,h),w=Math.abs(k.size[0]-g)>.5,C=Math.abs(k.size[1]-y)>.5;if(!w&&!C)return;const x=b.Block.write(u,h);x.size=[g,y],x.position=[f.left,f.top],o.value.transformBoxId!==null&&le.UpdateTransformBox.spawn(u,{transformBoxId:o.value.transformBoxId})}a.watch(()=>r.value,()=>{s(u=>{const f=$w(u);if(i&&!f){const h=n.containerRef.value;if(!h)return;l=Sl(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(b.Text.read(p,m).content!==f){const y=b.Text.write(p,m);y.content=f}c(p,h)})}return{handleEditEnd:d}}function $w(n){const e=le.SelectionStateSingleton.read(n);return e.state===le.SelectionState.Dragging&&e.draggedEntity!==null&&b.hasComponent(n,e.draggedEntity,le.TransformHandle)&&le.TransformHandle.read(n,e.draggedEntity).kind===le.TransformHandleKind.Stretch}function ps(){const n=a.inject(_s);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 zw=500,Fw=1500;function $f(){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},zw)}function l(){s(),e.value=!1,n.value=null,t.value&&(r=setTimeout(()=>{t.value=!1,r=null},Fw))}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 Ot(){const n=a.inject(ca);if(!n)throw new Error("useTooltipSingleton must be used within a WovenCanvas component");return n}const Hw={key:1},Uw=["innerHTML"],zf=50,jw=300,ms=a.defineComponent({__name:"EditableText",props:{blockElement:{},entityId:{},block:{},stratum:{},selected:{type:Boolean},held:{},hovered:{type:Boolean},edited:{type:Boolean},opacity:{},connector:{}},emits:["editEnd"],setup(n,{expose:e,emit:t}){var T;const o=n,r=t,s=pe(o.entityId,b.Text),i=Te(b.Camera),l=Te(b.Screen),c=Fo(),{nextEditorTick:d}=de(),u=Te(b.Mouse),f=a.ref(null);e({editableTextRef:f});const h=a.ref(((T=s.value)==null?void 0:T.content)??""),p=a.shallowRef(null);function m(v){const I=new DOMParser().parseFromString(v,"text/html");return I.body.querySelectorAll("[style], [class]").forEach(D=>{D.removeAttribute("style"),D.removeAttribute("class")}),I.body.innerHTML}function g(){d(v=>{const B=b.Text.write(v,o.entityId);B.constrainWidth=!0;const I=b.Block.read(v,o.entityId),D=Math.max(I.size[0],jw),V=b.Block.write(v,o.entityId);V.size=[D,I.size[1]],b.ResetKeyboard.spawn(v),le.DeselectAll.spawn(v)})}function y(v,B){var W,J,K;const I=s.value;if(!I)return!1;const D=((W=B.clipboardData)==null?void 0:W.getData("text/html"))??"",V=((J=B.clipboardData)==null?void 0:J.getData("text/plain"))??"";return!D.includes("data-pm-slice")&&D?(B.preventDefault(),(K=p.value)==null||K.commands.insertContent(m(D),{parseOptions:{preserveWhitespace:!0}}),!I.constrainWidth&&V.length>zf&&g(),!0):(!I.constrainWidth&&V.length>zf&&g(),!1)}function k(){var v,B;return new hk({extensions:[Wu,qu,Ju,wl,bf,Yu,Xu,Qu,gf.configure({openOnClick:!1,HTMLAttributes:{rel:"noopener noreferrer",target:"_blank"}}),yf.configure({types:["paragraph"],alignments:["left","center","right","justify"],defaultAlignment:((v=s.value)==null?void 0:v.defaultAlignment)??"left"}),Tw],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 w(p.value),!o.blockElement)return;c.register(p.value,f.value,o.blockElement)}else p.value&&(c.unregister(),C(p.value),p.value.destroy(),p.value=null)},{immediate:!0});async function w(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 D=f.value;if(B&&I&&D){const z=B[0]+I.left,W=B[1]+I.top,J=v.view.posAtCoords({left:z,top:W});if(J){v.chain().focus().setTextSelection(J.pos).run();return}}v.commands.focus("start")}function C(v){let B=v.getHTML();const D=B.replace(/<[^>]*>/g,"").trim().length>0;D||(B=""),h.value=B,d(V=>{var U,F;const z=b.getBlockDef(V,o.block.tag);if(!D&&((U=z.editOptions)!=null&&U.removeWhenTextEmpty)){b.removeEntity(V,o.entityId);return}const W=(F=f.value)==null?void 0:F.closest(".wov-block"),J=(W==null?void 0:W.firstElementChild)??f.value;if(!J){console.warn("EditableText: no element to measure");return}const K=Sl(J,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,D=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(${D}, ${V})`:void 0}});function S(v){v.key==="Control"||v.key==="Meta"||v.stopPropagation()}function M(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:S,onPointerdown:M,onPointermove:M,onPointerup:M,onClick:E},[p.value?(a.openBlock(),a.createBlock(a.unref(pk),{key:0,editor:p.value},null,8,["editor"])):(a.openBlock(),a.createElementBlock("div",Hw,[a.createElementVNode("div",{class:"tiptap ProseMirror",innerHTML:h.value},null,8,Uw)]))],36))}}),Ww={class:"wov-shape-svg",viewBox:"0 0 100 100",preserveAspectRatio:"none"},Kw=["d","fill","stroke","stroke-width","stroke-dasharray"],Ff=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,b.Shape),o=pe(e.entityId,b.VerticalAlign),r=a.ref(null),s={[b.VerticalAlignment.Top]:"flex-start",[b.VerticalAlignment.Center]:"center",[b.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===b.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)??b.StrokeKind.Solid}),u=a.computed(()=>{var g;return ro[((g=t.value)==null?void 0:g.kind)??"rectangle"]??ro.rectangle}),f=a.computed(()=>{const g=c.value;switch(d.value){case b.StrokeKind.Dashed:return`${g*3} ${g*3}`;case b.StrokeKind.None:return"";case b.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)??b.VerticalAlignment.Top]}}),{nextEditorTick:p}=de();function m(g){p(y=>{if(b.Text.read(y,e.entityId).content===g.content)return;const w=b.Text.write(y,e.entityId);w.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",Ww,[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,Kw)])),a.createElementVNode("div",{class:"wov-shape-content",style:a.normalizeStyle(h.value)},[a.createVNode(ms,a.mergeProps(e,{"block-element":r.value,onEditEnd:m}),null,16,["block-element"])],4)],512))}}),qw={class:"wov-tape-block"},Jw={key:0,class:"wov-tape-placeholder"},Hf=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(He);if(!t)throw new Error("TapeBlock must be used within a WovenCanvas component");const o=t,r=pe(e.entityId,b.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===b.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",qw,[i.value&&!s.value?(a.openBlock(),a.createElementBlock("div",Jw)):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)]))}}),Gw=["data-text-empty"],Uf=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,b.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}=Bl({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(ms,a.mergeProps(e,{"block-element":t.value,onEditEnd:a.unref(i)}),null,16,["block-element","onEditEnd"])],12,Gw))}}),gs=Math.min,En=Math.max,ys=Math.round,ks=Math.floor,gt=n=>({x:n,y:n}),Yw={left:"right",right:"left",bottom:"top",top:"bottom"},Xw={start:"end",end:"start"};function jf(n,e,t){return En(n,gs(e,t))}function ws(n,e){return typeof n=="function"?n(e):n}function vn(n){return n.split("-")[0]}function bs(n){return n.split("-")[1]}function Wf(n){return n==="x"?"y":"x"}function Kf(n){return n==="y"?"height":"width"}const Qw=new Set(["top","bottom"]);function en(n){return Qw.has(vn(n))?"y":"x"}function qf(n){return Wf(en(n))}function Zw(n,e,t){t===void 0&&(t=!1);const o=bs(n),r=qf(n),s=Kf(r);let i=r==="x"?o===(t?"end":"start")?"right":"left":o==="start"?"bottom":"top";return e.reference[s]>e.floating[s]&&(i=Cs(i)),[i,Cs(i)]}function eb(n){const e=Cs(n);return[Il(n),e,Il(e)]}function Il(n){return n.replace(/start|end/g,e=>Xw[e])}const Jf=["left","right"],Gf=["right","left"],tb=["top","bottom"],nb=["bottom","top"];function ob(n,e,t){switch(n){case"top":case"bottom":return t?e?Gf:Jf:e?Jf:Gf;case"left":case"right":return e?tb:nb;default:return[]}}function rb(n,e,t,o){const r=bs(n);let s=ob(vn(n),t==="start",o);return r&&(s=s.map(i=>i+"-"+r),e&&(s=s.concat(s.map(Il)))),s}function Cs(n){return n.replace(/left|right|bottom|top/g,e=>Yw[e])}function sb(n){return{top:0,right:0,bottom:0,left:0,...n}}function ib(n){return typeof n!="number"?sb(n):{top:n,right:n,bottom:n,left:n}}function xs(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 Yf(n,e,t){let{reference:o,floating:r}=n;const s=en(e),i=qf(e),l=Kf(i),c=vn(e),d=s==="y",u=o.x+o.width/2-r.width/2,f=o.y+o.height/2-r.height/2,h=o[l]/2-r[l]/2;let p;switch(c){case"top":p={x:u,y:o.y-r.height};break;case"bottom":p={x:u,y:o.y+o.height};break;case"right":p={x:o.x+o.width,y:f};break;case"left":p={x:o.x-r.width,y:f};break;default:p={x:o.x,y:o.y}}switch(bs(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 lb(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}=ws(e,n),m=ib(p),y=l[h?f==="floating"?"reference":"floating":f],k=xs(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})),w=f==="floating"?{x:o,y:r,width:i.floating.width,height:i.floating.height}:i.reference,C=await(s.getOffsetParent==null?void 0:s.getOffsetParent(l.floating)),x=await(s.isElement==null?void 0:s.isElement(C))?await(s.getScale==null?void 0:s.getScale(C))||{x:1,y:1}:{x:1,y:1},S=xs(s.convertOffsetParentRelativeRectToViewportRelativeRect?await s.convertOffsetParentRelativeRectToViewportRelativeRect({elements:l,rect:w,offsetParent:C,strategy:c}):w);return{top:(k.top-S.top+m.top)/x.y,bottom:(S.bottom-k.bottom+m.bottom)/x.y,left:(k.left-S.left+m.left)/x.x,right:(S.right-k.right+m.right)/x.x}}const ab=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}=Yf(d,o,c),h=o,p={},m=0;for(let y=0;y<l.length;y++){var g;const{name:k,fn:w}=l[y],{x:C,y:x,data:S,reset:M}=await w({x:u,y:f,initialPlacement:o,placement:h,strategy:r,middlewareData:p,rects:d,platform:{...i,detectOverflow:(g=i.detectOverflow)!=null?g:lb},elements:{reference:n,floating:e}});u=C??u,f=x??f,p={...p,[k]:{...p[k],...S}},M&&m<=50&&(m++,typeof M=="object"&&(M.placement&&(h=M.placement),M.rects&&(d=M.rects===!0?await i.getElementRects({reference:n,floating:e,strategy:r}):M.rects),{x:u,y:f}=Yf(d,h,c)),y=-1)}return{x:u,y:f,placement:h,strategy:r,middlewareData:p}},cb=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}=ws(n,e);if((t=s.arrow)!=null&&t.alignmentOffset)return{};const k=vn(r),w=en(l),C=vn(l)===l,x=await(c.isRTL==null?void 0:c.isRTL(d.floating)),S=h||(C||!g?[Cs(l)]:eb(l)),M=m!=="none";!h&&M&&S.push(...rb(l,g,m,x));const E=[l,...S],T=await c.detectOverflow(e,y),v=[];let B=((o=s.flip)==null?void 0:o.overflows)||[];if(u&&v.push(T[k]),f){const z=Zw(r,i,x);v.push(T[z[0]],T[z[1]])}if(B=[...B,{placement:r,overflows:v}],!v.every(z=>z<=0)){var I,D;const z=(((I=s.flip)==null?void 0:I.index)||0)+1,W=E[z];if(W&&(!(f==="alignment"?w!==en(W):!1)||B.every(U=>en(U.placement)===w?U.overflows[0]>0:!0)))return{data:{index:z,overflows:B},reset:{placement:W}};let J=(D=B.filter(K=>K.overflows[0]<=0).sort((K,U)=>K.overflows[1]-U.overflows[1])[0])==null?void 0:D.placement;if(!J)switch(p){case"bestFit":{var V;const K=(V=B.filter(U=>{if(M){const F=en(U.placement);return F===w||F==="y"}return!0}).map(U=>[U.placement,U.overflows.filter(F=>F>0).reduce((F,X)=>F+X,0)]).sort((U,F)=>U[1]-F[1])[0])==null?void 0:V[0];K&&(J=K);break}case"initialPlacement":J=l;break}if(r!==J)return{reset:{placement:J}}}return{}}}},db=new Set(["left","top"]);async function ub(n,e){const{placement:t,platform:o,elements:r}=n,s=await(o.isRTL==null?void 0:o.isRTL(r.floating)),i=vn(t),l=bs(t),c=en(t)==="y",d=db.has(i)?-1:1,u=s&&c?-1:1,f=ws(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 fb=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 ub(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}}}}},hb=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:w,y:C}=k;return{x:w,y:C}}},...d}=ws(n,e),u={x:t,y:o},f=await s.detectOverflow(e,d),h=en(vn(r)),p=Wf(h);let m=u[p],g=u[h];if(i){const k=p==="y"?"top":"left",w=p==="y"?"bottom":"right",C=m+f[k],x=m-f[w];m=jf(C,m,x)}if(l){const k=h==="y"?"top":"left",w=h==="y"?"bottom":"right",C=g+f[k],x=g-f[w];g=jf(C,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 Ss(){return typeof window<"u"}function Mn(n){return Ol(n)?(n.nodeName||"").toLowerCase():"#document"}function We(n){var e;return(n==null||(e=n.ownerDocument)==null?void 0:e.defaultView)||window}function yt(n){var e;return(e=(Ol(n)?n.ownerDocument:n.document)||window.document)==null?void 0:e.documentElement}function Ol(n){return Ss()?n instanceof Node||n instanceof We(n).Node:!1}function rt(n){return Ss()?n instanceof Element||n instanceof We(n).Element:!1}function kt(n){return Ss()?n instanceof HTMLElement||n instanceof We(n).HTMLElement:!1}function Xf(n){return!Ss()||typeof ShadowRoot>"u"?!1:n instanceof ShadowRoot||n instanceof We(n).ShadowRoot}const pb=new Set(["inline","contents"]);function Ho(n){const{overflow:e,overflowX:t,overflowY:o,display:r}=st(n);return/auto|scroll|overlay|hidden|clip/.test(e+o+t)&&!pb.has(r)}const mb=new Set(["table","td","th"]);function gb(n){return mb.has(Mn(n))}const yb=[":popover-open",":modal"];function Es(n){return yb.some(e=>{try{return n.matches(e)}catch{return!1}})}const kb=["transform","translate","scale","rotate","perspective"],wb=["transform","translate","scale","rotate","perspective","filter"],bb=["paint","layout","strict","content"];function Rl(n){const e=Pl(),t=rt(n)?st(n):n;return kb.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)||wb.some(o=>(t.willChange||"").includes(o))||bb.some(o=>(t.contain||"").includes(o))}function Cb(n){let e=tn(n);for(;kt(e)&&!Yn(e);){if(Rl(e))return e;if(Es(e))return null;e=tn(e)}return null}function Pl(){return typeof CSS>"u"||!CSS.supports?!1:CSS.supports("-webkit-backdrop-filter","none")}const xb=new Set(["html","body","#document"]);function Yn(n){return xb.has(Mn(n))}function st(n){return We(n).getComputedStyle(n)}function vs(n){return rt(n)?{scrollLeft:n.scrollLeft,scrollTop:n.scrollTop}:{scrollLeft:n.scrollX,scrollTop:n.scrollY}}function tn(n){if(Mn(n)==="html")return n;const e=n.assignedSlot||n.parentNode||Xf(n)&&n.host||yt(n);return Xf(e)?e.host:e}function Qf(n){const e=tn(n);return Yn(e)?n.ownerDocument?n.ownerDocument.body:n.body:kt(e)&&Ho(e)?e:Qf(e)}function Uo(n,e,t){var o;e===void 0&&(e=[]),t===void 0&&(t=!0);const r=Qf(n),s=r===((o=n.ownerDocument)==null?void 0:o.body),i=We(r);if(s){const l=Dl(i);return e.concat(i,i.visualViewport||[],Ho(r)?r:[],l&&t?Uo(l):[])}return e.concat(r,Uo(r,[],t))}function Dl(n){return n.parent&&Object.getPrototypeOf(n.parent)?n.frameElement:null}function Zf(n){const e=st(n);let t=parseFloat(e.width)||0,o=parseFloat(e.height)||0;const r=kt(n),s=r?n.offsetWidth:t,i=r?n.offsetHeight:o,l=ys(t)!==s||ys(o)!==i;return l&&(t=s,o=i),{width:t,height:o,$:l}}function _l(n){return rt(n)?n:n.contextElement}function Xn(n){const e=_l(n);if(!kt(e))return gt(1);const t=e.getBoundingClientRect(),{width:o,height:r,$:s}=Zf(e);let i=(s?ys(t.width):t.width)/o,l=(s?ys(t.height):t.height)/r;return(!i||!Number.isFinite(i))&&(i=1),(!l||!Number.isFinite(l))&&(l=1),{x:i,y:l}}const Sb=gt(0);function eh(n){const e=We(n);return!Pl()||!e.visualViewport?Sb:{x:e.visualViewport.offsetLeft,y:e.visualViewport.offsetTop}}function Eb(n,e,t){return e===void 0&&(e=!1),!t||e&&t!==We(n)?!1:e}function Tn(n,e,t,o){e===void 0&&(e=!1),t===void 0&&(t=!1);const r=n.getBoundingClientRect(),s=_l(n);let i=gt(1);e&&(o?rt(o)&&(i=Xn(o)):i=Xn(n));const l=Eb(s,t,o)?eh(s):gt(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=We(s),p=o&&rt(o)?We(o):o;let m=h,g=Dl(m);for(;g&&o&&p!==m;){const y=Xn(g),k=g.getBoundingClientRect(),w=st(g),C=k.left+(g.clientLeft+parseFloat(w.paddingLeft))*y.x,x=k.top+(g.clientTop+parseFloat(w.paddingTop))*y.y;c*=y.x,d*=y.y,u*=y.x,f*=y.y,c+=C,d+=x,m=We(g),g=Dl(m)}}return xs({width:u,height:f,x:c,y:d})}function Ms(n,e){const t=vs(n).scrollLeft;return e?e.left+t:Tn(yt(n)).left+t}function th(n,e){const t=n.getBoundingClientRect(),o=t.left+e.scrollLeft-Ms(n,t),r=t.top+e.scrollTop;return{x:o,y:r}}function vb(n){let{elements:e,rect:t,offsetParent:o,strategy:r}=n;const s=r==="fixed",i=yt(o),l=e?Es(e.floating):!1;if(o===i||l&&s)return t;let c={scrollLeft:0,scrollTop:0},d=gt(1);const u=gt(0),f=kt(o);if((f||!f&&!s)&&((Mn(o)!=="body"||Ho(i))&&(c=vs(o)),kt(o))){const p=Tn(o);d=Xn(o),u.x=p.x+o.clientLeft,u.y=p.y+o.clientTop}const h=i&&!f&&!s?th(i,c):gt(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 Mb(n){return Array.from(n.getClientRects())}function Tb(n){const e=yt(n),t=vs(n),o=n.ownerDocument.body,r=En(e.scrollWidth,e.clientWidth,o.scrollWidth,o.clientWidth),s=En(e.scrollHeight,e.clientHeight,o.scrollHeight,o.clientHeight);let i=-t.scrollLeft+Ms(n);const l=-t.scrollTop;return st(o).direction==="rtl"&&(i+=En(e.clientWidth,o.clientWidth)-r),{width:r,height:s,x:i,y:l}}const nh=25;function Nb(n,e){const t=We(n),o=yt(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=Pl();(!u||u&&e==="fixed")&&(l=r.offsetLeft,c=r.offsetTop)}const d=Ms(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<=nh&&(s-=m)}else d<=nh&&(s+=d);return{width:s,height:i,x:l,y:c}}const Ab=new Set(["absolute","fixed"]);function Bb(n,e){const t=Tn(n,!0,e==="fixed"),o=t.top+n.clientTop,r=t.left+n.clientLeft,s=kt(n)?Xn(n):gt(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 oh(n,e,t){let o;if(e==="viewport")o=Nb(n,t);else if(e==="document")o=Tb(yt(n));else if(rt(e))o=Bb(e,t);else{const r=eh(n);o={x:e.x-r.x,y:e.y-r.y,width:e.width,height:e.height}}return xs(o)}function rh(n,e){const t=tn(n);return t===e||!rt(t)||Yn(t)?!1:st(t).position==="fixed"||rh(t,e)}function Ib(n,e){const t=e.get(n);if(t)return t;let o=Uo(n,[],!1).filter(l=>rt(l)&&Mn(l)!=="body"),r=null;const s=st(n).position==="fixed";let i=s?tn(n):n;for(;rt(i)&&!Yn(i);){const l=st(i),c=Rl(i);!c&&l.position==="fixed"&&(r=null),(s?!c&&!r:!c&&l.position==="static"&&!!r&&Ab.has(r.position)||Ho(i)&&!c&&rh(n,i))?o=o.filter(u=>u!==i):r=l,i=tn(i)}return e.set(n,o),o}function Ob(n){let{element:e,boundary:t,rootBoundary:o,strategy:r}=n;const i=[...t==="clippingAncestors"?Es(e)?[]:Ib(e,this._c):[].concat(t),o],l=i[0],c=i.reduce((d,u)=>{const f=oh(e,u,r);return d.top=En(f.top,d.top),d.right=gs(f.right,d.right),d.bottom=gs(f.bottom,d.bottom),d.left=En(f.left,d.left),d},oh(e,l,r));return{width:c.right-c.left,height:c.bottom-c.top,x:c.left,y:c.top}}function Rb(n){const{width:e,height:t}=Zf(n);return{width:e,height:t}}function Pb(n,e,t){const o=kt(e),r=yt(e),s=t==="fixed",i=Tn(n,!0,s,e);let l={scrollLeft:0,scrollTop:0};const c=gt(0);function d(){c.x=Ms(r)}if(o||!o&&!s)if((Mn(e)!=="body"||Ho(r))&&(l=vs(e)),o){const p=Tn(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?th(r,l):gt(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 Ll(n){return st(n).position==="static"}function sh(n,e){if(!kt(n)||st(n).position==="fixed")return null;if(e)return e(n);let t=n.offsetParent;return yt(n)===t&&(t=t.ownerDocument.body),t}function ih(n,e){const t=We(n);if(Es(n))return t;if(!kt(n)){let r=tn(n);for(;r&&!Yn(r);){if(rt(r)&&!Ll(r))return r;r=tn(r)}return t}let o=sh(n,e);for(;o&&gb(o)&&Ll(o);)o=sh(o,e);return o&&Yn(o)&&Ll(o)&&!Rl(o)?t:o||Cb(n)||t}const Db=async function(n){const e=this.getOffsetParent||ih,t=this.getDimensions,o=await t(n.floating);return{reference:Pb(n.reference,await e(n.floating),n.strategy),floating:{x:0,y:0,width:o.width,height:o.height}}};function _b(n){return st(n).direction==="rtl"}const Lb={convertOffsetParentRelativeRectToViewportRelativeRect:vb,getDocumentElement:yt,getClippingRect:Ob,getOffsetParent:ih,getElementRects:Db,getClientRects:Mb,getDimensions:Rb,getScale:Xn,isElement:rt,isRTL:_b};function lh(n,e){return n.x===e.x&&n.y===e.y&&n.width===e.width&&n.height===e.height}function Vb(n,e){let t=null,o;const r=yt(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=ks(f),g=ks(r.clientWidth-(u+h)),y=ks(r.clientHeight-(f+p)),k=ks(u),C={rootMargin:-m+"px "+-g+"px "+-y+"px "+-k+"px",threshold:En(0,gs(1,c))||1};let x=!0;function S(M){const E=M[0].intersectionRatio;if(E!==c){if(!x)return i();E?i(!1,E):o=setTimeout(()=>{i(!1,1e-7)},1e3)}E===1&&!lh(d,n.getBoundingClientRect())&&i(),x=!1}try{t=new IntersectionObserver(S,{...C,root:r.ownerDocument})}catch{t=new IntersectionObserver(S,C)}t.observe(n)}return i(!0),s}function Ts(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=_l(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?Vb(d,t):null;let h=-1,p=null;i&&(p=new ResizeObserver(k=>{let[w]=k;w&&w.target===d&&p&&(p.unobserve(e),cancelAnimationFrame(h),h=requestAnimationFrame(()=>{var C;(C=p)==null||C.observe(e)})),t()}),d&&!c&&p.observe(d),p.observe(e));let m,g=c?Tn(n):null;c&&y();function y(){const k=Tn(n);g&&!lh(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=p)==null||k.disconnect(),p=null,c&&cancelAnimationFrame(m)}}const Qn=fb,Zn=hb,eo=cb,$b=(n,e,t)=>{const o=new Map,r={platform:Lb,...t},s={...r.platform,_c:o};return ab(n,e,{...r,platform:s})};function zb(n){return n!=null&&typeof n=="object"&&"$el"in n}function ah(n){if(zb(n)){const e=n.$el;return Ol(e)&&Mn(e)==="#comment"?null:e}return n}function jo(n){return typeof n=="function"?n():a.unref(n)}function ch(n){return typeof window>"u"?1:(n.ownerDocument.defaultView||window).devicePixelRatio||1}function dh(n,e){const t=ch(n);return Math.round(e*t)/t}function to(n,e,t){t===void 0&&(t={});const o=t.whileElementsMounted,r=a.computed(()=>{var E;return(E=jo(t.open))!=null?E:!0}),s=a.computed(()=>jo(t.middleware)),i=a.computed(()=>{var E;return(E=jo(t.placement))!=null?E:"bottom"}),l=a.computed(()=>{var E;return(E=jo(t.strategy))!=null?E:"absolute"}),c=a.computed(()=>{var E;return(E=jo(t.transform))!=null?E:!0}),d=a.computed(()=>ah(n.value)),u=a.computed(()=>ah(e.value)),f=a.ref(0),h=a.ref(0),p=a.ref(l.value),m=a.ref(i.value),g=a.shallowRef({}),y=a.ref(!1),k=a.computed(()=>{const E={position:p.value,left:"0",top:"0"};if(!u.value)return E;const T=dh(u.value,f.value),v=dh(u.value,h.value);return c.value?{...E,transform:"translate("+T+"px, "+v+"px)",...ch(u.value)>=1.5&&{willChange:"transform"}}:{position:p.value,left:T+"px",top:v+"px"}});let w;function C(){if(d.value==null||u.value==null)return;const E=r.value;$b(d.value,u.value,{middleware:s.value,placement:i.value,strategy:l.value}).then(T=>{f.value=T.x,h.value=T.y,p.value=T.strategy,m.value=T.placement,g.value=T.middlewareData,y.value=E!==!1})}function x(){typeof w=="function"&&(w(),w=void 0)}function S(){if(x(),o===void 0){C();return}if(d.value!=null&&u.value!=null){w=o(d.value,u.value,C);return}}function M(){r.value||(y.value=!1)}return a.watch([s,i,l,r],C,{flush:"sync"}),a.watch([d,u],S,{flush:"sync"}),a.watch(r,M,{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:C}}const Fb=["menu-open"],Ke=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(ia,null),i=a.inject(la,0),l=Math.random().toString(36).slice(2);a.provide(la,i+1);const{show:c,hide:d}=Ot(),u=a.ref(!1);s&&a.watch(()=>s.value.get(i),C=>{C!==void 0&&C!==l&&u.value&&(u.value=!1)});const f=a.ref(null),h=a.ref(null),{floatingStyles:p}=to(f,h,{placement:t.placement,middleware:[Qn(t.offsetPx),eo(),Zn({padding:8})],whileElementsMounted:Ts});function m(){t.disabled||(u.value=!u.value)}function g(){u.value=!1}function y(C){var T,v,B;const x=C.target,S=(T=f.value)==null?void 0:T.contains(x),M=(v=h.value)==null?void 0:v.contains(x),E=(B=x.closest)==null?void 0:B.call(x,".wov-menu-dropdown");!S&&!M&&!E&&g()}function k(){t.title&&f.value&&!u.value&&c(t.title,f.value)}function w(){d()}return a.watch(u,C=>{C?(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)}),(C,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:w},[a.renderSlot(C.$slots,"button",{isOpen:u.value})],42,Fb),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(C.$slots,"dropdown",{close:g})],4)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)],64))}}),Hb={},Ub={viewBox:"0 0 512 320",fill:"currentColor",style:{width:"7px",color:"var(--wov-gray-300)"}};function jb(n,e){return a.openBlock(),a.createElementBlock("svg",Ub,[...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 qe=sn(Hb,[["render",jb]]),Wb={class:"wov-menu-button"},Kb=["innerHTML"],qb=["onClick"],Jb=["innerHTML"],Vl=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 On(l)});t(l=>{let c=null;for(const d of e.entityIds){if(b.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(b.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(b.hasComponent(c,d,ee.ElbowArrow)){const u=ee.ElbowArrow.write(c,d);e.side==="start"?u.startArrowHead=l:u.endArrowHead=l}if(b.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(Ke,{title:n.side==="start"?"Start Arrow Head":"End Arrow Head"},{button:a.withCtx(()=>[a.createElementVNode("div",Wb,[(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,Kb)),a.createVNode(qe,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(a.unref(Ds),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,Jb))],10,qb))),128))]),_:1},8,["title"]))}}),Gb={class:"wov-menu-button"},Yb=["onClick"],uh=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(b.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(b.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(b.hasComponent(l,c,ee.ElbowArrow)){const d=ee.ElbowArrow.write(l,c);d.thickness=i}b.hasComponent(l,c,ee.ArcArrow)&&ee.ArcArrow.setThickness(l,c,i)}})}return(i,l)=>(a.openBlock(),a.createBlock(Ke,{title:"Thickness"},{button:a.withCtx(()=>[a.createElementVNode("div",Gb,[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(qe,{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,Yb)),64))]),_:1}))}}),Xb=["value"],Qb=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,Xb))}}),fh=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))}}),Zb={class:"wov-color-picker"},e2={class:"wov-color-picker-area"},t2={class:"wov-color-picker-selector-gradient"},n2="linear-gradient(to bottom, red 0%, #ff0 17%, #0f0 33%, #0ff 50%, #00f 67%, #f0f 83%, red 100%)",hh=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 M,E;return u.value||((M=r.value)==null?void 0:M.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(()=>Pf({h:h.value.h,s:100,v:100})),m=a.computed(()=>Pf({h:h.value.h,s:h.value.s,v:h.value.v})),g=a.computed(()=>t.withOpacity?Df(h.value):m.value),y=a.computed(()=>`linear-gradient(to top, transparent 0%, ${m.value} 100%)`);function k(M){if(M){const E=Rf(M);l.value={x:E.s,y:100-E.v},c.value=E.h/360*100,d.value=100-E.a/255*100}}function w(M){k(M),o("update:modelValue",t.withOpacity?Df(Rf(M)):M)}k(t.modelValue),a.watch(()=>t.modelValue,M=>{f.value||k(M)}),a.watch([l,c,d],()=>{f.value&&o("update:modelValue",g.value)});function C(M){u.value=!0,x(M),window.addEventListener("pointermove",x),window.addEventListener("pointerup",S)}function x(M){if(!i.value)return;const E=i.value.getBoundingClientRect(),T=Math.max(0,Math.min(100,(M.clientX-E.left)/E.width*100)),v=Math.max(0,Math.min(100,(M.clientY-E.top)/E.height*100));l.value={x:T,y:v}}function S(){u.value=!1,window.removeEventListener("pointermove",x),window.removeEventListener("pointerup",S)}return(M,E)=>(a.openBlock(),a.createElementBlock("div",Zb,[a.createVNode(Qb,{modelValue:g.value,"onUpdate:modelValue":w},null,8,["modelValue"]),a.createElementVNode("div",e2,[a.createElementVNode("div",{ref_key:"selectorRef",ref:i,class:"wov-color-picker-selector",style:a.normalizeStyle({backgroundColor:p.value}),onPointerdown:a.withModifiers(C,["prevent"])},[a.createElementVNode("div",t2,[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(fh,{ref_key:"hueSliderRef",ref:r,modelValue:c.value,"onUpdate:modelValue":E[0]||(E[0]=T=>c.value=T),thumbColor:p.value,background:n2},null,8,["modelValue","thumbColor"]),n.withOpacity?(a.openBlock(),a.createBlock(fh,{key:0,ref_key:"opacitySliderRef",ref:s,modelValue:d.value,"onUpdate:modelValue":E[1]||(E[1]=T=>d.value=T),thumbColor:m.value,background:y.value,class:"wov-color-picker-opacity"},null,8,["modelValue","thumbColor","background"])):a.createCommentVNode("",!0)])]))}}),o2={class:"wov-color-bubbles-container"},r2={key:1,class:"wov-color-bubbles"},s2=["onClick"],Ns=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 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: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=El(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=El(m);g&&o("change",g)}return(m,g)=>(a.openBlock(),a.createElementBlock("div",o2,[i.value?(a.openBlock(),a.createBlock(hh,{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",r2,[(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,s2))),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)]))]))}}),i2={class:"wov-color-button"},ph=a.defineComponent({__name:"ColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=de(),o=Bt(()=>e.entityIds,b.Color),r=a.computed(()=>{const d=new Set;for(const u of o.value.values())if(u){const f=zo(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=zo(d);t(f=>{for(const h of e.entityIds)b.Color.fromHex(f,h,u)})}return(d,u)=>(a.openBlock(),a.createBlock(Ke,{title:"Color"},{button:a.withCtx(()=>[a.createElementVNode("div",i2,[a.createElementVNode("div",{class:"wov-color-swatch",style:a.normalizeStyle(l.value)},null,4),a.createVNode(qe,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createVNode(Ns,{currentColor:i.value??void 0,hideHighlight:s.value,withPicker:!0,onChange:c},null,8,["currentColor","hideHighlight"])]),_:1}))}}),Nn=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}=Ot();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))}}),$l=a.defineComponent({__name:"MenuTooltip",setup(n){const{activeTooltip:e,isVisible:t}=Ot(),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}=to(s,r,{placement:"top",middleware:[Qn(8),eo({fallbackPlacements:["bottom"]}),Zn({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)}}),l2={class:"wov-menu-button"},a2=["onClick"],mh=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=Bt(()=>t.entityIds,Jo.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=Jo.PenStroke.write(c,d);u.thickness=l}})}return(l,c)=>(a.openBlock(),a.createBlock(Ke,{title:"Thickness"},{button:a.withCtx(()=>[a.createElementVNode("div",l2,[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(qe,{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,a2)),64))]),_:1}))}}),c2={class:"wov-fill-color-button"},d2={class:"wov-fill-dropdown"},u2={key:0,class:"wov-fill-mode-section"},f2=["title","onClick"],h2={viewBox:"0 0 24 24",fill:"none"},p2=["fill","fill-opacity","stroke","stroke-width","stroke-dasharray"],gh=a.defineComponent({__name:"ShapeFillColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=de(),o=Bt(()=>e.entityIds,b.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=b.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=zo({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=b.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(Ke,{title:"Fill Color"},{button:a.withCtx(()=>[a.createElementVNode("div",c2,[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(qe,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",d2,[h.value?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",u2,[(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",h2,[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,p2)])),a.createElementVNode("span",null,a.toDisplayString(g.label),1)],10,f2)),64))])),a.createVNode(Ns,{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}))}}),m2={class:"wov-shape-kind-button"},g2={class:"wov-shape-kind-dropdown"},y2=["onClick"],k2={viewBox:"0 0 20 20",class:"wov-shape-option-icon",fill:"none",stroke:"currentColor","stroke-width":"4"},w2=["d"],yh=a.defineComponent({__name:"ShapeKindButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=de(),o=Bt(()=>e.entityIds,b.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(ro).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=b.Shape.write(d,u);f.kind=c}})}return(c,d)=>(a.openBlock(),a.createBlock(Ke,{title:"Shape Type"},{button:a.withCtx(()=>[a.createElementVNode("div",m2,[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(qe,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",g2,[(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",k2,[a.createElementVNode("path",{d:a.unref(ro)[u.kind],transform:"translate(2, 2) scale(0.16)"},null,8,w2)])),a.createElementVNode("span",null,a.toDisplayString(u.label),1)],10,y2))),128))])]),_:1}))}}),b2={class:"wov-stroke-style-section"},C2=["title","onClick"],x2={viewBox:"0 0 24 8",fill:"none",stroke:"currentColor","stroke-width":"2"},S2=["stroke-dasharray","stroke-opacity"],E2=a.defineComponent({__name:"StrokeStyleOptions",props:{currentStyle:{},hasMultipleStyles:{type:Boolean}},emits:["change"],setup(n,{emit:e}){const t=e,o=[{kind:b.StrokeKind.Solid,label:"Solid"},{kind:b.StrokeKind.Dashed,label:"Dashed"},{kind:b.StrokeKind.None,label:"None"}];function r(i){switch(i){case b.StrokeKind.Dashed:return"6 6";case b.StrokeKind.None:return"";case b.StrokeKind.Solid:default:return""}}function s(i){t("change",i)}return(i,l)=>(a.openBlock(),a.createElementBlock("div",b2,[(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",x2,[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(b.StrokeKind).None?.3:1},null,8,S2)])),a.createElementVNode("span",null,a.toDisplayString(c.label),1)],10,C2)),64))]))}}),v2={class:"wov-stroke-color-button"},M2={class:"wov-stroke-dropdown"},T2={key:1,class:"wov-stroke-divider"},kh=a.defineComponent({__name:"ShapeStrokeColorButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=de(),o=Bt(()=>e.entityIds,b.Shape),r=a.ref(!1),s=a.computed(()=>{const h=new Set;for(const p of o.value.values())if(p){const m=zo({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)??b.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=b.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=b.Shape.write(p,m);g.strokeKind=h}})}return(h,p)=>(a.openBlock(),a.createBlock(Ke,{title:"Stroke Color"},{button:a.withCtx(()=>[a.createElementVNode("div",v2,[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(qe,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",M2,[r.value?a.createCommentVNode("",!0):(a.openBlock(),a.createBlock(E2,{key:0,currentStyle:c.value,hasMultipleStyles:d.value,onChange:f},null,8,["currentStyle","hasMultipleStyles"])),r.value?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",T2)),a.createVNode(Ns,{currentColor:l.value,hideHighlight:i.value,withPicker:!0,onChange:u,onPickerOpen:p[0]||(p[0]=m=>r.value=m)},null,8,["currentColor","hideHighlight"])])]),_:1}))}}),N2={class:"wov-tape-image-button"},A2={class:"wov-tape-image-bubbles"},B2=["onClick"],wh=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=Bt(()=>t.entityIds,b.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=b.Asset.write(c,d);u.identifier=l}})}return(l,c)=>(a.openBlock(),a.createBlock(Ke,{title:"Tape Style"},{button:a.withCtx(()=>[a.createElementVNode("div",N2,[a.createElementVNode("div",{class:"wov-tape-image-swatch",style:a.normalizeStyle(s.value?{backgroundImage:`url(${s.value})`}:{})},null,4),a.createVNode(qe,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",A2,[(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,B2)),64))])]),_:1}))}}),I2={key:0,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},O2={key:1,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},R2={key:2,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},P2={key:3,xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},zl=a.defineComponent({__name:"TextAlignmentButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=[b.TextAlignment.Left,b.TextAlignment.Center,b.TextAlignment.Right,b.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(Nn,{key:0,title:"Text Align",onClick:s},{default:a.withCtx(()=>[a.unref(t).alignment===a.unref(b.TextAlignment).Left?(a.openBlock(),a.createElementBlock("svg",I2,[...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(b.TextAlignment).Center?(a.openBlock(),a.createElementBlock("svg",O2,[...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(b.TextAlignment).Right?(a.openBlock(),a.createElementBlock("svg",R2,[...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",P2,[...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)}}),Fl=a.defineComponent({__name:"TextBoldButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Nn,{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 D2(n,e){return a.getCurrentScope()?(a.onScopeDispose(n,e),!0):!1}const _2=typeof window<"u"&&typeof document<"u";typeof WorkerGlobalScope<"u"&&globalThis instanceof WorkerGlobalScope;const L2=Object.prototype.toString,V2=n=>L2.call(n)==="[object Object]",As=()=>{};function Bs(n){return Array.isArray(n)?n:[n]}function $2(n){return a.getCurrentInstance()}function z2(n,e=!0,t){$2()?a.onMounted(n,t):e?n():a.nextTick(n)}function F2(n,e,t){return a.watch(n,e,{...t,immediate:!0})}const Is=_2?window:void 0;function it(n){var e;const t=a.toValue(n);return(e=t==null?void 0:t.$el)!==null&&e!==void 0?e:t}function Hl(...n){const e=(o,r,s,i)=>(o.addEventListener(r,s,i),()=>o.removeEventListener(r,s,i)),t=a.computed(()=>{const o=Bs(a.toValue(n[0])).filter(r=>r!=null);return o.every(r=>typeof r!="string")?o:void 0});return F2(()=>{var o,r;return[(o=(r=t.value)===null||r===void 0?void 0:r.map(s=>it(s)))!==null&&o!==void 0?o:[Is].filter(s=>s!=null),Bs(a.toValue(t.value?n[1]:n[0])),Bs(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=V2(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 H2(n,e,t={}){const{window:o=Is,ignore:r=[],capture:s=!0,detectIframe:i=!1,controls:l=!1}=t;if(!o)return l?{stop:As,cancel:As,trigger:As}:As;let c=!0;const d=y=>a.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=it(k);return w&&(y.target===w||y.composedPath().includes(w))}});function u(y){const k=a.toValue(y);return k&&k.$.subTree.shapeFlag===16}function f(y,k){const w=a.toValue(y),C=w.$.subTree&&w.$.subTree.children;return C==null||!Array.isArray(C)?!1:C.some(x=>x.el===k.target||k.composedPath().includes(x.el))}const h=y=>{const k=it(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=[Hl(o,"click",y=>{p||(p=!0,setTimeout(()=>{p=!1},0),h(y))},{passive:!0,capture:s}),Hl(o,"pointerdown",y=>{const k=it(n);c=!d(y)&&!!(k&&!y.composedPath().includes(k))},{passive:!0}),i&&Hl(o,"blur",y=>{setTimeout(()=>{var k;const w=it(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:()=>{c=!1},trigger:y=>{c=!0,h(y),c=!1}}:g}function U2(){const n=a.shallowRef(!1),e=a.getCurrentInstance();return e&&a.onMounted(()=>{n.value=!0},e),n}function j2(n){const e=U2();return a.computed(()=>(e.value,!!n()))}function W2(n,e,t={}){const{window:o=Is,...r}=t;let s;const i=j2(()=>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=>it(f)):[it(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 D2(d),{isSupported:i,stop:d}}function bh(n,e={width:0,height:0},t={}){const{window:o=Is,box:r="content-box"}=t,s=a.computed(()=>{var f;return(f=it(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}=W2(n,([f])=>{const h=r==="border-box"?f.borderBoxSize:r==="content-box"?f.contentBoxSize:f.devicePixelContentBoxSize;if(o&&s.value){const p=it(n);if(p){const m=p.getBoundingClientRect();i.value=m.width,l.value=m.height}}else if(h){const p=Bs(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);z2(()=>{const f=it(n);f&&(i.value="offsetWidth"in f?f.offsetWidth:e.width,l.value="offsetHeight"in f?f.offsetHeight:e.height)});const d=a.watch(()=>it(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 Ch(){const n=a.inject(He);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 K2={class:"wov-font-family-button"},q2={class:"wov-font-family-label"},J2={class:"wov-font-list"},G2=["onClick"],Y2=["src","alt"],Ul=a.defineComponent({__name:"TextFontFamilyButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=Ch(),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(Ke,{key:0,title:"Font Family"},{button:a.withCtx(()=>[a.createElementVNode("div",K2,[a.createElementVNode("span",q2,a.toDisplayString(l.value),1),a.createVNode(qe,{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",J2,[(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,Y2)):(a.openBlock(),a.createElementBlock("span",{key:1,class:"wov-font-name",style:a.normalizeStyle({fontFamily:h.name})},a.toDisplayString(h.displayName),5))],10,G2))),128))])],32)]),_:1})):a.createCommentVNode("",!0)}}),X2={class:"wov-font-size-button"},Q2={class:"wov-font-size-label"},Z2=["onClick"],eC={key:0,class:"wov-check-icon",xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 448 512",fill:"currentColor"},tC={class:"wov-input-container"},nC=["value"],jl=a.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=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(Ke,{key:0,title:"Font Size"},{button:a.withCtx(()=>[a.createElementVNode("div",X2,[a.createElementVNode("span",Q2,a.toDisplayString(i.value),1),a.createVNode(qe,{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",eC,[...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,Z2)),64)),p[3]||(p[3]=a.createElementVNode("div",{class:"wov-separator"},null,-1)),a.createElementVNode("div",tC,[a.createElementVNode("input",{class:"wov-custom-input",value:l.value,onInput:d,onKeydown:u,placeholder:"Custom size"},null,40,nC),p[2]||(p[2]=a.createElementVNode("span",{class:"wov-px-suffix"},"px",-1))])],32)]),_:1})):a.createCommentVNode("",!0)}}),Wl=a.defineComponent({__name:"TextItalicButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Nn,{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)}}),Kl=a.defineComponent({__name:"TextUnderlineButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds);return(r,s)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Nn,{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)}}),oC={class:"wov-link-input-container"},rC=["onKeydown"],ql=a.defineComponent({__name:"TextLinkButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>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}=to(l,c,{placement:"top",middleware:[Qn(8),eo(),Zn({padding:8})],whileElementsMounted:Ts});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,w;const y=g.target;!((k=l.value)!=null&&k.contains(y))&&!((w=c.value)!=null&&w.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(Nn,{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",oC,[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,rC),[[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))}}),sC={class:"wov-text-color-button"},iC={class:"wov-text-icon-container"},Jl=a.defineComponent({__name:"TextColorButton",props:{entityIds:{}},setup(n){const e=n,{state:t,commands:o}=ot(()=>e.entityIds),r=a.computed(()=>t.color??"#000000"),s=a.computed(()=>({backgroundColor:r.value}));function i(l){o.setColor(zo(l))}return(l,c)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createBlock(Ke,{key:0,title:"Text Color"},{button:a.withCtx(()=>[a.createElementVNode("div",sC,[a.createElementVNode("div",iC,[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(qe,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createVNode(Ns,{currentColor:r.value,withPicker:!0,onChange:i},null,8,["currentColor"])]),_:1})):a.createCommentVNode("",!0)}}),lC={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"},aC={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"},cC={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"},xh=a.defineComponent({__name:"VerticalAlignButton",props:{entityIds:{}},setup(n){const e=n,{nextEditorTick:t}=de(),{state:o}=ot(()=>e.entityIds),r=[b.VerticalAlignment.Top,b.VerticalAlignment.Center,b.VerticalAlignment.Bottom],s=Bt(()=>e.entityIds,b.VerticalAlign),i=a.computed(()=>{let c=null;for(const d of s.value.values()){const u=(d==null?void 0:d.value)??b.VerticalAlignment.Top;if(c===null)c=u;else if(c!==u)return null}return c});function l(){const c=i.value??b.VerticalAlignment.Top,d=r.indexOf(c),u=r[(d+1)%r.length];t(f=>{for(const h of e.entityIds){const p=b.VerticalAlign.write(f,h);p.value=u}})}return(c,d)=>a.unref(o).showTextMenuButtons?(a.openBlock(),a.createBlock(Nn,{key:0,title:"Vertical Align",onClick:l},{default:a.withCtx(()=>[i.value===a.unref(b.VerticalAlignment).Top||i.value===null?(a.openBlock(),a.createElementBlock("svg",lC,[...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(b.VerticalAlignment).Center?(a.openBlock(),a.createElementBlock("svg",aC,[...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",cC,[...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)}}),dC={class:"wov-text-group-button"},uC={class:"wov-text-group-dropdown"},fC={class:"wov-text-group-row wov-text-group-row-full"},hC={class:"wov-text-group-row"},pC=a.defineComponent({__name:"TextButtonGroup",props:{entityIds:{},showVerticalAlign:{type:Boolean}},setup(n){const e=n,{state:t}=ot(()=>e.entityIds),o=a.inject("containerRef"),{width:r}=bh(o),s=a.computed(()=>r.value>0&&r.value<600),i=a.ref(new Map);return a.provide(ia,i),(l,c)=>a.unref(t).showTextMenuButtons?(a.openBlock(),a.createElementBlock(a.Fragment,{key:0},[s.value?(a.openBlock(),a.createBlock(Ke,{key:0,title:"Text Formatting",placement:"top"},{button:a.withCtx(()=>[a.createElementVNode("div",dC,[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(qe,{class:"wov-chevron-down"})])]),dropdown:a.withCtx(()=>[a.createElementVNode("div",uC,[a.createElementVNode("div",fC,[a.createVNode(Ul,{entityIds:n.entityIds},null,8,["entityIds"]),c[1]||(c[1]=a.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),a.createVNode(jl,{entityIds:n.entityIds},null,8,["entityIds"])]),a.createElementVNode("div",hC,[a.createVNode(Fl,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Wl,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Kl,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(ql,{entityIds:n.entityIds},null,8,["entityIds"]),c[2]||(c[2]=a.createElementVNode("div",{class:"wov-text-group-spacer"},null,-1)),a.createVNode(Jl,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(zl,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(a.openBlock(),a.createBlock(xh,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):a.createCommentVNode("",!0)])])]),_:1})):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[a.createVNode(Ul,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(jl,{entityIds:n.entityIds},null,8,["entityIds"]),c[3]||(c[3]=a.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),a.createVNode(Fl,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Wl,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(Kl,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(ql,{entityIds:n.entityIds},null,8,["entityIds"]),c[4]||(c[4]=a.createElementVNode("div",{divider:"",class:"wov-divider"},null,-1)),a.createVNode(Jl,{entityIds:n.entityIds},null,8,["entityIds"]),a.createVNode(zl,{entityIds:n.entityIds},null,8,["entityIds"]),n.showVerticalAlign?(a.openBlock(),a.createBlock(xh,{key:0,entityIds:n.entityIds},null,8,["entityIds"])):a.createCommentVNode("",!0)],64))],64)):a.createCommentVNode("",!0)}}),Sh=a.defineComponent({__name:"CanvasBackground",props:{background:{}},setup(n){const e=n,t=Te(b.Camera),o=Te(b.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,w,C){const x=C/2;y.beginPath(),y.arc(k,w,x,0,Math.PI*2),y.fill()}function u(y,k,w){if(!c)return null;const C=w.dotSize??2,x=y*w.subdivisionStep,S=k*w.subdivisionStep;if(x<=0||S<=0)return null;c.width=x,c.height=S;const M=c.getContext("2d");if(!M)return null;if(M.clearRect(0,0,x,S),M.fillStyle=w.strokeColor,w.subdivisionStep===1)d(M,x/2,S/2,C);else for(let E=0;E<w.subdivisionStep;E++)for(let T=0;T<w.subdivisionStep;T++){const v=(E+.5)*(x/w.subdivisionStep),B=(T+.5)*(S/w.subdivisionStep),D=E===0&&T===0?2*C:C;d(M,v,B,D)}return M.createPattern(c,"repeat")}function f(y,k,w,C,x,S){y.lineWidth=S,y.beginPath(),y.moveTo(k,w),y.lineTo(C,x),y.stroke()}function h(y,k,w){if(!c)return null;const C=w.gridSize??1,x=y*w.subdivisionStep,S=k*w.subdivisionStep;if(x<=0||S<=0)return null;c.width=x,c.height=S;const M=c.getContext("2d");if(!M)return null;if(M.clearRect(0,0,x,S),M.strokeStyle=w.strokeColor,w.subdivisionStep===1)f(M,0,0,x,0,C),f(M,0,0,0,S,C);else{const E=x/w.subdivisionStep,T=S/w.subdivisionStep;for(let v=0;v<=w.subdivisionStep;v++){const B=v*E,I=v%w.subdivisionStep===0;f(M,B,0,B,S,I?3*C:C)}for(let v=0;v<=w.subdivisionStep;v++){const B=v*T,I=v%w.subdivisionStep===0;f(M,0,B,x,B,I?3*C:C)}}return M.createPattern(c,"repeat")}function p(y){let k=o.value.colWidth,w=o.value.rowHeight;const C=e.background.subdivisionStep,x=s.value.width,S=s.value.height,M=t.value.left,E=t.value.top,T=M+x/t.value.zoom,v=E+S/t.value.zoom;let B=k*C,I=w*C,D=0,V=0,z=Number.POSITIVE_INFINITY,W=Number.POSITIVE_INFINITY;for(;;){B=C*k,I=C*w,D=Math.floor(M/B)*B,V=Math.floor(E/I)*I;const Be=Math.ceil(T/B)*B,ce=Math.ceil(v/I)*I;if(W=Math.round((Be-D)/k),z=Math.round((ce-V)/w),Math.max(W,z)>200)k*=2,w*=2;else break}const J=k*t.value.zoom,K=w*t.value.zoom,U=Math.round(J),F=Math.round(K),X=u(U,F,e.background);if(!X)return;X.setTransform(new DOMMatrix().scale(J/U,K/F));const oe=(D-M-k/2)*t.value.zoom,ie=(V-E-w/2)*t.value.zoom;y.save(),y.translate(oe,ie),y.fillStyle=X,y.fillRect(0,0,x+B*t.value.zoom,S+I*t.value.zoom),y.restore()}function m(y){let k=o.value.colWidth,w=o.value.rowHeight;const C=e.background.subdivisionStep,x=s.value.width,S=s.value.height,M=t.value.left,E=t.value.top,T=M+x/t.value.zoom,v=E+S/t.value.zoom;let B=k*C,I=w*C,D=0,V=0,z=Number.POSITIVE_INFINITY,W=Number.POSITIVE_INFINITY;for(;;){B=C*k,I=C*w,D=Math.floor(M/B)*B,V=Math.floor(E/I)*I;const Be=Math.ceil(T/B)*B,ce=Math.ceil(v/I)*I;if(W=Math.round((Be-D)/k),z=Math.round((ce-V)/w),Math.max(W,z)>200)k*=2,w*=2;else break}const J=k*t.value.zoom,K=w*t.value.zoom,U=Math.round(J),F=Math.round(K),X=h(U,F,e.background);if(!X)return;X.setTransform(new DOMMatrix().scale(J/U,K/F));const oe=(D-M)*t.value.zoom,ie=(V-E)*t.value.zoom;y.save(),y.translate(oe,ie),y.fillStyle=X,y.fillRect(0,0,x+B*t.value.zoom,S+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:w,height:C}=s.value;w===0||C===0||(y.width=w,y.height=C,k.clearRect(0,0,w,C),k.fillStyle=e.background.color,k.fillRect(0,0,w,C),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 Eh(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 vh=a.defineComponent({__name:"FloatingMenuBar",setup(n){const e=a.useSlots(),{reset:t}=Ot(),o=a.inject(aa),{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(ph,{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(yh,{entityIds:a.unref(r)},null,8,["entityIds"]),a.createVNode(gh,{entityIds:a.unref(r)},null,8,["entityIds"]),a.createVNode(kh,{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(mh,{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(uh,{entityIds:a.unref(r)},null,8,["entityIds"])]),a.renderSlot(d.$slots,"button:arrowHeadStart",{entityIds:a.unref(r)},()=>[a.createVNode(Vl,{entityIds:a.unref(r),side:"start"},null,8,["entityIds"])]),a.renderSlot(d.$slots,"button:arrowHeadEnd",{entityIds:a.unref(r)},()=>[a.createVNode(Vl,{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(wh,{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(pC,{entityIds:a.unref(r),showVerticalAlign:a.unref(s).has("verticalAlign")},null,8,["entityIds","showVerticalAlign"])]):a.createCommentVNode("",!0),a.createVNode($l)],32))}}),mC={class:"wov-floating-menu-inner"},Mh=a.defineComponent({__name:"FloatingMenu",setup(n){const e=a.inject(He),t=If([b.Block,le.Selected]),o=Te(b.Camera),r=Te(b.Screen),s=Te(le.SelectionStateSingleton),i=Fo(),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 S=t.value.map(M=>({tag:M.block.value.tag}));return Eh(x,S)});a.provide(aa,{selectedIds:l,commonComponents:c});const d=[0,0,0,0];function u(...x){let S=1/0,M=1/0,E=-1/0,T=-1/0,v=!1;for(const B of x){if(!B)continue;const I=B.getBoundingClientRect();I.width<=0||(v=!0,S=Math.min(S,I.left),M=Math.min(M,I.top),E=Math.max(E,I.right),T=Math.max(T,I.bottom))}return v?{x:S,y:M,left:S,top:M,right:E,bottom:T,width:E-S,height:T-M,toJSON:()=>({})}:null}const f=a.computed(()=>{if(t.value.length===0)return null;const x=o.value;if(!x)return null;let S=null;for(const M of t.value){const E=M.block.value;Pe.Rect.getAabb(E.position,E.size,E.rotateZ,d),Pe.Aabb.translate(d,[-x.left,-x.top]),Pe.Aabb.scale(d,x.zoom),S===null?S=Pe.Aabb.clone(d):Pe.Aabb.union(S,d)}return S}),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 S=i.blockElement.value,M=i.textElement.value,E=u(S,M);if(E)return{getBoundingClientRect:()=>E};const T=f.value;if(!T)return null;const v=x.getBoundingClientRect();return{getBoundingClientRect(){return{x:v.left+T[0],y:v.top+T[1],width:T[2]-T[0],height:T[3]-T[1],top:v.top+T[1],left:v.left+T[0],right:v.left+T[2],bottom:v.top+T[3]}}}}),m=a.ref(null),g={name:"clampToViewport",fn({y:x,rects:S}){const T=window.innerHeight-S.floating.height-8;return{y:Math.max(8,Math.min(x,T))}}},{floatingStyles:y}=to(p,m,{placement:"top",middleware:[Qn(12),eo({fallbackPlacements:["bottom"]}),Zn({padding:8}),g]}),k=a.computed(()=>{const x=f.value,S=r.value;return!x||!S?!0:x[2]<0||x[0]>S.width||x[3]<0||x[1]>S.height}),w=[le.SelectionState.Dragging,le.SelectionState.SelectionBoxDragging],C=a.computed(()=>t.value.length>0&&!k.value&&!w.includes(s.value.state));return(x,S)=>(a.openBlock(),a.createBlock(a.Transition,{name:"wov-fade"},{default:a.withCtx(()=>[C.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",mC,[a.renderSlot(x.$slots,"default",{},()=>[a.createVNode(vh)])])],4)):a.createCommentVNode("",!0)]),_:3}))}}),gC={key:0,class:"wov-loading-overlay"},yC={class:"wov-loading-spinner"},Th=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",gC,[a.createElementVNode("div",yC,a.toDisplayString(e.value),1)])):a.createCommentVNode("",!0)]),_:1}))}}),no="editing",kC={class:"wov-action-bar"},wC=a.defineComponent({__name:"ActionBar",setup(n){const{getEditor:e}=de(),t=a.inject(He),o=a.ref(!1),r=a.ref(!1);if(t){const c=t.registerTickCallback(d=>{const{store:u}=b.getPluginResources(d,no);o.value=u.canUndo(),r.value=u.canRedo()});a.onUnmounted(c)}function s(){const c=e();c==null||c.command(b.Undo)}function i(){const c=e();c==null||c.command(b.Redo)}function l(){const c=e();c==null||c.command(le.RemoveSelected)}return(c,d)=>(a.openBlock(),a.createElementBlock("div",kC,[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)])])]))}}),lt=a.defineComponent({__name:"ToolbarButton",props:{name:{},tooltip:{},dragOutSnapshot:{},placementSnapshot:{},cursor:{default:"crosshair"}},setup(n){const e=n,t=a.inject(_s);if(!t)throw new Error("ToolbarButton must be used within a Toolbar component");const o=t,r=a.ref(null),{show:s,hide:i}=Ot(),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))}}),bC='<?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>',CC='<?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>',xC='<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>',nn={Select:"select",Hand:"hand",Crosshair:"crosshair"},Nh={[nn.Select]:{makeSvg:()=>bC,hotspot:[1,0],rotationOffset:0},[nn.Hand]:{makeSvg:()=>CC,hotspot:[12,12],rotationOffset:0},[nn.Crosshair]:{makeSvg:()=>xC,hotspot:[12,12],rotationOffset:0}},SC={viewBox:"0 0 20 20",style:{"fill-rule":"evenodd","clip-rule":"evenodd","stroke-miterlimit":"10"}},Ah=a.defineComponent({__name:"SelectTool",setup(n){const{nextEditorTick:e}=de(),{activeTool:t}=ps();return a.watch(t,(o,r)=>{r==="select"&&e(s=>{le.DeselectAll.spawn(s)})}),(o,r)=>(a.openBlock(),a.createBlock(lt,{name:"select",tooltip:"Select",cursor:a.unref(nn).Select},{default:a.withCtx(()=>[(a.openBlock(),a.createElementBlock("svg",SC,[...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"]))}}),Bh=a.defineComponent({__name:"HandTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(lt,{name:"hand",tooltip:"Hand",cursor:a.unref(nn).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"]))}}),Ih=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:b.TextAlignment.Center},verticalAlign:{value:b.VerticalAlignment.Center}});return(t,o)=>(a.openBlock(),a.createBlock(lt,{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"]))}}),Oh=a.defineComponent({__name:"ShapeTool",setup(n){const e=JSON.stringify({block:{tag:"shape",size:[200,200]},shape:{kind:"rectangle",strokeKind:b.StrokeKind.Solid,strokeWidth:2,strokeRed:0,strokeGreen:0,strokeBlue:0,strokeAlpha:255,fillRed:255,fillGreen:255,fillBlue:255,fillAlpha:0},text:{defaultAlignment:b.TextAlignment.Center},verticalAlign:{value:b.VerticalAlignment.Center}});return(t,o)=>(a.openBlock(),a.createBlock(lt,{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"]))}}),Rh=a.defineComponent({__name:"EraserTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(lt,{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}))}}),Ph=a.defineComponent({__name:"PenTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(lt,{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}))}}),Dh=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(lt,{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"]))}}),_h=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(lt,{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"]))}}),Lh=a.defineComponent({__name:"ImageTool",setup(n){const{nextEditorTick:e}=de(),{show:t,hide:o}=Ot(),{setTool:r}=ps(),{createImageBlock:s}=Bf(),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=b.Camera.read(g),k=b.Screen.read(g),w=y.left+k.width/y.zoom/2,C=y.top+k.height/y.zoom/2;await s(m,w,C),r("select",void 0,nn.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))}}),EC={class:"wov-embed-provider-grid"},vC=["onClick"],MC={class:"wov-embed-provider-icon"},TC={key:0,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},NC={key:1,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},AC={key:2,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},BC={key:3,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},IC={key:4,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},OC={key:5,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},RC={key:6,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},PC={key:7,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"1.5","stroke-linecap":"round","stroke-linejoin":"round"},DC={class:"wov-embed-provider-label"},_C={class:"wov-embed-panel-header"},LC={class:"wov-embed-url-form"},VC=["placeholder"],$C={key:0,class:"wov-embed-url-error"},Vh=a.defineComponent({__name:"EmbedTool",setup(n){const{nextEditorTick:e}=de(),{show:t,hide:o}=Ot(),{setTool:r}=ps(),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}=to(s,i,{placement:"top",middleware:[Qn(16),eo(),Zn({padding:8})],whileElementsMounted:Ts}),m=[{value:b.EmbedProvider.Youtube,label:"YouTube",icon:"youtube"},{value:b.EmbedProvider.Spotify,label:"Spotify",icon:"spotify"},{value:b.EmbedProvider.GoogleMaps,label:"Google Maps",icon:"map"},{value:b.EmbedProvider.GoogleCalendar,label:"Google Calendar",icon:"calendar"},{value:b.EmbedProvider.GoogleSlides,label:"Google Slides",icon:"slides"},{value:b.EmbedProvider.Figma,label:"Figma",icon:"figma"},{value:b.EmbedProvider.GithubGist,label:"GitHub Gist",icon:"gist"},{value:b.EmbedProvider.Tldraw,label:"tldraw",icon:"tldraw"}],g=a.computed(()=>{if(!d.value)return"Paste a URL...";switch(d.value){case b.EmbedProvider.Youtube:return"https://www.youtube.com/watch?v=...";case b.EmbedProvider.Spotify:return"https://open.spotify.com/track/...";case b.EmbedProvider.GoogleMaps:return"https://www.google.com/maps/...";case b.EmbedProvider.GoogleCalendar:return"https://calendar.google.com/...";case b.EmbedProvider.GoogleSlides:return"https://docs.google.com/presentation/...";case b.EmbedProvider.Figma:return"https://www.figma.com/...";case b.EmbedProvider.GithubGist:return"https://gist.github.com/...";case b.EmbedProvider.Tldraw:return"https://www.tldraw.com/...";default:return"Paste a URL..."}});function y(){c.value=!c.value,d.value=null,u.value="",f.value=""}function k(T){d.value=T,u.value="",f.value="",a.nextTick(()=>{var v;(v=l.value)==null||v.focus()})}function w(){d.value=null,u.value="",f.value=""}async function C(){const T=u.value.trim();if(!T){f.value="Please enter a URL";return}try{new URL(T)}catch{f.value="Please enter a valid URL";return}const v=d.value??b.detectEmbedProvider(T),B=b.validateEmbedUrl(T,v);if(B){f.value=B;return}const I=b.resolveEmbedUrl(T,v);let D=480,V=320;switch(v){case b.EmbedProvider.Youtube:D=560,V=315;break;case b.EmbedProvider.Spotify:D=352,V=152;break;case b.EmbedProvider.GoogleMaps:D=600,V=450;break;case b.EmbedProvider.GoogleCalendar:D=600,V=500;break;case b.EmbedProvider.GoogleSlides:D=640,V=389;break;case b.EmbedProvider.Figma:D=600,V=400;break;case b.EmbedProvider.GithubGist:D=500,V=300;break;case b.EmbedProvider.Tldraw:D=600,V=400;break}const z=await e(),W=b.Camera.read(z),J=b.Screen.read(z),K=W.left+J.width/W.zoom/2,U=W.top+J.height/W.zoom/2,F=b.Grid.read(z);F.enabled&&(D=Math.max(F.colWidth,Math.round(D/F.colWidth)*F.colWidth),V=Math.max(F.rowHeight,Math.round(V/F.rowHeight)*F.rowHeight));const X=b.createEntity(z);b.addComponent(z,X,b.Block);const oe=b.Block.write(z,X);oe.tag="embed",oe.position[0]=K-D/2,oe.position[1]=U-V/2,oe.size[0]=D,oe.size[1]=V,b.Grid.snapPosition(z,oe.position),b.addComponent(z,X,b.Embed);const ie=b.Embed.write(z,X);ie.url=T,ie.embedUrl=I,ie.provider=v,b.addComponent(z,X,Ve.Synced,{id:crypto.randomUUID()}),c.value=!1,d.value=null,u.value="",r("select",void 0,nn.Select)}function x(T){T.key==="Enter"?(T.preventDefault(),C()):T.key==="Escape"&&(T.preventDefault(),d.value?w():c.value=!1)}function S(T){const v=T.target;s.value&&!s.value.contains(v)&&i.value&&!i.value.contains(v)&&(c.value=!1)}a.watch(c,T=>{T?document.addEventListener("click",S,!0):document.removeEventListener("click",S,!0)});function M(){s.value&&t("Embed",s.value)}function E(){o()}return(T,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:M,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",_C,[a.createElementVNode("button",{class:"wov-embed-back-button",onClick:w},[...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",LC,[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,VC),[[a.vModelText,u.value]]),f.value?(a.openBlock(),a.createElementBlock("div",$C,a.toDisplayString(f.value),1)):a.createCommentVNode("",!0),a.createElementVNode("button",{class:"wov-embed-submit-button",onClick:C}," 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",EC,[(a.openBlock(),a.createElementBlock(a.Fragment,null,a.renderList(m,I=>a.createElementVNode("button",{key:I.value,class:"wov-embed-provider-button",onClick:D=>k(I.value)},[a.createElementVNode("span",MC,[I.icon==="youtube"?(a.openBlock(),a.createElementBlock("svg",TC,[...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",NC,[...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",AC,[...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",BC,[...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",IC,[...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",OC,[...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",RC,[...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",PC,[...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",DC,a.toDisplayString(I.label),1)],8,vC)),64))])],64))],4)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)],64)}}}),zC="https://storage.googleapis.com/download/storage/v1/b/zine-maker-public/o/tapes%2F7e3b7dde-927d-4b09-aeb4-d49eac36d4ea.png?generation=1715183194653465&alt=media",$h=a.defineComponent({__name:"TapeTool",setup(n){const e=JSON.stringify({block:{tag:"tape",size:[200,30]},tape:{thickness:30},asset:{identifier:zC,uploadState:"complete"}});return(t,o)=>(a.openBlock(),a.createBlock(lt,{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"]))}}),FC={class:"wov-toolbar-container"},zh=a.defineComponent({__name:"Toolbar",setup(n){const e=a.useSlots(),{reset:t}=Ot(),{nextEditorTick:o}=de(),r=a.ref(null),s=a.ref(null),i=Te(b.Controls),l=a.computed(()=>i.value.leftMouseTool),c=[Ah,Bh,Dh,Lh,Vh,Oh,_h,Ih,$h,Ph,Rh],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),w=a.ref(48),{width:C}=bh(d);function x(){return h.value?Array.from(h.value.children).filter(U=>!U.classList.contains("wov-overflow-button")&&!U.classList.contains("wov-menu-tooltip")):[]}function S(){var oe;const U=x();if(U.length===0)return;g.value=U.length;const F=getComputedStyle(h.value);k.value=parseFloat(F.gap)||8;const X=((oe=p.value)==null?void 0:oe.offsetWidth)||40;w.value=X+k.value,y.value=U.map(ie=>ie.offsetWidth)}function M(){if(y.value.length===0)return;const X=C.value-40-20,oe=k.value,ie=w.value;let Be=0,ce=0;for(let Fe=0;Fe<y.value.length;Fe++){const Bn=y.value[Fe],on=Be>0?Bn+oe:Bn,Rt=y.value.length-Fe-1>0?ie:0;if(Be+on+Rt<=X)Be+=on,ce++;else break}m.value=Math.max(1,ce)}a.watch(C,()=>{y.value.length>0&&M()}),a.onMounted(()=>{a.nextTick(()=>{S(),M()})});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:T}=to(p,u,{placement:"top",middleware:[Qn(16),eo(),Zn({padding:8})],whileElementsMounted:Ts});function v(){f.value=!f.value}function B(){f.value=!1}function I(U){const F=U.target;p.value&&!p.value.contains(F)&&u.value&&!u.value.contains(F)&&B()}a.watch(f,U=>{U?document.addEventListener("click",I,!0):document.removeEventListener("click",I,!0)}),a.watch(E,U=>{U||B()});function D(U,F,X){s.value=F??null,o(oe=>{const ie=b.Controls.write(oe);ie.leftMouseTool=U,ie.heldSnapshot=F??"",X&&b.Cursor.setCursor(oe,X)})}function V(U){o(F=>{const X=b.Controls.write(F);X.leftMouseTool="drag-out",X.heldSnapshot=U})}function z(U,F){r.value=U,s.value=F??null}function W(){r.value=null,s.value=null}function J(){t(),r.value&&s.value&&V(s.value),r.value=null,s.value=null}const K={activeTool:l,heldTool:r,setTool:D,dragOutTool:V,onToolPointerDown:z,onToolPointerUp:W};return a.provide(_s,K),(U,F)=>(a.openBlock(),a.createElementBlock("div",FC,[a.createVNode(wC),a.createElementVNode("div",{ref_key:"toolsContainerRef",ref:h,class:"wov-toolbar",onMouseleave:J},[a.unref(e).default?a.renderSlot(U.$slots,"default",{key:0}):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},a.renderList(c,(X,oe)=>a.createVNode(a.resolveDynamicComponent(X),{key:oe})),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($l)],544),a.unref(d)?(a.openBlock(),a.createBlock(a.Teleport,{key:0,to:a.unref(d)},[f.value&&E.value?(a.openBlock(),a.createElementBlock("div",{key:0,ref_key:"overflowMenuRef",ref:u,class:"wov-toolbar-overflow-menu",style:a.normalizeStyle(a.unref(T))},[a.unref(e).default?a.renderSlot(U.$slots,"default",{key:0}):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},a.renderList(c,(X,oe)=>a.createVNode(a.resolveDynamicComponent(X),{key:oe})),64))],4)):a.createCommentVNode("",!0)],8,["to"])):a.createCommentVNode("",!0)]))}}),HC=a.defineComponent({__name:"ArcArrowTool",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(lt,{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}))}}),UC={class:"wov-user-presence-avatars"},jC=["src","alt"],WC={class:"wov-user-presence-list"},KC=["src","alt"],qC={class:"wov-user-presence-name"},JC=4,Fh=a.defineComponent({__name:"UserPresence",props:{users:{}},setup(n){const e=n,t=a.ref(!1),o=a.ref(null);H2(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,JC));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",UC,[(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,jC)):(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",WC,[(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,KC)):(a.openBlock(),a.createElementBlock(a.Fragment,{key:1},[a.createTextVNode(a.toDisplayString(d.initials),1)],64))],4),a.createElementVNode("span",qC,a.toDisplayString(d.name),1)]))),128))])],32)):a.createCommentVNode("",!0)],512)):a.createCommentVNode("",!0)}}),Gl=(n,e)=>e.some(t=>n instanceof t);let Hh,Uh;function GC(){return Hh||(Hh=[IDBDatabase,IDBObjectStore,IDBIndex,IDBCursor,IDBTransaction])}function YC(){return Uh||(Uh=[IDBCursor.prototype.advance,IDBCursor.prototype.continue,IDBCursor.prototype.continuePrimaryKey])}const Yl=new WeakMap,Xl=new WeakMap,Os=new WeakMap;function XC(n){const e=new Promise((t,o)=>{const r=()=>{n.removeEventListener("success",s),n.removeEventListener("error",i)},s=()=>{t(An(n.result)),r()},i=()=>{o(n.error),r()};n.addEventListener("success",s),n.addEventListener("error",i)});return Os.set(e,n),e}function QC(n){if(Yl.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)});Yl.set(n,e)}let Ql={get(n,e,t){if(n instanceof IDBTransaction){if(e==="done")return Yl.get(n);if(e==="store")return t.objectStoreNames[1]?void 0:t.objectStore(t.objectStoreNames[0])}return An(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 jh(n){Ql=n(Ql)}function ZC(n){return YC().includes(n)?function(...e){return n.apply(Zl(this),e),An(this.request)}:function(...e){return An(n.apply(Zl(this),e))}}function ex(n){return typeof n=="function"?ZC(n):(n instanceof IDBTransaction&&QC(n),Gl(n,GC())?new Proxy(n,Ql):n)}function An(n){if(n instanceof IDBRequest)return XC(n);if(Xl.has(n))return Xl.get(n);const e=ex(n);return e!==n&&(Xl.set(n,e),Os.set(e,n)),e}const Zl=n=>Os.get(n);function tx(n,e,{blocked:t,upgrade:o,blocking:r,terminated:s}={}){const i=indexedDB.open(n,e),l=An(i);return o&&i.addEventListener("upgradeneeded",c=>{o(An(i.result),c.oldVersion,c.newVersion,An(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 nx=["get","getKey","getAll","getAllKeys","count"],ox=["put","add","delete","clear"],ea=new Map;function Wh(n,e){if(!(n instanceof IDBDatabase&&!(e in n)&&typeof e=="string"))return;if(ea.get(e))return ea.get(e);const t=e.replace(/FromIndex$/,""),o=e!==t,r=ox.includes(t);if(!(t in(o?IDBIndex:IDBObjectStore).prototype)||!(r||nx.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 ea.set(e,s),s}jh(n=>({...n,get:(e,t,o)=>Wh(e,t)||n.get(e,t,o),has:(e,t)=>!!Wh(e,t)||n.has(e,t)}));const rx=["continue","continuePrimaryKey","advance"],Kh={},ta=new WeakMap,qh=new WeakMap,sx={get(n,e){if(!rx.includes(e))return n[e];let t=Kh[e];return t||(t=Kh[e]=function(...o){ta.set(this,qh.get(this)[e](...o))}),t}};async function*ix(...n){let e=this;if(e instanceof IDBCursor||(e=await e.openCursor(...n)),!e)return;e=e;const t=new Proxy(e,sx);for(qh.set(t,e),Os.set(t,Zl(e));e;)yield t,e=await(ta.get(t)||e.continue()),ta.delete(t)}function Jh(n,e){return e===Symbol.asyncIterator&&Gl(n,[IDBIndex,IDBObjectStore,IDBCursor])||e==="iterate"&&Gl(n,[IDBIndex,IDBObjectStore])}jh(n=>({...n,get(e,t,o){return Jh(e,t)?ix:n.get(e,t,o)},has(e,t){return Jh(e,t)||n.has(e,t)}}));async function na(n,e){const t=await tx(n,1,{upgrade(o){o.objectStoreNames.contains(e)||o.createObjectStore(e)}});return new lx(t,e)}var lx=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()}},ax=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([na(`${n}-jobs`,"jobs"),na(`${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))}}},cx="wovencanvas-assets",dx="blobs",ux=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=na(cx,dx).then(n=>(this.store=n,n))),this.initPromise)}};const fx={class:"wov-selection-box"},hx=a.defineComponent({__name:"SelectionBox",setup(n){return(e,t)=>(a.openBlock(),a.createElementBlock("div",fx))}}),px={class:"wov-transform-box"},mx=a.defineComponent({__name:"TransformBox",setup(n){return(e,t)=>(a.openBlock(),a.createElementBlock("div",px))}}),gx={},yx={class:"wov-transform-handle"};function kx(n,e){return a.openBlock(),a.createElementBlock("div",yx)}const wx=sn(gx,[["render",kx]]),bx=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,b.Color),o=pe(e.entityId,b.VerticalAlign),r=a.ref(null),s={[b.VerticalAlignment.Top]:"flex-start",[b.VerticalAlignment.Center]:"center",[b.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)??b.VerticalAlignment.Top]}}),{handleEditEnd:l}=Bl({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(ms,a.mergeProps(e,{"block-element":r.value,onEditEnd:a.unref(l)}),null,16,["block-element","onEditEnd"])],4))}}),Rs=Ve.defineCanvasSingleton({name:"blockPlacementState"},{editedCheckpoint:b.field.string().default("").max(36)}),Gh=b.defineQuery(n=>n.with(b.Edited));function Cx(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 xx(n,e,t){const o=b.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];b.Grid.snapPosition(n,s);const[i,l]=s,c=e.block.rank??b.RankBounds.genNext(n),d=b.createEntity(n);"synced"in e||b.addComponent(n,d,b.Synced,{id:crypto.randomUUID()});const u=Object.assign({},e.block,{position:[i,l],size:r,rank:c});b.addComponent(n,d,b.Block,u);for(const h of o.components)if(!(h.name in e))b.addComponent(n,d,h);else{const p=e[h.name];b.addComponent(n,d,h,p)}const{sessionId:f}=b.getResources(n);return b.addComponent(n,d,b.Held,{sessionId:f}),d}function Yh(n,e,t,o,r){const s=xx(n,e,t),i=b.Block.read(n,s);if(b.canBlockEdit(n,e.block.tag)&&(b.addComponent(n,s,le.EditAfterPlacing,{}),r==="placement")){const{store:u}=b.getPluginResources(n,no),f=u.createCheckpoint();if(f){const h=Rs.write(n);h.editedCheckpoint=f}}const l=le.SelectionStateSingleton.write(n);l.state=r==="dragOut"?le.SelectionState.Dragging:le.SelectionState.Pointing,l.dragStart=t,l.draggedEntity=s,l.draggedEntityStart=i.position,l.pointingStartClient=o,l.pointingStartWorld=t,l.isCloning=!1;const c=b.Controls.write(n);c.leftMouseTool="select",c.heldSnapshot="";const d=b.Cursor.write(n);d.cursorKind="select",d.rotation=0}function Sx(n){const e=Rs.read(n);if(e.editedCheckpoint){const t=e.editedCheckpoint;Rs.write(n).editedCheckpoint="";const{store:o}=b.getPluginResources(n,no);o.onSettled(()=>o.squashToCheckpoint(t),{frames:5})}}const Ex=b.defineEditorSystem({phase:"capture"},n=>{Gh.removed(n).length>0&&Gh.current(n).length===0&&Sx(n);const e=b.Controls.read(n);if(!e.heldSnapshot)return;const t=b.getPointerInput(n,[b.PointerButton.Left]);if(t.length===0)return;const o=Cx(e.heldSnapshot);if(!o)return;if(e.leftMouseTool==="drag-out"){const s=t.find(i=>i.type==="pointerMove"&&!i.obscured);if(!s)return;Yh(n,o,s.worldPosition,s.screenPosition,"dragOut")}else{const s=t.find(i=>i.type==="pointerDown"&&!i.obscured);if(!s)return;Yh(n,o,s.worldPosition,s.screenPosition,"placement")}}),vx=b.defineEditorSystem({phase:"update"},n=>{const{store:e}=b.getPluginResources(n,no);b.on(n,b.Undo,()=>{e.canUndo()&&(le.deselectAll(n),e.undo())}),b.on(n,b.Redo,()=>{e.canRedo()&&(le.deselectAll(n),e.redo())})}),Mx=[{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 Xh(n){return{name:no,resources:{store:n.store},singletons:[Rs],systems:[Ex,vx],cursors:Nh,fonts:Mx,keybinds:[{command:b.Undo.name,key:b.Key.Z,mod:!0},{command:b.Redo.name,key:b.Key.Y,mod:!0},{command:b.Redo.name,key:b.Key.Z,mod:!0,shift:!0}]}}const Tx=a.defineComponent({__name:"FileDropZone",props:{maxSize:{default:400}},setup(n){const e=n,{nextEditorTick:t}=de(),{createImageBlock:o}=Bf(),r=a.ref(!1);let s=0;const i=a.inject("containerRef");function l(w){var C;(C=w.dataTransfer)!=null&&C.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 w=i==null?void 0:i.value;w&&(w.addEventListener("dragenter",l),w.addEventListener("dragleave",c),w.addEventListener("drop",d))}),a.onUnmounted(()=>{const w=i==null?void 0:i.value;w&&(w.removeEventListener("dragenter",l),w.removeEventListener("dragleave",c),w.removeEventListener("drop",d))});function u(w){w.preventDefault(),w.dataTransfer&&(w.dataTransfer.dropEffect="copy")}function f(w){w.preventDefault()}function h(w){w.preventDefault()}async function p(w){if(w.preventDefault(),!w.dataTransfer)return;const C=w.clientX,x=w.clientY,S=Array.from(w.dataTransfer.files).filter(E=>E.type.startsWith("image/"));if(S.length>0){for(const E of S)await y(E,C,x);return}const M=m(w.dataTransfer);M&&await k(M,C,x)}function m(w){const C=w.getData("text/uri-list");if(C){const E=C.split(`
107
+ `).filter(T=>!T.startsWith("#")).find(T=>g(T));if(E)return E}const x=w.getData("text/html");if(x){const M=x.match(/<img[^>]+src=["']([^"']+)["']/i);if(M!=null&&M[1])return M[1]}const S=w.getData("text/plain");return S&&g(S)?S:null}function g(w){try{const x=new URL(w).pathname.toLowerCase();return/\.(jpg|jpeg|png|gif|webp|svg|bmp|ico)$/i.test(x)||w.startsWith("data:image/"),!0}catch{return!1}}async function y(w,C,x){const S=await t(),M=b.Camera.read(S),E=b.Screen.read(S),T=M.left+(C-E.left)/M.zoom,v=M.top+(x-E.top)/M.zoom;await o(w,T,v,{maxSize:e.maxSize})}async function k(w,C,x){try{const S=await fetch(w);if(!S.ok){console.warn("Failed to fetch image from URL:",w);return}const M=await S.blob();if(!M.type.startsWith("image/")){console.warn("URL did not return an image:",w);return}const T=new URL(w).pathname.split("/").pop()||"image",v=new File([M],T,{type:M.type});await y(v,C,x)}catch(S){console.warn("Failed to load image from URL:",w,S)}}return(w,C)=>(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))}}),Nx={class:"wov-user-cursors"},Ax={class:"wov-cursor-svg",viewBox:"0 0 4.35 4.75",width:"20",height:"20"},Bx=["fill"],Ix="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",Ox=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",Nx,[(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",Ax,[a.createElementVNode("path",{fill:s.color,stroke:"#fff","stroke-miterlimit":"10","stroke-width":".25",d:Ix},null,8,Bx)])),a.createElementVNode("span",{class:"wov-cursor-label",style:a.normalizeStyle({backgroundColor:s.color})},a.toDisplayString(s.name),5)],4))),128))]))}}),Rx={key:0,class:"wov-offline-indicator"},Px=a.defineComponent({__name:"OfflineIndicator",props:{isOnline:{type:Boolean}},setup(n){return(e,t)=>n.isOnline?a.createCommentVNode("",!0):(a.openBlock(),a.createElementBlock("div",Rx,"Working Offline"))}}),Dx={key:0,class:"wov-version-mismatch-overlay"},_x=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",Dx,[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)}}),Lx=a.defineComponent({__name:"BackToContentButton",setup(n){const{nextEditorTick:e}=de(),t=Te(b.Camera),o=b.defineQuery(d=>d.with(b.Synced,b.Block,b.Aabb)),r=a.ref(0),s=a.inject(He);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 D=b.Aabb.read(d,I);f=Math.min(f,D.value[0]),h=Math.min(h,D.value[1]),p=Math.max(p,D.value[2]),m=Math.max(m,D.value[3])}const g=b.Screen.read(d),y=b.Camera.read(d),k=b.getPluginResources(d,Ps.CONTROLS_PLUGIN_NAME)??Ps.DEFAULT_CONTROLS_OPTIONS;let w=Math.min(g.width/(p-f),g.height/(m-h));w/=1.1,w=Math.min(w,y.zoom),w=Math.max(k.minZoom,Math.min(k.maxZoom,w));const C=(f+p)/2,x=(h+m)/2;let S=C-g.width/w/2,M=x-g.height/w/2;const E=g.width/w,T=g.height/w;let v=!1;for(const I of u){const D=b.Aabb.read(d,I);if(l(D.value,S,M,E,T)){v=!0;break}}if(!v){const I=Math.floor(Math.random()*u.length),D=u[I],V=b.Aabb.read(d,D),z=(V.value[0]+V.value[2])/2,W=(V.value[1]+V.value[3])/2;S=z-E/2,M=W-T/2}const B=b.Camera.write(d);B.left=S,B.top=M,B.zoom=w})}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)}}),Vx=["data-entity-id","data-selected","data-held-by-other","data-hovered"],$x=a.defineComponent({__name:"WovenCanvasCore",props:{store:{},editor:{},background:{},assetProvider:{},pluginOptions:{},controls:{},initialState:{}},emits:["ready"],async setup(n,{emit:e}){var ep;let t,o;const r=b.defineQuery(A=>A.tracking(b.Block)),s=b.defineQuery(A=>A.with(b.Block).tracking(b.Connector)),i=b.defineQuery(A=>A.with(b.Block).tracking(le.Selected)),l=b.defineQuery(A=>A.with(b.Block).tracking(b.Held)),c=b.defineQuery(A=>A.with(b.Block).tracking(b.Hovered)),d=b.defineQuery(A=>A.with(b.Block).tracking(b.Edited)),u=b.defineQuery(A=>A.with(b.Block).tracking(b.Opacity)),f=b.defineQuery(A=>A.tracking(b.User)),h=n,p=e,m=a.ref(null),g=a.shallowRef(null),y=b.UserData.parse(((ep=h.editor)==null?void 0:ep.user)??{}),k=new Set,w=new Map,C=a.shallowRef([]),x=new Map,S=new Map,M=new Set,E=new Map,T=a.shallowRef([]),v=a.ref(!0),B=a.ref(!1),I=a.ref(!h.initialState),D=a.shallowRef(b.Camera.default());function V(A,j,N){let G=x.get(A);G||(G=new Map,x.set(A,G));let _=G.get(j);return _||(_=new Set,G.set(j,_)),_.add(N),()=>{_.delete(N),_.size===0&&(G.delete(j),G.size===0&&x.delete(A))}}function z(A,j,N,G=!1){const _=x.get(j);if(!_)return;const L=_.get(N.name);if(!L||L.size===0)return;let Ce=null;G||(Ce=N.snapshot(A,j));for(const rn of L)rn(Ce)}function W(A,j){let N=S.get(A);return N||(N=new Set,S.set(A,N)),N.add(j),()=>{N.delete(j),N.size===0&&S.delete(A)}}function J(A,j){const N=S.get(j.name);if(!N||N.size===0)return;const G=j.snapshot(A);for(const _ of N)_(G)}function K(A){return M.add(A),()=>{M.delete(A)}}function U(){return y.sessionId}function F(A){return w.get(A)??null}const X={hasEntity:A=>k.has(A),getEditor:()=>g.value,getAssetManager:()=>Fe,getSessionId:U,getUserBySessionId:F,subscribeComponent:V,subscribeSingleton:W,registerTickCallback:K};a.provide(He,X),a.provide("containerRef",m);const oe=$f();a.provide(ca,oe);let ie=0,Be=null,ce=null,Fe=null;function Bn(A){var G;const j=[],N=h.pluginOptions;return(N==null?void 0:N.controls)!==!1&&j.push(Ps.CanvasControlsPlugin((N==null?void 0:N.controls)??{})),(N==null?void 0:N.selection)!==!1&&j.push(le.createSelectionPlugin((N==null?void 0:N.selection)||void 0)),(N==null?void 0:N.eraser)!==!1&&j.push(qo.createEraserPlugin((N==null?void 0:N.eraser)||void 0)),(N==null?void 0:N.pen)!==!1&&j.push(Jo.createPenPlugin()),(N==null?void 0:N.arrows)!==!1&&j.push(ee.createArrowsPlugin((N==null?void 0:N.arrows)||void 0)),(N==null?void 0:N.tapes)!==!1&&j.push(ip.createTapesPlugin()),j.push(Xh({store:A})),(G=h.editor)!=null&&G.plugins&&j.push(...h.editor.plugins),j}function on(){const A=h.store??{},j={history:!0,...A};return A.websocket&&(j.websocket={...A.websocket,onVersionMismatch:N=>{var G,_;B.value=!0,(_=(G=A.websocket)==null?void 0:G.onVersionMismatch)==null||_.call(G,N)},onConnectivityChange:N=>{var G,_;v.value=N,(_=(G=A.websocket)==null?void 0:G.onConnectivityChange)==null||_.call(G,N)}}),j}async function Wo(A,j){const N=on();A||(delete N.persistence,delete N.websocket),j&&(N.initialState=j),ce=new Ve.CanvasStore(N);const G={...h.editor,user:y,plugins:Bn(ce),controls:h.controls},_=new b.Editor(A,G);return await _.initialize(),await ce.initialize({components:_.components,singletons:_.singletons}),_}async function In(A){A.nextTick(j=>{ce&&ce.sync(j),Fx(j),Hx(j);for(const N of M)N(j)}),await A.tick()}async function Rt(){!g.value||!ce||(await In(g.value),Be=requestAnimationFrame(Rt))}if(W(b.Camera.name,A=>{A&&(D.value=A)}),h.initialState){const A=([t,o]=a.withAsyncContext(()=>Wo(null,h.initialState)),t=await t,o(),t);[t,o]=a.withAsyncContext(()=>In(A)),await t,o(),[t,o]=a.withAsyncContext(()=>In(A)),await t,o(),g.value=A}let Qh=null;a.onMounted(async()=>{var G;if(!m.value)return;Qh=()=>{var _;(_=m.value)==null||_.scrollTo(0,0)},m.value.addEventListener("scroll",Qh),g.value&&(g.value.dispose(),ce==null||ce.close(),ce=null,ie=0);const A=await Wo(m.value,h.initialState);g.value=A,I.value=!1;const N=((G=(h.store??{}).persistence)==null?void 0:G.documentId)??"default";Fe=new ax({provider:h.assetProvider??new ux,documentId:N}),await Fe.init(),await Fe.resumePendingUploads(),Be=requestAnimationFrame(Rt),p("ready",g.value,ce)}),a.onUnmounted(()=>{var A;Be!==null&&cancelAnimationFrame(Be),Fe==null||Fe.close(),ce==null||ce.close(),(A=g.value)==null||A.dispose()});function Fx(A){const{events:j,newIndex:N}=A.eventBuffer.readEvents(ie);if(ie=N,j.length===0)return;const{componentsById:G,singletonsById:_}=b.getResources(A);for(const{entityId:L,eventType:Ce,componentId:rn}of j){if(L===b.SINGLETON_ENTITY_ID){if(Ce===b.EventType.CHANGED){const at=_.get(rn);at&&J(A,at)}continue}if(Ce===b.EventType.ADDED)k.add(L);else if(Ce===b.EventType.REMOVED)k.delete(L),x.delete(L);else if(Ce===b.EventType.COMPONENT_ADDED){k.add(L);const at=G.get(rn);at&&z(A,L,at)}else if(Ce===b.EventType.COMPONENT_REMOVED){const at=G.get(rn);at&&z(A,L,at,!0)}else if(Ce===b.EventType.CHANGED){const at=G.get(rn);at&&z(A,L,at)}}}function Hx(A){var G;let j=!1;for(const _ of r.added(A)){const L=b.Block.snapshot(A,_),Ce=(G=g.value)==null?void 0:G.blockDefs[L.tag],rn=(Ce==null?void 0:Ce.stratum)??"content";E.set(_,a.ref({entityId:_,block:L,stratum:rn,selected:!1,held:null,hovered:!1,edited:!1,opacity:null,connector:null})),j=!0}for(const _ of r.removed(A))E.delete(_),j=!0;for(const _ of r.changed(A)){const L=E.get(_);if(L){const Ce=b.Block.snapshot(A,_);L.value.block.rank!==Ce.rank&&(j=!0),L.value.block=Ce}}let N=!1;for(const _ of f.addedOrChanged(A)){const L=b.User.snapshot(A,_);w.set(L.sessionId,L),N=!0}for(const _ of f.removed(A)){const L=b.User.read(A,_);w.delete(L.sessionId),N=!0}N&&(C.value=Array.from(w.values()));for(const _ of i.added(A)){const L=E.get(_);L&&!L.value.selected&&(L.value.selected=!0)}for(const _ of i.removed(A)){const L=E.get(_);L&&L.value.selected&&(L.value.selected=!1)}for(const _ of l.addedOrChanged(A)){const L=E.get(_);L&&(L.value.held=b.Held.snapshot(A,_))}for(const _ of l.removed(A)){const L=E.get(_);L&&L.value.held!==null&&(L.value.held=null)}for(const _ of c.added(A)){const L=E.get(_);L&&!L.value.hovered&&(L.value.hovered=!0)}for(const _ of c.removed(A)){const L=E.get(_);L&&L.value.hovered&&(L.value.hovered=!1)}for(const _ of d.added(A)){const L=E.get(_);L&&!L.value.edited&&(L.value.edited=!0)}for(const _ of d.removed(A)){const L=E.get(_);L&&L.value.edited&&(L.value.edited=!1)}for(const _ of u.addedOrChanged(A)){const L=E.get(_);L&&(L.value.opacity=b.Opacity.snapshot(A,_))}for(const _ of u.removed(A)){const L=E.get(_);L&&L.value.opacity!==null&&(L.value.opacity=null)}for(const _ of s.addedOrChanged(A)){const L=E.get(_);L&&(L.value.connector=b.Connector.snapshot(A,_))}for(const _ of s.removed(A)){const L=E.get(_);L&&L.value.connector!==null&&(L.value.connector=null)}if(j){const _=Array.from(E.values());_.sort((L,Ce)=>L.value.block.rank>Ce.value.block.rank?1:-1),T.value=_}}function Ux(A){const j=A.rotateZ!==0,N=A.flip[0],G=A.flip[1];if(!j&&!N&&!G)return;const _=[];return j&&_.push(`rotate(${A.rotateZ}rad)`),N&&_.push("scaleX(-1)"),G&&_.push("scaleY(-1)"),_.join(" ")}function Zh(A){const{held:j}=A;if(!j||!j.sessionId||j.sessionId===y.sessionId)return null;const N=F(j.sessionId);return(N==null?void 0:N.color)??null}function jx(A){const{block:j,stratum:N,opacity:G}=A,_=Zh(A),L=G!==null?G.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:b.STRATUM_ORDER[N]*1e3,transform:Ux(j),opacity:L,pointerEvents:"none",userSelect:"none","--wov-held-by-color":_??void 0,transition:L===1?"opacity 0ms 32ms":void 0}}return(A,j)=>(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(A.$slots,"background",{key:0,background:n.background},()=>[a.createVNode(Sh,{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(${D.value.zoom}) translate(${-D.value.left}px, ${-D.value.top}px)`,"--wov-zoom":D.value.zoom})},[(a.openBlock(!0),a.createElementBlock(a.Fragment,null,a.renderList(T.value,N=>(a.openBlock(),a.createElementBlock("div",{key:N.value.entityId,"data-entity-id":N.value.entityId,style:a.normalizeStyle(jx(N.value)),"data-selected":N.value.selected||void 0,"data-held-by-other":Zh(N.value)!==null||void 0,"data-hovered":N.value.hovered||void 0,class:"wov-block"},[a.renderSlot(A.$slots,`block:${N.value.block.tag}`,a.mergeProps({ref_for:!0},N.value),()=>[N.value.block.tag==="selection-box"?(a.openBlock(),a.createBlock(hx,a.mergeProps({key:0,ref_for:!0},N.value),null,16)):N.value.block.tag==="transform-box"?(a.openBlock(),a.createBlock(mx,a.mergeProps({key:1,ref_for:!0},N.value),null,16)):N.value.block.tag==="transform-handle"?(a.openBlock(),a.createBlock(wx,a.mergeProps({key:2,ref_for:!0},N.value),null,16)):N.value.block.tag==="arrow-handle"?(a.openBlock(),a.createBlock(ua,a.mergeProps({key:3,ref_for:!0},N.value),null,16)):N.value.block.tag==="arrow-terminal"?(a.openBlock(),a.createBlock(fa,a.mergeProps({key:4,ref_for:!0},N.value),null,16)):N.value.block.tag==="sticky-note"?(a.openBlock(),a.createBlock(bx,a.mergeProps({key:5,ref_for:!0},N.value),null,16)):N.value.block.tag==="eraser"?(a.openBlock(),a.createBlock(Ba,a.mergeProps({key:6,ref_for:!0},N.value),null,16)):N.value.block.tag==="pen-stroke"?(a.openBlock(),a.createBlock(Oa,a.mergeProps({key:7,ref_for:!0},N.value),null,16)):N.value.block.tag==="arc-arrow"?(a.openBlock(),a.createBlock(da,a.mergeProps({key:8,ref_for:!0},N.value),null,16)):N.value.block.tag==="elbow-arrow"?(a.openBlock(),a.createBlock(ha,a.mergeProps({key:9,ref_for:!0},N.value),null,16)):N.value.block.tag==="text"?(a.openBlock(),a.createBlock(Uf,a.mergeProps({key:10,ref_for:!0},N.value),null,16)):N.value.block.tag==="image"?(a.openBlock(),a.createBlock(Ia,a.mergeProps({key:11,ref_for:!0},N.value),null,16)):N.value.block.tag==="shape"?(a.openBlock(),a.createBlock(Ff,a.mergeProps({key:12,ref_for:!0},N.value),null,16)):N.value.block.tag==="embed"?(a.openBlock(),a.createBlock(pa,a.mergeProps({key:13,ref_for:!0},N.value),null,16)):N.value.block.tag==="tape"?(a.openBlock(),a.createBlock(Hf,a.mergeProps({key:14,ref_for:!0},N.value),null,16)):a.createCommentVNode("",!0)])],12,Vx))),128))],4),g.value?a.renderSlot(A.$slots,"user-cursors",{key:1,users:C.value,currentSessionId:a.unref(y).sessionId,camera:D.value},()=>[a.createVNode(Ox,{users:C.value,"current-session-id":a.unref(y).sessionId,camera:D.value},null,8,["users","current-session-id","camera"])]):a.createCommentVNode("",!0),g.value?(a.openBlock(),a.createBlock(Mh,{key:2},{default:a.withCtx(N=>[a.renderSlot(A.$slots,"floating-menu",a.normalizeProps(a.guardReactiveProps(N)))]),_:3})):a.createCommentVNode("",!0),g.value?a.renderSlot(A.$slots,"user-presence",{key:3,users:C.value},()=>[a.createVNode(Fh,{users:C.value},null,8,["users"])]):a.createCommentVNode("",!0),g.value?a.renderSlot(A.$slots,"toolbar",{key:4},()=>[a.createVNode(zh)]):a.createCommentVNode("",!0),g.value?a.renderSlot(A.$slots,"default",{key:5}):a.createCommentVNode("",!0),a.renderSlot(A.$slots,"offline-indicator",{isOnline:v.value},()=>[a.createVNode(Px,{"is-online":v.value},null,8,["is-online"])]),a.renderSlot(A.$slots,"version-mismatch",{versionMismatch:B.value},()=>[a.createVNode(_x,{"version-mismatch":B.value},null,8,["version-mismatch"])]),a.renderSlot(A.$slots,"back-to-content",{},()=>[a.createVNode(Lx)]),a.renderSlot(A.$slots,"loading",{isLoading:I.value},()=>[a.createVNode(Th,{"is-loading":I.value},null,8,["is-loading"])]),g.value?a.renderSlot(A.$slots,"file-drop-zone",{key:6},()=>[a.createVNode(Tx)]):a.createCommentVNode("",!0)],512))}}),zx=a.defineComponent({inheritAttrs:!1,__name:"WovenCanvas",setup(n){return(e,t)=>(a.openBlock(),a.createBlock(a.Suspense,null,{default:a.withCtx(()=>[a.createVNode($x,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(R,"CanvasComponentDef",{enumerable:!0,get:()=>Ve.CanvasComponentDef}),Object.defineProperty(R,"CanvasSingletonDef",{enumerable:!0,get:()=>Ve.CanvasSingletonDef}),Object.defineProperty(R,"CanvasStore",{enumerable:!0,get:()=>Ve.CanvasStore}),Object.defineProperty(R,"Synced",{enumerable:!0,get:()=>Ve.Synced}),Object.defineProperty(R,"defineCanvasComponent",{enumerable:!0,get:()=>Ve.defineCanvasComponent}),Object.defineProperty(R,"defineCanvasSingleton",{enumerable:!0,get:()=>Ve.defineCanvasSingleton}),R.ARROW_HEADS=Ds,R.ArcArrow=da,R.ArcArrowTool=HC,R.ArrowHandle=ua,R.ArrowHead=wt,R.ArrowHeadButton=Vl,R.ArrowTerminal=fa,R.ArrowThicknessButton=uh,R.CURSORS=Nh,R.CanvasBackground=Sh,R.ColorButton=ph,R.ColorPicker=hh,R.CursorKind=nn,R.EDITING_PLUGIN_NAME=no,R.EditableText=ms,R.EditingPlugin=Xh,R.ElbowArrow=ha,R.ElbowArrowTool=_h,R.EmbedBlock=pa,R.EmbedTool=Vh,R.Eraser=Ba,R.EraserTool=Rh,R.FloatingMenu=Mh,R.FloatingMenuBar=vh,R.HandTool=Bh,R.IconChevronDown=qe,R.ImageBlock=Ia,R.ImageTool=Lh,R.LoadingOverlay=Th,R.MenuButton=Nn,R.MenuDropdown=Ke,R.MenuTooltip=$l,R.PenStroke=Oa,R.PenStrokeThicknessButton=mh,R.PenTool=Ph,R.SHAPES=ro,R.SelectTool=Ah,R.ShapeBlock=Ff,R.ShapeFillColorButton=gh,R.ShapeKindButton=yh,R.ShapeStrokeColorButton=kh,R.ShapeTool=Oh,R.StickyNoteTool=Ih,R.TapeBlock=Hf,R.TapeImageButton=wh,R.TapeTool=$h,R.TextAlignmentButton=zl,R.TextBlock=Uf,R.TextBoldButton=Fl,R.TextColorButton=Jl,R.TextFontFamilyButton=Ul,R.TextFontSizeButton=jl,R.TextItalicButton=Wl,R.TextLinkButton=ql,R.TextTool=Dh,R.TextUnderlineButton=Kl,R.Toolbar=zh,R.ToolbarButton=lt,R.UserPresence=Fh,R.WovenCanvas=zx,R.computeCommonComponents=Eh,R.createTooltipContext=$f,R.getArrowHead=On,R.useComponent=pe,R.useComponents=Bt,R.useEditorContext=de,R.useFonts=Ch,R.useQuery=If,R.useSingleton=Te,R.useTextBatchController=Vf,R.useTextEditorController=Fo,R.useTextFormatting=ot,R.useTextStretchBehavior=Bl,R.useToolbar=ps,R.useTooltipSingleton=Ot,Object.defineProperty(R,Symbol.toStringTag,{value:"Module"})});