oficina / mapa Public

Editor fidelity: pair the common head and tail before aligning

rebuild and adoptInto aligned every block with a full longest common
subsequence. Pairing the matching head and tail first makes the usual
case (a few blocks differ) linear: rebuilding a 1,140-block, 379KB spec
went from 340ms to 71ms. Typing there costs 9ms a keystroke.

editor.json is rewritten: the pairing can choose other, equally valid
pairs, which moves some saved bytes; every L3 check still holds.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 7f6ff80d1e4223151d812e9a5a2e777e3e029fc4 parent a183933
3 files changed, +25 −9
  • editor/fidelity.mjs +17 −1
  • internal/mapa/markup/testdata/editor.json +1 −1
  • internal/mapa/static/{editor.e67effa70bb31619.js => editor.eb10982d80e27da0.js} +7 −7
diff --git a/editor/fidelity.mjs b/editor/fidelity.mjs
index 702301a..d1e2ba0 100644
--- a/editor/fidelity.mjs
+++ b/editor/fidelity.mjs
@@ -91,8 +91,24 @@ function sameBlock (block, parsed) {
}
// align pairs a's items with b's by a longest common subsequence under
-// same, in order.
+// same, in order. The common head and tail are paired first, so the
+// usual case (a few blocks differ) is linear.
function align (a, b, same) {
+ let head = 0
+ while (head < a.length && head < b.length && same(a[head], b[head])) head++
+ let tail = 0
+ while (tail < a.length - head && tail < b.length - head &&
+ same(a[a.length - 1 - tail], b[b.length - 1 - tail])) tail++
+ const middle = lcs(a.slice(head, a.length - tail), b.slice(head, b.length - tail), same)
+ return [
+ ...Array.from({ length: head }, (_, index) => [index, index]),
+ ...middle.map(([row, column]) => [row + head, column + head]),
+ ...Array.from({ length: tail }, (_, index) =>
+ [a.length - tail + index, b.length - tail + index])
+ ]
+}
+
+function lcs (a, b, same) {
const rows = a.length
const columns = b.length
const lengths = Array.from({ length: rows + 1 }, () => new Int32Array(columns + 1))
diff --git a/internal/mapa/markup/testdata/editor.json b/internal/mapa/markup/testdata/editor.json
index d55f25c..0e80e61 100644
--- a/internal/mapa/markup/testdata/editor.json
+++ b/internal/mapa/markup/testdata/editor.json
@@ -183,7 +183,7 @@
{"name":"commonmark/082","body":" *ar\nb- az*\n\noo *ba```r\nba*[[2026-11-12]]*z*\t\n====\n\n==\n\n=* \n\nFé\n\noo *ba*````r`\n`ba`[[2026-11-12]]*z*\t\n====","blocks":["paragraph","paragraph","paragraph","paragraph","paragraph","paragraph"]},
{"name":"commonmark/083","body":"F[[Acme]]o![[fichas:c1]]\n\nF[[Acme]]---oo\n-------------------------\n\noow**ord**","blocks":["paragraph","paragraph","rule","paragraph"]},
{"name":"commonmark/084","body":"é Foo\n\n-----\n\né \n Foo\n\n Fo`w Foror\n\nda o\n =**=**\n\n Foooo\n\n---\n\no","blocks":["paragraph","rule","paragraph","paragraph","paragraph","paragraph","rule","paragraph"]},
-{"name":"commonmark/085","body":" Foo\n #~~~ 1. ---\n\n a1.[ ] Foo\n---\n\nFo\no\n # \n\n---\n\n---\n\n1.","blocks":["paragraph","paragraph","rule","paragraph","rule","rule","paragraph"]},
+{"name":"commonmark/085","body":" Foo\n #~~~ 1. ---\n\n a1.[ ] Foo\n---\n\nFo\no\n # \n---\n\n---\n\n1.","blocks":["paragraph","paragraph","rule","paragraph","rule","rule","paragraph"]},
{"name":"commonmark/086","body":"*`![[fichas:c1]]`> \n\n``\n\n*\n\n``","blocks":["paragraph","paragraph","paragraph","paragraph"]},
{"name":"commonmark/087","body":"o[Fo\n --[[Acme#^b1|that]]---Foo-1. \n [[Acme#^b1|that]]- ] ooFo\n --[[Acme#^b1|that]]---Foo-1. \n [[Acme#^b1|that]]---","blocks":["paragraph"]},
{"name":"commonmark/088","body":"Foo\n= [[Acme#^b1|that]]=FF\n\nFoo\n= [[Acme#^b1|that]]=FF\n\n ^ab","blocks":["paragraph","paragraph","paragraph"]},
diff --git a/internal/mapa/static/editor.e67effa70bb31619.js b/internal/mapa/static/editor.eb10982d80e27da0.js
similarity index 86%
rename from internal/mapa/static/editor.e67effa70bb31619.js
rename to internal/mapa/static/editor.eb10982d80e27da0.js
index f0382e2..6241797 100644
--- a/internal/mapa/static/editor.e67effa70bb31619.js
+++ b/internal/mapa/static/editor.eb10982d80e27da0.js
@@ -1,13 +1,13 @@
function M(n){this.content=n}M.prototype={constructor:M,find:function(n){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===n)return e;return-1},get:function(n){var e=this.find(n);return e==-1?void 0:this.content[e+1]},update:function(n,e,t){var r=t&&t!=n?this.remove(t):this,i=r.find(n),s=r.content.slice();return i==-1?s.push(t||n,e):(s[i+1]=e,t&&(s[i]=t)),new M(s)},remove:function(n){var e=this.find(n);if(e==-1)return this;var t=this.content.slice();return t.splice(e,2),new M(t)},addToStart:function(n,e){return new M([n,e].concat(this.remove(n).content))},addToEnd:function(n,e){var t=this.remove(n).content.slice();return t.push(n,e),new M(t)},addBefore:function(n,e,t){var r=this.remove(e),i=r.content.slice(),s=r.find(n);return i.splice(s==-1?i.length:s,0,e,t),new M(i)},forEach:function(n){for(var e=0;e<this.content.length;e+=2)n(this.content[e],this.content[e+1])},prepend:function(n){return n=M.from(n),n.size?new M(n.content.concat(this.subtract(n).content)):this},append:function(n){return n=M.from(n),n.size?new M(this.subtract(n).content.concat(n.content)):this},subtract:function(n){var e=this;n=M.from(n);for(var t=0;t<n.content.length;t+=2)e=e.remove(n.content[t]);return e},toObject:function(){var n={};return this.forEach(function(e,t){n[e]=t}),n},get size(){return this.content.length>>1}};M.from=function(n){if(n instanceof M)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new M(e)};var Ue=M;function Ot(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){let o=i.text,l=s.text,a=0;for(;o[a]==l[a];a++)t++;return a&&a<o.length&&a<l.length&&Tt(o.charCodeAt(a-1))&&Ct(o.charCodeAt(a))&&t--,t}if(i.content.size||s.content.size){let o=Ot(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function Et(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),a=o.nodeSize;if(o==l){t-=a,r-=a;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let c=o.text,u=l.text,h=c.length,f=u.length;for(;h>0&&f>0&&c[h-1]==u[f-1];)h--,f--,t--,r--;return h&&f&&h<c.length&&Tt(c.charCodeAt(h-1))&&Ct(c.charCodeAt(h))&&(t++,r++),{a:t,b:r}}if(o.content.size||l.content.size){let c=Et(o.content,l.content,t-1,r-1);if(c)return c}t-=a,r-=a}}function Ct(n){return n>=56320&&n<57344}function Tt(n){return n>=55296&&n<56320}var m=class n{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let r=0;r<e.length;r++)this.size+=e[r].nodeSize}nodesBetween(e,t,r,i=0,s){for(let o=0,l=0;l<t;o++){let a=this.content[o],c=l+a.nodeSize;if(c>e&&r(a,i+l,s||null,o)!==!1&&a.content.size){let u=l+1;a.nodesBetween(Math.max(0,e-u),Math.min(a.content.size,t-u),r,i+u)}l=c}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,a)=>{let c=l.isText?l.text.slice(Math.max(e,a)-a,t-a):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&c||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=c},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);s<e.content.length;s++)i.push(e.content[s]);return new n(i,this.size+e.size)}cut(e,t=this.size){if(e==0&&t==this.size)return this;let r=[],i=0;if(t>e)for(let s=0,o=0;o<t;s++){let l=this.content[s],a=o+l.nodeSize;a>e&&((o<e||a>t)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=a}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,r=0;t<this.content.length;t++){let i=this.content[t];e(i,r,t),r+=i.nodeSize}}findDiffStart(e,t=0){return Ot(this,e,t)}findDiffEnd(e,t=this.size,r=e.size){return Et(this,e,t,r)}findIndex(e){if(e==0)return pe(0,e);if(e==this.size)return pe(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,r=0;;t++){let i=this.child(t),s=r+i.nodeSize;if(s>=e)return s==e?pe(t+1,s):pe(t,r);r=s}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return n.fromArray(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;i<e.length;i++){let s=e[i];r+=s.nodeSize,i&&s.isText&&e[i-1].sameMarkup(s)?(t||(t=e.slice(0,i)),t[t.length-1]=s.withText(t[t.length-1].text+s.text)):t&&t.push(s)}return new n(t||e,r)}static from(e){if(!e)return n.empty;if(e instanceof n)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new n([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}};m.empty=new m([],0);var He={index:0,offset:0};function pe(n,e){return He.index=n,He.offset=e,He}function de(n,e){if(n===e)return!0;if(!(n&&typeof n=="object")||!(e&&typeof e=="object"))return!1;let t=Array.isArray(n);if(Array.isArray(e)!=t)return!1;if(t){if(n.length!=e.length)return!1;for(let r=0;r<n.length;r++)if(!de(n[r],e[r]))return!1}else{for(let r in n)if(!(r in e)||!de(n[r],e[r]))return!1;for(let r in e)if(!(r in n))return!1}return!0}var y=class n{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,r=!1;for(let i=0;i<e.length;i++){let s=e[i];if(this.eq(s))return e;if(this.type.excludes(s.type))t||(t=e.slice(0,i));else{if(s.type.excludes(this.type))return e;!r&&s.type.rank>this.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&de(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let r=e.marks[t.type];if(!r)throw new RangeError(`There is no mark type ${t.type} in this schema`);let i=r.create(t.attrs);return r.checkAttrs(i.attrs),i}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let r=0;r<e.length;r++)if(!e[r].eq(t[r]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return n.none;if(e instanceof n)return[e];let t=e.slice();return t.sort((r,i)=>r.type.rank-i.type.rank),t}};y.none=[];var D=class extends Error{},d=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=At(this.content,e+this.openStart,t,this.openStart+1,this.openEnd+1);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(Nt(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(m.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};d.empty=new d(m.empty,0,0);function Nt(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(Nt(s.content,e-i-1,t-i-1)))}function At(n,e,t,r,i,s){let{index:o,offset:l}=n.findIndex(e),a=n.maybeChild(o);if(l==e||a.isText)return s&&r<=0&&i<=0&&!s.canReplace(o,o,t)?null:n.cut(0,e).append(t).append(n.cut(e));let c=At(a.content,e-l-1,t,o==0?r-1:0,o==n.childCount-1?i-1:0,a);return c&&n.replaceChild(o,a.copy(c))}function Pn(n,e,t){if(t.openStart>n.depth)throw new D("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new D("Inconsistent open depths");return Rt(n,e,t,0)}function Rt(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r<n.depth-t.openStart){let o=Rt(n,e,t,r+1);return s.copy(s.content.replaceChild(i,o))}else if(t.content.size)if(!t.openStart&&!t.openEnd&&n.depth==r&&e.depth==r){let o=n.parent,l=o.content;return L(o,l.cut(0,n.parentOffset).append(t.content).append(l.cut(e.parentOffset)))}else{let{start:o,end:l}=Wn(t,n);return L(s,zt(n,o,l,e,r))}else return L(s,me(n,e,r))}function It(n,e){if(!e.type.compatibleContent(n.type))throw new D("Cannot join "+e.type.name+" onto "+n.type.name)}function Ve(n,e,t){let r=n.node(t);return It(r,e.node(t)),r}function W(n,e){let t=e.length-1;t>=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function ie(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(W(n.nodeAfter,r),s++));for(let l=s;l<o;l++)W(i.child(l),r);e&&e.depth==t&&e.textOffset&&W(e.nodeBefore,r)}function L(n,e){if(!n.type.validContent(e))throw new D("Invalid content for node "+n.type.name);return n.copy(e)}function zt(n,e,t,r,i){let s=n.depth>i&&Ve(n,e,i+1),o=r.depth>i&&Ve(t,r,i+1),l=[];return ie(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(It(s,o),W(L(s,zt(n,e,t,r,i+1)),l)):(s&&W(L(s,me(n,e,i+1)),l),ie(e,t,i,l),o&&W(L(o,me(t,r,i+1)),l)),ie(r,null,i,l),new m(l)}function me(n,e,t){let r=[];if(ie(null,n,t,r),n.depth>t){let i=Ve(n,e,t+1);W(L(i,me(n,e,t+1)),r)}return ie(e,null,t,r),new m(r)}function Wn(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(m.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var ge=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s<e;s++)i+=r.child(s).nodeSize;return i}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return y.none;if(this.textOffset)return e.child(t).marks;let r=e.maybeChild(t-1),i=e.maybeChild(t);if(!r){let l=r;r=i,i=l}let s=r.marks;for(var o=0;o<s.length;o++)s[o].type.spec.inclusive===!1&&(!i||!s[o].isInSet(i.marks))&&(s=s[o--].removeFromSet(s));return s}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let r=t.marks,i=e.parent.maybeChild(e.index());for(var s=0;s<r.length;s++)r[s].type.spec.inclusive===!1&&(!i||!r[s].isInSet(i.marks))&&(r=r[s--].removeFromSet(r));return r}sharedDepth(e){for(let t=this.depth;t>0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos<this.pos)return e.blockRange(this);for(let r=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);r>=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Ze(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos<this.pos?e:this}toString(){let e="";for(let t=1;t<=this.depth;t++)e+=(e?"/":"")+this.node(t).type.name+"_"+this.index(t-1);return e+":"+this.parentOffset}static resolve(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:a}=o.content.findIndex(s),c=s-a;if(r.push(o,l,i+a),!c||(o=o.child(l),o.isText))break;s=c-1,i+=a+1}return new n(t,r,s)}static resolveCached(e,t){let r=St.get(e);if(r)for(let s=0;s<r.elts.length;s++){let o=r.elts[s];if(o.pos==t)return o}else St.set(e,r=new je);let i=r.elts[r.i]=n.resolve(e,t);return r.i=(r.i+1)%Ln,i}},je=class{constructor(){this.elts=[],this.i=0}},Ln=12,St=new WeakMap,Ze=class{constructor(e,t,r){this.$from=e,this.$to=t,this.depth=r}get start(){return this.$from.before(this.depth+1)}get end(){return this.$to.after(this.depth+1)}get parent(){return this.$from.node(this.depth)}get startIndex(){return this.$from.index(this.depth)}get endIndex(){return this.$to.indexAfter(this.depth)}},$n=Object.create(null),A=class n{constructor(e,t,r,i=y.none){this.type=e,this.attrs=t,this.marks=i,this.content=r||m.empty}get children(){return this.content.content}get nodeSize(){return this.isLeaf?1:2+this.content.size}get childCount(){return this.content.childCount}child(e){return this.content.child(e)}maybeChild(e){return this.content.maybeChild(e)}forEach(e){this.content.forEach(e)}nodesBetween(e,t,r,i=0){this.content.nodesBetween(e,t,r,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,r,i){return this.content.textBetween(e,t,r,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,r){return this.type==e&&de(this.attrs,t||e.defaultAttrs||$n)&&y.sameSet(this.marks,r||y.none)}copy(e=null){return e==this.content?this:new n(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return e==0&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,r=!1){if(e==t)return d.empty;let i=this.resolve(e),s=this.resolve(t),o=r?0:i.sharedDepth(t),l=i.start(o),c=i.node(o).content.cut(i.pos-l,s.pos-l);return new d(c,i.depth-o,s.depth-o)}replace(e,t,r){return Pn(this.resolve(e),this.resolve(t),r)}nodeAt(e){for(let t=this;;){let{index:r,offset:i}=t.content.findIndex(e);if(t=t.maybeChild(r),!t)return null;if(i==e||t.isText)return t;e-=i+1}}childAfter(e){let{index:t,offset:r}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:r}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:r}=this.content.findIndex(e);if(r<e)return{node:this.content.child(t),index:t,offset:r};let i=this.content.child(t-1);return{node:i,index:t-1,offset:r-i.nodeSize}}resolve(e){return ge.resolveCached(this,e)}resolveNoCache(e){return ge.resolve(this,e)}rangeHasMark(e,t,r){let i=!1;return t>e&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),Dt(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=m.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let a=i;a<s;a++)if(!this.type.allowsMarks(r.child(a).marks))return!1;return!0}canReplaceWith(e,t,r,i){if(i&&!this.type.allowsMarks(i))return!1;let s=this.contentMatchAt(e).matchType(r),o=s&&s.matchFragment(this.content,t);return o?o.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content),this.type.checkAttrs(this.attrs);let e=y.none;for(let t=0;t<this.marks.length;t++){let r=this.marks[t];r.type.checkAttrs(r.attrs),e=r.addToSet(e)}if(!y.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(t=>t.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=m.fromJSON(e,t.content),s=e.nodeType(t.type).create(t.attrs,i,r);return s.type.checkAttrs(s.attrs),s}};A.prototype.text=void 0;var Ke=class n extends A{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):Dt(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function Dt(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var $=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new Ge(e,t);if(r.next==null)return n.empty;let i=Ft(r);r.next&&r.err("Unexpected trailing text");let s=Kn(Zn(i));return Gn(s,r),s}matchType(e){for(let t=0;t<this.next.length;t++)if(this.next[t].type==e)return this.next[t].next;return null}matchFragment(e,t=0,r=e.childCount){let i=this;for(let s=t;i&&s<r;s++)i=i.matchType(e.child(s).type);return i}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let r=0;r<e.next.length;r++)if(this.next[t].type==e.next[r].type)return!0;return!1}fillBefore(e,t=!1,r=0){let i=[this];function s(o,l){let a=o.matchFragment(e,r);if(a&&(!t||a.validEnd))return m.from(l.map(c=>c.createAndFill()));for(let c=0;c<o.next.length;c++){let{type:u,next:h}=o.next[c];if(!(u.isText||u.hasRequiredAttrs())&&i.indexOf(h)==-1){i.push(h);let f=s(h,l.concat(u));if(f)return f}}return null}return s(this,[])}findWrapping(e){for(let r=0;r<this.wrapCache.length;r+=2)if(this.wrapCache[r]==e)return this.wrapCache[r+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),r=[{match:this,type:null,via:null}];for(;r.length;){let i=r.shift(),s=i.match;if(s.matchType(e)){let o=[];for(let l=i;l.type;l=l.via)o.push(l.type);return o.reverse()}for(let o=0;o<s.next.length;o++){let{type:l,next:a}=s.next[o];!l.isLeaf&&!l.hasRequiredAttrs()&&!(l.name in t)&&(!i.type||a.validEnd)&&(r.push({match:l.contentMatch,type:l,via:i}),t[l.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i<r.next.length;i++)e.indexOf(r.next[i].next)==-1&&t(r.next[i].next)}return t(this),e.map((r,i)=>{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o<r.next.length;o++)s+=(o?", ":"")+r.next[o].type.name+"->"+e.indexOf(r.next[o].next);return s}).join(`
-`)}};$.empty=new $(!0);var Ge=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Ft(n){let e=[];do e.push(qn(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function qn(n){let e=[];do e.push(Un(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Un(n){let e=jn(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=Hn(n,e);else break;return e}function Mt(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Hn(n,e){let t=Mt(n),r=t;return n.eat(",")&&(n.next!="}"?r=Mt(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Vn(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function jn(n){if(n.eat("(")){let e=Ft(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Vn(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Zn(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return r(l,a),i(s(o.expr,a),a),[r(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[r(a)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c<o.min;c++){let u=t();i(s(o.expr,a),u),a=u}if(o.max==-1)i(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let u=t();r(a,u),i(s(o.expr,a),u),a=u}return[r(a)]}else{if(o.type=="name")return[r(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Bt(n,e){return e-n}function bt(n,e){let t=[];return r(e),t.sort(Bt);function r(i){let s=n[i];if(s.length==1&&!s[0].term)return r(s[0].to);t.push(i);for(let o=0;o<s.length;o++){let{term:l,to:a}=s[o];!l&&t.indexOf(a)==-1&&r(a)}}}function Kn(n){let e=Object.create(null);return t(bt(n,0));function t(r){let i=[];r.forEach(o=>{n[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let u=0;u<i.length;u++)i[u][0]==l&&(c=i[u][1]);bt(n,a).forEach(u=>{c||i.push([l,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let s=e[r.join(",")]=new $(r.indexOf(n.length-1)>-1);for(let o=0;o<i.length;o++){let l=i[o][1].sort(Bt);s.next.push({type:i[o][0],next:e[l.join(",")]||t(l)})}return s}}function Gn(n,e){for(let t=0,r=[n];t<r.length;t++){let i=r[t],s=!i.validEnd,o=[];for(let l=0;l<i.next.length;l++){let{type:a,next:c}=i.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),r.indexOf(c)==-1&&r.push(c)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Jt(n){let e=Object.create(null);for(let t in n){let r=n[t];if(!r.hasDefault)return null;e[t]=r.default}return e}function Pt(n,e){let t=Object.create(null);for(let r in n){let i=e&&e[r];if(i===void 0){let s=n[r];if(s.hasDefault)i=s.default;else throw new RangeError("No value supplied for attribute "+r)}t[r]=i}return t}function Wt(n,e,t,r){for(let i in e)if(!(i in n))throw new RangeError(`Unsupported attribute ${i} for ${t} of type ${r}`);for(let i in n)n[i].validate&&n[i].validate(e[i])}function Lt(n,e){let t=Object.create(null);if(e)for(let r in e)t[r]=new Qe(n,r,e[r]);return t}var ye=class n{constructor(e,t,r){this.name=e,this.schema=t,this.spec=r,this.markSet=null,this.groups=r.group?r.group.split(" "):[],this.attrs=Lt(e,r.attrs),this.defaultAttrs=Jt(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(r.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==$.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Pt(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new A(this,this.computeAttrs(e),m.from(t),y.setFrom(r))}createChecked(e=null,t,r){return t=m.from(t),this.checkContent(t),new A(this,this.computeAttrs(e),t,y.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=m.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(m.empty,!0);return s?new A(this,e,t.append(s),y.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r<e.childCount;r++)if(!this.allowsMarks(e.child(r).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){Wt(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let r=0;r<e.length;r++)this.allowsMarkType(e[r].type)?t&&t.push(e[r]):t||(t=e.slice(0,r));return t?t.length?t:y.none:e}static compile(e,t){let r=Object.create(null);e.forEach((s,o)=>r[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Qn(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var Qe=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Qn(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},xe=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=Lt(e,i.attrs),this.excluded=null;let s=Jt(this.attrs);this.instance=s?new y(this,s):null}create(e=null){return!e&&this.instance?this.instance:new y(this,Pt(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){Wt(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}},ke=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=Ue.from(e.nodes),t.marks=Ue.from(e.marks||{}),this.nodes=ye.compile(this.spec.nodes,this),this.marks=xe.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=$.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?vt(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:vt(this,o.split(" "))}this.nodeFromJSON=i=>A.fromJSON(this,i),this.markFromJSON=i=>y.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ye){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Ke(r,r.defaultAttrs,e,y.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function vt(n,e){let t=[];for(let r=0;r<e.length;r++){let i=e[r],s=n.marks[i],o=s;if(s)t.push(s);else for(let l in n.marks){let a=n.marks[l];(i=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(i)>-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}var $t="http://www.w3.org/2000/svg",Xn={page:["M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z","M14 2v4a2 2 0 0 0 2 2h4","M9 13h6","M9 17h4"],"page-plus":["M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z","M14 2v4a2 2 0 0 0 2 2h4","M9 15h6","M12 12v6"],calendar:["M8 2v4","M16 2v4","M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z","M3 10h18"],block:["M13 4v16","M17 4v16","M19 4H9.5a4.5 4.5 0 0 0 0 9H13"],embed:["M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z","m3.3 7 8.7 5 8.7-5","M12 22V12"]};function qt(n){return[`${$t} svg`,{"mapa-i":"",viewBox:"0 0 24 24","aria-hidden":"true"},...Xn[n].map(e=>[`${$t} path`,{d:e}])]}function we({href:n,kind:e,title:t,label:r,icon:i,shown:s,note:o}){let l={href:n,"mapa-chip":e};t&&(l.title=t),l["aria-label"]=r;let a=["a",l,qt(i),s];return o&&a.push(["span",{"mapa-chip-note":""},o]),a}function Xe({target:n,anchor:e,shown:t},r){let i=t||n;if(r.broken)return["span",{"mapa-chip":"broken"},i];if(r.day)return Yn(t,r);if(r.pending)return we({href:r.href,kind:"pending",icon:"page-plus",shown:i,label:`${i}, page not written yet`});let s=r.title||n,o={href:r.href,kind:"team",icon:"page",shown:i,label:`${i}, team page`};return r.alias&&(o.title=`Now called ${s}`,o.label=`${i}, now called ${s}`),e&&(o.kind=o.icon="block",o.label=`${i}, a block in ${s}`),e&&r.blockGone&&(o.kind="block gone",o.label=`${i}, block removed from ${s}`,o.note="block removed"),we(o)}function Yn(n,e){return we(n?{href:e.href,kind:"date",icon:"calendar",shown:n,label:`${n}, your note for ${e.day}`}:{href:e.href,kind:"date",icon:"calendar",shown:e.day,label:`${e.day}, your note`})}function Ut(n){return["span",{"mapa-chip":"embed",role:"img","aria-label":`${n}, embedded item, not shown yet`},qt("embed"),n]}var _n=/^[A-Za-z0-9\-_.~!$&'()*+,;=:[\]<>"]$/u,er=/^[A-Za-z0-9\-._:~!$&'()*+,;=%@]$/u,Ht=/^[0-9A-Fa-f]$/u;function Se(n){let e=tr(n);if(e===null)return!1;switch(e.scheme){case"http":case"https":return e.host!==""&&!e.host.startsWith("[");case"mailto":return e.opaque!==""}return!1}function tr(n){let e=n.indexOf("#"),t=e<0?n:n.slice(0,e),r=e<0?"":n.slice(e+1),i=nr(t);return i===null||r!==""&&!Ye(r)?null:i}function nr(n){if(/[\x00-\x1f\x7f]/u.test(n))return null;if(n==="*")return{scheme:"",host:"",opaque:""};let e=rr(n);if(e===null)return null;let t=e.rest,r={scheme:e.name.toLowerCase(),host:"",opaque:""};if(t.endsWith("?")&&t.split("?").length===2?t=t.slice(0,-1):t.includes("?")&&(t=t.slice(0,t.indexOf("?"))),!t.startsWith("/")){if(r.scheme!=="")return r.opaque=t,r;if(t.split("/")[0].includes(":"))return null}if((r.scheme!==""||!t.startsWith("///"))&&t.startsWith("//")){let i=t.slice(2);t="";let s=i.indexOf("/");s>=0&&(t=i.slice(s),i=i.slice(0,s));let o=ir(r.scheme,i);if(o===null)return null;r.host=o}return Ye(t)?r:null}function rr(n){for(let e=0;e<n.length;e++){let t=n[e];if(!/^[A-Za-z]$/u.test(t)){if(/^[0-9+\-.]$/u.test(t)){if(e===0)return{name:"",rest:n};continue}return t===":"?e===0?null:{name:n.slice(0,e),rest:n.slice(e+1)}:{name:"",rest:n}}}return{name:"",rest:n}}function ir(n,e){let t=e.lastIndexOf("@"),r=sr(n,t<0?e:e.slice(t+1));if(r===null||t<0)return r;let i=e.slice(0,t);for(let s of i)if(!er.test(s))return null;return Ye(i)?r:null}function sr(n,e){let t=e.lastIndexOf("[");if(t>0)return null;if(t===0)return"[";let r=e.indexOf(":");if(r!==-1){let i=e.lastIndexOf(":");if(i!==r&&n!=="http"&&n!=="https"&&(r=i),!/^:[0-9]*$/u.test(e.slice(r)))return null}return or(e)?e:null}function or(n){for(let e=0;e<n.length;e++){let t=n[e];if(t==="%"){if(!Vt(n,e)||parseInt(n[e+1],16)<8&&n.slice(e,e+3)!=="%25")return!1;e+=2}else if(t.charCodeAt(0)<128&&!_n.test(t))return!1}return!0}function Ye(n){for(let e=0;e<n.length;e++)if(n[e]==="%"){if(!Vt(n,e))return!1;e+=2}return!0}function Vt(n,e){return e+2<n.length&&Ht.test(n[e+1])&&Ht.test(n[e+2])}var be="paragraph",R="heading",k="item",T="code",v="quote",N="rule",lr="text",et="code",oe="wiki",Me="web",le="embed",q="[^\\t\\n\\f\\r ]",Yt=new RegExp(`^(#{1,6})[ \\t]+${q}`,"u"),ae=/^([ \t]*)([-*+]|[0-9]{1,9}[.)])[ \t]+/u,Z=/^ {0,3}(```|~~~)/u,tt=/^ {0,3}(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/u,_t=/[ \t]\^([A-Za-z0-9-]{1,40})[ \t]*$/u,ar=/^\[([^\]\n]+)\]\(([^)\t\n\f\r ]+)\)/u,cr=/^https?:\/\/[^\t\n\f\r <>()[\]]+[^\t\n\f\r <>()[\].,;:!?'"]/u,hr=/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/u,ur=/^\[([ xX])\][ \t]+/u,jt=/[\t\n\v\f\r \u0085\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]/u;function F(n){let e=0,t=n.length;for(;e<t&&jt.test(n[e]);)e++;for(;t>e&&jt.test(n[t-1]);)t--;return n.slice(e,t)}function ce(n,e){let t=0;for(;t<n.length&&e.includes(n[t]);)t++;return n.slice(t)}function Zt(n){let e=0;for(let t of n){let r=t.codePointAt(0);e+=r<128?1:r<2048?2:r<65536?3:4}return e}function ve(n){return U(n).replace(/[ \t\n]+$/u,"")}function U(n){return n.replaceAll(`\r
+`)}};$.empty=new $(!0);var Ge=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function Ft(n){let e=[];do e.push(qn(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function qn(n){let e=[];do e.push(Un(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function Un(n){let e=jn(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=Hn(n,e);else break;return e}function Mt(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function Hn(n,e){let t=Mt(n),r=t;return n.eat(",")&&(n.next!="}"?r=Mt(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function Vn(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.isInGroup(e)&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function jn(n){if(n.eat("(")){let e=Ft(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=Vn(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function Zn(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,a){let c={term:a,to:l};return e[o].push(c),c}function i(o,l){o.forEach(a=>a.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((a,c)=>a.concat(s(c,l)),[]);if(o.type=="seq")for(let a=0;;a++){let c=s(o.exprs[a],l);if(a==o.exprs.length-1)return c;i(c,l=t())}else if(o.type=="star"){let a=t();return r(l,a),i(s(o.expr,a),a),[r(a)]}else if(o.type=="plus"){let a=t();return i(s(o.expr,l),a),i(s(o.expr,a),a),[r(a)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let a=l;for(let c=0;c<o.min;c++){let u=t();i(s(o.expr,a),u),a=u}if(o.max==-1)i(s(o.expr,a),a);else for(let c=o.min;c<o.max;c++){let u=t();r(a,u),i(s(o.expr,a),u),a=u}return[r(a)]}else{if(o.type=="name")return[r(l,void 0,o.value)];throw new Error("Unknown expr type")}}}}function Bt(n,e){return e-n}function bt(n,e){let t=[];return r(e),t.sort(Bt);function r(i){let s=n[i];if(s.length==1&&!s[0].term)return r(s[0].to);t.push(i);for(let o=0;o<s.length;o++){let{term:l,to:a}=s[o];!l&&t.indexOf(a)==-1&&r(a)}}}function Kn(n){let e=Object.create(null);return t(bt(n,0));function t(r){let i=[];r.forEach(o=>{n[o].forEach(({term:l,to:a})=>{if(!l)return;let c;for(let u=0;u<i.length;u++)i[u][0]==l&&(c=i[u][1]);bt(n,a).forEach(u=>{c||i.push([l,c=[]]),c.indexOf(u)==-1&&c.push(u)})})});let s=e[r.join(",")]=new $(r.indexOf(n.length-1)>-1);for(let o=0;o<i.length;o++){let l=i[o][1].sort(Bt);s.next.push({type:i[o][0],next:e[l.join(",")]||t(l)})}return s}}function Gn(n,e){for(let t=0,r=[n];t<r.length;t++){let i=r[t],s=!i.validEnd,o=[];for(let l=0;l<i.next.length;l++){let{type:a,next:c}=i.next[l];o.push(a.name),s&&!(a.isText||a.hasRequiredAttrs())&&(s=!1),r.indexOf(c)==-1&&r.push(c)}s&&e.err("Only non-generatable nodes ("+o.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function Jt(n){let e=Object.create(null);for(let t in n){let r=n[t];if(!r.hasDefault)return null;e[t]=r.default}return e}function Pt(n,e){let t=Object.create(null);for(let r in n){let i=e&&e[r];if(i===void 0){let s=n[r];if(s.hasDefault)i=s.default;else throw new RangeError("No value supplied for attribute "+r)}t[r]=i}return t}function Wt(n,e,t,r){for(let i in e)if(!(i in n))throw new RangeError(`Unsupported attribute ${i} for ${t} of type ${r}`);for(let i in n)n[i].validate&&n[i].validate(e[i])}function Lt(n,e){let t=Object.create(null);if(e)for(let r in e)t[r]=new Qe(n,r,e[r]);return t}var ye=class n{constructor(e,t,r){this.name=e,this.schema=t,this.spec=r,this.markSet=null,this.groups=r.group?r.group.split(" "):[],this.attrs=Lt(e,r.attrs),this.defaultAttrs=Jt(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(r.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==$.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}isInGroup(e){return this.groups.indexOf(e)>-1}get whitespace(){return this.spec.whitespace||(this.spec.code?"pre":"normal")}hasRequiredAttrs(){for(let e in this.attrs)if(this.attrs[e].isRequired)return!0;return!1}compatibleContent(e){return this==e||this.contentMatch.compatible(e.contentMatch)}computeAttrs(e){return!e&&this.defaultAttrs?this.defaultAttrs:Pt(this.attrs,e)}create(e=null,t,r){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new A(this,this.computeAttrs(e),m.from(t),y.setFrom(r))}createChecked(e=null,t,r){return t=m.from(t),this.checkContent(t),new A(this,this.computeAttrs(e),t,y.setFrom(r))}createAndFill(e=null,t,r){if(e=this.computeAttrs(e),t=m.from(t),t.size){let o=this.contentMatch.fillBefore(t);if(!o)return null;t=o.append(t)}let i=this.contentMatch.matchFragment(t),s=i&&i.fillBefore(m.empty,!0);return s?new A(this,e,t.append(s),y.setFrom(r)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let r=0;r<e.childCount;r++)if(!this.allowsMarks(e.child(r).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){Wt(this.attrs,e,"node",this.name)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let t;for(let r=0;r<e.length;r++)this.allowsMarkType(e[r].type)?t&&t.push(e[r]):t||(t=e.slice(0,r));return t?t.length?t:y.none:e}static compile(e,t){let r=Object.create(null);e.forEach((s,o)=>r[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}};function Qn(n,e,t){let r=t.split("|");return i=>{let s=i===null?"null":typeof i;if(r.indexOf(s)<0)throw new RangeError(`Expected value of type ${r} for attribute ${e} on type ${n}, got ${s}`)}}var Qe=class{constructor(e,t,r){this.hasDefault=Object.prototype.hasOwnProperty.call(r,"default"),this.default=r.default,this.validate=typeof r.validate=="string"?Qn(e,t,r.validate):r.validate}get isRequired(){return!this.hasDefault}},xe=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=Lt(e,i.attrs),this.excluded=null;let s=Jt(this.attrs);this.instance=s?new y(this,s):null}create(e=null){return!e&&this.instance?this.instance:new y(this,Pt(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t<e.length;t++)e[t].type==this&&(e=e.slice(0,t).concat(e.slice(t+1)),t--);return e}isInSet(e){for(let t=0;t<e.length;t++)if(e[t].type==this)return e[t]}checkAttrs(e){Wt(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}},ke=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=Ue.from(e.nodes),t.marks=Ue.from(e.marks||{}),this.nodes=ye.compile(this.spec.nodes,this),this.marks=xe.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=$.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?vt(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:vt(this,o.split(" "))}this.nodeFromJSON=i=>A.fromJSON(this,i),this.markFromJSON=i=>y.fromJSON(this,i),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ye){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new Ke(r,r.defaultAttrs,e,y.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function vt(n,e){let t=[];for(let r=0;r<e.length;r++){let i=e[r],s=n.marks[i],o=s;if(s)t.push(s);else for(let l in n.marks){let a=n.marks[l];(i=="_"||a.spec.group&&a.spec.group.split(" ").indexOf(i)>-1)&&t.push(o=a)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}var $t="http://www.w3.org/2000/svg",Xn={page:["M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z","M14 2v4a2 2 0 0 0 2 2h4","M9 13h6","M9 17h4"],"page-plus":["M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z","M14 2v4a2 2 0 0 0 2 2h4","M9 15h6","M12 12v6"],calendar:["M8 2v4","M16 2v4","M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z","M3 10h18"],block:["M13 4v16","M17 4v16","M19 4H9.5a4.5 4.5 0 0 0 0 9H13"],embed:["M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z","m3.3 7 8.7 5 8.7-5","M12 22V12"]};function qt(n){return[`${$t} svg`,{"mapa-i":"",viewBox:"0 0 24 24","aria-hidden":"true"},...Xn[n].map(e=>[`${$t} path`,{d:e}])]}function we({href:n,kind:e,title:t,label:r,icon:i,shown:s,note:o}){let l={href:n,"mapa-chip":e};t&&(l.title=t),l["aria-label"]=r;let a=["a",l,qt(i),s];return o&&a.push(["span",{"mapa-chip-note":""},o]),a}function Xe({target:n,anchor:e,shown:t},r){let i=t||n;if(r.broken)return["span",{"mapa-chip":"broken"},i];if(r.day)return _n(t,r);if(r.pending)return we({href:r.href,kind:"pending",icon:"page-plus",shown:i,label:`${i}, page not written yet`});let s=r.title||n,o={href:r.href,kind:"team",icon:"page",shown:i,label:`${i}, team page`};return r.alias&&(o.title=`Now called ${s}`,o.label=`${i}, now called ${s}`),e&&(o.kind=o.icon="block",o.label=`${i}, a block in ${s}`),e&&r.blockGone&&(o.kind="block gone",o.label=`${i}, block removed from ${s}`,o.note="block removed"),we(o)}function _n(n,e){return we(n?{href:e.href,kind:"date",icon:"calendar",shown:n,label:`${n}, your note for ${e.day}`}:{href:e.href,kind:"date",icon:"calendar",shown:e.day,label:`${e.day}, your note`})}function Ut(n){return["span",{"mapa-chip":"embed",role:"img","aria-label":`${n}, embedded item, not shown yet`},qt("embed"),n]}var Yn=/^[A-Za-z0-9\-_.~!$&'()*+,;=:[\]<>"]$/u,er=/^[A-Za-z0-9\-._:~!$&'()*+,;=%@]$/u,Ht=/^[0-9A-Fa-f]$/u;function Se(n){let e=tr(n);if(e===null)return!1;switch(e.scheme){case"http":case"https":return e.host!==""&&!e.host.startsWith("[");case"mailto":return e.opaque!==""}return!1}function tr(n){let e=n.indexOf("#"),t=e<0?n:n.slice(0,e),r=e<0?"":n.slice(e+1),i=nr(t);return i===null||r!==""&&!_e(r)?null:i}function nr(n){if(/[\x00-\x1f\x7f]/u.test(n))return null;if(n==="*")return{scheme:"",host:"",opaque:""};let e=rr(n);if(e===null)return null;let t=e.rest,r={scheme:e.name.toLowerCase(),host:"",opaque:""};if(t.endsWith("?")&&t.split("?").length===2?t=t.slice(0,-1):t.includes("?")&&(t=t.slice(0,t.indexOf("?"))),!t.startsWith("/")){if(r.scheme!=="")return r.opaque=t,r;if(t.split("/")[0].includes(":"))return null}if((r.scheme!==""||!t.startsWith("///"))&&t.startsWith("//")){let i=t.slice(2);t="";let s=i.indexOf("/");s>=0&&(t=i.slice(s),i=i.slice(0,s));let o=ir(r.scheme,i);if(o===null)return null;r.host=o}return _e(t)?r:null}function rr(n){for(let e=0;e<n.length;e++){let t=n[e];if(!/^[A-Za-z]$/u.test(t)){if(/^[0-9+\-.]$/u.test(t)){if(e===0)return{name:"",rest:n};continue}return t===":"?e===0?null:{name:n.slice(0,e),rest:n.slice(e+1)}:{name:"",rest:n}}}return{name:"",rest:n}}function ir(n,e){let t=e.lastIndexOf("@"),r=sr(n,t<0?e:e.slice(t+1));if(r===null||t<0)return r;let i=e.slice(0,t);for(let s of i)if(!er.test(s))return null;return _e(i)?r:null}function sr(n,e){let t=e.lastIndexOf("[");if(t>0)return null;if(t===0)return"[";let r=e.indexOf(":");if(r!==-1){let i=e.lastIndexOf(":");if(i!==r&&n!=="http"&&n!=="https"&&(r=i),!/^:[0-9]*$/u.test(e.slice(r)))return null}return or(e)?e:null}function or(n){for(let e=0;e<n.length;e++){let t=n[e];if(t==="%"){if(!Vt(n,e)||parseInt(n[e+1],16)<8&&n.slice(e,e+3)!=="%25")return!1;e+=2}else if(t.charCodeAt(0)<128&&!Yn.test(t))return!1}return!0}function _e(n){for(let e=0;e<n.length;e++)if(n[e]==="%"){if(!Vt(n,e))return!1;e+=2}return!0}function Vt(n,e){return e+2<n.length&&Ht.test(n[e+1])&&Ht.test(n[e+2])}var be="paragraph",R="heading",k="item",T="code",v="quote",N="rule",lr="text",et="code",oe="wiki",Me="web",le="embed",q="[^\\t\\n\\f\\r ]",_t=new RegExp(`^(#{1,6})[ \\t]+${q}`,"u"),ae=/^([ \t]*)([-*+]|[0-9]{1,9}[.)])[ \t]+/u,Z=/^ {0,3}(```|~~~)/u,tt=/^ {0,3}(?:(?:-[ \t]*){3,}|(?:\*[ \t]*){3,}|(?:_[ \t]*){3,})$/u,Yt=/[ \t]\^([A-Za-z0-9-]{1,40})[ \t]*$/u,ar=/^\[([^\]\n]+)\]\(([^)\t\n\f\r ]+)\)/u,cr=/^https?:\/\/[^\t\n\f\r <>()[\]]+[^\t\n\f\r <>()[\].,;:!?'"]/u,hr=/^[0-9]{4}-[0-9]{2}-[0-9]{2}$/u,ur=/^\[([ xX])\][ \t]+/u,jt=/[\t\n\v\f\r \u0085\u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000]/u;function F(n){let e=0,t=n.length;for(;e<t&&jt.test(n[e]);)e++;for(;t>e&&jt.test(n[t-1]);)t--;return n.slice(e,t)}function ce(n,e){let t=0;for(;t<n.length&&e.includes(n[t]);)t++;return n.slice(t)}function Zt(n){let e=0;for(let t of n){let r=t.codePointAt(0);e+=r<128?1:r<2048?2:r<65536?3:4}return e}function ve(n){return U(n).replace(/[ \t\n]+$/u,"")}function U(n){return n.replaceAll(`\r
`,`
`).replaceAll("\r",`
`)}function I(n){let e=U(n).split(`
-`),t=[0],r=[0];for(let s of e)t.push(t[t.length-1]+Zt(s)+1),r.push(r[r.length-1]+s.length+1);let i=[];for(let s=0;s<e.length;){if(F(e[s])===""){s++;continue}let[o,l]=fr(e,s);o.marker=gr(o),o.start=t[s],o.end=o.start+Zt(o.source),o.from=r[s],o.to=o.from+o.source.length,i.push(o),s=l}return i}function se(n,e,t={}){return{kind:n,source:e,level:0,ordered:!1,marker:"",...t}}function fr(n,e){let t=n[e];if(Z.test(t))return pr(n,e);let r=Yt.exec(t);return r?[se(R,t,{level:r[1].length}),e+1]:tt.test(t)?[se(N,t),e+1]:ae.test(t)?dr(n,e):_e(t)?Kt(n,e,v,_e):Kt(n,e,be,en)}function pr(n,e){let t=Z.exec(n[e])[1],r=e+1;for(;r<n.length&&!ce(n[r]," ").startsWith(t);)r++;return r<n.length&&r++,[se(T,n.slice(e,r).join(`
+`),t=[0],r=[0];for(let s of e)t.push(t[t.length-1]+Zt(s)+1),r.push(r[r.length-1]+s.length+1);let i=[];for(let s=0;s<e.length;){if(F(e[s])===""){s++;continue}let[o,l]=fr(e,s);o.marker=gr(o),o.start=t[s],o.end=o.start+Zt(o.source),o.from=r[s],o.to=o.from+o.source.length,i.push(o),s=l}return i}function se(n,e,t={}){return{kind:n,source:e,level:0,ordered:!1,marker:"",...t}}function fr(n,e){let t=n[e];if(Z.test(t))return pr(n,e);let r=_t.exec(t);return r?[se(R,t,{level:r[1].length}),e+1]:tt.test(t)?[se(N,t),e+1]:ae.test(t)?dr(n,e):Ye(t)?Kt(n,e,v,Ye):Kt(n,e,be,en)}function pr(n,e){let t=Z.exec(n[e])[1],r=e+1;for(;r<n.length&&!ce(n[r]," ").startsWith(t);)r++;return r<n.length&&r++,[se(T,n.slice(e,r).join(`
`)),r]}function dr(n,e){let t=ae.exec(n[e]),r=t[1].replaceAll(" "," "),i=e+1;for(;i<n.length&&en(n[i]);)i++;return[se(k,n.slice(e,i).join(`
`),{level:Math.floor(r.length/2),ordered:!/[-*+]/u.test(t[2])}),i]}function Kt(n,e,t,r){let i=e+1;for(;i<n.length&&r(n[i]);)i++;return[se(t,n.slice(e,i).join(`
-`)),i]}function _e(n){return ce(n," ").startsWith(">")}function en(n){return F(n)!==""&&!mr(n)}function mr(n){return Z.test(n)||Yt.test(n)||tt.test(n)||ae.test(n)||_e(n)}function gr(n){if(n.kind===T||n.kind===N)return"";let e=n.source.slice(n.source.lastIndexOf(`
-`)+1),t=_t.exec(e);return t?t[1]:""}function nt(n){let e=n.source;switch(n.kind){case T:return yr(e);case R:e=ce(e,"# ");break;case k:e=e.replace(ae,"");break;case v:e=xr(e);break}return n.marker!==""&&(e=e.replace(_t,"")),e}function yr(n){let e=n.split(`
+`)),i]}function Ye(n){return ce(n," ").startsWith(">")}function en(n){return F(n)!==""&&!mr(n)}function mr(n){return Z.test(n)||_t.test(n)||tt.test(n)||ae.test(n)||Ye(n)}function gr(n){if(n.kind===T||n.kind===N)return"";let e=n.source.slice(n.source.lastIndexOf(`
+`)+1),t=Yt.exec(e);return t?t[1]:""}function nt(n){let e=n.source;switch(n.kind){case T:return yr(e);case R:e=ce(e,"# ");break;case k:e=e.replace(ae,"");break;case v:e=xr(e);break}return n.marker!==""&&(e=e.replace(Yt,"")),e}function yr(n){let e=n.split(`
`);return e.length<=1?"":(Z.test(e[e.length-1])&&(e=e.slice(0,-1)),e.slice(1).join(`
`))}function xr(n){return n.split(`
`).map(e=>(e=ce(e," "),e.startsWith(">")&&(e=e.slice(1)),e.startsWith(" ")?e.slice(1):e)).join(`
@@ -22,9 +22,9 @@ function M(n){this.content=n}M.prototype={constructor:M,find:function(n){for(var
`+t.close),!e&&!fn(i)&&(i+=`
`+r.trimStart()),i}function fn(n){let e=n.split(`
`);return e.length>1&&Te(e[e.length-1],Ce(e[0]))}function ze(n){let e=[];n.forEach(r=>{let i=s=>r.marks.some(o=>o.type.name===s);if(r.isText){let s=r.marks.find(l=>l.type.name==="link"),o=e[e.length-1];i("code")?o?.kind==="code"?o.text+=r.text:e.push({kind:"code",text:r.text}):s?o?.kind==="link"&&o.mark.eq(s)?o.text+=r.text:e.push({kind:"link",text:r.text,mark:s}):e.push({kind:"text",text:r.text,em:i("em"),strong:i("strong")})}else if(r.type.name==="hard_break"){let s=/^[ \t]*/u.exec(r.attrs.indent??"")[0];e.push({kind:"text",text:`
-`+s,em:i("em"),strong:i("strong")})}else e.push({kind:"atom",text:_r(r)})});let t="";for(let r=0;r<e.length;){let i=e[r];if(i.kind==="text"){let s=r;for(;s<e.length&&e[s].kind==="text";)s++;t+=Qr(e.slice(r,s)),r=s;continue}i.kind==="code"?t+="`"+i.text+"`":i.kind==="link"?t+=Gr(i):t+=i.text,r++}return U(t)}function Gr({text:n,mark:e}){return e.attrs.bare&&n===e.attrs.href?n:`[${n}](${e.attrs.href})`}function Qr(n){return pn(n,"em",e=>Xr(e),"*")}function Xr(n){return pn(n,"strong",e=>e.map(t=>t.text).join(""),"**")}function pn(n,e,t,r){let i="";for(let s=0;s<n.length;){let o=s;for(;o<n.length&&n[o][e]===n[s][e];)o++;let l=t(n.slice(s,o));i+=n[s][e]?Yr(l,r):l,s=o}return i}function Yr(n,e){let t=/^([\t\n\f\r ]*)([^]*?)([\t\n\f\r ]*)$/u.exec(n);return t[2]===""?n:t[1]+e+t[2]+e+t[3]}function _r(n){let e=n.attrs;return e.source!=null&&ei(n,e.source)?e.source:n.type.name==="embed"?`![[${e.ref}]]`:`[[${n.type.name==="datelink"?e.date:e.target}${e.anchor?"#^"+e.anchor:""}${e.shown?"|"+e.shown:""}]]`}function ei(n,e){let t=Oe(e);if(t.length!==1||t[0].source!==e)return!1;let r=t[0];if(n.type.name==="embed")return r.kind===le&&r.text.slice(3,-2)===n.attrs.ref;if(r.kind!==oe)return!1;let i=n.type.name==="datelink";return K(r.target)===i&&r.target===(i?n.attrs.date:n.attrs.target)&&r.anchor===(n.attrs.anchor??"")&&r.text===(n.attrs.shown??"")}function O(n,e,t={}){let r=t.fresh??new Set,i=t.joins??new Set,s=E(n),o=new Set;for(let h of s){let f=h.node.attrs.origin;h.origin=f,h.first=f!=null&&!o.has(f),f!=null&&o.add(f),h.entry=h.first?e?.get(f):void 0,h.untouched=!r.has(h.index)&&Hr(h,h.entry),h.text=h.untouched?h.entry.source:Re(h)}let l=-1;s.forEach((h,f)=>{h.text!==""&&(l=f)});for(let h of s.slice(0,Math.max(l,0)))h.kind===T&&(h.untouched&&fn(h.text)||(h.untouched=!1,h.text=Re(h,{last:!1})));let a=s.filter(h=>h.text!==""),c="";a.forEach((h,f)=>{f===0?t.edges!==!1&&h.entry?.leading!=null&&(c+=h.entry.leading):(h.seam=ti(a[f-1],h,i.has(h.index)),c+=h.seam),c+=h.text});let u=a[a.length-1];return t.edges!==!1&&u?.entry?.trailing!=null&&(c+=u.entry.trailing),{body:t.raw?U(c):ve(c),blocks:s,emitted:a}}function lt(n,e,t){return O(n,e,t).body}function ti(n,e,t){if(!t&&n.first&&e.first){if(n.entry&&n.entry.next===e.origin&&n.entry.after!=null)return n.entry.after;if(e.entry&&e.entry.prev===n.origin&&e.entry.before!=null)return e.entry.before}return ni(n.kind,e.kind)}function ni(n,e){return n===k&&e===k?`
+`+s,em:i("em"),strong:i("strong")})}else e.push({kind:"atom",text:Yr(r)})});let t="";for(let r=0;r<e.length;){let i=e[r];if(i.kind==="text"){let s=r;for(;s<e.length&&e[s].kind==="text";)s++;t+=Qr(e.slice(r,s)),r=s;continue}i.kind==="code"?t+="`"+i.text+"`":i.kind==="link"?t+=Gr(i):t+=i.text,r++}return U(t)}function Gr({text:n,mark:e}){return e.attrs.bare&&n===e.attrs.href?n:`[${n}](${e.attrs.href})`}function Qr(n){return pn(n,"em",e=>Xr(e),"*")}function Xr(n){return pn(n,"strong",e=>e.map(t=>t.text).join(""),"**")}function pn(n,e,t,r){let i="";for(let s=0;s<n.length;){let o=s;for(;o<n.length&&n[o][e]===n[s][e];)o++;let l=t(n.slice(s,o));i+=n[s][e]?_r(l,r):l,s=o}return i}function _r(n,e){let t=/^([\t\n\f\r ]*)([^]*?)([\t\n\f\r ]*)$/u.exec(n);return t[2]===""?n:t[1]+e+t[2]+e+t[3]}function Yr(n){let e=n.attrs;return e.source!=null&&ei(n,e.source)?e.source:n.type.name==="embed"?`![[${e.ref}]]`:`[[${n.type.name==="datelink"?e.date:e.target}${e.anchor?"#^"+e.anchor:""}${e.shown?"|"+e.shown:""}]]`}function ei(n,e){let t=Oe(e);if(t.length!==1||t[0].source!==e)return!1;let r=t[0];if(n.type.name==="embed")return r.kind===le&&r.text.slice(3,-2)===n.attrs.ref;if(r.kind!==oe)return!1;let i=n.type.name==="datelink";return K(r.target)===i&&r.target===(i?n.attrs.date:n.attrs.target)&&r.anchor===(n.attrs.anchor??"")&&r.text===(n.attrs.shown??"")}function O(n,e,t={}){let r=t.fresh??new Set,i=t.joins??new Set,s=E(n),o=new Set;for(let h of s){let f=h.node.attrs.origin;h.origin=f,h.first=f!=null&&!o.has(f),f!=null&&o.add(f),h.entry=h.first?e?.get(f):void 0,h.untouched=!r.has(h.index)&&Hr(h,h.entry),h.text=h.untouched?h.entry.source:Re(h)}let l=-1;s.forEach((h,f)=>{h.text!==""&&(l=f)});for(let h of s.slice(0,Math.max(l,0)))h.kind===T&&(h.untouched&&fn(h.text)||(h.untouched=!1,h.text=Re(h,{last:!1})));let a=s.filter(h=>h.text!==""),c="";a.forEach((h,f)=>{f===0?t.edges!==!1&&h.entry?.leading!=null&&(c+=h.entry.leading):(h.seam=ti(a[f-1],h,i.has(h.index)),c+=h.seam),c+=h.text});let u=a[a.length-1];return t.edges!==!1&&u?.entry?.trailing!=null&&(c+=u.entry.trailing),{body:t.raw?U(c):ve(c),blocks:s,emitted:a}}function lt(n,e,t){return O(n,e,t).body}function ti(n,e,t){if(!t&&n.first&&e.first){if(n.entry&&n.entry.next===e.origin&&n.entry.after!=null)return n.entry.after;if(e.entry&&e.entry.prev===n.origin&&e.entry.before!=null)return e.entry.before}return ni(n.kind,e.kind)}function ni(n,e){return n===k&&e===k?`
`:`
-`}function at(n){let e=new Set;return n.map(t=>{if(t.kind===R)return`${R}:${Math.min(Math.max(t.node.attrs.level,1),6)}`;if(t.kind!==k)return t.kind;let r=!e.has(t.listPos);return e.add(t.listPos),`${k}:${t.list}:${t.depth}:${r}`})}function ri(n,e){return at(E(G(n,I(e),{trailing:!1})))}function dn(n){return at(n)}function ii(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)if(n[r]!==e[r])return r;return n.length===e.length?-1:t}function De(n,e){let t=n.type.schema,r=l=>{let a=O(n,e,l);return a.shapes=at(a.emitted),a.mismatch=ii(a.shapes,ri(t,a.body)),a},i=new Set,s=new Set,o=r({});for(let l=0;o.mismatch>=0&&l<4;l++){let a=[-1,0,1,2].map(c=>o.emitted[o.mismatch+c]);for(let c of a)c&&(s.add(c.index),l>=2&&i.add(c.index));o=r({fresh:i,joins:s})}if(o.mismatch>=0){let l=new Set(o.blocks.map(a=>a.index));o=r({fresh:l,joins:l})}return{ok:o.mismatch<0,body:o.body,shapes:o.shapes,fixed:s.size>0}}var gn=65535,yn=Math.pow(2,16);function si(n,e){return n+e*yn}function mn(n){return n&gn}function oi(n){return(n-(n&gn))/yn}var xn=1,kn=2,Fe=4,wn=8,Be=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&wn)>0}get deletedBefore(){return(this.delInfo&(xn|Fe))>0}get deletedAfter(){return(this.delInfo&(kn|Fe))>0}get deletedAcross(){return(this.delInfo&Fe)>0}},z=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=mn(e);if(!this.inverted)for(let i=0;i<r;i++)t+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+t+oi(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,r){let i=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?i:0);if(a>e)break;let c=this.ranges[l+s],u=this.ranges[l+o],h=a+c;if(e<=h){let f=c?e==a?-1:e==h?1:t:t,p=a+i+(f<0?0:u);if(r)return p;let g=e==(t<0?a:h)?null:si(l/3,e-a),b=e==a?kn:e==h?xn:Fe;return(t<0?e!=a:e!=h)&&(b|=wn),new Be(p,b,g)}i+=u-c}return r?e+i:new Be(e+i,0,null)}touches(e,t){let r=0,i=mn(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?r:0);if(a>e)break;let c=this.ranges[l+s],u=a+c;if(e<=u&&l==i*3)return!0;r+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i<this.ranges.length;i+=3){let o=this.ranges[i],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),c=this.ranges[i+t],u=this.ranges[i+r];e(l,l+c,a,a+u),s+=u-c}}invert(){return new n(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?n.empty:new n(e<0?[0,-e,0]:[0,0,e])}};z.empty=new z([]);var ct=Object.create(null),w=class{getMap(){return z.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=ct[t.stepType];if(!r)throw new RangeError(`No step type ${t.stepType} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in ct)throw new RangeError("Duplicate use of step JSON ID "+e);return ct[e]=t,t.prototype.jsonID=e,t}},S=class n{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new n(e,null)}static fail(e){return new n(null,e)}static fromReplace(e,t,r,i){try{return n.ok(e.replace(t,r,i))}catch(s){if(s instanceof D)return n.fail(s.message);throw s}}};function pt(n,e,t){let r=[];for(let i=0;i<n.childCount;i++){let s=n.child(i);s.content.size&&(s=s.copy(pt(s.content,e,s))),s.isInline&&(s=e(s,t,i)),r.push(s)}return m.fromArray(r)}var Je=class n extends w{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=e.resolve(this.from),i=r.node(r.sharedDepth(this.to)),s=new d(pt(t.content,(o,l)=>!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return S.fromReplace(e,this.from,this.to,s)}invert(){return new Pe(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};w.jsonID("addMark",Je);var Pe=class n extends w{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new d(pt(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return S.fromReplace(e,this.from,this.to,r)}invert(){return new Je(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};w.jsonID("removeMark",Pe);var We=class n extends w{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return S.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return S.fromReplace(e,this.pos,this.pos+1,new d(m.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;i<t.marks.length;i++)if(!t.marks[i].isInSet(r))return new n(this.pos,t.marks[i]);return new n(this.pos,this.mark)}}return new Le(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new n(t.pos,e.markFromJSON(t.mark))}};w.jsonID("addNodeMark",We);var Le=class n extends w{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return S.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return S.fromReplace(e,this.pos,this.pos+1,new d(m.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new We(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new n(t.pos,e.markFromJSON(t.mark))}};w.jsonID("removeNodeMark",Le);var X=class n extends w{constructor(e,t,r,i=!1){super(),this.from=e,this.to=t,this.slice=r,this.structure=i}apply(e){return this.structure&&ht(e,this.from,this.to)?S.fail("Structure replace would overwrite content"):S.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new z([this.from,this.to-this.from,this.slice.size])}invert(e){return new n(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),r=this.from==this.to&&n.MAP_BIAS<0?t:e.mapResult(this.from,1);return r.deletedAcross&&t.deletedAcross?null:new n(r.pos,Math.max(r.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof n)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?d.empty:new d(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new n(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?d.empty:new d(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new n(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new n(t.from,t.to,d.fromJSON(e,t.slice),!!t.structure)}};X.MAP_BIAS=1;w.jsonID("replace",X);var he=class n extends w{constructor(e,t,r,i,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=r,this.gapTo=i,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(ht(e,this.from,this.gapFrom)||ht(e,this.gapTo,this.to)))return S.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return S.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,t.content);return r?S.fromReplace(e,this.from,this.to,r):S.fail("Content does not fit in gap")}getMap(){return new z([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new n(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),i=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return t.deletedAcross&&r.deletedAcross||i<t.pos||s>r.pos?null:new n(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,d.fromJSON(e,t.slice),t.insert,!!t.structure)}};w.jsonID("replaceAround",he);function ht(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}var ut=class n extends w{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return S.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return S.fromReplace(e,this.pos,this.pos+1,new d(m.from(i),0,t.isLeaf?0:1))}getMap(){return z.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};w.jsonID("attr",ut);var ft=class n extends w{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return S.ok(r)}getMap(){return z.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};w.jsonID("docAttr",ft);var ue=class extends Error{};ue=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};ue.prototype=Object.create(Error.prototype);ue.prototype.constructor=ue;ue.prototype.name="TransformError";var dt=Object.create(null),x=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new gt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=d.empty){let r=t.content.lastChild,i=null;for(let l=0;l<t.openEnd;l++)i=r,r=r.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:c}=o[l],u=e.mapping.slice(s);e.replaceRange(u.map(a.pos),u.map(c.pos),l?d.empty:t),l==0&&bn(e,s,(r?r.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,t){let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:o,$to:l}=i[s],a=e.mapping.slice(r),c=a.map(o.pos),u=a.map(l.pos);s?e.deleteRange(c,u):(e.replaceRangeWith(c,u,t),bn(e,r,t.isInline?-1:1))}}static findFrom(e,t,r=!1){let i=e.parent.inlineContent?new C(e):Y(e.node(0),e.parent,e.pos,e.index(),t,r);if(i)return i;for(let s=e.depth-1;s>=0;s--){let o=t<0?Y(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Y(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new V(e.node(0))}static atStart(e){return Y(e,e,0,0,1)||new V(e)}static atEnd(e){return Y(e,e,e.content.size,e.childCount,-1)||new V(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=dt[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in dt)throw new RangeError("Duplicate use of selection JSON ID "+e);return dt[e]=t,t.prototype.jsonID=e,t}getBookmark(){return C.between(this.$anchor,this.$head).getBookmark()}};x.prototype.visible=!0;var gt=class{constructor(e,t){this.$from=e,this.$to=t}},Sn=!1;function Mn(n){!Sn&&!n.parent.inlineContent&&(Sn=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var C=class n extends x{constructor(e,t=e){Mn(e),Mn(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return x.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=d.empty){if(super.replace(e,t),t==d.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new $e(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=x.findFrom(t,r,!0)||x.findFrom(t,-r,!0);if(s)t=s.$head;else return x.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(x.findFrom(e,-r,!0)||x.findFrom(e,r,!0)).$anchor,e.pos<t.pos!=i<0&&(e=t))),new n(e,t)}};x.jsonID("text",C);var $e=class n{constructor(e,t){this.anchor=e,this.head=t}map(e){return new n(e.map(this.anchor),e.map(this.head))}resolve(e){return C.between(e.resolve(this.anchor),e.resolve(this.head))}},J=class n extends x{constructor(e){let t=e.nodeAfter,r=e.node(0).resolve(e.pos+t.nodeSize);super(e,r),this.node=t}map(e,t){let{deleted:r,pos:i}=t.mapResult(this.anchor),s=e.resolve(i);return r?x.near(s):new n(s)}content(){return new d(m.from(this.node),0,0)}eq(e){return e instanceof n&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new yt(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new n(e.resolve(t.anchor))}static create(e,t){return new n(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};J.prototype.visible=!1;x.jsonID("node",J);var yt=class n{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:r}=e.mapResult(this.anchor);return t?new $e(r,r):new n(r)}resolve(e){let t=e.resolve(this.anchor),r=t.nodeAfter;return r&&J.isSelectable(r)?new J(t):x.near(t)}},V=class n extends x{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=d.empty){if(t==d.empty){e.delete(0,e.doc.content.size);let r=x.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new n(e)}map(e){return new n(e)}eq(e){return e instanceof n}getBookmark(){return li}};x.jsonID("all",V);var li={map(){return this},resolve(n){return new V(n)}};function Y(n,e,t,r,i,s=!1){if(e.inlineContent)return C.create(n,t);for(let o=r-(i>0?0:1);i>0?o<e.childCount:o>=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&J.isSelectable(l))return J.create(n,t-(i<0?l.nodeSize:0))}else{let a=Y(n,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function bn(n,e,t){let r=n.steps.length-1;if(r<e)return;let i=n.steps[r];if(!(i instanceof X||i instanceof he))return;let s=n.mapping.maps[r],o;s.forEach((l,a,c,u)=>{o==null&&(o=u)}),n.setSelection(x.near(n.doc.resolve(o),t))}function vn(n,e){return!e||!n?n:n.bind(e)}var _=class{constructor(e,t,r){this.name=e,this.init=vn(t.init,r),this.apply=vn(t.apply,r)}},Yi=[new _("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new _("selection",{init(n,e){return n.selection||x.atStart(e.doc)},apply(n){return n.selection}}),new _("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new _("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];function On(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=On(i,e,{})),t[r]=i}return t}var ee=class{constructor(e){this.spec=e,this.props={},e.props&&On(e.props,this,this.props),this.key=e.key?e.key.key:En("plugin")}getState(e){return e[this.key]}},mt=Object.create(null);function En(n){return n in mt?n+"$"+ ++mt[n]:(mt[n]=0,n+"$")}var te=class{constructor(e="key"){this.key=En(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var qe=class{constructor(){this.issued=0,this.table=new Map}mint(){return++this.issued}get(e){return this.table.get(e)}record(e,t){if(this.table.has(e))throw new Error(`origin ${e} is already recorded`);this.table.set(e,Object.freeze(t))}},ne=new te("mapa-fidelity");function re(n,e,t,r={}){let i=U(t),s=I(i),o=s.map(()=>e.mint()),l=G(n,s,{origin:u=>o[u],...r}),a=E(l).slice(0,s.length),c=r.edges!==!1;return s.forEach((u,h)=>{let f=s[h-1],p=s[h+1];e.record(o[h],{node:a[h].node,source:u.source,context:B(a[h]),prev:f?o[h-1]:null,next:p?o[h+1]:null,before:f?i.slice(f.to,u.from):null,after:p?i.slice(u.to,p.from):null,leading:c&&!f?i.slice(0,u.from):null,trailing:c&&!p?i.slice(u.to):null})}),{doc:l,nodes:a,origins:o}}function ai(n,e){let t=new qe,{doc:r}=re(n,t,e);return{doc:r,fidelity:t}}function ci(n,e){return B(n)===B(e)&&ot(H(n),e.node)}function Tn(n,e,t){let r=n.length,i=e.length,s=Array.from({length:r+1},()=>new Int32Array(i+1));for(let l=r-1;l>=0;l--)for(let a=i-1;a>=0;a--)s[l][a]=t(n[l],e[a])?s[l+1][a+1]+1:Math.max(s[l+1][a],s[l][a+1]);let o=[];for(let l=0,a=0;l<r&&a<i;)t(n[l],e[a])?(o.push([l,a]),l++,a++):s[l+1][a]>=s[l][a+1]?l++:a++;return o}function Nn(n,e,t){let r=n.state,{nodes:i,origins:s}=re(r.schema,e,t),o=i.slice(0,s.length),l=O(r.doc,e).emitted,a=r.tr;for(let[c,u]of Tn(l,o,ci))a.setNodeAttribute(l[c].pos,"origin",s[u]);return a.setMeta("addToHistory",!1).setMeta(ne,{rebuilt:!0}),n.dispatch(a),{ok:lt(n.state.doc,e)===ve(t)}}function xt(n,e){let t=e.topNodeType.create(null,n),{emitted:r}=O(t,null,{raw:!0}),i=dn(r);return JSON.stringify(r.map((s,o)=>[i[o],s.text]))}function An(n,e,t){let r=n.doc.type.schema,{doc:i}=re(r,e,t),s=[];n.doc.forEach((f,p)=>{let g=xt(f,r);g!=="[]"&&s.push({node:f,offset:p,key:g})});let o=[];i.forEach(f=>{let p=xt(f,r);p!=="[]"&&o.push({node:f,key:p})});let l=Tn(s,o,(f,p)=>f.key===p.key),a=[],c=[-1,-1];for(let f of[...l,[s.length,o.length]]){let[p,g]=[c[0]+1,c[1]+1];if(f[0]>p||f[1]>g){let b=p<s.length?s[p].offset:s[s.length-1]?s[s.length-1].offset+s[s.length-1].node.nodeSize:0,P=f[0]>p?s[f[0]-1].offset+s[f[0]-1].node.nodeSize:b;a.push({from:b,to:P,nodes:o.slice(g,f[1]).map(fe=>fe.node)})}c=f}let u=n.selection.head,h=null;for(let f of a.reverse()){h===null&&u>=f.from&&u<=f.to&&(h={left:hi(n.doc,u,f.to),gap:f});let p=[];n.doc.nodesBetween(f.from,f.to,(g,b)=>(b>=f.from&&xt(g,r)==="[]"&&p.push(g),!1)),n.replaceWith(f.from,f.to,m.from([...f.nodes,...p])),f.size=[...f.nodes,...p].reduce((g,b)=>g+b.nodeSize,0)}if(h){let f=n.mapping.map(h.gap.from,-1),p=ui(n.doc,f,f+h.gap.size,h.left);n.setSelection(C.near(n.doc.resolve(p),-1))}return n}function hi(n,e,t){let r=0;return n.nodesBetween(e,t,(i,s)=>{i.isText?r+=Math.min(s+i.nodeSize,t)-Math.max(s,e):i.isInline&&(r+=1)}),r}function ui(n,e,t,r){let i=null,s=[];n.nodesBetween(e,t,(o,l)=>{if(o.isTextblock)return s.push({node:o,pos:l}),!1});for(let{node:o,pos:l}of s.reverse()){let a=o.content.size;if(r<=a){i=l+1+a-r;break}r-=a}return i===null&&(i=s.length?s[s.length-1].pos+1:e),Math.min(Math.max(i,0),n.content.size)}function Rn(n,e,t){let r=An(n.state.tr,e,t);return r.docChanged&&n.dispatch(r.scrollIntoView()),Nn(n,e,t)}function fi(n,e){let t=De(n.state.doc,e);if(t.ok)return{body:t.body,shapes:t.shapes,adopted:!1};Rn(n,e,t.body);let r=De(n.state.doc,e);return{body:r.body,shapes:r.shapes,adopted:!0}}var pi={paragraph:["marker"],heading:["level","marker"],code_block:["fence","info","closed","close"],list_item:["indent","bullet","number","delim","task","checked","marker"],blockquote:["prefix","marker"]};function Cn(n){return n.kind===k||n.kind===v?n.holder:n.node}function di(n,e){if(n.kind===N)return null;let t=Re(n);if(t==="")return null;let r=I(t);if(r.length!==1||r[0].kind!==n.kind)return"structural";let i=E(G(e,r,{trailing:!1}))[0];if(n.kind===k&&i.list!==n.list)return"structural";let s=Cn(n),o=Cn(i),l=[];for(let f of pi[s.type.name]??[])JSON.stringify(s.attrs[f])!==JSON.stringify(o.attrs[f])&&l.push([f,o.attrs[f]]);let a=H(n).content,c=i.node.content,u=a.findDiffStart(c);if(u===null&&l.length===0)return null;let h=null;if(u!==null){let{a:f,b:p}=a.findDiffEnd(c),g=u-Math.min(f,p);g>0&&(f+=g,p+=g),h={from:u,to:f,content:c.cut(u,p)}}return{block:n,attrs:l,diff:h,text:t,node:i.node}}function mi(n,{block:e,attrs:t,diff:r},i){if(r){let o=e.pos+1;n.replaceWith(o+r.from,o+r.to,r.content)}let s=e.kind===k||e.kind===v?e.holderPos:e.pos;for(let[o,l]of t)n.setNodeAttribute(s,o,l);n.setNodeAttribute(e.pos,"origin",i)}function gi(n,e,t=null){let r=n.tr;return In(r,e,t),r.docChanged?r:null}function yi(n,e){let t=n.blocks.filter(i=>!i.untouched);if(!e)return t;let r=new Map(E(e).map(i=>[i.node,B(i)]));return t.filter(i=>r.get(i.node)!==B(i))}function In(n,e,t){let r=n.doc.type.schema,i=O(n.doc,e),s=[];for(let h of yi(i,t)){let f=di(h,r);if(f==="structural"){An(n,e,i.body);return}f&&s.push(f)}if(s.length===0)return;let o=new Map(s.map(h=>[h.block,e.mint()])),l=h=>o.get(h)??(h.first?h.origin:null),{emitted:a}=i,c=s.map(({block:h,text:f,node:p})=>{let g=a.indexOf(h),b=a[g-1],P=a[g+1],fe=o.get(h);return{origin:fe,source:f,node:p.type.create({...p.attrs,origin:fe},p.content,p.marks),prev:b?l(b):null,next:P?l(P):null,before:b?h.seam:null,after:P?P.seam:null,leading:g===0?h.entry?.leading??null:null,trailing:g>=0&&!P?h.entry?.trailing??null:null}});for(let h of[...s].reverse())mi(n,h,o.get(h.block));let u=new Map(E(n.doc).map(h=>[h.node.attrs.origin,h]));for(let{origin:h,...f}of c)e.record(h,{...f,context:B(u.get(h))})}function xi(n,e){let t=o=>{let l=new Map;for(let a of E(o)){let c=a.holder.attrs.marker;c&&l.set(c,(l.get(c)??0)+1)}return l},r=e?t(e):new Map,i=new Set(e?E(e).map(o=>o.holder):[]),s=E(n.doc);for(let[o,l]of t(n.doc)){let a=l-Math.max(r.get(o)??0,1);if(a<=0)continue;let[,...c]=s.filter(h=>h.holder.attrs.marker===o),u=[...c.filter(h=>!i.has(h.holder)).reverse(),...c.filter(h=>i.has(h.holder)).reverse()];for(let h of u.slice(0,a))n.setNodeAttribute(h.holderPos,"marker",null)}}function ki(n){return Math.floor(String(n??"").replaceAll(" "," ").length/2)}function wi(n,e){let t=-1;for(let s of O(n.doc,e).emitted){if(s.kind!==k){t=-1;continue}let o=ki(s.holder.attrs.indent),l=" ".repeat(s.depth);Math.min(o,t+1)!==s.depth&&s.depth<=t+1&&s.holder.attrs.indent!==l&&n.setNodeAttribute(s.holderPos,"indent",l),t=s.depth}let r=[],i=(s,o)=>{let l=o,a=null;s.forEach(c=>{a&&a.type===c.type&&(c.type.name==="bullet_list"||c.type.name==="ordered_list")&&r.push(l),a=c,l+=c.nodeSize})};i(n.doc,0),n.doc.descendants((s,o)=>{if(s.isTextblock)return!1;i(s,o+1)});for(let s of r.sort((o,l)=>l-o))n.join(s)}function Si(n){let e=n.doc.lastChild;(!e||e.type.name!=="paragraph")&&n.insert(n.doc.content.size,n.doc.type.schema.nodes.paragraph.create())}function zn(n,e,t=null){let r=n.tr;for(let i=0;i<4;i++){let s=r.doc;if(In(r,e,t),xi(r,t),wi(r,e),Si(r),r.doc===s)break}return r.docChanged?r:null}function Mi(n,e={}){let t=null,r=null,i=()=>e.composing?e.composing():t?.composing??!1;return new ee({key:ne,state:{init:()=>n,apply:(s,o)=>o},view(s){return t=s,{destroy(){t=null}}},props:{handleDOMEvents:{compositionend(s){return setTimeout(()=>{t===s&&r&&s.dispatch(s.state.tr.setMeta(ne,{composed:!0}))},50),!1}}},appendTransaction(s,o,l){if(!s.some(h=>h.docChanged&&!h.getMeta(ne)?.rebuilt)&&!r)return null;if(i())return r=r??o.doc,null;let c=r??o.doc;r=null;let u=zn(l,n,c);return u?u.setMeta(ne,{settled:!0}):null}})}var kt="application/x-mapa";function wt(n,e,t=n.selection.from,r=n.selection.to){let i=n.doc.slice(t,r,!0),s=n.schema.topNodeType.create(null,i.content),{body:o,emitted:l}=O(s,e,{edges:!1,raw:!0}),a=JSON.stringify({v:1,sources:l.map(c=>c.text),seams:l.slice(1).map(c=>c.seam)});return{text:o,mapa:a}}function bi(n){let e;try{e=JSON.parse(n)}catch{return null}let{sources:t,seams:r}=e??{};if(e?.v!==1||!Array.isArray(t)||!Array.isArray(r)||t.length===0||r.length!==t.length-1||![...t,...r].every(o=>typeof o=="string")||!r.every(o=>/^\n(?:[^\n]*\n)*$/u.test(o)))return null;let i=t.map((o,l)=>(l?r[l-1]:"")+o).join(""),s=I(i);return s.length!==t.length||s.some((o,l)=>o.source!==t[l])?null:i}function vi(n,e){let{from:t,to:r}=n.selection,i=new Set;for(let s of O(n.doc,e).emitted){let o=s.holder.attrs.marker,l=s.holderPos>=t&&s.holderPos+s.holder.nodeSize<=r;o&&!l&&i.add(o)}return i}function Dn(n,e){let t=[];return n.forEach(r=>{let i=r;!r.isTextblock&&!r.isLeaf&&(i=r.copy(Dn(r.content,e))),i.attrs.marker&&e.has(i.attrs.marker)&&(i=i.type.create({...i.attrs,marker:null},i.content,i.marks)),t.push(i)}),m.from(t)}function Fn(n,e,t){let r=vi(e,t);return r.size===0?n:new d(Dn(n.content,r),n.openStart,n.openEnd)}function Bn(n,e,t){let r=bi(t);if(r===null)return null;let{doc:i}=re(n.schema,e,r,{trailing:!1,edges:!1}),s=Fn(d.maxOpen(i.content),n,e),{$from:o,empty:l}=n.selection;if(l&&o.depth===1&&o.parent.type.name==="paragraph"&&o.parent.content.size===0){let a=n.tr.replaceWith(o.before(),o.after(),s.content),c=o.before()+s.content.size;return a.setSelection(C.near(a.doc.resolve(c),-1))}return n.tr.replaceSelection(s)}function Jn(n,e){let t=it(n,e,{trailing:!1});return t.childCount?d.maxOpen(t.content):d.empty}function Oi(n,e){let t=e.content,r=t.firstChild;if(!r)return"";r.isInline?t=m.from(n.nodes.paragraph.create(null,t)):r.type.name==="list_item"&&(t=m.from(n.nodes.bullet_list.create(null,t)));try{return O(n.topNodeType.create(null,t),null,{edges:!1,raw:!0}).body}catch{return e.content.textBetween(0,e.content.size,`
+`}function at(n){let e=new Set;return n.map(t=>{if(t.kind===R)return`${R}:${Math.min(Math.max(t.node.attrs.level,1),6)}`;if(t.kind!==k)return t.kind;let r=!e.has(t.listPos);return e.add(t.listPos),`${k}:${t.list}:${t.depth}:${r}`})}function ri(n,e){return at(E(G(n,I(e),{trailing:!1})))}function dn(n){return at(n)}function ii(n,e){let t=Math.min(n.length,e.length);for(let r=0;r<t;r++)if(n[r]!==e[r])return r;return n.length===e.length?-1:t}function De(n,e){let t=n.type.schema,r=l=>{let a=O(n,e,l);return a.shapes=at(a.emitted),a.mismatch=ii(a.shapes,ri(t,a.body)),a},i=new Set,s=new Set,o=r({});for(let l=0;o.mismatch>=0&&l<4;l++){let a=[-1,0,1,2].map(c=>o.emitted[o.mismatch+c]);for(let c of a)c&&(s.add(c.index),l>=2&&i.add(c.index));o=r({fresh:i,joins:s})}if(o.mismatch>=0){let l=new Set(o.blocks.map(a=>a.index));o=r({fresh:l,joins:l})}return{ok:o.mismatch<0,body:o.body,shapes:o.shapes,fixed:s.size>0}}var gn=65535,yn=Math.pow(2,16);function si(n,e){return n+e*yn}function mn(n){return n&gn}function oi(n){return(n-(n&gn))/yn}var xn=1,kn=2,Fe=4,wn=8,Be=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&wn)>0}get deletedBefore(){return(this.delInfo&(xn|Fe))>0}get deletedAfter(){return(this.delInfo&(kn|Fe))>0}get deletedAcross(){return(this.delInfo&Fe)>0}},z=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=mn(e);if(!this.inverted)for(let i=0;i<r;i++)t+=this.ranges[i*3+2]-this.ranges[i*3+1];return this.ranges[r*3]+t+oi(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,r){let i=0,s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?i:0);if(a>e)break;let c=this.ranges[l+s],u=this.ranges[l+o],h=a+c;if(e<=h){let f=c?e==a?-1:e==h?1:t:t,p=a+i+(f<0?0:u);if(r)return p;let g=e==(t<0?a:h)?null:si(l/3,e-a),b=e==a?kn:e==h?xn:Fe;return(t<0?e!=a:e!=h)&&(b|=wn),new Be(p,b,g)}i+=u-c}return r?e+i:new Be(e+i,0,null)}touches(e,t){let r=0,i=mn(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;l<this.ranges.length;l+=3){let a=this.ranges[l]-(this.inverted?r:0);if(a>e)break;let c=this.ranges[l+s],u=a+c;if(e<=u&&l==i*3)return!0;r+=this.ranges[l+o]-c}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i<this.ranges.length;i+=3){let o=this.ranges[i],l=o-(this.inverted?s:0),a=o+(this.inverted?0:s),c=this.ranges[i+t],u=this.ranges[i+r];e(l,l+c,a,a+u),s+=u-c}}invert(){return new n(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?n.empty:new n(e<0?[0,-e,0]:[0,0,e])}};z.empty=new z([]);var ct=Object.create(null),w=class{getMap(){return z.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let r=ct[t.stepType];if(!r)throw new RangeError(`No step type ${t.stepType} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in ct)throw new RangeError("Duplicate use of step JSON ID "+e);return ct[e]=t,t.prototype.jsonID=e,t}},S=class n{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new n(e,null)}static fail(e){return new n(null,e)}static fromReplace(e,t,r,i){try{return n.ok(e.replace(t,r,i))}catch(s){if(s instanceof D)return n.fail(s.message);throw s}}};function pt(n,e,t){let r=[];for(let i=0;i<n.childCount;i++){let s=n.child(i);s.content.size&&(s=s.copy(pt(s.content,e,s))),s.isInline&&(s=e(s,t,i)),r.push(s)}return m.fromArray(r)}var Je=class n extends w{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=e.resolve(this.from),i=r.node(r.sharedDepth(this.to)),s=new d(pt(t.content,(o,l)=>!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return S.fromReplace(e,this.from,this.to,s)}invert(){return new Pe(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};w.jsonID("addMark",Je);var Pe=class n extends w{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new d(pt(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return S.fromReplace(e,this.from,this.to,r)}invert(){return new Je(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};w.jsonID("removeMark",Pe);var We=class n extends w{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return S.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return S.fromReplace(e,this.pos,this.pos+1,new d(m.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;i<t.marks.length;i++)if(!t.marks[i].isInSet(r))return new n(this.pos,t.marks[i]);return new n(this.pos,this.mark)}}return new Le(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new n(t.pos,e.markFromJSON(t.mark))}};w.jsonID("addNodeMark",We);var Le=class n extends w{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return S.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return S.fromReplace(e,this.pos,this.pos+1,new d(m.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new We(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if(typeof t.pos!="number")throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new n(t.pos,e.markFromJSON(t.mark))}};w.jsonID("removeNodeMark",Le);var X=class n extends w{constructor(e,t,r,i=!1){super(),this.from=e,this.to=t,this.slice=r,this.structure=i}apply(e){return this.structure&&ht(e,this.from,this.to)?S.fail("Structure replace would overwrite content"):S.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new z([this.from,this.to-this.from,this.slice.size])}invert(e){return new n(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.to,-1),r=this.from==this.to&&n.MAP_BIAS<0?t:e.mapResult(this.from,1);return r.deletedAcross&&t.deletedAcross?null:new n(r.pos,Math.max(r.pos,t.pos),this.slice,this.structure)}merge(e){if(!(e instanceof n)||e.structure||this.structure)return null;if(this.from+this.slice.size==e.from&&!this.slice.openEnd&&!e.slice.openStart){let t=this.slice.size+e.slice.size==0?d.empty:new d(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new n(this.from,this.to+(e.to-e.from),t,this.structure)}else if(e.to==this.from&&!this.slice.openStart&&!e.slice.openEnd){let t=this.slice.size+e.slice.size==0?d.empty:new d(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new n(e.from,this.to,t,this.structure)}else return null}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new n(t.from,t.to,d.fromJSON(e,t.slice),!!t.structure)}};X.MAP_BIAS=1;w.jsonID("replace",X);var he=class n extends w{constructor(e,t,r,i,s,o,l=!1){super(),this.from=e,this.to=t,this.gapFrom=r,this.gapTo=i,this.slice=s,this.insert=o,this.structure=l}apply(e){if(this.structure&&(ht(e,this.from,this.gapFrom)||ht(e,this.gapTo,this.to)))return S.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return S.fail("Gap is not a flat range");let r=this.slice.insertAt(this.insert,t.content);return r?S.fromReplace(e,this.from,this.to,r):S.fail("Content does not fit in gap")}getMap(){return new z([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new n(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1),i=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),s=this.to==this.gapTo?r.pos:e.map(this.gapTo,1);return t.deletedAcross&&r.deletedAcross||i<t.pos||s>r.pos?null:new n(t.pos,r.pos,i,s,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,d.fromJSON(e,t.slice),t.insert,!!t.structure)}};w.jsonID("replaceAround",he);function ht(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}var ut=class n extends w{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return S.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return S.fromReplace(e,this.pos,this.pos+1,new d(m.from(i),0,t.isLeaf?0:1))}getMap(){return z.empty}invert(e){return new n(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};w.jsonID("attr",ut);var ft=class n extends w{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return S.ok(r)}getMap(){return z.empty}invert(e){return new n(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};w.jsonID("docAttr",ft);var ue=class extends Error{};ue=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};ue.prototype=Object.create(Error.prototype);ue.prototype.constructor=ue;ue.prototype.name="TransformError";var dt=Object.create(null),x=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new gt(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=d.empty){let r=t.content.lastChild,i=null;for(let l=0;l<t.openEnd;l++)i=r,r=r.lastChild;let s=e.steps.length,o=this.ranges;for(let l=0;l<o.length;l++){let{$from:a,$to:c}=o[l],u=e.mapping.slice(s);e.replaceRange(u.map(a.pos),u.map(c.pos),l?d.empty:t),l==0&&bn(e,s,(r?r.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,t){let r=e.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:o,$to:l}=i[s],a=e.mapping.slice(r),c=a.map(o.pos),u=a.map(l.pos);s?e.deleteRange(c,u):(e.replaceRangeWith(c,u,t),bn(e,r,t.isInline?-1:1))}}static findFrom(e,t,r=!1){let i=e.parent.inlineContent?new C(e):_(e.node(0),e.parent,e.pos,e.index(),t,r);if(i)return i;for(let s=e.depth-1;s>=0;s--){let o=t<0?_(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):_(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new V(e.node(0))}static atStart(e){return _(e,e,0,0,1)||new V(e)}static atEnd(e){return _(e,e,e.content.size,e.childCount,-1)||new V(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=dt[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in dt)throw new RangeError("Duplicate use of selection JSON ID "+e);return dt[e]=t,t.prototype.jsonID=e,t}getBookmark(){return C.between(this.$anchor,this.$head).getBookmark()}};x.prototype.visible=!0;var gt=class{constructor(e,t){this.$from=e,this.$to=t}},Sn=!1;function Mn(n){!Sn&&!n.parent.inlineContent&&(Sn=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var C=class n extends x{constructor(e,t=e){Mn(e),Mn(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return x.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=d.empty){if(super.replace(e,t),t==d.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new $e(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=x.findFrom(t,r,!0)||x.findFrom(t,-r,!0);if(s)t=s.$head;else return x.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(x.findFrom(e,-r,!0)||x.findFrom(e,r,!0)).$anchor,e.pos<t.pos!=i<0&&(e=t))),new n(e,t)}};x.jsonID("text",C);var $e=class n{constructor(e,t){this.anchor=e,this.head=t}map(e){return new n(e.map(this.anchor),e.map(this.head))}resolve(e){return C.between(e.resolve(this.anchor),e.resolve(this.head))}},J=class n extends x{constructor(e){let t=e.nodeAfter,r=e.node(0).resolve(e.pos+t.nodeSize);super(e,r),this.node=t}map(e,t){let{deleted:r,pos:i}=t.mapResult(this.anchor),s=e.resolve(i);return r?x.near(s):new n(s)}content(){return new d(m.from(this.node),0,0)}eq(e){return e instanceof n&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new yt(this.anchor)}static fromJSON(e,t){if(typeof t.anchor!="number")throw new RangeError("Invalid input for NodeSelection.fromJSON");return new n(e.resolve(t.anchor))}static create(e,t){return new n(e.resolve(t))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};J.prototype.visible=!1;x.jsonID("node",J);var yt=class n{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:r}=e.mapResult(this.anchor);return t?new $e(r,r):new n(r)}resolve(e){let t=e.resolve(this.anchor),r=t.nodeAfter;return r&&J.isSelectable(r)?new J(t):x.near(t)}},V=class n extends x{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=d.empty){if(t==d.empty){e.delete(0,e.doc.content.size);let r=x.atStart(e.doc);r.eq(e.selection)||e.setSelection(r)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new n(e)}map(e){return new n(e)}eq(e){return e instanceof n}getBookmark(){return li}};x.jsonID("all",V);var li={map(){return this},resolve(n){return new V(n)}};function _(n,e,t,r,i,s=!1){if(e.inlineContent)return C.create(n,t);for(let o=r-(i>0?0:1);i>0?o<e.childCount:o>=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&J.isSelectable(l))return J.create(n,t-(i<0?l.nodeSize:0))}else{let a=_(n,l,t+i,i<0?l.childCount:0,i,s);if(a)return a}t+=l.nodeSize*i}return null}function bn(n,e,t){let r=n.steps.length-1;if(r<e)return;let i=n.steps[r];if(!(i instanceof X||i instanceof he))return;let s=n.mapping.maps[r],o;s.forEach((l,a,c,u)=>{o==null&&(o=u)}),n.setSelection(x.near(n.doc.resolve(o),t))}function vn(n,e){return!e||!n?n:n.bind(e)}var Y=class{constructor(e,t,r){this.name=e,this.init=vn(t.init,r),this.apply=vn(t.apply,r)}},Yi=[new Y("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new Y("selection",{init(n,e){return n.selection||x.atStart(e.doc)},apply(n){return n.selection}}),new Y("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new Y("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})];function On(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=On(i,e,{})),t[r]=i}return t}var ee=class{constructor(e){this.spec=e,this.props={},e.props&&On(e.props,this,this.props),this.key=e.key?e.key.key:En("plugin")}getState(e){return e[this.key]}},mt=Object.create(null);function En(n){return n in mt?n+"$"+ ++mt[n]:(mt[n]=0,n+"$")}var te=class{constructor(e="key"){this.key=En(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var qe=class{constructor(){this.issued=0,this.table=new Map}mint(){return++this.issued}get(e){return this.table.get(e)}record(e,t){if(this.table.has(e))throw new Error(`origin ${e} is already recorded`);this.table.set(e,Object.freeze(t))}},ne=new te("mapa-fidelity");function re(n,e,t,r={}){let i=U(t),s=I(i),o=s.map(()=>e.mint()),l=G(n,s,{origin:u=>o[u],...r}),a=E(l).slice(0,s.length),c=r.edges!==!1;return s.forEach((u,h)=>{let f=s[h-1],p=s[h+1];e.record(o[h],{node:a[h].node,source:u.source,context:B(a[h]),prev:f?o[h-1]:null,next:p?o[h+1]:null,before:f?i.slice(f.to,u.from):null,after:p?i.slice(u.to,p.from):null,leading:c&&!f?i.slice(0,u.from):null,trailing:c&&!p?i.slice(u.to):null})}),{doc:l,nodes:a,origins:o}}function ai(n,e){let t=new qe,{doc:r}=re(n,t,e);return{doc:r,fidelity:t}}function ci(n,e){return B(n)===B(e)&&ot(H(n),e.node)}function Tn(n,e,t){let r=0;for(;r<n.length&&r<e.length&&t(n[r],e[r]);)r++;let i=0;for(;i<n.length-r&&i<e.length-r&&t(n[n.length-1-i],e[e.length-1-i]);)i++;let s=hi(n.slice(r,n.length-i),e.slice(r,e.length-i),t);return[...Array.from({length:r},(o,l)=>[l,l]),...s.map(([o,l])=>[o+r,l+r]),...Array.from({length:i},(o,l)=>[n.length-i+l,e.length-i+l])]}function hi(n,e,t){let r=n.length,i=e.length,s=Array.from({length:r+1},()=>new Int32Array(i+1));for(let l=r-1;l>=0;l--)for(let a=i-1;a>=0;a--)s[l][a]=t(n[l],e[a])?s[l+1][a+1]+1:Math.max(s[l+1][a],s[l][a+1]);let o=[];for(let l=0,a=0;l<r&&a<i;)t(n[l],e[a])?(o.push([l,a]),l++,a++):s[l+1][a]>=s[l][a+1]?l++:a++;return o}function Nn(n,e,t){let r=n.state,{nodes:i,origins:s}=re(r.schema,e,t),o=i.slice(0,s.length),l=O(r.doc,e).emitted,a=r.tr;for(let[c,u]of Tn(l,o,ci))a.setNodeAttribute(l[c].pos,"origin",s[u]);return a.setMeta("addToHistory",!1).setMeta(ne,{rebuilt:!0}),n.dispatch(a),{ok:lt(n.state.doc,e)===ve(t)}}function xt(n,e){let t=e.topNodeType.create(null,n),{emitted:r}=O(t,null,{raw:!0}),i=dn(r);return JSON.stringify(r.map((s,o)=>[i[o],s.text]))}function An(n,e,t){let r=n.doc.type.schema,{doc:i}=re(r,e,t),s=[];n.doc.forEach((f,p)=>{let g=xt(f,r);g!=="[]"&&s.push({node:f,offset:p,key:g})});let o=[];i.forEach(f=>{let p=xt(f,r);p!=="[]"&&o.push({node:f,key:p})});let l=Tn(s,o,(f,p)=>f.key===p.key),a=[],c=[-1,-1];for(let f of[...l,[s.length,o.length]]){let[p,g]=[c[0]+1,c[1]+1];if(f[0]>p||f[1]>g){let b=p<s.length?s[p].offset:s[s.length-1]?s[s.length-1].offset+s[s.length-1].node.nodeSize:0,P=f[0]>p?s[f[0]-1].offset+s[f[0]-1].node.nodeSize:b;a.push({from:b,to:P,nodes:o.slice(g,f[1]).map(fe=>fe.node)})}c=f}let u=n.selection.head,h=null;for(let f of a.reverse()){h===null&&u>=f.from&&u<=f.to&&(h={left:ui(n.doc,u,f.to),gap:f});let p=[];n.doc.nodesBetween(f.from,f.to,(g,b)=>(b>=f.from&&xt(g,r)==="[]"&&p.push(g),!1)),n.replaceWith(f.from,f.to,m.from([...f.nodes,...p])),f.size=[...f.nodes,...p].reduce((g,b)=>g+b.nodeSize,0)}if(h){let f=n.mapping.map(h.gap.from,-1),p=fi(n.doc,f,f+h.gap.size,h.left);n.setSelection(C.near(n.doc.resolve(p),-1))}return n}function ui(n,e,t){let r=0;return n.nodesBetween(e,t,(i,s)=>{i.isText?r+=Math.min(s+i.nodeSize,t)-Math.max(s,e):i.isInline&&(r+=1)}),r}function fi(n,e,t,r){let i=null,s=[];n.nodesBetween(e,t,(o,l)=>{if(o.isTextblock)return s.push({node:o,pos:l}),!1});for(let{node:o,pos:l}of s.reverse()){let a=o.content.size;if(r<=a){i=l+1+a-r;break}r-=a}return i===null&&(i=s.length?s[s.length-1].pos+1:e),Math.min(Math.max(i,0),n.content.size)}function Rn(n,e,t){let r=An(n.state.tr,e,t);return r.docChanged&&n.dispatch(r.scrollIntoView()),Nn(n,e,t)}function pi(n,e){let t=De(n.state.doc,e);if(t.ok)return{body:t.body,shapes:t.shapes,adopted:!1};Rn(n,e,t.body);let r=De(n.state.doc,e);return{body:r.body,shapes:r.shapes,adopted:!0}}var di={paragraph:["marker"],heading:["level","marker"],code_block:["fence","info","closed","close"],list_item:["indent","bullet","number","delim","task","checked","marker"],blockquote:["prefix","marker"]};function Cn(n){return n.kind===k||n.kind===v?n.holder:n.node}function mi(n,e){if(n.kind===N)return null;let t=Re(n);if(t==="")return null;let r=I(t);if(r.length!==1||r[0].kind!==n.kind)return"structural";let i=E(G(e,r,{trailing:!1}))[0];if(n.kind===k&&i.list!==n.list)return"structural";let s=Cn(n),o=Cn(i),l=[];for(let f of di[s.type.name]??[])JSON.stringify(s.attrs[f])!==JSON.stringify(o.attrs[f])&&l.push([f,o.attrs[f]]);let a=H(n).content,c=i.node.content,u=a.findDiffStart(c);if(u===null&&l.length===0)return null;let h=null;if(u!==null){let{a:f,b:p}=a.findDiffEnd(c),g=u-Math.min(f,p);g>0&&(f+=g,p+=g),h={from:u,to:f,content:c.cut(u,p)}}return{block:n,attrs:l,diff:h,text:t,node:i.node}}function gi(n,{block:e,attrs:t,diff:r},i){if(r){let o=e.pos+1;n.replaceWith(o+r.from,o+r.to,r.content)}let s=e.kind===k||e.kind===v?e.holderPos:e.pos;for(let[o,l]of t)n.setNodeAttribute(s,o,l);n.setNodeAttribute(e.pos,"origin",i)}function yi(n,e,t=null){let r=n.tr;return In(r,e,t),r.docChanged?r:null}function xi(n,e){let t=n.blocks.filter(i=>!i.untouched);if(!e)return t;let r=new Map(E(e).map(i=>[i.node,B(i)]));return t.filter(i=>r.get(i.node)!==B(i))}function In(n,e,t){let r=n.doc.type.schema,i=O(n.doc,e),s=[];for(let h of xi(i,t)){let f=mi(h,r);if(f==="structural"){An(n,e,i.body);return}f&&s.push(f)}if(s.length===0)return;let o=new Map(s.map(h=>[h.block,e.mint()])),l=h=>o.get(h)??(h.first?h.origin:null),{emitted:a}=i,c=s.map(({block:h,text:f,node:p})=>{let g=a.indexOf(h),b=a[g-1],P=a[g+1],fe=o.get(h);return{origin:fe,source:f,node:p.type.create({...p.attrs,origin:fe},p.content,p.marks),prev:b?l(b):null,next:P?l(P):null,before:b?h.seam:null,after:P?P.seam:null,leading:g===0?h.entry?.leading??null:null,trailing:g>=0&&!P?h.entry?.trailing??null:null}});for(let h of[...s].reverse())gi(n,h,o.get(h.block));let u=new Map(E(n.doc).map(h=>[h.node.attrs.origin,h]));for(let{origin:h,...f}of c)e.record(h,{...f,context:B(u.get(h))})}function ki(n,e){let t=o=>{let l=new Map;for(let a of E(o)){let c=a.holder.attrs.marker;c&&l.set(c,(l.get(c)??0)+1)}return l},r=e?t(e):new Map,i=new Set(e?E(e).map(o=>o.holder):[]),s=E(n.doc);for(let[o,l]of t(n.doc)){let a=l-Math.max(r.get(o)??0,1);if(a<=0)continue;let[,...c]=s.filter(h=>h.holder.attrs.marker===o),u=[...c.filter(h=>!i.has(h.holder)).reverse(),...c.filter(h=>i.has(h.holder)).reverse()];for(let h of u.slice(0,a))n.setNodeAttribute(h.holderPos,"marker",null)}}function wi(n){return Math.floor(String(n??"").replaceAll(" "," ").length/2)}function Si(n,e){let t=-1;for(let s of O(n.doc,e).emitted){if(s.kind!==k){t=-1;continue}let o=wi(s.holder.attrs.indent),l=" ".repeat(s.depth);Math.min(o,t+1)!==s.depth&&s.depth<=t+1&&s.holder.attrs.indent!==l&&n.setNodeAttribute(s.holderPos,"indent",l),t=s.depth}let r=[],i=(s,o)=>{let l=o,a=null;s.forEach(c=>{a&&a.type===c.type&&(c.type.name==="bullet_list"||c.type.name==="ordered_list")&&r.push(l),a=c,l+=c.nodeSize})};i(n.doc,0),n.doc.descendants((s,o)=>{if(s.isTextblock)return!1;i(s,o+1)});for(let s of r.sort((o,l)=>l-o))n.join(s)}function Mi(n){let e=n.doc.lastChild;(!e||e.type.name!=="paragraph")&&n.insert(n.doc.content.size,n.doc.type.schema.nodes.paragraph.create())}function zn(n,e,t=null){let r=n.tr;for(let i=0;i<4;i++){let s=r.doc;if(In(r,e,t),ki(r,t),Si(r,e),Mi(r),r.doc===s)break}return r.docChanged?r:null}function bi(n,e={}){let t=null,r=null,i=()=>e.composing?e.composing():t?.composing??!1;return new ee({key:ne,state:{init:()=>n,apply:(s,o)=>o},view(s){return t=s,{destroy(){t=null}}},props:{handleDOMEvents:{compositionend(s){return setTimeout(()=>{t===s&&r&&s.dispatch(s.state.tr.setMeta(ne,{composed:!0}))},50),!1}}},appendTransaction(s,o,l){if(!s.some(h=>h.docChanged&&!h.getMeta(ne)?.rebuilt)&&!r)return null;if(i())return r=r??o.doc,null;let c=r??o.doc;r=null;let u=zn(l,n,c);return u?u.setMeta(ne,{settled:!0}):null}})}var kt="application/x-mapa";function wt(n,e,t=n.selection.from,r=n.selection.to){let i=n.doc.slice(t,r,!0),s=n.schema.topNodeType.create(null,i.content),{body:o,emitted:l}=O(s,e,{edges:!1,raw:!0}),a=JSON.stringify({v:1,sources:l.map(c=>c.text),seams:l.slice(1).map(c=>c.seam)});return{text:o,mapa:a}}function vi(n){let e;try{e=JSON.parse(n)}catch{return null}let{sources:t,seams:r}=e??{};if(e?.v!==1||!Array.isArray(t)||!Array.isArray(r)||t.length===0||r.length!==t.length-1||![...t,...r].every(o=>typeof o=="string")||!r.every(o=>/^\n(?:[^\n]*\n)*$/u.test(o)))return null;let i=t.map((o,l)=>(l?r[l-1]:"")+o).join(""),s=I(i);return s.length!==t.length||s.some((o,l)=>o.source!==t[l])?null:i}function Oi(n,e){let{from:t,to:r}=n.selection,i=new Set;for(let s of O(n.doc,e).emitted){let o=s.holder.attrs.marker,l=s.holderPos>=t&&s.holderPos+s.holder.nodeSize<=r;o&&!l&&i.add(o)}return i}function Dn(n,e){let t=[];return n.forEach(r=>{let i=r;!r.isTextblock&&!r.isLeaf&&(i=r.copy(Dn(r.content,e))),i.attrs.marker&&e.has(i.attrs.marker)&&(i=i.type.create({...i.attrs,marker:null},i.content,i.marks)),t.push(i)}),m.from(t)}function Fn(n,e,t){let r=Oi(e,t);return r.size===0?n:new d(Dn(n.content,r),n.openStart,n.openEnd)}function Bn(n,e,t){let r=vi(t);if(r===null)return null;let{doc:i}=re(n.schema,e,r,{trailing:!1,edges:!1}),s=Fn(d.maxOpen(i.content),n,e),{$from:o,empty:l}=n.selection;if(l&&o.depth===1&&o.parent.type.name==="paragraph"&&o.parent.content.size===0){let a=n.tr.replaceWith(o.before(),o.after(),s.content),c=o.before()+s.content.size;return a.setSelection(C.near(a.doc.resolve(c),-1))}return n.tr.replaceSelection(s)}function Jn(n,e){let t=it(n,e,{trailing:!1});return t.childCount?d.maxOpen(t.content):d.empty}function Ei(n,e){let t=e.content,r=t.firstChild;if(!r)return"";r.isInline?t=m.from(n.nodes.paragraph.create(null,t)):r.type.name==="list_item"&&(t=m.from(n.nodes.bullet_list.create(null,t)));try{return O(n.topNodeType.create(null,t),null,{edges:!1,raw:!0}).body}catch{return e.content.textBetween(0,e.content.size,`
-`)}}var Ei=new te("mapa-clipboard");function Ci(n){let e=(t,r,i)=>{let s=r.clipboardData;if(!s||t.state.selection.empty)return!1;let{text:o,mapa:l}=wt(t.state,n),{dom:a}=t.serializeForClipboard(t.state.selection.content());return r.preventDefault(),s.clearData(),s.setData("text/html",a.innerHTML),s.setData("text/plain",o),s.setData(kt,l),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut")),!0};return new ee({key:Ei,props:{handleDOMEvents:{copy:(t,r)=>e(t,r,!1),cut:(t,r)=>e(t,r,!0)},handlePaste(t,r){let i=r.clipboardData?.getData(kt);if(!i)return!1;let s=Bn(t.state,n,i);return s?(t.dispatch(s.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0):!1},clipboardTextSerializer(t,r){return r.state.selection.content().eq(t)?wt(r.state,n).text:Oi(r.state.schema,t)},clipboardTextParser(t,r,i,s){return Jn(s.state.schema,t)},transformPasted(t,r){return Fn(t,r.state,n)}}})}var ms=an();export{qe as Fidelity,Rn as applyBody,Ci as clipboardPlugin,wt as copyData,an as createSchema,E as docBlocks,ne as fidelityKey,Mi as fidelityPlugin,it as fromMarkdown,kt as mapaType,ai as mount,Bn as pasteTransaction,fi as prepareSave,Nn as rebuild,re as recordBody,gi as reparse,ms as schema,lt as serialise,O as serialiseDetailed,zn as settle,De as structureCheck,Jn as textSlice};
+`)}}var Ci=new te("mapa-clipboard");function Ti(n){let e=(t,r,i)=>{let s=r.clipboardData;if(!s||t.state.selection.empty)return!1;let{text:o,mapa:l}=wt(t.state,n),{dom:a}=t.serializeForClipboard(t.state.selection.content());return r.preventDefault(),s.clearData(),s.setData("text/html",a.innerHTML),s.setData("text/plain",o),s.setData(kt,l),i&&t.dispatch(t.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut")),!0};return new ee({key:Ci,props:{handleDOMEvents:{copy:(t,r)=>e(t,r,!1),cut:(t,r)=>e(t,r,!0)},handlePaste(t,r){let i=r.clipboardData?.getData(kt);if(!i)return!1;let s=Bn(t.state,n,i);return s?(t.dispatch(s.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0):!1},clipboardTextSerializer(t,r){return r.state.selection.content().eq(t)?wt(r.state,n).text:Ei(r.state.schema,t)},clipboardTextParser(t,r,i,s){return Jn(s.state.schema,t)},transformPasted(t,r){return Fn(t,r.state,n)}}})}var gs=an();export{qe as Fidelity,Rn as applyBody,Ti as clipboardPlugin,wt as copyData,an as createSchema,E as docBlocks,ne as fidelityKey,bi as fidelityPlugin,it as fromMarkdown,kt as mapaType,ai as mount,Bn as pasteTransaction,pi as prepareSave,Nn as rebuild,re as recordBody,yi as reparse,gs as schema,lt as serialise,O as serialiseDetailed,zn as settle,De as structureCheck,Jn as textSlice};