oficina / docs Public

Sans is what a document is set in

Every paragraph nobody has marked is laid out in a different face from
today, on screen and on paper, so every existing document repaginates.
That is the change, not a side effect of it.

The default is now stated in one place with a name — internal/fonts'
Default — and the three restatements of it answer to that one. The PDF
exporter reads the constant rather than naming a face of its own. The
stylesheet cannot read it, being CSS, so
TestPageGeometryMatchesTheStylesheet grew four rows that compare its
font-family declarations against export.FontCSSName, which resolves a
run through styleFor rather than restating its answer: the screen's
default and the exporter's default are now the same face by test, and a
serif-marked run is serif in both.

The toolbar had 'serif' written into two expressions — the value that
means "clear the mark" and the value reported for a run that has none.
Both are fixtures/fonts.mjs's DEFAULT_FONT now, and
TestTheToolbarDefaultFontIsTheDefaultFace holds that literal, and the
order of the rendered options, to internal/fonts. This is the failure
worth naming: a toolbar that disagrees loses nothing and throws nothing,
it just labels sans text "Serif", so choosing serif appears to do
nothing and there is no error afterwards to find.

Page counts did not move: the two tests that assert them come out at 4
and 2 pages either way, measured before and after. Their thresholds
(>= 3, >= 2) are still the honest statement of what each needs — more
than one page, so there is a break to test across — so neither was
touched.

fixtures/browser-drive.mjs now drives serif rather than sans. Driving
sans would have waited for a class the control is correct never to
write, and reported the font control broken.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Paul Campbell pushed by paul@keymail.dev cb1a73e88a5284867def7cb490e204a39dc1c0d7 parent 13c8189
11 files changed, +281 −29
  • fixtures/browser-drive.mjs +11 −4
  • fixtures/fonts.mjs +9 −2
  • fixtures/fonts.test.mjs +6 −6
  • internal/docs/export.go +11 −1
  • internal/docs/export_test.go +98 −0
  • internal/docs/static/{editor.24c1880485a21f1b.js => editor.ef226ffccaced6e5.js} +1 −1
  • internal/docs/views/show.html +19 −3
  • internal/export/pdf.go +39 −1
  • internal/export/pdf_test.go +50 −0
  • internal/export/sample_pdf_test.go +1 −1
  • internal/fonts/fonts.go +36 −10

Intent

