oficina / docs Public

Two the re-check found, one of them mine from an hour ago

focusStop was missing from createToolbar's early return. editor-entry.js
binds Escape to it and the comment beside that binding promises that
with no toolbar there is nowhere to go and false comes back — but the
no-root branch returned no focusStop at all, so Escape would have thrown
a TypeError inside ProseMirror's keymap. Unreachable today, because
show.html always renders the bar; which is exactly why a comment
asserting the guarantee needed the code to hold it.
toolbar-roving.mjs's own early return already did, and this one was
written an hour later without looking at it.

And the last corner where the two indent clamps disagreed: a run of ten
or more digits passes the digits-only check on both sides, then
overflows u32 in Rust and rendered flush left, while Number() here turns
it into a float far above the maximum and clamps to 8. A string that
passed the digit check can only fail the parse by being too large, so
unwrap_or(u32::MAX) is the right reading of it. The comment had claimed
agreement "on every input"; now it is true, and indent.test.mjs holds it.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev e8295bf5ce5fa7a25afc235d261df6a28e04bfd6 parent 18fbc4f
5 files changed, +33 −3
  • core/src/fragment.rs +12 −1
  • fixtures/indent.test.mjs +11 −0
  • fixtures/toolbar.mjs +9 −1
  • internal/core/testdata/docs_core.wasm binary
  • internal/docs/static/{editor.51ada8c82c1866c8.js => editor.d8d3d5d91b1c09c4.js} +1 −1

CI passed — run details

