medium-proeditor
Version:
A powerful & customizable Medium-style rich text editor
1 lines • 396 kB
JavaScript
!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).CommonFeatures={})}(this,(function(e){"use strict";function t(e){return"Object"===function(e){return Object.prototype.toString.call(e).slice(8,-1)}(e)&&(e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype)}function n(e,i){const o={...e};if(t(e)&&t(i))for(const a of Object.keys(i))t(i[a])&&t(e[a])?o[a]=n(e[a],i[a]):o[a]=i[a];return o}class i{config;options;storage;constructor(e){this.config={...e},e.addOptions&&(this.options=e.addOptions.call({name:e.name})),e.addStorage&&(this.storage=e.addStorage.call({name:e.name,options:this.options}))}static create(e){return new i(e)}configure(e={}){return new i({...this.config,addOptions:()=>n(this.options,e)})}}function o(e,t,n){for(let i=0;;i++){if(i==e.childCount||i==t.childCount)return e.childCount==t.childCount?null:n;let a=e.child(i),r=t.child(i);if(a!=r){if(!a.sameMarkup(r))return n;if(a.isText&&a.text!=r.text){for(let e=0;a.text[e]==r.text[e];e++)n++;return n}if(a.content.size||r.content.size){let e=o(a.content,r.content,n+1);if(null!=e)return e}n+=a.nodeSize}else n+=a.nodeSize}}function a(e,t,n,i){for(let o=e.childCount,r=t.childCount;;){if(0==o||0==r)return o==r?null:{a:n,b:i};let s=e.child(--o),l=t.child(--r),c=s.nodeSize;if(s!=l){if(!s.sameMarkup(l))return{a:n,b:i};if(s.isText&&s.text!=l.text){let e=0,t=Math.min(s.text.length,l.text.length);for(;e<t&&s.text[s.text.length-e-1]==l.text[l.text.length-e-1];)e++,n--,i--;return{a:n,b:i}}if(s.content.size||l.content.size){let e=a(s.content,l.content,n-1,i-1);if(e)return e}n-=c,i-=c}else n-=c,i-=c}}class r{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 a=0,r=0;r<t;a++){let s=this.content[a],l=r+s.nodeSize;if(l>e&&!1!==n(s,i+r,o||null,a)&&s.content.size){let o=r+1;s.nodesBetween(Math.max(0,e-o),Math.min(s.content.size,t-o),n,i+o)}r=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let o="",a=!0;return this.nodesBetween(e,t,((r,s)=>{let l=r.isText?r.text.slice(Math.max(e,s)-s,t-s):r.isLeaf?i?"function"==typeof i?i(r):i:r.type.spec.leafText?r.type.spec.leafText(r):"":"";r.isBlock&&(r.isLeaf&&l||r.isTextblock)&&n&&(a?a=!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(),o=0;for(t.isText&&t.sameMarkup(n)&&(i[i.length-1]=t.withText(t.text+n.text),o=1);o<e.content.length;o++)i.push(e.content[o]);return new r(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,a=0;a<t;o++){let r=this.content[o],s=a+r.nodeSize;s>e&&((a<e||s>t)&&(r=r.isText?r.cut(Math.max(0,e-a),Math.min(r.text.length,t-a)):r.cut(Math.max(0,e-a-1),Math.min(r.content.size,t-a-1))),n.push(r),i+=r.nodeSize),a=s}return new r(n,i)}cutByIndex(e,t){return e==t?r.empty:0==e&&t==this.content.length?this:new r(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let i=this.content.slice(),o=this.size+t.nodeSize-n.nodeSize;return i[e]=t,new r(i,o)}addToStart(e){return new r([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new r(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 o(this,e,t)}findDiffEnd(e,t=this.size,n=e.size){return a(this,e,t,n)}findIndex(e,t=-1){if(0==e)return l(0,e);if(e==this.size)return l(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?l(n+1,o):l(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 r.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new r(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return r.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 r(t||e,n)}static from(e){if(!e)return r.empty;if(e instanceof r)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new r([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}r.empty=new r([],0);const s={index:0,offset:0};function l(e,t){return s.index=e,s.offset=t,s}function c(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(!c(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!c(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class m{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&&c(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 m.none;if(e instanceof m)return[e];let t=e.slice();return t.sort(((e,t)=>e.type.rank-t.type.rank)),t}}m.none=[];class d extends Error{}class u{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=p(this.content,e+this.openStart,t);return n&&new u(n,this.openStart,this.openEnd)}removeBetween(e,t){return new u(h(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 u.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 u(r.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 u(e,n,i)}}function h(e,t,n){let{index:i,offset:o}=e.findIndex(t),a=e.maybeChild(i),{index:r,offset:s}=e.findIndex(n);if(o==t||a.isText){if(s!=n&&!e.child(r).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(i!=r)throw new RangeError("Removing non-flat range");return e.replaceChild(i,a.copy(h(a.content,t-o-1,n-o-1)))}function p(e,t,n,i){let{index:o,offset:a}=e.findIndex(t),r=e.maybeChild(o);if(a==t||r.isText)return i&&!i.canReplace(o,o,n)?null:e.cut(0,t).append(n).append(e.cut(t));let s=p(r.content,t-a-1,n);return s&&e.replaceChild(o,r.copy(s))}u.empty=new u(r.empty,0,0);class f{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 g{constructor(e,t,n,i){this.name=e,this.rank=t,this.schema=n,this.spec=i,this.attrs=function(e,t){let n=Object.create(null);if(t)for(let i in t)n[i]=new f(e,i,t[i]);return n}(e,i.attrs),this.excluded=null;let o=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}(this.attrs);this.instance=o?new m(this,o):null}create(e=null){return!e&&this.instance?this.instance:new m(this,function(e,t){let n=Object.create(null);for(let i in e){let o=t&&t[i];if(void 0===o){let t=e[i];if(!t.hasDefault)throw new RangeError("No value supplied for attribute "+i);o=t.default}n[i]=o}return n}(this.attrs,e))}static compile(e,t){let n=Object.create(null),i=0;return e.forEach(((e,o)=>n[e]=new g(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){!function(e,t,n){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])}}(this.attrs,e,"mark",this.name)}excludes(e){return this.excluded.indexOf(e)>-1}}class b{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 k(this,t,!1);return n.addAll(e,m.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new k(this,t,!0);return n.addAll(e,m.none,t.from,t.to),u.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(E(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],a=i.style;if(!(0!=a.indexOf(e)||i.context&&!n.matchesContext(i.context)||a.length>e.length&&(61!=a.charCodeAt(e.length)||a.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=x(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=x(e)),e.node||e.ignore||e.mark||(e.node=t)}))}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new b(e,b.schemaRules(e)))}}const _={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},y={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},w={ol:!0,ul:!0};function j(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class v{constructor(e,t,n,i,o,a){this.type=e,this.attrs=t,this.marks=n,this.solid=i,this.options=a,this.content=[],this.activeMarks=m.none,this.match=o||(4&a?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(r.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=r.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(r.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&&!_.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class k{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let i,o=t.topNode,a=j(null,t.preserveWhitespace,0)|(n?4:0);i=o?new v(o.type,o.attrs,m.none,!0,t.topMatch||o.type.contentMatch,a):new v(n?null:e.schema.topNodeType,null,m.none,!0,null,a),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 a,r=e.nodeName.toLowerCase();w.hasOwnProperty(r)&&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&&w.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let s=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,n));e:if(s?s.ignore:y.hasOwnProperty(r))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let n,i=this.needsBlock;if(_.hasOwnProperty(r))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 a=s&&s.skip?t:this.readStyles(e,t);a&&this.addAll(e,a),n&&this.sync(o),this.needsBlock=i}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,s,n,!1===s.consuming?a: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,a;if(t.node)if(a=this.parser.schema.nodes[t.node],a.isLeaf)this.insertNode(a.create(t.attrs),n)||this.leafFallback(e,n);else{let e=this.enter(a,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 r=this.top;if(a&&a.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(r)&&this.open--}addAll(e,t,n,i){let o=n||0;for(let a=n?e.childNodes[n]:e.firstChild,r=null==i?null:e.childNodes[i];a!=r;a=a.nextSibling,++o)this.findAtPoint(e,o),this.addDOM(a,t);this.findAtPoint(e,o)}findPlace(e,t){let n,i;for(let t=this.open;t>=0;t--){let o=this.nodes[t],a=o.findWrapping(e);if(a&&(!n||n.length>a.length)&&(n=a,i=o,!a.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=m.none;for(let o of n.concat(e.marks))(t.type?t.type.allowsMarkType(o.type):N(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 a=this.top;a.match=a.match&&a.match.matchType(e);let r=j(e,o,a.options);4&a.options&&0==a.content.length&&(r|=4);let s=m.none;return n=n.filter((t=>!(a.type?a.type.allowsMarkType(t.type):N(t.type,e))||(s=t.addToSet(s),!1))),this.nodes.push(new v(e,t,s,i,null,r)),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),a=(e,r)=>{for(;e>=0;e--){let s=t[e];if(""==s){if(e==t.length-1||0==e)continue;for(;r>=o;r--)if(a(e-1,r))return!0;return!1}{let e=r>0||0==r&&i?this.nodes[r].type:n&&r>=o?n.node(r-o).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;r--}}return!0};return a(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 E(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function x(e){let t={};for(let n in e)t[n]=e[n];return t}function N(e,t){let n=t.schema.nodes;for(let i in n){let o=n[i];if(!o.allowsMarkType(e))continue;let a=[],r=e=>{a.push(e);for(let n=0;n<e.edgeCount;n++){let{type:i,next:o}=e.edge(n);if(i==t)return!0;if(a.indexOf(o)<0&&r(o))return!0}};if(r(o.contentMatch))return!0}}class S{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=M(t).createDocumentFragment());let i=n,o=[];return e.forEach((e=>{if(o.length||e.marks.length){let n=0,a=0;for(;n<o.length&&a<e.marks.length;){let t=e.marks[a];if(this.marks[t.type.name]){if(!t.eq(o[n][0])||!1===t.type.spec.spanning)break;n++,a++}else a++}for(;n<o.length;)i=o.pop()[1];for(;a<e.marks.length;){let n=e.marks[a++],r=this.serializeMark(n,e.isInline,t);r&&(o.push([n,i]),i.appendChild(r.dom),i=r.contentDOM||r.dom)}}i.appendChild(this.serializeNodeInner(e,t))})),n}serializeNodeInner(e,t){let{dom:n,contentDOM:i}=T(M(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&&T(M(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return T(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new S(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=C(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return C(e.marks)}}function C(e){let t={};for(let n in e){let i=e[n].spec.toDOM;i&&(t[n]=i)}return t}function M(e){return e.document||window.document}const O=new WeakMap;function A(e){let t=O.get(e);return void 0===t&&O.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 T(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,a=t[0];if("string"!=typeof a)throw new RangeError("Invalid array passed to renderSpec");if(i&&(o=A(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 r,s=a.indexOf(" ");s>0&&(n=a.slice(0,s),a=a.slice(s+1));let l=n?e.createElementNS(n,a):e.createElement(a),c=t[1],m=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){m=2;for(let e in c)if(null!=c[e]){let t=e.indexOf(" ");t>0?l.setAttributeNS(e.slice(0,t),e.slice(t+1),c[e]):l.setAttribute(e,c[e])}}for(let o=m;o<t.length;o++){let a=t[o];if(0===a){if(o<t.length-1||o>m)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:t,contentDOM:o}=T(e,a,n,i);if(l.appendChild(t),o){if(r)throw new RangeError("Multiple content holes");r=o}}}return{dom:l,contentDOM:r}}const R=Math.pow(2,16);function I(e,t){return e+t*R}function D(e){return 65535&e}class L{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 z{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&z.empty)return z.empty}recover(e){let t=0,n=D(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))/R}(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,a=this.inverted?1:2;for(let r=0;r<this.ranges.length;r+=3){let s=this.ranges[r]-(this.inverted?i:0);if(s>e)break;let l=this.ranges[r+o],c=this.ranges[r+a],m=s+l;if(e<=m){let o=s+i+((l?e==s?-1:e==m?1:t:t)<0?0:c);if(n)return o;let a=e==(t<0?s:m)?null:I(r/3,e-s),d=e==s?2:e==m?1:4;return(t<0?e!=s:e!=m)&&(d|=8),new L(o,d,a)}i+=c-l}return n?e+i:new L(e+i,0,null)}touches(e,t){let n=0,i=D(t),o=this.inverted?2:1,a=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let r=this.ranges[t]-(this.inverted?n:0);if(r>e)break;let s=this.ranges[t+o];if(e<=r+s&&t==3*i)return!0;n+=this.ranges[t+a]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let i=0,o=0;i<this.ranges.length;i+=3){let a=this.ranges[i],r=a-(this.inverted?o:0),s=a+(this.inverted?0:o),l=this.ranges[i+t],c=this.ranges[i+n];e(r,r+l,s,s+c),o+=c-l}}invert(){return new z(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?z.empty:new z(e<0?[0,-e,0]:[0,0,e])}}z.empty=new z([]);class B{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 B(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 B;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 L(e,i,null)}}const $=Object.create(null);class F{getMap(){return z.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=$[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 $)throw new RangeError("Duplicate use of step JSON ID "+e);return $[e]=t,t.prototype.jsonID=e,t}}class P{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new P(e,null)}static fail(e){return new P(null,e)}static fromReplace(e,t,n,i){try{return P.ok(e.replace(t,n,i))}catch(e){if(e instanceof d)return P.fail(e.message);throw e}}}function H(e,t,n){let i=[];for(let o=0;o<e.childCount;o++){let a=e.child(o);a.content.size&&(a=a.copy(H(a.content,t,a))),a.isInline&&(a=t(a,n,o)),i.push(a)}return r.fromArray(i)}class U extends F{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 u(H(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 P.fromReplace(e,this.from,this.to,o)}invert(){return new q(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new U(t.pos,n.pos,this.mark)}merge(e){return e instanceof U&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new U(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new U(t.from,t.to,e.markFromJSON(t.mark))}}F.jsonID("addMark",U);class q extends F{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new u(H(t.content,(e=>e.mark(this.mark.removeFromSet(e.marks))),e),t.openStart,t.openEnd);return P.fromReplace(e,this.from,this.to,n)}invert(){return new U(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deleted&&n.deleted||t.pos>=n.pos?null:new q(t.pos,n.pos,this.mark)}merge(e){return e instanceof q&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new q(Math.min(this.from,e.from),Math.max(this.to,e.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new q(t.from,t.to,e.markFromJSON(t.mark))}}F.jsonID("removeMark",q);class K extends F{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return P.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return P.fromReplace(e,this.pos,this.pos+1,new u(r.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new K(this.pos,t.marks[n]);return new K(this.pos,this.mark)}}return new W(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new K(t.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new K(t.pos,e.markFromJSON(t.mark))}}F.jsonID("addNodeMark",K);class W extends F{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return P.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return P.fromReplace(e,this.pos,this.pos+1,new u(r.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new K(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new W(t.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(e,t){if("number"!=typeof t.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new W(t.pos,e.markFromJSON(t.mark))}}F.jsonID("removeNodeMark",W);class G extends F{constructor(e,t,n,i=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=i}apply(e){return this.structure&&V(e,this.from,this.to)?P.fail("Structure replace would overwrite content"):P.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new z([this.from,this.to-this.from,this.slice.size])}invert(e){return new G(this.from,this.from+this.slice.size,e.slice(this.from,this.to))}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1);return t.deletedAcross&&n.deletedAcross?null:new G(t.pos,Math.max(t.pos,n.pos),this.slice)}merge(e){if(!(e instanceof G)||e.structure||this.structure)return null;if(this.from+this.slice.size!=e.from||this.slice.openEnd||e.slice.openStart){if(e.to!=this.from||this.slice.openStart||e.slice.openEnd)return null;{let t=this.slice.size+e.slice.size==0?u.empty:new u(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new G(e.from,this.to,t,this.structure)}}{let t=this.slice.size+e.slice.size==0?u.empty:new u(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new G(this.from,this.to+(e.to-e.from),t,this.structure)}}toJSON(){let e={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new G(t.from,t.to,u.fromJSON(e,t.slice),!!t.structure)}}F.jsonID("replace",G);class Z extends F{constructor(e,t,n,i,o,a,r=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=i,this.slice=o,this.insert=a,this.structure=r}apply(e){if(this.structure&&(V(e,this.from,this.gapFrom)||V(e,this.gapTo,this.to)))return P.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return P.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?P.fromReplace(e,this.from,this.to,n):P.fail("Content does not fit in gap")}getMap(){return new z([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(e){let t=this.gapTo-this.gapFrom;return new Z(this.from,this.from+this.slice.size+t,this.from+this.insert,this.from+this.insert+t,e.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(e){let t=e.mapResult(this.from,1),n=e.mapResult(this.to,-1),i=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),o=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||i<t.pos||o>n.pos?null:new Z(t.pos,n.pos,i,o,this.slice,this.insert,this.structure)}toJSON(){let e={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(e.slice=this.slice.toJSON()),this.structure&&(e.structure=!0),e}static fromJSON(e,t){if("number"!=typeof t.from||"number"!=typeof t.to||"number"!=typeof t.gapFrom||"number"!=typeof t.gapTo||"number"!=typeof t.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new Z(t.from,t.to,t.gapFrom,t.gapTo,u.fromJSON(e,t.slice),t.insert,!!t.structure)}}function V(e,t,n){let i=e.resolve(t),o=n-t,a=i.depth;for(;o>0&&a>0&&i.indexAfter(a)==i.node(a).childCount;)a--,o--;if(o>0){let e=i.node(a).maybeChild(i.indexAfter(a));for(;o>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,o--}}return!1}function J(e,t,n,i=n.contentMatch,o=!0){let a=e.doc.nodeAt(t),s=[],l=t+1;for(let t=0;t<a.childCount;t++){let c=a.child(t),m=l+c.nodeSize,d=i.matchType(c.type);if(d){i=d;for(let t=0;t<c.marks.length;t++)n.allowsMarkType(c.marks[t].type)||e.step(new q(l,m,c.marks[t]));if(o&&c.isText&&"pre"!=n.whitespace){let e,t,i=/\r?\n|\r/g;for(;e=i.exec(c.text);)t||(t=new u(r.from(n.schema.text(" ",n.allowedMarks(c.marks))),0,0)),s.push(new G(l+e.index,l+e.index+e[0].length,t))}}else s.push(new G(l,m,u.empty));l=m}if(!i.validEnd){let t=i.fillBefore(r.empty,!0);e.replace(l,l,new u(t,0,0))}for(let t=s.length-1;t>=0;t--)e.step(s[t])}function X(e,t,n,i){t.forEach(((o,a)=>{if(o.isText){let r,s=/\r?\n|\r/g;for(;r=s.exec(o.text);){let o=e.mapping.slice(i).map(n+1+a+r.index);e.replaceWith(o,o+1,t.type.schema.linebreakReplacement.create())}}}))}function Q(e,t,n,i){t.forEach(((o,a)=>{if(o.type==o.type.schema.linebreakReplacement){let o=e.mapping.slice(i).map(n+1+a);e.replaceWith(o,o+1,t.type.schema.text("\n"))}}))}function Y(e,t,n){return!n.openStart&&!n.openEnd&&e.start()==t.start()&&e.parent.canReplace(e.index(),t.index(),n.content)}F.jsonID("replaceAround",Z);class ee{constructor(e,t,n){this.$from=e,this.$to=t,this.unplaced=n,this.frontier=[],this.placed=r.empty;for(let t=0;t<=e.depth;t++){let n=e.node(t);this.frontier.push({type:n.type,match:n.contentMatchAt(e.indexAfter(t))})}for(let t=e.depth;t>0;t--)this.placed=r.from(e.node(t).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let e=this.findFittable();e?this.placeNodes(e):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,n=this.$from,i=this.close(e<0?this.$to:n.doc.resolve(e));if(!i)return null;let o=this.placed,a=n.depth,r=i.depth;for(;a&&r&&1==o.childCount;)o=o.firstChild.content,a--,r--;let s=new u(o,a,r);return e>-1?new Z(n.pos,e,this.$to.pos,this.$to.end(),s,t):s.size||n.pos!=this.$to.pos?new G(n.pos,i.pos,s):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,n=0,i=this.unplaced.openEnd;n<e;n++){let o=t.firstChild;if(t.childCount>1&&(i=0),o.type.spec.isolating&&i<=n){e=n;break}t=o.content}for(let t=1;t<=2;t++)for(let n=1==t?e:this.unplaced.openStart;n>=0;n--){let e,i=null;n?(i=ie(this.unplaced.content,n-1).firstChild,e=i.content):e=this.unplaced.content;let o=e.firstChild;for(let e=this.depth;e>=0;e--){let a,{type:s,match:l}=this.frontier[e],c=null;if(1==t&&(o?l.matchType(o.type)||(c=l.fillBefore(r.from(o),!1)):i&&s.compatibleContent(i.type)))return{sliceDepth:n,frontierDepth:e,parent:i,inject:c};if(2==t&&o&&(a=l.findWrapping(o.type)))return{sliceDepth:n,frontierDepth:e,parent:i,wrap:a};if(i&&l.matchType(i.type))break}}}openMore(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=ie(e,t);return!(!i.childCount||i.firstChild.isLeaf)&&(this.unplaced=new u(e,t+1,Math.max(n,i.size+t>=e.size-n?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:n}=this.unplaced,i=ie(e,t);if(i.childCount<=1&&t>0){let o=e.size-t<=t+i.size;this.unplaced=new u(te(e,t-1,1),t-1,o?t-1:n)}else this.unplaced=new u(te(e,t,1),t,n)}placeNodes({sliceDepth:e,frontierDepth:t,parent:n,inject:i,wrap:o}){for(;this.depth>t;)this.closeFrontierNode();if(o)for(let e=0;e<o.length;e++)this.openFrontierNode(o[e]);let a=this.unplaced,s=n?n.content:a.content,l=a.openStart-e,c=0,m=[],{match:d,type:h}=this.frontier[t];if(i){for(let e=0;e<i.childCount;e++)m.push(i.child(e));d=d.matchFragment(i)}let p=s.size+e-(a.content.size-a.openEnd);for(;c<s.childCount;){let e=s.child(c),t=d.matchType(e.type);if(!t)break;c++,(c>1||0==l||e.content.size)&&(d=t,m.push(oe(e.mark(h.allowedMarks(e.marks)),1==c?l:0,c==s.childCount?p:-1)))}let f=c==s.childCount;f||(p=-1),this.placed=ne(this.placed,t,r.from(m)),this.frontier[t].match=d,f&&p<0&&n&&n.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let e=0,t=s;e<p;e++){let e=t.lastChild;this.frontier.push({type:e.type,match:e.contentMatchAt(e.childCount)}),t=e.content}this.unplaced=f?0==e?u.empty:new u(te(a.content,e-1,1),e-1,p<0?a.openEnd:e-1):new u(te(a.content,e,c),a.openStart,a.openEnd)}mustMoveInline(){if(!this.$to.parent.isTextblock)return-1;let e,t=this.frontier[this.depth];if(!t.type.isTextblock||!ae(this.$to,this.$to.depth,t.type,t.match,!1)||this.$to.depth==this.depth&&(e=this.findCloseLevel(this.$to))&&e.depth==this.depth)return-1;let{depth:n}=this.$to,i=this.$to.after(n);for(;n>1&&i==this.$to.end(--n);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:n,type:i}=this.frontier[t],o=t<e.depth&&e.end(t+1)==e.pos+(e.depth-(t+1)),a=ae(e,t,i,n,o);if(a){for(let n=t-1;n>=0;n--){let{match:t,type:i}=this.frontier[n],o=ae(e,n,i,t,!0);if(!o||o.childCount)continue e}return{depth:t,fit:a,move:o?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=ne(this.placed,t.depth,t.fit)),e=t.move;for(let n=t.depth+1;n<=e.depth;n++){let t=e.node(n),i=t.type.contentMatch.fillBefore(t.content,!0,e.index(n));this.openFrontierNode(t.type,t.attrs,i)}return e}openFrontierNode(e,t=null,n){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=ne(this.placed,this.depth,r.from(e.create(t,n))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let e=this.frontier.pop().match.fillBefore(r.empty,!0);e.childCount&&(this.placed=ne(this.placed,this.frontier.length,e))}}function te(e,t,n){return 0==t?e.cutByIndex(n,e.childCount):e.replaceChild(0,e.firstChild.copy(te(e.firstChild.content,t-1,n)))}function ne(e,t,n){return 0==t?e.append(n):e.replaceChild(e.childCount-1,e.lastChild.copy(ne(e.lastChild.content,t-1,n)))}function ie(e,t){for(let n=0;n<t;n++)e=e.firstChild.content;return e}function oe(e,t,n){if(t<=0)return e;let i=e.content;return t>1&&(i=i.replaceChild(0,oe(i.firstChild,t-1,1==i.childCount?n-1:0))),t>0&&(i=e.type.contentMatch.fillBefore(i).append(i),n<=0&&(i=i.append(e.type.contentMatch.matchFragment(i).fillBefore(r.empty,!0)))),e.copy(i)}function ae(e,t,n,i,o){let a=e.node(t),r=o?e.indexAfter(t):e.index(t);if(r==a.childCount&&!n.compatibleContent(a.type))return null;let s=i.fillBefore(a.content,!0,r);return s&&!function(e,t,n){for(let i=n;i<t.childCount;i++)if(!e.allowsMarks(t.child(i).marks))return!0;return!1}(n,a.content,r)?s:null}function re(e,t,n,i,o){if(t<n){let o=e.firstChild;e=e.replaceChild(0,o.copy(re(o.content,t+1,n,i,o)))}if(t>i){let t=o.contentMatchAt(0),n=t.fillBefore(e).append(e);e=n.append(t.matchFragment(n).fillBefore(r.empty,!0))}return e}function se(e,t){let n=[];for(let i=Math.min(e.depth,t.depth);i>=0;i--){let o=e.start(i);if(o<e.pos-(e.depth-i)||t.end(i)>t.pos+(t.depth-i)||e.node(i).type.spec.isolating||t.node(i).type.spec.isolating)break;(o==t.start(i)||i==e.depth&&i==t.depth&&e.parent.inlineContent&&t.parent.inlineContent&&i&&t.start(i-1)==o-1)&&n.push(i)}return n}class le extends F{constructor(e,t,n){super(),this.pos=e,this.attr=t,this.value=n}apply(e){let t=e.nodeAt(this.pos);if(!t)return P.fail("No node at attribute step's position");let n=Object.create(null);for(let e in t.attrs)n[e]=t.attrs[e];n[this.attr]=this.value;let i=t.type.create(n,null,t.marks);return P.fromReplace(e,this.pos,this.pos+1,new u(r.from(i),0,t.isLeaf?0:1))}getMap(){return z.empty}invert(e){return new le(this.pos,this.attr,e.nodeAt(this.pos).attrs[this.attr])}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new le(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if("number"!=typeof t.pos||"string"!=typeof t.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new le(t.pos,t.attr,t.value)}}F.jsonID("attr",le);class ce extends F{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let n in e.attrs)t[n]=e.attrs[n];t[this.attr]=this.value;let n=e.type.create(t,e.content,e.marks);return P.ok(n)}getMap(){return z.empty}invert(e){return new ce(this.attr,e.attrs[this.attr])}map(e){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(e,t){if("string"!=typeof t.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new ce(t.attr,t.value)}}F.jsonID("docAttr",ce);let me=class extends Error{};me=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},(me.prototype=Object.create(Error.prototype)).constructor=me,me.prototype.name="TransformError";class de{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new B}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new me(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,n=u.empty){let i=function(e,t,n=t,i=u.empty){if(t==n&&!i.size)return null;let o=e.resolve(t),a=e.resolve(n);return Y(o,a,i)?new G(t,n,i):new ee(o,a,i).fit()}(this.doc,e,t,n);return i&&this.step(i),this}replaceWith(e,t,n){return this.replace(e,t,new u(r.from(n),0,0))}delete(e,t){return this.replace(e,t,u.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,n){return function(e,t,n,i){if(!i.size)return e.deleteRange(t,n);let o=e.doc.resolve(t),a=e.doc.resolve(n);if(Y(o,a,i))return e.step(new G(t,n,i));let r=se(o,e.doc.resolve(n));0==r[r.length-1]&&r.pop();let s=-(o.depth+1);r.unshift(s);for(let e=o.depth,t=o.pos-1;e>0;e--,t--){let n=o.node(e).type.spec;if(n.defining||n.definingAsContext||n.isolating)break;r.indexOf(e)>-1?s=e:o.before(e)==t&&r.splice(1,0,-e)}let l=r.indexOf(s),c=[],m=i.openStart;for(let e=i.content,t=0;;t++){let n=e.firstChild;if(c.push(n),t==i.openStart)break;e=n.content}for(let e=m-1;e>=0;e--){let t=c[e],n=(d=t.type).spec.defining||d.spec.definingForContent;if(n&&!t.sameMarkup(o.node(Math.abs(s)-1)))m=e;else if(n||!t.type.isTextblock)break}var d;for(let t=i.openStart;t>=0;t--){let s=(t+m+1)%(i.openStart+1),d=c[s];if(d)for(let t=0;t<r.length;t++){let c=r[(t+l)%r.length],m=!0;c<0&&(m=!1,c=-c);let h=o.node(c-1),p=o.index(c-1);if(h.canReplaceWith(p,p,d.type,d.marks))return e.replace(o.before(c),m?a.after(c):n,new u(re(i.content,0,i.openStart,s),s,i.openEnd))}}let h=e.steps.length;for(let s=r.length-1;s>=0&&(e.replace(t,n,i),!(e.steps.length>h));s--){let e=r[s];e<0||(t=o.before(e),n=a.after(e))}}(this,e,t,n),this}replaceRangeWith(e,t,n){return function(e,t,n,i){if(!i.isInline&&t==n&&e.doc.resolve(t).parent.content.size){let o=function(e,t,n){let i=e.resolve(t);if(i.parent.canReplaceWith(i.index(),i.index(),n))return t;if(0==i.parentOffset)for(let e=i.depth-1;e>=0;e--){let t=i.index(e);if(i.node(e).canReplaceWith(t,t,n))return i.before(e+1);if(t>0)return null}if(i.parentOffset==i.parent.content.size)for(let e=i.depth-1;e>=0;e--){let t=i.indexAfter(e);if(i.node(e).canReplaceWith(t,t,n))return i.after(e+1);if(t<i.node(e).childCount)return null}return null}(e.doc,t,i.type);null!=o&&(t=n=o)}e.replaceRange(t,n,new u(r.from(i),0,0))}(this,e,t,n),this}deleteRange(e,t){return function(e,t,n){let i=e.doc.resolve(t),o=e.doc.resolve(n),a=se(i,o);for(let t=0;t<a.length;t++){let n=a[t],r=t==a.length-1;if(r&&0==n||i.node(n).type.contentMatch.validEnd)return e.delete(i.start(n),o.end(n));if(n>0&&(r||i.node(n-1).canReplace(i.index(n-1),o.indexAfter(n-1))))return e.delete(i.before(n),o.after(n))}for(let a=1;a<=i.depth&&a<=o.depth;a++)if(t-i.start(a)==i.depth-a&&n>i.end(a)&&o.end(a)-n!=o.depth-a&&i.start(a-1)==o.start(a-1)&&i.node(a-1).canReplace(i.index(a-1),o.index(a-1)))return e.delete(i.before(a),n);e.delete(t,n)}(this,e,t),this}lift(e,t){return function(e,t,n){let{$from:i,$to:o,depth:a}=t,s=i.before(a+1),l=o.after(a+1),c=s,m=l,d=r.empty,h=0;for(let e=a,t=!1;e>n;e--)t||i.index(e)>0?(t=!0,d=r.from(i.node(e).copy(d)),h++):c--;let p=r.empty,f=0;for(let e=a,t=!1;e>n;e--)t||o.after(e+1)<o.end(e)?(t=!0,p=r.from(o.node(e).copy(p)),f++):m++;e.step(new Z(c,m,s,l,new u(d.append(p),h,f),d.size-h,!0))}(this,e,t),this}join(e,t=1){return function(e,t,n){let i=null,{linebreakReplacement:o}=e.doc.type.schema,a=e.doc.resolve(t-n),r=a.node().type;if(o&&r.inlineContent){let e="pre"==r.whitespace,t=!!r.contentMatch.matchType(o);e&&!t?i=!1:!e&&t&&(i=!0)}let s=e.steps.length;if(!1===i){let i=e.doc.resolve(t+n);Q(e,i.node(),i.before(),s)}r.inlineContent&&J(e,t+n-1,r,a.node().contentMatchAt(a.index()),null==i);let l=e.mapping.slice(s),c=l.map(t-n);if(e.step(new G(c,l.map(t+n,-1),u.empty,!0)),!0===i){let t=e.doc.resolve(c);X(e,t.node(),t.before(),e.steps.length)}}(this,e,t),this}wrap(e,t){return function(e,t,n){let i=r.empty;for(let e=n.length-1;e>=0;e--){if(i.size){let t=n[e].type.contentMatch.matchFragment(i);if(!t||!t.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}i=r.from(n[e].type.create(n[e].attrs,i))}let o=t.start,a=t.end;e.step(new Z(o,a,o,a,new u(i,0,0),n.length,!0))}(this,e,t),this}setBlockType(e,t=e,n,i=null){return function(e,t,n,i,o){if(!i.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let a=e.steps.length;e.doc.nodesBetween(t,n,((t,n)=>{let s="function"==typeof o?o(t):o;if(t.isTextblock&&!t.hasMarkup(i,s)&&function(e,t,n){let i=e.resolve(t),o=i.index();return i.parent.canReplaceWith(o,o+1,n)}(e.doc,e.mapping.slice(a).map(n),i)){let o=null;if(i.schema.linebreakReplacement){let e="pre"==i.whitespace,t=!!i.contentMatch.matchType(i.schema.linebreakReplacement);e&&!t?o=!1:!e&&t&&(o=!0)}!1===o&&Q(e,t,n,a),J(e,e.mapping.slice(a).map(n,1),i,void 0,null===o);let l=e.mapping.slice(a),c=l.map(n,1),m=l.map(n+t.nodeSize,1);return e.step(new Z(c,m,c+1,m-1,new u(r.from(i.create(s,null,t.marks)),0,0),1,!0)),!0===o&&X(e,t,n,a),!1}}))}(this,e,t,n,i),this}setNodeMarkup(e,t,n=null,i){return function(e,t,n,i,o){let a=e.doc.nodeAt(t);if(!a)throw new RangeError("No node at given position");n||(n=a.type);let s=n.create(i,null,o||a.marks);if(a.isLeaf)return e.replaceWith(t,t+a.nodeSize,s);if(!n.validContent(a.content))throw new RangeError("Invalid content for node type "+n.name);e.step(new Z(t,t+a.nodeSize,t+1,t+a.nodeSize-1,new u(r.from(s),0,0),1,!0))}(this,e,t,n,i),this}setNodeAttribute(e,t,n){return this.step(new le(e,t,n)),this}setDocAttribute(e,t){return this.step(new ce(e,t)),this}addNodeMark(e,t){return this.step(new K(e,t)),this}removeNodeMark(e,t){if(!(t instanceof m)){let n=this.doc.nodeAt(e);if(!n)throw new RangeError("No node at position "+e);if(!(t=t.isInSet(n.marks)))return this}return this.step(new W(e,t)),this}split(e,t=1,n){return function(e,t,n=1,i){let o=e.doc.resolve(t),a=r.empty,s=r.empty;for(let e=o.depth,t=o.depth-n,l=n-1;e>t;e--,l--){a=r.from(o.node(e).copy(a));let t=i&&i[l];s=r.from(t?t.type.create(t.attrs,s):o.node(e).copy(s))}e.step(new G(t,t,new u(a.append(s),n,n),!0))}(this,e,t,n),this}addMark(e,t,n){