@kerebron/legacy-compat 0.8.2 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/kerebron.cjs CHANGED
@@ -1,7 +1,7 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const require_rolldown_runtime=require("./rolldown-runtime-C6qsp3rV.cjs");function OrderedMap(e){this.content=e}OrderedMap.prototype={constructor:OrderedMap,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return-1},get:function(e){var t=this.find(e);return t==-1?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,a=r.find(e),o=r.content.slice();return a==-1?o.push(n||e,t):(o[a+1]=t,n&&(o[a]=n)),new OrderedMap(o)},remove:function(e){var t=this.find(e);if(t==-1)return this;var n=this.content.slice();return n.splice(t,2),new OrderedMap(n)},addToStart:function(e,t){return new OrderedMap([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new OrderedMap(n)},addBefore:function(e,t,n){var r=this.remove(t),a=r.content.slice(),o=r.find(e);return a.splice(o==-1?a.length:o,0,t,n),new OrderedMap(a)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return e=OrderedMap.from(e),e.size?new OrderedMap(e.content.concat(this.subtract(e).content)):this},append:function(e){return e=OrderedMap.from(e),e.size?new OrderedMap(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=OrderedMap.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},OrderedMap.from=function(e){if(e instanceof OrderedMap)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new OrderedMap(t)};function findDiffStart(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let a=e.child(r),o=t.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){for(let e=0;a.text[e]==o.text[e];e++)n++;return n}if(a.content.size||o.content.size){let e=findDiffStart(a.content,o.content,n+1);if(e!=null)return e}n+=a.nodeSize}}function findDiffEnd(e,t,n,r){for(let a=e.childCount,o=t.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let s=e.child(--a),c=t.child(--o),l=s.nodeSize;if(s==c){n-=l,r-=l;continue}if(!s.sameMarkup(c))return{a:n,b:r};if(s.isText&&s.text!=c.text){let e=0,t=Math.min(s.text.length,c.text.length);for(;e<t&&s.text[s.text.length-e-1]==c.text[c.text.length-e-1];)e++,n--,r--;return{a:n,b:r}}if(s.content.size||c.content.size){let e=findDiffEnd(s.content,c.content,n-1,r-1);if(e)return e}n-=l,r-=l}}var Fragment=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,a){for(let o=0,s=0;s<t;o++){let c=this.content[o],l=s+c.nodeSize;if(l>e&&n(c,r+s,a||null,o)!==!1&&c.content.size){let a=s+1;c.nodesBetween(Math.max(0,e-a),Math.min(c.content.size,t-a),n,r+a)}s=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let a=``,o=!0;return this.nodesBetween(e,t,(s,c)=>{let l=s.isText?s.text.slice(Math.max(e,c)-c,t-c):s.isLeaf?r?typeof r==`function`?r(s):r:s.type.spec.leafText?s.type.spec.leafText(s):``:``;s.isBlock&&(s.isLeaf&&l||s.isTextblock)&&n&&(o?o=!1:a+=n),a+=l},0),a}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<t.content.length;o++)a.push(t.content[o]);return new e(a,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],a=0;if(n>t)for(let e=0,o=0;o<n;e++){let s=this.content[e],c=o+s.nodeSize;c>t&&((o<t||c>n)&&(s=s.isText?s.cut(Math.max(0,t-o),Math.min(s.text.length,n-o)):s.cut(Math.max(0,t-o-1),Math.min(s.content.size,n-o-1))),r.push(s),a+=s.nodeSize),o=c}return new e(r,a)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[t]=n,new e(a,o)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.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 RangeError(`Index `+e+` out of range for `+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return findDiffStart(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return findDiffEnd(this,e,t,n)}findIndex(e){if(e==0)return retIndex(0,e);if(e==this.size)return retIndex(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),a=n+r.nodeSize;if(a>=e)return a==e?retIndex(t+1,a):retIndex(t,n);n=a}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return new e(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;e<t.length;e++){let a=t[e];r+=a.nodeSize,e&&a.isText&&t[e-1].sameMarkup(a)?(n||=t.slice(0,e),n[n.length-1]=a.withText(n[n.length-1].text+a.text)):n&&n.push(a)}return new e(n||t,r)}static from(t){if(!t)return e.empty;if(t instanceof e)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new e([t],t.nodeSize);throw RangeError(`Can not convert `+t+` to a Fragment`+(t.nodesBetween?` (looks like multiple versions of prosemirror-model were loaded)`:``))}};Fragment.empty=new Fragment([],0);var found={index:0,offset:0};function retIndex(e,t){return found.index=e,found.offset=t,found}function compareDeep(e,t){if(e===t)return!0;if(!(e&&typeof e==`object`)||!(t&&typeof t==`object`))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!compareDeep(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!compareDeep(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var Mark$1=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let a=e[r];if(this.eq(a))return e;if(this.type.excludes(a.type))t||=e.slice(0,r);else if(a.type.excludes(this.type))return e;else!n&&a.type.rank>this.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(a)}return t||=e.slice(),n||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&&compareDeep(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 RangeError(`Invalid input for Mark.fromJSON`);let n=e.marks[t.type];if(!n)throw RangeError(`There is no mark type ${t.type} in this schema`);let r=n.create(t.attrs);return n.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return e.none;if(t instanceof e)return[t];let n=t.slice();return n.sort((e,t)=>e.type.rank-t.type.rank),n}};Mark$1.none=[];var ReplaceError=class extends Error{},Slice=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=insertInto(this.content,t+this.openStart,n);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(removeRange(this.content,t+this.openStart,n+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(t,n){if(!n)return e.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!=`number`||typeof a!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(Fragment.fromJSON(t,n.content),r,a)}static maxOpen(t,n=!0){let r=0,a=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)a++;return new e(t,r,a)}};Slice.empty=new Slice(Fragment.empty,0,0);function removeRange(e,t,n){let{index:r,offset:a}=e.findIndex(t),o=e.maybeChild(r),{index:s,offset:c}=e.findIndex(n);if(a==t||o.isText){if(c!=n&&!e.child(s).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=s)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,o.copy(removeRange(o.content,t-a-1,n-a-1)))}function insertInto(e,t,n,r){let{index:a,offset:o}=e.findIndex(t),s=e.maybeChild(a);if(o==t||s.isText)return r&&!r.canReplace(a,a,n)?null:e.cut(0,t).append(n).append(e.cut(t));let c=insertInto(s.content,t-o-1,n,s);return c&&e.replaceChild(a,s.copy(c))}function replace(e,t,n){if(n.openStart>e.depth)throw new ReplaceError(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new ReplaceError(`Inconsistent open depths`);return replaceOuter(e,t,n,0)}function replaceOuter(e,t,n,r){let a=e.index(r),o=e.node(r);if(a==t.index(r)&&r<e.depth-n.openStart){let s=replaceOuter(e,t,n,r+1);return o.copy(o.content.replaceChild(a,s))}else if(!n.content.size)return close(o,replaceTwoWay(e,t,r));else if(!n.openStart&&!n.openEnd&&e.depth==r&&t.depth==r){let r=e.parent,a=r.content;return close(r,a.cut(0,e.parentOffset).append(n.content).append(a.cut(t.parentOffset)))}else{let{start:a,end:s}=prepareSliceForReplace(n,e);return close(o,replaceThreeWay(e,a,s,t,r))}}function checkJoin(e,t){if(!t.type.compatibleContent(e.type))throw new ReplaceError(`Cannot join `+t.type.name+` onto `+e.type.name)}function joinable$1(e,t,n){let r=e.node(n);return checkJoin(r,t.node(n)),r}function addNode(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function addRange(e,t,n,r){let a=(t||e).node(n),o=0,s=t?t.index(n):a.childCount;e&&(o=e.index(n),e.depth>n?o++:e.textOffset&&(addNode(e.nodeAfter,r),o++));for(let e=o;e<s;e++)addNode(a.child(e),r);t&&t.depth==n&&t.textOffset&&addNode(t.nodeBefore,r)}function close(e,t){return e.type.checkContent(t),e.copy(t)}function replaceThreeWay(e,t,n,r,a){let o=e.depth>a&&joinable$1(e,t,a+1),s=r.depth>a&&joinable$1(n,r,a+1),c=[];return addRange(null,e,a,c),o&&s&&t.index(a)==n.index(a)?(checkJoin(o,s),addNode(close(o,replaceThreeWay(e,t,n,r,a+1)),c)):(o&&addNode(close(o,replaceTwoWay(e,t,a+1)),c),addRange(t,n,a,c),s&&addNode(close(s,replaceTwoWay(n,r,a+1)),c)),addRange(r,null,a,c),new Fragment(c)}function replaceTwoWay(e,t,n){let r=[];return addRange(null,e,n,r),e.depth>n&&addNode(close(joinable$1(e,t,n+1),replaceTwoWay(e,t,n+1)),r),addRange(t,null,n,r),new Fragment(r)}function prepareSliceForReplace(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(Fragment.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var ResolvedPos=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,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 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 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 n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return Mark$1.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let a=n.marks;for(var o=0;o<a.length;o++)a[o].type.spec.inclusive===!1&&(!r||!a[o].isInSet(r.marks))&&(a=a[o--].removeFromSet(a));return a}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var a=0;a<n.length;a++)n[a].type.spec.inclusive===!1&&(!r||!n[a].isInSet(r.marks))&&(n=n[a--].removeFromSet(n));return n}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 n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new NodeRange(this,e,n);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(t,n){if(!(n>=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],a=0,o=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(o),s=o-n;if(r.push(e,t,a+n),!s||(e=e.child(t),e.isText))break;o=s-1,a+=n+1}return new e(n,r,o)}static resolveCached(t,n){let r=resolveCache.get(t);if(r)for(let e=0;e<r.elts.length;e++){let t=r.elts[e];if(t.pos==n)return t}else resolveCache.set(t,r=new ResolveCache);let a=r.elts[r.i]=e.resolve(t,n);return r.i=(r.i+1)%resolveCacheSize,a}},ResolveCache=class{constructor(){this.elts=[],this.i=0}},resolveCacheSize=12,resolveCache=new WeakMap,NodeRange=class{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}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)}},emptyAttrs=Object.create(null),Node$3=class e{constructor(e,t,n,r=Mark$1.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||Fragment.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,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,``)}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&compareDeep(this.attrs,t||e.defaultAttrs||emptyAttrs)&&Mark$1.sameSet(this.marks,n||Mark$1.none)}copy(t=null){return t==this.content?this:new e(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.content,t)}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,n=!1){if(e==t)return Slice.empty;let r=this.resolve(e),a=this.resolve(t),o=n?0:r.sharedDepth(t),s=r.start(o);return new Slice(r.node(o).content.cut(r.pos-s,a.pos-s),r.depth-o,a.depth-o)}replace(e,t,n){return replace(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return ResolvedPos.resolveCached(this,e)}resolveNoCache(e){return ResolvedPos.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),wrapMarks(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=Fragment.empty,r=0,a=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,r,a),s=o&&o.matchFragment(this.content,t);if(!s||!s.validEnd)return!1;for(let e=r;e<a;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let a=this.contentMatchAt(e).matchType(n),o=a&&a.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=Mark$1.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!Mark$1.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.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(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=Fragment.fromJSON(e,t.content),a=e.nodeType(t.type).create(t.attrs,r,n);return a.type.checkAttrs(a.attrs),a}};Node$3.prototype.text=void 0;var TextNode=class e extends Node$3{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):wrapMarks(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(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,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 wrapMarks(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var ContentMatch=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new TokenStream(t,n);if(r.next==null)return e.empty;let a=parseExpr(r);r.next&&r.err(`Unexpected trailing text`);let o=dfa(nfa(a));return checkForDeadEnds(o,r),o}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,n=e.childCount){let r=this;for(let a=t;r&&a<n;a++)r=r.matchType(e.child(a).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];function a(o,s){let c=o.matchFragment(e,n);if(c&&(!t||c.validEnd))return Fragment.from(s.map(e=>e.createAndFill()));for(let e=0;e<o.next.length;e++){let{type:t,next:n}=o.next[e];if(!(t.isText||t.hasRequiredAttrs())&&r.indexOf(n)==-1){r.push(n);let e=a(n,s.concat(t));if(e)return e}}return null}return a(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),a=r.match;if(a.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<a.next.length;e++){let{type:o,next:s}=a.next[e];!o.isLeaf&&!o.hasRequiredAttrs()&&!(o.name in t)&&(!r.type||s.validEnd)&&(n.push({match:o.contentMatch,type:o,via:r}),t[o.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r<n.next.length;r++)e.indexOf(n.next[r].next)==-1&&t(n.next[r].next)}return t(this),e.map((t,n)=>{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n<t.next.length;n++)r+=(n?`, `:``)+t.next[n].type.name+`->`+e.indexOf(t.next[n].next);return r}).join(`
2
- `)}};ContentMatch.empty=new ContentMatch(!0);var TokenStream=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 SyntaxError(e+` (in content expression '`+this.string+`')`)}};function parseExpr(e){let t=[];do t.push(parseExprSeq(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function parseExprSeq(e){let t=[];do t.push(parseExprSubscript(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function parseExprSubscript(e){let t=parseExprAtom(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=parseExprRange(e,t);else break;return t}function parseNum(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function parseExprRange(e,t){let n=parseNum(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:parseNum(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function resolveName(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let a=[];for(let e in n){let r=n[e];r.isInGroup(t)&&a.push(r)}return a.length==0&&e.err(`No node type or group '`+t+`' found`),a}function parseExprAtom(e){if(e.eat(`(`)){let t=parseExpr(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}else if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=resolveName(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function nfa(e){let t=[[]];return a(o(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let a={term:r,to:n};return t[e].push(a),a}function a(e,t){e.forEach(e=>e.to=t)}function o(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(o(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let s=o(e.exprs[r],t);if(r==e.exprs.length-1)return s;a(s,t=n())}else if(e.type==`star`){let s=n();return r(t,s),a(o(e.expr,s),s),[r(s)]}else if(e.type==`plus`){let s=n();return a(o(e.expr,t),s),a(o(e.expr,s),s),[r(s)]}else if(e.type==`opt`)return[r(t)].concat(o(e.expr,t));else if(e.type==`range`){let s=t;for(let t=0;t<e.min;t++){let t=n();a(o(e.expr,s),t),s=t}if(e.max==-1)a(o(e.expr,s),s);else for(let t=e.min;t<e.max;t++){let t=n();r(s,t),a(o(e.expr,s),t),s=t}return[r(s)]}else if(e.type==`name`)return[r(t,void 0,e.value)];else throw Error(`Unknown expr type`)}}function cmp(e,t){return t-e}function nullFrom(e,t){let n=[];return r(t),n.sort(cmp);function r(t){let a=e[t];if(a.length==1&&!a[0].term)return r(a[0].to);n.push(t);for(let e=0;e<a.length;e++){let{term:t,to:o}=a[e];!t&&n.indexOf(o)==-1&&r(o)}}}function dfa(e){let t=Object.create(null);return n(nullFrom(e,0));function n(r){let a=[];r.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e<a.length;e++)a[e][0]==t&&(r=a[e][1]);nullFrom(e,n).forEach(e=>{r||a.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let o=t[r.join(`,`)]=new ContentMatch(r.indexOf(e.length-1)>-1);for(let e=0;e<a.length;e++){let r=a[e][1].sort(cmp);o.next.push({type:a[e][0],next:t[r.join(`,`)]||n(r)})}return o}}function checkForDeadEnds(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],a=!e.validEnd,o=[];for(let t=0;t<e.next.length;t++){let{type:n,next:s}=e.next[t];o.push(n.name),a&&!(n.isText||n.hasRequiredAttrs())&&(a=!1),r.indexOf(s)==-1&&r.push(s)}a&&t.err(`Only non-generatable nodes (`+o.join(`, `)+`) in a required position (see https://prosemirror.net/docs/guide/#generatable)`)}}function defaultAttrs(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function computeAttrs(e,t){let n=Object.create(null);for(let r in e){let a=t&&t[r];if(a===void 0){let t=e[r];if(t.hasDefault)a=t.default;else throw RangeError(`No value supplied for attribute `+r)}n[r]=a}return n}function checkAttrs(e,t,n,r){for(let r in t)if(!(r in e))throw RangeError(`Unsupported attribute ${r} for ${n} of type ${r}`);for(let n in e){let r=e[n];r.validate&&r.validate(t[n])}}function initAttrs(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new Attribute(e,r,t[r]);return n}var NodeType$1=class e{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(` `):[],this.attrs=initAttrs(e,n.attrs),this.defaultAttrs=defaultAttrs(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e==`text`),this.isText=e==`text`}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==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:computeAttrs(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new Node$3(this,this.computeAttrs(e),Fragment.from(t),Mark$1.setFrom(n))}createChecked(e=null,t,n){return t=Fragment.from(t),this.checkContent(t),new Node$3(this,this.computeAttrs(e),t,Mark$1.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=Fragment.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),a=r&&r.fillBefore(Fragment.empty,!0);return a?new Node$3(this,e,t.append(a),Mark$1.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){checkAttrs(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 n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||=e.slice(0,n);return t?t.length?t:Mark$1.none:e}static compile(t,n){let r=Object.create(null);t.forEach((t,a)=>r[t]=new e(t,n,a));let a=n.spec.topNode||`doc`;if(!r[a])throw RangeError(`Schema is missing its top node type ('`+a+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function validateType(e,t,n){let r=n.split(`|`);return n=>{let a=n===null?`null`:typeof n;if(r.indexOf(a)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${a}`)}}var Attribute=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?validateType(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},MarkType=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=initAttrs(e,r.attrs),this.excluded=null;let a=defaultAttrs(this.attrs);this.instance=a?new Mark$1(this,a):null}create(e=null){return!e&&this.instance?this.instance:new Mark$1(this,computeAttrs(this.attrs,e))}static compile(t,n){let r=Object.create(null),a=0;return t.forEach((t,o)=>r[t]=new e(t,a++,n,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){checkAttrs(this.attrs,e,`mark`,this.name)}excludes(e){return this.excluded.indexOf(e)>-1}},Schema=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=OrderedMap.from(e.nodes),t.marks=OrderedMap.from(e.marks||{}),this.nodes=NodeType$1.compile(this.spec.nodes,this),this.marks=MarkType.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],r=t.spec.content||``,a=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=ContentMatch.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=a==`_`?null:a?gatherMarks(this,a.split(` `)):a==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:gatherMarks(this,n.split(` `))}this.nodeFromJSON=e=>Node$3.fromJSON(this,e),this.markFromJSON=e=>Mark$1.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof NodeType$1))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new TextNode(n,n.defaultAttrs,e,Mark$1.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 RangeError(`Unknown node type: `+e);return t}};function gatherMarks(e,t){let n=[];for(let r=0;r<t.length;r++){let a=t[r],o=e.marks[a],s=o;if(o)n.push(o);else for(let t in e.marks){let r=e.marks[t];(a==`_`||r.spec.group&&r.spec.group.split(` `).indexOf(a)>-1)&&n.push(s=r)}if(!s)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function isTagRule(e){return e.tag!=null}function isStyleRule(e){return e.style!=null}var DOMParser$1=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(isTagRule(e))this.tags.push(e);else if(isStyleRule(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new ParseContext(this,t,!1);return n.addAll(e,Mark$1.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new ParseContext(this,t,!0);return n.addAll(e,Mark$1.none,t.from,t.to),Slice.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(matches(e,n.tag)&&(n.namespace===void 0||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(t===!1)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let a=r?this.styles.indexOf(r)+1:0;a<this.styles.length;a++){let r=this.styles[a],o=r.style;if(!(o.indexOf(e)!=0||r.context&&!n.matchesContext(r.context)||o.length>e.length&&(o.charCodeAt(e.length)!=61||o.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((e.priority==null?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=copy(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=copy(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},blockTags={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},ignoreTags={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},listTags={ol:!0,ul:!0},OPT_PRESERVE_WS=1,OPT_PRESERVE_WS_FULL=2,OPT_OPEN_LEFT=4;function wsOptionsFor(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?OPT_PRESERVE_WS:0)|(t===`full`?OPT_PRESERVE_WS_FULL:0)}var NodeContext=class{constructor(e,t,n,r,a,o){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=o,this.content=[],this.activeMarks=Mark$1.none,this.match=a||(o&OPT_OPEN_LEFT?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Fragment.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&OPT_PRESERVE_WS)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=Fragment.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Fragment.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!blockTags.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},ParseContext=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,a,o=wsOptionsFor(null,t.preserveWhitespace,0)|(n?OPT_OPEN_LEFT:0);a=r?new NodeContext(r.type,r.attrs,Mark$1.none,!0,t.topMatch||r.type.contentMatch,o):n?new NodeContext(null,null,Mark$1.none,!0,null,o):new NodeContext(e.schema.topNodeType,null,Mark$1.none,!0,null,o),this.nodes=[a],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,a=r.options&OPT_PRESERVE_WS_FULL?`full`:this.localPreserveWS||(r.options&OPT_PRESERVE_WS)>0;if(a===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(a)n=a===`full`?n.replace(/\r\n?/g,`
3
- `):n.replace(/\r?\n|\r/g,` `);else if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],a=e.previousSibling;(!t||a&&a.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,a=this.top;(e.tagName==`PRE`||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),s;listTags.hasOwnProperty(o)&&this.parser.normalizeLists&&normalizeList(e);let c=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,n));out:if(c?c.ignore:ignoreTags.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!c||c.skip||c.closeParent){c&&c.closeParent?this.open=Math.max(0,this.open-1):c&&c.skip.nodeType&&(e=c.skip);let n,r=this.needsBlock;if(blockTags.hasOwnProperty(o))a.content.length&&a.content[0].isInline&&this.open&&(this.open--,a=this.top),n=!0,a.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break out}let s=c&&c.skip?t:this.readStyles(e,t);s&&this.addAll(e,s),n&&this.sync(a),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,c,n,c.consuming===!1?s:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName==`BR`&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
4
- `),t)}ignoreFallback(e,t){e.nodeName==`BR`&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text(`-`),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],a=n.getPropertyValue(r);if(a)for(let e;;){let n=this.parser.matchStyle(r,a,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let a,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(o,t.attrs||null,n,t.preserveWhitespace);e&&(a=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let s=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}a&&this.sync(s)&&this.open--}addAll(e,t,n,r){let a=n||0;for(let o=n?e.childNodes[n]:e.firstChild,s=r==null?null:e.childNodes[r];o!=s;o=o.nextSibling,++a)this.findAtPoint(e,a),this.addDOM(o,t);this.findAtPoint(e,a)}findPlace(e,t,n){let r,a;for(let t=this.open,o=0;t>=0;t--){let s=this.nodes[t],c=s.findWrapping(e);if(c&&(!r||r.length>c.length+o)&&(r=c,a=s,!c.length))break;if(s.solid){if(n)break;o+=2}}if(!r)return null;this.sync(a);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&=t.match.matchType(e.type);let n=Mark$1.none;for(let a of r.concat(e.marks))(t.type?t.type.allowsMarkType(a.type):markMayApply(a.type,e.type))&&(n=a.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let a=this.findPlace(e.create(t),n,!1);return a&&=this.enterInner(e,t,n,!0,r),a}enterInner(e,t,n,r=!1,a){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let s=wsOptionsFor(e,a,o.options);o.options&OPT_OPEN_LEFT&&o.content.length==0&&(s|=OPT_OPEN_LEFT);let c=Mark$1.none;return n=n.filter(t=>(o.type?o.type.allowsMarkType(t.type):markMayApply(t.type,e))?(c=t.addToSet(c),!1):!0),this.nodes.push(new NodeContext(e,t,c,r,null,s)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=OPT_PRESERVE_WS);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf(`|`)>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),a=-(n?n.depth+1:0)+ +!r,o=(e,s)=>{for(;e>=0;e--){let c=t[e];if(c==``){if(e==t.length-1||e==0)continue;for(;s>=a;s--)if(o(e-1,s))return!0;return!1}else{let e=s>0||s==0&&r?this.nodes[s].type:n&&s>=a?n.node(s-a).type:null;if(!e||e.name!=c&&!e.isInGroup(c))return!1;s--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function normalizeList(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&listTags.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function matches(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function copy(e){let t={};for(let n in e)t[n]=e[n];return t}function markMayApply(e,t){let n=t.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(e))continue;let o=[],s=e=>{o.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:a}=e.edge(n);if(r==t||o.indexOf(a)<0&&s(a))return!0}};if(s(a.contentMatch))return!0}}var DOMSerializer=class e{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||=doc$1(t).createDocumentFragment();let r=n,a=[];return e.forEach(e=>{if(a.length||e.marks.length){let n=0,o=0;for(;n<a.length&&o<e.marks.length;){let t=e.marks[o];if(!this.marks[t.type.name]){o++;continue}if(!t.eq(a[n][0])||t.type.spec.spanning===!1)break;n++,o++}for(;n<a.length;)r=a.pop()[1];for(;o<e.marks.length;){let n=e.marks[o++],s=this.serializeMark(n,e.isInline,t);s&&(a.push([n,r]),r.appendChild(s.dom),r=s.contentDOM||s.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){let{dom:n,contentDOM:r}=renderSpec(doc$1(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw RangeError(`Content hole not allowed in a leaf node spec`);this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let a=this.serializeMark(e.marks[r],e.isInline,t);a&&((a.contentDOM||a.dom).appendChild(n),n=a.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&renderSpec(doc$1(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return renderSpec(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=gatherToDOM(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return gatherToDOM(e.marks)}};function gatherToDOM(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function doc$1(e){return e.document||window.document}var suspiciousAttributeCache=new WeakMap;function suspiciousAttributes(e){let t=suspiciousAttributeCache.get(e);return t===void 0&&suspiciousAttributeCache.set(e,t=suspiciousAttributesInner(e)),t}function suspiciousAttributesInner(e){let t=null;function n(e){if(e&&typeof e==`object`)if(Array.isArray(e))if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t<e.length;t++)n(e[t]);else for(let t in e)n(e[t])}return n(e),t}function renderSpec(e,t,n,r){if(typeof t==`string`)return{dom:e.createTextNode(t)};if(t.nodeType!=null)return{dom:t};if(t.dom&&t.dom.nodeType!=null)return t;let a=t[0],o;if(typeof a!=`string`)throw RangeError(`Invalid array passed to renderSpec`);if(r&&(o=suspiciousAttributes(r))&&o.indexOf(t)>-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let s=a.indexOf(` `);s>0&&(n=a.slice(0,s),a=a.slice(s+1));let c,l=n?e.createElementNS(n,a):e.createElement(a),u=t[1],d=1;if(u&&typeof u==`object`&&u.nodeType==null&&!Array.isArray(u)){d=2;for(let e in u)if(u[e]!=null){let t=e.indexOf(` `);t>0?l.setAttributeNS(e.slice(0,t),e.slice(t+1),u[e]):e==`style`&&l.style?l.style.cssText=u[e]:l.setAttribute(e,u[e])}}for(let a=d;a<t.length;a++){let o=t[a];if(o===0){if(a<t.length-1||a>d)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:l,contentDOM:l}}else{let{dom:t,contentDOM:a}=renderSpec(e,o,n,r);if(l.appendChild(t),a){if(c)throw RangeError(`Multiple content holes`);c=a}}}return{dom:l,contentDOM:c}}var lower16=65535,factor16=2**16;function makeRecover(e,t){return e+t*factor16}function recoverIndex(e){return e&lower16}function recoverOffset(e){return(e-(e&lower16))/factor16}var DEL_BEFORE=1,DEL_AFTER=2,DEL_ACROSS=4,DEL_SIDE=8,MapResult=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&DEL_SIDE)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&DEL_ACROSS)>0}},StepMap=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=recoverIndex(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[e*3+2]-this.ranges[e*3+1];return this.ranges[n*3]+t+recoverOffset(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,a=this.inverted?2:1,o=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let c=this.ranges[s]-(this.inverted?r:0);if(c>e)break;let l=this.ranges[s+a],u=this.ranges[s+o],d=c+l;if(e<=d){let a=l?e==c?-1:e==d?1:t:t,o=c+r+(a<0?0:u);if(n)return o;let f=e==(t<0?c:d)?null:makeRecover(s/3,e-c),p=e==c?DEL_AFTER:e==d?DEL_BEFORE:DEL_ACROSS;return(t<0?e!=c:e!=d)&&(p|=DEL_SIDE),new MapResult(o,p,f)}r+=u-l}return n?e+r:new MapResult(e+r,0,null)}touches(e,t){let n=0,r=recoverIndex(t),a=this.inverted?2:1,o=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let s=this.ranges[t]-(this.inverted?n:0);if(s>e)break;let c=this.ranges[t+a];if(e<=s+c&&t==r*3)return!0;n+=this.ranges[t+o]-c}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,a=0;r<this.ranges.length;r+=3){let o=this.ranges[r],s=o-(this.inverted?a:0),c=o+(this.inverted?0:a),l=this.ranges[r+t],u=this.ranges[r+n];e(s,s+l,c,c+u),a+=u-l}}invert(){return new e(this.ranges,!this.inverted)}toString(){return(this.inverted?`-`:``)+JSON.stringify(this.ranges)}static offset(t){return t==0?e.empty:new e(t<0?[0,-t,0]:[0,0,t])}};StepMap.empty=new StepMap([]);var Mapping=class e{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(t=0,n=this.maps.length){return new e(this._maps,this.mirror,t,n)}appendMap(e,t){this.ownData||=(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||=[],this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let a=this._maps[n].mapResult(e,t);if(a.recover!=null){let t=this.getMirror(n);if(t!=null&&t>n&&t<this.to){n=t,e=this._maps[t].recover(a.recover);continue}}r|=a.delInfo,e=a.pos}return n?e:new MapResult(e,r,null)}},stepsByID=Object.create(null),Step=class{getMap(){return StepMap.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError(`Invalid input for Step.fromJSON`);let n=stepsByID[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in stepsByID)throw RangeError(`Duplicate use of step JSON ID `+e);return stepsByID[e]=t,t.prototype.jsonID=e,t}},StepResult=class e{constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,a){try{return e.ok(t.replace(n,r,a))}catch(t){if(t instanceof ReplaceError)return e.fail(t.message);throw t}}};function mapFragment(e,t,n){let r=[];for(let a=0;a<e.childCount;a++){let o=e.child(a);o.content.size&&(o=o.copy(mapFragment(o.content,t,o))),o.isInline&&(o=t(o,n,a)),r.push(o)}return Fragment.fromArray(r)}var AddMarkStep=class e extends Step{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),a=new Slice(mapFragment(t.content,(e,t)=>!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return StepResult.fromReplace(e,this.from,this.to,a)}invert(){return new RemoveMarkStep(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};Step.jsonID(`addMark`,AddMarkStep);var RemoveMarkStep=class e extends Step{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new Slice(mapFragment(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return StepResult.fromReplace(e,this.from,this.to,n)}invert(){return new AddMarkStep(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};Step.jsonID(`removeMark`,RemoveMarkStep);var AddNodeMarkStep=class e extends Step{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return StepResult.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return StepResult.fromReplace(e,this.pos,this.pos+1,new Slice(Fragment.from(n),0,+!t.isLeaf))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;r<n.marks.length;r++)if(!n.marks[r].isInSet(t))return new e(this.pos,n.marks[r]);return new e(this.pos,this.mark)}}return new RemoveNodeMarkStep(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`addNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for AddNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};Step.jsonID(`addNodeMark`,AddNodeMarkStep);var RemoveNodeMarkStep=class e extends Step{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return StepResult.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return StepResult.fromReplace(e,this.pos,this.pos+1,new Slice(Fragment.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new AddNodeMarkStep(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`removeNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for RemoveNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};Step.jsonID(`removeNodeMark`,RemoveNodeMarkStep);var ReplaceStep=class e extends Step{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&contentBetween(e,this.from,this.to)?StepResult.fail(`Structure replace would overwrite content`):StepResult.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new StepMap([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new e(n.pos,Math.max(n.pos,r.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?Slice.empty:new Slice(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new e(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?Slice.empty:new Slice(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new e(t.from,this.to,n,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(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for ReplaceStep.fromJSON`);return new e(n.from,n.to,Slice.fromJSON(t,n.slice),!!n.structure)}};Step.jsonID(`replace`,ReplaceStep);var ReplaceAroundStep=class e extends Step{constructor(e,t,n,r,a,o,s=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=a,this.insert=o,this.structure=s}apply(e){if(this.structure&&(contentBetween(e,this.from,this.gapFrom)||contentBetween(e,this.gapTo,this.to)))return StepResult.fail(`Structure gap-replace would overwrite content`);let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return StepResult.fail(`Gap is not a flat range`);let n=this.slice.insertAt(this.insert,t.content);return n?StepResult.fromReplace(e,this.from,this.to,n):StepResult.fail(`Content does not fit in gap`)}getMap(){return new StepMap([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),a=this.from==this.gapFrom?n.pos:t.map(this.gapFrom,-1),o=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new e(n.pos,r.pos,a,o,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(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,Slice.fromJSON(t,n.slice),n.insert,!!n.structure)}};Step.jsonID(`replaceAround`,ReplaceAroundStep);function contentBetween(e,t,n){let r=e.resolve(t),a=n-t,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let e=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,a--}}return!1}function addMark(e,t,n,r){let a=[],o=[],s,c;e.doc.nodesBetween(t,n,(e,l,u)=>{if(!e.isInline)return;let d=e.marks;if(!r.isInSet(d)&&u.type.allowsMarkType(r.type)){let u=Math.max(l,t),f=Math.min(l+e.nodeSize,n),p=r.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(p)||(s&&s.to==u&&s.mark.eq(d[e])?s.to=f:a.push(s=new RemoveMarkStep(u,f,d[e])));c&&c.to==u?c.to=f:o.push(c=new AddMarkStep(u,f,r))}}),a.forEach(t=>e.step(t)),o.forEach(t=>e.step(t))}function removeMark(e,t,n,r){let a=[],o=0;e.doc.nodesBetween(t,n,(e,s)=>{if(!e.isInline)return;o++;let c=null;if(r instanceof MarkType){let t=e.marks,n;for(;n=r.isInSet(t);)(c||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(c=[r]):c=e.marks;if(c&&c.length){let r=Math.min(s+e.nodeSize,n);for(let e=0;e<c.length;e++){let n=c[e],l;for(let e=0;e<a.length;e++){let t=a[e];t.step==o-1&&n.eq(a[e].style)&&(l=t)}l?(l.to=r,l.step=o):a.push({style:n,from:Math.max(s,t),to:r,step:o})}}}),a.forEach(t=>e.step(new RemoveMarkStep(t.from,t.to,t.style)))}function clearIncompatible(e,t,n,r=n.contentMatch,a=!0){let o=e.doc.nodeAt(t),s=[],c=t+1;for(let t=0;t<o.childCount;t++){let l=o.child(t),u=c+l.nodeSize,d=r.matchType(l.type);if(!d)s.push(new ReplaceStep(c,u,Slice.empty));else{r=d;for(let t=0;t<l.marks.length;t++)n.allowsMarkType(l.marks[t].type)||e.step(new RemoveMarkStep(c,u,l.marks[t]));if(a&&l.isText&&n.whitespace!=`pre`){let e,t=/\r?\n|\r/g,r;for(;e=t.exec(l.text);)r||=new Slice(Fragment.from(n.schema.text(` `,n.allowedMarks(l.marks))),0,0),s.push(new ReplaceStep(c+e.index,c+e.index+e[0].length,r))}}c=u}if(!r.validEnd){let t=r.fillBefore(Fragment.empty,!0);e.replace(c,c,new Slice(t,0,0))}for(let t=s.length-1;t>=0;t--)e.step(s[t])}function canCut(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function liftTarget(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth;;--n){let r=e.$from.node(n),a=e.$from.index(n),o=e.$to.indexAfter(n);if(n<e.depth&&r.canReplace(a,o,t))return n;if(n==0||r.type.spec.isolating||!canCut(r,a,o))break}return null}function lift$1(e,t,n){let{$from:r,$to:a,depth:o}=t,s=r.before(o+1),c=a.after(o+1),l=s,u=c,d=Fragment.empty,f=0;for(let e=o,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,d=Fragment.from(r.node(e).copy(d)),f++):l--;let p=Fragment.empty,m=0;for(let e=o,t=!1;e>n;e--)t||a.after(e+1)<a.end(e)?(t=!0,p=Fragment.from(a.node(e).copy(p)),m++):u++;e.step(new ReplaceAroundStep(l,u,s,c,new Slice(d.append(p),f,m),d.size-f,!0))}function findWrapping(e,t,n=null,r=e){let a=findWrappingOutside(e,t),o=a&&findWrappingInside(r,t);return o?a.map(withAttrs).concat({type:t,attrs:n}).concat(o.map(withAttrs)):null}function withAttrs(e){return{type:e,attrs:null}}function findWrappingOutside(e,t){let{parent:n,startIndex:r,endIndex:a}=e,o=n.contentMatchAt(r).findWrapping(t);if(!o)return null;let s=o.length?o[0]:t;return n.canReplaceWith(r,a,s)?o:null}function findWrappingInside(e,t){let{parent:n,startIndex:r,endIndex:a}=e,o=n.child(r),s=t.contentMatch.findWrapping(o.type);if(!s)return null;let c=(s.length?s[s.length-1]:t).contentMatch;for(let e=r;c&&e<a;e++)c=c.matchType(n.child(e).type);return!c||!c.validEnd?null:s}function wrap(e,t,n){let r=Fragment.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=Fragment.from(n[e].type.create(n[e].attrs,r))}let a=t.start,o=t.end;e.step(new ReplaceAroundStep(a,o,a,o,new Slice(r,0,0),n.length,!0))}function setBlockType$1(e,t,n,r,a){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let o=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let s=typeof a==`function`?a(t):a;if(t.isTextblock&&!t.hasMarkup(r,s)&&canChangeType(e.doc,e.mapping.slice(o).map(n),r)){let a=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?a=!1:!e&&t&&(a=!0)}a===!1&&replaceLinebreaks(e,t,n,o),clearIncompatible(e,e.mapping.slice(o).map(n,1),r,void 0,a===null);let c=e.mapping.slice(o),l=c.map(n,1),u=c.map(n+t.nodeSize,1);return e.step(new ReplaceAroundStep(l,u,l+1,u-1,new Slice(Fragment.from(r.create(s,null,t.marks)),0,0),1,!0)),a===!0&&replaceNewlines(e,t,n,o),!1}})}function replaceNewlines(e,t,n,r){t.forEach((a,o)=>{if(a.isText){let s,c=/\r?\n|\r/g;for(;s=c.exec(a.text);){let a=e.mapping.slice(r).map(n+1+o+s.index);e.replaceWith(a,a+1,t.type.schema.linebreakReplacement.create())}}})}function replaceLinebreaks(e,t,n,r){t.forEach((a,o)=>{if(a.type==a.type.schema.linebreakReplacement){let a=e.mapping.slice(r).map(n+1+o);e.replaceWith(a,a+1,t.type.schema.text(`
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const require_rolldown_runtime=require("./rolldown-runtime-C6qsp3rV.cjs");function OrderedMap(e){this.content=e}OrderedMap.prototype={constructor:OrderedMap,find:function(e){for(var t=0;t<this.content.length;t+=2)if(this.content[t]===e)return t;return-1},get:function(e){var t=this.find(e);return t==-1?void 0:this.content[t+1]},update:function(e,t,n){var r=n&&n!=e?this.remove(n):this,a=r.find(e),o=r.content.slice();return a==-1?o.push(n||e,t):(o[a+1]=t,n&&(o[a]=n)),new OrderedMap(o)},remove:function(e){var t=this.find(e);if(t==-1)return this;var n=this.content.slice();return n.splice(t,2),new OrderedMap(n)},addToStart:function(e,t){return new OrderedMap([e,t].concat(this.remove(e).content))},addToEnd:function(e,t){var n=this.remove(e).content.slice();return n.push(e,t),new OrderedMap(n)},addBefore:function(e,t,n){var r=this.remove(t),a=r.content.slice(),o=r.find(e);return a.splice(o==-1?a.length:o,0,t,n),new OrderedMap(a)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(e){return e=OrderedMap.from(e),e.size?new OrderedMap(e.content.concat(this.subtract(e).content)):this},append:function(e){return e=OrderedMap.from(e),e.size?new OrderedMap(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var t=this;e=OrderedMap.from(e);for(var n=0;n<e.content.length;n+=2)t=t.remove(e.content[n]);return t},toObject:function(){var e={};return this.forEach(function(t,n){e[t]=n}),e},get size(){return this.content.length>>1}},OrderedMap.from=function(e){if(e instanceof OrderedMap)return e;var t=[];if(e)for(var n in e)t.push(n,e[n]);return new OrderedMap(t)};function findDiffStart(e,t,n){for(let r=0;;r++){if(r==e.childCount||r==t.childCount)return e.childCount==t.childCount?null:n;let a=e.child(r),o=t.child(r);if(a==o){n+=a.nodeSize;continue}if(!a.sameMarkup(o))return n;if(a.isText&&a.text!=o.text){let e=a.text,t=o.text,r=0;for(;e[r]==t[r];r++)n++;return r&&r<e.length&&r<t.length&&surrogateHigh(e.charCodeAt(r-1))&&surrogateLow(e.charCodeAt(r))&&n--,n}if(a.content.size||o.content.size){let e=findDiffStart(a.content,o.content,n+1);if(e!=null)return e}n+=a.nodeSize}}function findDiffEnd(e,t,n,r){for(let a=e.childCount,o=t.childCount;;){if(a==0||o==0)return a==o?null:{a:n,b:r};let s=e.child(--a),c=t.child(--o),l=s.nodeSize;if(s==c){n-=l,r-=l;continue}if(!s.sameMarkup(c))return{a:n,b:r};if(s.isText&&s.text!=c.text){let e=s.text,t=c.text,a=e.length,o=t.length;for(;a>0&&o>0&&e[a-1]==t[o-1];)a--,o--,n--,r--;return a&&o&&a<e.length&&surrogateHigh(e.charCodeAt(a-1))&&surrogateLow(e.charCodeAt(a))&&(n++,r++),{a:n,b:r}}if(s.content.size||c.content.size){let e=findDiffEnd(s.content,c.content,n-1,r-1);if(e)return e}n-=l,r-=l}}function surrogateLow(e){return e>=56320&&e<57344}function surrogateHigh(e){return e>=55296&&e<56320}var Fragment=class e{constructor(e,t){if(this.content=e,this.size=t||0,t==null)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,r=0,a){for(let o=0,s=0;s<t;o++){let c=this.content[o],l=s+c.nodeSize;if(l>e&&n(c,r+s,a||null,o)!==!1&&c.content.size){let a=s+1;c.nodesBetween(Math.max(0,e-a),Math.min(c.content.size,t-a),n,r+a)}s=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,r){let a=``,o=!0;return this.nodesBetween(e,t,(s,c)=>{let l=s.isText?s.text.slice(Math.max(e,c)-c,t-c):s.isLeaf?r?typeof r==`function`?r(s):r:s.type.spec.leafText?s.type.spec.leafText(s):``:``;s.isBlock&&(s.isLeaf&&l||s.isTextblock)&&n&&(o?o=!1:a+=n),a+=l},0),a}append(t){if(!t.size)return this;if(!this.size)return t;let n=this.lastChild,r=t.firstChild,a=this.content.slice(),o=0;for(n.isText&&n.sameMarkup(r)&&(a[a.length-1]=n.withText(n.text+r.text),o=1);o<t.content.length;o++)a.push(t.content[o]);return new e(a,this.size+t.size)}cut(t,n=this.size){if(t==0&&n==this.size)return this;let r=[],a=0;if(n>t)for(let e=0,o=0;o<n;e++){let s=this.content[e],c=o+s.nodeSize;c>t&&((o<t||c>n)&&(s=s.isText?s.cut(Math.max(0,t-o),Math.min(s.text.length,n-o)):s.cut(Math.max(0,t-o-1),Math.min(s.content.size,n-o-1))),r.push(s),a+=s.nodeSize),o=c}return new e(r,a)}cutByIndex(t,n){return t==n?e.empty:t==0&&n==this.content.length?this:new e(this.content.slice(t,n))}replaceChild(t,n){let r=this.content[t];if(r==n)return this;let a=this.content.slice(),o=this.size+n.nodeSize-r.nodeSize;return a[t]=n,new e(a,o)}addToStart(t){return new e([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new e(this.content.concat(t),this.size+t.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 RangeError(`Index `+e+` out of range for `+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let r=this.content[t];e(r,n,t),n+=r.nodeSize}}findDiffStart(e,t=0){return findDiffStart(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return findDiffEnd(this,e,t,n)}findIndex(e){if(e==0)return retIndex(0,e);if(e==this.size)return retIndex(this.content.length,e);if(e>this.size||e<0)throw RangeError(`Position ${e} outside of fragment (${this})`);for(let t=0,n=0;;t++){let r=this.child(t),a=n+r.nodeSize;if(a>=e)return a==e?retIndex(t+1,a):retIndex(t,n);n=a}}toString(){return`<`+this.toStringInner()+`>`}toStringInner(){return this.content.join(`, `)}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(t,n){if(!n)return e.empty;if(!Array.isArray(n))throw RangeError(`Invalid input for Fragment.fromJSON`);return e.fromArray(n.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return e.empty;let n,r=0;for(let e=0;e<t.length;e++){let a=t[e];r+=a.nodeSize,e&&a.isText&&t[e-1].sameMarkup(a)?(n||=t.slice(0,e),n[n.length-1]=a.withText(n[n.length-1].text+a.text)):n&&n.push(a)}return new e(n||t,r)}static from(t){if(!t)return e.empty;if(t instanceof e)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new e([t],t.nodeSize);throw RangeError(`Can not convert `+t+` to a Fragment`+(t.nodesBetween?` (looks like multiple versions of prosemirror-model were loaded)`:``))}};Fragment.empty=new Fragment([],0);var found={index:0,offset:0};function retIndex(e,t){return found.index=e,found.offset=t,found}function compareDeep(e,t){if(e===t)return!0;if(!(e&&typeof e==`object`)||!(t&&typeof t==`object`))return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!compareDeep(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!compareDeep(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}var Mark$1=class e{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let r=0;r<e.length;r++){let a=e[r];if(this.eq(a))return e;if(this.type.excludes(a.type))t||=e.slice(0,r);else if(a.type.excludes(this.type))return e;else!n&&a.type.rank>this.type.rank&&(t||=e.slice(0,r),t.push(this),n=!0),t&&t.push(a)}return t||=e.slice(),n||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&&compareDeep(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 RangeError(`Invalid input for Mark.fromJSON`);let n=e.marks[t.type];if(!n)throw RangeError(`There is no mark type ${t.type} in this schema`);let r=n.create(t.attrs);return n.checkAttrs(r.attrs),r}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&t.length==0)return e.none;if(t instanceof e)return[t];let n=t.slice();return n.sort((e,t)=>e.type.rank-t.type.rank),n}};Mark$1.none=[];var ReplaceError=class extends Error{},Slice=class e{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,n){let r=insertInto(this.content,t+this.openStart,n,this.openStart+1,this.openEnd+1);return r&&new e(r,this.openStart,this.openEnd)}removeBetween(t,n){return new e(removeRange(this.content,t+this.openStart,n+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(t,n){if(!n)return e.empty;let r=n.openStart||0,a=n.openEnd||0;if(typeof r!=`number`||typeof a!=`number`)throw RangeError(`Invalid input for Slice.fromJSON`);return new e(Fragment.fromJSON(t,n.content),r,a)}static maxOpen(t,n=!0){let r=0,a=0;for(let e=t.firstChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.firstChild)r++;for(let e=t.lastChild;e&&!e.isLeaf&&(n||!e.type.spec.isolating);e=e.lastChild)a++;return new e(t,r,a)}};Slice.empty=new Slice(Fragment.empty,0,0);function removeRange(e,t,n){let{index:r,offset:a}=e.findIndex(t),o=e.maybeChild(r),{index:s,offset:c}=e.findIndex(n);if(a==t||o.isText){if(c!=n&&!e.child(s).isText)throw RangeError(`Removing non-flat range`);return e.cut(0,t).append(e.cut(n))}if(r!=s)throw RangeError(`Removing non-flat range`);return e.replaceChild(r,o.copy(removeRange(o.content,t-a-1,n-a-1)))}function insertInto(e,t,n,r,a,o){let{index:s,offset:c}=e.findIndex(t),l=e.maybeChild(s);if(c==t||l.isText)return o&&r<=0&&a<=0&&!o.canReplace(s,s,n)?null:e.cut(0,t).append(n).append(e.cut(t));let u=insertInto(l.content,t-c-1,n,s==0?r-1:0,s==e.childCount-1?a-1:0,l);return u&&e.replaceChild(s,l.copy(u))}function replace(e,t,n){if(n.openStart>e.depth)throw new ReplaceError(`Inserted content deeper than insertion position`);if(e.depth-n.openStart!=t.depth-n.openEnd)throw new ReplaceError(`Inconsistent open depths`);return replaceOuter(e,t,n,0)}function replaceOuter(e,t,n,r){let a=e.index(r),o=e.node(r);if(a==t.index(r)&&r<e.depth-n.openStart){let s=replaceOuter(e,t,n,r+1);return o.copy(o.content.replaceChild(a,s))}else if(!n.content.size)return close(o,replaceTwoWay(e,t,r));else if(!n.openStart&&!n.openEnd&&e.depth==r&&t.depth==r){let r=e.parent,a=r.content;return close(r,a.cut(0,e.parentOffset).append(n.content).append(a.cut(t.parentOffset)))}else{let{start:a,end:s}=prepareSliceForReplace(n,e);return close(o,replaceThreeWay(e,a,s,t,r))}}function checkJoin(e,t){if(!t.type.compatibleContent(e.type))throw new ReplaceError(`Cannot join `+t.type.name+` onto `+e.type.name)}function joinable$1(e,t,n){let r=e.node(n);return checkJoin(r,t.node(n)),r}function addNode(e,t){let n=t.length-1;n>=0&&e.isText&&e.sameMarkup(t[n])?t[n]=e.withText(t[n].text+e.text):t.push(e)}function addRange(e,t,n,r){let a=(t||e).node(n),o=0,s=t?t.index(n):a.childCount;e&&(o=e.index(n),e.depth>n?o++:e.textOffset&&(addNode(e.nodeAfter,r),o++));for(let e=o;e<s;e++)addNode(a.child(e),r);t&&t.depth==n&&t.textOffset&&addNode(t.nodeBefore,r)}function close(e,t){if(!e.type.validContent(t))throw new ReplaceError(`Invalid content for node `+e.type.name);return e.copy(t)}function replaceThreeWay(e,t,n,r,a){let o=e.depth>a&&joinable$1(e,t,a+1),s=r.depth>a&&joinable$1(n,r,a+1),c=[];return addRange(null,e,a,c),o&&s&&t.index(a)==n.index(a)?(checkJoin(o,s),addNode(close(o,replaceThreeWay(e,t,n,r,a+1)),c)):(o&&addNode(close(o,replaceTwoWay(e,t,a+1)),c),addRange(t,n,a,c),s&&addNode(close(s,replaceTwoWay(n,r,a+1)),c)),addRange(r,null,a,c),new Fragment(c)}function replaceTwoWay(e,t,n){let r=[];return addRange(null,e,n,r),e.depth>n&&addNode(close(joinable$1(e,t,n+1),replaceTwoWay(e,t,n+1)),r),addRange(t,null,n,r),new Fragment(r)}function prepareSliceForReplace(e,t){let n=t.depth-e.openStart,r=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)r=t.node(e).copy(Fragment.from(r));return{start:r.resolveNoCache(e.openStart+n),end:r.resolveNoCache(r.content.size-e.openEnd-n)}}var ResolvedPos=class e{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,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 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 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 n=this.pos-this.path[this.path.length-1],r=e.child(t);return n?e.child(t).cut(n):r}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[t*3],r=t==0?0:this.path[t*3-1]+1;for(let t=0;t<e;t++)r+=n.child(t).nodeSize;return r}marks(){let e=this.parent,t=this.index();if(e.content.size==0)return Mark$1.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),r=e.maybeChild(t);if(!n){let e=n;n=r,r=e}let a=n.marks;for(var o=0;o<a.length;o++)a[o].type.spec.inclusive===!1&&(!r||!a[o].isInSet(r.marks))&&(a=a[o--].removeFromSet(a));return a}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,r=e.parent.maybeChild(e.index());for(var a=0;a<n.length;a++)n[a].type.spec.inclusive===!1&&(!r||!n[a].isInSet(r.marks))&&(n=n[a--].removeFromSet(n));return n}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 n=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);n>=0;n--)if(e.pos<=this.end(n)&&(!t||t(this.node(n))))return new NodeRange(this,e,n);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(t,n){if(!(n>=0&&n<=t.content.size))throw RangeError(`Position `+n+` out of range`);let r=[],a=0,o=n;for(let e=t;;){let{index:t,offset:n}=e.content.findIndex(o),s=o-n;if(r.push(e,t,a+n),!s||(e=e.child(t),e.isText))break;o=s-1,a+=n+1}return new e(n,r,o)}static resolveCached(t,n){let r=resolveCache.get(t);if(r)for(let e=0;e<r.elts.length;e++){let t=r.elts[e];if(t.pos==n)return t}else resolveCache.set(t,r=new ResolveCache);let a=r.elts[r.i]=e.resolve(t,n);return r.i=(r.i+1)%resolveCacheSize,a}},ResolveCache=class{constructor(){this.elts=[],this.i=0}},resolveCacheSize=12,resolveCache=new WeakMap,NodeRange=class{constructor(e,t,n){this.$from=e,this.$to=t,this.depth=n}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)}},emptyAttrs=Object.create(null),Node$3=class e{constructor(e,t,n,r=Mark$1.none){this.type=e,this.attrs=t,this.marks=r,this.content=n||Fragment.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,n,r=0){this.content.nodesBetween(e,t,n,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,``)}textBetween(e,t,n,r){return this.content.textBetween(e,t,n,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&compareDeep(this.attrs,t||e.defaultAttrs||emptyAttrs)&&Mark$1.sameSet(this.marks,n||Mark$1.none)}copy(t=null){return t==this.content?this:new e(this.type,this.attrs,t,this.marks)}mark(t){return t==this.marks?this:new e(this.type,this.attrs,this.content,t)}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,n=!1){if(e==t)return Slice.empty;let r=this.resolve(e),a=this.resolve(t),o=n?0:r.sharedDepth(t),s=r.start(o);return new Slice(r.node(o).content.cut(r.pos-s,a.pos-s),r.depth-o,a.depth-o)}replace(e,t,n){return replace(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:r}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(r==e||t.isText)return t;e-=r+1}}childAfter(e){let{index:t,offset:n}=this.content.findIndex(e);return{node:this.content.maybeChild(t),index:t,offset:n}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:t,offset:n}=this.content.findIndex(e);if(n<e)return{node:this.content.child(t),index:t,offset:n};let r=this.content.child(t-1);return{node:r,index:t-1,offset:n-r.nodeSize}}resolve(e){return ResolvedPos.resolveCached(this,e)}resolveNoCache(e){return ResolvedPos.resolve(this,e)}rangeHasMark(e,t,n){let r=!1;return t>e&&this.nodesBetween(e,t,e=>(n.isInSet(e.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+=`(`+this.content.toStringInner()+`)`),wrapMarks(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw Error(`Called contentMatchAt on a node with invalid content`);return t}canReplace(e,t,n=Fragment.empty,r=0,a=n.childCount){let o=this.contentMatchAt(e).matchFragment(n,r,a),s=o&&o.matchFragment(this.content,t);if(!s||!s.validEnd)return!1;for(let e=r;e<a;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,r){if(r&&!this.type.allowsMarks(r))return!1;let a=this.contentMatchAt(e).matchType(n),o=a&&a.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=Mark$1.none;for(let t=0;t<this.marks.length;t++){let n=this.marks[t];n.type.checkAttrs(n.attrs),e=n.addToSet(e)}if(!Mark$1.sameSet(e,this.marks))throw RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(e=>e.type.name)}`);this.content.forEach(e=>e.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(e=>e.toJSON())),e}static fromJSON(e,t){if(!t)throw RangeError(`Invalid input for Node.fromJSON`);let n;if(t.marks){if(!Array.isArray(t.marks))throw RangeError(`Invalid mark data for Node.fromJSON`);n=t.marks.map(e.markFromJSON)}if(t.type==`text`){if(typeof t.text!=`string`)throw RangeError(`Invalid text node in JSON`);return e.text(t.text,n)}let r=Fragment.fromJSON(e,t.content),a=e.nodeType(t.type).create(t.attrs,r,n);return a.type.checkAttrs(a.attrs),a}};Node$3.prototype.text=void 0;var TextNode=class e extends Node$3{constructor(e,t,n,r){if(super(e,t,null,r),!n)throw RangeError(`Empty text nodes are not allowed`);this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):wrapMarks(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(t){return t==this.marks?this:new e(this.type,this.attrs,this.text,t)}withText(t){return t==this.text?this:new e(this.type,this.attrs,t,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 wrapMarks(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+`(`+t+`)`;return t}var ContentMatch=class e{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(t,n){let r=new TokenStream(t,n);if(r.next==null)return e.empty;let a=parseExpr(r);r.next&&r.err(`Unexpected trailing text`);let o=dfa(nfa(a));return checkForDeadEnds(o,r),o}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,n=e.childCount){let r=this;for(let a=t;r&&a<n;a++)r=r.matchType(e.child(a).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:t}=this.next[e];if(!(t.isText||t.hasRequiredAttrs()))return t}return null}compatible(e){for(let t=0;t<this.next.length;t++)for(let n=0;n<e.next.length;n++)if(this.next[t].type==e.next[n].type)return!0;return!1}fillBefore(e,t=!1,n=0){let r=[this];function a(o,s){let c=o.matchFragment(e,n);if(c&&(!t||c.validEnd))return Fragment.from(s.map(e=>e.createAndFill()));for(let e=0;e<o.next.length;e++){let{type:t,next:n}=o.next[e];if(!(t.isText||t.hasRequiredAttrs())&&r.indexOf(n)==-1){r.push(n);let e=a(n,s.concat(t));if(e)return e}}return null}return a(this,[])}findWrapping(e){for(let t=0;t<this.wrapCache.length;t+=2)if(this.wrapCache[t]==e)return this.wrapCache[t+1];let t=this.computeWrapping(e);return this.wrapCache.push(e,t),t}computeWrapping(e){let t=Object.create(null),n=[{match:this,type:null,via:null}];for(;n.length;){let r=n.shift(),a=r.match;if(a.matchType(e)){let e=[];for(let t=r;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<a.next.length;e++){let{type:o,next:s}=a.next[e];!o.isLeaf&&!o.hasRequiredAttrs()&&!(o.name in t)&&(!r.type||s.validEnd)&&(n.push({match:o.contentMatch,type:o,via:r}),t[o.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(n){e.push(n);for(let r=0;r<n.next.length;r++)e.indexOf(n.next[r].next)==-1&&t(n.next[r].next)}return t(this),e.map((t,n)=>{let r=n+(t.validEnd?`*`:` `)+` `;for(let n=0;n<t.next.length;n++)r+=(n?`, `:``)+t.next[n].type.name+`->`+e.indexOf(t.next[n].next);return r}).join(`
2
+ `)}};ContentMatch.empty=new ContentMatch(!0);var TokenStream=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 SyntaxError(e+` (in content expression '`+this.string+`')`)}};function parseExpr(e){let t=[];do t.push(parseExprSeq(e));while(e.eat(`|`));return t.length==1?t[0]:{type:`choice`,exprs:t}}function parseExprSeq(e){let t=[];do t.push(parseExprSubscript(e));while(e.next&&e.next!=`)`&&e.next!=`|`);return t.length==1?t[0]:{type:`seq`,exprs:t}}function parseExprSubscript(e){let t=parseExprAtom(e);for(;;)if(e.eat(`+`))t={type:`plus`,expr:t};else if(e.eat(`*`))t={type:`star`,expr:t};else if(e.eat(`?`))t={type:`opt`,expr:t};else if(e.eat(`{`))t=parseExprRange(e,t);else break;return t}function parseNum(e){/\D/.test(e.next)&&e.err(`Expected number, got '`+e.next+`'`);let t=Number(e.next);return e.pos++,t}function parseExprRange(e,t){let n=parseNum(e),r=n;return e.eat(`,`)&&(r=e.next==`}`?-1:parseNum(e)),e.eat(`}`)||e.err(`Unclosed braced range`),{type:`range`,min:n,max:r,expr:t}}function resolveName(e,t){let n=e.nodeTypes,r=n[t];if(r)return[r];let a=[];for(let e in n){let r=n[e];r.isInGroup(t)&&a.push(r)}return a.length==0&&e.err(`No node type or group '`+t+`' found`),a}function parseExprAtom(e){if(e.eat(`(`)){let t=parseExpr(e);return e.eat(`)`)||e.err(`Missing closing paren`),t}else if(/\W/.test(e.next))e.err(`Unexpected token '`+e.next+`'`);else{let t=resolveName(e,e.next).map(t=>(e.inline==null?e.inline=t.isInline:e.inline!=t.isInline&&e.err(`Mixing inline and block content`),{type:`name`,value:t}));return e.pos++,t.length==1?t[0]:{type:`choice`,exprs:t}}}function nfa(e){let t=[[]];return a(o(e,0),n()),t;function n(){return t.push([])-1}function r(e,n,r){let a={term:r,to:n};return t[e].push(a),a}function a(e,t){e.forEach(e=>e.to=t)}function o(e,t){if(e.type==`choice`)return e.exprs.reduce((e,n)=>e.concat(o(n,t)),[]);if(e.type==`seq`)for(let r=0;;r++){let s=o(e.exprs[r],t);if(r==e.exprs.length-1)return s;a(s,t=n())}else if(e.type==`star`){let s=n();return r(t,s),a(o(e.expr,s),s),[r(s)]}else if(e.type==`plus`){let s=n();return a(o(e.expr,t),s),a(o(e.expr,s),s),[r(s)]}else if(e.type==`opt`)return[r(t)].concat(o(e.expr,t));else if(e.type==`range`){let s=t;for(let t=0;t<e.min;t++){let t=n();a(o(e.expr,s),t),s=t}if(e.max==-1)a(o(e.expr,s),s);else for(let t=e.min;t<e.max;t++){let t=n();r(s,t),a(o(e.expr,s),t),s=t}return[r(s)]}else if(e.type==`name`)return[r(t,void 0,e.value)];else throw Error(`Unknown expr type`)}}function cmp(e,t){return t-e}function nullFrom(e,t){let n=[];return r(t),n.sort(cmp);function r(t){let a=e[t];if(a.length==1&&!a[0].term)return r(a[0].to);n.push(t);for(let e=0;e<a.length;e++){let{term:t,to:o}=a[e];!t&&n.indexOf(o)==-1&&r(o)}}}function dfa(e){let t=Object.create(null);return n(nullFrom(e,0));function n(r){let a=[];r.forEach(t=>{e[t].forEach(({term:t,to:n})=>{if(!t)return;let r;for(let e=0;e<a.length;e++)a[e][0]==t&&(r=a[e][1]);nullFrom(e,n).forEach(e=>{r||a.push([t,r=[]]),r.indexOf(e)==-1&&r.push(e)})})});let o=t[r.join(`,`)]=new ContentMatch(r.indexOf(e.length-1)>-1);for(let e=0;e<a.length;e++){let r=a[e][1].sort(cmp);o.next.push({type:a[e][0],next:t[r.join(`,`)]||n(r)})}return o}}function checkForDeadEnds(e,t){for(let n=0,r=[e];n<r.length;n++){let e=r[n],a=!e.validEnd,o=[];for(let t=0;t<e.next.length;t++){let{type:n,next:s}=e.next[t];o.push(n.name),a&&!(n.isText||n.hasRequiredAttrs())&&(a=!1),r.indexOf(s)==-1&&r.push(s)}a&&t.err(`Only non-generatable nodes (`+o.join(`, `)+`) in a required position (see https://prosemirror.net/docs/guide/#generatable)`)}}function defaultAttrs(e){let t=Object.create(null);for(let n in e){let r=e[n];if(!r.hasDefault)return null;t[n]=r.default}return t}function computeAttrs(e,t){let n=Object.create(null);for(let r in e){let a=t&&t[r];if(a===void 0){let t=e[r];if(t.hasDefault)a=t.default;else throw RangeError(`No value supplied for attribute `+r)}n[r]=a}return n}function checkAttrs(e,t,n,r){for(let a in t)if(!(a in e))throw RangeError(`Unsupported attribute ${a} for ${n} of type ${r}`);for(let n in e)e[n].validate&&e[n].validate(t[n])}function initAttrs(e,t){let n=Object.create(null);if(t)for(let r in t)n[r]=new Attribute(e,r,t[r]);return n}var NodeType$1=class e{constructor(e,t,n){this.name=e,this.schema=t,this.spec=n,this.markSet=null,this.groups=n.group?n.group.split(` `):[],this.attrs=initAttrs(e,n.attrs),this.defaultAttrs=defaultAttrs(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||e==`text`),this.isText=e==`text`}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==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:computeAttrs(this.attrs,e)}create(e=null,t,n){if(this.isText)throw Error(`NodeType.create can't construct text nodes`);return new Node$3(this,this.computeAttrs(e),Fragment.from(t),Mark$1.setFrom(n))}createChecked(e=null,t,n){return t=Fragment.from(t),this.checkContent(t),new Node$3(this,this.computeAttrs(e),t,Mark$1.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),t=Fragment.from(t),t.size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let r=this.contentMatch.matchFragment(t),a=r&&r.fillBefore(Fragment.empty,!0);return a?new Node$3(this,e,t.append(a),Mark$1.setFrom(n)):null}validContent(e){let t=this.contentMatch.matchFragment(e);if(!t||!t.validEnd)return!1;for(let t=0;t<e.childCount;t++)if(!this.allowsMarks(e.child(t).marks))return!1;return!0}checkContent(e){if(!this.validContent(e))throw RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){checkAttrs(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 n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||=e.slice(0,n);return t?t.length?t:Mark$1.none:e}static compile(t,n){let r=Object.create(null);t.forEach((t,a)=>r[t]=new e(t,n,a));let a=n.spec.topNode||`doc`;if(!r[a])throw RangeError(`Schema is missing its top node type ('`+a+`')`);if(!r.text)throw RangeError(`Every schema needs a 'text' type`);for(let e in r.text.attrs)throw RangeError(`The text node type should not have attributes`);return r}};function validateType(e,t,n){let r=n.split(`|`);return n=>{let a=n===null?`null`:typeof n;if(r.indexOf(a)<0)throw RangeError(`Expected value of type ${r} for attribute ${t} on type ${e}, got ${a}`)}}var Attribute=class{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,`default`),this.default=n.default,this.validate=typeof n.validate==`string`?validateType(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}},MarkType=class e{constructor(e,t,n,r){this.name=e,this.rank=t,this.schema=n,this.spec=r,this.attrs=initAttrs(e,r.attrs),this.excluded=null;let a=defaultAttrs(this.attrs);this.instance=a?new Mark$1(this,a):null}create(e=null){return!e&&this.instance?this.instance:new Mark$1(this,computeAttrs(this.attrs,e))}static compile(t,n){let r=Object.create(null),a=0;return t.forEach((t,o)=>r[t]=new e(t,a++,n,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){checkAttrs(this.attrs,e,`mark`,this.name)}excludes(e){return this.excluded.indexOf(e)>-1}},Schema=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let n in e)t[n]=e[n];t.nodes=OrderedMap.from(e.nodes),t.marks=OrderedMap.from(e.marks||{}),this.nodes=NodeType$1.compile(this.spec.nodes,this),this.marks=MarkType.compile(this.spec.marks,this);let n=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw RangeError(e+` can not be both a node and a mark`);let t=this.nodes[e],r=t.spec.content||``,a=t.spec.marks;if(t.contentMatch=n[r]||(n[r]=ContentMatch.parse(r,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw RangeError(`Multiple linebreak nodes defined`);if(!t.isInline||!t.isLeaf)throw RangeError(`Linebreak replacement nodes must be inline leaf nodes`);this.linebreakReplacement=t}t.markSet=a==`_`?null:a?gatherMarks(this,a.split(` `)):a==``||!t.inlineContent?[]:null}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=n==null?[t]:n==``?[]:gatherMarks(this,n.split(` `))}this.nodeFromJSON=e=>Node$3.fromJSON(this,e),this.markFromJSON=e=>Mark$1.fromJSON(this,e),this.topNodeType=this.nodes[this.spec.topNode||`doc`],this.cached.wrappings=Object.create(null)}node(e,t=null,n,r){if(typeof e==`string`)e=this.nodeType(e);else if(!(e instanceof NodeType$1))throw RangeError(`Invalid node type: `+e);else if(e.schema!=this)throw RangeError(`Node type from different schema used (`+e.name+`)`);return e.createChecked(t,n,r)}text(e,t){let n=this.nodes.text;return new TextNode(n,n.defaultAttrs,e,Mark$1.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 RangeError(`Unknown node type: `+e);return t}};function gatherMarks(e,t){let n=[];for(let r=0;r<t.length;r++){let a=t[r],o=e.marks[a],s=o;if(o)n.push(o);else for(let t in e.marks){let r=e.marks[t];(a==`_`||r.spec.group&&r.spec.group.split(` `).indexOf(a)>-1)&&n.push(s=r)}if(!s)throw SyntaxError(`Unknown mark type: '`+t[r]+`'`)}return n}function isTagRule(e){return e.tag!=null}function isStyleRule(e){return e.style!=null}var DOMParser$1=class e{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach(e=>{if(isTagRule(e))this.tags.push(e);else if(isStyleRule(e)){let t=/[^=]*/.exec(e.style)[0];n.indexOf(t)<0&&n.push(t),this.styles.push(e)}}),this.normalizeLists=!this.tags.some(t=>{if(!/^(ul|ol)\b/.test(t.tag)||!t.node)return!1;let n=e.nodes[t.node];return n.contentMatch.matchType(n)})}parse(e,t={}){let n=new ParseContext(this,t,!1);return n.addAll(e,Mark$1.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new ParseContext(this,t,!0);return n.addAll(e,Mark$1.none,t.from,t.to),Slice.maxOpen(n.finish())}matchTag(e,t,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(matches(e,n.tag)&&(n.namespace===void 0||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(t===!1)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,r){for(let a=r?this.styles.indexOf(r)+1:0;a<this.styles.length;a++){let r=this.styles[a],o=r.style;if(!(o.indexOf(e)!=0||r.context&&!n.matchesContext(r.context)||o.length>e.length&&(o.charCodeAt(e.length)!=61||o.slice(e.length+1)!=t))){if(r.getAttrs){let e=r.getAttrs(t);if(e===!1)continue;r.attrs=e||void 0}return r}}}static schemaRules(e){let t=[];function n(e){let n=e.priority==null?50:e.priority,r=0;for(;r<t.length;r++){let e=t[r];if((e.priority==null?50:e.priority)<n)break}t.splice(r,0,e)}for(let t in e.marks){let r=e.marks[t].spec.parseDOM;r&&r.forEach(e=>{n(e=copy(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)})}for(let t in e.nodes){let r=e.nodes[t].spec.parseDOM;r&&r.forEach(e=>{n(e=copy(e)),e.node||e.ignore||e.mark||(e.node=t)})}return t}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new e(t,e.schemaRules(t)))}},blockTags={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},ignoreTags={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},listTags={ol:!0,ul:!0},OPT_PRESERVE_WS=1,OPT_PRESERVE_WS_FULL=2,OPT_OPEN_LEFT=4;function wsOptionsFor(e,t,n){return t==null?e&&e.whitespace==`pre`?3:n&-5:(t?OPT_PRESERVE_WS:0)|(t===`full`?OPT_PRESERVE_WS_FULL:0)}var NodeContext=class{constructor(e,t,n,r,a,o){this.type=e,this.attrs=t,this.marks=n,this.solid=r,this.options=o,this.content=[],this.activeMarks=Mark$1.none,this.match=a||(o&OPT_OPEN_LEFT?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(Fragment.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let t=this.type.contentMatch,n;return(n=t.findWrapping(e.type))?(this.match=t,n):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&OPT_PRESERVE_WS)){let e=this.content[this.content.length-1],t;if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let t=Fragment.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(Fragment.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!blockTags.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}},ParseContext=class{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let r=t.topNode,a,o=wsOptionsFor(null,t.preserveWhitespace,0)|(n?OPT_OPEN_LEFT:0);a=r?new NodeContext(r.type,r.attrs,Mark$1.none,!0,t.topMatch||r.type.contentMatch,o):n?new NodeContext(null,null,Mark$1.none,!0,null,o):new NodeContext(e.schema.topNodeType,null,Mark$1.none,!0,null,o),this.nodes=[a],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){e.nodeType==3?this.addTextNode(e,t):e.nodeType==1&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,r=this.top,a=r.options&OPT_PRESERVE_WS_FULL?`full`:this.localPreserveWS||(r.options&OPT_PRESERVE_WS)>0,{schema:o}=this.parser;if(a===`full`||r.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(!a){if(n=n.replace(/[ \t\r\n\u000c]+/g,` `),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=r.content[r.content.length-1],a=e.previousSibling;(!t||a&&a.nodeName==`BR`||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}}else if(a===`full`)n=n.replace(/\r\n?/g,`
3
+ `);else if(o.linebreakReplacement&&/[\r\n]/.test(n)&&this.top.findWrapping(o.linebreakReplacement.create())){let e=n.split(/\r?\n|\r/);for(let n=0;n<e.length;n++)n&&this.insertNode(o.linebreakReplacement.create(),t,!0),e[n]&&this.insertNode(o.text(e[n]),t,!/\S/.test(e[n]));n=``}else n=n.replace(/\r?\n|\r/g,` `);n&&this.insertNode(o.text(n),t,!/\S/.test(n)),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let r=this.localPreserveWS,a=this.top;(e.tagName==`PRE`||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o=e.nodeName.toLowerCase(),s;listTags.hasOwnProperty(o)&&this.parser.normalizeLists&&normalizeList(e);let c=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(s=this.parser.matchTag(e,this,n));out:if(c?c.ignore:ignoreTags.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e,t);else if(!c||c.skip||c.closeParent){c&&c.closeParent?this.open=Math.max(0,this.open-1):c&&c.skip.nodeType&&(e=c.skip);let n,r=this.needsBlock;if(blockTags.hasOwnProperty(o))a.content.length&&a.content[0].isInline&&this.open&&(this.open--,a=this.top),n=!0,a.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break out}let s=c&&c.skip?t:this.readStyles(e,t);s&&this.addAll(e,s),n&&this.sync(a),this.needsBlock=r}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,c,n,c.consuming===!1?s:void 0)}this.localPreserveWS=r}leafFallback(e,t){e.nodeName==`BR`&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
4
+ `),t)}ignoreFallback(e,t){e.nodeName==`BR`&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text(`-`),t,!0)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let r=this.parser.matchedStyles[e],a=n.getPropertyValue(r);if(a)for(let e;;){let n=this.parser.matchStyle(r,a,this,e);if(!n)break;if(n.ignore)return null;if(t=n.clearMark?t.filter(e=>!n.clearMark(e)):t.concat(this.parser.schema.marks[n.mark].create(n.attrs)),n.consuming===!1)e=n;else break}}return t}addElementByRule(e,t,n,r){let a,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),n,e.nodeName==`BR`)||this.leafFallback(e,n);else{let e=this.enter(o,t.attrs||null,n,t.preserveWhitespace);e&&(a=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let s=this.top;if(o&&o.isLeaf)this.findInside(e);else if(r)this.addElement(e,n,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(e=>this.insertNode(e,n,!1));else{let r=e;typeof t.contentElement==`string`?r=e.querySelector(t.contentElement):typeof t.contentElement==`function`?r=t.contentElement(e):t.contentElement&&(r=t.contentElement),this.findAround(e,r,!0),this.addAll(r,n),this.findAround(e,r,!1)}a&&this.sync(s)&&this.open--}addAll(e,t,n,r){let a=n||0;for(let o=n?e.childNodes[n]:e.firstChild,s=r==null?null:e.childNodes[r];o!=s;o=o.nextSibling,++a)this.findAtPoint(e,a),this.addDOM(o,t);this.findAtPoint(e,a)}findPlace(e,t,n){let r,a;for(let t=this.open,o=0;t>=0;t--){let s=this.nodes[t],c=s.findWrapping(e);if(c&&(!r||r.length>c.length+o)&&(r=c,a=s,!c.length))break;if(s.solid){if(n)break;o+=2}}if(!r)return null;this.sync(a);for(let e=0;e<r.length;e++)t=this.enterInner(r[e],null,t,!1);return t}insertNode(e,t,n){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let r=this.findPlace(e,t,n);if(r){this.closeExtra();let t=this.top;t.match&&=t.match.matchType(e.type);let n=Mark$1.none;for(let a of r.concat(e.marks))(t.type?t.type.allowsMarkType(a.type):markMayApply(a.type,e.type))&&(n=a.addToSet(n));return t.content.push(e.mark(n)),!0}return!1}enter(e,t,n,r){let a=this.findPlace(e.create(t),n,!1);return a&&=this.enterInner(e,t,n,!0,r),a}enterInner(e,t,n,r=!1,a){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let s=wsOptionsFor(e,a,o.options);o.options&OPT_OPEN_LEFT&&o.content.length==0&&(s|=OPT_OPEN_LEFT);let c=Mark$1.none;return n=n.filter(t=>(o.type?o.type.allowsMarkType(t.type):markMayApply(t.type,e))?(c=t.addToSet(c),!1):!0),this.nodes.push(new NodeContext(e,t,c,r,null,s)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!!(this.isOpen||this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--)if(this.nodes[t]==e)return this.open=t,!0;else this.localPreserveWS&&(this.nodes[t].options|=OPT_PRESERVE_WS);return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].pos==null&&e.nodeType==1&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&t.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf(`|`)>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split(`/`),n=this.options.context,r=!this.isOpen&&(!n||n.parent.type==this.nodes[0].type),a=-(n?n.depth+1:0)+ +!r,o=(e,s)=>{for(;e>=0;e--){let c=t[e];if(c==``){if(e==t.length-1||e==0)continue;for(;s>=a;s--)if(o(e-1,s))return!0;return!1}else{let e=s>0||s==0&&r?this.nodes[s].type:n&&s>=a?n.node(s-a).type:null;if(!e||e.name!=c&&!e.isInGroup(c))return!1;s--}}return!0};return o(t.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let t=e.depth;t>=0;t--){let n=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let e in this.parser.schema.nodes){let t=this.parser.schema.nodes[e];if(t.isTextblock&&t.defaultAttrs)return t}}};function normalizeList(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=t.nodeType==1?t.nodeName.toLowerCase():null;e&&listTags.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):e==`li`?n=t:e&&(n=null)}}function matches(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function copy(e){let t={};for(let n in e)t[n]=e[n];return t}function markMayApply(e,t){let n=t.schema.nodes;for(let r in n){let a=n[r];if(!a.allowsMarkType(e))continue;let o=[],s=e=>{o.push(e);for(let n=0;n<e.edgeCount;n++){let{type:r,next:a}=e.edge(n);if(r==t||o.indexOf(a)<0&&s(a))return!0}};if(s(a.contentMatch))return!0}}var DOMSerializer=class e{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||=doc$1(t).createDocumentFragment();let r=n,a=[];return e.forEach(e=>{if(a.length||e.marks.length){let n=0,o=0;for(;n<a.length&&o<e.marks.length;){let t=e.marks[o];if(!this.marks[t.type.name]){o++;continue}if(!t.eq(a[n][0])||t.type.spec.spanning===!1)break;n++,o++}for(;n<a.length;)r=a.pop()[1];for(;o<e.marks.length;){let n=e.marks[o++],s=this.serializeMark(n,e.isInline,t);s&&(a.push([n,r]),r.appendChild(s.dom),r=s.contentDOM||s.dom)}}r.appendChild(this.serializeNodeInner(e,t))}),n}serializeNodeInner(e,t){if(e.isText)return doc$1(t).createTextNode(e.text);let{dom:n,contentDOM:r}=renderSpec(doc$1(t),this.nodes[e.type.name](e),null,e.attrs);if(r){if(e.isLeaf)throw RangeError(`Content hole not allowed in a leaf node spec`);this.serializeFragment(e.content,t,r)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let r=e.marks.length-1;r>=0;r--){let a=this.serializeMark(e.marks[r],e.isInline,t);a&&((a.contentDOM||a.dom).appendChild(n),n=a.dom)}return n}serializeMark(e,t,n={}){let r=this.marks[e.type.name];return r&&renderSpec(doc$1(n),r(e,t),null,e.attrs)}static renderSpec(e,t,n=null,r){return typeof t==`string`?{dom:e.createTextNode(t)}:renderSpec(e,t,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new e(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(e){let t=gatherToDOM(e.nodes);return t.text||=e=>e.text,t}static marksFromSchema(e){return gatherToDOM(e.marks)}};function gatherToDOM(e){let t={};for(let n in e){let r=e[n].spec.toDOM;r&&(t[n]=r)}return t}function doc$1(e){return e.document||window.document}var suspiciousAttributeCache=new WeakMap;function suspiciousAttributes(e){let t=suspiciousAttributeCache.get(e);return t===void 0&&suspiciousAttributeCache.set(e,t=suspiciousAttributesInner(e)),t}function suspiciousAttributesInner(e){let t=null;function n(e){if(e&&typeof e==`object`)if(Array.isArray(e))if(typeof e[0]==`string`)t||=[],t.push(e);else for(let t=0;t<e.length;t++)n(e[t]);else for(let t in e)n(e[t])}return n(e),t}function renderSpec(e,t,n,r){if(t.nodeType==1)return{dom:t};if(t.dom&&t.dom.nodeType==1)return t;let a=t[0],o;if(typeof a!=`string`)throw RangeError(`Invalid array passed to renderSpec`);if(r&&(o=suspiciousAttributes(r))&&o.indexOf(t)>-1)throw RangeError(`Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.`);let s=a.indexOf(` `);s>0&&(n=a.slice(0,s),a=a.slice(s+1));let c,l=n?e.createElementNS(n,a):e.createElement(a),u=t[1],d=1;if(u&&typeof u==`object`&&u.nodeType==null&&!Array.isArray(u)){d=2;for(let e in u)if(u[e]!=null){let t=e.indexOf(` `);t>0?l.setAttributeNS(e.slice(0,t),e.slice(t+1),u[e]):e==`style`&&l.style?l.style.cssText=u[e]:l.setAttribute(e,u[e])}}for(let a=d;a<t.length;a++){let o=t[a];if(o===0){if(a<t.length-1||a>d)throw RangeError(`Content hole must be the only child of its parent node`);return{dom:l,contentDOM:l}}else if(typeof o==`string`)l.appendChild(e.createTextNode(o));else{let{dom:t,contentDOM:a}=renderSpec(e,o,n,r);if(l.appendChild(t),a){if(c)throw RangeError(`Multiple content holes`);c=a}}}return{dom:l,contentDOM:c}}var lower16=65535,factor16=2**16;function makeRecover(e,t){return e+t*factor16}function recoverIndex(e){return e&lower16}function recoverOffset(e){return(e-(e&lower16))/factor16}var DEL_BEFORE=1,DEL_AFTER=2,DEL_ACROSS=4,DEL_SIDE=8,MapResult=class{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(this.delInfo&DEL_SIDE)>0}get deletedBefore(){return(this.delInfo&5)>0}get deletedAfter(){return(this.delInfo&6)>0}get deletedAcross(){return(this.delInfo&DEL_ACROSS)>0}},StepMap=class e{constructor(t,n=!1){if(this.ranges=t,this.inverted=n,!t.length&&e.empty)return e.empty}recover(e){let t=0,n=recoverIndex(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[e*3+2]-this.ranges[e*3+1];return this.ranges[n*3]+t+recoverOffset(e)}mapResult(e,t=1){return this._map(e,t,!1)}map(e,t=1){return this._map(e,t,!0)}_map(e,t,n){let r=0,a=this.inverted?2:1,o=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let c=this.ranges[s]-(this.inverted?r:0);if(c>e)break;let l=this.ranges[s+a],u=this.ranges[s+o],d=c+l;if(e<=d){let a=l?e==c?-1:e==d?1:t:t,o=c+r+(a<0?0:u);if(n)return o;let f=e==(t<0?c:d)?null:makeRecover(s/3,e-c),p=e==c?DEL_AFTER:e==d?DEL_BEFORE:DEL_ACROSS;return(t<0?e!=c:e!=d)&&(p|=DEL_SIDE),new MapResult(o,p,f)}r+=u-l}return n?e+r:new MapResult(e+r,0,null)}touches(e,t){let n=0,r=recoverIndex(t),a=this.inverted?2:1,o=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let s=this.ranges[t]-(this.inverted?n:0);if(s>e)break;let c=this.ranges[t+a];if(e<=s+c&&t==r*3)return!0;n+=this.ranges[t+o]-c}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,a=0;r<this.ranges.length;r+=3){let o=this.ranges[r],s=o-(this.inverted?a:0),c=o+(this.inverted?0:a),l=this.ranges[r+t],u=this.ranges[r+n];e(s,s+l,c,c+u),a+=u-l}}invert(){return new e(this.ranges,!this.inverted)}toString(){return(this.inverted?`-`:``)+JSON.stringify(this.ranges)}static offset(t){return t==0?e.empty:new e(t<0?[0,-t,0]:[0,0,t])}};StepMap.empty=new StepMap([]);var Mapping=class e{constructor(e,t,n=0,r=e?e.length:0){this.mirror=t,this.from=n,this.to=r,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(t=0,n=this.maps.length){return new e(this._maps,this.mirror,t,n)}appendMap(e,t){this.ownData||=(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),!0),this.to=this._maps.push(e),t!=null&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let r=e.getMirror(t);this.appendMap(e._maps[t],r!=null&&r<t?n+r:void 0)}}getMirror(e){if(this.mirror){for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}}setMirror(e,t){this.mirror||=[],this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let r=e.getMirror(t);this.appendMap(e._maps[t].invert(),r!=null&&r>t?n-r-1:void 0)}}invert(){let t=new e;return t.appendMappingInverted(this),t}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let n=this.from;n<this.to;n++)e=this._maps[n].map(e,t);return e}mapResult(e,t=1){return this._map(e,t,!1)}_map(e,t,n){let r=0;for(let n=this.from;n<this.to;n++){let a=this._maps[n].mapResult(e,t);if(a.recover!=null){let t=this.getMirror(n);if(t!=null&&t>n&&t<this.to){n=t,e=this._maps[t].recover(a.recover);continue}}r|=a.delInfo,e=a.pos}return n?e:new MapResult(e,r,null)}},stepsByID=Object.create(null),Step=class{getMap(){return StepMap.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw RangeError(`Invalid input for Step.fromJSON`);let n=stepsByID[t.stepType];if(!n)throw RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in stepsByID)throw RangeError(`Duplicate use of step JSON ID `+e);return stepsByID[e]=t,t.prototype.jsonID=e,t}},StepResult=class e{constructor(e,t){this.doc=e,this.failed=t}static ok(t){return new e(t,null)}static fail(t){return new e(null,t)}static fromReplace(t,n,r,a){try{return e.ok(t.replace(n,r,a))}catch(t){if(t instanceof ReplaceError)return e.fail(t.message);throw t}}};function mapFragment(e,t,n){let r=[];for(let a=0;a<e.childCount;a++){let o=e.child(a);o.content.size&&(o=o.copy(mapFragment(o.content,t,o))),o.isInline&&(o=t(o,n,a)),r.push(o)}return Fragment.fromArray(r)}var AddMarkStep=class e extends Step{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=e.resolve(this.from),r=n.node(n.sharedDepth(this.to)),a=new Slice(mapFragment(t.content,(e,t)=>!e.isAtom||!t.type.allowsMarkType(this.mark.type)?e:e.mark(this.mark.addToSet(e.marks)),r),t.openStart,t.openEnd);return StepResult.fromReplace(e,this.from,this.to,a)}invert(){return new RemoveMarkStep(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`addMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for AddMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};Step.jsonID(`addMark`,AddMarkStep);var RemoveMarkStep=class e extends Step{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new Slice(mapFragment(t.content,e=>e.mark(this.mark.removeFromSet(e.marks)),e),t.openStart,t.openEnd);return StepResult.fromReplace(e,this.from,this.to,n)}invert(){return new AddMarkStep(this.from,this.to,this.mark)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deleted&&r.deleted||n.pos>=r.pos?null:new e(n.pos,r.pos,this.mark)}merge(t){return t instanceof e&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new e(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:`removeMark`,mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for RemoveMarkStep.fromJSON`);return new e(n.from,n.to,t.markFromJSON(n.mark))}};Step.jsonID(`removeMark`,RemoveMarkStep);var AddNodeMarkStep=class e extends Step{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return StepResult.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return StepResult.fromReplace(e,this.pos,this.pos+1,new Slice(Fragment.from(n),0,+!t.isLeaf))}invert(t){let n=t.nodeAt(this.pos);if(n){let t=this.mark.addToSet(n.marks);if(t.length==n.marks.length){for(let r=0;r<n.marks.length;r++)if(!n.marks[r].isInSet(t))return new e(this.pos,n.marks[r]);return new e(this.pos,this.mark)}}return new RemoveNodeMarkStep(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`addNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for AddNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};Step.jsonID(`addNodeMark`,AddNodeMarkStep);var RemoveNodeMarkStep=class e extends Step{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return StepResult.fail(`No node at mark step's position`);let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return StepResult.fromReplace(e,this.pos,this.pos+1,new Slice(Fragment.from(n),0,+!t.isLeaf))}invert(e){let t=e.nodeAt(this.pos);return!t||!this.mark.isInSet(t.marks)?this:new AddNodeMarkStep(this.pos,this.mark)}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.mark)}toJSON(){return{stepType:`removeNodeMark`,pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,n){if(typeof n.pos!=`number`)throw RangeError(`Invalid input for RemoveNodeMarkStep.fromJSON`);return new e(n.pos,t.markFromJSON(n.mark))}};Step.jsonID(`removeNodeMark`,RemoveNodeMarkStep);var ReplaceStep=class e extends Step{constructor(e,t,n,r=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=r}apply(e){return this.structure&&contentBetween(e,this.from,this.to)?StepResult.fail(`Structure replace would overwrite content`):StepResult.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new StepMap([this.from,this.to-this.from,this.slice.size])}invert(t){return new e(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1);return n.deletedAcross&&r.deletedAcross?null:new e(n.pos,Math.max(n.pos,r.pos),this.slice,this.structure)}merge(t){if(!(t instanceof e)||t.structure||this.structure)return null;if(this.from+this.slice.size==t.from&&!this.slice.openEnd&&!t.slice.openStart){let n=this.slice.size+t.slice.size==0?Slice.empty:new Slice(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new e(this.from,this.to+(t.to-t.from),n,this.structure)}else if(t.to==this.from&&!this.slice.openStart&&!t.slice.openEnd){let n=this.slice.size+t.slice.size==0?Slice.empty:new Slice(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new e(t.from,this.to,n,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(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`)throw RangeError(`Invalid input for ReplaceStep.fromJSON`);return new e(n.from,n.to,Slice.fromJSON(t,n.slice),!!n.structure)}};Step.jsonID(`replace`,ReplaceStep);var ReplaceAroundStep=class e extends Step{constructor(e,t,n,r,a,o,s=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=r,this.slice=a,this.insert=o,this.structure=s}apply(e){if(this.structure&&(contentBetween(e,this.from,this.gapFrom)||contentBetween(e,this.gapTo,this.to)))return StepResult.fail(`Structure gap-replace would overwrite content`);let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return StepResult.fail(`Gap is not a flat range`);let n=this.slice.insertAt(this.insert,t.content);return n?StepResult.fromReplace(e,this.from,this.to,n):StepResult.fail(`Content does not fit in gap`)}getMap(){return new StepMap([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let n=this.gapTo-this.gapFrom;return new e(this.from,this.from+this.slice.size+n,this.from+this.insert,this.from+this.insert+n,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let n=t.mapResult(this.from,1),r=t.mapResult(this.to,-1),a=this.from==this.gapFrom?n.pos:t.map(this.gapFrom,-1),o=this.to==this.gapTo?r.pos:t.map(this.gapTo,1);return n.deletedAcross&&r.deletedAcross||a<n.pos||o>r.pos?null:new e(n.pos,r.pos,a,o,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(t,n){if(typeof n.from!=`number`||typeof n.to!=`number`||typeof n.gapFrom!=`number`||typeof n.gapTo!=`number`||typeof n.insert!=`number`)throw RangeError(`Invalid input for ReplaceAroundStep.fromJSON`);return new e(n.from,n.to,n.gapFrom,n.gapTo,Slice.fromJSON(t,n.slice),n.insert,!!n.structure)}};Step.jsonID(`replaceAround`,ReplaceAroundStep);function contentBetween(e,t,n){let r=e.resolve(t),a=n-t,o=r.depth;for(;a>0&&o>0&&r.indexAfter(o)==r.node(o).childCount;)o--,a--;if(a>0){let e=r.node(o).maybeChild(r.indexAfter(o));for(;a>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,a--}}return!1}function addMark(e,t,n,r){let a=[],o=[],s,c;e.doc.nodesBetween(t,n,(e,l,u)=>{if(!e.isInline)return;let d=e.marks;if(!r.isInSet(d)&&u.type.allowsMarkType(r.type)){let u=Math.max(l,t),f=Math.min(l+e.nodeSize,n),p=r.addToSet(d);for(let e=0;e<d.length;e++)d[e].isInSet(p)||(s&&s.to==u&&s.mark.eq(d[e])?s.to=f:a.push(s=new RemoveMarkStep(u,f,d[e])));c&&c.to==u?c.to=f:o.push(c=new AddMarkStep(u,f,r))}}),a.forEach(t=>e.step(t)),o.forEach(t=>e.step(t))}function removeMark(e,t,n,r){let a=[],o=0;e.doc.nodesBetween(t,n,(e,s)=>{if(!e.isInline)return;o++;let c=null;if(r instanceof MarkType){let t=e.marks,n;for(;n=r.isInSet(t);)(c||=[]).push(n),t=n.removeFromSet(t)}else r?r.isInSet(e.marks)&&(c=[r]):c=e.marks;if(c&&c.length){let r=Math.min(s+e.nodeSize,n);for(let e=0;e<c.length;e++){let n=c[e],l;for(let e=0;e<a.length;e++){let t=a[e];t.step==o-1&&n.eq(a[e].style)&&(l=t)}l?(l.to=r,l.step=o):a.push({style:n,from:Math.max(s,t),to:r,step:o})}}}),a.forEach(t=>e.step(new RemoveMarkStep(t.from,t.to,t.style)))}function clearIncompatible(e,t,n,r=n.contentMatch,a=!0){let o=e.doc.nodeAt(t),s=[],c=t+1;for(let t=0;t<o.childCount;t++){let l=o.child(t),u=c+l.nodeSize,d=r.matchType(l.type);if(!d)s.push(new ReplaceStep(c,u,Slice.empty));else{r=d;for(let t=0;t<l.marks.length;t++)n.allowsMarkType(l.marks[t].type)||e.step(new RemoveMarkStep(c,u,l.marks[t]));if(a&&l.isText&&n.whitespace!=`pre`){let e,t=/\r?\n|\r/g,r;for(;e=t.exec(l.text);)r||=new Slice(Fragment.from(n.schema.text(` `,n.allowedMarks(l.marks))),0,0),s.push(new ReplaceStep(c+e.index,c+e.index+e[0].length,r))}}c=u}if(!r.validEnd){let t=r.fillBefore(Fragment.empty,!0);e.replace(c,c,new Slice(t,0,0))}for(let t=s.length-1;t>=0;t--)e.step(s[t])}function canCut(e,t,n){return(t==0||e.canReplace(t,e.childCount))&&(n==e.childCount||e.canReplace(0,n))}function liftTarget(e){let t=e.parent.content.cutByIndex(e.startIndex,e.endIndex);for(let n=e.depth;;--n){let r=e.$from.node(n),a=e.$from.index(n),o=e.$to.indexAfter(n);if(n<e.depth&&r.canReplace(a,o,t))return n;if(n==0||r.type.spec.isolating||!canCut(r,a,o))break}return null}function lift$1(e,t,n){let{$from:r,$to:a,depth:o}=t,s=r.before(o+1),c=a.after(o+1),l=s,u=c,d=Fragment.empty,f=0;for(let e=o,t=!1;e>n;e--)t||r.index(e)>0?(t=!0,d=Fragment.from(r.node(e).copy(d)),f++):l--;let p=Fragment.empty,m=0;for(let e=o,t=!1;e>n;e--)t||a.after(e+1)<a.end(e)?(t=!0,p=Fragment.from(a.node(e).copy(p)),m++):u++;e.step(new ReplaceAroundStep(l,u,s,c,new Slice(d.append(p),f,m),d.size-f,!0))}function findWrapping(e,t,n=null,r=e){let a=findWrappingOutside(e,t),o=a&&findWrappingInside(r,t);return o?a.map(withAttrs).concat({type:t,attrs:n}).concat(o.map(withAttrs)):null}function withAttrs(e){return{type:e,attrs:null}}function findWrappingOutside(e,t){let{parent:n,startIndex:r,endIndex:a}=e,o=n.contentMatchAt(r).findWrapping(t);if(!o)return null;let s=o.length?o[0]:t;return n.canReplaceWith(r,a,s)?o:null}function findWrappingInside(e,t){let{parent:n,startIndex:r,endIndex:a}=e,o=n.child(r),s=t.contentMatch.findWrapping(o.type);if(!s)return null;let c=(s.length?s[s.length-1]:t).contentMatch;for(let e=r;c&&e<a;e++)c=c.matchType(n.child(e).type);return!c||!c.validEnd?null:s}function wrap(e,t,n){let r=Fragment.empty;for(let e=n.length-1;e>=0;e--){if(r.size){let t=n[e].type.contentMatch.matchFragment(r);if(!t||!t.validEnd)throw RangeError(`Wrapper type given to Transform.wrap does not form valid content of its parent wrapper`)}r=Fragment.from(n[e].type.create(n[e].attrs,r))}let a=t.start,o=t.end;e.step(new ReplaceAroundStep(a,o,a,o,new Slice(r,0,0),n.length,!0))}function setBlockType$1(e,t,n,r,a){if(!r.isTextblock)throw RangeError(`Type given to setBlockType should be a textblock`);let o=e.steps.length;e.doc.nodesBetween(t,n,(t,n)=>{let s=typeof a==`function`?a(t):a;if(t.isTextblock&&!t.hasMarkup(r,s)&&canChangeType(e.doc,e.mapping.slice(o).map(n),r)){let a=null;if(r.schema.linebreakReplacement){let e=r.whitespace==`pre`,t=!!r.contentMatch.matchType(r.schema.linebreakReplacement);e&&!t?a=!1:!e&&t&&(a=!0)}a===!1&&replaceLinebreaks(e,t,n,o),clearIncompatible(e,e.mapping.slice(o).map(n,1),r,void 0,a===null);let c=e.mapping.slice(o),l=c.map(n,1),u=c.map(n+t.nodeSize,1);return e.step(new ReplaceAroundStep(l,u,l+1,u-1,new Slice(Fragment.from(r.create(s,null,t.marks)),0,0),1,!0)),a===!0&&replaceNewlines(e,t,n,o),!1}})}function replaceNewlines(e,t,n,r){t.forEach((a,o)=>{if(a.isText){let s,c=/\r?\n|\r/g;for(;s=c.exec(a.text);){let a=e.mapping.slice(r).map(n+1+o+s.index);e.replaceWith(a,a+1,t.type.schema.linebreakReplacement.create())}}})}function replaceLinebreaks(e,t,n,r){t.forEach((a,o)=>{if(a.type==a.type.schema.linebreakReplacement){let a=e.mapping.slice(r).map(n+1+o);e.replaceWith(a,a+1,t.type.schema.text(`
5
5
  `))}})}function canChangeType(e,t,n){let r=e.resolve(t),a=r.index();return r.parent.canReplaceWith(a,a+1,n)}function setNodeMarkup(e,t,n,r,a){let o=e.doc.nodeAt(t);if(!o)throw RangeError(`No node at given position`);n||=o.type;let s=n.create(r,null,a||o.marks);if(o.isLeaf)return e.replaceWith(t,t+o.nodeSize,s);if(!n.validContent(o.content))throw RangeError(`Invalid content for node type `+n.name);e.step(new ReplaceAroundStep(t,t+o.nodeSize,t+1,t+o.nodeSize-1,new Slice(Fragment.from(s),0,0),1,!0))}function canSplit(e,t,n=1,r){let a=e.resolve(t),o=a.depth-n,s=r&&r[r.length-1]||a.parent;if(o<0||a.parent.type.spec.isolating||!a.parent.canReplace(a.index(),a.parent.childCount)||!s.type.validContent(a.parent.content.cutByIndex(a.index(),a.parent.childCount)))return!1;for(let e=a.depth-1,t=n-2;e>o;e--,t--){let n=a.node(e),o=a.index(e);if(n.type.spec.isolating)return!1;let s=n.content.cutByIndex(o,n.childCount),c=r&&r[t+1];c&&(s=s.replaceChild(0,c.type.create(c.attrs)));let l=r&&r[t]||n;if(!n.canReplace(o+1,n.childCount)||!l.type.validContent(s))return!1}let c=a.indexAfter(o),l=r&&r[0];return a.node(o).canReplaceWith(c,c,l?l.type:a.node(o+1).type)}function split(e,t,n=1,r){let a=e.doc.resolve(t),o=Fragment.empty,s=Fragment.empty;for(let e=a.depth,t=a.depth-n,c=n-1;e>t;e--,c--){o=Fragment.from(a.node(e).copy(o));let t=r&&r[c];s=Fragment.from(t?t.type.create(t.attrs,s):a.node(e).copy(s))}e.step(new ReplaceStep(t,t,new Slice(o.append(s),n,n),!0))}function canJoin(e,t){let n=e.resolve(t),r=n.index();return joinable(n.nodeBefore,n.nodeAfter)&&n.parent.canReplace(r,r+1)}function canAppendWithSubstitutedLinebreaks(e,t){t.content.size||e.type.compatibleContent(t.type);let n=e.contentMatchAt(e.childCount),{linebreakReplacement:r}=e.type.schema;for(let a=0;a<t.childCount;a++){let o=t.child(a),s=o.type==r?e.type.schema.nodes.text:o.type;if(n=n.matchType(s),!n||!e.type.allowsMarks(o.marks))return!1}return n.validEnd}function joinable(e,t){return!!(e&&t&&!e.isLeaf&&canAppendWithSubstitutedLinebreaks(e,t))}function joinPoint(e,t,n=-1){let r=e.resolve(t);for(let e=r.depth;;e--){let a,o,s=r.index(e);if(e==r.depth?(a=r.nodeBefore,o=r.nodeAfter):n>0?(a=r.node(e+1),s++,o=r.node(e).maybeChild(s)):(a=r.node(e).maybeChild(s-1),o=r.node(e+1)),a&&!a.isTextblock&&joinable(a,o)&&r.node(e).canReplace(s,s+1))return t;if(e==0)break;t=n<0?r.before(e):r.after(e)}}function join(e,t,n){let r=null,{linebreakReplacement:a}=e.doc.type.schema,o=e.doc.resolve(t-n),s=o.node().type;if(a&&s.inlineContent){let e=s.whitespace==`pre`,t=!!s.contentMatch.matchType(a);e&&!t?r=!1:!e&&t&&(r=!0)}let c=e.steps.length;if(r===!1){let r=e.doc.resolve(t+n);replaceLinebreaks(e,r.node(),r.before(),c)}s.inlineContent&&clearIncompatible(e,t+n-1,s,o.node().contentMatchAt(o.index()),r==null);let l=e.mapping.slice(c),u=l.map(t-n);if(e.step(new ReplaceStep(u,l.map(t+n,-1),Slice.empty,!0)),r===!0){let t=e.doc.resolve(u);replaceNewlines(e,t.node(),t.before(),e.steps.length)}return e}function insertPoint(e,t,n){let r=e.resolve(t);if(r.parent.canReplaceWith(r.index(),r.index(),n))return t;if(r.parentOffset==0)for(let e=r.depth-1;e>=0;e--){let t=r.index(e);if(r.node(e).canReplaceWith(t,t,n))return r.before(e+1);if(t>0)return null}if(r.parentOffset==r.parent.content.size)for(let e=r.depth-1;e>=0;e--){let t=r.indexAfter(e);if(r.node(e).canReplaceWith(t,t,n))return r.after(e+1);if(t<r.node(e).childCount)return null}return null}function dropPoint(e,t,n){let r=e.resolve(t);if(!n.content.size)return t;let a=n.content;for(let e=0;e<n.openStart;e++)a=a.firstChild.content;for(let e=1;e<=(n.openStart==0&&n.size?2:1);e++)for(let t=r.depth;t>=0;t--){let n=t==r.depth?0:r.pos<=(r.start(t+1)+r.end(t+1))/2?-1:1,o=r.index(t)+ +(n>0),s=r.node(t),c=!1;if(e==1)c=s.canReplace(o,o,a);else{let e=s.contentMatchAt(o).findWrapping(a.firstChild.type);c=e&&s.canReplaceWith(o,o,e[0])}if(c)return n==0?r.pos:n<0?r.before(t+1):r.after(t+1)}return null}function replaceStep(e,t,n=t,r=Slice.empty){if(t==n&&!r.size)return null;let a=e.resolve(t),o=e.resolve(n);return fitsTrivially(a,o,r)?new ReplaceStep(t,n,r):new Fitter(a,o,r).fit()}function fitsTrivially(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}var Fitter=class{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=Fragment.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=Fragment.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,r=this.close(e<0?this.$to:n.doc.resolve(e));if(!r)return null;let a=this.placed,o=n.depth,s=r.depth;for(;o&&s&&a.childCount==1;)a=a.firstChild.content,o--,s--;let c=new Slice(a,o,s);return e>-1?new ReplaceAroundStep(n.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||n.pos!=this.$to.pos?new ReplaceStep(n.pos,r.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,r=this.unplaced.openEnd;n<e;n++){let a=t.firstChild;if(t.childCount>1&&(r=0),a.type.spec.isolating&&r<=n){e=n;break}t=a.content}for(let t=1;t<=2;t++)for(let n=t==1?e:this.unplaced.openStart;n>=0;n--){let e,r=null;n?(r=contentAt(this.unplaced.content,n-1).firstChild,e=r.content):e=this.unplaced.content;let a=e.firstChild;for(let e=this.depth;e>=0;e--){let{type:o,match:s}=this.frontier[e],c,l=null;if(t==1&&(a?s.matchType(a.type)||(l=s.fillBefore(Fragment.from(a),!1)):r&&o.compatibleContent(r.type)))return{sliceDepth:n,frontierDepth:e,parent:r,inject:l};if(t==2&&a&&(c=s.findWrapping(a.type)))return{sliceDepth:n,frontierDepth:e,parent:r,wrap:c};if(r&&s.matchType(r.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=contentAt(e,t);return!r.childCount||r.firstChild.isLeaf?!1:(this.unplaced=new Slice(e,t+1,Math.max(n,r.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,r=contentAt(e,t);if(r.childCount<=1&&t>0){let a=e.size-t<=t+r.size;this.unplaced=new Slice(dropFromFragment(e,t-1,1),t-1,a?t-1:n)}else this.unplaced=new Slice(dropFromFragment(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:r,wrap:a}){for(;this.depth>t;)this.closeFrontierNode();if(a)for(let e=0;e<a.length;e++)this.openFrontierNode(a[e]);let o=this.unplaced,s=n?n.content:o.content,c=o.openStart-e,l=0,u=[],{match:d,type:f}=this.frontier[t];if(r){for(let e=0;e<r.childCount;e++)u.push(r.child(e));d=d.matchFragment(r)}let p=s.size+e-(o.content.size-o.openEnd);for(;l<s.childCount;){let e=s.child(l),t=d.matchType(e.type);if(!t)break;l++,(l>1||c==0||e.content.size)&&(d=t,u.push(closeNodeStart(e.mark(f.allowedMarks(e.marks)),l==1?c:0,l==s.childCount?p:-1)))}let m=l==s.childCount;m||(p=-1),this.placed=addToFragment(this.placed,t,Fragment.from(u)),this.frontier[t].match=d,m&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=s;e<p;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=m?e==0?Slice.empty:new Slice(dropFromFragment(o.content,e-1,1),e-1,p<0?o.openEnd:e-1):new Slice(dropFromFragment(o.content,e,l),o.openStart,o.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e=this.frontier[this.depth],t;if(!e.type.isTextblock||!contentAfterFits(this.$to,this.$to.depth,e.type,e.match,!1)||this.$to.depth==this.depth&&(t=this.findCloseLevel(this.$to))&&t.depth==this.depth)return-1;let{depth:n}=this.$to,r=this.$to.after(n);for(;n>1&&r==this.$to.end(--n);)++r;return r}findCloseLevel(e){scan:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:r}=this.frontier[t],a=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),o=contentAfterFits(e,t,r,n,a);if(o){for(let n=t-1;n>=0;n--){let{match:t,type:r}=this.frontier[n],a=contentAfterFits(e,n,r,t,!0);if(!a||a.childCount)continue scan}return{depth:t,fit:o,move:a?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=addToFragment(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),r=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,r)}return e}openFrontierNode(e,t=null,n){let r=this.frontier[this.depth];r.match=r.match.matchType(e),this.placed=addToFragment(this.placed,this.depth,Fragment.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(Fragment.empty,!0);e.childCount&&(this.placed=addToFragment(this.placed,this.frontier.length,e))}};function dropFromFragment(e,t,n){return t==0?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(dropFromFragment(e.firstChild.content,t-1,n)))}function addToFragment(e,t,n){return t==0?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(addToFragment(e.lastChild.content,t-1,n)))}function contentAt(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function closeNodeStart(e,t,n){if(t<=0)return e;let r=e.content;return t>1&&(r=r.replaceChild(0,closeNodeStart(r.firstChild,t-1,r.childCount==1?n-1:0))),t>0&&(r=e.type.contentMatch.fillBefore(r).append(r),n<=0&&(r=r.append(e.type.contentMatch.matchFragment(r).fillBefore(Fragment.empty,!0)))),e.copy(r)}function contentAfterFits(e,t,n,r,a){let o=e.node(t),s=a?e.indexAfter(t):e.index(t);if(s==o.childCount&&!n.compatibleContent(o.type))return null;let c=r.fillBefore(o.content,!0,s);return c&&!invalidMarks(n,o.content,s)?c:null}function invalidMarks(e,t,n){for(let r=n;r<t.childCount;r++)if(!e.allowsMarks(t.child(r).marks))return!0;return!1}function definesContent(e){return e.spec.defining||e.spec.definingForContent}function replaceRange(e,t,n,r){if(!r.size)return e.deleteRange(t,n);let a=e.doc.resolve(t),o=e.doc.resolve(n);if(fitsTrivially(a,o,r))return e.step(new ReplaceStep(t,n,r));let s=coveredDepths(a,e.doc.resolve(n));s[s.length-1]==0&&s.pop();let c=-(a.depth+1);s.unshift(c);for(let e=a.depth,t=a.pos-1;e>0;e--,t--){let n=a.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;s.indexOf(e)>-1?c=e:a.before(e)==t&&s.splice(1,0,-e)}let l=s.indexOf(c),u=[],d=r.openStart;for(let e=r.content,t=0;;t++){let n=e.firstChild;if(u.push(n),t==r.openStart)break;e=n.content}for(let e=d-1;e>=0;e--){let t=u[e],n=definesContent(t.type);if(n&&!t.sameMarkup(a.node(Math.abs(c)-1)))d=e;else if(n||!t.type.isTextblock)break}for(let t=r.openStart;t>=0;t--){let c=(t+d+1)%(r.openStart+1),f=u[c];if(f)for(let t=0;t<s.length;t++){let u=s[(t+l)%s.length],d=!0;u<0&&(d=!1,u=-u);let p=a.node(u-1),m=a.index(u-1);if(p.canReplaceWith(m,m,f.type,f.marks))return e.replace(a.before(u),d?o.after(u):n,new Slice(closeFragment(r.content,0,r.openStart,c),c,r.openEnd))}}let f=e.steps.length;for(let c=s.length-1;c>=0&&(e.replace(t,n,r),!(e.steps.length>f));c--){let e=s[c];e<0||(t=a.before(e),n=o.after(e))}}function closeFragment(e,t,n,r,a){if(t<n){let a=e.firstChild;e=e.replaceChild(0,a.copy(closeFragment(a.content,t+1,n,r,a)))}if(t>r){let t=a.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(Fragment.empty,!0))}return e}function replaceRangeWith(e,t,n,r){if(!r.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let a=insertPoint(e.doc,t,r.type);a!=null&&(t=n=a)}e.replaceRange(t,n,new Slice(Fragment.from(r),0,0))}function deleteRange(e,t,n){let r=e.doc.resolve(t),a=e.doc.resolve(n),o=coveredDepths(r,a);for(let t=0;t<o.length;t++){let n=o[t],s=t==o.length-1;if(s&&n==0||r.node(n).type.contentMatch.validEnd)return e.delete(r.start(n),a.end(n));if(n>0&&(s||r.node(n-1).canReplace(r.index(n-1),a.indexAfter(n-1))))return e.delete(r.before(n),a.after(n))}for(let o=1;o<=r.depth&&o<=a.depth;o++)if(t-r.start(o)==r.depth-o&&n>r.end(o)&&a.end(o)-n!=a.depth-o&&r.start(o-1)==a.start(o-1)&&r.node(o-1).canReplace(r.index(o-1),a.index(o-1)))return e.delete(r.before(o),n);e.delete(t,n)}function coveredDepths(e,t){let n=[],r=Math.min(e.depth,t.depth);for(let a=r;a>=0;a--){let r=e.start(a);if(r<e.pos-(e.depth-a)||t.end(a)>t.pos+(t.depth-a)||e.node(a).type.spec.isolating||t.node(a).type.spec.isolating)break;(r==t.start(a)||a==e.depth&&a==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&a&&t.start(a-1)==r-1)&&n.push(a)}return n}var AttrStep=class e extends Step{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return StepResult.fail(`No node at attribute step's position`);let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let r=t.type.create(n,null,t.marks);return StepResult.fromReplace(e,this.pos,this.pos+1,new Slice(Fragment.from(r),0,+!t.isLeaf))}getMap(){return StepMap.empty}invert(t){return new e(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let n=t.mapResult(this.pos,1);return n.deletedAfter?null:new e(n.pos,this.attr,this.value)}toJSON(){return{stepType:`attr`,pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.pos!=`number`||typeof n.attr!=`string`)throw RangeError(`Invalid input for AttrStep.fromJSON`);return new e(n.pos,n.attr,n.value)}};Step.jsonID(`attr`,AttrStep);var DocAttrStep=class e extends Step{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return StepResult.ok(n)}getMap(){return StepMap.empty}invert(t){return new e(this.attr,t.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:`docAttr`,attr:this.attr,value:this.value}}static fromJSON(t,n){if(typeof n.attr!=`string`)throw RangeError(`Invalid input for DocAttrStep.fromJSON`);return new e(n.attr,n.value)}};Step.jsonID(`docAttr`,DocAttrStep);var TransformError=class extends Error{};TransformError=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},TransformError.prototype=Object.create(Error.prototype),TransformError.prototype.constructor=TransformError,TransformError.prototype.name=`TransformError`;var Transform=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Mapping}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new TransformError(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=Slice.empty){let r=replaceStep(this.doc,e,t,n);return r&&this.step(r),this}replaceWith(e,t,n){return this.replace(e,t,new Slice(Fragment.from(n),0,0))}delete(e,t){return this.replace(e,t,Slice.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return replaceRange(this,e,t,n),this}replaceRangeWith(e,t,n){return replaceRangeWith(this,e,t,n),this}deleteRange(e,t){return deleteRange(this,e,t),this}lift(e,t){return lift$1(this,e,t),this}join(e,t=1){return join(this,e,t),this}wrap(e,t){return wrap(this,e,t),this}setBlockType(e,t=e,n,r=null){return setBlockType$1(this,e,t,n,r),this}setNodeMarkup(e,t,n=null,r){return setNodeMarkup(this,e,t,n,r),this}setNodeAttribute(e,t,n){return this.step(new AttrStep(e,t,n)),this}setDocAttribute(e,t){return this.step(new DocAttrStep(e,t)),this}addNodeMark(e,t){return this.step(new AddNodeMarkStep(e,t)),this}removeNodeMark(e,t){let n=this.doc.nodeAt(e);if(!n)throw RangeError(`No node at position `+e);if(t instanceof Mark$1)t.isInSet(n.marks)&&this.step(new RemoveNodeMarkStep(e,t));else{let r=n.marks,a,o=[];for(;a=t.isInSet(r);)o.push(new RemoveNodeMarkStep(e,a)),r=a.removeFromSet(r);for(let e=o.length-1;e>=0;e--)this.step(o[e])}return this}split(e,t=1,n){return split(this,e,t,n),this}addMark(e,t,n){return addMark(this,e,t,n),this}removeMark(e,t,n){return removeMark(this,e,t,n),this}clearIncompatible(e,t,n){return clearIncompatible(this,e,t,n),this}},classesById=Object.create(null),Selection=class{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new SelectionRange(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=Slice.empty){let n=t.content.lastChild,r=null;for(let e=0;e<t.openEnd;e++)r=n,n=n.lastChild;let a=e.steps.length,o=this.ranges;for(let s=0;s<o.length;s++){let{$from:c,$to:l}=o[s],u=e.mapping.slice(a);e.replaceRange(u.map(c.pos),u.map(l.pos),s?Slice.empty:t),s==0&&selectionToInsertionEnd(e,a,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,r=this.ranges;for(let a=0;a<r.length;a++){let{$from:o,$to:s}=r[a],c=e.mapping.slice(n),l=c.map(o.pos),u=c.map(s.pos);a?e.deleteRange(l,u):(e.replaceRangeWith(l,u,t),selectionToInsertionEnd(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let r=e.parent.inlineContent?new TextSelection(e):findSelectionIn(e.node(0),e.parent,e.pos,e.index(),t,n);if(r)return r;for(let r=e.depth-1;r>=0;r--){let a=t<0?findSelectionIn(e.node(0),e.node(r),e.before(r+1),e.index(r),t,n):findSelectionIn(e.node(0),e.node(r),e.after(r+1),e.index(r)+1,t,n);if(a)return a}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new AllSelection(e.node(0))}static atStart(e){return findSelectionIn(e,e,0,0,1)||new AllSelection(e)}static atEnd(e){return findSelectionIn(e,e,e.content.size,e.childCount,-1)||new AllSelection(e)}static fromJSON(e,t){if(!t||!t.type)throw RangeError(`Invalid input for Selection.fromJSON`);let n=classesById[t.type];if(!n)throw RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in classesById)throw RangeError(`Duplicate use of selection JSON ID `+e);return classesById[e]=t,t.prototype.jsonID=e,t}getBookmark(){return TextSelection.between(this.$anchor,this.$head).getBookmark()}};Selection.prototype.visible=!0;var SelectionRange=class{constructor(e,t){this.$from=e,this.$to=t}},warnedAboutTextSelection=!1;function checkTextSelection(e){!warnedAboutTextSelection&&!e.parent.inlineContent&&(warnedAboutTextSelection=!0,console.warn(`TextSelection endpoint not pointing into a node with inline content (`+e.parent.type.name+`)`))}var TextSelection=class e extends Selection{constructor(e,t=e){checkTextSelection(e),checkTextSelection(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,n){let r=t.resolve(n.map(this.head));if(!r.parent.inlineContent)return Selection.near(r);let a=t.resolve(n.map(this.anchor));return new e(a.parent.inlineContent?a:r,r)}replace(e,t=Slice.empty){if(super.replace(e,t),t==Slice.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(t){return t instanceof e&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new TextBookmark(this.anchor,this.head)}toJSON(){return{type:`text`,anchor:this.anchor,head:this.head}}static fromJSON(t,n){if(typeof n.anchor!=`number`||typeof n.head!=`number`)throw RangeError(`Invalid input for TextSelection.fromJSON`);return new e(t.resolve(n.anchor),t.resolve(n.head))}static create(e,t,n=t){let r=e.resolve(t);return new this(r,n==t?r:e.resolve(n))}static between(t,n,r){let a=t.pos-n.pos;if((!r||a)&&(r=a>=0?1:-1),!n.parent.inlineContent){let e=Selection.findFrom(n,r,!0)||Selection.findFrom(n,-r,!0);if(e)n=e.$head;else return Selection.near(n,r)}return t.parent.inlineContent||(a==0?t=n:(t=(Selection.findFrom(t,-r,!0)||Selection.findFrom(t,r,!0)).$anchor,t.pos<n.pos!=a<0&&(t=n))),new e(t,n)}};Selection.jsonID(`text`,TextSelection);var TextBookmark=class e{constructor(e,t){this.anchor=e,this.head=t}map(t){return new e(t.map(this.anchor),t.map(this.head))}resolve(e){return TextSelection.between(e.resolve(this.anchor),e.resolve(this.head))}},NodeSelection=class e extends Selection{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(t,n){let{deleted:r,pos:a}=n.mapResult(this.anchor),o=t.resolve(a);return r?Selection.near(o):new e(o)}content(){return new Slice(Fragment.from(this.node),0,0)}eq(t){return t instanceof e&&t.anchor==this.anchor}toJSON(){return{type:`node`,anchor:this.anchor}}getBookmark(){return new NodeBookmark$1(this.anchor)}static fromJSON(t,n){if(typeof n.anchor!=`number`)throw RangeError(`Invalid input for NodeSelection.fromJSON`);return new e(t.resolve(n.anchor))}static create(t,n){return new e(t.resolve(n))}static isSelectable(e){return!e.isText&&e.type.spec.selectable!==!1}};NodeSelection.prototype.visible=!1,Selection.jsonID(`node`,NodeSelection);var NodeBookmark$1=class e{constructor(e){this.anchor=e}map(t){let{deleted:n,pos:r}=t.mapResult(this.anchor);return n?new TextBookmark(r,r):new e(r)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&NodeSelection.isSelectable(n)?new NodeSelection(t):Selection.near(t)}},AllSelection=class e extends Selection{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=Slice.empty){if(t==Slice.empty){e.delete(0,e.doc.content.size);let t=Selection.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:`all`}}static fromJSON(t){return new e(t)}map(t){return new e(t)}eq(t){return t instanceof e}getBookmark(){return AllBookmark}};Selection.jsonID(`all`,AllSelection);var AllBookmark={map(){return this},resolve(e){return new AllSelection(e)}};function findSelectionIn(e,t,n,r,a,o=!1){if(t.inlineContent)return TextSelection.create(e,n);for(let s=r-(a>0?0:1);a>0?s<t.childCount:s>=0;s+=a){let r=t.child(s);if(!r.isAtom){let t=findSelectionIn(e,r,n+a,a<0?r.childCount:0,a,o);if(t)return t}else if(!o&&NodeSelection.isSelectable(r))return NodeSelection.create(e,n-(a<0?r.nodeSize:0));n+=r.nodeSize*a}return null}function selectionToInsertionEnd(e,t,n){let r=e.steps.length-1;if(r<t)return;let a=e.steps[r];if(!(a instanceof ReplaceStep||a instanceof ReplaceAroundStep))return;let o=e.mapping.maps[r],s;o.forEach((e,t,n,r)=>{s??=r}),e.setSelection(Selection.near(e.doc.resolve(s),n))}var UPDATED_SEL=1,UPDATED_MARKS=2,UPDATED_SCROLL=4,Transaction=class extends Transform{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor<this.steps.length&&(this.curSelection=this.curSelection.map(this.doc,this.mapping.slice(this.curSelectionFor)),this.curSelectionFor=this.steps.length),this.curSelection}setSelection(e){if(e.$from.doc!=this.doc)throw RangeError(`Selection passed to setSelection must point at the current document`);return this.curSelection=e,this.curSelectionFor=this.steps.length,this.updated=(this.updated|UPDATED_SEL)&-3,this.storedMarks=null,this}get selectionSet(){return(this.updated&UPDATED_SEL)>0}setStoredMarks(e){return this.storedMarks=e,this.updated|=UPDATED_MARKS,this}ensureMarks(e){return Mark$1.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&UPDATED_MARKS)>0}addStep(e,t){super.addStep(e,t),this.updated&=-3,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let n=this.selection;return t&&(e=e.mark(this.storedMarks||(n.empty?n.$from.marks():n.$from.marksAcross(n.$to)||Mark$1.none))),n.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,n){let r=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(r.text(e),!0):this.deleteSelection();{if(n??=t,n??=t,!e)return this.deleteRange(t,n);let a=this.storedMarks;if(!a){let e=this.doc.resolve(t);a=n==t?e.marks():e.marksAcross(this.doc.resolve(n))}return this.replaceRangeWith(t,n,r.text(e,a)),this.selection.empty||this.setSelection(Selection.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e==`string`?e:e.key]=t,this}getMeta(e){return this.meta[typeof e==`string`?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=UPDATED_SCROLL,this}get scrolledIntoView(){return(this.updated&UPDATED_SCROLL)>0}};function bind(e,t){return!t||!e?e:e.bind(t)}var FieldDesc=class{constructor(e,t,n){this.name=e,this.init=bind(t.init,n),this.apply=bind(t.apply,n)}},baseFields=[new FieldDesc(`doc`,{init(e){return e.doc||e.schema.topNodeType.createAndFill()},apply(e){return e.doc}}),new FieldDesc(`selection`,{init(e,t){return e.selection||Selection.atStart(t.doc)},apply(e){return e.selection}}),new FieldDesc(`storedMarks`,{init(e){return e.storedMarks||null},apply(e,t,n,r){return r.selection.$cursor?e.storedMarks:null}}),new FieldDesc(`scrollToSelection`,{init(){return 0},apply(e,t){return e.scrolledIntoView?t+1:t}})],Configuration=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=baseFields.slice(),t&&t.forEach(e=>{if(this.pluginsByKey[e.key])throw RangeError(`Adding different instances of a keyed plugin (`+e.key+`)`);this.plugins.push(e),this.pluginsByKey[e.key]=e,e.spec.state&&this.fields.push(new FieldDesc(e.key,e.spec.state,e))})}},EditorState=class e{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let n=0;n<this.config.plugins.length;n++)if(n!=t){let t=this.config.plugins[n];if(t.spec.filterTransaction&&!t.spec.filterTransaction.call(t,e,this))return!1}return!0}applyTransaction(e){if(!this.filterTransaction(e))return{state:this,transactions:[]};let t=[e],n=this.applyInner(e),r=null;for(;;){let a=!1;for(let o=0;o<this.config.plugins.length;o++){let s=this.config.plugins[o];if(s.spec.appendTransaction){let c=r?r[o].n:0,l=r?r[o].state:this,u=c<t.length&&s.spec.appendTransaction.call(s,c?t.slice(c):t,l,n);if(u&&n.filterTransaction(u,o)){if(u.setMeta(`appendedTransaction`,e),!r){r=[];for(let e=0;e<this.config.plugins.length;e++)r.push(e<o?{state:n,n:t.length}:{state:this,n:0})}t.push(u),n=n.applyInner(u),a=!0}r&&(r[o]={state:n,n:t.length})}}if(!a)return{state:n,transactions:t}}}applyInner(t){if(!t.before.eq(this.doc))throw RangeError(`Applying a mismatched transaction`);let n=new e(this.config),r=this.config.fields;for(let e=0;e<r.length;e++){let a=r[e];n[a.name]=a.apply(t,this[a.name],this,n)}return n}get tr(){return new Transaction(this)}static create(t){let n=new Configuration(t.doc?t.doc.type.schema:t.schema,t.plugins),r=new e(n);for(let e=0;e<n.fields.length;e++)r[n.fields[e].name]=n.fields[e].init(t,r);return r}reconfigure(t){let n=new Configuration(this.schema,t.plugins),r=n.fields,a=new e(n);for(let e=0;e<r.length;e++){let n=r[e].name;a[n]=this.hasOwnProperty(n)?this[n]:r[e].init(t,a)}return a}toJSON(e){let t={doc:this.doc.toJSON(),selection:this.selection.toJSON()};if(this.storedMarks&&(t.storedMarks=this.storedMarks.map(e=>e.toJSON())),e&&typeof e==`object`)for(let n in e){if(n==`doc`||n==`selection`)throw RangeError("The JSON fields `doc` and `selection` are reserved");let r=e[n],a=r.spec.state;a&&a.toJSON&&(t[n]=a.toJSON.call(r,this[r.key]))}return t}static fromJSON(t,n,r){if(!n)throw RangeError(`Invalid input for EditorState.fromJSON`);if(!t.schema)throw RangeError(`Required config field 'schema' missing`);let a=new Configuration(t.schema,t.plugins),o=new e(a);return a.fields.forEach(e=>{if(e.name==`doc`)o.doc=Node$3.fromJSON(t.schema,n.doc);else if(e.name==`selection`)o.selection=Selection.fromJSON(o.doc,n.selection);else if(e.name==`storedMarks`)n.storedMarks&&(o.storedMarks=n.storedMarks.map(t.schema.markFromJSON));else{if(r)for(let a in r){let s=r[a],c=s.spec.state;if(s.key==e.name&&c&&c.fromJSON&&Object.prototype.hasOwnProperty.call(n,a)){o[e.name]=c.fromJSON.call(s,t,n[a],o);return}}o[e.name]=e.init(t,o)}}),o}};function bindProps(e,t,n){for(let r in e){let a=e[r];a instanceof Function?a=a.bind(t):r==`handleDOMEvents`&&(a=bindProps(a,t,{})),n[r]=a}return n}var Plugin=class{constructor(e){this.spec=e,this.props={},e.props&&bindProps(e.props,this,this.props),this.key=e.key?e.key.key:createKey(`plugin`)}getState(e){return e[this.key]}},keys=Object.create(null);function createKey(e){return e in keys?e+`$`+ ++keys[e]:(keys[e]=0,e+`$`)}var PluginKey=class{constructor(e=`key`){this.key=createKey(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}},domIndex=function(e){for(var t=0;;t++)if(e=e.previousSibling,!e)return t},parentNode=function(e){let t=e.assignedSlot||e.parentNode;return t&&t.nodeType==11?t.host:t},reusedRange=null,textRange=function(e,t,n){let r=reusedRange||=document.createRange();return r.setEnd(e,n??e.nodeValue.length),r.setStart(e,t||0),r},clearReusedRange=function(){reusedRange=null},isEquivalentPosition=function(e,t,n,r){return n&&(scanFor(e,t,n,r,-1)||scanFor(e,t,n,r,1))},atomElements=/^(img|br|input|textarea|hr)$/i;function scanFor(e,t,n,r,a){for(var o;;){if(e==n&&t==r)return!0;if(t==(a<0?0:nodeSize(e))){let n=e.parentNode;if(!n||n.nodeType!=1||hasBlockDesc(e)||atomElements.test(e.nodeName)||e.contentEditable==`false`)return!1;t=domIndex(e)+(a<0?0:1),e=n}else if(e.nodeType==1){let n=e.childNodes[t+(a<0?-1:0)];if(n.nodeType==1&&n.contentEditable==`false`)if(n.pmViewDesc?.ignoreForSelection)t+=a;else return!1;else e=n,t=a<0?nodeSize(e):0}else return!1}}function nodeSize(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function textNodeBefore$1(e,t){for(;;){if(e.nodeType==3&&t)return e;if(e.nodeType==1&&t>0){if(e.contentEditable==`false`)return null;e=e.childNodes[t-1],t=nodeSize(e)}else if(e.parentNode&&!hasBlockDesc(e))t=domIndex(e),e=e.parentNode;else return null}}function textNodeAfter$1(e,t){for(;;){if(e.nodeType==3&&t<e.nodeValue.length)return e;if(e.nodeType==1&&t<e.childNodes.length){if(e.contentEditable==`false`)return null;e=e.childNodes[t],t=0}else if(e.parentNode&&!hasBlockDesc(e))t=domIndex(e)+1,e=e.parentNode;else return null}}function isOnEdge(e,t,n){for(let r=t==0,a=t==nodeSize(e);r||a;){if(e==n)return!0;let t=domIndex(e);if(e=e.parentNode,!e)return!1;r&&=t==0,a&&=t==nodeSize(e)}}function hasBlockDesc(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}var selectionCollapsed=function(e){return e.focusNode&&isEquivalentPosition(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function keyEvent(e,t){let n=document.createEvent(`Event`);return n.initEvent(`keydown`,!0,!0),n.keyCode=e,n.key=n.code=t,n}function deepActiveElement(e){let t=e.activeElement;for(;t&&t.shadowRoot;)t=t.shadowRoot.activeElement;return t}function caretFromPoint(e,t,n){if(e.caretPositionFromPoint)try{let r=e.caretPositionFromPoint(t,n);if(r)return{node:r.offsetNode,offset:Math.min(nodeSize(r.offsetNode),r.offset)}}catch{}if(e.caretRangeFromPoint){let r=e.caretRangeFromPoint(t,n);if(r)return{node:r.startContainer,offset:Math.min(nodeSize(r.startContainer),r.startOffset)}}}var nav=typeof navigator<`u`?navigator:null,doc=typeof document<`u`?document:null,agent=nav&&nav.userAgent||``,ie_edge=/Edge\/(\d+)/.exec(agent),ie_upto10=/MSIE \d/.exec(agent),ie_11up=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(agent),ie$1=!!(ie_upto10||ie_11up||ie_edge),ie_version=ie_upto10?document.documentMode:ie_11up?+ie_11up[1]:ie_edge?+ie_edge[1]:0,gecko=!ie$1&&/gecko\/(\d+)/i.test(agent);gecko&&+(/Firefox\/(\d+)/.exec(agent)||[0,0])[1];var _chrome=!ie$1&&/Chrome\/(\d+)/.exec(agent),chrome=!!_chrome,chrome_version=_chrome?+_chrome[1]:0,safari=!ie$1&&!!nav&&/Apple Computer/.test(nav.vendor),ios=safari&&(/Mobile\/\w+/.test(agent)||!!nav&&nav.maxTouchPoints>2),mac$2=ios||(nav?/Mac/.test(nav.platform):!1),windows$1=nav?/Win/.test(nav.platform):!1,android=/Android \d/.test(agent),webkit=!!doc&&`webkitFontSmoothing`in doc.documentElement.style,webkit_version=webkit?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function windowRect(e){let t=e.defaultView&&e.defaultView.visualViewport;return t?{left:0,right:t.width,top:0,bottom:t.height}:{left:0,right:e.documentElement.clientWidth,top:0,bottom:e.documentElement.clientHeight}}function getSide(e,t){return typeof e==`number`?e:e[t]}function clientRect(e){let t=e.getBoundingClientRect(),n=t.width/e.offsetWidth||1,r=t.height/e.offsetHeight||1;return{left:t.left,right:t.left+e.clientWidth*n,top:t.top,bottom:t.top+e.clientHeight*r}}function scrollRectIntoView(e,t,n){let r=e.someProp(`scrollThreshold`)||0,a=e.someProp(`scrollMargin`)||5,o=e.dom.ownerDocument;for(let s=n||e.dom;s;){if(s.nodeType!=1){s=parentNode(s);continue}let e=s,n=e==o.body,c=n?windowRect(o):clientRect(e),l=0,u=0;if(t.top<c.top+getSide(r,`top`)?u=-(c.top-t.top+getSide(a,`top`)):t.bottom>c.bottom-getSide(r,`bottom`)&&(u=t.bottom-t.top>c.bottom-c.top?t.top+getSide(a,`top`)-c.top:t.bottom-c.bottom+getSide(a,`bottom`)),t.left<c.left+getSide(r,`left`)?l=-(c.left-t.left+getSide(a,`left`)):t.right>c.right-getSide(r,`right`)&&(l=t.right-c.right+getSide(a,`right`)),l||u)if(n)o.defaultView.scrollBy(l,u);else{let n=e.scrollLeft,r=e.scrollTop;u&&(e.scrollTop+=u),l&&(e.scrollLeft+=l);let a=e.scrollLeft-n,o=e.scrollTop-r;t={left:t.left-a,top:t.top-o,right:t.right-a,bottom:t.bottom-o}}let d=n?`fixed`:getComputedStyle(s).position;if(/^(fixed|sticky)$/.test(d))break;s=d==`absolute`?s.offsetParent:parentNode(s)}}function storeScrollPos(e){let t=e.dom.getBoundingClientRect(),n=Math.max(0,t.top),r,a;for(let o=(t.left+t.right)/2,s=n+1;s<Math.min(innerHeight,t.bottom);s+=5){let t=e.root.elementFromPoint(o,s);if(!t||t==e.dom||!e.dom.contains(t))continue;let c=t.getBoundingClientRect();if(c.top>=n-20){r=t,a=c.top;break}}return{refDOM:r,refTop:a,stack:scrollStack(e.dom)}}function scrollStack(e){let t=[],n=e.ownerDocument;for(let r=e;r&&(t.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),e!=n);r=parentNode(r));return t}function resetScrollPos({refDOM:e,refTop:t,stack:n}){let r=e?e.getBoundingClientRect().top:0;restoreScrollStack(n,r==0?0:r-t)}function restoreScrollStack(e,t){for(let n=0;n<e.length;n++){let{dom:r,top:a,left:o}=e[n];r.scrollTop!=a+t&&(r.scrollTop=a+t),r.scrollLeft!=o&&(r.scrollLeft=o)}}var preventScrollSupported=null;function focusPreventScroll(e){if(e.setActive)return e.setActive();if(preventScrollSupported)return e.focus(preventScrollSupported);let t=scrollStack(e);e.focus(preventScrollSupported==null?{get preventScroll(){return preventScrollSupported={preventScroll:!0},!0}}:void 0),preventScrollSupported||(preventScrollSupported=!1,restoreScrollStack(t,0))}function findOffsetInNode(e,t){let n,r=2e8,a,o=0,s=t.top,c=t.top,l,u;for(let d=e.firstChild,f=0;d;d=d.nextSibling,f++){let e;if(d.nodeType==1)e=d.getClientRects();else if(d.nodeType==3)e=textRange(d).getClientRects();else continue;for(let p=0;p<e.length;p++){let m=e[p];if(m.top<=s&&m.bottom>=c){s=Math.max(m.bottom,s),c=Math.min(m.top,c);let e=m.left>t.left?m.left-t.left:m.right<t.left?t.left-m.right:0;if(e<r){n=d,r=e,a=e&&n.nodeType==3?{left:m.right<t.left?m.right:m.left,top:t.top}:t,d.nodeType==1&&e&&(o=f+ +(t.left>=(m.left+m.right)/2));continue}}else m.top>t.top&&!l&&m.left<=t.left&&m.right>=t.left&&(l=d,u={left:Math.max(m.left,Math.min(m.right,t.left)),top:m.top});!n&&(t.left>=m.right&&t.top>=m.top||t.left>=m.left&&t.top>=m.bottom)&&(o=f+1)}}return!n&&l&&(n=l,a=u,r=0),n&&n.nodeType==3?findOffsetInText(n,a):!n||r&&n.nodeType==1?{node:e,offset:o}:findOffsetInNode(n,a)}function findOffsetInText(e,t){let n=e.nodeValue.length,r=document.createRange();for(let a=0;a<n;a++){r.setEnd(e,a+1),r.setStart(e,a);let n=singleRect(r,1);if(n.top!=n.bottom&&inRect(t,n))return{node:e,offset:a+ +(t.left>=(n.left+n.right)/2)}}return{node:e,offset:0}}function inRect(e,t){return e.left>=t.left-1&&e.left<=t.right+1&&e.top>=t.top-1&&e.top<=t.bottom+1}function targetKludge(e,t){let n=e.parentNode;return n&&/^li$/i.test(n.nodeName)&&t.left<e.getBoundingClientRect().left?n:e}function posFromElement(e,t,n){let{node:r,offset:a}=findOffsetInNode(t,n),o=-1;if(r.nodeType==1&&!r.firstChild){let e=r.getBoundingClientRect();o=e.left!=e.right&&n.left>(e.left+e.right)/2?1:-1}return e.docView.posFromDOM(r,a,o)}function posFromCaret(e,t,n,r){let a=-1;for(let n=t,o=!1;n!=e.dom;){let t=e.docView.nearestDesc(n,!0),s;if(!t)return null;if(t.dom.nodeType==1&&(t.node.isBlock&&t.parent||!t.contentDOM)&&((s=t.dom.getBoundingClientRect()).width||s.height)&&(t.node.isBlock&&t.parent&&(!o&&s.left>r.left||s.top>r.top?a=t.posBefore:(!o&&s.right<r.left||s.bottom<r.top)&&(a=t.posAfter),o=!0),!t.contentDOM&&a<0&&!t.node.isText))return(t.node.isBlock?r.top<(s.top+s.bottom)/2:r.left<(s.left+s.right)/2)?t.posBefore:t.posAfter;n=t.dom.parentNode}return a>-1?a:e.docView.posFromDOM(t,n,-1)}function elementFromPoint(e,t,n){let r=e.childNodes.length;if(r&&n.top<n.bottom)for(let a=Math.max(0,Math.min(r-1,Math.floor(r*(t.top-n.top)/(n.bottom-n.top))-2)),o=a;;){let n=e.childNodes[o];if(n.nodeType==1){let e=n.getClientRects();for(let r=0;r<e.length;r++){let a=e[r];if(inRect(t,a))return elementFromPoint(n,t,a)}}if((o=(o+1)%r)==a)break}return e}function posAtCoords(e,t){let n=e.dom.ownerDocument,r,a=0,o=caretFromPoint(n,t.left,t.top);o&&({node:r,offset:a}=o);let s=(e.root.elementFromPoint?e.root:n).elementFromPoint(t.left,t.top),c;if(!s||!e.dom.contains(s.nodeType==1?s:s.parentNode)){let n=e.dom.getBoundingClientRect();if(!inRect(t,n)||(s=elementFromPoint(e.dom,t,n),!s))return null}if(safari)for(let e=s;r&&e;e=parentNode(e))e.draggable&&(r=void 0);if(s=targetKludge(s,t),r){if(gecko&&r.nodeType==1&&(a=Math.min(a,r.childNodes.length),a<r.childNodes.length)){let e=r.childNodes[a],n;e.nodeName==`IMG`&&(n=e.getBoundingClientRect()).right<=t.left&&n.bottom>t.top&&a++}let n;webkit&&a&&r.nodeType==1&&(n=r.childNodes[a-1]).nodeType==1&&n.contentEditable==`false`&&n.getBoundingClientRect().top>=t.top&&a--,r==e.dom&&a==r.childNodes.length-1&&r.lastChild.nodeType==1&&t.top>r.lastChild.getBoundingClientRect().bottom?c=e.state.doc.content.size:(a==0||r.nodeType!=1||r.childNodes[a-1].nodeName!=`BR`)&&(c=posFromCaret(e,r,a,t))}c??=posFromElement(e,s,t);let l=e.docView.nearestDesc(s,!0);return{pos:c,inside:l?l.posAtStart-l.border:-1}}function nonZero(e){return e.top<e.bottom||e.left<e.right}function singleRect(e,t){let n=e.getClientRects();if(n.length){let e=n[t<0?0:n.length-1];if(nonZero(e))return e}return Array.prototype.find.call(n,nonZero)||e.getBoundingClientRect()}var BIDI=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;function coordsAtPos(e,t,n){let{node:r,offset:a,atom:o}=e.docView.domFromPos(t,n<0?-1:1),s=webkit||gecko;if(r.nodeType==3)if(s&&(BIDI.test(r.nodeValue)||(n<0?!a:a==r.nodeValue.length))){let e=singleRect(textRange(r,a,a),n);if(gecko&&a&&/\s/.test(r.nodeValue[a-1])&&a<r.nodeValue.length){let t=singleRect(textRange(r,a-1,a-1),-1);if(t.top==e.top){let n=singleRect(textRange(r,a,a+1),-1);if(n.top!=e.top)return flattenV(n,n.left<t.left)}}return e}else{let e=a,t=a,o=n<0?1:-1;return n<0&&!a?(t++,o=-1):n>=0&&a==r.nodeValue.length?(e--,o=1):n<0?e--:t++,flattenV(singleRect(textRange(r,e,t),o),o<0)}if(!e.state.doc.resolve(t-(o||0)).parent.inlineContent){if(o==null&&a&&(n<0||a==nodeSize(r))){let e=r.childNodes[a-1];if(e.nodeType==1)return flattenH(e.getBoundingClientRect(),!1)}if(o==null&&a<nodeSize(r)){let e=r.childNodes[a];if(e.nodeType==1)return flattenH(e.getBoundingClientRect(),!0)}return flattenH(r.getBoundingClientRect(),n>=0)}if(o==null&&a&&(n<0||a==nodeSize(r))){let e=r.childNodes[a-1],t=e.nodeType==3?textRange(e,nodeSize(e)-+!s):e.nodeType==1&&(e.nodeName!=`BR`||!e.nextSibling)?e:null;if(t)return flattenV(singleRect(t,1),!1)}if(o==null&&a<nodeSize(r)){let e=r.childNodes[a];for(;e.pmViewDesc&&e.pmViewDesc.ignoreForCoords;)e=e.nextSibling;let t=e?e.nodeType==3?textRange(e,0,+!s):e.nodeType==1?e:null:null;if(t)return flattenV(singleRect(t,-1),!0)}return flattenV(singleRect(r.nodeType==3?textRange(r):r,-n),n>=0)}function flattenV(e,t){if(e.width==0)return e;let n=t?e.left:e.right;return{top:e.top,bottom:e.bottom,left:n,right:n}}function flattenH(e,t){if(e.height==0)return e;let n=t?e.top:e.bottom;return{top:n,bottom:n,left:e.left,right:e.right}}function withFlushedState(e,t,n){let r=e.state,a=e.root.activeElement;r!=t&&e.updateState(t),a!=e.dom&&e.focus();try{return n()}finally{r!=t&&e.updateState(r),a!=e.dom&&a&&a.focus()}}function endOfTextblockVertical(e,t,n){let r=t.selection,a=n==`up`?r.$from:r.$to;return withFlushedState(e,t,()=>{let{node:t}=e.docView.domFromPos(a.pos,n==`up`?-1:1);for(;;){let n=e.docView.nearestDesc(t,!0);if(!n)break;if(n.node.isBlock){t=n.contentDOM||n.dom;break}t=n.dom.parentNode}let r=coordsAtPos(e,a.pos,1);for(let e=t.firstChild;e;e=e.nextSibling){let t;if(e.nodeType==1)t=e.getClientRects();else if(e.nodeType==3)t=textRange(e,0,e.nodeValue.length).getClientRects();else continue;for(let e=0;e<t.length;e++){let a=t[e];if(a.bottom>a.top+1&&(n==`up`?r.top-a.top>(a.bottom-r.top)*2:a.bottom-r.bottom>(r.bottom-a.top)*2))return!1}}return!0})}var maybeRTL=/[\u0590-\u08ac]/;function endOfTextblockHorizontal(e,t,n){let{$head:r}=t.selection;if(!r.parent.isTextblock)return!1;let a=r.parentOffset,o=!a,s=a==r.parent.content.size,c=e.domSelection();return c?!maybeRTL.test(r.parent.textContent)||!c.modify?n==`left`||n==`backward`?o:s:withFlushedState(e,t,()=>{let{focusNode:t,focusOffset:a,anchorNode:o,anchorOffset:s}=e.domSelectionRange(),l=c.caretBidiLevel;c.modify(`move`,n,`character`);let u=r.depth?e.docView.domAfterPos(r.before()):e.dom,{focusNode:d,focusOffset:f}=e.domSelectionRange(),p=d&&!u.contains(d.nodeType==1?d:d.parentNode)||t==d&&a==f;try{c.collapse(o,s),t&&(t!=o||a!=s)&&c.extend&&c.extend(t,a)}catch{}return l!=null&&(c.caretBidiLevel=l),p}):r.pos==r.start()||r.pos==r.end()}var cachedState=null,cachedDir=null,cachedResult=!1;function endOfTextblock(e,t,n){return cachedState==t&&cachedDir==n?cachedResult:(cachedState=t,cachedDir=n,cachedResult=n==`up`||n==`down`?endOfTextblockVertical(e,t,n):endOfTextblockHorizontal(e,t,n))}var NOT_DIRTY=0,CHILD_DIRTY=1,CONTENT_DIRTY=2,NODE_DIRTY=3,ViewDesc=class{constructor(e,t,n,r){this.parent=e,this.children=t,this.dom=n,this.contentDOM=r,this.dirty=NOT_DIRTY,n.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,n){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;t<this.children.length;t++)e+=this.children[t].size;return e}get border(){return 0}destroy(){this.parent=void 0,this.dom.pmViewDesc==this&&(this.dom.pmViewDesc=void 0);for(let e=0;e<this.children.length;e++)this.children[e].destroy()}posBeforeChild(e){for(let t=0,n=this.posAtStart;;t++){let r=this.children[t];if(r==e)return n;n+=r.size}}get posBefore(){return this.parent.posBeforeChild(this)}get posAtStart(){return this.parent?this.parent.posBeforeChild(this)+this.border:0}get posAfter(){return this.posBefore+this.size}get posAtEnd(){return this.posAtStart+this.size-2*this.border}localPosFromDOM(e,t,n){if(this.contentDOM&&this.contentDOM.contains(e.nodeType==1?e:e.parentNode))if(n<0){let n,r;if(e==this.contentDOM)n=e.childNodes[t-1];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.previousSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.previousSibling;return n?this.posBeforeChild(r)+r.size:this.posAtStart}else{let n,r;if(e==this.contentDOM)n=e.childNodes[t];else{for(;e.parentNode!=this.contentDOM;)e=e.parentNode;n=e.nextSibling}for(;n&&!((r=n.pmViewDesc)&&r.parent==this);)n=n.nextSibling;return n?this.posBeforeChild(r):this.posAtEnd}let r;if(e==this.dom&&this.contentDOM)r=t>domIndex(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))r=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!1;break}if(t.previousSibling)break}if(r==null&&t==e.childNodes.length)for(let t=e;;t=t.parentNode){if(t==this.dom){r=!0;break}if(t.nextSibling)break}}return r??n>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let n=!0,r=e;r;r=r.parentNode){let a=this.getDesc(r),o;if(a&&(!t||a.node))if(n&&(o=a.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))n=!1;else return a}}getDesc(e){let t=e.pmViewDesc;for(let e=t;e;e=e.parent)if(e==this)return t}posFromDOM(e,t,n){for(let r=e;r;r=r.parentNode){let a=this.getDesc(r);if(a)return a.localPosFromDOM(e,t,n)}return-1}descAt(e){for(let t=0,n=0;t<this.children.length;t++){let r=this.children[t],a=n+r.size;if(n==e&&a!=n){for(;!r.border&&r.children.length;)for(let e=0;e<r.children.length;e++){let t=r.children[e];if(t.size){r=t;break}}return r}if(e<a)return r.descAt(e-n-r.border);n=a}}domFromPos(e,t){if(!this.contentDOM)return{node:this.dom,offset:0,atom:e+1};let n=0,r=0;for(let t=0;n<this.children.length;n++){let a=this.children[n],o=t+a.size;if(o>e||a instanceof TrailingHackViewDesc){r=e-t;break}t=o}if(r)return this.children[n].domFromPos(r-this.children[n].border,t);for(let e;n&&!(e=this.children[n-1]).size&&e instanceof WidgetViewDesc&&e.side>=0;n--);if(t<=0){let e,r=!0;for(;e=n?this.children[n-1]:null,!(!e||e.dom.parentNode==this.contentDOM);n--,r=!1);return e&&t&&r&&!e.border&&!e.domAtom?e.domFromPos(e.size,t):{node:this.contentDOM,offset:e?domIndex(e.dom)+1:0}}else{let e,r=!0;for(;e=n<this.children.length?this.children[n]:null,!(!e||e.dom.parentNode==this.contentDOM);n++,r=!1);return e&&r&&!e.border&&!e.domAtom?e.domFromPos(0,t):{node:this.contentDOM,offset:e?domIndex(e.dom):this.contentDOM.childNodes.length}}}parseRange(e,t,n=0){if(this.children.length==0)return{node:this.contentDOM,from:e,to:t,fromOffset:0,toOffset:this.contentDOM.childNodes.length};let r=-1,a=-1;for(let o=n,s=0;;s++){let n=this.children[s],c=o+n.size;if(r==-1&&e<=c){let a=o+n.border;if(e>=a&&t<=c-n.border&&n.node&&n.contentDOM&&this.contentDOM.contains(n.contentDOM))return n.parseRange(e,t,a);e=o;for(let t=s;t>0;t--){let n=this.children[t-1];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(1)){r=domIndex(n.dom)+1;break}e-=n.size}r==-1&&(r=0)}if(r>-1&&(c>t||s==this.children.length-1)){t=c;for(let e=s+1;e<this.children.length;e++){let n=this.children[e];if(n.size&&n.dom.parentNode==this.contentDOM&&!n.emptyChildAt(-1)){a=domIndex(n.dom);break}t+=n.size}a==-1&&(a=this.contentDOM.childNodes.length);break}o=c}return{node:this.contentDOM,from:e,to:t,fromOffset:r,toOffset:a}}emptyChildAt(e){if(this.border||!this.contentDOM||!this.children.length)return!1;let t=this.children[e<0?0:this.children.length-1];return t.size==0||t.emptyChildAt(e)}domAfterPos(e){let{node:t,offset:n}=this.domFromPos(e,0);if(t.nodeType!=1||n==t.childNodes.length)throw RangeError(`No node after pos `+e);return t.childNodes[n]}setSelection(e,t,n,r=!1){let a=Math.min(e,t),o=Math.max(e,t);for(let s=0,c=0;s<this.children.length;s++){let l=this.children[s],u=c+l.size;if(a>c&&o<u)return l.setSelection(e-c-l.border,t-c-l.border,n,r);c=u}let s=this.domFromPos(e,e?-1:1),c=t==e?s:this.domFromPos(t,t?-1:1),l=n.root.getSelection(),u=n.domSelectionRange(),d=!1;if((gecko||safari)&&e==t){let{node:e,offset:t}=s;if(e.nodeType==3){if(d=!!(t&&e.nodeValue[t-1]==`
6
6
  `),d&&t==e.nodeValue.length)for(let t=e,n;t;t=t.parentNode){if(n=t.nextSibling){n.nodeName==`BR`&&(s=c={node:n.parentNode,offset:domIndex(n)+1});break}let e=t.pmViewDesc;if(e&&e.node&&e.node.isBlock)break}}else{let n=e.childNodes[t-1];d=n&&(n.nodeName==`BR`||n.contentEditable==`false`)}}if(gecko&&u.focusNode&&u.focusNode!=c.node&&u.focusNode.nodeType==1){let e=u.focusNode.childNodes[u.focusOffset];e&&e.contentEditable==`false`&&(r=!0)}if(!(r||d&&safari)&&isEquivalentPosition(s.node,s.offset,u.anchorNode,u.anchorOffset)&&isEquivalentPosition(c.node,c.offset,u.focusNode,u.focusOffset))return;let f=!1;if((l.extend||e==t)&&!d){l.collapse(s.node,s.offset);try{e!=t&&l.extend(c.node,c.offset),f=!0}catch{}}if(!f){if(e>t){let e=s;s=c,c=e}let n=document.createRange();n.setEnd(c.node,c.offset),n.setStart(s.node,s.offset),l.removeAllRanges(),l.addRange(n)}}ignoreMutation(e){return!this.contentDOM&&e.type!=`selection`}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let n=0,r=0;r<this.children.length;r++){let a=this.children[r],o=n+a.size;if(n==o?e<=o&&t>=n:e<o&&t>n){let r=n+a.border,s=o-a.border;if(e>=r&&t<=s){this.dirty=e==n||t==o?CONTENT_DIRTY:CHILD_DIRTY,e==r&&t==s&&(a.contentLost||a.dom.parentNode!=this.contentDOM)?a.dirty=NODE_DIRTY:a.markDirty(e-r,t-r);return}else a.dirty=a.dom==a.contentDOM&&a.dom.parentNode==this.contentDOM&&!a.children.length?CONTENT_DIRTY:NODE_DIRTY}n=o}this.dirty=CONTENT_DIRTY}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let n=e==1?CONTENT_DIRTY:CHILD_DIRTY;t.dirty<n&&(t.dirty=n)}}get domAtom(){return!1}get ignoreForCoords(){return!1}get ignoreForSelection(){return!1}isText(e){return!1}},WidgetViewDesc=class extends ViewDesc{constructor(e,t,n,r){let a,o=t.type.toDOM;if(typeof o==`function`&&(o=o(n,()=>{if(!a)return r;if(a.parent)return a.parent.posBeforeChild(a)})),!t.type.spec.raw){if(o.nodeType!=1){let e=document.createElement(`span`);e.appendChild(o),o=e}o.contentEditable=`false`,o.classList.add(`ProseMirror-widget`)}super(e,[],o,null),this.widget=t,this.widget=t,a=this}matchesWidget(e){return this.dirty==NOT_DIRTY&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!=`selection`||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get ignoreForSelection(){return!!this.widget.type.spec.relaxedSide}get side(){return this.widget.type.side}},CompositionViewDesc=class extends ViewDesc{constructor(e,t,n,r){super(e,[],t,null),this.textDOM=n,this.text=r}get size(){return this.text.length}localPosFromDOM(e,t){return e==this.textDOM?this.posAtStart+t:this.posAtStart+(t?this.size:0)}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type===`characterData`&&e.target.nodeValue==e.oldValue}},MarkViewDesc=class e extends ViewDesc{constructor(e,t,n,r,a){super(e,[],n,r),this.mark=t,this.spec=a}static create(t,n,r,a){let o=a.nodeViews[n.type.name],s=o&&o(n,a,r);return(!s||!s.dom)&&(s=DOMSerializer.renderSpec(document,n.type.spec.toDOM(n,r),null,n.attrs)),new e(t,n,s.dom,s.contentDOM||s.dom,s)}parseRule(){return this.dirty&NODE_DIRTY||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=NODE_DIRTY&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=NOT_DIRTY){let e=this.parent;for(;!e.node;)e=e.parent;e.dirty<this.dirty&&(e.dirty=this.dirty),this.dirty=NOT_DIRTY}}slice(t,n,r){let a=e.create(this.parent,this.mark,!0,r),o=this.children,s=this.size;n<s&&(o=replaceNodes(o,n,s,r)),t>0&&(o=replaceNodes(o,0,t,r));for(let e=0;e<o.length;e++)o[e].parent=a;return a.children=o,a}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}},NodeViewDesc=class e extends ViewDesc{constructor(e,t,n,r,a,o,s,c,l){super(e,[],a,o),this.node=t,this.outerDeco=n,this.innerDeco=r,this.nodeDOM=s}static create(t,n,r,a,o,s){let c=o.nodeViews[n.type.name],l,u=c&&c(n,o,()=>{if(!l)return s;if(l.parent)return l.parent.posBeforeChild(l)},r,a),d=u&&u.dom,f=u&&u.contentDOM;if(n.isText){if(!d)d=document.createTextNode(n.text);else if(d.nodeType!=3)throw RangeError(`Text must be rendered as a DOM text node`)}else if(!d){let e=DOMSerializer.renderSpec(document,n.type.spec.toDOM(n),null,n.attrs);({dom:d,contentDOM:f}=e)}!f&&!n.isText&&d.nodeName!=`BR`&&(d.hasAttribute(`contenteditable`)||(d.contentEditable=`false`),n.type.spec.draggable&&(d.draggable=!0));let p=d;return d=applyOuterDeco(d,r,n),u?l=new CustomNodeViewDesc(t,n,r,a,d,f||null,p,u,o,s+1):n.isText?new TextViewDesc(t,n,r,a,d,p,o):new e(t,n,r,a,d,f||null,p,o,s+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace==`pre`&&(e.preserveWhitespace=`full`),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let n=this.children[t];if(this.dom.contains(n.dom.parentNode)){e.contentElement=n.dom.parentNode;break}}e.contentElement||(e.getContent=()=>Fragment.empty)}return e}matchesNode(e,t,n){return this.dirty==NOT_DIRTY&&e.eq(this.node)&&sameOuterDeco(t,this.outerDeco)&&n.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return+!this.node.isLeaf}updateChildren(e,t){let n=this.node.inlineContent,r=t,a=e.composing?this.localCompositionInfo(e,t):null,o=a&&a.pos>-1?a:null,s=a&&a.pos<0,c=new ViewTreeUpdater(this,o&&o.node,e);iterDeco(this.node,this.innerDeco,(t,a,o)=>{t.spec.marks?c.syncToMarks(t.spec.marks,n,e):t.type.side>=0&&!o&&c.syncToMarks(a==this.node.childCount?Mark$1.none:this.node.child(a).marks,n,e),c.placeWidget(t,e,r)},(t,o,l,u)=>{c.syncToMarks(t.marks,n,e);let d;c.findNodeMatch(t,o,l,u)||s&&e.state.selection.from>r&&e.state.selection.to<r+t.nodeSize&&(d=c.findIndexWithChild(a.node))>-1&&c.updateNodeAt(t,o,l,d,e)||c.updateNextNode(t,o,l,e,u,r)||c.addNode(t,o,l,e,r),r+=t.nodeSize}),c.syncToMarks([],n,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==CONTENT_DIRTY)&&(o&&this.protectLocalComposition(e,o),renderDescs(this.contentDOM,this.children,e),ios&&iosHacks(this.dom))}localCompositionInfo(e,t){let{from:n,to:r}=e.state.selection;if(!(e.state.selection instanceof TextSelection)||n<t||r>t+this.node.content.size)return null;let a=e.input.compositionNode;if(!a||!this.dom.contains(a.parentNode))return null;if(this.node.inlineContent){let e=a.nodeValue,o=findTextInFragment(this.node.content,e,n-t,r-t);return o<0?null:{node:a,pos:o,text:e}}else return{node:a,pos:-1,text:``}}protectLocalComposition(e,{node:t,pos:n,text:r}){if(this.getDesc(t))return;let a=t;for(;a.parentNode!=this.contentDOM;a=a.parentNode){for(;a.previousSibling;)a.parentNode.removeChild(a.previousSibling);for(;a.nextSibling;)a.parentNode.removeChild(a.nextSibling);a.pmViewDesc&&=void 0}let o=new CompositionViewDesc(this,a,t,r);e.input.compositionNodes.push(o),this.children=replaceNodes(this.children,n,n+r.length,e,o)}update(e,t,n,r){return this.dirty==NODE_DIRTY||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,n,r),!0)}updateInner(e,t,n,r){this.updateOuterDeco(t),this.node=e,this.innerDeco=n,this.contentDOM&&this.updateChildren(r,this.posAtStart),this.dirty=NOT_DIRTY}updateOuterDeco(e){if(sameOuterDeco(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,n=this.dom;this.dom=patchOuterDeco(this.dom,this.nodeDOM,computeOuterDeco(this.outerDeco,this.node,t),computeOuterDeco(e,this.node,t)),this.dom!=n&&(n.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&(this.nodeDOM.classList.remove(`ProseMirror-selectednode`),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute(`draggable`))}get domAtom(){return this.node.isAtom}};function docViewDesc(e,t,n,r,a){applyOuterDeco(r,t,e);let o=new NodeViewDesc(void 0,e,t,n,r,r,r,a,0);return o.contentDOM&&o.updateChildren(a,0),o}var TextViewDesc=class e extends NodeViewDesc{constructor(e,t,n,r,a,o,s){super(e,t,n,r,a,null,o,s,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,n,r){return this.dirty==NODE_DIRTY||this.dirty!=NOT_DIRTY&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=NOT_DIRTY||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,r.trackWrites==this.nodeDOM&&(r.trackWrites=null)),this.node=e,this.dirty=NOT_DIRTY,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,n){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,n)}ignoreMutation(e){return e.type!=`characterData`&&e.type!=`selection`}slice(t,n,r){let a=this.node.cut(t,n),o=document.createTextNode(a.text);return new e(this.parent,a,this.outerDeco,this.innerDeco,o,o,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=NODE_DIRTY)}get domAtom(){return!1}isText(e){return this.node.text==e}},TrailingHackViewDesc=class extends ViewDesc{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==NOT_DIRTY&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName==`IMG`}},CustomNodeViewDesc=class extends NodeViewDesc{constructor(e,t,n,r,a,o,s,c,l,u){super(e,t,n,r,a,o,s,l,u),this.spec=c}update(e,t,n,r){if(this.dirty==NODE_DIRTY)return!1;if(this.spec.update&&(this.node.type==e.type||this.spec.multiType)){let a=this.spec.update(e,t,n);return a&&this.updateInner(e,t,n,r),a}else if(!this.contentDOM&&!e.isLeaf)return!1;else return super.update(e,t,n,r)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,n,r){this.spec.setSelection?this.spec.setSelection(e,t,n.root):super.setSelection(e,t,n,r)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function renderDescs(e,t,n){let r=e.firstChild,a=!1;for(let o=0;o<t.length;o++){let s=t[o],c=s.dom;if(c.parentNode==e){for(;c!=r;)r=rm(r),a=!0;r=r.nextSibling}else a=!0,e.insertBefore(c,r);if(s instanceof MarkViewDesc){let t=r?r.previousSibling:e.lastChild;renderDescs(s.contentDOM,s.children,n),r=t?t.nextSibling:e.firstChild}}for(;r;)r=rm(r),a=!0;a&&n.trackWrites==e&&(n.trackWrites=null)}var OuterDecoLevel=function(e){e&&(this.nodeName=e)};OuterDecoLevel.prototype=Object.create(null);var noDeco=[new OuterDecoLevel];function computeOuterDeco(e,t,n){if(e.length==0)return noDeco;let r=n?noDeco[0]:new OuterDecoLevel,a=[r];for(let o=0;o<e.length;o++){let s=e[o].type.attrs;if(s){s.nodeName&&a.push(r=new OuterDecoLevel(s.nodeName));for(let e in s){let o=s[e];o!=null&&(n&&a.length==1&&a.push(r=new OuterDecoLevel(t.isInline?`span`:`div`)),e==`class`?r.class=(r.class?r.class+` `:``)+o:e==`style`?r.style=(r.style?r.style+`;`:``)+o:e!=`nodeName`&&(r[e]=o))}}}return a}function patchOuterDeco(e,t,n,r){if(n==noDeco&&r==noDeco)return t;let a=t;for(let t=0;t<r.length;t++){let o=r[t],s=n[t];if(t){let t;s&&s.nodeName==o.nodeName&&a!=e&&(t=a.parentNode)&&t.nodeName.toLowerCase()==o.nodeName?a=t:(t=document.createElement(o.nodeName),t.pmIsDeco=!0,t.appendChild(a),s=noDeco[0],a=t)}patchAttributes(a,s||noDeco[0],o)}return a}function patchAttributes(e,t,n){for(let r in t)r!=`class`&&r!=`style`&&r!=`nodeName`&&!(r in n)&&e.removeAttribute(r);for(let r in n)r!=`class`&&r!=`style`&&r!=`nodeName`&&n[r]!=t[r]&&e.setAttribute(r,n[r]);if(t.class!=n.class){let r=t.class?t.class.split(` `).filter(Boolean):[],a=n.class?n.class.split(` `).filter(Boolean):[];for(let t=0;t<r.length;t++)a.indexOf(r[t])==-1&&e.classList.remove(r[t]);for(let t=0;t<a.length;t++)r.indexOf(a[t])==-1&&e.classList.add(a[t]);e.classList.length==0&&e.removeAttribute(`class`)}if(t.style!=n.style){if(t.style){let n=/\s*([\w\-\xa1-\uffff]+)\s*:(?:"(?:\\.|[^"])*"|'(?:\\.|[^'])*'|\(.*?\)|[^;])*/g,r;for(;r=n.exec(t.style);)e.style.removeProperty(r[1])}n.style&&(e.style.cssText+=n.style)}}function applyOuterDeco(e,t,n){return patchOuterDeco(e,e,noDeco,computeOuterDeco(t,n,e.nodeType!=1))}function sameOuterDeco(e,t){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].type.eq(t[n].type))return!1;return!0}function rm(e){let t=e.nextSibling;return e.parentNode.removeChild(e),t}var ViewTreeUpdater=class{constructor(e,t,n){this.lock=t,this.view=n,this.index=0,this.stack=[],this.changed=!1,this.top=e,this.preMatch=preMatch(e.node.content,e)}destroyBetween(e,t){if(e!=t){for(let n=e;n<t;n++)this.top.children[n].destroy();this.top.children.splice(e,t-e),this.changed=!0}}destroyRest(){this.destroyBetween(this.index,this.top.children.length)}syncToMarks(e,t,n){let r=0,a=this.stack.length>>1,o=Math.min(a,e.length);for(;r<o&&(r==a-1?this.top:this.stack[r+1<<1]).matchesMark(e[r])&&e[r].type.spec.spanning!==!1;)r++;for(;r<a;)this.destroyRest(),this.top.dirty=NOT_DIRTY,this.index=this.stack.pop(),this.top=this.stack.pop(),a--;for(;a<e.length;){this.stack.push(this.top,this.index+1);let r=-1;for(let t=this.index;t<Math.min(this.index+3,this.top.children.length);t++){let n=this.top.children[t];if(n.matchesMark(e[a])&&!this.isLocked(n.dom)){r=t;break}}if(r>-1)r>this.index&&(this.changed=!0,this.destroyBetween(this.index,r)),this.top=this.top.children[this.index];else{let r=MarkViewDesc.create(this.top,e[a],t,n);this.top.children.splice(this.index,0,r),this.top=r,this.changed=!0}this.index=0,a++}}findNodeMatch(e,t,n,r){let a=-1,o;if(r>=this.preMatch.index&&(o=this.preMatch.matches[r-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,n))a=this.top.children.indexOf(o,this.index);else for(let r=this.index,o=Math.min(this.top.children.length,r+5);r<o;r++){let o=this.top.children[r];if(o.matchesNode(e,t,n)&&!this.preMatch.matched.has(o)){a=r;break}}return a<0?!1:(this.destroyBetween(this.index,a),this.index++,!0)}updateNodeAt(e,t,n,r,a){let o=this.top.children[r];return o.dirty==NODE_DIRTY&&o.dom==o.contentDOM&&(o.dirty=CONTENT_DIRTY),o.update(e,t,n,a)?(this.destroyBetween(this.index,r),this.index++,!0):!1}findIndexWithChild(e){for(;;){let t=e.parentNode;if(!t)return-1;if(t==this.top.contentDOM){let t=e.pmViewDesc;if(t){for(let e=this.index;e<this.top.children.length;e++)if(this.top.children[e]==t)return e}return-1}e=t}}updateNextNode(e,t,n,r,a,o){for(let s=this.index;s<this.top.children.length;s++){let c=this.top.children[s];if(c instanceof NodeViewDesc){let l=this.preMatch.matched.get(c);if(l!=null&&l!=a)return!1;let u=c.dom,d,f=this.isLocked(u)&&!(e.isText&&c.node&&c.node.isText&&c.nodeDOM.nodeValue==e.text&&c.dirty!=NODE_DIRTY&&sameOuterDeco(t,c.outerDeco));if(!f&&c.update(e,t,n,r))return this.destroyBetween(this.index,s),c.dom!=u&&(this.changed=!0),this.index++,!0;if(!f&&(d=this.recreateWrapper(c,e,t,n,r,o)))return this.destroyBetween(this.index,s),this.top.children[this.index]=d,d.contentDOM&&(d.dirty=CONTENT_DIRTY,d.updateChildren(r,o+1),d.dirty=NOT_DIRTY),this.changed=!0,this.index++,!0;break}}return!1}recreateWrapper(e,t,n,r,a,o){if(e.dirty||t.isAtom||!e.children.length||!e.node.content.eq(t.content)||!sameOuterDeco(n,e.outerDeco)||!r.eq(e.innerDeco))return null;let s=NodeViewDesc.create(this.top,t,n,r,a,o);if(s.contentDOM){s.children=e.children,e.children=[];for(let e of s.children)e.parent=s}return e.destroy(),s}addNode(e,t,n,r,a){let o=NodeViewDesc.create(this.top,e,t,n,r,a);o.contentDOM&&o.updateChildren(r,a+1),this.top.children.splice(this.index++,0,o),this.changed=!0}placeWidget(e,t,n){let r=this.index<this.top.children.length?this.top.children[this.index]:null;if(r&&r.matchesWidget(e)&&(e==r.widget||!r.widget.type.toDOM.parentNode))this.index++;else{let r=new WidgetViewDesc(this.top,e,t,n);this.top.children.splice(this.index++,0,r),this.changed=!0}}addTextblockHacks(){let e=this.top.children[this.index-1],t=this.top;for(;e instanceof MarkViewDesc;)t=e,e=t.children[t.children.length-1];(!e||!(e instanceof TextViewDesc)||/\n$/.test(e.node.text)||this.view.requiresGeckoHackNode&&/\s$/.test(e.node.text))&&((safari||chrome)&&e&&e.dom.contentEditable==`false`&&this.addHackNode(`IMG`,t),this.addHackNode(`BR`,this.top))}addHackNode(e,t){if(t==this.top&&this.index<t.children.length&&t.children[this.index].matchesHack(e))this.index++;else{let n=document.createElement(e);e==`IMG`&&(n.className=`ProseMirror-separator`,n.alt=``),e==`BR`&&(n.className=`ProseMirror-trailingBreak`);let r=new TrailingHackViewDesc(this.top,[],n,null);t==this.top?t.children.splice(this.index++,0,r):t.children.push(r),this.changed=!0}}isLocked(e){return this.lock&&(e==this.lock||e.nodeType==1&&e.contains(this.lock.parentNode))}};function preMatch(e,t){let n=t,r=n.children.length,a=e.childCount,o=new Map,s=[];outer:for(;a>0;){let c;for(;;)if(r){let e=n.children[r-1];if(e instanceof MarkViewDesc)n=e,r=e.children.length;else{c=e,r--;break}}else if(n==t)break outer;else r=n.parent.children.indexOf(n),n=n.parent;let l=c.node;if(l){if(l!=e.child(a-1))break;--a,o.set(c,a),s.push(c)}}return{index:a,matched:o,matches:s.reverse()}}function compareSide(e,t){return e.type.side-t.type.side}function iterDeco(e,t,n,r){let a=t.locals(e),o=0;if(a.length==0){for(let n=0;n<e.childCount;n++){let s=e.child(n);r(s,a,t.forChild(o,s),n),o+=s.nodeSize}return}let s=0,c=[],l=null;for(let u=0;;){let d,f;for(;s<a.length&&a[s].to==o;){let e=a[s++];e.widget&&(d?(f||=[d]).push(e):d=e)}if(d)if(f){f.sort(compareSide);for(let e=0;e<f.length;e++)n(f[e],u,!!l)}else n(d,u,!!l);let p,m;if(l)m=-1,p=l,l=null;else if(u<e.childCount)m=u,p=e.child(u++);else break;for(let e=0;e<c.length;e++)c[e].to<=o&&c.splice(e--,1);for(;s<a.length&&a[s].from<=o&&a[s].to>o;)c.push(a[s++]);let h=o+p.nodeSize;if(p.isText){let e=h;s<a.length&&a[s].from<e&&(e=a[s].from);for(let t=0;t<c.length;t++)c[t].to<e&&(e=c[t].to);e<h&&(l=p.cut(e-o),p=p.cut(0,e-o),h=e,m=-1)}else for(;s<a.length&&a[s].to<h;)s++;let g=p.isInline&&!p.isLeaf?c.filter(e=>!e.inline):c.slice();r(p,g,t.forChild(o,p),m),o=h}}function iosHacks(e){if(e.nodeName==`UL`||e.nodeName==`OL`){let t=e.style.cssText;e.style.cssText=t+`; list-style: square !important`,window.getComputedStyle(e).listStyle,e.style.cssText=t}}function findTextInFragment(e,t,n,r){for(let a=0,o=0;a<e.childCount&&o<=r;){let s=e.child(a++),c=o;if(o+=s.nodeSize,!s.isText)continue;let l=s.text;for(;a<e.childCount;){let t=e.child(a++);if(o+=t.nodeSize,!t.isText)break;l+=t.text}if(o>=n){if(o>=r&&l.slice(r-t.length-c,r-c)==t)return r-t.length;let e=c<r?l.lastIndexOf(t,r-c-1):-1;if(e>=0&&e+t.length+c>=n)return c+e;if(n==r&&l.length>=r+t.length-c&&l.slice(r-c,r-c+t.length)==t)return r}}return-1}function replaceNodes(e,t,n,r,a){let o=[];for(let s=0,c=0;s<e.length;s++){let l=e[s],u=c,d=c+=l.size;u>=n||d<=t?o.push(l):(u<t&&o.push(l.slice(0,t-u,r)),a&&=(o.push(a),void 0),d>n&&o.push(l.slice(n-u,l.size,r)))}return o}function selectionFromDOM(e,t=null){let n=e.domSelectionRange(),r=e.state.doc;if(!n.focusNode)return null;let a=e.docView.nearestDesc(n.focusNode),o=a&&a.size==0,s=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let c=r.resolve(s),l,u;if(selectionCollapsed(n)){for(l=s;a&&!a.node;)a=a.parent;let e=a.node;if(a&&e.isAtom&&NodeSelection.isSelectable(e)&&a.parent&&!(e.isInline&&isOnEdge(n.focusNode,n.focusOffset,a.dom))){let e=a.posBefore;u=new NodeSelection(s==e?c:r.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=s,a=s;for(let r=0;r<n.rangeCount;r++){let o=n.getRangeAt(r);t=Math.min(t,e.docView.posFromDOM(o.startContainer,o.startOffset,1)),a=Math.max(a,e.docView.posFromDOM(o.endContainer,o.endOffset,-1))}if(t<0)return null;[l,s]=a==e.state.selection.anchor?[a,t]:[t,a],c=r.resolve(s)}else l=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=r.resolve(l);if(!u){let n=t==`pointer`||e.state.selection.head<c.pos&&!o?1:-1;u=selectionBetween(e,d,c,n)}return u}function editorOwnsSelection(e){return e.editable?e.hasFocus():hasSelection(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function selectionToDOM(e,t=!1){let n=e.state.selection;if(syncNodeSelection(e,n),editorOwnsSelection(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&chrome){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&isEquivalentPosition(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset)){e.input.mouseDown.delayedSelectionSync=!0,e.domObserver.setCurSelection();return}}if(e.domObserver.disconnectSelection(),e.cursorWrapper)selectCursorWrapper(e);else{let{anchor:r,head:a}=n,o,s;brokenSelectBetweenUneditable&&!(n instanceof TextSelection)&&(n.$from.parent.inlineContent||(o=temporarilyEditableNear(e,n.from)),!n.empty&&!n.$from.parent.inlineContent&&(s=temporarilyEditableNear(e,n.to))),e.docView.setSelection(r,a,e,t),brokenSelectBetweenUneditable&&(o&&resetEditable(o),s&&resetEditable(s)),n.visible?e.dom.classList.remove(`ProseMirror-hideselection`):(e.dom.classList.add(`ProseMirror-hideselection`),`onselectionchange`in document&&removeClassOnSelectionChange(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}var brokenSelectBetweenUneditable=safari||chrome&&chrome_version<63;function temporarilyEditableNear(e,t){let{node:n,offset:r}=e.docView.domFromPos(t,0),a=r<n.childNodes.length?n.childNodes[r]:null,o=r?n.childNodes[r-1]:null;if(safari&&a&&a.contentEditable==`false`)return setEditable(a);if((!a||a.contentEditable==`false`)&&(!o||o.contentEditable==`false`)){if(a)return setEditable(a);if(o)return setEditable(o)}}function setEditable(e){return e.contentEditable=`true`,safari&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function resetEditable(e){e.contentEditable=`false`,e.wasDraggable&&=(e.draggable=!0,null)}function removeClassOnSelectionChange(e){let t=e.dom.ownerDocument;t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard);let n=e.domSelectionRange(),r=n.anchorNode,a=n.anchorOffset;t.addEventListener(`selectionchange`,e.input.hideSelectionGuard=()=>{(n.anchorNode!=r||n.anchorOffset!=a)&&(t.removeEventListener(`selectionchange`,e.input.hideSelectionGuard),setTimeout(()=>{(!editorOwnsSelection(e)||e.state.selection.visible)&&e.dom.classList.remove(`ProseMirror-hideselection`)},20))})}function selectCursorWrapper(e){let t=e.domSelection(),n=document.createRange();if(!t)return;let r=e.cursorWrapper.dom,a=r.nodeName==`IMG`;a?n.setStart(r.parentNode,domIndex(r)+1):n.setStart(r,0),n.collapse(!0),t.removeAllRanges(),t.addRange(n),!a&&!e.state.selection.visible&&ie$1&&ie_version<=11&&(r.disabled=!0,r.disabled=!1)}function syncNodeSelection(e,t){if(t instanceof NodeSelection){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(clearNodeSelection(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else clearNodeSelection(e)}function clearNodeSelection(e){e.lastSelectedViewDesc&&=(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),void 0)}function selectionBetween(e,t,n,r){return e.someProp(`createSelectionBetween`,r=>r(e,t,n))||TextSelection.between(t,n,r)}function hasFocusAndSelection(e){return e.editable&&!e.hasFocus()?!1:hasSelection(e)}function hasSelection(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(t.anchorNode.nodeType==3?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(t.focusNode.nodeType==3?t.focusNode.parentNode:t.focusNode))}catch{return!1}}function anchorInRightPlace(e){let t=e.docView.domFromPos(e.state.selection.anchor,0),n=e.domSelectionRange();return isEquivalentPosition(t.node,t.offset,n.anchorNode,n.anchorOffset)}function moveSelectionBlock(e,t){let{$anchor:n,$head:r}=e.selection,a=t>0?n.max(r):n.min(r),o=a.parent.inlineContent?a.depth?e.doc.resolve(t>0?a.after():a.before()):null:a;return o&&Selection.findFrom(o,t)}function apply(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function selectHorizontally(e,t,n){let r=e.state.selection;if(r instanceof TextSelection){if(n.indexOf(`s`)>-1){let{$head:n}=r,a=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!a||a.isText||!a.isLeaf)return!1;let o=e.state.doc.resolve(n.pos+a.nodeSize*(t<0?-1:1));return apply(e,new TextSelection(r.$anchor,o))}else if(!r.empty)return!1;else if(e.endOfTextblock(t>0?`forward`:`backward`)){let n=moveSelectionBlock(e.state,t);return n&&n instanceof NodeSelection?apply(e,n):!1}else if(!(mac$2&&n.indexOf(`m`)>-1)){let n=r.$head,a=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter,o;if(!a||a.isText)return!1;let s=t<0?n.pos-a.nodeSize:n.pos;return a.isAtom||(o=e.docView.descAt(s))&&!o.contentDOM?NodeSelection.isSelectable(a)?apply(e,new NodeSelection(t<0?e.state.doc.resolve(n.pos-a.nodeSize):n)):webkit?apply(e,new TextSelection(e.state.doc.resolve(t<0?s:s+a.nodeSize))):!1:!1}}else if(r instanceof NodeSelection&&r.node.isInline)return apply(e,new TextSelection(t>0?r.$to:r.$from));else{let n=moveSelectionBlock(e.state,t);return n?apply(e,n):!1}}function nodeLen(e){return e.nodeType==3?e.nodeValue.length:e.childNodes.length}function isIgnorable(e,t){let n=e.pmViewDesc;return n&&n.size==0&&(t<0||e.nextSibling||e.nodeName!=`BR`)}function skipIgnoredNodes(e,t){return t<0?skipIgnoredNodesBefore(e):skipIgnoredNodesAfter(e)}function skipIgnoredNodesBefore(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let a,o,s=!1;for(gecko&&n.nodeType==1&&r<nodeLen(n)&&isIgnorable(n.childNodes[r],-1)&&(s=!0);;)if(r>0){if(n.nodeType!=1)break;{let e=n.childNodes[r-1];if(isIgnorable(e,-1))a=n,o=--r;else if(e.nodeType==3)n=e,r=n.nodeValue.length;else break}}else if(isBlockNode(n))break;else{let t=n.previousSibling;for(;t&&isIgnorable(t,-1);)a=n.parentNode,o=domIndex(t),t=t.previousSibling;if(t)n=t,r=nodeLen(n);else{if(n=n.parentNode,n==e.dom)break;r=0}}s?setSelFocus(e,n,r):a&&setSelFocus(e,a,o)}function skipIgnoredNodesAfter(e){let t=e.domSelectionRange(),n=t.focusNode,r=t.focusOffset;if(!n)return;let a=nodeLen(n),o,s;for(;;)if(r<a){if(n.nodeType!=1)break;let e=n.childNodes[r];if(isIgnorable(e,1))o=n,s=++r;else break}else if(isBlockNode(n))break;else{let t=n.nextSibling;for(;t&&isIgnorable(t,1);)o=t.parentNode,s=domIndex(t)+1,t=t.nextSibling;if(t)n=t,r=0,a=nodeLen(n);else{if(n=n.parentNode,n==e.dom)break;r=a=0}}o&&setSelFocus(e,o,s)}function isBlockNode(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function textNodeAfter(e,t){for(;e&&t==e.childNodes.length&&!hasBlockDesc(e);)t=domIndex(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable==`false`)break;e=n,t=0}}function textNodeBefore(e,t){for(;e&&!t&&!hasBlockDesc(e);)t=domIndex(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(n.nodeType==3)return n;if(n.nodeType==1&&n.contentEditable==`false`)break;e=n,t=e.childNodes.length}}function setSelFocus(e,t,n){if(t.nodeType!=3){let e,r;(r=textNodeAfter(t,n))?(t=r,n=0):(e=textNodeBefore(t,n))&&(t=e,n=e.nodeValue.length)}let r=e.domSelection();if(!r)return;if(selectionCollapsed(r)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),r.removeAllRanges(),r.addRange(e)}else r.extend&&r.extend(t,n);e.domObserver.setCurSelection();let{state:a}=e;setTimeout(()=>{e.state==a&&selectionToDOM(e)},50)}function findDirection(e,t){let n=e.state.doc.resolve(t);if(!(chrome||windows$1)&&n.parent.inlineContent){let r=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),a=(n.top+n.bottom)/2;if(a>r.top&&a<r.bottom&&Math.abs(n.left-r.left)>1)return n.left<r.left?`ltr`:`rtl`}if(t<n.end()){let n=e.coordsAtPos(t+1),a=(n.top+n.bottom)/2;if(a>r.top&&a<r.bottom&&Math.abs(n.left-r.left)>1)return n.left>r.left?`ltr`:`rtl`}}return getComputedStyle(e.dom).direction==`rtl`?`rtl`:`ltr`}function selectVertically(e,t,n){let r=e.state.selection;if(r instanceof TextSelection&&!r.empty||n.indexOf(`s`)>-1||mac$2&&n.indexOf(`m`)>-1)return!1;let{$from:a,$to:o}=r;if(!a.parent.inlineContent||e.endOfTextblock(t<0?`up`:`down`)){let n=moveSelectionBlock(e.state,t);if(n&&n instanceof NodeSelection)return apply(e,n)}if(!a.parent.inlineContent){let n=t<0?a:o,s=r instanceof AllSelection?Selection.near(n,t):Selection.findFrom(n,t);return s?apply(e,s):!1}return!1}function stopNativeHorizontalDelete(e,t){if(!(e.state.selection instanceof TextSelection))return!0;let{$head:n,$anchor:r,empty:a}=e.state.selection;if(!n.sameParent(r))return!0;if(!a)return!1;if(e.endOfTextblock(t>0?`forward`:`backward`))return!0;let o=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(o&&!o.isText){let r=e.state.tr;return t<0?r.delete(n.pos-o.nodeSize,n.pos):r.delete(n.pos,n.pos+o.nodeSize),e.dispatch(r),!0}return!1}function switchEditable(e,t,n){e.domObserver.stop(),t.contentEditable=n,e.domObserver.start()}function safariDownArrowBug(e){if(!safari||e.state.selection.$head.parentOffset>0)return!1;let{focusNode:t,focusOffset:n}=e.domSelectionRange();if(t&&t.nodeType==1&&n==0&&t.firstChild&&t.firstChild.contentEditable==`false`){let n=t.firstChild;switchEditable(e,n,`true`),setTimeout(()=>switchEditable(e,n,`false`),20)}return!1}function getMods(e){let t=``;return e.ctrlKey&&(t+=`c`),e.metaKey&&(t+=`m`),e.altKey&&(t+=`a`),e.shiftKey&&(t+=`s`),t}function captureKeyDown(e,t){let n=t.keyCode,r=getMods(t);if(n==8||mac$2&&n==72&&r==`c`)return stopNativeHorizontalDelete(e,-1)||skipIgnoredNodes(e,-1);if(n==46&&!t.shiftKey||mac$2&&n==68&&r==`c`)return stopNativeHorizontalDelete(e,1)||skipIgnoredNodes(e,1);if(n==13||n==27)return!0;if(n==37||mac$2&&n==66&&r==`c`){let t=n==37?findDirection(e,e.state.selection.from)==`ltr`?-1:1:-1;return selectHorizontally(e,t,r)||skipIgnoredNodes(e,t)}else if(n==39||mac$2&&n==70&&r==`c`){let t=n==39?findDirection(e,e.state.selection.from)==`ltr`?1:-1:1;return selectHorizontally(e,t,r)||skipIgnoredNodes(e,t)}else if(n==38||mac$2&&n==80&&r==`c`)return selectVertically(e,-1,r)||skipIgnoredNodes(e,-1);else if(n==40||mac$2&&n==78&&r==`c`)return safariDownArrowBug(e)||selectVertically(e,1,r)||skipIgnoredNodes(e,1);else if(r==(mac$2?`m`:`c`)&&(n==66||n==73||n==89||n==90))return!0;return!1}function serializeForClipboard(e,t){e.someProp(`transformCopied`,n=>{t=n(t,e)});let n=[],{content:r,openStart:a,openEnd:o}=t;for(;a>1&&o>1&&r.childCount==1&&r.firstChild.childCount==1;){a--,o--;let e=r.firstChild;n.push(e.type.name,e.attrs==e.type.defaultAttrs?null:e.attrs),r=e.content}let s=e.someProp(`clipboardSerializer`)||DOMSerializer.fromSchema(e.state.schema),c=detachedDoc(),l=c.createElement(`div`);l.appendChild(s.serializeFragment(r,{document:c}));let u=l.firstChild,d,f=0;for(;u&&u.nodeType==1&&(d=wrapMap[u.nodeName.toLowerCase()]);){for(let e=d.length-1;e>=0;e--){let t=c.createElement(d[e]);for(;l.firstChild;)t.appendChild(l.firstChild);l.appendChild(t),f++}u=l.firstChild}return u&&u.nodeType==1&&u.setAttribute(`data-pm-slice`,`${a} ${o}${f?` -${f}`:``} ${JSON.stringify(n)}`),{dom:l,text:e.someProp(`clipboardTextSerializer`,n=>n(t,e))||t.content.textBetween(0,t.content.size,`
7
7