Attributed to this commit: 43.1 g CO₂e (5651052 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on worktree-sans, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/fixtures/browser-drive.mjs b/fixtures/browser-drive.mjs
index d5d5750..4ea64d2 100644
--- a/fixtures/browser-drive.mjs
+++ b/fixtures/browser-drive.mjs
@@ -311,15 +311,22 @@ async function run() {
// A font mark, through the select, and the class it must produce —
// the same class core/src/fragment.rs renders server-side.
+ //
+ // Serif, not sans, and that is not interchangeable. Sans is the
+ // default now (fixtures/fonts.mjs's DEFAULT_FONT), and choosing the
+ // default CLEARS the group rather than setting a mark — so a drive
+ // that picked sans would wait for a class the control is correct never
+ // to write, and report the font control broken. Any non-default face
+ // makes the check honest; serif is the one this change made sayable.
await evaluate(
- `(()=>{const s=document.querySelector('[data-docs-select="font"]');s.value='sans';` +
+ `(()=>{const s=document.querySelector('[data-docs-select="font"]');s.value='serif';` +
`s.dispatchEvent(new Event('change',{bubbles:true}));return true})()`,
)
try {
- await settle('the sans face to apply', (html) => html.includes('docs-font-sans'))
- check('the font control applies the sans mark', true)
+ await settle('the serif face to apply', (html) => html.includes('docs-font-serif'))
+ check('the font control applies the serif mark', true)
} catch (err) {
- check('the font control applies the sans mark', false, err.message)
+ check('the font control applies the serif mark', false, err.message)
}
// A heading, through the block select — asserted on the ONE block
diff --git a/fixtures/fonts.mjs b/fixtures/fonts.mjs
index d5cb18f..f2ce3a6 100644
--- a/fixtures/fonts.mjs
+++ b/fixtures/fonts.mjs
@@ -33,10 +33,17 @@
// The faces a person can choose, in the order the toolbar shows them —
// default first, because a <select> shows its first option until
// something sets a value, and with no JavaScript nothing ever does.
-export const FONTS = ['serif', 'sans', 'mono']
+export const FONTS = ['sans', 'serif', 'mono']
// The face an unmarked run is in.
-export const DEFAULT_FONT = 'serif'
+//
+// One line, and moving it changes what most of the text in most
+// documents is set in — on screen, on paper, and in what this control
+// says. It is not a preference expressed here: internal/fonts' Default
+// is the one that governs layout, and internal/docs's
+// TestTheToolbarDefaultFontIsTheDefaultFace fails if this line and that
+// constant name different faces.
+export const DEFAULT_FONT = 'sans'
// Every font mark, including the default's. The default's mark is never
// written by the toolbar, but it is real: a document written before the
diff --git a/fixtures/fonts.test.mjs b/fixtures/fonts.test.mjs
index 3cb63a5..df35dbe 100644
--- a/fixtures/fonts.test.mjs
+++ b/fixtures/fonts.test.mjs
@@ -5,7 +5,7 @@
// is four functions over plain strings, and the toolbar's own reading of
// a selection reduces to fontForMarks once the active marks are known.
//
-// The expectations below are LITERAL — 'serif', 'font_sans' — and not
+// The expectations below are LITERAL — 'sans', 'font_serif' — and not
// derived from DEFAULT_FONT or FONT_MARKS. That is the whole point.
// Asserting fontForMarks([]) === DEFAULT_FONT would pass for any value
// of DEFAULT_FONT, including one that disagrees with the stylesheet, and
@@ -34,19 +34,19 @@ test('the faces are serif, sans and mono', () => {
// The default, written out. If this line and views/show.html's
// [docs-text] rule disagree, the font control names a face the text is
// not in and nothing else goes wrong.
-test('an unmarked run is serif', () => {
- assert.equal(fontForMarks([]), 'serif')
+test('an unmarked run is sans', () => {
+ assert.equal(fontForMarks([]), 'sans')
})
// The default is spelled as the absence of a mark, so choosing it is a
// clear rather than a set. A document only carries a font mark where
// somebody asked for a face other than the one they had.
test('choosing the default clears the mark rather than setting one', () => {
- assert.equal(fontMark('serif'), null)
+ assert.equal(fontMark('sans'), null)
})
test('choosing a non-default face sets that face mark', () => {
- assert.equal(fontMark('sans'), 'font_sans')
+ assert.equal(fontMark('serif'), 'font_serif')
assert.equal(fontMark('mono'), 'font_mono')
})
@@ -70,7 +70,7 @@ test('every font mark reads back as its own face', () => {
// A mark from some other group must not be read as a font.
test('a non-font mark leaves the face at the default', () => {
- assert.equal(fontForMarks(['strong', 'size_lg']), 'serif')
+ assert.equal(fontForMarks(['strong', 'size_lg']), 'sans')
})
// The schema's `excludes` makes this unreachable through the editor and
diff --git a/internal/docs/export.go b/internal/docs/export.go
index 3843e4d..2152a5e 100644
--- a/internal/docs/export.go
+++ b/internal/docs/export.go
@@ -89,9 +89,19 @@ func newToolbarView(r *http.Request) toolbarView {
{"heading-3", rastrillo.T(r, "docs.editor.toolbar.block.heading3")},
},
FontLabel: rastrillo.T(r, "docs.editor.toolbar.font"),
+ // Sans first, for the reason spelled out under Sizes below: a
+ // <select> shows its first option until something sets a value,
+ // and with no JavaScript nothing ever does. This list used to
+ // open with Serif and was right to, because serif was the face
+ // an unmarked run was in; it is sans now (internal/fonts'
+ // Default), and the order had to move with it or the control
+ // would name a face the document is not in. The order is the
+ // same one fixtures/fonts.mjs's FONTS carries, and
+ // TestTheToolbarDefaultFontIsTheDefaultFace holds both to
+ // internal/fonts.
Fonts: []toolbarOption{
- {"serif", rastrillo.T(r, "docs.editor.toolbar.font.serif")},
{"sans", rastrillo.T(r, "docs.editor.toolbar.font.sans")},
+ {"serif", rastrillo.T(r, "docs.editor.toolbar.font.serif")},
{"mono", rastrillo.T(r, "docs.editor.toolbar.font.mono")},
},
SizeLabel: rastrillo.T(r, "docs.editor.toolbar.size"),
diff --git a/internal/docs/export_test.go b/internal/docs/export_test.go
index d98f957..2013886 100644
--- a/internal/docs/export_test.go
+++ b/internal/docs/export_test.go
@@ -230,6 +230,43 @@ func TestPageGeometryMatchesTheStylesheet(t *testing.T) {
}
}
+ // The faces, which the table above cannot see either: it compares
+ // numbers, and a face is a name.
+ //
+ // This is the pairing nothing forced before. The screen's default
+ // family is a literal in a CSS rule and the exporter's is a Go
+ // constant reached through a switch, in two languages, in two
+ // binaries — and a document paginates the same on screen and in its
+ // own PDF only while both measure with the SAME font program. When
+ // they disagree the export does not fail; it just breaks its lines
+ // somewhere else, and the page breaks move with them.
+ //
+ // The want side goes through export.FontCSSName, which resolves a
+ // run through styleFor rather than restating its answer, so this
+ // compares the stylesheet against what the exporter actually does.
+ // The default row (no marks) is the one that matters most: it is
+ // what every paragraph nobody has marked is set in, which is most of
+ // the text in most documents.
+ for _, c := range []struct {
+ what string
+ pattern string
+ want string
+ }{
+ {"default body face", `\[docs-text\]\s*\{[^}]*font-family:\s*"([^"]+)"`, export.FontCSSName()},
+ {"serif mark face", `\.docs-font-serif[^}]*font-family:\s*"([^"]+)"`, export.FontCSSName("font_serif")},
+ {"sans mark face", `\.docs-font-sans[^}]*font-family:\s*"([^"]+)"`, export.FontCSSName("font_sans")},
+ {"mono mark face", `\.docs-font-mono[^}]*font-family:\s*"([^"]+)"`, export.FontCSSName("font_mono")},
+ } {
+ m := regexp.MustCompile(c.pattern).FindStringSubmatch(sheet)
+ if m == nil {
+ t.Errorf("%s: found nothing matching %s in views/show.html — either the rule is missing or the stylesheet was restructured and this test can no longer see what it is checking", c.what, c.pattern)
+ continue
+ }
+ if m[1] != c.want {
+ t.Errorf("%s: the stylesheet names %q, internal/export lays it out in %q", c.what, m[1], c.want)
+ }
+ }
+
// The block-level margins, which the table above cannot see.
//
// internal/export/pdf.go states these three as constants and its
@@ -558,6 +595,67 @@ func TestToolbarOptionValuesMatchTheBundle(t *testing.T) {
}
}
+// The toolbar's idea of the default face has to be the app's.
+//
+// Three separate statements of one decision, in three languages:
+// internal/fonts' Default (which internal/export/pdf.go lays an unmarked
+// run out with, and which TestPageGeometryMatchesTheStylesheet has
+// already tied to views/show.html's [docs-text] rule),
+// fixtures/fonts.mjs's DEFAULT_FONT (which is what the font control
+// READS when a run carries no font mark), and the order of the options
+// this page renders (which is what that control SHOWS when no script
+// ever sets its value).
+//
+// A disagreement between them is the quietest failure in this change.
+// Nothing throws, nothing is lost, no pixel is wrong except the label:
+// the control says "Serif" over text drawn in sans, so a person who
+// wants serif chooses the face the control already claims to be showing
+// and watches nothing happen. There is no error to find afterwards.
+//
+// Go cannot import an ES module, so the JS half is read as source. That
+// makes the pattern load-bearing in the way this file keeps insisting
+// on: if DEFAULT_FONT is renamed or restructured the match fails and
+// this test says so, rather than finding nothing and passing.
+func TestTheToolbarDefaultFontIsTheDefaultFace(t *testing.T) {
+ want := fonts.Default.Key()
+
+ module, err := os.ReadFile("../../fixtures/fonts.mjs")
+ if err != nil {
+ t.Fatal(err)
+ }
+ m := regexp.MustCompile(`export const DEFAULT_FONT = '([a-z]+)'`).FindSubmatch(module)
+ if m == nil {
+ t.Fatal("fixtures/fonts.mjs no longer declares DEFAULT_FONT the way this test reads it — it was restructured and this check can no longer see what it is checking")
+ }
+ if got := string(m[1]); got != want {
+ t.Errorf("the toolbar reads an unmarked run as %q, internal/fonts lays it out in %q", got, want)
+ }
+
+ // And the scriptless case: a <select> shows its first option until
+ // something sets a value, and with no JavaScript nothing ever does.
+ // Listing the default anywhere but first means the control names a
+ // face the document is not in, for every reader without scripting,
+ // permanently.
+ app, err := NewForTest(t)
+ if err != nil {
+ t.Fatalf("NewForTest: %v", err)
+ }
+ doc := exportable(t, app, "toolbar@example.com", "Fonts")
+ body := serve(app, app.TestRequest(t, "toolbar@example.com", http.MethodGet, "/d/"+doc.Sqid, nil)).Body.String()
+
+ block := regexp.MustCompile(`(?s)data-docs-select="font"[^>]*>(.*?)</select>`).FindStringSubmatch(body)
+ if block == nil {
+ t.Fatal("the page renders no font select — the toolbar markup was restructured and this check can no longer see what it is checking")
+ }
+ options := regexp.MustCompile(`<option value="([^"]+)"`).FindAllStringSubmatch(block[1], -1)
+ if len(options) != 3 {
+ t.Fatalf("the font control offers %d faces, the core set has 3", len(options))
+ }
+ if got := options[0][1]; got != want {
+ t.Errorf("the font control shows %q before any script runs, internal/fonts lays an unmarked run out in %q", got, want)
+ }
+}
+
// Every face the stylesheet declares must be a face the app serves,
// and it must actually serve it.
func TestFontFacesAreDeclaredAndServed(t *testing.T) {
diff --git a/internal/docs/static/editor.24c1880485a21f1b.js b/internal/docs/static/editor.ef226ffccaced6e5.js
similarity index 96%
rename from internal/docs/static/editor.24c1880485a21f1b.js
rename to internal/docs/static/editor.ef226ffccaced6e5.js
index 099025d..f8f1220 100644
--- a/internal/docs/static/editor.24c1880485a21f1b.js
+++ b/internal/docs/static/editor.ef226ffccaced6e5.js
@@ -11,4 +11,4 @@ ${t.toString()}`)},ho=class{constructor(e){this.patterns=[],this.$state=e}if(e,t
`);return{dom:c,text:u,slice:e}}function Qf(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",u=>{e=u(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",u=>{l=u(l,n,!0)}),l;let f=n.someProp("clipboardTextParser",u=>u(e,i,r,n));if(f)l=f;else{let u=i.marks(),{schema:d}=n.state,p=Vt.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,u)))})}}else n.someProp("transformPastedHTML",f=>{t=f(t,n)}),o=ny(t),qr&&ry(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let f=+h[3];f>0;f--){let u=o.firstChild;for(;u&&u.nodeType!=1;)u=u.nextSibling;if(!u)break;o=u}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||Or.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(u){return u.nodeName=="BR"&&!u.nextSibling&&u.parentNode&&!Qg.test(u.parentNode.nodeName)?{ignore:!0}:null}})),h)l=iy(Ef(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(ey(l.content,i),!0),l.openStart||l.openEnd){let f=0,u=0;for(let d=l.content.firstChild;f<l.openStart&&!d.type.spec.isolating;f++,d=d.firstChild);for(let d=l.content.lastChild;u<l.openEnd&&!d.type.spec.isolating;u++,d=d.lastChild);l=Ef(l,f,u)}return n.someProp("transformPasted",f=>{l=f(l,n,c)}),l}var Qg=/^(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 ey(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&&tu(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=nu(o[o.length-1],s.length));let h=eu(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return x.from(o)}return n}function eu(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,x.from(n));return n}function tu(n,e,t,r,i){if(i<n.length&&i<e.length&&n[i]==e[i]){let s=tu(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(eu(t,n,i+1))))}}function nu(n,e){if(e==0)return n;let t=n.content.replaceChild(n.childCount-1,nu(n.lastChild,e-1)),r=n.contentMatchAt(n.childCount).fillBefore(x.empty,!0);return n.copy(t.append(r))}function Bl(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=Bl(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 Ef(n,e,t){return e<n.openStart&&(n=new b(Bl(n.content,-1,e,n.openStart,0,n.openEnd),e,n.openEnd)),t<n.openEnd&&(n=new b(Bl(n.content,1,t,n.openEnd,0,0),n.openStart,t)),n}var ru={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 iu(){return document.implementation.createHTMLDocument("title")}var Vr=null;function ty(n){let e=window.trustedTypes;if(!e)return n;if(!Vr){if(Vr=e.defaultPolicy)try{return Vr.createHTML(n)}catch{}Vr=e.createPolicy("ProseMirrorClipboard",{createHTML:t=>t})}return Vr.createHTML(n)}function ny(n){let e=/^(\s*<meta [^>]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=iu(),r=t.body,i=/<([a-z][^>\s]+)/i.exec(n),s;if((s=i&&ru[i[1].toLowerCase()])&&(n=s.map(o=>"<"+o+">").join("")+n+s.map(o=>"</"+o+">").reverse().join("")),r.innerHTML=ty(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 h=r.querySelectorAll(a.selectorText);for(let f=0;f<h.length;f++)h[f].style.cssText+=a.style.cssText}}}return r}function ry(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 iy(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 le={},ce={},sy={touchstart:!0,touchmove:!0},Vl=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 oy(n){for(let e in le){let t=le[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{cy(n,r)&&!Wl(n,r)&&(n.editable||!(r.type in ce))&&t(n,r)},sy[e]?{passive:!0}:void 0)}re&&n.dom.addEventListener("input",()=>null),Ul(n)}function Ze(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function ly(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 Ul(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>Wl(n,r))})}function Wl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function cy(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 ay(n,e){!Wl(n,e)&&le[e.type]&&(n.editable||!(e.type in ce))&&le[e.type](n,e)}ce.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!lu(n)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Xe&&Q&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),Fn&&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,Pt(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Zg(n,t)?t.preventDefault():Ze(n,"key")};ce.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ce.keypress=(n,e)=>{let t=e;if(lu(n)||!t.charCode||t.ctrlKey&&!t.altKey||Oe&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof I)||!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 Jr(n){return{left:n.clientX,top:n.clientY}}function hy(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function Kl(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 jr(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 fy(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&S.isSelectable(r)?(jr(n,new S(t),"pointer"),!0):!1}function uy(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?(jr(n,S.create(n.state.doc,i),"pointer"),!0):!1}function dy(n,e,t,r,i){return Kl(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?uy(n,t):fy(n,t))}function py(n,e,t,r){return Kl(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function my(n,e,t,r){return Kl(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||gy(n,t,r)}function gy(n,e,t){if(t.button!=0)return!1;let r=su(n,e,!0),i=n.state.doc;return r?(jr(n,r,"pointer"),r instanceof I&&i.eq(n.state.doc)&&(n.input.mouseDown=new Ll(n,r)),!0):!1}function su(n,e,t){let r=n.state.doc;if(e==-1)return r.inlineContent?I.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 I.create(r,l+1,l+1+o.content.size);if(t&&S.isSelectable(o))return S.create(r,l)}return null}function Yl(n){return Ss(n)}var ou=Oe?"metaKey":"ctrlKey";le.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=Yl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&hy(t,n.input.lastClick)&&!t[ou]&&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(Jr(t));o&&(s=="singleClick"?n.input.mouseDown=new vl(n,o,t,!!r):(s=="doubleClick"?py:my)(n,o.pos,o.inside,t)?t.preventDefault():Ze(n,"pointer"))};var ks=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}},vl=class extends ks{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[ou],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.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()),Ze(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||Qe(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(Jr(e))),this.updateAllowDefault(e),this.allowDefault||!t?Ze(this.view,"pointer"):dy(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||re&&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)?(jr(this.view,D.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):Ze(this.view,"pointer")}move(e){this.updateAllowDefault(e),Ze(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}},Ll=class extends ks{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(),Ze(this.view,"pointer");let t=this.view.posAtCoords(Jr(e)),r=t&&su(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];jr(this.view,I.create(i,o,l),"pointer")}};le.touchstart=n=>{n.input.lastTouch=Date.now(),Yl(n),Ze(n,"pointer")};le.touchmove=n=>{n.input.lastTouch=Date.now(),Ze(n,"pointer")};le.contextmenu=n=>Yl(n);function lu(n,e){return n.composing?!0:re&&Math.abs(Date.now()-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var yy=Xe?5e3:-1;ce.compositionstart=ce.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$to;if(e.selection instanceof I&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)||Q&&Ff&&xy(n)))n.markCursor=n.state.storedMarks||t.marks(),Ss(n,!0),n.markCursor=null;else if(Ss(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}cu(n,yy)};function xy(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"}ce.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++,cu(n,20))};function cu(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>Ss(n),e))}function au(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=Date.now());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function by(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=gg(e.focusNode,e.focusOffset),r=yg(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 Ss(n,e=!1){if(!(Xe&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),au(n),e||n.docView&&n.docView.dirty){let t=ql(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 wy(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 Lr=ge&&ut<15||Fn&&kg<604;le.copy=ce.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=Lr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=jl(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):wy(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function ky(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function Sy(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?Fr(n,r.value,null,i,e):Fr(n,r.textContent,r.innerHTML,i,e)},50)}function Fr(n,e,t,r,i){let s=Qf(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=ky(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 hu(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," "):""}ce.paste=(n,e)=>{let t=e;if(n.composing&&!Xe)return;let r=Lr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Fr(n,hu(r),r.getData("text/html"),i,t)?t.preventDefault():Sy(n,t)};var Cs=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},Cy=Oe?"altKey":"ctrlKey";function fu(n,e){let t;return n.someProp("dragCopies",r=>{t=t||r(e)}),t!=null?!t:!e[Cy]}le.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(Jr(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 f=n.docView.nearestDesc(t.target,!0);f&&f.node.type.spec.draggable&&f!=n.docView&&(o=S.create(n.state.doc,f.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=jl(n,l);(!t.dataTransfer.files.length||!Q||Lf>120)&&t.dataTransfer.clearData(),t.dataTransfer.setData(Lr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",Lr||t.dataTransfer.setData("text/plain",a),n.dragging=new Cs(h,fu(n,t),o)};le.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ce.dragover=ce.dragenter=(n,e)=>e.preventDefault();ce.drop=(n,e)=>{try{Ty(n,e,n.dragging)}finally{n.dragging=null}};function Ty(n,e,t){if(!e.dataTransfer)return;let r=n.posAtCoords(Jr(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=Qf(n,hu(e.dataTransfer),Lr?null:e.dataTransfer.getData("text/html"),!1,i);let o=!!(t&&fu(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?Kh(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),h=s.openStart==0&&s.openEnd==0&&s.content.childCount==1,f=c.doc;if(h?c.replaceRangeWith(a,a,s.content.firstChild):c.replaceRange(a,a,s),c.doc.eq(f))return;let u=c.doc.resolve(a);if(h&&S.isSelectable(s.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(s.content.firstChild))c.setSelection(new S(u));else{let d=c.mapping.map(l);c.mapping.maps[c.mapping.maps.length-1].forEach((p,m,g,y)=>d=y),c.setSelection(Jl(n,u,c.doc.resolve(d)))}n.focus(),n.dispatch(c.setMeta("uiEvent","drop"))}le.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())&&Qe(n)},20))};le.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)};le.beforeinput=(n,e)=>{if(Xe&&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,Pt(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 ce)le[n]=ce[n];function Pr(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 Ts=class n{constructor(e,t){this.toDOM=e,this.spec=t||jt,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 pt(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&&Pr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},Jt=class n{constructor(e,t){this.attrs=e,this.spec=t||jt}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 pt(s,o,this)}valid(e,t){return t.from<t.to}eq(e){return this==e||e instanceof n&&Pr(this.attrs,e.attrs)&&Pr(this.spec,e.spec)}static is(e){return e.type instanceof n}destroy(){}},Fl=class n{constructor(e,t){this.attrs=e,this.spec=t||jt}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 pt(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&&Pr(this.attrs,e.attrs)&&Pr(this.spec,e.spec)}destroy(){}},pt=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 Ts(t,r))}static inline(e,t,r,i){return new n(e,t,new Jt(r,i))}static node(e,t,r,i){return new n(e,t,new Fl(r,i))}get spec(){return this.type.spec}get inline(){return this.type instanceof Jt}get widget(){return this.type instanceof Ts}},vn=[],jt={},Ae=class n{constructor(e,t){this.local=e.length?e:vn,this.children=t.length?t:vn}static create(e,t){return t.length?Es(t,e,0,jt):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||jt)}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?Oy(this.children,o||[],e,t,r,i,s):o?new n(o.sort(Wt),vn):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,h;if(h=du(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,h,a+1):i.splice(s,0,c,c+l.nodeSize,Es(h,l,a+1,jt)),s+=3}});let o=uu(s?pu(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(Wt):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 h=0,f;h<e.length;h++)(f=e[h])&&f.from>l&&f.to<c&&(e[h]=null,(o||(o=[])).push(f));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 Jt){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;a<h&&(i||(i=[])).push(c.copy(a,h))}}if(i){let l=new n(i.sort(Wt),vn);return r?new Os([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 Hl(this.localsInner(e))}localsInner(e){if(this==ne)return vn;if(e.inlineContent||!this.local.some(Jt.is))return this.local;let t=[];for(let r=0;r<this.local.length;r++)this.local[r].type instanceof Jt||t.push(this.local[r]);return t}forEachSet(e){e(this)}};Ae.empty=new Ae([],[]);Ae.removeOverlap=Hl;var ne=Ae.empty,Os=class n{constructor(e){this.members=e}map(e,t){let r=this.members.map(i=>i.map(e,t,jt));return n.from(r)}forChild(e,t){if(t.isLeaf)return Ae.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?Hl(r?t:t.sort(Wt)):vn}static from(e){switch(e.length){case 0:return ne;case 1:return e[0];default:return new n(e.every(t=>t instanceof Ae)?e:e.reduce((t,r)=>t.concat(r instanceof Ae?r:r.members),[]))}}forEachSet(e){for(let t=0;t<this.members.length;t++)this.members[t].forEachSet(e)}};function Oy(n,e,t,r,i,s,o){let l=n.slice();for(let a=0,h=s;a<t.maps.length;a++){let f=0;t.maps[a].forEach((u,d,p,m)=>{let g=m-p-(d-u);for(let y=0;y<l.length;y+=3){let k=l[y+1];if(k<0||u>k+h-f)continue;let w=l[y]+h-f;d>=w?l[y+1]=u<=w?-2:-1:u>=h&&g&&(l[y]+=g,l[y+1]+=g)}f+=g}),h=t.maps[a].map(h,-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 h=t.map(n[a]+s),f=h-i;if(f<0||f>=r.content.size){c=!0;continue}let u=t.map(n[a+1]+s,-1),d=u-i,{index:p,offset:m}=r.content.findIndex(f),g=r.maybeChild(p);if(g&&m==f&&m+g.nodeSize==d){let y=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);y!=ne?(l[a]=f,l[a+1]=d,l[a+2]=y):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=Ey(l,n,e,t,i,s,o),h=Es(a,r,0,o);e=h.local;for(let f=0;f<l.length;f+=3)l[f+1]<0&&(l.splice(f,3),f-=3);for(let f=0,u=0;f<h.children.length;f+=3){let d=h.children[f];for(;u<l.length&&l[u]<d;)u+=3;l.splice(u,0,h.children[f],h.children[f+1],h.children[f+2])}}return new Ae(e.sort(Wt),l)}function uu(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 pt(i.from+e,i.to+e,i.type))}return t}function Ey(n,e,t,r,i,s,o){function l(c,a){for(let h=0;h<c.local.length;h++){let f=c.local[h].map(r,i,a);f?t.push(f):o.onRemove&&o.onRemove(c.local[h].spec)}for(let h=0;h<c.children.length;h+=3)l(c.children[h+2],c.children[h]+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 du(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 pu(n){let e=[];for(let t=0;t<n.length;t++)n[t]!=null&&e.push(n[t]);return e}function Es(n,e,t,r){let i=[],s=!1;e.forEach((l,c)=>{let a=du(n,l,c+t);if(a){s=!0;let h=Es(a,l,t+c+1,r);h!=ne&&i.push(c,c+l.nodeSize,h)}});let o=uu(s?pu(n):n,-t).sort(Wt);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 Ae(o,i):ne}function Wt(n,e){return n.from-e.from||n.to-e.to}function Hl(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),Df(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),Df(e,i,r.copy(s.from,r.to)));break}}}return e}function Df(n,e,t){for(;e<n.length&&Wt(t,n[e])>0;)e++;n.splice(e,0,t)}function wl(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=ne&&e.push(r)}),n.cursorWrapper&&e.push(Ae.create(n.state.doc,[n.cursorWrapper.deco])),Os.from(e)}var Dy={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},My=ge&&ut<=11,Pl=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}},zl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new Pl,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]);ge&&ut<=11&&r.some(i=>i.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():re&&e.composing&&r.some(i=>i.type=="childList"&&i.target.nodeName=="TR")?(e.input.badSafariComposition=!0,this.flushSoon()):this.flush()}),My&&(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,Dy)),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(wf(this.view)){if(this.suppressingSelectionUpdates)return Qe(this.view);if(ge&&ut<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&Kt(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=Ln(s))t.add(s);for(let s=e.anchorNode;s;s=Ln(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)&&wf(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;h<t.length;h++){let f=this.registerMutation(t[h],c);f&&(s=s<0?f.from:Math.min(f.from,s),o=o<0?f.to:Math.max(f.to,o),f.typeOver&&(l=!0))}if(c.some(h=>h.nodeName=="BR")&&(e.input.lastKeyCode==8||e.input.lastKeyCode==46||Q&&(e.composing||e.input.compositionEndedAt>Date.now()-50)&&t.some(h=>h.type=="childList"&&h.removedNodes.length))){for(let h of c)if(h.nodeName=="BR"&&h.parentNode){let f=h.nextSibling;for(;f&&f.nodeType==1;){if(f.contentEditable=="false"){h.parentNode.removeChild(h);break}f=f.firstChild}}}else if(De&&c.length){let h=c.filter(f=>f.nodeName=="BR");if(h.length==2){let[f,u]=h;f.parentNode&&f.parentNode.parentNode==u.parentNode?u.remove():f.remove()}else{let{focusNode:f}=this.currentSelection;for(let u of h){let d=u.parentNode;d&&d.nodeName=="LI"&&(!f||Iy(e,f)!=d)&&u.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&&Ds(r)&&(a=ql(e))&&a.eq(D.near(e.state.doc.resolve(0),1))?(e.input.lastFocus=0,Qe(e),this.currentSelection.set(r),e.scrollToSelection()):(s>-1||i)&&(s>-1&&(e.docView.markDirty(s,o),Ay(e)),e.input.badSafariComposition&&(e.input.badSafariComposition=!1,_y(e,c)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||Qe(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 h=0;h<e.addedNodes.length;h++){let f=e.addedNodes[h];t.push(f),f.nodeType==3&&(this.lastChangedTextNode=f)}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(ge&&ut<=11&&e.addedNodes.length)for(let h=0;h<e.addedNodes.length;h++){let{previousSibling:f,nextSibling:u}=e.addedNodes[h];(!f||Array.prototype.indexOf.call(e.addedNodes,f)<0)&&(i=f),(!u||Array.prototype.indexOf.call(e.addedNodes,u)<0)&&(s=u)}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})}},Mf=new WeakMap,Af=!1;function Ay(n){if(!Mf.has(n)&&(Mf.set(n,null),["normal","nowrap","pre-line"].indexOf(getComputedStyle(n.dom).whiteSpace)!==-1)){if(n.requiresGeckoHackNode=De,Af)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."),Af=!0}}function Nf(n,e){let t=e.startContainer,r=e.startOffset,i=e.endContainer,s=e.endOffset,o=n.domAtPos(n.state.selection.anchor);return Kt(o.node,o.offset,i,s)&&([t,r,i,s]=[i,s,t,r]),{anchorNode:t,anchorOffset:r,focusNode:i,focusOffset:s}}function Ny(n,e){if(e.getComposedRanges){let i=e.getComposedRanges(n.root)[0];if(i)return Nf(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?Nf(n,t):null}function Iy(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 _y(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 Ry(n,e,t,r){let{node:i,fromOffset:s,toOffset:o,from:l,to:c}=n.docView.parseRange(e,t),a=n.domSelectionRange(),h,f=a.anchorNode;if(f&&n.dom.contains(f.nodeType==1?f:f.parentNode)&&(h=[{node:f,offset:a.anchorOffset}],Ds(a)||h.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 u=n.state.doc,d=n.someProp("domParser")||Or.fromSchema(n.state.schema),p=u.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:h,ruleFromNode:By(r),context:p});if(h&&h[0].pos!=null){let y=h[0].pos,k=h[1]&&h[1].pos;k==null&&(k=y),m={anchor:y+l,head:k+l}}return{doc:g,sel:m,from:l,to:c}}var By=n=>e=>{let t=e.pmViewDesc;if(t)return t.parseRule(n);if(e.nodeName=="BR"&&e.parentNode){if(re&&/^(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||re&&/^(tr|table)$/i.test(e.parentNode.nodeName))return{ignore:!0}}else if(e.nodeName=="IMG"&&e.getAttribute("mark-placeholder"))return{ignore:!0};return null},Vy=/^(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 Uy(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=ql(n,T);if(B&&!n.state.selection.eq(B)){if(Q&&Xe&&n.input.lastKeyCode===13&&Date.now()-100<n.input.lastKeyCodeTime&&n.someProp("handleKeyDown",be=>be(n,Pt(13,"Enter"))))return;let $=n.state.tr.setSelection(B);T=="pointer"?$.setMeta("pointer",!0):T=="key"&&$.scrollIntoView(),s&&$.setMeta("composition",s),n.dispatch($)}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=Ry(n,e,t,i),h=n.state.doc,f=h.slice(a.from,a.to),u,d;n.input.lastKeyCode===8&&Date.now()-100<n.input.lastKeyCodeTime?(u=n.state.selection.to,d="end"):(u=n.state.selection.from,d="start"),n.input.lastKeyCode=null;let p=Fy(f.content,a.doc.content,a.from,u,d);if(p&&n.input.domChangeCount++,(Fn&&n.input.lastIOSEnter>Date.now()-225||Xe)&&i.some(T=>T.nodeType==1&&!Vy.test(T.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",T=>T(n,Pt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof I&&!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=If(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 I&&(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)),ge&&ut<=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=h.resolve(p.start),k=m.sameParent(g)&&m.parent.inlineContent&&y.end()>=p.endA;if((Fn&&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,Pt(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&Ly(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",T=>T(n,Pt(8,"Backspace")))){Xe&&Q&&n.domObserver.suppressSelectionUpdates();return}Q&&p.endB==p.start&&(n.input.lastChromeDelete=Date.now()),Xe&&!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,Pt(13,"Enter"))})},20));let w=p.start,O=p.endA,A=T=>{let B=T||n.state.tr.replace(w,O,a.doc.slice(p.start-a.from,p.endB-a.from));if(a.sel){let $=If(n,B.doc,a.sel);$&&!(Q&&n.composing&&$.empty&&(p.start!=p.endB||n.input.lastChromeDelete<Date.now()-100)&&($.head==w||$.head==B.mapping.map(O)-1)||ge&&$.empty&&$.head==w)&&B.setSelection($)}return s&&B.setMeta("composition",s),B.scrollIntoView()},R;if(k)if(m.pos==g.pos){ge&&ut<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>Qe(n),20));let T=A(n.state.tr.delete(w,O)),B=h.resolve(p.start).marksAcross(h.resolve(p.endA));B&&T.ensureMarks(B),n.dispatch(T)}else if(p.endA==p.endB&&(R=vy(m.parent.content.cut(m.parentOffset,g.parentOffset),y.parent.content.cut(y.parentOffset,p.endA-y.start())))){let T=A(n.state.tr);R.type=="add"?T.addMark(w,O,R.mark):T.removeMark(w,O,R.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=()=>A(n.state.tr.insertText(T,w,O));n.someProp("handleTextInput",$=>$(n,w,O,T,B))||n.dispatch(B())}else n.dispatch(A());else n.dispatch(A())}function If(n,e,t){return Math.max(t.anchor,t.head)>e.content.size?null:Jl(n,e.resolve(t.anchor),e.resolve(t.head))}function vy(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;h<r.length;h++)i=r[h].removeFromSet(i);for(let h=0;h<t.length;h++)s=t[h].removeFromSet(s);if(i.length==1&&s.length==0)l=i[0],o="add",c=h=>h.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;h<e.childCount;h++)a.push(c(e.child(h)));if(x.from(a).eq(n))return{mark:l,type:o}}function Ly(n,e,t,r,i){if(t-e<=i.pos-r.pos||kl(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(kl(s,!0,!0));return!o.parent.isTextblock||o.pos>t||kl(o,!0,!1)<t?!1:r.parent.content.cut(r.parentOffset).eq(o.parent.content)}function kl(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 Fy(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 h=Math.max(0,s-Math.min(c,a));r-=c+h-s}if(c<s&&o<l){let h=r<=s&&r>=c?s-r:0;s-=h,a=s+(a-c),c=s}else if(a<s){let h=r<=s&&r>=a?s-r:0;s-=h,c=s+(c-a),a=s}return{start:s,endA:c,endB:a}}var zr=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 Vl,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(Uf),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=Bf(this),Rf(this),this.nodeViews=Vf(this),this.docView=pf(this.state.doc,_f(this),wl(this),this.dom,this),this.domObserver=new zl(this,(r,i,s,o)=>Uy(this,r,i,s,o)),this.domObserver.start(),oy(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&&Ul(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(Uf),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&&(au(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=Vf(this);zy(d,this.nodeViews)&&(this.nodeViews=d,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Ul(this),this.editable=Bf(this),Rf(this);let c=wl(this),a=_f(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",f=s||!this.docView.matchesNode(e.doc,a,c);(f||!e.selection.eq(i.selection))&&(o=!0);let u=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&Tg(this);if(o){this.domObserver.stop();let d=f&&(ge||Q)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&Py(i.selection,e.selection);if(f){let m=Q?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=by(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=pf(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())&&jg(this)&&p.delaySelUpdate())?Qe(this,d):(Gf(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),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():u&&Og(u)}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&&af(this,t.getBoundingClientRect(),e)}else af(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 Cs(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(ge){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&&Eg(this.dom),Qe(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 Ig(this,e)}coordsAtPos(e,t=1){return Jf(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 Ug(this,t||this.state,e)}pasteHTML(e,t){return Fr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Fr(this,e,null,!0,t||new ClipboardEvent("paste"))}serializeForClipboard(e){return jl(this,e)}destroy(){this.docView&&(ly(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],wl(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,pg())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return ay(this,e)}domSelectionRange(){let e=this.domSelection();return e?re&&this.root.nodeType===11&&bg(this.dom.ownerDocument)==this.dom&&Ny(this,e)||e:{focusNode:null,focusOffset:0,anchorNode:null,anchorOffset:0}}domSelection(){return this.root.getSelection()}};zr.prototype.dispatch=function(n){let e=this._props.dispatchTransaction;e?e.call(this,n):this.updateState(this.state.apply(n))};function _f(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"),[pt.node(0,n.state.doc.content.size,e)]}function Rf(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:pt.widget(n.state.selection.from,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function Bf(n){return!n.someProp("editable",e=>e(n.state)===!1)}function Py(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 Vf(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 zy(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 Uf(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 $y=["p",0],qy=["blockquote",0],Jy=["hr"],jy=["pre",["code",0]],Wy=["br"],Ky={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return $y}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return qy}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return Jy}},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 jy}},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 Wy}}},Yy=["em",0],Hy=["strong",0],Gy=["code",0],Xy={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 Yy}},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 Hy}},code:{code:!0,parseDOM:[{tag:"code"}],toDOM(){return Gy}}},Ms=new An({nodes:Ky,marks:Xy});var Zy=["ol",0],Qy=["ul",0],e0=["li",0],t0={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?Zy:["ol",{start:n.attrs.order},0]}},n0={parseDOM:[{tag:"ul"}],toDOM(){return Qy}},r0={parseDOM:[{tag:"li"}],toDOM(){return e0},defining:!0};function Gl(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 mu(n,e,t){return n.append({ordered_list:Gl(t0,{content:"list_item+",group:t}),bullet_list:Gl(n0,{content:"list_item+",group:t}),list_item:Gl(r0,{content:e})})}function gu(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 i0(l,o,n,e)?(r&&r(l.scrollIntoView()),!0):!1}}function i0(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 Rt(c,c,e.depth),e.endIndex<e.parent.childCount&&(e=new Rt(e.$from,o.resolve(e.$to.end(e.depth)),e.depth)),i=!0}let l=fs(s,t,r,e);return l?(n&&s0(n,e,l,i,t),!0):!1}function s0(n,e,t,r,i){let s=x.empty;for(let h=t.length-1;h>=0;h--)s=x.from(t[h].type.create(t[h].attrs,s));n.step(new X(e.start-(r?2:0),e.end,e.start,e.end,new b(s,0,0),t.length,!0));let o=0;for(let h=0;h<t.length;h++)t[h].type==i&&(o=h+1);let l=t.length-o,c=e.start+t.length-(r?2:0),a=e.parent;for(let h=e.startIndex,f=e.endIndex,u=!0;h<f;h++,u=!1)!u&&Lt(n.doc,c,l)&&(n.split(c,l),c+=2*l),c+=a.child(h).nodeSize;return n}function yu(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?o0(e,t,n,s):l0(e,t,s):!0:!1}}function o0(n,e,t,r){let i=n.tr,s=r.end,o=r.$to.end(r.depth);s<o&&(i.step(new X(s-1,o,s,o,new b(x.from(t.create(null,r.parent.copy())),1,0),1,!0)),r=new Rt(i.doc.resolve(r.$from.pos),i.doc.resolve(o),r.depth));let l=vt(r);if(l==null)return!1;i.lift(r,l);let c=i.doc.resolve(i.mapping.map(s,-1)-1);return _r(i.doc,c.pos)&&c.nodeBefore.type==c.nodeAfter.type&&i.join(c.pos),e(i.scrollIntoView()),!0}function l0(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),h=s.index(-1);if(!a.canReplace(h+(l?0:1),h+1,o.content.append(c?x.empty:x.from(i))))return!1;let f=s.pos,u=f+o.nodeSize;return r.step(new X(f-(l?1:0),u+(c?1:0),f+1,u-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}var et={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:"'"},Ns={48:")",49:"!",50:"@",51:"#",52:"$",53:"%",54:"^",55:"&",56:"*",57:"(",59:":",61:"+",173:"_",186:":",187:"+",188:"<",189:"_",190:">",191:"?",192:"~",219:"{",220:"|",221:"}",222:'"'},c0=typeof navigator<"u"&&/Mac/.test(navigator.platform),a0=typeof navigator<"u"&&/MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);for(z=0;z<10;z++)et[48+z]=et[96+z]=String(z);var z;for(z=1;z<=24;z++)et[z+111]="F"+z;var z;for(z=65;z<=90;z++)et[z]=String.fromCharCode(z+32),Ns[z]=String.fromCharCode(z);var z;for(As in et)Ns.hasOwnProperty(As)||(Ns[As]=et[As]);var As;function xu(n){var e=c0&&n.metaKey&&n.shiftKey&&!n.ctrlKey&&!n.altKey||a0&&n.shiftKey&&n.key&&n.key.length==1||n.key=="Unidentified",t=!e&&n.key||(n.shiftKey?Ns:et)[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 h0=typeof navigator<"u"&&/Mac|iP(hone|[oa]d)/.test(navigator.platform),f0=typeof navigator<"u"&&/Win/.test(navigator.platform);function u0(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))h0?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 d0(n){let e=Object.create(null);for(let t in n)e[u0(t)]=n[t];return e}function Xl(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 Zl(n){return new Le({props:{handleKeyDown:p0(n)}})}function p0(n){let e=d0(n);return function(t,r){let i=xu(r),s,o=e[Xl(i,r)];if(o&&o(t.state,t.dispatch,t))return!0;if(i.length==1&&i!=" "){if(r.shiftKey){let l=e[Xl(i,r,!1)];if(l&&l(t.state,t.dispatch,t))return!0}if((r.altKey||r.metaKey||r.ctrlKey)&&!(f0&&r.ctrlKey&&r.altKey)&&(s=et[r.keyCode])&&s!=i){let l=e[Xl(s,r)];if(l&&l(t.state,t.dispatch,t))return!0}}return!1}}var wu=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function m0(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var g0=(n,e,t)=>{let r=m0(n,t);if(!r)return!1;let i=ku(r);if(!i){let o=r.blockRange(),l=o&&vt(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(Tu(n,i,e,-1))return!0;if(r.parent.content.size==0&&(Pn(s,"end")||S.isSelectable(s)))for(let o=r.depth;;o--){let l=us(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(Pn(s,"end")?D.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 Pn(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 y0=(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=ku(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 ku(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 x0(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset<t.parent.content.size)?null:t}var b0=(n,e,t)=>{let r=x0(n,t);if(!r)return!1;let i=Su(r);if(!i)return!1;let s=i.nodeAfter;if(Tu(n,i,e,1))return!0;if(r.parent.content.size==0&&(Pn(s,"start")||S.isSelectable(s))){let o=us(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(Pn(s,"start")?D.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},w0=(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=Su(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 Su(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 Cu=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&vt(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},k0=(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 ec(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 S0=(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=ec(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(D.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},C0=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof oe||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=ec(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(I.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},T0=(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(Lt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&vt(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function O0(n){return(e,t)=>{if(e.selection instanceof S&&e.selection.node.isBlock){let{$from:d}=e.selection;return!d.parentOffset||!Lt(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 I||e.selection instanceof oe)&&r.deleteSelection();let{$from:i}=r.selection,s=r.steps.length,o=[],l,c,a=!1,h=!1;for(let d=i.depth;;d--)if(i.node(d).isBlock){a=i.end(d)==i.pos+(i.depth-d),h=i.start(d)==i.pos-(i.depth-d),c=ec(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 f=i.pos,u=Lt(r.doc,f,o.length,o);if(u||(o[0]=c?{type:c}:null,u=Lt(r.doc,f,o.length,o)),!u)return!1;if(r.split(f,o.length,o),!a&&h&&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 E0=O0();var D0=(n,e)=>(e&&e(n.tr.setSelection(new oe(n.doc))),!0);function M0(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||_r(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Tu(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&M0(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 X(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&&_r(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&c?null:D.findFrom(e,1),f=h&&h.$from.blockRange(h.$to),u=f&&vt(f);if(u!=null&&u>=e.depth)return t&&t(n.tr.lift(f,u).scrollIntoView()),!0;if(a&&Pn(s,"start",!0)&&Pn(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 X(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 Ou(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(I.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var A0=Ou(-1),N0=Ou(1);function Eu(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&fs(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function tc(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 h=t.doc.resolve(a),f=h.index();i=h.parent.canReplaceWith(f,f+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 I0(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 _0(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 Rn(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.pos<i.pos&&e.push(new Rn(r,i))}return e}function Ht(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:h}=o.selection;if(c&&!a||!I0(o.doc,h,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 f,u=o.tr;i||(h=_0(h)),r?f=!h.some(d=>o.doc.rangeHasMark(d.$from.pos,d.$to.pos,n)):f=!h.every(d=>{let p=!1;return u.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<h.length;d++){let{$from:p,$to:m}=h[d];if(!f)u.removeMark(p.pos,m.pos,n);else{let g=p.pos,y=m.pos,k=p.nodeAfter,w=m.nodeBefore,O=s&&k&&k.isText?/^\s*/.exec(k.text)[0].length:0,A=s&&w&&w.isText?/\s*$/.exec(w.text)[0].length:0;g+O<y&&(g+=O,y-=A),u.addMark(g,y,n.create(e))}}l(u.scrollIntoView())}return!0}}function nc(...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 Ql=nc(wu,g0,y0),bu=nc(wu,b0,w0),tt={Enter:nc(k0,C0,T0,E0),"Mod-Enter":S0,Backspace:Ql,"Mod-Backspace":Ql,"Shift-Backspace":Ql,Delete:bu,"Mod-Delete":bu,"Mod-a":D0},Du={"Ctrl-h":tt.Backspace,"Alt-Backspace":tt["Mod-Backspace"],"Ctrl-d":tt.Delete,"Ctrl-Alt-Backspace":tt["Mod-Delete"],"Alt-Delete":tt["Mod-Delete"],"Alt-d":tt["Mod-Delete"],"Ctrl-a":A0,"Ctrl-e":N0};for(let n in tt)Du[n]=tt[n];var R0=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,Mu=R0?Du:tt;var Au=()=>{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var B0=/[\uD800-\uDBFF]/,V0=/[\uDC00-\uDFFF]/,U0=(n,e)=>{let t=0,r=0;for(;t<n.length&&t<e.length&&n[t]===e[t];)t++;for(t>0&&B0.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&&V0.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Nu=U0;var L=new Bn("y-sync"),Pe=new Bn("y-undo"),Hb=new Bn("yjs-cursor");var ze=(n,e)=>n>>>e|n<<32-e,v0=n=>ze(n,2)^ze(n,13)^ze(n,22),L0=n=>ze(n,6)^ze(n,11)^ze(n,25),F0=n=>ze(n,7)^ze(n,18)^n>>>3,P0=n=>ze(n,17)^ze(n,19)^n>>>10,z0=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]),$0=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),rc=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set($0),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let f=16;f<64;f++)t[f]=P0(t[f-2])+t[f-7]+F0(t[f-15])+t[f-16];let r=e[0],i=e[1],s=e[2],o=e[3],l=e[4],c=e[5],a=e[6],h=e[7];for(let f=0,u,d;f<64;f++)u=h+L0(l)+(l&c^~l&a)+z0[f]+t[f]>>>0,d=v0(r)+(r&i^r&s^i&s)>>>0,h=a,a=c,c=l,l=o+u>>>0,o=s,s=i,i=r,r=u+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]+=h}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}},Iu=n=>new rc().digest(n);var J0=n=>{for(let t=6;t<n.length;t++)n[t%6]=n[t%6]^n[t];return n.slice(0,6)},_u=n=>Yc(J0(Iu(Gc(n))));var Wr=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!Nt(e.ds,n.id),W0=[{light:"#ecd44433",dark:"#ecd444"}],K0=(n,e,t)=>{if(!n.has(t)){if(n.size<e.length){let r=Ne();n.forEach(i=>r.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,Bc(e))}return n.get(t)},lc=(n,{colors:e=W0,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new Rs(n,s),c=new Le({props:{editable:a=>{let h=L.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:L,state:{init:(a,h)=>({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,h)=>{let f=a.getMeta(L);if(f!==void 0){h=Object.assign({},h);for(let u in f)h[u]=f[u]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=f!==void 0&&!!f.isChangeOrigin,h.isUndoRedoOperation=f!==void 0&&!!f.isChangeOrigin&&!!f.isUndoRedoOperation,l.prosemirrorView!==null&&f!==void 0&&(f.snapshot!=null||f.prevSnapshot!=null)&&uo(0,()=>{l.prosemirrorView!=null&&(f.restore==null?l._renderSnapshot(f.snapshot,f.prevSnapshot,h):(l._renderSnapshot(f.snapshot,f.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){let f=Pe.getState(a.state),u=f&&f.undoManager;u&&u.stopCapturing()}l.mux(()=>{h.doc.transact(f=>{f.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},L)})}},destroy:()=>{l.destroy()}})});return c},Y0=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null)if(e.type==="all")n.setSelection(new oe(n.doc));else if(e.type==="node"){let r=_s(t.doc,t.type,e.anchor,t.mapping);n.setSelection(S.create(n.doc,r))}else{let r=_s(t.doc,t.type,e.anchor,t.mapping),i=_s(t.doc,t.type,e.head,t.mapping);if(r!==null&&i!==null){let s=I.between(n.doc.resolve(r),n.doc.resolve(i));n.setSelection(s)}}},Kr=(n,e)=>({type:e.selection.jsonID,anchor:oc(e.selection.anchor,n.type,n.mapping),head:oc(e.selection.head,n.type,n.mapping)}),Rs=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Au(),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=Kr(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()?(rr&&this._domSelectionInView===null&&(uo(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=je.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=Ki(Ji(),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=>Is(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=>Is(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=Je(Ie(e.anchor,0),r.doc.content.size),s=Je(Ie(e.head,0),r.doc.content.size);r.setSelection(I.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=Yi(this.doc)),e instanceof Uint8Array||t instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&q(),i=new Se({gc:!1}),ji(i,t),t=Yi(i),ji(i,e),e=Yi(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=Ce(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(f=>{We(o,f,u=>{})});let c=(f,u)=>{let d=f==="added"?l.getUserByClientId(u.client):l.getUserByDeletedId(u);return{user:d,type:f,color:K0(r.colorMapping,r.colors,d)}},a=Ko(s,new Sn(t.ds,e.sv)).map(f=>!f._item.deleted||Wr(f._item,e)||Wr(f._item,t)?Is(f,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,t,c):null).filter(f=>f!==null),h=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(x.from(a),0,0));this.prosemirrorView.dispatch(h.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);We(t,t.deleteSet,l=>{if(l.constructor===_){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=>Vu(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));Y0(o,this.beforeTransactionSelection,this),o=o.setMeta(L,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Cn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Vs(this.doc,this.type,e,this),this.beforeTransactionSelection=Kr(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))}},Vu=(n,e,t,r,i,s)=>{let o=t.mapping.get(n);if(o===void 0){if(n instanceof H)return Is(n,e,t,r,i,s);throw se()}return o},Is=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c instanceof H){let a=Vu(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content?.type;a instanceof Ke&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(f=>{a._item.delete(f)}));let h=H0(c,e,t,r,i,s);h!==null&&h.forEach(f=>{f!==null&&o.push(f)})}};r===void 0||i===void 0?n.toArray().forEach(l):Ko(n,new Sn(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Wr(n._item,r)?Wr(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}},H0=(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,tx(a.attributes,e)))}}catch{return n.doc.transact(a=>{n._item.delete(a)},L),null}return o},G0=(n,e)=>{let t=new pe,r=n.map(i=>({insert:i.text,attributes:Lu(i.marks,e)}));return t.applyDelta(r),e.mapping.set(t,n),t},X0=(n,e)=>{let t=new H(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,Us(n).map(r=>ic(r,e))),e.mapping.set(t,n),t},ic=(n,e)=>n instanceof Array?G0(n,e):X0(n,e),Ru=n=>typeof n=="object"&&n!==null,cc=(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||Ru(o)&&Ru(l)&&cc(o,l)}return r},Us=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},Uu=(n,e)=>{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Gs(r.attributes||{}).length===e[i].marks.length&&st(r.attributes,(s,o)=>{let l=vu(o),c=e[i].marks;return cc(s,c.find(a=>a.type.name===l)?.attrs)}))},Yr=(n,e)=>{if(n instanceof H&&!(e instanceof Array)&&sc(n,e)){let t=Us(e);return n._length===t.length&&cc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Yr(r,t[i]))}return n instanceof pe&&e instanceof Array&&Uu(n,e)},Bs=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),Bu=(n,e,t)=>{let r=n.toArray(),i=Us(e),s=i.length,o=r.length,l=Je(o,s),c=0,a=0,h=!1;for(;c<l;c++){let f=r[c],u=i[c];if(Bs(t.mapping.get(f),u))h=!0;else if(!Yr(f,u))break}for(;c+a<l;a++){let f=r[o-a-1],u=i[s-a-1];if(Bs(t.mapping.get(f),u))h=!0;else if(!Yr(f,u))break}return{equalityFactor:c+a,foundMappedChild:h}},Z0=n=>{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof _e?e+=t.content.str:t.content instanceof v&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},Q0=(n,e,t)=>{t.mapping.set(n,e);let{nAttrs:r,str:i}=Z0(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,Lu(a.marks,t))})),{insert:o,remove:l,index:c}=Nu(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})))},ex=/(.*)(--[a-zA-Z0-9+/=]{8})$/,vu=n=>ex.exec(n)?.[1]??n,tx=(n,e)=>{let t=[];for(let r in n)t.push(e.mark(vu(r),n[r]));return t},Lu=(n,e)=>{let t={};return n.forEach(r=>{if(r.type.name!=="ychange"){let i=we(e.isOMark,r.type,()=>!r.type.excludes(r.type));t[i?`${r.type.name}--${_u(r.toJSON())}`:r.type.name]=r.attrs}}),t},Vs=(n,e,t,r)=>{if(e instanceof H&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.mapping.set(e,t),e instanceof H){let f=e.getAttributes(),u=t.attrs;for(let d in u)u[d]!==null?f[d]!==u[d]&&d!=="ychange"&&e.setAttribute(d,u[d]):e.removeAttribute(d);for(let d in f)u[d]===void 0&&e.removeAttribute(d)}let i=Us(t),s=i.length,o=e.toArray(),l=o.length,c=Je(s,l),a=0,h=0;for(;a<c;a++){let f=o[a],u=i[a];if(!Bs(r.mapping.get(f),u))if(Yr(f,u))r.mapping.set(f,u);else break}for(;h+a<c;h++){let f=o[l-h-1],u=i[s-h-1];if(!Bs(r.mapping.get(f),u))if(Yr(f,u))r.mapping.set(f,u);else break}n.transact(()=>{for(;l-a-h>0&&s-a-h>0;){let u=o[a],d=i[a],p=o[l-h-1],m=i[s-h-1];if(u instanceof pe&&d instanceof Array)Uu(u,d)||Q0(u,d,r),a+=1;else{let g=u instanceof H&&sc(u,d),y=p instanceof H&&sc(p,m);if(g&&y){let k=Bu(u,d,r),w=Bu(p,m,r);k.foundMappedChild&&!w.foundMappedChild?y=!1:!k.foundMappedChild&&w.foundMappedChild||k.equalityFactor<w.equalityFactor?g=!1:y=!1}g?(Vs(n,u,d,r),a+=1):y?(Vs(n,p,m,r),h+=1):(r.mapping.delete(e.get(a)),e.delete(a,1),e.insert(a,[ic(d,r)]),a+=1)}}let f=l-a-h;if(l===1&&s===0&&o[0]instanceof pe?(r.mapping.delete(o[0]),o[0].delete(0,o[0].length)):f>0&&(e.slice(a,a+f).forEach(u=>r.mapping.delete(u)),e.delete(a,f)),a+h<s){let u=[];for(let d=a;d<s-h;d++)u.push(ic(i[d],r));e.insert(a,u)}},L)},sc=(n,e)=>!(e instanceof Array)&&n.nodeName===e.type.name;var oc=(n,e,t)=>{if(n===0)return Wi(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 pe){if(r._length>=n)return Wi(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 Dt(r._item===null?null:r._item.id,r._item===null?En(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 Dt(r._item===null?null:r._item.id,r._item===null?En(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 q();if(n===0&&r.constructor!==pe&&r!==e)return nx(r._item.parent,r._item)}return Wi(e,e._length,e.length===0?-1:0)},nx=(n,e)=>{let t=null,r=null;return n._item===null?r=En(n):t=C(n._item.id.client,n._item.id.clock),new Dt(t,r,e.id)},_s=(n,e,t,r)=>{let i=Fa(t,n);if(i===null||i.type!==e&&!kn(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===pe)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 pe?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 pe?o+=a._length:o+=r.get(a).nodeSize),c=c.right}}s=l}return o-1};var ac=n=>Pe.getState(n)?.undoManager?.undo()!=null,vs=n=>Pe.getState(n)?.undoManager?.redo()!=null,Fu=(n,e)=>e==null?Pe.getState(n)?.undoManager?.canUndo():ac(n),Pu=(n,e)=>e==null?Pe.getState(n)?.undoManager?.canRedo():vs(n),rx=new Set(["paragraph"]),ix=(n,e)=>!(n instanceof _)||!(n.content instanceof Te)||!(n.content.type instanceof Ke||n.content.type instanceof H&&e.has(n.content.type.nodeName))||n.content.type._length===0,zu=({protectedNodes:n=rx,trackedOrigins:e=[],undoManager:t=null}={})=>new Le({key:Pe,state:{init:(r,i)=>{let s=L.getState(i),o=t||new Cn(s.type,{trackedOrigins:new Set([L].concat(e)),deleteFilter:l=>ix(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,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Kr(l,s),hasUndoOps:a,hasRedoOps:h}:a!==i.hasUndoOps||h!==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=Pe.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Pe.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 $u({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 h(){l||(l=i(f,r))}async function f(){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"),h();return}if(o=null,m.ok){a("ok");return}if(m.status>=400&&m.status<500){a("failed");return}s.unshift(p),a("retrying"),h()}function u(p){s.push(p),!l&&(l=i(f,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:u,flush:f,pendingBytes:d,get status(){return c}}}function qu({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,h=null;function f(){a++,h&&s(h),h=i(u,r(a))}async function u(){if(h&&(s(h),h=null),!(!l||c)){c=!0;try{await n(),l=!1,a=0,t&&t()}catch{f()}finally{c=!1}}}function d(){l||(l=!0,a=0,e&&e()),u()}return o(()=>{l&&u()}),{reportDivergence:d,get diverged(){return l},get resyncing(){return c}}}var hc={center:"docs-align-center",right:"docs-align-right"},Ju=["left","center","right"];function Ls(n){return Object.prototype.hasOwnProperty.call(hc,n)?hc[n]:null}function sx(n){for(let[e,t]of Object.entries(hc))if(n.includes(t))return e;return null}function ju(n){return{...n,attrs:{...n.attrs||{},align:{default:null}},parseDOM:[{tag:"p",getAttrs:e=>({align:sx(Array.from(e.classList||[]))})}],toDOM:e=>{let t=Ls(e.attrs.align);return t?["p",{class:t},0]:["p",0]}}}function Wu(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 Ku(n){let e=n.selection.$from.parent,t=e.attrs&&e.attrs.align;return Ls(t)?t:"left"}function Yu(n,e){if(!n||e.length===0)return{ensureReachable(){}};let t=()=>e.filter(s=>!s.disabled);function r(s){for(let o of e)o.tabIndex=o===s?0:-1}function i(){let s=t();s.length!==0&&(s.some(o=>o.tabIndex===0)||r(s[0]))}return n.addEventListener("keydown",s=>{let o=s.key;if(o!=="ArrowRight"&&o!=="ArrowLeft"&&o!=="Home"&&o!=="End")return;let l=t(),c=l.indexOf(document.activeElement);if(c<0||l.length===0)return;let a;o==="Home"?a=l[0]:o==="End"?a=l[l.length-1]:o==="ArrowRight"?a=l[(c+1)%l.length]:a=l[(c-1+l.length)%l.length],s.preventDefault(),r(a),a.focus()}),n.addEventListener("focusin",s=>{e.includes(s.target)&&r(s.target)}),i(),{ensureReachable:i}}var Gt=["serif","sans","mono"],gt="serif",Hr=["font_serif","font_sans","font_mono"];function fc(n){if(Gt.includes(n))return n===gt?null:"font_"+n}function Hu(n){for(let e of Hr)if(n.includes(e))return e.slice(5);return gt}function ox(){let n=Hr.map(e=>e.slice(5));if([...n].sort().join()!==[...Gt].sort().join())throw new Error(`fonts: marks [${n}] do not match the faces [${Gt}]`);if(!Gt.includes(gt))throw new Error(`fonts: the default ${JSON.stringify(gt)} is not one of [${Gt}]`);if(Gt[0]!==gt)throw new Error(`fonts: the toolbar lists ${JSON.stringify(Gt[0])} first but the default is ${JSON.stringify(gt)} \u2014 with no JavaScript the control would name a face the text is not in`);if(fc(gt)!==null)throw new Error(`fonts: the default ${JSON.stringify(gt)} must be spelled as the absence of a mark`)}ox();var Gu=["size_sm","size_lg","size_xl"],uc={align_left:null,align_center:"center",align_right:"right"};function lx(){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&&!Ls(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=[...Ju].sort();if(e.join()!==t.join())throw new Error(`toolbar: alignment commands [${e}] do not match align.mjs's [${t}]`)}lx();function Qu({root:n,schema:e,getView:t}){if(!n)return{plugin:null};let r=Array.from(n.querySelectorAll("[data-docs-command]")),i=Array.from(n.querySelectorAll("[data-docs-select]")),s=cx(e);for(let a of r)a.addEventListener("mousedown",h=>h.preventDefault()),a.addEventListener("click",()=>{let h=t(),f=s[a.getAttribute("data-docs-command")];!h||!f||(f(h.state,h.dispatch,h),h.focus())});for(let a of i)a.addEventListener("mousedown",h=>h.stopPropagation()),a.addEventListener("change",()=>{let h=t();if(!h)return;let f=a.getAttribute("data-docs-select"),u=a.value;if(f==="block"&&ax(e,u)(h.state,h.dispatch),f==="font"){let d=fc(u);d!==void 0&&Xu(e,Hr,d)(h.state,h.dispatch)}f==="size"&&Xu(e,Gu,u==="normal"?null:"size_"+u)(h.state,h.dispatch),h.focus()});function o(a){let h=a.state;for(let f of r){let u=f.getAttribute("data-docs-command"),d=s[u];if(!d)continue;let p=d(h,null,a);f.disabled=!p;let m=fx(h,e,u);f.setAttribute("aria-pressed",m?"true":"false")}for(let f of i){f.disabled=!1;let u=f.getAttribute("data-docs-select");u==="block"&&(f.value=ux(h)),u==="font"&&(f.value=dx(h,e)),u==="size"&&(f.value=px(h,e,Gu,"size_","normal"))}}let l=Yu(n,[...r,...i]);return{plugin:new Le({view:a=>(o(a),l.ensureReachable(),{update:h=>{o(h),l.ensureReachable()}})})}}function cx(n){let e=n.marks,t=n.nodes;return{undo:Fu,redo:Pu,strong:Ht(e.strong),em:Ht(e.em),code:Ht(e.code),bullet_list:Zu(t.bullet_list,t.list_item),ordered_list:Zu(t.ordered_list,t.list_item),blockquote:hx(t.blockquote),...Object.fromEntries(Object.entries(uc).map(([r,i])=>[r,Wu(i)]))}}function ax(n,e){if(e==="paragraph")return tc(n.nodes.paragraph);let t=Number(e.split("-")[1]);return Number.isInteger(t)?tc(n.nodes.heading,{level:t}):()=>!1}function Xu(n,e,t){return(r,i)=>{let s=e.map(f=>n.marks[f]).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 f=(r.storedMarks||r.selection.$from.marks()).filter(u=>!s.includes(u.type));return o&&(f=o.create().addToSet(f)),i(r.tr.setStoredMarks(f)),!0}let h=r.tr;for(let f of s)h.removeMark(l,c,f);return o&&h.addMark(l,c,o.create()),i(h),!0}}function Zu(n,e){let t=gu(n),r=yu(e);return(i,s,o)=>Gr(i,n)?r(i,s,o):t(i,s,o)}function hx(n){let e=Eu(n);return(t,r,i)=>Gr(t,n)?Cu(t,r,i):e(t,r,i)}function Gr(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 fx(n,e,t){if(t.startsWith("align_"))return Ku(n)===t.slice(6);if(t==="bullet_list")return Gr(n,e.nodes.bullet_list);if(t==="ordered_list")return Gr(n,e.nodes.ordered_list);if(t==="blockquote")return Gr(n,e.nodes.blockquote);let r=e.marks[t];return r?dc(n,r):!1}function dc(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 ux(n){let e=n.selection.$from.parent;return e.type.name==="heading"?"heading-"+e.attrs.level:"paragraph"}function dx(n,e){let t=Hr.filter(r=>{let i=e.marks[r];return i&&dc(n,i)});return Hu(t)}function px(n,e,t,r,i){for(let s of t){let o=e.marks[s];if(o&&dc(n,o))return s.slice(r.length)}return i}function pc(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 ed({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,h=null,f=!1,u=!1,d=!1;function p(){h!==null&&o(h),h=s(()=>{h=null,m()},l)}function m(){h!==null&&(o(h),h=null),a&&(a.close(),a=null)}function g(){f||a||(a=e(k=>{p(),k>c&&y()},k=>{m(),i(k)}),p())}async function y(){if(u){d=!0;return}u=!0;try{let k=c,w=await t(k);if(f)return;try{w&&w.bytes&&w.bytes.length&&r(w.bytes)}catch{if(w=await t(k,{raw:!0}),f)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{u=!1,d&&!f&&(d=!1,y())}}return{start(){f=!1,g()},stop(){f=!0,m()},noteOwnSeq(k){typeof k!="number"||!Number.isFinite(k)||k===c+1&&(c=k)},noteActivity(){f||(a?p():g())},noteHidden(){m()},get cursor(){return c},get streaming(){return a!==null}}}function zn(n,e){return{group:e,excludes:e,parseDOM:[{tag:"span."+n}],toDOM:()=>["span",{class:n},0]}}var mx=Ms.spec.marks.addToStart("size_xl",zn("docs-size-xl","fontSize")).addToStart("size_lg",zn("docs-size-lg","fontSize")).addToStart("size_sm",zn("docs-size-sm","fontSize")).addToStart("font_mono",zn("docs-font-mono","fontFamily")).addToStart("font_sans",zn("docs-font-sans","fontFamily")).addToStart("font_serif",zn("docs-font-serif","fontFamily")),gx=mu(Ms.spec.nodes.update("paragraph",ju(Ms.spec.nodes.get("paragraph"))),"paragraph block*","block"),Xr=new An({nodes:gx,marks:mx});function yx(n,e){return e&&e(n.tr.replaceSelectionWith(Xr.nodes.hard_break.create()).scrollIntoView()),!0}var xx=250;function mc(n,e){if(!e.length)return;let t=an(e);for(;ci(t);)va(t,n,"server")}async function bx(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=Qu({root:document.querySelector("[docs-toolbar]"),schema:Xr,getView:()=>l});function h(O){i&&i.setAttribute("data-state",s?"failed":O)}function f(O){return $u({post:async A=>{let R=await fetch(t,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/octet-stream"},body:A}),T=O();if(R.ok&&T){let B=Number(R.headers.get("Docs-Seq"));Number.isFinite(B)&&T.noteOwnSeq(B)}return R},mergeUpdates:qa,debounceMs:xx,onStatus:A=>{A==="failed"&&(s=!0,g.reportDivergence()),h(A)}})}function u(O){let A=l;if(!A||O.button!==0||A.dom.contains(O.target))return;let R=A.dom.getBoundingClientRect(),T=A.posAtCoords({left:Math.min(Math.max(O.clientX,R.left+1),R.right-1),top:Math.min(Math.max(O.clientY,R.top+1),R.bottom-1)}),B=T?T.pos:A.state.doc.content.size,$=D.near(A.state.doc.resolve(B));O.preventDefault(),A.dispatch(A.state.tr.setSelection($).scrollIntoView()),A.focus()}function d(O,A){let R=[lc(A),zu(),Zl({"Mod-z":ac,"Mod-y":vs,"Mod-Shift-z":vs,"Mod-b":Ht(Xr.marks.strong),"Mod-i":Ht(Xr.marks.em),"Shift-Enter":yx}),Zl(Mu)];return a.plugin&&R.push(a.plugin),new zr({mount:O},{state:ms.create({schema:Xr,plugins:R})})}async function p(O){let A=pc(t,{raw:O}),R=await fetch(A,{credentials:"same-origin"});if(!R.ok)throw new Error(`load ${A}: ${R.status}`);return{log:new Uint8Array(await R.arrayBuffer()),startSeq:Number(R.headers.get("Docs-Seq"))}}async function m(){let{log:O,startSeq:A}=await p(!1),R=new Se;try{mc(R,O)}catch{({log:O,startSeq:A}=await p(!0)),R=new Se,mc(R,O)}let T=R.getXmlFragment("prosemirror"),B=null,$=f(()=>B);R.on("update",(be,$n)=>{$n!=="server"&&(g.diverged||$.enqueue(be))}),l&&l.destroy(),o=$,l=d(n,T),c&&c.stop(),B=ed({initialSeq:Number.isFinite(A)?A:0,openStream:(be,$n)=>{let Xt=new EventSource(r,{withCredentials:!0});return Xt.addEventListener("update",nt=>be(Number(nt.data))),Xt.addEventListener("error",nt=>$n(nt)),{close:()=>Xt.close()}},fetchSince:async(be,{raw:$n}={})=>{let Xt=pc(t,{since:be,raw:$n}),nt=await fetch(Xt,{credentials:"same-origin"});if(!nt.ok)throw new Error(`fetch ${Xt}: ${nt.status}`);return{bytes:new Uint8Array(await nt.arrayBuffer()),seq:Number(nt.headers.get("Docs-Seq"))}},onUpdates:be=>{g.diverged||mc(R,be)},onError:be=>{console.error("live updates:",be)}}),c=B,c.start(),typeof document<"u"&&document.hidden&&c.noteHidden()}let g=qu({attemptResync:m,onDiverged:()=>h("failed"),onRecovered:()=>h(s?"failed":"ok")});await m(),addEventListener("visibilitychange",()=>{document.hidden?c&&c.noteHidden():c&&c.noteActivity()});for(let O of["pointermove","scroll","keydown","focus"])addEventListener(O,()=>c&&c.noteActivity(),{passive:!0,capture:!0});let y=n.closest("[docs-page]");y&&y.addEventListener("mousedown",u);let k=!1,w=()=>{k=!0,setTimeout(()=>{k=!1},0)};return document.addEventListener("mousedown",w,!0),document.addEventListener("touchstart",w,!0),n.addEventListener("focus",()=>{if(k)return;let O=l;O&&O.dispatch(O.state.tr.scrollIntoView())}),addEventListener("beforeunload",()=>{let O=o&&o.pendingBytes();if(!O)return;let A=new Blob([O],{type:"application/octet-stream"});navigator.sendBeacon(t,A)||(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:O}).catch(()=>{}))}),l}var gc=document.querySelector("[docs-editor]");gc&&bx(gc).catch(n=>{gc.setAttribute("data-editor-failed","1"),console.error(n)});export{bx as mountEditor};
+`).scrollIntoView()),!0)};function ec(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 S0=(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=ec(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(D.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},C0=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof oe||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=ec(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(I.create(l.doc,o+1)),e(l.scrollIntoView())}return!0},T0=(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(Lt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&vt(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function O0(n){return(e,t)=>{if(e.selection instanceof S&&e.selection.node.isBlock){let{$from:d}=e.selection;return!d.parentOffset||!Lt(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 I||e.selection instanceof oe)&&r.deleteSelection();let{$from:i}=r.selection,s=r.steps.length,o=[],l,c,a=!1,h=!1;for(let d=i.depth;;d--)if(i.node(d).isBlock){a=i.end(d)==i.pos+(i.depth-d),h=i.start(d)==i.pos-(i.depth-d),c=ec(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 f=i.pos,u=Lt(r.doc,f,o.length,o);if(u||(o[0]=c?{type:c}:null,u=Lt(r.doc,f,o.length,o)),!u)return!1;if(r.split(f,o.length,o),!a&&h&&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 E0=O0();var D0=(n,e)=>(e&&e(n.tr.setSelection(new oe(n.doc))),!0);function M0(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||_r(n.doc,e.pos))?!1:(t&&t(n.tr.join(e.pos).scrollIntoView()),!0)}function Tu(n,e,t,r){let i=e.nodeBefore,s=e.nodeAfter,o,l,c=i.type.spec.isolating||s.type.spec.isolating;if(!c&&M0(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 X(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&&_r(m.doc,g.pos)&&m.join(g.pos),t(m.scrollIntoView())}return!0}let h=s.type.spec.isolating||r>0&&c?null:D.findFrom(e,1),f=h&&h.$from.blockRange(h.$to),u=f&&vt(f);if(u!=null&&u>=e.depth)return t&&t(n.tr.lift(f,u).scrollIntoView()),!0;if(a&&Pn(s,"start",!0)&&Pn(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 X(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 Ou(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(I.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var A0=Ou(-1),N0=Ou(1);function Eu(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&fs(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function tc(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 h=t.doc.resolve(a),f=h.index();i=h.parent.canReplaceWith(f,f+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 I0(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 _0(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 Rn(r,r.doc.resolve(o+1))),r=r.doc.resolve(o+1+s.content.size),!1}),r.pos<i.pos&&e.push(new Rn(r,i))}return e}function Ht(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:h}=o.selection;if(c&&!a||!I0(o.doc,h,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 f,u=o.tr;i||(h=_0(h)),r?f=!h.some(d=>o.doc.rangeHasMark(d.$from.pos,d.$to.pos,n)):f=!h.every(d=>{let p=!1;return u.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<h.length;d++){let{$from:p,$to:m}=h[d];if(!f)u.removeMark(p.pos,m.pos,n);else{let g=p.pos,y=m.pos,k=p.nodeAfter,w=m.nodeBefore,O=s&&k&&k.isText?/^\s*/.exec(k.text)[0].length:0,A=s&&w&&w.isText?/\s*$/.exec(w.text)[0].length:0;g+O<y&&(g+=O,y-=A),u.addMark(g,y,n.create(e))}}l(u.scrollIntoView())}return!0}}function nc(...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 Ql=nc(wu,g0,y0),bu=nc(wu,b0,w0),tt={Enter:nc(k0,C0,T0,E0),"Mod-Enter":S0,Backspace:Ql,"Mod-Backspace":Ql,"Shift-Backspace":Ql,Delete:bu,"Mod-Delete":bu,"Mod-a":D0},Du={"Ctrl-h":tt.Backspace,"Alt-Backspace":tt["Mod-Backspace"],"Ctrl-d":tt.Delete,"Ctrl-Alt-Backspace":tt["Mod-Delete"],"Alt-Delete":tt["Mod-Delete"],"Alt-d":tt["Mod-Delete"],"Ctrl-a":A0,"Ctrl-e":N0};for(let n in tt)Du[n]=tt[n];var R0=typeof navigator<"u"?/Mac|iP(hone|[oa]d)/.test(navigator.platform):typeof os<"u"&&os.platform?os.platform()=="darwin":!1,Mu=R0?Du:tt;var Au=()=>{let n=!0;return(e,t)=>{if(n){n=!1;try{e()}finally{n=!0}}else t!==void 0&&t()}};var B0=/[\uD800-\uDBFF]/,V0=/[\uDC00-\uDFFF]/,U0=(n,e)=>{let t=0,r=0;for(;t<n.length&&t<e.length&&n[t]===e[t];)t++;for(t>0&&B0.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&&V0.test(n[n.length-r])&&r--,{index:t,remove:n.length-t-r,insert:e.slice(t,e.length-r)}},Nu=U0;var L=new Bn("y-sync"),Pe=new Bn("y-undo"),Hb=new Bn("yjs-cursor");var ze=(n,e)=>n>>>e|n<<32-e,v0=n=>ze(n,2)^ze(n,13)^ze(n,22),L0=n=>ze(n,6)^ze(n,11)^ze(n,25),F0=n=>ze(n,7)^ze(n,18)^n>>>3,P0=n=>ze(n,17)^ze(n,19)^n>>>10,z0=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]),$0=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),rc=class{constructor(){let e=new ArrayBuffer(320);this._H=new Uint32Array(e,0,8),this._H.set($0),this._W=new Uint32Array(e,64,64)}_updateHash(){let e=this._H,t=this._W;for(let f=16;f<64;f++)t[f]=P0(t[f-2])+t[f-7]+F0(t[f-15])+t[f-16];let r=e[0],i=e[1],s=e[2],o=e[3],l=e[4],c=e[5],a=e[6],h=e[7];for(let f=0,u,d;f<64;f++)u=h+L0(l)+(l&c^~l&a)+z0[f]+t[f]>>>0,d=v0(r)+(r&i^r&s^i&s)>>>0,h=a,a=c,c=l,l=o+u>>>0,o=s,s=i,i=r,r=u+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]+=h}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}},Iu=n=>new rc().digest(n);var J0=n=>{for(let t=6;t<n.length;t++)n[t%6]=n[t%6]^n[t];return n.slice(0,6)},_u=n=>Yc(J0(Iu(Gc(n))));var Wr=(n,e)=>e===void 0?!n.deleted:e.sv.has(n.id.client)&&e.sv.get(n.id.client)>n.id.clock&&!Nt(e.ds,n.id),W0=[{light:"#ecd44433",dark:"#ecd444"}],K0=(n,e,t)=>{if(!n.has(t)){if(n.size<e.length){let r=Ne();n.forEach(i=>r.add(i)),e=e.filter(i=>!r.has(i))}n.set(t,Bc(e))}return n.get(t)},lc=(n,{colors:e=W0,colorMapping:t=new Map,permanentUserData:r=null,onFirstRender:i=()=>{},mapping:s}={})=>{let o=!1,l=new Rs(n,s),c=new Le({props:{editable:a=>{let h=L.getState(a);return h.snapshot==null&&h.prevSnapshot==null}},key:L,state:{init:(a,h)=>({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,h)=>{let f=a.getMeta(L);if(f!==void 0){h=Object.assign({},h);for(let u in f)h[u]=f[u]}return h.addToHistory=a.getMeta("addToHistory")!==!1,h.isChangeOrigin=f!==void 0&&!!f.isChangeOrigin,h.isUndoRedoOperation=f!==void 0&&!!f.isChangeOrigin&&!!f.isUndoRedoOperation,l.prosemirrorView!==null&&f!==void 0&&(f.snapshot!=null||f.prevSnapshot!=null)&&uo(0,()=>{l.prosemirrorView!=null&&(f.restore==null?l._renderSnapshot(f.snapshot,f.prevSnapshot,h):(l._renderSnapshot(f.snapshot,f.snapshot,h),delete h.restore,delete h.snapshot,delete h.prevSnapshot,l.mux(()=>{l._prosemirrorChanged(l.prosemirrorView.state.doc)})))}),h}},view:a=>(l.initView(a),s==null&&l._forceRerender(),i(),{update:()=>{let h=c.getState(a.state);if(h.snapshot==null&&h.prevSnapshot==null&&(o||a.state.doc.content.findDiffStart(a.state.doc.type.createAndFill().content)!==null)){if(o=!0,h.addToHistory===!1&&!h.isChangeOrigin){let f=Pe.getState(a.state),u=f&&f.undoManager;u&&u.stopCapturing()}l.mux(()=>{h.doc.transact(f=>{f.meta.set("addToHistory",h.addToHistory),l._prosemirrorChanged(a.state.doc)},L)})}},destroy:()=>{l.destroy()}})});return c},Y0=(n,e,t)=>{if(e!==null&&e.anchor!==null&&e.head!==null)if(e.type==="all")n.setSelection(new oe(n.doc));else if(e.type==="node"){let r=_s(t.doc,t.type,e.anchor,t.mapping);n.setSelection(S.create(n.doc,r))}else{let r=_s(t.doc,t.type,e.anchor,t.mapping),i=_s(t.doc,t.type,e.head,t.mapping);if(r!==null&&i!==null){let s=I.between(n.doc.resolve(r),n.doc.resolve(i));n.setSelection(s)}}},Kr=(n,e)=>({type:e.selection.jsonID,anchor:oc(e.selection.anchor,n.type,n.mapping),head:oc(e.selection.head,n.type,n.mapping)}),Rs=class{constructor(e,t=new Map){this.type=e,this.prosemirrorView=null,this.mux=Au(),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=Kr(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()?(rr&&this._domSelectionInView===null&&(uo(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=je.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=Ki(Ji(),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=>Is(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=>Is(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=Je(Ie(e.anchor,0),r.doc.content.size),s=Je(Ie(e.head,0),r.doc.content.size);r.setSelection(I.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=Yi(this.doc)),e instanceof Uint8Array||t instanceof Uint8Array)if((!(e instanceof Uint8Array)||!(t instanceof Uint8Array))&&q(),i=new Se({gc:!1}),ji(i,t),t=Yi(i),ji(i,e),e=Yi(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=Ce(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(f=>{We(o,f,u=>{})});let c=(f,u)=>{let d=f==="added"?l.getUserByClientId(u.client):l.getUserByDeletedId(u);return{user:d,type:f,color:K0(r.colorMapping,r.colors,d)}},a=Ko(s,new Sn(t.ds,e.sv)).map(f=>!f._item.deleted||Wr(f._item,e)||Wr(f._item,t)?Is(f,this.prosemirrorView.state.schema,{mapping:new Map,isOMark:new Map},e,t,c):null).filter(f=>f!==null),h=this._tr.replace(0,this.prosemirrorView.state.doc.content.size,new b(x.from(a),0,0));this.prosemirrorView.dispatch(h.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);We(t,t.deleteSet,l=>{if(l.constructor===_){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=>Vu(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));Y0(o,this.beforeTransactionSelection,this),o=o.setMeta(L,{isChangeOrigin:!0,isUndoRedoOperation:t.origin instanceof Cn}),this.beforeTransactionSelection!==null&&this._isLocalCursorInView()&&o.scrollIntoView(),this.prosemirrorView.dispatch(o)})}_prosemirrorChanged(e){this.doc.transact(()=>{Vs(this.doc,this.type,e,this),this.beforeTransactionSelection=Kr(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))}},Vu=(n,e,t,r,i,s)=>{let o=t.mapping.get(n);if(o===void 0){if(n instanceof H)return Is(n,e,t,r,i,s);throw se()}return o},Is=(n,e,t,r,i,s)=>{let o=[],l=c=>{if(c instanceof H){let a=Vu(c,e,t,r,i,s);a!==null&&o.push(a)}else{let a=c._item.right?.content?.type;a instanceof Ke&&!a._item.deleted&&a._item.id.client===a.doc.clientID&&(c.applyDelta([{retain:c.length},...a.toDelta()]),a.doc.transact(f=>{a._item.delete(f)}));let h=H0(c,e,t,r,i,s);h!==null&&h.forEach(f=>{f!==null&&o.push(f)})}};r===void 0||i===void 0?n.toArray().forEach(l):Ko(n,new Sn(i.ds,r.sv)).forEach(l);try{let c=n.getAttributes(r);r!==void 0&&(Wr(n._item,r)?Wr(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}},H0=(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,tx(a.attributes,e)))}}catch{return n.doc.transact(a=>{n._item.delete(a)},L),null}return o},G0=(n,e)=>{let t=new pe,r=n.map(i=>({insert:i.text,attributes:Lu(i.marks,e)}));return t.applyDelta(r),e.mapping.set(t,n),t},X0=(n,e)=>{let t=new H(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,Us(n).map(r=>ic(r,e))),e.mapping.set(t,n),t},ic=(n,e)=>n instanceof Array?G0(n,e):X0(n,e),Ru=n=>typeof n=="object"&&n!==null,cc=(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||Ru(o)&&Ru(l)&&cc(o,l)}return r},Us=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},Uu=(n,e)=>{let t=n.toDelta();return t.length===e.length&&t.every((r,i)=>r.insert===e[i].text&&Gs(r.attributes||{}).length===e[i].marks.length&&st(r.attributes,(s,o)=>{let l=vu(o),c=e[i].marks;return cc(s,c.find(a=>a.type.name===l)?.attrs)}))},Yr=(n,e)=>{if(n instanceof H&&!(e instanceof Array)&&sc(n,e)){let t=Us(e);return n._length===t.length&&cc(n.getAttributes(),e.attrs)&&n.toArray().every((r,i)=>Yr(r,t[i]))}return n instanceof pe&&e instanceof Array&&Uu(n,e)},Bs=(n,e)=>n===e||n instanceof Array&&e instanceof Array&&n.length===e.length&&n.every((t,r)=>e[r]===t),Bu=(n,e,t)=>{let r=n.toArray(),i=Us(e),s=i.length,o=r.length,l=Je(o,s),c=0,a=0,h=!1;for(;c<l;c++){let f=r[c],u=i[c];if(Bs(t.mapping.get(f),u))h=!0;else if(!Yr(f,u))break}for(;c+a<l;a++){let f=r[o-a-1],u=i[s-a-1];if(Bs(t.mapping.get(f),u))h=!0;else if(!Yr(f,u))break}return{equalityFactor:c+a,foundMappedChild:h}},Z0=n=>{let e="",t=n._start,r={};for(;t!==null;)t.deleted||(t.countable&&t.content instanceof _e?e+=t.content.str:t.content instanceof v&&(r[t.content.key]=null)),t=t.right;return{str:e,nAttrs:r}},Q0=(n,e,t)=>{t.mapping.set(n,e);let{nAttrs:r,str:i}=Z0(n),s=e.map(a=>({insert:a.text,attributes:Object.assign({},r,Lu(a.marks,t))})),{insert:o,remove:l,index:c}=Nu(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})))},ex=/(.*)(--[a-zA-Z0-9+/=]{8})$/,vu=n=>ex.exec(n)?.[1]??n,tx=(n,e)=>{let t=[];for(let r in n)t.push(e.mark(vu(r),n[r]));return t},Lu=(n,e)=>{let t={};return n.forEach(r=>{if(r.type.name!=="ychange"){let i=we(e.isOMark,r.type,()=>!r.type.excludes(r.type));t[i?`${r.type.name}--${_u(r.toJSON())}`:r.type.name]=r.attrs}}),t},Vs=(n,e,t,r)=>{if(e instanceof H&&e.nodeName!==t.type.name)throw new Error("node name mismatch!");if(r.mapping.set(e,t),e instanceof H){let f=e.getAttributes(),u=t.attrs;for(let d in u)u[d]!==null?f[d]!==u[d]&&d!=="ychange"&&e.setAttribute(d,u[d]):e.removeAttribute(d);for(let d in f)u[d]===void 0&&e.removeAttribute(d)}let i=Us(t),s=i.length,o=e.toArray(),l=o.length,c=Je(s,l),a=0,h=0;for(;a<c;a++){let f=o[a],u=i[a];if(!Bs(r.mapping.get(f),u))if(Yr(f,u))r.mapping.set(f,u);else break}for(;h+a<c;h++){let f=o[l-h-1],u=i[s-h-1];if(!Bs(r.mapping.get(f),u))if(Yr(f,u))r.mapping.set(f,u);else break}n.transact(()=>{for(;l-a-h>0&&s-a-h>0;){let u=o[a],d=i[a],p=o[l-h-1],m=i[s-h-1];if(u instanceof pe&&d instanceof Array)Uu(u,d)||Q0(u,d,r),a+=1;else{let g=u instanceof H&&sc(u,d),y=p instanceof H&&sc(p,m);if(g&&y){let k=Bu(u,d,r),w=Bu(p,m,r);k.foundMappedChild&&!w.foundMappedChild?y=!1:!k.foundMappedChild&&w.foundMappedChild||k.equalityFactor<w.equalityFactor?g=!1:y=!1}g?(Vs(n,u,d,r),a+=1):y?(Vs(n,p,m,r),h+=1):(r.mapping.delete(e.get(a)),e.delete(a,1),e.insert(a,[ic(d,r)]),a+=1)}}let f=l-a-h;if(l===1&&s===0&&o[0]instanceof pe?(r.mapping.delete(o[0]),o[0].delete(0,o[0].length)):f>0&&(e.slice(a,a+f).forEach(u=>r.mapping.delete(u)),e.delete(a,f)),a+h<s){let u=[];for(let d=a;d<s-h;d++)u.push(ic(i[d],r));e.insert(a,u)}},L)},sc=(n,e)=>!(e instanceof Array)&&n.nodeName===e.type.name;var oc=(n,e,t)=>{if(n===0)return Wi(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 pe){if(r._length>=n)return Wi(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 Dt(r._item===null?null:r._item.id,r._item===null?En(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 Dt(r._item===null?null:r._item.id,r._item===null?En(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 q();if(n===0&&r.constructor!==pe&&r!==e)return nx(r._item.parent,r._item)}return Wi(e,e._length,e.length===0?-1:0)},nx=(n,e)=>{let t=null,r=null;return n._item===null?r=En(n):t=C(n._item.id.client,n._item.id.clock),new Dt(t,r,e.id)},_s=(n,e,t,r)=>{let i=Fa(t,n);if(i===null||i.type!==e&&!kn(e,i.type._item))return null;let s=i.type,o=0;if(s.constructor===pe)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 pe?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 pe?o+=a._length:o+=r.get(a).nodeSize),c=c.right}}s=l}return o-1};var ac=n=>Pe.getState(n)?.undoManager?.undo()!=null,vs=n=>Pe.getState(n)?.undoManager?.redo()!=null,Fu=(n,e)=>e==null?Pe.getState(n)?.undoManager?.canUndo():ac(n),Pu=(n,e)=>e==null?Pe.getState(n)?.undoManager?.canRedo():vs(n),rx=new Set(["paragraph"]),ix=(n,e)=>!(n instanceof _)||!(n.content instanceof Te)||!(n.content.type instanceof Ke||n.content.type instanceof H&&e.has(n.content.type.nodeName))||n.content.type._length===0,zu=({protectedNodes:n=rx,trackedOrigins:e=[],undoManager:t=null}={})=>new Le({key:Pe,state:{init:(r,i)=>{let s=L.getState(i),o=t||new Cn(s.type,{trackedOrigins:new Set([L].concat(e)),deleteFilter:l=>ix(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,h=c.redoStack.length>0;return l?{undoManager:c,prevSel:Kr(l,s),hasUndoOps:a,hasRedoOps:h}:a!==i.hasUndoOps||h!==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=Pe.getState(r.state).undoManager;return s.on("stack-item-added",({stackItem:o})=>{let l=i.binding;l&&o.meta.set(l,Pe.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 $u({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 h(){l||(l=i(f,r))}async function f(){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"),h();return}if(o=null,m.ok){a("ok");return}if(m.status>=400&&m.status<500){a("failed");return}s.unshift(p),a("retrying"),h()}function u(p){s.push(p),!l&&(l=i(f,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:u,flush:f,pendingBytes:d,get status(){return c}}}function qu({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,h=null;function f(){a++,h&&s(h),h=i(u,r(a))}async function u(){if(h&&(s(h),h=null),!(!l||c)){c=!0;try{await n(),l=!1,a=0,t&&t()}catch{f()}finally{c=!1}}}function d(){l||(l=!0,a=0,e&&e()),u()}return o(()=>{l&&u()}),{reportDivergence:d,get diverged(){return l},get resyncing(){return c}}}var hc={center:"docs-align-center",right:"docs-align-right"},Ju=["left","center","right"];function Ls(n){return Object.prototype.hasOwnProperty.call(hc,n)?hc[n]:null}function sx(n){for(let[e,t]of Object.entries(hc))if(n.includes(t))return e;return null}function ju(n){return{...n,attrs:{...n.attrs||{},align:{default:null}},parseDOM:[{tag:"p",getAttrs:e=>({align:sx(Array.from(e.classList||[]))})}],toDOM:e=>{let t=Ls(e.attrs.align);return t?["p",{class:t},0]:["p",0]}}}function Wu(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 Ku(n){let e=n.selection.$from.parent,t=e.attrs&&e.attrs.align;return Ls(t)?t:"left"}function Yu(n,e){if(!n||e.length===0)return{ensureReachable(){}};let t=()=>e.filter(s=>!s.disabled);function r(s){for(let o of e)o.tabIndex=o===s?0:-1}function i(){let s=t();s.length!==0&&(s.some(o=>o.tabIndex===0)||r(s[0]))}return n.addEventListener("keydown",s=>{let o=s.key;if(o!=="ArrowRight"&&o!=="ArrowLeft"&&o!=="Home"&&o!=="End")return;let l=t(),c=l.indexOf(document.activeElement);if(c<0||l.length===0)return;let a;o==="Home"?a=l[0]:o==="End"?a=l[l.length-1]:o==="ArrowRight"?a=l[(c+1)%l.length]:a=l[(c-1+l.length)%l.length],s.preventDefault(),r(a),a.focus()}),n.addEventListener("focusin",s=>{e.includes(s.target)&&r(s.target)}),i(),{ensureReachable:i}}var Gt=["sans","serif","mono"],gt="sans",Hr=["font_serif","font_sans","font_mono"];function fc(n){if(Gt.includes(n))return n===gt?null:"font_"+n}function Hu(n){for(let e of Hr)if(n.includes(e))return e.slice(5);return gt}function ox(){let n=Hr.map(e=>e.slice(5));if([...n].sort().join()!==[...Gt].sort().join())throw new Error(`fonts: marks [${n}] do not match the faces [${Gt}]`);if(!Gt.includes(gt))throw new Error(`fonts: the default ${JSON.stringify(gt)} is not one of [${Gt}]`);if(Gt[0]!==gt)throw new Error(`fonts: the toolbar lists ${JSON.stringify(Gt[0])} first but the default is ${JSON.stringify(gt)} \u2014 with no JavaScript the control would name a face the text is not in`);if(fc(gt)!==null)throw new Error(`fonts: the default ${JSON.stringify(gt)} must be spelled as the absence of a mark`)}ox();var Gu=["size_sm","size_lg","size_xl"],uc={align_left:null,align_center:"center",align_right:"right"};function lx(){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&&!Ls(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=[...Ju].sort();if(e.join()!==t.join())throw new Error(`toolbar: alignment commands [${e}] do not match align.mjs's [${t}]`)}lx();function Qu({root:n,schema:e,getView:t}){if(!n)return{plugin:null};let r=Array.from(n.querySelectorAll("[data-docs-command]")),i=Array.from(n.querySelectorAll("[data-docs-select]")),s=cx(e);for(let a of r)a.addEventListener("mousedown",h=>h.preventDefault()),a.addEventListener("click",()=>{let h=t(),f=s[a.getAttribute("data-docs-command")];!h||!f||(f(h.state,h.dispatch,h),h.focus())});for(let a of i)a.addEventListener("mousedown",h=>h.stopPropagation()),a.addEventListener("change",()=>{let h=t();if(!h)return;let f=a.getAttribute("data-docs-select"),u=a.value;if(f==="block"&&ax(e,u)(h.state,h.dispatch),f==="font"){let d=fc(u);d!==void 0&&Xu(e,Hr,d)(h.state,h.dispatch)}f==="size"&&Xu(e,Gu,u==="normal"?null:"size_"+u)(h.state,h.dispatch),h.focus()});function o(a){let h=a.state;for(let f of r){let u=f.getAttribute("data-docs-command"),d=s[u];if(!d)continue;let p=d(h,null,a);f.disabled=!p;let m=fx(h,e,u);f.setAttribute("aria-pressed",m?"true":"false")}for(let f of i){f.disabled=!1;let u=f.getAttribute("data-docs-select");u==="block"&&(f.value=ux(h)),u==="font"&&(f.value=dx(h,e)),u==="size"&&(f.value=px(h,e,Gu,"size_","normal"))}}let l=Yu(n,[...r,...i]);return{plugin:new Le({view:a=>(o(a),l.ensureReachable(),{update:h=>{o(h),l.ensureReachable()}})})}}function cx(n){let e=n.marks,t=n.nodes;return{undo:Fu,redo:Pu,strong:Ht(e.strong),em:Ht(e.em),code:Ht(e.code),bullet_list:Zu(t.bullet_list,t.list_item),ordered_list:Zu(t.ordered_list,t.list_item),blockquote:hx(t.blockquote),...Object.fromEntries(Object.entries(uc).map(([r,i])=>[r,Wu(i)]))}}function ax(n,e){if(e==="paragraph")return tc(n.nodes.paragraph);let t=Number(e.split("-")[1]);return Number.isInteger(t)?tc(n.nodes.heading,{level:t}):()=>!1}function Xu(n,e,t){return(r,i)=>{let s=e.map(f=>n.marks[f]).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 f=(r.storedMarks||r.selection.$from.marks()).filter(u=>!s.includes(u.type));return o&&(f=o.create().addToSet(f)),i(r.tr.setStoredMarks(f)),!0}let h=r.tr;for(let f of s)h.removeMark(l,c,f);return o&&h.addMark(l,c,o.create()),i(h),!0}}function Zu(n,e){let t=gu(n),r=yu(e);return(i,s,o)=>Gr(i,n)?r(i,s,o):t(i,s,o)}function hx(n){let e=Eu(n);return(t,r,i)=>Gr(t,n)?Cu(t,r,i):e(t,r,i)}function Gr(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 fx(n,e,t){if(t.startsWith("align_"))return Ku(n)===t.slice(6);if(t==="bullet_list")return Gr(n,e.nodes.bullet_list);if(t==="ordered_list")return Gr(n,e.nodes.ordered_list);if(t==="blockquote")return Gr(n,e.nodes.blockquote);let r=e.marks[t];return r?dc(n,r):!1}function dc(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 ux(n){let e=n.selection.$from.parent;return e.type.name==="heading"?"heading-"+e.attrs.level:"paragraph"}function dx(n,e){let t=Hr.filter(r=>{let i=e.marks[r];return i&&dc(n,i)});return Hu(t)}function px(n,e,t,r,i){for(let s of t){let o=e.marks[s];if(o&&dc(n,o))return s.slice(r.length)}return i}function pc(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 ed({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,h=null,f=!1,u=!1,d=!1;function p(){h!==null&&o(h),h=s(()=>{h=null,m()},l)}function m(){h!==null&&(o(h),h=null),a&&(a.close(),a=null)}function g(){f||a||(a=e(k=>{p(),k>c&&y()},k=>{m(),i(k)}),p())}async function y(){if(u){d=!0;return}u=!0;try{let k=c,w=await t(k);if(f)return;try{w&&w.bytes&&w.bytes.length&&r(w.bytes)}catch{if(w=await t(k,{raw:!0}),f)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{u=!1,d&&!f&&(d=!1,y())}}return{start(){f=!1,g()},stop(){f=!0,m()},noteOwnSeq(k){typeof k!="number"||!Number.isFinite(k)||k===c+1&&(c=k)},noteActivity(){f||(a?p():g())},noteHidden(){m()},get cursor(){return c},get streaming(){return a!==null}}}function zn(n,e){return{group:e,excludes:e,parseDOM:[{tag:"span."+n}],toDOM:()=>["span",{class:n},0]}}var mx=Ms.spec.marks.addToStart("size_xl",zn("docs-size-xl","fontSize")).addToStart("size_lg",zn("docs-size-lg","fontSize")).addToStart("size_sm",zn("docs-size-sm","fontSize")).addToStart("font_mono",zn("docs-font-mono","fontFamily")).addToStart("font_sans",zn("docs-font-sans","fontFamily")).addToStart("font_serif",zn("docs-font-serif","fontFamily")),gx=mu(Ms.spec.nodes.update("paragraph",ju(Ms.spec.nodes.get("paragraph"))),"paragraph block*","block"),Xr=new An({nodes:gx,marks:mx});function yx(n,e){return e&&e(n.tr.replaceSelectionWith(Xr.nodes.hard_break.create()).scrollIntoView()),!0}var xx=250;function mc(n,e){if(!e.length)return;let t=an(e);for(;ci(t);)va(t,n,"server")}async function bx(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=Qu({root:document.querySelector("[docs-toolbar]"),schema:Xr,getView:()=>l});function h(O){i&&i.setAttribute("data-state",s?"failed":O)}function f(O){return $u({post:async A=>{let R=await fetch(t,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/octet-stream"},body:A}),T=O();if(R.ok&&T){let B=Number(R.headers.get("Docs-Seq"));Number.isFinite(B)&&T.noteOwnSeq(B)}return R},mergeUpdates:qa,debounceMs:xx,onStatus:A=>{A==="failed"&&(s=!0,g.reportDivergence()),h(A)}})}function u(O){let A=l;if(!A||O.button!==0||A.dom.contains(O.target))return;let R=A.dom.getBoundingClientRect(),T=A.posAtCoords({left:Math.min(Math.max(O.clientX,R.left+1),R.right-1),top:Math.min(Math.max(O.clientY,R.top+1),R.bottom-1)}),B=T?T.pos:A.state.doc.content.size,$=D.near(A.state.doc.resolve(B));O.preventDefault(),A.dispatch(A.state.tr.setSelection($).scrollIntoView()),A.focus()}function d(O,A){let R=[lc(A),zu(),Zl({"Mod-z":ac,"Mod-y":vs,"Mod-Shift-z":vs,"Mod-b":Ht(Xr.marks.strong),"Mod-i":Ht(Xr.marks.em),"Shift-Enter":yx}),Zl(Mu)];return a.plugin&&R.push(a.plugin),new zr({mount:O},{state:ms.create({schema:Xr,plugins:R})})}async function p(O){let A=pc(t,{raw:O}),R=await fetch(A,{credentials:"same-origin"});if(!R.ok)throw new Error(`load ${A}: ${R.status}`);return{log:new Uint8Array(await R.arrayBuffer()),startSeq:Number(R.headers.get("Docs-Seq"))}}async function m(){let{log:O,startSeq:A}=await p(!1),R=new Se;try{mc(R,O)}catch{({log:O,startSeq:A}=await p(!0)),R=new Se,mc(R,O)}let T=R.getXmlFragment("prosemirror"),B=null,$=f(()=>B);R.on("update",(be,$n)=>{$n!=="server"&&(g.diverged||$.enqueue(be))}),l&&l.destroy(),o=$,l=d(n,T),c&&c.stop(),B=ed({initialSeq:Number.isFinite(A)?A:0,openStream:(be,$n)=>{let Xt=new EventSource(r,{withCredentials:!0});return Xt.addEventListener("update",nt=>be(Number(nt.data))),Xt.addEventListener("error",nt=>$n(nt)),{close:()=>Xt.close()}},fetchSince:async(be,{raw:$n}={})=>{let Xt=pc(t,{since:be,raw:$n}),nt=await fetch(Xt,{credentials:"same-origin"});if(!nt.ok)throw new Error(`fetch ${Xt}: ${nt.status}`);return{bytes:new Uint8Array(await nt.arrayBuffer()),seq:Number(nt.headers.get("Docs-Seq"))}},onUpdates:be=>{g.diverged||mc(R,be)},onError:be=>{console.error("live updates:",be)}}),c=B,c.start(),typeof document<"u"&&document.hidden&&c.noteHidden()}let g=qu({attemptResync:m,onDiverged:()=>h("failed"),onRecovered:()=>h(s?"failed":"ok")});await m(),addEventListener("visibilitychange",()=>{document.hidden?c&&c.noteHidden():c&&c.noteActivity()});for(let O of["pointermove","scroll","keydown","focus"])addEventListener(O,()=>c&&c.noteActivity(),{passive:!0,capture:!0});let y=n.closest("[docs-page]");y&&y.addEventListener("mousedown",u);let k=!1,w=()=>{k=!0,setTimeout(()=>{k=!1},0)};return document.addEventListener("mousedown",w,!0),document.addEventListener("touchstart",w,!0),n.addEventListener("focus",()=>{if(k)return;let O=l;O&&O.dispatch(O.state.tr.scrollIntoView())}),addEventListener("beforeunload",()=>{let O=o&&o.pendingBytes();if(!O)return;let A=new Blob([O],{type:"application/octet-stream"});navigator.sendBeacon(t,A)||(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:O}).catch(()=>{}))}),l}var gc=document.querySelector("[docs-editor]");gc&&bx(gc).catch(n=>{gc.setAttribute("data-editor-failed","1"),console.error(n)});export{bx as mountEditor};
diff --git a/internal/docs/views/show.html b/internal/docs/views/show.html
index 6728170..53c6055 100644
--- a/internal/docs/views/show.html
+++ b/internal/docs/views/show.html
@@ -110,8 +110,13 @@
desktop it is worth every pixel. On a 375px phone the three together
(375 - 32 - 32 - 192) left a 119px column, and at 320px, which this
app supports without exemption (WCAG 2.2 AA SC 1.4.10), 64px: about
- five characters of 12pt Georgia per line. A page margin that
- squeezes the page is no longer describing the page.
+ five characters of 12pt body text per line. A page margin that
+ squeezes the page is no longer describing the page. (The character
+ counts here and below were measured against 12pt Georgia, the
+ fallback for the serif this canvas used to default to. The default
+ is Docs Sans now, whose characters run a little wider at the same
+ size, so the counts are if anything generous — the breakpoint the
+ arithmetic argues for does not move.)
(An earlier version of this comment counted two insets and said
151px and 96px. It was wrong in the direction that flatters the
@@ -218,9 +223,20 @@
font-display: swap;
}
{{end}}
+ /* The default face. Sans, and NOT because sans is nicer: this is the
+ face every paragraph nobody has marked is laid out in, on screen
+ and in the PDF, so it is a measurement before it is a taste. It has
+ to name the same font program internal/export/pdf.go's styleFor
+ falls back to (internal/fonts' Default) or a document breaks its
+ lines in one place on screen and another on paper, and
+ TestPageGeometryMatchesTheStylesheet is what holds the two equal.
+
+ Georgia and Times New Roman are gone from this stack with the serif
+ that named them; Arial and Helvetica are the fallbacks now, for the
+ seconds before "Docs Sans" loads. */
[docs-text] {
overflow-wrap: break-word;
- font-family: "Docs Serif", Georgia, "Times New Roman", serif;
+ font-family: "Docs Sans", Arial, Helvetica, sans-serif;
font-size: 12pt;
line-height: 1.4;
}
diff --git a/internal/export/pdf.go b/internal/export/pdf.go
index 8ebccd3..79dc1eb 100644
--- a/internal/export/pdf.go
+++ b/internal/export/pdf.go
@@ -112,6 +112,30 @@ func BlockSpace(name string) (float64, bool) {
return 0, false
}
+// FontCSSName is the CSS family name of the face this exporter lays a
+// run carrying these marks out in — no marks meaning an unmarked run,
+// which is the case that matters most, since it is what most of the
+// text in most documents is.
+//
+// It exists for internal/docs's TestPageGeometryMatchesTheStylesheet,
+// which is the only thing holding these faces equal to the
+// font-family declarations in views/show.html. Nothing else can: the
+// stylesheet is CSS in a template and this is a switch in Go, they name
+// the same faces in two languages, and a document paginates the same on
+// screen and on paper only while they agree.
+//
+// It resolves through styleFor rather than restating the answer, so it
+// reports what the exporter actually does and not what this file says
+// elsewhere that it does. A block context of scale 1 with no marks is
+// exactly an ordinary body paragraph.
+func FontCSSName(marks ...string) string {
+ m := make([]Mark, 0, len(marks))
+ for _, name := range marks {
+ m = append(m, Mark{Type: name})
+ }
+ return (&layout{}).styleFor(m, blockContext{scale: 1}).face.Family.CSSName()
+}
+
// Report is what an export could not do faithfully — §11.2's
// degrade-loudly rule, in the one form this exporter can currently
// fail: a character none of the core faces has a glyph for. A document
@@ -754,12 +778,26 @@ func (l *layout) styleFor(marks []Mark, ctx blockContext) style {
return false
}
- family := fonts.Serif
+ // fonts.Default, not a face named here: an unmarked run is whatever
+ // views/show.html's [docs-text] rule sets, and the two are held equal
+ // by internal/docs's TestPageGeometryMatchesTheStylesheet through
+ // FontCSSName above. Naming a face here instead would make this a
+ // second opinion about the default, and the one that only shows up
+ // on paper.
+ //
+ // All three marks are listed, the default's included. font_serif is
+ // not redundant with that fallback: it means "serif, whatever the
+ // default happens to be", which is what a document says when somebody
+ // chose serif on purpose, and leaving it out would silently repaint
+ // their text the day the default moves again.
+ family := fonts.Default
switch {
case has("font_mono"):
family = fonts.Mono
case has("font_sans"):
family = fonts.Sans
+ case has("font_serif"):
+ family = fonts.Serif
}
size := BodySizePt * ctx.scale
diff --git a/internal/export/pdf_test.go b/internal/export/pdf_test.go
index bcbd904..f7c92e2 100644
--- a/internal/export/pdf_test.go
+++ b/internal/export/pdf_test.go
@@ -5,6 +5,7 @@ import (
"fmt"
"math"
"regexp"
+ "sort"
"strconv"
"strings"
"testing"
@@ -89,6 +90,55 @@ func TestPDFEmbedsAFaceForEachStyleUsed(t *testing.T) {
}
}
+// The face a run is actually drawn in, read back off the paper.
+//
+// Everything else about the default face is checked one step short of
+// the PDF: internal/docs's TestPageGeometryMatchesTheStylesheet compares
+// the name styleFor resolves to against the stylesheet, which proves the
+// two agree but not that the agreed face is what gets embedded and
+// selected. This reads /BaseFont out of the file, which is the last
+// place a mistake could still be hiding.
+//
+// Both halves matter and they fail in opposite directions. An unmarked
+// run must be the DEFAULT face — that is most of the text in most
+// documents, and it is what moved. A font_serif run must be serif
+// whatever the default is — that is the mark existing at all, and if
+// styleFor did not handle it the run would fall through to the default
+// and this test would see one face where it wants two.
+func TestPDFDrawsTheDefaultFaceAndTheSerifMark(t *testing.T) {
+ js := `{"type":"doc","content":[
+ {"type":"paragraph","content":[{"type":"text","text":"Unmarked"}]},
+ {"type":"paragraph","content":[{"type":"text","text":"Serif","marks":[{"type":"font_serif"}]}]}
+ ]}`
+ data, _ := mustPDF(t, mustParse(t, "", js))
+ f := readPDF(t, data)
+
+ faces := map[string]bool{}
+ for _, o := range f.objects {
+ for _, m := range regexp.MustCompile(`/BaseFont /[A-Z]{6}\+([^ />]+)`).FindAllStringSubmatch(o.dict, -1) {
+ faces[m[1]] = true
+ }
+ }
+ if len(faces) == 0 {
+ t.Fatal("the PDF names no faces at all — the font dictionaries were restructured and this test can no longer see what it is checking")
+ }
+ if !faces["LiberationSans-Regular"] {
+ t.Errorf("an unmarked run is not drawn in Liberation Sans; the PDF uses %v", sortedKeys(faces))
+ }
+ if !faces["LiberationSerif-Regular"] {
+ t.Errorf("a font_serif run is not drawn in Liberation Serif; the PDF uses %v", sortedKeys(faces))
+ }
+}
+
+func sortedKeys(m map[string]bool) []string {
+ out := make([]string, 0, len(m))
+ for k := range m {
+ out = append(out, k)
+ }
+ sort.Strings(out)
+ return out
+}
+
// The embedded font must be a subset, not the whole face — an export
// that embeds four full faces is a megabyte and a half of font for a
// page of text.
diff --git a/internal/export/sample_pdf_test.go b/internal/export/sample_pdf_test.go
index 5e05bbe..95089a2 100644
--- a/internal/export/sample_pdf_test.go
+++ b/internal/export/sample_pdf_test.go
@@ -35,7 +35,7 @@ func TestWriteSamplePDF(t *testing.T) {
{"type":"text","text":" in it. Accents (café, naïve, Zoë) and punctuation the web is full of — em dashes, “curly quotes” — come through the same path."}
]},
{"type":"paragraph","content":[
- {"type":"text","text":"This sentence is set in the sans face","marks":[{"type":"font_sans"}]},
+ {"type":"text","text":"This sentence is set in the serif face","marks":[{"type":"font_serif"}]},
{"type":"text","text":", this one is larger","marks":[{"type":"size_lg"}]},
{"type":"text","text":", and this one is small.","marks":[{"type":"size_sm"}]}
]},
diff --git a/internal/fonts/fonts.go b/internal/fonts/fonts.go
index 495864d..34ee7cd 100644
--- a/internal/fonts/fonts.go
+++ b/internal/fonts/fonts.go
@@ -51,10 +51,14 @@ import (
//go:embed files
var files embed.FS
-// Family is one of the three faces a document can ask for. Serif is
-// the default — a document that has never been told otherwise is set
-// in it — which is why it is the zero value and why nothing in the
-// CRDT marks a serif run as serif (core/src/fragment.rs's MARKS).
+// Family is one of the three faces a document can ask for.
+//
+// Serif is the zero value for no reason worth relying on: it is first
+// in the list, and it was once the default. It is not the default now
+// (see Default below), and nothing here should read the zero value as
+// "the default" — Go gives a Family field in an uninitialised struct
+// the value Serif whether or not anybody meant it, so a default spelled
+// that way is a default nobody can see going wrong.
type Family uint8
const (
@@ -63,10 +67,32 @@ const (
Mono
)
+// Default is the face a run carrying no font mark is set in.
+//
+// It is a decision, not a property of any face, and it is stated in
+// four places that cannot import each other: here, views/show.html's
+// `[docs-text]` rule, internal/export/pdf.go's styleFor (which reads
+// this constant, so those two are one place and a half), and
+// fixtures/fonts.mjs's DEFAULT_FONT, which is what the toolbar tells a
+// person their unmarked text is in. internal/docs's
+// TestPageGeometryMatchesTheStylesheet and
+// TestTheToolbarDefaultFontIsTheDefaultFace are what hold the other
+// three to this one.
+//
+// Moving it changes the metrics every unmarked paragraph is laid out
+// with, on screen and in its own PDF, so every existing document
+// repaginates. That is not a side effect to be minimised — it is the
+// change — and it is safe only because the screen and the exporter
+// measure with the same font programs and are made to name the same
+// face here.
+const Default = Sans
+
// Key is the family's name in the vocabulary shared by the CRDT marks
-// (font_sans, font_mono), the CSS classes (docs-font-sans), and the
-// toolbar's own control. Serif's key exists for the toolbar to select
-// with even though no mark ever carries it.
+// (font_serif, font_sans, font_mono), the CSS classes
+// (docs-font-serif), and the toolbar's own control
+// (fixtures/fonts.mjs's FONTS). All three faces have a mark now; the
+// default's is simply one the toolbar never writes, because choosing
+// the default clears the group rather than setting anything.
func (f Family) Key() string {
switch f {
case Sans:
@@ -100,8 +126,8 @@ func (f Family) CSSName() string {
// false return is load-bearing: keys reach this from mark names in a
// document, and a document can carry any bytes at all
// (POST /d/{sqid}/updates), so an unrecognised key must be a miss the
-// caller decides about rather than a silent fallback to serif that
-// hides a mark this build does not understand.
+// caller decides about rather than a silent fallback to the default
+// that hides a mark this build does not understand.
func FamilyForKey(key string) (Family, bool) {
switch key {
case "serif":
@@ -238,7 +264,7 @@ func Get(family Family, bold, italic bool) Face {
// instead of trusting an ordering that exists for a different
// reason.
for _, f := range faces {
- if f.Family == Serif && !f.Bold && !f.Italic {
+ if f.Family == Default && !f.Bold && !f.Italic {
return f
}
}