@veltdev/tiptap-velt-comments
Version:
Tiptap Extension to add Google Docs-style overlay comments to your Tiptap editor. Works with the Velt Collaboration SDK.
1 lines • 100 kB
JavaScript
import{Mark as t,mergeAttributes as e}from"@tiptap/core";var n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function r(t,e,n,r){return new(n||(n=Promise))((function(o,i){function s(t){try{a(r.next(t))}catch(t){i(t)}}function l(t){try{a(r.throw(t))}catch(t){i(t)}}function a(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(s,l)}a((r=r.apply(t,e||[])).next())}))}function o(t,e){var n,r,o,i={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=l(0),s.throw=l(1),s.return=l(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function l(l){return function(a){return function(l){if(n)throw new TypeError("Generator is already executing.");for(;s&&(s=0,l[0]&&(i=0)),i;)try{if(n=1,r&&(o=2&l[0]?r.return:l[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,l[1])).done)return o;switch(r=0,o&&(l=[2&l[0],o.value]),l[0]){case 0:case 1:o=l;break;case 4:return i.label++,{value:l[1],done:!1};case 5:i.label++,r=l[1],l=[0];continue;case 7:l=i.ops.pop(),i.trys.pop();continue;default:if(!(o=i.trys,(o=o.length>0&&o[o.length-1])||6!==l[0]&&2!==l[0])){i=0;continue}if(3===l[0]&&(!o||l[1]>o[0]&&l[1]<o[3])){i.label=l[1];break}if(6===l[0]&&i.label<o[1]){i.label=o[1],o=l;break}if(o&&i.label<o[2]){i.label=o[2],i.ops.push(l);break}o[2]&&i.ops.pop(),i.trys.pop();continue}l=e.call(t,i)}catch(t){l=[6,t],r=0}finally{n=o=0}if(5&l[0])throw l[1];return{value:l[0]?l[1]:void 0,done:!0}}([l,a])}}}function i(t,e,n){for(let r=0;;r++){if(r==t.childCount||r==e.childCount)return t.childCount==e.childCount?null:n;let o=t.child(r),s=e.child(r);if(o!=s){if(!o.sameMarkup(s))return n;if(o.isText&&o.text!=s.text){for(let t=0;o.text[t]==s.text[t];t++)n++;return n}if(o.content.size||s.content.size){let t=i(o.content,s.content,n+1);if(null!=t)return t}n+=o.nodeSize}else n+=o.nodeSize}}function s(t,e,n,r){for(let o=t.childCount,i=e.childCount;;){if(0==o||0==i)return o==i?null:{a:n,b:r};let l=t.child(--o),a=e.child(--i),c=l.nodeSize;if(l!=a){if(!l.sameMarkup(a))return{a:n,b:r};if(l.isText&&l.text!=a.text){let t=0,e=Math.min(l.text.length,a.text.length);for(;t<e&&l.text[l.text.length-t-1]==a.text[a.text.length-t-1];)t++,n--,r--;return{a:n,b:r}}if(l.content.size||a.content.size){let t=s(l.content,a.content,n-1,r-1);if(t)return t}n-=c,r-=c}else n-=c,r-=c}}"function"==typeof SuppressedError&&SuppressedError;class l{constructor(t,e){if(this.content=t,this.size=e||0,null==e)for(let e=0;e<t.length;e++)this.size+=t[e].nodeSize}nodesBetween(t,e,n,r=0,o){for(let i=0,s=0;s<e;i++){let l=this.content[i],a=s+l.nodeSize;if(a>t&&!1!==n(l,r+s,o||null,i)&&l.content.size){let o=s+1;l.nodesBetween(Math.max(0,t-o),Math.min(l.content.size,e-o),n,r+o)}s=a}}descendants(t){this.nodesBetween(0,this.size,t)}textBetween(t,e,n,r){let o="",i=!0;return this.nodesBetween(t,e,((s,l)=>{let a=s.isText?s.text.slice(Math.max(t,l)-l,e-l):s.isLeaf?r?"function"==typeof r?r(s):r:s.type.spec.leafText?s.type.spec.leafText(s):"":"";s.isBlock&&(s.isLeaf&&a||s.isTextblock)&&n&&(i?i=!1:o+=n),o+=a}),0),o}append(t){if(!t.size)return this;if(!this.size)return t;let e=this.lastChild,n=t.firstChild,r=this.content.slice(),o=0;for(e.isText&&e.sameMarkup(n)&&(r[r.length-1]=e.withText(e.text+n.text),o=1);o<t.content.length;o++)r.push(t.content[o]);return new l(r,this.size+t.size)}cut(t,e=this.size){if(0==t&&e==this.size)return this;let n=[],r=0;if(e>t)for(let o=0,i=0;i<e;o++){let s=this.content[o],l=i+s.nodeSize;l>t&&((i<t||l>e)&&(s=s.isText?s.cut(Math.max(0,t-i),Math.min(s.text.length,e-i)):s.cut(Math.max(0,t-i-1),Math.min(s.content.size,e-i-1))),n.push(s),r+=s.nodeSize),i=l}return new l(n,r)}cutByIndex(t,e){return t==e?l.empty:0==t&&e==this.content.length?this:new l(this.content.slice(t,e))}replaceChild(t,e){let n=this.content[t];if(n==e)return this;let r=this.content.slice(),o=this.size+e.nodeSize-n.nodeSize;return r[t]=e,new l(r,o)}addToStart(t){return new l([t].concat(this.content),this.size+t.nodeSize)}addToEnd(t){return new l(this.content.concat(t),this.size+t.nodeSize)}eq(t){if(this.content.length!=t.content.length)return!1;for(let e=0;e<this.content.length;e++)if(!this.content[e].eq(t.content[e]))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(t){let e=this.content[t];if(!e)throw new RangeError("Index "+t+" out of range for "+this);return e}maybeChild(t){return this.content[t]||null}forEach(t){for(let e=0,n=0;e<this.content.length;e++){let r=this.content[e];t(r,n,e),n+=r.nodeSize}}findDiffStart(t,e=0){return i(this,t,e)}findDiffEnd(t,e=this.size,n=t.size){return s(this,t,e,n)}findIndex(t,e=-1){if(0==t)return c(0,t);if(t==this.size)return c(this.content.length,t);if(t>this.size||t<0)throw new RangeError(`Position ${t} outside of fragment (${this})`);for(let n=0,r=0;;n++){let o=r+this.child(n).nodeSize;if(o>=t)return o==t||e>0?c(n+1,o):c(n,r);r=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map((t=>t.toJSON())):null}static fromJSON(t,e){if(!e)return l.empty;if(!Array.isArray(e))throw new RangeError("Invalid input for Fragment.fromJSON");return new l(e.map(t.nodeFromJSON))}static fromArray(t){if(!t.length)return l.empty;let e,n=0;for(let r=0;r<t.length;r++){let o=t[r];n+=o.nodeSize,r&&o.isText&&t[r-1].sameMarkup(o)?(e||(e=t.slice(0,r)),e[e.length-1]=o.withText(e[e.length-1].text+o.text)):e&&e.push(o)}return new l(e||t,n)}static from(t){if(!t)return l.empty;if(t instanceof l)return t;if(Array.isArray(t))return this.fromArray(t);if(t.attrs)return new l([t],t.nodeSize);throw new RangeError("Can not convert "+t+" to a Fragment"+(t.nodesBetween?" (looks like multiple versions of prosemirror-model were loaded)":""))}}l.empty=new l([],0);const a={index:0,offset:0};function c(t,e){return a.index=t,a.offset=e,a}function d(t,e){if(t===e)return!0;if(!t||"object"!=typeof t||!e||"object"!=typeof e)return!1;let n=Array.isArray(t);if(Array.isArray(e)!=n)return!1;if(n){if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!d(t[n],e[n]))return!1}else{for(let n in t)if(!(n in e)||!d(t[n],e[n]))return!1;for(let n in e)if(!(n in t))return!1}return!0}class h{constructor(t,e){this.type=t,this.attrs=e}addToSet(t){let e,n=!1;for(let r=0;r<t.length;r++){let o=t[r];if(this.eq(o))return t;if(this.type.excludes(o.type))e||(e=t.slice(0,r));else{if(o.type.excludes(this.type))return t;!n&&o.type.rank>this.type.rank&&(e||(e=t.slice(0,r)),e.push(this),n=!0),e&&e.push(o)}}return e||(e=t.slice()),n||e.push(this),e}removeFromSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))return t.slice(0,e).concat(t.slice(e+1));return t}isInSet(t){for(let e=0;e<t.length;e++)if(this.eq(t[e]))return!0;return!1}eq(t){return this==t||this.type==t.type&&d(this.attrs,t.attrs)}toJSON(){let t={type:this.type.name};for(let e in this.attrs){t.attrs=this.attrs;break}return t}static fromJSON(t,e){if(!e)throw new RangeError("Invalid input for Mark.fromJSON");let n=t.marks[e.type];if(!n)throw new RangeError(`There is no mark type ${e.type} in this schema`);let r=n.create(e.attrs);return n.checkAttrs(r.attrs),r}static sameSet(t,e){if(t==e)return!0;if(t.length!=e.length)return!1;for(let n=0;n<t.length;n++)if(!t[n].eq(e[n]))return!1;return!0}static setFrom(t){if(!t||Array.isArray(t)&&0==t.length)return h.none;if(t instanceof h)return[t];let e=t.slice();return e.sort(((t,e)=>t.type.rank-e.type.rank)),e}}h.none=[];class u extends Error{}class f{constructor(t,e,n){this.content=t,this.openStart=e,this.openEnd=n}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(t,e){let n=m(this.content,t+this.openStart,e);return n&&new f(n,this.openStart,this.openEnd)}removeBetween(t,e){return new f(p(this.content,t+this.openStart,e+this.openStart),this.openStart,this.openEnd)}eq(t){return this.content.eq(t.content)&&this.openStart==t.openStart&&this.openEnd==t.openEnd}toString(){return this.content+"("+this.openStart+","+this.openEnd+")"}toJSON(){if(!this.content.size)return null;let t={content:this.content.toJSON()};return this.openStart>0&&(t.openStart=this.openStart),this.openEnd>0&&(t.openEnd=this.openEnd),t}static fromJSON(t,e){if(!e)return f.empty;let n=e.openStart||0,r=e.openEnd||0;if("number"!=typeof n||"number"!=typeof r)throw new RangeError("Invalid input for Slice.fromJSON");return new f(l.fromJSON(t,e.content),n,r)}static maxOpen(t,e=!0){let n=0,r=0;for(let r=t.firstChild;r&&!r.isLeaf&&(e||!r.type.spec.isolating);r=r.firstChild)n++;for(let n=t.lastChild;n&&!n.isLeaf&&(e||!n.type.spec.isolating);n=n.lastChild)r++;return new f(t,n,r)}}function p(t,e,n){let{index:r,offset:o}=t.findIndex(e),i=t.maybeChild(r),{index:s,offset:l}=t.findIndex(n);if(o==e||i.isText){if(l!=n&&!t.child(s).isText)throw new RangeError("Removing non-flat range");return t.cut(0,e).append(t.cut(n))}if(r!=s)throw new RangeError("Removing non-flat range");return t.replaceChild(r,i.copy(p(i.content,e-o-1,n-o-1)))}function m(t,e,n,r){let{index:o,offset:i}=t.findIndex(e),s=t.maybeChild(o);if(i==e||s.isText)return r&&!r.canReplace(o,o,n)?null:t.cut(0,e).append(n).append(t.cut(e));let l=m(s.content,e-i-1,n);return l&&t.replaceChild(o,s.copy(l))}f.empty=new f(l.empty,0,0);class g{constructor(t,e){this.schema=t,this.rules=e,this.tags=[],this.styles=[];let n=this.matchedStyles=[];e.forEach((t=>{if(function(t){return null!=t.tag}(t))this.tags.push(t);else if(function(t){return null!=t.style}(t)){let e=/[^=]*/.exec(t.style)[0];n.indexOf(e)<0&&n.push(e),this.styles.push(t)}})),this.normalizeLists=!this.tags.some((e=>{if(!/^(ul|ol)\b/.test(e.tag)||!e.node)return!1;let n=t.nodes[e.node];return n.contentMatch.matchType(n)}))}parse(t,e={}){let n=new x(this,e,!1);return n.addAll(t,h.none,e.from,e.to),n.finish()}parseSlice(t,e={}){let n=new x(this,e,!0);return n.addAll(t,h.none,e.from,e.to),f.maxOpen(n.finish())}matchTag(t,e,n){for(let r=n?this.tags.indexOf(n)+1:0;r<this.tags.length;r++){let n=this.tags[r];if(C(t,n.tag)&&(void 0===n.namespace||t.namespaceURI==n.namespace)&&(!n.context||e.matchesContext(n.context))){if(n.getAttrs){let e=n.getAttrs(t);if(!1===e)continue;n.attrs=e||void 0}return n}}}matchStyle(t,e,n,r){for(let o=r?this.styles.indexOf(r)+1:0;o<this.styles.length;o++){let r=this.styles[o],i=r.style;if(!(0!=i.indexOf(t)||r.context&&!n.matchesContext(r.context)||i.length>t.length&&(61!=i.charCodeAt(t.length)||i.slice(t.length+1)!=e))){if(r.getAttrs){let t=r.getAttrs(e);if(!1===t)continue;r.attrs=t||void 0}return r}}}static schemaRules(t){let e=[];function n(t){let n=null==t.priority?50:t.priority,r=0;for(;r<e.length;r++){let t=e[r];if((null==t.priority?50:t.priority)<n)break}e.splice(r,0,t)}for(let e in t.marks){let r=t.marks[e].spec.parseDOM;r&&r.forEach((t=>{n(t=T(t)),t.mark||t.ignore||t.clearMark||(t.mark=e)}))}for(let e in t.nodes){let r=t.nodes[e].spec.parseDOM;r&&r.forEach((t=>{n(t=T(t)),t.node||t.ignore||t.mark||(t.node=e)}))}return e}static fromSchema(t){return t.cached.domParser||(t.cached.domParser=new g(t,g.schemaRules(t)))}}const v={address:!0,article:!0,aside:!0,blockquote:!0,canvas:!0,dd:!0,div:!0,dl:!0,fieldset:!0,figcaption:!0,figure:!0,footer:!0,form:!0,h1:!0,h2:!0,h3:!0,h4:!0,h5:!0,h6:!0,header:!0,hgroup:!0,hr:!0,li:!0,noscript:!0,ol:!0,output:!0,p:!0,pre:!0,section:!0,table:!0,tfoot:!0,ul:!0},y={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},w={ol:!0,ul:!0};function S(t,e,n){return null!=e?(e?1:0)|("full"===e?2:0):t&&"pre"==t.whitespace?3:-5&n}class b{constructor(t,e,n,r,o,i){this.type=t,this.attrs=e,this.marks=n,this.solid=r,this.options=i,this.content=[],this.activeMarks=h.none,this.match=o||(4&i?null:t.contentMatch)}findWrapping(t){if(!this.match){if(!this.type)return[];let e=this.type.contentMatch.fillBefore(l.from(t));if(!e){let e,n=this.type.contentMatch;return(e=n.findWrapping(t.type))?(this.match=n,e):null}this.match=this.type.contentMatch.matchFragment(e)}return this.match.findWrapping(t.type)}finish(t){if(!(1&this.options)){let t,e=this.content[this.content.length-1];if(e&&e.isText&&(t=/[ \t\r\n\u000c]+$/.exec(e.text))){let n=e;e.text.length==t[0].length?this.content.pop():this.content[this.content.length-1]=n.withText(n.text.slice(0,n.text.length-t[0].length))}}let e=l.from(this.content);return!t&&this.match&&(e=e.append(this.match.fillBefore(l.empty,!0))),this.type?this.type.create(this.attrs,e,this.marks):e}inlineContext(t){return this.type?this.type.inlineContent:this.content.length?this.content[0].isInline:t.parentNode&&!v.hasOwnProperty(t.parentNode.nodeName.toLowerCase())}}class x{constructor(t,e,n){this.parser=t,this.options=e,this.isOpen=n,this.open=0;let r,o=e.topNode,i=S(null,e.preserveWhitespace,0)|(n?4:0);r=o?new b(o.type,o.attrs,h.none,!0,e.topMatch||o.type.contentMatch,i):new b(n?null:t.schema.topNodeType,null,h.none,!0,null,i),this.nodes=[r],this.find=e.findPositions,this.needsBlock=!1}get top(){return this.nodes[this.open]}addDOM(t,e){3==t.nodeType?this.addTextNode(t,e):1==t.nodeType&&this.addElement(t,e)}addTextNode(t,e){let n=t.nodeValue,r=this.top;if(2&r.options||r.inlineContext(t)||/[^ \t\r\n\u000c]/.test(n)){if(1&r.options)n=2&r.options?n.replace(/\r\n?/g,"\n"):n.replace(/\r?\n|\r/g," ");else if(n=n.replace(/[ \t\r\n\u000c]+/g," "),/^[ \t\r\n\u000c]/.test(n)&&this.open==this.nodes.length-1){let e=r.content[r.content.length-1],o=t.previousSibling;(!e||o&&"BR"==o.nodeName||e.isText&&/[ \t\r\n\u000c]$/.test(e.text))&&(n=n.slice(1))}n&&this.insertNode(this.parser.schema.text(n),e),this.findInText(t)}else this.findInside(t)}addElement(t,e,n){let r,o=t.nodeName.toLowerCase();w.hasOwnProperty(o)&&this.parser.normalizeLists&&function(t){for(let e=t.firstChild,n=null;e;e=e.nextSibling){let t=1==e.nodeType?e.nodeName.toLowerCase():null;t&&w.hasOwnProperty(t)&&n?(n.appendChild(e),e=n):"li"==t?n=e:t&&(n=null)}}(t);let i=this.options.ruleFromNode&&this.options.ruleFromNode(t)||(r=this.parser.matchTag(t,this,n));if(i?i.ignore:y.hasOwnProperty(o))this.findInside(t),this.ignoreFallback(t,e);else if(!i||i.skip||i.closeParent){i&&i.closeParent?this.open=Math.max(0,this.open-1):i&&i.skip.nodeType&&(t=i.skip);let n,r=this.top,s=this.needsBlock;if(v.hasOwnProperty(o))r.content.length&&r.content[0].isInline&&this.open&&(this.open--,r=this.top),n=!0,r.type||(this.needsBlock=!0);else if(!t.firstChild)return void this.leafFallback(t,e);let l=i&&i.skip?e:this.readStyles(t,e);l&&this.addAll(t,l),n&&this.sync(r),this.needsBlock=s}else{let n=this.readStyles(t,e);n&&this.addElementByRule(t,i,n,!1===i.consuming?r:void 0)}}leafFallback(t,e){"BR"==t.nodeName&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(t.ownerDocument.createTextNode("\n"),e)}ignoreFallback(t,e){"BR"!=t.nodeName||this.top.type&&this.top.type.inlineContent||this.findPlace(this.parser.schema.text("-"),e)}readStyles(t,e){let n=t.style;if(n&&n.length)for(let t=0;t<this.parser.matchedStyles.length;t++){let r=this.parser.matchedStyles[t],o=n.getPropertyValue(r);if(o)for(let t;;){let n=this.parser.matchStyle(r,o,this,t);if(!n)break;if(n.ignore)return null;if(e=n.clearMark?e.filter((t=>!n.clearMark(t))):e.concat(this.parser.schema.marks[n.mark].create(n.attrs)),!1!==n.consuming)break;t=n}}return e}addElementByRule(t,e,n,r){let o,i;if(e.node)if(i=this.parser.schema.nodes[e.node],i.isLeaf)this.insertNode(i.create(e.attrs),n)||this.leafFallback(t,n);else{let t=this.enter(i,e.attrs||null,n,e.preserveWhitespace);t&&(o=!0,n=t)}else{let t=this.parser.schema.marks[e.mark];n=n.concat(t.create(e.attrs))}let s=this.top;if(i&&i.isLeaf)this.findInside(t);else if(r)this.addElement(t,n,r);else if(e.getContent)this.findInside(t),e.getContent(t,this.parser.schema).forEach((t=>this.insertNode(t,n)));else{let r=t;"string"==typeof e.contentElement?r=t.querySelector(e.contentElement):"function"==typeof e.contentElement?r=e.contentElement(t):e.contentElement&&(r=e.contentElement),this.findAround(t,r,!0),this.addAll(r,n),this.findAround(t,r,!1)}o&&this.sync(s)&&this.open--}addAll(t,e,n,r){let o=n||0;for(let i=n?t.childNodes[n]:t.firstChild,s=null==r?null:t.childNodes[r];i!=s;i=i.nextSibling,++o)this.findAtPoint(t,o),this.addDOM(i,e);this.findAtPoint(t,o)}findPlace(t,e){let n,r;for(let e=this.open;e>=0;e--){let o=this.nodes[e],i=o.findWrapping(t);if(i&&(!n||n.length>i.length)&&(n=i,r=o,!i.length))break;if(o.solid)break}if(!n)return null;this.sync(r);for(let t=0;t<n.length;t++)e=this.enterInner(n[t],null,e,!1);return e}insertNode(t,e){if(t.isInline&&this.needsBlock&&!this.top.type){let t=this.textblockFromContext();t&&(e=this.enterInner(t,null,e))}let n=this.findPlace(t,e);if(n){this.closeExtra();let e=this.top;e.match&&(e.match=e.match.matchType(t.type));let r=h.none;for(let o of n.concat(t.marks))(e.type?e.type.allowsMarkType(o.type):k(o.type,t.type))&&(r=o.addToSet(r));return e.content.push(t.mark(r)),!0}return!1}enter(t,e,n,r){let o=this.findPlace(t.create(e),n);return o&&(o=this.enterInner(t,e,n,!0,r)),o}enterInner(t,e,n,r=!1,o){this.closeExtra();let i=this.top;i.match=i.match&&i.match.matchType(t);let s=S(t,o,i.options);4&i.options&&0==i.content.length&&(s|=4);let l=h.none;return n=n.filter((e=>!(i.type?i.type.allowsMarkType(e.type):k(e.type,t))||(l=e.addToSet(l),!1))),this.nodes.push(new b(t,e,l,r,null,s)),this.open++,n}closeExtra(t=!1){let e=this.nodes.length-1;if(e>this.open){for(;e>this.open;e--)this.nodes[e-1].content.push(this.nodes[e].finish(t));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(t){for(let e=this.open;e>=0;e--)if(this.nodes[e]==t)return this.open=e,!0;return!1}get currentPos(){this.closeExtra();let t=0;for(let e=this.open;e>=0;e--){let n=this.nodes[e].content;for(let e=n.length-1;e>=0;e--)t+=n[e].nodeSize;e&&t++}return t}findAtPoint(t,e){if(this.find)for(let n=0;n<this.find.length;n++)this.find[n].node==t&&this.find[n].offset==e&&(this.find[n].pos=this.currentPos)}findInside(t){if(this.find)for(let e=0;e<this.find.length;e++)null==this.find[e].pos&&1==t.nodeType&&t.contains(this.find[e].node)&&(this.find[e].pos=this.currentPos)}findAround(t,e,n){if(t!=e&&this.find)for(let r=0;r<this.find.length;r++)if(null==this.find[r].pos&&1==t.nodeType&&t.contains(this.find[r].node)){e.compareDocumentPosition(this.find[r].node)&(n?2:4)&&(this.find[r].pos=this.currentPos)}}findInText(t){if(this.find)for(let e=0;e<this.find.length;e++)this.find[e].node==t&&(this.find[e].pos=this.currentPos-(t.nodeValue.length-this.find[e].offset))}matchesContext(t){if(t.indexOf("|")>-1)return t.split(/\s*\|\s*/).some(this.matchesContext,this);let e=t.split("/"),n=this.options.context,r=!(this.isOpen||n&&n.parent.type!=this.nodes[0].type),o=-(n?n.depth+1:0)+(r?0:1),i=(t,s)=>{for(;t>=0;t--){let l=e[t];if(""==l){if(t==e.length-1||0==t)continue;for(;s>=o;s--)if(i(t-1,s))return!0;return!1}{let t=s>0||0==s&&r?this.nodes[s].type:n&&s>=o?n.node(s-o).type:null;if(!t||t.name!=l&&!t.isInGroup(l))return!1;s--}}return!0};return i(e.length-1,this.open)}textblockFromContext(){let t=this.options.context;if(t)for(let e=t.depth;e>=0;e--){let n=t.node(e).contentMatchAt(t.indexAfter(e)).defaultType;if(n&&n.isTextblock&&n.defaultAttrs)return n}for(let t in this.parser.schema.nodes){let e=this.parser.schema.nodes[t];if(e.isTextblock&&e.defaultAttrs)return e}}}function C(t,e){return(t.matches||t.msMatchesSelector||t.webkitMatchesSelector||t.mozMatchesSelector).call(t,e)}function T(t){let e={};for(let n in t)e[n]=t[n];return e}function k(t,e){let n=e.schema.nodes;for(let r in n){let o=n[r];if(!o.allowsMarkType(t))continue;let i=[],s=t=>{i.push(t);for(let n=0;n<t.edgeCount;n++){let{type:r,next:o}=t.edge(n);if(r==e)return!0;if(i.indexOf(o)<0&&s(o))return!0}};if(s(o.contentMatch))return!0}}class E{constructor(t,e){this.nodes=t,this.marks=e}serializeFragment(t,e={},n){n||(n=N(e).createDocumentFragment());let r=n,o=[];return t.forEach((t=>{if(o.length||t.marks.length){let n=0,i=0;for(;n<o.length&&i<t.marks.length;){let e=t.marks[i];if(this.marks[e.type.name]){if(!e.eq(o[n][0])||!1===e.type.spec.spanning)break;n++,i++}else i++}for(;n<o.length;)r=o.pop()[1];for(;i<t.marks.length;){let n=t.marks[i++],s=this.serializeMark(n,t.isInline,e);s&&(o.push([n,r]),r.appendChild(s.dom),r=s.contentDOM||s.dom)}}r.appendChild(this.serializeNodeInner(t,e))})),n}serializeNodeInner(t,e){let{dom:n,contentDOM:r}=M(N(e),this.nodes[t.type.name](t),null,t.attrs);if(r){if(t.isLeaf)throw new RangeError("Content hole not allowed in a leaf node spec");this.serializeFragment(t.content,e,r)}return n}serializeNode(t,e={}){let n=this.serializeNodeInner(t,e);for(let r=t.marks.length-1;r>=0;r--){let o=this.serializeMark(t.marks[r],t.isInline,e);o&&((o.contentDOM||o.dom).appendChild(n),n=o.dom)}return n}serializeMark(t,e,n={}){let r=this.marks[t.type.name];return r&&M(N(n),r(t,e),null,t.attrs)}static renderSpec(t,e,n=null,r){return M(t,e,n,r)}static fromSchema(t){return t.cached.domSerializer||(t.cached.domSerializer=new E(this.nodesFromSchema(t),this.marksFromSchema(t)))}static nodesFromSchema(t){let e=I(t.nodes);return e.text||(e.text=t=>t.text),e}static marksFromSchema(t){return I(t.marks)}}function I(t){let e={};for(let n in t){let r=t[n].spec.toDOM;r&&(e[n]=r)}return e}function N(t){return t.document||window.document}const O=new WeakMap;function A(t){let e=O.get(t);return void 0===e&&O.set(t,e=function(t){let e=null;function n(t){if(t&&"object"==typeof t)if(Array.isArray(t))if("string"==typeof t[0])e||(e=[]),e.push(t);else for(let e=0;e<t.length;e++)n(t[e]);else for(let e in t)n(t[e])}return n(t),e}(t)),e}function M(t,e,n,r){if("string"==typeof e)return{dom:t.createTextNode(e)};if(null!=e.nodeType)return{dom:e};if(e.dom&&null!=e.dom.nodeType)return e;let o,i=e[0];if("string"!=typeof i)throw new RangeError("Invalid array passed to renderSpec");if(r&&(o=A(r))&&o.indexOf(e)>-1)throw new RangeError("Using an array from an attribute object as a DOM spec. This may be an attempted cross site scripting attack.");let s,l=i.indexOf(" ");l>0&&(n=i.slice(0,l),i=i.slice(l+1));let a=n?t.createElementNS(n,i):t.createElement(i),c=e[1],d=1;if(c&&"object"==typeof c&&null==c.nodeType&&!Array.isArray(c)){d=2;for(let t in c)if(null!=c[t]){let e=t.indexOf(" ");e>0?a.setAttributeNS(t.slice(0,e),t.slice(e+1),c[t]):a.setAttribute(t,c[t])}}for(let o=d;o<e.length;o++){let i=e[o];if(0===i){if(o<e.length-1||o>d)throw new RangeError("Content hole must be the only child of its parent node");return{dom:a,contentDOM:a}}{let{dom:e,contentDOM:o}=M(t,i,n,r);if(a.appendChild(e),o){if(s)throw new RangeError("Multiple content holes");s=o}}}return{dom:a,contentDOM:s}}const D=Math.pow(2,16);function R(t){return 65535&t}class z{constructor(t,e,n){this.pos=t,this.delInfo=e,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 P{constructor(t,e=!1){if(this.ranges=t,this.inverted=e,!t.length&&P.empty)return P.empty}recover(t){let e=0,n=R(t);if(!this.inverted)for(let t=0;t<n;t++)e+=this.ranges[3*t+2]-this.ranges[3*t+1];return this.ranges[3*n]+e+function(t){return(t-(65535&t))/D}(t)}mapResult(t,e=1){return this._map(t,e,!1)}map(t,e=1){return this._map(t,e,!0)}_map(t,e,n){let r=0,o=this.inverted?2:1,i=this.inverted?1:2;for(let s=0;s<this.ranges.length;s+=3){let l=this.ranges[s]-(this.inverted?r:0);if(l>t)break;let a=this.ranges[s+o],c=this.ranges[s+i],d=l+a;if(t<=d){let o=l+r+((a?t==l?-1:t==d?1:e:e)<0?0:c);if(n)return o;let i=t==(e<0?l:d)?null:s/3+(t-l)*D,h=t==l?2:t==d?1:4;return(e<0?t!=l:t!=d)&&(h|=8),new z(o,h,i)}r+=c-a}return n?t+r:new z(t+r,0,null)}touches(t,e){let n=0,r=R(e),o=this.inverted?2:1,i=this.inverted?1:2;for(let e=0;e<this.ranges.length;e+=3){let s=this.ranges[e]-(this.inverted?n:0);if(s>t)break;let l=this.ranges[e+o];if(t<=s+l&&e==3*r)return!0;n+=this.ranges[e+i]-l}return!1}forEach(t){let e=this.inverted?2:1,n=this.inverted?1:2;for(let r=0,o=0;r<this.ranges.length;r+=3){let i=this.ranges[r],s=i-(this.inverted?o:0),l=i+(this.inverted?0:o),a=this.ranges[r+e],c=this.ranges[r+n];t(s,s+a,l,l+c),o+=c-a}}invert(){return new P(this.ranges,!this.inverted)}toString(){return(this.inverted?"-":"")+JSON.stringify(this.ranges)}static offset(t){return 0==t?P.empty:new P(t<0?[0,-t,0]:[0,0,t])}}P.empty=new P([]);const F=Object.create(null);class ${getMap(){return P.empty}merge(t){return null}static fromJSON(t,e){if(!e||!e.stepType)throw new RangeError("Invalid input for Step.fromJSON");let n=F[e.stepType];if(!n)throw new RangeError(`No step type ${e.stepType} defined`);return n.fromJSON(t,e)}static jsonID(t,e){if(t in F)throw new RangeError("Duplicate use of step JSON ID "+t);return F[t]=e,e.prototype.jsonID=t,e}}class J{constructor(t,e){this.doc=t,this.failed=e}static ok(t){return new J(t,null)}static fail(t){return new J(null,t)}static fromReplace(t,e,n,r){try{return J.ok(t.replace(e,n,r))}catch(t){if(t instanceof u)return J.fail(t.message);throw t}}}function V(t,e,n){let r=[];for(let o=0;o<t.childCount;o++){let i=t.child(o);i.content.size&&(i=i.copy(V(i.content,e,i))),i.isInline&&(i=e(i,n,o)),r.push(i)}return l.fromArray(r)}class L extends ${constructor(t,e,n){super(),this.from=t,this.to=e,this.mark=n}apply(t){let e=t.slice(this.from,this.to),n=t.resolve(this.from),r=n.node(n.sharedDepth(this.to)),o=new f(V(e.content,((t,e)=>t.isAtom&&e.type.allowsMarkType(this.mark.type)?t.mark(this.mark.addToSet(t.marks)):t),r),e.openStart,e.openEnd);return J.fromReplace(t,this.from,this.to,o)}invert(){return new B(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1);return e.deleted&&n.deleted||e.pos>=n.pos?null:new L(e.pos,n.pos,this.mark)}merge(t){return t instanceof L&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new L(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"addMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new L(e.from,e.to,t.markFromJSON(e.mark))}}$.jsonID("addMark",L);class B extends ${constructor(t,e,n){super(),this.from=t,this.to=e,this.mark=n}apply(t){let e=t.slice(this.from,this.to),n=new f(V(e.content,(t=>t.mark(this.mark.removeFromSet(t.marks))),t),e.openStart,e.openEnd);return J.fromReplace(t,this.from,this.to,n)}invert(){return new L(this.from,this.to,this.mark)}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1);return e.deleted&&n.deleted||e.pos>=n.pos?null:new B(e.pos,n.pos,this.mark)}merge(t){return t instanceof B&&t.mark.eq(this.mark)&&this.from<=t.to&&this.to>=t.from?new B(Math.min(this.from,t.from),Math.max(this.to,t.to),this.mark):null}toJSON(){return{stepType:"removeMark",mark:this.mark.toJSON(),from:this.from,to:this.to}}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new B(e.from,e.to,t.markFromJSON(e.mark))}}$.jsonID("removeMark",B);class q extends ${constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return J.fail("No node at mark step's position");let n=e.type.create(e.attrs,null,this.mark.addToSet(e.marks));return J.fromReplace(t,this.pos,this.pos+1,new f(l.from(n),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);if(e){let t=this.mark.addToSet(e.marks);if(t.length==e.marks.length){for(let n=0;n<e.marks.length;n++)if(!e.marks[n].isInSet(t))return new q(this.pos,e.marks[n]);return new q(this.pos,this.mark)}}return new j(this.pos,this.mark)}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new q(e.pos,this.mark)}toJSON(){return{stepType:"addNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for AddNodeMarkStep.fromJSON");return new q(e.pos,t.markFromJSON(e.mark))}}$.jsonID("addNodeMark",q);class j extends ${constructor(t,e){super(),this.pos=t,this.mark=e}apply(t){let e=t.nodeAt(this.pos);if(!e)return J.fail("No node at mark step's position");let n=e.type.create(e.attrs,null,this.mark.removeFromSet(e.marks));return J.fromReplace(t,this.pos,this.pos+1,new f(l.from(n),0,e.isLeaf?0:1))}invert(t){let e=t.nodeAt(this.pos);return e&&this.mark.isInSet(e.marks)?new q(this.pos,this.mark):this}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new j(e.pos,this.mark)}toJSON(){return{stepType:"removeNodeMark",pos:this.pos,mark:this.mark.toJSON()}}static fromJSON(t,e){if("number"!=typeof e.pos)throw new RangeError("Invalid input for RemoveNodeMarkStep.fromJSON");return new j(e.pos,t.markFromJSON(e.mark))}}$.jsonID("removeNodeMark",j);class K extends ${constructor(t,e,n,r=!1){super(),this.from=t,this.to=e,this.slice=n,this.structure=r}apply(t){return this.structure&&H(t,this.from,this.to)?J.fail("Structure replace would overwrite content"):J.fromReplace(t,this.from,this.to,this.slice)}getMap(){return new P([this.from,this.to-this.from,this.slice.size])}invert(t){return new K(this.from,this.from+this.slice.size,t.slice(this.from,this.to))}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1);return e.deletedAcross&&n.deletedAcross?null:new K(e.pos,Math.max(e.pos,n.pos),this.slice)}merge(t){if(!(t instanceof K)||t.structure||this.structure)return null;if(this.from+this.slice.size!=t.from||this.slice.openEnd||t.slice.openStart){if(t.to!=this.from||this.slice.openStart||t.slice.openEnd)return null;{let e=this.slice.size+t.slice.size==0?f.empty:new f(t.slice.content.append(this.slice.content),t.slice.openStart,this.slice.openEnd);return new K(t.from,this.to,e,this.structure)}}{let e=this.slice.size+t.slice.size==0?f.empty:new f(this.slice.content.append(t.slice.content),this.slice.openStart,t.slice.openEnd);return new K(this.from,this.to+(t.to-t.from),e,this.structure)}}toJSON(){let t={stepType:"replace",from:this.from,to:this.to};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to)throw new RangeError("Invalid input for ReplaceStep.fromJSON");return new K(e.from,e.to,f.fromJSON(t,e.slice),!!e.structure)}}$.jsonID("replace",K);class W extends ${constructor(t,e,n,r,o,i,s=!1){super(),this.from=t,this.to=e,this.gapFrom=n,this.gapTo=r,this.slice=o,this.insert=i,this.structure=s}apply(t){if(this.structure&&(H(t,this.from,this.gapFrom)||H(t,this.gapTo,this.to)))return J.fail("Structure gap-replace would overwrite content");let e=t.slice(this.gapFrom,this.gapTo);if(e.openStart||e.openEnd)return J.fail("Gap is not a flat range");let n=this.slice.insertAt(this.insert,e.content);return n?J.fromReplace(t,this.from,this.to,n):J.fail("Content does not fit in gap")}getMap(){return new P([this.from,this.gapFrom-this.from,this.insert,this.gapTo,this.to-this.gapTo,this.slice.size-this.insert])}invert(t){let e=this.gapTo-this.gapFrom;return new W(this.from,this.from+this.slice.size+e,this.from+this.insert,this.from+this.insert+e,t.slice(this.from,this.to).removeBetween(this.gapFrom-this.from,this.gapTo-this.from),this.gapFrom-this.from,this.structure)}map(t){let e=t.mapResult(this.from,1),n=t.mapResult(this.to,-1),r=this.from==this.gapFrom?e.pos:t.map(this.gapFrom,-1),o=this.to==this.gapTo?n.pos:t.map(this.gapTo,1);return e.deletedAcross&&n.deletedAcross||r<e.pos||o>n.pos?null:new W(e.pos,n.pos,r,o,this.slice,this.insert,this.structure)}toJSON(){let t={stepType:"replaceAround",from:this.from,to:this.to,gapFrom:this.gapFrom,gapTo:this.gapTo,insert:this.insert};return this.slice.size&&(t.slice=this.slice.toJSON()),this.structure&&(t.structure=!0),t}static fromJSON(t,e){if("number"!=typeof e.from||"number"!=typeof e.to||"number"!=typeof e.gapFrom||"number"!=typeof e.gapTo||"number"!=typeof e.insert)throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new W(e.from,e.to,e.gapFrom,e.gapTo,f.fromJSON(t,e.slice),e.insert,!!e.structure)}}function H(t,e,n){let r=t.resolve(e),o=n-e,i=r.depth;for(;o>0&&i>0&&r.indexAfter(i)==r.node(i).childCount;)i--,o--;if(o>0){let t=r.node(i).maybeChild(r.indexAfter(i));for(;o>0;){if(!t||t.isLeaf)return!0;t=t.firstChild,o--}}return!1}$.jsonID("replaceAround",W);class _ extends ${constructor(t,e,n){super(),this.pos=t,this.attr=e,this.value=n}apply(t){let e=t.nodeAt(this.pos);if(!e)return J.fail("No node at attribute step's position");let n=Object.create(null);for(let t in e.attrs)n[t]=e.attrs[t];n[this.attr]=this.value;let r=e.type.create(n,null,e.marks);return J.fromReplace(t,this.pos,this.pos+1,new f(l.from(r),0,e.isLeaf?0:1))}getMap(){return P.empty}invert(t){return new _(this.pos,this.attr,t.nodeAt(this.pos).attrs[this.attr])}map(t){let e=t.mapResult(this.pos,1);return e.deletedAfter?null:new _(e.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(t,e){if("number"!=typeof e.pos||"string"!=typeof e.attr)throw new RangeError("Invalid input for AttrStep.fromJSON");return new _(e.pos,e.attr,e.value)}}$.jsonID("attr",_);class G extends ${constructor(t,e){super(),this.attr=t,this.value=e}apply(t){let e=Object.create(null);for(let n in t.attrs)e[n]=t.attrs[n];e[this.attr]=this.value;let n=t.type.create(e,t.content,t.marks);return J.ok(n)}getMap(){return P.empty}invert(t){return new G(this.attr,t.attrs[this.attr])}map(t){return this}toJSON(){return{stepType:"docAttr",attr:this.attr,value:this.value}}static fromJSON(t,e){if("string"!=typeof e.attr)throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new G(e.attr,e.value)}}$.jsonID("docAttr",G);let U=class extends Error{};U=function t(e){let n=Error.call(this,e);return n.__proto__=t.prototype,n},(U.prototype=Object.create(Error.prototype)).constructor=U,U.prototype.name="TransformError";const X=Object.create(null);class Y{constructor(t,e,n){this.$anchor=t,this.$head=e,this.ranges=n||[new Q(t.min(e),t.max(e))]}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 t=this.ranges;for(let e=0;e<t.length;e++)if(t[e].$from.pos!=t[e].$to.pos)return!1;return!0}content(){return this.$from.doc.slice(this.from,this.to,!0)}replace(t,e=f.empty){let n=e.content.lastChild,r=null;for(let t=0;t<e.openEnd;t++)r=n,n=n.lastChild;let o=t.steps.length,i=this.ranges;for(let s=0;s<i.length;s++){let{$from:l,$to:a}=i[s],c=t.mapping.slice(o);t.replaceRange(c.map(l.pos),c.map(a.pos),s?f.empty:e),0==s&&at(t,o,(n?n.isInline:r&&r.isTextblock)?-1:1)}}replaceWith(t,e){let n=t.steps.length,r=this.ranges;for(let o=0;o<r.length;o++){let{$from:i,$to:s}=r[o],l=t.mapping.slice(n),a=l.map(i.pos),c=l.map(s.pos);o?t.deleteRange(a,c):(t.replaceRangeWith(a,c,e),at(t,n,e.isInline?-1:1))}}static findFrom(t,e,n=!1){let r=t.parent.inlineContent?new et(t):lt(t.node(0),t.parent,t.pos,t.index(),e,n);if(r)return r;for(let r=t.depth-1;r>=0;r--){let o=e<0?lt(t.node(0),t.node(r),t.before(r+1),t.index(r),e,n):lt(t.node(0),t.node(r),t.after(r+1),t.index(r)+1,e,n);if(o)return o}return null}static near(t,e=1){return this.findFrom(t,e)||this.findFrom(t,-e)||new it(t.node(0))}static atStart(t){return lt(t,t,0,0,1)||new it(t)}static atEnd(t){return lt(t,t,t.content.size,t.childCount,-1)||new it(t)}static fromJSON(t,e){if(!e||!e.type)throw new RangeError("Invalid input for Selection.fromJSON");let n=X[e.type];if(!n)throw new RangeError(`No selection type ${e.type} defined`);return n.fromJSON(t,e)}static jsonID(t,e){if(t in X)throw new RangeError("Duplicate use of selection JSON ID "+t);return X[t]=e,e.prototype.jsonID=t,e}getBookmark(){return et.between(this.$anchor,this.$head).getBookmark()}}Y.prototype.visible=!0;class Q{constructor(t,e){this.$from=t,this.$to=e}}let Z=!1;function tt(t){Z||t.parent.inlineContent||(Z=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+t.parent.type.name+")"))}class et extends Y{constructor(t,e=t){tt(t),tt(e),super(t,e)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(t,e){let n=t.resolve(e.map(this.head));if(!n.parent.inlineContent)return Y.near(n);let r=t.resolve(e.map(this.anchor));return new et(r.parent.inlineContent?r:n,n)}replace(t,e=f.empty){if(super.replace(t,e),e==f.empty){let e=this.$from.marksAcross(this.$to);e&&t.ensureMarks(e)}}eq(t){return t instanceof et&&t.anchor==this.anchor&&t.head==this.head}getBookmark(){return new nt(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(t,e){if("number"!=typeof e.anchor||"number"!=typeof e.head)throw new RangeError("Invalid input for TextSelection.fromJSON");return new et(t.resolve(e.anchor),t.resolve(e.head))}static create(t,e,n=e){let r=t.resolve(e);return new this(r,n==e?r:t.resolve(n))}static between(t,e,n){let r=t.pos-e.pos;if(n&&!r||(n=r>=0?1:-1),!e.parent.inlineContent){let t=Y.findFrom(e,n,!0)||Y.findFrom(e,-n,!0);if(!t)return Y.near(e,n);e=t.$head}return t.parent.inlineContent||(0==r||(t=(Y.findFrom(t,-n,!0)||Y.findFrom(t,n,!0)).$anchor).pos<e.pos!=r<0)&&(t=e),new et(t,e)}}Y.jsonID("text",et);class nt{constructor(t,e){this.anchor=t,this.head=e}map(t){return new nt(t.map(this.anchor),t.map(this.head))}resolve(t){return et.between(t.resolve(this.anchor),t.resolve(this.head))}}class rt extends Y{constructor(t){let e=t.nodeAfter,n=t.node(0).resolve(t.pos+e.nodeSize);super(t,n),this.node=e}map(t,e){let{deleted:n,pos:r}=e.mapResult(this.anchor),o=t.resolve(r);return n?Y.near(o):new rt(o)}content(){return new f(l.from(this.node),0,0)}eq(t){return t instanceof rt&&t.anchor==this.anchor}toJSON(){return{type:"node",anchor:this.anchor}}getBookmark(){return new ot(this.anchor)}static fromJSON(t,e){if("number"!=typeof e.anchor)throw new RangeError("Invalid input for NodeSelection.fromJSON");return new rt(t.resolve(e.anchor))}static create(t,e){return new rt(t.resolve(e))}static isSelectable(t){return!t.isText&&!1!==t.type.spec.selectable}}rt.prototype.visible=!1,Y.jsonID("node",rt);class ot{constructor(t){this.anchor=t}map(t){let{deleted:e,pos:n}=t.mapResult(this.anchor);return e?new nt(n,n):new ot(n)}resolve(t){let e=t.resolve(this.anchor),n=e.nodeAfter;return n&&rt.isSelectable(n)?new rt(e):Y.near(e)}}class it extends Y{constructor(t){super(t.resolve(0),t.resolve(t.content.size))}replace(t,e=f.empty){if(e==f.empty){t.delete(0,t.doc.content.size);let e=Y.atStart(t.doc);e.eq(t.selection)||t.setSelection(e)}else super.replace(t,e)}toJSON(){return{type:"all"}}static fromJSON(t){return new it(t)}map(t){return new it(t)}eq(t){return t instanceof it}getBookmark(){return st}}Y.jsonID("all",it);const st={map(){return this},resolve:t=>new it(t)};function lt(t,e,n,r,o,i=!1){if(e.inlineContent)return et.create(t,n);for(let s=r-(o>0?0:1);o>0?s<e.childCount:s>=0;s+=o){let r=e.child(s);if(r.isAtom){if(!i&&rt.isSelectable(r))return rt.create(t,n-(o<0?r.nodeSize:0))}else{let e=lt(t,r,n+o,o<0?r.childCount:0,o,i);if(e)return e}n+=r.nodeSize*o}return null}function at(t,e,n){let r=t.steps.length-1;if(r<e)return;let o,i=t.steps[r];(i instanceof K||i instanceof W)&&(t.mapping.maps[r].forEach(((t,e,n,r)=>{null==o&&(o=r)})),t.setSelection(Y.near(t.doc.resolve(o),n)))}function ct(t,e){return e&&t?t.bind(e):t}class dt{constructor(t,e,n){this.name=t,this.init=ct(e.init,n),this.apply=ct(e.apply,n)}}new dt("doc",{init:t=>t.doc||t.schema.topNodeType.createAndFill(),apply:t=>t.doc}),new dt("selection",{init:(t,e)=>t.selection||Y.atStart(e.doc),apply:t=>t.selection}),new dt("storedMarks",{init:t=>t.storedMarks||null,apply:(t,e,n,r)=>r.selection.$cursor?t.storedMarks:null}),new dt("scrollToSelection",{init:()=>0,apply:(t,e)=>t.scrolledIntoView?e+1:e});const ht=Object.create(null);class ut{constructor(t="key"){this.key=function(t){return t in ht?t+"$"+ ++ht[t]:(ht[t]=0,t+"$")}(t)}get(t){return t.config.pluginsByKey[this.key]}getState(t){return t[this.key]}}const ft=function(t){for(var e=0;;e++)if(!(t=t.previousSibling))return e},pt=function(t,e,n,r){return n&&(gt(t,e,n,r,-1)||gt(t,e,n,r,1))},mt=/^(img|br|input|textarea|hr)$/i;function gt(t,e,n,r,o){for(;;){if(t==n&&e==r)return!0;if(e==(o<0?0:vt(t))){let n=t.parentNode;if(!n||1!=n.nodeType||yt(t)||mt.test(t.nodeName)||"false"==t.contentEditable)return!1;e=ft(t)+(o<0?0:1),t=n}else{if(1!=t.nodeType)return!1;if("false"==(t=t.childNodes[e+(o<0?-1:0)]).contentEditable)return!1;e=o<0?vt(t):0}}}function vt(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function yt(t){let e;for(let n=t;n&&!(e=n.pmViewDesc);n=n.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==t||e.contentDOM==t)}const wt=function(t){return t.focusNode&&pt(t.focusNode,t.focusOffset,t.anchorNode,t.anchorOffset)};function St(t,e){let n=document.createEvent("Event");return n.initEvent("keydown",!0,!0),n.keyCode=t,n.key=n.code=e,n}const bt="undefined"!=typeof navigator?navigator:null,xt="undefined"!=typeof document?document:null,Ct=bt&&bt.userAgent||"",Tt=/Edge\/(\d+)/.exec(Ct),kt=/MSIE \d/.exec(Ct),Et=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ct),It=!!(kt||Et||Tt),Nt=kt?document.documentMode:Et?+Et[1]:Tt?+Tt[1]:0,Ot=!It&&/gecko\/(\d+)/i.test(Ct);Ot&&(/Firefox\/(\d+)/.exec(Ct)||[0,0])[1];const At=!It&&/Chrome\/(\d+)/.exec(Ct),Mt=!!At,Dt=At?+At[1]:0,Rt=!It&&!!bt&&/Apple Computer/.test(bt.vendor),zt=Rt&&(/Mobile\/\w+/.test(Ct)||!!bt&&bt.maxTouchPoints>2),Pt=zt||!!bt&&/Mac/.test(bt.platform),Ft=!!bt&&/Win/.test(bt.platform),$t=/Android \d/.test(Ct),Jt=!!xt&&"webkitFontSmoothing"in xt.documentElement.style,Vt=Jt?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Lt(t,e=null){let n=t.domSelectionRange(),r=t.state.doc;if(!n.focusNode)return null;let o=t.docView.nearestDesc(n.focusNode),i=o&&0==o.size,s=t.docView.posFromDOM(n.focusNode,n.focusOffset,1);if(s<0)return null;let l,a,c=r.resolve(s);if(wt(n)){for(l=s;o&&!o.node;)o=o.parent;let t=o.node;if(o&&t.isAtom&&rt.isSelectable(t)&&o.parent&&(!t.isInline||!function(t,e,n){for(let r=0==e,o=e==vt(t);r||o;){if(t==n)return!0;let e=ft(t);if(!(t=t.parentNode))return!1;r=r&&0==e,o=o&&e==vt(t)}}(n.focusNode,n.focusOffset,o.dom))){let t=o.posBefore;a=new rt(s==t?c:r.resolve(t))}}else{if(n instanceof t.dom.ownerDocument.defaultView.Selection&&n.rangeCount>1){let e=s,o=s;for(let r=0;r<n.rangeCount;r++){let i=n.getRangeAt(r);e=Math.min(e,t.docView.posFromDOM(i.startContainer,i.startOffset,1)),o=Math.max(o,t.docView.posFromDOM(i.endContainer,i.endOffset,-1))}if(e<0)return null;[l,s]=o==t.state.selection.anchor?[o,e]:[e,o],c=r.resolve(s)}else l=t.docView.posFromDOM(n.anchorNode,n.anchorOffset,1);if(l<0)return null}let d=r.resolve(l);if(!a){a=Gt(t,d,c,"pointer"==e||t.state.selection.head<c.pos&&!i?1:-1)}return a}function Bt(t){return t.editable?t.hasFocus():function(t){let e=t.domSelectionRange();if(!e.anchorNode)return!1;try{return t.dom.contains(3==e.anchorNode.nodeType?e.anchorNode.parentNode:e.anchorNode)&&(t.editable||t.dom.contains(3==e.focusNode.nodeType?e.focusNode.parentNode:e.focusNode))}catch(t){return!1}}(t)&&document.activeElement&&document.activeElement.contains(t.dom)}function qt(t,e=!1){let n=t.state.selection;if(function(t,e){if(e instanceof rt){let n=t.docView.descAt(e.from);n!=t.lastSelectedViewDesc&&(_t(t),n&&n.selectNode(),t.lastSelectedViewDesc=n)}else _t(t)}(t,n),Bt(t)){if(!e&&t.input.mouseDown&&t.input.mouseDown.allowDefault&&Mt){let e=t.domSelectionRange(),n=t.domObserver.currentSelection;if(e.anchorNode&&n.anchorNode&&pt(e.anchorNode,e.anchorOffset,n.anchorNode,n.anchorOffset))return t.input.mouseDown.delayedSelectionSync=!0,void t.domObserver.setCurSelection()}if(t.domObserver.disconnectSelection(),t.cursorWrapper)!function(t){let e=t.domSelection(),n=document.createRange();if(!e)return;let r=t.cursorWrapper.dom,o="IMG"==r.nodeName;o?n.setStart(r.parentNode,ft(r)+1):n.setStart(r,0);n.collapse(!0),e.removeAllRanges(),e.addRange(n),!o&&!t.state.selection.visible&&It&&Nt<=11&&(r.disabled=!0,r.disabled=!1)}(t);else{let r,o,{anchor:i,head:s}=n;!jt||n instanceof et||(n.$from.parent.inlineContent||(r=Kt(t,n.from)),n.empty||n.$from.parent.inlineContent||(o=Kt(t,n.to))),t.docView.setSelection(i,s,t.root,e),jt&&(r&&Ht(r),o&&Ht(o)),n.visible?t.dom.classList.remove("ProseMirror-hideselection"):(t.dom.classList.add("ProseMirror-hideselection"),"onselectionchange"in document&&function(t){let e=t.dom.ownerDocument;e.removeEventListener("selectionchange",t.input.hideSelectionGuard);let n=t.domSelectionRange(),r=n.anchorNode,o=n.anchorOffset;e.addEventListener("selectionchange",t.input.hideSelectionGuard=()=>{n.anchorNode==r&&n.anchorOffset==o||(e.removeEventListener("selectionchange",t.input.hideSelectionGuard),setTimeout((()=>{Bt(t)&&!t.state.selection.visible||t.dom.classList.remove("ProseMirror-hideselection")}),20))})}(t))}t.domObserver.setCurSelection(),t.domObserver.connectSelection()}}const jt=Rt||Mt&&Dt<63;function Kt(t,e){let{node:n,offset:r}=t.docView.domFromPos(e,0),o=r<n.childNodes.length?n.childNodes[r]:null,i=r?n.childNodes[r-1]:null;if(Rt&&o&&"false"==o.contentEditable)return Wt(o);if(!(o&&"false"!=o.contentEditable||i&&"false"!=i.contentEditable)){if(o)return Wt(o);if(i)return Wt(i)}}function Wt(t){return t.contentEditable="true",Rt&&t.draggable&&(t.draggable=!1,t.wasDraggable=!0),t}function Ht(t){t.contentEditable="false",t.wasDraggable&&(t.draggable=!0,t.wasDraggable=null)}function _t(t){t.lastSelectedViewDesc&&(t.lastSelectedViewDesc.parent&&t.lastSelectedViewDesc.deselectNode(),t.lastSelectedViewDesc=void 0)}function Gt(t,e,n,r){return t.someProp("createSelectionBetween",(r=>r(t,e,n)))||et.between(e,n,r)}function Ut(t,e){let{$anchor:n,$head:r}=t.selection,o=e>0?n.max(r):n.min(r),i=o.parent.inlineContent?o.depth?t.doc.resolve(e>0?o.after():o.before()):null:o;return i&&Y.findFrom(i,e)}function Xt(t,e){return t.dispatch(t.state.tr.setSelection(e).scrollIntoView()),!0}function Yt(t,e,n){let r=t.state.selection;if(!(r instanceof et)){if(r instanceof rt&&r.node.isInline)return Xt(t,new et(e>0?r.$to:r.$from));{let n=Ut(t.state,e);return!!n&&Xt(t,n)}}if(n.indexOf("s")>-1){let{$head:n}=r,o=n.textOffset?null:e<0?n.nodeBefore:n.nodeAfter;if(!o||o.isText||!o.isLeaf)return!1;let i=t.state.doc.resolve(n.pos+o.nodeSize*(e<0?-1:1));return Xt(t,new et(r.$anchor,i))}if(!r.empty)return!1;if(t.endOfTextblock(e>0?"forward":"backward")){let n=Ut(t.state,e);return!!(n&&n instanceof rt)&&Xt(t,n)}if(!(Pt&&n.indexOf("m")>-1)){let n,o=r.$head,i=o.textOffset?null:e<0?o.nodeBefore:o.nodeAfter;if(!i||i.isText)return!1;let s=e<0?o.pos-i.nodeSize:o.pos;return!!(i.isAtom||(n=t.docView.descAt(s))&&!n.contentDOM)&&(rt.isSelectable(i)?Xt(t,new rt(e<0?t.state.doc.resolve(o.pos-i.nodeSize):o)):!!Jt&&Xt(t,new et(t.state.doc.resolve(e<0?s:s+i.nodeSize))))}}function Qt(t){return 3==t.nodeType?t.nodeValue.length:t.childNodes.length}function Zt(t,e){let n=t.pmViewDesc;return n&&0==n.size&&(e<0||t.nextSibling||"BR"!=t.nodeName)}function te(t,e){return e<0?function(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let o,i,s=!1;Ot&&1==n.nodeType&&r<Qt(n)&&Zt(n.childNodes[r],-1)&&(s=!0);for(;;)if(r>0){if(1!=n.nodeType)break;{let t=n.childNodes[r-1];if(Zt(t,-1))o=n,i=--r;else{if(3!=t.nodeType)break;n=t,r=n.nodeValue.length}}}else{if(ee(n))break;{let e=n.previousSibling;for(;e&&Zt(e,-1);)o=n.parentNode,i=ft(e),e=e.previousSibling;if(e)n=e,r=Qt(n);else{if(n=n.parentNode,n==t.dom)break;r=0}}}s?ne(t,n,r):o&&ne(t,o,i)}(t):function(t){let e=t.domSelectionRange(),n=e.focusNode,r=e.focusOffset;if(!n)return;let o,i,s=Qt(n);for(;;)if(r<s){if(1!=n.nodeType)break;if(!Zt(n.childNodes[r],1))break;o=n,i=++r}else{if(ee(n))break;{let e=n.nextSibling;for(;e&&Zt(e,1);)o=e.parentNode,i=ft(e)+1,e=e.nextSibling;if(e)n=e,r=0,s=Qt(n);else{if(n=n.parentNode,n==t.dom)break;r=s=0}}}o&&ne(t,o,i)}(t)}function ee(t){let e=t.pmViewDesc;return e&&e.node&&e.node.isBlock}function ne(t,e,n){if(3!=e.nodeType){let t,r;(r=function(t,e){for(;t&&e==t.childNodes.length&&!yt(t);)e=ft(t)+1,t=t.parentNode;for(;t&&e<t.childNodes.length;){let n=t.childNodes[e];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;t=n,e=0}}(e,n))?(e=r,n=0):(t=function(t,e){for(;t&&!e&&!yt(t);)e=ft(t),t=t.parentNode;for(;t&&e;){let n=t.childNodes[e-1];if(3==n.nodeType)return n;if(1==n.nodeType&&"false"==n.contentEditable)break;e=(t=n).childNodes.length}}(e,n))&&(e=t,n=t.nodeValue.length)}let r=t.domSelection();if(!r)return;if(wt(r)){let t=document.createRange();t.setEnd(e,n),t.setStart(e,n),r.removeAllRanges(),r.addRange(t)}else r.extend&&r.extend(e,n);t.domObserver.setCurSelection();let{state:o}=t;setTimeout((()=>{t.state==o&&qt(t)}),50)}function re(t,e){let n=t.state.doc.resolve(e);if(!Mt&&!Ft&&n.parent.inlineContent){let r=t.coordsAtPos(e);if(e>n.start()){let n=t.coordsAtPos(e-1),o=(n.top+n.bottom)/2;if(o>r.top&&o<r.bottom&&Math.abs(n.left-r.left)>1)return n.left<r.left?"ltr":"rtl"}if(e<n.end()){let n=t.coordsAtPos(e+1),o=(n.top+n.bottom)/2;if(o>r.top&&o<r.bottom&&Math.abs(n.left-r.left)>1)return n.left>r.left?"ltr":"rtl"}}return"rtl"==getComputedStyle(t.dom).direction?"rtl":"ltr"}function oe(t,e,n){let r=t.state.selection;if(r instanceof et&&!r.empty||n.indexOf("s")>-1)return!1;if(Pt&&n.indexOf("m")>-1)return!1;let{$from:o,$to:i}=r;if(!o.parent.inlineContent||t.endOfTextblock(e<0?"up":"down")){let n=Ut(t.state,e);if(n&&n instanceof rt)return Xt(t,n)}if(!o.parent.inlineContent){let n=e<0?o:i,s=r instanceof it?Y.near(n,e):Y.findFrom(n,e);return!!s&&Xt(t,s)}return!1}function ie(t,e){if(!(t.state.selection instanceof et))return!0;let{$head:n,$anchor:r,empty:o}=t.state.selection;if(!n.sameParent(r))return!0;if(!o)return!1;if(t.endOfTextblock(e>0?"forward