diff --git a/blocks/edit/prose/index.js b/blocks/edit/prose/index.js
index 22cf8efe..27790ad7 100644
--- a/blocks/edit/prose/index.js
+++ b/blocks/edit/prose/index.js
@@ -1,10 +1,8 @@
/* eslint-disable max-classes-per-file */
import {
- DOMParser,
EditorState,
EditorView,
Schema,
- TextSelection,
baseSchema,
history,
buildKeymap,
@@ -19,8 +17,6 @@ import {
liftListItem,
sinkListItem,
gapCursor,
- InputRule,
- inputRules,
Y,
WebsocketProvider,
ySyncPlugin,
@@ -35,7 +31,6 @@ import prose2aem from '../../shared/prose2aem.js';
import menu from './plugins/menu.js';
import imageDrop from './plugins/imageDrop.js';
import linkConverter from './plugins/linkConverter.js';
-import sectionPasteHandler from './plugins/sectionPasteHandler.js';
import { COLLAB_ORIGIN, getDaAdmin } from '../../shared/constants.js';
import { addLocNodes, getLocClass } from './loc-utils.js';
@@ -206,36 +201,6 @@ function generateColor(name, hRange = [0, 360], sRange = [60, 80], lRange = [40,
return `#${f(0)}${f(8)}${f(4)}`;
}
-function getDashesInputRule() {
- return new InputRule(
- /^---[\n]$/,
- (state, match, start, end) => {
- const div = document.createElement('div');
- div.append(document.createElement('hr'));
- const newNodes = DOMParser.fromSchema(state.schema).parse(div);
-
- const selection = TextSelection.create(state.doc, start, end);
- dispatchTransaction(state.tr.setSelection(selection).replaceSelectionWith(newNodes));
- },
- );
-}
-
-// This function returns a modified inputrule plugin that triggers when the regex in the
-// rule matches and the Enter key is pressed
-function getInputRulesPlugin() {
- const irsplugin = inputRules({ rules: [getDashesInputRule()] });
-
- const hkd = (view, event) => {
- if (event.key !== 'Enter') return false;
- const { $cursor } = view.state.selection;
- if ($cursor) return irsplugin.props.handleTextInput(view, $cursor.pos, $cursor.pos, '\n');
- return false;
- };
- irsplugin.props.handleKeyDown = hkd; // Add the handleKeyDown function
-
- return irsplugin;
-}
-
export default function initProse({ editor, path }) {
// Destroy ProseMirror if it already exists - GH-212
if (window.view) delete window.view;
@@ -296,10 +261,8 @@ export default function initProse({ editor, path }) {
menu,
imageDrop(schema),
linkConverter(schema),
- sectionPasteHandler(schema),
columnResizing(),
tableEditing(),
- getInputRulesPlugin(),
keymap(buildKeymap(schema)),
keymap(baseKeymap),
keymap({
diff --git a/blocks/edit/prose/plugins/sectionPasteHandler.js b/blocks/edit/prose/plugins/sectionPasteHandler.js
deleted file mode 100644
index a348d2fa..00000000
--- a/blocks/edit/prose/plugins/sectionPasteHandler.js
+++ /dev/null
@@ -1,153 +0,0 @@
-import { Plugin, Slice } from 'da-y-wrapper';
-
-function closeParagraph(paraContent, newContent) {
- if (paraContent.length > 0) {
- const newPara = {
- type: 'paragraph',
- content: [...paraContent],
- };
- newContent.push(newPara);
- paraContent.length = 0;
- }
-}
-
-/**
- * Find section breaks in HTML pasted from desktop Word and add a horizontal rule
- * after each one.
- * In Desktop Word each section is represented as a top-level div element, right
- * under the body element.
- */
-function handleDesktopWordSectionBreaks(html) {
- try {
- const parser = new DOMParser();
- const doc = parser.parseFromString(html, 'text/html');
-
- if (doc.querySelector('meta[name="ProgId"]')?.content !== 'Word.Document') {
- // This is not a word document
- return html;
- }
-
- let modified = false;
- // Add a hr element after all top-level div elements
- const sections = doc.querySelectorAll('body > div');
- sections.forEach((section) => {
- if (section.nextElementSibling) {
- // only add the hr if there is something after the section
- section.after(doc.createElement('hr'));
- modified = true;
- }
- });
-
- if (!modified) {
- return html;
- }
-
- const serializer = new XMLSerializer();
- return serializer.serializeToString(doc);
- } catch (error) {
- // eslint-disable-next-line no-console
- console.error('Error handling desktop Word section breaks:', error);
- return html;
- }
-}
-
-/**
- * Find section breaks in HTML pasted from Word online and add a horizontal rule
- * after each one.
- * In Word online section breaks are quite hard to identify, but it turns out that
- * they seem to be indicated by a span element with a data-ccp-props attribute, of
- * which one of the values is 'single'. This is quite brittle but right now seems
- * to be the only way to find them. In the future Word online might provide a
- * better way to identify section breaks.
- */
-function handleWordOnlineSectionBreaks(html) {
- try {
- const parser = new DOMParser();
- const doc = parser.parseFromString(html, 'text/html');
-
- let modified = false;
- // The span[data-ccp-props] are the magic indicator if one of the JSON values in there is the
- // word 'single' then we need to add a section break.
- const sections = doc.querySelectorAll('div > p > span[data-ccp-props]');
- sections.forEach((section) => {
- const props = JSON.parse(section.getAttribute('data-ccp-props'));
- for (const key of Object.keys(props)) {
- if (props[key] === 'single') {
- const hr = doc.createElement('hr');
- section.parentNode.after(hr);
- modified = true;
- break;
- }
- }
- });
-
- if (!modified) {
- return html;
- }
-
- const serializer = new XMLSerializer();
- return serializer.serializeToString(doc);
- } catch (error) {
- // eslint-disable-next-line no-console
- console.error('Error handling Word online section breaks:', error);
- return html;
- }
-}
-
-/* When text is pasted, handle section breaks. */
-export default function sectionPasteHandler(schema) {
- return new Plugin({
- props: {
- /* A section break entered in Word is not kept in the text of the document, but
- * buried in the HTML that is pasted. This function uses highly specific ways to find
- * these section breaks and adds a
element for them.
- */
- transformPastedHTML: (html) => {
- const newHTML = handleDesktopWordSectionBreaks(html);
- const newHTML2 = handleWordOnlineSectionBreaks(newHTML);
- return newHTML2;
- },
-
- /* Convert 3 dashes on a line by itself (top level only) to a horizontal rule,
- * which is then interpreted as a section break.
- */
- transformPasted: (slice) => {
- const jslice = slice.toJSON();
- const { content } = jslice;
- if (!content) return slice;
-
- const newContent = [];
-
- for (const el of content) {
- if (el.type !== 'paragraph') {
- newContent.push(el);
- } else {
- const newParaCont = [];
-
- for (const pc of el.content) {
- if (pc.type !== 'text') {
- newParaCont.push(pc);
- } else if (pc.text.trim() === '---') {
- closeParagraph(newParaCont, newContent);
-
- newContent.push({ type: 'horizontal_rule' });
- } else {
- newParaCont.push(pc);
- }
- }
-
- closeParagraph(newParaCont, newContent);
- }
- }
-
- const newSlice = {
- content: newContent,
- openStart: slice.openStart,
- openEnd: slice.openEnd,
- };
-
- return Slice.fromJSON(schema, newSlice);
- },
- },
- });
-}
diff --git a/deps/da-y-wrapper/dist/index.js b/deps/da-y-wrapper/dist/index.js
index 94a7eeab..0145b6de 100644
--- a/deps/da-y-wrapper/dist/index.js
+++ b/deps/da-y-wrapper/dist/index.js
@@ -1,12 +1,12 @@
-var rp=Object.defineProperty;var ip=(n,e)=>{for(var t in e)rp(n,t,{get:e[t],enumerable:!0})};function se(n){this.content=n}se.prototype={constructor:se,find:function(n){for(var e=0;e>1}};se.from=function(n){if(n instanceof se)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new se(e)};var po=se;function Zc(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=Zc(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function ea(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=a},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?Vi(r+1,o):Vi(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};E.none=[];var Qt=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=na(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(ta(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 n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(y.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(y.empty,0,0);function ta(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(ta(s.content,e-i-1,t-i-1)))}function na(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=na(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function sp(n,e,t){if(t.openStart>n.depth)throw new Qt("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new Qt("Inconsistent open depths");return ra(n,e,t,0)}function ra(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Ar(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(Gt(n.nodeAfter,r),s++));for(let l=s;li&&bo(n,e,i+1),o=r.depth>i&&bo(t,r,i+1),l=[];return Ar(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(ia(s,o),Gt(Xt(s,sa(n,e,t,r,i+1)),l)):(s&&Gt(Xt(s,Pi(n,e,i+1)),l),Ar(e,t,i,l),o&&Gt(Xt(o,Pi(t,r,i+1)),l)),Ar(r,null,i,l),new y(l)}function Pi(n,e,t){let r=[];if(Ar(null,n,t,r),n.depth>t){let i=bo(n,e,t+1);Gt(Xt(i,Pi(n,e,t+1)),r)}return Ar(e,null,t,r),new y(r)}function op(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(y.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var Li=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new Zt(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){for(let i=0;ie&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),oa(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=y.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r=null;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=y.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,i,r)}};qe.prototype.text=void 0;var xo=class n extends qe{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):oa(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function oa(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var en=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new So(e,t);if(r.next==null)return n.empty;let i=la(r);r.next&&r.err("Unexpected trailing text");let s=mp(pp(i));return gp(s,r),s}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(`
-`)}};en.empty=new en(!0);var So=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function la(n){let e=[];do e.push(ap(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function ap(n){let e=[];do e.push(hp(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function hp(n){let e=up(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=dp(n,e);else break;return e}function Kc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function dp(n,e){let t=Kc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Kc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function fp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.groups.indexOf(e)>-1&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function up(n){if(n.eat("(")){let e=la(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=fp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function pp(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new en(r.indexOf(n.length-1)>-1);for(let o=0;o-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}},ko=class{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}},Dr=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=da(i.attrs),this.excluded=null;let s=aa(this.attrs);this.instance=s?new E(this,s):null}create(e=null){return!e&&this.instance?this.instance:new E(this,ha(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},Tr=class{constructor(e){this.linebreakReplacement=null,this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=po.from(e.nodes),t.marks=po.from(e.marks||{}),this.nodes=zi.compile(this.spec.nodes,this),this.marks=Dr.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;if(s.contentMatch=r[o]||(r[o]=en.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.spec.linebreakReplacement){if(this.linebreakReplacement)throw new RangeError("Multiple linebreak nodes defined");if(!s.isInline||!s.isLeaf)throw new RangeError("Linebreak replacement nodes must be inline leaf nodes");this.linebreakReplacement=s}s.markSet=l=="_"?null:l?Yc(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:Yc(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof zi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new xo(r,r.defaultAttrs,e,E.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return qe.fromJSON(this,e)}markFromJSON(e){return E.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function Yc(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}function yp(n){return n.tag!=null}function wp(n){return n.style!=null}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach(r=>{yp(r)?this.tags.push(r):wp(r)&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,t={}){let r=new Hi(this,t,!1);return r.addAll(e,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new Hi(this,t,!0);return r.addAll(e,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=Xc(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=Xc(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},fa={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},bp={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ua={ol:!0,ul:!0},Fi=1,qi=2,Er=4;function Gc(n,e,t){return e!=null?(e?Fi:0)|(e==="full"?qi:0):n&&n.whitespace=="pre"?Fi|qi:t&~Er}var Ln=class{constructor(e,t,r,i,s,o,l){this.type=e,this.attrs=t,this.marks=r,this.pendingMarks=i,this.solid=s,this.options=l,this.content=[],this.activeMarks=E.none,this.stashMarks=[],this.match=o||(l&Er?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(y.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Fi)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=y.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(y.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}popFromStashMark(e){for(let t=this.stashMarks.length-1;t>=0;t--)if(e.eq(this.stashMarks[t]))return this.stashMarks.splice(t,1)[0]}applyPending(e){for(let t=0,r=this.pendingMarks;tthis.addAll(e)),o&&this.sync(l),this.needsBlock=c}else this.withStyleRules(e,()=>{this.addElementByRule(e,s,s.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
-`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let t=E.none,r=E.none;for(let i=0;i{o.clearMark(l)&&(r=l.addToSet(r))}):t=this.parser.schema.marks[o.mark].create(o.attrs).addToSet(t),o.consuming===!1)s=o;else break}return[t,r]}addElementByRule(e,t,r){let i,s,o;t.node?(s=this.parser.schema.nodes[t.node],s.isLeaf?this.insertNode(s.create(t.attrs))||this.leafFallback(e):i=this.enter(s,t.attrs||null,t.preserveWhitespace)):(o=this.parser.schema.marks[t.mark].create(t.attrs),this.addPendingMark(o));let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c)}i&&this.sync(l)&&this.open--,o&&this.removePendingMark(o,l)}addAll(e,t,r){let i=t||0;for(let s=t?e.childNodes[t]:e.firstChild,o=r==null?null:e.childNodes[r];s!=o;s=s.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(s);this.findAtPoint(e,i)}findPlace(e){let t,r;for(let i=this.open;i>=0;i--){let s=this.nodes[i],o=s.findWrapping(e);if(o&&(!t||t.length>o.length)&&(t=o,r=s,!o.length)||s.solid)break}if(!t)return!1;this.sync(r);for(let i=0;ithis.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;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&h.groups.indexOf(a)==-1)return!1;c--}}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 r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let t=Mp(e,this.top.pendingMarks);t&&this.top.stashMarks.push(t),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,t){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let o=i.popFromStashMark(e);o&&i.type&&i.type.allowsMarkType(o.type)&&(i.activeMarks=o.addToSet(i.activeMarks))}if(i==t)break}}};function xp(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ua.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function Sp(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function kp(n){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,t,r=[];for(;t=e.exec(n);)r.push(t[1],t[2].trim());return r}function Xc(n){let e={};for(let t in n)e[t]=n[t];return e}function Cp(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let c=0;c{if(s.length||o.marks.length){let l=0,c=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&n.renderSpec(wo(r),i(e,t))}static renderSpec(e,t,r=null){if(typeof t=="string")return{dom:e.createTextNode(t)};if(t.nodeType!=null)return{dom:t};if(t.dom&&t.dom.nodeType!=null)return t;let i=t[0],s=i.indexOf(" ");s>0&&(r=i.slice(0,s),i=i.slice(s+1));let o,l=r?e.createElementNS(r,i):e.createElement(i),c=t[1],a=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){a=2;for(let h in c)if(c[h]!=null){let d=h.indexOf(" ");d>0?l.setAttributeNS(h.slice(0,d),h.slice(d+1),c[h]):l.setAttribute(h,c[h])}}for(let h=a;ha)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:f,contentDOM:u}=n.renderSpec(e,d,r);if(l.appendChild(f),u){if(o)throw new RangeError("Multiple content holes");o=u}}}return{dom:l,contentDOM:o}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Qc(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Qc(e.marks)}};function Qc(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function wo(n){return n.document||window.document}var ga=65535,ya=Math.pow(2,16);function Ep(n,e){return n+e*ya}function pa(n){return n&ga}function Dp(n){return(n-(n&ga))/ya}var wa=1,ba=2,Ji=4,xa=8,Ir=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&xa)>0}get deletedBefore(){return(this.delInfo&(wa|Ji))>0}get deletedAfter(){return(this.delInfo&(ba|Ji))>0}get deletedAcross(){return(this.delInfo&Ji)>0}},ct=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=pa(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:Ep(l/3,e-c),m=e==c?ba:e==d?wa:Ji;return(t<0?e!=c:e!=d)&&(m|=xa),new Ir(u,m,p)}i+=h-a}return r?e+i:new Ir(e+i,0,null)}touches(e,t){let r=0,i=pa(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return Z.fromReplace(e,this.from,this.to,s)}invert(){return new tn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};Y.jsonID("addMark",vr);var tn=class n extends Y{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(To(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Z.fromReplace(e,this.from,this.to,r)}invert(){return new vr(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};Y.jsonID("removeMark",tn);var _r=class n extends Y{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Z.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Z.fromReplace(e,this.pos,this.pos+1,new b(y.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,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(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};Y.jsonID("replaceAround",G);function Eo(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function Tp(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Op(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof Dr){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new tn(o.from,o.to,o.style)))}function Np(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),s=[],o=e+1;for(let l=0;l=0;l--)n.step(s[l])}function Ip(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function nn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=y.from(r.node(p).copy(h)),d++):c--;let f=y.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=y.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new G(i,s,i,s,new b(r,0,0),t.length,!0))}function Vp(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{if(o.isTextblock&&!o.hasMarkup(r,i)&&Bp(n.doc,n.mapping.slice(s).map(l),r)){n.clearIncompatible(n.mapping.slice(s).map(l,1),r);let c=n.mapping.slice(s),a=c.map(l,1),h=c.map(l+o.nodeSize,1);return n.step(new G(a,h,a+1,h-1,new b(y.from(r.create(i,null,o.marks)),0,0),1,!0)),!1}})}function Bp(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Pp(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new G(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(y.from(o),0,0),1,!0))}function Nt(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>s;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function Lp(n,e,t=1,r){let i=n.doc.resolve(e),s=y.empty,o=y.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=y.from(i.node(l).copy(s));let h=r&&r[a];o=y.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Me(e,e,new b(s.append(o),t,t),!0))}function rn(n,e){let t=n.resolve(e),r=t.index();return Sa(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function Sa(n,e){return!!(n&&e&&!n.isLeaf&&n.canAppend(e))}function Oo(n,e,t=-1){let r=n.resolve(e);for(let i=r.depth;;i--){let s,o,l=r.index(i);if(i==r.depth?(s=r.nodeBefore,o=r.nodeAfter):t>0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&Sa(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function zp(n,e,t){let r=new Me(e-t,e+t,b.empty,!0);n.step(r)}function Fp(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function ji(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return Ca(i,s,r)?new Me(e,t,r):new Do(i,s,r).fit()}function Ca(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Do=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=y.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=y.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let c=new b(s,o,l);return e>-1?new G(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Me(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=Mo(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(o?a.matchType(o.type)||(d=a.fillBefore(y.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Mo(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=Mo(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Or(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Or(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(Ma(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Nr(this.placed,t,y.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:c,type:a}=this.frontier[l],h=Ao(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Nr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Nr(this.placed,this.depth,y.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(y.empty,!0);t.childCount&&(this.placed=Nr(this.placed,this.frontier.length,t))}};function Or(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Or(n.firstChild.content,e-1,t)))}function Nr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Nr(n.lastChild.content,e-1,t)))}function Mo(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Ma(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(y.empty,!0)))),n.copy(r)}function Ao(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!qp(t,s.content,o)?l:null}function qp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==u&&o.splice(1,0,-f)}let c=o.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=Hp(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=o[f];u<0||(e=i.before(u),t=s.after(u))}}function Aa(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(y.empty,!0))}return n}function Wp(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Fp(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(y.from(r),0,0))}function $p(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=Ea(r,i);for(let o=0;o0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o)return n.delete(r.before(o),t);n.delete(e,t)}function Ea(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var Wi=class n extends Y{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return Z.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return Z.fromReplace(e,this.pos,this.pos+1,new b(y.from(i),0,t.isLeaf?0:1))}getMap(){return ct.empty}invert(e){return new n(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 n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};Y.jsonID("attr",Wi);var $i=class n extends Y{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return Z.ok(r)}getMap(){return ct.empty}invert(e){return new n(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(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};Y.jsonID("docAttr",$i);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Rr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=ji(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(y.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Jp(this,e,t,r),this}replaceRangeWith(e,t,r){return Wp(this,e,t,r),this}deleteRange(e,t){return $p(this,e,t),this}lift(e,t){return Rp(this,e,t),this}join(e,t=1){return zp(this,e,t),this}wrap(e,t){return Up(this,e,t),this}setBlockType(e,t=e,r,i=null){return Vp(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Pp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new Wi(e,t,r)),this}setDocAttribute(e,t){return this.step(new $i(e,t)),this}addNodeMark(e,t){return this.step(new _r(e,t)),this}removeNodeMark(e,t){if(!(t instanceof E)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new Ur(e,t)),this}split(e,t=1,r){return Lp(this,e,t,r),this}addMark(e,t,r){return Tp(this,e,t,r),this}removeMark(e,t,r){return Op(this,e,t,r),this}clearIncompatible(e,t,r){return Np(this,e,t,r),this}};var No=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Br(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=0;s--){let o=t<0?Hn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Hn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Ae(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Ae(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Ae(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=No[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in No)throw new RangeError("Duplicate use of selection JSON ID "+e);return No[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var Br=class{constructor(e,t){this.$from=e,this.$to=t}},Da=!1;function Ta(n){!Da&&!n.parent.inlineContent&&(Da=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Ta(e),Ta(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Gi(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Oa(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var Na=1,Yi=2,Ia=4,vo=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=Yi,this}ensureMarks(e){return E.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&Yi)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~Yi,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||E.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Ia,this}get scrolledIntoView(){return(this.updated&Ia)>0}};function Ra(n,e){return!e||!n?n:n.bind(e)}var sn=class{constructor(e,t,r){this.name=e,this.init=Ra(t.init,r),this.apply=Ra(t.apply,r)}},jp=[new sn("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new sn("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new sn("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new sn("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],Vr=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=jp.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new sn(r.key,r.spec.state,r))})}},_o=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new Vr(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=qe.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function va(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=va(i,e,{})),t[r]=i}return t}var F=class{constructor(e){this.spec=e,this.props={},e.props&&va(e.props,this,this.props),this.key=e.key?e.key.key:_a("plugin")}getState(e){return e[this.key]}},Io=Object.create(null);function _a(n){return n in Io?n+"$"+ ++Io[n]:(Io[n]=0,n+"$")}var fe=class{constructor(e="key"){this.key=_a(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var ee=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Fr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Lo=null,ht=function(n,e,t){let r=Lo||(Lo=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},Yp=function(){Lo=null},fn=function(n,e,t,r){return t&&(Ua(n,e,t,r,-1)||Ua(n,e,t,r,1))},Gp=/^(img|br|input|textarea|hr)$/i;function Ua(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:He(n))){let s=n.parentNode;if(!s||s.nodeType!=1||Wr(n)||Gp.test(n.nodeName)||n.contentEditable=="false")return!1;e=ee(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?He(n):0}else return!1}}function He(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Xp(n,e){for(;;){if(n.nodeType==3&&e)return n;if(n.nodeType==1&&e>0){if(n.contentEditable=="false")return null;n=n.childNodes[e-1],e=He(n)}else if(n.parentNode&&!Wr(n))e=ee(n),n=n.parentNode;else return null}}function Qp(n,e){for(;;){if(n.nodeType==3&&e2),Re=jn||(Je?/Mac/.test(Je.platform):!1),rm=Je?/Win/.test(Je.platform):!1,Le=/Android \d/.test(Vt),$r=!!Va&&"webkitFontSmoothing"in Va.documentElement.style,im=$r?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function sm(n){let e=n.defaultView&&n.defaultView.visualViewport;return e?{left:0,right:e.width,top:0,bottom:e.height}:{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function at(n,e){return typeof n=="number"?n:n[e]}function om(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Ba(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=Fr(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?sm(s):om(l),h=0,d=0;if(e.topa.bottom-at(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+at(i,"top")-a.top:e.bottom-a.bottom+at(i,"bottom")),e.lefta.right-at(r,"right")&&(h=e.right-a.right+at(i,"right")),h||d)if(c)s.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function lm(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:mh(n.dom)}}function mh(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Fr(r));return e}function cm({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;gh(t,r==0?0:r-e)}function gh(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?hm(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:yh(t,i)}function hm(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function sl(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function dm(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function um(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!o||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!o&&(o=!0,c.left>r.left||c.top>r.top?i=l.posBefore:(c.right-1?i:n.docView.posFromDOM(e,t,-1)}function wh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;$r&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=um(n,r,i,e))}l==null&&(l=fm(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Pa(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Pr(It(ht(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==He(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Uo(c.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==He(r))){let c=r.childNodes[i-1],a=c.nodeType==3?ht(c,He(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Pr(It(a,1),!1)}if(s==null&&i=0)}function Pr(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Uo(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function xh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function gm(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return xh(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=bh(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=ht(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var ym=/[\u0590-\u08ac]/;function wm(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return!ym.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:xh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g})}var La=null,za=null,Fa=!1;function bm(n,e,t){return La==e&&za==t?Fa:(La=e,za=t,Fa=t=="up"||t=="down"?gm(n,e,t):wm(n,e,t))}var ve=0,qa=1,ln=2,We=3,un=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ve,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tee(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof Zi){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof Xi&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?ee(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=ee(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){let u=l;l=c,c=u}let f=document.createRange();f.setEnd(c.node,c.offset),f.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?ln:qa,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=We:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?ln:We}r=o}this.dirty=ln}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?ln:qa;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==ve&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},Ho=class extends un{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Yn=class n extends un{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=Ot.renderSpec(document,t.type.spec.toDOM(t,r))),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&We||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=We&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ve){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=jo(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,d=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:d}=Ot.renderSpec(document,t.type.spec.toDOM(t)));!d&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let f=h;return h=Ch(h,r,t),a?c=new Jo(e,t,r,i,h,d||null,f,a,s,o+1):t.isText?new Qi(e,t,r,i,h,f,s):new n(e,t,r,i,h,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>y.empty)}return e}matchesNode(e,t,r){return this.dirty==ve&&e.eq(this.node)&&$o(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new Ko(this,o&&o.node,e);Cm(this.node,this.innerDeco,(a,h,d)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!d&&c.syncToMarks(h==this.node.childCount?E.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,d,f)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,d,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,d,u,e)||c.updateNextNode(a,h,d,e,f,i)||c.addNode(a,h,d,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==ln)&&(o&&this.protectLocalComposition(e,o),Sh(this.contentDOM,this.children,e),jn&&Mm(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||rt+this.node.content.size)return null;let s=e.input.compositionNode;if(!s||!this.dom.contains(s.parentNode))return null;if(this.node.inlineContent){let o=s.nodeValue,l=Am(this.node.content,o,r-t,i-t);return l<0?null:{node:s,pos:l,text:o}}else return{node:s,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new Ho(this,s,t,i);e.input.compositionNodes.push(o),this.children=jo(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==We||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=ve}updateOuterDeco(e){if($o(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=kh(this.dom,this.nodeDOM,Wo(this.outerDeco,this.node,t),Wo(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}};function Ha(n,e,t,r,i){Ch(r,e,n);let s=new Ut(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var Qi=class n extends Ut{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==We||this.dirty!=ve&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ve||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=ve,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=We)}get domAtom(){return!1}isText(e){return this.node.text==e}},Zi=class extends un{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ve&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},Jo=class extends Ut{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==We)return!1;if(this.spec.update){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function Sh(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let c=Yn.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof Yn)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function km(n,e){return n.type.side-e.type.side}function Cm(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+f.nodeSize;if(f.isText){let g=p;o!g.inline):l.slice();r(f,m,e.forChild(s,f),u),s=p}}function Mm(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function Am(n,e,t,r){for(let i=0,s=0;i=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function jo(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function ol(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),c,a;if(ls(t)){for(c=l;i&&!i.node;)i=i.parent;let h=i.node;if(i&&h.isAtom&&C.isSelectable(h)&&i.parent&&!(h.isInline&&Zp(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;a=new C(o==d?l:r.resolve(d))}}else{let h=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(h<0)return null;c=r.resolve(h)}if(!a){let h=e=="pointer"||n.state.selection.head{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Mh(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function Dm(n){let e=n.domSelection(),t=document.createRange(),r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setEnd(r.parentNode,ee(r)+1):t.setEnd(r,0),t.collapse(!1),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&xe&&_t<=11&&(r.disabled=!0,r.disabled=!1)}function Ah(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&(ja(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else ja(n)}function ja(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function ll(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function Ya(n){return n.editable&&!n.hasFocus()?!1:Eh(n)}function Eh(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function Tm(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return fn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Yo(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function Rt(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function Ga(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return Rt(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Yo(n.state,e);return i&&i instanceof C?Rt(n,i):!1}else if(!(Re&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?C.isSelectable(s)?Rt(n,new C(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):$r?Rt(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof C&&r.node.isInline)return Rt(n,new A(e>0?r.$to:r.$from));{let i=Yo(n.state,e);return i?Rt(n,i):!1}}}function es(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function zr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Wn(n,e){return e<0?Om(n):Nm(n)}function Om(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(ze&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(zr(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Dh(t))break;{let l=t.previousSibling;for(;l&&zr(l,-1);)i=t.parentNode,s=ee(l),l=l.previousSibling;if(l)t=l,r=es(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?Go(n,t,r):i&&Go(n,i,s)}function Nm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=es(t),s,o;for(;;)if(r{n.state==i&&dt(n)},50)}function Xa(n,e){let t=n.state.doc.resolve(e);if(!(ue||rm)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Qa(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||Re&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Yo(n.state,e);if(o&&o instanceof C)return Rt(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Ae?S.near(o,e):S.findFrom(o,e);return l?Rt(n,l):!1}return!1}function Za(n,e){if(!(n.state.selection instanceof A))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function eh(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function vm(n){if(!pe||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;eh(n,r,"true"),setTimeout(()=>eh(n,r,"false"),20)}return!1}function _m(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Um(n,e){let t=e.keyCode,r=_m(e);if(t==8||Re&&t==72&&r=="c")return Za(n,-1)||Wn(n,-1);if(t==46&&!e.shiftKey||Re&&t==68&&r=="c")return Za(n,1)||Wn(n,1);if(t==13||t==27)return!0;if(t==37||Re&&t==66&&r=="c"){let i=t==37?Xa(n,n.state.selection.from)=="ltr"?-1:1:-1;return Ga(n,i,r)||Wn(n,i)}else if(t==39||Re&&t==70&&r=="c"){let i=t==39?Xa(n,n.state.selection.from)=="ltr"?1:-1:1;return Ga(n,i,r)||Wn(n,i)}else{if(t==38||Re&&t==80&&r=="c")return Qa(n,-1,r)||Wn(n,-1);if(t==40||Re&&t==78&&r=="c")return vm(n)||Qa(n,1,r)||Wn(n,1);if(r==(Re?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Th(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||Ot.fromSchema(n.state.schema),l=_h(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=vh[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),d++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,`
+var Zu=Object.defineProperty;var ep=(n,e)=>{for(var t in e)Zu(n,t,{get:e[t],enumerable:!0})};function ie(n){this.content=n}ie.prototype={constructor:ie,find:function(n){for(var e=0;e>1}};ie.from=function(n){if(n instanceof ie)return n;var e=[];if(n)for(var t in n)e.push(t,n[t]);return new ie(e)};var ho=ie;function Gc(n,e,t){for(let r=0;;r++){if(r==n.childCount||r==e.childCount)return n.childCount==e.childCount?null:t;let i=n.child(r),s=e.child(r);if(i==s){t+=i.nodeSize;continue}if(!i.sameMarkup(s))return t;if(i.isText&&i.text!=s.text){for(let o=0;i.text[o]==s.text[o];o++)t++;return t}if(i.content.size||s.content.size){let o=Gc(i.content,s.content,t+1);if(o!=null)return o}t+=i.nodeSize}}function Xc(n,e,t,r){for(let i=n.childCount,s=e.childCount;;){if(i==0||s==0)return i==s?null:{a:t,b:r};let o=n.child(--i),l=e.child(--s),c=o.nodeSize;if(o==l){t-=c,r-=c;continue}if(!o.sameMarkup(l))return{a:t,b:r};if(o.isText&&o.text!=l.text){let a=0,h=Math.min(o.text.length,l.text.length);for(;ae&&r(c,i+l,s||null,o)!==!1&&c.content.size){let h=l+1;c.nodesBetween(Math.max(0,e-h),Math.min(c.content.size,t-h),r,i+h)}l=a}}descendants(e){this.nodesBetween(0,this.size,e)}textBetween(e,t,r,i){let s="",o=!0;return this.nodesBetween(e,t,(l,c)=>{let a=l.isText?l.text.slice(Math.max(e,c)-c,t-c):l.isLeaf?i?typeof i=="function"?i(l):i:l.type.spec.leafText?l.type.spec.leafText(l):"":"";l.isBlock&&(l.isLeaf&&a||l.isTextblock)&&r&&(o?o=!1:s+=r),s+=a},0),s}append(e){if(!e.size)return this;if(!this.size)return e;let t=this.lastChild,r=e.firstChild,i=this.content.slice(),s=0;for(t.isText&&t.sameMarkup(r)&&(i[i.length-1]=t.withText(t.text+r.text),s=1);se)for(let s=0,o=0;oe&&((ot)&&(l.isText?l=l.cut(Math.max(0,e-o),Math.min(l.text.length,t-o)):l=l.cut(Math.max(0,e-o-1),Math.min(l.content.size,t-o-1))),r.push(l),i+=l.nodeSize),o=c}return new n(r,i)}cutByIndex(e,t){return e==t?n.empty:e==0&&t==this.content.length?this:new n(this.content.slice(e,t))}replaceChild(e,t){let r=this.content[e];if(r==t)return this;let i=this.content.slice(),s=this.size+t.nodeSize-r.nodeSize;return i[e]=t,new n(i,s)}addToStart(e){return new n([e].concat(this.content),this.size+e.nodeSize)}addToEnd(e){return new n(this.content.concat(e),this.size+e.nodeSize)}eq(e){if(this.content.length!=e.content.length)return!1;for(let t=0;tthis.size||e<0)throw new RangeError(`Position ${e} outside of fragment (${this})`);for(let r=0,i=0;;r++){let s=this.child(r),o=i+s.nodeSize;if(o>=e)return o==e||t>0?vi(r+1,o):vi(r,i);i=o}}toString(){return"<"+this.toStringInner()+">"}toStringInner(){return this.content.join(", ")}toJSON(){return this.content.length?this.content.map(e=>e.toJSON()):null}static fromJSON(e,t){if(!t)return n.empty;if(!Array.isArray(t))throw new RangeError("Invalid input for Fragment.fromJSON");return new n(t.map(e.nodeFromJSON))}static fromArray(e){if(!e.length)return n.empty;let t,r=0;for(let i=0;ithis.type.rank&&(t||(t=e.slice(0,i)),t.push(this),r=!0),t&&t.push(s)}}return t||(t=e.slice()),r||t.push(this),t}removeFromSet(e){for(let t=0;tr.type.rank-i.type.rank),t}};D.none=[];var en=class extends Error{},b=class n{constructor(e,t,r){this.content=e,this.openStart=t,this.openEnd=r}get size(){return this.content.size-this.openStart-this.openEnd}insertAt(e,t){let r=Zc(this.content,e+this.openStart,t);return r&&new n(r,this.openStart,this.openEnd)}removeBetween(e,t){return new n(Qc(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 n.empty;let r=t.openStart||0,i=t.openEnd||0;if(typeof r!="number"||typeof i!="number")throw new RangeError("Invalid input for Slice.fromJSON");return new n(y.fromJSON(e,t.content),r,i)}static maxOpen(e,t=!0){let r=0,i=0;for(let s=e.firstChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.firstChild)r++;for(let s=e.lastChild;s&&!s.isLeaf&&(t||!s.type.spec.isolating);s=s.lastChild)i++;return new n(e,r,i)}};b.empty=new b(y.empty,0,0);function Qc(n,e,t){let{index:r,offset:i}=n.findIndex(e),s=n.maybeChild(r),{index:o,offset:l}=n.findIndex(t);if(i==e||s.isText){if(l!=t&&!n.child(o).isText)throw new RangeError("Removing non-flat range");return n.cut(0,e).append(n.cut(t))}if(r!=o)throw new RangeError("Removing non-flat range");return n.replaceChild(r,s.copy(Qc(s.content,e-i-1,t-i-1)))}function Zc(n,e,t,r){let{index:i,offset:s}=n.findIndex(e),o=n.maybeChild(i);if(s==e||o.isText)return r&&!r.canReplace(i,i,t)?null:n.cut(0,e).append(t).append(n.cut(e));let l=Zc(o.content,e-s-1,t);return l&&n.replaceChild(i,o.copy(l))}function tp(n,e,t){if(t.openStart>n.depth)throw new en("Inserted content deeper than insertion position");if(n.depth-t.openStart!=e.depth-t.openEnd)throw new en("Inconsistent open depths");return ea(n,e,t,0)}function ea(n,e,t,r){let i=n.index(r),s=n.node(r);if(i==e.index(r)&&r=0&&n.isText&&n.sameMarkup(e[t])?e[t]=n.withText(e[t].text+n.text):e.push(n)}function Cr(n,e,t,r){let i=(e||n).node(t),s=0,o=e?e.index(t):i.childCount;n&&(s=n.index(t),n.depth>t?s++:n.textOffset&&(Qt(n.nodeAfter,r),s++));for(let l=s;li&&go(n,e,i+1),o=r.depth>i&&go(t,r,i+1),l=[];return Cr(null,n,i,l),s&&o&&e.index(i)==t.index(i)?(ta(s,o),Qt(Zt(s,na(n,e,t,r,i+1)),l)):(s&&Qt(Zt(s,Ui(n,e,i+1)),l),Cr(e,t,i,l),o&&Qt(Zt(o,Ui(t,r,i+1)),l)),Cr(r,null,i,l),new y(l)}function Ui(n,e,t){let r=[];if(Cr(null,n,t,r),n.depth>t){let i=go(n,e,t+1);Qt(Zt(i,Ui(n,e,t+1)),r)}return Cr(e,null,t,r),new y(r)}function np(n,e){let t=e.depth-n.openStart,i=e.node(t).copy(n.content);for(let s=t-1;s>=0;s--)i=e.node(s).copy(y.from(i));return{start:i.resolveNoCache(n.openStart+t),end:i.resolveNoCache(i.content.size-n.openEnd-t)}}var Bi=class n{constructor(e,t,r){this.pos=e,this.path=t,this.parentOffset=r,this.depth=t.length/3-1}resolveDepth(e){return e==null?this.depth:e<0?this.depth+e:e}get parent(){return this.node(this.depth)}get doc(){return this.node(0)}node(e){return this.path[this.resolveDepth(e)*3]}index(e){return this.path[this.resolveDepth(e)*3+1]}indexAfter(e){return e=this.resolveDepth(e),this.index(e)+(e==this.depth&&!this.textOffset?0:1)}start(e){return e=this.resolveDepth(e),e==0?0:this.path[e*3-1]+1}end(e){return e=this.resolveDepth(e),this.start(e)+this.node(e).content.size}before(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position before the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]}after(e){if(e=this.resolveDepth(e),!e)throw new RangeError("There is no position after the top-level node");return e==this.depth+1?this.pos:this.path[e*3-1]+this.path[e*3].nodeSize}get textOffset(){return this.pos-this.path[this.path.length-1]}get nodeAfter(){let e=this.parent,t=this.index(this.depth);if(t==e.childCount)return null;let r=this.pos-this.path[this.path.length-1],i=e.child(t);return r?e.child(t).cut(r):i}get nodeBefore(){let e=this.index(this.depth),t=this.pos-this.path[this.path.length-1];return t?this.parent.child(e).cut(0,t):e==0?null:this.parent.child(e-1)}posAtIndex(e,t){t=this.resolveDepth(t);let r=this.path[t*3],i=t==0?0:this.path[t*3-1]+1;for(let s=0;s0;t--)if(this.start(t)<=e&&this.end(t)>=e)return t;return 0}blockRange(e=this,t){if(e.pos=0;r--)if(e.pos<=this.end(r)&&(!t||t(this.node(r))))return new tn(this,e,r);return null}sameParent(e){return this.pos-this.parentOffset==e.pos-e.parentOffset}max(e){return e.pos>this.pos?e:this}min(e){return e.pos=0&&t<=e.content.size))throw new RangeError("Position "+t+" out of range");let r=[],i=0,s=t;for(let o=e;;){let{index:l,offset:c}=o.content.findIndex(s),a=s-c;if(r.push(o,l,i+c),!a||(o=o.child(l),o.isText))break;s=a-1,i+=c+1}return new n(t,r,s)}static resolveCached(e,t){for(let i=0;ie&&this.nodesBetween(e,t,s=>(r.isInSet(s.marks)&&(i=!0),!i)),i}get isBlock(){return this.type.isBlock}get isTextblock(){return this.type.isTextblock}get inlineContent(){return this.type.inlineContent}get isInline(){return this.type.isInline}get isText(){return this.type.isText}get isLeaf(){return this.type.isLeaf}get isAtom(){return this.type.isAtom}toString(){if(this.type.spec.toDebugString)return this.type.spec.toDebugString(this);let e=this.type.name;return this.content.size&&(e+="("+this.content.toStringInner()+")"),ra(this.marks,e)}contentMatchAt(e){let t=this.type.contentMatch.matchFragment(this.content,0,e);if(!t)throw new Error("Called contentMatchAt on a node with invalid content");return t}canReplace(e,t,r=y.empty,i=0,s=r.childCount){let o=this.contentMatchAt(e).matchFragment(r,i,s),l=o&&o.matchFragment(this.content,t);if(!l||!l.validEnd)return!1;for(let c=i;ct.type.name)}`);this.content.forEach(t=>t.check())}toJSON(){let e={type:this.type.name};for(let t in this.attrs){e.attrs=this.attrs;break}return this.content.size&&(e.content=this.content.toJSON()),this.marks.length&&(e.marks=this.marks.map(t=>t.toJSON())),e}static fromJSON(e,t){if(!t)throw new RangeError("Invalid input for Node.fromJSON");let r=null;if(t.marks){if(!Array.isArray(t.marks))throw new RangeError("Invalid mark data for Node.fromJSON");r=t.marks.map(e.markFromJSON)}if(t.type=="text"){if(typeof t.text!="string")throw new RangeError("Invalid text node in JSON");return e.text(t.text,r)}let i=y.fromJSON(e,t.content);return e.nodeType(t.type).create(t.attrs,i,r)}};Fe.prototype.text=void 0;var yo=class n extends Fe{constructor(e,t,r,i){if(super(e,t,null,i),!r)throw new RangeError("Empty text nodes are not allowed");this.text=r}toString(){return this.type.spec.toDebugString?this.type.spec.toDebugString(this):ra(this.marks,JSON.stringify(this.text))}get textContent(){return this.text}textBetween(e,t){return this.text.slice(e,t)}get nodeSize(){return this.text.length}mark(e){return e==this.marks?this:new n(this.type,this.attrs,this.text,e)}withText(e){return e==this.text?this:new n(this.type,this.attrs,e,this.marks)}cut(e=0,t=this.text.length){return e==0&&t==this.text.length?this:this.withText(this.text.slice(e,t))}eq(e){return this.sameMarkup(e)&&this.text==e.text}toJSON(){let e=super.toJSON();return e.text=this.text,e}};function ra(n,e){for(let t=n.length-1;t>=0;t--)e=n[t].type.name+"("+e+")";return e}var nn=class n{constructor(e){this.validEnd=e,this.next=[],this.wrapCache=[]}static parse(e,t){let r=new wo(e,t);if(r.next==null)return n.empty;let i=ia(r);r.next&&r.err("Unexpected trailing text");let s=dp(hp(i));return fp(s,r),s}matchType(e){for(let t=0;ta.createAndFill()));for(let a=0;a=this.next.length)throw new RangeError(`There's no ${e}th edge in this content match`);return this.next[e]}toString(){let e=[];function t(r){e.push(r);for(let i=0;i{let s=i+(r.validEnd?"*":" ")+" ";for(let o=0;o"+e.indexOf(r.next[o].next);return s}).join(`
+`)}};nn.empty=new nn(!0);var wo=class{constructor(e,t){this.string=e,this.nodeTypes=t,this.inline=null,this.pos=0,this.tokens=e.split(/\s*(?=\b|\W|$)/),this.tokens[this.tokens.length-1]==""&&this.tokens.pop(),this.tokens[0]==""&&this.tokens.shift()}get next(){return this.tokens[this.pos]}eat(e){return this.next==e&&(this.pos++||!0)}err(e){throw new SyntaxError(e+" (in content expression '"+this.string+"')")}};function ia(n){let e=[];do e.push(sp(n));while(n.eat("|"));return e.length==1?e[0]:{type:"choice",exprs:e}}function sp(n){let e=[];do e.push(op(n));while(n.next&&n.next!=")"&&n.next!="|");return e.length==1?e[0]:{type:"seq",exprs:e}}function op(n){let e=ap(n);for(;;)if(n.eat("+"))e={type:"plus",expr:e};else if(n.eat("*"))e={type:"star",expr:e};else if(n.eat("?"))e={type:"opt",expr:e};else if(n.eat("{"))e=lp(n,e);else break;return e}function Jc(n){/\D/.test(n.next)&&n.err("Expected number, got '"+n.next+"'");let e=Number(n.next);return n.pos++,e}function lp(n,e){let t=Jc(n),r=t;return n.eat(",")&&(n.next!="}"?r=Jc(n):r=-1),n.eat("}")||n.err("Unclosed braced range"),{type:"range",min:t,max:r,expr:e}}function cp(n,e){let t=n.nodeTypes,r=t[e];if(r)return[r];let i=[];for(let s in t){let o=t[s];o.groups.indexOf(e)>-1&&i.push(o)}return i.length==0&&n.err("No node type or group '"+e+"' found"),i}function ap(n){if(n.eat("(")){let e=ia(n);return n.eat(")")||n.err("Missing closing paren"),e}else if(/\W/.test(n.next))n.err("Unexpected token '"+n.next+"'");else{let e=cp(n,n.next).map(t=>(n.inline==null?n.inline=t.isInline:n.inline!=t.isInline&&n.err("Mixing inline and block content"),{type:"name",value:t}));return n.pos++,e.length==1?e[0]:{type:"choice",exprs:e}}}function hp(n){let e=[[]];return i(s(n,0),t()),e;function t(){return e.push([])-1}function r(o,l,c){let a={term:c,to:l};return e[o].push(a),a}function i(o,l){o.forEach(c=>c.to=l)}function s(o,l){if(o.type=="choice")return o.exprs.reduce((c,a)=>c.concat(s(a,l)),[]);if(o.type=="seq")for(let c=0;;c++){let a=s(o.exprs[c],l);if(c==o.exprs.length-1)return a;i(a,l=t())}else if(o.type=="star"){let c=t();return r(l,c),i(s(o.expr,c),c),[r(c)]}else if(o.type=="plus"){let c=t();return i(s(o.expr,l),c),i(s(o.expr,c),c),[r(c)]}else{if(o.type=="opt")return[r(l)].concat(s(o.expr,l));if(o.type=="range"){let c=l;for(let a=0;a{n[o].forEach(({term:l,to:c})=>{if(!l)return;let a;for(let h=0;h{a||i.push([l,a=[]]),a.indexOf(h)==-1&&a.push(h)})})});let s=e[r.join(",")]=new nn(r.indexOf(n.length-1)>-1);for(let o=0;o-1}allowsMarks(e){if(this.markSet==null)return!0;for(let t=0;tr[s]=new n(s,t,o));let i=t.spec.topNode||"doc";if(!r[i])throw new RangeError("Schema is missing its top node type ('"+i+"')");if(!r.text)throw new RangeError("Every schema needs a 'text' type");for(let s in r.text.attrs)throw new RangeError("The text node type should not have attributes");return r}},bo=class{constructor(e){this.hasDefault=Object.prototype.hasOwnProperty.call(e,"default"),this.default=e.default}get isRequired(){return!this.hasDefault}},Ar=class n{constructor(e,t,r,i){this.name=e,this.rank=t,this.schema=r,this.spec=i,this.attrs=ca(i.attrs),this.excluded=null;let s=oa(this.attrs);this.instance=s?new D(this,s):null}create(e=null){return!e&&this.instance?this.instance:new D(this,la(this.attrs,e))}static compile(e,t){let r=Object.create(null),i=0;return e.forEach((s,o)=>r[s]=new n(s,i++,t,o)),r}removeFromSet(e){for(var t=0;t-1}},Er=class{constructor(e){this.cached=Object.create(null);let t=this.spec={};for(let i in e)t[i]=e[i];t.nodes=ho.from(e.nodes),t.marks=ho.from(e.marks||{}),this.nodes=Vi.compile(this.spec.nodes,this),this.marks=Ar.compile(this.spec.marks,this);let r=Object.create(null);for(let i in this.nodes){if(i in this.marks)throw new RangeError(i+" can not be both a node and a mark");let s=this.nodes[i],o=s.spec.content||"",l=s.spec.marks;s.contentMatch=r[o]||(r[o]=nn.parse(o,this.nodes)),s.inlineContent=s.contentMatch.inlineContent,s.markSet=l=="_"?null:l?$c(this,l.split(" ")):l==""||!s.inlineContent?[]:null}for(let i in this.marks){let s=this.marks[i],o=s.spec.excludes;s.excluded=o==null?[s]:o==""?[]:$c(this,o.split(" "))}this.nodeFromJSON=this.nodeFromJSON.bind(this),this.markFromJSON=this.markFromJSON.bind(this),this.topNodeType=this.nodes[this.spec.topNode||"doc"],this.cached.wrappings=Object.create(null)}node(e,t=null,r,i){if(typeof e=="string")e=this.nodeType(e);else if(e instanceof Vi){if(e.schema!=this)throw new RangeError("Node type from different schema used ("+e.name+")")}else throw new RangeError("Invalid node type: "+e);return e.createChecked(t,r,i)}text(e,t){let r=this.nodes.text;return new yo(r,r.defaultAttrs,e,D.setFrom(t))}mark(e,t){return typeof e=="string"&&(e=this.marks[e]),e.create(t)}nodeFromJSON(e){return Fe.fromJSON(this,e)}markFromJSON(e){return D.fromJSON(this,e)}nodeType(e){let t=this.nodes[e];if(!t)throw new RangeError("Unknown node type: "+e);return t}};function $c(n,e){let t=[];for(let r=0;r-1)&&t.push(o=c)}if(!o)throw new SyntaxError("Unknown mark type: '"+e[r]+"'")}return t}var zn=class n{constructor(e,t){this.schema=e,this.rules=t,this.tags=[],this.styles=[],t.forEach(r=>{r.tag?this.tags.push(r):r.style&&this.styles.push(r)}),this.normalizeLists=!this.tags.some(r=>{if(!/^(ul|ol)\b/.test(r.tag)||!r.node)return!1;let i=e.nodes[r.node];return i.contentMatch.matchType(i)})}parse(e,t={}){let r=new zi(this,t,!1);return r.addAll(e,t.from,t.to),r.finish()}parseSlice(e,t={}){let r=new zi(this,t,!0);return r.addAll(e,t.from,t.to),b.maxOpen(r.finish())}matchTag(e,t,r){for(let i=r?this.tags.indexOf(r)+1:0;ie.length&&(l.charCodeAt(e.length)!=61||l.slice(e.length+1)!=t))){if(o.getAttrs){let c=o.getAttrs(t);if(c===!1)continue;o.attrs=c||void 0}return o}}}static schemaRules(e){let t=[];function r(i){let s=i.priority==null?50:i.priority,o=0;for(;o{r(o=jc(o)),o.mark||o.ignore||o.clearMark||(o.mark=i)})}for(let i in e.nodes){let s=e.nodes[i].spec.parseDOM;s&&s.forEach(o=>{r(o=jc(o)),o.node||o.ignore||o.mark||(o.node=i)})}return t}static fromSchema(e){return e.cached.domParser||(e.cached.domParser=new n(e,n.schemaRules(e)))}},aa={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},up={head:!0,noscript:!0,object:!0,script:!0,style:!0,title:!0},ha={ol:!0,ul:!0},Pi=1,Li=2,Mr=4;function Kc(n,e,t){return e!=null?(e?Pi:0)|(e==="full"?Li:0):n&&n.whitespace=="pre"?Pi|Li:t&~Mr}var Ln=class{constructor(e,t,r,i,s,o,l){this.type=e,this.attrs=t,this.marks=r,this.pendingMarks=i,this.solid=s,this.options=l,this.content=[],this.activeMarks=D.none,this.stashMarks=[],this.match=o||(l&Mr?null:e.contentMatch)}findWrapping(e){if(!this.match){if(!this.type)return[];let t=this.type.contentMatch.fillBefore(y.from(e));if(t)this.match=this.type.contentMatch.matchFragment(t);else{let r=this.type.contentMatch,i;return(i=r.findWrapping(e.type))?(this.match=r,i):null}}return this.match.findWrapping(e.type)}finish(e){if(!(this.options&Pi)){let r=this.content[this.content.length-1],i;if(r&&r.isText&&(i=/[ \t\r\n\u000c]+$/.exec(r.text))){let s=r;r.text.length==i[0].length?this.content.pop():this.content[this.content.length-1]=s.withText(s.text.slice(0,s.text.length-i[0].length))}}let t=y.from(this.content);return!e&&this.match&&(t=t.append(this.match.fillBefore(y.empty,!0))),this.type?this.type.create(this.attrs,t,this.marks):t}popFromStashMark(e){for(let t=this.stashMarks.length-1;t>=0;t--)if(e.eq(this.stashMarks[t]))return this.stashMarks.splice(t,1)[0]}applyPending(e){for(let t=0,r=this.pendingMarks;tthis.addAll(e)),o&&this.sync(l),this.needsBlock=c}else this.withStyleRules(e,()=>{this.addElementByRule(e,s,s.consuming===!1?i:void 0)})}leafFallback(e){e.nodeName=="BR"&&this.top.type&&this.top.type.inlineContent&&this.addTextNode(e.ownerDocument.createTextNode(`
+`))}ignoreFallback(e){e.nodeName=="BR"&&(!this.top.type||!this.top.type.inlineContent)&&this.findPlace(this.parser.schema.text("-"))}readStyles(e){let t=D.none,r=D.none;for(let i=0;i{o.clearMark(l)&&(r=l.addToSet(r))}):t=this.parser.schema.marks[o.mark].create(o.attrs).addToSet(t),o.consuming===!1)s=o;else break}return[t,r]}addElementByRule(e,t,r){let i,s,o;t.node?(s=this.parser.schema.nodes[t.node],s.isLeaf?this.insertNode(s.create(t.attrs))||this.leafFallback(e):i=this.enter(s,t.attrs||null,t.preserveWhitespace)):(o=this.parser.schema.marks[t.mark].create(t.attrs),this.addPendingMark(o));let l=this.top;if(s&&s.isLeaf)this.findInside(e);else if(r)this.addElement(e,r);else if(t.getContent)this.findInside(e),t.getContent(e,this.parser.schema).forEach(c=>this.insertNode(c));else{let c=e;typeof t.contentElement=="string"?c=e.querySelector(t.contentElement):typeof t.contentElement=="function"?c=t.contentElement(e):t.contentElement&&(c=t.contentElement),this.findAround(e,c,!0),this.addAll(c)}i&&this.sync(l)&&this.open--,o&&this.removePendingMark(o,l)}addAll(e,t,r){let i=t||0;for(let s=t?e.childNodes[t]:e.firstChild,o=r==null?null:e.childNodes[r];s!=o;s=s.nextSibling,++i)this.findAtPoint(e,i),this.addDOM(s);this.findAtPoint(e,i)}findPlace(e){let t,r;for(let i=this.open;i>=0;i--){let s=this.nodes[i],o=s.findWrapping(e);if(o&&(!t||t.length>o.length)&&(t=o,r=s,!o.length)||s.solid)break}if(!t)return!1;this.sync(r);for(let i=0;ithis.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;return!1}get currentPos(){this.closeExtra();let e=0;for(let t=this.open;t>=0;t--){let r=this.nodes[t].content;for(let i=r.length-1;i>=0;i--)e+=r[i].nodeSize;t&&e++}return e}findAtPoint(e,t){if(this.find)for(let r=0;r-1)return e.split(/\s*\|\s*/).some(this.matchesContext,this);let t=e.split("/"),r=this.options.context,i=!this.isOpen&&(!r||r.parent.type==this.nodes[0].type),s=-(r?r.depth+1:0)+(i?0:1),o=(l,c)=>{for(;l>=0;l--){let a=t[l];if(a==""){if(l==t.length-1||l==0)continue;for(;c>=s;c--)if(o(l-1,c))return!0;return!1}else{let h=c>0||c==0&&i?this.nodes[c].type:r&&c>=s?r.node(c-s).type:null;if(!h||h.name!=a&&h.groups.indexOf(a)==-1)return!1;c--}}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 r=e.node(t).contentMatchAt(e.indexAfter(t)).defaultType;if(r&&r.isTextblock&&r.defaultAttrs)return r}for(let t in this.parser.schema.nodes){let r=this.parser.schema.nodes[t];if(r.isTextblock&&r.defaultAttrs)return r}}addPendingMark(e){let t=wp(e,this.top.pendingMarks);t&&this.top.stashMarks.push(t),this.top.pendingMarks=e.addToSet(this.top.pendingMarks)}removePendingMark(e,t){for(let r=this.open;r>=0;r--){let i=this.nodes[r];if(i.pendingMarks.lastIndexOf(e)>-1)i.pendingMarks=e.removeFromSet(i.pendingMarks);else{i.activeMarks=e.removeFromSet(i.activeMarks);let o=i.popFromStashMark(e);o&&i.type&&i.type.allowsMarkType(o.type)&&(i.activeMarks=o.addToSet(i.activeMarks))}if(i==t)break}}};function pp(n){for(let e=n.firstChild,t=null;e;e=e.nextSibling){let r=e.nodeType==1?e.nodeName.toLowerCase():null;r&&ha.hasOwnProperty(r)&&t?(t.appendChild(e),e=t):r=="li"?t=e:r&&(t=null)}}function mp(n,e){return(n.matches||n.msMatchesSelector||n.webkitMatchesSelector||n.mozMatchesSelector).call(n,e)}function gp(n){let e=/\s*([\w-]+)\s*:\s*([^;]+)/g,t,r=[];for(;t=e.exec(n);)r.push(t[1],t[2].trim());return r}function jc(n){let e={};for(let t in n)e[t]=n[t];return e}function yp(n,e){let t=e.schema.nodes;for(let r in t){let i=t[r];if(!i.allowsMarkType(n))continue;let s=[],o=l=>{s.push(l);for(let c=0;c{if(s.length||o.marks.length){let l=0,c=0;for(;l=0;i--){let s=this.serializeMark(e.marks[i],e.isInline,t);s&&((s.contentDOM||s.dom).appendChild(r),r=s.dom)}return r}serializeMark(e,t,r={}){let i=this.marks[e.type.name];return i&&n.renderSpec(mo(r),i(e,t))}static renderSpec(e,t,r=null){if(typeof t=="string")return{dom:e.createTextNode(t)};if(t.nodeType!=null)return{dom:t};if(t.dom&&t.dom.nodeType!=null)return t;let i=t[0],s=i.indexOf(" ");s>0&&(r=i.slice(0,s),i=i.slice(s+1));let o,l=r?e.createElementNS(r,i):e.createElement(i),c=t[1],a=1;if(c&&typeof c=="object"&&c.nodeType==null&&!Array.isArray(c)){a=2;for(let h in c)if(c[h]!=null){let d=h.indexOf(" ");d>0?l.setAttributeNS(h.slice(0,d),h.slice(d+1),c[h]):l.setAttribute(h,c[h])}}for(let h=a;ha)throw new RangeError("Content hole must be the only child of its parent node");return{dom:l,contentDOM:l}}else{let{dom:f,contentDOM:u}=n.renderSpec(e,d,r);if(l.appendChild(f),u){if(o)throw new RangeError("Multiple content holes");o=u}}}return{dom:l,contentDOM:o}}static fromSchema(e){return e.cached.domSerializer||(e.cached.domSerializer=new n(this.nodesFromSchema(e),this.marksFromSchema(e)))}static nodesFromSchema(e){let t=Yc(e.nodes);return t.text||(t.text=r=>r.text),t}static marksFromSchema(e){return Yc(e.marks)}};function Yc(n){let e={};for(let t in n){let r=n[t].spec.toDOM;r&&(e[t]=r)}return e}function mo(n){return n.document||window.document}var ua=65535,pa=Math.pow(2,16);function xp(n,e){return n+e*pa}function da(n){return n&ua}function Sp(n){return(n-(n&ua))/pa}var ma=1,ga=2,Fi=4,ya=8,Or=class{constructor(e,t,r){this.pos=e,this.delInfo=t,this.recover=r}get deleted(){return(this.delInfo&ya)>0}get deletedBefore(){return(this.delInfo&(ma|Fi))>0}get deletedAfter(){return(this.delInfo&(ga|Fi))>0}get deletedAcross(){return(this.delInfo&Fi)>0}},at=class n{constructor(e,t=!1){if(this.ranges=e,this.inverted=t,!e.length&&n.empty)return n.empty}recover(e){let t=0,r=da(e);if(!this.inverted)for(let i=0;ie)break;let a=this.ranges[l+s],h=this.ranges[l+o],d=c+a;if(e<=d){let f=a?e==c?-1:e==d?1:t:t,u=c+i+(f<0?0:h);if(r)return u;let p=e==(t<0?c:d)?null:xp(l/3,e-c),m=e==c?ga:e==d?ma:Fi;return(t<0?e!=c:e!=d)&&(m|=ya),new Or(u,m,p)}i+=h-a}return r?e+i:new Or(e+i,0,null)}touches(e,t){let r=0,i=da(t),s=this.inverted?2:1,o=this.inverted?1:2;for(let l=0;le)break;let a=this.ranges[l+s],h=c+a;if(e<=h&&l==i*3)return!0;r+=this.ranges[l+o]-a}return!1}forEach(e){let t=this.inverted?2:1,r=this.inverted?1:2;for(let i=0,s=0;i=0;t--){let i=e.getMirror(t);this.appendMap(e.maps[t].invert(),i!=null&&i>t?r-i-1:void 0)}}invert(){let e=new n;return e.appendMappingInverted(this),e}map(e,t=1){if(this.mirror)return this._map(e,t,!0);for(let r=this.from;rs&&c!o.isAtom||!l.type.allowsMarkType(this.mark.type)?o:o.mark(this.mark.addToSet(o.marks)),i),t.openStart,t.openEnd);return Q.fromReplace(e,this.from,this.to,s)}invert(){return new rn(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for AddMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};Y.jsonID("addMark",Ir);var rn=class n extends Y{constructor(e,t,r){super(),this.from=e,this.to=t,this.mark=r}apply(e){let t=e.slice(this.from,this.to),r=new b(Ao(t.content,i=>i.mark(this.mark.removeFromSet(i.marks)),e),t.openStart,t.openEnd);return Q.fromReplace(e,this.from,this.to,r)}invert(){return new Ir(this.from,this.to,this.mark)}map(e){let t=e.mapResult(this.from,1),r=e.mapResult(this.to,-1);return t.deleted&&r.deleted||t.pos>=r.pos?null:new n(t.pos,r.pos,this.mark)}merge(e){return e instanceof n&&e.mark.eq(this.mark)&&this.from<=e.to&&this.to>=e.from?new n(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(typeof t.from!="number"||typeof t.to!="number")throw new RangeError("Invalid input for RemoveMarkStep.fromJSON");return new n(t.from,t.to,e.markFromJSON(t.mark))}};Y.jsonID("removeMark",rn);var Rr=class n extends Y{constructor(e,t){super(),this.pos=e,this.mark=t}apply(e){let t=e.nodeAt(this.pos);if(!t)return Q.fail("No node at mark step's position");let r=t.type.create(t.attrs,null,this.mark.addToSet(t.marks));return Q.fromReplace(e,this.pos,this.pos+1,new b(y.from(r),0,t.isLeaf?0:1))}invert(e){let t=e.nodeAt(this.pos);if(t){let r=this.mark.addToSet(t.marks);if(r.length==t.marks.length){for(let i=0;ir.pos?null:new n(t.pos,r.pos,i,s,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(typeof t.from!="number"||typeof t.to!="number"||typeof t.gapFrom!="number"||typeof t.gapTo!="number"||typeof t.insert!="number")throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");return new n(t.from,t.to,t.gapFrom,t.gapTo,b.fromJSON(e,t.slice),t.insert,!!t.structure)}};Y.jsonID("replaceAround",G);function Co(n,e,t){let r=n.resolve(e),i=t-e,s=r.depth;for(;i>0&&s>0&&r.indexAfter(s)==r.node(s).childCount;)s--,i--;if(i>0){let o=r.node(s).maybeChild(r.indexAfter(s));for(;i>0;){if(!o||o.isLeaf)return!0;o=o.firstChild,i--}}return!1}function kp(n,e,t,r){let i=[],s=[],o,l;n.doc.nodesBetween(e,t,(c,a,h)=>{if(!c.isInline)return;let d=c.marks;if(!r.isInSet(d)&&h.type.allowsMarkType(r.type)){let f=Math.max(a,e),u=Math.min(a+c.nodeSize,t),p=r.addToSet(d);for(let m=0;mn.step(c)),s.forEach(c=>n.step(c))}function Cp(n,e,t,r){let i=[],s=0;n.doc.nodesBetween(e,t,(o,l)=>{if(!o.isInline)return;s++;let c=null;if(r instanceof Ar){let a=o.marks,h;for(;h=r.isInSet(a);)(c||(c=[])).push(h),a=h.removeFromSet(a)}else r?r.isInSet(o.marks)&&(c=[r]):c=o.marks;if(c&&c.length){let a=Math.min(l+o.nodeSize,t);for(let h=0;hn.step(new rn(o.from,o.to,o.style)))}function Mp(n,e,t,r=t.contentMatch){let i=n.doc.nodeAt(e),s=[],o=e+1;for(let l=0;l=0;l--)n.step(s[l])}function Ap(n,e,t){return(e==0||n.canReplace(e,n.childCount))&&(t==n.childCount||n.canReplace(0,t))}function sn(n){let t=n.parent.content.cutByIndex(n.startIndex,n.endIndex);for(let r=n.depth;;--r){let i=n.$from.node(r),s=n.$from.index(r),o=n.$to.indexAfter(r);if(rt;p--)m||r.index(p)>0?(m=!0,h=y.from(r.node(p).copy(h)),d++):c--;let f=y.empty,u=0;for(let p=s,m=!1;p>t;p--)m||i.after(p+1)=0;o--){if(r.size){let l=t[o].type.contentMatch.matchFragment(r);if(!l||!l.validEnd)throw new RangeError("Wrapper type given to Transform.wrap does not form valid content of its parent wrapper")}r=y.from(t[o].type.create(t[o].attrs,r))}let i=e.start,s=e.end;n.step(new G(i,s,i,s,new b(r,0,0),t.length,!0))}function Np(n,e,t,r,i){if(!r.isTextblock)throw new RangeError("Type given to setBlockType should be a textblock");let s=n.steps.length;n.doc.nodesBetween(e,t,(o,l)=>{if(o.isTextblock&&!o.hasMarkup(r,i)&&Ip(n.doc,n.mapping.slice(s).map(l),r)){n.clearIncompatible(n.mapping.slice(s).map(l,1),r);let c=n.mapping.slice(s),a=c.map(l,1),h=c.map(l+o.nodeSize,1);return n.step(new G(a,h,a+1,h-1,new b(y.from(r.create(i,null,o.marks)),0,0),1,!0)),!1}})}function Ip(n,e,t){let r=n.resolve(e),i=r.index();return r.parent.canReplaceWith(i,i+1,t)}function Rp(n,e,t,r,i){let s=n.doc.nodeAt(e);if(!s)throw new RangeError("No node at given position");t||(t=s.type);let o=t.create(r,null,i||s.marks);if(s.isLeaf)return n.replaceWith(e,e+s.nodeSize,o);if(!t.validContent(s.content))throw new RangeError("Invalid content for node type "+t.name);n.step(new G(e,e+s.nodeSize,e+1,e+s.nodeSize-1,new b(y.from(o),0,0),1,!0))}function Ot(n,e,t=1,r){let i=n.resolve(e),s=i.depth-t,o=r&&r[r.length-1]||i.parent;if(s<0||i.parent.type.spec.isolating||!i.parent.canReplace(i.index(),i.parent.childCount)||!o.type.validContent(i.parent.content.cutByIndex(i.index(),i.parent.childCount)))return!1;for(let a=i.depth-1,h=t-2;a>s;a--,h--){let d=i.node(a),f=i.index(a);if(d.type.spec.isolating)return!1;let u=d.content.cutByIndex(f,d.childCount),p=r&&r[h+1];p&&(u=u.replaceChild(0,p.type.create(p.attrs)));let m=r&&r[h]||d;if(!d.canReplace(f+1,d.childCount)||!m.type.validContent(u))return!1}let l=i.indexAfter(s),c=r&&r[0];return i.node(s).canReplaceWith(l,l,c?c.type:i.node(s+1).type)}function vp(n,e,t=1,r){let i=n.doc.resolve(e),s=y.empty,o=y.empty;for(let l=i.depth,c=i.depth-t,a=t-1;l>c;l--,a--){s=y.from(i.node(l).copy(s));let h=r&&r[a];o=y.from(h?h.type.create(h.attrs,o):i.node(l).copy(o))}n.step(new Ce(e,e,new b(s.append(o),t,t),!0))}function on(n,e){let t=n.resolve(e),r=t.index();return wa(t.nodeBefore,t.nodeAfter)&&t.parent.canReplace(r,r+1)}function wa(n,e){return!!(n&&e&&!n.isLeaf&&n.canAppend(e))}function Eo(n,e,t=-1){let r=n.resolve(e);for(let i=r.depth;;i--){let s,o,l=r.index(i);if(i==r.depth?(s=r.nodeBefore,o=r.nodeAfter):t>0?(s=r.node(i+1),l++,o=r.node(i).maybeChild(l)):(s=r.node(i).maybeChild(l-1),o=r.node(i+1)),s&&!s.isTextblock&&wa(s,o)&&r.node(i).canReplace(l,l+1))return e;if(i==0)break;e=t<0?r.before(i):r.after(i)}}function _p(n,e,t){let r=new Ce(e-t,e+t,b.empty,!0);n.step(r)}function Up(n,e,t){let r=n.resolve(e);if(r.parent.canReplaceWith(r.index(),r.index(),t))return e;if(r.parentOffset==0)for(let i=r.depth-1;i>=0;i--){let s=r.index(i);if(r.node(i).canReplaceWith(s,s,t))return r.before(i+1);if(s>0)return null}if(r.parentOffset==r.parent.content.size)for(let i=r.depth-1;i>=0;i--){let s=r.indexAfter(i);if(r.node(i).canReplaceWith(s,s,t))return r.after(i+1);if(s=0;o--){let l=o==r.depth?0:r.pos<=(r.start(o+1)+r.end(o+1))/2?-1:1,c=r.index(o)+(l>0?1:0),a=r.node(o),h=!1;if(s==1)h=a.canReplace(c,c,i);else{let d=a.contentMatchAt(c).findWrapping(i.firstChild.type);h=d&&a.canReplaceWith(c,c,d[0])}if(h)return l==0?r.pos:l<0?r.before(o+1):r.after(o+1)}return null}function Wi(n,e,t=e,r=b.empty){if(e==t&&!r.size)return null;let i=n.resolve(e),s=n.resolve(t);return xa(i,s,r)?new Ce(e,t,r):new Mo(i,s,r).fit()}function xa(n,e,t){return!t.openStart&&!t.openEnd&&n.start()==e.start()&&n.parent.canReplace(n.index(),e.index(),t.content)}var Mo=class{constructor(e,t,r){this.$from=e,this.$to=t,this.unplaced=r,this.frontier=[],this.placed=y.empty;for(let i=0;i<=e.depth;i++){let s=e.node(i);this.frontier.push({type:s.type,match:s.contentMatchAt(e.indexAfter(i))})}for(let i=e.depth;i>0;i--)this.placed=y.from(e.node(i).copy(this.placed))}get depth(){return this.frontier.length-1}fit(){for(;this.unplaced.size;){let a=this.findFittable();a?this.placeNodes(a):this.openMore()||this.dropNode()}let e=this.mustMoveInline(),t=this.placed.size-this.depth-this.$from.depth,r=this.$from,i=this.close(e<0?this.$to:r.doc.resolve(e));if(!i)return null;let s=this.placed,o=r.depth,l=i.depth;for(;o&&l&&s.childCount==1;)s=s.firstChild.content,o--,l--;let c=new b(s,o,l);return e>-1?new G(r.pos,e,this.$to.pos,this.$to.end(),c,t):c.size||r.pos!=this.$to.pos?new Ce(r.pos,i.pos,c):null}findFittable(){let e=this.unplaced.openStart;for(let t=this.unplaced.content,r=0,i=this.unplaced.openEnd;r1&&(i=0),s.type.spec.isolating&&i<=r){e=r;break}t=s.content}for(let t=1;t<=2;t++)for(let r=t==1?e:this.unplaced.openStart;r>=0;r--){let i,s=null;r?(s=So(this.unplaced.content,r-1).firstChild,i=s.content):i=this.unplaced.content;let o=i.firstChild;for(let l=this.depth;l>=0;l--){let{type:c,match:a}=this.frontier[l],h,d=null;if(t==1&&(o?a.matchType(o.type)||(d=a.fillBefore(y.from(o),!1)):s&&c.compatibleContent(s.type)))return{sliceDepth:r,frontierDepth:l,parent:s,inject:d};if(t==2&&o&&(h=a.findWrapping(o.type)))return{sliceDepth:r,frontierDepth:l,parent:s,wrap:h};if(s&&a.matchType(s.type))break}}}openMore(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=So(e,t);return!i.childCount||i.firstChild.isLeaf?!1:(this.unplaced=new b(e,t+1,Math.max(r,i.size+t>=e.size-r?t+1:0)),!0)}dropNode(){let{content:e,openStart:t,openEnd:r}=this.unplaced,i=So(e,t);if(i.childCount<=1&&t>0){let s=e.size-t<=t+i.size;this.unplaced=new b(Dr(e,t-1,1),t-1,s?t-1:r)}else this.unplaced=new b(Dr(e,t,1),t,r)}placeNodes({sliceDepth:e,frontierDepth:t,parent:r,inject:i,wrap:s}){for(;this.depth>t;)this.closeFrontierNode();if(s)for(let m=0;m1||c==0||m.content.size)&&(d=g,h.push(Sa(m.mark(f.allowedMarks(m.marks)),a==1?c:0,a==l.childCount?u:-1)))}let p=a==l.childCount;p||(u=-1),this.placed=Tr(this.placed,t,y.from(h)),this.frontier[t].match=d,p&&u<0&&r&&r.type==this.frontier[this.depth].type&&this.frontier.length>1&&this.closeFrontierNode();for(let m=0,g=l;m1&&i==this.$to.end(--r);)++i;return i}findCloseLevel(e){e:for(let t=Math.min(this.depth,e.depth);t>=0;t--){let{match:r,type:i}=this.frontier[t],s=t=0;l--){let{match:c,type:a}=this.frontier[l],h=ko(e,l,a,c,!0);if(!h||h.childCount)continue e}return{depth:t,fit:o,move:s?e.doc.resolve(e.after(t+1)):e}}}}close(e){let t=this.findCloseLevel(e);if(!t)return null;for(;this.depth>t.depth;)this.closeFrontierNode();t.fit.childCount&&(this.placed=Tr(this.placed,t.depth,t.fit)),e=t.move;for(let r=t.depth+1;r<=e.depth;r++){let i=e.node(r),s=i.type.contentMatch.fillBefore(i.content,!0,e.index(r));this.openFrontierNode(i.type,i.attrs,s)}return e}openFrontierNode(e,t=null,r){let i=this.frontier[this.depth];i.match=i.match.matchType(e),this.placed=Tr(this.placed,this.depth,y.from(e.create(t,r))),this.frontier.push({type:e,match:e.contentMatch})}closeFrontierNode(){let t=this.frontier.pop().match.fillBefore(y.empty,!0);t.childCount&&(this.placed=Tr(this.placed,this.frontier.length,t))}};function Dr(n,e,t){return e==0?n.cutByIndex(t,n.childCount):n.replaceChild(0,n.firstChild.copy(Dr(n.firstChild.content,e-1,t)))}function Tr(n,e,t){return e==0?n.append(t):n.replaceChild(n.childCount-1,n.lastChild.copy(Tr(n.lastChild.content,e-1,t)))}function So(n,e){for(let t=0;t1&&(r=r.replaceChild(0,Sa(r.firstChild,e-1,r.childCount==1?t-1:0))),e>0&&(r=n.type.contentMatch.fillBefore(r).append(r),t<=0&&(r=r.append(n.type.contentMatch.matchFragment(r).fillBefore(y.empty,!0)))),n.copy(r)}function ko(n,e,t,r,i){let s=n.node(e),o=i?n.indexAfter(e):n.index(e);if(o==s.childCount&&!t.compatibleContent(s.type))return null;let l=r.fillBefore(s.content,!0,o);return l&&!Bp(t,s.content,o)?l:null}function Bp(n,e,t){for(let r=t;r0;f--,u--){let p=i.node(f).type.spec;if(p.defining||p.definingAsContext||p.isolating)break;o.indexOf(f)>-1?l=f:i.before(f)==u&&o.splice(1,0,-f)}let c=o.indexOf(l),a=[],h=r.openStart;for(let f=r.content,u=0;;u++){let p=f.firstChild;if(a.push(p),u==r.openStart)break;f=p.content}for(let f=h-1;f>=0;f--){let u=a[f],p=Vp(u.type);if(p&&!u.sameMarkup(i.node(Math.abs(l)-1)))h=f;else if(p||!u.type.isTextblock)break}for(let f=r.openStart;f>=0;f--){let u=(f+h+1)%(r.openStart+1),p=a[u];if(p)for(let m=0;m=0&&(n.replace(e,t,r),!(n.steps.length>d));f--){let u=o[f];u<0||(e=i.before(u),t=s.after(u))}}function ka(n,e,t,r,i){if(er){let s=i.contentMatchAt(0),o=s.fillBefore(n).append(n);n=o.append(s.matchFragment(o).fillBefore(y.empty,!0))}return n}function Lp(n,e,t,r){if(!r.isInline&&e==t&&n.doc.resolve(e).parent.content.size){let i=Up(n.doc,e,r.type);i!=null&&(e=t=i)}n.replaceRange(e,t,new b(y.from(r),0,0))}function zp(n,e,t){let r=n.doc.resolve(e),i=n.doc.resolve(t),s=Ca(r,i);for(let o=0;o0&&(c||r.node(l-1).canReplace(r.index(l-1),i.indexAfter(l-1))))return n.delete(r.before(l),i.after(l))}for(let o=1;o<=r.depth&&o<=i.depth;o++)if(e-r.start(o)==r.depth-o&&t>r.end(o)&&i.end(o)-t!=i.depth-o)return n.delete(r.before(o),t);n.delete(e,t)}function Ca(n,e){let t=[],r=Math.min(n.depth,e.depth);for(let i=r;i>=0;i--){let s=n.start(i);if(se.pos+(e.depth-i)||n.node(i).type.spec.isolating||e.node(i).type.spec.isolating)break;(s==e.start(i)||i==n.depth&&i==e.depth&&n.parent.inlineContent&&e.parent.inlineContent&&i&&e.start(i-1)==s-1)&&t.push(i)}return t}var qi=class n extends Y{constructor(e,t,r){super(),this.pos=e,this.attr=t,this.value=r}apply(e){let t=e.nodeAt(this.pos);if(!t)return Q.fail("No node at attribute step's position");let r=Object.create(null);for(let s in t.attrs)r[s]=t.attrs[s];r[this.attr]=this.value;let i=t.type.create(r,null,t.marks);return Q.fromReplace(e,this.pos,this.pos+1,new b(y.from(i),0,t.isLeaf?0:1))}getMap(){return at.empty}invert(e){return new n(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 n(t.pos,this.attr,this.value)}toJSON(){return{stepType:"attr",pos:this.pos,attr:this.attr,value:this.value}}static fromJSON(e,t){if(typeof t.pos!="number"||typeof t.attr!="string")throw new RangeError("Invalid input for AttrStep.fromJSON");return new n(t.pos,t.attr,t.value)}};Y.jsonID("attr",qi);var Hi=class n extends Y{constructor(e,t){super(),this.attr=e,this.value=t}apply(e){let t=Object.create(null);for(let i in e.attrs)t[i]=e.attrs[i];t[this.attr]=this.value;let r=e.type.create(t,e.content,e.marks);return Q.ok(r)}getMap(){return at.empty}invert(e){return new n(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(typeof t.attr!="string")throw new RangeError("Invalid input for DocAttrStep.fromJSON");return new n(t.attr,t.value)}};Y.jsonID("docAttr",Hi);var Fn=class extends Error{};Fn=function n(e){let t=Error.call(this,e);return t.__proto__=n.prototype,t};Fn.prototype=Object.create(Error.prototype);Fn.prototype.constructor=Fn;Fn.prototype.name="TransformError";var qn=class{constructor(e){this.doc=e,this.steps=[],this.docs=[],this.mapping=new Nr}get before(){return this.docs.length?this.docs[0]:this.doc}step(e){let t=this.maybeStep(e);if(t.failed)throw new Fn(t.failed);return this}maybeStep(e){let t=e.apply(this.doc);return t.failed||this.addStep(e,t.doc),t}get docChanged(){return this.steps.length>0}addStep(e,t){this.docs.push(this.doc),this.steps.push(e),this.mapping.appendMap(e.getMap()),this.doc=t}replace(e,t=e,r=b.empty){let i=Wi(this.doc,e,t,r);return i&&this.step(i),this}replaceWith(e,t,r){return this.replace(e,t,new b(y.from(r),0,0))}delete(e,t){return this.replace(e,t,b.empty)}insert(e,t){return this.replaceWith(e,e,t)}replaceRange(e,t,r){return Pp(this,e,t,r),this}replaceRangeWith(e,t,r){return Lp(this,e,t,r),this}deleteRange(e,t){return zp(this,e,t),this}lift(e,t){return Ep(this,e,t),this}join(e,t=1){return _p(this,e,t),this}wrap(e,t){return Op(this,e,t),this}setBlockType(e,t=e,r,i=null){return Np(this,e,t,r,i),this}setNodeMarkup(e,t,r=null,i){return Rp(this,e,t,r,i),this}setNodeAttribute(e,t,r){return this.step(new qi(e,t,r)),this}setDocAttribute(e,t){return this.step(new Hi(e,t)),this}addNodeMark(e,t){return this.step(new Rr(e,t)),this}removeNodeMark(e,t){if(!(t instanceof D)){let r=this.doc.nodeAt(e);if(!r)throw new RangeError("No node at position "+e);if(t=t.isInSet(r.marks),!t)return this}return this.step(new vr(e,t)),this}split(e,t=1,r){return vp(this,e,t,r),this}addMark(e,t,r){return kp(this,e,t,r),this}removeMark(e,t,r){return Cp(this,e,t,r),this}clearIncompatible(e,t,r){return Mp(this,e,t,r),this}};var Do=Object.create(null),S=class{constructor(e,t,r){this.$anchor=e,this.$head=t,this.ranges=r||[new Ur(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=0;s--){let o=t<0?Hn(e.node(0),e.node(s),e.before(s+1),e.index(s),t,r):Hn(e.node(0),e.node(s),e.after(s+1),e.index(s)+1,t,r);if(o)return o}return null}static near(e,t=1){return this.findFrom(e,t)||this.findFrom(e,-t)||new Me(e.node(0))}static atStart(e){return Hn(e,e,0,0,1)||new Me(e)}static atEnd(e){return Hn(e,e,e.content.size,e.childCount,-1)||new Me(e)}static fromJSON(e,t){if(!t||!t.type)throw new RangeError("Invalid input for Selection.fromJSON");let r=Do[t.type];if(!r)throw new RangeError(`No selection type ${t.type} defined`);return r.fromJSON(e,t)}static jsonID(e,t){if(e in Do)throw new RangeError("Duplicate use of selection JSON ID "+e);return Do[e]=t,t.prototype.jsonID=e,t}getBookmark(){return A.between(this.$anchor,this.$head).getBookmark()}};S.prototype.visible=!0;var Ur=class{constructor(e,t){this.$from=e,this.$to=t}},Ma=!1;function Aa(n){!Ma&&!n.parent.inlineContent&&(Ma=!0,console.warn("TextSelection endpoint not pointing into a node with inline content ("+n.parent.type.name+")"))}var A=class n extends S{constructor(e,t=e){Aa(e),Aa(t),super(e,t)}get $cursor(){return this.$anchor.pos==this.$head.pos?this.$head:null}map(e,t){let r=e.resolve(t.map(this.head));if(!r.parent.inlineContent)return S.near(r);let i=e.resolve(t.map(this.anchor));return new n(i.parent.inlineContent?i:r,r)}replace(e,t=b.empty){if(super.replace(e,t),t==b.empty){let r=this.$from.marksAcross(this.$to);r&&e.ensureMarks(r)}}eq(e){return e instanceof n&&e.anchor==this.anchor&&e.head==this.head}getBookmark(){return new Ki(this.anchor,this.head)}toJSON(){return{type:"text",anchor:this.anchor,head:this.head}}static fromJSON(e,t){if(typeof t.anchor!="number"||typeof t.head!="number")throw new RangeError("Invalid input for TextSelection.fromJSON");return new n(e.resolve(t.anchor),e.resolve(t.head))}static create(e,t,r=t){let i=e.resolve(t);return new this(i,r==t?i:e.resolve(r))}static between(e,t,r){let i=e.pos-t.pos;if((!r||i)&&(r=i>=0?1:-1),!t.parent.inlineContent){let s=S.findFrom(t,r,!0)||S.findFrom(t,-r,!0);if(s)t=s.$head;else return S.near(t,r)}return e.parent.inlineContent||(i==0?e=t:(e=(S.findFrom(e,-r,!0)||S.findFrom(e,r,!0)).$anchor,e.pos0?0:1);i>0?o=0;o+=i){let l=e.child(o);if(l.isAtom){if(!s&&C.isSelectable(l))return C.create(n,t-(i<0?l.nodeSize:0))}else{let c=Hn(n,l,t+i,i<0?l.childCount:0,i,s);if(c)return c}t+=l.nodeSize*i}return null}function Ea(n,e,t){let r=n.steps.length-1;if(r{o==null&&(o=h)}),n.setSelection(S.near(n.doc.resolve(o),t))}var Da=1,$i=2,Ta=4,No=class extends qn{constructor(e){super(e.doc),this.curSelectionFor=0,this.updated=0,this.meta=Object.create(null),this.time=Date.now(),this.curSelection=e.selection,this.storedMarks=e.storedMarks}get selection(){return this.curSelectionFor0}setStoredMarks(e){return this.storedMarks=e,this.updated|=$i,this}ensureMarks(e){return D.sameSet(this.storedMarks||this.selection.$from.marks(),e)||this.setStoredMarks(e),this}addStoredMark(e){return this.ensureMarks(e.addToSet(this.storedMarks||this.selection.$head.marks()))}removeStoredMark(e){return this.ensureMarks(e.removeFromSet(this.storedMarks||this.selection.$head.marks()))}get storedMarksSet(){return(this.updated&$i)>0}addStep(e,t){super.addStep(e,t),this.updated=this.updated&~$i,this.storedMarks=null}setTime(e){return this.time=e,this}replaceSelection(e){return this.selection.replace(this,e),this}replaceSelectionWith(e,t=!0){let r=this.selection;return t&&(e=e.mark(this.storedMarks||(r.empty?r.$from.marks():r.$from.marksAcross(r.$to)||D.none))),r.replaceWith(this,e),this}deleteSelection(){return this.selection.replace(this),this}insertText(e,t,r){let i=this.doc.type.schema;if(t==null)return e?this.replaceSelectionWith(i.text(e),!0):this.deleteSelection();{if(r==null&&(r=t),r=r??t,!e)return this.deleteRange(t,r);let s=this.storedMarks;if(!s){let o=this.doc.resolve(t);s=r==t?o.marks():o.marksAcross(this.doc.resolve(r))}return this.replaceRangeWith(t,r,i.text(e,s)),this.selection.empty||this.setSelection(S.near(this.selection.$to)),this}}setMeta(e,t){return this.meta[typeof e=="string"?e:e.key]=t,this}getMeta(e){return this.meta[typeof e=="string"?e:e.key]}get isGeneric(){for(let e in this.meta)return!1;return!0}scrollIntoView(){return this.updated|=Ta,this}get scrolledIntoView(){return(this.updated&Ta)>0}};function Oa(n,e){return!e||!n?n:n.bind(e)}var ln=class{constructor(e,t,r){this.name=e,this.init=Oa(t.init,r),this.apply=Oa(t.apply,r)}},qp=[new ln("doc",{init(n){return n.doc||n.schema.topNodeType.createAndFill()},apply(n){return n.doc}}),new ln("selection",{init(n,e){return n.selection||S.atStart(e.doc)},apply(n){return n.selection}}),new ln("storedMarks",{init(n){return n.storedMarks||null},apply(n,e,t,r){return r.selection.$cursor?n.storedMarks:null}}),new ln("scrollToSelection",{init(){return 0},apply(n,e){return n.scrolledIntoView?e+1:e}})],_r=class{constructor(e,t){this.schema=e,this.plugins=[],this.pluginsByKey=Object.create(null),this.fields=qp.slice(),t&&t.forEach(r=>{if(this.pluginsByKey[r.key])throw new RangeError("Adding different instances of a keyed plugin ("+r.key+")");this.plugins.push(r),this.pluginsByKey[r.key]=r,r.spec.state&&this.fields.push(new ln(r.key,r.spec.state,r))})}},Io=class n{constructor(e){this.config=e}get schema(){return this.config.schema}get plugins(){return this.config.plugins}apply(e){return this.applyTransaction(e).state}filterTransaction(e,t=-1){for(let r=0;rr.toJSON())),e&&typeof e=="object")for(let r in e){if(r=="doc"||r=="selection")throw new RangeError("The JSON fields `doc` and `selection` are reserved");let i=e[r],s=i.spec.state;s&&s.toJSON&&(t[r]=s.toJSON.call(i,this[i.key]))}return t}static fromJSON(e,t,r){if(!t)throw new RangeError("Invalid input for EditorState.fromJSON");if(!e.schema)throw new RangeError("Required config field 'schema' missing");let i=new _r(e.schema,e.plugins),s=new n(i);return i.fields.forEach(o=>{if(o.name=="doc")s.doc=Fe.fromJSON(e.schema,t.doc);else if(o.name=="selection")s.selection=S.fromJSON(s.doc,t.selection);else if(o.name=="storedMarks")t.storedMarks&&(s.storedMarks=t.storedMarks.map(e.schema.markFromJSON));else{if(r)for(let l in r){let c=r[l],a=c.spec.state;if(c.key==o.name&&a&&a.fromJSON&&Object.prototype.hasOwnProperty.call(t,l)){s[o.name]=a.fromJSON.call(c,e,t[l],s);return}}s[o.name]=o.init(e,s)}}),s}};function Na(n,e,t){for(let r in n){let i=n[r];i instanceof Function?i=i.bind(e):r=="handleDOMEvents"&&(i=Na(i,e,{})),t[r]=i}return t}var W=class{constructor(e){this.spec=e,this.props={},e.props&&Na(e.props,this,this.props),this.key=e.key?e.key.key:Ia("plugin")}getState(e){return e[this.key]}},To=Object.create(null);function Ia(n){return n in To?n+"$"+ ++To[n]:(To[n]=0,n+"$")}var fe=class{constructor(e="key"){this.key=Ia(e)}get(e){return e.config.pluginsByKey[this.key]}getState(e){return e[this.key]}};var ue=function(n){for(var e=0;;e++)if(n=n.previousSibling,!n)return e},Lr=function(n){let e=n.assignedSlot||n.parentNode;return e&&e.nodeType==11?e.host:e},Ra=null,dt=function(n,e,t){let r=Ra||(Ra=document.createRange());return r.setEnd(n,t??n.nodeValue.length),r.setStart(n,e||0),r},pn=function(n,e,t,r){return t&&(va(n,e,t,r,-1)||va(n,e,t,r,1))},Hp=/^(img|br|input|textarea|hr)$/i;function va(n,e,t,r,i){for(;;){if(n==t&&e==r)return!0;if(e==(i<0?0:qe(n))){let s=n.parentNode;if(!s||s.nodeType!=1||tl(n)||Hp.test(n.nodeName)||n.contentEditable=="false")return!1;e=ue(n)+(i<0?0:1),n=s}else if(n.nodeType==1){if(n=n.childNodes[e+(i<0?-1:0)],n.contentEditable=="false")return!1;e=i<0?qe(n):0}else return!1}}function qe(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Jp(n,e,t){for(let r=e==0,i=e==qe(n);r||i;){if(n==t)return!0;let s=ue(n);if(n=n.parentNode,!n)return!1;r=r&&s==0,i=i&&s==qe(n)}}function tl(n){let e;for(let t=n;t&&!(e=t.pmViewDesc);t=t.parentNode);return e&&e.node&&e.node.isBlock&&(e.dom==n||e.contentDOM==n)}var rs=function(n){return n.focusNode&&pn(n.focusNode,n.focusOffset,n.anchorNode,n.anchorOffset)};function cn(n,e){let t=document.createEvent("Event");return t.initEvent("keydown",!0,!0),t.keyCode=n,t.key=t.code=e,t}function Wp(n){let e=n.activeElement;for(;e&&e.shadowRoot;)e=e.shadowRoot.activeElement;return e}function $p(n,e,t){if(n.caretPositionFromPoint)try{let r=n.caretPositionFromPoint(e,t);if(r)return{node:r.offsetNode,offset:r.offset}}catch{}if(n.caretRangeFromPoint){let r=n.caretRangeFromPoint(e,t);if(r)return{node:r.startContainer,offset:r.startOffset}}}var He=typeof navigator<"u"?navigator:null,_a=typeof document<"u"?document:null,Ut=He&&He.userAgent||"",Bo=/Edge\/(\d+)/.exec(Ut),dh=/MSIE \d/.exec(Ut),Vo=/Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(Ut),xe=!!(dh||Vo||Bo),vt=dh?document.documentMode:Vo?+Vo[1]:Bo?+Bo[1]:0,ze=!xe&&/gecko\/(\d+)/i.test(Ut);ze&&+(/Firefox\/(\d+)/.exec(Ut)||[0,0])[1];var Po=!xe&&/Chrome\/(\d+)/.exec(Ut),oe=!!Po,Kp=Po?+Po[1]:0,pe=!xe&&!!He&&/Apple Computer/.test(He.vendor),jn=pe&&(/Mobile\/\w+/.test(Ut)||!!He&&He.maxTouchPoints>2),Re=jn||(He?/Mac/.test(He.platform):!1),jp=He?/Win/.test(He.platform):!1,Le=/Android \d/.test(Ut),Hr=!!_a&&"webkitFontSmoothing"in _a.documentElement.style,Yp=Hr?+(/\bAppleWebKit\/(\d+)/.exec(navigator.userAgent)||[0,0])[1]:0;function Gp(n){return{left:0,right:n.documentElement.clientWidth,top:0,bottom:n.documentElement.clientHeight}}function ht(n,e){return typeof n=="number"?n:n[e]}function Xp(n){let e=n.getBoundingClientRect(),t=e.width/n.offsetWidth||1,r=e.height/n.offsetHeight||1;return{left:e.left,right:e.left+n.clientWidth*t,top:e.top,bottom:e.top+n.clientHeight*r}}function Ua(n,e,t){let r=n.someProp("scrollThreshold")||0,i=n.someProp("scrollMargin")||5,s=n.dom.ownerDocument;for(let o=t||n.dom;o;o=Lr(o)){if(o.nodeType!=1)continue;let l=o,c=l==s.body,a=c?Gp(s):Xp(l),h=0,d=0;if(e.topa.bottom-ht(r,"bottom")&&(d=e.bottom-e.top>a.bottom-a.top?e.top+ht(i,"top")-a.top:e.bottom-a.bottom+ht(i,"bottom")),e.lefta.right-ht(r,"right")&&(h=e.right-a.right+ht(i,"right")),h||d)if(c)s.defaultView.scrollBy(h,d);else{let f=l.scrollLeft,u=l.scrollTop;d&&(l.scrollTop+=d),h&&(l.scrollLeft+=h);let p=l.scrollLeft-f,m=l.scrollTop-u;e={left:e.left-p,top:e.top-m,right:e.right-p,bottom:e.bottom-m}}if(c||/^(fixed|sticky)$/.test(getComputedStyle(o).position))break}}function Qp(n){let e=n.dom.getBoundingClientRect(),t=Math.max(0,e.top),r,i;for(let s=(e.left+e.right)/2,o=t+1;o=t-20){r=l,i=c.top;break}}return{refDOM:r,refTop:i,stack:fh(n.dom)}}function fh(n){let e=[],t=n.ownerDocument;for(let r=n;r&&(e.push({dom:r,top:r.scrollTop,left:r.scrollLeft}),n!=t);r=Lr(r));return e}function Zp({refDOM:n,refTop:e,stack:t}){let r=n?n.getBoundingClientRect().top:0;uh(t,r==0?0:r-e)}function uh(n,e){for(let t=0;t=l){o=Math.max(p.bottom,o),l=Math.min(p.top,l);let m=p.left>e.left?p.left-e.left:p.right=(p.left+p.right)/2?1:0));continue}}else p.top>e.top&&!c&&p.left<=e.left&&p.right>=e.left&&(c=h,a={left:Math.max(p.left,Math.min(p.right,e.left)),top:p.top});!t&&(e.left>=p.right&&e.top>=p.top||e.left>=p.left&&e.top>=p.bottom)&&(s=d+1)}}return!t&&c&&(t=c,i=a,r=0),t&&t.nodeType==3?tm(t,i):!t||r&&t.nodeType==1?{node:n,offset:s}:ph(t,i)}function tm(n,e){let t=n.nodeValue.length,r=document.createRange();for(let i=0;i=(s.left+s.right)/2?1:0)}}return{node:n,offset:0}}function nl(n,e){return n.left>=e.left-1&&n.left<=e.right+1&&n.top>=e.top-1&&n.top<=e.bottom+1}function nm(n,e){let t=n.parentNode;return t&&/^li$/i.test(t.nodeName)&&e.left(o.left+o.right)/2?1:-1}return n.docView.posFromDOM(r,i,s)}function im(n,e,t,r){let i=-1;for(let s=e,o=!1;s!=n.dom;){let l=n.docView.nearestDesc(s,!0);if(!l)return null;if(l.dom.nodeType==1&&(l.node.isBlock&&l.parent&&!o||!l.contentDOM)){let c=l.dom.getBoundingClientRect();if(l.node.isBlock&&l.parent&&!o&&(o=!0,c.left>r.left||c.top>r.top?i=l.posBefore:(c.right-1?i:n.docView.posFromDOM(e,t,-1)}function mh(n,e,t){let r=n.childNodes.length;if(r&&t.tope.top&&i++}let a;Hr&&i&&r.nodeType==1&&(a=r.childNodes[i-1]).nodeType==1&&a.contentEditable=="false"&&a.getBoundingClientRect().top>=e.top&&i--,r==n.dom&&i==r.childNodes.length-1&&r.lastChild.nodeType==1&&e.top>r.lastChild.getBoundingClientRect().bottom?l=n.state.doc.content.size:(i==0||r.nodeType!=1||r.childNodes[i-1].nodeName!="BR")&&(l=im(n,r,i,e))}l==null&&(l=rm(n,o,e));let c=n.docView.nearestDesc(o,!0);return{pos:l,inside:c?c.posAtStart-c.border:-1}}function Ba(n){return n.top=0&&i==r.nodeValue.length?(c--,h=1):t<0?c--:a++,Br(Nt(dt(r,c,a),h),h<0)}if(!n.state.doc.resolve(e-(s||0)).parent.inlineContent){if(s==null&&i&&(t<0||i==qe(r))){let c=r.childNodes[i-1];if(c.nodeType==1)return Ro(c.getBoundingClientRect(),!1)}if(s==null&&i=0)}if(s==null&&i&&(t<0||i==qe(r))){let c=r.childNodes[i-1],a=c.nodeType==3?dt(c,qe(c)-(o?0:1)):c.nodeType==1&&(c.nodeName!="BR"||!c.nextSibling)?c:null;if(a)return Br(Nt(a,1),!1)}if(s==null&&i=0)}function Br(n,e){if(n.width==0)return n;let t=e?n.left:n.right;return{top:n.top,bottom:n.bottom,left:t,right:t}}function Ro(n,e){if(n.height==0)return n;let t=e?n.top:n.bottom;return{top:t,bottom:t,left:n.left,right:n.right}}function yh(n,e,t){let r=n.state,i=n.root.activeElement;r!=e&&n.updateState(e),i!=n.dom&&n.focus();try{return t()}finally{r!=e&&n.updateState(r),i!=n.dom&&i&&i.focus()}}function lm(n,e,t){let r=e.selection,i=t=="up"?r.$from:r.$to;return yh(n,e,()=>{let{node:s}=n.docView.domFromPos(i.pos,t=="up"?-1:1);for(;;){let l=n.docView.nearestDesc(s,!0);if(!l)break;if(l.node.isBlock){s=l.contentDOM||l.dom;break}s=l.dom.parentNode}let o=gh(n,i.pos,1);for(let l=s.firstChild;l;l=l.nextSibling){let c;if(l.nodeType==1)c=l.getClientRects();else if(l.nodeType==3)c=dt(l,0,l.nodeValue.length).getClientRects();else continue;for(let a=0;ah.top+1&&(t=="up"?o.top-h.top>(h.bottom-o.top)*2:h.bottom-o.bottom>(o.bottom-h.top)*2))return!1}}return!0})}var cm=/[\u0590-\u08ac]/;function am(n,e,t){let{$head:r}=e.selection;if(!r.parent.isTextblock)return!1;let i=r.parentOffset,s=!i,o=i==r.parent.content.size,l=n.domSelection();return!cm.test(r.parent.textContent)||!l.modify?t=="left"||t=="backward"?s:o:yh(n,e,()=>{let{focusNode:c,focusOffset:a,anchorNode:h,anchorOffset:d}=n.domSelectionRange(),f=l.caretBidiLevel;l.modify("move",t,"character");let u=r.depth?n.docView.domAfterPos(r.before()):n.dom,{focusNode:p,focusOffset:m}=n.domSelectionRange(),g=p&&!u.contains(p.nodeType==1?p:p.parentNode)||c==p&&a==m;try{l.collapse(h,d),c&&(c!=h||a!=d)&&l.extend&&l.extend(c,a)}catch{}return f!=null&&(l.caretBidiLevel=f),g})}var Va=null,Pa=null,La=!1;function hm(n,e,t){return Va==e&&Pa==t?La:(Va=e,Pa=t,La=t=="up"||t=="down"?lm(n,e,t):am(n,e,t))}var ve=0,za=1,an=2,Je=3,mn=class{constructor(e,t,r,i){this.parent=e,this.children=t,this.dom=r,this.contentDOM=i,this.dirty=ve,r.pmViewDesc=this}matchesWidget(e){return!1}matchesMark(e){return!1}matchesNode(e,t,r){return!1}matchesHack(e){return!1}parseRule(){return null}stopEvent(e){return!1}get size(){let e=0;for(let t=0;tue(this.contentDOM);else if(this.contentDOM&&this.contentDOM!=this.dom&&this.dom.contains(this.contentDOM))i=e.compareDocumentPosition(this.contentDOM)&2;else if(this.dom.firstChild){if(t==0)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!1;break}if(s.previousSibling)break}if(i==null&&t==e.childNodes.length)for(let s=e;;s=s.parentNode){if(s==this.dom){i=!0;break}if(s.nextSibling)break}}return i??r>0?this.posAtEnd:this.posAtStart}nearestDesc(e,t=!1){for(let r=!0,i=e;i;i=i.parentNode){let s=this.getDesc(i),o;if(s&&(!t||s.node))if(r&&(o=s.nodeDOM)&&!(o.nodeType==1?o.contains(e.nodeType==1?e:e.parentNode):o==e))r=!1;else return s}}getDesc(e){let t=e.pmViewDesc;for(let r=t;r;r=r.parent)if(r==this)return t}posFromDOM(e,t,r){for(let i=e;i;i=i.parentNode){let s=this.getDesc(i);if(s)return s.localPosFromDOM(e,t,r)}return-1}descAt(e){for(let t=0,r=0;te||o instanceof Gi){i=e-s;break}s=l}if(i)return this.children[r].domFromPos(i-this.children[r].border,t);for(let s;r&&!(s=this.children[r-1]).size&&s instanceof ji&&s.side>=0;r--);if(t<=0){let s,o=!0;for(;s=r?this.children[r-1]:null,!(!s||s.dom.parentNode==this.contentDOM);r--,o=!1);return s&&t&&o&&!s.border&&!s.domAtom?s.domFromPos(s.size,t):{node:this.contentDOM,offset:s?ue(s.dom)+1:0}}else{let s,o=!0;for(;s=r=h&&t<=a-c.border&&c.node&&c.contentDOM&&this.contentDOM.contains(c.contentDOM))return c.parseRange(e,t,h);e=o;for(let d=l;d>0;d--){let f=this.children[d-1];if(f.size&&f.dom.parentNode==this.contentDOM&&!f.emptyChildAt(1)){i=ue(f.dom)+1;break}e-=f.size}i==-1&&(i=0)}if(i>-1&&(a>t||l==this.children.length-1)){t=a;for(let h=l+1;hu&&ot){let u=l;l=c,c=u}let f=document.createRange();f.setEnd(c.node,c.offset),f.setStart(l.node,l.offset),a.removeAllRanges(),a.addRange(f)}}ignoreMutation(e){return!this.contentDOM&&e.type!="selection"}get contentLost(){return this.contentDOM&&this.contentDOM!=this.dom&&!this.dom.contains(this.contentDOM)}markDirty(e,t){for(let r=0,i=0;i=r:er){let l=r+s.border,c=o-s.border;if(e>=l&&t<=c){this.dirty=e==r||t==o?an:za,e==l&&t==c&&(s.contentLost||s.dom.parentNode!=this.contentDOM)?s.dirty=Je:s.markDirty(e-l,t-l);return}else s.dirty=s.dom==s.contentDOM&&s.dom.parentNode==this.contentDOM&&!s.children.length?an:Je}r=o}this.dirty=an}markParentsDirty(){let e=1;for(let t=this.parent;t;t=t.parent,e++){let r=e==1?an:za;t.dirty{if(!s)return i;if(s.parent)return s.parent.posBeforeChild(s)})),!t.type.spec.raw){if(o.nodeType!=1){let l=document.createElement("span");l.appendChild(o),o=l}o.contentEditable="false",o.classList.add("ProseMirror-widget")}super(e,[],o,null),this.widget=t,this.widget=t,s=this}matchesWidget(e){return this.dirty==ve&&e.type.eq(this.widget.type)}parseRule(){return{ignore:!0}}stopEvent(e){let t=this.widget.spec.stopEvent;return t?t(e):!1}ignoreMutation(e){return e.type!="selection"||this.widget.spec.ignoreSelection}destroy(){this.widget.type.destroy(this.dom),super.destroy()}get domAtom(){return!0}get side(){return this.widget.type.side}},Lo=class extends mn{constructor(e,t,r,i){super(e,[],t,null),this.textDOM=r,this.text=i}get size(){return this.text.length}localPosFromDOM(e,t){return e!=this.textDOM?this.posAtStart+(t?this.size:0):this.posAtStart+t}domFromPos(e){return{node:this.textDOM,offset:e}}ignoreMutation(e){return e.type==="characterData"&&e.target.nodeValue==e.oldValue}},Yn=class n extends mn{constructor(e,t,r,i){super(e,[],r,i),this.mark=t}static create(e,t,r,i){let s=i.nodeViews[t.type.name],o=s&&s(t,i,r);return(!o||!o.dom)&&(o=Tt.renderSpec(document,t.type.spec.toDOM(t,r))),new n(e,t,o.dom,o.contentDOM||o.dom)}parseRule(){return this.dirty&Je||this.mark.type.spec.reparseInView?null:{mark:this.mark.type.name,attrs:this.mark.attrs,contentElement:this.contentDOM}}matchesMark(e){return this.dirty!=Je&&this.mark.eq(e)}markDirty(e,t){if(super.markDirty(e,t),this.dirty!=ve){let r=this.parent;for(;!r.node;)r=r.parent;r.dirty0&&(s=Jo(s,0,e,r));for(let l=0;l{if(!c)return o;if(c.parent)return c.parent.posBeforeChild(c)},r,i),h=a&&a.dom,d=a&&a.contentDOM;if(t.isText){if(!h)h=document.createTextNode(t.text);else if(h.nodeType!=3)throw new RangeError("Text must be rendered as a DOM text node")}else h||({dom:h,contentDOM:d}=Tt.renderSpec(document,t.type.spec.toDOM(t)));!d&&!t.isText&&h.nodeName!="BR"&&(h.hasAttribute("contenteditable")||(h.contentEditable="false"),t.type.spec.draggable&&(h.draggable=!0));let f=h;return h=xh(h,r,t),a?c=new zo(e,t,r,i,h,d||null,f,a,s,o+1):t.isText?new Yi(e,t,r,i,h,f,s):new n(e,t,r,i,h,d||null,f,s,o+1)}parseRule(){if(this.node.type.spec.reparseInView)return null;let e={node:this.node.type.name,attrs:this.node.attrs};if(this.node.type.whitespace=="pre"&&(e.preserveWhitespace="full"),!this.contentDOM)e.getContent=()=>this.node.content;else if(!this.contentLost)e.contentElement=this.contentDOM;else{for(let t=this.children.length-1;t>=0;t--){let r=this.children[t];if(this.dom.contains(r.dom.parentNode)){e.contentElement=r.dom.parentNode;break}}e.contentElement||(e.getContent=()=>y.empty)}return e}matchesNode(e,t,r){return this.dirty==ve&&e.eq(this.node)&&qo(t,this.outerDeco)&&r.eq(this.innerDeco)}get size(){return this.node.nodeSize}get border(){return this.node.isLeaf?0:1}updateChildren(e,t){let r=this.node.inlineContent,i=t,s=e.composing?this.localCompositionInfo(e,t):null,o=s&&s.pos>-1?s:null,l=s&&s.pos<0,c=new Ho(this,o&&o.node,e);pm(this.node,this.innerDeco,(a,h,d)=>{a.spec.marks?c.syncToMarks(a.spec.marks,r,e):a.type.side>=0&&!d&&c.syncToMarks(h==this.node.childCount?D.none:this.node.child(h).marks,r,e),c.placeWidget(a,e,i)},(a,h,d,f)=>{c.syncToMarks(a.marks,r,e);let u;c.findNodeMatch(a,h,d,f)||l&&e.state.selection.from>i&&e.state.selection.to-1&&c.updateNodeAt(a,h,d,u,e)||c.updateNextNode(a,h,d,e,f,i)||c.addNode(a,h,d,e,i),i+=a.nodeSize}),c.syncToMarks([],r,e),this.node.isTextblock&&c.addTextblockHacks(),c.destroyRest(),(c.changed||this.dirty==an)&&(o&&this.protectLocalComposition(e,o),wh(this.contentDOM,this.children,e),jn&&mm(this.dom))}localCompositionInfo(e,t){let{from:r,to:i}=e.state.selection;if(!(e.state.selection instanceof A)||rt+this.node.content.size)return null;let s=e.domSelectionRange(),o=gm(s.focusNode,s.focusOffset);if(!o||!this.dom.contains(o.parentNode))return null;if(this.node.inlineContent){let l=o.nodeValue,c=ym(this.node.content,l,r-t,i-t);return c<0?null:{node:o,pos:c,text:l}}else return{node:o,pos:-1,text:""}}protectLocalComposition(e,{node:t,pos:r,text:i}){if(this.getDesc(t))return;let s=t;for(;s.parentNode!=this.contentDOM;s=s.parentNode){for(;s.previousSibling;)s.parentNode.removeChild(s.previousSibling);for(;s.nextSibling;)s.parentNode.removeChild(s.nextSibling);s.pmViewDesc&&(s.pmViewDesc=void 0)}let o=new Lo(this,s,t,i);e.input.compositionNodes.push(o),this.children=Jo(this.children,r,r+i.length,e,o)}update(e,t,r,i){return this.dirty==Je||!e.sameMarkup(this.node)?!1:(this.updateInner(e,t,r,i),!0)}updateInner(e,t,r,i){this.updateOuterDeco(t),this.node=e,this.innerDeco=r,this.contentDOM&&this.updateChildren(i,this.posAtStart),this.dirty=ve}updateOuterDeco(e){if(qo(e,this.outerDeco))return;let t=this.nodeDOM.nodeType!=1,r=this.dom;this.dom=bh(this.dom,this.nodeDOM,Fo(this.outerDeco,this.node,t),Fo(e,this.node,t)),this.dom!=r&&(r.pmViewDesc=void 0,this.dom.pmViewDesc=this),this.outerDeco=e}selectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.add("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&(this.dom.draggable=!0)}deselectNode(){this.nodeDOM.nodeType==1&&this.nodeDOM.classList.remove("ProseMirror-selectednode"),(this.contentDOM||!this.node.type.spec.draggable)&&this.dom.removeAttribute("draggable")}get domAtom(){return this.node.isAtom}};function Fa(n,e,t,r,i){xh(r,e,n);let s=new _t(void 0,n,e,t,r,r,r,i,0);return s.contentDOM&&s.updateChildren(i,0),s}var Yi=class n extends _t{constructor(e,t,r,i,s,o,l){super(e,t,r,i,s,null,o,l,0)}parseRule(){let e=this.nodeDOM.parentNode;for(;e&&e!=this.dom&&!e.pmIsDeco;)e=e.parentNode;return{skip:e||!0}}update(e,t,r,i){return this.dirty==Je||this.dirty!=ve&&!this.inParent()||!e.sameMarkup(this.node)?!1:(this.updateOuterDeco(t),(this.dirty!=ve||e.text!=this.node.text)&&e.text!=this.nodeDOM.nodeValue&&(this.nodeDOM.nodeValue=e.text,i.trackWrites==this.nodeDOM&&(i.trackWrites=null)),this.node=e,this.dirty=ve,!0)}inParent(){let e=this.parent.contentDOM;for(let t=this.nodeDOM;t;t=t.parentNode)if(t==e)return!0;return!1}domFromPos(e){return{node:this.nodeDOM,offset:e}}localPosFromDOM(e,t,r){return e==this.nodeDOM?this.posAtStart+Math.min(t,this.node.text.length):super.localPosFromDOM(e,t,r)}ignoreMutation(e){return e.type!="characterData"&&e.type!="selection"}slice(e,t,r){let i=this.node.cut(e,t),s=document.createTextNode(i.text);return new n(this.parent,i,this.outerDeco,this.innerDeco,s,s,r)}markDirty(e,t){super.markDirty(e,t),this.dom!=this.nodeDOM&&(e==0||t==this.nodeDOM.nodeValue.length)&&(this.dirty=Je)}get domAtom(){return!1}},Gi=class extends mn{parseRule(){return{ignore:!0}}matchesHack(e){return this.dirty==ve&&this.dom.nodeName==e}get domAtom(){return!0}get ignoreForCoords(){return this.dom.nodeName=="IMG"}},zo=class extends _t{constructor(e,t,r,i,s,o,l,c,a,h){super(e,t,r,i,s,o,l,a,h),this.spec=c}update(e,t,r,i){if(this.dirty==Je)return!1;if(this.spec.update){let s=this.spec.update(e,t,r);return s&&this.updateInner(e,t,r,i),s}else return!this.contentDOM&&!e.isLeaf?!1:super.update(e,t,r,i)}selectNode(){this.spec.selectNode?this.spec.selectNode():super.selectNode()}deselectNode(){this.spec.deselectNode?this.spec.deselectNode():super.deselectNode()}setSelection(e,t,r,i){this.spec.setSelection?this.spec.setSelection(e,t,r):super.setSelection(e,t,r,i)}destroy(){this.spec.destroy&&this.spec.destroy(),super.destroy()}stopEvent(e){return this.spec.stopEvent?this.spec.stopEvent(e):!1}ignoreMutation(e){return this.spec.ignoreMutation?this.spec.ignoreMutation(e):super.ignoreMutation(e)}};function wh(n,e,t){let r=n.firstChild,i=!1;for(let s=0;s>1,o=Math.min(s,e.length);for(;i-1)l>this.index&&(this.changed=!0,this.destroyBetween(this.index,l)),this.top=this.top.children[this.index];else{let c=Yn.create(this.top,e[s],t,r);this.top.children.splice(this.index,0,c),this.top=c,this.changed=!0}this.index=0,s++}}findNodeMatch(e,t,r,i){let s=-1,o;if(i>=this.preMatch.index&&(o=this.preMatch.matches[i-this.preMatch.index]).parent==this.top&&o.matchesNode(e,t,r))s=this.top.children.indexOf(o,this.index);else for(let l=this.index,c=Math.min(this.top.children.length,l+5);l0;){let l;for(;;)if(r){let a=t.children[r-1];if(a instanceof Yn)t=a,r=a.children.length;else{l=a,r--;break}}else{if(t==e)break e;r=t.parent.children.indexOf(t),t=t.parent}let c=l.node;if(c){if(c!=n.child(i-1))break;--i,s.set(l,i),o.push(l)}}return{index:i,matched:s,matches:o.reverse()}}function um(n,e){return n.type.side-e.type.side}function pm(n,e,t,r){let i=e.locals(n),s=0;if(i.length==0){for(let a=0;as;)l.push(i[o++]);let p=s+f.nodeSize;if(f.isText){let g=p;o!g.inline):l.slice();r(f,m,e.forChild(s,f),u),s=p}}function mm(n){if(n.nodeName=="UL"||n.nodeName=="OL"){let e=n.style.cssText;n.style.cssText=e+"; list-style: square !important",window.getComputedStyle(n).listStyle,n.style.cssText=e}}function gm(n,e){for(;;){if(n.nodeType==3)return n;if(n.nodeType==1&&e>0){if(n.childNodes.length>e&&n.childNodes[e].nodeType==3)return n.childNodes[e];n=n.childNodes[e-1],e=qe(n)}else if(n.nodeType==1&&e=t){if(s>=r&&c.slice(r-e.length-l,r-l)==e)return r-e.length;let a=l=0&&a+e.length+l>=t)return l+a;if(t==r&&c.length>=r+e.length-l&&c.slice(r-l,r-l+e.length)==e)return r}}return-1}function Jo(n,e,t,r,i){let s=[];for(let o=0,l=0;o=t||h<=e?s.push(c):(at&&s.push(c.slice(t-a,c.size,r)))}return s}function rl(n,e=null){let t=n.domSelectionRange(),r=n.state.doc;if(!t.focusNode)return null;let i=n.docView.nearestDesc(t.focusNode),s=i&&i.size==0,o=n.docView.posFromDOM(t.focusNode,t.focusOffset,1);if(o<0)return null;let l=r.resolve(o),c,a;if(rs(t)){for(c=l;i&&!i.node;)i=i.parent;let h=i.node;if(i&&h.isAtom&&C.isSelectable(h)&&i.parent&&!(h.isInline&&Jp(t.focusNode,t.focusOffset,i.dom))){let d=i.posBefore;a=new C(o==d?l:r.resolve(d))}}else{let h=n.docView.posFromDOM(t.anchorNode,t.anchorOffset,1);if(h<0)return null;c=r.resolve(h)}if(!a){let h=e=="pointer"||n.state.selection.head{(t.anchorNode!=r||t.anchorOffset!=i)&&(e.removeEventListener("selectionchange",n.input.hideSelectionGuard),setTimeout(()=>{(!Sh(n)||n.state.selection.visible)&&n.dom.classList.remove("ProseMirror-hideselection")},20))})}function bm(n){let e=n.domSelection(),t=document.createRange(),r=n.cursorWrapper.dom,i=r.nodeName=="IMG";i?t.setEnd(r.parentNode,ue(r)+1):t.setEnd(r,0),t.collapse(!1),e.removeAllRanges(),e.addRange(t),!i&&!n.state.selection.visible&&xe&&vt<=11&&(r.disabled=!0,r.disabled=!1)}function kh(n,e){if(e instanceof C){let t=n.docView.descAt(e.from);t!=n.lastSelectedViewDesc&&($a(n),t&&t.selectNode(),n.lastSelectedViewDesc=t)}else $a(n)}function $a(n){n.lastSelectedViewDesc&&(n.lastSelectedViewDesc.parent&&n.lastSelectedViewDesc.deselectNode(),n.lastSelectedViewDesc=void 0)}function il(n,e,t,r){return n.someProp("createSelectionBetween",i=>i(n,e,t))||A.between(e,t,r)}function Ka(n){return n.editable&&!n.hasFocus()?!1:Ch(n)}function Ch(n){let e=n.domSelectionRange();if(!e.anchorNode)return!1;try{return n.dom.contains(e.anchorNode.nodeType==3?e.anchorNode.parentNode:e.anchorNode)&&(n.editable||n.dom.contains(e.focusNode.nodeType==3?e.focusNode.parentNode:e.focusNode))}catch{return!1}}function xm(n){let e=n.docView.domFromPos(n.state.selection.anchor,0),t=n.domSelectionRange();return pn(e.node,e.offset,t.anchorNode,t.anchorOffset)}function Wo(n,e){let{$anchor:t,$head:r}=n.selection,i=e>0?t.max(r):t.min(r),s=i.parent.inlineContent?i.depth?n.doc.resolve(e>0?i.after():i.before()):null:i;return s&&S.findFrom(s,e)}function It(n,e){return n.dispatch(n.state.tr.setSelection(e).scrollIntoView()),!0}function ja(n,e,t){let r=n.state.selection;if(r instanceof A)if(t.indexOf("s")>-1){let{$head:i}=r,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter;if(!s||s.isText||!s.isLeaf)return!1;let o=n.state.doc.resolve(i.pos+s.nodeSize*(e<0?-1:1));return It(n,new A(r.$anchor,o))}else if(r.empty){if(n.endOfTextblock(e>0?"forward":"backward")){let i=Wo(n.state,e);return i&&i instanceof C?It(n,i):!1}else if(!(Re&&t.indexOf("m")>-1)){let i=r.$head,s=i.textOffset?null:e<0?i.nodeBefore:i.nodeAfter,o;if(!s||s.isText)return!1;let l=e<0?i.pos-s.nodeSize:i.pos;return s.isAtom||(o=n.docView.descAt(l))&&!o.contentDOM?C.isSelectable(s)?It(n,new C(e<0?n.state.doc.resolve(i.pos-s.nodeSize):i)):Hr?It(n,new A(n.state.doc.resolve(e<0?l:l+s.nodeSize))):!1:!1}}else return!1;else{if(r instanceof C&&r.node.isInline)return It(n,new A(e>0?r.$to:r.$from));{let i=Wo(n.state,e);return i?It(n,i):!1}}}function Xi(n){return n.nodeType==3?n.nodeValue.length:n.childNodes.length}function Pr(n,e){let t=n.pmViewDesc;return t&&t.size==0&&(e<0||n.nextSibling||n.nodeName!="BR")}function Wn(n,e){return e<0?Sm(n):km(n)}function Sm(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i,s,o=!1;for(ze&&t.nodeType==1&&r0){if(t.nodeType!=1)break;{let l=t.childNodes[r-1];if(Pr(l,-1))i=t,s=--r;else if(l.nodeType==3)t=l,r=t.nodeValue.length;else break}}else{if(Mh(t))break;{let l=t.previousSibling;for(;l&&Pr(l,-1);)i=t.parentNode,s=ue(l),l=l.previousSibling;if(l)t=l,r=Xi(t);else{if(t=t.parentNode,t==n.dom)break;r=0}}}o?$o(n,t,r):i&&$o(n,i,s)}function km(n){let e=n.domSelectionRange(),t=e.focusNode,r=e.focusOffset;if(!t)return;let i=Xi(t),s,o;for(;;)if(r{n.state==i&&ft(n)},50)}function Ya(n,e){let t=n.state.doc.resolve(e);if(!(oe||jp)&&t.parent.inlineContent){let i=n.coordsAtPos(e);if(e>t.start()){let s=n.coordsAtPos(e-1),o=(s.top+s.bottom)/2;if(o>i.top&&o1)return s.lefti.top&&o1)return s.left>i.left?"ltr":"rtl"}}return getComputedStyle(n.dom).direction=="rtl"?"rtl":"ltr"}function Ga(n,e,t){let r=n.state.selection;if(r instanceof A&&!r.empty||t.indexOf("s")>-1||Re&&t.indexOf("m")>-1)return!1;let{$from:i,$to:s}=r;if(!i.parent.inlineContent||n.endOfTextblock(e<0?"up":"down")){let o=Wo(n.state,e);if(o&&o instanceof C)return It(n,o)}if(!i.parent.inlineContent){let o=e<0?i:s,l=r instanceof Me?S.near(o,e):S.findFrom(o,e);return l?It(n,l):!1}return!1}function Xa(n,e){if(!(n.state.selection instanceof A))return!0;let{$head:t,$anchor:r,empty:i}=n.state.selection;if(!t.sameParent(r))return!0;if(!i)return!1;if(n.endOfTextblock(e>0?"forward":"backward"))return!0;let s=!t.textOffset&&(e<0?t.nodeBefore:t.nodeAfter);if(s&&!s.isText){let o=n.state.tr;return e<0?o.delete(t.pos-s.nodeSize,t.pos):o.delete(t.pos,t.pos+s.nodeSize),n.dispatch(o),!0}return!1}function Qa(n,e,t){n.domObserver.stop(),e.contentEditable=t,n.domObserver.start()}function Am(n){if(!pe||n.state.selection.$head.parentOffset>0)return!1;let{focusNode:e,focusOffset:t}=n.domSelectionRange();if(e&&e.nodeType==1&&t==0&&e.firstChild&&e.firstChild.contentEditable=="false"){let r=e.firstChild;Qa(n,r,"true"),setTimeout(()=>Qa(n,r,"false"),20)}return!1}function Em(n){let e="";return n.ctrlKey&&(e+="c"),n.metaKey&&(e+="m"),n.altKey&&(e+="a"),n.shiftKey&&(e+="s"),e}function Dm(n,e){let t=e.keyCode,r=Em(e);if(t==8||Re&&t==72&&r=="c")return Xa(n,-1)||Wn(n,-1);if(t==46&&!e.shiftKey||Re&&t==68&&r=="c")return Xa(n,1)||Wn(n,1);if(t==13||t==27)return!0;if(t==37||Re&&t==66&&r=="c"){let i=t==37?Ya(n,n.state.selection.from)=="ltr"?-1:1:-1;return ja(n,i,r)||Wn(n,i)}else if(t==39||Re&&t==70&&r=="c"){let i=t==39?Ya(n,n.state.selection.from)=="ltr"?1:-1:1;return ja(n,i,r)||Wn(n,i)}else{if(t==38||Re&&t==80&&r=="c")return Ga(n,-1,r)||Wn(n,-1);if(t==40||Re&&t==78&&r=="c")return Am(n)||Ga(n,1,r)||Wn(n,1);if(r==(Re?"m":"c")&&(t==66||t==73||t==89||t==90))return!0}return!1}function Ah(n,e){n.someProp("transformCopied",u=>{e=u(e,n)});let t=[],{content:r,openStart:i,openEnd:s}=e;for(;i>1&&s>1&&r.childCount==1&&r.firstChild.childCount==1;){i--,s--;let u=r.firstChild;t.push(u.type.name,u.attrs!=u.type.defaultAttrs?u.attrs:null),r=u.content}let o=n.someProp("clipboardSerializer")||Tt.fromSchema(n.state.schema),l=Ih(),c=l.createElement("div");c.appendChild(o.serializeFragment(r,{document:l}));let a=c.firstChild,h,d=0;for(;a&&a.nodeType==1&&(h=Nh[a.nodeName.toLowerCase()]);){for(let u=h.length-1;u>=0;u--){let p=l.createElement(h[u]);for(;c.firstChild;)p.appendChild(c.firstChild);c.appendChild(p),d++}a=c.firstChild}a&&a.nodeType==1&&a.setAttribute("data-pm-slice",`${i} ${s}${d?` -${d}`:""} ${JSON.stringify(t)}`);let f=n.someProp("clipboardTextSerializer",u=>u(e,n))||e.content.textBetween(0,e.content.size,`
-`);return{dom:c,text:f,slice:e}}function Oh(n,e,t,r,i){let s=i.parent.type.spec.code,o,l;if(!t&&!e)return null;let c=e&&(r||s||!t);if(c){if(n.someProp("transformPastedText",f=>{e=f(e,s||r,n)}),s)return e?new b(y.from(n.state.schema.text(e.replace(/\r\n?/g,`
-`))),0,0):b.empty;let d=n.someProp("clipboardTextParser",f=>f(e,i,r,n));if(d)l=d;else{let f=i.marks(),{schema:u}=n.state,p=Ot.fromSchema(u);o=document.createElement("div"),e.split(/(?:\r\n?|\n)+/).forEach(m=>{let g=o.appendChild(document.createElement("p"));m&&g.appendChild(p.serializeNode(u.text(m,f)))})}}else n.someProp("transformPastedHTML",d=>{t=d(t,n)}),o=Pm(t),$r&&Lm(o);let a=o&&o.querySelector("[data-pm-slice]"),h=a&&/^(\d+) (\d+)(?: -(\d+))? (.*)/.exec(a.getAttribute("data-pm-slice")||"");if(h&&h[3])for(let d=+h[3];d>0;d--){let f=o.firstChild;for(;f&&f.nodeType!=1;)f=f.nextSibling;if(!f)break;o=f}if(l||(l=(n.someProp("clipboardParser")||n.someProp("domParser")||zn.fromSchema(n.state.schema)).parseSlice(o,{preserveWhitespace:!!(c||h),context:i,ruleFromNode(f){return f.nodeName=="BR"&&!f.nextSibling&&f.parentNode&&!Vm.test(f.parentNode.nodeName)?{ignore:!0}:null}})),h)l=zm(th(l,+h[1],+h[2]),h[4]);else if(l=b.maxOpen(Bm(l.content,i),!0),l.openStart||l.openEnd){let d=0,f=0;for(let u=l.content.firstChild;d{l=d(l,n)}),l}var Vm=/^(a|abbr|acronym|b|cite|code|del|em|i|ins|kbd|label|output|q|ruby|s|samp|span|strong|sub|sup|time|u|tt|var)$/i;function Bm(n,e){if(n.childCount<2)return n;for(let t=e.depth;t>=0;t--){let i=e.node(t).contentMatchAt(e.index(t)),s,o=[];if(n.forEach(l=>{if(!o)return;let c=i.findWrapping(l.type),a;if(!c)return o=null;if(a=o.length&&s.length&&Ih(c,s,l,o[o.length-1],0))o[o.length-1]=a;else{o.length&&(o[o.length-1]=Rh(o[o.length-1],s.length));let h=Nh(l,c);o.push(h),i=i.matchType(h.type),s=c}}),o)return y.from(o)}return n}function Nh(n,e,t=0){for(let r=e.length-1;r>=t;r--)n=e[r].create(null,y.from(n));return n}function Ih(n,e,t,r,i){if(i1&&(s=0),i=t&&(l=e<0?o.contentMatchAt(0).fillBefore(l,s<=i).append(l):l.append(o.contentMatchAt(o.childCount).fillBefore(y.empty,!0))),n.replaceChild(e<0?0:n.childCount-1,o.copy(l))}function th(n,e,t){return e]*>)*/.exec(n);e&&(n=n.slice(e[0].length));let t=_h().createElement("div"),r=/<([a-z][^>\s]+)/i.exec(n),i;if((i=r&&vh[r[1].toLowerCase()])&&(n=i.map(s=>"<"+s+">").join("")+n+i.map(s=>""+s+">").reverse().join("")),t.innerHTML=n,i)for(let s=0;s=0;l-=2){let c=t.nodes[r[l]];if(!c||c.hasRequiredAttrs())break;i=y.from(c.create(r[l+1],i)),s++,o++}return new b(i,s,o)}var me={},ge={},Fm={touchstart:!0,touchmove:!0},Qo=class{constructor(){this.shiftKey=!1,this.mouseDown=null,this.lastKeyCode=null,this.lastKeyCodeTime=0,this.lastClick={time:0,x:0,y:0,type:""},this.lastSelectionOrigin=null,this.lastSelectionTime=0,this.lastIOSEnter=0,this.lastIOSEnterFallbackTimeout=-1,this.lastFocus=0,this.lastTouch=0,this.lastAndroidDelete=0,this.composing=!1,this.compositionNode=null,this.composingTimeout=-1,this.compositionNodes=[],this.compositionEndedAt=-2e8,this.compositionID=1,this.compositionPendingChanges=0,this.domChangeCount=0,this.eventHandlers=Object.create(null),this.hideSelectionGuard=null}};function qm(n){for(let e in me){let t=me[e];n.dom.addEventListener(e,n.input.eventHandlers[e]=r=>{Jm(n,r)&&!cl(n,r)&&(n.editable||!(r.type in ge))&&t(n,r)},Fm[e]?{passive:!0}:void 0)}pe&&n.dom.addEventListener("input",()=>null),Zo(n)}function vt(n,e){n.input.lastSelectionOrigin=e,n.input.lastSelectionTime=Date.now()}function Hm(n){n.domObserver.stop();for(let e in n.input.eventHandlers)n.dom.removeEventListener(e,n.input.eventHandlers[e]);clearTimeout(n.input.composingTimeout),clearTimeout(n.input.lastIOSEnterFallbackTimeout)}function Zo(n){n.someProp("handleDOMEvents",e=>{for(let t in e)n.input.eventHandlers[t]||n.dom.addEventListener(t,n.input.eventHandlers[t]=r=>cl(n,r))})}function cl(n,e){return n.someProp("handleDOMEvents",t=>{let r=t[e.type];return r?r(n,e)||e.defaultPrevented:!1})}function Jm(n,e){if(!e.bubbles)return!0;if(e.defaultPrevented)return!1;for(let t=e.target;t!=n.dom;t=t.parentNode)if(!t||t.nodeType==11||t.pmViewDesc&&t.pmViewDesc.stopEvent(e))return!1;return!0}function Wm(n,e){!cl(n,e)&&me[e.type]&&(n.editable||!(e.type in ge))&&me[e.type](n,e)}ge.keydown=(n,e)=>{let t=e;if(n.input.shiftKey=t.keyCode==16||t.shiftKey,!Vh(n,t)&&(n.input.lastKeyCode=t.keyCode,n.input.lastKeyCodeTime=Date.now(),!(Le&&ue&&t.keyCode==13)))if(t.keyCode!=229&&n.domObserver.forceFlush(),jn&&t.keyCode==13&&!t.ctrlKey&&!t.altKey&&!t.metaKey){let r=Date.now();n.input.lastIOSEnter=r,n.input.lastIOSEnterFallbackTimeout=setTimeout(()=>{n.input.lastIOSEnter==r&&(n.someProp("handleKeyDown",i=>i(n,on(13,"Enter"))),n.input.lastIOSEnter=0)},200)}else n.someProp("handleKeyDown",r=>r(n,t))||Um(n,t)?t.preventDefault():vt(n,"key")};ge.keyup=(n,e)=>{e.keyCode==16&&(n.input.shiftKey=!1)};ge.keypress=(n,e)=>{let t=e;if(Vh(n,t)||!t.charCode||t.ctrlKey&&!t.altKey||Re&&t.metaKey)return;if(n.someProp("handleKeyPress",i=>i(n,t))){t.preventDefault();return}let r=n.state.selection;if(!(r instanceof A)||!r.$from.sameParent(r.$to)){let i=String.fromCharCode(t.charCode);!/[\r\n]/.test(i)&&!n.someProp("handleTextInput",s=>s(n,r.$from.pos,r.$to.pos,i))&&n.dispatch(n.state.tr.insertText(i).scrollIntoView()),t.preventDefault()}};function cs(n){return{left:n.clientX,top:n.clientY}}function $m(n,e){let t=e.x-n.clientX,r=e.y-n.clientY;return t*t+r*r<100}function al(n,e,t,r,i){if(r==-1)return!1;let s=n.state.doc.resolve(r);for(let o=s.depth+1;o>0;o--)if(n.someProp(e,l=>o>s.depth?l(n,t,s.nodeAfter,s.before(o),i,!0):l(n,t,s.node(o),s.before(o),i,!1)))return!0;return!1}function Kn(n,e,t){n.focused||n.focus();let r=n.state.tr.setSelection(e);t=="pointer"&&r.setMeta("pointer",!0),n.dispatch(r)}function Km(n,e){if(e==-1)return!1;let t=n.state.doc.resolve(e),r=t.nodeAfter;return r&&r.isAtom&&C.isSelectable(r)?(Kn(n,new C(t),"pointer"),!0):!1}function jm(n,e){if(e==-1)return!1;let t=n.state.selection,r,i;t instanceof C&&(r=t.node);let s=n.state.doc.resolve(e);for(let o=s.depth+1;o>0;o--){let l=o>s.depth?s.nodeAfter:s.node(o);if(C.isSelectable(l)){r&&t.$from.depth>0&&o>=t.$from.depth&&s.before(t.$from.depth+1)==t.$from.pos?i=s.before(t.$from.depth):i=s.before(o);break}}return i!=null?(Kn(n,C.create(n.state.doc,i),"pointer"),!0):!1}function Ym(n,e,t,r,i){return al(n,"handleClickOn",e,t,r)||n.someProp("handleClick",s=>s(n,e,r))||(i?jm(n,t):Km(n,t))}function Gm(n,e,t,r){return al(n,"handleDoubleClickOn",e,t,r)||n.someProp("handleDoubleClick",i=>i(n,e,r))}function Xm(n,e,t,r){return al(n,"handleTripleClickOn",e,t,r)||n.someProp("handleTripleClick",i=>i(n,e,r))||Qm(n,t,r)}function Qm(n,e,t){if(t.button!=0)return!1;let r=n.state.doc;if(e==-1)return r.inlineContent?(Kn(n,A.create(r,0,r.content.size),"pointer"),!0):!1;let i=r.resolve(e);for(let s=i.depth+1;s>0;s--){let o=s>i.depth?i.nodeAfter:i.node(s),l=i.before(s);if(o.inlineContent)Kn(n,A.create(r,l+1,l+1+o.content.size),"pointer");else if(C.isSelectable(o))Kn(n,C.create(r,l),"pointer");else continue;return!0}}function hl(n){return ts(n)}var Uh=Re?"metaKey":"ctrlKey";me.mousedown=(n,e)=>{let t=e;n.input.shiftKey=t.shiftKey;let r=hl(n),i=Date.now(),s="singleClick";i-n.input.lastClick.time<500&&$m(t,n.input.lastClick)&&!t[Uh]&&(n.input.lastClick.type=="singleClick"?s="doubleClick":n.input.lastClick.type=="doubleClick"&&(s="tripleClick")),n.input.lastClick={time:i,x:t.clientX,y:t.clientY,type:s};let o=n.posAtCoords(cs(t));o&&(s=="singleClick"?(n.input.mouseDown&&n.input.mouseDown.done(),n.input.mouseDown=new el(n,o,t,!!r)):(s=="doubleClick"?Gm:Xm)(n,o.pos,o.inside,t)?t.preventDefault():vt(n,"pointer"))};var el=class{constructor(e,t,r,i){this.view=e,this.pos=t,this.event=r,this.flushed=i,this.delayedSelectionSync=!1,this.mightDrag=null,this.startDoc=e.state.doc,this.selectNode=!!r[Uh],this.allowDefault=r.shiftKey;let s,o;if(t.inside>-1)s=e.state.doc.nodeAt(t.inside),o=t.inside;else{let h=e.state.doc.resolve(t.pos);s=h.parent,o=h.depth?h.before():0}let l=i?null:r.target,c=l?e.docView.nearestDesc(l,!0):null;this.target=c?c.dom:null;let{selection:a}=e.state;(r.button==0&&s.type.spec.draggable&&s.type.spec.selectable!==!1||a instanceof C&&a.from<=o&&a.to>o)&&(this.mightDrag={node:s,pos:o,addAttr:!!(this.target&&!this.target.draggable),setUneditable:!!(this.target&&ze&&!this.target.hasAttribute("contentEditable"))}),this.target&&this.mightDrag&&(this.mightDrag.addAttr||this.mightDrag.setUneditable)&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&(this.target.draggable=!0),this.mightDrag.setUneditable&&setTimeout(()=>{this.view.input.mouseDown==this&&this.target.setAttribute("contentEditable","false")},20),this.view.domObserver.start()),e.root.addEventListener("mouseup",this.up=this.up.bind(this)),e.root.addEventListener("mousemove",this.move=this.move.bind(this)),vt(e,"pointer")}done(){this.view.root.removeEventListener("mouseup",this.up),this.view.root.removeEventListener("mousemove",this.move),this.mightDrag&&this.target&&(this.view.domObserver.stop(),this.mightDrag.addAttr&&this.target.removeAttribute("draggable"),this.mightDrag.setUneditable&&this.target.removeAttribute("contentEditable"),this.view.domObserver.start()),this.delayedSelectionSync&&setTimeout(()=>dt(this.view)),this.view.input.mouseDown=null}up(e){if(this.done(),!this.view.dom.contains(e.target))return;let t=this.pos;this.view.state.doc!=this.startDoc&&(t=this.view.posAtCoords(cs(e))),this.updateAllowDefault(e),this.allowDefault||!t?vt(this.view,"pointer"):Ym(this.view,t.pos,t.inside,e,this.selectNode)?e.preventDefault():e.button==0&&(this.flushed||pe&&this.mightDrag&&!this.mightDrag.node.isAtom||ue&&!this.view.state.selection.visible&&Math.min(Math.abs(t.pos-this.view.state.selection.from),Math.abs(t.pos-this.view.state.selection.to))<=2)?(Kn(this.view,S.near(this.view.state.doc.resolve(t.pos)),"pointer"),e.preventDefault()):vt(this.view,"pointer")}move(e){this.updateAllowDefault(e),vt(this.view,"pointer"),e.buttons==0&&this.done()}updateAllowDefault(e){!this.allowDefault&&(Math.abs(this.event.x-e.clientX)>4||Math.abs(this.event.y-e.clientY)>4)&&(this.allowDefault=!0)}};me.touchstart=n=>{n.input.lastTouch=Date.now(),hl(n),vt(n,"pointer")};me.touchmove=n=>{n.input.lastTouch=Date.now(),vt(n,"pointer")};me.contextmenu=n=>hl(n);function Vh(n,e){return n.composing?!0:pe&&Math.abs(e.timeStamp-n.input.compositionEndedAt)<500?(n.input.compositionEndedAt=-2e8,!0):!1}var Zm=Le?5e3:-1;ge.compositionstart=ge.compositionupdate=n=>{if(!n.composing){n.domObserver.flush();let{state:e}=n,t=e.selection.$from;if(e.selection.empty&&(e.storedMarks||!t.textOffset&&t.parentOffset&&t.nodeBefore.marks.some(r=>r.type.spec.inclusive===!1)))n.markCursor=n.state.storedMarks||t.marks(),ts(n,!0),n.markCursor=null;else if(ts(n),ze&&e.selection.empty&&t.parentOffset&&!t.textOffset&&t.nodeBefore.marks.length){let r=n.domSelectionRange();for(let i=r.focusNode,s=r.focusOffset;i&&i.nodeType==1&&s!=0;){let o=s<0?i.lastChild:i.childNodes[s-1];if(!o)break;if(o.nodeType==3){n.domSelection().collapse(o,o.nodeValue.length);break}else i=o,s=-1}}n.input.composing=!0}Bh(n,Zm)};ge.compositionend=(n,e)=>{n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=e.timeStamp,n.input.compositionPendingChanges=n.domObserver.pendingRecords().length?n.input.compositionID:0,n.input.compositionNode=null,n.input.compositionPendingChanges&&Promise.resolve().then(()=>n.domObserver.flush()),n.input.compositionID++,Bh(n,20))};function Bh(n,e){clearTimeout(n.input.composingTimeout),e>-1&&(n.input.composingTimeout=setTimeout(()=>ts(n),e))}function Ph(n){for(n.composing&&(n.input.composing=!1,n.input.compositionEndedAt=tg());n.input.compositionNodes.length>0;)n.input.compositionNodes.pop().markParentsDirty()}function eg(n){let e=n.domSelectionRange();if(!e.focusNode)return null;let t=Xp(e.focusNode,e.focusOffset),r=Qp(e.focusNode,e.focusOffset);if(t&&r&&t!=r){let i=r.pmViewDesc;if(!i||!i.isText(r.nodeValue))return r;if(n.input.compositionNode==r){let s=t.pmViewDesc;if(!(!s||!s.isText(t.nodeValue)))return r}}return t||r}function tg(){let n=document.createEvent("Event");return n.initEvent("event",!0,!0),n.timeStamp}function ts(n,e=!1){if(!(Le&&n.domObserver.flushingSoon>=0)){if(n.domObserver.forceFlush(),Ph(n),e||n.docView&&n.docView.dirty){let t=ol(n);return t&&!t.eq(n.state.selection)?n.dispatch(n.state.tr.setSelection(t)):n.updateState(n.state),!0}return!1}}function ng(n,e){if(!n.dom.parentNode)return;let t=n.dom.parentNode.appendChild(document.createElement("div"));t.appendChild(e),t.style.cssText="position: fixed; left: -10000px; top: 10px";let r=getSelection(),i=document.createRange();i.selectNodeContents(e),n.dom.blur(),r.removeAllRanges(),r.addRange(i),setTimeout(()=>{t.parentNode&&t.parentNode.removeChild(t),n.focus()},50)}var qr=xe&&_t<15||jn&&im<604;me.copy=ge.cut=(n,e)=>{let t=e,r=n.state.selection,i=t.type=="cut";if(r.empty)return;let s=qr?null:t.clipboardData,o=r.content(),{dom:l,text:c}=Th(n,o);s?(t.preventDefault(),s.clearData(),s.setData("text/html",l.innerHTML),s.setData("text/plain",c)):ng(n,l),i&&n.dispatch(n.state.tr.deleteSelection().scrollIntoView().setMeta("uiEvent","cut"))};function rg(n){return n.openStart==0&&n.openEnd==0&&n.content.childCount==1?n.content.firstChild:null}function ig(n,e){if(!n.dom.parentNode)return;let t=n.input.shiftKey||n.state.selection.$from.parent.type.spec.code,r=n.dom.parentNode.appendChild(document.createElement(t?"textarea":"div"));t||(r.contentEditable="true"),r.style.cssText="position: fixed; left: -10000px; top: 10px",r.focus();let i=n.input.shiftKey&&n.input.lastKeyCode!=45;setTimeout(()=>{n.focus(),r.parentNode&&r.parentNode.removeChild(r),t?Hr(n,r.value,null,i,e):Hr(n,r.textContent,r.innerHTML,i,e)},50)}function Hr(n,e,t,r,i){let s=Oh(n,e,t,r,n.state.selection.$from);if(n.someProp("handlePaste",c=>c(n,i,s||b.empty)))return!0;if(!s)return!1;let o=rg(s),l=o?n.state.tr.replaceSelectionWith(o,r):n.state.tr.replaceSelection(s);return n.dispatch(l.scrollIntoView().setMeta("paste",!0).setMeta("uiEvent","paste")),!0}function Lh(n){let e=n.getData("text/plain")||n.getData("Text");if(e)return e;let t=n.getData("text/uri-list");return t?t.replace(/\r?\n/g," "):""}ge.paste=(n,e)=>{let t=e;if(n.composing&&!Le)return;let r=qr?null:t.clipboardData,i=n.input.shiftKey&&n.input.lastKeyCode!=45;r&&Hr(n,Lh(r),r.getData("text/html"),i,t)?t.preventDefault():ig(n,t)};var ns=class{constructor(e,t,r){this.slice=e,this.move=t,this.node=r}},zh=Re?"altKey":"ctrlKey";me.dragstart=(n,e)=>{let t=e,r=n.input.mouseDown;if(r&&r.done(),!t.dataTransfer)return;let i=n.state.selection,s=i.empty?null:n.posAtCoords(cs(t)),o;if(!(s&&s.pos>=i.from&&s.pos<=(i instanceof C?i.to-1:i.to))){if(r&&r.mightDrag)o=C.create(n.state.doc,r.mightDrag.pos);else if(t.target&&t.target.nodeType==1){let d=n.docView.nearestDesc(t.target,!0);d&&d.node.type.spec.draggable&&d!=n.docView&&(o=C.create(n.state.doc,d.posBefore))}}let l=(o||n.state.selection).content(),{dom:c,text:a,slice:h}=Th(n,l);t.dataTransfer.clearData(),t.dataTransfer.setData(qr?"Text":"text/html",c.innerHTML),t.dataTransfer.effectAllowed="copyMove",qr||t.dataTransfer.setData("text/plain",a),n.dragging=new ns(h,!t[zh],o)};me.dragend=n=>{let e=n.dragging;window.setTimeout(()=>{n.dragging==e&&(n.dragging=null)},50)};ge.dragover=ge.dragenter=(n,e)=>e.preventDefault();ge.drop=(n,e)=>{let t=e,r=n.dragging;if(n.dragging=null,!t.dataTransfer)return;let i=n.posAtCoords(cs(t));if(!i)return;let s=n.state.doc.resolve(i.pos),o=r&&r.slice;o?n.someProp("transformPasted",p=>{o=p(o,n)}):o=Oh(n,Lh(t.dataTransfer),qr?null:t.dataTransfer.getData("text/html"),!1,s);let l=!!(r&&!t[zh]);if(n.someProp("handleDrop",p=>p(n,t,o||b.empty,l))){t.preventDefault();return}if(!o)return;t.preventDefault();let c=o?ka(n.state.doc,s.pos,o):s.pos;c==null&&(c=s.pos);let a=n.state.tr;if(l){let{node:p}=r;p?p.replace(a):a.deleteSelection()}let h=a.mapping.map(c),d=o.openStart==0&&o.openEnd==0&&o.content.childCount==1,f=a.doc;if(d?a.replaceRangeWith(h,h,o.content.firstChild):a.replaceRange(h,h,o),a.doc.eq(f))return;let u=a.doc.resolve(h);if(d&&C.isSelectable(o.content.firstChild)&&u.nodeAfter&&u.nodeAfter.sameMarkup(o.content.firstChild))a.setSelection(new C(u));else{let p=a.mapping.map(c);a.mapping.maps[a.mapping.maps.length-1].forEach((m,g,w,I)=>p=I),a.setSelection(ll(n,u,a.doc.resolve(p)))}n.focus(),n.dispatch(a.setMeta("uiEvent","drop"))};me.focus=n=>{n.input.lastFocus=Date.now(),n.focused||(n.domObserver.stop(),n.dom.classList.add("ProseMirror-focused"),n.domObserver.start(),n.focused=!0,setTimeout(()=>{n.docView&&n.hasFocus()&&!n.domObserver.currentSelection.eq(n.domSelectionRange())&&dt(n)},20))};me.blur=(n,e)=>{let t=e;n.focused&&(n.domObserver.stop(),n.dom.classList.remove("ProseMirror-focused"),n.domObserver.start(),t.relatedTarget&&n.dom.contains(t.relatedTarget)&&n.domObserver.currentSelection.clear(),n.focused=!1)};me.beforeinput=(n,e)=>{if(ue&&Le&&e.inputType=="deleteContentBackward"){n.domObserver.flushSoon();let{domChangeCount:r}=n.input;setTimeout(()=>{if(n.input.domChangeCount!=r||(n.dom.blur(),n.focus(),n.someProp("handleKeyDown",s=>s(n,on(8,"Backspace")))))return;let{$cursor:i}=n.state.selection;i&&i.pos>0&&n.dispatch(n.state.tr.delete(i.pos-1,i.pos).scrollIntoView())},50)}};for(let n in ge)me[n]=ge[n];function Jr(n,e){if(n==e)return!0;for(let t in n)if(n[t]!==e[t])return!1;for(let t in e)if(!(t in n))return!1;return!0}var rs=class n{constructor(e,t){this.toDOM=e,this.spec=t||hn,this.side=this.spec.side||0}map(e,t,r,i){let{pos:s,deleted:o}=e.mapResult(t.from+i,this.side<0?-1:1);return o?null:new te(s-r,s-r,this)}valid(){return!0}eq(e){return this==e||e instanceof n&&(this.spec.key&&this.spec.key==e.spec.key||this.toDOM==e.toDOM&&Jr(this.spec,e.spec))}destroy(e){this.spec.destroy&&this.spec.destroy(e)}},an=class n{constructor(e,t){this.attrs=e,this.spec=t||hn}map(e,t,r,i){let s=e.map(t.from+i,this.spec.inclusiveStart?-1:1)-r,o=e.map(t.to+i,this.spec.inclusiveEnd?1:-1)-r;return s>=o?null:new te(s,o,this)}valid(e,t){return t.from=e&&(!s||s(l.spec))&&r.push(l.copy(l.from+i,l.to+i))}for(let o=0;oe){let l=this.children[o]+1;this.children[o+2].findInner(e-l,t-l,r,i+l,s)}}map(e,t,r){return this==oe||e.maps.length==0?this:this.mapInner(e,t,0,0,r||hn)}mapInner(e,t,r,i,s){let o;for(let l=0;l{let a=c+r,h;if(h=qh(t,l,a)){for(i||(i=this.children.slice());sl&&d.to=e){this.children[l]==e&&(r=this.children[l+2]);break}let s=e+1,o=s+t.content.size;for(let l=0;ls&&c.type instanceof an){let a=Math.max(s,c.from)-s,h=Math.min(o,c.to)-s;ai.map(e,t,hn));return n.from(r)}forChild(e,t){if(t.isLeaf)return P.empty;let r=[];for(let i=0;it instanceof P)?e:e.reduce((t,r)=>t.concat(r instanceof P?r:r.members),[]))}}};function sg(n,e,t,r,i,s,o){let l=n.slice();for(let a=0,h=s;a{let g=m-p-(u-f);for(let w=0;wI+h-d)continue;let z=l[w]+h-d;u>=z?l[w+1]=f<=z?-2:-1:f>=h&&g&&(l[w]+=g,l[w+1]+=g)}d+=g}),h=t.maps[a].map(h,-1)}let c=!1;for(let a=0;a=r.content.size){c=!0;continue}let f=t.map(n[a+1]+s,-1),u=f-i,{index:p,offset:m}=r.content.findIndex(d),g=r.maybeChild(p);if(g&&m==d&&m+g.nodeSize==u){let w=l[a+2].mapInner(t,g,h+1,n[a]+s+1,o);w!=oe?(l[a]=d,l[a+1]=u,l[a+2]=w):(l[a+1]=-2,c=!0)}else c=!0}if(c){let a=og(l,n,e,t,i,s,o),h=ss(a,r,0,o);e=h.local;for(let d=0;dt&&o.to{let a=qh(n,l,c+t);if(a){s=!0;let h=ss(a,l,t+c+1,r);h!=oe&&i.push(c,c+l.nodeSize,h)}});let o=Fh(s?Hh(n):n,-t).sort(dn);for(let l=0;l0;)e++;n.splice(e,0,t)}function Bo(n){let e=[];return n.someProp("decorations",t=>{let r=t(n.state);r&&r!=oe&&e.push(r)}),n.cursorWrapper&&e.push(P.create(n.state.doc,[n.cursorWrapper.deco])),is.from(e)}var lg={childList:!0,characterData:!0,characterDataOldValue:!0,attributes:!0,attributeOldValue:!0,subtree:!0},cg=xe&&_t<=11,nl=class{constructor(){this.anchorNode=null,this.anchorOffset=0,this.focusNode=null,this.focusOffset=0}set(e){this.anchorNode=e.anchorNode,this.anchorOffset=e.anchorOffset,this.focusNode=e.focusNode,this.focusOffset=e.focusOffset}clear(){this.anchorNode=this.focusNode=null}eq(e){return e.anchorNode==this.anchorNode&&e.anchorOffset==this.anchorOffset&&e.focusNode==this.focusNode&&e.focusOffset==this.focusOffset}},rl=class{constructor(e,t){this.view=e,this.handleDOMChange=t,this.queue=[],this.flushingSoon=-1,this.observer=null,this.currentSelection=new nl,this.onCharData=null,this.suppressingSelectionUpdates=!1,this.observer=window.MutationObserver&&new window.MutationObserver(r=>{for(let i=0;ii.type=="childList"&&i.removedNodes.length||i.type=="characterData"&&i.oldValue.length>i.target.nodeValue.length)?this.flushSoon():this.flush()}),cg&&(this.onCharData=r=>{this.queue.push({target:r.target,type:"characterData",oldValue:r.prevValue}),this.flushSoon()}),this.onSelectionChange=this.onSelectionChange.bind(this)}flushSoon(){this.flushingSoon<0&&(this.flushingSoon=window.setTimeout(()=>{this.flushingSoon=-1,this.flush()},20))}forceFlush(){this.flushingSoon>-1&&(window.clearTimeout(this.flushingSoon),this.flushingSoon=-1,this.flush())}start(){this.observer&&(this.observer.takeRecords(),this.observer.observe(this.view.dom,lg)),this.onCharData&&this.view.dom.addEventListener("DOMCharacterDataModified",this.onCharData),this.connectSelection()}stop(){if(this.observer){let e=this.observer.takeRecords();if(e.length){for(let t=0;tthis.flush(),20)}this.observer.disconnect()}this.onCharData&&this.view.dom.removeEventListener("DOMCharacterDataModified",this.onCharData),this.disconnectSelection()}connectSelection(){this.view.dom.ownerDocument.addEventListener("selectionchange",this.onSelectionChange)}disconnectSelection(){this.view.dom.ownerDocument.removeEventListener("selectionchange",this.onSelectionChange)}suppressSelectionUpdates(){this.suppressingSelectionUpdates=!0,setTimeout(()=>this.suppressingSelectionUpdates=!1,50)}onSelectionChange(){if(Ya(this.view)){if(this.suppressingSelectionUpdates)return dt(this.view);if(xe&&_t<=11&&!this.view.state.selection.empty){let e=this.view.domSelectionRange();if(e.focusNode&&fn(e.focusNode,e.focusOffset,e.anchorNode,e.anchorOffset))return this.flushSoon()}this.flush()}}setCurSelection(){this.currentSelection.set(this.view.domSelectionRange())}ignoreSelectionChange(e){if(!e.focusNode)return!0;let t=new Set,r;for(let s=e.focusNode;s;s=Fr(s))t.add(s);for(let s=e.anchorNode;s;s=Fr(s))if(t.has(s)){r=s;break}let i=r&&this.view.docView.nearestDesc(r);if(i&&i.ignoreMutation({type:"selection",target:r.nodeType==3?r.parentNode:r}))return this.setCurSelection(),!0}pendingRecords(){if(this.observer)for(let e of this.observer.takeRecords())this.queue.push(e);return this.queue}flush(){let{view:e}=this;if(!e.docView||this.flushingSoon>-1)return;let t=this.pendingRecords();t.length&&(this.queue=[]);let r=e.domSelectionRange(),i=!this.suppressingSelectionUpdates&&!this.currentSelection.eq(r)&&Ya(e)&&!this.ignoreSelectionChange(r),s=-1,o=-1,l=!1,c=[];if(e.editable)for(let h=0;h1){let h=c.filter(d=>d.nodeName=="BR");if(h.length==2){let d=h[0],f=h[1];d.parentNode&&d.parentNode.parentNode==f.parentNode?f.remove():d.remove()}}let a=null;s<0&&i&&e.input.lastFocus>Date.now()-200&&Math.max(e.input.lastTouch,e.input.lastClick.time)-1||i)&&(s>-1&&(e.docView.markDirty(s,o),ag(e)),this.handleDOMChange(s,o,l,c),e.docView&&e.docView.dirty?e.updateState(e.state):this.currentSelection.eq(r)||dt(e),this.currentSelection.set(r))}registerMutation(e,t){if(t.indexOf(e.target)>-1)return null;let r=this.view.docView.nearestDesc(e.target);if(e.type=="attributes"&&(r==this.view.docView||e.attributeName=="contenteditable"||e.attributeName=="style"&&!e.oldValue&&!e.target.getAttribute("style"))||!r||r.ignoreMutation(e))return null;if(e.type=="childList"){for(let h=0;hi;g--){let w=r.childNodes[g-1],I=w.pmViewDesc;if(w.nodeName=="BR"&&!I){s=g;break}if(!I||I.size)break}let d=n.state.doc,f=n.someProp("domParser")||zn.fromSchema(n.state.schema),u=d.resolve(o),p=null,m=f.parse(r,{topNode:u.parent,topMatch:u.parent.contentMatchAt(u.index()),topOpen:!0,from:i,to:s,preserveWhitespace:u.parent.type.whitespace=="pre"?"full":!0,findPositions:a,ruleFromNode:fg,context:u});if(a&&a[0].pos!=null){let g=a[0].pos,w=a[1]&&a[1].pos;w==null&&(w=g),p={anchor:g+o,head:w+o}}return{doc:m,sel:p,from:o,to:l}}function fg(n){let e=n.pmViewDesc;if(e)return e.parseRule();if(n.nodeName=="BR"&&n.parentNode){if(pe&&/^(ul|ol)$/i.test(n.parentNode.nodeName)){let t=document.createElement("div");return t.appendChild(document.createElement("li")),{skip:t}}else if(n.parentNode.lastChild==n||pe&&/^(tr|table)$/i.test(n.parentNode.nodeName))return{ignore:!0}}else if(n.nodeName=="IMG"&&n.getAttribute("mark-placeholder"))return{ignore:!0};return null}var ug=/^(a|abbr|acronym|b|bd[io]|big|br|button|cite|code|data(list)?|del|dfn|em|i|ins|kbd|label|map|mark|meter|output|q|ruby|s|samp|small|span|strong|su[bp]|time|u|tt|var)$/i;function pg(n,e,t,r,i){let s=n.input.compositionPendingChanges||(n.composing?n.input.compositionID:0);if(n.input.compositionPendingChanges=0,e<0){let D=n.input.lastSelectionTime>Date.now()-50?n.input.lastSelectionOrigin:null,Tt=ol(n,D);if(Tt&&!n.state.selection.eq(Tt)){if(ue&&Le&&n.input.lastKeyCode===13&&Date.now()-100np(n,on(13,"Enter"))))return;let Ui=n.state.tr.setSelection(Tt);D=="pointer"?Ui.setMeta("pointer",!0):D=="key"&&Ui.scrollIntoView(),s&&Ui.setMeta("composition",s),n.dispatch(Ui)}return}let o=n.state.doc.resolve(e),l=o.sharedDepth(t);e=o.before(l+1),t=n.state.doc.resolve(t).after(l+1);let c=n.state.selection,a=dg(n,e,t),h=n.state.doc,d=h.slice(a.from,a.to),f,u;n.input.lastKeyCode===8&&Date.now()-100Date.now()-225||Le)&&i.some(D=>D.nodeType==1&&!ug.test(D.nodeName))&&(!p||p.endA>=p.endB)&&n.someProp("handleKeyDown",D=>D(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(!p)if(r&&c instanceof A&&!c.empty&&c.$head.sameParent(c.$anchor)&&!n.composing&&!(a.sel&&a.sel.anchor!=a.sel.head))p={start:c.from,endA:c.to,endB:c.to};else{if(a.sel){let D=lh(n,n.state.doc,a.sel);if(D&&!D.eq(n.state.selection)){let Tt=n.state.tr.setSelection(D);s&&Tt.setMeta("composition",s),n.dispatch(Tt)}}return}n.input.domChangeCount++,n.state.selection.fromn.state.selection.from&&p.start<=n.state.selection.from+2&&n.state.selection.from>=a.from?p.start=n.state.selection.from:p.endA=n.state.selection.to-2&&n.state.selection.to<=a.to&&(p.endB+=n.state.selection.to-p.endA,p.endA=n.state.selection.to)),xe&&_t<=11&&p.endB==p.start+1&&p.endA==p.start&&p.start>a.from&&a.doc.textBetween(p.start-a.from-1,p.start-a.from+1)==" \xA0"&&(p.start--,p.endA--,p.endB--);let m=a.doc.resolveNoCache(p.start-a.from),g=a.doc.resolveNoCache(p.endB-a.from),w=h.resolve(p.start),I=m.sameParent(g)&&m.parent.inlineContent&&w.end()>=p.endA,z;if((jn&&n.input.lastIOSEnter>Date.now()-225&&(!I||i.some(D=>D.nodeName=="DIV"||D.nodeName=="P"))||!I&&m.posD(n,on(13,"Enter")))){n.input.lastIOSEnter=0;return}if(n.state.selection.anchor>p.start&&gg(h,p.start,p.endA,m,g)&&n.someProp("handleKeyDown",D=>D(n,on(8,"Backspace")))){Le&&ue&&n.domObserver.suppressSelectionUpdates();return}ue&&Le&&p.endB==p.start&&(n.input.lastAndroidDelete=Date.now()),Le&&!I&&m.start()!=g.start()&&g.parentOffset==0&&m.depth==g.depth&&a.sel&&a.sel.anchor==a.sel.head&&a.sel.head==p.endA&&(p.endB-=2,g=a.doc.resolveNoCache(p.endB-a.from),setTimeout(()=>{n.someProp("handleKeyDown",function(D){return D(n,on(13,"Enter"))})},20));let Ie=p.start,de=p.endA,j,lt,Dt;if(I){if(m.pos==g.pos)xe&&_t<=11&&m.parentOffset==0&&(n.domObserver.suppressSelectionUpdates(),setTimeout(()=>dt(n),20)),j=n.state.tr.delete(Ie,de),lt=h.resolve(p.start).marksAcross(h.resolve(p.endA));else if(p.endA==p.endB&&(Dt=mg(m.parent.content.cut(m.parentOffset,g.parentOffset),w.parent.content.cut(w.parentOffset,p.endA-w.start()))))j=n.state.tr,Dt.type=="add"?j.addMark(Ie,de,Dt.mark):j.removeMark(Ie,de,Dt.mark);else if(m.parent.child(m.index()).isText&&m.index()==g.index()-(g.textOffset?0:1)){let D=m.parent.textBetween(m.parentOffset,g.parentOffset);if(n.someProp("handleTextInput",Tt=>Tt(n,Ie,de,D)))return;j=n.state.tr.insertText(D,Ie,de)}}if(j||(j=n.state.tr.replace(Ie,de,a.doc.slice(p.start-a.from,p.endB-a.from))),a.sel){let D=lh(n,j.doc,a.sel);D&&!(ue&&Le&&n.composing&&D.empty&&(p.start!=p.endB||n.input.lastAndroidDeletee.content.size?null:ll(n,e.resolve(t.anchor),e.resolve(t.head))}function mg(n,e){let t=n.firstChild.marks,r=e.firstChild.marks,i=t,s=r,o,l,c;for(let h=0;hh.mark(l.addToSet(h.marks));else if(i.length==0&&s.length==1)l=s[0],o="remove",c=h=>h.mark(l.removeFromSet(h.marks));else return null;let a=[];for(let h=0;ht||Po(o,!0,!1)0&&(e||n.indexAfter(r)==n.node(r).childCount);)r--,i++,e=!1;if(t){let s=n.node(r).maybeChild(n.indexAfter(r));for(;s&&!s.isLeaf;)s=s.firstChild,i++}return i}function yg(n,e,t,r,i){let s=n.findDiffStart(e,t);if(s==null)return null;let{a:o,b:l}=n.findDiffEnd(e,t+n.size,t+e.size);if(i=="end"){let c=Math.max(0,s-Math.min(o,l));r-=o+c-s}if(o=o?s-r:0;s-=c,s&&s=l?s-r:0;s-=c,s&&s=56320&&e<=57343&&t>=55296&&t<=56319}var il=class{constructor(e,t){this._root=null,this.focused=!1,this.trackWrites=null,this.mounted=!1,this.markCursor=null,this.cursorWrapper=null,this.lastSelectedViewDesc=void 0,this.input=new Qo,this.prevDirectPlugins=[],this.pluginViews=[],this.requiresGeckoHackNode=!1,this.dragging=null,this._props=t,this.state=t.state,this.directPlugins=t.plugins||[],this.directPlugins.forEach(uh),this.dispatch=this.dispatch.bind(this),this.dom=e&&e.mount||document.createElement("div"),e&&(e.appendChild?e.appendChild(this.dom):typeof e=="function"?e(this.dom):e.mount&&(this.mounted=!0)),this.editable=dh(this),hh(this),this.nodeViews=fh(this),this.docView=Ha(this.state.doc,ah(this),Bo(this),this.dom,this),this.domObserver=new rl(this,(r,i,s,o)=>pg(this,r,i,s,o)),this.domObserver.start(),qm(this),this.updatePluginViews()}get composing(){return this.input.composing}get props(){if(this._props.state!=this.state){let e=this._props;this._props={};for(let t in e)this._props[t]=e[t];this._props.state=this.state}return this._props}update(e){e.handleDOMEvents!=this._props.handleDOMEvents&&Zo(this);let t=this._props;this._props=e,e.plugins&&(e.plugins.forEach(uh),this.directPlugins=e.plugins),this.updateStateInner(e.state,t)}setProps(e){let t={};for(let r in this._props)t[r]=this._props[r];t.state=this.state;for(let r in e)t[r]=e[r];this.update(t)}updateState(e){this.updateStateInner(e,this._props)}updateStateInner(e,t){var r;let i=this.state,s=!1,o=!1;e.storedMarks&&this.composing&&(Ph(this),o=!0),this.state=e;let l=i.plugins!=e.plugins||this._props.plugins!=t.plugins;if(l||this._props.plugins!=t.plugins||this._props.nodeViews!=t.nodeViews){let u=fh(this);bg(u,this.nodeViews)&&(this.nodeViews=u,s=!0)}(l||t.handleDOMEvents!=this._props.handleDOMEvents)&&Zo(this),this.editable=dh(this),hh(this);let c=Bo(this),a=ah(this),h=i.plugins!=e.plugins&&!i.doc.eq(e.doc)?"reset":e.scrollToSelection>i.scrollToSelection?"to selection":"preserve",d=s||!this.docView.matchesNode(e.doc,a,c);(d||!e.selection.eq(i.selection))&&(o=!0);let f=h=="preserve"&&o&&this.dom.style.overflowAnchor==null&&lm(this);if(o){this.domObserver.stop();let u=d&&(xe||ue)&&!this.composing&&!i.selection.empty&&!e.selection.empty&&wg(i.selection,e.selection);if(d){let p=ue?this.trackWrites=this.domSelectionRange().focusNode:null;this.composing&&(this.input.compositionNode=eg(this)),(s||!this.docView.update(e.doc,a,c,this))&&(this.docView.updateOuterDeco(a),this.docView.destroy(),this.docView=Ha(e.doc,a,c,this.dom,this)),p&&!this.trackWrites&&(u=!0)}u||!(this.input.mouseDown&&this.domObserver.currentSelection.eq(this.domSelectionRange())&&Tm(this))?dt(this,u):(Ah(this,e.selection),this.domObserver.setCurSelection()),this.domObserver.start()}this.updatePluginViews(i),!((r=this.dragging)===null||r===void 0)&&r.node&&!i.doc.eq(e.doc)&&this.updateDraggedNode(this.dragging,i),h=="reset"?this.dom.scrollTop=0:h=="to selection"?this.scrollToSelection():f&&cm(f)}scrollToSelection(){let e=this.domSelectionRange().focusNode;if(!this.someProp("handleScrollToSelection",t=>t(this)))if(this.state.selection instanceof C){let t=this.docView.domAfterPos(this.state.selection.from);t.nodeType==1&&Ba(this,t.getBoundingClientRect(),e)}else Ba(this,this.coordsAtPos(this.state.selection.head,1),e)}destroyPluginViews(){let e;for(;e=this.pluginViews.pop();)e.destroy&&e.destroy()}updatePluginViews(e){if(!e||e.plugins!=this.state.plugins||this.directPlugins!=this.prevDirectPlugins){this.prevDirectPlugins=this.directPlugins,this.destroyPluginViews();for(let t=0;t0&&this.state.doc.nodeAt(s))==r.node&&(i=s)}this.dragging=new ns(e.slice,e.move,i<0?void 0:C.create(this.state.doc,i))}someProp(e,t){let r=this._props&&this._props[e],i;if(r!=null&&(i=t?t(r):r))return i;for(let o=0;ot.ownerDocument.getSelection()),this._root=t}return e||document}updateRoot(){this._root=null}posAtCoords(e){return pm(this,e)}coordsAtPos(e,t=1){return bh(this,e,t)}domAtPos(e,t=0){return this.docView.domFromPos(e,t)}nodeDOM(e){let t=this.docView.descAt(e);return t?t.nodeDOM:null}posAtDOM(e,t,r=-1){let i=this.docView.posFromDOM(e,t,r);if(i==null)throw new RangeError("DOM position not inside the editor");return i}endOfTextblock(e,t){return bm(this,t||this.state,e)}pasteHTML(e,t){return Hr(this,"",e,!1,t||new ClipboardEvent("paste"))}pasteText(e,t){return Hr(this,e,null,!0,t||new ClipboardEvent("paste"))}destroy(){this.docView&&(Hm(this),this.destroyPluginViews(),this.mounted?(this.docView.update(this.state.doc,[],Bo(this),this),this.dom.textContent=""):this.dom.parentNode&&this.dom.parentNode.removeChild(this.dom),this.docView.destroy(),this.docView=null,Yp())}get isDestroyed(){return this.docView==null}dispatchEvent(e){return Wm(this,e)}dispatch(e){let t=this._props.dispatchTransaction;t?t.call(this,e):this.updateState(this.state.apply(e))}domSelectionRange(){let e=this.domSelection();return pe&&this.root.nodeType===11&&em(this.dom.ownerDocument)==this.dom&&hg(this,e)||e}domSelection(){return this.root.getSelection()}};function ah(n){let e=Object.create(null);return e.class="ProseMirror",e.contenteditable=String(n.editable),n.someProp("attributes",t=>{if(typeof t=="function"&&(t=t(n.state)),t)for(let r in t)r=="class"?e.class+=" "+t[r]:r=="style"?e.style=(e.style?e.style+";":"")+t[r]:!e[r]&&r!="contenteditable"&&r!="nodeName"&&(e[r]=String(t[r]))}),e.translate||(e.translate="no"),[te.node(0,n.state.doc.content.size,e)]}function hh(n){if(n.markCursor){let e=document.createElement("img");e.className="ProseMirror-separator",e.setAttribute("mark-placeholder","true"),e.setAttribute("alt",""),n.cursorWrapper={dom:e,deco:te.widget(n.state.selection.head,e,{raw:!0,marks:n.markCursor})}}else n.cursorWrapper=null}function dh(n){return!n.someProp("editable",e=>e(n.state)===!1)}function wg(n,e){let t=Math.min(n.$anchor.sharedDepth(n.head),e.$anchor.sharedDepth(e.head));return n.$anchor.start(t)!=e.$anchor.start(t)}function fh(n){let e=Object.create(null);function t(r){for(let i in r)Object.prototype.hasOwnProperty.call(e,i)||(e[i]=r[i])}return n.someProp("nodeViews",t),n.someProp("markViews",t),e}function bg(n,e){let t=0,r=0;for(let i in n){if(n[i]!=e[i])return!0;t++}for(let i in e)r++;return t!=r}function uh(n){if(n.spec.state||n.spec.filterTransaction||n.spec.appendTransaction)throw new RangeError("Plugins passed directly to the view must not have a state component")}var xg=["p",0],Sg=["blockquote",0],kg=["hr"],Cg=["pre",["code",0]],Mg=["br"],Ag={doc:{content:"block+"},paragraph:{content:"inline*",group:"block",parseDOM:[{tag:"p"}],toDOM(){return xg}},blockquote:{content:"block+",group:"block",defining:!0,parseDOM:[{tag:"blockquote"}],toDOM(){return Sg}},horizontal_rule:{group:"block",parseDOM:[{tag:"hr"}],toDOM(){return kg}},heading:{attrs:{level:{default:1}},content:"inline*",group:"block",defining:!0,parseDOM:[{tag:"h1",attrs:{level:1}},{tag:"h2",attrs:{level:2}},{tag:"h3",attrs:{level:3}},{tag:"h4",attrs:{level:4}},{tag:"h5",attrs:{level:5}},{tag:"h6",attrs:{level:6}}],toDOM(n){return["h"+n.attrs.level,0]}},code_block:{content:"text*",marks:"",group:"block",code:!0,defining:!0,parseDOM:[{tag:"pre",preserveWhitespace:"full"}],toDOM(){return Cg}},text:{group:"inline"},image:{inline:!0,attrs:{src:{},alt:{default:null},title:{default:null}},group:"inline",draggable:!0,parseDOM:[{tag:"img[src]",getAttrs(n){return{src:n.getAttribute("src"),title:n.getAttribute("title"),alt:n.getAttribute("alt")}}}],toDOM(n){let{src:e,alt:t,title:r}=n.attrs;return["img",{src:e,alt:t,title:r}]}},hard_break:{inline:!0,group:"inline",selectable:!1,parseDOM:[{tag:"br"}],toDOM(){return Mg}}},Eg=["em",0],Dg=["strong",0],Tg=["code",0],Og={link:{attrs:{href:{},title:{default:null}},inclusive:!1,parseDOM:[{tag:"a[href]",getAttrs(n){return{href:n.getAttribute("href"),title:n.getAttribute("title")}}}],toDOM(n){let{href:e,title:t}=n.attrs;return["a",{href:e,title:t},0]}},em:{parseDOM:[{tag:"i"},{tag:"em"},{style:"font-style=italic"},{style:"font-style=normal",clearMark:n=>n.type.name=="em"}],toDOM(){return Eg}},strong:{parseDOM:[{tag:"strong"},{tag:"b",getAttrs:n=>n.style.fontWeight!="normal"&&null},{style:"font-weight=400",clearMark:n=>n.type.name=="strong"},{style:"font-weight",getAttrs:n=>/^(bold(er)?|[5-9]\d{2,})$/.test(n)&&null}],toDOM(){return Dg}},code:{parseDOM:[{tag:"code"}],toDOM(){return Tg}}},Ng=new Tr({nodes:Ag,marks:Og});var Wh=(n,e)=>n.selection.empty?!1:(e&&e(n.tr.deleteSelection().scrollIntoView()),!0);function Ig(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("backward",n):t.parentOffset>0)?null:t}var Rg=(n,e,t)=>{let r=Ig(n,t);if(!r)return!1;let i=$h(r);if(!i){let o=r.blockRange(),l=o&&nn(o);return l==null?!1:(e&&e(n.tr.lift(o,l).scrollIntoView()),!0)}let s=i.nodeBefore;if(!s.type.spec.isolating&&Yh(n,i,e))return!0;if(r.parent.content.size==0&&(Gn(s,"end")||C.isSelectable(s))){let o=ji(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("backward",n):r.parentOffset>0)return!1;s=$h(r)}let o=s&&s.nodeBefore;return!o||!C.isSelectable(o)?!1:(e&&e(n.tr.setSelection(C.create(n.doc,s.pos-o.nodeSize)).scrollIntoView()),!0)};function $h(n){if(!n.parent.type.spec.isolating)for(let e=n.depth-1;e>=0;e--){if(n.index(e)>0)return n.doc.resolve(n.before(e+1));if(n.node(e).type.spec.isolating)break}return null}function _g(n,e){let{$cursor:t}=n.selection;return!t||(e?!e.endOfTextblock("forward",n):t.parentOffset{let r=_g(n,t);if(!r)return!1;let i=Kh(r);if(!i)return!1;let s=i.nodeAfter;if(Yh(n,i,e))return!0;if(r.parent.content.size==0&&(Gn(s,"start")||C.isSelectable(s))){let o=ji(n.doc,r.before(),r.after(),b.empty);if(o&&o.slice.size{let{$head:r,empty:i}=n.selection,s=r;if(!i)return!1;if(r.parent.isTextblock){if(t?!t.endOfTextblock("forward",n):r.parentOffset=0;e--){let t=n.node(e);if(n.index(e)+1{let t=n.selection,r=t instanceof C,i;if(r){if(t.node.isTextblock||!rn(n.doc,t.from))return!1;i=t.from}else if(i=Oo(n.doc,t.from,-1),i==null)return!1;if(e){let s=n.tr.join(i);r&&s.setSelection(C.create(s.doc,i-n.doc.resolve(i).nodeBefore.nodeSize)),e(s.scrollIntoView())}return!0},jh=(n,e)=>{let t=n.selection,r;if(t instanceof C){if(t.node.isTextblock||!rn(n.doc,t.to))return!1;r=t.to}else if(r=Oo(n.doc,t.to,1),r==null)return!1;return e&&e(n.tr.join(r).scrollIntoView()),!0},jr=(n,e)=>{let{$from:t,$to:r}=n.selection,i=t.blockRange(r),s=i&&nn(i);return s==null?!1:(e&&e(n.tr.lift(i,s).scrollIntoView()),!0)},Bg=(n,e)=>{let{$head:t,$anchor:r}=n.selection;return!t.parent.type.spec.code||!t.sameParent(r)?!1:(e&&e(n.tr.insertText(`
-`).scrollIntoView()),!0)};function ul(n){for(let e=0;e{let{$head:t,$anchor:r}=n.selection;if(!t.parent.type.spec.code||!t.sameParent(r))return!1;let i=t.node(-1),s=t.indexAfter(-1),o=ul(i.contentMatchAt(s));if(!o||!i.canReplaceWith(s,s,o))return!1;if(e){let l=t.after(),c=n.tr.replaceWith(l,l,o.createAndFill());c.setSelection(S.near(c.doc.resolve(l),1)),e(c.scrollIntoView())}return!0},Pg=(n,e)=>{let t=n.selection,{$from:r,$to:i}=t;if(t instanceof Ae||r.parent.inlineContent||i.parent.inlineContent)return!1;let s=ul(i.parent.contentMatchAt(i.indexAfter()));if(!s||!s.isTextblock)return!1;if(e){let o=(!r.parentOffset&&i.index(){let{$cursor:t}=n.selection;if(!t||t.parent.content.size)return!1;if(t.depth>1&&t.after()!=t.end(-1)){let s=t.before();if(Nt(n.doc,s))return e&&e(n.tr.split(s).scrollIntoView()),!0}let r=t.blockRange(),i=r&&nn(r);return i==null?!1:(e&&e(n.tr.lift(r,i).scrollIntoView()),!0)};function zg(n){return(e,t)=>{let{$from:r,$to:i}=e.selection;if(e.selection instanceof C&&e.selection.node.isBlock)return!r.parentOffset||!Nt(e.doc,r.pos)?!1:(t&&t(e.tr.split(r.pos).scrollIntoView()),!0);if(!r.parent.isBlock)return!1;if(t){let s=i.parentOffset==i.parent.content.size,o=e.tr;(e.selection instanceof A||e.selection instanceof Ae)&&o.deleteSelection();let l=r.depth==0?null:ul(r.node(-1).contentMatchAt(r.indexAfter(-1))),c=n&&n(i.parent,s),a=c?[c]:s&&l?[{type:l}]:void 0,h=Nt(o.doc,o.mapping.map(r.pos),1,a);if(!a&&!h&&Nt(o.doc,o.mapping.map(r.pos),1,l?[{type:l}]:void 0)&&(l&&(a=[{type:l}]),h=!0),h&&(o.split(o.mapping.map(r.pos),1,a),!s&&!r.parentOffset&&r.parent.type!=l)){let d=o.mapping.map(r.before()),f=o.doc.resolve(d);l&&r.node(-1).canReplaceWith(f.index(),f.index()+1,l)&&o.setNodeMarkup(o.mapping.map(r.before()),l)}t(o.scrollIntoView())}return!0}}var Fg=zg();var Yr=(n,e)=>{let{$from:t,to:r}=n.selection,i,s=t.sharedDepth(r);return s==0?!1:(i=t.before(s),e&&e(n.tr.setSelection(C.create(n.doc,i))),!0)},qg=(n,e)=>(e&&e(n.tr.setSelection(new Ae(n.doc))),!0);function Hg(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s=e.index();return!r||!i||!r.type.compatibleContent(i.type)?!1:!r.content.size&&e.parent.canReplace(s-1,s)?(t&&t(n.tr.delete(e.pos-r.nodeSize,e.pos).scrollIntoView()),!0):!e.parent.canReplace(s,s+1)||!(i.isTextblock||rn(n.doc,e.pos))?!1:(t&&t(n.tr.clearIncompatible(e.pos,r.type,r.contentMatchAt(r.childCount)).join(e.pos).scrollIntoView()),!0)}function Yh(n,e,t){let r=e.nodeBefore,i=e.nodeAfter,s,o;if(r.type.spec.isolating||i.type.spec.isolating)return!1;if(Hg(n,e,t))return!0;let l=e.parent.canReplace(e.index(),e.index()+1);if(l&&(s=(o=r.contentMatchAt(r.childCount)).findWrapping(i.type))&&o.matchType(s[0]||i.type).validEnd){if(t){let d=e.pos+i.nodeSize,f=y.empty;for(let m=s.length-1;m>=0;m--)f=y.from(s[m].create(null,f));f=y.from(r.copy(f));let u=n.tr.step(new G(e.pos-1,d,e.pos,d,new b(f,1,0),s.length,!0)),p=d+2*s.length;rn(u.doc,p)&&u.join(p),t(u.scrollIntoView())}return!0}let c=S.findFrom(e,1),a=c&&c.$from.blockRange(c.$to),h=a&&nn(a);if(h!=null&&h>=e.depth)return t&&t(n.tr.lift(a,h).scrollIntoView()),!0;if(l&&Gn(i,"start",!0)&&Gn(r,"end")){let d=r,f=[];for(;f.push(d),!d.isTextblock;)d=d.lastChild;let u=i,p=1;for(;!u.isTextblock;u=u.firstChild)p++;if(d.canReplace(d.childCount,d.childCount,u.content)){if(t){let m=y.empty;for(let w=f.length-1;w>=0;w--)m=y.from(f[w].copy(m));let g=n.tr.step(new G(e.pos-f.length,e.pos+i.nodeSize,e.pos+p,e.pos+i.nodeSize-p,new b(m,f.length,0),0,!0));t(g.scrollIntoView())}return!0}}return!1}function Gh(n){return function(e,t){let r=e.selection,i=n<0?r.$from:r.$to,s=i.depth;for(;i.node(s).isInline;){if(!s)return!1;s--}return i.node(s).isTextblock?(t&&t(e.tr.setSelection(A.create(e.doc,n<0?i.start(s):i.end(s)))),!0):!1}}var Jg=Gh(-1),Wg=Gh(1);function ml(n,e=null){return function(t,r){let{$from:i,$to:s}=t.selection,o=i.blockRange(s),l=o&&Ki(o,n,e);return l?(r&&r(t.tr.wrap(o,l).scrollIntoView()),!0):!1}}function Xn(n,e=null){return function(t,r){let i=!1;for(let s=0;s{if(i)return!1;if(!(!c.isTextblock||c.hasMarkup(n,e)))if(c.type==n)i=!0;else{let h=t.doc.resolve(a),d=h.index();i=h.parent.canReplaceWith(d,d+1,n)}})}if(!i)return!1;if(r){let s=t.tr;for(let o=0;o{if(o)return!1;o=l.inlineContent&&l.type.allowsMarkType(t)}),o)return!0}return!1}function pn(n,e=null){return function(t,r){let{empty:i,$cursor:s,ranges:o}=t.selection;if(i&&!s||!$g(t.doc,o,n))return!1;if(r)if(s)n.isInSet(t.storedMarks||s.marks())?r(t.tr.removeStoredMark(n)):r(t.tr.addStoredMark(n.create(e)));else{let l=!1,c=t.tr;for(let a=0;!l&&a=t?ne.empty:this.sliceInner(Math.max(0,e),Math.min(this.length,t))};ne.prototype.get=function(e){if(!(e<0||e>=this.length))return this.getInner(e)};ne.prototype.forEach=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length),t<=r?this.forEachInner(e,t,r,0):this.forEachInvertedInner(e,t,r,0)};ne.prototype.map=function(e,t,r){t===void 0&&(t=0),r===void 0&&(r=this.length);var i=[];return this.forEach(function(s,o){return i.push(e(s,o))},t,r),i};ne.from=function(e){return e instanceof ne?e:e&&e.length?new Zh(e):ne.empty};var Zh=function(n){function e(r){n.call(this),this.values=r}n&&(e.__proto__=n),e.prototype=Object.create(n&&n.prototype),e.prototype.constructor=e;var t={length:{configurable:!0},depth:{configurable:!0}};return e.prototype.flatten=function(){return this.values},e.prototype.sliceInner=function(i,s){return i==0&&s==this.length?this:new e(this.values.slice(i,s))},e.prototype.getInner=function(i){return this.values[i]},e.prototype.forEachInner=function(i,s,o,l){for(var c=s;c