medium-proeditor
Version:
A powerful & customizable Medium-style rich text editor
1 lines • 271 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).CodeBlock={})}(this,(function(e){"use strict";function t(e,n,i){for(let r=0;;r++){if(r==e.childCount||r==n.childCount)return e.childCount==n.childCount?null:i;let o=e.child(r),a=n.child(r);if(o!=a){if(!o.sameMarkup(a))return i;if(o.isText&&o.text!=a.text){for(let e=0;o.text[e]==a.text[e];e++)i++;return i}if(o.content.size||a.content.size){let e=t(o.content,a.content,i+1);if(null!=e)return e}i+=o.nodeSize}else i+=o.nodeSize}}function n(e,t,i,r){for(let o=e.childCount,a=t.childCount;;){if(0==o||0==a)return o==a?null:{a:i,b:r};let s=e.child(--o),l=t.child(--a),c=s.nodeSize;if(s!=l){if(!s.sameMarkup(l))return{a:i,b:r};if(s.isText&&s.text!=l.text){let e=0,t=Math.min(s.text.length,l.text.length);for(;e<t&&s.text[s.text.length-e-1]==l.text[l.text.length-e-1];)e++,i--,r--;return{a:i,b:r}}if(s.content.size||l.content.size){let e=n(s.content,l.content,i-1,r-1);if(e)return e}i-=c,r-=c}else i-=c,r-=c}}class i{constructor(e,t){if(this.content=e,this.size=t||0,null==t)for(let t=0;t<e.length;t++)this.size+=e[t].nodeSize}nodesBetween(e,t,n,i=0,r){for(let o=0,a=0;a<t;o++){let s=this.content[o],l=a+s.nodeSize;if(l>e&&!1!==n(s,i+a,r||null,o)&&s.content.size){let r=a+1;s.nodesBetween(Math.max(0,e-r),Math.min(s.content.size,t-r),n,i+r)}a=l}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,n,i){let r="",o=!0;return this.nodesBetween(e,t,((a,s)=>{let l=a.isText?a.text.slice(Math.max(e,s)-s,t-s):a.isLeaf?i?"function"==typeof i?i(a):i:a.type.spec.leafText?a.type.spec.leafText(a):"":"";a.isBlock&&(a.isLeaf&&l||a.isTextblock)&&n&&(o?o=!1:r+=n),r+=l}),0),r}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,n=e.firstChild,r=this.content.slice(),o=0;for(t.isText&&t.sameMarkup(n)&&(r[r.length-1]=t.withText(t.text+n.text),o=1);o<e.content.length;o++)r.push(e.content[o]);return new i(r,this.size+e.size)}cut(e,t=this.size){if(0==e&&t==this.size)return this;let n=[],r=0;if(t>e)for(let i=0,o=0;o<t;i++){let a=this.content[i],s=o+a.nodeSize;s>e&&((o<e||s>t)&&(a=a.isText?a.cut(Math.max(0,e-o),Math.min(a.text.length,t-o)):a.cut(Math.max(0,e-o-1),Math.min(a.content.size,t-o-1))),n.push(a),r+=a.nodeSize),o=s}return new i(n,r)}cutByIndex(e,t){return e==t?i.empty:0==e&&t==this.content.length?this:new i(this.content.slice(e,t))}replaceChild(e,t){let n=this.content[e];if(n==t)return this;let r=this.content.slice(),o=this.size+t.nodeSize-n.nodeSize;return r[e]=t,new i(r,o)}addToStart(e){return new i([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new i(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;t<this.content.length;t++)if(!this.content[t].eq(e.content[t]))return!1;return!0}get firstChild(){return this.content.length?this.content[0]:null}get lastChild(){return this.content.length?this.content[this.content.length-1]:null}get childCount(){return this.content.length}child(e){let t=this.content[e];if(!t)throw new RangeError("Index "+e+" out of range for "+this);return t}maybeChild(e){return this.content[e]||null}forEach(e){for(let t=0,n=0;t<this.content.length;t++){let i=this.content[t];e(i,n,t),n+=i.nodeSize}}findDiffStart(e,n=0){return t(this,e,n)}findDiffEnd(e,t=this.size,i=e.size){return n(this,e,t,i)}findIndex(e,t=-1){if(0==e)return o(0,e);if(e==this.size)return o(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 r=i+this.child(n).nodeSize;if(r>=e)return r==e||t>0?o(n+1,r):o(n,i);i=r}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((e=>e.toJSON())):null}static fromJSON(e,t){if(!t)return i.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new i(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return i.empty;let t,n=0;for(let i=0;i<e.length;i++){let r=e[i];n+=r.nodeSize,i&&r.isText&&e[i-1].sameMarkup(r)?(t||(t=e.slice(0,i)),t[t.length-1]=r.withText(t[t.length-1].text+r.text)):t&&t.push(r)}return new i(t||e,n)}static from(e){if(!e)return i.empty;if(e instanceof i)return e;if(Array.isArray(e))return this.fromArray(e);if(e.attrs)return new i([e],e.nodeSize);throw new RangeError("Can not convert "+e+" to a Fragment"+(e.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}i.empty=new i([],0);const r={index:0,offset:0};function o(e,t){return r.index=e,r.offset=t,r}function a(e,t){if(e===t)return!0;if(!e||"object"!=typeof e||!t||"object"!=typeof t)return!1;let n=Array.isArray(e);if(Array.isArray(t)!=n)return!1;if(n){if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!a(e[n],t[n]))return!1}else{for(let n in e)if(!(n in t)||!a(e[n],t[n]))return!1;for(let n in t)if(!(n in e))return!1}return!0}class s{constructor(e,t){this.type=e,this.attrs=t}addToSet(e){let t,n=!1;for(let i=0;i<e.length;i++){let r=e[i];if(this.eq(r))return e;if(this.type.excludes(r.type))t||(t=e.slice(0,i));else{if(r.type.excludes(this.type))return e;!n&&r.type.rank>this.type.rank&&(t||(t=e.slice(0,i)),t.push(this),n=!0),t&&t.push(r)}}return t||(t=e.slice()),n||t.push(this),t}removeFromSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return e.slice(0,t).concat(e.slice(t+1));return e}isInSet(e){for(let t=0;t<e.length;t++)if(this.eq(e[t]))return!0;return!1}eq(e){return this==e||this.type==e.type&&a(this.attrs,e.attrs)}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Mark.fromJSON");let n=e.marks[t.type];if(!n)throw new RangeError(`There is no mark type ${t.type} in this schema`);let i=n.create(t.attrs);return n.checkAttrs(i.attrs),i}static sameSet(e,t){if(e==t)return!0;if(e.length!=t.length)return!1;for(let n=0;n<e.length;n++)if(!e[n].eq(t[n]))return!1;return!0}static setFrom(e){if(!e||Array.isArray(e)&&0==e.length)return s.none;if(e instanceof s)return[e];let t=e.slice();return t.sort(((e,t)=>e.type.rank-t.type.rank)),t}}s.none=[];class l extends Error{}class c{constructor(e,t,n){this.content=e,this.openStart=t,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let n=u(this.content,e+this.openStart,t);return n&&new c(n,this.openStart,this.openEnd)}removeBetween(e,t){return new c(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 c.empty;let n=t.openStart||0,r=t.openEnd||0;if("number"!=typeof n||"number"!=typeof r)throw new RangeError("Invalid input for Slice.fromJSON");return new c(i.fromJSON(e,t.content),n,r)}static maxOpen(e,t=!0){let n=0,i=0;for(let i=e.firstChild;i&&!i.isLeaf&&(t||!i.type.spec.isolating);i=i.firstChild)n++;for(let n=e.lastChild;n&&!n.isLeaf&&(t||!n.type.spec.isolating);n=n.lastChild)i++;return new c(e,n,i)}}function d(e,t,n){let{index:i,offset:r}=e.findIndex(t),o=e.maybeChild(i),{index:a,offset:s}=e.findIndex(n);if(r==t||o.isText){if(s!=n&&!e.child(a).isText)throw new RangeError("Removing non-flat range");return e.cut(0,t).append(e.cut(n))}if(i!=a)throw new RangeError("Removing non-flat range");return e.replaceChild(i,o.copy(d(o.content,t-r-1,n-r-1)))}function u(e,t,n,i){let{index:r,offset:o}=e.findIndex(t),a=e.maybeChild(r);if(o==t||a.isText)return i&&!i.canReplace(r,r,n)?null:e.cut(0,t).append(n).append(e.cut(t));let s=u(a.content,t-o-1,n);return s&&e.replaceChild(r,a.copy(s))}c.empty=new c(i.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 y(this,t,!1);return n.addAll(e,s.none,t.from,t.to),n.finish()}parseSlice(e,t={}){let n=new y(this,t,!0);return n.addAll(e,s.none,t.from,t.to),c.maxOpen(n.finish())}matchTag(e,t,n){for(let i=n?this.tags.indexOf(n)+1:0;i<this.tags.length;i++){let n=this.tags[i];if(w(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 r=i?this.styles.indexOf(i)+1:0;r<this.styles.length;r++){let i=this.styles[r],o=i.style;if(!(0!=o.indexOf(e)||i.context&&!n.matchesContext(i.context)||o.length>e.length&&(61!=o.charCodeAt(e.length)||o.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=v(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=v(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 h={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},f={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},m={ol:!0,ul:!0};function g(e,t,n){return null!=t?(t?1:0)|("full"===t?2:0):e&&"pre"==e.whitespace?3:-5&n}class b{constructor(e,t,n,i,r,o){this.type=e,this.attrs=t,this.marks=n,this.solid=i,this.options=o,this.content=[],this.activeMarks=s.none,this.match=r||(4&o?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(i.from(e));if(!t){let t,n=this.type.contentMatch;return(t=n.findWrapping(e.type))?(this.match=n,t):null}this.match=this.type.contentMatch.matchFragment(t)}return this.match.findWrapping(e.type)}finish(e){if(!(1&this.options)){let e,t=this.content[this.content.length-1];if(t&&t.isText&&(e=/[ \t\r\n\u000c]+$/.exec(t.text))){let n=t;t.text.length==e[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-e[0].length))}}let t=i.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(i.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}inlineContext(e){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:e.parentNode&&!h.hasOwnProperty(e.parentNode.nodeName.toLowerCase())}}class y{constructor(e,t,n){this.parser=e,this.options=t,this.isOpen=n,this.open=0,this.localPreserveWS=!1;let i,r=t.topNode,o=g(null,t.preserveWhitespace,0)|(n?4:0);i=r?new b(r.type,r.attrs,s.none,!0,t.topMatch||r.type.contentMatch,o):new b(n?null:e.schema.topNodeType,null,s.none,!0,null,o),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,r=2&i.options?"full":this.localPreserveWS||(1&i.options)>0;if("full"===r||i.inlineContext(e)||/[^ \t\r\n\u000c]/.test(n)){if(r)n="full"!==r?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],r=e.previousSibling;(!t||r&&"BR"==r.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,r=this.top;("PRE"==e.tagName||/pre/.test(e.style&&e.style.whiteSpace))&&(this.localPreserveWS=!0);let o,a=e.nodeName.toLowerCase();m.hasOwnProperty(a)&&this.parser.normalizeLists&&function(e){for(let t=e.firstChild,n=null;t;t=t.nextSibling){let e=1==t.nodeType?t.nodeName.toLowerCase():null;e&&m.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)||(o=this.parser.matchTag(e,this,n));e:if(s?s.ignore:f.hasOwnProperty(a))this.findInside(e),this.ignoreFallback(e,t);else if(!s||s.skip||s.closeParent){s&&s.closeParent?this.open=Math.max(0,this.open-1):s&&s.skip.nodeType&&(e=s.skip);let n,i=this.needsBlock;if(h.hasOwnProperty(a))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),n=!0,r.type||(this.needsBlock=!0);else if(!e.firstChild){this.leafFallback(e,t);break e}let o=s&&s.skip?t:this.readStyles(e,t);o&&this.addAll(e,o),n&&this.sync(r),this.needsBlock=i}else{let n=this.readStyles(e,t);n&&this.addElementByRule(e,s,n,!1===s.consuming?o: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],r=n.getPropertyValue(i);if(r)for(let e;;){let n=this.parser.matchStyle(i,r,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 r,o;if(t.node)if(o=this.parser.schema.nodes[t.node],o.isLeaf)this.insertNode(o.create(t.attrs),n)||this.leafFallback(e,n);else{let e=this.enter(o,t.attrs||null,n,t.preserveWhitespace);e&&(r=!0,n=e)}else{let e=this.parser.schema.marks[t.mark];n=n.concat(e.create(t.attrs))}let a=this.top;if(o&&o.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)}r&&this.sync(a)&&this.open--}addAll(e,t,n,i){let r=n||0;for(let o=n?e.childNodes[n]:e.firstChild,a=null==i?null:e.childNodes[i];o!=a;o=o.nextSibling,++r)this.findAtPoint(e,r),this.addDOM(o,t);this.findAtPoint(e,r)}findPlace(e,t){let n,i;for(let t=this.open;t>=0;t--){let r=this.nodes[t],o=r.findWrapping(e);if(o&&(!n||n.length>o.length)&&(n=o,i=r,!o.length))break;if(r.solid)break}if(!n)return null;this.sync(i);for(let e=0;e<n.length;e++)t=this.enterInner(n[e],null,t,!1);return t}insertNode(e,t){if(e.isInline&&this.needsBlock&&!this.top.type){let e=this.textblockFromContext();e&&(t=this.enterInner(e,null,t))}let n=this.findPlace(e,t);if(n){this.closeExtra();let t=this.top;t.match&&(t.match=t.match.matchType(e.type));let i=s.none;for(let r of n.concat(e.marks))(t.type?t.type.allowsMarkType(r.type):_(r.type,e.type))&&(i=r.addToSet(i));return t.content.push(e.mark(i)),!0}return!1}enter(e,t,n,i){let r=this.findPlace(e.create(t),n);return r&&(r=this.enterInner(e,t,n,!0,i)),r}enterInner(e,t,n,i=!1,r){this.closeExtra();let o=this.top;o.match=o.match&&o.match.matchType(e);let a=g(e,r,o.options);4&o.options&&0==o.content.length&&(a|=4);let l=s.none;return n=n.filter((t=>!(o.type?o.type.allowsMarkType(t.type):_(t.type,e))||(l=t.addToSet(l),!1))),this.nodes.push(new b(e,t,l,i,null,a)),this.open++,n}closeExtra(e=!1){let t=this.nodes.length-1;if(t>this.open){for(;t>this.open;t--)this.nodes[t-1].content.push(this.nodes[t].finish(e));this.nodes.length=this.open+1}}finish(){return this.open=0,this.closeExtra(this.isOpen),this.nodes[0].finish(!(!this.isOpen&&!this.options.topOpen))}sync(e){for(let t=this.open;t>=0;t--){if(this.nodes[t]==e)return this.open=t,!0;this.localPreserveWS&&(this.nodes[t].options|=1)}return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let n=this.nodes[t].content;for(let t=n.length-1;t>=0;t--)e+=n[t].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==e&&this.find[n].offset==t&&(this.find[n].pos=this.currentPos)}findInside(e){if(this.find)for(let t=0;t<this.find.length;t++)null==this.find[t].pos&&1==e.nodeType&&e.contains(this.find[t].node)&&(this.find[t].pos=this.currentPos)}findAround(e,t,n){if(e!=t&&this.find)for(let i=0;i<this.find.length;i++)if(null==this.find[i].pos&&1==e.nodeType&&e.contains(this.find[i].node)){t.compareDocumentPosition(this.find[i].node)&(n?2:4)&&(this.find[i].pos=this.currentPos)}}findInText(e){if(this.find)for(let t=0;t<this.find.length;t++)this.find[t].node==e&&(this.find[t].pos=this.currentPos-(e.nodeValue.length-this.find[t].offset))}matchesContext(e){if(e.indexOf("|")>-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),n=this.options.context,i=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),r=-(n?n.depth+1:0)+(i?0:1),o=(e,a)=>{for(;e>=0;e--){let s=t[e];if(""==s){if(e==t.length-1||0==e)continue;for(;a>=r;a--)if(o(e-1,a))return!0;return!1}{let e=a>0||0==a&&i?this.nodes[a].type:n&&a>=r?n.node(a-r).type:null;if(!e||e.name!=s&&!e.isInGroup(s))return!1;a--}}return!0};return o(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 w(e,t){return(e.matches||e.msMatchesSelector||e.webkitMatchesSelector||e.mozMatchesSelector).call(e,t)}function v(e){let t={};for(let n in e)t[n]=e[n];return t}function _(e,t){let n=t.schema.nodes;for(let i in n){let r=n[i];if(!r.allowsMarkType(e))continue;let o=[],a=e=>{o.push(e);for(let n=0;n<e.edgeCount;n++){let{type:i,next:r}=e.edge(n);if(i==t)return!0;if(o.indexOf(r)<0&&a(r))return!0}};if(a(r.contentMatch))return!0}}class E{constructor(e,t){this.nodes=e,this.marks=t}serializeFragment(e,t={},n){n||(n=x(t).createDocumentFragment());let i=n,r=[];return e.forEach((e=>{if(r.length||e.marks.length){let n=0,o=0;for(;n<r.length&&o<e.marks.length;){let t=e.marks[o];if(this.marks[t.type.name]){if(!t.eq(r[n][0])||!1===t.type.spec.spanning)break;n++,o++}else o++}for(;n<r.length;)i=r.pop()[1];for(;o<e.marks.length;){let n=e.marks[o++],a=this.serializeMark(n,e.isInline,t);a&&(r.push([n,i]),i.appendChild(a.dom),i=a.contentDOM||a.dom)}}i.appendChild(this.serializeNodeInner(e,t))})),n}serializeNodeInner(e,t){let{dom:n,contentDOM:i}=O(x(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 r=this.serializeMark(e.marks[i],e.isInline,t);r&&((r.contentDOM||r.dom).appendChild(n),n=r.dom)}return n}serializeMark(e,t,n={}){let i=this.marks[e.type.name];return i&&O(x(n),i(e,t),null,e.attrs)}static renderSpec(e,t,n=null,i){return O(e,t,n,i)}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new E(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=k(e.nodes);return t.text||(t.text=e=>e.text),t}static marksFromSchema(e){return k(e.marks)}}function k(e){let t={};for(let n in e){let i=e[n].spec.toDOM;i&&(t[n]=i)}return t}function x(e){return e.document||window.document}const N=new WeakMap;function S(e){let t=N.get(e);return void 0===t&&N.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 O(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 r,o=t[0];if("string"!=typeof o)throw new RangeError("Invalid array passed to renderSpec");if(i&&(r=S(i))&&r.indexOf(t)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let a,s=o.indexOf(" ");s>0&&(n=o.slice(0,s),o=o.slice(s+1));let l=n?e.createElementNS(n,o):e.createElement(o),c=t[1],d=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){d=2;for(let e in c)if(null!=c[e]){let t=e.indexOf(" ");t>0?l.setAttributeNS(e.slice(0,t),e.slice(t+1),c[e]):l.setAttribute(e,c[e])}}for(let r=d;r<t.length;r++){let o=t[r];if(0===o){if(r<t.length-1||r>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}{let{dom:t,contentDOM:r}=O(e,o,n,i);if(l.appendChild(t),r){if(a)throw new RangeError("Multiple content holes");a=r}}}return{dom:l,contentDOM:a}}const C=Math.pow(2,16);function M(e,t){return e+t*C}function A(e){return 65535&e}class T{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 R{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&R.empty)return R.empty}recover(e){let t=0,n=A(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))/C}(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,r=this.inverted?2:1,o=this.inverted?1:2;for(let a=0;a<this.ranges.length;a+=3){let s=this.ranges[a]-(this.inverted?i:0);if(s>e)break;let l=this.ranges[a+r],c=this.ranges[a+o],d=s+l;if(e<=d){let r=s+i+((l?e==s?-1:e==d?1:t:t)<0?0:c);if(n)return r;let o=e==(t<0?s:d)?null:M(a/3,e-s),u=e==s?2:e==d?1:4;return(t<0?e!=s:e!=d)&&(u|=8),new T(r,u,o)}i+=c-l}return n?e+i:new T(e+i,0,null)}touches(e,t){let n=0,i=A(t),r=this.inverted?2:1,o=this.inverted?1:2;for(let t=0;t<this.ranges.length;t+=3){let a=this.ranges[t]-(this.inverted?n:0);if(a>e)break;let s=this.ranges[t+r];if(e<=a+s&&t==3*i)return!0;n+=this.ranges[t+o]-s}return!1}forEach(e){let t=this.inverted?2:1,n=this.inverted?1:2;for(let i=0,r=0;i<this.ranges.length;i+=3){let o=this.ranges[i],a=o-(this.inverted?r:0),s=o+(this.inverted?0:r),l=this.ranges[i+t],c=this.ranges[i+n];e(a,a+l,s,s+c),r+=c-l}}invert(){return new R(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(e){return 0==e?R.empty:new R(e<0?[0,-e,0]:[0,0,e])}}R.empty=new R([]);const D=Object.create(null);class I{getMap(){return R.empty}merge(e){return null}static fromJSON(e,t){if(!t||!t.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=D[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 D)throw new RangeError("Duplicate use of step JSON ID "+e);return D[e]=t,t.prototype.jsonID=e,t}}class L{constructor(e,t){this.doc=e,this.failed=t}static ok(e){return new L(e,null)}static fail(e){return new L(null,e)}static fromReplace(e,t,n,i){try{return L.ok(e.replace(t,n,i))}catch(e){if(e instanceof l)return L.fail(e.message);throw e}}}function B(e,t,n){let r=[];for(let i=0;i<e.childCount;i++){let o=e.child(i);o.content.size&&(o=o.copy(B(o.content,t,o))),o.isInline&&(o=t(o,n,i)),r.push(o)}return i.fromArray(r)}class z extends I{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)),r=new c(B(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 L.fromReplace(e,this.from,this.to,r)}invert(){return new $(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 z(t.pos,n.pos,this.mark)}merge(e){return e instanceof z&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new z(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 z(t.from,t.to,e.markFromJSON(t.mark))}}I.jsonID("addMark",z);class $ extends I{constructor(e,t,n){super(),this.from=e,this.to=t,this.mark=n}apply(e){let t=e.slice(this.from,this.to),n=new c(B(t.content,(e=>e.mark(this.mark.removeFromSet(e.marks))),e),t.openStart,t.openEnd);return L.fromReplace(e,this.from,this.to,n)}invert(){return new z(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 $(t.pos,n.pos,this.mark)}merge(e){return e instanceof $&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new $(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 $(t.from,t.to,e.markFromJSON(t.mark))}}I.jsonID("removeMark",$);class F extends I{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return L.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return L.fromReplace(e,this.pos,this.pos+1,new c(i.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let e=this.mark.addToSet(t.marks);if(e.length==t.marks.length){for(let n=0;n<t.marks.length;n++)if(!t.marks[n].isInSet(e))return new F(this.pos,t.marks[n]);return new F(this.pos,this.mark)}}return new P(this.pos,this.mark)}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new F(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 F(t.pos,e.markFromJSON(t.mark))}}I.jsonID("addNodeMark",F);class P extends I{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return L.fail("No node at mark step's position");let n=t.type.create(t.attrs,null,this.mark.removeFromSet(t.marks));return L.fromReplace(e,this.pos,this.pos+1,new c(i.from(n),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);return t&&this.mark.isInSet(t.marks)?new F(this.pos,this.mark):this}map(e){let t=e.mapResult(this.pos,1);return t.deletedAfter?null:new P(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 P(t.pos,e.markFromJSON(t.mark))}}I.jsonID("removeNodeMark",P);class j extends I{constructor(e,t,n,i=!1){super(),this.from=e,this.to=t,this.slice=n,this.structure=i}apply(e){return this.structure&&K(e,this.from,this.to)?L.fail("Structure replace would overwrite content"):L.fromReplace(e,this.from,this.to,this.slice)}getMap(){return new R([this.from,this.to-this.from,this.slice.size])}invert(e){return new j(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 j(t.pos,Math.max(t.pos,n.pos),this.slice)}merge(e){if(!(e instanceof j)||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?c.empty:new c(e.slice.content.append(this.slice.content),e.slice.openStart,this.slice.openEnd);return new j(e.from,this.to,t,this.structure)}}{let t=this.slice.size+e.slice.size==0?c.empty:new c(this.slice.content.append(e.slice.content),this.slice.openStart,e.slice.openEnd);return new j(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 j(t.from,t.to,c.fromJSON(e,t.slice),!!t.structure)}}I.jsonID("replace",j);class U extends I{constructor(e,t,n,i,r,o,a=!1){super(),this.from=e,this.to=t,this.gapFrom=n,this.gapTo=i,this.slice=r,this.insert=o,this.structure=a}apply(e){if(this.structure&&(K(e,this.from,this.gapFrom)||K(e,this.gapTo,this.to)))return L.fail("Structure gap-replace would overwrite content");let t=e.slice(this.gapFrom,this.gapTo);if(t.openStart||t.openEnd)return L.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,t.content);return n?L.fromReplace(e,this.from,this.to,n):L.fail("Content does not fit in gap")}getMap(){return new R([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 U(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),r=this.to==this.gapTo?n.pos:e.map(this.gapTo,1);return t.deletedAcross&&n.deletedAcross||i<t.pos||r>n.pos?null:new U(t.pos,n.pos,i,r,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 U(t.from,t.to,t.gapFrom,t.gapTo,c.fromJSON(e,t.slice),t.insert,!!t.structure)}}function K(e,t,n){let i=e.resolve(t),r=n-t,o=i.depth;for(;r>0&&o>0&&i.indexAfter(o)==i.node(o).childCount;)o--,r--;if(r>0){let e=i.node(o).maybeChild(i.indexAfter(o));for(;r>0;){if(!e||e.isLeaf)return!0;e=e.firstChild,r--}}return!1}I.jsonID("replaceAround",U);class q extends I{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 L.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 r=t.type.create(n,null,t.marks);return L.fromReplace(e,this.pos,this.pos+1,new c(i.from(r),0,t.isLeaf?0:1))}getMap(){return R.empty}invert(e){return new q(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 q(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 q(t.pos,t.attr,t.value)}}I.jsonID("attr",q);class H extends I{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 L.ok(n)}getMap(){return R.empty}invert(e){return new H(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 H(t.attr,t.value)}}I.jsonID("docAttr",H);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 Z=Object.create(null);class W{constructor(e,t,n){this.$anchor=e,this.$head=t,this.ranges=n||[new J(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=c.empty){let n=t.content.lastChild,i=null;for(let e=0;e<t.openEnd;e++)i=n,n=n.lastChild;let r=e.steps.length,o=this.ranges;for(let a=0;a<o.length;a++){let{$from:s,$to:l}=o[a],d=e.mapping.slice(r);e.replaceRange(d.map(s.pos),d.map(l.pos),a?c.empty:t),0==a&&oe(e,r,(n?n.isInline:i&&i.isTextblock)?-1:1)}}replaceWith(e,t){let n=e.steps.length,i=this.ranges;for(let r=0;r<i.length;r++){let{$from:o,$to:a}=i[r],s=e.mapping.slice(n),l=s.map(o.pos),c=s.map(a.pos);r?e.deleteRange(l,c):(e.replaceRangeWith(l,c,t),oe(e,n,t.isInline?-1:1))}}static findFrom(e,t,n=!1){let i=e.parent.inlineContent?new Q(e):re(e.node(0),e.parent,e.pos,e.index(),t,n);if(i)return i;for(let i=e.depth-1;i>=0;i--){let r=t<0?re(e.node(0),e.node(i),e.before(i+1),e.index(i),t,n):re(e.node(0),e.node(i),e.after(i+1),e.index(i)+1,t,n);if(r)return r}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new ne(e.node(0))}static atStart(e){return re(e,e,0,0,1)||new ne(e)}static atEnd(e){return re(e,e,e.content.size,e.childCount,-1)||new ne(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=Z[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 Z)throw new RangeError("Duplicate use of selection JSON ID "+e);return Z[e]=t,t.prototype.jsonID=e,t}getBookmark(){return Q.between(this.$anchor,this.$head).getBookmark()}}W.prototype.visible=!0;class J{constructor(e,t){this.$from=e,this.$to=t}}let V=!1;function X(e){V||e.parent.inlineContent||(V=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+e.parent.type.name+")"))}class Q extends W{constructor(e,t=e){X(e),X(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 W.near(n);let i=e.resolve(t.map(this.anchor));return new Q(i.parent.inlineContent?i:n,n)}replace(e,t=c.empty){if(super.replace(e,t),t==c.empty){let t=this.$from.marksAcross(this.$to);t&&e.ensureMarks(t)}}eq(e){return e instanceof Q&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Y(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 Q(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,n=t){let i=e.resolve(t);return new this(i,n==t?i:e.resolve(n))}static between(e,t,n){let i=e.pos-t.pos;if(n&&!i||(n=i>=0?1:-1),!t.parent.inlineContent){let e=W.findFrom(t,n,!0)||W.findFrom(t,-n,!0);if(!e)return W.near(t,n);t=e.$head}return e.parent.inlineContent||(0==i||(e=(W.findFrom(e,-n,!0)||W.findFrom(e,n,!0)).$anchor).pos<t.pos!=i<0)&&(e=t),new Q(e,t)}}W.jsonID("text",Q);class Y{constructor(e,t){this.anchor=e,this.head=t}map(e){return new Y(e.map(this.anchor),e.map(this.head))}resolve(e){return Q.between(e.resolve(this.anchor),e.resolve(this.head))}}class ee extends W{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:i}=t.mapResult(this.anchor),r=e.resolve(i);return n?W.near(r):new ee(r)}content(){return new c(i.from(this.node),0,0)}eq(e){return e instanceof ee&&e.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new te(this.anchor)}static fromJSON(e,t){if("number"!=typeof t.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new ee(e.resolve(t.anchor))}static create(e,t){return new ee(e.resolve(t))}static isSelectable(e){return!e.isText&&!1!==e.type.spec.selectable}}ee.prototype.visible=!1,W.jsonID("node",ee);class te{constructor(e){this.anchor=e}map(e){let{deleted:t,pos:n}=e.mapResult(this.anchor);return t?new Y(n,n):new te(n)}resolve(e){let t=e.resolve(this.anchor),n=t.nodeAfter;return n&&ee.isSelectable(n)?new ee(t):W.near(t)}}class ne extends W{constructor(e){super(e.resolve(0),e.resolve(e.content.size))}replace(e,t=c.empty){if(t==c.empty){e.delete(0,e.doc.content.size);let t=W.atStart(e.doc);t.eq(e.selection)||e.setSelection(t)}else super.replace(e,t)}toJSON(){return{type:"all"}}static fromJSON(e){return new ne(e)}map(e){return new ne(e)}eq(e){return e instanceof ne}getBookmark(){return ie}}W.jsonID("all",ne);const ie={map(){return this},resolve:e=>new ne(e)};function re(e,t,n,i,r,o=!1){if(t.inlineContent)return Q.create(e,n);for(let a=i-(r>0?0:1);r>0?a<t.childCount:a>=0;a+=r){let i=t.child(a);if(i.isAtom){if(!o&&ee.isSelectable(i))return ee.create(e,n-(r<0?i.nodeSize:0))}else{let t=re(e,i,n+r,r<0?i.childCount:0,r,o);if(t)return t}n+=i.nodeSize*r}return null}function oe(e,t,n){let i=e.steps.length-1;if(i<t)return;let r,o=e.steps[i];(o instanceof j||o instanceof U)&&(e.mapping.maps[i].forEach(((e,t,n,i)=>{null==r&&(r=i)})),e.setSelection(W.near(e.doc.resolve(r),n)))}function ae(e,t){return t&&e?e.bind(t):e}class se{constructor(e,t,n){this.name=e,this.init=ae(t.init,n),this.apply=ae(t.apply,n)}}function le(e,t,n){for(let i in e){let r=e[i];r instanceof Function?r=r.bind(t):"handleDOMEvents"==i&&(r=le(r,t,{})),n[i]=r}return n}new se("doc",{init:e=>e.doc||e.schema.topNodeType.createAndFill(),apply:e=>e.doc}),new se("selection",{init:(e,t)=>e.selection||W.atStart(t.doc),apply:e=>e.selection}),new se("storedMarks",{init:e=>e.storedMarks||null,apply:(e,t,n,i)=>i.selection.$cursor?e.storedMarks:null}),new se("scrollToSelection",{init:()=>0,apply:(e,t)=>e.scrolledIntoView?t+1:t});class ce{constructor(e){this.spec=e,this.props={},e.props&&le(e.props,this,this.props),this.key=e.key?e.key.key:ue("plugin")}getState(e){return e[this.key]}}const de=Object.create(null);function ue(e){return e in de?e+"$"+ ++de[e]:(de[e]=0,e+"$")}class pe{constructor(e="key"){this.key=ue(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}}function he(e,t=null){return function(n,i){let r=!1;for(let i=0;i<n.selection.ranges.length&&!r;i++){let{$from:{pos:o},$to:{pos:a}}=n.selection.ranges[i];n.doc.nodesBetween(o,a,((i,o)=>{if(r)return!1;if(i.isTextblock&&!i.hasMarkup(e,t))if(i.type==e)r=!0;else{let t=n.doc.resolve(o),i=t.index();r=t.parent.canReplaceWith(i,i+1,e)}}))}if(!r)return!1;if(i){let r=n.tr;for(let i=0;i<n.selection.ranges.length;i++){let{$from:{pos:o},$to:{pos:a}}=n.selection.ranges[i];r.setBlockType(o,a,e,t)}i(r.scrollIntoView())}return!0}}function fe(e,t,n={}){const{from:i,to:r,empty:o}=e.selection,a=[];e.doc.nodesBetween(i,r,((e,t)=>{if(e.isText)return;const n=Math.max(i,t),o=Math.min(r,t+e.nodeSize);a.push({node:e,from:n,to:o})}));const s=r-i,l=a.filter((e=>!t||t.name===e.node.type.name)).filter((e=>function(e,t){const n=Object.keys(t);return!n.length||n.every((n=>t[n]===e[n]))}(e.node.attrs,n)));if(o)return!!l.length;return l.reduce(((e,t)=>e+t.to-t.from),0)>=s}"undefined"!=typeof navigator?/Mac|iP(hone|[oa]d)/.test(navigator.platform):"undefined"!=typeof os&&os.platform&&os.platform();const me=(e,t,n={})=>(i,r)=>{const o=fe(i,e,n);let a;return i.selection.$anchor.sameParent(i.selection.$head)&&(a=i.selection.$anchor.parent.attrs),o?he(i.schema.nodes[t.name],a)(i,r):he(i.schema.nodes[e.name],{...a,...n})(i,r)};function ge(e){return"Object"===function(e){return Object.prototype.toString.call(e).slice(8,-1)}(e)&&(e.constructor===Object&&Object.getPrototypeOf(e)===Object.prototype)}function be(e,t){const n={...e};if(ge(e)&&ge(t))for(const i of Object.keys(t))ge(t[i])&&ge(e[i])?n[i]=be(e[i],t[i]):n[i]=t[i];return n}class ye{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 ye(e)}configure(e={}){return new ye({...this.config,addOptions:()=>be(this.options,e)})}}const we=["bash","c","cpp","csharp","css","dart","diff","go","graphql","ini","java","javascript","json","kotlin","less","lua","makefile","xml","markdown","objectivec","perl","php","php-template","plaintext","python","python-repl","r","ruby","rust","scss","shell","sql","swift","typescript","vbnet","wasm","yaml"],ve={bash:"Bash",c:"C",cpp:"C++",csharp:"C#",css:"CSS",dart:"Dart",diff:"Diff",go:"Go",graphql:"GraphQL",ini:"TOML, INI",java:"Java",javascript:"JavaScript",json:"JSON",kotlin:"Kotlin",less:"Less",lua:"Lua",makefile:"Makefile",markdown:"Markdown",objectivec:"Objective-C",perl:"Perl",php:"PHP","php-template":"PHP template",plaintext:"Plain Text",python:"Python","python-repl":"python-repl",r:"R",ruby:"Ruby",rust:"Rust",scss:"SCSS",shell:"Shell",sql:"SQL",swift:"Swift",typescript:"TypeScript",vbnet:"VB.NET",wasm:"WebAssembly",xml:"HTML, XML",yaml:"YAML"},_e=function(e){for(var t=0;;t++)if(!(e=e.previousSibling))return t},Ee=function(e,t,n,i){return n&&(xe(e,t,n,i,-1)||xe(e,t,n,i,1))},ke=/^(img|br|input|textarea|hr)$/i;function xe(e,t,n,i,r){for(;;){if(e==n&&t==i)return!0;if(t==(r<0?0:Ne(e))){let n=e.parentNode;if(!n||1!=n.nodeType||Se(e)||ke.test(e.nodeName)||"false"==e.contentEditable)return!1;t=_e(e)+(r<0?0:1),e=n}else{if(1!=e.nodeType)return!1;if("false"==(e=e.childNodes[t+(r<0?-1:0)]).contentEditable)return!1;t=r<0?Ne(e):0}}}function Ne(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function Se(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 Oe=function(e){return e.focusNode&&Ee(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset)};function Ce(e,t){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=e,n.key=n.code=t,n}const Me="undefined"!=typeof navigator?navigator:null,Ae="undefined"!=typeof document?document:null,Te=Me&&Me.userAgent||"",Re=/Edge\/(\d+)/.exec(Te),De=/MSIE \d/.exec(Te),Ie=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Te),Le=!!(De||Ie||Re),Be=De?document.documentMode:Ie?+Ie[1]:Re?+Re[1]:0,ze=!Le&&/gecko\/(\d+)/i.test(Te);ze&&(/Firefox\/(\d+)/.exec(Te)||[0,0])[1];const $e=!Le&&/Chrome\/(\d+)/.exec(Te),Fe=!!$e,Pe=$e?+$e[1]:0,je=!Le&&!!Me&&/Apple Computer/.test(Me.vendor),Ue=je&&(/Mobile\/\w+/.test(Te)||!!Me&&Me.maxTouchPoints>2),Ke=Ue||!!Me&&/Mac/.test(Me.platform),qe=!!Me&&/Win/.test(Me.platform),He=/Android \d/.test(Te),Ge=!!Ae&&"webkitFontSmoothing"in Ae.documentElement.style,Ze=Ge?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function We(e,t=null){let n=e.domSelectionRange(),i=e.state.doc;if(!n.focusNode)return null;let r=e.docView.nearestDesc(n.focusNode),o=r&&0==r.size,a=e.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(a<0)return null;let s,l,c=i.resolve(a);if(Oe(n)){for(s=a;r&&!r.node;)r=r.parent;let e=r.node;if(r&&e.isAtom&&ee.isSelectable(e)&&r.parent&&(!e.isInline||!function(e,t,n){for(let i=0==t,r=t==Ne(e);i||r;){if(e==n)return!0;let t=_e(e);if(!(e=e.parentNode))return!1;i=i&&0==t,r=r&&t==Ne(e)}}(n.focusNode,n.focusOffset,r.dom))){let e=r.posBefore;l=new ee(a==e?c:i.resolve(e))}}else{if(n instanceof e.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let t=a,r=a;for(let i=0;i<n.rangeCount;i++){let o=n.getRangeAt(i);t=Math.min(t,e.docView.posFromDOM(o.startContainer,o.startOffset,1)),r=Math.max(r,e.docView.posFromDOM(o.endContainer,o.endOffset,-1))}if(t<0)return null;[s,a]=r==e.state.selection.anchor?[r,t]:[t,r],c=i.resolve(a)}else s=e.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(s<0)return null}let d=i.resolve(s);if(!l){l=nt(e,d,c,"pointer"==t||e.state.selection.head<c.pos&&!o?1:-1)}return l}function Je(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 Ve(e,t=!1){let n=e.state.selection;if(function(e,t){if(t instanceof ee){let n=e.docView.descAt(t.from);n!=e.lastSelectedViewDesc&&(tt(e),n&&n.selectNode(),e.lastSelectedViewDesc=n)}else tt(e)}(e,n),Je(e)){if(!t&&e.input.mouseDown&&e.input.mouseDown.allowDefault&&Fe){let t=e.domSelectionRange(),n=e.domObserver.currentSelection;if(t.anchorNode&&n.anchorNode&&Ee(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 i=e.cursorWrapper.dom,r="IMG"==i.nodeName;r?n.setStart(i.parentNode,_e(i)+1):n.setStart(i,0);n.collapse(!0),t.removeAllRanges(),t.addRange(n),!r&&!e.state.selection.visible&&Le&&Be<=11&&(i.disabled=!0,i.disabled=!1)}(e);else{let i,r,{anchor:o,head:a}=n;!Xe||n instanceof Q||(n.$from.parent.inlineContent||(i=Qe(e,n.from)),n.empty||n.$from.parent.inlineContent||(r=Qe(e,n.to))),e.docView.setSelection(o,a,e,t),Xe&&(i&&et(i),r&&et(r)),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(),i=n.anchorNode,r=n.anchorOffset;t.addEventListener("selectionchange",e.input.hideSelectionGuard=()=>{n.anchorNode==i&&n.anchorOffset==r||(t.removeEventListener("selectionchange",e.input.hideSelectionGuard),setTimeout((()=>{Je(e)&&!e.state.selection.visible||e.dom.classList.remove("ProseMirror-hideselection")}),20))})}(e))}e.domObserver.setCurSelection(),e.domObserver.connectSelection()}}const Xe=je||Fe&&Pe<63;function Qe(e,t){let{node:n,offset:i}=e.docView.domFromPos(t,0),r=i<n.childNodes.length?n.childNodes[i]:null,o=i?n.childNodes[i-1]:null;if(je&&r&&"false"==r.contentEditable)return Ye(r);if(!(r&&"false"!=r.contentEditable||o&&"false"!=o.contentEditable)){if(r)return Ye(r);if(o)return Ye(o)}}function Ye(e){return e.contentEditable="true",je&&e.draggable&&(e.draggable=!1,e.wasDraggable=!0),e}function et(e){e.contentEditable="false",e.wasDraggable&&(e.draggable=!0,e.wasDraggable=null)}function tt(e){e.lastSelectedViewDesc&&(e.lastSelectedViewDesc.parent&&e.lastSelectedViewDesc.deselectNode(),e.lastSelectedViewDesc=void 0)}function nt(e,t,n,i){return e.someProp("createSelectionBetween",(i=>i(e,t,n)))||Q.between(t,n,i)}function it(e,t){let{$anchor:n,$head:i}=e.selection,r=t>0?n.max(i):n.min(i),o=r.parent.inlineContent?r.depth?e.doc.resolve(t>0?r.after():r.before()):null:r;return o&&W.findFrom(o,t)}function rt(e,t){return e.dispatch(e.state.tr.setSelection(t).scrollIntoView()),!0}function ot(e,t,n){let i=e.state.selection;if(!(i instanceof Q)){if(i instanceof ee&&i.node.isInline)return rt(e,new Q(t>0?i.$to:i.$from));{let n=it(e.state,t);return!!n&&rt(e,n)}}if(n.indexOf("s")>-1){let{$head:n}=i,r=n.textOffset?null:t<0?n.nodeBefore:n.nodeAfter;if(!r||r.isText||!r.isLeaf)return!1;let o=e.state.doc.resolve(n.pos+r.nodeSize*(t<0?-1:1));return rt(e,new Q(i.$anchor,o))}if(!i.empty)return!1;if(e.endOfTextblock(t>0?"forward":"backward")){let n=it(e.state,t);return!!(n&&n instanceof ee)&&rt(e,n)}if(!(Ke&&n.indexOf("m")>-1)){let n,r=i.$head,o=r.textOffset?null:t<0?r.nodeBefore:r.nodeAfter;if(!o||o.isText)return!1;let a=t<0?r.pos-o.nodeSize:r.pos;return!!(o.isAtom||(n=e.docView.descAt(a))&&!n.contentDOM)&&(ee.isSelectable(o)?rt(e,new ee(t<0?e.state.doc.resolve(r.pos-o.nodeSize):r)):!!Ge&&rt(e,new Q(e.state.doc.resolve(t<0?a:a+o.nodeSize))))}}function at(e){return 3==e.nodeType?e.nodeValue.length:e.childNodes.length}function st(e,t){let n=e.pmViewDesc;return n&&0==n.size&&(t<0||e.nextSibling||"BR"!=e.nodeName)}function lt(e,t){return t<0?function(e){let t=e.domSelectionRange(),n=t.focusNode,i=t.focusOffset;if(!n)return;let r,o,a=!1;ze&&1==n.nodeType&&i<at(n)&&st(n.childNodes[i],-1)&&(a=!0);for(;;)if(i>0){if(1!=n.nodeType)break;{let e=n.childNodes[i-1];if(st(e,-1))r=n,o=--i;else{if(3!=e.nodeType)break;n=e,i=n.nodeValue.length}}}else{if(ct(n))break;{let t=n.previousSibling;for(;t&&st(t,-1);)r=n.parentNode,o=_e(t),t=t.previousSibling;if(t)n=t,i=at(n);else{if(n=n.parentNode,n==e.dom)break;i=0}}}a?dt(e,n,i):r&&dt(e,r,o)}(e):function(e){let t=e.domSelectionRange(),n=t.focusNode,i=t.focusOffset;if(!n)return;let r,o,a=at(n);for(;;)if(i<a){if(1!=n.nodeType)break;if(!st(n.childNodes[i],1))break;r=n,o=++i}else{if(ct(n))break;{let t=n.nextSibling;for(;t&&st(t,1);)r=t.parentNode,o=_e(t)+1,t=t.nextSibling;if(t)n=t,i=0,a=at(n);else{if(n=n.parentNode,n==e.dom)break;i=a=0}}}r&&dt(e,r,o)}(e)}function ct(e){let t=e.pmViewDesc;return