UNPKG

medium-proeditor

Version:

A powerful & customizable Medium-style rich text editor

1 lines 610 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).Editor={})}(this,(function(e){"use strict";function t(e){this.content=e}function n(e,t,i){for(let o=0;;o++){if(o==e.childCount||o==t.childCount)return e.childCount==t.childCount?null:i;let r=e.child(o),s=t.child(o);if(r!=s){if(!r.sameMarkup(s))return i;if(r.isText&&r.text!=s.text){for(let e=0;r.text[e]==s.text[e];e++)i++;return i}if(r.content.size||s.content.size){let e=n(r.content,s.content,i+1);if(null!=e)return e}i+=r.nodeSize}else i+=r.nodeSize}}function i(e,t,n,o){for(let r=e.childCount,s=t.childCount;;){if(0==r||0==s)return r==s?null:{a:n,b:o};let a=e.child(--r),l=t.child(--s),c=a.nodeSize;if(a!=l){if(!a.sameMarkup(l))return{a:n,b:o};if(a.isText&&a.text!=l.text){let e=0,t=Math.min(a.text.length,l.text.length);for(;e<t&&a.text[a.text.length-e-1]==l.text[l.text.length-e-1];)e++,n--,o--;return{a:n,b:o}}if(a.content.size||l.content.size){let e=i(a.content,l.content,n-1,o-1);if(e)return e}n-=c,o-=c}else n-=c,o-=c}}t.prototype={constructor:t,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(e,n,i){var o=i&&i!=e?this.remove(i):this,r=o.find(e),s=o.content.slice();return-1==r?s.push(i||e,n):(s[r+1]=n,i&&(s[r]=i)),new t(s)},remove:function(e){var n=this.find(e);if(-1==n)return this;var i=this.content.slice();return i.splice(n,2),new t(i)},addToStart:function(e,n){return new t([e,n].concat(this.remove(e).content))},addToEnd:function(e,n){var i=this.remove(e).content.slice();return i.push(e,n),new t(i)},addBefore:function(e,n,i){var o=this.remove(n),r=o.content.slice(),s=o.find(e);return r.splice(-1==s?r.length:s,0,n,i),new t(r)},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=t.from(e)).size?new t(e.content.concat(this.subtract(e).content)):this},append:function(e){return(e=t.from(e)).size?new t(this.subtract(e).content.concat(e.content)):this},subtract:function(e){var n=this;e=t.from(e);for(var i=0;i<e.content.length;i+=2)n=n.remove(e.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}},t.from=function(e){if(e instanceof t)return e;var n=[];if(e)for(var i in e)n.push(i,e[i]);return new t(n)};class o{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,s=0;s<t;r++){let a=this.content[r],l=s+a.nodeSize;if(l>e&&!1!==n(a,i+s,o||null,r)&&a.content.size){let o=s+1;a.nodesBetween(Math.max(0,e-o),Math.min(a.content.size,t-o),n,i+o)}s=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let o="",r=!0;return this.nodesBetween(e,t,((s,a)=>{let l=s.isText?s.text.slice(Math.max(e,a)-a,t-a):s.isLeaf?i?"function"==typeof i?i(s):i:s.type.spec.leafText?s.type.spec.leafText(s):"":"";s.isBlock&&(s.isLeaf&&l||s.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,i=this.content.slice(),r=0;for(t.isText&&t.sameMarkup(n)&&(i[i.length-1]=t.withText(t.text+n.text),r=1);r<e.content.length;r++)i.push(e.content[r]);return new o(i,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],i=0;if(t>e)for(let o=0,r=0;r<t;o++){let s=this.content[o],a=r+s.nodeSize;a>e&&((r<e||a>t)&&(s=s.isText?s.cut(Math.max(0,e-r),Math.min(s.text.length,t-r)):s.cut(Math.max(0,e-r-1),Math.min(s.content.size,t-r-1))),n.push(s),i+=s.nodeSize),r=a}return new o(n,i)}cutByIndex(e,t){return e==t?o.empty:0==e&&t==this.content.length?this:new o(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let i=this.content.slice(),r=this.size+t.nodeSize-n.nodeSize;return i[e]=t,new o(i,r)}addToStart(e){return new o([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new o(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,t=0){return n(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return i(this,e,t,n)}findIndex(e,t=-1){if(0==e)return s(0,e);if(e==this.size)return s(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?s(n+1,o):s(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 o.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new o(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return o.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 o(t||e,n)}static from(e){if(!e)return o.empty;if(e instanceof o)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new o([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}o.empty=new o([],0);const r={index:0,offset:0};function s(e,t){return r.index=e,r.offset=t,r}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 l{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 l.none;if(e instanceof l)return[e];let t=e.slice();return t.sort(((e,t)=>e.type.rank-t.type.rank)),t}}l.none=[];class c extends Error{}class d{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=u(this.content,e+this.openStart,t);return n&&new d(n,this.openStart,this.openEnd)}removeBetween(e,t){return new d(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 d.empty;let n=t.openStart||0,i=t.openEnd||0;if("number"!=typeof n||"number"!=typeof i)throw new RangeError("Invalid input for Slice.fromJSON");return new d(o.fromJSON(e,t.content),n,i)}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 d(e,n,i)}}function m(e,t,n){let{index:i,offset:o}=e.findIndex(t),r=e.maybeChild(i),{index:s,offset:a}=e.findIndex(n);if(o==t||r.isText){if(a!=n&&!e.child(s).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(i!=s)throw new RangeError("Removing non-flat range");return e.replaceChild(i,r.copy(m(r.content,t-o-1,n-o-1)))}function u(e,t,n,i){let{index:o,offset:r}=e.findIndex(t),s=e.maybeChild(o);if(r==t||s.isText)return i&&!i.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let a=u(s.content,t-r-1,n);return a&&e.replaceChild(o,s.copy(a))}function h(e,t,n){if(n.openStart>e.depth)throw new c("Inserted content deeper than insertion position");if(e.depth-n.openStart!=t.depth-n.openEnd)throw new c("Inconsistent open depths");return p(e,t,n,0)}function p(e,t,n,i){let r=e.index(i),s=e.node(i);if(r==t.index(i)&&i<e.depth-n.openStart){let o=p(e,t,n,i+1);return s.copy(s.content.replaceChild(r,o))}if(n.content.size){if(n.openStart||n.openEnd||e.depth!=i||t.depth!=i){let{start:r,end:a}=function(e,t){let n=t.depth-e.openStart,i=t.node(n).copy(e.content);for(let e=n-1;e>=0;e--)i=t.node(e).copy(o.from(i));return{start:i.resolveNoCache(e.openStart+n),end:i.resolveNoCache(i.content.size-e.openEnd-n)}}(n,e);return w(s,v(e,r,a,t,i))}{let i=e.parent,o=i.content;return w(i,o.cut(0,e.parentOffset).append(n.content).append(o.cut(t.parentOffset)))}}return w(s,_(e,t,i))}function f(e,t){if(!t.type.compatibleContent(e.type))throw new c("Cannot join "+t.type.name+" onto "+e.type.name)}function g(e,t,n){let i=e.node(n);return f(i,t.node(n)),i}function b(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 y(e,t,n,i){let o=(t||e).node(n),r=0,s=t?t.index(n):o.childCount;e&&(r=e.index(n),e.depth>n?r++:e.textOffset&&(b(e.nodeAfter,i),r++));for(let e=r;e<s;e++)b(o.child(e),i);t&&t.depth==n&&t.textOffset&&b(t.nodeBefore,i)}function w(e,t){return e.type.checkContent(t),e.copy(t)}function v(e,t,n,i,r){let s=e.depth>r&&g(e,t,r+1),a=i.depth>r&&g(n,i,r+1),l=[];return y(null,e,r,l),s&&a&&t.index(r)==n.index(r)?(f(s,a),b(w(s,v(e,t,n,i,r+1)),l)):(s&&b(w(s,_(e,t,r+1)),l),y(t,n,r,l),a&&b(w(a,_(n,i,r+1)),l)),y(i,null,r,l),new o(l)}function _(e,t,n){let i=[];if(y(null,e,n,i),e.depth>n){b(w(g(e,t,n+1),_(e,t,n+1)),i)}return y(t,null,n,i),new o(i)}d.empty=new d(o.empty,0,0);class k{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 l.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 N(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),s=o-r;if(n.push(t,e,i+r),!s)break;if(t=t.child(e),t.isText)break;o=s-1,i+=r+1}return new k(t,n,o)}static resolveCached(e,t){let n=E.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 E.set(e,n=new x);let i=n.elts[n.i]=k.resolve(e,t);return n.i=(n.i+1)%j,i}}class x{constructor(){this.elts=[],this.i=0}}const j=12,E=new WeakMap;class N{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 S=Object.create(null);class M{constructor(e,t,n,i=l.none){this.type=e,this.attrs=t,this.marks=i,this.content=n||o.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||S)&&l.sameSet(this.marks,n||l.none)}copy(e=null){return e==this.content?this:new M(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new M(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 d.empty;let i=this.resolve(e),o=this.resolve(t),r=n?0:i.sharedDepth(t),s=i.start(r),a=i.node(r).content.cut(i.pos-s,o.pos-s);return new d(a,i.depth-r,o.depth-r)}replace(e,t,n){return h(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 k.resolveCached(this,e)}resolveNoCache(e){return k.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()+")"),O(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=o.empty,i=0,r=n.childCount){let s=this.contentMatchAt(e).matchFragment(n,i,r),a=s&&s.matchFragment(this.content,t);if(!a||!a.validEnd)return!1;for(let e=i;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=l.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(!l.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 i=o.fromJSON(e,t.content),r=e.nodeType(t.type).create(t.attrs,i,n);return r.type.checkAttrs(r.attrs),r}}M.prototype.text=void 0;class C extends M{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):O(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 C(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new C(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 O(e,t){for(let n=e.length-1;n>=0;n--)t=e[n].type.name+"("+t+")";return t}class A{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let n=new T(e,t);if(null==n.next)return A.empty;let i=D(n);n.next&&n.err("Unexpected trailing text");let o=function(e){let t=Object.create(null);return n(P(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]);P(e,n).forEach((e=>{i||o.push([t,i=[]]),-1==i.indexOf(e)&&i.push(e)}))}))}));let r=t[i.join(",")]=new A(i.indexOf(e.length-1)>-1);for(let e=0;e<o.length;e++){let i=o[e][1].sort(B);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 s=n();return i(t,s),o(r(e.expr,s),s),[i(s)]}if("plus"==e.type){let s=n();return o(r(e.expr,t),s),o(r(e.expr,s),s),[i(s)]}if("opt"==e.type)return[i(t)].concat(r(e.expr,t));if("range"==e.type){let s=t;for(let t=0;t<e.min;t++){let t=n();o(r(e.expr,s),t),s=t}if(-1==e.max)o(r(e.expr,s),s);else for(let t=e.min;t<e.max;t++){let t=n();i(s,t),o(r(e.expr,s),t),s=t}return[i(s)]}if("name"==e.type)return[i(t,void 0,e.value)];throw new Error("Unknown expr type")}for(let i=0;;i++){let s=r(e.exprs[i],t);if(i==e.exprs.length-1)return s;o(s,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:s}=e.next[t];r.push(n.name),!o||n.isText||n.hasRequiredAttrs()||(o=!1),-1==i.indexOf(s)&&i.push(s)}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 i=[this];return function r(s,a){let l=s.matchFragment(e,n);if(l&&(!t||l.validEnd))return o.from(a.map((e=>e.createAndFill())));for(let e=0;e<s.next.length;e++){let{type:t,next:n}=s.next[e];if(!t.isText&&!t.hasRequiredAttrs()&&-1==i.indexOf(n)){i.push(n);let e=r(n,a.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:s}=o.next[e];r.isLeaf||r.hasRequiredAttrs()||r.name in t||i.type&&!s.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")}}A.empty=new A(!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 D(e){let t=[];do{t.push(I(e))}while(e.eat("|"));return 1==t.length?t[0]:{type:"choice",exprs:t}}function I(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=D(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=z(e,t)}return t}function L(e){/\D/.test(e.next)&&e.err("Expected number, got '"+e.next+"'");let t=Number(e.next);return e.pos++,t}function z(e,t){let n=L(e),i=n;return e.eat(",")&&(i="}"!=e.next?L(e):-1),e.eat("}")||e.err("Unclosed braced range"),{type:"range",min:n,max:i,expr:t}}function B(e,t){return t-e}function P(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(B)}function $(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 F(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 q(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 H(e,t){let n=Object.create(null);if(t)for(let i in t)n[i]=new V(e,i,t[i]);return n}class U{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=H(e,n.attrs),this.defaultAttrs=$(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==A.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:F(this.attrs,e)}create(e=null,t,n){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new M(this,this.computeAttrs(e),o.from(t),l.setFrom(n))}createChecked(e=null,t,n){return t=o.from(t),this.checkContent(t),new M(this,this.computeAttrs(e),t,l.setFrom(n))}createAndFill(e=null,t,n){if(e=this.computeAttrs(e),(t=o.from(t)).size){let e=this.contentMatch.fillBefore(t);if(!e)return null;t=e.append(t)}let i=this.contentMatch.matchFragment(t),r=i&&i.fillBefore(o.empty,!0);return r?new M(this,e,t.append(r),l.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){q(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:l.none:e}static compile(e,t){let n=Object.create(null);e.forEach(((e,i)=>n[e]=new U(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 V{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 K{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=H(e,i.attrs),this.excluded=null;let o=$(this.attrs);this.instance=o?new l(this,o):null}create(e=null){return!e&&this.instance?this.instance:new l(this,F(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach(((e,o)=>n[e]=new K(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){q(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class W{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let t in e)n[t]=e[t];n.nodes=t.from(e.nodes),n.marks=t.from(e.marks||{}),this.nodes=U.compile(this.spec.nodes,this),this.marks=K.compile(this.spec.marks,this);let i=Object.create(null);for(let e in this.nodes){if(e in this.marks)throw new RangeError(e+" can not be both a node and a mark");let t=this.nodes[e],n=t.spec.content||"",o=t.spec.marks;if(t.contentMatch=i[n]||(i[n]=A.parse(n,this.nodes)),t.inlineContent=t.contentMatch.inlineContent,t.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!t.isInline||!t.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=t}t.markSet="_"==o?null:o?G(this,o.split(" ")):""!=o&&t.inlineContent?null:[]}for(let e in this.marks){let t=this.marks[e],n=t.spec.excludes;t.excluded=null==n?[t]:""==n?[]:G(this,n.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,n,i){if("string"==typeof e)e=this.nodeType(e);else{if(!(e instanceof U))throw new RangeError("Invalid node type: "+e);if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}return e.createChecked(t,n,i)}text(e,t){let n=this.nodes.text;return new C(n,n.defaultAttrs,e,l.setFrom(t))}mark(e,t){return"string"==typeof e&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return M.fromJSON(this,e)}markFromJSON(e){return l.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}}function G(e,t){let n=[];for(let i=0;i<t.length;i++){let o=t[i],r=e.marks[o],s=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(s=i)}if(!s)throw new SyntaxError("Unknown mark type: '"+t[i]+"'")}return n}class J{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 te(this,t,!1);return n.addAll(e,l.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new te(this,t,!0);return n.addAll(e,l.none,t.from,t.to),d.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(ne(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=ie(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=ie(e)),e.node||e.ignore||e.mark||(e.node=t)}))}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new J(e,J.schemaRules(e)))}}const Z={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},Q={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},X={ol:!0,ul:!0};function Y(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class ee{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=l.none,this.match=o||(4&r?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(o.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=o.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(o.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&&!Z.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class te{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=Y(null,t.preserveWhitespace,0)|(n?4:0);i=o?new ee(o.type,o.attrs,l.none,!0,t.topMatch||o.type.contentMatch,r):new ee(n?null:e.schema.topNodeType,null,l.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,s=e.nodeName.toLowerCase();X.hasOwnProperty(s)&&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&&X.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let a=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(r=this.parser.matchTag(e,this,n));e:if(a?a.ignore:Q.hasOwnProperty(s))this.findInside(e),this.ignoreFallback(e,t);else if(!a||a.skip||a.closeParent){a&&a.closeParent?this.open=Math.max(0,this.open-1):a&&a.skip.nodeType&&(e=a.skip);let n,i=this.needsBlock;if(Z.hasOwnProperty(s))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=a&&a.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,a,n,!1===a.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 s=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(s)&&this.open--}addAll(e,t,n,i){let o=n||0;for(let r=n?e.childNodes[n]:e.firstChild,s=null==i?null:e.childNodes[i];r!=s;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=l.none;for(let o of n.concat(e.marks))(t.type?t.type.allowsMarkType(o.type):oe(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 s=Y(e,o,r.options);4&r.options&&0==r.content.length&&(s|=4);let a=l.none;return n=n.filter((t=>!(r.type?r.type.allowsMarkType(t.type):oe(t.type,e))||(a=t.addToSet(a),!1))),this.nodes.push(new ee(e,t,a,i,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;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,s)=>{for(;e>=0;e--){let a=t[e];if(""==a){if(e==t.length-1||0==e)continue;for(;s>=o;s--)if(r(e-1,s))return!0;return!1}{let e=s>0||0==s&&i?this.nodes[s].type:n&&s>=o?n.node(s-o).type:null;if(!e||e.name!=a&&!e.isInGroup(a))return!1;s--}}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 ne(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function ie(e){let t={};for(let n in e)t[n]=e[n];return t}function oe(e,t){let n=t.schema.nodes;for(let i in n){let o=n[i];if(!o.allowsMarkType(e))continue;let r=[],s=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&&s(o))return!0}};if(s(o.contentMatch))return!0}}class re{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=ae(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++],s=this.serializeMark(n,e.isInline,t);s&&(o.push([n,i]),i.appendChild(s.dom),i=s.contentDOM||s.dom)}}i.appendChild(this.serializeNodeInner(e,t))})),n}serializeNodeInner(e,t){let{dom:n,contentDOM:i}=de(ae(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&&de(ae(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return de(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new re(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=se(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return se(e.marks)}}function se(e){let t={};for(let n in e){let i=e[n].spec.toDOM;i&&(t[n]=i)}return t}function ae(e){return e.document||window.document}const le=new WeakMap;function ce(e){let t=le.get(e);return void 0===t&&le.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 de(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=ce(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 s,a=r.indexOf(" ");a>0&&(n=r.slice(0,a),r=r.slice(a+1));let l=n?e.createElementNS(n,r):e.createElement(r),c=t[1],d=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){d=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=d;o<t.length;o++){let r=t[o];if(0===r){if(o<t.length-1||o>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:t,contentDOM:o}=de(e,r,n,i);if(l.appendChild(t),o){if(s)throw new RangeError("Multiple content holes");s=o}}}return{dom:l,contentDOM:s}}const me=Math.pow(2,16);function ue(e,t){return e+t*me}function he(e){return 65535&e}class pe{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 fe{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&fe.empty)return fe.empty}recover(e){let t=0,n=he(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))/me}(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 s=0;s<this.ranges.length;s+=3){let a=this.ranges[s]-(this.inverted?i:0);if(a>e)break;let l=this.ranges[s+o],c=this.ranges[s+r],d=a+l;if(e<=d){let o=a+i+((l?e==a?-1:e==d?1:t:t)<0?0:c);if(n)return o;let r=e==(t<0?a:d)?null:ue(s/3,e-a),m=e==a?2:e==d?1:4;return(t<0?e!=a:e!=d)&&(m|=8),new pe(o,m,r)}i+=c-l}return n?e+i:new pe(e+i,0,null)}touches(e,t){let n=0,i=he(t),o=this.inverted?2:1,r=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 a=this.ranges[t+o];if(e<=s+a&&t==3*i)return!0;n+=this.ranges[t+r]-a}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],s=r-(this.inverted?o:0),a=r+(this.inverted?0:o),l=this.ranges[i+t],c=this.ranges[i+n];e(s,s+l,a,a+c),o+=c-l}}invert(){return new fe(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?fe.empty:new fe(e<0?[0,-e,0]:[0,0,e])}}fe.empty=new fe([]);class ge{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 ge(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 ge;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 pe(e,i,null)}}const be=Object.create(null);class ye{getMap(){return fe.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=be[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 be)throw new RangeError("Duplicate use of step JSON ID "+e);return be[e]=t,t.prototype.jsonID=e,t}}class we{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new we(e,null)}static fail(e){return new we(null,e)}static fromReplace(e,t,n,i){try{return we.ok(e.replace(t,n,i))}catch(e){if(e instanceof c)return we.fail(e.message);throw e}}}function ve(e,t,n){let i=[];for(let o=0;o<e.childCount;o++){let r=e.child(o);r.content.size&&(r=r.copy(ve(r.content,t,r))),r.isInline&&(r=t(r,n,o)),i.push(r)}return o.fromArray(i)}class _e extends ye{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 d(ve(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 we.fromReplace(e,this.from,this.to,o)}invert(){return new ke(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.po