@yuniit/element-tiptap
Version:
🌸A modern WYSIWYG rich-text editor using tiptap and Element Plus for Vue3
4 lines • 849 kB
JavaScript
(function(j,s){typeof exports=="object"&&typeof module!="undefined"?s(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],s):(j=typeof globalThis!="undefined"?globalThis:j||self,s(j.ElementTiptapVue3={},j.vue))})(this,function(j,s){"use strict";function Ye(t){this.content=t}Ye.prototype={constructor:Ye,find:function(t){for(var e=0;e<this.content.length;e+=2)if(this.content[e]===t)return e;return-1},get:function(t){var e=this.find(t);return e==-1?void 0:this.content[e+1]},update:function(t,e,n){var o=n&&n!=t?this.remove(n):this,r=o.find(t),i=o.content.slice();return r==-1?i.push(n||t,e):(i[r+1]=e,n&&(i[r]=n)),new Ye(i)},remove:function(t){var e=this.find(t);if(e==-1)return this;var n=this.content.slice();return n.splice(e,2),new Ye(n)},addToStart:function(t,e){return new Ye([t,e].concat(this.remove(t).content))},addToEnd:function(t,e){var n=this.remove(t).content.slice();return n.push(t,e),new Ye(n)},addBefore:function(t,e,n){var o=this.remove(e),r=o.content.slice(),i=o.find(t);return r.splice(i==-1?r.length:i,0,e,n),new Ye(r)},forEach:function(t){for(var e=0;e<this.content.length;e+=2)t(this.content[e],this.content[e+1])},prepend:function(t){return t=Ye.from(t),t.size?new Ye(t.content.concat(this.subtract(t).content)):this},append:function(t){return t=Ye.from(t),t.size?new Ye(this.subtract(t).content.concat(t.content)):this},subtract:function(t){var e=this;t=Ye.from(t);for(var n=0;n<t.content.length;n+=2)e=e.remove(t.content[n]);return e},toObject:function(){var t={};return this.forEach(function(e,n){t[e]=n}),t},get size(){return this.content.length>>1}},Ye.from=function(t){if(t instanceof Ye)return t;var e=[];if(t)for(var n in t)e.push(n,t[n]);return new Ye(e)};function uf(t,e,n){for(let o=0;;o++){if(o==t.childCount||o==e.childCount)return t.childCount==e.childCount?null:n;let r=t.child(o),i=e.child(o);if(r==i){n+=r.nodeSize;continue}if(!r.sameMarkup(i))return n;if(r.isText&&r.text!=i.text){for(let l=0;r.text[l]==i.text[l];l++)n++;return n}if(r.content.size||i.content.size){let l=uf(r.content,i.content,n+1);if(l!=null)return l}n+=r.nodeSize}}function df(t,e,n,o){for(let r=t.childCount,i=e.childCount;;){if(r==0||i==0)return r==i?null:{a:n,b:o};let l=t.child(--r),a=e.child(--i),c=l.nodeSize;if(l==a){n-=c,o-=c;continue}if(!l.sameMarkup(a))return{a:n,b:o};if(l.isText&&l.text!=a.text){let u=0,d=Math.min(l.text.length,a.text.length);for(;u<d&&l.text[l.text.length-u-1]==a.text[a.text.length-u-1];)u++,n--,o--;return{a:n,b:o}}if(l.content.size||a.content.size){let u=df(l.content,a.content,n-1,o-1);if(u)return u}n-=c,o-=c}}class O{constructor(e,n){if(this.content=e,this.size=n||0,n==null)for(let o=0;o<e.length;o++)this.size+=e[o].nodeSize}nodesBetween(e,n,o,r=0,i){for(let l=0,a=0;a<n;l++){let c=this.content[l],u=a+c.nodeSize;if(u>e&&o(c,r+a,i||null,l)!==!1&&c.content.size){let d=a+1;c.nodesBetween(Math.max(0,e-d),Math.min(c.content.size,n-d),o,r+d)}a=u}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,n,o,r){let i="",l=!0;return this.nodesBetween(e,n,(a,c)=>{let u=a.isText?a.text.slice(Math.max(e,c)-c,n-c):a.isLeaf?r?typeof r=="function"?r(a):r:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&u||a.isTextblock)&&o&&(l?l=!1:i+=o),i+=u},0),i}append(e){if(!e.size)return this;if(!this.size)return e;let n=this.lastChild,o=e.firstChild,r=this.content.slice(),i=0;for(n.isText&&n.sameMarkup(o)&&(r[r.length-1]=n.withText(n.text+o.text),i=1);i<e.content.length;i++)r.push(e.content[i]);return new O(r,this.size+e.size)}cut(e,n=this.size){if(e==0&&n==this.size)return this;let o=[],r=0;if(n>e)for(let i=0,l=0;l<n;i++){let a=this.content[i],c=l+a.nodeSize;c>e&&((l<e||c>n)&&(a.isText?a=a.cut(Math.max(0,e-l),Math.min(a.text.length,n-l)):a=a.cut(Math.max(0,e-l-1),Math.min(a.content.size,n-l-1))),o.push(a),r+=a.nodeSize),l=c}return new O(o,r)}cutByIndex(e,n){return e==n?O.empty:e==0&&n==this.content.length?this:new O(this.content.slice(e,n))}replaceChild(e,n){let o=this.content[e];if(o==n)return this;let r=this.content.slice(),i=this.size+n.nodeSize-o.nodeSize;return r[e]=n,new O(r,i)}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 n=0;n<this.content.length;n++)if(!this.content[n].eq(e.content[n]))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 n=this.content[e];if(!n)throw new RangeError("Index "+e+" out of range for "+this);return n}maybeChild(e){return this.content[e]||null}forEach(e){for(let n=0,o=0;n<this.content.length;n++){let r=this.content[n];e(r,o,n),o+=r.nodeSize}}findDiffStart(e,n=0){return uf(this,e,n)}findDiffEnd(e,n=this.size,o=e.size){return df(this,e,n,o)}findIndex(e,n=-1){if(e==0)return Ji(0,e);if(e==this.size)return Ji(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let o=0,r=0;;o++){let i=this.child(o),l=r+i.nodeSize;if(l>=e)return l==e||n>0?Ji(o+1,l):Ji(o,r);r=l}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,n){if(!n)return O.empty;if(!Array.isArray(n))throw new RangeError("Invalid input for Fragment.fromJSON");return new O(n.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return O.empty;let n,o=0;for(let r=0;r<e.length;r++){let i=e[r];o+=i.nodeSize,r&&i.isText&&e[r-1].sameMarkup(i)?(n||(n=e.slice(0,r)),n[n.length-1]=i.withText(n[n.length-1].text+i.text)):n&&n.push(i)}return new O(n||e,o)}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 Na={index:0,offset:0};function Ji(t,e){return Na.index=t,Na.offset=e,Na}function Yi(t,e){if(t===e)return!0;if(!(t&&typeof t=="object")||!(e&&typeof e=="object"))return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let o=0;o<t.length;o++)if(!Yi(t[o],e[o]))return!1}else{for(let o in t)if(!(o in e)||!Yi(t[o],e[o]))return!1;for(let o in e)if(!(o in t))return!1}return!0}class me{constructor(e,n){this.type=e,this.attrs=n}addToSet(e){let n,o=!1;for(let r=0;r<e.length;r++){let i=e[r];if(this.eq(i))return e;if(this.type.excludes(i.type))n||(n=e.slice(0,r));else{if(i.type.excludes(this.type))return e;!o&&i.type.rank>this.type.rank&&(n||(n=e.slice(0,r)),n.push(this),o=!0),n&&n.push(i)}}return n||(n=e.slice()),o||n.push(this),n}removeFromSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return e.slice(0,n).concat(e.slice(n+1));return e}isInSet(e){for(let n=0;n<e.length;n++)if(this.eq(e[n]))return!0;return!1}eq(e){return this==e||this.type==e.type&&Yi(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let n in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Mark.fromJSON");let o=e.marks[n.type];if(!o)throw new RangeError(`There is no mark type ${n.type} in this schema`);return o.create(n.attrs)}static sameSet(e,n){if(e==n)return!0;if(e.length!=n.length)return!1;for(let o=0;o<e.length;o++)if(!e[o].eq(n[o]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&e.length==0)return me.none;if(e instanceof me)return[e];let n=e.slice();return n.sort((o,r)=>o.type.rank-r.type.rank),n}}me.none=[];class Xi extends Error{}class P{constructor(e,n,o){this.content=e,this.openStart=n,this.openEnd=o}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,n){let o=pf(this.content,e+this.openStart,n);return o&&new P(o,this.openStart,this.openEnd)}removeBetween(e,n){return new P(ff(this.content,e+this.openStart,n+this.openStart),this.openStart,this.openEnd)}eq(e){return this.content.eq(e.content)&&this.openStart==e.openStart&&this.openEnd==e.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let e={content:this.content.toJSON()};return this.openStart>0&&(e.openStart=this.openStart),this.openEnd>0&&(e.openEnd=this.openEnd),e}static fromJSON(e,n){if(!n)return P.empty;let o=n.openStart||0,r=n.openEnd||0;if(typeof o!="number"||typeof r!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new P(O.fromJSON(e,n.content),o,r)}static maxOpen(e,n=!0){let o=0,r=0;for(let i=e.firstChild;i&&!i.isLeaf&&(n||!i.type.spec.isolating);i=i.firstChild)o++;for(let i=e.lastChild;i&&!i.isLeaf&&(n||!i.type.spec.isolating);i=i.lastChild)r++;return new P(e,o,r)}}P.empty=new P(O.empty,0,0);function ff(t,e,n){let{index:o,offset:r}=t.findIndex(e),i=t.maybeChild(o),{index:l,offset:a}=t.findIndex(n);if(r==e||i.isText){if(a!=n&&!t.child(l).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(o!=l)throw new RangeError("Removing non-flat range");return t.replaceChild(o,i.copy(ff(i.content,e-r-1,n-r-1)))}function pf(t,e,n,o){let{index:r,offset:i}=t.findIndex(e),l=t.maybeChild(r);if(i==e||l.isText)return o&&!o.canReplace(r,r,n)?null:t.cut(0,e).append(n).append(t.cut(e));let a=pf(l.content,e-i-1,n);return a&&t.replaceChild(r,l.copy(a))}function u4(t,e,n){if(n.openStart>t.depth)throw new Xi("Inserted content deeper than insertion position");if(t.depth-n.openStart!=e.depth-n.openEnd)throw new Xi("Inconsistent open depths");return hf(t,e,n,0)}function hf(t,e,n,o){let r=t.index(o),i=t.node(o);if(r==e.index(o)&&o<t.depth-n.openStart){let l=hf(t,e,n,o+1);return i.copy(i.content.replaceChild(r,l))}else if(n.content.size)if(!n.openStart&&!n.openEnd&&t.depth==o&&e.depth==o){let l=t.parent,a=l.content;return bo(l,a.cut(0,t.parentOffset).append(n.content).append(a.cut(e.parentOffset)))}else{let{start:l,end:a}=d4(n,t);return bo(i,gf(t,l,a,e,o))}else return bo(i,Zi(t,e,o))}function mf(t,e){if(!e.type.compatibleContent(t.type))throw new Xi("Cannot join "+e.type.name+" onto "+t.type.name)}function Ia(t,e,n){let o=t.node(n);return mf(o,e.node(n)),o}function go(t,e){let n=e.length-1;n>=0&&t.isText&&t.sameMarkup(e[n])?e[n]=t.withText(e[n].text+t.text):e.push(t)}function Wr(t,e,n,o){let r=(e||t).node(n),i=0,l=e?e.index(n):r.childCount;t&&(i=t.index(n),t.depth>n?i++:t.textOffset&&(go(t.nodeAfter,o),i++));for(let a=i;a<l;a++)go(r.child(a),o);e&&e.depth==n&&e.textOffset&&go(e.nodeBefore,o)}function bo(t,e){return t.type.checkContent(e),t.copy(e)}function gf(t,e,n,o,r){let i=t.depth>r&&Ia(t,e,r+1),l=o.depth>r&&Ia(n,o,r+1),a=[];return Wr(null,t,r,a),i&&l&&e.index(r)==n.index(r)?(mf(i,l),go(bo(i,gf(t,e,n,o,r+1)),a)):(i&&go(bo(i,Zi(t,e,r+1)),a),Wr(e,n,r,a),l&&go(bo(l,Zi(n,o,r+1)),a)),Wr(o,null,r,a),new O(a)}function Zi(t,e,n){let o=[];if(Wr(null,t,n,o),t.depth>n){let r=Ia(t,e,n+1);go(bo(r,Zi(t,e,n+1)),o)}return Wr(e,null,n,o),new O(o)}function d4(t,e){let n=e.depth-t.openStart,r=e.node(n).copy(t.content);for(let i=n-1;i>=0;i--)r=e.node(i).copy(O.from(r));return{start:r.resolveNoCache(t.openStart+n),end:r.resolveNoCache(r.content.size-t.openEnd-n)}}class qr{constructor(e,n,o){this.pos=e,this.path=n,this.parentOffset=o,this.depth=n.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,n=this.index(this.depth);if(n==e.childCount)return null;let o=this.pos-this.path[this.path.length-1],r=e.child(n);return o?e.child(n).cut(o):r}get nodeBefore(){let e=this.index(this.depth),n=this.pos-this.path[this.path.length-1];return n?this.parent.child(e).cut(0,n):e==0?null:this.parent.child(e-1)}posAtIndex(e,n){n=this.resolveDepth(n);let o=this.path[n*3],r=n==0?0:this.path[n*3-1]+1;for(let i=0;i<e;i++)r+=o.child(i).nodeSize;return r}marks(){let e=this.parent,n=this.index();if(e.content.size==0)return me.none;if(this.textOffset)return e.child(n).marks;let o=e.maybeChild(n-1),r=e.maybeChild(n);if(!o){let a=o;o=r,r=a}let i=o.marks;for(var l=0;l<i.length;l++)i[l].type.spec.inclusive===!1&&(!r||!i[l].isInSet(r.marks))&&(i=i[l--].removeFromSet(i));return i}marksAcross(e){let n=this.parent.maybeChild(this.index());if(!n||!n.isInline)return null;let o=n.marks,r=e.parent.maybeChild(e.index());for(var i=0;i<o.length;i++)o[i].type.spec.inclusive===!1&&(!r||!o[i].isInSet(r.marks))&&(o=o[i--].removeFromSet(o));return o}sharedDepth(e){for(let n=this.depth;n>0;n--)if(this.start(n)<=e&&this.end(n)>=e)return n;return 0}blockRange(e=this,n){if(e.pos<this.pos)return e.blockRange(this);for(let o=this.depth-(this.parent.inlineContent||this.pos==e.pos?1:0);o>=0;o--)if(e.pos<=this.end(o)&&(!n||n(this.node(o))))return new Qi(this,e,o);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 n=1;n<=this.depth;n++)e+=(e?"/":"")+this.node(n).type.name+"_"+this.index(n-1);return e+":"+this.parentOffset}static resolve(e,n){if(!(n>=0&&n<=e.content.size))throw new RangeError("Position "+n+" out of range");let o=[],r=0,i=n;for(let l=e;;){let{index:a,offset:c}=l.content.findIndex(i),u=i-c;if(o.push(l,a,r+c),!u||(l=l.child(a),l.isText))break;i=u-1,r+=c+1}return new qr(n,o,i)}static resolveCached(e,n){for(let r=0;r<$a.length;r++){let i=$a[r];if(i.pos==n&&i.doc==e)return i}let o=$a[La]=qr.resolve(e,n);return La=(La+1)%f4,o}}let $a=[],La=0,f4=12;class Qi{constructor(e,n,o){this.$from=e,this.$to=n,this.depth=o}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 p4=Object.create(null);class tn{constructor(e,n,o,r=me.none){this.type=e,this.attrs=n,this.marks=r,this.content=o||O.empty}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,n,o,r=0){this.content.nodesBetween(e,n,o,r,this)}descendants(e){this.nodesBetween(0,this.content.size,e)}get textContent(){return this.isLeaf&&this.type.spec.leafText?this.type.spec.leafText(this):this.textBetween(0,this.content.size,"")}textBetween(e,n,o,r){return this.content.textBetween(e,n,o,r)}get firstChild(){return this.content.firstChild}get lastChild(){return this.content.lastChild}eq(e){return this==e||this.sameMarkup(e)&&this.content.eq(e.content)}sameMarkup(e){return this.hasMarkup(e.type,e.attrs,e.marks)}hasMarkup(e,n,o){return this.type==e&&Yi(this.attrs,n||e.defaultAttrs||p4)&&me.sameSet(this.marks,o||me.none)}copy(e=null){return e==this.content?this:new tn(this.type,this.attrs,e,this.marks)}mark(e){return e==this.marks?this:new tn(this.type,this.attrs,this.content,e)}cut(e,n=this.content.size){return e==0&&n==this.content.size?this:this.copy(this.content.cut(e,n))}slice(e,n=this.content.size,o=!1){if(e==n)return P.empty;let r=this.resolve(e),i=this.resolve(n),l=o?0:r.sharedDepth(n),a=r.start(l),u=r.node(l).content.cut(r.pos-a,i.pos-a);return new P(u,r.depth-l,i.depth-l)}replace(e,n,o){return u4(this.resolve(e),this.resolve(n),o)}nodeAt(e){for(let n=this;;){let{index:o,offset:r}=n.content.findIndex(e);if(n=n.maybeChild(o),!n)return null;if(r==e||n.isText)return n;e-=r+1}}childAfter(e){let{index:n,offset:o}=this.content.findIndex(e);return{node:this.content.maybeChild(n),index:n,offset:o}}childBefore(e){if(e==0)return{node:null,index:0,offset:0};let{index:n,offset:o}=this.content.findIndex(e);if(o<e)return{node:this.content.child(n),index:n,offset:o};let r=this.content.child(n-1);return{node:r,index:n-1,offset:o-r.nodeSize}}resolve(e){return qr.resolveCached(this,e)}resolveNoCache(e){return qr.resolve(this,e)}rangeHasMark(e,n,o){let r=!1;return n>e&&this.nodesBetween(e,n,i=>(o.isInSet(i.marks)&&(r=!0),!r)),r}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),bf(this.marks,e)}contentMatchAt(e){let n=this.type.contentMatch.matchFragment(this.content,0,e);if(!n)throw new Error("Called contentMatchAt on a node with invalid content");return n}canReplace(e,n,o=O.empty,r=0,i=o.childCount){let l=this.contentMatchAt(e).matchFragment(o,r,i),a=l&&l.matchFragment(this.content,n);if(!a||!a.validEnd)return!1;for(let c=r;c<i;c++)if(!this.type.allowsMarks(o.child(c).marks))return!1;return!0}canReplaceWith(e,n,o,r){if(r&&!this.type.allowsMarks(r))return!1;let i=this.contentMatchAt(e).matchType(o),l=i&&i.matchFragment(this.content,n);return l?l.validEnd:!1}canAppend(e){return e.content.size?this.canReplace(this.childCount,this.childCount,e.content):this.type.compatibleContent(e.type)}check(){this.type.checkContent(this.content);let e=me.none;for(let n=0;n<this.marks.length;n++)e=this.marks[n].addToSet(e);if(!me.sameSet(e,this.marks))throw new RangeError(`Invalid collection of marks for node ${this.type.name}: ${this.marks.map(n=>n.type.name)}`);this.content.forEach(n=>n.check())}toJSON(){let e={type:this.type.name};for(let n 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(n=>n.toJSON())),e}static fromJSON(e,n){if(!n)throw new RangeError("Invalid input for Node.fromJSON");let o=null;if(n.marks){if(!Array.isArray(n.marks))throw new RangeError("Invalid mark data for Node.fromJSON");o=n.marks.map(e.markFromJSON)}if(n.type=="text"){if(typeof n.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(n.text,o)}let r=O.fromJSON(e,n.content);return e.nodeType(n.type).create(n.attrs,r,o)}}tn.prototype.text=void 0;class es extends tn{constructor(e,n,o,r){if(super(e,n,null,r),!o)throw new RangeError("Empty text nodes are not allowed");this.text=o}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):bf(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,n){return this.text.slice(e,n)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new es(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new es(this.type,this.attrs,e,this.marks)}cut(e=0,n=this.text.length){return e==0&&n==this.text.length?this:this.withText(this.text.slice(e,n))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}}function bf(t,e){for(let n=t.length-1;n>=0;n--)e=t[n].type.name+"("+e+")";return e}class yo{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,n){let o=new h4(e,n);if(o.next==null)return yo.empty;let r=yf(o);o.next&&o.err("Unexpected trailing text");let i=E4(w4(r));return k4(i,o),i}matchType(e){for(let n=0;n<this.next.length;n++)if(this.next[n].type==e)return this.next[n].next;return null}matchFragment(e,n=0,o=e.childCount){let r=this;for(let i=n;r&&i<o;i++)r=r.matchType(e.child(i).type);return r}get inlineContent(){return this.next.length!=0&&this.next[0].type.isInline}get defaultType(){for(let e=0;e<this.next.length;e++){let{type:n}=this.next[e];if(!(n.isText||n.hasRequiredAttrs()))return n}return null}compatible(e){for(let n=0;n<this.next.length;n++)for(let o=0;o<e.next.length;o++)if(this.next[n].type==e.next[o].type)return!0;return!1}fillBefore(e,n=!1,o=0){let r=[this];function i(l,a){let c=l.matchFragment(e,o);if(c&&(!n||c.validEnd))return O.from(a.map(u=>u.createAndFill()));for(let u=0;u<l.next.length;u++){let{type:d,next:f}=l.next[u];if(!(d.isText||d.hasRequiredAttrs())&&r.indexOf(f)==-1){r.push(f);let p=i(f,a.concat(d));if(p)return p}}return null}return i(this,[])}findWrapping(e){for(let o=0;o<this.wrapCache.length;o+=2)if(this.wrapCache[o]==e)return this.wrapCache[o+1];let n=this.computeWrapping(e);return this.wrapCache.push(e,n),n}computeWrapping(e){let n=Object.create(null),o=[{match:this,type:null,via:null}];for(;o.length;){let r=o.shift(),i=r.match;if(i.matchType(e)){let l=[];for(let a=r;a.type;a=a.via)l.push(a.type);return l.reverse()}for(let l=0;l<i.next.length;l++){let{type:a,next:c}=i.next[l];!a.isLeaf&&!a.hasRequiredAttrs()&&!(a.name in n)&&(!r.type||c.validEnd)&&(o.push({match:a.contentMatch,type:a,via:r}),n[a.name]=!0)}}return null}get edgeCount(){return this.next.length}edge(e){if(e>=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function n(o){e.push(o);for(let r=0;r<o.next.length;r++)e.indexOf(o.next[r].next)==-1&&n(o.next[r].next)}return n(this),e.map((o,r)=>{let i=r+(o.validEnd?"*":" ")+" ";for(let l=0;l<o.next.length;l++)i+=(l?", ":"")+o.next[l].type.name+"->"+e.indexOf(o.next[l].next);return i}).join(`
`)}}yo.empty=new yo(!0);class h4{constructor(e,n){this.string=e,this.nodeTypes=n,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 yf(t){let e=[];do e.push(m4(t));while(t.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function m4(t){let e=[];do e.push(g4(t));while(t.next&&t.next!=")"&&t.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function g4(t){let e=C4(t);for(;;)if(t.eat("+"))e={type:"plus",expr:e};else if(t.eat("*"))e={type:"star",expr:e};else if(t.eat("?"))e={type:"opt",expr:e};else if(t.eat("{"))e=b4(t,e);else break;return e}function Cf(t){/\D/.test(t.next)&&t.err("Expected number, got '"+t.next+"'");let e=Number(t.next);return t.pos++,e}function b4(t,e){let n=Cf(t),o=n;return t.eat(",")&&(t.next!="}"?o=Cf(t):o=-1),t.eat("}")||t.err("Unclosed braced range"),{type:"range",min:n,max:o,expr:e}}function y4(t,e){let n=t.nodeTypes,o=n[e];if(o)return[o];let r=[];for(let i in n){let l=n[i];l.groups.indexOf(e)>-1&&r.push(l)}return r.length==0&&t.err("No node type or group '"+e+"' found"),r}function C4(t){if(t.eat("(")){let e=yf(t);return t.eat(")")||t.err("Missing closing paren"),e}else if(/\W/.test(t.next))t.err("Unexpected token '"+t.next+"'");else{let e=y4(t,t.next).map(n=>(t.inline==null?t.inline=n.isInline:t.inline!=n.isInline&&t.err("Mixing inline and block content"),{type:"name",value:n}));return t.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function w4(t){let e=[[]];return r(i(t,0),n()),e;function n(){return e.push([])-1}function o(l,a,c){let u={term:c,to:a};return e[l].push(u),u}function r(l,a){l.forEach(c=>c.to=a)}function i(l,a){if(l.type=="choice")return l.exprs.reduce((c,u)=>c.concat(i(u,a)),[]);if(l.type=="seq")for(let c=0;;c++){let u=i(l.exprs[c],a);if(c==l.exprs.length-1)return u;r(u,a=n())}else if(l.type=="star"){let c=n();return o(a,c),r(i(l.expr,c),c),[o(c)]}else if(l.type=="plus"){let c=n();return r(i(l.expr,a),c),r(i(l.expr,c),c),[o(c)]}else{if(l.type=="opt")return[o(a)].concat(i(l.expr,a));if(l.type=="range"){let c=a;for(let u=0;u<l.min;u++){let d=n();r(i(l.expr,c),d),c=d}if(l.max==-1)r(i(l.expr,c),c);else for(let u=l.min;u<l.max;u++){let d=n();o(c,d),r(i(l.expr,c),d),c=d}return[o(c)]}else{if(l.type=="name")return[o(a,void 0,l.value)];throw new Error("Unknown expr type")}}}}function wf(t,e){return e-t}function Ef(t,e){let n=[];return o(e),n.sort(wf);function o(r){let i=t[r];if(i.length==1&&!i[0].term)return o(i[0].to);n.push(r);for(let l=0;l<i.length;l++){let{term:a,to:c}=i[l];!a&&n.indexOf(c)==-1&&o(c)}}}function E4(t){let e=Object.create(null);return n(Ef(t,0));function n(o){let r=[];o.forEach(l=>{t[l].forEach(({term:a,to:c})=>{if(!a)return;let u;for(let d=0;d<r.length;d++)r[d][0]==a&&(u=r[d][1]);Ef(t,c).forEach(d=>{u||r.push([a,u=[]]),u.indexOf(d)==-1&&u.push(d)})})});let i=e[o.join(",")]=new yo(o.indexOf(t.length-1)>-1);for(let l=0;l<r.length;l++){let a=r[l][1].sort(wf);i.next.push({type:r[l][0],next:e[a.join(",")]||n(a)})}return i}}function k4(t,e){for(let n=0,o=[t];n<o.length;n++){let r=o[n],i=!r.validEnd,l=[];for(let a=0;a<r.next.length;a++){let{type:c,next:u}=r.next[a];l.push(c.name),i&&!(c.isText||c.hasRequiredAttrs())&&(i=!1),o.indexOf(u)==-1&&o.push(u)}i&&e.err("Only non-generatable nodes ("+l.join(", ")+") in a required position (see https://prosemirror.net/docs/guide/#generatable)")}}function kf(t){let e=Object.create(null);for(let n in t){let o=t[n];if(!o.hasDefault)return null;e[n]=o.default}return e}function vf(t,e){let n=Object.create(null);for(let o in t){let r=e&&e[o];if(r===void 0){let i=t[o];if(i.hasDefault)r=i.default;else throw new RangeError("No value supplied for attribute "+o)}n[o]=r}return n}function Sf(t){let e=Object.create(null);if(t)for(let n in t)e[n]=new v4(t[n]);return e}class ts{constructor(e,n,o){this.name=e,this.schema=n,this.spec=o,this.markSet=null,this.groups=o.group?o.group.split(" "):[],this.attrs=Sf(o.attrs),this.defaultAttrs=kf(this.attrs),this.contentMatch=null,this.inlineContent=null,this.isBlock=!(o.inline||e=="text"),this.isText=e=="text"}get isInline(){return!this.isBlock}get isTextblock(){return this.isBlock&&this.inlineContent}get isLeaf(){return this.contentMatch==yo.empty}get isAtom(){return this.isLeaf||!!this.spec.atom}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:vf(this.attrs,e)}create(e=null,n,o){if(this.isText)throw new Error("NodeType.create can't construct text nodes");return new tn(this,this.computeAttrs(e),O.from(n),me.setFrom(o))}createChecked(e=null,n,o){return n=O.from(n),this.checkContent(n),new tn(this,this.computeAttrs(e),n,me.setFrom(o))}createAndFill(e=null,n,o){if(e=this.computeAttrs(e),n=O.from(n),n.size){let l=this.contentMatch.fillBefore(n);if(!l)return null;n=l.append(n)}let r=this.contentMatch.matchFragment(n),i=r&&r.fillBefore(O.empty,!0);return i?new tn(this,e,n.append(i),me.setFrom(o)):null}validContent(e){let n=this.contentMatch.matchFragment(e);if(!n||!n.validEnd)return!1;for(let o=0;o<e.childCount;o++)if(!this.allowsMarks(e.child(o).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)}`)}allowsMarkType(e){return this.markSet==null||this.markSet.indexOf(e)>-1}allowsMarks(e){if(this.markSet==null)return!0;for(let n=0;n<e.length;n++)if(!this.allowsMarkType(e[n].type))return!1;return!0}allowedMarks(e){if(this.markSet==null)return e;let n;for(let o=0;o<e.length;o++)this.allowsMarkType(e[o].type)?n&&n.push(e[o]):n||(n=e.slice(0,o));return n?n.length?n:me.none:e}static compile(e,n){let o=Object.create(null);e.forEach((i,l)=>o[i]=new ts(i,n,l));let r=n.spec.topNode||"doc";if(!o[r])throw new RangeError("Schema is missing its top node type ('"+r+"')");if(!o.text)throw new RangeError("Every schema needs a 'text' type");for(let i in o.text.attrs)throw new RangeError("The text node type should not have attributes");return o}}class v4{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}}class ns{constructor(e,n,o,r){this.name=e,this.rank=n,this.schema=o,this.spec=r,this.attrs=Sf(r.attrs),this.excluded=null;let i=kf(this.attrs);this.instance=i?new me(this,i):null}create(e=null){return!e&&this.instance?this.instance:new me(this,vf(this.attrs,e))}static compile(e,n){let o=Object.create(null),r=0;return e.forEach((i,l)=>o[i]=new ns(i,r++,n,l)),o}removeFromSet(e){for(var n=0;n<e.length;n++)e[n].type==this&&(e=e.slice(0,n).concat(e.slice(n+1)),n--);return e}isInSet(e){for(let n=0;n<e.length;n++)if(e[n].type==this)return e[n]}excludes(e){return this.excluded.indexOf(e)>-1}}class S4{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let n=this.spec={};for(let r in e)n[r]=e[r];n.nodes=Ye.from(e.nodes),n.marks=Ye.from(e.marks||{}),this.nodes=ts.compile(this.spec.nodes,this),this.marks=ns.compile(this.spec.marks,this);let o=Object.create(null);for(let r in this.nodes){if(r in this.marks)throw new RangeError(r+" can not be both a node and a mark");let i=this.nodes[r],l=i.spec.content||"",a=i.spec.marks;if(i.contentMatch=o[l]||(o[l]=yo.parse(l,this.nodes)),i.inlineContent=i.contentMatch.inlineContent,i.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!i.isInline||!i.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=i}i.markSet=a=="_"?null:a?_f(this,a.split(" ")):a==""||!i.inlineContent?[]:null}for(let r in this.marks){let i=this.marks[r],l=i.spec.excludes;i.excluded=l==null?[i]:l==""?[]:_f(this,l.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,n=null,o,r){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof ts){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(n,o,r)}text(e,n){let o=this.nodes.text;return new es(o,o.defaultAttrs,e,me.setFrom(n))}mark(e,n){return typeof e=="string"&&(e=this.marks[e]),e.create(n)}nodeFromJSON(e){return tn.fromJSON(this,e)}markFromJSON(e){return me.fromJSON(this,e)}nodeType(e){let n=this.nodes[e];if(!n)throw new RangeError("Unknown node type: "+e);return n}}function _f(t,e){let n=[];for(let o=0;o<e.length;o++){let r=e[o],i=t.marks[r],l=i;if(i)n.push(i);else for(let a in t.marks){let c=t.marks[a];(r=="_"||c.spec.group&&c.spec.group.split(" ").indexOf(r)>-1)&&n.push(l=c)}if(!l)throw new SyntaxError("Unknown mark type: '"+e[o]+"'")}return n}function _4(t){return t.tag!=null}function T4(t){return t.style!=null}class Zo{constructor(e,n){this.schema=e,this.rules=n,this.tags=[],this.styles=[],n.forEach(o=>{_4(o)?this.tags.push(o):T4(o)&&this.styles.push(o)}),this.normalizeLists=!this.tags.some(o=>{if(!/^(ul|ol)\b/.test(o.tag)||!o.node)return!1;let r=e.nodes[o.node];return r.contentMatch.matchType(r)})}parse(e,n={}){let o=new Mf(this,n,!1);return o.addAll(e,n.from,n.to),o.finish()}parseSlice(e,n={}){let o=new Mf(this,n,!0);return o.addAll(e,n.from,n.to),P.maxOpen(o.finish())}matchTag(e,n,o){for(let r=o?this.tags.indexOf(o)+1:0;r<this.tags.length;r++){let i=this.tags[r];if(M4(e,i.tag)&&(i.namespace===void 0||e.namespaceURI==i.namespace)&&(!i.context||n.matchesContext(i.context))){if(i.getAttrs){let l=i.getAttrs(e);if(l===!1)continue;i.attrs=l||void 0}return i}}}matchStyle(e,n,o,r){for(let i=r?this.styles.indexOf(r)+1:0;i<this.styles.length;i++){let l=this.styles[i],a=l.style;if(!(a.indexOf(e)!=0||l.context&&!o.matchesContext(l.context)||a.length>e.length&&(a.charCodeAt(e.length)!=61||a.slice(e.length+1)!=n))){if(l.getAttrs){let c=l.getAttrs(n);if(c===!1)continue;l.attrs=c||void 0}return l}}}static schemaRules(e){let n=[];function o(r){let i=r.priority==null?50:r.priority,l=0;for(;l<n.length;l++){let a=n[l];if((a.priority==null?50:a.priority)<i)break}n.splice(l,0,r)}for(let r in e.marks){let i=e.marks[r].spec.parseDOM;i&&i.forEach(l=>{o(l=Df(l)),l.mark||l.ignore||l.clearMark||(l.mark=r)})}for(let r in e.nodes){let i=e.nodes[r].spec.parseDOM;i&&i.forEach(l=>{o(l=Df(l)),l.node||l.ignore||l.mark||(l.node=r)})}return n}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new Zo(e,Zo.schemaRules(e)))}}const Tf={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},A4={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},Af={ol:!0,ul:!0},rs=1,is=2,Kr=4;function xf(t,e,n){return e!=null?(e?rs:0)|(e==="full"?is:0):t&&t.whitespace=="pre"?rs|is:n&~Kr}class ss{constructor(e,n,o,r,i,l,a){this.type=e,this.attrs=n,this.marks=o,this.pendingMarks=r,this.solid=i,this.options=a,this.content=[],this.activeMarks=me.none,this.stashMarks=[],this.match=l||(a&Kr?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let n=this.type.contentMatch.fillBefore(O.from(e));if(n)this.match=this.type.contentMatch.matchFragment(n);else{let o=this.type.contentMatch,r;return(r=o.findWrapping(e.type))?(this.match=o,r):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&rs)){let o=this.content[this.content.length-1],r;if(o&&o.isText&&(r=/[ \t\r\n\u000c]+$/.exec(o.text))){let i=o;o.text.length==r[0].length?this.content.pop():this.content[this.content.length-1]=i.withText(i.text.slice(0,i.text.length-r[0].length))}}let n=O.from(this.content);return!e&&this.match&&(n=n.append(this.match.fillBefore(O.empty,!0))),this.type?this.type.create(this.attrs,n,this.marks):n}popFromStashMark(e){for(let n=this.stashMarks.length-1;n>=0;n--)if(e.eq(this.stashMarks[n]))return this.stashMarks.splice(n,1)[0]}applyPending(e){for(let n=0,o=this.pendingMarks;n<o.length;n++){let r=o[n];(this.type?this.type.allowsMarkType(r.type):D4(r.type,e))&&!r.isInSet(this.activeMarks)&&(this.activeMarks=r.addToSet(this.activeMarks),this.pendingMarks=r.removeFromSet(this.pendingMarks))}}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!Tf.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class Mf{constructor(e,n,o){this.parser=e,this.options=n,this.isOpen=o,this.open=0;let r=n.topNode,i,l=xf(null,n.preserveWhitespace,0)|(o?Kr:0);r?i=new ss(r.type,r.attrs,me.none,me.none,!0,n.topMatch||r.type.contentMatch,l):o?i=new ss(null,null,me.none,me.none,!0,null,l):i=new ss(e.schema.topNodeType,null,me.none,me.none,!0,null,l),this.nodes=[i],this.find=n.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(e){e.nodeType==3?this.addTextNode(e):e.nodeType==1&&this.addElement(e)}withStyleRules(e,n){let o=e.style;if(!o||!o.length)return n();let r=this.readStyles(e.style);if(!r)return;let[i,l]=r,a=this.top;for(let c=0;c<l.length;c++)this.removePendingMark(l[c],a);for(let c=0;c<i.length;c++)this.addPendingMark(i[c]);n();for(let c=0;c<i.length;c++)this.removePendingMark(i[c],a);for(let c=0;c<l.length;c++)this.addPendingMark(l[c])}addTextNode(e){let n=e.nodeValue,o=this.top;if(o.options&is||o.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(o.options&rs)o.options&is?n=n.replace(/\r\n?/g,`
`):n=n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let r=o.content[o.content.length-1],i=e.previousSibling;(!r||i&&i.nodeName=="BR"||r.isText&&/[ \t\r\n\u000c]$/.test(r.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n)),this.findInText(e)}else this.findInside(e)}addElement(e,n){let o=e.nodeName.toLowerCase(),r;Af.hasOwnProperty(o)&&this.parser.normalizeLists&&x4(e);let i=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(r=this.parser.matchTag(e,this,n));if(i?i.ignore:A4.hasOwnProperty(o))this.findInside(e),this.ignoreFallback(e);else if(!i||i.skip||i.closeParent){i&&i.closeParent?this.open=Math.max(0,this.open-1):i&&i.skip.nodeType&&(e=i.skip);let l,a=this.top,c=this.needsBlock;if(Tf.hasOwnProperty(o))a.content.length&&a.content[0].isInline&&this.open&&(this.open--,a=this.top),l=!0,a.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e);return}i&&i.skip?this.addAll(e):this.withStyleRules(e,()=>this.addAll(e)),l&&this.sync(a),this.needsBlock=c}else this.withStyleRules(e,()=>{this.addElementByRule(e,i,i.consuming===!1?r:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let n=me.none,o=me.none;for(let r=0,i=e.length;r<i;r++){let l=e.item(r);for(let a=void 0;;){let c=this.parser.matchStyle(l,e.getPropertyValue(l),this,a);if(!c)break;if(c.ignore)return null;if(c.clearMark?this.top.pendingMarks.concat(this.top.activeMarks).forEach(u=>{c.clearMark(u)&&(o=u.addToSet(o))}):n=this.parser.schema.marks[c.mark].create(c.attrs).addToSet(n),c.consuming===!1)a=c;else break}}return[n,o]}addElementByRule(e,n,o){let r,i,l;n.node?(i=this.parser.schema.nodes[n.node],i.isLeaf?this.insertNode(i.create(n.attrs))||this.leafFallback(e):r=this.enter(i,n.attrs||null,n.preserveWhitespace)):(l=this.parser.schema.marks[n.mark].create(n.attrs),this.addPendingMark(l));let a=this.top;if(i&&i.isLeaf)this.findInside(e);else if(o)this.addElement(e,o);else if(n.getContent)this.findInside(e),n.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=e;typeof n.contentElement=="string"?c=e.querySelector(n.contentElement):typeof n.contentElement=="function"?c=n.contentElement(e):n.contentElement&&(c=n.contentElement),this.findAround(e,c,!0),this.addAll(c)}r&&this.sync(a)&&this.open--,l&&this.removePendingMark(l,a)}addAll(e,n,o){let r=n||0;for(let i=n?e.childNodes[n]:e.firstChild,l=o==null?null:e.childNodes[o];i!=l;i=i.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(i);this.findAtPoint(e,r)}findPlace(e){let n,o;for(let r=this.open;r>=0;r--){let i=this.nodes[r],l=i.findWrapping(e);if(l&&(!n||n.length>l.length)&&(n=l,o=i,!l.length)||i.solid)break}if(!n)return!1;this.sync(o);for(let r=0;r<n.length;r++)this.enterInner(n[r],null,!1);return!0}insertNode(e){if(e.isInline&&this.needsBlock&&!this.top.type){let n=this.textblockFromContext();n&&this.enterInner(n)}if(this.findPlace(e)){this.closeExtra();let n=this.top;n.applyPending(e.type),n.match&&(n.match=n.match.matchType(e.type));let o=n.activeMarks;for(let r=0;r<e.marks.length;r++)(!n.type||n.type.allowsMarkType(e.marks[r].type))&&(o=e.marks[r].addToSet(o));return n.content.push(e.mark(o)),!0}return!1}enter(e,n,o){let r=this.findPlace(e.create(n));return r&&this.enterInner(e,n,!0,o),r}enterInner(e,n=null,o=!1,r){this.closeExtra();let i=this.top;i.applyPending(e),i.match=i.match&&i.match.matchType(e);let l=xf(e,r,i.options);i.options&Kr&&i.content.length==0&&(l|=Kr),this.nodes.push(new ss(e,n,i.activeMarks,i.pendingMarks,o,null,l)),this.open++}closeExtra(e=!1){let n=this.nodes.length-1;if(n>this.open){for(;n>this.open;n--)this.nodes[n-1].content.push(this.nodes[n].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 n=this.open;n>=0;n--)if(this.nodes[n]==e)return this.open=n,!0;return!1}get currentPos(){this.closeExtra();let e=0;for(let n=this.open;n>=0;n--){let o=this.nodes[n].content;for(let r=o.length-1;r>=0;r--)e+=o[r].nodeSize;n&&e++}return e}findAtPoint(e,n){if(this.find)for(let o=0;o<this.find.length;o++)this.find[o].node==e&&this.find[o].offset==n&&(this.find[o].pos=this.currentPos)}findInside(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].pos==null&&e.nodeType==1&&e.contains(this.find[n].node)&&(this.find[n].pos=this.currentPos)}findAround(e,n,o){if(e!=n&&this.find)for(let r=0;r<this.find.length;r++)this.find[r].pos==null&&e.nodeType==1&&e.contains(this.find[r].node)&&n.compareDocumentPosition(this.find[r].node)&(o?2:4)&&(this.find[r].pos=this.currentPos)}findInText(e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&(this.find[n].pos=this.currentPos-(e.nodeValue.length-this.find[n].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let n=e.split("/"),o=this.options.context,r=!this.isOpen&&(!o||o.parent.type==this.nodes[0].type),i=-(o?o.depth+1:0)+(r?0:1),l=(a,c)=>{for(;a>=0;a--){let u=n[a];if(u==""){if(a==n.length-1||a==0)continue;for(;c>=i;c--)if(l(a-1,c))return!0;return!1}else{let d=c>0||c==0&&r?this.nodes[c].type:o&&c>=i?o.node(c-i).type:null;if(!d||d.name!=u&&d.groups.indexOf(u)==-1)return!1;c--}}return!0};return l(n.length-1,this.open)}textblockFromContext(){let e=this.options.context;if(e)for(let n=e.depth;n>=0;n--){let o=e.node(n).contentMatchAt(e.indexAfter(n)).defaultType;if(o&&o.isTextblock&&o.defaultAttrs)return o}for(let n in this.parser.schema.nodes){let o=this.parser.schema.nodes[n];if(o.isTextblock&&o.defaultAttrs)return o}}addPendingMark(e){let n=B4(e,this.top.pendingMarks);n&&this.top.stashMarks.push(n),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,n){for(let o=this.open;o>=0;o--){let r=this.nodes[o];if(r.pendingMarks.lastIndexOf(e)>-1)r.pendingMarks=e.removeFromSet(r.pendingMarks);else{r.activeMarks=e.removeFromSet(r.activeMarks);let l=r.popFromStashMark(e);l&&r.type&&r.type.allowsMarkType(l.type)&&(r.activeMarks=l.addToSet(r.activeMarks))}if(r==n)break}}}function x4(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let o=e.nodeType==1?e.nodeName.toLowerCase():null;o&&Af.hasOwnProperty(o)&&n?(n.appendChild(e),e=n):o=="li"?n=e:o&&(n=null)}}function M4(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function Df(t){let e={};for(let n in t)e[n]=t[n];return e}function D4(t,e){let n=e.schema.nodes;for(let o in n){let r=n[o];if(!r.allowsMarkType(t))continue;let i=[],l=a=>{i.push(a);for(let c=0;c<a.edgeCount;c++){let{type:u,next:d}=a.edge(c);if(u==e||i.indexOf(d)<0&&l(d))return!0}};if(l(r.contentMatch))return!0}}function B4(t,e){for(let n=0;n<e.length;n++)if(t.eq(e[n]))return e[n]}class nn{constructor(e,n){this.nodes=e,this.marks=n}serializeFragment(e,n={},o){o||(o=Ra(n).createDocumentFragment());let r=o,i=[];return e.forEach(l=>{if(i.length||l.marks.length){let a=0,c=0;for(;a<i.length&&c<l.marks.length;){let u=l.marks[c];if(!this.marks[u.type.name]){c++;continue}if(!u.eq(i[a][0])||u.type.spec.spanning===!1)break;a++,c++}for(;a<i.length;)r=i.pop()[1];for(;c<l.marks.length;){let u=l.marks[c++],d=this.serializeMark(u,l.isInline,n);d&&(i.push([u,r]),r.appendChild(d.dom),r=d.contentDOM||d.dom)}}r.appendChild(this.serializeNodeInner(l,n))}),o}serializeNodeInner(e,n){let{dom:o,contentDOM:r}=nn.renderSpec(Ra(n),this.nodes[e.type.name](e));if(r){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,n,r)}return o}serializeNode(e,n={}){let o=this.serializeNodeInner(e,n);for(let r=e.marks.length-1;r>=0;r--){let i=this.serializeMark(e.marks[r],e.isInline,n);i&&((i.contentDOM||i.dom).appendChild(o),o=i.dom)}return o}serializeMark(e,n,o={}){let r=this.marks[e.type.name];return r&&nn.renderSpec(Ra(o),r(e,n))}static renderSpec(e,n,o=null){if(typeof n=="string")return{dom:e.createTextNode(n)};if(n.nodeType!=null)return{dom:n};if(n.dom&&n.dom.nodeType!=null)return n;let r=n[0],i=r.indexOf(" ");i>0&&(o=r.slice(0,i),r=r.slice(i+1));let l,a=o?e.createElementNS(o,r):e.createElement(r),c=n[1],u=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){u=2;for(let d in c)if(c[d]!=null){let f=d.indexOf(" ");f>0?a.setAttributeNS(d.slice(0,f),d.slice(f+1),c[d]):a.setAttribute(d,c[d])}}for(let d=u;d<n.length;d++){let f=n[d];if(f===0){if(d<n.length-1||d>u)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}else{let{dom:p,contentDOM:m}=nn.renderSpec(e,f,o);if(a.appendChild(p),m){if(l)throw new RangeError("Multiple content holes");l=m}}}return{dom:a,contentDOM:l}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new nn(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let n=Bf(e.nodes);return n.text||(n.text=o=>o.text),n}static marksFromSchema(e){return Bf(e.marks)}}function Bf(t){let e={};for(let n in t){let o=t[n].spec.toDOM;o&&(e[n]=o)}return e}function Ra(t){return t.document||window.document}const Of=65535,Nf=Math.pow(2,16);function O4(t,e){return t+e*Nf}function If(t){return t&Of}function N4(t){return(t-(t&Of))/Nf}const $f=1,Lf=2,ls=4,Rf=8;class Pa{constructor(e,n,o){this.pos=e,this.delInfo=n,this.recover=o}get deleted(){return(this.delInfo&Rf)>0}get deletedBefore(){return(this.delInfo&($f|ls))>0}get deletedAfter(){return(this.delInfo&(Lf|ls))>0}get deletedAcross(){return(this.delInfo&ls)>0}}class vt{constructor(e,n=!1){if(this.ranges=e,this.inverted=n,!e.length&&vt.empty)return vt.empty}recover(e){let n=0,o=If(e);if(!this.inverted)for(let r=0;r<o;r++)n+=this.ranges[r*3+2]-this.ranges[r*3+1];return this.ranges[o*3]+n+N4(e)}mapResult(e,n=1){return this._map(e,n,!1)}map(e,n=1){return this._map(e,n,!0)}_map(e,n,o){let r=0,i=this.inverted?2:1,l=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let c=this.ranges[a]-(this.inverted?r:0);if(c>e)break;let u=this.ranges[a+i],d=this.ranges[a+l],f=c+u;if(e<=f){let p=u?e==c?-1:e==f?1:n:n,m=c+r+(p<0?0:d);if(o)return m;let h=e==(n<0?c:f)?null:O4(a/3,e-c),g=e==c?Lf:e==f?$f:ls;return(n<0?e!=c:e!=f)&&(g|=Rf),new Pa(m,g,h)}r+=d-u}return o?e+r:new Pa(e+r,0,null)}touches(e,n){let o=0,r=If(n),i=this.inverted?2:1,l=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let c=this.ranges[a]-(this.inverted?o:0);if(c>e)break;let u=this.ranges[a+i],d=c+u;if(e<=d&&a==r*3)return!0;o+=this.ranges[a+l]-u}return!1}forEach(e){let n=this.inverted?2:1,o=this.inverted?1:2;for(let r=0,i=0;r<this.ranges.length;r+=3){let l=this.ranges[r],a=l-(this.inverted?i:0),c=l+(this.inverted?0:i),u=this.ranges[r+n],d=this.ranges[r+o];e(a,a+u,c,c+d),i+=d-u}}invert(){return new vt(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return e==0?vt.empty:new vt(e<0?[0,-e,0]:[0,0,e])}}vt.empty=new vt([]);class Qo{constructor(e=[],n,o=0,r=e.length){this.maps=e,this.mirror=n,this.from=o,this.to=r}slice(e=0,n=this.maps.length){return new Qo(this.maps,this.mirror,e,n)}copy(){return new Qo(this.maps.slice(),this.mirror&&this.mirror.slice(),this.from,this.to)}appendMap(e,n){this.to=this.maps.push(e),n!=null&&this.setMirror(this.maps.length-1,n)}appendMapping(e){for(let n=0,o=this.maps.length;n<e.maps.length;n++){let r=e.getMirror(n);this.appendMap(e.maps[n],r!=null&&r<n?o+r:void 0)}}getMirror(e){if(this.mirror){for(let n=0;n<this.mirror.length;n++)if(this.mirror[n]==e)return this.mirror[n+(n%2?-1:1)]}}setMirror(e,n){this.mirror||(this.mirror=[]),this.mirror.push(e,n)}appendMappingInverted(e){for(let n=e.maps.length-1,o=this.maps.length+e.maps.length;n>=0;n--){let r=e.getMirror(n);this.appendMap(e.maps[n].invert(),r!=null&&r>n?o-r-1:void 0)}}invert(){let e=new Qo;return e.appendMappingInverted(this),e}map(e,n=1){if(this.mirror)return this._map(e,n,!0);for(let o=this.from;o<this.to;o++)e=this.maps[o].map(e,n);return e}mapResult(e,n=1){return this._map(e,n,!1)}_map(e,n,o){let r=0;for(let i=this.from;i<this.to;i++){let l=this.maps[i],a=l.mapResult(e,n);if(a.recover!=null){let c=this.getMirror(i);if(c!=null&&c>i&&c<this.to){i=c,e=this.maps[c].recover(a.recover);continue}}r|=a.delInfo,e=a.pos}return o?e:new Pa(e,r,null)}}const Fa=Object.create(null);class nt{getMap(){return vt.empty}merge(e){return null}static fromJSON(e,n){if(!n||!n.stepType)throw new RangeError("Invalid input for Step.fromJSON");let o=Fa[n.stepType];if(!o)throw new RangeError(`No step type ${n.stepType} defined`);return o.fromJSON(e,n)}static jsonID(e,n){if(e in Fa)throw new RangeError("Duplicate use of step JSON ID "+e);return Fa[e]=n,n.prototype.jsonID=e,n}}class Re{constructor(e,n){this.doc=e,this.failed=n}static ok(e){return new Re(e,null)}static fail(e){return new Re(null,e)}static fromReplace(e,n,o,r){try{return Re.ok(e.replace(n,o,r))}catch(i){if(i instanceof Xi)return Re.fail(i.message);throw i}}}function za(t,e,n){let o=[];for(let r=0;r<t.childCount;r++){let i=t.child(r);i.content.size&&(i=i.copy(za(i.content,e,i))),i.isInline&&(i=e(i,n,r)),o.push(i)}return O.fromArray(o)}class Pn extends nt{constructor(e,n,o){super(),this.from=e,this.to=n,this.mark=o}apply(e){let n=e.slice(this.from,this.to),o=e.resolve(this.from),r=o.node(o.sharedDepth(this.to)),i=new P(za(n.content,(l,a)=>!l.isAtom||!a.type.allowsMarkType(this.mark.type)?l:l.mark(this.mark.addToSet(l.marks)),r),n.openStart,n.openEnd);return Re.fromReplace(e,this.from,this.to,i)}invert(){return new on(this.from,this.to,this.mark)}map(e){let n=e.mapResult(this.from,1),o=e.mapResult(this.to,-1);return n.deleted&&o.deleted||n.pos>=o.pos?null:new Pn(n.pos,o.pos,this.mark)}merge(e){return e instanceof Pn&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new Pn(Math.min(this.from,e.fro