medium-proeditor
Version:
A powerful & customizable Medium-style rich text editor
1 lines • 155 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).Emoji={})}(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,o){const i={...e};if(t(e)&&t(o))for(const a of Object.keys(o))t(o[a])&&t(e[a])?i[a]=n(e[a],o[a]):i[a]=o[a];return i}class o{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 o(e)}configure(e={}){return new o({...this.config,addOptions:()=>n(this.options,e)})}}function i(e,t,n){for(let o=0;;o++){if(o==e.childCount||o==t.childCount)return e.childCount==t.childCount?null:n;let a=e.child(o),r=t.child(o);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=i(a.content,r.content,n+1);if(null!=e)return e}n+=a.nodeSize}else n+=a.nodeSize}}function a(e,t,n,o){for(let i=e.childCount,r=t.childCount;;){if(0==i||0==r)return i==r?null:{a:n,b:o};let m=e.child(--i),s=t.child(--r),l=m.nodeSize;if(m!=s){if(!m.sameMarkup(s))return{a:n,b:o};if(m.isText&&m.text!=s.text){let e=0,t=Math.min(m.text.length,s.text.length);for(;e<t&&m.text[m.text.length-e-1]==s.text[s.text.length-e-1];)e++,n--,o--;return{a:n,b:o}}if(m.content.size||s.content.size){let e=a(m.content,s.content,n-1,o-1);if(e)return e}n-=l,o-=l}else n-=l,o-=l}}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,o=0,i){for(let a=0,r=0;r<t;a++){let m=this.content[a],s=r+m.nodeSize;if(s>e&&!1!==n(m,o+r,i||null,a)&&m.content.size){let i=r+1;m.nodesBetween(Math.max(0,e-i),Math.min(m.content.size,t-i),n,o+i)}r=s}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,o){let i="",a=!0;return this.nodesBetween(e,t,((r,m)=>{let s=r.isText?r.text.slice(Math.max(e,m)-m,t-m):r.isLeaf?o?"function"==typeof o?o(r):o:r.type.spec.leafText?r.type.spec.leafText(r):"":"";r.isBlock&&(r.isLeaf&&s||r.isTextblock)&&n&&(a?a=!1:i+=n),i+=s}),0),i}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,o=this.content.slice(),i=0;for(t.isText&&t.sameMarkup(n)&&(o[o.length-1]=t.withText(t.text+n.text),i=1);i<e.content.length;i++)o.push(e.content[i]);return new r(o,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],o=0;if(t>e)for(let i=0,a=0;a<t;i++){let r=this.content[i],m=a+r.nodeSize;m>e&&((a<e||m>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),o+=r.nodeSize),a=m}return new r(n,o)}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 o=this.content.slice(),i=this.size+t.nodeSize-n.nodeSize;return o[e]=t,new r(o,i)}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 o=this.content[t];e(o,n,t),n+=o.nodeSize}}findDiffStart(e,t=0){return i(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 s(0,e);if(e==this.size)return s(this.content.length,e);if(e>this.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let n=0,o=0;;n++){let i=o+this.child(n).nodeSize;if(i>=e)return i==e||t>0?s(n+1,i):s(n,o);o=i}}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 o=0;o<e.length;o++){let i=e[o];n+=i.nodeSize,o&&i.isText&&e[o-1].sameMarkup(i)?(t||(t=e.slice(0,o)),t[t.length-1]=i.withText(t[t.length-1].text+i.text)):t&&t.push(i)}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 m={index:0,offset:0};function s(e,t){return m.index=e,m.offset=t,m}function l(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(!l(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!l(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class c{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let o=0;o<e.length;o++){let i=e[o];if(this.eq(i))return e;if(this.type.excludes(i.type))t||(t=e.slice(0,o));else{if(i.type.excludes(this.type))return e;!n&&i.type.rank>this.type.rank&&(t||(t=e.slice(0,o)),t.push(this),n=!0),t&&t.push(i)}}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&&l(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 o=n.create(t.attrs);return n.checkAttrs(o.attrs),o}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 c.none;if(e instanceof c)return[e];let t=e.slice();return t.sort(((e,t)=>e.type.rank-t.type.rank)),t}}c.none=[];class h 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=f(this.content,e+this.openStart,t);return n&&new u(n,this.openStart,this.openEnd)}removeBetween(e,t){return new u(d(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,o=t.openEnd||0;if("number"!=typeof n||"number"!=typeof o)throw new RangeError("Invalid input for Slice.fromJSON");return new u(r.fromJSON(e,t.content),n,o)}static maxOpen(e,t=!0){let n=0,o=0;for(let o=e.firstChild;o&&!o.isLeaf&&(t||!o.type.spec.isolating);o=o.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)o++;return new u(e,n,o)}}function d(e,t,n){let{index:o,offset:i}=e.findIndex(t),a=e.maybeChild(o),{index:r,offset:m}=e.findIndex(n);if(i==t||a.isText){if(m!=n&&!e.child(r).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(o!=r)throw new RangeError("Removing non-flat range");return e.replaceChild(o,a.copy(d(a.content,t-i-1,n-i-1)))}function f(e,t,n,o){let{index:i,offset:a}=e.findIndex(t),r=e.maybeChild(i);if(a==t||r.isText)return o&&!o.canReplace(i,i,n)?null:e.cut(0,t).append(n).append(e.cut(t));let m=f(r.content,t-a-1,n);return m&&e.replaceChild(i,r.copy(m))}u.empty=new u(r.empty,0,0);class p{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 b(this,t,!1);return n.addAll(e,c.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new b(this,t,!0);return n.addAll(e,c.none,t.from,t.to),u.maxOpen(n.finish())}matchTag(e,t,n){for(let o=n?this.tags.indexOf(n)+1:0;o<this.tags.length;o++){let n=this.tags[o];if(v(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,o){for(let i=o?this.styles.indexOf(o)+1:0;i<this.styles.length;i++){let o=this.styles[i],a=o.style;if(!(0!=a.indexOf(e)||o.context&&!n.matchesContext(o.context)||a.length>e.length&&(61!=a.charCodeAt(e.length)||a.slice(e.length+1)!=t))){if(o.getAttrs){let e=o.getAttrs(t);if(!1===e)continue;o.attrs=e||void 0}return o}}}static schemaRules(e){let t=[];function n(e){let n=null==e.priority?50:e.priority,o=0;for(;o<t.length;o++){let e=t[o];if((null==e.priority?50:e.priority)<n)break}t.splice(o,0,e)}for(let t in e.marks){let o=e.marks[t].spec.parseDOM;o&&o.forEach((e=>{n(e=k(e)),e.mark||e.ignore||e.clearMark||(e.mark=t)}))}for(let t in e.nodes){let o=e.nodes[t].spec.parseDOM;o&&o.forEach((e=>{n(e=k(e)),e.node||e.ignore||e.mark||(e.node=t)}))}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new p(e,p.schemaRules(e)))}}const j={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},g={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},_={ol:!0,ul:!0};function w(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class y{constructor(e,t,n,o,i,a){this.type=e,this.attrs=t,this.marks=n,this.solid=o,this.options=a,this.content=[],this.activeMarks=c.none,this.match=i||(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&&!j.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class b{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let o,i=t.topNode,a=w(null,t.preserveWhitespace,0)|(n?4:0);o=i?new y(i.type,i.attrs,c.none,!0,t.topMatch||i.type.contentMatch,a):new y(n?null:e.schema.topNodeType,null,c.none,!0,null,a),this.nodes=[o],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,o=this.top,i=2&o.options?"full":this.localPreserveWS||(1&o.options)>0;if("full"===i||o.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(i)n="full"!==i?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=o.content[o.content.length-1],i=e.previousSibling;(!t||i&&"BR"==i.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 o=this.localPreserveWS,i=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let a,r=e.nodeName.toLowerCase();_.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&&_.hasOwnProperty(e)&&n?(n.appendChild(t),t=n):"li"==e?n=t:e&&(n=null)}}(e);let m=this.options.ruleFromNode&&this.options.ruleFromNode(e)||(a=this.parser.matchTag(e,this,n));e:if(m?m.ignore:g.hasOwnProperty(r))this.findInside(e),this.ignoreFallback(e,t);else if(!m||m.skip||m.closeParent){m&&m.closeParent?this.open=Math.max(0,this.open-1):m&&m.skip.nodeType&&(e=m.skip);let n,o=this.needsBlock;if(j.hasOwnProperty(r))i.content.length&&i.content[0].isInline&&this.open&&(this.open--,i=this.top),n=!0,i.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let a=m&&m.skip?t:this.readStyles(e,t);a&&this.addAll(e,a),n&&this.sync(i),this.needsBlock=o}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,m,n,!1===m.consuming?a:void 0)}this.localPreserveWS=o}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 o=this.parser.matchedStyles[e],i=n.getPropertyValue(o);if(i)for(let e;;){let n=this.parser.matchStyle(o,i,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,o){let i,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&&(i=!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(o)this.addElement(e,n,o);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach((e=>this.insertNode(e,n)));else{let o=e;"string"==typeof t.contentElement?o=e.querySelector(t.contentElement):"function"==typeof t.contentElement?o=t.contentElement(e):t.contentElement&&(o=t.contentElement),this.findAround(e,o,!0),this.addAll(o,n),this.findAround(e,o,!1)}i&&this.sync(r)&&this.open--}addAll(e,t,n,o){let i=n||0;for(let a=n?e.childNodes[n]:e.firstChild,r=null==o?null:e.childNodes[o];a!=r;a=a.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(a,t);this.findAtPoint(e,i)}findPlace(e,t){let n,o;for(let t=this.open;t>=0;t--){let i=this.nodes[t],a=i.findWrapping(e);if(a&&(!n||n.length>a.length)&&(n=a,o=i,!a.length))break;if(i.solid)break}if(!n)return null;this.sync(o);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 o=c.none;for(let i of n.concat(e.marks))(t.type?t.type.allowsMarkType(i.type):x(i.type,e.type))&&(o=i.addToSet(o));return t.content.push(e.mark(o)),!0}return!1}enter(e,t,n,o){let i=this.findPlace(e.create(t),n);return i&&(i=this.enterInner(e,t,n,!0,o)),i}enterInner(e,t,n,o=!1,i){this.closeExtra();let a=this.top;a.match=a.match&&a.match.matchType(e);let r=w(e,i,a.options);4&a.options&&0==a.content.length&&(r|=4);let m=c.none;return n=n.filter((t=>!(a.type?a.type.allowsMarkType(t.type):x(t.type,e))||(m=t.addToSet(m),!1))),this.nodes.push(new y(e,t,m,o,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 o=0;o<this.find.length;o++)if(null==this.find[o].pos&&1==e.nodeType&&e.contains(this.find[o].node)){t.compareDocumentPosition(this.find[o].node)&(n?2:4)&&(this.find[o].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,o=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),i=-(n?n.depth+1:0)+(o?0:1),a=(e,r)=>{for(;e>=0;e--){let m=t[e];if(""==m){if(e==t.length-1||0==e)continue;for(;r>=i;r--)if(a(e-1,r))return!0;return!1}{let e=r>0||0==r&&o?this.nodes[r].type:n&&r>=i?n.node(r-i).type:null;if(!e||e.name!=m&&!e.isInGroup(m))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 v(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function k(e){let t={};for(let n in e)t[n]=e[n];return t}function x(e,t){let n=t.schema.nodes;for(let o in n){let i=n[o];if(!i.allowsMarkType(e))continue;let a=[],r=e=>{a.push(e);for(let n=0;n<e.edgeCount;n++){let{type:o,next:i}=e.edge(n);if(o==t)return!0;if(a.indexOf(i)<0&&r(i))return!0}};if(r(i.contentMatch))return!0}}class S{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=C(t).createDocumentFragment());let o=n,i=[];return e.forEach((e=>{if(i.length||e.marks.length){let n=0,a=0;for(;n<i.length&&a<e.marks.length;){let t=e.marks[a];if(this.marks[t.type.name]){if(!t.eq(i[n][0])||!1===t.type.spec.spanning)break;n++,a++}else a++}for(;n<i.length;)o=i.pop()[1];for(;a<e.marks.length;){let n=e.marks[a++],r=this.serializeMark(n,e.isInline,t);r&&(i.push([n,o]),o.appendChild(r.dom),o=r.contentDOM||r.dom)}}o.appendChild(this.serializeNodeInner(e,t))})),n}serializeNodeInner(e,t){let{dom:n,contentDOM:o}=N(C(t),this.nodes[e.type.name](e),null,e.attrs);if(o){if(e.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(e.content,t,o)}return n}serializeNode(e,t={}){let n=this.serializeNodeInner(e,t);for(let o=e.marks.length-1;o>=0;o--){let i=this.serializeMark(e.marks[o],e.isInline,t);i&&((i.contentDOM||i.dom).appendChild(n),n=i.dom)}return n}serializeMark(e,t,n={}){let o=this.marks[e.type.name];return o&&N(C(n),o(e,t),null,e.attrs)}static renderSpec(e,t,n=null,o){return N(e,t,n,o)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new S(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=T(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return T(e.marks)}}function T(e){let t={};for(let n in e){let o=e[n].spec.toDOM;o&&(t[n]=o)}return t}function C(e){return e.document||window.document}const O=new WeakMap;function E(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 N(e,t,n,o){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 i,a=t[0];if("string"!=typeof a)throw new RangeError("Invalid array passed to renderSpec");if(o&&(i=E(o))&&i.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,m=a.indexOf(" ");m>0&&(n=a.slice(0,m),a=a.slice(m+1));let s=n?e.createElementNS(n,a):e.createElement(a),l=t[1],c=1;if(l&&"object"==typeof l&&null==l.nodeType&&!Array.isArray(l)){c=2;for(let e in l)if(null!=l[e]){let t=e.indexOf(" ");t>0?s.setAttributeNS(e.slice(0,t),e.slice(t+1),l[e]):s.setAttribute(e,l[e])}}for(let i=c;i<t.length;i++){let a=t[i];if(0===a){if(i<t.length-1||i>c)throw new RangeError("Content hole must be the only child of its parent node");return{dom:s,contentDOM:s}}{let{dom:t,contentDOM:i}=N(e,a,n,o);if(s.appendChild(t),i){if(r)throw new RangeError("Multiple content holes");r=i}}}return{dom:s,contentDOM:r}}const D=Math.pow(2,16);function A(e,t){return e+t*D}function M(e){return 65535&e}class R{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=M(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))/D}(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 o=0,i=this.inverted?2:1,a=this.inverted?1:2;for(let r=0;r<this.ranges.length;r+=3){let m=this.ranges[r]-(this.inverted?o:0);if(m>e)break;let s=this.ranges[r+i],l=this.ranges[r+a],c=m+s;if(e<=c){let i=m+o+((s?e==m?-1:e==c?1:t:t)<0?0:l);if(n)return i;let a=e==(t<0?m:c)?null:A(r/3,e-m),h=e==m?2:e==c?1:4;return(t<0?e!=m:e!=c)&&(h|=8),new R(i,h,a)}o+=l-s}return n?e+o:new R(e+o,0,null)}touches(e,t){let n=0,o=M(t),i=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 m=this.ranges[t+i];if(e<=r+m&&t==3*o)return!0;n+=this.ranges[t+a]-m}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let o=0,i=0;o<this.ranges.length;o+=3){let a=this.ranges[o],r=a-(this.inverted?i:0),m=a+(this.inverted?0:i),s=this.ranges[o+t],l=this.ranges[o+n];e(r,r+s,m,m+l),i+=l-s}}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([]);const I=Object.create(null);class P{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=I[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 I)throw new RangeError("Duplicate use of step JSON ID "+e);return I[e]=t,t.prototype.jsonID=e,t}}class ${constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new $(e,null)}static fail(e){return new $(null,e)}static fromReplace(e,t,n,o){try{return $.ok(e.replace(t,n,o))}catch(e){if(e instanceof h)return $.fail(e.message);throw e}}}function L(e,t,n){let o=[];for(let i=0;i<e.childCount;i++){let a=e.child(i);a.content.size&&(a=a.copy(L(a.content,t,a))),a.isInline&&(a=t(a,n,i)),o.push(a)}return r.fromArray(o)}class q extends P{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),o=n.node(n.sharedDepth(this.to)),i=new u(L(t.content,((e,t)=>e.isAtom&&t.type.allowsMarkType(this.mark.type)?e.mark(this.mark.addToSet(e.marks)):e),o),t.openStart,t.openEnd);return $.fromReplace(e,this.from,this.to,i)}invert(){return new F(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:"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 q(t.from,t.to,e.markFromJSON(t.mark))}}P.jsonID("addMark",q);class F extends P{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(L(t.content,(e=>e.mark(this.mark.removeFromSet(e.marks))),e),t.openStart,t.openEnd);return $.fromReplace(e,this.from,this.to,n)}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 F(t.pos,n.pos,this.mark)}merge(e){return e instanceof F&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new F(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 F(t.from,t.to,e.markFromJSON(t.mark))}}P.jsonID("removeMark",F);class J extends P{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return $.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return $.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 J(this.pos,t.marks[n]);return new J(this.pos,this.mark)}}return new B(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new J(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 J(t.pos,e.markFromJSON(t.mark))}}P.jsonID("addNodeMark",J);class B extends P{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return $.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return $.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 J(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new B(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 B(t.pos,e.markFromJSON(t.mark))}}P.jsonID("removeNodeMark",B);class V extends P{constructor(e,t,n,o=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=o}apply(e){return this.structure&&W(e,this.from,this.to)?$.fail("Structure replace would overwrite content"):$.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 V(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 V(t.pos,Math.max(t.pos,n.pos),this.slice)}merge(e){if(!(e instanceof V)||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 V(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 V(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 V(t.from,t.to,u.fromJSON(e,t.slice),!!t.structure)}}P.jsonID("replace",V);class K extends P{constructor(e,t,n,o,i,a,r=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=o,this.slice=i,this.insert=a,this.structure=r}apply(e){if(this.structure&&(W(e,this.from,this.gapFrom)||W(e,this.gapTo,this.to)))return $.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return $.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?$.fromReplace(e,this.from,this.to,n):$.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 K(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),o=this.from==this.gapFrom?t.pos:e.map(this.gapFrom,-1),i=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||o<t.pos||i>n.pos?null:new K(t.pos,n.pos,o,i,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 K(t.from,t.to,t.gapFrom,t.gapTo,u.fromJSON(e,t.slice),t.insert,!!t.structure)}}function W(e,t,n){let o=e.resolve(t),i=n-t,a=o.depth;for(;i>0&&a>0&&o.indexAfter(a)==o.node(a).childCount;)a--,i--;if(i>0){let e=o.node(a).maybeChild(o.indexAfter(a));for(;i>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,i--}}return!1}P.jsonID("replaceAround",K);class H extends P{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 $.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 o=t.type.create(n,null,t.marks);return $.fromReplace(e,this.pos,this.pos+1,new u(r.from(o),0,t.isLeaf?0:1))}getMap(){return z.empty}invert(e){return new H(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 H(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 H(t.pos,t.attr,t.value)}}P.jsonID("attr",H);class U extends P{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 $.ok(n)}getMap(){return z.empty}invert(e){return new U(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 U(t.attr,t.value)}}P.jsonID("docAttr",U);let G=class extends Error{};G=function e(t){let n=Error.call(this,t);return n.__proto__=e.prototype,n},(G.prototype=Object.create(Error.prototype)).constructor=G,G.prototype.name="TransformError";const X=Object.create(null);class Y{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new Q(e.min(t),e.max(t))]}get anchor(){return this.$anchor.pos}get head(){return this.$head.pos}get from(){return this.$from.pos}get to(){return this.$to.pos}get $from(){return this.ranges[0].$from}get $to(){return this.ranges[0].$to}get empty(){let e=this.ranges;for(let t=0;t<e.length;t++)if(e[t].$from.pos!=e[t].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(e,t=u.empty){let n=t.content.lastChild,o=null;for(let e=0;e<t.openEnd;e++)o=n,n=n.lastChild;let i=e.steps.length,a=this.ranges;for(let r=0;r<a.length;r++){let{$from:m,$to:s}=a[r],l=e.mapping.slice(i);e.replaceRange(l.map(m.pos),l.map(s.pos),r?u.empty:t),0==r&&se(e,i,(n?n.isInline:o&&o.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,o=this.ranges;for(let i=0;i<o.length;i++){let{$from:a,$to:r}=o[i],m=e.mapping.slice(n),s=m.map(a.pos),l=m.map(r.pos);i?e.deleteRange(s,l):(e.replaceRangeWith(s,l,t),se(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let o=e.parent.inlineContent?new te(e):me(e.node(0),e.parent,e.pos,e.index(),t,n);if(o)return o;for(let o=e.depth-1;o>=0;o--){let i=t<0?me(e.node(0),e.node(o),e.before(o+1),e.index(o),t,n):me(e.node(0),e.node(o),e.after(o+1),e.index(o)+1,t,n);if(i)return i}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new ae(e.node(0))}static atStart(e){return me(e,e,0,0,1)||new ae(e)}static atEnd(e){return me(e,e,e.content.size,e.childCount,-1)||new ae(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=X[t.type];if(!n)throw new RangeError(`No selection type ${t.type} defined`);return n.fromJSON(e,t)}static jsonID(e,t){if(e in X)throw new RangeError("Duplicate use of selection JSON ID "+e);return X[e]=t,t.prototype.jsonID=e,t}getBookmark(){return te.between(this.$anchor,this.$head).getBookmark()}}Y.prototype.visible=!0;class Q{constructor(e,t){this.$from=e,this.$to=t}}let Z=!1;function ee(e){Z||e.parent.inlineContent||(Z=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class te extends Y{constructor(e,t=e){ee(e),ee(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let n=e.resolve(t.map(this.head));if(!n.parent.inlineContent)return Y.near(n);let o=e.resolve(t.map(this.anchor));return new te(o.parent.inlineContent?o:n,n)}replace(e,t=u.empty){if(super.replace(e,t),t==u.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof te&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new ne(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if("number"!=typeof t.anchor||"number"!=typeof t.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new te(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let o=e.resolve(t);return new this(o,n==t?o:e.resolve(n))}static between(e,t,n){let o=e.pos-t.pos;if(n&&!o||(n=o>=0?1:-1),!t.parent.inlineContent){let e=Y.findFrom(t,n,!0)||Y.findFrom(t,-n,!0);if(!e)return Y.near(t,n);t=e.$head}return e.parent.inlineContent||(0==o||(e=(Y.findFrom(e,-n,!0)||Y.findFrom(e,n,!0)).$anchor).pos<t.pos!=o<0)&&(e=t),new te(e,t)}}Y.jsonID("text",te);class ne{constructor(e,t){this.anchor=e,this.head=t}map(e){return new ne(e.map(this.anchor),e.map(this.head))}resolve(e){return te.between(e.resolve(this.anchor),e.resolve(this.head))}}class oe extends Y{constructor(e){let t=e.nodeAfter,n=e.node(0).resolve(e.pos+t.nodeSize);super(e,n),this.node=t}map(e,t){let{deleted:n,pos:o}=t.mapResult(this.anchor),i=e.resolve(o);return n?Y.near(i):new oe(i)}content(){return new u(r.from(this.node),0,0)}eq(e){return e instanceof oe&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new ie(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new oe(e.resolve(t.anchor))}static create(e,t){return new oe(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}oe.prototype.visible=!1,Y.jsonID("node",oe);class ie{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new ne(n,n):new ie(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&oe.isSelectable(n)?new oe(t):Y.near(t)}}class ae extends Y{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=u.empty){if(t==u.empty){e.delete(0,e.doc.content.size);let t=Y.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new ae(e)}map(e){return new ae(e)}eq(e){return e instanceof ae}getBookmark(){return re}}Y.jsonID("all",ae);const re={map(){return this},resolve:e=>new ae(e)};function me(e,t,n,o,i,a=!1){if(t.inlineContent)return te.create(e,n);for(let r=o-(i>0?0:1);i>0?r<t.childCount:r>=0;r+=i){let o=t.child(r);if(o.isAtom){if(!a&&oe.isSelectable(o))return oe.create(e,n-(i<0?o.nodeSize:0))}else{let t=me(e,o,n+i,i<0?o.childCount:0,i,a);if(t)return t}n+=o.nodeSize*i}return null}function se(e,t,n){let o=e.steps.length-1;if(o<t)return;let i,a=e.steps[o];(a instanceof V||a instanceof K)&&(e.mapping.maps[o].forEach(((e,t,n,o)=>{null==i&&(i=o)})),e.setSelection(Y.near(e.doc.resolve(i),n)))}function le(e,t){return t&&e?e.bind(t):e}class ce{constructor(e,t,n){this.name=e,this.init=le(t.init,n),this.apply=le(t.apply,n)}}function he(e,t,n){for(let o in e){let i=e[o];i instanceof Function?i=i.bind(t):"handleDOMEvents"==o&&(i=he(i,t,{})),n[o]=i}return n}new ce("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new ce("selection",{init:(e,t)=>e.selection||Y.atStart(t.doc),apply:e=>e.selection}),new ce("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,o)=>o.selection.$cursor?e.storedMarks:null}),new ce("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t});class ue{constructor(e){this.spec=e,this.props={},e.props&&he(e.props,this,this.props),this.key=e.key?e.key.key:fe("plugin")}getState(e){return e[this.key]}}const de=Object.create(null);function fe(e){return e in de?e+"$"+ ++de[e]:(de[e]=0,e+"$")}class pe{constructor(e="key"){this.key=fe(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}class je{find;handler;constructor(e){this.find=e.find,this.handler=e.handler}}const ge=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},_e=function(e,t,n,o){return n&&(ye(e,t,n,o,-1)||ye(e,t,n,o,1))},we=/^(img|br|input|textarea|hr)$/i;function ye(e,t,n,o,i){for(;;){if(e==n&&t==o)return!0;if(t==(i<0?0:be(e))){let n=e.parentNode;if(!n||1!=n.nodeType||ve(e)||we.test(e.nodeName)||"false"==e.contentEditable)return!1;t=ge(e)+(i<0?0:1),e=n}else{if(1!=e.nodeType)return!1;if("false"==(e=e.childNodes[t+(i<0?-1:0)]).contentEditable)return!1;t=i<0?be(e):0}}}function be(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function ve(e){let t;for(let n=e;n&&!(t=n.pmViewDesc);n=n.parentNode);return t&&t.node&&t.node.isBlock&&(t.dom==e||t.contentDOM==e)}const ke=function(e){return e.focusNode&&_e(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function xe(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}const Se="undefined"!=typeof navigator?navigator:null,Te="undefined"!=typeof document?document:null,Ce=Se&&Se.userAgent||"",Oe=/Edge\/(\d+)/.exec(Ce),Ee=/MSIE \d/.exec(Ce),Ne=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ce),De=!!(Ee||Ne||Oe),Ae=Ee?document.documentMode:Ne?+Ne[1]:Oe?+Oe[1]:0,Me=!De&&/gecko\/(\d+)/i.test(Ce);Me&&(/Firefox\/(\d+)/.exec(Ce)||[0,0])[1];const Re=!De&&/Chrome\/(\d+)/.exec(Ce),ze=!!Re,Ie=Re?+Re[1]:0,Pe=!De&&!!Se&&/Apple Computer/.test(Se.vendor),$e=Pe&&(/Mobile\/\w+/.test(Ce)||!!Se&&Se.maxTouchPoints>2),Le=$e||!!Se&&/Mac/.test(Se.platform),qe=!!Se&&/Win/.test(Se.platform),Fe=/Android \d/.test(Ce),Je=!!Te&&"webkitFontSmoothing"in Te.documentElement.style,Be=Je?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Ve(e,t=null){let n=e.domSelectionRange(),o=e.state.doc;if(!n.focusNode)return null;let i=e.docView.nearestDesc(n.focusNode),a=i&&0==i.size,r=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(r<0)return null;let m,s,l=o.resolve(r);if(ke(n)){for(m=r;i&&!i.node;)i=i.parent;let e=i.node;if(i&&e.isAtom&&oe.isSelectable(e)&&i.parent&&(!e.isInline||!function(e,t,n){for(let o=0==t,i=t==be(e);o||i;){if(e==n)return!0;let t=ge(e);if(!(e=e.parentNode))return!1;o=o&&0==t,i=i&&t==be(e)}}(n.focusNode,n.focusOffset,i.dom))){let e=i.posBefore;s=new oe(r==e?l:o.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=r,i=r;for(let o=0;o<n.rangeCount;o++){let a=n.getRangeAt(o);t=Math.min(t,e.docView.posFromDOM(a.startContainer,a.startOffset,1)),i=Math.max(i,e.docView.posFromDOM(a.endContainer,a.endOffset,-1))}if(t<0)return null;[m,r]=i==e.state.selection.anchor?[i,t]:[t,i],l=o.resolve(r)}else m=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(m<0)return null}let c=o.resolve(m);if(!s){s=Qe(e,c,l,"pointer"==t||e.state.selection.head<l.pos&&!a?1:-1)}return s}function Ke(e){return e.editable?e.hasFocus():function(e){let t=e.domSelectionRange();if(!t.anchorNode)return!1;try{return e.dom.contains(3==t.anchorNode.nodeType?t.anchorNode.parentNode:t.anchorNode)&&(e.editable||e.dom.contains(3==t.focusNode.nodeType?t.focusNode.parentNode:t.focusNode))}catch(e){return!1}}(e)&&document.activeElement&&document.activeElement.contains(e.dom)}function We(e,t=!1){let n=e.state.selection;if(function(e,t){if(t instanceof oe){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(Ye(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else Ye(e)}(e,n),Ke(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&ze){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&_e(t.anchorNode,t.anchorOffset,n.anchorNode,n.anchorOffset))return e.input.mouseDown.delayedSelectionSync=!0,void e.domObserver.setCurSelection()}if(e.domObserver.disconnectSelection(),e.cursorWrapper)!function(e){let t=e.domSelection(),n=document.createRange();if(!t)return;let o=e.cursorWrapper.dom,i="IMG"==o.nodeName;i?n.setStart(o.parentNode,ge(o)+1):n.setStart(o,0);n.collapse(!0),t.removeAllRanges(),t.addRange(n),!i&&!e.state.selection.visible&&De&&Ae<=11&&(o.disabled=!0,o.disabled=!1)}(e);else{let o,i,{anchor:a,head:r}=n;!He||n instanceof te||(n.$from.parent.inlineContent||(o=Ue(e,n.from)),n.empty||n.$from.parent.inlineContent||(i=Ue(e,n.to))),e.docView.setSelection(a,r,e,t),He&&(o&&Xe(o),i&&Xe(i)),n.visible?e.dom.classList.remove("ProseMirror-hideselection"):(e.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(e){let t=e.dom.ownerDocument;t.removeEventListener("selectionchange",e.input.hideSelectionGuard);let n=e.domSelectionRange(),o=n.anchorNode,i=n.anchorOffset;t.addEventListener("selectionchange",e.input.hideSelectionGuard=()=>{n.anchorNode==o&&n.anchorOffset==i||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout((()=>{Ke(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")}),20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}const He=Pe||ze&&Ie<63;function Ue(e,t){let{node:n,offset:o}=e.docView.domFromPos(t,0),i=o<n.childNodes.length?n.childNodes[o]:null,a=o?n.childNodes[o-1]:null;if(Pe&&i&&"false"==i.contentEditable)return Ge(i);if(!(i&&"false"!=i.contentEditable||a&&"false"!=a.contentEditable)){if(i)return Ge(i);if(a)return Ge(a)}}function Ge(e){return e.contentEditable="true",Pe&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function Xe(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function Ye(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function Qe(e,t,n,o){return e.someProp("createSelectionBetween",(o=>o(e,t,n)))||te.between(t,n,o)}function Ze(e,t){let{$anchor:n,$head:o}=e.selection,i=t>0?n.max(o):n.min(o),a=i.parent.inlineContent?i.depth?e.doc.resolve(t>0?i.after():i.before()):null:i;return a&&Y.findFrom(a,t)}function et(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function tt(e,t,n){let o=e.state.selection;if(!(o instanceof te)){if(o instanceof oe&&o.node.isInline)return et(e,new te(t>0?o.$to:o.$from));{let n=Ze(e.state,t);return!!n&&et(e,n)}}if(n.indexOf("s")>-1){let{$head:n}=o,i=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!i||i.isText||!i.isLeaf)return!1;let a=e.state.doc.resolve(n.pos+i.nodeSize*(t<0?-1:1));return et(e,new te(o.$anchor,a))}if(!o.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=Ze(e.state,t);return!!(n&&n instanceof oe)&&et(e,n)}if(!(Le&&n.indexOf("m")>-1)){let n,i=o.$head,a=i.textOffset?null:t<0?i.nodeBefore:i.nodeAfter;if(!a||a.isText)return!1;let r=t<0?i.pos-a.nodeSize:i.pos;return!!(a.isAtom||(n=e.docView.descAt(r))&&!n.contentDOM)&&(oe.isSelectable(a)?et(e,new oe(t<0?e.state.doc.resolve(i.pos-a.nodeSize):i)):!!Je&&et(e,new te(e.state.doc.resolve(t<0?r:r+a.nodeSize))))}}function nt(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function ot(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function it(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let i,a,r=!1;Me&&1==n.nodeType&&o<nt(n)&&ot(n.childNodes[o],-1)&&(r=!0);for(;;)if(o>0){if(1!=n.nodeType)break;{let e=n.childNodes[o-1];if(ot(e,-1))i=n,a=--o;else{if(3!=e.nodeType)break;n=e,o=n.nodeValue.length}}}else{if(at(n))break;{let t=n.previousSibling;for(;t&&ot(t,-1);)i=n.parentNode,a=ge(t),t=t.previousSibling;if(t)n=t,o=nt(n);else{if(n=n.parentNode,n==e.dom)break;o=0}}}r?rt(e,n,o):i&&rt(e,i,a)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,o=t.focusOffset;if(!n)return;let i,a,r=nt(n);for(;;)if(o<r){if(1!=n.nodeType)break;if(!ot(n.childNodes[o],1))break;i=n,a=++o}else{if(at(n))break;{let t=n.nextSibling;for(;t&&ot(t,1);)i=t.parentNode,a=ge(t)+1,t=t.nextSibling;if(t)n=t,o=0,r=nt(n);else{if(n=n.parentNode,n==e.dom)break;o=r=0}}}i&&rt(e,i,a)}(e)}function at(e){let t=e.pmViewDesc;return t&&t.node&&t.node.isBlock}function rt(e,t,n){if(3!=t.nodeType){let e,o;(o=function(e,t){for(;e&&t==e.childNodes.length&&!ve(e);)t=ge(e)+1,e=e.parentNode;for(;e&&t<e.childNodes.length;){let n=e.childNodes[t];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=n,t=0}}(t,n))?(t=o,n=0):(e=function(e,t){for(;e&&!t&&!ve(e);)t=ge(e),e=e.parentNode;for(;e&&t;){let n=e.childNodes[t-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=(e=n).childNodes.length}}(t,n))&&(t=e,n=e.nodeValue.length)}let o=e.domSelection();if(!o)return;if(ke(o)){let e=document.createRange();e.setEnd(t,n),e.setStart(t,n),o.removeAllRanges(),o.addRange(e)}else o.extend&&o.extend(t,n);e.domObserver.setCurSelection();let{state:i}=e;setTimeout((()=>{e.state==i&&We(e)}),50)}function mt(e,t){let n=e.state.doc.resolve(t);if(!ze&&!qe&&n.parent.inlineContent){let o=e.coordsAtPos(t);if(t>n.start()){let n=e.coordsAtPos(t-1),i=(n.top+n.bottom)/2;if(i>o.top&&i<o.bottom&&Math.abs(n.left-o.left)>1)return n.left<o.left?"ltr":"rtl"}if(t<n.end()){let n=e.coordsAtPos(t+1),i=(n.top+n.bottom)/2;if(i>o.top&&i<o.bottom&&Math.abs(n.left-o.left)>1)return n.left>o.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(e.dom).direction?"rtl":"ltr"}function st(e,t,n){let o=e.state.selection;if(o instanceof te&&!o.empty||n.indexOf("s")>-1)return!1;if(Le&&n.indexOf("m")>-1)return!1;let{$from:i,$to:a}=o;if(!i.parent.inlineContent||e.endOfTextblock(t<0?"up":"down")){let n=Ze(e.state,t);if(n&&n instanceof oe)return et(e,n)}if(!i.parent.inlineContent){let n=t<0?i:a,r=o instanceof ae?Y.near(n,t):Y.findFrom(n,t);return!!r&&et(e,r)}return!1}function lt(e,t){if(!(e.state.selection instanceof te))return!0;let{$head:n,$anchor:o,empty:i}=e.state.selection;if(!n.sameParent(o))return!0;if(!i)return!1;if(e.endOfTextblock(t>0?"forward":"backward"))return!0;let a=!n.textOffset&&(t<0?n.nodeBefore:n.nodeAfter);if(a&&!a.isText){let o=e.state.tr;return t<0?o.delete(n.pos-a.nodeSize,n.pos):o.delete(n.pos,n.pos+a.nodeSize),e.dispatch(o),!0}return!1}function ct(e,t,n){e.domObserver.stop(),