diff --git a/core/src/fragment.rs b/core/src/fragment.rs
index 2b1e942..5074ad3 100644
--- a/core/src/fragment.rs
+++ b/core/src/fragment.rs
@@ -216,7 +216,18 @@ fn indent_level<T: ReadTxn>(txn: &T, e: &XmlElementRef) -> Option<u8> {
if raw.is_empty() || !raw.bytes().all(|b| b.is_ascii_digit()) {
return None;
}
- let level = raw.parse::<u32>().ok()?.min(MAX_INDENT as u32) as u8;
+ // unwrap_or(u32::MAX), not `.ok()?`. A string that passed the
+ // digits-only check above and still fails to parse can only have
+ // failed by being too large — so treating it as "as large as
+ // possible" clamps it, where propagating the error would render it
+ // flush left. That is the last corner where this and
+ // fixtures/indent.mjs disagreed: JavaScript's Number() turns a
+ // twenty-digit run into a float far above the maximum and clamps to
+ // 8, and now so does this.
+ let level = raw
+ .parse::<u32>()
+ .unwrap_or(u32::MAX)
+ .min(MAX_INDENT as u32) as u8;
if level == 0 {
None
} else {
diff --git a/fixtures/indent.test.mjs b/fixtures/indent.test.mjs
index 1510af9..8a53ca7 100644
--- a/fixtures/indent.test.mjs
+++ b/fixtures/indent.test.mjs
@@ -32,6 +32,17 @@ test('zero, null and absent are all the same answer: no indent', () => {
assert.equal(indentClass(''), null)
})
+test('a run of digits too large for any integer type still clamps', () => {
+ // The last corner where this and core/src/fragment.rs disagreed.
+ // Rust parses as u32, which a twenty-digit run overflows; it now
+ // treats an overflow as "too large" and clamps, matching what
+ // Number() does here. Before that, the same document indented at 8 in
+ // the editor and rendered flush left for a reader with no
+ // JavaScript.
+ assert.equal(normaliseIndent('99999999999999999999'), MAX_INDENT)
+ assert.equal(indentClass('99999999999999999999'), 'docs-indent-' + MAX_INDENT)
+})
+
test('a level past the maximum clamps rather than being emitted', () => {
assert.equal(normaliseIndent(99), MAX_INDENT)
assert.equal(indentClass(99), 'docs-indent-' + MAX_INDENT)
diff --git a/fixtures/toolbar.mjs b/fixtures/toolbar.mjs
index c7e9fe6..0f7033c 100644
--- a/fixtures/toolbar.mjs
+++ b/fixtures/toolbar.mjs
@@ -186,7 +186,15 @@ export function createToolbar({ root, schema, getView, onSync }) {
// returned either way — the menu bar reads it, and a template that
// renders a menu without a formatting bar (or a future one that drops
// the bar entirely) must still get working menu commands.
- if (!root) return { plugin: null, commands: buildCommands(schema) }
+ // focusStop is in the early return too, and its absence was a real
+ // bug for one commit: editor-entry.js binds Escape to it and its
+ // comment promises that with no toolbar there is "nowhere to go" and
+ // false comes back — but this branch returned no focusStop at all, so
+ // Escape would have thrown a TypeError inside ProseMirror's keymap.
+ // Unreachable today because show.html always renders the bar, which
+ // is exactly why a comment asserting the guarantee needed the code to
+ // hold it. toolbar-roving.mjs's own early return already did.
+ if (!root) return { plugin: null, commands: buildCommands(schema), focusStop: () => false }
const buttons = Array.from(root.querySelectorAll('[data-docs-command]'))
const selects = Array.from(root.querySelectorAll('[data-docs-select]'))
diff --git a/internal/core/testdata/docs_core.wasm b/internal/core/testdata/docs_core.wasm
index b90b562..98eadac 100755
Binary files a/internal/core/testdata/docs_core.wasm and b/internal/core/testdata/docs_core.wasm differ
diff --git a/internal/docs/static/editor.51ada8c82c1866c8.js b/internal/docs/static/editor.d8d3d5d91b1c09c4.js
similarity index 96%
rename from internal/docs/static/editor.51ada8c82c1866c8.js
rename to internal/docs/static/editor.d8d3d5d91b1c09c4.js
index 37dbfa4..284473c 100644
--- a/internal/docs/static/editor.51ada8c82c1866c8.js
+++ b/internal/docs/static/editor.d8d3d5d91b1c09c4.js
@@ -11,4 +11,4 @@ ${t.toString()}`)},_o=class{constructor(e){this.patterns=[],this.$state=e}if(e,t
`);return{dom:c,text:h,slice:e}}function Ah(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let c=!!e&&(r||s||!t);if(c){if(n.someProp("transformPastedText",h=>{e=h(e,s||r,n)}),s)return l=new b(x.from(n.state.schema.text(e.replace(/\r\n?/g,`
`))),0,0),n.someProp("transformPasted",h=>{l=h(l,n,!0)}),l;let u=n.someProp("clipboardTextParser",h=>h(e,i,r,n));if(u)l=u;else{let h=i.marks(),{schema:d}=n.state,p=Kt.fromSchema(d);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(d.text(m,h)))})}}else n.someProp("transformPastedHTML",u=>{t=u(t,n)}),o=Yy(t),ii&&Gy(o);let a=o&&o.querySelector("[data-pm-slice]"),f=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(f&&f[3])for(let u=+f[3];u>0;u--){let h=o.firstChild;for(;h&&h.nodeType!=1;)h=h.nextSibling;if(!h)break;o=h}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zr.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||f),context:i,ruleFromNode(h){return h.nodeName=="BR"&&!h.nextSibling&&h.parentNode&&!jy.test(h.parentNode.nodeName)?{ignore:!0}:null}})),f)l=Xy(eh(l,+f[1],+f[2]),f[4]);else if(l=b.maxOpen(Ky(l.content,i),!0),l.openStart||l.openEnd){let u=0,h=0;for(let d=l.content.firstChild;u<l.openStart&&!d.type.spec.isolating;u++,d=d.firstChild);for(let d=l.content.lastChild;h<l.openEnd&&!d.type.spec.isolating;h++,d=d.lastChild);l=eh(l,u,h)}return n.someProp("transformPasted",u=>{l=u(l,n,c)}),l}var jy=/^(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 Ky(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&Dh(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Nh(o[o.length-1],s.length));let f=Oh(l,c);o.push(f),i=i.matchType(f.type),s=c}}),o)return x.from(o)}return n}function Oh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,x.from(n));return n}function Dh(n,e,t,r,i){if(i<n.length&&i<e.length&&n[i]==e[i]){let s=Dh(n,e,t,r.lastChild,i+1);if(s)return r.copy(r.content.replaceChild(r.childCount-1,s));if(r.contentMatchAt(r.childCount).matchType(i==n.length-1?t.type:n[i+1]))return r.copy(r.content.append(x.from(Oh(t,n,i+1))))}}function Nh(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,Nh(n.lastChild,e-1)),r=n.contentMatchAt(n.childCount).fillBefore(x.empty,!0);return n.copy(t.append(r))}function tc(n,e,t,r,i,s){let o=e<0?n.firstChild:n.lastChild,l=o.content;return n.childCount>1&&(s=0),i<r-1&&(l=tc(l,e,t,r,i+1,s)),i>=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(x.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function eh(n,e,t){return e<n.openStart&&(n=new b(tc(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new b(tc(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}var Ih={thead:["table"],tbody:["table"],tfoot:["table"],caption:["table"],colgroup:["table"],col:["table","colgroup"],tr:["table","tbody"],td:["table","tbody","tr"],th:["table","tbody","tr"]};function _h(){return document.implementation.createHTMLDocument("title")}var Gr=null;function Hy(n){let e=window.trustedTypes;if(!e)return n;if(!Gr){if(Gr=e.defaultPolicy)try{return Gr.createHTML(n)}catch{}Gr=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})}return Gr.createHTML(n)}function Yy(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=_h(),r=t.body,i=/<([a-z][^>\s]+)/i.exec(n),s;if((s=i&&Ih[i[1].toLowerCase()])&&(n=s.map(o=>"<"+o+">").join("")+n+s.map(o=>"</"+o+">").reverse().join("")),r.innerHTML=Hy(n),s)for(let o=0;o<s.length;o++)r=r.querySelector(s[o])||r;for(let o=0;o<t.styleSheets.length;o++){let l=t.styleSheets[o];for(let c=0;c<l.rules.length;c++){let a=l.rules[c];if(a instanceof CSSStyleRule){let f=r.querySelectorAll(a.selectorText);for(let u=0;u<f.length;u++)f[u].style.cssText+=a.style.cssText}}}return r}function Gy(n){let e=n.querySelectorAll(Q?"span:not([class]):not([style])":"span.Apple-converted-space");for(let t=0;t<e.length;t++){let r=e[t];r.childNodes.length==1&&r.textContent=="\xA0"&&r.parentNode&&r.parentNode.replaceChild(n.ownerDocument.createTextNode(" "),r)}}function Xy(n,e){if(!n.size)return n;let t=n.content.firstChild.type.schema,r;try{r=JSON.parse(e)}catch{return n}let{content:i,openStart:s,openEnd:o}=n;for(let l=r.length-2;l>=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;try{c.checkAttrs(r[l+1])}catch{break}i=x.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var ce={},ae={},Zy={touchstart:!0,touchmove:!0},nc=class{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 Qy(n){for(let e in ce){let t=ce[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{t0(n,r)&&!dc(n,r)&&(n.editable||!(r.type in ae))&&t(n,r)},Zy[e]?{passive:!0}:void 0)}ie&&n.dom.addEventListener("input",()=>null),rc(n)}function it(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function e0(n){n.input.mouseDown&&n.input.mouseDown.done(),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 rc(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>dc(n,r))})}function dc(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function t0(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 n0(n,e){!dc(n,e)&&ce[e.type]&&(n.editable||!(e.type in ae))&&ce[e.type](n,e)}ae.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Bh(n)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(rt&&Q&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),Xn&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,Zt(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Wy(n,t)?t.preventDefault():it(n,"key")};ae.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ae.keypress=(n,e)=>{let t=e;if(Bh(n)||!t.charCode||t.ctrlKey&&!t.altKey||Ae&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof N)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode),s=()=>n.state.tr.insertText(i).scrollIntoView();!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",o=>o(n,r.$from.pos,r.$to.pos,i,s))&&n.dispatch(s()),t.preventDefault()}};function si(n){return{left:n.clientX,top:n.clientY}}function r0(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function pc(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function oi(n,e,t){if(n.focused||n.focus(),n.state.selection.eq(e))return;let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function i0(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&S.isSelectable(r)?(oi(n,new S(t),"pointer"),!0):!1}function s0(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof S&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(S.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(oi(n,S.create(n.state.doc,i),"pointer"),!0):!1}function o0(n,e,t,r,i){return pc(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?s0(n,t):i0(n,t))}function l0(n,e,t,r){return pc(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function c0(n,e,t,r){return pc(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||a0(n,t,r)}function a0(n,e,t){if(t.button!=0)return!1;let r=Rh(n,e,!0),i=n.state.doc;return r?(oi(n,r,"pointer"),r instanceof N&&i.eq(n.state.doc)&&(n.input.mouseDown=new sc(n,r)),!0):!1}function Rh(n,e,t){let r=n.state.doc;if(e==-1)return r.inlineContent?N.create(r,0,r.content.size):null;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)return N.create(r,l+1,l+1+o.content.size);if(t&&S.isSelectable(o))return S.create(r,l)}return null}function mc(n){return Ps(n)}var vh=Ae?"metaKey":"ctrlKey";ce.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=mc(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&r0(t,n.input.lastClick)&&!t[vh]&&n.input.lastClick.button==t.button&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s,button:t.button},n.input.mouseDown&&n.input.mouseDown.done();let o=n.posAtCoords(si(t));o&&(s=="singleClick"?n.input.mouseDown=new ic(n,o,t,!!r):(s=="doubleClick"?l0:c0)(n,o.pos,o.inside,t)?t.preventDefault():it(n,"pointer"))};var Fs=class{constructor(e){this.view=e,this.mightDrag=null,e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this))}up(e){this.done()}move(e){e.buttons==0&&this.done()}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.view.input.mouseDown==this&&(this.view.input.mouseDown=null)}delaySelUpdate(){return!1}},ic=class extends Fs{constructor(e,t,r,i){super(e),this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.startDoc=e.state.doc,this.selectNode=!!r[vh],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let f=e.state.doc.resolve(t.pos);s=f.parent,o=f.depth?f.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c&&c.nodeDOM.nodeType==1?c.nodeDOM:null;let{selection:a}=e.state;r.button==0&&(s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof S&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&De&&!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()),it(e,"pointer")}done(){super.done(),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(()=>{this.view.isDestroyed||st(this.view)})}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(si(e))),this.updateAllowDefault(e),this.allowDefault||!t?it(this.view,"pointer"):o0(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||ie&&this.mightDrag&&!this.mightDrag.node.isAtom||Q&&!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)?(oi(this.view,M.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):it(this.view,"pointer")}move(e){this.updateAllowDefault(e),it(this.view,"pointer"),super.move(e)}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}delaySelUpdate(){return this.allowDefault?(this.delayedSelectionSync=!0,!0):!1}},sc=class extends Fs{constructor(e,t){super(e),this.startSelection=t,this.startDoc=e.state.doc}move(e){if(e.buttons==0||this.view.isDestroyed||!this.view.state.doc.eq(this.startDoc)){this.done();return}e.preventDefault(),it(this.view,"pointer");let t=this.view.posAtCoords(si(e)),r=t&&Rh(this.view,t.inside,!1);if(!r)return;let{doc:i}=this.view.state,s=this.startSelection,[o,l]=r.from<s.from?[s.to,r.from]:[s.from,r.to];oi(this.view,N.create(i,o,l),"pointer")}};ce.touchstart=n=>{n.input.lastTouch=Date.now(),mc(n),it(n,"pointer")};ce.touchmove=n=>{n.input.lastTouch=Date.now(),it(n,"pointer")};ce.contextmenu=n=>mc(n);function Bh(n,e){return n.composing?!0:ie&&Math.abs(Date.now()-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var f0=rt?5e3:-1;ae.compositionstart=ae.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof N&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||Q&&dh&&u0(n)))n.markCursor=n.state.storedMarks||t.marks(),Ps(n,!0),n.markCursor=null;else if(Ps(n,!e.selection.empty),De&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){let l=n.domSelection();l&&l.collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}Vh(n,f0)};function u0(n){let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(!e||e.nodeType!=1||t>=e.childNodes.length)return!1;let r=e.childNodes[t];return r.nodeType==1&&r.contentEditable=="false"}ae.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=Date.now(),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++,Vh(n,20))};function Vh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Ps(n),e))}function Uh(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=Date.now());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function h0(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=ay(e.focusNode,e.focusOffset),r=fy(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc,s=n.domObserver.lastChangedTextNode;if(t==s||r==s)return s;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let o=t.pmViewDesc;if(!(!o||!o.isText(t.nodeValue)))return r}}return t||r}function Ps(n,e=!1){if(!(rt&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Uh(n),e||n.docView&&n.docView.dirty){let t=fc(n),r=n.state.selection;return t&&!t.eq(r)?n.dispatch(n.state.tr.setSelection(t)):(n.markCursor||e)&&!r.$from.node(r.$from.sharedDepth(r.to)).inlineContent?n.dispatch(n.state.tr.deleteSelection()):n.updateState(n.state),!0}return!1}}function d0(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 r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var Qr=xe&&St<15||Xn&&py<604;ce.copy=ae.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Qr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=hc(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):d0(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function p0(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function m0(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?ei(n,r.value,null,i,e):ei(n,r.textContent,r.innerHTML,i,e)},50)}function ei(n,e,t,r,i){let s=Ah(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=p0(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Lh(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," "):""}ae.paste=(n,e)=>{let t=e;if(n.composing&&!rt)return;let r=Qr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&ei(n,Lh(r),r.getData("text/html"),i,t)?t.preventDefault():m0(n,t)};var zs=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},g0=Ae?"altKey":"ctrlKey";function Fh(n,e){let t;return n.someProp("dragCopies",r=>{t=t||r(e)}),t!=null?!t:!e[g0]}ce.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(si(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof S?i.to-1:i.to))){if(r&&r.mightDrag)o=S.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let u=n.docView.nearestDesc(t.target,!0);u&&u.node.type.spec.draggable&&u!=n.docView&&(o=S.create(n.state.doc,u.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:f}=hc(n,l);(!t.dataTransfer.files.length||!Q||hh>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Qr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",Qr||t.dataTransfer.setData("text/plain",a),n.dragging=new zs(f,Fh(n,t),o)};ce.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ae.dragover=ae.dragenter=(n,e)=>e.preventDefault();ae.drop=(n,e)=>{try{y0(n,e,n.dragging)}finally{n.dragging=null}};function y0(n,e,t){if(!e.dataTransfer)return;let r=n.posAtCoords(si(e));if(!r)return;let i=n.state.doc.resolve(r.pos),s=t&&t.slice;s?n.someProp("transformPasted",d=>{s=d(s,n,!1)}):s=Ah(n,Lh(e.dataTransfer),Qr?null:e.dataTransfer.getData("text/html"),!1,i);let o=!!(t&&Fh(n,e));if(n.someProp("handleDrop",d=>d(n,e,s||b.empty,o))){e.preventDefault();return}if(!s)return;e.preventDefault();let l=s?Su(n.state.doc,i.pos,s):i.pos;l==null&&(l=i.pos);let c=n.state.tr;if(o){let{node:d}=t;d?d.replace(c):c.deleteSelection()}let a=c.mapping.map(l),f=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,u=c.doc;if(f?c.replaceRangeWith(a,a,s.content.firstChild):c.replaceRange(a,a,s),c.doc.eq(u))return;let h=c.doc.resolve(a);if(f&&S.isSelectable(s.content.firstChild)&&h.nodeAfter&&h.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new S(h));else{let d=c.mapping.map(l);c.mapping.maps[c.mapping.maps.length-1].forEach((p,m,g,y)=>d=y),c.setSelection(uc(n,h,c.doc.resolve(d)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))}ce.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())&&st(n)},20))};ce.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)};ce.beforeinput=(n,e)=>{if(rt&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,Zt(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in ae)ce[n]=ae[n];function ti(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}var $s=class n{constructor(e,t){this.toDOM=e,this.spec=t||rn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new $e(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&ti(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},nn=class n{constructor(e,t){this.attrs=e,this.spec=t||rn}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new $e(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof n&&ti(this.attrs,e.attrs)&&ti(this.spec,e.spec)}static is(e){return e.type instanceof n}destroy(){}},oc=class n{constructor(e,t){this.attrs=e,this.spec=t||rn}map(e,t,r,i){let s=e.mapResult(t.from+i,1);if(s.deleted)return null;let o=e.mapResult(t.to+i,-1);return o.deleted||o.pos<=s.pos?null:new $e(s.pos-r,o.pos-r,this)}valid(e,t){let{index:r,offset:i}=e.content.findIndex(t.from),s;return i==t.from&&!(s=e.child(r)).isText&&i+s.nodeSize==t.to}eq(e){return this==e||e instanceof n&&ti(this.attrs,e.attrs)&&ti(this.spec,e.spec)}destroy(){}},$e=class n{constructor(e,t,r){this.from=e,this.to=t,this.type=r}copy(e,t){return new n(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,r){return this.type.map(e,this,t,r)}static widget(e,t,r){return new n(e,e,new $s(t,r))}static inline(e,t,r,i){return new n(e,t,new nn(r,i))}static node(e,t,r,i){return new n(e,t,new oc(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof nn}get widget(){return this.type instanceof $s}},Yn=[],rn={},re=class n{constructor(e,t){this.local=e.length?e:Yn,this.children=t.length?t:Yn}static create(e,t){return t.length?Js(t,e,0,rn):ne}find(e,t,r){let i=[];return this.findInner(e??0,t??1e9,i,0,r),i}findInner(e,t,r,i,s){for(let o=0;o<this.local.length;o++){let l=this.local[o];l.from<=t&&l.to>=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;o<this.children.length;o+=3)if(this.children[o]<t&&this.children[o+1]>e){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==ne||e.maps.length==0?this:this.mapInner(e,t,0,0,r||rn)}mapInner(e,t,r,i,s){let o;for(let l=0;l<this.local.length;l++){let c=this.local[l].map(e,r,i);c&&c.type.valid(t,c)?(o||(o=[])).push(c):s.onRemove&&s.onRemove(this.local[l].spec)}return this.children.length?x0(this.children,o||[],e,t,r,i,s):o?new n(o.sort(sn),Yn):ne}add(e,t){return t.length?this==ne?n.create(e,t):this.addInner(e,t,0):this}addInner(e,t,r){let i,s=0;e.forEach((l,c)=>{let a=c+r,f;if(f=zh(t,l,a)){for(i||(i=this.children.slice());s<i.length&&i[s]<c;)s+=3;i[s]==c?i[s+2]=i[s+2].addInner(l,f,a+1):i.splice(s,0,c,c+l.nodeSize,Js(f,l,a+1,rn)),s+=3}});let o=Ph(s?$h(t):t,-r);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||o.splice(l--,1);return new n(o.length?this.local.concat(o).sort(sn):this.local,i||this.children)}remove(e){return e.length==0||this==ne?this:this.removeInner(e,0)}removeInner(e,t){let r=this.children,i=this.local;for(let s=0;s<r.length;s+=3){let o,l=r[s]+t,c=r[s+1]+t;for(let f=0,u;f<e.length;f++)(u=e[f])&&u.from>l&&u.to<c&&(e[f]=null,(o||(o=[])).push(u));if(!o)continue;r==this.children&&(r=this.children.slice());let a=r[s+2].removeInner(o,l+1);a!=ne?r[s+2]=a:(r.splice(s,3),s-=3)}if(i.length){for(let s=0,o;s<e.length;s++)if(o=e[s])for(let l=0;l<i.length;l++)i[l].eq(o,t)&&(i==this.local&&(i=this.local.slice()),i.splice(l--,1))}return r==this.children&&i==this.local?this:i.length||r.length?new n(i,r):ne}forChild(e,t){if(this==ne)return this;if(t.isLeaf)return n.empty;let r,i;for(let l=0;l<this.children.length;l+=3)if(this.children[l]>=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;l<this.local.length;l++){let c=this.local[l];if(c.from<o&&c.to>s&&c.type instanceof nn){let a=Math.max(s,c.from)-s,f=Math.min(o,c.to)-s;a<f&&(i||(i=[])).push(c.copy(a,f))}}if(i){let l=new n(i.sort(sn),Yn);return r?new qs([l,r]):l}return r||ne}eq(e){if(this==e)return!0;if(!(e instanceof n)||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 gc(this.localsInner(e))}localsInner(e){if(this==ne)return Yn;if(e.inlineContent||!this.local.some(nn.is))return this.local;let t=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof nn||t.push(this.local[r]);return t}forEachSet(e){e(this)}};re.empty=new re([],[]);re.removeOverlap=gc;var ne=re.empty,qs=class n{constructor(e){this.members=e}map(e,t){let r=this.members.map(i=>i.map(e,t,rn));return n.from(r)}forChild(e,t){if(t.isLeaf)return re.empty;let r=[];for(let i=0;i<this.members.length;i++){let s=this.members[i].forChild(e,t);s!=ne&&(s instanceof n?r=r.concat(s.members):r.push(s))}return n.from(r)}eq(e){if(!(e instanceof n)||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,r=!0;for(let i=0;i<this.members.length;i++){let s=this.members[i].localsInner(e);if(s.length)if(!t)t=s;else{r&&(t=t.slice(),r=!1);for(let o=0;o<s.length;o++)t.push(s[o])}}return t?gc(r?t:t.sort(sn)):Yn}static from(e){switch(e.length){case 0:return ne;case 1:return e[0];default:return new n(e.every(t=>t instanceof re)?e:e.reduce((t,r)=>t.concat(r instanceof re?r:r.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function x0(n,e,t,r,i,s,o){let l=n.slice();for(let a=0,f=s;a<t.maps.length;a++){let u=0;t.maps[a].forEach((h,d,p,m)=>{let g=m-p-(d-h);for(let y=0;y<l.length;y+=3){let k=l[y+1];if(k<0||h>k+f-u)continue;let w=l[y]+f-u;d>=w?l[y+1]=h<=w?-2:-1:h>=f&&g&&(l[y]+=g,l[y+1]+=g)}u+=g}),f=t.maps[a].map(f,-1)}let c=!1;for(let a=0;a<l.length;a+=3)if(l[a+1]<0){if(l[a+1]==-2){c=!0,l[a+1]=-1;continue}let f=t.map(n[a]+s),u=f-i;if(u<0||u>=r.content.size){c=!0;continue}let h=t.map(n[a+1]+s,-1),d=h-i,{index:p,offset:m}=r.content.findIndex(u),g=r.maybeChild(p);if(g&&m==u&&m+g.nodeSize==d){let y=l[a+2].mapInner(t,g,f+1,n[a]+s+1,o);y!=ne?(l[a]=u,l[a+1]=d,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=b0(l,n,e,t,i,s,o),f=Js(a,r,0,o);e=f.local;for(let u=0;u<l.length;u+=3)l[u+1]<0&&(l.splice(u,3),u-=3);for(let u=0,h=0;u<f.children.length;u+=3){let d=f.children[u];for(;h<l.length&&l[h]<d;)h+=3;l.splice(h,0,f.children[u],f.children[u+1],f.children[u+2])}}return new re(e.sort(sn),l)}function Ph(n,e){if(!e||!n.length)return n;let t=[];for(let r=0;r<n.length;r++){let i=n[r];t.push(new $e(i.from+e,i.to+e,i.type))}return t}function b0(n,e,t,r,i,s,o){function l(c,a){for(let f=0;f<c.local.length;f++){let u=c.local[f].map(r,i,a);u?t.push(u):o.onRemove&&o.onRemove(c.local[f].spec)}for(let f=0;f<c.children.length;f+=3)l(c.children[f+2],c.children[f]+a+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 zh(n,e,t){if(e.isLeaf)return null;let r=t+e.nodeSize,i=null;for(let s=0,o;s<n.length;s++)(o=n[s])&&o.from>t&&o.to<r&&((i||(i=[])).push(o),n[s]=null);return i}function $h(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function Js(n,e,t,r){let i=[],s=!1;e.forEach((l,c)=>{let a=zh(n,l,c+t);if(a){s=!0;let f=Js(a,l,t+c+1,r);f!=ne&&i.push(c,c+l.nodeSize,f)}});let o=Ph(s?$h(n):n,-t).sort(sn);for(let l=0;l<o.length;l++)o[l].type.valid(e,o[l])||(r.onRemove&&r.onRemove(o[l].spec),o.splice(l--,1));return o.length||i.length?new re(o,i):ne}function sn(n,e){return n.from-e.from||n.to-e.to}function gc(n){let e=n;for(let t=0;t<e.length-1;t++){let r=e[t];if(r.from!=r.to)for(let i=t+1;i<e.length;i++){let s=e[i];if(s.from==r.from){s.to!=r.to&&(e==n&&(e=n.slice()),e[i]=s.copy(s.from,r.to),th(e,i+1,s.copy(r.to,s.to)));continue}else{s.from<r.to&&(e==n&&(e=n.slice()),e[t]=r.copy(r.from,s.from),th(e,i,r.copy(s.from,r.to)));break}}}return e}function th(n,e,t){for(;e<n.length&&sn(t,n[e])>0;)e++;n.splice(e,0,t)}function zl(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=ne&&e.push(r)}),n.cursorWrapper&&e.push(re.create(n.state.doc,[n.cursorWrapper.deco])),qs.from(e)}var w0={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},k0=xe&&St<=11,lc=class{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}},cc=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new lc,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.lastChangedTextNode=null,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;i<r.length;i++)this.queue.push(r[i]);xe&&St<=11&&r.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():ie&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),k0&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.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,w0)),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(Hu(this.view)){if(this.suppressingSelectionUpdates)return st(this.view);if(xe&&St<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&on(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,r;for(let s=e.focusNode;s;s=Gn(s))t.add(s);for(let s=e.anchorNode;s;s=Gn(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))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 r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Hu(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let f=0;f<t.length;f++){let u=this.registerMutation(t[f],c);u&&(s=s<0?u.from:Math.min(u.from,s),o=o<0?u.to:Math.max(u.to,o),u.typeOver&&(l=!0))}if(c.some(f=>f.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||Q&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(f=>f.type=="childList"&&f.removedNodes.length))){for(let f of c)if(f.nodeName=="BR"&&f.parentNode){let u=f.nextSibling;for(;u&&u.nodeType==1;){if(u.contentEditable=="false"){f.parentNode.removeChild(f);break}u=u.firstChild}}}else if(De&&c.length){let f=c.filter(u=>u.nodeName=="BR");if(f.length==2){let[u,h]=f;u.parentNode&&u.parentNode.parentNode==h.parentNode?h.remove():u.remove()}else{let{focusNode:u}=this.currentSelection;for(let h of f){let d=h.parentNode;d&&d.nodeName=="LI"&&(!u||T0(e,u)!=d)&&h.remove()}}}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)<Date.now()-300&&Ws(r)&&(a=fc(e))&&a.eq(M.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,st(e),this.currentSelection.set(r),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,o),S0(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,E0(e,c)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||st(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let f=0;f<e.addedNodes.length;f++){let u=e.addedNodes[f];t.push(u),u.nodeType==3&&(this.lastChangedTextNode=u)}if(r.contentDOM&&r.contentDOM!=r.dom&&!r.contentDOM.contains(e.target))return{from:r.posBefore,to:r.posAfter};let i=e.previousSibling,s=e.nextSibling;if(xe&&St<=11&&e.addedNodes.length)for(let f=0;f<e.addedNodes.length;f++){let{previousSibling:u,nextSibling:h}=e.addedNodes[f];(!u||Array.prototype.indexOf.call(e.addedNodes,u)<0)&&(i=u),(!h||Array.prototype.indexOf.call(e.addedNodes,h)<0)&&(s=h)}let o=i&&i.parentNode==e.target?Z(i)+1:0,l=r.localPosFromDOM(e.target,o,-1),c=s&&s.parentNode==e.target?Z(s):e.target.childNodes.length,a=r.localPosFromDOM(e.target,c,1);return{from:l,to:a}}else return e.type=="attributes"?{from:r.posAtStart-r.border,to:r.posAtEnd+r.border}:(this.lastChangedTextNode=e.target,{from:r.posAtStart,to:r.posAtEnd,typeOver:e.target.nodeValue==e.oldValue})}},nh=new WeakMap,rh=!1;function S0(n){if(!nh.has(n)&&(nh.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=De,rh)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."),rh=!0}}function ih(n,e){let t=e.startContainer,r=e.startOffset,i=e.endContainer,s=e.endOffset,o=n.domAtPos(n.state.selection.anchor);return on(o.node,o.offset,i,s)&&([t,r,i,s]=[i,s,t,r]),{anchorNode:t,anchorOffset:r,focusNode:i,focusOffset:s}}function C0(n,e){if(e.getComposedRanges){let i=e.getComposedRanges(n.root)[0];if(i)return ih(n,i)}let t;function r(i){i.preventDefault(),i.stopImmediatePropagation(),t=i.getTargetRanges()[0]}return n.dom.addEventListener("beforeinput",r,!0),document.execCommand("indent"),n.dom.removeEventListener("beforeinput",r,!0),t?ih(n,t):null}function T0(n,e){for(let t=e.parentNode;t&&t!=n.dom;t=t.parentNode){let r=n.docView.nearestDesc(t,!0);if(r&&r.node.isBlock)return t}return null}function E0(n,e){var t;let{focusNode:r,focusOffset:i}=n.domSelectionRange();for(let s of e)if(((t=s.parentNode)===null||t===void 0?void 0:t.nodeName)=="TR"){let o=s.nextSibling;for(;o&&o.nodeName!="TD"&&o.nodeName!="TH";)o=o.nextSibling;if(o){let l=o;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),r==s&&n.domSelection().collapse(s,i)}else s.parentNode.removeChild(s)}}function M0(n,e,t,r){let{node:i,fromOffset:s,toOffset:o,from:l,to:c}=n.docView.parseRange(e,t),a=n.domSelectionRange(),f,u=a.anchorNode;if(u&&n.dom.contains(u.nodeType==1?u:u.parentNode)&&(f=[{node:u,offset:a.anchorOffset}],Ws(a)||f.push({node:a.focusNode,offset:a.focusOffset})),Q&&n.input.lastKeyCode===8)for(let y=o;y>s;y--){let k=i.childNodes[y-1],w=k.pmViewDesc;if(k.nodeName=="BR"&&!w){o=y;break}if(!w||w.size)break}let h=n.state.doc,d=n.someProp("domParser")||zr.fromSchema(n.state.schema),p=h.resolve(l),m=null,g=d.parse(i,{topNode:p.parent,topMatch:p.parent.contentMatchAt(p.index()),topOpen:!0,from:s,to:o,preserveWhitespace:p.parent.type.whitespace=="pre"?"full":!0,findPositions:f,ruleFromNode:A0(r),context:p});if(f&&f[0].pos!=null){let y=f[0].pos,k=f[1]&&f[1].pos;k==null&&(k=y),m={anchor:y+l,head:k+l}}return{doc:g,sel:m,from:l,to:c}}var A0=n=>e=>{let t=e.pmViewDesc;if(t)return t.parseRule(n);if(e.nodeName=="BR"&&e.parentNode){if(ie&&/^(ul|ol)$/i.test(e.parentNode.nodeName)){let r=document.createElement("div");return r.appendChild(document.createElement("li")),{skip:r}}else if(e.parentNode.lastChild==e||ie&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName=="IMG"&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null},O0=/^(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 D0(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let T=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,B=fc(n,T);if(B&&!n.state.selection.eq(B)){if(Q&&rt&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",mi=>mi(n,Zt(13,"Enter"))))return;let J=n.state.tr.setSelection(B);T=="pointer"?J.setMeta("pointer",!0):T=="key"&&J.scrollIntoView(),s&&J.setMeta("composition",s),n.dispatch(J)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=M0(n,e,t,i),f=n.state.doc,u=f.slice(a.from,a.to),h,d;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(h=n.state.selection.to,d="end"):(h=n.state.selection.from,d="start"),n.input.lastKeyCode=null;let p=_0(u.content,a.doc.content,a.from,h,d);if(p&&n.input.domChangeCount++,(Xn&&n.input.lastIOSEnter>Date.now()-225||rt)&&i.some(T=>T.nodeType==1&&!O0.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,Zt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof N&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let T=sh(n,n.state.doc,a.sel);if(T&&!T.eq(n.state.selection)){let B=n.state.tr.setSelection(T);s&&B.setMeta("composition",s),n.dispatch(B)}}return}n.state.selection.from<n.state.selection.to&&p.start==p.endB&&n.state.selection instanceof N&&(p.start>n.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA<n.state.selection.to&&p.endA>=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),xe&&St<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),y=f.resolve(p.start),k=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA;if((Xn&&n.input.lastIOSEnter>Date.now()-225&&(!k||i.some(T=>T.nodeName=="DIV"||T.nodeName=="P"))||!k&&m.pos<a.doc.content.size&&(!m.sameParent(g)||!m.parent.inlineContent)&&m.pos<g.pos&&!/\S/.test(a.doc.textBetween(m.pos,g.pos,"","")))&&n.someProp("handleKeyDown",T=>T(n,Zt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&I0(f,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,Zt(8,"Backspace")))){rt&&Q&&n.domObserver.suppressSelectionUpdates();return}Q&&p.endB==p.start&&(n.input.lastChromeDelete=Date.now()),rt&&!k&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(T){return T(n,Zt(13,"Enter"))})},20));let w=p.start,be=p.endA,Be=T=>{let B=T||n.state.tr.replace(w,be,a.doc.slice(p.start-a.from,p.endB-a.from));if(a.sel){let J=sh(n,B.doc,a.sel);J&&!(Q&&n.composing&&J.empty&&(p.start!=p.endB||n.input.lastChromeDelete<Date.now()-100)&&(J.head==w||J.head==B.mapping.map(be)-1)||xe&&J.empty&&J.head==w)&&B.setSelection(J)}return s&&B.setMeta("composition",s),B.scrollIntoView()},At;if(k)if(m.pos==g.pos){xe&&St<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>st(n),20));let T=Be(n.state.tr.delete(w,be)),B=f.resolve(p.start).marksAcross(f.resolve(p.endA));B&&T.ensureMarks(B),n.dispatch(T)}else if(p.endA==p.endB&&(At=N0(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start())))){let T=Be(n.state.tr);At.type=="add"?T.addMark(w,be,At.mark):T.removeMark(w,be,At.mark),n.dispatch(T)}else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let T=m.parent.textBetween(m.parentOffset,g.parentOffset),B=()=>Be(n.state.tr.insertText(T,w,be));n.someProp("handleTextInput",J=>J(n,w,be,T,B))||n.dispatch(B())}else n.dispatch(Be());else n.dispatch(Be())}function sh(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:uc(n,e.resolve(t.anchor),e.resolve(t.head))}function N0(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let f=0;f<r.length;f++)i=r[f].removeFromSet(i);for(let f=0;f<t.length;f++)s=t[f].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],o="add",c=f=>f.mark(l.addToSet(f.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=f=>f.mark(l.removeFromSet(f.marks));else return null;let a=[];for(let f=0;f<e.childCount;f++)a.push(c(e.child(f)));if(x.from(a).eq(n))return{mark:l,type:o}}function I0(n,e,t,r,i){if(t-e<=i.pos-r.pos||$l(r,!0,!1)<i.pos)return!1;let s=n.resolve(e);if(!r.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 o=n.resolve($l(s,!0,!0));return!o.parent.isTextblock||o.pos>t||$l(o,!0,!1)<t?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function $l(n,e,t){let r=n.depth,i=e?n.end():n.pos;for(;r>0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function _0(n,e,t,r,i){let s=n.findDiffStart(e,t),o=t+n.size,l=t+e.size;if(s==null)return null;let{a:c,b:a}=n.findDiffEnd(e,o,l);if(i=="end"){let f=Math.max(0,s-Math.min(c,a));r-=c+f-s}if(c<s&&o<l){let f=r<=s&&r>=c?s-r:0;s-=f,a=s+(a-c),c=s}else if(a<s){let f=r<=s&&r>=a?s-r:0;s-=f,c=s+(c-a),a=s}return{start:s,endA:c,endB:a}}var ni=class{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 nc,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(fh),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=ch(this),lh(this),this.nodeViews=ah(this),this.docView=$u(this.state.doc,oh(this),zl(this),this.dom,this),this.domObserver=new cc(this,(r,i,s,o)=>D0(this,r,i,s,o)),this.domObserver.start(),Qy(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&&rc(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(fh),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Uh(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let d=ah(this);v0(d,this.nodeViews)&&(this.nodeViews=d,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&rc(this),this.editable=ch(this),lh(this);let c=zl(this),a=oh(this),f=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",u=s||!this.docView.matchesNode(e.doc,a,c);(u||!e.selection.eq(i.selection))&&(o=!0);let h=f=="preserve"&&o&&this.dom.style.overflowAnchor==null&&yy(this);if(o){this.domObserver.stop();let d=u&&(xe||Q)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&R0(i.selection,e.selection);if(u){let m=Q?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=h0(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=$u(e.doc,a,c,this.dom,this)),m&&(!this.trackWrites||!this.dom.contains(this.trackWrites))&&(d=!0)}let p=this.input.mouseDown;d||!(p&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Ly(this)&&p.delaySelUpdate())?st(this,d):(Th(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),f=="reset"?this.dom.scrollTop=0:f=="to selection"?this.scrollToSelection():h&&xy(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 S){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Uu(this,t.getBoundingClientRect(),e)}else Uu(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 r=this.directPlugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}for(let t=0;t<this.state.plugins.length;t++){let r=this.state.plugins[t];r.spec.view&&this.pluginViews.push(r.spec.view(this))}}else for(let t=0;t<this.pluginViews.length;t++){let r=this.pluginViews[t];r.update&&r.update(this,e)}}updateDraggedNode(e,t){let r=e.node,i=-1;if(r.from<this.state.doc.content.size&&this.state.doc.nodeAt(r.from)==r.node)i=r.from;else{let s=r.from+(this.state.doc.content.size-t.doc.content.size);(s>0&&s<this.state.doc.content.size&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new zs(e.slice,e.move,i<0?void 0:S.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;o<this.directPlugins.length;o++){let l=this.directPlugins[o].props[e];if(l!=null&&(i=t?t(l):l))return i}let s=this.state.plugins;if(s)for(let o=0;o<s.length;o++){let l=s[o].props[e];if(l!=null&&(i=t?t(l):l))return i}}hasFocus(){if(xe){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&&by(this.dom),st(this),this.domObserver.start()}get root(){let e=this._root;if(e==null){for(let t=this.dom.parentNode;t;t=t.parentNode)if(t.nodeType==9||t.nodeType==11&&t.host)return t.getSelection||(Object.getPrototypeOf(t).getSelection=()=>t.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return Ty(this,e)}coordsAtPos(e,t=1){return xh(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,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return Dy(this,t||this.state,e)}pasteHTML(e,t){return ei(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return ei(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return hc(this,e)}destroy(){this.docView&&(e0(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],zl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,ly())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return n0(this,e)}domSelectionRange(){let e=this.domSelection();return e?ie&&this.root.nodeType===11&&hy(this.dom.ownerDocument)==this.dom&&C0(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};ni.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function oh(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 r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[$e.node(0,n.state.doc.content.size,e)]}function lh(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:$e.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function ch(n){return!n.someProp("editable",e=>e(n.state)===!1)}function R0(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 ah(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function v0(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function fh(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")}var B0=["p",0],V0=["blockquote",0],U0=["hr"],L0=["pre",["code",0]],F0=["br"],P0={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return B0}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return V0}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return U0}},heading:{attrs:{level:{default:1,validate:"number"}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return L0}},text:{group:"inline"},image:{inline:!0,attrs:{src:{validate:"string"},alt:{default:null,validate:"string|null"},title:{default:null,validate:"string|null"}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return F0}}},z0=["em",0],$0=["strong",0],q0=["code",0],J0={link:{attrs:{href:{validate:"string"},title:{default:null,validate:"string|null"}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return z0}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return $0}},code:{code:!0,parseDOM:[{tag:"code"}],toDOM(){return q0}}},Zn=new zn({nodes:P0,marks:J0});var W0=["ol",0],j0=["ul",0],K0=["li",0],H0={attrs:{order:{default:1,validate:"number"}},parseDOM:[{tag:"ol",getAttrs(n){return{order:n.hasAttribute("start")?+n.getAttribute("start"):1}}}],toDOM(n){return n.attrs.order==1?W0:["ol",{start:n.attrs.order},0]}},Y0={parseDOM:[{tag:"ul"}],toDOM(){return j0}},G0={parseDOM:[{tag:"li"}],toDOM(){return K0},defining:!0};function yc(n,e){let t={};for(let r in n)t[r]=n[r];for(let r in e)t[r]=e[r];return t}function qh(n,e,t){return n.append({ordered_list:yc(H0,{content:"list_item+",group:t}),bullet_list:yc(Y0,{content:"list_item+",group:t}),list_item:yc(G0,{content:e})})}function Jh(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s);if(!o)return!1;let l=r?t.tr:null;return X0(l,o,n,e)?(r&&r(l.scrollIntoView()),!0):!1}}function X0(n,e,t,r=null){let i=!1,s=e,o=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=o.resolve(e.start-2);s=new Wt(c,c,e.depth),e.endIndex<e.parent.childCount&&(e=new Wt(e.$from,o.resolve(e.$to.end(e.depth)),e.depth)),i=!0}let l=Jn(s,t,r,e);return l?(n&&Z0(n,e,l,i,t),!0):!1}function Z0(n,e,t,r,i){let s=x.empty;for(let f=t.length-1;f>=0;f--)s=x.from(t[f].type.create(t[f].attrs,s));n.step(new H(e.start-(r?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let f=0;f<t.length;f++)t[f].type==i&&(o=f+1);let l=t.length-o,c=e.start+t.length-(r?2:0),a=e.parent;for(let f=e.startIndex,u=e.endIndex,h=!0;f<u;f++,h=!1)!h&&xt(n.doc,c,l)&&(n.split(c,l),c+=2*l),c+=a.child(f).nodeSize;return n}function Wh(n,e){return function(t,r){let{$from:i,$to:s,node:o}=t.selection;if(o&&o.isBlock||i.depth<2||!i.sameParent(s))return!1;let l=i.node(-1);if(l.type!=n)return!1;if(i.parent.content.size==0&&i.node(-1).childCount==i.indexAfter(-1)){if(i.depth==3||i.node(-3).type!=n||i.index(-2)!=i.node(-2).childCount-1)return!1;if(r){let u=x.empty,h=i.index(-1)?1:i.index(-2)?2:3;for(let y=i.depth-h;y>=i.depth-3;y--)u=x.from(i.node(y).copy(u));let d=i.indexAfter(-1)<i.node(-2).childCount?1:i.indexAfter(-2)<i.node(-3).childCount?2:3;u=u.append(x.from(n.createAndFill()));let p=i.before(i.depth-(h-1)),m=t.tr.replace(p,i.after(-d),new b(u,4-h,0)),g=-1;m.doc.nodesBetween(p,m.doc.content.size,(y,k)=>{if(g>-1)return!1;y.isTextblock&&y.content.size==0&&(g=k+1)}),g>-1&&m.setSelection(M.near(m.doc.resolve(g))),r(m.scrollIntoView())}return!0}let c=s.pos==i.end()?l.contentMatchAt(0).defaultType:null,a=t.tr.delete(i.pos,s.pos),f=c?[e?{type:n,attrs:e}:null,{type:c}]:void 0;return xt(a.doc,i.pos,2,f)?(r&&r(a.split(i.pos,2,f).scrollIntoView()),!0):!1}}function li(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,o=>o.childCount>0&&o.firstChild.type==n);return s?t?r.node(s.depth-1).type==n?Q0(e,t,n,s):ex(e,t,s):!0:!1}}function Q0(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);s<o&&(i.step(new H(s-1,o,s,o,new b(x.from(t.create(null,r.parent.copy())),1,0),1,!0)),r=new Wt(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let l=Yt(r);if(l==null)return!1;i.lift(r,l);let c=i.doc.resolve(i.mapping.map(s,-1)-1);return Gt(i.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&i.join(c.pos),e(i.scrollIntoView()),!0}function ex(n,e,t){let r=n.tr,i=t.parent;for(let d=t.end,p=t.endIndex-1,m=t.startIndex;p>m;p--)d-=i.child(p).nodeSize,r.delete(d-1,d+1);let s=r.doc.resolve(t.start),o=s.nodeAfter;if(r.mapping.map(t.end)!=t.start+s.nodeAfter.nodeSize)return!1;let l=t.startIndex==0,c=t.endIndex==i.childCount,a=s.node(-1),f=s.index(-1);if(!a.canReplace(f+(l?0:1),f+1,o.content.append(c?x.empty:x.from(i))))return!1;let u=s.pos,h=u+o.nodeSize;return r.step(new H(u-(l?1:0),h+(c?1:0),u+1,h-1,new b((l?x.empty:x.from(i.copy(x.empty))).append(c?x.empty:x.from(i.copy(x.empty))),l?0:1,c?0:1),l?0:1)),e(r.scrollIntoView()),!0}function js(n){return function(e,t){let{$from:r,$to:i}=e.selection,s=r.blockRange(i,a=>a.childCount>0&&a.firstChild.type==n);if(!s)return!1;let o=s.startIndex;if(o==0)return!1;let l=s.parent,c=l.child(o-1);if(c.type!=n)return!1;if(t){let a=c.lastChild&&c.lastChild.type==l.type,f=x.from(a?n.create():null),u=new b(x.from(n.create(null,x.from(l.type.create(null,f)))),a?3:1,0),h=s.start,d=s.end;t(e.tr.step(new H(h-(a?3:1),d,h,d,u,1,!0)).scrollIntoView())}return!0}}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:"'"},Hs={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},tx=typeof navigator<"u"&&/Mac/.test(navigator.platform),nx=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(z=0;z<10;z++)ot[48+z]=ot[96+z]=String(z);var z;for(z=1;z<=24;z++)ot[z+111]="F"+z;var z;for(z=65;z<=90;z++)ot[z]=String.fromCharCode(z+32),Hs[z]=String.fromCharCode(z);var z;for(Ks in ot)Hs.hasOwnProperty(Ks)||(Hs[Ks]=ot[Ks]);var Ks;function jh(n){var e=tx&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||nx&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Hs: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}var rx=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),ix=typeof navigator<"u"&&/Win/.test(navigator.platform);function sx(n){let e=n.split(/-(?!$)/),t=e[e.length-1];t=="Space"&&(t=" ");let r,i,s,o;for(let l=0;l<e.length-1;l++){let c=e[l];if(/^(cmd|meta|m)$/i.test(c))o=!0;else if(/^a(lt)?$/i.test(c))r=!0;else if(/^(c|ctrl|control)$/i.test(c))i=!0;else if(/^s(hift)?$/i.test(c))s=!0;else if(/^mod$/i.test(c))rx?o=!0:i=!0;else throw new Error("Unrecognized modifier name: "+c)}return r&&(t="Alt-"+t),i&&(t="Ctrl-"+t),o&&(t="Meta-"+t),s&&(t="Shift-"+t),t}function ox(n){let e=Object.create(null);for(let t in n)e[sx(t)]=n[t];return e}function xc(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 bc(n){return new ye({props:{handleKeyDown:lx(n)}})}function lx(n){let e=ox(n);return function(t,r){let i=jh(r),s,o=e[xc(i,r)];if(o&&o(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(r.shiftKey){let l=e[xc(i,r,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((r.altKey||r.metaKey||r.ctrlKey)&&!(ix&&r.ctrlKey&&r.altKey)&&(s=ot[r.keyCode])&&s!=i){let l=e[xc(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var Hh=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function cx(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var ax=(n,e,t)=>{let r=cx(n,t);if(!r)return!1;let i=Yh(r);if(!i){let o=r.blockRange(),l=o&&Yt(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Zh(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Qn(s,"end")||S.isSelectable(s)))for(let o=r.depth;;o--){let l=Ns(n.doc,r.before(o),r.after(o),b.empty);if(l&&l.slice.size<l.to-l.from){if(e){let c=n.tr.step(l);c.setSelection(Qn(s,"end")?M.findFrom(c.doc.resolve(c.mapping.map(i.pos,-1)),-1):S.create(c.doc,i.pos-s.nodeSize)),e(c.scrollIntoView())}return!0}if(o==1||r.node(o-1).childCount>1)break}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos-s.nodeSize,i.pos).scrollIntoView()),!0):!1};function Qn(n,e,t=!1){for(let r=n;r;r=e=="start"?r.firstChild:r.lastChild){if(r.isTextblock)return!0;if(t&&r.childCount!=1)return!1}return!1}var fx=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=Yh(r)}let o=s&&s.nodeBefore;return!o||!S.isSelectable(o)?!1:(e&&e(n.tr.setSelection(S.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function Yh(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 ux(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}var hx=(n,e,t)=>{let r=ux(n,t);if(!r)return!1;let i=Gh(r);if(!i)return!1;let s=i.nodeAfter;if(Zh(n,i,e,1))return!0;if(r.parent.content.size==0&&(Qn(s,"start")||S.isSelectable(s))){let o=Ns(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size<o.to-o.from){if(e){let l=n.tr.step(o);l.setSelection(Qn(s,"start")?M.findFrom(l.doc.resolve(l.mapping.map(i.pos)),1):S.create(l.doc,l.mapping.map(i.pos))),e(l.scrollIntoView())}return!0}}return s.isAtom&&i.depth==r.depth-1?(e&&e(n.tr.delete(i.pos,i.pos+s.nodeSize).scrollIntoView()),!0):!1},dx=(n,e,t)=>{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset<r.parent.content.size)return!1;s=Gh(r)}let o=s&&s.nodeAfter;return!o||!S.isSelectable(o)?!1:(e&&e(n.tr.setSelection(S.create(n.doc,s.pos)).scrollIntoView()),!0)};function Gh(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}var Xh=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&Yt(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},px=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(`
-`).scrollIntoView()),!0)};function kc(n){for(let e=0;e<n.edgeCount;e++){let{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}var mx=(n,e)=>{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=kc(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(M.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},gx=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof le||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=kc(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,l=n.tr.insert(o,s.createAndFill());l.setSelection(N.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},yx=(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(xt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Yt(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function xx(n){return(e,t)=>{if(e.selection instanceof S&&e.selection.node.isBlock){let{$from:d}=e.selection;return!d.parentOffset||!xt(e.doc,d.pos)?!1:(t&&t(e.tr.split(d.pos).scrollIntoView()),!0)}if(!e.selection.$from.depth)return!1;let r=e.tr;!e.selection.empty&&(e.selection instanceof N||e.selection instanceof le)&&r.deleteSelection();let{$from:i}=r.selection,s=r.steps.length,o=[],l,c,a=!1,f=!1;for(let d=i.depth;;d--)if(i.node(d).isBlock){a=i.end(d)==i.pos+(i.depth-d),f=i.start(d)==i.pos-(i.depth-d),c=kc(i.node(d-1).contentMatchAt(i.indexAfter(d-1)));let m=n&&n(i.parent,a,i);o.unshift(m||(a&&c?{type:c}:null)),l=d;break}else{if(d==1)return!1;o.unshift(null)}let u=i.pos,h=xt(r.doc,u,o.length,o);if(h||(o[0]=c?{type:c}:null,h=xt(r.doc,u,o.length,o)),!h)return!1;if(r.split(u,o.length,o),!a&&f&&i.node(l).type!=c){let d=r.mapping.slice(s),p=d.map(i.before(l)),m=r.doc.resolve(p);c&&i.node(l-1).canReplaceWith(m.index(),m.index()+1,c)&&r.setNodeMarkup(d.map(i.before(l)),c)}return t&&t(r.scrollIntoView()),!0}}var bx=xx();var Sc=(n,e)=>(e&&e(n.tr.setSelection(new le(n.doc))),!0);function wx(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||Gt(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Zh(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&wx(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let d=e.pos+s.nodeSize,p=x.empty;for(let y=o.length-1;y>=0;y--)p=x.from(o[y].create(null,p));p=x.from(i.copy(p));let m=n.tr.step(new H(e.pos-1,d,e.pos,d,new b(p,1,0),o.length,!0)),g=m.doc.resolve(d+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Gt(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let f=s.type.spec.isolating||r>0&&c?null:M.findFrom(e,1),u=f&&f.$from.blockRange(f.$to),h=u&&Yt(u);if(h!=null&&h>=e.depth)return t&&t(n.tr.lift(u,h).scrollIntoView()),!0;if(a&&Qn(s,"start",!0)&&Qn(i,"end")){let d=i,p=[];for(;p.push(d),!d.isTextblock;)d=d.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(d.canReplace(d.childCount,d.childCount,m.content)){if(t){let y=x.empty;for(let w=p.length-1;w>=0;w--)y=x.from(p[w].copy(y));let k=n.tr.step(new H(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,p.length,0),0,!0));t(k.scrollIntoView())}return!0}}return!1}function Qh(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(N.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var kx=Qh(-1),Sx=Qh(1);function ed(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Jn(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Cc(n,e=null){return function(t,r){let i=!1;for(let s=0;s<t.selection.ranges.length&&!i;s++){let{$from:{pos:o},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(o,l,(c,a)=>{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let f=t.doc.resolve(a),u=f.index();i=f.parent.canReplaceWith(u,u+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o<t.selection.ranges.length;o++){let{$from:{pos:l},$to:{pos:c}}=t.selection.ranges[o];s.setBlockType(l,c,n,e)}r(s.scrollIntoView())}return!0}}function Cx(n,e,t,r){for(let i=0;i<e.length;i++){let{$from:s,$to:o}=e[i],l=s.depth==0?n.inlineContent&&n.type.allowsMarkType(t):!1;if(n.nodesBetween(s.pos,o.pos,(c,a)=>{if(l||!r&&c.isAtom&&c.isInline&&a>=s.pos&&a+c.nodeSize<=o.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function Tx(n){let e=[];for(let t=0;t<n.length;t++){let{$from:r,$to:i}=n[t];r.doc.nodesBetween(r.pos,i.pos,(s,o)=>{if(s.isAtom&&s.content.size&&s.isInline&&o>=r.pos&&o+s.nodeSize<=i.pos)return o+1>r.pos&&e.push(new jn(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.pos<i.pos&&e.push(new jn(r,i))}return e}function cn(n,e=null,t){let r=(t&&t.removeWhenPresent)!==!1,i=(t&&t.enterInlineAtoms)!==!1,s=!(t&&t.includeWhitespace);return function(o,l){let{empty:c,$cursor:a,ranges:f}=o.selection;if(c&&!a||!Cx(o.doc,f,n,i))return!1;if(l)if(a)n.isInSet(o.storedMarks||a.marks())?l(o.tr.removeStoredMark(n)):l(o.tr.addStoredMark(n.create(e)));else{let u,h=o.tr;i||(f=Tx(f)),r?u=!f.some(d=>o.doc.rangeHasMark(d.$from.pos,d.$to.pos,n)):u=!f.every(d=>{let p=!1;return h.doc.nodesBetween(d.$from.pos,d.$to.pos,(m,g,y)=>{if(p)return!1;p=!n.isInSet(m.marks)&&!!y&&y.type.allowsMarkType(n)&&!(m.isText&&/^\s*$/.test(m.textBetween(Math.max(0,d.$from.pos-g),Math.min(m.nodeSize,d.$to.pos-g))))}),!p});for(let d=0;d<f.length;d++){let{$from:p,$to:m}=f[d];if(!u)h.removeMark(p.pos,m.pos,n);else{let g=p.pos,y=m.pos,k=p.nodeAfter,w=m.nodeBefore,be=s&&k&&k.isText?/^\s*/.exec(k.text)[0].length:0,Be=s&&w&&w.isText?/\s*$/.exec(w.text)[0].length:0;g+be<y&&(g+=be,y-=Be),h.addMark(g,y,n.create(e))}}l(h.scrollIntoView())}return!0}}function qe(...n){return function(e,t,r){for(let i=0;i<n.length;i++)if(n[i](e,t,r))return!0;return!1}}var wc=qe(Hh,ax,fx),Kh=qe(Hh,hx,dx),lt={Enter:qe(px,gx,yx,bx),"Mod-Enter":mx,Backspace:wc,"Mod-Backspace":wc,"Shift-Backspace":wc,Delete:Kh,"Mod-Delete":Kh,"Mod-a":Sc},td={"Ctrl-h":lt.Backspace,"Alt-Backspace":lt["Mod-Backspace"],"Ctrl-d":lt.Delete,"Ctrl-Alt-Backspace":lt["Mod-Delete"],"Alt-Delete":lt["Mod-Delete"],"Alt-d":lt["Mod-Delete"],"Ctrl-a":kx,"Ctrl-e":Sx};for(let n in lt)td[n]=lt[n];var Ex=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,Tc=Ex?td:lt;function Mx(n){let e=Ec(n);return e?"docs-indent-"+e:null}function Ec(n){if(typeof n!="number"&&(typeof n!="string"||!/^\d+$/.test(n)))return 0;let e=Number(n);return!Number.isInteger(e)||e<1?0:Math.min(e,8)}function Ax(n){for(let e of n){if(!e.startsWith("docs-indent-"))continue;let t=Ec(e.slice(12));if(t)return t}return null}function Mc(n,e){let t=n.parseDOM||[{tag:e}];return{...n,attrs:{...n.attrs||{},indent:{default:null}},parseDOM:t.map(r=>({...r,getAttrs:i=>{let s=r.getAttrs?r.getAttrs(i):{};return s===!1?!1:{...s||{},indent:Ax(Array.from(i.classList||[]))}}})),toDOM:r=>{let i=n.toDOM?n.toDOM(r):[e,0],s=Mx(r.attrs.indent);if(!s)return i;let[o,l,...c]=i;if(l&&typeof l=="object"&&!Array.isArray(l)){let a={...l,class:l.class?l.class+" "+s:s};return[o,a,...c]}return[o,{class:s},l,...c]}}}function er(n){return(e,t)=>{let{from:r,to:i}=e.selection,s=!1,o=e.tr;return e.doc.nodesBetween(r,i,(l,c)=>{if(!l.type.isTextblock||!l.type.spec.attrs||!l.type.spec.attrs.indent)return;let a=Ec(l.attrs.indent),f=Math.max(0,Math.min(8,a+n));f!==a&&(s=!0,t&&o.setNodeMarkup(c,null,{...l.attrs,indent:f===0?null:f}))}),s?(t&&t(o),!0):!1}}var Je=class{constructor(e,t,r={}){this.match=e,this.match=e,this.handler=typeof t=="string"?Ox(t):t,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1,this.inCodeMark=r.inCodeMark!==!1}};function Ox(n){return function(e,t,r,i){let s=n;if(t[1]){let o=t[0].lastIndexOf(t[1]);s+=t[0].slice(o+t[1].length),r+=o;let l=r-i;l>0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var Dx=500;function rd({rules:n}){let e=new ye({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return nd(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&nd(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function nd(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-Dx),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a<i.length;a++){let f=i[a];if(!f.inCodeMark&&l.marks().some(p=>p.type.spec.code))continue;if(l.parent.type.spec.code){if(!f.inCode)continue}else if(f.inCode==="only")continue;let u=f.match.exec(c);if(!u||u[0].length<r.length)continue;let h=e-(u[0].length-r.length);if(!f.inCodeMark){let p=!1;if(o.doc.nodesBetween(h,l.pos,m=>{m.isInline&&m.marks.some(g=>g.type.spec.code)&&(p=!0)}),p)continue}let d=f.handler(o,u,h,t);if(d)return f.undoable&&d.setMeta(s,{transform:d,from:e,to:t,text:r}),n.dispatch(d),!0}return!1}var id=(n,e)=>{let t=n.plugins;for(let r=0;r<t.length;r++){let i=t[r],s;if(i.spec.isInputRules&&(s=i.getState(n))){if(e){let o=n.tr,l=s.transform;for(let c=l.steps.length-1;c>=0;c--)o.step(l.steps[c].invert(l.docs[c]));if(s.text){let c=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},ok=new Je(/--$/,"\u2014",{inCodeMark:!1}),lk=new Je(/\.\.\.$/,"\u2026",{inCodeMark:!1}),ck=new Je(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),ak=new Je(/"$/,"\u201D",{inCodeMark:!1}),fk=new Je(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),uk=new Je(/'$/,"\u2019",{inCodeMark:!1});function Ys(n,e,t=null,r){return new Je(n,(i,s,o,l)=>{let c=t instanceof Function?t(s):t,a=i.tr.delete(o,l),f=a.doc.resolve(o),u=f.blockRange(),h=u&&Jn(u,e,c);if(!h)return null;a.wrap(u,h);let d=a.doc.resolve(o-1).nodeBefore;return d&&d.type==e&&Gt(a.doc,o-1)&&(!r||r(s,d))&&a.join(o-1),a})}function sd(n,e,t=null){return new Je(n,(r,i,s,o)=>{let l=r.doc.resolve(s),c=t instanceof Function?t(i):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?r.tr.delete(s,o).setBlockType(s,s,e,c):null})}var Nx=/^\s*([-+*])\s$/,Ix=/^(\d+)\.\s$/,_x=/^\s*>\s$/,Rx=/^(#{1,3})\s$/;function od(n){let e=[],{bullet_list:t,ordered_list:r,blockquote:i,heading:s}=n.nodes;return t&&e.push(Ys(Nx,t)),r&&e.push(Ys(Ix,r)),i&&e.push(Ys(_x,i)),s&&e.push(sd(Rx,s,o=>({level:o[1].length}))),rd({rules:e})}var ct=[12,8,9,10,11,14,18,24,36,48,72],Et=12,Mt=[...ct.filter(n=>n!==Et).map(n=>"size_"+n),"size_sm","size_lg","size_xl"],Gs={size_sm:10,size_lg:14,size_xl:18};function ld(n){let e=Number(n);if(ct.includes(e))return e===Et?null:"size_"+e}function cd(n){for(let e of Mt)if(n.includes(e))return e in Gs?Gs[e]:Number(e.slice(5));return Et}function vx(){if(!ct.includes(Et))throw new Error(`sizes: the default ${Et} is not one of [${ct}]`);if(ct[0]!==Et)throw new Error(`sizes: the control lists ${ct[0]} first but the default is ${Et} \u2014 with no JavaScript the control would name a size the text is not set in`);for(let[t,r]of Object.entries(Gs)){if(!ct.includes(r))throw new Error(`sizes: the legacy mark ${t} maps to ${r}pt, which is not on the ladder [${ct}]`);if(!Mt.includes(t))throw new Error(`sizes: the legacy mark ${t} is not in the group the toolbar clears`)}let n=ct.filter(t=>t!==Et).map(t=>"size_"+t),e=Mt.filter(t=>!(t in Gs));if(n.join()!==e.join())throw new Error(`sizes: the marks [${e}] do not match the offered sizes [${n}]`)}vx();var ci=new bt("docs-pages"),Bx=864,tr="paged",Ac="infinite",Vx="docs-view";function ad(n){document.cookie=`${Vx}=${n}; Path=/; Max-Age=31536000; SameSite=Lax`}function Ux(n){let e=[],t=n.state.doc,r=null;return t.forEach((i,s)=>{let o=n.nodeDOM(s);if(!o||!o.getBoundingClientRect)return;let l=o.getBoundingClientRect();if(l.height!==0){if(r===null){r=l.top;return}l.bottom-r>Bx&&(e.push(s),r=l.top)}}),e}function fd({getMode:n,pageLabel:e}){return new ye({key:ci,state:{init:()=>({positions:[],deco:re.empty}),apply(t,r,i,s){let o=t.getMeta(ci);if(!o)return{positions:r.positions,deco:r.deco.map(t.mapping,t.doc)};let l=o.positions.map((c,a)=>$e.widget(c,()=>Lx(a+2,e),{side:-1,ignoreSelection:!0}));return{positions:o.positions,deco:re.create(s.doc,l)}}},props:{decorations(t){return n()!==tr?re.empty:ci.getState(t).deco}},view(t){let r=0,i="",s=()=>{if(r=0,n()!==tr){i!==""&&(i="",t.dispatch(t.state.tr.setMeta(ci,{positions:[]})));return}let c=Ux(t),a=c.join(",");a!==i&&(i=a,t.dispatch(t.state.tr.setMeta(ci,{positions:c})))},o=()=>{r||(r=requestAnimationFrame(s))},l=typeof ResizeObserver=="function"?new ResizeObserver(o):null;return l&&l.observe(t.dom),o(),{update:o,destroy(){r&&cancelAnimationFrame(r),l&&l.disconnect()}}}})}function Lx(n,e){let t=document.createElement("div");t.setAttribute("docs-page-gap",""),t.setAttribute("contenteditable","false"),t.setAttribute("aria-hidden","true");let r=document.createElement("span");return r.setAttribute("docs-page-number",""),r.textContent=e?e.replace("{n}",String(n)):String(n),t.appendChild(r),t}var ud=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):null;function hd(n){if(!n)return 0;if(ud){let t=0;for(let r of ud.segment(n))r.isWordLike&&t++;return t}let e=n.trim().split(/\s+/);return e.length===1&&e[0]===""?0:e.length}function dd(n){let e=[];return n.descendants(t=>{t.isText?e.push(t.text):t.isBlock&&e.length&&e.push(" ")}),e.join("")}function Fx(n){let e=dd(n.doc),{from:t,to:r,empty:i}=n.selection,s=0;n.doc.forEach(l=>{(l.isTextblock||l.type.name.endsWith("_list")||l.type.name==="blockquote")&&s++});let o=i?null:dd(n.doc.cut(t,r));return{words:hd(e),characters:e.length,charactersNoSpaces:e.replace(/\s/g,"").length,paragraphs:s,selection:o===null?null:{words:hd(o),characters:o.length}}}function pd(n,{getView:e}){if(!n||typeof n.showModal!="function")return null;let t={words:n.querySelector("[docs-count-words]"),characters:n.querySelector("[docs-count-characters]"),charactersNoSpaces:n.querySelector("[docs-count-characters-nospaces]"),paragraphs:n.querySelector("[docs-count-paragraphs]"),selection:n.querySelector("[docs-count-selection]"),selectionWords:n.querySelector("[docs-count-selection-words]")};return()=>{let r=e();if(!r)return!1;let i=Fx(r.state);return t.words&&(t.words.textContent=String(i.words)),t.characters&&(t.characters.textContent=String(i.characters)),t.charactersNoSpaces&&(t.charactersNoSpaces.textContent=String(i.charactersNoSpaces)),t.paragraphs&&(t.paragraphs.textContent=String(i.paragraphs)),t.selection&&(t.selection.hidden=i.selection===null),t.selectionWords&&i.selection&&(t.selectionWords.textContent=String(i.selection.words)),n.showModal(),!0}}function Px(n){let e=[];if(!n)return e;for(let t of n.querySelectorAll("[docs-menu]")){let r=t.querySelector("[docs-menu-title]"),i=r?r.textContent.trim():"";for(let s of t.querySelectorAll("[docs-menu-item]")){let o=s.getAttribute("data-docs-shortcut");if(!o)continue;let l=(s.firstChild&&s.firstChild.textContent?s.firstChild.textContent:s.textContent).trim();e.push({group:i,label:l,keys:o})}}return e}function md(n,{menubar:e,extraRows:t}){if(!n||typeof n.showModal!="function")return null;let r=n.querySelector("[docs-shortcuts-body]");return r?()=>{let i=[...Px(e),...t||[]];r.textContent="";let s=null;for(let o of i){if(o.group&&o.group!==s){s=o.group;let f=document.createElement("h3");f.setAttribute("docs-shortcuts-group",""),f.textContent=s,r.appendChild(f)}let l=document.createElement("div");l.setAttribute("docs-shortcuts-row","");let c=document.createElement("span");c.textContent=o.label;let a=document.createElement("kbd");a.textContent=o.keys,l.append(c,a),r.appendChild(l)}return n.showModal(),!0}:null}var gd=()=>{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var zx=/[\uD800-\uDBFF]/,$x=/[\uDC00-\uDFFF]/,qx=(n,e)=>{let t=0,r=0;for(;t<n.length&&t<e.length&&n[t]===e[t];)t++;for(t>0&&zx.test(n[t-1])&&t--;r+t<n.length&&r+t<e.length&&n[n.length-r-1]===e[e.length-r-1];)r++;return r>0&&$x.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},yd=qx;var L=new bt("y-sync"),We=new bt("y-undo"),Tk=new bt("yjs-cursor");var je=(n,e)=>n>>>e|n<<32-e,Jx=n=>je(n,2)^je(n,13)^je(n,22),Wx=n=>je(n,6)^je(n,11)^je(n,25),jx=n=>je(n,7)^je(n,18)^n>>>3,Kx=n=>je(n,17)^je(n,19)^n>>>10,Hx=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Yx=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Oc=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(Yx),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let u=16;u<64;u++)t[u]=Kx(t[u-2])+t[u-7]+jx(t[u-15])+t[u-16];let r=e[0],i=e[1],s=e[2],o=e[3],l=e[4],c=e[5],a=e[6],f=e[7];for(let u=0,h,d;u<64;u++)h=f+Wx(l)+(l&c^~l&a)+Hx[u]+t[u]>>>0,d=Jx(r)+(r&i^r&s^i&s)>>>0,f=a,a=c,c=l,l=o+h>>>0,o=s,s=i,i=r,r=h+d>>>0;e[0]+=r,e[1]+=i,e[2]+=s,e[3]+=o,e[4]+=l,e[5]+=c,e[6]+=a,e[7]+=f}digest(e){let t=0;for(;t+56<=e.length;){let o=0;for(;o<16&&t+3<e.length;o++)this._W[o]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(t%64!==0){for(this._W.fill(0,o,16);t<e.length;)this._W[o]|=e[t]<<(3-t%4)*8,t++;this._W[o]|=128<<(3-t%4)*8}this._updateHash()}let r=t%64!==0;this._W.fill(0,0,16);let i=0;for(;t<e.length;i++)for(let o=3;o>=0&&t<e.length;o--)this._W[i]|=e[t++]<<o*8;r||(this._W[i-(t%4===0?0:1)]|=128<<(3-t%4)*8),this._W[14]=e.byteLength/536870912,this._W[15]=e.byteLength*8,this._updateHash();let s=new Uint8Array(32);for(let o=0;o<this._H.length;o++)for(let l=0;l<4;l++)s[o*4+l]=this._H[o]>>>(3-l)*8;return s}},xd=n=>new Oc().digest(n);var Xx=n=>{for(let t=6;t<n.length;t++)n[t%6]=n[t%6]^n[t];return n.slice(0,6)},bd=n=>Sa(Xx(xd(Ta(n))));var ai=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!$t(e.ds,n.id),Qx=[{light:"#ecd44433",dark:"#ecd444"}],eb=(n,e,t)=>{if(!n.has(t)){if(n.size<e.length){let r=Ie();n.forEach(i=>r.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,ca(e))}return n.get(t)},_c=(n,{colors:e=Qx,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new Qs(n,s),c=new ye({props:{editable:a=>{let f=L.getState(a);return f.snapshot==null&&f.prevSnapshot==null}},key:L,state:{init:(a,f)=>({type:n,doc:n.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(a,f)=>{let u=a.getMeta(L);if(u!==void 0){f=Object.assign({},f);for(let h in u)f[h]=u[h]}return f.addToHistory=a.getMeta("addToHistory")!==!1,f.isChangeOrigin=u!==void 0&&!!u.isChangeOrigin,f.isUndoRedoOperation=u!==void 0&&!!u.isChangeOrigin&&!!u.isUndoRedoOperation,l.prosemirrorView!==null&&u!==void 0&&(u.snapshot!=null||u.prevSnapshot!=null)&&vo(0,()=>{l.prosemirrorView!=null&&(u.restore==null?l._renderSnapshot(u.snapshot,u.prevSnapshot,f):(l._renderSnapshot(u.snapshot,u.snapshot,f),delete f.restore,delete f.snapshot,delete f.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),f}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let f=c.getState(a.state);if(f.snapshot==null&&f.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,f.addToHistory===!1&&!f.isChangeOrigin){let u=We.getState(a.state),h=u&&u.undoManager;h&&h.stopCapturing()}l.mux(()=>{f.doc.transact(u=>{u.meta.set("addToHistory",f.addToHistory),l._prosemirrorChanged(a.state.doc)},L)})}},destroy:()=>{l.destroy()}})});return c},tb=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null)if(e.type==="all")n.setSelection(new le(n.doc));else if(e.type==="node"){let r=Zs(t.doc,t.type,e.anchor,t.mapping);n.setSelection(S.create(n.doc,r))}else{let r=Zs(t.doc,t.type,e.anchor,t.mapping),i=Zs(t.doc,t.type,e.head,t.mapping);if(r!==null&&i!==null){let s=N.between(n.doc.resolve(r),n.doc.resolve(i));n.setSelection(s)}}},fi=(n,e)=>({type:e.selection.jsonID,anchor:Ic(e.selection.anchor,n.type,n.mapping),head:Ic(e.selection.head,n.type,n.mapping)}),Qs=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=gd(),this.mapping=t,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=fi(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(br&&this._domSelectionInView===null&&(vo(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection();if(e==null||e.anchorNode==null)return!1;let t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let i=t.getBoundingClientRect(),s=Xe.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=ds(fs(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(L,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(r=>Xs(r,this.prosemirrorView.state.schema,this)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(x.from(e),0,0));t.setMeta(L,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(i=>Xs(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(x.from(t),0,0));if(e){let i=Ge(_e(e.anchor,0),r.doc.content.size),s=Ge(_e(e.head,0),r.doc.content.size);r.setSelection(N.create(r.doc,i,s))}this.prosemirrorView.dispatch(r.setMeta(L,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){let i=this.doc,s=this.type;if(e||(e=ps(this.doc)),e instanceof Uint8Array||t instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&$(),i=new Te({gc:!1}),us(i,t),t=ps(i),us(i,e),e=ps(i),s._item===null){let o=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);s=i.getXmlFragment(o)}else{let o=i.store.clients.get(s._item.id.client)??[],l=Ee(o,s._item.id.clock);s=o[l].content.type}this.mapping.clear(),this.mux(()=>{i.transact(o=>{let l=r.permanentUserData;l&&l.dss.forEach(u=>{Ze(o,u,h=>{})});let c=(u,h)=>{let d=u==="added"?l.getUserByClientId(h.client):l.getUserByDeletedId(h);return{user:d,type:u,color:eb(r.colorMapping,r.colors,d)}},a=pl(s,new vn(t.ds,e.sv)).map(u=>!u._item.deleted||ai(u._item,e)||ai(u._item,t)?Xs(u,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,t,c):null).filter(u=>u!==null),f=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(x.from(a),0,0));this.prosemirrorView.dispatch(f.setMeta(L,{isChangeOrigin:!0}))},L)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let r=L.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{let i=(l,c)=>this.mapping.delete(c);Ze(t,t.deleteSet,l=>{if(l.constructor===I){let c=l.content.type;c&&this.mapping.delete(c)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);let s=this.type.toArray().map(l=>Sd(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(x.from(s),0,0));tb(o,this.beforeTransactionSelection,this),o=o.setMeta(L,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Bn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{to(this.doc,this.type,e,this),this.beforeTransactionSelection=fi(this,this.prosemirrorView.state)},L)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},Sd=(n,e,t,r,i,s)=>{let o=t.mapping.get(n);if(o===void 0){if(n instanceof G)return Xs(n,e,t,r,i,s);throw oe()}return o},Xs=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c instanceof G){let a=Sd(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content?.type;a instanceof Qe&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(u=>{a._item.delete(u)}));let f=nb(c,e,t,r,i,s);f!==null&&f.forEach(u=>{u!==null&&o.push(u)})}};r===void 0||i===void 0?n.toArray().forEach(l):pl(n,new vn(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(ai(n._item,r)?ai(n._item,i)||(c.ychange=s?s("added",n._item.id):{type:"added"}):c.ychange=s?s("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,o);return t.mapping.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},L),t.mapping.delete(n),null}},nb=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c<l.length;c++){let a=l[c];o.push(e.text(a.insert,cb(a.attributes,e)))}}catch{return n.doc.transact(a=>{n._item.delete(a)},L),null}return o},rb=(n,e)=>{let t=new me,r=n.map(i=>({insert:i.text,attributes:Ed(i.marks,e)}));return t.applyDelta(r),e.mapping.set(t,n),t},ib=(n,e)=>{let t=new G(n.type.name);for(let r in n.attrs){let i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,no(n).map(r=>Dc(r,e))),e.mapping.set(t,n),t},Dc=(n,e)=>n instanceof Array?rb(n,e):ib(n,e),wd=n=>typeof n=="object"&&n!==null,Rc=(n,e)=>{let t=Object.keys(n).filter(i=>n[i]!==null),r=t.length===(e==null?0:Object.keys(e).filter(i=>e[i]!==null).length);for(let i=0;i<t.length&&r;i++){let s=t[i],o=n[s],l=e[s];r=s==="ychange"||o===l||wd(o)&&wd(l)&&Rc(o,l)}return r},no=n=>{let e=n.content.content,t=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.isText){let s=[];for(let o=e[r];r<e.length&&o.isText;o=e[++r])s.push(o);r--,t.push(s)}else t.push(i)}return t},Cd=(n,e)=>{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&xo(r.attributes||{}).length===e[i].marks.length&&dt(r.attributes,(s,o)=>{let l=Td(o),c=e[i].marks;return Rc(s,c.find(a=>a.type.name===l)?.attrs)}))},ui=(n,e)=>{if(n instanceof G&&!(e instanceof Array)&&Nc(n,e)){let t=no(e);return n._length===t.length&&Rc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>ui(r,t[i]))}return n instanceof me&&e instanceof Array&&Cd(n,e)},eo=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),kd=(n,e,t)=>{let r=n.toArray(),i=no(e),s=i.length,o=r.length,l=Ge(o,s),c=0,a=0,f=!1;for(;c<l;c++){let u=r[c],h=i[c];if(eo(t.mapping.get(u),h))f=!0;else if(!ui(u,h))break}for(;c+a<l;a++){let u=r[o-a-1],h=i[s-a-1];if(eo(t.mapping.get(u),h))f=!0;else if(!ui(u,h))break}return{equalityFactor:c+a,foundMappedChild:f}},sb=n=>{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Re?e+=t.content.str:t.content instanceof U&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},ob=(n,e,t)=>{t.mapping.set(n,e);let{nAttrs:r,str:i}=sb(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,Ed(a.marks,t))})),{insert:o,remove:l,index:c}=yd(i,s.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,o),n.applyDelta(s.map(a=>({retain:a.insert.length,attributes:a.attributes})))},lb=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Td=n=>lb.exec(n)?.[1]??n,cb=(n,e)=>{let t=[];for(let r in n)t.push(e.mark(Td(r),n[r]));return t},Ed=(n,e)=>{let t={};return n.forEach(r=>{if(r.type.name!=="ychange"){let i=Se(e.isOMark,r.type,()=>!r.type.excludes(r.type));t[i?`${r.type.name}--${bd(r.toJSON())}`:r.type.name]=r.attrs}}),t},to=(n,e,t,r)=>{if(e instanceof G&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.mapping.set(e,t),e instanceof G){let u=e.getAttributes(),h=t.attrs;for(let d in h)h[d]!==null?u[d]!==h[d]&&d!=="ychange"&&e.setAttribute(d,h[d]):e.removeAttribute(d);for(let d in u)h[d]===void 0&&e.removeAttribute(d)}let i=no(t),s=i.length,o=e.toArray(),l=o.length,c=Ge(s,l),a=0,f=0;for(;a<c;a++){let u=o[a],h=i[a];if(!eo(r.mapping.get(u),h))if(ui(u,h))r.mapping.set(u,h);else break}for(;f+a<c;f++){let u=o[l-f-1],h=i[s-f-1];if(!eo(r.mapping.get(u),h))if(ui(u,h))r.mapping.set(u,h);else break}n.transact(()=>{for(;l-a-f>0&&s-a-f>0;){let h=o[a],d=i[a],p=o[l-f-1],m=i[s-f-1];if(h instanceof me&&d instanceof Array)Cd(h,d)||ob(h,d,r),a+=1;else{let g=h instanceof G&&Nc(h,d),y=p instanceof G&&Nc(p,m);if(g&&y){let k=kd(h,d,r),w=kd(p,m,r);k.foundMappedChild&&!w.foundMappedChild?y=!1:!k.foundMappedChild&&w.foundMappedChild||k.equalityFactor<w.equalityFactor?g=!1:y=!1}g?(to(n,h,d,r),a+=1):y?(to(n,p,m,r),f+=1):(r.mapping.delete(e.get(a)),e.delete(a,1),e.insert(a,[Dc(d,r)]),a+=1)}}let u=l-a-f;if(l===1&&s===0&&o[0]instanceof me?(r.mapping.delete(o[0]),o[0].delete(0,o[0].length)):u>0&&(e.slice(a,a+u).forEach(h=>r.mapping.delete(h)),e.delete(a,u)),a+f<s){let h=[];for(let d=a;d<s-f;d++)h.push(Dc(i[d],r));e.insert(a,h)}},L)},Nc=(n,e)=>!(e instanceof Array)&&n.nodeName===e.type.name;var Ic=(n,e,t)=>{if(n===0)return hs(e,0,e.length===0?-1:0);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof me){if(r._length>=n)return hs(r,n,e.length===0?-1:0);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n<i)r=r._first.content.type,n--;else{if(n===1&&r._length===0&&i>1)return new Ft(r._item===null?null:r._item.id,r._item===null?Ln(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new Ft(r._item===null?null:r._item.id,r._item===null?Ln(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw $();if(n===0&&r.constructor!==me&&r!==e)return ab(r._item.parent,r._item)}return hs(e,e._length,e.length===0?-1:0)},ab=(n,e)=>{let t=null,r=null;return n._item===null?r=Ln(n):t=C(n._item.id.client,n._item.id.clock),new Ft(t,r,e.id)},Zs=(n,e,t,r)=>{let i=pf(t,n);if(i===null||i.type!==e&&!Rn(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===me)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,c=0;for(;c<s._length&&c<i.index&&l!==null;){if(!l.deleted){let a=l.content.type;c++,a instanceof me?o+=a._length:o+=r.get(a).nodeSize}l=l.right}o+=1}for(;s!==e&&s._item!==null;){let l=s._item.parent;if(l._item===null||!l._item.deleted){o+=1;let c=l._first;for(;c!==null;){let a=c.content.type;if(a===s)break;c.deleted||(a instanceof me?o+=a._length:o+=r.get(a).nodeSize),c=c.right}}s=l}return o-1};var vc=n=>We.getState(n)?.undoManager?.undo()!=null,ro=n=>We.getState(n)?.undoManager?.redo()!=null,Md=(n,e)=>e==null?We.getState(n)?.undoManager?.canUndo():vc(n),Ad=(n,e)=>e==null?We.getState(n)?.undoManager?.canRedo():ro(n),fb=new Set(["paragraph"]),ub=(n,e)=>!(n instanceof I)||!(n.content instanceof Me)||!(n.content.type instanceof Qe||n.content.type instanceof G&&e.has(n.content.type.nodeName))||n.content.type._length===0,Od=({protectedNodes:n=fb,trackedOrigins:e=[],undoManager:t=null}={})=>new ye({key:We,state:{init:(r,i)=>{let s=L.getState(i),o=t||new Bn(s.type,{trackedOrigins:new Set([L].concat(e)),deleteFilter:l=>ub(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{let l=L.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,f=c.redoStack.length>0;return l?{undoManager:c,prevSel:fi(l,s),hasUndoOps:a,hasRedoOps:f}:a!==i.hasUndoOps||f!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):i}},view:r=>{let i=L.getState(r.state),s=We.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,We.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{let l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});function Dd({post:n,mergeUpdates:e,onStatus:t,debounceMs:r=2e3,setTimeoutFn:i=setTimeout}){let s=[],o=null,l=null,c="ok";function a(p){c==="failed"&&p!=="failed"||(c=p,t&&t(c))}function f(){l||(l=i(u,r))}async function u(){if(l=null,!s.length)return;let p=e(s);s=[],o=p;let m;try{m=await n(p)}catch{o=null,s.unshift(p),a("retrying"),f();return}if(o=null,m.ok){a("ok");return}if(m.status>=400&&m.status<500){a("failed");return}s.unshift(p),a("retrying"),f()}function h(p){s.push(p),!l&&(l=i(u,r))}function d(){let p=[];return o&&p.push(o),s.length&&p.push(e(s)),p.length?p.length===1?p[0]:e(p):null}return{enqueue:h,flush:u,pendingBytes:d,get status(){return c}}}function Nd({attemptResync:n,onDiverged:e,onRecovered:t,backoffMs:r=l=>Math.min(1e3*2**(l-1),3e4),setTimeoutFn:i=setTimeout,clearTimeoutFn:s=clearTimeout,addOnlineListener:o=l=>addEventListener("online",l)}){let l=!1,c=!1,a=0,f=null;function u(){a++,f&&s(f),f=i(h,r(a))}async function h(){if(f&&(s(f),f=null),!(!l||c)){c=!0;try{await n(),l=!1,a=0,t&&t()}catch{u()}finally{c=!1}}}function d(){l||(l=!0,a=0,e&&e()),h()}return o(()=>{l&&h()}),{reportDivergence:d,get diverged(){return l},get resyncing(){return c}}}var Bc={center:"docs-align-center",right:"docs-align-right"},Id=["left","center","right"];function io(n){return Object.prototype.hasOwnProperty.call(Bc,n)?Bc[n]:null}function hb(n){for(let[e,t]of Object.entries(Bc))if(n.includes(t))return e;return null}function _d(n){return{...n,attrs:{...n.attrs||{},align:{default:null}},parseDOM:[{tag:"p",getAttrs:e=>({align:hb(Array.from(e.classList||[]))})}],toDOM:e=>{let t=io(e.attrs.align);return t?["p",{class:t},0]:["p",0]}}}function Rd(n){return(e,t)=>{let{from:r,to:i}=e.selection,s=!1,o=e.tr;return e.doc.nodesBetween(r,i,(l,c)=>{l.type.isTextblock&&(!l.type.spec.attrs||!l.type.spec.attrs.align||(s=!0,t&&o.setNodeMarkup(c,null,{...l.attrs,align:n})))}),s?(t&&t(o),!0):!1}}function vd(n){let e=n.selection.$from.parent,t=e.attrs&&e.attrs.align;return io(t)?t:"left"}function Bd(n){return{...n,parseDOM:[{tag:"br.Apple-interchange-newline",ignore:!0},...n.parseDOM||[]]}}function Vd(n){let e=n.nodes.paragraph,t=n.nodes.hard_break;return r=>{let i=Ud(r.content,e,t);return i===r.content?r:new b(i,r.openStart,r.openEnd)}}function Ud(n,e,t){let r=[],i=!1;return n.forEach(s=>{if(s.type===e&&s.childCount>0&&db(s,t)){for(let l=0;l<s.childCount;l+=1)r.push(e.create(s.attrs));i=!0;return}if(s.isTextblock||s.isLeaf){r.push(s);return}let o=Ud(s.content,e,t);if(o===s.content){r.push(s);return}r.push(s.copy(o)),i=!0}),i?x.fromArray(r):n}function db(n,e){let t=!0;return n.forEach(r=>{r.type!==e&&(t=!1)}),t}function Ld(n,e){if(!n||e.length===0)return{ensureReachable(){},focusStop(){return!1}};let t=()=>e.filter(o=>!o.disabled);function r(o){for(let l of e)l.tabIndex=l===o?0:-1}function i(){let o=t();o.length!==0&&(o.some(l=>l.tabIndex===0)||r(o[0]))}n.addEventListener("keydown",o=>{let l=o.key;if(l!=="ArrowRight"&&l!=="ArrowLeft"&&l!=="Home"&&l!=="End")return;let c=t(),a=c.indexOf(document.activeElement);if(a<0||c.length===0)return;let f;l==="Home"?f=c[0]:l==="End"?f=c[c.length-1]:l==="ArrowRight"?f=c[(a+1)%c.length]:f=c[(a-1+c.length)%c.length],o.preventDefault(),r(f),f.focus()}),n.addEventListener("focusin",o=>{e.includes(o.target)&&r(o.target)}),i();function s(){let o=t();if(o.length===0)return!1;let l=o.find(c=>c.tabIndex===0)||o[0];return r(l),l.focus(),!0}return{ensureReachable:i,focusStop:s}}var an=["sans","serif","mono"],nr="sans",hi=["font_mono","font_sans","font_serif"];function Fd(n){if(an.includes(n))return n===nr?null:"font_"+n}function Pd(n){for(let e of hi)if(n.includes(e))return e.slice(5);return nr}function pb(){let n=hi.map(e=>e.slice(5));if([...n].sort().join()!==[...an].sort().join())throw new Error(`fonts: marks [${n}] do not match the faces [${an}]`);if(!an.includes(nr))throw new Error(`fonts: the default ${JSON.stringify(nr)} is not one of [${an}]`);if(an[0]!==nr)throw new Error(`fonts: the toolbar lists ${JSON.stringify(an[0])} first but the default is ${JSON.stringify(nr)} \u2014 with no JavaScript the control would name a face the text is not in`)}pb();var Uc={align_left:null,align_center:"center",align_right:"right"};function mb(){let n=Object.keys(Uc);for(let r of n){let i=Uc[r],s="align_"+(i===null?"left":i);if(r!==s)throw new Error(`toolbar: ${r} sets the alignment ${JSON.stringify(i)}, which belongs to ${s}`);if(i!==null&&!io(i))throw new Error(`toolbar: ${r} sets ${JSON.stringify(i)}, which align.mjs does not know`)}let e=n.map(r=>r.slice(6)).sort(),t=[...Id].sort();if(e.join()!==t.join())throw new Error(`toolbar: alignment commands [${e}] do not match align.mjs's [${t}]`)}mb();function Vc(n){let e=n.previousElementSibling;return!e||!e.hasAttribute("rst-combo")?null:e.querySelector("input")}function gb(n,e){if(!e)return;let t=n.getAttribute("aria-label");t&&e.setAttribute("aria-label",t)}function yb(n,e){if(!e||document.activeElement===e)return;let t=n.options[n.selectedIndex];e.value=t?t.text:""}function Jd({root:n,schema:e,getView:t,onSync:r}){if(!n)return{plugin:null,commands:zd(e)};let i=Array.from(n.querySelectorAll("[data-docs-command]")),s=Array.from(n.querySelectorAll("[data-docs-select]")),o=zd(e);for(let f of i)f.addEventListener("mousedown",u=>u.preventDefault()),f.addEventListener("click",()=>{let u=t(),h=o[f.getAttribute("data-docs-command")];!u||!h||(h(u.state,u.dispatch,u),u.focus())});for(let f of s)f.addEventListener("mousedown",u=>u.stopPropagation()),f.addEventListener("change",()=>{let u=t();u&&u.focus()}),f.addEventListener("change",()=>{let u=t();if(!u)return;let h=f.getAttribute("data-docs-select"),d=f.value;if(h==="block"&&di(e,d)(u.state,u.dispatch),h==="font"){let p=Fd(d);p!==void 0&&$d(e,hi,p)(u.state,u.dispatch)}if(h==="size"){let p=ld(d);p!==void 0&&$d(e,Mt,p)(u.state,u.dispatch)}u.focus()});function l(f){let u=f.state;for(let h of i){let d=h.getAttribute("data-docs-command"),p=o[d];if(!p)continue;let m=p(u,null,f);h.disabled=!m;let g=wb(u,e,d);h.setAttribute("aria-pressed",g?"true":"false")}for(let h of s){h.disabled=!1;let d=Vc(h);d&&(d.disabled=!1),gb(h,d);let p=h.getAttribute("data-docs-select");p==="block"&&(h.value=kb(u)),p==="font"&&(h.value=Sb(u,e)),p==="size"&&(h.value=String(cd(Cb(u,e,Mt)))),yb(h,Vc(h))}r&&r(f)}let c=Ld(n,[...i,...s.map(f=>Vc(f)||f)]);return{plugin:new ye({view:f=>(l(f),c.ensureReachable(),{update:u=>{l(u),c.ensureReachable()}})}),commands:o,focusStop:c.focusStop}}function zd(n){let e=n.marks,t=n.nodes;return{undo:Md,redo:Ad,strong:cn(e.strong),em:cn(e.em),code:cn(e.code),bullet_list:qd(t.bullet_list,t.list_item),ordered_list:qd(t.ordered_list,t.list_item),blockquote:bb(t.blockquote),select_all:Sc,clear_formatting:xb,block_paragraph:di(n,"paragraph"),"block_heading-1":di(n,"heading-1"),"block_heading-2":di(n,"heading-2"),"block_heading-3":di(n,"heading-3"),indent:qe(js(t.list_item),er(1)),outdent:qe(li(t.list_item),er(-1)),...Object.fromEntries(Object.entries(Uc).map(([r,i])=>[r,Rd(i)]))}}function xb(n,e){let{from:t,to:r,empty:i}=n.selection;if(i)return!1;if(e){let s=n.tr.removeMark(t,r,null);s.setBlockType(t,r,n.schema.nodes.paragraph),e(s.scrollIntoView())}return!0}function di(n,e){if(e==="paragraph")return Cc(n.nodes.paragraph);let t=Number(e.split("-")[1]);return Number.isInteger(t)?Cc(n.nodes.heading,{level:t}):()=>!1}function $d(n,e,t){return(r,i)=>{let s=e.map(u=>n.marks[u]).filter(Boolean),o=t?n.marks[t]:null;if(t&&!o)return!1;if(!i)return!0;let{from:l,to:c,empty:a}=r.selection;if(a){let u=(r.storedMarks||r.selection.$from.marks()).filter(h=>!s.includes(h.type));return o&&(u=o.create().addToSet(u)),i(r.tr.setStoredMarks(u)),!0}let f=r.tr;for(let u of s)f.removeMark(l,c,u);return o&&f.addMark(l,c,o.create()),i(f),!0}}function qd(n,e){let t=Jh(n),r=li(e);return(i,s,o)=>pi(i,n)?r(i,s,o):t(i,s,o)}function bb(n){let e=ed(n);return(t,r,i)=>pi(t,n)?Xh(t,r,i):e(t,r,i)}function pi(n,e){let t=n.selection.$from;for(let r=t.depth;r>0;r--)if(t.node(r).type===e)return!0;return!1}function wb(n,e,t){if(t.startsWith("align_"))return vd(n)===t.slice(6);if(t==="bullet_list")return pi(n,e.nodes.bullet_list);if(t==="ordered_list")return pi(n,e.nodes.ordered_list);if(t==="blockquote")return pi(n,e.nodes.blockquote);let r=e.marks[t];return r?Lc(n,r):!1}function Lc(n,e){let{from:t,$from:r,to:i,empty:s}=n.selection;return s?!!e.isInSet(n.storedMarks||r.marks()):n.doc.rangeHasMark(t,i,e)}function kb(n){let e=n.selection.$from.parent;return e.type.name==="heading"?"heading-"+e.attrs.level:"paragraph"}function Sb(n,e){let t=hi.filter(r=>{let i=e.marks[r];return i&&Lc(n,i)});return Pd(t)}function Cb(n,e,t){let r=[];for(let i of t){let s=e.marks[i];s&&Lc(n,s)&&r.push(i)}return r}var Tb={print:()=>(window.print(),!0)};function Wd(n){return n.querySelector("[docs-menu][open]")}function Pc(n){return Array.from(n.querySelectorAll("[docs-menu-title]"))}function Fc(n){return Array.from(n.querySelectorAll("[docs-menu-item]")).filter(e=>!e.disabled)}function zc(n,e){for(let t of Pc(n))t.tabIndex=t===e?0:-1;e.focus()}function rr(n,e){let t=Wd(n);if(!t)return!1;if(t.open=!1,e){let r=t.querySelector("[docs-menu-title]");r&&zc(n,r)}return!0}function jd(n,{getView:e,commands:t,extraCommands:r}){if(!n)return null;let i=Pc(n);if(!i.length)return null;for(let[c,a]of i.entries())a.tabIndex=c===0?0:-1;let s={...Tb,...r||{}};function o(c,a){let f=s[c];if(f){if(a){let p=a.closest("[docs-menu]");if(p){let m=p.querySelector("[docs-menu-title]");m&&zc(n,m)}}return f()}let u=e();if(!u)return!1;let h=t[c];if(!h)return!1;let d=h(u.state,u.dispatch,u);return u.focus(),d}n.addEventListener("click",c=>{let a=c.target.closest("[docs-menu-item]");if(!(!a||a.disabled)){if(!a.hasAttribute("data-docs-command")){rr(n,!1);return}c.preventDefault(),o(a.getAttribute("data-docs-command"),a),rr(n,!1)}}),n.addEventListener("keydown",c=>{let a=c.target.closest("[docs-menu-title]"),f=c.target.closest("[docs-menu-item]"),u=Wd(n);switch(c.key){case"Escape":rr(n,!0)&&c.preventDefault();return;case"ArrowRight":case"ArrowLeft":{let h=a||u&&u.querySelector("[docs-menu-title]");if(!h)return;c.preventDefault();let d=Pc(n),p=d[(d.indexOf(h)+(c.key==="ArrowRight"?1:-1)+d.length)%d.length],m=!!u;rr(n,!1),m&&(p.closest("[docs-menu]").open=!0),zc(n,p);return}case"ArrowDown":case"ArrowUp":{if(a){c.preventDefault();let h=a.closest("[docs-menu]");h.open=!0;let d=Fc(h);d.length&&d[c.key==="ArrowDown"?0:d.length-1].focus();return}if(f&&u){c.preventDefault();let h=Fc(u),d=h.indexOf(f);if(d<0||!h.length)return;h[(d+(c.key==="ArrowDown"?1:-1)+h.length)%h.length].focus()}return}case"Home":case"End":{if(!f||!u)return;c.preventDefault();let h=Fc(u);h.length&&h[c.key==="Home"?0:h.length-1].focus();return}case"Tab":rr(n,!1)}}),document.addEventListener("click",c=>{n.contains(c.target)||rr(n,!1)},!0);function l(c){for(let a of n.querySelectorAll("[docs-menu-item][data-docs-command]")){if(a.hasAttribute("data-docs-unavailable"))continue;let f=a.getAttribute("data-docs-command");if(s[f]){a.disabled=!1;continue}let u=t[f];a.disabled=!(c&&u&&u(c.state,null,c))}}return{sync:l}}function $c(n,{since:e,raw:t}={}){let r=[];return e!==void 0&&r.push(`since=${e}`),t&&r.push("raw=1"),r.length?`${n}?${r.join("&")}`:n}function Kd({initialSeq:n=0,openStream:e,fetchSince:t,onUpdates:r,onError:i=()=>{},setTimeoutFn:s=setTimeout,clearTimeoutFn:o=clearTimeout,idleMs:l=12e4}){let c=n,a=null,f=null,u=!1,h=!1,d=!1;function p(){f!==null&&o(f),f=s(()=>{f=null,m()},l)}function m(){f!==null&&(o(f),f=null),a&&(a.close(),a=null)}function g(){u||a||(a=e(k=>{p(),k>c&&y()},k=>{m(),i(k)}),p())}async function y(){if(h){d=!0;return}h=!0;try{let k=c,w=await t(k);if(u)return;try{w&&w.bytes&&w.bytes.length&&r(w.bytes)}catch{if(w=await t(k,{raw:!0}),u)return;w&&w.bytes&&w.bytes.length&&r(w.bytes)}w&&typeof w.seq=="number"&&w.seq>c&&(c=w.seq)}catch(k){i(k)}finally{h=!1,d&&!u&&(d=!1,y())}}return{start(){u=!1,g()},stop(){u=!0,m()},noteOwnSeq(k){typeof k!="number"||!Number.isFinite(k)||k===c+1&&(c=k)},noteActivity(){u||(a?p():g())},noteHidden(){m()},get cursor(){return c},get streaming(){return a!==null}}}function so(n,e){return{group:e,excludes:e,parseDOM:[{tag:"span."+n}],toDOM:()=>["span",{class:n},0]}}var Eb=Mt.reduce((n,e)=>n.addToStart(e,so("docs-"+e.replace("_","-"),"fontSize")),Zn.spec.marks).addToStart("font_mono",so("docs-font-mono","fontFamily")).addToStart("font_sans",so("docs-font-sans","fontFamily")).addToStart("font_serif",so("docs-font-serif","fontFamily")),Mb=qh(Zn.spec.nodes.update("paragraph",Mc(_d(Zn.spec.nodes.get("paragraph")),"p")).update("heading",Mc(Zn.spec.nodes.get("heading"),"h1")).update("hard_break",Bd(Zn.spec.nodes.get("hard_break"))),"paragraph block*","block"),Ke=new zn({nodes:Mb,marks:Eb});function Ab(n,e){return e&&e(n.tr.replaceSelectionWith(Ke.nodes.hard_break.create()).scrollIntoView()),!0}var Ob=250;function qc(n,e){if(!e.length)return;let t=kn(e);for(;Ai(t);)hf(t,n,"server")}async function Db(n){let e=n.getAttribute("data-sqid"),t=`/d/${e}/updates`,r=`/d/${e}/stream`,i=document.querySelector("[docs-save-status]"),s=!1,o=null,l=null,c=null,a=null,f=document.querySelector("[docs-canvas]"),u=f&&f.getAttribute("data-view")===tr?tr:Ac,h=f?f.getAttribute("data-page-label"):"";function d(E){u=E,f&&f.setAttribute("data-view",E),ad(E);let _=l;_&&_.dispatch(_.state.tr)}let p=pd(document.querySelector("[docs-wordcount]"),{getView:()=>l}),m=md(document.querySelector("[docs-shortcuts]"),{menubar:document.querySelector("[docs-menubar]"),extraRows:Array.from(document.querySelectorAll("[docs-shortcuts-extra] span")).map(E=>({group:E.closest("[docs-shortcuts-extra]").getAttribute("data-group")||"",label:E.getAttribute("data-label")||"",keys:E.getAttribute("data-keys")||""}))}),g=Jd({root:document.querySelector("[docs-toolbar]"),schema:Ke,getView:()=>l,onSync:E=>{a&&a.sync(E)}});a=jd(document.querySelector("[docs-menubar]"),{getView:()=>l,commands:g.commands,extraCommands:{view_paged:()=>(d(tr),!0),view_infinite:()=>(d(Ac),!0),...p?{word_count:p}:{},...m?{shortcuts:m}:{}}});function y(E){i&&i.setAttribute("data-state",s?"failed":E)}function k(E){return Dd({post:async _=>{let v=await fetch(t,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/octet-stream"},body:_}),Ot=E();if(v.ok&&Ot){let at=Number(v.headers.get("Docs-Seq"));Number.isFinite(at)&&Ot.noteOwnSeq(at)}return v},mergeUpdates:xf,debounceMs:Ob,onStatus:_=>{_==="failed"&&(s=!0,T.reportDivergence()),y(_)}})}function w(E){let _=l;if(!_||E.button!==0||_.dom.contains(E.target))return;let v=_.dom.getBoundingClientRect(),Ot=_.posAtCoords({left:Math.min(Math.max(E.clientX,v.left+1),v.right-1),top:Math.min(Math.max(E.clientY,v.top+1),v.bottom-1)}),at=Ot?Ot.pos:_.state.doc.content.size,gi=M.near(_.state.doc.resolve(at));E.preventDefault(),_.dispatch(_.state.tr.setSelection(gi).scrollIntoView()),_.focus()}function be(E,_){let v=[_c(_),Od(),od(Ke),fd({getMode:()=>u,pageLabel:h}),bc({"Mod-z":vc,"Mod-y":ro,"Mod-Shift-z":ro,"Mod-b":cn(Ke.marks.strong),"Mod-i":cn(Ke.marks.em),"Shift-Enter":Ab,Tab:qe(js(Ke.nodes.list_item),er(1)),"Shift-Tab":qe(li(Ke.nodes.list_item),er(-1)),Backspace:id,Escape:()=>g.focusStop(),Enter:qe(Wh(Ke.nodes.list_item),Tc.Enter)}),bc(Tc)];return g.plugin&&v.push(g.plugin),new ni({mount:E},{state:Rs.create({schema:Ke,plugins:v}),transformPasted:Vd(Ke)})}async function Be(E){let _=$c(t,{raw:E}),v=await fetch(_,{credentials:"same-origin"});if(!v.ok)throw new Error(`load ${_}: ${v.status}`);return{log:new Uint8Array(await v.arrayBuffer()),startSeq:Number(v.headers.get("Docs-Seq"))}}async function At(){let{log:E,startSeq:_}=await Be(!1),v=new Te;try{qc(v,E)}catch{({log:E,startSeq:_}=await Be(!0)),v=new Te,qc(v,E)}let Ot=v.getXmlFragment("prosemirror"),at=null,gi=k(()=>at);v.on("update",(Ve,ir)=>{ir!=="server"&&(T.diverged||gi.enqueue(Ve))}),l&&l.destroy(),o=gi,l=be(n,Ot),c&&c.stop(),at=Kd({initialSeq:Number.isFinite(_)?_:0,openStream:(Ve,ir)=>{let fn=new EventSource(r,{withCredentials:!0});return fn.addEventListener("update",ft=>Ve(Number(ft.data))),fn.addEventListener("error",ft=>ir(ft)),{close:()=>fn.close()}},fetchSince:async(Ve,{raw:ir}={})=>{let fn=$c(t,{since:Ve,raw:ir}),ft=await fetch(fn,{credentials:"same-origin"});if(!ft.ok)throw new Error(`fetch ${fn}: ${ft.status}`);return{bytes:new Uint8Array(await ft.arrayBuffer()),seq:Number(ft.headers.get("Docs-Seq"))}},onUpdates:Ve=>{T.diverged||qc(v,Ve)},onError:Ve=>{console.error("live updates:",Ve)}}),c=at,c.start(),typeof document<"u"&&document.hidden&&c.noteHidden()}let T=Nd({attemptResync:At,onDiverged:()=>y("failed"),onRecovered:()=>y(s?"failed":"ok")});await At(),addEventListener("visibilitychange",()=>{document.hidden?c&&c.noteHidden():c&&c.noteActivity()});for(let E of["pointermove","scroll","keydown","focus"])addEventListener(E,()=>c&&c.noteActivity(),{passive:!0,capture:!0});let B=n.closest("[docs-page]");B&&B.addEventListener("mousedown",w);let J=!1,mi=()=>{J=!0,setTimeout(()=>{J=!1},0)};return document.addEventListener("mousedown",mi,!0),document.addEventListener("touchstart",mi,!0),n.addEventListener("focus",()=>{if(J)return;let E=l;E&&E.dispatch(E.state.tr.scrollIntoView())}),addEventListener("beforeunload",()=>{let E=o&&o.pendingBytes();if(!E)return;let _=new Blob([E],{type:"application/octet-stream"});navigator.sendBeacon(t,_)||(console.error("beforeunload: sendBeacon refused the pending edit, retrying via keepalive fetch"),fetch(t,{method:"POST",credentials:"same-origin",keepalive:!0,headers:{"Content-Type":"application/octet-stream"},body:E}).catch(()=>{}))}),l}var Jc=document.querySelector("[docs-editor]");Jc&&Db(Jc).catch(n=>{Jc.setAttribute("data-editor-failed","1"),console.error(n)});export{Db as mountEditor};
+`).scrollIntoView()),!0)};function kc(n){for(let e=0;e<n.edgeCount;e++){let{type:t}=n.edge(e);if(t.isTextblock&&!t.hasRequiredAttrs())return t}return null}var mx=(n,e)=>{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=kc(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(M.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},gx=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof le||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=kc(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index()<i.parent.childCount?r:i).pos,l=n.tr.insert(o,s.createAndFill());l.setSelection(N.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},yx=(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(xt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&Yt(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function xx(n){return(e,t)=>{if(e.selection instanceof S&&e.selection.node.isBlock){let{$from:d}=e.selection;return!d.parentOffset||!xt(e.doc,d.pos)?!1:(t&&t(e.tr.split(d.pos).scrollIntoView()),!0)}if(!e.selection.$from.depth)return!1;let r=e.tr;!e.selection.empty&&(e.selection instanceof N||e.selection instanceof le)&&r.deleteSelection();let{$from:i}=r.selection,s=r.steps.length,o=[],l,c,a=!1,f=!1;for(let d=i.depth;;d--)if(i.node(d).isBlock){a=i.end(d)==i.pos+(i.depth-d),f=i.start(d)==i.pos-(i.depth-d),c=kc(i.node(d-1).contentMatchAt(i.indexAfter(d-1)));let m=n&&n(i.parent,a,i);o.unshift(m||(a&&c?{type:c}:null)),l=d;break}else{if(d==1)return!1;o.unshift(null)}let u=i.pos,h=xt(r.doc,u,o.length,o);if(h||(o[0]=c?{type:c}:null,h=xt(r.doc,u,o.length,o)),!h)return!1;if(r.split(u,o.length,o),!a&&f&&i.node(l).type!=c){let d=r.mapping.slice(s),p=d.map(i.before(l)),m=r.doc.resolve(p);c&&i.node(l-1).canReplaceWith(m.index(),m.index()+1,c)&&r.setNodeMarkup(d.map(i.before(l)),c)}return t&&t(r.scrollIntoView()),!0}}var bx=xx();var Sc=(n,e)=>(e&&e(n.tr.setSelection(new le(n.doc))),!0);function wx(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||Gt(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Zh(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&wx(n,e,t))return!0;let a=!c&&e.parent.canReplace(e.index(),e.index()+1);if(a&&(o=(l=i.contentMatchAt(i.childCount)).findWrapping(s.type))&&l.matchType(o[0]||s.type).validEnd){if(t){let d=e.pos+s.nodeSize,p=x.empty;for(let y=o.length-1;y>=0;y--)p=x.from(o[y].create(null,p));p=x.from(i.copy(p));let m=n.tr.step(new H(e.pos-1,d,e.pos,d,new b(p,1,0),o.length,!0)),g=m.doc.resolve(d+2*o.length);g.nodeAfter&&g.nodeAfter.type==i.type&&Gt(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let f=s.type.spec.isolating||r>0&&c?null:M.findFrom(e,1),u=f&&f.$from.blockRange(f.$to),h=u&&Yt(u);if(h!=null&&h>=e.depth)return t&&t(n.tr.lift(u,h).scrollIntoView()),!0;if(a&&Qn(s,"start",!0)&&Qn(i,"end")){let d=i,p=[];for(;p.push(d),!d.isTextblock;)d=d.lastChild;let m=s,g=1;for(;!m.isTextblock;m=m.firstChild)g++;if(d.canReplace(d.childCount,d.childCount,m.content)){if(t){let y=x.empty;for(let w=p.length-1;w>=0;w--)y=x.from(p[w].copy(y));let k=n.tr.step(new H(e.pos-p.length,e.pos+s.nodeSize,e.pos+g,e.pos+s.nodeSize-g,new b(y,p.length,0),0,!0));t(k.scrollIntoView())}return!0}}return!1}function Qh(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(N.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var kx=Qh(-1),Sx=Qh(1);function ed(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Jn(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Cc(n,e=null){return function(t,r){let i=!1;for(let s=0;s<t.selection.ranges.length&&!i;s++){let{$from:{pos:o},$to:{pos:l}}=t.selection.ranges[s];t.doc.nodesBetween(o,l,(c,a)=>{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let f=t.doc.resolve(a),u=f.index();i=f.parent.canReplaceWith(u,u+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o<t.selection.ranges.length;o++){let{$from:{pos:l},$to:{pos:c}}=t.selection.ranges[o];s.setBlockType(l,c,n,e)}r(s.scrollIntoView())}return!0}}function Cx(n,e,t,r){for(let i=0;i<e.length;i++){let{$from:s,$to:o}=e[i],l=s.depth==0?n.inlineContent&&n.type.allowsMarkType(t):!1;if(n.nodesBetween(s.pos,o.pos,(c,a)=>{if(l||!r&&c.isAtom&&c.isInline&&a>=s.pos&&a+c.nodeSize<=o.pos)return!1;l=c.inlineContent&&c.type.allowsMarkType(t)}),l)return!0}return!1}function Tx(n){let e=[];for(let t=0;t<n.length;t++){let{$from:r,$to:i}=n[t];r.doc.nodesBetween(r.pos,i.pos,(s,o)=>{if(s.isAtom&&s.content.size&&s.isInline&&o>=r.pos&&o+s.nodeSize<=i.pos)return o+1>r.pos&&e.push(new jn(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.pos<i.pos&&e.push(new jn(r,i))}return e}function cn(n,e=null,t){let r=(t&&t.removeWhenPresent)!==!1,i=(t&&t.enterInlineAtoms)!==!1,s=!(t&&t.includeWhitespace);return function(o,l){let{empty:c,$cursor:a,ranges:f}=o.selection;if(c&&!a||!Cx(o.doc,f,n,i))return!1;if(l)if(a)n.isInSet(o.storedMarks||a.marks())?l(o.tr.removeStoredMark(n)):l(o.tr.addStoredMark(n.create(e)));else{let u,h=o.tr;i||(f=Tx(f)),r?u=!f.some(d=>o.doc.rangeHasMark(d.$from.pos,d.$to.pos,n)):u=!f.every(d=>{let p=!1;return h.doc.nodesBetween(d.$from.pos,d.$to.pos,(m,g,y)=>{if(p)return!1;p=!n.isInSet(m.marks)&&!!y&&y.type.allowsMarkType(n)&&!(m.isText&&/^\s*$/.test(m.textBetween(Math.max(0,d.$from.pos-g),Math.min(m.nodeSize,d.$to.pos-g))))}),!p});for(let d=0;d<f.length;d++){let{$from:p,$to:m}=f[d];if(!u)h.removeMark(p.pos,m.pos,n);else{let g=p.pos,y=m.pos,k=p.nodeAfter,w=m.nodeBefore,be=s&&k&&k.isText?/^\s*/.exec(k.text)[0].length:0,Be=s&&w&&w.isText?/\s*$/.exec(w.text)[0].length:0;g+be<y&&(g+=be,y-=Be),h.addMark(g,y,n.create(e))}}l(h.scrollIntoView())}return!0}}function qe(...n){return function(e,t,r){for(let i=0;i<n.length;i++)if(n[i](e,t,r))return!0;return!1}}var wc=qe(Hh,ax,fx),Kh=qe(Hh,hx,dx),lt={Enter:qe(px,gx,yx,bx),"Mod-Enter":mx,Backspace:wc,"Mod-Backspace":wc,"Shift-Backspace":wc,Delete:Kh,"Mod-Delete":Kh,"Mod-a":Sc},td={"Ctrl-h":lt.Backspace,"Alt-Backspace":lt["Mod-Backspace"],"Ctrl-d":lt.Delete,"Ctrl-Alt-Backspace":lt["Mod-Delete"],"Alt-Delete":lt["Mod-Delete"],"Alt-d":lt["Mod-Delete"],"Ctrl-a":kx,"Ctrl-e":Sx};for(let n in lt)td[n]=lt[n];var Ex=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,Tc=Ex?td:lt;function Mx(n){let e=Ec(n);return e?"docs-indent-"+e:null}function Ec(n){if(typeof n!="number"&&(typeof n!="string"||!/^\d+$/.test(n)))return 0;let e=Number(n);return!Number.isInteger(e)||e<1?0:Math.min(e,8)}function Ax(n){for(let e of n){if(!e.startsWith("docs-indent-"))continue;let t=Ec(e.slice(12));if(t)return t}return null}function Mc(n,e){let t=n.parseDOM||[{tag:e}];return{...n,attrs:{...n.attrs||{},indent:{default:null}},parseDOM:t.map(r=>({...r,getAttrs:i=>{let s=r.getAttrs?r.getAttrs(i):{};return s===!1?!1:{...s||{},indent:Ax(Array.from(i.classList||[]))}}})),toDOM:r=>{let i=n.toDOM?n.toDOM(r):[e,0],s=Mx(r.attrs.indent);if(!s)return i;let[o,l,...c]=i;if(l&&typeof l=="object"&&!Array.isArray(l)){let a={...l,class:l.class?l.class+" "+s:s};return[o,a,...c]}return[o,{class:s},l,...c]}}}function er(n){return(e,t)=>{let{from:r,to:i}=e.selection,s=!1,o=e.tr;return e.doc.nodesBetween(r,i,(l,c)=>{if(!l.type.isTextblock||!l.type.spec.attrs||!l.type.spec.attrs.indent)return;let a=Ec(l.attrs.indent),f=Math.max(0,Math.min(8,a+n));f!==a&&(s=!0,t&&o.setNodeMarkup(c,null,{...l.attrs,indent:f===0?null:f}))}),s?(t&&t(o),!0):!1}}var Je=class{constructor(e,t,r={}){this.match=e,this.match=e,this.handler=typeof t=="string"?Ox(t):t,this.undoable=r.undoable!==!1,this.inCode=r.inCode||!1,this.inCodeMark=r.inCodeMark!==!1}};function Ox(n){return function(e,t,r,i){let s=n;if(t[1]){let o=t[0].lastIndexOf(t[1]);s+=t[0].slice(o+t[1].length),r+=o;let l=r-i;l>0&&(s=t[0].slice(o-l,o)+s,r=i)}return e.tr.insertText(s,r,i)}}var Dx=500;function rd({rules:n}){let e=new ye({state:{init(){return null},apply(t,r){let i=t.getMeta(this);return i||(t.selectionSet||t.docChanged?null:r)}},props:{handleTextInput(t,r,i,s){return nd(t,r,i,s,n,e)},handleDOMEvents:{compositionend:t=>{setTimeout(()=>{let{$cursor:r}=t.state.selection;r&&nd(t,r.pos,r.pos,"",n,e)})}}},isInputRules:!0});return e}function nd(n,e,t,r,i,s){if(n.composing)return!1;let o=n.state,l=o.doc.resolve(e),c=l.parent.textBetween(Math.max(0,l.parentOffset-Dx),l.parentOffset,null,"\uFFFC")+r;for(let a=0;a<i.length;a++){let f=i[a];if(!f.inCodeMark&&l.marks().some(p=>p.type.spec.code))continue;if(l.parent.type.spec.code){if(!f.inCode)continue}else if(f.inCode==="only")continue;let u=f.match.exec(c);if(!u||u[0].length<r.length)continue;let h=e-(u[0].length-r.length);if(!f.inCodeMark){let p=!1;if(o.doc.nodesBetween(h,l.pos,m=>{m.isInline&&m.marks.some(g=>g.type.spec.code)&&(p=!0)}),p)continue}let d=f.handler(o,u,h,t);if(d)return f.undoable&&d.setMeta(s,{transform:d,from:e,to:t,text:r}),n.dispatch(d),!0}return!1}var id=(n,e)=>{let t=n.plugins;for(let r=0;r<t.length;r++){let i=t[r],s;if(i.spec.isInputRules&&(s=i.getState(n))){if(e){let o=n.tr,l=s.transform;for(let c=l.steps.length-1;c>=0;c--)o.step(l.steps[c].invert(l.docs[c]));if(s.text){let c=o.doc.resolve(s.from).marks();o.replaceWith(s.from,s.to,n.schema.text(s.text,c))}else o.delete(s.from,s.to);e(o)}return!0}}return!1},ok=new Je(/--$/,"\u2014",{inCodeMark:!1}),lk=new Je(/\.\.\.$/,"\u2026",{inCodeMark:!1}),ck=new Je(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(")$/,"\u201C",{inCodeMark:!1}),ak=new Je(/"$/,"\u201D",{inCodeMark:!1}),fk=new Je(/(?:^|[\s\{\[\(\<'"\u2018\u201C])(')$/,"\u2018",{inCodeMark:!1}),uk=new Je(/'$/,"\u2019",{inCodeMark:!1});function Ys(n,e,t=null,r){return new Je(n,(i,s,o,l)=>{let c=t instanceof Function?t(s):t,a=i.tr.delete(o,l),f=a.doc.resolve(o),u=f.blockRange(),h=u&&Jn(u,e,c);if(!h)return null;a.wrap(u,h);let d=a.doc.resolve(o-1).nodeBefore;return d&&d.type==e&&Gt(a.doc,o-1)&&(!r||r(s,d))&&a.join(o-1),a})}function sd(n,e,t=null){return new Je(n,(r,i,s,o)=>{let l=r.doc.resolve(s),c=t instanceof Function?t(i):t;return l.node(-1).canReplaceWith(l.index(-1),l.indexAfter(-1),e)?r.tr.delete(s,o).setBlockType(s,s,e,c):null})}var Nx=/^\s*([-+*])\s$/,Ix=/^(\d+)\.\s$/,_x=/^\s*>\s$/,Rx=/^(#{1,3})\s$/;function od(n){let e=[],{bullet_list:t,ordered_list:r,blockquote:i,heading:s}=n.nodes;return t&&e.push(Ys(Nx,t)),r&&e.push(Ys(Ix,r)),i&&e.push(Ys(_x,i)),s&&e.push(sd(Rx,s,o=>({level:o[1].length}))),rd({rules:e})}var ct=[12,8,9,10,11,14,18,24,36,48,72],Et=12,Mt=[...ct.filter(n=>n!==Et).map(n=>"size_"+n),"size_sm","size_lg","size_xl"],Gs={size_sm:10,size_lg:14,size_xl:18};function ld(n){let e=Number(n);if(ct.includes(e))return e===Et?null:"size_"+e}function cd(n){for(let e of Mt)if(n.includes(e))return e in Gs?Gs[e]:Number(e.slice(5));return Et}function vx(){if(!ct.includes(Et))throw new Error(`sizes: the default ${Et} is not one of [${ct}]`);if(ct[0]!==Et)throw new Error(`sizes: the control lists ${ct[0]} first but the default is ${Et} \u2014 with no JavaScript the control would name a size the text is not set in`);for(let[t,r]of Object.entries(Gs)){if(!ct.includes(r))throw new Error(`sizes: the legacy mark ${t} maps to ${r}pt, which is not on the ladder [${ct}]`);if(!Mt.includes(t))throw new Error(`sizes: the legacy mark ${t} is not in the group the toolbar clears`)}let n=ct.filter(t=>t!==Et).map(t=>"size_"+t),e=Mt.filter(t=>!(t in Gs));if(n.join()!==e.join())throw new Error(`sizes: the marks [${e}] do not match the offered sizes [${n}]`)}vx();var ci=new bt("docs-pages"),Bx=864,tr="paged",Ac="infinite",Vx="docs-view";function ad(n){document.cookie=`${Vx}=${n}; Path=/; Max-Age=31536000; SameSite=Lax`}function Ux(n){let e=[],t=n.state.doc,r=null;return t.forEach((i,s)=>{let o=n.nodeDOM(s);if(!o||!o.getBoundingClientRect)return;let l=o.getBoundingClientRect();if(l.height!==0){if(r===null){r=l.top;return}l.bottom-r>Bx&&(e.push(s),r=l.top)}}),e}function fd({getMode:n,pageLabel:e}){return new ye({key:ci,state:{init:()=>({positions:[],deco:re.empty}),apply(t,r,i,s){let o=t.getMeta(ci);if(!o)return{positions:r.positions,deco:r.deco.map(t.mapping,t.doc)};let l=o.positions.map((c,a)=>$e.widget(c,()=>Lx(a+2,e),{side:-1,ignoreSelection:!0}));return{positions:o.positions,deco:re.create(s.doc,l)}}},props:{decorations(t){return n()!==tr?re.empty:ci.getState(t).deco}},view(t){let r=0,i="",s=()=>{if(r=0,n()!==tr){i!==""&&(i="",t.dispatch(t.state.tr.setMeta(ci,{positions:[]})));return}let c=Ux(t),a=c.join(",");a!==i&&(i=a,t.dispatch(t.state.tr.setMeta(ci,{positions:c})))},o=()=>{r||(r=requestAnimationFrame(s))},l=typeof ResizeObserver=="function"?new ResizeObserver(o):null;return l&&l.observe(t.dom),o(),{update:o,destroy(){r&&cancelAnimationFrame(r),l&&l.disconnect()}}}})}function Lx(n,e){let t=document.createElement("div");t.setAttribute("docs-page-gap",""),t.setAttribute("contenteditable","false"),t.setAttribute("aria-hidden","true");let r=document.createElement("span");return r.setAttribute("docs-page-number",""),r.textContent=e?e.replace("{n}",String(n)):String(n),t.appendChild(r),t}var ud=typeof Intl<"u"&&typeof Intl.Segmenter=="function"?new Intl.Segmenter(void 0,{granularity:"word"}):null;function hd(n){if(!n)return 0;if(ud){let t=0;for(let r of ud.segment(n))r.isWordLike&&t++;return t}let e=n.trim().split(/\s+/);return e.length===1&&e[0]===""?0:e.length}function dd(n){let e=[];return n.descendants(t=>{t.isText?e.push(t.text):t.isBlock&&e.length&&e.push(" ")}),e.join("")}function Fx(n){let e=dd(n.doc),{from:t,to:r,empty:i}=n.selection,s=0;n.doc.forEach(l=>{(l.isTextblock||l.type.name.endsWith("_list")||l.type.name==="blockquote")&&s++});let o=i?null:dd(n.doc.cut(t,r));return{words:hd(e),characters:e.length,charactersNoSpaces:e.replace(/\s/g,"").length,paragraphs:s,selection:o===null?null:{words:hd(o),characters:o.length}}}function pd(n,{getView:e}){if(!n||typeof n.showModal!="function")return null;let t={words:n.querySelector("[docs-count-words]"),characters:n.querySelector("[docs-count-characters]"),charactersNoSpaces:n.querySelector("[docs-count-characters-nospaces]"),paragraphs:n.querySelector("[docs-count-paragraphs]"),selection:n.querySelector("[docs-count-selection]"),selectionWords:n.querySelector("[docs-count-selection-words]")};return()=>{let r=e();if(!r)return!1;let i=Fx(r.state);return t.words&&(t.words.textContent=String(i.words)),t.characters&&(t.characters.textContent=String(i.characters)),t.charactersNoSpaces&&(t.charactersNoSpaces.textContent=String(i.charactersNoSpaces)),t.paragraphs&&(t.paragraphs.textContent=String(i.paragraphs)),t.selection&&(t.selection.hidden=i.selection===null),t.selectionWords&&i.selection&&(t.selectionWords.textContent=String(i.selection.words)),n.showModal(),!0}}function Px(n){let e=[];if(!n)return e;for(let t of n.querySelectorAll("[docs-menu]")){let r=t.querySelector("[docs-menu-title]"),i=r?r.textContent.trim():"";for(let s of t.querySelectorAll("[docs-menu-item]")){let o=s.getAttribute("data-docs-shortcut");if(!o)continue;let l=(s.firstChild&&s.firstChild.textContent?s.firstChild.textContent:s.textContent).trim();e.push({group:i,label:l,keys:o})}}return e}function md(n,{menubar:e,extraRows:t}){if(!n||typeof n.showModal!="function")return null;let r=n.querySelector("[docs-shortcuts-body]");return r?()=>{let i=[...Px(e),...t||[]];r.textContent="";let s=null;for(let o of i){if(o.group&&o.group!==s){s=o.group;let f=document.createElement("h3");f.setAttribute("docs-shortcuts-group",""),f.textContent=s,r.appendChild(f)}let l=document.createElement("div");l.setAttribute("docs-shortcuts-row","");let c=document.createElement("span");c.textContent=o.label;let a=document.createElement("kbd");a.textContent=o.keys,l.append(c,a),r.appendChild(l)}return n.showModal(),!0}:null}var gd=()=>{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var zx=/[\uD800-\uDBFF]/,$x=/[\uDC00-\uDFFF]/,qx=(n,e)=>{let t=0,r=0;for(;t<n.length&&t<e.length&&n[t]===e[t];)t++;for(t>0&&zx.test(n[t-1])&&t--;r+t<n.length&&r+t<e.length&&n[n.length-r-1]===e[e.length-r-1];)r++;return r>0&&$x.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},yd=qx;var L=new bt("y-sync"),We=new bt("y-undo"),Tk=new bt("yjs-cursor");var je=(n,e)=>n>>>e|n<<32-e,Jx=n=>je(n,2)^je(n,13)^je(n,22),Wx=n=>je(n,6)^je(n,11)^je(n,25),jx=n=>je(n,7)^je(n,18)^n>>>3,Kx=n=>je(n,17)^je(n,19)^n>>>10,Hx=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Yx=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Oc=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set(Yx),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let u=16;u<64;u++)t[u]=Kx(t[u-2])+t[u-7]+jx(t[u-15])+t[u-16];let r=e[0],i=e[1],s=e[2],o=e[3],l=e[4],c=e[5],a=e[6],f=e[7];for(let u=0,h,d;u<64;u++)h=f+Wx(l)+(l&c^~l&a)+Hx[u]+t[u]>>>0,d=Jx(r)+(r&i^r&s^i&s)>>>0,f=a,a=c,c=l,l=o+h>>>0,o=s,s=i,i=r,r=h+d>>>0;e[0]+=r,e[1]+=i,e[2]+=s,e[3]+=o,e[4]+=l,e[5]+=c,e[6]+=a,e[7]+=f}digest(e){let t=0;for(;t+56<=e.length;){let o=0;for(;o<16&&t+3<e.length;o++)this._W[o]=e[t++]<<24|e[t++]<<16|e[t++]<<8|e[t++];if(t%64!==0){for(this._W.fill(0,o,16);t<e.length;)this._W[o]|=e[t]<<(3-t%4)*8,t++;this._W[o]|=128<<(3-t%4)*8}this._updateHash()}let r=t%64!==0;this._W.fill(0,0,16);let i=0;for(;t<e.length;i++)for(let o=3;o>=0&&t<e.length;o--)this._W[i]|=e[t++]<<o*8;r||(this._W[i-(t%4===0?0:1)]|=128<<(3-t%4)*8),this._W[14]=e.byteLength/536870912,this._W[15]=e.byteLength*8,this._updateHash();let s=new Uint8Array(32);for(let o=0;o<this._H.length;o++)for(let l=0;l<4;l++)s[o*4+l]=this._H[o]>>>(3-l)*8;return s}},xd=n=>new Oc().digest(n);var Xx=n=>{for(let t=6;t<n.length;t++)n[t%6]=n[t%6]^n[t];return n.slice(0,6)},bd=n=>Sa(Xx(xd(Ta(n))));var ai=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!$t(e.ds,n.id),Qx=[{light:"#ecd44433",dark:"#ecd444"}],eb=(n,e,t)=>{if(!n.has(t)){if(n.size<e.length){let r=Ie();n.forEach(i=>r.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,ca(e))}return n.get(t)},_c=(n,{colors:e=Qx,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new Qs(n,s),c=new ye({props:{editable:a=>{let f=L.getState(a);return f.snapshot==null&&f.prevSnapshot==null}},key:L,state:{init:(a,f)=>({type:n,doc:n.doc,binding:l,snapshot:null,prevSnapshot:null,isChangeOrigin:!1,isUndoRedoOperation:!1,addToHistory:!0,colors:e,colorMapping:t,permanentUserData:r}),apply:(a,f)=>{let u=a.getMeta(L);if(u!==void 0){f=Object.assign({},f);for(let h in u)f[h]=u[h]}return f.addToHistory=a.getMeta("addToHistory")!==!1,f.isChangeOrigin=u!==void 0&&!!u.isChangeOrigin,f.isUndoRedoOperation=u!==void 0&&!!u.isChangeOrigin&&!!u.isUndoRedoOperation,l.prosemirrorView!==null&&u!==void 0&&(u.snapshot!=null||u.prevSnapshot!=null)&&vo(0,()=>{l.prosemirrorView!=null&&(u.restore==null?l._renderSnapshot(u.snapshot,u.prevSnapshot,f):(l._renderSnapshot(u.snapshot,u.snapshot,f),delete f.restore,delete f.snapshot,delete f.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),f}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let f=c.getState(a.state);if(f.snapshot==null&&f.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,f.addToHistory===!1&&!f.isChangeOrigin){let u=We.getState(a.state),h=u&&u.undoManager;h&&h.stopCapturing()}l.mux(()=>{f.doc.transact(u=>{u.meta.set("addToHistory",f.addToHistory),l._prosemirrorChanged(a.state.doc)},L)})}},destroy:()=>{l.destroy()}})});return c},tb=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null)if(e.type==="all")n.setSelection(new le(n.doc));else if(e.type==="node"){let r=Zs(t.doc,t.type,e.anchor,t.mapping);n.setSelection(S.create(n.doc,r))}else{let r=Zs(t.doc,t.type,e.anchor,t.mapping),i=Zs(t.doc,t.type,e.head,t.mapping);if(r!==null&&i!==null){let s=N.between(n.doc.resolve(r),n.doc.resolve(i));n.setSelection(s)}}},fi=(n,e)=>({type:e.selection.jsonID,anchor:Ic(e.selection.anchor,n.type,n.mapping),head:Ic(e.selection.head,n.type,n.mapping)}),Qs=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=gd(),this.mapping=t,this.isOMark=new Map,this._observeFunction=this._typeChanged.bind(this),this.doc=e.doc,this.beforeTransactionSelection=null,this.beforeAllTransactions=()=>{this.beforeTransactionSelection===null&&this.prosemirrorView!=null&&(this.beforeTransactionSelection=fi(this,this.prosemirrorView.state))},this.afterAllTransactions=()=>{this.beforeTransactionSelection=null},this._domSelectionInView=null}get _tr(){return this.prosemirrorView.state.tr.setMeta("addToHistory",!1)}_isLocalCursorInView(){return this.prosemirrorView.hasFocus()?(br&&this._domSelectionInView===null&&(vo(0,()=>{this._domSelectionInView=null}),this._domSelectionInView=this._isDomSelectionInView()),this._domSelectionInView):!1}_isDomSelectionInView(){let e=this.prosemirrorView._root.getSelection();if(e==null||e.anchorNode==null)return!1;let t=this.prosemirrorView._root.createRange();t.setStart(e.anchorNode,e.anchorOffset),t.setEnd(e.focusNode,e.focusOffset),t.getClientRects().length===0&&t.startContainer&&t.collapsed&&t.selectNodeContents(t.startContainer);let i=t.getBoundingClientRect(),s=Xe.documentElement;return i.bottom>=0&&i.right>=0&&i.left<=(window.innerWidth||s.clientWidth||0)&&i.top<=(window.innerHeight||s.clientHeight||0)}renderSnapshot(e,t){t||(t=ds(fs(),new Map)),this.prosemirrorView.dispatch(this._tr.setMeta(L,{snapshot:e,prevSnapshot:t}))}unrenderSnapshot(){this.mapping.clear(),this.mux(()=>{let e=this.type.toArray().map(r=>Xs(r,this.prosemirrorView.state.schema,this)).filter(r=>r!==null),t=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(x.from(e),0,0));t.setMeta(L,{snapshot:null,prevSnapshot:null}),this.prosemirrorView.dispatch(t)})}_forceRerender(){this.mapping.clear(),this.mux(()=>{let e=this.beforeTransactionSelection!==null?null:this.prosemirrorView.state.selection,t=this.type.toArray().map(i=>Xs(i,this.prosemirrorView.state.schema,this)).filter(i=>i!==null),r=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(x.from(t),0,0));if(e){let i=Ge(_e(e.anchor,0),r.doc.content.size),s=Ge(_e(e.head,0),r.doc.content.size);r.setSelection(N.create(r.doc,i,s))}this.prosemirrorView.dispatch(r.setMeta(L,{isChangeOrigin:!0,binding:this}))})}_renderSnapshot(e,t,r){let i=this.doc,s=this.type;if(e||(e=ps(this.doc)),e instanceof Uint8Array||t instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&$(),i=new Te({gc:!1}),us(i,t),t=ps(i),us(i,e),e=ps(i),s._item===null){let o=Array.from(this.doc.share.keys()).find(l=>this.doc.share.get(l)===this.type);s=i.getXmlFragment(o)}else{let o=i.store.clients.get(s._item.id.client)??[],l=Ee(o,s._item.id.clock);s=o[l].content.type}this.mapping.clear(),this.mux(()=>{i.transact(o=>{let l=r.permanentUserData;l&&l.dss.forEach(u=>{Ze(o,u,h=>{})});let c=(u,h)=>{let d=u==="added"?l.getUserByClientId(h.client):l.getUserByDeletedId(h);return{user:d,type:u,color:eb(r.colorMapping,r.colors,d)}},a=pl(s,new vn(t.ds,e.sv)).map(u=>!u._item.deleted||ai(u._item,e)||ai(u._item,t)?Xs(u,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,t,c):null).filter(u=>u!==null),f=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(x.from(a),0,0));this.prosemirrorView.dispatch(f.setMeta(L,{isChangeOrigin:!0}))},L)})}_typeChanged(e,t){if(this.prosemirrorView==null)return;let r=L.getState(this.prosemirrorView.state);if(e.length===0||r.snapshot!=null||r.prevSnapshot!=null){this.renderSnapshot(r.snapshot,r.prevSnapshot);return}this.mux(()=>{let i=(l,c)=>this.mapping.delete(c);Ze(t,t.deleteSet,l=>{if(l.constructor===I){let c=l.content.type;c&&this.mapping.delete(c)}}),t.changed.forEach(i),t.changedParentTypes.forEach(i);let s=this.type.toArray().map(l=>Sd(l,this.prosemirrorView.state.schema,this)).filter(l=>l!==null),o=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(x.from(s),0,0));tb(o,this.beforeTransactionSelection,this),o=o.setMeta(L,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Bn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{to(this.doc,this.type,e,this),this.beforeTransactionSelection=fi(this,this.prosemirrorView.state)},L)}initView(e){this.prosemirrorView!=null&&this.destroy(),this.prosemirrorView=e,this.doc.on("beforeAllTransactions",this.beforeAllTransactions),this.doc.on("afterAllTransactions",this.afterAllTransactions),this.type.observeDeep(this._observeFunction)}destroy(){this.prosemirrorView!=null&&(this.prosemirrorView=null,this.type.unobserveDeep(this._observeFunction),this.doc.off("beforeAllTransactions",this.beforeAllTransactions),this.doc.off("afterAllTransactions",this.afterAllTransactions))}},Sd=(n,e,t,r,i,s)=>{let o=t.mapping.get(n);if(o===void 0){if(n instanceof G)return Xs(n,e,t,r,i,s);throw oe()}return o},Xs=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c instanceof G){let a=Sd(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content?.type;a instanceof Qe&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(u=>{a._item.delete(u)}));let f=nb(c,e,t,r,i,s);f!==null&&f.forEach(u=>{u!==null&&o.push(u)})}};r===void 0||i===void 0?n.toArray().forEach(l):pl(n,new vn(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(ai(n._item,r)?ai(n._item,i)||(c.ychange=s?s("added",n._item.id):{type:"added"}):c.ychange=s?s("removed",n._item.id):{type:"removed"});let a=e.node(n.nodeName,c,o);return t.mapping.set(n,a),a}catch{return n.doc.transact(a=>{n._item.delete(a)},L),t.mapping.delete(n),null}},nb=(n,e,t,r,i,s)=>{let o=[],l=n.toDelta(r,i,s);try{for(let c=0;c<l.length;c++){let a=l[c];o.push(e.text(a.insert,cb(a.attributes,e)))}}catch{return n.doc.transact(a=>{n._item.delete(a)},L),null}return o},rb=(n,e)=>{let t=new me,r=n.map(i=>({insert:i.text,attributes:Ed(i.marks,e)}));return t.applyDelta(r),e.mapping.set(t,n),t},ib=(n,e)=>{let t=new G(n.type.name);for(let r in n.attrs){let i=n.attrs[r];i!==null&&r!=="ychange"&&t.setAttribute(r,i)}return t.insert(0,no(n).map(r=>Dc(r,e))),e.mapping.set(t,n),t},Dc=(n,e)=>n instanceof Array?rb(n,e):ib(n,e),wd=n=>typeof n=="object"&&n!==null,Rc=(n,e)=>{let t=Object.keys(n).filter(i=>n[i]!==null),r=t.length===(e==null?0:Object.keys(e).filter(i=>e[i]!==null).length);for(let i=0;i<t.length&&r;i++){let s=t[i],o=n[s],l=e[s];r=s==="ychange"||o===l||wd(o)&&wd(l)&&Rc(o,l)}return r},no=n=>{let e=n.content.content,t=[];for(let r=0;r<e.length;r++){let i=e[r];if(i.isText){let s=[];for(let o=e[r];r<e.length&&o.isText;o=e[++r])s.push(o);r--,t.push(s)}else t.push(i)}return t},Cd=(n,e)=>{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&xo(r.attributes||{}).length===e[i].marks.length&&dt(r.attributes,(s,o)=>{let l=Td(o),c=e[i].marks;return Rc(s,c.find(a=>a.type.name===l)?.attrs)}))},ui=(n,e)=>{if(n instanceof G&&!(e instanceof Array)&&Nc(n,e)){let t=no(e);return n._length===t.length&&Rc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>ui(r,t[i]))}return n instanceof me&&e instanceof Array&&Cd(n,e)},eo=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),kd=(n,e,t)=>{let r=n.toArray(),i=no(e),s=i.length,o=r.length,l=Ge(o,s),c=0,a=0,f=!1;for(;c<l;c++){let u=r[c],h=i[c];if(eo(t.mapping.get(u),h))f=!0;else if(!ui(u,h))break}for(;c+a<l;a++){let u=r[o-a-1],h=i[s-a-1];if(eo(t.mapping.get(u),h))f=!0;else if(!ui(u,h))break}return{equalityFactor:c+a,foundMappedChild:f}},sb=n=>{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof Re?e+=t.content.str:t.content instanceof U&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},ob=(n,e,t)=>{t.mapping.set(n,e);let{nAttrs:r,str:i}=sb(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,Ed(a.marks,t))})),{insert:o,remove:l,index:c}=yd(i,s.map(a=>a.insert).join(""));n.delete(c,l),n.insert(c,o),n.applyDelta(s.map(a=>({retain:a.insert.length,attributes:a.attributes})))},lb=/(.*)(--[a-zA-Z0-9+/=]{8})$/,Td=n=>lb.exec(n)?.[1]??n,cb=(n,e)=>{let t=[];for(let r in n)t.push(e.mark(Td(r),n[r]));return t},Ed=(n,e)=>{let t={};return n.forEach(r=>{if(r.type.name!=="ychange"){let i=Se(e.isOMark,r.type,()=>!r.type.excludes(r.type));t[i?`${r.type.name}--${bd(r.toJSON())}`:r.type.name]=r.attrs}}),t},to=(n,e,t,r)=>{if(e instanceof G&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.mapping.set(e,t),e instanceof G){let u=e.getAttributes(),h=t.attrs;for(let d in h)h[d]!==null?u[d]!==h[d]&&d!=="ychange"&&e.setAttribute(d,h[d]):e.removeAttribute(d);for(let d in u)h[d]===void 0&&e.removeAttribute(d)}let i=no(t),s=i.length,o=e.toArray(),l=o.length,c=Ge(s,l),a=0,f=0;for(;a<c;a++){let u=o[a],h=i[a];if(!eo(r.mapping.get(u),h))if(ui(u,h))r.mapping.set(u,h);else break}for(;f+a<c;f++){let u=o[l-f-1],h=i[s-f-1];if(!eo(r.mapping.get(u),h))if(ui(u,h))r.mapping.set(u,h);else break}n.transact(()=>{for(;l-a-f>0&&s-a-f>0;){let h=o[a],d=i[a],p=o[l-f-1],m=i[s-f-1];if(h instanceof me&&d instanceof Array)Cd(h,d)||ob(h,d,r),a+=1;else{let g=h instanceof G&&Nc(h,d),y=p instanceof G&&Nc(p,m);if(g&&y){let k=kd(h,d,r),w=kd(p,m,r);k.foundMappedChild&&!w.foundMappedChild?y=!1:!k.foundMappedChild&&w.foundMappedChild||k.equalityFactor<w.equalityFactor?g=!1:y=!1}g?(to(n,h,d,r),a+=1):y?(to(n,p,m,r),f+=1):(r.mapping.delete(e.get(a)),e.delete(a,1),e.insert(a,[Dc(d,r)]),a+=1)}}let u=l-a-f;if(l===1&&s===0&&o[0]instanceof me?(r.mapping.delete(o[0]),o[0].delete(0,o[0].length)):u>0&&(e.slice(a,a+u).forEach(h=>r.mapping.delete(h)),e.delete(a,u)),a+f<s){let h=[];for(let d=a;d<s-f;d++)h.push(Dc(i[d],r));e.insert(a,h)}},L)},Nc=(n,e)=>!(e instanceof Array)&&n.nodeName===e.type.name;var Ic=(n,e,t)=>{if(n===0)return hs(e,0,e.length===0?-1:0);let r=e._first===null?null:e._first.content.type;for(;r!==null&&e!==r;){if(r instanceof me){if(r._length>=n)return hs(r,n,e.length===0?-1:0);if(n-=r._length,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{do r=r._item===null?null:r._item.parent,n--;while(r!==e&&r!==null&&r._item!==null&&r._item.next===null);r!==null&&r!==e&&(r=r._item===null?null:r._item.next.content.type)}}else{let i=(t.get(r)||{nodeSize:0}).nodeSize;if(r._first!==null&&n<i)r=r._first.content.type,n--;else{if(n===1&&r._length===0&&i>1)return new Ft(r._item===null?null:r._item.id,r._item===null?Ln(r):null,null);if(n-=i,r._item!==null&&r._item.next!==null)r=r._item.next.content.type;else{if(n===0)return r=r._item===null?r:r._item.parent,new Ft(r._item===null?null:r._item.id,r._item===null?Ln(r):null,null);do r=r._item.parent,n--;while(r!==e&&r._item.next===null);r!==e&&(r=r._item.next.content.type)}}}if(r===null)throw $();if(n===0&&r.constructor!==me&&r!==e)return ab(r._item.parent,r._item)}return hs(e,e._length,e.length===0?-1:0)},ab=(n,e)=>{let t=null,r=null;return n._item===null?r=Ln(n):t=C(n._item.id.client,n._item.id.clock),new Ft(t,r,e.id)},Zs=(n,e,t,r)=>{let i=pf(t,n);if(i===null||i.type!==e&&!Rn(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===me)o=i.index;else if(s._item===null||!s._item.deleted){let l=s._first,c=0;for(;c<s._length&&c<i.index&&l!==null;){if(!l.deleted){let a=l.content.type;c++,a instanceof me?o+=a._length:o+=r.get(a).nodeSize}l=l.right}o+=1}for(;s!==e&&s._item!==null;){let l=s._item.parent;if(l._item===null||!l._item.deleted){o+=1;let c=l._first;for(;c!==null;){let a=c.content.type;if(a===s)break;c.deleted||(a instanceof me?o+=a._length:o+=r.get(a).nodeSize),c=c.right}}s=l}return o-1};var vc=n=>We.getState(n)?.undoManager?.undo()!=null,ro=n=>We.getState(n)?.undoManager?.redo()!=null,Md=(n,e)=>e==null?We.getState(n)?.undoManager?.canUndo():vc(n),Ad=(n,e)=>e==null?We.getState(n)?.undoManager?.canRedo():ro(n),fb=new Set(["paragraph"]),ub=(n,e)=>!(n instanceof I)||!(n.content instanceof Me)||!(n.content.type instanceof Qe||n.content.type instanceof G&&e.has(n.content.type.nodeName))||n.content.type._length===0,Od=({protectedNodes:n=fb,trackedOrigins:e=[],undoManager:t=null}={})=>new ye({key:We,state:{init:(r,i)=>{let s=L.getState(i),o=t||new Bn(s.type,{trackedOrigins:new Set([L].concat(e)),deleteFilter:l=>ub(l,n),captureTransaction:l=>l.meta.get("addToHistory")!==!1});return{undoManager:o,prevSel:null,hasUndoOps:o.undoStack.length>0,hasRedoOps:o.redoStack.length>0}},apply:(r,i,s,o)=>{let l=L.getState(o).binding,c=i.undoManager,a=c.undoStack.length>0,f=c.redoStack.length>0;return l?{undoManager:c,prevSel:fi(l,s),hasUndoOps:a,hasRedoOps:f}:a!==i.hasUndoOps||f!==i.hasRedoOps?Object.assign({},i,{hasUndoOps:c.undoStack.length>0,hasRedoOps:c.redoStack.length>0}):i}},view:r=>{let i=L.getState(r.state),s=We.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,We.getState(r.state).prevSel)}),s.on("stack-item-popped",({stackItem:o})=>{let l=i.binding;l&&(l.beforeTransactionSelection=o.meta.get(l)||l.beforeTransactionSelection)}),{destroy:()=>{s.destroy()}}}});function Dd({post:n,mergeUpdates:e,onStatus:t,debounceMs:r=2e3,setTimeoutFn:i=setTimeout}){let s=[],o=null,l=null,c="ok";function a(p){c==="failed"&&p!=="failed"||(c=p,t&&t(c))}function f(){l||(l=i(u,r))}async function u(){if(l=null,!s.length)return;let p=e(s);s=[],o=p;let m;try{m=await n(p)}catch{o=null,s.unshift(p),a("retrying"),f();return}if(o=null,m.ok){a("ok");return}if(m.status>=400&&m.status<500){a("failed");return}s.unshift(p),a("retrying"),f()}function h(p){s.push(p),!l&&(l=i(u,r))}function d(){let p=[];return o&&p.push(o),s.length&&p.push(e(s)),p.length?p.length===1?p[0]:e(p):null}return{enqueue:h,flush:u,pendingBytes:d,get status(){return c}}}function Nd({attemptResync:n,onDiverged:e,onRecovered:t,backoffMs:r=l=>Math.min(1e3*2**(l-1),3e4),setTimeoutFn:i=setTimeout,clearTimeoutFn:s=clearTimeout,addOnlineListener:o=l=>addEventListener("online",l)}){let l=!1,c=!1,a=0,f=null;function u(){a++,f&&s(f),f=i(h,r(a))}async function h(){if(f&&(s(f),f=null),!(!l||c)){c=!0;try{await n(),l=!1,a=0,t&&t()}catch{u()}finally{c=!1}}}function d(){l||(l=!0,a=0,e&&e()),h()}return o(()=>{l&&h()}),{reportDivergence:d,get diverged(){return l},get resyncing(){return c}}}var Bc={center:"docs-align-center",right:"docs-align-right"},Id=["left","center","right"];function io(n){return Object.prototype.hasOwnProperty.call(Bc,n)?Bc[n]:null}function hb(n){for(let[e,t]of Object.entries(Bc))if(n.includes(t))return e;return null}function _d(n){return{...n,attrs:{...n.attrs||{},align:{default:null}},parseDOM:[{tag:"p",getAttrs:e=>({align:hb(Array.from(e.classList||[]))})}],toDOM:e=>{let t=io(e.attrs.align);return t?["p",{class:t},0]:["p",0]}}}function Rd(n){return(e,t)=>{let{from:r,to:i}=e.selection,s=!1,o=e.tr;return e.doc.nodesBetween(r,i,(l,c)=>{l.type.isTextblock&&(!l.type.spec.attrs||!l.type.spec.attrs.align||(s=!0,t&&o.setNodeMarkup(c,null,{...l.attrs,align:n})))}),s?(t&&t(o),!0):!1}}function vd(n){let e=n.selection.$from.parent,t=e.attrs&&e.attrs.align;return io(t)?t:"left"}function Bd(n){return{...n,parseDOM:[{tag:"br.Apple-interchange-newline",ignore:!0},...n.parseDOM||[]]}}function Vd(n){let e=n.nodes.paragraph,t=n.nodes.hard_break;return r=>{let i=Ud(r.content,e,t);return i===r.content?r:new b(i,r.openStart,r.openEnd)}}function Ud(n,e,t){let r=[],i=!1;return n.forEach(s=>{if(s.type===e&&s.childCount>0&&db(s,t)){for(let l=0;l<s.childCount;l+=1)r.push(e.create(s.attrs));i=!0;return}if(s.isTextblock||s.isLeaf){r.push(s);return}let o=Ud(s.content,e,t);if(o===s.content){r.push(s);return}r.push(s.copy(o)),i=!0}),i?x.fromArray(r):n}function db(n,e){let t=!0;return n.forEach(r=>{r.type!==e&&(t=!1)}),t}function Ld(n,e){if(!n||e.length===0)return{ensureReachable(){},focusStop(){return!1}};let t=()=>e.filter(o=>!o.disabled);function r(o){for(let l of e)l.tabIndex=l===o?0:-1}function i(){let o=t();o.length!==0&&(o.some(l=>l.tabIndex===0)||r(o[0]))}n.addEventListener("keydown",o=>{let l=o.key;if(l!=="ArrowRight"&&l!=="ArrowLeft"&&l!=="Home"&&l!=="End")return;let c=t(),a=c.indexOf(document.activeElement);if(a<0||c.length===0)return;let f;l==="Home"?f=c[0]:l==="End"?f=c[c.length-1]:l==="ArrowRight"?f=c[(a+1)%c.length]:f=c[(a-1+c.length)%c.length],o.preventDefault(),r(f),f.focus()}),n.addEventListener("focusin",o=>{e.includes(o.target)&&r(o.target)}),i();function s(){let o=t();if(o.length===0)return!1;let l=o.find(c=>c.tabIndex===0)||o[0];return r(l),l.focus(),!0}return{ensureReachable:i,focusStop:s}}var an=["sans","serif","mono"],nr="sans",hi=["font_mono","font_sans","font_serif"];function Fd(n){if(an.includes(n))return n===nr?null:"font_"+n}function Pd(n){for(let e of hi)if(n.includes(e))return e.slice(5);return nr}function pb(){let n=hi.map(e=>e.slice(5));if([...n].sort().join()!==[...an].sort().join())throw new Error(`fonts: marks [${n}] do not match the faces [${an}]`);if(!an.includes(nr))throw new Error(`fonts: the default ${JSON.stringify(nr)} is not one of [${an}]`);if(an[0]!==nr)throw new Error(`fonts: the toolbar lists ${JSON.stringify(an[0])} first but the default is ${JSON.stringify(nr)} \u2014 with no JavaScript the control would name a face the text is not in`)}pb();var Uc={align_left:null,align_center:"center",align_right:"right"};function mb(){let n=Object.keys(Uc);for(let r of n){let i=Uc[r],s="align_"+(i===null?"left":i);if(r!==s)throw new Error(`toolbar: ${r} sets the alignment ${JSON.stringify(i)}, which belongs to ${s}`);if(i!==null&&!io(i))throw new Error(`toolbar: ${r} sets ${JSON.stringify(i)}, which align.mjs does not know`)}let e=n.map(r=>r.slice(6)).sort(),t=[...Id].sort();if(e.join()!==t.join())throw new Error(`toolbar: alignment commands [${e}] do not match align.mjs's [${t}]`)}mb();function Vc(n){let e=n.previousElementSibling;return!e||!e.hasAttribute("rst-combo")?null:e.querySelector("input")}function gb(n,e){if(!e)return;let t=n.getAttribute("aria-label");t&&e.setAttribute("aria-label",t)}function yb(n,e){if(!e||document.activeElement===e)return;let t=n.options[n.selectedIndex];e.value=t?t.text:""}function Jd({root:n,schema:e,getView:t,onSync:r}){if(!n)return{plugin:null,commands:zd(e),focusStop:()=>!1};let i=Array.from(n.querySelectorAll("[data-docs-command]")),s=Array.from(n.querySelectorAll("[data-docs-select]")),o=zd(e);for(let f of i)f.addEventListener("mousedown",u=>u.preventDefault()),f.addEventListener("click",()=>{let u=t(),h=o[f.getAttribute("data-docs-command")];!u||!h||(h(u.state,u.dispatch,u),u.focus())});for(let f of s)f.addEventListener("mousedown",u=>u.stopPropagation()),f.addEventListener("change",()=>{let u=t();u&&u.focus()}),f.addEventListener("change",()=>{let u=t();if(!u)return;let h=f.getAttribute("data-docs-select"),d=f.value;if(h==="block"&&di(e,d)(u.state,u.dispatch),h==="font"){let p=Fd(d);p!==void 0&&$d(e,hi,p)(u.state,u.dispatch)}if(h==="size"){let p=ld(d);p!==void 0&&$d(e,Mt,p)(u.state,u.dispatch)}u.focus()});function l(f){let u=f.state;for(let h of i){let d=h.getAttribute("data-docs-command"),p=o[d];if(!p)continue;let m=p(u,null,f);h.disabled=!m;let g=wb(u,e,d);h.setAttribute("aria-pressed",g?"true":"false")}for(let h of s){h.disabled=!1;let d=Vc(h);d&&(d.disabled=!1),gb(h,d);let p=h.getAttribute("data-docs-select");p==="block"&&(h.value=kb(u)),p==="font"&&(h.value=Sb(u,e)),p==="size"&&(h.value=String(cd(Cb(u,e,Mt)))),yb(h,Vc(h))}r&&r(f)}let c=Ld(n,[...i,...s.map(f=>Vc(f)||f)]);return{plugin:new ye({view:f=>(l(f),c.ensureReachable(),{update:u=>{l(u),c.ensureReachable()}})}),commands:o,focusStop:c.focusStop}}function zd(n){let e=n.marks,t=n.nodes;return{undo:Md,redo:Ad,strong:cn(e.strong),em:cn(e.em),code:cn(e.code),bullet_list:qd(t.bullet_list,t.list_item),ordered_list:qd(t.ordered_list,t.list_item),blockquote:bb(t.blockquote),select_all:Sc,clear_formatting:xb,block_paragraph:di(n,"paragraph"),"block_heading-1":di(n,"heading-1"),"block_heading-2":di(n,"heading-2"),"block_heading-3":di(n,"heading-3"),indent:qe(js(t.list_item),er(1)),outdent:qe(li(t.list_item),er(-1)),...Object.fromEntries(Object.entries(Uc).map(([r,i])=>[r,Rd(i)]))}}function xb(n,e){let{from:t,to:r,empty:i}=n.selection;if(i)return!1;if(e){let s=n.tr.removeMark(t,r,null);s.setBlockType(t,r,n.schema.nodes.paragraph),e(s.scrollIntoView())}return!0}function di(n,e){if(e==="paragraph")return Cc(n.nodes.paragraph);let t=Number(e.split("-")[1]);return Number.isInteger(t)?Cc(n.nodes.heading,{level:t}):()=>!1}function $d(n,e,t){return(r,i)=>{let s=e.map(u=>n.marks[u]).filter(Boolean),o=t?n.marks[t]:null;if(t&&!o)return!1;if(!i)return!0;let{from:l,to:c,empty:a}=r.selection;if(a){let u=(r.storedMarks||r.selection.$from.marks()).filter(h=>!s.includes(h.type));return o&&(u=o.create().addToSet(u)),i(r.tr.setStoredMarks(u)),!0}let f=r.tr;for(let u of s)f.removeMark(l,c,u);return o&&f.addMark(l,c,o.create()),i(f),!0}}function qd(n,e){let t=Jh(n),r=li(e);return(i,s,o)=>pi(i,n)?r(i,s,o):t(i,s,o)}function bb(n){let e=ed(n);return(t,r,i)=>pi(t,n)?Xh(t,r,i):e(t,r,i)}function pi(n,e){let t=n.selection.$from;for(let r=t.depth;r>0;r--)if(t.node(r).type===e)return!0;return!1}function wb(n,e,t){if(t.startsWith("align_"))return vd(n)===t.slice(6);if(t==="bullet_list")return pi(n,e.nodes.bullet_list);if(t==="ordered_list")return pi(n,e.nodes.ordered_list);if(t==="blockquote")return pi(n,e.nodes.blockquote);let r=e.marks[t];return r?Lc(n,r):!1}function Lc(n,e){let{from:t,$from:r,to:i,empty:s}=n.selection;return s?!!e.isInSet(n.storedMarks||r.marks()):n.doc.rangeHasMark(t,i,e)}function kb(n){let e=n.selection.$from.parent;return e.type.name==="heading"?"heading-"+e.attrs.level:"paragraph"}function Sb(n,e){let t=hi.filter(r=>{let i=e.marks[r];return i&&Lc(n,i)});return Pd(t)}function Cb(n,e,t){let r=[];for(let i of t){let s=e.marks[i];s&&Lc(n,s)&&r.push(i)}return r}var Tb={print:()=>(window.print(),!0)};function Wd(n){return n.querySelector("[docs-menu][open]")}function Pc(n){return Array.from(n.querySelectorAll("[docs-menu-title]"))}function Fc(n){return Array.from(n.querySelectorAll("[docs-menu-item]")).filter(e=>!e.disabled)}function zc(n,e){for(let t of Pc(n))t.tabIndex=t===e?0:-1;e.focus()}function rr(n,e){let t=Wd(n);if(!t)return!1;if(t.open=!1,e){let r=t.querySelector("[docs-menu-title]");r&&zc(n,r)}return!0}function jd(n,{getView:e,commands:t,extraCommands:r}){if(!n)return null;let i=Pc(n);if(!i.length)return null;for(let[c,a]of i.entries())a.tabIndex=c===0?0:-1;let s={...Tb,...r||{}};function o(c,a){let f=s[c];if(f){if(a){let p=a.closest("[docs-menu]");if(p){let m=p.querySelector("[docs-menu-title]");m&&zc(n,m)}}return f()}let u=e();if(!u)return!1;let h=t[c];if(!h)return!1;let d=h(u.state,u.dispatch,u);return u.focus(),d}n.addEventListener("click",c=>{let a=c.target.closest("[docs-menu-item]");if(!(!a||a.disabled)){if(!a.hasAttribute("data-docs-command")){rr(n,!1);return}c.preventDefault(),o(a.getAttribute("data-docs-command"),a),rr(n,!1)}}),n.addEventListener("keydown",c=>{let a=c.target.closest("[docs-menu-title]"),f=c.target.closest("[docs-menu-item]"),u=Wd(n);switch(c.key){case"Escape":rr(n,!0)&&c.preventDefault();return;case"ArrowRight":case"ArrowLeft":{let h=a||u&&u.querySelector("[docs-menu-title]");if(!h)return;c.preventDefault();let d=Pc(n),p=d[(d.indexOf(h)+(c.key==="ArrowRight"?1:-1)+d.length)%d.length],m=!!u;rr(n,!1),m&&(p.closest("[docs-menu]").open=!0),zc(n,p);return}case"ArrowDown":case"ArrowUp":{if(a){c.preventDefault();let h=a.closest("[docs-menu]");h.open=!0;let d=Fc(h);d.length&&d[c.key==="ArrowDown"?0:d.length-1].focus();return}if(f&&u){c.preventDefault();let h=Fc(u),d=h.indexOf(f);if(d<0||!h.length)return;h[(d+(c.key==="ArrowDown"?1:-1)+h.length)%h.length].focus()}return}case"Home":case"End":{if(!f||!u)return;c.preventDefault();let h=Fc(u);h.length&&h[c.key==="Home"?0:h.length-1].focus();return}case"Tab":rr(n,!1)}}),document.addEventListener("click",c=>{n.contains(c.target)||rr(n,!1)},!0);function l(c){for(let a of n.querySelectorAll("[docs-menu-item][data-docs-command]")){if(a.hasAttribute("data-docs-unavailable"))continue;let f=a.getAttribute("data-docs-command");if(s[f]){a.disabled=!1;continue}let u=t[f];a.disabled=!(c&&u&&u(c.state,null,c))}}return{sync:l}}function $c(n,{since:e,raw:t}={}){let r=[];return e!==void 0&&r.push(`since=${e}`),t&&r.push("raw=1"),r.length?`${n}?${r.join("&")}`:n}function Kd({initialSeq:n=0,openStream:e,fetchSince:t,onUpdates:r,onError:i=()=>{},setTimeoutFn:s=setTimeout,clearTimeoutFn:o=clearTimeout,idleMs:l=12e4}){let c=n,a=null,f=null,u=!1,h=!1,d=!1;function p(){f!==null&&o(f),f=s(()=>{f=null,m()},l)}function m(){f!==null&&(o(f),f=null),a&&(a.close(),a=null)}function g(){u||a||(a=e(k=>{p(),k>c&&y()},k=>{m(),i(k)}),p())}async function y(){if(h){d=!0;return}h=!0;try{let k=c,w=await t(k);if(u)return;try{w&&w.bytes&&w.bytes.length&&r(w.bytes)}catch{if(w=await t(k,{raw:!0}),u)return;w&&w.bytes&&w.bytes.length&&r(w.bytes)}w&&typeof w.seq=="number"&&w.seq>c&&(c=w.seq)}catch(k){i(k)}finally{h=!1,d&&!u&&(d=!1,y())}}return{start(){u=!1,g()},stop(){u=!0,m()},noteOwnSeq(k){typeof k!="number"||!Number.isFinite(k)||k===c+1&&(c=k)},noteActivity(){u||(a?p():g())},noteHidden(){m()},get cursor(){return c},get streaming(){return a!==null}}}function so(n,e){return{group:e,excludes:e,parseDOM:[{tag:"span."+n}],toDOM:()=>["span",{class:n},0]}}var Eb=Mt.reduce((n,e)=>n.addToStart(e,so("docs-"+e.replace("_","-"),"fontSize")),Zn.spec.marks).addToStart("font_mono",so("docs-font-mono","fontFamily")).addToStart("font_sans",so("docs-font-sans","fontFamily")).addToStart("font_serif",so("docs-font-serif","fontFamily")),Mb=qh(Zn.spec.nodes.update("paragraph",Mc(_d(Zn.spec.nodes.get("paragraph")),"p")).update("heading",Mc(Zn.spec.nodes.get("heading"),"h1")).update("hard_break",Bd(Zn.spec.nodes.get("hard_break"))),"paragraph block*","block"),Ke=new zn({nodes:Mb,marks:Eb});function Ab(n,e){return e&&e(n.tr.replaceSelectionWith(Ke.nodes.hard_break.create()).scrollIntoView()),!0}var Ob=250;function qc(n,e){if(!e.length)return;let t=kn(e);for(;Ai(t);)hf(t,n,"server")}async function Db(n){let e=n.getAttribute("data-sqid"),t=`/d/${e}/updates`,r=`/d/${e}/stream`,i=document.querySelector("[docs-save-status]"),s=!1,o=null,l=null,c=null,a=null,f=document.querySelector("[docs-canvas]"),u=f&&f.getAttribute("data-view")===tr?tr:Ac,h=f?f.getAttribute("data-page-label"):"";function d(E){u=E,f&&f.setAttribute("data-view",E),ad(E);let _=l;_&&_.dispatch(_.state.tr)}let p=pd(document.querySelector("[docs-wordcount]"),{getView:()=>l}),m=md(document.querySelector("[docs-shortcuts]"),{menubar:document.querySelector("[docs-menubar]"),extraRows:Array.from(document.querySelectorAll("[docs-shortcuts-extra] span")).map(E=>({group:E.closest("[docs-shortcuts-extra]").getAttribute("data-group")||"",label:E.getAttribute("data-label")||"",keys:E.getAttribute("data-keys")||""}))}),g=Jd({root:document.querySelector("[docs-toolbar]"),schema:Ke,getView:()=>l,onSync:E=>{a&&a.sync(E)}});a=jd(document.querySelector("[docs-menubar]"),{getView:()=>l,commands:g.commands,extraCommands:{view_paged:()=>(d(tr),!0),view_infinite:()=>(d(Ac),!0),...p?{word_count:p}:{},...m?{shortcuts:m}:{}}});function y(E){i&&i.setAttribute("data-state",s?"failed":E)}function k(E){return Dd({post:async _=>{let v=await fetch(t,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/octet-stream"},body:_}),Ot=E();if(v.ok&&Ot){let at=Number(v.headers.get("Docs-Seq"));Number.isFinite(at)&&Ot.noteOwnSeq(at)}return v},mergeUpdates:xf,debounceMs:Ob,onStatus:_=>{_==="failed"&&(s=!0,T.reportDivergence()),y(_)}})}function w(E){let _=l;if(!_||E.button!==0||_.dom.contains(E.target))return;let v=_.dom.getBoundingClientRect(),Ot=_.posAtCoords({left:Math.min(Math.max(E.clientX,v.left+1),v.right-1),top:Math.min(Math.max(E.clientY,v.top+1),v.bottom-1)}),at=Ot?Ot.pos:_.state.doc.content.size,gi=M.near(_.state.doc.resolve(at));E.preventDefault(),_.dispatch(_.state.tr.setSelection(gi).scrollIntoView()),_.focus()}function be(E,_){let v=[_c(_),Od(),od(Ke),fd({getMode:()=>u,pageLabel:h}),bc({"Mod-z":vc,"Mod-y":ro,"Mod-Shift-z":ro,"Mod-b":cn(Ke.marks.strong),"Mod-i":cn(Ke.marks.em),"Shift-Enter":Ab,Tab:qe(js(Ke.nodes.list_item),er(1)),"Shift-Tab":qe(li(Ke.nodes.list_item),er(-1)),Backspace:id,Escape:()=>g.focusStop(),Enter:qe(Wh(Ke.nodes.list_item),Tc.Enter)}),bc(Tc)];return g.plugin&&v.push(g.plugin),new ni({mount:E},{state:Rs.create({schema:Ke,plugins:v}),transformPasted:Vd(Ke)})}async function Be(E){let _=$c(t,{raw:E}),v=await fetch(_,{credentials:"same-origin"});if(!v.ok)throw new Error(`load ${_}: ${v.status}`);return{log:new Uint8Array(await v.arrayBuffer()),startSeq:Number(v.headers.get("Docs-Seq"))}}async function At(){let{log:E,startSeq:_}=await Be(!1),v=new Te;try{qc(v,E)}catch{({log:E,startSeq:_}=await Be(!0)),v=new Te,qc(v,E)}let Ot=v.getXmlFragment("prosemirror"),at=null,gi=k(()=>at);v.on("update",(Ve,ir)=>{ir!=="server"&&(T.diverged||gi.enqueue(Ve))}),l&&l.destroy(),o=gi,l=be(n,Ot),c&&c.stop(),at=Kd({initialSeq:Number.isFinite(_)?_:0,openStream:(Ve,ir)=>{let fn=new EventSource(r,{withCredentials:!0});return fn.addEventListener("update",ft=>Ve(Number(ft.data))),fn.addEventListener("error",ft=>ir(ft)),{close:()=>fn.close()}},fetchSince:async(Ve,{raw:ir}={})=>{let fn=$c(t,{since:Ve,raw:ir}),ft=await fetch(fn,{credentials:"same-origin"});if(!ft.ok)throw new Error(`fetch ${fn}: ${ft.status}`);return{bytes:new Uint8Array(await ft.arrayBuffer()),seq:Number(ft.headers.get("Docs-Seq"))}},onUpdates:Ve=>{T.diverged||qc(v,Ve)},onError:Ve=>{console.error("live updates:",Ve)}}),c=at,c.start(),typeof document<"u"&&document.hidden&&c.noteHidden()}let T=Nd({attemptResync:At,onDiverged:()=>y("failed"),onRecovered:()=>y(s?"failed":"ok")});await At(),addEventListener("visibilitychange",()=>{document.hidden?c&&c.noteHidden():c&&c.noteActivity()});for(let E of["pointermove","scroll","keydown","focus"])addEventListener(E,()=>c&&c.noteActivity(),{passive:!0,capture:!0});let B=n.closest("[docs-page]");B&&B.addEventListener("mousedown",w);let J=!1,mi=()=>{J=!0,setTimeout(()=>{J=!1},0)};return document.addEventListener("mousedown",mi,!0),document.addEventListener("touchstart",mi,!0),n.addEventListener("focus",()=>{if(J)return;let E=l;E&&E.dispatch(E.state.tr.scrollIntoView())}),addEventListener("beforeunload",()=>{let E=o&&o.pendingBytes();if(!E)return;let _=new Blob([E],{type:"application/octet-stream"});navigator.sendBeacon(t,_)||(console.error("beforeunload: sendBeacon refused the pending edit, retrying via keepalive fetch"),fetch(t,{method:"POST",credentials:"same-origin",keepalive:!0,headers:{"Content-Type":"application/octet-stream"},body:E}).catch(()=>{}))}),l}var Jc=document.querySelector("[docs-editor]");Jc&&Db(Jc).catch(n=>{Jc.setAttribute("data-editor-failed","1"),console.error(n)});export{Db as mountEditor};