medium-proeditor
Version:
A powerful & customizable Medium-style rich text editor
1 lines • 494 kB
JavaScript
"use strict";function e(e){this.content=e}function t(e,n,i){for(let o=0;;o++){if(o==e.childCount||o==n.childCount)return e.childCount==n.childCount?null:i;let r=e.child(o),a=n.child(o);if(r!=a){if(!r.sameMarkup(a))return i;if(r.isText&&r.text!=a.text){for(let e=0;r.text[e]==a.text[e];e++)i++;return i}if(r.content.size||a.content.size){let e=t(r.content,a.content,i+1);if(null!=e)return e}i+=r.nodeSize}else i+=r.nodeSize}}function n(e,t,i,o){for(let r=e.childCount,a=t.childCount;;){if(0==r||0==a)return r==a?null:{a:i,b:o};let s=e.child(--r),l=t.child(--a),c=s.nodeSize;if(s!=l){if(!s.sameMarkup(l))return{a:i,b:o};if(s.isText&&s.text!=l.text){let e=0,t=Math.min(s.text.length,l.text.length);for(;e<t&&s.text[s.text.length-e-1]==l.text[l.text.length-e-1];)e++,i--,o--;return{a:i,b:o}}if(s.content.size||l.content.size){let e=n(s.content,l.content,i-1,o-1);if(e)return e}i-=c,o-=c}else i-=c,o-=c}}e.prototype={constructor:e,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-1==t?void 0:this.content[t+1]},update:function(t,n,i){var o=i&&i!=t?this.remove(i):this,r=o.find(t),a=o.content.slice();return-1==r?a.push(i||t,n):(a[r+1]=n,i&&(a[r]=i)),new e(a)},remove:function(t){var n=this.find(t);if(-1==n)return this;var i=this.content.slice();return i.splice(n,2),new e(i)},addToStart:function(t,n){return new e([t,n].concat(this.remove(t).content))},addToEnd:function(t,n){var i=this.remove(t).content.slice();return i.push(t,n),new e(i)},addBefore:function(t,n,i){var o=this.remove(n),r=o.content.slice(),a=o.find(t);return r.splice(-1==a?r.length:a,0,n,i),new e(r)},forEach:function(e){for(var t=0;t<this.content.length;t+=2)e(this.content[t],this.content[t+1])},prepend:function(t){return(t=e.from(t)).size?new e(t.content.concat(this.subtract(t).content)):this},append:function(t){return(t=e.from(t)).size?new e(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var n=this;t=e.from(t);for(var i=0;i<t.content.length;i+=2)n=n.remove(t.content[i]);return n},toObject:function(){var e={};return this.forEach((function(t,n){e[t]=n})),e},get size(){return this.content.length>>1}},e.from=function(t){if(t instanceof e)return t;var n=[];if(t)for(var i in t)n.push(i,t[i]);return new e(n)};class i{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,i=0,o){for(let r=0,a=0;a<t;r++){let s=this.content[r],l=a+s.nodeSize;if(l>e&&!1!==n(s,i+a,o||null,r)&&s.content.size){let o=a+1;s.nodesBetween(Math.max(0,e-o),Math.min(s.content.size,t-o),n,i+o)}a=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let o="",r=!0;return this.nodesBetween(e,t,((a,s)=>{let l=a.isText?a.text.slice(Math.max(e,s)-s,t-s):a.isLeaf?i?"function"==typeof i?i(a):i:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&l||a.isTextblock)&&n&&(r?r=!1:o+=n),o+=l}),0),o}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,o=this.content.slice(),r=0;for(t.isText&&t.sameMarkup(n)&&(o[o.length-1]=t.withText(t.text+n.text),r=1);r<e.content.length;r++)o.push(e.content[r]);return new i(o,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],o=0;if(t>e)for(let i=0,r=0;r<t;i++){let a=this.content[i],s=r+a.nodeSize;s>e&&((r<e||s>t)&&(a=a.isText?a.cut(Math.max(0,e-r),Math.min(a.text.length,t-r)):a.cut(Math.max(0,e-r-1),Math.min(a.content.size,t-r-1))),n.push(a),o+=a.nodeSize),r=s}return new i(n,o)}cutByIndex(e,t){return e==t?i.empty:0==e&&t==this.content.length?this:new i(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let o=this.content.slice(),r=this.size+t.nodeSize-n.nodeSize;return o[e]=t,new i(o,r)}addToStart(e){return new i([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new i(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let i=this.content[t];e(i,n,t),n+=i.nodeSize}}findDiffStart(e,n=0){return t(this,e,n)}findDiffEnd(e,t=this.size,i=e.size){return n(this,e,t,i)}findIndex(e,t=-1){if(0==e)return r(0,e);if(e==this.size)return r(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,i=0;;n++){let o=i+this.child(n).nodeSize;if(o>=e)return o==e||t>0?r(n+1,o):r(n,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((e=>e.toJSON())):null}static fromJSON(e,t){if(!t)return i.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new i(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return i.empty;let t,n=0;for(let i=0;i<e.length;i++){let o=e[i];n+=o.nodeSize,i&&o.isText&&e[i-1].sameMarkup(o)?(t||(t=e.slice(0,i)),t[t.length-1]=o.withText(t[t.length-1].text+o.text)):t&&t.push(o)}return new i(t||e,n)}static from(e){if(!e)return i.empty;if(e instanceof i)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new i([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}i.empty=new i([],0);const o={index:0,offset:0};function r(e,t){return o.index=e,o.offset=t,o}function a(e,t){if(e===t)return!0;if(!e||"object"!=typeof e||!t||"object"!=typeof t)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(!a(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!a(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class s{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let i=0;i<e.length;i++){let o=e[i];if(this.eq(o))return e;if(this.type.excludes(o.type))t||(t=e.slice(0,i));else{if(o.type.excludes(this.type))return e;!n&&o.type.rank>this.type.rank&&(t||(t=e.slice(0,i)),t.push(this),n=!0),t&&t.push(o)}}return t||(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&&a(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);let i=n.create(t.attrs);return n.checkAttrs(i.attrs),i}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(e){if(!e||Array.isArray(e)&&0==e.length)return s.none;if(e instanceof s)return[e];let t=e.slice();return t.sort(((e,t)=>e.type.rank-t.type.rank)),t}}s.none=[];class l extends Error{}class c{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=d(this.content,e+this.openStart,t);return n&&new c(n,this.openStart,this.openEnd)}removeBetween(e,t){return new c(m(this.content,e+this.openStart,t+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,t){if(!t)return c.empty;let n=t.openStart||0,o=t.openEnd||0;if("number"!=typeof n||"number"!=typeof o)throw new RangeError("Invalid input for Slice.fromJSON");return new c(i.fromJSON(e,t.content),n,o)}static maxOpen(e,t=!0){let n=0,i=0;for(let i=e.firstChild;i&&!i.isLeaf&&(t||!i.type.spec.isolating);i=i.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)i++;return new c(e,n,i)}}function m(e,t,n){let{index:i,offset:o}=e.findIndex(t),r=e.maybeChild(i),{index:a,offset:s}=e.findIndex(n);if(o==t||r.isText){if(s!=n&&!e.child(a).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(i!=a)throw new RangeError("Removing non-flat range");return e.replaceChild(i,r.copy(m(r.content,t-o-1,n-o-1)))}function d(e,t,n,i){let{index:o,offset:r}=e.findIndex(t),a=e.maybeChild(o);if(r==t||a.isText)return i&&!i.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let s=d(a.content,t-r-1,n);return s&&e.replaceChild(o,a.copy(s))}function u(e,t,n){if(n.openStart>e.depth)throw new l("Inserted content deeper than insertion position");if(e.depth-n.openStart!=t.depth-n.openEnd)throw new l("Inconsistent open depths");return h(e,t,n,0)}function h(e,t,n,o){let r=e.index(o),a=e.node(o);if(r==t.index(o)&&o<e.depth-n.openStart){let i=h(e,t,n,o+1);return a.copy(a.content.replaceChild(r,i))}if(n.content.size){if(n.openStart||n.openEnd||e.depth!=o||t.depth!=o){let{start:r,end:s}=function(e,t){let n=t.depth-e.openStart,o=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)o=t.node(e).copy(i.from(o));return{start:o.resolveNoCache(e.openStart+n),end:o.resolveNoCache(o.content.size-e.openEnd-n)}}(n,e);return y(a,w(e,r,s,t,o))}{let i=e.parent,o=i.content;return y(i,o.cut(0,e.parentOffset).append(n.content).append(o.cut(t.parentOffset)))}}return y(a,_(e,t,o))}function p(e,t){if(!t.type.compatibleContent(e.type))throw new l("Cannot join "+t.type.name+" onto "+e.type.name)}function f(e,t,n){let i=e.node(n);return p(i,t.node(n)),i}function g(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 b(e,t,n,i){let o=(t||e).node(n),r=0,a=t?t.index(n):o.childCount;e&&(r=e.index(n),e.depth>n?r++:e.textOffset&&(g(e.nodeAfter,i),r++));for(let e=r;e<a;e++)g(o.child(e),i);t&&t.depth==n&&t.textOffset&&g(t.nodeBefore,i)}function y(e,t){return e.type.checkContent(t),e.copy(t)}function w(e,t,n,o,r){let a=e.depth>r&&f(e,t,r+1),s=o.depth>r&&f(n,o,r+1),l=[];return b(null,e,r,l),a&&s&&t.index(r)==n.index(r)?(p(a,s),g(y(a,w(e,t,n,o,r+1)),l)):(a&&g(y(a,_(e,t,r+1)),l),b(t,n,r,l),s&&g(y(s,_(n,o,r+1)),l)),b(o,null,r,l),new i(l)}function _(e,t,n){let o=[];if(b(null,e,n,o),e.depth>n){g(y(f(e,t,n+1),_(e,t,n+1)),o)}return b(t,null,n,o),new i(o)}c.empty=new c(i.empty,0,0);class v{constructor(e,t,n){this.pos=e,this.path=t,this.parentOffset=n,this.depth=t.length/3-1}resolveDepth(e){return null==e?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[3*this.resolveDepth(e)]}index(e){return this.path[3*this.resolveDepth(e)+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e!=this.depth||this.textOffset?1:0)}start(e){return 0==(e=this.resolveDepth(e))?0:this.path[3*e-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(!(e=this.resolveDepth(e)))throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]}after(e){if(!(e=this.resolveDepth(e)))throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[3*e-1]+this.path[3*e].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],i=e.child(t);return n?e.child(t).cut(n):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):0==e?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let n=this.path[3*t],i=0==t?0:this.path[3*t-1]+1;for(let t=0;t<e;t++)i+=n.child(t).nodeSize;return i}marks(){let e=this.parent,t=this.index();if(0==e.content.size)return s.none;if(this.textOffset)return e.child(t).marks;let n=e.maybeChild(t-1),i=e.maybeChild(t);if(!n){let e=n;n=i,i=e}let o=n.marks;for(var r=0;r<o.length;r++)!1!==o[r].type.spec.inclusive||i&&o[r].isInSet(i.marks)||(o=o[r--].removeFromSet(o));return o}marksAcross(e){let t=this.parent.maybeChild(this.index());if(!t||!t.isInline)return null;let n=t.marks,i=e.parent.maybeChild(e.index());for(var o=0;o<n.length;o++)!1!==n[o].type.spec.inclusive||i&&n[o].isInSet(i.marks)||(n=n[o--].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 E(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(e,t){if(!(t>=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let n=[],i=0,o=t;for(let t=e;;){let{index:e,offset:r}=t.content.findIndex(o),a=o-r;if(n.push(t,e,i+r),!a)break;if(t=t.child(e),t.isText)break;o=a-1,i+=r+1}return new v(t,n,o)}static resolveCached(e,t){let n=x.get(e);if(n)for(let e=0;e<n.elts.length;e++){let i=n.elts[e];if(i.pos==t)return i}else x.set(e,n=new k);let i=n.elts[n.i]=v.resolve(e,t);return n.i=(n.i+1)%j,i}}class k{constructor(){this.elts=[],this.i=0}}const j=12,x=new WeakMap;class E{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)}}const N=Object.create(null);class S{constructor(e,t,n,o=s.none){this.type=e,this.attrs=t,this.marks=o,this.content=n||i.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,i=0){this.content.nodesBetween(e,t,n,i,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,t,n,i){return this.content.textBetween(e,t,n,i)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,t,n){return this.type==e&&a(this.attrs,t||e.defaultAttrs||N)&&s.sameSet(this.marks,n||s.none)}copy(e=null){return e==this.content?this:new S(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new S(this.type,this.attrs,this.content,e)}cut(e,t=this.content.size){return 0==e&&t==this.content.size?this:this.copy(this.content.cut(e,t))}slice(e,t=this.content.size,n=!1){if(e==t)return c.empty;let i=this.resolve(e),o=this.resolve(t),r=n?0:i.sharedDepth(t),a=i.start(r),s=i.node(r).content.cut(i.pos-a,o.pos-a);return new c(s,i.depth-r,o.depth-r)}replace(e,t,n){return u(this.resolve(e),this.resolve(t),n)}nodeAt(e){for(let t=this;;){let{index:n,offset:i}=t.content.findIndex(e);if(t=t.maybeChild(n),!t)return null;if(i==e||t.isText)return t;e-=i+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(0==e)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 i=this.content.child(t-1);return{node:i,index:t-1,offset:n-i.nodeSize}}resolve(e){return v.resolveCached(this,e)}resolveNoCache(e){return v.resolve(this,e)}rangeHasMark(e,t,n){let i=!1;return t>e&&this.nodesBetween(e,t,(e=>(n.isInSet(e.marks)&&(i=!0),!i))),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),C(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,n=i.empty,o=0,r=n.childCount){let a=this.contentMatchAt(e).matchFragment(n,o,r),s=a&&a.matchFragment(this.content,t);if(!s||!s.validEnd)return!1;for(let e=o;e<r;e++)if(!this.type.allowsMarks(n.child(e).marks))return!1;return!0}canReplaceWith(e,t,n,i){if(i&&!this.type.allowsMarks(i))return!1;let o=this.contentMatchAt(e).matchType(n),r=o&&o.matchFragment(this.content,t);return!!r&&r.validEnd}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=s.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(!s.sameSet(e,this.marks))throw new 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 new RangeError("Invalid input for Node.fromJSON");let n;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");n=t.marks.map(e.markFromJSON)}if("text"==t.type){if("string"!=typeof t.text)throw new RangeError("Invalid text node in JSON");return e.text(t.text,n)}let o=i.fromJSON(e,t.content),r=e.nodeType(t.type).create(t.attrs,o,n);return r.type.checkAttrs(r.attrs),r}}S.prototype.text=void 0;class M extends S{constructor(e,t,n,i){if(super(e,t,null,i),!n)throw new RangeError("Empty text nodes are not allowed");this.text=n}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):C(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new M(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new M(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return 0==e&&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 C(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class O{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new T(e,t);if(null==n.next)return O.empty;let i=A(n);n.next&&n.err("Unexpected trailing text");let o=function(e){let t=Object.create(null);return n(B(e,0));function n(i){let o=[];i.forEach((t=>{e[t].forEach((({term:t,to:n})=>{if(!t)return;let i;for(let e=0;e<o.length;e++)o[e][0]==t&&(i=o[e][1]);B(e,n).forEach((e=>{i||o.push([t,i=[]]),-1==i.indexOf(e)&&i.push(e)}))}))}));let r=t[i.join(",")]=new O(i.indexOf(e.length-1)>-1);for(let e=0;e<o.length;e++){let i=o[e][1].sort(z);r.next.push({type:o[e][0],next:t[i.join(",")]||n(i)})}return r}}(function(e){let t=[[]];return o(r(e,0),n()),t;function n(){return t.push([])-1}function i(e,n,i){let o={term:i,to:n};return t[e].push(o),o}function o(e,t){e.forEach((e=>e.to=t))}function r(e,t){if("choice"==e.type)return e.exprs.reduce(((e,n)=>e.concat(r(n,t))),[]);if("seq"!=e.type){if("star"==e.type){let a=n();return i(t,a),o(r(e.expr,a),a),[i(a)]}if("plus"==e.type){let a=n();return o(r(e.expr,t),a),o(r(e.expr,a),a),[i(a)]}if("opt"==e.type)return[i(t)].concat(r(e.expr,t));if("range"==e.type){let a=t;for(let t=0;t<e.min;t++){let t=n();o(r(e.expr,a),t),a=t}if(-1==e.max)o(r(e.expr,a),a);else for(let t=e.min;t<e.max;t++){let t=n();i(a,t),o(r(e.expr,a),t),a=t}return[i(a)]}if("name"==e.type)return[i(t,void 0,e.value)];throw new Error("Unknown expr type")}for(let i=0;;i++){let a=r(e.exprs[i],t);if(i==e.exprs.length-1)return a;o(a,t=n())}}}(i));return function(e,t){for(let n=0,i=[e];n<i.length;n++){let e=i[n],o=!e.validEnd,r=[];for(let t=0;t<e.next.length;t++){let{type:n,next:a}=e.next[t];r.push(n.name),!o||n.isText||n.hasRequiredAttrs()||(o=!1),-1==i.indexOf(a)&&i.push(a)}o&&t.err("Only non-generatable nodes ("+r.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}(o,n),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 i=this;for(let o=t;i&&o<n;o++)i=i.matchType(e.child(o).type);return i}get inlineContent(){return 0!=this.next.length&&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 o=[this];return function r(a,s){let l=a.matchFragment(e,n);if(l&&(!t||l.validEnd))return i.from(s.map((e=>e.createAndFill())));for(let e=0;e<a.next.length;e++){let{type:t,next:n}=a.next[e];if(!t.isText&&!t.hasRequiredAttrs()&&-1==o.indexOf(n)){o.push(n);let e=r(n,s.concat(t));if(e)return e}}return null}(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 i=n.shift(),o=i.match;if(o.matchType(e)){let e=[];for(let t=i;t.type;t=t.via)e.push(t.type);return e.reverse()}for(let e=0;e<o.next.length;e++){let{type:r,next:a}=o.next[e];r.isLeaf||r.hasRequiredAttrs()||r.name in t||i.type&&!a.validEnd||(n.push({match:r.contentMatch,type:r,via:i}),t[r.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];return function t(n){e.push(n);for(let i=0;i<n.next.length;i++)-1==e.indexOf(n.next[i].next)&&t(n.next[i].next)}(this),e.map(((t,n)=>{let i=n+(t.validEnd?"*":" ")+" ";for(let n=0;n<t.next.length;n++)i+=(n?", ":"")+t.next[n].type.name+"->"+e.indexOf(t.next[n].next);return i})).join("\n")}}O.empty=new O(!0);class T{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),""==this.tokens[this.tokens.length-1]&&this.tokens.pop(),""==this.tokens[0]&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}}function A(e){let t=[];do{t.push(D(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function D(e){let t=[];do{t.push(R(e))}while(e.next&&")"!=e.next&&"|"!=e.next);return 1==t.length?t[0]:{type:"seq",exprs:t}}function R(e){let t=function(e){if(e.eat("(")){let t=A(e);return e.eat(")")||e.err("Missing closing paren"),t}if(!/\W/.test(e.next)){let t=function(e,t){let n=e.nodeTypes,i=n[t];if(i)return[i];let o=[];for(let e in n){let i=n[e];i.isInGroup(t)&&o.push(i)}0==o.length&&e.err("No node type or group '"+t+"' found");return o}(e,e.next).map((t=>(null==e.inline?e.inline=t.isInline:e.inline!=t.isInline&&e.err("Mixing inline and block content"),{type:"name",value:t})));return e.pos++,1==t.length?t[0]:{type:"choice",exprs:t}}e.err("Unexpected token '"+e.next+"'")}(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("{"))break;t=L(e,t)}return t}function I(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function L(e,t){let n=I(e),i=n;return e.eat(",")&&(i="}"!=e.next?I(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:i,expr:t}}function z(e,t){return t-e}function B(e,t){let n=[];return function t(i){let o=e[i];if(1==o.length&&!o[0].term)return t(o[0].to);n.push(i);for(let e=0;e<o.length;e++){let{term:i,to:r}=o[e];i||-1!=n.indexOf(r)||t(r)}}(t),n.sort(z)}function P(e){let t=Object.create(null);for(let n in e){let i=e[n];if(!i.hasDefault)return null;t[n]=i.default}return t}function $(e,t){let n=Object.create(null);for(let i in e){let o=t&&t[i];if(void 0===o){let t=e[i];if(!t.hasDefault)throw new RangeError("No value supplied for attribute "+i);o=t.default}n[i]=o}return n}function F(e,t,n,i){for(let i in t)if(!(i in e))throw new RangeError(`Unsupported attribute ${i} for ${n} of type ${i}`);for(let n in e){let i=e[n];i.validate&&i.validate(t[n])}}function q(e,t){let n=Object.create(null);if(t)for(let i in t)n[i]=new U(e,i,t[i]);return n}class H{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=q(e,n.attrs),this.defaultAttrs=P(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(n.inline||"text"==e),this.isText="text"==e}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==O.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:$(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new S(this,this.computeAttrs(e),i.from(t),s.setFrom(n))}createChecked(e=null,t,n){return t=i.from(t),this.checkContent(t),new S(this,this.computeAttrs(e),t,s.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=i.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let o=this.contentMatch.matchFragment(t),r=o&&o.fillBefore(i.empty,!0);return r?new S(this,e,t.append(r),s.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 new RangeError(`Invalid content for node ${this.name}: ${e.toString().slice(0,50)}`)}checkAttrs(e){F(this.attrs,e,"node",this.name)}allowsMarkType(e){return null==this.markSet||this.markSet.indexOf(e)>-1}allowsMarks(e){if(null==this.markSet)return!0;for(let t=0;t<e.length;t++)if(!this.allowsMarkType(e[t].type))return!1;return!0}allowedMarks(e){if(null==this.markSet)return e;let t;for(let n=0;n<e.length;n++)this.allowsMarkType(e[n].type)?t&&t.push(e[n]):t||(t=e.slice(0,n));return t?t.length?t:s.none:e}static compile(e,t){let n=Object.create(null);e.forEach(((e,i)=>n[e]=new H(e,t,i)));let i=t.spec.topNode||"doc";if(!n[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!n.text)throw new RangeError("Every schema needs a 'text' type");for(let e in n.text.attrs)throw new RangeError("The text node type should not have attributes");return n}}class U{constructor(e,t,n){this.hasDefault=Object.prototype.hasOwnProperty.call(n,"default"),this.default=n.default,this.validate="string"==typeof n.validate?function(e,t,n){let i=n.split("|");return n=>{let o=null===n?"null":typeof n;if(i.indexOf(o)<0)throw new RangeError(`Expected value of type ${i} for attribute ${t} on type ${e}, got ${o}`)}}(e,t,n.validate):n.validate}get isRequired(){return!this.hasDefault}}class V{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=q(e,i.attrs),this.excluded=null;let o=P(this.attrs);this.instance=o?new s(this,o):null}create(e=null){return!e&&this.instance?this.instance:new s(this,$(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach(((e,o)=>n[e]=new V(e,i++,t,o))),n}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){F(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}function K(e,t){let n=[];for(let i=0;i<t.length;i++){let o=t[i],r=e.marks[o],a=r;if(r)n.push(r);else for(let t in e.marks){let i=e.marks[t];("_"==o||i.spec.group&&i.spec.group.split(" ").indexOf(o)>-1)&&n.push(a=i)}if(!a)throw new SyntaxError("Unknown mark type: '"+t[i]+"'")}return n}class W{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[];let n=this.matchedStyles=[];t.forEach((e=>{if(function(e){return null!=e.tag}(e))this.tags.push(e);else if(function(e){return null!=e.style}(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 Y(this,t,!1);return n.addAll(e,s.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new Y(this,t,!0);return n.addAll(e,s.none,t.from,t.to),c.maxOpen(n.finish())}matchTag(e,t,n){for(let i=n?this.tags.indexOf(n)+1:0;i<this.tags.length;i++){let n=this.tags[i];if(ee(e,n.tag)&&(void 0===n.namespace||e.namespaceURI==n.namespace)&&(!n.context||t.matchesContext(n.context))){if(n.getAttrs){let t=n.getAttrs(e);if(!1===t)continue;n.attrs=t||void 0}return n}}}matchStyle(e,t,n,i){for(let o=i?this.styles.indexOf(i)+1:0;o<this.styles.length;o++){let i=this.styles[o],r=i.style;if(!(0!=r.indexOf(e)||i.context&&!n.matchesContext(i.context)||r.length>e.length&&(61!=r.charCodeAt(e.length)||r.slice(e.length+1)!=t))){if(i.getAttrs){let e=i.getAttrs(t);if(!1===e)continue;i.attrs=e||void 0}return i}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,i=0;for(;i<t.length;i++){let e=t[i];if((null==e.priority?50:e.priority)<n)break}t.splice(i,0,e)}for(let t in e.marks){let i=e.marks[t].spec.parseDOM;i&&i.forEach((e=>{n(e=te(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)}))}for(let t in e.nodes){let i=e.nodes[t].spec.parseDOM;i&&i.forEach((e=>{n(e=te(e)),e.node||e.ignore||e.mark||(e.node=t)}))}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new W(e,W.schemaRules(e)))}}const G={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},J={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Z={ol:!0,ul:!0};function X(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class Q{constructor(e,t,n,i,o,r){this.type=e,this.attrs=t,this.marks=n,this.solid=i,this.options=r,this.content=[],this.activeMarks=s.none,this.match=o||(4&r?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(i.from(e));if(!t){let t,n=this.type.contentMatch;return(t=n.findWrapping(e.type))?(this.match=n,t):null}this.match=this.type.contentMatch.matchFragment(t)}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e,t=this.content[this.content.length-1];if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let n=t;t.text.length==e[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-e[0].length))}}let t=i.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(i.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&&!G.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Y{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let i,o=t.topNode,r=X(null,t.preserveWhitespace,0)|(n?4:0);i=o?new Q(o.type,o.attrs,s.none,!0,t.topMatch||o.type.contentMatch,r):new Q(n?null:e.schema.topNodeType,null,s.none,!0,null,r),this.nodes=[i],this.find=t.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e,t){3==e.nodeType?this.addTextNode(e,t):1==e.nodeType&&this.addElement(e,t)}addTextNode(e,t){let n=e.nodeValue,i=this.top,o=2&i.options?"full":this.localPreserveWS||(1&i.options)>0;if("full"===o||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(o)n="full"!==o?n.replace(/\r?\n|\r/g," "):n.replace(/\r\n?/g,"\n");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let t=i.content[i.content.length-1],o=e.previousSibling;(!t||o&&"BR"==o.nodeName||t.isText&&/[ \t\r\n\u000c]$/.test(t.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n),t),this.findInText(e)}else this.findInside(e)}addElement(e,t,n){let i=this.localPreserveWS,o=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let r,a=e.nodeName.toLowerCase();Z.hasOwnProperty(a)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&Z.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(r=this.parser.matchTag(e,this,n));e:if(s?s.ignore:J.hasOwnProperty(a))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let n,i=this.needsBlock;if(G.hasOwnProperty(a))o.content.length&&o.content[0].isInline&&this.open&&(this.open--,o=this.top),n=!0,o.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let r=s&&s.skip?t:this.readStyles(e,t);r&&this.addAll(e,r),n&&this.sync(o),this.needsBlock=i}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,s,n,!1===s.consuming?r:void 0)}this.localPreserveWS=i}leafFallback(e,t){"BR"==e.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode("\n"),t)}ignoreFallback(e,t){"BR"!=e.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),t)}readStyles(e,t){let n=e.style;if(n&&n.length)for(let e=0;e<this.parser.matchedStyles.length;e++){let i=this.parser.matchedStyles[e],o=n.getPropertyValue(i);if(o)for(let e;;){let n=this.parser.matchStyle(i,o,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)),!1!==n.consuming)break;e=n}}return t}addElementByRule(e,t,n,i){let o,r;if(t.node)if(r=this.parser.schema.nodes[t.node],r.isLeaf)this.insertNode(r.create(t.attrs),n)||this.leafFallback(e,n);else{let e=this.enter(r,t.attrs||null,n,t.preserveWhitespace);e&&(o=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let a=this.top;if(r&&r.isLeaf)this.findInside(e);else if(i)this.addElement(e,n,i);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach((e=>this.insertNode(e,n)));else{let i=e;"string"==typeof t.contentElement?i=e.querySelector(t.contentElement):"function"==typeof t.contentElement?i=t.contentElement(e):t.contentElement&&(i=t.contentElement),this.findAround(e,i,!0),this.addAll(i,n),this.findAround(e,i,!1)}o&&this.sync(a)&&this.open--}addAll(e,t,n,i){let o=n||0;for(let r=n?e.childNodes[n]:e.firstChild,a=null==i?null:e.childNodes[i];r!=a;r=r.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(r,t);this.findAtPoint(e,o)}findPlace(e,t){let n,i;for(let t=this.open;t>=0;t--){let o=this.nodes[t],r=o.findWrapping(e);if(r&&(!n||n.length>r.length)&&(n=r,i=o,!r.length))break;if(o.solid)break}if(!n)return null;this.sync(i);for(let e=0;e<n.length;e++)t=this.enterInner(n[e],null,t,!1);return t}insertNode(e,t){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let n=this.findPlace(e,t);if(n){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let i=s.none;for(let o of n.concat(e.marks))(t.type?t.type.allowsMarkType(o.type):ne(o.type,e.type))&&(i=o.addToSet(i));return t.content.push(e.mark(i)),!0}return!1}enter(e,t,n,i){let o=this.findPlace(e.create(t),n);return o&&(o=this.enterInner(e,t,n,!0,i)),o}enterInner(e,t,n,i=!1,o){this.closeExtra();let r=this.top;r.match=r.match&&r.match.matchType(e);let a=X(e,o,r.options);4&r.options&&0==r.content.length&&(a|=4);let l=s.none;return n=n.filter((t=>!(r.type?r.type.allowsMarkType(t.type):ne(t.type,e))||(l=t.addToSet(l),!1))),this.nodes.push(new Q(e,t,l,i,null,a)),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;this.localPreserveWS&&(this.nodes[t].options|=1)}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++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let i=0;i<this.find.length;i++)if(null==this.find[i].pos&&1==e.nodeType&&e.contains(this.find[i].node)){t.compareDocumentPosition(this.find[i].node)&(n?2:4)&&(this.find[i].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,i=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),o=-(n?n.depth+1:0)+(i?0:1),r=(e,a)=>{for(;e>=0;e--){let s=t[e];if(""==s){if(e==t.length-1||0==e)continue;for(;a>=o;a--)if(r(e-1,a))return!0;return!1}{let e=a>0||0==a&&i?this.nodes[a].type:n&&a>=o?n.node(a-o).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;a--}}return!0};return r(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 ee(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function te(e){let t={};for(let n in e)t[n]=e[n];return t}function ne(e,t){let n=t.schema.nodes;for(let i in n){let o=n[i];if(!o.allowsMarkType(e))continue;let r=[],a=e=>{r.push(e);for(let n=0;n<e.edgeCount;n++){let{type:i,next:o}=e.edge(n);if(i==t)return!0;if(r.indexOf(o)<0&&a(o))return!0}};if(a(o.contentMatch))return!0}}class ie{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=re(t).createDocumentFragment());let i=n,o=[];return e.forEach((e=>{if(o.length||e.marks.length){let n=0,r=0;for(;n<o.length&&r<e.marks.length;){let t=e.marks[r];if(this.marks[t.type.name]){if(!t.eq(o[n][0])||!1===t.type.spec.spanning)break;n++,r++}else r++}for(;n<o.length;)i=o.pop()[1];for(;r<e.marks.length;){let n=e.marks[r++],a=this.serializeMark(n,e.isInline,t);a&&(o.push([n,i]),i.appendChild(a.dom),i=a.contentDOM||a.dom)}}i.appendChild(this.serializeNodeInner(e,t))})),n}serializeNodeInner(e,t){let{dom:n,contentDOM:i}=le(re(t),this.nodes[e.type.name](e),null,e.attrs);if(i){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,i)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let i=e.marks.length-1;i>=0;i--){let o=this.serializeMark(e.marks[i],e.isInline,t);o&&((o.contentDOM||o.dom).appendChild(n),n=o.dom)}return n}serializeMark(e,t,n={}){let i=this.marks[e.type.name];return i&&le(re(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return le(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new ie(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=oe(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return oe(e.marks)}}function oe(e){let t={};for(let n in e){let i=e[n].spec.toDOM;i&&(t[n]=i)}return t}function re(e){return e.document||window.document}const ae=new WeakMap;function se(e){let t=ae.get(e);return void 0===t&&ae.set(e,t=function(e){let t=null;function n(e){if(e&&"object"==typeof e)if(Array.isArray(e))if("string"==typeof e[0])t||(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}(e)),t}function le(e,t,n,i){if("string"==typeof t)return{dom:e.createTextNode(t)};if(null!=t.nodeType)return{dom:t};if(t.dom&&null!=t.dom.nodeType)return t;let o,r=t[0];if("string"!=typeof r)throw new RangeError("Invalid array passed to renderSpec");if(i&&(o=se(i))&&o.indexOf(t)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let a,s=r.indexOf(" ");s>0&&(n=r.slice(0,s),r=r.slice(s+1));let l=n?e.createElementNS(n,r):e.createElement(r),c=t[1],m=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){m=2;for(let e in c)if(null!=c[e]){let t=e.indexOf(" ");t>0?l.setAttributeNS(e.slice(0,t),e.slice(t+1),c[e]):l.setAttribute(e,c[e])}}for(let o=m;o<t.length;o++){let r=t[o];if(0===r){if(o<t.length-1||o>m)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:t,contentDOM:o}=le(e,r,n,i);if(l.appendChild(t),o){if(a)throw new RangeError("Multiple content holes");a=o}}}return{dom:l,contentDOM:a}}const ce=Math.pow(2,16);function me(e,t){return e+t*ce}function de(e){return 65535&e}class ue{constructor(e,t,n){this.pos=e,this.delInfo=t,this.recover=n}get deleted(){return(8&this.delInfo)>0}get deletedBefore(){return(5&this.delInfo)>0}get deletedAfter(){return(6&this.delInfo)>0}get deletedAcross(){return(4&this.delInfo)>0}}class he{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&he.empty)return he.empty}recover(e){let t=0,n=de(e);if(!this.inverted)for(let e=0;e<n;e++)t+=this.ranges[3*e+2]-this.ranges[3*e+1];return this.ranges[3*n]+t+function(e){return(e-(65535&e))/ce}(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 i=0,o=this.inverted?2:1,r=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let s=this.ranges[a]-(this.inverted?i:0);if(s>e)break;let l=this.ranges[a+o],c=this.ranges[a+r],m=s+l;if(e<=m){let o=s+i+((l?e==s?-1:e==m?1:t:t)<0?0:c);if(n)return o;let r=e==(t<0?s:m)?null:me(a/3,e-s),d=e==s?2:e==m?1:4;return(t<0?e!=s:e!=m)&&(d|=8),new ue(o,d,r)}i+=c-l}return n?e+i:new ue(e+i,0,null)}touches(e,t){let n=0,i=de(t),o=this.inverted?2:1,r=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let a=this.ranges[t]-(this.inverted?n:0);if(a>e)break;let s=this.ranges[t+o];if(e<=a+s&&t==3*i)return!0;n+=this.ranges[t+r]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let i=0,o=0;i<this.ranges.length;i+=3){let r=this.ranges[i],a=r-(this.inverted?o:0),s=r+(this.inverted?0:o),l=this.ranges[i+t],c=this.ranges[i+n];e(a,a+l,s,s+c),o+=c-l}}invert(){return new he(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?he.empty:new he(e<0?[0,-e,0]:[0,0,e])}}he.empty=new he([]);class pe{constructor(e,t,n=0,i=(e?e.length:0)){this.mirror=t,this.from=n,this.to=i,this._maps=e||[],this.ownData=!(e||t)}get maps(){return this._maps}slice(e=0,t=this.maps.length){return new pe(this._maps,this.mirror,e,t)}appendMap(e,t){this.ownData||(this._maps=this._maps.slice(),this.mirror=this.mirror&&this.mirror.slice(),this.ownData=!0),this.to=this._maps.push(e),null!=t&&this.setMirror(this._maps.length-1,t)}appendMapping(e){for(let t=0,n=this._maps.length;t<e._maps.length;t++){let i=e.getMirror(t);this.appendMap(e._maps[t],null!=i&&i<t?n+i:void 0)}}getMirror(e){if(this.mirror)for(let t=0;t<this.mirror.length;t++)if(this.mirror[t]==e)return this.mirror[t+(t%2?-1:1)]}setMirror(e,t){this.mirror||(this.mirror=[]),this.mirror.push(e,t)}appendMappingInverted(e){for(let t=e.maps.length-1,n=this._maps.length+e._maps.length;t>=0;t--){let i=e.getMirror(t);this.appendMap(e._maps[t].invert(),null!=i&&i>t?n-i-1:void 0)}}invert(){let e=new pe;return e.appendMappingInverted(this),e}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 i=0;for(let n=this.from;n<this.to;n++){let o=this._maps[n].mapResult(e,t);if(null!=o.recover){let t=this.getMirror(n);if(null!=t&&t>n&&t<this.to){n=t,e=this._maps[t].recover(o.recover);continue}}i|=o.delInfo,e=o.pos}return n?e:new ue(e,i,null)}}const fe=Object.create(null);class ge{getMap(){return he.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=fe[t.stepType];if(!n)throw new RangeError(`No step type ${t.stepType} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in fe)throw new RangeError("Duplicate use of step JSON ID "+e);return fe[e]=t,t.prototype.jsonID=e,t}}class be{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new be(e,null)}static fail(e){return new be(null,e)}static fromReplace(e,t,n,i){try{return be.ok(e.replace(t,n,i))}catch(e){if(e instanceof l)return be.fail(e.message);throw e}}}function ye(e,t,n){let o=[];for(let i=0;i<e.childCount;i++){let r=e.child(i);r.content.size&&(r=r.copy(ye(r.content,t,r))),r.isInline&&(r=t(r,n,i)),o.push(r)}return i.fromArray(o)}class we extends ge{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),i=n.node(n.sharedDepth(this.to)),o=new c(ye(t.content,((e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e),i),t.openStart,t.openEnd);return be.fromReplace(e,this.from,this.to,o)}invert(){return new _e(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new we(t.pos,n.pos,this.mark)}merge(e){return e instanceof we&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new we(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new we(t.from,t.to,e.markFromJSON(t.mark))}}ge.jsonID("addMark",we);class _e extends ge{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 c(ye(t.content,(e=>e.mark(this.mark.removeFromSet(e.marks))),e),t.openStart,t.openEnd);return be.fromReplace(e,this.from,this.to,n)}invert(){return new we(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new _e(t.pos,n.pos,this.mark)}merge(e){return e instanceof _e&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new _e(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new _e(t.from,t.to,e.markFromJSON(t.mark))}}ge.jsonID("removeMark",_e);class ve extends ge{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return be.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return be.fromReplace(e,this.pos,this.pos+1,new c(i.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new ve(this.pos,t.marks[n]);return new ve(this.pos,this.mark)}}return new ke(this.pos,this.mark)}map(e){let t=e